2 * Copyright 2003 Digi International (www.digi.com)
3 * Scott H Kilau <Scott_Kilau at digi dot com>
5 * This program is free software; you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published by
7 * the Free Software Foundation; either version 2, or (at your option)
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY, EXPRESS OR IMPLIED; without even the
12 * implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
13 * PURPOSE. See the GNU General Public License for more details.
15 * You should have received a copy of the GNU General Public License
16 * along with this program; if not, write to the Free Software
17 * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
20 * NOTE TO LINUX KERNEL HACKERS: DO NOT REFORMAT THIS CODE!
22 * This is shared code between Digi's CVS archive and the
23 * Linux Kernel sources.
24 * Changing the source just for reformatting needlessly breaks
25 * our CVS diff history.
27 * Send any bug fixes/changes to: Eng.Linux at digi dot com.
33 #include <linux/kernel.h>
34 #include <linux/module.h>
35 #include <linux/pci.h>
36 #include <linux/delay.h> /* For udelay */
37 #include <linux/slab.h>
38 #include <asm/uaccess.h> /* For copy_from_user/copy_to_user */
39 #include <linux/sched.h>
41 #include <linux/interrupt.h> /* For tasklet and interrupt structs/defines */
42 #include <linux/ctype.h>
43 #include <linux/tty.h>
44 #include <linux/tty_flip.h>
45 #include <linux/serial_reg.h>
46 #include <asm/io.h> /* For read[bwl]/write[bwl] */
48 #include <linux/string.h>
49 #include <linux/device.h>
50 #include <linux/kdev_t.h>
52 #include "dgap_driver.h"
54 #include "dgap_conf.h"
55 #include "dgap_parse.h"
56 #include "dgap_types.h"
58 #define init_MUTEX(sem) sema_init(sem, 1)
59 #define DECLARE_MUTEX(name) \
60 struct semaphore name = __SEMAPHORE_INITIALIZER(name, 1)
62 MODULE_LICENSE("GPL");
63 MODULE_AUTHOR("Digi International, http://www.digi.com");
64 MODULE_DESCRIPTION("Driver for the Digi International EPCA PCI based product line");
65 MODULE_SUPPORTED_DEVICE("dgap");
68 * insmod command line overrideable parameters
70 * NOTE: we use a set of macros to create the variables, which allows
71 * us to specify the variable type, name, initial value, and description.
73 PARM_INT(debug, 0x00, 0644, "Driver debugging level");
74 PARM_INT(rawreadok, 1, 0644, "Bypass flip buffers on input");
75 PARM_INT(trcbuf_size, 0x100000, 0644, "Debugging trace buffer size.");
78 /**************************************************************************
80 * protos for this file
84 static int dgap_start(void);
85 static void dgap_init_globals(void);
86 static int dgap_found_board(struct pci_dev *pdev, int id);
87 static void dgap_cleanup_board(struct board_t *brd);
88 static void dgap_poll_handler(ulong dummy);
89 static int dgap_init_pci(void);
90 static int dgap_init_one(struct pci_dev *pdev, const struct pci_device_id *ent);
91 static void dgap_remove_one(struct pci_dev *dev);
92 static int dgap_probe1(struct pci_dev *pdev, int card_type);
93 static void dgap_mbuf(struct board_t *brd, const char *fmt, ...);
94 static int dgap_do_remap(struct board_t *brd);
95 static irqreturn_t dgap_intr(int irq, void *voidbrd);
97 /* Our function prototypes */
98 static int dgap_tty_open(struct tty_struct *tty, struct file *file);
99 static void dgap_tty_close(struct tty_struct *tty, struct file *file);
100 static int dgap_block_til_ready(struct tty_struct *tty, struct file *file, struct channel_t *ch);
101 static int dgap_tty_ioctl(struct tty_struct *tty, unsigned int cmd, unsigned long arg);
102 static int dgap_tty_digigeta(struct tty_struct *tty, struct digi_t __user *retinfo);
103 static int dgap_tty_digiseta(struct tty_struct *tty, struct digi_t __user *new_info);
104 static int dgap_tty_digigetedelay(struct tty_struct *tty, int __user *retinfo);
105 static int dgap_tty_digisetedelay(struct tty_struct *tty, int __user *new_info);
106 static int dgap_tty_write_room(struct tty_struct* tty);
107 static int dgap_tty_chars_in_buffer(struct tty_struct* tty);
108 static void dgap_tty_start(struct tty_struct *tty);
109 static void dgap_tty_stop(struct tty_struct *tty);
110 static void dgap_tty_throttle(struct tty_struct *tty);
111 static void dgap_tty_unthrottle(struct tty_struct *tty);
112 static void dgap_tty_flush_chars(struct tty_struct *tty);
113 static void dgap_tty_flush_buffer(struct tty_struct *tty);
114 static void dgap_tty_hangup(struct tty_struct *tty);
115 static int dgap_wait_for_drain(struct tty_struct *tty);
116 static int dgap_set_modem_info(struct tty_struct *tty, unsigned int command, unsigned int __user *value);
117 static int dgap_get_modem_info(struct channel_t *ch, unsigned int __user *value);
118 static int dgap_tty_digisetcustombaud(struct tty_struct *tty, int __user *new_info);
119 static int dgap_tty_digigetcustombaud(struct tty_struct *tty, int __user *retinfo);
120 static int dgap_tty_tiocmget(struct tty_struct *tty);
121 static int dgap_tty_tiocmset(struct tty_struct *tty, unsigned int set, unsigned int clear);
122 static int dgap_tty_send_break(struct tty_struct *tty, int msec);
123 static void dgap_tty_wait_until_sent(struct tty_struct *tty, int timeout);
124 static int dgap_tty_write(struct tty_struct *tty, const unsigned char *buf, int count);
125 static void dgap_tty_set_termios(struct tty_struct *tty, struct ktermios *old_termios);
126 static int dgap_tty_put_char(struct tty_struct *tty, unsigned char c);
127 static void dgap_tty_send_xchar(struct tty_struct *tty, char ch);
129 int dgap_tty_register(struct board_t *brd);
130 int dgap_tty_preinit(void);
131 int dgap_tty_init(struct board_t *);
132 void dgap_tty_post_uninit(void);
133 void dgap_tty_uninit(struct board_t *);
134 void dgap_carrier(struct channel_t *ch);
135 void dgap_input(struct channel_t *ch);
138 * Our function prototypes from dgap_fep5
140 static void dgap_cmdw_ext(struct channel_t *ch, u16 cmd, u16 word, uint ncmds);
141 static int dgap_event(struct board_t *bd);
144 * Function prototypes from dgap_parse.c.
146 static int dgap_gettok(char **in, struct cnode *p);
147 static char *dgap_getword(char **in);
148 static char *dgap_savestring(char *s);
149 static struct cnode *dgap_newnode(int t);
150 static int dgap_checknode(struct cnode *p);
151 static void dgap_err(char *s);
154 * Function prototypes from dgap_sysfs.h
162 void dgap_create_ports_sysfiles(struct board_t *bd);
163 void dgap_remove_ports_sysfiles(struct board_t *bd);
165 void dgap_create_driver_sysfiles(struct pci_driver *);
166 void dgap_remove_driver_sysfiles(struct pci_driver *);
168 int dgap_tty_class_init(void);
169 int dgap_tty_class_destroy(void);
171 void dgap_create_tty_sysfs(struct un_t *un, struct device *c);
172 void dgap_remove_tty_sysfs(struct device *c);
174 /* Driver load/unload functions */
175 int dgap_init_module(void);
176 void dgap_cleanup_module(void);
178 module_init(dgap_init_module);
179 module_exit(dgap_cleanup_module);
183 * File operations permitted on Control/Management major.
185 static struct file_operations DgapBoardFops =
187 .owner = THIS_MODULE,
195 struct board_t *dgap_Board[MAXBOARDS];
196 DEFINE_SPINLOCK(dgap_global_lock);
197 ulong dgap_poll_counter;
198 char *dgap_config_buf;
199 int dgap_driver_state = DRIVER_INITIALIZED;
200 DEFINE_SPINLOCK(dgap_dl_lock);
201 wait_queue_head_t dgap_dl_wait;
203 int dgap_poll_tick = 20; /* Poll interval - 20 ms */
208 static int dgap_Major_Control_Registered = FALSE;
209 static uint dgap_driver_start = FALSE;
211 static struct class * dgap_class;
213 static struct board_t *dgap_BoardsByMajor[256];
214 static uchar *dgap_TmpWriteBuf = NULL;
215 static DECLARE_MUTEX(dgap_TmpWriteSem);
216 static uint dgap_count = 500;
221 static DEFINE_SPINLOCK(dgap_poll_lock); /* Poll scheduling lock */
222 static ulong dgap_poll_time; /* Time of next poll */
223 static uint dgap_poll_stop; /* Used to tell poller to stop */
224 static struct timer_list dgap_poll_timer;
227 static struct pci_device_id dgap_pci_tbl[] = {
228 { DIGI_VID, PCI_DEVICE_XEM_DID, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0 },
229 { DIGI_VID, PCI_DEVICE_CX_DID, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 1 },
230 { DIGI_VID, PCI_DEVICE_CX_IBM_DID, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 2 },
231 { DIGI_VID, PCI_DEVICE_EPCJ_DID, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 3 },
232 { DIGI_VID, PCI_DEVICE_920_2_DID, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 4 },
233 { DIGI_VID, PCI_DEVICE_920_4_DID, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 5 },
234 { DIGI_VID, PCI_DEVICE_920_8_DID, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 6 },
235 { DIGI_VID, PCI_DEVICE_XR_DID, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 7 },
236 { DIGI_VID, PCI_DEVICE_XRJ_DID, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 8 },
237 { DIGI_VID, PCI_DEVICE_XR_422_DID, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 9 },
238 { DIGI_VID, PCI_DEVICE_XR_IBM_DID, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 10 },
239 { DIGI_VID, PCI_DEVICE_XR_SAIP_DID, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 11 },
240 { DIGI_VID, PCI_DEVICE_XR_BULL_DID, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 12 },
241 { DIGI_VID, PCI_DEVICE_920_8_HP_DID, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 13 },
242 { DIGI_VID, PCI_DEVICE_XEM_HP_DID, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 14 },
243 {0,} /* 0 terminated list. */
245 MODULE_DEVICE_TABLE(pci, dgap_pci_tbl);
249 * A generic list of Product names, PCI Vendor ID, and PCI Device ID.
258 static struct board_id dgap_Ids[] =
260 { PPCM, PCI_DEVICE_XEM_NAME, 64, (T_PCXM | T_PCLITE | T_PCIBUS) },
261 { PCX, PCI_DEVICE_CX_NAME, 128, (T_CX | T_PCIBUS) },
262 { PCX, PCI_DEVICE_CX_IBM_NAME, 128, (T_CX | T_PCIBUS) },
263 { PEPC, PCI_DEVICE_EPCJ_NAME, 224, (T_EPC | T_PCIBUS) },
264 { APORT2_920P, PCI_DEVICE_920_2_NAME, 2, (T_PCXR | T_PCLITE | T_PCIBUS) },
265 { APORT4_920P, PCI_DEVICE_920_4_NAME, 4, (T_PCXR | T_PCLITE | T_PCIBUS) },
266 { APORT8_920P, PCI_DEVICE_920_8_NAME, 8, (T_PCXR | T_PCLITE | T_PCIBUS) },
267 { PAPORT8, PCI_DEVICE_XR_NAME, 8, (T_PCXR | T_PCLITE | T_PCIBUS) },
268 { PAPORT8, PCI_DEVICE_XRJ_NAME, 8, (T_PCXR | T_PCLITE | T_PCIBUS) },
269 { PAPORT8, PCI_DEVICE_XR_422_NAME, 8, (T_PCXR | T_PCLITE | T_PCIBUS) },
270 { PAPORT8, PCI_DEVICE_XR_IBM_NAME, 8, (T_PCXR | T_PCLITE | T_PCIBUS) },
271 { PAPORT8, PCI_DEVICE_XR_SAIP_NAME, 8, (T_PCXR | T_PCLITE | T_PCIBUS) },
272 { PAPORT8, PCI_DEVICE_XR_BULL_NAME, 8, (T_PCXR | T_PCLITE | T_PCIBUS) },
273 { APORT8_920P, PCI_DEVICE_920_8_HP_NAME, 8, (T_PCXR | T_PCLITE | T_PCIBUS) },
274 { PPCM, PCI_DEVICE_XEM_HP_NAME, 64, (T_PCXM | T_PCLITE | T_PCIBUS) },
275 {0,} /* 0 terminated list. */
278 static struct pci_driver dgap_driver = {
280 .probe = dgap_init_one,
281 .id_table = dgap_pci_tbl,
282 .remove = dgap_remove_one,
286 char *dgap_state_text[] = {
288 "Configuration for board not found.\n\t\t\tRun mpi to configure board.",
294 "Need Device Creation",
295 "Requested Device Creation",
296 "Finished Device Creation",
300 "Finished BIOS Load",
305 "Requested PROC creation",
306 "Finished PROC creation",
310 char *dgap_driver_state_text[] = {
311 "Driver Initialized",
312 "Driver needs configuration load.",
313 "Driver requested configuration from download daemon.",
318 * Default transparent print information.
320 static struct digi_t dgap_digi_init = {
321 .digi_flags = DIGI_COOK, /* Flags */
322 .digi_maxcps = 100, /* Max CPS */
323 .digi_maxchar = 50, /* Max chars in print queue */
324 .digi_bufsize = 100, /* Printer buffer size */
325 .digi_onlen = 4, /* size of printer on string */
326 .digi_offlen = 4, /* size of printer off string */
327 .digi_onstr = "\033[5i", /* ANSI printer on string ] */
328 .digi_offstr = "\033[4i", /* ANSI printer off string ] */
329 .digi_term = "ansi" /* default terminal type */
334 * Define a local default termios struct. All ports will be created
335 * with this termios initially.
337 * This defines a raw port at 9600 baud, 8 data bits, no parity,
341 static struct ktermios DgapDefaultTermios =
343 .c_iflag = (DEFAULT_IFLAGS), /* iflags */
344 .c_oflag = (DEFAULT_OFLAGS), /* oflags */
345 .c_cflag = (DEFAULT_CFLAGS), /* cflags */
346 .c_lflag = (DEFAULT_LFLAGS), /* lflags */
351 static const struct tty_operations dgap_tty_ops = {
352 .open = dgap_tty_open,
353 .close = dgap_tty_close,
354 .write = dgap_tty_write,
355 .write_room = dgap_tty_write_room,
356 .flush_buffer = dgap_tty_flush_buffer,
357 .chars_in_buffer = dgap_tty_chars_in_buffer,
358 .flush_chars = dgap_tty_flush_chars,
359 .ioctl = dgap_tty_ioctl,
360 .set_termios = dgap_tty_set_termios,
361 .stop = dgap_tty_stop,
362 .start = dgap_tty_start,
363 .throttle = dgap_tty_throttle,
364 .unthrottle = dgap_tty_unthrottle,
365 .hangup = dgap_tty_hangup,
366 .put_char = dgap_tty_put_char,
367 .tiocmget = dgap_tty_tiocmget,
368 .tiocmset = dgap_tty_tiocmset,
369 .break_ctl = dgap_tty_send_break,
370 .wait_until_sent = dgap_tty_wait_until_sent,
371 .send_xchar = dgap_tty_send_xchar
375 * Our needed internal static variables from dgap_parse.c
377 static struct cnode dgap_head;
379 static char dgap_cword[MAXCWORD];
386 static struct toklist dgap_tlist[] = {
387 { BEGIN, "config_begin" },
388 { END, "config_end" },
390 { PCX, "Digi_AccelePort_C/X_PCI" }, /* C/X_PCI */
391 { PEPC, "Digi_AccelePort_EPC/X_PCI" }, /* EPC/X_PCI */
392 { PPCM, "Digi_AccelePort_Xem_PCI" }, /* PCI/Xem */
393 { APORT2_920P, "Digi_AccelePort_2r_920_PCI" },
394 { APORT4_920P, "Digi_AccelePort_4r_920_PCI" },
395 { APORT8_920P, "Digi_AccelePort_8r_920_PCI" },
396 { PAPORT4, "Digi_AccelePort_4r_PCI(EIA-232/RS-422)" },
397 { PAPORT8, "Digi_AccelePort_8r_PCI(EIA-232/RS-422)" },
399 { PCIINFO, "pciinfo" },
402 { CONC, "concentrator" },
412 { CONNECT, "connect" },
413 { METHOD, "method" },
414 { STATUS, "status" },
415 { CUSTOM, "Custom" },
421 { NPORTS, "nports" },
426 { ALTPIN, "altpin" },
427 { USEINTR, "useintr" },
428 { TTSIZ, "ttysize" },
430 { BSSIZ, "boardsize" },
431 { UNTSIZ, "schedsize" },
432 { F2SIZ, "f2200size" },
433 { VPSIZ, "vpixsize" },
437 /************************************************************************
439 * Driver load/unload functions
441 ************************************************************************/
446 * Module load. This is where it all starts.
448 int dgap_init_module(void)
452 APR(("%s, Digi International Part Number %s\n", DG_NAME, DG_PART));
455 * Initialize global stuff
464 * Find and configure all the cards
466 rc = dgap_init_pci();
469 * If something went wrong in the scan, bail out of driver.
472 /* Only unregister the pci driver if it was actually registered. */
474 pci_unregister_driver(&dgap_driver);
476 printk("WARNING: dgap driver load failed. No DGAP boards found.\n");
478 dgap_cleanup_module();
481 dgap_create_driver_sysfiles(&dgap_driver);
484 DPR_INIT(("Finished init_module. Returning %d\n", rc));
492 static int dgap_start(void)
497 if (dgap_driver_start == FALSE) {
499 dgap_driver_start = TRUE;
501 /* make sure that the globals are init'd before we do anything else */
506 APR(("For the tools package or updated drivers please visit http://www.digi.com\n"));
509 * Register our base character device into the kernel.
510 * This allows the download daemon to connect to the downld device
511 * before any of the boards are init'ed.
513 if (!dgap_Major_Control_Registered) {
515 * Register management/dpa devices
517 rc = register_chrdev(DIGI_DGAP_MAJOR, "dgap", &DgapBoardFops);
519 APR(("Can't register dgap driver device (%d)\n", rc));
523 dgap_class = class_create(THIS_MODULE, "dgap_mgmt");
524 device_create(dgap_class, NULL,
525 MKDEV(DIGI_DGAP_MAJOR, 0),
527 device_create(dgap_class, NULL,
528 MKDEV(DIGI_DGAP_MAJOR, 1),
529 NULL, "dgap_downld");
530 dgap_Major_Control_Registered = TRUE;
534 * Init any global tty stuff.
536 rc = dgap_tty_preinit();
539 APR(("tty preinit - not enough memory (%d)\n", rc));
543 /* Start the poller */
544 DGAP_LOCK(dgap_poll_lock, flags);
545 init_timer(&dgap_poll_timer);
546 dgap_poll_timer.function = dgap_poll_handler;
547 dgap_poll_timer.data = 0;
548 dgap_poll_time = jiffies + dgap_jiffies_from_ms(dgap_poll_tick);
549 dgap_poll_timer.expires = dgap_poll_time;
550 DGAP_UNLOCK(dgap_poll_lock, flags);
552 add_timer(&dgap_poll_timer);
554 dgap_driver_state = DRIVER_NEED_CONFIG_LOAD;
562 * Register pci driver, and return how many boards we have.
564 static int dgap_init_pci(void)
566 return pci_register_driver(&dgap_driver);
570 /* returns count (>= 0), or negative on error */
571 static int dgap_init_one(struct pci_dev *pdev, const struct pci_device_id *ent)
575 /* wake up and enable device */
576 rc = pci_enable_device(pdev);
581 rc = dgap_probe1(pdev, ent->driver_data);
584 DPR_INIT(("Incrementing numboards to %d\n", dgap_NumBoards));
591 static int dgap_probe1(struct pci_dev *pdev, int card_type)
593 return dgap_found_board(pdev, card_type);
597 static void dgap_remove_one(struct pci_dev *dev)
604 * dgap_cleanup_module()
606 * Module unload. This is where it all ends.
608 void dgap_cleanup_module(void)
613 DGAP_LOCK(dgap_poll_lock, lock_flags);
615 DGAP_UNLOCK(dgap_poll_lock, lock_flags);
617 /* Turn off poller right away. */
618 del_timer_sync( &dgap_poll_timer);
620 dgap_remove_driver_sysfiles(&dgap_driver);
623 if (dgap_Major_Control_Registered) {
624 device_destroy(dgap_class, MKDEV(DIGI_DGAP_MAJOR, 0));
625 device_destroy(dgap_class, MKDEV(DIGI_DGAP_MAJOR, 1));
626 class_destroy(dgap_class);
627 unregister_chrdev(DIGI_DGAP_MAJOR, "dgap");
630 kfree(dgap_config_buf);
632 for (i = 0; i < dgap_NumBoards; ++i) {
633 dgap_remove_ports_sysfiles(dgap_Board[i]);
634 dgap_tty_uninit(dgap_Board[i]);
635 dgap_cleanup_board(dgap_Board[i]);
638 dgap_tty_post_uninit();
640 #if defined(DGAP_TRACER)
641 /* last thing, make sure we release the tracebuffer */
645 pci_unregister_driver(&dgap_driver);
650 * dgap_cleanup_board()
652 * Free all the memory associated with a board
654 static void dgap_cleanup_board(struct board_t *brd)
658 if(!brd || brd->magic != DGAP_BOARD_MAGIC)
661 if (brd->intr_used && brd->irq)
662 free_irq(brd->irq, brd);
664 tasklet_kill(&brd->helper_tasklet);
666 if (brd->re_map_port) {
667 release_mem_region(brd->membase + 0x200000, 0x200000);
668 iounmap(brd->re_map_port);
669 brd->re_map_port = NULL;
672 if (brd->re_map_membase) {
673 release_mem_region(brd->membase, 0x200000);
674 iounmap(brd->re_map_membase);
675 brd->re_map_membase = NULL;
678 if (brd->msgbuf_head) {
681 DGAP_LOCK(dgap_global_lock, flags);
683 printk("%s", brd->msgbuf_head);
684 kfree(brd->msgbuf_head);
685 brd->msgbuf_head = NULL;
686 DGAP_UNLOCK(dgap_global_lock, flags);
689 /* Free all allocated channels structs */
690 for (i = 0; i < MAXPORTS ; i++) {
691 if (brd->channels[i]) {
692 kfree(brd->channels[i]);
693 brd->channels[i] = NULL;
698 kfree(brd->flipflagbuf);
700 dgap_Board[brd->boardnum] = NULL;
709 * A board has been found, init it.
711 static int dgap_found_board(struct pci_dev *pdev, int id)
714 unsigned int pci_irq;
718 /* get the board structure and prep it */
719 brd = dgap_Board[dgap_NumBoards] =
720 (struct board_t *) kzalloc(sizeof(struct board_t), GFP_KERNEL);
722 APR(("memory allocation for board structure failed\n"));
726 /* make a temporary message buffer for the boot messages */
727 brd->msgbuf = brd->msgbuf_head =
728 (char *) kzalloc(sizeof(char) * 8192, GFP_KERNEL);
731 APR(("memory allocation for board msgbuf failed\n"));
735 /* store the info for the board we've found */
736 brd->magic = DGAP_BOARD_MAGIC;
737 brd->boardnum = dgap_NumBoards;
739 brd->vendor = dgap_pci_tbl[id].vendor;
740 brd->device = dgap_pci_tbl[id].device;
742 brd->pci_bus = pdev->bus->number;
743 brd->pci_slot = PCI_SLOT(pdev->devfn);
744 brd->name = dgap_Ids[id].name;
745 brd->maxports = dgap_Ids[id].maxports;
746 brd->type = dgap_Ids[id].config_type;
747 brd->dpatype = dgap_Ids[id].dpatype;
748 brd->dpastatus = BD_NOFEP;
749 init_waitqueue_head(&brd->state_wait);
751 DGAP_SPINLOCK_INIT(brd->bd_lock);
753 brd->state = BOARD_FOUND;
755 brd->inhibit_poller = FALSE;
756 brd->wait_for_bios = 0;
757 brd->wait_for_fep = 0;
759 for (i = 0; i < MAXPORTS; i++) {
760 brd->channels[i] = NULL;
763 /* store which card & revision we have */
764 pci_read_config_word(pdev, PCI_SUBSYSTEM_VENDOR_ID, &brd->subvendor);
765 pci_read_config_word(pdev, PCI_SUBSYSTEM_ID, &brd->subdevice);
766 pci_read_config_byte(pdev, PCI_REVISION_ID, &brd->rev);
771 /* get the PCI Base Address Registers */
773 /* Xr Jupiter and EPC use BAR 2 */
774 if (brd->device == PCI_DEVICE_XRJ_DID || brd->device == PCI_DEVICE_EPCJ_DID) {
775 brd->membase = pci_resource_start(pdev, 2);
776 brd->membase_end = pci_resource_end(pdev, 2);
778 /* Everyone else uses BAR 0 */
780 brd->membase = pci_resource_start(pdev, 0);
781 brd->membase_end = pci_resource_end(pdev, 0);
785 APR(("card has no PCI IO resources, failing board.\n"));
789 if (brd->membase & 1)
795 * On the PCI boards, there is no IO space allocated
796 * The I/O registers will be in the first 3 bytes of the
797 * upper 2MB of the 4MB memory space. The board memory
798 * will be mapped into the low 2MB of the 4MB memory space
800 brd->port = brd->membase + PCI_IO_OFFSET;
801 brd->port_end = brd->port + PCI_IO_SIZE;
805 * Special initialization for non-PLX boards
807 if (brd->device != PCI_DEVICE_XRJ_DID && brd->device != PCI_DEVICE_EPCJ_DID) {
810 pci_write_config_byte(pdev, 0x40, 0);
811 pci_write_config_byte(pdev, 0x46, 0);
813 /* Limit burst length to 2 doubleword transactions */
814 pci_write_config_byte(pdev, 0x42, 1);
817 * Enable IO and mem if not already done.
818 * This was needed for support on Itanium.
820 pci_read_config_word(pdev, PCI_COMMAND, &cmd);
821 cmd |= (PCI_COMMAND_IO | PCI_COMMAND_MEMORY);
822 pci_write_config_word(pdev, PCI_COMMAND, cmd);
825 /* init our poll helper tasklet */
826 tasklet_init(&brd->helper_tasklet, dgap_poll_tasklet, (unsigned long) brd);
828 /* Log the information about the board */
829 dgap_mbuf(brd, DRVSTR": board %d: %s (rev %d), irq %d\n",
830 dgap_NumBoards, brd->name, brd->rev, brd->irq);
832 DPR_INIT(("dgap_scan(%d) - printing out the msgbuf\n", i));
833 DGAP_LOCK(dgap_global_lock, flags);
835 printk("%s", brd->msgbuf_head);
836 kfree(brd->msgbuf_head);
837 brd->msgbuf_head = NULL;
838 DGAP_UNLOCK(dgap_global_lock, flags);
840 i = dgap_do_remap(brd);
842 brd->state = BOARD_FAILED;
844 brd->state = NEED_RESET;
850 int dgap_finalize_board_init(struct board_t *brd) {
854 DPR_INIT(("dgap_finalize_board_init() - start\n"));
856 if (!brd || brd->magic != DGAP_BOARD_MAGIC)
859 DPR_INIT(("dgap_finalize_board_init() - start #2\n"));
861 brd->use_interrupts = dgap_config_get_useintr(brd);
864 * Set up our interrupt handler if we are set to do interrupts.
866 if (brd->use_interrupts && brd->irq) {
868 rc = request_irq(brd->irq, dgap_intr, IRQF_SHARED, "DGAP", brd);
871 dgap_mbuf(brd, DRVSTR": Failed to hook IRQ %d. Board will work in poll mode.\n",
888 static int dgap_do_remap(struct board_t *brd)
890 if (!brd || brd->magic != DGAP_BOARD_MAGIC)
893 if (!request_mem_region(brd->membase, 0x200000, "dgap")) {
894 APR(("dgap: mem_region %lx already in use.\n", brd->membase));
898 if (!request_mem_region(brd->membase + PCI_IO_OFFSET, 0x200000, "dgap")) {
899 APR(("dgap: mem_region IO %lx already in use.\n",
900 brd->membase + PCI_IO_OFFSET));
901 release_mem_region(brd->membase, 0x200000);
905 brd->re_map_membase = ioremap(brd->membase, 0x200000);
906 if (!brd->re_map_membase) {
907 APR(("dgap: ioremap mem %lx cannot be mapped.\n", brd->membase));
908 release_mem_region(brd->membase, 0x200000);
909 release_mem_region(brd->membase + PCI_IO_OFFSET, 0x200000);
913 brd->re_map_port = ioremap((brd->membase + PCI_IO_OFFSET), 0x200000);
914 if (!brd->re_map_port) {
915 release_mem_region(brd->membase, 0x200000);
916 release_mem_region(brd->membase + PCI_IO_OFFSET, 0x200000);
917 iounmap(brd->re_map_membase);
918 APR(("dgap: ioremap IO mem %lx cannot be mapped.\n",
919 brd->membase + PCI_IO_OFFSET));
923 DPR_INIT(("remapped io: 0x%p remapped mem: 0x%p\n",
924 brd->re_map_port, brd->re_map_membase));
929 /*****************************************************************************
949 * As each timer expires, it determines (a) whether the "transmit"
950 * waiter needs to be woken up, and (b) whether the poller needs to
953 ******************************************************************************/
955 static void dgap_poll_handler(ulong dummy)
959 unsigned long lock_flags;
960 unsigned long lock_flags2;
967 * If driver needs the config file still,
968 * keep trying to wake up the downloader to
971 if (dgap_driver_state == DRIVER_NEED_CONFIG_LOAD) {
973 * Signal downloader, its got some work to do.
975 DGAP_LOCK(dgap_dl_lock, lock_flags2);
976 if (dgap_dl_action != 1) {
978 wake_up_interruptible(&dgap_dl_wait);
980 DGAP_UNLOCK(dgap_dl_lock, lock_flags2);
981 goto schedule_poller;
984 * Do not start the board state machine until
985 * driver tells us its up and running, and has
986 * everything it needs.
988 else if (dgap_driver_state != DRIVER_READY) {
989 goto schedule_poller;
993 * If we have just 1 board, or the system is not SMP,
994 * then use the typical old style poller.
995 * Otherwise, use our new tasklet based poller, which should
996 * speed things up for multiple boards.
998 if ( (dgap_NumBoards == 1) || (num_online_cpus() <= 1) ) {
999 for (i = 0; i < dgap_NumBoards; i++) {
1001 brd = dgap_Board[i];
1003 if (brd->state == BOARD_FAILED) {
1006 if (!brd->intr_running) {
1007 /* Call the real board poller directly */
1008 dgap_poll_tasklet((unsigned long) brd);
1013 /* Go thru each board, kicking off a tasklet for each if needed */
1014 for (i = 0; i < dgap_NumBoards; i++) {
1015 brd = dgap_Board[i];
1018 * Attempt to grab the board lock.
1020 * If we can't get it, no big deal, the next poll will get it.
1021 * Basically, I just really don't want to spin in here, because I want
1022 * to kick off my tasklets as fast as I can, and then get out the poller.
1024 if (!spin_trylock(&brd->bd_lock)) {
1028 /* If board is in a failed state, don't bother scheduling a tasklet */
1029 if (brd->state == BOARD_FAILED) {
1030 spin_unlock(&brd->bd_lock);
1034 /* Schedule a poll helper task */
1035 if (!brd->intr_running) {
1036 tasklet_schedule(&brd->helper_tasklet);
1040 * Can't do DGAP_UNLOCK here, as we don't have
1041 * lock_flags because we did a trylock above.
1043 spin_unlock(&brd->bd_lock);
1050 * Schedule ourself back at the nominal wakeup interval.
1052 DGAP_LOCK(dgap_poll_lock, lock_flags );
1053 dgap_poll_time += dgap_jiffies_from_ms(dgap_poll_tick);
1055 new_time = dgap_poll_time - jiffies;
1057 if ((ulong) new_time >= 2 * dgap_poll_tick) {
1058 dgap_poll_time = jiffies + dgap_jiffies_from_ms(dgap_poll_tick);
1061 dgap_poll_timer.function = dgap_poll_handler;
1062 dgap_poll_timer.data = 0;
1063 dgap_poll_timer.expires = dgap_poll_time;
1064 DGAP_UNLOCK(dgap_poll_lock, lock_flags );
1066 if (!dgap_poll_stop)
1067 add_timer(&dgap_poll_timer);
1076 * Driver interrupt handler.
1078 static irqreturn_t dgap_intr(int irq, void *voidbrd)
1080 struct board_t *brd = (struct board_t *) voidbrd;
1083 APR(("Received interrupt (%d) with null board associated\n", irq));
1088 * Check to make sure its for us.
1090 if (brd->magic != DGAP_BOARD_MAGIC) {
1091 APR(("Received interrupt (%d) with a board pointer that wasn't ours!\n", irq));
1098 * Schedule tasklet to run at a better time.
1100 tasklet_schedule(&brd->helper_tasklet);
1106 * dgap_init_globals()
1108 * This is where we initialize the globals from the static insmod
1109 * configuration variables. These are declared near the head of
1112 static void dgap_init_globals(void)
1116 dgap_rawreadok = rawreadok;
1117 dgap_trcbuf_size = trcbuf_size;
1120 for (i = 0; i < MAXBOARDS; i++) {
1121 dgap_Board[i] = NULL;
1124 init_timer( &dgap_poll_timer );
1126 init_waitqueue_head(&dgap_dl_wait);
1131 /************************************************************************
1135 ************************************************************************/
1141 * Used to print to the message buffer during board init.
1143 static void dgap_mbuf(struct board_t *brd, const char *fmt, ...) {
1147 unsigned long flags;
1150 DGAP_LOCK(dgap_global_lock, flags);
1152 /* Format buf using fmt and arguments contained in ap. */
1154 i = vsnprintf(buf, sizeof(buf), fmt, ap);
1159 if (!brd || !brd->msgbuf) {
1161 DGAP_UNLOCK(dgap_global_lock, flags);
1165 length = strlen(buf) + 1;
1166 if (brd->msgbuf - brd->msgbuf_head < length)
1167 length = brd->msgbuf - brd->msgbuf_head;
1168 memcpy(brd->msgbuf, buf, length);
1169 brd->msgbuf += length;
1171 DGAP_UNLOCK(dgap_global_lock, flags);
1178 * Put the driver to sleep for x ms's
1180 * Returns 0 if timed out, !0 (showing signal) if interrupted by a signal.
1182 int dgap_ms_sleep(ulong ms)
1184 current->state = TASK_INTERRUPTIBLE;
1185 schedule_timeout((ms * HZ) / 1000);
1186 return (signal_pending(current));
1192 * dgap_ioctl_name() : Returns a text version of each ioctl value.
1194 char *dgap_ioctl_name(int cmd)
1198 case TCGETA: return("TCGETA");
1199 case TCGETS: return("TCGETS");
1200 case TCSETA: return("TCSETA");
1201 case TCSETS: return("TCSETS");
1202 case TCSETAW: return("TCSETAW");
1203 case TCSETSW: return("TCSETSW");
1204 case TCSETAF: return("TCSETAF");
1205 case TCSETSF: return("TCSETSF");
1206 case TCSBRK: return("TCSBRK");
1207 case TCXONC: return("TCXONC");
1208 case TCFLSH: return("TCFLSH");
1209 case TIOCGSID: return("TIOCGSID");
1211 case TIOCGETD: return("TIOCGETD");
1212 case TIOCSETD: return("TIOCSETD");
1213 case TIOCGWINSZ: return("TIOCGWINSZ");
1214 case TIOCSWINSZ: return("TIOCSWINSZ");
1216 case TIOCMGET: return("TIOCMGET");
1217 case TIOCMSET: return("TIOCMSET");
1218 case TIOCMBIS: return("TIOCMBIS");
1219 case TIOCMBIC: return("TIOCMBIC");
1222 case DIGI_SETA: return("DIGI_SETA");
1223 case DIGI_SETAW: return("DIGI_SETAW");
1224 case DIGI_SETAF: return("DIGI_SETAF");
1225 case DIGI_SETFLOW: return("DIGI_SETFLOW");
1226 case DIGI_SETAFLOW: return("DIGI_SETAFLOW");
1227 case DIGI_GETFLOW: return("DIGI_GETFLOW");
1228 case DIGI_GETAFLOW: return("DIGI_GETAFLOW");
1229 case DIGI_GETA: return("DIGI_GETA");
1230 case DIGI_GEDELAY: return("DIGI_GEDELAY");
1231 case DIGI_SEDELAY: return("DIGI_SEDELAY");
1232 case DIGI_GETCUSTOMBAUD: return("DIGI_GETCUSTOMBAUD");
1233 case DIGI_SETCUSTOMBAUD: return("DIGI_SETCUSTOMBAUD");
1234 case TIOCMODG: return("TIOCMODG");
1235 case TIOCMODS: return("TIOCMODS");
1236 case TIOCSDTR: return("TIOCSDTR");
1237 case TIOCCDTR: return("TIOCCDTR");
1239 default: return("unknown");
1243 /************************************************************************
1245 * TTY Initialization/Cleanup Functions
1247 ************************************************************************/
1250 * dgap_tty_preinit()
1252 * Initialize any global tty related data before we download any boards.
1254 int dgap_tty_preinit(void)
1256 unsigned long flags;
1258 DGAP_LOCK(dgap_global_lock, flags);
1261 * Allocate a buffer for doing the copy from user space to
1262 * kernel space in dgap_input(). We only use one buffer and
1263 * control access to it with a semaphore. If we are paging, we
1264 * are already in trouble so one buffer won't hurt much anyway.
1266 dgap_TmpWriteBuf = kmalloc(WRITEBUFLEN, GFP_ATOMIC);
1268 if (!dgap_TmpWriteBuf) {
1269 DGAP_UNLOCK(dgap_global_lock, flags);
1270 DPR_INIT(("unable to allocate tmp write buf"));
1274 DGAP_UNLOCK(dgap_global_lock, flags);
1280 * dgap_tty_register()
1282 * Init the tty subsystem for this board.
1284 int dgap_tty_register(struct board_t *brd)
1288 DPR_INIT(("tty_register start"));
1290 brd->SerialDriver = alloc_tty_driver(MAXPORTS);
1292 snprintf(brd->SerialName, MAXTTYNAMELEN, "tty_dgap_%d_", brd->boardnum);
1293 brd->SerialDriver->name = brd->SerialName;
1294 brd->SerialDriver->name_base = 0;
1295 brd->SerialDriver->major = 0;
1296 brd->SerialDriver->minor_start = 0;
1297 brd->SerialDriver->type = TTY_DRIVER_TYPE_SERIAL;
1298 brd->SerialDriver->subtype = SERIAL_TYPE_NORMAL;
1299 brd->SerialDriver->init_termios = DgapDefaultTermios;
1300 brd->SerialDriver->driver_name = DRVSTR;
1301 brd->SerialDriver->flags = (TTY_DRIVER_REAL_RAW | TTY_DRIVER_DYNAMIC_DEV | TTY_DRIVER_HARDWARE_BREAK);
1303 /* The kernel wants space to store pointers to tty_structs */
1304 brd->SerialDriver->ttys = kzalloc(MAXPORTS * sizeof(struct tty_struct *), GFP_KERNEL);
1305 if (!brd->SerialDriver->ttys)
1309 * Entry points for driver. Called by the kernel from
1310 * tty_io.c and n_tty.c.
1312 tty_set_operations(brd->SerialDriver, &dgap_tty_ops);
1315 * If we're doing transparent print, we have to do all of the above
1316 * again, separately so we don't get the LD confused about what major
1317 * we are when we get into the dgap_tty_open() routine.
1319 brd->PrintDriver = alloc_tty_driver(MAXPORTS);
1321 snprintf(brd->PrintName, MAXTTYNAMELEN, "pr_dgap_%d_", brd->boardnum);
1322 brd->PrintDriver->name = brd->PrintName;
1323 brd->PrintDriver->name_base = 0;
1324 brd->PrintDriver->major = 0;
1325 brd->PrintDriver->minor_start = 0;
1326 brd->PrintDriver->type = TTY_DRIVER_TYPE_SERIAL;
1327 brd->PrintDriver->subtype = SERIAL_TYPE_NORMAL;
1328 brd->PrintDriver->init_termios = DgapDefaultTermios;
1329 brd->PrintDriver->driver_name = DRVSTR;
1330 brd->PrintDriver->flags = (TTY_DRIVER_REAL_RAW | TTY_DRIVER_DYNAMIC_DEV | TTY_DRIVER_HARDWARE_BREAK);
1332 /* The kernel wants space to store pointers to tty_structs */
1333 brd->PrintDriver->ttys = kzalloc(MAXPORTS * sizeof(struct tty_struct *), GFP_KERNEL);
1334 if (!brd->PrintDriver->ttys)
1338 * Entry points for driver. Called by the kernel from
1339 * tty_io.c and n_tty.c.
1341 tty_set_operations(brd->PrintDriver, &dgap_tty_ops);
1343 if (!brd->dgap_Major_Serial_Registered) {
1344 /* Register tty devices */
1345 rc = tty_register_driver(brd->SerialDriver);
1347 APR(("Can't register tty device (%d)\n", rc));
1350 brd->dgap_Major_Serial_Registered = TRUE;
1351 dgap_BoardsByMajor[brd->SerialDriver->major] = brd;
1352 brd->dgap_Serial_Major = brd->SerialDriver->major;
1355 if (!brd->dgap_Major_TransparentPrint_Registered) {
1356 /* Register Transparent Print devices */
1357 rc = tty_register_driver(brd->PrintDriver);
1359 APR(("Can't register Transparent Print device (%d)\n", rc));
1362 brd->dgap_Major_TransparentPrint_Registered = TRUE;
1363 dgap_BoardsByMajor[brd->PrintDriver->major] = brd;
1364 brd->dgap_TransparentPrint_Major = brd->PrintDriver->major;
1367 DPR_INIT(("DGAP REGISTER TTY: MAJORS: %d %d\n", brd->SerialDriver->major,
1368 brd->PrintDriver->major));
1377 * Init the tty subsystem. Called once per board after board has been
1378 * downloaded and init'ed.
1380 int dgap_tty_init(struct board_t *brd)
1384 uint true_count = 0;
1387 struct channel_t *ch;
1394 DPR_INIT(("dgap_tty_init start\n"));
1397 * Initialize board structure elements.
1400 vaddr = brd->re_map_membase;
1401 true_count = readw((vaddr + NCHAN));
1403 brd->nasync = dgap_config_get_number_of_ports(brd);
1406 brd->nasync = brd->maxports;
1409 if (brd->nasync > brd->maxports) {
1410 brd->nasync = brd->maxports;
1413 if (true_count != brd->nasync) {
1414 if ((brd->type == PPCM) && (true_count == 64)) {
1415 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",
1416 brd->name, brd->nasync, true_count));
1418 else if ((brd->type == PPCM) && (true_count == 0)) {
1419 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",
1420 brd->name, brd->nasync, true_count));
1423 APR(("***WARNING**** %s configured for %d ports, has %d ports.\n",
1424 brd->name, brd->nasync, true_count));
1427 brd->nasync = true_count;
1429 /* If no ports, don't bother going any further */
1431 brd->state = BOARD_FAILED;
1432 brd->dpastatus = BD_NOFEP;
1438 * Allocate channel memory that might not have been allocated
1439 * when the driver was first loaded.
1441 for (i = 0; i < brd->nasync; i++) {
1442 if (!brd->channels[i]) {
1443 brd->channels[i] = kzalloc(sizeof(struct channel_t), GFP_ATOMIC);
1444 if (!brd->channels[i]) {
1445 DPR_CORE(("%s:%d Unable to allocate memory for channel struct\n",
1446 __FILE__, __LINE__));
1451 ch = brd->channels[0];
1452 vaddr = brd->re_map_membase;
1454 bs = (struct bs_t *) ((ulong) vaddr + CHANBUF);
1455 cm = (struct cm_t *) ((ulong) vaddr + CMDBUF);
1459 /* Set up channel variables */
1460 for (i = 0; i < brd->nasync; i++, ch = brd->channels[i], bs++) {
1462 if (!brd->channels[i])
1465 DGAP_SPINLOCK_INIT(ch->ch_lock);
1467 /* Store all our magic numbers */
1468 ch->magic = DGAP_CHANNEL_MAGIC;
1469 ch->ch_tun.magic = DGAP_UNIT_MAGIC;
1470 ch->ch_tun.un_type = DGAP_SERIAL;
1471 ch->ch_tun.un_ch = ch;
1472 ch->ch_tun.un_dev = i;
1474 ch->ch_pun.magic = DGAP_UNIT_MAGIC;
1475 ch->ch_pun.un_type = DGAP_PRINT;
1476 ch->ch_pun.un_ch = ch;
1477 ch->ch_pun.un_dev = i;
1479 ch->ch_vaddr = vaddr;
1484 ch->ch_digi = dgap_digi_init;
1487 * Set up digi dsr and dcd bits based on altpin flag.
1489 if (dgap_config_get_altpin(brd)) {
1492 ch->ch_digi.digi_flags |= DIGI_ALTPIN;
1496 ch->ch_dsr = DM_DSR;
1499 ch->ch_taddr = vaddr + ((ch->ch_bs->tx_seg) << 4);
1500 ch->ch_raddr = vaddr + ((ch->ch_bs->rx_seg) << 4);
1503 ch->ch_tsize = readw(&(ch->ch_bs->tx_max)) + 1;
1504 ch->ch_rsize = readw(&(ch->ch_bs->rx_max)) + 1;
1508 /* .25 second delay */
1509 ch->ch_close_delay = 250;
1512 * Set queue water marks, interrupt mask,
1513 * and general tty parameters.
1515 ch->ch_tlw = tlw = ch->ch_tsize >= 2000 ? ((ch->ch_tsize * 5) / 8) : ch->ch_tsize / 2;
1517 dgap_cmdw(ch, STLOW, tlw, 0);
1519 dgap_cmdw(ch, SRLOW, ch->ch_rsize / 2, 0);
1521 dgap_cmdw(ch, SRHIGH, 7 * ch->ch_rsize / 8, 0);
1523 ch->ch_mistat = readb(&(ch->ch_bs->m_stat));
1525 init_waitqueue_head(&ch->ch_flags_wait);
1526 init_waitqueue_head(&ch->ch_tun.un_flags_wait);
1527 init_waitqueue_head(&ch->ch_pun.un_flags_wait);
1528 init_waitqueue_head(&ch->ch_sniff_wait);
1530 /* Turn on all modem interrupts for now */
1531 modem = (DM_CD | DM_DSR | DM_CTS | DM_RI);
1532 writeb(modem, &(ch->ch_bs->m_int));
1535 * Set edelay to 0 if interrupts are turned on,
1536 * otherwise set edelay to the usual 100.
1539 writew(0, &(ch->ch_bs->edelay));
1541 writew(100, &(ch->ch_bs->edelay));
1543 writeb(1, &(ch->ch_bs->idata));
1547 DPR_INIT(("dgap_tty_init finish\n"));
1554 * dgap_tty_post_uninit()
1556 * UnInitialize any global tty related data.
1558 void dgap_tty_post_uninit(void)
1560 kfree(dgap_TmpWriteBuf);
1561 dgap_TmpWriteBuf = NULL;
1568 * Uninitialize the TTY portion of this driver. Free all memory and
1571 void dgap_tty_uninit(struct board_t *brd)
1575 if (brd->dgap_Major_Serial_Registered) {
1576 dgap_BoardsByMajor[brd->SerialDriver->major] = NULL;
1577 brd->dgap_Serial_Major = 0;
1578 for (i = 0; i < brd->nasync; i++) {
1579 dgap_remove_tty_sysfs(brd->channels[i]->ch_tun.un_sysfs);
1580 tty_unregister_device(brd->SerialDriver, i);
1582 tty_unregister_driver(brd->SerialDriver);
1583 kfree(brd->SerialDriver->ttys);
1584 brd->SerialDriver->ttys = NULL;
1585 put_tty_driver(brd->SerialDriver);
1586 brd->dgap_Major_Serial_Registered = FALSE;
1589 if (brd->dgap_Major_TransparentPrint_Registered) {
1590 dgap_BoardsByMajor[brd->PrintDriver->major] = NULL;
1591 brd->dgap_TransparentPrint_Major = 0;
1592 for (i = 0; i < brd->nasync; i++) {
1593 dgap_remove_tty_sysfs(brd->channels[i]->ch_pun.un_sysfs);
1594 tty_unregister_device(brd->PrintDriver, i);
1596 tty_unregister_driver(brd->PrintDriver);
1597 kfree(brd->PrintDriver->ttys);
1598 brd->PrintDriver->ttys = NULL;
1599 put_tty_driver(brd->PrintDriver);
1600 brd->dgap_Major_TransparentPrint_Registered = FALSE;
1605 #define TMPBUFLEN (1024)
1608 * dgap_sniff - Dump data out to the "sniff" buffer if the
1609 * proc sniff file is opened...
1611 static void dgap_sniff_nowait_nolock(struct channel_t *ch, uchar *text, uchar *buf, int len)
1619 char tmpbuf[TMPBUFLEN];
1623 /* Leave if sniff not open */
1624 if (!(ch->ch_sniff_flags & SNIFF_OPEN))
1627 do_gettimeofday(&tv);
1629 /* Create our header for data dump */
1630 p += sprintf(p, "<%ld %ld><%s><", tv.tv_sec, tv.tv_usec, text);
1631 tmpbuflen = p - tmpbuf;
1636 for (i = 0; i < len && tmpbuflen < (TMPBUFLEN - 4); i++) {
1637 p += sprintf(p, "%02x ", *buf);
1639 tmpbuflen = p - tmpbuf;
1642 if (tmpbuflen < (TMPBUFLEN - 4)) {
1644 p += sprintf(p - 1, "%s\n", ">");
1646 p += sprintf(p, "%s\n", ">");
1652 nbuf = strlen(tmpbuf);
1656 * Loop while data remains.
1658 while (nbuf > 0 && ch->ch_sniff_buf) {
1660 * Determine the amount of available space left in the
1661 * buffer. If there's none, wait until some appears.
1663 n = (ch->ch_sniff_out - ch->ch_sniff_in - 1) & SNIFF_MASK;
1666 * If there is no space left to write to in our sniff buffer,
1667 * we have no choice but to drop the data.
1668 * We *cannot* sleep here waiting for space, because this
1669 * function was probably called by the interrupt/timer routines!
1676 * Copy as much data as will fit.
1682 r = SNIFF_MAX - ch->ch_sniff_in;
1685 memcpy(ch->ch_sniff_buf + ch->ch_sniff_in, p, r);
1688 ch->ch_sniff_in = 0;
1693 memcpy(ch->ch_sniff_buf + ch->ch_sniff_in, p, n);
1695 ch->ch_sniff_in += n;
1700 * Wakeup any thread waiting for data
1702 if (ch->ch_sniff_flags & SNIFF_WAIT_DATA) {
1703 ch->ch_sniff_flags &= ~SNIFF_WAIT_DATA;
1704 wake_up_interruptible(&ch->ch_sniff_wait);
1709 * If the user sent us too much data to push into our tmpbuf,
1710 * we need to keep looping around on all the data.
1712 if (too_much_data) {
1717 } while (too_much_data);
1721 /*=======================================================================
1723 * dgap_input - Process received data.
1725 * ch - Pointer to channel structure.
1727 *=======================================================================*/
1729 void dgap_input(struct channel_t *ch)
1733 struct tty_struct *tp;
1734 struct tty_ldisc *ld;
1748 if (!ch || ch->magic != DGAP_CHANNEL_MAGIC)
1751 tp = ch->ch_tun.un_tty;
1759 if(!bd || bd->magic != DGAP_BOARD_MAGIC)
1762 DPR_READ(("dgap_input start\n"));
1764 DGAP_LOCK(bd->bd_lock, lock_flags);
1765 DGAP_LOCK(ch->ch_lock, lock_flags2);
1768 * Figure the number of characters in the buffer.
1769 * Exit immediately if none.
1772 rmask = ch->ch_rsize - 1;
1774 head = readw(&(bs->rx_head));
1776 tail = readw(&(bs->rx_tail));
1779 data_len = (head - tail) & rmask;
1781 if (data_len == 0) {
1782 writeb(1, &(bs->idata));
1783 DGAP_UNLOCK(ch->ch_lock, lock_flags2);
1784 DGAP_UNLOCK(bd->bd_lock, lock_flags);
1785 DPR_READ(("No data on port %d\n", ch->ch_portnum));
1790 * If the device is not open, or CREAD is off, flush
1791 * input data and return immediately.
1793 if ((bd->state != BOARD_READY) || !tp || (tp->magic != TTY_MAGIC) ||
1794 !(ch->ch_tun.un_flags & UN_ISOPEN) || !(tp->termios.c_cflag & CREAD) ||
1795 (ch->ch_tun.un_flags & UN_CLOSING)) {
1797 DPR_READ(("input. dropping %d bytes on port %d...\n", data_len, ch->ch_portnum));
1798 DPR_READ(("input. tp: %p tp->magic: %x MAGIC:%x ch flags: %x\n",
1799 tp, tp ? tp->magic : 0, TTY_MAGIC, ch->ch_tun.un_flags));
1800 writew(head, &(bs->rx_tail));
1801 writeb(1, &(bs->idata));
1802 DGAP_UNLOCK(ch->ch_lock, lock_flags2);
1803 DGAP_UNLOCK(bd->bd_lock, lock_flags);
1808 * If we are throttled, simply don't read any data.
1810 if (ch->ch_flags & CH_RXBLOCK) {
1811 writeb(1, &(bs->idata));
1812 DGAP_UNLOCK(ch->ch_lock, lock_flags2);
1813 DGAP_UNLOCK(bd->bd_lock, lock_flags);
1814 DPR_READ(("Port %d throttled, not reading any data. head: %x tail: %x\n",
1815 ch->ch_portnum, head, tail));
1822 tmpchar = readb(&(bs->orun));
1824 ch->ch_err_overrun++;
1825 writeb(0, &(bs->orun));
1828 DPR_READ(("dgap_input start 2\n"));
1830 /* Decide how much data we can send into the tty layer */
1831 flip_len = TTY_FLIPBUF_SIZE;
1833 /* Chop down the length, if needed */
1834 len = min(data_len, flip_len);
1835 len = min(len, (N_TTY_BUF_SIZE - 1));
1837 ld = tty_ldisc_ref(tp);
1839 #ifdef TTY_DONT_FLIP
1841 * If the DONT_FLIP flag is on, don't flush our buffer, and act
1842 * like the ld doesn't have any space to put the data right now.
1844 if (test_bit(TTY_DONT_FLIP, &tp->flags))
1849 * If we were unable to get a reference to the ld,
1850 * don't flush our buffer, and act like the ld doesn't
1851 * have any space to put the data right now.
1857 * If ld doesn't have a pointer to a receive_buf function,
1858 * flush the data, then act like the ld doesn't have any
1859 * space to put the data right now.
1861 if (!ld->ops->receive_buf) {
1862 writew(head, &(bs->rx_tail));
1868 writeb(1, &(bs->idata));
1869 DGAP_UNLOCK(ch->ch_lock, lock_flags2);
1870 DGAP_UNLOCK(bd->bd_lock, lock_flags);
1871 DPR_READ(("dgap_input 1 - finish\n"));
1873 tty_ldisc_deref(ld);
1877 buf = ch->ch_bd->flipbuf;
1881 * n now contains the most amount of data we can copy,
1882 * bounded either by our buffer size or the amount
1883 * of data the card actually has pending...
1887 s = ((head >= tail) ? head : ch->ch_rsize) - tail;
1893 memcpy_fromio(buf, (char *) ch->ch_raddr + tail, s);
1894 dgap_sniff_nowait_nolock(ch, "USER READ", buf, s);
1900 /* Flip queue if needed */
1904 writew(tail, &(bs->rx_tail));
1905 writeb(1, &(bs->idata));
1906 ch->ch_rxcount += len;
1909 * If we are completely raw, we don't need to go through a lot
1910 * of the tty layers that exist.
1911 * In this case, we take the shortest and fastest route we
1912 * can to relay the data to the user.
1914 * On the other hand, if we are not raw, we need to go through
1915 * the tty layer, which has its API more well defined.
1917 if (I_PARMRK(tp) || I_BRKINT(tp) || I_INPCK(tp)) {
1918 dgap_parity_scan(ch, ch->ch_bd->flipbuf, ch->ch_bd->flipflagbuf, &len);
1920 len = tty_buffer_request_room(tp->port, len);
1921 tty_insert_flip_string_flags(tp->port, ch->ch_bd->flipbuf,
1922 ch->ch_bd->flipflagbuf, len);
1925 len = tty_buffer_request_room(tp->port, len);
1926 tty_insert_flip_string(tp->port, ch->ch_bd->flipbuf, len);
1929 DGAP_UNLOCK(ch->ch_lock, lock_flags2);
1930 DGAP_UNLOCK(bd->bd_lock, lock_flags);
1932 /* Tell the tty layer its okay to "eat" the data now */
1933 tty_flip_buffer_push(tp->port);
1936 tty_ldisc_deref(ld);
1938 DPR_READ(("dgap_input - finish\n"));
1942 /************************************************************************
1943 * Determines when CARRIER changes state and takes appropriate
1945 ************************************************************************/
1946 void dgap_carrier(struct channel_t *ch)
1950 int virt_carrier = 0;
1951 int phys_carrier = 0;
1953 DPR_CARR(("dgap_carrier called...\n"));
1955 if (!ch || ch->magic != DGAP_CHANNEL_MAGIC)
1960 if (!bd || bd->magic != DGAP_BOARD_MAGIC)
1963 /* Make sure altpin is always set correctly */
1964 if (ch->ch_digi.digi_flags & DIGI_ALTPIN) {
1969 ch->ch_dsr = DM_DSR;
1973 if (ch->ch_mistat & D_CD(ch)) {
1974 DPR_CARR(("mistat: %x D_CD: %x\n", ch->ch_mistat, D_CD(ch)));
1978 if (ch->ch_digi.digi_flags & DIGI_FORCEDCD) {
1982 if (ch->ch_c_cflag & CLOCAL) {
1987 DPR_CARR(("DCD: physical: %d virt: %d\n", phys_carrier, virt_carrier));
1990 * Test for a VIRTUAL carrier transition to HIGH.
1992 if (((ch->ch_flags & CH_FCAR) == 0) && (virt_carrier == 1)) {
1995 * When carrier rises, wake any threads waiting
1996 * for carrier in the open routine.
1999 DPR_CARR(("carrier: virt DCD rose\n"));
2001 if (waitqueue_active(&(ch->ch_flags_wait)))
2002 wake_up_interruptible(&ch->ch_flags_wait);
2006 * Test for a PHYSICAL carrier transition to HIGH.
2008 if (((ch->ch_flags & CH_CD) == 0) && (phys_carrier == 1)) {
2011 * When carrier rises, wake any threads waiting
2012 * for carrier in the open routine.
2015 DPR_CARR(("carrier: physical DCD rose\n"));
2017 if (waitqueue_active(&(ch->ch_flags_wait)))
2018 wake_up_interruptible(&ch->ch_flags_wait);
2022 * Test for a PHYSICAL transition to low, so long as we aren't
2023 * currently ignoring physical transitions (which is what "virtual
2024 * carrier" indicates).
2026 * The transition of the virtual carrier to low really doesn't
2027 * matter... it really only means "ignore carrier state", not
2028 * "make pretend that carrier is there".
2030 if ((virt_carrier == 0) && ((ch->ch_flags & CH_CD) != 0) &&
2031 (phys_carrier == 0))
2035 * When carrier drops:
2037 * Drop carrier on all open units.
2039 * Flush queues, waking up any task waiting in the
2042 * Send a hangup to the control terminal.
2044 * Enable all select calls.
2046 if (waitqueue_active(&(ch->ch_flags_wait)))
2047 wake_up_interruptible(&ch->ch_flags_wait);
2049 if (ch->ch_tun.un_open_count > 0) {
2050 DPR_CARR(("Sending tty hangup\n"));
2051 tty_hangup(ch->ch_tun.un_tty);
2054 if (ch->ch_pun.un_open_count > 0) {
2055 DPR_CARR(("Sending pr hangup\n"));
2056 tty_hangup(ch->ch_pun.un_tty);
2061 * Make sure that our cached values reflect the current reality.
2063 if (virt_carrier == 1)
2064 ch->ch_flags |= CH_FCAR;
2066 ch->ch_flags &= ~CH_FCAR;
2068 if (phys_carrier == 1)
2069 ch->ch_flags |= CH_CD;
2071 ch->ch_flags &= ~CH_CD;
2075 /************************************************************************
2077 * TTY Entry points and helper functions
2079 ************************************************************************/
2085 static int dgap_tty_open(struct tty_struct *tty, struct file *file)
2087 struct board_t *brd;
2088 struct channel_t *ch;
2100 major = MAJOR(tty_devnum(tty));
2101 minor = MINOR(tty_devnum(tty));
2107 /* Get board pointer from our array of majors we have allocated */
2108 brd = dgap_BoardsByMajor[major];
2114 * If board is not yet up to a state of READY, go to
2115 * sleep waiting for it to happen or they cancel the open.
2117 rc = wait_event_interruptible(brd->state_wait,
2118 (brd->state & BOARD_READY));
2124 DGAP_LOCK(brd->bd_lock, lock_flags);
2126 /* The wait above should guarantee this cannot happen */
2127 if (brd->state != BOARD_READY) {
2128 DGAP_UNLOCK(brd->bd_lock, lock_flags);
2132 /* If opened device is greater than our number of ports, bail. */
2133 if (MINOR(tty_devnum(tty)) > brd->nasync) {
2134 DGAP_UNLOCK(brd->bd_lock, lock_flags);
2138 ch = brd->channels[minor];
2140 DGAP_UNLOCK(brd->bd_lock, lock_flags);
2144 /* Grab channel lock */
2145 DGAP_LOCK(ch->ch_lock, lock_flags2);
2147 /* Figure out our type */
2148 if (major == brd->dgap_Serial_Major) {
2149 un = &brd->channels[minor]->ch_tun;
2150 un->un_type = DGAP_SERIAL;
2152 else if (major == brd->dgap_TransparentPrint_Major) {
2153 un = &brd->channels[minor]->ch_pun;
2154 un->un_type = DGAP_PRINT;
2157 DGAP_UNLOCK(ch->ch_lock, lock_flags2);
2158 DGAP_UNLOCK(brd->bd_lock, lock_flags);
2159 DPR_OPEN(("%d Unknown TYPE!\n", __LINE__));
2163 /* Store our unit into driver_data, so we always have it available. */
2164 tty->driver_data = un;
2166 DPR_OPEN(("Open called. MAJOR: %d MINOR:%d unit: %p NAME: %s\n",
2167 MAJOR(tty_devnum(tty)), MINOR(tty_devnum(tty)), un, brd->name));
2170 * Error if channel info pointer is NULL.
2174 DGAP_UNLOCK(ch->ch_lock, lock_flags2);
2175 DGAP_UNLOCK(brd->bd_lock, lock_flags);
2176 DPR_OPEN(("%d BS is 0!\n", __LINE__));
2180 DPR_OPEN(("%d: tflag=%x pflag=%x\n", __LINE__, ch->ch_tun.un_flags, ch->ch_pun.un_flags));
2185 if (!(un->un_flags & UN_ISOPEN)) {
2186 /* Store important variables. */
2189 /* Maybe do something here to the TTY struct as well? */
2193 * Initialize if neither terminal or printer is open.
2195 if (!((ch->ch_tun.un_flags | ch->ch_pun.un_flags) & UN_ISOPEN)) {
2197 DPR_OPEN(("dgap_open: initializing channel in open...\n"));
2203 * Flush input queue.
2205 head = readw(&(bs->rx_head));
2206 writew(head, &(bs->rx_tail));
2209 ch->pscan_state = 0;
2210 ch->pscan_savechar = 0;
2212 ch->ch_c_cflag = tty->termios.c_cflag;
2213 ch->ch_c_iflag = tty->termios.c_iflag;
2214 ch->ch_c_oflag = tty->termios.c_oflag;
2215 ch->ch_c_lflag = tty->termios.c_lflag;
2216 ch->ch_startc = tty->termios.c_cc[VSTART];
2217 ch->ch_stopc = tty->termios.c_cc[VSTOP];
2219 /* TODO: flush our TTY struct here? */
2224 * Run param in case we changed anything
2229 * follow protocol for opening port
2232 DGAP_UNLOCK(ch->ch_lock, lock_flags2);
2233 DGAP_UNLOCK(brd->bd_lock, lock_flags);
2235 rc = dgap_block_til_ready(tty, file, ch);
2242 DPR_OPEN(("dgap_tty_open returning after dgap_block_til_ready "
2246 /* No going back now, increment our unit and channel counters */
2247 DGAP_LOCK(ch->ch_lock, lock_flags);
2248 ch->ch_open_count++;
2249 un->un_open_count++;
2250 un->un_flags |= (UN_ISOPEN);
2251 DGAP_UNLOCK(ch->ch_lock, lock_flags);
2253 DPR_OPEN(("dgap_tty_open finished\n"));
2259 * dgap_block_til_ready()
2261 * Wait for DCD, if needed.
2263 static int dgap_block_til_ready(struct tty_struct *tty, struct file *file, struct channel_t *ch)
2266 struct un_t *un = NULL;
2269 int sleep_on_un_flags = 0;
2271 if (!tty || tty->magic != TTY_MAGIC || !file || !ch || ch->magic != DGAP_CHANNEL_MAGIC) {
2275 un = tty->driver_data;
2276 if (!un || un->magic != DGAP_UNIT_MAGIC) {
2280 DPR_OPEN(("dgap_block_til_ready - before block.\n"));
2282 DGAP_LOCK(ch->ch_lock, lock_flags);
2289 sleep_on_un_flags = 0;
2292 * If board has failed somehow during our sleep, bail with error.
2294 if (ch->ch_bd->state == BOARD_FAILED) {
2299 /* If tty was hung up, break out of loop and set error. */
2300 if (tty_hung_up_p(file)) {
2306 * If either unit is in the middle of the fragile part of close,
2307 * we just cannot touch the channel safely.
2308 * Go back to sleep, knowing that when the channel can be
2309 * touched safely, the close routine will signal the
2310 * ch_wait_flags to wake us back up.
2312 if (!((ch->ch_tun.un_flags | ch->ch_pun.un_flags) & UN_CLOSING)) {
2315 * Our conditions to leave cleanly and happily:
2316 * 1) NONBLOCKING on the tty is set.
2318 * 3) DCD (fake or real) is active.
2321 if (file->f_flags & O_NONBLOCK) {
2325 if (tty->flags & (1 << TTY_IO_ERROR)) {
2329 if (ch->ch_flags & CH_CD) {
2330 DPR_OPEN(("%d: ch_flags: %x\n", __LINE__, ch->ch_flags));
2334 if (ch->ch_flags & CH_FCAR) {
2335 DPR_OPEN(("%d: ch_flags: %x\n", __LINE__, ch->ch_flags));
2340 sleep_on_un_flags = 1;
2344 * If there is a signal pending, the user probably
2345 * interrupted (ctrl-c) us.
2346 * Leave loop with error set.
2348 if (signal_pending(current)) {
2349 DPR_OPEN(("%d: signal pending...\n", __LINE__));
2350 retval = -ERESTARTSYS;
2354 DPR_OPEN(("dgap_block_til_ready - blocking.\n"));
2357 * Store the flags before we let go of channel lock
2359 if (sleep_on_un_flags)
2360 old_flags = ch->ch_tun.un_flags | ch->ch_pun.un_flags;
2362 old_flags = ch->ch_flags;
2365 * Let go of channel lock before calling schedule.
2366 * Our poller will get any FEP events and wake us up when DCD
2367 * eventually goes active.
2370 DGAP_UNLOCK(ch->ch_lock, lock_flags);
2372 DPR_OPEN(("Going to sleep on %s flags...\n",
2373 (sleep_on_un_flags ? "un" : "ch")));
2376 * Wait for something in the flags to change from the current value.
2378 if (sleep_on_un_flags) {
2379 retval = wait_event_interruptible(un->un_flags_wait,
2380 (old_flags != (ch->ch_tun.un_flags | ch->ch_pun.un_flags)));
2383 retval = wait_event_interruptible(ch->ch_flags_wait,
2384 (old_flags != ch->ch_flags));
2387 DPR_OPEN(("After sleep... retval: %x\n", retval));
2390 * We got woken up for some reason.
2391 * Before looping around, grab our channel lock.
2393 DGAP_LOCK(ch->ch_lock, lock_flags);
2398 DGAP_UNLOCK(ch->ch_lock, lock_flags);
2400 DPR_OPEN(("dgap_block_til_ready - after blocking.\n"));
2403 DPR_OPEN(("dgap_block_til_ready - done. error. retval: %x\n", retval));
2407 DPR_OPEN(("dgap_block_til_ready - done no error. jiffies: %lu\n", jiffies));
2416 * Hangup the port. Like a close, but don't wait for output to drain.
2418 static void dgap_tty_hangup(struct tty_struct *tty)
2421 struct channel_t *ch;
2424 if (!tty || tty->magic != TTY_MAGIC)
2427 un = tty->driver_data;
2428 if (!un || un->magic != DGAP_UNIT_MAGIC)
2432 if (!ch || ch->magic != DGAP_CHANNEL_MAGIC)
2436 if (!bd || bd->magic != DGAP_BOARD_MAGIC)
2439 DPR_CLOSE(("dgap_hangup called. ch->ch_open_count: %d un->un_open_count: %d\n",
2440 ch->ch_open_count, un->un_open_count));
2442 /* flush the transmit queues */
2443 dgap_tty_flush_buffer(tty);
2445 DPR_CLOSE(("dgap_hangup finished. ch->ch_open_count: %d un->un_open_count: %d\n",
2446 ch->ch_open_count, un->un_open_count));
2455 static void dgap_tty_close(struct tty_struct *tty, struct file *file)
2457 struct ktermios *ts;
2459 struct channel_t *ch;
2464 if (!tty || tty->magic != TTY_MAGIC)
2467 un = tty->driver_data;
2468 if (!un || un->magic != DGAP_UNIT_MAGIC)
2472 if (!ch || ch->magic != DGAP_CHANNEL_MAGIC)
2476 if (!bd || bd->magic != DGAP_BOARD_MAGIC)
2481 DPR_CLOSE(("Close called\n"));
2483 DGAP_LOCK(ch->ch_lock, lock_flags);
2486 * Determine if this is the last close or not - and if we agree about
2487 * which type of close it is with the Line Discipline
2489 if ((tty->count == 1) && (un->un_open_count != 1)) {
2491 * Uh, oh. tty->count is 1, which means that the tty
2492 * structure will be freed. un_open_count should always
2493 * be one in these conditions. If it's greater than
2494 * one, we've got real problems, since it means the
2495 * serial port won't be shutdown.
2497 APR(("tty->count is 1, un open count is %d\n", un->un_open_count));
2498 un->un_open_count = 1;
2501 if (--un->un_open_count < 0) {
2502 APR(("bad serial port open count of %d\n", un->un_open_count));
2503 un->un_open_count = 0;
2506 ch->ch_open_count--;
2508 if (ch->ch_open_count && un->un_open_count) {
2509 DPR_CLOSE(("dgap_tty_close: not last close ch: %d un:%d\n",
2510 ch->ch_open_count, un->un_open_count));
2512 DGAP_UNLOCK(ch->ch_lock, lock_flags);
2516 /* OK, its the last close on the unit */
2517 DPR_CLOSE(("dgap_tty_close - last close on unit procedures\n"));
2519 un->un_flags |= UN_CLOSING;
2524 * Only officially close channel if count is 0 and
2525 * DIGI_PRINTER bit is not set.
2527 if ((ch->ch_open_count == 0) && !(ch->ch_digi.digi_flags & DIGI_PRINTER)) {
2529 ch->ch_flags &= ~(CH_RXBLOCK);
2531 DGAP_UNLOCK(ch->ch_lock, lock_flags);
2533 /* wait for output to drain */
2534 /* This will also return if we take an interrupt */
2536 DPR_CLOSE(("Calling wait_for_drain\n"));
2537 rc = dgap_wait_for_drain(tty);
2538 DPR_CLOSE(("After calling wait_for_drain\n"));
2541 DPR_BASIC(("dgap_tty_close - bad return: %d ", rc));
2544 dgap_tty_flush_buffer(tty);
2545 tty_ldisc_flush(tty);
2547 DGAP_LOCK(ch->ch_lock, lock_flags);
2552 * If we have HUPCL set, lower DTR and RTS
2554 if (ch->ch_c_cflag & HUPCL ) {
2555 DPR_CLOSE(("Close. HUPCL set, dropping DTR/RTS\n"));
2556 ch->ch_mostat &= ~(D_RTS(ch)|D_DTR(ch));
2557 dgap_cmdb( ch, SMODEM, 0, D_DTR(ch)|D_RTS(ch), 0 );
2560 * Go to sleep to ensure RTS/DTR
2561 * have been dropped for modems to see it.
2563 if (ch->ch_close_delay) {
2564 DPR_CLOSE(("Close. Sleeping for RTS/DTR drop\n"));
2566 DGAP_UNLOCK(ch->ch_lock, lock_flags);
2567 dgap_ms_sleep(ch->ch_close_delay);
2568 DGAP_LOCK(ch->ch_lock, lock_flags);
2570 DPR_CLOSE(("Close. After sleeping for RTS/DTR drop\n"));
2574 ch->pscan_state = 0;
2575 ch->pscan_savechar = 0;
2576 ch->ch_baud_info = 0;
2581 * turn off print device when closing print device.
2583 if ((un->un_type == DGAP_PRINT) && (ch->ch_flags & CH_PRON) ) {
2584 dgap_wmove(ch, ch->ch_digi.digi_offstr,
2585 (int) ch->ch_digi.digi_offlen);
2586 ch->ch_flags &= ~CH_PRON;
2590 un->un_flags &= ~(UN_ISOPEN | UN_CLOSING);
2591 tty->driver_data = NULL;
2593 DPR_CLOSE(("Close. Doing wakeups\n"));
2594 wake_up_interruptible(&ch->ch_flags_wait);
2595 wake_up_interruptible(&un->un_flags_wait);
2597 DGAP_UNLOCK(ch->ch_lock, lock_flags);
2599 DPR_BASIC(("dgap_tty_close - complete\n"));
2604 * dgap_tty_chars_in_buffer()
2606 * Return number of characters that have not been transmitted yet.
2608 * This routine is used by the line discipline to determine if there
2609 * is data waiting to be transmitted/drained/flushed or not.
2611 static int dgap_tty_chars_in_buffer(struct tty_struct *tty)
2613 struct board_t *bd = NULL;
2614 struct channel_t *ch = NULL;
2615 struct un_t *un = NULL;
2616 struct bs_t *bs = NULL;
2619 u16 thead, ttail, tmask, chead, ctail;
2620 ulong lock_flags = 0;
2621 ulong lock_flags2 = 0;
2626 un = tty->driver_data;
2627 if (!un || un->magic != DGAP_UNIT_MAGIC)
2631 if (!ch || ch->magic != DGAP_CHANNEL_MAGIC)
2635 if (!bd || bd->magic != DGAP_BOARD_MAGIC)
2642 DGAP_LOCK(bd->bd_lock, lock_flags);
2643 DGAP_LOCK(ch->ch_lock, lock_flags2);
2645 tmask = (ch->ch_tsize - 1);
2647 /* Get Transmit queue pointers */
2648 thead = readw(&(bs->tx_head)) & tmask;
2649 ttail = readw(&(bs->tx_tail)) & tmask;
2651 /* Get tbusy flag */
2652 tbusy = readb(&(bs->tbusy));
2654 /* Get Command queue pointers */
2655 chead = readw(&(ch->ch_cm->cm_head));
2656 ctail = readw(&(ch->ch_cm->cm_tail));
2658 DGAP_UNLOCK(ch->ch_lock, lock_flags2);
2659 DGAP_UNLOCK(bd->bd_lock, lock_flags);
2662 * The only way we know for sure if there is no pending
2663 * data left to be transferred, is if:
2664 * 1) Transmit head and tail are equal (empty).
2665 * 2) Command queue head and tail are equal (empty).
2666 * 3) The "TBUSY" flag is 0. (Transmitter not busy).
2669 if ((ttail == thead) && (tbusy == 0) && (chead == ctail)) {
2674 chars = thead - ttail;
2676 chars = thead - ttail + ch->ch_tsize;
2678 * Fudge factor here.
2679 * If chars is zero, we know that the command queue had
2680 * something in it or tbusy was set. Because we cannot
2681 * be sure if there is still some data to be transmitted,
2682 * lets lie, and tell ld we have 1 byte left.
2686 * If TBUSY is still set, and our tx buffers are empty,
2687 * force the firmware to send me another wakeup after
2688 * TBUSY has been cleared.
2691 DGAP_LOCK(ch->ch_lock, lock_flags);
2692 un->un_flags |= UN_EMPTY;
2693 writeb(1, &(bs->iempty));
2694 DGAP_UNLOCK(ch->ch_lock, lock_flags);
2700 DPR_WRITE(("dgap_tty_chars_in_buffer. Port: %x - %d (head: %d tail: %d tsize: %d)\n",
2701 ch->ch_portnum, chars, thead, ttail, ch->ch_tsize));
2706 static int dgap_wait_for_drain(struct tty_struct *tty)
2708 struct channel_t *ch;
2713 ulong lock_flags = 0;
2715 if (!tty || tty->magic != TTY_MAGIC)
2718 un = tty->driver_data;
2719 if (!un || un->magic != DGAP_UNIT_MAGIC)
2723 if (!ch || ch->magic != DGAP_CHANNEL_MAGIC)
2732 DPR_DRAIN(("dgap_wait_for_drain start\n"));
2734 /* Loop until data is drained */
2735 while (count != 0) {
2737 count = dgap_tty_chars_in_buffer(tty);
2742 /* Set flag waiting for drain */
2743 DGAP_LOCK(ch->ch_lock, lock_flags);
2744 un->un_flags |= UN_EMPTY;
2745 writeb(1, &(bs->iempty));
2746 DGAP_UNLOCK(ch->ch_lock, lock_flags);
2748 /* Go to sleep till we get woken up */
2749 ret = wait_event_interruptible(un->un_flags_wait, ((un->un_flags & UN_EMPTY) == 0));
2750 /* If ret is non-zero, user ctrl-c'ed us */
2756 DGAP_LOCK(ch->ch_lock, lock_flags);
2757 un->un_flags &= ~(UN_EMPTY);
2758 DGAP_UNLOCK(ch->ch_lock, lock_flags);
2760 DPR_DRAIN(("dgap_wait_for_drain finish\n"));
2768 * Reduces bytes_available to the max number of characters
2769 * that can be sent currently given the maxcps value, and
2770 * returns the new bytes_available. This only affects printer
2773 static int dgap_maxcps_room(struct tty_struct *tty, int bytes_available)
2775 struct channel_t *ch = NULL;
2776 struct un_t *un = NULL;
2779 return (bytes_available);
2781 un = tty->driver_data;
2782 if (!un || un->magic != DGAP_UNIT_MAGIC)
2783 return (bytes_available);
2786 if (!ch || ch->magic != DGAP_CHANNEL_MAGIC)
2787 return (bytes_available);
2790 * If its not the Transparent print device, return
2791 * the full data amount.
2793 if (un->un_type != DGAP_PRINT)
2794 return (bytes_available);
2796 if (ch->ch_digi.digi_maxcps > 0 && ch->ch_digi.digi_bufsize > 0 ) {
2798 unsigned long current_time = jiffies;
2799 unsigned long buffer_time = current_time +
2800 (HZ * ch->ch_digi.digi_bufsize) / ch->ch_digi.digi_maxcps;
2802 if (ch->ch_cpstime < current_time) {
2803 /* buffer is empty */
2804 ch->ch_cpstime = current_time; /* reset ch_cpstime */
2805 cps_limit = ch->ch_digi.digi_bufsize;
2807 else if (ch->ch_cpstime < buffer_time) {
2808 /* still room in the buffer */
2809 cps_limit = ((buffer_time - ch->ch_cpstime) * ch->ch_digi.digi_maxcps) / HZ;
2812 /* no room in the buffer */
2816 bytes_available = min(cps_limit, bytes_available);
2819 return (bytes_available);
2823 static inline void dgap_set_firmware_event(struct un_t *un, unsigned int event)
2825 struct channel_t *ch = NULL;
2826 struct bs_t *bs = NULL;
2828 if (!un || un->magic != DGAP_UNIT_MAGIC)
2831 if (!ch || ch->magic != DGAP_CHANNEL_MAGIC)
2837 if ((event & UN_LOW) != 0) {
2838 if ((un->un_flags & UN_LOW) == 0) {
2839 un->un_flags |= UN_LOW;
2840 writeb(1, &(bs->ilow));
2843 if ((event & UN_LOW) != 0) {
2844 if ((un->un_flags & UN_EMPTY) == 0) {
2845 un->un_flags |= UN_EMPTY;
2846 writeb(1, &(bs->iempty));
2853 * dgap_tty_write_room()
2855 * Return space available in Tx buffer
2857 static int dgap_tty_write_room(struct tty_struct *tty)
2859 struct channel_t *ch = NULL;
2860 struct un_t *un = NULL;
2861 struct bs_t *bs = NULL;
2862 u16 head, tail, tmask;
2864 ulong lock_flags = 0;
2866 if (tty == NULL || dgap_TmpWriteBuf == NULL)
2869 un = tty->driver_data;
2870 if (!un || un->magic != DGAP_UNIT_MAGIC)
2874 if (!ch || ch->magic != DGAP_CHANNEL_MAGIC)
2881 DGAP_LOCK(ch->ch_lock, lock_flags);
2883 tmask = ch->ch_tsize - 1;
2884 head = readw(&(bs->tx_head)) & tmask;
2885 tail = readw(&(bs->tx_tail)) & tmask;
2887 if ((ret = tail - head - 1) < 0)
2888 ret += ch->ch_tsize;
2890 /* Limit printer to maxcps */
2891 ret = dgap_maxcps_room(tty, ret);
2894 * If we are printer device, leave space for
2895 * possibly both the on and off strings.
2897 if (un->un_type == DGAP_PRINT) {
2898 if (!(ch->ch_flags & CH_PRON))
2899 ret -= ch->ch_digi.digi_onlen;
2900 ret -= ch->ch_digi.digi_offlen;
2903 if (ch->ch_flags & CH_PRON)
2904 ret -= ch->ch_digi.digi_offlen;
2911 * Schedule FEP to wake us up if needed.
2913 * TODO: This might be overkill...
2914 * Do we really need to schedule callbacks from the FEP
2915 * in every case? Can we get smarter based on ret?
2917 dgap_set_firmware_event(un, UN_LOW | UN_EMPTY);
2918 DGAP_UNLOCK(ch->ch_lock, lock_flags);
2920 DPR_WRITE(("dgap_tty_write_room - %d tail: %d head: %d\n", ret, tail, head));
2927 * dgap_tty_put_char()
2929 * Put a character into ch->ch_buf
2931 * - used by the line discipline for OPOST processing
2933 static int dgap_tty_put_char(struct tty_struct *tty, unsigned char c)
2936 * Simply call tty_write.
2938 DPR_WRITE(("dgap_tty_put_char called\n"));
2939 dgap_tty_write(tty, &c, 1);
2947 * Take data from the user or kernel and send it out to the FEP.
2948 * In here exists all the Transparent Print magic as well.
2950 static int dgap_tty_write(struct tty_struct *tty, const unsigned char *buf, int count)
2952 struct channel_t *ch = NULL;
2953 struct un_t *un = NULL;
2954 struct bs_t *bs = NULL;
2956 u16 head, tail, tmask, remain;
2957 int bufcount = 0, n = 0;
2962 if (tty == NULL || dgap_TmpWriteBuf == NULL)
2965 un = tty->driver_data;
2966 if (!un || un->magic != DGAP_UNIT_MAGIC)
2970 if (!ch || ch->magic != DGAP_CHANNEL_MAGIC)
2980 DPR_WRITE(("dgap_tty_write: Port: %x tty=%p user=%d len=%d\n",
2981 ch->ch_portnum, tty, from_user, count));
2984 * Store original amount of characters passed in.
2985 * This helps to figure out if we should ask the FEP
2986 * to send us an event when it has more space available.
2990 DGAP_LOCK(ch->ch_lock, lock_flags);
2992 /* Get our space available for the channel from the board */
2993 tmask = ch->ch_tsize - 1;
2994 head = readw(&(bs->tx_head)) & tmask;
2995 tail = readw(&(bs->tx_tail)) & tmask;
2997 if ((bufcount = tail - head - 1) < 0)
2998 bufcount += ch->ch_tsize;
3000 DPR_WRITE(("%d: bufcount: %x count: %x tail: %x head: %x tmask: %x\n",
3001 __LINE__, bufcount, count, tail, head, tmask));
3004 * Limit printer output to maxcps overall, with bursts allowed
3005 * up to bufsize characters.
3007 bufcount = dgap_maxcps_room(tty, bufcount);
3010 * Take minimum of what the user wants to send, and the
3011 * space available in the FEP buffer.
3013 count = min(count, bufcount);
3016 * Bail if no space left.
3019 dgap_set_firmware_event(un, UN_LOW | UN_EMPTY);
3020 DGAP_UNLOCK(ch->ch_lock, lock_flags);
3025 * Output the printer ON string, if we are in terminal mode, but
3026 * need to be in printer mode.
3028 if ((un->un_type == DGAP_PRINT) && !(ch->ch_flags & CH_PRON)) {
3029 dgap_wmove(ch, ch->ch_digi.digi_onstr,
3030 (int) ch->ch_digi.digi_onlen);
3031 head = readw(&(bs->tx_head)) & tmask;
3032 ch->ch_flags |= CH_PRON;
3036 * On the other hand, output the printer OFF string, if we are
3037 * currently in printer mode, but need to output to the terminal.
3039 if ((un->un_type != DGAP_PRINT) && (ch->ch_flags & CH_PRON)) {
3040 dgap_wmove(ch, ch->ch_digi.digi_offstr,
3041 (int) ch->ch_digi.digi_offlen);
3042 head = readw(&(bs->tx_head)) & tmask;
3043 ch->ch_flags &= ~CH_PRON;
3047 * If there is nothing left to copy, or I can't handle any more data, leave.
3050 dgap_set_firmware_event(un, UN_LOW | UN_EMPTY);
3051 DGAP_UNLOCK(ch->ch_lock, lock_flags);
3057 count = min(count, WRITEBUFLEN);
3059 DGAP_UNLOCK(ch->ch_lock, lock_flags);
3062 * If data is coming from user space, copy it into a temporary
3063 * buffer so we don't get swapped out while doing the copy to
3066 /* we're allowed to block if it's from_user */
3067 if (down_interruptible(&dgap_TmpWriteSem)) {
3071 if (copy_from_user(dgap_TmpWriteBuf, (const uchar __user *) buf, count)) {
3072 up(&dgap_TmpWriteSem);
3073 printk("Write: Copy from user failed!\n");
3077 DGAP_LOCK(ch->ch_lock, lock_flags);
3079 buf = dgap_TmpWriteBuf;
3085 * If the write wraps over the top of the circular buffer,
3086 * move the portion up to the wrap point, and reset the
3087 * pointers to the bottom.
3089 remain = ch->ch_tstart + ch->ch_tsize - head;
3093 vaddr = ch->ch_taddr + head;
3095 memcpy_toio(vaddr, (uchar *) buf, remain);
3096 dgap_sniff_nowait_nolock(ch, "USER WRITE", (uchar *) buf, remain);
3098 head = ch->ch_tstart;
3105 * Move rest of data.
3107 vaddr = ch->ch_taddr + head;
3110 memcpy_toio(vaddr, (uchar *) buf, remain);
3111 dgap_sniff_nowait_nolock(ch, "USER WRITE", (uchar *) buf, remain);
3118 ch->ch_txcount += count;
3120 writew(head, &(bs->tx_head));
3124 dgap_set_firmware_event(un, UN_LOW | UN_EMPTY);
3127 * If this is the print device, and the
3128 * printer is still on, we need to turn it
3129 * off before going idle. If the buffer is
3130 * non-empty, wait until it goes empty.
3131 * Otherwise turn it off right now.
3133 if ((un->un_type == DGAP_PRINT) && (ch->ch_flags & CH_PRON)) {
3134 tail = readw(&(bs->tx_tail)) & tmask;
3137 un->un_flags |= UN_EMPTY;
3138 writeb(1, &(bs->iempty));
3141 dgap_wmove(ch, ch->ch_digi.digi_offstr,
3142 (int) ch->ch_digi.digi_offlen);
3143 head = readw(&(bs->tx_head)) & tmask;
3144 ch->ch_flags &= ~CH_PRON;
3148 /* Update printer buffer empty time. */
3149 if ((un->un_type == DGAP_PRINT) && (ch->ch_digi.digi_maxcps > 0)
3150 && (ch->ch_digi.digi_bufsize > 0)) {
3151 ch->ch_cpstime += (HZ * count) / ch->ch_digi.digi_maxcps;
3155 DGAP_UNLOCK(ch->ch_lock, lock_flags);
3156 up(&dgap_TmpWriteSem);
3159 DGAP_UNLOCK(ch->ch_lock, lock_flags);
3162 DPR_WRITE(("Write finished - Write %d bytes of %d.\n", count, orig_count));
3170 * Return modem signals to ld.
3172 static int dgap_tty_tiocmget(struct tty_struct *tty)
3174 struct channel_t *ch;
3180 if (!tty || tty->magic != TTY_MAGIC)
3183 un = tty->driver_data;
3184 if (!un || un->magic != DGAP_UNIT_MAGIC)
3188 if (!ch || ch->magic != DGAP_CHANNEL_MAGIC)
3191 DPR_IOCTL(("dgap_tty_tiocmget start\n"));
3193 DGAP_LOCK(ch->ch_lock, lock_flags);
3195 mstat = readb(&(ch->ch_bs->m_stat));
3196 /* Append any outbound signals that might be pending... */
3197 mstat |= ch->ch_mostat;
3199 DGAP_UNLOCK(ch->ch_lock, lock_flags);
3203 if (mstat & D_DTR(ch))
3204 result |= TIOCM_DTR;
3205 if (mstat & D_RTS(ch))
3206 result |= TIOCM_RTS;
3207 if (mstat & D_CTS(ch))
3208 result |= TIOCM_CTS;
3209 if (mstat & D_DSR(ch))
3210 result |= TIOCM_DSR;
3211 if (mstat & D_RI(ch))
3213 if (mstat & D_CD(ch))
3216 DPR_IOCTL(("dgap_tty_tiocmget finish\n"));
3223 * dgap_tty_tiocmset()
3225 * Set modem signals, called by ld.
3228 static int dgap_tty_tiocmset(struct tty_struct *tty,
3229 unsigned int set, unsigned int clear)
3232 struct channel_t *ch;
3238 if (!tty || tty->magic != TTY_MAGIC)
3241 un = tty->driver_data;
3242 if (!un || un->magic != DGAP_UNIT_MAGIC)
3246 if (!ch || ch->magic != DGAP_CHANNEL_MAGIC)
3250 if (!bd || bd->magic != DGAP_BOARD_MAGIC)
3253 DPR_IOCTL(("dgap_tty_tiocmset start\n"));
3255 DGAP_LOCK(bd->bd_lock, lock_flags);
3256 DGAP_LOCK(ch->ch_lock, lock_flags2);
3258 if (set & TIOCM_RTS) {
3259 ch->ch_mforce |= D_RTS(ch);
3260 ch->ch_mval |= D_RTS(ch);
3263 if (set & TIOCM_DTR) {
3264 ch->ch_mforce |= D_DTR(ch);
3265 ch->ch_mval |= D_DTR(ch);
3268 if (clear & TIOCM_RTS) {
3269 ch->ch_mforce |= D_RTS(ch);
3270 ch->ch_mval &= ~(D_RTS(ch));
3273 if (clear & TIOCM_DTR) {
3274 ch->ch_mforce |= D_DTR(ch);
3275 ch->ch_mval &= ~(D_DTR(ch));
3280 DGAP_UNLOCK(ch->ch_lock, lock_flags2);
3281 DGAP_UNLOCK(bd->bd_lock, lock_flags);
3283 DPR_IOCTL(("dgap_tty_tiocmset finish\n"));
3291 * dgap_tty_send_break()
3293 * Send a Break, called by ld.
3295 static int dgap_tty_send_break(struct tty_struct *tty, int msec)
3298 struct channel_t *ch;
3304 if (!tty || tty->magic != TTY_MAGIC)
3307 un = tty->driver_data;
3308 if (!un || un->magic != DGAP_UNIT_MAGIC)
3312 if (!ch || ch->magic != DGAP_CHANNEL_MAGIC)
3316 if (!bd || bd->magic != DGAP_BOARD_MAGIC)
3331 DPR_IOCTL(("dgap_tty_send_break start 1. %lx\n", jiffies));
3333 DGAP_LOCK(bd->bd_lock, lock_flags);
3334 DGAP_LOCK(ch->ch_lock, lock_flags2);
3336 dgap_cmdw(ch, SBREAK, (u16) SBREAK_TIME, 0);
3338 dgap_cmdw(ch, SBREAK, (u16) msec, 0);
3340 DGAP_UNLOCK(ch->ch_lock, lock_flags2);
3341 DGAP_UNLOCK(bd->bd_lock, lock_flags);
3343 DPR_IOCTL(("dgap_tty_send_break finish\n"));
3352 * dgap_tty_wait_until_sent()
3354 * wait until data has been transmitted, called by ld.
3356 static void dgap_tty_wait_until_sent(struct tty_struct *tty, int timeout)
3359 rc = dgap_wait_for_drain(tty);
3361 DPR_IOCTL(("dgap_tty_ioctl - bad return: %d ", rc));
3372 * send a high priority character, called by ld.
3374 static void dgap_tty_send_xchar(struct tty_struct *tty, char c)
3377 struct channel_t *ch;
3382 if (!tty || tty->magic != TTY_MAGIC)
3385 un = tty->driver_data;
3386 if (!un || un->magic != DGAP_UNIT_MAGIC)
3390 if (!ch || ch->magic != DGAP_CHANNEL_MAGIC)
3394 if (!bd || bd->magic != DGAP_BOARD_MAGIC)
3397 DPR_IOCTL(("dgap_tty_send_xchar start 1. %lx\n", jiffies));
3399 DGAP_LOCK(bd->bd_lock, lock_flags);
3400 DGAP_LOCK(ch->ch_lock, lock_flags2);
3403 * This is technically what we should do.
3404 * However, the NIST tests specifically want
3405 * to see each XON or XOFF character that it
3406 * sends, so lets just send each character
3410 if (c == STOP_CHAR(tty)) {
3411 dgap_cmdw(ch, RPAUSE, 0, 0);
3413 else if (c == START_CHAR(tty)) {
3414 dgap_cmdw(ch, RRESUME, 0, 0);
3417 dgap_wmove(ch, &c, 1);
3420 dgap_wmove(ch, &c, 1);
3423 DGAP_UNLOCK(ch->ch_lock, lock_flags2);
3424 DGAP_UNLOCK(bd->bd_lock, lock_flags);
3426 DPR_IOCTL(("dgap_tty_send_xchar finish\n"));
3435 * Return modem signals to ld.
3437 static int dgap_get_modem_info(struct channel_t *ch, unsigned int __user *value)
3444 DPR_IOCTL(("dgap_get_modem_info start\n"));
3446 if (!ch || ch->magic != DGAP_CHANNEL_MAGIC)
3449 DGAP_LOCK(ch->ch_lock, lock_flags);
3451 mstat = readb(&(ch->ch_bs->m_stat));
3452 /* Append any outbound signals that might be pending... */
3453 mstat |= ch->ch_mostat;
3455 DGAP_UNLOCK(ch->ch_lock, lock_flags);
3459 if (mstat & D_DTR(ch))
3460 result |= TIOCM_DTR;
3461 if (mstat & D_RTS(ch))
3462 result |= TIOCM_RTS;
3463 if (mstat & D_CTS(ch))
3464 result |= TIOCM_CTS;
3465 if (mstat & D_DSR(ch))
3466 result |= TIOCM_DSR;
3467 if (mstat & D_RI(ch))
3469 if (mstat & D_CD(ch))
3472 rc = put_user(result, value);
3474 DPR_IOCTL(("dgap_get_modem_info finish\n"));
3480 * dgap_set_modem_info()
3482 * Set modem signals, called by ld.
3484 static int dgap_set_modem_info(struct tty_struct *tty, unsigned int command, unsigned int __user *value)
3487 struct channel_t *ch;
3490 unsigned int arg = 0;
3494 if (!tty || tty->magic != TTY_MAGIC)
3497 un = tty->driver_data;
3498 if (!un || un->magic != DGAP_UNIT_MAGIC)
3502 if (!ch || ch->magic != DGAP_CHANNEL_MAGIC)
3506 if (!bd || bd->magic != DGAP_BOARD_MAGIC)
3509 DPR_IOCTL(("dgap_set_modem_info() start\n"));
3511 ret = get_user(arg, value);
3513 DPR_IOCTL(("dgap_set_modem_info %d ret: %x. finished.\n", __LINE__, ret));
3517 DPR_IOCTL(("dgap_set_modem_info: command: %x arg: %x\n", command, arg));
3521 if (arg & TIOCM_RTS) {
3522 ch->ch_mforce |= D_RTS(ch);
3523 ch->ch_mval |= D_RTS(ch);
3526 if (arg & TIOCM_DTR) {
3527 ch->ch_mforce |= D_DTR(ch);
3528 ch->ch_mval |= D_DTR(ch);
3534 if (arg & TIOCM_RTS) {
3535 ch->ch_mforce |= D_RTS(ch);
3536 ch->ch_mval &= ~(D_RTS(ch));
3539 if (arg & TIOCM_DTR) {
3540 ch->ch_mforce |= D_DTR(ch);
3541 ch->ch_mval &= ~(D_DTR(ch));
3547 ch->ch_mforce = D_DTR(ch)|D_RTS(ch);
3549 if (arg & TIOCM_RTS) {
3550 ch->ch_mval |= D_RTS(ch);
3553 ch->ch_mval &= ~(D_RTS(ch));
3556 if (arg & TIOCM_DTR) {
3557 ch->ch_mval |= (D_DTR(ch));
3560 ch->ch_mval &= ~(D_DTR(ch));
3569 DGAP_LOCK(bd->bd_lock, lock_flags);
3570 DGAP_LOCK(ch->ch_lock, lock_flags2);
3574 DGAP_UNLOCK(ch->ch_lock, lock_flags2);
3575 DGAP_UNLOCK(bd->bd_lock, lock_flags);
3577 DPR_IOCTL(("dgap_set_modem_info finish\n"));
3584 * dgap_tty_digigeta()
3586 * Ioctl to get the information for ditty.
3591 static int dgap_tty_digigeta(struct tty_struct *tty, struct digi_t __user *retinfo)
3593 struct channel_t *ch;
3601 if (!tty || tty->magic != TTY_MAGIC)
3604 un = tty->driver_data;
3605 if (!un || un->magic != DGAP_UNIT_MAGIC)
3609 if (!ch || ch->magic != DGAP_CHANNEL_MAGIC)
3612 memset(&tmp, 0, sizeof(tmp));
3614 DGAP_LOCK(ch->ch_lock, lock_flags);
3615 memcpy(&tmp, &ch->ch_digi, sizeof(tmp));
3616 DGAP_UNLOCK(ch->ch_lock, lock_flags);
3618 if (copy_to_user(retinfo, &tmp, sizeof(*retinfo)))
3626 * dgap_tty_digiseta()
3628 * Ioctl to set the information for ditty.
3633 static int dgap_tty_digiseta(struct tty_struct *tty, struct digi_t __user *new_info)
3636 struct channel_t *ch;
3638 struct digi_t new_digi;
3639 ulong lock_flags = 0;
3640 unsigned long lock_flags2;
3642 DPR_IOCTL(("DIGI_SETA start\n"));
3644 if (!tty || tty->magic != TTY_MAGIC)
3647 un = tty->driver_data;
3648 if (!un || un->magic != DGAP_UNIT_MAGIC)
3652 if (!ch || ch->magic != DGAP_CHANNEL_MAGIC)
3656 if (!bd || bd->magic != DGAP_BOARD_MAGIC)
3659 if (copy_from_user(&new_digi, new_info, sizeof(struct digi_t))) {
3660 DPR_IOCTL(("DIGI_SETA failed copy_from_user\n"));
3664 DGAP_LOCK(bd->bd_lock, lock_flags);
3665 DGAP_LOCK(ch->ch_lock, lock_flags2);
3667 memcpy(&ch->ch_digi, &new_digi, sizeof(struct digi_t));
3669 if (ch->ch_digi.digi_maxcps < 1)
3670 ch->ch_digi.digi_maxcps = 1;
3672 if (ch->ch_digi.digi_maxcps > 10000)
3673 ch->ch_digi.digi_maxcps = 10000;
3675 if (ch->ch_digi.digi_bufsize < 10)
3676 ch->ch_digi.digi_bufsize = 10;
3678 if (ch->ch_digi.digi_maxchar < 1)
3679 ch->ch_digi.digi_maxchar = 1;
3681 if (ch->ch_digi.digi_maxchar > ch->ch_digi.digi_bufsize)
3682 ch->ch_digi.digi_maxchar = ch->ch_digi.digi_bufsize;
3684 if (ch->ch_digi.digi_onlen > DIGI_PLEN)
3685 ch->ch_digi.digi_onlen = DIGI_PLEN;
3687 if (ch->ch_digi.digi_offlen > DIGI_PLEN)
3688 ch->ch_digi.digi_offlen = DIGI_PLEN;
3692 DGAP_UNLOCK(ch->ch_lock, lock_flags2);
3693 DGAP_UNLOCK(bd->bd_lock, lock_flags);
3695 DPR_IOCTL(("DIGI_SETA finish\n"));
3702 * dgap_tty_digigetedelay()
3704 * Ioctl to get the current edelay setting.
3709 static int dgap_tty_digigetedelay(struct tty_struct *tty, int __user *retinfo)
3711 struct channel_t *ch;
3719 if (!tty || tty->magic != TTY_MAGIC)
3722 un = tty->driver_data;
3723 if (!un || un->magic != DGAP_UNIT_MAGIC)
3727 if (!ch || ch->magic != DGAP_CHANNEL_MAGIC)
3730 memset(&tmp, 0, sizeof(tmp));
3732 DGAP_LOCK(ch->ch_lock, lock_flags);
3733 tmp = readw(&(ch->ch_bs->edelay));
3734 DGAP_UNLOCK(ch->ch_lock, lock_flags);
3736 if (copy_to_user(retinfo, &tmp, sizeof(*retinfo)))
3744 * dgap_tty_digisetedelay()
3746 * Ioctl to set the EDELAY setting
3749 static int dgap_tty_digisetedelay(struct tty_struct *tty, int __user *new_info)
3752 struct channel_t *ch;
3758 DPR_IOCTL(("DIGI_SETA start\n"));
3760 if (!tty || tty->magic != TTY_MAGIC)
3763 un = tty->driver_data;
3764 if (!un || un->magic != DGAP_UNIT_MAGIC)
3768 if (!ch || ch->magic != DGAP_CHANNEL_MAGIC)
3772 if (!bd || bd->magic != DGAP_BOARD_MAGIC)
3775 if (copy_from_user(&new_digi, new_info, sizeof(int))) {
3776 DPR_IOCTL(("DIGI_SETEDELAY failed copy_from_user\n"));
3780 DGAP_LOCK(bd->bd_lock, lock_flags);
3781 DGAP_LOCK(ch->ch_lock, lock_flags2);
3783 writew((u16) new_digi, &(ch->ch_bs->edelay));
3787 DGAP_UNLOCK(ch->ch_lock, lock_flags2);
3788 DGAP_UNLOCK(bd->bd_lock, lock_flags);
3790 DPR_IOCTL(("DIGI_SETA finish\n"));
3797 * dgap_tty_digigetcustombaud()
3799 * Ioctl to get the current custom baud rate setting.
3801 static int dgap_tty_digigetcustombaud(struct tty_struct *tty, int __user *retinfo)
3803 struct channel_t *ch;
3811 if (!tty || tty->magic != TTY_MAGIC)
3814 un = tty->driver_data;
3815 if (!un || un->magic != DGAP_UNIT_MAGIC)
3819 if (!ch || ch->magic != DGAP_CHANNEL_MAGIC)
3822 memset(&tmp, 0, sizeof(tmp));
3824 DGAP_LOCK(ch->ch_lock, lock_flags);
3825 tmp = dgap_get_custom_baud(ch);
3826 DGAP_UNLOCK(ch->ch_lock, lock_flags);
3828 DPR_IOCTL(("DIGI_GETCUSTOMBAUD. Returning %d\n", tmp));
3830 if (copy_to_user(retinfo, &tmp, sizeof(*retinfo)))
3838 * dgap_tty_digisetcustombaud()
3840 * Ioctl to set the custom baud rate setting
3842 static int dgap_tty_digisetcustombaud(struct tty_struct *tty, int __user *new_info)
3845 struct channel_t *ch;
3851 DPR_IOCTL(("DIGI_SETCUSTOMBAUD start\n"));
3853 if (!tty || tty->magic != TTY_MAGIC)
3856 un = tty->driver_data;
3857 if (!un || un->magic != DGAP_UNIT_MAGIC)
3861 if (!ch || ch->magic != DGAP_CHANNEL_MAGIC)
3865 if (!bd || bd->magic != DGAP_BOARD_MAGIC)
3869 if (copy_from_user(&new_rate, new_info, sizeof(unsigned int))) {
3870 DPR_IOCTL(("DIGI_SETCUSTOMBAUD failed copy_from_user\n"));
3874 if (bd->bd_flags & BD_FEP5PLUS) {
3876 DPR_IOCTL(("DIGI_SETCUSTOMBAUD. Setting %d\n", new_rate));
3878 DGAP_LOCK(bd->bd_lock, lock_flags);
3879 DGAP_LOCK(ch->ch_lock, lock_flags2);
3881 ch->ch_custom_speed = new_rate;
3885 DGAP_UNLOCK(ch->ch_lock, lock_flags2);
3886 DGAP_UNLOCK(bd->bd_lock, lock_flags);
3889 DPR_IOCTL(("DIGI_SETCUSTOMBAUD finish\n"));
3896 * dgap_set_termios()
3898 static void dgap_tty_set_termios(struct tty_struct *tty, struct ktermios *old_termios)
3901 struct channel_t *ch;
3903 unsigned long lock_flags;
3904 unsigned long lock_flags2;
3906 if (!tty || tty->magic != TTY_MAGIC)
3909 un = tty->driver_data;
3910 if (!un || un->magic != DGAP_UNIT_MAGIC)
3914 if (!ch || ch->magic != DGAP_CHANNEL_MAGIC)
3918 if (!bd || bd->magic != DGAP_BOARD_MAGIC)
3921 DGAP_LOCK(bd->bd_lock, lock_flags);
3922 DGAP_LOCK(ch->ch_lock, lock_flags2);
3924 ch->ch_c_cflag = tty->termios.c_cflag;
3925 ch->ch_c_iflag = tty->termios.c_iflag;
3926 ch->ch_c_oflag = tty->termios.c_oflag;
3927 ch->ch_c_lflag = tty->termios.c_lflag;
3928 ch->ch_startc = tty->termios.c_cc[VSTART];
3929 ch->ch_stopc = tty->termios.c_cc[VSTOP];
3934 DGAP_UNLOCK(ch->ch_lock, lock_flags2);
3935 DGAP_UNLOCK(bd->bd_lock, lock_flags);
3939 static void dgap_tty_throttle(struct tty_struct *tty)
3942 struct channel_t *ch;
3947 if (!tty || tty->magic != TTY_MAGIC)
3950 un = tty->driver_data;
3951 if (!un || un->magic != DGAP_UNIT_MAGIC)
3955 if (!ch || ch->magic != DGAP_CHANNEL_MAGIC)
3959 if (!bd || bd->magic != DGAP_BOARD_MAGIC)
3962 DPR_IOCTL(("dgap_tty_throttle start\n"));
3964 DGAP_LOCK(bd->bd_lock, lock_flags);
3965 DGAP_LOCK(ch->ch_lock, lock_flags2);
3967 ch->ch_flags |= (CH_RXBLOCK);
3969 dgap_cmdw(ch, RPAUSE, 0, 0);
3972 DGAP_UNLOCK(ch->ch_lock, lock_flags2);
3973 DGAP_UNLOCK(bd->bd_lock, lock_flags);
3975 DPR_IOCTL(("dgap_tty_throttle finish\n"));
3979 static void dgap_tty_unthrottle(struct tty_struct *tty)
3982 struct channel_t *ch;
3987 if (!tty || tty->magic != TTY_MAGIC)
3990 un = tty->driver_data;
3991 if (!un || un->magic != DGAP_UNIT_MAGIC)
3995 if (!ch || ch->magic != DGAP_CHANNEL_MAGIC)
3999 if (!bd || bd->magic != DGAP_BOARD_MAGIC)
4002 DPR_IOCTL(("dgap_tty_unthrottle start\n"));
4004 DGAP_LOCK(bd->bd_lock, lock_flags);
4005 DGAP_LOCK(ch->ch_lock, lock_flags2);
4007 ch->ch_flags &= ~(CH_RXBLOCK);
4010 dgap_cmdw(ch, RRESUME, 0, 0);
4013 DGAP_UNLOCK(ch->ch_lock, lock_flags2);
4014 DGAP_UNLOCK(bd->bd_lock, lock_flags);
4016 DPR_IOCTL(("dgap_tty_unthrottle finish\n"));
4020 static void dgap_tty_start(struct tty_struct *tty)
4023 struct channel_t *ch;
4028 if (!tty || tty->magic != TTY_MAGIC)
4031 un = tty->driver_data;
4032 if (!un || un->magic != DGAP_UNIT_MAGIC)
4036 if (!ch || ch->magic != DGAP_CHANNEL_MAGIC)
4040 if (!bd || bd->magic != DGAP_BOARD_MAGIC)
4043 DPR_IOCTL(("dgap_tty_start start\n"));
4045 DGAP_LOCK(bd->bd_lock, lock_flags);
4046 DGAP_LOCK(ch->ch_lock, lock_flags2);
4048 dgap_cmdw(ch, RESUMETX, 0, 0);
4050 DGAP_UNLOCK(ch->ch_lock, lock_flags2);
4051 DGAP_UNLOCK(bd->bd_lock, lock_flags);
4053 DPR_IOCTL(("dgap_tty_start finish\n"));
4057 static void dgap_tty_stop(struct tty_struct *tty)
4060 struct channel_t *ch;
4065 if (!tty || tty->magic != TTY_MAGIC)
4068 un = tty->driver_data;
4069 if (!un || un->magic != DGAP_UNIT_MAGIC)
4073 if (!ch || ch->magic != DGAP_CHANNEL_MAGIC)
4077 if (!bd || bd->magic != DGAP_BOARD_MAGIC)
4080 DPR_IOCTL(("dgap_tty_stop start\n"));
4082 DGAP_LOCK(bd->bd_lock, lock_flags);
4083 DGAP_LOCK(ch->ch_lock, lock_flags2);
4085 dgap_cmdw(ch, PAUSETX, 0, 0);
4087 DGAP_UNLOCK(ch->ch_lock, lock_flags2);
4088 DGAP_UNLOCK(bd->bd_lock, lock_flags);
4090 DPR_IOCTL(("dgap_tty_stop finish\n"));
4095 * dgap_tty_flush_chars()
4097 * Flush the cook buffer
4099 * Note to self, and any other poor souls who venture here:
4101 * flush in this case DOES NOT mean dispose of the data.
4102 * instead, it means "stop buffering and send it if you
4103 * haven't already." Just guess how I figured that out... SRW 2-Jun-98
4105 * It is also always called in interrupt context - JAR 8-Sept-99
4107 static void dgap_tty_flush_chars(struct tty_struct *tty)
4110 struct channel_t *ch;
4115 if (!tty || tty->magic != TTY_MAGIC)
4118 un = tty->driver_data;
4119 if (!un || un->magic != DGAP_UNIT_MAGIC)
4123 if (!ch || ch->magic != DGAP_CHANNEL_MAGIC)
4127 if (!bd || bd->magic != DGAP_BOARD_MAGIC)
4130 DPR_IOCTL(("dgap_tty_flush_chars start\n"));
4132 DGAP_LOCK(bd->bd_lock, lock_flags);
4133 DGAP_LOCK(ch->ch_lock, lock_flags2);
4135 /* TODO: Do something here */
4137 DGAP_UNLOCK(ch->ch_lock, lock_flags2);
4138 DGAP_UNLOCK(bd->bd_lock, lock_flags);
4140 DPR_IOCTL(("dgap_tty_flush_chars finish\n"));
4146 * dgap_tty_flush_buffer()
4148 * Flush Tx buffer (make in == out)
4150 static void dgap_tty_flush_buffer(struct tty_struct *tty)
4153 struct channel_t *ch;
4159 if (!tty || tty->magic != TTY_MAGIC)
4162 un = tty->driver_data;
4163 if (!un || un->magic != DGAP_UNIT_MAGIC)
4167 if (!ch || ch->magic != DGAP_CHANNEL_MAGIC)
4171 if (!bd || bd->magic != DGAP_BOARD_MAGIC)
4174 DPR_IOCTL(("dgap_tty_flush_buffer on port: %d start\n", ch->ch_portnum));
4176 DGAP_LOCK(bd->bd_lock, lock_flags);
4177 DGAP_LOCK(ch->ch_lock, lock_flags2);
4179 ch->ch_flags &= ~CH_STOP;
4180 head = readw(&(ch->ch_bs->tx_head));
4181 dgap_cmdw(ch, FLUSHTX, (u16) head, 0);
4182 dgap_cmdw(ch, RESUMETX, 0, 0);
4183 if (ch->ch_tun.un_flags & (UN_LOW|UN_EMPTY)) {
4184 ch->ch_tun.un_flags &= ~(UN_LOW|UN_EMPTY);
4185 wake_up_interruptible(&ch->ch_tun.un_flags_wait);
4187 if (ch->ch_pun.un_flags & (UN_LOW|UN_EMPTY)) {
4188 ch->ch_pun.un_flags &= ~(UN_LOW|UN_EMPTY);
4189 wake_up_interruptible(&ch->ch_pun.un_flags_wait);
4192 DGAP_UNLOCK(ch->ch_lock, lock_flags2);
4193 DGAP_UNLOCK(bd->bd_lock, lock_flags);
4194 if (waitqueue_active(&tty->write_wait))
4195 wake_up_interruptible(&tty->write_wait);
4198 DPR_IOCTL(("dgap_tty_flush_buffer finish\n"));
4203 /*****************************************************************************
4205 * The IOCTL function and all of its helpers
4207 *****************************************************************************/
4212 * The usual assortment of ioctl's
4214 static int dgap_tty_ioctl(struct tty_struct *tty, unsigned int cmd,
4218 struct channel_t *ch;
4222 ulong lock_flags = 0;
4223 ulong lock_flags2 = 0;
4224 void __user *uarg = (void __user *) arg;
4226 if (!tty || tty->magic != TTY_MAGIC)
4229 un = tty->driver_data;
4230 if (!un || un->magic != DGAP_UNIT_MAGIC)
4234 if (!ch || ch->magic != DGAP_CHANNEL_MAGIC)
4238 if (!bd || bd->magic != DGAP_BOARD_MAGIC)
4241 DPR_IOCTL(("dgap_tty_ioctl start on port %d - cmd %s (%x), arg %lx\n",
4242 ch->ch_portnum, dgap_ioctl_name(cmd), cmd, arg));
4244 DGAP_LOCK(bd->bd_lock, lock_flags);
4245 DGAP_LOCK(ch->ch_lock, lock_flags2);
4247 if (un->un_open_count <= 0) {
4248 DPR_BASIC(("dgap_tty_ioctl - unit not open.\n"));
4249 DGAP_UNLOCK(ch->ch_lock, lock_flags2);
4250 DGAP_UNLOCK(bd->bd_lock, lock_flags);
4256 /* Here are all the standard ioctl's that we MUST implement */
4260 * TCSBRK is SVID version: non-zero arg --> no break
4261 * this behaviour is exploited by tcdrain().
4263 * According to POSIX.1 spec (7.2.2.1.2) breaks should be
4264 * between 0.25 and 0.5 seconds so we'll ask for something
4265 * in the middle: 0.375 seconds.
4267 rc = tty_check_change(tty);
4268 DGAP_UNLOCK(ch->ch_lock, lock_flags2);
4269 DGAP_UNLOCK(bd->bd_lock, lock_flags);
4274 rc = dgap_wait_for_drain(tty);
4277 DPR_IOCTL(("dgap_tty_ioctl - bad return: %d ", rc));
4281 DGAP_LOCK(bd->bd_lock, lock_flags);
4282 DGAP_LOCK(ch->ch_lock, lock_flags2);
4284 if(((cmd == TCSBRK) && (!arg)) || (cmd == TCSBRKP)) {
4285 dgap_cmdw(ch, SBREAK, (u16) SBREAK_TIME, 0);
4288 DGAP_UNLOCK(ch->ch_lock, lock_flags2);
4289 DGAP_UNLOCK(bd->bd_lock, lock_flags);
4291 DPR_IOCTL(("dgap_tty_ioctl finish on port %d - cmd %s (%x), arg %lx\n",
4292 ch->ch_portnum, dgap_ioctl_name(cmd), cmd, arg));
4298 /* support for POSIX tcsendbreak()
4300 * According to POSIX.1 spec (7.2.2.1.2) breaks should be
4301 * between 0.25 and 0.5 seconds so we'll ask for something
4302 * in the middle: 0.375 seconds.
4304 rc = tty_check_change(tty);
4305 DGAP_UNLOCK(ch->ch_lock, lock_flags2);
4306 DGAP_UNLOCK(bd->bd_lock, lock_flags);
4311 rc = dgap_wait_for_drain(tty);
4313 DPR_IOCTL(("dgap_tty_ioctl - bad return: %d ", rc));
4317 DGAP_LOCK(bd->bd_lock, lock_flags);
4318 DGAP_LOCK(ch->ch_lock, lock_flags2);
4320 dgap_cmdw(ch, SBREAK, (u16) SBREAK_TIME, 0);
4322 DGAP_UNLOCK(ch->ch_lock, lock_flags2);
4323 DGAP_UNLOCK(bd->bd_lock, lock_flags);
4325 DPR_IOCTL(("dgap_tty_ioctl finish on port %d - cmd %s (%x), arg %lx\n",
4326 ch->ch_portnum, dgap_ioctl_name(cmd), cmd, arg));
4332 * FEP5 doesn't support turning on a break unconditionally.
4333 * The FEP5 device will stop sending a break automatically
4334 * after the specified time value that was sent when turning on
4337 rc = tty_check_change(tty);
4338 DGAP_UNLOCK(ch->ch_lock, lock_flags2);
4339 DGAP_UNLOCK(bd->bd_lock, lock_flags);
4344 rc = dgap_wait_for_drain(tty);
4346 DPR_IOCTL(("dgap_tty_ioctl - bad return: %d ", rc));
4350 DGAP_LOCK(bd->bd_lock, lock_flags);
4351 DGAP_LOCK(ch->ch_lock, lock_flags2);
4353 dgap_cmdw(ch, SBREAK, (u16) SBREAK_TIME, 0);
4355 DGAP_UNLOCK(ch->ch_lock, lock_flags2);
4356 DGAP_UNLOCK(bd->bd_lock, lock_flags);
4358 DPR_IOCTL(("dgap_tty_ioctl finish on port %d - cmd %s (%x), arg %lx\n",
4359 ch->ch_portnum, dgap_ioctl_name(cmd), cmd, arg));
4365 * FEP5 doesn't support turning off a break unconditionally.
4366 * The FEP5 device will stop sending a break automatically
4367 * after the specified time value that was sent when turning on
4370 DGAP_UNLOCK(ch->ch_lock, lock_flags2);
4371 DGAP_UNLOCK(bd->bd_lock, lock_flags);
4376 DGAP_UNLOCK(ch->ch_lock, lock_flags2);
4377 DGAP_UNLOCK(bd->bd_lock, lock_flags);
4379 rc = put_user(C_CLOCAL(tty) ? 1 : 0, (unsigned long __user *) arg);
4383 DGAP_UNLOCK(ch->ch_lock, lock_flags2);
4384 DGAP_UNLOCK(bd->bd_lock, lock_flags);
4386 rc = get_user(arg, (unsigned long __user *) arg);
4390 DGAP_LOCK(bd->bd_lock, lock_flags);
4391 DGAP_LOCK(ch->ch_lock, lock_flags2);
4392 tty->termios.c_cflag = ((tty->termios.c_cflag & ~CLOCAL) | (arg ? CLOCAL : 0));
4394 DGAP_UNLOCK(ch->ch_lock, lock_flags2);
4395 DGAP_UNLOCK(bd->bd_lock, lock_flags);
4400 DGAP_UNLOCK(ch->ch_lock, lock_flags2);
4401 DGAP_UNLOCK(bd->bd_lock, lock_flags);
4402 return(dgap_get_modem_info(ch, uarg));
4407 DGAP_UNLOCK(ch->ch_lock, lock_flags2);
4408 DGAP_UNLOCK(bd->bd_lock, lock_flags);
4409 return(dgap_set_modem_info(tty, cmd, uarg));
4412 * Here are any additional ioctl's that we want to implement
4417 * The linux tty driver doesn't have a flush
4418 * input routine for the driver, assuming all backed
4419 * up data is in the line disc. buffers. However,
4420 * we all know that's not the case. Here, we
4421 * act on the ioctl, but then lie and say we didn't
4422 * so the line discipline will process the flush
4425 rc = tty_check_change(tty);
4427 DGAP_UNLOCK(ch->ch_lock, lock_flags2);
4428 DGAP_UNLOCK(bd->bd_lock, lock_flags);
4432 if ((arg == TCIFLUSH) || (arg == TCIOFLUSH)) {
4433 if (!(un->un_type == DGAP_PRINT)) {
4434 head = readw(&(ch->ch_bs->rx_head));
4435 writew(head, &(ch->ch_bs->rx_tail));
4436 writeb(0, &(ch->ch_bs->orun));
4440 if ((arg == TCOFLUSH) || (arg == TCIOFLUSH)) {
4441 ch->ch_flags &= ~CH_STOP;
4442 head = readw(&(ch->ch_bs->tx_head));
4443 dgap_cmdw(ch, FLUSHTX, (u16) head, 0 );
4444 dgap_cmdw(ch, RESUMETX, 0, 0);
4445 if (ch->ch_tun.un_flags & (UN_LOW|UN_EMPTY)) {
4446 ch->ch_tun.un_flags &= ~(UN_LOW|UN_EMPTY);
4447 wake_up_interruptible(&ch->ch_tun.un_flags_wait);
4449 if (ch->ch_pun.un_flags & (UN_LOW|UN_EMPTY)) {
4450 ch->ch_pun.un_flags &= ~(UN_LOW|UN_EMPTY);
4451 wake_up_interruptible(&ch->ch_pun.un_flags_wait);
4453 if (waitqueue_active(&tty->write_wait))
4454 wake_up_interruptible(&tty->write_wait);
4456 /* Can't hold any locks when calling tty_wakeup! */
4457 DGAP_UNLOCK(ch->ch_lock, lock_flags2);
4458 DGAP_UNLOCK(bd->bd_lock, lock_flags);
4460 DGAP_LOCK(bd->bd_lock, lock_flags);
4461 DGAP_LOCK(ch->ch_lock, lock_flags2);
4464 /* pretend we didn't recognize this IOCTL */
4465 DGAP_UNLOCK(ch->ch_lock, lock_flags2);
4466 DGAP_UNLOCK(bd->bd_lock, lock_flags);
4468 DPR_IOCTL(("dgap_tty_ioctl (LINE:%d) finish on port %d - cmd %s (%x), arg %lx\n",
4469 __LINE__, ch->ch_portnum, dgap_ioctl_name(cmd), cmd, arg));
4471 return(-ENOIOCTLCMD);
4476 * The linux tty driver doesn't have a flush
4477 * input routine for the driver, assuming all backed
4478 * up data is in the line disc. buffers. However,
4479 * we all know that's not the case. Here, we
4480 * act on the ioctl, but then lie and say we didn't
4481 * so the line discipline will process the flush
4484 if (cmd == TCSETSF) {
4486 ch->ch_flags &= ~CH_STOP;
4487 head = readw(&(ch->ch_bs->rx_head));
4488 writew(head, &(ch->ch_bs->rx_tail));
4491 /* now wait for all the output to drain */
4492 DGAP_UNLOCK(ch->ch_lock, lock_flags2);
4493 DGAP_UNLOCK(bd->bd_lock, lock_flags);
4494 rc = dgap_wait_for_drain(tty);
4496 DPR_IOCTL(("dgap_tty_ioctl - bad return: %d ", rc));
4500 DPR_IOCTL(("dgap_tty_ioctl finish on port %d - cmd %s (%x), arg %lx\n",
4501 ch->ch_portnum, dgap_ioctl_name(cmd), cmd, arg));
4503 /* pretend we didn't recognize this */
4504 return(-ENOIOCTLCMD);
4508 DGAP_UNLOCK(ch->ch_lock, lock_flags2);
4509 DGAP_UNLOCK(bd->bd_lock, lock_flags);
4510 rc = dgap_wait_for_drain(tty);
4512 DPR_IOCTL(("dgap_tty_ioctl - bad return: %d ", rc));
4516 /* pretend we didn't recognize this */
4517 return(-ENOIOCTLCMD);
4521 * The Linux Line Discipline (LD) would do this for us if we
4522 * let it, but we have the special firmware options to do this
4523 * the "right way" regardless of hardware or software flow
4524 * control so we'll do it outselves instead of letting the LD
4527 rc = tty_check_change(tty);
4529 DGAP_UNLOCK(ch->ch_lock, lock_flags2);
4530 DGAP_UNLOCK(bd->bd_lock, lock_flags);
4534 DPR_IOCTL(("dgap_ioctl - in TCXONC - %d\n", cmd));
4538 DGAP_UNLOCK(ch->ch_lock, lock_flags2);
4539 DGAP_UNLOCK(bd->bd_lock, lock_flags);
4540 dgap_tty_start(tty);
4543 DGAP_UNLOCK(ch->ch_lock, lock_flags2);
4544 DGAP_UNLOCK(bd->bd_lock, lock_flags);
4548 DGAP_UNLOCK(ch->ch_lock, lock_flags2);
4549 DGAP_UNLOCK(bd->bd_lock, lock_flags);
4550 /* Make the ld do it */
4551 return(-ENOIOCTLCMD);
4553 DGAP_UNLOCK(ch->ch_lock, lock_flags2);
4554 DGAP_UNLOCK(bd->bd_lock, lock_flags);
4555 /* Make the ld do it */
4556 return(-ENOIOCTLCMD);
4558 DGAP_UNLOCK(ch->ch_lock, lock_flags2);
4559 DGAP_UNLOCK(bd->bd_lock, lock_flags);
4564 /* get information for ditty */
4565 DGAP_UNLOCK(ch->ch_lock, lock_flags2);
4566 DGAP_UNLOCK(bd->bd_lock, lock_flags);
4567 return(dgap_tty_digigeta(tty, uarg));
4572 /* set information for ditty */
4573 if (cmd == (DIGI_SETAW)) {
4575 DGAP_UNLOCK(ch->ch_lock, lock_flags2);
4576 DGAP_UNLOCK(bd->bd_lock, lock_flags);
4577 rc = dgap_wait_for_drain(tty);
4579 DPR_IOCTL(("dgap_tty_ioctl - bad return: %d ", rc));
4582 DGAP_LOCK(bd->bd_lock, lock_flags);
4583 DGAP_LOCK(ch->ch_lock, lock_flags2);
4586 tty_ldisc_flush(tty);
4591 DGAP_UNLOCK(ch->ch_lock, lock_flags2);
4592 DGAP_UNLOCK(bd->bd_lock, lock_flags);
4593 return(dgap_tty_digiseta(tty, uarg));
4596 DGAP_UNLOCK(ch->ch_lock, lock_flags2);
4597 DGAP_UNLOCK(bd->bd_lock, lock_flags);
4598 return(dgap_tty_digigetedelay(tty, uarg));
4601 DGAP_UNLOCK(ch->ch_lock, lock_flags2);
4602 DGAP_UNLOCK(bd->bd_lock, lock_flags);
4603 return(dgap_tty_digisetedelay(tty, uarg));
4605 case DIGI_GETCUSTOMBAUD:
4606 DGAP_UNLOCK(ch->ch_lock, lock_flags2);
4607 DGAP_UNLOCK(bd->bd_lock, lock_flags);
4608 return(dgap_tty_digigetcustombaud(tty, uarg));
4610 case DIGI_SETCUSTOMBAUD:
4611 DGAP_UNLOCK(ch->ch_lock, lock_flags2);
4612 DGAP_UNLOCK(bd->bd_lock, lock_flags);
4613 return(dgap_tty_digisetcustombaud(tty, uarg));
4615 case DIGI_RESET_PORT:
4616 dgap_firmware_reset_port(ch);
4618 DGAP_UNLOCK(ch->ch_lock, lock_flags2);
4619 DGAP_UNLOCK(bd->bd_lock, lock_flags);
4623 DGAP_UNLOCK(ch->ch_lock, lock_flags2);
4624 DGAP_UNLOCK(bd->bd_lock, lock_flags);
4626 DPR_IOCTL(("dgap_tty_ioctl - in default\n"));
4627 DPR_IOCTL(("dgap_tty_ioctl end - cmd %s (%x), arg %lx\n",
4628 dgap_ioctl_name(cmd), cmd, arg));
4630 return(-ENOIOCTLCMD);
4634 * Loads the dgap.conf config file from the user.
4636 void dgap_do_config_load(uchar __user *uaddr, int len)
4640 uchar __user *from_addr = uaddr;
4644 to_addr = dgap_config_buf = kzalloc(len + 1, GFP_ATOMIC);
4645 if (!dgap_config_buf) {
4646 DPR_INIT(("dgap_do_config_load - unable to allocate memory for file\n"));
4647 dgap_driver_state = DRIVER_NEED_CONFIG_LOAD;
4657 if (copy_from_user((char *) &buf, from_addr, n) == -1 )
4660 /* Copy data from buffer to kernel memory */
4661 memcpy(to_addr, buf, n);
4663 /* increment counts */
4670 dgap_config_buf[orig_len] = '\0';
4672 to_addr = dgap_config_buf;
4673 dgap_parsefile(&to_addr, TRUE);
4675 DPR_INIT(("dgap_config_load() finish\n"));
4681 int dgap_after_config_loaded(void)
4687 * Register our ttys, now that we have the config loaded.
4689 for (i = 0; i < dgap_NumBoards; ++i) {
4692 * Initialize KME waitqueues...
4694 init_waitqueue_head(&(dgap_Board[i]->kme_wait));
4697 * allocate flip buffer for board.
4699 dgap_Board[i]->flipbuf = kzalloc(MYFLIPLEN, GFP_ATOMIC);
4700 dgap_Board[i]->flipflagbuf = kzalloc(MYFLIPLEN, GFP_ATOMIC);
4708 /*=======================================================================
4710 * usertoboard - copy from user space to board space.
4712 *=======================================================================*/
4713 static int dgap_usertoboard(struct board_t *brd, char *to_addr, char __user *from_addr, int len)
4718 if (!brd || brd->magic != DGAP_BOARD_MAGIC)
4725 if (copy_from_user((char *) &buf, from_addr, n) == -1 ) {
4729 /* Copy data from buffer to card memory */
4730 memcpy_toio(to_addr, buf, n);
4732 /* increment counts */
4743 * Copies the BIOS code from the user to the board,
4744 * and starts the BIOS running.
4746 void dgap_do_bios_load(struct board_t *brd, uchar __user *ubios, int len)
4752 if (!brd || (brd->magic != DGAP_BOARD_MAGIC) || !brd->re_map_membase)
4755 DPR_INIT(("dgap_do_bios_load() start\n"));
4757 addr = brd->re_map_membase;
4762 for (i = 0; i < 16; i++)
4763 writeb(0, addr + POSTAREA + i);
4769 if (dgap_usertoboard(brd, addr + offset, ubios, len) == -1 ) {
4770 brd->state = BOARD_FAILED;
4771 brd->dpastatus = BD_NOFEP;
4775 writel(0x0bf00401, addr);
4776 writel(0, (addr + 4));
4778 /* Clear the reset, and change states. */
4779 writeb(FEPCLR, brd->re_map_port);
4780 brd->state = WAIT_BIOS_LOAD;
4785 * Checks to see if the BIOS completed running on the card.
4787 static void dgap_do_wait_for_bios(struct board_t *brd)
4792 if (!brd || (brd->magic != DGAP_BOARD_MAGIC) || !brd->re_map_membase)
4795 addr = brd->re_map_membase;
4796 word = readw(addr + POSTAREA);
4798 /* Check to see if BIOS thinks board is good. (GD). */
4799 if (word == *(u16 *) "GD") {
4800 DPR_INIT(("GOT GD in memory, moving states.\n"));
4801 brd->state = FINISHED_BIOS_LOAD;
4805 /* Give up on board after too long of time taken */
4806 if (brd->wait_for_bios++ > 5000) {
4807 u16 err1 = readw(addr + SEQUENCE);
4808 u16 err2 = readw(addr + ERROR);
4809 APR(("***WARNING*** %s failed diagnostics. Error #(%x,%x).\n",
4810 brd->name, err1, err2));
4811 brd->state = BOARD_FAILED;
4812 brd->dpastatus = BD_NOFEP;
4818 * Copies the FEP code from the user to the board,
4819 * and starts the FEP running.
4821 void dgap_do_fep_load(struct board_t *brd, uchar __user *ufep, int len)
4826 if (!brd || (brd->magic != DGAP_BOARD_MAGIC) || !brd->re_map_membase)
4829 addr = brd->re_map_membase;
4831 DPR_INIT(("dgap_do_fep_load() for board %s : start\n", brd->name));
4837 if (dgap_usertoboard(brd, addr + offset, ufep, len) == -1 ) {
4838 brd->state = BOARD_FAILED;
4839 brd->dpastatus = BD_NOFEP;
4844 * If board is a concentrator product, we need to give
4845 * it its config string describing how the concentrators look.
4847 if ((brd->type == PCX) || (brd->type == PEPC)) {
4849 uchar *config, *xconfig;
4852 xconfig = dgap_create_config_string(brd, string);
4854 /* Write string to board memory */
4855 config = addr + CONFIG;
4856 for (; i < CONFIGSIZE; i++, config++, xconfig++) {
4857 writeb(*xconfig, config);
4858 if ((*xconfig & 0xff) == 0xff)
4863 writel(0xbfc01004, (addr + 0xc34));
4864 writel(0x3, (addr + 0xc30));
4866 /* change states. */
4867 brd->state = WAIT_FEP_LOAD;
4869 DPR_INIT(("dgap_do_fep_load() for board %s : finish\n", brd->name));
4875 * Waits for the FEP to report thats its ready for us to use.
4877 static void dgap_do_wait_for_fep(struct board_t *brd)
4882 if (!brd || (brd->magic != DGAP_BOARD_MAGIC) || !brd->re_map_membase)
4885 addr = brd->re_map_membase;
4887 DPR_INIT(("dgap_do_wait_for_fep() for board %s : start. addr: %p\n", brd->name, addr));
4889 word = readw(addr + FEPSTAT);
4891 /* Check to see if FEP is up and running now. */
4892 if (word == *(u16 *) "OS") {
4893 DPR_INIT(("GOT OS in memory for board %s, moving states.\n", brd->name));
4894 brd->state = FINISHED_FEP_LOAD;
4897 * Check to see if the board can support FEP5+ commands.
4899 word = readw(addr + FEP5_PLUS);
4900 if (word == *(u16 *) "5A") {
4901 DPR_INIT(("GOT 5A in memory for board %s, board supports extended FEP5 commands.\n", brd->name));
4902 brd->bd_flags |= BD_FEP5PLUS;
4908 /* Give up on board after too long of time taken */
4909 if (brd->wait_for_fep++ > 5000) {
4910 u16 err1 = readw(addr + SEQUENCE);
4911 u16 err2 = readw(addr + ERROR);
4912 APR(("***WARNING*** FEPOS for %s not functioning. Error #(%x,%x).\n",
4913 brd->name, err1, err2));
4914 brd->state = BOARD_FAILED;
4915 brd->dpastatus = BD_NOFEP;
4918 DPR_INIT(("dgap_do_wait_for_fep() for board %s : finish\n", brd->name));
4923 * Physically forces the FEP5 card to reset itself.
4925 static void dgap_do_reset_board(struct board_t *brd)
4932 if (!brd || (brd->magic != DGAP_BOARD_MAGIC) || !brd->re_map_membase || !brd->re_map_port) {
4933 DPR_INIT(("dgap_do_reset_board() start. bad values. brd: %p mem: %p io: %p\n",
4934 brd, brd ? brd->re_map_membase : 0, brd ? brd->re_map_port : 0));
4938 DPR_INIT(("dgap_do_reset_board() start. io: %p\n", brd->re_map_port));
4940 /* FEPRST does not vary among supported boards */
4941 writeb(FEPRST, brd->re_map_port);
4943 for (i = 0; i <= 1000; i++) {
4944 check = readb(brd->re_map_port) & 0xe;
4945 if (check == FEPRST)
4951 APR(("*** WARNING *** Board not resetting... Failing board.\n"));
4952 brd->state = BOARD_FAILED;
4953 brd->dpastatus = BD_NOFEP;
4958 * Make sure there really is memory out there.
4960 writel(0xa55a3cc3, (brd->re_map_membase + LOWMEM));
4961 writel(0x5aa5c33c, (brd->re_map_membase + HIGHMEM));
4962 check1 = readl(brd->re_map_membase + LOWMEM);
4963 check2 = readl(brd->re_map_membase + HIGHMEM);
4965 if ((check1 != 0xa55a3cc3) || (check2 != 0x5aa5c33c)) {
4966 APR(("*** Warning *** No memory at %p for board.\n", brd->re_map_membase));
4967 brd->state = BOARD_FAILED;
4968 brd->dpastatus = BD_NOFEP;
4972 if (brd->state != BOARD_FAILED)
4973 brd->state = FINISHED_RESET;
4976 DPR_INIT(("dgap_do_reset_board() finish\n"));
4981 * Sends a concentrator image into the FEP5 board.
4983 void dgap_do_conc_load(struct board_t *brd, uchar *uaddr, int len)
4987 struct downld_t *to_dp;
4989 if (!brd || (brd->magic != DGAP_BOARD_MAGIC) || !brd->re_map_membase)
4992 vaddr = brd->re_map_membase;
4994 offset = readw((u16 *) (vaddr + DOWNREQ));
4995 to_dp = (struct downld_t *) (vaddr + (int) offset);
4998 * The image was already read into kernel space,
4999 * we do NOT need a user space read here
5001 memcpy_toio((char *) to_dp, uaddr, sizeof(struct downld_t));
5003 /* Tell card we have data for it */
5004 writew(0, vaddr + (DOWNREQ));
5006 brd->conc_dl_status = NO_PENDING_CONCENTRATOR_REQUESTS;
5010 #define EXPANSION_ROM_SIZE (64 * 1024)
5011 #define FEP5_ROM_MAGIC (0xFEFFFFFF)
5013 static void dgap_get_vpd(struct board_t *brd)
5025 * Poke the magic number at the PCI Rom Address location.
5026 * If VPD is supported, the value read from that address
5029 magic = FEP5_ROM_MAGIC;
5030 pci_write_config_dword(brd->pdev, PCI_ROM_ADDRESS, magic);
5031 pci_read_config_dword(brd->pdev, PCI_ROM_ADDRESS, &magic);
5033 /* VPD not supported, bail */
5038 * To get to the OTPROM memory, we have to send the boards base
5039 * address or'ed with 1 into the PCI Rom Address location.
5041 magic = brd->membase | 0x01;
5042 pci_write_config_dword(brd->pdev, PCI_ROM_ADDRESS, magic);
5043 pci_read_config_dword(brd->pdev, PCI_ROM_ADDRESS, &magic);
5045 byte1 = readb(brd->re_map_membase);
5046 byte2 = readb(brd->re_map_membase + 1);
5049 * If the board correctly swapped to the OTPROM memory,
5050 * the first 2 bytes (header) should be 0x55, 0xAA
5052 if (byte1 == 0x55 && byte2 == 0xAA) {
5057 * We have to run through all the OTPROM memory looking
5058 * for the VPD offset.
5060 while (base_offset <= EXPANSION_ROM_SIZE) {
5063 * Lots of magic numbers here.
5065 * The VPD offset is located inside the ROM Data Structure.
5066 * We also have to remember the length of each
5067 * ROM Data Structure, so we can "hop" to the next
5068 * entry if the VPD isn't in the current
5069 * ROM Data Structure.
5071 rom_offset = readw(brd->re_map_membase + base_offset + 0x18);
5072 image_length = readw(brd->re_map_membase + rom_offset + 0x10) * 512;
5073 vpd_offset = readw(brd->re_map_membase + rom_offset + 0x08);
5075 /* Found the VPD entry */
5079 /* We didn't find a VPD entry, go to next ROM entry. */
5080 base_offset += image_length;
5082 byte1 = readb(brd->re_map_membase + base_offset);
5083 byte2 = readb(brd->re_map_membase + base_offset + 1);
5086 * If the new ROM offset doesn't have 0x55, 0xAA
5087 * as its header, we have run out of ROM.
5089 if (byte1 != 0x55 || byte2 != 0xAA)
5094 * If we have a VPD offset, then mark the board
5095 * as having a valid VPD, and copy VPDSIZE (512) bytes of
5096 * that VPD to the buffer we have in our board structure.
5099 brd->bd_flags |= BD_HAS_VPD;
5100 for (i = 0; i < VPDSIZE; i++)
5101 brd->vpd[i] = readb(brd->re_map_membase + vpd_offset + i);
5106 * We MUST poke the magic number at the PCI Rom Address location again.
5107 * This makes the card report the regular board memory back to us,
5108 * rather than the OTPROM memory.
5110 magic = FEP5_ROM_MAGIC;
5111 pci_write_config_dword(brd->pdev, PCI_ROM_ADDRESS, magic);
5116 * Our board poller function.
5118 void dgap_poll_tasklet(unsigned long data)
5120 struct board_t *bd = (struct board_t *) data;
5128 if (!bd || (bd->magic != DGAP_BOARD_MAGIC)) {
5129 APR(("dgap_poll_tasklet() - NULL or bad bd.\n"));
5133 if (bd->inhibit_poller)
5136 DGAP_LOCK(bd->bd_lock, lock_flags);
5138 vaddr = bd->re_map_membase;
5141 * If board is ready, parse deeper to see if there is anything to do.
5143 if (bd->state == BOARD_READY) {
5145 struct ev_t *eaddr = NULL;
5147 if (!bd->re_map_membase) {
5148 DGAP_UNLOCK(bd->bd_lock, lock_flags);
5151 if (!bd->re_map_port) {
5152 DGAP_UNLOCK(bd->bd_lock, lock_flags);
5161 * If this is a CX or EPCX, we need to see if the firmware
5162 * is requesting a concentrator image from us.
5164 if ((bd->type == PCX) || (bd->type == PEPC)) {
5165 chk_addr = (u16 *) (vaddr + DOWNREQ);
5166 check = readw(chk_addr);
5167 /* Nonzero if FEP is requesting concentrator image. */
5169 if (bd->conc_dl_status == NO_PENDING_CONCENTRATOR_REQUESTS)
5170 bd->conc_dl_status = NEED_CONCENTRATOR;
5172 * Signal downloader, its got some work to do.
5174 DGAP_LOCK(dgap_dl_lock, lock_flags2);
5175 if (dgap_dl_action != 1) {
5177 wake_up_interruptible(&dgap_dl_wait);
5179 DGAP_UNLOCK(dgap_dl_lock, lock_flags2);
5184 eaddr = (struct ev_t *) (vaddr + EVBUF);
5186 /* Get our head and tail */
5187 head = readw(&(eaddr->ev_head));
5188 tail = readw(&(eaddr->ev_tail));
5191 * If there is an event pending. Go service it.
5194 DGAP_UNLOCK(bd->bd_lock, lock_flags);
5196 DGAP_LOCK(bd->bd_lock, lock_flags);
5201 * If board is doing interrupts, ACK the interrupt.
5203 if (bd && bd->intr_running) {
5204 readb(bd->re_map_port + 2);
5207 DGAP_UNLOCK(bd->bd_lock, lock_flags);
5211 /* Our state machine to get the board up and running */
5214 if (bd->state == NEED_RESET) {
5219 dgap_do_reset_board(bd);
5222 /* Move to next state */
5223 if (bd->state == FINISHED_RESET) {
5224 bd->state = NEED_CONFIG;
5227 if (bd->state == NEED_CONFIG) {
5229 * Match this board to a config the user created for us.
5231 bd->bd_config = dgap_find_config(bd->type, bd->pci_bus, bd->pci_slot);
5234 * Because the 4 port Xr products share the same PCI ID
5235 * as the 8 port Xr products, if we receive a NULL config
5236 * back, and this is a PAPORT8 board, retry with a
5237 * PAPORT4 attempt as well.
5239 if (bd->type == PAPORT8 && !bd->bd_config) {
5240 bd->bd_config = dgap_find_config(PAPORT4, bd->pci_bus, bd->pci_slot);
5244 * Register the ttys (if any) into the kernel.
5246 if (bd->bd_config) {
5247 bd->state = FINISHED_CONFIG;
5250 bd->state = CONFIG_NOT_FOUND;
5254 /* Move to next state */
5255 if (bd->state == FINISHED_CONFIG) {
5256 bd->state = NEED_DEVICE_CREATION;
5259 /* Move to next state */
5260 if (bd->state == NEED_DEVICE_CREATION) {
5262 * Signal downloader, its got some work to do.
5264 DGAP_LOCK(dgap_dl_lock, lock_flags2);
5265 if (dgap_dl_action != 1) {
5267 wake_up_interruptible(&dgap_dl_wait);
5269 DGAP_UNLOCK(dgap_dl_lock, lock_flags2);
5272 /* Move to next state */
5273 if (bd->state == FINISHED_DEVICE_CREATION) {
5274 bd->state = NEED_BIOS_LOAD;
5277 /* Move to next state */
5278 if (bd->state == NEED_BIOS_LOAD) {
5280 * Signal downloader, its got some work to do.
5282 DGAP_LOCK(dgap_dl_lock, lock_flags2);
5283 if (dgap_dl_action != 1) {
5285 wake_up_interruptible(&dgap_dl_wait);
5287 DGAP_UNLOCK(dgap_dl_lock, lock_flags2);
5290 /* Wait for BIOS to test board... */
5291 if (bd->state == WAIT_BIOS_LOAD) {
5292 dgap_do_wait_for_bios(bd);
5295 /* Move to next state */
5296 if (bd->state == FINISHED_BIOS_LOAD) {
5297 bd->state = NEED_FEP_LOAD;
5300 * Signal downloader, its got some work to do.
5302 DGAP_LOCK(dgap_dl_lock, lock_flags2);
5303 if (dgap_dl_action != 1) {
5305 wake_up_interruptible(&dgap_dl_wait);
5307 DGAP_UNLOCK(dgap_dl_lock, lock_flags2);
5310 /* Wait for FEP to load on board... */
5311 if (bd->state == WAIT_FEP_LOAD) {
5312 dgap_do_wait_for_fep(bd);
5316 /* Move to next state */
5317 if (bd->state == FINISHED_FEP_LOAD) {
5320 * Do tty device initialization.
5322 int rc = dgap_tty_init(bd);
5325 dgap_tty_uninit(bd);
5326 APR(("Can't init tty devices (%d)\n", rc));
5327 bd->state = BOARD_FAILED;
5328 bd->dpastatus = BD_NOFEP;
5331 bd->state = NEED_PROC_CREATION;
5334 * Signal downloader, its got some work to do.
5336 DGAP_LOCK(dgap_dl_lock, lock_flags2);
5337 if (dgap_dl_action != 1) {
5339 wake_up_interruptible(&dgap_dl_wait);
5341 DGAP_UNLOCK(dgap_dl_lock, lock_flags2);
5345 /* Move to next state */
5346 if (bd->state == FINISHED_PROC_CREATION) {
5348 bd->state = BOARD_READY;
5349 bd->dpastatus = BD_RUNNING;
5352 * If user requested the board to run in interrupt mode,
5353 * go and set it up on the board.
5355 if (bd->intr_used) {
5356 writew(1, (bd->re_map_membase + ENABLE_INTR));
5358 * Tell the board to poll the UARTS as fast as possible.
5360 writew(FEPPOLL_MIN, (bd->re_map_membase + FEPPOLL));
5361 bd->intr_running = 1;
5364 /* Wake up anyone waiting for board state to change to ready */
5365 wake_up_interruptible(&bd->state_wait);
5368 DGAP_UNLOCK(bd->bd_lock, lock_flags);
5372 /*=======================================================================
5374 * dgap_cmdb - Sends a 2 byte command to the FEP.
5376 * ch - Pointer to channel structure.
5377 * cmd - Command to be sent.
5378 * byte1 - Integer containing first byte to be sent.
5379 * byte2 - Integer containing second byte to be sent.
5380 * ncmds - Wait until ncmds or fewer cmds are left
5381 * in the cmd buffer before returning.
5383 *=======================================================================*/
5384 void dgap_cmdb(struct channel_t *ch, uchar cmd, uchar byte1, uchar byte2, uint ncmds)
5387 struct cm_t *cm_addr = NULL;
5393 if (!ch || ch->magic != DGAP_CHANNEL_MAGIC)
5397 * Check if board is still alive.
5399 if (ch->ch_bd->state == BOARD_FAILED) {
5400 DPR_CORE(("%s:%d board is in failed state.\n", __FILE__, __LINE__));
5405 * Make sure the pointers are in range before
5406 * writing to the FEP memory.
5408 vaddr = ch->ch_bd->re_map_membase;
5413 cm_addr = (struct cm_t *) (vaddr + CMDBUF);
5414 head = readw(&(cm_addr->cm_head));
5417 * Forget it if pointers out of range.
5419 if (head >= (CMDMAX - CMDSTART) || (head & 03)) {
5420 DPR_CORE(("%s:%d pointers out of range, failing board!\n", __FILE__, __LINE__));
5421 ch->ch_bd->state = BOARD_FAILED;
5426 * Put the data in the circular command buffer.
5428 writeb(cmd, (char *) (vaddr + head + CMDSTART + 0));
5429 writeb((uchar) ch->ch_portnum, (char *) (vaddr + head + CMDSTART + 1));
5430 writeb(byte1, (char *) (vaddr + head + CMDSTART + 2));
5431 writeb(byte2, (char *) (vaddr + head + CMDSTART + 3));
5433 head = (head + 4) & (CMDMAX - CMDSTART - 4);
5435 writew(head, &(cm_addr->cm_head));
5438 * Wait if necessary before updating the head
5439 * pointer to limit the number of outstanding
5440 * commands to the FEP. If the time spent waiting
5441 * is outlandish, declare the FEP dead.
5443 for (count = dgap_count ;;) {
5445 head = readw(&(cm_addr->cm_head));
5446 tail = readw(&(cm_addr->cm_tail));
5448 n = (head - tail) & (CMDMAX - CMDSTART - 4);
5450 if (n <= ncmds * sizeof(struct cm_t))
5454 DPR_CORE(("%s:%d failing board.\n",__FILE__, __LINE__));
5455 ch->ch_bd->state = BOARD_FAILED;
5463 /*=======================================================================
5465 * dgap_cmdw - Sends a 1 word command to the FEP.
5467 * ch - Pointer to channel structure.
5468 * cmd - Command to be sent.
5469 * word - Integer containing word to be sent.
5470 * ncmds - Wait until ncmds or fewer cmds are left
5471 * in the cmd buffer before returning.
5473 *=======================================================================*/
5474 void dgap_cmdw(struct channel_t *ch, uchar cmd, u16 word, uint ncmds)
5477 struct cm_t *cm_addr = NULL;
5483 if (!ch || ch->magic != DGAP_CHANNEL_MAGIC)
5487 * Check if board is still alive.
5489 if (ch->ch_bd->state == BOARD_FAILED) {
5490 DPR_CORE(("%s:%d board is failed!\n", __FILE__, __LINE__));
5495 * Make sure the pointers are in range before
5496 * writing to the FEP memory.
5498 vaddr = ch->ch_bd->re_map_membase;
5502 cm_addr = (struct cm_t *) (vaddr + CMDBUF);
5503 head = readw(&(cm_addr->cm_head));
5506 * Forget it if pointers out of range.
5508 if (head >= (CMDMAX - CMDSTART) || (head & 03)) {
5509 DPR_CORE(("%s:%d Pointers out of range. Failing board.\n",__FILE__, __LINE__));
5510 ch->ch_bd->state = BOARD_FAILED;
5515 * Put the data in the circular command buffer.
5517 writeb(cmd, (char *) (vaddr + head + CMDSTART + 0));
5518 writeb((uchar) ch->ch_portnum, (char *) (vaddr + head + CMDSTART + 1));
5519 writew((u16) word, (char *) (vaddr + head + CMDSTART + 2));
5521 head = (head + 4) & (CMDMAX - CMDSTART - 4);
5523 writew(head, &(cm_addr->cm_head));
5526 * Wait if necessary before updating the head
5527 * pointer to limit the number of outstanding
5528 * commands to the FEP. If the time spent waiting
5529 * is outlandish, declare the FEP dead.
5531 for (count = dgap_count ;;) {
5533 head = readw(&(cm_addr->cm_head));
5534 tail = readw(&(cm_addr->cm_tail));
5536 n = (head - tail) & (CMDMAX - CMDSTART - 4);
5538 if (n <= ncmds * sizeof(struct cm_t))
5542 DPR_CORE(("%s:%d Failing board.\n",__FILE__, __LINE__));
5543 ch->ch_bd->state = BOARD_FAILED;
5552 /*=======================================================================
5554 * dgap_cmdw_ext - Sends a extended word command to the FEP.
5556 * ch - Pointer to channel structure.
5557 * cmd - Command to be sent.
5558 * word - Integer containing word to be sent.
5559 * ncmds - Wait until ncmds or fewer cmds are left
5560 * in the cmd buffer before returning.
5562 *=======================================================================*/
5563 static void dgap_cmdw_ext(struct channel_t *ch, u16 cmd, u16 word, uint ncmds)
5566 struct cm_t *cm_addr = NULL;
5572 if (!ch || ch->magic != DGAP_CHANNEL_MAGIC)
5576 * Check if board is still alive.
5578 if (ch->ch_bd->state == BOARD_FAILED) {
5579 DPR_CORE(("%s:%d board is failed!\n", __FILE__, __LINE__));
5584 * Make sure the pointers are in range before
5585 * writing to the FEP memory.
5587 vaddr = ch->ch_bd->re_map_membase;
5591 cm_addr = (struct cm_t *) (vaddr + CMDBUF);
5592 head = readw(&(cm_addr->cm_head));
5595 * Forget it if pointers out of range.
5597 if (head >= (CMDMAX - CMDSTART) || (head & 03)) {
5598 DPR_CORE(("%s:%d Pointers out of range. Failing board.\n",__FILE__, __LINE__));
5599 ch->ch_bd->state = BOARD_FAILED;
5604 * Put the data in the circular command buffer.
5607 /* Write an FF to tell the FEP that we want an extended command */
5608 writeb((uchar) 0xff, (char *) (vaddr + head + CMDSTART + 0));
5610 writeb((uchar) ch->ch_portnum, (uchar *) (vaddr + head + CMDSTART + 1));
5611 writew((u16) cmd, (char *) (vaddr + head + CMDSTART + 2));
5614 * If the second part of the command won't fit,
5615 * put it at the beginning of the circular buffer.
5617 if (((head + 4) >= ((CMDMAX - CMDSTART)) || (head & 03))) {
5618 writew((u16) word, (char *) (vaddr + CMDSTART));
5620 writew((u16) word, (char *) (vaddr + head + CMDSTART + 4));
5623 head = (head + 8) & (CMDMAX - CMDSTART - 4);
5625 writew(head, &(cm_addr->cm_head));
5628 * Wait if necessary before updating the head
5629 * pointer to limit the number of outstanding
5630 * commands to the FEP. If the time spent waiting
5631 * is outlandish, declare the FEP dead.
5633 for (count = dgap_count ;;) {
5635 head = readw(&(cm_addr->cm_head));
5636 tail = readw(&(cm_addr->cm_tail));
5638 n = (head - tail) & (CMDMAX - CMDSTART - 4);
5640 if (n <= ncmds * sizeof(struct cm_t))
5644 DPR_CORE(("%s:%d Failing board.\n",__FILE__, __LINE__));
5645 ch->ch_bd->state = BOARD_FAILED;
5653 /*=======================================================================
5655 * dgap_wmove - Write data to FEP buffer.
5657 * ch - Pointer to channel structure.
5658 * buf - Poiter to characters to be moved.
5659 * cnt - Number of characters to move.
5661 *=======================================================================*/
5662 void dgap_wmove(struct channel_t *ch, char *buf, uint cnt)
5669 if (!ch || ch->magic != DGAP_CHANNEL_MAGIC)
5676 head = readw(&(bs->tx_head));
5679 * If pointers are out of range, just return.
5681 if ((cnt > ch->ch_tsize) || (unsigned)(head - ch->ch_tstart) >= ch->ch_tsize) {
5682 DPR_CORE(("%s:%d pointer out of range", __FILE__, __LINE__));
5687 * If the write wraps over the top of the circular buffer,
5688 * move the portion up to the wrap point, and reset the
5689 * pointers to the bottom.
5691 n = ch->ch_tstart + ch->ch_tsize - head;
5695 taddr = ch->ch_taddr + head;
5696 memcpy_toio(taddr, buf, n);
5697 head = ch->ch_tstart;
5702 * Move rest of data.
5704 taddr = ch->ch_taddr + head;
5706 memcpy_toio(taddr, buf, n);
5709 writew(head, &(bs->tx_head));
5713 * Retrives the current custom baud rate from FEP memory,
5714 * and returns it back to the user.
5715 * Returns 0 on error.
5717 uint dgap_get_custom_baud(struct channel_t *ch)
5723 if (!ch || ch->magic != DGAP_CHANNEL_MAGIC) {
5727 if (!ch->ch_bd || ch->ch_bd->magic != DGAP_BOARD_MAGIC) {
5731 if (!(ch->ch_bd->bd_flags & BD_FEP5PLUS))
5734 vaddr = ch->ch_bd->re_map_membase;
5740 * Go get from fep mem, what the fep
5741 * believes the custom baud rate is.
5743 offset = ((((*(unsigned short *)(vaddr + ECS_SEG)) << 4) +
5744 (ch->ch_portnum * 0x28) + LINE_SPEED));
5746 value = readw(vaddr + offset);
5752 * Calls the firmware to reset this channel.
5754 void dgap_firmware_reset_port(struct channel_t *ch)
5756 dgap_cmdb(ch, CHRESET, 0, 0, 0);
5759 * Now that the channel is reset, we need to make sure
5760 * all the current settings get reapplied to the port
5763 * So we will set the driver's cache of firmware
5764 * settings all to 0, and then call param.
5766 ch->ch_fepiflag = 0;
5767 ch->ch_fepcflag = 0;
5768 ch->ch_fepoflag = 0;
5769 ch->ch_fepstartc = 0;
5770 ch->ch_fepstopc = 0;
5771 ch->ch_fepastartc = 0;
5772 ch->ch_fepastopc = 0;
5778 /*=======================================================================
5780 * dgap_param - Set Digi parameters.
5782 * struct tty_struct * - TTY for port.
5784 *=======================================================================*/
5785 int dgap_param(struct tty_struct *tty)
5787 struct ktermios *ts;
5789 struct channel_t *ch;
5798 if (!tty || tty->magic != TTY_MAGIC)
5801 un = (struct un_t *) tty->driver_data;
5802 if (!un || un->magic != DGAP_UNIT_MAGIC)
5806 if (!ch || ch->magic != DGAP_CHANNEL_MAGIC)
5810 if (!bd || bd->magic != DGAP_BOARD_MAGIC)
5817 DPR_PARAM(("param start: tdev: %x cflags: %x oflags: %x iflags: %x\n",
5818 ch->ch_tun.un_dev, ch->ch_c_cflag, ch->ch_c_oflag, ch->ch_c_iflag));
5823 * If baud rate is zero, flush queues, and set mval to drop DTR.
5825 if ((ch->ch_c_cflag & (CBAUD)) == 0) {
5828 head = readw(&(ch->ch_bs->rx_head));
5829 writew(head, &(ch->ch_bs->rx_tail));
5832 head = readw(&(ch->ch_bs->tx_head));
5833 writew(head, &(ch->ch_bs->tx_tail));
5835 ch->ch_flags |= (CH_BAUD0);
5837 /* Drop RTS and DTR */
5838 ch->ch_mval &= ~(D_RTS(ch)|D_DTR(ch));
5839 mval = D_DTR(ch) | D_RTS(ch);
5840 ch->ch_baud_info = 0;
5842 } else if (ch->ch_custom_speed && (bd->bd_flags & BD_FEP5PLUS)) {
5844 * Tell the fep to do the command
5847 DPR_PARAM(("param: Want %d speed\n", ch->ch_custom_speed));
5849 dgap_cmdw_ext(ch, 0xff01, ch->ch_custom_speed, 0);
5852 * Now go get from fep mem, what the fep
5853 * believes the custom baud rate is.
5855 ch->ch_baud_info = ch->ch_custom_speed = dgap_get_custom_baud(ch);
5857 DPR_PARAM(("param: Got %d speed\n", ch->ch_custom_speed));
5859 /* Handle transition from B0 */
5860 if (ch->ch_flags & CH_BAUD0) {
5861 ch->ch_flags &= ~(CH_BAUD0);
5862 ch->ch_mval |= (D_RTS(ch)|D_DTR(ch));
5864 mval = D_DTR(ch) | D_RTS(ch);
5868 * Set baud rate, character size, and parity.
5876 ulong bauds[4][16] = {
5880 600, 1200, 1800, 2400,
5881 4800, 9600, 19200, 38400 },
5882 { /* slowbaud & CBAUDEX */
5883 0, 57600, 115200, 230400,
5884 460800, 150, 200, 921600,
5885 600, 1200, 1800, 2400,
5886 4800, 9600, 19200, 38400 },
5888 0, 57600, 76800, 115200,
5889 14400, 57600, 230400, 76800,
5890 115200, 230400, 28800, 460800,
5891 921600, 9600, 19200, 38400 },
5892 { /* fastbaud & CBAUDEX */
5893 0, 57600, 115200, 230400,
5894 460800, 150, 200, 921600,
5895 600, 1200, 1800, 2400,
5896 4800, 9600, 19200, 38400 }
5899 /* Only use the TXPrint baud rate if the terminal unit is NOT open */
5900 if (!(ch->ch_tun.un_flags & UN_ISOPEN) && (un->un_type == DGAP_PRINT))
5901 baud = C_BAUD(ch->ch_pun.un_tty) & 0xff;
5903 baud = C_BAUD(ch->ch_tun.un_tty) & 0xff;
5905 if (ch->ch_c_cflag & CBAUDEX)
5908 if (ch->ch_digi.digi_flags & DIGI_FAST)
5913 if ((iindex >= 0) && (iindex < 4) && (jindex >= 0) && (jindex < 16)) {
5914 baud = bauds[iindex][jindex];
5916 DPR_IOCTL(("baud indices were out of range (%d)(%d)",
5924 ch->ch_baud_info = baud;
5928 * CBAUD has bit position 0x1000 set these days to indicate Linux
5930 * We use a different bit assignment for high speed. Clear this
5931 * bit out while grabbing the parts of "cflag" we want.
5933 cflag = ch->ch_c_cflag & ((CBAUD ^ CBAUDEX) | PARODD | PARENB | CSTOPB | CSIZE);
5936 * HUPCL bit is used by FEP to indicate fast baud
5937 * table is to be used.
5939 if ((ch->ch_digi.digi_flags & DIGI_FAST) || (ch->ch_c_cflag & CBAUDEX))
5943 if ((ch->ch_c_cflag & CBAUDEX) && !(ch->ch_digi.digi_flags & DIGI_FAST)) {
5945 * The below code is trying to guarantee that only baud rates
5946 * 115200, 230400, 460800, 921600 are remapped. We use exclusive or
5947 * because the various baud rates share common bit positions
5948 * and therefore can't be tested for easily.
5950 tcflag_t tcflag = (ch->ch_c_cflag & CBAUD) | CBAUDEX;
5953 /* Map high speed requests to index into FEP's baud table */
5982 cflag = (cflag & ~(CBAUD | CBAUDEX)) | baudpart;
5987 if (cflag != ch->ch_fepcflag) {
5988 ch->ch_fepcflag = (u16) (cflag & 0xffff);
5990 /* Okay to have channel and board locks held calling this */
5991 dgap_cmdw(ch, SCFLAG, (u16) cflag, 0);
5994 /* Handle transition from B0 */
5995 if (ch->ch_flags & CH_BAUD0) {
5996 ch->ch_flags &= ~(CH_BAUD0);
5997 ch->ch_mval |= (D_RTS(ch)|D_DTR(ch));
5999 mval = D_DTR(ch) | D_RTS(ch);
6005 iflag = ch->ch_c_iflag & (IGNBRK | BRKINT | IGNPAR | PARMRK | INPCK | ISTRIP | IXON | IXANY | IXOFF);
6007 if ((ch->ch_startc == _POSIX_VDISABLE) || (ch->ch_stopc == _POSIX_VDISABLE)) {
6008 iflag &= ~(IXON | IXOFF);
6009 ch->ch_c_iflag &= ~(IXON | IXOFF);
6013 * Only the IBM Xr card can switch between
6014 * 232 and 422 modes on the fly
6016 if (bd->device == PCI_DEVICE_XR_IBM_DID) {
6017 if (ch->ch_digi.digi_flags & DIGI_422)
6018 dgap_cmdb(ch, SCOMMODE, MODE_422, 0, 0);
6020 dgap_cmdb(ch, SCOMMODE, MODE_232, 0, 0);
6023 if (ch->ch_digi.digi_flags & DIGI_ALTPIN)
6026 if (iflag != ch->ch_fepiflag) {
6027 ch->ch_fepiflag = iflag;
6029 /* Okay to have channel and board locks held calling this */
6030 dgap_cmdw(ch, SIFLAG, (u16) ch->ch_fepiflag, 0);
6034 * Select hardware handshaking.
6038 if (ch->ch_c_cflag & CRTSCTS) {
6039 hflow |= (D_RTS(ch) | D_CTS(ch));
6041 if (ch->ch_digi.digi_flags & RTSPACE)
6043 if (ch->ch_digi.digi_flags & DTRPACE)
6045 if (ch->ch_digi.digi_flags & CTSPACE)
6047 if (ch->ch_digi.digi_flags & DSRPACE)
6049 if (ch->ch_digi.digi_flags & DCDPACE)
6052 if (hflow != ch->ch_hflow) {
6053 ch->ch_hflow = hflow;
6055 /* Okay to have channel and board locks held calling this */
6056 dgap_cmdb(ch, SHFLOW, (uchar) hflow, 0xff, 0);
6061 * Set RTS and/or DTR Toggle if needed, but only if product is FEP5+ based.
6063 if (bd->bd_flags & BD_FEP5PLUS) {
6065 if (ch->ch_digi.digi_flags & DIGI_RTS_TOGGLE) {
6066 hflow2 |= (D_RTS(ch));
6068 if (ch->ch_digi.digi_flags & DIGI_DTR_TOGGLE) {
6069 hflow2 |= (D_DTR(ch));
6072 dgap_cmdw_ext(ch, 0xff03, hflow2, 0);
6076 * Set modem control lines.
6079 mval ^= ch->ch_mforce & (mval ^ ch->ch_mval);
6081 DPR_PARAM(("dgap_param: mval: %x ch_mforce: %x ch_mval: %x ch_mostat: %x\n",
6082 mval, ch->ch_mforce, ch->ch_mval, ch->ch_mostat));
6084 if (ch->ch_mostat ^ mval) {
6085 ch->ch_mostat = mval;
6087 /* Okay to have channel and board locks held calling this */
6088 DPR_PARAM(("dgap_param: Sending SMODEM mval: %x\n", mval));
6089 dgap_cmdb(ch, SMODEM, (uchar) mval, D_RTS(ch)|D_DTR(ch), 0);
6093 * Read modem signals, and then call carrier function.
6095 ch->ch_mistat = readb(&(bs->m_stat));
6099 * Set the start and stop characters.
6101 if (ch->ch_startc != ch->ch_fepstartc || ch->ch_stopc != ch->ch_fepstopc) {
6102 ch->ch_fepstartc = ch->ch_startc;
6103 ch->ch_fepstopc = ch->ch_stopc;
6105 /* Okay to have channel and board locks held calling this */
6106 dgap_cmdb(ch, SFLOWC, ch->ch_fepstartc, ch->ch_fepstopc, 0);
6110 * Set the Auxiliary start and stop characters.
6112 if (ch->ch_astartc != ch->ch_fepastartc || ch->ch_astopc != ch->ch_fepastopc) {
6113 ch->ch_fepastartc = ch->ch_astartc;
6114 ch->ch_fepastopc = ch->ch_astopc;
6116 /* Okay to have channel and board locks held calling this */
6117 dgap_cmdb(ch, SAFLOWC, ch->ch_fepastartc, ch->ch_fepastopc, 0);
6120 DPR_PARAM(("param finish\n"));
6127 * dgap_parity_scan()
6129 * Convert the FEP5 way of reporting parity errors and breaks into
6130 * the Linux line discipline way.
6132 void dgap_parity_scan(struct channel_t *ch, unsigned char *cbuf, unsigned char *fbuf, int *len)
6136 unsigned char *in, *cout, *fout;
6143 DPR_PSCAN(("dgap_parity_scan start\n"));
6145 if (!ch || ch->magic != DGAP_CHANNEL_MAGIC)
6150 switch (ch->pscan_state) {
6152 /* reset to sanity and fall through */
6153 ch->pscan_state = 0;
6156 /* No FF seen yet */
6157 if (c == (unsigned char) '\377') {
6158 /* delete this character from stream */
6159 ch->pscan_state = 1;
6162 *fout++ = TTY_NORMAL;
6169 if (c == (unsigned char) '\377') {
6170 /* doubled ff, transform to single ff */
6172 *fout++ = TTY_NORMAL;
6174 ch->pscan_state = 0;
6176 /* save value examination in next state */
6177 ch->pscan_savechar = c;
6178 ch->pscan_state = 2;
6183 /* third character of ff sequence */
6187 if (ch->pscan_savechar == 0x0) {
6190 DPR_PSCAN(("dgap_parity_scan in 3rd char of ff seq. c: %x setting break.\n", c));
6192 *fout++ = TTY_BREAK;
6195 DPR_PSCAN(("dgap_parity_scan in 3rd char of ff seq. c: %x setting parity.\n", c));
6196 ch->ch_err_parity++;
6197 *fout++ = TTY_PARITY;
6201 DPR_PSCAN(("%s:%d Logic Error.\n", __FILE__, __LINE__));
6205 ch->pscan_state = 0;
6209 DPR_PSCAN(("dgap_parity_scan finish\n"));
6215 /*=======================================================================
6217 * dgap_event - FEP to host event processing routine.
6219 * bd - Board of current event.
6221 *=======================================================================*/
6222 static int dgap_event(struct board_t *bd)
6224 struct channel_t *ch;
6229 uchar *vaddr = NULL;
6230 struct ev_t *eaddr = NULL;
6238 if (!bd || bd->magic != DGAP_BOARD_MAGIC)
6241 DGAP_LOCK(bd->bd_lock, lock_flags);
6243 vaddr = bd->re_map_membase;
6246 DGAP_UNLOCK(bd->bd_lock, lock_flags);
6250 eaddr = (struct ev_t *) (vaddr + EVBUF);
6252 /* Get our head and tail */
6253 head = readw(&(eaddr->ev_head));
6254 tail = readw(&(eaddr->ev_tail));
6257 * Forget it if pointers out of range.
6260 if (head >= EVMAX - EVSTART || tail >= EVMAX - EVSTART ||
6261 (head | tail) & 03) {
6262 DPR_EVENT(("should be calling xxfail %d\n", __LINE__));
6263 /* Let go of board lock */
6264 DGAP_UNLOCK(bd->bd_lock, lock_flags);
6269 * Loop to process all the events in the buffer.
6271 while (tail != head) {
6274 * Get interrupt information.
6277 event = bd->re_map_membase + tail + EVSTART;
6284 DPR_EVENT(("event: jiffies: %ld port: %d reason: %x modem: %x\n",
6285 jiffies, port, reason, modem));
6288 * Make sure the interrupt is valid.
6290 if (port >= bd->nasync)
6293 if (!(reason & (IFMODEM | IFBREAK | IFTLW | IFTEM | IFDATA))) {
6297 ch = bd->channels[port];
6299 if (!ch || ch->magic != DGAP_CHANNEL_MAGIC) {
6304 * If we have made it here, the event was valid.
6305 * Lock down the channel.
6307 DGAP_LOCK(ch->ch_lock, lock_flags2);
6312 DGAP_UNLOCK(ch->ch_lock, lock_flags2);
6317 * Process received data.
6319 if (reason & IFDATA) {
6322 * ALL LOCKS *MUST* BE DROPPED BEFORE CALLING INPUT!
6323 * input could send some data to ld, which in turn
6324 * could do a callback to one of our other functions.
6326 DGAP_UNLOCK(ch->ch_lock, lock_flags2);
6327 DGAP_UNLOCK(bd->bd_lock, lock_flags);
6331 DGAP_LOCK(bd->bd_lock, lock_flags);
6332 DGAP_LOCK(ch->ch_lock, lock_flags2);
6334 if (ch->ch_flags & CH_RACTIVE)
6335 ch->ch_flags |= CH_RENABLE;
6337 writeb(1, &(bs->idata));
6339 if (ch->ch_flags & CH_RWAIT) {
6340 ch->ch_flags &= ~CH_RWAIT;
6342 wake_up_interruptible(&ch->ch_tun.un_flags_wait);
6347 * Process Modem change signals.
6349 if (reason & IFMODEM) {
6350 ch->ch_mistat = modem;
6357 if (reason & IFBREAK) {
6359 DPR_EVENT(("got IFBREAK\n"));
6361 if (ch->ch_tun.un_tty) {
6362 /* A break has been indicated */
6364 tty_buffer_request_room(ch->ch_tun.un_tty->port, 1);
6365 tty_insert_flip_char(ch->ch_tun.un_tty->port, 0, TTY_BREAK);
6366 tty_flip_buffer_push(ch->ch_tun.un_tty->port);
6371 * Process Transmit low.
6373 if (reason & IFTLW) {
6375 DPR_EVENT(("event: got low event\n"));
6377 if (ch->ch_tun.un_flags & UN_LOW) {
6378 ch->ch_tun.un_flags &= ~UN_LOW;
6380 if (ch->ch_tun.un_flags & UN_ISOPEN) {
6381 if ((ch->ch_tun.un_tty->flags &
6382 (1 << TTY_DO_WRITE_WAKEUP)) &&
6383 ch->ch_tun.un_tty->ldisc->ops->write_wakeup)
6385 DGAP_UNLOCK(ch->ch_lock, lock_flags2);
6386 DGAP_UNLOCK(bd->bd_lock, lock_flags);
6387 (ch->ch_tun.un_tty->ldisc->ops->write_wakeup)(ch->ch_tun.un_tty);
6388 DGAP_LOCK(bd->bd_lock, lock_flags);
6389 DGAP_LOCK(ch->ch_lock, lock_flags2);
6391 wake_up_interruptible(&ch->ch_tun.un_tty->write_wait);
6392 wake_up_interruptible(&ch->ch_tun.un_flags_wait);
6394 DPR_EVENT(("event: Got low event. jiffies: %lu\n", jiffies));
6398 if (ch->ch_pun.un_flags & UN_LOW) {
6399 ch->ch_pun.un_flags &= ~UN_LOW;
6400 if (ch->ch_pun.un_flags & UN_ISOPEN) {
6401 if ((ch->ch_pun.un_tty->flags &
6402 (1 << TTY_DO_WRITE_WAKEUP)) &&
6403 ch->ch_pun.un_tty->ldisc->ops->write_wakeup)
6405 DGAP_UNLOCK(ch->ch_lock, lock_flags2);
6406 DGAP_UNLOCK(bd->bd_lock, lock_flags);
6407 (ch->ch_pun.un_tty->ldisc->ops->write_wakeup)(ch->ch_pun.un_tty);
6408 DGAP_LOCK(bd->bd_lock, lock_flags);
6409 DGAP_LOCK(ch->ch_lock, lock_flags2);
6411 wake_up_interruptible(&ch->ch_pun.un_tty->write_wait);
6412 wake_up_interruptible(&ch->ch_pun.un_flags_wait);
6416 if (ch->ch_flags & CH_WLOW) {
6417 ch->ch_flags &= ~CH_WLOW;
6418 wake_up_interruptible(&ch->ch_flags_wait);
6423 * Process Transmit empty.
6425 if (reason & IFTEM) {
6426 DPR_EVENT(("event: got empty event\n"));
6428 if (ch->ch_tun.un_flags & UN_EMPTY) {
6429 ch->ch_tun.un_flags &= ~UN_EMPTY;
6430 if (ch->ch_tun.un_flags & UN_ISOPEN) {
6431 if ((ch->ch_tun.un_tty->flags &
6432 (1 << TTY_DO_WRITE_WAKEUP)) &&
6433 ch->ch_tun.un_tty->ldisc->ops->write_wakeup)
6435 DGAP_UNLOCK(ch->ch_lock, lock_flags2);
6436 DGAP_UNLOCK(bd->bd_lock, lock_flags);
6438 (ch->ch_tun.un_tty->ldisc->ops->write_wakeup)(ch->ch_tun.un_tty);
6439 DGAP_LOCK(bd->bd_lock, lock_flags);
6440 DGAP_LOCK(ch->ch_lock, lock_flags2);
6442 wake_up_interruptible(&ch->ch_tun.un_tty->write_wait);
6443 wake_up_interruptible(&ch->ch_tun.un_flags_wait);
6447 if (ch->ch_pun.un_flags & UN_EMPTY) {
6448 ch->ch_pun.un_flags &= ~UN_EMPTY;
6449 if (ch->ch_pun.un_flags & UN_ISOPEN) {
6450 if ((ch->ch_pun.un_tty->flags &
6451 (1 << TTY_DO_WRITE_WAKEUP)) &&
6452 ch->ch_pun.un_tty->ldisc->ops->write_wakeup)
6454 DGAP_UNLOCK(ch->ch_lock, lock_flags2);
6455 DGAP_UNLOCK(bd->bd_lock, lock_flags);
6456 (ch->ch_pun.un_tty->ldisc->ops->write_wakeup)(ch->ch_pun.un_tty);
6457 DGAP_LOCK(bd->bd_lock, lock_flags);
6458 DGAP_LOCK(ch->ch_lock, lock_flags2);
6460 wake_up_interruptible(&ch->ch_pun.un_tty->write_wait);
6461 wake_up_interruptible(&ch->ch_pun.un_flags_wait);
6466 if (ch->ch_flags & CH_WEMPTY) {
6467 ch->ch_flags &= ~CH_WEMPTY;
6468 wake_up_interruptible(&ch->ch_flags_wait);
6472 DGAP_UNLOCK(ch->ch_lock, lock_flags2);
6475 tail = (tail + 4) & (EVMAX - EVSTART - 4);
6478 writew(tail, &(eaddr->ev_tail));
6479 DGAP_UNLOCK(bd->bd_lock, lock_flags);
6484 static ssize_t dgap_driver_version_show(struct device_driver *ddp, char *buf)
6486 return snprintf(buf, PAGE_SIZE, "%s\n", DG_PART);
6488 static DRIVER_ATTR(version, S_IRUSR, dgap_driver_version_show, NULL);
6491 static ssize_t dgap_driver_boards_show(struct device_driver *ddp, char *buf)
6493 return snprintf(buf, PAGE_SIZE, "%d\n", dgap_NumBoards);
6495 static DRIVER_ATTR(boards, S_IRUSR, dgap_driver_boards_show, NULL);
6498 static ssize_t dgap_driver_maxboards_show(struct device_driver *ddp, char *buf)
6500 return snprintf(buf, PAGE_SIZE, "%d\n", MAXBOARDS);
6502 static DRIVER_ATTR(maxboards, S_IRUSR, dgap_driver_maxboards_show, NULL);
6505 static ssize_t dgap_driver_pollcounter_show(struct device_driver *ddp, char *buf)
6507 return snprintf(buf, PAGE_SIZE, "%ld\n", dgap_poll_counter);
6509 static DRIVER_ATTR(pollcounter, S_IRUSR, dgap_driver_pollcounter_show, NULL);
6512 static ssize_t dgap_driver_state_show(struct device_driver *ddp, char *buf)
6514 return snprintf(buf, PAGE_SIZE, "%s\n", dgap_driver_state_text[dgap_driver_state]);
6516 static DRIVER_ATTR(state, S_IRUSR, dgap_driver_state_show, NULL);
6519 static ssize_t dgap_driver_debug_show(struct device_driver *ddp, char *buf)
6521 return snprintf(buf, PAGE_SIZE, "0x%x\n", dgap_debug);
6524 static ssize_t dgap_driver_debug_store(struct device_driver *ddp, const char *buf, size_t count)
6526 sscanf(buf, "0x%x\n", &dgap_debug);
6529 static DRIVER_ATTR(debug, (S_IRUSR | S_IWUSR), dgap_driver_debug_show, dgap_driver_debug_store);
6532 static ssize_t dgap_driver_rawreadok_show(struct device_driver *ddp, char *buf)
6534 return snprintf(buf, PAGE_SIZE, "0x%x\n", dgap_rawreadok);
6537 static ssize_t dgap_driver_rawreadok_store(struct device_driver *ddp, const char *buf, size_t count)
6539 sscanf(buf, "0x%x\n", &dgap_rawreadok);
6542 static DRIVER_ATTR(rawreadok, (S_IRUSR | S_IWUSR), dgap_driver_rawreadok_show, dgap_driver_rawreadok_store);
6545 static ssize_t dgap_driver_pollrate_show(struct device_driver *ddp, char *buf)
6547 return snprintf(buf, PAGE_SIZE, "%dms\n", dgap_poll_tick);
6550 static ssize_t dgap_driver_pollrate_store(struct device_driver *ddp, const char *buf, size_t count)
6552 sscanf(buf, "%d\n", &dgap_poll_tick);
6555 static DRIVER_ATTR(pollrate, (S_IRUSR | S_IWUSR), dgap_driver_pollrate_show, dgap_driver_pollrate_store);
6558 void dgap_create_driver_sysfiles(struct pci_driver *dgap_driver)
6561 struct device_driver *driverfs = &dgap_driver->driver;
6563 rc |= driver_create_file(driverfs, &driver_attr_version);
6564 rc |= driver_create_file(driverfs, &driver_attr_boards);
6565 rc |= driver_create_file(driverfs, &driver_attr_maxboards);
6566 rc |= driver_create_file(driverfs, &driver_attr_debug);
6567 rc |= driver_create_file(driverfs, &driver_attr_rawreadok);
6568 rc |= driver_create_file(driverfs, &driver_attr_pollrate);
6569 rc |= driver_create_file(driverfs, &driver_attr_pollcounter);
6570 rc |= driver_create_file(driverfs, &driver_attr_state);
6572 printk(KERN_ERR "DGAP: sysfs driver_create_file failed!\n");
6577 void dgap_remove_driver_sysfiles(struct pci_driver *dgap_driver)
6579 struct device_driver *driverfs = &dgap_driver->driver;
6580 driver_remove_file(driverfs, &driver_attr_version);
6581 driver_remove_file(driverfs, &driver_attr_boards);
6582 driver_remove_file(driverfs, &driver_attr_maxboards);
6583 driver_remove_file(driverfs, &driver_attr_debug);
6584 driver_remove_file(driverfs, &driver_attr_rawreadok);
6585 driver_remove_file(driverfs, &driver_attr_pollrate);
6586 driver_remove_file(driverfs, &driver_attr_pollcounter);
6587 driver_remove_file(driverfs, &driver_attr_state);
6591 #define DGAP_VERIFY_BOARD(p, bd) \
6595 bd = dev_get_drvdata(p); \
6596 if (!bd || bd->magic != DGAP_BOARD_MAGIC) \
6598 if (bd->state != BOARD_READY) \
6602 static ssize_t dgap_ports_state_show(struct device *p, struct device_attribute *attr, char *buf)
6608 DGAP_VERIFY_BOARD(p, bd);
6610 for (i = 0; i < bd->nasync; i++) {
6611 count += snprintf(buf + count, PAGE_SIZE - count,
6612 "%d %s\n", bd->channels[i]->ch_portnum,
6613 bd->channels[i]->ch_open_count ? "Open" : "Closed");
6617 static DEVICE_ATTR(ports_state, S_IRUSR, dgap_ports_state_show, NULL);
6620 static ssize_t dgap_ports_baud_show(struct device *p, struct device_attribute *attr, char *buf)
6626 DGAP_VERIFY_BOARD(p, bd);
6628 for (i = 0; i < bd->nasync; i++) {
6629 count += snprintf(buf + count, PAGE_SIZE - count,
6630 "%d %d\n", bd->channels[i]->ch_portnum, bd->channels[i]->ch_baud_info);
6634 static DEVICE_ATTR(ports_baud, S_IRUSR, dgap_ports_baud_show, NULL);
6637 static ssize_t dgap_ports_msignals_show(struct device *p, struct device_attribute *attr, char *buf)
6643 DGAP_VERIFY_BOARD(p, bd);
6645 for (i = 0; i < bd->nasync; i++) {
6646 if (bd->channels[i]->ch_open_count) {
6647 count += snprintf(buf + count, PAGE_SIZE - count,
6648 "%d %s %s %s %s %s %s\n", bd->channels[i]->ch_portnum,
6649 (bd->channels[i]->ch_mostat & UART_MCR_RTS) ? "RTS" : "",
6650 (bd->channels[i]->ch_mistat & UART_MSR_CTS) ? "CTS" : "",
6651 (bd->channels[i]->ch_mostat & UART_MCR_DTR) ? "DTR" : "",
6652 (bd->channels[i]->ch_mistat & UART_MSR_DSR) ? "DSR" : "",
6653 (bd->channels[i]->ch_mistat & UART_MSR_DCD) ? "DCD" : "",
6654 (bd->channels[i]->ch_mistat & UART_MSR_RI) ? "RI" : "");
6656 count += snprintf(buf + count, PAGE_SIZE - count,
6657 "%d\n", bd->channels[i]->ch_portnum);
6662 static DEVICE_ATTR(ports_msignals, S_IRUSR, dgap_ports_msignals_show, NULL);
6665 static ssize_t dgap_ports_iflag_show(struct device *p, struct device_attribute *attr, char *buf)
6671 DGAP_VERIFY_BOARD(p, bd);
6673 for (i = 0; i < bd->nasync; i++) {
6674 count += snprintf(buf + count, PAGE_SIZE - count, "%d %x\n",
6675 bd->channels[i]->ch_portnum, bd->channels[i]->ch_c_iflag);
6679 static DEVICE_ATTR(ports_iflag, S_IRUSR, dgap_ports_iflag_show, NULL);
6682 static ssize_t dgap_ports_cflag_show(struct device *p, struct device_attribute *attr, char *buf)
6688 DGAP_VERIFY_BOARD(p, bd);
6690 for (i = 0; i < bd->nasync; i++) {
6691 count += snprintf(buf + count, PAGE_SIZE - count, "%d %x\n",
6692 bd->channels[i]->ch_portnum, bd->channels[i]->ch_c_cflag);
6696 static DEVICE_ATTR(ports_cflag, S_IRUSR, dgap_ports_cflag_show, NULL);
6699 static ssize_t dgap_ports_oflag_show(struct device *p, struct device_attribute *attr, char *buf)
6705 DGAP_VERIFY_BOARD(p, bd);
6707 for (i = 0; i < bd->nasync; i++) {
6708 count += snprintf(buf + count, PAGE_SIZE - count, "%d %x\n",
6709 bd->channels[i]->ch_portnum, bd->channels[i]->ch_c_oflag);
6713 static DEVICE_ATTR(ports_oflag, S_IRUSR, dgap_ports_oflag_show, NULL);
6716 static ssize_t dgap_ports_lflag_show(struct device *p, struct device_attribute *attr, char *buf)
6722 DGAP_VERIFY_BOARD(p, bd);
6724 for (i = 0; i < bd->nasync; i++) {
6725 count += snprintf(buf + count, PAGE_SIZE - count, "%d %x\n",
6726 bd->channels[i]->ch_portnum, bd->channels[i]->ch_c_lflag);
6730 static DEVICE_ATTR(ports_lflag, S_IRUSR, dgap_ports_lflag_show, NULL);
6733 static ssize_t dgap_ports_digi_flag_show(struct device *p, struct device_attribute *attr, char *buf)
6739 DGAP_VERIFY_BOARD(p, bd);
6741 for (i = 0; i < bd->nasync; i++) {
6742 count += snprintf(buf + count, PAGE_SIZE - count, "%d %x\n",
6743 bd->channels[i]->ch_portnum, bd->channels[i]->ch_digi.digi_flags);
6747 static DEVICE_ATTR(ports_digi_flag, S_IRUSR, dgap_ports_digi_flag_show, NULL);
6750 static ssize_t dgap_ports_rxcount_show(struct device *p, struct device_attribute *attr, char *buf)
6756 DGAP_VERIFY_BOARD(p, bd);
6758 for (i = 0; i < bd->nasync; i++) {
6759 count += snprintf(buf + count, PAGE_SIZE - count, "%d %ld\n",
6760 bd->channels[i]->ch_portnum, bd->channels[i]->ch_rxcount);
6764 static DEVICE_ATTR(ports_rxcount, S_IRUSR, dgap_ports_rxcount_show, NULL);
6767 static ssize_t dgap_ports_txcount_show(struct device *p, struct device_attribute *attr, char *buf)
6773 DGAP_VERIFY_BOARD(p, bd);
6775 for (i = 0; i < bd->nasync; i++) {
6776 count += snprintf(buf + count, PAGE_SIZE - count, "%d %ld\n",
6777 bd->channels[i]->ch_portnum, bd->channels[i]->ch_txcount);
6781 static DEVICE_ATTR(ports_txcount, S_IRUSR, dgap_ports_txcount_show, NULL);
6784 /* this function creates the sys files that will export each signal status
6785 * to sysfs each value will be put in a separate filename
6787 void dgap_create_ports_sysfiles(struct board_t *bd)
6791 dev_set_drvdata(&bd->pdev->dev, bd);
6792 rc |= device_create_file(&(bd->pdev->dev), &dev_attr_ports_state);
6793 rc |= device_create_file(&(bd->pdev->dev), &dev_attr_ports_baud);
6794 rc |= device_create_file(&(bd->pdev->dev), &dev_attr_ports_msignals);
6795 rc |= device_create_file(&(bd->pdev->dev), &dev_attr_ports_iflag);
6796 rc |= device_create_file(&(bd->pdev->dev), &dev_attr_ports_cflag);
6797 rc |= device_create_file(&(bd->pdev->dev), &dev_attr_ports_oflag);
6798 rc |= device_create_file(&(bd->pdev->dev), &dev_attr_ports_lflag);
6799 rc |= device_create_file(&(bd->pdev->dev), &dev_attr_ports_digi_flag);
6800 rc |= device_create_file(&(bd->pdev->dev), &dev_attr_ports_rxcount);
6801 rc |= device_create_file(&(bd->pdev->dev), &dev_attr_ports_txcount);
6803 printk(KERN_ERR "DGAP: sysfs device_create_file failed!\n");
6808 /* removes all the sys files created for that port */
6809 void dgap_remove_ports_sysfiles(struct board_t *bd)
6811 device_remove_file(&(bd->pdev->dev), &dev_attr_ports_state);
6812 device_remove_file(&(bd->pdev->dev), &dev_attr_ports_baud);
6813 device_remove_file(&(bd->pdev->dev), &dev_attr_ports_msignals);
6814 device_remove_file(&(bd->pdev->dev), &dev_attr_ports_iflag);
6815 device_remove_file(&(bd->pdev->dev), &dev_attr_ports_cflag);
6816 device_remove_file(&(bd->pdev->dev), &dev_attr_ports_oflag);
6817 device_remove_file(&(bd->pdev->dev), &dev_attr_ports_lflag);
6818 device_remove_file(&(bd->pdev->dev), &dev_attr_ports_digi_flag);
6819 device_remove_file(&(bd->pdev->dev), &dev_attr_ports_rxcount);
6820 device_remove_file(&(bd->pdev->dev), &dev_attr_ports_txcount);
6824 static ssize_t dgap_tty_state_show(struct device *d, struct device_attribute *attr, char *buf)
6827 struct channel_t *ch;
6832 un = dev_get_drvdata(d);
6833 if (!un || un->magic != DGAP_UNIT_MAGIC)
6836 if (!ch || ch->magic != DGAP_CHANNEL_MAGIC)
6839 if (!bd || bd->magic != DGAP_BOARD_MAGIC)
6841 if (bd->state != BOARD_READY)
6844 return snprintf(buf, PAGE_SIZE, "%s", un->un_open_count ? "Open" : "Closed");
6846 static DEVICE_ATTR(state, S_IRUSR, dgap_tty_state_show, NULL);
6849 static ssize_t dgap_tty_baud_show(struct device *d, struct device_attribute *attr, char *buf)
6852 struct channel_t *ch;
6857 un = dev_get_drvdata(d);
6858 if (!un || un->magic != DGAP_UNIT_MAGIC)
6861 if (!ch || ch->magic != DGAP_CHANNEL_MAGIC)
6864 if (!bd || bd->magic != DGAP_BOARD_MAGIC)
6866 if (bd->state != BOARD_READY)
6869 return snprintf(buf, PAGE_SIZE, "%d\n", ch->ch_baud_info);
6871 static DEVICE_ATTR(baud, S_IRUSR, dgap_tty_baud_show, NULL);
6874 static ssize_t dgap_tty_msignals_show(struct device *d, struct device_attribute *attr, char *buf)
6877 struct channel_t *ch;
6882 un = dev_get_drvdata(d);
6883 if (!un || un->magic != DGAP_UNIT_MAGIC)
6886 if (!ch || ch->magic != DGAP_CHANNEL_MAGIC)
6889 if (!bd || bd->magic != DGAP_BOARD_MAGIC)
6891 if (bd->state != BOARD_READY)
6894 if (ch->ch_open_count) {
6895 return snprintf(buf, PAGE_SIZE, "%s %s %s %s %s %s\n",
6896 (ch->ch_mostat & UART_MCR_RTS) ? "RTS" : "",
6897 (ch->ch_mistat & UART_MSR_CTS) ? "CTS" : "",
6898 (ch->ch_mostat & UART_MCR_DTR) ? "DTR" : "",
6899 (ch->ch_mistat & UART_MSR_DSR) ? "DSR" : "",
6900 (ch->ch_mistat & UART_MSR_DCD) ? "DCD" : "",
6901 (ch->ch_mistat & UART_MSR_RI) ? "RI" : "");
6905 static DEVICE_ATTR(msignals, S_IRUSR, dgap_tty_msignals_show, NULL);
6908 static ssize_t dgap_tty_iflag_show(struct device *d, struct device_attribute *attr, char *buf)
6911 struct channel_t *ch;
6916 un = dev_get_drvdata(d);
6917 if (!un || un->magic != DGAP_UNIT_MAGIC)
6920 if (!ch || ch->magic != DGAP_CHANNEL_MAGIC)
6923 if (!bd || bd->magic != DGAP_BOARD_MAGIC)
6925 if (bd->state != BOARD_READY)
6928 return snprintf(buf, PAGE_SIZE, "%x\n", ch->ch_c_iflag);
6930 static DEVICE_ATTR(iflag, S_IRUSR, dgap_tty_iflag_show, NULL);
6933 static ssize_t dgap_tty_cflag_show(struct device *d, struct device_attribute *attr, char *buf)
6936 struct channel_t *ch;
6941 un = dev_get_drvdata(d);
6942 if (!un || un->magic != DGAP_UNIT_MAGIC)
6945 if (!ch || ch->magic != DGAP_CHANNEL_MAGIC)
6948 if (!bd || bd->magic != DGAP_BOARD_MAGIC)
6950 if (bd->state != BOARD_READY)
6953 return snprintf(buf, PAGE_SIZE, "%x\n", ch->ch_c_cflag);
6955 static DEVICE_ATTR(cflag, S_IRUSR, dgap_tty_cflag_show, NULL);
6958 static ssize_t dgap_tty_oflag_show(struct device *d, struct device_attribute *attr, char *buf)
6961 struct channel_t *ch;
6966 un = dev_get_drvdata(d);
6967 if (!un || un->magic != DGAP_UNIT_MAGIC)
6970 if (!ch || ch->magic != DGAP_CHANNEL_MAGIC)
6973 if (!bd || bd->magic != DGAP_BOARD_MAGIC)
6975 if (bd->state != BOARD_READY)
6978 return snprintf(buf, PAGE_SIZE, "%x\n", ch->ch_c_oflag);
6980 static DEVICE_ATTR(oflag, S_IRUSR, dgap_tty_oflag_show, NULL);
6983 static ssize_t dgap_tty_lflag_show(struct device *d, struct device_attribute *attr, char *buf)
6986 struct channel_t *ch;
6991 un = dev_get_drvdata(d);
6992 if (!un || un->magic != DGAP_UNIT_MAGIC)
6995 if (!ch || ch->magic != DGAP_CHANNEL_MAGIC)
6998 if (!bd || bd->magic != DGAP_BOARD_MAGIC)
7000 if (bd->state != BOARD_READY)
7003 return snprintf(buf, PAGE_SIZE, "%x\n", ch->ch_c_lflag);
7005 static DEVICE_ATTR(lflag, S_IRUSR, dgap_tty_lflag_show, NULL);
7008 static ssize_t dgap_tty_digi_flag_show(struct device *d, struct device_attribute *attr, char *buf)
7011 struct channel_t *ch;
7016 un = dev_get_drvdata(d);
7017 if (!un || un->magic != DGAP_UNIT_MAGIC)
7020 if (!ch || ch->magic != DGAP_CHANNEL_MAGIC)
7023 if (!bd || bd->magic != DGAP_BOARD_MAGIC)
7025 if (bd->state != BOARD_READY)
7028 return snprintf(buf, PAGE_SIZE, "%x\n", ch->ch_digi.digi_flags);
7030 static DEVICE_ATTR(digi_flag, S_IRUSR, dgap_tty_digi_flag_show, NULL);
7033 static ssize_t dgap_tty_rxcount_show(struct device *d, struct device_attribute *attr, char *buf)
7036 struct channel_t *ch;
7041 un = dev_get_drvdata(d);
7042 if (!un || un->magic != DGAP_UNIT_MAGIC)
7045 if (!ch || ch->magic != DGAP_CHANNEL_MAGIC)
7048 if (!bd || bd->magic != DGAP_BOARD_MAGIC)
7050 if (bd->state != BOARD_READY)
7053 return snprintf(buf, PAGE_SIZE, "%ld\n", ch->ch_rxcount);
7055 static DEVICE_ATTR(rxcount, S_IRUSR, dgap_tty_rxcount_show, NULL);
7058 static ssize_t dgap_tty_txcount_show(struct device *d, struct device_attribute *attr, char *buf)
7061 struct channel_t *ch;
7066 un = dev_get_drvdata(d);
7067 if (!un || un->magic != DGAP_UNIT_MAGIC)
7070 if (!ch || ch->magic != DGAP_CHANNEL_MAGIC)
7073 if (!bd || bd->magic != DGAP_BOARD_MAGIC)
7075 if (bd->state != BOARD_READY)
7078 return snprintf(buf, PAGE_SIZE, "%ld\n", ch->ch_txcount);
7080 static DEVICE_ATTR(txcount, S_IRUSR, dgap_tty_txcount_show, NULL);
7083 static ssize_t dgap_tty_name_show(struct device *d, struct device_attribute *attr, char *buf)
7086 struct channel_t *ch;
7090 struct cnode *cptr = NULL;
7098 un = dev_get_drvdata(d);
7099 if (!un || un->magic != DGAP_UNIT_MAGIC)
7102 if (!ch || ch->magic != DGAP_CHANNEL_MAGIC)
7105 if (!bd || bd->magic != DGAP_BOARD_MAGIC)
7107 if (bd->state != BOARD_READY)
7111 cn = ch->ch_portnum;
7113 for (cptr = bd->bd_config; cptr; cptr = cptr->next) {
7115 if ((cptr->type == BNODE) &&
7116 ((cptr->u.board.type == APORT2_920P) || (cptr->u.board.type == APORT4_920P) ||
7117 (cptr->u.board.type == APORT8_920P) || (cptr->u.board.type == PAPORT4) ||
7118 (cptr->u.board.type == PAPORT8))) {
7121 if (cptr->u.board.v_start)
7122 starto = cptr->u.board.start;
7127 if (cptr->type == TNODE && found == TRUE) {
7129 if (strstr(cptr->u.ttyname, "tty")) {
7130 ptr1 = cptr->u.ttyname;
7134 ptr1 = cptr->u.ttyname;
7137 for (i = 0; i < dgap_config_get_number_of_ports(bd); i++) {
7139 return snprintf(buf, PAGE_SIZE, "%s%s%02d\n",
7140 (un->un_type == DGAP_PRINT) ? "pr" : "tty",
7146 if (cptr->type == CNODE) {
7148 for (i = 0; i < cptr->u.conc.nport; i++) {
7149 if (cn == (i + ncount)) {
7151 return snprintf(buf, PAGE_SIZE, "%s%s%02d\n",
7152 (un->un_type == DGAP_PRINT) ? "pr" : "tty",
7154 i + (cptr->u.conc.v_start ? cptr->u.conc.start : 1));
7158 ncount += cptr->u.conc.nport;
7161 if (cptr->type == MNODE) {
7163 for (i = 0; i < cptr->u.module.nport; i++) {
7164 if (cn == (i + ncount)) {
7165 return snprintf(buf, PAGE_SIZE, "%s%s%02d\n",
7166 (un->un_type == DGAP_PRINT) ? "pr" : "tty",
7168 i + (cptr->u.module.v_start ? cptr->u.module.start : 1));
7172 ncount += cptr->u.module.nport;
7177 return snprintf(buf, PAGE_SIZE, "%s_dgap_%d_%d\n",
7178 (un->un_type == DGAP_PRINT) ? "pr" : "tty", bn, cn);
7181 static DEVICE_ATTR(custom_name, S_IRUSR, dgap_tty_name_show, NULL);
7184 static struct attribute *dgap_sysfs_tty_entries[] = {
7185 &dev_attr_state.attr,
7186 &dev_attr_baud.attr,
7187 &dev_attr_msignals.attr,
7188 &dev_attr_iflag.attr,
7189 &dev_attr_cflag.attr,
7190 &dev_attr_oflag.attr,
7191 &dev_attr_lflag.attr,
7192 &dev_attr_digi_flag.attr,
7193 &dev_attr_rxcount.attr,
7194 &dev_attr_txcount.attr,
7195 &dev_attr_custom_name.attr,
7200 static struct attribute_group dgap_tty_attribute_group = {
7202 .attrs = dgap_sysfs_tty_entries,
7208 void dgap_create_tty_sysfs(struct un_t *un, struct device *c)
7212 ret = sysfs_create_group(&c->kobj, &dgap_tty_attribute_group);
7214 printk(KERN_ERR "dgap: failed to create sysfs tty device attributes.\n");
7215 sysfs_remove_group(&c->kobj, &dgap_tty_attribute_group);
7219 dev_set_drvdata(c, un);
7224 void dgap_remove_tty_sysfs(struct device *c)
7226 sysfs_remove_group(&c->kobj, &dgap_tty_attribute_group);
7230 * Parse a configuration file read into memory as a string.
7232 int dgap_parsefile(char **in, int Remove)
7234 struct cnode *p, *brd, *line, *conc;
7236 char *s = NULL, *s2 = NULL;
7240 brd = line = conc = NULL;
7242 /* perhaps we are adding to an existing list? */
7243 while (p->next != NULL) {
7247 /* file must start with a BEGIN */
7248 while ( (rc = dgap_gettok(in,p)) != BEGIN ) {
7250 dgap_err("unexpected EOF");
7256 rc = dgap_gettok(in,p);
7258 dgap_err("unexpected EOF");
7264 dgap_err("unexpected end of file");
7267 case BEGIN: /* should only be 1 begin */
7268 dgap_err("unexpected config_begin\n");
7274 case BOARD: /* board info */
7275 if (dgap_checknode(p))
7277 if ( (p->next = dgap_newnode(BNODE)) == NULL ) {
7278 dgap_err("out of memory");
7283 p->u.board.status = dgap_savestring("No");
7289 case APORT2_920P: /* AccelePort_4 */
7290 if (p->type != BNODE) {
7291 dgap_err("unexpected Digi_2r_920 string");
7294 p->u.board.type = APORT2_920P;
7295 p->u.board.v_type = 1;
7296 DPR_INIT(("Adding Digi_2r_920 PCI to config...\n"));
7299 case APORT4_920P: /* AccelePort_4 */
7300 if (p->type != BNODE) {
7301 dgap_err("unexpected Digi_4r_920 string");
7304 p->u.board.type = APORT4_920P;
7305 p->u.board.v_type = 1;
7306 DPR_INIT(("Adding Digi_4r_920 PCI to config...\n"));
7309 case APORT8_920P: /* AccelePort_8 */
7310 if (p->type != BNODE) {
7311 dgap_err("unexpected Digi_8r_920 string");
7314 p->u.board.type = APORT8_920P;
7315 p->u.board.v_type = 1;
7316 DPR_INIT(("Adding Digi_8r_920 PCI to config...\n"));
7319 case PAPORT4: /* AccelePort_4 PCI */
7320 if (p->type != BNODE) {
7321 dgap_err("unexpected Digi_4r(PCI) string");
7324 p->u.board.type = PAPORT4;
7325 p->u.board.v_type = 1;
7326 DPR_INIT(("Adding Digi_4r PCI to config...\n"));
7329 case PAPORT8: /* AccelePort_8 PCI */
7330 if (p->type != BNODE) {
7331 dgap_err("unexpected Digi_8r string");
7334 p->u.board.type = PAPORT8;
7335 p->u.board.v_type = 1;
7336 DPR_INIT(("Adding Digi_8r PCI to config...\n"));
7339 case PCX: /* PCI C/X */
7340 if (p->type != BNODE) {
7341 dgap_err("unexpected Digi_C/X_(PCI) string");
7344 p->u.board.type = PCX;
7345 p->u.board.v_type = 1;
7346 p->u.board.conc1 = 0;
7347 p->u.board.conc2 = 0;
7348 p->u.board.module1 = 0;
7349 p->u.board.module2 = 0;
7350 DPR_INIT(("Adding PCI C/X to config...\n"));
7353 case PEPC: /* PCI EPC/X */
7354 if (p->type != BNODE) {
7355 dgap_err("unexpected \"Digi_EPC/X_(PCI)\" string");
7358 p->u.board.type = PEPC;
7359 p->u.board.v_type = 1;
7360 p->u.board.conc1 = 0;
7361 p->u.board.conc2 = 0;
7362 p->u.board.module1 = 0;
7363 p->u.board.module2 = 0;
7364 DPR_INIT(("Adding PCI EPC/X to config...\n"));
7367 case PPCM: /* PCI/Xem */
7368 if (p->type != BNODE) {
7369 dgap_err("unexpected PCI/Xem string");
7372 p->u.board.type = PPCM;
7373 p->u.board.v_type = 1;
7374 p->u.board.conc1 = 0;
7375 p->u.board.conc2 = 0;
7376 DPR_INIT(("Adding PCI XEM to config...\n"));
7379 case IO: /* i/o port */
7380 if (p->type != BNODE) {
7381 dgap_err("IO port only vaild for boards");
7384 s = dgap_getword(in);
7386 dgap_err("unexpected end of file");
7389 p->u.board.portstr = dgap_savestring(s);
7390 p->u.board.port = (short)simple_strtol(s, &s2, 0);
7391 if ((short)strlen(s) > (short)(s2 - s)) {
7392 dgap_err("bad number for IO port");
7395 p->u.board.v_port = 1;
7396 DPR_INIT(("Adding IO (%s) to config...\n", s));
7399 case MEM: /* memory address */
7400 if (p->type != BNODE) {
7401 dgap_err("memory address only vaild for boards");
7404 s = dgap_getword(in);
7406 dgap_err("unexpected end of file");
7409 p->u.board.addrstr = dgap_savestring(s);
7410 p->u.board.addr = simple_strtoul(s, &s2, 0);
7411 if ((int)strlen(s) > (int)(s2 - s)) {
7412 dgap_err("bad number for memory address");
7415 p->u.board.v_addr = 1;
7416 DPR_INIT(("Adding MEM (%s) to config...\n", s));
7419 case PCIINFO: /* pci information */
7420 if (p->type != BNODE) {
7421 dgap_err("memory address only vaild for boards");
7424 s = dgap_getword(in);
7426 dgap_err("unexpected end of file");
7429 p->u.board.pcibusstr = dgap_savestring(s);
7430 p->u.board.pcibus = simple_strtoul(s, &s2, 0);
7431 if ((int)strlen(s) > (int)(s2 - s)) {
7432 dgap_err("bad number for pci bus");
7435 p->u.board.v_pcibus = 1;
7436 s = dgap_getword(in);
7438 dgap_err("unexpected end of file");
7441 p->u.board.pcislotstr = dgap_savestring(s);
7442 p->u.board.pcislot = simple_strtoul(s, &s2, 0);
7443 if ((int)strlen(s) > (int)(s2 - s)) {
7444 dgap_err("bad number for pci slot");
7447 p->u.board.v_pcislot = 1;
7449 DPR_INIT(("Adding PCIINFO (%s %s) to config...\n", p->u.board.pcibusstr,
7450 p->u.board.pcislotstr));
7454 if (p->type != BNODE) {
7455 dgap_err("install method only vaild for boards");
7458 s = dgap_getword(in);
7460 dgap_err("unexpected end of file");
7463 p->u.board.method = dgap_savestring(s);
7464 p->u.board.v_method = 1;
7465 DPR_INIT(("Adding METHOD (%s) to config...\n", s));
7469 if (p->type != BNODE) {
7470 dgap_err("config status only vaild for boards");
7473 s = dgap_getword(in);
7475 dgap_err("unexpected end of file");
7478 p->u.board.status = dgap_savestring(s);
7479 DPR_INIT(("Adding STATUS (%s) to config...\n", s));
7482 case NPORTS: /* number of ports */
7483 if (p->type == BNODE) {
7484 s = dgap_getword(in);
7486 dgap_err("unexpected end of file");
7489 p->u.board.nport = (char)simple_strtol(s, &s2, 0);
7490 if ((int)strlen(s) > (int)(s2 - s)) {
7491 dgap_err("bad number for number of ports");
7494 p->u.board.v_nport = 1;
7495 } else if (p->type == CNODE) {
7496 s = dgap_getword(in);
7498 dgap_err("unexpected end of file");
7501 p->u.conc.nport = (char)simple_strtol(s, &s2, 0);
7502 if ((int)strlen(s) > (int)(s2 - s)) {
7503 dgap_err("bad number for number of ports");
7506 p->u.conc.v_nport = 1;
7507 } else if (p->type == MNODE) {
7508 s = dgap_getword(in);
7510 dgap_err("unexpected end of file");
7513 p->u.module.nport = (char)simple_strtol(s, &s2, 0);
7514 if ((int)strlen(s) > (int)(s2 - s)) {
7515 dgap_err("bad number for number of ports");
7518 p->u.module.v_nport = 1;
7520 dgap_err("nports only valid for concentrators or modules");
7523 DPR_INIT(("Adding NPORTS (%s) to config...\n", s));
7526 case ID: /* letter ID used in tty name */
7527 s = dgap_getword(in);
7529 dgap_err("unexpected end of file");
7533 p->u.board.status = dgap_savestring(s);
7535 if (p->type == CNODE) {
7536 p->u.conc.id = dgap_savestring(s);
7538 } else if (p->type == MNODE) {
7539 p->u.module.id = dgap_savestring(s);
7540 p->u.module.v_id = 1;
7542 dgap_err("id only valid for concentrators or modules");
7545 DPR_INIT(("Adding ID (%s) to config...\n", s));
7548 case STARTO: /* start offset of ID */
7549 if (p->type == BNODE) {
7550 s = dgap_getword(in);
7552 dgap_err("unexpected end of file");
7555 p->u.board.start = simple_strtol(s, &s2, 0);
7556 if ((int)strlen(s) > (int)(s2 - s)) {
7557 dgap_err("bad number for start of tty count");
7560 p->u.board.v_start = 1;
7561 } else if (p->type == CNODE) {
7562 s = dgap_getword(in);
7564 dgap_err("unexpected end of file");
7567 p->u.conc.start = simple_strtol(s, &s2, 0);
7568 if ((int)strlen(s) > (int)(s2 - s)) {
7569 dgap_err("bad number for start of tty count");
7572 p->u.conc.v_start = 1;
7573 } else if (p->type == MNODE) {
7574 s = dgap_getword(in);
7576 dgap_err("unexpected end of file");
7579 p->u.module.start = simple_strtol(s, &s2, 0);
7580 if ((int)strlen(s) > (int)(s2 - s)) {
7581 dgap_err("bad number for start of tty count");
7584 p->u.module.v_start = 1;
7586 dgap_err("start only valid for concentrators or modules");
7589 DPR_INIT(("Adding START (%s) to config...\n", s));
7592 case TTYN: /* tty name prefix */
7593 if (dgap_checknode(p))
7595 if ( (p->next = dgap_newnode(TNODE)) == NULL ) {
7596 dgap_err("out of memory");
7600 if ( (s = dgap_getword(in)) == NULL ) {
7601 dgap_err("unexpeced end of file");
7604 if ( (p->u.ttyname = dgap_savestring(s)) == NULL ) {
7605 dgap_err("out of memory");
7608 DPR_INIT(("Adding TTY (%s) to config...\n", s));
7611 case CU: /* cu name prefix */
7612 if (dgap_checknode(p))
7614 if ( (p->next = dgap_newnode(CUNODE)) == NULL ) {
7615 dgap_err("out of memory");
7619 if ( (s = dgap_getword(in)) == NULL ) {
7620 dgap_err("unexpeced end of file");
7623 if ( (p->u.cuname = dgap_savestring(s)) == NULL ) {
7624 dgap_err("out of memory");
7627 DPR_INIT(("Adding CU (%s) to config...\n", s));
7630 case LINE: /* line information */
7631 if (dgap_checknode(p))
7634 dgap_err("must specify board before line info");
7637 switch (brd->u.board.type) {
7639 dgap_err("line not vaild for PC/em");
7642 if ( (p->next = dgap_newnode(LNODE)) == NULL ) {
7643 dgap_err("out of memory");
7650 DPR_INIT(("Adding LINE to config...\n"));
7653 case CONC: /* concentrator information */
7654 if (dgap_checknode(p))
7657 dgap_err("must specify line info before concentrator");
7660 if ( (p->next = dgap_newnode(CNODE)) == NULL ) {
7661 dgap_err("out of memory");
7667 brd->u.board.conc2++;
7669 brd->u.board.conc1++;
7671 DPR_INIT(("Adding CONC to config...\n"));
7674 case CX: /* c/x type concentrator */
7675 if (p->type != CNODE) {
7676 dgap_err("cx only valid for concentrators");
7679 p->u.conc.type = CX;
7680 p->u.conc.v_type = 1;
7681 DPR_INIT(("Adding CX to config...\n"));
7684 case EPC: /* epc type concentrator */
7685 if (p->type != CNODE) {
7686 dgap_err("cx only valid for concentrators");
7689 p->u.conc.type = EPC;
7690 p->u.conc.v_type = 1;
7691 DPR_INIT(("Adding EPC to config...\n"));
7694 case MOD: /* EBI module */
7695 if (dgap_checknode(p))
7698 dgap_err("must specify board info before EBI modules");
7701 switch (brd->u.board.type) {
7707 dgap_err("must specify concentrator info before EBI module");
7711 if ( (p->next = dgap_newnode(MNODE)) == NULL ) {
7712 dgap_err("out of memory");
7717 brd->u.board.module2++;
7719 brd->u.board.module1++;
7721 DPR_INIT(("Adding MOD to config...\n"));
7724 case PORTS: /* ports type EBI module */
7725 if (p->type != MNODE) {
7726 dgap_err("ports only valid for EBI modules");
7729 p->u.module.type = PORTS;
7730 p->u.module.v_type = 1;
7731 DPR_INIT(("Adding PORTS to config...\n"));
7734 case MODEM: /* ports type EBI module */
7735 if (p->type != MNODE) {
7736 dgap_err("modem only valid for modem modules");
7739 p->u.module.type = MODEM;
7740 p->u.module.v_type = 1;
7741 DPR_INIT(("Adding MODEM to config...\n"));
7745 if (p->type == LNODE) {
7746 if ((s = dgap_getword(in)) == NULL) {
7747 dgap_err("unexpected end of file");
7750 p->u.line.cable = dgap_savestring(s);
7751 p->u.line.v_cable = 1;
7753 DPR_INIT(("Adding CABLE (%s) to config...\n", s));
7756 case SPEED: /* sync line speed indication */
7757 if (p->type == LNODE) {
7758 s = dgap_getword(in);
7760 dgap_err("unexpected end of file");
7763 p->u.line.speed = (char)simple_strtol(s, &s2, 0);
7764 if ((short)strlen(s) > (short)(s2 - s)) {
7765 dgap_err("bad number for line speed");
7768 p->u.line.v_speed = 1;
7769 } else if (p->type == CNODE) {
7770 s = dgap_getword(in);
7772 dgap_err("unexpected end of file");
7775 p->u.conc.speed = (char)simple_strtol(s, &s2, 0);
7776 if ((short)strlen(s) > (short)(s2 - s)) {
7777 dgap_err("bad number for line speed");
7780 p->u.conc.v_speed = 1;
7782 dgap_err("speed valid only for lines or concentrators.");
7785 DPR_INIT(("Adding SPEED (%s) to config...\n", s));
7789 if (p->type == CNODE) {
7790 if ((s = dgap_getword(in)) == NULL) {
7791 dgap_err("unexpected end of file");
7794 p->u.conc.connect = dgap_savestring(s);
7795 p->u.conc.v_connect = 1;
7797 DPR_INIT(("Adding CONNECT (%s) to config...\n", s));
7799 case PRINT: /* transparent print name prefix */
7800 if (dgap_checknode(p))
7802 if ( (p->next = dgap_newnode(PNODE)) == NULL ) {
7803 dgap_err("out of memory");
7807 if ( (s = dgap_getword(in)) == NULL ) {
7808 dgap_err("unexpeced end of file");
7811 if ( (p->u.printname = dgap_savestring(s)) == NULL ) {
7812 dgap_err("out of memory");
7815 DPR_INIT(("Adding PRINT (%s) to config...\n", s));
7818 case CMAJOR: /* major number */
7819 if (dgap_checknode(p))
7821 if ( (p->next = dgap_newnode(JNODE)) == NULL ) {
7822 dgap_err("out of memory");
7826 s = dgap_getword(in);
7828 dgap_err("unexpected end of file");
7831 p->u.majornumber = simple_strtol(s, &s2, 0);
7832 if ((int)strlen(s) > (int)(s2 - s)) {
7833 dgap_err("bad number for major number");
7836 DPR_INIT(("Adding CMAJOR (%s) to config...\n", s));
7839 case ALTPIN: /* altpin setting */
7840 if (dgap_checknode(p))
7842 if ( (p->next = dgap_newnode(ANODE)) == NULL ) {
7843 dgap_err("out of memory");
7847 s = dgap_getword(in);
7849 dgap_err("unexpected end of file");
7852 p->u.altpin = simple_strtol(s, &s2, 0);
7853 if ((int)strlen(s) > (int)(s2 - s)) {
7854 dgap_err("bad number for altpin");
7857 DPR_INIT(("Adding ALTPIN (%s) to config...\n", s));
7860 case USEINTR: /* enable interrupt setting */
7861 if (dgap_checknode(p))
7863 if ( (p->next = dgap_newnode(INTRNODE)) == NULL ) {
7864 dgap_err("out of memory");
7868 s = dgap_getword(in);
7870 dgap_err("unexpected end of file");
7873 p->u.useintr = simple_strtol(s, &s2, 0);
7874 if ((int)strlen(s) > (int)(s2 - s)) {
7875 dgap_err("bad number for useintr");
7878 DPR_INIT(("Adding USEINTR (%s) to config...\n", s));
7881 case TTSIZ: /* size of tty structure */
7882 if (dgap_checknode(p))
7884 if ( (p->next = dgap_newnode(TSNODE)) == NULL ) {
7885 dgap_err("out of memory");
7889 s = dgap_getword(in);
7891 dgap_err("unexpected end of file");
7894 p->u.ttysize = simple_strtol(s, &s2, 0);
7895 if ((int)strlen(s) > (int)(s2 - s)) {
7896 dgap_err("bad number for ttysize");
7899 DPR_INIT(("Adding TTSIZ (%s) to config...\n", s));
7902 case CHSIZ: /* channel structure size */
7903 if (dgap_checknode(p))
7905 if ( (p->next = dgap_newnode(CSNODE)) == NULL ) {
7906 dgap_err("out of memory");
7910 s = dgap_getword(in);
7912 dgap_err("unexpected end of file");
7915 p->u.chsize = simple_strtol(s, &s2, 0);
7916 if ((int)strlen(s) > (int)(s2 - s)) {
7917 dgap_err("bad number for chsize");
7920 DPR_INIT(("Adding CHSIZE (%s) to config...\n", s));
7923 case BSSIZ: /* board structure size */
7924 if (dgap_checknode(p))
7926 if ( (p->next = dgap_newnode(BSNODE)) == NULL ) {
7927 dgap_err("out of memory");
7931 s = dgap_getword(in);
7933 dgap_err("unexpected end of file");
7936 p->u.bssize = simple_strtol(s, &s2, 0);
7937 if ((int)strlen(s) > (int)(s2 - s)) {
7938 dgap_err("bad number for bssize");
7941 DPR_INIT(("Adding BSSIZ (%s) to config...\n", s));
7944 case UNTSIZ: /* sched structure size */
7945 if (dgap_checknode(p))
7947 if ( (p->next = dgap_newnode(USNODE)) == NULL ) {
7948 dgap_err("out of memory");
7952 s = dgap_getword(in);
7954 dgap_err("unexpected end of file");
7957 p->u.unsize = simple_strtol(s, &s2, 0);
7958 if ((int)strlen(s) > (int)(s2 - s)) {
7959 dgap_err("bad number for schedsize");
7962 DPR_INIT(("Adding UNTSIZ (%s) to config...\n", s));
7965 case F2SIZ: /* f2200 structure size */
7966 if (dgap_checknode(p))
7968 if ( (p->next = dgap_newnode(FSNODE)) == NULL ) {
7969 dgap_err("out of memory");
7973 s = dgap_getword(in);
7975 dgap_err("unexpected end of file");
7978 p->u.f2size = simple_strtol(s, &s2, 0);
7979 if ((int)strlen(s) > (int)(s2 - s)) {
7980 dgap_err("bad number for f2200size");
7983 DPR_INIT(("Adding F2SIZ (%s) to config...\n", s));
7986 case VPSIZ: /* vpix structure size */
7987 if (dgap_checknode(p))
7989 if ( (p->next = dgap_newnode(VSNODE)) == NULL ) {
7990 dgap_err("out of memory");
7994 s = dgap_getword(in);
7996 dgap_err("unexpected end of file");
7999 p->u.vpixsize = simple_strtol(s, &s2, 0);
8000 if ((int)strlen(s) > (int)(s2 - s)) {
8001 dgap_err("bad number for vpixsize");
8004 DPR_INIT(("Adding VPSIZ (%s) to config...\n", s));
8012 * dgap_sindex: much like index(), but it looks for a match of any character in
8013 * the group, and returns that position. If the first character is a ^, then
8014 * this will match the first occurrence not in that group.
8016 static char *dgap_sindex (char *string, char *group)
8020 if (!string || !group)
8021 return (char *) NULL;
8023 if (*group == '^') {
8025 for (; *string; string++) {
8026 for (ptr = group; *ptr; ptr++) {
8027 if (*ptr == *string)
8035 for (; *string; string++) {
8036 for (ptr = group; *ptr; ptr++) {
8037 if (*ptr == *string)
8043 return (char *) NULL;
8048 * Get a token from the input file; return 0 if end of file is reached
8050 static int dgap_gettok(char **in, struct cnode *p)
8055 if (strstr(dgap_cword, "boar")) {
8056 w = dgap_getword(in);
8057 snprintf(dgap_cword, MAXCWORD, "%s", w);
8058 for (t = dgap_tlist; t->token != 0; t++) {
8059 if ( !strcmp(w, t->string)) {
8063 dgap_err("board !!type not specified");
8067 while ( (w = dgap_getword(in)) != NULL ) {
8068 snprintf(dgap_cword, MAXCWORD, "%s", w);
8069 for (t = dgap_tlist; t->token != 0; t++) {
8070 if ( !strcmp(w, t->string) )
8080 * get a word from the input stream, also keep track of current line number.
8081 * words are separated by whitespace.
8083 static char *dgap_getword(char **in)
8085 char *ret_ptr = *in;
8087 char *ptr = dgap_sindex(*in, " \t\n");
8089 /* If no word found, return null */
8093 /* Mark new location for our buffer */
8097 /* Eat any extra spaces/tabs/newlines that might be present */
8098 while (*in && **in && ((**in == ' ') || (**in == '\t') || (**in == '\n'))) {
8108 * print an error message, giving the line number in the file where
8109 * the error occurred.
8111 static void dgap_err(char *s)
8113 printk("DGAP: parse: %s\n", s);
8118 * allocate a new configuration node of type t
8120 static struct cnode *dgap_newnode(int t)
8124 n = kmalloc(sizeof(struct cnode), GFP_ATOMIC);
8126 memset((char *)n, 0, sizeof(struct cnode));
8134 * dgap_checknode: see if all the necessary info has been supplied for a node
8135 * before creating the next node.
8137 static int dgap_checknode(struct cnode *p)
8141 if (p->u.board.v_type == 0) {
8142 dgap_err("board type !not specified");
8149 if (p->u.line.v_speed == 0) {
8150 dgap_err("line speed not specified");
8156 if (p->u.conc.v_type == 0) {
8157 dgap_err("concentrator type not specified");
8160 if (p->u.conc.v_speed == 0) {
8161 dgap_err("concentrator line speed not specified");
8164 if (p->u.conc.v_nport == 0) {
8165 dgap_err("number of ports on concentrator not specified");
8168 if (p->u.conc.v_id == 0) {
8169 dgap_err("concentrator id letter not specified");
8175 if (p->u.module.v_type == 0) {
8176 dgap_err("EBI module type not specified");
8179 if (p->u.module.v_nport == 0) {
8180 dgap_err("number of ports on EBI module not specified");
8183 if (p->u.module.v_id == 0) {
8184 dgap_err("EBI module id letter not specified");
8193 * save a string somewhere
8195 static char *dgap_savestring(char *s)
8198 if ( (p = kmalloc(strlen(s) + 1, GFP_ATOMIC) ) != NULL) {
8206 * Given a board pointer, returns whether we should use interrupts or not.
8208 uint dgap_config_get_useintr(struct board_t *bd)
8210 struct cnode *p = NULL;
8215 for (p = bd->bd_config; p; p = p->next) {
8219 * check for pcxr types.
8221 return p->u.useintr;
8227 /* If not found, then don't turn on interrupts. */
8233 * Given a board pointer, returns whether we turn on altpin or not.
8235 uint dgap_config_get_altpin(struct board_t *bd)
8237 struct cnode *p = NULL;
8242 for (p = bd->bd_config; p; p = p->next) {
8246 * check for pcxr types.
8254 /* If not found, then don't turn on interrupts. */
8261 * Given a specific type of board, if found, detached link and
8262 * returns the first occurrence in the list.
8264 struct cnode *dgap_find_config(int type, int bus, int slot)
8266 struct cnode *p, *prev = NULL, *prev2 = NULL, *found = NULL;
8270 while (p->next != NULL) {
8274 if (p->type == BNODE) {
8276 if (p->u.board.type == type) {
8278 if (p->u.board.v_pcibus && p->u.board.pcibus != bus) {
8279 DPR(("Found matching board, but wrong bus position. System says bus %d, we want bus %ld\n",
8280 bus, p->u.board.pcibus));
8283 if (p->u.board.v_pcislot && p->u.board.pcislot != slot) {
8284 DPR_INIT(("Found matching board, but wrong slot position. System says slot %d, we want slot %ld\n",
8285 slot, p->u.board.pcislot));
8289 DPR_INIT(("Matched type in config file\n"));
8293 * Keep walking thru the list till we find the next board.
8295 while (p->next != NULL) {
8298 if (p->type == BNODE) {
8301 * Mark the end of our 1 board chain of configs.
8306 * Link the "next" board to the previous board,
8307 * effectively "unlinking" our board from the main config.
8315 * It must be the last board in the list.
8326 * Given a board pointer, walks the config link, counting up
8327 * all ports user specified should be on the board.
8328 * (This does NOT mean they are all actually present right now tho)
8330 uint dgap_config_get_number_of_ports(struct board_t *bd)
8333 struct cnode *p = NULL;
8338 for (p = bd->bd_config; p; p = p->next) {
8343 * check for pcxr types.
8345 if (p->u.board.type > EPCFE)
8346 count += p->u.board.nport;
8349 count += p->u.conc.nport;
8352 count += p->u.module.nport;
8359 char *dgap_create_config_string(struct board_t *bd, char *string)
8362 struct cnode *p = NULL;
8363 struct cnode *q = NULL;
8371 for (p = bd->bd_config; p; p = p->next) {
8377 *ptr = p->u.line.speed;
8382 * Because the EPC/con concentrators can have EM modules
8383 * hanging off of them, we have to walk ahead in the list
8384 * and keep adding the number of ports on each EM to the config.
8387 speed = p->u.conc.speed;
8389 if ((q != NULL) && (q->type == MNODE) ) {
8390 *ptr = (p->u.conc.nport + 0x80);
8393 while ((q->next != NULL) && (q->next->type) == MNODE) {
8394 *ptr = (q->u.module.nport + 0x80);
8399 *ptr = q->u.module.nport;
8402 *ptr = p->u.conc.nport;
8418 char *dgap_get_config_letters(struct board_t *bd, char *string)
8422 struct cnode *cptr = NULL;
8424 int left = MAXTTYNAMELEN;
8430 for (cptr = bd->bd_config; cptr; cptr = cptr->next) {
8432 if ((cptr->type == BNODE) &&
8433 ((cptr->u.board.type == APORT2_920P) || (cptr->u.board.type == APORT4_920P) ||
8434 (cptr->u.board.type == APORT8_920P) || (cptr->u.board.type == PAPORT4) ||
8435 (cptr->u.board.type == PAPORT8))) {
8440 if (cptr->type == TNODE && found == TRUE) {
8442 if (strstr(cptr->u.ttyname, "tty")) {
8443 ptr1 = cptr->u.ttyname;
8447 ptr1 = cptr->u.ttyname;
8450 len = snprintf(ptr, left, "%s", ptr1);
8458 if (cptr->type == CNODE) {
8459 if (cptr->u.conc.id) {
8460 len = snprintf(ptr, left, "%s", cptr->u.conc.id);
8468 if (cptr->type == MNODE) {
8469 if (cptr->u.module.id) {
8470 len = snprintf(ptr, left, "%s", cptr->u.module.id);