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.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>
102 #include <linux/device.h>
104 #include <linux/tty.h>
105 #include <linux/tty_flip.h>
106 #include <linux/termios.h>
107 #include <linux/tty_driver.h>
108 #include <linux/serial.h>
109 #include <linux/ptrace.h>
110 #include <linux/ioport.h>
112 #include <linux/cdk.h>
113 #include <linux/comstats.h>
114 #include <linux/delay.h>
115 #include <linux/bitops.h>
117 #include <asm/system.h>
121 #include <linux/vmalloc.h>
122 #include <linux/init.h>
124 #include <asm/uaccess.h>
126 #include "ip2types.h"
127 #include "ip2trace.h"
128 #include "ip2ioctl.h"
137 #include <linux/proc_fs.h>
139 static int ip2_read_procmem(char *, char **, off_t, int);
140 static 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, 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 get_serial_info(i2ChanStrPtr, struct serial_struct __user *);
205 static int set_serial_info(i2ChanStrPtr, struct serial_struct __user *);
207 static ssize_t ip2_ipl_read(struct file *, char __user *, size_t, loff_t *);
208 static ssize_t ip2_ipl_write(struct file *, const char __user *, size_t, loff_t *);
209 static int ip2_ipl_ioctl(struct inode *, struct file *, UINT, ULONG);
210 static int ip2_ipl_open(struct inode *, struct file *);
212 static int DumpTraceBuffer(char __user *, int);
213 static int DumpFifoBuffer( char __user *, int);
215 static void ip2_init_board(int);
216 static unsigned short find_eisa_board(int);
222 static struct tty_driver *ip2_tty_driver;
224 /* Here, then is a table of board pointers which the interrupt routine should
225 * scan through to determine who it must service.
227 static unsigned short i2nBoards; // Number of boards here
229 static i2eBordStrPtr i2BoardPtrTable[IP2_MAX_BOARDS];
231 static i2ChanStrPtr DevTable[IP2_MAX_PORTS];
232 //DevTableMem just used to save addresses for kfree
233 static void *DevTableMem[IP2_MAX_BOARDS];
235 /* This is the driver descriptor for the ip2ipl device, which is used to
236 * download the loadware to the boards.
238 static struct file_operations ip2_ipl = {
239 .owner = THIS_MODULE,
240 .read = ip2_ipl_read,
241 .write = ip2_ipl_write,
242 .ioctl = ip2_ipl_ioctl,
243 .open = ip2_ipl_open,
246 static unsigned long irq_counter = 0;
247 static unsigned long bh_counter = 0;
249 // Use immediate queue to service interrupts
251 //#define USE_IQ // PCI&2.2 needs work
253 /* The timer_list entry for our poll routine. If interrupt operation is not
254 * selected, the board is serviced periodically to see if anything needs doing.
256 #define POLL_TIMEOUT (jiffies + 1)
257 static DEFINE_TIMER(PollTimer, ip2_poll, 0, 0);
260 #ifdef IP2DEBUG_TRACE
261 /* Trace (debug) buffer data */
262 #define TRACEMAX 1000
263 static unsigned long tracebuf[TRACEMAX];
264 static int tracestuff;
265 static int tracestrip;
266 static int tracewrap;
273 #if defined(MODULE) && defined(IP2DEBUG_OPEN)
274 #define DBG_CNT(s) printk(KERN_DEBUG "(%s): [%x] refc=%d, ttyc=%d, modc=%x -> %s\n", \
275 tty->name,(pCh->flags),ip2_tty_driver->refcount, \
276 tty->count,/*GET_USE_COUNT(module)*/0,s)
285 #include "i2ellis.c" /* Extremely low-level interface services */
286 #include "i2cmd.c" /* Standard loadware command definitions */
287 #include "i2lib.c" /* High level interface services */
289 /* Configuration area for modprobe */
291 MODULE_AUTHOR("Doug McNash");
292 MODULE_DESCRIPTION("Computone IntelliPort Plus Driver");
294 static int poll_only = 0;
297 static int Eisa_slot;
300 static char rirqs[IP2_MAX_BOARDS];
301 static int Valid_Irqs[] = { 3, 4, 5, 7, 10, 11, 12, 15, 0};
303 /* for sysfs class support */
304 static struct class *ip2_class;
306 // Some functions to keep track of what irq's we have
309 is_valid_irq(int irq)
313 while ((*i != 0) && (*i != irq)) {
320 mark_requested_irq( char irq )
322 rirqs[iindx++] = irq;
327 clear_requested_irq( char irq )
330 for ( i = 0; i < IP2_MAX_BOARDS; ++i ) {
331 if (rirqs[i] == irq) {
341 have_requested_irq( char irq )
343 // array init to zeros so 0 irq will not be requested as a side effect
345 for ( i = 0; i < IP2_MAX_BOARDS; ++i ) {
352 /******************************************************************************/
353 /* Function: init_module() */
354 /* Parameters: None */
355 /* Returns: Success (0) */
358 /* This is a required entry point for an installable module. It simply calls */
359 /* the driver initialisation function and returns what it returns. */
360 /******************************************************************************/
366 printk (KERN_DEBUG "Loading module ...\n" );
372 /******************************************************************************/
373 /* Function: cleanup_module() */
374 /* Parameters: None */
375 /* Returns: Nothing */
378 /* This is a required entry point for an installable module. It has to return */
379 /* the device and the driver to a passive state. It should not be necessary */
380 /* to reset the board fully, especially as the loadware is downloaded */
381 /* externally rather than in the driver. We just want to disable the board */
382 /* and clear the loadware to a reset state. To allow this there has to be a */
383 /* way to detect whether the board has the loadware running at init time to */
384 /* handle subsequent installations of the driver. All memory allocated by the */
385 /* driver should be returned since it may be unloaded from memory. */
386 /******************************************************************************/
395 printk (KERN_DEBUG "Unloading %s: version %s\n", pcName, pcVersion );
397 /* Stop poll timer if we had one. */
399 del_timer ( &PollTimer );
403 /* Reset the boards we have. */
404 for( i = 0; i < IP2_MAX_BOARDS; ++i ) {
405 if ( i2BoardPtrTable[i] ) {
406 iiReset( i2BoardPtrTable[i] );
410 /* The following is done at most once, if any boards were installed. */
411 for ( i = 0; i < IP2_MAX_BOARDS; ++i ) {
412 if ( i2BoardPtrTable[i] ) {
413 iiResetDelay( i2BoardPtrTable[i] );
414 /* free io addresses and Tibet */
415 release_region( ip2config.addr[i], 8 );
416 class_device_destroy(ip2_class, MKDEV(IP2_IPL_MAJOR, 4 * i));
417 devfs_remove("ip2/ipl%d", i);
418 class_device_destroy(ip2_class, MKDEV(IP2_IPL_MAJOR, 4 * i + 1));
419 devfs_remove("ip2/stat%d", i);
421 /* Disable and remove interrupt handler. */
422 if ( (ip2config.irq[i] > 0) && have_requested_irq(ip2config.irq[i]) ) {
423 free_irq ( ip2config.irq[i], (void *)&pcName);
424 clear_requested_irq( ip2config.irq[i]);
427 class_destroy(ip2_class);
429 if ( ( err = tty_unregister_driver ( ip2_tty_driver ) ) ) {
430 printk(KERN_ERR "IP2: failed to unregister tty driver (%d)\n", err);
432 put_tty_driver(ip2_tty_driver);
433 if ( ( err = unregister_chrdev ( IP2_IPL_MAJOR, pcIpl ) ) ) {
434 printk(KERN_ERR "IP2: failed to unregister IPL driver (%d)\n", err);
436 remove_proc_entry("ip2mem", &proc_root);
439 for (i = 0; i < IP2_MAX_BOARDS; i++) {
442 if (ip2config.type[i] == PCI && ip2config.pci_dev[i]) {
443 pci_disable_device(ip2config.pci_dev[i]);
444 ip2config.pci_dev[i] = NULL;
447 if ((pB = i2BoardPtrTable[i]) != 0 ) {
449 i2BoardPtrTable[i] = NULL;
451 if ((DevTableMem[i]) != NULL ) {
452 kfree ( DevTableMem[i] );
453 DevTableMem[i] = NULL;
457 /* Cleanup the iiEllis subsystem. */
460 printk (KERN_DEBUG "IP2 Unloaded\n" );
465 static struct tty_operations ip2_ops = {
469 .put_char = ip2_putchar,
470 .flush_chars = ip2_flush_chars,
471 .write_room = ip2_write_room,
472 .chars_in_buffer = ip2_chars_in_buf,
473 .flush_buffer = ip2_flush_buffer,
475 .throttle = ip2_throttle,
476 .unthrottle = ip2_unthrottle,
477 .set_termios = ip2_set_termios,
478 .set_ldisc = ip2_set_line_discipline,
481 .hangup = ip2_hangup,
482 .read_proc = ip2_read_proc,
483 .tiocmget = ip2_tiocmget,
484 .tiocmset = ip2_tiocmset,
487 /******************************************************************************/
488 /* Function: ip2_loadmain() */
489 /* Parameters: irq, io from command line of insmod et. al. */
490 /* pointer to fip firmware and firmware size for boards */
491 /* Returns: Success (0) */
494 /* This was the required entry point for all drivers (now in ip2.c) */
495 /* It performs all */
496 /* initialisation of the devices and driver structures, and registers itself */
497 /* with the relevant kernel modules. */
498 /******************************************************************************/
499 /* SA_INTERRUPT- if set blocks all interrupts else only this line */
500 /* SA_SHIRQ - for shared irq PCI or maybe EISA only */
501 /* SA_RANDOM - can be source for cert. random number generators */
502 #define IP2_SA_FLAGS 0
505 ip2_loadmain(int *iop, int *irqp, unsigned char *firmware, int firmsize)
511 i2eBordStrPtr pB = NULL;
514 ip2trace (ITRC_NO_PORT, ITRC_INIT, ITRC_ENTER, 0 );
516 /* process command line arguments to modprobe or
517 insmod i.e. iop & irqp */
518 /* irqp and iop should ALWAYS be specified now... But we check
519 them individually just to be sure, anyways... */
520 for ( i = 0; i < IP2_MAX_BOARDS; ++i ) {
522 ip2config.addr[i] = iop[i];
525 ip2config.irq[i] = irqp[i];
527 ip2config.irq[i] = 0;
529 // This is a little bit of a hack. If poll_only=1 on command
530 // line back in ip2.c OR all IRQs on all specified boards are
531 // explicitly set to 0, then drop to poll only mode and override
532 // PCI or EISA interrupts. This superceeds the old hack of
533 // triggering if all interrupts were zero (like da default).
534 // Still a hack but less prone to random acts of terrorism.
536 // What we really should do, now that the IRQ default is set
537 // to -1, is to use 0 as a hard coded, do not probe.
540 poll_only |= irqp[i];
544 poll_only = !poll_only;
546 Fip_firmware = firmware;
547 Fip_firmware_size = firmsize;
549 /* Announce our presence */
550 printk( KERN_INFO "%s version %s\n", pcName, pcVersion );
552 // ip2 can be unloaded and reloaded for no good reason
553 // we can't let that happen here or bad things happen
554 // second load hoses board but not system - fixme later
556 printk( KERN_INFO "Still loaded\n" );
561 ip2_tty_driver = alloc_tty_driver(IP2_MAX_PORTS);
565 /* Initialise the iiEllis subsystem. */
568 /* Initialize arrays. */
569 memset( i2BoardPtrTable, 0, sizeof i2BoardPtrTable );
570 memset( DevTable, 0, sizeof DevTable );
572 /* Initialise all the boards we can find (up to the maximum). */
573 for ( i = 0; i < IP2_MAX_BOARDS; ++i ) {
574 switch ( ip2config.addr[i] ) {
575 case 0: /* skip this slot even if card is present */
578 /* ISA address must be specified */
579 if ( (ip2config.addr[i] < 0x100) || (ip2config.addr[i] > 0x3f8) ) {
580 printk ( KERN_ERR "IP2: Bad ISA board %d address %x\n",
581 i, ip2config.addr[i] );
582 ip2config.addr[i] = 0;
584 ip2config.type[i] = ISA;
586 /* Check for valid irq argument, set for polling if invalid */
587 if (ip2config.irq[i] && !is_valid_irq(ip2config.irq[i])) {
588 printk(KERN_ERR "IP2: Bad IRQ(%d) specified\n",ip2config.irq[i]);
589 ip2config.irq[i] = 0;// 0 is polling and is valid in that sense
596 struct pci_dev *pci_dev_i = NULL;
597 pci_dev_i = pci_find_device(PCI_VENDOR_ID_COMPUTONE,
598 PCI_DEVICE_ID_COMPUTONE_IP2EX, pci_dev_i);
599 if (pci_dev_i != NULL) {
602 if (pci_enable_device(pci_dev_i)) {
603 printk( KERN_ERR "IP2: can't enable PCI device at %s\n",
604 pci_name(pci_dev_i));
607 ip2config.type[i] = PCI;
608 ip2config.pci_dev[i] = pci_dev_i;
610 pci_read_config_dword(pci_dev_i, PCI_BASE_ADDRESS_1, &addr);
612 ip2config.addr[i]=(USHORT)(addr&0xfffe);
614 printk( KERN_ERR "IP2: PCI I/O address error\n");
617 // If the PCI BIOS assigned it, lets try and use it. If we
618 // can't acquire it or it screws up, deal with it then.
620 // if (!is_valid_irq(pci_irq)) {
621 // printk( KERN_ERR "IP2: Bad PCI BIOS IRQ(%d)\n",pci_irq);
624 ip2config.irq[i] = pci_dev_i->irq;
625 } else { // ann error
626 ip2config.addr[i] = 0;
627 if (status == PCIBIOS_DEVICE_NOT_FOUND) {
628 printk( KERN_ERR "IP2: PCI board %d not found\n", i );
630 printk( KERN_ERR "IP2: PCI error 0x%x \n", status );
635 printk( KERN_ERR "IP2: PCI card specified but PCI support not\n");
636 printk( KERN_ERR "IP2: configured in this kernel.\n");
637 printk( KERN_ERR "IP2: Recompile kernel with CONFIG_PCI defined!\n");
638 #endif /* CONFIG_PCI */
641 if ( (ip2config.addr[i] = find_eisa_board( Eisa_slot + 1 )) != 0) {
642 /* Eisa_irq set as side effect, boo */
643 ip2config.type[i] = EISA;
645 ip2config.irq[i] = Eisa_irq;
649 for ( i = 0; i < IP2_MAX_BOARDS; ++i ) {
650 if ( ip2config.addr[i] ) {
651 pB = kmalloc( sizeof(i2eBordStr), GFP_KERNEL);
653 i2BoardPtrTable[i] = pB;
654 memset( pB, 0, sizeof(i2eBordStr) );
655 iiSetAddress( pB, ip2config.addr[i], ii2DelayTimer );
658 printk(KERN_ERR "IP2: board memory allocation error\n");
662 for ( i = 0; i < IP2_MAX_BOARDS; ++i ) {
663 if ( ( pB = i2BoardPtrTable[i] ) != NULL ) {
668 for ( i = 0; i < IP2_MAX_BOARDS; ++i ) {
669 if ( i2BoardPtrTable[i] != NULL ) {
674 ip2trace (ITRC_NO_PORT, ITRC_INIT, 2, 0 );
676 ip2_tty_driver->owner = THIS_MODULE;
677 ip2_tty_driver->name = "ttyF";
678 ip2_tty_driver->devfs_name = "tts/F";
679 ip2_tty_driver->driver_name = pcDriver_name;
680 ip2_tty_driver->major = IP2_TTY_MAJOR;
681 ip2_tty_driver->minor_start = 0;
682 ip2_tty_driver->type = TTY_DRIVER_TYPE_SERIAL;
683 ip2_tty_driver->subtype = SERIAL_TYPE_NORMAL;
684 ip2_tty_driver->init_termios = tty_std_termios;
685 ip2_tty_driver->init_termios.c_cflag = B9600|CS8|CREAD|HUPCL|CLOCAL;
686 ip2_tty_driver->flags = TTY_DRIVER_REAL_RAW | TTY_DRIVER_NO_DEVFS;
687 tty_set_operations(ip2_tty_driver, &ip2_ops);
689 ip2trace (ITRC_NO_PORT, ITRC_INIT, 3, 0 );
691 /* Register the tty devices. */
692 if ( ( err = tty_register_driver ( ip2_tty_driver ) ) ) {
693 printk(KERN_ERR "IP2: failed to register tty driver (%d)\n", err);
694 put_tty_driver(ip2_tty_driver);
697 /* Register the IPL driver. */
698 if ( ( err = register_chrdev ( IP2_IPL_MAJOR, pcIpl, &ip2_ipl ) ) ) {
699 printk(KERN_ERR "IP2: failed to register IPL device (%d)\n", err );
701 /* create the sysfs class */
702 ip2_class = class_create(THIS_MODULE, "ip2");
703 if (IS_ERR(ip2_class)) {
704 err = PTR_ERR(ip2_class);
708 /* Register the read_procmem thing */
709 if (!create_proc_info_entry("ip2mem",0,&proc_root,ip2_read_procmem)) {
710 printk(KERN_ERR "IP2: failed to register read_procmem\n");
713 ip2trace (ITRC_NO_PORT, ITRC_INIT, 4, 0 );
714 /* Register the interrupt handler or poll handler, depending upon the
715 * specified interrupt.
718 for( i = 0; i < IP2_MAX_BOARDS; ++i ) {
719 if ( 0 == ip2config.addr[i] ) {
723 if ( NULL != ( pB = i2BoardPtrTable[i] ) ) {
724 class_device_create(ip2_class, NULL,
725 MKDEV(IP2_IPL_MAJOR, 4 * i),
727 class_device_create(ip2_class, NULL,
728 MKDEV(IP2_IPL_MAJOR, 4 * i + 1),
731 for ( box = 0; box < ABS_MAX_BOXES; ++box )
733 for ( j = 0; j < ABS_BIGGEST_BOX; ++j )
735 if ( pB->i2eChannelMap[box] & (1 << j) )
737 tty_register_device(ip2_tty_driver,
738 j + ABS_BIGGEST_BOX *
739 (box+i*ABS_MAX_BOXES), NULL);
746 // Poll only forces driver to only use polling and
747 // to ignore the probed PCI or EISA interrupts.
748 ip2config.irq[i] = CIR_POLL;
750 if ( ip2config.irq[i] == CIR_POLL ) {
753 PollTimer.expires = POLL_TIMEOUT;
754 add_timer ( &PollTimer );
756 printk( KERN_INFO "IP2: polling\n");
759 if (have_requested_irq(ip2config.irq[i]))
761 rc = request_irq( ip2config.irq[i], ip2_interrupt,
762 IP2_SA_FLAGS | (ip2config.type[i] == PCI ? SA_SHIRQ : 0),
763 pcName, (void *)&pcName);
765 printk(KERN_ERR "IP2: an request_irq failed: error %d\n",rc);
766 ip2config.irq[i] = CIR_POLL;
767 printk( KERN_INFO "IP2: Polling %ld/sec.\n",
768 (POLL_TIMEOUT - jiffies));
771 mark_requested_irq(ip2config.irq[i]);
772 /* Initialise the interrupt handler bottom half (aka slih). */
775 for( i = 0; i < IP2_MAX_BOARDS; ++i ) {
776 if ( i2BoardPtrTable[i] ) {
777 set_irq( i, ip2config.irq[i] ); /* set and enable board interrupt */
781 ip2trace (ITRC_NO_PORT, ITRC_INIT, ITRC_RETURN, 0 );
785 class_destroy(ip2_class);
787 unregister_chrdev(IP2_IPL_MAJOR, "ip2");
792 EXPORT_SYMBOL(ip2_loadmain);
794 /******************************************************************************/
795 /* Function: ip2_init_board() */
796 /* Parameters: Index of board in configuration structure */
797 /* Returns: Success (0) */
800 /* This function initializes the specified board. The loadware is copied to */
801 /* the board, the channel structures are initialized, and the board details */
802 /* are reported on the console. */
803 /******************************************************************************/
805 ip2_init_board( int boardnum )
808 int nports = 0, nboxes = 0;
810 i2eBordStrPtr pB = i2BoardPtrTable[boardnum];
812 if ( !iiInitialize ( pB ) ) {
813 printk ( KERN_ERR "IP2: Failed to initialize board at 0x%x, error %d\n",
814 pB->i2eBase, pB->i2eError );
817 printk(KERN_INFO "IP2: Board %d: addr=0x%x irq=%d\n", boardnum + 1,
818 ip2config.addr[boardnum], ip2config.irq[boardnum] );
820 if (!request_region( ip2config.addr[boardnum], 8, pcName )) {
821 printk(KERN_ERR "IP2: bad addr=0x%x\n", ip2config.addr[boardnum]);
825 if ( iiDownloadAll ( pB, (loadHdrStrPtr)Fip_firmware, 1, Fip_firmware_size )
827 printk ( KERN_ERR "IP2: failed to download loadware\n" );
828 goto err_release_region;
830 printk ( KERN_INFO "IP2: fv=%d.%d.%d lv=%d.%d.%d\n",
831 pB->i2ePom.e.porVersion,
832 pB->i2ePom.e.porRevision,
833 pB->i2ePom.e.porSubRev, pB->i2eLVersion,
834 pB->i2eLRevision, pB->i2eLSub );
837 switch ( pB->i2ePom.e.porID & ~POR_ID_RESERVED ) {
840 printk( KERN_ERR "IP2: Unknown board type, ID = %x\n",
841 pB->i2ePom.e.porID );
843 goto err_release_region;
846 case POR_ID_II_4: /* IntelliPort-II, ISA-4 (4xRJ45) */
847 printk ( KERN_INFO "IP2: ISA-4\n" );
851 case POR_ID_II_8: /* IntelliPort-II, 8-port using standard brick. */
852 printk ( KERN_INFO "IP2: ISA-8 std\n" );
856 case POR_ID_II_8R: /* IntelliPort-II, 8-port using RJ11's (no CTS) */
857 printk ( KERN_INFO "IP2: ISA-8 RJ11\n" );
861 case POR_ID_FIIEX: /* IntelliPort IIEX */
863 int portnum = IP2_PORTS_PER_BOARD * boardnum;
866 for( box = 0; box < ABS_MAX_BOXES; ++box ) {
867 if ( pB->i2eChannelMap[box] != 0 ) {
870 for( i = 0; i < ABS_BIGGEST_BOX; ++i ) {
871 if ( pB->i2eChannelMap[box] & 1<< i ) {
876 DevTableMem[boardnum] = pCh =
877 kmalloc( sizeof(i2ChanStr) * nports, GFP_KERNEL );
879 printk ( KERN_ERR "IP2: (i2_init_channel:) Out of memory.\n");
880 goto err_release_region;
882 if ( !i2InitChannels( pB, nports, pCh ) ) {
883 printk(KERN_ERR "IP2: i2InitChannels failed: %d\n",pB->i2eError);
885 goto err_release_region;
887 pB->i2eChannelPtr = &DevTable[portnum];
888 pB->i2eChannelCnt = ABS_MOST_PORTS;
890 for( box = 0; box < ABS_MAX_BOXES; ++box, portnum += ABS_BIGGEST_BOX ) {
891 for( i = 0; i < ABS_BIGGEST_BOX; ++i ) {
892 if ( pB->i2eChannelMap[box] & (1 << i) ) {
893 DevTable[portnum + i] = pCh;
894 pCh->port_index = portnum + i;
899 printk(KERN_INFO "IP2: EX box=%d ports=%d %d bit\n",
900 nboxes, nports, pB->i2eDataWidth16 ? 16 : 8 );
904 DevTableMem[boardnum] = pCh =
905 kmalloc ( sizeof (i2ChanStr) * nports, GFP_KERNEL );
907 printk ( KERN_ERR "IP2: (i2_init_channel:) Out of memory.\n");
908 goto err_release_region;
910 pB->i2eChannelPtr = pCh;
911 pB->i2eChannelCnt = nports;
912 if ( !i2InitChannels( pB, nports, pCh ) ) {
913 printk(KERN_ERR "IP2: i2InitChannels failed: %d\n",pB->i2eError);
915 goto err_release_region;
917 pB->i2eChannelPtr = &DevTable[IP2_PORTS_PER_BOARD * boardnum];
919 for( i = 0; i < pB->i2eChannelCnt; ++i ) {
920 DevTable[IP2_PORTS_PER_BOARD * boardnum + i] = pCh;
921 pCh->port_index = (IP2_PORTS_PER_BOARD * boardnum) + i;
925 INIT_WORK(&pB->tqueue_interrupt, (void(*)(void*)) ip2_interrupt_bh, pB);
929 release_region(ip2config.addr[boardnum], 8);
932 i2BoardPtrTable[boardnum] = NULL;
936 /******************************************************************************/
937 /* Function: find_eisa_board ( int start_slot ) */
938 /* Parameters: First slot to check */
939 /* Returns: Address of EISA IntelliPort II controller */
942 /* This function searches for an EISA IntelliPort controller, starting */
943 /* from the specified slot number. If the motherboard is not identified as an */
944 /* EISA motherboard, or no valid board ID is selected it returns 0. Otherwise */
945 /* it returns the base address of the controller. */
946 /******************************************************************************/
947 static unsigned short
948 find_eisa_board( int start_slot )
951 unsigned int idm = 0;
952 unsigned int idp = 0;
953 unsigned int base = 0;
960 * First a check for an EISA motherboard, which we do by comparing the
961 * EISA ID registers for the system board and the first couple of slots.
962 * No slot ID should match the system board ID, but on an ISA or PCI
963 * machine the odds are that an empty bus will return similar values for
967 value = (inb(i) << 24) + (inb(i+1) << 16) + (inb(i+2) << 8) + inb(i+3);
968 for( i = 0x1c80; i <= 0x4c80; i += 0x1000 ) {
969 j = (inb(i)<<24)+(inb(i+1)<<16)+(inb(i+2)<<8)+inb(i+3);
975 * OK, so we are inclined to believe that this is an EISA machine. Find
976 * an IntelliPort controller.
978 for( i = start_slot; i < 16; i++ ) {
980 idm = (inb(base + 0xc80) << 8) | (inb(base + 0xc81) & 0xff);
981 idp = (inb(base + 0xc82) << 8) | (inb(base + 0xc83) & 0xff);
983 if ( idm == 0x0e8e ) {
984 if ( idp == 0x0281 || idp == 0x0218 ) {
986 } else if ( idp == 0x0282 || idp == 0x0283 ) {
987 ismine = 3; /* Can do edge-trigger */
998 /* It's some sort of EISA card, but at what address is it configured? */
1000 setup_address = base + 0xc88;
1001 value = inb(base + 0xc86);
1002 setup_irq = (value & 8) ? Valid_Irqs[value & 7] : 0;
1004 if ( (ismine & 2) && !(value & 0x10) ) {
1005 ismine = 1; /* Could be edging, but not */
1008 if ( Eisa_irq == 0 ) {
1009 Eisa_irq = setup_irq;
1010 } else if ( Eisa_irq != setup_irq ) {
1011 printk ( KERN_ERR "IP2: EISA irq mismatch between EISA controllers\n" );
1014 #ifdef IP2DEBUG_INIT
1015 printk(KERN_DEBUG "Computone EISA board in slot %d, I.D. 0x%x%x, Address 0x%x",
1016 base >> 12, idm, idp, setup_address);
1018 printk(KERN_DEBUG ", Interrupt %d %s\n",
1019 setup_irq, (ismine & 2) ? "(edge)" : "(level)");
1021 printk(KERN_DEBUG ", (polled)\n");
1024 return setup_address;
1027 /******************************************************************************/
1028 /* Function: set_irq() */
1029 /* Parameters: index to board in board table */
1031 /* Returns: Success (0) */
1034 /******************************************************************************/
1036 set_irq( int boardnum, int boardIrq )
1038 unsigned char tempCommand[16];
1039 i2eBordStrPtr pB = i2BoardPtrTable[boardnum];
1040 unsigned long flags;
1043 * Notify the boards they may generate interrupts. This is done by
1044 * sending an in-line command to channel 0 on each board. This is why
1045 * the channels have to be defined already. For each board, if the
1046 * interrupt has never been defined, we must do so NOW, directly, since
1047 * board will not send flow control or even give an interrupt until this
1048 * is done. If polling we must send 0 as the interrupt parameter.
1051 // We will get an interrupt here at the end of this function
1053 iiDisableMailIrq(pB);
1055 /* We build up the entire packet header. */
1056 CHANNEL_OF(tempCommand) = 0;
1057 PTYPE_OF(tempCommand) = PTYPE_INLINE;
1058 CMD_COUNT_OF(tempCommand) = 2;
1059 (CMD_OF(tempCommand))[0] = CMDVALUE_IRQ;
1060 (CMD_OF(tempCommand))[1] = boardIrq;
1062 * Write to FIFO; don't bother to adjust fifo capacity for this, since
1063 * board will respond almost immediately after SendMail hit.
1065 WRITE_LOCK_IRQSAVE(&pB->write_fifo_spinlock,flags);
1066 iiWriteBuf(pB, tempCommand, 4);
1067 WRITE_UNLOCK_IRQRESTORE(&pB->write_fifo_spinlock,flags);
1068 pB->i2eUsingIrq = boardIrq;
1069 pB->i2eOutMailWaiting |= MB_OUT_STUFFED;
1071 /* Need to update number of boards before you enable mailbox int */
1074 CHANNEL_OF(tempCommand) = 0;
1075 PTYPE_OF(tempCommand) = PTYPE_BYPASS;
1076 CMD_COUNT_OF(tempCommand) = 6;
1077 (CMD_OF(tempCommand))[0] = 88; // SILO
1078 (CMD_OF(tempCommand))[1] = 64; // chars
1079 (CMD_OF(tempCommand))[2] = 32; // ms
1081 (CMD_OF(tempCommand))[3] = 28; // MAX_BLOCK
1082 (CMD_OF(tempCommand))[4] = 64; // chars
1084 (CMD_OF(tempCommand))[5] = 87; // HW_TEST
1085 WRITE_LOCK_IRQSAVE(&pB->write_fifo_spinlock,flags);
1086 iiWriteBuf(pB, tempCommand, 8);
1087 WRITE_UNLOCK_IRQRESTORE(&pB->write_fifo_spinlock,flags);
1089 CHANNEL_OF(tempCommand) = 0;
1090 PTYPE_OF(tempCommand) = PTYPE_BYPASS;
1091 CMD_COUNT_OF(tempCommand) = 1;
1092 (CMD_OF(tempCommand))[0] = 84; /* get BOX_IDS */
1093 iiWriteBuf(pB, tempCommand, 3);
1096 // enable heartbeat for test porpoises
1097 CHANNEL_OF(tempCommand) = 0;
1098 PTYPE_OF(tempCommand) = PTYPE_BYPASS;
1099 CMD_COUNT_OF(tempCommand) = 2;
1100 (CMD_OF(tempCommand))[0] = 44; /* get ping */
1101 (CMD_OF(tempCommand))[1] = 200; /* 200 ms */
1102 WRITE_LOCK_IRQSAVE(&pB->write_fifo_spinlock,flags);
1103 iiWriteBuf(pB, tempCommand, 4);
1104 WRITE_UNLOCK_IRQRESTORE(&pB->write_fifo_spinlock,flags);
1107 iiEnableMailIrq(pB);
1108 iiSendPendingMail(pB);
1111 /******************************************************************************/
1112 /* Interrupt Handler Section */
1113 /******************************************************************************/
1116 service_all_boards(void)
1121 /* Service every board on the list */
1122 for( i = 0; i < IP2_MAX_BOARDS; ++i ) {
1123 pB = i2BoardPtrTable[i];
1125 i2ServiceBoard( pB );
1131 /******************************************************************************/
1132 /* Function: ip2_interrupt_bh(pB) */
1133 /* Parameters: pB - pointer to the board structure */
1134 /* Returns: Nothing */
1137 /* Service the board in a bottom half interrupt handler and then */
1138 /* reenable the board's interrupts if it has an IRQ number */
1140 /******************************************************************************/
1142 ip2_interrupt_bh(i2eBordStrPtr pB)
1144 // pB better well be set or we have a problem! We can only get
1145 // here from the IMMEDIATE queue. Here, we process the boards.
1146 // Checking pB doesn't cost much and it saves us from the sanity checkers.
1151 i2ServiceBoard( pB );
1152 if( pB->i2eUsingIrq ) {
1153 // Re-enable his interrupts
1154 iiEnableMailIrq(pB);
1160 /******************************************************************************/
1161 /* Function: ip2_interrupt(int irq, void *dev_id, struct pt_regs * regs) */
1162 /* Parameters: irq - interrupt number */
1163 /* pointer to optional device ID structure */
1164 /* pointer to register structure */
1165 /* Returns: Nothing */
1169 /* Our task here is simply to identify each board which needs servicing. */
1170 /* If we are queuing then, queue it to be serviced, and disable its irq */
1171 /* mask otherwise process the board directly. */
1173 /* We could queue by IRQ but that just complicates things on both ends */
1174 /* with very little gain in performance (how many instructions does */
1175 /* it take to iterate on the immediate queue). */
1178 /******************************************************************************/
1180 ip2_interrupt(int irq, void *dev_id, struct pt_regs * regs)
1186 ip2trace (ITRC_NO_PORT, ITRC_INTR, 99, 1, irq );
1188 /* Service just the boards on the list using this irq */
1189 for( i = 0; i < i2nBoards; ++i ) {
1190 pB = i2BoardPtrTable[i];
1192 // Only process those boards which match our IRQ.
1193 // IRQ = 0 for polled boards, we won't poll "IRQ" boards
1195 if ( pB && (pB->i2eUsingIrq == irq) ) {
1199 if (NO_MAIL_HERE != ( pB->i2eStartMail = iiGetMail(pB))) {
1200 // Disable his interrupt (will be enabled when serviced)
1201 // This is mostly to protect from reentrancy.
1202 iiDisableMailIrq(pB);
1204 // Park the board on the immediate queue for processing.
1205 schedule_work(&pB->tqueue_interrupt);
1207 // Make sure the immediate queue is flagged to fire.
1210 // We are using immediate servicing here. This sucks and can
1211 // cause all sorts of havoc with ppp and others. The failsafe
1212 // check on iiSendPendingMail could also throw a hairball.
1213 i2ServiceBoard( pB );
1214 #endif /* USE_IQI */
1220 ip2trace (ITRC_NO_PORT, ITRC_INTR, ITRC_RETURN, 0 );
1221 return IRQ_RETVAL(handled);
1224 /******************************************************************************/
1225 /* Function: ip2_poll(unsigned long arg) */
1227 /* Returns: Nothing */
1230 /* This function calls the library routine i2ServiceBoard for each board in */
1231 /* the board table. This is used instead of the interrupt routine when polled */
1232 /* mode is specified. */
1233 /******************************************************************************/
1235 ip2_poll(unsigned long arg)
1237 ip2trace (ITRC_NO_PORT, ITRC_INTR, 100, 0 );
1239 TimerOn = 0; // it's the truth but not checked in service
1241 // Just polled boards, IRQ = 0 will hit all non-interrupt boards.
1242 // It will NOT poll boards handled by hard interrupts.
1243 // The issue of queued BH interrups is handled in ip2_interrupt().
1244 ip2_interrupt(0, NULL, NULL);
1246 PollTimer.expires = POLL_TIMEOUT;
1247 add_timer( &PollTimer );
1250 ip2trace (ITRC_NO_PORT, ITRC_INTR, ITRC_RETURN, 0 );
1253 static void do_input(void *p)
1255 i2ChanStrPtr pCh = p;
1256 unsigned long flags;
1258 ip2trace(CHANN, ITRC_INPUT, 21, 0 );
1261 if ( pCh->pTTY != NULL ) {
1262 READ_LOCK_IRQSAVE(&pCh->Ibuf_spinlock,flags)
1263 if (!pCh->throttled && (pCh->Ibuf_stuff != pCh->Ibuf_strip)) {
1264 READ_UNLOCK_IRQRESTORE(&pCh->Ibuf_spinlock,flags)
1267 READ_UNLOCK_IRQRESTORE(&pCh->Ibuf_spinlock,flags)
1269 ip2trace(CHANN, ITRC_INPUT, 22, 0 );
1271 i2InputFlush( pCh );
1275 // code duplicated from n_tty (ldisc)
1276 static inline void isig(int sig, struct tty_struct *tty, int flush)
1279 kill_pg(tty->pgrp, sig, 1);
1280 if (flush || !L_NOFLSH(tty)) {
1281 if ( tty->ldisc.flush_buffer )
1282 tty->ldisc.flush_buffer(tty);
1283 i2InputFlush( tty->driver_data );
1287 static void do_status(void *p)
1289 i2ChanStrPtr pCh = p;
1292 status = i2GetStatus( pCh, (I2_BRK|I2_PAR|I2_FRA|I2_OVR) );
1294 ip2trace (CHANN, ITRC_STATUS, 21, 1, status );
1296 if (pCh->pTTY && (status & (I2_BRK|I2_PAR|I2_FRA|I2_OVR)) ) {
1297 if ( (status & I2_BRK) ) {
1298 // code duplicated from n_tty (ldisc)
1299 if (I_IGNBRK(pCh->pTTY))
1301 if (I_BRKINT(pCh->pTTY)) {
1302 isig(SIGINT, pCh->pTTY, 1);
1305 wake_up_interruptible(&pCh->pTTY->read_wait);
1307 #ifdef NEVER_HAPPENS_AS_SETUP_XXX
1308 // and can't work because we don't know the_char
1309 // as the_char is reported on a separate path
1310 // The intelligent board does this stuff as setup
1312 char brkf = TTY_NORMAL;
1313 unsigned char brkc = '\0';
1315 if ( (status & I2_BRK) ) {
1319 else if (status & I2_PAR) {
1322 } else if (status & I2_FRA) {
1325 } else if (status & I2_OVR) {
1329 tmp = pCh->pTTY->real_raw;
1330 pCh->pTTY->real_raw = 0;
1331 pCh->pTTY->ldisc.receive_buf( pCh->pTTY, &brkc, &brkf, 1 );
1332 pCh->pTTY->real_raw = tmp;
1334 #endif /* NEVER_HAPPENS_AS_SETUP_XXX */
1338 if ( status & (I2_DDCD | I2_DDSR | I2_DCTS | I2_DRI) ) {
1339 wake_up_interruptible(&pCh->delta_msr_wait);
1341 if ( (pCh->flags & ASYNC_CHECK_CD) && (status & I2_DDCD) ) {
1342 if ( status & I2_DCD ) {
1344 wake_up_interruptible ( &pCh->open_wait );
1347 if (pCh->pTTY && (!(pCh->pTTY->termios->c_cflag & CLOCAL)) ) {
1348 tty_hangup( pCh->pTTY );
1354 ip2trace (CHANN, ITRC_STATUS, 26, 0 );
1357 /******************************************************************************/
1358 /* Device Open/Close/Ioctl Entry Point Section */
1359 /******************************************************************************/
1361 /******************************************************************************/
1362 /* Function: open_sanity_check() */
1363 /* Parameters: Pointer to tty structure */
1364 /* Pointer to file structure */
1365 /* Returns: Success or failure */
1368 /* Verifies the structure magic numbers and cross links. */
1369 /******************************************************************************/
1370 #ifdef IP2DEBUG_OPEN
1372 open_sanity_check( i2ChanStrPtr pCh, i2eBordStrPtr pBrd )
1374 if ( pBrd->i2eValid != I2E_MAGIC ) {
1375 printk(KERN_ERR "IP2: invalid board structure\n" );
1376 } else if ( pBrd != pCh->pMyBord ) {
1377 printk(KERN_ERR "IP2: board structure pointer mismatch (%p)\n",
1379 } else if ( pBrd->i2eChannelCnt < pCh->port_index ) {
1380 printk(KERN_ERR "IP2: bad device index (%d)\n", pCh->port_index );
1381 } else if (&((i2ChanStrPtr)pBrd->i2eChannelPtr)[pCh->port_index] != pCh) {
1383 printk(KERN_INFO "IP2: all pointers check out!\n" );
1389 /******************************************************************************/
1390 /* Function: ip2_open() */
1391 /* Parameters: Pointer to tty structure */
1392 /* Pointer to file structure */
1393 /* Returns: Success or failure */
1395 /* Description: (MANDATORY) */
1396 /* A successful device open has to run a gauntlet of checks before it */
1397 /* completes. After some sanity checking and pointer setup, the function */
1398 /* blocks until all conditions are satisfied. It then initialises the port to */
1399 /* the default characteristics and returns. */
1400 /******************************************************************************/
1402 ip2_open( PTTY tty, struct file *pFile )
1407 i2ChanStrPtr pCh = DevTable[tty->index];
1409 ip2trace (tty->index, ITRC_OPEN, ITRC_ENTER, 0 );
1411 if ( pCh == NULL ) {
1414 /* Setup pointer links in device and tty structures */
1416 tty->driver_data = pCh;
1418 #ifdef IP2DEBUG_OPEN
1420 "IP2:open(tty=%p,pFile=%p):dev=%s,ch=%d,idx=%d\n",
1421 tty, pFile, tty->name, pCh->infl.hd.i2sChannel, pCh->port_index);
1422 open_sanity_check ( pCh, pCh->pMyBord );
1425 i2QueueCommands(PTYPE_INLINE, pCh, 100, 3, CMD_DTRUP,CMD_RTSUP,CMD_DCD_REP);
1426 pCh->dataSetOut |= (I2_DTR | I2_RTS);
1427 serviceOutgoingFifo( pCh->pMyBord );
1429 /* Block here until the port is ready (per serial and istallion) */
1431 * 1. If the port is in the middle of closing wait for the completion
1432 * and then return the appropriate error.
1434 init_waitqueue_entry(&wait, current);
1435 add_wait_queue(&pCh->close_wait, &wait);
1436 set_current_state( TASK_INTERRUPTIBLE );
1438 if ( tty_hung_up_p(pFile) || ( pCh->flags & ASYNC_CLOSING )) {
1439 if ( pCh->flags & ASYNC_CLOSING ) {
1442 if ( tty_hung_up_p(pFile) ) {
1443 set_current_state( TASK_RUNNING );
1444 remove_wait_queue(&pCh->close_wait, &wait);
1445 return( pCh->flags & ASYNC_HUP_NOTIFY ) ? -EAGAIN : -ERESTARTSYS;
1448 set_current_state( TASK_RUNNING );
1449 remove_wait_queue(&pCh->close_wait, &wait);
1452 * 3. Handle a non-blocking open of a normal port.
1454 if ( (pFile->f_flags & O_NONBLOCK) || (tty->flags & (1<<TTY_IO_ERROR) )) {
1455 pCh->flags |= ASYNC_NORMAL_ACTIVE;
1459 * 4. Now loop waiting for the port to be free and carrier present
1462 if ( tty->termios->c_cflag & CLOCAL )
1465 #ifdef IP2DEBUG_OPEN
1466 printk(KERN_DEBUG "OpenBlock: do_clocal = %d\n", do_clocal);
1471 init_waitqueue_entry(&wait, current);
1472 add_wait_queue(&pCh->open_wait, &wait);
1475 i2QueueCommands(PTYPE_INLINE, pCh, 100, 2, CMD_DTRUP, CMD_RTSUP);
1476 pCh->dataSetOut |= (I2_DTR | I2_RTS);
1477 set_current_state( TASK_INTERRUPTIBLE );
1478 serviceOutgoingFifo( pCh->pMyBord );
1479 if ( tty_hung_up_p(pFile) ) {
1480 set_current_state( TASK_RUNNING );
1481 remove_wait_queue(&pCh->open_wait, &wait);
1482 return ( pCh->flags & ASYNC_HUP_NOTIFY ) ? -EBUSY : -ERESTARTSYS;
1484 if (!(pCh->flags & ASYNC_CLOSING) &&
1485 (do_clocal || (pCh->dataSetIn & I2_DCD) )) {
1490 #ifdef IP2DEBUG_OPEN
1491 printk(KERN_DEBUG "ASYNC_CLOSING = %s\n",
1492 (pCh->flags & ASYNC_CLOSING)?"True":"False");
1493 printk(KERN_DEBUG "OpenBlock: waiting for CD or signal\n");
1495 ip2trace (CHANN, ITRC_OPEN, 3, 2, 0,
1496 (pCh->flags & ASYNC_CLOSING) );
1497 /* check for signal */
1498 if (signal_pending(current)) {
1499 rc = (( pCh->flags & ASYNC_HUP_NOTIFY ) ? -EAGAIN : -ERESTARTSYS);
1504 set_current_state( TASK_RUNNING );
1505 remove_wait_queue(&pCh->open_wait, &wait);
1507 --pCh->wopen; //why count?
1509 ip2trace (CHANN, ITRC_OPEN, 4, 0 );
1514 pCh->flags |= ASYNC_NORMAL_ACTIVE;
1518 /* first open - Assign termios structure to port */
1519 if ( tty->count == 1 ) {
1520 i2QueueCommands(PTYPE_INLINE, pCh, 0, 2, CMD_CTSFL_DSAB, CMD_RTSFL_DSAB);
1521 /* Now we must send the termios settings to the loadware */
1522 set_params( pCh, NULL );
1526 * Now set any i2lib options. These may go away if the i2lib code ends
1527 * up rolled into the mainline.
1529 pCh->channelOptions |= CO_NBLOCK_WRITE;
1531 #ifdef IP2DEBUG_OPEN
1532 printk (KERN_DEBUG "IP2: open completed\n" );
1534 serviceOutgoingFifo( pCh->pMyBord );
1536 ip2trace (CHANN, ITRC_OPEN, ITRC_RETURN, 0 );
1541 /******************************************************************************/
1542 /* Function: ip2_close() */
1543 /* Parameters: Pointer to tty structure */
1544 /* Pointer to file structure */
1545 /* Returns: Nothing */
1550 /******************************************************************************/
1552 ip2_close( PTTY tty, struct file *pFile )
1554 i2ChanStrPtr pCh = tty->driver_data;
1560 ip2trace (CHANN, ITRC_CLOSE, ITRC_ENTER, 0 );
1562 #ifdef IP2DEBUG_OPEN
1563 printk(KERN_DEBUG "IP2:close %s:\n",tty->name);
1566 if ( tty_hung_up_p ( pFile ) ) {
1568 ip2trace (CHANN, ITRC_CLOSE, 2, 1, 2 );
1572 if ( tty->count > 1 ) { /* not the last close */
1574 ip2trace (CHANN, ITRC_CLOSE, 2, 1, 3 );
1578 pCh->flags |= ASYNC_CLOSING; // last close actually
1582 if (pCh->ClosingWaitTime != ASYNC_CLOSING_WAIT_NONE) {
1584 * Before we drop DTR, make sure the transmitter has completely drained.
1585 * This uses an timeout, after which the close
1588 ip2_wait_until_sent(tty, pCh->ClosingWaitTime );
1591 * At this point we stop accepting input. Here we flush the channel
1592 * input buffer which will allow the board to send up more data. Any
1593 * additional input is tossed at interrupt/poll time.
1595 i2InputFlush( pCh );
1597 /* disable DSS reporting */
1598 i2QueueCommands(PTYPE_INLINE, pCh, 100, 4,
1599 CMD_DCD_NREP, CMD_CTS_NREP, CMD_DSR_NREP, CMD_RI_NREP);
1600 if ( !tty || (tty->termios->c_cflag & HUPCL) ) {
1601 i2QueueCommands(PTYPE_INLINE, pCh, 100, 2, CMD_RTSDN, CMD_DTRDN);
1602 pCh->dataSetOut &= ~(I2_DTR | I2_RTS);
1603 i2QueueCommands( PTYPE_INLINE, pCh, 100, 1, CMD_PAUSE(25));
1606 serviceOutgoingFifo ( pCh->pMyBord );
1608 if ( tty->driver->flush_buffer )
1609 tty->driver->flush_buffer(tty);
1610 if ( tty->ldisc.flush_buffer )
1611 tty->ldisc.flush_buffer(tty);
1617 if (pCh->ClosingDelay) {
1618 msleep_interruptible(jiffies_to_msecs(pCh->ClosingDelay));
1620 wake_up_interruptible(&pCh->open_wait);
1623 pCh->flags &=~(ASYNC_NORMAL_ACTIVE|ASYNC_CLOSING);
1624 wake_up_interruptible(&pCh->close_wait);
1626 #ifdef IP2DEBUG_OPEN
1627 DBG_CNT("ip2_close: after wakeups--");
1631 ip2trace (CHANN, ITRC_CLOSE, ITRC_RETURN, 1, 1 );
1636 /******************************************************************************/
1637 /* Function: ip2_hangup() */
1638 /* Parameters: Pointer to tty structure */
1639 /* Returns: Nothing */
1644 /******************************************************************************/
1646 ip2_hangup ( PTTY tty )
1648 i2ChanStrPtr pCh = tty->driver_data;
1654 ip2trace (CHANN, ITRC_HANGUP, ITRC_ENTER, 0 );
1656 ip2_flush_buffer(tty);
1658 /* disable DSS reporting */
1660 i2QueueCommands(PTYPE_BYPASS, pCh, 0, 1, CMD_DCD_NREP);
1661 i2QueueCommands(PTYPE_INLINE, pCh, 0, 2, CMD_CTSFL_DSAB, CMD_RTSFL_DSAB);
1662 if ( (tty->termios->c_cflag & HUPCL) ) {
1663 i2QueueCommands(PTYPE_BYPASS, pCh, 0, 2, CMD_RTSDN, CMD_DTRDN);
1664 pCh->dataSetOut &= ~(I2_DTR | I2_RTS);
1665 i2QueueCommands( PTYPE_INLINE, pCh, 100, 1, CMD_PAUSE(25));
1667 i2QueueCommands(PTYPE_INLINE, pCh, 1, 3,
1668 CMD_CTS_NREP, CMD_DSR_NREP, CMD_RI_NREP);
1669 serviceOutgoingFifo ( pCh->pMyBord );
1671 wake_up_interruptible ( &pCh->delta_msr_wait );
1673 pCh->flags &= ~ASYNC_NORMAL_ACTIVE;
1675 wake_up_interruptible ( &pCh->open_wait );
1677 ip2trace (CHANN, ITRC_HANGUP, ITRC_RETURN, 0 );
1680 /******************************************************************************/
1681 /******************************************************************************/
1682 /* Device Output Section */
1683 /******************************************************************************/
1684 /******************************************************************************/
1686 /******************************************************************************/
1687 /* Function: ip2_write() */
1688 /* Parameters: Pointer to tty structure */
1689 /* Flag denoting data is in user (1) or kernel (0) space */
1690 /* Pointer to data */
1691 /* Number of bytes to write */
1692 /* Returns: Number of bytes actually written */
1694 /* Description: (MANDATORY) */
1697 /******************************************************************************/
1699 ip2_write( PTTY tty, const unsigned char *pData, int count)
1701 i2ChanStrPtr pCh = tty->driver_data;
1703 unsigned long flags;
1705 ip2trace (CHANN, ITRC_WRITE, ITRC_ENTER, 2, count, -1 );
1707 /* Flush out any buffered data left over from ip2_putchar() calls. */
1708 ip2_flush_chars( tty );
1710 /* This is the actual move bit. Make sure it does what we need!!!!! */
1711 WRITE_LOCK_IRQSAVE(&pCh->Pbuf_spinlock,flags);
1712 bytesSent = i2Output( pCh, pData, count, 0 );
1713 WRITE_UNLOCK_IRQRESTORE(&pCh->Pbuf_spinlock,flags);
1715 ip2trace (CHANN, ITRC_WRITE, ITRC_RETURN, 1, bytesSent );
1717 return bytesSent > 0 ? bytesSent : 0;
1720 /******************************************************************************/
1721 /* Function: ip2_putchar() */
1722 /* Parameters: Pointer to tty structure */
1723 /* Character to write */
1724 /* Returns: Nothing */
1729 /******************************************************************************/
1731 ip2_putchar( PTTY tty, unsigned char ch )
1733 i2ChanStrPtr pCh = tty->driver_data;
1734 unsigned long flags;
1736 // ip2trace (CHANN, ITRC_PUTC, ITRC_ENTER, 1, ch );
1738 WRITE_LOCK_IRQSAVE(&pCh->Pbuf_spinlock,flags);
1739 pCh->Pbuf[pCh->Pbuf_stuff++] = ch;
1740 if ( pCh->Pbuf_stuff == sizeof pCh->Pbuf ) {
1741 WRITE_UNLOCK_IRQRESTORE(&pCh->Pbuf_spinlock,flags);
1742 ip2_flush_chars( tty );
1744 WRITE_UNLOCK_IRQRESTORE(&pCh->Pbuf_spinlock,flags);
1746 // ip2trace (CHANN, ITRC_PUTC, ITRC_RETURN, 1, ch );
1749 /******************************************************************************/
1750 /* Function: ip2_flush_chars() */
1751 /* Parameters: Pointer to tty structure */
1752 /* Returns: Nothing */
1756 /******************************************************************************/
1758 ip2_flush_chars( PTTY tty )
1761 i2ChanStrPtr pCh = tty->driver_data;
1762 unsigned long flags;
1764 WRITE_LOCK_IRQSAVE(&pCh->Pbuf_spinlock,flags);
1765 if ( pCh->Pbuf_stuff ) {
1767 // ip2trace (CHANN, ITRC_PUTC, 10, 1, strip );
1770 // We may need to restart i2Output if it does not fullfill this request
1772 strip = i2Output( pCh, pCh->Pbuf, pCh->Pbuf_stuff, 0 );
1773 if ( strip != pCh->Pbuf_stuff ) {
1774 memmove( pCh->Pbuf, &pCh->Pbuf[strip], pCh->Pbuf_stuff - strip );
1776 pCh->Pbuf_stuff -= strip;
1778 WRITE_UNLOCK_IRQRESTORE(&pCh->Pbuf_spinlock,flags);
1781 /******************************************************************************/
1782 /* Function: ip2_write_room() */
1783 /* Parameters: Pointer to tty structure */
1784 /* Returns: Number of bytes that the driver can accept */
1788 /******************************************************************************/
1790 ip2_write_room ( PTTY tty )
1793 i2ChanStrPtr pCh = tty->driver_data;
1794 unsigned long flags;
1796 READ_LOCK_IRQSAVE(&pCh->Pbuf_spinlock,flags);
1797 bytesFree = i2OutputFree( pCh ) - pCh->Pbuf_stuff;
1798 READ_UNLOCK_IRQRESTORE(&pCh->Pbuf_spinlock,flags);
1800 ip2trace (CHANN, ITRC_WRITE, 11, 1, bytesFree );
1802 return ((bytesFree > 0) ? bytesFree : 0);
1805 /******************************************************************************/
1806 /* Function: ip2_chars_in_buf() */
1807 /* Parameters: Pointer to tty structure */
1808 /* Returns: Number of bytes queued for transmission */
1813 /******************************************************************************/
1815 ip2_chars_in_buf ( PTTY tty )
1817 i2ChanStrPtr pCh = tty->driver_data;
1819 unsigned long flags;
1821 ip2trace (CHANN, ITRC_WRITE, 12, 1, pCh->Obuf_char_count + pCh->Pbuf_stuff );
1823 #ifdef IP2DEBUG_WRITE
1824 printk (KERN_DEBUG "IP2: chars in buffer = %d (%d,%d)\n",
1825 pCh->Obuf_char_count + pCh->Pbuf_stuff,
1826 pCh->Obuf_char_count, pCh->Pbuf_stuff );
1828 READ_LOCK_IRQSAVE(&pCh->Obuf_spinlock,flags);
1829 rc = pCh->Obuf_char_count;
1830 READ_UNLOCK_IRQRESTORE(&pCh->Obuf_spinlock,flags);
1831 READ_LOCK_IRQSAVE(&pCh->Pbuf_spinlock,flags);
1832 rc += pCh->Pbuf_stuff;
1833 READ_UNLOCK_IRQRESTORE(&pCh->Pbuf_spinlock,flags);
1837 /******************************************************************************/
1838 /* Function: ip2_flush_buffer() */
1839 /* Parameters: Pointer to tty structure */
1840 /* Returns: Nothing */
1845 /******************************************************************************/
1847 ip2_flush_buffer( PTTY tty )
1849 i2ChanStrPtr pCh = tty->driver_data;
1850 unsigned long flags;
1852 ip2trace (CHANN, ITRC_FLUSH, ITRC_ENTER, 0 );
1854 #ifdef IP2DEBUG_WRITE
1855 printk (KERN_DEBUG "IP2: flush buffer\n" );
1857 WRITE_LOCK_IRQSAVE(&pCh->Pbuf_spinlock,flags);
1858 pCh->Pbuf_stuff = 0;
1859 WRITE_UNLOCK_IRQRESTORE(&pCh->Pbuf_spinlock,flags);
1860 i2FlushOutput( pCh );
1863 ip2trace (CHANN, ITRC_FLUSH, ITRC_RETURN, 0 );
1867 /******************************************************************************/
1868 /* Function: ip2_wait_until_sent() */
1869 /* Parameters: Pointer to tty structure */
1870 /* Timeout for wait. */
1871 /* Returns: Nothing */
1874 /* This function is used in place of the normal tty_wait_until_sent, which */
1875 /* only waits for the driver buffers to be empty (or rather, those buffers */
1876 /* reported by chars_in_buffer) which doesn't work for IP2 due to the */
1877 /* indeterminate number of bytes buffered on the board. */
1878 /******************************************************************************/
1880 ip2_wait_until_sent ( PTTY tty, int timeout )
1883 i2ChanStrPtr pCh = tty->driver_data;
1885 tty_wait_until_sent(tty, timeout );
1886 if ( (i = timeout - (jiffies -i)) > 0)
1887 i2DrainOutput( pCh, i );
1890 /******************************************************************************/
1891 /******************************************************************************/
1892 /* Device Input Section */
1893 /******************************************************************************/
1894 /******************************************************************************/
1896 /******************************************************************************/
1897 /* Function: ip2_throttle() */
1898 /* Parameters: Pointer to tty structure */
1899 /* Returns: Nothing */
1904 /******************************************************************************/
1906 ip2_throttle ( PTTY tty )
1908 i2ChanStrPtr pCh = tty->driver_data;
1910 #ifdef IP2DEBUG_READ
1911 printk (KERN_DEBUG "IP2: throttle\n" );
1914 * Signal the poll/interrupt handlers not to forward incoming data to
1915 * the line discipline. This will cause the buffers to fill up in the
1916 * library and thus cause the library routines to send the flow control
1922 /******************************************************************************/
1923 /* Function: ip2_unthrottle() */
1924 /* Parameters: Pointer to tty structure */
1925 /* Returns: Nothing */
1930 /******************************************************************************/
1932 ip2_unthrottle ( PTTY tty )
1934 i2ChanStrPtr pCh = tty->driver_data;
1935 unsigned long flags;
1937 #ifdef IP2DEBUG_READ
1938 printk (KERN_DEBUG "IP2: unthrottle\n" );
1941 /* Pass incoming data up to the line discipline again. */
1943 i2QueueCommands(PTYPE_BYPASS, pCh, 0, 1, CMD_RESUME);
1944 serviceOutgoingFifo( pCh->pMyBord );
1945 READ_LOCK_IRQSAVE(&pCh->Ibuf_spinlock,flags)
1946 if ( pCh->Ibuf_stuff != pCh->Ibuf_strip ) {
1947 READ_UNLOCK_IRQRESTORE(&pCh->Ibuf_spinlock,flags)
1948 #ifdef IP2DEBUG_READ
1949 printk (KERN_DEBUG "i2Input called from unthrottle\n" );
1953 READ_UNLOCK_IRQRESTORE(&pCh->Ibuf_spinlock,flags)
1957 ip2_start ( PTTY tty )
1959 i2ChanStrPtr pCh = DevTable[tty->index];
1961 i2QueueCommands(PTYPE_BYPASS, pCh, 0, 1, CMD_RESUME);
1962 i2QueueCommands(PTYPE_BYPASS, pCh, 100, 1, CMD_UNSUSPEND);
1963 i2QueueCommands(PTYPE_BYPASS, pCh, 100, 1, CMD_RESUME);
1964 #ifdef IP2DEBUG_WRITE
1965 printk (KERN_DEBUG "IP2: start tx\n" );
1970 ip2_stop ( PTTY tty )
1972 i2ChanStrPtr pCh = DevTable[tty->index];
1974 i2QueueCommands(PTYPE_BYPASS, pCh, 100, 1, CMD_SUSPEND);
1975 #ifdef IP2DEBUG_WRITE
1976 printk (KERN_DEBUG "IP2: stop tx\n" );
1980 /******************************************************************************/
1981 /* Device Ioctl Section */
1982 /******************************************************************************/
1984 static int ip2_tiocmget(struct tty_struct *tty, struct file *file)
1986 i2ChanStrPtr pCh = DevTable[tty->index];
1987 #ifdef ENABLE_DSSNOW
1995 FIXME - the following code is causing a NULL pointer dereference in
1996 2.3.51 in an interrupt handler. It's suppose to prompt the board
1997 to return the DSS signal status immediately. Why doesn't it do
1998 the same thing in 2.2.14?
2001 /* This thing is still busted in the 1.2.12 driver on 2.4.x
2002 and even hoses the serial console so the oops can be trapped.
2005 #ifdef ENABLE_DSSNOW
2006 i2QueueCommands(PTYPE_BYPASS, pCh, 100, 1, CMD_DSS_NOW);
2008 init_waitqueue_entry(&wait, current);
2009 add_wait_queue(&pCh->dss_now_wait, &wait);
2010 set_current_state( TASK_INTERRUPTIBLE );
2012 serviceOutgoingFifo( pCh->pMyBord );
2016 set_current_state( TASK_RUNNING );
2017 remove_wait_queue(&pCh->dss_now_wait, &wait);
2019 if (signal_pending(current)) {
2023 return ((pCh->dataSetOut & I2_RTS) ? TIOCM_RTS : 0)
2024 | ((pCh->dataSetOut & I2_DTR) ? TIOCM_DTR : 0)
2025 | ((pCh->dataSetIn & I2_DCD) ? TIOCM_CAR : 0)
2026 | ((pCh->dataSetIn & I2_RI) ? TIOCM_RNG : 0)
2027 | ((pCh->dataSetIn & I2_DSR) ? TIOCM_DSR : 0)
2028 | ((pCh->dataSetIn & I2_CTS) ? TIOCM_CTS : 0);
2031 static int ip2_tiocmset(struct tty_struct *tty, struct file *file,
2032 unsigned int set, unsigned int clear)
2034 i2ChanStrPtr pCh = DevTable[tty->index];
2039 if (set & TIOCM_RTS) {
2040 i2QueueCommands(PTYPE_INLINE, pCh, 100, 1, CMD_RTSUP);
2041 pCh->dataSetOut |= I2_RTS;
2043 if (set & TIOCM_DTR) {
2044 i2QueueCommands(PTYPE_INLINE, pCh, 100, 1, CMD_DTRUP);
2045 pCh->dataSetOut |= I2_DTR;
2048 if (clear & TIOCM_RTS) {
2049 i2QueueCommands(PTYPE_INLINE, pCh, 100, 1, CMD_RTSDN);
2050 pCh->dataSetOut &= ~I2_RTS;
2052 if (clear & TIOCM_DTR) {
2053 i2QueueCommands(PTYPE_INLINE, pCh, 100, 1, CMD_DTRDN);
2054 pCh->dataSetOut &= ~I2_DTR;
2056 serviceOutgoingFifo( pCh->pMyBord );
2060 /******************************************************************************/
2061 /* Function: ip2_ioctl() */
2062 /* Parameters: Pointer to tty structure */
2063 /* Pointer to file structure */
2066 /* Returns: Success or failure */
2071 /******************************************************************************/
2073 ip2_ioctl ( PTTY tty, struct file *pFile, UINT cmd, ULONG arg )
2076 i2ChanStrPtr pCh = DevTable[tty->index];
2078 struct async_icount cprev, cnow; /* kernel counter temps */
2079 struct serial_icounter_struct __user *p_cuser;
2081 unsigned long flags;
2082 void __user *argp = (void __user *)arg;
2089 ip2trace (CHANN, ITRC_IOCTL, ITRC_ENTER, 2, cmd, arg );
2091 #ifdef IP2DEBUG_IOCTL
2092 printk(KERN_DEBUG "IP2: ioctl cmd (%x), arg (%lx)\n", cmd, arg );
2098 ip2trace (CHANN, ITRC_IOCTL, 2, 1, rc );
2100 rc = get_serial_info(pCh, argp);
2107 ip2trace (CHANN, ITRC_IOCTL, 3, 1, rc );
2109 rc = set_serial_info(pCh, argp);
2115 rc = tty_check_change(tty);
2120 //return -ENOIOCTLCMD;
2123 //return -ENOIOCTLCMD;
2126 if (STOP_CHAR(tty) != __DISABLED_CHAR) {
2127 i2QueueCommands( PTYPE_BYPASS, pCh, 100, 1,
2128 CMD_XMIT_NOW(STOP_CHAR(tty)));
2132 if (START_CHAR(tty) != __DISABLED_CHAR) {
2133 i2QueueCommands( PTYPE_BYPASS, pCh, 100, 1,
2134 CMD_XMIT_NOW(START_CHAR(tty)));
2142 case TCSBRK: /* SVID version: non-zero arg --> no break */
2143 rc = tty_check_change(tty);
2145 ip2trace (CHANN, ITRC_IOCTL, 4, 1, rc );
2148 ip2_wait_until_sent(tty,0);
2150 i2QueueCommands(PTYPE_INLINE, pCh, 100, 1, CMD_SEND_BRK(250));
2151 serviceOutgoingFifo( pCh->pMyBord );
2156 case TCSBRKP: /* support for POSIX tcsendbreak() */
2157 rc = tty_check_change(tty);
2159 ip2trace (CHANN, ITRC_IOCTL, 5, 1, rc );
2162 ip2_wait_until_sent(tty,0);
2163 i2QueueCommands(PTYPE_INLINE, pCh, 100, 1,
2164 CMD_SEND_BRK(arg ? arg*100 : 250));
2165 serviceOutgoingFifo ( pCh->pMyBord );
2171 ip2trace (CHANN, ITRC_IOCTL, 6, 1, rc );
2173 rc = put_user(C_CLOCAL(tty) ? 1 : 0, (unsigned long __user *)argp);
2180 ip2trace (CHANN, ITRC_IOCTL, 7, 1, rc );
2182 rc = get_user(arg,(unsigned long __user *) argp);
2185 tty->termios->c_cflag = ((tty->termios->c_cflag & ~CLOCAL)
2186 | (arg ? CLOCAL : 0));
2191 * Wait for any of the 4 modem inputs (DCD,RI,DSR,CTS) to change - mask
2192 * passed in arg for lines of interest (use |'ed TIOCM_RNG/DSR/CD/CTS
2193 * for masking). Caller should use TIOCGICOUNT to see which one it was
2196 WRITE_LOCK_IRQSAVE(&pB->read_fifo_spinlock, flags);
2197 cprev = pCh->icount; /* note the counters on entry */
2198 WRITE_UNLOCK_IRQRESTORE(&pB->read_fifo_spinlock, flags);
2199 i2QueueCommands(PTYPE_BYPASS, pCh, 100, 4,
2200 CMD_DCD_REP, CMD_CTS_REP, CMD_DSR_REP, CMD_RI_REP);
2201 init_waitqueue_entry(&wait, current);
2202 add_wait_queue(&pCh->delta_msr_wait, &wait);
2203 set_current_state( TASK_INTERRUPTIBLE );
2205 serviceOutgoingFifo( pCh->pMyBord );
2207 ip2trace (CHANN, ITRC_IOCTL, 10, 0 );
2211 ip2trace (CHANN, ITRC_IOCTL, 11, 0 );
2213 /* see if a signal did it */
2214 if (signal_pending(current)) {
2218 WRITE_LOCK_IRQSAVE(&pB->read_fifo_spinlock, flags);
2219 cnow = pCh->icount; /* atomic copy */
2220 WRITE_UNLOCK_IRQRESTORE(&pB->read_fifo_spinlock, flags);
2221 if (cnow.rng == cprev.rng && cnow.dsr == cprev.dsr &&
2222 cnow.dcd == cprev.dcd && cnow.cts == cprev.cts) {
2223 rc = -EIO; /* no change => rc */
2226 if (((arg & TIOCM_RNG) && (cnow.rng != cprev.rng)) ||
2227 ((arg & TIOCM_DSR) && (cnow.dsr != cprev.dsr)) ||
2228 ((arg & TIOCM_CD) && (cnow.dcd != cprev.dcd)) ||
2229 ((arg & TIOCM_CTS) && (cnow.cts != cprev.cts)) ) {
2235 set_current_state( TASK_RUNNING );
2236 remove_wait_queue(&pCh->delta_msr_wait, &wait);
2238 i2QueueCommands(PTYPE_BYPASS, pCh, 100, 3,
2239 CMD_CTS_NREP, CMD_DSR_NREP, CMD_RI_NREP);
2240 if ( ! (pCh->flags & ASYNC_CHECK_CD)) {
2241 i2QueueCommands(PTYPE_BYPASS, pCh, 100, 1, CMD_DCD_NREP);
2243 serviceOutgoingFifo( pCh->pMyBord );
2248 * Get counter of input serial line interrupts (DCD,RI,DSR,CTS)
2249 * Return: write counters to the user passed counter struct
2250 * NB: both 1->0 and 0->1 transitions are counted except for RI where
2251 * only 0->1 is counted. The controller is quite capable of counting
2252 * both, but this done to preserve compatibility with the standard
2256 ip2trace (CHANN, ITRC_IOCTL, 11, 1, rc );
2258 WRITE_LOCK_IRQSAVE(&pB->read_fifo_spinlock, flags);
2260 WRITE_UNLOCK_IRQRESTORE(&pB->read_fifo_spinlock, flags);
2262 rc = put_user(cnow.cts, &p_cuser->cts);
2263 rc = put_user(cnow.dsr, &p_cuser->dsr);
2264 rc = put_user(cnow.rng, &p_cuser->rng);
2265 rc = put_user(cnow.dcd, &p_cuser->dcd);
2266 rc = put_user(cnow.rx, &p_cuser->rx);
2267 rc = put_user(cnow.tx, &p_cuser->tx);
2268 rc = put_user(cnow.frame, &p_cuser->frame);
2269 rc = put_user(cnow.overrun, &p_cuser->overrun);
2270 rc = put_user(cnow.parity, &p_cuser->parity);
2271 rc = put_user(cnow.brk, &p_cuser->brk);
2272 rc = put_user(cnow.buf_overrun, &p_cuser->buf_overrun);
2276 * The rest are not supported by this driver. By returning -ENOIOCTLCMD they
2277 * will be passed to the line discipline for it to handle.
2283 case TIOCSERGSTRUCT:
2284 case TIOCSERGETMULTI:
2285 case TIOCSERSETMULTI:
2288 ip2trace (CHANN, ITRC_IOCTL, 12, 0 );
2294 ip2trace (CHANN, ITRC_IOCTL, ITRC_RETURN, 0 );
2299 /******************************************************************************/
2300 /* Function: GetSerialInfo() */
2301 /* Parameters: Pointer to channel structure */
2302 /* Pointer to old termios structure */
2303 /* Returns: Nothing */
2306 /* This is to support the setserial command, and requires processing of the */
2307 /* standard Linux serial structure. */
2308 /******************************************************************************/
2310 get_serial_info ( i2ChanStrPtr pCh, struct serial_struct __user *retinfo )
2312 struct serial_struct tmp;
2314 memset ( &tmp, 0, sizeof(tmp) );
2315 tmp.type = pCh->pMyBord->channelBtypes.bid_value[(pCh->port_index & (IP2_PORTS_PER_BOARD-1))/16];
2316 if (BID_HAS_654(tmp.type)) {
2317 tmp.type = PORT_16650;
2319 tmp.type = PORT_CIRRUS;
2321 tmp.line = pCh->port_index;
2322 tmp.port = pCh->pMyBord->i2eBase;
2323 tmp.irq = ip2config.irq[pCh->port_index/64];
2324 tmp.flags = pCh->flags;
2325 tmp.baud_base = pCh->BaudBase;
2326 tmp.close_delay = pCh->ClosingDelay;
2327 tmp.closing_wait = pCh->ClosingWaitTime;
2328 tmp.custom_divisor = pCh->BaudDivisor;
2329 return copy_to_user(retinfo,&tmp,sizeof(*retinfo));
2332 /******************************************************************************/
2333 /* Function: SetSerialInfo() */
2334 /* Parameters: Pointer to channel structure */
2335 /* Pointer to old termios structure */
2336 /* Returns: Nothing */
2339 /* This function provides support for setserial, which uses the TIOCSSERIAL */
2340 /* ioctl. Not all setserial parameters are relevant. If the user attempts to */
2341 /* change the IRQ, address or type of the port the ioctl fails. */
2342 /******************************************************************************/
2344 set_serial_info( i2ChanStrPtr pCh, struct serial_struct __user *new_info )
2346 struct serial_struct ns;
2347 int old_flags, old_baud_divisor;
2349 if (copy_from_user(&ns, new_info, sizeof (ns)))
2353 * We don't allow setserial to change IRQ, board address, type or baud
2354 * base. Also line nunber as such is meaningless but we use it for our
2355 * array index so it is fixed also.
2357 if ( (ns.irq != ip2config.irq[pCh->port_index])
2358 || ((int) ns.port != ((int) (pCh->pMyBord->i2eBase)))
2359 || (ns.baud_base != pCh->BaudBase)
2360 || (ns.line != pCh->port_index) ) {
2364 old_flags = pCh->flags;
2365 old_baud_divisor = pCh->BaudDivisor;
2367 if ( !capable(CAP_SYS_ADMIN) ) {
2368 if ( ( ns.close_delay != pCh->ClosingDelay ) ||
2369 ( (ns.flags & ~ASYNC_USR_MASK) !=
2370 (pCh->flags & ~ASYNC_USR_MASK) ) ) {
2374 pCh->flags = (pCh->flags & ~ASYNC_USR_MASK) |
2375 (ns.flags & ASYNC_USR_MASK);
2376 pCh->BaudDivisor = ns.custom_divisor;
2378 pCh->flags = (pCh->flags & ~ASYNC_FLAGS) |
2379 (ns.flags & ASYNC_FLAGS);
2380 pCh->BaudDivisor = ns.custom_divisor;
2381 pCh->ClosingDelay = ns.close_delay * HZ/100;
2382 pCh->ClosingWaitTime = ns.closing_wait * HZ/100;
2385 if ( ( (old_flags & ASYNC_SPD_MASK) != (pCh->flags & ASYNC_SPD_MASK) )
2386 || (old_baud_divisor != pCh->BaudDivisor) ) {
2387 // Invalidate speed and reset parameters
2388 set_params( pCh, NULL );
2394 /******************************************************************************/
2395 /* Function: ip2_set_termios() */
2396 /* Parameters: Pointer to tty structure */
2397 /* Pointer to old termios structure */
2398 /* Returns: Nothing */
2403 /******************************************************************************/
2405 ip2_set_termios( PTTY tty, struct termios *old_termios )
2407 i2ChanStrPtr pCh = (i2ChanStrPtr)tty->driver_data;
2409 #ifdef IP2DEBUG_IOCTL
2410 printk (KERN_DEBUG "IP2: set termios %p\n", old_termios );
2413 set_params( pCh, old_termios );
2416 /******************************************************************************/
2417 /* Function: ip2_set_line_discipline() */
2418 /* Parameters: Pointer to tty structure */
2419 /* Returns: Nothing */
2421 /* Description: Does nothing */
2424 /******************************************************************************/
2426 ip2_set_line_discipline ( PTTY tty )
2428 #ifdef IP2DEBUG_IOCTL
2429 printk (KERN_DEBUG "IP2: set line discipline\n" );
2432 ip2trace (((i2ChanStrPtr)tty->driver_data)->port_index, ITRC_IOCTL, 16, 0 );
2436 /******************************************************************************/
2437 /* Function: SetLine Characteristics() */
2438 /* Parameters: Pointer to channel structure */
2439 /* Returns: Nothing */
2442 /* This routine is called to update the channel structure with the new line */
2443 /* characteristics, and send the appropriate commands to the board when they */
2445 /******************************************************************************/
2447 set_params( i2ChanStrPtr pCh, struct termios *o_tios )
2449 tcflag_t cflag, iflag, lflag;
2450 char stop_char, start_char;
2451 struct termios dummy;
2453 lflag = pCh->pTTY->termios->c_lflag;
2454 cflag = pCh->pTTY->termios->c_cflag;
2455 iflag = pCh->pTTY->termios->c_iflag;
2457 if (o_tios == NULL) {
2458 dummy.c_lflag = ~lflag;
2459 dummy.c_cflag = ~cflag;
2460 dummy.c_iflag = ~iflag;
2465 switch ( cflag & CBAUD ) {
2467 i2QueueCommands( PTYPE_BYPASS, pCh, 100, 2, CMD_RTSDN, CMD_DTRDN);
2468 pCh->dataSetOut &= ~(I2_DTR | I2_RTS);
2469 i2QueueCommands( PTYPE_INLINE, pCh, 100, 1, CMD_PAUSE(25));
2470 pCh->pTTY->termios->c_cflag |= (CBAUD & o_tios->c_cflag);
2475 * This is the speed that is overloaded with all the other high
2476 * speeds, depending upon the flag settings.
2478 if ( ( pCh->flags & ASYNC_SPD_MASK ) == ASYNC_SPD_HI ) {
2479 pCh->speed = CBR_57600;
2480 } else if ( (pCh->flags & ASYNC_SPD_MASK) == ASYNC_SPD_VHI ) {
2481 pCh->speed = CBR_115200;
2482 } else if ( (pCh->flags & ASYNC_SPD_MASK) == ASYNC_SPD_CUST ) {
2483 pCh->speed = CBR_C1;
2485 pCh->speed = CBR_38400;
2488 case B50: pCh->speed = CBR_50; break;
2489 case B75: pCh->speed = CBR_75; break;
2490 case B110: pCh->speed = CBR_110; break;
2491 case B134: pCh->speed = CBR_134; break;
2492 case B150: pCh->speed = CBR_150; break;
2493 case B200: pCh->speed = CBR_200; break;
2494 case B300: pCh->speed = CBR_300; break;
2495 case B600: pCh->speed = CBR_600; break;
2496 case B1200: pCh->speed = CBR_1200; break;
2497 case B1800: pCh->speed = CBR_1800; break;
2498 case B2400: pCh->speed = CBR_2400; break;
2499 case B4800: pCh->speed = CBR_4800; break;
2500 case B9600: pCh->speed = CBR_9600; break;
2501 case B19200: pCh->speed = CBR_19200; break;
2502 case B57600: pCh->speed = CBR_57600; break;
2503 case B115200: pCh->speed = CBR_115200; break;
2504 case B153600: pCh->speed = CBR_153600; break;
2505 case B230400: pCh->speed = CBR_230400; break;
2506 case B307200: pCh->speed = CBR_307200; break;
2507 case B460800: pCh->speed = CBR_460800; break;
2508 case B921600: pCh->speed = CBR_921600; break;
2509 default: pCh->speed = CBR_9600; break;
2511 if ( pCh->speed == CBR_C1 ) {
2512 // Process the custom speed parameters.
2513 int bps = pCh->BaudBase / pCh->BaudDivisor;
2514 if ( bps == 921600 ) {
2515 pCh->speed = CBR_921600;
2518 i2QueueCommands( PTYPE_INLINE, pCh, 100, 1, CMD_BAUD_DEF1(bps) );
2521 i2QueueCommands( PTYPE_INLINE, pCh, 100, 1, CMD_SETBAUD(pCh->speed));
2523 i2QueueCommands ( PTYPE_INLINE, pCh, 100, 2, CMD_DTRUP, CMD_RTSUP);
2524 pCh->dataSetOut |= (I2_DTR | I2_RTS);
2526 if ( (CSTOPB & cflag) ^ (CSTOPB & o_tios->c_cflag))
2528 i2QueueCommands ( PTYPE_INLINE, pCh, 100, 1,
2529 CMD_SETSTOP( ( cflag & CSTOPB ) ? CST_2 : CST_1));
2531 if (((PARENB|PARODD) & cflag) ^ ((PARENB|PARODD) & o_tios->c_cflag))
2533 i2QueueCommands ( PTYPE_INLINE, pCh, 100, 1,
2535 (cflag & PARENB ? (cflag & PARODD ? CSP_OD : CSP_EV) : CSP_NP)
2539 /* byte size and parity */
2540 if ( (CSIZE & cflag)^(CSIZE & o_tios->c_cflag))
2543 switch ( cflag & CSIZE ) {
2544 case CS5: datasize = CSZ_5; break;
2545 case CS6: datasize = CSZ_6; break;
2546 case CS7: datasize = CSZ_7; break;
2547 case CS8: datasize = CSZ_8; break;
2548 default: datasize = CSZ_5; break; /* as per serial.c */
2550 i2QueueCommands ( PTYPE_INLINE, pCh, 100, 1, CMD_SETBITS(datasize) );
2552 /* Process CTS flow control flag setting */
2553 if ( (cflag & CRTSCTS) ) {
2554 i2QueueCommands(PTYPE_INLINE, pCh, 100,
2555 2, CMD_CTSFL_ENAB, CMD_RTSFL_ENAB);
2557 i2QueueCommands(PTYPE_INLINE, pCh, 100,
2558 2, CMD_CTSFL_DSAB, CMD_RTSFL_DSAB);
2561 // Process XON/XOFF flow control flags settings
2563 stop_char = STOP_CHAR(pCh->pTTY);
2564 start_char = START_CHAR(pCh->pTTY);
2566 //////////// can't be \000
2567 if (stop_char == __DISABLED_CHAR )
2569 stop_char = ~__DISABLED_CHAR;
2571 if (start_char == __DISABLED_CHAR )
2573 start_char = ~__DISABLED_CHAR;
2575 /////////////////////////////////
2577 if ( o_tios->c_cc[VSTART] != start_char )
2579 i2QueueCommands(PTYPE_BYPASS, pCh, 100, 1, CMD_DEF_IXON(start_char));
2580 i2QueueCommands(PTYPE_INLINE, pCh, 100, 1, CMD_DEF_OXON(start_char));
2582 if ( o_tios->c_cc[VSTOP] != stop_char )
2584 i2QueueCommands(PTYPE_BYPASS, pCh, 100, 1, CMD_DEF_IXOFF(stop_char));
2585 i2QueueCommands(PTYPE_INLINE, pCh, 100, 1, CMD_DEF_OXOFF(stop_char));
2587 if (stop_char == __DISABLED_CHAR )
2589 stop_char = ~__DISABLED_CHAR; //TEST123
2592 if ((iflag & (IXOFF))^(o_tios->c_iflag & (IXOFF)))
2594 if ( iflag & IXOFF ) { // Enable XOFF output flow control
2595 i2QueueCommands(PTYPE_INLINE, pCh, 100, 1, CMD_OXON_OPT(COX_XON));
2596 } else { // Disable XOFF output flow control
2598 i2QueueCommands(PTYPE_INLINE, pCh, 100, 1, CMD_OXON_OPT(COX_NONE));
2601 if (start_char == __DISABLED_CHAR )
2605 if ((iflag & (IXON|IXANY)) ^ (o_tios->c_iflag & (IXON|IXANY)))
2607 if ( iflag & IXON ) {
2608 if ( iflag & IXANY ) { // Enable XON/XANY output flow control
2609 i2QueueCommands(PTYPE_INLINE, pCh, 100, 1, CMD_IXON_OPT(CIX_XANY));
2610 } else { // Enable XON output flow control
2611 i2QueueCommands(PTYPE_INLINE, pCh, 100, 1, CMD_IXON_OPT(CIX_XON));
2613 } else { // Disable XON output flow control
2615 i2QueueCommands(PTYPE_INLINE, pCh, 100, 1, CMD_IXON_OPT(CIX_NONE));
2618 if ( (iflag & ISTRIP) ^ ( o_tios->c_iflag & (ISTRIP)) )
2620 i2QueueCommands(PTYPE_INLINE, pCh, 100, 1,
2621 CMD_ISTRIP_OPT((iflag & ISTRIP ? 1 : 0)));
2623 if ( (iflag & INPCK) ^ ( o_tios->c_iflag & (INPCK)) )
2625 i2QueueCommands(PTYPE_INLINE, pCh, 100, 1,
2626 CMD_PARCHK((iflag & INPCK) ? CPK_ENAB : CPK_DSAB));
2629 if ( (iflag & (IGNBRK|PARMRK|BRKINT|IGNPAR))
2630 ^ ( o_tios->c_iflag & (IGNBRK|PARMRK|BRKINT|IGNPAR)) )
2635 if ( iflag & IGNBRK ) { /* Ignore breaks altogether */
2636 /* Ignore breaks altogether */
2637 i2QueueCommands(PTYPE_INLINE, pCh, 100, 1, CMD_BRK_NREP);
2639 if ( iflag & BRKINT ) {
2640 if ( iflag & PARMRK ) {
2641 brkrpt = 0x0a; // exception an inline triple
2643 brkrpt = 0x1a; // exception and NULL
2645 brkrpt |= 0x04; // flush input
2647 if ( iflag & PARMRK ) {
2648 brkrpt = 0x0b; //POSIX triple \0377 \0 \0
2650 brkrpt = 0x01; // Null only
2653 i2QueueCommands(PTYPE_INLINE, pCh, 100, 1, CMD_BRK_REP(brkrpt));
2656 if (iflag & IGNPAR) {
2658 /* would be 2 for not cirrus bug */
2659 /* would be 0x20 cept for cirrus bug */
2661 if ( iflag & PARMRK ) {
2663 * Replace error characters with 3-byte sequence (\0377,\0,char)
2666 i2QueueCommands(PTYPE_INLINE, pCh, 100, 1, CMD_ISTRIP_OPT((char)0));
2671 i2QueueCommands(PTYPE_INLINE, pCh, 100, 1, CMD_SET_ERROR(parrpt));
2673 if (cflag & CLOCAL) {
2674 // Status reporting fails for DCD if this is off
2675 i2QueueCommands(PTYPE_INLINE, pCh, 100, 1, CMD_DCD_NREP);
2676 pCh->flags &= ~ASYNC_CHECK_CD;
2678 i2QueueCommands(PTYPE_INLINE, pCh, 100, 1, CMD_DCD_REP);
2679 pCh->flags |= ASYNC_CHECK_CD;
2683 i2DrainOutput( pCh, 100 );
2686 /******************************************************************************/
2687 /* IPL Device Section */
2688 /******************************************************************************/
2690 /******************************************************************************/
2691 /* Function: ip2_ipl_read() */
2692 /* Parameters: Pointer to device inode */
2693 /* Pointer to file structure */
2694 /* Pointer to data */
2695 /* Number of bytes to read */
2696 /* Returns: Success or failure */
2698 /* Description: Ugly */
2701 /******************************************************************************/
2705 ip2_ipl_read(struct file *pFile, char __user *pData, size_t count, loff_t *off )
2707 unsigned int minor = iminor(pFile->f_dentry->d_inode);
2711 printk (KERN_DEBUG "IP2IPL: read %p, %d bytes\n", pData, count );
2715 case 0: // IPL device
2718 case 1: // Status dump
2721 case 2: // Ping device
2724 case 3: // Trace device
2725 rc = DumpTraceBuffer ( pData, count );
2727 case 4: // Trace device
2728 rc = DumpFifoBuffer ( pData, count );
2738 DumpFifoBuffer ( char __user *pData, int count )
2742 rc = copy_to_user(pData, DBGBuf, count);
2744 printk(KERN_DEBUG "Last index %d\n", I );
2747 #endif /* DEBUG_FIFO */
2752 DumpTraceBuffer ( char __user *pData, int count )
2754 #ifdef IP2DEBUG_TRACE
2758 int *pIndex = (int __user *)pData;
2760 if ( count < (sizeof(int) * 6) ) {
2763 rc = put_user(tracewrap, pIndex );
2764 rc = put_user(TRACEMAX, ++pIndex );
2765 rc = put_user(tracestrip, ++pIndex );
2766 rc = put_user(tracestuff, ++pIndex );
2767 pData += sizeof(int) * 6;
2768 count -= sizeof(int) * 6;
2770 dumpcount = tracestuff - tracestrip;
2771 if ( dumpcount < 0 ) {
2772 dumpcount += TRACEMAX;
2774 if ( dumpcount > count ) {
2777 chunk = TRACEMAX - tracestrip;
2778 if ( dumpcount > chunk ) {
2779 rc = copy_to_user(pData, &tracebuf[tracestrip],
2780 chunk * sizeof(tracebuf[0]) );
2781 pData += chunk * sizeof(tracebuf[0]);
2783 chunk = dumpcount - chunk;
2787 rc = copy_to_user(pData, &tracebuf[tracestrip],
2788 chunk * sizeof(tracebuf[0]) );
2789 tracestrip += chunk;
2792 rc = put_user(tracestrip, ++pIndex );
2793 rc = put_user(tracestuff, ++pIndex );
2801 /******************************************************************************/
2802 /* Function: ip2_ipl_write() */
2804 /* Pointer to file structure */
2805 /* Pointer to data */
2806 /* Number of bytes to write */
2807 /* Returns: Success or failure */
2812 /******************************************************************************/
2814 ip2_ipl_write(struct file *pFile, const char __user *pData, size_t count, loff_t *off)
2817 printk (KERN_DEBUG "IP2IPL: write %p, %d bytes\n", pData, count );
2822 /******************************************************************************/
2823 /* Function: ip2_ipl_ioctl() */
2824 /* Parameters: Pointer to device inode */
2825 /* Pointer to file structure */
2828 /* Returns: Success or failure */
2833 /******************************************************************************/
2835 ip2_ipl_ioctl ( struct inode *pInode, struct file *pFile, UINT cmd, ULONG arg )
2837 unsigned int iplminor = iminor(pInode);
2839 void __user *argp = (void __user *)arg;
2840 ULONG __user *pIndex = argp;
2841 i2eBordStrPtr pB = i2BoardPtrTable[iplminor / 4];
2845 printk (KERN_DEBUG "IP2IPL: ioctl cmd %d, arg %ld\n", cmd, arg );
2848 switch ( iplminor ) {
2849 case 0: // IPL device
2852 case 1: // Status dump
2857 case 64: /* Driver - ip2stat */
2858 rc = put_user(ip2_tty_driver->refcount, pIndex++ );
2859 rc = put_user(irq_counter, pIndex++ );
2860 rc = put_user(bh_counter, pIndex++ );
2863 case 65: /* Board - ip2stat */
2865 rc = copy_to_user(argp, pB, sizeof(i2eBordStr));
2866 rc = put_user(INB(pB->i2eStatus),
2867 (ULONG __user *)(arg + (ULONG)(&pB->i2eStatus) - (ULONG)pB ) );
2874 if (cmd < IP2_MAX_PORTS) {
2875 pCh = DevTable[cmd];
2878 rc = copy_to_user(argp, pCh, sizeof(i2ChanStr));
2888 case 2: // Ping device
2891 case 3: // Trace device
2893 * akpm: This used to write a whole bunch of function addresses
2894 * to userspace, which generated lots of put_user() warnings.
2895 * I killed it all. Just return "success" and don't do
2911 /******************************************************************************/
2912 /* Function: ip2_ipl_open() */
2913 /* Parameters: Pointer to device inode */
2914 /* Pointer to file structure */
2915 /* Returns: Success or failure */
2920 /******************************************************************************/
2922 ip2_ipl_open( struct inode *pInode, struct file *pFile )
2924 unsigned int iplminor = iminor(pInode);
2929 printk (KERN_DEBUG "IP2IPL: open\n" );
2933 // These are the IPL devices
2940 // These are the status devices
2947 // These are the debug devices
2952 pB = i2BoardPtrTable[iplminor / 4];
2953 pCh = (i2ChanStrPtr) pB->i2eChannelPtr;
2956 // This is the trace device
2962 /******************************************************************************/
2963 /* Function: ip2_read_procmem */
2966 /* Returns: Length of output */
2969 /* Supplies some driver operating parameters */
2970 /* Not real useful unless your debugging the fifo */
2972 /******************************************************************************/
2974 #define LIMIT (PAGE_SIZE - 120)
2977 ip2_read_procmem(char *buf, char **start, off_t offset, int len)
2986 #define FMTLINE "%3d: 0x%08x 0x%08x 0%011o 0%011o\n"
2987 #define FMTLIN2 " 0x%04x 0x%04x tx flow 0x%x\n"
2988 #define FMTLIN3 " 0x%04x 0x%04x rc flow\n"
2990 len += sprintf(buf+len,"\n");
2992 for( i = 0; i < IP2_MAX_BOARDS; ++i ) {
2993 pB = i2BoardPtrTable[i];
2995 len += sprintf(buf+len,"board %d:\n",i);
2996 len += sprintf(buf+len,"\tFifo rem: %d mty: %x outM %x\n",
2997 pB->i2eFifoRemains,pB->i2eWaitingForEmptyFifo,pB->i2eOutMailWaiting);
3001 len += sprintf(buf+len,"#: tty flags, port flags, cflags, iflags\n");
3002 for (i=0; i < IP2_MAX_PORTS; i++) {
3008 if (tty && tty->count) {
3009 len += sprintf(buf+len,FMTLINE,i,(int)tty->flags,pCh->flags,
3010 tty->termios->c_cflag,tty->termios->c_iflag);
3012 len += sprintf(buf+len,FMTLIN2,
3013 pCh->outfl.asof,pCh->outfl.room,pCh->channelNeeds);
3014 len += sprintf(buf+len,FMTLIN3,pCh->infl.asof,pCh->infl.room);
3022 * This is the handler for /proc/tty/driver/ip2
3024 * This stretch of code has been largely plagerized from at least three
3025 * different sources including ip2mkdev.c and a couple of other drivers.
3026 * The bugs are all mine. :-) =mhw=
3028 static int ip2_read_proc(char *page, char **start, off_t off,
3029 int count, int *eof, void *data)
3039 len += sprintf(page, "ip2info: 1.0 driver: %s\n", pcVersion );
3040 len += sprintf(page+len, "Driver: SMajor=%d CMajor=%d IMajor=%d MaxBoards=%d MaxBoxes=%d MaxPorts=%d\n",
3041 IP2_TTY_MAJOR, IP2_CALLOUT_MAJOR, IP2_IPL_MAJOR,
3042 IP2_MAX_BOARDS, ABS_MAX_BOXES, ABS_BIGGEST_BOX);
3044 for( i = 0; i < IP2_MAX_BOARDS; ++i ) {
3045 /* This need to be reset for a board by board count... */
3047 pB = i2BoardPtrTable[i];
3049 switch( pB->i2ePom.e.porID & ~POR_ID_RESERVED )
3052 len += sprintf( page+len, "Board %d: EX ports=", i );
3053 for( box = 0; box < ABS_MAX_BOXES; ++box )
3057 if( pB->i2eChannelMap[box] != 0 ) ++boxes;
3058 for( j = 0; j < ABS_BIGGEST_BOX; ++j )
3060 if( pB->i2eChannelMap[box] & 1<< j ) {
3064 len += sprintf( page+len, "%d,", ports );
3068 --len; /* Backup over that last comma */
3070 len += sprintf( page+len, " boxes=%d width=%d", boxes, pB->i2eDataWidth16 ? 16 : 8 );
3074 len += sprintf(page+len, "Board %d: ISA-4 ports=4 boxes=1", i );
3079 len += sprintf(page+len, "Board %d: ISA-8-std ports=8 boxes=1", i );
3084 len += sprintf(page+len, "Board %d: ISA-8-RJ11 ports=8 boxes=1", i );
3089 len += sprintf(page+len, "Board %d: unknown", i );
3090 /* Don't try and probe for minor numbers */
3095 /* Don't try and probe for minor numbers */
3096 len += sprintf(page+len, "Board %d: vacant", i );
3101 len += sprintf(page+len, " minors=" );
3103 for ( box = 0; box < ABS_MAX_BOXES; ++box )
3105 for ( j = 0; j < ABS_BIGGEST_BOX; ++j )
3107 if ( pB->i2eChannelMap[box] & (1 << j) )
3109 len += sprintf (page+len,"%d,",
3110 j + ABS_BIGGEST_BOX *
3111 (box+i*ABS_MAX_BOXES));
3116 page[ len - 1 ] = '\n'; /* Overwrite that last comma */
3118 len += sprintf (page+len,"\n" );
3121 if (len+begin > off+count)
3123 if (len+begin < off) {
3129 if (i >= IP2_MAX_BOARDS)
3131 if (off >= len+begin)
3134 *start = page + (off-begin);
3135 return ((count < begin+len-off) ? count : begin+len-off);
3138 /******************************************************************************/
3139 /* Function: ip2trace() */
3140 /* Parameters: Value to add to trace buffer */
3141 /* Returns: Nothing */
3146 /******************************************************************************/
3147 #ifdef IP2DEBUG_TRACE
3149 ip2trace (unsigned short pn, unsigned char cat, unsigned char label, unsigned long codes, ...)
3152 unsigned long *pCode = &codes;
3153 union ip2breadcrumb bc;
3157 tracebuf[tracestuff++] = jiffies;
3158 if ( tracestuff == TRACEMAX ) {
3161 if ( tracestuff == tracestrip ) {
3162 if ( ++tracestrip == TRACEMAX ) {
3168 bc.hdr.port = 0xff & pn;
3170 bc.hdr.codes = (unsigned char)( codes & 0xff );
3171 bc.hdr.label = label;
3172 tracebuf[tracestuff++] = bc.value;
3175 if ( tracestuff == TRACEMAX ) {
3178 if ( tracestuff == tracestrip ) {
3179 if ( ++tracestrip == TRACEMAX ) {
3188 tracebuf[tracestuff++] = *++pCode;
3194 MODULE_LICENSE("GPL");