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
86 #include <linux/ctype.h>
87 #include <linux/string.h>
88 #include <linux/fcntl.h>
89 #include <linux/errno.h>
90 #include <linux/module.h>
91 #include <linux/signal.h>
92 #include <linux/sched.h>
93 #include <linux/timer.h>
94 #include <linux/interrupt.h>
95 #include <linux/pci.h>
97 #include <linux/slab.h>
98 #include <linux/major.h>
99 #include <linux/wait.h>
100 #include <linux/device.h>
102 #include <linux/tty.h>
103 #include <linux/tty_flip.h>
104 #include <linux/termios.h>
105 #include <linux/tty_driver.h>
106 #include <linux/serial.h>
107 #include <linux/ptrace.h>
108 #include <linux/ioport.h>
110 #include <linux/cdk.h>
111 #include <linux/comstats.h>
112 #include <linux/delay.h>
113 #include <linux/bitops.h>
115 #include <asm/system.h>
119 #include <linux/vmalloc.h>
120 #include <linux/init.h>
122 #include <asm/uaccess.h>
124 #include "ip2types.h"
125 #include "ip2trace.h"
126 #include "ip2ioctl.h"
135 #include <linux/proc_fs.h>
136 #include <linux/seq_file.h>
138 static const struct file_operations ip2mem_proc_fops;
139 static int ip2_read_proc(char *, char **, off_t, int, int *, void * );
141 /********************/
142 /* Type Definitions */
143 /********************/
149 /* String constants to identify ourselves */
150 static char *pcName = "Computone IntelliPort Plus multiport driver";
151 static char *pcVersion = "1.2.14";
153 /* String constants for port names */
154 static char *pcDriver_name = "ip2";
155 static char *pcIpl = "ip2ipl";
157 // cheezy kludge or genius - you decide?
158 int ip2_loadmain(int *, int *, unsigned char *, int);
159 static unsigned char *Fip_firmware;
160 static int Fip_firmware_size;
162 /***********************/
163 /* Function Prototypes */
164 /***********************/
166 /* Global module entry functions */
168 /* Private (static) functions */
169 static int ip2_open(PTTY, struct file *);
170 static void ip2_close(PTTY, struct file *);
171 static int ip2_write(PTTY, const unsigned char *, int);
172 static void ip2_putchar(PTTY, unsigned char);
173 static void ip2_flush_chars(PTTY);
174 static int ip2_write_room(PTTY);
175 static int ip2_chars_in_buf(PTTY);
176 static void ip2_flush_buffer(PTTY);
177 static int ip2_ioctl(PTTY, struct file *, UINT, ULONG);
178 static void ip2_set_termios(PTTY, struct ktermios *);
179 static void ip2_set_line_discipline(PTTY);
180 static void ip2_throttle(PTTY);
181 static void ip2_unthrottle(PTTY);
182 static void ip2_stop(PTTY);
183 static void ip2_start(PTTY);
184 static void ip2_hangup(PTTY);
185 static int ip2_tiocmget(struct tty_struct *tty, struct file *file);
186 static int ip2_tiocmset(struct tty_struct *tty, struct file *file,
187 unsigned int set, unsigned int clear);
189 static void set_irq(int, int);
190 static void ip2_interrupt_bh(struct work_struct *work);
191 static irqreturn_t ip2_interrupt(int irq, void *dev_id);
192 static void ip2_poll(unsigned long arg);
193 static inline void service_all_boards(void);
194 static void do_input(struct work_struct *);
195 static void do_status(struct work_struct *);
197 static void ip2_wait_until_sent(PTTY,int);
199 static void set_params (i2ChanStrPtr, struct ktermios *);
200 static int get_serial_info(i2ChanStrPtr, struct serial_struct __user *);
201 static int set_serial_info(i2ChanStrPtr, struct serial_struct __user *);
203 static ssize_t ip2_ipl_read(struct file *, char __user *, size_t, loff_t *);
204 static ssize_t ip2_ipl_write(struct file *, const char __user *, size_t, loff_t *);
205 static int ip2_ipl_ioctl(struct inode *, struct file *, UINT, ULONG);
206 static int ip2_ipl_open(struct inode *, struct file *);
208 static int DumpTraceBuffer(char __user *, int);
209 static int DumpFifoBuffer( char __user *, int);
211 static void ip2_init_board(int);
212 static unsigned short find_eisa_board(int);
218 static struct tty_driver *ip2_tty_driver;
220 /* Here, then is a table of board pointers which the interrupt routine should
221 * scan through to determine who it must service.
223 static unsigned short i2nBoards; // Number of boards here
225 static i2eBordStrPtr i2BoardPtrTable[IP2_MAX_BOARDS];
227 static i2ChanStrPtr DevTable[IP2_MAX_PORTS];
228 //DevTableMem just used to save addresses for kfree
229 static void *DevTableMem[IP2_MAX_BOARDS];
231 /* This is the driver descriptor for the ip2ipl device, which is used to
232 * download the loadware to the boards.
234 static const struct file_operations ip2_ipl = {
235 .owner = THIS_MODULE,
236 .read = ip2_ipl_read,
237 .write = ip2_ipl_write,
238 .ioctl = ip2_ipl_ioctl,
239 .open = ip2_ipl_open,
242 static unsigned long irq_counter = 0;
243 static unsigned long bh_counter = 0;
245 // Use immediate queue to service interrupts
247 //#define USE_IQ // PCI&2.2 needs work
249 /* The timer_list entry for our poll routine. If interrupt operation is not
250 * selected, the board is serviced periodically to see if anything needs doing.
252 #define POLL_TIMEOUT (jiffies + 1)
253 static DEFINE_TIMER(PollTimer, ip2_poll, 0, 0);
256 #ifdef IP2DEBUG_TRACE
257 /* Trace (debug) buffer data */
258 #define TRACEMAX 1000
259 static unsigned long tracebuf[TRACEMAX];
260 static int tracestuff;
261 static int tracestrip;
262 static int tracewrap;
269 #if defined(MODULE) && defined(IP2DEBUG_OPEN)
270 #define DBG_CNT(s) printk(KERN_DEBUG "(%s): [%x] refc=%d, ttyc=%d, modc=%x -> %s\n", \
271 tty->name,(pCh->flags),ip2_tty_driver->refcount, \
272 tty->count,/*GET_USE_COUNT(module)*/0,s)
281 #include "i2ellis.c" /* Extremely low-level interface services */
282 #include "i2cmd.c" /* Standard loadware command definitions */
283 #include "i2lib.c" /* High level interface services */
285 /* Configuration area for modprobe */
287 MODULE_AUTHOR("Doug McNash");
288 MODULE_DESCRIPTION("Computone IntelliPort Plus Driver");
290 static int poll_only = 0;
293 static int Eisa_slot;
296 static char rirqs[IP2_MAX_BOARDS];
297 static int Valid_Irqs[] = { 3, 4, 5, 7, 10, 11, 12, 15, 0};
299 /* for sysfs class support */
300 static struct class *ip2_class;
302 // Some functions to keep track of what irq's we have
305 is_valid_irq(int irq)
309 while ((*i != 0) && (*i != irq)) {
316 mark_requested_irq( char irq )
318 rirqs[iindx++] = irq;
323 clear_requested_irq( char irq )
326 for ( i = 0; i < IP2_MAX_BOARDS; ++i ) {
327 if (rirqs[i] == irq) {
337 have_requested_irq( char irq )
339 // array init to zeros so 0 irq will not be requested as a side effect
341 for ( i = 0; i < IP2_MAX_BOARDS; ++i ) {
348 /******************************************************************************/
349 /* Function: init_module() */
350 /* Parameters: None */
351 /* Returns: Success (0) */
354 /* This is a required entry point for an installable module. It simply calls */
355 /* the driver initialisation function and returns what it returns. */
356 /******************************************************************************/
362 printk (KERN_DEBUG "Loading module ...\n" );
368 /******************************************************************************/
369 /* Function: cleanup_module() */
370 /* Parameters: None */
371 /* Returns: Nothing */
374 /* This is a required entry point for an installable module. It has to return */
375 /* the device and the driver to a passive state. It should not be necessary */
376 /* to reset the board fully, especially as the loadware is downloaded */
377 /* externally rather than in the driver. We just want to disable the board */
378 /* and clear the loadware to a reset state. To allow this there has to be a */
379 /* way to detect whether the board has the loadware running at init time to */
380 /* handle subsequent installations of the driver. All memory allocated by the */
381 /* driver should be returned since it may be unloaded from memory. */
382 /******************************************************************************/
391 printk (KERN_DEBUG "Unloading %s: version %s\n", pcName, pcVersion );
393 /* Stop poll timer if we had one. */
395 del_timer ( &PollTimer );
399 /* Reset the boards we have. */
400 for( i = 0; i < IP2_MAX_BOARDS; ++i ) {
401 if ( i2BoardPtrTable[i] ) {
402 iiReset( i2BoardPtrTable[i] );
406 /* The following is done at most once, if any boards were installed. */
407 for ( i = 0; i < IP2_MAX_BOARDS; ++i ) {
408 if ( i2BoardPtrTable[i] ) {
409 iiResetDelay( i2BoardPtrTable[i] );
410 /* free io addresses and Tibet */
411 release_region( ip2config.addr[i], 8 );
412 device_destroy(ip2_class, MKDEV(IP2_IPL_MAJOR, 4 * i));
413 device_destroy(ip2_class, MKDEV(IP2_IPL_MAJOR, 4 * i + 1));
415 /* Disable and remove interrupt handler. */
416 if ( (ip2config.irq[i] > 0) && have_requested_irq(ip2config.irq[i]) ) {
417 free_irq ( ip2config.irq[i], (void *)&pcName);
418 clear_requested_irq( ip2config.irq[i]);
421 class_destroy(ip2_class);
422 if ( ( err = tty_unregister_driver ( ip2_tty_driver ) ) ) {
423 printk(KERN_ERR "IP2: failed to unregister tty driver (%d)\n", err);
425 put_tty_driver(ip2_tty_driver);
426 unregister_chrdev(IP2_IPL_MAJOR, pcIpl);
427 remove_proc_entry("ip2mem", NULL);
430 for (i = 0; i < IP2_MAX_BOARDS; i++) {
433 if (ip2config.type[i] == PCI && ip2config.pci_dev[i]) {
434 pci_disable_device(ip2config.pci_dev[i]);
435 pci_dev_put(ip2config.pci_dev[i]);
436 ip2config.pci_dev[i] = NULL;
439 if ((pB = i2BoardPtrTable[i]) != 0 ) {
441 i2BoardPtrTable[i] = NULL;
443 if ((DevTableMem[i]) != NULL ) {
444 kfree ( DevTableMem[i] );
445 DevTableMem[i] = NULL;
449 /* Cleanup the iiEllis subsystem. */
452 printk (KERN_DEBUG "IP2 Unloaded\n" );
457 static const struct tty_operations ip2_ops = {
461 .put_char = ip2_putchar,
462 .flush_chars = ip2_flush_chars,
463 .write_room = ip2_write_room,
464 .chars_in_buffer = ip2_chars_in_buf,
465 .flush_buffer = ip2_flush_buffer,
467 .throttle = ip2_throttle,
468 .unthrottle = ip2_unthrottle,
469 .set_termios = ip2_set_termios,
470 .set_ldisc = ip2_set_line_discipline,
473 .hangup = ip2_hangup,
474 .read_proc = ip2_read_proc,
475 .tiocmget = ip2_tiocmget,
476 .tiocmset = ip2_tiocmset,
479 /******************************************************************************/
480 /* Function: ip2_loadmain() */
481 /* Parameters: irq, io from command line of insmod et. al. */
482 /* pointer to fip firmware and firmware size for boards */
483 /* Returns: Success (0) */
486 /* This was the required entry point for all drivers (now in ip2.c) */
487 /* It performs all */
488 /* initialisation of the devices and driver structures, and registers itself */
489 /* with the relevant kernel modules. */
490 /******************************************************************************/
491 /* IRQF_DISABLED - if set blocks all interrupts else only this line */
492 /* IRQF_SHARED - for shared irq PCI or maybe EISA only */
493 /* SA_RANDOM - can be source for cert. random number generators */
494 #define IP2_SA_FLAGS 0
497 ip2_loadmain(int *iop, int *irqp, unsigned char *firmware, int firmsize)
502 i2eBordStrPtr pB = NULL;
504 static struct pci_dev *pci_dev_i = NULL;
506 ip2trace (ITRC_NO_PORT, ITRC_INIT, ITRC_ENTER, 0 );
508 /* process command line arguments to modprobe or
509 insmod i.e. iop & irqp */
510 /* irqp and iop should ALWAYS be specified now... But we check
511 them individually just to be sure, anyways... */
512 for ( i = 0; i < IP2_MAX_BOARDS; ++i ) {
514 ip2config.addr[i] = iop[i];
517 ip2config.irq[i] = irqp[i];
519 ip2config.irq[i] = 0;
521 // This is a little bit of a hack. If poll_only=1 on command
522 // line back in ip2.c OR all IRQs on all specified boards are
523 // explicitly set to 0, then drop to poll only mode and override
524 // PCI or EISA interrupts. This superceeds the old hack of
525 // triggering if all interrupts were zero (like da default).
526 // Still a hack but less prone to random acts of terrorism.
528 // What we really should do, now that the IRQ default is set
529 // to -1, is to use 0 as a hard coded, do not probe.
532 poll_only |= irqp[i];
536 poll_only = !poll_only;
538 Fip_firmware = firmware;
539 Fip_firmware_size = firmsize;
541 /* Announce our presence */
542 printk( KERN_INFO "%s version %s\n", pcName, pcVersion );
544 // ip2 can be unloaded and reloaded for no good reason
545 // we can't let that happen here or bad things happen
546 // second load hoses board but not system - fixme later
548 printk( KERN_INFO "Still loaded\n" );
553 ip2_tty_driver = alloc_tty_driver(IP2_MAX_PORTS);
557 /* Initialise the iiEllis subsystem. */
560 /* Initialize arrays. */
561 memset( i2BoardPtrTable, 0, sizeof i2BoardPtrTable );
562 memset( DevTable, 0, sizeof DevTable );
564 /* Initialise all the boards we can find (up to the maximum). */
565 for ( i = 0; i < IP2_MAX_BOARDS; ++i ) {
566 switch ( ip2config.addr[i] ) {
567 case 0: /* skip this slot even if card is present */
570 /* ISA address must be specified */
571 if ( (ip2config.addr[i] < 0x100) || (ip2config.addr[i] > 0x3f8) ) {
572 printk ( KERN_ERR "IP2: Bad ISA board %d address %x\n",
573 i, ip2config.addr[i] );
574 ip2config.addr[i] = 0;
576 ip2config.type[i] = ISA;
578 /* Check for valid irq argument, set for polling if invalid */
579 if (ip2config.irq[i] && !is_valid_irq(ip2config.irq[i])) {
580 printk(KERN_ERR "IP2: Bad IRQ(%d) specified\n",ip2config.irq[i]);
581 ip2config.irq[i] = 0;// 0 is polling and is valid in that sense
590 pci_dev_i = pci_get_device(PCI_VENDOR_ID_COMPUTONE,
591 PCI_DEVICE_ID_COMPUTONE_IP2EX, pci_dev_i);
592 if (pci_dev_i != NULL) {
595 if (pci_enable_device(pci_dev_i)) {
596 printk( KERN_ERR "IP2: can't enable PCI device at %s\n",
597 pci_name(pci_dev_i));
600 ip2config.type[i] = PCI;
601 ip2config.pci_dev[i] = pci_dev_get(pci_dev_i);
603 pci_read_config_dword(pci_dev_i, PCI_BASE_ADDRESS_1, &addr);
605 ip2config.addr[i]=(USHORT)(addr&0xfffe);
607 printk( KERN_ERR "IP2: PCI I/O address error\n");
610 // If the PCI BIOS assigned it, lets try and use it. If we
611 // can't acquire it or it screws up, deal with it then.
613 // if (!is_valid_irq(pci_irq)) {
614 // printk( KERN_ERR "IP2: Bad PCI BIOS IRQ(%d)\n",pci_irq);
617 ip2config.irq[i] = pci_dev_i->irq;
618 } else { // ann error
619 ip2config.addr[i] = 0;
620 printk(KERN_ERR "IP2: PCI board %d not found\n", i);
624 printk( KERN_ERR "IP2: PCI card specified but PCI support not\n");
625 printk( KERN_ERR "IP2: configured in this kernel.\n");
626 printk( KERN_ERR "IP2: Recompile kernel with CONFIG_PCI defined!\n");
627 #endif /* CONFIG_PCI */
630 if ( (ip2config.addr[i] = find_eisa_board( Eisa_slot + 1 )) != 0) {
631 /* Eisa_irq set as side effect, boo */
632 ip2config.type[i] = EISA;
634 ip2config.irq[i] = Eisa_irq;
639 pci_dev_put(pci_dev_i);
641 for ( i = 0; i < IP2_MAX_BOARDS; ++i ) {
642 if ( ip2config.addr[i] ) {
643 pB = kzalloc(sizeof(i2eBordStr), GFP_KERNEL);
645 i2BoardPtrTable[i] = pB;
646 iiSetAddress( pB, ip2config.addr[i], ii2DelayTimer );
649 printk(KERN_ERR "IP2: board memory allocation error\n");
653 for ( i = 0; i < IP2_MAX_BOARDS; ++i ) {
654 if ( ( pB = i2BoardPtrTable[i] ) != NULL ) {
659 for ( i = 0; i < IP2_MAX_BOARDS; ++i ) {
660 if ( i2BoardPtrTable[i] != NULL ) {
665 ip2trace (ITRC_NO_PORT, ITRC_INIT, 2, 0 );
667 ip2_tty_driver->owner = THIS_MODULE;
668 ip2_tty_driver->name = "ttyF";
669 ip2_tty_driver->driver_name = pcDriver_name;
670 ip2_tty_driver->major = IP2_TTY_MAJOR;
671 ip2_tty_driver->minor_start = 0;
672 ip2_tty_driver->type = TTY_DRIVER_TYPE_SERIAL;
673 ip2_tty_driver->subtype = SERIAL_TYPE_NORMAL;
674 ip2_tty_driver->init_termios = tty_std_termios;
675 ip2_tty_driver->init_termios.c_cflag = B9600|CS8|CREAD|HUPCL|CLOCAL;
676 ip2_tty_driver->flags = TTY_DRIVER_REAL_RAW | TTY_DRIVER_DYNAMIC_DEV;
677 tty_set_operations(ip2_tty_driver, &ip2_ops);
679 ip2trace (ITRC_NO_PORT, ITRC_INIT, 3, 0 );
681 /* Register the tty devices. */
682 if ( ( err = tty_register_driver ( ip2_tty_driver ) ) ) {
683 printk(KERN_ERR "IP2: failed to register tty driver (%d)\n", err);
684 put_tty_driver(ip2_tty_driver);
687 /* Register the IPL driver. */
688 if ( ( err = register_chrdev ( IP2_IPL_MAJOR, pcIpl, &ip2_ipl ) ) ) {
689 printk(KERN_ERR "IP2: failed to register IPL device (%d)\n", err );
691 /* create the sysfs class */
692 ip2_class = class_create(THIS_MODULE, "ip2");
693 if (IS_ERR(ip2_class)) {
694 err = PTR_ERR(ip2_class);
698 /* Register the read_procmem thing */
699 if (!proc_create("ip2mem",0,NULL,&ip2mem_proc_fops)) {
700 printk(KERN_ERR "IP2: failed to register read_procmem\n");
703 ip2trace (ITRC_NO_PORT, ITRC_INIT, 4, 0 );
704 /* Register the interrupt handler or poll handler, depending upon the
705 * specified interrupt.
708 for( i = 0; i < IP2_MAX_BOARDS; ++i ) {
709 if ( 0 == ip2config.addr[i] ) {
713 if ( NULL != ( pB = i2BoardPtrTable[i] ) ) {
714 device_create(ip2_class, NULL,
715 MKDEV(IP2_IPL_MAJOR, 4 * i),
717 device_create(ip2_class, NULL,
718 MKDEV(IP2_IPL_MAJOR, 4 * i + 1),
721 for ( box = 0; box < ABS_MAX_BOXES; ++box )
723 for ( j = 0; j < ABS_BIGGEST_BOX; ++j )
725 if ( pB->i2eChannelMap[box] & (1 << j) )
727 tty_register_device(ip2_tty_driver,
728 j + ABS_BIGGEST_BOX *
729 (box+i*ABS_MAX_BOXES), NULL);
736 // Poll only forces driver to only use polling and
737 // to ignore the probed PCI or EISA interrupts.
738 ip2config.irq[i] = CIR_POLL;
740 if ( ip2config.irq[i] == CIR_POLL ) {
743 PollTimer.expires = POLL_TIMEOUT;
744 add_timer ( &PollTimer );
746 printk( KERN_INFO "IP2: polling\n");
749 if (have_requested_irq(ip2config.irq[i]))
751 rc = request_irq( ip2config.irq[i], ip2_interrupt,
752 IP2_SA_FLAGS | (ip2config.type[i] == PCI ? IRQF_SHARED : 0),
753 pcName, i2BoardPtrTable[i]);
755 printk(KERN_ERR "IP2: an request_irq failed: error %d\n",rc);
756 ip2config.irq[i] = CIR_POLL;
757 printk( KERN_INFO "IP2: Polling %ld/sec.\n",
758 (POLL_TIMEOUT - jiffies));
761 mark_requested_irq(ip2config.irq[i]);
762 /* Initialise the interrupt handler bottom half (aka slih). */
765 for( i = 0; i < IP2_MAX_BOARDS; ++i ) {
766 if ( i2BoardPtrTable[i] ) {
767 set_irq( i, ip2config.irq[i] ); /* set and enable board interrupt */
771 ip2trace (ITRC_NO_PORT, ITRC_INIT, ITRC_RETURN, 0 );
775 unregister_chrdev(IP2_IPL_MAJOR, "ip2");
780 EXPORT_SYMBOL(ip2_loadmain);
782 /******************************************************************************/
783 /* Function: ip2_init_board() */
784 /* Parameters: Index of board in configuration structure */
785 /* Returns: Success (0) */
788 /* This function initializes the specified board. The loadware is copied to */
789 /* the board, the channel structures are initialized, and the board details */
790 /* are reported on the console. */
791 /******************************************************************************/
793 ip2_init_board( int boardnum )
796 int nports = 0, nboxes = 0;
798 i2eBordStrPtr pB = i2BoardPtrTable[boardnum];
800 if ( !iiInitialize ( pB ) ) {
801 printk ( KERN_ERR "IP2: Failed to initialize board at 0x%x, error %d\n",
802 pB->i2eBase, pB->i2eError );
805 printk(KERN_INFO "IP2: Board %d: addr=0x%x irq=%d\n", boardnum + 1,
806 ip2config.addr[boardnum], ip2config.irq[boardnum] );
808 if (!request_region( ip2config.addr[boardnum], 8, pcName )) {
809 printk(KERN_ERR "IP2: bad addr=0x%x\n", ip2config.addr[boardnum]);
813 if ( iiDownloadAll ( pB, (loadHdrStrPtr)Fip_firmware, 1, Fip_firmware_size )
815 printk ( KERN_ERR "IP2: failed to download loadware\n" );
816 goto err_release_region;
818 printk ( KERN_INFO "IP2: fv=%d.%d.%d lv=%d.%d.%d\n",
819 pB->i2ePom.e.porVersion,
820 pB->i2ePom.e.porRevision,
821 pB->i2ePom.e.porSubRev, pB->i2eLVersion,
822 pB->i2eLRevision, pB->i2eLSub );
825 switch ( pB->i2ePom.e.porID & ~POR_ID_RESERVED ) {
828 printk( KERN_ERR "IP2: Unknown board type, ID = %x\n",
829 pB->i2ePom.e.porID );
831 goto err_release_region;
834 case POR_ID_II_4: /* IntelliPort-II, ISA-4 (4xRJ45) */
835 printk ( KERN_INFO "IP2: ISA-4\n" );
839 case POR_ID_II_8: /* IntelliPort-II, 8-port using standard brick. */
840 printk ( KERN_INFO "IP2: ISA-8 std\n" );
844 case POR_ID_II_8R: /* IntelliPort-II, 8-port using RJ11's (no CTS) */
845 printk ( KERN_INFO "IP2: ISA-8 RJ11\n" );
849 case POR_ID_FIIEX: /* IntelliPort IIEX */
851 int portnum = IP2_PORTS_PER_BOARD * boardnum;
854 for( box = 0; box < ABS_MAX_BOXES; ++box ) {
855 if ( pB->i2eChannelMap[box] != 0 ) {
858 for( i = 0; i < ABS_BIGGEST_BOX; ++i ) {
859 if ( pB->i2eChannelMap[box] & 1<< i ) {
864 DevTableMem[boardnum] = pCh =
865 kmalloc( sizeof(i2ChanStr) * nports, GFP_KERNEL );
867 printk ( KERN_ERR "IP2: (i2_init_channel:) Out of memory.\n");
868 goto err_release_region;
870 if ( !i2InitChannels( pB, nports, pCh ) ) {
871 printk(KERN_ERR "IP2: i2InitChannels failed: %d\n",pB->i2eError);
873 goto err_release_region;
875 pB->i2eChannelPtr = &DevTable[portnum];
876 pB->i2eChannelCnt = ABS_MOST_PORTS;
878 for( box = 0; box < ABS_MAX_BOXES; ++box, portnum += ABS_BIGGEST_BOX ) {
879 for( i = 0; i < ABS_BIGGEST_BOX; ++i ) {
880 if ( pB->i2eChannelMap[box] & (1 << i) ) {
881 DevTable[portnum + i] = pCh;
882 pCh->port_index = portnum + i;
887 printk(KERN_INFO "IP2: EX box=%d ports=%d %d bit\n",
888 nboxes, nports, pB->i2eDataWidth16 ? 16 : 8 );
892 DevTableMem[boardnum] = pCh =
893 kmalloc ( sizeof (i2ChanStr) * nports, GFP_KERNEL );
895 printk ( KERN_ERR "IP2: (i2_init_channel:) Out of memory.\n");
896 goto err_release_region;
898 pB->i2eChannelPtr = pCh;
899 pB->i2eChannelCnt = nports;
900 if ( !i2InitChannels( pB, nports, pCh ) ) {
901 printk(KERN_ERR "IP2: i2InitChannels failed: %d\n",pB->i2eError);
903 goto err_release_region;
905 pB->i2eChannelPtr = &DevTable[IP2_PORTS_PER_BOARD * boardnum];
907 for( i = 0; i < pB->i2eChannelCnt; ++i ) {
908 DevTable[IP2_PORTS_PER_BOARD * boardnum + i] = pCh;
909 pCh->port_index = (IP2_PORTS_PER_BOARD * boardnum) + i;
913 INIT_WORK(&pB->tqueue_interrupt, ip2_interrupt_bh);
917 release_region(ip2config.addr[boardnum], 8);
920 i2BoardPtrTable[boardnum] = NULL;
924 /******************************************************************************/
925 /* Function: find_eisa_board ( int start_slot ) */
926 /* Parameters: First slot to check */
927 /* Returns: Address of EISA IntelliPort II controller */
930 /* This function searches for an EISA IntelliPort controller, starting */
931 /* from the specified slot number. If the motherboard is not identified as an */
932 /* EISA motherboard, or no valid board ID is selected it returns 0. Otherwise */
933 /* it returns the base address of the controller. */
934 /******************************************************************************/
935 static unsigned short
936 find_eisa_board( int start_slot )
939 unsigned int idm = 0;
940 unsigned int idp = 0;
941 unsigned int base = 0;
948 * First a check for an EISA motherboard, which we do by comparing the
949 * EISA ID registers for the system board and the first couple of slots.
950 * No slot ID should match the system board ID, but on an ISA or PCI
951 * machine the odds are that an empty bus will return similar values for
955 value = (inb(i) << 24) + (inb(i+1) << 16) + (inb(i+2) << 8) + inb(i+3);
956 for( i = 0x1c80; i <= 0x4c80; i += 0x1000 ) {
957 j = (inb(i)<<24)+(inb(i+1)<<16)+(inb(i+2)<<8)+inb(i+3);
963 * OK, so we are inclined to believe that this is an EISA machine. Find
964 * an IntelliPort controller.
966 for( i = start_slot; i < 16; i++ ) {
968 idm = (inb(base + 0xc80) << 8) | (inb(base + 0xc81) & 0xff);
969 idp = (inb(base + 0xc82) << 8) | (inb(base + 0xc83) & 0xff);
971 if ( idm == 0x0e8e ) {
972 if ( idp == 0x0281 || idp == 0x0218 ) {
974 } else if ( idp == 0x0282 || idp == 0x0283 ) {
975 ismine = 3; /* Can do edge-trigger */
986 /* It's some sort of EISA card, but at what address is it configured? */
988 setup_address = base + 0xc88;
989 value = inb(base + 0xc86);
990 setup_irq = (value & 8) ? Valid_Irqs[value & 7] : 0;
992 if ( (ismine & 2) && !(value & 0x10) ) {
993 ismine = 1; /* Could be edging, but not */
996 if ( Eisa_irq == 0 ) {
997 Eisa_irq = setup_irq;
998 } else if ( Eisa_irq != setup_irq ) {
999 printk ( KERN_ERR "IP2: EISA irq mismatch between EISA controllers\n" );
1002 #ifdef IP2DEBUG_INIT
1003 printk(KERN_DEBUG "Computone EISA board in slot %d, I.D. 0x%x%x, Address 0x%x",
1004 base >> 12, idm, idp, setup_address);
1006 printk(KERN_DEBUG ", Interrupt %d %s\n",
1007 setup_irq, (ismine & 2) ? "(edge)" : "(level)");
1009 printk(KERN_DEBUG ", (polled)\n");
1012 return setup_address;
1015 /******************************************************************************/
1016 /* Function: set_irq() */
1017 /* Parameters: index to board in board table */
1019 /* Returns: Success (0) */
1022 /******************************************************************************/
1024 set_irq( int boardnum, int boardIrq )
1026 unsigned char tempCommand[16];
1027 i2eBordStrPtr pB = i2BoardPtrTable[boardnum];
1028 unsigned long flags;
1031 * Notify the boards they may generate interrupts. This is done by
1032 * sending an in-line command to channel 0 on each board. This is why
1033 * the channels have to be defined already. For each board, if the
1034 * interrupt has never been defined, we must do so NOW, directly, since
1035 * board will not send flow control or even give an interrupt until this
1036 * is done. If polling we must send 0 as the interrupt parameter.
1039 // We will get an interrupt here at the end of this function
1041 iiDisableMailIrq(pB);
1043 /* We build up the entire packet header. */
1044 CHANNEL_OF(tempCommand) = 0;
1045 PTYPE_OF(tempCommand) = PTYPE_INLINE;
1046 CMD_COUNT_OF(tempCommand) = 2;
1047 (CMD_OF(tempCommand))[0] = CMDVALUE_IRQ;
1048 (CMD_OF(tempCommand))[1] = boardIrq;
1050 * Write to FIFO; don't bother to adjust fifo capacity for this, since
1051 * board will respond almost immediately after SendMail hit.
1053 WRITE_LOCK_IRQSAVE(&pB->write_fifo_spinlock,flags);
1054 iiWriteBuf(pB, tempCommand, 4);
1055 WRITE_UNLOCK_IRQRESTORE(&pB->write_fifo_spinlock,flags);
1056 pB->i2eUsingIrq = boardIrq;
1057 pB->i2eOutMailWaiting |= MB_OUT_STUFFED;
1059 /* Need to update number of boards before you enable mailbox int */
1062 CHANNEL_OF(tempCommand) = 0;
1063 PTYPE_OF(tempCommand) = PTYPE_BYPASS;
1064 CMD_COUNT_OF(tempCommand) = 6;
1065 (CMD_OF(tempCommand))[0] = 88; // SILO
1066 (CMD_OF(tempCommand))[1] = 64; // chars
1067 (CMD_OF(tempCommand))[2] = 32; // ms
1069 (CMD_OF(tempCommand))[3] = 28; // MAX_BLOCK
1070 (CMD_OF(tempCommand))[4] = 64; // chars
1072 (CMD_OF(tempCommand))[5] = 87; // HW_TEST
1073 WRITE_LOCK_IRQSAVE(&pB->write_fifo_spinlock,flags);
1074 iiWriteBuf(pB, tempCommand, 8);
1075 WRITE_UNLOCK_IRQRESTORE(&pB->write_fifo_spinlock,flags);
1077 CHANNEL_OF(tempCommand) = 0;
1078 PTYPE_OF(tempCommand) = PTYPE_BYPASS;
1079 CMD_COUNT_OF(tempCommand) = 1;
1080 (CMD_OF(tempCommand))[0] = 84; /* get BOX_IDS */
1081 iiWriteBuf(pB, tempCommand, 3);
1084 // enable heartbeat for test porpoises
1085 CHANNEL_OF(tempCommand) = 0;
1086 PTYPE_OF(tempCommand) = PTYPE_BYPASS;
1087 CMD_COUNT_OF(tempCommand) = 2;
1088 (CMD_OF(tempCommand))[0] = 44; /* get ping */
1089 (CMD_OF(tempCommand))[1] = 200; /* 200 ms */
1090 WRITE_LOCK_IRQSAVE(&pB->write_fifo_spinlock,flags);
1091 iiWriteBuf(pB, tempCommand, 4);
1092 WRITE_UNLOCK_IRQRESTORE(&pB->write_fifo_spinlock,flags);
1095 iiEnableMailIrq(pB);
1096 iiSendPendingMail(pB);
1099 /******************************************************************************/
1100 /* Interrupt Handler Section */
1101 /******************************************************************************/
1104 service_all_boards(void)
1109 /* Service every board on the list */
1110 for( i = 0; i < IP2_MAX_BOARDS; ++i ) {
1111 pB = i2BoardPtrTable[i];
1113 i2ServiceBoard( pB );
1119 /******************************************************************************/
1120 /* Function: ip2_interrupt_bh(work) */
1121 /* Parameters: work - pointer to the board structure */
1122 /* Returns: Nothing */
1125 /* Service the board in a bottom half interrupt handler and then */
1126 /* reenable the board's interrupts if it has an IRQ number */
1128 /******************************************************************************/
1130 ip2_interrupt_bh(struct work_struct *work)
1132 i2eBordStrPtr pB = container_of(work, i2eBordStr, tqueue_interrupt);
1133 // pB better well be set or we have a problem! We can only get
1134 // here from the IMMEDIATE queue. Here, we process the boards.
1135 // Checking pB doesn't cost much and it saves us from the sanity checkers.
1140 i2ServiceBoard( pB );
1141 if( pB->i2eUsingIrq ) {
1142 // Re-enable his interrupts
1143 iiEnableMailIrq(pB);
1149 /******************************************************************************/
1150 /* Function: ip2_interrupt(int irq, void *dev_id) */
1151 /* Parameters: irq - interrupt number */
1152 /* pointer to optional device ID structure */
1153 /* Returns: Nothing */
1157 /* Our task here is simply to identify each board which needs servicing. */
1158 /* If we are queuing then, queue it to be serviced, and disable its irq */
1159 /* mask otherwise process the board directly. */
1161 /* We could queue by IRQ but that just complicates things on both ends */
1162 /* with very little gain in performance (how many instructions does */
1163 /* it take to iterate on the immediate queue). */
1166 /******************************************************************************/
1168 ip2_irq_work(i2eBordStrPtr pB)
1171 if (NO_MAIL_HERE != ( pB->i2eStartMail = iiGetMail(pB))) {
1172 // Disable his interrupt (will be enabled when serviced)
1173 // This is mostly to protect from reentrancy.
1174 iiDisableMailIrq(pB);
1176 // Park the board on the immediate queue for processing.
1177 schedule_work(&pB->tqueue_interrupt);
1179 // Make sure the immediate queue is flagged to fire.
1183 // We are using immediate servicing here. This sucks and can
1184 // cause all sorts of havoc with ppp and others. The failsafe
1185 // check on iiSendPendingMail could also throw a hairball.
1187 i2ServiceBoard( pB );
1189 #endif /* USE_IQI */
1193 ip2_polled_interrupt(void)
1199 ip2trace (ITRC_NO_PORT, ITRC_INTR, 99, 1, irq );
1201 /* Service just the boards on the list using this irq */
1202 for( i = 0; i < i2nBoards; ++i ) {
1203 pB = i2BoardPtrTable[i];
1205 // Only process those boards which match our IRQ.
1206 // IRQ = 0 for polled boards, we won't poll "IRQ" boards
1208 if ( pB && (pB->i2eUsingIrq == irq) ) {
1215 ip2trace (ITRC_NO_PORT, ITRC_INTR, ITRC_RETURN, 0 );
1219 ip2_interrupt(int irq, void *dev_id)
1221 i2eBordStrPtr pB = dev_id;
1223 ip2trace (ITRC_NO_PORT, ITRC_INTR, 99, 1, pB->i2eUsingIrq );
1229 ip2trace (ITRC_NO_PORT, ITRC_INTR, ITRC_RETURN, 0 );
1233 /******************************************************************************/
1234 /* Function: ip2_poll(unsigned long arg) */
1236 /* Returns: Nothing */
1239 /* This function calls the library routine i2ServiceBoard for each board in */
1240 /* the board table. This is used instead of the interrupt routine when polled */
1241 /* mode is specified. */
1242 /******************************************************************************/
1244 ip2_poll(unsigned long arg)
1246 ip2trace (ITRC_NO_PORT, ITRC_INTR, 100, 0 );
1248 TimerOn = 0; // it's the truth but not checked in service
1250 // Just polled boards, IRQ = 0 will hit all non-interrupt boards.
1251 // It will NOT poll boards handled by hard interrupts.
1252 // The issue of queued BH interrupts is handled in ip2_interrupt().
1253 ip2_polled_interrupt();
1255 PollTimer.expires = POLL_TIMEOUT;
1256 add_timer( &PollTimer );
1259 ip2trace (ITRC_NO_PORT, ITRC_INTR, ITRC_RETURN, 0 );
1262 static void do_input(struct work_struct *work)
1264 i2ChanStrPtr pCh = container_of(work, i2ChanStr, tqueue_input);
1265 unsigned long flags;
1267 ip2trace(CHANN, ITRC_INPUT, 21, 0 );
1270 if ( pCh->pTTY != NULL ) {
1271 READ_LOCK_IRQSAVE(&pCh->Ibuf_spinlock,flags)
1272 if (!pCh->throttled && (pCh->Ibuf_stuff != pCh->Ibuf_strip)) {
1273 READ_UNLOCK_IRQRESTORE(&pCh->Ibuf_spinlock,flags)
1276 READ_UNLOCK_IRQRESTORE(&pCh->Ibuf_spinlock,flags)
1278 ip2trace(CHANN, ITRC_INPUT, 22, 0 );
1280 i2InputFlush( pCh );
1284 // code duplicated from n_tty (ldisc)
1285 static inline void isig(int sig, struct tty_struct *tty, int flush)
1288 kill_pgrp(tty->pgrp, sig, 1);
1289 if (flush || !L_NOFLSH(tty)) {
1290 if ( tty->ldisc.flush_buffer )
1291 tty->ldisc.flush_buffer(tty);
1292 i2InputFlush( tty->driver_data );
1296 static void do_status(struct work_struct *work)
1298 i2ChanStrPtr pCh = container_of(work, i2ChanStr, tqueue_status);
1301 status = i2GetStatus( pCh, (I2_BRK|I2_PAR|I2_FRA|I2_OVR) );
1303 ip2trace (CHANN, ITRC_STATUS, 21, 1, status );
1305 if (pCh->pTTY && (status & (I2_BRK|I2_PAR|I2_FRA|I2_OVR)) ) {
1306 if ( (status & I2_BRK) ) {
1307 // code duplicated from n_tty (ldisc)
1308 if (I_IGNBRK(pCh->pTTY))
1310 if (I_BRKINT(pCh->pTTY)) {
1311 isig(SIGINT, pCh->pTTY, 1);
1314 wake_up_interruptible(&pCh->pTTY->read_wait);
1316 #ifdef NEVER_HAPPENS_AS_SETUP_XXX
1317 // and can't work because we don't know the_char
1318 // as the_char is reported on a separate path
1319 // The intelligent board does this stuff as setup
1321 char brkf = TTY_NORMAL;
1322 unsigned char brkc = '\0';
1324 if ( (status & I2_BRK) ) {
1328 else if (status & I2_PAR) {
1331 } else if (status & I2_FRA) {
1334 } else if (status & I2_OVR) {
1338 tmp = pCh->pTTY->real_raw;
1339 pCh->pTTY->real_raw = 0;
1340 pCh->pTTY->ldisc.receive_buf( pCh->pTTY, &brkc, &brkf, 1 );
1341 pCh->pTTY->real_raw = tmp;
1343 #endif /* NEVER_HAPPENS_AS_SETUP_XXX */
1347 if ( status & (I2_DDCD | I2_DDSR | I2_DCTS | I2_DRI) ) {
1348 wake_up_interruptible(&pCh->delta_msr_wait);
1350 if ( (pCh->flags & ASYNC_CHECK_CD) && (status & I2_DDCD) ) {
1351 if ( status & I2_DCD ) {
1353 wake_up_interruptible ( &pCh->open_wait );
1356 if (pCh->pTTY && (!(pCh->pTTY->termios->c_cflag & CLOCAL)) ) {
1357 tty_hangup( pCh->pTTY );
1363 ip2trace (CHANN, ITRC_STATUS, 26, 0 );
1366 /******************************************************************************/
1367 /* Device Open/Close/Ioctl Entry Point Section */
1368 /******************************************************************************/
1370 /******************************************************************************/
1371 /* Function: open_sanity_check() */
1372 /* Parameters: Pointer to tty structure */
1373 /* Pointer to file structure */
1374 /* Returns: Success or failure */
1377 /* Verifies the structure magic numbers and cross links. */
1378 /******************************************************************************/
1379 #ifdef IP2DEBUG_OPEN
1381 open_sanity_check( i2ChanStrPtr pCh, i2eBordStrPtr pBrd )
1383 if ( pBrd->i2eValid != I2E_MAGIC ) {
1384 printk(KERN_ERR "IP2: invalid board structure\n" );
1385 } else if ( pBrd != pCh->pMyBord ) {
1386 printk(KERN_ERR "IP2: board structure pointer mismatch (%p)\n",
1388 } else if ( pBrd->i2eChannelCnt < pCh->port_index ) {
1389 printk(KERN_ERR "IP2: bad device index (%d)\n", pCh->port_index );
1390 } else if (&((i2ChanStrPtr)pBrd->i2eChannelPtr)[pCh->port_index] != pCh) {
1392 printk(KERN_INFO "IP2: all pointers check out!\n" );
1398 /******************************************************************************/
1399 /* Function: ip2_open() */
1400 /* Parameters: Pointer to tty structure */
1401 /* Pointer to file structure */
1402 /* Returns: Success or failure */
1404 /* Description: (MANDATORY) */
1405 /* A successful device open has to run a gauntlet of checks before it */
1406 /* completes. After some sanity checking and pointer setup, the function */
1407 /* blocks until all conditions are satisfied. It then initialises the port to */
1408 /* the default characteristics and returns. */
1409 /******************************************************************************/
1411 ip2_open( PTTY tty, struct file *pFile )
1416 i2ChanStrPtr pCh = DevTable[tty->index];
1418 ip2trace (tty->index, ITRC_OPEN, ITRC_ENTER, 0 );
1420 if ( pCh == NULL ) {
1423 /* Setup pointer links in device and tty structures */
1425 tty->driver_data = pCh;
1427 #ifdef IP2DEBUG_OPEN
1429 "IP2:open(tty=%p,pFile=%p):dev=%s,ch=%d,idx=%d\n",
1430 tty, pFile, tty->name, pCh->infl.hd.i2sChannel, pCh->port_index);
1431 open_sanity_check ( pCh, pCh->pMyBord );
1434 i2QueueCommands(PTYPE_INLINE, pCh, 100, 3, CMD_DTRUP,CMD_RTSUP,CMD_DCD_REP);
1435 pCh->dataSetOut |= (I2_DTR | I2_RTS);
1436 serviceOutgoingFifo( pCh->pMyBord );
1438 /* Block here until the port is ready (per serial and istallion) */
1440 * 1. If the port is in the middle of closing wait for the completion
1441 * and then return the appropriate error.
1443 init_waitqueue_entry(&wait, current);
1444 add_wait_queue(&pCh->close_wait, &wait);
1445 set_current_state( TASK_INTERRUPTIBLE );
1447 if ( tty_hung_up_p(pFile) || ( pCh->flags & ASYNC_CLOSING )) {
1448 if ( pCh->flags & ASYNC_CLOSING ) {
1451 if ( tty_hung_up_p(pFile) ) {
1452 set_current_state( TASK_RUNNING );
1453 remove_wait_queue(&pCh->close_wait, &wait);
1454 return( pCh->flags & ASYNC_HUP_NOTIFY ) ? -EAGAIN : -ERESTARTSYS;
1457 set_current_state( TASK_RUNNING );
1458 remove_wait_queue(&pCh->close_wait, &wait);
1461 * 3. Handle a non-blocking open of a normal port.
1463 if ( (pFile->f_flags & O_NONBLOCK) || (tty->flags & (1<<TTY_IO_ERROR) )) {
1464 pCh->flags |= ASYNC_NORMAL_ACTIVE;
1468 * 4. Now loop waiting for the port to be free and carrier present
1471 if ( tty->termios->c_cflag & CLOCAL )
1474 #ifdef IP2DEBUG_OPEN
1475 printk(KERN_DEBUG "OpenBlock: do_clocal = %d\n", do_clocal);
1480 init_waitqueue_entry(&wait, current);
1481 add_wait_queue(&pCh->open_wait, &wait);
1484 i2QueueCommands(PTYPE_INLINE, pCh, 100, 2, CMD_DTRUP, CMD_RTSUP);
1485 pCh->dataSetOut |= (I2_DTR | I2_RTS);
1486 set_current_state( TASK_INTERRUPTIBLE );
1487 serviceOutgoingFifo( pCh->pMyBord );
1488 if ( tty_hung_up_p(pFile) ) {
1489 set_current_state( TASK_RUNNING );
1490 remove_wait_queue(&pCh->open_wait, &wait);
1491 return ( pCh->flags & ASYNC_HUP_NOTIFY ) ? -EBUSY : -ERESTARTSYS;
1493 if (!(pCh->flags & ASYNC_CLOSING) &&
1494 (do_clocal || (pCh->dataSetIn & I2_DCD) )) {
1499 #ifdef IP2DEBUG_OPEN
1500 printk(KERN_DEBUG "ASYNC_CLOSING = %s\n",
1501 (pCh->flags & ASYNC_CLOSING)?"True":"False");
1502 printk(KERN_DEBUG "OpenBlock: waiting for CD or signal\n");
1504 ip2trace (CHANN, ITRC_OPEN, 3, 2, 0,
1505 (pCh->flags & ASYNC_CLOSING) );
1506 /* check for signal */
1507 if (signal_pending(current)) {
1508 rc = (( pCh->flags & ASYNC_HUP_NOTIFY ) ? -EAGAIN : -ERESTARTSYS);
1513 set_current_state( TASK_RUNNING );
1514 remove_wait_queue(&pCh->open_wait, &wait);
1516 --pCh->wopen; //why count?
1518 ip2trace (CHANN, ITRC_OPEN, 4, 0 );
1523 pCh->flags |= ASYNC_NORMAL_ACTIVE;
1527 /* first open - Assign termios structure to port */
1528 if ( tty->count == 1 ) {
1529 i2QueueCommands(PTYPE_INLINE, pCh, 0, 2, CMD_CTSFL_DSAB, CMD_RTSFL_DSAB);
1530 /* Now we must send the termios settings to the loadware */
1531 set_params( pCh, NULL );
1535 * Now set any i2lib options. These may go away if the i2lib code ends
1536 * up rolled into the mainline.
1538 pCh->channelOptions |= CO_NBLOCK_WRITE;
1540 #ifdef IP2DEBUG_OPEN
1541 printk (KERN_DEBUG "IP2: open completed\n" );
1543 serviceOutgoingFifo( pCh->pMyBord );
1545 ip2trace (CHANN, ITRC_OPEN, ITRC_RETURN, 0 );
1550 /******************************************************************************/
1551 /* Function: ip2_close() */
1552 /* Parameters: Pointer to tty structure */
1553 /* Pointer to file structure */
1554 /* Returns: Nothing */
1559 /******************************************************************************/
1561 ip2_close( PTTY tty, struct file *pFile )
1563 i2ChanStrPtr pCh = tty->driver_data;
1569 ip2trace (CHANN, ITRC_CLOSE, ITRC_ENTER, 0 );
1571 #ifdef IP2DEBUG_OPEN
1572 printk(KERN_DEBUG "IP2:close %s:\n",tty->name);
1575 if ( tty_hung_up_p ( pFile ) ) {
1577 ip2trace (CHANN, ITRC_CLOSE, 2, 1, 2 );
1581 if ( tty->count > 1 ) { /* not the last close */
1583 ip2trace (CHANN, ITRC_CLOSE, 2, 1, 3 );
1587 pCh->flags |= ASYNC_CLOSING; // last close actually
1591 if (pCh->ClosingWaitTime != ASYNC_CLOSING_WAIT_NONE) {
1593 * Before we drop DTR, make sure the transmitter has completely drained.
1594 * This uses an timeout, after which the close
1597 ip2_wait_until_sent(tty, pCh->ClosingWaitTime );
1600 * At this point we stop accepting input. Here we flush the channel
1601 * input buffer which will allow the board to send up more data. Any
1602 * additional input is tossed at interrupt/poll time.
1604 i2InputFlush( pCh );
1606 /* disable DSS reporting */
1607 i2QueueCommands(PTYPE_INLINE, pCh, 100, 4,
1608 CMD_DCD_NREP, CMD_CTS_NREP, CMD_DSR_NREP, CMD_RI_NREP);
1609 if ( !tty || (tty->termios->c_cflag & HUPCL) ) {
1610 i2QueueCommands(PTYPE_INLINE, pCh, 100, 2, CMD_RTSDN, CMD_DTRDN);
1611 pCh->dataSetOut &= ~(I2_DTR | I2_RTS);
1612 i2QueueCommands( PTYPE_INLINE, pCh, 100, 1, CMD_PAUSE(25));
1615 serviceOutgoingFifo ( pCh->pMyBord );
1617 if ( tty->driver->flush_buffer )
1618 tty->driver->flush_buffer(tty);
1619 if ( tty->ldisc.flush_buffer )
1620 tty->ldisc.flush_buffer(tty);
1626 if (pCh->ClosingDelay) {
1627 msleep_interruptible(jiffies_to_msecs(pCh->ClosingDelay));
1629 wake_up_interruptible(&pCh->open_wait);
1632 pCh->flags &=~(ASYNC_NORMAL_ACTIVE|ASYNC_CLOSING);
1633 wake_up_interruptible(&pCh->close_wait);
1635 #ifdef IP2DEBUG_OPEN
1636 DBG_CNT("ip2_close: after wakeups--");
1640 ip2trace (CHANN, ITRC_CLOSE, ITRC_RETURN, 1, 1 );
1645 /******************************************************************************/
1646 /* Function: ip2_hangup() */
1647 /* Parameters: Pointer to tty structure */
1648 /* Returns: Nothing */
1653 /******************************************************************************/
1655 ip2_hangup ( PTTY tty )
1657 i2ChanStrPtr pCh = tty->driver_data;
1663 ip2trace (CHANN, ITRC_HANGUP, ITRC_ENTER, 0 );
1665 ip2_flush_buffer(tty);
1667 /* disable DSS reporting */
1669 i2QueueCommands(PTYPE_BYPASS, pCh, 0, 1, CMD_DCD_NREP);
1670 i2QueueCommands(PTYPE_INLINE, pCh, 0, 2, CMD_CTSFL_DSAB, CMD_RTSFL_DSAB);
1671 if ( (tty->termios->c_cflag & HUPCL) ) {
1672 i2QueueCommands(PTYPE_BYPASS, pCh, 0, 2, CMD_RTSDN, CMD_DTRDN);
1673 pCh->dataSetOut &= ~(I2_DTR | I2_RTS);
1674 i2QueueCommands( PTYPE_INLINE, pCh, 100, 1, CMD_PAUSE(25));
1676 i2QueueCommands(PTYPE_INLINE, pCh, 1, 3,
1677 CMD_CTS_NREP, CMD_DSR_NREP, CMD_RI_NREP);
1678 serviceOutgoingFifo ( pCh->pMyBord );
1680 wake_up_interruptible ( &pCh->delta_msr_wait );
1682 pCh->flags &= ~ASYNC_NORMAL_ACTIVE;
1684 wake_up_interruptible ( &pCh->open_wait );
1686 ip2trace (CHANN, ITRC_HANGUP, ITRC_RETURN, 0 );
1689 /******************************************************************************/
1690 /******************************************************************************/
1691 /* Device Output Section */
1692 /******************************************************************************/
1693 /******************************************************************************/
1695 /******************************************************************************/
1696 /* Function: ip2_write() */
1697 /* Parameters: Pointer to tty structure */
1698 /* Flag denoting data is in user (1) or kernel (0) space */
1699 /* Pointer to data */
1700 /* Number of bytes to write */
1701 /* Returns: Number of bytes actually written */
1703 /* Description: (MANDATORY) */
1706 /******************************************************************************/
1708 ip2_write( PTTY tty, const unsigned char *pData, int count)
1710 i2ChanStrPtr pCh = tty->driver_data;
1712 unsigned long flags;
1714 ip2trace (CHANN, ITRC_WRITE, ITRC_ENTER, 2, count, -1 );
1716 /* Flush out any buffered data left over from ip2_putchar() calls. */
1717 ip2_flush_chars( tty );
1719 /* This is the actual move bit. Make sure it does what we need!!!!! */
1720 WRITE_LOCK_IRQSAVE(&pCh->Pbuf_spinlock,flags);
1721 bytesSent = i2Output( pCh, pData, count);
1722 WRITE_UNLOCK_IRQRESTORE(&pCh->Pbuf_spinlock,flags);
1724 ip2trace (CHANN, ITRC_WRITE, ITRC_RETURN, 1, bytesSent );
1726 return bytesSent > 0 ? bytesSent : 0;
1729 /******************************************************************************/
1730 /* Function: ip2_putchar() */
1731 /* Parameters: Pointer to tty structure */
1732 /* Character to write */
1733 /* Returns: Nothing */
1738 /******************************************************************************/
1740 ip2_putchar( PTTY tty, unsigned char ch )
1742 i2ChanStrPtr pCh = tty->driver_data;
1743 unsigned long flags;
1745 // ip2trace (CHANN, ITRC_PUTC, ITRC_ENTER, 1, ch );
1747 WRITE_LOCK_IRQSAVE(&pCh->Pbuf_spinlock,flags);
1748 pCh->Pbuf[pCh->Pbuf_stuff++] = ch;
1749 if ( pCh->Pbuf_stuff == sizeof pCh->Pbuf ) {
1750 WRITE_UNLOCK_IRQRESTORE(&pCh->Pbuf_spinlock,flags);
1751 ip2_flush_chars( tty );
1753 WRITE_UNLOCK_IRQRESTORE(&pCh->Pbuf_spinlock,flags);
1755 // ip2trace (CHANN, ITRC_PUTC, ITRC_RETURN, 1, ch );
1758 /******************************************************************************/
1759 /* Function: ip2_flush_chars() */
1760 /* Parameters: Pointer to tty structure */
1761 /* Returns: Nothing */
1765 /******************************************************************************/
1767 ip2_flush_chars( PTTY tty )
1770 i2ChanStrPtr pCh = tty->driver_data;
1771 unsigned long flags;
1773 WRITE_LOCK_IRQSAVE(&pCh->Pbuf_spinlock,flags);
1774 if ( pCh->Pbuf_stuff ) {
1776 // ip2trace (CHANN, ITRC_PUTC, 10, 1, strip );
1779 // We may need to restart i2Output if it does not fullfill this request
1781 strip = i2Output( pCh, pCh->Pbuf, pCh->Pbuf_stuff);
1782 if ( strip != pCh->Pbuf_stuff ) {
1783 memmove( pCh->Pbuf, &pCh->Pbuf[strip], pCh->Pbuf_stuff - strip );
1785 pCh->Pbuf_stuff -= strip;
1787 WRITE_UNLOCK_IRQRESTORE(&pCh->Pbuf_spinlock,flags);
1790 /******************************************************************************/
1791 /* Function: ip2_write_room() */
1792 /* Parameters: Pointer to tty structure */
1793 /* Returns: Number of bytes that the driver can accept */
1797 /******************************************************************************/
1799 ip2_write_room ( PTTY tty )
1802 i2ChanStrPtr pCh = tty->driver_data;
1803 unsigned long flags;
1805 READ_LOCK_IRQSAVE(&pCh->Pbuf_spinlock,flags);
1806 bytesFree = i2OutputFree( pCh ) - pCh->Pbuf_stuff;
1807 READ_UNLOCK_IRQRESTORE(&pCh->Pbuf_spinlock,flags);
1809 ip2trace (CHANN, ITRC_WRITE, 11, 1, bytesFree );
1811 return ((bytesFree > 0) ? bytesFree : 0);
1814 /******************************************************************************/
1815 /* Function: ip2_chars_in_buf() */
1816 /* Parameters: Pointer to tty structure */
1817 /* Returns: Number of bytes queued for transmission */
1822 /******************************************************************************/
1824 ip2_chars_in_buf ( PTTY tty )
1826 i2ChanStrPtr pCh = tty->driver_data;
1828 unsigned long flags;
1830 ip2trace (CHANN, ITRC_WRITE, 12, 1, pCh->Obuf_char_count + pCh->Pbuf_stuff );
1832 #ifdef IP2DEBUG_WRITE
1833 printk (KERN_DEBUG "IP2: chars in buffer = %d (%d,%d)\n",
1834 pCh->Obuf_char_count + pCh->Pbuf_stuff,
1835 pCh->Obuf_char_count, pCh->Pbuf_stuff );
1837 READ_LOCK_IRQSAVE(&pCh->Obuf_spinlock,flags);
1838 rc = pCh->Obuf_char_count;
1839 READ_UNLOCK_IRQRESTORE(&pCh->Obuf_spinlock,flags);
1840 READ_LOCK_IRQSAVE(&pCh->Pbuf_spinlock,flags);
1841 rc += pCh->Pbuf_stuff;
1842 READ_UNLOCK_IRQRESTORE(&pCh->Pbuf_spinlock,flags);
1846 /******************************************************************************/
1847 /* Function: ip2_flush_buffer() */
1848 /* Parameters: Pointer to tty structure */
1849 /* Returns: Nothing */
1854 /******************************************************************************/
1856 ip2_flush_buffer( PTTY tty )
1858 i2ChanStrPtr pCh = tty->driver_data;
1859 unsigned long flags;
1861 ip2trace (CHANN, ITRC_FLUSH, ITRC_ENTER, 0 );
1863 #ifdef IP2DEBUG_WRITE
1864 printk (KERN_DEBUG "IP2: flush buffer\n" );
1866 WRITE_LOCK_IRQSAVE(&pCh->Pbuf_spinlock,flags);
1867 pCh->Pbuf_stuff = 0;
1868 WRITE_UNLOCK_IRQRESTORE(&pCh->Pbuf_spinlock,flags);
1869 i2FlushOutput( pCh );
1872 ip2trace (CHANN, ITRC_FLUSH, ITRC_RETURN, 0 );
1876 /******************************************************************************/
1877 /* Function: ip2_wait_until_sent() */
1878 /* Parameters: Pointer to tty structure */
1879 /* Timeout for wait. */
1880 /* Returns: Nothing */
1883 /* This function is used in place of the normal tty_wait_until_sent, which */
1884 /* only waits for the driver buffers to be empty (or rather, those buffers */
1885 /* reported by chars_in_buffer) which doesn't work for IP2 due to the */
1886 /* indeterminate number of bytes buffered on the board. */
1887 /******************************************************************************/
1889 ip2_wait_until_sent ( PTTY tty, int timeout )
1892 i2ChanStrPtr pCh = tty->driver_data;
1894 tty_wait_until_sent(tty, timeout );
1895 if ( (i = timeout - (jiffies -i)) > 0)
1896 i2DrainOutput( pCh, i );
1899 /******************************************************************************/
1900 /******************************************************************************/
1901 /* Device Input Section */
1902 /******************************************************************************/
1903 /******************************************************************************/
1905 /******************************************************************************/
1906 /* Function: ip2_throttle() */
1907 /* Parameters: Pointer to tty structure */
1908 /* Returns: Nothing */
1913 /******************************************************************************/
1915 ip2_throttle ( PTTY tty )
1917 i2ChanStrPtr pCh = tty->driver_data;
1919 #ifdef IP2DEBUG_READ
1920 printk (KERN_DEBUG "IP2: throttle\n" );
1923 * Signal the poll/interrupt handlers not to forward incoming data to
1924 * the line discipline. This will cause the buffers to fill up in the
1925 * library and thus cause the library routines to send the flow control
1931 /******************************************************************************/
1932 /* Function: ip2_unthrottle() */
1933 /* Parameters: Pointer to tty structure */
1934 /* Returns: Nothing */
1939 /******************************************************************************/
1941 ip2_unthrottle ( PTTY tty )
1943 i2ChanStrPtr pCh = tty->driver_data;
1944 unsigned long flags;
1946 #ifdef IP2DEBUG_READ
1947 printk (KERN_DEBUG "IP2: unthrottle\n" );
1950 /* Pass incoming data up to the line discipline again. */
1952 i2QueueCommands(PTYPE_BYPASS, pCh, 0, 1, CMD_RESUME);
1953 serviceOutgoingFifo( pCh->pMyBord );
1954 READ_LOCK_IRQSAVE(&pCh->Ibuf_spinlock,flags)
1955 if ( pCh->Ibuf_stuff != pCh->Ibuf_strip ) {
1956 READ_UNLOCK_IRQRESTORE(&pCh->Ibuf_spinlock,flags)
1957 #ifdef IP2DEBUG_READ
1958 printk (KERN_DEBUG "i2Input called from unthrottle\n" );
1962 READ_UNLOCK_IRQRESTORE(&pCh->Ibuf_spinlock,flags)
1966 ip2_start ( PTTY tty )
1968 i2ChanStrPtr pCh = DevTable[tty->index];
1970 i2QueueCommands(PTYPE_BYPASS, pCh, 0, 1, CMD_RESUME);
1971 i2QueueCommands(PTYPE_BYPASS, pCh, 100, 1, CMD_UNSUSPEND);
1972 i2QueueCommands(PTYPE_BYPASS, pCh, 100, 1, CMD_RESUME);
1973 #ifdef IP2DEBUG_WRITE
1974 printk (KERN_DEBUG "IP2: start tx\n" );
1979 ip2_stop ( PTTY tty )
1981 i2ChanStrPtr pCh = DevTable[tty->index];
1983 i2QueueCommands(PTYPE_BYPASS, pCh, 100, 1, CMD_SUSPEND);
1984 #ifdef IP2DEBUG_WRITE
1985 printk (KERN_DEBUG "IP2: stop tx\n" );
1989 /******************************************************************************/
1990 /* Device Ioctl Section */
1991 /******************************************************************************/
1993 static int ip2_tiocmget(struct tty_struct *tty, struct file *file)
1995 i2ChanStrPtr pCh = DevTable[tty->index];
1996 #ifdef ENABLE_DSSNOW
2004 FIXME - the following code is causing a NULL pointer dereference in
2005 2.3.51 in an interrupt handler. It's suppose to prompt the board
2006 to return the DSS signal status immediately. Why doesn't it do
2007 the same thing in 2.2.14?
2010 /* This thing is still busted in the 1.2.12 driver on 2.4.x
2011 and even hoses the serial console so the oops can be trapped.
2014 #ifdef ENABLE_DSSNOW
2015 i2QueueCommands(PTYPE_BYPASS, pCh, 100, 1, CMD_DSS_NOW);
2017 init_waitqueue_entry(&wait, current);
2018 add_wait_queue(&pCh->dss_now_wait, &wait);
2019 set_current_state( TASK_INTERRUPTIBLE );
2021 serviceOutgoingFifo( pCh->pMyBord );
2025 set_current_state( TASK_RUNNING );
2026 remove_wait_queue(&pCh->dss_now_wait, &wait);
2028 if (signal_pending(current)) {
2032 return ((pCh->dataSetOut & I2_RTS) ? TIOCM_RTS : 0)
2033 | ((pCh->dataSetOut & I2_DTR) ? TIOCM_DTR : 0)
2034 | ((pCh->dataSetIn & I2_DCD) ? TIOCM_CAR : 0)
2035 | ((pCh->dataSetIn & I2_RI) ? TIOCM_RNG : 0)
2036 | ((pCh->dataSetIn & I2_DSR) ? TIOCM_DSR : 0)
2037 | ((pCh->dataSetIn & I2_CTS) ? TIOCM_CTS : 0);
2040 static int ip2_tiocmset(struct tty_struct *tty, struct file *file,
2041 unsigned int set, unsigned int clear)
2043 i2ChanStrPtr pCh = DevTable[tty->index];
2048 if (set & TIOCM_RTS) {
2049 i2QueueCommands(PTYPE_INLINE, pCh, 100, 1, CMD_RTSUP);
2050 pCh->dataSetOut |= I2_RTS;
2052 if (set & TIOCM_DTR) {
2053 i2QueueCommands(PTYPE_INLINE, pCh, 100, 1, CMD_DTRUP);
2054 pCh->dataSetOut |= I2_DTR;
2057 if (clear & TIOCM_RTS) {
2058 i2QueueCommands(PTYPE_INLINE, pCh, 100, 1, CMD_RTSDN);
2059 pCh->dataSetOut &= ~I2_RTS;
2061 if (clear & TIOCM_DTR) {
2062 i2QueueCommands(PTYPE_INLINE, pCh, 100, 1, CMD_DTRDN);
2063 pCh->dataSetOut &= ~I2_DTR;
2065 serviceOutgoingFifo( pCh->pMyBord );
2069 /******************************************************************************/
2070 /* Function: ip2_ioctl() */
2071 /* Parameters: Pointer to tty structure */
2072 /* Pointer to file structure */
2075 /* Returns: Success or failure */
2080 /******************************************************************************/
2082 ip2_ioctl ( PTTY tty, struct file *pFile, UINT cmd, ULONG arg )
2085 i2ChanStrPtr pCh = DevTable[tty->index];
2087 struct async_icount cprev, cnow; /* kernel counter temps */
2088 struct serial_icounter_struct __user *p_cuser;
2090 unsigned long flags;
2091 void __user *argp = (void __user *)arg;
2098 ip2trace (CHANN, ITRC_IOCTL, ITRC_ENTER, 2, cmd, arg );
2100 #ifdef IP2DEBUG_IOCTL
2101 printk(KERN_DEBUG "IP2: ioctl cmd (%x), arg (%lx)\n", cmd, arg );
2107 ip2trace (CHANN, ITRC_IOCTL, 2, 1, rc );
2109 rc = get_serial_info(pCh, argp);
2116 ip2trace (CHANN, ITRC_IOCTL, 3, 1, rc );
2118 rc = set_serial_info(pCh, argp);
2124 rc = tty_check_change(tty);
2129 //return -ENOIOCTLCMD;
2132 //return -ENOIOCTLCMD;
2135 if (STOP_CHAR(tty) != __DISABLED_CHAR) {
2136 i2QueueCommands( PTYPE_BYPASS, pCh, 100, 1,
2137 CMD_XMIT_NOW(STOP_CHAR(tty)));
2141 if (START_CHAR(tty) != __DISABLED_CHAR) {
2142 i2QueueCommands( PTYPE_BYPASS, pCh, 100, 1,
2143 CMD_XMIT_NOW(START_CHAR(tty)));
2151 case TCSBRK: /* SVID version: non-zero arg --> no break */
2152 rc = tty_check_change(tty);
2154 ip2trace (CHANN, ITRC_IOCTL, 4, 1, rc );
2157 ip2_wait_until_sent(tty,0);
2159 i2QueueCommands(PTYPE_INLINE, pCh, 100, 1, CMD_SEND_BRK(250));
2160 serviceOutgoingFifo( pCh->pMyBord );
2165 case TCSBRKP: /* support for POSIX tcsendbreak() */
2166 rc = tty_check_change(tty);
2168 ip2trace (CHANN, ITRC_IOCTL, 5, 1, rc );
2171 ip2_wait_until_sent(tty,0);
2172 i2QueueCommands(PTYPE_INLINE, pCh, 100, 1,
2173 CMD_SEND_BRK(arg ? arg*100 : 250));
2174 serviceOutgoingFifo ( pCh->pMyBord );
2180 ip2trace (CHANN, ITRC_IOCTL, 6, 1, rc );
2182 rc = put_user(C_CLOCAL(tty) ? 1 : 0, (unsigned long __user *)argp);
2189 ip2trace (CHANN, ITRC_IOCTL, 7, 1, rc );
2191 rc = get_user(arg,(unsigned long __user *) argp);
2194 tty->termios->c_cflag = ((tty->termios->c_cflag & ~CLOCAL)
2195 | (arg ? CLOCAL : 0));
2200 * Wait for any of the 4 modem inputs (DCD,RI,DSR,CTS) to change - mask
2201 * passed in arg for lines of interest (use |'ed TIOCM_RNG/DSR/CD/CTS
2202 * for masking). Caller should use TIOCGICOUNT to see which one it was
2205 WRITE_LOCK_IRQSAVE(&pB->read_fifo_spinlock, flags);
2206 cprev = pCh->icount; /* note the counters on entry */
2207 WRITE_UNLOCK_IRQRESTORE(&pB->read_fifo_spinlock, flags);
2208 i2QueueCommands(PTYPE_BYPASS, pCh, 100, 4,
2209 CMD_DCD_REP, CMD_CTS_REP, CMD_DSR_REP, CMD_RI_REP);
2210 init_waitqueue_entry(&wait, current);
2211 add_wait_queue(&pCh->delta_msr_wait, &wait);
2212 set_current_state( TASK_INTERRUPTIBLE );
2214 serviceOutgoingFifo( pCh->pMyBord );
2216 ip2trace (CHANN, ITRC_IOCTL, 10, 0 );
2220 ip2trace (CHANN, ITRC_IOCTL, 11, 0 );
2222 /* see if a signal did it */
2223 if (signal_pending(current)) {
2227 WRITE_LOCK_IRQSAVE(&pB->read_fifo_spinlock, flags);
2228 cnow = pCh->icount; /* atomic copy */
2229 WRITE_UNLOCK_IRQRESTORE(&pB->read_fifo_spinlock, flags);
2230 if (cnow.rng == cprev.rng && cnow.dsr == cprev.dsr &&
2231 cnow.dcd == cprev.dcd && cnow.cts == cprev.cts) {
2232 rc = -EIO; /* no change => rc */
2235 if (((arg & TIOCM_RNG) && (cnow.rng != cprev.rng)) ||
2236 ((arg & TIOCM_DSR) && (cnow.dsr != cprev.dsr)) ||
2237 ((arg & TIOCM_CD) && (cnow.dcd != cprev.dcd)) ||
2238 ((arg & TIOCM_CTS) && (cnow.cts != cprev.cts)) ) {
2244 set_current_state( TASK_RUNNING );
2245 remove_wait_queue(&pCh->delta_msr_wait, &wait);
2247 i2QueueCommands(PTYPE_BYPASS, pCh, 100, 3,
2248 CMD_CTS_NREP, CMD_DSR_NREP, CMD_RI_NREP);
2249 if ( ! (pCh->flags & ASYNC_CHECK_CD)) {
2250 i2QueueCommands(PTYPE_BYPASS, pCh, 100, 1, CMD_DCD_NREP);
2252 serviceOutgoingFifo( pCh->pMyBord );
2257 * Get counter of input serial line interrupts (DCD,RI,DSR,CTS)
2258 * Return: write counters to the user passed counter struct
2259 * NB: both 1->0 and 0->1 transitions are counted except for RI where
2260 * only 0->1 is counted. The controller is quite capable of counting
2261 * both, but this done to preserve compatibility with the standard
2265 ip2trace (CHANN, ITRC_IOCTL, 11, 1, rc );
2267 WRITE_LOCK_IRQSAVE(&pB->read_fifo_spinlock, flags);
2269 WRITE_UNLOCK_IRQRESTORE(&pB->read_fifo_spinlock, flags);
2271 rc = put_user(cnow.cts, &p_cuser->cts);
2272 rc = put_user(cnow.dsr, &p_cuser->dsr);
2273 rc = put_user(cnow.rng, &p_cuser->rng);
2274 rc = put_user(cnow.dcd, &p_cuser->dcd);
2275 rc = put_user(cnow.rx, &p_cuser->rx);
2276 rc = put_user(cnow.tx, &p_cuser->tx);
2277 rc = put_user(cnow.frame, &p_cuser->frame);
2278 rc = put_user(cnow.overrun, &p_cuser->overrun);
2279 rc = put_user(cnow.parity, &p_cuser->parity);
2280 rc = put_user(cnow.brk, &p_cuser->brk);
2281 rc = put_user(cnow.buf_overrun, &p_cuser->buf_overrun);
2285 * The rest are not supported by this driver. By returning -ENOIOCTLCMD they
2286 * will be passed to the line discipline for it to handle.
2292 case TIOCSERGSTRUCT:
2293 case TIOCSERGETMULTI:
2294 case TIOCSERSETMULTI:
2297 ip2trace (CHANN, ITRC_IOCTL, 12, 0 );
2303 ip2trace (CHANN, ITRC_IOCTL, ITRC_RETURN, 0 );
2308 /******************************************************************************/
2309 /* Function: GetSerialInfo() */
2310 /* Parameters: Pointer to channel structure */
2311 /* Pointer to old termios structure */
2312 /* Returns: Nothing */
2315 /* This is to support the setserial command, and requires processing of the */
2316 /* standard Linux serial structure. */
2317 /******************************************************************************/
2319 get_serial_info ( i2ChanStrPtr pCh, struct serial_struct __user *retinfo )
2321 struct serial_struct tmp;
2323 memset ( &tmp, 0, sizeof(tmp) );
2324 tmp.type = pCh->pMyBord->channelBtypes.bid_value[(pCh->port_index & (IP2_PORTS_PER_BOARD-1))/16];
2325 if (BID_HAS_654(tmp.type)) {
2326 tmp.type = PORT_16650;
2328 tmp.type = PORT_CIRRUS;
2330 tmp.line = pCh->port_index;
2331 tmp.port = pCh->pMyBord->i2eBase;
2332 tmp.irq = ip2config.irq[pCh->port_index/64];
2333 tmp.flags = pCh->flags;
2334 tmp.baud_base = pCh->BaudBase;
2335 tmp.close_delay = pCh->ClosingDelay;
2336 tmp.closing_wait = pCh->ClosingWaitTime;
2337 tmp.custom_divisor = pCh->BaudDivisor;
2338 return copy_to_user(retinfo,&tmp,sizeof(*retinfo));
2341 /******************************************************************************/
2342 /* Function: SetSerialInfo() */
2343 /* Parameters: Pointer to channel structure */
2344 /* Pointer to old termios structure */
2345 /* Returns: Nothing */
2348 /* This function provides support for setserial, which uses the TIOCSSERIAL */
2349 /* ioctl. Not all setserial parameters are relevant. If the user attempts to */
2350 /* change the IRQ, address or type of the port the ioctl fails. */
2351 /******************************************************************************/
2353 set_serial_info( i2ChanStrPtr pCh, struct serial_struct __user *new_info )
2355 struct serial_struct ns;
2356 int old_flags, old_baud_divisor;
2358 if (copy_from_user(&ns, new_info, sizeof (ns)))
2362 * We don't allow setserial to change IRQ, board address, type or baud
2363 * base. Also line nunber as such is meaningless but we use it for our
2364 * array index so it is fixed also.
2366 if ( (ns.irq != ip2config.irq[pCh->port_index])
2367 || ((int) ns.port != ((int) (pCh->pMyBord->i2eBase)))
2368 || (ns.baud_base != pCh->BaudBase)
2369 || (ns.line != pCh->port_index) ) {
2373 old_flags = pCh->flags;
2374 old_baud_divisor = pCh->BaudDivisor;
2376 if ( !capable(CAP_SYS_ADMIN) ) {
2377 if ( ( ns.close_delay != pCh->ClosingDelay ) ||
2378 ( (ns.flags & ~ASYNC_USR_MASK) !=
2379 (pCh->flags & ~ASYNC_USR_MASK) ) ) {
2383 pCh->flags = (pCh->flags & ~ASYNC_USR_MASK) |
2384 (ns.flags & ASYNC_USR_MASK);
2385 pCh->BaudDivisor = ns.custom_divisor;
2387 pCh->flags = (pCh->flags & ~ASYNC_FLAGS) |
2388 (ns.flags & ASYNC_FLAGS);
2389 pCh->BaudDivisor = ns.custom_divisor;
2390 pCh->ClosingDelay = ns.close_delay * HZ/100;
2391 pCh->ClosingWaitTime = ns.closing_wait * HZ/100;
2394 if ( ( (old_flags & ASYNC_SPD_MASK) != (pCh->flags & ASYNC_SPD_MASK) )
2395 || (old_baud_divisor != pCh->BaudDivisor) ) {
2396 // Invalidate speed and reset parameters
2397 set_params( pCh, NULL );
2403 /******************************************************************************/
2404 /* Function: ip2_set_termios() */
2405 /* Parameters: Pointer to tty structure */
2406 /* Pointer to old termios structure */
2407 /* Returns: Nothing */
2412 /******************************************************************************/
2414 ip2_set_termios( PTTY tty, struct ktermios *old_termios )
2416 i2ChanStrPtr pCh = (i2ChanStrPtr)tty->driver_data;
2418 #ifdef IP2DEBUG_IOCTL
2419 printk (KERN_DEBUG "IP2: set termios %p\n", old_termios );
2422 set_params( pCh, old_termios );
2425 /******************************************************************************/
2426 /* Function: ip2_set_line_discipline() */
2427 /* Parameters: Pointer to tty structure */
2428 /* Returns: Nothing */
2430 /* Description: Does nothing */
2433 /******************************************************************************/
2435 ip2_set_line_discipline ( PTTY tty )
2437 #ifdef IP2DEBUG_IOCTL
2438 printk (KERN_DEBUG "IP2: set line discipline\n" );
2441 ip2trace (((i2ChanStrPtr)tty->driver_data)->port_index, ITRC_IOCTL, 16, 0 );
2445 /******************************************************************************/
2446 /* Function: SetLine Characteristics() */
2447 /* Parameters: Pointer to channel structure */
2448 /* Returns: Nothing */
2451 /* This routine is called to update the channel structure with the new line */
2452 /* characteristics, and send the appropriate commands to the board when they */
2454 /******************************************************************************/
2456 set_params( i2ChanStrPtr pCh, struct ktermios *o_tios )
2458 tcflag_t cflag, iflag, lflag;
2459 char stop_char, start_char;
2460 struct ktermios dummy;
2462 lflag = pCh->pTTY->termios->c_lflag;
2463 cflag = pCh->pTTY->termios->c_cflag;
2464 iflag = pCh->pTTY->termios->c_iflag;
2466 if (o_tios == NULL) {
2467 dummy.c_lflag = ~lflag;
2468 dummy.c_cflag = ~cflag;
2469 dummy.c_iflag = ~iflag;
2474 switch ( cflag & CBAUD ) {
2476 i2QueueCommands( PTYPE_BYPASS, pCh, 100, 2, CMD_RTSDN, CMD_DTRDN);
2477 pCh->dataSetOut &= ~(I2_DTR | I2_RTS);
2478 i2QueueCommands( PTYPE_INLINE, pCh, 100, 1, CMD_PAUSE(25));
2479 pCh->pTTY->termios->c_cflag |= (CBAUD & o_tios->c_cflag);
2484 * This is the speed that is overloaded with all the other high
2485 * speeds, depending upon the flag settings.
2487 if ( ( pCh->flags & ASYNC_SPD_MASK ) == ASYNC_SPD_HI ) {
2488 pCh->speed = CBR_57600;
2489 } else if ( (pCh->flags & ASYNC_SPD_MASK) == ASYNC_SPD_VHI ) {
2490 pCh->speed = CBR_115200;
2491 } else if ( (pCh->flags & ASYNC_SPD_MASK) == ASYNC_SPD_CUST ) {
2492 pCh->speed = CBR_C1;
2494 pCh->speed = CBR_38400;
2497 case B50: pCh->speed = CBR_50; break;
2498 case B75: pCh->speed = CBR_75; break;
2499 case B110: pCh->speed = CBR_110; break;
2500 case B134: pCh->speed = CBR_134; break;
2501 case B150: pCh->speed = CBR_150; break;
2502 case B200: pCh->speed = CBR_200; break;
2503 case B300: pCh->speed = CBR_300; break;
2504 case B600: pCh->speed = CBR_600; break;
2505 case B1200: pCh->speed = CBR_1200; break;
2506 case B1800: pCh->speed = CBR_1800; break;
2507 case B2400: pCh->speed = CBR_2400; break;
2508 case B4800: pCh->speed = CBR_4800; break;
2509 case B9600: pCh->speed = CBR_9600; break;
2510 case B19200: pCh->speed = CBR_19200; break;
2511 case B57600: pCh->speed = CBR_57600; break;
2512 case B115200: pCh->speed = CBR_115200; break;
2513 case B153600: pCh->speed = CBR_153600; break;
2514 case B230400: pCh->speed = CBR_230400; break;
2515 case B307200: pCh->speed = CBR_307200; break;
2516 case B460800: pCh->speed = CBR_460800; break;
2517 case B921600: pCh->speed = CBR_921600; break;
2518 default: pCh->speed = CBR_9600; break;
2520 if ( pCh->speed == CBR_C1 ) {
2521 // Process the custom speed parameters.
2522 int bps = pCh->BaudBase / pCh->BaudDivisor;
2523 if ( bps == 921600 ) {
2524 pCh->speed = CBR_921600;
2527 i2QueueCommands( PTYPE_INLINE, pCh, 100, 1, CMD_BAUD_DEF1(bps) );
2530 i2QueueCommands( PTYPE_INLINE, pCh, 100, 1, CMD_SETBAUD(pCh->speed));
2532 i2QueueCommands ( PTYPE_INLINE, pCh, 100, 2, CMD_DTRUP, CMD_RTSUP);
2533 pCh->dataSetOut |= (I2_DTR | I2_RTS);
2535 if ( (CSTOPB & cflag) ^ (CSTOPB & o_tios->c_cflag))
2537 i2QueueCommands ( PTYPE_INLINE, pCh, 100, 1,
2538 CMD_SETSTOP( ( cflag & CSTOPB ) ? CST_2 : CST_1));
2540 if (((PARENB|PARODD) & cflag) ^ ((PARENB|PARODD) & o_tios->c_cflag))
2542 i2QueueCommands ( PTYPE_INLINE, pCh, 100, 1,
2544 (cflag & PARENB ? (cflag & PARODD ? CSP_OD : CSP_EV) : CSP_NP)
2548 /* byte size and parity */
2549 if ( (CSIZE & cflag)^(CSIZE & o_tios->c_cflag))
2552 switch ( cflag & CSIZE ) {
2553 case CS5: datasize = CSZ_5; break;
2554 case CS6: datasize = CSZ_6; break;
2555 case CS7: datasize = CSZ_7; break;
2556 case CS8: datasize = CSZ_8; break;
2557 default: datasize = CSZ_5; break; /* as per serial.c */
2559 i2QueueCommands ( PTYPE_INLINE, pCh, 100, 1, CMD_SETBITS(datasize) );
2561 /* Process CTS flow control flag setting */
2562 if ( (cflag & CRTSCTS) ) {
2563 i2QueueCommands(PTYPE_INLINE, pCh, 100,
2564 2, CMD_CTSFL_ENAB, CMD_RTSFL_ENAB);
2566 i2QueueCommands(PTYPE_INLINE, pCh, 100,
2567 2, CMD_CTSFL_DSAB, CMD_RTSFL_DSAB);
2570 // Process XON/XOFF flow control flags settings
2572 stop_char = STOP_CHAR(pCh->pTTY);
2573 start_char = START_CHAR(pCh->pTTY);
2575 //////////// can't be \000
2576 if (stop_char == __DISABLED_CHAR )
2578 stop_char = ~__DISABLED_CHAR;
2580 if (start_char == __DISABLED_CHAR )
2582 start_char = ~__DISABLED_CHAR;
2584 /////////////////////////////////
2586 if ( o_tios->c_cc[VSTART] != start_char )
2588 i2QueueCommands(PTYPE_BYPASS, pCh, 100, 1, CMD_DEF_IXON(start_char));
2589 i2QueueCommands(PTYPE_INLINE, pCh, 100, 1, CMD_DEF_OXON(start_char));
2591 if ( o_tios->c_cc[VSTOP] != stop_char )
2593 i2QueueCommands(PTYPE_BYPASS, pCh, 100, 1, CMD_DEF_IXOFF(stop_char));
2594 i2QueueCommands(PTYPE_INLINE, pCh, 100, 1, CMD_DEF_OXOFF(stop_char));
2596 if (stop_char == __DISABLED_CHAR )
2598 stop_char = ~__DISABLED_CHAR; //TEST123
2601 if ((iflag & (IXOFF))^(o_tios->c_iflag & (IXOFF)))
2603 if ( iflag & IXOFF ) { // Enable XOFF output flow control
2604 i2QueueCommands(PTYPE_INLINE, pCh, 100, 1, CMD_OXON_OPT(COX_XON));
2605 } else { // Disable XOFF output flow control
2607 i2QueueCommands(PTYPE_INLINE, pCh, 100, 1, CMD_OXON_OPT(COX_NONE));
2610 if (start_char == __DISABLED_CHAR )
2614 if ((iflag & (IXON|IXANY)) ^ (o_tios->c_iflag & (IXON|IXANY)))
2616 if ( iflag & IXON ) {
2617 if ( iflag & IXANY ) { // Enable XON/XANY output flow control
2618 i2QueueCommands(PTYPE_INLINE, pCh, 100, 1, CMD_IXON_OPT(CIX_XANY));
2619 } else { // Enable XON output flow control
2620 i2QueueCommands(PTYPE_INLINE, pCh, 100, 1, CMD_IXON_OPT(CIX_XON));
2622 } else { // Disable XON output flow control
2624 i2QueueCommands(PTYPE_INLINE, pCh, 100, 1, CMD_IXON_OPT(CIX_NONE));
2627 if ( (iflag & ISTRIP) ^ ( o_tios->c_iflag & (ISTRIP)) )
2629 i2QueueCommands(PTYPE_INLINE, pCh, 100, 1,
2630 CMD_ISTRIP_OPT((iflag & ISTRIP ? 1 : 0)));
2632 if ( (iflag & INPCK) ^ ( o_tios->c_iflag & (INPCK)) )
2634 i2QueueCommands(PTYPE_INLINE, pCh, 100, 1,
2635 CMD_PARCHK((iflag & INPCK) ? CPK_ENAB : CPK_DSAB));
2638 if ( (iflag & (IGNBRK|PARMRK|BRKINT|IGNPAR))
2639 ^ ( o_tios->c_iflag & (IGNBRK|PARMRK|BRKINT|IGNPAR)) )
2644 if ( iflag & IGNBRK ) { /* Ignore breaks altogether */
2645 /* Ignore breaks altogether */
2646 i2QueueCommands(PTYPE_INLINE, pCh, 100, 1, CMD_BRK_NREP);
2648 if ( iflag & BRKINT ) {
2649 if ( iflag & PARMRK ) {
2650 brkrpt = 0x0a; // exception an inline triple
2652 brkrpt = 0x1a; // exception and NULL
2654 brkrpt |= 0x04; // flush input
2656 if ( iflag & PARMRK ) {
2657 brkrpt = 0x0b; //POSIX triple \0377 \0 \0
2659 brkrpt = 0x01; // Null only
2662 i2QueueCommands(PTYPE_INLINE, pCh, 100, 1, CMD_BRK_REP(brkrpt));
2665 if (iflag & IGNPAR) {
2667 /* would be 2 for not cirrus bug */
2668 /* would be 0x20 cept for cirrus bug */
2670 if ( iflag & PARMRK ) {
2672 * Replace error characters with 3-byte sequence (\0377,\0,char)
2675 i2QueueCommands(PTYPE_INLINE, pCh, 100, 1, CMD_ISTRIP_OPT((char)0));
2680 i2QueueCommands(PTYPE_INLINE, pCh, 100, 1, CMD_SET_ERROR(parrpt));
2682 if (cflag & CLOCAL) {
2683 // Status reporting fails for DCD if this is off
2684 i2QueueCommands(PTYPE_INLINE, pCh, 100, 1, CMD_DCD_NREP);
2685 pCh->flags &= ~ASYNC_CHECK_CD;
2687 i2QueueCommands(PTYPE_INLINE, pCh, 100, 1, CMD_DCD_REP);
2688 pCh->flags |= ASYNC_CHECK_CD;
2692 i2DrainOutput( pCh, 100 );
2695 /******************************************************************************/
2696 /* IPL Device Section */
2697 /******************************************************************************/
2699 /******************************************************************************/
2700 /* Function: ip2_ipl_read() */
2701 /* Parameters: Pointer to device inode */
2702 /* Pointer to file structure */
2703 /* Pointer to data */
2704 /* Number of bytes to read */
2705 /* Returns: Success or failure */
2707 /* Description: Ugly */
2710 /******************************************************************************/
2714 ip2_ipl_read(struct file *pFile, char __user *pData, size_t count, loff_t *off )
2716 unsigned int minor = iminor(pFile->f_path.dentry->d_inode);
2720 printk (KERN_DEBUG "IP2IPL: read %p, %d bytes\n", pData, count );
2724 case 0: // IPL device
2727 case 1: // Status dump
2730 case 2: // Ping device
2733 case 3: // Trace device
2734 rc = DumpTraceBuffer ( pData, count );
2736 case 4: // Trace device
2737 rc = DumpFifoBuffer ( pData, count );
2747 DumpFifoBuffer ( char __user *pData, int count )
2751 rc = copy_to_user(pData, DBGBuf, count);
2753 printk(KERN_DEBUG "Last index %d\n", I );
2756 #endif /* DEBUG_FIFO */
2761 DumpTraceBuffer ( char __user *pData, int count )
2763 #ifdef IP2DEBUG_TRACE
2767 int *pIndex = (int __user *)pData;
2769 if ( count < (sizeof(int) * 6) ) {
2772 rc = put_user(tracewrap, pIndex );
2773 rc = put_user(TRACEMAX, ++pIndex );
2774 rc = put_user(tracestrip, ++pIndex );
2775 rc = put_user(tracestuff, ++pIndex );
2776 pData += sizeof(int) * 6;
2777 count -= sizeof(int) * 6;
2779 dumpcount = tracestuff - tracestrip;
2780 if ( dumpcount < 0 ) {
2781 dumpcount += TRACEMAX;
2783 if ( dumpcount > count ) {
2786 chunk = TRACEMAX - tracestrip;
2787 if ( dumpcount > chunk ) {
2788 rc = copy_to_user(pData, &tracebuf[tracestrip],
2789 chunk * sizeof(tracebuf[0]) );
2790 pData += chunk * sizeof(tracebuf[0]);
2792 chunk = dumpcount - chunk;
2796 rc = copy_to_user(pData, &tracebuf[tracestrip],
2797 chunk * sizeof(tracebuf[0]) );
2798 tracestrip += chunk;
2801 rc = put_user(tracestrip, ++pIndex );
2802 rc = put_user(tracestuff, ++pIndex );
2810 /******************************************************************************/
2811 /* Function: ip2_ipl_write() */
2813 /* Pointer to file structure */
2814 /* Pointer to data */
2815 /* Number of bytes to write */
2816 /* Returns: Success or failure */
2821 /******************************************************************************/
2823 ip2_ipl_write(struct file *pFile, const char __user *pData, size_t count, loff_t *off)
2826 printk (KERN_DEBUG "IP2IPL: write %p, %d bytes\n", pData, count );
2831 /******************************************************************************/
2832 /* Function: ip2_ipl_ioctl() */
2833 /* Parameters: Pointer to device inode */
2834 /* Pointer to file structure */
2837 /* Returns: Success or failure */
2842 /******************************************************************************/
2844 ip2_ipl_ioctl ( struct inode *pInode, struct file *pFile, UINT cmd, ULONG arg )
2846 unsigned int iplminor = iminor(pInode);
2848 void __user *argp = (void __user *)arg;
2849 ULONG __user *pIndex = argp;
2850 i2eBordStrPtr pB = i2BoardPtrTable[iplminor / 4];
2854 printk (KERN_DEBUG "IP2IPL: ioctl cmd %d, arg %ld\n", cmd, arg );
2857 switch ( iplminor ) {
2858 case 0: // IPL device
2861 case 1: // Status dump
2866 case 64: /* Driver - ip2stat */
2867 rc = put_user(ip2_tty_driver->refcount, pIndex++ );
2868 rc = put_user(irq_counter, pIndex++ );
2869 rc = put_user(bh_counter, pIndex++ );
2872 case 65: /* Board - ip2stat */
2874 rc = copy_to_user(argp, pB, sizeof(i2eBordStr));
2875 rc = put_user(INB(pB->i2eStatus),
2876 (ULONG __user *)(arg + (ULONG)(&pB->i2eStatus) - (ULONG)pB ) );
2883 if (cmd < IP2_MAX_PORTS) {
2884 pCh = DevTable[cmd];
2887 rc = copy_to_user(argp, pCh, sizeof(i2ChanStr));
2897 case 2: // Ping device
2900 case 3: // Trace device
2902 * akpm: This used to write a whole bunch of function addresses
2903 * to userspace, which generated lots of put_user() warnings.
2904 * I killed it all. Just return "success" and don't do
2920 /******************************************************************************/
2921 /* Function: ip2_ipl_open() */
2922 /* Parameters: Pointer to device inode */
2923 /* Pointer to file structure */
2924 /* Returns: Success or failure */
2929 /******************************************************************************/
2931 ip2_ipl_open( struct inode *pInode, struct file *pFile )
2933 unsigned int iplminor = iminor(pInode);
2938 printk (KERN_DEBUG "IP2IPL: open\n" );
2942 // These are the IPL devices
2949 // These are the status devices
2956 // These are the debug devices
2961 pB = i2BoardPtrTable[iplminor / 4];
2962 pCh = (i2ChanStrPtr) pB->i2eChannelPtr;
2965 // This is the trace device
2973 proc_ip2mem_show(struct seq_file *m, void *v)
2980 #define FMTLINE "%3d: 0x%08x 0x%08x 0%011o 0%011o\n"
2981 #define FMTLIN2 " 0x%04x 0x%04x tx flow 0x%x\n"
2982 #define FMTLIN3 " 0x%04x 0x%04x rc flow\n"
2986 for( i = 0; i < IP2_MAX_BOARDS; ++i ) {
2987 pB = i2BoardPtrTable[i];
2989 seq_printf(m,"board %d:\n",i);
2990 seq_printf(m,"\tFifo rem: %d mty: %x outM %x\n",
2991 pB->i2eFifoRemains,pB->i2eWaitingForEmptyFifo,pB->i2eOutMailWaiting);
2995 seq_printf(m,"#: tty flags, port flags, cflags, iflags\n");
2996 for (i=0; i < IP2_MAX_PORTS; i++) {
3000 if (tty && tty->count) {
3001 seq_printf(m,FMTLINE,i,(int)tty->flags,pCh->flags,
3002 tty->termios->c_cflag,tty->termios->c_iflag);
3004 seq_printf(m,FMTLIN2,
3005 pCh->outfl.asof,pCh->outfl.room,pCh->channelNeeds);
3006 seq_printf(m,FMTLIN3,pCh->infl.asof,pCh->infl.room);
3013 static int proc_ip2mem_open(struct inode *inode, struct file *file)
3015 return single_open(file, proc_ip2mem_show, NULL);
3018 static const struct file_operations ip2mem_proc_fops = {
3019 .owner = THIS_MODULE,
3020 .open = proc_ip2mem_open,
3022 .llseek = seq_lseek,
3023 .release = single_release,
3027 * This is the handler for /proc/tty/driver/ip2
3029 * This stretch of code has been largely plagerized from at least three
3030 * different sources including ip2mkdev.c and a couple of other drivers.
3031 * The bugs are all mine. :-) =mhw=
3033 static int ip2_read_proc(char *page, char **start, off_t off,
3034 int count, int *eof, void *data)
3044 len += sprintf(page, "ip2info: 1.0 driver: %s\n", pcVersion );
3045 len += sprintf(page+len, "Driver: SMajor=%d CMajor=%d IMajor=%d MaxBoards=%d MaxBoxes=%d MaxPorts=%d\n",
3046 IP2_TTY_MAJOR, IP2_CALLOUT_MAJOR, IP2_IPL_MAJOR,
3047 IP2_MAX_BOARDS, ABS_MAX_BOXES, ABS_BIGGEST_BOX);
3049 for( i = 0; i < IP2_MAX_BOARDS; ++i ) {
3050 /* This need to be reset for a board by board count... */
3052 pB = i2BoardPtrTable[i];
3054 switch( pB->i2ePom.e.porID & ~POR_ID_RESERVED )
3057 len += sprintf( page+len, "Board %d: EX ports=", i );
3058 for( box = 0; box < ABS_MAX_BOXES; ++box )
3062 if( pB->i2eChannelMap[box] != 0 ) ++boxes;
3063 for( j = 0; j < ABS_BIGGEST_BOX; ++j )
3065 if( pB->i2eChannelMap[box] & 1<< j ) {
3069 len += sprintf( page+len, "%d,", ports );
3073 --len; /* Backup over that last comma */
3075 len += sprintf( page+len, " boxes=%d width=%d", boxes, pB->i2eDataWidth16 ? 16 : 8 );
3079 len += sprintf(page+len, "Board %d: ISA-4 ports=4 boxes=1", i );
3084 len += sprintf(page+len, "Board %d: ISA-8-std ports=8 boxes=1", i );
3089 len += sprintf(page+len, "Board %d: ISA-8-RJ11 ports=8 boxes=1", i );
3094 len += sprintf(page+len, "Board %d: unknown", i );
3095 /* Don't try and probe for minor numbers */
3100 /* Don't try and probe for minor numbers */
3101 len += sprintf(page+len, "Board %d: vacant", i );
3106 len += sprintf(page+len, " minors=" );
3108 for ( box = 0; box < ABS_MAX_BOXES; ++box )
3110 for ( j = 0; j < ABS_BIGGEST_BOX; ++j )
3112 if ( pB->i2eChannelMap[box] & (1 << j) )
3114 len += sprintf (page+len,"%d,",
3115 j + ABS_BIGGEST_BOX *
3116 (box+i*ABS_MAX_BOXES));
3121 page[ len - 1 ] = '\n'; /* Overwrite that last comma */
3123 len += sprintf (page+len,"\n" );
3126 if (len+begin > off+count)
3128 if (len+begin < off) {
3134 if (i >= IP2_MAX_BOARDS)
3136 if (off >= len+begin)
3139 *start = page + (off-begin);
3140 return ((count < begin+len-off) ? count : begin+len-off);
3143 /******************************************************************************/
3144 /* Function: ip2trace() */
3145 /* Parameters: Value to add to trace buffer */
3146 /* Returns: Nothing */
3151 /******************************************************************************/
3152 #ifdef IP2DEBUG_TRACE
3154 ip2trace (unsigned short pn, unsigned char cat, unsigned char label, unsigned long codes, ...)
3157 unsigned long *pCode = &codes;
3158 union ip2breadcrumb bc;
3162 tracebuf[tracestuff++] = jiffies;
3163 if ( tracestuff == TRACEMAX ) {
3166 if ( tracestuff == tracestrip ) {
3167 if ( ++tracestrip == TRACEMAX ) {
3173 bc.hdr.port = 0xff & pn;
3175 bc.hdr.codes = (unsigned char)( codes & 0xff );
3176 bc.hdr.label = label;
3177 tracebuf[tracestuff++] = bc.value;
3180 if ( tracestuff == TRACEMAX ) {
3183 if ( tracestuff == tracestrip ) {
3184 if ( ++tracestrip == TRACEMAX ) {
3193 tracebuf[tracestuff++] = *++pCode;
3199 MODULE_LICENSE("GPL");
3201 static struct pci_device_id ip2main_pci_tbl[] __devinitdata = {
3202 { PCI_DEVICE(PCI_VENDOR_ID_COMPUTONE, PCI_DEVICE_ID_COMPUTONE_IP2EX) },
3206 MODULE_DEVICE_TABLE(pci, ip2main_pci_tbl);