2 * Copyright 2003 Digi International (www.digi.com)
3 * Scott H Kilau <Scott_Kilau at digi dot com>
5 * This program is free software; you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published by
7 * the Free Software Foundation; either version 2, or (at your option)
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY, EXPRESS OR IMPLIED; without even the
12 * implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
13 * PURPOSE. See the GNU General Public License for more details.
15 * You should have received a copy of the GNU General Public License
16 * along with this program; if not, write to the Free Software
17 * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
20 * NOTE TO LINUX KERNEL HACKERS: DO NOT REFORMAT THIS CODE!
22 * This is shared code between Digi's CVS archive and the
23 * Linux Kernel sources.
24 * Changing the source just for reformatting needlessly breaks
25 * our CVS diff history.
27 * Send any bug fixes/changes to: Eng.Linux at digi dot com.
33 #include <linux/kernel.h>
34 #include <linux/module.h>
35 #include <linux/pci.h>
36 #include <linux/delay.h> /* For udelay */
37 #include <linux/slab.h>
38 #include <asm/uaccess.h> /* For copy_from_user/copy_to_user */
39 #include <linux/sched.h>
41 #include <linux/interrupt.h> /* For tasklet and interrupt structs/defines */
42 #include <linux/ctype.h>
43 #include <linux/tty.h>
44 #include <linux/tty_flip.h>
45 #include <linux/serial_reg.h>
46 #include <asm/io.h> /* For read[bwl]/write[bwl] */
48 #include <linux/string.h>
49 #include <linux/device.h>
50 #include <linux/kdev_t.h>
52 #include "dgap_driver.h"
53 #include "dgap_conf.h"
54 #include "dgap_parse.h"
55 #include "dgap_types.h"
57 #define init_MUTEX(sem) sema_init(sem, 1)
58 #define DECLARE_MUTEX(name) \
59 struct semaphore name = __SEMAPHORE_INITIALIZER(name, 1)
61 MODULE_LICENSE("GPL");
62 MODULE_AUTHOR("Digi International, http://www.digi.com");
63 MODULE_DESCRIPTION("Driver for the Digi International EPCA PCI based product line");
64 MODULE_SUPPORTED_DEVICE("dgap");
67 * insmod command line overrideable parameters
69 * NOTE: we use a set of macros to create the variables, which allows
70 * us to specify the variable type, name, initial value, and description.
72 PARM_INT(debug, 0x00, 0644, "Driver debugging level");
73 PARM_INT(rawreadok, 1, 0644, "Bypass flip buffers on input");
74 PARM_INT(trcbuf_size, 0x100000, 0644, "Debugging trace buffer size.");
77 /**************************************************************************
79 * protos for this file
83 static int dgap_start(void);
84 static void dgap_init_globals(void);
85 static int dgap_found_board(struct pci_dev *pdev, int id);
86 static void dgap_cleanup_board(struct board_t *brd);
87 static void dgap_poll_handler(ulong dummy);
88 static int dgap_init_pci(void);
89 static int dgap_init_one(struct pci_dev *pdev, const struct pci_device_id *ent);
90 static void dgap_remove_one(struct pci_dev *dev);
91 static int dgap_probe1(struct pci_dev *pdev, int card_type);
92 static void dgap_mbuf(struct board_t *brd, const char *fmt, ...);
93 static int dgap_do_remap(struct board_t *brd);
94 static irqreturn_t dgap_intr(int irq, void *voidbrd);
96 /* Our function prototypes */
97 static int dgap_tty_open(struct tty_struct *tty, struct file *file);
98 static void dgap_tty_close(struct tty_struct *tty, struct file *file);
99 static int dgap_block_til_ready(struct tty_struct *tty, struct file *file, struct channel_t *ch);
100 static int dgap_tty_ioctl(struct tty_struct *tty, unsigned int cmd, unsigned long arg);
101 static int dgap_tty_digigeta(struct tty_struct *tty, struct digi_t __user *retinfo);
102 static int dgap_tty_digiseta(struct tty_struct *tty, struct digi_t __user *new_info);
103 static int dgap_tty_digigetedelay(struct tty_struct *tty, int __user *retinfo);
104 static int dgap_tty_digisetedelay(struct tty_struct *tty, int __user *new_info);
105 static int dgap_tty_write_room(struct tty_struct* tty);
106 static int dgap_tty_chars_in_buffer(struct tty_struct* tty);
107 static void dgap_tty_start(struct tty_struct *tty);
108 static void dgap_tty_stop(struct tty_struct *tty);
109 static void dgap_tty_throttle(struct tty_struct *tty);
110 static void dgap_tty_unthrottle(struct tty_struct *tty);
111 static void dgap_tty_flush_chars(struct tty_struct *tty);
112 static void dgap_tty_flush_buffer(struct tty_struct *tty);
113 static void dgap_tty_hangup(struct tty_struct *tty);
114 static int dgap_wait_for_drain(struct tty_struct *tty);
115 static int dgap_set_modem_info(struct tty_struct *tty, unsigned int command, unsigned int __user *value);
116 static int dgap_get_modem_info(struct channel_t *ch, unsigned int __user *value);
117 static int dgap_tty_digisetcustombaud(struct tty_struct *tty, int __user *new_info);
118 static int dgap_tty_digigetcustombaud(struct tty_struct *tty, int __user *retinfo);
119 static int dgap_tty_tiocmget(struct tty_struct *tty);
120 static int dgap_tty_tiocmset(struct tty_struct *tty, unsigned int set, unsigned int clear);
121 static int dgap_tty_send_break(struct tty_struct *tty, int msec);
122 static void dgap_tty_wait_until_sent(struct tty_struct *tty, int timeout);
123 static int dgap_tty_write(struct tty_struct *tty, const unsigned char *buf, int count);
124 static void dgap_tty_set_termios(struct tty_struct *tty, struct ktermios *old_termios);
125 static int dgap_tty_put_char(struct tty_struct *tty, unsigned char c);
126 static void dgap_tty_send_xchar(struct tty_struct *tty, char ch);
128 int dgap_tty_register(struct board_t *brd);
129 int dgap_tty_preinit(void);
130 int dgap_tty_init(struct board_t *);
131 void dgap_tty_post_uninit(void);
132 void dgap_tty_uninit(struct board_t *);
133 void dgap_carrier(struct channel_t *ch);
134 void dgap_input(struct channel_t *ch);
137 * Our function prototypes from dgap_fep5
139 static void dgap_cmdw_ext(struct channel_t *ch, u16 cmd, u16 word, uint ncmds);
140 static int dgap_event(struct board_t *bd);
143 * Function prototypes from dgap_parse.c.
145 static int dgap_gettok(char **in, struct cnode *p);
146 static char *dgap_getword(char **in);
147 static char *dgap_savestring(char *s);
148 static struct cnode *dgap_newnode(int t);
149 static int dgap_checknode(struct cnode *p);
150 static void dgap_err(char *s);
153 * Function prototypes from dgap_sysfs.h
161 void dgap_create_ports_sysfiles(struct board_t *bd);
162 void dgap_remove_ports_sysfiles(struct board_t *bd);
164 void dgap_create_driver_sysfiles(struct pci_driver *);
165 void dgap_remove_driver_sysfiles(struct pci_driver *);
167 int dgap_tty_class_init(void);
168 int dgap_tty_class_destroy(void);
170 void dgap_create_tty_sysfs(struct un_t *un, struct device *c);
171 void dgap_remove_tty_sysfs(struct device *c);
173 /* Driver load/unload functions */
174 int dgap_init_module(void);
175 void dgap_cleanup_module(void);
177 module_init(dgap_init_module);
178 module_exit(dgap_cleanup_module);
182 * File operations permitted on Control/Management major.
184 static struct file_operations DgapBoardFops =
186 .owner = THIS_MODULE,
194 struct board_t *dgap_Board[MAXBOARDS];
195 DEFINE_SPINLOCK(dgap_global_lock);
196 ulong dgap_poll_counter;
197 char *dgap_config_buf;
198 int dgap_driver_state = DRIVER_INITIALIZED;
199 DEFINE_SPINLOCK(dgap_dl_lock);
200 wait_queue_head_t dgap_dl_wait;
202 int dgap_poll_tick = 20; /* Poll interval - 20 ms */
207 static int dgap_Major_Control_Registered = FALSE;
208 static uint dgap_driver_start = FALSE;
210 static struct class * dgap_class;
212 static struct board_t *dgap_BoardsByMajor[256];
213 static uchar *dgap_TmpWriteBuf = NULL;
214 static DECLARE_MUTEX(dgap_TmpWriteSem);
215 static uint dgap_count = 500;
220 static DEFINE_SPINLOCK(dgap_poll_lock); /* Poll scheduling lock */
221 static ulong dgap_poll_time; /* Time of next poll */
222 static uint dgap_poll_stop; /* Used to tell poller to stop */
223 static struct timer_list dgap_poll_timer;
226 static struct pci_device_id dgap_pci_tbl[] = {
227 { DIGI_VID, PCI_DEVICE_XEM_DID, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0 },
228 { DIGI_VID, PCI_DEVICE_CX_DID, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 1 },
229 { DIGI_VID, PCI_DEVICE_CX_IBM_DID, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 2 },
230 { DIGI_VID, PCI_DEVICE_EPCJ_DID, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 3 },
231 { DIGI_VID, PCI_DEVICE_920_2_DID, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 4 },
232 { DIGI_VID, PCI_DEVICE_920_4_DID, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 5 },
233 { DIGI_VID, PCI_DEVICE_920_8_DID, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 6 },
234 { DIGI_VID, PCI_DEVICE_XR_DID, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 7 },
235 { DIGI_VID, PCI_DEVICE_XRJ_DID, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 8 },
236 { DIGI_VID, PCI_DEVICE_XR_422_DID, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 9 },
237 { DIGI_VID, PCI_DEVICE_XR_IBM_DID, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 10 },
238 { DIGI_VID, PCI_DEVICE_XR_SAIP_DID, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 11 },
239 { DIGI_VID, PCI_DEVICE_XR_BULL_DID, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 12 },
240 { DIGI_VID, PCI_DEVICE_920_8_HP_DID, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 13 },
241 { DIGI_VID, PCI_DEVICE_XEM_HP_DID, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 14 },
242 {0,} /* 0 terminated list. */
244 MODULE_DEVICE_TABLE(pci, dgap_pci_tbl);
248 * A generic list of Product names, PCI Vendor ID, and PCI Device ID.
257 static struct board_id dgap_Ids[] =
259 { PPCM, PCI_DEVICE_XEM_NAME, 64, (T_PCXM | T_PCLITE | T_PCIBUS) },
260 { PCX, PCI_DEVICE_CX_NAME, 128, (T_CX | T_PCIBUS) },
261 { PCX, PCI_DEVICE_CX_IBM_NAME, 128, (T_CX | T_PCIBUS) },
262 { PEPC, PCI_DEVICE_EPCJ_NAME, 224, (T_EPC | T_PCIBUS) },
263 { APORT2_920P, PCI_DEVICE_920_2_NAME, 2, (T_PCXR | T_PCLITE | T_PCIBUS) },
264 { APORT4_920P, PCI_DEVICE_920_4_NAME, 4, (T_PCXR | T_PCLITE | T_PCIBUS) },
265 { APORT8_920P, PCI_DEVICE_920_8_NAME, 8, (T_PCXR | T_PCLITE | T_PCIBUS) },
266 { PAPORT8, PCI_DEVICE_XR_NAME, 8, (T_PCXR | T_PCLITE | T_PCIBUS) },
267 { PAPORT8, PCI_DEVICE_XRJ_NAME, 8, (T_PCXR | T_PCLITE | T_PCIBUS) },
268 { PAPORT8, PCI_DEVICE_XR_422_NAME, 8, (T_PCXR | T_PCLITE | T_PCIBUS) },
269 { PAPORT8, PCI_DEVICE_XR_IBM_NAME, 8, (T_PCXR | T_PCLITE | T_PCIBUS) },
270 { PAPORT8, PCI_DEVICE_XR_SAIP_NAME, 8, (T_PCXR | T_PCLITE | T_PCIBUS) },
271 { PAPORT8, PCI_DEVICE_XR_BULL_NAME, 8, (T_PCXR | T_PCLITE | T_PCIBUS) },
272 { APORT8_920P, PCI_DEVICE_920_8_HP_NAME, 8, (T_PCXR | T_PCLITE | T_PCIBUS) },
273 { PPCM, PCI_DEVICE_XEM_HP_NAME, 64, (T_PCXM | T_PCLITE | T_PCIBUS) },
274 {0,} /* 0 terminated list. */
277 static struct pci_driver dgap_driver = {
279 .probe = dgap_init_one,
280 .id_table = dgap_pci_tbl,
281 .remove = dgap_remove_one,
285 char *dgap_state_text[] = {
287 "Configuration for board not found.\n\t\t\tRun mpi to configure board.",
293 "Need Device Creation",
294 "Requested Device Creation",
295 "Finished Device Creation",
299 "Finished BIOS Load",
304 "Requested PROC creation",
305 "Finished PROC creation",
309 char *dgap_driver_state_text[] = {
310 "Driver Initialized",
311 "Driver needs configuration load.",
312 "Driver requested configuration from download daemon.",
317 * Default transparent print information.
319 static struct digi_t dgap_digi_init = {
320 .digi_flags = DIGI_COOK, /* Flags */
321 .digi_maxcps = 100, /* Max CPS */
322 .digi_maxchar = 50, /* Max chars in print queue */
323 .digi_bufsize = 100, /* Printer buffer size */
324 .digi_onlen = 4, /* size of printer on string */
325 .digi_offlen = 4, /* size of printer off string */
326 .digi_onstr = "\033[5i", /* ANSI printer on string ] */
327 .digi_offstr = "\033[4i", /* ANSI printer off string ] */
328 .digi_term = "ansi" /* default terminal type */
333 * Define a local default termios struct. All ports will be created
334 * with this termios initially.
336 * This defines a raw port at 9600 baud, 8 data bits, no parity,
340 static struct ktermios DgapDefaultTermios =
342 .c_iflag = (DEFAULT_IFLAGS), /* iflags */
343 .c_oflag = (DEFAULT_OFLAGS), /* oflags */
344 .c_cflag = (DEFAULT_CFLAGS), /* cflags */
345 .c_lflag = (DEFAULT_LFLAGS), /* lflags */
350 static const struct tty_operations dgap_tty_ops = {
351 .open = dgap_tty_open,
352 .close = dgap_tty_close,
353 .write = dgap_tty_write,
354 .write_room = dgap_tty_write_room,
355 .flush_buffer = dgap_tty_flush_buffer,
356 .chars_in_buffer = dgap_tty_chars_in_buffer,
357 .flush_chars = dgap_tty_flush_chars,
358 .ioctl = dgap_tty_ioctl,
359 .set_termios = dgap_tty_set_termios,
360 .stop = dgap_tty_stop,
361 .start = dgap_tty_start,
362 .throttle = dgap_tty_throttle,
363 .unthrottle = dgap_tty_unthrottle,
364 .hangup = dgap_tty_hangup,
365 .put_char = dgap_tty_put_char,
366 .tiocmget = dgap_tty_tiocmget,
367 .tiocmset = dgap_tty_tiocmset,
368 .break_ctl = dgap_tty_send_break,
369 .wait_until_sent = dgap_tty_wait_until_sent,
370 .send_xchar = dgap_tty_send_xchar
374 * Our needed internal static variables from dgap_parse.c
376 static struct cnode dgap_head;
378 static char dgap_cword[MAXCWORD];
385 static struct toklist dgap_tlist[] = {
386 { BEGIN, "config_begin" },
387 { END, "config_end" },
389 { PCX, "Digi_AccelePort_C/X_PCI" }, /* C/X_PCI */
390 { PEPC, "Digi_AccelePort_EPC/X_PCI" }, /* EPC/X_PCI */
391 { PPCM, "Digi_AccelePort_Xem_PCI" }, /* PCI/Xem */
392 { APORT2_920P, "Digi_AccelePort_2r_920_PCI" },
393 { APORT4_920P, "Digi_AccelePort_4r_920_PCI" },
394 { APORT8_920P, "Digi_AccelePort_8r_920_PCI" },
395 { PAPORT4, "Digi_AccelePort_4r_PCI(EIA-232/RS-422)" },
396 { PAPORT8, "Digi_AccelePort_8r_PCI(EIA-232/RS-422)" },
398 { PCIINFO, "pciinfo" },
401 { CONC, "concentrator" },
411 { CONNECT, "connect" },
412 { METHOD, "method" },
413 { STATUS, "status" },
414 { CUSTOM, "Custom" },
420 { NPORTS, "nports" },
425 { ALTPIN, "altpin" },
426 { USEINTR, "useintr" },
427 { TTSIZ, "ttysize" },
429 { BSSIZ, "boardsize" },
430 { UNTSIZ, "schedsize" },
431 { F2SIZ, "f2200size" },
432 { VPSIZ, "vpixsize" },
436 /************************************************************************
438 * Driver load/unload functions
440 ************************************************************************/
445 * Module load. This is where it all starts.
447 int dgap_init_module(void)
451 APR(("%s, Digi International Part Number %s\n", DG_NAME, DG_PART));
454 * Initialize global stuff
463 * Find and configure all the cards
465 rc = dgap_init_pci();
468 * If something went wrong in the scan, bail out of driver.
471 /* Only unregister the pci driver if it was actually registered. */
473 pci_unregister_driver(&dgap_driver);
475 printk("WARNING: dgap driver load failed. No DGAP boards found.\n");
477 dgap_cleanup_module();
480 dgap_create_driver_sysfiles(&dgap_driver);
483 DPR_INIT(("Finished init_module. Returning %d\n", rc));
491 static int dgap_start(void)
496 if (dgap_driver_start == FALSE) {
498 dgap_driver_start = TRUE;
500 /* make sure that the globals are init'd before we do anything else */
505 APR(("For the tools package or updated drivers please visit http://www.digi.com\n"));
508 * Register our base character device into the kernel.
509 * This allows the download daemon to connect to the downld device
510 * before any of the boards are init'ed.
512 if (!dgap_Major_Control_Registered) {
514 * Register management/dpa devices
516 rc = register_chrdev(DIGI_DGAP_MAJOR, "dgap", &DgapBoardFops);
518 APR(("Can't register dgap driver device (%d)\n", rc));
522 dgap_class = class_create(THIS_MODULE, "dgap_mgmt");
523 device_create(dgap_class, NULL,
524 MKDEV(DIGI_DGAP_MAJOR, 0),
526 device_create(dgap_class, NULL,
527 MKDEV(DIGI_DGAP_MAJOR, 1),
528 NULL, "dgap_downld");
529 dgap_Major_Control_Registered = TRUE;
533 * Init any global tty stuff.
535 rc = dgap_tty_preinit();
538 APR(("tty preinit - not enough memory (%d)\n", rc));
542 /* Start the poller */
543 DGAP_LOCK(dgap_poll_lock, flags);
544 init_timer(&dgap_poll_timer);
545 dgap_poll_timer.function = dgap_poll_handler;
546 dgap_poll_timer.data = 0;
547 dgap_poll_time = jiffies + dgap_jiffies_from_ms(dgap_poll_tick);
548 dgap_poll_timer.expires = dgap_poll_time;
549 DGAP_UNLOCK(dgap_poll_lock, flags);
551 add_timer(&dgap_poll_timer);
553 dgap_driver_state = DRIVER_NEED_CONFIG_LOAD;
561 * Register pci driver, and return how many boards we have.
563 static int dgap_init_pci(void)
565 return pci_register_driver(&dgap_driver);
569 /* returns count (>= 0), or negative on error */
570 static int dgap_init_one(struct pci_dev *pdev, const struct pci_device_id *ent)
574 /* wake up and enable device */
575 rc = pci_enable_device(pdev);
580 rc = dgap_probe1(pdev, ent->driver_data);
583 DPR_INIT(("Incrementing numboards to %d\n", dgap_NumBoards));
590 static int dgap_probe1(struct pci_dev *pdev, int card_type)
592 return dgap_found_board(pdev, card_type);
596 static void dgap_remove_one(struct pci_dev *dev)
603 * dgap_cleanup_module()
605 * Module unload. This is where it all ends.
607 void dgap_cleanup_module(void)
612 DGAP_LOCK(dgap_poll_lock, lock_flags);
614 DGAP_UNLOCK(dgap_poll_lock, lock_flags);
616 /* Turn off poller right away. */
617 del_timer_sync( &dgap_poll_timer);
619 dgap_remove_driver_sysfiles(&dgap_driver);
622 if (dgap_Major_Control_Registered) {
623 device_destroy(dgap_class, MKDEV(DIGI_DGAP_MAJOR, 0));
624 device_destroy(dgap_class, MKDEV(DIGI_DGAP_MAJOR, 1));
625 class_destroy(dgap_class);
626 unregister_chrdev(DIGI_DGAP_MAJOR, "dgap");
629 kfree(dgap_config_buf);
631 for (i = 0; i < dgap_NumBoards; ++i) {
632 dgap_remove_ports_sysfiles(dgap_Board[i]);
633 dgap_tty_uninit(dgap_Board[i]);
634 dgap_cleanup_board(dgap_Board[i]);
637 dgap_tty_post_uninit();
639 #if defined(DGAP_TRACER)
640 /* last thing, make sure we release the tracebuffer */
644 pci_unregister_driver(&dgap_driver);
649 * dgap_cleanup_board()
651 * Free all the memory associated with a board
653 static void dgap_cleanup_board(struct board_t *brd)
657 if(!brd || brd->magic != DGAP_BOARD_MAGIC)
660 if (brd->intr_used && brd->irq)
661 free_irq(brd->irq, brd);
663 tasklet_kill(&brd->helper_tasklet);
665 if (brd->re_map_port) {
666 release_mem_region(brd->membase + 0x200000, 0x200000);
667 iounmap(brd->re_map_port);
668 brd->re_map_port = NULL;
671 if (brd->re_map_membase) {
672 release_mem_region(brd->membase, 0x200000);
673 iounmap(brd->re_map_membase);
674 brd->re_map_membase = NULL;
677 if (brd->msgbuf_head) {
680 DGAP_LOCK(dgap_global_lock, flags);
682 printk("%s", brd->msgbuf_head);
683 kfree(brd->msgbuf_head);
684 brd->msgbuf_head = NULL;
685 DGAP_UNLOCK(dgap_global_lock, flags);
688 /* Free all allocated channels structs */
689 for (i = 0; i < MAXPORTS ; i++) {
690 if (brd->channels[i]) {
691 kfree(brd->channels[i]);
692 brd->channels[i] = NULL;
697 kfree(brd->flipflagbuf);
699 dgap_Board[brd->boardnum] = NULL;
708 * A board has been found, init it.
710 static int dgap_found_board(struct pci_dev *pdev, int id)
713 unsigned int pci_irq;
717 /* get the board structure and prep it */
718 brd = dgap_Board[dgap_NumBoards] =
719 (struct board_t *) kzalloc(sizeof(struct board_t), GFP_KERNEL);
721 APR(("memory allocation for board structure failed\n"));
725 /* make a temporary message buffer for the boot messages */
726 brd->msgbuf = brd->msgbuf_head =
727 (char *) kzalloc(sizeof(char) * 8192, GFP_KERNEL);
730 APR(("memory allocation for board msgbuf failed\n"));
734 /* store the info for the board we've found */
735 brd->magic = DGAP_BOARD_MAGIC;
736 brd->boardnum = dgap_NumBoards;
738 brd->vendor = dgap_pci_tbl[id].vendor;
739 brd->device = dgap_pci_tbl[id].device;
741 brd->pci_bus = pdev->bus->number;
742 brd->pci_slot = PCI_SLOT(pdev->devfn);
743 brd->name = dgap_Ids[id].name;
744 brd->maxports = dgap_Ids[id].maxports;
745 brd->type = dgap_Ids[id].config_type;
746 brd->dpatype = dgap_Ids[id].dpatype;
747 brd->dpastatus = BD_NOFEP;
748 init_waitqueue_head(&brd->state_wait);
750 DGAP_SPINLOCK_INIT(brd->bd_lock);
752 brd->state = BOARD_FOUND;
754 brd->inhibit_poller = FALSE;
755 brd->wait_for_bios = 0;
756 brd->wait_for_fep = 0;
758 for (i = 0; i < MAXPORTS; i++) {
759 brd->channels[i] = NULL;
762 /* store which card & revision we have */
763 pci_read_config_word(pdev, PCI_SUBSYSTEM_VENDOR_ID, &brd->subvendor);
764 pci_read_config_word(pdev, PCI_SUBSYSTEM_ID, &brd->subdevice);
765 pci_read_config_byte(pdev, PCI_REVISION_ID, &brd->rev);
770 /* get the PCI Base Address Registers */
772 /* Xr Jupiter and EPC use BAR 2 */
773 if (brd->device == PCI_DEVICE_XRJ_DID || brd->device == PCI_DEVICE_EPCJ_DID) {
774 brd->membase = pci_resource_start(pdev, 2);
775 brd->membase_end = pci_resource_end(pdev, 2);
777 /* Everyone else uses BAR 0 */
779 brd->membase = pci_resource_start(pdev, 0);
780 brd->membase_end = pci_resource_end(pdev, 0);
784 APR(("card has no PCI IO resources, failing board.\n"));
788 if (brd->membase & 1)
794 * On the PCI boards, there is no IO space allocated
795 * The I/O registers will be in the first 3 bytes of the
796 * upper 2MB of the 4MB memory space. The board memory
797 * will be mapped into the low 2MB of the 4MB memory space
799 brd->port = brd->membase + PCI_IO_OFFSET;
800 brd->port_end = brd->port + PCI_IO_SIZE;
804 * Special initialization for non-PLX boards
806 if (brd->device != PCI_DEVICE_XRJ_DID && brd->device != PCI_DEVICE_EPCJ_DID) {
809 pci_write_config_byte(pdev, 0x40, 0);
810 pci_write_config_byte(pdev, 0x46, 0);
812 /* Limit burst length to 2 doubleword transactions */
813 pci_write_config_byte(pdev, 0x42, 1);
816 * Enable IO and mem if not already done.
817 * This was needed for support on Itanium.
819 pci_read_config_word(pdev, PCI_COMMAND, &cmd);
820 cmd |= (PCI_COMMAND_IO | PCI_COMMAND_MEMORY);
821 pci_write_config_word(pdev, PCI_COMMAND, cmd);
824 /* init our poll helper tasklet */
825 tasklet_init(&brd->helper_tasklet, dgap_poll_tasklet, (unsigned long) brd);
827 /* Log the information about the board */
828 dgap_mbuf(brd, DRVSTR": board %d: %s (rev %d), irq %d\n",
829 dgap_NumBoards, brd->name, brd->rev, brd->irq);
831 DPR_INIT(("dgap_scan(%d) - printing out the msgbuf\n", i));
832 DGAP_LOCK(dgap_global_lock, flags);
834 printk("%s", brd->msgbuf_head);
835 kfree(brd->msgbuf_head);
836 brd->msgbuf_head = NULL;
837 DGAP_UNLOCK(dgap_global_lock, flags);
839 i = dgap_do_remap(brd);
841 brd->state = BOARD_FAILED;
843 brd->state = NEED_RESET;
849 int dgap_finalize_board_init(struct board_t *brd) {
853 DPR_INIT(("dgap_finalize_board_init() - start\n"));
855 if (!brd || brd->magic != DGAP_BOARD_MAGIC)
858 DPR_INIT(("dgap_finalize_board_init() - start #2\n"));
860 brd->use_interrupts = dgap_config_get_useintr(brd);
863 * Set up our interrupt handler if we are set to do interrupts.
865 if (brd->use_interrupts && brd->irq) {
867 rc = request_irq(brd->irq, dgap_intr, IRQF_SHARED, "DGAP", brd);
870 dgap_mbuf(brd, DRVSTR": Failed to hook IRQ %d. Board will work in poll mode.\n",
887 static int dgap_do_remap(struct board_t *brd)
889 if (!brd || brd->magic != DGAP_BOARD_MAGIC)
892 if (!request_mem_region(brd->membase, 0x200000, "dgap")) {
893 APR(("dgap: mem_region %lx already in use.\n", brd->membase));
897 if (!request_mem_region(brd->membase + PCI_IO_OFFSET, 0x200000, "dgap")) {
898 APR(("dgap: mem_region IO %lx already in use.\n",
899 brd->membase + PCI_IO_OFFSET));
900 release_mem_region(brd->membase, 0x200000);
904 brd->re_map_membase = ioremap(brd->membase, 0x200000);
905 if (!brd->re_map_membase) {
906 APR(("dgap: ioremap mem %lx cannot be mapped.\n", brd->membase));
907 release_mem_region(brd->membase, 0x200000);
908 release_mem_region(brd->membase + PCI_IO_OFFSET, 0x200000);
912 brd->re_map_port = ioremap((brd->membase + PCI_IO_OFFSET), 0x200000);
913 if (!brd->re_map_port) {
914 release_mem_region(brd->membase, 0x200000);
915 release_mem_region(brd->membase + PCI_IO_OFFSET, 0x200000);
916 iounmap(brd->re_map_membase);
917 APR(("dgap: ioremap IO mem %lx cannot be mapped.\n",
918 brd->membase + PCI_IO_OFFSET));
922 DPR_INIT(("remapped io: 0x%p remapped mem: 0x%p\n",
923 brd->re_map_port, brd->re_map_membase));
928 /*****************************************************************************
948 * As each timer expires, it determines (a) whether the "transmit"
949 * waiter needs to be woken up, and (b) whether the poller needs to
952 ******************************************************************************/
954 static void dgap_poll_handler(ulong dummy)
958 unsigned long lock_flags;
959 unsigned long lock_flags2;
966 * If driver needs the config file still,
967 * keep trying to wake up the downloader to
970 if (dgap_driver_state == DRIVER_NEED_CONFIG_LOAD) {
972 * Signal downloader, its got some work to do.
974 DGAP_LOCK(dgap_dl_lock, lock_flags2);
975 if (dgap_dl_action != 1) {
977 wake_up_interruptible(&dgap_dl_wait);
979 DGAP_UNLOCK(dgap_dl_lock, lock_flags2);
980 goto schedule_poller;
983 * Do not start the board state machine until
984 * driver tells us its up and running, and has
985 * everything it needs.
987 else if (dgap_driver_state != DRIVER_READY) {
988 goto schedule_poller;
992 * If we have just 1 board, or the system is not SMP,
993 * then use the typical old style poller.
994 * Otherwise, use our new tasklet based poller, which should
995 * speed things up for multiple boards.
997 if ( (dgap_NumBoards == 1) || (num_online_cpus() <= 1) ) {
998 for (i = 0; i < dgap_NumBoards; i++) {
1000 brd = dgap_Board[i];
1002 if (brd->state == BOARD_FAILED) {
1005 if (!brd->intr_running) {
1006 /* Call the real board poller directly */
1007 dgap_poll_tasklet((unsigned long) brd);
1012 /* Go thru each board, kicking off a tasklet for each if needed */
1013 for (i = 0; i < dgap_NumBoards; i++) {
1014 brd = dgap_Board[i];
1017 * Attempt to grab the board lock.
1019 * If we can't get it, no big deal, the next poll will get it.
1020 * Basically, I just really don't want to spin in here, because I want
1021 * to kick off my tasklets as fast as I can, and then get out the poller.
1023 if (!spin_trylock(&brd->bd_lock)) {
1027 /* If board is in a failed state, don't bother scheduling a tasklet */
1028 if (brd->state == BOARD_FAILED) {
1029 spin_unlock(&brd->bd_lock);
1033 /* Schedule a poll helper task */
1034 if (!brd->intr_running) {
1035 tasklet_schedule(&brd->helper_tasklet);
1039 * Can't do DGAP_UNLOCK here, as we don't have
1040 * lock_flags because we did a trylock above.
1042 spin_unlock(&brd->bd_lock);
1049 * Schedule ourself back at the nominal wakeup interval.
1051 DGAP_LOCK(dgap_poll_lock, lock_flags );
1052 dgap_poll_time += dgap_jiffies_from_ms(dgap_poll_tick);
1054 new_time = dgap_poll_time - jiffies;
1056 if ((ulong) new_time >= 2 * dgap_poll_tick) {
1057 dgap_poll_time = jiffies + dgap_jiffies_from_ms(dgap_poll_tick);
1060 dgap_poll_timer.function = dgap_poll_handler;
1061 dgap_poll_timer.data = 0;
1062 dgap_poll_timer.expires = dgap_poll_time;
1063 DGAP_UNLOCK(dgap_poll_lock, lock_flags );
1065 if (!dgap_poll_stop)
1066 add_timer(&dgap_poll_timer);
1075 * Driver interrupt handler.
1077 static irqreturn_t dgap_intr(int irq, void *voidbrd)
1079 struct board_t *brd = (struct board_t *) voidbrd;
1082 APR(("Received interrupt (%d) with null board associated\n", irq));
1087 * Check to make sure its for us.
1089 if (brd->magic != DGAP_BOARD_MAGIC) {
1090 APR(("Received interrupt (%d) with a board pointer that wasn't ours!\n", irq));
1097 * Schedule tasklet to run at a better time.
1099 tasklet_schedule(&brd->helper_tasklet);
1105 * dgap_init_globals()
1107 * This is where we initialize the globals from the static insmod
1108 * configuration variables. These are declared near the head of
1111 static void dgap_init_globals(void)
1115 dgap_rawreadok = rawreadok;
1116 dgap_trcbuf_size = trcbuf_size;
1119 for (i = 0; i < MAXBOARDS; i++) {
1120 dgap_Board[i] = NULL;
1123 init_timer( &dgap_poll_timer );
1125 init_waitqueue_head(&dgap_dl_wait);
1130 /************************************************************************
1134 ************************************************************************/
1140 * Used to print to the message buffer during board init.
1142 static void dgap_mbuf(struct board_t *brd, const char *fmt, ...) {
1146 unsigned long flags;
1149 DGAP_LOCK(dgap_global_lock, flags);
1151 /* Format buf using fmt and arguments contained in ap. */
1153 i = vsnprintf(buf, sizeof(buf), fmt, ap);
1158 if (!brd || !brd->msgbuf) {
1160 DGAP_UNLOCK(dgap_global_lock, flags);
1164 length = strlen(buf) + 1;
1165 if (brd->msgbuf - brd->msgbuf_head < length)
1166 length = brd->msgbuf - brd->msgbuf_head;
1167 memcpy(brd->msgbuf, buf, length);
1168 brd->msgbuf += length;
1170 DGAP_UNLOCK(dgap_global_lock, flags);
1177 * Put the driver to sleep for x ms's
1179 * Returns 0 if timed out, !0 (showing signal) if interrupted by a signal.
1181 int dgap_ms_sleep(ulong ms)
1183 current->state = TASK_INTERRUPTIBLE;
1184 schedule_timeout((ms * HZ) / 1000);
1185 return (signal_pending(current));
1191 * dgap_ioctl_name() : Returns a text version of each ioctl value.
1193 char *dgap_ioctl_name(int cmd)
1197 case TCGETA: return("TCGETA");
1198 case TCGETS: return("TCGETS");
1199 case TCSETA: return("TCSETA");
1200 case TCSETS: return("TCSETS");
1201 case TCSETAW: return("TCSETAW");
1202 case TCSETSW: return("TCSETSW");
1203 case TCSETAF: return("TCSETAF");
1204 case TCSETSF: return("TCSETSF");
1205 case TCSBRK: return("TCSBRK");
1206 case TCXONC: return("TCXONC");
1207 case TCFLSH: return("TCFLSH");
1208 case TIOCGSID: return("TIOCGSID");
1210 case TIOCGETD: return("TIOCGETD");
1211 case TIOCSETD: return("TIOCSETD");
1212 case TIOCGWINSZ: return("TIOCGWINSZ");
1213 case TIOCSWINSZ: return("TIOCSWINSZ");
1215 case TIOCMGET: return("TIOCMGET");
1216 case TIOCMSET: return("TIOCMSET");
1217 case TIOCMBIS: return("TIOCMBIS");
1218 case TIOCMBIC: return("TIOCMBIC");
1221 case DIGI_SETA: return("DIGI_SETA");
1222 case DIGI_SETAW: return("DIGI_SETAW");
1223 case DIGI_SETAF: return("DIGI_SETAF");
1224 case DIGI_SETFLOW: return("DIGI_SETFLOW");
1225 case DIGI_SETAFLOW: return("DIGI_SETAFLOW");
1226 case DIGI_GETFLOW: return("DIGI_GETFLOW");
1227 case DIGI_GETAFLOW: return("DIGI_GETAFLOW");
1228 case DIGI_GETA: return("DIGI_GETA");
1229 case DIGI_GEDELAY: return("DIGI_GEDELAY");
1230 case DIGI_SEDELAY: return("DIGI_SEDELAY");
1231 case DIGI_GETCUSTOMBAUD: return("DIGI_GETCUSTOMBAUD");
1232 case DIGI_SETCUSTOMBAUD: return("DIGI_SETCUSTOMBAUD");
1233 case TIOCMODG: return("TIOCMODG");
1234 case TIOCMODS: return("TIOCMODS");
1235 case TIOCSDTR: return("TIOCSDTR");
1236 case TIOCCDTR: return("TIOCCDTR");
1238 default: return("unknown");
1242 /************************************************************************
1244 * TTY Initialization/Cleanup Functions
1246 ************************************************************************/
1249 * dgap_tty_preinit()
1251 * Initialize any global tty related data before we download any boards.
1253 int dgap_tty_preinit(void)
1255 unsigned long flags;
1257 DGAP_LOCK(dgap_global_lock, flags);
1260 * Allocate a buffer for doing the copy from user space to
1261 * kernel space in dgap_input(). We only use one buffer and
1262 * control access to it with a semaphore. If we are paging, we
1263 * are already in trouble so one buffer won't hurt much anyway.
1265 dgap_TmpWriteBuf = kmalloc(WRITEBUFLEN, GFP_ATOMIC);
1267 if (!dgap_TmpWriteBuf) {
1268 DGAP_UNLOCK(dgap_global_lock, flags);
1269 DPR_INIT(("unable to allocate tmp write buf"));
1273 DGAP_UNLOCK(dgap_global_lock, flags);
1279 * dgap_tty_register()
1281 * Init the tty subsystem for this board.
1283 int dgap_tty_register(struct board_t *brd)
1287 DPR_INIT(("tty_register start"));
1289 brd->SerialDriver = alloc_tty_driver(MAXPORTS);
1291 snprintf(brd->SerialName, MAXTTYNAMELEN, "tty_dgap_%d_", brd->boardnum);
1292 brd->SerialDriver->name = brd->SerialName;
1293 brd->SerialDriver->name_base = 0;
1294 brd->SerialDriver->major = 0;
1295 brd->SerialDriver->minor_start = 0;
1296 brd->SerialDriver->type = TTY_DRIVER_TYPE_SERIAL;
1297 brd->SerialDriver->subtype = SERIAL_TYPE_NORMAL;
1298 brd->SerialDriver->init_termios = DgapDefaultTermios;
1299 brd->SerialDriver->driver_name = DRVSTR;
1300 brd->SerialDriver->flags = (TTY_DRIVER_REAL_RAW | TTY_DRIVER_DYNAMIC_DEV | TTY_DRIVER_HARDWARE_BREAK);
1302 /* The kernel wants space to store pointers to tty_structs */
1303 brd->SerialDriver->ttys = kzalloc(MAXPORTS * sizeof(struct tty_struct *), GFP_KERNEL);
1304 if (!brd->SerialDriver->ttys)
1308 * Entry points for driver. Called by the kernel from
1309 * tty_io.c and n_tty.c.
1311 tty_set_operations(brd->SerialDriver, &dgap_tty_ops);
1314 * If we're doing transparent print, we have to do all of the above
1315 * again, separately so we don't get the LD confused about what major
1316 * we are when we get into the dgap_tty_open() routine.
1318 brd->PrintDriver = alloc_tty_driver(MAXPORTS);
1320 snprintf(brd->PrintName, MAXTTYNAMELEN, "pr_dgap_%d_", brd->boardnum);
1321 brd->PrintDriver->name = brd->PrintName;
1322 brd->PrintDriver->name_base = 0;
1323 brd->PrintDriver->major = 0;
1324 brd->PrintDriver->minor_start = 0;
1325 brd->PrintDriver->type = TTY_DRIVER_TYPE_SERIAL;
1326 brd->PrintDriver->subtype = SERIAL_TYPE_NORMAL;
1327 brd->PrintDriver->init_termios = DgapDefaultTermios;
1328 brd->PrintDriver->driver_name = DRVSTR;
1329 brd->PrintDriver->flags = (TTY_DRIVER_REAL_RAW | TTY_DRIVER_DYNAMIC_DEV | TTY_DRIVER_HARDWARE_BREAK);
1331 /* The kernel wants space to store pointers to tty_structs */
1332 brd->PrintDriver->ttys = kzalloc(MAXPORTS * sizeof(struct tty_struct *), GFP_KERNEL);
1333 if (!brd->PrintDriver->ttys)
1337 * Entry points for driver. Called by the kernel from
1338 * tty_io.c and n_tty.c.
1340 tty_set_operations(brd->PrintDriver, &dgap_tty_ops);
1342 if (!brd->dgap_Major_Serial_Registered) {
1343 /* Register tty devices */
1344 rc = tty_register_driver(brd->SerialDriver);
1346 APR(("Can't register tty device (%d)\n", rc));
1349 brd->dgap_Major_Serial_Registered = TRUE;
1350 dgap_BoardsByMajor[brd->SerialDriver->major] = brd;
1351 brd->dgap_Serial_Major = brd->SerialDriver->major;
1354 if (!brd->dgap_Major_TransparentPrint_Registered) {
1355 /* Register Transparent Print devices */
1356 rc = tty_register_driver(brd->PrintDriver);
1358 APR(("Can't register Transparent Print device (%d)\n", rc));
1361 brd->dgap_Major_TransparentPrint_Registered = TRUE;
1362 dgap_BoardsByMajor[brd->PrintDriver->major] = brd;
1363 brd->dgap_TransparentPrint_Major = brd->PrintDriver->major;
1366 DPR_INIT(("DGAP REGISTER TTY: MAJORS: %d %d\n", brd->SerialDriver->major,
1367 brd->PrintDriver->major));
1376 * Init the tty subsystem. Called once per board after board has been
1377 * downloaded and init'ed.
1379 int dgap_tty_init(struct board_t *brd)
1383 uint true_count = 0;
1386 struct channel_t *ch;
1393 DPR_INIT(("dgap_tty_init start\n"));
1396 * Initialize board structure elements.
1399 vaddr = brd->re_map_membase;
1400 true_count = readw((vaddr + NCHAN));
1402 brd->nasync = dgap_config_get_number_of_ports(brd);
1405 brd->nasync = brd->maxports;
1408 if (brd->nasync > brd->maxports) {
1409 brd->nasync = brd->maxports;
1412 if (true_count != brd->nasync) {
1413 if ((brd->type == PPCM) && (true_count == 64)) {
1414 APR(("***WARNING**** %s configured for %d ports, has %d ports.\nPlease make SURE the EBI cable running from the card\nto each EM module is plugged into EBI IN!\n",
1415 brd->name, brd->nasync, true_count));
1417 else if ((brd->type == PPCM) && (true_count == 0)) {
1418 APR(("***WARNING**** %s configured for %d ports, has %d ports.\nPlease make SURE the EBI cable running from the card\nto each EM module is plugged into EBI IN!\n",
1419 brd->name, brd->nasync, true_count));
1422 APR(("***WARNING**** %s configured for %d ports, has %d ports.\n",
1423 brd->name, brd->nasync, true_count));
1426 brd->nasync = true_count;
1428 /* If no ports, don't bother going any further */
1430 brd->state = BOARD_FAILED;
1431 brd->dpastatus = BD_NOFEP;
1437 * Allocate channel memory that might not have been allocated
1438 * when the driver was first loaded.
1440 for (i = 0; i < brd->nasync; i++) {
1441 if (!brd->channels[i]) {
1442 brd->channels[i] = kzalloc(sizeof(struct channel_t), GFP_ATOMIC);
1443 if (!brd->channels[i]) {
1444 DPR_CORE(("%s:%d Unable to allocate memory for channel struct\n",
1445 __FILE__, __LINE__));
1450 ch = brd->channels[0];
1451 vaddr = brd->re_map_membase;
1453 bs = (struct bs_t *) ((ulong) vaddr + CHANBUF);
1454 cm = (struct cm_t *) ((ulong) vaddr + CMDBUF);
1458 /* Set up channel variables */
1459 for (i = 0; i < brd->nasync; i++, ch = brd->channels[i], bs++) {
1461 if (!brd->channels[i])
1464 DGAP_SPINLOCK_INIT(ch->ch_lock);
1466 /* Store all our magic numbers */
1467 ch->magic = DGAP_CHANNEL_MAGIC;
1468 ch->ch_tun.magic = DGAP_UNIT_MAGIC;
1469 ch->ch_tun.un_type = DGAP_SERIAL;
1470 ch->ch_tun.un_ch = ch;
1471 ch->ch_tun.un_dev = i;
1473 ch->ch_pun.magic = DGAP_UNIT_MAGIC;
1474 ch->ch_pun.un_type = DGAP_PRINT;
1475 ch->ch_pun.un_ch = ch;
1476 ch->ch_pun.un_dev = i;
1478 ch->ch_vaddr = vaddr;
1483 ch->ch_digi = dgap_digi_init;
1486 * Set up digi dsr and dcd bits based on altpin flag.
1488 if (dgap_config_get_altpin(brd)) {
1491 ch->ch_digi.digi_flags |= DIGI_ALTPIN;
1495 ch->ch_dsr = DM_DSR;
1498 ch->ch_taddr = vaddr + ((ch->ch_bs->tx_seg) << 4);
1499 ch->ch_raddr = vaddr + ((ch->ch_bs->rx_seg) << 4);
1502 ch->ch_tsize = readw(&(ch->ch_bs->tx_max)) + 1;
1503 ch->ch_rsize = readw(&(ch->ch_bs->rx_max)) + 1;
1507 /* .25 second delay */
1508 ch->ch_close_delay = 250;
1511 * Set queue water marks, interrupt mask,
1512 * and general tty parameters.
1514 ch->ch_tlw = tlw = ch->ch_tsize >= 2000 ? ((ch->ch_tsize * 5) / 8) : ch->ch_tsize / 2;
1516 dgap_cmdw(ch, STLOW, tlw, 0);
1518 dgap_cmdw(ch, SRLOW, ch->ch_rsize / 2, 0);
1520 dgap_cmdw(ch, SRHIGH, 7 * ch->ch_rsize / 8, 0);
1522 ch->ch_mistat = readb(&(ch->ch_bs->m_stat));
1524 init_waitqueue_head(&ch->ch_flags_wait);
1525 init_waitqueue_head(&ch->ch_tun.un_flags_wait);
1526 init_waitqueue_head(&ch->ch_pun.un_flags_wait);
1527 init_waitqueue_head(&ch->ch_sniff_wait);
1529 /* Turn on all modem interrupts for now */
1530 modem = (DM_CD | DM_DSR | DM_CTS | DM_RI);
1531 writeb(modem, &(ch->ch_bs->m_int));
1534 * Set edelay to 0 if interrupts are turned on,
1535 * otherwise set edelay to the usual 100.
1538 writew(0, &(ch->ch_bs->edelay));
1540 writew(100, &(ch->ch_bs->edelay));
1542 writeb(1, &(ch->ch_bs->idata));
1546 DPR_INIT(("dgap_tty_init finish\n"));
1553 * dgap_tty_post_uninit()
1555 * UnInitialize any global tty related data.
1557 void dgap_tty_post_uninit(void)
1559 kfree(dgap_TmpWriteBuf);
1560 dgap_TmpWriteBuf = NULL;
1567 * Uninitialize the TTY portion of this driver. Free all memory and
1570 void dgap_tty_uninit(struct board_t *brd)
1574 if (brd->dgap_Major_Serial_Registered) {
1575 dgap_BoardsByMajor[brd->SerialDriver->major] = NULL;
1576 brd->dgap_Serial_Major = 0;
1577 for (i = 0; i < brd->nasync; i++) {
1578 dgap_remove_tty_sysfs(brd->channels[i]->ch_tun.un_sysfs);
1579 tty_unregister_device(brd->SerialDriver, i);
1581 tty_unregister_driver(brd->SerialDriver);
1582 kfree(brd->SerialDriver->ttys);
1583 brd->SerialDriver->ttys = NULL;
1584 put_tty_driver(brd->SerialDriver);
1585 brd->dgap_Major_Serial_Registered = FALSE;
1588 if (brd->dgap_Major_TransparentPrint_Registered) {
1589 dgap_BoardsByMajor[brd->PrintDriver->major] = NULL;
1590 brd->dgap_TransparentPrint_Major = 0;
1591 for (i = 0; i < brd->nasync; i++) {
1592 dgap_remove_tty_sysfs(brd->channels[i]->ch_pun.un_sysfs);
1593 tty_unregister_device(brd->PrintDriver, i);
1595 tty_unregister_driver(brd->PrintDriver);
1596 kfree(brd->PrintDriver->ttys);
1597 brd->PrintDriver->ttys = NULL;
1598 put_tty_driver(brd->PrintDriver);
1599 brd->dgap_Major_TransparentPrint_Registered = FALSE;
1604 #define TMPBUFLEN (1024)
1607 * dgap_sniff - Dump data out to the "sniff" buffer if the
1608 * proc sniff file is opened...
1610 static void dgap_sniff_nowait_nolock(struct channel_t *ch, uchar *text, uchar *buf, int len)
1618 char tmpbuf[TMPBUFLEN];
1622 /* Leave if sniff not open */
1623 if (!(ch->ch_sniff_flags & SNIFF_OPEN))
1626 do_gettimeofday(&tv);
1628 /* Create our header for data dump */
1629 p += sprintf(p, "<%ld %ld><%s><", tv.tv_sec, tv.tv_usec, text);
1630 tmpbuflen = p - tmpbuf;
1635 for (i = 0; i < len && tmpbuflen < (TMPBUFLEN - 4); i++) {
1636 p += sprintf(p, "%02x ", *buf);
1638 tmpbuflen = p - tmpbuf;
1641 if (tmpbuflen < (TMPBUFLEN - 4)) {
1643 p += sprintf(p - 1, "%s\n", ">");
1645 p += sprintf(p, "%s\n", ">");
1651 nbuf = strlen(tmpbuf);
1655 * Loop while data remains.
1657 while (nbuf > 0 && ch->ch_sniff_buf) {
1659 * Determine the amount of available space left in the
1660 * buffer. If there's none, wait until some appears.
1662 n = (ch->ch_sniff_out - ch->ch_sniff_in - 1) & SNIFF_MASK;
1665 * If there is no space left to write to in our sniff buffer,
1666 * we have no choice but to drop the data.
1667 * We *cannot* sleep here waiting for space, because this
1668 * function was probably called by the interrupt/timer routines!
1675 * Copy as much data as will fit.
1681 r = SNIFF_MAX - ch->ch_sniff_in;
1684 memcpy(ch->ch_sniff_buf + ch->ch_sniff_in, p, r);
1687 ch->ch_sniff_in = 0;
1692 memcpy(ch->ch_sniff_buf + ch->ch_sniff_in, p, n);
1694 ch->ch_sniff_in += n;
1699 * Wakeup any thread waiting for data
1701 if (ch->ch_sniff_flags & SNIFF_WAIT_DATA) {
1702 ch->ch_sniff_flags &= ~SNIFF_WAIT_DATA;
1703 wake_up_interruptible(&ch->ch_sniff_wait);
1708 * If the user sent us too much data to push into our tmpbuf,
1709 * we need to keep looping around on all the data.
1711 if (too_much_data) {
1716 } while (too_much_data);
1720 /*=======================================================================
1722 * dgap_input - Process received data.
1724 * ch - Pointer to channel structure.
1726 *=======================================================================*/
1728 void dgap_input(struct channel_t *ch)
1732 struct tty_struct *tp;
1733 struct tty_ldisc *ld;
1747 if (!ch || ch->magic != DGAP_CHANNEL_MAGIC)
1750 tp = ch->ch_tun.un_tty;
1758 if(!bd || bd->magic != DGAP_BOARD_MAGIC)
1761 DPR_READ(("dgap_input start\n"));
1763 DGAP_LOCK(bd->bd_lock, lock_flags);
1764 DGAP_LOCK(ch->ch_lock, lock_flags2);
1767 * Figure the number of characters in the buffer.
1768 * Exit immediately if none.
1771 rmask = ch->ch_rsize - 1;
1773 head = readw(&(bs->rx_head));
1775 tail = readw(&(bs->rx_tail));
1778 data_len = (head - tail) & rmask;
1780 if (data_len == 0) {
1781 writeb(1, &(bs->idata));
1782 DGAP_UNLOCK(ch->ch_lock, lock_flags2);
1783 DGAP_UNLOCK(bd->bd_lock, lock_flags);
1784 DPR_READ(("No data on port %d\n", ch->ch_portnum));
1789 * If the device is not open, or CREAD is off, flush
1790 * input data and return immediately.
1792 if ((bd->state != BOARD_READY) || !tp || (tp->magic != TTY_MAGIC) ||
1793 !(ch->ch_tun.un_flags & UN_ISOPEN) || !(tp->termios.c_cflag & CREAD) ||
1794 (ch->ch_tun.un_flags & UN_CLOSING)) {
1796 DPR_READ(("input. dropping %d bytes on port %d...\n", data_len, ch->ch_portnum));
1797 DPR_READ(("input. tp: %p tp->magic: %x MAGIC:%x ch flags: %x\n",
1798 tp, tp ? tp->magic : 0, TTY_MAGIC, ch->ch_tun.un_flags));
1799 writew(head, &(bs->rx_tail));
1800 writeb(1, &(bs->idata));
1801 DGAP_UNLOCK(ch->ch_lock, lock_flags2);
1802 DGAP_UNLOCK(bd->bd_lock, lock_flags);
1807 * If we are throttled, simply don't read any data.
1809 if (ch->ch_flags & CH_RXBLOCK) {
1810 writeb(1, &(bs->idata));
1811 DGAP_UNLOCK(ch->ch_lock, lock_flags2);
1812 DGAP_UNLOCK(bd->bd_lock, lock_flags);
1813 DPR_READ(("Port %d throttled, not reading any data. head: %x tail: %x\n",
1814 ch->ch_portnum, head, tail));
1821 tmpchar = readb(&(bs->orun));
1823 ch->ch_err_overrun++;
1824 writeb(0, &(bs->orun));
1827 DPR_READ(("dgap_input start 2\n"));
1829 /* Decide how much data we can send into the tty layer */
1830 flip_len = TTY_FLIPBUF_SIZE;
1832 /* Chop down the length, if needed */
1833 len = min(data_len, flip_len);
1834 len = min(len, (N_TTY_BUF_SIZE - 1));
1836 ld = tty_ldisc_ref(tp);
1838 #ifdef TTY_DONT_FLIP
1840 * If the DONT_FLIP flag is on, don't flush our buffer, and act
1841 * like the ld doesn't have any space to put the data right now.
1843 if (test_bit(TTY_DONT_FLIP, &tp->flags))
1848 * If we were unable to get a reference to the ld,
1849 * don't flush our buffer, and act like the ld doesn't
1850 * have any space to put the data right now.
1856 * If ld doesn't have a pointer to a receive_buf function,
1857 * flush the data, then act like the ld doesn't have any
1858 * space to put the data right now.
1860 if (!ld->ops->receive_buf) {
1861 writew(head, &(bs->rx_tail));
1867 writeb(1, &(bs->idata));
1868 DGAP_UNLOCK(ch->ch_lock, lock_flags2);
1869 DGAP_UNLOCK(bd->bd_lock, lock_flags);
1870 DPR_READ(("dgap_input 1 - finish\n"));
1872 tty_ldisc_deref(ld);
1876 buf = ch->ch_bd->flipbuf;
1880 * n now contains the most amount of data we can copy,
1881 * bounded either by our buffer size or the amount
1882 * of data the card actually has pending...
1886 s = ((head >= tail) ? head : ch->ch_rsize) - tail;
1892 memcpy_fromio(buf, (char *) ch->ch_raddr + tail, s);
1893 dgap_sniff_nowait_nolock(ch, "USER READ", buf, s);
1899 /* Flip queue if needed */
1903 writew(tail, &(bs->rx_tail));
1904 writeb(1, &(bs->idata));
1905 ch->ch_rxcount += len;
1908 * If we are completely raw, we don't need to go through a lot
1909 * of the tty layers that exist.
1910 * In this case, we take the shortest and fastest route we
1911 * can to relay the data to the user.
1913 * On the other hand, if we are not raw, we need to go through
1914 * the tty layer, which has its API more well defined.
1916 if (I_PARMRK(tp) || I_BRKINT(tp) || I_INPCK(tp)) {
1917 dgap_parity_scan(ch, ch->ch_bd->flipbuf, ch->ch_bd->flipflagbuf, &len);
1919 len = tty_buffer_request_room(tp->port, len);
1920 tty_insert_flip_string_flags(tp->port, ch->ch_bd->flipbuf,
1921 ch->ch_bd->flipflagbuf, len);
1924 len = tty_buffer_request_room(tp->port, len);
1925 tty_insert_flip_string(tp->port, ch->ch_bd->flipbuf, len);
1928 DGAP_UNLOCK(ch->ch_lock, lock_flags2);
1929 DGAP_UNLOCK(bd->bd_lock, lock_flags);
1931 /* Tell the tty layer its okay to "eat" the data now */
1932 tty_flip_buffer_push(tp->port);
1935 tty_ldisc_deref(ld);
1937 DPR_READ(("dgap_input - finish\n"));
1941 /************************************************************************
1942 * Determines when CARRIER changes state and takes appropriate
1944 ************************************************************************/
1945 void dgap_carrier(struct channel_t *ch)
1949 int virt_carrier = 0;
1950 int phys_carrier = 0;
1952 DPR_CARR(("dgap_carrier called...\n"));
1954 if (!ch || ch->magic != DGAP_CHANNEL_MAGIC)
1959 if (!bd || bd->magic != DGAP_BOARD_MAGIC)
1962 /* Make sure altpin is always set correctly */
1963 if (ch->ch_digi.digi_flags & DIGI_ALTPIN) {
1968 ch->ch_dsr = DM_DSR;
1972 if (ch->ch_mistat & D_CD(ch)) {
1973 DPR_CARR(("mistat: %x D_CD: %x\n", ch->ch_mistat, D_CD(ch)));
1977 if (ch->ch_digi.digi_flags & DIGI_FORCEDCD) {
1981 if (ch->ch_c_cflag & CLOCAL) {
1986 DPR_CARR(("DCD: physical: %d virt: %d\n", phys_carrier, virt_carrier));
1989 * Test for a VIRTUAL carrier transition to HIGH.
1991 if (((ch->ch_flags & CH_FCAR) == 0) && (virt_carrier == 1)) {
1994 * When carrier rises, wake any threads waiting
1995 * for carrier in the open routine.
1998 DPR_CARR(("carrier: virt DCD rose\n"));
2000 if (waitqueue_active(&(ch->ch_flags_wait)))
2001 wake_up_interruptible(&ch->ch_flags_wait);
2005 * Test for a PHYSICAL carrier transition to HIGH.
2007 if (((ch->ch_flags & CH_CD) == 0) && (phys_carrier == 1)) {
2010 * When carrier rises, wake any threads waiting
2011 * for carrier in the open routine.
2014 DPR_CARR(("carrier: physical DCD rose\n"));
2016 if (waitqueue_active(&(ch->ch_flags_wait)))
2017 wake_up_interruptible(&ch->ch_flags_wait);
2021 * Test for a PHYSICAL transition to low, so long as we aren't
2022 * currently ignoring physical transitions (which is what "virtual
2023 * carrier" indicates).
2025 * The transition of the virtual carrier to low really doesn't
2026 * matter... it really only means "ignore carrier state", not
2027 * "make pretend that carrier is there".
2029 if ((virt_carrier == 0) && ((ch->ch_flags & CH_CD) != 0) &&
2030 (phys_carrier == 0))
2034 * When carrier drops:
2036 * Drop carrier on all open units.
2038 * Flush queues, waking up any task waiting in the
2041 * Send a hangup to the control terminal.
2043 * Enable all select calls.
2045 if (waitqueue_active(&(ch->ch_flags_wait)))
2046 wake_up_interruptible(&ch->ch_flags_wait);
2048 if (ch->ch_tun.un_open_count > 0) {
2049 DPR_CARR(("Sending tty hangup\n"));
2050 tty_hangup(ch->ch_tun.un_tty);
2053 if (ch->ch_pun.un_open_count > 0) {
2054 DPR_CARR(("Sending pr hangup\n"));
2055 tty_hangup(ch->ch_pun.un_tty);
2060 * Make sure that our cached values reflect the current reality.
2062 if (virt_carrier == 1)
2063 ch->ch_flags |= CH_FCAR;
2065 ch->ch_flags &= ~CH_FCAR;
2067 if (phys_carrier == 1)
2068 ch->ch_flags |= CH_CD;
2070 ch->ch_flags &= ~CH_CD;
2074 /************************************************************************
2076 * TTY Entry points and helper functions
2078 ************************************************************************/
2084 static int dgap_tty_open(struct tty_struct *tty, struct file *file)
2086 struct board_t *brd;
2087 struct channel_t *ch;
2099 major = MAJOR(tty_devnum(tty));
2100 minor = MINOR(tty_devnum(tty));
2106 /* Get board pointer from our array of majors we have allocated */
2107 brd = dgap_BoardsByMajor[major];
2113 * If board is not yet up to a state of READY, go to
2114 * sleep waiting for it to happen or they cancel the open.
2116 rc = wait_event_interruptible(brd->state_wait,
2117 (brd->state & BOARD_READY));
2123 DGAP_LOCK(brd->bd_lock, lock_flags);
2125 /* The wait above should guarantee this cannot happen */
2126 if (brd->state != BOARD_READY) {
2127 DGAP_UNLOCK(brd->bd_lock, lock_flags);
2131 /* If opened device is greater than our number of ports, bail. */
2132 if (MINOR(tty_devnum(tty)) > brd->nasync) {
2133 DGAP_UNLOCK(brd->bd_lock, lock_flags);
2137 ch = brd->channels[minor];
2139 DGAP_UNLOCK(brd->bd_lock, lock_flags);
2143 /* Grab channel lock */
2144 DGAP_LOCK(ch->ch_lock, lock_flags2);
2146 /* Figure out our type */
2147 if (major == brd->dgap_Serial_Major) {
2148 un = &brd->channels[minor]->ch_tun;
2149 un->un_type = DGAP_SERIAL;
2151 else if (major == brd->dgap_TransparentPrint_Major) {
2152 un = &brd->channels[minor]->ch_pun;
2153 un->un_type = DGAP_PRINT;
2156 DGAP_UNLOCK(ch->ch_lock, lock_flags2);
2157 DGAP_UNLOCK(brd->bd_lock, lock_flags);
2158 DPR_OPEN(("%d Unknown TYPE!\n", __LINE__));
2162 /* Store our unit into driver_data, so we always have it available. */
2163 tty->driver_data = un;
2165 DPR_OPEN(("Open called. MAJOR: %d MINOR:%d unit: %p NAME: %s\n",
2166 MAJOR(tty_devnum(tty)), MINOR(tty_devnum(tty)), un, brd->name));
2169 * Error if channel info pointer is NULL.
2173 DGAP_UNLOCK(ch->ch_lock, lock_flags2);
2174 DGAP_UNLOCK(brd->bd_lock, lock_flags);
2175 DPR_OPEN(("%d BS is 0!\n", __LINE__));
2179 DPR_OPEN(("%d: tflag=%x pflag=%x\n", __LINE__, ch->ch_tun.un_flags, ch->ch_pun.un_flags));
2184 if (!(un->un_flags & UN_ISOPEN)) {
2185 /* Store important variables. */
2188 /* Maybe do something here to the TTY struct as well? */
2192 * Initialize if neither terminal or printer is open.
2194 if (!((ch->ch_tun.un_flags | ch->ch_pun.un_flags) & UN_ISOPEN)) {
2196 DPR_OPEN(("dgap_open: initializing channel in open...\n"));
2202 * Flush input queue.
2204 head = readw(&(bs->rx_head));
2205 writew(head, &(bs->rx_tail));
2208 ch->pscan_state = 0;
2209 ch->pscan_savechar = 0;
2211 ch->ch_c_cflag = tty->termios.c_cflag;
2212 ch->ch_c_iflag = tty->termios.c_iflag;
2213 ch->ch_c_oflag = tty->termios.c_oflag;
2214 ch->ch_c_lflag = tty->termios.c_lflag;
2215 ch->ch_startc = tty->termios.c_cc[VSTART];
2216 ch->ch_stopc = tty->termios.c_cc[VSTOP];
2218 /* TODO: flush our TTY struct here? */
2223 * Run param in case we changed anything
2228 * follow protocol for opening port
2231 DGAP_UNLOCK(ch->ch_lock, lock_flags2);
2232 DGAP_UNLOCK(brd->bd_lock, lock_flags);
2234 rc = dgap_block_til_ready(tty, file, ch);
2241 DPR_OPEN(("dgap_tty_open returning after dgap_block_til_ready "
2245 /* No going back now, increment our unit and channel counters */
2246 DGAP_LOCK(ch->ch_lock, lock_flags);
2247 ch->ch_open_count++;
2248 un->un_open_count++;
2249 un->un_flags |= (UN_ISOPEN);
2250 DGAP_UNLOCK(ch->ch_lock, lock_flags);
2252 DPR_OPEN(("dgap_tty_open finished\n"));
2258 * dgap_block_til_ready()
2260 * Wait for DCD, if needed.
2262 static int dgap_block_til_ready(struct tty_struct *tty, struct file *file, struct channel_t *ch)
2265 struct un_t *un = NULL;
2268 int sleep_on_un_flags = 0;
2270 if (!tty || tty->magic != TTY_MAGIC || !file || !ch || ch->magic != DGAP_CHANNEL_MAGIC) {
2274 un = tty->driver_data;
2275 if (!un || un->magic != DGAP_UNIT_MAGIC) {
2279 DPR_OPEN(("dgap_block_til_ready - before block.\n"));
2281 DGAP_LOCK(ch->ch_lock, lock_flags);
2288 sleep_on_un_flags = 0;
2291 * If board has failed somehow during our sleep, bail with error.
2293 if (ch->ch_bd->state == BOARD_FAILED) {
2298 /* If tty was hung up, break out of loop and set error. */
2299 if (tty_hung_up_p(file)) {
2305 * If either unit is in the middle of the fragile part of close,
2306 * we just cannot touch the channel safely.
2307 * Go back to sleep, knowing that when the channel can be
2308 * touched safely, the close routine will signal the
2309 * ch_wait_flags to wake us back up.
2311 if (!((ch->ch_tun.un_flags | ch->ch_pun.un_flags) & UN_CLOSING)) {
2314 * Our conditions to leave cleanly and happily:
2315 * 1) NONBLOCKING on the tty is set.
2317 * 3) DCD (fake or real) is active.
2320 if (file->f_flags & O_NONBLOCK) {
2324 if (tty->flags & (1 << TTY_IO_ERROR)) {
2328 if (ch->ch_flags & CH_CD) {
2329 DPR_OPEN(("%d: ch_flags: %x\n", __LINE__, ch->ch_flags));
2333 if (ch->ch_flags & CH_FCAR) {
2334 DPR_OPEN(("%d: ch_flags: %x\n", __LINE__, ch->ch_flags));
2339 sleep_on_un_flags = 1;
2343 * If there is a signal pending, the user probably
2344 * interrupted (ctrl-c) us.
2345 * Leave loop with error set.
2347 if (signal_pending(current)) {
2348 DPR_OPEN(("%d: signal pending...\n", __LINE__));
2349 retval = -ERESTARTSYS;
2353 DPR_OPEN(("dgap_block_til_ready - blocking.\n"));
2356 * Store the flags before we let go of channel lock
2358 if (sleep_on_un_flags)
2359 old_flags = ch->ch_tun.un_flags | ch->ch_pun.un_flags;
2361 old_flags = ch->ch_flags;
2364 * Let go of channel lock before calling schedule.
2365 * Our poller will get any FEP events and wake us up when DCD
2366 * eventually goes active.
2369 DGAP_UNLOCK(ch->ch_lock, lock_flags);
2371 DPR_OPEN(("Going to sleep on %s flags...\n",
2372 (sleep_on_un_flags ? "un" : "ch")));
2375 * Wait for something in the flags to change from the current value.
2377 if (sleep_on_un_flags) {
2378 retval = wait_event_interruptible(un->un_flags_wait,
2379 (old_flags != (ch->ch_tun.un_flags | ch->ch_pun.un_flags)));
2382 retval = wait_event_interruptible(ch->ch_flags_wait,
2383 (old_flags != ch->ch_flags));
2386 DPR_OPEN(("After sleep... retval: %x\n", retval));
2389 * We got woken up for some reason.
2390 * Before looping around, grab our channel lock.
2392 DGAP_LOCK(ch->ch_lock, lock_flags);
2397 DGAP_UNLOCK(ch->ch_lock, lock_flags);
2399 DPR_OPEN(("dgap_block_til_ready - after blocking.\n"));
2402 DPR_OPEN(("dgap_block_til_ready - done. error. retval: %x\n", retval));
2406 DPR_OPEN(("dgap_block_til_ready - done no error. jiffies: %lu\n", jiffies));
2415 * Hangup the port. Like a close, but don't wait for output to drain.
2417 static void dgap_tty_hangup(struct tty_struct *tty)
2420 struct channel_t *ch;
2423 if (!tty || tty->magic != TTY_MAGIC)
2426 un = tty->driver_data;
2427 if (!un || un->magic != DGAP_UNIT_MAGIC)
2431 if (!ch || ch->magic != DGAP_CHANNEL_MAGIC)
2435 if (!bd || bd->magic != DGAP_BOARD_MAGIC)
2438 DPR_CLOSE(("dgap_hangup called. ch->ch_open_count: %d un->un_open_count: %d\n",
2439 ch->ch_open_count, un->un_open_count));
2441 /* flush the transmit queues */
2442 dgap_tty_flush_buffer(tty);
2444 DPR_CLOSE(("dgap_hangup finished. ch->ch_open_count: %d un->un_open_count: %d\n",
2445 ch->ch_open_count, un->un_open_count));
2454 static void dgap_tty_close(struct tty_struct *tty, struct file *file)
2456 struct ktermios *ts;
2458 struct channel_t *ch;
2463 if (!tty || tty->magic != TTY_MAGIC)
2466 un = tty->driver_data;
2467 if (!un || un->magic != DGAP_UNIT_MAGIC)
2471 if (!ch || ch->magic != DGAP_CHANNEL_MAGIC)
2475 if (!bd || bd->magic != DGAP_BOARD_MAGIC)
2480 DPR_CLOSE(("Close called\n"));
2482 DGAP_LOCK(ch->ch_lock, lock_flags);
2485 * Determine if this is the last close or not - and if we agree about
2486 * which type of close it is with the Line Discipline
2488 if ((tty->count == 1) && (un->un_open_count != 1)) {
2490 * Uh, oh. tty->count is 1, which means that the tty
2491 * structure will be freed. un_open_count should always
2492 * be one in these conditions. If it's greater than
2493 * one, we've got real problems, since it means the
2494 * serial port won't be shutdown.
2496 APR(("tty->count is 1, un open count is %d\n", un->un_open_count));
2497 un->un_open_count = 1;
2500 if (--un->un_open_count < 0) {
2501 APR(("bad serial port open count of %d\n", un->un_open_count));
2502 un->un_open_count = 0;
2505 ch->ch_open_count--;
2507 if (ch->ch_open_count && un->un_open_count) {
2508 DPR_CLOSE(("dgap_tty_close: not last close ch: %d un:%d\n",
2509 ch->ch_open_count, un->un_open_count));
2511 DGAP_UNLOCK(ch->ch_lock, lock_flags);
2515 /* OK, its the last close on the unit */
2516 DPR_CLOSE(("dgap_tty_close - last close on unit procedures\n"));
2518 un->un_flags |= UN_CLOSING;
2523 * Only officially close channel if count is 0 and
2524 * DIGI_PRINTER bit is not set.
2526 if ((ch->ch_open_count == 0) && !(ch->ch_digi.digi_flags & DIGI_PRINTER)) {
2528 ch->ch_flags &= ~(CH_RXBLOCK);
2530 DGAP_UNLOCK(ch->ch_lock, lock_flags);
2532 /* wait for output to drain */
2533 /* This will also return if we take an interrupt */
2535 DPR_CLOSE(("Calling wait_for_drain\n"));
2536 rc = dgap_wait_for_drain(tty);
2537 DPR_CLOSE(("After calling wait_for_drain\n"));
2540 DPR_BASIC(("dgap_tty_close - bad return: %d ", rc));
2543 dgap_tty_flush_buffer(tty);
2544 tty_ldisc_flush(tty);
2546 DGAP_LOCK(ch->ch_lock, lock_flags);
2551 * If we have HUPCL set, lower DTR and RTS
2553 if (ch->ch_c_cflag & HUPCL ) {
2554 DPR_CLOSE(("Close. HUPCL set, dropping DTR/RTS\n"));
2555 ch->ch_mostat &= ~(D_RTS(ch)|D_DTR(ch));
2556 dgap_cmdb( ch, SMODEM, 0, D_DTR(ch)|D_RTS(ch), 0 );
2559 * Go to sleep to ensure RTS/DTR
2560 * have been dropped for modems to see it.
2562 if (ch->ch_close_delay) {
2563 DPR_CLOSE(("Close. Sleeping for RTS/DTR drop\n"));
2565 DGAP_UNLOCK(ch->ch_lock, lock_flags);
2566 dgap_ms_sleep(ch->ch_close_delay);
2567 DGAP_LOCK(ch->ch_lock, lock_flags);
2569 DPR_CLOSE(("Close. After sleeping for RTS/DTR drop\n"));
2573 ch->pscan_state = 0;
2574 ch->pscan_savechar = 0;
2575 ch->ch_baud_info = 0;
2580 * turn off print device when closing print device.
2582 if ((un->un_type == DGAP_PRINT) && (ch->ch_flags & CH_PRON) ) {
2583 dgap_wmove(ch, ch->ch_digi.digi_offstr,
2584 (int) ch->ch_digi.digi_offlen);
2585 ch->ch_flags &= ~CH_PRON;
2589 un->un_flags &= ~(UN_ISOPEN | UN_CLOSING);
2590 tty->driver_data = NULL;
2592 DPR_CLOSE(("Close. Doing wakeups\n"));
2593 wake_up_interruptible(&ch->ch_flags_wait);
2594 wake_up_interruptible(&un->un_flags_wait);
2596 DGAP_UNLOCK(ch->ch_lock, lock_flags);
2598 DPR_BASIC(("dgap_tty_close - complete\n"));
2603 * dgap_tty_chars_in_buffer()
2605 * Return number of characters that have not been transmitted yet.
2607 * This routine is used by the line discipline to determine if there
2608 * is data waiting to be transmitted/drained/flushed or not.
2610 static int dgap_tty_chars_in_buffer(struct tty_struct *tty)
2612 struct board_t *bd = NULL;
2613 struct channel_t *ch = NULL;
2614 struct un_t *un = NULL;
2615 struct bs_t *bs = NULL;
2618 u16 thead, ttail, tmask, chead, ctail;
2619 ulong lock_flags = 0;
2620 ulong lock_flags2 = 0;
2625 un = tty->driver_data;
2626 if (!un || un->magic != DGAP_UNIT_MAGIC)
2630 if (!ch || ch->magic != DGAP_CHANNEL_MAGIC)
2634 if (!bd || bd->magic != DGAP_BOARD_MAGIC)
2641 DGAP_LOCK(bd->bd_lock, lock_flags);
2642 DGAP_LOCK(ch->ch_lock, lock_flags2);
2644 tmask = (ch->ch_tsize - 1);
2646 /* Get Transmit queue pointers */
2647 thead = readw(&(bs->tx_head)) & tmask;
2648 ttail = readw(&(bs->tx_tail)) & tmask;
2650 /* Get tbusy flag */
2651 tbusy = readb(&(bs->tbusy));
2653 /* Get Command queue pointers */
2654 chead = readw(&(ch->ch_cm->cm_head));
2655 ctail = readw(&(ch->ch_cm->cm_tail));
2657 DGAP_UNLOCK(ch->ch_lock, lock_flags2);
2658 DGAP_UNLOCK(bd->bd_lock, lock_flags);
2661 * The only way we know for sure if there is no pending
2662 * data left to be transferred, is if:
2663 * 1) Transmit head and tail are equal (empty).
2664 * 2) Command queue head and tail are equal (empty).
2665 * 3) The "TBUSY" flag is 0. (Transmitter not busy).
2668 if ((ttail == thead) && (tbusy == 0) && (chead == ctail)) {
2673 chars = thead - ttail;
2675 chars = thead - ttail + ch->ch_tsize;
2677 * Fudge factor here.
2678 * If chars is zero, we know that the command queue had
2679 * something in it or tbusy was set. Because we cannot
2680 * be sure if there is still some data to be transmitted,
2681 * lets lie, and tell ld we have 1 byte left.
2685 * If TBUSY is still set, and our tx buffers are empty,
2686 * force the firmware to send me another wakeup after
2687 * TBUSY has been cleared.
2690 DGAP_LOCK(ch->ch_lock, lock_flags);
2691 un->un_flags |= UN_EMPTY;
2692 writeb(1, &(bs->iempty));
2693 DGAP_UNLOCK(ch->ch_lock, lock_flags);
2699 DPR_WRITE(("dgap_tty_chars_in_buffer. Port: %x - %d (head: %d tail: %d tsize: %d)\n",
2700 ch->ch_portnum, chars, thead, ttail, ch->ch_tsize));
2705 static int dgap_wait_for_drain(struct tty_struct *tty)
2707 struct channel_t *ch;
2712 ulong lock_flags = 0;
2714 if (!tty || tty->magic != TTY_MAGIC)
2717 un = tty->driver_data;
2718 if (!un || un->magic != DGAP_UNIT_MAGIC)
2722 if (!ch || ch->magic != DGAP_CHANNEL_MAGIC)
2731 DPR_DRAIN(("dgap_wait_for_drain start\n"));
2733 /* Loop until data is drained */
2734 while (count != 0) {
2736 count = dgap_tty_chars_in_buffer(tty);
2741 /* Set flag waiting for drain */
2742 DGAP_LOCK(ch->ch_lock, lock_flags);
2743 un->un_flags |= UN_EMPTY;
2744 writeb(1, &(bs->iempty));
2745 DGAP_UNLOCK(ch->ch_lock, lock_flags);
2747 /* Go to sleep till we get woken up */
2748 ret = wait_event_interruptible(un->un_flags_wait, ((un->un_flags & UN_EMPTY) == 0));
2749 /* If ret is non-zero, user ctrl-c'ed us */
2755 DGAP_LOCK(ch->ch_lock, lock_flags);
2756 un->un_flags &= ~(UN_EMPTY);
2757 DGAP_UNLOCK(ch->ch_lock, lock_flags);
2759 DPR_DRAIN(("dgap_wait_for_drain finish\n"));
2767 * Reduces bytes_available to the max number of characters
2768 * that can be sent currently given the maxcps value, and
2769 * returns the new bytes_available. This only affects printer
2772 static int dgap_maxcps_room(struct tty_struct *tty, int bytes_available)
2774 struct channel_t *ch = NULL;
2775 struct un_t *un = NULL;
2778 return (bytes_available);
2780 un = tty->driver_data;
2781 if (!un || un->magic != DGAP_UNIT_MAGIC)
2782 return (bytes_available);
2785 if (!ch || ch->magic != DGAP_CHANNEL_MAGIC)
2786 return (bytes_available);
2789 * If its not the Transparent print device, return
2790 * the full data amount.
2792 if (un->un_type != DGAP_PRINT)
2793 return (bytes_available);
2795 if (ch->ch_digi.digi_maxcps > 0 && ch->ch_digi.digi_bufsize > 0 ) {
2797 unsigned long current_time = jiffies;
2798 unsigned long buffer_time = current_time +
2799 (HZ * ch->ch_digi.digi_bufsize) / ch->ch_digi.digi_maxcps;
2801 if (ch->ch_cpstime < current_time) {
2802 /* buffer is empty */
2803 ch->ch_cpstime = current_time; /* reset ch_cpstime */
2804 cps_limit = ch->ch_digi.digi_bufsize;
2806 else if (ch->ch_cpstime < buffer_time) {
2807 /* still room in the buffer */
2808 cps_limit = ((buffer_time - ch->ch_cpstime) * ch->ch_digi.digi_maxcps) / HZ;
2811 /* no room in the buffer */
2815 bytes_available = min(cps_limit, bytes_available);
2818 return (bytes_available);
2822 static inline void dgap_set_firmware_event(struct un_t *un, unsigned int event)
2824 struct channel_t *ch = NULL;
2825 struct bs_t *bs = NULL;
2827 if (!un || un->magic != DGAP_UNIT_MAGIC)
2830 if (!ch || ch->magic != DGAP_CHANNEL_MAGIC)
2836 if ((event & UN_LOW) != 0) {
2837 if ((un->un_flags & UN_LOW) == 0) {
2838 un->un_flags |= UN_LOW;
2839 writeb(1, &(bs->ilow));
2842 if ((event & UN_LOW) != 0) {
2843 if ((un->un_flags & UN_EMPTY) == 0) {
2844 un->un_flags |= UN_EMPTY;
2845 writeb(1, &(bs->iempty));
2852 * dgap_tty_write_room()
2854 * Return space available in Tx buffer
2856 static int dgap_tty_write_room(struct tty_struct *tty)
2858 struct channel_t *ch = NULL;
2859 struct un_t *un = NULL;
2860 struct bs_t *bs = NULL;
2861 u16 head, tail, tmask;
2863 ulong lock_flags = 0;
2865 if (tty == NULL || dgap_TmpWriteBuf == NULL)
2868 un = tty->driver_data;
2869 if (!un || un->magic != DGAP_UNIT_MAGIC)
2873 if (!ch || ch->magic != DGAP_CHANNEL_MAGIC)
2880 DGAP_LOCK(ch->ch_lock, lock_flags);
2882 tmask = ch->ch_tsize - 1;
2883 head = readw(&(bs->tx_head)) & tmask;
2884 tail = readw(&(bs->tx_tail)) & tmask;
2886 if ((ret = tail - head - 1) < 0)
2887 ret += ch->ch_tsize;
2889 /* Limit printer to maxcps */
2890 ret = dgap_maxcps_room(tty, ret);
2893 * If we are printer device, leave space for
2894 * possibly both the on and off strings.
2896 if (un->un_type == DGAP_PRINT) {
2897 if (!(ch->ch_flags & CH_PRON))
2898 ret -= ch->ch_digi.digi_onlen;
2899 ret -= ch->ch_digi.digi_offlen;
2902 if (ch->ch_flags & CH_PRON)
2903 ret -= ch->ch_digi.digi_offlen;
2910 * Schedule FEP to wake us up if needed.
2912 * TODO: This might be overkill...
2913 * Do we really need to schedule callbacks from the FEP
2914 * in every case? Can we get smarter based on ret?
2916 dgap_set_firmware_event(un, UN_LOW | UN_EMPTY);
2917 DGAP_UNLOCK(ch->ch_lock, lock_flags);
2919 DPR_WRITE(("dgap_tty_write_room - %d tail: %d head: %d\n", ret, tail, head));
2926 * dgap_tty_put_char()
2928 * Put a character into ch->ch_buf
2930 * - used by the line discipline for OPOST processing
2932 static int dgap_tty_put_char(struct tty_struct *tty, unsigned char c)
2935 * Simply call tty_write.
2937 DPR_WRITE(("dgap_tty_put_char called\n"));
2938 dgap_tty_write(tty, &c, 1);
2946 * Take data from the user or kernel and send it out to the FEP.
2947 * In here exists all the Transparent Print magic as well.
2949 static int dgap_tty_write(struct tty_struct *tty, const unsigned char *buf, int count)
2951 struct channel_t *ch = NULL;
2952 struct un_t *un = NULL;
2953 struct bs_t *bs = NULL;
2955 u16 head, tail, tmask, remain;
2956 int bufcount = 0, n = 0;
2961 if (tty == NULL || dgap_TmpWriteBuf == NULL)
2964 un = tty->driver_data;
2965 if (!un || un->magic != DGAP_UNIT_MAGIC)
2969 if (!ch || ch->magic != DGAP_CHANNEL_MAGIC)
2979 DPR_WRITE(("dgap_tty_write: Port: %x tty=%p user=%d len=%d\n",
2980 ch->ch_portnum, tty, from_user, count));
2983 * Store original amount of characters passed in.
2984 * This helps to figure out if we should ask the FEP
2985 * to send us an event when it has more space available.
2989 DGAP_LOCK(ch->ch_lock, lock_flags);
2991 /* Get our space available for the channel from the board */
2992 tmask = ch->ch_tsize - 1;
2993 head = readw(&(bs->tx_head)) & tmask;
2994 tail = readw(&(bs->tx_tail)) & tmask;
2996 if ((bufcount = tail - head - 1) < 0)
2997 bufcount += ch->ch_tsize;
2999 DPR_WRITE(("%d: bufcount: %x count: %x tail: %x head: %x tmask: %x\n",
3000 __LINE__, bufcount, count, tail, head, tmask));
3003 * Limit printer output to maxcps overall, with bursts allowed
3004 * up to bufsize characters.
3006 bufcount = dgap_maxcps_room(tty, bufcount);
3009 * Take minimum of what the user wants to send, and the
3010 * space available in the FEP buffer.
3012 count = min(count, bufcount);
3015 * Bail if no space left.
3018 dgap_set_firmware_event(un, UN_LOW | UN_EMPTY);
3019 DGAP_UNLOCK(ch->ch_lock, lock_flags);
3024 * Output the printer ON string, if we are in terminal mode, but
3025 * need to be in printer mode.
3027 if ((un->un_type == DGAP_PRINT) && !(ch->ch_flags & CH_PRON)) {
3028 dgap_wmove(ch, ch->ch_digi.digi_onstr,
3029 (int) ch->ch_digi.digi_onlen);
3030 head = readw(&(bs->tx_head)) & tmask;
3031 ch->ch_flags |= CH_PRON;
3035 * On the other hand, output the printer OFF string, if we are
3036 * currently in printer mode, but need to output to the terminal.
3038 if ((un->un_type != DGAP_PRINT) && (ch->ch_flags & CH_PRON)) {
3039 dgap_wmove(ch, ch->ch_digi.digi_offstr,
3040 (int) ch->ch_digi.digi_offlen);
3041 head = readw(&(bs->tx_head)) & tmask;
3042 ch->ch_flags &= ~CH_PRON;
3046 * If there is nothing left to copy, or I can't handle any more data, leave.
3049 dgap_set_firmware_event(un, UN_LOW | UN_EMPTY);
3050 DGAP_UNLOCK(ch->ch_lock, lock_flags);
3056 count = min(count, WRITEBUFLEN);
3058 DGAP_UNLOCK(ch->ch_lock, lock_flags);
3061 * If data is coming from user space, copy it into a temporary
3062 * buffer so we don't get swapped out while doing the copy to
3065 /* we're allowed to block if it's from_user */
3066 if (down_interruptible(&dgap_TmpWriteSem)) {
3070 if (copy_from_user(dgap_TmpWriteBuf, (const uchar __user *) buf, count)) {
3071 up(&dgap_TmpWriteSem);
3072 printk("Write: Copy from user failed!\n");
3076 DGAP_LOCK(ch->ch_lock, lock_flags);
3078 buf = dgap_TmpWriteBuf;
3084 * If the write wraps over the top of the circular buffer,
3085 * move the portion up to the wrap point, and reset the
3086 * pointers to the bottom.
3088 remain = ch->ch_tstart + ch->ch_tsize - head;
3092 vaddr = ch->ch_taddr + head;
3094 memcpy_toio(vaddr, (uchar *) buf, remain);
3095 dgap_sniff_nowait_nolock(ch, "USER WRITE", (uchar *) buf, remain);
3097 head = ch->ch_tstart;
3104 * Move rest of data.
3106 vaddr = ch->ch_taddr + head;
3109 memcpy_toio(vaddr, (uchar *) buf, remain);
3110 dgap_sniff_nowait_nolock(ch, "USER WRITE", (uchar *) buf, remain);
3117 ch->ch_txcount += count;
3119 writew(head, &(bs->tx_head));
3123 dgap_set_firmware_event(un, UN_LOW | UN_EMPTY);
3126 * If this is the print device, and the
3127 * printer is still on, we need to turn it
3128 * off before going idle. If the buffer is
3129 * non-empty, wait until it goes empty.
3130 * Otherwise turn it off right now.
3132 if ((un->un_type == DGAP_PRINT) && (ch->ch_flags & CH_PRON)) {
3133 tail = readw(&(bs->tx_tail)) & tmask;
3136 un->un_flags |= UN_EMPTY;
3137 writeb(1, &(bs->iempty));
3140 dgap_wmove(ch, ch->ch_digi.digi_offstr,
3141 (int) ch->ch_digi.digi_offlen);
3142 head = readw(&(bs->tx_head)) & tmask;
3143 ch->ch_flags &= ~CH_PRON;
3147 /* Update printer buffer empty time. */
3148 if ((un->un_type == DGAP_PRINT) && (ch->ch_digi.digi_maxcps > 0)
3149 && (ch->ch_digi.digi_bufsize > 0)) {
3150 ch->ch_cpstime += (HZ * count) / ch->ch_digi.digi_maxcps;
3154 DGAP_UNLOCK(ch->ch_lock, lock_flags);
3155 up(&dgap_TmpWriteSem);
3158 DGAP_UNLOCK(ch->ch_lock, lock_flags);
3161 DPR_WRITE(("Write finished - Write %d bytes of %d.\n", count, orig_count));
3169 * Return modem signals to ld.
3171 static int dgap_tty_tiocmget(struct tty_struct *tty)
3173 struct channel_t *ch;
3179 if (!tty || tty->magic != TTY_MAGIC)
3182 un = tty->driver_data;
3183 if (!un || un->magic != DGAP_UNIT_MAGIC)
3187 if (!ch || ch->magic != DGAP_CHANNEL_MAGIC)
3190 DPR_IOCTL(("dgap_tty_tiocmget start\n"));
3192 DGAP_LOCK(ch->ch_lock, lock_flags);
3194 mstat = readb(&(ch->ch_bs->m_stat));
3195 /* Append any outbound signals that might be pending... */
3196 mstat |= ch->ch_mostat;
3198 DGAP_UNLOCK(ch->ch_lock, lock_flags);
3202 if (mstat & D_DTR(ch))
3203 result |= TIOCM_DTR;
3204 if (mstat & D_RTS(ch))
3205 result |= TIOCM_RTS;
3206 if (mstat & D_CTS(ch))
3207 result |= TIOCM_CTS;
3208 if (mstat & D_DSR(ch))
3209 result |= TIOCM_DSR;
3210 if (mstat & D_RI(ch))
3212 if (mstat & D_CD(ch))
3215 DPR_IOCTL(("dgap_tty_tiocmget finish\n"));
3222 * dgap_tty_tiocmset()
3224 * Set modem signals, called by ld.
3227 static int dgap_tty_tiocmset(struct tty_struct *tty,
3228 unsigned int set, unsigned int clear)
3231 struct channel_t *ch;
3237 if (!tty || tty->magic != TTY_MAGIC)
3240 un = tty->driver_data;
3241 if (!un || un->magic != DGAP_UNIT_MAGIC)
3245 if (!ch || ch->magic != DGAP_CHANNEL_MAGIC)
3249 if (!bd || bd->magic != DGAP_BOARD_MAGIC)
3252 DPR_IOCTL(("dgap_tty_tiocmset start\n"));
3254 DGAP_LOCK(bd->bd_lock, lock_flags);
3255 DGAP_LOCK(ch->ch_lock, lock_flags2);
3257 if (set & TIOCM_RTS) {
3258 ch->ch_mforce |= D_RTS(ch);
3259 ch->ch_mval |= D_RTS(ch);
3262 if (set & TIOCM_DTR) {
3263 ch->ch_mforce |= D_DTR(ch);
3264 ch->ch_mval |= D_DTR(ch);
3267 if (clear & TIOCM_RTS) {
3268 ch->ch_mforce |= D_RTS(ch);
3269 ch->ch_mval &= ~(D_RTS(ch));
3272 if (clear & TIOCM_DTR) {
3273 ch->ch_mforce |= D_DTR(ch);
3274 ch->ch_mval &= ~(D_DTR(ch));
3279 DGAP_UNLOCK(ch->ch_lock, lock_flags2);
3280 DGAP_UNLOCK(bd->bd_lock, lock_flags);
3282 DPR_IOCTL(("dgap_tty_tiocmset finish\n"));
3290 * dgap_tty_send_break()
3292 * Send a Break, called by ld.
3294 static int dgap_tty_send_break(struct tty_struct *tty, int msec)
3297 struct channel_t *ch;
3303 if (!tty || tty->magic != TTY_MAGIC)
3306 un = tty->driver_data;
3307 if (!un || un->magic != DGAP_UNIT_MAGIC)
3311 if (!ch || ch->magic != DGAP_CHANNEL_MAGIC)
3315 if (!bd || bd->magic != DGAP_BOARD_MAGIC)
3330 DPR_IOCTL(("dgap_tty_send_break start 1. %lx\n", jiffies));
3332 DGAP_LOCK(bd->bd_lock, lock_flags);
3333 DGAP_LOCK(ch->ch_lock, lock_flags2);
3335 dgap_cmdw(ch, SBREAK, (u16) SBREAK_TIME, 0);
3337 dgap_cmdw(ch, SBREAK, (u16) msec, 0);
3339 DGAP_UNLOCK(ch->ch_lock, lock_flags2);
3340 DGAP_UNLOCK(bd->bd_lock, lock_flags);
3342 DPR_IOCTL(("dgap_tty_send_break finish\n"));
3351 * dgap_tty_wait_until_sent()
3353 * wait until data has been transmitted, called by ld.
3355 static void dgap_tty_wait_until_sent(struct tty_struct *tty, int timeout)
3358 rc = dgap_wait_for_drain(tty);
3360 DPR_IOCTL(("dgap_tty_ioctl - bad return: %d ", rc));
3371 * send a high priority character, called by ld.
3373 static void dgap_tty_send_xchar(struct tty_struct *tty, char c)
3376 struct channel_t *ch;
3381 if (!tty || tty->magic != TTY_MAGIC)
3384 un = tty->driver_data;
3385 if (!un || un->magic != DGAP_UNIT_MAGIC)
3389 if (!ch || ch->magic != DGAP_CHANNEL_MAGIC)
3393 if (!bd || bd->magic != DGAP_BOARD_MAGIC)
3396 DPR_IOCTL(("dgap_tty_send_xchar start 1. %lx\n", jiffies));
3398 DGAP_LOCK(bd->bd_lock, lock_flags);
3399 DGAP_LOCK(ch->ch_lock, lock_flags2);
3402 * This is technically what we should do.
3403 * However, the NIST tests specifically want
3404 * to see each XON or XOFF character that it
3405 * sends, so lets just send each character
3409 if (c == STOP_CHAR(tty)) {
3410 dgap_cmdw(ch, RPAUSE, 0, 0);
3412 else if (c == START_CHAR(tty)) {
3413 dgap_cmdw(ch, RRESUME, 0, 0);
3416 dgap_wmove(ch, &c, 1);
3419 dgap_wmove(ch, &c, 1);
3422 DGAP_UNLOCK(ch->ch_lock, lock_flags2);
3423 DGAP_UNLOCK(bd->bd_lock, lock_flags);
3425 DPR_IOCTL(("dgap_tty_send_xchar finish\n"));
3434 * Return modem signals to ld.
3436 static int dgap_get_modem_info(struct channel_t *ch, unsigned int __user *value)
3443 DPR_IOCTL(("dgap_get_modem_info start\n"));
3445 if (!ch || ch->magic != DGAP_CHANNEL_MAGIC)
3448 DGAP_LOCK(ch->ch_lock, lock_flags);
3450 mstat = readb(&(ch->ch_bs->m_stat));
3451 /* Append any outbound signals that might be pending... */
3452 mstat |= ch->ch_mostat;
3454 DGAP_UNLOCK(ch->ch_lock, lock_flags);
3458 if (mstat & D_DTR(ch))
3459 result |= TIOCM_DTR;
3460 if (mstat & D_RTS(ch))
3461 result |= TIOCM_RTS;
3462 if (mstat & D_CTS(ch))
3463 result |= TIOCM_CTS;
3464 if (mstat & D_DSR(ch))
3465 result |= TIOCM_DSR;
3466 if (mstat & D_RI(ch))
3468 if (mstat & D_CD(ch))
3471 rc = put_user(result, value);
3473 DPR_IOCTL(("dgap_get_modem_info finish\n"));
3479 * dgap_set_modem_info()
3481 * Set modem signals, called by ld.
3483 static int dgap_set_modem_info(struct tty_struct *tty, unsigned int command, unsigned int __user *value)
3486 struct channel_t *ch;
3489 unsigned int arg = 0;
3493 if (!tty || tty->magic != TTY_MAGIC)
3496 un = tty->driver_data;
3497 if (!un || un->magic != DGAP_UNIT_MAGIC)
3501 if (!ch || ch->magic != DGAP_CHANNEL_MAGIC)
3505 if (!bd || bd->magic != DGAP_BOARD_MAGIC)
3508 DPR_IOCTL(("dgap_set_modem_info() start\n"));
3510 ret = get_user(arg, value);
3512 DPR_IOCTL(("dgap_set_modem_info %d ret: %x. finished.\n", __LINE__, ret));
3516 DPR_IOCTL(("dgap_set_modem_info: command: %x arg: %x\n", command, arg));
3520 if (arg & TIOCM_RTS) {
3521 ch->ch_mforce |= D_RTS(ch);
3522 ch->ch_mval |= D_RTS(ch);
3525 if (arg & TIOCM_DTR) {
3526 ch->ch_mforce |= D_DTR(ch);
3527 ch->ch_mval |= D_DTR(ch);
3533 if (arg & TIOCM_RTS) {
3534 ch->ch_mforce |= D_RTS(ch);
3535 ch->ch_mval &= ~(D_RTS(ch));
3538 if (arg & TIOCM_DTR) {
3539 ch->ch_mforce |= D_DTR(ch);
3540 ch->ch_mval &= ~(D_DTR(ch));
3546 ch->ch_mforce = D_DTR(ch)|D_RTS(ch);
3548 if (arg & TIOCM_RTS) {
3549 ch->ch_mval |= D_RTS(ch);
3552 ch->ch_mval &= ~(D_RTS(ch));
3555 if (arg & TIOCM_DTR) {
3556 ch->ch_mval |= (D_DTR(ch));
3559 ch->ch_mval &= ~(D_DTR(ch));
3568 DGAP_LOCK(bd->bd_lock, lock_flags);
3569 DGAP_LOCK(ch->ch_lock, lock_flags2);
3573 DGAP_UNLOCK(ch->ch_lock, lock_flags2);
3574 DGAP_UNLOCK(bd->bd_lock, lock_flags);
3576 DPR_IOCTL(("dgap_set_modem_info finish\n"));
3583 * dgap_tty_digigeta()
3585 * Ioctl to get the information for ditty.
3590 static int dgap_tty_digigeta(struct tty_struct *tty, struct digi_t __user *retinfo)
3592 struct channel_t *ch;
3600 if (!tty || tty->magic != TTY_MAGIC)
3603 un = tty->driver_data;
3604 if (!un || un->magic != DGAP_UNIT_MAGIC)
3608 if (!ch || ch->magic != DGAP_CHANNEL_MAGIC)
3611 memset(&tmp, 0, sizeof(tmp));
3613 DGAP_LOCK(ch->ch_lock, lock_flags);
3614 memcpy(&tmp, &ch->ch_digi, sizeof(tmp));
3615 DGAP_UNLOCK(ch->ch_lock, lock_flags);
3617 if (copy_to_user(retinfo, &tmp, sizeof(*retinfo)))
3625 * dgap_tty_digiseta()
3627 * Ioctl to set the information for ditty.
3632 static int dgap_tty_digiseta(struct tty_struct *tty, struct digi_t __user *new_info)
3635 struct channel_t *ch;
3637 struct digi_t new_digi;
3638 ulong lock_flags = 0;
3639 unsigned long lock_flags2;
3641 DPR_IOCTL(("DIGI_SETA start\n"));
3643 if (!tty || tty->magic != TTY_MAGIC)
3646 un = tty->driver_data;
3647 if (!un || un->magic != DGAP_UNIT_MAGIC)
3651 if (!ch || ch->magic != DGAP_CHANNEL_MAGIC)
3655 if (!bd || bd->magic != DGAP_BOARD_MAGIC)
3658 if (copy_from_user(&new_digi, new_info, sizeof(struct digi_t))) {
3659 DPR_IOCTL(("DIGI_SETA failed copy_from_user\n"));
3663 DGAP_LOCK(bd->bd_lock, lock_flags);
3664 DGAP_LOCK(ch->ch_lock, lock_flags2);
3666 memcpy(&ch->ch_digi, &new_digi, sizeof(struct digi_t));
3668 if (ch->ch_digi.digi_maxcps < 1)
3669 ch->ch_digi.digi_maxcps = 1;
3671 if (ch->ch_digi.digi_maxcps > 10000)
3672 ch->ch_digi.digi_maxcps = 10000;
3674 if (ch->ch_digi.digi_bufsize < 10)
3675 ch->ch_digi.digi_bufsize = 10;
3677 if (ch->ch_digi.digi_maxchar < 1)
3678 ch->ch_digi.digi_maxchar = 1;
3680 if (ch->ch_digi.digi_maxchar > ch->ch_digi.digi_bufsize)
3681 ch->ch_digi.digi_maxchar = ch->ch_digi.digi_bufsize;
3683 if (ch->ch_digi.digi_onlen > DIGI_PLEN)
3684 ch->ch_digi.digi_onlen = DIGI_PLEN;
3686 if (ch->ch_digi.digi_offlen > DIGI_PLEN)
3687 ch->ch_digi.digi_offlen = DIGI_PLEN;
3691 DGAP_UNLOCK(ch->ch_lock, lock_flags2);
3692 DGAP_UNLOCK(bd->bd_lock, lock_flags);
3694 DPR_IOCTL(("DIGI_SETA finish\n"));
3701 * dgap_tty_digigetedelay()
3703 * Ioctl to get the current edelay setting.
3708 static int dgap_tty_digigetedelay(struct tty_struct *tty, int __user *retinfo)
3710 struct channel_t *ch;
3718 if (!tty || tty->magic != TTY_MAGIC)
3721 un = tty->driver_data;
3722 if (!un || un->magic != DGAP_UNIT_MAGIC)
3726 if (!ch || ch->magic != DGAP_CHANNEL_MAGIC)
3729 memset(&tmp, 0, sizeof(tmp));
3731 DGAP_LOCK(ch->ch_lock, lock_flags);
3732 tmp = readw(&(ch->ch_bs->edelay));
3733 DGAP_UNLOCK(ch->ch_lock, lock_flags);
3735 if (copy_to_user(retinfo, &tmp, sizeof(*retinfo)))
3743 * dgap_tty_digisetedelay()
3745 * Ioctl to set the EDELAY setting
3748 static int dgap_tty_digisetedelay(struct tty_struct *tty, int __user *new_info)
3751 struct channel_t *ch;
3757 DPR_IOCTL(("DIGI_SETA start\n"));
3759 if (!tty || tty->magic != TTY_MAGIC)
3762 un = tty->driver_data;
3763 if (!un || un->magic != DGAP_UNIT_MAGIC)
3767 if (!ch || ch->magic != DGAP_CHANNEL_MAGIC)
3771 if (!bd || bd->magic != DGAP_BOARD_MAGIC)
3774 if (copy_from_user(&new_digi, new_info, sizeof(int))) {
3775 DPR_IOCTL(("DIGI_SETEDELAY failed copy_from_user\n"));
3779 DGAP_LOCK(bd->bd_lock, lock_flags);
3780 DGAP_LOCK(ch->ch_lock, lock_flags2);
3782 writew((u16) new_digi, &(ch->ch_bs->edelay));
3786 DGAP_UNLOCK(ch->ch_lock, lock_flags2);
3787 DGAP_UNLOCK(bd->bd_lock, lock_flags);
3789 DPR_IOCTL(("DIGI_SETA finish\n"));
3796 * dgap_tty_digigetcustombaud()
3798 * Ioctl to get the current custom baud rate setting.
3800 static int dgap_tty_digigetcustombaud(struct tty_struct *tty, int __user *retinfo)
3802 struct channel_t *ch;
3810 if (!tty || tty->magic != TTY_MAGIC)
3813 un = tty->driver_data;
3814 if (!un || un->magic != DGAP_UNIT_MAGIC)
3818 if (!ch || ch->magic != DGAP_CHANNEL_MAGIC)
3821 memset(&tmp, 0, sizeof(tmp));
3823 DGAP_LOCK(ch->ch_lock, lock_flags);
3824 tmp = dgap_get_custom_baud(ch);
3825 DGAP_UNLOCK(ch->ch_lock, lock_flags);
3827 DPR_IOCTL(("DIGI_GETCUSTOMBAUD. Returning %d\n", tmp));
3829 if (copy_to_user(retinfo, &tmp, sizeof(*retinfo)))
3837 * dgap_tty_digisetcustombaud()
3839 * Ioctl to set the custom baud rate setting
3841 static int dgap_tty_digisetcustombaud(struct tty_struct *tty, int __user *new_info)
3844 struct channel_t *ch;
3850 DPR_IOCTL(("DIGI_SETCUSTOMBAUD start\n"));
3852 if (!tty || tty->magic != TTY_MAGIC)
3855 un = tty->driver_data;
3856 if (!un || un->magic != DGAP_UNIT_MAGIC)
3860 if (!ch || ch->magic != DGAP_CHANNEL_MAGIC)
3864 if (!bd || bd->magic != DGAP_BOARD_MAGIC)
3868 if (copy_from_user(&new_rate, new_info, sizeof(unsigned int))) {
3869 DPR_IOCTL(("DIGI_SETCUSTOMBAUD failed copy_from_user\n"));
3873 if (bd->bd_flags & BD_FEP5PLUS) {
3875 DPR_IOCTL(("DIGI_SETCUSTOMBAUD. Setting %d\n", new_rate));
3877 DGAP_LOCK(bd->bd_lock, lock_flags);
3878 DGAP_LOCK(ch->ch_lock, lock_flags2);
3880 ch->ch_custom_speed = new_rate;
3884 DGAP_UNLOCK(ch->ch_lock, lock_flags2);
3885 DGAP_UNLOCK(bd->bd_lock, lock_flags);
3888 DPR_IOCTL(("DIGI_SETCUSTOMBAUD finish\n"));
3895 * dgap_set_termios()
3897 static void dgap_tty_set_termios(struct tty_struct *tty, struct ktermios *old_termios)
3900 struct channel_t *ch;
3902 unsigned long lock_flags;
3903 unsigned long lock_flags2;
3905 if (!tty || tty->magic != TTY_MAGIC)
3908 un = tty->driver_data;
3909 if (!un || un->magic != DGAP_UNIT_MAGIC)
3913 if (!ch || ch->magic != DGAP_CHANNEL_MAGIC)
3917 if (!bd || bd->magic != DGAP_BOARD_MAGIC)
3920 DGAP_LOCK(bd->bd_lock, lock_flags);
3921 DGAP_LOCK(ch->ch_lock, lock_flags2);
3923 ch->ch_c_cflag = tty->termios.c_cflag;
3924 ch->ch_c_iflag = tty->termios.c_iflag;
3925 ch->ch_c_oflag = tty->termios.c_oflag;
3926 ch->ch_c_lflag = tty->termios.c_lflag;
3927 ch->ch_startc = tty->termios.c_cc[VSTART];
3928 ch->ch_stopc = tty->termios.c_cc[VSTOP];
3933 DGAP_UNLOCK(ch->ch_lock, lock_flags2);
3934 DGAP_UNLOCK(bd->bd_lock, lock_flags);
3938 static void dgap_tty_throttle(struct tty_struct *tty)
3941 struct channel_t *ch;
3946 if (!tty || tty->magic != TTY_MAGIC)
3949 un = tty->driver_data;
3950 if (!un || un->magic != DGAP_UNIT_MAGIC)
3954 if (!ch || ch->magic != DGAP_CHANNEL_MAGIC)
3958 if (!bd || bd->magic != DGAP_BOARD_MAGIC)
3961 DPR_IOCTL(("dgap_tty_throttle start\n"));
3963 DGAP_LOCK(bd->bd_lock, lock_flags);
3964 DGAP_LOCK(ch->ch_lock, lock_flags2);
3966 ch->ch_flags |= (CH_RXBLOCK);
3968 dgap_cmdw(ch, RPAUSE, 0, 0);
3971 DGAP_UNLOCK(ch->ch_lock, lock_flags2);
3972 DGAP_UNLOCK(bd->bd_lock, lock_flags);
3974 DPR_IOCTL(("dgap_tty_throttle finish\n"));
3978 static void dgap_tty_unthrottle(struct tty_struct *tty)
3981 struct channel_t *ch;
3986 if (!tty || tty->magic != TTY_MAGIC)
3989 un = tty->driver_data;
3990 if (!un || un->magic != DGAP_UNIT_MAGIC)
3994 if (!ch || ch->magic != DGAP_CHANNEL_MAGIC)
3998 if (!bd || bd->magic != DGAP_BOARD_MAGIC)
4001 DPR_IOCTL(("dgap_tty_unthrottle start\n"));
4003 DGAP_LOCK(bd->bd_lock, lock_flags);
4004 DGAP_LOCK(ch->ch_lock, lock_flags2);
4006 ch->ch_flags &= ~(CH_RXBLOCK);
4009 dgap_cmdw(ch, RRESUME, 0, 0);
4012 DGAP_UNLOCK(ch->ch_lock, lock_flags2);
4013 DGAP_UNLOCK(bd->bd_lock, lock_flags);
4015 DPR_IOCTL(("dgap_tty_unthrottle finish\n"));
4019 static void dgap_tty_start(struct tty_struct *tty)
4022 struct channel_t *ch;
4027 if (!tty || tty->magic != TTY_MAGIC)
4030 un = tty->driver_data;
4031 if (!un || un->magic != DGAP_UNIT_MAGIC)
4035 if (!ch || ch->magic != DGAP_CHANNEL_MAGIC)
4039 if (!bd || bd->magic != DGAP_BOARD_MAGIC)
4042 DPR_IOCTL(("dgap_tty_start start\n"));
4044 DGAP_LOCK(bd->bd_lock, lock_flags);
4045 DGAP_LOCK(ch->ch_lock, lock_flags2);
4047 dgap_cmdw(ch, RESUMETX, 0, 0);
4049 DGAP_UNLOCK(ch->ch_lock, lock_flags2);
4050 DGAP_UNLOCK(bd->bd_lock, lock_flags);
4052 DPR_IOCTL(("dgap_tty_start finish\n"));
4056 static void dgap_tty_stop(struct tty_struct *tty)
4059 struct channel_t *ch;
4064 if (!tty || tty->magic != TTY_MAGIC)
4067 un = tty->driver_data;
4068 if (!un || un->magic != DGAP_UNIT_MAGIC)
4072 if (!ch || ch->magic != DGAP_CHANNEL_MAGIC)
4076 if (!bd || bd->magic != DGAP_BOARD_MAGIC)
4079 DPR_IOCTL(("dgap_tty_stop start\n"));
4081 DGAP_LOCK(bd->bd_lock, lock_flags);
4082 DGAP_LOCK(ch->ch_lock, lock_flags2);
4084 dgap_cmdw(ch, PAUSETX, 0, 0);
4086 DGAP_UNLOCK(ch->ch_lock, lock_flags2);
4087 DGAP_UNLOCK(bd->bd_lock, lock_flags);
4089 DPR_IOCTL(("dgap_tty_stop finish\n"));
4094 * dgap_tty_flush_chars()
4096 * Flush the cook buffer
4098 * Note to self, and any other poor souls who venture here:
4100 * flush in this case DOES NOT mean dispose of the data.
4101 * instead, it means "stop buffering and send it if you
4102 * haven't already." Just guess how I figured that out... SRW 2-Jun-98
4104 * It is also always called in interrupt context - JAR 8-Sept-99
4106 static void dgap_tty_flush_chars(struct tty_struct *tty)
4109 struct channel_t *ch;
4114 if (!tty || tty->magic != TTY_MAGIC)
4117 un = tty->driver_data;
4118 if (!un || un->magic != DGAP_UNIT_MAGIC)
4122 if (!ch || ch->magic != DGAP_CHANNEL_MAGIC)
4126 if (!bd || bd->magic != DGAP_BOARD_MAGIC)
4129 DPR_IOCTL(("dgap_tty_flush_chars start\n"));
4131 DGAP_LOCK(bd->bd_lock, lock_flags);
4132 DGAP_LOCK(ch->ch_lock, lock_flags2);
4134 /* TODO: Do something here */
4136 DGAP_UNLOCK(ch->ch_lock, lock_flags2);
4137 DGAP_UNLOCK(bd->bd_lock, lock_flags);
4139 DPR_IOCTL(("dgap_tty_flush_chars finish\n"));
4145 * dgap_tty_flush_buffer()
4147 * Flush Tx buffer (make in == out)
4149 static void dgap_tty_flush_buffer(struct tty_struct *tty)
4152 struct channel_t *ch;
4158 if (!tty || tty->magic != TTY_MAGIC)
4161 un = tty->driver_data;
4162 if (!un || un->magic != DGAP_UNIT_MAGIC)
4166 if (!ch || ch->magic != DGAP_CHANNEL_MAGIC)
4170 if (!bd || bd->magic != DGAP_BOARD_MAGIC)
4173 DPR_IOCTL(("dgap_tty_flush_buffer on port: %d start\n", ch->ch_portnum));
4175 DGAP_LOCK(bd->bd_lock, lock_flags);
4176 DGAP_LOCK(ch->ch_lock, lock_flags2);
4178 ch->ch_flags &= ~CH_STOP;
4179 head = readw(&(ch->ch_bs->tx_head));
4180 dgap_cmdw(ch, FLUSHTX, (u16) head, 0);
4181 dgap_cmdw(ch, RESUMETX, 0, 0);
4182 if (ch->ch_tun.un_flags & (UN_LOW|UN_EMPTY)) {
4183 ch->ch_tun.un_flags &= ~(UN_LOW|UN_EMPTY);
4184 wake_up_interruptible(&ch->ch_tun.un_flags_wait);
4186 if (ch->ch_pun.un_flags & (UN_LOW|UN_EMPTY)) {
4187 ch->ch_pun.un_flags &= ~(UN_LOW|UN_EMPTY);
4188 wake_up_interruptible(&ch->ch_pun.un_flags_wait);
4191 DGAP_UNLOCK(ch->ch_lock, lock_flags2);
4192 DGAP_UNLOCK(bd->bd_lock, lock_flags);
4193 if (waitqueue_active(&tty->write_wait))
4194 wake_up_interruptible(&tty->write_wait);
4197 DPR_IOCTL(("dgap_tty_flush_buffer finish\n"));
4202 /*****************************************************************************
4204 * The IOCTL function and all of its helpers
4206 *****************************************************************************/
4211 * The usual assortment of ioctl's
4213 static int dgap_tty_ioctl(struct tty_struct *tty, unsigned int cmd,
4217 struct channel_t *ch;
4221 ulong lock_flags = 0;
4222 ulong lock_flags2 = 0;
4223 void __user *uarg = (void __user *) arg;
4225 if (!tty || tty->magic != TTY_MAGIC)
4228 un = tty->driver_data;
4229 if (!un || un->magic != DGAP_UNIT_MAGIC)
4233 if (!ch || ch->magic != DGAP_CHANNEL_MAGIC)
4237 if (!bd || bd->magic != DGAP_BOARD_MAGIC)
4240 DPR_IOCTL(("dgap_tty_ioctl start on port %d - cmd %s (%x), arg %lx\n",
4241 ch->ch_portnum, dgap_ioctl_name(cmd), cmd, arg));
4243 DGAP_LOCK(bd->bd_lock, lock_flags);
4244 DGAP_LOCK(ch->ch_lock, lock_flags2);
4246 if (un->un_open_count <= 0) {
4247 DPR_BASIC(("dgap_tty_ioctl - unit not open.\n"));
4248 DGAP_UNLOCK(ch->ch_lock, lock_flags2);
4249 DGAP_UNLOCK(bd->bd_lock, lock_flags);
4255 /* Here are all the standard ioctl's that we MUST implement */
4259 * TCSBRK is SVID version: non-zero arg --> no break
4260 * this behaviour is exploited by tcdrain().
4262 * According to POSIX.1 spec (7.2.2.1.2) breaks should be
4263 * between 0.25 and 0.5 seconds so we'll ask for something
4264 * in the middle: 0.375 seconds.
4266 rc = tty_check_change(tty);
4267 DGAP_UNLOCK(ch->ch_lock, lock_flags2);
4268 DGAP_UNLOCK(bd->bd_lock, lock_flags);
4273 rc = dgap_wait_for_drain(tty);
4276 DPR_IOCTL(("dgap_tty_ioctl - bad return: %d ", rc));
4280 DGAP_LOCK(bd->bd_lock, lock_flags);
4281 DGAP_LOCK(ch->ch_lock, lock_flags2);
4283 if(((cmd == TCSBRK) && (!arg)) || (cmd == TCSBRKP)) {
4284 dgap_cmdw(ch, SBREAK, (u16) SBREAK_TIME, 0);
4287 DGAP_UNLOCK(ch->ch_lock, lock_flags2);
4288 DGAP_UNLOCK(bd->bd_lock, lock_flags);
4290 DPR_IOCTL(("dgap_tty_ioctl finish on port %d - cmd %s (%x), arg %lx\n",
4291 ch->ch_portnum, dgap_ioctl_name(cmd), cmd, arg));
4297 /* support for POSIX tcsendbreak()
4299 * According to POSIX.1 spec (7.2.2.1.2) breaks should be
4300 * between 0.25 and 0.5 seconds so we'll ask for something
4301 * in the middle: 0.375 seconds.
4303 rc = tty_check_change(tty);
4304 DGAP_UNLOCK(ch->ch_lock, lock_flags2);
4305 DGAP_UNLOCK(bd->bd_lock, lock_flags);
4310 rc = dgap_wait_for_drain(tty);
4312 DPR_IOCTL(("dgap_tty_ioctl - bad return: %d ", rc));
4316 DGAP_LOCK(bd->bd_lock, lock_flags);
4317 DGAP_LOCK(ch->ch_lock, lock_flags2);
4319 dgap_cmdw(ch, SBREAK, (u16) SBREAK_TIME, 0);
4321 DGAP_UNLOCK(ch->ch_lock, lock_flags2);
4322 DGAP_UNLOCK(bd->bd_lock, lock_flags);
4324 DPR_IOCTL(("dgap_tty_ioctl finish on port %d - cmd %s (%x), arg %lx\n",
4325 ch->ch_portnum, dgap_ioctl_name(cmd), cmd, arg));
4331 * FEP5 doesn't support turning on a break unconditionally.
4332 * The FEP5 device will stop sending a break automatically
4333 * after the specified time value that was sent when turning on
4336 rc = tty_check_change(tty);
4337 DGAP_UNLOCK(ch->ch_lock, lock_flags2);
4338 DGAP_UNLOCK(bd->bd_lock, lock_flags);
4343 rc = dgap_wait_for_drain(tty);
4345 DPR_IOCTL(("dgap_tty_ioctl - bad return: %d ", rc));
4349 DGAP_LOCK(bd->bd_lock, lock_flags);
4350 DGAP_LOCK(ch->ch_lock, lock_flags2);
4352 dgap_cmdw(ch, SBREAK, (u16) SBREAK_TIME, 0);
4354 DGAP_UNLOCK(ch->ch_lock, lock_flags2);
4355 DGAP_UNLOCK(bd->bd_lock, lock_flags);
4357 DPR_IOCTL(("dgap_tty_ioctl finish on port %d - cmd %s (%x), arg %lx\n",
4358 ch->ch_portnum, dgap_ioctl_name(cmd), cmd, arg));
4364 * FEP5 doesn't support turning off a break unconditionally.
4365 * The FEP5 device will stop sending a break automatically
4366 * after the specified time value that was sent when turning on
4369 DGAP_UNLOCK(ch->ch_lock, lock_flags2);
4370 DGAP_UNLOCK(bd->bd_lock, lock_flags);
4375 DGAP_UNLOCK(ch->ch_lock, lock_flags2);
4376 DGAP_UNLOCK(bd->bd_lock, lock_flags);
4378 rc = put_user(C_CLOCAL(tty) ? 1 : 0, (unsigned long __user *) arg);
4382 DGAP_UNLOCK(ch->ch_lock, lock_flags2);
4383 DGAP_UNLOCK(bd->bd_lock, lock_flags);
4385 rc = get_user(arg, (unsigned long __user *) arg);
4389 DGAP_LOCK(bd->bd_lock, lock_flags);
4390 DGAP_LOCK(ch->ch_lock, lock_flags2);
4391 tty->termios.c_cflag = ((tty->termios.c_cflag & ~CLOCAL) | (arg ? CLOCAL : 0));
4393 DGAP_UNLOCK(ch->ch_lock, lock_flags2);
4394 DGAP_UNLOCK(bd->bd_lock, lock_flags);
4399 DGAP_UNLOCK(ch->ch_lock, lock_flags2);
4400 DGAP_UNLOCK(bd->bd_lock, lock_flags);
4401 return(dgap_get_modem_info(ch, uarg));
4406 DGAP_UNLOCK(ch->ch_lock, lock_flags2);
4407 DGAP_UNLOCK(bd->bd_lock, lock_flags);
4408 return(dgap_set_modem_info(tty, cmd, uarg));
4411 * Here are any additional ioctl's that we want to implement
4416 * The linux tty driver doesn't have a flush
4417 * input routine for the driver, assuming all backed
4418 * up data is in the line disc. buffers. However,
4419 * we all know that's not the case. Here, we
4420 * act on the ioctl, but then lie and say we didn't
4421 * so the line discipline will process the flush
4424 rc = tty_check_change(tty);
4426 DGAP_UNLOCK(ch->ch_lock, lock_flags2);
4427 DGAP_UNLOCK(bd->bd_lock, lock_flags);
4431 if ((arg == TCIFLUSH) || (arg == TCIOFLUSH)) {
4432 if (!(un->un_type == DGAP_PRINT)) {
4433 head = readw(&(ch->ch_bs->rx_head));
4434 writew(head, &(ch->ch_bs->rx_tail));
4435 writeb(0, &(ch->ch_bs->orun));
4439 if ((arg == TCOFLUSH) || (arg == TCIOFLUSH)) {
4440 ch->ch_flags &= ~CH_STOP;
4441 head = readw(&(ch->ch_bs->tx_head));
4442 dgap_cmdw(ch, FLUSHTX, (u16) head, 0 );
4443 dgap_cmdw(ch, RESUMETX, 0, 0);
4444 if (ch->ch_tun.un_flags & (UN_LOW|UN_EMPTY)) {
4445 ch->ch_tun.un_flags &= ~(UN_LOW|UN_EMPTY);
4446 wake_up_interruptible(&ch->ch_tun.un_flags_wait);
4448 if (ch->ch_pun.un_flags & (UN_LOW|UN_EMPTY)) {
4449 ch->ch_pun.un_flags &= ~(UN_LOW|UN_EMPTY);
4450 wake_up_interruptible(&ch->ch_pun.un_flags_wait);
4452 if (waitqueue_active(&tty->write_wait))
4453 wake_up_interruptible(&tty->write_wait);
4455 /* Can't hold any locks when calling tty_wakeup! */
4456 DGAP_UNLOCK(ch->ch_lock, lock_flags2);
4457 DGAP_UNLOCK(bd->bd_lock, lock_flags);
4459 DGAP_LOCK(bd->bd_lock, lock_flags);
4460 DGAP_LOCK(ch->ch_lock, lock_flags2);
4463 /* pretend we didn't recognize this IOCTL */
4464 DGAP_UNLOCK(ch->ch_lock, lock_flags2);
4465 DGAP_UNLOCK(bd->bd_lock, lock_flags);
4467 DPR_IOCTL(("dgap_tty_ioctl (LINE:%d) finish on port %d - cmd %s (%x), arg %lx\n",
4468 __LINE__, ch->ch_portnum, dgap_ioctl_name(cmd), cmd, arg));
4470 return(-ENOIOCTLCMD);
4475 * The linux tty driver doesn't have a flush
4476 * input routine for the driver, assuming all backed
4477 * up data is in the line disc. buffers. However,
4478 * we all know that's not the case. Here, we
4479 * act on the ioctl, but then lie and say we didn't
4480 * so the line discipline will process the flush
4483 if (cmd == TCSETSF) {
4485 ch->ch_flags &= ~CH_STOP;
4486 head = readw(&(ch->ch_bs->rx_head));
4487 writew(head, &(ch->ch_bs->rx_tail));
4490 /* now wait for all the output to drain */
4491 DGAP_UNLOCK(ch->ch_lock, lock_flags2);
4492 DGAP_UNLOCK(bd->bd_lock, lock_flags);
4493 rc = dgap_wait_for_drain(tty);
4495 DPR_IOCTL(("dgap_tty_ioctl - bad return: %d ", rc));
4499 DPR_IOCTL(("dgap_tty_ioctl finish on port %d - cmd %s (%x), arg %lx\n",
4500 ch->ch_portnum, dgap_ioctl_name(cmd), cmd, arg));
4502 /* pretend we didn't recognize this */
4503 return(-ENOIOCTLCMD);
4507 DGAP_UNLOCK(ch->ch_lock, lock_flags2);
4508 DGAP_UNLOCK(bd->bd_lock, lock_flags);
4509 rc = dgap_wait_for_drain(tty);
4511 DPR_IOCTL(("dgap_tty_ioctl - bad return: %d ", rc));
4515 /* pretend we didn't recognize this */
4516 return(-ENOIOCTLCMD);
4520 * The Linux Line Discipline (LD) would do this for us if we
4521 * let it, but we have the special firmware options to do this
4522 * the "right way" regardless of hardware or software flow
4523 * control so we'll do it outselves instead of letting the LD
4526 rc = tty_check_change(tty);
4528 DGAP_UNLOCK(ch->ch_lock, lock_flags2);
4529 DGAP_UNLOCK(bd->bd_lock, lock_flags);
4533 DPR_IOCTL(("dgap_ioctl - in TCXONC - %d\n", cmd));
4537 DGAP_UNLOCK(ch->ch_lock, lock_flags2);
4538 DGAP_UNLOCK(bd->bd_lock, lock_flags);
4539 dgap_tty_start(tty);
4542 DGAP_UNLOCK(ch->ch_lock, lock_flags2);
4543 DGAP_UNLOCK(bd->bd_lock, lock_flags);
4547 DGAP_UNLOCK(ch->ch_lock, lock_flags2);
4548 DGAP_UNLOCK(bd->bd_lock, lock_flags);
4549 /* Make the ld do it */
4550 return(-ENOIOCTLCMD);
4552 DGAP_UNLOCK(ch->ch_lock, lock_flags2);
4553 DGAP_UNLOCK(bd->bd_lock, lock_flags);
4554 /* Make the ld do it */
4555 return(-ENOIOCTLCMD);
4557 DGAP_UNLOCK(ch->ch_lock, lock_flags2);
4558 DGAP_UNLOCK(bd->bd_lock, lock_flags);
4563 /* get information for ditty */
4564 DGAP_UNLOCK(ch->ch_lock, lock_flags2);
4565 DGAP_UNLOCK(bd->bd_lock, lock_flags);
4566 return(dgap_tty_digigeta(tty, uarg));
4571 /* set information for ditty */
4572 if (cmd == (DIGI_SETAW)) {
4574 DGAP_UNLOCK(ch->ch_lock, lock_flags2);
4575 DGAP_UNLOCK(bd->bd_lock, lock_flags);
4576 rc = dgap_wait_for_drain(tty);
4578 DPR_IOCTL(("dgap_tty_ioctl - bad return: %d ", rc));
4581 DGAP_LOCK(bd->bd_lock, lock_flags);
4582 DGAP_LOCK(ch->ch_lock, lock_flags2);
4585 tty_ldisc_flush(tty);
4590 DGAP_UNLOCK(ch->ch_lock, lock_flags2);
4591 DGAP_UNLOCK(bd->bd_lock, lock_flags);
4592 return(dgap_tty_digiseta(tty, uarg));
4595 DGAP_UNLOCK(ch->ch_lock, lock_flags2);
4596 DGAP_UNLOCK(bd->bd_lock, lock_flags);
4597 return(dgap_tty_digigetedelay(tty, uarg));
4600 DGAP_UNLOCK(ch->ch_lock, lock_flags2);
4601 DGAP_UNLOCK(bd->bd_lock, lock_flags);
4602 return(dgap_tty_digisetedelay(tty, uarg));
4604 case DIGI_GETCUSTOMBAUD:
4605 DGAP_UNLOCK(ch->ch_lock, lock_flags2);
4606 DGAP_UNLOCK(bd->bd_lock, lock_flags);
4607 return(dgap_tty_digigetcustombaud(tty, uarg));
4609 case DIGI_SETCUSTOMBAUD:
4610 DGAP_UNLOCK(ch->ch_lock, lock_flags2);
4611 DGAP_UNLOCK(bd->bd_lock, lock_flags);
4612 return(dgap_tty_digisetcustombaud(tty, uarg));
4614 case DIGI_RESET_PORT:
4615 dgap_firmware_reset_port(ch);
4617 DGAP_UNLOCK(ch->ch_lock, lock_flags2);
4618 DGAP_UNLOCK(bd->bd_lock, lock_flags);
4622 DGAP_UNLOCK(ch->ch_lock, lock_flags2);
4623 DGAP_UNLOCK(bd->bd_lock, lock_flags);
4625 DPR_IOCTL(("dgap_tty_ioctl - in default\n"));
4626 DPR_IOCTL(("dgap_tty_ioctl end - cmd %s (%x), arg %lx\n",
4627 dgap_ioctl_name(cmd), cmd, arg));
4629 return(-ENOIOCTLCMD);
4633 * Loads the dgap.conf config file from the user.
4635 void dgap_do_config_load(uchar __user *uaddr, int len)
4639 uchar __user *from_addr = uaddr;
4643 to_addr = dgap_config_buf = kzalloc(len + 1, GFP_ATOMIC);
4644 if (!dgap_config_buf) {
4645 DPR_INIT(("dgap_do_config_load - unable to allocate memory for file\n"));
4646 dgap_driver_state = DRIVER_NEED_CONFIG_LOAD;
4656 if (copy_from_user((char *) &buf, from_addr, n) == -1 )
4659 /* Copy data from buffer to kernel memory */
4660 memcpy(to_addr, buf, n);
4662 /* increment counts */
4669 dgap_config_buf[orig_len] = '\0';
4671 to_addr = dgap_config_buf;
4672 dgap_parsefile(&to_addr, TRUE);
4674 DPR_INIT(("dgap_config_load() finish\n"));
4680 int dgap_after_config_loaded(void)
4686 * Register our ttys, now that we have the config loaded.
4688 for (i = 0; i < dgap_NumBoards; ++i) {
4691 * Initialize KME waitqueues...
4693 init_waitqueue_head(&(dgap_Board[i]->kme_wait));
4696 * allocate flip buffer for board.
4698 dgap_Board[i]->flipbuf = kzalloc(MYFLIPLEN, GFP_ATOMIC);
4699 dgap_Board[i]->flipflagbuf = kzalloc(MYFLIPLEN, GFP_ATOMIC);
4707 /*=======================================================================
4709 * usertoboard - copy from user space to board space.
4711 *=======================================================================*/
4712 static int dgap_usertoboard(struct board_t *brd, char *to_addr, char __user *from_addr, int len)
4717 if (!brd || brd->magic != DGAP_BOARD_MAGIC)
4724 if (copy_from_user((char *) &buf, from_addr, n) == -1 ) {
4728 /* Copy data from buffer to card memory */
4729 memcpy_toio(to_addr, buf, n);
4731 /* increment counts */
4742 * Copies the BIOS code from the user to the board,
4743 * and starts the BIOS running.
4745 void dgap_do_bios_load(struct board_t *brd, uchar __user *ubios, int len)
4751 if (!brd || (brd->magic != DGAP_BOARD_MAGIC) || !brd->re_map_membase)
4754 DPR_INIT(("dgap_do_bios_load() start\n"));
4756 addr = brd->re_map_membase;
4761 for (i = 0; i < 16; i++)
4762 writeb(0, addr + POSTAREA + i);
4768 if (dgap_usertoboard(brd, addr + offset, ubios, len) == -1 ) {
4769 brd->state = BOARD_FAILED;
4770 brd->dpastatus = BD_NOFEP;
4774 writel(0x0bf00401, addr);
4775 writel(0, (addr + 4));
4777 /* Clear the reset, and change states. */
4778 writeb(FEPCLR, brd->re_map_port);
4779 brd->state = WAIT_BIOS_LOAD;
4784 * Checks to see if the BIOS completed running on the card.
4786 static void dgap_do_wait_for_bios(struct board_t *brd)
4791 if (!brd || (brd->magic != DGAP_BOARD_MAGIC) || !brd->re_map_membase)
4794 addr = brd->re_map_membase;
4795 word = readw(addr + POSTAREA);
4797 /* Check to see if BIOS thinks board is good. (GD). */
4798 if (word == *(u16 *) "GD") {
4799 DPR_INIT(("GOT GD in memory, moving states.\n"));
4800 brd->state = FINISHED_BIOS_LOAD;
4804 /* Give up on board after too long of time taken */
4805 if (brd->wait_for_bios++ > 5000) {
4806 u16 err1 = readw(addr + SEQUENCE);
4807 u16 err2 = readw(addr + ERROR);
4808 APR(("***WARNING*** %s failed diagnostics. Error #(%x,%x).\n",
4809 brd->name, err1, err2));
4810 brd->state = BOARD_FAILED;
4811 brd->dpastatus = BD_NOFEP;
4817 * Copies the FEP code from the user to the board,
4818 * and starts the FEP running.
4820 void dgap_do_fep_load(struct board_t *brd, uchar __user *ufep, int len)
4825 if (!brd || (brd->magic != DGAP_BOARD_MAGIC) || !brd->re_map_membase)
4828 addr = brd->re_map_membase;
4830 DPR_INIT(("dgap_do_fep_load() for board %s : start\n", brd->name));
4836 if (dgap_usertoboard(brd, addr + offset, ufep, len) == -1 ) {
4837 brd->state = BOARD_FAILED;
4838 brd->dpastatus = BD_NOFEP;
4843 * If board is a concentrator product, we need to give
4844 * it its config string describing how the concentrators look.
4846 if ((brd->type == PCX) || (brd->type == PEPC)) {
4848 uchar *config, *xconfig;
4851 xconfig = dgap_create_config_string(brd, string);
4853 /* Write string to board memory */
4854 config = addr + CONFIG;
4855 for (; i < CONFIGSIZE; i++, config++, xconfig++) {
4856 writeb(*xconfig, config);
4857 if ((*xconfig & 0xff) == 0xff)
4862 writel(0xbfc01004, (addr + 0xc34));
4863 writel(0x3, (addr + 0xc30));
4865 /* change states. */
4866 brd->state = WAIT_FEP_LOAD;
4868 DPR_INIT(("dgap_do_fep_load() for board %s : finish\n", brd->name));
4874 * Waits for the FEP to report thats its ready for us to use.
4876 static void dgap_do_wait_for_fep(struct board_t *brd)
4881 if (!brd || (brd->magic != DGAP_BOARD_MAGIC) || !brd->re_map_membase)
4884 addr = brd->re_map_membase;
4886 DPR_INIT(("dgap_do_wait_for_fep() for board %s : start. addr: %p\n", brd->name, addr));
4888 word = readw(addr + FEPSTAT);
4890 /* Check to see if FEP is up and running now. */
4891 if (word == *(u16 *) "OS") {
4892 DPR_INIT(("GOT OS in memory for board %s, moving states.\n", brd->name));
4893 brd->state = FINISHED_FEP_LOAD;
4896 * Check to see if the board can support FEP5+ commands.
4898 word = readw(addr + FEP5_PLUS);
4899 if (word == *(u16 *) "5A") {
4900 DPR_INIT(("GOT 5A in memory for board %s, board supports extended FEP5 commands.\n", brd->name));
4901 brd->bd_flags |= BD_FEP5PLUS;
4907 /* Give up on board after too long of time taken */
4908 if (brd->wait_for_fep++ > 5000) {
4909 u16 err1 = readw(addr + SEQUENCE);
4910 u16 err2 = readw(addr + ERROR);
4911 APR(("***WARNING*** FEPOS for %s not functioning. Error #(%x,%x).\n",
4912 brd->name, err1, err2));
4913 brd->state = BOARD_FAILED;
4914 brd->dpastatus = BD_NOFEP;
4917 DPR_INIT(("dgap_do_wait_for_fep() for board %s : finish\n", brd->name));
4922 * Physically forces the FEP5 card to reset itself.
4924 static void dgap_do_reset_board(struct board_t *brd)
4931 if (!brd || (brd->magic != DGAP_BOARD_MAGIC) || !brd->re_map_membase || !brd->re_map_port) {
4932 DPR_INIT(("dgap_do_reset_board() start. bad values. brd: %p mem: %p io: %p\n",
4933 brd, brd ? brd->re_map_membase : 0, brd ? brd->re_map_port : 0));
4937 DPR_INIT(("dgap_do_reset_board() start. io: %p\n", brd->re_map_port));
4939 /* FEPRST does not vary among supported boards */
4940 writeb(FEPRST, brd->re_map_port);
4942 for (i = 0; i <= 1000; i++) {
4943 check = readb(brd->re_map_port) & 0xe;
4944 if (check == FEPRST)
4950 APR(("*** WARNING *** Board not resetting... Failing board.\n"));
4951 brd->state = BOARD_FAILED;
4952 brd->dpastatus = BD_NOFEP;
4957 * Make sure there really is memory out there.
4959 writel(0xa55a3cc3, (brd->re_map_membase + LOWMEM));
4960 writel(0x5aa5c33c, (brd->re_map_membase + HIGHMEM));
4961 check1 = readl(brd->re_map_membase + LOWMEM);
4962 check2 = readl(brd->re_map_membase + HIGHMEM);
4964 if ((check1 != 0xa55a3cc3) || (check2 != 0x5aa5c33c)) {
4965 APR(("*** Warning *** No memory at %p for board.\n", brd->re_map_membase));
4966 brd->state = BOARD_FAILED;
4967 brd->dpastatus = BD_NOFEP;
4971 if (brd->state != BOARD_FAILED)
4972 brd->state = FINISHED_RESET;
4975 DPR_INIT(("dgap_do_reset_board() finish\n"));
4980 * Sends a concentrator image into the FEP5 board.
4982 void dgap_do_conc_load(struct board_t *brd, uchar *uaddr, int len)
4986 struct downld_t *to_dp;
4988 if (!brd || (brd->magic != DGAP_BOARD_MAGIC) || !brd->re_map_membase)
4991 vaddr = brd->re_map_membase;
4993 offset = readw((u16 *) (vaddr + DOWNREQ));
4994 to_dp = (struct downld_t *) (vaddr + (int) offset);
4997 * The image was already read into kernel space,
4998 * we do NOT need a user space read here
5000 memcpy_toio((char *) to_dp, uaddr, sizeof(struct downld_t));
5002 /* Tell card we have data for it */
5003 writew(0, vaddr + (DOWNREQ));
5005 brd->conc_dl_status = NO_PENDING_CONCENTRATOR_REQUESTS;
5009 #define EXPANSION_ROM_SIZE (64 * 1024)
5010 #define FEP5_ROM_MAGIC (0xFEFFFFFF)
5012 static void dgap_get_vpd(struct board_t *brd)
5024 * Poke the magic number at the PCI Rom Address location.
5025 * If VPD is supported, the value read from that address
5028 magic = FEP5_ROM_MAGIC;
5029 pci_write_config_dword(brd->pdev, PCI_ROM_ADDRESS, magic);
5030 pci_read_config_dword(brd->pdev, PCI_ROM_ADDRESS, &magic);
5032 /* VPD not supported, bail */
5037 * To get to the OTPROM memory, we have to send the boards base
5038 * address or'ed with 1 into the PCI Rom Address location.
5040 magic = brd->membase | 0x01;
5041 pci_write_config_dword(brd->pdev, PCI_ROM_ADDRESS, magic);
5042 pci_read_config_dword(brd->pdev, PCI_ROM_ADDRESS, &magic);
5044 byte1 = readb(brd->re_map_membase);
5045 byte2 = readb(brd->re_map_membase + 1);
5048 * If the board correctly swapped to the OTPROM memory,
5049 * the first 2 bytes (header) should be 0x55, 0xAA
5051 if (byte1 == 0x55 && byte2 == 0xAA) {
5056 * We have to run through all the OTPROM memory looking
5057 * for the VPD offset.
5059 while (base_offset <= EXPANSION_ROM_SIZE) {
5062 * Lots of magic numbers here.
5064 * The VPD offset is located inside the ROM Data Structure.
5065 * We also have to remember the length of each
5066 * ROM Data Structure, so we can "hop" to the next
5067 * entry if the VPD isn't in the current
5068 * ROM Data Structure.
5070 rom_offset = readw(brd->re_map_membase + base_offset + 0x18);
5071 image_length = readw(brd->re_map_membase + rom_offset + 0x10) * 512;
5072 vpd_offset = readw(brd->re_map_membase + rom_offset + 0x08);
5074 /* Found the VPD entry */
5078 /* We didn't find a VPD entry, go to next ROM entry. */
5079 base_offset += image_length;
5081 byte1 = readb(brd->re_map_membase + base_offset);
5082 byte2 = readb(brd->re_map_membase + base_offset + 1);
5085 * If the new ROM offset doesn't have 0x55, 0xAA
5086 * as its header, we have run out of ROM.
5088 if (byte1 != 0x55 || byte2 != 0xAA)
5093 * If we have a VPD offset, then mark the board
5094 * as having a valid VPD, and copy VPDSIZE (512) bytes of
5095 * that VPD to the buffer we have in our board structure.
5098 brd->bd_flags |= BD_HAS_VPD;
5099 for (i = 0; i < VPDSIZE; i++)
5100 brd->vpd[i] = readb(brd->re_map_membase + vpd_offset + i);
5105 * We MUST poke the magic number at the PCI Rom Address location again.
5106 * This makes the card report the regular board memory back to us,
5107 * rather than the OTPROM memory.
5109 magic = FEP5_ROM_MAGIC;
5110 pci_write_config_dword(brd->pdev, PCI_ROM_ADDRESS, magic);
5115 * Our board poller function.
5117 void dgap_poll_tasklet(unsigned long data)
5119 struct board_t *bd = (struct board_t *) data;
5127 if (!bd || (bd->magic != DGAP_BOARD_MAGIC)) {
5128 APR(("dgap_poll_tasklet() - NULL or bad bd.\n"));
5132 if (bd->inhibit_poller)
5135 DGAP_LOCK(bd->bd_lock, lock_flags);
5137 vaddr = bd->re_map_membase;
5140 * If board is ready, parse deeper to see if there is anything to do.
5142 if (bd->state == BOARD_READY) {
5144 struct ev_t *eaddr = NULL;
5146 if (!bd->re_map_membase) {
5147 DGAP_UNLOCK(bd->bd_lock, lock_flags);
5150 if (!bd->re_map_port) {
5151 DGAP_UNLOCK(bd->bd_lock, lock_flags);
5160 * If this is a CX or EPCX, we need to see if the firmware
5161 * is requesting a concentrator image from us.
5163 if ((bd->type == PCX) || (bd->type == PEPC)) {
5164 chk_addr = (u16 *) (vaddr + DOWNREQ);
5165 check = readw(chk_addr);
5166 /* Nonzero if FEP is requesting concentrator image. */
5168 if (bd->conc_dl_status == NO_PENDING_CONCENTRATOR_REQUESTS)
5169 bd->conc_dl_status = NEED_CONCENTRATOR;
5171 * Signal downloader, its got some work to do.
5173 DGAP_LOCK(dgap_dl_lock, lock_flags2);
5174 if (dgap_dl_action != 1) {
5176 wake_up_interruptible(&dgap_dl_wait);
5178 DGAP_UNLOCK(dgap_dl_lock, lock_flags2);
5183 eaddr = (struct ev_t *) (vaddr + EVBUF);
5185 /* Get our head and tail */
5186 head = readw(&(eaddr->ev_head));
5187 tail = readw(&(eaddr->ev_tail));
5190 * If there is an event pending. Go service it.
5193 DGAP_UNLOCK(bd->bd_lock, lock_flags);
5195 DGAP_LOCK(bd->bd_lock, lock_flags);
5200 * If board is doing interrupts, ACK the interrupt.
5202 if (bd && bd->intr_running) {
5203 readb(bd->re_map_port + 2);
5206 DGAP_UNLOCK(bd->bd_lock, lock_flags);
5210 /* Our state machine to get the board up and running */
5213 if (bd->state == NEED_RESET) {
5218 dgap_do_reset_board(bd);
5221 /* Move to next state */
5222 if (bd->state == FINISHED_RESET) {
5223 bd->state = NEED_CONFIG;
5226 if (bd->state == NEED_CONFIG) {
5228 * Match this board to a config the user created for us.
5230 bd->bd_config = dgap_find_config(bd->type, bd->pci_bus, bd->pci_slot);
5233 * Because the 4 port Xr products share the same PCI ID
5234 * as the 8 port Xr products, if we receive a NULL config
5235 * back, and this is a PAPORT8 board, retry with a
5236 * PAPORT4 attempt as well.
5238 if (bd->type == PAPORT8 && !bd->bd_config) {
5239 bd->bd_config = dgap_find_config(PAPORT4, bd->pci_bus, bd->pci_slot);
5243 * Register the ttys (if any) into the kernel.
5245 if (bd->bd_config) {
5246 bd->state = FINISHED_CONFIG;
5249 bd->state = CONFIG_NOT_FOUND;
5253 /* Move to next state */
5254 if (bd->state == FINISHED_CONFIG) {
5255 bd->state = NEED_DEVICE_CREATION;
5258 /* Move to next state */
5259 if (bd->state == NEED_DEVICE_CREATION) {
5261 * Signal downloader, its got some work to do.
5263 DGAP_LOCK(dgap_dl_lock, lock_flags2);
5264 if (dgap_dl_action != 1) {
5266 wake_up_interruptible(&dgap_dl_wait);
5268 DGAP_UNLOCK(dgap_dl_lock, lock_flags2);
5271 /* Move to next state */
5272 if (bd->state == FINISHED_DEVICE_CREATION) {
5273 bd->state = NEED_BIOS_LOAD;
5276 /* Move to next state */
5277 if (bd->state == NEED_BIOS_LOAD) {
5279 * Signal downloader, its got some work to do.
5281 DGAP_LOCK(dgap_dl_lock, lock_flags2);
5282 if (dgap_dl_action != 1) {
5284 wake_up_interruptible(&dgap_dl_wait);
5286 DGAP_UNLOCK(dgap_dl_lock, lock_flags2);
5289 /* Wait for BIOS to test board... */
5290 if (bd->state == WAIT_BIOS_LOAD) {
5291 dgap_do_wait_for_bios(bd);
5294 /* Move to next state */
5295 if (bd->state == FINISHED_BIOS_LOAD) {
5296 bd->state = NEED_FEP_LOAD;
5299 * Signal downloader, its got some work to do.
5301 DGAP_LOCK(dgap_dl_lock, lock_flags2);
5302 if (dgap_dl_action != 1) {
5304 wake_up_interruptible(&dgap_dl_wait);
5306 DGAP_UNLOCK(dgap_dl_lock, lock_flags2);
5309 /* Wait for FEP to load on board... */
5310 if (bd->state == WAIT_FEP_LOAD) {
5311 dgap_do_wait_for_fep(bd);
5315 /* Move to next state */
5316 if (bd->state == FINISHED_FEP_LOAD) {
5319 * Do tty device initialization.
5321 int rc = dgap_tty_init(bd);
5324 dgap_tty_uninit(bd);
5325 APR(("Can't init tty devices (%d)\n", rc));
5326 bd->state = BOARD_FAILED;
5327 bd->dpastatus = BD_NOFEP;
5330 bd->state = NEED_PROC_CREATION;
5333 * Signal downloader, its got some work to do.
5335 DGAP_LOCK(dgap_dl_lock, lock_flags2);
5336 if (dgap_dl_action != 1) {
5338 wake_up_interruptible(&dgap_dl_wait);
5340 DGAP_UNLOCK(dgap_dl_lock, lock_flags2);
5344 /* Move to next state */
5345 if (bd->state == FINISHED_PROC_CREATION) {
5347 bd->state = BOARD_READY;
5348 bd->dpastatus = BD_RUNNING;
5351 * If user requested the board to run in interrupt mode,
5352 * go and set it up on the board.
5354 if (bd->intr_used) {
5355 writew(1, (bd->re_map_membase + ENABLE_INTR));
5357 * Tell the board to poll the UARTS as fast as possible.
5359 writew(FEPPOLL_MIN, (bd->re_map_membase + FEPPOLL));
5360 bd->intr_running = 1;
5363 /* Wake up anyone waiting for board state to change to ready */
5364 wake_up_interruptible(&bd->state_wait);
5367 DGAP_UNLOCK(bd->bd_lock, lock_flags);
5371 /*=======================================================================
5373 * dgap_cmdb - Sends a 2 byte command to the FEP.
5375 * ch - Pointer to channel structure.
5376 * cmd - Command to be sent.
5377 * byte1 - Integer containing first byte to be sent.
5378 * byte2 - Integer containing second byte to be sent.
5379 * ncmds - Wait until ncmds or fewer cmds are left
5380 * in the cmd buffer before returning.
5382 *=======================================================================*/
5383 void dgap_cmdb(struct channel_t *ch, uchar cmd, uchar byte1, uchar byte2, uint ncmds)
5386 struct cm_t *cm_addr = NULL;
5392 if (!ch || ch->magic != DGAP_CHANNEL_MAGIC)
5396 * Check if board is still alive.
5398 if (ch->ch_bd->state == BOARD_FAILED) {
5399 DPR_CORE(("%s:%d board is in failed state.\n", __FILE__, __LINE__));
5404 * Make sure the pointers are in range before
5405 * writing to the FEP memory.
5407 vaddr = ch->ch_bd->re_map_membase;
5412 cm_addr = (struct cm_t *) (vaddr + CMDBUF);
5413 head = readw(&(cm_addr->cm_head));
5416 * Forget it if pointers out of range.
5418 if (head >= (CMDMAX - CMDSTART) || (head & 03)) {
5419 DPR_CORE(("%s:%d pointers out of range, failing board!\n", __FILE__, __LINE__));
5420 ch->ch_bd->state = BOARD_FAILED;
5425 * Put the data in the circular command buffer.
5427 writeb(cmd, (char *) (vaddr + head + CMDSTART + 0));
5428 writeb((uchar) ch->ch_portnum, (char *) (vaddr + head + CMDSTART + 1));
5429 writeb(byte1, (char *) (vaddr + head + CMDSTART + 2));
5430 writeb(byte2, (char *) (vaddr + head + CMDSTART + 3));
5432 head = (head + 4) & (CMDMAX - CMDSTART - 4);
5434 writew(head, &(cm_addr->cm_head));
5437 * Wait if necessary before updating the head
5438 * pointer to limit the number of outstanding
5439 * commands to the FEP. If the time spent waiting
5440 * is outlandish, declare the FEP dead.
5442 for (count = dgap_count ;;) {
5444 head = readw(&(cm_addr->cm_head));
5445 tail = readw(&(cm_addr->cm_tail));
5447 n = (head - tail) & (CMDMAX - CMDSTART - 4);
5449 if (n <= ncmds * sizeof(struct cm_t))
5453 DPR_CORE(("%s:%d failing board.\n",__FILE__, __LINE__));
5454 ch->ch_bd->state = BOARD_FAILED;
5462 /*=======================================================================
5464 * dgap_cmdw - Sends a 1 word command to the FEP.
5466 * ch - Pointer to channel structure.
5467 * cmd - Command to be sent.
5468 * word - Integer containing word to be sent.
5469 * ncmds - Wait until ncmds or fewer cmds are left
5470 * in the cmd buffer before returning.
5472 *=======================================================================*/
5473 void dgap_cmdw(struct channel_t *ch, uchar cmd, u16 word, uint ncmds)
5476 struct cm_t *cm_addr = NULL;
5482 if (!ch || ch->magic != DGAP_CHANNEL_MAGIC)
5486 * Check if board is still alive.
5488 if (ch->ch_bd->state == BOARD_FAILED) {
5489 DPR_CORE(("%s:%d board is failed!\n", __FILE__, __LINE__));
5494 * Make sure the pointers are in range before
5495 * writing to the FEP memory.
5497 vaddr = ch->ch_bd->re_map_membase;
5501 cm_addr = (struct cm_t *) (vaddr + CMDBUF);
5502 head = readw(&(cm_addr->cm_head));
5505 * Forget it if pointers out of range.
5507 if (head >= (CMDMAX - CMDSTART) || (head & 03)) {
5508 DPR_CORE(("%s:%d Pointers out of range. Failing board.\n",__FILE__, __LINE__));
5509 ch->ch_bd->state = BOARD_FAILED;
5514 * Put the data in the circular command buffer.
5516 writeb(cmd, (char *) (vaddr + head + CMDSTART + 0));
5517 writeb((uchar) ch->ch_portnum, (char *) (vaddr + head + CMDSTART + 1));
5518 writew((u16) word, (char *) (vaddr + head + CMDSTART + 2));
5520 head = (head + 4) & (CMDMAX - CMDSTART - 4);
5522 writew(head, &(cm_addr->cm_head));
5525 * Wait if necessary before updating the head
5526 * pointer to limit the number of outstanding
5527 * commands to the FEP. If the time spent waiting
5528 * is outlandish, declare the FEP dead.
5530 for (count = dgap_count ;;) {
5532 head = readw(&(cm_addr->cm_head));
5533 tail = readw(&(cm_addr->cm_tail));
5535 n = (head - tail) & (CMDMAX - CMDSTART - 4);
5537 if (n <= ncmds * sizeof(struct cm_t))
5541 DPR_CORE(("%s:%d Failing board.\n",__FILE__, __LINE__));
5542 ch->ch_bd->state = BOARD_FAILED;
5551 /*=======================================================================
5553 * dgap_cmdw_ext - Sends a extended word command to the FEP.
5555 * ch - Pointer to channel structure.
5556 * cmd - Command to be sent.
5557 * word - Integer containing word to be sent.
5558 * ncmds - Wait until ncmds or fewer cmds are left
5559 * in the cmd buffer before returning.
5561 *=======================================================================*/
5562 static void dgap_cmdw_ext(struct channel_t *ch, u16 cmd, u16 word, uint ncmds)
5565 struct cm_t *cm_addr = NULL;
5571 if (!ch || ch->magic != DGAP_CHANNEL_MAGIC)
5575 * Check if board is still alive.
5577 if (ch->ch_bd->state == BOARD_FAILED) {
5578 DPR_CORE(("%s:%d board is failed!\n", __FILE__, __LINE__));
5583 * Make sure the pointers are in range before
5584 * writing to the FEP memory.
5586 vaddr = ch->ch_bd->re_map_membase;
5590 cm_addr = (struct cm_t *) (vaddr + CMDBUF);
5591 head = readw(&(cm_addr->cm_head));
5594 * Forget it if pointers out of range.
5596 if (head >= (CMDMAX - CMDSTART) || (head & 03)) {
5597 DPR_CORE(("%s:%d Pointers out of range. Failing board.\n",__FILE__, __LINE__));
5598 ch->ch_bd->state = BOARD_FAILED;
5603 * Put the data in the circular command buffer.
5606 /* Write an FF to tell the FEP that we want an extended command */
5607 writeb((uchar) 0xff, (char *) (vaddr + head + CMDSTART + 0));
5609 writeb((uchar) ch->ch_portnum, (uchar *) (vaddr + head + CMDSTART + 1));
5610 writew((u16) cmd, (char *) (vaddr + head + CMDSTART + 2));
5613 * If the second part of the command won't fit,
5614 * put it at the beginning of the circular buffer.
5616 if (((head + 4) >= ((CMDMAX - CMDSTART)) || (head & 03))) {
5617 writew((u16) word, (char *) (vaddr + CMDSTART));
5619 writew((u16) word, (char *) (vaddr + head + CMDSTART + 4));
5622 head = (head + 8) & (CMDMAX - CMDSTART - 4);
5624 writew(head, &(cm_addr->cm_head));
5627 * Wait if necessary before updating the head
5628 * pointer to limit the number of outstanding
5629 * commands to the FEP. If the time spent waiting
5630 * is outlandish, declare the FEP dead.
5632 for (count = dgap_count ;;) {
5634 head = readw(&(cm_addr->cm_head));
5635 tail = readw(&(cm_addr->cm_tail));
5637 n = (head - tail) & (CMDMAX - CMDSTART - 4);
5639 if (n <= ncmds * sizeof(struct cm_t))
5643 DPR_CORE(("%s:%d Failing board.\n",__FILE__, __LINE__));
5644 ch->ch_bd->state = BOARD_FAILED;
5652 /*=======================================================================
5654 * dgap_wmove - Write data to FEP buffer.
5656 * ch - Pointer to channel structure.
5657 * buf - Poiter to characters to be moved.
5658 * cnt - Number of characters to move.
5660 *=======================================================================*/
5661 void dgap_wmove(struct channel_t *ch, char *buf, uint cnt)
5668 if (!ch || ch->magic != DGAP_CHANNEL_MAGIC)
5675 head = readw(&(bs->tx_head));
5678 * If pointers are out of range, just return.
5680 if ((cnt > ch->ch_tsize) || (unsigned)(head - ch->ch_tstart) >= ch->ch_tsize) {
5681 DPR_CORE(("%s:%d pointer out of range", __FILE__, __LINE__));
5686 * If the write wraps over the top of the circular buffer,
5687 * move the portion up to the wrap point, and reset the
5688 * pointers to the bottom.
5690 n = ch->ch_tstart + ch->ch_tsize - head;
5694 taddr = ch->ch_taddr + head;
5695 memcpy_toio(taddr, buf, n);
5696 head = ch->ch_tstart;
5701 * Move rest of data.
5703 taddr = ch->ch_taddr + head;
5705 memcpy_toio(taddr, buf, n);
5708 writew(head, &(bs->tx_head));
5712 * Retrives the current custom baud rate from FEP memory,
5713 * and returns it back to the user.
5714 * Returns 0 on error.
5716 uint dgap_get_custom_baud(struct channel_t *ch)
5722 if (!ch || ch->magic != DGAP_CHANNEL_MAGIC) {
5726 if (!ch->ch_bd || ch->ch_bd->magic != DGAP_BOARD_MAGIC) {
5730 if (!(ch->ch_bd->bd_flags & BD_FEP5PLUS))
5733 vaddr = ch->ch_bd->re_map_membase;
5739 * Go get from fep mem, what the fep
5740 * believes the custom baud rate is.
5742 offset = ((((*(unsigned short *)(vaddr + ECS_SEG)) << 4) +
5743 (ch->ch_portnum * 0x28) + LINE_SPEED));
5745 value = readw(vaddr + offset);
5751 * Calls the firmware to reset this channel.
5753 void dgap_firmware_reset_port(struct channel_t *ch)
5755 dgap_cmdb(ch, CHRESET, 0, 0, 0);
5758 * Now that the channel is reset, we need to make sure
5759 * all the current settings get reapplied to the port
5762 * So we will set the driver's cache of firmware
5763 * settings all to 0, and then call param.
5765 ch->ch_fepiflag = 0;
5766 ch->ch_fepcflag = 0;
5767 ch->ch_fepoflag = 0;
5768 ch->ch_fepstartc = 0;
5769 ch->ch_fepstopc = 0;
5770 ch->ch_fepastartc = 0;
5771 ch->ch_fepastopc = 0;
5777 /*=======================================================================
5779 * dgap_param - Set Digi parameters.
5781 * struct tty_struct * - TTY for port.
5783 *=======================================================================*/
5784 int dgap_param(struct tty_struct *tty)
5786 struct ktermios *ts;
5788 struct channel_t *ch;
5797 if (!tty || tty->magic != TTY_MAGIC)
5800 un = (struct un_t *) tty->driver_data;
5801 if (!un || un->magic != DGAP_UNIT_MAGIC)
5805 if (!ch || ch->magic != DGAP_CHANNEL_MAGIC)
5809 if (!bd || bd->magic != DGAP_BOARD_MAGIC)
5816 DPR_PARAM(("param start: tdev: %x cflags: %x oflags: %x iflags: %x\n",
5817 ch->ch_tun.un_dev, ch->ch_c_cflag, ch->ch_c_oflag, ch->ch_c_iflag));
5822 * If baud rate is zero, flush queues, and set mval to drop DTR.
5824 if ((ch->ch_c_cflag & (CBAUD)) == 0) {
5827 head = readw(&(ch->ch_bs->rx_head));
5828 writew(head, &(ch->ch_bs->rx_tail));
5831 head = readw(&(ch->ch_bs->tx_head));
5832 writew(head, &(ch->ch_bs->tx_tail));
5834 ch->ch_flags |= (CH_BAUD0);
5836 /* Drop RTS and DTR */
5837 ch->ch_mval &= ~(D_RTS(ch)|D_DTR(ch));
5838 mval = D_DTR(ch) | D_RTS(ch);
5839 ch->ch_baud_info = 0;
5841 } else if (ch->ch_custom_speed && (bd->bd_flags & BD_FEP5PLUS)) {
5843 * Tell the fep to do the command
5846 DPR_PARAM(("param: Want %d speed\n", ch->ch_custom_speed));
5848 dgap_cmdw_ext(ch, 0xff01, ch->ch_custom_speed, 0);
5851 * Now go get from fep mem, what the fep
5852 * believes the custom baud rate is.
5854 ch->ch_baud_info = ch->ch_custom_speed = dgap_get_custom_baud(ch);
5856 DPR_PARAM(("param: Got %d speed\n", ch->ch_custom_speed));
5858 /* Handle transition from B0 */
5859 if (ch->ch_flags & CH_BAUD0) {
5860 ch->ch_flags &= ~(CH_BAUD0);
5861 ch->ch_mval |= (D_RTS(ch)|D_DTR(ch));
5863 mval = D_DTR(ch) | D_RTS(ch);
5867 * Set baud rate, character size, and parity.
5875 ulong bauds[4][16] = {
5879 600, 1200, 1800, 2400,
5880 4800, 9600, 19200, 38400 },
5881 { /* slowbaud & CBAUDEX */
5882 0, 57600, 115200, 230400,
5883 460800, 150, 200, 921600,
5884 600, 1200, 1800, 2400,
5885 4800, 9600, 19200, 38400 },
5887 0, 57600, 76800, 115200,
5888 14400, 57600, 230400, 76800,
5889 115200, 230400, 28800, 460800,
5890 921600, 9600, 19200, 38400 },
5891 { /* fastbaud & CBAUDEX */
5892 0, 57600, 115200, 230400,
5893 460800, 150, 200, 921600,
5894 600, 1200, 1800, 2400,
5895 4800, 9600, 19200, 38400 }
5898 /* Only use the TXPrint baud rate if the terminal unit is NOT open */
5899 if (!(ch->ch_tun.un_flags & UN_ISOPEN) && (un->un_type == DGAP_PRINT))
5900 baud = C_BAUD(ch->ch_pun.un_tty) & 0xff;
5902 baud = C_BAUD(ch->ch_tun.un_tty) & 0xff;
5904 if (ch->ch_c_cflag & CBAUDEX)
5907 if (ch->ch_digi.digi_flags & DIGI_FAST)
5912 if ((iindex >= 0) && (iindex < 4) && (jindex >= 0) && (jindex < 16)) {
5913 baud = bauds[iindex][jindex];
5915 DPR_IOCTL(("baud indices were out of range (%d)(%d)",
5923 ch->ch_baud_info = baud;
5927 * CBAUD has bit position 0x1000 set these days to indicate Linux
5929 * We use a different bit assignment for high speed. Clear this
5930 * bit out while grabbing the parts of "cflag" we want.
5932 cflag = ch->ch_c_cflag & ((CBAUD ^ CBAUDEX) | PARODD | PARENB | CSTOPB | CSIZE);
5935 * HUPCL bit is used by FEP to indicate fast baud
5936 * table is to be used.
5938 if ((ch->ch_digi.digi_flags & DIGI_FAST) || (ch->ch_c_cflag & CBAUDEX))
5942 if ((ch->ch_c_cflag & CBAUDEX) && !(ch->ch_digi.digi_flags & DIGI_FAST)) {
5944 * The below code is trying to guarantee that only baud rates
5945 * 115200, 230400, 460800, 921600 are remapped. We use exclusive or
5946 * because the various baud rates share common bit positions
5947 * and therefore can't be tested for easily.
5949 tcflag_t tcflag = (ch->ch_c_cflag & CBAUD) | CBAUDEX;
5952 /* Map high speed requests to index into FEP's baud table */
5981 cflag = (cflag & ~(CBAUD | CBAUDEX)) | baudpart;
5986 if (cflag != ch->ch_fepcflag) {
5987 ch->ch_fepcflag = (u16) (cflag & 0xffff);
5989 /* Okay to have channel and board locks held calling this */
5990 dgap_cmdw(ch, SCFLAG, (u16) cflag, 0);
5993 /* Handle transition from B0 */
5994 if (ch->ch_flags & CH_BAUD0) {
5995 ch->ch_flags &= ~(CH_BAUD0);
5996 ch->ch_mval |= (D_RTS(ch)|D_DTR(ch));
5998 mval = D_DTR(ch) | D_RTS(ch);
6004 iflag = ch->ch_c_iflag & (IGNBRK | BRKINT | IGNPAR | PARMRK | INPCK | ISTRIP | IXON | IXANY | IXOFF);
6006 if ((ch->ch_startc == _POSIX_VDISABLE) || (ch->ch_stopc == _POSIX_VDISABLE)) {
6007 iflag &= ~(IXON | IXOFF);
6008 ch->ch_c_iflag &= ~(IXON | IXOFF);
6012 * Only the IBM Xr card can switch between
6013 * 232 and 422 modes on the fly
6015 if (bd->device == PCI_DEVICE_XR_IBM_DID) {
6016 if (ch->ch_digi.digi_flags & DIGI_422)
6017 dgap_cmdb(ch, SCOMMODE, MODE_422, 0, 0);
6019 dgap_cmdb(ch, SCOMMODE, MODE_232, 0, 0);
6022 if (ch->ch_digi.digi_flags & DIGI_ALTPIN)
6025 if (iflag != ch->ch_fepiflag) {
6026 ch->ch_fepiflag = iflag;
6028 /* Okay to have channel and board locks held calling this */
6029 dgap_cmdw(ch, SIFLAG, (u16) ch->ch_fepiflag, 0);
6033 * Select hardware handshaking.
6037 if (ch->ch_c_cflag & CRTSCTS) {
6038 hflow |= (D_RTS(ch) | D_CTS(ch));
6040 if (ch->ch_digi.digi_flags & RTSPACE)
6042 if (ch->ch_digi.digi_flags & DTRPACE)
6044 if (ch->ch_digi.digi_flags & CTSPACE)
6046 if (ch->ch_digi.digi_flags & DSRPACE)
6048 if (ch->ch_digi.digi_flags & DCDPACE)
6051 if (hflow != ch->ch_hflow) {
6052 ch->ch_hflow = hflow;
6054 /* Okay to have channel and board locks held calling this */
6055 dgap_cmdb(ch, SHFLOW, (uchar) hflow, 0xff, 0);
6060 * Set RTS and/or DTR Toggle if needed, but only if product is FEP5+ based.
6062 if (bd->bd_flags & BD_FEP5PLUS) {
6064 if (ch->ch_digi.digi_flags & DIGI_RTS_TOGGLE) {
6065 hflow2 |= (D_RTS(ch));
6067 if (ch->ch_digi.digi_flags & DIGI_DTR_TOGGLE) {
6068 hflow2 |= (D_DTR(ch));
6071 dgap_cmdw_ext(ch, 0xff03, hflow2, 0);
6075 * Set modem control lines.
6078 mval ^= ch->ch_mforce & (mval ^ ch->ch_mval);
6080 DPR_PARAM(("dgap_param: mval: %x ch_mforce: %x ch_mval: %x ch_mostat: %x\n",
6081 mval, ch->ch_mforce, ch->ch_mval, ch->ch_mostat));
6083 if (ch->ch_mostat ^ mval) {
6084 ch->ch_mostat = mval;
6086 /* Okay to have channel and board locks held calling this */
6087 DPR_PARAM(("dgap_param: Sending SMODEM mval: %x\n", mval));
6088 dgap_cmdb(ch, SMODEM, (uchar) mval, D_RTS(ch)|D_DTR(ch), 0);
6092 * Read modem signals, and then call carrier function.
6094 ch->ch_mistat = readb(&(bs->m_stat));
6098 * Set the start and stop characters.
6100 if (ch->ch_startc != ch->ch_fepstartc || ch->ch_stopc != ch->ch_fepstopc) {
6101 ch->ch_fepstartc = ch->ch_startc;
6102 ch->ch_fepstopc = ch->ch_stopc;
6104 /* Okay to have channel and board locks held calling this */
6105 dgap_cmdb(ch, SFLOWC, ch->ch_fepstartc, ch->ch_fepstopc, 0);
6109 * Set the Auxiliary start and stop characters.
6111 if (ch->ch_astartc != ch->ch_fepastartc || ch->ch_astopc != ch->ch_fepastopc) {
6112 ch->ch_fepastartc = ch->ch_astartc;
6113 ch->ch_fepastopc = ch->ch_astopc;
6115 /* Okay to have channel and board locks held calling this */
6116 dgap_cmdb(ch, SAFLOWC, ch->ch_fepastartc, ch->ch_fepastopc, 0);
6119 DPR_PARAM(("param finish\n"));
6126 * dgap_parity_scan()
6128 * Convert the FEP5 way of reporting parity errors and breaks into
6129 * the Linux line discipline way.
6131 void dgap_parity_scan(struct channel_t *ch, unsigned char *cbuf, unsigned char *fbuf, int *len)
6135 unsigned char *in, *cout, *fout;
6142 DPR_PSCAN(("dgap_parity_scan start\n"));
6144 if (!ch || ch->magic != DGAP_CHANNEL_MAGIC)
6149 switch (ch->pscan_state) {
6151 /* reset to sanity and fall through */
6152 ch->pscan_state = 0;
6155 /* No FF seen yet */
6156 if (c == (unsigned char) '\377') {
6157 /* delete this character from stream */
6158 ch->pscan_state = 1;
6161 *fout++ = TTY_NORMAL;
6168 if (c == (unsigned char) '\377') {
6169 /* doubled ff, transform to single ff */
6171 *fout++ = TTY_NORMAL;
6173 ch->pscan_state = 0;
6175 /* save value examination in next state */
6176 ch->pscan_savechar = c;
6177 ch->pscan_state = 2;
6182 /* third character of ff sequence */
6186 if (ch->pscan_savechar == 0x0) {
6189 DPR_PSCAN(("dgap_parity_scan in 3rd char of ff seq. c: %x setting break.\n", c));
6191 *fout++ = TTY_BREAK;
6194 DPR_PSCAN(("dgap_parity_scan in 3rd char of ff seq. c: %x setting parity.\n", c));
6195 ch->ch_err_parity++;
6196 *fout++ = TTY_PARITY;
6200 DPR_PSCAN(("%s:%d Logic Error.\n", __FILE__, __LINE__));
6204 ch->pscan_state = 0;
6208 DPR_PSCAN(("dgap_parity_scan finish\n"));
6214 /*=======================================================================
6216 * dgap_event - FEP to host event processing routine.
6218 * bd - Board of current event.
6220 *=======================================================================*/
6221 static int dgap_event(struct board_t *bd)
6223 struct channel_t *ch;
6228 uchar *vaddr = NULL;
6229 struct ev_t *eaddr = NULL;
6237 if (!bd || bd->magic != DGAP_BOARD_MAGIC)
6240 DGAP_LOCK(bd->bd_lock, lock_flags);
6242 vaddr = bd->re_map_membase;
6245 DGAP_UNLOCK(bd->bd_lock, lock_flags);
6249 eaddr = (struct ev_t *) (vaddr + EVBUF);
6251 /* Get our head and tail */
6252 head = readw(&(eaddr->ev_head));
6253 tail = readw(&(eaddr->ev_tail));
6256 * Forget it if pointers out of range.
6259 if (head >= EVMAX - EVSTART || tail >= EVMAX - EVSTART ||
6260 (head | tail) & 03) {
6261 DPR_EVENT(("should be calling xxfail %d\n", __LINE__));
6262 /* Let go of board lock */
6263 DGAP_UNLOCK(bd->bd_lock, lock_flags);
6268 * Loop to process all the events in the buffer.
6270 while (tail != head) {
6273 * Get interrupt information.
6276 event = bd->re_map_membase + tail + EVSTART;
6283 DPR_EVENT(("event: jiffies: %ld port: %d reason: %x modem: %x\n",
6284 jiffies, port, reason, modem));
6287 * Make sure the interrupt is valid.
6289 if (port >= bd->nasync)
6292 if (!(reason & (IFMODEM | IFBREAK | IFTLW | IFTEM | IFDATA))) {
6296 ch = bd->channels[port];
6298 if (!ch || ch->magic != DGAP_CHANNEL_MAGIC) {
6303 * If we have made it here, the event was valid.
6304 * Lock down the channel.
6306 DGAP_LOCK(ch->ch_lock, lock_flags2);
6311 DGAP_UNLOCK(ch->ch_lock, lock_flags2);
6316 * Process received data.
6318 if (reason & IFDATA) {
6321 * ALL LOCKS *MUST* BE DROPPED BEFORE CALLING INPUT!
6322 * input could send some data to ld, which in turn
6323 * could do a callback to one of our other functions.
6325 DGAP_UNLOCK(ch->ch_lock, lock_flags2);
6326 DGAP_UNLOCK(bd->bd_lock, lock_flags);
6330 DGAP_LOCK(bd->bd_lock, lock_flags);
6331 DGAP_LOCK(ch->ch_lock, lock_flags2);
6333 if (ch->ch_flags & CH_RACTIVE)
6334 ch->ch_flags |= CH_RENABLE;
6336 writeb(1, &(bs->idata));
6338 if (ch->ch_flags & CH_RWAIT) {
6339 ch->ch_flags &= ~CH_RWAIT;
6341 wake_up_interruptible(&ch->ch_tun.un_flags_wait);
6346 * Process Modem change signals.
6348 if (reason & IFMODEM) {
6349 ch->ch_mistat = modem;
6356 if (reason & IFBREAK) {
6358 DPR_EVENT(("got IFBREAK\n"));
6360 if (ch->ch_tun.un_tty) {
6361 /* A break has been indicated */
6363 tty_buffer_request_room(ch->ch_tun.un_tty->port, 1);
6364 tty_insert_flip_char(ch->ch_tun.un_tty->port, 0, TTY_BREAK);
6365 tty_flip_buffer_push(ch->ch_tun.un_tty->port);
6370 * Process Transmit low.
6372 if (reason & IFTLW) {
6374 DPR_EVENT(("event: got low event\n"));
6376 if (ch->ch_tun.un_flags & UN_LOW) {
6377 ch->ch_tun.un_flags &= ~UN_LOW;
6379 if (ch->ch_tun.un_flags & UN_ISOPEN) {
6380 if ((ch->ch_tun.un_tty->flags &
6381 (1 << TTY_DO_WRITE_WAKEUP)) &&
6382 ch->ch_tun.un_tty->ldisc->ops->write_wakeup)
6384 DGAP_UNLOCK(ch->ch_lock, lock_flags2);
6385 DGAP_UNLOCK(bd->bd_lock, lock_flags);
6386 (ch->ch_tun.un_tty->ldisc->ops->write_wakeup)(ch->ch_tun.un_tty);
6387 DGAP_LOCK(bd->bd_lock, lock_flags);
6388 DGAP_LOCK(ch->ch_lock, lock_flags2);
6390 wake_up_interruptible(&ch->ch_tun.un_tty->write_wait);
6391 wake_up_interruptible(&ch->ch_tun.un_flags_wait);
6393 DPR_EVENT(("event: Got low event. jiffies: %lu\n", jiffies));
6397 if (ch->ch_pun.un_flags & UN_LOW) {
6398 ch->ch_pun.un_flags &= ~UN_LOW;
6399 if (ch->ch_pun.un_flags & UN_ISOPEN) {
6400 if ((ch->ch_pun.un_tty->flags &
6401 (1 << TTY_DO_WRITE_WAKEUP)) &&
6402 ch->ch_pun.un_tty->ldisc->ops->write_wakeup)
6404 DGAP_UNLOCK(ch->ch_lock, lock_flags2);
6405 DGAP_UNLOCK(bd->bd_lock, lock_flags);
6406 (ch->ch_pun.un_tty->ldisc->ops->write_wakeup)(ch->ch_pun.un_tty);
6407 DGAP_LOCK(bd->bd_lock, lock_flags);
6408 DGAP_LOCK(ch->ch_lock, lock_flags2);
6410 wake_up_interruptible(&ch->ch_pun.un_tty->write_wait);
6411 wake_up_interruptible(&ch->ch_pun.un_flags_wait);
6415 if (ch->ch_flags & CH_WLOW) {
6416 ch->ch_flags &= ~CH_WLOW;
6417 wake_up_interruptible(&ch->ch_flags_wait);
6422 * Process Transmit empty.
6424 if (reason & IFTEM) {
6425 DPR_EVENT(("event: got empty event\n"));
6427 if (ch->ch_tun.un_flags & UN_EMPTY) {
6428 ch->ch_tun.un_flags &= ~UN_EMPTY;
6429 if (ch->ch_tun.un_flags & UN_ISOPEN) {
6430 if ((ch->ch_tun.un_tty->flags &
6431 (1 << TTY_DO_WRITE_WAKEUP)) &&
6432 ch->ch_tun.un_tty->ldisc->ops->write_wakeup)
6434 DGAP_UNLOCK(ch->ch_lock, lock_flags2);
6435 DGAP_UNLOCK(bd->bd_lock, lock_flags);
6437 (ch->ch_tun.un_tty->ldisc->ops->write_wakeup)(ch->ch_tun.un_tty);
6438 DGAP_LOCK(bd->bd_lock, lock_flags);
6439 DGAP_LOCK(ch->ch_lock, lock_flags2);
6441 wake_up_interruptible(&ch->ch_tun.un_tty->write_wait);
6442 wake_up_interruptible(&ch->ch_tun.un_flags_wait);
6446 if (ch->ch_pun.un_flags & UN_EMPTY) {
6447 ch->ch_pun.un_flags &= ~UN_EMPTY;
6448 if (ch->ch_pun.un_flags & UN_ISOPEN) {
6449 if ((ch->ch_pun.un_tty->flags &
6450 (1 << TTY_DO_WRITE_WAKEUP)) &&
6451 ch->ch_pun.un_tty->ldisc->ops->write_wakeup)
6453 DGAP_UNLOCK(ch->ch_lock, lock_flags2);
6454 DGAP_UNLOCK(bd->bd_lock, lock_flags);
6455 (ch->ch_pun.un_tty->ldisc->ops->write_wakeup)(ch->ch_pun.un_tty);
6456 DGAP_LOCK(bd->bd_lock, lock_flags);
6457 DGAP_LOCK(ch->ch_lock, lock_flags2);
6459 wake_up_interruptible(&ch->ch_pun.un_tty->write_wait);
6460 wake_up_interruptible(&ch->ch_pun.un_flags_wait);
6465 if (ch->ch_flags & CH_WEMPTY) {
6466 ch->ch_flags &= ~CH_WEMPTY;
6467 wake_up_interruptible(&ch->ch_flags_wait);
6471 DGAP_UNLOCK(ch->ch_lock, lock_flags2);
6474 tail = (tail + 4) & (EVMAX - EVSTART - 4);
6477 writew(tail, &(eaddr->ev_tail));
6478 DGAP_UNLOCK(bd->bd_lock, lock_flags);
6483 static ssize_t dgap_driver_version_show(struct device_driver *ddp, char *buf)
6485 return snprintf(buf, PAGE_SIZE, "%s\n", DG_PART);
6487 static DRIVER_ATTR(version, S_IRUSR, dgap_driver_version_show, NULL);
6490 static ssize_t dgap_driver_boards_show(struct device_driver *ddp, char *buf)
6492 return snprintf(buf, PAGE_SIZE, "%d\n", dgap_NumBoards);
6494 static DRIVER_ATTR(boards, S_IRUSR, dgap_driver_boards_show, NULL);
6497 static ssize_t dgap_driver_maxboards_show(struct device_driver *ddp, char *buf)
6499 return snprintf(buf, PAGE_SIZE, "%d\n", MAXBOARDS);
6501 static DRIVER_ATTR(maxboards, S_IRUSR, dgap_driver_maxboards_show, NULL);
6504 static ssize_t dgap_driver_pollcounter_show(struct device_driver *ddp, char *buf)
6506 return snprintf(buf, PAGE_SIZE, "%ld\n", dgap_poll_counter);
6508 static DRIVER_ATTR(pollcounter, S_IRUSR, dgap_driver_pollcounter_show, NULL);
6511 static ssize_t dgap_driver_state_show(struct device_driver *ddp, char *buf)
6513 return snprintf(buf, PAGE_SIZE, "%s\n", dgap_driver_state_text[dgap_driver_state]);
6515 static DRIVER_ATTR(state, S_IRUSR, dgap_driver_state_show, NULL);
6518 static ssize_t dgap_driver_debug_show(struct device_driver *ddp, char *buf)
6520 return snprintf(buf, PAGE_SIZE, "0x%x\n", dgap_debug);
6523 static ssize_t dgap_driver_debug_store(struct device_driver *ddp, const char *buf, size_t count)
6525 sscanf(buf, "0x%x\n", &dgap_debug);
6528 static DRIVER_ATTR(debug, (S_IRUSR | S_IWUSR), dgap_driver_debug_show, dgap_driver_debug_store);
6531 static ssize_t dgap_driver_rawreadok_show(struct device_driver *ddp, char *buf)
6533 return snprintf(buf, PAGE_SIZE, "0x%x\n", dgap_rawreadok);
6536 static ssize_t dgap_driver_rawreadok_store(struct device_driver *ddp, const char *buf, size_t count)
6538 sscanf(buf, "0x%x\n", &dgap_rawreadok);
6541 static DRIVER_ATTR(rawreadok, (S_IRUSR | S_IWUSR), dgap_driver_rawreadok_show, dgap_driver_rawreadok_store);
6544 static ssize_t dgap_driver_pollrate_show(struct device_driver *ddp, char *buf)
6546 return snprintf(buf, PAGE_SIZE, "%dms\n", dgap_poll_tick);
6549 static ssize_t dgap_driver_pollrate_store(struct device_driver *ddp, const char *buf, size_t count)
6551 sscanf(buf, "%d\n", &dgap_poll_tick);
6554 static DRIVER_ATTR(pollrate, (S_IRUSR | S_IWUSR), dgap_driver_pollrate_show, dgap_driver_pollrate_store);
6557 void dgap_create_driver_sysfiles(struct pci_driver *dgap_driver)
6560 struct device_driver *driverfs = &dgap_driver->driver;
6562 rc |= driver_create_file(driverfs, &driver_attr_version);
6563 rc |= driver_create_file(driverfs, &driver_attr_boards);
6564 rc |= driver_create_file(driverfs, &driver_attr_maxboards);
6565 rc |= driver_create_file(driverfs, &driver_attr_debug);
6566 rc |= driver_create_file(driverfs, &driver_attr_rawreadok);
6567 rc |= driver_create_file(driverfs, &driver_attr_pollrate);
6568 rc |= driver_create_file(driverfs, &driver_attr_pollcounter);
6569 rc |= driver_create_file(driverfs, &driver_attr_state);
6571 printk(KERN_ERR "DGAP: sysfs driver_create_file failed!\n");
6576 void dgap_remove_driver_sysfiles(struct pci_driver *dgap_driver)
6578 struct device_driver *driverfs = &dgap_driver->driver;
6579 driver_remove_file(driverfs, &driver_attr_version);
6580 driver_remove_file(driverfs, &driver_attr_boards);
6581 driver_remove_file(driverfs, &driver_attr_maxboards);
6582 driver_remove_file(driverfs, &driver_attr_debug);
6583 driver_remove_file(driverfs, &driver_attr_rawreadok);
6584 driver_remove_file(driverfs, &driver_attr_pollrate);
6585 driver_remove_file(driverfs, &driver_attr_pollcounter);
6586 driver_remove_file(driverfs, &driver_attr_state);
6590 #define DGAP_VERIFY_BOARD(p, bd) \
6594 bd = dev_get_drvdata(p); \
6595 if (!bd || bd->magic != DGAP_BOARD_MAGIC) \
6597 if (bd->state != BOARD_READY) \
6601 static ssize_t dgap_ports_state_show(struct device *p, struct device_attribute *attr, char *buf)
6607 DGAP_VERIFY_BOARD(p, bd);
6609 for (i = 0; i < bd->nasync; i++) {
6610 count += snprintf(buf + count, PAGE_SIZE - count,
6611 "%d %s\n", bd->channels[i]->ch_portnum,
6612 bd->channels[i]->ch_open_count ? "Open" : "Closed");
6616 static DEVICE_ATTR(ports_state, S_IRUSR, dgap_ports_state_show, NULL);
6619 static ssize_t dgap_ports_baud_show(struct device *p, struct device_attribute *attr, char *buf)
6625 DGAP_VERIFY_BOARD(p, bd);
6627 for (i = 0; i < bd->nasync; i++) {
6628 count += snprintf(buf + count, PAGE_SIZE - count,
6629 "%d %d\n", bd->channels[i]->ch_portnum, bd->channels[i]->ch_baud_info);
6633 static DEVICE_ATTR(ports_baud, S_IRUSR, dgap_ports_baud_show, NULL);
6636 static ssize_t dgap_ports_msignals_show(struct device *p, struct device_attribute *attr, char *buf)
6642 DGAP_VERIFY_BOARD(p, bd);
6644 for (i = 0; i < bd->nasync; i++) {
6645 if (bd->channels[i]->ch_open_count) {
6646 count += snprintf(buf + count, PAGE_SIZE - count,
6647 "%d %s %s %s %s %s %s\n", bd->channels[i]->ch_portnum,
6648 (bd->channels[i]->ch_mostat & UART_MCR_RTS) ? "RTS" : "",
6649 (bd->channels[i]->ch_mistat & UART_MSR_CTS) ? "CTS" : "",
6650 (bd->channels[i]->ch_mostat & UART_MCR_DTR) ? "DTR" : "",
6651 (bd->channels[i]->ch_mistat & UART_MSR_DSR) ? "DSR" : "",
6652 (bd->channels[i]->ch_mistat & UART_MSR_DCD) ? "DCD" : "",
6653 (bd->channels[i]->ch_mistat & UART_MSR_RI) ? "RI" : "");
6655 count += snprintf(buf + count, PAGE_SIZE - count,
6656 "%d\n", bd->channels[i]->ch_portnum);
6661 static DEVICE_ATTR(ports_msignals, S_IRUSR, dgap_ports_msignals_show, NULL);
6664 static ssize_t dgap_ports_iflag_show(struct device *p, struct device_attribute *attr, char *buf)
6670 DGAP_VERIFY_BOARD(p, bd);
6672 for (i = 0; i < bd->nasync; i++) {
6673 count += snprintf(buf + count, PAGE_SIZE - count, "%d %x\n",
6674 bd->channels[i]->ch_portnum, bd->channels[i]->ch_c_iflag);
6678 static DEVICE_ATTR(ports_iflag, S_IRUSR, dgap_ports_iflag_show, NULL);
6681 static ssize_t dgap_ports_cflag_show(struct device *p, struct device_attribute *attr, char *buf)
6687 DGAP_VERIFY_BOARD(p, bd);
6689 for (i = 0; i < bd->nasync; i++) {
6690 count += snprintf(buf + count, PAGE_SIZE - count, "%d %x\n",
6691 bd->channels[i]->ch_portnum, bd->channels[i]->ch_c_cflag);
6695 static DEVICE_ATTR(ports_cflag, S_IRUSR, dgap_ports_cflag_show, NULL);
6698 static ssize_t dgap_ports_oflag_show(struct device *p, struct device_attribute *attr, char *buf)
6704 DGAP_VERIFY_BOARD(p, bd);
6706 for (i = 0; i < bd->nasync; i++) {
6707 count += snprintf(buf + count, PAGE_SIZE - count, "%d %x\n",
6708 bd->channels[i]->ch_portnum, bd->channels[i]->ch_c_oflag);
6712 static DEVICE_ATTR(ports_oflag, S_IRUSR, dgap_ports_oflag_show, NULL);
6715 static ssize_t dgap_ports_lflag_show(struct device *p, struct device_attribute *attr, char *buf)
6721 DGAP_VERIFY_BOARD(p, bd);
6723 for (i = 0; i < bd->nasync; i++) {
6724 count += snprintf(buf + count, PAGE_SIZE - count, "%d %x\n",
6725 bd->channels[i]->ch_portnum, bd->channels[i]->ch_c_lflag);
6729 static DEVICE_ATTR(ports_lflag, S_IRUSR, dgap_ports_lflag_show, NULL);
6732 static ssize_t dgap_ports_digi_flag_show(struct device *p, struct device_attribute *attr, char *buf)
6738 DGAP_VERIFY_BOARD(p, bd);
6740 for (i = 0; i < bd->nasync; i++) {
6741 count += snprintf(buf + count, PAGE_SIZE - count, "%d %x\n",
6742 bd->channels[i]->ch_portnum, bd->channels[i]->ch_digi.digi_flags);
6746 static DEVICE_ATTR(ports_digi_flag, S_IRUSR, dgap_ports_digi_flag_show, NULL);
6749 static ssize_t dgap_ports_rxcount_show(struct device *p, struct device_attribute *attr, char *buf)
6755 DGAP_VERIFY_BOARD(p, bd);
6757 for (i = 0; i < bd->nasync; i++) {
6758 count += snprintf(buf + count, PAGE_SIZE - count, "%d %ld\n",
6759 bd->channels[i]->ch_portnum, bd->channels[i]->ch_rxcount);
6763 static DEVICE_ATTR(ports_rxcount, S_IRUSR, dgap_ports_rxcount_show, NULL);
6766 static ssize_t dgap_ports_txcount_show(struct device *p, struct device_attribute *attr, char *buf)
6772 DGAP_VERIFY_BOARD(p, bd);
6774 for (i = 0; i < bd->nasync; i++) {
6775 count += snprintf(buf + count, PAGE_SIZE - count, "%d %ld\n",
6776 bd->channels[i]->ch_portnum, bd->channels[i]->ch_txcount);
6780 static DEVICE_ATTR(ports_txcount, S_IRUSR, dgap_ports_txcount_show, NULL);
6783 /* this function creates the sys files that will export each signal status
6784 * to sysfs each value will be put in a separate filename
6786 void dgap_create_ports_sysfiles(struct board_t *bd)
6790 dev_set_drvdata(&bd->pdev->dev, bd);
6791 rc |= device_create_file(&(bd->pdev->dev), &dev_attr_ports_state);
6792 rc |= device_create_file(&(bd->pdev->dev), &dev_attr_ports_baud);
6793 rc |= device_create_file(&(bd->pdev->dev), &dev_attr_ports_msignals);
6794 rc |= device_create_file(&(bd->pdev->dev), &dev_attr_ports_iflag);
6795 rc |= device_create_file(&(bd->pdev->dev), &dev_attr_ports_cflag);
6796 rc |= device_create_file(&(bd->pdev->dev), &dev_attr_ports_oflag);
6797 rc |= device_create_file(&(bd->pdev->dev), &dev_attr_ports_lflag);
6798 rc |= device_create_file(&(bd->pdev->dev), &dev_attr_ports_digi_flag);
6799 rc |= device_create_file(&(bd->pdev->dev), &dev_attr_ports_rxcount);
6800 rc |= device_create_file(&(bd->pdev->dev), &dev_attr_ports_txcount);
6802 printk(KERN_ERR "DGAP: sysfs device_create_file failed!\n");
6807 /* removes all the sys files created for that port */
6808 void dgap_remove_ports_sysfiles(struct board_t *bd)
6810 device_remove_file(&(bd->pdev->dev), &dev_attr_ports_state);
6811 device_remove_file(&(bd->pdev->dev), &dev_attr_ports_baud);
6812 device_remove_file(&(bd->pdev->dev), &dev_attr_ports_msignals);
6813 device_remove_file(&(bd->pdev->dev), &dev_attr_ports_iflag);
6814 device_remove_file(&(bd->pdev->dev), &dev_attr_ports_cflag);
6815 device_remove_file(&(bd->pdev->dev), &dev_attr_ports_oflag);
6816 device_remove_file(&(bd->pdev->dev), &dev_attr_ports_lflag);
6817 device_remove_file(&(bd->pdev->dev), &dev_attr_ports_digi_flag);
6818 device_remove_file(&(bd->pdev->dev), &dev_attr_ports_rxcount);
6819 device_remove_file(&(bd->pdev->dev), &dev_attr_ports_txcount);
6823 static ssize_t dgap_tty_state_show(struct device *d, struct device_attribute *attr, char *buf)
6826 struct channel_t *ch;
6831 un = dev_get_drvdata(d);
6832 if (!un || un->magic != DGAP_UNIT_MAGIC)
6835 if (!ch || ch->magic != DGAP_CHANNEL_MAGIC)
6838 if (!bd || bd->magic != DGAP_BOARD_MAGIC)
6840 if (bd->state != BOARD_READY)
6843 return snprintf(buf, PAGE_SIZE, "%s", un->un_open_count ? "Open" : "Closed");
6845 static DEVICE_ATTR(state, S_IRUSR, dgap_tty_state_show, NULL);
6848 static ssize_t dgap_tty_baud_show(struct device *d, struct device_attribute *attr, char *buf)
6851 struct channel_t *ch;
6856 un = dev_get_drvdata(d);
6857 if (!un || un->magic != DGAP_UNIT_MAGIC)
6860 if (!ch || ch->magic != DGAP_CHANNEL_MAGIC)
6863 if (!bd || bd->magic != DGAP_BOARD_MAGIC)
6865 if (bd->state != BOARD_READY)
6868 return snprintf(buf, PAGE_SIZE, "%d\n", ch->ch_baud_info);
6870 static DEVICE_ATTR(baud, S_IRUSR, dgap_tty_baud_show, NULL);
6873 static ssize_t dgap_tty_msignals_show(struct device *d, struct device_attribute *attr, char *buf)
6876 struct channel_t *ch;
6881 un = dev_get_drvdata(d);
6882 if (!un || un->magic != DGAP_UNIT_MAGIC)
6885 if (!ch || ch->magic != DGAP_CHANNEL_MAGIC)
6888 if (!bd || bd->magic != DGAP_BOARD_MAGIC)
6890 if (bd->state != BOARD_READY)
6893 if (ch->ch_open_count) {
6894 return snprintf(buf, PAGE_SIZE, "%s %s %s %s %s %s\n",
6895 (ch->ch_mostat & UART_MCR_RTS) ? "RTS" : "",
6896 (ch->ch_mistat & UART_MSR_CTS) ? "CTS" : "",
6897 (ch->ch_mostat & UART_MCR_DTR) ? "DTR" : "",
6898 (ch->ch_mistat & UART_MSR_DSR) ? "DSR" : "",
6899 (ch->ch_mistat & UART_MSR_DCD) ? "DCD" : "",
6900 (ch->ch_mistat & UART_MSR_RI) ? "RI" : "");
6904 static DEVICE_ATTR(msignals, S_IRUSR, dgap_tty_msignals_show, NULL);
6907 static ssize_t dgap_tty_iflag_show(struct device *d, struct device_attribute *attr, char *buf)
6910 struct channel_t *ch;
6915 un = dev_get_drvdata(d);
6916 if (!un || un->magic != DGAP_UNIT_MAGIC)
6919 if (!ch || ch->magic != DGAP_CHANNEL_MAGIC)
6922 if (!bd || bd->magic != DGAP_BOARD_MAGIC)
6924 if (bd->state != BOARD_READY)
6927 return snprintf(buf, PAGE_SIZE, "%x\n", ch->ch_c_iflag);
6929 static DEVICE_ATTR(iflag, S_IRUSR, dgap_tty_iflag_show, NULL);
6932 static ssize_t dgap_tty_cflag_show(struct device *d, struct device_attribute *attr, char *buf)
6935 struct channel_t *ch;
6940 un = dev_get_drvdata(d);
6941 if (!un || un->magic != DGAP_UNIT_MAGIC)
6944 if (!ch || ch->magic != DGAP_CHANNEL_MAGIC)
6947 if (!bd || bd->magic != DGAP_BOARD_MAGIC)
6949 if (bd->state != BOARD_READY)
6952 return snprintf(buf, PAGE_SIZE, "%x\n", ch->ch_c_cflag);
6954 static DEVICE_ATTR(cflag, S_IRUSR, dgap_tty_cflag_show, NULL);
6957 static ssize_t dgap_tty_oflag_show(struct device *d, struct device_attribute *attr, char *buf)
6960 struct channel_t *ch;
6965 un = dev_get_drvdata(d);
6966 if (!un || un->magic != DGAP_UNIT_MAGIC)
6969 if (!ch || ch->magic != DGAP_CHANNEL_MAGIC)
6972 if (!bd || bd->magic != DGAP_BOARD_MAGIC)
6974 if (bd->state != BOARD_READY)
6977 return snprintf(buf, PAGE_SIZE, "%x\n", ch->ch_c_oflag);
6979 static DEVICE_ATTR(oflag, S_IRUSR, dgap_tty_oflag_show, NULL);
6982 static ssize_t dgap_tty_lflag_show(struct device *d, struct device_attribute *attr, char *buf)
6985 struct channel_t *ch;
6990 un = dev_get_drvdata(d);
6991 if (!un || un->magic != DGAP_UNIT_MAGIC)
6994 if (!ch || ch->magic != DGAP_CHANNEL_MAGIC)
6997 if (!bd || bd->magic != DGAP_BOARD_MAGIC)
6999 if (bd->state != BOARD_READY)
7002 return snprintf(buf, PAGE_SIZE, "%x\n", ch->ch_c_lflag);
7004 static DEVICE_ATTR(lflag, S_IRUSR, dgap_tty_lflag_show, NULL);
7007 static ssize_t dgap_tty_digi_flag_show(struct device *d, struct device_attribute *attr, char *buf)
7010 struct channel_t *ch;
7015 un = dev_get_drvdata(d);
7016 if (!un || un->magic != DGAP_UNIT_MAGIC)
7019 if (!ch || ch->magic != DGAP_CHANNEL_MAGIC)
7022 if (!bd || bd->magic != DGAP_BOARD_MAGIC)
7024 if (bd->state != BOARD_READY)
7027 return snprintf(buf, PAGE_SIZE, "%x\n", ch->ch_digi.digi_flags);
7029 static DEVICE_ATTR(digi_flag, S_IRUSR, dgap_tty_digi_flag_show, NULL);
7032 static ssize_t dgap_tty_rxcount_show(struct device *d, struct device_attribute *attr, char *buf)
7035 struct channel_t *ch;
7040 un = dev_get_drvdata(d);
7041 if (!un || un->magic != DGAP_UNIT_MAGIC)
7044 if (!ch || ch->magic != DGAP_CHANNEL_MAGIC)
7047 if (!bd || bd->magic != DGAP_BOARD_MAGIC)
7049 if (bd->state != BOARD_READY)
7052 return snprintf(buf, PAGE_SIZE, "%ld\n", ch->ch_rxcount);
7054 static DEVICE_ATTR(rxcount, S_IRUSR, dgap_tty_rxcount_show, NULL);
7057 static ssize_t dgap_tty_txcount_show(struct device *d, struct device_attribute *attr, char *buf)
7060 struct channel_t *ch;
7065 un = dev_get_drvdata(d);
7066 if (!un || un->magic != DGAP_UNIT_MAGIC)
7069 if (!ch || ch->magic != DGAP_CHANNEL_MAGIC)
7072 if (!bd || bd->magic != DGAP_BOARD_MAGIC)
7074 if (bd->state != BOARD_READY)
7077 return snprintf(buf, PAGE_SIZE, "%ld\n", ch->ch_txcount);
7079 static DEVICE_ATTR(txcount, S_IRUSR, dgap_tty_txcount_show, NULL);
7082 static ssize_t dgap_tty_name_show(struct device *d, struct device_attribute *attr, char *buf)
7085 struct channel_t *ch;
7089 struct cnode *cptr = NULL;
7097 un = dev_get_drvdata(d);
7098 if (!un || un->magic != DGAP_UNIT_MAGIC)
7101 if (!ch || ch->magic != DGAP_CHANNEL_MAGIC)
7104 if (!bd || bd->magic != DGAP_BOARD_MAGIC)
7106 if (bd->state != BOARD_READY)
7110 cn = ch->ch_portnum;
7112 for (cptr = bd->bd_config; cptr; cptr = cptr->next) {
7114 if ((cptr->type == BNODE) &&
7115 ((cptr->u.board.type == APORT2_920P) || (cptr->u.board.type == APORT4_920P) ||
7116 (cptr->u.board.type == APORT8_920P) || (cptr->u.board.type == PAPORT4) ||
7117 (cptr->u.board.type == PAPORT8))) {
7120 if (cptr->u.board.v_start)
7121 starto = cptr->u.board.start;
7126 if (cptr->type == TNODE && found == TRUE) {
7128 if (strstr(cptr->u.ttyname, "tty")) {
7129 ptr1 = cptr->u.ttyname;
7133 ptr1 = cptr->u.ttyname;
7136 for (i = 0; i < dgap_config_get_number_of_ports(bd); i++) {
7138 return snprintf(buf, PAGE_SIZE, "%s%s%02d\n",
7139 (un->un_type == DGAP_PRINT) ? "pr" : "tty",
7145 if (cptr->type == CNODE) {
7147 for (i = 0; i < cptr->u.conc.nport; i++) {
7148 if (cn == (i + ncount)) {
7150 return snprintf(buf, PAGE_SIZE, "%s%s%02d\n",
7151 (un->un_type == DGAP_PRINT) ? "pr" : "tty",
7153 i + (cptr->u.conc.v_start ? cptr->u.conc.start : 1));
7157 ncount += cptr->u.conc.nport;
7160 if (cptr->type == MNODE) {
7162 for (i = 0; i < cptr->u.module.nport; i++) {
7163 if (cn == (i + ncount)) {
7164 return snprintf(buf, PAGE_SIZE, "%s%s%02d\n",
7165 (un->un_type == DGAP_PRINT) ? "pr" : "tty",
7167 i + (cptr->u.module.v_start ? cptr->u.module.start : 1));
7171 ncount += cptr->u.module.nport;
7176 return snprintf(buf, PAGE_SIZE, "%s_dgap_%d_%d\n",
7177 (un->un_type == DGAP_PRINT) ? "pr" : "tty", bn, cn);
7180 static DEVICE_ATTR(custom_name, S_IRUSR, dgap_tty_name_show, NULL);
7183 static struct attribute *dgap_sysfs_tty_entries[] = {
7184 &dev_attr_state.attr,
7185 &dev_attr_baud.attr,
7186 &dev_attr_msignals.attr,
7187 &dev_attr_iflag.attr,
7188 &dev_attr_cflag.attr,
7189 &dev_attr_oflag.attr,
7190 &dev_attr_lflag.attr,
7191 &dev_attr_digi_flag.attr,
7192 &dev_attr_rxcount.attr,
7193 &dev_attr_txcount.attr,
7194 &dev_attr_custom_name.attr,
7199 static struct attribute_group dgap_tty_attribute_group = {
7201 .attrs = dgap_sysfs_tty_entries,
7207 void dgap_create_tty_sysfs(struct un_t *un, struct device *c)
7211 ret = sysfs_create_group(&c->kobj, &dgap_tty_attribute_group);
7213 printk(KERN_ERR "dgap: failed to create sysfs tty device attributes.\n");
7214 sysfs_remove_group(&c->kobj, &dgap_tty_attribute_group);
7218 dev_set_drvdata(c, un);
7223 void dgap_remove_tty_sysfs(struct device *c)
7225 sysfs_remove_group(&c->kobj, &dgap_tty_attribute_group);
7229 * Parse a configuration file read into memory as a string.
7231 int dgap_parsefile(char **in, int Remove)
7233 struct cnode *p, *brd, *line, *conc;
7235 char *s = NULL, *s2 = NULL;
7239 brd = line = conc = NULL;
7241 /* perhaps we are adding to an existing list? */
7242 while (p->next != NULL) {
7246 /* file must start with a BEGIN */
7247 while ( (rc = dgap_gettok(in,p)) != BEGIN ) {
7249 dgap_err("unexpected EOF");
7255 rc = dgap_gettok(in,p);
7257 dgap_err("unexpected EOF");
7263 dgap_err("unexpected end of file");
7266 case BEGIN: /* should only be 1 begin */
7267 dgap_err("unexpected config_begin\n");
7273 case BOARD: /* board info */
7274 if (dgap_checknode(p))
7276 if ( (p->next = dgap_newnode(BNODE)) == NULL ) {
7277 dgap_err("out of memory");
7282 p->u.board.status = dgap_savestring("No");
7288 case APORT2_920P: /* AccelePort_4 */
7289 if (p->type != BNODE) {
7290 dgap_err("unexpected Digi_2r_920 string");
7293 p->u.board.type = APORT2_920P;
7294 p->u.board.v_type = 1;
7295 DPR_INIT(("Adding Digi_2r_920 PCI to config...\n"));
7298 case APORT4_920P: /* AccelePort_4 */
7299 if (p->type != BNODE) {
7300 dgap_err("unexpected Digi_4r_920 string");
7303 p->u.board.type = APORT4_920P;
7304 p->u.board.v_type = 1;
7305 DPR_INIT(("Adding Digi_4r_920 PCI to config...\n"));
7308 case APORT8_920P: /* AccelePort_8 */
7309 if (p->type != BNODE) {
7310 dgap_err("unexpected Digi_8r_920 string");
7313 p->u.board.type = APORT8_920P;
7314 p->u.board.v_type = 1;
7315 DPR_INIT(("Adding Digi_8r_920 PCI to config...\n"));
7318 case PAPORT4: /* AccelePort_4 PCI */
7319 if (p->type != BNODE) {
7320 dgap_err("unexpected Digi_4r(PCI) string");
7323 p->u.board.type = PAPORT4;
7324 p->u.board.v_type = 1;
7325 DPR_INIT(("Adding Digi_4r PCI to config...\n"));
7328 case PAPORT8: /* AccelePort_8 PCI */
7329 if (p->type != BNODE) {
7330 dgap_err("unexpected Digi_8r string");
7333 p->u.board.type = PAPORT8;
7334 p->u.board.v_type = 1;
7335 DPR_INIT(("Adding Digi_8r PCI to config...\n"));
7338 case PCX: /* PCI C/X */
7339 if (p->type != BNODE) {
7340 dgap_err("unexpected Digi_C/X_(PCI) string");
7343 p->u.board.type = PCX;
7344 p->u.board.v_type = 1;
7345 p->u.board.conc1 = 0;
7346 p->u.board.conc2 = 0;
7347 p->u.board.module1 = 0;
7348 p->u.board.module2 = 0;
7349 DPR_INIT(("Adding PCI C/X to config...\n"));
7352 case PEPC: /* PCI EPC/X */
7353 if (p->type != BNODE) {
7354 dgap_err("unexpected \"Digi_EPC/X_(PCI)\" string");
7357 p->u.board.type = PEPC;
7358 p->u.board.v_type = 1;
7359 p->u.board.conc1 = 0;
7360 p->u.board.conc2 = 0;
7361 p->u.board.module1 = 0;
7362 p->u.board.module2 = 0;
7363 DPR_INIT(("Adding PCI EPC/X to config...\n"));
7366 case PPCM: /* PCI/Xem */
7367 if (p->type != BNODE) {
7368 dgap_err("unexpected PCI/Xem string");
7371 p->u.board.type = PPCM;
7372 p->u.board.v_type = 1;
7373 p->u.board.conc1 = 0;
7374 p->u.board.conc2 = 0;
7375 DPR_INIT(("Adding PCI XEM to config...\n"));
7378 case IO: /* i/o port */
7379 if (p->type != BNODE) {
7380 dgap_err("IO port only vaild for boards");
7383 s = dgap_getword(in);
7385 dgap_err("unexpected end of file");
7388 p->u.board.portstr = dgap_savestring(s);
7389 p->u.board.port = (short)simple_strtol(s, &s2, 0);
7390 if ((short)strlen(s) > (short)(s2 - s)) {
7391 dgap_err("bad number for IO port");
7394 p->u.board.v_port = 1;
7395 DPR_INIT(("Adding IO (%s) to config...\n", s));
7398 case MEM: /* memory address */
7399 if (p->type != BNODE) {
7400 dgap_err("memory address only vaild for boards");
7403 s = dgap_getword(in);
7405 dgap_err("unexpected end of file");
7408 p->u.board.addrstr = dgap_savestring(s);
7409 p->u.board.addr = simple_strtoul(s, &s2, 0);
7410 if ((int)strlen(s) > (int)(s2 - s)) {
7411 dgap_err("bad number for memory address");
7414 p->u.board.v_addr = 1;
7415 DPR_INIT(("Adding MEM (%s) to config...\n", s));
7418 case PCIINFO: /* pci information */
7419 if (p->type != BNODE) {
7420 dgap_err("memory address only vaild for boards");
7423 s = dgap_getword(in);
7425 dgap_err("unexpected end of file");
7428 p->u.board.pcibusstr = dgap_savestring(s);
7429 p->u.board.pcibus = simple_strtoul(s, &s2, 0);
7430 if ((int)strlen(s) > (int)(s2 - s)) {
7431 dgap_err("bad number for pci bus");
7434 p->u.board.v_pcibus = 1;
7435 s = dgap_getword(in);
7437 dgap_err("unexpected end of file");
7440 p->u.board.pcislotstr = dgap_savestring(s);
7441 p->u.board.pcislot = simple_strtoul(s, &s2, 0);
7442 if ((int)strlen(s) > (int)(s2 - s)) {
7443 dgap_err("bad number for pci slot");
7446 p->u.board.v_pcislot = 1;
7448 DPR_INIT(("Adding PCIINFO (%s %s) to config...\n", p->u.board.pcibusstr,
7449 p->u.board.pcislotstr));
7453 if (p->type != BNODE) {
7454 dgap_err("install method only vaild for boards");
7457 s = dgap_getword(in);
7459 dgap_err("unexpected end of file");
7462 p->u.board.method = dgap_savestring(s);
7463 p->u.board.v_method = 1;
7464 DPR_INIT(("Adding METHOD (%s) to config...\n", s));
7468 if (p->type != BNODE) {
7469 dgap_err("config status only vaild for boards");
7472 s = dgap_getword(in);
7474 dgap_err("unexpected end of file");
7477 p->u.board.status = dgap_savestring(s);
7478 DPR_INIT(("Adding STATUS (%s) to config...\n", s));
7481 case NPORTS: /* number of ports */
7482 if (p->type == BNODE) {
7483 s = dgap_getword(in);
7485 dgap_err("unexpected end of file");
7488 p->u.board.nport = (char)simple_strtol(s, &s2, 0);
7489 if ((int)strlen(s) > (int)(s2 - s)) {
7490 dgap_err("bad number for number of ports");
7493 p->u.board.v_nport = 1;
7494 } else if (p->type == CNODE) {
7495 s = dgap_getword(in);
7497 dgap_err("unexpected end of file");
7500 p->u.conc.nport = (char)simple_strtol(s, &s2, 0);
7501 if ((int)strlen(s) > (int)(s2 - s)) {
7502 dgap_err("bad number for number of ports");
7505 p->u.conc.v_nport = 1;
7506 } else if (p->type == MNODE) {
7507 s = dgap_getword(in);
7509 dgap_err("unexpected end of file");
7512 p->u.module.nport = (char)simple_strtol(s, &s2, 0);
7513 if ((int)strlen(s) > (int)(s2 - s)) {
7514 dgap_err("bad number for number of ports");
7517 p->u.module.v_nport = 1;
7519 dgap_err("nports only valid for concentrators or modules");
7522 DPR_INIT(("Adding NPORTS (%s) to config...\n", s));
7525 case ID: /* letter ID used in tty name */
7526 s = dgap_getword(in);
7528 dgap_err("unexpected end of file");
7532 p->u.board.status = dgap_savestring(s);
7534 if (p->type == CNODE) {
7535 p->u.conc.id = dgap_savestring(s);
7537 } else if (p->type == MNODE) {
7538 p->u.module.id = dgap_savestring(s);
7539 p->u.module.v_id = 1;
7541 dgap_err("id only valid for concentrators or modules");
7544 DPR_INIT(("Adding ID (%s) to config...\n", s));
7547 case STARTO: /* start offset of ID */
7548 if (p->type == BNODE) {
7549 s = dgap_getword(in);
7551 dgap_err("unexpected end of file");
7554 p->u.board.start = simple_strtol(s, &s2, 0);
7555 if ((int)strlen(s) > (int)(s2 - s)) {
7556 dgap_err("bad number for start of tty count");
7559 p->u.board.v_start = 1;
7560 } else if (p->type == CNODE) {
7561 s = dgap_getword(in);
7563 dgap_err("unexpected end of file");
7566 p->u.conc.start = simple_strtol(s, &s2, 0);
7567 if ((int)strlen(s) > (int)(s2 - s)) {
7568 dgap_err("bad number for start of tty count");
7571 p->u.conc.v_start = 1;
7572 } else if (p->type == MNODE) {
7573 s = dgap_getword(in);
7575 dgap_err("unexpected end of file");
7578 p->u.module.start = simple_strtol(s, &s2, 0);
7579 if ((int)strlen(s) > (int)(s2 - s)) {
7580 dgap_err("bad number for start of tty count");
7583 p->u.module.v_start = 1;
7585 dgap_err("start only valid for concentrators or modules");
7588 DPR_INIT(("Adding START (%s) to config...\n", s));
7591 case TTYN: /* tty name prefix */
7592 if (dgap_checknode(p))
7594 if ( (p->next = dgap_newnode(TNODE)) == NULL ) {
7595 dgap_err("out of memory");
7599 if ( (s = dgap_getword(in)) == NULL ) {
7600 dgap_err("unexpeced end of file");
7603 if ( (p->u.ttyname = dgap_savestring(s)) == NULL ) {
7604 dgap_err("out of memory");
7607 DPR_INIT(("Adding TTY (%s) to config...\n", s));
7610 case CU: /* cu name prefix */
7611 if (dgap_checknode(p))
7613 if ( (p->next = dgap_newnode(CUNODE)) == NULL ) {
7614 dgap_err("out of memory");
7618 if ( (s = dgap_getword(in)) == NULL ) {
7619 dgap_err("unexpeced end of file");
7622 if ( (p->u.cuname = dgap_savestring(s)) == NULL ) {
7623 dgap_err("out of memory");
7626 DPR_INIT(("Adding CU (%s) to config...\n", s));
7629 case LINE: /* line information */
7630 if (dgap_checknode(p))
7633 dgap_err("must specify board before line info");
7636 switch (brd->u.board.type) {
7638 dgap_err("line not vaild for PC/em");
7641 if ( (p->next = dgap_newnode(LNODE)) == NULL ) {
7642 dgap_err("out of memory");
7649 DPR_INIT(("Adding LINE to config...\n"));
7652 case CONC: /* concentrator information */
7653 if (dgap_checknode(p))
7656 dgap_err("must specify line info before concentrator");
7659 if ( (p->next = dgap_newnode(CNODE)) == NULL ) {
7660 dgap_err("out of memory");
7666 brd->u.board.conc2++;
7668 brd->u.board.conc1++;
7670 DPR_INIT(("Adding CONC to config...\n"));
7673 case CX: /* c/x type concentrator */
7674 if (p->type != CNODE) {
7675 dgap_err("cx only valid for concentrators");
7678 p->u.conc.type = CX;
7679 p->u.conc.v_type = 1;
7680 DPR_INIT(("Adding CX to config...\n"));
7683 case EPC: /* epc type concentrator */
7684 if (p->type != CNODE) {
7685 dgap_err("cx only valid for concentrators");
7688 p->u.conc.type = EPC;
7689 p->u.conc.v_type = 1;
7690 DPR_INIT(("Adding EPC to config...\n"));
7693 case MOD: /* EBI module */
7694 if (dgap_checknode(p))
7697 dgap_err("must specify board info before EBI modules");
7700 switch (brd->u.board.type) {
7706 dgap_err("must specify concentrator info before EBI module");
7710 if ( (p->next = dgap_newnode(MNODE)) == NULL ) {
7711 dgap_err("out of memory");
7716 brd->u.board.module2++;
7718 brd->u.board.module1++;
7720 DPR_INIT(("Adding MOD to config...\n"));
7723 case PORTS: /* ports type EBI module */
7724 if (p->type != MNODE) {
7725 dgap_err("ports only valid for EBI modules");
7728 p->u.module.type = PORTS;
7729 p->u.module.v_type = 1;
7730 DPR_INIT(("Adding PORTS to config...\n"));
7733 case MODEM: /* ports type EBI module */
7734 if (p->type != MNODE) {
7735 dgap_err("modem only valid for modem modules");
7738 p->u.module.type = MODEM;
7739 p->u.module.v_type = 1;
7740 DPR_INIT(("Adding MODEM to config...\n"));
7744 if (p->type == LNODE) {
7745 if ((s = dgap_getword(in)) == NULL) {
7746 dgap_err("unexpected end of file");
7749 p->u.line.cable = dgap_savestring(s);
7750 p->u.line.v_cable = 1;
7752 DPR_INIT(("Adding CABLE (%s) to config...\n", s));
7755 case SPEED: /* sync line speed indication */
7756 if (p->type == LNODE) {
7757 s = dgap_getword(in);
7759 dgap_err("unexpected end of file");
7762 p->u.line.speed = (char)simple_strtol(s, &s2, 0);
7763 if ((short)strlen(s) > (short)(s2 - s)) {
7764 dgap_err("bad number for line speed");
7767 p->u.line.v_speed = 1;
7768 } else if (p->type == CNODE) {
7769 s = dgap_getword(in);
7771 dgap_err("unexpected end of file");
7774 p->u.conc.speed = (char)simple_strtol(s, &s2, 0);
7775 if ((short)strlen(s) > (short)(s2 - s)) {
7776 dgap_err("bad number for line speed");
7779 p->u.conc.v_speed = 1;
7781 dgap_err("speed valid only for lines or concentrators.");
7784 DPR_INIT(("Adding SPEED (%s) to config...\n", s));
7788 if (p->type == CNODE) {
7789 if ((s = dgap_getword(in)) == NULL) {
7790 dgap_err("unexpected end of file");
7793 p->u.conc.connect = dgap_savestring(s);
7794 p->u.conc.v_connect = 1;
7796 DPR_INIT(("Adding CONNECT (%s) to config...\n", s));
7798 case PRINT: /* transparent print name prefix */
7799 if (dgap_checknode(p))
7801 if ( (p->next = dgap_newnode(PNODE)) == NULL ) {
7802 dgap_err("out of memory");
7806 if ( (s = dgap_getword(in)) == NULL ) {
7807 dgap_err("unexpeced end of file");
7810 if ( (p->u.printname = dgap_savestring(s)) == NULL ) {
7811 dgap_err("out of memory");
7814 DPR_INIT(("Adding PRINT (%s) to config...\n", s));
7817 case CMAJOR: /* major number */
7818 if (dgap_checknode(p))
7820 if ( (p->next = dgap_newnode(JNODE)) == NULL ) {
7821 dgap_err("out of memory");
7825 s = dgap_getword(in);
7827 dgap_err("unexpected end of file");
7830 p->u.majornumber = simple_strtol(s, &s2, 0);
7831 if ((int)strlen(s) > (int)(s2 - s)) {
7832 dgap_err("bad number for major number");
7835 DPR_INIT(("Adding CMAJOR (%s) to config...\n", s));
7838 case ALTPIN: /* altpin setting */
7839 if (dgap_checknode(p))
7841 if ( (p->next = dgap_newnode(ANODE)) == NULL ) {
7842 dgap_err("out of memory");
7846 s = dgap_getword(in);
7848 dgap_err("unexpected end of file");
7851 p->u.altpin = simple_strtol(s, &s2, 0);
7852 if ((int)strlen(s) > (int)(s2 - s)) {
7853 dgap_err("bad number for altpin");
7856 DPR_INIT(("Adding ALTPIN (%s) to config...\n", s));
7859 case USEINTR: /* enable interrupt setting */
7860 if (dgap_checknode(p))
7862 if ( (p->next = dgap_newnode(INTRNODE)) == NULL ) {
7863 dgap_err("out of memory");
7867 s = dgap_getword(in);
7869 dgap_err("unexpected end of file");
7872 p->u.useintr = simple_strtol(s, &s2, 0);
7873 if ((int)strlen(s) > (int)(s2 - s)) {
7874 dgap_err("bad number for useintr");
7877 DPR_INIT(("Adding USEINTR (%s) to config...\n", s));
7880 case TTSIZ: /* size of tty structure */
7881 if (dgap_checknode(p))
7883 if ( (p->next = dgap_newnode(TSNODE)) == NULL ) {
7884 dgap_err("out of memory");
7888 s = dgap_getword(in);
7890 dgap_err("unexpected end of file");
7893 p->u.ttysize = simple_strtol(s, &s2, 0);
7894 if ((int)strlen(s) > (int)(s2 - s)) {
7895 dgap_err("bad number for ttysize");
7898 DPR_INIT(("Adding TTSIZ (%s) to config...\n", s));
7901 case CHSIZ: /* channel structure size */
7902 if (dgap_checknode(p))
7904 if ( (p->next = dgap_newnode(CSNODE)) == NULL ) {
7905 dgap_err("out of memory");
7909 s = dgap_getword(in);
7911 dgap_err("unexpected end of file");
7914 p->u.chsize = simple_strtol(s, &s2, 0);
7915 if ((int)strlen(s) > (int)(s2 - s)) {
7916 dgap_err("bad number for chsize");
7919 DPR_INIT(("Adding CHSIZE (%s) to config...\n", s));
7922 case BSSIZ: /* board structure size */
7923 if (dgap_checknode(p))
7925 if ( (p->next = dgap_newnode(BSNODE)) == NULL ) {
7926 dgap_err("out of memory");
7930 s = dgap_getword(in);
7932 dgap_err("unexpected end of file");
7935 p->u.bssize = simple_strtol(s, &s2, 0);
7936 if ((int)strlen(s) > (int)(s2 - s)) {
7937 dgap_err("bad number for bssize");
7940 DPR_INIT(("Adding BSSIZ (%s) to config...\n", s));
7943 case UNTSIZ: /* sched structure size */
7944 if (dgap_checknode(p))
7946 if ( (p->next = dgap_newnode(USNODE)) == NULL ) {
7947 dgap_err("out of memory");
7951 s = dgap_getword(in);
7953 dgap_err("unexpected end of file");
7956 p->u.unsize = simple_strtol(s, &s2, 0);
7957 if ((int)strlen(s) > (int)(s2 - s)) {
7958 dgap_err("bad number for schedsize");
7961 DPR_INIT(("Adding UNTSIZ (%s) to config...\n", s));
7964 case F2SIZ: /* f2200 structure size */
7965 if (dgap_checknode(p))
7967 if ( (p->next = dgap_newnode(FSNODE)) == NULL ) {
7968 dgap_err("out of memory");
7972 s = dgap_getword(in);
7974 dgap_err("unexpected end of file");
7977 p->u.f2size = simple_strtol(s, &s2, 0);
7978 if ((int)strlen(s) > (int)(s2 - s)) {
7979 dgap_err("bad number for f2200size");
7982 DPR_INIT(("Adding F2SIZ (%s) to config...\n", s));
7985 case VPSIZ: /* vpix structure size */
7986 if (dgap_checknode(p))
7988 if ( (p->next = dgap_newnode(VSNODE)) == NULL ) {
7989 dgap_err("out of memory");
7993 s = dgap_getword(in);
7995 dgap_err("unexpected end of file");
7998 p->u.vpixsize = simple_strtol(s, &s2, 0);
7999 if ((int)strlen(s) > (int)(s2 - s)) {
8000 dgap_err("bad number for vpixsize");
8003 DPR_INIT(("Adding VPSIZ (%s) to config...\n", s));
8011 * dgap_sindex: much like index(), but it looks for a match of any character in
8012 * the group, and returns that position. If the first character is a ^, then
8013 * this will match the first occurrence not in that group.
8015 static char *dgap_sindex (char *string, char *group)
8019 if (!string || !group)
8020 return (char *) NULL;
8022 if (*group == '^') {
8024 for (; *string; string++) {
8025 for (ptr = group; *ptr; ptr++) {
8026 if (*ptr == *string)
8034 for (; *string; string++) {
8035 for (ptr = group; *ptr; ptr++) {
8036 if (*ptr == *string)
8042 return (char *) NULL;
8047 * Get a token from the input file; return 0 if end of file is reached
8049 static int dgap_gettok(char **in, struct cnode *p)
8054 if (strstr(dgap_cword, "boar")) {
8055 w = dgap_getword(in);
8056 snprintf(dgap_cword, MAXCWORD, "%s", w);
8057 for (t = dgap_tlist; t->token != 0; t++) {
8058 if ( !strcmp(w, t->string)) {
8062 dgap_err("board !!type not specified");
8066 while ( (w = dgap_getword(in)) != NULL ) {
8067 snprintf(dgap_cword, MAXCWORD, "%s", w);
8068 for (t = dgap_tlist; t->token != 0; t++) {
8069 if ( !strcmp(w, t->string) )
8079 * get a word from the input stream, also keep track of current line number.
8080 * words are separated by whitespace.
8082 static char *dgap_getword(char **in)
8084 char *ret_ptr = *in;
8086 char *ptr = dgap_sindex(*in, " \t\n");
8088 /* If no word found, return null */
8092 /* Mark new location for our buffer */
8096 /* Eat any extra spaces/tabs/newlines that might be present */
8097 while (*in && **in && ((**in == ' ') || (**in == '\t') || (**in == '\n'))) {
8107 * print an error message, giving the line number in the file where
8108 * the error occurred.
8110 static void dgap_err(char *s)
8112 printk("DGAP: parse: %s\n", s);
8117 * allocate a new configuration node of type t
8119 static struct cnode *dgap_newnode(int t)
8123 n = kmalloc(sizeof(struct cnode), GFP_ATOMIC);
8125 memset((char *)n, 0, sizeof(struct cnode));
8133 * dgap_checknode: see if all the necessary info has been supplied for a node
8134 * before creating the next node.
8136 static int dgap_checknode(struct cnode *p)
8140 if (p->u.board.v_type == 0) {
8141 dgap_err("board type !not specified");
8148 if (p->u.line.v_speed == 0) {
8149 dgap_err("line speed not specified");
8155 if (p->u.conc.v_type == 0) {
8156 dgap_err("concentrator type not specified");
8159 if (p->u.conc.v_speed == 0) {
8160 dgap_err("concentrator line speed not specified");
8163 if (p->u.conc.v_nport == 0) {
8164 dgap_err("number of ports on concentrator not specified");
8167 if (p->u.conc.v_id == 0) {
8168 dgap_err("concentrator id letter not specified");
8174 if (p->u.module.v_type == 0) {
8175 dgap_err("EBI module type not specified");
8178 if (p->u.module.v_nport == 0) {
8179 dgap_err("number of ports on EBI module not specified");
8182 if (p->u.module.v_id == 0) {
8183 dgap_err("EBI module id letter not specified");
8192 * save a string somewhere
8194 static char *dgap_savestring(char *s)
8197 if ( (p = kmalloc(strlen(s) + 1, GFP_ATOMIC) ) != NULL) {
8205 * Given a board pointer, returns whether we should use interrupts or not.
8207 uint dgap_config_get_useintr(struct board_t *bd)
8209 struct cnode *p = NULL;
8214 for (p = bd->bd_config; p; p = p->next) {
8218 * check for pcxr types.
8220 return p->u.useintr;
8226 /* If not found, then don't turn on interrupts. */
8232 * Given a board pointer, returns whether we turn on altpin or not.
8234 uint dgap_config_get_altpin(struct board_t *bd)
8236 struct cnode *p = NULL;
8241 for (p = bd->bd_config; p; p = p->next) {
8245 * check for pcxr types.
8253 /* If not found, then don't turn on interrupts. */
8260 * Given a specific type of board, if found, detached link and
8261 * returns the first occurrence in the list.
8263 struct cnode *dgap_find_config(int type, int bus, int slot)
8265 struct cnode *p, *prev = NULL, *prev2 = NULL, *found = NULL;
8269 while (p->next != NULL) {
8273 if (p->type == BNODE) {
8275 if (p->u.board.type == type) {
8277 if (p->u.board.v_pcibus && p->u.board.pcibus != bus) {
8278 DPR(("Found matching board, but wrong bus position. System says bus %d, we want bus %ld\n",
8279 bus, p->u.board.pcibus));
8282 if (p->u.board.v_pcislot && p->u.board.pcislot != slot) {
8283 DPR_INIT(("Found matching board, but wrong slot position. System says slot %d, we want slot %ld\n",
8284 slot, p->u.board.pcislot));
8288 DPR_INIT(("Matched type in config file\n"));
8292 * Keep walking thru the list till we find the next board.
8294 while (p->next != NULL) {
8297 if (p->type == BNODE) {
8300 * Mark the end of our 1 board chain of configs.
8305 * Link the "next" board to the previous board,
8306 * effectively "unlinking" our board from the main config.
8314 * It must be the last board in the list.
8325 * Given a board pointer, walks the config link, counting up
8326 * all ports user specified should be on the board.
8327 * (This does NOT mean they are all actually present right now tho)
8329 uint dgap_config_get_number_of_ports(struct board_t *bd)
8332 struct cnode *p = NULL;
8337 for (p = bd->bd_config; p; p = p->next) {
8342 * check for pcxr types.
8344 if (p->u.board.type > EPCFE)
8345 count += p->u.board.nport;
8348 count += p->u.conc.nport;
8351 count += p->u.module.nport;
8358 char *dgap_create_config_string(struct board_t *bd, char *string)
8361 struct cnode *p = NULL;
8362 struct cnode *q = NULL;
8370 for (p = bd->bd_config; p; p = p->next) {
8376 *ptr = p->u.line.speed;
8381 * Because the EPC/con concentrators can have EM modules
8382 * hanging off of them, we have to walk ahead in the list
8383 * and keep adding the number of ports on each EM to the config.
8386 speed = p->u.conc.speed;
8388 if ((q != NULL) && (q->type == MNODE) ) {
8389 *ptr = (p->u.conc.nport + 0x80);
8392 while ((q->next != NULL) && (q->next->type) == MNODE) {
8393 *ptr = (q->u.module.nport + 0x80);
8398 *ptr = q->u.module.nport;
8401 *ptr = p->u.conc.nport;
8417 char *dgap_get_config_letters(struct board_t *bd, char *string)
8421 struct cnode *cptr = NULL;
8423 int left = MAXTTYNAMELEN;
8429 for (cptr = bd->bd_config; cptr; cptr = cptr->next) {
8431 if ((cptr->type == BNODE) &&
8432 ((cptr->u.board.type == APORT2_920P) || (cptr->u.board.type == APORT4_920P) ||
8433 (cptr->u.board.type == APORT8_920P) || (cptr->u.board.type == PAPORT4) ||
8434 (cptr->u.board.type == PAPORT8))) {
8439 if (cptr->type == TNODE && found == TRUE) {
8441 if (strstr(cptr->u.ttyname, "tty")) {
8442 ptr1 = cptr->u.ttyname;
8446 ptr1 = cptr->u.ttyname;
8449 len = snprintf(ptr, left, "%s", ptr1);
8457 if (cptr->type == CNODE) {
8458 if (cptr->u.conc.id) {
8459 len = snprintf(ptr, left, "%s", cptr->u.conc.id);
8467 if (cptr->type == MNODE) {
8468 if (cptr->u.module.id) {
8469 len = snprintf(ptr, left, "%s", cptr->u.module.id);