2 * Copyright 2003 Digi International (www.digi.com)
3 * Scott H Kilau <Scott_Kilau at digi dot com>
5 * This program is free software; you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published by
7 * the Free Software Foundation; either version 2, or (at your option)
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY, EXPRESS OR IMPLIED; without even the
12 * implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
13 * PURPOSE. See the GNU General Public License for more details.
15 * You should have received a copy of the GNU General Public License
16 * along with this program; if not, write to the Free Software
17 * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
20 * NOTE TO LINUX KERNEL HACKERS: DO NOT REFORMAT THIS CODE!
22 * This is shared code between Digi's CVS archive and the
23 * Linux Kernel sources.
24 * Changing the source just for reformatting needlessly breaks
25 * our CVS diff history.
27 * Send any bug fixes/changes to: Eng.Linux at digi dot com.
33 #include <linux/kernel.h>
34 #include <linux/module.h>
35 #include <linux/pci.h>
36 #include <linux/delay.h> /* For udelay */
37 #include <linux/slab.h>
38 #include <asm/uaccess.h> /* For copy_from_user/copy_to_user */
39 #include <linux/sched.h>
41 #include <linux/interrupt.h> /* For tasklet and interrupt structs/defines */
42 #include <linux/ctype.h>
43 #include <linux/tty.h>
44 #include <linux/tty_flip.h>
45 #include <linux/serial_reg.h>
46 #include <asm/io.h> /* For read[bwl]/write[bwl] */
48 #include <linux/string.h>
49 #include <linux/device.h>
50 #include <linux/kdev_t.h>
52 #include "dgap_driver.h"
53 #include "dgap_types.h"
55 #define init_MUTEX(sem) sema_init(sem, 1)
56 #define DECLARE_MUTEX(name) \
57 struct semaphore name = __SEMAPHORE_INITIALIZER(name, 1)
59 MODULE_LICENSE("GPL");
60 MODULE_AUTHOR("Digi International, http://www.digi.com");
61 MODULE_DESCRIPTION("Driver for the Digi International EPCA PCI based product line");
62 MODULE_SUPPORTED_DEVICE("dgap");
65 * insmod command line overrideable parameters
67 * NOTE: we use a set of macros to create the variables, which allows
68 * us to specify the variable type, name, initial value, and description.
70 PARM_INT(debug, 0x00, 0644, "Driver debugging level");
71 PARM_INT(rawreadok, 1, 0644, "Bypass flip buffers on input");
72 PARM_INT(trcbuf_size, 0x100000, 0644, "Debugging trace buffer size.");
75 /**************************************************************************
77 * protos for this file
81 static int dgap_start(void);
82 static void dgap_init_globals(void);
83 static int dgap_found_board(struct pci_dev *pdev, int id);
84 static void dgap_cleanup_board(struct board_t *brd);
85 static void dgap_poll_handler(ulong dummy);
86 static int dgap_init_pci(void);
87 static int dgap_init_one(struct pci_dev *pdev, const struct pci_device_id *ent);
88 static void dgap_remove_one(struct pci_dev *dev);
89 static int dgap_probe1(struct pci_dev *pdev, int card_type);
90 static void dgap_mbuf(struct board_t *brd, const char *fmt, ...);
91 static int dgap_do_remap(struct board_t *brd);
92 static irqreturn_t dgap_intr(int irq, void *voidbrd);
94 /* Our function prototypes */
95 static int dgap_tty_open(struct tty_struct *tty, struct file *file);
96 static void dgap_tty_close(struct tty_struct *tty, struct file *file);
97 static int dgap_block_til_ready(struct tty_struct *tty, struct file *file, struct channel_t *ch);
98 static int dgap_tty_ioctl(struct tty_struct *tty, unsigned int cmd, unsigned long arg);
99 static int dgap_tty_digigeta(struct tty_struct *tty, struct digi_t __user *retinfo);
100 static int dgap_tty_digiseta(struct tty_struct *tty, struct digi_t __user *new_info);
101 static int dgap_tty_digigetedelay(struct tty_struct *tty, int __user *retinfo);
102 static int dgap_tty_digisetedelay(struct tty_struct *tty, int __user *new_info);
103 static int dgap_tty_write_room(struct tty_struct* tty);
104 static int dgap_tty_chars_in_buffer(struct tty_struct* tty);
105 static void dgap_tty_start(struct tty_struct *tty);
106 static void dgap_tty_stop(struct tty_struct *tty);
107 static void dgap_tty_throttle(struct tty_struct *tty);
108 static void dgap_tty_unthrottle(struct tty_struct *tty);
109 static void dgap_tty_flush_chars(struct tty_struct *tty);
110 static void dgap_tty_flush_buffer(struct tty_struct *tty);
111 static void dgap_tty_hangup(struct tty_struct *tty);
112 static int dgap_wait_for_drain(struct tty_struct *tty);
113 static int dgap_set_modem_info(struct tty_struct *tty, unsigned int command, unsigned int __user *value);
114 static int dgap_get_modem_info(struct channel_t *ch, unsigned int __user *value);
115 static int dgap_tty_digisetcustombaud(struct tty_struct *tty, int __user *new_info);
116 static int dgap_tty_digigetcustombaud(struct tty_struct *tty, int __user *retinfo);
117 static int dgap_tty_tiocmget(struct tty_struct *tty);
118 static int dgap_tty_tiocmset(struct tty_struct *tty, unsigned int set, unsigned int clear);
119 static int dgap_tty_send_break(struct tty_struct *tty, int msec);
120 static void dgap_tty_wait_until_sent(struct tty_struct *tty, int timeout);
121 static int dgap_tty_write(struct tty_struct *tty, const unsigned char *buf, int count);
122 static void dgap_tty_set_termios(struct tty_struct *tty, struct ktermios *old_termios);
123 static int dgap_tty_put_char(struct tty_struct *tty, unsigned char c);
124 static void dgap_tty_send_xchar(struct tty_struct *tty, char ch);
126 int dgap_tty_register(struct board_t *brd);
127 int dgap_tty_preinit(void);
128 int dgap_tty_init(struct board_t *);
129 void dgap_tty_post_uninit(void);
130 void dgap_tty_uninit(struct board_t *);
131 void dgap_carrier(struct channel_t *ch);
132 void dgap_input(struct channel_t *ch);
135 * Our function prototypes from dgap_fep5
137 static void dgap_cmdw_ext(struct channel_t *ch, u16 cmd, u16 word, uint ncmds);
138 static int dgap_event(struct board_t *bd);
141 * Function prototypes from dgap_parse.c.
143 static int dgap_gettok(char **in, struct cnode *p);
144 static char *dgap_getword(char **in);
145 static char *dgap_savestring(char *s);
146 static struct cnode *dgap_newnode(int t);
147 static int dgap_checknode(struct cnode *p);
148 static void dgap_err(char *s);
151 * Function prototypes from dgap_sysfs.h
159 void dgap_create_ports_sysfiles(struct board_t *bd);
160 void dgap_remove_ports_sysfiles(struct board_t *bd);
162 void dgap_create_driver_sysfiles(struct pci_driver *);
163 void dgap_remove_driver_sysfiles(struct pci_driver *);
165 int dgap_tty_class_init(void);
166 int dgap_tty_class_destroy(void);
168 void dgap_create_tty_sysfs(struct un_t *un, struct device *c);
169 void dgap_remove_tty_sysfs(struct device *c);
172 * Function prototypes from dgap_parse.h
174 int dgap_parsefile(char **in, int Remove);
175 struct cnode *dgap_find_config(int type, int bus, int slot);
176 uint dgap_config_get_number_of_ports(struct board_t *bd);
177 char *dgap_create_config_string(struct board_t *bd, char *string);
178 char *dgap_get_config_letters(struct board_t *bd, char *string);
179 uint dgap_config_get_useintr(struct board_t *bd);
180 uint dgap_config_get_altpin(struct board_t *bd);
182 /* Driver load/unload functions */
183 int dgap_init_module(void);
184 void dgap_cleanup_module(void);
186 module_init(dgap_init_module);
187 module_exit(dgap_cleanup_module);
191 * File operations permitted on Control/Management major.
193 static struct file_operations DgapBoardFops =
195 .owner = THIS_MODULE,
203 struct board_t *dgap_Board[MAXBOARDS];
204 DEFINE_SPINLOCK(dgap_global_lock);
205 ulong dgap_poll_counter;
206 char *dgap_config_buf;
207 int dgap_driver_state = DRIVER_INITIALIZED;
208 DEFINE_SPINLOCK(dgap_dl_lock);
209 wait_queue_head_t dgap_dl_wait;
211 int dgap_poll_tick = 20; /* Poll interval - 20 ms */
216 static int dgap_Major_Control_Registered = FALSE;
217 static uint dgap_driver_start = FALSE;
219 static struct class * dgap_class;
221 static struct board_t *dgap_BoardsByMajor[256];
222 static uchar *dgap_TmpWriteBuf = NULL;
223 static DECLARE_MUTEX(dgap_TmpWriteSem);
224 static uint dgap_count = 500;
229 static DEFINE_SPINLOCK(dgap_poll_lock); /* Poll scheduling lock */
230 static ulong dgap_poll_time; /* Time of next poll */
231 static uint dgap_poll_stop; /* Used to tell poller to stop */
232 static struct timer_list dgap_poll_timer;
235 static struct pci_device_id dgap_pci_tbl[] = {
236 { DIGI_VID, PCI_DEVICE_XEM_DID, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0 },
237 { DIGI_VID, PCI_DEVICE_CX_DID, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 1 },
238 { DIGI_VID, PCI_DEVICE_CX_IBM_DID, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 2 },
239 { DIGI_VID, PCI_DEVICE_EPCJ_DID, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 3 },
240 { DIGI_VID, PCI_DEVICE_920_2_DID, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 4 },
241 { DIGI_VID, PCI_DEVICE_920_4_DID, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 5 },
242 { DIGI_VID, PCI_DEVICE_920_8_DID, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 6 },
243 { DIGI_VID, PCI_DEVICE_XR_DID, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 7 },
244 { DIGI_VID, PCI_DEVICE_XRJ_DID, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 8 },
245 { DIGI_VID, PCI_DEVICE_XR_422_DID, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 9 },
246 { DIGI_VID, PCI_DEVICE_XR_IBM_DID, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 10 },
247 { DIGI_VID, PCI_DEVICE_XR_SAIP_DID, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 11 },
248 { DIGI_VID, PCI_DEVICE_XR_BULL_DID, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 12 },
249 { DIGI_VID, PCI_DEVICE_920_8_HP_DID, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 13 },
250 { DIGI_VID, PCI_DEVICE_XEM_HP_DID, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 14 },
251 {0,} /* 0 terminated list. */
253 MODULE_DEVICE_TABLE(pci, dgap_pci_tbl);
257 * A generic list of Product names, PCI Vendor ID, and PCI Device ID.
266 static struct board_id dgap_Ids[] =
268 { PPCM, PCI_DEVICE_XEM_NAME, 64, (T_PCXM | T_PCLITE | T_PCIBUS) },
269 { PCX, PCI_DEVICE_CX_NAME, 128, (T_CX | T_PCIBUS) },
270 { PCX, PCI_DEVICE_CX_IBM_NAME, 128, (T_CX | T_PCIBUS) },
271 { PEPC, PCI_DEVICE_EPCJ_NAME, 224, (T_EPC | T_PCIBUS) },
272 { APORT2_920P, PCI_DEVICE_920_2_NAME, 2, (T_PCXR | T_PCLITE | T_PCIBUS) },
273 { APORT4_920P, PCI_DEVICE_920_4_NAME, 4, (T_PCXR | T_PCLITE | T_PCIBUS) },
274 { APORT8_920P, PCI_DEVICE_920_8_NAME, 8, (T_PCXR | T_PCLITE | T_PCIBUS) },
275 { PAPORT8, PCI_DEVICE_XR_NAME, 8, (T_PCXR | T_PCLITE | T_PCIBUS) },
276 { PAPORT8, PCI_DEVICE_XRJ_NAME, 8, (T_PCXR | T_PCLITE | T_PCIBUS) },
277 { PAPORT8, PCI_DEVICE_XR_422_NAME, 8, (T_PCXR | T_PCLITE | T_PCIBUS) },
278 { PAPORT8, PCI_DEVICE_XR_IBM_NAME, 8, (T_PCXR | T_PCLITE | T_PCIBUS) },
279 { PAPORT8, PCI_DEVICE_XR_SAIP_NAME, 8, (T_PCXR | T_PCLITE | T_PCIBUS) },
280 { PAPORT8, PCI_DEVICE_XR_BULL_NAME, 8, (T_PCXR | T_PCLITE | T_PCIBUS) },
281 { APORT8_920P, PCI_DEVICE_920_8_HP_NAME, 8, (T_PCXR | T_PCLITE | T_PCIBUS) },
282 { PPCM, PCI_DEVICE_XEM_HP_NAME, 64, (T_PCXM | T_PCLITE | T_PCIBUS) },
283 {0,} /* 0 terminated list. */
286 static struct pci_driver dgap_driver = {
288 .probe = dgap_init_one,
289 .id_table = dgap_pci_tbl,
290 .remove = dgap_remove_one,
294 char *dgap_state_text[] = {
296 "Configuration for board not found.\n\t\t\tRun mpi to configure board.",
302 "Need Device Creation",
303 "Requested Device Creation",
304 "Finished Device Creation",
308 "Finished BIOS Load",
313 "Requested PROC creation",
314 "Finished PROC creation",
318 char *dgap_driver_state_text[] = {
319 "Driver Initialized",
320 "Driver needs configuration load.",
321 "Driver requested configuration from download daemon.",
326 * Default transparent print information.
328 static struct digi_t dgap_digi_init = {
329 .digi_flags = DIGI_COOK, /* Flags */
330 .digi_maxcps = 100, /* Max CPS */
331 .digi_maxchar = 50, /* Max chars in print queue */
332 .digi_bufsize = 100, /* Printer buffer size */
333 .digi_onlen = 4, /* size of printer on string */
334 .digi_offlen = 4, /* size of printer off string */
335 .digi_onstr = "\033[5i", /* ANSI printer on string ] */
336 .digi_offstr = "\033[4i", /* ANSI printer off string ] */
337 .digi_term = "ansi" /* default terminal type */
342 * Define a local default termios struct. All ports will be created
343 * with this termios initially.
345 * This defines a raw port at 9600 baud, 8 data bits, no parity,
349 static struct ktermios DgapDefaultTermios =
351 .c_iflag = (DEFAULT_IFLAGS), /* iflags */
352 .c_oflag = (DEFAULT_OFLAGS), /* oflags */
353 .c_cflag = (DEFAULT_CFLAGS), /* cflags */
354 .c_lflag = (DEFAULT_LFLAGS), /* lflags */
359 static const struct tty_operations dgap_tty_ops = {
360 .open = dgap_tty_open,
361 .close = dgap_tty_close,
362 .write = dgap_tty_write,
363 .write_room = dgap_tty_write_room,
364 .flush_buffer = dgap_tty_flush_buffer,
365 .chars_in_buffer = dgap_tty_chars_in_buffer,
366 .flush_chars = dgap_tty_flush_chars,
367 .ioctl = dgap_tty_ioctl,
368 .set_termios = dgap_tty_set_termios,
369 .stop = dgap_tty_stop,
370 .start = dgap_tty_start,
371 .throttle = dgap_tty_throttle,
372 .unthrottle = dgap_tty_unthrottle,
373 .hangup = dgap_tty_hangup,
374 .put_char = dgap_tty_put_char,
375 .tiocmget = dgap_tty_tiocmget,
376 .tiocmset = dgap_tty_tiocmset,
377 .break_ctl = dgap_tty_send_break,
378 .wait_until_sent = dgap_tty_wait_until_sent,
379 .send_xchar = dgap_tty_send_xchar
383 * Our needed internal static variables from dgap_parse.c
385 static struct cnode dgap_head;
387 static char dgap_cword[MAXCWORD];
394 static struct toklist dgap_tlist[] = {
395 { BEGIN, "config_begin" },
396 { END, "config_end" },
398 { PCX, "Digi_AccelePort_C/X_PCI" }, /* C/X_PCI */
399 { PEPC, "Digi_AccelePort_EPC/X_PCI" }, /* EPC/X_PCI */
400 { PPCM, "Digi_AccelePort_Xem_PCI" }, /* PCI/Xem */
401 { APORT2_920P, "Digi_AccelePort_2r_920_PCI" },
402 { APORT4_920P, "Digi_AccelePort_4r_920_PCI" },
403 { APORT8_920P, "Digi_AccelePort_8r_920_PCI" },
404 { PAPORT4, "Digi_AccelePort_4r_PCI(EIA-232/RS-422)" },
405 { PAPORT8, "Digi_AccelePort_8r_PCI(EIA-232/RS-422)" },
407 { PCIINFO, "pciinfo" },
410 { CONC, "concentrator" },
420 { CONNECT, "connect" },
421 { METHOD, "method" },
422 { STATUS, "status" },
423 { CUSTOM, "Custom" },
429 { NPORTS, "nports" },
434 { ALTPIN, "altpin" },
435 { USEINTR, "useintr" },
436 { TTSIZ, "ttysize" },
438 { BSSIZ, "boardsize" },
439 { UNTSIZ, "schedsize" },
440 { F2SIZ, "f2200size" },
441 { VPSIZ, "vpixsize" },
445 /************************************************************************
447 * Driver load/unload functions
449 ************************************************************************/
454 * Module load. This is where it all starts.
456 int dgap_init_module(void)
460 APR(("%s, Digi International Part Number %s\n", DG_NAME, DG_PART));
463 * Initialize global stuff
472 * Find and configure all the cards
474 rc = dgap_init_pci();
477 * If something went wrong in the scan, bail out of driver.
480 /* Only unregister the pci driver if it was actually registered. */
482 pci_unregister_driver(&dgap_driver);
484 printk("WARNING: dgap driver load failed. No DGAP boards found.\n");
486 dgap_cleanup_module();
489 dgap_create_driver_sysfiles(&dgap_driver);
492 DPR_INIT(("Finished init_module. Returning %d\n", rc));
500 static int dgap_start(void)
505 if (dgap_driver_start == FALSE) {
507 dgap_driver_start = TRUE;
509 /* make sure that the globals are init'd before we do anything else */
514 APR(("For the tools package or updated drivers please visit http://www.digi.com\n"));
517 * Register our base character device into the kernel.
518 * This allows the download daemon to connect to the downld device
519 * before any of the boards are init'ed.
521 if (!dgap_Major_Control_Registered) {
523 * Register management/dpa devices
525 rc = register_chrdev(DIGI_DGAP_MAJOR, "dgap", &DgapBoardFops);
527 APR(("Can't register dgap driver device (%d)\n", rc));
531 dgap_class = class_create(THIS_MODULE, "dgap_mgmt");
532 device_create(dgap_class, NULL,
533 MKDEV(DIGI_DGAP_MAJOR, 0),
535 device_create(dgap_class, NULL,
536 MKDEV(DIGI_DGAP_MAJOR, 1),
537 NULL, "dgap_downld");
538 dgap_Major_Control_Registered = TRUE;
542 * Init any global tty stuff.
544 rc = dgap_tty_preinit();
547 APR(("tty preinit - not enough memory (%d)\n", rc));
551 /* Start the poller */
552 DGAP_LOCK(dgap_poll_lock, flags);
553 init_timer(&dgap_poll_timer);
554 dgap_poll_timer.function = dgap_poll_handler;
555 dgap_poll_timer.data = 0;
556 dgap_poll_time = jiffies + dgap_jiffies_from_ms(dgap_poll_tick);
557 dgap_poll_timer.expires = dgap_poll_time;
558 DGAP_UNLOCK(dgap_poll_lock, flags);
560 add_timer(&dgap_poll_timer);
562 dgap_driver_state = DRIVER_NEED_CONFIG_LOAD;
570 * Register pci driver, and return how many boards we have.
572 static int dgap_init_pci(void)
574 return pci_register_driver(&dgap_driver);
578 /* returns count (>= 0), or negative on error */
579 static int dgap_init_one(struct pci_dev *pdev, const struct pci_device_id *ent)
583 /* wake up and enable device */
584 rc = pci_enable_device(pdev);
589 rc = dgap_probe1(pdev, ent->driver_data);
592 DPR_INIT(("Incrementing numboards to %d\n", dgap_NumBoards));
599 static int dgap_probe1(struct pci_dev *pdev, int card_type)
601 return dgap_found_board(pdev, card_type);
605 static void dgap_remove_one(struct pci_dev *dev)
612 * dgap_cleanup_module()
614 * Module unload. This is where it all ends.
616 void dgap_cleanup_module(void)
621 DGAP_LOCK(dgap_poll_lock, lock_flags);
623 DGAP_UNLOCK(dgap_poll_lock, lock_flags);
625 /* Turn off poller right away. */
626 del_timer_sync( &dgap_poll_timer);
628 dgap_remove_driver_sysfiles(&dgap_driver);
631 if (dgap_Major_Control_Registered) {
632 device_destroy(dgap_class, MKDEV(DIGI_DGAP_MAJOR, 0));
633 device_destroy(dgap_class, MKDEV(DIGI_DGAP_MAJOR, 1));
634 class_destroy(dgap_class);
635 unregister_chrdev(DIGI_DGAP_MAJOR, "dgap");
638 kfree(dgap_config_buf);
640 for (i = 0; i < dgap_NumBoards; ++i) {
641 dgap_remove_ports_sysfiles(dgap_Board[i]);
642 dgap_tty_uninit(dgap_Board[i]);
643 dgap_cleanup_board(dgap_Board[i]);
646 dgap_tty_post_uninit();
648 #if defined(DGAP_TRACER)
649 /* last thing, make sure we release the tracebuffer */
653 pci_unregister_driver(&dgap_driver);
658 * dgap_cleanup_board()
660 * Free all the memory associated with a board
662 static void dgap_cleanup_board(struct board_t *brd)
666 if(!brd || brd->magic != DGAP_BOARD_MAGIC)
669 if (brd->intr_used && brd->irq)
670 free_irq(brd->irq, brd);
672 tasklet_kill(&brd->helper_tasklet);
674 if (brd->re_map_port) {
675 release_mem_region(brd->membase + 0x200000, 0x200000);
676 iounmap(brd->re_map_port);
677 brd->re_map_port = NULL;
680 if (brd->re_map_membase) {
681 release_mem_region(brd->membase, 0x200000);
682 iounmap(brd->re_map_membase);
683 brd->re_map_membase = NULL;
686 if (brd->msgbuf_head) {
689 DGAP_LOCK(dgap_global_lock, flags);
691 printk("%s", brd->msgbuf_head);
692 kfree(brd->msgbuf_head);
693 brd->msgbuf_head = NULL;
694 DGAP_UNLOCK(dgap_global_lock, flags);
697 /* Free all allocated channels structs */
698 for (i = 0; i < MAXPORTS ; i++) {
699 if (brd->channels[i]) {
700 kfree(brd->channels[i]);
701 brd->channels[i] = NULL;
706 kfree(brd->flipflagbuf);
708 dgap_Board[brd->boardnum] = NULL;
717 * A board has been found, init it.
719 static int dgap_found_board(struct pci_dev *pdev, int id)
722 unsigned int pci_irq;
726 /* get the board structure and prep it */
727 brd = dgap_Board[dgap_NumBoards] =
728 (struct board_t *) kzalloc(sizeof(struct board_t), GFP_KERNEL);
730 APR(("memory allocation for board structure failed\n"));
734 /* make a temporary message buffer for the boot messages */
735 brd->msgbuf = brd->msgbuf_head =
736 (char *) kzalloc(sizeof(char) * 8192, GFP_KERNEL);
739 APR(("memory allocation for board msgbuf failed\n"));
743 /* store the info for the board we've found */
744 brd->magic = DGAP_BOARD_MAGIC;
745 brd->boardnum = dgap_NumBoards;
747 brd->vendor = dgap_pci_tbl[id].vendor;
748 brd->device = dgap_pci_tbl[id].device;
750 brd->pci_bus = pdev->bus->number;
751 brd->pci_slot = PCI_SLOT(pdev->devfn);
752 brd->name = dgap_Ids[id].name;
753 brd->maxports = dgap_Ids[id].maxports;
754 brd->type = dgap_Ids[id].config_type;
755 brd->dpatype = dgap_Ids[id].dpatype;
756 brd->dpastatus = BD_NOFEP;
757 init_waitqueue_head(&brd->state_wait);
759 DGAP_SPINLOCK_INIT(brd->bd_lock);
761 brd->state = BOARD_FOUND;
763 brd->inhibit_poller = FALSE;
764 brd->wait_for_bios = 0;
765 brd->wait_for_fep = 0;
767 for (i = 0; i < MAXPORTS; i++) {
768 brd->channels[i] = NULL;
771 /* store which card & revision we have */
772 pci_read_config_word(pdev, PCI_SUBSYSTEM_VENDOR_ID, &brd->subvendor);
773 pci_read_config_word(pdev, PCI_SUBSYSTEM_ID, &brd->subdevice);
774 pci_read_config_byte(pdev, PCI_REVISION_ID, &brd->rev);
779 /* get the PCI Base Address Registers */
781 /* Xr Jupiter and EPC use BAR 2 */
782 if (brd->device == PCI_DEVICE_XRJ_DID || brd->device == PCI_DEVICE_EPCJ_DID) {
783 brd->membase = pci_resource_start(pdev, 2);
784 brd->membase_end = pci_resource_end(pdev, 2);
786 /* Everyone else uses BAR 0 */
788 brd->membase = pci_resource_start(pdev, 0);
789 brd->membase_end = pci_resource_end(pdev, 0);
793 APR(("card has no PCI IO resources, failing board.\n"));
797 if (brd->membase & 1)
803 * On the PCI boards, there is no IO space allocated
804 * The I/O registers will be in the first 3 bytes of the
805 * upper 2MB of the 4MB memory space. The board memory
806 * will be mapped into the low 2MB of the 4MB memory space
808 brd->port = brd->membase + PCI_IO_OFFSET;
809 brd->port_end = brd->port + PCI_IO_SIZE;
813 * Special initialization for non-PLX boards
815 if (brd->device != PCI_DEVICE_XRJ_DID && brd->device != PCI_DEVICE_EPCJ_DID) {
818 pci_write_config_byte(pdev, 0x40, 0);
819 pci_write_config_byte(pdev, 0x46, 0);
821 /* Limit burst length to 2 doubleword transactions */
822 pci_write_config_byte(pdev, 0x42, 1);
825 * Enable IO and mem if not already done.
826 * This was needed for support on Itanium.
828 pci_read_config_word(pdev, PCI_COMMAND, &cmd);
829 cmd |= (PCI_COMMAND_IO | PCI_COMMAND_MEMORY);
830 pci_write_config_word(pdev, PCI_COMMAND, cmd);
833 /* init our poll helper tasklet */
834 tasklet_init(&brd->helper_tasklet, dgap_poll_tasklet, (unsigned long) brd);
836 /* Log the information about the board */
837 dgap_mbuf(brd, DRVSTR": board %d: %s (rev %d), irq %d\n",
838 dgap_NumBoards, brd->name, brd->rev, brd->irq);
840 DPR_INIT(("dgap_scan(%d) - printing out the msgbuf\n", i));
841 DGAP_LOCK(dgap_global_lock, flags);
843 printk("%s", brd->msgbuf_head);
844 kfree(brd->msgbuf_head);
845 brd->msgbuf_head = NULL;
846 DGAP_UNLOCK(dgap_global_lock, flags);
848 i = dgap_do_remap(brd);
850 brd->state = BOARD_FAILED;
852 brd->state = NEED_RESET;
858 int dgap_finalize_board_init(struct board_t *brd) {
862 DPR_INIT(("dgap_finalize_board_init() - start\n"));
864 if (!brd || brd->magic != DGAP_BOARD_MAGIC)
867 DPR_INIT(("dgap_finalize_board_init() - start #2\n"));
869 brd->use_interrupts = dgap_config_get_useintr(brd);
872 * Set up our interrupt handler if we are set to do interrupts.
874 if (brd->use_interrupts && brd->irq) {
876 rc = request_irq(brd->irq, dgap_intr, IRQF_SHARED, "DGAP", brd);
879 dgap_mbuf(brd, DRVSTR": Failed to hook IRQ %d. Board will work in poll mode.\n",
896 static int dgap_do_remap(struct board_t *brd)
898 if (!brd || brd->magic != DGAP_BOARD_MAGIC)
901 if (!request_mem_region(brd->membase, 0x200000, "dgap")) {
902 APR(("dgap: mem_region %lx already in use.\n", brd->membase));
906 if (!request_mem_region(brd->membase + PCI_IO_OFFSET, 0x200000, "dgap")) {
907 APR(("dgap: mem_region IO %lx already in use.\n",
908 brd->membase + PCI_IO_OFFSET));
909 release_mem_region(brd->membase, 0x200000);
913 brd->re_map_membase = ioremap(brd->membase, 0x200000);
914 if (!brd->re_map_membase) {
915 APR(("dgap: ioremap mem %lx cannot be mapped.\n", brd->membase));
916 release_mem_region(brd->membase, 0x200000);
917 release_mem_region(brd->membase + PCI_IO_OFFSET, 0x200000);
921 brd->re_map_port = ioremap((brd->membase + PCI_IO_OFFSET), 0x200000);
922 if (!brd->re_map_port) {
923 release_mem_region(brd->membase, 0x200000);
924 release_mem_region(brd->membase + PCI_IO_OFFSET, 0x200000);
925 iounmap(brd->re_map_membase);
926 APR(("dgap: ioremap IO mem %lx cannot be mapped.\n",
927 brd->membase + PCI_IO_OFFSET));
931 DPR_INIT(("remapped io: 0x%p remapped mem: 0x%p\n",
932 brd->re_map_port, brd->re_map_membase));
937 /*****************************************************************************
957 * As each timer expires, it determines (a) whether the "transmit"
958 * waiter needs to be woken up, and (b) whether the poller needs to
961 ******************************************************************************/
963 static void dgap_poll_handler(ulong dummy)
967 unsigned long lock_flags;
968 unsigned long lock_flags2;
975 * If driver needs the config file still,
976 * keep trying to wake up the downloader to
979 if (dgap_driver_state == DRIVER_NEED_CONFIG_LOAD) {
981 * Signal downloader, its got some work to do.
983 DGAP_LOCK(dgap_dl_lock, lock_flags2);
984 if (dgap_dl_action != 1) {
986 wake_up_interruptible(&dgap_dl_wait);
988 DGAP_UNLOCK(dgap_dl_lock, lock_flags2);
989 goto schedule_poller;
992 * Do not start the board state machine until
993 * driver tells us its up and running, and has
994 * everything it needs.
996 else if (dgap_driver_state != DRIVER_READY) {
997 goto schedule_poller;
1001 * If we have just 1 board, or the system is not SMP,
1002 * then use the typical old style poller.
1003 * Otherwise, use our new tasklet based poller, which should
1004 * speed things up for multiple boards.
1006 if ( (dgap_NumBoards == 1) || (num_online_cpus() <= 1) ) {
1007 for (i = 0; i < dgap_NumBoards; i++) {
1009 brd = dgap_Board[i];
1011 if (brd->state == BOARD_FAILED) {
1014 if (!brd->intr_running) {
1015 /* Call the real board poller directly */
1016 dgap_poll_tasklet((unsigned long) brd);
1021 /* Go thru each board, kicking off a tasklet for each if needed */
1022 for (i = 0; i < dgap_NumBoards; i++) {
1023 brd = dgap_Board[i];
1026 * Attempt to grab the board lock.
1028 * If we can't get it, no big deal, the next poll will get it.
1029 * Basically, I just really don't want to spin in here, because I want
1030 * to kick off my tasklets as fast as I can, and then get out the poller.
1032 if (!spin_trylock(&brd->bd_lock)) {
1036 /* If board is in a failed state, don't bother scheduling a tasklet */
1037 if (brd->state == BOARD_FAILED) {
1038 spin_unlock(&brd->bd_lock);
1042 /* Schedule a poll helper task */
1043 if (!brd->intr_running) {
1044 tasklet_schedule(&brd->helper_tasklet);
1048 * Can't do DGAP_UNLOCK here, as we don't have
1049 * lock_flags because we did a trylock above.
1051 spin_unlock(&brd->bd_lock);
1058 * Schedule ourself back at the nominal wakeup interval.
1060 DGAP_LOCK(dgap_poll_lock, lock_flags );
1061 dgap_poll_time += dgap_jiffies_from_ms(dgap_poll_tick);
1063 new_time = dgap_poll_time - jiffies;
1065 if ((ulong) new_time >= 2 * dgap_poll_tick) {
1066 dgap_poll_time = jiffies + dgap_jiffies_from_ms(dgap_poll_tick);
1069 dgap_poll_timer.function = dgap_poll_handler;
1070 dgap_poll_timer.data = 0;
1071 dgap_poll_timer.expires = dgap_poll_time;
1072 DGAP_UNLOCK(dgap_poll_lock, lock_flags );
1074 if (!dgap_poll_stop)
1075 add_timer(&dgap_poll_timer);
1084 * Driver interrupt handler.
1086 static irqreturn_t dgap_intr(int irq, void *voidbrd)
1088 struct board_t *brd = (struct board_t *) voidbrd;
1091 APR(("Received interrupt (%d) with null board associated\n", irq));
1096 * Check to make sure its for us.
1098 if (brd->magic != DGAP_BOARD_MAGIC) {
1099 APR(("Received interrupt (%d) with a board pointer that wasn't ours!\n", irq));
1106 * Schedule tasklet to run at a better time.
1108 tasklet_schedule(&brd->helper_tasklet);
1114 * dgap_init_globals()
1116 * This is where we initialize the globals from the static insmod
1117 * configuration variables. These are declared near the head of
1120 static void dgap_init_globals(void)
1124 dgap_rawreadok = rawreadok;
1125 dgap_trcbuf_size = trcbuf_size;
1128 for (i = 0; i < MAXBOARDS; i++) {
1129 dgap_Board[i] = NULL;
1132 init_timer( &dgap_poll_timer );
1134 init_waitqueue_head(&dgap_dl_wait);
1139 /************************************************************************
1143 ************************************************************************/
1149 * Used to print to the message buffer during board init.
1151 static void dgap_mbuf(struct board_t *brd, const char *fmt, ...) {
1155 unsigned long flags;
1158 DGAP_LOCK(dgap_global_lock, flags);
1160 /* Format buf using fmt and arguments contained in ap. */
1162 i = vsnprintf(buf, sizeof(buf), fmt, ap);
1167 if (!brd || !brd->msgbuf) {
1169 DGAP_UNLOCK(dgap_global_lock, flags);
1173 length = strlen(buf) + 1;
1174 if (brd->msgbuf - brd->msgbuf_head < length)
1175 length = brd->msgbuf - brd->msgbuf_head;
1176 memcpy(brd->msgbuf, buf, length);
1177 brd->msgbuf += length;
1179 DGAP_UNLOCK(dgap_global_lock, flags);
1186 * Put the driver to sleep for x ms's
1188 * Returns 0 if timed out, !0 (showing signal) if interrupted by a signal.
1190 int dgap_ms_sleep(ulong ms)
1192 current->state = TASK_INTERRUPTIBLE;
1193 schedule_timeout((ms * HZ) / 1000);
1194 return (signal_pending(current));
1200 * dgap_ioctl_name() : Returns a text version of each ioctl value.
1202 char *dgap_ioctl_name(int cmd)
1206 case TCGETA: return("TCGETA");
1207 case TCGETS: return("TCGETS");
1208 case TCSETA: return("TCSETA");
1209 case TCSETS: return("TCSETS");
1210 case TCSETAW: return("TCSETAW");
1211 case TCSETSW: return("TCSETSW");
1212 case TCSETAF: return("TCSETAF");
1213 case TCSETSF: return("TCSETSF");
1214 case TCSBRK: return("TCSBRK");
1215 case TCXONC: return("TCXONC");
1216 case TCFLSH: return("TCFLSH");
1217 case TIOCGSID: return("TIOCGSID");
1219 case TIOCGETD: return("TIOCGETD");
1220 case TIOCSETD: return("TIOCSETD");
1221 case TIOCGWINSZ: return("TIOCGWINSZ");
1222 case TIOCSWINSZ: return("TIOCSWINSZ");
1224 case TIOCMGET: return("TIOCMGET");
1225 case TIOCMSET: return("TIOCMSET");
1226 case TIOCMBIS: return("TIOCMBIS");
1227 case TIOCMBIC: return("TIOCMBIC");
1230 case DIGI_SETA: return("DIGI_SETA");
1231 case DIGI_SETAW: return("DIGI_SETAW");
1232 case DIGI_SETAF: return("DIGI_SETAF");
1233 case DIGI_SETFLOW: return("DIGI_SETFLOW");
1234 case DIGI_SETAFLOW: return("DIGI_SETAFLOW");
1235 case DIGI_GETFLOW: return("DIGI_GETFLOW");
1236 case DIGI_GETAFLOW: return("DIGI_GETAFLOW");
1237 case DIGI_GETA: return("DIGI_GETA");
1238 case DIGI_GEDELAY: return("DIGI_GEDELAY");
1239 case DIGI_SEDELAY: return("DIGI_SEDELAY");
1240 case DIGI_GETCUSTOMBAUD: return("DIGI_GETCUSTOMBAUD");
1241 case DIGI_SETCUSTOMBAUD: return("DIGI_SETCUSTOMBAUD");
1242 case TIOCMODG: return("TIOCMODG");
1243 case TIOCMODS: return("TIOCMODS");
1244 case TIOCSDTR: return("TIOCSDTR");
1245 case TIOCCDTR: return("TIOCCDTR");
1247 default: return("unknown");
1251 /************************************************************************
1253 * TTY Initialization/Cleanup Functions
1255 ************************************************************************/
1258 * dgap_tty_preinit()
1260 * Initialize any global tty related data before we download any boards.
1262 int dgap_tty_preinit(void)
1264 unsigned long flags;
1266 DGAP_LOCK(dgap_global_lock, flags);
1269 * Allocate a buffer for doing the copy from user space to
1270 * kernel space in dgap_input(). We only use one buffer and
1271 * control access to it with a semaphore. If we are paging, we
1272 * are already in trouble so one buffer won't hurt much anyway.
1274 dgap_TmpWriteBuf = kmalloc(WRITEBUFLEN, GFP_ATOMIC);
1276 if (!dgap_TmpWriteBuf) {
1277 DGAP_UNLOCK(dgap_global_lock, flags);
1278 DPR_INIT(("unable to allocate tmp write buf"));
1282 DGAP_UNLOCK(dgap_global_lock, flags);
1288 * dgap_tty_register()
1290 * Init the tty subsystem for this board.
1292 int dgap_tty_register(struct board_t *brd)
1296 DPR_INIT(("tty_register start"));
1298 brd->SerialDriver = alloc_tty_driver(MAXPORTS);
1300 snprintf(brd->SerialName, MAXTTYNAMELEN, "tty_dgap_%d_", brd->boardnum);
1301 brd->SerialDriver->name = brd->SerialName;
1302 brd->SerialDriver->name_base = 0;
1303 brd->SerialDriver->major = 0;
1304 brd->SerialDriver->minor_start = 0;
1305 brd->SerialDriver->type = TTY_DRIVER_TYPE_SERIAL;
1306 brd->SerialDriver->subtype = SERIAL_TYPE_NORMAL;
1307 brd->SerialDriver->init_termios = DgapDefaultTermios;
1308 brd->SerialDriver->driver_name = DRVSTR;
1309 brd->SerialDriver->flags = (TTY_DRIVER_REAL_RAW | TTY_DRIVER_DYNAMIC_DEV | TTY_DRIVER_HARDWARE_BREAK);
1311 /* The kernel wants space to store pointers to tty_structs */
1312 brd->SerialDriver->ttys = kzalloc(MAXPORTS * sizeof(struct tty_struct *), GFP_KERNEL);
1313 if (!brd->SerialDriver->ttys)
1317 * Entry points for driver. Called by the kernel from
1318 * tty_io.c and n_tty.c.
1320 tty_set_operations(brd->SerialDriver, &dgap_tty_ops);
1323 * If we're doing transparent print, we have to do all of the above
1324 * again, separately so we don't get the LD confused about what major
1325 * we are when we get into the dgap_tty_open() routine.
1327 brd->PrintDriver = alloc_tty_driver(MAXPORTS);
1329 snprintf(brd->PrintName, MAXTTYNAMELEN, "pr_dgap_%d_", brd->boardnum);
1330 brd->PrintDriver->name = brd->PrintName;
1331 brd->PrintDriver->name_base = 0;
1332 brd->PrintDriver->major = 0;
1333 brd->PrintDriver->minor_start = 0;
1334 brd->PrintDriver->type = TTY_DRIVER_TYPE_SERIAL;
1335 brd->PrintDriver->subtype = SERIAL_TYPE_NORMAL;
1336 brd->PrintDriver->init_termios = DgapDefaultTermios;
1337 brd->PrintDriver->driver_name = DRVSTR;
1338 brd->PrintDriver->flags = (TTY_DRIVER_REAL_RAW | TTY_DRIVER_DYNAMIC_DEV | TTY_DRIVER_HARDWARE_BREAK);
1340 /* The kernel wants space to store pointers to tty_structs */
1341 brd->PrintDriver->ttys = kzalloc(MAXPORTS * sizeof(struct tty_struct *), GFP_KERNEL);
1342 if (!brd->PrintDriver->ttys)
1346 * Entry points for driver. Called by the kernel from
1347 * tty_io.c and n_tty.c.
1349 tty_set_operations(brd->PrintDriver, &dgap_tty_ops);
1351 if (!brd->dgap_Major_Serial_Registered) {
1352 /* Register tty devices */
1353 rc = tty_register_driver(brd->SerialDriver);
1355 APR(("Can't register tty device (%d)\n", rc));
1358 brd->dgap_Major_Serial_Registered = TRUE;
1359 dgap_BoardsByMajor[brd->SerialDriver->major] = brd;
1360 brd->dgap_Serial_Major = brd->SerialDriver->major;
1363 if (!brd->dgap_Major_TransparentPrint_Registered) {
1364 /* Register Transparent Print devices */
1365 rc = tty_register_driver(brd->PrintDriver);
1367 APR(("Can't register Transparent Print device (%d)\n", rc));
1370 brd->dgap_Major_TransparentPrint_Registered = TRUE;
1371 dgap_BoardsByMajor[brd->PrintDriver->major] = brd;
1372 brd->dgap_TransparentPrint_Major = brd->PrintDriver->major;
1375 DPR_INIT(("DGAP REGISTER TTY: MAJORS: %d %d\n", brd->SerialDriver->major,
1376 brd->PrintDriver->major));
1385 * Init the tty subsystem. Called once per board after board has been
1386 * downloaded and init'ed.
1388 int dgap_tty_init(struct board_t *brd)
1392 uint true_count = 0;
1395 struct channel_t *ch;
1402 DPR_INIT(("dgap_tty_init start\n"));
1405 * Initialize board structure elements.
1408 vaddr = brd->re_map_membase;
1409 true_count = readw((vaddr + NCHAN));
1411 brd->nasync = dgap_config_get_number_of_ports(brd);
1414 brd->nasync = brd->maxports;
1417 if (brd->nasync > brd->maxports) {
1418 brd->nasync = brd->maxports;
1421 if (true_count != brd->nasync) {
1422 if ((brd->type == PPCM) && (true_count == 64)) {
1423 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",
1424 brd->name, brd->nasync, true_count));
1426 else if ((brd->type == PPCM) && (true_count == 0)) {
1427 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",
1428 brd->name, brd->nasync, true_count));
1431 APR(("***WARNING**** %s configured for %d ports, has %d ports.\n",
1432 brd->name, brd->nasync, true_count));
1435 brd->nasync = true_count;
1437 /* If no ports, don't bother going any further */
1439 brd->state = BOARD_FAILED;
1440 brd->dpastatus = BD_NOFEP;
1446 * Allocate channel memory that might not have been allocated
1447 * when the driver was first loaded.
1449 for (i = 0; i < brd->nasync; i++) {
1450 if (!brd->channels[i]) {
1451 brd->channels[i] = kzalloc(sizeof(struct channel_t), GFP_ATOMIC);
1452 if (!brd->channels[i]) {
1453 DPR_CORE(("%s:%d Unable to allocate memory for channel struct\n",
1454 __FILE__, __LINE__));
1459 ch = brd->channels[0];
1460 vaddr = brd->re_map_membase;
1462 bs = (struct bs_t *) ((ulong) vaddr + CHANBUF);
1463 cm = (struct cm_t *) ((ulong) vaddr + CMDBUF);
1467 /* Set up channel variables */
1468 for (i = 0; i < brd->nasync; i++, ch = brd->channels[i], bs++) {
1470 if (!brd->channels[i])
1473 DGAP_SPINLOCK_INIT(ch->ch_lock);
1475 /* Store all our magic numbers */
1476 ch->magic = DGAP_CHANNEL_MAGIC;
1477 ch->ch_tun.magic = DGAP_UNIT_MAGIC;
1478 ch->ch_tun.un_type = DGAP_SERIAL;
1479 ch->ch_tun.un_ch = ch;
1480 ch->ch_tun.un_dev = i;
1482 ch->ch_pun.magic = DGAP_UNIT_MAGIC;
1483 ch->ch_pun.un_type = DGAP_PRINT;
1484 ch->ch_pun.un_ch = ch;
1485 ch->ch_pun.un_dev = i;
1487 ch->ch_vaddr = vaddr;
1492 ch->ch_digi = dgap_digi_init;
1495 * Set up digi dsr and dcd bits based on altpin flag.
1497 if (dgap_config_get_altpin(brd)) {
1500 ch->ch_digi.digi_flags |= DIGI_ALTPIN;
1504 ch->ch_dsr = DM_DSR;
1507 ch->ch_taddr = vaddr + ((ch->ch_bs->tx_seg) << 4);
1508 ch->ch_raddr = vaddr + ((ch->ch_bs->rx_seg) << 4);
1511 ch->ch_tsize = readw(&(ch->ch_bs->tx_max)) + 1;
1512 ch->ch_rsize = readw(&(ch->ch_bs->rx_max)) + 1;
1516 /* .25 second delay */
1517 ch->ch_close_delay = 250;
1520 * Set queue water marks, interrupt mask,
1521 * and general tty parameters.
1523 ch->ch_tlw = tlw = ch->ch_tsize >= 2000 ? ((ch->ch_tsize * 5) / 8) : ch->ch_tsize / 2;
1525 dgap_cmdw(ch, STLOW, tlw, 0);
1527 dgap_cmdw(ch, SRLOW, ch->ch_rsize / 2, 0);
1529 dgap_cmdw(ch, SRHIGH, 7 * ch->ch_rsize / 8, 0);
1531 ch->ch_mistat = readb(&(ch->ch_bs->m_stat));
1533 init_waitqueue_head(&ch->ch_flags_wait);
1534 init_waitqueue_head(&ch->ch_tun.un_flags_wait);
1535 init_waitqueue_head(&ch->ch_pun.un_flags_wait);
1536 init_waitqueue_head(&ch->ch_sniff_wait);
1538 /* Turn on all modem interrupts for now */
1539 modem = (DM_CD | DM_DSR | DM_CTS | DM_RI);
1540 writeb(modem, &(ch->ch_bs->m_int));
1543 * Set edelay to 0 if interrupts are turned on,
1544 * otherwise set edelay to the usual 100.
1547 writew(0, &(ch->ch_bs->edelay));
1549 writew(100, &(ch->ch_bs->edelay));
1551 writeb(1, &(ch->ch_bs->idata));
1555 DPR_INIT(("dgap_tty_init finish\n"));
1562 * dgap_tty_post_uninit()
1564 * UnInitialize any global tty related data.
1566 void dgap_tty_post_uninit(void)
1568 kfree(dgap_TmpWriteBuf);
1569 dgap_TmpWriteBuf = NULL;
1576 * Uninitialize the TTY portion of this driver. Free all memory and
1579 void dgap_tty_uninit(struct board_t *brd)
1583 if (brd->dgap_Major_Serial_Registered) {
1584 dgap_BoardsByMajor[brd->SerialDriver->major] = NULL;
1585 brd->dgap_Serial_Major = 0;
1586 for (i = 0; i < brd->nasync; i++) {
1587 dgap_remove_tty_sysfs(brd->channels[i]->ch_tun.un_sysfs);
1588 tty_unregister_device(brd->SerialDriver, i);
1590 tty_unregister_driver(brd->SerialDriver);
1591 kfree(brd->SerialDriver->ttys);
1592 brd->SerialDriver->ttys = NULL;
1593 put_tty_driver(brd->SerialDriver);
1594 brd->dgap_Major_Serial_Registered = FALSE;
1597 if (brd->dgap_Major_TransparentPrint_Registered) {
1598 dgap_BoardsByMajor[brd->PrintDriver->major] = NULL;
1599 brd->dgap_TransparentPrint_Major = 0;
1600 for (i = 0; i < brd->nasync; i++) {
1601 dgap_remove_tty_sysfs(brd->channels[i]->ch_pun.un_sysfs);
1602 tty_unregister_device(brd->PrintDriver, i);
1604 tty_unregister_driver(brd->PrintDriver);
1605 kfree(brd->PrintDriver->ttys);
1606 brd->PrintDriver->ttys = NULL;
1607 put_tty_driver(brd->PrintDriver);
1608 brd->dgap_Major_TransparentPrint_Registered = FALSE;
1613 #define TMPBUFLEN (1024)
1616 * dgap_sniff - Dump data out to the "sniff" buffer if the
1617 * proc sniff file is opened...
1619 static void dgap_sniff_nowait_nolock(struct channel_t *ch, uchar *text, uchar *buf, int len)
1627 char tmpbuf[TMPBUFLEN];
1631 /* Leave if sniff not open */
1632 if (!(ch->ch_sniff_flags & SNIFF_OPEN))
1635 do_gettimeofday(&tv);
1637 /* Create our header for data dump */
1638 p += sprintf(p, "<%ld %ld><%s><", tv.tv_sec, tv.tv_usec, text);
1639 tmpbuflen = p - tmpbuf;
1644 for (i = 0; i < len && tmpbuflen < (TMPBUFLEN - 4); i++) {
1645 p += sprintf(p, "%02x ", *buf);
1647 tmpbuflen = p - tmpbuf;
1650 if (tmpbuflen < (TMPBUFLEN - 4)) {
1652 p += sprintf(p - 1, "%s\n", ">");
1654 p += sprintf(p, "%s\n", ">");
1660 nbuf = strlen(tmpbuf);
1664 * Loop while data remains.
1666 while (nbuf > 0 && ch->ch_sniff_buf) {
1668 * Determine the amount of available space left in the
1669 * buffer. If there's none, wait until some appears.
1671 n = (ch->ch_sniff_out - ch->ch_sniff_in - 1) & SNIFF_MASK;
1674 * If there is no space left to write to in our sniff buffer,
1675 * we have no choice but to drop the data.
1676 * We *cannot* sleep here waiting for space, because this
1677 * function was probably called by the interrupt/timer routines!
1684 * Copy as much data as will fit.
1690 r = SNIFF_MAX - ch->ch_sniff_in;
1693 memcpy(ch->ch_sniff_buf + ch->ch_sniff_in, p, r);
1696 ch->ch_sniff_in = 0;
1701 memcpy(ch->ch_sniff_buf + ch->ch_sniff_in, p, n);
1703 ch->ch_sniff_in += n;
1708 * Wakeup any thread waiting for data
1710 if (ch->ch_sniff_flags & SNIFF_WAIT_DATA) {
1711 ch->ch_sniff_flags &= ~SNIFF_WAIT_DATA;
1712 wake_up_interruptible(&ch->ch_sniff_wait);
1717 * If the user sent us too much data to push into our tmpbuf,
1718 * we need to keep looping around on all the data.
1720 if (too_much_data) {
1725 } while (too_much_data);
1729 /*=======================================================================
1731 * dgap_input - Process received data.
1733 * ch - Pointer to channel structure.
1735 *=======================================================================*/
1737 void dgap_input(struct channel_t *ch)
1741 struct tty_struct *tp;
1742 struct tty_ldisc *ld;
1756 if (!ch || ch->magic != DGAP_CHANNEL_MAGIC)
1759 tp = ch->ch_tun.un_tty;
1767 if(!bd || bd->magic != DGAP_BOARD_MAGIC)
1770 DPR_READ(("dgap_input start\n"));
1772 DGAP_LOCK(bd->bd_lock, lock_flags);
1773 DGAP_LOCK(ch->ch_lock, lock_flags2);
1776 * Figure the number of characters in the buffer.
1777 * Exit immediately if none.
1780 rmask = ch->ch_rsize - 1;
1782 head = readw(&(bs->rx_head));
1784 tail = readw(&(bs->rx_tail));
1787 data_len = (head - tail) & rmask;
1789 if (data_len == 0) {
1790 writeb(1, &(bs->idata));
1791 DGAP_UNLOCK(ch->ch_lock, lock_flags2);
1792 DGAP_UNLOCK(bd->bd_lock, lock_flags);
1793 DPR_READ(("No data on port %d\n", ch->ch_portnum));
1798 * If the device is not open, or CREAD is off, flush
1799 * input data and return immediately.
1801 if ((bd->state != BOARD_READY) || !tp || (tp->magic != TTY_MAGIC) ||
1802 !(ch->ch_tun.un_flags & UN_ISOPEN) || !(tp->termios.c_cflag & CREAD) ||
1803 (ch->ch_tun.un_flags & UN_CLOSING)) {
1805 DPR_READ(("input. dropping %d bytes on port %d...\n", data_len, ch->ch_portnum));
1806 DPR_READ(("input. tp: %p tp->magic: %x MAGIC:%x ch flags: %x\n",
1807 tp, tp ? tp->magic : 0, TTY_MAGIC, ch->ch_tun.un_flags));
1808 writew(head, &(bs->rx_tail));
1809 writeb(1, &(bs->idata));
1810 DGAP_UNLOCK(ch->ch_lock, lock_flags2);
1811 DGAP_UNLOCK(bd->bd_lock, lock_flags);
1816 * If we are throttled, simply don't read any data.
1818 if (ch->ch_flags & CH_RXBLOCK) {
1819 writeb(1, &(bs->idata));
1820 DGAP_UNLOCK(ch->ch_lock, lock_flags2);
1821 DGAP_UNLOCK(bd->bd_lock, lock_flags);
1822 DPR_READ(("Port %d throttled, not reading any data. head: %x tail: %x\n",
1823 ch->ch_portnum, head, tail));
1830 tmpchar = readb(&(bs->orun));
1832 ch->ch_err_overrun++;
1833 writeb(0, &(bs->orun));
1836 DPR_READ(("dgap_input start 2\n"));
1838 /* Decide how much data we can send into the tty layer */
1839 flip_len = TTY_FLIPBUF_SIZE;
1841 /* Chop down the length, if needed */
1842 len = min(data_len, flip_len);
1843 len = min(len, (N_TTY_BUF_SIZE - 1));
1845 ld = tty_ldisc_ref(tp);
1847 #ifdef TTY_DONT_FLIP
1849 * If the DONT_FLIP flag is on, don't flush our buffer, and act
1850 * like the ld doesn't have any space to put the data right now.
1852 if (test_bit(TTY_DONT_FLIP, &tp->flags))
1857 * If we were unable to get a reference to the ld,
1858 * don't flush our buffer, and act like the ld doesn't
1859 * have any space to put the data right now.
1865 * If ld doesn't have a pointer to a receive_buf function,
1866 * flush the data, then act like the ld doesn't have any
1867 * space to put the data right now.
1869 if (!ld->ops->receive_buf) {
1870 writew(head, &(bs->rx_tail));
1876 writeb(1, &(bs->idata));
1877 DGAP_UNLOCK(ch->ch_lock, lock_flags2);
1878 DGAP_UNLOCK(bd->bd_lock, lock_flags);
1879 DPR_READ(("dgap_input 1 - finish\n"));
1881 tty_ldisc_deref(ld);
1885 buf = ch->ch_bd->flipbuf;
1889 * n now contains the most amount of data we can copy,
1890 * bounded either by our buffer size or the amount
1891 * of data the card actually has pending...
1895 s = ((head >= tail) ? head : ch->ch_rsize) - tail;
1901 memcpy_fromio(buf, (char *) ch->ch_raddr + tail, s);
1902 dgap_sniff_nowait_nolock(ch, "USER READ", buf, s);
1908 /* Flip queue if needed */
1912 writew(tail, &(bs->rx_tail));
1913 writeb(1, &(bs->idata));
1914 ch->ch_rxcount += len;
1917 * If we are completely raw, we don't need to go through a lot
1918 * of the tty layers that exist.
1919 * In this case, we take the shortest and fastest route we
1920 * can to relay the data to the user.
1922 * On the other hand, if we are not raw, we need to go through
1923 * the tty layer, which has its API more well defined.
1925 if (I_PARMRK(tp) || I_BRKINT(tp) || I_INPCK(tp)) {
1926 dgap_parity_scan(ch, ch->ch_bd->flipbuf, ch->ch_bd->flipflagbuf, &len);
1928 len = tty_buffer_request_room(tp->port, len);
1929 tty_insert_flip_string_flags(tp->port, ch->ch_bd->flipbuf,
1930 ch->ch_bd->flipflagbuf, len);
1933 len = tty_buffer_request_room(tp->port, len);
1934 tty_insert_flip_string(tp->port, ch->ch_bd->flipbuf, len);
1937 DGAP_UNLOCK(ch->ch_lock, lock_flags2);
1938 DGAP_UNLOCK(bd->bd_lock, lock_flags);
1940 /* Tell the tty layer its okay to "eat" the data now */
1941 tty_flip_buffer_push(tp->port);
1944 tty_ldisc_deref(ld);
1946 DPR_READ(("dgap_input - finish\n"));
1950 /************************************************************************
1951 * Determines when CARRIER changes state and takes appropriate
1953 ************************************************************************/
1954 void dgap_carrier(struct channel_t *ch)
1958 int virt_carrier = 0;
1959 int phys_carrier = 0;
1961 DPR_CARR(("dgap_carrier called...\n"));
1963 if (!ch || ch->magic != DGAP_CHANNEL_MAGIC)
1968 if (!bd || bd->magic != DGAP_BOARD_MAGIC)
1971 /* Make sure altpin is always set correctly */
1972 if (ch->ch_digi.digi_flags & DIGI_ALTPIN) {
1977 ch->ch_dsr = DM_DSR;
1981 if (ch->ch_mistat & D_CD(ch)) {
1982 DPR_CARR(("mistat: %x D_CD: %x\n", ch->ch_mistat, D_CD(ch)));
1986 if (ch->ch_digi.digi_flags & DIGI_FORCEDCD) {
1990 if (ch->ch_c_cflag & CLOCAL) {
1995 DPR_CARR(("DCD: physical: %d virt: %d\n", phys_carrier, virt_carrier));
1998 * Test for a VIRTUAL carrier transition to HIGH.
2000 if (((ch->ch_flags & CH_FCAR) == 0) && (virt_carrier == 1)) {
2003 * When carrier rises, wake any threads waiting
2004 * for carrier in the open routine.
2007 DPR_CARR(("carrier: virt DCD rose\n"));
2009 if (waitqueue_active(&(ch->ch_flags_wait)))
2010 wake_up_interruptible(&ch->ch_flags_wait);
2014 * Test for a PHYSICAL carrier transition to HIGH.
2016 if (((ch->ch_flags & CH_CD) == 0) && (phys_carrier == 1)) {
2019 * When carrier rises, wake any threads waiting
2020 * for carrier in the open routine.
2023 DPR_CARR(("carrier: physical DCD rose\n"));
2025 if (waitqueue_active(&(ch->ch_flags_wait)))
2026 wake_up_interruptible(&ch->ch_flags_wait);
2030 * Test for a PHYSICAL transition to low, so long as we aren't
2031 * currently ignoring physical transitions (which is what "virtual
2032 * carrier" indicates).
2034 * The transition of the virtual carrier to low really doesn't
2035 * matter... it really only means "ignore carrier state", not
2036 * "make pretend that carrier is there".
2038 if ((virt_carrier == 0) && ((ch->ch_flags & CH_CD) != 0) &&
2039 (phys_carrier == 0))
2043 * When carrier drops:
2045 * Drop carrier on all open units.
2047 * Flush queues, waking up any task waiting in the
2050 * Send a hangup to the control terminal.
2052 * Enable all select calls.
2054 if (waitqueue_active(&(ch->ch_flags_wait)))
2055 wake_up_interruptible(&ch->ch_flags_wait);
2057 if (ch->ch_tun.un_open_count > 0) {
2058 DPR_CARR(("Sending tty hangup\n"));
2059 tty_hangup(ch->ch_tun.un_tty);
2062 if (ch->ch_pun.un_open_count > 0) {
2063 DPR_CARR(("Sending pr hangup\n"));
2064 tty_hangup(ch->ch_pun.un_tty);
2069 * Make sure that our cached values reflect the current reality.
2071 if (virt_carrier == 1)
2072 ch->ch_flags |= CH_FCAR;
2074 ch->ch_flags &= ~CH_FCAR;
2076 if (phys_carrier == 1)
2077 ch->ch_flags |= CH_CD;
2079 ch->ch_flags &= ~CH_CD;
2083 /************************************************************************
2085 * TTY Entry points and helper functions
2087 ************************************************************************/
2093 static int dgap_tty_open(struct tty_struct *tty, struct file *file)
2095 struct board_t *brd;
2096 struct channel_t *ch;
2108 major = MAJOR(tty_devnum(tty));
2109 minor = MINOR(tty_devnum(tty));
2115 /* Get board pointer from our array of majors we have allocated */
2116 brd = dgap_BoardsByMajor[major];
2122 * If board is not yet up to a state of READY, go to
2123 * sleep waiting for it to happen or they cancel the open.
2125 rc = wait_event_interruptible(brd->state_wait,
2126 (brd->state & BOARD_READY));
2132 DGAP_LOCK(brd->bd_lock, lock_flags);
2134 /* The wait above should guarantee this cannot happen */
2135 if (brd->state != BOARD_READY) {
2136 DGAP_UNLOCK(brd->bd_lock, lock_flags);
2140 /* If opened device is greater than our number of ports, bail. */
2141 if (MINOR(tty_devnum(tty)) > brd->nasync) {
2142 DGAP_UNLOCK(brd->bd_lock, lock_flags);
2146 ch = brd->channels[minor];
2148 DGAP_UNLOCK(brd->bd_lock, lock_flags);
2152 /* Grab channel lock */
2153 DGAP_LOCK(ch->ch_lock, lock_flags2);
2155 /* Figure out our type */
2156 if (major == brd->dgap_Serial_Major) {
2157 un = &brd->channels[minor]->ch_tun;
2158 un->un_type = DGAP_SERIAL;
2160 else if (major == brd->dgap_TransparentPrint_Major) {
2161 un = &brd->channels[minor]->ch_pun;
2162 un->un_type = DGAP_PRINT;
2165 DGAP_UNLOCK(ch->ch_lock, lock_flags2);
2166 DGAP_UNLOCK(brd->bd_lock, lock_flags);
2167 DPR_OPEN(("%d Unknown TYPE!\n", __LINE__));
2171 /* Store our unit into driver_data, so we always have it available. */
2172 tty->driver_data = un;
2174 DPR_OPEN(("Open called. MAJOR: %d MINOR:%d unit: %p NAME: %s\n",
2175 MAJOR(tty_devnum(tty)), MINOR(tty_devnum(tty)), un, brd->name));
2178 * Error if channel info pointer is NULL.
2182 DGAP_UNLOCK(ch->ch_lock, lock_flags2);
2183 DGAP_UNLOCK(brd->bd_lock, lock_flags);
2184 DPR_OPEN(("%d BS is 0!\n", __LINE__));
2188 DPR_OPEN(("%d: tflag=%x pflag=%x\n", __LINE__, ch->ch_tun.un_flags, ch->ch_pun.un_flags));
2193 if (!(un->un_flags & UN_ISOPEN)) {
2194 /* Store important variables. */
2197 /* Maybe do something here to the TTY struct as well? */
2201 * Initialize if neither terminal or printer is open.
2203 if (!((ch->ch_tun.un_flags | ch->ch_pun.un_flags) & UN_ISOPEN)) {
2205 DPR_OPEN(("dgap_open: initializing channel in open...\n"));
2211 * Flush input queue.
2213 head = readw(&(bs->rx_head));
2214 writew(head, &(bs->rx_tail));
2217 ch->pscan_state = 0;
2218 ch->pscan_savechar = 0;
2220 ch->ch_c_cflag = tty->termios.c_cflag;
2221 ch->ch_c_iflag = tty->termios.c_iflag;
2222 ch->ch_c_oflag = tty->termios.c_oflag;
2223 ch->ch_c_lflag = tty->termios.c_lflag;
2224 ch->ch_startc = tty->termios.c_cc[VSTART];
2225 ch->ch_stopc = tty->termios.c_cc[VSTOP];
2227 /* TODO: flush our TTY struct here? */
2232 * Run param in case we changed anything
2237 * follow protocol for opening port
2240 DGAP_UNLOCK(ch->ch_lock, lock_flags2);
2241 DGAP_UNLOCK(brd->bd_lock, lock_flags);
2243 rc = dgap_block_til_ready(tty, file, ch);
2250 DPR_OPEN(("dgap_tty_open returning after dgap_block_til_ready "
2254 /* No going back now, increment our unit and channel counters */
2255 DGAP_LOCK(ch->ch_lock, lock_flags);
2256 ch->ch_open_count++;
2257 un->un_open_count++;
2258 un->un_flags |= (UN_ISOPEN);
2259 DGAP_UNLOCK(ch->ch_lock, lock_flags);
2261 DPR_OPEN(("dgap_tty_open finished\n"));
2267 * dgap_block_til_ready()
2269 * Wait for DCD, if needed.
2271 static int dgap_block_til_ready(struct tty_struct *tty, struct file *file, struct channel_t *ch)
2274 struct un_t *un = NULL;
2277 int sleep_on_un_flags = 0;
2279 if (!tty || tty->magic != TTY_MAGIC || !file || !ch || ch->magic != DGAP_CHANNEL_MAGIC) {
2283 un = tty->driver_data;
2284 if (!un || un->magic != DGAP_UNIT_MAGIC) {
2288 DPR_OPEN(("dgap_block_til_ready - before block.\n"));
2290 DGAP_LOCK(ch->ch_lock, lock_flags);
2297 sleep_on_un_flags = 0;
2300 * If board has failed somehow during our sleep, bail with error.
2302 if (ch->ch_bd->state == BOARD_FAILED) {
2307 /* If tty was hung up, break out of loop and set error. */
2308 if (tty_hung_up_p(file)) {
2314 * If either unit is in the middle of the fragile part of close,
2315 * we just cannot touch the channel safely.
2316 * Go back to sleep, knowing that when the channel can be
2317 * touched safely, the close routine will signal the
2318 * ch_wait_flags to wake us back up.
2320 if (!((ch->ch_tun.un_flags | ch->ch_pun.un_flags) & UN_CLOSING)) {
2323 * Our conditions to leave cleanly and happily:
2324 * 1) NONBLOCKING on the tty is set.
2326 * 3) DCD (fake or real) is active.
2329 if (file->f_flags & O_NONBLOCK) {
2333 if (tty->flags & (1 << TTY_IO_ERROR)) {
2337 if (ch->ch_flags & CH_CD) {
2338 DPR_OPEN(("%d: ch_flags: %x\n", __LINE__, ch->ch_flags));
2342 if (ch->ch_flags & CH_FCAR) {
2343 DPR_OPEN(("%d: ch_flags: %x\n", __LINE__, ch->ch_flags));
2348 sleep_on_un_flags = 1;
2352 * If there is a signal pending, the user probably
2353 * interrupted (ctrl-c) us.
2354 * Leave loop with error set.
2356 if (signal_pending(current)) {
2357 DPR_OPEN(("%d: signal pending...\n", __LINE__));
2358 retval = -ERESTARTSYS;
2362 DPR_OPEN(("dgap_block_til_ready - blocking.\n"));
2365 * Store the flags before we let go of channel lock
2367 if (sleep_on_un_flags)
2368 old_flags = ch->ch_tun.un_flags | ch->ch_pun.un_flags;
2370 old_flags = ch->ch_flags;
2373 * Let go of channel lock before calling schedule.
2374 * Our poller will get any FEP events and wake us up when DCD
2375 * eventually goes active.
2378 DGAP_UNLOCK(ch->ch_lock, lock_flags);
2380 DPR_OPEN(("Going to sleep on %s flags...\n",
2381 (sleep_on_un_flags ? "un" : "ch")));
2384 * Wait for something in the flags to change from the current value.
2386 if (sleep_on_un_flags) {
2387 retval = wait_event_interruptible(un->un_flags_wait,
2388 (old_flags != (ch->ch_tun.un_flags | ch->ch_pun.un_flags)));
2391 retval = wait_event_interruptible(ch->ch_flags_wait,
2392 (old_flags != ch->ch_flags));
2395 DPR_OPEN(("After sleep... retval: %x\n", retval));
2398 * We got woken up for some reason.
2399 * Before looping around, grab our channel lock.
2401 DGAP_LOCK(ch->ch_lock, lock_flags);
2406 DGAP_UNLOCK(ch->ch_lock, lock_flags);
2408 DPR_OPEN(("dgap_block_til_ready - after blocking.\n"));
2411 DPR_OPEN(("dgap_block_til_ready - done. error. retval: %x\n", retval));
2415 DPR_OPEN(("dgap_block_til_ready - done no error. jiffies: %lu\n", jiffies));
2424 * Hangup the port. Like a close, but don't wait for output to drain.
2426 static void dgap_tty_hangup(struct tty_struct *tty)
2429 struct channel_t *ch;
2432 if (!tty || tty->magic != TTY_MAGIC)
2435 un = tty->driver_data;
2436 if (!un || un->magic != DGAP_UNIT_MAGIC)
2440 if (!ch || ch->magic != DGAP_CHANNEL_MAGIC)
2444 if (!bd || bd->magic != DGAP_BOARD_MAGIC)
2447 DPR_CLOSE(("dgap_hangup called. ch->ch_open_count: %d un->un_open_count: %d\n",
2448 ch->ch_open_count, un->un_open_count));
2450 /* flush the transmit queues */
2451 dgap_tty_flush_buffer(tty);
2453 DPR_CLOSE(("dgap_hangup finished. ch->ch_open_count: %d un->un_open_count: %d\n",
2454 ch->ch_open_count, un->un_open_count));
2463 static void dgap_tty_close(struct tty_struct *tty, struct file *file)
2465 struct ktermios *ts;
2467 struct channel_t *ch;
2472 if (!tty || tty->magic != TTY_MAGIC)
2475 un = tty->driver_data;
2476 if (!un || un->magic != DGAP_UNIT_MAGIC)
2480 if (!ch || ch->magic != DGAP_CHANNEL_MAGIC)
2484 if (!bd || bd->magic != DGAP_BOARD_MAGIC)
2489 DPR_CLOSE(("Close called\n"));
2491 DGAP_LOCK(ch->ch_lock, lock_flags);
2494 * Determine if this is the last close or not - and if we agree about
2495 * which type of close it is with the Line Discipline
2497 if ((tty->count == 1) && (un->un_open_count != 1)) {
2499 * Uh, oh. tty->count is 1, which means that the tty
2500 * structure will be freed. un_open_count should always
2501 * be one in these conditions. If it's greater than
2502 * one, we've got real problems, since it means the
2503 * serial port won't be shutdown.
2505 APR(("tty->count is 1, un open count is %d\n", un->un_open_count));
2506 un->un_open_count = 1;
2509 if (--un->un_open_count < 0) {
2510 APR(("bad serial port open count of %d\n", un->un_open_count));
2511 un->un_open_count = 0;
2514 ch->ch_open_count--;
2516 if (ch->ch_open_count && un->un_open_count) {
2517 DPR_CLOSE(("dgap_tty_close: not last close ch: %d un:%d\n",
2518 ch->ch_open_count, un->un_open_count));
2520 DGAP_UNLOCK(ch->ch_lock, lock_flags);
2524 /* OK, its the last close on the unit */
2525 DPR_CLOSE(("dgap_tty_close - last close on unit procedures\n"));
2527 un->un_flags |= UN_CLOSING;
2532 * Only officially close channel if count is 0 and
2533 * DIGI_PRINTER bit is not set.
2535 if ((ch->ch_open_count == 0) && !(ch->ch_digi.digi_flags & DIGI_PRINTER)) {
2537 ch->ch_flags &= ~(CH_RXBLOCK);
2539 DGAP_UNLOCK(ch->ch_lock, lock_flags);
2541 /* wait for output to drain */
2542 /* This will also return if we take an interrupt */
2544 DPR_CLOSE(("Calling wait_for_drain\n"));
2545 rc = dgap_wait_for_drain(tty);
2546 DPR_CLOSE(("After calling wait_for_drain\n"));
2549 DPR_BASIC(("dgap_tty_close - bad return: %d ", rc));
2552 dgap_tty_flush_buffer(tty);
2553 tty_ldisc_flush(tty);
2555 DGAP_LOCK(ch->ch_lock, lock_flags);
2560 * If we have HUPCL set, lower DTR and RTS
2562 if (ch->ch_c_cflag & HUPCL ) {
2563 DPR_CLOSE(("Close. HUPCL set, dropping DTR/RTS\n"));
2564 ch->ch_mostat &= ~(D_RTS(ch)|D_DTR(ch));
2565 dgap_cmdb( ch, SMODEM, 0, D_DTR(ch)|D_RTS(ch), 0 );
2568 * Go to sleep to ensure RTS/DTR
2569 * have been dropped for modems to see it.
2571 if (ch->ch_close_delay) {
2572 DPR_CLOSE(("Close. Sleeping for RTS/DTR drop\n"));
2574 DGAP_UNLOCK(ch->ch_lock, lock_flags);
2575 dgap_ms_sleep(ch->ch_close_delay);
2576 DGAP_LOCK(ch->ch_lock, lock_flags);
2578 DPR_CLOSE(("Close. After sleeping for RTS/DTR drop\n"));
2582 ch->pscan_state = 0;
2583 ch->pscan_savechar = 0;
2584 ch->ch_baud_info = 0;
2589 * turn off print device when closing print device.
2591 if ((un->un_type == DGAP_PRINT) && (ch->ch_flags & CH_PRON) ) {
2592 dgap_wmove(ch, ch->ch_digi.digi_offstr,
2593 (int) ch->ch_digi.digi_offlen);
2594 ch->ch_flags &= ~CH_PRON;
2598 un->un_flags &= ~(UN_ISOPEN | UN_CLOSING);
2599 tty->driver_data = NULL;
2601 DPR_CLOSE(("Close. Doing wakeups\n"));
2602 wake_up_interruptible(&ch->ch_flags_wait);
2603 wake_up_interruptible(&un->un_flags_wait);
2605 DGAP_UNLOCK(ch->ch_lock, lock_flags);
2607 DPR_BASIC(("dgap_tty_close - complete\n"));
2612 * dgap_tty_chars_in_buffer()
2614 * Return number of characters that have not been transmitted yet.
2616 * This routine is used by the line discipline to determine if there
2617 * is data waiting to be transmitted/drained/flushed or not.
2619 static int dgap_tty_chars_in_buffer(struct tty_struct *tty)
2621 struct board_t *bd = NULL;
2622 struct channel_t *ch = NULL;
2623 struct un_t *un = NULL;
2624 struct bs_t *bs = NULL;
2627 u16 thead, ttail, tmask, chead, ctail;
2628 ulong lock_flags = 0;
2629 ulong lock_flags2 = 0;
2634 un = tty->driver_data;
2635 if (!un || un->magic != DGAP_UNIT_MAGIC)
2639 if (!ch || ch->magic != DGAP_CHANNEL_MAGIC)
2643 if (!bd || bd->magic != DGAP_BOARD_MAGIC)
2650 DGAP_LOCK(bd->bd_lock, lock_flags);
2651 DGAP_LOCK(ch->ch_lock, lock_flags2);
2653 tmask = (ch->ch_tsize - 1);
2655 /* Get Transmit queue pointers */
2656 thead = readw(&(bs->tx_head)) & tmask;
2657 ttail = readw(&(bs->tx_tail)) & tmask;
2659 /* Get tbusy flag */
2660 tbusy = readb(&(bs->tbusy));
2662 /* Get Command queue pointers */
2663 chead = readw(&(ch->ch_cm->cm_head));
2664 ctail = readw(&(ch->ch_cm->cm_tail));
2666 DGAP_UNLOCK(ch->ch_lock, lock_flags2);
2667 DGAP_UNLOCK(bd->bd_lock, lock_flags);
2670 * The only way we know for sure if there is no pending
2671 * data left to be transferred, is if:
2672 * 1) Transmit head and tail are equal (empty).
2673 * 2) Command queue head and tail are equal (empty).
2674 * 3) The "TBUSY" flag is 0. (Transmitter not busy).
2677 if ((ttail == thead) && (tbusy == 0) && (chead == ctail)) {
2682 chars = thead - ttail;
2684 chars = thead - ttail + ch->ch_tsize;
2686 * Fudge factor here.
2687 * If chars is zero, we know that the command queue had
2688 * something in it or tbusy was set. Because we cannot
2689 * be sure if there is still some data to be transmitted,
2690 * lets lie, and tell ld we have 1 byte left.
2694 * If TBUSY is still set, and our tx buffers are empty,
2695 * force the firmware to send me another wakeup after
2696 * TBUSY has been cleared.
2699 DGAP_LOCK(ch->ch_lock, lock_flags);
2700 un->un_flags |= UN_EMPTY;
2701 writeb(1, &(bs->iempty));
2702 DGAP_UNLOCK(ch->ch_lock, lock_flags);
2708 DPR_WRITE(("dgap_tty_chars_in_buffer. Port: %x - %d (head: %d tail: %d tsize: %d)\n",
2709 ch->ch_portnum, chars, thead, ttail, ch->ch_tsize));
2714 static int dgap_wait_for_drain(struct tty_struct *tty)
2716 struct channel_t *ch;
2721 ulong lock_flags = 0;
2723 if (!tty || tty->magic != TTY_MAGIC)
2726 un = tty->driver_data;
2727 if (!un || un->magic != DGAP_UNIT_MAGIC)
2731 if (!ch || ch->magic != DGAP_CHANNEL_MAGIC)
2740 DPR_DRAIN(("dgap_wait_for_drain start\n"));
2742 /* Loop until data is drained */
2743 while (count != 0) {
2745 count = dgap_tty_chars_in_buffer(tty);
2750 /* Set flag waiting for drain */
2751 DGAP_LOCK(ch->ch_lock, lock_flags);
2752 un->un_flags |= UN_EMPTY;
2753 writeb(1, &(bs->iempty));
2754 DGAP_UNLOCK(ch->ch_lock, lock_flags);
2756 /* Go to sleep till we get woken up */
2757 ret = wait_event_interruptible(un->un_flags_wait, ((un->un_flags & UN_EMPTY) == 0));
2758 /* If ret is non-zero, user ctrl-c'ed us */
2764 DGAP_LOCK(ch->ch_lock, lock_flags);
2765 un->un_flags &= ~(UN_EMPTY);
2766 DGAP_UNLOCK(ch->ch_lock, lock_flags);
2768 DPR_DRAIN(("dgap_wait_for_drain finish\n"));
2776 * Reduces bytes_available to the max number of characters
2777 * that can be sent currently given the maxcps value, and
2778 * returns the new bytes_available. This only affects printer
2781 static int dgap_maxcps_room(struct tty_struct *tty, int bytes_available)
2783 struct channel_t *ch = NULL;
2784 struct un_t *un = NULL;
2787 return (bytes_available);
2789 un = tty->driver_data;
2790 if (!un || un->magic != DGAP_UNIT_MAGIC)
2791 return (bytes_available);
2794 if (!ch || ch->magic != DGAP_CHANNEL_MAGIC)
2795 return (bytes_available);
2798 * If its not the Transparent print device, return
2799 * the full data amount.
2801 if (un->un_type != DGAP_PRINT)
2802 return (bytes_available);
2804 if (ch->ch_digi.digi_maxcps > 0 && ch->ch_digi.digi_bufsize > 0 ) {
2806 unsigned long current_time = jiffies;
2807 unsigned long buffer_time = current_time +
2808 (HZ * ch->ch_digi.digi_bufsize) / ch->ch_digi.digi_maxcps;
2810 if (ch->ch_cpstime < current_time) {
2811 /* buffer is empty */
2812 ch->ch_cpstime = current_time; /* reset ch_cpstime */
2813 cps_limit = ch->ch_digi.digi_bufsize;
2815 else if (ch->ch_cpstime < buffer_time) {
2816 /* still room in the buffer */
2817 cps_limit = ((buffer_time - ch->ch_cpstime) * ch->ch_digi.digi_maxcps) / HZ;
2820 /* no room in the buffer */
2824 bytes_available = min(cps_limit, bytes_available);
2827 return (bytes_available);
2831 static inline void dgap_set_firmware_event(struct un_t *un, unsigned int event)
2833 struct channel_t *ch = NULL;
2834 struct bs_t *bs = NULL;
2836 if (!un || un->magic != DGAP_UNIT_MAGIC)
2839 if (!ch || ch->magic != DGAP_CHANNEL_MAGIC)
2845 if ((event & UN_LOW) != 0) {
2846 if ((un->un_flags & UN_LOW) == 0) {
2847 un->un_flags |= UN_LOW;
2848 writeb(1, &(bs->ilow));
2851 if ((event & UN_LOW) != 0) {
2852 if ((un->un_flags & UN_EMPTY) == 0) {
2853 un->un_flags |= UN_EMPTY;
2854 writeb(1, &(bs->iempty));
2861 * dgap_tty_write_room()
2863 * Return space available in Tx buffer
2865 static int dgap_tty_write_room(struct tty_struct *tty)
2867 struct channel_t *ch = NULL;
2868 struct un_t *un = NULL;
2869 struct bs_t *bs = NULL;
2870 u16 head, tail, tmask;
2872 ulong lock_flags = 0;
2874 if (tty == NULL || dgap_TmpWriteBuf == NULL)
2877 un = tty->driver_data;
2878 if (!un || un->magic != DGAP_UNIT_MAGIC)
2882 if (!ch || ch->magic != DGAP_CHANNEL_MAGIC)
2889 DGAP_LOCK(ch->ch_lock, lock_flags);
2891 tmask = ch->ch_tsize - 1;
2892 head = readw(&(bs->tx_head)) & tmask;
2893 tail = readw(&(bs->tx_tail)) & tmask;
2895 if ((ret = tail - head - 1) < 0)
2896 ret += ch->ch_tsize;
2898 /* Limit printer to maxcps */
2899 ret = dgap_maxcps_room(tty, ret);
2902 * If we are printer device, leave space for
2903 * possibly both the on and off strings.
2905 if (un->un_type == DGAP_PRINT) {
2906 if (!(ch->ch_flags & CH_PRON))
2907 ret -= ch->ch_digi.digi_onlen;
2908 ret -= ch->ch_digi.digi_offlen;
2911 if (ch->ch_flags & CH_PRON)
2912 ret -= ch->ch_digi.digi_offlen;
2919 * Schedule FEP to wake us up if needed.
2921 * TODO: This might be overkill...
2922 * Do we really need to schedule callbacks from the FEP
2923 * in every case? Can we get smarter based on ret?
2925 dgap_set_firmware_event(un, UN_LOW | UN_EMPTY);
2926 DGAP_UNLOCK(ch->ch_lock, lock_flags);
2928 DPR_WRITE(("dgap_tty_write_room - %d tail: %d head: %d\n", ret, tail, head));
2935 * dgap_tty_put_char()
2937 * Put a character into ch->ch_buf
2939 * - used by the line discipline for OPOST processing
2941 static int dgap_tty_put_char(struct tty_struct *tty, unsigned char c)
2944 * Simply call tty_write.
2946 DPR_WRITE(("dgap_tty_put_char called\n"));
2947 dgap_tty_write(tty, &c, 1);
2955 * Take data from the user or kernel and send it out to the FEP.
2956 * In here exists all the Transparent Print magic as well.
2958 static int dgap_tty_write(struct tty_struct *tty, const unsigned char *buf, int count)
2960 struct channel_t *ch = NULL;
2961 struct un_t *un = NULL;
2962 struct bs_t *bs = NULL;
2964 u16 head, tail, tmask, remain;
2965 int bufcount = 0, n = 0;
2970 if (tty == NULL || dgap_TmpWriteBuf == NULL)
2973 un = tty->driver_data;
2974 if (!un || un->magic != DGAP_UNIT_MAGIC)
2978 if (!ch || ch->magic != DGAP_CHANNEL_MAGIC)
2988 DPR_WRITE(("dgap_tty_write: Port: %x tty=%p user=%d len=%d\n",
2989 ch->ch_portnum, tty, from_user, count));
2992 * Store original amount of characters passed in.
2993 * This helps to figure out if we should ask the FEP
2994 * to send us an event when it has more space available.
2998 DGAP_LOCK(ch->ch_lock, lock_flags);
3000 /* Get our space available for the channel from the board */
3001 tmask = ch->ch_tsize - 1;
3002 head = readw(&(bs->tx_head)) & tmask;
3003 tail = readw(&(bs->tx_tail)) & tmask;
3005 if ((bufcount = tail - head - 1) < 0)
3006 bufcount += ch->ch_tsize;
3008 DPR_WRITE(("%d: bufcount: %x count: %x tail: %x head: %x tmask: %x\n",
3009 __LINE__, bufcount, count, tail, head, tmask));
3012 * Limit printer output to maxcps overall, with bursts allowed
3013 * up to bufsize characters.
3015 bufcount = dgap_maxcps_room(tty, bufcount);
3018 * Take minimum of what the user wants to send, and the
3019 * space available in the FEP buffer.
3021 count = min(count, bufcount);
3024 * Bail if no space left.
3027 dgap_set_firmware_event(un, UN_LOW | UN_EMPTY);
3028 DGAP_UNLOCK(ch->ch_lock, lock_flags);
3033 * Output the printer ON string, if we are in terminal mode, but
3034 * need to be in printer mode.
3036 if ((un->un_type == DGAP_PRINT) && !(ch->ch_flags & CH_PRON)) {
3037 dgap_wmove(ch, ch->ch_digi.digi_onstr,
3038 (int) ch->ch_digi.digi_onlen);
3039 head = readw(&(bs->tx_head)) & tmask;
3040 ch->ch_flags |= CH_PRON;
3044 * On the other hand, output the printer OFF string, if we are
3045 * currently in printer mode, but need to output to the terminal.
3047 if ((un->un_type != DGAP_PRINT) && (ch->ch_flags & CH_PRON)) {
3048 dgap_wmove(ch, ch->ch_digi.digi_offstr,
3049 (int) ch->ch_digi.digi_offlen);
3050 head = readw(&(bs->tx_head)) & tmask;
3051 ch->ch_flags &= ~CH_PRON;
3055 * If there is nothing left to copy, or I can't handle any more data, leave.
3058 dgap_set_firmware_event(un, UN_LOW | UN_EMPTY);
3059 DGAP_UNLOCK(ch->ch_lock, lock_flags);
3065 count = min(count, WRITEBUFLEN);
3067 DGAP_UNLOCK(ch->ch_lock, lock_flags);
3070 * If data is coming from user space, copy it into a temporary
3071 * buffer so we don't get swapped out while doing the copy to
3074 /* we're allowed to block if it's from_user */
3075 if (down_interruptible(&dgap_TmpWriteSem)) {
3079 if (copy_from_user(dgap_TmpWriteBuf, (const uchar __user *) buf, count)) {
3080 up(&dgap_TmpWriteSem);
3081 printk("Write: Copy from user failed!\n");
3085 DGAP_LOCK(ch->ch_lock, lock_flags);
3087 buf = dgap_TmpWriteBuf;
3093 * If the write wraps over the top of the circular buffer,
3094 * move the portion up to the wrap point, and reset the
3095 * pointers to the bottom.
3097 remain = ch->ch_tstart + ch->ch_tsize - head;
3101 vaddr = ch->ch_taddr + head;
3103 memcpy_toio(vaddr, (uchar *) buf, remain);
3104 dgap_sniff_nowait_nolock(ch, "USER WRITE", (uchar *) buf, remain);
3106 head = ch->ch_tstart;
3113 * Move rest of data.
3115 vaddr = ch->ch_taddr + head;
3118 memcpy_toio(vaddr, (uchar *) buf, remain);
3119 dgap_sniff_nowait_nolock(ch, "USER WRITE", (uchar *) buf, remain);
3126 ch->ch_txcount += count;
3128 writew(head, &(bs->tx_head));
3132 dgap_set_firmware_event(un, UN_LOW | UN_EMPTY);
3135 * If this is the print device, and the
3136 * printer is still on, we need to turn it
3137 * off before going idle. If the buffer is
3138 * non-empty, wait until it goes empty.
3139 * Otherwise turn it off right now.
3141 if ((un->un_type == DGAP_PRINT) && (ch->ch_flags & CH_PRON)) {
3142 tail = readw(&(bs->tx_tail)) & tmask;
3145 un->un_flags |= UN_EMPTY;
3146 writeb(1, &(bs->iempty));
3149 dgap_wmove(ch, ch->ch_digi.digi_offstr,
3150 (int) ch->ch_digi.digi_offlen);
3151 head = readw(&(bs->tx_head)) & tmask;
3152 ch->ch_flags &= ~CH_PRON;
3156 /* Update printer buffer empty time. */
3157 if ((un->un_type == DGAP_PRINT) && (ch->ch_digi.digi_maxcps > 0)
3158 && (ch->ch_digi.digi_bufsize > 0)) {
3159 ch->ch_cpstime += (HZ * count) / ch->ch_digi.digi_maxcps;
3163 DGAP_UNLOCK(ch->ch_lock, lock_flags);
3164 up(&dgap_TmpWriteSem);
3167 DGAP_UNLOCK(ch->ch_lock, lock_flags);
3170 DPR_WRITE(("Write finished - Write %d bytes of %d.\n", count, orig_count));
3178 * Return modem signals to ld.
3180 static int dgap_tty_tiocmget(struct tty_struct *tty)
3182 struct channel_t *ch;
3188 if (!tty || tty->magic != TTY_MAGIC)
3191 un = tty->driver_data;
3192 if (!un || un->magic != DGAP_UNIT_MAGIC)
3196 if (!ch || ch->magic != DGAP_CHANNEL_MAGIC)
3199 DPR_IOCTL(("dgap_tty_tiocmget start\n"));
3201 DGAP_LOCK(ch->ch_lock, lock_flags);
3203 mstat = readb(&(ch->ch_bs->m_stat));
3204 /* Append any outbound signals that might be pending... */
3205 mstat |= ch->ch_mostat;
3207 DGAP_UNLOCK(ch->ch_lock, lock_flags);
3211 if (mstat & D_DTR(ch))
3212 result |= TIOCM_DTR;
3213 if (mstat & D_RTS(ch))
3214 result |= TIOCM_RTS;
3215 if (mstat & D_CTS(ch))
3216 result |= TIOCM_CTS;
3217 if (mstat & D_DSR(ch))
3218 result |= TIOCM_DSR;
3219 if (mstat & D_RI(ch))
3221 if (mstat & D_CD(ch))
3224 DPR_IOCTL(("dgap_tty_tiocmget finish\n"));
3231 * dgap_tty_tiocmset()
3233 * Set modem signals, called by ld.
3236 static int dgap_tty_tiocmset(struct tty_struct *tty,
3237 unsigned int set, unsigned int clear)
3240 struct channel_t *ch;
3246 if (!tty || tty->magic != TTY_MAGIC)
3249 un = tty->driver_data;
3250 if (!un || un->magic != DGAP_UNIT_MAGIC)
3254 if (!ch || ch->magic != DGAP_CHANNEL_MAGIC)
3258 if (!bd || bd->magic != DGAP_BOARD_MAGIC)
3261 DPR_IOCTL(("dgap_tty_tiocmset start\n"));
3263 DGAP_LOCK(bd->bd_lock, lock_flags);
3264 DGAP_LOCK(ch->ch_lock, lock_flags2);
3266 if (set & TIOCM_RTS) {
3267 ch->ch_mforce |= D_RTS(ch);
3268 ch->ch_mval |= D_RTS(ch);
3271 if (set & TIOCM_DTR) {
3272 ch->ch_mforce |= D_DTR(ch);
3273 ch->ch_mval |= D_DTR(ch);
3276 if (clear & TIOCM_RTS) {
3277 ch->ch_mforce |= D_RTS(ch);
3278 ch->ch_mval &= ~(D_RTS(ch));
3281 if (clear & TIOCM_DTR) {
3282 ch->ch_mforce |= D_DTR(ch);
3283 ch->ch_mval &= ~(D_DTR(ch));
3288 DGAP_UNLOCK(ch->ch_lock, lock_flags2);
3289 DGAP_UNLOCK(bd->bd_lock, lock_flags);
3291 DPR_IOCTL(("dgap_tty_tiocmset finish\n"));
3299 * dgap_tty_send_break()
3301 * Send a Break, called by ld.
3303 static int dgap_tty_send_break(struct tty_struct *tty, int msec)
3306 struct channel_t *ch;
3312 if (!tty || tty->magic != TTY_MAGIC)
3315 un = tty->driver_data;
3316 if (!un || un->magic != DGAP_UNIT_MAGIC)
3320 if (!ch || ch->magic != DGAP_CHANNEL_MAGIC)
3324 if (!bd || bd->magic != DGAP_BOARD_MAGIC)
3339 DPR_IOCTL(("dgap_tty_send_break start 1. %lx\n", jiffies));
3341 DGAP_LOCK(bd->bd_lock, lock_flags);
3342 DGAP_LOCK(ch->ch_lock, lock_flags2);
3344 dgap_cmdw(ch, SBREAK, (u16) SBREAK_TIME, 0);
3346 dgap_cmdw(ch, SBREAK, (u16) msec, 0);
3348 DGAP_UNLOCK(ch->ch_lock, lock_flags2);
3349 DGAP_UNLOCK(bd->bd_lock, lock_flags);
3351 DPR_IOCTL(("dgap_tty_send_break finish\n"));
3360 * dgap_tty_wait_until_sent()
3362 * wait until data has been transmitted, called by ld.
3364 static void dgap_tty_wait_until_sent(struct tty_struct *tty, int timeout)
3367 rc = dgap_wait_for_drain(tty);
3369 DPR_IOCTL(("dgap_tty_ioctl - bad return: %d ", rc));
3380 * send a high priority character, called by ld.
3382 static void dgap_tty_send_xchar(struct tty_struct *tty, char c)
3385 struct channel_t *ch;
3390 if (!tty || tty->magic != TTY_MAGIC)
3393 un = tty->driver_data;
3394 if (!un || un->magic != DGAP_UNIT_MAGIC)
3398 if (!ch || ch->magic != DGAP_CHANNEL_MAGIC)
3402 if (!bd || bd->magic != DGAP_BOARD_MAGIC)
3405 DPR_IOCTL(("dgap_tty_send_xchar start 1. %lx\n", jiffies));
3407 DGAP_LOCK(bd->bd_lock, lock_flags);
3408 DGAP_LOCK(ch->ch_lock, lock_flags2);
3411 * This is technically what we should do.
3412 * However, the NIST tests specifically want
3413 * to see each XON or XOFF character that it
3414 * sends, so lets just send each character
3418 if (c == STOP_CHAR(tty)) {
3419 dgap_cmdw(ch, RPAUSE, 0, 0);
3421 else if (c == START_CHAR(tty)) {
3422 dgap_cmdw(ch, RRESUME, 0, 0);
3425 dgap_wmove(ch, &c, 1);
3428 dgap_wmove(ch, &c, 1);
3431 DGAP_UNLOCK(ch->ch_lock, lock_flags2);
3432 DGAP_UNLOCK(bd->bd_lock, lock_flags);
3434 DPR_IOCTL(("dgap_tty_send_xchar finish\n"));
3443 * Return modem signals to ld.
3445 static int dgap_get_modem_info(struct channel_t *ch, unsigned int __user *value)
3452 DPR_IOCTL(("dgap_get_modem_info start\n"));
3454 if (!ch || ch->magic != DGAP_CHANNEL_MAGIC)
3457 DGAP_LOCK(ch->ch_lock, lock_flags);
3459 mstat = readb(&(ch->ch_bs->m_stat));
3460 /* Append any outbound signals that might be pending... */
3461 mstat |= ch->ch_mostat;
3463 DGAP_UNLOCK(ch->ch_lock, lock_flags);
3467 if (mstat & D_DTR(ch))
3468 result |= TIOCM_DTR;
3469 if (mstat & D_RTS(ch))
3470 result |= TIOCM_RTS;
3471 if (mstat & D_CTS(ch))
3472 result |= TIOCM_CTS;
3473 if (mstat & D_DSR(ch))
3474 result |= TIOCM_DSR;
3475 if (mstat & D_RI(ch))
3477 if (mstat & D_CD(ch))
3480 rc = put_user(result, value);
3482 DPR_IOCTL(("dgap_get_modem_info finish\n"));
3488 * dgap_set_modem_info()
3490 * Set modem signals, called by ld.
3492 static int dgap_set_modem_info(struct tty_struct *tty, unsigned int command, unsigned int __user *value)
3495 struct channel_t *ch;
3498 unsigned int arg = 0;
3502 if (!tty || tty->magic != TTY_MAGIC)
3505 un = tty->driver_data;
3506 if (!un || un->magic != DGAP_UNIT_MAGIC)
3510 if (!ch || ch->magic != DGAP_CHANNEL_MAGIC)
3514 if (!bd || bd->magic != DGAP_BOARD_MAGIC)
3517 DPR_IOCTL(("dgap_set_modem_info() start\n"));
3519 ret = get_user(arg, value);
3521 DPR_IOCTL(("dgap_set_modem_info %d ret: %x. finished.\n", __LINE__, ret));
3525 DPR_IOCTL(("dgap_set_modem_info: command: %x arg: %x\n", command, arg));
3529 if (arg & TIOCM_RTS) {
3530 ch->ch_mforce |= D_RTS(ch);
3531 ch->ch_mval |= D_RTS(ch);
3534 if (arg & TIOCM_DTR) {
3535 ch->ch_mforce |= D_DTR(ch);
3536 ch->ch_mval |= D_DTR(ch);
3542 if (arg & TIOCM_RTS) {
3543 ch->ch_mforce |= D_RTS(ch);
3544 ch->ch_mval &= ~(D_RTS(ch));
3547 if (arg & TIOCM_DTR) {
3548 ch->ch_mforce |= D_DTR(ch);
3549 ch->ch_mval &= ~(D_DTR(ch));
3555 ch->ch_mforce = D_DTR(ch)|D_RTS(ch);
3557 if (arg & TIOCM_RTS) {
3558 ch->ch_mval |= D_RTS(ch);
3561 ch->ch_mval &= ~(D_RTS(ch));
3564 if (arg & TIOCM_DTR) {
3565 ch->ch_mval |= (D_DTR(ch));
3568 ch->ch_mval &= ~(D_DTR(ch));
3577 DGAP_LOCK(bd->bd_lock, lock_flags);
3578 DGAP_LOCK(ch->ch_lock, lock_flags2);
3582 DGAP_UNLOCK(ch->ch_lock, lock_flags2);
3583 DGAP_UNLOCK(bd->bd_lock, lock_flags);
3585 DPR_IOCTL(("dgap_set_modem_info finish\n"));
3592 * dgap_tty_digigeta()
3594 * Ioctl to get the information for ditty.
3599 static int dgap_tty_digigeta(struct tty_struct *tty, struct digi_t __user *retinfo)
3601 struct channel_t *ch;
3609 if (!tty || tty->magic != TTY_MAGIC)
3612 un = tty->driver_data;
3613 if (!un || un->magic != DGAP_UNIT_MAGIC)
3617 if (!ch || ch->magic != DGAP_CHANNEL_MAGIC)
3620 memset(&tmp, 0, sizeof(tmp));
3622 DGAP_LOCK(ch->ch_lock, lock_flags);
3623 memcpy(&tmp, &ch->ch_digi, sizeof(tmp));
3624 DGAP_UNLOCK(ch->ch_lock, lock_flags);
3626 if (copy_to_user(retinfo, &tmp, sizeof(*retinfo)))
3634 * dgap_tty_digiseta()
3636 * Ioctl to set the information for ditty.
3641 static int dgap_tty_digiseta(struct tty_struct *tty, struct digi_t __user *new_info)
3644 struct channel_t *ch;
3646 struct digi_t new_digi;
3647 ulong lock_flags = 0;
3648 unsigned long lock_flags2;
3650 DPR_IOCTL(("DIGI_SETA start\n"));
3652 if (!tty || tty->magic != TTY_MAGIC)
3655 un = tty->driver_data;
3656 if (!un || un->magic != DGAP_UNIT_MAGIC)
3660 if (!ch || ch->magic != DGAP_CHANNEL_MAGIC)
3664 if (!bd || bd->magic != DGAP_BOARD_MAGIC)
3667 if (copy_from_user(&new_digi, new_info, sizeof(struct digi_t))) {
3668 DPR_IOCTL(("DIGI_SETA failed copy_from_user\n"));
3672 DGAP_LOCK(bd->bd_lock, lock_flags);
3673 DGAP_LOCK(ch->ch_lock, lock_flags2);
3675 memcpy(&ch->ch_digi, &new_digi, sizeof(struct digi_t));
3677 if (ch->ch_digi.digi_maxcps < 1)
3678 ch->ch_digi.digi_maxcps = 1;
3680 if (ch->ch_digi.digi_maxcps > 10000)
3681 ch->ch_digi.digi_maxcps = 10000;
3683 if (ch->ch_digi.digi_bufsize < 10)
3684 ch->ch_digi.digi_bufsize = 10;
3686 if (ch->ch_digi.digi_maxchar < 1)
3687 ch->ch_digi.digi_maxchar = 1;
3689 if (ch->ch_digi.digi_maxchar > ch->ch_digi.digi_bufsize)
3690 ch->ch_digi.digi_maxchar = ch->ch_digi.digi_bufsize;
3692 if (ch->ch_digi.digi_onlen > DIGI_PLEN)
3693 ch->ch_digi.digi_onlen = DIGI_PLEN;
3695 if (ch->ch_digi.digi_offlen > DIGI_PLEN)
3696 ch->ch_digi.digi_offlen = DIGI_PLEN;
3700 DGAP_UNLOCK(ch->ch_lock, lock_flags2);
3701 DGAP_UNLOCK(bd->bd_lock, lock_flags);
3703 DPR_IOCTL(("DIGI_SETA finish\n"));
3710 * dgap_tty_digigetedelay()
3712 * Ioctl to get the current edelay setting.
3717 static int dgap_tty_digigetedelay(struct tty_struct *tty, int __user *retinfo)
3719 struct channel_t *ch;
3727 if (!tty || tty->magic != TTY_MAGIC)
3730 un = tty->driver_data;
3731 if (!un || un->magic != DGAP_UNIT_MAGIC)
3735 if (!ch || ch->magic != DGAP_CHANNEL_MAGIC)
3738 memset(&tmp, 0, sizeof(tmp));
3740 DGAP_LOCK(ch->ch_lock, lock_flags);
3741 tmp = readw(&(ch->ch_bs->edelay));
3742 DGAP_UNLOCK(ch->ch_lock, lock_flags);
3744 if (copy_to_user(retinfo, &tmp, sizeof(*retinfo)))
3752 * dgap_tty_digisetedelay()
3754 * Ioctl to set the EDELAY setting
3757 static int dgap_tty_digisetedelay(struct tty_struct *tty, int __user *new_info)
3760 struct channel_t *ch;
3766 DPR_IOCTL(("DIGI_SETA start\n"));
3768 if (!tty || tty->magic != TTY_MAGIC)
3771 un = tty->driver_data;
3772 if (!un || un->magic != DGAP_UNIT_MAGIC)
3776 if (!ch || ch->magic != DGAP_CHANNEL_MAGIC)
3780 if (!bd || bd->magic != DGAP_BOARD_MAGIC)
3783 if (copy_from_user(&new_digi, new_info, sizeof(int))) {
3784 DPR_IOCTL(("DIGI_SETEDELAY failed copy_from_user\n"));
3788 DGAP_LOCK(bd->bd_lock, lock_flags);
3789 DGAP_LOCK(ch->ch_lock, lock_flags2);
3791 writew((u16) new_digi, &(ch->ch_bs->edelay));
3795 DGAP_UNLOCK(ch->ch_lock, lock_flags2);
3796 DGAP_UNLOCK(bd->bd_lock, lock_flags);
3798 DPR_IOCTL(("DIGI_SETA finish\n"));
3805 * dgap_tty_digigetcustombaud()
3807 * Ioctl to get the current custom baud rate setting.
3809 static int dgap_tty_digigetcustombaud(struct tty_struct *tty, int __user *retinfo)
3811 struct channel_t *ch;
3819 if (!tty || tty->magic != TTY_MAGIC)
3822 un = tty->driver_data;
3823 if (!un || un->magic != DGAP_UNIT_MAGIC)
3827 if (!ch || ch->magic != DGAP_CHANNEL_MAGIC)
3830 memset(&tmp, 0, sizeof(tmp));
3832 DGAP_LOCK(ch->ch_lock, lock_flags);
3833 tmp = dgap_get_custom_baud(ch);
3834 DGAP_UNLOCK(ch->ch_lock, lock_flags);
3836 DPR_IOCTL(("DIGI_GETCUSTOMBAUD. Returning %d\n", tmp));
3838 if (copy_to_user(retinfo, &tmp, sizeof(*retinfo)))
3846 * dgap_tty_digisetcustombaud()
3848 * Ioctl to set the custom baud rate setting
3850 static int dgap_tty_digisetcustombaud(struct tty_struct *tty, int __user *new_info)
3853 struct channel_t *ch;
3859 DPR_IOCTL(("DIGI_SETCUSTOMBAUD start\n"));
3861 if (!tty || tty->magic != TTY_MAGIC)
3864 un = tty->driver_data;
3865 if (!un || un->magic != DGAP_UNIT_MAGIC)
3869 if (!ch || ch->magic != DGAP_CHANNEL_MAGIC)
3873 if (!bd || bd->magic != DGAP_BOARD_MAGIC)
3877 if (copy_from_user(&new_rate, new_info, sizeof(unsigned int))) {
3878 DPR_IOCTL(("DIGI_SETCUSTOMBAUD failed copy_from_user\n"));
3882 if (bd->bd_flags & BD_FEP5PLUS) {
3884 DPR_IOCTL(("DIGI_SETCUSTOMBAUD. Setting %d\n", new_rate));
3886 DGAP_LOCK(bd->bd_lock, lock_flags);
3887 DGAP_LOCK(ch->ch_lock, lock_flags2);
3889 ch->ch_custom_speed = new_rate;
3893 DGAP_UNLOCK(ch->ch_lock, lock_flags2);
3894 DGAP_UNLOCK(bd->bd_lock, lock_flags);
3897 DPR_IOCTL(("DIGI_SETCUSTOMBAUD finish\n"));
3904 * dgap_set_termios()
3906 static void dgap_tty_set_termios(struct tty_struct *tty, struct ktermios *old_termios)
3909 struct channel_t *ch;
3911 unsigned long lock_flags;
3912 unsigned long lock_flags2;
3914 if (!tty || tty->magic != TTY_MAGIC)
3917 un = tty->driver_data;
3918 if (!un || un->magic != DGAP_UNIT_MAGIC)
3922 if (!ch || ch->magic != DGAP_CHANNEL_MAGIC)
3926 if (!bd || bd->magic != DGAP_BOARD_MAGIC)
3929 DGAP_LOCK(bd->bd_lock, lock_flags);
3930 DGAP_LOCK(ch->ch_lock, lock_flags2);
3932 ch->ch_c_cflag = tty->termios.c_cflag;
3933 ch->ch_c_iflag = tty->termios.c_iflag;
3934 ch->ch_c_oflag = tty->termios.c_oflag;
3935 ch->ch_c_lflag = tty->termios.c_lflag;
3936 ch->ch_startc = tty->termios.c_cc[VSTART];
3937 ch->ch_stopc = tty->termios.c_cc[VSTOP];
3942 DGAP_UNLOCK(ch->ch_lock, lock_flags2);
3943 DGAP_UNLOCK(bd->bd_lock, lock_flags);
3947 static void dgap_tty_throttle(struct tty_struct *tty)
3950 struct channel_t *ch;
3955 if (!tty || tty->magic != TTY_MAGIC)
3958 un = tty->driver_data;
3959 if (!un || un->magic != DGAP_UNIT_MAGIC)
3963 if (!ch || ch->magic != DGAP_CHANNEL_MAGIC)
3967 if (!bd || bd->magic != DGAP_BOARD_MAGIC)
3970 DPR_IOCTL(("dgap_tty_throttle start\n"));
3972 DGAP_LOCK(bd->bd_lock, lock_flags);
3973 DGAP_LOCK(ch->ch_lock, lock_flags2);
3975 ch->ch_flags |= (CH_RXBLOCK);
3977 dgap_cmdw(ch, RPAUSE, 0, 0);
3980 DGAP_UNLOCK(ch->ch_lock, lock_flags2);
3981 DGAP_UNLOCK(bd->bd_lock, lock_flags);
3983 DPR_IOCTL(("dgap_tty_throttle finish\n"));
3987 static void dgap_tty_unthrottle(struct tty_struct *tty)
3990 struct channel_t *ch;
3995 if (!tty || tty->magic != TTY_MAGIC)
3998 un = tty->driver_data;
3999 if (!un || un->magic != DGAP_UNIT_MAGIC)
4003 if (!ch || ch->magic != DGAP_CHANNEL_MAGIC)
4007 if (!bd || bd->magic != DGAP_BOARD_MAGIC)
4010 DPR_IOCTL(("dgap_tty_unthrottle start\n"));
4012 DGAP_LOCK(bd->bd_lock, lock_flags);
4013 DGAP_LOCK(ch->ch_lock, lock_flags2);
4015 ch->ch_flags &= ~(CH_RXBLOCK);
4018 dgap_cmdw(ch, RRESUME, 0, 0);
4021 DGAP_UNLOCK(ch->ch_lock, lock_flags2);
4022 DGAP_UNLOCK(bd->bd_lock, lock_flags);
4024 DPR_IOCTL(("dgap_tty_unthrottle finish\n"));
4028 static void dgap_tty_start(struct tty_struct *tty)
4031 struct channel_t *ch;
4036 if (!tty || tty->magic != TTY_MAGIC)
4039 un = tty->driver_data;
4040 if (!un || un->magic != DGAP_UNIT_MAGIC)
4044 if (!ch || ch->magic != DGAP_CHANNEL_MAGIC)
4048 if (!bd || bd->magic != DGAP_BOARD_MAGIC)
4051 DPR_IOCTL(("dgap_tty_start start\n"));
4053 DGAP_LOCK(bd->bd_lock, lock_flags);
4054 DGAP_LOCK(ch->ch_lock, lock_flags2);
4056 dgap_cmdw(ch, RESUMETX, 0, 0);
4058 DGAP_UNLOCK(ch->ch_lock, lock_flags2);
4059 DGAP_UNLOCK(bd->bd_lock, lock_flags);
4061 DPR_IOCTL(("dgap_tty_start finish\n"));
4065 static void dgap_tty_stop(struct tty_struct *tty)
4068 struct channel_t *ch;
4073 if (!tty || tty->magic != TTY_MAGIC)
4076 un = tty->driver_data;
4077 if (!un || un->magic != DGAP_UNIT_MAGIC)
4081 if (!ch || ch->magic != DGAP_CHANNEL_MAGIC)
4085 if (!bd || bd->magic != DGAP_BOARD_MAGIC)
4088 DPR_IOCTL(("dgap_tty_stop start\n"));
4090 DGAP_LOCK(bd->bd_lock, lock_flags);
4091 DGAP_LOCK(ch->ch_lock, lock_flags2);
4093 dgap_cmdw(ch, PAUSETX, 0, 0);
4095 DGAP_UNLOCK(ch->ch_lock, lock_flags2);
4096 DGAP_UNLOCK(bd->bd_lock, lock_flags);
4098 DPR_IOCTL(("dgap_tty_stop finish\n"));
4103 * dgap_tty_flush_chars()
4105 * Flush the cook buffer
4107 * Note to self, and any other poor souls who venture here:
4109 * flush in this case DOES NOT mean dispose of the data.
4110 * instead, it means "stop buffering and send it if you
4111 * haven't already." Just guess how I figured that out... SRW 2-Jun-98
4113 * It is also always called in interrupt context - JAR 8-Sept-99
4115 static void dgap_tty_flush_chars(struct tty_struct *tty)
4118 struct channel_t *ch;
4123 if (!tty || tty->magic != TTY_MAGIC)
4126 un = tty->driver_data;
4127 if (!un || un->magic != DGAP_UNIT_MAGIC)
4131 if (!ch || ch->magic != DGAP_CHANNEL_MAGIC)
4135 if (!bd || bd->magic != DGAP_BOARD_MAGIC)
4138 DPR_IOCTL(("dgap_tty_flush_chars start\n"));
4140 DGAP_LOCK(bd->bd_lock, lock_flags);
4141 DGAP_LOCK(ch->ch_lock, lock_flags2);
4143 /* TODO: Do something here */
4145 DGAP_UNLOCK(ch->ch_lock, lock_flags2);
4146 DGAP_UNLOCK(bd->bd_lock, lock_flags);
4148 DPR_IOCTL(("dgap_tty_flush_chars finish\n"));
4154 * dgap_tty_flush_buffer()
4156 * Flush Tx buffer (make in == out)
4158 static void dgap_tty_flush_buffer(struct tty_struct *tty)
4161 struct channel_t *ch;
4167 if (!tty || tty->magic != TTY_MAGIC)
4170 un = tty->driver_data;
4171 if (!un || un->magic != DGAP_UNIT_MAGIC)
4175 if (!ch || ch->magic != DGAP_CHANNEL_MAGIC)
4179 if (!bd || bd->magic != DGAP_BOARD_MAGIC)
4182 DPR_IOCTL(("dgap_tty_flush_buffer on port: %d start\n", ch->ch_portnum));
4184 DGAP_LOCK(bd->bd_lock, lock_flags);
4185 DGAP_LOCK(ch->ch_lock, lock_flags2);
4187 ch->ch_flags &= ~CH_STOP;
4188 head = readw(&(ch->ch_bs->tx_head));
4189 dgap_cmdw(ch, FLUSHTX, (u16) head, 0);
4190 dgap_cmdw(ch, RESUMETX, 0, 0);
4191 if (ch->ch_tun.un_flags & (UN_LOW|UN_EMPTY)) {
4192 ch->ch_tun.un_flags &= ~(UN_LOW|UN_EMPTY);
4193 wake_up_interruptible(&ch->ch_tun.un_flags_wait);
4195 if (ch->ch_pun.un_flags & (UN_LOW|UN_EMPTY)) {
4196 ch->ch_pun.un_flags &= ~(UN_LOW|UN_EMPTY);
4197 wake_up_interruptible(&ch->ch_pun.un_flags_wait);
4200 DGAP_UNLOCK(ch->ch_lock, lock_flags2);
4201 DGAP_UNLOCK(bd->bd_lock, lock_flags);
4202 if (waitqueue_active(&tty->write_wait))
4203 wake_up_interruptible(&tty->write_wait);
4206 DPR_IOCTL(("dgap_tty_flush_buffer finish\n"));
4211 /*****************************************************************************
4213 * The IOCTL function and all of its helpers
4215 *****************************************************************************/
4220 * The usual assortment of ioctl's
4222 static int dgap_tty_ioctl(struct tty_struct *tty, unsigned int cmd,
4226 struct channel_t *ch;
4230 ulong lock_flags = 0;
4231 ulong lock_flags2 = 0;
4232 void __user *uarg = (void __user *) arg;
4234 if (!tty || tty->magic != TTY_MAGIC)
4237 un = tty->driver_data;
4238 if (!un || un->magic != DGAP_UNIT_MAGIC)
4242 if (!ch || ch->magic != DGAP_CHANNEL_MAGIC)
4246 if (!bd || bd->magic != DGAP_BOARD_MAGIC)
4249 DPR_IOCTL(("dgap_tty_ioctl start on port %d - cmd %s (%x), arg %lx\n",
4250 ch->ch_portnum, dgap_ioctl_name(cmd), cmd, arg));
4252 DGAP_LOCK(bd->bd_lock, lock_flags);
4253 DGAP_LOCK(ch->ch_lock, lock_flags2);
4255 if (un->un_open_count <= 0) {
4256 DPR_BASIC(("dgap_tty_ioctl - unit not open.\n"));
4257 DGAP_UNLOCK(ch->ch_lock, lock_flags2);
4258 DGAP_UNLOCK(bd->bd_lock, lock_flags);
4264 /* Here are all the standard ioctl's that we MUST implement */
4268 * TCSBRK is SVID version: non-zero arg --> no break
4269 * this behaviour is exploited by tcdrain().
4271 * According to POSIX.1 spec (7.2.2.1.2) breaks should be
4272 * between 0.25 and 0.5 seconds so we'll ask for something
4273 * in the middle: 0.375 seconds.
4275 rc = tty_check_change(tty);
4276 DGAP_UNLOCK(ch->ch_lock, lock_flags2);
4277 DGAP_UNLOCK(bd->bd_lock, lock_flags);
4282 rc = dgap_wait_for_drain(tty);
4285 DPR_IOCTL(("dgap_tty_ioctl - bad return: %d ", rc));
4289 DGAP_LOCK(bd->bd_lock, lock_flags);
4290 DGAP_LOCK(ch->ch_lock, lock_flags2);
4292 if(((cmd == TCSBRK) && (!arg)) || (cmd == TCSBRKP)) {
4293 dgap_cmdw(ch, SBREAK, (u16) SBREAK_TIME, 0);
4296 DGAP_UNLOCK(ch->ch_lock, lock_flags2);
4297 DGAP_UNLOCK(bd->bd_lock, lock_flags);
4299 DPR_IOCTL(("dgap_tty_ioctl finish on port %d - cmd %s (%x), arg %lx\n",
4300 ch->ch_portnum, dgap_ioctl_name(cmd), cmd, arg));
4306 /* support for POSIX tcsendbreak()
4308 * According to POSIX.1 spec (7.2.2.1.2) breaks should be
4309 * between 0.25 and 0.5 seconds so we'll ask for something
4310 * in the middle: 0.375 seconds.
4312 rc = tty_check_change(tty);
4313 DGAP_UNLOCK(ch->ch_lock, lock_flags2);
4314 DGAP_UNLOCK(bd->bd_lock, lock_flags);
4319 rc = dgap_wait_for_drain(tty);
4321 DPR_IOCTL(("dgap_tty_ioctl - bad return: %d ", rc));
4325 DGAP_LOCK(bd->bd_lock, lock_flags);
4326 DGAP_LOCK(ch->ch_lock, lock_flags2);
4328 dgap_cmdw(ch, SBREAK, (u16) SBREAK_TIME, 0);
4330 DGAP_UNLOCK(ch->ch_lock, lock_flags2);
4331 DGAP_UNLOCK(bd->bd_lock, lock_flags);
4333 DPR_IOCTL(("dgap_tty_ioctl finish on port %d - cmd %s (%x), arg %lx\n",
4334 ch->ch_portnum, dgap_ioctl_name(cmd), cmd, arg));
4340 * FEP5 doesn't support turning on a break unconditionally.
4341 * The FEP5 device will stop sending a break automatically
4342 * after the specified time value that was sent when turning on
4345 rc = tty_check_change(tty);
4346 DGAP_UNLOCK(ch->ch_lock, lock_flags2);
4347 DGAP_UNLOCK(bd->bd_lock, lock_flags);
4352 rc = dgap_wait_for_drain(tty);
4354 DPR_IOCTL(("dgap_tty_ioctl - bad return: %d ", rc));
4358 DGAP_LOCK(bd->bd_lock, lock_flags);
4359 DGAP_LOCK(ch->ch_lock, lock_flags2);
4361 dgap_cmdw(ch, SBREAK, (u16) SBREAK_TIME, 0);
4363 DGAP_UNLOCK(ch->ch_lock, lock_flags2);
4364 DGAP_UNLOCK(bd->bd_lock, lock_flags);
4366 DPR_IOCTL(("dgap_tty_ioctl finish on port %d - cmd %s (%x), arg %lx\n",
4367 ch->ch_portnum, dgap_ioctl_name(cmd), cmd, arg));
4373 * FEP5 doesn't support turning off a break unconditionally.
4374 * The FEP5 device will stop sending a break automatically
4375 * after the specified time value that was sent when turning on
4378 DGAP_UNLOCK(ch->ch_lock, lock_flags2);
4379 DGAP_UNLOCK(bd->bd_lock, lock_flags);
4384 DGAP_UNLOCK(ch->ch_lock, lock_flags2);
4385 DGAP_UNLOCK(bd->bd_lock, lock_flags);
4387 rc = put_user(C_CLOCAL(tty) ? 1 : 0, (unsigned long __user *) arg);
4391 DGAP_UNLOCK(ch->ch_lock, lock_flags2);
4392 DGAP_UNLOCK(bd->bd_lock, lock_flags);
4394 rc = get_user(arg, (unsigned long __user *) arg);
4398 DGAP_LOCK(bd->bd_lock, lock_flags);
4399 DGAP_LOCK(ch->ch_lock, lock_flags2);
4400 tty->termios.c_cflag = ((tty->termios.c_cflag & ~CLOCAL) | (arg ? CLOCAL : 0));
4402 DGAP_UNLOCK(ch->ch_lock, lock_flags2);
4403 DGAP_UNLOCK(bd->bd_lock, lock_flags);
4408 DGAP_UNLOCK(ch->ch_lock, lock_flags2);
4409 DGAP_UNLOCK(bd->bd_lock, lock_flags);
4410 return(dgap_get_modem_info(ch, uarg));
4415 DGAP_UNLOCK(ch->ch_lock, lock_flags2);
4416 DGAP_UNLOCK(bd->bd_lock, lock_flags);
4417 return(dgap_set_modem_info(tty, cmd, uarg));
4420 * Here are any additional ioctl's that we want to implement
4425 * The linux tty driver doesn't have a flush
4426 * input routine for the driver, assuming all backed
4427 * up data is in the line disc. buffers. However,
4428 * we all know that's not the case. Here, we
4429 * act on the ioctl, but then lie and say we didn't
4430 * so the line discipline will process the flush
4433 rc = tty_check_change(tty);
4435 DGAP_UNLOCK(ch->ch_lock, lock_flags2);
4436 DGAP_UNLOCK(bd->bd_lock, lock_flags);
4440 if ((arg == TCIFLUSH) || (arg == TCIOFLUSH)) {
4441 if (!(un->un_type == DGAP_PRINT)) {
4442 head = readw(&(ch->ch_bs->rx_head));
4443 writew(head, &(ch->ch_bs->rx_tail));
4444 writeb(0, &(ch->ch_bs->orun));
4448 if ((arg == TCOFLUSH) || (arg == TCIOFLUSH)) {
4449 ch->ch_flags &= ~CH_STOP;
4450 head = readw(&(ch->ch_bs->tx_head));
4451 dgap_cmdw(ch, FLUSHTX, (u16) head, 0 );
4452 dgap_cmdw(ch, RESUMETX, 0, 0);
4453 if (ch->ch_tun.un_flags & (UN_LOW|UN_EMPTY)) {
4454 ch->ch_tun.un_flags &= ~(UN_LOW|UN_EMPTY);
4455 wake_up_interruptible(&ch->ch_tun.un_flags_wait);
4457 if (ch->ch_pun.un_flags & (UN_LOW|UN_EMPTY)) {
4458 ch->ch_pun.un_flags &= ~(UN_LOW|UN_EMPTY);
4459 wake_up_interruptible(&ch->ch_pun.un_flags_wait);
4461 if (waitqueue_active(&tty->write_wait))
4462 wake_up_interruptible(&tty->write_wait);
4464 /* Can't hold any locks when calling tty_wakeup! */
4465 DGAP_UNLOCK(ch->ch_lock, lock_flags2);
4466 DGAP_UNLOCK(bd->bd_lock, lock_flags);
4468 DGAP_LOCK(bd->bd_lock, lock_flags);
4469 DGAP_LOCK(ch->ch_lock, lock_flags2);
4472 /* pretend we didn't recognize this IOCTL */
4473 DGAP_UNLOCK(ch->ch_lock, lock_flags2);
4474 DGAP_UNLOCK(bd->bd_lock, lock_flags);
4476 DPR_IOCTL(("dgap_tty_ioctl (LINE:%d) finish on port %d - cmd %s (%x), arg %lx\n",
4477 __LINE__, ch->ch_portnum, dgap_ioctl_name(cmd), cmd, arg));
4479 return(-ENOIOCTLCMD);
4484 * The linux tty driver doesn't have a flush
4485 * input routine for the driver, assuming all backed
4486 * up data is in the line disc. buffers. However,
4487 * we all know that's not the case. Here, we
4488 * act on the ioctl, but then lie and say we didn't
4489 * so the line discipline will process the flush
4492 if (cmd == TCSETSF) {
4494 ch->ch_flags &= ~CH_STOP;
4495 head = readw(&(ch->ch_bs->rx_head));
4496 writew(head, &(ch->ch_bs->rx_tail));
4499 /* now wait for all the output to drain */
4500 DGAP_UNLOCK(ch->ch_lock, lock_flags2);
4501 DGAP_UNLOCK(bd->bd_lock, lock_flags);
4502 rc = dgap_wait_for_drain(tty);
4504 DPR_IOCTL(("dgap_tty_ioctl - bad return: %d ", rc));
4508 DPR_IOCTL(("dgap_tty_ioctl finish on port %d - cmd %s (%x), arg %lx\n",
4509 ch->ch_portnum, dgap_ioctl_name(cmd), cmd, arg));
4511 /* pretend we didn't recognize this */
4512 return(-ENOIOCTLCMD);
4516 DGAP_UNLOCK(ch->ch_lock, lock_flags2);
4517 DGAP_UNLOCK(bd->bd_lock, lock_flags);
4518 rc = dgap_wait_for_drain(tty);
4520 DPR_IOCTL(("dgap_tty_ioctl - bad return: %d ", rc));
4524 /* pretend we didn't recognize this */
4525 return(-ENOIOCTLCMD);
4529 * The Linux Line Discipline (LD) would do this for us if we
4530 * let it, but we have the special firmware options to do this
4531 * the "right way" regardless of hardware or software flow
4532 * control so we'll do it outselves instead of letting the LD
4535 rc = tty_check_change(tty);
4537 DGAP_UNLOCK(ch->ch_lock, lock_flags2);
4538 DGAP_UNLOCK(bd->bd_lock, lock_flags);
4542 DPR_IOCTL(("dgap_ioctl - in TCXONC - %d\n", cmd));
4546 DGAP_UNLOCK(ch->ch_lock, lock_flags2);
4547 DGAP_UNLOCK(bd->bd_lock, lock_flags);
4548 dgap_tty_start(tty);
4551 DGAP_UNLOCK(ch->ch_lock, lock_flags2);
4552 DGAP_UNLOCK(bd->bd_lock, lock_flags);
4556 DGAP_UNLOCK(ch->ch_lock, lock_flags2);
4557 DGAP_UNLOCK(bd->bd_lock, lock_flags);
4558 /* Make the ld do it */
4559 return(-ENOIOCTLCMD);
4561 DGAP_UNLOCK(ch->ch_lock, lock_flags2);
4562 DGAP_UNLOCK(bd->bd_lock, lock_flags);
4563 /* Make the ld do it */
4564 return(-ENOIOCTLCMD);
4566 DGAP_UNLOCK(ch->ch_lock, lock_flags2);
4567 DGAP_UNLOCK(bd->bd_lock, lock_flags);
4572 /* get information for ditty */
4573 DGAP_UNLOCK(ch->ch_lock, lock_flags2);
4574 DGAP_UNLOCK(bd->bd_lock, lock_flags);
4575 return(dgap_tty_digigeta(tty, uarg));
4580 /* set information for ditty */
4581 if (cmd == (DIGI_SETAW)) {
4583 DGAP_UNLOCK(ch->ch_lock, lock_flags2);
4584 DGAP_UNLOCK(bd->bd_lock, lock_flags);
4585 rc = dgap_wait_for_drain(tty);
4587 DPR_IOCTL(("dgap_tty_ioctl - bad return: %d ", rc));
4590 DGAP_LOCK(bd->bd_lock, lock_flags);
4591 DGAP_LOCK(ch->ch_lock, lock_flags2);
4594 tty_ldisc_flush(tty);
4599 DGAP_UNLOCK(ch->ch_lock, lock_flags2);
4600 DGAP_UNLOCK(bd->bd_lock, lock_flags);
4601 return(dgap_tty_digiseta(tty, uarg));
4604 DGAP_UNLOCK(ch->ch_lock, lock_flags2);
4605 DGAP_UNLOCK(bd->bd_lock, lock_flags);
4606 return(dgap_tty_digigetedelay(tty, uarg));
4609 DGAP_UNLOCK(ch->ch_lock, lock_flags2);
4610 DGAP_UNLOCK(bd->bd_lock, lock_flags);
4611 return(dgap_tty_digisetedelay(tty, uarg));
4613 case DIGI_GETCUSTOMBAUD:
4614 DGAP_UNLOCK(ch->ch_lock, lock_flags2);
4615 DGAP_UNLOCK(bd->bd_lock, lock_flags);
4616 return(dgap_tty_digigetcustombaud(tty, uarg));
4618 case DIGI_SETCUSTOMBAUD:
4619 DGAP_UNLOCK(ch->ch_lock, lock_flags2);
4620 DGAP_UNLOCK(bd->bd_lock, lock_flags);
4621 return(dgap_tty_digisetcustombaud(tty, uarg));
4623 case DIGI_RESET_PORT:
4624 dgap_firmware_reset_port(ch);
4626 DGAP_UNLOCK(ch->ch_lock, lock_flags2);
4627 DGAP_UNLOCK(bd->bd_lock, lock_flags);
4631 DGAP_UNLOCK(ch->ch_lock, lock_flags2);
4632 DGAP_UNLOCK(bd->bd_lock, lock_flags);
4634 DPR_IOCTL(("dgap_tty_ioctl - in default\n"));
4635 DPR_IOCTL(("dgap_tty_ioctl end - cmd %s (%x), arg %lx\n",
4636 dgap_ioctl_name(cmd), cmd, arg));
4638 return(-ENOIOCTLCMD);
4642 * Loads the dgap.conf config file from the user.
4644 void dgap_do_config_load(uchar __user *uaddr, int len)
4648 uchar __user *from_addr = uaddr;
4652 to_addr = dgap_config_buf = kzalloc(len + 1, GFP_ATOMIC);
4653 if (!dgap_config_buf) {
4654 DPR_INIT(("dgap_do_config_load - unable to allocate memory for file\n"));
4655 dgap_driver_state = DRIVER_NEED_CONFIG_LOAD;
4665 if (copy_from_user((char *) &buf, from_addr, n) == -1 )
4668 /* Copy data from buffer to kernel memory */
4669 memcpy(to_addr, buf, n);
4671 /* increment counts */
4678 dgap_config_buf[orig_len] = '\0';
4680 to_addr = dgap_config_buf;
4681 dgap_parsefile(&to_addr, TRUE);
4683 DPR_INIT(("dgap_config_load() finish\n"));
4689 int dgap_after_config_loaded(void)
4695 * Register our ttys, now that we have the config loaded.
4697 for (i = 0; i < dgap_NumBoards; ++i) {
4700 * Initialize KME waitqueues...
4702 init_waitqueue_head(&(dgap_Board[i]->kme_wait));
4705 * allocate flip buffer for board.
4707 dgap_Board[i]->flipbuf = kzalloc(MYFLIPLEN, GFP_ATOMIC);
4708 dgap_Board[i]->flipflagbuf = kzalloc(MYFLIPLEN, GFP_ATOMIC);
4716 /*=======================================================================
4718 * usertoboard - copy from user space to board space.
4720 *=======================================================================*/
4721 static int dgap_usertoboard(struct board_t *brd, char *to_addr, char __user *from_addr, int len)
4726 if (!brd || brd->magic != DGAP_BOARD_MAGIC)
4733 if (copy_from_user((char *) &buf, from_addr, n) == -1 ) {
4737 /* Copy data from buffer to card memory */
4738 memcpy_toio(to_addr, buf, n);
4740 /* increment counts */
4751 * Copies the BIOS code from the user to the board,
4752 * and starts the BIOS running.
4754 void dgap_do_bios_load(struct board_t *brd, uchar __user *ubios, int len)
4760 if (!brd || (brd->magic != DGAP_BOARD_MAGIC) || !brd->re_map_membase)
4763 DPR_INIT(("dgap_do_bios_load() start\n"));
4765 addr = brd->re_map_membase;
4770 for (i = 0; i < 16; i++)
4771 writeb(0, addr + POSTAREA + i);
4777 if (dgap_usertoboard(brd, addr + offset, ubios, len) == -1 ) {
4778 brd->state = BOARD_FAILED;
4779 brd->dpastatus = BD_NOFEP;
4783 writel(0x0bf00401, addr);
4784 writel(0, (addr + 4));
4786 /* Clear the reset, and change states. */
4787 writeb(FEPCLR, brd->re_map_port);
4788 brd->state = WAIT_BIOS_LOAD;
4793 * Checks to see if the BIOS completed running on the card.
4795 static void dgap_do_wait_for_bios(struct board_t *brd)
4800 if (!brd || (brd->magic != DGAP_BOARD_MAGIC) || !brd->re_map_membase)
4803 addr = brd->re_map_membase;
4804 word = readw(addr + POSTAREA);
4806 /* Check to see if BIOS thinks board is good. (GD). */
4807 if (word == *(u16 *) "GD") {
4808 DPR_INIT(("GOT GD in memory, moving states.\n"));
4809 brd->state = FINISHED_BIOS_LOAD;
4813 /* Give up on board after too long of time taken */
4814 if (brd->wait_for_bios++ > 5000) {
4815 u16 err1 = readw(addr + SEQUENCE);
4816 u16 err2 = readw(addr + ERROR);
4817 APR(("***WARNING*** %s failed diagnostics. Error #(%x,%x).\n",
4818 brd->name, err1, err2));
4819 brd->state = BOARD_FAILED;
4820 brd->dpastatus = BD_NOFEP;
4826 * Copies the FEP code from the user to the board,
4827 * and starts the FEP running.
4829 void dgap_do_fep_load(struct board_t *brd, uchar __user *ufep, int len)
4834 if (!brd || (brd->magic != DGAP_BOARD_MAGIC) || !brd->re_map_membase)
4837 addr = brd->re_map_membase;
4839 DPR_INIT(("dgap_do_fep_load() for board %s : start\n", brd->name));
4845 if (dgap_usertoboard(brd, addr + offset, ufep, len) == -1 ) {
4846 brd->state = BOARD_FAILED;
4847 brd->dpastatus = BD_NOFEP;
4852 * If board is a concentrator product, we need to give
4853 * it its config string describing how the concentrators look.
4855 if ((brd->type == PCX) || (brd->type == PEPC)) {
4857 uchar *config, *xconfig;
4860 xconfig = dgap_create_config_string(brd, string);
4862 /* Write string to board memory */
4863 config = addr + CONFIG;
4864 for (; i < CONFIGSIZE; i++, config++, xconfig++) {
4865 writeb(*xconfig, config);
4866 if ((*xconfig & 0xff) == 0xff)
4871 writel(0xbfc01004, (addr + 0xc34));
4872 writel(0x3, (addr + 0xc30));
4874 /* change states. */
4875 brd->state = WAIT_FEP_LOAD;
4877 DPR_INIT(("dgap_do_fep_load() for board %s : finish\n", brd->name));
4883 * Waits for the FEP to report thats its ready for us to use.
4885 static void dgap_do_wait_for_fep(struct board_t *brd)
4890 if (!brd || (brd->magic != DGAP_BOARD_MAGIC) || !brd->re_map_membase)
4893 addr = brd->re_map_membase;
4895 DPR_INIT(("dgap_do_wait_for_fep() for board %s : start. addr: %p\n", brd->name, addr));
4897 word = readw(addr + FEPSTAT);
4899 /* Check to see if FEP is up and running now. */
4900 if (word == *(u16 *) "OS") {
4901 DPR_INIT(("GOT OS in memory for board %s, moving states.\n", brd->name));
4902 brd->state = FINISHED_FEP_LOAD;
4905 * Check to see if the board can support FEP5+ commands.
4907 word = readw(addr + FEP5_PLUS);
4908 if (word == *(u16 *) "5A") {
4909 DPR_INIT(("GOT 5A in memory for board %s, board supports extended FEP5 commands.\n", brd->name));
4910 brd->bd_flags |= BD_FEP5PLUS;
4916 /* Give up on board after too long of time taken */
4917 if (brd->wait_for_fep++ > 5000) {
4918 u16 err1 = readw(addr + SEQUENCE);
4919 u16 err2 = readw(addr + ERROR);
4920 APR(("***WARNING*** FEPOS for %s not functioning. Error #(%x,%x).\n",
4921 brd->name, err1, err2));
4922 brd->state = BOARD_FAILED;
4923 brd->dpastatus = BD_NOFEP;
4926 DPR_INIT(("dgap_do_wait_for_fep() for board %s : finish\n", brd->name));
4931 * Physically forces the FEP5 card to reset itself.
4933 static void dgap_do_reset_board(struct board_t *brd)
4940 if (!brd || (brd->magic != DGAP_BOARD_MAGIC) || !brd->re_map_membase || !brd->re_map_port) {
4941 DPR_INIT(("dgap_do_reset_board() start. bad values. brd: %p mem: %p io: %p\n",
4942 brd, brd ? brd->re_map_membase : 0, brd ? brd->re_map_port : 0));
4946 DPR_INIT(("dgap_do_reset_board() start. io: %p\n", brd->re_map_port));
4948 /* FEPRST does not vary among supported boards */
4949 writeb(FEPRST, brd->re_map_port);
4951 for (i = 0; i <= 1000; i++) {
4952 check = readb(brd->re_map_port) & 0xe;
4953 if (check == FEPRST)
4959 APR(("*** WARNING *** Board not resetting... Failing board.\n"));
4960 brd->state = BOARD_FAILED;
4961 brd->dpastatus = BD_NOFEP;
4966 * Make sure there really is memory out there.
4968 writel(0xa55a3cc3, (brd->re_map_membase + LOWMEM));
4969 writel(0x5aa5c33c, (brd->re_map_membase + HIGHMEM));
4970 check1 = readl(brd->re_map_membase + LOWMEM);
4971 check2 = readl(brd->re_map_membase + HIGHMEM);
4973 if ((check1 != 0xa55a3cc3) || (check2 != 0x5aa5c33c)) {
4974 APR(("*** Warning *** No memory at %p for board.\n", brd->re_map_membase));
4975 brd->state = BOARD_FAILED;
4976 brd->dpastatus = BD_NOFEP;
4980 if (brd->state != BOARD_FAILED)
4981 brd->state = FINISHED_RESET;
4984 DPR_INIT(("dgap_do_reset_board() finish\n"));
4989 * Sends a concentrator image into the FEP5 board.
4991 void dgap_do_conc_load(struct board_t *brd, uchar *uaddr, int len)
4995 struct downld_t *to_dp;
4997 if (!brd || (brd->magic != DGAP_BOARD_MAGIC) || !brd->re_map_membase)
5000 vaddr = brd->re_map_membase;
5002 offset = readw((u16 *) (vaddr + DOWNREQ));
5003 to_dp = (struct downld_t *) (vaddr + (int) offset);
5006 * The image was already read into kernel space,
5007 * we do NOT need a user space read here
5009 memcpy_toio((char *) to_dp, uaddr, sizeof(struct downld_t));
5011 /* Tell card we have data for it */
5012 writew(0, vaddr + (DOWNREQ));
5014 brd->conc_dl_status = NO_PENDING_CONCENTRATOR_REQUESTS;
5018 #define EXPANSION_ROM_SIZE (64 * 1024)
5019 #define FEP5_ROM_MAGIC (0xFEFFFFFF)
5021 static void dgap_get_vpd(struct board_t *brd)
5033 * Poke the magic number at the PCI Rom Address location.
5034 * If VPD is supported, the value read from that address
5037 magic = FEP5_ROM_MAGIC;
5038 pci_write_config_dword(brd->pdev, PCI_ROM_ADDRESS, magic);
5039 pci_read_config_dword(brd->pdev, PCI_ROM_ADDRESS, &magic);
5041 /* VPD not supported, bail */
5046 * To get to the OTPROM memory, we have to send the boards base
5047 * address or'ed with 1 into the PCI Rom Address location.
5049 magic = brd->membase | 0x01;
5050 pci_write_config_dword(brd->pdev, PCI_ROM_ADDRESS, magic);
5051 pci_read_config_dword(brd->pdev, PCI_ROM_ADDRESS, &magic);
5053 byte1 = readb(brd->re_map_membase);
5054 byte2 = readb(brd->re_map_membase + 1);
5057 * If the board correctly swapped to the OTPROM memory,
5058 * the first 2 bytes (header) should be 0x55, 0xAA
5060 if (byte1 == 0x55 && byte2 == 0xAA) {
5065 * We have to run through all the OTPROM memory looking
5066 * for the VPD offset.
5068 while (base_offset <= EXPANSION_ROM_SIZE) {
5071 * Lots of magic numbers here.
5073 * The VPD offset is located inside the ROM Data Structure.
5074 * We also have to remember the length of each
5075 * ROM Data Structure, so we can "hop" to the next
5076 * entry if the VPD isn't in the current
5077 * ROM Data Structure.
5079 rom_offset = readw(brd->re_map_membase + base_offset + 0x18);
5080 image_length = readw(brd->re_map_membase + rom_offset + 0x10) * 512;
5081 vpd_offset = readw(brd->re_map_membase + rom_offset + 0x08);
5083 /* Found the VPD entry */
5087 /* We didn't find a VPD entry, go to next ROM entry. */
5088 base_offset += image_length;
5090 byte1 = readb(brd->re_map_membase + base_offset);
5091 byte2 = readb(brd->re_map_membase + base_offset + 1);
5094 * If the new ROM offset doesn't have 0x55, 0xAA
5095 * as its header, we have run out of ROM.
5097 if (byte1 != 0x55 || byte2 != 0xAA)
5102 * If we have a VPD offset, then mark the board
5103 * as having a valid VPD, and copy VPDSIZE (512) bytes of
5104 * that VPD to the buffer we have in our board structure.
5107 brd->bd_flags |= BD_HAS_VPD;
5108 for (i = 0; i < VPDSIZE; i++)
5109 brd->vpd[i] = readb(brd->re_map_membase + vpd_offset + i);
5114 * We MUST poke the magic number at the PCI Rom Address location again.
5115 * This makes the card report the regular board memory back to us,
5116 * rather than the OTPROM memory.
5118 magic = FEP5_ROM_MAGIC;
5119 pci_write_config_dword(brd->pdev, PCI_ROM_ADDRESS, magic);
5124 * Our board poller function.
5126 void dgap_poll_tasklet(unsigned long data)
5128 struct board_t *bd = (struct board_t *) data;
5136 if (!bd || (bd->magic != DGAP_BOARD_MAGIC)) {
5137 APR(("dgap_poll_tasklet() - NULL or bad bd.\n"));
5141 if (bd->inhibit_poller)
5144 DGAP_LOCK(bd->bd_lock, lock_flags);
5146 vaddr = bd->re_map_membase;
5149 * If board is ready, parse deeper to see if there is anything to do.
5151 if (bd->state == BOARD_READY) {
5153 struct ev_t *eaddr = NULL;
5155 if (!bd->re_map_membase) {
5156 DGAP_UNLOCK(bd->bd_lock, lock_flags);
5159 if (!bd->re_map_port) {
5160 DGAP_UNLOCK(bd->bd_lock, lock_flags);
5169 * If this is a CX or EPCX, we need to see if the firmware
5170 * is requesting a concentrator image from us.
5172 if ((bd->type == PCX) || (bd->type == PEPC)) {
5173 chk_addr = (u16 *) (vaddr + DOWNREQ);
5174 check = readw(chk_addr);
5175 /* Nonzero if FEP is requesting concentrator image. */
5177 if (bd->conc_dl_status == NO_PENDING_CONCENTRATOR_REQUESTS)
5178 bd->conc_dl_status = NEED_CONCENTRATOR;
5180 * Signal downloader, its got some work to do.
5182 DGAP_LOCK(dgap_dl_lock, lock_flags2);
5183 if (dgap_dl_action != 1) {
5185 wake_up_interruptible(&dgap_dl_wait);
5187 DGAP_UNLOCK(dgap_dl_lock, lock_flags2);
5192 eaddr = (struct ev_t *) (vaddr + EVBUF);
5194 /* Get our head and tail */
5195 head = readw(&(eaddr->ev_head));
5196 tail = readw(&(eaddr->ev_tail));
5199 * If there is an event pending. Go service it.
5202 DGAP_UNLOCK(bd->bd_lock, lock_flags);
5204 DGAP_LOCK(bd->bd_lock, lock_flags);
5209 * If board is doing interrupts, ACK the interrupt.
5211 if (bd && bd->intr_running) {
5212 readb(bd->re_map_port + 2);
5215 DGAP_UNLOCK(bd->bd_lock, lock_flags);
5219 /* Our state machine to get the board up and running */
5222 if (bd->state == NEED_RESET) {
5227 dgap_do_reset_board(bd);
5230 /* Move to next state */
5231 if (bd->state == FINISHED_RESET) {
5232 bd->state = NEED_CONFIG;
5235 if (bd->state == NEED_CONFIG) {
5237 * Match this board to a config the user created for us.
5239 bd->bd_config = dgap_find_config(bd->type, bd->pci_bus, bd->pci_slot);
5242 * Because the 4 port Xr products share the same PCI ID
5243 * as the 8 port Xr products, if we receive a NULL config
5244 * back, and this is a PAPORT8 board, retry with a
5245 * PAPORT4 attempt as well.
5247 if (bd->type == PAPORT8 && !bd->bd_config) {
5248 bd->bd_config = dgap_find_config(PAPORT4, bd->pci_bus, bd->pci_slot);
5252 * Register the ttys (if any) into the kernel.
5254 if (bd->bd_config) {
5255 bd->state = FINISHED_CONFIG;
5258 bd->state = CONFIG_NOT_FOUND;
5262 /* Move to next state */
5263 if (bd->state == FINISHED_CONFIG) {
5264 bd->state = NEED_DEVICE_CREATION;
5267 /* Move to next state */
5268 if (bd->state == NEED_DEVICE_CREATION) {
5270 * Signal downloader, its got some work to do.
5272 DGAP_LOCK(dgap_dl_lock, lock_flags2);
5273 if (dgap_dl_action != 1) {
5275 wake_up_interruptible(&dgap_dl_wait);
5277 DGAP_UNLOCK(dgap_dl_lock, lock_flags2);
5280 /* Move to next state */
5281 if (bd->state == FINISHED_DEVICE_CREATION) {
5282 bd->state = NEED_BIOS_LOAD;
5285 /* Move to next state */
5286 if (bd->state == NEED_BIOS_LOAD) {
5288 * Signal downloader, its got some work to do.
5290 DGAP_LOCK(dgap_dl_lock, lock_flags2);
5291 if (dgap_dl_action != 1) {
5293 wake_up_interruptible(&dgap_dl_wait);
5295 DGAP_UNLOCK(dgap_dl_lock, lock_flags2);
5298 /* Wait for BIOS to test board... */
5299 if (bd->state == WAIT_BIOS_LOAD) {
5300 dgap_do_wait_for_bios(bd);
5303 /* Move to next state */
5304 if (bd->state == FINISHED_BIOS_LOAD) {
5305 bd->state = NEED_FEP_LOAD;
5308 * Signal downloader, its got some work to do.
5310 DGAP_LOCK(dgap_dl_lock, lock_flags2);
5311 if (dgap_dl_action != 1) {
5313 wake_up_interruptible(&dgap_dl_wait);
5315 DGAP_UNLOCK(dgap_dl_lock, lock_flags2);
5318 /* Wait for FEP to load on board... */
5319 if (bd->state == WAIT_FEP_LOAD) {
5320 dgap_do_wait_for_fep(bd);
5324 /* Move to next state */
5325 if (bd->state == FINISHED_FEP_LOAD) {
5328 * Do tty device initialization.
5330 int rc = dgap_tty_init(bd);
5333 dgap_tty_uninit(bd);
5334 APR(("Can't init tty devices (%d)\n", rc));
5335 bd->state = BOARD_FAILED;
5336 bd->dpastatus = BD_NOFEP;
5339 bd->state = NEED_PROC_CREATION;
5342 * Signal downloader, its got some work to do.
5344 DGAP_LOCK(dgap_dl_lock, lock_flags2);
5345 if (dgap_dl_action != 1) {
5347 wake_up_interruptible(&dgap_dl_wait);
5349 DGAP_UNLOCK(dgap_dl_lock, lock_flags2);
5353 /* Move to next state */
5354 if (bd->state == FINISHED_PROC_CREATION) {
5356 bd->state = BOARD_READY;
5357 bd->dpastatus = BD_RUNNING;
5360 * If user requested the board to run in interrupt mode,
5361 * go and set it up on the board.
5363 if (bd->intr_used) {
5364 writew(1, (bd->re_map_membase + ENABLE_INTR));
5366 * Tell the board to poll the UARTS as fast as possible.
5368 writew(FEPPOLL_MIN, (bd->re_map_membase + FEPPOLL));
5369 bd->intr_running = 1;
5372 /* Wake up anyone waiting for board state to change to ready */
5373 wake_up_interruptible(&bd->state_wait);
5376 DGAP_UNLOCK(bd->bd_lock, lock_flags);
5380 /*=======================================================================
5382 * dgap_cmdb - Sends a 2 byte command to the FEP.
5384 * ch - Pointer to channel structure.
5385 * cmd - Command to be sent.
5386 * byte1 - Integer containing first byte to be sent.
5387 * byte2 - Integer containing second byte to be sent.
5388 * ncmds - Wait until ncmds or fewer cmds are left
5389 * in the cmd buffer before returning.
5391 *=======================================================================*/
5392 void dgap_cmdb(struct channel_t *ch, uchar cmd, uchar byte1, uchar byte2, uint ncmds)
5395 struct cm_t *cm_addr = NULL;
5401 if (!ch || ch->magic != DGAP_CHANNEL_MAGIC)
5405 * Check if board is still alive.
5407 if (ch->ch_bd->state == BOARD_FAILED) {
5408 DPR_CORE(("%s:%d board is in failed state.\n", __FILE__, __LINE__));
5413 * Make sure the pointers are in range before
5414 * writing to the FEP memory.
5416 vaddr = ch->ch_bd->re_map_membase;
5421 cm_addr = (struct cm_t *) (vaddr + CMDBUF);
5422 head = readw(&(cm_addr->cm_head));
5425 * Forget it if pointers out of range.
5427 if (head >= (CMDMAX - CMDSTART) || (head & 03)) {
5428 DPR_CORE(("%s:%d pointers out of range, failing board!\n", __FILE__, __LINE__));
5429 ch->ch_bd->state = BOARD_FAILED;
5434 * Put the data in the circular command buffer.
5436 writeb(cmd, (char *) (vaddr + head + CMDSTART + 0));
5437 writeb((uchar) ch->ch_portnum, (char *) (vaddr + head + CMDSTART + 1));
5438 writeb(byte1, (char *) (vaddr + head + CMDSTART + 2));
5439 writeb(byte2, (char *) (vaddr + head + CMDSTART + 3));
5441 head = (head + 4) & (CMDMAX - CMDSTART - 4);
5443 writew(head, &(cm_addr->cm_head));
5446 * Wait if necessary before updating the head
5447 * pointer to limit the number of outstanding
5448 * commands to the FEP. If the time spent waiting
5449 * is outlandish, declare the FEP dead.
5451 for (count = dgap_count ;;) {
5453 head = readw(&(cm_addr->cm_head));
5454 tail = readw(&(cm_addr->cm_tail));
5456 n = (head - tail) & (CMDMAX - CMDSTART - 4);
5458 if (n <= ncmds * sizeof(struct cm_t))
5462 DPR_CORE(("%s:%d failing board.\n",__FILE__, __LINE__));
5463 ch->ch_bd->state = BOARD_FAILED;
5471 /*=======================================================================
5473 * dgap_cmdw - Sends a 1 word command to the FEP.
5475 * ch - Pointer to channel structure.
5476 * cmd - Command to be sent.
5477 * word - Integer containing word to be sent.
5478 * ncmds - Wait until ncmds or fewer cmds are left
5479 * in the cmd buffer before returning.
5481 *=======================================================================*/
5482 void dgap_cmdw(struct channel_t *ch, uchar cmd, u16 word, uint ncmds)
5485 struct cm_t *cm_addr = NULL;
5491 if (!ch || ch->magic != DGAP_CHANNEL_MAGIC)
5495 * Check if board is still alive.
5497 if (ch->ch_bd->state == BOARD_FAILED) {
5498 DPR_CORE(("%s:%d board is failed!\n", __FILE__, __LINE__));
5503 * Make sure the pointers are in range before
5504 * writing to the FEP memory.
5506 vaddr = ch->ch_bd->re_map_membase;
5510 cm_addr = (struct cm_t *) (vaddr + CMDBUF);
5511 head = readw(&(cm_addr->cm_head));
5514 * Forget it if pointers out of range.
5516 if (head >= (CMDMAX - CMDSTART) || (head & 03)) {
5517 DPR_CORE(("%s:%d Pointers out of range. Failing board.\n",__FILE__, __LINE__));
5518 ch->ch_bd->state = BOARD_FAILED;
5523 * Put the data in the circular command buffer.
5525 writeb(cmd, (char *) (vaddr + head + CMDSTART + 0));
5526 writeb((uchar) ch->ch_portnum, (char *) (vaddr + head + CMDSTART + 1));
5527 writew((u16) word, (char *) (vaddr + head + CMDSTART + 2));
5529 head = (head + 4) & (CMDMAX - CMDSTART - 4);
5531 writew(head, &(cm_addr->cm_head));
5534 * Wait if necessary before updating the head
5535 * pointer to limit the number of outstanding
5536 * commands to the FEP. If the time spent waiting
5537 * is outlandish, declare the FEP dead.
5539 for (count = dgap_count ;;) {
5541 head = readw(&(cm_addr->cm_head));
5542 tail = readw(&(cm_addr->cm_tail));
5544 n = (head - tail) & (CMDMAX - CMDSTART - 4);
5546 if (n <= ncmds * sizeof(struct cm_t))
5550 DPR_CORE(("%s:%d Failing board.\n",__FILE__, __LINE__));
5551 ch->ch_bd->state = BOARD_FAILED;
5560 /*=======================================================================
5562 * dgap_cmdw_ext - Sends a extended word command to the FEP.
5564 * ch - Pointer to channel structure.
5565 * cmd - Command to be sent.
5566 * word - Integer containing word to be sent.
5567 * ncmds - Wait until ncmds or fewer cmds are left
5568 * in the cmd buffer before returning.
5570 *=======================================================================*/
5571 static void dgap_cmdw_ext(struct channel_t *ch, u16 cmd, u16 word, uint ncmds)
5574 struct cm_t *cm_addr = NULL;
5580 if (!ch || ch->magic != DGAP_CHANNEL_MAGIC)
5584 * Check if board is still alive.
5586 if (ch->ch_bd->state == BOARD_FAILED) {
5587 DPR_CORE(("%s:%d board is failed!\n", __FILE__, __LINE__));
5592 * Make sure the pointers are in range before
5593 * writing to the FEP memory.
5595 vaddr = ch->ch_bd->re_map_membase;
5599 cm_addr = (struct cm_t *) (vaddr + CMDBUF);
5600 head = readw(&(cm_addr->cm_head));
5603 * Forget it if pointers out of range.
5605 if (head >= (CMDMAX - CMDSTART) || (head & 03)) {
5606 DPR_CORE(("%s:%d Pointers out of range. Failing board.\n",__FILE__, __LINE__));
5607 ch->ch_bd->state = BOARD_FAILED;
5612 * Put the data in the circular command buffer.
5615 /* Write an FF to tell the FEP that we want an extended command */
5616 writeb((uchar) 0xff, (char *) (vaddr + head + CMDSTART + 0));
5618 writeb((uchar) ch->ch_portnum, (uchar *) (vaddr + head + CMDSTART + 1));
5619 writew((u16) cmd, (char *) (vaddr + head + CMDSTART + 2));
5622 * If the second part of the command won't fit,
5623 * put it at the beginning of the circular buffer.
5625 if (((head + 4) >= ((CMDMAX - CMDSTART)) || (head & 03))) {
5626 writew((u16) word, (char *) (vaddr + CMDSTART));
5628 writew((u16) word, (char *) (vaddr + head + CMDSTART + 4));
5631 head = (head + 8) & (CMDMAX - CMDSTART - 4);
5633 writew(head, &(cm_addr->cm_head));
5636 * Wait if necessary before updating the head
5637 * pointer to limit the number of outstanding
5638 * commands to the FEP. If the time spent waiting
5639 * is outlandish, declare the FEP dead.
5641 for (count = dgap_count ;;) {
5643 head = readw(&(cm_addr->cm_head));
5644 tail = readw(&(cm_addr->cm_tail));
5646 n = (head - tail) & (CMDMAX - CMDSTART - 4);
5648 if (n <= ncmds * sizeof(struct cm_t))
5652 DPR_CORE(("%s:%d Failing board.\n",__FILE__, __LINE__));
5653 ch->ch_bd->state = BOARD_FAILED;
5661 /*=======================================================================
5663 * dgap_wmove - Write data to FEP buffer.
5665 * ch - Pointer to channel structure.
5666 * buf - Poiter to characters to be moved.
5667 * cnt - Number of characters to move.
5669 *=======================================================================*/
5670 void dgap_wmove(struct channel_t *ch, char *buf, uint cnt)
5677 if (!ch || ch->magic != DGAP_CHANNEL_MAGIC)
5684 head = readw(&(bs->tx_head));
5687 * If pointers are out of range, just return.
5689 if ((cnt > ch->ch_tsize) || (unsigned)(head - ch->ch_tstart) >= ch->ch_tsize) {
5690 DPR_CORE(("%s:%d pointer out of range", __FILE__, __LINE__));
5695 * If the write wraps over the top of the circular buffer,
5696 * move the portion up to the wrap point, and reset the
5697 * pointers to the bottom.
5699 n = ch->ch_tstart + ch->ch_tsize - head;
5703 taddr = ch->ch_taddr + head;
5704 memcpy_toio(taddr, buf, n);
5705 head = ch->ch_tstart;
5710 * Move rest of data.
5712 taddr = ch->ch_taddr + head;
5714 memcpy_toio(taddr, buf, n);
5717 writew(head, &(bs->tx_head));
5721 * Retrives the current custom baud rate from FEP memory,
5722 * and returns it back to the user.
5723 * Returns 0 on error.
5725 uint dgap_get_custom_baud(struct channel_t *ch)
5731 if (!ch || ch->magic != DGAP_CHANNEL_MAGIC) {
5735 if (!ch->ch_bd || ch->ch_bd->magic != DGAP_BOARD_MAGIC) {
5739 if (!(ch->ch_bd->bd_flags & BD_FEP5PLUS))
5742 vaddr = ch->ch_bd->re_map_membase;
5748 * Go get from fep mem, what the fep
5749 * believes the custom baud rate is.
5751 offset = ((((*(unsigned short *)(vaddr + ECS_SEG)) << 4) +
5752 (ch->ch_portnum * 0x28) + LINE_SPEED));
5754 value = readw(vaddr + offset);
5760 * Calls the firmware to reset this channel.
5762 void dgap_firmware_reset_port(struct channel_t *ch)
5764 dgap_cmdb(ch, CHRESET, 0, 0, 0);
5767 * Now that the channel is reset, we need to make sure
5768 * all the current settings get reapplied to the port
5771 * So we will set the driver's cache of firmware
5772 * settings all to 0, and then call param.
5774 ch->ch_fepiflag = 0;
5775 ch->ch_fepcflag = 0;
5776 ch->ch_fepoflag = 0;
5777 ch->ch_fepstartc = 0;
5778 ch->ch_fepstopc = 0;
5779 ch->ch_fepastartc = 0;
5780 ch->ch_fepastopc = 0;
5786 /*=======================================================================
5788 * dgap_param - Set Digi parameters.
5790 * struct tty_struct * - TTY for port.
5792 *=======================================================================*/
5793 int dgap_param(struct tty_struct *tty)
5795 struct ktermios *ts;
5797 struct channel_t *ch;
5806 if (!tty || tty->magic != TTY_MAGIC)
5809 un = (struct un_t *) tty->driver_data;
5810 if (!un || un->magic != DGAP_UNIT_MAGIC)
5814 if (!ch || ch->magic != DGAP_CHANNEL_MAGIC)
5818 if (!bd || bd->magic != DGAP_BOARD_MAGIC)
5825 DPR_PARAM(("param start: tdev: %x cflags: %x oflags: %x iflags: %x\n",
5826 ch->ch_tun.un_dev, ch->ch_c_cflag, ch->ch_c_oflag, ch->ch_c_iflag));
5831 * If baud rate is zero, flush queues, and set mval to drop DTR.
5833 if ((ch->ch_c_cflag & (CBAUD)) == 0) {
5836 head = readw(&(ch->ch_bs->rx_head));
5837 writew(head, &(ch->ch_bs->rx_tail));
5840 head = readw(&(ch->ch_bs->tx_head));
5841 writew(head, &(ch->ch_bs->tx_tail));
5843 ch->ch_flags |= (CH_BAUD0);
5845 /* Drop RTS and DTR */
5846 ch->ch_mval &= ~(D_RTS(ch)|D_DTR(ch));
5847 mval = D_DTR(ch) | D_RTS(ch);
5848 ch->ch_baud_info = 0;
5850 } else if (ch->ch_custom_speed && (bd->bd_flags & BD_FEP5PLUS)) {
5852 * Tell the fep to do the command
5855 DPR_PARAM(("param: Want %d speed\n", ch->ch_custom_speed));
5857 dgap_cmdw_ext(ch, 0xff01, ch->ch_custom_speed, 0);
5860 * Now go get from fep mem, what the fep
5861 * believes the custom baud rate is.
5863 ch->ch_baud_info = ch->ch_custom_speed = dgap_get_custom_baud(ch);
5865 DPR_PARAM(("param: Got %d speed\n", ch->ch_custom_speed));
5867 /* Handle transition from B0 */
5868 if (ch->ch_flags & CH_BAUD0) {
5869 ch->ch_flags &= ~(CH_BAUD0);
5870 ch->ch_mval |= (D_RTS(ch)|D_DTR(ch));
5872 mval = D_DTR(ch) | D_RTS(ch);
5876 * Set baud rate, character size, and parity.
5884 ulong bauds[4][16] = {
5888 600, 1200, 1800, 2400,
5889 4800, 9600, 19200, 38400 },
5890 { /* slowbaud & CBAUDEX */
5891 0, 57600, 115200, 230400,
5892 460800, 150, 200, 921600,
5893 600, 1200, 1800, 2400,
5894 4800, 9600, 19200, 38400 },
5896 0, 57600, 76800, 115200,
5897 14400, 57600, 230400, 76800,
5898 115200, 230400, 28800, 460800,
5899 921600, 9600, 19200, 38400 },
5900 { /* fastbaud & CBAUDEX */
5901 0, 57600, 115200, 230400,
5902 460800, 150, 200, 921600,
5903 600, 1200, 1800, 2400,
5904 4800, 9600, 19200, 38400 }
5907 /* Only use the TXPrint baud rate if the terminal unit is NOT open */
5908 if (!(ch->ch_tun.un_flags & UN_ISOPEN) && (un->un_type == DGAP_PRINT))
5909 baud = C_BAUD(ch->ch_pun.un_tty) & 0xff;
5911 baud = C_BAUD(ch->ch_tun.un_tty) & 0xff;
5913 if (ch->ch_c_cflag & CBAUDEX)
5916 if (ch->ch_digi.digi_flags & DIGI_FAST)
5921 if ((iindex >= 0) && (iindex < 4) && (jindex >= 0) && (jindex < 16)) {
5922 baud = bauds[iindex][jindex];
5924 DPR_IOCTL(("baud indices were out of range (%d)(%d)",
5932 ch->ch_baud_info = baud;
5936 * CBAUD has bit position 0x1000 set these days to indicate Linux
5938 * We use a different bit assignment for high speed. Clear this
5939 * bit out while grabbing the parts of "cflag" we want.
5941 cflag = ch->ch_c_cflag & ((CBAUD ^ CBAUDEX) | PARODD | PARENB | CSTOPB | CSIZE);
5944 * HUPCL bit is used by FEP to indicate fast baud
5945 * table is to be used.
5947 if ((ch->ch_digi.digi_flags & DIGI_FAST) || (ch->ch_c_cflag & CBAUDEX))
5951 if ((ch->ch_c_cflag & CBAUDEX) && !(ch->ch_digi.digi_flags & DIGI_FAST)) {
5953 * The below code is trying to guarantee that only baud rates
5954 * 115200, 230400, 460800, 921600 are remapped. We use exclusive or
5955 * because the various baud rates share common bit positions
5956 * and therefore can't be tested for easily.
5958 tcflag_t tcflag = (ch->ch_c_cflag & CBAUD) | CBAUDEX;
5961 /* Map high speed requests to index into FEP's baud table */
5990 cflag = (cflag & ~(CBAUD | CBAUDEX)) | baudpart;
5995 if (cflag != ch->ch_fepcflag) {
5996 ch->ch_fepcflag = (u16) (cflag & 0xffff);
5998 /* Okay to have channel and board locks held calling this */
5999 dgap_cmdw(ch, SCFLAG, (u16) cflag, 0);
6002 /* Handle transition from B0 */
6003 if (ch->ch_flags & CH_BAUD0) {
6004 ch->ch_flags &= ~(CH_BAUD0);
6005 ch->ch_mval |= (D_RTS(ch)|D_DTR(ch));
6007 mval = D_DTR(ch) | D_RTS(ch);
6013 iflag = ch->ch_c_iflag & (IGNBRK | BRKINT | IGNPAR | PARMRK | INPCK | ISTRIP | IXON | IXANY | IXOFF);
6015 if ((ch->ch_startc == _POSIX_VDISABLE) || (ch->ch_stopc == _POSIX_VDISABLE)) {
6016 iflag &= ~(IXON | IXOFF);
6017 ch->ch_c_iflag &= ~(IXON | IXOFF);
6021 * Only the IBM Xr card can switch between
6022 * 232 and 422 modes on the fly
6024 if (bd->device == PCI_DEVICE_XR_IBM_DID) {
6025 if (ch->ch_digi.digi_flags & DIGI_422)
6026 dgap_cmdb(ch, SCOMMODE, MODE_422, 0, 0);
6028 dgap_cmdb(ch, SCOMMODE, MODE_232, 0, 0);
6031 if (ch->ch_digi.digi_flags & DIGI_ALTPIN)
6034 if (iflag != ch->ch_fepiflag) {
6035 ch->ch_fepiflag = iflag;
6037 /* Okay to have channel and board locks held calling this */
6038 dgap_cmdw(ch, SIFLAG, (u16) ch->ch_fepiflag, 0);
6042 * Select hardware handshaking.
6046 if (ch->ch_c_cflag & CRTSCTS) {
6047 hflow |= (D_RTS(ch) | D_CTS(ch));
6049 if (ch->ch_digi.digi_flags & RTSPACE)
6051 if (ch->ch_digi.digi_flags & DTRPACE)
6053 if (ch->ch_digi.digi_flags & CTSPACE)
6055 if (ch->ch_digi.digi_flags & DSRPACE)
6057 if (ch->ch_digi.digi_flags & DCDPACE)
6060 if (hflow != ch->ch_hflow) {
6061 ch->ch_hflow = hflow;
6063 /* Okay to have channel and board locks held calling this */
6064 dgap_cmdb(ch, SHFLOW, (uchar) hflow, 0xff, 0);
6069 * Set RTS and/or DTR Toggle if needed, but only if product is FEP5+ based.
6071 if (bd->bd_flags & BD_FEP5PLUS) {
6073 if (ch->ch_digi.digi_flags & DIGI_RTS_TOGGLE) {
6074 hflow2 |= (D_RTS(ch));
6076 if (ch->ch_digi.digi_flags & DIGI_DTR_TOGGLE) {
6077 hflow2 |= (D_DTR(ch));
6080 dgap_cmdw_ext(ch, 0xff03, hflow2, 0);
6084 * Set modem control lines.
6087 mval ^= ch->ch_mforce & (mval ^ ch->ch_mval);
6089 DPR_PARAM(("dgap_param: mval: %x ch_mforce: %x ch_mval: %x ch_mostat: %x\n",
6090 mval, ch->ch_mforce, ch->ch_mval, ch->ch_mostat));
6092 if (ch->ch_mostat ^ mval) {
6093 ch->ch_mostat = mval;
6095 /* Okay to have channel and board locks held calling this */
6096 DPR_PARAM(("dgap_param: Sending SMODEM mval: %x\n", mval));
6097 dgap_cmdb(ch, SMODEM, (uchar) mval, D_RTS(ch)|D_DTR(ch), 0);
6101 * Read modem signals, and then call carrier function.
6103 ch->ch_mistat = readb(&(bs->m_stat));
6107 * Set the start and stop characters.
6109 if (ch->ch_startc != ch->ch_fepstartc || ch->ch_stopc != ch->ch_fepstopc) {
6110 ch->ch_fepstartc = ch->ch_startc;
6111 ch->ch_fepstopc = ch->ch_stopc;
6113 /* Okay to have channel and board locks held calling this */
6114 dgap_cmdb(ch, SFLOWC, ch->ch_fepstartc, ch->ch_fepstopc, 0);
6118 * Set the Auxiliary start and stop characters.
6120 if (ch->ch_astartc != ch->ch_fepastartc || ch->ch_astopc != ch->ch_fepastopc) {
6121 ch->ch_fepastartc = ch->ch_astartc;
6122 ch->ch_fepastopc = ch->ch_astopc;
6124 /* Okay to have channel and board locks held calling this */
6125 dgap_cmdb(ch, SAFLOWC, ch->ch_fepastartc, ch->ch_fepastopc, 0);
6128 DPR_PARAM(("param finish\n"));
6135 * dgap_parity_scan()
6137 * Convert the FEP5 way of reporting parity errors and breaks into
6138 * the Linux line discipline way.
6140 void dgap_parity_scan(struct channel_t *ch, unsigned char *cbuf, unsigned char *fbuf, int *len)
6144 unsigned char *in, *cout, *fout;
6151 DPR_PSCAN(("dgap_parity_scan start\n"));
6153 if (!ch || ch->magic != DGAP_CHANNEL_MAGIC)
6158 switch (ch->pscan_state) {
6160 /* reset to sanity and fall through */
6161 ch->pscan_state = 0;
6164 /* No FF seen yet */
6165 if (c == (unsigned char) '\377') {
6166 /* delete this character from stream */
6167 ch->pscan_state = 1;
6170 *fout++ = TTY_NORMAL;
6177 if (c == (unsigned char) '\377') {
6178 /* doubled ff, transform to single ff */
6180 *fout++ = TTY_NORMAL;
6182 ch->pscan_state = 0;
6184 /* save value examination in next state */
6185 ch->pscan_savechar = c;
6186 ch->pscan_state = 2;
6191 /* third character of ff sequence */
6195 if (ch->pscan_savechar == 0x0) {
6198 DPR_PSCAN(("dgap_parity_scan in 3rd char of ff seq. c: %x setting break.\n", c));
6200 *fout++ = TTY_BREAK;
6203 DPR_PSCAN(("dgap_parity_scan in 3rd char of ff seq. c: %x setting parity.\n", c));
6204 ch->ch_err_parity++;
6205 *fout++ = TTY_PARITY;
6209 DPR_PSCAN(("%s:%d Logic Error.\n", __FILE__, __LINE__));
6213 ch->pscan_state = 0;
6217 DPR_PSCAN(("dgap_parity_scan finish\n"));
6223 /*=======================================================================
6225 * dgap_event - FEP to host event processing routine.
6227 * bd - Board of current event.
6229 *=======================================================================*/
6230 static int dgap_event(struct board_t *bd)
6232 struct channel_t *ch;
6237 uchar *vaddr = NULL;
6238 struct ev_t *eaddr = NULL;
6246 if (!bd || bd->magic != DGAP_BOARD_MAGIC)
6249 DGAP_LOCK(bd->bd_lock, lock_flags);
6251 vaddr = bd->re_map_membase;
6254 DGAP_UNLOCK(bd->bd_lock, lock_flags);
6258 eaddr = (struct ev_t *) (vaddr + EVBUF);
6260 /* Get our head and tail */
6261 head = readw(&(eaddr->ev_head));
6262 tail = readw(&(eaddr->ev_tail));
6265 * Forget it if pointers out of range.
6268 if (head >= EVMAX - EVSTART || tail >= EVMAX - EVSTART ||
6269 (head | tail) & 03) {
6270 DPR_EVENT(("should be calling xxfail %d\n", __LINE__));
6271 /* Let go of board lock */
6272 DGAP_UNLOCK(bd->bd_lock, lock_flags);
6277 * Loop to process all the events in the buffer.
6279 while (tail != head) {
6282 * Get interrupt information.
6285 event = bd->re_map_membase + tail + EVSTART;
6292 DPR_EVENT(("event: jiffies: %ld port: %d reason: %x modem: %x\n",
6293 jiffies, port, reason, modem));
6296 * Make sure the interrupt is valid.
6298 if (port >= bd->nasync)
6301 if (!(reason & (IFMODEM | IFBREAK | IFTLW | IFTEM | IFDATA))) {
6305 ch = bd->channels[port];
6307 if (!ch || ch->magic != DGAP_CHANNEL_MAGIC) {
6312 * If we have made it here, the event was valid.
6313 * Lock down the channel.
6315 DGAP_LOCK(ch->ch_lock, lock_flags2);
6320 DGAP_UNLOCK(ch->ch_lock, lock_flags2);
6325 * Process received data.
6327 if (reason & IFDATA) {
6330 * ALL LOCKS *MUST* BE DROPPED BEFORE CALLING INPUT!
6331 * input could send some data to ld, which in turn
6332 * could do a callback to one of our other functions.
6334 DGAP_UNLOCK(ch->ch_lock, lock_flags2);
6335 DGAP_UNLOCK(bd->bd_lock, lock_flags);
6339 DGAP_LOCK(bd->bd_lock, lock_flags);
6340 DGAP_LOCK(ch->ch_lock, lock_flags2);
6342 if (ch->ch_flags & CH_RACTIVE)
6343 ch->ch_flags |= CH_RENABLE;
6345 writeb(1, &(bs->idata));
6347 if (ch->ch_flags & CH_RWAIT) {
6348 ch->ch_flags &= ~CH_RWAIT;
6350 wake_up_interruptible(&ch->ch_tun.un_flags_wait);
6355 * Process Modem change signals.
6357 if (reason & IFMODEM) {
6358 ch->ch_mistat = modem;
6365 if (reason & IFBREAK) {
6367 DPR_EVENT(("got IFBREAK\n"));
6369 if (ch->ch_tun.un_tty) {
6370 /* A break has been indicated */
6372 tty_buffer_request_room(ch->ch_tun.un_tty->port, 1);
6373 tty_insert_flip_char(ch->ch_tun.un_tty->port, 0, TTY_BREAK);
6374 tty_flip_buffer_push(ch->ch_tun.un_tty->port);
6379 * Process Transmit low.
6381 if (reason & IFTLW) {
6383 DPR_EVENT(("event: got low event\n"));
6385 if (ch->ch_tun.un_flags & UN_LOW) {
6386 ch->ch_tun.un_flags &= ~UN_LOW;
6388 if (ch->ch_tun.un_flags & UN_ISOPEN) {
6389 if ((ch->ch_tun.un_tty->flags &
6390 (1 << TTY_DO_WRITE_WAKEUP)) &&
6391 ch->ch_tun.un_tty->ldisc->ops->write_wakeup)
6393 DGAP_UNLOCK(ch->ch_lock, lock_flags2);
6394 DGAP_UNLOCK(bd->bd_lock, lock_flags);
6395 (ch->ch_tun.un_tty->ldisc->ops->write_wakeup)(ch->ch_tun.un_tty);
6396 DGAP_LOCK(bd->bd_lock, lock_flags);
6397 DGAP_LOCK(ch->ch_lock, lock_flags2);
6399 wake_up_interruptible(&ch->ch_tun.un_tty->write_wait);
6400 wake_up_interruptible(&ch->ch_tun.un_flags_wait);
6402 DPR_EVENT(("event: Got low event. jiffies: %lu\n", jiffies));
6406 if (ch->ch_pun.un_flags & UN_LOW) {
6407 ch->ch_pun.un_flags &= ~UN_LOW;
6408 if (ch->ch_pun.un_flags & UN_ISOPEN) {
6409 if ((ch->ch_pun.un_tty->flags &
6410 (1 << TTY_DO_WRITE_WAKEUP)) &&
6411 ch->ch_pun.un_tty->ldisc->ops->write_wakeup)
6413 DGAP_UNLOCK(ch->ch_lock, lock_flags2);
6414 DGAP_UNLOCK(bd->bd_lock, lock_flags);
6415 (ch->ch_pun.un_tty->ldisc->ops->write_wakeup)(ch->ch_pun.un_tty);
6416 DGAP_LOCK(bd->bd_lock, lock_flags);
6417 DGAP_LOCK(ch->ch_lock, lock_flags2);
6419 wake_up_interruptible(&ch->ch_pun.un_tty->write_wait);
6420 wake_up_interruptible(&ch->ch_pun.un_flags_wait);
6424 if (ch->ch_flags & CH_WLOW) {
6425 ch->ch_flags &= ~CH_WLOW;
6426 wake_up_interruptible(&ch->ch_flags_wait);
6431 * Process Transmit empty.
6433 if (reason & IFTEM) {
6434 DPR_EVENT(("event: got empty event\n"));
6436 if (ch->ch_tun.un_flags & UN_EMPTY) {
6437 ch->ch_tun.un_flags &= ~UN_EMPTY;
6438 if (ch->ch_tun.un_flags & UN_ISOPEN) {
6439 if ((ch->ch_tun.un_tty->flags &
6440 (1 << TTY_DO_WRITE_WAKEUP)) &&
6441 ch->ch_tun.un_tty->ldisc->ops->write_wakeup)
6443 DGAP_UNLOCK(ch->ch_lock, lock_flags2);
6444 DGAP_UNLOCK(bd->bd_lock, lock_flags);
6446 (ch->ch_tun.un_tty->ldisc->ops->write_wakeup)(ch->ch_tun.un_tty);
6447 DGAP_LOCK(bd->bd_lock, lock_flags);
6448 DGAP_LOCK(ch->ch_lock, lock_flags2);
6450 wake_up_interruptible(&ch->ch_tun.un_tty->write_wait);
6451 wake_up_interruptible(&ch->ch_tun.un_flags_wait);
6455 if (ch->ch_pun.un_flags & UN_EMPTY) {
6456 ch->ch_pun.un_flags &= ~UN_EMPTY;
6457 if (ch->ch_pun.un_flags & UN_ISOPEN) {
6458 if ((ch->ch_pun.un_tty->flags &
6459 (1 << TTY_DO_WRITE_WAKEUP)) &&
6460 ch->ch_pun.un_tty->ldisc->ops->write_wakeup)
6462 DGAP_UNLOCK(ch->ch_lock, lock_flags2);
6463 DGAP_UNLOCK(bd->bd_lock, lock_flags);
6464 (ch->ch_pun.un_tty->ldisc->ops->write_wakeup)(ch->ch_pun.un_tty);
6465 DGAP_LOCK(bd->bd_lock, lock_flags);
6466 DGAP_LOCK(ch->ch_lock, lock_flags2);
6468 wake_up_interruptible(&ch->ch_pun.un_tty->write_wait);
6469 wake_up_interruptible(&ch->ch_pun.un_flags_wait);
6474 if (ch->ch_flags & CH_WEMPTY) {
6475 ch->ch_flags &= ~CH_WEMPTY;
6476 wake_up_interruptible(&ch->ch_flags_wait);
6480 DGAP_UNLOCK(ch->ch_lock, lock_flags2);
6483 tail = (tail + 4) & (EVMAX - EVSTART - 4);
6486 writew(tail, &(eaddr->ev_tail));
6487 DGAP_UNLOCK(bd->bd_lock, lock_flags);
6492 static ssize_t dgap_driver_version_show(struct device_driver *ddp, char *buf)
6494 return snprintf(buf, PAGE_SIZE, "%s\n", DG_PART);
6496 static DRIVER_ATTR(version, S_IRUSR, dgap_driver_version_show, NULL);
6499 static ssize_t dgap_driver_boards_show(struct device_driver *ddp, char *buf)
6501 return snprintf(buf, PAGE_SIZE, "%d\n", dgap_NumBoards);
6503 static DRIVER_ATTR(boards, S_IRUSR, dgap_driver_boards_show, NULL);
6506 static ssize_t dgap_driver_maxboards_show(struct device_driver *ddp, char *buf)
6508 return snprintf(buf, PAGE_SIZE, "%d\n", MAXBOARDS);
6510 static DRIVER_ATTR(maxboards, S_IRUSR, dgap_driver_maxboards_show, NULL);
6513 static ssize_t dgap_driver_pollcounter_show(struct device_driver *ddp, char *buf)
6515 return snprintf(buf, PAGE_SIZE, "%ld\n", dgap_poll_counter);
6517 static DRIVER_ATTR(pollcounter, S_IRUSR, dgap_driver_pollcounter_show, NULL);
6520 static ssize_t dgap_driver_state_show(struct device_driver *ddp, char *buf)
6522 return snprintf(buf, PAGE_SIZE, "%s\n", dgap_driver_state_text[dgap_driver_state]);
6524 static DRIVER_ATTR(state, S_IRUSR, dgap_driver_state_show, NULL);
6527 static ssize_t dgap_driver_debug_show(struct device_driver *ddp, char *buf)
6529 return snprintf(buf, PAGE_SIZE, "0x%x\n", dgap_debug);
6532 static ssize_t dgap_driver_debug_store(struct device_driver *ddp, const char *buf, size_t count)
6534 sscanf(buf, "0x%x\n", &dgap_debug);
6537 static DRIVER_ATTR(debug, (S_IRUSR | S_IWUSR), dgap_driver_debug_show, dgap_driver_debug_store);
6540 static ssize_t dgap_driver_rawreadok_show(struct device_driver *ddp, char *buf)
6542 return snprintf(buf, PAGE_SIZE, "0x%x\n", dgap_rawreadok);
6545 static ssize_t dgap_driver_rawreadok_store(struct device_driver *ddp, const char *buf, size_t count)
6547 sscanf(buf, "0x%x\n", &dgap_rawreadok);
6550 static DRIVER_ATTR(rawreadok, (S_IRUSR | S_IWUSR), dgap_driver_rawreadok_show, dgap_driver_rawreadok_store);
6553 static ssize_t dgap_driver_pollrate_show(struct device_driver *ddp, char *buf)
6555 return snprintf(buf, PAGE_SIZE, "%dms\n", dgap_poll_tick);
6558 static ssize_t dgap_driver_pollrate_store(struct device_driver *ddp, const char *buf, size_t count)
6560 sscanf(buf, "%d\n", &dgap_poll_tick);
6563 static DRIVER_ATTR(pollrate, (S_IRUSR | S_IWUSR), dgap_driver_pollrate_show, dgap_driver_pollrate_store);
6566 void dgap_create_driver_sysfiles(struct pci_driver *dgap_driver)
6569 struct device_driver *driverfs = &dgap_driver->driver;
6571 rc |= driver_create_file(driverfs, &driver_attr_version);
6572 rc |= driver_create_file(driverfs, &driver_attr_boards);
6573 rc |= driver_create_file(driverfs, &driver_attr_maxboards);
6574 rc |= driver_create_file(driverfs, &driver_attr_debug);
6575 rc |= driver_create_file(driverfs, &driver_attr_rawreadok);
6576 rc |= driver_create_file(driverfs, &driver_attr_pollrate);
6577 rc |= driver_create_file(driverfs, &driver_attr_pollcounter);
6578 rc |= driver_create_file(driverfs, &driver_attr_state);
6580 printk(KERN_ERR "DGAP: sysfs driver_create_file failed!\n");
6585 void dgap_remove_driver_sysfiles(struct pci_driver *dgap_driver)
6587 struct device_driver *driverfs = &dgap_driver->driver;
6588 driver_remove_file(driverfs, &driver_attr_version);
6589 driver_remove_file(driverfs, &driver_attr_boards);
6590 driver_remove_file(driverfs, &driver_attr_maxboards);
6591 driver_remove_file(driverfs, &driver_attr_debug);
6592 driver_remove_file(driverfs, &driver_attr_rawreadok);
6593 driver_remove_file(driverfs, &driver_attr_pollrate);
6594 driver_remove_file(driverfs, &driver_attr_pollcounter);
6595 driver_remove_file(driverfs, &driver_attr_state);
6599 #define DGAP_VERIFY_BOARD(p, bd) \
6603 bd = dev_get_drvdata(p); \
6604 if (!bd || bd->magic != DGAP_BOARD_MAGIC) \
6606 if (bd->state != BOARD_READY) \
6610 static ssize_t dgap_ports_state_show(struct device *p, struct device_attribute *attr, char *buf)
6616 DGAP_VERIFY_BOARD(p, bd);
6618 for (i = 0; i < bd->nasync; i++) {
6619 count += snprintf(buf + count, PAGE_SIZE - count,
6620 "%d %s\n", bd->channels[i]->ch_portnum,
6621 bd->channels[i]->ch_open_count ? "Open" : "Closed");
6625 static DEVICE_ATTR(ports_state, S_IRUSR, dgap_ports_state_show, NULL);
6628 static ssize_t dgap_ports_baud_show(struct device *p, struct device_attribute *attr, char *buf)
6634 DGAP_VERIFY_BOARD(p, bd);
6636 for (i = 0; i < bd->nasync; i++) {
6637 count += snprintf(buf + count, PAGE_SIZE - count,
6638 "%d %d\n", bd->channels[i]->ch_portnum, bd->channels[i]->ch_baud_info);
6642 static DEVICE_ATTR(ports_baud, S_IRUSR, dgap_ports_baud_show, NULL);
6645 static ssize_t dgap_ports_msignals_show(struct device *p, struct device_attribute *attr, char *buf)
6651 DGAP_VERIFY_BOARD(p, bd);
6653 for (i = 0; i < bd->nasync; i++) {
6654 if (bd->channels[i]->ch_open_count) {
6655 count += snprintf(buf + count, PAGE_SIZE - count,
6656 "%d %s %s %s %s %s %s\n", bd->channels[i]->ch_portnum,
6657 (bd->channels[i]->ch_mostat & UART_MCR_RTS) ? "RTS" : "",
6658 (bd->channels[i]->ch_mistat & UART_MSR_CTS) ? "CTS" : "",
6659 (bd->channels[i]->ch_mostat & UART_MCR_DTR) ? "DTR" : "",
6660 (bd->channels[i]->ch_mistat & UART_MSR_DSR) ? "DSR" : "",
6661 (bd->channels[i]->ch_mistat & UART_MSR_DCD) ? "DCD" : "",
6662 (bd->channels[i]->ch_mistat & UART_MSR_RI) ? "RI" : "");
6664 count += snprintf(buf + count, PAGE_SIZE - count,
6665 "%d\n", bd->channels[i]->ch_portnum);
6670 static DEVICE_ATTR(ports_msignals, S_IRUSR, dgap_ports_msignals_show, NULL);
6673 static ssize_t dgap_ports_iflag_show(struct device *p, struct device_attribute *attr, char *buf)
6679 DGAP_VERIFY_BOARD(p, bd);
6681 for (i = 0; i < bd->nasync; i++) {
6682 count += snprintf(buf + count, PAGE_SIZE - count, "%d %x\n",
6683 bd->channels[i]->ch_portnum, bd->channels[i]->ch_c_iflag);
6687 static DEVICE_ATTR(ports_iflag, S_IRUSR, dgap_ports_iflag_show, NULL);
6690 static ssize_t dgap_ports_cflag_show(struct device *p, struct device_attribute *attr, char *buf)
6696 DGAP_VERIFY_BOARD(p, bd);
6698 for (i = 0; i < bd->nasync; i++) {
6699 count += snprintf(buf + count, PAGE_SIZE - count, "%d %x\n",
6700 bd->channels[i]->ch_portnum, bd->channels[i]->ch_c_cflag);
6704 static DEVICE_ATTR(ports_cflag, S_IRUSR, dgap_ports_cflag_show, NULL);
6707 static ssize_t dgap_ports_oflag_show(struct device *p, struct device_attribute *attr, char *buf)
6713 DGAP_VERIFY_BOARD(p, bd);
6715 for (i = 0; i < bd->nasync; i++) {
6716 count += snprintf(buf + count, PAGE_SIZE - count, "%d %x\n",
6717 bd->channels[i]->ch_portnum, bd->channels[i]->ch_c_oflag);
6721 static DEVICE_ATTR(ports_oflag, S_IRUSR, dgap_ports_oflag_show, NULL);
6724 static ssize_t dgap_ports_lflag_show(struct device *p, struct device_attribute *attr, char *buf)
6730 DGAP_VERIFY_BOARD(p, bd);
6732 for (i = 0; i < bd->nasync; i++) {
6733 count += snprintf(buf + count, PAGE_SIZE - count, "%d %x\n",
6734 bd->channels[i]->ch_portnum, bd->channels[i]->ch_c_lflag);
6738 static DEVICE_ATTR(ports_lflag, S_IRUSR, dgap_ports_lflag_show, NULL);
6741 static ssize_t dgap_ports_digi_flag_show(struct device *p, struct device_attribute *attr, char *buf)
6747 DGAP_VERIFY_BOARD(p, bd);
6749 for (i = 0; i < bd->nasync; i++) {
6750 count += snprintf(buf + count, PAGE_SIZE - count, "%d %x\n",
6751 bd->channels[i]->ch_portnum, bd->channels[i]->ch_digi.digi_flags);
6755 static DEVICE_ATTR(ports_digi_flag, S_IRUSR, dgap_ports_digi_flag_show, NULL);
6758 static ssize_t dgap_ports_rxcount_show(struct device *p, struct device_attribute *attr, char *buf)
6764 DGAP_VERIFY_BOARD(p, bd);
6766 for (i = 0; i < bd->nasync; i++) {
6767 count += snprintf(buf + count, PAGE_SIZE - count, "%d %ld\n",
6768 bd->channels[i]->ch_portnum, bd->channels[i]->ch_rxcount);
6772 static DEVICE_ATTR(ports_rxcount, S_IRUSR, dgap_ports_rxcount_show, NULL);
6775 static ssize_t dgap_ports_txcount_show(struct device *p, struct device_attribute *attr, char *buf)
6781 DGAP_VERIFY_BOARD(p, bd);
6783 for (i = 0; i < bd->nasync; i++) {
6784 count += snprintf(buf + count, PAGE_SIZE - count, "%d %ld\n",
6785 bd->channels[i]->ch_portnum, bd->channels[i]->ch_txcount);
6789 static DEVICE_ATTR(ports_txcount, S_IRUSR, dgap_ports_txcount_show, NULL);
6792 /* this function creates the sys files that will export each signal status
6793 * to sysfs each value will be put in a separate filename
6795 void dgap_create_ports_sysfiles(struct board_t *bd)
6799 dev_set_drvdata(&bd->pdev->dev, bd);
6800 rc |= device_create_file(&(bd->pdev->dev), &dev_attr_ports_state);
6801 rc |= device_create_file(&(bd->pdev->dev), &dev_attr_ports_baud);
6802 rc |= device_create_file(&(bd->pdev->dev), &dev_attr_ports_msignals);
6803 rc |= device_create_file(&(bd->pdev->dev), &dev_attr_ports_iflag);
6804 rc |= device_create_file(&(bd->pdev->dev), &dev_attr_ports_cflag);
6805 rc |= device_create_file(&(bd->pdev->dev), &dev_attr_ports_oflag);
6806 rc |= device_create_file(&(bd->pdev->dev), &dev_attr_ports_lflag);
6807 rc |= device_create_file(&(bd->pdev->dev), &dev_attr_ports_digi_flag);
6808 rc |= device_create_file(&(bd->pdev->dev), &dev_attr_ports_rxcount);
6809 rc |= device_create_file(&(bd->pdev->dev), &dev_attr_ports_txcount);
6811 printk(KERN_ERR "DGAP: sysfs device_create_file failed!\n");
6816 /* removes all the sys files created for that port */
6817 void dgap_remove_ports_sysfiles(struct board_t *bd)
6819 device_remove_file(&(bd->pdev->dev), &dev_attr_ports_state);
6820 device_remove_file(&(bd->pdev->dev), &dev_attr_ports_baud);
6821 device_remove_file(&(bd->pdev->dev), &dev_attr_ports_msignals);
6822 device_remove_file(&(bd->pdev->dev), &dev_attr_ports_iflag);
6823 device_remove_file(&(bd->pdev->dev), &dev_attr_ports_cflag);
6824 device_remove_file(&(bd->pdev->dev), &dev_attr_ports_oflag);
6825 device_remove_file(&(bd->pdev->dev), &dev_attr_ports_lflag);
6826 device_remove_file(&(bd->pdev->dev), &dev_attr_ports_digi_flag);
6827 device_remove_file(&(bd->pdev->dev), &dev_attr_ports_rxcount);
6828 device_remove_file(&(bd->pdev->dev), &dev_attr_ports_txcount);
6832 static ssize_t dgap_tty_state_show(struct device *d, struct device_attribute *attr, char *buf)
6835 struct channel_t *ch;
6840 un = dev_get_drvdata(d);
6841 if (!un || un->magic != DGAP_UNIT_MAGIC)
6844 if (!ch || ch->magic != DGAP_CHANNEL_MAGIC)
6847 if (!bd || bd->magic != DGAP_BOARD_MAGIC)
6849 if (bd->state != BOARD_READY)
6852 return snprintf(buf, PAGE_SIZE, "%s", un->un_open_count ? "Open" : "Closed");
6854 static DEVICE_ATTR(state, S_IRUSR, dgap_tty_state_show, NULL);
6857 static ssize_t dgap_tty_baud_show(struct device *d, struct device_attribute *attr, char *buf)
6860 struct channel_t *ch;
6865 un = dev_get_drvdata(d);
6866 if (!un || un->magic != DGAP_UNIT_MAGIC)
6869 if (!ch || ch->magic != DGAP_CHANNEL_MAGIC)
6872 if (!bd || bd->magic != DGAP_BOARD_MAGIC)
6874 if (bd->state != BOARD_READY)
6877 return snprintf(buf, PAGE_SIZE, "%d\n", ch->ch_baud_info);
6879 static DEVICE_ATTR(baud, S_IRUSR, dgap_tty_baud_show, NULL);
6882 static ssize_t dgap_tty_msignals_show(struct device *d, struct device_attribute *attr, char *buf)
6885 struct channel_t *ch;
6890 un = dev_get_drvdata(d);
6891 if (!un || un->magic != DGAP_UNIT_MAGIC)
6894 if (!ch || ch->magic != DGAP_CHANNEL_MAGIC)
6897 if (!bd || bd->magic != DGAP_BOARD_MAGIC)
6899 if (bd->state != BOARD_READY)
6902 if (ch->ch_open_count) {
6903 return snprintf(buf, PAGE_SIZE, "%s %s %s %s %s %s\n",
6904 (ch->ch_mostat & UART_MCR_RTS) ? "RTS" : "",
6905 (ch->ch_mistat & UART_MSR_CTS) ? "CTS" : "",
6906 (ch->ch_mostat & UART_MCR_DTR) ? "DTR" : "",
6907 (ch->ch_mistat & UART_MSR_DSR) ? "DSR" : "",
6908 (ch->ch_mistat & UART_MSR_DCD) ? "DCD" : "",
6909 (ch->ch_mistat & UART_MSR_RI) ? "RI" : "");
6913 static DEVICE_ATTR(msignals, S_IRUSR, dgap_tty_msignals_show, NULL);
6916 static ssize_t dgap_tty_iflag_show(struct device *d, struct device_attribute *attr, char *buf)
6919 struct channel_t *ch;
6924 un = dev_get_drvdata(d);
6925 if (!un || un->magic != DGAP_UNIT_MAGIC)
6928 if (!ch || ch->magic != DGAP_CHANNEL_MAGIC)
6931 if (!bd || bd->magic != DGAP_BOARD_MAGIC)
6933 if (bd->state != BOARD_READY)
6936 return snprintf(buf, PAGE_SIZE, "%x\n", ch->ch_c_iflag);
6938 static DEVICE_ATTR(iflag, S_IRUSR, dgap_tty_iflag_show, NULL);
6941 static ssize_t dgap_tty_cflag_show(struct device *d, struct device_attribute *attr, char *buf)
6944 struct channel_t *ch;
6949 un = dev_get_drvdata(d);
6950 if (!un || un->magic != DGAP_UNIT_MAGIC)
6953 if (!ch || ch->magic != DGAP_CHANNEL_MAGIC)
6956 if (!bd || bd->magic != DGAP_BOARD_MAGIC)
6958 if (bd->state != BOARD_READY)
6961 return snprintf(buf, PAGE_SIZE, "%x\n", ch->ch_c_cflag);
6963 static DEVICE_ATTR(cflag, S_IRUSR, dgap_tty_cflag_show, NULL);
6966 static ssize_t dgap_tty_oflag_show(struct device *d, struct device_attribute *attr, char *buf)
6969 struct channel_t *ch;
6974 un = dev_get_drvdata(d);
6975 if (!un || un->magic != DGAP_UNIT_MAGIC)
6978 if (!ch || ch->magic != DGAP_CHANNEL_MAGIC)
6981 if (!bd || bd->magic != DGAP_BOARD_MAGIC)
6983 if (bd->state != BOARD_READY)
6986 return snprintf(buf, PAGE_SIZE, "%x\n", ch->ch_c_oflag);
6988 static DEVICE_ATTR(oflag, S_IRUSR, dgap_tty_oflag_show, NULL);
6991 static ssize_t dgap_tty_lflag_show(struct device *d, struct device_attribute *attr, char *buf)
6994 struct channel_t *ch;
6999 un = dev_get_drvdata(d);
7000 if (!un || un->magic != DGAP_UNIT_MAGIC)
7003 if (!ch || ch->magic != DGAP_CHANNEL_MAGIC)
7006 if (!bd || bd->magic != DGAP_BOARD_MAGIC)
7008 if (bd->state != BOARD_READY)
7011 return snprintf(buf, PAGE_SIZE, "%x\n", ch->ch_c_lflag);
7013 static DEVICE_ATTR(lflag, S_IRUSR, dgap_tty_lflag_show, NULL);
7016 static ssize_t dgap_tty_digi_flag_show(struct device *d, struct device_attribute *attr, char *buf)
7019 struct channel_t *ch;
7024 un = dev_get_drvdata(d);
7025 if (!un || un->magic != DGAP_UNIT_MAGIC)
7028 if (!ch || ch->magic != DGAP_CHANNEL_MAGIC)
7031 if (!bd || bd->magic != DGAP_BOARD_MAGIC)
7033 if (bd->state != BOARD_READY)
7036 return snprintf(buf, PAGE_SIZE, "%x\n", ch->ch_digi.digi_flags);
7038 static DEVICE_ATTR(digi_flag, S_IRUSR, dgap_tty_digi_flag_show, NULL);
7041 static ssize_t dgap_tty_rxcount_show(struct device *d, struct device_attribute *attr, char *buf)
7044 struct channel_t *ch;
7049 un = dev_get_drvdata(d);
7050 if (!un || un->magic != DGAP_UNIT_MAGIC)
7053 if (!ch || ch->magic != DGAP_CHANNEL_MAGIC)
7056 if (!bd || bd->magic != DGAP_BOARD_MAGIC)
7058 if (bd->state != BOARD_READY)
7061 return snprintf(buf, PAGE_SIZE, "%ld\n", ch->ch_rxcount);
7063 static DEVICE_ATTR(rxcount, S_IRUSR, dgap_tty_rxcount_show, NULL);
7066 static ssize_t dgap_tty_txcount_show(struct device *d, struct device_attribute *attr, char *buf)
7069 struct channel_t *ch;
7074 un = dev_get_drvdata(d);
7075 if (!un || un->magic != DGAP_UNIT_MAGIC)
7078 if (!ch || ch->magic != DGAP_CHANNEL_MAGIC)
7081 if (!bd || bd->magic != DGAP_BOARD_MAGIC)
7083 if (bd->state != BOARD_READY)
7086 return snprintf(buf, PAGE_SIZE, "%ld\n", ch->ch_txcount);
7088 static DEVICE_ATTR(txcount, S_IRUSR, dgap_tty_txcount_show, NULL);
7091 static ssize_t dgap_tty_name_show(struct device *d, struct device_attribute *attr, char *buf)
7094 struct channel_t *ch;
7098 struct cnode *cptr = NULL;
7106 un = dev_get_drvdata(d);
7107 if (!un || un->magic != DGAP_UNIT_MAGIC)
7110 if (!ch || ch->magic != DGAP_CHANNEL_MAGIC)
7113 if (!bd || bd->magic != DGAP_BOARD_MAGIC)
7115 if (bd->state != BOARD_READY)
7119 cn = ch->ch_portnum;
7121 for (cptr = bd->bd_config; cptr; cptr = cptr->next) {
7123 if ((cptr->type == BNODE) &&
7124 ((cptr->u.board.type == APORT2_920P) || (cptr->u.board.type == APORT4_920P) ||
7125 (cptr->u.board.type == APORT8_920P) || (cptr->u.board.type == PAPORT4) ||
7126 (cptr->u.board.type == PAPORT8))) {
7129 if (cptr->u.board.v_start)
7130 starto = cptr->u.board.start;
7135 if (cptr->type == TNODE && found == TRUE) {
7137 if (strstr(cptr->u.ttyname, "tty")) {
7138 ptr1 = cptr->u.ttyname;
7142 ptr1 = cptr->u.ttyname;
7145 for (i = 0; i < dgap_config_get_number_of_ports(bd); i++) {
7147 return snprintf(buf, PAGE_SIZE, "%s%s%02d\n",
7148 (un->un_type == DGAP_PRINT) ? "pr" : "tty",
7154 if (cptr->type == CNODE) {
7156 for (i = 0; i < cptr->u.conc.nport; i++) {
7157 if (cn == (i + ncount)) {
7159 return snprintf(buf, PAGE_SIZE, "%s%s%02d\n",
7160 (un->un_type == DGAP_PRINT) ? "pr" : "tty",
7162 i + (cptr->u.conc.v_start ? cptr->u.conc.start : 1));
7166 ncount += cptr->u.conc.nport;
7169 if (cptr->type == MNODE) {
7171 for (i = 0; i < cptr->u.module.nport; i++) {
7172 if (cn == (i + ncount)) {
7173 return snprintf(buf, PAGE_SIZE, "%s%s%02d\n",
7174 (un->un_type == DGAP_PRINT) ? "pr" : "tty",
7176 i + (cptr->u.module.v_start ? cptr->u.module.start : 1));
7180 ncount += cptr->u.module.nport;
7185 return snprintf(buf, PAGE_SIZE, "%s_dgap_%d_%d\n",
7186 (un->un_type == DGAP_PRINT) ? "pr" : "tty", bn, cn);
7189 static DEVICE_ATTR(custom_name, S_IRUSR, dgap_tty_name_show, NULL);
7192 static struct attribute *dgap_sysfs_tty_entries[] = {
7193 &dev_attr_state.attr,
7194 &dev_attr_baud.attr,
7195 &dev_attr_msignals.attr,
7196 &dev_attr_iflag.attr,
7197 &dev_attr_cflag.attr,
7198 &dev_attr_oflag.attr,
7199 &dev_attr_lflag.attr,
7200 &dev_attr_digi_flag.attr,
7201 &dev_attr_rxcount.attr,
7202 &dev_attr_txcount.attr,
7203 &dev_attr_custom_name.attr,
7208 static struct attribute_group dgap_tty_attribute_group = {
7210 .attrs = dgap_sysfs_tty_entries,
7216 void dgap_create_tty_sysfs(struct un_t *un, struct device *c)
7220 ret = sysfs_create_group(&c->kobj, &dgap_tty_attribute_group);
7222 printk(KERN_ERR "dgap: failed to create sysfs tty device attributes.\n");
7223 sysfs_remove_group(&c->kobj, &dgap_tty_attribute_group);
7227 dev_set_drvdata(c, un);
7232 void dgap_remove_tty_sysfs(struct device *c)
7234 sysfs_remove_group(&c->kobj, &dgap_tty_attribute_group);
7238 * Parse a configuration file read into memory as a string.
7240 int dgap_parsefile(char **in, int Remove)
7242 struct cnode *p, *brd, *line, *conc;
7244 char *s = NULL, *s2 = NULL;
7248 brd = line = conc = NULL;
7250 /* perhaps we are adding to an existing list? */
7251 while (p->next != NULL) {
7255 /* file must start with a BEGIN */
7256 while ( (rc = dgap_gettok(in,p)) != BEGIN ) {
7258 dgap_err("unexpected EOF");
7264 rc = dgap_gettok(in,p);
7266 dgap_err("unexpected EOF");
7272 dgap_err("unexpected end of file");
7275 case BEGIN: /* should only be 1 begin */
7276 dgap_err("unexpected config_begin\n");
7282 case BOARD: /* board info */
7283 if (dgap_checknode(p))
7285 if ( (p->next = dgap_newnode(BNODE)) == NULL ) {
7286 dgap_err("out of memory");
7291 p->u.board.status = dgap_savestring("No");
7297 case APORT2_920P: /* AccelePort_4 */
7298 if (p->type != BNODE) {
7299 dgap_err("unexpected Digi_2r_920 string");
7302 p->u.board.type = APORT2_920P;
7303 p->u.board.v_type = 1;
7304 DPR_INIT(("Adding Digi_2r_920 PCI to config...\n"));
7307 case APORT4_920P: /* AccelePort_4 */
7308 if (p->type != BNODE) {
7309 dgap_err("unexpected Digi_4r_920 string");
7312 p->u.board.type = APORT4_920P;
7313 p->u.board.v_type = 1;
7314 DPR_INIT(("Adding Digi_4r_920 PCI to config...\n"));
7317 case APORT8_920P: /* AccelePort_8 */
7318 if (p->type != BNODE) {
7319 dgap_err("unexpected Digi_8r_920 string");
7322 p->u.board.type = APORT8_920P;
7323 p->u.board.v_type = 1;
7324 DPR_INIT(("Adding Digi_8r_920 PCI to config...\n"));
7327 case PAPORT4: /* AccelePort_4 PCI */
7328 if (p->type != BNODE) {
7329 dgap_err("unexpected Digi_4r(PCI) string");
7332 p->u.board.type = PAPORT4;
7333 p->u.board.v_type = 1;
7334 DPR_INIT(("Adding Digi_4r PCI to config...\n"));
7337 case PAPORT8: /* AccelePort_8 PCI */
7338 if (p->type != BNODE) {
7339 dgap_err("unexpected Digi_8r string");
7342 p->u.board.type = PAPORT8;
7343 p->u.board.v_type = 1;
7344 DPR_INIT(("Adding Digi_8r PCI to config...\n"));
7347 case PCX: /* PCI C/X */
7348 if (p->type != BNODE) {
7349 dgap_err("unexpected Digi_C/X_(PCI) string");
7352 p->u.board.type = PCX;
7353 p->u.board.v_type = 1;
7354 p->u.board.conc1 = 0;
7355 p->u.board.conc2 = 0;
7356 p->u.board.module1 = 0;
7357 p->u.board.module2 = 0;
7358 DPR_INIT(("Adding PCI C/X to config...\n"));
7361 case PEPC: /* PCI EPC/X */
7362 if (p->type != BNODE) {
7363 dgap_err("unexpected \"Digi_EPC/X_(PCI)\" string");
7366 p->u.board.type = PEPC;
7367 p->u.board.v_type = 1;
7368 p->u.board.conc1 = 0;
7369 p->u.board.conc2 = 0;
7370 p->u.board.module1 = 0;
7371 p->u.board.module2 = 0;
7372 DPR_INIT(("Adding PCI EPC/X to config...\n"));
7375 case PPCM: /* PCI/Xem */
7376 if (p->type != BNODE) {
7377 dgap_err("unexpected PCI/Xem string");
7380 p->u.board.type = PPCM;
7381 p->u.board.v_type = 1;
7382 p->u.board.conc1 = 0;
7383 p->u.board.conc2 = 0;
7384 DPR_INIT(("Adding PCI XEM to config...\n"));
7387 case IO: /* i/o port */
7388 if (p->type != BNODE) {
7389 dgap_err("IO port only vaild for boards");
7392 s = dgap_getword(in);
7394 dgap_err("unexpected end of file");
7397 p->u.board.portstr = dgap_savestring(s);
7398 p->u.board.port = (short)simple_strtol(s, &s2, 0);
7399 if ((short)strlen(s) > (short)(s2 - s)) {
7400 dgap_err("bad number for IO port");
7403 p->u.board.v_port = 1;
7404 DPR_INIT(("Adding IO (%s) to config...\n", s));
7407 case MEM: /* memory address */
7408 if (p->type != BNODE) {
7409 dgap_err("memory address only vaild for boards");
7412 s = dgap_getword(in);
7414 dgap_err("unexpected end of file");
7417 p->u.board.addrstr = dgap_savestring(s);
7418 p->u.board.addr = simple_strtoul(s, &s2, 0);
7419 if ((int)strlen(s) > (int)(s2 - s)) {
7420 dgap_err("bad number for memory address");
7423 p->u.board.v_addr = 1;
7424 DPR_INIT(("Adding MEM (%s) to config...\n", s));
7427 case PCIINFO: /* pci information */
7428 if (p->type != BNODE) {
7429 dgap_err("memory address only vaild for boards");
7432 s = dgap_getword(in);
7434 dgap_err("unexpected end of file");
7437 p->u.board.pcibusstr = dgap_savestring(s);
7438 p->u.board.pcibus = simple_strtoul(s, &s2, 0);
7439 if ((int)strlen(s) > (int)(s2 - s)) {
7440 dgap_err("bad number for pci bus");
7443 p->u.board.v_pcibus = 1;
7444 s = dgap_getword(in);
7446 dgap_err("unexpected end of file");
7449 p->u.board.pcislotstr = dgap_savestring(s);
7450 p->u.board.pcislot = simple_strtoul(s, &s2, 0);
7451 if ((int)strlen(s) > (int)(s2 - s)) {
7452 dgap_err("bad number for pci slot");
7455 p->u.board.v_pcislot = 1;
7457 DPR_INIT(("Adding PCIINFO (%s %s) to config...\n", p->u.board.pcibusstr,
7458 p->u.board.pcislotstr));
7462 if (p->type != BNODE) {
7463 dgap_err("install method only vaild for boards");
7466 s = dgap_getword(in);
7468 dgap_err("unexpected end of file");
7471 p->u.board.method = dgap_savestring(s);
7472 p->u.board.v_method = 1;
7473 DPR_INIT(("Adding METHOD (%s) to config...\n", s));
7477 if (p->type != BNODE) {
7478 dgap_err("config status only vaild for boards");
7481 s = dgap_getword(in);
7483 dgap_err("unexpected end of file");
7486 p->u.board.status = dgap_savestring(s);
7487 DPR_INIT(("Adding STATUS (%s) to config...\n", s));
7490 case NPORTS: /* number of ports */
7491 if (p->type == BNODE) {
7492 s = dgap_getword(in);
7494 dgap_err("unexpected end of file");
7497 p->u.board.nport = (char)simple_strtol(s, &s2, 0);
7498 if ((int)strlen(s) > (int)(s2 - s)) {
7499 dgap_err("bad number for number of ports");
7502 p->u.board.v_nport = 1;
7503 } else if (p->type == CNODE) {
7504 s = dgap_getword(in);
7506 dgap_err("unexpected end of file");
7509 p->u.conc.nport = (char)simple_strtol(s, &s2, 0);
7510 if ((int)strlen(s) > (int)(s2 - s)) {
7511 dgap_err("bad number for number of ports");
7514 p->u.conc.v_nport = 1;
7515 } else if (p->type == MNODE) {
7516 s = dgap_getword(in);
7518 dgap_err("unexpected end of file");
7521 p->u.module.nport = (char)simple_strtol(s, &s2, 0);
7522 if ((int)strlen(s) > (int)(s2 - s)) {
7523 dgap_err("bad number for number of ports");
7526 p->u.module.v_nport = 1;
7528 dgap_err("nports only valid for concentrators or modules");
7531 DPR_INIT(("Adding NPORTS (%s) to config...\n", s));
7534 case ID: /* letter ID used in tty name */
7535 s = dgap_getword(in);
7537 dgap_err("unexpected end of file");
7541 p->u.board.status = dgap_savestring(s);
7543 if (p->type == CNODE) {
7544 p->u.conc.id = dgap_savestring(s);
7546 } else if (p->type == MNODE) {
7547 p->u.module.id = dgap_savestring(s);
7548 p->u.module.v_id = 1;
7550 dgap_err("id only valid for concentrators or modules");
7553 DPR_INIT(("Adding ID (%s) to config...\n", s));
7556 case STARTO: /* start offset of ID */
7557 if (p->type == BNODE) {
7558 s = dgap_getword(in);
7560 dgap_err("unexpected end of file");
7563 p->u.board.start = simple_strtol(s, &s2, 0);
7564 if ((int)strlen(s) > (int)(s2 - s)) {
7565 dgap_err("bad number for start of tty count");
7568 p->u.board.v_start = 1;
7569 } else if (p->type == CNODE) {
7570 s = dgap_getword(in);
7572 dgap_err("unexpected end of file");
7575 p->u.conc.start = simple_strtol(s, &s2, 0);
7576 if ((int)strlen(s) > (int)(s2 - s)) {
7577 dgap_err("bad number for start of tty count");
7580 p->u.conc.v_start = 1;
7581 } else if (p->type == MNODE) {
7582 s = dgap_getword(in);
7584 dgap_err("unexpected end of file");
7587 p->u.module.start = simple_strtol(s, &s2, 0);
7588 if ((int)strlen(s) > (int)(s2 - s)) {
7589 dgap_err("bad number for start of tty count");
7592 p->u.module.v_start = 1;
7594 dgap_err("start only valid for concentrators or modules");
7597 DPR_INIT(("Adding START (%s) to config...\n", s));
7600 case TTYN: /* tty name prefix */
7601 if (dgap_checknode(p))
7603 if ( (p->next = dgap_newnode(TNODE)) == NULL ) {
7604 dgap_err("out of memory");
7608 if ( (s = dgap_getword(in)) == NULL ) {
7609 dgap_err("unexpeced end of file");
7612 if ( (p->u.ttyname = dgap_savestring(s)) == NULL ) {
7613 dgap_err("out of memory");
7616 DPR_INIT(("Adding TTY (%s) to config...\n", s));
7619 case CU: /* cu name prefix */
7620 if (dgap_checknode(p))
7622 if ( (p->next = dgap_newnode(CUNODE)) == NULL ) {
7623 dgap_err("out of memory");
7627 if ( (s = dgap_getword(in)) == NULL ) {
7628 dgap_err("unexpeced end of file");
7631 if ( (p->u.cuname = dgap_savestring(s)) == NULL ) {
7632 dgap_err("out of memory");
7635 DPR_INIT(("Adding CU (%s) to config...\n", s));
7638 case LINE: /* line information */
7639 if (dgap_checknode(p))
7642 dgap_err("must specify board before line info");
7645 switch (brd->u.board.type) {
7647 dgap_err("line not vaild for PC/em");
7650 if ( (p->next = dgap_newnode(LNODE)) == NULL ) {
7651 dgap_err("out of memory");
7658 DPR_INIT(("Adding LINE to config...\n"));
7661 case CONC: /* concentrator information */
7662 if (dgap_checknode(p))
7665 dgap_err("must specify line info before concentrator");
7668 if ( (p->next = dgap_newnode(CNODE)) == NULL ) {
7669 dgap_err("out of memory");
7675 brd->u.board.conc2++;
7677 brd->u.board.conc1++;
7679 DPR_INIT(("Adding CONC to config...\n"));
7682 case CX: /* c/x type concentrator */
7683 if (p->type != CNODE) {
7684 dgap_err("cx only valid for concentrators");
7687 p->u.conc.type = CX;
7688 p->u.conc.v_type = 1;
7689 DPR_INIT(("Adding CX to config...\n"));
7692 case EPC: /* epc type concentrator */
7693 if (p->type != CNODE) {
7694 dgap_err("cx only valid for concentrators");
7697 p->u.conc.type = EPC;
7698 p->u.conc.v_type = 1;
7699 DPR_INIT(("Adding EPC to config...\n"));
7702 case MOD: /* EBI module */
7703 if (dgap_checknode(p))
7706 dgap_err("must specify board info before EBI modules");
7709 switch (brd->u.board.type) {
7715 dgap_err("must specify concentrator info before EBI module");
7719 if ( (p->next = dgap_newnode(MNODE)) == NULL ) {
7720 dgap_err("out of memory");
7725 brd->u.board.module2++;
7727 brd->u.board.module1++;
7729 DPR_INIT(("Adding MOD to config...\n"));
7732 case PORTS: /* ports type EBI module */
7733 if (p->type != MNODE) {
7734 dgap_err("ports only valid for EBI modules");
7737 p->u.module.type = PORTS;
7738 p->u.module.v_type = 1;
7739 DPR_INIT(("Adding PORTS to config...\n"));
7742 case MODEM: /* ports type EBI module */
7743 if (p->type != MNODE) {
7744 dgap_err("modem only valid for modem modules");
7747 p->u.module.type = MODEM;
7748 p->u.module.v_type = 1;
7749 DPR_INIT(("Adding MODEM to config...\n"));
7753 if (p->type == LNODE) {
7754 if ((s = dgap_getword(in)) == NULL) {
7755 dgap_err("unexpected end of file");
7758 p->u.line.cable = dgap_savestring(s);
7759 p->u.line.v_cable = 1;
7761 DPR_INIT(("Adding CABLE (%s) to config...\n", s));
7764 case SPEED: /* sync line speed indication */
7765 if (p->type == LNODE) {
7766 s = dgap_getword(in);
7768 dgap_err("unexpected end of file");
7771 p->u.line.speed = (char)simple_strtol(s, &s2, 0);
7772 if ((short)strlen(s) > (short)(s2 - s)) {
7773 dgap_err("bad number for line speed");
7776 p->u.line.v_speed = 1;
7777 } else if (p->type == CNODE) {
7778 s = dgap_getword(in);
7780 dgap_err("unexpected end of file");
7783 p->u.conc.speed = (char)simple_strtol(s, &s2, 0);
7784 if ((short)strlen(s) > (short)(s2 - s)) {
7785 dgap_err("bad number for line speed");
7788 p->u.conc.v_speed = 1;
7790 dgap_err("speed valid only for lines or concentrators.");
7793 DPR_INIT(("Adding SPEED (%s) to config...\n", s));
7797 if (p->type == CNODE) {
7798 if ((s = dgap_getword(in)) == NULL) {
7799 dgap_err("unexpected end of file");
7802 p->u.conc.connect = dgap_savestring(s);
7803 p->u.conc.v_connect = 1;
7805 DPR_INIT(("Adding CONNECT (%s) to config...\n", s));
7807 case PRINT: /* transparent print name prefix */
7808 if (dgap_checknode(p))
7810 if ( (p->next = dgap_newnode(PNODE)) == NULL ) {
7811 dgap_err("out of memory");
7815 if ( (s = dgap_getword(in)) == NULL ) {
7816 dgap_err("unexpeced end of file");
7819 if ( (p->u.printname = dgap_savestring(s)) == NULL ) {
7820 dgap_err("out of memory");
7823 DPR_INIT(("Adding PRINT (%s) to config...\n", s));
7826 case CMAJOR: /* major number */
7827 if (dgap_checknode(p))
7829 if ( (p->next = dgap_newnode(JNODE)) == NULL ) {
7830 dgap_err("out of memory");
7834 s = dgap_getword(in);
7836 dgap_err("unexpected end of file");
7839 p->u.majornumber = simple_strtol(s, &s2, 0);
7840 if ((int)strlen(s) > (int)(s2 - s)) {
7841 dgap_err("bad number for major number");
7844 DPR_INIT(("Adding CMAJOR (%s) to config...\n", s));
7847 case ALTPIN: /* altpin setting */
7848 if (dgap_checknode(p))
7850 if ( (p->next = dgap_newnode(ANODE)) == NULL ) {
7851 dgap_err("out of memory");
7855 s = dgap_getword(in);
7857 dgap_err("unexpected end of file");
7860 p->u.altpin = simple_strtol(s, &s2, 0);
7861 if ((int)strlen(s) > (int)(s2 - s)) {
7862 dgap_err("bad number for altpin");
7865 DPR_INIT(("Adding ALTPIN (%s) to config...\n", s));
7868 case USEINTR: /* enable interrupt setting */
7869 if (dgap_checknode(p))
7871 if ( (p->next = dgap_newnode(INTRNODE)) == NULL ) {
7872 dgap_err("out of memory");
7876 s = dgap_getword(in);
7878 dgap_err("unexpected end of file");
7881 p->u.useintr = simple_strtol(s, &s2, 0);
7882 if ((int)strlen(s) > (int)(s2 - s)) {
7883 dgap_err("bad number for useintr");
7886 DPR_INIT(("Adding USEINTR (%s) to config...\n", s));
7889 case TTSIZ: /* size of tty structure */
7890 if (dgap_checknode(p))
7892 if ( (p->next = dgap_newnode(TSNODE)) == NULL ) {
7893 dgap_err("out of memory");
7897 s = dgap_getword(in);
7899 dgap_err("unexpected end of file");
7902 p->u.ttysize = simple_strtol(s, &s2, 0);
7903 if ((int)strlen(s) > (int)(s2 - s)) {
7904 dgap_err("bad number for ttysize");
7907 DPR_INIT(("Adding TTSIZ (%s) to config...\n", s));
7910 case CHSIZ: /* channel structure size */
7911 if (dgap_checknode(p))
7913 if ( (p->next = dgap_newnode(CSNODE)) == NULL ) {
7914 dgap_err("out of memory");
7918 s = dgap_getword(in);
7920 dgap_err("unexpected end of file");
7923 p->u.chsize = simple_strtol(s, &s2, 0);
7924 if ((int)strlen(s) > (int)(s2 - s)) {
7925 dgap_err("bad number for chsize");
7928 DPR_INIT(("Adding CHSIZE (%s) to config...\n", s));
7931 case BSSIZ: /* board structure size */
7932 if (dgap_checknode(p))
7934 if ( (p->next = dgap_newnode(BSNODE)) == NULL ) {
7935 dgap_err("out of memory");
7939 s = dgap_getword(in);
7941 dgap_err("unexpected end of file");
7944 p->u.bssize = simple_strtol(s, &s2, 0);
7945 if ((int)strlen(s) > (int)(s2 - s)) {
7946 dgap_err("bad number for bssize");
7949 DPR_INIT(("Adding BSSIZ (%s) to config...\n", s));
7952 case UNTSIZ: /* sched structure size */
7953 if (dgap_checknode(p))
7955 if ( (p->next = dgap_newnode(USNODE)) == NULL ) {
7956 dgap_err("out of memory");
7960 s = dgap_getword(in);
7962 dgap_err("unexpected end of file");
7965 p->u.unsize = simple_strtol(s, &s2, 0);
7966 if ((int)strlen(s) > (int)(s2 - s)) {
7967 dgap_err("bad number for schedsize");
7970 DPR_INIT(("Adding UNTSIZ (%s) to config...\n", s));
7973 case F2SIZ: /* f2200 structure size */
7974 if (dgap_checknode(p))
7976 if ( (p->next = dgap_newnode(FSNODE)) == NULL ) {
7977 dgap_err("out of memory");
7981 s = dgap_getword(in);
7983 dgap_err("unexpected end of file");
7986 p->u.f2size = simple_strtol(s, &s2, 0);
7987 if ((int)strlen(s) > (int)(s2 - s)) {
7988 dgap_err("bad number for f2200size");
7991 DPR_INIT(("Adding F2SIZ (%s) to config...\n", s));
7994 case VPSIZ: /* vpix structure size */
7995 if (dgap_checknode(p))
7997 if ( (p->next = dgap_newnode(VSNODE)) == NULL ) {
7998 dgap_err("out of memory");
8002 s = dgap_getword(in);
8004 dgap_err("unexpected end of file");
8007 p->u.vpixsize = simple_strtol(s, &s2, 0);
8008 if ((int)strlen(s) > (int)(s2 - s)) {
8009 dgap_err("bad number for vpixsize");
8012 DPR_INIT(("Adding VPSIZ (%s) to config...\n", s));
8020 * dgap_sindex: much like index(), but it looks for a match of any character in
8021 * the group, and returns that position. If the first character is a ^, then
8022 * this will match the first occurrence not in that group.
8024 static char *dgap_sindex (char *string, char *group)
8028 if (!string || !group)
8029 return (char *) NULL;
8031 if (*group == '^') {
8033 for (; *string; string++) {
8034 for (ptr = group; *ptr; ptr++) {
8035 if (*ptr == *string)
8043 for (; *string; string++) {
8044 for (ptr = group; *ptr; ptr++) {
8045 if (*ptr == *string)
8051 return (char *) NULL;
8056 * Get a token from the input file; return 0 if end of file is reached
8058 static int dgap_gettok(char **in, struct cnode *p)
8063 if (strstr(dgap_cword, "boar")) {
8064 w = dgap_getword(in);
8065 snprintf(dgap_cword, MAXCWORD, "%s", w);
8066 for (t = dgap_tlist; t->token != 0; t++) {
8067 if ( !strcmp(w, t->string)) {
8071 dgap_err("board !!type not specified");
8075 while ( (w = dgap_getword(in)) != NULL ) {
8076 snprintf(dgap_cword, MAXCWORD, "%s", w);
8077 for (t = dgap_tlist; t->token != 0; t++) {
8078 if ( !strcmp(w, t->string) )
8088 * get a word from the input stream, also keep track of current line number.
8089 * words are separated by whitespace.
8091 static char *dgap_getword(char **in)
8093 char *ret_ptr = *in;
8095 char *ptr = dgap_sindex(*in, " \t\n");
8097 /* If no word found, return null */
8101 /* Mark new location for our buffer */
8105 /* Eat any extra spaces/tabs/newlines that might be present */
8106 while (*in && **in && ((**in == ' ') || (**in == '\t') || (**in == '\n'))) {
8116 * print an error message, giving the line number in the file where
8117 * the error occurred.
8119 static void dgap_err(char *s)
8121 printk("DGAP: parse: %s\n", s);
8126 * allocate a new configuration node of type t
8128 static struct cnode *dgap_newnode(int t)
8132 n = kmalloc(sizeof(struct cnode), GFP_ATOMIC);
8134 memset((char *)n, 0, sizeof(struct cnode));
8142 * dgap_checknode: see if all the necessary info has been supplied for a node
8143 * before creating the next node.
8145 static int dgap_checknode(struct cnode *p)
8149 if (p->u.board.v_type == 0) {
8150 dgap_err("board type !not specified");
8157 if (p->u.line.v_speed == 0) {
8158 dgap_err("line speed not specified");
8164 if (p->u.conc.v_type == 0) {
8165 dgap_err("concentrator type not specified");
8168 if (p->u.conc.v_speed == 0) {
8169 dgap_err("concentrator line speed not specified");
8172 if (p->u.conc.v_nport == 0) {
8173 dgap_err("number of ports on concentrator not specified");
8176 if (p->u.conc.v_id == 0) {
8177 dgap_err("concentrator id letter not specified");
8183 if (p->u.module.v_type == 0) {
8184 dgap_err("EBI module type not specified");
8187 if (p->u.module.v_nport == 0) {
8188 dgap_err("number of ports on EBI module not specified");
8191 if (p->u.module.v_id == 0) {
8192 dgap_err("EBI module id letter not specified");
8201 * save a string somewhere
8203 static char *dgap_savestring(char *s)
8206 if ( (p = kmalloc(strlen(s) + 1, GFP_ATOMIC) ) != NULL) {
8214 * Given a board pointer, returns whether we should use interrupts or not.
8216 uint dgap_config_get_useintr(struct board_t *bd)
8218 struct cnode *p = NULL;
8223 for (p = bd->bd_config; p; p = p->next) {
8227 * check for pcxr types.
8229 return p->u.useintr;
8235 /* If not found, then don't turn on interrupts. */
8241 * Given a board pointer, returns whether we turn on altpin or not.
8243 uint dgap_config_get_altpin(struct board_t *bd)
8245 struct cnode *p = NULL;
8250 for (p = bd->bd_config; p; p = p->next) {
8254 * check for pcxr types.
8262 /* If not found, then don't turn on interrupts. */
8269 * Given a specific type of board, if found, detached link and
8270 * returns the first occurrence in the list.
8272 struct cnode *dgap_find_config(int type, int bus, int slot)
8274 struct cnode *p, *prev = NULL, *prev2 = NULL, *found = NULL;
8278 while (p->next != NULL) {
8282 if (p->type == BNODE) {
8284 if (p->u.board.type == type) {
8286 if (p->u.board.v_pcibus && p->u.board.pcibus != bus) {
8287 DPR(("Found matching board, but wrong bus position. System says bus %d, we want bus %ld\n",
8288 bus, p->u.board.pcibus));
8291 if (p->u.board.v_pcislot && p->u.board.pcislot != slot) {
8292 DPR_INIT(("Found matching board, but wrong slot position. System says slot %d, we want slot %ld\n",
8293 slot, p->u.board.pcislot));
8297 DPR_INIT(("Matched type in config file\n"));
8301 * Keep walking thru the list till we find the next board.
8303 while (p->next != NULL) {
8306 if (p->type == BNODE) {
8309 * Mark the end of our 1 board chain of configs.
8314 * Link the "next" board to the previous board,
8315 * effectively "unlinking" our board from the main config.
8323 * It must be the last board in the list.
8334 * Given a board pointer, walks the config link, counting up
8335 * all ports user specified should be on the board.
8336 * (This does NOT mean they are all actually present right now tho)
8338 uint dgap_config_get_number_of_ports(struct board_t *bd)
8341 struct cnode *p = NULL;
8346 for (p = bd->bd_config; p; p = p->next) {
8351 * check for pcxr types.
8353 if (p->u.board.type > EPCFE)
8354 count += p->u.board.nport;
8357 count += p->u.conc.nport;
8360 count += p->u.module.nport;
8367 char *dgap_create_config_string(struct board_t *bd, char *string)
8370 struct cnode *p = NULL;
8371 struct cnode *q = NULL;
8379 for (p = bd->bd_config; p; p = p->next) {
8385 *ptr = p->u.line.speed;
8390 * Because the EPC/con concentrators can have EM modules
8391 * hanging off of them, we have to walk ahead in the list
8392 * and keep adding the number of ports on each EM to the config.
8395 speed = p->u.conc.speed;
8397 if ((q != NULL) && (q->type == MNODE) ) {
8398 *ptr = (p->u.conc.nport + 0x80);
8401 while ((q->next != NULL) && (q->next->type) == MNODE) {
8402 *ptr = (q->u.module.nport + 0x80);
8407 *ptr = q->u.module.nport;
8410 *ptr = p->u.conc.nport;
8426 char *dgap_get_config_letters(struct board_t *bd, char *string)
8430 struct cnode *cptr = NULL;
8432 int left = MAXTTYNAMELEN;
8438 for (cptr = bd->bd_config; cptr; cptr = cptr->next) {
8440 if ((cptr->type == BNODE) &&
8441 ((cptr->u.board.type == APORT2_920P) || (cptr->u.board.type == APORT4_920P) ||
8442 (cptr->u.board.type == APORT8_920P) || (cptr->u.board.type == PAPORT4) ||
8443 (cptr->u.board.type == PAPORT8))) {
8448 if (cptr->type == TNODE && found == TRUE) {
8450 if (strstr(cptr->u.ttyname, "tty")) {
8451 ptr1 = cptr->u.ttyname;
8455 ptr1 = cptr->u.ttyname;
8458 len = snprintf(ptr, left, "%s", ptr1);
8466 if (cptr->type == CNODE) {
8467 if (cptr->u.conc.id) {
8468 len = snprintf(ptr, left, "%s", cptr->u.conc.id);
8476 if (cptr->type == MNODE) {
8477 if (cptr->u.module.id) {
8478 len = snprintf(ptr, left, "%s", cptr->u.module.id);