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"
54 #include "dgap_fep5.h"
55 #include "dgap_conf.h"
56 #include "dgap_parse.h"
57 #include "dgap_sysfs.h"
58 #include "dgap_types.h"
60 #define init_MUTEX(sem) sema_init(sem, 1)
61 #define DECLARE_MUTEX(name) \
62 struct semaphore name = __SEMAPHORE_INITIALIZER(name, 1)
64 MODULE_LICENSE("GPL");
65 MODULE_AUTHOR("Digi International, http://www.digi.com");
66 MODULE_DESCRIPTION("Driver for the Digi International EPCA PCI based product line");
67 MODULE_SUPPORTED_DEVICE("dgap");
70 * insmod command line overrideable parameters
72 * NOTE: we use a set of macros to create the variables, which allows
73 * us to specify the variable type, name, initial value, and description.
75 PARM_INT(debug, 0x00, 0644, "Driver debugging level");
76 PARM_INT(rawreadok, 1, 0644, "Bypass flip buffers on input");
77 PARM_INT(trcbuf_size, 0x100000, 0644, "Debugging trace buffer size.");
80 /**************************************************************************
82 * protos for this file
86 static int dgap_start(void);
87 static void dgap_init_globals(void);
88 static int dgap_found_board(struct pci_dev *pdev, int id);
89 static void dgap_cleanup_board(struct board_t *brd);
90 static void dgap_poll_handler(ulong dummy);
91 static int dgap_init_pci(void);
92 static int dgap_init_one(struct pci_dev *pdev, const struct pci_device_id *ent);
93 static void dgap_remove_one(struct pci_dev *dev);
94 static int dgap_probe1(struct pci_dev *pdev, int card_type);
95 static void dgap_mbuf(struct board_t *brd, const char *fmt, ...);
96 static int dgap_do_remap(struct board_t *brd);
97 static irqreturn_t dgap_intr(int irq, void *voidbrd);
99 /* Our function prototypes */
100 static int dgap_tty_open(struct tty_struct *tty, struct file *file);
101 static void dgap_tty_close(struct tty_struct *tty, struct file *file);
102 static int dgap_block_til_ready(struct tty_struct *tty, struct file *file, struct channel_t *ch);
103 static int dgap_tty_ioctl(struct tty_struct *tty, unsigned int cmd, unsigned long arg);
104 static int dgap_tty_digigeta(struct tty_struct *tty, struct digi_t __user *retinfo);
105 static int dgap_tty_digiseta(struct tty_struct *tty, struct digi_t __user *new_info);
106 static int dgap_tty_digigetedelay(struct tty_struct *tty, int __user *retinfo);
107 static int dgap_tty_digisetedelay(struct tty_struct *tty, int __user *new_info);
108 static int dgap_tty_write_room(struct tty_struct* tty);
109 static int dgap_tty_chars_in_buffer(struct tty_struct* tty);
110 static void dgap_tty_start(struct tty_struct *tty);
111 static void dgap_tty_stop(struct tty_struct *tty);
112 static void dgap_tty_throttle(struct tty_struct *tty);
113 static void dgap_tty_unthrottle(struct tty_struct *tty);
114 static void dgap_tty_flush_chars(struct tty_struct *tty);
115 static void dgap_tty_flush_buffer(struct tty_struct *tty);
116 static void dgap_tty_hangup(struct tty_struct *tty);
117 static int dgap_wait_for_drain(struct tty_struct *tty);
118 static int dgap_set_modem_info(struct tty_struct *tty, unsigned int command, unsigned int __user *value);
119 static int dgap_get_modem_info(struct channel_t *ch, unsigned int __user *value);
120 static int dgap_tty_digisetcustombaud(struct tty_struct *tty, int __user *new_info);
121 static int dgap_tty_digigetcustombaud(struct tty_struct *tty, int __user *retinfo);
122 static int dgap_tty_tiocmget(struct tty_struct *tty);
123 static int dgap_tty_tiocmset(struct tty_struct *tty, unsigned int set, unsigned int clear);
124 static int dgap_tty_send_break(struct tty_struct *tty, int msec);
125 static void dgap_tty_wait_until_sent(struct tty_struct *tty, int timeout);
126 static int dgap_tty_write(struct tty_struct *tty, const unsigned char *buf, int count);
127 static void dgap_tty_set_termios(struct tty_struct *tty, struct ktermios *old_termios);
128 static int dgap_tty_put_char(struct tty_struct *tty, unsigned char c);
129 static void dgap_tty_send_xchar(struct tty_struct *tty, char ch);
131 int dgap_tty_register(struct board_t *brd);
132 int dgap_tty_preinit(void);
133 int dgap_tty_init(struct board_t *);
134 void dgap_tty_post_uninit(void);
135 void dgap_tty_uninit(struct board_t *);
136 void dgap_carrier(struct channel_t *ch);
137 void dgap_input(struct channel_t *ch);
140 * Our function prototypes from dgap_fep5
142 static void dgap_cmdw_ext(struct channel_t *ch, u16 cmd, u16 word, uint ncmds);
143 static int dgap_event(struct board_t *bd);
146 * Function prototypes from dgap_parse.c.
148 static int dgap_gettok(char **in, struct cnode *p);
149 static char *dgap_getword(char **in);
150 static char *dgap_savestring(char *s);
151 static struct cnode *dgap_newnode(int t);
152 static int dgap_checknode(struct cnode *p);
153 static void dgap_err(char *s);
155 /* Driver load/unload functions */
156 int dgap_init_module(void);
157 void dgap_cleanup_module(void);
159 module_init(dgap_init_module);
160 module_exit(dgap_cleanup_module);
164 * File operations permitted on Control/Management major.
166 static struct file_operations DgapBoardFops =
168 .owner = THIS_MODULE,
176 struct board_t *dgap_Board[MAXBOARDS];
177 DEFINE_SPINLOCK(dgap_global_lock);
178 ulong dgap_poll_counter;
179 char *dgap_config_buf;
180 int dgap_driver_state = DRIVER_INITIALIZED;
181 DEFINE_SPINLOCK(dgap_dl_lock);
182 wait_queue_head_t dgap_dl_wait;
184 int dgap_poll_tick = 20; /* Poll interval - 20 ms */
189 static int dgap_Major_Control_Registered = FALSE;
190 static uint dgap_driver_start = FALSE;
192 static struct class * dgap_class;
194 static struct board_t *dgap_BoardsByMajor[256];
195 static uchar *dgap_TmpWriteBuf = NULL;
196 static DECLARE_MUTEX(dgap_TmpWriteSem);
197 static uint dgap_count = 500;
202 static DEFINE_SPINLOCK(dgap_poll_lock); /* Poll scheduling lock */
203 static ulong dgap_poll_time; /* Time of next poll */
204 static uint dgap_poll_stop; /* Used to tell poller to stop */
205 static struct timer_list dgap_poll_timer;
208 static struct pci_device_id dgap_pci_tbl[] = {
209 { DIGI_VID, PCI_DEVICE_XEM_DID, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0 },
210 { DIGI_VID, PCI_DEVICE_CX_DID, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 1 },
211 { DIGI_VID, PCI_DEVICE_CX_IBM_DID, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 2 },
212 { DIGI_VID, PCI_DEVICE_EPCJ_DID, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 3 },
213 { DIGI_VID, PCI_DEVICE_920_2_DID, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 4 },
214 { DIGI_VID, PCI_DEVICE_920_4_DID, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 5 },
215 { DIGI_VID, PCI_DEVICE_920_8_DID, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 6 },
216 { DIGI_VID, PCI_DEVICE_XR_DID, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 7 },
217 { DIGI_VID, PCI_DEVICE_XRJ_DID, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 8 },
218 { DIGI_VID, PCI_DEVICE_XR_422_DID, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 9 },
219 { DIGI_VID, PCI_DEVICE_XR_IBM_DID, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 10 },
220 { DIGI_VID, PCI_DEVICE_XR_SAIP_DID, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 11 },
221 { DIGI_VID, PCI_DEVICE_XR_BULL_DID, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 12 },
222 { DIGI_VID, PCI_DEVICE_920_8_HP_DID, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 13 },
223 { DIGI_VID, PCI_DEVICE_XEM_HP_DID, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 14 },
224 {0,} /* 0 terminated list. */
226 MODULE_DEVICE_TABLE(pci, dgap_pci_tbl);
230 * A generic list of Product names, PCI Vendor ID, and PCI Device ID.
239 static struct board_id dgap_Ids[] =
241 { PPCM, PCI_DEVICE_XEM_NAME, 64, (T_PCXM | T_PCLITE | T_PCIBUS) },
242 { PCX, PCI_DEVICE_CX_NAME, 128, (T_CX | T_PCIBUS) },
243 { PCX, PCI_DEVICE_CX_IBM_NAME, 128, (T_CX | T_PCIBUS) },
244 { PEPC, PCI_DEVICE_EPCJ_NAME, 224, (T_EPC | T_PCIBUS) },
245 { APORT2_920P, PCI_DEVICE_920_2_NAME, 2, (T_PCXR | T_PCLITE | T_PCIBUS) },
246 { APORT4_920P, PCI_DEVICE_920_4_NAME, 4, (T_PCXR | T_PCLITE | T_PCIBUS) },
247 { APORT8_920P, PCI_DEVICE_920_8_NAME, 8, (T_PCXR | T_PCLITE | T_PCIBUS) },
248 { PAPORT8, PCI_DEVICE_XR_NAME, 8, (T_PCXR | T_PCLITE | T_PCIBUS) },
249 { PAPORT8, PCI_DEVICE_XRJ_NAME, 8, (T_PCXR | T_PCLITE | T_PCIBUS) },
250 { PAPORT8, PCI_DEVICE_XR_422_NAME, 8, (T_PCXR | T_PCLITE | T_PCIBUS) },
251 { PAPORT8, PCI_DEVICE_XR_IBM_NAME, 8, (T_PCXR | T_PCLITE | T_PCIBUS) },
252 { PAPORT8, PCI_DEVICE_XR_SAIP_NAME, 8, (T_PCXR | T_PCLITE | T_PCIBUS) },
253 { PAPORT8, PCI_DEVICE_XR_BULL_NAME, 8, (T_PCXR | T_PCLITE | T_PCIBUS) },
254 { APORT8_920P, PCI_DEVICE_920_8_HP_NAME, 8, (T_PCXR | T_PCLITE | T_PCIBUS) },
255 { PPCM, PCI_DEVICE_XEM_HP_NAME, 64, (T_PCXM | T_PCLITE | T_PCIBUS) },
256 {0,} /* 0 terminated list. */
259 static struct pci_driver dgap_driver = {
261 .probe = dgap_init_one,
262 .id_table = dgap_pci_tbl,
263 .remove = dgap_remove_one,
267 char *dgap_state_text[] = {
269 "Configuration for board not found.\n\t\t\tRun mpi to configure board.",
275 "Need Device Creation",
276 "Requested Device Creation",
277 "Finished Device Creation",
281 "Finished BIOS Load",
286 "Requested PROC creation",
287 "Finished PROC creation",
291 char *dgap_driver_state_text[] = {
292 "Driver Initialized",
293 "Driver needs configuration load.",
294 "Driver requested configuration from download daemon.",
299 * Default transparent print information.
301 static struct digi_t dgap_digi_init = {
302 .digi_flags = DIGI_COOK, /* Flags */
303 .digi_maxcps = 100, /* Max CPS */
304 .digi_maxchar = 50, /* Max chars in print queue */
305 .digi_bufsize = 100, /* Printer buffer size */
306 .digi_onlen = 4, /* size of printer on string */
307 .digi_offlen = 4, /* size of printer off string */
308 .digi_onstr = "\033[5i", /* ANSI printer on string ] */
309 .digi_offstr = "\033[4i", /* ANSI printer off string ] */
310 .digi_term = "ansi" /* default terminal type */
315 * Define a local default termios struct. All ports will be created
316 * with this termios initially.
318 * This defines a raw port at 9600 baud, 8 data bits, no parity,
322 static struct ktermios DgapDefaultTermios =
324 .c_iflag = (DEFAULT_IFLAGS), /* iflags */
325 .c_oflag = (DEFAULT_OFLAGS), /* oflags */
326 .c_cflag = (DEFAULT_CFLAGS), /* cflags */
327 .c_lflag = (DEFAULT_LFLAGS), /* lflags */
332 static const struct tty_operations dgap_tty_ops = {
333 .open = dgap_tty_open,
334 .close = dgap_tty_close,
335 .write = dgap_tty_write,
336 .write_room = dgap_tty_write_room,
337 .flush_buffer = dgap_tty_flush_buffer,
338 .chars_in_buffer = dgap_tty_chars_in_buffer,
339 .flush_chars = dgap_tty_flush_chars,
340 .ioctl = dgap_tty_ioctl,
341 .set_termios = dgap_tty_set_termios,
342 .stop = dgap_tty_stop,
343 .start = dgap_tty_start,
344 .throttle = dgap_tty_throttle,
345 .unthrottle = dgap_tty_unthrottle,
346 .hangup = dgap_tty_hangup,
347 .put_char = dgap_tty_put_char,
348 .tiocmget = dgap_tty_tiocmget,
349 .tiocmset = dgap_tty_tiocmset,
350 .break_ctl = dgap_tty_send_break,
351 .wait_until_sent = dgap_tty_wait_until_sent,
352 .send_xchar = dgap_tty_send_xchar
356 * Our needed internal static variables from dgap_parse.c
358 static struct cnode dgap_head;
360 static char dgap_cword[MAXCWORD];
367 static struct toklist dgap_tlist[] = {
368 { BEGIN, "config_begin" },
369 { END, "config_end" },
371 { PCX, "Digi_AccelePort_C/X_PCI" }, /* C/X_PCI */
372 { PEPC, "Digi_AccelePort_EPC/X_PCI" }, /* EPC/X_PCI */
373 { PPCM, "Digi_AccelePort_Xem_PCI" }, /* PCI/Xem */
374 { APORT2_920P, "Digi_AccelePort_2r_920_PCI" },
375 { APORT4_920P, "Digi_AccelePort_4r_920_PCI" },
376 { APORT8_920P, "Digi_AccelePort_8r_920_PCI" },
377 { PAPORT4, "Digi_AccelePort_4r_PCI(EIA-232/RS-422)" },
378 { PAPORT8, "Digi_AccelePort_8r_PCI(EIA-232/RS-422)" },
380 { PCIINFO, "pciinfo" },
383 { CONC, "concentrator" },
393 { CONNECT, "connect" },
394 { METHOD, "method" },
395 { STATUS, "status" },
396 { CUSTOM, "Custom" },
402 { NPORTS, "nports" },
407 { ALTPIN, "altpin" },
408 { USEINTR, "useintr" },
409 { TTSIZ, "ttysize" },
411 { BSSIZ, "boardsize" },
412 { UNTSIZ, "schedsize" },
413 { F2SIZ, "f2200size" },
414 { VPSIZ, "vpixsize" },
418 /************************************************************************
420 * Driver load/unload functions
422 ************************************************************************/
427 * Module load. This is where it all starts.
429 int dgap_init_module(void)
433 APR(("%s, Digi International Part Number %s\n", DG_NAME, DG_PART));
436 * Initialize global stuff
445 * Find and configure all the cards
447 rc = dgap_init_pci();
450 * If something went wrong in the scan, bail out of driver.
453 /* Only unregister the pci driver if it was actually registered. */
455 pci_unregister_driver(&dgap_driver);
457 printk("WARNING: dgap driver load failed. No DGAP boards found.\n");
459 dgap_cleanup_module();
462 dgap_create_driver_sysfiles(&dgap_driver);
465 DPR_INIT(("Finished init_module. Returning %d\n", rc));
473 static int dgap_start(void)
478 if (dgap_driver_start == FALSE) {
480 dgap_driver_start = TRUE;
482 /* make sure that the globals are init'd before we do anything else */
487 APR(("For the tools package or updated drivers please visit http://www.digi.com\n"));
490 * Register our base character device into the kernel.
491 * This allows the download daemon to connect to the downld device
492 * before any of the boards are init'ed.
494 if (!dgap_Major_Control_Registered) {
496 * Register management/dpa devices
498 rc = register_chrdev(DIGI_DGAP_MAJOR, "dgap", &DgapBoardFops);
500 APR(("Can't register dgap driver device (%d)\n", rc));
504 dgap_class = class_create(THIS_MODULE, "dgap_mgmt");
505 device_create(dgap_class, NULL,
506 MKDEV(DIGI_DGAP_MAJOR, 0),
508 device_create(dgap_class, NULL,
509 MKDEV(DIGI_DGAP_MAJOR, 1),
510 NULL, "dgap_downld");
511 dgap_Major_Control_Registered = TRUE;
515 * Init any global tty stuff.
517 rc = dgap_tty_preinit();
520 APR(("tty preinit - not enough memory (%d)\n", rc));
524 /* Start the poller */
525 DGAP_LOCK(dgap_poll_lock, flags);
526 init_timer(&dgap_poll_timer);
527 dgap_poll_timer.function = dgap_poll_handler;
528 dgap_poll_timer.data = 0;
529 dgap_poll_time = jiffies + dgap_jiffies_from_ms(dgap_poll_tick);
530 dgap_poll_timer.expires = dgap_poll_time;
531 DGAP_UNLOCK(dgap_poll_lock, flags);
533 add_timer(&dgap_poll_timer);
535 dgap_driver_state = DRIVER_NEED_CONFIG_LOAD;
543 * Register pci driver, and return how many boards we have.
545 static int dgap_init_pci(void)
547 return pci_register_driver(&dgap_driver);
551 /* returns count (>= 0), or negative on error */
552 static int dgap_init_one(struct pci_dev *pdev, const struct pci_device_id *ent)
556 /* wake up and enable device */
557 rc = pci_enable_device(pdev);
562 rc = dgap_probe1(pdev, ent->driver_data);
565 DPR_INIT(("Incrementing numboards to %d\n", dgap_NumBoards));
572 static int dgap_probe1(struct pci_dev *pdev, int card_type)
574 return dgap_found_board(pdev, card_type);
578 static void dgap_remove_one(struct pci_dev *dev)
585 * dgap_cleanup_module()
587 * Module unload. This is where it all ends.
589 void dgap_cleanup_module(void)
594 DGAP_LOCK(dgap_poll_lock, lock_flags);
596 DGAP_UNLOCK(dgap_poll_lock, lock_flags);
598 /* Turn off poller right away. */
599 del_timer_sync( &dgap_poll_timer);
601 dgap_remove_driver_sysfiles(&dgap_driver);
604 if (dgap_Major_Control_Registered) {
605 device_destroy(dgap_class, MKDEV(DIGI_DGAP_MAJOR, 0));
606 device_destroy(dgap_class, MKDEV(DIGI_DGAP_MAJOR, 1));
607 class_destroy(dgap_class);
608 unregister_chrdev(DIGI_DGAP_MAJOR, "dgap");
611 kfree(dgap_config_buf);
613 for (i = 0; i < dgap_NumBoards; ++i) {
614 dgap_remove_ports_sysfiles(dgap_Board[i]);
615 dgap_tty_uninit(dgap_Board[i]);
616 dgap_cleanup_board(dgap_Board[i]);
619 dgap_tty_post_uninit();
621 #if defined(DGAP_TRACER)
622 /* last thing, make sure we release the tracebuffer */
626 pci_unregister_driver(&dgap_driver);
631 * dgap_cleanup_board()
633 * Free all the memory associated with a board
635 static void dgap_cleanup_board(struct board_t *brd)
639 if(!brd || brd->magic != DGAP_BOARD_MAGIC)
642 if (brd->intr_used && brd->irq)
643 free_irq(brd->irq, brd);
645 tasklet_kill(&brd->helper_tasklet);
647 if (brd->re_map_port) {
648 release_mem_region(brd->membase + 0x200000, 0x200000);
649 iounmap(brd->re_map_port);
650 brd->re_map_port = NULL;
653 if (brd->re_map_membase) {
654 release_mem_region(brd->membase, 0x200000);
655 iounmap(brd->re_map_membase);
656 brd->re_map_membase = NULL;
659 if (brd->msgbuf_head) {
662 DGAP_LOCK(dgap_global_lock, flags);
664 printk("%s", brd->msgbuf_head);
665 kfree(brd->msgbuf_head);
666 brd->msgbuf_head = NULL;
667 DGAP_UNLOCK(dgap_global_lock, flags);
670 /* Free all allocated channels structs */
671 for (i = 0; i < MAXPORTS ; i++) {
672 if (brd->channels[i]) {
673 kfree(brd->channels[i]);
674 brd->channels[i] = NULL;
679 kfree(brd->flipflagbuf);
681 dgap_Board[brd->boardnum] = NULL;
690 * A board has been found, init it.
692 static int dgap_found_board(struct pci_dev *pdev, int id)
695 unsigned int pci_irq;
699 /* get the board structure and prep it */
700 brd = dgap_Board[dgap_NumBoards] =
701 (struct board_t *) kzalloc(sizeof(struct board_t), GFP_KERNEL);
703 APR(("memory allocation for board structure failed\n"));
707 /* make a temporary message buffer for the boot messages */
708 brd->msgbuf = brd->msgbuf_head =
709 (char *) kzalloc(sizeof(char) * 8192, GFP_KERNEL);
712 APR(("memory allocation for board msgbuf failed\n"));
716 /* store the info for the board we've found */
717 brd->magic = DGAP_BOARD_MAGIC;
718 brd->boardnum = dgap_NumBoards;
720 brd->vendor = dgap_pci_tbl[id].vendor;
721 brd->device = dgap_pci_tbl[id].device;
723 brd->pci_bus = pdev->bus->number;
724 brd->pci_slot = PCI_SLOT(pdev->devfn);
725 brd->name = dgap_Ids[id].name;
726 brd->maxports = dgap_Ids[id].maxports;
727 brd->type = dgap_Ids[id].config_type;
728 brd->dpatype = dgap_Ids[id].dpatype;
729 brd->dpastatus = BD_NOFEP;
730 init_waitqueue_head(&brd->state_wait);
732 DGAP_SPINLOCK_INIT(brd->bd_lock);
734 brd->state = BOARD_FOUND;
736 brd->inhibit_poller = FALSE;
737 brd->wait_for_bios = 0;
738 brd->wait_for_fep = 0;
740 for (i = 0; i < MAXPORTS; i++) {
741 brd->channels[i] = NULL;
744 /* store which card & revision we have */
745 pci_read_config_word(pdev, PCI_SUBSYSTEM_VENDOR_ID, &brd->subvendor);
746 pci_read_config_word(pdev, PCI_SUBSYSTEM_ID, &brd->subdevice);
747 pci_read_config_byte(pdev, PCI_REVISION_ID, &brd->rev);
752 /* get the PCI Base Address Registers */
754 /* Xr Jupiter and EPC use BAR 2 */
755 if (brd->device == PCI_DEVICE_XRJ_DID || brd->device == PCI_DEVICE_EPCJ_DID) {
756 brd->membase = pci_resource_start(pdev, 2);
757 brd->membase_end = pci_resource_end(pdev, 2);
759 /* Everyone else uses BAR 0 */
761 brd->membase = pci_resource_start(pdev, 0);
762 brd->membase_end = pci_resource_end(pdev, 0);
766 APR(("card has no PCI IO resources, failing board.\n"));
770 if (brd->membase & 1)
776 * On the PCI boards, there is no IO space allocated
777 * The I/O registers will be in the first 3 bytes of the
778 * upper 2MB of the 4MB memory space. The board memory
779 * will be mapped into the low 2MB of the 4MB memory space
781 brd->port = brd->membase + PCI_IO_OFFSET;
782 brd->port_end = brd->port + PCI_IO_SIZE;
786 * Special initialization for non-PLX boards
788 if (brd->device != PCI_DEVICE_XRJ_DID && brd->device != PCI_DEVICE_EPCJ_DID) {
791 pci_write_config_byte(pdev, 0x40, 0);
792 pci_write_config_byte(pdev, 0x46, 0);
794 /* Limit burst length to 2 doubleword transactions */
795 pci_write_config_byte(pdev, 0x42, 1);
798 * Enable IO and mem if not already done.
799 * This was needed for support on Itanium.
801 pci_read_config_word(pdev, PCI_COMMAND, &cmd);
802 cmd |= (PCI_COMMAND_IO | PCI_COMMAND_MEMORY);
803 pci_write_config_word(pdev, PCI_COMMAND, cmd);
806 /* init our poll helper tasklet */
807 tasklet_init(&brd->helper_tasklet, dgap_poll_tasklet, (unsigned long) brd);
809 /* Log the information about the board */
810 dgap_mbuf(brd, DRVSTR": board %d: %s (rev %d), irq %d\n",
811 dgap_NumBoards, brd->name, brd->rev, brd->irq);
813 DPR_INIT(("dgap_scan(%d) - printing out the msgbuf\n", i));
814 DGAP_LOCK(dgap_global_lock, flags);
816 printk("%s", brd->msgbuf_head);
817 kfree(brd->msgbuf_head);
818 brd->msgbuf_head = NULL;
819 DGAP_UNLOCK(dgap_global_lock, flags);
821 i = dgap_do_remap(brd);
823 brd->state = BOARD_FAILED;
825 brd->state = NEED_RESET;
831 int dgap_finalize_board_init(struct board_t *brd) {
835 DPR_INIT(("dgap_finalize_board_init() - start\n"));
837 if (!brd || brd->magic != DGAP_BOARD_MAGIC)
840 DPR_INIT(("dgap_finalize_board_init() - start #2\n"));
842 brd->use_interrupts = dgap_config_get_useintr(brd);
845 * Set up our interrupt handler if we are set to do interrupts.
847 if (brd->use_interrupts && brd->irq) {
849 rc = request_irq(brd->irq, dgap_intr, IRQF_SHARED, "DGAP", brd);
852 dgap_mbuf(brd, DRVSTR": Failed to hook IRQ %d. Board will work in poll mode.\n",
869 static int dgap_do_remap(struct board_t *brd)
871 if (!brd || brd->magic != DGAP_BOARD_MAGIC)
874 if (!request_mem_region(brd->membase, 0x200000, "dgap")) {
875 APR(("dgap: mem_region %lx already in use.\n", brd->membase));
879 if (!request_mem_region(brd->membase + PCI_IO_OFFSET, 0x200000, "dgap")) {
880 APR(("dgap: mem_region IO %lx already in use.\n",
881 brd->membase + PCI_IO_OFFSET));
882 release_mem_region(brd->membase, 0x200000);
886 brd->re_map_membase = ioremap(brd->membase, 0x200000);
887 if (!brd->re_map_membase) {
888 APR(("dgap: ioremap mem %lx cannot be mapped.\n", brd->membase));
889 release_mem_region(brd->membase, 0x200000);
890 release_mem_region(brd->membase + PCI_IO_OFFSET, 0x200000);
894 brd->re_map_port = ioremap((brd->membase + PCI_IO_OFFSET), 0x200000);
895 if (!brd->re_map_port) {
896 release_mem_region(brd->membase, 0x200000);
897 release_mem_region(brd->membase + PCI_IO_OFFSET, 0x200000);
898 iounmap(brd->re_map_membase);
899 APR(("dgap: ioremap IO mem %lx cannot be mapped.\n",
900 brd->membase + PCI_IO_OFFSET));
904 DPR_INIT(("remapped io: 0x%p remapped mem: 0x%p\n",
905 brd->re_map_port, brd->re_map_membase));
910 /*****************************************************************************
930 * As each timer expires, it determines (a) whether the "transmit"
931 * waiter needs to be woken up, and (b) whether the poller needs to
934 ******************************************************************************/
936 static void dgap_poll_handler(ulong dummy)
940 unsigned long lock_flags;
941 unsigned long lock_flags2;
948 * If driver needs the config file still,
949 * keep trying to wake up the downloader to
952 if (dgap_driver_state == DRIVER_NEED_CONFIG_LOAD) {
954 * Signal downloader, its got some work to do.
956 DGAP_LOCK(dgap_dl_lock, lock_flags2);
957 if (dgap_dl_action != 1) {
959 wake_up_interruptible(&dgap_dl_wait);
961 DGAP_UNLOCK(dgap_dl_lock, lock_flags2);
962 goto schedule_poller;
965 * Do not start the board state machine until
966 * driver tells us its up and running, and has
967 * everything it needs.
969 else if (dgap_driver_state != DRIVER_READY) {
970 goto schedule_poller;
974 * If we have just 1 board, or the system is not SMP,
975 * then use the typical old style poller.
976 * Otherwise, use our new tasklet based poller, which should
977 * speed things up for multiple boards.
979 if ( (dgap_NumBoards == 1) || (num_online_cpus() <= 1) ) {
980 for (i = 0; i < dgap_NumBoards; i++) {
984 if (brd->state == BOARD_FAILED) {
987 if (!brd->intr_running) {
988 /* Call the real board poller directly */
989 dgap_poll_tasklet((unsigned long) brd);
994 /* Go thru each board, kicking off a tasklet for each if needed */
995 for (i = 0; i < dgap_NumBoards; i++) {
999 * Attempt to grab the board lock.
1001 * If we can't get it, no big deal, the next poll will get it.
1002 * Basically, I just really don't want to spin in here, because I want
1003 * to kick off my tasklets as fast as I can, and then get out the poller.
1005 if (!spin_trylock(&brd->bd_lock)) {
1009 /* If board is in a failed state, don't bother scheduling a tasklet */
1010 if (brd->state == BOARD_FAILED) {
1011 spin_unlock(&brd->bd_lock);
1015 /* Schedule a poll helper task */
1016 if (!brd->intr_running) {
1017 tasklet_schedule(&brd->helper_tasklet);
1021 * Can't do DGAP_UNLOCK here, as we don't have
1022 * lock_flags because we did a trylock above.
1024 spin_unlock(&brd->bd_lock);
1031 * Schedule ourself back at the nominal wakeup interval.
1033 DGAP_LOCK(dgap_poll_lock, lock_flags );
1034 dgap_poll_time += dgap_jiffies_from_ms(dgap_poll_tick);
1036 new_time = dgap_poll_time - jiffies;
1038 if ((ulong) new_time >= 2 * dgap_poll_tick) {
1039 dgap_poll_time = jiffies + dgap_jiffies_from_ms(dgap_poll_tick);
1042 dgap_poll_timer.function = dgap_poll_handler;
1043 dgap_poll_timer.data = 0;
1044 dgap_poll_timer.expires = dgap_poll_time;
1045 DGAP_UNLOCK(dgap_poll_lock, lock_flags );
1047 if (!dgap_poll_stop)
1048 add_timer(&dgap_poll_timer);
1057 * Driver interrupt handler.
1059 static irqreturn_t dgap_intr(int irq, void *voidbrd)
1061 struct board_t *brd = (struct board_t *) voidbrd;
1064 APR(("Received interrupt (%d) with null board associated\n", irq));
1069 * Check to make sure its for us.
1071 if (brd->magic != DGAP_BOARD_MAGIC) {
1072 APR(("Received interrupt (%d) with a board pointer that wasn't ours!\n", irq));
1079 * Schedule tasklet to run at a better time.
1081 tasklet_schedule(&brd->helper_tasklet);
1087 * dgap_init_globals()
1089 * This is where we initialize the globals from the static insmod
1090 * configuration variables. These are declared near the head of
1093 static void dgap_init_globals(void)
1097 dgap_rawreadok = rawreadok;
1098 dgap_trcbuf_size = trcbuf_size;
1101 for (i = 0; i < MAXBOARDS; i++) {
1102 dgap_Board[i] = NULL;
1105 init_timer( &dgap_poll_timer );
1107 init_waitqueue_head(&dgap_dl_wait);
1112 /************************************************************************
1116 ************************************************************************/
1122 * Used to print to the message buffer during board init.
1124 static void dgap_mbuf(struct board_t *brd, const char *fmt, ...) {
1128 unsigned long flags;
1131 DGAP_LOCK(dgap_global_lock, flags);
1133 /* Format buf using fmt and arguments contained in ap. */
1135 i = vsnprintf(buf, sizeof(buf), fmt, ap);
1140 if (!brd || !brd->msgbuf) {
1142 DGAP_UNLOCK(dgap_global_lock, flags);
1146 length = strlen(buf) + 1;
1147 if (brd->msgbuf - brd->msgbuf_head < length)
1148 length = brd->msgbuf - brd->msgbuf_head;
1149 memcpy(brd->msgbuf, buf, length);
1150 brd->msgbuf += length;
1152 DGAP_UNLOCK(dgap_global_lock, flags);
1159 * Put the driver to sleep for x ms's
1161 * Returns 0 if timed out, !0 (showing signal) if interrupted by a signal.
1163 int dgap_ms_sleep(ulong ms)
1165 current->state = TASK_INTERRUPTIBLE;
1166 schedule_timeout((ms * HZ) / 1000);
1167 return (signal_pending(current));
1173 * dgap_ioctl_name() : Returns a text version of each ioctl value.
1175 char *dgap_ioctl_name(int cmd)
1179 case TCGETA: return("TCGETA");
1180 case TCGETS: return("TCGETS");
1181 case TCSETA: return("TCSETA");
1182 case TCSETS: return("TCSETS");
1183 case TCSETAW: return("TCSETAW");
1184 case TCSETSW: return("TCSETSW");
1185 case TCSETAF: return("TCSETAF");
1186 case TCSETSF: return("TCSETSF");
1187 case TCSBRK: return("TCSBRK");
1188 case TCXONC: return("TCXONC");
1189 case TCFLSH: return("TCFLSH");
1190 case TIOCGSID: return("TIOCGSID");
1192 case TIOCGETD: return("TIOCGETD");
1193 case TIOCSETD: return("TIOCSETD");
1194 case TIOCGWINSZ: return("TIOCGWINSZ");
1195 case TIOCSWINSZ: return("TIOCSWINSZ");
1197 case TIOCMGET: return("TIOCMGET");
1198 case TIOCMSET: return("TIOCMSET");
1199 case TIOCMBIS: return("TIOCMBIS");
1200 case TIOCMBIC: return("TIOCMBIC");
1203 case DIGI_SETA: return("DIGI_SETA");
1204 case DIGI_SETAW: return("DIGI_SETAW");
1205 case DIGI_SETAF: return("DIGI_SETAF");
1206 case DIGI_SETFLOW: return("DIGI_SETFLOW");
1207 case DIGI_SETAFLOW: return("DIGI_SETAFLOW");
1208 case DIGI_GETFLOW: return("DIGI_GETFLOW");
1209 case DIGI_GETAFLOW: return("DIGI_GETAFLOW");
1210 case DIGI_GETA: return("DIGI_GETA");
1211 case DIGI_GEDELAY: return("DIGI_GEDELAY");
1212 case DIGI_SEDELAY: return("DIGI_SEDELAY");
1213 case DIGI_GETCUSTOMBAUD: return("DIGI_GETCUSTOMBAUD");
1214 case DIGI_SETCUSTOMBAUD: return("DIGI_SETCUSTOMBAUD");
1215 case TIOCMODG: return("TIOCMODG");
1216 case TIOCMODS: return("TIOCMODS");
1217 case TIOCSDTR: return("TIOCSDTR");
1218 case TIOCCDTR: return("TIOCCDTR");
1220 default: return("unknown");
1224 /************************************************************************
1226 * TTY Initialization/Cleanup Functions
1228 ************************************************************************/
1231 * dgap_tty_preinit()
1233 * Initialize any global tty related data before we download any boards.
1235 int dgap_tty_preinit(void)
1237 unsigned long flags;
1239 DGAP_LOCK(dgap_global_lock, flags);
1242 * Allocate a buffer for doing the copy from user space to
1243 * kernel space in dgap_input(). We only use one buffer and
1244 * control access to it with a semaphore. If we are paging, we
1245 * are already in trouble so one buffer won't hurt much anyway.
1247 dgap_TmpWriteBuf = kmalloc(WRITEBUFLEN, GFP_ATOMIC);
1249 if (!dgap_TmpWriteBuf) {
1250 DGAP_UNLOCK(dgap_global_lock, flags);
1251 DPR_INIT(("unable to allocate tmp write buf"));
1255 DGAP_UNLOCK(dgap_global_lock, flags);
1261 * dgap_tty_register()
1263 * Init the tty subsystem for this board.
1265 int dgap_tty_register(struct board_t *brd)
1269 DPR_INIT(("tty_register start"));
1271 brd->SerialDriver = alloc_tty_driver(MAXPORTS);
1273 snprintf(brd->SerialName, MAXTTYNAMELEN, "tty_dgap_%d_", brd->boardnum);
1274 brd->SerialDriver->name = brd->SerialName;
1275 brd->SerialDriver->name_base = 0;
1276 brd->SerialDriver->major = 0;
1277 brd->SerialDriver->minor_start = 0;
1278 brd->SerialDriver->type = TTY_DRIVER_TYPE_SERIAL;
1279 brd->SerialDriver->subtype = SERIAL_TYPE_NORMAL;
1280 brd->SerialDriver->init_termios = DgapDefaultTermios;
1281 brd->SerialDriver->driver_name = DRVSTR;
1282 brd->SerialDriver->flags = (TTY_DRIVER_REAL_RAW | TTY_DRIVER_DYNAMIC_DEV | TTY_DRIVER_HARDWARE_BREAK);
1284 /* The kernel wants space to store pointers to tty_structs */
1285 brd->SerialDriver->ttys = kzalloc(MAXPORTS * sizeof(struct tty_struct *), GFP_KERNEL);
1286 if (!brd->SerialDriver->ttys)
1290 * Entry points for driver. Called by the kernel from
1291 * tty_io.c and n_tty.c.
1293 tty_set_operations(brd->SerialDriver, &dgap_tty_ops);
1296 * If we're doing transparent print, we have to do all of the above
1297 * again, separately so we don't get the LD confused about what major
1298 * we are when we get into the dgap_tty_open() routine.
1300 brd->PrintDriver = alloc_tty_driver(MAXPORTS);
1302 snprintf(brd->PrintName, MAXTTYNAMELEN, "pr_dgap_%d_", brd->boardnum);
1303 brd->PrintDriver->name = brd->PrintName;
1304 brd->PrintDriver->name_base = 0;
1305 brd->PrintDriver->major = 0;
1306 brd->PrintDriver->minor_start = 0;
1307 brd->PrintDriver->type = TTY_DRIVER_TYPE_SERIAL;
1308 brd->PrintDriver->subtype = SERIAL_TYPE_NORMAL;
1309 brd->PrintDriver->init_termios = DgapDefaultTermios;
1310 brd->PrintDriver->driver_name = DRVSTR;
1311 brd->PrintDriver->flags = (TTY_DRIVER_REAL_RAW | TTY_DRIVER_DYNAMIC_DEV | TTY_DRIVER_HARDWARE_BREAK);
1313 /* The kernel wants space to store pointers to tty_structs */
1314 brd->PrintDriver->ttys = kzalloc(MAXPORTS * sizeof(struct tty_struct *), GFP_KERNEL);
1315 if (!brd->PrintDriver->ttys)
1319 * Entry points for driver. Called by the kernel from
1320 * tty_io.c and n_tty.c.
1322 tty_set_operations(brd->PrintDriver, &dgap_tty_ops);
1324 if (!brd->dgap_Major_Serial_Registered) {
1325 /* Register tty devices */
1326 rc = tty_register_driver(brd->SerialDriver);
1328 APR(("Can't register tty device (%d)\n", rc));
1331 brd->dgap_Major_Serial_Registered = TRUE;
1332 dgap_BoardsByMajor[brd->SerialDriver->major] = brd;
1333 brd->dgap_Serial_Major = brd->SerialDriver->major;
1336 if (!brd->dgap_Major_TransparentPrint_Registered) {
1337 /* Register Transparent Print devices */
1338 rc = tty_register_driver(brd->PrintDriver);
1340 APR(("Can't register Transparent Print device (%d)\n", rc));
1343 brd->dgap_Major_TransparentPrint_Registered = TRUE;
1344 dgap_BoardsByMajor[brd->PrintDriver->major] = brd;
1345 brd->dgap_TransparentPrint_Major = brd->PrintDriver->major;
1348 DPR_INIT(("DGAP REGISTER TTY: MAJORS: %d %d\n", brd->SerialDriver->major,
1349 brd->PrintDriver->major));
1358 * Init the tty subsystem. Called once per board after board has been
1359 * downloaded and init'ed.
1361 int dgap_tty_init(struct board_t *brd)
1365 uint true_count = 0;
1368 struct channel_t *ch;
1375 DPR_INIT(("dgap_tty_init start\n"));
1378 * Initialize board structure elements.
1381 vaddr = brd->re_map_membase;
1382 true_count = readw((vaddr + NCHAN));
1384 brd->nasync = dgap_config_get_number_of_ports(brd);
1387 brd->nasync = brd->maxports;
1390 if (brd->nasync > brd->maxports) {
1391 brd->nasync = brd->maxports;
1394 if (true_count != brd->nasync) {
1395 if ((brd->type == PPCM) && (true_count == 64)) {
1396 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",
1397 brd->name, brd->nasync, true_count));
1399 else if ((brd->type == PPCM) && (true_count == 0)) {
1400 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",
1401 brd->name, brd->nasync, true_count));
1404 APR(("***WARNING**** %s configured for %d ports, has %d ports.\n",
1405 brd->name, brd->nasync, true_count));
1408 brd->nasync = true_count;
1410 /* If no ports, don't bother going any further */
1412 brd->state = BOARD_FAILED;
1413 brd->dpastatus = BD_NOFEP;
1419 * Allocate channel memory that might not have been allocated
1420 * when the driver was first loaded.
1422 for (i = 0; i < brd->nasync; i++) {
1423 if (!brd->channels[i]) {
1424 brd->channels[i] = kzalloc(sizeof(struct channel_t), GFP_ATOMIC);
1425 if (!brd->channels[i]) {
1426 DPR_CORE(("%s:%d Unable to allocate memory for channel struct\n",
1427 __FILE__, __LINE__));
1432 ch = brd->channels[0];
1433 vaddr = brd->re_map_membase;
1435 bs = (struct bs_t *) ((ulong) vaddr + CHANBUF);
1436 cm = (struct cm_t *) ((ulong) vaddr + CMDBUF);
1440 /* Set up channel variables */
1441 for (i = 0; i < brd->nasync; i++, ch = brd->channels[i], bs++) {
1443 if (!brd->channels[i])
1446 DGAP_SPINLOCK_INIT(ch->ch_lock);
1448 /* Store all our magic numbers */
1449 ch->magic = DGAP_CHANNEL_MAGIC;
1450 ch->ch_tun.magic = DGAP_UNIT_MAGIC;
1451 ch->ch_tun.un_type = DGAP_SERIAL;
1452 ch->ch_tun.un_ch = ch;
1453 ch->ch_tun.un_dev = i;
1455 ch->ch_pun.magic = DGAP_UNIT_MAGIC;
1456 ch->ch_pun.un_type = DGAP_PRINT;
1457 ch->ch_pun.un_ch = ch;
1458 ch->ch_pun.un_dev = i;
1460 ch->ch_vaddr = vaddr;
1465 ch->ch_digi = dgap_digi_init;
1468 * Set up digi dsr and dcd bits based on altpin flag.
1470 if (dgap_config_get_altpin(brd)) {
1473 ch->ch_digi.digi_flags |= DIGI_ALTPIN;
1477 ch->ch_dsr = DM_DSR;
1480 ch->ch_taddr = vaddr + ((ch->ch_bs->tx_seg) << 4);
1481 ch->ch_raddr = vaddr + ((ch->ch_bs->rx_seg) << 4);
1484 ch->ch_tsize = readw(&(ch->ch_bs->tx_max)) + 1;
1485 ch->ch_rsize = readw(&(ch->ch_bs->rx_max)) + 1;
1489 /* .25 second delay */
1490 ch->ch_close_delay = 250;
1493 * Set queue water marks, interrupt mask,
1494 * and general tty parameters.
1496 ch->ch_tlw = tlw = ch->ch_tsize >= 2000 ? ((ch->ch_tsize * 5) / 8) : ch->ch_tsize / 2;
1498 dgap_cmdw(ch, STLOW, tlw, 0);
1500 dgap_cmdw(ch, SRLOW, ch->ch_rsize / 2, 0);
1502 dgap_cmdw(ch, SRHIGH, 7 * ch->ch_rsize / 8, 0);
1504 ch->ch_mistat = readb(&(ch->ch_bs->m_stat));
1506 init_waitqueue_head(&ch->ch_flags_wait);
1507 init_waitqueue_head(&ch->ch_tun.un_flags_wait);
1508 init_waitqueue_head(&ch->ch_pun.un_flags_wait);
1509 init_waitqueue_head(&ch->ch_sniff_wait);
1511 /* Turn on all modem interrupts for now */
1512 modem = (DM_CD | DM_DSR | DM_CTS | DM_RI);
1513 writeb(modem, &(ch->ch_bs->m_int));
1516 * Set edelay to 0 if interrupts are turned on,
1517 * otherwise set edelay to the usual 100.
1520 writew(0, &(ch->ch_bs->edelay));
1522 writew(100, &(ch->ch_bs->edelay));
1524 writeb(1, &(ch->ch_bs->idata));
1528 DPR_INIT(("dgap_tty_init finish\n"));
1535 * dgap_tty_post_uninit()
1537 * UnInitialize any global tty related data.
1539 void dgap_tty_post_uninit(void)
1541 kfree(dgap_TmpWriteBuf);
1542 dgap_TmpWriteBuf = NULL;
1549 * Uninitialize the TTY portion of this driver. Free all memory and
1552 void dgap_tty_uninit(struct board_t *brd)
1556 if (brd->dgap_Major_Serial_Registered) {
1557 dgap_BoardsByMajor[brd->SerialDriver->major] = NULL;
1558 brd->dgap_Serial_Major = 0;
1559 for (i = 0; i < brd->nasync; i++) {
1560 dgap_remove_tty_sysfs(brd->channels[i]->ch_tun.un_sysfs);
1561 tty_unregister_device(brd->SerialDriver, i);
1563 tty_unregister_driver(brd->SerialDriver);
1564 kfree(brd->SerialDriver->ttys);
1565 brd->SerialDriver->ttys = NULL;
1566 put_tty_driver(brd->SerialDriver);
1567 brd->dgap_Major_Serial_Registered = FALSE;
1570 if (brd->dgap_Major_TransparentPrint_Registered) {
1571 dgap_BoardsByMajor[brd->PrintDriver->major] = NULL;
1572 brd->dgap_TransparentPrint_Major = 0;
1573 for (i = 0; i < brd->nasync; i++) {
1574 dgap_remove_tty_sysfs(brd->channels[i]->ch_pun.un_sysfs);
1575 tty_unregister_device(brd->PrintDriver, i);
1577 tty_unregister_driver(brd->PrintDriver);
1578 kfree(brd->PrintDriver->ttys);
1579 brd->PrintDriver->ttys = NULL;
1580 put_tty_driver(brd->PrintDriver);
1581 brd->dgap_Major_TransparentPrint_Registered = FALSE;
1586 #define TMPBUFLEN (1024)
1589 * dgap_sniff - Dump data out to the "sniff" buffer if the
1590 * proc sniff file is opened...
1592 static void dgap_sniff_nowait_nolock(struct channel_t *ch, uchar *text, uchar *buf, int len)
1600 char tmpbuf[TMPBUFLEN];
1604 /* Leave if sniff not open */
1605 if (!(ch->ch_sniff_flags & SNIFF_OPEN))
1608 do_gettimeofday(&tv);
1610 /* Create our header for data dump */
1611 p += sprintf(p, "<%ld %ld><%s><", tv.tv_sec, tv.tv_usec, text);
1612 tmpbuflen = p - tmpbuf;
1617 for (i = 0; i < len && tmpbuflen < (TMPBUFLEN - 4); i++) {
1618 p += sprintf(p, "%02x ", *buf);
1620 tmpbuflen = p - tmpbuf;
1623 if (tmpbuflen < (TMPBUFLEN - 4)) {
1625 p += sprintf(p - 1, "%s\n", ">");
1627 p += sprintf(p, "%s\n", ">");
1633 nbuf = strlen(tmpbuf);
1637 * Loop while data remains.
1639 while (nbuf > 0 && ch->ch_sniff_buf) {
1641 * Determine the amount of available space left in the
1642 * buffer. If there's none, wait until some appears.
1644 n = (ch->ch_sniff_out - ch->ch_sniff_in - 1) & SNIFF_MASK;
1647 * If there is no space left to write to in our sniff buffer,
1648 * we have no choice but to drop the data.
1649 * We *cannot* sleep here waiting for space, because this
1650 * function was probably called by the interrupt/timer routines!
1657 * Copy as much data as will fit.
1663 r = SNIFF_MAX - ch->ch_sniff_in;
1666 memcpy(ch->ch_sniff_buf + ch->ch_sniff_in, p, r);
1669 ch->ch_sniff_in = 0;
1674 memcpy(ch->ch_sniff_buf + ch->ch_sniff_in, p, n);
1676 ch->ch_sniff_in += n;
1681 * Wakeup any thread waiting for data
1683 if (ch->ch_sniff_flags & SNIFF_WAIT_DATA) {
1684 ch->ch_sniff_flags &= ~SNIFF_WAIT_DATA;
1685 wake_up_interruptible(&ch->ch_sniff_wait);
1690 * If the user sent us too much data to push into our tmpbuf,
1691 * we need to keep looping around on all the data.
1693 if (too_much_data) {
1698 } while (too_much_data);
1702 /*=======================================================================
1704 * dgap_input - Process received data.
1706 * ch - Pointer to channel structure.
1708 *=======================================================================*/
1710 void dgap_input(struct channel_t *ch)
1714 struct tty_struct *tp;
1715 struct tty_ldisc *ld;
1729 if (!ch || ch->magic != DGAP_CHANNEL_MAGIC)
1732 tp = ch->ch_tun.un_tty;
1740 if(!bd || bd->magic != DGAP_BOARD_MAGIC)
1743 DPR_READ(("dgap_input start\n"));
1745 DGAP_LOCK(bd->bd_lock, lock_flags);
1746 DGAP_LOCK(ch->ch_lock, lock_flags2);
1749 * Figure the number of characters in the buffer.
1750 * Exit immediately if none.
1753 rmask = ch->ch_rsize - 1;
1755 head = readw(&(bs->rx_head));
1757 tail = readw(&(bs->rx_tail));
1760 data_len = (head - tail) & rmask;
1762 if (data_len == 0) {
1763 writeb(1, &(bs->idata));
1764 DGAP_UNLOCK(ch->ch_lock, lock_flags2);
1765 DGAP_UNLOCK(bd->bd_lock, lock_flags);
1766 DPR_READ(("No data on port %d\n", ch->ch_portnum));
1771 * If the device is not open, or CREAD is off, flush
1772 * input data and return immediately.
1774 if ((bd->state != BOARD_READY) || !tp || (tp->magic != TTY_MAGIC) ||
1775 !(ch->ch_tun.un_flags & UN_ISOPEN) || !(tp->termios.c_cflag & CREAD) ||
1776 (ch->ch_tun.un_flags & UN_CLOSING)) {
1778 DPR_READ(("input. dropping %d bytes on port %d...\n", data_len, ch->ch_portnum));
1779 DPR_READ(("input. tp: %p tp->magic: %x MAGIC:%x ch flags: %x\n",
1780 tp, tp ? tp->magic : 0, TTY_MAGIC, ch->ch_tun.un_flags));
1781 writew(head, &(bs->rx_tail));
1782 writeb(1, &(bs->idata));
1783 DGAP_UNLOCK(ch->ch_lock, lock_flags2);
1784 DGAP_UNLOCK(bd->bd_lock, lock_flags);
1789 * If we are throttled, simply don't read any data.
1791 if (ch->ch_flags & CH_RXBLOCK) {
1792 writeb(1, &(bs->idata));
1793 DGAP_UNLOCK(ch->ch_lock, lock_flags2);
1794 DGAP_UNLOCK(bd->bd_lock, lock_flags);
1795 DPR_READ(("Port %d throttled, not reading any data. head: %x tail: %x\n",
1796 ch->ch_portnum, head, tail));
1803 tmpchar = readb(&(bs->orun));
1805 ch->ch_err_overrun++;
1806 writeb(0, &(bs->orun));
1809 DPR_READ(("dgap_input start 2\n"));
1811 /* Decide how much data we can send into the tty layer */
1812 flip_len = TTY_FLIPBUF_SIZE;
1814 /* Chop down the length, if needed */
1815 len = min(data_len, flip_len);
1816 len = min(len, (N_TTY_BUF_SIZE - 1));
1818 ld = tty_ldisc_ref(tp);
1820 #ifdef TTY_DONT_FLIP
1822 * If the DONT_FLIP flag is on, don't flush our buffer, and act
1823 * like the ld doesn't have any space to put the data right now.
1825 if (test_bit(TTY_DONT_FLIP, &tp->flags))
1830 * If we were unable to get a reference to the ld,
1831 * don't flush our buffer, and act like the ld doesn't
1832 * have any space to put the data right now.
1838 * If ld doesn't have a pointer to a receive_buf function,
1839 * flush the data, then act like the ld doesn't have any
1840 * space to put the data right now.
1842 if (!ld->ops->receive_buf) {
1843 writew(head, &(bs->rx_tail));
1849 writeb(1, &(bs->idata));
1850 DGAP_UNLOCK(ch->ch_lock, lock_flags2);
1851 DGAP_UNLOCK(bd->bd_lock, lock_flags);
1852 DPR_READ(("dgap_input 1 - finish\n"));
1854 tty_ldisc_deref(ld);
1858 buf = ch->ch_bd->flipbuf;
1862 * n now contains the most amount of data we can copy,
1863 * bounded either by our buffer size or the amount
1864 * of data the card actually has pending...
1868 s = ((head >= tail) ? head : ch->ch_rsize) - tail;
1874 memcpy_fromio(buf, (char *) ch->ch_raddr + tail, s);
1875 dgap_sniff_nowait_nolock(ch, "USER READ", buf, s);
1881 /* Flip queue if needed */
1885 writew(tail, &(bs->rx_tail));
1886 writeb(1, &(bs->idata));
1887 ch->ch_rxcount += len;
1890 * If we are completely raw, we don't need to go through a lot
1891 * of the tty layers that exist.
1892 * In this case, we take the shortest and fastest route we
1893 * can to relay the data to the user.
1895 * On the other hand, if we are not raw, we need to go through
1896 * the tty layer, which has its API more well defined.
1898 if (I_PARMRK(tp) || I_BRKINT(tp) || I_INPCK(tp)) {
1899 dgap_parity_scan(ch, ch->ch_bd->flipbuf, ch->ch_bd->flipflagbuf, &len);
1901 len = tty_buffer_request_room(tp->port, len);
1902 tty_insert_flip_string_flags(tp->port, ch->ch_bd->flipbuf,
1903 ch->ch_bd->flipflagbuf, len);
1906 len = tty_buffer_request_room(tp->port, len);
1907 tty_insert_flip_string(tp->port, ch->ch_bd->flipbuf, len);
1910 DGAP_UNLOCK(ch->ch_lock, lock_flags2);
1911 DGAP_UNLOCK(bd->bd_lock, lock_flags);
1913 /* Tell the tty layer its okay to "eat" the data now */
1914 tty_flip_buffer_push(tp->port);
1917 tty_ldisc_deref(ld);
1919 DPR_READ(("dgap_input - finish\n"));
1923 /************************************************************************
1924 * Determines when CARRIER changes state and takes appropriate
1926 ************************************************************************/
1927 void dgap_carrier(struct channel_t *ch)
1931 int virt_carrier = 0;
1932 int phys_carrier = 0;
1934 DPR_CARR(("dgap_carrier called...\n"));
1936 if (!ch || ch->magic != DGAP_CHANNEL_MAGIC)
1941 if (!bd || bd->magic != DGAP_BOARD_MAGIC)
1944 /* Make sure altpin is always set correctly */
1945 if (ch->ch_digi.digi_flags & DIGI_ALTPIN) {
1950 ch->ch_dsr = DM_DSR;
1954 if (ch->ch_mistat & D_CD(ch)) {
1955 DPR_CARR(("mistat: %x D_CD: %x\n", ch->ch_mistat, D_CD(ch)));
1959 if (ch->ch_digi.digi_flags & DIGI_FORCEDCD) {
1963 if (ch->ch_c_cflag & CLOCAL) {
1968 DPR_CARR(("DCD: physical: %d virt: %d\n", phys_carrier, virt_carrier));
1971 * Test for a VIRTUAL carrier transition to HIGH.
1973 if (((ch->ch_flags & CH_FCAR) == 0) && (virt_carrier == 1)) {
1976 * When carrier rises, wake any threads waiting
1977 * for carrier in the open routine.
1980 DPR_CARR(("carrier: virt DCD rose\n"));
1982 if (waitqueue_active(&(ch->ch_flags_wait)))
1983 wake_up_interruptible(&ch->ch_flags_wait);
1987 * Test for a PHYSICAL carrier transition to HIGH.
1989 if (((ch->ch_flags & CH_CD) == 0) && (phys_carrier == 1)) {
1992 * When carrier rises, wake any threads waiting
1993 * for carrier in the open routine.
1996 DPR_CARR(("carrier: physical DCD rose\n"));
1998 if (waitqueue_active(&(ch->ch_flags_wait)))
1999 wake_up_interruptible(&ch->ch_flags_wait);
2003 * Test for a PHYSICAL transition to low, so long as we aren't
2004 * currently ignoring physical transitions (which is what "virtual
2005 * carrier" indicates).
2007 * The transition of the virtual carrier to low really doesn't
2008 * matter... it really only means "ignore carrier state", not
2009 * "make pretend that carrier is there".
2011 if ((virt_carrier == 0) && ((ch->ch_flags & CH_CD) != 0) &&
2012 (phys_carrier == 0))
2016 * When carrier drops:
2018 * Drop carrier on all open units.
2020 * Flush queues, waking up any task waiting in the
2023 * Send a hangup to the control terminal.
2025 * Enable all select calls.
2027 if (waitqueue_active(&(ch->ch_flags_wait)))
2028 wake_up_interruptible(&ch->ch_flags_wait);
2030 if (ch->ch_tun.un_open_count > 0) {
2031 DPR_CARR(("Sending tty hangup\n"));
2032 tty_hangup(ch->ch_tun.un_tty);
2035 if (ch->ch_pun.un_open_count > 0) {
2036 DPR_CARR(("Sending pr hangup\n"));
2037 tty_hangup(ch->ch_pun.un_tty);
2042 * Make sure that our cached values reflect the current reality.
2044 if (virt_carrier == 1)
2045 ch->ch_flags |= CH_FCAR;
2047 ch->ch_flags &= ~CH_FCAR;
2049 if (phys_carrier == 1)
2050 ch->ch_flags |= CH_CD;
2052 ch->ch_flags &= ~CH_CD;
2056 /************************************************************************
2058 * TTY Entry points and helper functions
2060 ************************************************************************/
2066 static int dgap_tty_open(struct tty_struct *tty, struct file *file)
2068 struct board_t *brd;
2069 struct channel_t *ch;
2081 major = MAJOR(tty_devnum(tty));
2082 minor = MINOR(tty_devnum(tty));
2088 /* Get board pointer from our array of majors we have allocated */
2089 brd = dgap_BoardsByMajor[major];
2095 * If board is not yet up to a state of READY, go to
2096 * sleep waiting for it to happen or they cancel the open.
2098 rc = wait_event_interruptible(brd->state_wait,
2099 (brd->state & BOARD_READY));
2105 DGAP_LOCK(brd->bd_lock, lock_flags);
2107 /* The wait above should guarantee this cannot happen */
2108 if (brd->state != BOARD_READY) {
2109 DGAP_UNLOCK(brd->bd_lock, lock_flags);
2113 /* If opened device is greater than our number of ports, bail. */
2114 if (MINOR(tty_devnum(tty)) > brd->nasync) {
2115 DGAP_UNLOCK(brd->bd_lock, lock_flags);
2119 ch = brd->channels[minor];
2121 DGAP_UNLOCK(brd->bd_lock, lock_flags);
2125 /* Grab channel lock */
2126 DGAP_LOCK(ch->ch_lock, lock_flags2);
2128 /* Figure out our type */
2129 if (major == brd->dgap_Serial_Major) {
2130 un = &brd->channels[minor]->ch_tun;
2131 un->un_type = DGAP_SERIAL;
2133 else if (major == brd->dgap_TransparentPrint_Major) {
2134 un = &brd->channels[minor]->ch_pun;
2135 un->un_type = DGAP_PRINT;
2138 DGAP_UNLOCK(ch->ch_lock, lock_flags2);
2139 DGAP_UNLOCK(brd->bd_lock, lock_flags);
2140 DPR_OPEN(("%d Unknown TYPE!\n", __LINE__));
2144 /* Store our unit into driver_data, so we always have it available. */
2145 tty->driver_data = un;
2147 DPR_OPEN(("Open called. MAJOR: %d MINOR:%d unit: %p NAME: %s\n",
2148 MAJOR(tty_devnum(tty)), MINOR(tty_devnum(tty)), un, brd->name));
2151 * Error if channel info pointer is NULL.
2155 DGAP_UNLOCK(ch->ch_lock, lock_flags2);
2156 DGAP_UNLOCK(brd->bd_lock, lock_flags);
2157 DPR_OPEN(("%d BS is 0!\n", __LINE__));
2161 DPR_OPEN(("%d: tflag=%x pflag=%x\n", __LINE__, ch->ch_tun.un_flags, ch->ch_pun.un_flags));
2166 if (!(un->un_flags & UN_ISOPEN)) {
2167 /* Store important variables. */
2170 /* Maybe do something here to the TTY struct as well? */
2174 * Initialize if neither terminal or printer is open.
2176 if (!((ch->ch_tun.un_flags | ch->ch_pun.un_flags) & UN_ISOPEN)) {
2178 DPR_OPEN(("dgap_open: initializing channel in open...\n"));
2184 * Flush input queue.
2186 head = readw(&(bs->rx_head));
2187 writew(head, &(bs->rx_tail));
2190 ch->pscan_state = 0;
2191 ch->pscan_savechar = 0;
2193 ch->ch_c_cflag = tty->termios.c_cflag;
2194 ch->ch_c_iflag = tty->termios.c_iflag;
2195 ch->ch_c_oflag = tty->termios.c_oflag;
2196 ch->ch_c_lflag = tty->termios.c_lflag;
2197 ch->ch_startc = tty->termios.c_cc[VSTART];
2198 ch->ch_stopc = tty->termios.c_cc[VSTOP];
2200 /* TODO: flush our TTY struct here? */
2205 * Run param in case we changed anything
2210 * follow protocol for opening port
2213 DGAP_UNLOCK(ch->ch_lock, lock_flags2);
2214 DGAP_UNLOCK(brd->bd_lock, lock_flags);
2216 rc = dgap_block_til_ready(tty, file, ch);
2223 DPR_OPEN(("dgap_tty_open returning after dgap_block_til_ready "
2227 /* No going back now, increment our unit and channel counters */
2228 DGAP_LOCK(ch->ch_lock, lock_flags);
2229 ch->ch_open_count++;
2230 un->un_open_count++;
2231 un->un_flags |= (UN_ISOPEN);
2232 DGAP_UNLOCK(ch->ch_lock, lock_flags);
2234 DPR_OPEN(("dgap_tty_open finished\n"));
2240 * dgap_block_til_ready()
2242 * Wait for DCD, if needed.
2244 static int dgap_block_til_ready(struct tty_struct *tty, struct file *file, struct channel_t *ch)
2247 struct un_t *un = NULL;
2250 int sleep_on_un_flags = 0;
2252 if (!tty || tty->magic != TTY_MAGIC || !file || !ch || ch->magic != DGAP_CHANNEL_MAGIC) {
2256 un = tty->driver_data;
2257 if (!un || un->magic != DGAP_UNIT_MAGIC) {
2261 DPR_OPEN(("dgap_block_til_ready - before block.\n"));
2263 DGAP_LOCK(ch->ch_lock, lock_flags);
2270 sleep_on_un_flags = 0;
2273 * If board has failed somehow during our sleep, bail with error.
2275 if (ch->ch_bd->state == BOARD_FAILED) {
2280 /* If tty was hung up, break out of loop and set error. */
2281 if (tty_hung_up_p(file)) {
2287 * If either unit is in the middle of the fragile part of close,
2288 * we just cannot touch the channel safely.
2289 * Go back to sleep, knowing that when the channel can be
2290 * touched safely, the close routine will signal the
2291 * ch_wait_flags to wake us back up.
2293 if (!((ch->ch_tun.un_flags | ch->ch_pun.un_flags) & UN_CLOSING)) {
2296 * Our conditions to leave cleanly and happily:
2297 * 1) NONBLOCKING on the tty is set.
2299 * 3) DCD (fake or real) is active.
2302 if (file->f_flags & O_NONBLOCK) {
2306 if (tty->flags & (1 << TTY_IO_ERROR)) {
2310 if (ch->ch_flags & CH_CD) {
2311 DPR_OPEN(("%d: ch_flags: %x\n", __LINE__, ch->ch_flags));
2315 if (ch->ch_flags & CH_FCAR) {
2316 DPR_OPEN(("%d: ch_flags: %x\n", __LINE__, ch->ch_flags));
2321 sleep_on_un_flags = 1;
2325 * If there is a signal pending, the user probably
2326 * interrupted (ctrl-c) us.
2327 * Leave loop with error set.
2329 if (signal_pending(current)) {
2330 DPR_OPEN(("%d: signal pending...\n", __LINE__));
2331 retval = -ERESTARTSYS;
2335 DPR_OPEN(("dgap_block_til_ready - blocking.\n"));
2338 * Store the flags before we let go of channel lock
2340 if (sleep_on_un_flags)
2341 old_flags = ch->ch_tun.un_flags | ch->ch_pun.un_flags;
2343 old_flags = ch->ch_flags;
2346 * Let go of channel lock before calling schedule.
2347 * Our poller will get any FEP events and wake us up when DCD
2348 * eventually goes active.
2351 DGAP_UNLOCK(ch->ch_lock, lock_flags);
2353 DPR_OPEN(("Going to sleep on %s flags...\n",
2354 (sleep_on_un_flags ? "un" : "ch")));
2357 * Wait for something in the flags to change from the current value.
2359 if (sleep_on_un_flags) {
2360 retval = wait_event_interruptible(un->un_flags_wait,
2361 (old_flags != (ch->ch_tun.un_flags | ch->ch_pun.un_flags)));
2364 retval = wait_event_interruptible(ch->ch_flags_wait,
2365 (old_flags != ch->ch_flags));
2368 DPR_OPEN(("After sleep... retval: %x\n", retval));
2371 * We got woken up for some reason.
2372 * Before looping around, grab our channel lock.
2374 DGAP_LOCK(ch->ch_lock, lock_flags);
2379 DGAP_UNLOCK(ch->ch_lock, lock_flags);
2381 DPR_OPEN(("dgap_block_til_ready - after blocking.\n"));
2384 DPR_OPEN(("dgap_block_til_ready - done. error. retval: %x\n", retval));
2388 DPR_OPEN(("dgap_block_til_ready - done no error. jiffies: %lu\n", jiffies));
2397 * Hangup the port. Like a close, but don't wait for output to drain.
2399 static void dgap_tty_hangup(struct tty_struct *tty)
2402 struct channel_t *ch;
2405 if (!tty || tty->magic != TTY_MAGIC)
2408 un = tty->driver_data;
2409 if (!un || un->magic != DGAP_UNIT_MAGIC)
2413 if (!ch || ch->magic != DGAP_CHANNEL_MAGIC)
2417 if (!bd || bd->magic != DGAP_BOARD_MAGIC)
2420 DPR_CLOSE(("dgap_hangup called. ch->ch_open_count: %d un->un_open_count: %d\n",
2421 ch->ch_open_count, un->un_open_count));
2423 /* flush the transmit queues */
2424 dgap_tty_flush_buffer(tty);
2426 DPR_CLOSE(("dgap_hangup finished. ch->ch_open_count: %d un->un_open_count: %d\n",
2427 ch->ch_open_count, un->un_open_count));
2436 static void dgap_tty_close(struct tty_struct *tty, struct file *file)
2438 struct ktermios *ts;
2440 struct channel_t *ch;
2445 if (!tty || tty->magic != TTY_MAGIC)
2448 un = tty->driver_data;
2449 if (!un || un->magic != DGAP_UNIT_MAGIC)
2453 if (!ch || ch->magic != DGAP_CHANNEL_MAGIC)
2457 if (!bd || bd->magic != DGAP_BOARD_MAGIC)
2462 DPR_CLOSE(("Close called\n"));
2464 DGAP_LOCK(ch->ch_lock, lock_flags);
2467 * Determine if this is the last close or not - and if we agree about
2468 * which type of close it is with the Line Discipline
2470 if ((tty->count == 1) && (un->un_open_count != 1)) {
2472 * Uh, oh. tty->count is 1, which means that the tty
2473 * structure will be freed. un_open_count should always
2474 * be one in these conditions. If it's greater than
2475 * one, we've got real problems, since it means the
2476 * serial port won't be shutdown.
2478 APR(("tty->count is 1, un open count is %d\n", un->un_open_count));
2479 un->un_open_count = 1;
2482 if (--un->un_open_count < 0) {
2483 APR(("bad serial port open count of %d\n", un->un_open_count));
2484 un->un_open_count = 0;
2487 ch->ch_open_count--;
2489 if (ch->ch_open_count && un->un_open_count) {
2490 DPR_CLOSE(("dgap_tty_close: not last close ch: %d un:%d\n",
2491 ch->ch_open_count, un->un_open_count));
2493 DGAP_UNLOCK(ch->ch_lock, lock_flags);
2497 /* OK, its the last close on the unit */
2498 DPR_CLOSE(("dgap_tty_close - last close on unit procedures\n"));
2500 un->un_flags |= UN_CLOSING;
2505 * Only officially close channel if count is 0 and
2506 * DIGI_PRINTER bit is not set.
2508 if ((ch->ch_open_count == 0) && !(ch->ch_digi.digi_flags & DIGI_PRINTER)) {
2510 ch->ch_flags &= ~(CH_RXBLOCK);
2512 DGAP_UNLOCK(ch->ch_lock, lock_flags);
2514 /* wait for output to drain */
2515 /* This will also return if we take an interrupt */
2517 DPR_CLOSE(("Calling wait_for_drain\n"));
2518 rc = dgap_wait_for_drain(tty);
2519 DPR_CLOSE(("After calling wait_for_drain\n"));
2522 DPR_BASIC(("dgap_tty_close - bad return: %d ", rc));
2525 dgap_tty_flush_buffer(tty);
2526 tty_ldisc_flush(tty);
2528 DGAP_LOCK(ch->ch_lock, lock_flags);
2533 * If we have HUPCL set, lower DTR and RTS
2535 if (ch->ch_c_cflag & HUPCL ) {
2536 DPR_CLOSE(("Close. HUPCL set, dropping DTR/RTS\n"));
2537 ch->ch_mostat &= ~(D_RTS(ch)|D_DTR(ch));
2538 dgap_cmdb( ch, SMODEM, 0, D_DTR(ch)|D_RTS(ch), 0 );
2541 * Go to sleep to ensure RTS/DTR
2542 * have been dropped for modems to see it.
2544 if (ch->ch_close_delay) {
2545 DPR_CLOSE(("Close. Sleeping for RTS/DTR drop\n"));
2547 DGAP_UNLOCK(ch->ch_lock, lock_flags);
2548 dgap_ms_sleep(ch->ch_close_delay);
2549 DGAP_LOCK(ch->ch_lock, lock_flags);
2551 DPR_CLOSE(("Close. After sleeping for RTS/DTR drop\n"));
2555 ch->pscan_state = 0;
2556 ch->pscan_savechar = 0;
2557 ch->ch_baud_info = 0;
2562 * turn off print device when closing print device.
2564 if ((un->un_type == DGAP_PRINT) && (ch->ch_flags & CH_PRON) ) {
2565 dgap_wmove(ch, ch->ch_digi.digi_offstr,
2566 (int) ch->ch_digi.digi_offlen);
2567 ch->ch_flags &= ~CH_PRON;
2571 un->un_flags &= ~(UN_ISOPEN | UN_CLOSING);
2572 tty->driver_data = NULL;
2574 DPR_CLOSE(("Close. Doing wakeups\n"));
2575 wake_up_interruptible(&ch->ch_flags_wait);
2576 wake_up_interruptible(&un->un_flags_wait);
2578 DGAP_UNLOCK(ch->ch_lock, lock_flags);
2580 DPR_BASIC(("dgap_tty_close - complete\n"));
2585 * dgap_tty_chars_in_buffer()
2587 * Return number of characters that have not been transmitted yet.
2589 * This routine is used by the line discipline to determine if there
2590 * is data waiting to be transmitted/drained/flushed or not.
2592 static int dgap_tty_chars_in_buffer(struct tty_struct *tty)
2594 struct board_t *bd = NULL;
2595 struct channel_t *ch = NULL;
2596 struct un_t *un = NULL;
2597 struct bs_t *bs = NULL;
2600 u16 thead, ttail, tmask, chead, ctail;
2601 ulong lock_flags = 0;
2602 ulong lock_flags2 = 0;
2607 un = tty->driver_data;
2608 if (!un || un->magic != DGAP_UNIT_MAGIC)
2612 if (!ch || ch->magic != DGAP_CHANNEL_MAGIC)
2616 if (!bd || bd->magic != DGAP_BOARD_MAGIC)
2623 DGAP_LOCK(bd->bd_lock, lock_flags);
2624 DGAP_LOCK(ch->ch_lock, lock_flags2);
2626 tmask = (ch->ch_tsize - 1);
2628 /* Get Transmit queue pointers */
2629 thead = readw(&(bs->tx_head)) & tmask;
2630 ttail = readw(&(bs->tx_tail)) & tmask;
2632 /* Get tbusy flag */
2633 tbusy = readb(&(bs->tbusy));
2635 /* Get Command queue pointers */
2636 chead = readw(&(ch->ch_cm->cm_head));
2637 ctail = readw(&(ch->ch_cm->cm_tail));
2639 DGAP_UNLOCK(ch->ch_lock, lock_flags2);
2640 DGAP_UNLOCK(bd->bd_lock, lock_flags);
2643 * The only way we know for sure if there is no pending
2644 * data left to be transferred, is if:
2645 * 1) Transmit head and tail are equal (empty).
2646 * 2) Command queue head and tail are equal (empty).
2647 * 3) The "TBUSY" flag is 0. (Transmitter not busy).
2650 if ((ttail == thead) && (tbusy == 0) && (chead == ctail)) {
2655 chars = thead - ttail;
2657 chars = thead - ttail + ch->ch_tsize;
2659 * Fudge factor here.
2660 * If chars is zero, we know that the command queue had
2661 * something in it or tbusy was set. Because we cannot
2662 * be sure if there is still some data to be transmitted,
2663 * lets lie, and tell ld we have 1 byte left.
2667 * If TBUSY is still set, and our tx buffers are empty,
2668 * force the firmware to send me another wakeup after
2669 * TBUSY has been cleared.
2672 DGAP_LOCK(ch->ch_lock, lock_flags);
2673 un->un_flags |= UN_EMPTY;
2674 writeb(1, &(bs->iempty));
2675 DGAP_UNLOCK(ch->ch_lock, lock_flags);
2681 DPR_WRITE(("dgap_tty_chars_in_buffer. Port: %x - %d (head: %d tail: %d tsize: %d)\n",
2682 ch->ch_portnum, chars, thead, ttail, ch->ch_tsize));
2687 static int dgap_wait_for_drain(struct tty_struct *tty)
2689 struct channel_t *ch;
2694 ulong lock_flags = 0;
2696 if (!tty || tty->magic != TTY_MAGIC)
2699 un = tty->driver_data;
2700 if (!un || un->magic != DGAP_UNIT_MAGIC)
2704 if (!ch || ch->magic != DGAP_CHANNEL_MAGIC)
2713 DPR_DRAIN(("dgap_wait_for_drain start\n"));
2715 /* Loop until data is drained */
2716 while (count != 0) {
2718 count = dgap_tty_chars_in_buffer(tty);
2723 /* Set flag waiting for drain */
2724 DGAP_LOCK(ch->ch_lock, lock_flags);
2725 un->un_flags |= UN_EMPTY;
2726 writeb(1, &(bs->iempty));
2727 DGAP_UNLOCK(ch->ch_lock, lock_flags);
2729 /* Go to sleep till we get woken up */
2730 ret = wait_event_interruptible(un->un_flags_wait, ((un->un_flags & UN_EMPTY) == 0));
2731 /* If ret is non-zero, user ctrl-c'ed us */
2737 DGAP_LOCK(ch->ch_lock, lock_flags);
2738 un->un_flags &= ~(UN_EMPTY);
2739 DGAP_UNLOCK(ch->ch_lock, lock_flags);
2741 DPR_DRAIN(("dgap_wait_for_drain finish\n"));
2749 * Reduces bytes_available to the max number of characters
2750 * that can be sent currently given the maxcps value, and
2751 * returns the new bytes_available. This only affects printer
2754 static int dgap_maxcps_room(struct tty_struct *tty, int bytes_available)
2756 struct channel_t *ch = NULL;
2757 struct un_t *un = NULL;
2760 return (bytes_available);
2762 un = tty->driver_data;
2763 if (!un || un->magic != DGAP_UNIT_MAGIC)
2764 return (bytes_available);
2767 if (!ch || ch->magic != DGAP_CHANNEL_MAGIC)
2768 return (bytes_available);
2771 * If its not the Transparent print device, return
2772 * the full data amount.
2774 if (un->un_type != DGAP_PRINT)
2775 return (bytes_available);
2777 if (ch->ch_digi.digi_maxcps > 0 && ch->ch_digi.digi_bufsize > 0 ) {
2779 unsigned long current_time = jiffies;
2780 unsigned long buffer_time = current_time +
2781 (HZ * ch->ch_digi.digi_bufsize) / ch->ch_digi.digi_maxcps;
2783 if (ch->ch_cpstime < current_time) {
2784 /* buffer is empty */
2785 ch->ch_cpstime = current_time; /* reset ch_cpstime */
2786 cps_limit = ch->ch_digi.digi_bufsize;
2788 else if (ch->ch_cpstime < buffer_time) {
2789 /* still room in the buffer */
2790 cps_limit = ((buffer_time - ch->ch_cpstime) * ch->ch_digi.digi_maxcps) / HZ;
2793 /* no room in the buffer */
2797 bytes_available = min(cps_limit, bytes_available);
2800 return (bytes_available);
2804 static inline void dgap_set_firmware_event(struct un_t *un, unsigned int event)
2806 struct channel_t *ch = NULL;
2807 struct bs_t *bs = NULL;
2809 if (!un || un->magic != DGAP_UNIT_MAGIC)
2812 if (!ch || ch->magic != DGAP_CHANNEL_MAGIC)
2818 if ((event & UN_LOW) != 0) {
2819 if ((un->un_flags & UN_LOW) == 0) {
2820 un->un_flags |= UN_LOW;
2821 writeb(1, &(bs->ilow));
2824 if ((event & UN_LOW) != 0) {
2825 if ((un->un_flags & UN_EMPTY) == 0) {
2826 un->un_flags |= UN_EMPTY;
2827 writeb(1, &(bs->iempty));
2834 * dgap_tty_write_room()
2836 * Return space available in Tx buffer
2838 static int dgap_tty_write_room(struct tty_struct *tty)
2840 struct channel_t *ch = NULL;
2841 struct un_t *un = NULL;
2842 struct bs_t *bs = NULL;
2843 u16 head, tail, tmask;
2845 ulong lock_flags = 0;
2847 if (tty == NULL || dgap_TmpWriteBuf == NULL)
2850 un = tty->driver_data;
2851 if (!un || un->magic != DGAP_UNIT_MAGIC)
2855 if (!ch || ch->magic != DGAP_CHANNEL_MAGIC)
2862 DGAP_LOCK(ch->ch_lock, lock_flags);
2864 tmask = ch->ch_tsize - 1;
2865 head = readw(&(bs->tx_head)) & tmask;
2866 tail = readw(&(bs->tx_tail)) & tmask;
2868 if ((ret = tail - head - 1) < 0)
2869 ret += ch->ch_tsize;
2871 /* Limit printer to maxcps */
2872 ret = dgap_maxcps_room(tty, ret);
2875 * If we are printer device, leave space for
2876 * possibly both the on and off strings.
2878 if (un->un_type == DGAP_PRINT) {
2879 if (!(ch->ch_flags & CH_PRON))
2880 ret -= ch->ch_digi.digi_onlen;
2881 ret -= ch->ch_digi.digi_offlen;
2884 if (ch->ch_flags & CH_PRON)
2885 ret -= ch->ch_digi.digi_offlen;
2892 * Schedule FEP to wake us up if needed.
2894 * TODO: This might be overkill...
2895 * Do we really need to schedule callbacks from the FEP
2896 * in every case? Can we get smarter based on ret?
2898 dgap_set_firmware_event(un, UN_LOW | UN_EMPTY);
2899 DGAP_UNLOCK(ch->ch_lock, lock_flags);
2901 DPR_WRITE(("dgap_tty_write_room - %d tail: %d head: %d\n", ret, tail, head));
2908 * dgap_tty_put_char()
2910 * Put a character into ch->ch_buf
2912 * - used by the line discipline for OPOST processing
2914 static int dgap_tty_put_char(struct tty_struct *tty, unsigned char c)
2917 * Simply call tty_write.
2919 DPR_WRITE(("dgap_tty_put_char called\n"));
2920 dgap_tty_write(tty, &c, 1);
2928 * Take data from the user or kernel and send it out to the FEP.
2929 * In here exists all the Transparent Print magic as well.
2931 static int dgap_tty_write(struct tty_struct *tty, const unsigned char *buf, int count)
2933 struct channel_t *ch = NULL;
2934 struct un_t *un = NULL;
2935 struct bs_t *bs = NULL;
2937 u16 head, tail, tmask, remain;
2938 int bufcount = 0, n = 0;
2943 if (tty == NULL || dgap_TmpWriteBuf == NULL)
2946 un = tty->driver_data;
2947 if (!un || un->magic != DGAP_UNIT_MAGIC)
2951 if (!ch || ch->magic != DGAP_CHANNEL_MAGIC)
2961 DPR_WRITE(("dgap_tty_write: Port: %x tty=%p user=%d len=%d\n",
2962 ch->ch_portnum, tty, from_user, count));
2965 * Store original amount of characters passed in.
2966 * This helps to figure out if we should ask the FEP
2967 * to send us an event when it has more space available.
2971 DGAP_LOCK(ch->ch_lock, lock_flags);
2973 /* Get our space available for the channel from the board */
2974 tmask = ch->ch_tsize - 1;
2975 head = readw(&(bs->tx_head)) & tmask;
2976 tail = readw(&(bs->tx_tail)) & tmask;
2978 if ((bufcount = tail - head - 1) < 0)
2979 bufcount += ch->ch_tsize;
2981 DPR_WRITE(("%d: bufcount: %x count: %x tail: %x head: %x tmask: %x\n",
2982 __LINE__, bufcount, count, tail, head, tmask));
2985 * Limit printer output to maxcps overall, with bursts allowed
2986 * up to bufsize characters.
2988 bufcount = dgap_maxcps_room(tty, bufcount);
2991 * Take minimum of what the user wants to send, and the
2992 * space available in the FEP buffer.
2994 count = min(count, bufcount);
2997 * Bail if no space left.
3000 dgap_set_firmware_event(un, UN_LOW | UN_EMPTY);
3001 DGAP_UNLOCK(ch->ch_lock, lock_flags);
3006 * Output the printer ON string, if we are in terminal mode, but
3007 * need to be in printer mode.
3009 if ((un->un_type == DGAP_PRINT) && !(ch->ch_flags & CH_PRON)) {
3010 dgap_wmove(ch, ch->ch_digi.digi_onstr,
3011 (int) ch->ch_digi.digi_onlen);
3012 head = readw(&(bs->tx_head)) & tmask;
3013 ch->ch_flags |= CH_PRON;
3017 * On the other hand, output the printer OFF string, if we are
3018 * currently in printer mode, but need to output to the terminal.
3020 if ((un->un_type != DGAP_PRINT) && (ch->ch_flags & CH_PRON)) {
3021 dgap_wmove(ch, ch->ch_digi.digi_offstr,
3022 (int) ch->ch_digi.digi_offlen);
3023 head = readw(&(bs->tx_head)) & tmask;
3024 ch->ch_flags &= ~CH_PRON;
3028 * If there is nothing left to copy, or I can't handle any more data, leave.
3031 dgap_set_firmware_event(un, UN_LOW | UN_EMPTY);
3032 DGAP_UNLOCK(ch->ch_lock, lock_flags);
3038 count = min(count, WRITEBUFLEN);
3040 DGAP_UNLOCK(ch->ch_lock, lock_flags);
3043 * If data is coming from user space, copy it into a temporary
3044 * buffer so we don't get swapped out while doing the copy to
3047 /* we're allowed to block if it's from_user */
3048 if (down_interruptible(&dgap_TmpWriteSem)) {
3052 if (copy_from_user(dgap_TmpWriteBuf, (const uchar __user *) buf, count)) {
3053 up(&dgap_TmpWriteSem);
3054 printk("Write: Copy from user failed!\n");
3058 DGAP_LOCK(ch->ch_lock, lock_flags);
3060 buf = dgap_TmpWriteBuf;
3066 * If the write wraps over the top of the circular buffer,
3067 * move the portion up to the wrap point, and reset the
3068 * pointers to the bottom.
3070 remain = ch->ch_tstart + ch->ch_tsize - head;
3074 vaddr = ch->ch_taddr + head;
3076 memcpy_toio(vaddr, (uchar *) buf, remain);
3077 dgap_sniff_nowait_nolock(ch, "USER WRITE", (uchar *) buf, remain);
3079 head = ch->ch_tstart;
3086 * Move rest of data.
3088 vaddr = ch->ch_taddr + head;
3091 memcpy_toio(vaddr, (uchar *) buf, remain);
3092 dgap_sniff_nowait_nolock(ch, "USER WRITE", (uchar *) buf, remain);
3099 ch->ch_txcount += count;
3101 writew(head, &(bs->tx_head));
3105 dgap_set_firmware_event(un, UN_LOW | UN_EMPTY);
3108 * If this is the print device, and the
3109 * printer is still on, we need to turn it
3110 * off before going idle. If the buffer is
3111 * non-empty, wait until it goes empty.
3112 * Otherwise turn it off right now.
3114 if ((un->un_type == DGAP_PRINT) && (ch->ch_flags & CH_PRON)) {
3115 tail = readw(&(bs->tx_tail)) & tmask;
3118 un->un_flags |= UN_EMPTY;
3119 writeb(1, &(bs->iempty));
3122 dgap_wmove(ch, ch->ch_digi.digi_offstr,
3123 (int) ch->ch_digi.digi_offlen);
3124 head = readw(&(bs->tx_head)) & tmask;
3125 ch->ch_flags &= ~CH_PRON;
3129 /* Update printer buffer empty time. */
3130 if ((un->un_type == DGAP_PRINT) && (ch->ch_digi.digi_maxcps > 0)
3131 && (ch->ch_digi.digi_bufsize > 0)) {
3132 ch->ch_cpstime += (HZ * count) / ch->ch_digi.digi_maxcps;
3136 DGAP_UNLOCK(ch->ch_lock, lock_flags);
3137 up(&dgap_TmpWriteSem);
3140 DGAP_UNLOCK(ch->ch_lock, lock_flags);
3143 DPR_WRITE(("Write finished - Write %d bytes of %d.\n", count, orig_count));
3151 * Return modem signals to ld.
3153 static int dgap_tty_tiocmget(struct tty_struct *tty)
3155 struct channel_t *ch;
3161 if (!tty || tty->magic != TTY_MAGIC)
3164 un = tty->driver_data;
3165 if (!un || un->magic != DGAP_UNIT_MAGIC)
3169 if (!ch || ch->magic != DGAP_CHANNEL_MAGIC)
3172 DPR_IOCTL(("dgap_tty_tiocmget start\n"));
3174 DGAP_LOCK(ch->ch_lock, lock_flags);
3176 mstat = readb(&(ch->ch_bs->m_stat));
3177 /* Append any outbound signals that might be pending... */
3178 mstat |= ch->ch_mostat;
3180 DGAP_UNLOCK(ch->ch_lock, lock_flags);
3184 if (mstat & D_DTR(ch))
3185 result |= TIOCM_DTR;
3186 if (mstat & D_RTS(ch))
3187 result |= TIOCM_RTS;
3188 if (mstat & D_CTS(ch))
3189 result |= TIOCM_CTS;
3190 if (mstat & D_DSR(ch))
3191 result |= TIOCM_DSR;
3192 if (mstat & D_RI(ch))
3194 if (mstat & D_CD(ch))
3197 DPR_IOCTL(("dgap_tty_tiocmget finish\n"));
3204 * dgap_tty_tiocmset()
3206 * Set modem signals, called by ld.
3209 static int dgap_tty_tiocmset(struct tty_struct *tty,
3210 unsigned int set, unsigned int clear)
3213 struct channel_t *ch;
3219 if (!tty || tty->magic != TTY_MAGIC)
3222 un = tty->driver_data;
3223 if (!un || un->magic != DGAP_UNIT_MAGIC)
3227 if (!ch || ch->magic != DGAP_CHANNEL_MAGIC)
3231 if (!bd || bd->magic != DGAP_BOARD_MAGIC)
3234 DPR_IOCTL(("dgap_tty_tiocmset start\n"));
3236 DGAP_LOCK(bd->bd_lock, lock_flags);
3237 DGAP_LOCK(ch->ch_lock, lock_flags2);
3239 if (set & TIOCM_RTS) {
3240 ch->ch_mforce |= D_RTS(ch);
3241 ch->ch_mval |= D_RTS(ch);
3244 if (set & TIOCM_DTR) {
3245 ch->ch_mforce |= D_DTR(ch);
3246 ch->ch_mval |= D_DTR(ch);
3249 if (clear & TIOCM_RTS) {
3250 ch->ch_mforce |= D_RTS(ch);
3251 ch->ch_mval &= ~(D_RTS(ch));
3254 if (clear & TIOCM_DTR) {
3255 ch->ch_mforce |= D_DTR(ch);
3256 ch->ch_mval &= ~(D_DTR(ch));
3261 DGAP_UNLOCK(ch->ch_lock, lock_flags2);
3262 DGAP_UNLOCK(bd->bd_lock, lock_flags);
3264 DPR_IOCTL(("dgap_tty_tiocmset finish\n"));
3272 * dgap_tty_send_break()
3274 * Send a Break, called by ld.
3276 static int dgap_tty_send_break(struct tty_struct *tty, int msec)
3279 struct channel_t *ch;
3285 if (!tty || tty->magic != TTY_MAGIC)
3288 un = tty->driver_data;
3289 if (!un || un->magic != DGAP_UNIT_MAGIC)
3293 if (!ch || ch->magic != DGAP_CHANNEL_MAGIC)
3297 if (!bd || bd->magic != DGAP_BOARD_MAGIC)
3312 DPR_IOCTL(("dgap_tty_send_break start 1. %lx\n", jiffies));
3314 DGAP_LOCK(bd->bd_lock, lock_flags);
3315 DGAP_LOCK(ch->ch_lock, lock_flags2);
3317 dgap_cmdw(ch, SBREAK, (u16) SBREAK_TIME, 0);
3319 dgap_cmdw(ch, SBREAK, (u16) msec, 0);
3321 DGAP_UNLOCK(ch->ch_lock, lock_flags2);
3322 DGAP_UNLOCK(bd->bd_lock, lock_flags);
3324 DPR_IOCTL(("dgap_tty_send_break finish\n"));
3333 * dgap_tty_wait_until_sent()
3335 * wait until data has been transmitted, called by ld.
3337 static void dgap_tty_wait_until_sent(struct tty_struct *tty, int timeout)
3340 rc = dgap_wait_for_drain(tty);
3342 DPR_IOCTL(("dgap_tty_ioctl - bad return: %d ", rc));
3353 * send a high priority character, called by ld.
3355 static void dgap_tty_send_xchar(struct tty_struct *tty, char c)
3358 struct channel_t *ch;
3363 if (!tty || tty->magic != TTY_MAGIC)
3366 un = tty->driver_data;
3367 if (!un || un->magic != DGAP_UNIT_MAGIC)
3371 if (!ch || ch->magic != DGAP_CHANNEL_MAGIC)
3375 if (!bd || bd->magic != DGAP_BOARD_MAGIC)
3378 DPR_IOCTL(("dgap_tty_send_xchar start 1. %lx\n", jiffies));
3380 DGAP_LOCK(bd->bd_lock, lock_flags);
3381 DGAP_LOCK(ch->ch_lock, lock_flags2);
3384 * This is technically what we should do.
3385 * However, the NIST tests specifically want
3386 * to see each XON or XOFF character that it
3387 * sends, so lets just send each character
3391 if (c == STOP_CHAR(tty)) {
3392 dgap_cmdw(ch, RPAUSE, 0, 0);
3394 else if (c == START_CHAR(tty)) {
3395 dgap_cmdw(ch, RRESUME, 0, 0);
3398 dgap_wmove(ch, &c, 1);
3401 dgap_wmove(ch, &c, 1);
3404 DGAP_UNLOCK(ch->ch_lock, lock_flags2);
3405 DGAP_UNLOCK(bd->bd_lock, lock_flags);
3407 DPR_IOCTL(("dgap_tty_send_xchar finish\n"));
3416 * Return modem signals to ld.
3418 static int dgap_get_modem_info(struct channel_t *ch, unsigned int __user *value)
3425 DPR_IOCTL(("dgap_get_modem_info start\n"));
3427 if (!ch || ch->magic != DGAP_CHANNEL_MAGIC)
3430 DGAP_LOCK(ch->ch_lock, lock_flags);
3432 mstat = readb(&(ch->ch_bs->m_stat));
3433 /* Append any outbound signals that might be pending... */
3434 mstat |= ch->ch_mostat;
3436 DGAP_UNLOCK(ch->ch_lock, lock_flags);
3440 if (mstat & D_DTR(ch))
3441 result |= TIOCM_DTR;
3442 if (mstat & D_RTS(ch))
3443 result |= TIOCM_RTS;
3444 if (mstat & D_CTS(ch))
3445 result |= TIOCM_CTS;
3446 if (mstat & D_DSR(ch))
3447 result |= TIOCM_DSR;
3448 if (mstat & D_RI(ch))
3450 if (mstat & D_CD(ch))
3453 rc = put_user(result, value);
3455 DPR_IOCTL(("dgap_get_modem_info finish\n"));
3461 * dgap_set_modem_info()
3463 * Set modem signals, called by ld.
3465 static int dgap_set_modem_info(struct tty_struct *tty, unsigned int command, unsigned int __user *value)
3468 struct channel_t *ch;
3471 unsigned int arg = 0;
3475 if (!tty || tty->magic != TTY_MAGIC)
3478 un = tty->driver_data;
3479 if (!un || un->magic != DGAP_UNIT_MAGIC)
3483 if (!ch || ch->magic != DGAP_CHANNEL_MAGIC)
3487 if (!bd || bd->magic != DGAP_BOARD_MAGIC)
3490 DPR_IOCTL(("dgap_set_modem_info() start\n"));
3492 ret = get_user(arg, value);
3494 DPR_IOCTL(("dgap_set_modem_info %d ret: %x. finished.\n", __LINE__, ret));
3498 DPR_IOCTL(("dgap_set_modem_info: command: %x arg: %x\n", command, arg));
3502 if (arg & TIOCM_RTS) {
3503 ch->ch_mforce |= D_RTS(ch);
3504 ch->ch_mval |= D_RTS(ch);
3507 if (arg & TIOCM_DTR) {
3508 ch->ch_mforce |= D_DTR(ch);
3509 ch->ch_mval |= D_DTR(ch);
3515 if (arg & TIOCM_RTS) {
3516 ch->ch_mforce |= D_RTS(ch);
3517 ch->ch_mval &= ~(D_RTS(ch));
3520 if (arg & TIOCM_DTR) {
3521 ch->ch_mforce |= D_DTR(ch);
3522 ch->ch_mval &= ~(D_DTR(ch));
3528 ch->ch_mforce = D_DTR(ch)|D_RTS(ch);
3530 if (arg & TIOCM_RTS) {
3531 ch->ch_mval |= D_RTS(ch);
3534 ch->ch_mval &= ~(D_RTS(ch));
3537 if (arg & TIOCM_DTR) {
3538 ch->ch_mval |= (D_DTR(ch));
3541 ch->ch_mval &= ~(D_DTR(ch));
3550 DGAP_LOCK(bd->bd_lock, lock_flags);
3551 DGAP_LOCK(ch->ch_lock, lock_flags2);
3555 DGAP_UNLOCK(ch->ch_lock, lock_flags2);
3556 DGAP_UNLOCK(bd->bd_lock, lock_flags);
3558 DPR_IOCTL(("dgap_set_modem_info finish\n"));
3565 * dgap_tty_digigeta()
3567 * Ioctl to get the information for ditty.
3572 static int dgap_tty_digigeta(struct tty_struct *tty, struct digi_t __user *retinfo)
3574 struct channel_t *ch;
3582 if (!tty || tty->magic != TTY_MAGIC)
3585 un = tty->driver_data;
3586 if (!un || un->magic != DGAP_UNIT_MAGIC)
3590 if (!ch || ch->magic != DGAP_CHANNEL_MAGIC)
3593 memset(&tmp, 0, sizeof(tmp));
3595 DGAP_LOCK(ch->ch_lock, lock_flags);
3596 memcpy(&tmp, &ch->ch_digi, sizeof(tmp));
3597 DGAP_UNLOCK(ch->ch_lock, lock_flags);
3599 if (copy_to_user(retinfo, &tmp, sizeof(*retinfo)))
3607 * dgap_tty_digiseta()
3609 * Ioctl to set the information for ditty.
3614 static int dgap_tty_digiseta(struct tty_struct *tty, struct digi_t __user *new_info)
3617 struct channel_t *ch;
3619 struct digi_t new_digi;
3620 ulong lock_flags = 0;
3621 unsigned long lock_flags2;
3623 DPR_IOCTL(("DIGI_SETA start\n"));
3625 if (!tty || tty->magic != TTY_MAGIC)
3628 un = tty->driver_data;
3629 if (!un || un->magic != DGAP_UNIT_MAGIC)
3633 if (!ch || ch->magic != DGAP_CHANNEL_MAGIC)
3637 if (!bd || bd->magic != DGAP_BOARD_MAGIC)
3640 if (copy_from_user(&new_digi, new_info, sizeof(struct digi_t))) {
3641 DPR_IOCTL(("DIGI_SETA failed copy_from_user\n"));
3645 DGAP_LOCK(bd->bd_lock, lock_flags);
3646 DGAP_LOCK(ch->ch_lock, lock_flags2);
3648 memcpy(&ch->ch_digi, &new_digi, sizeof(struct digi_t));
3650 if (ch->ch_digi.digi_maxcps < 1)
3651 ch->ch_digi.digi_maxcps = 1;
3653 if (ch->ch_digi.digi_maxcps > 10000)
3654 ch->ch_digi.digi_maxcps = 10000;
3656 if (ch->ch_digi.digi_bufsize < 10)
3657 ch->ch_digi.digi_bufsize = 10;
3659 if (ch->ch_digi.digi_maxchar < 1)
3660 ch->ch_digi.digi_maxchar = 1;
3662 if (ch->ch_digi.digi_maxchar > ch->ch_digi.digi_bufsize)
3663 ch->ch_digi.digi_maxchar = ch->ch_digi.digi_bufsize;
3665 if (ch->ch_digi.digi_onlen > DIGI_PLEN)
3666 ch->ch_digi.digi_onlen = DIGI_PLEN;
3668 if (ch->ch_digi.digi_offlen > DIGI_PLEN)
3669 ch->ch_digi.digi_offlen = DIGI_PLEN;
3673 DGAP_UNLOCK(ch->ch_lock, lock_flags2);
3674 DGAP_UNLOCK(bd->bd_lock, lock_flags);
3676 DPR_IOCTL(("DIGI_SETA finish\n"));
3683 * dgap_tty_digigetedelay()
3685 * Ioctl to get the current edelay setting.
3690 static int dgap_tty_digigetedelay(struct tty_struct *tty, int __user *retinfo)
3692 struct channel_t *ch;
3700 if (!tty || tty->magic != TTY_MAGIC)
3703 un = tty->driver_data;
3704 if (!un || un->magic != DGAP_UNIT_MAGIC)
3708 if (!ch || ch->magic != DGAP_CHANNEL_MAGIC)
3711 memset(&tmp, 0, sizeof(tmp));
3713 DGAP_LOCK(ch->ch_lock, lock_flags);
3714 tmp = readw(&(ch->ch_bs->edelay));
3715 DGAP_UNLOCK(ch->ch_lock, lock_flags);
3717 if (copy_to_user(retinfo, &tmp, sizeof(*retinfo)))
3725 * dgap_tty_digisetedelay()
3727 * Ioctl to set the EDELAY setting
3730 static int dgap_tty_digisetedelay(struct tty_struct *tty, int __user *new_info)
3733 struct channel_t *ch;
3739 DPR_IOCTL(("DIGI_SETA start\n"));
3741 if (!tty || tty->magic != TTY_MAGIC)
3744 un = tty->driver_data;
3745 if (!un || un->magic != DGAP_UNIT_MAGIC)
3749 if (!ch || ch->magic != DGAP_CHANNEL_MAGIC)
3753 if (!bd || bd->magic != DGAP_BOARD_MAGIC)
3756 if (copy_from_user(&new_digi, new_info, sizeof(int))) {
3757 DPR_IOCTL(("DIGI_SETEDELAY failed copy_from_user\n"));
3761 DGAP_LOCK(bd->bd_lock, lock_flags);
3762 DGAP_LOCK(ch->ch_lock, lock_flags2);
3764 writew((u16) new_digi, &(ch->ch_bs->edelay));
3768 DGAP_UNLOCK(ch->ch_lock, lock_flags2);
3769 DGAP_UNLOCK(bd->bd_lock, lock_flags);
3771 DPR_IOCTL(("DIGI_SETA finish\n"));
3778 * dgap_tty_digigetcustombaud()
3780 * Ioctl to get the current custom baud rate setting.
3782 static int dgap_tty_digigetcustombaud(struct tty_struct *tty, int __user *retinfo)
3784 struct channel_t *ch;
3792 if (!tty || tty->magic != TTY_MAGIC)
3795 un = tty->driver_data;
3796 if (!un || un->magic != DGAP_UNIT_MAGIC)
3800 if (!ch || ch->magic != DGAP_CHANNEL_MAGIC)
3803 memset(&tmp, 0, sizeof(tmp));
3805 DGAP_LOCK(ch->ch_lock, lock_flags);
3806 tmp = dgap_get_custom_baud(ch);
3807 DGAP_UNLOCK(ch->ch_lock, lock_flags);
3809 DPR_IOCTL(("DIGI_GETCUSTOMBAUD. Returning %d\n", tmp));
3811 if (copy_to_user(retinfo, &tmp, sizeof(*retinfo)))
3819 * dgap_tty_digisetcustombaud()
3821 * Ioctl to set the custom baud rate setting
3823 static int dgap_tty_digisetcustombaud(struct tty_struct *tty, int __user *new_info)
3826 struct channel_t *ch;
3832 DPR_IOCTL(("DIGI_SETCUSTOMBAUD start\n"));
3834 if (!tty || tty->magic != TTY_MAGIC)
3837 un = tty->driver_data;
3838 if (!un || un->magic != DGAP_UNIT_MAGIC)
3842 if (!ch || ch->magic != DGAP_CHANNEL_MAGIC)
3846 if (!bd || bd->magic != DGAP_BOARD_MAGIC)
3850 if (copy_from_user(&new_rate, new_info, sizeof(unsigned int))) {
3851 DPR_IOCTL(("DIGI_SETCUSTOMBAUD failed copy_from_user\n"));
3855 if (bd->bd_flags & BD_FEP5PLUS) {
3857 DPR_IOCTL(("DIGI_SETCUSTOMBAUD. Setting %d\n", new_rate));
3859 DGAP_LOCK(bd->bd_lock, lock_flags);
3860 DGAP_LOCK(ch->ch_lock, lock_flags2);
3862 ch->ch_custom_speed = new_rate;
3866 DGAP_UNLOCK(ch->ch_lock, lock_flags2);
3867 DGAP_UNLOCK(bd->bd_lock, lock_flags);
3870 DPR_IOCTL(("DIGI_SETCUSTOMBAUD finish\n"));
3877 * dgap_set_termios()
3879 static void dgap_tty_set_termios(struct tty_struct *tty, struct ktermios *old_termios)
3882 struct channel_t *ch;
3884 unsigned long lock_flags;
3885 unsigned long lock_flags2;
3887 if (!tty || tty->magic != TTY_MAGIC)
3890 un = tty->driver_data;
3891 if (!un || un->magic != DGAP_UNIT_MAGIC)
3895 if (!ch || ch->magic != DGAP_CHANNEL_MAGIC)
3899 if (!bd || bd->magic != DGAP_BOARD_MAGIC)
3902 DGAP_LOCK(bd->bd_lock, lock_flags);
3903 DGAP_LOCK(ch->ch_lock, lock_flags2);
3905 ch->ch_c_cflag = tty->termios.c_cflag;
3906 ch->ch_c_iflag = tty->termios.c_iflag;
3907 ch->ch_c_oflag = tty->termios.c_oflag;
3908 ch->ch_c_lflag = tty->termios.c_lflag;
3909 ch->ch_startc = tty->termios.c_cc[VSTART];
3910 ch->ch_stopc = tty->termios.c_cc[VSTOP];
3915 DGAP_UNLOCK(ch->ch_lock, lock_flags2);
3916 DGAP_UNLOCK(bd->bd_lock, lock_flags);
3920 static void dgap_tty_throttle(struct tty_struct *tty)
3923 struct channel_t *ch;
3928 if (!tty || tty->magic != TTY_MAGIC)
3931 un = tty->driver_data;
3932 if (!un || un->magic != DGAP_UNIT_MAGIC)
3936 if (!ch || ch->magic != DGAP_CHANNEL_MAGIC)
3940 if (!bd || bd->magic != DGAP_BOARD_MAGIC)
3943 DPR_IOCTL(("dgap_tty_throttle start\n"));
3945 DGAP_LOCK(bd->bd_lock, lock_flags);
3946 DGAP_LOCK(ch->ch_lock, lock_flags2);
3948 ch->ch_flags |= (CH_RXBLOCK);
3950 dgap_cmdw(ch, RPAUSE, 0, 0);
3953 DGAP_UNLOCK(ch->ch_lock, lock_flags2);
3954 DGAP_UNLOCK(bd->bd_lock, lock_flags);
3956 DPR_IOCTL(("dgap_tty_throttle finish\n"));
3960 static void dgap_tty_unthrottle(struct tty_struct *tty)
3963 struct channel_t *ch;
3968 if (!tty || tty->magic != TTY_MAGIC)
3971 un = tty->driver_data;
3972 if (!un || un->magic != DGAP_UNIT_MAGIC)
3976 if (!ch || ch->magic != DGAP_CHANNEL_MAGIC)
3980 if (!bd || bd->magic != DGAP_BOARD_MAGIC)
3983 DPR_IOCTL(("dgap_tty_unthrottle start\n"));
3985 DGAP_LOCK(bd->bd_lock, lock_flags);
3986 DGAP_LOCK(ch->ch_lock, lock_flags2);
3988 ch->ch_flags &= ~(CH_RXBLOCK);
3991 dgap_cmdw(ch, RRESUME, 0, 0);
3994 DGAP_UNLOCK(ch->ch_lock, lock_flags2);
3995 DGAP_UNLOCK(bd->bd_lock, lock_flags);
3997 DPR_IOCTL(("dgap_tty_unthrottle finish\n"));
4001 static void dgap_tty_start(struct tty_struct *tty)
4004 struct channel_t *ch;
4009 if (!tty || tty->magic != TTY_MAGIC)
4012 un = tty->driver_data;
4013 if (!un || un->magic != DGAP_UNIT_MAGIC)
4017 if (!ch || ch->magic != DGAP_CHANNEL_MAGIC)
4021 if (!bd || bd->magic != DGAP_BOARD_MAGIC)
4024 DPR_IOCTL(("dgap_tty_start start\n"));
4026 DGAP_LOCK(bd->bd_lock, lock_flags);
4027 DGAP_LOCK(ch->ch_lock, lock_flags2);
4029 dgap_cmdw(ch, RESUMETX, 0, 0);
4031 DGAP_UNLOCK(ch->ch_lock, lock_flags2);
4032 DGAP_UNLOCK(bd->bd_lock, lock_flags);
4034 DPR_IOCTL(("dgap_tty_start finish\n"));
4038 static void dgap_tty_stop(struct tty_struct *tty)
4041 struct channel_t *ch;
4046 if (!tty || tty->magic != TTY_MAGIC)
4049 un = tty->driver_data;
4050 if (!un || un->magic != DGAP_UNIT_MAGIC)
4054 if (!ch || ch->magic != DGAP_CHANNEL_MAGIC)
4058 if (!bd || bd->magic != DGAP_BOARD_MAGIC)
4061 DPR_IOCTL(("dgap_tty_stop start\n"));
4063 DGAP_LOCK(bd->bd_lock, lock_flags);
4064 DGAP_LOCK(ch->ch_lock, lock_flags2);
4066 dgap_cmdw(ch, PAUSETX, 0, 0);
4068 DGAP_UNLOCK(ch->ch_lock, lock_flags2);
4069 DGAP_UNLOCK(bd->bd_lock, lock_flags);
4071 DPR_IOCTL(("dgap_tty_stop finish\n"));
4076 * dgap_tty_flush_chars()
4078 * Flush the cook buffer
4080 * Note to self, and any other poor souls who venture here:
4082 * flush in this case DOES NOT mean dispose of the data.
4083 * instead, it means "stop buffering and send it if you
4084 * haven't already." Just guess how I figured that out... SRW 2-Jun-98
4086 * It is also always called in interrupt context - JAR 8-Sept-99
4088 static void dgap_tty_flush_chars(struct tty_struct *tty)
4091 struct channel_t *ch;
4096 if (!tty || tty->magic != TTY_MAGIC)
4099 un = tty->driver_data;
4100 if (!un || un->magic != DGAP_UNIT_MAGIC)
4104 if (!ch || ch->magic != DGAP_CHANNEL_MAGIC)
4108 if (!bd || bd->magic != DGAP_BOARD_MAGIC)
4111 DPR_IOCTL(("dgap_tty_flush_chars start\n"));
4113 DGAP_LOCK(bd->bd_lock, lock_flags);
4114 DGAP_LOCK(ch->ch_lock, lock_flags2);
4116 /* TODO: Do something here */
4118 DGAP_UNLOCK(ch->ch_lock, lock_flags2);
4119 DGAP_UNLOCK(bd->bd_lock, lock_flags);
4121 DPR_IOCTL(("dgap_tty_flush_chars finish\n"));
4127 * dgap_tty_flush_buffer()
4129 * Flush Tx buffer (make in == out)
4131 static void dgap_tty_flush_buffer(struct tty_struct *tty)
4134 struct channel_t *ch;
4140 if (!tty || tty->magic != TTY_MAGIC)
4143 un = tty->driver_data;
4144 if (!un || un->magic != DGAP_UNIT_MAGIC)
4148 if (!ch || ch->magic != DGAP_CHANNEL_MAGIC)
4152 if (!bd || bd->magic != DGAP_BOARD_MAGIC)
4155 DPR_IOCTL(("dgap_tty_flush_buffer on port: %d start\n", ch->ch_portnum));
4157 DGAP_LOCK(bd->bd_lock, lock_flags);
4158 DGAP_LOCK(ch->ch_lock, lock_flags2);
4160 ch->ch_flags &= ~CH_STOP;
4161 head = readw(&(ch->ch_bs->tx_head));
4162 dgap_cmdw(ch, FLUSHTX, (u16) head, 0);
4163 dgap_cmdw(ch, RESUMETX, 0, 0);
4164 if (ch->ch_tun.un_flags & (UN_LOW|UN_EMPTY)) {
4165 ch->ch_tun.un_flags &= ~(UN_LOW|UN_EMPTY);
4166 wake_up_interruptible(&ch->ch_tun.un_flags_wait);
4168 if (ch->ch_pun.un_flags & (UN_LOW|UN_EMPTY)) {
4169 ch->ch_pun.un_flags &= ~(UN_LOW|UN_EMPTY);
4170 wake_up_interruptible(&ch->ch_pun.un_flags_wait);
4173 DGAP_UNLOCK(ch->ch_lock, lock_flags2);
4174 DGAP_UNLOCK(bd->bd_lock, lock_flags);
4175 if (waitqueue_active(&tty->write_wait))
4176 wake_up_interruptible(&tty->write_wait);
4179 DPR_IOCTL(("dgap_tty_flush_buffer finish\n"));
4184 /*****************************************************************************
4186 * The IOCTL function and all of its helpers
4188 *****************************************************************************/
4193 * The usual assortment of ioctl's
4195 static int dgap_tty_ioctl(struct tty_struct *tty, unsigned int cmd,
4199 struct channel_t *ch;
4203 ulong lock_flags = 0;
4204 ulong lock_flags2 = 0;
4205 void __user *uarg = (void __user *) arg;
4207 if (!tty || tty->magic != TTY_MAGIC)
4210 un = tty->driver_data;
4211 if (!un || un->magic != DGAP_UNIT_MAGIC)
4215 if (!ch || ch->magic != DGAP_CHANNEL_MAGIC)
4219 if (!bd || bd->magic != DGAP_BOARD_MAGIC)
4222 DPR_IOCTL(("dgap_tty_ioctl start on port %d - cmd %s (%x), arg %lx\n",
4223 ch->ch_portnum, dgap_ioctl_name(cmd), cmd, arg));
4225 DGAP_LOCK(bd->bd_lock, lock_flags);
4226 DGAP_LOCK(ch->ch_lock, lock_flags2);
4228 if (un->un_open_count <= 0) {
4229 DPR_BASIC(("dgap_tty_ioctl - unit not open.\n"));
4230 DGAP_UNLOCK(ch->ch_lock, lock_flags2);
4231 DGAP_UNLOCK(bd->bd_lock, lock_flags);
4237 /* Here are all the standard ioctl's that we MUST implement */
4241 * TCSBRK is SVID version: non-zero arg --> no break
4242 * this behaviour is exploited by tcdrain().
4244 * According to POSIX.1 spec (7.2.2.1.2) breaks should be
4245 * between 0.25 and 0.5 seconds so we'll ask for something
4246 * in the middle: 0.375 seconds.
4248 rc = tty_check_change(tty);
4249 DGAP_UNLOCK(ch->ch_lock, lock_flags2);
4250 DGAP_UNLOCK(bd->bd_lock, lock_flags);
4255 rc = dgap_wait_for_drain(tty);
4258 DPR_IOCTL(("dgap_tty_ioctl - bad return: %d ", rc));
4262 DGAP_LOCK(bd->bd_lock, lock_flags);
4263 DGAP_LOCK(ch->ch_lock, lock_flags2);
4265 if(((cmd == TCSBRK) && (!arg)) || (cmd == TCSBRKP)) {
4266 dgap_cmdw(ch, SBREAK, (u16) SBREAK_TIME, 0);
4269 DGAP_UNLOCK(ch->ch_lock, lock_flags2);
4270 DGAP_UNLOCK(bd->bd_lock, lock_flags);
4272 DPR_IOCTL(("dgap_tty_ioctl finish on port %d - cmd %s (%x), arg %lx\n",
4273 ch->ch_portnum, dgap_ioctl_name(cmd), cmd, arg));
4279 /* support for POSIX tcsendbreak()
4281 * According to POSIX.1 spec (7.2.2.1.2) breaks should be
4282 * between 0.25 and 0.5 seconds so we'll ask for something
4283 * in the middle: 0.375 seconds.
4285 rc = tty_check_change(tty);
4286 DGAP_UNLOCK(ch->ch_lock, lock_flags2);
4287 DGAP_UNLOCK(bd->bd_lock, lock_flags);
4292 rc = dgap_wait_for_drain(tty);
4294 DPR_IOCTL(("dgap_tty_ioctl - bad return: %d ", rc));
4298 DGAP_LOCK(bd->bd_lock, lock_flags);
4299 DGAP_LOCK(ch->ch_lock, lock_flags2);
4301 dgap_cmdw(ch, SBREAK, (u16) SBREAK_TIME, 0);
4303 DGAP_UNLOCK(ch->ch_lock, lock_flags2);
4304 DGAP_UNLOCK(bd->bd_lock, lock_flags);
4306 DPR_IOCTL(("dgap_tty_ioctl finish on port %d - cmd %s (%x), arg %lx\n",
4307 ch->ch_portnum, dgap_ioctl_name(cmd), cmd, arg));
4313 * FEP5 doesn't support turning on a break unconditionally.
4314 * The FEP5 device will stop sending a break automatically
4315 * after the specified time value that was sent when turning on
4318 rc = tty_check_change(tty);
4319 DGAP_UNLOCK(ch->ch_lock, lock_flags2);
4320 DGAP_UNLOCK(bd->bd_lock, lock_flags);
4325 rc = dgap_wait_for_drain(tty);
4327 DPR_IOCTL(("dgap_tty_ioctl - bad return: %d ", rc));
4331 DGAP_LOCK(bd->bd_lock, lock_flags);
4332 DGAP_LOCK(ch->ch_lock, lock_flags2);
4334 dgap_cmdw(ch, SBREAK, (u16) SBREAK_TIME, 0);
4336 DGAP_UNLOCK(ch->ch_lock, lock_flags2);
4337 DGAP_UNLOCK(bd->bd_lock, lock_flags);
4339 DPR_IOCTL(("dgap_tty_ioctl finish on port %d - cmd %s (%x), arg %lx\n",
4340 ch->ch_portnum, dgap_ioctl_name(cmd), cmd, arg));
4346 * FEP5 doesn't support turning off a break unconditionally.
4347 * The FEP5 device will stop sending a break automatically
4348 * after the specified time value that was sent when turning on
4351 DGAP_UNLOCK(ch->ch_lock, lock_flags2);
4352 DGAP_UNLOCK(bd->bd_lock, lock_flags);
4357 DGAP_UNLOCK(ch->ch_lock, lock_flags2);
4358 DGAP_UNLOCK(bd->bd_lock, lock_flags);
4360 rc = put_user(C_CLOCAL(tty) ? 1 : 0, (unsigned long __user *) arg);
4364 DGAP_UNLOCK(ch->ch_lock, lock_flags2);
4365 DGAP_UNLOCK(bd->bd_lock, lock_flags);
4367 rc = get_user(arg, (unsigned long __user *) arg);
4371 DGAP_LOCK(bd->bd_lock, lock_flags);
4372 DGAP_LOCK(ch->ch_lock, lock_flags2);
4373 tty->termios.c_cflag = ((tty->termios.c_cflag & ~CLOCAL) | (arg ? CLOCAL : 0));
4375 DGAP_UNLOCK(ch->ch_lock, lock_flags2);
4376 DGAP_UNLOCK(bd->bd_lock, lock_flags);
4381 DGAP_UNLOCK(ch->ch_lock, lock_flags2);
4382 DGAP_UNLOCK(bd->bd_lock, lock_flags);
4383 return(dgap_get_modem_info(ch, uarg));
4388 DGAP_UNLOCK(ch->ch_lock, lock_flags2);
4389 DGAP_UNLOCK(bd->bd_lock, lock_flags);
4390 return(dgap_set_modem_info(tty, cmd, uarg));
4393 * Here are any additional ioctl's that we want to implement
4398 * The linux tty driver doesn't have a flush
4399 * input routine for the driver, assuming all backed
4400 * up data is in the line disc. buffers. However,
4401 * we all know that's not the case. Here, we
4402 * act on the ioctl, but then lie and say we didn't
4403 * so the line discipline will process the flush
4406 rc = tty_check_change(tty);
4408 DGAP_UNLOCK(ch->ch_lock, lock_flags2);
4409 DGAP_UNLOCK(bd->bd_lock, lock_flags);
4413 if ((arg == TCIFLUSH) || (arg == TCIOFLUSH)) {
4414 if (!(un->un_type == DGAP_PRINT)) {
4415 head = readw(&(ch->ch_bs->rx_head));
4416 writew(head, &(ch->ch_bs->rx_tail));
4417 writeb(0, &(ch->ch_bs->orun));
4421 if ((arg == TCOFLUSH) || (arg == TCIOFLUSH)) {
4422 ch->ch_flags &= ~CH_STOP;
4423 head = readw(&(ch->ch_bs->tx_head));
4424 dgap_cmdw(ch, FLUSHTX, (u16) head, 0 );
4425 dgap_cmdw(ch, RESUMETX, 0, 0);
4426 if (ch->ch_tun.un_flags & (UN_LOW|UN_EMPTY)) {
4427 ch->ch_tun.un_flags &= ~(UN_LOW|UN_EMPTY);
4428 wake_up_interruptible(&ch->ch_tun.un_flags_wait);
4430 if (ch->ch_pun.un_flags & (UN_LOW|UN_EMPTY)) {
4431 ch->ch_pun.un_flags &= ~(UN_LOW|UN_EMPTY);
4432 wake_up_interruptible(&ch->ch_pun.un_flags_wait);
4434 if (waitqueue_active(&tty->write_wait))
4435 wake_up_interruptible(&tty->write_wait);
4437 /* Can't hold any locks when calling tty_wakeup! */
4438 DGAP_UNLOCK(ch->ch_lock, lock_flags2);
4439 DGAP_UNLOCK(bd->bd_lock, lock_flags);
4441 DGAP_LOCK(bd->bd_lock, lock_flags);
4442 DGAP_LOCK(ch->ch_lock, lock_flags2);
4445 /* pretend we didn't recognize this IOCTL */
4446 DGAP_UNLOCK(ch->ch_lock, lock_flags2);
4447 DGAP_UNLOCK(bd->bd_lock, lock_flags);
4449 DPR_IOCTL(("dgap_tty_ioctl (LINE:%d) finish on port %d - cmd %s (%x), arg %lx\n",
4450 __LINE__, ch->ch_portnum, dgap_ioctl_name(cmd), cmd, arg));
4452 return(-ENOIOCTLCMD);
4457 * The linux tty driver doesn't have a flush
4458 * input routine for the driver, assuming all backed
4459 * up data is in the line disc. buffers. However,
4460 * we all know that's not the case. Here, we
4461 * act on the ioctl, but then lie and say we didn't
4462 * so the line discipline will process the flush
4465 if (cmd == TCSETSF) {
4467 ch->ch_flags &= ~CH_STOP;
4468 head = readw(&(ch->ch_bs->rx_head));
4469 writew(head, &(ch->ch_bs->rx_tail));
4472 /* now wait for all the output to drain */
4473 DGAP_UNLOCK(ch->ch_lock, lock_flags2);
4474 DGAP_UNLOCK(bd->bd_lock, lock_flags);
4475 rc = dgap_wait_for_drain(tty);
4477 DPR_IOCTL(("dgap_tty_ioctl - bad return: %d ", rc));
4481 DPR_IOCTL(("dgap_tty_ioctl finish on port %d - cmd %s (%x), arg %lx\n",
4482 ch->ch_portnum, dgap_ioctl_name(cmd), cmd, arg));
4484 /* pretend we didn't recognize this */
4485 return(-ENOIOCTLCMD);
4489 DGAP_UNLOCK(ch->ch_lock, lock_flags2);
4490 DGAP_UNLOCK(bd->bd_lock, lock_flags);
4491 rc = dgap_wait_for_drain(tty);
4493 DPR_IOCTL(("dgap_tty_ioctl - bad return: %d ", rc));
4497 /* pretend we didn't recognize this */
4498 return(-ENOIOCTLCMD);
4502 * The Linux Line Discipline (LD) would do this for us if we
4503 * let it, but we have the special firmware options to do this
4504 * the "right way" regardless of hardware or software flow
4505 * control so we'll do it outselves instead of letting the LD
4508 rc = tty_check_change(tty);
4510 DGAP_UNLOCK(ch->ch_lock, lock_flags2);
4511 DGAP_UNLOCK(bd->bd_lock, lock_flags);
4515 DPR_IOCTL(("dgap_ioctl - in TCXONC - %d\n", cmd));
4519 DGAP_UNLOCK(ch->ch_lock, lock_flags2);
4520 DGAP_UNLOCK(bd->bd_lock, lock_flags);
4521 dgap_tty_start(tty);
4524 DGAP_UNLOCK(ch->ch_lock, lock_flags2);
4525 DGAP_UNLOCK(bd->bd_lock, lock_flags);
4529 DGAP_UNLOCK(ch->ch_lock, lock_flags2);
4530 DGAP_UNLOCK(bd->bd_lock, lock_flags);
4531 /* Make the ld do it */
4532 return(-ENOIOCTLCMD);
4534 DGAP_UNLOCK(ch->ch_lock, lock_flags2);
4535 DGAP_UNLOCK(bd->bd_lock, lock_flags);
4536 /* Make the ld do it */
4537 return(-ENOIOCTLCMD);
4539 DGAP_UNLOCK(ch->ch_lock, lock_flags2);
4540 DGAP_UNLOCK(bd->bd_lock, lock_flags);
4545 /* get information for ditty */
4546 DGAP_UNLOCK(ch->ch_lock, lock_flags2);
4547 DGAP_UNLOCK(bd->bd_lock, lock_flags);
4548 return(dgap_tty_digigeta(tty, uarg));
4553 /* set information for ditty */
4554 if (cmd == (DIGI_SETAW)) {
4556 DGAP_UNLOCK(ch->ch_lock, lock_flags2);
4557 DGAP_UNLOCK(bd->bd_lock, lock_flags);
4558 rc = dgap_wait_for_drain(tty);
4560 DPR_IOCTL(("dgap_tty_ioctl - bad return: %d ", rc));
4563 DGAP_LOCK(bd->bd_lock, lock_flags);
4564 DGAP_LOCK(ch->ch_lock, lock_flags2);
4567 tty_ldisc_flush(tty);
4572 DGAP_UNLOCK(ch->ch_lock, lock_flags2);
4573 DGAP_UNLOCK(bd->bd_lock, lock_flags);
4574 return(dgap_tty_digiseta(tty, uarg));
4577 DGAP_UNLOCK(ch->ch_lock, lock_flags2);
4578 DGAP_UNLOCK(bd->bd_lock, lock_flags);
4579 return(dgap_tty_digigetedelay(tty, uarg));
4582 DGAP_UNLOCK(ch->ch_lock, lock_flags2);
4583 DGAP_UNLOCK(bd->bd_lock, lock_flags);
4584 return(dgap_tty_digisetedelay(tty, uarg));
4586 case DIGI_GETCUSTOMBAUD:
4587 DGAP_UNLOCK(ch->ch_lock, lock_flags2);
4588 DGAP_UNLOCK(bd->bd_lock, lock_flags);
4589 return(dgap_tty_digigetcustombaud(tty, uarg));
4591 case DIGI_SETCUSTOMBAUD:
4592 DGAP_UNLOCK(ch->ch_lock, lock_flags2);
4593 DGAP_UNLOCK(bd->bd_lock, lock_flags);
4594 return(dgap_tty_digisetcustombaud(tty, uarg));
4596 case DIGI_RESET_PORT:
4597 dgap_firmware_reset_port(ch);
4599 DGAP_UNLOCK(ch->ch_lock, lock_flags2);
4600 DGAP_UNLOCK(bd->bd_lock, lock_flags);
4604 DGAP_UNLOCK(ch->ch_lock, lock_flags2);
4605 DGAP_UNLOCK(bd->bd_lock, lock_flags);
4607 DPR_IOCTL(("dgap_tty_ioctl - in default\n"));
4608 DPR_IOCTL(("dgap_tty_ioctl end - cmd %s (%x), arg %lx\n",
4609 dgap_ioctl_name(cmd), cmd, arg));
4611 return(-ENOIOCTLCMD);
4615 * Loads the dgap.conf config file from the user.
4617 void dgap_do_config_load(uchar __user *uaddr, int len)
4621 uchar __user *from_addr = uaddr;
4625 to_addr = dgap_config_buf = kzalloc(len + 1, GFP_ATOMIC);
4626 if (!dgap_config_buf) {
4627 DPR_INIT(("dgap_do_config_load - unable to allocate memory for file\n"));
4628 dgap_driver_state = DRIVER_NEED_CONFIG_LOAD;
4638 if (copy_from_user((char *) &buf, from_addr, n) == -1 )
4641 /* Copy data from buffer to kernel memory */
4642 memcpy(to_addr, buf, n);
4644 /* increment counts */
4651 dgap_config_buf[orig_len] = '\0';
4653 to_addr = dgap_config_buf;
4654 dgap_parsefile(&to_addr, TRUE);
4656 DPR_INIT(("dgap_config_load() finish\n"));
4662 int dgap_after_config_loaded(void)
4668 * Register our ttys, now that we have the config loaded.
4670 for (i = 0; i < dgap_NumBoards; ++i) {
4673 * Initialize KME waitqueues...
4675 init_waitqueue_head(&(dgap_Board[i]->kme_wait));
4678 * allocate flip buffer for board.
4680 dgap_Board[i]->flipbuf = kzalloc(MYFLIPLEN, GFP_ATOMIC);
4681 dgap_Board[i]->flipflagbuf = kzalloc(MYFLIPLEN, GFP_ATOMIC);
4689 /*=======================================================================
4691 * usertoboard - copy from user space to board space.
4693 *=======================================================================*/
4694 static int dgap_usertoboard(struct board_t *brd, char *to_addr, char __user *from_addr, int len)
4699 if (!brd || brd->magic != DGAP_BOARD_MAGIC)
4706 if (copy_from_user((char *) &buf, from_addr, n) == -1 ) {
4710 /* Copy data from buffer to card memory */
4711 memcpy_toio(to_addr, buf, n);
4713 /* increment counts */
4724 * Copies the BIOS code from the user to the board,
4725 * and starts the BIOS running.
4727 void dgap_do_bios_load(struct board_t *brd, uchar __user *ubios, int len)
4733 if (!brd || (brd->magic != DGAP_BOARD_MAGIC) || !brd->re_map_membase)
4736 DPR_INIT(("dgap_do_bios_load() start\n"));
4738 addr = brd->re_map_membase;
4743 for (i = 0; i < 16; i++)
4744 writeb(0, addr + POSTAREA + i);
4750 if (dgap_usertoboard(brd, addr + offset, ubios, len) == -1 ) {
4751 brd->state = BOARD_FAILED;
4752 brd->dpastatus = BD_NOFEP;
4756 writel(0x0bf00401, addr);
4757 writel(0, (addr + 4));
4759 /* Clear the reset, and change states. */
4760 writeb(FEPCLR, brd->re_map_port);
4761 brd->state = WAIT_BIOS_LOAD;
4766 * Checks to see if the BIOS completed running on the card.
4768 static void dgap_do_wait_for_bios(struct board_t *brd)
4773 if (!brd || (brd->magic != DGAP_BOARD_MAGIC) || !brd->re_map_membase)
4776 addr = brd->re_map_membase;
4777 word = readw(addr + POSTAREA);
4779 /* Check to see if BIOS thinks board is good. (GD). */
4780 if (word == *(u16 *) "GD") {
4781 DPR_INIT(("GOT GD in memory, moving states.\n"));
4782 brd->state = FINISHED_BIOS_LOAD;
4786 /* Give up on board after too long of time taken */
4787 if (brd->wait_for_bios++ > 5000) {
4788 u16 err1 = readw(addr + SEQUENCE);
4789 u16 err2 = readw(addr + ERROR);
4790 APR(("***WARNING*** %s failed diagnostics. Error #(%x,%x).\n",
4791 brd->name, err1, err2));
4792 brd->state = BOARD_FAILED;
4793 brd->dpastatus = BD_NOFEP;
4799 * Copies the FEP code from the user to the board,
4800 * and starts the FEP running.
4802 void dgap_do_fep_load(struct board_t *brd, uchar __user *ufep, int len)
4807 if (!brd || (brd->magic != DGAP_BOARD_MAGIC) || !brd->re_map_membase)
4810 addr = brd->re_map_membase;
4812 DPR_INIT(("dgap_do_fep_load() for board %s : start\n", brd->name));
4818 if (dgap_usertoboard(brd, addr + offset, ufep, len) == -1 ) {
4819 brd->state = BOARD_FAILED;
4820 brd->dpastatus = BD_NOFEP;
4825 * If board is a concentrator product, we need to give
4826 * it its config string describing how the concentrators look.
4828 if ((brd->type == PCX) || (brd->type == PEPC)) {
4830 uchar *config, *xconfig;
4833 xconfig = dgap_create_config_string(brd, string);
4835 /* Write string to board memory */
4836 config = addr + CONFIG;
4837 for (; i < CONFIGSIZE; i++, config++, xconfig++) {
4838 writeb(*xconfig, config);
4839 if ((*xconfig & 0xff) == 0xff)
4844 writel(0xbfc01004, (addr + 0xc34));
4845 writel(0x3, (addr + 0xc30));
4847 /* change states. */
4848 brd->state = WAIT_FEP_LOAD;
4850 DPR_INIT(("dgap_do_fep_load() for board %s : finish\n", brd->name));
4856 * Waits for the FEP to report thats its ready for us to use.
4858 static void dgap_do_wait_for_fep(struct board_t *brd)
4863 if (!brd || (brd->magic != DGAP_BOARD_MAGIC) || !brd->re_map_membase)
4866 addr = brd->re_map_membase;
4868 DPR_INIT(("dgap_do_wait_for_fep() for board %s : start. addr: %p\n", brd->name, addr));
4870 word = readw(addr + FEPSTAT);
4872 /* Check to see if FEP is up and running now. */
4873 if (word == *(u16 *) "OS") {
4874 DPR_INIT(("GOT OS in memory for board %s, moving states.\n", brd->name));
4875 brd->state = FINISHED_FEP_LOAD;
4878 * Check to see if the board can support FEP5+ commands.
4880 word = readw(addr + FEP5_PLUS);
4881 if (word == *(u16 *) "5A") {
4882 DPR_INIT(("GOT 5A in memory for board %s, board supports extended FEP5 commands.\n", brd->name));
4883 brd->bd_flags |= BD_FEP5PLUS;
4889 /* Give up on board after too long of time taken */
4890 if (brd->wait_for_fep++ > 5000) {
4891 u16 err1 = readw(addr + SEQUENCE);
4892 u16 err2 = readw(addr + ERROR);
4893 APR(("***WARNING*** FEPOS for %s not functioning. Error #(%x,%x).\n",
4894 brd->name, err1, err2));
4895 brd->state = BOARD_FAILED;
4896 brd->dpastatus = BD_NOFEP;
4899 DPR_INIT(("dgap_do_wait_for_fep() for board %s : finish\n", brd->name));
4904 * Physically forces the FEP5 card to reset itself.
4906 static void dgap_do_reset_board(struct board_t *brd)
4913 if (!brd || (brd->magic != DGAP_BOARD_MAGIC) || !brd->re_map_membase || !brd->re_map_port) {
4914 DPR_INIT(("dgap_do_reset_board() start. bad values. brd: %p mem: %p io: %p\n",
4915 brd, brd ? brd->re_map_membase : 0, brd ? brd->re_map_port : 0));
4919 DPR_INIT(("dgap_do_reset_board() start. io: %p\n", brd->re_map_port));
4921 /* FEPRST does not vary among supported boards */
4922 writeb(FEPRST, brd->re_map_port);
4924 for (i = 0; i <= 1000; i++) {
4925 check = readb(brd->re_map_port) & 0xe;
4926 if (check == FEPRST)
4932 APR(("*** WARNING *** Board not resetting... Failing board.\n"));
4933 brd->state = BOARD_FAILED;
4934 brd->dpastatus = BD_NOFEP;
4939 * Make sure there really is memory out there.
4941 writel(0xa55a3cc3, (brd->re_map_membase + LOWMEM));
4942 writel(0x5aa5c33c, (brd->re_map_membase + HIGHMEM));
4943 check1 = readl(brd->re_map_membase + LOWMEM);
4944 check2 = readl(brd->re_map_membase + HIGHMEM);
4946 if ((check1 != 0xa55a3cc3) || (check2 != 0x5aa5c33c)) {
4947 APR(("*** Warning *** No memory at %p for board.\n", brd->re_map_membase));
4948 brd->state = BOARD_FAILED;
4949 brd->dpastatus = BD_NOFEP;
4953 if (brd->state != BOARD_FAILED)
4954 brd->state = FINISHED_RESET;
4957 DPR_INIT(("dgap_do_reset_board() finish\n"));
4962 * Sends a concentrator image into the FEP5 board.
4964 void dgap_do_conc_load(struct board_t *brd, uchar *uaddr, int len)
4968 struct downld_t *to_dp;
4970 if (!brd || (brd->magic != DGAP_BOARD_MAGIC) || !brd->re_map_membase)
4973 vaddr = brd->re_map_membase;
4975 offset = readw((u16 *) (vaddr + DOWNREQ));
4976 to_dp = (struct downld_t *) (vaddr + (int) offset);
4979 * The image was already read into kernel space,
4980 * we do NOT need a user space read here
4982 memcpy_toio((char *) to_dp, uaddr, sizeof(struct downld_t));
4984 /* Tell card we have data for it */
4985 writew(0, vaddr + (DOWNREQ));
4987 brd->conc_dl_status = NO_PENDING_CONCENTRATOR_REQUESTS;
4991 #define EXPANSION_ROM_SIZE (64 * 1024)
4992 #define FEP5_ROM_MAGIC (0xFEFFFFFF)
4994 static void dgap_get_vpd(struct board_t *brd)
5006 * Poke the magic number at the PCI Rom Address location.
5007 * If VPD is supported, the value read from that address
5010 magic = FEP5_ROM_MAGIC;
5011 pci_write_config_dword(brd->pdev, PCI_ROM_ADDRESS, magic);
5012 pci_read_config_dword(brd->pdev, PCI_ROM_ADDRESS, &magic);
5014 /* VPD not supported, bail */
5019 * To get to the OTPROM memory, we have to send the boards base
5020 * address or'ed with 1 into the PCI Rom Address location.
5022 magic = brd->membase | 0x01;
5023 pci_write_config_dword(brd->pdev, PCI_ROM_ADDRESS, magic);
5024 pci_read_config_dword(brd->pdev, PCI_ROM_ADDRESS, &magic);
5026 byte1 = readb(brd->re_map_membase);
5027 byte2 = readb(brd->re_map_membase + 1);
5030 * If the board correctly swapped to the OTPROM memory,
5031 * the first 2 bytes (header) should be 0x55, 0xAA
5033 if (byte1 == 0x55 && byte2 == 0xAA) {
5038 * We have to run through all the OTPROM memory looking
5039 * for the VPD offset.
5041 while (base_offset <= EXPANSION_ROM_SIZE) {
5044 * Lots of magic numbers here.
5046 * The VPD offset is located inside the ROM Data Structure.
5047 * We also have to remember the length of each
5048 * ROM Data Structure, so we can "hop" to the next
5049 * entry if the VPD isn't in the current
5050 * ROM Data Structure.
5052 rom_offset = readw(brd->re_map_membase + base_offset + 0x18);
5053 image_length = readw(brd->re_map_membase + rom_offset + 0x10) * 512;
5054 vpd_offset = readw(brd->re_map_membase + rom_offset + 0x08);
5056 /* Found the VPD entry */
5060 /* We didn't find a VPD entry, go to next ROM entry. */
5061 base_offset += image_length;
5063 byte1 = readb(brd->re_map_membase + base_offset);
5064 byte2 = readb(brd->re_map_membase + base_offset + 1);
5067 * If the new ROM offset doesn't have 0x55, 0xAA
5068 * as its header, we have run out of ROM.
5070 if (byte1 != 0x55 || byte2 != 0xAA)
5075 * If we have a VPD offset, then mark the board
5076 * as having a valid VPD, and copy VPDSIZE (512) bytes of
5077 * that VPD to the buffer we have in our board structure.
5080 brd->bd_flags |= BD_HAS_VPD;
5081 for (i = 0; i < VPDSIZE; i++)
5082 brd->vpd[i] = readb(brd->re_map_membase + vpd_offset + i);
5087 * We MUST poke the magic number at the PCI Rom Address location again.
5088 * This makes the card report the regular board memory back to us,
5089 * rather than the OTPROM memory.
5091 magic = FEP5_ROM_MAGIC;
5092 pci_write_config_dword(brd->pdev, PCI_ROM_ADDRESS, magic);
5097 * Our board poller function.
5099 void dgap_poll_tasklet(unsigned long data)
5101 struct board_t *bd = (struct board_t *) data;
5109 if (!bd || (bd->magic != DGAP_BOARD_MAGIC)) {
5110 APR(("dgap_poll_tasklet() - NULL or bad bd.\n"));
5114 if (bd->inhibit_poller)
5117 DGAP_LOCK(bd->bd_lock, lock_flags);
5119 vaddr = bd->re_map_membase;
5122 * If board is ready, parse deeper to see if there is anything to do.
5124 if (bd->state == BOARD_READY) {
5126 struct ev_t *eaddr = NULL;
5128 if (!bd->re_map_membase) {
5129 DGAP_UNLOCK(bd->bd_lock, lock_flags);
5132 if (!bd->re_map_port) {
5133 DGAP_UNLOCK(bd->bd_lock, lock_flags);
5142 * If this is a CX or EPCX, we need to see if the firmware
5143 * is requesting a concentrator image from us.
5145 if ((bd->type == PCX) || (bd->type == PEPC)) {
5146 chk_addr = (u16 *) (vaddr + DOWNREQ);
5147 check = readw(chk_addr);
5148 /* Nonzero if FEP is requesting concentrator image. */
5150 if (bd->conc_dl_status == NO_PENDING_CONCENTRATOR_REQUESTS)
5151 bd->conc_dl_status = NEED_CONCENTRATOR;
5153 * Signal downloader, its got some work to do.
5155 DGAP_LOCK(dgap_dl_lock, lock_flags2);
5156 if (dgap_dl_action != 1) {
5158 wake_up_interruptible(&dgap_dl_wait);
5160 DGAP_UNLOCK(dgap_dl_lock, lock_flags2);
5165 eaddr = (struct ev_t *) (vaddr + EVBUF);
5167 /* Get our head and tail */
5168 head = readw(&(eaddr->ev_head));
5169 tail = readw(&(eaddr->ev_tail));
5172 * If there is an event pending. Go service it.
5175 DGAP_UNLOCK(bd->bd_lock, lock_flags);
5177 DGAP_LOCK(bd->bd_lock, lock_flags);
5182 * If board is doing interrupts, ACK the interrupt.
5184 if (bd && bd->intr_running) {
5185 readb(bd->re_map_port + 2);
5188 DGAP_UNLOCK(bd->bd_lock, lock_flags);
5192 /* Our state machine to get the board up and running */
5195 if (bd->state == NEED_RESET) {
5200 dgap_do_reset_board(bd);
5203 /* Move to next state */
5204 if (bd->state == FINISHED_RESET) {
5205 bd->state = NEED_CONFIG;
5208 if (bd->state == NEED_CONFIG) {
5210 * Match this board to a config the user created for us.
5212 bd->bd_config = dgap_find_config(bd->type, bd->pci_bus, bd->pci_slot);
5215 * Because the 4 port Xr products share the same PCI ID
5216 * as the 8 port Xr products, if we receive a NULL config
5217 * back, and this is a PAPORT8 board, retry with a
5218 * PAPORT4 attempt as well.
5220 if (bd->type == PAPORT8 && !bd->bd_config) {
5221 bd->bd_config = dgap_find_config(PAPORT4, bd->pci_bus, bd->pci_slot);
5225 * Register the ttys (if any) into the kernel.
5227 if (bd->bd_config) {
5228 bd->state = FINISHED_CONFIG;
5231 bd->state = CONFIG_NOT_FOUND;
5235 /* Move to next state */
5236 if (bd->state == FINISHED_CONFIG) {
5237 bd->state = NEED_DEVICE_CREATION;
5240 /* Move to next state */
5241 if (bd->state == NEED_DEVICE_CREATION) {
5243 * Signal downloader, its got some work to do.
5245 DGAP_LOCK(dgap_dl_lock, lock_flags2);
5246 if (dgap_dl_action != 1) {
5248 wake_up_interruptible(&dgap_dl_wait);
5250 DGAP_UNLOCK(dgap_dl_lock, lock_flags2);
5253 /* Move to next state */
5254 if (bd->state == FINISHED_DEVICE_CREATION) {
5255 bd->state = NEED_BIOS_LOAD;
5258 /* Move to next state */
5259 if (bd->state == NEED_BIOS_LOAD) {
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 /* Wait for BIOS to test board... */
5272 if (bd->state == WAIT_BIOS_LOAD) {
5273 dgap_do_wait_for_bios(bd);
5276 /* Move to next state */
5277 if (bd->state == FINISHED_BIOS_LOAD) {
5278 bd->state = NEED_FEP_LOAD;
5281 * Signal downloader, its got some work to do.
5283 DGAP_LOCK(dgap_dl_lock, lock_flags2);
5284 if (dgap_dl_action != 1) {
5286 wake_up_interruptible(&dgap_dl_wait);
5288 DGAP_UNLOCK(dgap_dl_lock, lock_flags2);
5291 /* Wait for FEP to load on board... */
5292 if (bd->state == WAIT_FEP_LOAD) {
5293 dgap_do_wait_for_fep(bd);
5297 /* Move to next state */
5298 if (bd->state == FINISHED_FEP_LOAD) {
5301 * Do tty device initialization.
5303 int rc = dgap_tty_init(bd);
5306 dgap_tty_uninit(bd);
5307 APR(("Can't init tty devices (%d)\n", rc));
5308 bd->state = BOARD_FAILED;
5309 bd->dpastatus = BD_NOFEP;
5312 bd->state = NEED_PROC_CREATION;
5315 * Signal downloader, its got some work to do.
5317 DGAP_LOCK(dgap_dl_lock, lock_flags2);
5318 if (dgap_dl_action != 1) {
5320 wake_up_interruptible(&dgap_dl_wait);
5322 DGAP_UNLOCK(dgap_dl_lock, lock_flags2);
5326 /* Move to next state */
5327 if (bd->state == FINISHED_PROC_CREATION) {
5329 bd->state = BOARD_READY;
5330 bd->dpastatus = BD_RUNNING;
5333 * If user requested the board to run in interrupt mode,
5334 * go and set it up on the board.
5336 if (bd->intr_used) {
5337 writew(1, (bd->re_map_membase + ENABLE_INTR));
5339 * Tell the board to poll the UARTS as fast as possible.
5341 writew(FEPPOLL_MIN, (bd->re_map_membase + FEPPOLL));
5342 bd->intr_running = 1;
5345 /* Wake up anyone waiting for board state to change to ready */
5346 wake_up_interruptible(&bd->state_wait);
5349 DGAP_UNLOCK(bd->bd_lock, lock_flags);
5353 /*=======================================================================
5355 * dgap_cmdb - Sends a 2 byte command to the FEP.
5357 * ch - Pointer to channel structure.
5358 * cmd - Command to be sent.
5359 * byte1 - Integer containing first byte to be sent.
5360 * byte2 - Integer containing second byte to be sent.
5361 * ncmds - Wait until ncmds or fewer cmds are left
5362 * in the cmd buffer before returning.
5364 *=======================================================================*/
5365 void dgap_cmdb(struct channel_t *ch, uchar cmd, uchar byte1, uchar byte2, uint ncmds)
5368 struct cm_t *cm_addr = NULL;
5374 if (!ch || ch->magic != DGAP_CHANNEL_MAGIC)
5378 * Check if board is still alive.
5380 if (ch->ch_bd->state == BOARD_FAILED) {
5381 DPR_CORE(("%s:%d board is in failed state.\n", __FILE__, __LINE__));
5386 * Make sure the pointers are in range before
5387 * writing to the FEP memory.
5389 vaddr = ch->ch_bd->re_map_membase;
5394 cm_addr = (struct cm_t *) (vaddr + CMDBUF);
5395 head = readw(&(cm_addr->cm_head));
5398 * Forget it if pointers out of range.
5400 if (head >= (CMDMAX - CMDSTART) || (head & 03)) {
5401 DPR_CORE(("%s:%d pointers out of range, failing board!\n", __FILE__, __LINE__));
5402 ch->ch_bd->state = BOARD_FAILED;
5407 * Put the data in the circular command buffer.
5409 writeb(cmd, (char *) (vaddr + head + CMDSTART + 0));
5410 writeb((uchar) ch->ch_portnum, (char *) (vaddr + head + CMDSTART + 1));
5411 writeb(byte1, (char *) (vaddr + head + CMDSTART + 2));
5412 writeb(byte2, (char *) (vaddr + head + CMDSTART + 3));
5414 head = (head + 4) & (CMDMAX - CMDSTART - 4);
5416 writew(head, &(cm_addr->cm_head));
5419 * Wait if necessary before updating the head
5420 * pointer to limit the number of outstanding
5421 * commands to the FEP. If the time spent waiting
5422 * is outlandish, declare the FEP dead.
5424 for (count = dgap_count ;;) {
5426 head = readw(&(cm_addr->cm_head));
5427 tail = readw(&(cm_addr->cm_tail));
5429 n = (head - tail) & (CMDMAX - CMDSTART - 4);
5431 if (n <= ncmds * sizeof(struct cm_t))
5435 DPR_CORE(("%s:%d failing board.\n",__FILE__, __LINE__));
5436 ch->ch_bd->state = BOARD_FAILED;
5444 /*=======================================================================
5446 * dgap_cmdw - Sends a 1 word command to the FEP.
5448 * ch - Pointer to channel structure.
5449 * cmd - Command to be sent.
5450 * word - Integer containing word to be sent.
5451 * ncmds - Wait until ncmds or fewer cmds are left
5452 * in the cmd buffer before returning.
5454 *=======================================================================*/
5455 void dgap_cmdw(struct channel_t *ch, uchar cmd, u16 word, uint ncmds)
5458 struct cm_t *cm_addr = NULL;
5464 if (!ch || ch->magic != DGAP_CHANNEL_MAGIC)
5468 * Check if board is still alive.
5470 if (ch->ch_bd->state == BOARD_FAILED) {
5471 DPR_CORE(("%s:%d board is failed!\n", __FILE__, __LINE__));
5476 * Make sure the pointers are in range before
5477 * writing to the FEP memory.
5479 vaddr = ch->ch_bd->re_map_membase;
5483 cm_addr = (struct cm_t *) (vaddr + CMDBUF);
5484 head = readw(&(cm_addr->cm_head));
5487 * Forget it if pointers out of range.
5489 if (head >= (CMDMAX - CMDSTART) || (head & 03)) {
5490 DPR_CORE(("%s:%d Pointers out of range. Failing board.\n",__FILE__, __LINE__));
5491 ch->ch_bd->state = BOARD_FAILED;
5496 * Put the data in the circular command buffer.
5498 writeb(cmd, (char *) (vaddr + head + CMDSTART + 0));
5499 writeb((uchar) ch->ch_portnum, (char *) (vaddr + head + CMDSTART + 1));
5500 writew((u16) word, (char *) (vaddr + head + CMDSTART + 2));
5502 head = (head + 4) & (CMDMAX - CMDSTART - 4);
5504 writew(head, &(cm_addr->cm_head));
5507 * Wait if necessary before updating the head
5508 * pointer to limit the number of outstanding
5509 * commands to the FEP. If the time spent waiting
5510 * is outlandish, declare the FEP dead.
5512 for (count = dgap_count ;;) {
5514 head = readw(&(cm_addr->cm_head));
5515 tail = readw(&(cm_addr->cm_tail));
5517 n = (head - tail) & (CMDMAX - CMDSTART - 4);
5519 if (n <= ncmds * sizeof(struct cm_t))
5523 DPR_CORE(("%s:%d Failing board.\n",__FILE__, __LINE__));
5524 ch->ch_bd->state = BOARD_FAILED;
5533 /*=======================================================================
5535 * dgap_cmdw_ext - Sends a extended word command to the FEP.
5537 * ch - Pointer to channel structure.
5538 * cmd - Command to be sent.
5539 * word - Integer containing word to be sent.
5540 * ncmds - Wait until ncmds or fewer cmds are left
5541 * in the cmd buffer before returning.
5543 *=======================================================================*/
5544 static void dgap_cmdw_ext(struct channel_t *ch, u16 cmd, u16 word, uint ncmds)
5547 struct cm_t *cm_addr = NULL;
5553 if (!ch || ch->magic != DGAP_CHANNEL_MAGIC)
5557 * Check if board is still alive.
5559 if (ch->ch_bd->state == BOARD_FAILED) {
5560 DPR_CORE(("%s:%d board is failed!\n", __FILE__, __LINE__));
5565 * Make sure the pointers are in range before
5566 * writing to the FEP memory.
5568 vaddr = ch->ch_bd->re_map_membase;
5572 cm_addr = (struct cm_t *) (vaddr + CMDBUF);
5573 head = readw(&(cm_addr->cm_head));
5576 * Forget it if pointers out of range.
5578 if (head >= (CMDMAX - CMDSTART) || (head & 03)) {
5579 DPR_CORE(("%s:%d Pointers out of range. Failing board.\n",__FILE__, __LINE__));
5580 ch->ch_bd->state = BOARD_FAILED;
5585 * Put the data in the circular command buffer.
5588 /* Write an FF to tell the FEP that we want an extended command */
5589 writeb((uchar) 0xff, (char *) (vaddr + head + CMDSTART + 0));
5591 writeb((uchar) ch->ch_portnum, (uchar *) (vaddr + head + CMDSTART + 1));
5592 writew((u16) cmd, (char *) (vaddr + head + CMDSTART + 2));
5595 * If the second part of the command won't fit,
5596 * put it at the beginning of the circular buffer.
5598 if (((head + 4) >= ((CMDMAX - CMDSTART)) || (head & 03))) {
5599 writew((u16) word, (char *) (vaddr + CMDSTART));
5601 writew((u16) word, (char *) (vaddr + head + CMDSTART + 4));
5604 head = (head + 8) & (CMDMAX - CMDSTART - 4);
5606 writew(head, &(cm_addr->cm_head));
5609 * Wait if necessary before updating the head
5610 * pointer to limit the number of outstanding
5611 * commands to the FEP. If the time spent waiting
5612 * is outlandish, declare the FEP dead.
5614 for (count = dgap_count ;;) {
5616 head = readw(&(cm_addr->cm_head));
5617 tail = readw(&(cm_addr->cm_tail));
5619 n = (head - tail) & (CMDMAX - CMDSTART - 4);
5621 if (n <= ncmds * sizeof(struct cm_t))
5625 DPR_CORE(("%s:%d Failing board.\n",__FILE__, __LINE__));
5626 ch->ch_bd->state = BOARD_FAILED;
5634 /*=======================================================================
5636 * dgap_wmove - Write data to FEP buffer.
5638 * ch - Pointer to channel structure.
5639 * buf - Poiter to characters to be moved.
5640 * cnt - Number of characters to move.
5642 *=======================================================================*/
5643 void dgap_wmove(struct channel_t *ch, char *buf, uint cnt)
5650 if (!ch || ch->magic != DGAP_CHANNEL_MAGIC)
5657 head = readw(&(bs->tx_head));
5660 * If pointers are out of range, just return.
5662 if ((cnt > ch->ch_tsize) || (unsigned)(head - ch->ch_tstart) >= ch->ch_tsize) {
5663 DPR_CORE(("%s:%d pointer out of range", __FILE__, __LINE__));
5668 * If the write wraps over the top of the circular buffer,
5669 * move the portion up to the wrap point, and reset the
5670 * pointers to the bottom.
5672 n = ch->ch_tstart + ch->ch_tsize - head;
5676 taddr = ch->ch_taddr + head;
5677 memcpy_toio(taddr, buf, n);
5678 head = ch->ch_tstart;
5683 * Move rest of data.
5685 taddr = ch->ch_taddr + head;
5687 memcpy_toio(taddr, buf, n);
5690 writew(head, &(bs->tx_head));
5694 * Retrives the current custom baud rate from FEP memory,
5695 * and returns it back to the user.
5696 * Returns 0 on error.
5698 uint dgap_get_custom_baud(struct channel_t *ch)
5704 if (!ch || ch->magic != DGAP_CHANNEL_MAGIC) {
5708 if (!ch->ch_bd || ch->ch_bd->magic != DGAP_BOARD_MAGIC) {
5712 if (!(ch->ch_bd->bd_flags & BD_FEP5PLUS))
5715 vaddr = ch->ch_bd->re_map_membase;
5721 * Go get from fep mem, what the fep
5722 * believes the custom baud rate is.
5724 offset = ((((*(unsigned short *)(vaddr + ECS_SEG)) << 4) +
5725 (ch->ch_portnum * 0x28) + LINE_SPEED));
5727 value = readw(vaddr + offset);
5733 * Calls the firmware to reset this channel.
5735 void dgap_firmware_reset_port(struct channel_t *ch)
5737 dgap_cmdb(ch, CHRESET, 0, 0, 0);
5740 * Now that the channel is reset, we need to make sure
5741 * all the current settings get reapplied to the port
5744 * So we will set the driver's cache of firmware
5745 * settings all to 0, and then call param.
5747 ch->ch_fepiflag = 0;
5748 ch->ch_fepcflag = 0;
5749 ch->ch_fepoflag = 0;
5750 ch->ch_fepstartc = 0;
5751 ch->ch_fepstopc = 0;
5752 ch->ch_fepastartc = 0;
5753 ch->ch_fepastopc = 0;
5759 /*=======================================================================
5761 * dgap_param - Set Digi parameters.
5763 * struct tty_struct * - TTY for port.
5765 *=======================================================================*/
5766 int dgap_param(struct tty_struct *tty)
5768 struct ktermios *ts;
5770 struct channel_t *ch;
5779 if (!tty || tty->magic != TTY_MAGIC)
5782 un = (struct un_t *) tty->driver_data;
5783 if (!un || un->magic != DGAP_UNIT_MAGIC)
5787 if (!ch || ch->magic != DGAP_CHANNEL_MAGIC)
5791 if (!bd || bd->magic != DGAP_BOARD_MAGIC)
5798 DPR_PARAM(("param start: tdev: %x cflags: %x oflags: %x iflags: %x\n",
5799 ch->ch_tun.un_dev, ch->ch_c_cflag, ch->ch_c_oflag, ch->ch_c_iflag));
5804 * If baud rate is zero, flush queues, and set mval to drop DTR.
5806 if ((ch->ch_c_cflag & (CBAUD)) == 0) {
5809 head = readw(&(ch->ch_bs->rx_head));
5810 writew(head, &(ch->ch_bs->rx_tail));
5813 head = readw(&(ch->ch_bs->tx_head));
5814 writew(head, &(ch->ch_bs->tx_tail));
5816 ch->ch_flags |= (CH_BAUD0);
5818 /* Drop RTS and DTR */
5819 ch->ch_mval &= ~(D_RTS(ch)|D_DTR(ch));
5820 mval = D_DTR(ch) | D_RTS(ch);
5821 ch->ch_baud_info = 0;
5823 } else if (ch->ch_custom_speed && (bd->bd_flags & BD_FEP5PLUS)) {
5825 * Tell the fep to do the command
5828 DPR_PARAM(("param: Want %d speed\n", ch->ch_custom_speed));
5830 dgap_cmdw_ext(ch, 0xff01, ch->ch_custom_speed, 0);
5833 * Now go get from fep mem, what the fep
5834 * believes the custom baud rate is.
5836 ch->ch_baud_info = ch->ch_custom_speed = dgap_get_custom_baud(ch);
5838 DPR_PARAM(("param: Got %d speed\n", ch->ch_custom_speed));
5840 /* Handle transition from B0 */
5841 if (ch->ch_flags & CH_BAUD0) {
5842 ch->ch_flags &= ~(CH_BAUD0);
5843 ch->ch_mval |= (D_RTS(ch)|D_DTR(ch));
5845 mval = D_DTR(ch) | D_RTS(ch);
5849 * Set baud rate, character size, and parity.
5857 ulong bauds[4][16] = {
5861 600, 1200, 1800, 2400,
5862 4800, 9600, 19200, 38400 },
5863 { /* slowbaud & CBAUDEX */
5864 0, 57600, 115200, 230400,
5865 460800, 150, 200, 921600,
5866 600, 1200, 1800, 2400,
5867 4800, 9600, 19200, 38400 },
5869 0, 57600, 76800, 115200,
5870 14400, 57600, 230400, 76800,
5871 115200, 230400, 28800, 460800,
5872 921600, 9600, 19200, 38400 },
5873 { /* fastbaud & CBAUDEX */
5874 0, 57600, 115200, 230400,
5875 460800, 150, 200, 921600,
5876 600, 1200, 1800, 2400,
5877 4800, 9600, 19200, 38400 }
5880 /* Only use the TXPrint baud rate if the terminal unit is NOT open */
5881 if (!(ch->ch_tun.un_flags & UN_ISOPEN) && (un->un_type == DGAP_PRINT))
5882 baud = C_BAUD(ch->ch_pun.un_tty) & 0xff;
5884 baud = C_BAUD(ch->ch_tun.un_tty) & 0xff;
5886 if (ch->ch_c_cflag & CBAUDEX)
5889 if (ch->ch_digi.digi_flags & DIGI_FAST)
5894 if ((iindex >= 0) && (iindex < 4) && (jindex >= 0) && (jindex < 16)) {
5895 baud = bauds[iindex][jindex];
5897 DPR_IOCTL(("baud indices were out of range (%d)(%d)",
5905 ch->ch_baud_info = baud;
5909 * CBAUD has bit position 0x1000 set these days to indicate Linux
5911 * We use a different bit assignment for high speed. Clear this
5912 * bit out while grabbing the parts of "cflag" we want.
5914 cflag = ch->ch_c_cflag & ((CBAUD ^ CBAUDEX) | PARODD | PARENB | CSTOPB | CSIZE);
5917 * HUPCL bit is used by FEP to indicate fast baud
5918 * table is to be used.
5920 if ((ch->ch_digi.digi_flags & DIGI_FAST) || (ch->ch_c_cflag & CBAUDEX))
5924 if ((ch->ch_c_cflag & CBAUDEX) && !(ch->ch_digi.digi_flags & DIGI_FAST)) {
5926 * The below code is trying to guarantee that only baud rates
5927 * 115200, 230400, 460800, 921600 are remapped. We use exclusive or
5928 * because the various baud rates share common bit positions
5929 * and therefore can't be tested for easily.
5931 tcflag_t tcflag = (ch->ch_c_cflag & CBAUD) | CBAUDEX;
5934 /* Map high speed requests to index into FEP's baud table */
5963 cflag = (cflag & ~(CBAUD | CBAUDEX)) | baudpart;
5968 if (cflag != ch->ch_fepcflag) {
5969 ch->ch_fepcflag = (u16) (cflag & 0xffff);
5971 /* Okay to have channel and board locks held calling this */
5972 dgap_cmdw(ch, SCFLAG, (u16) cflag, 0);
5975 /* Handle transition from B0 */
5976 if (ch->ch_flags & CH_BAUD0) {
5977 ch->ch_flags &= ~(CH_BAUD0);
5978 ch->ch_mval |= (D_RTS(ch)|D_DTR(ch));
5980 mval = D_DTR(ch) | D_RTS(ch);
5986 iflag = ch->ch_c_iflag & (IGNBRK | BRKINT | IGNPAR | PARMRK | INPCK | ISTRIP | IXON | IXANY | IXOFF);
5988 if ((ch->ch_startc == _POSIX_VDISABLE) || (ch->ch_stopc == _POSIX_VDISABLE)) {
5989 iflag &= ~(IXON | IXOFF);
5990 ch->ch_c_iflag &= ~(IXON | IXOFF);
5994 * Only the IBM Xr card can switch between
5995 * 232 and 422 modes on the fly
5997 if (bd->device == PCI_DEVICE_XR_IBM_DID) {
5998 if (ch->ch_digi.digi_flags & DIGI_422)
5999 dgap_cmdb(ch, SCOMMODE, MODE_422, 0, 0);
6001 dgap_cmdb(ch, SCOMMODE, MODE_232, 0, 0);
6004 if (ch->ch_digi.digi_flags & DIGI_ALTPIN)
6007 if (iflag != ch->ch_fepiflag) {
6008 ch->ch_fepiflag = iflag;
6010 /* Okay to have channel and board locks held calling this */
6011 dgap_cmdw(ch, SIFLAG, (u16) ch->ch_fepiflag, 0);
6015 * Select hardware handshaking.
6019 if (ch->ch_c_cflag & CRTSCTS) {
6020 hflow |= (D_RTS(ch) | D_CTS(ch));
6022 if (ch->ch_digi.digi_flags & RTSPACE)
6024 if (ch->ch_digi.digi_flags & DTRPACE)
6026 if (ch->ch_digi.digi_flags & CTSPACE)
6028 if (ch->ch_digi.digi_flags & DSRPACE)
6030 if (ch->ch_digi.digi_flags & DCDPACE)
6033 if (hflow != ch->ch_hflow) {
6034 ch->ch_hflow = hflow;
6036 /* Okay to have channel and board locks held calling this */
6037 dgap_cmdb(ch, SHFLOW, (uchar) hflow, 0xff, 0);
6042 * Set RTS and/or DTR Toggle if needed, but only if product is FEP5+ based.
6044 if (bd->bd_flags & BD_FEP5PLUS) {
6046 if (ch->ch_digi.digi_flags & DIGI_RTS_TOGGLE) {
6047 hflow2 |= (D_RTS(ch));
6049 if (ch->ch_digi.digi_flags & DIGI_DTR_TOGGLE) {
6050 hflow2 |= (D_DTR(ch));
6053 dgap_cmdw_ext(ch, 0xff03, hflow2, 0);
6057 * Set modem control lines.
6060 mval ^= ch->ch_mforce & (mval ^ ch->ch_mval);
6062 DPR_PARAM(("dgap_param: mval: %x ch_mforce: %x ch_mval: %x ch_mostat: %x\n",
6063 mval, ch->ch_mforce, ch->ch_mval, ch->ch_mostat));
6065 if (ch->ch_mostat ^ mval) {
6066 ch->ch_mostat = mval;
6068 /* Okay to have channel and board locks held calling this */
6069 DPR_PARAM(("dgap_param: Sending SMODEM mval: %x\n", mval));
6070 dgap_cmdb(ch, SMODEM, (uchar) mval, D_RTS(ch)|D_DTR(ch), 0);
6074 * Read modem signals, and then call carrier function.
6076 ch->ch_mistat = readb(&(bs->m_stat));
6080 * Set the start and stop characters.
6082 if (ch->ch_startc != ch->ch_fepstartc || ch->ch_stopc != ch->ch_fepstopc) {
6083 ch->ch_fepstartc = ch->ch_startc;
6084 ch->ch_fepstopc = ch->ch_stopc;
6086 /* Okay to have channel and board locks held calling this */
6087 dgap_cmdb(ch, SFLOWC, ch->ch_fepstartc, ch->ch_fepstopc, 0);
6091 * Set the Auxiliary start and stop characters.
6093 if (ch->ch_astartc != ch->ch_fepastartc || ch->ch_astopc != ch->ch_fepastopc) {
6094 ch->ch_fepastartc = ch->ch_astartc;
6095 ch->ch_fepastopc = ch->ch_astopc;
6097 /* Okay to have channel and board locks held calling this */
6098 dgap_cmdb(ch, SAFLOWC, ch->ch_fepastartc, ch->ch_fepastopc, 0);
6101 DPR_PARAM(("param finish\n"));
6108 * dgap_parity_scan()
6110 * Convert the FEP5 way of reporting parity errors and breaks into
6111 * the Linux line discipline way.
6113 void dgap_parity_scan(struct channel_t *ch, unsigned char *cbuf, unsigned char *fbuf, int *len)
6117 unsigned char *in, *cout, *fout;
6124 DPR_PSCAN(("dgap_parity_scan start\n"));
6126 if (!ch || ch->magic != DGAP_CHANNEL_MAGIC)
6131 switch (ch->pscan_state) {
6133 /* reset to sanity and fall through */
6134 ch->pscan_state = 0;
6137 /* No FF seen yet */
6138 if (c == (unsigned char) '\377') {
6139 /* delete this character from stream */
6140 ch->pscan_state = 1;
6143 *fout++ = TTY_NORMAL;
6150 if (c == (unsigned char) '\377') {
6151 /* doubled ff, transform to single ff */
6153 *fout++ = TTY_NORMAL;
6155 ch->pscan_state = 0;
6157 /* save value examination in next state */
6158 ch->pscan_savechar = c;
6159 ch->pscan_state = 2;
6164 /* third character of ff sequence */
6168 if (ch->pscan_savechar == 0x0) {
6171 DPR_PSCAN(("dgap_parity_scan in 3rd char of ff seq. c: %x setting break.\n", c));
6173 *fout++ = TTY_BREAK;
6176 DPR_PSCAN(("dgap_parity_scan in 3rd char of ff seq. c: %x setting parity.\n", c));
6177 ch->ch_err_parity++;
6178 *fout++ = TTY_PARITY;
6182 DPR_PSCAN(("%s:%d Logic Error.\n", __FILE__, __LINE__));
6186 ch->pscan_state = 0;
6190 DPR_PSCAN(("dgap_parity_scan finish\n"));
6196 /*=======================================================================
6198 * dgap_event - FEP to host event processing routine.
6200 * bd - Board of current event.
6202 *=======================================================================*/
6203 static int dgap_event(struct board_t *bd)
6205 struct channel_t *ch;
6210 uchar *vaddr = NULL;
6211 struct ev_t *eaddr = NULL;
6219 if (!bd || bd->magic != DGAP_BOARD_MAGIC)
6222 DGAP_LOCK(bd->bd_lock, lock_flags);
6224 vaddr = bd->re_map_membase;
6227 DGAP_UNLOCK(bd->bd_lock, lock_flags);
6231 eaddr = (struct ev_t *) (vaddr + EVBUF);
6233 /* Get our head and tail */
6234 head = readw(&(eaddr->ev_head));
6235 tail = readw(&(eaddr->ev_tail));
6238 * Forget it if pointers out of range.
6241 if (head >= EVMAX - EVSTART || tail >= EVMAX - EVSTART ||
6242 (head | tail) & 03) {
6243 DPR_EVENT(("should be calling xxfail %d\n", __LINE__));
6244 /* Let go of board lock */
6245 DGAP_UNLOCK(bd->bd_lock, lock_flags);
6250 * Loop to process all the events in the buffer.
6252 while (tail != head) {
6255 * Get interrupt information.
6258 event = bd->re_map_membase + tail + EVSTART;
6265 DPR_EVENT(("event: jiffies: %ld port: %d reason: %x modem: %x\n",
6266 jiffies, port, reason, modem));
6269 * Make sure the interrupt is valid.
6271 if (port >= bd->nasync)
6274 if (!(reason & (IFMODEM | IFBREAK | IFTLW | IFTEM | IFDATA))) {
6278 ch = bd->channels[port];
6280 if (!ch || ch->magic != DGAP_CHANNEL_MAGIC) {
6285 * If we have made it here, the event was valid.
6286 * Lock down the channel.
6288 DGAP_LOCK(ch->ch_lock, lock_flags2);
6293 DGAP_UNLOCK(ch->ch_lock, lock_flags2);
6298 * Process received data.
6300 if (reason & IFDATA) {
6303 * ALL LOCKS *MUST* BE DROPPED BEFORE CALLING INPUT!
6304 * input could send some data to ld, which in turn
6305 * could do a callback to one of our other functions.
6307 DGAP_UNLOCK(ch->ch_lock, lock_flags2);
6308 DGAP_UNLOCK(bd->bd_lock, lock_flags);
6312 DGAP_LOCK(bd->bd_lock, lock_flags);
6313 DGAP_LOCK(ch->ch_lock, lock_flags2);
6315 if (ch->ch_flags & CH_RACTIVE)
6316 ch->ch_flags |= CH_RENABLE;
6318 writeb(1, &(bs->idata));
6320 if (ch->ch_flags & CH_RWAIT) {
6321 ch->ch_flags &= ~CH_RWAIT;
6323 wake_up_interruptible(&ch->ch_tun.un_flags_wait);
6328 * Process Modem change signals.
6330 if (reason & IFMODEM) {
6331 ch->ch_mistat = modem;
6338 if (reason & IFBREAK) {
6340 DPR_EVENT(("got IFBREAK\n"));
6342 if (ch->ch_tun.un_tty) {
6343 /* A break has been indicated */
6345 tty_buffer_request_room(ch->ch_tun.un_tty->port, 1);
6346 tty_insert_flip_char(ch->ch_tun.un_tty->port, 0, TTY_BREAK);
6347 tty_flip_buffer_push(ch->ch_tun.un_tty->port);
6352 * Process Transmit low.
6354 if (reason & IFTLW) {
6356 DPR_EVENT(("event: got low event\n"));
6358 if (ch->ch_tun.un_flags & UN_LOW) {
6359 ch->ch_tun.un_flags &= ~UN_LOW;
6361 if (ch->ch_tun.un_flags & UN_ISOPEN) {
6362 if ((ch->ch_tun.un_tty->flags &
6363 (1 << TTY_DO_WRITE_WAKEUP)) &&
6364 ch->ch_tun.un_tty->ldisc->ops->write_wakeup)
6366 DGAP_UNLOCK(ch->ch_lock, lock_flags2);
6367 DGAP_UNLOCK(bd->bd_lock, lock_flags);
6368 (ch->ch_tun.un_tty->ldisc->ops->write_wakeup)(ch->ch_tun.un_tty);
6369 DGAP_LOCK(bd->bd_lock, lock_flags);
6370 DGAP_LOCK(ch->ch_lock, lock_flags2);
6372 wake_up_interruptible(&ch->ch_tun.un_tty->write_wait);
6373 wake_up_interruptible(&ch->ch_tun.un_flags_wait);
6375 DPR_EVENT(("event: Got low event. jiffies: %lu\n", jiffies));
6379 if (ch->ch_pun.un_flags & UN_LOW) {
6380 ch->ch_pun.un_flags &= ~UN_LOW;
6381 if (ch->ch_pun.un_flags & UN_ISOPEN) {
6382 if ((ch->ch_pun.un_tty->flags &
6383 (1 << TTY_DO_WRITE_WAKEUP)) &&
6384 ch->ch_pun.un_tty->ldisc->ops->write_wakeup)
6386 DGAP_UNLOCK(ch->ch_lock, lock_flags2);
6387 DGAP_UNLOCK(bd->bd_lock, lock_flags);
6388 (ch->ch_pun.un_tty->ldisc->ops->write_wakeup)(ch->ch_pun.un_tty);
6389 DGAP_LOCK(bd->bd_lock, lock_flags);
6390 DGAP_LOCK(ch->ch_lock, lock_flags2);
6392 wake_up_interruptible(&ch->ch_pun.un_tty->write_wait);
6393 wake_up_interruptible(&ch->ch_pun.un_flags_wait);
6397 if (ch->ch_flags & CH_WLOW) {
6398 ch->ch_flags &= ~CH_WLOW;
6399 wake_up_interruptible(&ch->ch_flags_wait);
6404 * Process Transmit empty.
6406 if (reason & IFTEM) {
6407 DPR_EVENT(("event: got empty event\n"));
6409 if (ch->ch_tun.un_flags & UN_EMPTY) {
6410 ch->ch_tun.un_flags &= ~UN_EMPTY;
6411 if (ch->ch_tun.un_flags & UN_ISOPEN) {
6412 if ((ch->ch_tun.un_tty->flags &
6413 (1 << TTY_DO_WRITE_WAKEUP)) &&
6414 ch->ch_tun.un_tty->ldisc->ops->write_wakeup)
6416 DGAP_UNLOCK(ch->ch_lock, lock_flags2);
6417 DGAP_UNLOCK(bd->bd_lock, lock_flags);
6419 (ch->ch_tun.un_tty->ldisc->ops->write_wakeup)(ch->ch_tun.un_tty);
6420 DGAP_LOCK(bd->bd_lock, lock_flags);
6421 DGAP_LOCK(ch->ch_lock, lock_flags2);
6423 wake_up_interruptible(&ch->ch_tun.un_tty->write_wait);
6424 wake_up_interruptible(&ch->ch_tun.un_flags_wait);
6428 if (ch->ch_pun.un_flags & UN_EMPTY) {
6429 ch->ch_pun.un_flags &= ~UN_EMPTY;
6430 if (ch->ch_pun.un_flags & UN_ISOPEN) {
6431 if ((ch->ch_pun.un_tty->flags &
6432 (1 << TTY_DO_WRITE_WAKEUP)) &&
6433 ch->ch_pun.un_tty->ldisc->ops->write_wakeup)
6435 DGAP_UNLOCK(ch->ch_lock, lock_flags2);
6436 DGAP_UNLOCK(bd->bd_lock, lock_flags);
6437 (ch->ch_pun.un_tty->ldisc->ops->write_wakeup)(ch->ch_pun.un_tty);
6438 DGAP_LOCK(bd->bd_lock, lock_flags);
6439 DGAP_LOCK(ch->ch_lock, lock_flags2);
6441 wake_up_interruptible(&ch->ch_pun.un_tty->write_wait);
6442 wake_up_interruptible(&ch->ch_pun.un_flags_wait);
6447 if (ch->ch_flags & CH_WEMPTY) {
6448 ch->ch_flags &= ~CH_WEMPTY;
6449 wake_up_interruptible(&ch->ch_flags_wait);
6453 DGAP_UNLOCK(ch->ch_lock, lock_flags2);
6456 tail = (tail + 4) & (EVMAX - EVSTART - 4);
6459 writew(tail, &(eaddr->ev_tail));
6460 DGAP_UNLOCK(bd->bd_lock, lock_flags);
6465 static ssize_t dgap_driver_version_show(struct device_driver *ddp, char *buf)
6467 return snprintf(buf, PAGE_SIZE, "%s\n", DG_PART);
6469 static DRIVER_ATTR(version, S_IRUSR, dgap_driver_version_show, NULL);
6472 static ssize_t dgap_driver_boards_show(struct device_driver *ddp, char *buf)
6474 return snprintf(buf, PAGE_SIZE, "%d\n", dgap_NumBoards);
6476 static DRIVER_ATTR(boards, S_IRUSR, dgap_driver_boards_show, NULL);
6479 static ssize_t dgap_driver_maxboards_show(struct device_driver *ddp, char *buf)
6481 return snprintf(buf, PAGE_SIZE, "%d\n", MAXBOARDS);
6483 static DRIVER_ATTR(maxboards, S_IRUSR, dgap_driver_maxboards_show, NULL);
6486 static ssize_t dgap_driver_pollcounter_show(struct device_driver *ddp, char *buf)
6488 return snprintf(buf, PAGE_SIZE, "%ld\n", dgap_poll_counter);
6490 static DRIVER_ATTR(pollcounter, S_IRUSR, dgap_driver_pollcounter_show, NULL);
6493 static ssize_t dgap_driver_state_show(struct device_driver *ddp, char *buf)
6495 return snprintf(buf, PAGE_SIZE, "%s\n", dgap_driver_state_text[dgap_driver_state]);
6497 static DRIVER_ATTR(state, S_IRUSR, dgap_driver_state_show, NULL);
6500 static ssize_t dgap_driver_debug_show(struct device_driver *ddp, char *buf)
6502 return snprintf(buf, PAGE_SIZE, "0x%x\n", dgap_debug);
6505 static ssize_t dgap_driver_debug_store(struct device_driver *ddp, const char *buf, size_t count)
6507 sscanf(buf, "0x%x\n", &dgap_debug);
6510 static DRIVER_ATTR(debug, (S_IRUSR | S_IWUSR), dgap_driver_debug_show, dgap_driver_debug_store);
6513 static ssize_t dgap_driver_rawreadok_show(struct device_driver *ddp, char *buf)
6515 return snprintf(buf, PAGE_SIZE, "0x%x\n", dgap_rawreadok);
6518 static ssize_t dgap_driver_rawreadok_store(struct device_driver *ddp, const char *buf, size_t count)
6520 sscanf(buf, "0x%x\n", &dgap_rawreadok);
6523 static DRIVER_ATTR(rawreadok, (S_IRUSR | S_IWUSR), dgap_driver_rawreadok_show, dgap_driver_rawreadok_store);
6526 static ssize_t dgap_driver_pollrate_show(struct device_driver *ddp, char *buf)
6528 return snprintf(buf, PAGE_SIZE, "%dms\n", dgap_poll_tick);
6531 static ssize_t dgap_driver_pollrate_store(struct device_driver *ddp, const char *buf, size_t count)
6533 sscanf(buf, "%d\n", &dgap_poll_tick);
6536 static DRIVER_ATTR(pollrate, (S_IRUSR | S_IWUSR), dgap_driver_pollrate_show, dgap_driver_pollrate_store);
6539 void dgap_create_driver_sysfiles(struct pci_driver *dgap_driver)
6542 struct device_driver *driverfs = &dgap_driver->driver;
6544 rc |= driver_create_file(driverfs, &driver_attr_version);
6545 rc |= driver_create_file(driverfs, &driver_attr_boards);
6546 rc |= driver_create_file(driverfs, &driver_attr_maxboards);
6547 rc |= driver_create_file(driverfs, &driver_attr_debug);
6548 rc |= driver_create_file(driverfs, &driver_attr_rawreadok);
6549 rc |= driver_create_file(driverfs, &driver_attr_pollrate);
6550 rc |= driver_create_file(driverfs, &driver_attr_pollcounter);
6551 rc |= driver_create_file(driverfs, &driver_attr_state);
6553 printk(KERN_ERR "DGAP: sysfs driver_create_file failed!\n");
6558 void dgap_remove_driver_sysfiles(struct pci_driver *dgap_driver)
6560 struct device_driver *driverfs = &dgap_driver->driver;
6561 driver_remove_file(driverfs, &driver_attr_version);
6562 driver_remove_file(driverfs, &driver_attr_boards);
6563 driver_remove_file(driverfs, &driver_attr_maxboards);
6564 driver_remove_file(driverfs, &driver_attr_debug);
6565 driver_remove_file(driverfs, &driver_attr_rawreadok);
6566 driver_remove_file(driverfs, &driver_attr_pollrate);
6567 driver_remove_file(driverfs, &driver_attr_pollcounter);
6568 driver_remove_file(driverfs, &driver_attr_state);
6572 #define DGAP_VERIFY_BOARD(p, bd) \
6576 bd = dev_get_drvdata(p); \
6577 if (!bd || bd->magic != DGAP_BOARD_MAGIC) \
6579 if (bd->state != BOARD_READY) \
6583 static ssize_t dgap_ports_state_show(struct device *p, struct device_attribute *attr, char *buf)
6589 DGAP_VERIFY_BOARD(p, bd);
6591 for (i = 0; i < bd->nasync; i++) {
6592 count += snprintf(buf + count, PAGE_SIZE - count,
6593 "%d %s\n", bd->channels[i]->ch_portnum,
6594 bd->channels[i]->ch_open_count ? "Open" : "Closed");
6598 static DEVICE_ATTR(ports_state, S_IRUSR, dgap_ports_state_show, NULL);
6601 static ssize_t dgap_ports_baud_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 %d\n", bd->channels[i]->ch_portnum, bd->channels[i]->ch_baud_info);
6615 static DEVICE_ATTR(ports_baud, S_IRUSR, dgap_ports_baud_show, NULL);
6618 static ssize_t dgap_ports_msignals_show(struct device *p, struct device_attribute *attr, char *buf)
6624 DGAP_VERIFY_BOARD(p, bd);
6626 for (i = 0; i < bd->nasync; i++) {
6627 if (bd->channels[i]->ch_open_count) {
6628 count += snprintf(buf + count, PAGE_SIZE - count,
6629 "%d %s %s %s %s %s %s\n", bd->channels[i]->ch_portnum,
6630 (bd->channels[i]->ch_mostat & UART_MCR_RTS) ? "RTS" : "",
6631 (bd->channels[i]->ch_mistat & UART_MSR_CTS) ? "CTS" : "",
6632 (bd->channels[i]->ch_mostat & UART_MCR_DTR) ? "DTR" : "",
6633 (bd->channels[i]->ch_mistat & UART_MSR_DSR) ? "DSR" : "",
6634 (bd->channels[i]->ch_mistat & UART_MSR_DCD) ? "DCD" : "",
6635 (bd->channels[i]->ch_mistat & UART_MSR_RI) ? "RI" : "");
6637 count += snprintf(buf + count, PAGE_SIZE - count,
6638 "%d\n", bd->channels[i]->ch_portnum);
6643 static DEVICE_ATTR(ports_msignals, S_IRUSR, dgap_ports_msignals_show, NULL);
6646 static ssize_t dgap_ports_iflag_show(struct device *p, struct device_attribute *attr, char *buf)
6652 DGAP_VERIFY_BOARD(p, bd);
6654 for (i = 0; i < bd->nasync; i++) {
6655 count += snprintf(buf + count, PAGE_SIZE - count, "%d %x\n",
6656 bd->channels[i]->ch_portnum, bd->channels[i]->ch_c_iflag);
6660 static DEVICE_ATTR(ports_iflag, S_IRUSR, dgap_ports_iflag_show, NULL);
6663 static ssize_t dgap_ports_cflag_show(struct device *p, struct device_attribute *attr, char *buf)
6669 DGAP_VERIFY_BOARD(p, bd);
6671 for (i = 0; i < bd->nasync; i++) {
6672 count += snprintf(buf + count, PAGE_SIZE - count, "%d %x\n",
6673 bd->channels[i]->ch_portnum, bd->channels[i]->ch_c_cflag);
6677 static DEVICE_ATTR(ports_cflag, S_IRUSR, dgap_ports_cflag_show, NULL);
6680 static ssize_t dgap_ports_oflag_show(struct device *p, struct device_attribute *attr, char *buf)
6686 DGAP_VERIFY_BOARD(p, bd);
6688 for (i = 0; i < bd->nasync; i++) {
6689 count += snprintf(buf + count, PAGE_SIZE - count, "%d %x\n",
6690 bd->channels[i]->ch_portnum, bd->channels[i]->ch_c_oflag);
6694 static DEVICE_ATTR(ports_oflag, S_IRUSR, dgap_ports_oflag_show, NULL);
6697 static ssize_t dgap_ports_lflag_show(struct device *p, struct device_attribute *attr, char *buf)
6703 DGAP_VERIFY_BOARD(p, bd);
6705 for (i = 0; i < bd->nasync; i++) {
6706 count += snprintf(buf + count, PAGE_SIZE - count, "%d %x\n",
6707 bd->channels[i]->ch_portnum, bd->channels[i]->ch_c_lflag);
6711 static DEVICE_ATTR(ports_lflag, S_IRUSR, dgap_ports_lflag_show, NULL);
6714 static ssize_t dgap_ports_digi_flag_show(struct device *p, struct device_attribute *attr, char *buf)
6720 DGAP_VERIFY_BOARD(p, bd);
6722 for (i = 0; i < bd->nasync; i++) {
6723 count += snprintf(buf + count, PAGE_SIZE - count, "%d %x\n",
6724 bd->channels[i]->ch_portnum, bd->channels[i]->ch_digi.digi_flags);
6728 static DEVICE_ATTR(ports_digi_flag, S_IRUSR, dgap_ports_digi_flag_show, NULL);
6731 static ssize_t dgap_ports_rxcount_show(struct device *p, struct device_attribute *attr, char *buf)
6737 DGAP_VERIFY_BOARD(p, bd);
6739 for (i = 0; i < bd->nasync; i++) {
6740 count += snprintf(buf + count, PAGE_SIZE - count, "%d %ld\n",
6741 bd->channels[i]->ch_portnum, bd->channels[i]->ch_rxcount);
6745 static DEVICE_ATTR(ports_rxcount, S_IRUSR, dgap_ports_rxcount_show, NULL);
6748 static ssize_t dgap_ports_txcount_show(struct device *p, struct device_attribute *attr, char *buf)
6754 DGAP_VERIFY_BOARD(p, bd);
6756 for (i = 0; i < bd->nasync; i++) {
6757 count += snprintf(buf + count, PAGE_SIZE - count, "%d %ld\n",
6758 bd->channels[i]->ch_portnum, bd->channels[i]->ch_txcount);
6762 static DEVICE_ATTR(ports_txcount, S_IRUSR, dgap_ports_txcount_show, NULL);
6765 /* this function creates the sys files that will export each signal status
6766 * to sysfs each value will be put in a separate filename
6768 void dgap_create_ports_sysfiles(struct board_t *bd)
6772 dev_set_drvdata(&bd->pdev->dev, bd);
6773 rc |= device_create_file(&(bd->pdev->dev), &dev_attr_ports_state);
6774 rc |= device_create_file(&(bd->pdev->dev), &dev_attr_ports_baud);
6775 rc |= device_create_file(&(bd->pdev->dev), &dev_attr_ports_msignals);
6776 rc |= device_create_file(&(bd->pdev->dev), &dev_attr_ports_iflag);
6777 rc |= device_create_file(&(bd->pdev->dev), &dev_attr_ports_cflag);
6778 rc |= device_create_file(&(bd->pdev->dev), &dev_attr_ports_oflag);
6779 rc |= device_create_file(&(bd->pdev->dev), &dev_attr_ports_lflag);
6780 rc |= device_create_file(&(bd->pdev->dev), &dev_attr_ports_digi_flag);
6781 rc |= device_create_file(&(bd->pdev->dev), &dev_attr_ports_rxcount);
6782 rc |= device_create_file(&(bd->pdev->dev), &dev_attr_ports_txcount);
6784 printk(KERN_ERR "DGAP: sysfs device_create_file failed!\n");
6789 /* removes all the sys files created for that port */
6790 void dgap_remove_ports_sysfiles(struct board_t *bd)
6792 device_remove_file(&(bd->pdev->dev), &dev_attr_ports_state);
6793 device_remove_file(&(bd->pdev->dev), &dev_attr_ports_baud);
6794 device_remove_file(&(bd->pdev->dev), &dev_attr_ports_msignals);
6795 device_remove_file(&(bd->pdev->dev), &dev_attr_ports_iflag);
6796 device_remove_file(&(bd->pdev->dev), &dev_attr_ports_cflag);
6797 device_remove_file(&(bd->pdev->dev), &dev_attr_ports_oflag);
6798 device_remove_file(&(bd->pdev->dev), &dev_attr_ports_lflag);
6799 device_remove_file(&(bd->pdev->dev), &dev_attr_ports_digi_flag);
6800 device_remove_file(&(bd->pdev->dev), &dev_attr_ports_rxcount);
6801 device_remove_file(&(bd->pdev->dev), &dev_attr_ports_txcount);
6805 static ssize_t dgap_tty_state_show(struct device *d, struct device_attribute *attr, char *buf)
6808 struct channel_t *ch;
6813 un = dev_get_drvdata(d);
6814 if (!un || un->magic != DGAP_UNIT_MAGIC)
6817 if (!ch || ch->magic != DGAP_CHANNEL_MAGIC)
6820 if (!bd || bd->magic != DGAP_BOARD_MAGIC)
6822 if (bd->state != BOARD_READY)
6825 return snprintf(buf, PAGE_SIZE, "%s", un->un_open_count ? "Open" : "Closed");
6827 static DEVICE_ATTR(state, S_IRUSR, dgap_tty_state_show, NULL);
6830 static ssize_t dgap_tty_baud_show(struct device *d, struct device_attribute *attr, char *buf)
6833 struct channel_t *ch;
6838 un = dev_get_drvdata(d);
6839 if (!un || un->magic != DGAP_UNIT_MAGIC)
6842 if (!ch || ch->magic != DGAP_CHANNEL_MAGIC)
6845 if (!bd || bd->magic != DGAP_BOARD_MAGIC)
6847 if (bd->state != BOARD_READY)
6850 return snprintf(buf, PAGE_SIZE, "%d\n", ch->ch_baud_info);
6852 static DEVICE_ATTR(baud, S_IRUSR, dgap_tty_baud_show, NULL);
6855 static ssize_t dgap_tty_msignals_show(struct device *d, struct device_attribute *attr, char *buf)
6858 struct channel_t *ch;
6863 un = dev_get_drvdata(d);
6864 if (!un || un->magic != DGAP_UNIT_MAGIC)
6867 if (!ch || ch->magic != DGAP_CHANNEL_MAGIC)
6870 if (!bd || bd->magic != DGAP_BOARD_MAGIC)
6872 if (bd->state != BOARD_READY)
6875 if (ch->ch_open_count) {
6876 return snprintf(buf, PAGE_SIZE, "%s %s %s %s %s %s\n",
6877 (ch->ch_mostat & UART_MCR_RTS) ? "RTS" : "",
6878 (ch->ch_mistat & UART_MSR_CTS) ? "CTS" : "",
6879 (ch->ch_mostat & UART_MCR_DTR) ? "DTR" : "",
6880 (ch->ch_mistat & UART_MSR_DSR) ? "DSR" : "",
6881 (ch->ch_mistat & UART_MSR_DCD) ? "DCD" : "",
6882 (ch->ch_mistat & UART_MSR_RI) ? "RI" : "");
6886 static DEVICE_ATTR(msignals, S_IRUSR, dgap_tty_msignals_show, NULL);
6889 static ssize_t dgap_tty_iflag_show(struct device *d, struct device_attribute *attr, char *buf)
6892 struct channel_t *ch;
6897 un = dev_get_drvdata(d);
6898 if (!un || un->magic != DGAP_UNIT_MAGIC)
6901 if (!ch || ch->magic != DGAP_CHANNEL_MAGIC)
6904 if (!bd || bd->magic != DGAP_BOARD_MAGIC)
6906 if (bd->state != BOARD_READY)
6909 return snprintf(buf, PAGE_SIZE, "%x\n", ch->ch_c_iflag);
6911 static DEVICE_ATTR(iflag, S_IRUSR, dgap_tty_iflag_show, NULL);
6914 static ssize_t dgap_tty_cflag_show(struct device *d, struct device_attribute *attr, char *buf)
6917 struct channel_t *ch;
6922 un = dev_get_drvdata(d);
6923 if (!un || un->magic != DGAP_UNIT_MAGIC)
6926 if (!ch || ch->magic != DGAP_CHANNEL_MAGIC)
6929 if (!bd || bd->magic != DGAP_BOARD_MAGIC)
6931 if (bd->state != BOARD_READY)
6934 return snprintf(buf, PAGE_SIZE, "%x\n", ch->ch_c_cflag);
6936 static DEVICE_ATTR(cflag, S_IRUSR, dgap_tty_cflag_show, NULL);
6939 static ssize_t dgap_tty_oflag_show(struct device *d, struct device_attribute *attr, char *buf)
6942 struct channel_t *ch;
6947 un = dev_get_drvdata(d);
6948 if (!un || un->magic != DGAP_UNIT_MAGIC)
6951 if (!ch || ch->magic != DGAP_CHANNEL_MAGIC)
6954 if (!bd || bd->magic != DGAP_BOARD_MAGIC)
6956 if (bd->state != BOARD_READY)
6959 return snprintf(buf, PAGE_SIZE, "%x\n", ch->ch_c_oflag);
6961 static DEVICE_ATTR(oflag, S_IRUSR, dgap_tty_oflag_show, NULL);
6964 static ssize_t dgap_tty_lflag_show(struct device *d, struct device_attribute *attr, char *buf)
6967 struct channel_t *ch;
6972 un = dev_get_drvdata(d);
6973 if (!un || un->magic != DGAP_UNIT_MAGIC)
6976 if (!ch || ch->magic != DGAP_CHANNEL_MAGIC)
6979 if (!bd || bd->magic != DGAP_BOARD_MAGIC)
6981 if (bd->state != BOARD_READY)
6984 return snprintf(buf, PAGE_SIZE, "%x\n", ch->ch_c_lflag);
6986 static DEVICE_ATTR(lflag, S_IRUSR, dgap_tty_lflag_show, NULL);
6989 static ssize_t dgap_tty_digi_flag_show(struct device *d, struct device_attribute *attr, char *buf)
6992 struct channel_t *ch;
6997 un = dev_get_drvdata(d);
6998 if (!un || un->magic != DGAP_UNIT_MAGIC)
7001 if (!ch || ch->magic != DGAP_CHANNEL_MAGIC)
7004 if (!bd || bd->magic != DGAP_BOARD_MAGIC)
7006 if (bd->state != BOARD_READY)
7009 return snprintf(buf, PAGE_SIZE, "%x\n", ch->ch_digi.digi_flags);
7011 static DEVICE_ATTR(digi_flag, S_IRUSR, dgap_tty_digi_flag_show, NULL);
7014 static ssize_t dgap_tty_rxcount_show(struct device *d, struct device_attribute *attr, char *buf)
7017 struct channel_t *ch;
7022 un = dev_get_drvdata(d);
7023 if (!un || un->magic != DGAP_UNIT_MAGIC)
7026 if (!ch || ch->magic != DGAP_CHANNEL_MAGIC)
7029 if (!bd || bd->magic != DGAP_BOARD_MAGIC)
7031 if (bd->state != BOARD_READY)
7034 return snprintf(buf, PAGE_SIZE, "%ld\n", ch->ch_rxcount);
7036 static DEVICE_ATTR(rxcount, S_IRUSR, dgap_tty_rxcount_show, NULL);
7039 static ssize_t dgap_tty_txcount_show(struct device *d, struct device_attribute *attr, char *buf)
7042 struct channel_t *ch;
7047 un = dev_get_drvdata(d);
7048 if (!un || un->magic != DGAP_UNIT_MAGIC)
7051 if (!ch || ch->magic != DGAP_CHANNEL_MAGIC)
7054 if (!bd || bd->magic != DGAP_BOARD_MAGIC)
7056 if (bd->state != BOARD_READY)
7059 return snprintf(buf, PAGE_SIZE, "%ld\n", ch->ch_txcount);
7061 static DEVICE_ATTR(txcount, S_IRUSR, dgap_tty_txcount_show, NULL);
7064 static ssize_t dgap_tty_name_show(struct device *d, struct device_attribute *attr, char *buf)
7067 struct channel_t *ch;
7071 struct cnode *cptr = NULL;
7079 un = dev_get_drvdata(d);
7080 if (!un || un->magic != DGAP_UNIT_MAGIC)
7083 if (!ch || ch->magic != DGAP_CHANNEL_MAGIC)
7086 if (!bd || bd->magic != DGAP_BOARD_MAGIC)
7088 if (bd->state != BOARD_READY)
7092 cn = ch->ch_portnum;
7094 for (cptr = bd->bd_config; cptr; cptr = cptr->next) {
7096 if ((cptr->type == BNODE) &&
7097 ((cptr->u.board.type == APORT2_920P) || (cptr->u.board.type == APORT4_920P) ||
7098 (cptr->u.board.type == APORT8_920P) || (cptr->u.board.type == PAPORT4) ||
7099 (cptr->u.board.type == PAPORT8))) {
7102 if (cptr->u.board.v_start)
7103 starto = cptr->u.board.start;
7108 if (cptr->type == TNODE && found == TRUE) {
7110 if (strstr(cptr->u.ttyname, "tty")) {
7111 ptr1 = cptr->u.ttyname;
7115 ptr1 = cptr->u.ttyname;
7118 for (i = 0; i < dgap_config_get_number_of_ports(bd); i++) {
7120 return snprintf(buf, PAGE_SIZE, "%s%s%02d\n",
7121 (un->un_type == DGAP_PRINT) ? "pr" : "tty",
7127 if (cptr->type == CNODE) {
7129 for (i = 0; i < cptr->u.conc.nport; i++) {
7130 if (cn == (i + ncount)) {
7132 return snprintf(buf, PAGE_SIZE, "%s%s%02d\n",
7133 (un->un_type == DGAP_PRINT) ? "pr" : "tty",
7135 i + (cptr->u.conc.v_start ? cptr->u.conc.start : 1));
7139 ncount += cptr->u.conc.nport;
7142 if (cptr->type == MNODE) {
7144 for (i = 0; i < cptr->u.module.nport; i++) {
7145 if (cn == (i + ncount)) {
7146 return snprintf(buf, PAGE_SIZE, "%s%s%02d\n",
7147 (un->un_type == DGAP_PRINT) ? "pr" : "tty",
7149 i + (cptr->u.module.v_start ? cptr->u.module.start : 1));
7153 ncount += cptr->u.module.nport;
7158 return snprintf(buf, PAGE_SIZE, "%s_dgap_%d_%d\n",
7159 (un->un_type == DGAP_PRINT) ? "pr" : "tty", bn, cn);
7162 static DEVICE_ATTR(custom_name, S_IRUSR, dgap_tty_name_show, NULL);
7165 static struct attribute *dgap_sysfs_tty_entries[] = {
7166 &dev_attr_state.attr,
7167 &dev_attr_baud.attr,
7168 &dev_attr_msignals.attr,
7169 &dev_attr_iflag.attr,
7170 &dev_attr_cflag.attr,
7171 &dev_attr_oflag.attr,
7172 &dev_attr_lflag.attr,
7173 &dev_attr_digi_flag.attr,
7174 &dev_attr_rxcount.attr,
7175 &dev_attr_txcount.attr,
7176 &dev_attr_custom_name.attr,
7181 static struct attribute_group dgap_tty_attribute_group = {
7183 .attrs = dgap_sysfs_tty_entries,
7189 void dgap_create_tty_sysfs(struct un_t *un, struct device *c)
7193 ret = sysfs_create_group(&c->kobj, &dgap_tty_attribute_group);
7195 printk(KERN_ERR "dgap: failed to create sysfs tty device attributes.\n");
7196 sysfs_remove_group(&c->kobj, &dgap_tty_attribute_group);
7200 dev_set_drvdata(c, un);
7205 void dgap_remove_tty_sysfs(struct device *c)
7207 sysfs_remove_group(&c->kobj, &dgap_tty_attribute_group);
7211 * Parse a configuration file read into memory as a string.
7213 int dgap_parsefile(char **in, int Remove)
7215 struct cnode *p, *brd, *line, *conc;
7217 char *s = NULL, *s2 = NULL;
7221 brd = line = conc = NULL;
7223 /* perhaps we are adding to an existing list? */
7224 while (p->next != NULL) {
7228 /* file must start with a BEGIN */
7229 while ( (rc = dgap_gettok(in,p)) != BEGIN ) {
7231 dgap_err("unexpected EOF");
7237 rc = dgap_gettok(in,p);
7239 dgap_err("unexpected EOF");
7245 dgap_err("unexpected end of file");
7248 case BEGIN: /* should only be 1 begin */
7249 dgap_err("unexpected config_begin\n");
7255 case BOARD: /* board info */
7256 if (dgap_checknode(p))
7258 if ( (p->next = dgap_newnode(BNODE)) == NULL ) {
7259 dgap_err("out of memory");
7264 p->u.board.status = dgap_savestring("No");
7270 case APORT2_920P: /* AccelePort_4 */
7271 if (p->type != BNODE) {
7272 dgap_err("unexpected Digi_2r_920 string");
7275 p->u.board.type = APORT2_920P;
7276 p->u.board.v_type = 1;
7277 DPR_INIT(("Adding Digi_2r_920 PCI to config...\n"));
7280 case APORT4_920P: /* AccelePort_4 */
7281 if (p->type != BNODE) {
7282 dgap_err("unexpected Digi_4r_920 string");
7285 p->u.board.type = APORT4_920P;
7286 p->u.board.v_type = 1;
7287 DPR_INIT(("Adding Digi_4r_920 PCI to config...\n"));
7290 case APORT8_920P: /* AccelePort_8 */
7291 if (p->type != BNODE) {
7292 dgap_err("unexpected Digi_8r_920 string");
7295 p->u.board.type = APORT8_920P;
7296 p->u.board.v_type = 1;
7297 DPR_INIT(("Adding Digi_8r_920 PCI to config...\n"));
7300 case PAPORT4: /* AccelePort_4 PCI */
7301 if (p->type != BNODE) {
7302 dgap_err("unexpected Digi_4r(PCI) string");
7305 p->u.board.type = PAPORT4;
7306 p->u.board.v_type = 1;
7307 DPR_INIT(("Adding Digi_4r PCI to config...\n"));
7310 case PAPORT8: /* AccelePort_8 PCI */
7311 if (p->type != BNODE) {
7312 dgap_err("unexpected Digi_8r string");
7315 p->u.board.type = PAPORT8;
7316 p->u.board.v_type = 1;
7317 DPR_INIT(("Adding Digi_8r PCI to config...\n"));
7320 case PCX: /* PCI C/X */
7321 if (p->type != BNODE) {
7322 dgap_err("unexpected Digi_C/X_(PCI) string");
7325 p->u.board.type = PCX;
7326 p->u.board.v_type = 1;
7327 p->u.board.conc1 = 0;
7328 p->u.board.conc2 = 0;
7329 p->u.board.module1 = 0;
7330 p->u.board.module2 = 0;
7331 DPR_INIT(("Adding PCI C/X to config...\n"));
7334 case PEPC: /* PCI EPC/X */
7335 if (p->type != BNODE) {
7336 dgap_err("unexpected \"Digi_EPC/X_(PCI)\" string");
7339 p->u.board.type = PEPC;
7340 p->u.board.v_type = 1;
7341 p->u.board.conc1 = 0;
7342 p->u.board.conc2 = 0;
7343 p->u.board.module1 = 0;
7344 p->u.board.module2 = 0;
7345 DPR_INIT(("Adding PCI EPC/X to config...\n"));
7348 case PPCM: /* PCI/Xem */
7349 if (p->type != BNODE) {
7350 dgap_err("unexpected PCI/Xem string");
7353 p->u.board.type = PPCM;
7354 p->u.board.v_type = 1;
7355 p->u.board.conc1 = 0;
7356 p->u.board.conc2 = 0;
7357 DPR_INIT(("Adding PCI XEM to config...\n"));
7360 case IO: /* i/o port */
7361 if (p->type != BNODE) {
7362 dgap_err("IO port only vaild for boards");
7365 s = dgap_getword(in);
7367 dgap_err("unexpected end of file");
7370 p->u.board.portstr = dgap_savestring(s);
7371 p->u.board.port = (short)simple_strtol(s, &s2, 0);
7372 if ((short)strlen(s) > (short)(s2 - s)) {
7373 dgap_err("bad number for IO port");
7376 p->u.board.v_port = 1;
7377 DPR_INIT(("Adding IO (%s) to config...\n", s));
7380 case MEM: /* memory address */
7381 if (p->type != BNODE) {
7382 dgap_err("memory address only vaild for boards");
7385 s = dgap_getword(in);
7387 dgap_err("unexpected end of file");
7390 p->u.board.addrstr = dgap_savestring(s);
7391 p->u.board.addr = simple_strtoul(s, &s2, 0);
7392 if ((int)strlen(s) > (int)(s2 - s)) {
7393 dgap_err("bad number for memory address");
7396 p->u.board.v_addr = 1;
7397 DPR_INIT(("Adding MEM (%s) to config...\n", s));
7400 case PCIINFO: /* pci information */
7401 if (p->type != BNODE) {
7402 dgap_err("memory address only vaild for boards");
7405 s = dgap_getword(in);
7407 dgap_err("unexpected end of file");
7410 p->u.board.pcibusstr = dgap_savestring(s);
7411 p->u.board.pcibus = simple_strtoul(s, &s2, 0);
7412 if ((int)strlen(s) > (int)(s2 - s)) {
7413 dgap_err("bad number for pci bus");
7416 p->u.board.v_pcibus = 1;
7417 s = dgap_getword(in);
7419 dgap_err("unexpected end of file");
7422 p->u.board.pcislotstr = dgap_savestring(s);
7423 p->u.board.pcislot = simple_strtoul(s, &s2, 0);
7424 if ((int)strlen(s) > (int)(s2 - s)) {
7425 dgap_err("bad number for pci slot");
7428 p->u.board.v_pcislot = 1;
7430 DPR_INIT(("Adding PCIINFO (%s %s) to config...\n", p->u.board.pcibusstr,
7431 p->u.board.pcislotstr));
7435 if (p->type != BNODE) {
7436 dgap_err("install method only vaild for boards");
7439 s = dgap_getword(in);
7441 dgap_err("unexpected end of file");
7444 p->u.board.method = dgap_savestring(s);
7445 p->u.board.v_method = 1;
7446 DPR_INIT(("Adding METHOD (%s) to config...\n", s));
7450 if (p->type != BNODE) {
7451 dgap_err("config status only vaild for boards");
7454 s = dgap_getword(in);
7456 dgap_err("unexpected end of file");
7459 p->u.board.status = dgap_savestring(s);
7460 DPR_INIT(("Adding STATUS (%s) to config...\n", s));
7463 case NPORTS: /* number of ports */
7464 if (p->type == BNODE) {
7465 s = dgap_getword(in);
7467 dgap_err("unexpected end of file");
7470 p->u.board.nport = (char)simple_strtol(s, &s2, 0);
7471 if ((int)strlen(s) > (int)(s2 - s)) {
7472 dgap_err("bad number for number of ports");
7475 p->u.board.v_nport = 1;
7476 } else if (p->type == CNODE) {
7477 s = dgap_getword(in);
7479 dgap_err("unexpected end of file");
7482 p->u.conc.nport = (char)simple_strtol(s, &s2, 0);
7483 if ((int)strlen(s) > (int)(s2 - s)) {
7484 dgap_err("bad number for number of ports");
7487 p->u.conc.v_nport = 1;
7488 } else if (p->type == MNODE) {
7489 s = dgap_getword(in);
7491 dgap_err("unexpected end of file");
7494 p->u.module.nport = (char)simple_strtol(s, &s2, 0);
7495 if ((int)strlen(s) > (int)(s2 - s)) {
7496 dgap_err("bad number for number of ports");
7499 p->u.module.v_nport = 1;
7501 dgap_err("nports only valid for concentrators or modules");
7504 DPR_INIT(("Adding NPORTS (%s) to config...\n", s));
7507 case ID: /* letter ID used in tty name */
7508 s = dgap_getword(in);
7510 dgap_err("unexpected end of file");
7514 p->u.board.status = dgap_savestring(s);
7516 if (p->type == CNODE) {
7517 p->u.conc.id = dgap_savestring(s);
7519 } else if (p->type == MNODE) {
7520 p->u.module.id = dgap_savestring(s);
7521 p->u.module.v_id = 1;
7523 dgap_err("id only valid for concentrators or modules");
7526 DPR_INIT(("Adding ID (%s) to config...\n", s));
7529 case STARTO: /* start offset of ID */
7530 if (p->type == BNODE) {
7531 s = dgap_getword(in);
7533 dgap_err("unexpected end of file");
7536 p->u.board.start = simple_strtol(s, &s2, 0);
7537 if ((int)strlen(s) > (int)(s2 - s)) {
7538 dgap_err("bad number for start of tty count");
7541 p->u.board.v_start = 1;
7542 } else if (p->type == CNODE) {
7543 s = dgap_getword(in);
7545 dgap_err("unexpected end of file");
7548 p->u.conc.start = simple_strtol(s, &s2, 0);
7549 if ((int)strlen(s) > (int)(s2 - s)) {
7550 dgap_err("bad number for start of tty count");
7553 p->u.conc.v_start = 1;
7554 } else if (p->type == MNODE) {
7555 s = dgap_getword(in);
7557 dgap_err("unexpected end of file");
7560 p->u.module.start = simple_strtol(s, &s2, 0);
7561 if ((int)strlen(s) > (int)(s2 - s)) {
7562 dgap_err("bad number for start of tty count");
7565 p->u.module.v_start = 1;
7567 dgap_err("start only valid for concentrators or modules");
7570 DPR_INIT(("Adding START (%s) to config...\n", s));
7573 case TTYN: /* tty name prefix */
7574 if (dgap_checknode(p))
7576 if ( (p->next = dgap_newnode(TNODE)) == NULL ) {
7577 dgap_err("out of memory");
7581 if ( (s = dgap_getword(in)) == NULL ) {
7582 dgap_err("unexpeced end of file");
7585 if ( (p->u.ttyname = dgap_savestring(s)) == NULL ) {
7586 dgap_err("out of memory");
7589 DPR_INIT(("Adding TTY (%s) to config...\n", s));
7592 case CU: /* cu name prefix */
7593 if (dgap_checknode(p))
7595 if ( (p->next = dgap_newnode(CUNODE)) == NULL ) {
7596 dgap_err("out of memory");
7600 if ( (s = dgap_getword(in)) == NULL ) {
7601 dgap_err("unexpeced end of file");
7604 if ( (p->u.cuname = dgap_savestring(s)) == NULL ) {
7605 dgap_err("out of memory");
7608 DPR_INIT(("Adding CU (%s) to config...\n", s));
7611 case LINE: /* line information */
7612 if (dgap_checknode(p))
7615 dgap_err("must specify board before line info");
7618 switch (brd->u.board.type) {
7620 dgap_err("line not vaild for PC/em");
7623 if ( (p->next = dgap_newnode(LNODE)) == NULL ) {
7624 dgap_err("out of memory");
7631 DPR_INIT(("Adding LINE to config...\n"));
7634 case CONC: /* concentrator information */
7635 if (dgap_checknode(p))
7638 dgap_err("must specify line info before concentrator");
7641 if ( (p->next = dgap_newnode(CNODE)) == NULL ) {
7642 dgap_err("out of memory");
7648 brd->u.board.conc2++;
7650 brd->u.board.conc1++;
7652 DPR_INIT(("Adding CONC to config...\n"));
7655 case CX: /* c/x type concentrator */
7656 if (p->type != CNODE) {
7657 dgap_err("cx only valid for concentrators");
7660 p->u.conc.type = CX;
7661 p->u.conc.v_type = 1;
7662 DPR_INIT(("Adding CX to config...\n"));
7665 case EPC: /* epc type concentrator */
7666 if (p->type != CNODE) {
7667 dgap_err("cx only valid for concentrators");
7670 p->u.conc.type = EPC;
7671 p->u.conc.v_type = 1;
7672 DPR_INIT(("Adding EPC to config...\n"));
7675 case MOD: /* EBI module */
7676 if (dgap_checknode(p))
7679 dgap_err("must specify board info before EBI modules");
7682 switch (brd->u.board.type) {
7688 dgap_err("must specify concentrator info before EBI module");
7692 if ( (p->next = dgap_newnode(MNODE)) == NULL ) {
7693 dgap_err("out of memory");
7698 brd->u.board.module2++;
7700 brd->u.board.module1++;
7702 DPR_INIT(("Adding MOD to config...\n"));
7705 case PORTS: /* ports type EBI module */
7706 if (p->type != MNODE) {
7707 dgap_err("ports only valid for EBI modules");
7710 p->u.module.type = PORTS;
7711 p->u.module.v_type = 1;
7712 DPR_INIT(("Adding PORTS to config...\n"));
7715 case MODEM: /* ports type EBI module */
7716 if (p->type != MNODE) {
7717 dgap_err("modem only valid for modem modules");
7720 p->u.module.type = MODEM;
7721 p->u.module.v_type = 1;
7722 DPR_INIT(("Adding MODEM to config...\n"));
7726 if (p->type == LNODE) {
7727 if ((s = dgap_getword(in)) == NULL) {
7728 dgap_err("unexpected end of file");
7731 p->u.line.cable = dgap_savestring(s);
7732 p->u.line.v_cable = 1;
7734 DPR_INIT(("Adding CABLE (%s) to config...\n", s));
7737 case SPEED: /* sync line speed indication */
7738 if (p->type == LNODE) {
7739 s = dgap_getword(in);
7741 dgap_err("unexpected end of file");
7744 p->u.line.speed = (char)simple_strtol(s, &s2, 0);
7745 if ((short)strlen(s) > (short)(s2 - s)) {
7746 dgap_err("bad number for line speed");
7749 p->u.line.v_speed = 1;
7750 } else if (p->type == CNODE) {
7751 s = dgap_getword(in);
7753 dgap_err("unexpected end of file");
7756 p->u.conc.speed = (char)simple_strtol(s, &s2, 0);
7757 if ((short)strlen(s) > (short)(s2 - s)) {
7758 dgap_err("bad number for line speed");
7761 p->u.conc.v_speed = 1;
7763 dgap_err("speed valid only for lines or concentrators.");
7766 DPR_INIT(("Adding SPEED (%s) to config...\n", s));
7770 if (p->type == CNODE) {
7771 if ((s = dgap_getword(in)) == NULL) {
7772 dgap_err("unexpected end of file");
7775 p->u.conc.connect = dgap_savestring(s);
7776 p->u.conc.v_connect = 1;
7778 DPR_INIT(("Adding CONNECT (%s) to config...\n", s));
7780 case PRINT: /* transparent print name prefix */
7781 if (dgap_checknode(p))
7783 if ( (p->next = dgap_newnode(PNODE)) == NULL ) {
7784 dgap_err("out of memory");
7788 if ( (s = dgap_getword(in)) == NULL ) {
7789 dgap_err("unexpeced end of file");
7792 if ( (p->u.printname = dgap_savestring(s)) == NULL ) {
7793 dgap_err("out of memory");
7796 DPR_INIT(("Adding PRINT (%s) to config...\n", s));
7799 case CMAJOR: /* major number */
7800 if (dgap_checknode(p))
7802 if ( (p->next = dgap_newnode(JNODE)) == NULL ) {
7803 dgap_err("out of memory");
7807 s = dgap_getword(in);
7809 dgap_err("unexpected end of file");
7812 p->u.majornumber = simple_strtol(s, &s2, 0);
7813 if ((int)strlen(s) > (int)(s2 - s)) {
7814 dgap_err("bad number for major number");
7817 DPR_INIT(("Adding CMAJOR (%s) to config...\n", s));
7820 case ALTPIN: /* altpin setting */
7821 if (dgap_checknode(p))
7823 if ( (p->next = dgap_newnode(ANODE)) == NULL ) {
7824 dgap_err("out of memory");
7828 s = dgap_getword(in);
7830 dgap_err("unexpected end of file");
7833 p->u.altpin = simple_strtol(s, &s2, 0);
7834 if ((int)strlen(s) > (int)(s2 - s)) {
7835 dgap_err("bad number for altpin");
7838 DPR_INIT(("Adding ALTPIN (%s) to config...\n", s));
7841 case USEINTR: /* enable interrupt setting */
7842 if (dgap_checknode(p))
7844 if ( (p->next = dgap_newnode(INTRNODE)) == NULL ) {
7845 dgap_err("out of memory");
7849 s = dgap_getword(in);
7851 dgap_err("unexpected end of file");
7854 p->u.useintr = simple_strtol(s, &s2, 0);
7855 if ((int)strlen(s) > (int)(s2 - s)) {
7856 dgap_err("bad number for useintr");
7859 DPR_INIT(("Adding USEINTR (%s) to config...\n", s));
7862 case TTSIZ: /* size of tty structure */
7863 if (dgap_checknode(p))
7865 if ( (p->next = dgap_newnode(TSNODE)) == NULL ) {
7866 dgap_err("out of memory");
7870 s = dgap_getword(in);
7872 dgap_err("unexpected end of file");
7875 p->u.ttysize = simple_strtol(s, &s2, 0);
7876 if ((int)strlen(s) > (int)(s2 - s)) {
7877 dgap_err("bad number for ttysize");
7880 DPR_INIT(("Adding TTSIZ (%s) to config...\n", s));
7883 case CHSIZ: /* channel structure size */
7884 if (dgap_checknode(p))
7886 if ( (p->next = dgap_newnode(CSNODE)) == NULL ) {
7887 dgap_err("out of memory");
7891 s = dgap_getword(in);
7893 dgap_err("unexpected end of file");
7896 p->u.chsize = simple_strtol(s, &s2, 0);
7897 if ((int)strlen(s) > (int)(s2 - s)) {
7898 dgap_err("bad number for chsize");
7901 DPR_INIT(("Adding CHSIZE (%s) to config...\n", s));
7904 case BSSIZ: /* board structure size */
7905 if (dgap_checknode(p))
7907 if ( (p->next = dgap_newnode(BSNODE)) == NULL ) {
7908 dgap_err("out of memory");
7912 s = dgap_getword(in);
7914 dgap_err("unexpected end of file");
7917 p->u.bssize = simple_strtol(s, &s2, 0);
7918 if ((int)strlen(s) > (int)(s2 - s)) {
7919 dgap_err("bad number for bssize");
7922 DPR_INIT(("Adding BSSIZ (%s) to config...\n", s));
7925 case UNTSIZ: /* sched structure size */
7926 if (dgap_checknode(p))
7928 if ( (p->next = dgap_newnode(USNODE)) == NULL ) {
7929 dgap_err("out of memory");
7933 s = dgap_getword(in);
7935 dgap_err("unexpected end of file");
7938 p->u.unsize = simple_strtol(s, &s2, 0);
7939 if ((int)strlen(s) > (int)(s2 - s)) {
7940 dgap_err("bad number for schedsize");
7943 DPR_INIT(("Adding UNTSIZ (%s) to config...\n", s));
7946 case F2SIZ: /* f2200 structure size */
7947 if (dgap_checknode(p))
7949 if ( (p->next = dgap_newnode(FSNODE)) == NULL ) {
7950 dgap_err("out of memory");
7954 s = dgap_getword(in);
7956 dgap_err("unexpected end of file");
7959 p->u.f2size = simple_strtol(s, &s2, 0);
7960 if ((int)strlen(s) > (int)(s2 - s)) {
7961 dgap_err("bad number for f2200size");
7964 DPR_INIT(("Adding F2SIZ (%s) to config...\n", s));
7967 case VPSIZ: /* vpix structure size */
7968 if (dgap_checknode(p))
7970 if ( (p->next = dgap_newnode(VSNODE)) == NULL ) {
7971 dgap_err("out of memory");
7975 s = dgap_getword(in);
7977 dgap_err("unexpected end of file");
7980 p->u.vpixsize = simple_strtol(s, &s2, 0);
7981 if ((int)strlen(s) > (int)(s2 - s)) {
7982 dgap_err("bad number for vpixsize");
7985 DPR_INIT(("Adding VPSIZ (%s) to config...\n", s));
7993 * dgap_sindex: much like index(), but it looks for a match of any character in
7994 * the group, and returns that position. If the first character is a ^, then
7995 * this will match the first occurrence not in that group.
7997 static char *dgap_sindex (char *string, char *group)
8001 if (!string || !group)
8002 return (char *) NULL;
8004 if (*group == '^') {
8006 for (; *string; string++) {
8007 for (ptr = group; *ptr; ptr++) {
8008 if (*ptr == *string)
8016 for (; *string; string++) {
8017 for (ptr = group; *ptr; ptr++) {
8018 if (*ptr == *string)
8024 return (char *) NULL;
8029 * Get a token from the input file; return 0 if end of file is reached
8031 static int dgap_gettok(char **in, struct cnode *p)
8036 if (strstr(dgap_cword, "boar")) {
8037 w = dgap_getword(in);
8038 snprintf(dgap_cword, MAXCWORD, "%s", w);
8039 for (t = dgap_tlist; t->token != 0; t++) {
8040 if ( !strcmp(w, t->string)) {
8044 dgap_err("board !!type not specified");
8048 while ( (w = dgap_getword(in)) != NULL ) {
8049 snprintf(dgap_cword, MAXCWORD, "%s", w);
8050 for (t = dgap_tlist; t->token != 0; t++) {
8051 if ( !strcmp(w, t->string) )
8061 * get a word from the input stream, also keep track of current line number.
8062 * words are separated by whitespace.
8064 static char *dgap_getword(char **in)
8066 char *ret_ptr = *in;
8068 char *ptr = dgap_sindex(*in, " \t\n");
8070 /* If no word found, return null */
8074 /* Mark new location for our buffer */
8078 /* Eat any extra spaces/tabs/newlines that might be present */
8079 while (*in && **in && ((**in == ' ') || (**in == '\t') || (**in == '\n'))) {
8089 * print an error message, giving the line number in the file where
8090 * the error occurred.
8092 static void dgap_err(char *s)
8094 printk("DGAP: parse: %s\n", s);
8099 * allocate a new configuration node of type t
8101 static struct cnode *dgap_newnode(int t)
8105 n = kmalloc(sizeof(struct cnode), GFP_ATOMIC);
8107 memset((char *)n, 0, sizeof(struct cnode));
8115 * dgap_checknode: see if all the necessary info has been supplied for a node
8116 * before creating the next node.
8118 static int dgap_checknode(struct cnode *p)
8122 if (p->u.board.v_type == 0) {
8123 dgap_err("board type !not specified");
8130 if (p->u.line.v_speed == 0) {
8131 dgap_err("line speed not specified");
8137 if (p->u.conc.v_type == 0) {
8138 dgap_err("concentrator type not specified");
8141 if (p->u.conc.v_speed == 0) {
8142 dgap_err("concentrator line speed not specified");
8145 if (p->u.conc.v_nport == 0) {
8146 dgap_err("number of ports on concentrator not specified");
8149 if (p->u.conc.v_id == 0) {
8150 dgap_err("concentrator id letter not specified");
8156 if (p->u.module.v_type == 0) {
8157 dgap_err("EBI module type not specified");
8160 if (p->u.module.v_nport == 0) {
8161 dgap_err("number of ports on EBI module not specified");
8164 if (p->u.module.v_id == 0) {
8165 dgap_err("EBI module id letter not specified");
8174 * save a string somewhere
8176 static char *dgap_savestring(char *s)
8179 if ( (p = kmalloc(strlen(s) + 1, GFP_ATOMIC) ) != NULL) {
8187 * Given a board pointer, returns whether we should use interrupts or not.
8189 uint dgap_config_get_useintr(struct board_t *bd)
8191 struct cnode *p = NULL;
8196 for (p = bd->bd_config; p; p = p->next) {
8200 * check for pcxr types.
8202 return p->u.useintr;
8208 /* If not found, then don't turn on interrupts. */
8214 * Given a board pointer, returns whether we turn on altpin or not.
8216 uint dgap_config_get_altpin(struct board_t *bd)
8218 struct cnode *p = NULL;
8223 for (p = bd->bd_config; p; p = p->next) {
8227 * check for pcxr types.
8235 /* If not found, then don't turn on interrupts. */
8242 * Given a specific type of board, if found, detached link and
8243 * returns the first occurrence in the list.
8245 struct cnode *dgap_find_config(int type, int bus, int slot)
8247 struct cnode *p, *prev = NULL, *prev2 = NULL, *found = NULL;
8251 while (p->next != NULL) {
8255 if (p->type == BNODE) {
8257 if (p->u.board.type == type) {
8259 if (p->u.board.v_pcibus && p->u.board.pcibus != bus) {
8260 DPR(("Found matching board, but wrong bus position. System says bus %d, we want bus %ld\n",
8261 bus, p->u.board.pcibus));
8264 if (p->u.board.v_pcislot && p->u.board.pcislot != slot) {
8265 DPR_INIT(("Found matching board, but wrong slot position. System says slot %d, we want slot %ld\n",
8266 slot, p->u.board.pcislot));
8270 DPR_INIT(("Matched type in config file\n"));
8274 * Keep walking thru the list till we find the next board.
8276 while (p->next != NULL) {
8279 if (p->type == BNODE) {
8282 * Mark the end of our 1 board chain of configs.
8287 * Link the "next" board to the previous board,
8288 * effectively "unlinking" our board from the main config.
8296 * It must be the last board in the list.
8307 * Given a board pointer, walks the config link, counting up
8308 * all ports user specified should be on the board.
8309 * (This does NOT mean they are all actually present right now tho)
8311 uint dgap_config_get_number_of_ports(struct board_t *bd)
8314 struct cnode *p = NULL;
8319 for (p = bd->bd_config; p; p = p->next) {
8324 * check for pcxr types.
8326 if (p->u.board.type > EPCFE)
8327 count += p->u.board.nport;
8330 count += p->u.conc.nport;
8333 count += p->u.module.nport;
8340 char *dgap_create_config_string(struct board_t *bd, char *string)
8343 struct cnode *p = NULL;
8344 struct cnode *q = NULL;
8352 for (p = bd->bd_config; p; p = p->next) {
8358 *ptr = p->u.line.speed;
8363 * Because the EPC/con concentrators can have EM modules
8364 * hanging off of them, we have to walk ahead in the list
8365 * and keep adding the number of ports on each EM to the config.
8368 speed = p->u.conc.speed;
8370 if ((q != NULL) && (q->type == MNODE) ) {
8371 *ptr = (p->u.conc.nport + 0x80);
8374 while ((q->next != NULL) && (q->next->type) == MNODE) {
8375 *ptr = (q->u.module.nport + 0x80);
8380 *ptr = q->u.module.nport;
8383 *ptr = p->u.conc.nport;
8399 char *dgap_get_config_letters(struct board_t *bd, char *string)
8403 struct cnode *cptr = NULL;
8405 int left = MAXTTYNAMELEN;
8411 for (cptr = bd->bd_config; cptr; cptr = cptr->next) {
8413 if ((cptr->type == BNODE) &&
8414 ((cptr->u.board.type == APORT2_920P) || (cptr->u.board.type == APORT4_920P) ||
8415 (cptr->u.board.type == APORT8_920P) || (cptr->u.board.type == PAPORT4) ||
8416 (cptr->u.board.type == PAPORT8))) {
8421 if (cptr->type == TNODE && found == TRUE) {
8423 if (strstr(cptr->u.ttyname, "tty")) {
8424 ptr1 = cptr->u.ttyname;
8428 ptr1 = cptr->u.ttyname;
8431 len = snprintf(ptr, left, "%s", ptr1);
8439 if (cptr->type == CNODE) {
8440 if (cptr->u.conc.id) {
8441 len = snprintf(ptr, left, "%s", cptr->u.conc.id);
8449 if (cptr->type == MNODE) {
8450 if (cptr->u.module.id) {
8451 len = snprintf(ptr, left, "%s", cptr->u.module.id);