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>
101 #include <linux/smp_lock.h>
102 #include <linux/firmware.h>
103 #include <linux/platform_device.h>
105 #include <linux/tty.h>
106 #include <linux/tty_flip.h>
107 #include <linux/termios.h>
108 #include <linux/tty_driver.h>
109 #include <linux/serial.h>
110 #include <linux/ptrace.h>
111 #include <linux/ioport.h>
113 #include <linux/cdk.h>
114 #include <linux/comstats.h>
115 #include <linux/delay.h>
116 #include <linux/bitops.h>
118 #include <asm/system.h>
122 #include <linux/vmalloc.h>
123 #include <linux/init.h>
125 #include <asm/uaccess.h>
127 #include "ip2types.h"
128 #include "ip2trace.h"
129 #include "ip2ioctl.h"
138 #include <linux/proc_fs.h>
139 #include <linux/seq_file.h>
141 static const struct file_operations ip2mem_proc_fops;
142 static int ip2_read_proc(char *, char **, off_t, int, int *, void * );
144 /********************/
145 /* Type Definitions */
146 /********************/
152 /* String constants to identify ourselves */
153 static const char pcName[] = "Computone IntelliPort Plus multiport driver";
154 static const char pcVersion[] = "1.2.14";
156 /* String constants for port names */
157 static const char pcDriver_name[] = "ip2";
158 static const char pcIpl[] = "ip2ipl";
160 /***********************/
161 /* Function Prototypes */
162 /***********************/
164 /* Global module entry functions */
166 /* Private (static) functions */
167 static int ip2_open(PTTY, struct file *);
168 static void ip2_close(PTTY, struct file *);
169 static int ip2_write(PTTY, const unsigned char *, int);
170 static int ip2_putchar(PTTY, unsigned char);
171 static void ip2_flush_chars(PTTY);
172 static int ip2_write_room(PTTY);
173 static int ip2_chars_in_buf(PTTY);
174 static void ip2_flush_buffer(PTTY);
175 static int ip2_ioctl(PTTY, struct file *, UINT, ULONG);
176 static void ip2_set_termios(PTTY, struct ktermios *);
177 static void ip2_set_line_discipline(PTTY);
178 static void ip2_throttle(PTTY);
179 static void ip2_unthrottle(PTTY);
180 static void ip2_stop(PTTY);
181 static void ip2_start(PTTY);
182 static void ip2_hangup(PTTY);
183 static int ip2_tiocmget(struct tty_struct *tty, struct file *file);
184 static int ip2_tiocmset(struct tty_struct *tty, struct file *file,
185 unsigned int set, unsigned int clear);
187 static void set_irq(int, int);
188 static void ip2_interrupt_bh(struct work_struct *work);
189 static irqreturn_t ip2_interrupt(int irq, void *dev_id);
190 static void ip2_poll(unsigned long arg);
191 static inline void service_all_boards(void);
192 static void do_input(struct work_struct *);
193 static void do_status(struct work_struct *);
195 static void ip2_wait_until_sent(PTTY,int);
197 static void set_params (i2ChanStrPtr, struct ktermios *);
198 static int get_serial_info(i2ChanStrPtr, struct serial_struct __user *);
199 static int set_serial_info(i2ChanStrPtr, struct serial_struct __user *);
201 static ssize_t ip2_ipl_read(struct file *, char __user *, size_t, loff_t *);
202 static ssize_t ip2_ipl_write(struct file *, const char __user *, size_t, loff_t *);
203 static long ip2_ipl_ioctl(struct file *, UINT, ULONG);
204 static int ip2_ipl_open(struct inode *, struct file *);
206 static int DumpTraceBuffer(char __user *, int);
207 static int DumpFifoBuffer( char __user *, int);
209 static void ip2_init_board(int, const struct firmware *);
210 static unsigned short find_eisa_board(int);
216 static struct tty_driver *ip2_tty_driver;
218 /* Here, then is a table of board pointers which the interrupt routine should
219 * scan through to determine who it must service.
221 static unsigned short i2nBoards; // Number of boards here
223 static i2eBordStrPtr i2BoardPtrTable[IP2_MAX_BOARDS];
225 static i2ChanStrPtr DevTable[IP2_MAX_PORTS];
226 //DevTableMem just used to save addresses for kfree
227 static void *DevTableMem[IP2_MAX_BOARDS];
229 /* This is the driver descriptor for the ip2ipl device, which is used to
230 * download the loadware to the boards.
232 static const struct file_operations ip2_ipl = {
233 .owner = THIS_MODULE,
234 .read = ip2_ipl_read,
235 .write = ip2_ipl_write,
236 .unlocked_ioctl = ip2_ipl_ioctl,
237 .open = ip2_ipl_open,
240 static unsigned long irq_counter;
241 static unsigned long bh_counter;
243 // Use immediate queue to service interrupts
245 //#define USE_IQ // PCI&2.2 needs work
247 /* The timer_list entry for our poll routine. If interrupt operation is not
248 * selected, the board is serviced periodically to see if anything needs doing.
250 #define POLL_TIMEOUT (jiffies + 1)
251 static DEFINE_TIMER(PollTimer, ip2_poll, 0, 0);
254 #ifdef IP2DEBUG_TRACE
255 /* Trace (debug) buffer data */
256 #define TRACEMAX 1000
257 static unsigned long tracebuf[TRACEMAX];
258 static int tracestuff;
259 static int tracestrip;
260 static int tracewrap;
267 #if defined(MODULE) && defined(IP2DEBUG_OPEN)
268 #define DBG_CNT(s) printk(KERN_DEBUG "(%s): [%x] refc=%d, ttyc=%d, modc=%x -> %s\n", \
269 tty->name,(pCh->flags),ip2_tty_driver->refcount, \
270 tty->count,/*GET_USE_COUNT(module)*/0,s)
279 #include "i2ellis.c" /* Extremely low-level interface services */
280 #include "i2cmd.c" /* Standard loadware command definitions */
281 #include "i2lib.c" /* High level interface services */
283 /* Configuration area for modprobe */
285 MODULE_AUTHOR("Doug McNash");
286 MODULE_DESCRIPTION("Computone IntelliPort Plus Driver");
287 MODULE_LICENSE("GPL");
289 static int poll_only;
292 static int Eisa_slot;
295 static char rirqs[IP2_MAX_BOARDS];
296 static int Valid_Irqs[] = { 3, 4, 5, 7, 10, 11, 12, 15, 0};
298 /* Note: Add compiled in defaults to these arrays, not to the structure
299 in ip2.h any longer. That structure WILL get overridden
300 by these values, or command line values, or insmod values!!! =mhw=
302 static int io[IP2_MAX_BOARDS];
303 static int irq[IP2_MAX_BOARDS] = { -1, -1, -1, -1 };
305 MODULE_AUTHOR("Doug McNash");
306 MODULE_DESCRIPTION("Computone IntelliPort Plus Driver");
307 module_param_array(irq, int, NULL, 0);
308 MODULE_PARM_DESC(irq, "Interrupts for IntelliPort Cards");
309 module_param_array(io, int, NULL, 0);
310 MODULE_PARM_DESC(io, "I/O ports for IntelliPort Cards");
311 module_param(poll_only, bool, 0);
312 MODULE_PARM_DESC(poll_only, "Do not use card interrupts");
314 /* for sysfs class support */
315 static struct class *ip2_class;
317 /* Some functions to keep track of what irqs we have */
319 static int __init is_valid_irq(int irq)
323 while (*i != 0 && *i != irq)
329 static void __init mark_requested_irq(char irq)
331 rirqs[iindx++] = irq;
334 static int __exit clear_requested_irq(char irq)
337 for (i = 0; i < IP2_MAX_BOARDS; ++i) {
338 if (rirqs[i] == irq) {
346 static int have_requested_irq(char irq)
348 /* array init to zeros so 0 irq will not be requested as a side
351 for (i = 0; i < IP2_MAX_BOARDS; ++i)
357 /******************************************************************************/
358 /* Function: cleanup_module() */
359 /* Parameters: None */
360 /* Returns: Nothing */
363 /* This is a required entry point for an installable module. It has to return */
364 /* the device and the driver to a passive state. It should not be necessary */
365 /* to reset the board fully, especially as the loadware is downloaded */
366 /* externally rather than in the driver. We just want to disable the board */
367 /* and clear the loadware to a reset state. To allow this there has to be a */
368 /* way to detect whether the board has the loadware running at init time to */
369 /* handle subsequent installations of the driver. All memory allocated by the */
370 /* driver should be returned since it may be unloaded from memory. */
371 /******************************************************************************/
372 static void __exit ip2_cleanup_module(void)
377 /* Stop poll timer if we had one. */
379 del_timer(&PollTimer);
383 /* Reset the boards we have. */
384 for (i = 0; i < IP2_MAX_BOARDS; i++)
385 if (i2BoardPtrTable[i])
386 iiReset(i2BoardPtrTable[i]);
388 /* The following is done at most once, if any boards were installed. */
389 for (i = 0; i < IP2_MAX_BOARDS; i++) {
390 if (i2BoardPtrTable[i]) {
391 iiResetDelay(i2BoardPtrTable[i]);
392 /* free io addresses and Tibet */
393 release_region(ip2config.addr[i], 8);
394 device_destroy(ip2_class, MKDEV(IP2_IPL_MAJOR, 4 * i));
395 device_destroy(ip2_class, MKDEV(IP2_IPL_MAJOR,
398 /* Disable and remove interrupt handler. */
399 if (ip2config.irq[i] > 0 &&
400 have_requested_irq(ip2config.irq[i])) {
401 free_irq(ip2config.irq[i], (void *)&pcName);
402 clear_requested_irq(ip2config.irq[i]);
405 class_destroy(ip2_class);
406 err = tty_unregister_driver(ip2_tty_driver);
408 printk(KERN_ERR "IP2: failed to unregister tty driver (%d)\n",
410 put_tty_driver(ip2_tty_driver);
411 unregister_chrdev(IP2_IPL_MAJOR, pcIpl);
412 remove_proc_entry("ip2mem", NULL);
415 for (i = 0; i < IP2_MAX_BOARDS; i++) {
418 if (ip2config.type[i] == PCI && ip2config.pci_dev[i]) {
419 pci_disable_device(ip2config.pci_dev[i]);
420 pci_dev_put(ip2config.pci_dev[i]);
421 ip2config.pci_dev[i] = NULL;
424 pB = i2BoardPtrTable[i];
427 i2BoardPtrTable[i] = NULL;
429 if (DevTableMem[i] != NULL) {
430 kfree(DevTableMem[i]);
431 DevTableMem[i] = NULL;
435 module_exit(ip2_cleanup_module);
437 static const struct tty_operations ip2_ops = {
441 .put_char = ip2_putchar,
442 .flush_chars = ip2_flush_chars,
443 .write_room = ip2_write_room,
444 .chars_in_buffer = ip2_chars_in_buf,
445 .flush_buffer = ip2_flush_buffer,
447 .throttle = ip2_throttle,
448 .unthrottle = ip2_unthrottle,
449 .set_termios = ip2_set_termios,
450 .set_ldisc = ip2_set_line_discipline,
453 .hangup = ip2_hangup,
454 .read_proc = ip2_read_proc,
455 .tiocmget = ip2_tiocmget,
456 .tiocmset = ip2_tiocmset,
459 /******************************************************************************/
460 /* Function: ip2_loadmain() */
461 /* Parameters: irq, io from command line of insmod et. al. */
462 /* pointer to fip firmware and firmware size for boards */
463 /* Returns: Success (0) */
466 /* This was the required entry point for all drivers (now in ip2.c) */
467 /* It performs all */
468 /* initialisation of the devices and driver structures, and registers itself */
469 /* with the relevant kernel modules. */
470 /******************************************************************************/
471 /* IRQF_DISABLED - if set blocks all interrupts else only this line */
472 /* IRQF_SHARED - for shared irq PCI or maybe EISA only */
473 /* SA_RANDOM - can be source for cert. random number generators */
474 #define IP2_SA_FLAGS 0
477 static const struct firmware *ip2_request_firmware(void)
479 struct platform_device *pdev;
480 const struct firmware *fw;
482 pdev = platform_device_register_simple("ip2", 0, NULL, 0);
484 printk(KERN_ERR "Failed to register platform device for ip2\n");
487 if (request_firmware(&fw, "intelliport2.bin", &pdev->dev)) {
488 printk(KERN_ERR "Failed to load firmware 'intelliport2.bin'\n");
491 platform_device_unregister(pdev);
496 /******************************************************************************
498 * str: kernel command line string
500 * Can't autoprobe the boards so user must specify configuration on
501 * kernel command line. Sane people build it modular but the others
504 * Alternating pairs of io,irq for up to 4 boards.
505 * ip2=io0,irq0,io1,irq1,io2,irq2,io3,irq3
510 * else => ISA I/O address
512 * irq=0 or invalid for ISA will revert to polling mode
514 * Any value = -1, do not overwrite compiled in value.
516 ******************************************************************************/
517 static int __init ip2_setup(char *str)
519 int j, ints[10]; /* 4 boards, 2 parameters + 2 */
522 str = get_options(str, ARRAY_SIZE(ints), ints);
524 for (i = 0, j = 1; i < 4; i++) {
538 __setup("ip2=", ip2_setup);
541 static int __init ip2_loadmain(void)
545 i2eBordStrPtr pB = NULL;
547 struct pci_dev *pdev = NULL;
548 const struct firmware *fw = NULL;
551 /* Hard lock the interrupts to zero */
552 irq[0] = irq[1] = irq[2] = irq[3] = poll_only = 0;
555 ip2trace(ITRC_NO_PORT, ITRC_INIT, ITRC_ENTER, 0);
557 /* process command line arguments to modprobe or
558 insmod i.e. iop & irqp */
559 /* irqp and iop should ALWAYS be specified now... But we check
560 them individually just to be sure, anyways... */
561 for (i = 0; i < IP2_MAX_BOARDS; ++i) {
562 ip2config.addr[i] = io[i];
564 ip2config.irq[i] = irq[i];
566 ip2config.irq[i] = 0;
567 /* This is a little bit of a hack. If poll_only=1 on command
568 line back in ip2.c OR all IRQs on all specified boards are
569 explicitly set to 0, then drop to poll only mode and override
570 PCI or EISA interrupts. This superceeds the old hack of
571 triggering if all interrupts were zero (like da default).
572 Still a hack but less prone to random acts of terrorism.
574 What we really should do, now that the IRQ default is set
575 to -1, is to use 0 as a hard coded, do not probe.
581 poll_only = !poll_only;
583 /* Announce our presence */
584 printk(KERN_INFO "%s version %s\n", pcName, pcVersion);
586 ip2_tty_driver = alloc_tty_driver(IP2_MAX_PORTS);
590 /* Initialise all the boards we can find (up to the maximum). */
591 for (i = 0; i < IP2_MAX_BOARDS; ++i) {
592 switch (ip2config.addr[i]) {
593 case 0: /* skip this slot even if card is present */
596 /* ISA address must be specified */
597 if (ip2config.addr[i] < 0x100 ||
598 ip2config.addr[i] > 0x3f8) {
599 printk(KERN_ERR "IP2: Bad ISA board %d "
602 ip2config.addr[i] = 0;
605 ip2config.type[i] = ISA;
607 /* Check for valid irq argument, set for polling if
609 if (ip2config.irq[i] &&
610 !is_valid_irq(ip2config.irq[i])) {
611 printk(KERN_ERR "IP2: Bad IRQ(%d) specified\n",
613 /* 0 is polling and is valid in that sense */
614 ip2config.irq[i] = 0;
623 pdev = pci_get_device(PCI_VENDOR_ID_COMPUTONE,
624 PCI_DEVICE_ID_COMPUTONE_IP2EX, pdev);
626 ip2config.addr[i] = 0;
627 printk(KERN_ERR "IP2: PCI board %d not "
632 if (pci_enable_device(pdev)) {
633 dev_err(&pdev->dev, "can't enable device\n");
636 ip2config.type[i] = PCI;
637 ip2config.pci_dev[i] = pci_dev_get(pdev);
638 status = pci_read_config_dword(pdev, PCI_BASE_ADDRESS_1,
641 ip2config.addr[i] = (USHORT)(addr & 0xfffe);
643 dev_err(&pdev->dev, "I/O address error\n");
645 ip2config.irq[i] = pdev->irq;
648 printk(KERN_ERR "IP2: PCI card specified but PCI "
649 "support not enabled.\n");
650 printk(KERN_ERR "IP2: Recompile kernel with CONFIG_PCI "
652 #endif /* CONFIG_PCI */
655 ip2config.addr[i] = find_eisa_board(Eisa_slot + 1);
656 if (ip2config.addr[i] != 0) {
657 /* Eisa_irq set as side effect, boo */
658 ip2config.type[i] = EISA;
660 ip2config.irq[i] = Eisa_irq;
666 for (i = 0; i < IP2_MAX_BOARDS; ++i) {
667 if (ip2config.addr[i]) {
668 pB = kzalloc(sizeof(i2eBordStr), GFP_KERNEL);
670 i2BoardPtrTable[i] = pB;
671 iiSetAddress(pB, ip2config.addr[i],
675 printk(KERN_ERR "IP2: board memory allocation "
679 for (i = 0; i < IP2_MAX_BOARDS; ++i) {
680 pB = i2BoardPtrTable[i];
686 for (i = 0; i < IP2_MAX_BOARDS; ++i) {
687 /* We don't want to request the firmware unless we have at
689 if (i2BoardPtrTable[i] != NULL) {
691 fw = ip2_request_firmware();
694 ip2_init_board(i, fw);
698 release_firmware(fw);
700 ip2trace(ITRC_NO_PORT, ITRC_INIT, 2, 0);
702 ip2_tty_driver->owner = THIS_MODULE;
703 ip2_tty_driver->name = "ttyF";
704 ip2_tty_driver->driver_name = pcDriver_name;
705 ip2_tty_driver->major = IP2_TTY_MAJOR;
706 ip2_tty_driver->minor_start = 0;
707 ip2_tty_driver->type = TTY_DRIVER_TYPE_SERIAL;
708 ip2_tty_driver->subtype = SERIAL_TYPE_NORMAL;
709 ip2_tty_driver->init_termios = tty_std_termios;
710 ip2_tty_driver->init_termios.c_cflag = B9600|CS8|CREAD|HUPCL|CLOCAL;
711 ip2_tty_driver->flags = TTY_DRIVER_REAL_RAW |
712 TTY_DRIVER_DYNAMIC_DEV;
713 tty_set_operations(ip2_tty_driver, &ip2_ops);
715 ip2trace(ITRC_NO_PORT, ITRC_INIT, 3, 0);
717 err = tty_register_driver(ip2_tty_driver);
719 printk(KERN_ERR "IP2: failed to register tty driver\n");
720 put_tty_driver(ip2_tty_driver);
721 return err; /* leaking resources */
724 err = register_chrdev(IP2_IPL_MAJOR, pcIpl, &ip2_ipl);
726 printk(KERN_ERR "IP2: failed to register IPL device (%d)\n",
729 /* create the sysfs class */
730 ip2_class = class_create(THIS_MODULE, "ip2");
731 if (IS_ERR(ip2_class)) {
732 err = PTR_ERR(ip2_class);
736 /* Register the read_procmem thing */
737 if (!proc_create("ip2mem",0,NULL,&ip2mem_proc_fops)) {
738 printk(KERN_ERR "IP2: failed to register read_procmem\n");
739 return -EIO; /* leaking resources */
742 ip2trace(ITRC_NO_PORT, ITRC_INIT, 4, 0);
743 /* Register the interrupt handler or poll handler, depending upon the
744 * specified interrupt.
747 for (i = 0; i < IP2_MAX_BOARDS; ++i) {
748 if (ip2config.addr[i] == 0)
751 pB = i2BoardPtrTable[i];
753 device_create_drvdata(ip2_class, NULL,
754 MKDEV(IP2_IPL_MAJOR, 4 * i),
756 device_create_drvdata(ip2_class, NULL,
757 MKDEV(IP2_IPL_MAJOR, 4 * i + 1),
760 for (box = 0; box < ABS_MAX_BOXES; box++)
761 for (j = 0; j < ABS_BIGGEST_BOX; j++)
762 if (pB->i2eChannelMap[box] & (1 << j))
765 j + ABS_BIGGEST_BOX *
766 (box+i*ABS_MAX_BOXES),
771 /* Poll only forces driver to only use polling and
772 to ignore the probed PCI or EISA interrupts. */
773 ip2config.irq[i] = CIR_POLL;
775 if (ip2config.irq[i] == CIR_POLL) {
778 PollTimer.expires = POLL_TIMEOUT;
779 add_timer(&PollTimer);
781 printk(KERN_INFO "IP2: polling\n");
784 if (have_requested_irq(ip2config.irq[i]))
786 rc = request_irq(ip2config.irq[i], ip2_interrupt,
788 (ip2config.type[i] == PCI ? IRQF_SHARED : 0),
789 pcName, i2BoardPtrTable[i]);
791 printk(KERN_ERR "IP2: request_irq failed: "
793 ip2config.irq[i] = CIR_POLL;
794 printk(KERN_INFO "IP2: Polling %ld/sec.\n",
795 (POLL_TIMEOUT - jiffies));
798 mark_requested_irq(ip2config.irq[i]);
799 /* Initialise the interrupt handler bottom half
804 for (i = 0; i < IP2_MAX_BOARDS; ++i) {
805 if (i2BoardPtrTable[i]) {
806 /* set and enable board interrupt */
807 set_irq(i, ip2config.irq[i]);
811 ip2trace(ITRC_NO_PORT, ITRC_INIT, ITRC_RETURN, 0);
816 unregister_chrdev(IP2_IPL_MAJOR, "ip2");
817 /* unregister and put tty here */
820 module_init(ip2_loadmain);
822 /******************************************************************************/
823 /* Function: ip2_init_board() */
824 /* Parameters: Index of board in configuration structure */
825 /* Returns: Success (0) */
828 /* This function initializes the specified board. The loadware is copied to */
829 /* the board, the channel structures are initialized, and the board details */
830 /* are reported on the console. */
831 /******************************************************************************/
833 ip2_init_board(int boardnum, const struct firmware *fw)
836 int nports = 0, nboxes = 0;
838 i2eBordStrPtr pB = i2BoardPtrTable[boardnum];
840 if ( !iiInitialize ( pB ) ) {
841 printk ( KERN_ERR "IP2: Failed to initialize board at 0x%x, error %d\n",
842 pB->i2eBase, pB->i2eError );
845 printk(KERN_INFO "IP2: Board %d: addr=0x%x irq=%d\n", boardnum + 1,
846 ip2config.addr[boardnum], ip2config.irq[boardnum] );
848 if (!request_region( ip2config.addr[boardnum], 8, pcName )) {
849 printk(KERN_ERR "IP2: bad addr=0x%x\n", ip2config.addr[boardnum]);
853 if ( iiDownloadAll ( pB, (loadHdrStrPtr)fw->data, 1, fw->size )
855 printk ( KERN_ERR "IP2: failed to download loadware\n" );
856 goto err_release_region;
858 printk ( KERN_INFO "IP2: fv=%d.%d.%d lv=%d.%d.%d\n",
859 pB->i2ePom.e.porVersion,
860 pB->i2ePom.e.porRevision,
861 pB->i2ePom.e.porSubRev, pB->i2eLVersion,
862 pB->i2eLRevision, pB->i2eLSub );
865 switch ( pB->i2ePom.e.porID & ~POR_ID_RESERVED ) {
868 printk( KERN_ERR "IP2: Unknown board type, ID = %x\n",
869 pB->i2ePom.e.porID );
871 goto err_release_region;
874 case POR_ID_II_4: /* IntelliPort-II, ISA-4 (4xRJ45) */
875 printk ( KERN_INFO "IP2: ISA-4\n" );
879 case POR_ID_II_8: /* IntelliPort-II, 8-port using standard brick. */
880 printk ( KERN_INFO "IP2: ISA-8 std\n" );
884 case POR_ID_II_8R: /* IntelliPort-II, 8-port using RJ11's (no CTS) */
885 printk ( KERN_INFO "IP2: ISA-8 RJ11\n" );
889 case POR_ID_FIIEX: /* IntelliPort IIEX */
891 int portnum = IP2_PORTS_PER_BOARD * boardnum;
894 for( box = 0; box < ABS_MAX_BOXES; ++box ) {
895 if ( pB->i2eChannelMap[box] != 0 ) {
898 for( i = 0; i < ABS_BIGGEST_BOX; ++i ) {
899 if ( pB->i2eChannelMap[box] & 1<< i ) {
904 DevTableMem[boardnum] = pCh =
905 kmalloc( sizeof(i2ChanStr) * nports, GFP_KERNEL );
907 printk ( KERN_ERR "IP2: (i2_init_channel:) Out of memory.\n");
908 goto err_release_region;
910 if ( !i2InitChannels( pB, nports, pCh ) ) {
911 printk(KERN_ERR "IP2: i2InitChannels failed: %d\n",pB->i2eError);
913 goto err_release_region;
915 pB->i2eChannelPtr = &DevTable[portnum];
916 pB->i2eChannelCnt = ABS_MOST_PORTS;
918 for( box = 0; box < ABS_MAX_BOXES; ++box, portnum += ABS_BIGGEST_BOX ) {
919 for( i = 0; i < ABS_BIGGEST_BOX; ++i ) {
920 if ( pB->i2eChannelMap[box] & (1 << i) ) {
921 DevTable[portnum + i] = pCh;
922 pCh->port_index = portnum + i;
927 printk(KERN_INFO "IP2: EX box=%d ports=%d %d bit\n",
928 nboxes, nports, pB->i2eDataWidth16 ? 16 : 8 );
932 DevTableMem[boardnum] = pCh =
933 kmalloc ( sizeof (i2ChanStr) * nports, GFP_KERNEL );
935 printk ( KERN_ERR "IP2: (i2_init_channel:) Out of memory.\n");
936 goto err_release_region;
938 pB->i2eChannelPtr = pCh;
939 pB->i2eChannelCnt = nports;
940 if ( !i2InitChannels( pB, nports, pCh ) ) {
941 printk(KERN_ERR "IP2: i2InitChannels failed: %d\n",pB->i2eError);
943 goto err_release_region;
945 pB->i2eChannelPtr = &DevTable[IP2_PORTS_PER_BOARD * boardnum];
947 for( i = 0; i < pB->i2eChannelCnt; ++i ) {
948 DevTable[IP2_PORTS_PER_BOARD * boardnum + i] = pCh;
949 pCh->port_index = (IP2_PORTS_PER_BOARD * boardnum) + i;
953 INIT_WORK(&pB->tqueue_interrupt, ip2_interrupt_bh);
957 release_region(ip2config.addr[boardnum], 8);
960 i2BoardPtrTable[boardnum] = NULL;
964 /******************************************************************************/
965 /* Function: find_eisa_board ( int start_slot ) */
966 /* Parameters: First slot to check */
967 /* Returns: Address of EISA IntelliPort II controller */
970 /* This function searches for an EISA IntelliPort controller, starting */
971 /* from the specified slot number. If the motherboard is not identified as an */
972 /* EISA motherboard, or no valid board ID is selected it returns 0. Otherwise */
973 /* it returns the base address of the controller. */
974 /******************************************************************************/
975 static unsigned short
976 find_eisa_board( int start_slot )
979 unsigned int idm = 0;
980 unsigned int idp = 0;
981 unsigned int base = 0;
988 * First a check for an EISA motherboard, which we do by comparing the
989 * EISA ID registers for the system board and the first couple of slots.
990 * No slot ID should match the system board ID, but on an ISA or PCI
991 * machine the odds are that an empty bus will return similar values for
995 value = (inb(i) << 24) + (inb(i+1) << 16) + (inb(i+2) << 8) + inb(i+3);
996 for( i = 0x1c80; i <= 0x4c80; i += 0x1000 ) {
997 j = (inb(i)<<24)+(inb(i+1)<<16)+(inb(i+2)<<8)+inb(i+3);
1003 * OK, so we are inclined to believe that this is an EISA machine. Find
1004 * an IntelliPort controller.
1006 for( i = start_slot; i < 16; i++ ) {
1008 idm = (inb(base + 0xc80) << 8) | (inb(base + 0xc81) & 0xff);
1009 idp = (inb(base + 0xc82) << 8) | (inb(base + 0xc83) & 0xff);
1011 if ( idm == 0x0e8e ) {
1012 if ( idp == 0x0281 || idp == 0x0218 ) {
1014 } else if ( idp == 0x0282 || idp == 0x0283 ) {
1015 ismine = 3; /* Can do edge-trigger */
1026 /* It's some sort of EISA card, but at what address is it configured? */
1028 setup_address = base + 0xc88;
1029 value = inb(base + 0xc86);
1030 setup_irq = (value & 8) ? Valid_Irqs[value & 7] : 0;
1032 if ( (ismine & 2) && !(value & 0x10) ) {
1033 ismine = 1; /* Could be edging, but not */
1036 if ( Eisa_irq == 0 ) {
1037 Eisa_irq = setup_irq;
1038 } else if ( Eisa_irq != setup_irq ) {
1039 printk ( KERN_ERR "IP2: EISA irq mismatch between EISA controllers\n" );
1042 #ifdef IP2DEBUG_INIT
1043 printk(KERN_DEBUG "Computone EISA board in slot %d, I.D. 0x%x%x, Address 0x%x",
1044 base >> 12, idm, idp, setup_address);
1046 printk(KERN_DEBUG ", Interrupt %d %s\n",
1047 setup_irq, (ismine & 2) ? "(edge)" : "(level)");
1049 printk(KERN_DEBUG ", (polled)\n");
1052 return setup_address;
1055 /******************************************************************************/
1056 /* Function: set_irq() */
1057 /* Parameters: index to board in board table */
1059 /* Returns: Success (0) */
1062 /******************************************************************************/
1064 set_irq( int boardnum, int boardIrq )
1066 unsigned char tempCommand[16];
1067 i2eBordStrPtr pB = i2BoardPtrTable[boardnum];
1068 unsigned long flags;
1071 * Notify the boards they may generate interrupts. This is done by
1072 * sending an in-line command to channel 0 on each board. This is why
1073 * the channels have to be defined already. For each board, if the
1074 * interrupt has never been defined, we must do so NOW, directly, since
1075 * board will not send flow control or even give an interrupt until this
1076 * is done. If polling we must send 0 as the interrupt parameter.
1079 // We will get an interrupt here at the end of this function
1081 iiDisableMailIrq(pB);
1083 /* We build up the entire packet header. */
1084 CHANNEL_OF(tempCommand) = 0;
1085 PTYPE_OF(tempCommand) = PTYPE_INLINE;
1086 CMD_COUNT_OF(tempCommand) = 2;
1087 (CMD_OF(tempCommand))[0] = CMDVALUE_IRQ;
1088 (CMD_OF(tempCommand))[1] = boardIrq;
1090 * Write to FIFO; don't bother to adjust fifo capacity for this, since
1091 * board will respond almost immediately after SendMail hit.
1093 write_lock_irqsave(&pB->write_fifo_spinlock, flags);
1094 iiWriteBuf(pB, tempCommand, 4);
1095 write_unlock_irqrestore(&pB->write_fifo_spinlock, flags);
1096 pB->i2eUsingIrq = boardIrq;
1097 pB->i2eOutMailWaiting |= MB_OUT_STUFFED;
1099 /* Need to update number of boards before you enable mailbox int */
1102 CHANNEL_OF(tempCommand) = 0;
1103 PTYPE_OF(tempCommand) = PTYPE_BYPASS;
1104 CMD_COUNT_OF(tempCommand) = 6;
1105 (CMD_OF(tempCommand))[0] = 88; // SILO
1106 (CMD_OF(tempCommand))[1] = 64; // chars
1107 (CMD_OF(tempCommand))[2] = 32; // ms
1109 (CMD_OF(tempCommand))[3] = 28; // MAX_BLOCK
1110 (CMD_OF(tempCommand))[4] = 64; // chars
1112 (CMD_OF(tempCommand))[5] = 87; // HW_TEST
1113 write_lock_irqsave(&pB->write_fifo_spinlock, flags);
1114 iiWriteBuf(pB, tempCommand, 8);
1115 write_unlock_irqrestore(&pB->write_fifo_spinlock, flags);
1117 CHANNEL_OF(tempCommand) = 0;
1118 PTYPE_OF(tempCommand) = PTYPE_BYPASS;
1119 CMD_COUNT_OF(tempCommand) = 1;
1120 (CMD_OF(tempCommand))[0] = 84; /* get BOX_IDS */
1121 iiWriteBuf(pB, tempCommand, 3);
1124 // enable heartbeat for test porpoises
1125 CHANNEL_OF(tempCommand) = 0;
1126 PTYPE_OF(tempCommand) = PTYPE_BYPASS;
1127 CMD_COUNT_OF(tempCommand) = 2;
1128 (CMD_OF(tempCommand))[0] = 44; /* get ping */
1129 (CMD_OF(tempCommand))[1] = 200; /* 200 ms */
1130 write_lock_irqsave(&pB->write_fifo_spinlock, flags);
1131 iiWriteBuf(pB, tempCommand, 4);
1132 write_unlock_irqrestore(&pB->write_fifo_spinlock, flags);
1135 iiEnableMailIrq(pB);
1136 iiSendPendingMail(pB);
1139 /******************************************************************************/
1140 /* Interrupt Handler Section */
1141 /******************************************************************************/
1144 service_all_boards(void)
1149 /* Service every board on the list */
1150 for( i = 0; i < IP2_MAX_BOARDS; ++i ) {
1151 pB = i2BoardPtrTable[i];
1153 i2ServiceBoard( pB );
1159 /******************************************************************************/
1160 /* Function: ip2_interrupt_bh(work) */
1161 /* Parameters: work - pointer to the board structure */
1162 /* Returns: Nothing */
1165 /* Service the board in a bottom half interrupt handler and then */
1166 /* reenable the board's interrupts if it has an IRQ number */
1168 /******************************************************************************/
1170 ip2_interrupt_bh(struct work_struct *work)
1172 i2eBordStrPtr pB = container_of(work, i2eBordStr, tqueue_interrupt);
1173 // pB better well be set or we have a problem! We can only get
1174 // here from the IMMEDIATE queue. Here, we process the boards.
1175 // Checking pB doesn't cost much and it saves us from the sanity checkers.
1180 i2ServiceBoard( pB );
1181 if( pB->i2eUsingIrq ) {
1182 // Re-enable his interrupts
1183 iiEnableMailIrq(pB);
1189 /******************************************************************************/
1190 /* Function: ip2_interrupt(int irq, void *dev_id) */
1191 /* Parameters: irq - interrupt number */
1192 /* pointer to optional device ID structure */
1193 /* Returns: Nothing */
1197 /* Our task here is simply to identify each board which needs servicing. */
1198 /* If we are queuing then, queue it to be serviced, and disable its irq */
1199 /* mask otherwise process the board directly. */
1201 /* We could queue by IRQ but that just complicates things on both ends */
1202 /* with very little gain in performance (how many instructions does */
1203 /* it take to iterate on the immediate queue). */
1206 /******************************************************************************/
1208 ip2_irq_work(i2eBordStrPtr pB)
1211 if (NO_MAIL_HERE != ( pB->i2eStartMail = iiGetMail(pB))) {
1212 // Disable his interrupt (will be enabled when serviced)
1213 // This is mostly to protect from reentrancy.
1214 iiDisableMailIrq(pB);
1216 // Park the board on the immediate queue for processing.
1217 schedule_work(&pB->tqueue_interrupt);
1219 // Make sure the immediate queue is flagged to fire.
1223 // We are using immediate servicing here. This sucks and can
1224 // cause all sorts of havoc with ppp and others. The failsafe
1225 // check on iiSendPendingMail could also throw a hairball.
1227 i2ServiceBoard( pB );
1229 #endif /* USE_IQI */
1233 ip2_polled_interrupt(void)
1238 ip2trace(ITRC_NO_PORT, ITRC_INTR, 99, 1, 0);
1240 /* Service just the boards on the list using this irq */
1241 for( i = 0; i < i2nBoards; ++i ) {
1242 pB = i2BoardPtrTable[i];
1244 // Only process those boards which match our IRQ.
1245 // IRQ = 0 for polled boards, we won't poll "IRQ" boards
1247 if (pB && pB->i2eUsingIrq == 0)
1253 ip2trace (ITRC_NO_PORT, ITRC_INTR, ITRC_RETURN, 0 );
1257 ip2_interrupt(int irq, void *dev_id)
1259 i2eBordStrPtr pB = dev_id;
1261 ip2trace (ITRC_NO_PORT, ITRC_INTR, 99, 1, pB->i2eUsingIrq );
1267 ip2trace (ITRC_NO_PORT, ITRC_INTR, ITRC_RETURN, 0 );
1271 /******************************************************************************/
1272 /* Function: ip2_poll(unsigned long arg) */
1274 /* Returns: Nothing */
1277 /* This function calls the library routine i2ServiceBoard for each board in */
1278 /* the board table. This is used instead of the interrupt routine when polled */
1279 /* mode is specified. */
1280 /******************************************************************************/
1282 ip2_poll(unsigned long arg)
1284 ip2trace (ITRC_NO_PORT, ITRC_INTR, 100, 0 );
1286 TimerOn = 0; // it's the truth but not checked in service
1288 // Just polled boards, IRQ = 0 will hit all non-interrupt boards.
1289 // It will NOT poll boards handled by hard interrupts.
1290 // The issue of queued BH interrupts is handled in ip2_interrupt().
1291 ip2_polled_interrupt();
1293 PollTimer.expires = POLL_TIMEOUT;
1294 add_timer( &PollTimer );
1297 ip2trace (ITRC_NO_PORT, ITRC_INTR, ITRC_RETURN, 0 );
1300 static void do_input(struct work_struct *work)
1302 i2ChanStrPtr pCh = container_of(work, i2ChanStr, tqueue_input);
1303 unsigned long flags;
1305 ip2trace(CHANN, ITRC_INPUT, 21, 0 );
1308 if ( pCh->pTTY != NULL ) {
1309 read_lock_irqsave(&pCh->Ibuf_spinlock, flags);
1310 if (!pCh->throttled && (pCh->Ibuf_stuff != pCh->Ibuf_strip)) {
1311 read_unlock_irqrestore(&pCh->Ibuf_spinlock, flags);
1314 read_unlock_irqrestore(&pCh->Ibuf_spinlock, flags);
1316 ip2trace(CHANN, ITRC_INPUT, 22, 0 );
1318 i2InputFlush( pCh );
1322 // code duplicated from n_tty (ldisc)
1323 static inline void isig(int sig, struct tty_struct *tty, int flush)
1325 /* FIXME: This is completely bogus */
1327 kill_pgrp(tty->pgrp, sig, 1);
1328 if (flush || !L_NOFLSH(tty)) {
1329 if ( tty->ldisc.ops->flush_buffer )
1330 tty->ldisc.ops->flush_buffer(tty);
1331 i2InputFlush( tty->driver_data );
1335 static void do_status(struct work_struct *work)
1337 i2ChanStrPtr pCh = container_of(work, i2ChanStr, tqueue_status);
1340 status = i2GetStatus( pCh, (I2_BRK|I2_PAR|I2_FRA|I2_OVR) );
1342 ip2trace (CHANN, ITRC_STATUS, 21, 1, status );
1344 if (pCh->pTTY && (status & (I2_BRK|I2_PAR|I2_FRA|I2_OVR)) ) {
1345 if ( (status & I2_BRK) ) {
1346 // code duplicated from n_tty (ldisc)
1347 if (I_IGNBRK(pCh->pTTY))
1349 if (I_BRKINT(pCh->pTTY)) {
1350 isig(SIGINT, pCh->pTTY, 1);
1353 wake_up_interruptible(&pCh->pTTY->read_wait);
1355 #ifdef NEVER_HAPPENS_AS_SETUP_XXX
1356 // and can't work because we don't know the_char
1357 // as the_char is reported on a separate path
1358 // The intelligent board does this stuff as setup
1360 char brkf = TTY_NORMAL;
1361 unsigned char brkc = '\0';
1363 if ( (status & I2_BRK) ) {
1367 else if (status & I2_PAR) {
1370 } else if (status & I2_FRA) {
1373 } else if (status & I2_OVR) {
1377 tmp = pCh->pTTY->real_raw;
1378 pCh->pTTY->real_raw = 0;
1379 pCh->pTTY->ldisc->ops.receive_buf( pCh->pTTY, &brkc, &brkf, 1 );
1380 pCh->pTTY->real_raw = tmp;
1382 #endif /* NEVER_HAPPENS_AS_SETUP_XXX */
1386 if ( status & (I2_DDCD | I2_DDSR | I2_DCTS | I2_DRI) ) {
1387 wake_up_interruptible(&pCh->delta_msr_wait);
1389 if ( (pCh->flags & ASYNC_CHECK_CD) && (status & I2_DDCD) ) {
1390 if ( status & I2_DCD ) {
1392 wake_up_interruptible ( &pCh->open_wait );
1395 if (pCh->pTTY && (!(pCh->pTTY->termios->c_cflag & CLOCAL)) ) {
1396 tty_hangup( pCh->pTTY );
1402 ip2trace (CHANN, ITRC_STATUS, 26, 0 );
1405 /******************************************************************************/
1406 /* Device Open/Close/Ioctl Entry Point Section */
1407 /******************************************************************************/
1409 /******************************************************************************/
1410 /* Function: open_sanity_check() */
1411 /* Parameters: Pointer to tty structure */
1412 /* Pointer to file structure */
1413 /* Returns: Success or failure */
1416 /* Verifies the structure magic numbers and cross links. */
1417 /******************************************************************************/
1418 #ifdef IP2DEBUG_OPEN
1420 open_sanity_check( i2ChanStrPtr pCh, i2eBordStrPtr pBrd )
1422 if ( pBrd->i2eValid != I2E_MAGIC ) {
1423 printk(KERN_ERR "IP2: invalid board structure\n" );
1424 } else if ( pBrd != pCh->pMyBord ) {
1425 printk(KERN_ERR "IP2: board structure pointer mismatch (%p)\n",
1427 } else if ( pBrd->i2eChannelCnt < pCh->port_index ) {
1428 printk(KERN_ERR "IP2: bad device index (%d)\n", pCh->port_index );
1429 } else if (&((i2ChanStrPtr)pBrd->i2eChannelPtr)[pCh->port_index] != pCh) {
1431 printk(KERN_INFO "IP2: all pointers check out!\n" );
1437 /******************************************************************************/
1438 /* Function: ip2_open() */
1439 /* Parameters: Pointer to tty structure */
1440 /* Pointer to file structure */
1441 /* Returns: Success or failure */
1443 /* Description: (MANDATORY) */
1444 /* A successful device open has to run a gauntlet of checks before it */
1445 /* completes. After some sanity checking and pointer setup, the function */
1446 /* blocks until all conditions are satisfied. It then initialises the port to */
1447 /* the default characteristics and returns. */
1448 /******************************************************************************/
1450 ip2_open( PTTY tty, struct file *pFile )
1455 i2ChanStrPtr pCh = DevTable[tty->index];
1457 ip2trace (tty->index, ITRC_OPEN, ITRC_ENTER, 0 );
1459 if ( pCh == NULL ) {
1462 /* Setup pointer links in device and tty structures */
1464 tty->driver_data = pCh;
1466 #ifdef IP2DEBUG_OPEN
1468 "IP2:open(tty=%p,pFile=%p):dev=%s,ch=%d,idx=%d\n",
1469 tty, pFile, tty->name, pCh->infl.hd.i2sChannel, pCh->port_index);
1470 open_sanity_check ( pCh, pCh->pMyBord );
1473 i2QueueCommands(PTYPE_INLINE, pCh, 100, 3, CMD_DTRUP,CMD_RTSUP,CMD_DCD_REP);
1474 pCh->dataSetOut |= (I2_DTR | I2_RTS);
1475 serviceOutgoingFifo( pCh->pMyBord );
1477 /* Block here until the port is ready (per serial and istallion) */
1479 * 1. If the port is in the middle of closing wait for the completion
1480 * and then return the appropriate error.
1482 init_waitqueue_entry(&wait, current);
1483 add_wait_queue(&pCh->close_wait, &wait);
1484 set_current_state( TASK_INTERRUPTIBLE );
1486 if ( tty_hung_up_p(pFile) || ( pCh->flags & ASYNC_CLOSING )) {
1487 if ( pCh->flags & ASYNC_CLOSING ) {
1490 if ( tty_hung_up_p(pFile) ) {
1491 set_current_state( TASK_RUNNING );
1492 remove_wait_queue(&pCh->close_wait, &wait);
1493 return( pCh->flags & ASYNC_HUP_NOTIFY ) ? -EAGAIN : -ERESTARTSYS;
1496 set_current_state( TASK_RUNNING );
1497 remove_wait_queue(&pCh->close_wait, &wait);
1500 * 3. Handle a non-blocking open of a normal port.
1502 if ( (pFile->f_flags & O_NONBLOCK) || (tty->flags & (1<<TTY_IO_ERROR) )) {
1503 pCh->flags |= ASYNC_NORMAL_ACTIVE;
1507 * 4. Now loop waiting for the port to be free and carrier present
1510 if ( tty->termios->c_cflag & CLOCAL )
1513 #ifdef IP2DEBUG_OPEN
1514 printk(KERN_DEBUG "OpenBlock: do_clocal = %d\n", do_clocal);
1519 init_waitqueue_entry(&wait, current);
1520 add_wait_queue(&pCh->open_wait, &wait);
1523 i2QueueCommands(PTYPE_INLINE, pCh, 100, 2, CMD_DTRUP, CMD_RTSUP);
1524 pCh->dataSetOut |= (I2_DTR | I2_RTS);
1525 set_current_state( TASK_INTERRUPTIBLE );
1526 serviceOutgoingFifo( pCh->pMyBord );
1527 if ( tty_hung_up_p(pFile) ) {
1528 set_current_state( TASK_RUNNING );
1529 remove_wait_queue(&pCh->open_wait, &wait);
1530 return ( pCh->flags & ASYNC_HUP_NOTIFY ) ? -EBUSY : -ERESTARTSYS;
1532 if (!(pCh->flags & ASYNC_CLOSING) &&
1533 (do_clocal || (pCh->dataSetIn & I2_DCD) )) {
1538 #ifdef IP2DEBUG_OPEN
1539 printk(KERN_DEBUG "ASYNC_CLOSING = %s\n",
1540 (pCh->flags & ASYNC_CLOSING)?"True":"False");
1541 printk(KERN_DEBUG "OpenBlock: waiting for CD or signal\n");
1543 ip2trace (CHANN, ITRC_OPEN, 3, 2, 0,
1544 (pCh->flags & ASYNC_CLOSING) );
1545 /* check for signal */
1546 if (signal_pending(current)) {
1547 rc = (( pCh->flags & ASYNC_HUP_NOTIFY ) ? -EAGAIN : -ERESTARTSYS);
1552 set_current_state( TASK_RUNNING );
1553 remove_wait_queue(&pCh->open_wait, &wait);
1555 --pCh->wopen; //why count?
1557 ip2trace (CHANN, ITRC_OPEN, 4, 0 );
1562 pCh->flags |= ASYNC_NORMAL_ACTIVE;
1566 /* first open - Assign termios structure to port */
1567 if ( tty->count == 1 ) {
1568 i2QueueCommands(PTYPE_INLINE, pCh, 0, 2, CMD_CTSFL_DSAB, CMD_RTSFL_DSAB);
1569 /* Now we must send the termios settings to the loadware */
1570 set_params( pCh, NULL );
1574 * Now set any i2lib options. These may go away if the i2lib code ends
1575 * up rolled into the mainline.
1577 pCh->channelOptions |= CO_NBLOCK_WRITE;
1579 #ifdef IP2DEBUG_OPEN
1580 printk (KERN_DEBUG "IP2: open completed\n" );
1582 serviceOutgoingFifo( pCh->pMyBord );
1584 ip2trace (CHANN, ITRC_OPEN, ITRC_RETURN, 0 );
1589 /******************************************************************************/
1590 /* Function: ip2_close() */
1591 /* Parameters: Pointer to tty structure */
1592 /* Pointer to file structure */
1593 /* Returns: Nothing */
1598 /******************************************************************************/
1600 ip2_close( PTTY tty, struct file *pFile )
1602 i2ChanStrPtr pCh = tty->driver_data;
1608 ip2trace (CHANN, ITRC_CLOSE, ITRC_ENTER, 0 );
1610 #ifdef IP2DEBUG_OPEN
1611 printk(KERN_DEBUG "IP2:close %s:\n",tty->name);
1614 if ( tty_hung_up_p ( pFile ) ) {
1616 ip2trace (CHANN, ITRC_CLOSE, 2, 1, 2 );
1620 if ( tty->count > 1 ) { /* not the last close */
1622 ip2trace (CHANN, ITRC_CLOSE, 2, 1, 3 );
1626 pCh->flags |= ASYNC_CLOSING; // last close actually
1630 if (pCh->ClosingWaitTime != ASYNC_CLOSING_WAIT_NONE) {
1632 * Before we drop DTR, make sure the transmitter has completely drained.
1633 * This uses an timeout, after which the close
1636 ip2_wait_until_sent(tty, pCh->ClosingWaitTime );
1639 * At this point we stop accepting input. Here we flush the channel
1640 * input buffer which will allow the board to send up more data. Any
1641 * additional input is tossed at interrupt/poll time.
1643 i2InputFlush( pCh );
1645 /* disable DSS reporting */
1646 i2QueueCommands(PTYPE_INLINE, pCh, 100, 4,
1647 CMD_DCD_NREP, CMD_CTS_NREP, CMD_DSR_NREP, CMD_RI_NREP);
1648 if ( !tty || (tty->termios->c_cflag & HUPCL) ) {
1649 i2QueueCommands(PTYPE_INLINE, pCh, 100, 2, CMD_RTSDN, CMD_DTRDN);
1650 pCh->dataSetOut &= ~(I2_DTR | I2_RTS);
1651 i2QueueCommands( PTYPE_INLINE, pCh, 100, 1, CMD_PAUSE(25));
1654 serviceOutgoingFifo ( pCh->pMyBord );
1656 tty_ldisc_flush(tty);
1657 tty_driver_flush_buffer(tty);
1663 if (pCh->ClosingDelay) {
1664 msleep_interruptible(jiffies_to_msecs(pCh->ClosingDelay));
1666 wake_up_interruptible(&pCh->open_wait);
1669 pCh->flags &=~(ASYNC_NORMAL_ACTIVE|ASYNC_CLOSING);
1670 wake_up_interruptible(&pCh->close_wait);
1672 #ifdef IP2DEBUG_OPEN
1673 DBG_CNT("ip2_close: after wakeups--");
1677 ip2trace (CHANN, ITRC_CLOSE, ITRC_RETURN, 1, 1 );
1682 /******************************************************************************/
1683 /* Function: ip2_hangup() */
1684 /* Parameters: Pointer to tty structure */
1685 /* Returns: Nothing */
1690 /******************************************************************************/
1692 ip2_hangup ( PTTY tty )
1694 i2ChanStrPtr pCh = tty->driver_data;
1700 ip2trace (CHANN, ITRC_HANGUP, ITRC_ENTER, 0 );
1702 ip2_flush_buffer(tty);
1704 /* disable DSS reporting */
1706 i2QueueCommands(PTYPE_BYPASS, pCh, 0, 1, CMD_DCD_NREP);
1707 i2QueueCommands(PTYPE_INLINE, pCh, 0, 2, CMD_CTSFL_DSAB, CMD_RTSFL_DSAB);
1708 if ( (tty->termios->c_cflag & HUPCL) ) {
1709 i2QueueCommands(PTYPE_BYPASS, pCh, 0, 2, CMD_RTSDN, CMD_DTRDN);
1710 pCh->dataSetOut &= ~(I2_DTR | I2_RTS);
1711 i2QueueCommands( PTYPE_INLINE, pCh, 100, 1, CMD_PAUSE(25));
1713 i2QueueCommands(PTYPE_INLINE, pCh, 1, 3,
1714 CMD_CTS_NREP, CMD_DSR_NREP, CMD_RI_NREP);
1715 serviceOutgoingFifo ( pCh->pMyBord );
1717 wake_up_interruptible ( &pCh->delta_msr_wait );
1719 pCh->flags &= ~ASYNC_NORMAL_ACTIVE;
1721 wake_up_interruptible ( &pCh->open_wait );
1723 ip2trace (CHANN, ITRC_HANGUP, ITRC_RETURN, 0 );
1726 /******************************************************************************/
1727 /******************************************************************************/
1728 /* Device Output Section */
1729 /******************************************************************************/
1730 /******************************************************************************/
1732 /******************************************************************************/
1733 /* Function: ip2_write() */
1734 /* Parameters: Pointer to tty structure */
1735 /* Flag denoting data is in user (1) or kernel (0) space */
1736 /* Pointer to data */
1737 /* Number of bytes to write */
1738 /* Returns: Number of bytes actually written */
1740 /* Description: (MANDATORY) */
1743 /******************************************************************************/
1745 ip2_write( PTTY tty, const unsigned char *pData, int count)
1747 i2ChanStrPtr pCh = tty->driver_data;
1749 unsigned long flags;
1751 ip2trace (CHANN, ITRC_WRITE, ITRC_ENTER, 2, count, -1 );
1753 /* Flush out any buffered data left over from ip2_putchar() calls. */
1754 ip2_flush_chars( tty );
1756 /* This is the actual move bit. Make sure it does what we need!!!!! */
1757 write_lock_irqsave(&pCh->Pbuf_spinlock, flags);
1758 bytesSent = i2Output( pCh, pData, count);
1759 write_unlock_irqrestore(&pCh->Pbuf_spinlock, flags);
1761 ip2trace (CHANN, ITRC_WRITE, ITRC_RETURN, 1, bytesSent );
1763 return bytesSent > 0 ? bytesSent : 0;
1766 /******************************************************************************/
1767 /* Function: ip2_putchar() */
1768 /* Parameters: Pointer to tty structure */
1769 /* Character to write */
1770 /* Returns: Nothing */
1775 /******************************************************************************/
1777 ip2_putchar( PTTY tty, unsigned char ch )
1779 i2ChanStrPtr pCh = tty->driver_data;
1780 unsigned long flags;
1782 // ip2trace (CHANN, ITRC_PUTC, ITRC_ENTER, 1, ch );
1784 write_lock_irqsave(&pCh->Pbuf_spinlock, flags);
1785 pCh->Pbuf[pCh->Pbuf_stuff++] = ch;
1786 if ( pCh->Pbuf_stuff == sizeof pCh->Pbuf ) {
1787 write_unlock_irqrestore(&pCh->Pbuf_spinlock, flags);
1788 ip2_flush_chars( tty );
1790 write_unlock_irqrestore(&pCh->Pbuf_spinlock, flags);
1793 // ip2trace (CHANN, ITRC_PUTC, ITRC_RETURN, 1, ch );
1796 /******************************************************************************/
1797 /* Function: ip2_flush_chars() */
1798 /* Parameters: Pointer to tty structure */
1799 /* Returns: Nothing */
1803 /******************************************************************************/
1805 ip2_flush_chars( PTTY tty )
1808 i2ChanStrPtr pCh = tty->driver_data;
1809 unsigned long flags;
1811 write_lock_irqsave(&pCh->Pbuf_spinlock, flags);
1812 if ( pCh->Pbuf_stuff ) {
1814 // ip2trace (CHANN, ITRC_PUTC, 10, 1, strip );
1817 // We may need to restart i2Output if it does not fullfill this request
1819 strip = i2Output( pCh, pCh->Pbuf, pCh->Pbuf_stuff);
1820 if ( strip != pCh->Pbuf_stuff ) {
1821 memmove( pCh->Pbuf, &pCh->Pbuf[strip], pCh->Pbuf_stuff - strip );
1823 pCh->Pbuf_stuff -= strip;
1825 write_unlock_irqrestore(&pCh->Pbuf_spinlock, flags);
1828 /******************************************************************************/
1829 /* Function: ip2_write_room() */
1830 /* Parameters: Pointer to tty structure */
1831 /* Returns: Number of bytes that the driver can accept */
1835 /******************************************************************************/
1837 ip2_write_room ( PTTY tty )
1840 i2ChanStrPtr pCh = tty->driver_data;
1841 unsigned long flags;
1843 read_lock_irqsave(&pCh->Pbuf_spinlock, flags);
1844 bytesFree = i2OutputFree( pCh ) - pCh->Pbuf_stuff;
1845 read_unlock_irqrestore(&pCh->Pbuf_spinlock, flags);
1847 ip2trace (CHANN, ITRC_WRITE, 11, 1, bytesFree );
1849 return ((bytesFree > 0) ? bytesFree : 0);
1852 /******************************************************************************/
1853 /* Function: ip2_chars_in_buf() */
1854 /* Parameters: Pointer to tty structure */
1855 /* Returns: Number of bytes queued for transmission */
1860 /******************************************************************************/
1862 ip2_chars_in_buf ( PTTY tty )
1864 i2ChanStrPtr pCh = tty->driver_data;
1866 unsigned long flags;
1868 ip2trace (CHANN, ITRC_WRITE, 12, 1, pCh->Obuf_char_count + pCh->Pbuf_stuff );
1870 #ifdef IP2DEBUG_WRITE
1871 printk (KERN_DEBUG "IP2: chars in buffer = %d (%d,%d)\n",
1872 pCh->Obuf_char_count + pCh->Pbuf_stuff,
1873 pCh->Obuf_char_count, pCh->Pbuf_stuff );
1875 read_lock_irqsave(&pCh->Obuf_spinlock, flags);
1876 rc = pCh->Obuf_char_count;
1877 read_unlock_irqrestore(&pCh->Obuf_spinlock, flags);
1878 read_lock_irqsave(&pCh->Pbuf_spinlock, flags);
1879 rc += pCh->Pbuf_stuff;
1880 read_unlock_irqrestore(&pCh->Pbuf_spinlock, flags);
1884 /******************************************************************************/
1885 /* Function: ip2_flush_buffer() */
1886 /* Parameters: Pointer to tty structure */
1887 /* Returns: Nothing */
1892 /******************************************************************************/
1894 ip2_flush_buffer( PTTY tty )
1896 i2ChanStrPtr pCh = tty->driver_data;
1897 unsigned long flags;
1899 ip2trace (CHANN, ITRC_FLUSH, ITRC_ENTER, 0 );
1901 #ifdef IP2DEBUG_WRITE
1902 printk (KERN_DEBUG "IP2: flush buffer\n" );
1904 write_lock_irqsave(&pCh->Pbuf_spinlock, flags);
1905 pCh->Pbuf_stuff = 0;
1906 write_unlock_irqrestore(&pCh->Pbuf_spinlock, flags);
1907 i2FlushOutput( pCh );
1910 ip2trace (CHANN, ITRC_FLUSH, ITRC_RETURN, 0 );
1914 /******************************************************************************/
1915 /* Function: ip2_wait_until_sent() */
1916 /* Parameters: Pointer to tty structure */
1917 /* Timeout for wait. */
1918 /* Returns: Nothing */
1921 /* This function is used in place of the normal tty_wait_until_sent, which */
1922 /* only waits for the driver buffers to be empty (or rather, those buffers */
1923 /* reported by chars_in_buffer) which doesn't work for IP2 due to the */
1924 /* indeterminate number of bytes buffered on the board. */
1925 /******************************************************************************/
1927 ip2_wait_until_sent ( PTTY tty, int timeout )
1930 i2ChanStrPtr pCh = tty->driver_data;
1932 tty_wait_until_sent(tty, timeout );
1933 if ( (i = timeout - (jiffies -i)) > 0)
1934 i2DrainOutput( pCh, i );
1937 /******************************************************************************/
1938 /******************************************************************************/
1939 /* Device Input Section */
1940 /******************************************************************************/
1941 /******************************************************************************/
1943 /******************************************************************************/
1944 /* Function: ip2_throttle() */
1945 /* Parameters: Pointer to tty structure */
1946 /* Returns: Nothing */
1951 /******************************************************************************/
1953 ip2_throttle ( PTTY tty )
1955 i2ChanStrPtr pCh = tty->driver_data;
1957 #ifdef IP2DEBUG_READ
1958 printk (KERN_DEBUG "IP2: throttle\n" );
1961 * Signal the poll/interrupt handlers not to forward incoming data to
1962 * the line discipline. This will cause the buffers to fill up in the
1963 * library and thus cause the library routines to send the flow control
1969 /******************************************************************************/
1970 /* Function: ip2_unthrottle() */
1971 /* Parameters: Pointer to tty structure */
1972 /* Returns: Nothing */
1977 /******************************************************************************/
1979 ip2_unthrottle ( PTTY tty )
1981 i2ChanStrPtr pCh = tty->driver_data;
1982 unsigned long flags;
1984 #ifdef IP2DEBUG_READ
1985 printk (KERN_DEBUG "IP2: unthrottle\n" );
1988 /* Pass incoming data up to the line discipline again. */
1990 i2QueueCommands(PTYPE_BYPASS, pCh, 0, 1, CMD_RESUME);
1991 serviceOutgoingFifo( pCh->pMyBord );
1992 read_lock_irqsave(&pCh->Ibuf_spinlock, flags);
1993 if ( pCh->Ibuf_stuff != pCh->Ibuf_strip ) {
1994 read_unlock_irqrestore(&pCh->Ibuf_spinlock, flags);
1995 #ifdef IP2DEBUG_READ
1996 printk (KERN_DEBUG "i2Input called from unthrottle\n" );
2000 read_unlock_irqrestore(&pCh->Ibuf_spinlock, flags);
2004 ip2_start ( PTTY tty )
2006 i2ChanStrPtr pCh = DevTable[tty->index];
2008 i2QueueCommands(PTYPE_BYPASS, pCh, 0, 1, CMD_RESUME);
2009 i2QueueCommands(PTYPE_BYPASS, pCh, 100, 1, CMD_UNSUSPEND);
2010 i2QueueCommands(PTYPE_BYPASS, pCh, 100, 1, CMD_RESUME);
2011 #ifdef IP2DEBUG_WRITE
2012 printk (KERN_DEBUG "IP2: start tx\n" );
2017 ip2_stop ( PTTY tty )
2019 i2ChanStrPtr pCh = DevTable[tty->index];
2021 i2QueueCommands(PTYPE_BYPASS, pCh, 100, 1, CMD_SUSPEND);
2022 #ifdef IP2DEBUG_WRITE
2023 printk (KERN_DEBUG "IP2: stop tx\n" );
2027 /******************************************************************************/
2028 /* Device Ioctl Section */
2029 /******************************************************************************/
2031 static int ip2_tiocmget(struct tty_struct *tty, struct file *file)
2033 i2ChanStrPtr pCh = DevTable[tty->index];
2034 #ifdef ENABLE_DSSNOW
2042 FIXME - the following code is causing a NULL pointer dereference in
2043 2.3.51 in an interrupt handler. It's suppose to prompt the board
2044 to return the DSS signal status immediately. Why doesn't it do
2045 the same thing in 2.2.14?
2048 /* This thing is still busted in the 1.2.12 driver on 2.4.x
2049 and even hoses the serial console so the oops can be trapped.
2052 #ifdef ENABLE_DSSNOW
2053 i2QueueCommands(PTYPE_BYPASS, pCh, 100, 1, CMD_DSS_NOW);
2055 init_waitqueue_entry(&wait, current);
2056 add_wait_queue(&pCh->dss_now_wait, &wait);
2057 set_current_state( TASK_INTERRUPTIBLE );
2059 serviceOutgoingFifo( pCh->pMyBord );
2063 set_current_state( TASK_RUNNING );
2064 remove_wait_queue(&pCh->dss_now_wait, &wait);
2066 if (signal_pending(current)) {
2070 return ((pCh->dataSetOut & I2_RTS) ? TIOCM_RTS : 0)
2071 | ((pCh->dataSetOut & I2_DTR) ? TIOCM_DTR : 0)
2072 | ((pCh->dataSetIn & I2_DCD) ? TIOCM_CAR : 0)
2073 | ((pCh->dataSetIn & I2_RI) ? TIOCM_RNG : 0)
2074 | ((pCh->dataSetIn & I2_DSR) ? TIOCM_DSR : 0)
2075 | ((pCh->dataSetIn & I2_CTS) ? TIOCM_CTS : 0);
2078 static int ip2_tiocmset(struct tty_struct *tty, struct file *file,
2079 unsigned int set, unsigned int clear)
2081 i2ChanStrPtr pCh = DevTable[tty->index];
2086 if (set & TIOCM_RTS) {
2087 i2QueueCommands(PTYPE_INLINE, pCh, 100, 1, CMD_RTSUP);
2088 pCh->dataSetOut |= I2_RTS;
2090 if (set & TIOCM_DTR) {
2091 i2QueueCommands(PTYPE_INLINE, pCh, 100, 1, CMD_DTRUP);
2092 pCh->dataSetOut |= I2_DTR;
2095 if (clear & TIOCM_RTS) {
2096 i2QueueCommands(PTYPE_INLINE, pCh, 100, 1, CMD_RTSDN);
2097 pCh->dataSetOut &= ~I2_RTS;
2099 if (clear & TIOCM_DTR) {
2100 i2QueueCommands(PTYPE_INLINE, pCh, 100, 1, CMD_DTRDN);
2101 pCh->dataSetOut &= ~I2_DTR;
2103 serviceOutgoingFifo( pCh->pMyBord );
2107 /******************************************************************************/
2108 /* Function: ip2_ioctl() */
2109 /* Parameters: Pointer to tty structure */
2110 /* Pointer to file structure */
2113 /* Returns: Success or failure */
2118 /******************************************************************************/
2120 ip2_ioctl ( PTTY tty, struct file *pFile, UINT cmd, ULONG arg )
2123 i2ChanStrPtr pCh = DevTable[tty->index];
2125 struct async_icount cprev, cnow; /* kernel counter temps */
2126 struct serial_icounter_struct __user *p_cuser;
2128 unsigned long flags;
2129 void __user *argp = (void __user *)arg;
2136 ip2trace (CHANN, ITRC_IOCTL, ITRC_ENTER, 2, cmd, arg );
2138 #ifdef IP2DEBUG_IOCTL
2139 printk(KERN_DEBUG "IP2: ioctl cmd (%x), arg (%lx)\n", cmd, arg );
2145 ip2trace (CHANN, ITRC_IOCTL, 2, 1, rc );
2147 rc = get_serial_info(pCh, argp);
2154 ip2trace (CHANN, ITRC_IOCTL, 3, 1, rc );
2156 rc = set_serial_info(pCh, argp);
2162 rc = tty_check_change(tty);
2167 //return -ENOIOCTLCMD;
2170 //return -ENOIOCTLCMD;
2173 if (STOP_CHAR(tty) != __DISABLED_CHAR) {
2174 i2QueueCommands( PTYPE_BYPASS, pCh, 100, 1,
2175 CMD_XMIT_NOW(STOP_CHAR(tty)));
2179 if (START_CHAR(tty) != __DISABLED_CHAR) {
2180 i2QueueCommands( PTYPE_BYPASS, pCh, 100, 1,
2181 CMD_XMIT_NOW(START_CHAR(tty)));
2189 case TCSBRK: /* SVID version: non-zero arg --> no break */
2190 rc = tty_check_change(tty);
2192 ip2trace (CHANN, ITRC_IOCTL, 4, 1, rc );
2195 ip2_wait_until_sent(tty,0);
2197 i2QueueCommands(PTYPE_INLINE, pCh, 100, 1, CMD_SEND_BRK(250));
2198 serviceOutgoingFifo( pCh->pMyBord );
2203 case TCSBRKP: /* support for POSIX tcsendbreak() */
2204 rc = tty_check_change(tty);
2206 ip2trace (CHANN, ITRC_IOCTL, 5, 1, rc );
2209 ip2_wait_until_sent(tty,0);
2210 i2QueueCommands(PTYPE_INLINE, pCh, 100, 1,
2211 CMD_SEND_BRK(arg ? arg*100 : 250));
2212 serviceOutgoingFifo ( pCh->pMyBord );
2218 ip2trace (CHANN, ITRC_IOCTL, 6, 1, rc );
2220 rc = put_user(C_CLOCAL(tty) ? 1 : 0, (unsigned long __user *)argp);
2227 ip2trace (CHANN, ITRC_IOCTL, 7, 1, rc );
2229 rc = get_user(arg,(unsigned long __user *) argp);
2232 tty->termios->c_cflag = ((tty->termios->c_cflag & ~CLOCAL)
2233 | (arg ? CLOCAL : 0));
2238 * Wait for any of the 4 modem inputs (DCD,RI,DSR,CTS) to change - mask
2239 * passed in arg for lines of interest (use |'ed TIOCM_RNG/DSR/CD/CTS
2240 * for masking). Caller should use TIOCGICOUNT to see which one it was
2243 write_lock_irqsave(&pB->read_fifo_spinlock, flags);
2244 cprev = pCh->icount; /* note the counters on entry */
2245 write_unlock_irqrestore(&pB->read_fifo_spinlock, flags);
2246 i2QueueCommands(PTYPE_BYPASS, pCh, 100, 4,
2247 CMD_DCD_REP, CMD_CTS_REP, CMD_DSR_REP, CMD_RI_REP);
2248 init_waitqueue_entry(&wait, current);
2249 add_wait_queue(&pCh->delta_msr_wait, &wait);
2250 set_current_state( TASK_INTERRUPTIBLE );
2252 serviceOutgoingFifo( pCh->pMyBord );
2254 ip2trace (CHANN, ITRC_IOCTL, 10, 0 );
2258 ip2trace (CHANN, ITRC_IOCTL, 11, 0 );
2260 /* see if a signal did it */
2261 if (signal_pending(current)) {
2265 write_lock_irqsave(&pB->read_fifo_spinlock, flags);
2266 cnow = pCh->icount; /* atomic copy */
2267 write_unlock_irqrestore(&pB->read_fifo_spinlock, flags);
2268 if (cnow.rng == cprev.rng && cnow.dsr == cprev.dsr &&
2269 cnow.dcd == cprev.dcd && cnow.cts == cprev.cts) {
2270 rc = -EIO; /* no change => rc */
2273 if (((arg & TIOCM_RNG) && (cnow.rng != cprev.rng)) ||
2274 ((arg & TIOCM_DSR) && (cnow.dsr != cprev.dsr)) ||
2275 ((arg & TIOCM_CD) && (cnow.dcd != cprev.dcd)) ||
2276 ((arg & TIOCM_CTS) && (cnow.cts != cprev.cts)) ) {
2282 set_current_state( TASK_RUNNING );
2283 remove_wait_queue(&pCh->delta_msr_wait, &wait);
2285 i2QueueCommands(PTYPE_BYPASS, pCh, 100, 3,
2286 CMD_CTS_NREP, CMD_DSR_NREP, CMD_RI_NREP);
2287 if ( ! (pCh->flags & ASYNC_CHECK_CD)) {
2288 i2QueueCommands(PTYPE_BYPASS, pCh, 100, 1, CMD_DCD_NREP);
2290 serviceOutgoingFifo( pCh->pMyBord );
2295 * Get counter of input serial line interrupts (DCD,RI,DSR,CTS)
2296 * Return: write counters to the user passed counter struct
2297 * NB: both 1->0 and 0->1 transitions are counted except for RI where
2298 * only 0->1 is counted. The controller is quite capable of counting
2299 * both, but this done to preserve compatibility with the standard
2303 ip2trace (CHANN, ITRC_IOCTL, 11, 1, rc );
2305 write_lock_irqsave(&pB->read_fifo_spinlock, flags);
2307 write_unlock_irqrestore(&pB->read_fifo_spinlock, flags);
2309 rc = put_user(cnow.cts, &p_cuser->cts);
2310 rc = put_user(cnow.dsr, &p_cuser->dsr);
2311 rc = put_user(cnow.rng, &p_cuser->rng);
2312 rc = put_user(cnow.dcd, &p_cuser->dcd);
2313 rc = put_user(cnow.rx, &p_cuser->rx);
2314 rc = put_user(cnow.tx, &p_cuser->tx);
2315 rc = put_user(cnow.frame, &p_cuser->frame);
2316 rc = put_user(cnow.overrun, &p_cuser->overrun);
2317 rc = put_user(cnow.parity, &p_cuser->parity);
2318 rc = put_user(cnow.brk, &p_cuser->brk);
2319 rc = put_user(cnow.buf_overrun, &p_cuser->buf_overrun);
2323 * The rest are not supported by this driver. By returning -ENOIOCTLCMD they
2324 * will be passed to the line discipline for it to handle.
2330 case TIOCSERGSTRUCT:
2331 case TIOCSERGETMULTI:
2332 case TIOCSERSETMULTI:
2335 ip2trace (CHANN, ITRC_IOCTL, 12, 0 );
2341 ip2trace (CHANN, ITRC_IOCTL, ITRC_RETURN, 0 );
2346 /******************************************************************************/
2347 /* Function: GetSerialInfo() */
2348 /* Parameters: Pointer to channel structure */
2349 /* Pointer to old termios structure */
2350 /* Returns: Nothing */
2353 /* This is to support the setserial command, and requires processing of the */
2354 /* standard Linux serial structure. */
2355 /******************************************************************************/
2357 get_serial_info ( i2ChanStrPtr pCh, struct serial_struct __user *retinfo )
2359 struct serial_struct tmp;
2361 memset ( &tmp, 0, sizeof(tmp) );
2362 tmp.type = pCh->pMyBord->channelBtypes.bid_value[(pCh->port_index & (IP2_PORTS_PER_BOARD-1))/16];
2363 if (BID_HAS_654(tmp.type)) {
2364 tmp.type = PORT_16650;
2366 tmp.type = PORT_CIRRUS;
2368 tmp.line = pCh->port_index;
2369 tmp.port = pCh->pMyBord->i2eBase;
2370 tmp.irq = ip2config.irq[pCh->port_index/64];
2371 tmp.flags = pCh->flags;
2372 tmp.baud_base = pCh->BaudBase;
2373 tmp.close_delay = pCh->ClosingDelay;
2374 tmp.closing_wait = pCh->ClosingWaitTime;
2375 tmp.custom_divisor = pCh->BaudDivisor;
2376 return copy_to_user(retinfo,&tmp,sizeof(*retinfo));
2379 /******************************************************************************/
2380 /* Function: SetSerialInfo() */
2381 /* Parameters: Pointer to channel structure */
2382 /* Pointer to old termios structure */
2383 /* Returns: Nothing */
2386 /* This function provides support for setserial, which uses the TIOCSSERIAL */
2387 /* ioctl. Not all setserial parameters are relevant. If the user attempts to */
2388 /* change the IRQ, address or type of the port the ioctl fails. */
2389 /******************************************************************************/
2391 set_serial_info( i2ChanStrPtr pCh, struct serial_struct __user *new_info )
2393 struct serial_struct ns;
2394 int old_flags, old_baud_divisor;
2396 if (copy_from_user(&ns, new_info, sizeof (ns)))
2400 * We don't allow setserial to change IRQ, board address, type or baud
2401 * base. Also line nunber as such is meaningless but we use it for our
2402 * array index so it is fixed also.
2404 if ( (ns.irq != ip2config.irq[pCh->port_index])
2405 || ((int) ns.port != ((int) (pCh->pMyBord->i2eBase)))
2406 || (ns.baud_base != pCh->BaudBase)
2407 || (ns.line != pCh->port_index) ) {
2411 old_flags = pCh->flags;
2412 old_baud_divisor = pCh->BaudDivisor;
2414 if ( !capable(CAP_SYS_ADMIN) ) {
2415 if ( ( ns.close_delay != pCh->ClosingDelay ) ||
2416 ( (ns.flags & ~ASYNC_USR_MASK) !=
2417 (pCh->flags & ~ASYNC_USR_MASK) ) ) {
2421 pCh->flags = (pCh->flags & ~ASYNC_USR_MASK) |
2422 (ns.flags & ASYNC_USR_MASK);
2423 pCh->BaudDivisor = ns.custom_divisor;
2425 pCh->flags = (pCh->flags & ~ASYNC_FLAGS) |
2426 (ns.flags & ASYNC_FLAGS);
2427 pCh->BaudDivisor = ns.custom_divisor;
2428 pCh->ClosingDelay = ns.close_delay * HZ/100;
2429 pCh->ClosingWaitTime = ns.closing_wait * HZ/100;
2432 if ( ( (old_flags & ASYNC_SPD_MASK) != (pCh->flags & ASYNC_SPD_MASK) )
2433 || (old_baud_divisor != pCh->BaudDivisor) ) {
2434 // Invalidate speed and reset parameters
2435 set_params( pCh, NULL );
2441 /******************************************************************************/
2442 /* Function: ip2_set_termios() */
2443 /* Parameters: Pointer to tty structure */
2444 /* Pointer to old termios structure */
2445 /* Returns: Nothing */
2450 /******************************************************************************/
2452 ip2_set_termios( PTTY tty, struct ktermios *old_termios )
2454 i2ChanStrPtr pCh = (i2ChanStrPtr)tty->driver_data;
2456 #ifdef IP2DEBUG_IOCTL
2457 printk (KERN_DEBUG "IP2: set termios %p\n", old_termios );
2460 set_params( pCh, old_termios );
2463 /******************************************************************************/
2464 /* Function: ip2_set_line_discipline() */
2465 /* Parameters: Pointer to tty structure */
2466 /* Returns: Nothing */
2468 /* Description: Does nothing */
2471 /******************************************************************************/
2473 ip2_set_line_discipline ( PTTY tty )
2475 #ifdef IP2DEBUG_IOCTL
2476 printk (KERN_DEBUG "IP2: set line discipline\n" );
2479 ip2trace (((i2ChanStrPtr)tty->driver_data)->port_index, ITRC_IOCTL, 16, 0 );
2483 /******************************************************************************/
2484 /* Function: SetLine Characteristics() */
2485 /* Parameters: Pointer to channel structure */
2486 /* Returns: Nothing */
2489 /* This routine is called to update the channel structure with the new line */
2490 /* characteristics, and send the appropriate commands to the board when they */
2492 /******************************************************************************/
2494 set_params( i2ChanStrPtr pCh, struct ktermios *o_tios )
2496 tcflag_t cflag, iflag, lflag;
2497 char stop_char, start_char;
2498 struct ktermios dummy;
2500 lflag = pCh->pTTY->termios->c_lflag;
2501 cflag = pCh->pTTY->termios->c_cflag;
2502 iflag = pCh->pTTY->termios->c_iflag;
2504 if (o_tios == NULL) {
2505 dummy.c_lflag = ~lflag;
2506 dummy.c_cflag = ~cflag;
2507 dummy.c_iflag = ~iflag;
2512 switch ( cflag & CBAUD ) {
2514 i2QueueCommands( PTYPE_BYPASS, pCh, 100, 2, CMD_RTSDN, CMD_DTRDN);
2515 pCh->dataSetOut &= ~(I2_DTR | I2_RTS);
2516 i2QueueCommands( PTYPE_INLINE, pCh, 100, 1, CMD_PAUSE(25));
2517 pCh->pTTY->termios->c_cflag |= (CBAUD & o_tios->c_cflag);
2522 * This is the speed that is overloaded with all the other high
2523 * speeds, depending upon the flag settings.
2525 if ( ( pCh->flags & ASYNC_SPD_MASK ) == ASYNC_SPD_HI ) {
2526 pCh->speed = CBR_57600;
2527 } else if ( (pCh->flags & ASYNC_SPD_MASK) == ASYNC_SPD_VHI ) {
2528 pCh->speed = CBR_115200;
2529 } else if ( (pCh->flags & ASYNC_SPD_MASK) == ASYNC_SPD_CUST ) {
2530 pCh->speed = CBR_C1;
2532 pCh->speed = CBR_38400;
2535 case B50: pCh->speed = CBR_50; break;
2536 case B75: pCh->speed = CBR_75; break;
2537 case B110: pCh->speed = CBR_110; break;
2538 case B134: pCh->speed = CBR_134; break;
2539 case B150: pCh->speed = CBR_150; break;
2540 case B200: pCh->speed = CBR_200; break;
2541 case B300: pCh->speed = CBR_300; break;
2542 case B600: pCh->speed = CBR_600; break;
2543 case B1200: pCh->speed = CBR_1200; break;
2544 case B1800: pCh->speed = CBR_1800; break;
2545 case B2400: pCh->speed = CBR_2400; break;
2546 case B4800: pCh->speed = CBR_4800; break;
2547 case B9600: pCh->speed = CBR_9600; break;
2548 case B19200: pCh->speed = CBR_19200; break;
2549 case B57600: pCh->speed = CBR_57600; break;
2550 case B115200: pCh->speed = CBR_115200; break;
2551 case B153600: pCh->speed = CBR_153600; break;
2552 case B230400: pCh->speed = CBR_230400; break;
2553 case B307200: pCh->speed = CBR_307200; break;
2554 case B460800: pCh->speed = CBR_460800; break;
2555 case B921600: pCh->speed = CBR_921600; break;
2556 default: pCh->speed = CBR_9600; break;
2558 if ( pCh->speed == CBR_C1 ) {
2559 // Process the custom speed parameters.
2560 int bps = pCh->BaudBase / pCh->BaudDivisor;
2561 if ( bps == 921600 ) {
2562 pCh->speed = CBR_921600;
2565 i2QueueCommands( PTYPE_INLINE, pCh, 100, 1, CMD_BAUD_DEF1(bps) );
2568 i2QueueCommands( PTYPE_INLINE, pCh, 100, 1, CMD_SETBAUD(pCh->speed));
2570 i2QueueCommands ( PTYPE_INLINE, pCh, 100, 2, CMD_DTRUP, CMD_RTSUP);
2571 pCh->dataSetOut |= (I2_DTR | I2_RTS);
2573 if ( (CSTOPB & cflag) ^ (CSTOPB & o_tios->c_cflag))
2575 i2QueueCommands ( PTYPE_INLINE, pCh, 100, 1,
2576 CMD_SETSTOP( ( cflag & CSTOPB ) ? CST_2 : CST_1));
2578 if (((PARENB|PARODD) & cflag) ^ ((PARENB|PARODD) & o_tios->c_cflag))
2580 i2QueueCommands ( PTYPE_INLINE, pCh, 100, 1,
2582 (cflag & PARENB ? (cflag & PARODD ? CSP_OD : CSP_EV) : CSP_NP)
2586 /* byte size and parity */
2587 if ( (CSIZE & cflag)^(CSIZE & o_tios->c_cflag))
2590 switch ( cflag & CSIZE ) {
2591 case CS5: datasize = CSZ_5; break;
2592 case CS6: datasize = CSZ_6; break;
2593 case CS7: datasize = CSZ_7; break;
2594 case CS8: datasize = CSZ_8; break;
2595 default: datasize = CSZ_5; break; /* as per serial.c */
2597 i2QueueCommands ( PTYPE_INLINE, pCh, 100, 1, CMD_SETBITS(datasize) );
2599 /* Process CTS flow control flag setting */
2600 if ( (cflag & CRTSCTS) ) {
2601 i2QueueCommands(PTYPE_INLINE, pCh, 100,
2602 2, CMD_CTSFL_ENAB, CMD_RTSFL_ENAB);
2604 i2QueueCommands(PTYPE_INLINE, pCh, 100,
2605 2, CMD_CTSFL_DSAB, CMD_RTSFL_DSAB);
2608 // Process XON/XOFF flow control flags settings
2610 stop_char = STOP_CHAR(pCh->pTTY);
2611 start_char = START_CHAR(pCh->pTTY);
2613 //////////// can't be \000
2614 if (stop_char == __DISABLED_CHAR )
2616 stop_char = ~__DISABLED_CHAR;
2618 if (start_char == __DISABLED_CHAR )
2620 start_char = ~__DISABLED_CHAR;
2622 /////////////////////////////////
2624 if ( o_tios->c_cc[VSTART] != start_char )
2626 i2QueueCommands(PTYPE_BYPASS, pCh, 100, 1, CMD_DEF_IXON(start_char));
2627 i2QueueCommands(PTYPE_INLINE, pCh, 100, 1, CMD_DEF_OXON(start_char));
2629 if ( o_tios->c_cc[VSTOP] != stop_char )
2631 i2QueueCommands(PTYPE_BYPASS, pCh, 100, 1, CMD_DEF_IXOFF(stop_char));
2632 i2QueueCommands(PTYPE_INLINE, pCh, 100, 1, CMD_DEF_OXOFF(stop_char));
2634 if (stop_char == __DISABLED_CHAR )
2636 stop_char = ~__DISABLED_CHAR; //TEST123
2639 if ((iflag & (IXOFF))^(o_tios->c_iflag & (IXOFF)))
2641 if ( iflag & IXOFF ) { // Enable XOFF output flow control
2642 i2QueueCommands(PTYPE_INLINE, pCh, 100, 1, CMD_OXON_OPT(COX_XON));
2643 } else { // Disable XOFF output flow control
2645 i2QueueCommands(PTYPE_INLINE, pCh, 100, 1, CMD_OXON_OPT(COX_NONE));
2648 if (start_char == __DISABLED_CHAR )
2652 if ((iflag & (IXON|IXANY)) ^ (o_tios->c_iflag & (IXON|IXANY)))
2654 if ( iflag & IXON ) {
2655 if ( iflag & IXANY ) { // Enable XON/XANY output flow control
2656 i2QueueCommands(PTYPE_INLINE, pCh, 100, 1, CMD_IXON_OPT(CIX_XANY));
2657 } else { // Enable XON output flow control
2658 i2QueueCommands(PTYPE_INLINE, pCh, 100, 1, CMD_IXON_OPT(CIX_XON));
2660 } else { // Disable XON output flow control
2662 i2QueueCommands(PTYPE_INLINE, pCh, 100, 1, CMD_IXON_OPT(CIX_NONE));
2665 if ( (iflag & ISTRIP) ^ ( o_tios->c_iflag & (ISTRIP)) )
2667 i2QueueCommands(PTYPE_INLINE, pCh, 100, 1,
2668 CMD_ISTRIP_OPT((iflag & ISTRIP ? 1 : 0)));
2670 if ( (iflag & INPCK) ^ ( o_tios->c_iflag & (INPCK)) )
2672 i2QueueCommands(PTYPE_INLINE, pCh, 100, 1,
2673 CMD_PARCHK((iflag & INPCK) ? CPK_ENAB : CPK_DSAB));
2676 if ( (iflag & (IGNBRK|PARMRK|BRKINT|IGNPAR))
2677 ^ ( o_tios->c_iflag & (IGNBRK|PARMRK|BRKINT|IGNPAR)) )
2682 if ( iflag & IGNBRK ) { /* Ignore breaks altogether */
2683 /* Ignore breaks altogether */
2684 i2QueueCommands(PTYPE_INLINE, pCh, 100, 1, CMD_BRK_NREP);
2686 if ( iflag & BRKINT ) {
2687 if ( iflag & PARMRK ) {
2688 brkrpt = 0x0a; // exception an inline triple
2690 brkrpt = 0x1a; // exception and NULL
2692 brkrpt |= 0x04; // flush input
2694 if ( iflag & PARMRK ) {
2695 brkrpt = 0x0b; //POSIX triple \0377 \0 \0
2697 brkrpt = 0x01; // Null only
2700 i2QueueCommands(PTYPE_INLINE, pCh, 100, 1, CMD_BRK_REP(brkrpt));
2703 if (iflag & IGNPAR) {
2705 /* would be 2 for not cirrus bug */
2706 /* would be 0x20 cept for cirrus bug */
2708 if ( iflag & PARMRK ) {
2710 * Replace error characters with 3-byte sequence (\0377,\0,char)
2713 i2QueueCommands(PTYPE_INLINE, pCh, 100, 1, CMD_ISTRIP_OPT((char)0));
2718 i2QueueCommands(PTYPE_INLINE, pCh, 100, 1, CMD_SET_ERROR(parrpt));
2720 if (cflag & CLOCAL) {
2721 // Status reporting fails for DCD if this is off
2722 i2QueueCommands(PTYPE_INLINE, pCh, 100, 1, CMD_DCD_NREP);
2723 pCh->flags &= ~ASYNC_CHECK_CD;
2725 i2QueueCommands(PTYPE_INLINE, pCh, 100, 1, CMD_DCD_REP);
2726 pCh->flags |= ASYNC_CHECK_CD;
2730 i2DrainOutput( pCh, 100 );
2733 /******************************************************************************/
2734 /* IPL Device Section */
2735 /******************************************************************************/
2737 /******************************************************************************/
2738 /* Function: ip2_ipl_read() */
2739 /* Parameters: Pointer to device inode */
2740 /* Pointer to file structure */
2741 /* Pointer to data */
2742 /* Number of bytes to read */
2743 /* Returns: Success or failure */
2745 /* Description: Ugly */
2748 /******************************************************************************/
2752 ip2_ipl_read(struct file *pFile, char __user *pData, size_t count, loff_t *off )
2754 unsigned int minor = iminor(pFile->f_path.dentry->d_inode);
2758 printk (KERN_DEBUG "IP2IPL: read %p, %d bytes\n", pData, count );
2762 case 0: // IPL device
2765 case 1: // Status dump
2768 case 2: // Ping device
2771 case 3: // Trace device
2772 rc = DumpTraceBuffer ( pData, count );
2774 case 4: // Trace device
2775 rc = DumpFifoBuffer ( pData, count );
2785 DumpFifoBuffer ( char __user *pData, int count )
2789 rc = copy_to_user(pData, DBGBuf, count);
2791 printk(KERN_DEBUG "Last index %d\n", I );
2794 #endif /* DEBUG_FIFO */
2799 DumpTraceBuffer ( char __user *pData, int count )
2801 #ifdef IP2DEBUG_TRACE
2805 int *pIndex = (int __user *)pData;
2807 if ( count < (sizeof(int) * 6) ) {
2810 rc = put_user(tracewrap, pIndex );
2811 rc = put_user(TRACEMAX, ++pIndex );
2812 rc = put_user(tracestrip, ++pIndex );
2813 rc = put_user(tracestuff, ++pIndex );
2814 pData += sizeof(int) * 6;
2815 count -= sizeof(int) * 6;
2817 dumpcount = tracestuff - tracestrip;
2818 if ( dumpcount < 0 ) {
2819 dumpcount += TRACEMAX;
2821 if ( dumpcount > count ) {
2824 chunk = TRACEMAX - tracestrip;
2825 if ( dumpcount > chunk ) {
2826 rc = copy_to_user(pData, &tracebuf[tracestrip],
2827 chunk * sizeof(tracebuf[0]) );
2828 pData += chunk * sizeof(tracebuf[0]);
2830 chunk = dumpcount - chunk;
2834 rc = copy_to_user(pData, &tracebuf[tracestrip],
2835 chunk * sizeof(tracebuf[0]) );
2836 tracestrip += chunk;
2839 rc = put_user(tracestrip, ++pIndex );
2840 rc = put_user(tracestuff, ++pIndex );
2848 /******************************************************************************/
2849 /* Function: ip2_ipl_write() */
2851 /* Pointer to file structure */
2852 /* Pointer to data */
2853 /* Number of bytes to write */
2854 /* Returns: Success or failure */
2859 /******************************************************************************/
2861 ip2_ipl_write(struct file *pFile, const char __user *pData, size_t count, loff_t *off)
2864 printk (KERN_DEBUG "IP2IPL: write %p, %d bytes\n", pData, count );
2869 /******************************************************************************/
2870 /* Function: ip2_ipl_ioctl() */
2871 /* Parameters: Pointer to device inode */
2872 /* Pointer to file structure */
2875 /* Returns: Success or failure */
2880 /******************************************************************************/
2882 ip2_ipl_ioctl (struct file *pFile, UINT cmd, ULONG arg )
2884 unsigned int iplminor = iminor(pFile->f_path.dentry->d_inode);
2886 void __user *argp = (void __user *)arg;
2887 ULONG __user *pIndex = argp;
2888 i2eBordStrPtr pB = i2BoardPtrTable[iplminor / 4];
2892 printk (KERN_DEBUG "IP2IPL: ioctl cmd %d, arg %ld\n", cmd, arg );
2897 switch ( iplminor ) {
2898 case 0: // IPL device
2901 case 1: // Status dump
2906 case 64: /* Driver - ip2stat */
2907 rc = put_user(ip2_tty_driver->refcount, pIndex++ );
2908 rc = put_user(irq_counter, pIndex++ );
2909 rc = put_user(bh_counter, pIndex++ );
2912 case 65: /* Board - ip2stat */
2914 rc = copy_to_user(argp, pB, sizeof(i2eBordStr));
2915 rc = put_user(inb(pB->i2eStatus),
2916 (ULONG __user *)(arg + (ULONG)(&pB->i2eStatus) - (ULONG)pB ) );
2923 if (cmd < IP2_MAX_PORTS) {
2924 pCh = DevTable[cmd];
2927 rc = copy_to_user(argp, pCh, sizeof(i2ChanStr));
2937 case 2: // Ping device
2940 case 3: // Trace device
2942 * akpm: This used to write a whole bunch of function addresses
2943 * to userspace, which generated lots of put_user() warnings.
2944 * I killed it all. Just return "success" and don't do
2961 /******************************************************************************/
2962 /* Function: ip2_ipl_open() */
2963 /* Parameters: Pointer to device inode */
2964 /* Pointer to file structure */
2965 /* Returns: Success or failure */
2970 /******************************************************************************/
2972 ip2_ipl_open( struct inode *pInode, struct file *pFile )
2976 printk (KERN_DEBUG "IP2IPL: open\n" );
2978 cycle_kernel_lock();
2983 proc_ip2mem_show(struct seq_file *m, void *v)
2990 #define FMTLINE "%3d: 0x%08x 0x%08x 0%011o 0%011o\n"
2991 #define FMTLIN2 " 0x%04x 0x%04x tx flow 0x%x\n"
2992 #define FMTLIN3 " 0x%04x 0x%04x rc flow\n"
2996 for( i = 0; i < IP2_MAX_BOARDS; ++i ) {
2997 pB = i2BoardPtrTable[i];
2999 seq_printf(m,"board %d:\n",i);
3000 seq_printf(m,"\tFifo rem: %d mty: %x outM %x\n",
3001 pB->i2eFifoRemains,pB->i2eWaitingForEmptyFifo,pB->i2eOutMailWaiting);
3005 seq_printf(m,"#: tty flags, port flags, cflags, iflags\n");
3006 for (i=0; i < IP2_MAX_PORTS; i++) {
3010 if (tty && tty->count) {
3011 seq_printf(m,FMTLINE,i,(int)tty->flags,pCh->flags,
3012 tty->termios->c_cflag,tty->termios->c_iflag);
3014 seq_printf(m,FMTLIN2,
3015 pCh->outfl.asof,pCh->outfl.room,pCh->channelNeeds);
3016 seq_printf(m,FMTLIN3,pCh->infl.asof,pCh->infl.room);
3023 static int proc_ip2mem_open(struct inode *inode, struct file *file)
3025 return single_open(file, proc_ip2mem_show, NULL);
3028 static const struct file_operations ip2mem_proc_fops = {
3029 .owner = THIS_MODULE,
3030 .open = proc_ip2mem_open,
3032 .llseek = seq_lseek,
3033 .release = single_release,
3037 * This is the handler for /proc/tty/driver/ip2
3039 * This stretch of code has been largely plagerized from at least three
3040 * different sources including ip2mkdev.c and a couple of other drivers.
3041 * The bugs are all mine. :-) =mhw=
3043 static int ip2_read_proc(char *page, char **start, off_t off,
3044 int count, int *eof, void *data)
3054 len += sprintf(page, "ip2info: 1.0 driver: %s\n", pcVersion );
3055 len += sprintf(page+len, "Driver: SMajor=%d CMajor=%d IMajor=%d MaxBoards=%d MaxBoxes=%d MaxPorts=%d\n",
3056 IP2_TTY_MAJOR, IP2_CALLOUT_MAJOR, IP2_IPL_MAJOR,
3057 IP2_MAX_BOARDS, ABS_MAX_BOXES, ABS_BIGGEST_BOX);
3059 for( i = 0; i < IP2_MAX_BOARDS; ++i ) {
3060 /* This need to be reset for a board by board count... */
3062 pB = i2BoardPtrTable[i];
3064 switch( pB->i2ePom.e.porID & ~POR_ID_RESERVED )
3067 len += sprintf( page+len, "Board %d: EX ports=", i );
3068 for( box = 0; box < ABS_MAX_BOXES; ++box )
3072 if( pB->i2eChannelMap[box] != 0 ) ++boxes;
3073 for( j = 0; j < ABS_BIGGEST_BOX; ++j )
3075 if( pB->i2eChannelMap[box] & 1<< j ) {
3079 len += sprintf( page+len, "%d,", ports );
3083 --len; /* Backup over that last comma */
3085 len += sprintf( page+len, " boxes=%d width=%d", boxes, pB->i2eDataWidth16 ? 16 : 8 );
3089 len += sprintf(page+len, "Board %d: ISA-4 ports=4 boxes=1", i );
3094 len += sprintf(page+len, "Board %d: ISA-8-std ports=8 boxes=1", i );
3099 len += sprintf(page+len, "Board %d: ISA-8-RJ11 ports=8 boxes=1", i );
3104 len += sprintf(page+len, "Board %d: unknown", i );
3105 /* Don't try and probe for minor numbers */
3110 /* Don't try and probe for minor numbers */
3111 len += sprintf(page+len, "Board %d: vacant", i );
3116 len += sprintf(page+len, " minors=" );
3118 for ( box = 0; box < ABS_MAX_BOXES; ++box )
3120 for ( j = 0; j < ABS_BIGGEST_BOX; ++j )
3122 if ( pB->i2eChannelMap[box] & (1 << j) )
3124 len += sprintf (page+len,"%d,",
3125 j + ABS_BIGGEST_BOX *
3126 (box+i*ABS_MAX_BOXES));
3131 page[ len - 1 ] = '\n'; /* Overwrite that last comma */
3133 len += sprintf (page+len,"\n" );
3136 if (len+begin > off+count)
3138 if (len+begin < off) {
3144 if (i >= IP2_MAX_BOARDS)
3146 if (off >= len+begin)
3149 *start = page + (off-begin);
3150 return ((count < begin+len-off) ? count : begin+len-off);
3153 /******************************************************************************/
3154 /* Function: ip2trace() */
3155 /* Parameters: Value to add to trace buffer */
3156 /* Returns: Nothing */
3161 /******************************************************************************/
3162 #ifdef IP2DEBUG_TRACE
3164 ip2trace (unsigned short pn, unsigned char cat, unsigned char label, unsigned long codes, ...)
3167 unsigned long *pCode = &codes;
3168 union ip2breadcrumb bc;
3172 tracebuf[tracestuff++] = jiffies;
3173 if ( tracestuff == TRACEMAX ) {
3176 if ( tracestuff == tracestrip ) {
3177 if ( ++tracestrip == TRACEMAX ) {
3183 bc.hdr.port = 0xff & pn;
3185 bc.hdr.codes = (unsigned char)( codes & 0xff );
3186 bc.hdr.label = label;
3187 tracebuf[tracestuff++] = bc.value;
3190 if ( tracestuff == TRACEMAX ) {
3193 if ( tracestuff == tracestrip ) {
3194 if ( ++tracestrip == TRACEMAX ) {
3203 tracebuf[tracestuff++] = *++pCode;
3209 MODULE_LICENSE("GPL");
3211 static struct pci_device_id ip2main_pci_tbl[] __devinitdata = {
3212 { PCI_DEVICE(PCI_VENDOR_ID_COMPUTONE, PCI_DEVICE_ID_COMPUTONE_IP2EX) },
3216 MODULE_DEVICE_TABLE(pci, ip2main_pci_tbl);