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 class_device_destroy(ip2_class, MKDEV(IP2_IPL_MAJOR, 4 * i + 1));
419 /* Disable and remove interrupt handler. */
420 if ( (ip2config.irq[i] > 0) && have_requested_irq(ip2config.irq[i]) ) {
421 free_irq ( ip2config.irq[i], (void *)&pcName);
422 clear_requested_irq( ip2config.irq[i]);
425 class_destroy(ip2_class);
426 if ( ( err = tty_unregister_driver ( ip2_tty_driver ) ) ) {
427 printk(KERN_ERR "IP2: failed to unregister tty driver (%d)\n", err);
429 put_tty_driver(ip2_tty_driver);
430 if ( ( err = unregister_chrdev ( IP2_IPL_MAJOR, pcIpl ) ) ) {
431 printk(KERN_ERR "IP2: failed to unregister IPL driver (%d)\n", err);
433 remove_proc_entry("ip2mem", &proc_root);
436 for (i = 0; i < IP2_MAX_BOARDS; i++) {
439 if (ip2config.type[i] == PCI && ip2config.pci_dev[i]) {
440 pci_disable_device(ip2config.pci_dev[i]);
441 ip2config.pci_dev[i] = NULL;
444 if ((pB = i2BoardPtrTable[i]) != 0 ) {
446 i2BoardPtrTable[i] = NULL;
448 if ((DevTableMem[i]) != NULL ) {
449 kfree ( DevTableMem[i] );
450 DevTableMem[i] = NULL;
454 /* Cleanup the iiEllis subsystem. */
457 printk (KERN_DEBUG "IP2 Unloaded\n" );
462 static struct tty_operations ip2_ops = {
466 .put_char = ip2_putchar,
467 .flush_chars = ip2_flush_chars,
468 .write_room = ip2_write_room,
469 .chars_in_buffer = ip2_chars_in_buf,
470 .flush_buffer = ip2_flush_buffer,
472 .throttle = ip2_throttle,
473 .unthrottle = ip2_unthrottle,
474 .set_termios = ip2_set_termios,
475 .set_ldisc = ip2_set_line_discipline,
478 .hangup = ip2_hangup,
479 .read_proc = ip2_read_proc,
480 .tiocmget = ip2_tiocmget,
481 .tiocmset = ip2_tiocmset,
484 /******************************************************************************/
485 /* Function: ip2_loadmain() */
486 /* Parameters: irq, io from command line of insmod et. al. */
487 /* pointer to fip firmware and firmware size for boards */
488 /* Returns: Success (0) */
491 /* This was the required entry point for all drivers (now in ip2.c) */
492 /* It performs all */
493 /* initialisation of the devices and driver structures, and registers itself */
494 /* with the relevant kernel modules. */
495 /******************************************************************************/
496 /* SA_INTERRUPT- if set blocks all interrupts else only this line */
497 /* SA_SHIRQ - for shared irq PCI or maybe EISA only */
498 /* SA_RANDOM - can be source for cert. random number generators */
499 #define IP2_SA_FLAGS 0
502 ip2_loadmain(int *iop, int *irqp, unsigned char *firmware, int firmsize)
508 i2eBordStrPtr pB = NULL;
511 ip2trace (ITRC_NO_PORT, ITRC_INIT, ITRC_ENTER, 0 );
513 /* process command line arguments to modprobe or
514 insmod i.e. iop & irqp */
515 /* irqp and iop should ALWAYS be specified now... But we check
516 them individually just to be sure, anyways... */
517 for ( i = 0; i < IP2_MAX_BOARDS; ++i ) {
519 ip2config.addr[i] = iop[i];
522 ip2config.irq[i] = irqp[i];
524 ip2config.irq[i] = 0;
526 // This is a little bit of a hack. If poll_only=1 on command
527 // line back in ip2.c OR all IRQs on all specified boards are
528 // explicitly set to 0, then drop to poll only mode and override
529 // PCI or EISA interrupts. This superceeds the old hack of
530 // triggering if all interrupts were zero (like da default).
531 // Still a hack but less prone to random acts of terrorism.
533 // What we really should do, now that the IRQ default is set
534 // to -1, is to use 0 as a hard coded, do not probe.
537 poll_only |= irqp[i];
541 poll_only = !poll_only;
543 Fip_firmware = firmware;
544 Fip_firmware_size = firmsize;
546 /* Announce our presence */
547 printk( KERN_INFO "%s version %s\n", pcName, pcVersion );
549 // ip2 can be unloaded and reloaded for no good reason
550 // we can't let that happen here or bad things happen
551 // second load hoses board but not system - fixme later
553 printk( KERN_INFO "Still loaded\n" );
558 ip2_tty_driver = alloc_tty_driver(IP2_MAX_PORTS);
562 /* Initialise the iiEllis subsystem. */
565 /* Initialize arrays. */
566 memset( i2BoardPtrTable, 0, sizeof i2BoardPtrTable );
567 memset( DevTable, 0, sizeof DevTable );
569 /* Initialise all the boards we can find (up to the maximum). */
570 for ( i = 0; i < IP2_MAX_BOARDS; ++i ) {
571 switch ( ip2config.addr[i] ) {
572 case 0: /* skip this slot even if card is present */
575 /* ISA address must be specified */
576 if ( (ip2config.addr[i] < 0x100) || (ip2config.addr[i] > 0x3f8) ) {
577 printk ( KERN_ERR "IP2: Bad ISA board %d address %x\n",
578 i, ip2config.addr[i] );
579 ip2config.addr[i] = 0;
581 ip2config.type[i] = ISA;
583 /* Check for valid irq argument, set for polling if invalid */
584 if (ip2config.irq[i] && !is_valid_irq(ip2config.irq[i])) {
585 printk(KERN_ERR "IP2: Bad IRQ(%d) specified\n",ip2config.irq[i]);
586 ip2config.irq[i] = 0;// 0 is polling and is valid in that sense
593 struct pci_dev *pci_dev_i = NULL;
594 pci_dev_i = pci_find_device(PCI_VENDOR_ID_COMPUTONE,
595 PCI_DEVICE_ID_COMPUTONE_IP2EX, pci_dev_i);
596 if (pci_dev_i != NULL) {
599 if (pci_enable_device(pci_dev_i)) {
600 printk( KERN_ERR "IP2: can't enable PCI device at %s\n",
601 pci_name(pci_dev_i));
604 ip2config.type[i] = PCI;
605 ip2config.pci_dev[i] = pci_dev_i;
607 pci_read_config_dword(pci_dev_i, PCI_BASE_ADDRESS_1, &addr);
609 ip2config.addr[i]=(USHORT)(addr&0xfffe);
611 printk( KERN_ERR "IP2: PCI I/O address error\n");
614 // If the PCI BIOS assigned it, lets try and use it. If we
615 // can't acquire it or it screws up, deal with it then.
617 // if (!is_valid_irq(pci_irq)) {
618 // printk( KERN_ERR "IP2: Bad PCI BIOS IRQ(%d)\n",pci_irq);
621 ip2config.irq[i] = pci_dev_i->irq;
622 } else { // ann error
623 ip2config.addr[i] = 0;
624 if (status == PCIBIOS_DEVICE_NOT_FOUND) {
625 printk( KERN_ERR "IP2: PCI board %d not found\n", i );
627 printk( KERN_ERR "IP2: PCI error 0x%x \n", status );
632 printk( KERN_ERR "IP2: PCI card specified but PCI support not\n");
633 printk( KERN_ERR "IP2: configured in this kernel.\n");
634 printk( KERN_ERR "IP2: Recompile kernel with CONFIG_PCI defined!\n");
635 #endif /* CONFIG_PCI */
638 if ( (ip2config.addr[i] = find_eisa_board( Eisa_slot + 1 )) != 0) {
639 /* Eisa_irq set as side effect, boo */
640 ip2config.type[i] = EISA;
642 ip2config.irq[i] = Eisa_irq;
646 for ( i = 0; i < IP2_MAX_BOARDS; ++i ) {
647 if ( ip2config.addr[i] ) {
648 pB = kmalloc( sizeof(i2eBordStr), GFP_KERNEL);
650 i2BoardPtrTable[i] = pB;
651 memset( pB, 0, sizeof(i2eBordStr) );
652 iiSetAddress( pB, ip2config.addr[i], ii2DelayTimer );
655 printk(KERN_ERR "IP2: board memory allocation error\n");
659 for ( i = 0; i < IP2_MAX_BOARDS; ++i ) {
660 if ( ( pB = i2BoardPtrTable[i] ) != NULL ) {
665 for ( i = 0; i < IP2_MAX_BOARDS; ++i ) {
666 if ( i2BoardPtrTable[i] != NULL ) {
671 ip2trace (ITRC_NO_PORT, ITRC_INIT, 2, 0 );
673 ip2_tty_driver->owner = THIS_MODULE;
674 ip2_tty_driver->name = "ttyF";
675 ip2_tty_driver->devfs_name = "tts/F";
676 ip2_tty_driver->driver_name = pcDriver_name;
677 ip2_tty_driver->major = IP2_TTY_MAJOR;
678 ip2_tty_driver->minor_start = 0;
679 ip2_tty_driver->type = TTY_DRIVER_TYPE_SERIAL;
680 ip2_tty_driver->subtype = SERIAL_TYPE_NORMAL;
681 ip2_tty_driver->init_termios = tty_std_termios;
682 ip2_tty_driver->init_termios.c_cflag = B9600|CS8|CREAD|HUPCL|CLOCAL;
683 ip2_tty_driver->flags = TTY_DRIVER_REAL_RAW | TTY_DRIVER_NO_DEVFS;
684 tty_set_operations(ip2_tty_driver, &ip2_ops);
686 ip2trace (ITRC_NO_PORT, ITRC_INIT, 3, 0 );
688 /* Register the tty devices. */
689 if ( ( err = tty_register_driver ( ip2_tty_driver ) ) ) {
690 printk(KERN_ERR "IP2: failed to register tty driver (%d)\n", err);
691 put_tty_driver(ip2_tty_driver);
694 /* Register the IPL driver. */
695 if ( ( err = register_chrdev ( IP2_IPL_MAJOR, pcIpl, &ip2_ipl ) ) ) {
696 printk(KERN_ERR "IP2: failed to register IPL device (%d)\n", err );
698 /* create the sysfs class */
699 ip2_class = class_create(THIS_MODULE, "ip2");
700 if (IS_ERR(ip2_class)) {
701 err = PTR_ERR(ip2_class);
705 /* Register the read_procmem thing */
706 if (!create_proc_info_entry("ip2mem",0,&proc_root,ip2_read_procmem)) {
707 printk(KERN_ERR "IP2: failed to register read_procmem\n");
710 ip2trace (ITRC_NO_PORT, ITRC_INIT, 4, 0 );
711 /* Register the interrupt handler or poll handler, depending upon the
712 * specified interrupt.
715 for( i = 0; i < IP2_MAX_BOARDS; ++i ) {
716 if ( 0 == ip2config.addr[i] ) {
720 if ( NULL != ( pB = i2BoardPtrTable[i] ) ) {
721 class_device_create(ip2_class, NULL,
722 MKDEV(IP2_IPL_MAJOR, 4 * i),
724 class_device_create(ip2_class, NULL,
725 MKDEV(IP2_IPL_MAJOR, 4 * i + 1),
728 for ( box = 0; box < ABS_MAX_BOXES; ++box )
730 for ( j = 0; j < ABS_BIGGEST_BOX; ++j )
732 if ( pB->i2eChannelMap[box] & (1 << j) )
734 tty_register_device(ip2_tty_driver,
735 j + ABS_BIGGEST_BOX *
736 (box+i*ABS_MAX_BOXES), NULL);
743 // Poll only forces driver to only use polling and
744 // to ignore the probed PCI or EISA interrupts.
745 ip2config.irq[i] = CIR_POLL;
747 if ( ip2config.irq[i] == CIR_POLL ) {
750 PollTimer.expires = POLL_TIMEOUT;
751 add_timer ( &PollTimer );
753 printk( KERN_INFO "IP2: polling\n");
756 if (have_requested_irq(ip2config.irq[i]))
758 rc = request_irq( ip2config.irq[i], ip2_interrupt,
759 IP2_SA_FLAGS | (ip2config.type[i] == PCI ? SA_SHIRQ : 0),
760 pcName, (void *)&pcName);
762 printk(KERN_ERR "IP2: an request_irq failed: error %d\n",rc);
763 ip2config.irq[i] = CIR_POLL;
764 printk( KERN_INFO "IP2: Polling %ld/sec.\n",
765 (POLL_TIMEOUT - jiffies));
768 mark_requested_irq(ip2config.irq[i]);
769 /* Initialise the interrupt handler bottom half (aka slih). */
772 for( i = 0; i < IP2_MAX_BOARDS; ++i ) {
773 if ( i2BoardPtrTable[i] ) {
774 set_irq( i, ip2config.irq[i] ); /* set and enable board interrupt */
778 ip2trace (ITRC_NO_PORT, ITRC_INIT, ITRC_RETURN, 0 );
782 class_destroy(ip2_class);
784 unregister_chrdev(IP2_IPL_MAJOR, "ip2");
789 EXPORT_SYMBOL(ip2_loadmain);
791 /******************************************************************************/
792 /* Function: ip2_init_board() */
793 /* Parameters: Index of board in configuration structure */
794 /* Returns: Success (0) */
797 /* This function initializes the specified board. The loadware is copied to */
798 /* the board, the channel structures are initialized, and the board details */
799 /* are reported on the console. */
800 /******************************************************************************/
802 ip2_init_board( int boardnum )
805 int nports = 0, nboxes = 0;
807 i2eBordStrPtr pB = i2BoardPtrTable[boardnum];
809 if ( !iiInitialize ( pB ) ) {
810 printk ( KERN_ERR "IP2: Failed to initialize board at 0x%x, error %d\n",
811 pB->i2eBase, pB->i2eError );
814 printk(KERN_INFO "IP2: Board %d: addr=0x%x irq=%d\n", boardnum + 1,
815 ip2config.addr[boardnum], ip2config.irq[boardnum] );
817 if (!request_region( ip2config.addr[boardnum], 8, pcName )) {
818 printk(KERN_ERR "IP2: bad addr=0x%x\n", ip2config.addr[boardnum]);
822 if ( iiDownloadAll ( pB, (loadHdrStrPtr)Fip_firmware, 1, Fip_firmware_size )
824 printk ( KERN_ERR "IP2: failed to download loadware\n" );
825 goto err_release_region;
827 printk ( KERN_INFO "IP2: fv=%d.%d.%d lv=%d.%d.%d\n",
828 pB->i2ePom.e.porVersion,
829 pB->i2ePom.e.porRevision,
830 pB->i2ePom.e.porSubRev, pB->i2eLVersion,
831 pB->i2eLRevision, pB->i2eLSub );
834 switch ( pB->i2ePom.e.porID & ~POR_ID_RESERVED ) {
837 printk( KERN_ERR "IP2: Unknown board type, ID = %x\n",
838 pB->i2ePom.e.porID );
840 goto err_release_region;
843 case POR_ID_II_4: /* IntelliPort-II, ISA-4 (4xRJ45) */
844 printk ( KERN_INFO "IP2: ISA-4\n" );
848 case POR_ID_II_8: /* IntelliPort-II, 8-port using standard brick. */
849 printk ( KERN_INFO "IP2: ISA-8 std\n" );
853 case POR_ID_II_8R: /* IntelliPort-II, 8-port using RJ11's (no CTS) */
854 printk ( KERN_INFO "IP2: ISA-8 RJ11\n" );
858 case POR_ID_FIIEX: /* IntelliPort IIEX */
860 int portnum = IP2_PORTS_PER_BOARD * boardnum;
863 for( box = 0; box < ABS_MAX_BOXES; ++box ) {
864 if ( pB->i2eChannelMap[box] != 0 ) {
867 for( i = 0; i < ABS_BIGGEST_BOX; ++i ) {
868 if ( pB->i2eChannelMap[box] & 1<< i ) {
873 DevTableMem[boardnum] = pCh =
874 kmalloc( sizeof(i2ChanStr) * nports, GFP_KERNEL );
876 printk ( KERN_ERR "IP2: (i2_init_channel:) Out of memory.\n");
877 goto err_release_region;
879 if ( !i2InitChannels( pB, nports, pCh ) ) {
880 printk(KERN_ERR "IP2: i2InitChannels failed: %d\n",pB->i2eError);
882 goto err_release_region;
884 pB->i2eChannelPtr = &DevTable[portnum];
885 pB->i2eChannelCnt = ABS_MOST_PORTS;
887 for( box = 0; box < ABS_MAX_BOXES; ++box, portnum += ABS_BIGGEST_BOX ) {
888 for( i = 0; i < ABS_BIGGEST_BOX; ++i ) {
889 if ( pB->i2eChannelMap[box] & (1 << i) ) {
890 DevTable[portnum + i] = pCh;
891 pCh->port_index = portnum + i;
896 printk(KERN_INFO "IP2: EX box=%d ports=%d %d bit\n",
897 nboxes, nports, pB->i2eDataWidth16 ? 16 : 8 );
901 DevTableMem[boardnum] = pCh =
902 kmalloc ( sizeof (i2ChanStr) * nports, GFP_KERNEL );
904 printk ( KERN_ERR "IP2: (i2_init_channel:) Out of memory.\n");
905 goto err_release_region;
907 pB->i2eChannelPtr = pCh;
908 pB->i2eChannelCnt = nports;
909 if ( !i2InitChannels( pB, nports, pCh ) ) {
910 printk(KERN_ERR "IP2: i2InitChannels failed: %d\n",pB->i2eError);
912 goto err_release_region;
914 pB->i2eChannelPtr = &DevTable[IP2_PORTS_PER_BOARD * boardnum];
916 for( i = 0; i < pB->i2eChannelCnt; ++i ) {
917 DevTable[IP2_PORTS_PER_BOARD * boardnum + i] = pCh;
918 pCh->port_index = (IP2_PORTS_PER_BOARD * boardnum) + i;
922 INIT_WORK(&pB->tqueue_interrupt, (void(*)(void*)) ip2_interrupt_bh, pB);
926 release_region(ip2config.addr[boardnum], 8);
929 i2BoardPtrTable[boardnum] = NULL;
933 /******************************************************************************/
934 /* Function: find_eisa_board ( int start_slot ) */
935 /* Parameters: First slot to check */
936 /* Returns: Address of EISA IntelliPort II controller */
939 /* This function searches for an EISA IntelliPort controller, starting */
940 /* from the specified slot number. If the motherboard is not identified as an */
941 /* EISA motherboard, or no valid board ID is selected it returns 0. Otherwise */
942 /* it returns the base address of the controller. */
943 /******************************************************************************/
944 static unsigned short
945 find_eisa_board( int start_slot )
948 unsigned int idm = 0;
949 unsigned int idp = 0;
950 unsigned int base = 0;
957 * First a check for an EISA motherboard, which we do by comparing the
958 * EISA ID registers for the system board and the first couple of slots.
959 * No slot ID should match the system board ID, but on an ISA or PCI
960 * machine the odds are that an empty bus will return similar values for
964 value = (inb(i) << 24) + (inb(i+1) << 16) + (inb(i+2) << 8) + inb(i+3);
965 for( i = 0x1c80; i <= 0x4c80; i += 0x1000 ) {
966 j = (inb(i)<<24)+(inb(i+1)<<16)+(inb(i+2)<<8)+inb(i+3);
972 * OK, so we are inclined to believe that this is an EISA machine. Find
973 * an IntelliPort controller.
975 for( i = start_slot; i < 16; i++ ) {
977 idm = (inb(base + 0xc80) << 8) | (inb(base + 0xc81) & 0xff);
978 idp = (inb(base + 0xc82) << 8) | (inb(base + 0xc83) & 0xff);
980 if ( idm == 0x0e8e ) {
981 if ( idp == 0x0281 || idp == 0x0218 ) {
983 } else if ( idp == 0x0282 || idp == 0x0283 ) {
984 ismine = 3; /* Can do edge-trigger */
995 /* It's some sort of EISA card, but at what address is it configured? */
997 setup_address = base + 0xc88;
998 value = inb(base + 0xc86);
999 setup_irq = (value & 8) ? Valid_Irqs[value & 7] : 0;
1001 if ( (ismine & 2) && !(value & 0x10) ) {
1002 ismine = 1; /* Could be edging, but not */
1005 if ( Eisa_irq == 0 ) {
1006 Eisa_irq = setup_irq;
1007 } else if ( Eisa_irq != setup_irq ) {
1008 printk ( KERN_ERR "IP2: EISA irq mismatch between EISA controllers\n" );
1011 #ifdef IP2DEBUG_INIT
1012 printk(KERN_DEBUG "Computone EISA board in slot %d, I.D. 0x%x%x, Address 0x%x",
1013 base >> 12, idm, idp, setup_address);
1015 printk(KERN_DEBUG ", Interrupt %d %s\n",
1016 setup_irq, (ismine & 2) ? "(edge)" : "(level)");
1018 printk(KERN_DEBUG ", (polled)\n");
1021 return setup_address;
1024 /******************************************************************************/
1025 /* Function: set_irq() */
1026 /* Parameters: index to board in board table */
1028 /* Returns: Success (0) */
1031 /******************************************************************************/
1033 set_irq( int boardnum, int boardIrq )
1035 unsigned char tempCommand[16];
1036 i2eBordStrPtr pB = i2BoardPtrTable[boardnum];
1037 unsigned long flags;
1040 * Notify the boards they may generate interrupts. This is done by
1041 * sending an in-line command to channel 0 on each board. This is why
1042 * the channels have to be defined already. For each board, if the
1043 * interrupt has never been defined, we must do so NOW, directly, since
1044 * board will not send flow control or even give an interrupt until this
1045 * is done. If polling we must send 0 as the interrupt parameter.
1048 // We will get an interrupt here at the end of this function
1050 iiDisableMailIrq(pB);
1052 /* We build up the entire packet header. */
1053 CHANNEL_OF(tempCommand) = 0;
1054 PTYPE_OF(tempCommand) = PTYPE_INLINE;
1055 CMD_COUNT_OF(tempCommand) = 2;
1056 (CMD_OF(tempCommand))[0] = CMDVALUE_IRQ;
1057 (CMD_OF(tempCommand))[1] = boardIrq;
1059 * Write to FIFO; don't bother to adjust fifo capacity for this, since
1060 * board will respond almost immediately after SendMail hit.
1062 WRITE_LOCK_IRQSAVE(&pB->write_fifo_spinlock,flags);
1063 iiWriteBuf(pB, tempCommand, 4);
1064 WRITE_UNLOCK_IRQRESTORE(&pB->write_fifo_spinlock,flags);
1065 pB->i2eUsingIrq = boardIrq;
1066 pB->i2eOutMailWaiting |= MB_OUT_STUFFED;
1068 /* Need to update number of boards before you enable mailbox int */
1071 CHANNEL_OF(tempCommand) = 0;
1072 PTYPE_OF(tempCommand) = PTYPE_BYPASS;
1073 CMD_COUNT_OF(tempCommand) = 6;
1074 (CMD_OF(tempCommand))[0] = 88; // SILO
1075 (CMD_OF(tempCommand))[1] = 64; // chars
1076 (CMD_OF(tempCommand))[2] = 32; // ms
1078 (CMD_OF(tempCommand))[3] = 28; // MAX_BLOCK
1079 (CMD_OF(tempCommand))[4] = 64; // chars
1081 (CMD_OF(tempCommand))[5] = 87; // HW_TEST
1082 WRITE_LOCK_IRQSAVE(&pB->write_fifo_spinlock,flags);
1083 iiWriteBuf(pB, tempCommand, 8);
1084 WRITE_UNLOCK_IRQRESTORE(&pB->write_fifo_spinlock,flags);
1086 CHANNEL_OF(tempCommand) = 0;
1087 PTYPE_OF(tempCommand) = PTYPE_BYPASS;
1088 CMD_COUNT_OF(tempCommand) = 1;
1089 (CMD_OF(tempCommand))[0] = 84; /* get BOX_IDS */
1090 iiWriteBuf(pB, tempCommand, 3);
1093 // enable heartbeat for test porpoises
1094 CHANNEL_OF(tempCommand) = 0;
1095 PTYPE_OF(tempCommand) = PTYPE_BYPASS;
1096 CMD_COUNT_OF(tempCommand) = 2;
1097 (CMD_OF(tempCommand))[0] = 44; /* get ping */
1098 (CMD_OF(tempCommand))[1] = 200; /* 200 ms */
1099 WRITE_LOCK_IRQSAVE(&pB->write_fifo_spinlock,flags);
1100 iiWriteBuf(pB, tempCommand, 4);
1101 WRITE_UNLOCK_IRQRESTORE(&pB->write_fifo_spinlock,flags);
1104 iiEnableMailIrq(pB);
1105 iiSendPendingMail(pB);
1108 /******************************************************************************/
1109 /* Interrupt Handler Section */
1110 /******************************************************************************/
1113 service_all_boards(void)
1118 /* Service every board on the list */
1119 for( i = 0; i < IP2_MAX_BOARDS; ++i ) {
1120 pB = i2BoardPtrTable[i];
1122 i2ServiceBoard( pB );
1128 /******************************************************************************/
1129 /* Function: ip2_interrupt_bh(pB) */
1130 /* Parameters: pB - pointer to the board structure */
1131 /* Returns: Nothing */
1134 /* Service the board in a bottom half interrupt handler and then */
1135 /* reenable the board's interrupts if it has an IRQ number */
1137 /******************************************************************************/
1139 ip2_interrupt_bh(i2eBordStrPtr pB)
1141 // pB better well be set or we have a problem! We can only get
1142 // here from the IMMEDIATE queue. Here, we process the boards.
1143 // Checking pB doesn't cost much and it saves us from the sanity checkers.
1148 i2ServiceBoard( pB );
1149 if( pB->i2eUsingIrq ) {
1150 // Re-enable his interrupts
1151 iiEnableMailIrq(pB);
1157 /******************************************************************************/
1158 /* Function: ip2_interrupt(int irq, void *dev_id, struct pt_regs * regs) */
1159 /* Parameters: irq - interrupt number */
1160 /* pointer to optional device ID structure */
1161 /* pointer to register structure */
1162 /* Returns: Nothing */
1166 /* Our task here is simply to identify each board which needs servicing. */
1167 /* If we are queuing then, queue it to be serviced, and disable its irq */
1168 /* mask otherwise process the board directly. */
1170 /* We could queue by IRQ but that just complicates things on both ends */
1171 /* with very little gain in performance (how many instructions does */
1172 /* it take to iterate on the immediate queue). */
1175 /******************************************************************************/
1177 ip2_interrupt(int irq, void *dev_id, struct pt_regs * regs)
1183 ip2trace (ITRC_NO_PORT, ITRC_INTR, 99, 1, irq );
1185 /* Service just the boards on the list using this irq */
1186 for( i = 0; i < i2nBoards; ++i ) {
1187 pB = i2BoardPtrTable[i];
1189 // Only process those boards which match our IRQ.
1190 // IRQ = 0 for polled boards, we won't poll "IRQ" boards
1192 if ( pB && (pB->i2eUsingIrq == irq) ) {
1196 if (NO_MAIL_HERE != ( pB->i2eStartMail = iiGetMail(pB))) {
1197 // Disable his interrupt (will be enabled when serviced)
1198 // This is mostly to protect from reentrancy.
1199 iiDisableMailIrq(pB);
1201 // Park the board on the immediate queue for processing.
1202 schedule_work(&pB->tqueue_interrupt);
1204 // Make sure the immediate queue is flagged to fire.
1207 // We are using immediate servicing here. This sucks and can
1208 // cause all sorts of havoc with ppp and others. The failsafe
1209 // check on iiSendPendingMail could also throw a hairball.
1210 i2ServiceBoard( pB );
1211 #endif /* USE_IQI */
1217 ip2trace (ITRC_NO_PORT, ITRC_INTR, ITRC_RETURN, 0 );
1218 return IRQ_RETVAL(handled);
1221 /******************************************************************************/
1222 /* Function: ip2_poll(unsigned long arg) */
1224 /* Returns: Nothing */
1227 /* This function calls the library routine i2ServiceBoard for each board in */
1228 /* the board table. This is used instead of the interrupt routine when polled */
1229 /* mode is specified. */
1230 /******************************************************************************/
1232 ip2_poll(unsigned long arg)
1234 ip2trace (ITRC_NO_PORT, ITRC_INTR, 100, 0 );
1236 TimerOn = 0; // it's the truth but not checked in service
1238 // Just polled boards, IRQ = 0 will hit all non-interrupt boards.
1239 // It will NOT poll boards handled by hard interrupts.
1240 // The issue of queued BH interrups is handled in ip2_interrupt().
1241 ip2_interrupt(0, NULL, NULL);
1243 PollTimer.expires = POLL_TIMEOUT;
1244 add_timer( &PollTimer );
1247 ip2trace (ITRC_NO_PORT, ITRC_INTR, ITRC_RETURN, 0 );
1250 static void do_input(void *p)
1252 i2ChanStrPtr pCh = p;
1253 unsigned long flags;
1255 ip2trace(CHANN, ITRC_INPUT, 21, 0 );
1258 if ( pCh->pTTY != NULL ) {
1259 READ_LOCK_IRQSAVE(&pCh->Ibuf_spinlock,flags)
1260 if (!pCh->throttled && (pCh->Ibuf_stuff != pCh->Ibuf_strip)) {
1261 READ_UNLOCK_IRQRESTORE(&pCh->Ibuf_spinlock,flags)
1264 READ_UNLOCK_IRQRESTORE(&pCh->Ibuf_spinlock,flags)
1266 ip2trace(CHANN, ITRC_INPUT, 22, 0 );
1268 i2InputFlush( pCh );
1272 // code duplicated from n_tty (ldisc)
1273 static inline void isig(int sig, struct tty_struct *tty, int flush)
1276 kill_pg(tty->pgrp, sig, 1);
1277 if (flush || !L_NOFLSH(tty)) {
1278 if ( tty->ldisc.flush_buffer )
1279 tty->ldisc.flush_buffer(tty);
1280 i2InputFlush( tty->driver_data );
1284 static void do_status(void *p)
1286 i2ChanStrPtr pCh = p;
1289 status = i2GetStatus( pCh, (I2_BRK|I2_PAR|I2_FRA|I2_OVR) );
1291 ip2trace (CHANN, ITRC_STATUS, 21, 1, status );
1293 if (pCh->pTTY && (status & (I2_BRK|I2_PAR|I2_FRA|I2_OVR)) ) {
1294 if ( (status & I2_BRK) ) {
1295 // code duplicated from n_tty (ldisc)
1296 if (I_IGNBRK(pCh->pTTY))
1298 if (I_BRKINT(pCh->pTTY)) {
1299 isig(SIGINT, pCh->pTTY, 1);
1302 wake_up_interruptible(&pCh->pTTY->read_wait);
1304 #ifdef NEVER_HAPPENS_AS_SETUP_XXX
1305 // and can't work because we don't know the_char
1306 // as the_char is reported on a separate path
1307 // The intelligent board does this stuff as setup
1309 char brkf = TTY_NORMAL;
1310 unsigned char brkc = '\0';
1312 if ( (status & I2_BRK) ) {
1316 else if (status & I2_PAR) {
1319 } else if (status & I2_FRA) {
1322 } else if (status & I2_OVR) {
1326 tmp = pCh->pTTY->real_raw;
1327 pCh->pTTY->real_raw = 0;
1328 pCh->pTTY->ldisc.receive_buf( pCh->pTTY, &brkc, &brkf, 1 );
1329 pCh->pTTY->real_raw = tmp;
1331 #endif /* NEVER_HAPPENS_AS_SETUP_XXX */
1335 if ( status & (I2_DDCD | I2_DDSR | I2_DCTS | I2_DRI) ) {
1336 wake_up_interruptible(&pCh->delta_msr_wait);
1338 if ( (pCh->flags & ASYNC_CHECK_CD) && (status & I2_DDCD) ) {
1339 if ( status & I2_DCD ) {
1341 wake_up_interruptible ( &pCh->open_wait );
1344 if (pCh->pTTY && (!(pCh->pTTY->termios->c_cflag & CLOCAL)) ) {
1345 tty_hangup( pCh->pTTY );
1351 ip2trace (CHANN, ITRC_STATUS, 26, 0 );
1354 /******************************************************************************/
1355 /* Device Open/Close/Ioctl Entry Point Section */
1356 /******************************************************************************/
1358 /******************************************************************************/
1359 /* Function: open_sanity_check() */
1360 /* Parameters: Pointer to tty structure */
1361 /* Pointer to file structure */
1362 /* Returns: Success or failure */
1365 /* Verifies the structure magic numbers and cross links. */
1366 /******************************************************************************/
1367 #ifdef IP2DEBUG_OPEN
1369 open_sanity_check( i2ChanStrPtr pCh, i2eBordStrPtr pBrd )
1371 if ( pBrd->i2eValid != I2E_MAGIC ) {
1372 printk(KERN_ERR "IP2: invalid board structure\n" );
1373 } else if ( pBrd != pCh->pMyBord ) {
1374 printk(KERN_ERR "IP2: board structure pointer mismatch (%p)\n",
1376 } else if ( pBrd->i2eChannelCnt < pCh->port_index ) {
1377 printk(KERN_ERR "IP2: bad device index (%d)\n", pCh->port_index );
1378 } else if (&((i2ChanStrPtr)pBrd->i2eChannelPtr)[pCh->port_index] != pCh) {
1380 printk(KERN_INFO "IP2: all pointers check out!\n" );
1386 /******************************************************************************/
1387 /* Function: ip2_open() */
1388 /* Parameters: Pointer to tty structure */
1389 /* Pointer to file structure */
1390 /* Returns: Success or failure */
1392 /* Description: (MANDATORY) */
1393 /* A successful device open has to run a gauntlet of checks before it */
1394 /* completes. After some sanity checking and pointer setup, the function */
1395 /* blocks until all conditions are satisfied. It then initialises the port to */
1396 /* the default characteristics and returns. */
1397 /******************************************************************************/
1399 ip2_open( PTTY tty, struct file *pFile )
1404 i2ChanStrPtr pCh = DevTable[tty->index];
1406 ip2trace (tty->index, ITRC_OPEN, ITRC_ENTER, 0 );
1408 if ( pCh == NULL ) {
1411 /* Setup pointer links in device and tty structures */
1413 tty->driver_data = pCh;
1415 #ifdef IP2DEBUG_OPEN
1417 "IP2:open(tty=%p,pFile=%p):dev=%s,ch=%d,idx=%d\n",
1418 tty, pFile, tty->name, pCh->infl.hd.i2sChannel, pCh->port_index);
1419 open_sanity_check ( pCh, pCh->pMyBord );
1422 i2QueueCommands(PTYPE_INLINE, pCh, 100, 3, CMD_DTRUP,CMD_RTSUP,CMD_DCD_REP);
1423 pCh->dataSetOut |= (I2_DTR | I2_RTS);
1424 serviceOutgoingFifo( pCh->pMyBord );
1426 /* Block here until the port is ready (per serial and istallion) */
1428 * 1. If the port is in the middle of closing wait for the completion
1429 * and then return the appropriate error.
1431 init_waitqueue_entry(&wait, current);
1432 add_wait_queue(&pCh->close_wait, &wait);
1433 set_current_state( TASK_INTERRUPTIBLE );
1435 if ( tty_hung_up_p(pFile) || ( pCh->flags & ASYNC_CLOSING )) {
1436 if ( pCh->flags & ASYNC_CLOSING ) {
1439 if ( tty_hung_up_p(pFile) ) {
1440 set_current_state( TASK_RUNNING );
1441 remove_wait_queue(&pCh->close_wait, &wait);
1442 return( pCh->flags & ASYNC_HUP_NOTIFY ) ? -EAGAIN : -ERESTARTSYS;
1445 set_current_state( TASK_RUNNING );
1446 remove_wait_queue(&pCh->close_wait, &wait);
1449 * 3. Handle a non-blocking open of a normal port.
1451 if ( (pFile->f_flags & O_NONBLOCK) || (tty->flags & (1<<TTY_IO_ERROR) )) {
1452 pCh->flags |= ASYNC_NORMAL_ACTIVE;
1456 * 4. Now loop waiting for the port to be free and carrier present
1459 if ( tty->termios->c_cflag & CLOCAL )
1462 #ifdef IP2DEBUG_OPEN
1463 printk(KERN_DEBUG "OpenBlock: do_clocal = %d\n", do_clocal);
1468 init_waitqueue_entry(&wait, current);
1469 add_wait_queue(&pCh->open_wait, &wait);
1472 i2QueueCommands(PTYPE_INLINE, pCh, 100, 2, CMD_DTRUP, CMD_RTSUP);
1473 pCh->dataSetOut |= (I2_DTR | I2_RTS);
1474 set_current_state( TASK_INTERRUPTIBLE );
1475 serviceOutgoingFifo( pCh->pMyBord );
1476 if ( tty_hung_up_p(pFile) ) {
1477 set_current_state( TASK_RUNNING );
1478 remove_wait_queue(&pCh->open_wait, &wait);
1479 return ( pCh->flags & ASYNC_HUP_NOTIFY ) ? -EBUSY : -ERESTARTSYS;
1481 if (!(pCh->flags & ASYNC_CLOSING) &&
1482 (do_clocal || (pCh->dataSetIn & I2_DCD) )) {
1487 #ifdef IP2DEBUG_OPEN
1488 printk(KERN_DEBUG "ASYNC_CLOSING = %s\n",
1489 (pCh->flags & ASYNC_CLOSING)?"True":"False");
1490 printk(KERN_DEBUG "OpenBlock: waiting for CD or signal\n");
1492 ip2trace (CHANN, ITRC_OPEN, 3, 2, 0,
1493 (pCh->flags & ASYNC_CLOSING) );
1494 /* check for signal */
1495 if (signal_pending(current)) {
1496 rc = (( pCh->flags & ASYNC_HUP_NOTIFY ) ? -EAGAIN : -ERESTARTSYS);
1501 set_current_state( TASK_RUNNING );
1502 remove_wait_queue(&pCh->open_wait, &wait);
1504 --pCh->wopen; //why count?
1506 ip2trace (CHANN, ITRC_OPEN, 4, 0 );
1511 pCh->flags |= ASYNC_NORMAL_ACTIVE;
1515 /* first open - Assign termios structure to port */
1516 if ( tty->count == 1 ) {
1517 i2QueueCommands(PTYPE_INLINE, pCh, 0, 2, CMD_CTSFL_DSAB, CMD_RTSFL_DSAB);
1518 /* Now we must send the termios settings to the loadware */
1519 set_params( pCh, NULL );
1523 * Now set any i2lib options. These may go away if the i2lib code ends
1524 * up rolled into the mainline.
1526 pCh->channelOptions |= CO_NBLOCK_WRITE;
1528 #ifdef IP2DEBUG_OPEN
1529 printk (KERN_DEBUG "IP2: open completed\n" );
1531 serviceOutgoingFifo( pCh->pMyBord );
1533 ip2trace (CHANN, ITRC_OPEN, ITRC_RETURN, 0 );
1538 /******************************************************************************/
1539 /* Function: ip2_close() */
1540 /* Parameters: Pointer to tty structure */
1541 /* Pointer to file structure */
1542 /* Returns: Nothing */
1547 /******************************************************************************/
1549 ip2_close( PTTY tty, struct file *pFile )
1551 i2ChanStrPtr pCh = tty->driver_data;
1557 ip2trace (CHANN, ITRC_CLOSE, ITRC_ENTER, 0 );
1559 #ifdef IP2DEBUG_OPEN
1560 printk(KERN_DEBUG "IP2:close %s:\n",tty->name);
1563 if ( tty_hung_up_p ( pFile ) ) {
1565 ip2trace (CHANN, ITRC_CLOSE, 2, 1, 2 );
1569 if ( tty->count > 1 ) { /* not the last close */
1571 ip2trace (CHANN, ITRC_CLOSE, 2, 1, 3 );
1575 pCh->flags |= ASYNC_CLOSING; // last close actually
1579 if (pCh->ClosingWaitTime != ASYNC_CLOSING_WAIT_NONE) {
1581 * Before we drop DTR, make sure the transmitter has completely drained.
1582 * This uses an timeout, after which the close
1585 ip2_wait_until_sent(tty, pCh->ClosingWaitTime );
1588 * At this point we stop accepting input. Here we flush the channel
1589 * input buffer which will allow the board to send up more data. Any
1590 * additional input is tossed at interrupt/poll time.
1592 i2InputFlush( pCh );
1594 /* disable DSS reporting */
1595 i2QueueCommands(PTYPE_INLINE, pCh, 100, 4,
1596 CMD_DCD_NREP, CMD_CTS_NREP, CMD_DSR_NREP, CMD_RI_NREP);
1597 if ( !tty || (tty->termios->c_cflag & HUPCL) ) {
1598 i2QueueCommands(PTYPE_INLINE, pCh, 100, 2, CMD_RTSDN, CMD_DTRDN);
1599 pCh->dataSetOut &= ~(I2_DTR | I2_RTS);
1600 i2QueueCommands( PTYPE_INLINE, pCh, 100, 1, CMD_PAUSE(25));
1603 serviceOutgoingFifo ( pCh->pMyBord );
1605 if ( tty->driver->flush_buffer )
1606 tty->driver->flush_buffer(tty);
1607 if ( tty->ldisc.flush_buffer )
1608 tty->ldisc.flush_buffer(tty);
1614 if (pCh->ClosingDelay) {
1615 msleep_interruptible(jiffies_to_msecs(pCh->ClosingDelay));
1617 wake_up_interruptible(&pCh->open_wait);
1620 pCh->flags &=~(ASYNC_NORMAL_ACTIVE|ASYNC_CLOSING);
1621 wake_up_interruptible(&pCh->close_wait);
1623 #ifdef IP2DEBUG_OPEN
1624 DBG_CNT("ip2_close: after wakeups--");
1628 ip2trace (CHANN, ITRC_CLOSE, ITRC_RETURN, 1, 1 );
1633 /******************************************************************************/
1634 /* Function: ip2_hangup() */
1635 /* Parameters: Pointer to tty structure */
1636 /* Returns: Nothing */
1641 /******************************************************************************/
1643 ip2_hangup ( PTTY tty )
1645 i2ChanStrPtr pCh = tty->driver_data;
1651 ip2trace (CHANN, ITRC_HANGUP, ITRC_ENTER, 0 );
1653 ip2_flush_buffer(tty);
1655 /* disable DSS reporting */
1657 i2QueueCommands(PTYPE_BYPASS, pCh, 0, 1, CMD_DCD_NREP);
1658 i2QueueCommands(PTYPE_INLINE, pCh, 0, 2, CMD_CTSFL_DSAB, CMD_RTSFL_DSAB);
1659 if ( (tty->termios->c_cflag & HUPCL) ) {
1660 i2QueueCommands(PTYPE_BYPASS, pCh, 0, 2, CMD_RTSDN, CMD_DTRDN);
1661 pCh->dataSetOut &= ~(I2_DTR | I2_RTS);
1662 i2QueueCommands( PTYPE_INLINE, pCh, 100, 1, CMD_PAUSE(25));
1664 i2QueueCommands(PTYPE_INLINE, pCh, 1, 3,
1665 CMD_CTS_NREP, CMD_DSR_NREP, CMD_RI_NREP);
1666 serviceOutgoingFifo ( pCh->pMyBord );
1668 wake_up_interruptible ( &pCh->delta_msr_wait );
1670 pCh->flags &= ~ASYNC_NORMAL_ACTIVE;
1672 wake_up_interruptible ( &pCh->open_wait );
1674 ip2trace (CHANN, ITRC_HANGUP, ITRC_RETURN, 0 );
1677 /******************************************************************************/
1678 /******************************************************************************/
1679 /* Device Output Section */
1680 /******************************************************************************/
1681 /******************************************************************************/
1683 /******************************************************************************/
1684 /* Function: ip2_write() */
1685 /* Parameters: Pointer to tty structure */
1686 /* Flag denoting data is in user (1) or kernel (0) space */
1687 /* Pointer to data */
1688 /* Number of bytes to write */
1689 /* Returns: Number of bytes actually written */
1691 /* Description: (MANDATORY) */
1694 /******************************************************************************/
1696 ip2_write( PTTY tty, const unsigned char *pData, int count)
1698 i2ChanStrPtr pCh = tty->driver_data;
1700 unsigned long flags;
1702 ip2trace (CHANN, ITRC_WRITE, ITRC_ENTER, 2, count, -1 );
1704 /* Flush out any buffered data left over from ip2_putchar() calls. */
1705 ip2_flush_chars( tty );
1707 /* This is the actual move bit. Make sure it does what we need!!!!! */
1708 WRITE_LOCK_IRQSAVE(&pCh->Pbuf_spinlock,flags);
1709 bytesSent = i2Output( pCh, pData, count, 0 );
1710 WRITE_UNLOCK_IRQRESTORE(&pCh->Pbuf_spinlock,flags);
1712 ip2trace (CHANN, ITRC_WRITE, ITRC_RETURN, 1, bytesSent );
1714 return bytesSent > 0 ? bytesSent : 0;
1717 /******************************************************************************/
1718 /* Function: ip2_putchar() */
1719 /* Parameters: Pointer to tty structure */
1720 /* Character to write */
1721 /* Returns: Nothing */
1726 /******************************************************************************/
1728 ip2_putchar( PTTY tty, unsigned char ch )
1730 i2ChanStrPtr pCh = tty->driver_data;
1731 unsigned long flags;
1733 // ip2trace (CHANN, ITRC_PUTC, ITRC_ENTER, 1, ch );
1735 WRITE_LOCK_IRQSAVE(&pCh->Pbuf_spinlock,flags);
1736 pCh->Pbuf[pCh->Pbuf_stuff++] = ch;
1737 if ( pCh->Pbuf_stuff == sizeof pCh->Pbuf ) {
1738 WRITE_UNLOCK_IRQRESTORE(&pCh->Pbuf_spinlock,flags);
1739 ip2_flush_chars( tty );
1741 WRITE_UNLOCK_IRQRESTORE(&pCh->Pbuf_spinlock,flags);
1743 // ip2trace (CHANN, ITRC_PUTC, ITRC_RETURN, 1, ch );
1746 /******************************************************************************/
1747 /* Function: ip2_flush_chars() */
1748 /* Parameters: Pointer to tty structure */
1749 /* Returns: Nothing */
1753 /******************************************************************************/
1755 ip2_flush_chars( PTTY tty )
1758 i2ChanStrPtr pCh = tty->driver_data;
1759 unsigned long flags;
1761 WRITE_LOCK_IRQSAVE(&pCh->Pbuf_spinlock,flags);
1762 if ( pCh->Pbuf_stuff ) {
1764 // ip2trace (CHANN, ITRC_PUTC, 10, 1, strip );
1767 // We may need to restart i2Output if it does not fullfill this request
1769 strip = i2Output( pCh, pCh->Pbuf, pCh->Pbuf_stuff, 0 );
1770 if ( strip != pCh->Pbuf_stuff ) {
1771 memmove( pCh->Pbuf, &pCh->Pbuf[strip], pCh->Pbuf_stuff - strip );
1773 pCh->Pbuf_stuff -= strip;
1775 WRITE_UNLOCK_IRQRESTORE(&pCh->Pbuf_spinlock,flags);
1778 /******************************************************************************/
1779 /* Function: ip2_write_room() */
1780 /* Parameters: Pointer to tty structure */
1781 /* Returns: Number of bytes that the driver can accept */
1785 /******************************************************************************/
1787 ip2_write_room ( PTTY tty )
1790 i2ChanStrPtr pCh = tty->driver_data;
1791 unsigned long flags;
1793 READ_LOCK_IRQSAVE(&pCh->Pbuf_spinlock,flags);
1794 bytesFree = i2OutputFree( pCh ) - pCh->Pbuf_stuff;
1795 READ_UNLOCK_IRQRESTORE(&pCh->Pbuf_spinlock,flags);
1797 ip2trace (CHANN, ITRC_WRITE, 11, 1, bytesFree );
1799 return ((bytesFree > 0) ? bytesFree : 0);
1802 /******************************************************************************/
1803 /* Function: ip2_chars_in_buf() */
1804 /* Parameters: Pointer to tty structure */
1805 /* Returns: Number of bytes queued for transmission */
1810 /******************************************************************************/
1812 ip2_chars_in_buf ( PTTY tty )
1814 i2ChanStrPtr pCh = tty->driver_data;
1816 unsigned long flags;
1818 ip2trace (CHANN, ITRC_WRITE, 12, 1, pCh->Obuf_char_count + pCh->Pbuf_stuff );
1820 #ifdef IP2DEBUG_WRITE
1821 printk (KERN_DEBUG "IP2: chars in buffer = %d (%d,%d)\n",
1822 pCh->Obuf_char_count + pCh->Pbuf_stuff,
1823 pCh->Obuf_char_count, pCh->Pbuf_stuff );
1825 READ_LOCK_IRQSAVE(&pCh->Obuf_spinlock,flags);
1826 rc = pCh->Obuf_char_count;
1827 READ_UNLOCK_IRQRESTORE(&pCh->Obuf_spinlock,flags);
1828 READ_LOCK_IRQSAVE(&pCh->Pbuf_spinlock,flags);
1829 rc += pCh->Pbuf_stuff;
1830 READ_UNLOCK_IRQRESTORE(&pCh->Pbuf_spinlock,flags);
1834 /******************************************************************************/
1835 /* Function: ip2_flush_buffer() */
1836 /* Parameters: Pointer to tty structure */
1837 /* Returns: Nothing */
1842 /******************************************************************************/
1844 ip2_flush_buffer( PTTY tty )
1846 i2ChanStrPtr pCh = tty->driver_data;
1847 unsigned long flags;
1849 ip2trace (CHANN, ITRC_FLUSH, ITRC_ENTER, 0 );
1851 #ifdef IP2DEBUG_WRITE
1852 printk (KERN_DEBUG "IP2: flush buffer\n" );
1854 WRITE_LOCK_IRQSAVE(&pCh->Pbuf_spinlock,flags);
1855 pCh->Pbuf_stuff = 0;
1856 WRITE_UNLOCK_IRQRESTORE(&pCh->Pbuf_spinlock,flags);
1857 i2FlushOutput( pCh );
1860 ip2trace (CHANN, ITRC_FLUSH, ITRC_RETURN, 0 );
1864 /******************************************************************************/
1865 /* Function: ip2_wait_until_sent() */
1866 /* Parameters: Pointer to tty structure */
1867 /* Timeout for wait. */
1868 /* Returns: Nothing */
1871 /* This function is used in place of the normal tty_wait_until_sent, which */
1872 /* only waits for the driver buffers to be empty (or rather, those buffers */
1873 /* reported by chars_in_buffer) which doesn't work for IP2 due to the */
1874 /* indeterminate number of bytes buffered on the board. */
1875 /******************************************************************************/
1877 ip2_wait_until_sent ( PTTY tty, int timeout )
1880 i2ChanStrPtr pCh = tty->driver_data;
1882 tty_wait_until_sent(tty, timeout );
1883 if ( (i = timeout - (jiffies -i)) > 0)
1884 i2DrainOutput( pCh, i );
1887 /******************************************************************************/
1888 /******************************************************************************/
1889 /* Device Input Section */
1890 /******************************************************************************/
1891 /******************************************************************************/
1893 /******************************************************************************/
1894 /* Function: ip2_throttle() */
1895 /* Parameters: Pointer to tty structure */
1896 /* Returns: Nothing */
1901 /******************************************************************************/
1903 ip2_throttle ( PTTY tty )
1905 i2ChanStrPtr pCh = tty->driver_data;
1907 #ifdef IP2DEBUG_READ
1908 printk (KERN_DEBUG "IP2: throttle\n" );
1911 * Signal the poll/interrupt handlers not to forward incoming data to
1912 * the line discipline. This will cause the buffers to fill up in the
1913 * library and thus cause the library routines to send the flow control
1919 /******************************************************************************/
1920 /* Function: ip2_unthrottle() */
1921 /* Parameters: Pointer to tty structure */
1922 /* Returns: Nothing */
1927 /******************************************************************************/
1929 ip2_unthrottle ( PTTY tty )
1931 i2ChanStrPtr pCh = tty->driver_data;
1932 unsigned long flags;
1934 #ifdef IP2DEBUG_READ
1935 printk (KERN_DEBUG "IP2: unthrottle\n" );
1938 /* Pass incoming data up to the line discipline again. */
1940 i2QueueCommands(PTYPE_BYPASS, pCh, 0, 1, CMD_RESUME);
1941 serviceOutgoingFifo( pCh->pMyBord );
1942 READ_LOCK_IRQSAVE(&pCh->Ibuf_spinlock,flags)
1943 if ( pCh->Ibuf_stuff != pCh->Ibuf_strip ) {
1944 READ_UNLOCK_IRQRESTORE(&pCh->Ibuf_spinlock,flags)
1945 #ifdef IP2DEBUG_READ
1946 printk (KERN_DEBUG "i2Input called from unthrottle\n" );
1950 READ_UNLOCK_IRQRESTORE(&pCh->Ibuf_spinlock,flags)
1954 ip2_start ( PTTY tty )
1956 i2ChanStrPtr pCh = DevTable[tty->index];
1958 i2QueueCommands(PTYPE_BYPASS, pCh, 0, 1, CMD_RESUME);
1959 i2QueueCommands(PTYPE_BYPASS, pCh, 100, 1, CMD_UNSUSPEND);
1960 i2QueueCommands(PTYPE_BYPASS, pCh, 100, 1, CMD_RESUME);
1961 #ifdef IP2DEBUG_WRITE
1962 printk (KERN_DEBUG "IP2: start tx\n" );
1967 ip2_stop ( PTTY tty )
1969 i2ChanStrPtr pCh = DevTable[tty->index];
1971 i2QueueCommands(PTYPE_BYPASS, pCh, 100, 1, CMD_SUSPEND);
1972 #ifdef IP2DEBUG_WRITE
1973 printk (KERN_DEBUG "IP2: stop tx\n" );
1977 /******************************************************************************/
1978 /* Device Ioctl Section */
1979 /******************************************************************************/
1981 static int ip2_tiocmget(struct tty_struct *tty, struct file *file)
1983 i2ChanStrPtr pCh = DevTable[tty->index];
1984 #ifdef ENABLE_DSSNOW
1992 FIXME - the following code is causing a NULL pointer dereference in
1993 2.3.51 in an interrupt handler. It's suppose to prompt the board
1994 to return the DSS signal status immediately. Why doesn't it do
1995 the same thing in 2.2.14?
1998 /* This thing is still busted in the 1.2.12 driver on 2.4.x
1999 and even hoses the serial console so the oops can be trapped.
2002 #ifdef ENABLE_DSSNOW
2003 i2QueueCommands(PTYPE_BYPASS, pCh, 100, 1, CMD_DSS_NOW);
2005 init_waitqueue_entry(&wait, current);
2006 add_wait_queue(&pCh->dss_now_wait, &wait);
2007 set_current_state( TASK_INTERRUPTIBLE );
2009 serviceOutgoingFifo( pCh->pMyBord );
2013 set_current_state( TASK_RUNNING );
2014 remove_wait_queue(&pCh->dss_now_wait, &wait);
2016 if (signal_pending(current)) {
2020 return ((pCh->dataSetOut & I2_RTS) ? TIOCM_RTS : 0)
2021 | ((pCh->dataSetOut & I2_DTR) ? TIOCM_DTR : 0)
2022 | ((pCh->dataSetIn & I2_DCD) ? TIOCM_CAR : 0)
2023 | ((pCh->dataSetIn & I2_RI) ? TIOCM_RNG : 0)
2024 | ((pCh->dataSetIn & I2_DSR) ? TIOCM_DSR : 0)
2025 | ((pCh->dataSetIn & I2_CTS) ? TIOCM_CTS : 0);
2028 static int ip2_tiocmset(struct tty_struct *tty, struct file *file,
2029 unsigned int set, unsigned int clear)
2031 i2ChanStrPtr pCh = DevTable[tty->index];
2036 if (set & TIOCM_RTS) {
2037 i2QueueCommands(PTYPE_INLINE, pCh, 100, 1, CMD_RTSUP);
2038 pCh->dataSetOut |= I2_RTS;
2040 if (set & TIOCM_DTR) {
2041 i2QueueCommands(PTYPE_INLINE, pCh, 100, 1, CMD_DTRUP);
2042 pCh->dataSetOut |= I2_DTR;
2045 if (clear & TIOCM_RTS) {
2046 i2QueueCommands(PTYPE_INLINE, pCh, 100, 1, CMD_RTSDN);
2047 pCh->dataSetOut &= ~I2_RTS;
2049 if (clear & TIOCM_DTR) {
2050 i2QueueCommands(PTYPE_INLINE, pCh, 100, 1, CMD_DTRDN);
2051 pCh->dataSetOut &= ~I2_DTR;
2053 serviceOutgoingFifo( pCh->pMyBord );
2057 /******************************************************************************/
2058 /* Function: ip2_ioctl() */
2059 /* Parameters: Pointer to tty structure */
2060 /* Pointer to file structure */
2063 /* Returns: Success or failure */
2068 /******************************************************************************/
2070 ip2_ioctl ( PTTY tty, struct file *pFile, UINT cmd, ULONG arg )
2073 i2ChanStrPtr pCh = DevTable[tty->index];
2075 struct async_icount cprev, cnow; /* kernel counter temps */
2076 struct serial_icounter_struct __user *p_cuser;
2078 unsigned long flags;
2079 void __user *argp = (void __user *)arg;
2086 ip2trace (CHANN, ITRC_IOCTL, ITRC_ENTER, 2, cmd, arg );
2088 #ifdef IP2DEBUG_IOCTL
2089 printk(KERN_DEBUG "IP2: ioctl cmd (%x), arg (%lx)\n", cmd, arg );
2095 ip2trace (CHANN, ITRC_IOCTL, 2, 1, rc );
2097 rc = get_serial_info(pCh, argp);
2104 ip2trace (CHANN, ITRC_IOCTL, 3, 1, rc );
2106 rc = set_serial_info(pCh, argp);
2112 rc = tty_check_change(tty);
2117 //return -ENOIOCTLCMD;
2120 //return -ENOIOCTLCMD;
2123 if (STOP_CHAR(tty) != __DISABLED_CHAR) {
2124 i2QueueCommands( PTYPE_BYPASS, pCh, 100, 1,
2125 CMD_XMIT_NOW(STOP_CHAR(tty)));
2129 if (START_CHAR(tty) != __DISABLED_CHAR) {
2130 i2QueueCommands( PTYPE_BYPASS, pCh, 100, 1,
2131 CMD_XMIT_NOW(START_CHAR(tty)));
2139 case TCSBRK: /* SVID version: non-zero arg --> no break */
2140 rc = tty_check_change(tty);
2142 ip2trace (CHANN, ITRC_IOCTL, 4, 1, rc );
2145 ip2_wait_until_sent(tty,0);
2147 i2QueueCommands(PTYPE_INLINE, pCh, 100, 1, CMD_SEND_BRK(250));
2148 serviceOutgoingFifo( pCh->pMyBord );
2153 case TCSBRKP: /* support for POSIX tcsendbreak() */
2154 rc = tty_check_change(tty);
2156 ip2trace (CHANN, ITRC_IOCTL, 5, 1, rc );
2159 ip2_wait_until_sent(tty,0);
2160 i2QueueCommands(PTYPE_INLINE, pCh, 100, 1,
2161 CMD_SEND_BRK(arg ? arg*100 : 250));
2162 serviceOutgoingFifo ( pCh->pMyBord );
2168 ip2trace (CHANN, ITRC_IOCTL, 6, 1, rc );
2170 rc = put_user(C_CLOCAL(tty) ? 1 : 0, (unsigned long __user *)argp);
2177 ip2trace (CHANN, ITRC_IOCTL, 7, 1, rc );
2179 rc = get_user(arg,(unsigned long __user *) argp);
2182 tty->termios->c_cflag = ((tty->termios->c_cflag & ~CLOCAL)
2183 | (arg ? CLOCAL : 0));
2188 * Wait for any of the 4 modem inputs (DCD,RI,DSR,CTS) to change - mask
2189 * passed in arg for lines of interest (use |'ed TIOCM_RNG/DSR/CD/CTS
2190 * for masking). Caller should use TIOCGICOUNT to see which one it was
2193 WRITE_LOCK_IRQSAVE(&pB->read_fifo_spinlock, flags);
2194 cprev = pCh->icount; /* note the counters on entry */
2195 WRITE_UNLOCK_IRQRESTORE(&pB->read_fifo_spinlock, flags);
2196 i2QueueCommands(PTYPE_BYPASS, pCh, 100, 4,
2197 CMD_DCD_REP, CMD_CTS_REP, CMD_DSR_REP, CMD_RI_REP);
2198 init_waitqueue_entry(&wait, current);
2199 add_wait_queue(&pCh->delta_msr_wait, &wait);
2200 set_current_state( TASK_INTERRUPTIBLE );
2202 serviceOutgoingFifo( pCh->pMyBord );
2204 ip2trace (CHANN, ITRC_IOCTL, 10, 0 );
2208 ip2trace (CHANN, ITRC_IOCTL, 11, 0 );
2210 /* see if a signal did it */
2211 if (signal_pending(current)) {
2215 WRITE_LOCK_IRQSAVE(&pB->read_fifo_spinlock, flags);
2216 cnow = pCh->icount; /* atomic copy */
2217 WRITE_UNLOCK_IRQRESTORE(&pB->read_fifo_spinlock, flags);
2218 if (cnow.rng == cprev.rng && cnow.dsr == cprev.dsr &&
2219 cnow.dcd == cprev.dcd && cnow.cts == cprev.cts) {
2220 rc = -EIO; /* no change => rc */
2223 if (((arg & TIOCM_RNG) && (cnow.rng != cprev.rng)) ||
2224 ((arg & TIOCM_DSR) && (cnow.dsr != cprev.dsr)) ||
2225 ((arg & TIOCM_CD) && (cnow.dcd != cprev.dcd)) ||
2226 ((arg & TIOCM_CTS) && (cnow.cts != cprev.cts)) ) {
2232 set_current_state( TASK_RUNNING );
2233 remove_wait_queue(&pCh->delta_msr_wait, &wait);
2235 i2QueueCommands(PTYPE_BYPASS, pCh, 100, 3,
2236 CMD_CTS_NREP, CMD_DSR_NREP, CMD_RI_NREP);
2237 if ( ! (pCh->flags & ASYNC_CHECK_CD)) {
2238 i2QueueCommands(PTYPE_BYPASS, pCh, 100, 1, CMD_DCD_NREP);
2240 serviceOutgoingFifo( pCh->pMyBord );
2245 * Get counter of input serial line interrupts (DCD,RI,DSR,CTS)
2246 * Return: write counters to the user passed counter struct
2247 * NB: both 1->0 and 0->1 transitions are counted except for RI where
2248 * only 0->1 is counted. The controller is quite capable of counting
2249 * both, but this done to preserve compatibility with the standard
2253 ip2trace (CHANN, ITRC_IOCTL, 11, 1, rc );
2255 WRITE_LOCK_IRQSAVE(&pB->read_fifo_spinlock, flags);
2257 WRITE_UNLOCK_IRQRESTORE(&pB->read_fifo_spinlock, flags);
2259 rc = put_user(cnow.cts, &p_cuser->cts);
2260 rc = put_user(cnow.dsr, &p_cuser->dsr);
2261 rc = put_user(cnow.rng, &p_cuser->rng);
2262 rc = put_user(cnow.dcd, &p_cuser->dcd);
2263 rc = put_user(cnow.rx, &p_cuser->rx);
2264 rc = put_user(cnow.tx, &p_cuser->tx);
2265 rc = put_user(cnow.frame, &p_cuser->frame);
2266 rc = put_user(cnow.overrun, &p_cuser->overrun);
2267 rc = put_user(cnow.parity, &p_cuser->parity);
2268 rc = put_user(cnow.brk, &p_cuser->brk);
2269 rc = put_user(cnow.buf_overrun, &p_cuser->buf_overrun);
2273 * The rest are not supported by this driver. By returning -ENOIOCTLCMD they
2274 * will be passed to the line discipline for it to handle.
2280 case TIOCSERGSTRUCT:
2281 case TIOCSERGETMULTI:
2282 case TIOCSERSETMULTI:
2285 ip2trace (CHANN, ITRC_IOCTL, 12, 0 );
2291 ip2trace (CHANN, ITRC_IOCTL, ITRC_RETURN, 0 );
2296 /******************************************************************************/
2297 /* Function: GetSerialInfo() */
2298 /* Parameters: Pointer to channel structure */
2299 /* Pointer to old termios structure */
2300 /* Returns: Nothing */
2303 /* This is to support the setserial command, and requires processing of the */
2304 /* standard Linux serial structure. */
2305 /******************************************************************************/
2307 get_serial_info ( i2ChanStrPtr pCh, struct serial_struct __user *retinfo )
2309 struct serial_struct tmp;
2311 memset ( &tmp, 0, sizeof(tmp) );
2312 tmp.type = pCh->pMyBord->channelBtypes.bid_value[(pCh->port_index & (IP2_PORTS_PER_BOARD-1))/16];
2313 if (BID_HAS_654(tmp.type)) {
2314 tmp.type = PORT_16650;
2316 tmp.type = PORT_CIRRUS;
2318 tmp.line = pCh->port_index;
2319 tmp.port = pCh->pMyBord->i2eBase;
2320 tmp.irq = ip2config.irq[pCh->port_index/64];
2321 tmp.flags = pCh->flags;
2322 tmp.baud_base = pCh->BaudBase;
2323 tmp.close_delay = pCh->ClosingDelay;
2324 tmp.closing_wait = pCh->ClosingWaitTime;
2325 tmp.custom_divisor = pCh->BaudDivisor;
2326 return copy_to_user(retinfo,&tmp,sizeof(*retinfo));
2329 /******************************************************************************/
2330 /* Function: SetSerialInfo() */
2331 /* Parameters: Pointer to channel structure */
2332 /* Pointer to old termios structure */
2333 /* Returns: Nothing */
2336 /* This function provides support for setserial, which uses the TIOCSSERIAL */
2337 /* ioctl. Not all setserial parameters are relevant. If the user attempts to */
2338 /* change the IRQ, address or type of the port the ioctl fails. */
2339 /******************************************************************************/
2341 set_serial_info( i2ChanStrPtr pCh, struct serial_struct __user *new_info )
2343 struct serial_struct ns;
2344 int old_flags, old_baud_divisor;
2346 if (copy_from_user(&ns, new_info, sizeof (ns)))
2350 * We don't allow setserial to change IRQ, board address, type or baud
2351 * base. Also line nunber as such is meaningless but we use it for our
2352 * array index so it is fixed also.
2354 if ( (ns.irq != ip2config.irq[pCh->port_index])
2355 || ((int) ns.port != ((int) (pCh->pMyBord->i2eBase)))
2356 || (ns.baud_base != pCh->BaudBase)
2357 || (ns.line != pCh->port_index) ) {
2361 old_flags = pCh->flags;
2362 old_baud_divisor = pCh->BaudDivisor;
2364 if ( !capable(CAP_SYS_ADMIN) ) {
2365 if ( ( ns.close_delay != pCh->ClosingDelay ) ||
2366 ( (ns.flags & ~ASYNC_USR_MASK) !=
2367 (pCh->flags & ~ASYNC_USR_MASK) ) ) {
2371 pCh->flags = (pCh->flags & ~ASYNC_USR_MASK) |
2372 (ns.flags & ASYNC_USR_MASK);
2373 pCh->BaudDivisor = ns.custom_divisor;
2375 pCh->flags = (pCh->flags & ~ASYNC_FLAGS) |
2376 (ns.flags & ASYNC_FLAGS);
2377 pCh->BaudDivisor = ns.custom_divisor;
2378 pCh->ClosingDelay = ns.close_delay * HZ/100;
2379 pCh->ClosingWaitTime = ns.closing_wait * HZ/100;
2382 if ( ( (old_flags & ASYNC_SPD_MASK) != (pCh->flags & ASYNC_SPD_MASK) )
2383 || (old_baud_divisor != pCh->BaudDivisor) ) {
2384 // Invalidate speed and reset parameters
2385 set_params( pCh, NULL );
2391 /******************************************************************************/
2392 /* Function: ip2_set_termios() */
2393 /* Parameters: Pointer to tty structure */
2394 /* Pointer to old termios structure */
2395 /* Returns: Nothing */
2400 /******************************************************************************/
2402 ip2_set_termios( PTTY tty, struct termios *old_termios )
2404 i2ChanStrPtr pCh = (i2ChanStrPtr)tty->driver_data;
2406 #ifdef IP2DEBUG_IOCTL
2407 printk (KERN_DEBUG "IP2: set termios %p\n", old_termios );
2410 set_params( pCh, old_termios );
2413 /******************************************************************************/
2414 /* Function: ip2_set_line_discipline() */
2415 /* Parameters: Pointer to tty structure */
2416 /* Returns: Nothing */
2418 /* Description: Does nothing */
2421 /******************************************************************************/
2423 ip2_set_line_discipline ( PTTY tty )
2425 #ifdef IP2DEBUG_IOCTL
2426 printk (KERN_DEBUG "IP2: set line discipline\n" );
2429 ip2trace (((i2ChanStrPtr)tty->driver_data)->port_index, ITRC_IOCTL, 16, 0 );
2433 /******************************************************************************/
2434 /* Function: SetLine Characteristics() */
2435 /* Parameters: Pointer to channel structure */
2436 /* Returns: Nothing */
2439 /* This routine is called to update the channel structure with the new line */
2440 /* characteristics, and send the appropriate commands to the board when they */
2442 /******************************************************************************/
2444 set_params( i2ChanStrPtr pCh, struct termios *o_tios )
2446 tcflag_t cflag, iflag, lflag;
2447 char stop_char, start_char;
2448 struct termios dummy;
2450 lflag = pCh->pTTY->termios->c_lflag;
2451 cflag = pCh->pTTY->termios->c_cflag;
2452 iflag = pCh->pTTY->termios->c_iflag;
2454 if (o_tios == NULL) {
2455 dummy.c_lflag = ~lflag;
2456 dummy.c_cflag = ~cflag;
2457 dummy.c_iflag = ~iflag;
2462 switch ( cflag & CBAUD ) {
2464 i2QueueCommands( PTYPE_BYPASS, pCh, 100, 2, CMD_RTSDN, CMD_DTRDN);
2465 pCh->dataSetOut &= ~(I2_DTR | I2_RTS);
2466 i2QueueCommands( PTYPE_INLINE, pCh, 100, 1, CMD_PAUSE(25));
2467 pCh->pTTY->termios->c_cflag |= (CBAUD & o_tios->c_cflag);
2472 * This is the speed that is overloaded with all the other high
2473 * speeds, depending upon the flag settings.
2475 if ( ( pCh->flags & ASYNC_SPD_MASK ) == ASYNC_SPD_HI ) {
2476 pCh->speed = CBR_57600;
2477 } else if ( (pCh->flags & ASYNC_SPD_MASK) == ASYNC_SPD_VHI ) {
2478 pCh->speed = CBR_115200;
2479 } else if ( (pCh->flags & ASYNC_SPD_MASK) == ASYNC_SPD_CUST ) {
2480 pCh->speed = CBR_C1;
2482 pCh->speed = CBR_38400;
2485 case B50: pCh->speed = CBR_50; break;
2486 case B75: pCh->speed = CBR_75; break;
2487 case B110: pCh->speed = CBR_110; break;
2488 case B134: pCh->speed = CBR_134; break;
2489 case B150: pCh->speed = CBR_150; break;
2490 case B200: pCh->speed = CBR_200; break;
2491 case B300: pCh->speed = CBR_300; break;
2492 case B600: pCh->speed = CBR_600; break;
2493 case B1200: pCh->speed = CBR_1200; break;
2494 case B1800: pCh->speed = CBR_1800; break;
2495 case B2400: pCh->speed = CBR_2400; break;
2496 case B4800: pCh->speed = CBR_4800; break;
2497 case B9600: pCh->speed = CBR_9600; break;
2498 case B19200: pCh->speed = CBR_19200; break;
2499 case B57600: pCh->speed = CBR_57600; break;
2500 case B115200: pCh->speed = CBR_115200; break;
2501 case B153600: pCh->speed = CBR_153600; break;
2502 case B230400: pCh->speed = CBR_230400; break;
2503 case B307200: pCh->speed = CBR_307200; break;
2504 case B460800: pCh->speed = CBR_460800; break;
2505 case B921600: pCh->speed = CBR_921600; break;
2506 default: pCh->speed = CBR_9600; break;
2508 if ( pCh->speed == CBR_C1 ) {
2509 // Process the custom speed parameters.
2510 int bps = pCh->BaudBase / pCh->BaudDivisor;
2511 if ( bps == 921600 ) {
2512 pCh->speed = CBR_921600;
2515 i2QueueCommands( PTYPE_INLINE, pCh, 100, 1, CMD_BAUD_DEF1(bps) );
2518 i2QueueCommands( PTYPE_INLINE, pCh, 100, 1, CMD_SETBAUD(pCh->speed));
2520 i2QueueCommands ( PTYPE_INLINE, pCh, 100, 2, CMD_DTRUP, CMD_RTSUP);
2521 pCh->dataSetOut |= (I2_DTR | I2_RTS);
2523 if ( (CSTOPB & cflag) ^ (CSTOPB & o_tios->c_cflag))
2525 i2QueueCommands ( PTYPE_INLINE, pCh, 100, 1,
2526 CMD_SETSTOP( ( cflag & CSTOPB ) ? CST_2 : CST_1));
2528 if (((PARENB|PARODD) & cflag) ^ ((PARENB|PARODD) & o_tios->c_cflag))
2530 i2QueueCommands ( PTYPE_INLINE, pCh, 100, 1,
2532 (cflag & PARENB ? (cflag & PARODD ? CSP_OD : CSP_EV) : CSP_NP)
2536 /* byte size and parity */
2537 if ( (CSIZE & cflag)^(CSIZE & o_tios->c_cflag))
2540 switch ( cflag & CSIZE ) {
2541 case CS5: datasize = CSZ_5; break;
2542 case CS6: datasize = CSZ_6; break;
2543 case CS7: datasize = CSZ_7; break;
2544 case CS8: datasize = CSZ_8; break;
2545 default: datasize = CSZ_5; break; /* as per serial.c */
2547 i2QueueCommands ( PTYPE_INLINE, pCh, 100, 1, CMD_SETBITS(datasize) );
2549 /* Process CTS flow control flag setting */
2550 if ( (cflag & CRTSCTS) ) {
2551 i2QueueCommands(PTYPE_INLINE, pCh, 100,
2552 2, CMD_CTSFL_ENAB, CMD_RTSFL_ENAB);
2554 i2QueueCommands(PTYPE_INLINE, pCh, 100,
2555 2, CMD_CTSFL_DSAB, CMD_RTSFL_DSAB);
2558 // Process XON/XOFF flow control flags settings
2560 stop_char = STOP_CHAR(pCh->pTTY);
2561 start_char = START_CHAR(pCh->pTTY);
2563 //////////// can't be \000
2564 if (stop_char == __DISABLED_CHAR )
2566 stop_char = ~__DISABLED_CHAR;
2568 if (start_char == __DISABLED_CHAR )
2570 start_char = ~__DISABLED_CHAR;
2572 /////////////////////////////////
2574 if ( o_tios->c_cc[VSTART] != start_char )
2576 i2QueueCommands(PTYPE_BYPASS, pCh, 100, 1, CMD_DEF_IXON(start_char));
2577 i2QueueCommands(PTYPE_INLINE, pCh, 100, 1, CMD_DEF_OXON(start_char));
2579 if ( o_tios->c_cc[VSTOP] != stop_char )
2581 i2QueueCommands(PTYPE_BYPASS, pCh, 100, 1, CMD_DEF_IXOFF(stop_char));
2582 i2QueueCommands(PTYPE_INLINE, pCh, 100, 1, CMD_DEF_OXOFF(stop_char));
2584 if (stop_char == __DISABLED_CHAR )
2586 stop_char = ~__DISABLED_CHAR; //TEST123
2589 if ((iflag & (IXOFF))^(o_tios->c_iflag & (IXOFF)))
2591 if ( iflag & IXOFF ) { // Enable XOFF output flow control
2592 i2QueueCommands(PTYPE_INLINE, pCh, 100, 1, CMD_OXON_OPT(COX_XON));
2593 } else { // Disable XOFF output flow control
2595 i2QueueCommands(PTYPE_INLINE, pCh, 100, 1, CMD_OXON_OPT(COX_NONE));
2598 if (start_char == __DISABLED_CHAR )
2602 if ((iflag & (IXON|IXANY)) ^ (o_tios->c_iflag & (IXON|IXANY)))
2604 if ( iflag & IXON ) {
2605 if ( iflag & IXANY ) { // Enable XON/XANY output flow control
2606 i2QueueCommands(PTYPE_INLINE, pCh, 100, 1, CMD_IXON_OPT(CIX_XANY));
2607 } else { // Enable XON output flow control
2608 i2QueueCommands(PTYPE_INLINE, pCh, 100, 1, CMD_IXON_OPT(CIX_XON));
2610 } else { // Disable XON output flow control
2612 i2QueueCommands(PTYPE_INLINE, pCh, 100, 1, CMD_IXON_OPT(CIX_NONE));
2615 if ( (iflag & ISTRIP) ^ ( o_tios->c_iflag & (ISTRIP)) )
2617 i2QueueCommands(PTYPE_INLINE, pCh, 100, 1,
2618 CMD_ISTRIP_OPT((iflag & ISTRIP ? 1 : 0)));
2620 if ( (iflag & INPCK) ^ ( o_tios->c_iflag & (INPCK)) )
2622 i2QueueCommands(PTYPE_INLINE, pCh, 100, 1,
2623 CMD_PARCHK((iflag & INPCK) ? CPK_ENAB : CPK_DSAB));
2626 if ( (iflag & (IGNBRK|PARMRK|BRKINT|IGNPAR))
2627 ^ ( o_tios->c_iflag & (IGNBRK|PARMRK|BRKINT|IGNPAR)) )
2632 if ( iflag & IGNBRK ) { /* Ignore breaks altogether */
2633 /* Ignore breaks altogether */
2634 i2QueueCommands(PTYPE_INLINE, pCh, 100, 1, CMD_BRK_NREP);
2636 if ( iflag & BRKINT ) {
2637 if ( iflag & PARMRK ) {
2638 brkrpt = 0x0a; // exception an inline triple
2640 brkrpt = 0x1a; // exception and NULL
2642 brkrpt |= 0x04; // flush input
2644 if ( iflag & PARMRK ) {
2645 brkrpt = 0x0b; //POSIX triple \0377 \0 \0
2647 brkrpt = 0x01; // Null only
2650 i2QueueCommands(PTYPE_INLINE, pCh, 100, 1, CMD_BRK_REP(brkrpt));
2653 if (iflag & IGNPAR) {
2655 /* would be 2 for not cirrus bug */
2656 /* would be 0x20 cept for cirrus bug */
2658 if ( iflag & PARMRK ) {
2660 * Replace error characters with 3-byte sequence (\0377,\0,char)
2663 i2QueueCommands(PTYPE_INLINE, pCh, 100, 1, CMD_ISTRIP_OPT((char)0));
2668 i2QueueCommands(PTYPE_INLINE, pCh, 100, 1, CMD_SET_ERROR(parrpt));
2670 if (cflag & CLOCAL) {
2671 // Status reporting fails for DCD if this is off
2672 i2QueueCommands(PTYPE_INLINE, pCh, 100, 1, CMD_DCD_NREP);
2673 pCh->flags &= ~ASYNC_CHECK_CD;
2675 i2QueueCommands(PTYPE_INLINE, pCh, 100, 1, CMD_DCD_REP);
2676 pCh->flags |= ASYNC_CHECK_CD;
2680 i2DrainOutput( pCh, 100 );
2683 /******************************************************************************/
2684 /* IPL Device Section */
2685 /******************************************************************************/
2687 /******************************************************************************/
2688 /* Function: ip2_ipl_read() */
2689 /* Parameters: Pointer to device inode */
2690 /* Pointer to file structure */
2691 /* Pointer to data */
2692 /* Number of bytes to read */
2693 /* Returns: Success or failure */
2695 /* Description: Ugly */
2698 /******************************************************************************/
2702 ip2_ipl_read(struct file *pFile, char __user *pData, size_t count, loff_t *off )
2704 unsigned int minor = iminor(pFile->f_dentry->d_inode);
2708 printk (KERN_DEBUG "IP2IPL: read %p, %d bytes\n", pData, count );
2712 case 0: // IPL device
2715 case 1: // Status dump
2718 case 2: // Ping device
2721 case 3: // Trace device
2722 rc = DumpTraceBuffer ( pData, count );
2724 case 4: // Trace device
2725 rc = DumpFifoBuffer ( pData, count );
2735 DumpFifoBuffer ( char __user *pData, int count )
2739 rc = copy_to_user(pData, DBGBuf, count);
2741 printk(KERN_DEBUG "Last index %d\n", I );
2744 #endif /* DEBUG_FIFO */
2749 DumpTraceBuffer ( char __user *pData, int count )
2751 #ifdef IP2DEBUG_TRACE
2755 int *pIndex = (int __user *)pData;
2757 if ( count < (sizeof(int) * 6) ) {
2760 rc = put_user(tracewrap, pIndex );
2761 rc = put_user(TRACEMAX, ++pIndex );
2762 rc = put_user(tracestrip, ++pIndex );
2763 rc = put_user(tracestuff, ++pIndex );
2764 pData += sizeof(int) * 6;
2765 count -= sizeof(int) * 6;
2767 dumpcount = tracestuff - tracestrip;
2768 if ( dumpcount < 0 ) {
2769 dumpcount += TRACEMAX;
2771 if ( dumpcount > count ) {
2774 chunk = TRACEMAX - tracestrip;
2775 if ( dumpcount > chunk ) {
2776 rc = copy_to_user(pData, &tracebuf[tracestrip],
2777 chunk * sizeof(tracebuf[0]) );
2778 pData += chunk * sizeof(tracebuf[0]);
2780 chunk = dumpcount - chunk;
2784 rc = copy_to_user(pData, &tracebuf[tracestrip],
2785 chunk * sizeof(tracebuf[0]) );
2786 tracestrip += chunk;
2789 rc = put_user(tracestrip, ++pIndex );
2790 rc = put_user(tracestuff, ++pIndex );
2798 /******************************************************************************/
2799 /* Function: ip2_ipl_write() */
2801 /* Pointer to file structure */
2802 /* Pointer to data */
2803 /* Number of bytes to write */
2804 /* Returns: Success or failure */
2809 /******************************************************************************/
2811 ip2_ipl_write(struct file *pFile, const char __user *pData, size_t count, loff_t *off)
2814 printk (KERN_DEBUG "IP2IPL: write %p, %d bytes\n", pData, count );
2819 /******************************************************************************/
2820 /* Function: ip2_ipl_ioctl() */
2821 /* Parameters: Pointer to device inode */
2822 /* Pointer to file structure */
2825 /* Returns: Success or failure */
2830 /******************************************************************************/
2832 ip2_ipl_ioctl ( struct inode *pInode, struct file *pFile, UINT cmd, ULONG arg )
2834 unsigned int iplminor = iminor(pInode);
2836 void __user *argp = (void __user *)arg;
2837 ULONG __user *pIndex = argp;
2838 i2eBordStrPtr pB = i2BoardPtrTable[iplminor / 4];
2842 printk (KERN_DEBUG "IP2IPL: ioctl cmd %d, arg %ld\n", cmd, arg );
2845 switch ( iplminor ) {
2846 case 0: // IPL device
2849 case 1: // Status dump
2854 case 64: /* Driver - ip2stat */
2855 rc = put_user(ip2_tty_driver->refcount, pIndex++ );
2856 rc = put_user(irq_counter, pIndex++ );
2857 rc = put_user(bh_counter, pIndex++ );
2860 case 65: /* Board - ip2stat */
2862 rc = copy_to_user(argp, pB, sizeof(i2eBordStr));
2863 rc = put_user(INB(pB->i2eStatus),
2864 (ULONG __user *)(arg + (ULONG)(&pB->i2eStatus) - (ULONG)pB ) );
2871 if (cmd < IP2_MAX_PORTS) {
2872 pCh = DevTable[cmd];
2875 rc = copy_to_user(argp, pCh, sizeof(i2ChanStr));
2885 case 2: // Ping device
2888 case 3: // Trace device
2890 * akpm: This used to write a whole bunch of function addresses
2891 * to userspace, which generated lots of put_user() warnings.
2892 * I killed it all. Just return "success" and don't do
2908 /******************************************************************************/
2909 /* Function: ip2_ipl_open() */
2910 /* Parameters: Pointer to device inode */
2911 /* Pointer to file structure */
2912 /* Returns: Success or failure */
2917 /******************************************************************************/
2919 ip2_ipl_open( struct inode *pInode, struct file *pFile )
2921 unsigned int iplminor = iminor(pInode);
2926 printk (KERN_DEBUG "IP2IPL: open\n" );
2930 // These are the IPL devices
2937 // These are the status devices
2944 // These are the debug devices
2949 pB = i2BoardPtrTable[iplminor / 4];
2950 pCh = (i2ChanStrPtr) pB->i2eChannelPtr;
2953 // This is the trace device
2959 /******************************************************************************/
2960 /* Function: ip2_read_procmem */
2963 /* Returns: Length of output */
2966 /* Supplies some driver operating parameters */
2967 /* Not real useful unless your debugging the fifo */
2969 /******************************************************************************/
2971 #define LIMIT (PAGE_SIZE - 120)
2974 ip2_read_procmem(char *buf, char **start, off_t offset, int len)
2983 #define FMTLINE "%3d: 0x%08x 0x%08x 0%011o 0%011o\n"
2984 #define FMTLIN2 " 0x%04x 0x%04x tx flow 0x%x\n"
2985 #define FMTLIN3 " 0x%04x 0x%04x rc flow\n"
2987 len += sprintf(buf+len,"\n");
2989 for( i = 0; i < IP2_MAX_BOARDS; ++i ) {
2990 pB = i2BoardPtrTable[i];
2992 len += sprintf(buf+len,"board %d:\n",i);
2993 len += sprintf(buf+len,"\tFifo rem: %d mty: %x outM %x\n",
2994 pB->i2eFifoRemains,pB->i2eWaitingForEmptyFifo,pB->i2eOutMailWaiting);
2998 len += sprintf(buf+len,"#: tty flags, port flags, cflags, iflags\n");
2999 for (i=0; i < IP2_MAX_PORTS; i++) {
3005 if (tty && tty->count) {
3006 len += sprintf(buf+len,FMTLINE,i,(int)tty->flags,pCh->flags,
3007 tty->termios->c_cflag,tty->termios->c_iflag);
3009 len += sprintf(buf+len,FMTLIN2,
3010 pCh->outfl.asof,pCh->outfl.room,pCh->channelNeeds);
3011 len += sprintf(buf+len,FMTLIN3,pCh->infl.asof,pCh->infl.room);
3019 * This is the handler for /proc/tty/driver/ip2
3021 * This stretch of code has been largely plagerized from at least three
3022 * different sources including ip2mkdev.c and a couple of other drivers.
3023 * The bugs are all mine. :-) =mhw=
3025 static int ip2_read_proc(char *page, char **start, off_t off,
3026 int count, int *eof, void *data)
3036 len += sprintf(page, "ip2info: 1.0 driver: %s\n", pcVersion );
3037 len += sprintf(page+len, "Driver: SMajor=%d CMajor=%d IMajor=%d MaxBoards=%d MaxBoxes=%d MaxPorts=%d\n",
3038 IP2_TTY_MAJOR, IP2_CALLOUT_MAJOR, IP2_IPL_MAJOR,
3039 IP2_MAX_BOARDS, ABS_MAX_BOXES, ABS_BIGGEST_BOX);
3041 for( i = 0; i < IP2_MAX_BOARDS; ++i ) {
3042 /* This need to be reset for a board by board count... */
3044 pB = i2BoardPtrTable[i];
3046 switch( pB->i2ePom.e.porID & ~POR_ID_RESERVED )
3049 len += sprintf( page+len, "Board %d: EX ports=", i );
3050 for( box = 0; box < ABS_MAX_BOXES; ++box )
3054 if( pB->i2eChannelMap[box] != 0 ) ++boxes;
3055 for( j = 0; j < ABS_BIGGEST_BOX; ++j )
3057 if( pB->i2eChannelMap[box] & 1<< j ) {
3061 len += sprintf( page+len, "%d,", ports );
3065 --len; /* Backup over that last comma */
3067 len += sprintf( page+len, " boxes=%d width=%d", boxes, pB->i2eDataWidth16 ? 16 : 8 );
3071 len += sprintf(page+len, "Board %d: ISA-4 ports=4 boxes=1", i );
3076 len += sprintf(page+len, "Board %d: ISA-8-std ports=8 boxes=1", i );
3081 len += sprintf(page+len, "Board %d: ISA-8-RJ11 ports=8 boxes=1", i );
3086 len += sprintf(page+len, "Board %d: unknown", i );
3087 /* Don't try and probe for minor numbers */
3092 /* Don't try and probe for minor numbers */
3093 len += sprintf(page+len, "Board %d: vacant", i );
3098 len += sprintf(page+len, " minors=" );
3100 for ( box = 0; box < ABS_MAX_BOXES; ++box )
3102 for ( j = 0; j < ABS_BIGGEST_BOX; ++j )
3104 if ( pB->i2eChannelMap[box] & (1 << j) )
3106 len += sprintf (page+len,"%d,",
3107 j + ABS_BIGGEST_BOX *
3108 (box+i*ABS_MAX_BOXES));
3113 page[ len - 1 ] = '\n'; /* Overwrite that last comma */
3115 len += sprintf (page+len,"\n" );
3118 if (len+begin > off+count)
3120 if (len+begin < off) {
3126 if (i >= IP2_MAX_BOARDS)
3128 if (off >= len+begin)
3131 *start = page + (off-begin);
3132 return ((count < begin+len-off) ? count : begin+len-off);
3135 /******************************************************************************/
3136 /* Function: ip2trace() */
3137 /* Parameters: Value to add to trace buffer */
3138 /* Returns: Nothing */
3143 /******************************************************************************/
3144 #ifdef IP2DEBUG_TRACE
3146 ip2trace (unsigned short pn, unsigned char cat, unsigned char label, unsigned long codes, ...)
3149 unsigned long *pCode = &codes;
3150 union ip2breadcrumb bc;
3154 tracebuf[tracestuff++] = jiffies;
3155 if ( tracestuff == TRACEMAX ) {
3158 if ( tracestuff == tracestrip ) {
3159 if ( ++tracestrip == TRACEMAX ) {
3165 bc.hdr.port = 0xff & pn;
3167 bc.hdr.codes = (unsigned char)( codes & 0xff );
3168 bc.hdr.label = label;
3169 tracebuf[tracestuff++] = bc.value;
3172 if ( tracestuff == TRACEMAX ) {
3175 if ( tracestuff == tracestrip ) {
3176 if ( ++tracestrip == TRACEMAX ) {
3185 tracebuf[tracestuff++] = *++pCode;
3191 MODULE_LICENSE("GPL");