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 const struct file_operations ip2_proc_fops
;
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
);
186 static int ip2_get_icount(struct tty_struct
*tty
,
187 struct serial_icounter_struct
*icount
);
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 long ip2_ipl_ioctl(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, const struct firmware
*);
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 .unlocked_ioctl
= ip2_ipl_ioctl
,
239 .open
= ip2_ipl_open
,
242 static unsigned long irq_counter
;
243 static unsigned long bh_counter
;
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);
255 #ifdef IP2DEBUG_TRACE
256 /* Trace (debug) buffer data */
257 #define TRACEMAX 1000
258 static unsigned long tracebuf
[TRACEMAX
];
259 static int tracestuff
;
260 static int tracestrip
;
261 static int tracewrap
;
268 #if defined(MODULE) && defined(IP2DEBUG_OPEN)
269 #define DBG_CNT(s) printk(KERN_DEBUG "(%s): [%x] ttyc=%d, modc=%x -> %s\n", \
270 tty->name,(pCh->flags), \
271 tty->count,/*GET_USE_COUNT(module)*/0,s)
280 #include "i2ellis.c" /* Extremely low-level interface services */
281 #include "i2cmd.c" /* Standard loadware command definitions */
282 #include "i2lib.c" /* High level interface services */
284 /* Configuration area for modprobe */
286 MODULE_AUTHOR("Doug McNash");
287 MODULE_DESCRIPTION("Computone IntelliPort Plus Driver");
288 MODULE_LICENSE("GPL");
290 static int poll_only
;
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 /* Note: Add compiled in defaults to these arrays, not to the structure
300 in ip2.h any longer. That structure WILL get overridden
301 by these values, or command line values, or insmod values!!! =mhw=
303 static int io
[IP2_MAX_BOARDS
];
304 static int irq
[IP2_MAX_BOARDS
] = { -1, -1, -1, -1 };
306 MODULE_AUTHOR("Doug McNash");
307 MODULE_DESCRIPTION("Computone IntelliPort Plus Driver");
308 module_param_array(irq
, int, NULL
, 0);
309 MODULE_PARM_DESC(irq
, "Interrupts for IntelliPort Cards");
310 module_param_array(io
, int, NULL
, 0);
311 MODULE_PARM_DESC(io
, "I/O ports for IntelliPort Cards");
312 module_param(poll_only
, bool, 0);
313 MODULE_PARM_DESC(poll_only
, "Do not use card interrupts");
315 /* for sysfs class support */
316 static struct class *ip2_class
;
318 /* Some functions to keep track of what irqs we have */
320 static int __init
is_valid_irq(int irq
)
324 while (*i
!= 0 && *i
!= irq
)
330 static void __init
mark_requested_irq(char irq
)
332 rirqs
[iindx
++] = irq
;
335 static int __exit
clear_requested_irq(char irq
)
338 for (i
= 0; i
< IP2_MAX_BOARDS
; ++i
) {
339 if (rirqs
[i
] == irq
) {
347 static int have_requested_irq(char irq
)
349 /* array init to zeros so 0 irq will not be requested as a side
352 for (i
= 0; i
< IP2_MAX_BOARDS
; ++i
)
358 /******************************************************************************/
359 /* Function: cleanup_module() */
360 /* Parameters: None */
361 /* Returns: Nothing */
364 /* This is a required entry point for an installable module. It has to return */
365 /* the device and the driver to a passive state. It should not be necessary */
366 /* to reset the board fully, especially as the loadware is downloaded */
367 /* externally rather than in the driver. We just want to disable the board */
368 /* and clear the loadware to a reset state. To allow this there has to be a */
369 /* way to detect whether the board has the loadware running at init time to */
370 /* handle subsequent installations of the driver. All memory allocated by the */
371 /* driver should be returned since it may be unloaded from memory. */
372 /******************************************************************************/
373 static void __exit
ip2_cleanup_module(void)
378 del_timer_sync(&PollTimer
);
380 /* Reset the boards we have. */
381 for (i
= 0; i
< IP2_MAX_BOARDS
; i
++)
382 if (i2BoardPtrTable
[i
])
383 iiReset(i2BoardPtrTable
[i
]);
385 /* The following is done at most once, if any boards were installed. */
386 for (i
= 0; i
< IP2_MAX_BOARDS
; i
++) {
387 if (i2BoardPtrTable
[i
]) {
388 iiResetDelay(i2BoardPtrTable
[i
]);
389 /* free io addresses and Tibet */
390 release_region(ip2config
.addr
[i
], 8);
391 device_destroy(ip2_class
, MKDEV(IP2_IPL_MAJOR
, 4 * i
));
392 device_destroy(ip2_class
, MKDEV(IP2_IPL_MAJOR
,
395 /* Disable and remove interrupt handler. */
396 if (ip2config
.irq
[i
] > 0 &&
397 have_requested_irq(ip2config
.irq
[i
])) {
398 free_irq(ip2config
.irq
[i
], (void *)&pcName
);
399 clear_requested_irq(ip2config
.irq
[i
]);
402 class_destroy(ip2_class
);
403 err
= tty_unregister_driver(ip2_tty_driver
);
405 printk(KERN_ERR
"IP2: failed to unregister tty driver (%d)\n",
407 put_tty_driver(ip2_tty_driver
);
408 unregister_chrdev(IP2_IPL_MAJOR
, pcIpl
);
409 remove_proc_entry("ip2mem", NULL
);
412 for (i
= 0; i
< IP2_MAX_BOARDS
; i
++) {
415 if (ip2config
.type
[i
] == PCI
&& ip2config
.pci_dev
[i
]) {
416 pci_disable_device(ip2config
.pci_dev
[i
]);
417 pci_dev_put(ip2config
.pci_dev
[i
]);
418 ip2config
.pci_dev
[i
] = NULL
;
421 pB
= i2BoardPtrTable
[i
];
424 i2BoardPtrTable
[i
] = NULL
;
426 if (DevTableMem
[i
] != NULL
) {
427 kfree(DevTableMem
[i
]);
428 DevTableMem
[i
] = NULL
;
432 module_exit(ip2_cleanup_module
);
434 static const struct tty_operations ip2_ops
= {
438 .put_char
= ip2_putchar
,
439 .flush_chars
= ip2_flush_chars
,
440 .write_room
= ip2_write_room
,
441 .chars_in_buffer
= ip2_chars_in_buf
,
442 .flush_buffer
= ip2_flush_buffer
,
444 .throttle
= ip2_throttle
,
445 .unthrottle
= ip2_unthrottle
,
446 .set_termios
= ip2_set_termios
,
447 .set_ldisc
= ip2_set_line_discipline
,
450 .hangup
= ip2_hangup
,
451 .tiocmget
= ip2_tiocmget
,
452 .tiocmset
= ip2_tiocmset
,
453 .get_icount
= ip2_get_icount
,
454 .proc_fops
= &ip2_proc_fops
,
457 /******************************************************************************/
458 /* Function: ip2_loadmain() */
459 /* Parameters: irq, io from command line of insmod et. al. */
460 /* pointer to fip firmware and firmware size for boards */
461 /* Returns: Success (0) */
464 /* This was the required entry point for all drivers (now in ip2.c) */
465 /* It performs all */
466 /* initialisation of the devices and driver structures, and registers itself */
467 /* with the relevant kernel modules. */
468 /******************************************************************************/
469 /* IRQF_DISABLED - if set blocks all interrupts else only this line */
470 /* IRQF_SHARED - for shared irq PCI or maybe EISA only */
471 /* SA_RANDOM - can be source for cert. random number generators */
472 #define IP2_SA_FLAGS 0
475 static const struct firmware
*ip2_request_firmware(void)
477 struct platform_device
*pdev
;
478 const struct firmware
*fw
;
480 pdev
= platform_device_register_simple("ip2", 0, NULL
, 0);
482 printk(KERN_ERR
"Failed to register platform device for ip2\n");
485 if (request_firmware(&fw
, "intelliport2.bin", &pdev
->dev
)) {
486 printk(KERN_ERR
"Failed to load firmware 'intelliport2.bin'\n");
489 platform_device_unregister(pdev
);
494 /******************************************************************************
496 * str: kernel command line string
498 * Can't autoprobe the boards so user must specify configuration on
499 * kernel command line. Sane people build it modular but the others
502 * Alternating pairs of io,irq for up to 4 boards.
503 * ip2=io0,irq0,io1,irq1,io2,irq2,io3,irq3
508 * else => ISA I/O address
510 * irq=0 or invalid for ISA will revert to polling mode
512 * Any value = -1, do not overwrite compiled in value.
514 ******************************************************************************/
515 static int __init
ip2_setup(char *str
)
517 int j
, ints
[10]; /* 4 boards, 2 parameters + 2 */
520 str
= get_options(str
, ARRAY_SIZE(ints
), ints
);
522 for (i
= 0, j
= 1; i
< 4; i
++) {
536 __setup("ip2=", ip2_setup
);
539 static int __init
ip2_loadmain(void)
543 i2eBordStrPtr pB
= NULL
;
545 struct pci_dev
*pdev
= NULL
;
546 const struct firmware
*fw
= NULL
;
549 /* Hard lock the interrupts to zero */
550 irq
[0] = irq
[1] = irq
[2] = irq
[3] = poll_only
= 0;
553 ip2trace(ITRC_NO_PORT
, ITRC_INIT
, ITRC_ENTER
, 0);
555 /* process command line arguments to modprobe or
556 insmod i.e. iop & irqp */
557 /* irqp and iop should ALWAYS be specified now... But we check
558 them individually just to be sure, anyways... */
559 for (i
= 0; i
< IP2_MAX_BOARDS
; ++i
) {
560 ip2config
.addr
[i
] = io
[i
];
562 ip2config
.irq
[i
] = irq
[i
];
564 ip2config
.irq
[i
] = 0;
565 /* This is a little bit of a hack. If poll_only=1 on command
566 line back in ip2.c OR all IRQs on all specified boards are
567 explicitly set to 0, then drop to poll only mode and override
568 PCI or EISA interrupts. This superceeds the old hack of
569 triggering if all interrupts were zero (like da default).
570 Still a hack but less prone to random acts of terrorism.
572 What we really should do, now that the IRQ default is set
573 to -1, is to use 0 as a hard coded, do not probe.
579 poll_only
= !poll_only
;
581 /* Announce our presence */
582 printk(KERN_INFO
"%s version %s\n", pcName
, pcVersion
);
584 ip2_tty_driver
= alloc_tty_driver(IP2_MAX_PORTS
);
588 /* Initialise all the boards we can find (up to the maximum). */
589 for (i
= 0; i
< IP2_MAX_BOARDS
; ++i
) {
590 switch (ip2config
.addr
[i
]) {
591 case 0: /* skip this slot even if card is present */
594 /* ISA address must be specified */
595 if (ip2config
.addr
[i
] < 0x100 ||
596 ip2config
.addr
[i
] > 0x3f8) {
597 printk(KERN_ERR
"IP2: Bad ISA board %d "
600 ip2config
.addr
[i
] = 0;
603 ip2config
.type
[i
] = ISA
;
605 /* Check for valid irq argument, set for polling if
607 if (ip2config
.irq
[i
] &&
608 !is_valid_irq(ip2config
.irq
[i
])) {
609 printk(KERN_ERR
"IP2: Bad IRQ(%d) specified\n",
611 /* 0 is polling and is valid in that sense */
612 ip2config
.irq
[i
] = 0;
621 pdev
= pci_get_device(PCI_VENDOR_ID_COMPUTONE
,
622 PCI_DEVICE_ID_COMPUTONE_IP2EX
, pdev
);
624 ip2config
.addr
[i
] = 0;
625 printk(KERN_ERR
"IP2: PCI board %d not "
630 if (pci_enable_device(pdev
)) {
631 dev_err(&pdev
->dev
, "can't enable device\n");
634 ip2config
.type
[i
] = PCI
;
635 ip2config
.pci_dev
[i
] = pci_dev_get(pdev
);
636 status
= pci_read_config_dword(pdev
, PCI_BASE_ADDRESS_1
,
639 ip2config
.addr
[i
] = (USHORT
)(addr
& 0xfffe);
641 dev_err(&pdev
->dev
, "I/O address error\n");
643 ip2config
.irq
[i
] = pdev
->irq
;
646 printk(KERN_ERR
"IP2: PCI card specified but PCI "
647 "support not enabled.\n");
648 printk(KERN_ERR
"IP2: Recompile kernel with CONFIG_PCI "
650 #endif /* CONFIG_PCI */
653 ip2config
.addr
[i
] = find_eisa_board(Eisa_slot
+ 1);
654 if (ip2config
.addr
[i
] != 0) {
655 /* Eisa_irq set as side effect, boo */
656 ip2config
.type
[i
] = EISA
;
658 ip2config
.irq
[i
] = Eisa_irq
;
664 for (i
= 0; i
< IP2_MAX_BOARDS
; ++i
) {
665 if (ip2config
.addr
[i
]) {
666 pB
= kzalloc(sizeof(i2eBordStr
), GFP_KERNEL
);
668 i2BoardPtrTable
[i
] = pB
;
669 iiSetAddress(pB
, ip2config
.addr
[i
],
673 printk(KERN_ERR
"IP2: board memory allocation "
677 for (i
= 0; i
< IP2_MAX_BOARDS
; ++i
) {
678 pB
= i2BoardPtrTable
[i
];
684 for (i
= 0; i
< IP2_MAX_BOARDS
; ++i
) {
685 /* We don't want to request the firmware unless we have at
687 if (i2BoardPtrTable
[i
] != NULL
) {
689 fw
= ip2_request_firmware();
692 ip2_init_board(i
, fw
);
696 release_firmware(fw
);
698 ip2trace(ITRC_NO_PORT
, ITRC_INIT
, 2, 0);
700 ip2_tty_driver
->owner
= THIS_MODULE
;
701 ip2_tty_driver
->name
= "ttyF";
702 ip2_tty_driver
->driver_name
= pcDriver_name
;
703 ip2_tty_driver
->major
= IP2_TTY_MAJOR
;
704 ip2_tty_driver
->minor_start
= 0;
705 ip2_tty_driver
->type
= TTY_DRIVER_TYPE_SERIAL
;
706 ip2_tty_driver
->subtype
= SERIAL_TYPE_NORMAL
;
707 ip2_tty_driver
->init_termios
= tty_std_termios
;
708 ip2_tty_driver
->init_termios
.c_cflag
= B9600
|CS8
|CREAD
|HUPCL
|CLOCAL
;
709 ip2_tty_driver
->flags
= TTY_DRIVER_REAL_RAW
|
710 TTY_DRIVER_DYNAMIC_DEV
;
711 tty_set_operations(ip2_tty_driver
, &ip2_ops
);
713 ip2trace(ITRC_NO_PORT
, ITRC_INIT
, 3, 0);
715 err
= tty_register_driver(ip2_tty_driver
);
717 printk(KERN_ERR
"IP2: failed to register tty driver\n");
718 put_tty_driver(ip2_tty_driver
);
719 return err
; /* leaking resources */
722 err
= register_chrdev(IP2_IPL_MAJOR
, pcIpl
, &ip2_ipl
);
724 printk(KERN_ERR
"IP2: failed to register IPL device (%d)\n",
727 /* create the sysfs class */
728 ip2_class
= class_create(THIS_MODULE
, "ip2");
729 if (IS_ERR(ip2_class
)) {
730 err
= PTR_ERR(ip2_class
);
734 /* Register the read_procmem thing */
735 if (!proc_create("ip2mem",0,NULL
,&ip2mem_proc_fops
)) {
736 printk(KERN_ERR
"IP2: failed to register read_procmem\n");
737 return -EIO
; /* leaking resources */
740 ip2trace(ITRC_NO_PORT
, ITRC_INIT
, 4, 0);
741 /* Register the interrupt handler or poll handler, depending upon the
742 * specified interrupt.
745 for (i
= 0; i
< IP2_MAX_BOARDS
; ++i
) {
746 if (ip2config
.addr
[i
] == 0)
749 pB
= i2BoardPtrTable
[i
];
751 device_create(ip2_class
, NULL
,
752 MKDEV(IP2_IPL_MAJOR
, 4 * i
),
754 device_create(ip2_class
, NULL
,
755 MKDEV(IP2_IPL_MAJOR
, 4 * i
+ 1),
758 for (box
= 0; box
< ABS_MAX_BOXES
; box
++)
759 for (j
= 0; j
< ABS_BIGGEST_BOX
; j
++)
760 if (pB
->i2eChannelMap
[box
] & (1 << j
))
763 j
+ ABS_BIGGEST_BOX
*
764 (box
+i
*ABS_MAX_BOXES
),
769 /* Poll only forces driver to only use polling and
770 to ignore the probed PCI or EISA interrupts. */
771 ip2config
.irq
[i
] = CIR_POLL
;
773 if (ip2config
.irq
[i
] == CIR_POLL
) {
775 if (!timer_pending(&PollTimer
)) {
776 mod_timer(&PollTimer
, POLL_TIMEOUT
);
777 printk(KERN_INFO
"IP2: polling\n");
780 if (have_requested_irq(ip2config
.irq
[i
]))
782 rc
= request_irq(ip2config
.irq
[i
], ip2_interrupt
,
784 (ip2config
.type
[i
] == PCI
? IRQF_SHARED
: 0),
785 pcName
, i2BoardPtrTable
[i
]);
787 printk(KERN_ERR
"IP2: request_irq failed: "
789 ip2config
.irq
[i
] = CIR_POLL
;
790 printk(KERN_INFO
"IP2: Polling %ld/sec.\n",
791 (POLL_TIMEOUT
- jiffies
));
794 mark_requested_irq(ip2config
.irq
[i
]);
795 /* Initialise the interrupt handler bottom half
800 for (i
= 0; i
< IP2_MAX_BOARDS
; ++i
) {
801 if (i2BoardPtrTable
[i
]) {
802 /* set and enable board interrupt */
803 set_irq(i
, ip2config
.irq
[i
]);
807 ip2trace(ITRC_NO_PORT
, ITRC_INIT
, ITRC_RETURN
, 0);
812 unregister_chrdev(IP2_IPL_MAJOR
, "ip2");
813 /* unregister and put tty here */
816 module_init(ip2_loadmain
);
818 /******************************************************************************/
819 /* Function: ip2_init_board() */
820 /* Parameters: Index of board in configuration structure */
821 /* Returns: Success (0) */
824 /* This function initializes the specified board. The loadware is copied to */
825 /* the board, the channel structures are initialized, and the board details */
826 /* are reported on the console. */
827 /******************************************************************************/
829 ip2_init_board(int boardnum
, const struct firmware
*fw
)
832 int nports
= 0, nboxes
= 0;
834 i2eBordStrPtr pB
= i2BoardPtrTable
[boardnum
];
836 if ( !iiInitialize ( pB
) ) {
837 printk ( KERN_ERR
"IP2: Failed to initialize board at 0x%x, error %d\n",
838 pB
->i2eBase
, pB
->i2eError
);
841 printk(KERN_INFO
"IP2: Board %d: addr=0x%x irq=%d\n", boardnum
+ 1,
842 ip2config
.addr
[boardnum
], ip2config
.irq
[boardnum
] );
844 if (!request_region( ip2config
.addr
[boardnum
], 8, pcName
)) {
845 printk(KERN_ERR
"IP2: bad addr=0x%x\n", ip2config
.addr
[boardnum
]);
849 if ( iiDownloadAll ( pB
, (loadHdrStrPtr
)fw
->data
, 1, fw
->size
)
851 printk ( KERN_ERR
"IP2: failed to download loadware\n" );
852 goto err_release_region
;
854 printk ( KERN_INFO
"IP2: fv=%d.%d.%d lv=%d.%d.%d\n",
855 pB
->i2ePom
.e
.porVersion
,
856 pB
->i2ePom
.e
.porRevision
,
857 pB
->i2ePom
.e
.porSubRev
, pB
->i2eLVersion
,
858 pB
->i2eLRevision
, pB
->i2eLSub
);
861 switch ( pB
->i2ePom
.e
.porID
& ~POR_ID_RESERVED
) {
864 printk( KERN_ERR
"IP2: Unknown board type, ID = %x\n",
865 pB
->i2ePom
.e
.porID
);
867 goto err_release_region
;
870 case POR_ID_II_4
: /* IntelliPort-II, ISA-4 (4xRJ45) */
871 printk ( KERN_INFO
"IP2: ISA-4\n" );
875 case POR_ID_II_8
: /* IntelliPort-II, 8-port using standard brick. */
876 printk ( KERN_INFO
"IP2: ISA-8 std\n" );
880 case POR_ID_II_8R
: /* IntelliPort-II, 8-port using RJ11's (no CTS) */
881 printk ( KERN_INFO
"IP2: ISA-8 RJ11\n" );
885 case POR_ID_FIIEX
: /* IntelliPort IIEX */
887 int portnum
= IP2_PORTS_PER_BOARD
* boardnum
;
890 for( box
= 0; box
< ABS_MAX_BOXES
; ++box
) {
891 if ( pB
->i2eChannelMap
[box
] != 0 ) {
894 for( i
= 0; i
< ABS_BIGGEST_BOX
; ++i
) {
895 if ( pB
->i2eChannelMap
[box
] & 1<< i
) {
900 DevTableMem
[boardnum
] = pCh
=
901 kmalloc( sizeof(i2ChanStr
) * nports
, GFP_KERNEL
);
903 printk ( KERN_ERR
"IP2: (i2_init_channel:) Out of memory.\n");
904 goto err_release_region
;
906 if ( !i2InitChannels( pB
, nports
, pCh
) ) {
907 printk(KERN_ERR
"IP2: i2InitChannels failed: %d\n",pB
->i2eError
);
909 goto err_release_region
;
911 pB
->i2eChannelPtr
= &DevTable
[portnum
];
912 pB
->i2eChannelCnt
= ABS_MOST_PORTS
;
914 for( box
= 0; box
< ABS_MAX_BOXES
; ++box
, portnum
+= ABS_BIGGEST_BOX
) {
915 for( i
= 0; i
< ABS_BIGGEST_BOX
; ++i
) {
916 if ( pB
->i2eChannelMap
[box
] & (1 << i
) ) {
917 DevTable
[portnum
+ i
] = pCh
;
918 pCh
->port_index
= portnum
+ i
;
923 printk(KERN_INFO
"IP2: EX box=%d ports=%d %d bit\n",
924 nboxes
, nports
, pB
->i2eDataWidth16
? 16 : 8 );
928 DevTableMem
[boardnum
] = pCh
=
929 kmalloc ( sizeof (i2ChanStr
) * nports
, GFP_KERNEL
);
931 printk ( KERN_ERR
"IP2: (i2_init_channel:) Out of memory.\n");
932 goto err_release_region
;
934 pB
->i2eChannelPtr
= pCh
;
935 pB
->i2eChannelCnt
= nports
;
936 if ( !i2InitChannels( pB
, nports
, pCh
) ) {
937 printk(KERN_ERR
"IP2: i2InitChannels failed: %d\n",pB
->i2eError
);
939 goto err_release_region
;
941 pB
->i2eChannelPtr
= &DevTable
[IP2_PORTS_PER_BOARD
* boardnum
];
943 for( i
= 0; i
< pB
->i2eChannelCnt
; ++i
) {
944 DevTable
[IP2_PORTS_PER_BOARD
* boardnum
+ i
] = pCh
;
945 pCh
->port_index
= (IP2_PORTS_PER_BOARD
* boardnum
) + i
;
949 INIT_WORK(&pB
->tqueue_interrupt
, ip2_interrupt_bh
);
953 release_region(ip2config
.addr
[boardnum
], 8);
956 i2BoardPtrTable
[boardnum
] = NULL
;
960 /******************************************************************************/
961 /* Function: find_eisa_board ( int start_slot ) */
962 /* Parameters: First slot to check */
963 /* Returns: Address of EISA IntelliPort II controller */
966 /* This function searches for an EISA IntelliPort controller, starting */
967 /* from the specified slot number. If the motherboard is not identified as an */
968 /* EISA motherboard, or no valid board ID is selected it returns 0. Otherwise */
969 /* it returns the base address of the controller. */
970 /******************************************************************************/
971 static unsigned short
972 find_eisa_board( int start_slot
)
975 unsigned int idm
= 0;
976 unsigned int idp
= 0;
977 unsigned int base
= 0;
984 * First a check for an EISA motherboard, which we do by comparing the
985 * EISA ID registers for the system board and the first couple of slots.
986 * No slot ID should match the system board ID, but on an ISA or PCI
987 * machine the odds are that an empty bus will return similar values for
991 value
= (inb(i
) << 24) + (inb(i
+1) << 16) + (inb(i
+2) << 8) + inb(i
+3);
992 for( i
= 0x1c80; i
<= 0x4c80; i
+= 0x1000 ) {
993 j
= (inb(i
)<<24)+(inb(i
+1)<<16)+(inb(i
+2)<<8)+inb(i
+3);
999 * OK, so we are inclined to believe that this is an EISA machine. Find
1000 * an IntelliPort controller.
1002 for( i
= start_slot
; i
< 16; i
++ ) {
1004 idm
= (inb(base
+ 0xc80) << 8) | (inb(base
+ 0xc81) & 0xff);
1005 idp
= (inb(base
+ 0xc82) << 8) | (inb(base
+ 0xc83) & 0xff);
1007 if ( idm
== 0x0e8e ) {
1008 if ( idp
== 0x0281 || idp
== 0x0218 ) {
1010 } else if ( idp
== 0x0282 || idp
== 0x0283 ) {
1011 ismine
= 3; /* Can do edge-trigger */
1022 /* It's some sort of EISA card, but at what address is it configured? */
1024 setup_address
= base
+ 0xc88;
1025 value
= inb(base
+ 0xc86);
1026 setup_irq
= (value
& 8) ? Valid_Irqs
[value
& 7] : 0;
1028 if ( (ismine
& 2) && !(value
& 0x10) ) {
1029 ismine
= 1; /* Could be edging, but not */
1032 if ( Eisa_irq
== 0 ) {
1033 Eisa_irq
= setup_irq
;
1034 } else if ( Eisa_irq
!= setup_irq
) {
1035 printk ( KERN_ERR
"IP2: EISA irq mismatch between EISA controllers\n" );
1038 #ifdef IP2DEBUG_INIT
1039 printk(KERN_DEBUG
"Computone EISA board in slot %d, I.D. 0x%x%x, Address 0x%x",
1040 base
>> 12, idm
, idp
, setup_address
);
1042 printk(KERN_DEBUG
", Interrupt %d %s\n",
1043 setup_irq
, (ismine
& 2) ? "(edge)" : "(level)");
1045 printk(KERN_DEBUG
", (polled)\n");
1048 return setup_address
;
1051 /******************************************************************************/
1052 /* Function: set_irq() */
1053 /* Parameters: index to board in board table */
1055 /* Returns: Success (0) */
1058 /******************************************************************************/
1060 set_irq( int boardnum
, int boardIrq
)
1062 unsigned char tempCommand
[16];
1063 i2eBordStrPtr pB
= i2BoardPtrTable
[boardnum
];
1064 unsigned long flags
;
1067 * Notify the boards they may generate interrupts. This is done by
1068 * sending an in-line command to channel 0 on each board. This is why
1069 * the channels have to be defined already. For each board, if the
1070 * interrupt has never been defined, we must do so NOW, directly, since
1071 * board will not send flow control or even give an interrupt until this
1072 * is done. If polling we must send 0 as the interrupt parameter.
1075 // We will get an interrupt here at the end of this function
1077 iiDisableMailIrq(pB
);
1079 /* We build up the entire packet header. */
1080 CHANNEL_OF(tempCommand
) = 0;
1081 PTYPE_OF(tempCommand
) = PTYPE_INLINE
;
1082 CMD_COUNT_OF(tempCommand
) = 2;
1083 (CMD_OF(tempCommand
))[0] = CMDVALUE_IRQ
;
1084 (CMD_OF(tempCommand
))[1] = boardIrq
;
1086 * Write to FIFO; don't bother to adjust fifo capacity for this, since
1087 * board will respond almost immediately after SendMail hit.
1089 write_lock_irqsave(&pB
->write_fifo_spinlock
, flags
);
1090 iiWriteBuf(pB
, tempCommand
, 4);
1091 write_unlock_irqrestore(&pB
->write_fifo_spinlock
, flags
);
1092 pB
->i2eUsingIrq
= boardIrq
;
1093 pB
->i2eOutMailWaiting
|= MB_OUT_STUFFED
;
1095 /* Need to update number of boards before you enable mailbox int */
1098 CHANNEL_OF(tempCommand
) = 0;
1099 PTYPE_OF(tempCommand
) = PTYPE_BYPASS
;
1100 CMD_COUNT_OF(tempCommand
) = 6;
1101 (CMD_OF(tempCommand
))[0] = 88; // SILO
1102 (CMD_OF(tempCommand
))[1] = 64; // chars
1103 (CMD_OF(tempCommand
))[2] = 32; // ms
1105 (CMD_OF(tempCommand
))[3] = 28; // MAX_BLOCK
1106 (CMD_OF(tempCommand
))[4] = 64; // chars
1108 (CMD_OF(tempCommand
))[5] = 87; // HW_TEST
1109 write_lock_irqsave(&pB
->write_fifo_spinlock
, flags
);
1110 iiWriteBuf(pB
, tempCommand
, 8);
1111 write_unlock_irqrestore(&pB
->write_fifo_spinlock
, flags
);
1113 CHANNEL_OF(tempCommand
) = 0;
1114 PTYPE_OF(tempCommand
) = PTYPE_BYPASS
;
1115 CMD_COUNT_OF(tempCommand
) = 1;
1116 (CMD_OF(tempCommand
))[0] = 84; /* get BOX_IDS */
1117 iiWriteBuf(pB
, tempCommand
, 3);
1120 // enable heartbeat for test porpoises
1121 CHANNEL_OF(tempCommand
) = 0;
1122 PTYPE_OF(tempCommand
) = PTYPE_BYPASS
;
1123 CMD_COUNT_OF(tempCommand
) = 2;
1124 (CMD_OF(tempCommand
))[0] = 44; /* get ping */
1125 (CMD_OF(tempCommand
))[1] = 200; /* 200 ms */
1126 write_lock_irqsave(&pB
->write_fifo_spinlock
, flags
);
1127 iiWriteBuf(pB
, tempCommand
, 4);
1128 write_unlock_irqrestore(&pB
->write_fifo_spinlock
, flags
);
1131 iiEnableMailIrq(pB
);
1132 iiSendPendingMail(pB
);
1135 /******************************************************************************/
1136 /* Interrupt Handler Section */
1137 /******************************************************************************/
1140 service_all_boards(void)
1145 /* Service every board on the list */
1146 for( i
= 0; i
< IP2_MAX_BOARDS
; ++i
) {
1147 pB
= i2BoardPtrTable
[i
];
1149 i2ServiceBoard( pB
);
1155 /******************************************************************************/
1156 /* Function: ip2_interrupt_bh(work) */
1157 /* Parameters: work - pointer to the board structure */
1158 /* Returns: Nothing */
1161 /* Service the board in a bottom half interrupt handler and then */
1162 /* reenable the board's interrupts if it has an IRQ number */
1164 /******************************************************************************/
1166 ip2_interrupt_bh(struct work_struct
*work
)
1168 i2eBordStrPtr pB
= container_of(work
, i2eBordStr
, tqueue_interrupt
);
1169 // pB better well be set or we have a problem! We can only get
1170 // here from the IMMEDIATE queue. Here, we process the boards.
1171 // Checking pB doesn't cost much and it saves us from the sanity checkers.
1176 i2ServiceBoard( pB
);
1177 if( pB
->i2eUsingIrq
) {
1178 // Re-enable his interrupts
1179 iiEnableMailIrq(pB
);
1185 /******************************************************************************/
1186 /* Function: ip2_interrupt(int irq, void *dev_id) */
1187 /* Parameters: irq - interrupt number */
1188 /* pointer to optional device ID structure */
1189 /* Returns: Nothing */
1193 /* Our task here is simply to identify each board which needs servicing. */
1194 /* If we are queuing then, queue it to be serviced, and disable its irq */
1195 /* mask otherwise process the board directly. */
1197 /* We could queue by IRQ but that just complicates things on both ends */
1198 /* with very little gain in performance (how many instructions does */
1199 /* it take to iterate on the immediate queue). */
1202 /******************************************************************************/
1204 ip2_irq_work(i2eBordStrPtr pB
)
1207 if (NO_MAIL_HERE
!= ( pB
->i2eStartMail
= iiGetMail(pB
))) {
1208 // Disable his interrupt (will be enabled when serviced)
1209 // This is mostly to protect from reentrancy.
1210 iiDisableMailIrq(pB
);
1212 // Park the board on the immediate queue for processing.
1213 schedule_work(&pB
->tqueue_interrupt
);
1215 // Make sure the immediate queue is flagged to fire.
1219 // We are using immediate servicing here. This sucks and can
1220 // cause all sorts of havoc with ppp and others. The failsafe
1221 // check on iiSendPendingMail could also throw a hairball.
1223 i2ServiceBoard( pB
);
1225 #endif /* USE_IQI */
1229 ip2_polled_interrupt(void)
1234 ip2trace(ITRC_NO_PORT
, ITRC_INTR
, 99, 1, 0);
1236 /* Service just the boards on the list using this irq */
1237 for( i
= 0; i
< i2nBoards
; ++i
) {
1238 pB
= i2BoardPtrTable
[i
];
1240 // Only process those boards which match our IRQ.
1241 // IRQ = 0 for polled boards, we won't poll "IRQ" boards
1243 if (pB
&& pB
->i2eUsingIrq
== 0)
1249 ip2trace (ITRC_NO_PORT
, ITRC_INTR
, ITRC_RETURN
, 0 );
1253 ip2_interrupt(int irq
, void *dev_id
)
1255 i2eBordStrPtr pB
= dev_id
;
1257 ip2trace (ITRC_NO_PORT
, ITRC_INTR
, 99, 1, pB
->i2eUsingIrq
);
1263 ip2trace (ITRC_NO_PORT
, ITRC_INTR
, ITRC_RETURN
, 0 );
1267 /******************************************************************************/
1268 /* Function: ip2_poll(unsigned long arg) */
1270 /* Returns: Nothing */
1273 /* This function calls the library routine i2ServiceBoard for each board in */
1274 /* the board table. This is used instead of the interrupt routine when polled */
1275 /* mode is specified. */
1276 /******************************************************************************/
1278 ip2_poll(unsigned long arg
)
1280 ip2trace (ITRC_NO_PORT
, ITRC_INTR
, 100, 0 );
1282 // Just polled boards, IRQ = 0 will hit all non-interrupt boards.
1283 // It will NOT poll boards handled by hard interrupts.
1284 // The issue of queued BH interrupts is handled in ip2_interrupt().
1285 ip2_polled_interrupt();
1287 mod_timer(&PollTimer
, POLL_TIMEOUT
);
1289 ip2trace (ITRC_NO_PORT
, ITRC_INTR
, ITRC_RETURN
, 0 );
1292 static void do_input(struct work_struct
*work
)
1294 i2ChanStrPtr pCh
= container_of(work
, i2ChanStr
, tqueue_input
);
1295 unsigned long flags
;
1297 ip2trace(CHANN
, ITRC_INPUT
, 21, 0 );
1300 if ( pCh
->pTTY
!= NULL
) {
1301 read_lock_irqsave(&pCh
->Ibuf_spinlock
, flags
);
1302 if (!pCh
->throttled
&& (pCh
->Ibuf_stuff
!= pCh
->Ibuf_strip
)) {
1303 read_unlock_irqrestore(&pCh
->Ibuf_spinlock
, flags
);
1306 read_unlock_irqrestore(&pCh
->Ibuf_spinlock
, flags
);
1308 ip2trace(CHANN
, ITRC_INPUT
, 22, 0 );
1310 i2InputFlush( pCh
);
1314 // code duplicated from n_tty (ldisc)
1315 static inline void isig(int sig
, struct tty_struct
*tty
, int flush
)
1317 /* FIXME: This is completely bogus */
1319 kill_pgrp(tty
->pgrp
, sig
, 1);
1320 if (flush
|| !L_NOFLSH(tty
)) {
1321 if ( tty
->ldisc
->ops
->flush_buffer
)
1322 tty
->ldisc
->ops
->flush_buffer(tty
);
1323 i2InputFlush( tty
->driver_data
);
1327 static void do_status(struct work_struct
*work
)
1329 i2ChanStrPtr pCh
= container_of(work
, i2ChanStr
, tqueue_status
);
1332 status
= i2GetStatus( pCh
, (I2_BRK
|I2_PAR
|I2_FRA
|I2_OVR
) );
1334 ip2trace (CHANN
, ITRC_STATUS
, 21, 1, status
);
1336 if (pCh
->pTTY
&& (status
& (I2_BRK
|I2_PAR
|I2_FRA
|I2_OVR
)) ) {
1337 if ( (status
& I2_BRK
) ) {
1338 // code duplicated from n_tty (ldisc)
1339 if (I_IGNBRK(pCh
->pTTY
))
1341 if (I_BRKINT(pCh
->pTTY
)) {
1342 isig(SIGINT
, pCh
->pTTY
, 1);
1345 wake_up_interruptible(&pCh
->pTTY
->read_wait
);
1347 #ifdef NEVER_HAPPENS_AS_SETUP_XXX
1348 // and can't work because we don't know the_char
1349 // as the_char is reported on a separate path
1350 // The intelligent board does this stuff as setup
1352 char brkf
= TTY_NORMAL
;
1353 unsigned char brkc
= '\0';
1355 if ( (status
& I2_BRK
) ) {
1359 else if (status
& I2_PAR
) {
1362 } else if (status
& I2_FRA
) {
1365 } else if (status
& I2_OVR
) {
1369 tmp
= pCh
->pTTY
->real_raw
;
1370 pCh
->pTTY
->real_raw
= 0;
1371 pCh
->pTTY
->ldisc
->ops
.receive_buf( pCh
->pTTY
, &brkc
, &brkf
, 1 );
1372 pCh
->pTTY
->real_raw
= tmp
;
1374 #endif /* NEVER_HAPPENS_AS_SETUP_XXX */
1378 if ( status
& (I2_DDCD
| I2_DDSR
| I2_DCTS
| I2_DRI
) ) {
1379 wake_up_interruptible(&pCh
->delta_msr_wait
);
1381 if ( (pCh
->flags
& ASYNC_CHECK_CD
) && (status
& I2_DDCD
) ) {
1382 if ( status
& I2_DCD
) {
1384 wake_up_interruptible ( &pCh
->open_wait
);
1387 if (pCh
->pTTY
&& (!(pCh
->pTTY
->termios
->c_cflag
& CLOCAL
)) ) {
1388 tty_hangup( pCh
->pTTY
);
1394 ip2trace (CHANN
, ITRC_STATUS
, 26, 0 );
1397 /******************************************************************************/
1398 /* Device Open/Close/Ioctl Entry Point Section */
1399 /******************************************************************************/
1401 /******************************************************************************/
1402 /* Function: open_sanity_check() */
1403 /* Parameters: Pointer to tty structure */
1404 /* Pointer to file structure */
1405 /* Returns: Success or failure */
1408 /* Verifies the structure magic numbers and cross links. */
1409 /******************************************************************************/
1410 #ifdef IP2DEBUG_OPEN
1412 open_sanity_check( i2ChanStrPtr pCh
, i2eBordStrPtr pBrd
)
1414 if ( pBrd
->i2eValid
!= I2E_MAGIC
) {
1415 printk(KERN_ERR
"IP2: invalid board structure\n" );
1416 } else if ( pBrd
!= pCh
->pMyBord
) {
1417 printk(KERN_ERR
"IP2: board structure pointer mismatch (%p)\n",
1419 } else if ( pBrd
->i2eChannelCnt
< pCh
->port_index
) {
1420 printk(KERN_ERR
"IP2: bad device index (%d)\n", pCh
->port_index
);
1421 } else if (&((i2ChanStrPtr
)pBrd
->i2eChannelPtr
)[pCh
->port_index
] != pCh
) {
1423 printk(KERN_INFO
"IP2: all pointers check out!\n" );
1429 /******************************************************************************/
1430 /* Function: ip2_open() */
1431 /* Parameters: Pointer to tty structure */
1432 /* Pointer to file structure */
1433 /* Returns: Success or failure */
1435 /* Description: (MANDATORY) */
1436 /* A successful device open has to run a gauntlet of checks before it */
1437 /* completes. After some sanity checking and pointer setup, the function */
1438 /* blocks until all conditions are satisfied. It then initialises the port to */
1439 /* the default characteristics and returns. */
1440 /******************************************************************************/
1442 ip2_open( PTTY tty
, struct file
*pFile
)
1447 i2ChanStrPtr pCh
= DevTable
[tty
->index
];
1449 ip2trace (tty
->index
, ITRC_OPEN
, ITRC_ENTER
, 0 );
1451 if ( pCh
== NULL
) {
1454 /* Setup pointer links in device and tty structures */
1456 tty
->driver_data
= pCh
;
1458 #ifdef IP2DEBUG_OPEN
1460 "IP2:open(tty=%p,pFile=%p):dev=%s,ch=%d,idx=%d\n",
1461 tty
, pFile
, tty
->name
, pCh
->infl
.hd
.i2sChannel
, pCh
->port_index
);
1462 open_sanity_check ( pCh
, pCh
->pMyBord
);
1465 i2QueueCommands(PTYPE_INLINE
, pCh
, 100, 3, CMD_DTRUP
,CMD_RTSUP
,CMD_DCD_REP
);
1466 pCh
->dataSetOut
|= (I2_DTR
| I2_RTS
);
1467 serviceOutgoingFifo( pCh
->pMyBord
);
1469 /* Block here until the port is ready (per serial and istallion) */
1471 * 1. If the port is in the middle of closing wait for the completion
1472 * and then return the appropriate error.
1474 init_waitqueue_entry(&wait
, current
);
1475 add_wait_queue(&pCh
->close_wait
, &wait
);
1476 set_current_state( TASK_INTERRUPTIBLE
);
1478 if ( tty_hung_up_p(pFile
) || ( pCh
->flags
& ASYNC_CLOSING
)) {
1479 if ( pCh
->flags
& ASYNC_CLOSING
) {
1482 if ( tty_hung_up_p(pFile
) ) {
1483 set_current_state( TASK_RUNNING
);
1484 remove_wait_queue(&pCh
->close_wait
, &wait
);
1485 return( pCh
->flags
& ASYNC_HUP_NOTIFY
) ? -EAGAIN
: -ERESTARTSYS
;
1488 set_current_state( TASK_RUNNING
);
1489 remove_wait_queue(&pCh
->close_wait
, &wait
);
1492 * 3. Handle a non-blocking open of a normal port.
1494 if ( (pFile
->f_flags
& O_NONBLOCK
) || (tty
->flags
& (1<<TTY_IO_ERROR
) )) {
1495 pCh
->flags
|= ASYNC_NORMAL_ACTIVE
;
1499 * 4. Now loop waiting for the port to be free and carrier present
1502 if ( tty
->termios
->c_cflag
& CLOCAL
)
1505 #ifdef IP2DEBUG_OPEN
1506 printk(KERN_DEBUG
"OpenBlock: do_clocal = %d\n", do_clocal
);
1511 init_waitqueue_entry(&wait
, current
);
1512 add_wait_queue(&pCh
->open_wait
, &wait
);
1515 i2QueueCommands(PTYPE_INLINE
, pCh
, 100, 2, CMD_DTRUP
, CMD_RTSUP
);
1516 pCh
->dataSetOut
|= (I2_DTR
| I2_RTS
);
1517 set_current_state( TASK_INTERRUPTIBLE
);
1518 serviceOutgoingFifo( pCh
->pMyBord
);
1519 if ( tty_hung_up_p(pFile
) ) {
1520 set_current_state( TASK_RUNNING
);
1521 remove_wait_queue(&pCh
->open_wait
, &wait
);
1522 return ( pCh
->flags
& ASYNC_HUP_NOTIFY
) ? -EBUSY
: -ERESTARTSYS
;
1524 if (!(pCh
->flags
& ASYNC_CLOSING
) &&
1525 (do_clocal
|| (pCh
->dataSetIn
& I2_DCD
) )) {
1530 #ifdef IP2DEBUG_OPEN
1531 printk(KERN_DEBUG
"ASYNC_CLOSING = %s\n",
1532 (pCh
->flags
& ASYNC_CLOSING
)?"True":"False");
1533 printk(KERN_DEBUG
"OpenBlock: waiting for CD or signal\n");
1535 ip2trace (CHANN
, ITRC_OPEN
, 3, 2, 0,
1536 (pCh
->flags
& ASYNC_CLOSING
) );
1537 /* check for signal */
1538 if (signal_pending(current
)) {
1539 rc
= (( pCh
->flags
& ASYNC_HUP_NOTIFY
) ? -EAGAIN
: -ERESTARTSYS
);
1544 set_current_state( TASK_RUNNING
);
1545 remove_wait_queue(&pCh
->open_wait
, &wait
);
1547 --pCh
->wopen
; //why count?
1549 ip2trace (CHANN
, ITRC_OPEN
, 4, 0 );
1554 pCh
->flags
|= ASYNC_NORMAL_ACTIVE
;
1558 /* first open - Assign termios structure to port */
1559 if ( tty
->count
== 1 ) {
1560 i2QueueCommands(PTYPE_INLINE
, pCh
, 0, 2, CMD_CTSFL_DSAB
, CMD_RTSFL_DSAB
);
1561 /* Now we must send the termios settings to the loadware */
1562 set_params( pCh
, NULL
);
1566 * Now set any i2lib options. These may go away if the i2lib code ends
1567 * up rolled into the mainline.
1569 pCh
->channelOptions
|= CO_NBLOCK_WRITE
;
1571 #ifdef IP2DEBUG_OPEN
1572 printk (KERN_DEBUG
"IP2: open completed\n" );
1574 serviceOutgoingFifo( pCh
->pMyBord
);
1576 ip2trace (CHANN
, ITRC_OPEN
, ITRC_RETURN
, 0 );
1581 /******************************************************************************/
1582 /* Function: ip2_close() */
1583 /* Parameters: Pointer to tty structure */
1584 /* Pointer to file structure */
1585 /* Returns: Nothing */
1590 /******************************************************************************/
1592 ip2_close( PTTY tty
, struct file
*pFile
)
1594 i2ChanStrPtr pCh
= tty
->driver_data
;
1600 ip2trace (CHANN
, ITRC_CLOSE
, ITRC_ENTER
, 0 );
1602 #ifdef IP2DEBUG_OPEN
1603 printk(KERN_DEBUG
"IP2:close %s:\n",tty
->name
);
1606 if ( tty_hung_up_p ( pFile
) ) {
1608 ip2trace (CHANN
, ITRC_CLOSE
, 2, 1, 2 );
1612 if ( tty
->count
> 1 ) { /* not the last close */
1614 ip2trace (CHANN
, ITRC_CLOSE
, 2, 1, 3 );
1618 pCh
->flags
|= ASYNC_CLOSING
; // last close actually
1622 if (pCh
->ClosingWaitTime
!= ASYNC_CLOSING_WAIT_NONE
) {
1624 * Before we drop DTR, make sure the transmitter has completely drained.
1625 * This uses an timeout, after which the close
1628 ip2_wait_until_sent(tty
, pCh
->ClosingWaitTime
);
1631 * At this point we stop accepting input. Here we flush the channel
1632 * input buffer which will allow the board to send up more data. Any
1633 * additional input is tossed at interrupt/poll time.
1635 i2InputFlush( pCh
);
1637 /* disable DSS reporting */
1638 i2QueueCommands(PTYPE_INLINE
, pCh
, 100, 4,
1639 CMD_DCD_NREP
, CMD_CTS_NREP
, CMD_DSR_NREP
, CMD_RI_NREP
);
1640 if ( !tty
|| (tty
->termios
->c_cflag
& HUPCL
) ) {
1641 i2QueueCommands(PTYPE_INLINE
, pCh
, 100, 2, CMD_RTSDN
, CMD_DTRDN
);
1642 pCh
->dataSetOut
&= ~(I2_DTR
| I2_RTS
);
1643 i2QueueCommands( PTYPE_INLINE
, pCh
, 100, 1, CMD_PAUSE(25));
1646 serviceOutgoingFifo ( pCh
->pMyBord
);
1648 tty_ldisc_flush(tty
);
1649 tty_driver_flush_buffer(tty
);
1655 if (pCh
->ClosingDelay
) {
1656 msleep_interruptible(jiffies_to_msecs(pCh
->ClosingDelay
));
1658 wake_up_interruptible(&pCh
->open_wait
);
1661 pCh
->flags
&=~(ASYNC_NORMAL_ACTIVE
|ASYNC_CLOSING
);
1662 wake_up_interruptible(&pCh
->close_wait
);
1664 #ifdef IP2DEBUG_OPEN
1665 DBG_CNT("ip2_close: after wakeups--");
1669 ip2trace (CHANN
, ITRC_CLOSE
, ITRC_RETURN
, 1, 1 );
1674 /******************************************************************************/
1675 /* Function: ip2_hangup() */
1676 /* Parameters: Pointer to tty structure */
1677 /* Returns: Nothing */
1682 /******************************************************************************/
1684 ip2_hangup ( PTTY tty
)
1686 i2ChanStrPtr pCh
= tty
->driver_data
;
1692 ip2trace (CHANN
, ITRC_HANGUP
, ITRC_ENTER
, 0 );
1694 ip2_flush_buffer(tty
);
1696 /* disable DSS reporting */
1698 i2QueueCommands(PTYPE_BYPASS
, pCh
, 0, 1, CMD_DCD_NREP
);
1699 i2QueueCommands(PTYPE_INLINE
, pCh
, 0, 2, CMD_CTSFL_DSAB
, CMD_RTSFL_DSAB
);
1700 if ( (tty
->termios
->c_cflag
& HUPCL
) ) {
1701 i2QueueCommands(PTYPE_BYPASS
, pCh
, 0, 2, CMD_RTSDN
, CMD_DTRDN
);
1702 pCh
->dataSetOut
&= ~(I2_DTR
| I2_RTS
);
1703 i2QueueCommands( PTYPE_INLINE
, pCh
, 100, 1, CMD_PAUSE(25));
1705 i2QueueCommands(PTYPE_INLINE
, pCh
, 1, 3,
1706 CMD_CTS_NREP
, CMD_DSR_NREP
, CMD_RI_NREP
);
1707 serviceOutgoingFifo ( pCh
->pMyBord
);
1709 wake_up_interruptible ( &pCh
->delta_msr_wait
);
1711 pCh
->flags
&= ~ASYNC_NORMAL_ACTIVE
;
1713 wake_up_interruptible ( &pCh
->open_wait
);
1715 ip2trace (CHANN
, ITRC_HANGUP
, ITRC_RETURN
, 0 );
1718 /******************************************************************************/
1719 /******************************************************************************/
1720 /* Device Output Section */
1721 /******************************************************************************/
1722 /******************************************************************************/
1724 /******************************************************************************/
1725 /* Function: ip2_write() */
1726 /* Parameters: Pointer to tty structure */
1727 /* Flag denoting data is in user (1) or kernel (0) space */
1728 /* Pointer to data */
1729 /* Number of bytes to write */
1730 /* Returns: Number of bytes actually written */
1732 /* Description: (MANDATORY) */
1735 /******************************************************************************/
1737 ip2_write( PTTY tty
, const unsigned char *pData
, int count
)
1739 i2ChanStrPtr pCh
= tty
->driver_data
;
1741 unsigned long flags
;
1743 ip2trace (CHANN
, ITRC_WRITE
, ITRC_ENTER
, 2, count
, -1 );
1745 /* Flush out any buffered data left over from ip2_putchar() calls. */
1746 ip2_flush_chars( tty
);
1748 /* This is the actual move bit. Make sure it does what we need!!!!! */
1749 write_lock_irqsave(&pCh
->Pbuf_spinlock
, flags
);
1750 bytesSent
= i2Output( pCh
, pData
, count
);
1751 write_unlock_irqrestore(&pCh
->Pbuf_spinlock
, flags
);
1753 ip2trace (CHANN
, ITRC_WRITE
, ITRC_RETURN
, 1, bytesSent
);
1755 return bytesSent
> 0 ? bytesSent
: 0;
1758 /******************************************************************************/
1759 /* Function: ip2_putchar() */
1760 /* Parameters: Pointer to tty structure */
1761 /* Character to write */
1762 /* Returns: Nothing */
1767 /******************************************************************************/
1769 ip2_putchar( PTTY tty
, unsigned char ch
)
1771 i2ChanStrPtr pCh
= tty
->driver_data
;
1772 unsigned long flags
;
1774 // ip2trace (CHANN, ITRC_PUTC, ITRC_ENTER, 1, ch );
1776 write_lock_irqsave(&pCh
->Pbuf_spinlock
, flags
);
1777 pCh
->Pbuf
[pCh
->Pbuf_stuff
++] = ch
;
1778 if ( pCh
->Pbuf_stuff
== sizeof pCh
->Pbuf
) {
1779 write_unlock_irqrestore(&pCh
->Pbuf_spinlock
, flags
);
1780 ip2_flush_chars( tty
);
1782 write_unlock_irqrestore(&pCh
->Pbuf_spinlock
, flags
);
1785 // ip2trace (CHANN, ITRC_PUTC, ITRC_RETURN, 1, ch );
1788 /******************************************************************************/
1789 /* Function: ip2_flush_chars() */
1790 /* Parameters: Pointer to tty structure */
1791 /* Returns: Nothing */
1795 /******************************************************************************/
1797 ip2_flush_chars( PTTY tty
)
1800 i2ChanStrPtr pCh
= tty
->driver_data
;
1801 unsigned long flags
;
1803 write_lock_irqsave(&pCh
->Pbuf_spinlock
, flags
);
1804 if ( pCh
->Pbuf_stuff
) {
1806 // ip2trace (CHANN, ITRC_PUTC, 10, 1, strip );
1809 // We may need to restart i2Output if it does not fullfill this request
1811 strip
= i2Output( pCh
, pCh
->Pbuf
, pCh
->Pbuf_stuff
);
1812 if ( strip
!= pCh
->Pbuf_stuff
) {
1813 memmove( pCh
->Pbuf
, &pCh
->Pbuf
[strip
], pCh
->Pbuf_stuff
- strip
);
1815 pCh
->Pbuf_stuff
-= strip
;
1817 write_unlock_irqrestore(&pCh
->Pbuf_spinlock
, flags
);
1820 /******************************************************************************/
1821 /* Function: ip2_write_room() */
1822 /* Parameters: Pointer to tty structure */
1823 /* Returns: Number of bytes that the driver can accept */
1827 /******************************************************************************/
1829 ip2_write_room ( PTTY tty
)
1832 i2ChanStrPtr pCh
= tty
->driver_data
;
1833 unsigned long flags
;
1835 read_lock_irqsave(&pCh
->Pbuf_spinlock
, flags
);
1836 bytesFree
= i2OutputFree( pCh
) - pCh
->Pbuf_stuff
;
1837 read_unlock_irqrestore(&pCh
->Pbuf_spinlock
, flags
);
1839 ip2trace (CHANN
, ITRC_WRITE
, 11, 1, bytesFree
);
1841 return ((bytesFree
> 0) ? bytesFree
: 0);
1844 /******************************************************************************/
1845 /* Function: ip2_chars_in_buf() */
1846 /* Parameters: Pointer to tty structure */
1847 /* Returns: Number of bytes queued for transmission */
1852 /******************************************************************************/
1854 ip2_chars_in_buf ( PTTY tty
)
1856 i2ChanStrPtr pCh
= tty
->driver_data
;
1858 unsigned long flags
;
1860 ip2trace (CHANN
, ITRC_WRITE
, 12, 1, pCh
->Obuf_char_count
+ pCh
->Pbuf_stuff
);
1862 #ifdef IP2DEBUG_WRITE
1863 printk (KERN_DEBUG
"IP2: chars in buffer = %d (%d,%d)\n",
1864 pCh
->Obuf_char_count
+ pCh
->Pbuf_stuff
,
1865 pCh
->Obuf_char_count
, pCh
->Pbuf_stuff
);
1867 read_lock_irqsave(&pCh
->Obuf_spinlock
, flags
);
1868 rc
= pCh
->Obuf_char_count
;
1869 read_unlock_irqrestore(&pCh
->Obuf_spinlock
, flags
);
1870 read_lock_irqsave(&pCh
->Pbuf_spinlock
, flags
);
1871 rc
+= pCh
->Pbuf_stuff
;
1872 read_unlock_irqrestore(&pCh
->Pbuf_spinlock
, flags
);
1876 /******************************************************************************/
1877 /* Function: ip2_flush_buffer() */
1878 /* Parameters: Pointer to tty structure */
1879 /* Returns: Nothing */
1884 /******************************************************************************/
1886 ip2_flush_buffer( PTTY tty
)
1888 i2ChanStrPtr pCh
= tty
->driver_data
;
1889 unsigned long flags
;
1891 ip2trace (CHANN
, ITRC_FLUSH
, ITRC_ENTER
, 0 );
1893 #ifdef IP2DEBUG_WRITE
1894 printk (KERN_DEBUG
"IP2: flush buffer\n" );
1896 write_lock_irqsave(&pCh
->Pbuf_spinlock
, flags
);
1897 pCh
->Pbuf_stuff
= 0;
1898 write_unlock_irqrestore(&pCh
->Pbuf_spinlock
, flags
);
1899 i2FlushOutput( pCh
);
1902 ip2trace (CHANN
, ITRC_FLUSH
, ITRC_RETURN
, 0 );
1906 /******************************************************************************/
1907 /* Function: ip2_wait_until_sent() */
1908 /* Parameters: Pointer to tty structure */
1909 /* Timeout for wait. */
1910 /* Returns: Nothing */
1913 /* This function is used in place of the normal tty_wait_until_sent, which */
1914 /* only waits for the driver buffers to be empty (or rather, those buffers */
1915 /* reported by chars_in_buffer) which doesn't work for IP2 due to the */
1916 /* indeterminate number of bytes buffered on the board. */
1917 /******************************************************************************/
1919 ip2_wait_until_sent ( PTTY tty
, int timeout
)
1922 i2ChanStrPtr pCh
= tty
->driver_data
;
1924 tty_wait_until_sent(tty
, timeout
);
1925 if ( (i
= timeout
- (jiffies
-i
)) > 0)
1926 i2DrainOutput( pCh
, i
);
1929 /******************************************************************************/
1930 /******************************************************************************/
1931 /* Device Input Section */
1932 /******************************************************************************/
1933 /******************************************************************************/
1935 /******************************************************************************/
1936 /* Function: ip2_throttle() */
1937 /* Parameters: Pointer to tty structure */
1938 /* Returns: Nothing */
1943 /******************************************************************************/
1945 ip2_throttle ( PTTY tty
)
1947 i2ChanStrPtr pCh
= tty
->driver_data
;
1949 #ifdef IP2DEBUG_READ
1950 printk (KERN_DEBUG
"IP2: throttle\n" );
1953 * Signal the poll/interrupt handlers not to forward incoming data to
1954 * the line discipline. This will cause the buffers to fill up in the
1955 * library and thus cause the library routines to send the flow control
1961 /******************************************************************************/
1962 /* Function: ip2_unthrottle() */
1963 /* Parameters: Pointer to tty structure */
1964 /* Returns: Nothing */
1969 /******************************************************************************/
1971 ip2_unthrottle ( PTTY tty
)
1973 i2ChanStrPtr pCh
= tty
->driver_data
;
1974 unsigned long flags
;
1976 #ifdef IP2DEBUG_READ
1977 printk (KERN_DEBUG
"IP2: unthrottle\n" );
1980 /* Pass incoming data up to the line discipline again. */
1982 i2QueueCommands(PTYPE_BYPASS
, pCh
, 0, 1, CMD_RESUME
);
1983 serviceOutgoingFifo( pCh
->pMyBord
);
1984 read_lock_irqsave(&pCh
->Ibuf_spinlock
, flags
);
1985 if ( pCh
->Ibuf_stuff
!= pCh
->Ibuf_strip
) {
1986 read_unlock_irqrestore(&pCh
->Ibuf_spinlock
, flags
);
1987 #ifdef IP2DEBUG_READ
1988 printk (KERN_DEBUG
"i2Input called from unthrottle\n" );
1992 read_unlock_irqrestore(&pCh
->Ibuf_spinlock
, flags
);
1996 ip2_start ( PTTY tty
)
1998 i2ChanStrPtr pCh
= DevTable
[tty
->index
];
2000 i2QueueCommands(PTYPE_BYPASS
, pCh
, 0, 1, CMD_RESUME
);
2001 i2QueueCommands(PTYPE_BYPASS
, pCh
, 100, 1, CMD_UNSUSPEND
);
2002 i2QueueCommands(PTYPE_BYPASS
, pCh
, 100, 1, CMD_RESUME
);
2003 #ifdef IP2DEBUG_WRITE
2004 printk (KERN_DEBUG
"IP2: start tx\n" );
2009 ip2_stop ( PTTY tty
)
2011 i2ChanStrPtr pCh
= DevTable
[tty
->index
];
2013 i2QueueCommands(PTYPE_BYPASS
, pCh
, 100, 1, CMD_SUSPEND
);
2014 #ifdef IP2DEBUG_WRITE
2015 printk (KERN_DEBUG
"IP2: stop tx\n" );
2019 /******************************************************************************/
2020 /* Device Ioctl Section */
2021 /******************************************************************************/
2023 static int ip2_tiocmget(struct tty_struct
*tty
, struct file
*file
)
2025 i2ChanStrPtr pCh
= DevTable
[tty
->index
];
2026 #ifdef ENABLE_DSSNOW
2034 FIXME - the following code is causing a NULL pointer dereference in
2035 2.3.51 in an interrupt handler. It's suppose to prompt the board
2036 to return the DSS signal status immediately. Why doesn't it do
2037 the same thing in 2.2.14?
2040 /* This thing is still busted in the 1.2.12 driver on 2.4.x
2041 and even hoses the serial console so the oops can be trapped.
2044 #ifdef ENABLE_DSSNOW
2045 i2QueueCommands(PTYPE_BYPASS
, pCh
, 100, 1, CMD_DSS_NOW
);
2047 init_waitqueue_entry(&wait
, current
);
2048 add_wait_queue(&pCh
->dss_now_wait
, &wait
);
2049 set_current_state( TASK_INTERRUPTIBLE
);
2051 serviceOutgoingFifo( pCh
->pMyBord
);
2055 set_current_state( TASK_RUNNING
);
2056 remove_wait_queue(&pCh
->dss_now_wait
, &wait
);
2058 if (signal_pending(current
)) {
2062 return ((pCh
->dataSetOut
& I2_RTS
) ? TIOCM_RTS
: 0)
2063 | ((pCh
->dataSetOut
& I2_DTR
) ? TIOCM_DTR
: 0)
2064 | ((pCh
->dataSetIn
& I2_DCD
) ? TIOCM_CAR
: 0)
2065 | ((pCh
->dataSetIn
& I2_RI
) ? TIOCM_RNG
: 0)
2066 | ((pCh
->dataSetIn
& I2_DSR
) ? TIOCM_DSR
: 0)
2067 | ((pCh
->dataSetIn
& I2_CTS
) ? TIOCM_CTS
: 0);
2070 static int ip2_tiocmset(struct tty_struct
*tty
, struct file
*file
,
2071 unsigned int set
, unsigned int clear
)
2073 i2ChanStrPtr pCh
= DevTable
[tty
->index
];
2078 if (set
& TIOCM_RTS
) {
2079 i2QueueCommands(PTYPE_INLINE
, pCh
, 100, 1, CMD_RTSUP
);
2080 pCh
->dataSetOut
|= I2_RTS
;
2082 if (set
& TIOCM_DTR
) {
2083 i2QueueCommands(PTYPE_INLINE
, pCh
, 100, 1, CMD_DTRUP
);
2084 pCh
->dataSetOut
|= I2_DTR
;
2087 if (clear
& TIOCM_RTS
) {
2088 i2QueueCommands(PTYPE_INLINE
, pCh
, 100, 1, CMD_RTSDN
);
2089 pCh
->dataSetOut
&= ~I2_RTS
;
2091 if (clear
& TIOCM_DTR
) {
2092 i2QueueCommands(PTYPE_INLINE
, pCh
, 100, 1, CMD_DTRDN
);
2093 pCh
->dataSetOut
&= ~I2_DTR
;
2095 serviceOutgoingFifo( pCh
->pMyBord
);
2099 /******************************************************************************/
2100 /* Function: ip2_ioctl() */
2101 /* Parameters: Pointer to tty structure */
2102 /* Pointer to file structure */
2105 /* Returns: Success or failure */
2110 /******************************************************************************/
2112 ip2_ioctl ( PTTY tty
, struct file
*pFile
, UINT cmd
, ULONG arg
)
2115 i2ChanStrPtr pCh
= DevTable
[tty
->index
];
2117 struct async_icount cprev
, cnow
; /* kernel counter temps */
2119 unsigned long flags
;
2120 void __user
*argp
= (void __user
*)arg
;
2127 ip2trace (CHANN
, ITRC_IOCTL
, ITRC_ENTER
, 2, cmd
, arg
);
2129 #ifdef IP2DEBUG_IOCTL
2130 printk(KERN_DEBUG
"IP2: ioctl cmd (%x), arg (%lx)\n", cmd
, arg
);
2136 ip2trace (CHANN
, ITRC_IOCTL
, 2, 1, rc
);
2138 rc
= get_serial_info(pCh
, argp
);
2145 ip2trace (CHANN
, ITRC_IOCTL
, 3, 1, rc
);
2147 rc
= set_serial_info(pCh
, argp
);
2153 rc
= tty_check_change(tty
);
2158 //return -ENOIOCTLCMD;
2161 //return -ENOIOCTLCMD;
2164 if (STOP_CHAR(tty
) != __DISABLED_CHAR
) {
2165 i2QueueCommands( PTYPE_BYPASS
, pCh
, 100, 1,
2166 CMD_XMIT_NOW(STOP_CHAR(tty
)));
2170 if (START_CHAR(tty
) != __DISABLED_CHAR
) {
2171 i2QueueCommands( PTYPE_BYPASS
, pCh
, 100, 1,
2172 CMD_XMIT_NOW(START_CHAR(tty
)));
2180 case TCSBRK
: /* SVID version: non-zero arg --> no break */
2181 rc
= tty_check_change(tty
);
2183 ip2trace (CHANN
, ITRC_IOCTL
, 4, 1, rc
);
2186 ip2_wait_until_sent(tty
,0);
2188 i2QueueCommands(PTYPE_INLINE
, pCh
, 100, 1, CMD_SEND_BRK(250));
2189 serviceOutgoingFifo( pCh
->pMyBord
);
2194 case TCSBRKP
: /* support for POSIX tcsendbreak() */
2195 rc
= tty_check_change(tty
);
2197 ip2trace (CHANN
, ITRC_IOCTL
, 5, 1, rc
);
2200 ip2_wait_until_sent(tty
,0);
2201 i2QueueCommands(PTYPE_INLINE
, pCh
, 100, 1,
2202 CMD_SEND_BRK(arg
? arg
*100 : 250));
2203 serviceOutgoingFifo ( pCh
->pMyBord
);
2209 ip2trace (CHANN
, ITRC_IOCTL
, 6, 1, rc
);
2211 rc
= put_user(C_CLOCAL(tty
) ? 1 : 0, (unsigned long __user
*)argp
);
2218 ip2trace (CHANN
, ITRC_IOCTL
, 7, 1, rc
);
2220 rc
= get_user(arg
,(unsigned long __user
*) argp
);
2223 tty
->termios
->c_cflag
= ((tty
->termios
->c_cflag
& ~CLOCAL
)
2224 | (arg
? CLOCAL
: 0));
2229 * Wait for any of the 4 modem inputs (DCD,RI,DSR,CTS) to change - mask
2230 * passed in arg for lines of interest (use |'ed TIOCM_RNG/DSR/CD/CTS
2231 * for masking). Caller should use TIOCGICOUNT to see which one it was
2234 write_lock_irqsave(&pB
->read_fifo_spinlock
, flags
);
2235 cprev
= pCh
->icount
; /* note the counters on entry */
2236 write_unlock_irqrestore(&pB
->read_fifo_spinlock
, flags
);
2237 i2QueueCommands(PTYPE_BYPASS
, pCh
, 100, 4,
2238 CMD_DCD_REP
, CMD_CTS_REP
, CMD_DSR_REP
, CMD_RI_REP
);
2239 init_waitqueue_entry(&wait
, current
);
2240 add_wait_queue(&pCh
->delta_msr_wait
, &wait
);
2241 set_current_state( TASK_INTERRUPTIBLE
);
2243 serviceOutgoingFifo( pCh
->pMyBord
);
2245 ip2trace (CHANN
, ITRC_IOCTL
, 10, 0 );
2249 ip2trace (CHANN
, ITRC_IOCTL
, 11, 0 );
2251 /* see if a signal did it */
2252 if (signal_pending(current
)) {
2256 write_lock_irqsave(&pB
->read_fifo_spinlock
, flags
);
2257 cnow
= pCh
->icount
; /* atomic copy */
2258 write_unlock_irqrestore(&pB
->read_fifo_spinlock
, flags
);
2259 if (cnow
.rng
== cprev
.rng
&& cnow
.dsr
== cprev
.dsr
&&
2260 cnow
.dcd
== cprev
.dcd
&& cnow
.cts
== cprev
.cts
) {
2261 rc
= -EIO
; /* no change => rc */
2264 if (((arg
& TIOCM_RNG
) && (cnow
.rng
!= cprev
.rng
)) ||
2265 ((arg
& TIOCM_DSR
) && (cnow
.dsr
!= cprev
.dsr
)) ||
2266 ((arg
& TIOCM_CD
) && (cnow
.dcd
!= cprev
.dcd
)) ||
2267 ((arg
& TIOCM_CTS
) && (cnow
.cts
!= cprev
.cts
)) ) {
2273 set_current_state( TASK_RUNNING
);
2274 remove_wait_queue(&pCh
->delta_msr_wait
, &wait
);
2276 i2QueueCommands(PTYPE_BYPASS
, pCh
, 100, 3,
2277 CMD_CTS_NREP
, CMD_DSR_NREP
, CMD_RI_NREP
);
2278 if ( ! (pCh
->flags
& ASYNC_CHECK_CD
)) {
2279 i2QueueCommands(PTYPE_BYPASS
, pCh
, 100, 1, CMD_DCD_NREP
);
2281 serviceOutgoingFifo( pCh
->pMyBord
);
2286 * The rest are not supported by this driver. By returning -ENOIOCTLCMD they
2287 * will be passed to the line discipline for it to handle.
2293 case TIOCSERGSTRUCT
:
2294 case TIOCSERGETMULTI
:
2295 case TIOCSERSETMULTI
:
2298 ip2trace (CHANN
, ITRC_IOCTL
, 12, 0 );
2304 ip2trace (CHANN
, ITRC_IOCTL
, ITRC_RETURN
, 0 );
2309 static int ip2_get_icount(struct tty_struct
*tty
,
2310 struct serial_icounter_struct
*icount
)
2312 i2ChanStrPtr pCh
= DevTable
[tty
->index
];
2314 struct async_icount cnow
; /* kernel counter temp */
2315 unsigned long flags
;
2323 * Get counter of input serial line interrupts (DCD,RI,DSR,CTS)
2324 * Return: write counters to the user passed counter struct
2325 * NB: both 1->0 and 0->1 transitions are counted except for RI where
2326 * only 0->1 is counted. The controller is quite capable of counting
2327 * both, but this done to preserve compatibility with the standard
2331 write_lock_irqsave(&pB
->read_fifo_spinlock
, flags
);
2333 write_unlock_irqrestore(&pB
->read_fifo_spinlock
, flags
);
2335 icount
->cts
= cnow
.cts
;
2336 icount
->dsr
= cnow
.dsr
;
2337 icount
->rng
= cnow
.rng
;
2338 icount
->dcd
= cnow
.dcd
;
2339 icount
->rx
= cnow
.rx
;
2340 icount
->tx
= cnow
.tx
;
2341 icount
->frame
= cnow
.frame
;
2342 icount
->overrun
= cnow
.overrun
;
2343 icount
->parity
= cnow
.parity
;
2344 icount
->brk
= cnow
.brk
;
2345 icount
->buf_overrun
= cnow
.buf_overrun
;
2349 /******************************************************************************/
2350 /* Function: GetSerialInfo() */
2351 /* Parameters: Pointer to channel structure */
2352 /* Pointer to old termios structure */
2353 /* Returns: Nothing */
2356 /* This is to support the setserial command, and requires processing of the */
2357 /* standard Linux serial structure. */
2358 /******************************************************************************/
2360 get_serial_info ( i2ChanStrPtr pCh
, struct serial_struct __user
*retinfo
)
2362 struct serial_struct tmp
;
2364 memset ( &tmp
, 0, sizeof(tmp
) );
2365 tmp
.type
= pCh
->pMyBord
->channelBtypes
.bid_value
[(pCh
->port_index
& (IP2_PORTS_PER_BOARD
-1))/16];
2366 if (BID_HAS_654(tmp
.type
)) {
2367 tmp
.type
= PORT_16650
;
2369 tmp
.type
= PORT_CIRRUS
;
2371 tmp
.line
= pCh
->port_index
;
2372 tmp
.port
= pCh
->pMyBord
->i2eBase
;
2373 tmp
.irq
= ip2config
.irq
[pCh
->port_index
/64];
2374 tmp
.flags
= pCh
->flags
;
2375 tmp
.baud_base
= pCh
->BaudBase
;
2376 tmp
.close_delay
= pCh
->ClosingDelay
;
2377 tmp
.closing_wait
= pCh
->ClosingWaitTime
;
2378 tmp
.custom_divisor
= pCh
->BaudDivisor
;
2379 return copy_to_user(retinfo
,&tmp
,sizeof(*retinfo
));
2382 /******************************************************************************/
2383 /* Function: SetSerialInfo() */
2384 /* Parameters: Pointer to channel structure */
2385 /* Pointer to old termios structure */
2386 /* Returns: Nothing */
2389 /* This function provides support for setserial, which uses the TIOCSSERIAL */
2390 /* ioctl. Not all setserial parameters are relevant. If the user attempts to */
2391 /* change the IRQ, address or type of the port the ioctl fails. */
2392 /******************************************************************************/
2394 set_serial_info( i2ChanStrPtr pCh
, struct serial_struct __user
*new_info
)
2396 struct serial_struct ns
;
2397 int old_flags
, old_baud_divisor
;
2399 if (copy_from_user(&ns
, new_info
, sizeof (ns
)))
2403 * We don't allow setserial to change IRQ, board address, type or baud
2404 * base. Also line nunber as such is meaningless but we use it for our
2405 * array index so it is fixed also.
2407 if ( (ns
.irq
!= ip2config
.irq
[pCh
->port_index
])
2408 || ((int) ns
.port
!= ((int) (pCh
->pMyBord
->i2eBase
)))
2409 || (ns
.baud_base
!= pCh
->BaudBase
)
2410 || (ns
.line
!= pCh
->port_index
) ) {
2414 old_flags
= pCh
->flags
;
2415 old_baud_divisor
= pCh
->BaudDivisor
;
2417 if ( !capable(CAP_SYS_ADMIN
) ) {
2418 if ( ( ns
.close_delay
!= pCh
->ClosingDelay
) ||
2419 ( (ns
.flags
& ~ASYNC_USR_MASK
) !=
2420 (pCh
->flags
& ~ASYNC_USR_MASK
) ) ) {
2424 pCh
->flags
= (pCh
->flags
& ~ASYNC_USR_MASK
) |
2425 (ns
.flags
& ASYNC_USR_MASK
);
2426 pCh
->BaudDivisor
= ns
.custom_divisor
;
2428 pCh
->flags
= (pCh
->flags
& ~ASYNC_FLAGS
) |
2429 (ns
.flags
& ASYNC_FLAGS
);
2430 pCh
->BaudDivisor
= ns
.custom_divisor
;
2431 pCh
->ClosingDelay
= ns
.close_delay
* HZ
/100;
2432 pCh
->ClosingWaitTime
= ns
.closing_wait
* HZ
/100;
2435 if ( ( (old_flags
& ASYNC_SPD_MASK
) != (pCh
->flags
& ASYNC_SPD_MASK
) )
2436 || (old_baud_divisor
!= pCh
->BaudDivisor
) ) {
2437 // Invalidate speed and reset parameters
2438 set_params( pCh
, NULL
);
2444 /******************************************************************************/
2445 /* Function: ip2_set_termios() */
2446 /* Parameters: Pointer to tty structure */
2447 /* Pointer to old termios structure */
2448 /* Returns: Nothing */
2453 /******************************************************************************/
2455 ip2_set_termios( PTTY tty
, struct ktermios
*old_termios
)
2457 i2ChanStrPtr pCh
= (i2ChanStrPtr
)tty
->driver_data
;
2459 #ifdef IP2DEBUG_IOCTL
2460 printk (KERN_DEBUG
"IP2: set termios %p\n", old_termios
);
2463 set_params( pCh
, old_termios
);
2466 /******************************************************************************/
2467 /* Function: ip2_set_line_discipline() */
2468 /* Parameters: Pointer to tty structure */
2469 /* Returns: Nothing */
2471 /* Description: Does nothing */
2474 /******************************************************************************/
2476 ip2_set_line_discipline ( PTTY tty
)
2478 #ifdef IP2DEBUG_IOCTL
2479 printk (KERN_DEBUG
"IP2: set line discipline\n" );
2482 ip2trace (((i2ChanStrPtr
)tty
->driver_data
)->port_index
, ITRC_IOCTL
, 16, 0 );
2486 /******************************************************************************/
2487 /* Function: SetLine Characteristics() */
2488 /* Parameters: Pointer to channel structure */
2489 /* Returns: Nothing */
2492 /* This routine is called to update the channel structure with the new line */
2493 /* characteristics, and send the appropriate commands to the board when they */
2495 /******************************************************************************/
2497 set_params( i2ChanStrPtr pCh
, struct ktermios
*o_tios
)
2499 tcflag_t cflag
, iflag
, lflag
;
2500 char stop_char
, start_char
;
2501 struct ktermios dummy
;
2503 lflag
= pCh
->pTTY
->termios
->c_lflag
;
2504 cflag
= pCh
->pTTY
->termios
->c_cflag
;
2505 iflag
= pCh
->pTTY
->termios
->c_iflag
;
2507 if (o_tios
== NULL
) {
2508 dummy
.c_lflag
= ~lflag
;
2509 dummy
.c_cflag
= ~cflag
;
2510 dummy
.c_iflag
= ~iflag
;
2515 switch ( cflag
& CBAUD
) {
2517 i2QueueCommands( PTYPE_BYPASS
, pCh
, 100, 2, CMD_RTSDN
, CMD_DTRDN
);
2518 pCh
->dataSetOut
&= ~(I2_DTR
| I2_RTS
);
2519 i2QueueCommands( PTYPE_INLINE
, pCh
, 100, 1, CMD_PAUSE(25));
2520 pCh
->pTTY
->termios
->c_cflag
|= (CBAUD
& o_tios
->c_cflag
);
2525 * This is the speed that is overloaded with all the other high
2526 * speeds, depending upon the flag settings.
2528 if ( ( pCh
->flags
& ASYNC_SPD_MASK
) == ASYNC_SPD_HI
) {
2529 pCh
->speed
= CBR_57600
;
2530 } else if ( (pCh
->flags
& ASYNC_SPD_MASK
) == ASYNC_SPD_VHI
) {
2531 pCh
->speed
= CBR_115200
;
2532 } else if ( (pCh
->flags
& ASYNC_SPD_MASK
) == ASYNC_SPD_CUST
) {
2533 pCh
->speed
= CBR_C1
;
2535 pCh
->speed
= CBR_38400
;
2538 case B50
: pCh
->speed
= CBR_50
; break;
2539 case B75
: pCh
->speed
= CBR_75
; break;
2540 case B110
: pCh
->speed
= CBR_110
; break;
2541 case B134
: pCh
->speed
= CBR_134
; break;
2542 case B150
: pCh
->speed
= CBR_150
; break;
2543 case B200
: pCh
->speed
= CBR_200
; break;
2544 case B300
: pCh
->speed
= CBR_300
; break;
2545 case B600
: pCh
->speed
= CBR_600
; break;
2546 case B1200
: pCh
->speed
= CBR_1200
; break;
2547 case B1800
: pCh
->speed
= CBR_1800
; break;
2548 case B2400
: pCh
->speed
= CBR_2400
; break;
2549 case B4800
: pCh
->speed
= CBR_4800
; break;
2550 case B9600
: pCh
->speed
= CBR_9600
; break;
2551 case B19200
: pCh
->speed
= CBR_19200
; break;
2552 case B57600
: pCh
->speed
= CBR_57600
; break;
2553 case B115200
: pCh
->speed
= CBR_115200
; break;
2554 case B153600
: pCh
->speed
= CBR_153600
; break;
2555 case B230400
: pCh
->speed
= CBR_230400
; break;
2556 case B307200
: pCh
->speed
= CBR_307200
; break;
2557 case B460800
: pCh
->speed
= CBR_460800
; break;
2558 case B921600
: pCh
->speed
= CBR_921600
; break;
2559 default: pCh
->speed
= CBR_9600
; break;
2561 if ( pCh
->speed
== CBR_C1
) {
2562 // Process the custom speed parameters.
2563 int bps
= pCh
->BaudBase
/ pCh
->BaudDivisor
;
2564 if ( bps
== 921600 ) {
2565 pCh
->speed
= CBR_921600
;
2568 i2QueueCommands( PTYPE_INLINE
, pCh
, 100, 1, CMD_BAUD_DEF1(bps
) );
2571 i2QueueCommands( PTYPE_INLINE
, pCh
, 100, 1, CMD_SETBAUD(pCh
->speed
));
2573 i2QueueCommands ( PTYPE_INLINE
, pCh
, 100, 2, CMD_DTRUP
, CMD_RTSUP
);
2574 pCh
->dataSetOut
|= (I2_DTR
| I2_RTS
);
2576 if ( (CSTOPB
& cflag
) ^ (CSTOPB
& o_tios
->c_cflag
))
2578 i2QueueCommands ( PTYPE_INLINE
, pCh
, 100, 1,
2579 CMD_SETSTOP( ( cflag
& CSTOPB
) ? CST_2
: CST_1
));
2581 if (((PARENB
|PARODD
) & cflag
) ^ ((PARENB
|PARODD
) & o_tios
->c_cflag
))
2583 i2QueueCommands ( PTYPE_INLINE
, pCh
, 100, 1,
2585 (cflag
& PARENB
? (cflag
& PARODD
? CSP_OD
: CSP_EV
) : CSP_NP
)
2589 /* byte size and parity */
2590 if ( (CSIZE
& cflag
)^(CSIZE
& o_tios
->c_cflag
))
2593 switch ( cflag
& CSIZE
) {
2594 case CS5
: datasize
= CSZ_5
; break;
2595 case CS6
: datasize
= CSZ_6
; break;
2596 case CS7
: datasize
= CSZ_7
; break;
2597 case CS8
: datasize
= CSZ_8
; break;
2598 default: datasize
= CSZ_5
; break; /* as per serial.c */
2600 i2QueueCommands ( PTYPE_INLINE
, pCh
, 100, 1, CMD_SETBITS(datasize
) );
2602 /* Process CTS flow control flag setting */
2603 if ( (cflag
& CRTSCTS
) ) {
2604 i2QueueCommands(PTYPE_INLINE
, pCh
, 100,
2605 2, CMD_CTSFL_ENAB
, CMD_RTSFL_ENAB
);
2607 i2QueueCommands(PTYPE_INLINE
, pCh
, 100,
2608 2, CMD_CTSFL_DSAB
, CMD_RTSFL_DSAB
);
2611 // Process XON/XOFF flow control flags settings
2613 stop_char
= STOP_CHAR(pCh
->pTTY
);
2614 start_char
= START_CHAR(pCh
->pTTY
);
2616 //////////// can't be \000
2617 if (stop_char
== __DISABLED_CHAR
)
2619 stop_char
= ~__DISABLED_CHAR
;
2621 if (start_char
== __DISABLED_CHAR
)
2623 start_char
= ~__DISABLED_CHAR
;
2625 /////////////////////////////////
2627 if ( o_tios
->c_cc
[VSTART
] != start_char
)
2629 i2QueueCommands(PTYPE_BYPASS
, pCh
, 100, 1, CMD_DEF_IXON(start_char
));
2630 i2QueueCommands(PTYPE_INLINE
, pCh
, 100, 1, CMD_DEF_OXON(start_char
));
2632 if ( o_tios
->c_cc
[VSTOP
] != stop_char
)
2634 i2QueueCommands(PTYPE_BYPASS
, pCh
, 100, 1, CMD_DEF_IXOFF(stop_char
));
2635 i2QueueCommands(PTYPE_INLINE
, pCh
, 100, 1, CMD_DEF_OXOFF(stop_char
));
2637 if (stop_char
== __DISABLED_CHAR
)
2639 stop_char
= ~__DISABLED_CHAR
; //TEST123
2642 if ((iflag
& (IXOFF
))^(o_tios
->c_iflag
& (IXOFF
)))
2644 if ( iflag
& IXOFF
) { // Enable XOFF output flow control
2645 i2QueueCommands(PTYPE_INLINE
, pCh
, 100, 1, CMD_OXON_OPT(COX_XON
));
2646 } else { // Disable XOFF output flow control
2648 i2QueueCommands(PTYPE_INLINE
, pCh
, 100, 1, CMD_OXON_OPT(COX_NONE
));
2651 if (start_char
== __DISABLED_CHAR
)
2655 if ((iflag
& (IXON
|IXANY
)) ^ (o_tios
->c_iflag
& (IXON
|IXANY
)))
2657 if ( iflag
& IXON
) {
2658 if ( iflag
& IXANY
) { // Enable XON/XANY output flow control
2659 i2QueueCommands(PTYPE_INLINE
, pCh
, 100, 1, CMD_IXON_OPT(CIX_XANY
));
2660 } else { // Enable XON output flow control
2661 i2QueueCommands(PTYPE_INLINE
, pCh
, 100, 1, CMD_IXON_OPT(CIX_XON
));
2663 } else { // Disable XON output flow control
2665 i2QueueCommands(PTYPE_INLINE
, pCh
, 100, 1, CMD_IXON_OPT(CIX_NONE
));
2668 if ( (iflag
& ISTRIP
) ^ ( o_tios
->c_iflag
& (ISTRIP
)) )
2670 i2QueueCommands(PTYPE_INLINE
, pCh
, 100, 1,
2671 CMD_ISTRIP_OPT((iflag
& ISTRIP
? 1 : 0)));
2673 if ( (iflag
& INPCK
) ^ ( o_tios
->c_iflag
& (INPCK
)) )
2675 i2QueueCommands(PTYPE_INLINE
, pCh
, 100, 1,
2676 CMD_PARCHK((iflag
& INPCK
) ? CPK_ENAB
: CPK_DSAB
));
2679 if ( (iflag
& (IGNBRK
|PARMRK
|BRKINT
|IGNPAR
))
2680 ^ ( o_tios
->c_iflag
& (IGNBRK
|PARMRK
|BRKINT
|IGNPAR
)) )
2685 if ( iflag
& IGNBRK
) { /* Ignore breaks altogether */
2686 /* Ignore breaks altogether */
2687 i2QueueCommands(PTYPE_INLINE
, pCh
, 100, 1, CMD_BRK_NREP
);
2689 if ( iflag
& BRKINT
) {
2690 if ( iflag
& PARMRK
) {
2691 brkrpt
= 0x0a; // exception an inline triple
2693 brkrpt
= 0x1a; // exception and NULL
2695 brkrpt
|= 0x04; // flush input
2697 if ( iflag
& PARMRK
) {
2698 brkrpt
= 0x0b; //POSIX triple \0377 \0 \0
2700 brkrpt
= 0x01; // Null only
2703 i2QueueCommands(PTYPE_INLINE
, pCh
, 100, 1, CMD_BRK_REP(brkrpt
));
2706 if (iflag
& IGNPAR
) {
2708 /* would be 2 for not cirrus bug */
2709 /* would be 0x20 cept for cirrus bug */
2711 if ( iflag
& PARMRK
) {
2713 * Replace error characters with 3-byte sequence (\0377,\0,char)
2716 i2QueueCommands(PTYPE_INLINE
, pCh
, 100, 1, CMD_ISTRIP_OPT((char)0));
2721 i2QueueCommands(PTYPE_INLINE
, pCh
, 100, 1, CMD_SET_ERROR(parrpt
));
2723 if (cflag
& CLOCAL
) {
2724 // Status reporting fails for DCD if this is off
2725 i2QueueCommands(PTYPE_INLINE
, pCh
, 100, 1, CMD_DCD_NREP
);
2726 pCh
->flags
&= ~ASYNC_CHECK_CD
;
2728 i2QueueCommands(PTYPE_INLINE
, pCh
, 100, 1, CMD_DCD_REP
);
2729 pCh
->flags
|= ASYNC_CHECK_CD
;
2733 i2DrainOutput( pCh
, 100 );
2736 /******************************************************************************/
2737 /* IPL Device Section */
2738 /******************************************************************************/
2740 /******************************************************************************/
2741 /* Function: ip2_ipl_read() */
2742 /* Parameters: Pointer to device inode */
2743 /* Pointer to file structure */
2744 /* Pointer to data */
2745 /* Number of bytes to read */
2746 /* Returns: Success or failure */
2748 /* Description: Ugly */
2751 /******************************************************************************/
2755 ip2_ipl_read(struct file
*pFile
, char __user
*pData
, size_t count
, loff_t
*off
)
2757 unsigned int minor
= iminor(pFile
->f_path
.dentry
->d_inode
);
2761 printk (KERN_DEBUG
"IP2IPL: read %p, %d bytes\n", pData
, count
);
2765 case 0: // IPL device
2768 case 1: // Status dump
2771 case 2: // Ping device
2774 case 3: // Trace device
2775 rc
= DumpTraceBuffer ( pData
, count
);
2777 case 4: // Trace device
2778 rc
= DumpFifoBuffer ( pData
, count
);
2788 DumpFifoBuffer ( char __user
*pData
, int count
)
2792 rc
= copy_to_user(pData
, DBGBuf
, count
);
2794 printk(KERN_DEBUG
"Last index %d\n", I
);
2797 #endif /* DEBUG_FIFO */
2802 DumpTraceBuffer ( char __user
*pData
, int count
)
2804 #ifdef IP2DEBUG_TRACE
2808 int *pIndex
= (int __user
*)pData
;
2810 if ( count
< (sizeof(int) * 6) ) {
2813 rc
= put_user(tracewrap
, pIndex
);
2814 rc
= put_user(TRACEMAX
, ++pIndex
);
2815 rc
= put_user(tracestrip
, ++pIndex
);
2816 rc
= put_user(tracestuff
, ++pIndex
);
2817 pData
+= sizeof(int) * 6;
2818 count
-= sizeof(int) * 6;
2820 dumpcount
= tracestuff
- tracestrip
;
2821 if ( dumpcount
< 0 ) {
2822 dumpcount
+= TRACEMAX
;
2824 if ( dumpcount
> count
) {
2827 chunk
= TRACEMAX
- tracestrip
;
2828 if ( dumpcount
> chunk
) {
2829 rc
= copy_to_user(pData
, &tracebuf
[tracestrip
],
2830 chunk
* sizeof(tracebuf
[0]) );
2831 pData
+= chunk
* sizeof(tracebuf
[0]);
2833 chunk
= dumpcount
- chunk
;
2837 rc
= copy_to_user(pData
, &tracebuf
[tracestrip
],
2838 chunk
* sizeof(tracebuf
[0]) );
2839 tracestrip
+= chunk
;
2842 rc
= put_user(tracestrip
, ++pIndex
);
2843 rc
= put_user(tracestuff
, ++pIndex
);
2851 /******************************************************************************/
2852 /* Function: ip2_ipl_write() */
2854 /* Pointer to file structure */
2855 /* Pointer to data */
2856 /* Number of bytes to write */
2857 /* Returns: Success or failure */
2862 /******************************************************************************/
2864 ip2_ipl_write(struct file
*pFile
, const char __user
*pData
, size_t count
, loff_t
*off
)
2867 printk (KERN_DEBUG
"IP2IPL: write %p, %d bytes\n", pData
, count
);
2872 /******************************************************************************/
2873 /* Function: ip2_ipl_ioctl() */
2874 /* Parameters: Pointer to device inode */
2875 /* Pointer to file structure */
2878 /* Returns: Success or failure */
2883 /******************************************************************************/
2885 ip2_ipl_ioctl (struct file
*pFile
, UINT cmd
, ULONG arg
)
2887 unsigned int iplminor
= iminor(pFile
->f_path
.dentry
->d_inode
);
2889 void __user
*argp
= (void __user
*)arg
;
2890 ULONG __user
*pIndex
= argp
;
2891 i2eBordStrPtr pB
= i2BoardPtrTable
[iplminor
/ 4];
2895 printk (KERN_DEBUG
"IP2IPL: ioctl cmd %d, arg %ld\n", cmd
, arg
);
2900 switch ( iplminor
) {
2901 case 0: // IPL device
2904 case 1: // Status dump
2909 case 64: /* Driver - ip2stat */
2910 rc
= put_user(-1, pIndex
++ );
2911 rc
= put_user(irq_counter
, pIndex
++ );
2912 rc
= put_user(bh_counter
, pIndex
++ );
2915 case 65: /* Board - ip2stat */
2917 rc
= copy_to_user(argp
, pB
, sizeof(i2eBordStr
));
2918 rc
= put_user(inb(pB
->i2eStatus
),
2919 (ULONG __user
*)(arg
+ (ULONG
)(&pB
->i2eStatus
) - (ULONG
)pB
) );
2926 if (cmd
< IP2_MAX_PORTS
) {
2927 pCh
= DevTable
[cmd
];
2930 rc
= copy_to_user(argp
, pCh
, sizeof(i2ChanStr
));
2940 case 2: // Ping device
2943 case 3: // Trace device
2945 * akpm: This used to write a whole bunch of function addresses
2946 * to userspace, which generated lots of put_user() warnings.
2947 * I killed it all. Just return "success" and don't do
2964 /******************************************************************************/
2965 /* Function: ip2_ipl_open() */
2966 /* Parameters: Pointer to device inode */
2967 /* Pointer to file structure */
2968 /* Returns: Success or failure */
2973 /******************************************************************************/
2975 ip2_ipl_open( struct inode
*pInode
, struct file
*pFile
)
2979 printk (KERN_DEBUG
"IP2IPL: open\n" );
2981 cycle_kernel_lock();
2986 proc_ip2mem_show(struct seq_file
*m
, void *v
)
2993 #define FMTLINE "%3d: 0x%08x 0x%08x 0%011o 0%011o\n"
2994 #define FMTLIN2 " 0x%04x 0x%04x tx flow 0x%x\n"
2995 #define FMTLIN3 " 0x%04x 0x%04x rc flow\n"
2999 for( i
= 0; i
< IP2_MAX_BOARDS
; ++i
) {
3000 pB
= i2BoardPtrTable
[i
];
3002 seq_printf(m
,"board %d:\n",i
);
3003 seq_printf(m
,"\tFifo rem: %d mty: %x outM %x\n",
3004 pB
->i2eFifoRemains
,pB
->i2eWaitingForEmptyFifo
,pB
->i2eOutMailWaiting
);
3008 seq_printf(m
,"#: tty flags, port flags, cflags, iflags\n");
3009 for (i
=0; i
< IP2_MAX_PORTS
; i
++) {
3013 if (tty
&& tty
->count
) {
3014 seq_printf(m
,FMTLINE
,i
,(int)tty
->flags
,pCh
->flags
,
3015 tty
->termios
->c_cflag
,tty
->termios
->c_iflag
);
3017 seq_printf(m
,FMTLIN2
,
3018 pCh
->outfl
.asof
,pCh
->outfl
.room
,pCh
->channelNeeds
);
3019 seq_printf(m
,FMTLIN3
,pCh
->infl
.asof
,pCh
->infl
.room
);
3026 static int proc_ip2mem_open(struct inode
*inode
, struct file
*file
)
3028 return single_open(file
, proc_ip2mem_show
, NULL
);
3031 static const struct file_operations ip2mem_proc_fops
= {
3032 .owner
= THIS_MODULE
,
3033 .open
= proc_ip2mem_open
,
3035 .llseek
= seq_lseek
,
3036 .release
= single_release
,
3040 * This is the handler for /proc/tty/driver/ip2
3042 * This stretch of code has been largely plagerized from at least three
3043 * different sources including ip2mkdev.c and a couple of other drivers.
3044 * The bugs are all mine. :-) =mhw=
3046 static int ip2_proc_show(struct seq_file
*m
, void *v
)
3055 seq_printf(m
, "ip2info: 1.0 driver: %s\n", pcVersion
);
3056 seq_printf(m
, "Driver: SMajor=%d CMajor=%d IMajor=%d MaxBoards=%d MaxBoxes=%d MaxPorts=%d\n",
3057 IP2_TTY_MAJOR
, IP2_CALLOUT_MAJOR
, IP2_IPL_MAJOR
,
3058 IP2_MAX_BOARDS
, ABS_MAX_BOXES
, ABS_BIGGEST_BOX
);
3060 for( i
= 0; i
< IP2_MAX_BOARDS
; ++i
) {
3061 /* This need to be reset for a board by board count... */
3063 pB
= i2BoardPtrTable
[i
];
3065 switch( pB
->i2ePom
.e
.porID
& ~POR_ID_RESERVED
)
3068 seq_printf(m
, "Board %d: EX ports=", i
);
3070 for( box
= 0; box
< ABS_MAX_BOXES
; ++box
)
3074 if( pB
->i2eChannelMap
[box
] != 0 ) ++boxes
;
3075 for( j
= 0; j
< ABS_BIGGEST_BOX
; ++j
)
3077 if( pB
->i2eChannelMap
[box
] & 1<< j
) {
3081 seq_printf(m
, "%s%d", sep
, ports
);
3085 seq_printf(m
, " boxes=%d width=%d", boxes
, pB
->i2eDataWidth16
? 16 : 8);
3089 seq_printf(m
, "Board %d: ISA-4 ports=4 boxes=1", i
);
3094 seq_printf(m
, "Board %d: ISA-8-std ports=8 boxes=1", i
);
3099 seq_printf(m
, "Board %d: ISA-8-RJ11 ports=8 boxes=1", i
);
3104 seq_printf(m
, "Board %d: unknown", i
);
3105 /* Don't try and probe for minor numbers */
3110 /* Don't try and probe for minor numbers */
3111 seq_printf(m
, "Board %d: vacant", i
);
3116 seq_puts(m
, " 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 seq_printf(m
, "%s%d", sep
,
3125 j
+ ABS_BIGGEST_BOX
*
3126 (box
+i
*ABS_MAX_BOXES
));
3137 static int ip2_proc_open(struct inode
*inode
, struct file
*file
)
3139 return single_open(file
, ip2_proc_show
, NULL
);
3142 static const struct file_operations ip2_proc_fops
= {
3143 .owner
= THIS_MODULE
,
3144 .open
= ip2_proc_open
,
3146 .llseek
= seq_lseek
,
3147 .release
= single_release
,
3150 /******************************************************************************/
3151 /* Function: ip2trace() */
3152 /* Parameters: Value to add to trace buffer */
3153 /* Returns: Nothing */
3158 /******************************************************************************/
3159 #ifdef IP2DEBUG_TRACE
3161 ip2trace (unsigned short pn
, unsigned char cat
, unsigned char label
, unsigned long codes
, ...)
3164 unsigned long *pCode
= &codes
;
3165 union ip2breadcrumb bc
;
3169 tracebuf
[tracestuff
++] = jiffies
;
3170 if ( tracestuff
== TRACEMAX
) {
3173 if ( tracestuff
== tracestrip
) {
3174 if ( ++tracestrip
== TRACEMAX
) {
3180 bc
.hdr
.port
= 0xff & pn
;
3182 bc
.hdr
.codes
= (unsigned char)( codes
& 0xff );
3183 bc
.hdr
.label
= label
;
3184 tracebuf
[tracestuff
++] = bc
.value
;
3187 if ( tracestuff
== TRACEMAX
) {
3190 if ( tracestuff
== tracestrip
) {
3191 if ( ++tracestrip
== TRACEMAX
) {
3200 tracebuf
[tracestuff
++] = *++pCode
;
3206 MODULE_LICENSE("GPL");
3208 static struct pci_device_id ip2main_pci_tbl
[] __devinitdata
= {
3209 { PCI_DEVICE(PCI_VENDOR_ID_COMPUTONE
, PCI_DEVICE_ID_COMPUTONE_IP2EX
) },
3213 MODULE_DEVICE_TABLE(pci
, ip2main_pci_tbl
);