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 #define init_MUTEX(sem) sema_init(sem, 1)
55 #define DECLARE_MUTEX(name) \
56 struct semaphore name = __SEMAPHORE_INITIALIZER(name, 1)
58 MODULE_LICENSE("GPL");
59 MODULE_AUTHOR("Digi International, http://www.digi.com");
60 MODULE_DESCRIPTION("Driver for the Digi International EPCA PCI based product line");
61 MODULE_SUPPORTED_DEVICE("dgap");
64 * insmod command line overrideable parameters
66 * NOTE: we use a set of macros to create the variables, which allows
67 * us to specify the variable type, name, initial value, and description.
69 PARM_INT(debug, 0x00, 0644, "Driver debugging level");
70 PARM_INT(rawreadok, 1, 0644, "Bypass flip buffers on input");
71 PARM_INT(trcbuf_size, 0x100000, 0644, "Debugging trace buffer size.");
74 /**************************************************************************
76 * protos for this file
80 static int dgap_start(void);
81 static void dgap_init_globals(void);
82 static int dgap_found_board(struct pci_dev *pdev, int id);
83 static void dgap_cleanup_board(struct board_t *brd);
84 static void dgap_poll_handler(ulong dummy);
85 static int dgap_init_pci(void);
86 static int dgap_init_one(struct pci_dev *pdev, const struct pci_device_id *ent);
87 static void dgap_remove_one(struct pci_dev *dev);
88 static int dgap_probe1(struct pci_dev *pdev, int card_type);
89 static void dgap_mbuf(struct board_t *brd, const char *fmt, ...);
90 static int dgap_do_remap(struct board_t *brd);
91 static irqreturn_t dgap_intr(int irq, void *voidbrd);
93 /* Our function prototypes */
94 static int dgap_tty_open(struct tty_struct *tty, struct file *file);
95 static void dgap_tty_close(struct tty_struct *tty, struct file *file);
96 static int dgap_block_til_ready(struct tty_struct *tty, struct file *file, struct channel_t *ch);
97 static int dgap_tty_ioctl(struct tty_struct *tty, unsigned int cmd, unsigned long arg);
98 static int dgap_tty_digigeta(struct tty_struct *tty, struct digi_t __user *retinfo);
99 static int dgap_tty_digiseta(struct tty_struct *tty, struct digi_t __user *new_info);
100 static int dgap_tty_digigetedelay(struct tty_struct *tty, int __user *retinfo);
101 static int dgap_tty_digisetedelay(struct tty_struct *tty, int __user *new_info);
102 static int dgap_tty_write_room(struct tty_struct* tty);
103 static int dgap_tty_chars_in_buffer(struct tty_struct* tty);
104 static void dgap_tty_start(struct tty_struct *tty);
105 static void dgap_tty_stop(struct tty_struct *tty);
106 static void dgap_tty_throttle(struct tty_struct *tty);
107 static void dgap_tty_unthrottle(struct tty_struct *tty);
108 static void dgap_tty_flush_chars(struct tty_struct *tty);
109 static void dgap_tty_flush_buffer(struct tty_struct *tty);
110 static void dgap_tty_hangup(struct tty_struct *tty);
111 static int dgap_wait_for_drain(struct tty_struct *tty);
112 static int dgap_set_modem_info(struct tty_struct *tty, unsigned int command, unsigned int __user *value);
113 static int dgap_get_modem_info(struct channel_t *ch, unsigned int __user *value);
114 static int dgap_tty_digisetcustombaud(struct tty_struct *tty, int __user *new_info);
115 static int dgap_tty_digigetcustombaud(struct tty_struct *tty, int __user *retinfo);
116 static int dgap_tty_tiocmget(struct tty_struct *tty);
117 static int dgap_tty_tiocmset(struct tty_struct *tty, unsigned int set, unsigned int clear);
118 static int dgap_tty_send_break(struct tty_struct *tty, int msec);
119 static void dgap_tty_wait_until_sent(struct tty_struct *tty, int timeout);
120 static int dgap_tty_write(struct tty_struct *tty, const unsigned char *buf, int count);
121 static void dgap_tty_set_termios(struct tty_struct *tty, struct ktermios *old_termios);
122 static int dgap_tty_put_char(struct tty_struct *tty, unsigned char c);
123 static void dgap_tty_send_xchar(struct tty_struct *tty, char ch);
125 static int dgap_tty_register(struct board_t *brd);
126 static int dgap_tty_preinit(void);
127 static int dgap_tty_init(struct board_t *);
128 static void dgap_tty_post_uninit(void);
129 static void dgap_tty_uninit(struct board_t *);
130 static void dgap_carrier(struct channel_t *ch);
131 static void dgap_input(struct channel_t *ch);
134 * Our function prototypes from dgap_fep5
136 static void dgap_cmdw_ext(struct channel_t *ch, u16 cmd, u16 word, uint ncmds);
137 static int dgap_event(struct board_t *bd);
139 static void dgap_poll_tasklet(unsigned long data);
140 static void dgap_cmdb(struct channel_t *ch, uchar cmd, uchar byte1, uchar byte2, uint ncmds);
141 static void dgap_cmdw(struct channel_t *ch, uchar cmd, u16 word, uint ncmds);
142 static void dgap_wmove(struct channel_t *ch, char *buf, uint cnt);
143 static int dgap_param(struct tty_struct *tty);
144 static void dgap_parity_scan(struct channel_t *ch, unsigned char *cbuf, unsigned char *fbuf, int *len);
145 static uint dgap_get_custom_baud(struct channel_t *ch);
146 static void dgap_firmware_reset_port(struct channel_t *ch);
149 * Function prototypes from dgap_parse.c.
151 static int dgap_gettok(char **in, struct cnode *p);
152 static char *dgap_getword(char **in);
153 static char *dgap_savestring(char *s);
154 static struct cnode *dgap_newnode(int t);
155 static int dgap_checknode(struct cnode *p);
156 static void dgap_err(char *s);
159 * Function prototypes from dgap_sysfs.h
167 static void dgap_create_ports_sysfiles(struct board_t *bd);
168 static void dgap_remove_ports_sysfiles(struct board_t *bd);
170 static void dgap_create_driver_sysfiles(struct pci_driver *);
171 static void dgap_remove_driver_sysfiles(struct pci_driver *);
173 static int dgap_tty_class_init(void);
174 static int dgap_tty_class_destroy(void);
176 static void dgap_create_tty_sysfs(struct un_t *un, struct device *c);
177 static void dgap_remove_tty_sysfs(struct device *c);
180 * Function prototypes from dgap_parse.h
182 static int dgap_parsefile(char **in, int Remove);
183 static struct cnode *dgap_find_config(int type, int bus, int slot);
184 static uint dgap_config_get_number_of_ports(struct board_t *bd);
185 static char *dgap_create_config_string(struct board_t *bd, char *string);
186 static char *dgap_get_config_letters(struct board_t *bd, char *string);
187 static uint dgap_config_get_useintr(struct board_t *bd);
188 static uint dgap_config_get_altpin(struct board_t *bd);
190 static int dgap_ms_sleep(ulong ms);
191 static char *dgap_ioctl_name(int cmd);
192 static void dgap_do_bios_load(struct board_t *brd, uchar __user *ubios, int len);
193 static void dgap_do_fep_load(struct board_t *brd, uchar __user *ufep, int len);
194 static void dgap_do_conc_load(struct board_t *brd, uchar *uaddr, int len);
195 static void dgap_do_config_load(uchar __user *uaddr, int len);
196 static int dgap_after_config_loaded(void);
197 static int dgap_finalize_board_init(struct board_t *brd);
200 /* Driver load/unload functions */
201 int dgap_init_module(void);
202 void dgap_cleanup_module(void);
204 module_init(dgap_init_module);
205 module_exit(dgap_cleanup_module);
209 * File operations permitted on Control/Management major.
211 static struct file_operations DgapBoardFops =
213 .owner = THIS_MODULE,
220 static uint dgap_NumBoards;
221 static struct board_t *dgap_Board[MAXBOARDS];
222 DEFINE_SPINLOCK(dgap_global_lock);
223 static ulong dgap_poll_counter;
224 static char *dgap_config_buf;
225 static int dgap_driver_state = DRIVER_INITIALIZED;
226 DEFINE_SPINLOCK(dgap_dl_lock);
227 static wait_queue_head_t dgap_dl_wait;
228 static int dgap_dl_action;
229 static int dgap_poll_tick = 20; /* Poll interval - 20 ms */
234 static int dgap_Major_Control_Registered = FALSE;
235 static uint dgap_driver_start = FALSE;
237 static struct class * dgap_class;
239 static struct board_t *dgap_BoardsByMajor[256];
240 static uchar *dgap_TmpWriteBuf = NULL;
241 DECLARE_MUTEX(dgap_TmpWriteSem);
242 static uint dgap_count = 500;
247 DEFINE_SPINLOCK(dgap_poll_lock); /* Poll scheduling lock */
248 static ulong dgap_poll_time; /* Time of next poll */
249 static uint dgap_poll_stop; /* Used to tell poller to stop */
250 static struct timer_list dgap_poll_timer;
253 static struct pci_device_id dgap_pci_tbl[] = {
254 { DIGI_VID, PCI_DEVICE_XEM_DID, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0 },
255 { DIGI_VID, PCI_DEVICE_CX_DID, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 1 },
256 { DIGI_VID, PCI_DEVICE_CX_IBM_DID, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 2 },
257 { DIGI_VID, PCI_DEVICE_EPCJ_DID, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 3 },
258 { DIGI_VID, PCI_DEVICE_920_2_DID, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 4 },
259 { DIGI_VID, PCI_DEVICE_920_4_DID, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 5 },
260 { DIGI_VID, PCI_DEVICE_920_8_DID, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 6 },
261 { DIGI_VID, PCI_DEVICE_XR_DID, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 7 },
262 { DIGI_VID, PCI_DEVICE_XRJ_DID, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 8 },
263 { DIGI_VID, PCI_DEVICE_XR_422_DID, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 9 },
264 { DIGI_VID, PCI_DEVICE_XR_IBM_DID, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 10 },
265 { DIGI_VID, PCI_DEVICE_XR_SAIP_DID, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 11 },
266 { DIGI_VID, PCI_DEVICE_XR_BULL_DID, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 12 },
267 { DIGI_VID, PCI_DEVICE_920_8_HP_DID, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 13 },
268 { DIGI_VID, PCI_DEVICE_XEM_HP_DID, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 14 },
269 {0,} /* 0 terminated list. */
271 MODULE_DEVICE_TABLE(pci, dgap_pci_tbl);
275 * A generic list of Product names, PCI Vendor ID, and PCI Device ID.
284 static struct board_id dgap_Ids[] =
286 { PPCM, PCI_DEVICE_XEM_NAME, 64, (T_PCXM | T_PCLITE | T_PCIBUS) },
287 { PCX, PCI_DEVICE_CX_NAME, 128, (T_CX | T_PCIBUS) },
288 { PCX, PCI_DEVICE_CX_IBM_NAME, 128, (T_CX | T_PCIBUS) },
289 { PEPC, PCI_DEVICE_EPCJ_NAME, 224, (T_EPC | T_PCIBUS) },
290 { APORT2_920P, PCI_DEVICE_920_2_NAME, 2, (T_PCXR | T_PCLITE | T_PCIBUS) },
291 { APORT4_920P, PCI_DEVICE_920_4_NAME, 4, (T_PCXR | T_PCLITE | T_PCIBUS) },
292 { APORT8_920P, PCI_DEVICE_920_8_NAME, 8, (T_PCXR | T_PCLITE | T_PCIBUS) },
293 { PAPORT8, PCI_DEVICE_XR_NAME, 8, (T_PCXR | T_PCLITE | T_PCIBUS) },
294 { PAPORT8, PCI_DEVICE_XRJ_NAME, 8, (T_PCXR | T_PCLITE | T_PCIBUS) },
295 { PAPORT8, PCI_DEVICE_XR_422_NAME, 8, (T_PCXR | T_PCLITE | T_PCIBUS) },
296 { PAPORT8, PCI_DEVICE_XR_IBM_NAME, 8, (T_PCXR | T_PCLITE | T_PCIBUS) },
297 { PAPORT8, PCI_DEVICE_XR_SAIP_NAME, 8, (T_PCXR | T_PCLITE | T_PCIBUS) },
298 { PAPORT8, PCI_DEVICE_XR_BULL_NAME, 8, (T_PCXR | T_PCLITE | T_PCIBUS) },
299 { APORT8_920P, PCI_DEVICE_920_8_HP_NAME, 8, (T_PCXR | T_PCLITE | T_PCIBUS) },
300 { PPCM, PCI_DEVICE_XEM_HP_NAME, 64, (T_PCXM | T_PCLITE | T_PCIBUS) },
301 {0,} /* 0 terminated list. */
304 static struct pci_driver dgap_driver = {
306 .probe = dgap_init_one,
307 .id_table = dgap_pci_tbl,
308 .remove = dgap_remove_one,
312 static char *dgap_state_text[] = {
314 "Configuration for board not found.\n\t\t\tRun mpi to configure board.",
320 "Need Device Creation",
321 "Requested Device Creation",
322 "Finished Device Creation",
326 "Finished BIOS Load",
331 "Requested PROC creation",
332 "Finished PROC creation",
336 static char *dgap_driver_state_text[] = {
337 "Driver Initialized",
338 "Driver needs configuration load.",
339 "Driver requested configuration from download daemon.",
344 * Default transparent print information.
346 static struct digi_t dgap_digi_init = {
347 .digi_flags = DIGI_COOK, /* Flags */
348 .digi_maxcps = 100, /* Max CPS */
349 .digi_maxchar = 50, /* Max chars in print queue */
350 .digi_bufsize = 100, /* Printer buffer size */
351 .digi_onlen = 4, /* size of printer on string */
352 .digi_offlen = 4, /* size of printer off string */
353 .digi_onstr = "\033[5i", /* ANSI printer on string ] */
354 .digi_offstr = "\033[4i", /* ANSI printer off string ] */
355 .digi_term = "ansi" /* default terminal type */
360 * Define a local default termios struct. All ports will be created
361 * with this termios initially.
363 * This defines a raw port at 9600 baud, 8 data bits, no parity,
367 static struct ktermios DgapDefaultTermios =
369 .c_iflag = (DEFAULT_IFLAGS), /* iflags */
370 .c_oflag = (DEFAULT_OFLAGS), /* oflags */
371 .c_cflag = (DEFAULT_CFLAGS), /* cflags */
372 .c_lflag = (DEFAULT_LFLAGS), /* lflags */
377 static const struct tty_operations dgap_tty_ops = {
378 .open = dgap_tty_open,
379 .close = dgap_tty_close,
380 .write = dgap_tty_write,
381 .write_room = dgap_tty_write_room,
382 .flush_buffer = dgap_tty_flush_buffer,
383 .chars_in_buffer = dgap_tty_chars_in_buffer,
384 .flush_chars = dgap_tty_flush_chars,
385 .ioctl = dgap_tty_ioctl,
386 .set_termios = dgap_tty_set_termios,
387 .stop = dgap_tty_stop,
388 .start = dgap_tty_start,
389 .throttle = dgap_tty_throttle,
390 .unthrottle = dgap_tty_unthrottle,
391 .hangup = dgap_tty_hangup,
392 .put_char = dgap_tty_put_char,
393 .tiocmget = dgap_tty_tiocmget,
394 .tiocmset = dgap_tty_tiocmset,
395 .break_ctl = dgap_tty_send_break,
396 .wait_until_sent = dgap_tty_wait_until_sent,
397 .send_xchar = dgap_tty_send_xchar
401 * Our needed internal static variables from dgap_parse.c
403 static struct cnode dgap_head;
405 static char dgap_cword[MAXCWORD];
412 static struct toklist dgap_tlist[] = {
413 { BEGIN, "config_begin" },
414 { END, "config_end" },
416 { PCX, "Digi_AccelePort_C/X_PCI" }, /* C/X_PCI */
417 { PEPC, "Digi_AccelePort_EPC/X_PCI" }, /* EPC/X_PCI */
418 { PPCM, "Digi_AccelePort_Xem_PCI" }, /* PCI/Xem */
419 { APORT2_920P, "Digi_AccelePort_2r_920_PCI" },
420 { APORT4_920P, "Digi_AccelePort_4r_920_PCI" },
421 { APORT8_920P, "Digi_AccelePort_8r_920_PCI" },
422 { PAPORT4, "Digi_AccelePort_4r_PCI(EIA-232/RS-422)" },
423 { PAPORT8, "Digi_AccelePort_8r_PCI(EIA-232/RS-422)" },
425 { PCIINFO, "pciinfo" },
428 { CONC, "concentrator" },
438 { CONNECT, "connect" },
439 { METHOD, "method" },
440 { STATUS, "status" },
441 { CUSTOM, "Custom" },
447 { NPORTS, "nports" },
452 { ALTPIN, "altpin" },
453 { USEINTR, "useintr" },
454 { TTSIZ, "ttysize" },
456 { BSSIZ, "boardsize" },
457 { UNTSIZ, "schedsize" },
458 { F2SIZ, "f2200size" },
459 { VPSIZ, "vpixsize" },
463 /************************************************************************
465 * Driver load/unload functions
467 ************************************************************************/
472 * Module load. This is where it all starts.
474 int dgap_init_module(void)
478 APR(("%s, Digi International Part Number %s\n", DG_NAME, DG_PART));
481 * Initialize global stuff
490 * Find and configure all the cards
492 rc = dgap_init_pci();
495 * If something went wrong in the scan, bail out of driver.
498 /* Only unregister the pci driver if it was actually registered. */
500 pci_unregister_driver(&dgap_driver);
502 printk("WARNING: dgap driver load failed. No DGAP boards found.\n");
504 dgap_cleanup_module();
507 dgap_create_driver_sysfiles(&dgap_driver);
510 DPR_INIT(("Finished init_module. Returning %d\n", rc));
518 static int dgap_start(void)
523 if (dgap_driver_start == FALSE) {
525 dgap_driver_start = TRUE;
527 /* make sure that the globals are init'd before we do anything else */
532 APR(("For the tools package or updated drivers please visit http://www.digi.com\n"));
535 * Register our base character device into the kernel.
536 * This allows the download daemon to connect to the downld device
537 * before any of the boards are init'ed.
539 if (!dgap_Major_Control_Registered) {
541 * Register management/dpa devices
543 rc = register_chrdev(DIGI_DGAP_MAJOR, "dgap", &DgapBoardFops);
545 APR(("Can't register dgap driver device (%d)\n", rc));
549 dgap_class = class_create(THIS_MODULE, "dgap_mgmt");
550 device_create(dgap_class, NULL,
551 MKDEV(DIGI_DGAP_MAJOR, 0),
553 device_create(dgap_class, NULL,
554 MKDEV(DIGI_DGAP_MAJOR, 1),
555 NULL, "dgap_downld");
556 dgap_Major_Control_Registered = TRUE;
560 * Init any global tty stuff.
562 rc = dgap_tty_preinit();
565 APR(("tty preinit - not enough memory (%d)\n", rc));
569 /* Start the poller */
570 DGAP_LOCK(dgap_poll_lock, flags);
571 init_timer(&dgap_poll_timer);
572 dgap_poll_timer.function = dgap_poll_handler;
573 dgap_poll_timer.data = 0;
574 dgap_poll_time = jiffies + dgap_jiffies_from_ms(dgap_poll_tick);
575 dgap_poll_timer.expires = dgap_poll_time;
576 DGAP_UNLOCK(dgap_poll_lock, flags);
578 add_timer(&dgap_poll_timer);
580 dgap_driver_state = DRIVER_NEED_CONFIG_LOAD;
588 * Register pci driver, and return how many boards we have.
590 static int dgap_init_pci(void)
592 return pci_register_driver(&dgap_driver);
596 /* returns count (>= 0), or negative on error */
597 static int dgap_init_one(struct pci_dev *pdev, const struct pci_device_id *ent)
601 /* wake up and enable device */
602 rc = pci_enable_device(pdev);
607 rc = dgap_probe1(pdev, ent->driver_data);
610 DPR_INIT(("Incrementing numboards to %d\n", dgap_NumBoards));
617 static int dgap_probe1(struct pci_dev *pdev, int card_type)
619 return dgap_found_board(pdev, card_type);
623 static void dgap_remove_one(struct pci_dev *dev)
630 * dgap_cleanup_module()
632 * Module unload. This is where it all ends.
634 void dgap_cleanup_module(void)
639 DGAP_LOCK(dgap_poll_lock, lock_flags);
641 DGAP_UNLOCK(dgap_poll_lock, lock_flags);
643 /* Turn off poller right away. */
644 del_timer_sync( &dgap_poll_timer);
646 dgap_remove_driver_sysfiles(&dgap_driver);
649 if (dgap_Major_Control_Registered) {
650 device_destroy(dgap_class, MKDEV(DIGI_DGAP_MAJOR, 0));
651 device_destroy(dgap_class, MKDEV(DIGI_DGAP_MAJOR, 1));
652 class_destroy(dgap_class);
653 unregister_chrdev(DIGI_DGAP_MAJOR, "dgap");
656 kfree(dgap_config_buf);
658 for (i = 0; i < dgap_NumBoards; ++i) {
659 dgap_remove_ports_sysfiles(dgap_Board[i]);
660 dgap_tty_uninit(dgap_Board[i]);
661 dgap_cleanup_board(dgap_Board[i]);
664 dgap_tty_post_uninit();
666 #if defined(DGAP_TRACER)
667 /* last thing, make sure we release the tracebuffer */
671 pci_unregister_driver(&dgap_driver);
676 * dgap_cleanup_board()
678 * Free all the memory associated with a board
680 static void dgap_cleanup_board(struct board_t *brd)
684 if(!brd || brd->magic != DGAP_BOARD_MAGIC)
687 if (brd->intr_used && brd->irq)
688 free_irq(brd->irq, brd);
690 tasklet_kill(&brd->helper_tasklet);
692 if (brd->re_map_port) {
693 release_mem_region(brd->membase + 0x200000, 0x200000);
694 iounmap(brd->re_map_port);
695 brd->re_map_port = NULL;
698 if (brd->re_map_membase) {
699 release_mem_region(brd->membase, 0x200000);
700 iounmap(brd->re_map_membase);
701 brd->re_map_membase = NULL;
704 if (brd->msgbuf_head) {
707 DGAP_LOCK(dgap_global_lock, flags);
709 printk("%s", brd->msgbuf_head);
710 kfree(brd->msgbuf_head);
711 brd->msgbuf_head = NULL;
712 DGAP_UNLOCK(dgap_global_lock, flags);
715 /* Free all allocated channels structs */
716 for (i = 0; i < MAXPORTS ; i++) {
717 if (brd->channels[i]) {
718 kfree(brd->channels[i]);
719 brd->channels[i] = NULL;
724 kfree(brd->flipflagbuf);
726 dgap_Board[brd->boardnum] = NULL;
735 * A board has been found, init it.
737 static int dgap_found_board(struct pci_dev *pdev, int id)
740 unsigned int pci_irq;
744 /* get the board structure and prep it */
745 brd = dgap_Board[dgap_NumBoards] =
746 (struct board_t *) kzalloc(sizeof(struct board_t), GFP_KERNEL);
748 APR(("memory allocation for board structure failed\n"));
752 /* make a temporary message buffer for the boot messages */
753 brd->msgbuf = brd->msgbuf_head =
754 (char *) kzalloc(sizeof(char) * 8192, GFP_KERNEL);
757 APR(("memory allocation for board msgbuf failed\n"));
761 /* store the info for the board we've found */
762 brd->magic = DGAP_BOARD_MAGIC;
763 brd->boardnum = dgap_NumBoards;
765 brd->vendor = dgap_pci_tbl[id].vendor;
766 brd->device = dgap_pci_tbl[id].device;
768 brd->pci_bus = pdev->bus->number;
769 brd->pci_slot = PCI_SLOT(pdev->devfn);
770 brd->name = dgap_Ids[id].name;
771 brd->maxports = dgap_Ids[id].maxports;
772 brd->type = dgap_Ids[id].config_type;
773 brd->dpatype = dgap_Ids[id].dpatype;
774 brd->dpastatus = BD_NOFEP;
775 init_waitqueue_head(&brd->state_wait);
777 DGAP_SPINLOCK_INIT(brd->bd_lock);
779 brd->state = BOARD_FOUND;
781 brd->inhibit_poller = FALSE;
782 brd->wait_for_bios = 0;
783 brd->wait_for_fep = 0;
785 for (i = 0; i < MAXPORTS; i++) {
786 brd->channels[i] = NULL;
789 /* store which card & revision we have */
790 pci_read_config_word(pdev, PCI_SUBSYSTEM_VENDOR_ID, &brd->subvendor);
791 pci_read_config_word(pdev, PCI_SUBSYSTEM_ID, &brd->subdevice);
792 pci_read_config_byte(pdev, PCI_REVISION_ID, &brd->rev);
797 /* get the PCI Base Address Registers */
799 /* Xr Jupiter and EPC use BAR 2 */
800 if (brd->device == PCI_DEVICE_XRJ_DID || brd->device == PCI_DEVICE_EPCJ_DID) {
801 brd->membase = pci_resource_start(pdev, 2);
802 brd->membase_end = pci_resource_end(pdev, 2);
804 /* Everyone else uses BAR 0 */
806 brd->membase = pci_resource_start(pdev, 0);
807 brd->membase_end = pci_resource_end(pdev, 0);
811 APR(("card has no PCI IO resources, failing board.\n"));
815 if (brd->membase & 1)
821 * On the PCI boards, there is no IO space allocated
822 * The I/O registers will be in the first 3 bytes of the
823 * upper 2MB of the 4MB memory space. The board memory
824 * will be mapped into the low 2MB of the 4MB memory space
826 brd->port = brd->membase + PCI_IO_OFFSET;
827 brd->port_end = brd->port + PCI_IO_SIZE;
831 * Special initialization for non-PLX boards
833 if (brd->device != PCI_DEVICE_XRJ_DID && brd->device != PCI_DEVICE_EPCJ_DID) {
836 pci_write_config_byte(pdev, 0x40, 0);
837 pci_write_config_byte(pdev, 0x46, 0);
839 /* Limit burst length to 2 doubleword transactions */
840 pci_write_config_byte(pdev, 0x42, 1);
843 * Enable IO and mem if not already done.
844 * This was needed for support on Itanium.
846 pci_read_config_word(pdev, PCI_COMMAND, &cmd);
847 cmd |= (PCI_COMMAND_IO | PCI_COMMAND_MEMORY);
848 pci_write_config_word(pdev, PCI_COMMAND, cmd);
851 /* init our poll helper tasklet */
852 tasklet_init(&brd->helper_tasklet, dgap_poll_tasklet, (unsigned long) brd);
854 /* Log the information about the board */
855 dgap_mbuf(brd, DRVSTR": board %d: %s (rev %d), irq %d\n",
856 dgap_NumBoards, brd->name, brd->rev, brd->irq);
858 DPR_INIT(("dgap_scan(%d) - printing out the msgbuf\n", i));
859 DGAP_LOCK(dgap_global_lock, flags);
861 printk("%s", brd->msgbuf_head);
862 kfree(brd->msgbuf_head);
863 brd->msgbuf_head = NULL;
864 DGAP_UNLOCK(dgap_global_lock, flags);
866 i = dgap_do_remap(brd);
868 brd->state = BOARD_FAILED;
870 brd->state = NEED_RESET;
876 static int dgap_finalize_board_init(struct board_t *brd) {
880 DPR_INIT(("dgap_finalize_board_init() - start\n"));
882 if (!brd || brd->magic != DGAP_BOARD_MAGIC)
885 DPR_INIT(("dgap_finalize_board_init() - start #2\n"));
887 brd->use_interrupts = dgap_config_get_useintr(brd);
890 * Set up our interrupt handler if we are set to do interrupts.
892 if (brd->use_interrupts && brd->irq) {
894 rc = request_irq(brd->irq, dgap_intr, IRQF_SHARED, "DGAP", brd);
897 dgap_mbuf(brd, DRVSTR": Failed to hook IRQ %d. Board will work in poll mode.\n",
914 static int dgap_do_remap(struct board_t *brd)
916 if (!brd || brd->magic != DGAP_BOARD_MAGIC)
919 if (!request_mem_region(brd->membase, 0x200000, "dgap")) {
920 APR(("dgap: mem_region %lx already in use.\n", brd->membase));
924 if (!request_mem_region(brd->membase + PCI_IO_OFFSET, 0x200000, "dgap")) {
925 APR(("dgap: mem_region IO %lx already in use.\n",
926 brd->membase + PCI_IO_OFFSET));
927 release_mem_region(brd->membase, 0x200000);
931 brd->re_map_membase = ioremap(brd->membase, 0x200000);
932 if (!brd->re_map_membase) {
933 APR(("dgap: ioremap mem %lx cannot be mapped.\n", brd->membase));
934 release_mem_region(brd->membase, 0x200000);
935 release_mem_region(brd->membase + PCI_IO_OFFSET, 0x200000);
939 brd->re_map_port = ioremap((brd->membase + PCI_IO_OFFSET), 0x200000);
940 if (!brd->re_map_port) {
941 release_mem_region(brd->membase, 0x200000);
942 release_mem_region(brd->membase + PCI_IO_OFFSET, 0x200000);
943 iounmap(brd->re_map_membase);
944 APR(("dgap: ioremap IO mem %lx cannot be mapped.\n",
945 brd->membase + PCI_IO_OFFSET));
949 DPR_INIT(("remapped io: 0x%p remapped mem: 0x%p\n",
950 brd->re_map_port, brd->re_map_membase));
955 /*****************************************************************************
975 * As each timer expires, it determines (a) whether the "transmit"
976 * waiter needs to be woken up, and (b) whether the poller needs to
979 ******************************************************************************/
981 static void dgap_poll_handler(ulong dummy)
985 unsigned long lock_flags;
986 unsigned long lock_flags2;
993 * If driver needs the config file still,
994 * keep trying to wake up the downloader to
997 if (dgap_driver_state == DRIVER_NEED_CONFIG_LOAD) {
999 * Signal downloader, its got some work to do.
1001 DGAP_LOCK(dgap_dl_lock, lock_flags2);
1002 if (dgap_dl_action != 1) {
1004 wake_up_interruptible(&dgap_dl_wait);
1006 DGAP_UNLOCK(dgap_dl_lock, lock_flags2);
1007 goto schedule_poller;
1010 * Do not start the board state machine until
1011 * driver tells us its up and running, and has
1012 * everything it needs.
1014 else if (dgap_driver_state != DRIVER_READY) {
1015 goto schedule_poller;
1019 * If we have just 1 board, or the system is not SMP,
1020 * then use the typical old style poller.
1021 * Otherwise, use our new tasklet based poller, which should
1022 * speed things up for multiple boards.
1024 if ( (dgap_NumBoards == 1) || (num_online_cpus() <= 1) ) {
1025 for (i = 0; i < dgap_NumBoards; i++) {
1027 brd = dgap_Board[i];
1029 if (brd->state == BOARD_FAILED) {
1032 if (!brd->intr_running) {
1033 /* Call the real board poller directly */
1034 dgap_poll_tasklet((unsigned long) brd);
1039 /* Go thru each board, kicking off a tasklet for each if needed */
1040 for (i = 0; i < dgap_NumBoards; i++) {
1041 brd = dgap_Board[i];
1044 * Attempt to grab the board lock.
1046 * If we can't get it, no big deal, the next poll will get it.
1047 * Basically, I just really don't want to spin in here, because I want
1048 * to kick off my tasklets as fast as I can, and then get out the poller.
1050 if (!spin_trylock(&brd->bd_lock)) {
1054 /* If board is in a failed state, don't bother scheduling a tasklet */
1055 if (brd->state == BOARD_FAILED) {
1056 spin_unlock(&brd->bd_lock);
1060 /* Schedule a poll helper task */
1061 if (!brd->intr_running) {
1062 tasklet_schedule(&brd->helper_tasklet);
1066 * Can't do DGAP_UNLOCK here, as we don't have
1067 * lock_flags because we did a trylock above.
1069 spin_unlock(&brd->bd_lock);
1076 * Schedule ourself back at the nominal wakeup interval.
1078 DGAP_LOCK(dgap_poll_lock, lock_flags );
1079 dgap_poll_time += dgap_jiffies_from_ms(dgap_poll_tick);
1081 new_time = dgap_poll_time - jiffies;
1083 if ((ulong) new_time >= 2 * dgap_poll_tick) {
1084 dgap_poll_time = jiffies + dgap_jiffies_from_ms(dgap_poll_tick);
1087 dgap_poll_timer.function = dgap_poll_handler;
1088 dgap_poll_timer.data = 0;
1089 dgap_poll_timer.expires = dgap_poll_time;
1090 DGAP_UNLOCK(dgap_poll_lock, lock_flags );
1092 if (!dgap_poll_stop)
1093 add_timer(&dgap_poll_timer);
1102 * Driver interrupt handler.
1104 static irqreturn_t dgap_intr(int irq, void *voidbrd)
1106 struct board_t *brd = (struct board_t *) voidbrd;
1109 APR(("Received interrupt (%d) with null board associated\n", irq));
1114 * Check to make sure its for us.
1116 if (brd->magic != DGAP_BOARD_MAGIC) {
1117 APR(("Received interrupt (%d) with a board pointer that wasn't ours!\n", irq));
1124 * Schedule tasklet to run at a better time.
1126 tasklet_schedule(&brd->helper_tasklet);
1132 * dgap_init_globals()
1134 * This is where we initialize the globals from the static insmod
1135 * configuration variables. These are declared near the head of
1138 static void dgap_init_globals(void)
1142 dgap_rawreadok = rawreadok;
1143 dgap_trcbuf_size = trcbuf_size;
1146 for (i = 0; i < MAXBOARDS; i++) {
1147 dgap_Board[i] = NULL;
1150 init_timer( &dgap_poll_timer );
1152 init_waitqueue_head(&dgap_dl_wait);
1157 /************************************************************************
1161 ************************************************************************/
1167 * Used to print to the message buffer during board init.
1169 static void dgap_mbuf(struct board_t *brd, const char *fmt, ...) {
1173 unsigned long flags;
1176 DGAP_LOCK(dgap_global_lock, flags);
1178 /* Format buf using fmt and arguments contained in ap. */
1180 i = vsnprintf(buf, sizeof(buf), fmt, ap);
1185 if (!brd || !brd->msgbuf) {
1187 DGAP_UNLOCK(dgap_global_lock, flags);
1191 length = strlen(buf) + 1;
1192 if (brd->msgbuf - brd->msgbuf_head < length)
1193 length = brd->msgbuf - brd->msgbuf_head;
1194 memcpy(brd->msgbuf, buf, length);
1195 brd->msgbuf += length;
1197 DGAP_UNLOCK(dgap_global_lock, flags);
1204 * Put the driver to sleep for x ms's
1206 * Returns 0 if timed out, !0 (showing signal) if interrupted by a signal.
1208 static int dgap_ms_sleep(ulong ms)
1210 current->state = TASK_INTERRUPTIBLE;
1211 schedule_timeout((ms * HZ) / 1000);
1212 return (signal_pending(current));
1218 * dgap_ioctl_name() : Returns a text version of each ioctl value.
1220 static char *dgap_ioctl_name(int cmd)
1224 case TCGETA: return("TCGETA");
1225 case TCGETS: return("TCGETS");
1226 case TCSETA: return("TCSETA");
1227 case TCSETS: return("TCSETS");
1228 case TCSETAW: return("TCSETAW");
1229 case TCSETSW: return("TCSETSW");
1230 case TCSETAF: return("TCSETAF");
1231 case TCSETSF: return("TCSETSF");
1232 case TCSBRK: return("TCSBRK");
1233 case TCXONC: return("TCXONC");
1234 case TCFLSH: return("TCFLSH");
1235 case TIOCGSID: return("TIOCGSID");
1237 case TIOCGETD: return("TIOCGETD");
1238 case TIOCSETD: return("TIOCSETD");
1239 case TIOCGWINSZ: return("TIOCGWINSZ");
1240 case TIOCSWINSZ: return("TIOCSWINSZ");
1242 case TIOCMGET: return("TIOCMGET");
1243 case TIOCMSET: return("TIOCMSET");
1244 case TIOCMBIS: return("TIOCMBIS");
1245 case TIOCMBIC: return("TIOCMBIC");
1248 case DIGI_SETA: return("DIGI_SETA");
1249 case DIGI_SETAW: return("DIGI_SETAW");
1250 case DIGI_SETAF: return("DIGI_SETAF");
1251 case DIGI_SETFLOW: return("DIGI_SETFLOW");
1252 case DIGI_SETAFLOW: return("DIGI_SETAFLOW");
1253 case DIGI_GETFLOW: return("DIGI_GETFLOW");
1254 case DIGI_GETAFLOW: return("DIGI_GETAFLOW");
1255 case DIGI_GETA: return("DIGI_GETA");
1256 case DIGI_GEDELAY: return("DIGI_GEDELAY");
1257 case DIGI_SEDELAY: return("DIGI_SEDELAY");
1258 case DIGI_GETCUSTOMBAUD: return("DIGI_GETCUSTOMBAUD");
1259 case DIGI_SETCUSTOMBAUD: return("DIGI_SETCUSTOMBAUD");
1260 case TIOCMODG: return("TIOCMODG");
1261 case TIOCMODS: return("TIOCMODS");
1262 case TIOCSDTR: return("TIOCSDTR");
1263 case TIOCCDTR: return("TIOCCDTR");
1265 default: return("unknown");
1269 /************************************************************************
1271 * TTY Initialization/Cleanup Functions
1273 ************************************************************************/
1276 * dgap_tty_preinit()
1278 * Initialize any global tty related data before we download any boards.
1280 static int dgap_tty_preinit(void)
1282 unsigned long flags;
1284 DGAP_LOCK(dgap_global_lock, flags);
1287 * Allocate a buffer for doing the copy from user space to
1288 * kernel space in dgap_input(). We only use one buffer and
1289 * control access to it with a semaphore. If we are paging, we
1290 * are already in trouble so one buffer won't hurt much anyway.
1292 dgap_TmpWriteBuf = kmalloc(WRITEBUFLEN, GFP_ATOMIC);
1294 if (!dgap_TmpWriteBuf) {
1295 DGAP_UNLOCK(dgap_global_lock, flags);
1296 DPR_INIT(("unable to allocate tmp write buf"));
1300 DGAP_UNLOCK(dgap_global_lock, flags);
1306 * dgap_tty_register()
1308 * Init the tty subsystem for this board.
1310 static int dgap_tty_register(struct board_t *brd)
1314 DPR_INIT(("tty_register start"));
1316 brd->SerialDriver = alloc_tty_driver(MAXPORTS);
1318 snprintf(brd->SerialName, MAXTTYNAMELEN, "tty_dgap_%d_", brd->boardnum);
1319 brd->SerialDriver->name = brd->SerialName;
1320 brd->SerialDriver->name_base = 0;
1321 brd->SerialDriver->major = 0;
1322 brd->SerialDriver->minor_start = 0;
1323 brd->SerialDriver->type = TTY_DRIVER_TYPE_SERIAL;
1324 brd->SerialDriver->subtype = SERIAL_TYPE_NORMAL;
1325 brd->SerialDriver->init_termios = DgapDefaultTermios;
1326 brd->SerialDriver->driver_name = DRVSTR;
1327 brd->SerialDriver->flags = (TTY_DRIVER_REAL_RAW | TTY_DRIVER_DYNAMIC_DEV | TTY_DRIVER_HARDWARE_BREAK);
1329 /* The kernel wants space to store pointers to tty_structs */
1330 brd->SerialDriver->ttys = kzalloc(MAXPORTS * sizeof(struct tty_struct *), GFP_KERNEL);
1331 if (!brd->SerialDriver->ttys)
1335 * Entry points for driver. Called by the kernel from
1336 * tty_io.c and n_tty.c.
1338 tty_set_operations(brd->SerialDriver, &dgap_tty_ops);
1341 * If we're doing transparent print, we have to do all of the above
1342 * again, separately so we don't get the LD confused about what major
1343 * we are when we get into the dgap_tty_open() routine.
1345 brd->PrintDriver = alloc_tty_driver(MAXPORTS);
1347 snprintf(brd->PrintName, MAXTTYNAMELEN, "pr_dgap_%d_", brd->boardnum);
1348 brd->PrintDriver->name = brd->PrintName;
1349 brd->PrintDriver->name_base = 0;
1350 brd->PrintDriver->major = 0;
1351 brd->PrintDriver->minor_start = 0;
1352 brd->PrintDriver->type = TTY_DRIVER_TYPE_SERIAL;
1353 brd->PrintDriver->subtype = SERIAL_TYPE_NORMAL;
1354 brd->PrintDriver->init_termios = DgapDefaultTermios;
1355 brd->PrintDriver->driver_name = DRVSTR;
1356 brd->PrintDriver->flags = (TTY_DRIVER_REAL_RAW | TTY_DRIVER_DYNAMIC_DEV | TTY_DRIVER_HARDWARE_BREAK);
1358 /* The kernel wants space to store pointers to tty_structs */
1359 brd->PrintDriver->ttys = kzalloc(MAXPORTS * sizeof(struct tty_struct *), GFP_KERNEL);
1360 if (!brd->PrintDriver->ttys)
1364 * Entry points for driver. Called by the kernel from
1365 * tty_io.c and n_tty.c.
1367 tty_set_operations(brd->PrintDriver, &dgap_tty_ops);
1369 if (!brd->dgap_Major_Serial_Registered) {
1370 /* Register tty devices */
1371 rc = tty_register_driver(brd->SerialDriver);
1373 APR(("Can't register tty device (%d)\n", rc));
1376 brd->dgap_Major_Serial_Registered = TRUE;
1377 dgap_BoardsByMajor[brd->SerialDriver->major] = brd;
1378 brd->dgap_Serial_Major = brd->SerialDriver->major;
1381 if (!brd->dgap_Major_TransparentPrint_Registered) {
1382 /* Register Transparent Print devices */
1383 rc = tty_register_driver(brd->PrintDriver);
1385 APR(("Can't register Transparent Print device (%d)\n", rc));
1388 brd->dgap_Major_TransparentPrint_Registered = TRUE;
1389 dgap_BoardsByMajor[brd->PrintDriver->major] = brd;
1390 brd->dgap_TransparentPrint_Major = brd->PrintDriver->major;
1393 DPR_INIT(("DGAP REGISTER TTY: MAJORS: %d %d\n", brd->SerialDriver->major,
1394 brd->PrintDriver->major));
1403 * Init the tty subsystem. Called once per board after board has been
1404 * downloaded and init'ed.
1406 static int dgap_tty_init(struct board_t *brd)
1410 uint true_count = 0;
1413 struct channel_t *ch;
1420 DPR_INIT(("dgap_tty_init start\n"));
1423 * Initialize board structure elements.
1426 vaddr = brd->re_map_membase;
1427 true_count = readw((vaddr + NCHAN));
1429 brd->nasync = dgap_config_get_number_of_ports(brd);
1432 brd->nasync = brd->maxports;
1435 if (brd->nasync > brd->maxports) {
1436 brd->nasync = brd->maxports;
1439 if (true_count != brd->nasync) {
1440 if ((brd->type == PPCM) && (true_count == 64)) {
1441 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",
1442 brd->name, brd->nasync, true_count));
1444 else if ((brd->type == PPCM) && (true_count == 0)) {
1445 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",
1446 brd->name, brd->nasync, true_count));
1449 APR(("***WARNING**** %s configured for %d ports, has %d ports.\n",
1450 brd->name, brd->nasync, true_count));
1453 brd->nasync = true_count;
1455 /* If no ports, don't bother going any further */
1457 brd->state = BOARD_FAILED;
1458 brd->dpastatus = BD_NOFEP;
1464 * Allocate channel memory that might not have been allocated
1465 * when the driver was first loaded.
1467 for (i = 0; i < brd->nasync; i++) {
1468 if (!brd->channels[i]) {
1469 brd->channels[i] = kzalloc(sizeof(struct channel_t), GFP_ATOMIC);
1470 if (!brd->channels[i]) {
1471 DPR_CORE(("%s:%d Unable to allocate memory for channel struct\n",
1472 __FILE__, __LINE__));
1477 ch = brd->channels[0];
1478 vaddr = brd->re_map_membase;
1480 bs = (struct bs_t *) ((ulong) vaddr + CHANBUF);
1481 cm = (struct cm_t *) ((ulong) vaddr + CMDBUF);
1485 /* Set up channel variables */
1486 for (i = 0; i < brd->nasync; i++, ch = brd->channels[i], bs++) {
1488 if (!brd->channels[i])
1491 DGAP_SPINLOCK_INIT(ch->ch_lock);
1493 /* Store all our magic numbers */
1494 ch->magic = DGAP_CHANNEL_MAGIC;
1495 ch->ch_tun.magic = DGAP_UNIT_MAGIC;
1496 ch->ch_tun.un_type = DGAP_SERIAL;
1497 ch->ch_tun.un_ch = ch;
1498 ch->ch_tun.un_dev = i;
1500 ch->ch_pun.magic = DGAP_UNIT_MAGIC;
1501 ch->ch_pun.un_type = DGAP_PRINT;
1502 ch->ch_pun.un_ch = ch;
1503 ch->ch_pun.un_dev = i;
1505 ch->ch_vaddr = vaddr;
1510 ch->ch_digi = dgap_digi_init;
1513 * Set up digi dsr and dcd bits based on altpin flag.
1515 if (dgap_config_get_altpin(brd)) {
1518 ch->ch_digi.digi_flags |= DIGI_ALTPIN;
1522 ch->ch_dsr = DM_DSR;
1525 ch->ch_taddr = vaddr + ((ch->ch_bs->tx_seg) << 4);
1526 ch->ch_raddr = vaddr + ((ch->ch_bs->rx_seg) << 4);
1529 ch->ch_tsize = readw(&(ch->ch_bs->tx_max)) + 1;
1530 ch->ch_rsize = readw(&(ch->ch_bs->rx_max)) + 1;
1534 /* .25 second delay */
1535 ch->ch_close_delay = 250;
1538 * Set queue water marks, interrupt mask,
1539 * and general tty parameters.
1541 ch->ch_tlw = tlw = ch->ch_tsize >= 2000 ? ((ch->ch_tsize * 5) / 8) : ch->ch_tsize / 2;
1543 dgap_cmdw(ch, STLOW, tlw, 0);
1545 dgap_cmdw(ch, SRLOW, ch->ch_rsize / 2, 0);
1547 dgap_cmdw(ch, SRHIGH, 7 * ch->ch_rsize / 8, 0);
1549 ch->ch_mistat = readb(&(ch->ch_bs->m_stat));
1551 init_waitqueue_head(&ch->ch_flags_wait);
1552 init_waitqueue_head(&ch->ch_tun.un_flags_wait);
1553 init_waitqueue_head(&ch->ch_pun.un_flags_wait);
1554 init_waitqueue_head(&ch->ch_sniff_wait);
1556 /* Turn on all modem interrupts for now */
1557 modem = (DM_CD | DM_DSR | DM_CTS | DM_RI);
1558 writeb(modem, &(ch->ch_bs->m_int));
1561 * Set edelay to 0 if interrupts are turned on,
1562 * otherwise set edelay to the usual 100.
1565 writew(0, &(ch->ch_bs->edelay));
1567 writew(100, &(ch->ch_bs->edelay));
1569 writeb(1, &(ch->ch_bs->idata));
1573 DPR_INIT(("dgap_tty_init finish\n"));
1580 * dgap_tty_post_uninit()
1582 * UnInitialize any global tty related data.
1584 static void dgap_tty_post_uninit(void)
1586 kfree(dgap_TmpWriteBuf);
1587 dgap_TmpWriteBuf = NULL;
1594 * Uninitialize the TTY portion of this driver. Free all memory and
1597 static void dgap_tty_uninit(struct board_t *brd)
1601 if (brd->dgap_Major_Serial_Registered) {
1602 dgap_BoardsByMajor[brd->SerialDriver->major] = NULL;
1603 brd->dgap_Serial_Major = 0;
1604 for (i = 0; i < brd->nasync; i++) {
1605 dgap_remove_tty_sysfs(brd->channels[i]->ch_tun.un_sysfs);
1606 tty_unregister_device(brd->SerialDriver, i);
1608 tty_unregister_driver(brd->SerialDriver);
1609 kfree(brd->SerialDriver->ttys);
1610 brd->SerialDriver->ttys = NULL;
1611 put_tty_driver(brd->SerialDriver);
1612 brd->dgap_Major_Serial_Registered = FALSE;
1615 if (brd->dgap_Major_TransparentPrint_Registered) {
1616 dgap_BoardsByMajor[brd->PrintDriver->major] = NULL;
1617 brd->dgap_TransparentPrint_Major = 0;
1618 for (i = 0; i < brd->nasync; i++) {
1619 dgap_remove_tty_sysfs(brd->channels[i]->ch_pun.un_sysfs);
1620 tty_unregister_device(brd->PrintDriver, i);
1622 tty_unregister_driver(brd->PrintDriver);
1623 kfree(brd->PrintDriver->ttys);
1624 brd->PrintDriver->ttys = NULL;
1625 put_tty_driver(brd->PrintDriver);
1626 brd->dgap_Major_TransparentPrint_Registered = FALSE;
1631 #define TMPBUFLEN (1024)
1634 * dgap_sniff - Dump data out to the "sniff" buffer if the
1635 * proc sniff file is opened...
1637 static void dgap_sniff_nowait_nolock(struct channel_t *ch, uchar *text, uchar *buf, int len)
1645 char tmpbuf[TMPBUFLEN];
1649 /* Leave if sniff not open */
1650 if (!(ch->ch_sniff_flags & SNIFF_OPEN))
1653 do_gettimeofday(&tv);
1655 /* Create our header for data dump */
1656 p += sprintf(p, "<%ld %ld><%s><", tv.tv_sec, tv.tv_usec, text);
1657 tmpbuflen = p - tmpbuf;
1662 for (i = 0; i < len && tmpbuflen < (TMPBUFLEN - 4); i++) {
1663 p += sprintf(p, "%02x ", *buf);
1665 tmpbuflen = p - tmpbuf;
1668 if (tmpbuflen < (TMPBUFLEN - 4)) {
1670 p += sprintf(p - 1, "%s\n", ">");
1672 p += sprintf(p, "%s\n", ">");
1678 nbuf = strlen(tmpbuf);
1682 * Loop while data remains.
1684 while (nbuf > 0 && ch->ch_sniff_buf) {
1686 * Determine the amount of available space left in the
1687 * buffer. If there's none, wait until some appears.
1689 n = (ch->ch_sniff_out - ch->ch_sniff_in - 1) & SNIFF_MASK;
1692 * If there is no space left to write to in our sniff buffer,
1693 * we have no choice but to drop the data.
1694 * We *cannot* sleep here waiting for space, because this
1695 * function was probably called by the interrupt/timer routines!
1702 * Copy as much data as will fit.
1708 r = SNIFF_MAX - ch->ch_sniff_in;
1711 memcpy(ch->ch_sniff_buf + ch->ch_sniff_in, p, r);
1714 ch->ch_sniff_in = 0;
1719 memcpy(ch->ch_sniff_buf + ch->ch_sniff_in, p, n);
1721 ch->ch_sniff_in += n;
1726 * Wakeup any thread waiting for data
1728 if (ch->ch_sniff_flags & SNIFF_WAIT_DATA) {
1729 ch->ch_sniff_flags &= ~SNIFF_WAIT_DATA;
1730 wake_up_interruptible(&ch->ch_sniff_wait);
1735 * If the user sent us too much data to push into our tmpbuf,
1736 * we need to keep looping around on all the data.
1738 if (too_much_data) {
1743 } while (too_much_data);
1747 /*=======================================================================
1749 * dgap_input - Process received data.
1751 * ch - Pointer to channel structure.
1753 *=======================================================================*/
1755 static void dgap_input(struct channel_t *ch)
1759 struct tty_struct *tp;
1760 struct tty_ldisc *ld;
1774 if (!ch || ch->magic != DGAP_CHANNEL_MAGIC)
1777 tp = ch->ch_tun.un_tty;
1785 if(!bd || bd->magic != DGAP_BOARD_MAGIC)
1788 DPR_READ(("dgap_input start\n"));
1790 DGAP_LOCK(bd->bd_lock, lock_flags);
1791 DGAP_LOCK(ch->ch_lock, lock_flags2);
1794 * Figure the number of characters in the buffer.
1795 * Exit immediately if none.
1798 rmask = ch->ch_rsize - 1;
1800 head = readw(&(bs->rx_head));
1802 tail = readw(&(bs->rx_tail));
1805 data_len = (head - tail) & rmask;
1807 if (data_len == 0) {
1808 writeb(1, &(bs->idata));
1809 DGAP_UNLOCK(ch->ch_lock, lock_flags2);
1810 DGAP_UNLOCK(bd->bd_lock, lock_flags);
1811 DPR_READ(("No data on port %d\n", ch->ch_portnum));
1816 * If the device is not open, or CREAD is off, flush
1817 * input data and return immediately.
1819 if ((bd->state != BOARD_READY) || !tp || (tp->magic != TTY_MAGIC) ||
1820 !(ch->ch_tun.un_flags & UN_ISOPEN) || !(tp->termios.c_cflag & CREAD) ||
1821 (ch->ch_tun.un_flags & UN_CLOSING)) {
1823 DPR_READ(("input. dropping %d bytes on port %d...\n", data_len, ch->ch_portnum));
1824 DPR_READ(("input. tp: %p tp->magic: %x MAGIC:%x ch flags: %x\n",
1825 tp, tp ? tp->magic : 0, TTY_MAGIC, ch->ch_tun.un_flags));
1826 writew(head, &(bs->rx_tail));
1827 writeb(1, &(bs->idata));
1828 DGAP_UNLOCK(ch->ch_lock, lock_flags2);
1829 DGAP_UNLOCK(bd->bd_lock, lock_flags);
1834 * If we are throttled, simply don't read any data.
1836 if (ch->ch_flags & CH_RXBLOCK) {
1837 writeb(1, &(bs->idata));
1838 DGAP_UNLOCK(ch->ch_lock, lock_flags2);
1839 DGAP_UNLOCK(bd->bd_lock, lock_flags);
1840 DPR_READ(("Port %d throttled, not reading any data. head: %x tail: %x\n",
1841 ch->ch_portnum, head, tail));
1848 tmpchar = readb(&(bs->orun));
1850 ch->ch_err_overrun++;
1851 writeb(0, &(bs->orun));
1854 DPR_READ(("dgap_input start 2\n"));
1856 /* Decide how much data we can send into the tty layer */
1857 flip_len = TTY_FLIPBUF_SIZE;
1859 /* Chop down the length, if needed */
1860 len = min(data_len, flip_len);
1861 len = min(len, (N_TTY_BUF_SIZE - 1));
1863 ld = tty_ldisc_ref(tp);
1865 #ifdef TTY_DONT_FLIP
1867 * If the DONT_FLIP flag is on, don't flush our buffer, and act
1868 * like the ld doesn't have any space to put the data right now.
1870 if (test_bit(TTY_DONT_FLIP, &tp->flags))
1875 * If we were unable to get a reference to the ld,
1876 * don't flush our buffer, and act like the ld doesn't
1877 * have any space to put the data right now.
1883 * If ld doesn't have a pointer to a receive_buf function,
1884 * flush the data, then act like the ld doesn't have any
1885 * space to put the data right now.
1887 if (!ld->ops->receive_buf) {
1888 writew(head, &(bs->rx_tail));
1894 writeb(1, &(bs->idata));
1895 DGAP_UNLOCK(ch->ch_lock, lock_flags2);
1896 DGAP_UNLOCK(bd->bd_lock, lock_flags);
1897 DPR_READ(("dgap_input 1 - finish\n"));
1899 tty_ldisc_deref(ld);
1903 buf = ch->ch_bd->flipbuf;
1907 * n now contains the most amount of data we can copy,
1908 * bounded either by our buffer size or the amount
1909 * of data the card actually has pending...
1913 s = ((head >= tail) ? head : ch->ch_rsize) - tail;
1919 memcpy_fromio(buf, (char *) ch->ch_raddr + tail, s);
1920 dgap_sniff_nowait_nolock(ch, "USER READ", buf, s);
1926 /* Flip queue if needed */
1930 writew(tail, &(bs->rx_tail));
1931 writeb(1, &(bs->idata));
1932 ch->ch_rxcount += len;
1935 * If we are completely raw, we don't need to go through a lot
1936 * of the tty layers that exist.
1937 * In this case, we take the shortest and fastest route we
1938 * can to relay the data to the user.
1940 * On the other hand, if we are not raw, we need to go through
1941 * the tty layer, which has its API more well defined.
1943 if (I_PARMRK(tp) || I_BRKINT(tp) || I_INPCK(tp)) {
1944 dgap_parity_scan(ch, ch->ch_bd->flipbuf, ch->ch_bd->flipflagbuf, &len);
1946 len = tty_buffer_request_room(tp->port, len);
1947 tty_insert_flip_string_flags(tp->port, ch->ch_bd->flipbuf,
1948 ch->ch_bd->flipflagbuf, len);
1951 len = tty_buffer_request_room(tp->port, len);
1952 tty_insert_flip_string(tp->port, ch->ch_bd->flipbuf, len);
1955 DGAP_UNLOCK(ch->ch_lock, lock_flags2);
1956 DGAP_UNLOCK(bd->bd_lock, lock_flags);
1958 /* Tell the tty layer its okay to "eat" the data now */
1959 tty_flip_buffer_push(tp->port);
1962 tty_ldisc_deref(ld);
1964 DPR_READ(("dgap_input - finish\n"));
1968 /************************************************************************
1969 * Determines when CARRIER changes state and takes appropriate
1971 ************************************************************************/
1972 static void dgap_carrier(struct channel_t *ch)
1976 int virt_carrier = 0;
1977 int phys_carrier = 0;
1979 DPR_CARR(("dgap_carrier called...\n"));
1981 if (!ch || ch->magic != DGAP_CHANNEL_MAGIC)
1986 if (!bd || bd->magic != DGAP_BOARD_MAGIC)
1989 /* Make sure altpin is always set correctly */
1990 if (ch->ch_digi.digi_flags & DIGI_ALTPIN) {
1995 ch->ch_dsr = DM_DSR;
1999 if (ch->ch_mistat & D_CD(ch)) {
2000 DPR_CARR(("mistat: %x D_CD: %x\n", ch->ch_mistat, D_CD(ch)));
2004 if (ch->ch_digi.digi_flags & DIGI_FORCEDCD) {
2008 if (ch->ch_c_cflag & CLOCAL) {
2013 DPR_CARR(("DCD: physical: %d virt: %d\n", phys_carrier, virt_carrier));
2016 * Test for a VIRTUAL carrier transition to HIGH.
2018 if (((ch->ch_flags & CH_FCAR) == 0) && (virt_carrier == 1)) {
2021 * When carrier rises, wake any threads waiting
2022 * for carrier in the open routine.
2025 DPR_CARR(("carrier: virt DCD rose\n"));
2027 if (waitqueue_active(&(ch->ch_flags_wait)))
2028 wake_up_interruptible(&ch->ch_flags_wait);
2032 * Test for a PHYSICAL carrier transition to HIGH.
2034 if (((ch->ch_flags & CH_CD) == 0) && (phys_carrier == 1)) {
2037 * When carrier rises, wake any threads waiting
2038 * for carrier in the open routine.
2041 DPR_CARR(("carrier: physical DCD rose\n"));
2043 if (waitqueue_active(&(ch->ch_flags_wait)))
2044 wake_up_interruptible(&ch->ch_flags_wait);
2048 * Test for a PHYSICAL transition to low, so long as we aren't
2049 * currently ignoring physical transitions (which is what "virtual
2050 * carrier" indicates).
2052 * The transition of the virtual carrier to low really doesn't
2053 * matter... it really only means "ignore carrier state", not
2054 * "make pretend that carrier is there".
2056 if ((virt_carrier == 0) && ((ch->ch_flags & CH_CD) != 0) &&
2057 (phys_carrier == 0))
2061 * When carrier drops:
2063 * Drop carrier on all open units.
2065 * Flush queues, waking up any task waiting in the
2068 * Send a hangup to the control terminal.
2070 * Enable all select calls.
2072 if (waitqueue_active(&(ch->ch_flags_wait)))
2073 wake_up_interruptible(&ch->ch_flags_wait);
2075 if (ch->ch_tun.un_open_count > 0) {
2076 DPR_CARR(("Sending tty hangup\n"));
2077 tty_hangup(ch->ch_tun.un_tty);
2080 if (ch->ch_pun.un_open_count > 0) {
2081 DPR_CARR(("Sending pr hangup\n"));
2082 tty_hangup(ch->ch_pun.un_tty);
2087 * Make sure that our cached values reflect the current reality.
2089 if (virt_carrier == 1)
2090 ch->ch_flags |= CH_FCAR;
2092 ch->ch_flags &= ~CH_FCAR;
2094 if (phys_carrier == 1)
2095 ch->ch_flags |= CH_CD;
2097 ch->ch_flags &= ~CH_CD;
2101 /************************************************************************
2103 * TTY Entry points and helper functions
2105 ************************************************************************/
2111 static int dgap_tty_open(struct tty_struct *tty, struct file *file)
2113 struct board_t *brd;
2114 struct channel_t *ch;
2126 major = MAJOR(tty_devnum(tty));
2127 minor = MINOR(tty_devnum(tty));
2133 /* Get board pointer from our array of majors we have allocated */
2134 brd = dgap_BoardsByMajor[major];
2140 * If board is not yet up to a state of READY, go to
2141 * sleep waiting for it to happen or they cancel the open.
2143 rc = wait_event_interruptible(brd->state_wait,
2144 (brd->state & BOARD_READY));
2150 DGAP_LOCK(brd->bd_lock, lock_flags);
2152 /* The wait above should guarantee this cannot happen */
2153 if (brd->state != BOARD_READY) {
2154 DGAP_UNLOCK(brd->bd_lock, lock_flags);
2158 /* If opened device is greater than our number of ports, bail. */
2159 if (MINOR(tty_devnum(tty)) > brd->nasync) {
2160 DGAP_UNLOCK(brd->bd_lock, lock_flags);
2164 ch = brd->channels[minor];
2166 DGAP_UNLOCK(brd->bd_lock, lock_flags);
2170 /* Grab channel lock */
2171 DGAP_LOCK(ch->ch_lock, lock_flags2);
2173 /* Figure out our type */
2174 if (major == brd->dgap_Serial_Major) {
2175 un = &brd->channels[minor]->ch_tun;
2176 un->un_type = DGAP_SERIAL;
2178 else if (major == brd->dgap_TransparentPrint_Major) {
2179 un = &brd->channels[minor]->ch_pun;
2180 un->un_type = DGAP_PRINT;
2183 DGAP_UNLOCK(ch->ch_lock, lock_flags2);
2184 DGAP_UNLOCK(brd->bd_lock, lock_flags);
2185 DPR_OPEN(("%d Unknown TYPE!\n", __LINE__));
2189 /* Store our unit into driver_data, so we always have it available. */
2190 tty->driver_data = un;
2192 DPR_OPEN(("Open called. MAJOR: %d MINOR:%d unit: %p NAME: %s\n",
2193 MAJOR(tty_devnum(tty)), MINOR(tty_devnum(tty)), un, brd->name));
2196 * Error if channel info pointer is NULL.
2200 DGAP_UNLOCK(ch->ch_lock, lock_flags2);
2201 DGAP_UNLOCK(brd->bd_lock, lock_flags);
2202 DPR_OPEN(("%d BS is 0!\n", __LINE__));
2206 DPR_OPEN(("%d: tflag=%x pflag=%x\n", __LINE__, ch->ch_tun.un_flags, ch->ch_pun.un_flags));
2211 if (!(un->un_flags & UN_ISOPEN)) {
2212 /* Store important variables. */
2215 /* Maybe do something here to the TTY struct as well? */
2219 * Initialize if neither terminal or printer is open.
2221 if (!((ch->ch_tun.un_flags | ch->ch_pun.un_flags) & UN_ISOPEN)) {
2223 DPR_OPEN(("dgap_open: initializing channel in open...\n"));
2229 * Flush input queue.
2231 head = readw(&(bs->rx_head));
2232 writew(head, &(bs->rx_tail));
2235 ch->pscan_state = 0;
2236 ch->pscan_savechar = 0;
2238 ch->ch_c_cflag = tty->termios.c_cflag;
2239 ch->ch_c_iflag = tty->termios.c_iflag;
2240 ch->ch_c_oflag = tty->termios.c_oflag;
2241 ch->ch_c_lflag = tty->termios.c_lflag;
2242 ch->ch_startc = tty->termios.c_cc[VSTART];
2243 ch->ch_stopc = tty->termios.c_cc[VSTOP];
2245 /* TODO: flush our TTY struct here? */
2250 * Run param in case we changed anything
2255 * follow protocol for opening port
2258 DGAP_UNLOCK(ch->ch_lock, lock_flags2);
2259 DGAP_UNLOCK(brd->bd_lock, lock_flags);
2261 rc = dgap_block_til_ready(tty, file, ch);
2268 DPR_OPEN(("dgap_tty_open returning after dgap_block_til_ready "
2272 /* No going back now, increment our unit and channel counters */
2273 DGAP_LOCK(ch->ch_lock, lock_flags);
2274 ch->ch_open_count++;
2275 un->un_open_count++;
2276 un->un_flags |= (UN_ISOPEN);
2277 DGAP_UNLOCK(ch->ch_lock, lock_flags);
2279 DPR_OPEN(("dgap_tty_open finished\n"));
2285 * dgap_block_til_ready()
2287 * Wait for DCD, if needed.
2289 static int dgap_block_til_ready(struct tty_struct *tty, struct file *file, struct channel_t *ch)
2292 struct un_t *un = NULL;
2295 int sleep_on_un_flags = 0;
2297 if (!tty || tty->magic != TTY_MAGIC || !file || !ch || ch->magic != DGAP_CHANNEL_MAGIC) {
2301 un = tty->driver_data;
2302 if (!un || un->magic != DGAP_UNIT_MAGIC) {
2306 DPR_OPEN(("dgap_block_til_ready - before block.\n"));
2308 DGAP_LOCK(ch->ch_lock, lock_flags);
2315 sleep_on_un_flags = 0;
2318 * If board has failed somehow during our sleep, bail with error.
2320 if (ch->ch_bd->state == BOARD_FAILED) {
2325 /* If tty was hung up, break out of loop and set error. */
2326 if (tty_hung_up_p(file)) {
2332 * If either unit is in the middle of the fragile part of close,
2333 * we just cannot touch the channel safely.
2334 * Go back to sleep, knowing that when the channel can be
2335 * touched safely, the close routine will signal the
2336 * ch_wait_flags to wake us back up.
2338 if (!((ch->ch_tun.un_flags | ch->ch_pun.un_flags) & UN_CLOSING)) {
2341 * Our conditions to leave cleanly and happily:
2342 * 1) NONBLOCKING on the tty is set.
2344 * 3) DCD (fake or real) is active.
2347 if (file->f_flags & O_NONBLOCK) {
2351 if (tty->flags & (1 << TTY_IO_ERROR)) {
2355 if (ch->ch_flags & CH_CD) {
2356 DPR_OPEN(("%d: ch_flags: %x\n", __LINE__, ch->ch_flags));
2360 if (ch->ch_flags & CH_FCAR) {
2361 DPR_OPEN(("%d: ch_flags: %x\n", __LINE__, ch->ch_flags));
2366 sleep_on_un_flags = 1;
2370 * If there is a signal pending, the user probably
2371 * interrupted (ctrl-c) us.
2372 * Leave loop with error set.
2374 if (signal_pending(current)) {
2375 DPR_OPEN(("%d: signal pending...\n", __LINE__));
2376 retval = -ERESTARTSYS;
2380 DPR_OPEN(("dgap_block_til_ready - blocking.\n"));
2383 * Store the flags before we let go of channel lock
2385 if (sleep_on_un_flags)
2386 old_flags = ch->ch_tun.un_flags | ch->ch_pun.un_flags;
2388 old_flags = ch->ch_flags;
2391 * Let go of channel lock before calling schedule.
2392 * Our poller will get any FEP events and wake us up when DCD
2393 * eventually goes active.
2396 DGAP_UNLOCK(ch->ch_lock, lock_flags);
2398 DPR_OPEN(("Going to sleep on %s flags...\n",
2399 (sleep_on_un_flags ? "un" : "ch")));
2402 * Wait for something in the flags to change from the current value.
2404 if (sleep_on_un_flags) {
2405 retval = wait_event_interruptible(un->un_flags_wait,
2406 (old_flags != (ch->ch_tun.un_flags | ch->ch_pun.un_flags)));
2409 retval = wait_event_interruptible(ch->ch_flags_wait,
2410 (old_flags != ch->ch_flags));
2413 DPR_OPEN(("After sleep... retval: %x\n", retval));
2416 * We got woken up for some reason.
2417 * Before looping around, grab our channel lock.
2419 DGAP_LOCK(ch->ch_lock, lock_flags);
2424 DGAP_UNLOCK(ch->ch_lock, lock_flags);
2426 DPR_OPEN(("dgap_block_til_ready - after blocking.\n"));
2429 DPR_OPEN(("dgap_block_til_ready - done. error. retval: %x\n", retval));
2433 DPR_OPEN(("dgap_block_til_ready - done no error. jiffies: %lu\n", jiffies));
2442 * Hangup the port. Like a close, but don't wait for output to drain.
2444 static void dgap_tty_hangup(struct tty_struct *tty)
2447 struct channel_t *ch;
2450 if (!tty || tty->magic != TTY_MAGIC)
2453 un = tty->driver_data;
2454 if (!un || un->magic != DGAP_UNIT_MAGIC)
2458 if (!ch || ch->magic != DGAP_CHANNEL_MAGIC)
2462 if (!bd || bd->magic != DGAP_BOARD_MAGIC)
2465 DPR_CLOSE(("dgap_hangup called. ch->ch_open_count: %d un->un_open_count: %d\n",
2466 ch->ch_open_count, un->un_open_count));
2468 /* flush the transmit queues */
2469 dgap_tty_flush_buffer(tty);
2471 DPR_CLOSE(("dgap_hangup finished. ch->ch_open_count: %d un->un_open_count: %d\n",
2472 ch->ch_open_count, un->un_open_count));
2481 static void dgap_tty_close(struct tty_struct *tty, struct file *file)
2483 struct ktermios *ts;
2485 struct channel_t *ch;
2490 if (!tty || tty->magic != TTY_MAGIC)
2493 un = tty->driver_data;
2494 if (!un || un->magic != DGAP_UNIT_MAGIC)
2498 if (!ch || ch->magic != DGAP_CHANNEL_MAGIC)
2502 if (!bd || bd->magic != DGAP_BOARD_MAGIC)
2507 DPR_CLOSE(("Close called\n"));
2509 DGAP_LOCK(ch->ch_lock, lock_flags);
2512 * Determine if this is the last close or not - and if we agree about
2513 * which type of close it is with the Line Discipline
2515 if ((tty->count == 1) && (un->un_open_count != 1)) {
2517 * Uh, oh. tty->count is 1, which means that the tty
2518 * structure will be freed. un_open_count should always
2519 * be one in these conditions. If it's greater than
2520 * one, we've got real problems, since it means the
2521 * serial port won't be shutdown.
2523 APR(("tty->count is 1, un open count is %d\n", un->un_open_count));
2524 un->un_open_count = 1;
2527 if (--un->un_open_count < 0) {
2528 APR(("bad serial port open count of %d\n", un->un_open_count));
2529 un->un_open_count = 0;
2532 ch->ch_open_count--;
2534 if (ch->ch_open_count && un->un_open_count) {
2535 DPR_CLOSE(("dgap_tty_close: not last close ch: %d un:%d\n",
2536 ch->ch_open_count, un->un_open_count));
2538 DGAP_UNLOCK(ch->ch_lock, lock_flags);
2542 /* OK, its the last close on the unit */
2543 DPR_CLOSE(("dgap_tty_close - last close on unit procedures\n"));
2545 un->un_flags |= UN_CLOSING;
2550 * Only officially close channel if count is 0 and
2551 * DIGI_PRINTER bit is not set.
2553 if ((ch->ch_open_count == 0) && !(ch->ch_digi.digi_flags & DIGI_PRINTER)) {
2555 ch->ch_flags &= ~(CH_RXBLOCK);
2557 DGAP_UNLOCK(ch->ch_lock, lock_flags);
2559 /* wait for output to drain */
2560 /* This will also return if we take an interrupt */
2562 DPR_CLOSE(("Calling wait_for_drain\n"));
2563 rc = dgap_wait_for_drain(tty);
2564 DPR_CLOSE(("After calling wait_for_drain\n"));
2567 DPR_BASIC(("dgap_tty_close - bad return: %d ", rc));
2570 dgap_tty_flush_buffer(tty);
2571 tty_ldisc_flush(tty);
2573 DGAP_LOCK(ch->ch_lock, lock_flags);
2578 * If we have HUPCL set, lower DTR and RTS
2580 if (ch->ch_c_cflag & HUPCL ) {
2581 DPR_CLOSE(("Close. HUPCL set, dropping DTR/RTS\n"));
2582 ch->ch_mostat &= ~(D_RTS(ch)|D_DTR(ch));
2583 dgap_cmdb( ch, SMODEM, 0, D_DTR(ch)|D_RTS(ch), 0 );
2586 * Go to sleep to ensure RTS/DTR
2587 * have been dropped for modems to see it.
2589 if (ch->ch_close_delay) {
2590 DPR_CLOSE(("Close. Sleeping for RTS/DTR drop\n"));
2592 DGAP_UNLOCK(ch->ch_lock, lock_flags);
2593 dgap_ms_sleep(ch->ch_close_delay);
2594 DGAP_LOCK(ch->ch_lock, lock_flags);
2596 DPR_CLOSE(("Close. After sleeping for RTS/DTR drop\n"));
2600 ch->pscan_state = 0;
2601 ch->pscan_savechar = 0;
2602 ch->ch_baud_info = 0;
2607 * turn off print device when closing print device.
2609 if ((un->un_type == DGAP_PRINT) && (ch->ch_flags & CH_PRON) ) {
2610 dgap_wmove(ch, ch->ch_digi.digi_offstr,
2611 (int) ch->ch_digi.digi_offlen);
2612 ch->ch_flags &= ~CH_PRON;
2616 un->un_flags &= ~(UN_ISOPEN | UN_CLOSING);
2617 tty->driver_data = NULL;
2619 DPR_CLOSE(("Close. Doing wakeups\n"));
2620 wake_up_interruptible(&ch->ch_flags_wait);
2621 wake_up_interruptible(&un->un_flags_wait);
2623 DGAP_UNLOCK(ch->ch_lock, lock_flags);
2625 DPR_BASIC(("dgap_tty_close - complete\n"));
2630 * dgap_tty_chars_in_buffer()
2632 * Return number of characters that have not been transmitted yet.
2634 * This routine is used by the line discipline to determine if there
2635 * is data waiting to be transmitted/drained/flushed or not.
2637 static int dgap_tty_chars_in_buffer(struct tty_struct *tty)
2639 struct board_t *bd = NULL;
2640 struct channel_t *ch = NULL;
2641 struct un_t *un = NULL;
2642 struct bs_t *bs = NULL;
2645 u16 thead, ttail, tmask, chead, ctail;
2646 ulong lock_flags = 0;
2647 ulong lock_flags2 = 0;
2652 un = tty->driver_data;
2653 if (!un || un->magic != DGAP_UNIT_MAGIC)
2657 if (!ch || ch->magic != DGAP_CHANNEL_MAGIC)
2661 if (!bd || bd->magic != DGAP_BOARD_MAGIC)
2668 DGAP_LOCK(bd->bd_lock, lock_flags);
2669 DGAP_LOCK(ch->ch_lock, lock_flags2);
2671 tmask = (ch->ch_tsize - 1);
2673 /* Get Transmit queue pointers */
2674 thead = readw(&(bs->tx_head)) & tmask;
2675 ttail = readw(&(bs->tx_tail)) & tmask;
2677 /* Get tbusy flag */
2678 tbusy = readb(&(bs->tbusy));
2680 /* Get Command queue pointers */
2681 chead = readw(&(ch->ch_cm->cm_head));
2682 ctail = readw(&(ch->ch_cm->cm_tail));
2684 DGAP_UNLOCK(ch->ch_lock, lock_flags2);
2685 DGAP_UNLOCK(bd->bd_lock, lock_flags);
2688 * The only way we know for sure if there is no pending
2689 * data left to be transferred, is if:
2690 * 1) Transmit head and tail are equal (empty).
2691 * 2) Command queue head and tail are equal (empty).
2692 * 3) The "TBUSY" flag is 0. (Transmitter not busy).
2695 if ((ttail == thead) && (tbusy == 0) && (chead == ctail)) {
2700 chars = thead - ttail;
2702 chars = thead - ttail + ch->ch_tsize;
2704 * Fudge factor here.
2705 * If chars is zero, we know that the command queue had
2706 * something in it or tbusy was set. Because we cannot
2707 * be sure if there is still some data to be transmitted,
2708 * lets lie, and tell ld we have 1 byte left.
2712 * If TBUSY is still set, and our tx buffers are empty,
2713 * force the firmware to send me another wakeup after
2714 * TBUSY has been cleared.
2717 DGAP_LOCK(ch->ch_lock, lock_flags);
2718 un->un_flags |= UN_EMPTY;
2719 writeb(1, &(bs->iempty));
2720 DGAP_UNLOCK(ch->ch_lock, lock_flags);
2726 DPR_WRITE(("dgap_tty_chars_in_buffer. Port: %x - %d (head: %d tail: %d tsize: %d)\n",
2727 ch->ch_portnum, chars, thead, ttail, ch->ch_tsize));
2732 static int dgap_wait_for_drain(struct tty_struct *tty)
2734 struct channel_t *ch;
2739 ulong lock_flags = 0;
2741 if (!tty || tty->magic != TTY_MAGIC)
2744 un = tty->driver_data;
2745 if (!un || un->magic != DGAP_UNIT_MAGIC)
2749 if (!ch || ch->magic != DGAP_CHANNEL_MAGIC)
2758 DPR_DRAIN(("dgap_wait_for_drain start\n"));
2760 /* Loop until data is drained */
2761 while (count != 0) {
2763 count = dgap_tty_chars_in_buffer(tty);
2768 /* Set flag waiting for drain */
2769 DGAP_LOCK(ch->ch_lock, lock_flags);
2770 un->un_flags |= UN_EMPTY;
2771 writeb(1, &(bs->iempty));
2772 DGAP_UNLOCK(ch->ch_lock, lock_flags);
2774 /* Go to sleep till we get woken up */
2775 ret = wait_event_interruptible(un->un_flags_wait, ((un->un_flags & UN_EMPTY) == 0));
2776 /* If ret is non-zero, user ctrl-c'ed us */
2782 DGAP_LOCK(ch->ch_lock, lock_flags);
2783 un->un_flags &= ~(UN_EMPTY);
2784 DGAP_UNLOCK(ch->ch_lock, lock_flags);
2786 DPR_DRAIN(("dgap_wait_for_drain finish\n"));
2794 * Reduces bytes_available to the max number of characters
2795 * that can be sent currently given the maxcps value, and
2796 * returns the new bytes_available. This only affects printer
2799 static int dgap_maxcps_room(struct tty_struct *tty, int bytes_available)
2801 struct channel_t *ch = NULL;
2802 struct un_t *un = NULL;
2805 return (bytes_available);
2807 un = tty->driver_data;
2808 if (!un || un->magic != DGAP_UNIT_MAGIC)
2809 return (bytes_available);
2812 if (!ch || ch->magic != DGAP_CHANNEL_MAGIC)
2813 return (bytes_available);
2816 * If its not the Transparent print device, return
2817 * the full data amount.
2819 if (un->un_type != DGAP_PRINT)
2820 return (bytes_available);
2822 if (ch->ch_digi.digi_maxcps > 0 && ch->ch_digi.digi_bufsize > 0 ) {
2824 unsigned long current_time = jiffies;
2825 unsigned long buffer_time = current_time +
2826 (HZ * ch->ch_digi.digi_bufsize) / ch->ch_digi.digi_maxcps;
2828 if (ch->ch_cpstime < current_time) {
2829 /* buffer is empty */
2830 ch->ch_cpstime = current_time; /* reset ch_cpstime */
2831 cps_limit = ch->ch_digi.digi_bufsize;
2833 else if (ch->ch_cpstime < buffer_time) {
2834 /* still room in the buffer */
2835 cps_limit = ((buffer_time - ch->ch_cpstime) * ch->ch_digi.digi_maxcps) / HZ;
2838 /* no room in the buffer */
2842 bytes_available = min(cps_limit, bytes_available);
2845 return (bytes_available);
2849 static inline void dgap_set_firmware_event(struct un_t *un, unsigned int event)
2851 struct channel_t *ch = NULL;
2852 struct bs_t *bs = NULL;
2854 if (!un || un->magic != DGAP_UNIT_MAGIC)
2857 if (!ch || ch->magic != DGAP_CHANNEL_MAGIC)
2863 if ((event & UN_LOW) != 0) {
2864 if ((un->un_flags & UN_LOW) == 0) {
2865 un->un_flags |= UN_LOW;
2866 writeb(1, &(bs->ilow));
2869 if ((event & UN_LOW) != 0) {
2870 if ((un->un_flags & UN_EMPTY) == 0) {
2871 un->un_flags |= UN_EMPTY;
2872 writeb(1, &(bs->iempty));
2879 * dgap_tty_write_room()
2881 * Return space available in Tx buffer
2883 static int dgap_tty_write_room(struct tty_struct *tty)
2885 struct channel_t *ch = NULL;
2886 struct un_t *un = NULL;
2887 struct bs_t *bs = NULL;
2888 u16 head, tail, tmask;
2890 ulong lock_flags = 0;
2892 if (tty == NULL || dgap_TmpWriteBuf == NULL)
2895 un = tty->driver_data;
2896 if (!un || un->magic != DGAP_UNIT_MAGIC)
2900 if (!ch || ch->magic != DGAP_CHANNEL_MAGIC)
2907 DGAP_LOCK(ch->ch_lock, lock_flags);
2909 tmask = ch->ch_tsize - 1;
2910 head = readw(&(bs->tx_head)) & tmask;
2911 tail = readw(&(bs->tx_tail)) & tmask;
2913 if ((ret = tail - head - 1) < 0)
2914 ret += ch->ch_tsize;
2916 /* Limit printer to maxcps */
2917 ret = dgap_maxcps_room(tty, ret);
2920 * If we are printer device, leave space for
2921 * possibly both the on and off strings.
2923 if (un->un_type == DGAP_PRINT) {
2924 if (!(ch->ch_flags & CH_PRON))
2925 ret -= ch->ch_digi.digi_onlen;
2926 ret -= ch->ch_digi.digi_offlen;
2929 if (ch->ch_flags & CH_PRON)
2930 ret -= ch->ch_digi.digi_offlen;
2937 * Schedule FEP to wake us up if needed.
2939 * TODO: This might be overkill...
2940 * Do we really need to schedule callbacks from the FEP
2941 * in every case? Can we get smarter based on ret?
2943 dgap_set_firmware_event(un, UN_LOW | UN_EMPTY);
2944 DGAP_UNLOCK(ch->ch_lock, lock_flags);
2946 DPR_WRITE(("dgap_tty_write_room - %d tail: %d head: %d\n", ret, tail, head));
2953 * dgap_tty_put_char()
2955 * Put a character into ch->ch_buf
2957 * - used by the line discipline for OPOST processing
2959 static int dgap_tty_put_char(struct tty_struct *tty, unsigned char c)
2962 * Simply call tty_write.
2964 DPR_WRITE(("dgap_tty_put_char called\n"));
2965 dgap_tty_write(tty, &c, 1);
2973 * Take data from the user or kernel and send it out to the FEP.
2974 * In here exists all the Transparent Print magic as well.
2976 static int dgap_tty_write(struct tty_struct *tty, const unsigned char *buf, int count)
2978 struct channel_t *ch = NULL;
2979 struct un_t *un = NULL;
2980 struct bs_t *bs = NULL;
2982 u16 head, tail, tmask, remain;
2983 int bufcount = 0, n = 0;
2988 if (tty == NULL || dgap_TmpWriteBuf == NULL)
2991 un = tty->driver_data;
2992 if (!un || un->magic != DGAP_UNIT_MAGIC)
2996 if (!ch || ch->magic != DGAP_CHANNEL_MAGIC)
3006 DPR_WRITE(("dgap_tty_write: Port: %x tty=%p user=%d len=%d\n",
3007 ch->ch_portnum, tty, from_user, count));
3010 * Store original amount of characters passed in.
3011 * This helps to figure out if we should ask the FEP
3012 * to send us an event when it has more space available.
3016 DGAP_LOCK(ch->ch_lock, lock_flags);
3018 /* Get our space available for the channel from the board */
3019 tmask = ch->ch_tsize - 1;
3020 head = readw(&(bs->tx_head)) & tmask;
3021 tail = readw(&(bs->tx_tail)) & tmask;
3023 if ((bufcount = tail - head - 1) < 0)
3024 bufcount += ch->ch_tsize;
3026 DPR_WRITE(("%d: bufcount: %x count: %x tail: %x head: %x tmask: %x\n",
3027 __LINE__, bufcount, count, tail, head, tmask));
3030 * Limit printer output to maxcps overall, with bursts allowed
3031 * up to bufsize characters.
3033 bufcount = dgap_maxcps_room(tty, bufcount);
3036 * Take minimum of what the user wants to send, and the
3037 * space available in the FEP buffer.
3039 count = min(count, bufcount);
3042 * Bail if no space left.
3045 dgap_set_firmware_event(un, UN_LOW | UN_EMPTY);
3046 DGAP_UNLOCK(ch->ch_lock, lock_flags);
3051 * Output the printer ON string, if we are in terminal mode, but
3052 * need to be in printer mode.
3054 if ((un->un_type == DGAP_PRINT) && !(ch->ch_flags & CH_PRON)) {
3055 dgap_wmove(ch, ch->ch_digi.digi_onstr,
3056 (int) ch->ch_digi.digi_onlen);
3057 head = readw(&(bs->tx_head)) & tmask;
3058 ch->ch_flags |= CH_PRON;
3062 * On the other hand, output the printer OFF string, if we are
3063 * currently in printer mode, but need to output to the terminal.
3065 if ((un->un_type != DGAP_PRINT) && (ch->ch_flags & CH_PRON)) {
3066 dgap_wmove(ch, ch->ch_digi.digi_offstr,
3067 (int) ch->ch_digi.digi_offlen);
3068 head = readw(&(bs->tx_head)) & tmask;
3069 ch->ch_flags &= ~CH_PRON;
3073 * If there is nothing left to copy, or I can't handle any more data, leave.
3076 dgap_set_firmware_event(un, UN_LOW | UN_EMPTY);
3077 DGAP_UNLOCK(ch->ch_lock, lock_flags);
3083 count = min(count, WRITEBUFLEN);
3085 DGAP_UNLOCK(ch->ch_lock, lock_flags);
3088 * If data is coming from user space, copy it into a temporary
3089 * buffer so we don't get swapped out while doing the copy to
3092 /* we're allowed to block if it's from_user */
3093 if (down_interruptible(&dgap_TmpWriteSem)) {
3097 if (copy_from_user(dgap_TmpWriteBuf, (const uchar __user *) buf, count)) {
3098 up(&dgap_TmpWriteSem);
3099 printk("Write: Copy from user failed!\n");
3103 DGAP_LOCK(ch->ch_lock, lock_flags);
3105 buf = dgap_TmpWriteBuf;
3111 * If the write wraps over the top of the circular buffer,
3112 * move the portion up to the wrap point, and reset the
3113 * pointers to the bottom.
3115 remain = ch->ch_tstart + ch->ch_tsize - head;
3119 vaddr = ch->ch_taddr + head;
3121 memcpy_toio(vaddr, (uchar *) buf, remain);
3122 dgap_sniff_nowait_nolock(ch, "USER WRITE", (uchar *) buf, remain);
3124 head = ch->ch_tstart;
3131 * Move rest of data.
3133 vaddr = ch->ch_taddr + head;
3136 memcpy_toio(vaddr, (uchar *) buf, remain);
3137 dgap_sniff_nowait_nolock(ch, "USER WRITE", (uchar *) buf, remain);
3144 ch->ch_txcount += count;
3146 writew(head, &(bs->tx_head));
3150 dgap_set_firmware_event(un, UN_LOW | UN_EMPTY);
3153 * If this is the print device, and the
3154 * printer is still on, we need to turn it
3155 * off before going idle. If the buffer is
3156 * non-empty, wait until it goes empty.
3157 * Otherwise turn it off right now.
3159 if ((un->un_type == DGAP_PRINT) && (ch->ch_flags & CH_PRON)) {
3160 tail = readw(&(bs->tx_tail)) & tmask;
3163 un->un_flags |= UN_EMPTY;
3164 writeb(1, &(bs->iempty));
3167 dgap_wmove(ch, ch->ch_digi.digi_offstr,
3168 (int) ch->ch_digi.digi_offlen);
3169 head = readw(&(bs->tx_head)) & tmask;
3170 ch->ch_flags &= ~CH_PRON;
3174 /* Update printer buffer empty time. */
3175 if ((un->un_type == DGAP_PRINT) && (ch->ch_digi.digi_maxcps > 0)
3176 && (ch->ch_digi.digi_bufsize > 0)) {
3177 ch->ch_cpstime += (HZ * count) / ch->ch_digi.digi_maxcps;
3181 DGAP_UNLOCK(ch->ch_lock, lock_flags);
3182 up(&dgap_TmpWriteSem);
3185 DGAP_UNLOCK(ch->ch_lock, lock_flags);
3188 DPR_WRITE(("Write finished - Write %d bytes of %d.\n", count, orig_count));
3196 * Return modem signals to ld.
3198 static int dgap_tty_tiocmget(struct tty_struct *tty)
3200 struct channel_t *ch;
3206 if (!tty || tty->magic != TTY_MAGIC)
3209 un = tty->driver_data;
3210 if (!un || un->magic != DGAP_UNIT_MAGIC)
3214 if (!ch || ch->magic != DGAP_CHANNEL_MAGIC)
3217 DPR_IOCTL(("dgap_tty_tiocmget start\n"));
3219 DGAP_LOCK(ch->ch_lock, lock_flags);
3221 mstat = readb(&(ch->ch_bs->m_stat));
3222 /* Append any outbound signals that might be pending... */
3223 mstat |= ch->ch_mostat;
3225 DGAP_UNLOCK(ch->ch_lock, lock_flags);
3229 if (mstat & D_DTR(ch))
3230 result |= TIOCM_DTR;
3231 if (mstat & D_RTS(ch))
3232 result |= TIOCM_RTS;
3233 if (mstat & D_CTS(ch))
3234 result |= TIOCM_CTS;
3235 if (mstat & D_DSR(ch))
3236 result |= TIOCM_DSR;
3237 if (mstat & D_RI(ch))
3239 if (mstat & D_CD(ch))
3242 DPR_IOCTL(("dgap_tty_tiocmget finish\n"));
3249 * dgap_tty_tiocmset()
3251 * Set modem signals, called by ld.
3254 static int dgap_tty_tiocmset(struct tty_struct *tty,
3255 unsigned int set, unsigned int clear)
3258 struct channel_t *ch;
3264 if (!tty || tty->magic != TTY_MAGIC)
3267 un = tty->driver_data;
3268 if (!un || un->magic != DGAP_UNIT_MAGIC)
3272 if (!ch || ch->magic != DGAP_CHANNEL_MAGIC)
3276 if (!bd || bd->magic != DGAP_BOARD_MAGIC)
3279 DPR_IOCTL(("dgap_tty_tiocmset start\n"));
3281 DGAP_LOCK(bd->bd_lock, lock_flags);
3282 DGAP_LOCK(ch->ch_lock, lock_flags2);
3284 if (set & TIOCM_RTS) {
3285 ch->ch_mforce |= D_RTS(ch);
3286 ch->ch_mval |= D_RTS(ch);
3289 if (set & TIOCM_DTR) {
3290 ch->ch_mforce |= D_DTR(ch);
3291 ch->ch_mval |= D_DTR(ch);
3294 if (clear & TIOCM_RTS) {
3295 ch->ch_mforce |= D_RTS(ch);
3296 ch->ch_mval &= ~(D_RTS(ch));
3299 if (clear & TIOCM_DTR) {
3300 ch->ch_mforce |= D_DTR(ch);
3301 ch->ch_mval &= ~(D_DTR(ch));
3306 DGAP_UNLOCK(ch->ch_lock, lock_flags2);
3307 DGAP_UNLOCK(bd->bd_lock, lock_flags);
3309 DPR_IOCTL(("dgap_tty_tiocmset finish\n"));
3317 * dgap_tty_send_break()
3319 * Send a Break, called by ld.
3321 static int dgap_tty_send_break(struct tty_struct *tty, int msec)
3324 struct channel_t *ch;
3330 if (!tty || tty->magic != TTY_MAGIC)
3333 un = tty->driver_data;
3334 if (!un || un->magic != DGAP_UNIT_MAGIC)
3338 if (!ch || ch->magic != DGAP_CHANNEL_MAGIC)
3342 if (!bd || bd->magic != DGAP_BOARD_MAGIC)
3357 DPR_IOCTL(("dgap_tty_send_break start 1. %lx\n", jiffies));
3359 DGAP_LOCK(bd->bd_lock, lock_flags);
3360 DGAP_LOCK(ch->ch_lock, lock_flags2);
3362 dgap_cmdw(ch, SBREAK, (u16) SBREAK_TIME, 0);
3364 dgap_cmdw(ch, SBREAK, (u16) msec, 0);
3366 DGAP_UNLOCK(ch->ch_lock, lock_flags2);
3367 DGAP_UNLOCK(bd->bd_lock, lock_flags);
3369 DPR_IOCTL(("dgap_tty_send_break finish\n"));
3378 * dgap_tty_wait_until_sent()
3380 * wait until data has been transmitted, called by ld.
3382 static void dgap_tty_wait_until_sent(struct tty_struct *tty, int timeout)
3385 rc = dgap_wait_for_drain(tty);
3387 DPR_IOCTL(("dgap_tty_ioctl - bad return: %d ", rc));
3398 * send a high priority character, called by ld.
3400 static void dgap_tty_send_xchar(struct tty_struct *tty, char c)
3403 struct channel_t *ch;
3408 if (!tty || tty->magic != TTY_MAGIC)
3411 un = tty->driver_data;
3412 if (!un || un->magic != DGAP_UNIT_MAGIC)
3416 if (!ch || ch->magic != DGAP_CHANNEL_MAGIC)
3420 if (!bd || bd->magic != DGAP_BOARD_MAGIC)
3423 DPR_IOCTL(("dgap_tty_send_xchar start 1. %lx\n", jiffies));
3425 DGAP_LOCK(bd->bd_lock, lock_flags);
3426 DGAP_LOCK(ch->ch_lock, lock_flags2);
3429 * This is technically what we should do.
3430 * However, the NIST tests specifically want
3431 * to see each XON or XOFF character that it
3432 * sends, so lets just send each character
3436 if (c == STOP_CHAR(tty)) {
3437 dgap_cmdw(ch, RPAUSE, 0, 0);
3439 else if (c == START_CHAR(tty)) {
3440 dgap_cmdw(ch, RRESUME, 0, 0);
3443 dgap_wmove(ch, &c, 1);
3446 dgap_wmove(ch, &c, 1);
3449 DGAP_UNLOCK(ch->ch_lock, lock_flags2);
3450 DGAP_UNLOCK(bd->bd_lock, lock_flags);
3452 DPR_IOCTL(("dgap_tty_send_xchar finish\n"));
3461 * Return modem signals to ld.
3463 static int dgap_get_modem_info(struct channel_t *ch, unsigned int __user *value)
3470 DPR_IOCTL(("dgap_get_modem_info start\n"));
3472 if (!ch || ch->magic != DGAP_CHANNEL_MAGIC)
3475 DGAP_LOCK(ch->ch_lock, lock_flags);
3477 mstat = readb(&(ch->ch_bs->m_stat));
3478 /* Append any outbound signals that might be pending... */
3479 mstat |= ch->ch_mostat;
3481 DGAP_UNLOCK(ch->ch_lock, lock_flags);
3485 if (mstat & D_DTR(ch))
3486 result |= TIOCM_DTR;
3487 if (mstat & D_RTS(ch))
3488 result |= TIOCM_RTS;
3489 if (mstat & D_CTS(ch))
3490 result |= TIOCM_CTS;
3491 if (mstat & D_DSR(ch))
3492 result |= TIOCM_DSR;
3493 if (mstat & D_RI(ch))
3495 if (mstat & D_CD(ch))
3498 rc = put_user(result, value);
3500 DPR_IOCTL(("dgap_get_modem_info finish\n"));
3506 * dgap_set_modem_info()
3508 * Set modem signals, called by ld.
3510 static int dgap_set_modem_info(struct tty_struct *tty, unsigned int command, unsigned int __user *value)
3513 struct channel_t *ch;
3516 unsigned int arg = 0;
3520 if (!tty || tty->magic != TTY_MAGIC)
3523 un = tty->driver_data;
3524 if (!un || un->magic != DGAP_UNIT_MAGIC)
3528 if (!ch || ch->magic != DGAP_CHANNEL_MAGIC)
3532 if (!bd || bd->magic != DGAP_BOARD_MAGIC)
3535 DPR_IOCTL(("dgap_set_modem_info() start\n"));
3537 ret = get_user(arg, value);
3539 DPR_IOCTL(("dgap_set_modem_info %d ret: %x. finished.\n", __LINE__, ret));
3543 DPR_IOCTL(("dgap_set_modem_info: command: %x arg: %x\n", command, arg));
3547 if (arg & TIOCM_RTS) {
3548 ch->ch_mforce |= D_RTS(ch);
3549 ch->ch_mval |= D_RTS(ch);
3552 if (arg & TIOCM_DTR) {
3553 ch->ch_mforce |= D_DTR(ch);
3554 ch->ch_mval |= D_DTR(ch);
3560 if (arg & TIOCM_RTS) {
3561 ch->ch_mforce |= D_RTS(ch);
3562 ch->ch_mval &= ~(D_RTS(ch));
3565 if (arg & TIOCM_DTR) {
3566 ch->ch_mforce |= D_DTR(ch);
3567 ch->ch_mval &= ~(D_DTR(ch));
3573 ch->ch_mforce = D_DTR(ch)|D_RTS(ch);
3575 if (arg & TIOCM_RTS) {
3576 ch->ch_mval |= D_RTS(ch);
3579 ch->ch_mval &= ~(D_RTS(ch));
3582 if (arg & TIOCM_DTR) {
3583 ch->ch_mval |= (D_DTR(ch));
3586 ch->ch_mval &= ~(D_DTR(ch));
3595 DGAP_LOCK(bd->bd_lock, lock_flags);
3596 DGAP_LOCK(ch->ch_lock, lock_flags2);
3600 DGAP_UNLOCK(ch->ch_lock, lock_flags2);
3601 DGAP_UNLOCK(bd->bd_lock, lock_flags);
3603 DPR_IOCTL(("dgap_set_modem_info finish\n"));
3610 * dgap_tty_digigeta()
3612 * Ioctl to get the information for ditty.
3617 static int dgap_tty_digigeta(struct tty_struct *tty, struct digi_t __user *retinfo)
3619 struct channel_t *ch;
3627 if (!tty || tty->magic != TTY_MAGIC)
3630 un = tty->driver_data;
3631 if (!un || un->magic != DGAP_UNIT_MAGIC)
3635 if (!ch || ch->magic != DGAP_CHANNEL_MAGIC)
3638 memset(&tmp, 0, sizeof(tmp));
3640 DGAP_LOCK(ch->ch_lock, lock_flags);
3641 memcpy(&tmp, &ch->ch_digi, sizeof(tmp));
3642 DGAP_UNLOCK(ch->ch_lock, lock_flags);
3644 if (copy_to_user(retinfo, &tmp, sizeof(*retinfo)))
3652 * dgap_tty_digiseta()
3654 * Ioctl to set the information for ditty.
3659 static int dgap_tty_digiseta(struct tty_struct *tty, struct digi_t __user *new_info)
3662 struct channel_t *ch;
3664 struct digi_t new_digi;
3665 ulong lock_flags = 0;
3666 unsigned long lock_flags2;
3668 DPR_IOCTL(("DIGI_SETA start\n"));
3670 if (!tty || tty->magic != TTY_MAGIC)
3673 un = tty->driver_data;
3674 if (!un || un->magic != DGAP_UNIT_MAGIC)
3678 if (!ch || ch->magic != DGAP_CHANNEL_MAGIC)
3682 if (!bd || bd->magic != DGAP_BOARD_MAGIC)
3685 if (copy_from_user(&new_digi, new_info, sizeof(struct digi_t))) {
3686 DPR_IOCTL(("DIGI_SETA failed copy_from_user\n"));
3690 DGAP_LOCK(bd->bd_lock, lock_flags);
3691 DGAP_LOCK(ch->ch_lock, lock_flags2);
3693 memcpy(&ch->ch_digi, &new_digi, sizeof(struct digi_t));
3695 if (ch->ch_digi.digi_maxcps < 1)
3696 ch->ch_digi.digi_maxcps = 1;
3698 if (ch->ch_digi.digi_maxcps > 10000)
3699 ch->ch_digi.digi_maxcps = 10000;
3701 if (ch->ch_digi.digi_bufsize < 10)
3702 ch->ch_digi.digi_bufsize = 10;
3704 if (ch->ch_digi.digi_maxchar < 1)
3705 ch->ch_digi.digi_maxchar = 1;
3707 if (ch->ch_digi.digi_maxchar > ch->ch_digi.digi_bufsize)
3708 ch->ch_digi.digi_maxchar = ch->ch_digi.digi_bufsize;
3710 if (ch->ch_digi.digi_onlen > DIGI_PLEN)
3711 ch->ch_digi.digi_onlen = DIGI_PLEN;
3713 if (ch->ch_digi.digi_offlen > DIGI_PLEN)
3714 ch->ch_digi.digi_offlen = DIGI_PLEN;
3718 DGAP_UNLOCK(ch->ch_lock, lock_flags2);
3719 DGAP_UNLOCK(bd->bd_lock, lock_flags);
3721 DPR_IOCTL(("DIGI_SETA finish\n"));
3728 * dgap_tty_digigetedelay()
3730 * Ioctl to get the current edelay setting.
3735 static int dgap_tty_digigetedelay(struct tty_struct *tty, int __user *retinfo)
3737 struct channel_t *ch;
3745 if (!tty || tty->magic != TTY_MAGIC)
3748 un = tty->driver_data;
3749 if (!un || un->magic != DGAP_UNIT_MAGIC)
3753 if (!ch || ch->magic != DGAP_CHANNEL_MAGIC)
3756 memset(&tmp, 0, sizeof(tmp));
3758 DGAP_LOCK(ch->ch_lock, lock_flags);
3759 tmp = readw(&(ch->ch_bs->edelay));
3760 DGAP_UNLOCK(ch->ch_lock, lock_flags);
3762 if (copy_to_user(retinfo, &tmp, sizeof(*retinfo)))
3770 * dgap_tty_digisetedelay()
3772 * Ioctl to set the EDELAY setting
3775 static int dgap_tty_digisetedelay(struct tty_struct *tty, int __user *new_info)
3778 struct channel_t *ch;
3784 DPR_IOCTL(("DIGI_SETA start\n"));
3786 if (!tty || tty->magic != TTY_MAGIC)
3789 un = tty->driver_data;
3790 if (!un || un->magic != DGAP_UNIT_MAGIC)
3794 if (!ch || ch->magic != DGAP_CHANNEL_MAGIC)
3798 if (!bd || bd->magic != DGAP_BOARD_MAGIC)
3801 if (copy_from_user(&new_digi, new_info, sizeof(int))) {
3802 DPR_IOCTL(("DIGI_SETEDELAY failed copy_from_user\n"));
3806 DGAP_LOCK(bd->bd_lock, lock_flags);
3807 DGAP_LOCK(ch->ch_lock, lock_flags2);
3809 writew((u16) new_digi, &(ch->ch_bs->edelay));
3813 DGAP_UNLOCK(ch->ch_lock, lock_flags2);
3814 DGAP_UNLOCK(bd->bd_lock, lock_flags);
3816 DPR_IOCTL(("DIGI_SETA finish\n"));
3823 * dgap_tty_digigetcustombaud()
3825 * Ioctl to get the current custom baud rate setting.
3827 static int dgap_tty_digigetcustombaud(struct tty_struct *tty, int __user *retinfo)
3829 struct channel_t *ch;
3837 if (!tty || tty->magic != TTY_MAGIC)
3840 un = tty->driver_data;
3841 if (!un || un->magic != DGAP_UNIT_MAGIC)
3845 if (!ch || ch->magic != DGAP_CHANNEL_MAGIC)
3848 memset(&tmp, 0, sizeof(tmp));
3850 DGAP_LOCK(ch->ch_lock, lock_flags);
3851 tmp = dgap_get_custom_baud(ch);
3852 DGAP_UNLOCK(ch->ch_lock, lock_flags);
3854 DPR_IOCTL(("DIGI_GETCUSTOMBAUD. Returning %d\n", tmp));
3856 if (copy_to_user(retinfo, &tmp, sizeof(*retinfo)))
3864 * dgap_tty_digisetcustombaud()
3866 * Ioctl to set the custom baud rate setting
3868 static int dgap_tty_digisetcustombaud(struct tty_struct *tty, int __user *new_info)
3871 struct channel_t *ch;
3877 DPR_IOCTL(("DIGI_SETCUSTOMBAUD start\n"));
3879 if (!tty || tty->magic != TTY_MAGIC)
3882 un = tty->driver_data;
3883 if (!un || un->magic != DGAP_UNIT_MAGIC)
3887 if (!ch || ch->magic != DGAP_CHANNEL_MAGIC)
3891 if (!bd || bd->magic != DGAP_BOARD_MAGIC)
3895 if (copy_from_user(&new_rate, new_info, sizeof(unsigned int))) {
3896 DPR_IOCTL(("DIGI_SETCUSTOMBAUD failed copy_from_user\n"));
3900 if (bd->bd_flags & BD_FEP5PLUS) {
3902 DPR_IOCTL(("DIGI_SETCUSTOMBAUD. Setting %d\n", new_rate));
3904 DGAP_LOCK(bd->bd_lock, lock_flags);
3905 DGAP_LOCK(ch->ch_lock, lock_flags2);
3907 ch->ch_custom_speed = new_rate;
3911 DGAP_UNLOCK(ch->ch_lock, lock_flags2);
3912 DGAP_UNLOCK(bd->bd_lock, lock_flags);
3915 DPR_IOCTL(("DIGI_SETCUSTOMBAUD finish\n"));
3922 * dgap_set_termios()
3924 static void dgap_tty_set_termios(struct tty_struct *tty, struct ktermios *old_termios)
3927 struct channel_t *ch;
3929 unsigned long lock_flags;
3930 unsigned long lock_flags2;
3932 if (!tty || tty->magic != TTY_MAGIC)
3935 un = tty->driver_data;
3936 if (!un || un->magic != DGAP_UNIT_MAGIC)
3940 if (!ch || ch->magic != DGAP_CHANNEL_MAGIC)
3944 if (!bd || bd->magic != DGAP_BOARD_MAGIC)
3947 DGAP_LOCK(bd->bd_lock, lock_flags);
3948 DGAP_LOCK(ch->ch_lock, lock_flags2);
3950 ch->ch_c_cflag = tty->termios.c_cflag;
3951 ch->ch_c_iflag = tty->termios.c_iflag;
3952 ch->ch_c_oflag = tty->termios.c_oflag;
3953 ch->ch_c_lflag = tty->termios.c_lflag;
3954 ch->ch_startc = tty->termios.c_cc[VSTART];
3955 ch->ch_stopc = tty->termios.c_cc[VSTOP];
3960 DGAP_UNLOCK(ch->ch_lock, lock_flags2);
3961 DGAP_UNLOCK(bd->bd_lock, lock_flags);
3965 static void dgap_tty_throttle(struct tty_struct *tty)
3968 struct channel_t *ch;
3973 if (!tty || tty->magic != TTY_MAGIC)
3976 un = tty->driver_data;
3977 if (!un || un->magic != DGAP_UNIT_MAGIC)
3981 if (!ch || ch->magic != DGAP_CHANNEL_MAGIC)
3985 if (!bd || bd->magic != DGAP_BOARD_MAGIC)
3988 DPR_IOCTL(("dgap_tty_throttle start\n"));
3990 DGAP_LOCK(bd->bd_lock, lock_flags);
3991 DGAP_LOCK(ch->ch_lock, lock_flags2);
3993 ch->ch_flags |= (CH_RXBLOCK);
3995 dgap_cmdw(ch, RPAUSE, 0, 0);
3998 DGAP_UNLOCK(ch->ch_lock, lock_flags2);
3999 DGAP_UNLOCK(bd->bd_lock, lock_flags);
4001 DPR_IOCTL(("dgap_tty_throttle finish\n"));
4005 static void dgap_tty_unthrottle(struct tty_struct *tty)
4008 struct channel_t *ch;
4013 if (!tty || tty->magic != TTY_MAGIC)
4016 un = tty->driver_data;
4017 if (!un || un->magic != DGAP_UNIT_MAGIC)
4021 if (!ch || ch->magic != DGAP_CHANNEL_MAGIC)
4025 if (!bd || bd->magic != DGAP_BOARD_MAGIC)
4028 DPR_IOCTL(("dgap_tty_unthrottle start\n"));
4030 DGAP_LOCK(bd->bd_lock, lock_flags);
4031 DGAP_LOCK(ch->ch_lock, lock_flags2);
4033 ch->ch_flags &= ~(CH_RXBLOCK);
4036 dgap_cmdw(ch, RRESUME, 0, 0);
4039 DGAP_UNLOCK(ch->ch_lock, lock_flags2);
4040 DGAP_UNLOCK(bd->bd_lock, lock_flags);
4042 DPR_IOCTL(("dgap_tty_unthrottle finish\n"));
4046 static void dgap_tty_start(struct tty_struct *tty)
4049 struct channel_t *ch;
4054 if (!tty || tty->magic != TTY_MAGIC)
4057 un = tty->driver_data;
4058 if (!un || un->magic != DGAP_UNIT_MAGIC)
4062 if (!ch || ch->magic != DGAP_CHANNEL_MAGIC)
4066 if (!bd || bd->magic != DGAP_BOARD_MAGIC)
4069 DPR_IOCTL(("dgap_tty_start start\n"));
4071 DGAP_LOCK(bd->bd_lock, lock_flags);
4072 DGAP_LOCK(ch->ch_lock, lock_flags2);
4074 dgap_cmdw(ch, RESUMETX, 0, 0);
4076 DGAP_UNLOCK(ch->ch_lock, lock_flags2);
4077 DGAP_UNLOCK(bd->bd_lock, lock_flags);
4079 DPR_IOCTL(("dgap_tty_start finish\n"));
4083 static void dgap_tty_stop(struct tty_struct *tty)
4086 struct channel_t *ch;
4091 if (!tty || tty->magic != TTY_MAGIC)
4094 un = tty->driver_data;
4095 if (!un || un->magic != DGAP_UNIT_MAGIC)
4099 if (!ch || ch->magic != DGAP_CHANNEL_MAGIC)
4103 if (!bd || bd->magic != DGAP_BOARD_MAGIC)
4106 DPR_IOCTL(("dgap_tty_stop start\n"));
4108 DGAP_LOCK(bd->bd_lock, lock_flags);
4109 DGAP_LOCK(ch->ch_lock, lock_flags2);
4111 dgap_cmdw(ch, PAUSETX, 0, 0);
4113 DGAP_UNLOCK(ch->ch_lock, lock_flags2);
4114 DGAP_UNLOCK(bd->bd_lock, lock_flags);
4116 DPR_IOCTL(("dgap_tty_stop finish\n"));
4121 * dgap_tty_flush_chars()
4123 * Flush the cook buffer
4125 * Note to self, and any other poor souls who venture here:
4127 * flush in this case DOES NOT mean dispose of the data.
4128 * instead, it means "stop buffering and send it if you
4129 * haven't already." Just guess how I figured that out... SRW 2-Jun-98
4131 * It is also always called in interrupt context - JAR 8-Sept-99
4133 static void dgap_tty_flush_chars(struct tty_struct *tty)
4136 struct channel_t *ch;
4141 if (!tty || tty->magic != TTY_MAGIC)
4144 un = tty->driver_data;
4145 if (!un || un->magic != DGAP_UNIT_MAGIC)
4149 if (!ch || ch->magic != DGAP_CHANNEL_MAGIC)
4153 if (!bd || bd->magic != DGAP_BOARD_MAGIC)
4156 DPR_IOCTL(("dgap_tty_flush_chars start\n"));
4158 DGAP_LOCK(bd->bd_lock, lock_flags);
4159 DGAP_LOCK(ch->ch_lock, lock_flags2);
4161 /* TODO: Do something here */
4163 DGAP_UNLOCK(ch->ch_lock, lock_flags2);
4164 DGAP_UNLOCK(bd->bd_lock, lock_flags);
4166 DPR_IOCTL(("dgap_tty_flush_chars finish\n"));
4172 * dgap_tty_flush_buffer()
4174 * Flush Tx buffer (make in == out)
4176 static void dgap_tty_flush_buffer(struct tty_struct *tty)
4179 struct channel_t *ch;
4185 if (!tty || tty->magic != TTY_MAGIC)
4188 un = tty->driver_data;
4189 if (!un || un->magic != DGAP_UNIT_MAGIC)
4193 if (!ch || ch->magic != DGAP_CHANNEL_MAGIC)
4197 if (!bd || bd->magic != DGAP_BOARD_MAGIC)
4200 DPR_IOCTL(("dgap_tty_flush_buffer on port: %d start\n", ch->ch_portnum));
4202 DGAP_LOCK(bd->bd_lock, lock_flags);
4203 DGAP_LOCK(ch->ch_lock, lock_flags2);
4205 ch->ch_flags &= ~CH_STOP;
4206 head = readw(&(ch->ch_bs->tx_head));
4207 dgap_cmdw(ch, FLUSHTX, (u16) head, 0);
4208 dgap_cmdw(ch, RESUMETX, 0, 0);
4209 if (ch->ch_tun.un_flags & (UN_LOW|UN_EMPTY)) {
4210 ch->ch_tun.un_flags &= ~(UN_LOW|UN_EMPTY);
4211 wake_up_interruptible(&ch->ch_tun.un_flags_wait);
4213 if (ch->ch_pun.un_flags & (UN_LOW|UN_EMPTY)) {
4214 ch->ch_pun.un_flags &= ~(UN_LOW|UN_EMPTY);
4215 wake_up_interruptible(&ch->ch_pun.un_flags_wait);
4218 DGAP_UNLOCK(ch->ch_lock, lock_flags2);
4219 DGAP_UNLOCK(bd->bd_lock, lock_flags);
4220 if (waitqueue_active(&tty->write_wait))
4221 wake_up_interruptible(&tty->write_wait);
4224 DPR_IOCTL(("dgap_tty_flush_buffer finish\n"));
4229 /*****************************************************************************
4231 * The IOCTL function and all of its helpers
4233 *****************************************************************************/
4238 * The usual assortment of ioctl's
4240 static int dgap_tty_ioctl(struct tty_struct *tty, unsigned int cmd,
4244 struct channel_t *ch;
4248 ulong lock_flags = 0;
4249 ulong lock_flags2 = 0;
4250 void __user *uarg = (void __user *) arg;
4252 if (!tty || tty->magic != TTY_MAGIC)
4255 un = tty->driver_data;
4256 if (!un || un->magic != DGAP_UNIT_MAGIC)
4260 if (!ch || ch->magic != DGAP_CHANNEL_MAGIC)
4264 if (!bd || bd->magic != DGAP_BOARD_MAGIC)
4267 DPR_IOCTL(("dgap_tty_ioctl start on port %d - cmd %s (%x), arg %lx\n",
4268 ch->ch_portnum, dgap_ioctl_name(cmd), cmd, arg));
4270 DGAP_LOCK(bd->bd_lock, lock_flags);
4271 DGAP_LOCK(ch->ch_lock, lock_flags2);
4273 if (un->un_open_count <= 0) {
4274 DPR_BASIC(("dgap_tty_ioctl - unit not open.\n"));
4275 DGAP_UNLOCK(ch->ch_lock, lock_flags2);
4276 DGAP_UNLOCK(bd->bd_lock, lock_flags);
4282 /* Here are all the standard ioctl's that we MUST implement */
4286 * TCSBRK is SVID version: non-zero arg --> no break
4287 * this behaviour is exploited by tcdrain().
4289 * According to POSIX.1 spec (7.2.2.1.2) breaks should be
4290 * between 0.25 and 0.5 seconds so we'll ask for something
4291 * in the middle: 0.375 seconds.
4293 rc = tty_check_change(tty);
4294 DGAP_UNLOCK(ch->ch_lock, lock_flags2);
4295 DGAP_UNLOCK(bd->bd_lock, lock_flags);
4300 rc = dgap_wait_for_drain(tty);
4303 DPR_IOCTL(("dgap_tty_ioctl - bad return: %d ", rc));
4307 DGAP_LOCK(bd->bd_lock, lock_flags);
4308 DGAP_LOCK(ch->ch_lock, lock_flags2);
4310 if(((cmd == TCSBRK) && (!arg)) || (cmd == TCSBRKP)) {
4311 dgap_cmdw(ch, SBREAK, (u16) SBREAK_TIME, 0);
4314 DGAP_UNLOCK(ch->ch_lock, lock_flags2);
4315 DGAP_UNLOCK(bd->bd_lock, lock_flags);
4317 DPR_IOCTL(("dgap_tty_ioctl finish on port %d - cmd %s (%x), arg %lx\n",
4318 ch->ch_portnum, dgap_ioctl_name(cmd), cmd, arg));
4324 /* support for POSIX tcsendbreak()
4326 * According to POSIX.1 spec (7.2.2.1.2) breaks should be
4327 * between 0.25 and 0.5 seconds so we'll ask for something
4328 * in the middle: 0.375 seconds.
4330 rc = tty_check_change(tty);
4331 DGAP_UNLOCK(ch->ch_lock, lock_flags2);
4332 DGAP_UNLOCK(bd->bd_lock, lock_flags);
4337 rc = dgap_wait_for_drain(tty);
4339 DPR_IOCTL(("dgap_tty_ioctl - bad return: %d ", rc));
4343 DGAP_LOCK(bd->bd_lock, lock_flags);
4344 DGAP_LOCK(ch->ch_lock, lock_flags2);
4346 dgap_cmdw(ch, SBREAK, (u16) SBREAK_TIME, 0);
4348 DGAP_UNLOCK(ch->ch_lock, lock_flags2);
4349 DGAP_UNLOCK(bd->bd_lock, lock_flags);
4351 DPR_IOCTL(("dgap_tty_ioctl finish on port %d - cmd %s (%x), arg %lx\n",
4352 ch->ch_portnum, dgap_ioctl_name(cmd), cmd, arg));
4358 * FEP5 doesn't support turning on a break unconditionally.
4359 * The FEP5 device will stop sending a break automatically
4360 * after the specified time value that was sent when turning on
4363 rc = tty_check_change(tty);
4364 DGAP_UNLOCK(ch->ch_lock, lock_flags2);
4365 DGAP_UNLOCK(bd->bd_lock, lock_flags);
4370 rc = dgap_wait_for_drain(tty);
4372 DPR_IOCTL(("dgap_tty_ioctl - bad return: %d ", rc));
4376 DGAP_LOCK(bd->bd_lock, lock_flags);
4377 DGAP_LOCK(ch->ch_lock, lock_flags2);
4379 dgap_cmdw(ch, SBREAK, (u16) SBREAK_TIME, 0);
4381 DGAP_UNLOCK(ch->ch_lock, lock_flags2);
4382 DGAP_UNLOCK(bd->bd_lock, lock_flags);
4384 DPR_IOCTL(("dgap_tty_ioctl finish on port %d - cmd %s (%x), arg %lx\n",
4385 ch->ch_portnum, dgap_ioctl_name(cmd), cmd, arg));
4391 * FEP5 doesn't support turning off a break unconditionally.
4392 * The FEP5 device will stop sending a break automatically
4393 * after the specified time value that was sent when turning on
4396 DGAP_UNLOCK(ch->ch_lock, lock_flags2);
4397 DGAP_UNLOCK(bd->bd_lock, lock_flags);
4402 DGAP_UNLOCK(ch->ch_lock, lock_flags2);
4403 DGAP_UNLOCK(bd->bd_lock, lock_flags);
4405 rc = put_user(C_CLOCAL(tty) ? 1 : 0, (unsigned long __user *) arg);
4409 DGAP_UNLOCK(ch->ch_lock, lock_flags2);
4410 DGAP_UNLOCK(bd->bd_lock, lock_flags);
4412 rc = get_user(arg, (unsigned long __user *) arg);
4416 DGAP_LOCK(bd->bd_lock, lock_flags);
4417 DGAP_LOCK(ch->ch_lock, lock_flags2);
4418 tty->termios.c_cflag = ((tty->termios.c_cflag & ~CLOCAL) | (arg ? CLOCAL : 0));
4420 DGAP_UNLOCK(ch->ch_lock, lock_flags2);
4421 DGAP_UNLOCK(bd->bd_lock, lock_flags);
4426 DGAP_UNLOCK(ch->ch_lock, lock_flags2);
4427 DGAP_UNLOCK(bd->bd_lock, lock_flags);
4428 return(dgap_get_modem_info(ch, uarg));
4433 DGAP_UNLOCK(ch->ch_lock, lock_flags2);
4434 DGAP_UNLOCK(bd->bd_lock, lock_flags);
4435 return(dgap_set_modem_info(tty, cmd, uarg));
4438 * Here are any additional ioctl's that we want to implement
4443 * The linux tty driver doesn't have a flush
4444 * input routine for the driver, assuming all backed
4445 * up data is in the line disc. buffers. However,
4446 * we all know that's not the case. Here, we
4447 * act on the ioctl, but then lie and say we didn't
4448 * so the line discipline will process the flush
4451 rc = tty_check_change(tty);
4453 DGAP_UNLOCK(ch->ch_lock, lock_flags2);
4454 DGAP_UNLOCK(bd->bd_lock, lock_flags);
4458 if ((arg == TCIFLUSH) || (arg == TCIOFLUSH)) {
4459 if (!(un->un_type == DGAP_PRINT)) {
4460 head = readw(&(ch->ch_bs->rx_head));
4461 writew(head, &(ch->ch_bs->rx_tail));
4462 writeb(0, &(ch->ch_bs->orun));
4466 if ((arg == TCOFLUSH) || (arg == TCIOFLUSH)) {
4467 ch->ch_flags &= ~CH_STOP;
4468 head = readw(&(ch->ch_bs->tx_head));
4469 dgap_cmdw(ch, FLUSHTX, (u16) head, 0 );
4470 dgap_cmdw(ch, RESUMETX, 0, 0);
4471 if (ch->ch_tun.un_flags & (UN_LOW|UN_EMPTY)) {
4472 ch->ch_tun.un_flags &= ~(UN_LOW|UN_EMPTY);
4473 wake_up_interruptible(&ch->ch_tun.un_flags_wait);
4475 if (ch->ch_pun.un_flags & (UN_LOW|UN_EMPTY)) {
4476 ch->ch_pun.un_flags &= ~(UN_LOW|UN_EMPTY);
4477 wake_up_interruptible(&ch->ch_pun.un_flags_wait);
4479 if (waitqueue_active(&tty->write_wait))
4480 wake_up_interruptible(&tty->write_wait);
4482 /* Can't hold any locks when calling tty_wakeup! */
4483 DGAP_UNLOCK(ch->ch_lock, lock_flags2);
4484 DGAP_UNLOCK(bd->bd_lock, lock_flags);
4486 DGAP_LOCK(bd->bd_lock, lock_flags);
4487 DGAP_LOCK(ch->ch_lock, lock_flags2);
4490 /* pretend we didn't recognize this IOCTL */
4491 DGAP_UNLOCK(ch->ch_lock, lock_flags2);
4492 DGAP_UNLOCK(bd->bd_lock, lock_flags);
4494 DPR_IOCTL(("dgap_tty_ioctl (LINE:%d) finish on port %d - cmd %s (%x), arg %lx\n",
4495 __LINE__, ch->ch_portnum, dgap_ioctl_name(cmd), cmd, arg));
4497 return(-ENOIOCTLCMD);
4502 * The linux tty driver doesn't have a flush
4503 * input routine for the driver, assuming all backed
4504 * up data is in the line disc. buffers. However,
4505 * we all know that's not the case. Here, we
4506 * act on the ioctl, but then lie and say we didn't
4507 * so the line discipline will process the flush
4510 if (cmd == TCSETSF) {
4512 ch->ch_flags &= ~CH_STOP;
4513 head = readw(&(ch->ch_bs->rx_head));
4514 writew(head, &(ch->ch_bs->rx_tail));
4517 /* now wait for all the output to drain */
4518 DGAP_UNLOCK(ch->ch_lock, lock_flags2);
4519 DGAP_UNLOCK(bd->bd_lock, lock_flags);
4520 rc = dgap_wait_for_drain(tty);
4522 DPR_IOCTL(("dgap_tty_ioctl - bad return: %d ", rc));
4526 DPR_IOCTL(("dgap_tty_ioctl finish on port %d - cmd %s (%x), arg %lx\n",
4527 ch->ch_portnum, dgap_ioctl_name(cmd), cmd, arg));
4529 /* pretend we didn't recognize this */
4530 return(-ENOIOCTLCMD);
4534 DGAP_UNLOCK(ch->ch_lock, lock_flags2);
4535 DGAP_UNLOCK(bd->bd_lock, lock_flags);
4536 rc = dgap_wait_for_drain(tty);
4538 DPR_IOCTL(("dgap_tty_ioctl - bad return: %d ", rc));
4542 /* pretend we didn't recognize this */
4543 return(-ENOIOCTLCMD);
4547 * The Linux Line Discipline (LD) would do this for us if we
4548 * let it, but we have the special firmware options to do this
4549 * the "right way" regardless of hardware or software flow
4550 * control so we'll do it outselves instead of letting the LD
4553 rc = tty_check_change(tty);
4555 DGAP_UNLOCK(ch->ch_lock, lock_flags2);
4556 DGAP_UNLOCK(bd->bd_lock, lock_flags);
4560 DPR_IOCTL(("dgap_ioctl - in TCXONC - %d\n", cmd));
4564 DGAP_UNLOCK(ch->ch_lock, lock_flags2);
4565 DGAP_UNLOCK(bd->bd_lock, lock_flags);
4566 dgap_tty_start(tty);
4569 DGAP_UNLOCK(ch->ch_lock, lock_flags2);
4570 DGAP_UNLOCK(bd->bd_lock, lock_flags);
4574 DGAP_UNLOCK(ch->ch_lock, lock_flags2);
4575 DGAP_UNLOCK(bd->bd_lock, lock_flags);
4576 /* Make the ld do it */
4577 return(-ENOIOCTLCMD);
4579 DGAP_UNLOCK(ch->ch_lock, lock_flags2);
4580 DGAP_UNLOCK(bd->bd_lock, lock_flags);
4581 /* Make the ld do it */
4582 return(-ENOIOCTLCMD);
4584 DGAP_UNLOCK(ch->ch_lock, lock_flags2);
4585 DGAP_UNLOCK(bd->bd_lock, lock_flags);
4590 /* get information for ditty */
4591 DGAP_UNLOCK(ch->ch_lock, lock_flags2);
4592 DGAP_UNLOCK(bd->bd_lock, lock_flags);
4593 return(dgap_tty_digigeta(tty, uarg));
4598 /* set information for ditty */
4599 if (cmd == (DIGI_SETAW)) {
4601 DGAP_UNLOCK(ch->ch_lock, lock_flags2);
4602 DGAP_UNLOCK(bd->bd_lock, lock_flags);
4603 rc = dgap_wait_for_drain(tty);
4605 DPR_IOCTL(("dgap_tty_ioctl - bad return: %d ", rc));
4608 DGAP_LOCK(bd->bd_lock, lock_flags);
4609 DGAP_LOCK(ch->ch_lock, lock_flags2);
4612 tty_ldisc_flush(tty);
4617 DGAP_UNLOCK(ch->ch_lock, lock_flags2);
4618 DGAP_UNLOCK(bd->bd_lock, lock_flags);
4619 return(dgap_tty_digiseta(tty, uarg));
4622 DGAP_UNLOCK(ch->ch_lock, lock_flags2);
4623 DGAP_UNLOCK(bd->bd_lock, lock_flags);
4624 return(dgap_tty_digigetedelay(tty, uarg));
4627 DGAP_UNLOCK(ch->ch_lock, lock_flags2);
4628 DGAP_UNLOCK(bd->bd_lock, lock_flags);
4629 return(dgap_tty_digisetedelay(tty, uarg));
4631 case DIGI_GETCUSTOMBAUD:
4632 DGAP_UNLOCK(ch->ch_lock, lock_flags2);
4633 DGAP_UNLOCK(bd->bd_lock, lock_flags);
4634 return(dgap_tty_digigetcustombaud(tty, uarg));
4636 case DIGI_SETCUSTOMBAUD:
4637 DGAP_UNLOCK(ch->ch_lock, lock_flags2);
4638 DGAP_UNLOCK(bd->bd_lock, lock_flags);
4639 return(dgap_tty_digisetcustombaud(tty, uarg));
4641 case DIGI_RESET_PORT:
4642 dgap_firmware_reset_port(ch);
4644 DGAP_UNLOCK(ch->ch_lock, lock_flags2);
4645 DGAP_UNLOCK(bd->bd_lock, lock_flags);
4649 DGAP_UNLOCK(ch->ch_lock, lock_flags2);
4650 DGAP_UNLOCK(bd->bd_lock, lock_flags);
4652 DPR_IOCTL(("dgap_tty_ioctl - in default\n"));
4653 DPR_IOCTL(("dgap_tty_ioctl end - cmd %s (%x), arg %lx\n",
4654 dgap_ioctl_name(cmd), cmd, arg));
4656 return(-ENOIOCTLCMD);
4660 * Loads the dgap.conf config file from the user.
4662 static void dgap_do_config_load(uchar __user *uaddr, int len)
4666 uchar __user *from_addr = uaddr;
4670 to_addr = dgap_config_buf = kzalloc(len + 1, GFP_ATOMIC);
4671 if (!dgap_config_buf) {
4672 DPR_INIT(("dgap_do_config_load - unable to allocate memory for file\n"));
4673 dgap_driver_state = DRIVER_NEED_CONFIG_LOAD;
4683 if (copy_from_user((char *) &buf, from_addr, n) == -1 )
4686 /* Copy data from buffer to kernel memory */
4687 memcpy(to_addr, buf, n);
4689 /* increment counts */
4696 dgap_config_buf[orig_len] = '\0';
4698 to_addr = dgap_config_buf;
4699 dgap_parsefile(&to_addr, TRUE);
4701 DPR_INIT(("dgap_config_load() finish\n"));
4707 static int dgap_after_config_loaded(void)
4713 * Register our ttys, now that we have the config loaded.
4715 for (i = 0; i < dgap_NumBoards; ++i) {
4718 * Initialize KME waitqueues...
4720 init_waitqueue_head(&(dgap_Board[i]->kme_wait));
4723 * allocate flip buffer for board.
4725 dgap_Board[i]->flipbuf = kzalloc(MYFLIPLEN, GFP_ATOMIC);
4726 dgap_Board[i]->flipflagbuf = kzalloc(MYFLIPLEN, GFP_ATOMIC);
4734 /*=======================================================================
4736 * usertoboard - copy from user space to board space.
4738 *=======================================================================*/
4739 static int dgap_usertoboard(struct board_t *brd, char *to_addr, char __user *from_addr, int len)
4744 if (!brd || brd->magic != DGAP_BOARD_MAGIC)
4751 if (copy_from_user((char *) &buf, from_addr, n) == -1 ) {
4755 /* Copy data from buffer to card memory */
4756 memcpy_toio(to_addr, buf, n);
4758 /* increment counts */
4769 * Copies the BIOS code from the user to the board,
4770 * and starts the BIOS running.
4772 static void dgap_do_bios_load(struct board_t *brd, uchar __user *ubios, int len)
4778 if (!brd || (brd->magic != DGAP_BOARD_MAGIC) || !brd->re_map_membase)
4781 DPR_INIT(("dgap_do_bios_load() start\n"));
4783 addr = brd->re_map_membase;
4788 for (i = 0; i < 16; i++)
4789 writeb(0, addr + POSTAREA + i);
4795 if (dgap_usertoboard(brd, addr + offset, ubios, len) == -1 ) {
4796 brd->state = BOARD_FAILED;
4797 brd->dpastatus = BD_NOFEP;
4801 writel(0x0bf00401, addr);
4802 writel(0, (addr + 4));
4804 /* Clear the reset, and change states. */
4805 writeb(FEPCLR, brd->re_map_port);
4806 brd->state = WAIT_BIOS_LOAD;
4811 * Checks to see if the BIOS completed running on the card.
4813 static void dgap_do_wait_for_bios(struct board_t *brd)
4818 if (!brd || (brd->magic != DGAP_BOARD_MAGIC) || !brd->re_map_membase)
4821 addr = brd->re_map_membase;
4822 word = readw(addr + POSTAREA);
4824 /* Check to see if BIOS thinks board is good. (GD). */
4825 if (word == *(u16 *) "GD") {
4826 DPR_INIT(("GOT GD in memory, moving states.\n"));
4827 brd->state = FINISHED_BIOS_LOAD;
4831 /* Give up on board after too long of time taken */
4832 if (brd->wait_for_bios++ > 5000) {
4833 u16 err1 = readw(addr + SEQUENCE);
4834 u16 err2 = readw(addr + ERROR);
4835 APR(("***WARNING*** %s failed diagnostics. Error #(%x,%x).\n",
4836 brd->name, err1, err2));
4837 brd->state = BOARD_FAILED;
4838 brd->dpastatus = BD_NOFEP;
4844 * Copies the FEP code from the user to the board,
4845 * and starts the FEP running.
4847 static void dgap_do_fep_load(struct board_t *brd, uchar __user *ufep, int len)
4852 if (!brd || (brd->magic != DGAP_BOARD_MAGIC) || !brd->re_map_membase)
4855 addr = brd->re_map_membase;
4857 DPR_INIT(("dgap_do_fep_load() for board %s : start\n", brd->name));
4863 if (dgap_usertoboard(brd, addr + offset, ufep, len) == -1 ) {
4864 brd->state = BOARD_FAILED;
4865 brd->dpastatus = BD_NOFEP;
4870 * If board is a concentrator product, we need to give
4871 * it its config string describing how the concentrators look.
4873 if ((brd->type == PCX) || (brd->type == PEPC)) {
4875 uchar *config, *xconfig;
4878 xconfig = dgap_create_config_string(brd, string);
4880 /* Write string to board memory */
4881 config = addr + CONFIG;
4882 for (; i < CONFIGSIZE; i++, config++, xconfig++) {
4883 writeb(*xconfig, config);
4884 if ((*xconfig & 0xff) == 0xff)
4889 writel(0xbfc01004, (addr + 0xc34));
4890 writel(0x3, (addr + 0xc30));
4892 /* change states. */
4893 brd->state = WAIT_FEP_LOAD;
4895 DPR_INIT(("dgap_do_fep_load() for board %s : finish\n", brd->name));
4901 * Waits for the FEP to report thats its ready for us to use.
4903 static void dgap_do_wait_for_fep(struct board_t *brd)
4908 if (!brd || (brd->magic != DGAP_BOARD_MAGIC) || !brd->re_map_membase)
4911 addr = brd->re_map_membase;
4913 DPR_INIT(("dgap_do_wait_for_fep() for board %s : start. addr: %p\n", brd->name, addr));
4915 word = readw(addr + FEPSTAT);
4917 /* Check to see if FEP is up and running now. */
4918 if (word == *(u16 *) "OS") {
4919 DPR_INIT(("GOT OS in memory for board %s, moving states.\n", brd->name));
4920 brd->state = FINISHED_FEP_LOAD;
4923 * Check to see if the board can support FEP5+ commands.
4925 word = readw(addr + FEP5_PLUS);
4926 if (word == *(u16 *) "5A") {
4927 DPR_INIT(("GOT 5A in memory for board %s, board supports extended FEP5 commands.\n", brd->name));
4928 brd->bd_flags |= BD_FEP5PLUS;
4934 /* Give up on board after too long of time taken */
4935 if (brd->wait_for_fep++ > 5000) {
4936 u16 err1 = readw(addr + SEQUENCE);
4937 u16 err2 = readw(addr + ERROR);
4938 APR(("***WARNING*** FEPOS for %s not functioning. Error #(%x,%x).\n",
4939 brd->name, err1, err2));
4940 brd->state = BOARD_FAILED;
4941 brd->dpastatus = BD_NOFEP;
4944 DPR_INIT(("dgap_do_wait_for_fep() for board %s : finish\n", brd->name));
4949 * Physically forces the FEP5 card to reset itself.
4951 static void dgap_do_reset_board(struct board_t *brd)
4958 if (!brd || (brd->magic != DGAP_BOARD_MAGIC) || !brd->re_map_membase || !brd->re_map_port) {
4959 DPR_INIT(("dgap_do_reset_board() start. bad values. brd: %p mem: %p io: %p\n",
4960 brd, brd ? brd->re_map_membase : 0, brd ? brd->re_map_port : 0));
4964 DPR_INIT(("dgap_do_reset_board() start. io: %p\n", brd->re_map_port));
4966 /* FEPRST does not vary among supported boards */
4967 writeb(FEPRST, brd->re_map_port);
4969 for (i = 0; i <= 1000; i++) {
4970 check = readb(brd->re_map_port) & 0xe;
4971 if (check == FEPRST)
4977 APR(("*** WARNING *** Board not resetting... Failing board.\n"));
4978 brd->state = BOARD_FAILED;
4979 brd->dpastatus = BD_NOFEP;
4984 * Make sure there really is memory out there.
4986 writel(0xa55a3cc3, (brd->re_map_membase + LOWMEM));
4987 writel(0x5aa5c33c, (brd->re_map_membase + HIGHMEM));
4988 check1 = readl(brd->re_map_membase + LOWMEM);
4989 check2 = readl(brd->re_map_membase + HIGHMEM);
4991 if ((check1 != 0xa55a3cc3) || (check2 != 0x5aa5c33c)) {
4992 APR(("*** Warning *** No memory at %p for board.\n", brd->re_map_membase));
4993 brd->state = BOARD_FAILED;
4994 brd->dpastatus = BD_NOFEP;
4998 if (brd->state != BOARD_FAILED)
4999 brd->state = FINISHED_RESET;
5002 DPR_INIT(("dgap_do_reset_board() finish\n"));
5007 * Sends a concentrator image into the FEP5 board.
5009 static void dgap_do_conc_load(struct board_t *brd, uchar *uaddr, int len)
5013 struct downld_t *to_dp;
5015 if (!brd || (brd->magic != DGAP_BOARD_MAGIC) || !brd->re_map_membase)
5018 vaddr = brd->re_map_membase;
5020 offset = readw((u16 *) (vaddr + DOWNREQ));
5021 to_dp = (struct downld_t *) (vaddr + (int) offset);
5024 * The image was already read into kernel space,
5025 * we do NOT need a user space read here
5027 memcpy_toio((char *) to_dp, uaddr, sizeof(struct downld_t));
5029 /* Tell card we have data for it */
5030 writew(0, vaddr + (DOWNREQ));
5032 brd->conc_dl_status = NO_PENDING_CONCENTRATOR_REQUESTS;
5036 #define EXPANSION_ROM_SIZE (64 * 1024)
5037 #define FEP5_ROM_MAGIC (0xFEFFFFFF)
5039 static void dgap_get_vpd(struct board_t *brd)
5051 * Poke the magic number at the PCI Rom Address location.
5052 * If VPD is supported, the value read from that address
5055 magic = FEP5_ROM_MAGIC;
5056 pci_write_config_dword(brd->pdev, PCI_ROM_ADDRESS, magic);
5057 pci_read_config_dword(brd->pdev, PCI_ROM_ADDRESS, &magic);
5059 /* VPD not supported, bail */
5064 * To get to the OTPROM memory, we have to send the boards base
5065 * address or'ed with 1 into the PCI Rom Address location.
5067 magic = brd->membase | 0x01;
5068 pci_write_config_dword(brd->pdev, PCI_ROM_ADDRESS, magic);
5069 pci_read_config_dword(brd->pdev, PCI_ROM_ADDRESS, &magic);
5071 byte1 = readb(brd->re_map_membase);
5072 byte2 = readb(brd->re_map_membase + 1);
5075 * If the board correctly swapped to the OTPROM memory,
5076 * the first 2 bytes (header) should be 0x55, 0xAA
5078 if (byte1 == 0x55 && byte2 == 0xAA) {
5083 * We have to run through all the OTPROM memory looking
5084 * for the VPD offset.
5086 while (base_offset <= EXPANSION_ROM_SIZE) {
5089 * Lots of magic numbers here.
5091 * The VPD offset is located inside the ROM Data Structure.
5092 * We also have to remember the length of each
5093 * ROM Data Structure, so we can "hop" to the next
5094 * entry if the VPD isn't in the current
5095 * ROM Data Structure.
5097 rom_offset = readw(brd->re_map_membase + base_offset + 0x18);
5098 image_length = readw(brd->re_map_membase + rom_offset + 0x10) * 512;
5099 vpd_offset = readw(brd->re_map_membase + rom_offset + 0x08);
5101 /* Found the VPD entry */
5105 /* We didn't find a VPD entry, go to next ROM entry. */
5106 base_offset += image_length;
5108 byte1 = readb(brd->re_map_membase + base_offset);
5109 byte2 = readb(brd->re_map_membase + base_offset + 1);
5112 * If the new ROM offset doesn't have 0x55, 0xAA
5113 * as its header, we have run out of ROM.
5115 if (byte1 != 0x55 || byte2 != 0xAA)
5120 * If we have a VPD offset, then mark the board
5121 * as having a valid VPD, and copy VPDSIZE (512) bytes of
5122 * that VPD to the buffer we have in our board structure.
5125 brd->bd_flags |= BD_HAS_VPD;
5126 for (i = 0; i < VPDSIZE; i++)
5127 brd->vpd[i] = readb(brd->re_map_membase + vpd_offset + i);
5132 * We MUST poke the magic number at the PCI Rom Address location again.
5133 * This makes the card report the regular board memory back to us,
5134 * rather than the OTPROM memory.
5136 magic = FEP5_ROM_MAGIC;
5137 pci_write_config_dword(brd->pdev, PCI_ROM_ADDRESS, magic);
5142 * Our board poller function.
5144 static void dgap_poll_tasklet(unsigned long data)
5146 struct board_t *bd = (struct board_t *) data;
5154 if (!bd || (bd->magic != DGAP_BOARD_MAGIC)) {
5155 APR(("dgap_poll_tasklet() - NULL or bad bd.\n"));
5159 if (bd->inhibit_poller)
5162 DGAP_LOCK(bd->bd_lock, lock_flags);
5164 vaddr = bd->re_map_membase;
5167 * If board is ready, parse deeper to see if there is anything to do.
5169 if (bd->state == BOARD_READY) {
5171 struct ev_t *eaddr = NULL;
5173 if (!bd->re_map_membase) {
5174 DGAP_UNLOCK(bd->bd_lock, lock_flags);
5177 if (!bd->re_map_port) {
5178 DGAP_UNLOCK(bd->bd_lock, lock_flags);
5187 * If this is a CX or EPCX, we need to see if the firmware
5188 * is requesting a concentrator image from us.
5190 if ((bd->type == PCX) || (bd->type == PEPC)) {
5191 chk_addr = (u16 *) (vaddr + DOWNREQ);
5192 check = readw(chk_addr);
5193 /* Nonzero if FEP is requesting concentrator image. */
5195 if (bd->conc_dl_status == NO_PENDING_CONCENTRATOR_REQUESTS)
5196 bd->conc_dl_status = NEED_CONCENTRATOR;
5198 * Signal downloader, its got some work to do.
5200 DGAP_LOCK(dgap_dl_lock, lock_flags2);
5201 if (dgap_dl_action != 1) {
5203 wake_up_interruptible(&dgap_dl_wait);
5205 DGAP_UNLOCK(dgap_dl_lock, lock_flags2);
5210 eaddr = (struct ev_t *) (vaddr + EVBUF);
5212 /* Get our head and tail */
5213 head = readw(&(eaddr->ev_head));
5214 tail = readw(&(eaddr->ev_tail));
5217 * If there is an event pending. Go service it.
5220 DGAP_UNLOCK(bd->bd_lock, lock_flags);
5222 DGAP_LOCK(bd->bd_lock, lock_flags);
5227 * If board is doing interrupts, ACK the interrupt.
5229 if (bd && bd->intr_running) {
5230 readb(bd->re_map_port + 2);
5233 DGAP_UNLOCK(bd->bd_lock, lock_flags);
5237 /* Our state machine to get the board up and running */
5240 if (bd->state == NEED_RESET) {
5245 dgap_do_reset_board(bd);
5248 /* Move to next state */
5249 if (bd->state == FINISHED_RESET) {
5250 bd->state = NEED_CONFIG;
5253 if (bd->state == NEED_CONFIG) {
5255 * Match this board to a config the user created for us.
5257 bd->bd_config = dgap_find_config(bd->type, bd->pci_bus, bd->pci_slot);
5260 * Because the 4 port Xr products share the same PCI ID
5261 * as the 8 port Xr products, if we receive a NULL config
5262 * back, and this is a PAPORT8 board, retry with a
5263 * PAPORT4 attempt as well.
5265 if (bd->type == PAPORT8 && !bd->bd_config) {
5266 bd->bd_config = dgap_find_config(PAPORT4, bd->pci_bus, bd->pci_slot);
5270 * Register the ttys (if any) into the kernel.
5272 if (bd->bd_config) {
5273 bd->state = FINISHED_CONFIG;
5276 bd->state = CONFIG_NOT_FOUND;
5280 /* Move to next state */
5281 if (bd->state == FINISHED_CONFIG) {
5282 bd->state = NEED_DEVICE_CREATION;
5285 /* Move to next state */
5286 if (bd->state == NEED_DEVICE_CREATION) {
5288 * Signal downloader, its got some work to do.
5290 DGAP_LOCK(dgap_dl_lock, lock_flags2);
5291 if (dgap_dl_action != 1) {
5293 wake_up_interruptible(&dgap_dl_wait);
5295 DGAP_UNLOCK(dgap_dl_lock, lock_flags2);
5298 /* Move to next state */
5299 if (bd->state == FINISHED_DEVICE_CREATION) {
5300 bd->state = NEED_BIOS_LOAD;
5303 /* Move to next state */
5304 if (bd->state == NEED_BIOS_LOAD) {
5306 * Signal downloader, its got some work to do.
5308 DGAP_LOCK(dgap_dl_lock, lock_flags2);
5309 if (dgap_dl_action != 1) {
5311 wake_up_interruptible(&dgap_dl_wait);
5313 DGAP_UNLOCK(dgap_dl_lock, lock_flags2);
5316 /* Wait for BIOS to test board... */
5317 if (bd->state == WAIT_BIOS_LOAD) {
5318 dgap_do_wait_for_bios(bd);
5321 /* Move to next state */
5322 if (bd->state == FINISHED_BIOS_LOAD) {
5323 bd->state = NEED_FEP_LOAD;
5326 * Signal downloader, its got some work to do.
5328 DGAP_LOCK(dgap_dl_lock, lock_flags2);
5329 if (dgap_dl_action != 1) {
5331 wake_up_interruptible(&dgap_dl_wait);
5333 DGAP_UNLOCK(dgap_dl_lock, lock_flags2);
5336 /* Wait for FEP to load on board... */
5337 if (bd->state == WAIT_FEP_LOAD) {
5338 dgap_do_wait_for_fep(bd);
5342 /* Move to next state */
5343 if (bd->state == FINISHED_FEP_LOAD) {
5346 * Do tty device initialization.
5348 int rc = dgap_tty_init(bd);
5351 dgap_tty_uninit(bd);
5352 APR(("Can't init tty devices (%d)\n", rc));
5353 bd->state = BOARD_FAILED;
5354 bd->dpastatus = BD_NOFEP;
5357 bd->state = NEED_PROC_CREATION;
5360 * Signal downloader, its got some work to do.
5362 DGAP_LOCK(dgap_dl_lock, lock_flags2);
5363 if (dgap_dl_action != 1) {
5365 wake_up_interruptible(&dgap_dl_wait);
5367 DGAP_UNLOCK(dgap_dl_lock, lock_flags2);
5371 /* Move to next state */
5372 if (bd->state == FINISHED_PROC_CREATION) {
5374 bd->state = BOARD_READY;
5375 bd->dpastatus = BD_RUNNING;
5378 * If user requested the board to run in interrupt mode,
5379 * go and set it up on the board.
5381 if (bd->intr_used) {
5382 writew(1, (bd->re_map_membase + ENABLE_INTR));
5384 * Tell the board to poll the UARTS as fast as possible.
5386 writew(FEPPOLL_MIN, (bd->re_map_membase + FEPPOLL));
5387 bd->intr_running = 1;
5390 /* Wake up anyone waiting for board state to change to ready */
5391 wake_up_interruptible(&bd->state_wait);
5394 DGAP_UNLOCK(bd->bd_lock, lock_flags);
5398 /*=======================================================================
5400 * dgap_cmdb - Sends a 2 byte command to the FEP.
5402 * ch - Pointer to channel structure.
5403 * cmd - Command to be sent.
5404 * byte1 - Integer containing first byte to be sent.
5405 * byte2 - Integer containing second byte to be sent.
5406 * ncmds - Wait until ncmds or fewer cmds are left
5407 * in the cmd buffer before returning.
5409 *=======================================================================*/
5410 static void dgap_cmdb(struct channel_t *ch, uchar cmd, uchar byte1, uchar byte2, uint ncmds)
5413 struct cm_t *cm_addr = NULL;
5419 if (!ch || ch->magic != DGAP_CHANNEL_MAGIC)
5423 * Check if board is still alive.
5425 if (ch->ch_bd->state == BOARD_FAILED) {
5426 DPR_CORE(("%s:%d board is in failed state.\n", __FILE__, __LINE__));
5431 * Make sure the pointers are in range before
5432 * writing to the FEP memory.
5434 vaddr = ch->ch_bd->re_map_membase;
5439 cm_addr = (struct cm_t *) (vaddr + CMDBUF);
5440 head = readw(&(cm_addr->cm_head));
5443 * Forget it if pointers out of range.
5445 if (head >= (CMDMAX - CMDSTART) || (head & 03)) {
5446 DPR_CORE(("%s:%d pointers out of range, failing board!\n", __FILE__, __LINE__));
5447 ch->ch_bd->state = BOARD_FAILED;
5452 * Put the data in the circular command buffer.
5454 writeb(cmd, (char *) (vaddr + head + CMDSTART + 0));
5455 writeb((uchar) ch->ch_portnum, (char *) (vaddr + head + CMDSTART + 1));
5456 writeb(byte1, (char *) (vaddr + head + CMDSTART + 2));
5457 writeb(byte2, (char *) (vaddr + head + CMDSTART + 3));
5459 head = (head + 4) & (CMDMAX - CMDSTART - 4);
5461 writew(head, &(cm_addr->cm_head));
5464 * Wait if necessary before updating the head
5465 * pointer to limit the number of outstanding
5466 * commands to the FEP. If the time spent waiting
5467 * is outlandish, declare the FEP dead.
5469 for (count = dgap_count ;;) {
5471 head = readw(&(cm_addr->cm_head));
5472 tail = readw(&(cm_addr->cm_tail));
5474 n = (head - tail) & (CMDMAX - CMDSTART - 4);
5476 if (n <= ncmds * sizeof(struct cm_t))
5480 DPR_CORE(("%s:%d failing board.\n",__FILE__, __LINE__));
5481 ch->ch_bd->state = BOARD_FAILED;
5489 /*=======================================================================
5491 * dgap_cmdw - Sends a 1 word command to the FEP.
5493 * ch - Pointer to channel structure.
5494 * cmd - Command to be sent.
5495 * word - Integer containing word to be sent.
5496 * ncmds - Wait until ncmds or fewer cmds are left
5497 * in the cmd buffer before returning.
5499 *=======================================================================*/
5500 static void dgap_cmdw(struct channel_t *ch, uchar cmd, u16 word, uint ncmds)
5503 struct cm_t *cm_addr = NULL;
5509 if (!ch || ch->magic != DGAP_CHANNEL_MAGIC)
5513 * Check if board is still alive.
5515 if (ch->ch_bd->state == BOARD_FAILED) {
5516 DPR_CORE(("%s:%d board is failed!\n", __FILE__, __LINE__));
5521 * Make sure the pointers are in range before
5522 * writing to the FEP memory.
5524 vaddr = ch->ch_bd->re_map_membase;
5528 cm_addr = (struct cm_t *) (vaddr + CMDBUF);
5529 head = readw(&(cm_addr->cm_head));
5532 * Forget it if pointers out of range.
5534 if (head >= (CMDMAX - CMDSTART) || (head & 03)) {
5535 DPR_CORE(("%s:%d Pointers out of range. Failing board.\n",__FILE__, __LINE__));
5536 ch->ch_bd->state = BOARD_FAILED;
5541 * Put the data in the circular command buffer.
5543 writeb(cmd, (char *) (vaddr + head + CMDSTART + 0));
5544 writeb((uchar) ch->ch_portnum, (char *) (vaddr + head + CMDSTART + 1));
5545 writew((u16) word, (char *) (vaddr + head + CMDSTART + 2));
5547 head = (head + 4) & (CMDMAX - CMDSTART - 4);
5549 writew(head, &(cm_addr->cm_head));
5552 * Wait if necessary before updating the head
5553 * pointer to limit the number of outstanding
5554 * commands to the FEP. If the time spent waiting
5555 * is outlandish, declare the FEP dead.
5557 for (count = dgap_count ;;) {
5559 head = readw(&(cm_addr->cm_head));
5560 tail = readw(&(cm_addr->cm_tail));
5562 n = (head - tail) & (CMDMAX - CMDSTART - 4);
5564 if (n <= ncmds * sizeof(struct cm_t))
5568 DPR_CORE(("%s:%d Failing board.\n",__FILE__, __LINE__));
5569 ch->ch_bd->state = BOARD_FAILED;
5578 /*=======================================================================
5580 * dgap_cmdw_ext - Sends a extended word command to the FEP.
5582 * ch - Pointer to channel structure.
5583 * cmd - Command to be sent.
5584 * word - Integer containing word to be sent.
5585 * ncmds - Wait until ncmds or fewer cmds are left
5586 * in the cmd buffer before returning.
5588 *=======================================================================*/
5589 static void dgap_cmdw_ext(struct channel_t *ch, u16 cmd, u16 word, uint ncmds)
5592 struct cm_t *cm_addr = NULL;
5598 if (!ch || ch->magic != DGAP_CHANNEL_MAGIC)
5602 * Check if board is still alive.
5604 if (ch->ch_bd->state == BOARD_FAILED) {
5605 DPR_CORE(("%s:%d board is failed!\n", __FILE__, __LINE__));
5610 * Make sure the pointers are in range before
5611 * writing to the FEP memory.
5613 vaddr = ch->ch_bd->re_map_membase;
5617 cm_addr = (struct cm_t *) (vaddr + CMDBUF);
5618 head = readw(&(cm_addr->cm_head));
5621 * Forget it if pointers out of range.
5623 if (head >= (CMDMAX - CMDSTART) || (head & 03)) {
5624 DPR_CORE(("%s:%d Pointers out of range. Failing board.\n",__FILE__, __LINE__));
5625 ch->ch_bd->state = BOARD_FAILED;
5630 * Put the data in the circular command buffer.
5633 /* Write an FF to tell the FEP that we want an extended command */
5634 writeb((uchar) 0xff, (char *) (vaddr + head + CMDSTART + 0));
5636 writeb((uchar) ch->ch_portnum, (uchar *) (vaddr + head + CMDSTART + 1));
5637 writew((u16) cmd, (char *) (vaddr + head + CMDSTART + 2));
5640 * If the second part of the command won't fit,
5641 * put it at the beginning of the circular buffer.
5643 if (((head + 4) >= ((CMDMAX - CMDSTART)) || (head & 03))) {
5644 writew((u16) word, (char *) (vaddr + CMDSTART));
5646 writew((u16) word, (char *) (vaddr + head + CMDSTART + 4));
5649 head = (head + 8) & (CMDMAX - CMDSTART - 4);
5651 writew(head, &(cm_addr->cm_head));
5654 * Wait if necessary before updating the head
5655 * pointer to limit the number of outstanding
5656 * commands to the FEP. If the time spent waiting
5657 * is outlandish, declare the FEP dead.
5659 for (count = dgap_count ;;) {
5661 head = readw(&(cm_addr->cm_head));
5662 tail = readw(&(cm_addr->cm_tail));
5664 n = (head - tail) & (CMDMAX - CMDSTART - 4);
5666 if (n <= ncmds * sizeof(struct cm_t))
5670 DPR_CORE(("%s:%d Failing board.\n",__FILE__, __LINE__));
5671 ch->ch_bd->state = BOARD_FAILED;
5679 /*=======================================================================
5681 * dgap_wmove - Write data to FEP buffer.
5683 * ch - Pointer to channel structure.
5684 * buf - Poiter to characters to be moved.
5685 * cnt - Number of characters to move.
5687 *=======================================================================*/
5688 static void dgap_wmove(struct channel_t *ch, char *buf, uint cnt)
5695 if (!ch || ch->magic != DGAP_CHANNEL_MAGIC)
5702 head = readw(&(bs->tx_head));
5705 * If pointers are out of range, just return.
5707 if ((cnt > ch->ch_tsize) || (unsigned)(head - ch->ch_tstart) >= ch->ch_tsize) {
5708 DPR_CORE(("%s:%d pointer out of range", __FILE__, __LINE__));
5713 * If the write wraps over the top of the circular buffer,
5714 * move the portion up to the wrap point, and reset the
5715 * pointers to the bottom.
5717 n = ch->ch_tstart + ch->ch_tsize - head;
5721 taddr = ch->ch_taddr + head;
5722 memcpy_toio(taddr, buf, n);
5723 head = ch->ch_tstart;
5728 * Move rest of data.
5730 taddr = ch->ch_taddr + head;
5732 memcpy_toio(taddr, buf, n);
5735 writew(head, &(bs->tx_head));
5739 * Retrives the current custom baud rate from FEP memory,
5740 * and returns it back to the user.
5741 * Returns 0 on error.
5743 static uint dgap_get_custom_baud(struct channel_t *ch)
5749 if (!ch || ch->magic != DGAP_CHANNEL_MAGIC) {
5753 if (!ch->ch_bd || ch->ch_bd->magic != DGAP_BOARD_MAGIC) {
5757 if (!(ch->ch_bd->bd_flags & BD_FEP5PLUS))
5760 vaddr = ch->ch_bd->re_map_membase;
5766 * Go get from fep mem, what the fep
5767 * believes the custom baud rate is.
5769 offset = ((((*(unsigned short *)(vaddr + ECS_SEG)) << 4) +
5770 (ch->ch_portnum * 0x28) + LINE_SPEED));
5772 value = readw(vaddr + offset);
5778 * Calls the firmware to reset this channel.
5780 static void dgap_firmware_reset_port(struct channel_t *ch)
5782 dgap_cmdb(ch, CHRESET, 0, 0, 0);
5785 * Now that the channel is reset, we need to make sure
5786 * all the current settings get reapplied to the port
5789 * So we will set the driver's cache of firmware
5790 * settings all to 0, and then call param.
5792 ch->ch_fepiflag = 0;
5793 ch->ch_fepcflag = 0;
5794 ch->ch_fepoflag = 0;
5795 ch->ch_fepstartc = 0;
5796 ch->ch_fepstopc = 0;
5797 ch->ch_fepastartc = 0;
5798 ch->ch_fepastopc = 0;
5804 /*=======================================================================
5806 * dgap_param - Set Digi parameters.
5808 * struct tty_struct * - TTY for port.
5810 *=======================================================================*/
5811 static int dgap_param(struct tty_struct *tty)
5813 struct ktermios *ts;
5815 struct channel_t *ch;
5824 if (!tty || tty->magic != TTY_MAGIC)
5827 un = (struct un_t *) tty->driver_data;
5828 if (!un || un->magic != DGAP_UNIT_MAGIC)
5832 if (!ch || ch->magic != DGAP_CHANNEL_MAGIC)
5836 if (!bd || bd->magic != DGAP_BOARD_MAGIC)
5843 DPR_PARAM(("param start: tdev: %x cflags: %x oflags: %x iflags: %x\n",
5844 ch->ch_tun.un_dev, ch->ch_c_cflag, ch->ch_c_oflag, ch->ch_c_iflag));
5849 * If baud rate is zero, flush queues, and set mval to drop DTR.
5851 if ((ch->ch_c_cflag & (CBAUD)) == 0) {
5854 head = readw(&(ch->ch_bs->rx_head));
5855 writew(head, &(ch->ch_bs->rx_tail));
5858 head = readw(&(ch->ch_bs->tx_head));
5859 writew(head, &(ch->ch_bs->tx_tail));
5861 ch->ch_flags |= (CH_BAUD0);
5863 /* Drop RTS and DTR */
5864 ch->ch_mval &= ~(D_RTS(ch)|D_DTR(ch));
5865 mval = D_DTR(ch) | D_RTS(ch);
5866 ch->ch_baud_info = 0;
5868 } else if (ch->ch_custom_speed && (bd->bd_flags & BD_FEP5PLUS)) {
5870 * Tell the fep to do the command
5873 DPR_PARAM(("param: Want %d speed\n", ch->ch_custom_speed));
5875 dgap_cmdw_ext(ch, 0xff01, ch->ch_custom_speed, 0);
5878 * Now go get from fep mem, what the fep
5879 * believes the custom baud rate is.
5881 ch->ch_baud_info = ch->ch_custom_speed = dgap_get_custom_baud(ch);
5883 DPR_PARAM(("param: Got %d speed\n", ch->ch_custom_speed));
5885 /* Handle transition from B0 */
5886 if (ch->ch_flags & CH_BAUD0) {
5887 ch->ch_flags &= ~(CH_BAUD0);
5888 ch->ch_mval |= (D_RTS(ch)|D_DTR(ch));
5890 mval = D_DTR(ch) | D_RTS(ch);
5894 * Set baud rate, character size, and parity.
5902 ulong bauds[4][16] = {
5906 600, 1200, 1800, 2400,
5907 4800, 9600, 19200, 38400 },
5908 { /* slowbaud & CBAUDEX */
5909 0, 57600, 115200, 230400,
5910 460800, 150, 200, 921600,
5911 600, 1200, 1800, 2400,
5912 4800, 9600, 19200, 38400 },
5914 0, 57600, 76800, 115200,
5915 14400, 57600, 230400, 76800,
5916 115200, 230400, 28800, 460800,
5917 921600, 9600, 19200, 38400 },
5918 { /* fastbaud & CBAUDEX */
5919 0, 57600, 115200, 230400,
5920 460800, 150, 200, 921600,
5921 600, 1200, 1800, 2400,
5922 4800, 9600, 19200, 38400 }
5925 /* Only use the TXPrint baud rate if the terminal unit is NOT open */
5926 if (!(ch->ch_tun.un_flags & UN_ISOPEN) && (un->un_type == DGAP_PRINT))
5927 baud = C_BAUD(ch->ch_pun.un_tty) & 0xff;
5929 baud = C_BAUD(ch->ch_tun.un_tty) & 0xff;
5931 if (ch->ch_c_cflag & CBAUDEX)
5934 if (ch->ch_digi.digi_flags & DIGI_FAST)
5939 if ((iindex >= 0) && (iindex < 4) && (jindex >= 0) && (jindex < 16)) {
5940 baud = bauds[iindex][jindex];
5942 DPR_IOCTL(("baud indices were out of range (%d)(%d)",
5950 ch->ch_baud_info = baud;
5954 * CBAUD has bit position 0x1000 set these days to indicate Linux
5956 * We use a different bit assignment for high speed. Clear this
5957 * bit out while grabbing the parts of "cflag" we want.
5959 cflag = ch->ch_c_cflag & ((CBAUD ^ CBAUDEX) | PARODD | PARENB | CSTOPB | CSIZE);
5962 * HUPCL bit is used by FEP to indicate fast baud
5963 * table is to be used.
5965 if ((ch->ch_digi.digi_flags & DIGI_FAST) || (ch->ch_c_cflag & CBAUDEX))
5969 if ((ch->ch_c_cflag & CBAUDEX) && !(ch->ch_digi.digi_flags & DIGI_FAST)) {
5971 * The below code is trying to guarantee that only baud rates
5972 * 115200, 230400, 460800, 921600 are remapped. We use exclusive or
5973 * because the various baud rates share common bit positions
5974 * and therefore can't be tested for easily.
5976 tcflag_t tcflag = (ch->ch_c_cflag & CBAUD) | CBAUDEX;
5979 /* Map high speed requests to index into FEP's baud table */
6008 cflag = (cflag & ~(CBAUD | CBAUDEX)) | baudpart;
6013 if (cflag != ch->ch_fepcflag) {
6014 ch->ch_fepcflag = (u16) (cflag & 0xffff);
6016 /* Okay to have channel and board locks held calling this */
6017 dgap_cmdw(ch, SCFLAG, (u16) cflag, 0);
6020 /* Handle transition from B0 */
6021 if (ch->ch_flags & CH_BAUD0) {
6022 ch->ch_flags &= ~(CH_BAUD0);
6023 ch->ch_mval |= (D_RTS(ch)|D_DTR(ch));
6025 mval = D_DTR(ch) | D_RTS(ch);
6031 iflag = ch->ch_c_iflag & (IGNBRK | BRKINT | IGNPAR | PARMRK | INPCK | ISTRIP | IXON | IXANY | IXOFF);
6033 if ((ch->ch_startc == _POSIX_VDISABLE) || (ch->ch_stopc == _POSIX_VDISABLE)) {
6034 iflag &= ~(IXON | IXOFF);
6035 ch->ch_c_iflag &= ~(IXON | IXOFF);
6039 * Only the IBM Xr card can switch between
6040 * 232 and 422 modes on the fly
6042 if (bd->device == PCI_DEVICE_XR_IBM_DID) {
6043 if (ch->ch_digi.digi_flags & DIGI_422)
6044 dgap_cmdb(ch, SCOMMODE, MODE_422, 0, 0);
6046 dgap_cmdb(ch, SCOMMODE, MODE_232, 0, 0);
6049 if (ch->ch_digi.digi_flags & DIGI_ALTPIN)
6052 if (iflag != ch->ch_fepiflag) {
6053 ch->ch_fepiflag = iflag;
6055 /* Okay to have channel and board locks held calling this */
6056 dgap_cmdw(ch, SIFLAG, (u16) ch->ch_fepiflag, 0);
6060 * Select hardware handshaking.
6064 if (ch->ch_c_cflag & CRTSCTS) {
6065 hflow |= (D_RTS(ch) | D_CTS(ch));
6067 if (ch->ch_digi.digi_flags & RTSPACE)
6069 if (ch->ch_digi.digi_flags & DTRPACE)
6071 if (ch->ch_digi.digi_flags & CTSPACE)
6073 if (ch->ch_digi.digi_flags & DSRPACE)
6075 if (ch->ch_digi.digi_flags & DCDPACE)
6078 if (hflow != ch->ch_hflow) {
6079 ch->ch_hflow = hflow;
6081 /* Okay to have channel and board locks held calling this */
6082 dgap_cmdb(ch, SHFLOW, (uchar) hflow, 0xff, 0);
6087 * Set RTS and/or DTR Toggle if needed, but only if product is FEP5+ based.
6089 if (bd->bd_flags & BD_FEP5PLUS) {
6091 if (ch->ch_digi.digi_flags & DIGI_RTS_TOGGLE) {
6092 hflow2 |= (D_RTS(ch));
6094 if (ch->ch_digi.digi_flags & DIGI_DTR_TOGGLE) {
6095 hflow2 |= (D_DTR(ch));
6098 dgap_cmdw_ext(ch, 0xff03, hflow2, 0);
6102 * Set modem control lines.
6105 mval ^= ch->ch_mforce & (mval ^ ch->ch_mval);
6107 DPR_PARAM(("dgap_param: mval: %x ch_mforce: %x ch_mval: %x ch_mostat: %x\n",
6108 mval, ch->ch_mforce, ch->ch_mval, ch->ch_mostat));
6110 if (ch->ch_mostat ^ mval) {
6111 ch->ch_mostat = mval;
6113 /* Okay to have channel and board locks held calling this */
6114 DPR_PARAM(("dgap_param: Sending SMODEM mval: %x\n", mval));
6115 dgap_cmdb(ch, SMODEM, (uchar) mval, D_RTS(ch)|D_DTR(ch), 0);
6119 * Read modem signals, and then call carrier function.
6121 ch->ch_mistat = readb(&(bs->m_stat));
6125 * Set the start and stop characters.
6127 if (ch->ch_startc != ch->ch_fepstartc || ch->ch_stopc != ch->ch_fepstopc) {
6128 ch->ch_fepstartc = ch->ch_startc;
6129 ch->ch_fepstopc = ch->ch_stopc;
6131 /* Okay to have channel and board locks held calling this */
6132 dgap_cmdb(ch, SFLOWC, ch->ch_fepstartc, ch->ch_fepstopc, 0);
6136 * Set the Auxiliary start and stop characters.
6138 if (ch->ch_astartc != ch->ch_fepastartc || ch->ch_astopc != ch->ch_fepastopc) {
6139 ch->ch_fepastartc = ch->ch_astartc;
6140 ch->ch_fepastopc = ch->ch_astopc;
6142 /* Okay to have channel and board locks held calling this */
6143 dgap_cmdb(ch, SAFLOWC, ch->ch_fepastartc, ch->ch_fepastopc, 0);
6146 DPR_PARAM(("param finish\n"));
6153 * dgap_parity_scan()
6155 * Convert the FEP5 way of reporting parity errors and breaks into
6156 * the Linux line discipline way.
6158 static void dgap_parity_scan(struct channel_t *ch, unsigned char *cbuf, unsigned char *fbuf, int *len)
6162 unsigned char *in, *cout, *fout;
6169 DPR_PSCAN(("dgap_parity_scan start\n"));
6171 if (!ch || ch->magic != DGAP_CHANNEL_MAGIC)
6176 switch (ch->pscan_state) {
6178 /* reset to sanity and fall through */
6179 ch->pscan_state = 0;
6182 /* No FF seen yet */
6183 if (c == (unsigned char) '\377') {
6184 /* delete this character from stream */
6185 ch->pscan_state = 1;
6188 *fout++ = TTY_NORMAL;
6195 if (c == (unsigned char) '\377') {
6196 /* doubled ff, transform to single ff */
6198 *fout++ = TTY_NORMAL;
6200 ch->pscan_state = 0;
6202 /* save value examination in next state */
6203 ch->pscan_savechar = c;
6204 ch->pscan_state = 2;
6209 /* third character of ff sequence */
6213 if (ch->pscan_savechar == 0x0) {
6216 DPR_PSCAN(("dgap_parity_scan in 3rd char of ff seq. c: %x setting break.\n", c));
6218 *fout++ = TTY_BREAK;
6221 DPR_PSCAN(("dgap_parity_scan in 3rd char of ff seq. c: %x setting parity.\n", c));
6222 ch->ch_err_parity++;
6223 *fout++ = TTY_PARITY;
6227 DPR_PSCAN(("%s:%d Logic Error.\n", __FILE__, __LINE__));
6231 ch->pscan_state = 0;
6235 DPR_PSCAN(("dgap_parity_scan finish\n"));
6241 /*=======================================================================
6243 * dgap_event - FEP to host event processing routine.
6245 * bd - Board of current event.
6247 *=======================================================================*/
6248 static int dgap_event(struct board_t *bd)
6250 struct channel_t *ch;
6255 uchar *vaddr = NULL;
6256 struct ev_t *eaddr = NULL;
6264 if (!bd || bd->magic != DGAP_BOARD_MAGIC)
6267 DGAP_LOCK(bd->bd_lock, lock_flags);
6269 vaddr = bd->re_map_membase;
6272 DGAP_UNLOCK(bd->bd_lock, lock_flags);
6276 eaddr = (struct ev_t *) (vaddr + EVBUF);
6278 /* Get our head and tail */
6279 head = readw(&(eaddr->ev_head));
6280 tail = readw(&(eaddr->ev_tail));
6283 * Forget it if pointers out of range.
6286 if (head >= EVMAX - EVSTART || tail >= EVMAX - EVSTART ||
6287 (head | tail) & 03) {
6288 DPR_EVENT(("should be calling xxfail %d\n", __LINE__));
6289 /* Let go of board lock */
6290 DGAP_UNLOCK(bd->bd_lock, lock_flags);
6295 * Loop to process all the events in the buffer.
6297 while (tail != head) {
6300 * Get interrupt information.
6303 event = bd->re_map_membase + tail + EVSTART;
6310 DPR_EVENT(("event: jiffies: %ld port: %d reason: %x modem: %x\n",
6311 jiffies, port, reason, modem));
6314 * Make sure the interrupt is valid.
6316 if (port >= bd->nasync)
6319 if (!(reason & (IFMODEM | IFBREAK | IFTLW | IFTEM | IFDATA))) {
6323 ch = bd->channels[port];
6325 if (!ch || ch->magic != DGAP_CHANNEL_MAGIC) {
6330 * If we have made it here, the event was valid.
6331 * Lock down the channel.
6333 DGAP_LOCK(ch->ch_lock, lock_flags2);
6338 DGAP_UNLOCK(ch->ch_lock, lock_flags2);
6343 * Process received data.
6345 if (reason & IFDATA) {
6348 * ALL LOCKS *MUST* BE DROPPED BEFORE CALLING INPUT!
6349 * input could send some data to ld, which in turn
6350 * could do a callback to one of our other functions.
6352 DGAP_UNLOCK(ch->ch_lock, lock_flags2);
6353 DGAP_UNLOCK(bd->bd_lock, lock_flags);
6357 DGAP_LOCK(bd->bd_lock, lock_flags);
6358 DGAP_LOCK(ch->ch_lock, lock_flags2);
6360 if (ch->ch_flags & CH_RACTIVE)
6361 ch->ch_flags |= CH_RENABLE;
6363 writeb(1, &(bs->idata));
6365 if (ch->ch_flags & CH_RWAIT) {
6366 ch->ch_flags &= ~CH_RWAIT;
6368 wake_up_interruptible(&ch->ch_tun.un_flags_wait);
6373 * Process Modem change signals.
6375 if (reason & IFMODEM) {
6376 ch->ch_mistat = modem;
6383 if (reason & IFBREAK) {
6385 DPR_EVENT(("got IFBREAK\n"));
6387 if (ch->ch_tun.un_tty) {
6388 /* A break has been indicated */
6390 tty_buffer_request_room(ch->ch_tun.un_tty->port, 1);
6391 tty_insert_flip_char(ch->ch_tun.un_tty->port, 0, TTY_BREAK);
6392 tty_flip_buffer_push(ch->ch_tun.un_tty->port);
6397 * Process Transmit low.
6399 if (reason & IFTLW) {
6401 DPR_EVENT(("event: got low event\n"));
6403 if (ch->ch_tun.un_flags & UN_LOW) {
6404 ch->ch_tun.un_flags &= ~UN_LOW;
6406 if (ch->ch_tun.un_flags & UN_ISOPEN) {
6407 if ((ch->ch_tun.un_tty->flags &
6408 (1 << TTY_DO_WRITE_WAKEUP)) &&
6409 ch->ch_tun.un_tty->ldisc->ops->write_wakeup)
6411 DGAP_UNLOCK(ch->ch_lock, lock_flags2);
6412 DGAP_UNLOCK(bd->bd_lock, lock_flags);
6413 (ch->ch_tun.un_tty->ldisc->ops->write_wakeup)(ch->ch_tun.un_tty);
6414 DGAP_LOCK(bd->bd_lock, lock_flags);
6415 DGAP_LOCK(ch->ch_lock, lock_flags2);
6417 wake_up_interruptible(&ch->ch_tun.un_tty->write_wait);
6418 wake_up_interruptible(&ch->ch_tun.un_flags_wait);
6420 DPR_EVENT(("event: Got low event. jiffies: %lu\n", jiffies));
6424 if (ch->ch_pun.un_flags & UN_LOW) {
6425 ch->ch_pun.un_flags &= ~UN_LOW;
6426 if (ch->ch_pun.un_flags & UN_ISOPEN) {
6427 if ((ch->ch_pun.un_tty->flags &
6428 (1 << TTY_DO_WRITE_WAKEUP)) &&
6429 ch->ch_pun.un_tty->ldisc->ops->write_wakeup)
6431 DGAP_UNLOCK(ch->ch_lock, lock_flags2);
6432 DGAP_UNLOCK(bd->bd_lock, lock_flags);
6433 (ch->ch_pun.un_tty->ldisc->ops->write_wakeup)(ch->ch_pun.un_tty);
6434 DGAP_LOCK(bd->bd_lock, lock_flags);
6435 DGAP_LOCK(ch->ch_lock, lock_flags2);
6437 wake_up_interruptible(&ch->ch_pun.un_tty->write_wait);
6438 wake_up_interruptible(&ch->ch_pun.un_flags_wait);
6442 if (ch->ch_flags & CH_WLOW) {
6443 ch->ch_flags &= ~CH_WLOW;
6444 wake_up_interruptible(&ch->ch_flags_wait);
6449 * Process Transmit empty.
6451 if (reason & IFTEM) {
6452 DPR_EVENT(("event: got empty event\n"));
6454 if (ch->ch_tun.un_flags & UN_EMPTY) {
6455 ch->ch_tun.un_flags &= ~UN_EMPTY;
6456 if (ch->ch_tun.un_flags & UN_ISOPEN) {
6457 if ((ch->ch_tun.un_tty->flags &
6458 (1 << TTY_DO_WRITE_WAKEUP)) &&
6459 ch->ch_tun.un_tty->ldisc->ops->write_wakeup)
6461 DGAP_UNLOCK(ch->ch_lock, lock_flags2);
6462 DGAP_UNLOCK(bd->bd_lock, lock_flags);
6464 (ch->ch_tun.un_tty->ldisc->ops->write_wakeup)(ch->ch_tun.un_tty);
6465 DGAP_LOCK(bd->bd_lock, lock_flags);
6466 DGAP_LOCK(ch->ch_lock, lock_flags2);
6468 wake_up_interruptible(&ch->ch_tun.un_tty->write_wait);
6469 wake_up_interruptible(&ch->ch_tun.un_flags_wait);
6473 if (ch->ch_pun.un_flags & UN_EMPTY) {
6474 ch->ch_pun.un_flags &= ~UN_EMPTY;
6475 if (ch->ch_pun.un_flags & UN_ISOPEN) {
6476 if ((ch->ch_pun.un_tty->flags &
6477 (1 << TTY_DO_WRITE_WAKEUP)) &&
6478 ch->ch_pun.un_tty->ldisc->ops->write_wakeup)
6480 DGAP_UNLOCK(ch->ch_lock, lock_flags2);
6481 DGAP_UNLOCK(bd->bd_lock, lock_flags);
6482 (ch->ch_pun.un_tty->ldisc->ops->write_wakeup)(ch->ch_pun.un_tty);
6483 DGAP_LOCK(bd->bd_lock, lock_flags);
6484 DGAP_LOCK(ch->ch_lock, lock_flags2);
6486 wake_up_interruptible(&ch->ch_pun.un_tty->write_wait);
6487 wake_up_interruptible(&ch->ch_pun.un_flags_wait);
6492 if (ch->ch_flags & CH_WEMPTY) {
6493 ch->ch_flags &= ~CH_WEMPTY;
6494 wake_up_interruptible(&ch->ch_flags_wait);
6498 DGAP_UNLOCK(ch->ch_lock, lock_flags2);
6501 tail = (tail + 4) & (EVMAX - EVSTART - 4);
6504 writew(tail, &(eaddr->ev_tail));
6505 DGAP_UNLOCK(bd->bd_lock, lock_flags);
6510 static ssize_t dgap_driver_version_show(struct device_driver *ddp, char *buf)
6512 return snprintf(buf, PAGE_SIZE, "%s\n", DG_PART);
6514 static DRIVER_ATTR(version, S_IRUSR, dgap_driver_version_show, NULL);
6517 static ssize_t dgap_driver_boards_show(struct device_driver *ddp, char *buf)
6519 return snprintf(buf, PAGE_SIZE, "%d\n", dgap_NumBoards);
6521 static DRIVER_ATTR(boards, S_IRUSR, dgap_driver_boards_show, NULL);
6524 static ssize_t dgap_driver_maxboards_show(struct device_driver *ddp, char *buf)
6526 return snprintf(buf, PAGE_SIZE, "%d\n", MAXBOARDS);
6528 static DRIVER_ATTR(maxboards, S_IRUSR, dgap_driver_maxboards_show, NULL);
6531 static ssize_t dgap_driver_pollcounter_show(struct device_driver *ddp, char *buf)
6533 return snprintf(buf, PAGE_SIZE, "%ld\n", dgap_poll_counter);
6535 static DRIVER_ATTR(pollcounter, S_IRUSR, dgap_driver_pollcounter_show, NULL);
6538 static ssize_t dgap_driver_state_show(struct device_driver *ddp, char *buf)
6540 return snprintf(buf, PAGE_SIZE, "%s\n", dgap_driver_state_text[dgap_driver_state]);
6542 static DRIVER_ATTR(state, S_IRUSR, dgap_driver_state_show, NULL);
6545 static ssize_t dgap_driver_debug_show(struct device_driver *ddp, char *buf)
6547 return snprintf(buf, PAGE_SIZE, "0x%x\n", dgap_debug);
6550 static ssize_t dgap_driver_debug_store(struct device_driver *ddp, const char *buf, size_t count)
6552 sscanf(buf, "0x%x\n", &dgap_debug);
6555 static DRIVER_ATTR(debug, (S_IRUSR | S_IWUSR), dgap_driver_debug_show, dgap_driver_debug_store);
6558 static ssize_t dgap_driver_rawreadok_show(struct device_driver *ddp, char *buf)
6560 return snprintf(buf, PAGE_SIZE, "0x%x\n", dgap_rawreadok);
6563 static ssize_t dgap_driver_rawreadok_store(struct device_driver *ddp, const char *buf, size_t count)
6565 sscanf(buf, "0x%x\n", &dgap_rawreadok);
6568 static DRIVER_ATTR(rawreadok, (S_IRUSR | S_IWUSR), dgap_driver_rawreadok_show, dgap_driver_rawreadok_store);
6571 static ssize_t dgap_driver_pollrate_show(struct device_driver *ddp, char *buf)
6573 return snprintf(buf, PAGE_SIZE, "%dms\n", dgap_poll_tick);
6576 static ssize_t dgap_driver_pollrate_store(struct device_driver *ddp, const char *buf, size_t count)
6578 sscanf(buf, "%d\n", &dgap_poll_tick);
6581 static DRIVER_ATTR(pollrate, (S_IRUSR | S_IWUSR), dgap_driver_pollrate_show, dgap_driver_pollrate_store);
6584 static void dgap_create_driver_sysfiles(struct pci_driver *dgap_driver)
6587 struct device_driver *driverfs = &dgap_driver->driver;
6589 rc |= driver_create_file(driverfs, &driver_attr_version);
6590 rc |= driver_create_file(driverfs, &driver_attr_boards);
6591 rc |= driver_create_file(driverfs, &driver_attr_maxboards);
6592 rc |= driver_create_file(driverfs, &driver_attr_debug);
6593 rc |= driver_create_file(driverfs, &driver_attr_rawreadok);
6594 rc |= driver_create_file(driverfs, &driver_attr_pollrate);
6595 rc |= driver_create_file(driverfs, &driver_attr_pollcounter);
6596 rc |= driver_create_file(driverfs, &driver_attr_state);
6598 printk(KERN_ERR "DGAP: sysfs driver_create_file failed!\n");
6603 static void dgap_remove_driver_sysfiles(struct pci_driver *dgap_driver)
6605 struct device_driver *driverfs = &dgap_driver->driver;
6606 driver_remove_file(driverfs, &driver_attr_version);
6607 driver_remove_file(driverfs, &driver_attr_boards);
6608 driver_remove_file(driverfs, &driver_attr_maxboards);
6609 driver_remove_file(driverfs, &driver_attr_debug);
6610 driver_remove_file(driverfs, &driver_attr_rawreadok);
6611 driver_remove_file(driverfs, &driver_attr_pollrate);
6612 driver_remove_file(driverfs, &driver_attr_pollcounter);
6613 driver_remove_file(driverfs, &driver_attr_state);
6617 #define DGAP_VERIFY_BOARD(p, bd) \
6621 bd = dev_get_drvdata(p); \
6622 if (!bd || bd->magic != DGAP_BOARD_MAGIC) \
6624 if (bd->state != BOARD_READY) \
6628 static ssize_t dgap_ports_state_show(struct device *p, struct device_attribute *attr, char *buf)
6634 DGAP_VERIFY_BOARD(p, bd);
6636 for (i = 0; i < bd->nasync; i++) {
6637 count += snprintf(buf + count, PAGE_SIZE - count,
6638 "%d %s\n", bd->channels[i]->ch_portnum,
6639 bd->channels[i]->ch_open_count ? "Open" : "Closed");
6643 static DEVICE_ATTR(ports_state, S_IRUSR, dgap_ports_state_show, NULL);
6646 static ssize_t dgap_ports_baud_show(struct device *p, struct device_attribute *attr, char *buf)
6652 DGAP_VERIFY_BOARD(p, bd);
6654 for (i = 0; i < bd->nasync; i++) {
6655 count += snprintf(buf + count, PAGE_SIZE - count,
6656 "%d %d\n", bd->channels[i]->ch_portnum, bd->channels[i]->ch_baud_info);
6660 static DEVICE_ATTR(ports_baud, S_IRUSR, dgap_ports_baud_show, NULL);
6663 static ssize_t dgap_ports_msignals_show(struct device *p, struct device_attribute *attr, char *buf)
6669 DGAP_VERIFY_BOARD(p, bd);
6671 for (i = 0; i < bd->nasync; i++) {
6672 if (bd->channels[i]->ch_open_count) {
6673 count += snprintf(buf + count, PAGE_SIZE - count,
6674 "%d %s %s %s %s %s %s\n", bd->channels[i]->ch_portnum,
6675 (bd->channels[i]->ch_mostat & UART_MCR_RTS) ? "RTS" : "",
6676 (bd->channels[i]->ch_mistat & UART_MSR_CTS) ? "CTS" : "",
6677 (bd->channels[i]->ch_mostat & UART_MCR_DTR) ? "DTR" : "",
6678 (bd->channels[i]->ch_mistat & UART_MSR_DSR) ? "DSR" : "",
6679 (bd->channels[i]->ch_mistat & UART_MSR_DCD) ? "DCD" : "",
6680 (bd->channels[i]->ch_mistat & UART_MSR_RI) ? "RI" : "");
6682 count += snprintf(buf + count, PAGE_SIZE - count,
6683 "%d\n", bd->channels[i]->ch_portnum);
6688 static DEVICE_ATTR(ports_msignals, S_IRUSR, dgap_ports_msignals_show, NULL);
6691 static ssize_t dgap_ports_iflag_show(struct device *p, struct device_attribute *attr, char *buf)
6697 DGAP_VERIFY_BOARD(p, bd);
6699 for (i = 0; i < bd->nasync; i++) {
6700 count += snprintf(buf + count, PAGE_SIZE - count, "%d %x\n",
6701 bd->channels[i]->ch_portnum, bd->channels[i]->ch_c_iflag);
6705 static DEVICE_ATTR(ports_iflag, S_IRUSR, dgap_ports_iflag_show, NULL);
6708 static ssize_t dgap_ports_cflag_show(struct device *p, struct device_attribute *attr, char *buf)
6714 DGAP_VERIFY_BOARD(p, bd);
6716 for (i = 0; i < bd->nasync; i++) {
6717 count += snprintf(buf + count, PAGE_SIZE - count, "%d %x\n",
6718 bd->channels[i]->ch_portnum, bd->channels[i]->ch_c_cflag);
6722 static DEVICE_ATTR(ports_cflag, S_IRUSR, dgap_ports_cflag_show, NULL);
6725 static ssize_t dgap_ports_oflag_show(struct device *p, struct device_attribute *attr, char *buf)
6731 DGAP_VERIFY_BOARD(p, bd);
6733 for (i = 0; i < bd->nasync; i++) {
6734 count += snprintf(buf + count, PAGE_SIZE - count, "%d %x\n",
6735 bd->channels[i]->ch_portnum, bd->channels[i]->ch_c_oflag);
6739 static DEVICE_ATTR(ports_oflag, S_IRUSR, dgap_ports_oflag_show, NULL);
6742 static ssize_t dgap_ports_lflag_show(struct device *p, struct device_attribute *attr, char *buf)
6748 DGAP_VERIFY_BOARD(p, bd);
6750 for (i = 0; i < bd->nasync; i++) {
6751 count += snprintf(buf + count, PAGE_SIZE - count, "%d %x\n",
6752 bd->channels[i]->ch_portnum, bd->channels[i]->ch_c_lflag);
6756 static DEVICE_ATTR(ports_lflag, S_IRUSR, dgap_ports_lflag_show, NULL);
6759 static ssize_t dgap_ports_digi_flag_show(struct device *p, struct device_attribute *attr, char *buf)
6765 DGAP_VERIFY_BOARD(p, bd);
6767 for (i = 0; i < bd->nasync; i++) {
6768 count += snprintf(buf + count, PAGE_SIZE - count, "%d %x\n",
6769 bd->channels[i]->ch_portnum, bd->channels[i]->ch_digi.digi_flags);
6773 static DEVICE_ATTR(ports_digi_flag, S_IRUSR, dgap_ports_digi_flag_show, NULL);
6776 static ssize_t dgap_ports_rxcount_show(struct device *p, struct device_attribute *attr, char *buf)
6782 DGAP_VERIFY_BOARD(p, bd);
6784 for (i = 0; i < bd->nasync; i++) {
6785 count += snprintf(buf + count, PAGE_SIZE - count, "%d %ld\n",
6786 bd->channels[i]->ch_portnum, bd->channels[i]->ch_rxcount);
6790 static DEVICE_ATTR(ports_rxcount, S_IRUSR, dgap_ports_rxcount_show, NULL);
6793 static ssize_t dgap_ports_txcount_show(struct device *p, struct device_attribute *attr, char *buf)
6799 DGAP_VERIFY_BOARD(p, bd);
6801 for (i = 0; i < bd->nasync; i++) {
6802 count += snprintf(buf + count, PAGE_SIZE - count, "%d %ld\n",
6803 bd->channels[i]->ch_portnum, bd->channels[i]->ch_txcount);
6807 static DEVICE_ATTR(ports_txcount, S_IRUSR, dgap_ports_txcount_show, NULL);
6810 /* this function creates the sys files that will export each signal status
6811 * to sysfs each value will be put in a separate filename
6813 static void dgap_create_ports_sysfiles(struct board_t *bd)
6817 dev_set_drvdata(&bd->pdev->dev, bd);
6818 rc |= device_create_file(&(bd->pdev->dev), &dev_attr_ports_state);
6819 rc |= device_create_file(&(bd->pdev->dev), &dev_attr_ports_baud);
6820 rc |= device_create_file(&(bd->pdev->dev), &dev_attr_ports_msignals);
6821 rc |= device_create_file(&(bd->pdev->dev), &dev_attr_ports_iflag);
6822 rc |= device_create_file(&(bd->pdev->dev), &dev_attr_ports_cflag);
6823 rc |= device_create_file(&(bd->pdev->dev), &dev_attr_ports_oflag);
6824 rc |= device_create_file(&(bd->pdev->dev), &dev_attr_ports_lflag);
6825 rc |= device_create_file(&(bd->pdev->dev), &dev_attr_ports_digi_flag);
6826 rc |= device_create_file(&(bd->pdev->dev), &dev_attr_ports_rxcount);
6827 rc |= device_create_file(&(bd->pdev->dev), &dev_attr_ports_txcount);
6829 printk(KERN_ERR "DGAP: sysfs device_create_file failed!\n");
6834 /* removes all the sys files created for that port */
6835 static void dgap_remove_ports_sysfiles(struct board_t *bd)
6837 device_remove_file(&(bd->pdev->dev), &dev_attr_ports_state);
6838 device_remove_file(&(bd->pdev->dev), &dev_attr_ports_baud);
6839 device_remove_file(&(bd->pdev->dev), &dev_attr_ports_msignals);
6840 device_remove_file(&(bd->pdev->dev), &dev_attr_ports_iflag);
6841 device_remove_file(&(bd->pdev->dev), &dev_attr_ports_cflag);
6842 device_remove_file(&(bd->pdev->dev), &dev_attr_ports_oflag);
6843 device_remove_file(&(bd->pdev->dev), &dev_attr_ports_lflag);
6844 device_remove_file(&(bd->pdev->dev), &dev_attr_ports_digi_flag);
6845 device_remove_file(&(bd->pdev->dev), &dev_attr_ports_rxcount);
6846 device_remove_file(&(bd->pdev->dev), &dev_attr_ports_txcount);
6850 static ssize_t dgap_tty_state_show(struct device *d, struct device_attribute *attr, char *buf)
6853 struct channel_t *ch;
6858 un = dev_get_drvdata(d);
6859 if (!un || un->magic != DGAP_UNIT_MAGIC)
6862 if (!ch || ch->magic != DGAP_CHANNEL_MAGIC)
6865 if (!bd || bd->magic != DGAP_BOARD_MAGIC)
6867 if (bd->state != BOARD_READY)
6870 return snprintf(buf, PAGE_SIZE, "%s", un->un_open_count ? "Open" : "Closed");
6872 static DEVICE_ATTR(state, S_IRUSR, dgap_tty_state_show, NULL);
6875 static ssize_t dgap_tty_baud_show(struct device *d, struct device_attribute *attr, char *buf)
6878 struct channel_t *ch;
6883 un = dev_get_drvdata(d);
6884 if (!un || un->magic != DGAP_UNIT_MAGIC)
6887 if (!ch || ch->magic != DGAP_CHANNEL_MAGIC)
6890 if (!bd || bd->magic != DGAP_BOARD_MAGIC)
6892 if (bd->state != BOARD_READY)
6895 return snprintf(buf, PAGE_SIZE, "%d\n", ch->ch_baud_info);
6897 static DEVICE_ATTR(baud, S_IRUSR, dgap_tty_baud_show, NULL);
6900 static ssize_t dgap_tty_msignals_show(struct device *d, struct device_attribute *attr, char *buf)
6903 struct channel_t *ch;
6908 un = dev_get_drvdata(d);
6909 if (!un || un->magic != DGAP_UNIT_MAGIC)
6912 if (!ch || ch->magic != DGAP_CHANNEL_MAGIC)
6915 if (!bd || bd->magic != DGAP_BOARD_MAGIC)
6917 if (bd->state != BOARD_READY)
6920 if (ch->ch_open_count) {
6921 return snprintf(buf, PAGE_SIZE, "%s %s %s %s %s %s\n",
6922 (ch->ch_mostat & UART_MCR_RTS) ? "RTS" : "",
6923 (ch->ch_mistat & UART_MSR_CTS) ? "CTS" : "",
6924 (ch->ch_mostat & UART_MCR_DTR) ? "DTR" : "",
6925 (ch->ch_mistat & UART_MSR_DSR) ? "DSR" : "",
6926 (ch->ch_mistat & UART_MSR_DCD) ? "DCD" : "",
6927 (ch->ch_mistat & UART_MSR_RI) ? "RI" : "");
6931 static DEVICE_ATTR(msignals, S_IRUSR, dgap_tty_msignals_show, NULL);
6934 static ssize_t dgap_tty_iflag_show(struct device *d, struct device_attribute *attr, char *buf)
6937 struct channel_t *ch;
6942 un = dev_get_drvdata(d);
6943 if (!un || un->magic != DGAP_UNIT_MAGIC)
6946 if (!ch || ch->magic != DGAP_CHANNEL_MAGIC)
6949 if (!bd || bd->magic != DGAP_BOARD_MAGIC)
6951 if (bd->state != BOARD_READY)
6954 return snprintf(buf, PAGE_SIZE, "%x\n", ch->ch_c_iflag);
6956 static DEVICE_ATTR(iflag, S_IRUSR, dgap_tty_iflag_show, NULL);
6959 static ssize_t dgap_tty_cflag_show(struct device *d, struct device_attribute *attr, char *buf)
6962 struct channel_t *ch;
6967 un = dev_get_drvdata(d);
6968 if (!un || un->magic != DGAP_UNIT_MAGIC)
6971 if (!ch || ch->magic != DGAP_CHANNEL_MAGIC)
6974 if (!bd || bd->magic != DGAP_BOARD_MAGIC)
6976 if (bd->state != BOARD_READY)
6979 return snprintf(buf, PAGE_SIZE, "%x\n", ch->ch_c_cflag);
6981 static DEVICE_ATTR(cflag, S_IRUSR, dgap_tty_cflag_show, NULL);
6984 static ssize_t dgap_tty_oflag_show(struct device *d, struct device_attribute *attr, char *buf)
6987 struct channel_t *ch;
6992 un = dev_get_drvdata(d);
6993 if (!un || un->magic != DGAP_UNIT_MAGIC)
6996 if (!ch || ch->magic != DGAP_CHANNEL_MAGIC)
6999 if (!bd || bd->magic != DGAP_BOARD_MAGIC)
7001 if (bd->state != BOARD_READY)
7004 return snprintf(buf, PAGE_SIZE, "%x\n", ch->ch_c_oflag);
7006 static DEVICE_ATTR(oflag, S_IRUSR, dgap_tty_oflag_show, NULL);
7009 static ssize_t dgap_tty_lflag_show(struct device *d, struct device_attribute *attr, char *buf)
7012 struct channel_t *ch;
7017 un = dev_get_drvdata(d);
7018 if (!un || un->magic != DGAP_UNIT_MAGIC)
7021 if (!ch || ch->magic != DGAP_CHANNEL_MAGIC)
7024 if (!bd || bd->magic != DGAP_BOARD_MAGIC)
7026 if (bd->state != BOARD_READY)
7029 return snprintf(buf, PAGE_SIZE, "%x\n", ch->ch_c_lflag);
7031 static DEVICE_ATTR(lflag, S_IRUSR, dgap_tty_lflag_show, NULL);
7034 static ssize_t dgap_tty_digi_flag_show(struct device *d, struct device_attribute *attr, char *buf)
7037 struct channel_t *ch;
7042 un = dev_get_drvdata(d);
7043 if (!un || un->magic != DGAP_UNIT_MAGIC)
7046 if (!ch || ch->magic != DGAP_CHANNEL_MAGIC)
7049 if (!bd || bd->magic != DGAP_BOARD_MAGIC)
7051 if (bd->state != BOARD_READY)
7054 return snprintf(buf, PAGE_SIZE, "%x\n", ch->ch_digi.digi_flags);
7056 static DEVICE_ATTR(digi_flag, S_IRUSR, dgap_tty_digi_flag_show, NULL);
7059 static ssize_t dgap_tty_rxcount_show(struct device *d, struct device_attribute *attr, char *buf)
7062 struct channel_t *ch;
7067 un = dev_get_drvdata(d);
7068 if (!un || un->magic != DGAP_UNIT_MAGIC)
7071 if (!ch || ch->magic != DGAP_CHANNEL_MAGIC)
7074 if (!bd || bd->magic != DGAP_BOARD_MAGIC)
7076 if (bd->state != BOARD_READY)
7079 return snprintf(buf, PAGE_SIZE, "%ld\n", ch->ch_rxcount);
7081 static DEVICE_ATTR(rxcount, S_IRUSR, dgap_tty_rxcount_show, NULL);
7084 static ssize_t dgap_tty_txcount_show(struct device *d, struct device_attribute *attr, char *buf)
7087 struct channel_t *ch;
7092 un = dev_get_drvdata(d);
7093 if (!un || un->magic != DGAP_UNIT_MAGIC)
7096 if (!ch || ch->magic != DGAP_CHANNEL_MAGIC)
7099 if (!bd || bd->magic != DGAP_BOARD_MAGIC)
7101 if (bd->state != BOARD_READY)
7104 return snprintf(buf, PAGE_SIZE, "%ld\n", ch->ch_txcount);
7106 static DEVICE_ATTR(txcount, S_IRUSR, dgap_tty_txcount_show, NULL);
7109 static ssize_t dgap_tty_name_show(struct device *d, struct device_attribute *attr, char *buf)
7112 struct channel_t *ch;
7116 struct cnode *cptr = NULL;
7124 un = dev_get_drvdata(d);
7125 if (!un || un->magic != DGAP_UNIT_MAGIC)
7128 if (!ch || ch->magic != DGAP_CHANNEL_MAGIC)
7131 if (!bd || bd->magic != DGAP_BOARD_MAGIC)
7133 if (bd->state != BOARD_READY)
7137 cn = ch->ch_portnum;
7139 for (cptr = bd->bd_config; cptr; cptr = cptr->next) {
7141 if ((cptr->type == BNODE) &&
7142 ((cptr->u.board.type == APORT2_920P) || (cptr->u.board.type == APORT4_920P) ||
7143 (cptr->u.board.type == APORT8_920P) || (cptr->u.board.type == PAPORT4) ||
7144 (cptr->u.board.type == PAPORT8))) {
7147 if (cptr->u.board.v_start)
7148 starto = cptr->u.board.start;
7153 if (cptr->type == TNODE && found == TRUE) {
7155 if (strstr(cptr->u.ttyname, "tty")) {
7156 ptr1 = cptr->u.ttyname;
7160 ptr1 = cptr->u.ttyname;
7163 for (i = 0; i < dgap_config_get_number_of_ports(bd); i++) {
7165 return snprintf(buf, PAGE_SIZE, "%s%s%02d\n",
7166 (un->un_type == DGAP_PRINT) ? "pr" : "tty",
7172 if (cptr->type == CNODE) {
7174 for (i = 0; i < cptr->u.conc.nport; i++) {
7175 if (cn == (i + ncount)) {
7177 return snprintf(buf, PAGE_SIZE, "%s%s%02d\n",
7178 (un->un_type == DGAP_PRINT) ? "pr" : "tty",
7180 i + (cptr->u.conc.v_start ? cptr->u.conc.start : 1));
7184 ncount += cptr->u.conc.nport;
7187 if (cptr->type == MNODE) {
7189 for (i = 0; i < cptr->u.module.nport; i++) {
7190 if (cn == (i + ncount)) {
7191 return snprintf(buf, PAGE_SIZE, "%s%s%02d\n",
7192 (un->un_type == DGAP_PRINT) ? "pr" : "tty",
7194 i + (cptr->u.module.v_start ? cptr->u.module.start : 1));
7198 ncount += cptr->u.module.nport;
7203 return snprintf(buf, PAGE_SIZE, "%s_dgap_%d_%d\n",
7204 (un->un_type == DGAP_PRINT) ? "pr" : "tty", bn, cn);
7207 static DEVICE_ATTR(custom_name, S_IRUSR, dgap_tty_name_show, NULL);
7210 static struct attribute *dgap_sysfs_tty_entries[] = {
7211 &dev_attr_state.attr,
7212 &dev_attr_baud.attr,
7213 &dev_attr_msignals.attr,
7214 &dev_attr_iflag.attr,
7215 &dev_attr_cflag.attr,
7216 &dev_attr_oflag.attr,
7217 &dev_attr_lflag.attr,
7218 &dev_attr_digi_flag.attr,
7219 &dev_attr_rxcount.attr,
7220 &dev_attr_txcount.attr,
7221 &dev_attr_custom_name.attr,
7226 static struct attribute_group dgap_tty_attribute_group = {
7228 .attrs = dgap_sysfs_tty_entries,
7234 static void dgap_create_tty_sysfs(struct un_t *un, struct device *c)
7238 ret = sysfs_create_group(&c->kobj, &dgap_tty_attribute_group);
7240 printk(KERN_ERR "dgap: failed to create sysfs tty device attributes.\n");
7241 sysfs_remove_group(&c->kobj, &dgap_tty_attribute_group);
7245 dev_set_drvdata(c, un);
7250 static void dgap_remove_tty_sysfs(struct device *c)
7252 sysfs_remove_group(&c->kobj, &dgap_tty_attribute_group);
7256 * Parse a configuration file read into memory as a string.
7258 static int dgap_parsefile(char **in, int Remove)
7260 struct cnode *p, *brd, *line, *conc;
7262 char *s = NULL, *s2 = NULL;
7266 brd = line = conc = NULL;
7268 /* perhaps we are adding to an existing list? */
7269 while (p->next != NULL) {
7273 /* file must start with a BEGIN */
7274 while ( (rc = dgap_gettok(in,p)) != BEGIN ) {
7276 dgap_err("unexpected EOF");
7282 rc = dgap_gettok(in,p);
7284 dgap_err("unexpected EOF");
7290 dgap_err("unexpected end of file");
7293 case BEGIN: /* should only be 1 begin */
7294 dgap_err("unexpected config_begin\n");
7300 case BOARD: /* board info */
7301 if (dgap_checknode(p))
7303 if ( (p->next = dgap_newnode(BNODE)) == NULL ) {
7304 dgap_err("out of memory");
7309 p->u.board.status = dgap_savestring("No");
7315 case APORT2_920P: /* AccelePort_4 */
7316 if (p->type != BNODE) {
7317 dgap_err("unexpected Digi_2r_920 string");
7320 p->u.board.type = APORT2_920P;
7321 p->u.board.v_type = 1;
7322 DPR_INIT(("Adding Digi_2r_920 PCI to config...\n"));
7325 case APORT4_920P: /* AccelePort_4 */
7326 if (p->type != BNODE) {
7327 dgap_err("unexpected Digi_4r_920 string");
7330 p->u.board.type = APORT4_920P;
7331 p->u.board.v_type = 1;
7332 DPR_INIT(("Adding Digi_4r_920 PCI to config...\n"));
7335 case APORT8_920P: /* AccelePort_8 */
7336 if (p->type != BNODE) {
7337 dgap_err("unexpected Digi_8r_920 string");
7340 p->u.board.type = APORT8_920P;
7341 p->u.board.v_type = 1;
7342 DPR_INIT(("Adding Digi_8r_920 PCI to config...\n"));
7345 case PAPORT4: /* AccelePort_4 PCI */
7346 if (p->type != BNODE) {
7347 dgap_err("unexpected Digi_4r(PCI) string");
7350 p->u.board.type = PAPORT4;
7351 p->u.board.v_type = 1;
7352 DPR_INIT(("Adding Digi_4r PCI to config...\n"));
7355 case PAPORT8: /* AccelePort_8 PCI */
7356 if (p->type != BNODE) {
7357 dgap_err("unexpected Digi_8r string");
7360 p->u.board.type = PAPORT8;
7361 p->u.board.v_type = 1;
7362 DPR_INIT(("Adding Digi_8r PCI to config...\n"));
7365 case PCX: /* PCI C/X */
7366 if (p->type != BNODE) {
7367 dgap_err("unexpected Digi_C/X_(PCI) string");
7370 p->u.board.type = PCX;
7371 p->u.board.v_type = 1;
7372 p->u.board.conc1 = 0;
7373 p->u.board.conc2 = 0;
7374 p->u.board.module1 = 0;
7375 p->u.board.module2 = 0;
7376 DPR_INIT(("Adding PCI C/X to config...\n"));
7379 case PEPC: /* PCI EPC/X */
7380 if (p->type != BNODE) {
7381 dgap_err("unexpected \"Digi_EPC/X_(PCI)\" string");
7384 p->u.board.type = PEPC;
7385 p->u.board.v_type = 1;
7386 p->u.board.conc1 = 0;
7387 p->u.board.conc2 = 0;
7388 p->u.board.module1 = 0;
7389 p->u.board.module2 = 0;
7390 DPR_INIT(("Adding PCI EPC/X to config...\n"));
7393 case PPCM: /* PCI/Xem */
7394 if (p->type != BNODE) {
7395 dgap_err("unexpected PCI/Xem string");
7398 p->u.board.type = PPCM;
7399 p->u.board.v_type = 1;
7400 p->u.board.conc1 = 0;
7401 p->u.board.conc2 = 0;
7402 DPR_INIT(("Adding PCI XEM to config...\n"));
7405 case IO: /* i/o port */
7406 if (p->type != BNODE) {
7407 dgap_err("IO port only vaild for boards");
7410 s = dgap_getword(in);
7412 dgap_err("unexpected end of file");
7415 p->u.board.portstr = dgap_savestring(s);
7416 p->u.board.port = (short)simple_strtol(s, &s2, 0);
7417 if ((short)strlen(s) > (short)(s2 - s)) {
7418 dgap_err("bad number for IO port");
7421 p->u.board.v_port = 1;
7422 DPR_INIT(("Adding IO (%s) to config...\n", s));
7425 case MEM: /* memory address */
7426 if (p->type != BNODE) {
7427 dgap_err("memory address only vaild for boards");
7430 s = dgap_getword(in);
7432 dgap_err("unexpected end of file");
7435 p->u.board.addrstr = dgap_savestring(s);
7436 p->u.board.addr = simple_strtoul(s, &s2, 0);
7437 if ((int)strlen(s) > (int)(s2 - s)) {
7438 dgap_err("bad number for memory address");
7441 p->u.board.v_addr = 1;
7442 DPR_INIT(("Adding MEM (%s) to config...\n", s));
7445 case PCIINFO: /* pci information */
7446 if (p->type != BNODE) {
7447 dgap_err("memory address only vaild for boards");
7450 s = dgap_getword(in);
7452 dgap_err("unexpected end of file");
7455 p->u.board.pcibusstr = dgap_savestring(s);
7456 p->u.board.pcibus = simple_strtoul(s, &s2, 0);
7457 if ((int)strlen(s) > (int)(s2 - s)) {
7458 dgap_err("bad number for pci bus");
7461 p->u.board.v_pcibus = 1;
7462 s = dgap_getword(in);
7464 dgap_err("unexpected end of file");
7467 p->u.board.pcislotstr = dgap_savestring(s);
7468 p->u.board.pcislot = simple_strtoul(s, &s2, 0);
7469 if ((int)strlen(s) > (int)(s2 - s)) {
7470 dgap_err("bad number for pci slot");
7473 p->u.board.v_pcislot = 1;
7475 DPR_INIT(("Adding PCIINFO (%s %s) to config...\n", p->u.board.pcibusstr,
7476 p->u.board.pcislotstr));
7480 if (p->type != BNODE) {
7481 dgap_err("install method only vaild for boards");
7484 s = dgap_getword(in);
7486 dgap_err("unexpected end of file");
7489 p->u.board.method = dgap_savestring(s);
7490 p->u.board.v_method = 1;
7491 DPR_INIT(("Adding METHOD (%s) to config...\n", s));
7495 if (p->type != BNODE) {
7496 dgap_err("config status only vaild for boards");
7499 s = dgap_getword(in);
7501 dgap_err("unexpected end of file");
7504 p->u.board.status = dgap_savestring(s);
7505 DPR_INIT(("Adding STATUS (%s) to config...\n", s));
7508 case NPORTS: /* number of ports */
7509 if (p->type == BNODE) {
7510 s = dgap_getword(in);
7512 dgap_err("unexpected end of file");
7515 p->u.board.nport = (char)simple_strtol(s, &s2, 0);
7516 if ((int)strlen(s) > (int)(s2 - s)) {
7517 dgap_err("bad number for number of ports");
7520 p->u.board.v_nport = 1;
7521 } else if (p->type == CNODE) {
7522 s = dgap_getword(in);
7524 dgap_err("unexpected end of file");
7527 p->u.conc.nport = (char)simple_strtol(s, &s2, 0);
7528 if ((int)strlen(s) > (int)(s2 - s)) {
7529 dgap_err("bad number for number of ports");
7532 p->u.conc.v_nport = 1;
7533 } else if (p->type == MNODE) {
7534 s = dgap_getword(in);
7536 dgap_err("unexpected end of file");
7539 p->u.module.nport = (char)simple_strtol(s, &s2, 0);
7540 if ((int)strlen(s) > (int)(s2 - s)) {
7541 dgap_err("bad number for number of ports");
7544 p->u.module.v_nport = 1;
7546 dgap_err("nports only valid for concentrators or modules");
7549 DPR_INIT(("Adding NPORTS (%s) to config...\n", s));
7552 case ID: /* letter ID used in tty name */
7553 s = dgap_getword(in);
7555 dgap_err("unexpected end of file");
7559 p->u.board.status = dgap_savestring(s);
7561 if (p->type == CNODE) {
7562 p->u.conc.id = dgap_savestring(s);
7564 } else if (p->type == MNODE) {
7565 p->u.module.id = dgap_savestring(s);
7566 p->u.module.v_id = 1;
7568 dgap_err("id only valid for concentrators or modules");
7571 DPR_INIT(("Adding ID (%s) to config...\n", s));
7574 case STARTO: /* start offset of ID */
7575 if (p->type == BNODE) {
7576 s = dgap_getword(in);
7578 dgap_err("unexpected end of file");
7581 p->u.board.start = simple_strtol(s, &s2, 0);
7582 if ((int)strlen(s) > (int)(s2 - s)) {
7583 dgap_err("bad number for start of tty count");
7586 p->u.board.v_start = 1;
7587 } else if (p->type == CNODE) {
7588 s = dgap_getword(in);
7590 dgap_err("unexpected end of file");
7593 p->u.conc.start = simple_strtol(s, &s2, 0);
7594 if ((int)strlen(s) > (int)(s2 - s)) {
7595 dgap_err("bad number for start of tty count");
7598 p->u.conc.v_start = 1;
7599 } else if (p->type == MNODE) {
7600 s = dgap_getword(in);
7602 dgap_err("unexpected end of file");
7605 p->u.module.start = simple_strtol(s, &s2, 0);
7606 if ((int)strlen(s) > (int)(s2 - s)) {
7607 dgap_err("bad number for start of tty count");
7610 p->u.module.v_start = 1;
7612 dgap_err("start only valid for concentrators or modules");
7615 DPR_INIT(("Adding START (%s) to config...\n", s));
7618 case TTYN: /* tty name prefix */
7619 if (dgap_checknode(p))
7621 if ( (p->next = dgap_newnode(TNODE)) == NULL ) {
7622 dgap_err("out of memory");
7626 if ( (s = dgap_getword(in)) == NULL ) {
7627 dgap_err("unexpeced end of file");
7630 if ( (p->u.ttyname = dgap_savestring(s)) == NULL ) {
7631 dgap_err("out of memory");
7634 DPR_INIT(("Adding TTY (%s) to config...\n", s));
7637 case CU: /* cu name prefix */
7638 if (dgap_checknode(p))
7640 if ( (p->next = dgap_newnode(CUNODE)) == NULL ) {
7641 dgap_err("out of memory");
7645 if ( (s = dgap_getword(in)) == NULL ) {
7646 dgap_err("unexpeced end of file");
7649 if ( (p->u.cuname = dgap_savestring(s)) == NULL ) {
7650 dgap_err("out of memory");
7653 DPR_INIT(("Adding CU (%s) to config...\n", s));
7656 case LINE: /* line information */
7657 if (dgap_checknode(p))
7660 dgap_err("must specify board before line info");
7663 switch (brd->u.board.type) {
7665 dgap_err("line not vaild for PC/em");
7668 if ( (p->next = dgap_newnode(LNODE)) == NULL ) {
7669 dgap_err("out of memory");
7676 DPR_INIT(("Adding LINE to config...\n"));
7679 case CONC: /* concentrator information */
7680 if (dgap_checknode(p))
7683 dgap_err("must specify line info before concentrator");
7686 if ( (p->next = dgap_newnode(CNODE)) == NULL ) {
7687 dgap_err("out of memory");
7693 brd->u.board.conc2++;
7695 brd->u.board.conc1++;
7697 DPR_INIT(("Adding CONC to config...\n"));
7700 case CX: /* c/x type concentrator */
7701 if (p->type != CNODE) {
7702 dgap_err("cx only valid for concentrators");
7705 p->u.conc.type = CX;
7706 p->u.conc.v_type = 1;
7707 DPR_INIT(("Adding CX to config...\n"));
7710 case EPC: /* epc type concentrator */
7711 if (p->type != CNODE) {
7712 dgap_err("cx only valid for concentrators");
7715 p->u.conc.type = EPC;
7716 p->u.conc.v_type = 1;
7717 DPR_INIT(("Adding EPC to config...\n"));
7720 case MOD: /* EBI module */
7721 if (dgap_checknode(p))
7724 dgap_err("must specify board info before EBI modules");
7727 switch (brd->u.board.type) {
7733 dgap_err("must specify concentrator info before EBI module");
7737 if ( (p->next = dgap_newnode(MNODE)) == NULL ) {
7738 dgap_err("out of memory");
7743 brd->u.board.module2++;
7745 brd->u.board.module1++;
7747 DPR_INIT(("Adding MOD to config...\n"));
7750 case PORTS: /* ports type EBI module */
7751 if (p->type != MNODE) {
7752 dgap_err("ports only valid for EBI modules");
7755 p->u.module.type = PORTS;
7756 p->u.module.v_type = 1;
7757 DPR_INIT(("Adding PORTS to config...\n"));
7760 case MODEM: /* ports type EBI module */
7761 if (p->type != MNODE) {
7762 dgap_err("modem only valid for modem modules");
7765 p->u.module.type = MODEM;
7766 p->u.module.v_type = 1;
7767 DPR_INIT(("Adding MODEM to config...\n"));
7771 if (p->type == LNODE) {
7772 if ((s = dgap_getword(in)) == NULL) {
7773 dgap_err("unexpected end of file");
7776 p->u.line.cable = dgap_savestring(s);
7777 p->u.line.v_cable = 1;
7779 DPR_INIT(("Adding CABLE (%s) to config...\n", s));
7782 case SPEED: /* sync line speed indication */
7783 if (p->type == LNODE) {
7784 s = dgap_getword(in);
7786 dgap_err("unexpected end of file");
7789 p->u.line.speed = (char)simple_strtol(s, &s2, 0);
7790 if ((short)strlen(s) > (short)(s2 - s)) {
7791 dgap_err("bad number for line speed");
7794 p->u.line.v_speed = 1;
7795 } else if (p->type == CNODE) {
7796 s = dgap_getword(in);
7798 dgap_err("unexpected end of file");
7801 p->u.conc.speed = (char)simple_strtol(s, &s2, 0);
7802 if ((short)strlen(s) > (short)(s2 - s)) {
7803 dgap_err("bad number for line speed");
7806 p->u.conc.v_speed = 1;
7808 dgap_err("speed valid only for lines or concentrators.");
7811 DPR_INIT(("Adding SPEED (%s) to config...\n", s));
7815 if (p->type == CNODE) {
7816 if ((s = dgap_getword(in)) == NULL) {
7817 dgap_err("unexpected end of file");
7820 p->u.conc.connect = dgap_savestring(s);
7821 p->u.conc.v_connect = 1;
7823 DPR_INIT(("Adding CONNECT (%s) to config...\n", s));
7825 case PRINT: /* transparent print name prefix */
7826 if (dgap_checknode(p))
7828 if ( (p->next = dgap_newnode(PNODE)) == NULL ) {
7829 dgap_err("out of memory");
7833 if ( (s = dgap_getword(in)) == NULL ) {
7834 dgap_err("unexpeced end of file");
7837 if ( (p->u.printname = dgap_savestring(s)) == NULL ) {
7838 dgap_err("out of memory");
7841 DPR_INIT(("Adding PRINT (%s) to config...\n", s));
7844 case CMAJOR: /* major number */
7845 if (dgap_checknode(p))
7847 if ( (p->next = dgap_newnode(JNODE)) == NULL ) {
7848 dgap_err("out of memory");
7852 s = dgap_getword(in);
7854 dgap_err("unexpected end of file");
7857 p->u.majornumber = simple_strtol(s, &s2, 0);
7858 if ((int)strlen(s) > (int)(s2 - s)) {
7859 dgap_err("bad number for major number");
7862 DPR_INIT(("Adding CMAJOR (%s) to config...\n", s));
7865 case ALTPIN: /* altpin setting */
7866 if (dgap_checknode(p))
7868 if ( (p->next = dgap_newnode(ANODE)) == NULL ) {
7869 dgap_err("out of memory");
7873 s = dgap_getword(in);
7875 dgap_err("unexpected end of file");
7878 p->u.altpin = simple_strtol(s, &s2, 0);
7879 if ((int)strlen(s) > (int)(s2 - s)) {
7880 dgap_err("bad number for altpin");
7883 DPR_INIT(("Adding ALTPIN (%s) to config...\n", s));
7886 case USEINTR: /* enable interrupt setting */
7887 if (dgap_checknode(p))
7889 if ( (p->next = dgap_newnode(INTRNODE)) == NULL ) {
7890 dgap_err("out of memory");
7894 s = dgap_getword(in);
7896 dgap_err("unexpected end of file");
7899 p->u.useintr = simple_strtol(s, &s2, 0);
7900 if ((int)strlen(s) > (int)(s2 - s)) {
7901 dgap_err("bad number for useintr");
7904 DPR_INIT(("Adding USEINTR (%s) to config...\n", s));
7907 case TTSIZ: /* size of tty structure */
7908 if (dgap_checknode(p))
7910 if ( (p->next = dgap_newnode(TSNODE)) == NULL ) {
7911 dgap_err("out of memory");
7915 s = dgap_getword(in);
7917 dgap_err("unexpected end of file");
7920 p->u.ttysize = simple_strtol(s, &s2, 0);
7921 if ((int)strlen(s) > (int)(s2 - s)) {
7922 dgap_err("bad number for ttysize");
7925 DPR_INIT(("Adding TTSIZ (%s) to config...\n", s));
7928 case CHSIZ: /* channel structure size */
7929 if (dgap_checknode(p))
7931 if ( (p->next = dgap_newnode(CSNODE)) == NULL ) {
7932 dgap_err("out of memory");
7936 s = dgap_getword(in);
7938 dgap_err("unexpected end of file");
7941 p->u.chsize = simple_strtol(s, &s2, 0);
7942 if ((int)strlen(s) > (int)(s2 - s)) {
7943 dgap_err("bad number for chsize");
7946 DPR_INIT(("Adding CHSIZE (%s) to config...\n", s));
7949 case BSSIZ: /* board structure size */
7950 if (dgap_checknode(p))
7952 if ( (p->next = dgap_newnode(BSNODE)) == NULL ) {
7953 dgap_err("out of memory");
7957 s = dgap_getword(in);
7959 dgap_err("unexpected end of file");
7962 p->u.bssize = simple_strtol(s, &s2, 0);
7963 if ((int)strlen(s) > (int)(s2 - s)) {
7964 dgap_err("bad number for bssize");
7967 DPR_INIT(("Adding BSSIZ (%s) to config...\n", s));
7970 case UNTSIZ: /* sched structure size */
7971 if (dgap_checknode(p))
7973 if ( (p->next = dgap_newnode(USNODE)) == NULL ) {
7974 dgap_err("out of memory");
7978 s = dgap_getword(in);
7980 dgap_err("unexpected end of file");
7983 p->u.unsize = simple_strtol(s, &s2, 0);
7984 if ((int)strlen(s) > (int)(s2 - s)) {
7985 dgap_err("bad number for schedsize");
7988 DPR_INIT(("Adding UNTSIZ (%s) to config...\n", s));
7991 case F2SIZ: /* f2200 structure size */
7992 if (dgap_checknode(p))
7994 if ( (p->next = dgap_newnode(FSNODE)) == NULL ) {
7995 dgap_err("out of memory");
7999 s = dgap_getword(in);
8001 dgap_err("unexpected end of file");
8004 p->u.f2size = simple_strtol(s, &s2, 0);
8005 if ((int)strlen(s) > (int)(s2 - s)) {
8006 dgap_err("bad number for f2200size");
8009 DPR_INIT(("Adding F2SIZ (%s) to config...\n", s));
8012 case VPSIZ: /* vpix structure size */
8013 if (dgap_checknode(p))
8015 if ( (p->next = dgap_newnode(VSNODE)) == NULL ) {
8016 dgap_err("out of memory");
8020 s = dgap_getword(in);
8022 dgap_err("unexpected end of file");
8025 p->u.vpixsize = simple_strtol(s, &s2, 0);
8026 if ((int)strlen(s) > (int)(s2 - s)) {
8027 dgap_err("bad number for vpixsize");
8030 DPR_INIT(("Adding VPSIZ (%s) to config...\n", s));
8038 * dgap_sindex: much like index(), but it looks for a match of any character in
8039 * the group, and returns that position. If the first character is a ^, then
8040 * this will match the first occurrence not in that group.
8042 static char *dgap_sindex (char *string, char *group)
8046 if (!string || !group)
8047 return (char *) NULL;
8049 if (*group == '^') {
8051 for (; *string; string++) {
8052 for (ptr = group; *ptr; ptr++) {
8053 if (*ptr == *string)
8061 for (; *string; string++) {
8062 for (ptr = group; *ptr; ptr++) {
8063 if (*ptr == *string)
8069 return (char *) NULL;
8074 * Get a token from the input file; return 0 if end of file is reached
8076 static int dgap_gettok(char **in, struct cnode *p)
8081 if (strstr(dgap_cword, "boar")) {
8082 w = dgap_getword(in);
8083 snprintf(dgap_cword, MAXCWORD, "%s", w);
8084 for (t = dgap_tlist; t->token != 0; t++) {
8085 if ( !strcmp(w, t->string)) {
8089 dgap_err("board !!type not specified");
8093 while ( (w = dgap_getword(in)) != NULL ) {
8094 snprintf(dgap_cword, MAXCWORD, "%s", w);
8095 for (t = dgap_tlist; t->token != 0; t++) {
8096 if ( !strcmp(w, t->string) )
8106 * get a word from the input stream, also keep track of current line number.
8107 * words are separated by whitespace.
8109 static char *dgap_getword(char **in)
8111 char *ret_ptr = *in;
8113 char *ptr = dgap_sindex(*in, " \t\n");
8115 /* If no word found, return null */
8119 /* Mark new location for our buffer */
8123 /* Eat any extra spaces/tabs/newlines that might be present */
8124 while (*in && **in && ((**in == ' ') || (**in == '\t') || (**in == '\n'))) {
8134 * print an error message, giving the line number in the file where
8135 * the error occurred.
8137 static void dgap_err(char *s)
8139 printk("DGAP: parse: %s\n", s);
8144 * allocate a new configuration node of type t
8146 static struct cnode *dgap_newnode(int t)
8150 n = kmalloc(sizeof(struct cnode), GFP_ATOMIC);
8152 memset((char *)n, 0, sizeof(struct cnode));
8160 * dgap_checknode: see if all the necessary info has been supplied for a node
8161 * before creating the next node.
8163 static int dgap_checknode(struct cnode *p)
8167 if (p->u.board.v_type == 0) {
8168 dgap_err("board type !not specified");
8175 if (p->u.line.v_speed == 0) {
8176 dgap_err("line speed not specified");
8182 if (p->u.conc.v_type == 0) {
8183 dgap_err("concentrator type not specified");
8186 if (p->u.conc.v_speed == 0) {
8187 dgap_err("concentrator line speed not specified");
8190 if (p->u.conc.v_nport == 0) {
8191 dgap_err("number of ports on concentrator not specified");
8194 if (p->u.conc.v_id == 0) {
8195 dgap_err("concentrator id letter not specified");
8201 if (p->u.module.v_type == 0) {
8202 dgap_err("EBI module type not specified");
8205 if (p->u.module.v_nport == 0) {
8206 dgap_err("number of ports on EBI module not specified");
8209 if (p->u.module.v_id == 0) {
8210 dgap_err("EBI module id letter not specified");
8219 * save a string somewhere
8221 static char *dgap_savestring(char *s)
8224 if ( (p = kmalloc(strlen(s) + 1, GFP_ATOMIC) ) != NULL) {
8232 * Given a board pointer, returns whether we should use interrupts or not.
8234 static uint dgap_config_get_useintr(struct board_t *bd)
8236 struct cnode *p = NULL;
8241 for (p = bd->bd_config; p; p = p->next) {
8245 * check for pcxr types.
8247 return p->u.useintr;
8253 /* If not found, then don't turn on interrupts. */
8259 * Given a board pointer, returns whether we turn on altpin or not.
8261 static uint dgap_config_get_altpin(struct board_t *bd)
8263 struct cnode *p = NULL;
8268 for (p = bd->bd_config; p; p = p->next) {
8272 * check for pcxr types.
8280 /* If not found, then don't turn on interrupts. */
8287 * Given a specific type of board, if found, detached link and
8288 * returns the first occurrence in the list.
8290 static struct cnode *dgap_find_config(int type, int bus, int slot)
8292 struct cnode *p, *prev = NULL, *prev2 = NULL, *found = NULL;
8296 while (p->next != NULL) {
8300 if (p->type == BNODE) {
8302 if (p->u.board.type == type) {
8304 if (p->u.board.v_pcibus && p->u.board.pcibus != bus) {
8305 DPR(("Found matching board, but wrong bus position. System says bus %d, we want bus %ld\n",
8306 bus, p->u.board.pcibus));
8309 if (p->u.board.v_pcislot && p->u.board.pcislot != slot) {
8310 DPR_INIT(("Found matching board, but wrong slot position. System says slot %d, we want slot %ld\n",
8311 slot, p->u.board.pcislot));
8315 DPR_INIT(("Matched type in config file\n"));
8319 * Keep walking thru the list till we find the next board.
8321 while (p->next != NULL) {
8324 if (p->type == BNODE) {
8327 * Mark the end of our 1 board chain of configs.
8332 * Link the "next" board to the previous board,
8333 * effectively "unlinking" our board from the main config.
8341 * It must be the last board in the list.
8352 * Given a board pointer, walks the config link, counting up
8353 * all ports user specified should be on the board.
8354 * (This does NOT mean they are all actually present right now tho)
8356 static uint dgap_config_get_number_of_ports(struct board_t *bd)
8359 struct cnode *p = NULL;
8364 for (p = bd->bd_config; p; p = p->next) {
8369 * check for pcxr types.
8371 if (p->u.board.type > EPCFE)
8372 count += p->u.board.nport;
8375 count += p->u.conc.nport;
8378 count += p->u.module.nport;
8385 static char *dgap_create_config_string(struct board_t *bd, char *string)
8388 struct cnode *p = NULL;
8389 struct cnode *q = NULL;
8397 for (p = bd->bd_config; p; p = p->next) {
8403 *ptr = p->u.line.speed;
8408 * Because the EPC/con concentrators can have EM modules
8409 * hanging off of them, we have to walk ahead in the list
8410 * and keep adding the number of ports on each EM to the config.
8413 speed = p->u.conc.speed;
8415 if ((q != NULL) && (q->type == MNODE) ) {
8416 *ptr = (p->u.conc.nport + 0x80);
8419 while ((q->next != NULL) && (q->next->type) == MNODE) {
8420 *ptr = (q->u.module.nport + 0x80);
8425 *ptr = q->u.module.nport;
8428 *ptr = p->u.conc.nport;
8444 static char *dgap_get_config_letters(struct board_t *bd, char *string)
8448 struct cnode *cptr = NULL;
8450 int left = MAXTTYNAMELEN;
8456 for (cptr = bd->bd_config; cptr; cptr = cptr->next) {
8458 if ((cptr->type == BNODE) &&
8459 ((cptr->u.board.type == APORT2_920P) || (cptr->u.board.type == APORT4_920P) ||
8460 (cptr->u.board.type == APORT8_920P) || (cptr->u.board.type == PAPORT4) ||
8461 (cptr->u.board.type == PAPORT8))) {
8466 if (cptr->type == TNODE && found == TRUE) {
8468 if (strstr(cptr->u.ttyname, "tty")) {
8469 ptr1 = cptr->u.ttyname;
8473 ptr1 = cptr->u.ttyname;
8476 len = snprintf(ptr, left, "%s", ptr1);
8484 if (cptr->type == CNODE) {
8485 if (cptr->u.conc.id) {
8486 len = snprintf(ptr, left, "%s", cptr->u.conc.id);
8494 if (cptr->type == MNODE) {
8495 if (cptr->u.module.id) {
8496 len = snprintf(ptr, left, "%s", cptr->u.module.id);