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 * In the original out of kernel Digi dgap driver, firmware
34 * loading was done via user land to driver handshaking.
36 * For cards that support a concentrator (port expander),
37 * I believe the concentrator its self told the card which
38 * concentrator is actually attached and then that info
39 * was used to tell user land which concentrator firmware
40 * image was to be downloaded. I think even the BIOS or
41 * FEP images required could change with the connection
42 * of a particular concentrator.
44 * Since I have no access to any of these cards or
45 * concentrators, I cannot put the correct concentrator
46 * firmware file names into the firmware_info structure
47 * as is now done for the BIOS and FEP images.
49 * I think, but am not certain, that the cards supporting
50 * concentrators will function without them. So support
51 * of these cards has been left in this driver.
53 * In order to fully support those cards, they would
54 * either have to be acquired for dissection or maybe
55 * Digi International could provide some assistance.
57 #undef DIGI_CONCENTRATORS_SUPPORTED
59 #include <linux/kernel.h>
60 #include <linux/module.h>
61 #include <linux/pci.h>
62 #include <linux/delay.h> /* For udelay */
63 #include <linux/slab.h>
64 #include <linux/uaccess.h>
65 #include <linux/sched.h>
67 #include <linux/interrupt.h> /* For tasklet and interrupt structs/defines */
68 #include <linux/ctype.h>
69 #include <linux/tty.h>
70 #include <linux/tty_flip.h>
71 #include <linux/serial_reg.h>
72 #include <linux/io.h> /* For read[bwl]/write[bwl] */
74 #include <linux/string.h>
75 #include <linux/device.h>
76 #include <linux/kdev_t.h>
77 #include <linux/firmware.h>
81 #define init_MUTEX(sem) sema_init(sem, 1)
82 #define DECLARE_MUTEX(name) \
83 struct semaphore name = __SEMAPHORE_INITIALIZER(name, 1)
85 MODULE_LICENSE("GPL");
86 MODULE_AUTHOR("Digi International, http://www.digi.com");
87 MODULE_DESCRIPTION("Driver for the Digi International EPCA PCI based product line");
88 MODULE_SUPPORTED_DEVICE("dgap");
90 /**************************************************************************
92 * protos for this file
96 static int dgap_start(void);
97 static void dgap_init_globals(void);
98 static int dgap_found_board(struct pci_dev *pdev, int id);
99 static void dgap_cleanup_board(struct board_t *brd);
100 static void dgap_poll_handler(ulong dummy);
101 static int dgap_init_pci(void);
102 static int dgap_init_one(struct pci_dev *pdev, const struct pci_device_id *ent);
103 static void dgap_remove_one(struct pci_dev *dev);
104 static int dgap_probe1(struct pci_dev *pdev, int card_type);
105 static int dgap_do_remap(struct board_t *brd);
106 static irqreturn_t dgap_intr(int irq, void *voidbrd);
108 /* Our function prototypes */
109 static int dgap_tty_open(struct tty_struct *tty, struct file *file);
110 static void dgap_tty_close(struct tty_struct *tty, struct file *file);
111 static int dgap_block_til_ready(struct tty_struct *tty, struct file *file,
112 struct channel_t *ch);
113 static int dgap_tty_ioctl(struct tty_struct *tty, unsigned int cmd,
115 static int dgap_tty_digigeta(struct tty_struct *tty,
116 struct digi_t __user *retinfo);
117 static int dgap_tty_digiseta(struct tty_struct *tty,
118 struct digi_t __user *new_info);
119 static int dgap_tty_digigetedelay(struct tty_struct *tty, int __user *retinfo);
120 static int dgap_tty_digisetedelay(struct tty_struct *tty, int __user *new_info);
121 static int dgap_tty_write_room(struct tty_struct *tty);
122 static int dgap_tty_chars_in_buffer(struct tty_struct *tty);
123 static void dgap_tty_start(struct tty_struct *tty);
124 static void dgap_tty_stop(struct tty_struct *tty);
125 static void dgap_tty_throttle(struct tty_struct *tty);
126 static void dgap_tty_unthrottle(struct tty_struct *tty);
127 static void dgap_tty_flush_chars(struct tty_struct *tty);
128 static void dgap_tty_flush_buffer(struct tty_struct *tty);
129 static void dgap_tty_hangup(struct tty_struct *tty);
130 static int dgap_wait_for_drain(struct tty_struct *tty);
131 static int dgap_set_modem_info(struct tty_struct *tty, unsigned int command,
132 unsigned int __user *value);
133 static int dgap_get_modem_info(struct channel_t *ch,
134 unsigned int __user *value);
135 static int dgap_tty_digisetcustombaud(struct tty_struct *tty,
136 int __user *new_info);
137 static int dgap_tty_digigetcustombaud(struct tty_struct *tty,
138 int __user *retinfo);
139 static int dgap_tty_tiocmget(struct tty_struct *tty);
140 static int dgap_tty_tiocmset(struct tty_struct *tty, unsigned int set,
142 static int dgap_tty_send_break(struct tty_struct *tty, int msec);
143 static void dgap_tty_wait_until_sent(struct tty_struct *tty, int timeout);
144 static int dgap_tty_write(struct tty_struct *tty, const unsigned char *buf,
146 static void dgap_tty_set_termios(struct tty_struct *tty,
147 struct ktermios *old_termios);
148 static int dgap_tty_put_char(struct tty_struct *tty, unsigned char c);
149 static void dgap_tty_send_xchar(struct tty_struct *tty, char ch);
151 static int dgap_tty_register(struct board_t *brd);
152 static int dgap_tty_preinit(void);
153 static int dgap_tty_init(struct board_t *);
154 static void dgap_tty_post_uninit(void);
155 static void dgap_tty_uninit(struct board_t *);
156 static void dgap_carrier(struct channel_t *ch);
157 static void dgap_input(struct channel_t *ch);
160 * Our function prototypes from dgap_fep5
162 static void dgap_cmdw_ext(struct channel_t *ch, u16 cmd, u16 word, uint ncmds);
163 static int dgap_event(struct board_t *bd);
165 static void dgap_poll_tasklet(unsigned long data);
166 static void dgap_cmdb(struct channel_t *ch, uchar cmd, uchar byte1,
167 uchar byte2, uint ncmds);
168 static void dgap_cmdw(struct channel_t *ch, uchar cmd, u16 word, uint ncmds);
169 static void dgap_wmove(struct channel_t *ch, char *buf, uint cnt);
170 static int dgap_param(struct tty_struct *tty);
171 static void dgap_parity_scan(struct channel_t *ch, unsigned char *cbuf,
172 unsigned char *fbuf, int *len);
173 static uint dgap_get_custom_baud(struct channel_t *ch);
174 static void dgap_firmware_reset_port(struct channel_t *ch);
177 * Function prototypes from dgap_parse.c.
179 static int dgap_gettok(char **in, struct cnode *p);
180 static char *dgap_getword(char **in);
181 static char *dgap_savestring(char *s);
182 static struct cnode *dgap_newnode(int t);
183 static int dgap_checknode(struct cnode *p);
184 static void dgap_err(char *s);
187 * Function prototypes from dgap_sysfs.h
195 static void dgap_create_ports_sysfiles(struct board_t *bd);
196 static void dgap_remove_ports_sysfiles(struct board_t *bd);
198 static void dgap_create_driver_sysfiles(struct pci_driver *);
199 static void dgap_remove_driver_sysfiles(struct pci_driver *);
201 static void dgap_create_tty_sysfs(struct un_t *un, struct device *c);
202 static void dgap_remove_tty_sysfs(struct device *c);
205 * Function prototypes from dgap_parse.h
207 static int dgap_parsefile(char **in, int Remove);
208 static struct cnode *dgap_find_config(int type, int bus, int slot);
209 static uint dgap_config_get_number_of_ports(struct board_t *bd);
210 static char *dgap_create_config_string(struct board_t *bd, char *string);
211 static uint dgap_config_get_useintr(struct board_t *bd);
212 static uint dgap_config_get_altpin(struct board_t *bd);
214 static int dgap_ms_sleep(ulong ms);
215 static void dgap_do_bios_load(struct board_t *brd, uchar __user *ubios,
217 static void dgap_do_fep_load(struct board_t *brd, uchar __user *ufep, int len);
218 #ifdef DIGI_CONCENTRATORS_SUPPORTED
219 static void dgap_do_conc_load(struct board_t *brd, uchar *uaddr, int len);
221 static int dgap_after_config_loaded(int board);
222 static int dgap_finalize_board_init(struct board_t *brd);
224 static void dgap_get_vpd(struct board_t *brd);
225 static void dgap_do_reset_board(struct board_t *brd);
226 static void dgap_do_wait_for_bios(struct board_t *brd);
227 static void dgap_do_wait_for_fep(struct board_t *brd);
228 static int dgap_tty_register_ports(struct board_t *brd);
229 static int dgap_firmware_load(struct pci_dev *pdev, int card_type);
231 /* Driver unload function */
232 static void dgap_cleanup_module(void);
234 module_exit(dgap_cleanup_module);
237 * File operations permitted on Control/Management major.
239 static const struct file_operations DgapBoardFops = {
240 .owner = THIS_MODULE,
246 static uint dgap_NumBoards;
247 static struct board_t *dgap_Board[MAXBOARDS];
248 static ulong dgap_poll_counter;
249 static char *dgap_config_buf;
250 static int dgap_driver_state = DRIVER_INITIALIZED;
251 DEFINE_SPINLOCK(dgap_dl_lock);
252 static wait_queue_head_t dgap_dl_wait;
253 static int dgap_dl_action;
254 static int dgap_poll_tick = 20; /* Poll interval - 20 ms */
259 static int dgap_Major_Control_Registered = FALSE;
260 static uint dgap_driver_start = FALSE;
262 static struct class *dgap_class;
264 static struct board_t *dgap_BoardsByMajor[256];
265 static uchar *dgap_TmpWriteBuf;
266 DECLARE_MUTEX(dgap_TmpWriteSem);
267 static uint dgap_count = 500;
272 DEFINE_SPINLOCK(dgap_poll_lock); /* Poll scheduling lock */
273 static ulong dgap_poll_time; /* Time of next poll */
274 static uint dgap_poll_stop; /* Used to tell poller to stop */
275 static struct timer_list dgap_poll_timer;
280 Card Model Number of Ports Interface
281 ----------------------------------------------------------------
282 Acceleport Xem 4 - 64 (EIA232 & EIA422)
283 Acceleport Xr 4 & 8 (EIA232)
284 Acceleport Xr 920 4 & 8 (EIA232)
285 Acceleport C/X 8 - 128 (EIA232)
286 Acceleport EPC/X 8 - 224 (EIA232)
287 Acceleport Xr/422 4 & 8 (EIA422)
288 Acceleport 2r/920 2 (EIA232)
289 Acceleport 4r/920 4 (EIA232)
290 Acceleport 8r/920 8 (EIA232)
292 IBM 8-Port Asynchronous PCI Adapter (EIA232)
293 IBM 128-Port Asynchronous PCI Adapter (EIA232 & EIA422)
296 static struct pci_device_id dgap_pci_tbl[] = {
297 { DIGI_VID, PCI_DEV_XEM_DID, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0 },
298 { DIGI_VID, PCI_DEV_CX_DID, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 1 },
299 { DIGI_VID, PCI_DEV_CX_IBM_DID, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 2 },
300 { DIGI_VID, PCI_DEV_EPCJ_DID, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 3 },
301 { DIGI_VID, PCI_DEV_920_2_DID, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 4 },
302 { DIGI_VID, PCI_DEV_920_4_DID, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 5 },
303 { DIGI_VID, PCI_DEV_920_8_DID, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 6 },
304 { DIGI_VID, PCI_DEV_XR_DID, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 7 },
305 { DIGI_VID, PCI_DEV_XRJ_DID, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 8 },
306 { DIGI_VID, PCI_DEV_XR_422_DID, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 9 },
307 { DIGI_VID, PCI_DEV_XR_IBM_DID, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 10 },
308 { DIGI_VID, PCI_DEV_XR_SAIP_DID, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 11 },
309 { DIGI_VID, PCI_DEV_XR_BULL_DID, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 12 },
310 { DIGI_VID, PCI_DEV_920_8_HP_DID, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 13 },
311 { DIGI_VID, PCI_DEV_XEM_HP_DID, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 14 },
312 {0,} /* 0 terminated list. */
314 MODULE_DEVICE_TABLE(pci, dgap_pci_tbl);
317 * A generic list of Product names, PCI Vendor ID, and PCI Device ID.
326 static struct board_id dgap_Ids[] = {
327 { PPCM, PCI_DEV_XEM_NAME, 64, (T_PCXM|T_PCLITE|T_PCIBUS) },
328 { PCX, PCI_DEV_CX_NAME, 128, (T_CX|T_PCIBUS) },
329 { PCX, PCI_DEV_CX_IBM_NAME, 128, (T_CX|T_PCIBUS) },
330 { PEPC, PCI_DEV_EPCJ_NAME, 224, (T_EPC|T_PCIBUS) },
331 { APORT2_920P, PCI_DEV_920_2_NAME, 2, (T_PCXR|T_PCLITE|T_PCIBUS) },
332 { APORT4_920P, PCI_DEV_920_4_NAME, 4, (T_PCXR|T_PCLITE|T_PCIBUS) },
333 { APORT8_920P, PCI_DEV_920_8_NAME, 8, (T_PCXR|T_PCLITE|T_PCIBUS) },
334 { PAPORT8, PCI_DEV_XR_NAME, 8, (T_PCXR|T_PCLITE|T_PCIBUS) },
335 { PAPORT8, PCI_DEV_XRJ_NAME, 8, (T_PCXR|T_PCLITE|T_PCIBUS) },
336 { PAPORT8, PCI_DEV_XR_422_NAME, 8, (T_PCXR|T_PCLITE|T_PCIBUS) },
337 { PAPORT8, PCI_DEV_XR_IBM_NAME, 8, (T_PCXR|T_PCLITE|T_PCIBUS) },
338 { PAPORT8, PCI_DEV_XR_SAIP_NAME, 8, (T_PCXR|T_PCLITE|T_PCIBUS) },
339 { PAPORT8, PCI_DEV_XR_BULL_NAME, 8, (T_PCXR|T_PCLITE|T_PCIBUS) },
340 { APORT8_920P, PCI_DEV_920_8_HP_NAME, 8, (T_PCXR|T_PCLITE|T_PCIBUS) },
341 { PPCM, PCI_DEV_XEM_HP_NAME, 64, (T_PCXM|T_PCLITE|T_PCIBUS) },
342 {0,} /* 0 terminated list. */
345 static struct pci_driver dgap_driver = {
347 .probe = dgap_init_one,
348 .id_table = dgap_pci_tbl,
349 .remove = dgap_remove_one,
352 struct firmware_info {
353 uchar *conf_name; /* dgap.conf */
354 uchar *bios_name; /* BIOS filename */
355 uchar *fep_name; /* FEP filename */
356 uchar *con_name; /* Concentrator filename FIXME*/
357 int num; /* sequence number */
361 * Firmware - BIOS, FEP, and CONC filenames
363 static struct firmware_info fw_info[] = {
364 { "dgap/dgap.conf", "dgap/sxbios.bin", "dgap/sxfep.bin", 0, 0 },
365 { "dgap/dgap.conf", "dgap/cxpbios.bin", "dgap/cxpfep.bin", 0, 1 },
366 { "dgap/dgap.conf", "dgap/cxpbios.bin", "dgap/cxpfep.bin", 0, 2 },
367 { "dgap/dgap.conf", "dgap/pcibios.bin", "dgap/pcifep.bin", 0, 3 },
368 { "dgap/dgap.conf", "dgap/xrbios.bin", "dgap/xrfep.bin", 0, 4 },
369 { "dgap/dgap.conf", "dgap/xrbios.bin", "dgap/xrfep.bin", 0, 5 },
370 { "dgap/dgap.conf", "dgap/xrbios.bin", "dgap/xrfep.bin", 0, 6 },
371 { "dgap/dgap.conf", "dgap/xrbios.bin", "dgap/xrfep.bin", 0, 7 },
372 { "dgap/dgap.conf", "dgap/xrbios.bin", "dgap/xrfep.bin", 0, 8 },
373 { "dgap/dgap.conf", "dgap/xrbios.bin", "dgap/xrfep.bin", 0, 9 },
374 { "dgap/dgap.conf", "dgap/xrbios.bin", "dgap/xrfep.bin", 0, 10 },
375 { "dgap/dgap.conf", "dgap/xrbios.bin", "dgap/xrfep.bin", 0, 11 },
376 { "dgap/dgap.conf", "dgap/xrbios.bin", "dgap/xrfep.bin", 0, 12 },
377 { "dgap/dgap.conf", "dgap/xrbios.bin", "dgap/xrfep.bin", 0, 13 },
378 { "dgap/dgap.conf", "dgap/sxbios.bin", "dgap/sxfep.bin", 0, 14 },
382 static char *dgap_driver_state_text[] = {
383 "Driver Initialized",
384 "Driver needs configuration load.",
385 "Driver requested configuration from download daemon.",
390 * Default transparent print information.
392 static struct digi_t dgap_digi_init = {
393 .digi_flags = DIGI_COOK, /* Flags */
394 .digi_maxcps = 100, /* Max CPS */
395 .digi_maxchar = 50, /* Max chars in print queue */
396 .digi_bufsize = 100, /* Printer buffer size */
397 .digi_onlen = 4, /* size of printer on string */
398 .digi_offlen = 4, /* size of printer off string */
399 .digi_onstr = "\033[5i", /* ANSI printer on string ] */
400 .digi_offstr = "\033[4i", /* ANSI printer off string ] */
401 .digi_term = "ansi" /* default terminal type */
405 * Define a local default termios struct. All ports will be created
406 * with this termios initially.
408 * This defines a raw port at 9600 baud, 8 data bits, no parity,
412 static struct ktermios DgapDefaultTermios = {
413 .c_iflag = (DEFAULT_IFLAGS), /* iflags */
414 .c_oflag = (DEFAULT_OFLAGS), /* oflags */
415 .c_cflag = (DEFAULT_CFLAGS), /* cflags */
416 .c_lflag = (DEFAULT_LFLAGS), /* lflags */
421 static const struct tty_operations dgap_tty_ops = {
422 .open = dgap_tty_open,
423 .close = dgap_tty_close,
424 .write = dgap_tty_write,
425 .write_room = dgap_tty_write_room,
426 .flush_buffer = dgap_tty_flush_buffer,
427 .chars_in_buffer = dgap_tty_chars_in_buffer,
428 .flush_chars = dgap_tty_flush_chars,
429 .ioctl = dgap_tty_ioctl,
430 .set_termios = dgap_tty_set_termios,
431 .stop = dgap_tty_stop,
432 .start = dgap_tty_start,
433 .throttle = dgap_tty_throttle,
434 .unthrottle = dgap_tty_unthrottle,
435 .hangup = dgap_tty_hangup,
436 .put_char = dgap_tty_put_char,
437 .tiocmget = dgap_tty_tiocmget,
438 .tiocmset = dgap_tty_tiocmset,
439 .break_ctl = dgap_tty_send_break,
440 .wait_until_sent = dgap_tty_wait_until_sent,
441 .send_xchar = dgap_tty_send_xchar
445 * Our needed internal static variables from dgap_parse.c
447 static struct cnode dgap_head;
449 static char dgap_cword[MAXCWORD];
456 static struct toklist dgap_tlist[] = {
457 { BEGIN, "config_begin" },
458 { END, "config_end" },
460 { PCX, "Digi_AccelePort_C/X_PCI" },
461 { PEPC, "Digi_AccelePort_EPC/X_PCI" },
462 { PPCM, "Digi_AccelePort_Xem_PCI" },
463 { APORT2_920P, "Digi_AccelePort_2r_920_PCI" },
464 { APORT4_920P, "Digi_AccelePort_4r_920_PCI" },
465 { APORT8_920P, "Digi_AccelePort_8r_920_PCI" },
466 { PAPORT4, "Digi_AccelePort_4r_PCI(EIA-232/RS-422)" },
467 { PAPORT8, "Digi_AccelePort_8r_PCI(EIA-232/RS-422)" },
469 { PCIINFO, "pciinfo" },
472 { CONC, "concentrator" },
482 { CONNECT, "connect" },
483 { METHOD, "method" },
484 { STATUS, "status" },
485 { CUSTOM, "Custom" },
491 { NPORTS, "nports" },
496 { ALTPIN, "altpin" },
497 { USEINTR, "useintr" },
498 { TTSIZ, "ttysize" },
500 { BSSIZ, "boardsize" },
501 { UNTSIZ, "schedsize" },
502 { F2SIZ, "f2200size" },
503 { VPSIZ, "vpixsize" },
507 /************************************************************************
509 * Driver load/unload functions
511 ************************************************************************/
516 * Module load. This is where it all starts.
518 static int dgap_init_module(void)
522 pr_info("%s, Digi International Part Number %s\n", DG_NAME, DG_PART);
524 dgap_driver_state = DRIVER_NEED_CONFIG_LOAD;
527 * Initialize global stuff
535 * Find and configure all the cards
537 rc = dgap_init_pci();
540 * If something went wrong in the scan, bail out of driver.
543 /* Only unregister the pci driver if it was actually registered. */
545 pci_unregister_driver(&dgap_driver);
547 pr_err("dgap: driver load failed. No boards found.\n");
549 dgap_cleanup_module();
551 dgap_create_driver_sysfiles(&dgap_driver);
552 dgap_driver_state = DRIVER_READY;
557 module_init(dgap_init_module);
562 static int dgap_start(void)
567 if (dgap_driver_start == FALSE) {
569 dgap_driver_start = TRUE;
572 * make sure that the globals are
573 * init'd before we do anything else
579 pr_info("For the tools package please visit http://www.digi.com\n");
582 * Register our base character device into the kernel.
584 if (!dgap_Major_Control_Registered) {
586 * Register management/dpa devices
588 rc = register_chrdev(DIGI_DGAP_MAJOR, "dgap",
593 dgap_class = class_create(THIS_MODULE, "dgap_mgmt");
594 device_create(dgap_class, NULL,
595 MKDEV(DIGI_DGAP_MAJOR, 0),
597 dgap_Major_Control_Registered = TRUE;
601 * Init any global tty stuff.
603 rc = dgap_tty_preinit();
608 /* Start the poller */
609 DGAP_LOCK(dgap_poll_lock, flags);
610 init_timer(&dgap_poll_timer);
611 dgap_poll_timer.function = dgap_poll_handler;
612 dgap_poll_timer.data = 0;
613 dgap_poll_time = jiffies + dgap_jiffies_from_ms(dgap_poll_tick);
614 dgap_poll_timer.expires = dgap_poll_time;
615 DGAP_UNLOCK(dgap_poll_lock, flags);
617 add_timer(&dgap_poll_timer);
619 dgap_driver_state = DRIVER_NEED_CONFIG_LOAD;
626 * Register pci driver, and return how many boards we have.
628 static int dgap_init_pci(void)
630 return pci_register_driver(&dgap_driver);
633 /* returns count (>= 0), or negative on error */
634 static int dgap_init_one(struct pci_dev *pdev, const struct pci_device_id *ent)
638 /* wake up and enable device */
639 rc = pci_enable_device(pdev);
644 rc = dgap_probe1(pdev, ent->driver_data);
647 rc = dgap_firmware_load(pdev, ent->driver_data);
653 static int dgap_probe1(struct pci_dev *pdev, int card_type)
655 return dgap_found_board(pdev, card_type);
658 static void dgap_remove_one(struct pci_dev *dev)
664 * dgap_cleanup_module()
666 * Module unload. This is where it all ends.
668 static void dgap_cleanup_module(void)
673 DGAP_LOCK(dgap_poll_lock, lock_flags);
675 DGAP_UNLOCK(dgap_poll_lock, lock_flags);
677 /* Turn off poller right away. */
678 del_timer_sync(&dgap_poll_timer);
680 dgap_remove_driver_sysfiles(&dgap_driver);
683 if (dgap_Major_Control_Registered) {
684 device_destroy(dgap_class, MKDEV(DIGI_DGAP_MAJOR, 0));
685 device_destroy(dgap_class, MKDEV(DIGI_DGAP_MAJOR, 1));
686 class_destroy(dgap_class);
687 unregister_chrdev(DIGI_DGAP_MAJOR, "dgap");
690 kfree(dgap_config_buf);
692 for (i = 0; i < dgap_NumBoards; ++i) {
693 dgap_remove_ports_sysfiles(dgap_Board[i]);
694 dgap_tty_uninit(dgap_Board[i]);
695 dgap_cleanup_board(dgap_Board[i]);
698 dgap_tty_post_uninit();
700 #if defined(DGAP_TRACER)
701 /* last thing, make sure we release the tracebuffer */
705 pci_unregister_driver(&dgap_driver);
709 * dgap_cleanup_board()
711 * Free all the memory associated with a board
713 static void dgap_cleanup_board(struct board_t *brd)
717 if (!brd || brd->magic != DGAP_BOARD_MAGIC)
720 if (brd->intr_used && brd->irq)
721 free_irq(brd->irq, brd);
723 tasklet_kill(&brd->helper_tasklet);
725 if (brd->re_map_port) {
726 release_mem_region(brd->membase + 0x200000, 0x200000);
727 iounmap(brd->re_map_port);
728 brd->re_map_port = NULL;
731 if (brd->re_map_membase) {
732 release_mem_region(brd->membase, 0x200000);
733 iounmap(brd->re_map_membase);
734 brd->re_map_membase = NULL;
737 /* Free all allocated channels structs */
738 for (i = 0; i < MAXPORTS ; i++)
739 kfree(brd->channels[i]);
742 kfree(brd->flipflagbuf);
744 dgap_Board[brd->boardnum] = NULL;
752 * A board has been found, init it.
754 static int dgap_found_board(struct pci_dev *pdev, int id)
757 unsigned int pci_irq;
760 /* get the board structure and prep it */
761 brd = kzalloc(sizeof(struct board_t), GFP_KERNEL);
765 dgap_Board[dgap_NumBoards] = brd;
767 /* store the info for the board we've found */
768 brd->magic = DGAP_BOARD_MAGIC;
769 brd->boardnum = dgap_NumBoards;
771 brd->vendor = dgap_pci_tbl[id].vendor;
772 brd->device = dgap_pci_tbl[id].device;
774 brd->pci_bus = pdev->bus->number;
775 brd->pci_slot = PCI_SLOT(pdev->devfn);
776 brd->name = dgap_Ids[id].name;
777 brd->maxports = dgap_Ids[id].maxports;
778 brd->type = dgap_Ids[id].config_type;
779 brd->dpatype = dgap_Ids[id].dpatype;
780 brd->dpastatus = BD_NOFEP;
781 init_waitqueue_head(&brd->state_wait);
783 DGAP_SPINLOCK_INIT(brd->bd_lock);
785 brd->state = BOARD_FOUND;
787 brd->inhibit_poller = FALSE;
788 brd->wait_for_bios = 0;
789 brd->wait_for_fep = 0;
791 for (i = 0; i < MAXPORTS; i++)
792 brd->channels[i] = NULL;
794 /* store which card & revision we have */
795 pci_read_config_word(pdev, PCI_SUBSYSTEM_VENDOR_ID, &brd->subvendor);
796 pci_read_config_word(pdev, PCI_SUBSYSTEM_ID, &brd->subdevice);
797 pci_read_config_byte(pdev, PCI_REVISION_ID, &brd->rev);
802 /* get the PCI Base Address Registers */
804 /* Xr Jupiter and EPC use BAR 2 */
805 if (brd->device == PCI_DEV_XRJ_DID || brd->device == PCI_DEV_EPCJ_DID) {
806 brd->membase = pci_resource_start(pdev, 2);
807 brd->membase_end = pci_resource_end(pdev, 2);
809 /* Everyone else uses BAR 0 */
811 brd->membase = pci_resource_start(pdev, 0);
812 brd->membase_end = pci_resource_end(pdev, 0);
818 if (brd->membase & 1)
824 * On the PCI boards, there is no IO space allocated
825 * The I/O registers will be in the first 3 bytes of the
826 * upper 2MB of the 4MB memory space. The board memory
827 * will be mapped into the low 2MB of the 4MB memory space
829 brd->port = brd->membase + PCI_IO_OFFSET;
830 brd->port_end = brd->port + PCI_IO_SIZE;
833 * Special initialization for non-PLX boards
835 if (brd->device != PCI_DEV_XRJ_DID && brd->device != PCI_DEV_EPCJ_DID) {
838 pci_write_config_byte(pdev, 0x40, 0);
839 pci_write_config_byte(pdev, 0x46, 0);
841 /* Limit burst length to 2 doubleword transactions */
842 pci_write_config_byte(pdev, 0x42, 1);
845 * Enable IO and mem if not already done.
846 * This was needed for support on Itanium.
848 pci_read_config_word(pdev, PCI_COMMAND, &cmd);
849 cmd |= (PCI_COMMAND_IO | PCI_COMMAND_MEMORY);
850 pci_write_config_word(pdev, PCI_COMMAND, cmd);
853 /* init our poll helper tasklet */
854 tasklet_init(&brd->helper_tasklet, dgap_poll_tasklet,
855 (unsigned long) brd);
857 i = dgap_do_remap(brd);
859 brd->state = BOARD_FAILED;
861 brd->state = NEED_RESET;
867 static int dgap_finalize_board_init(struct board_t *brd)
871 if (!brd || brd->magic != DGAP_BOARD_MAGIC)
874 brd->use_interrupts = dgap_config_get_useintr(brd);
877 * Set up our interrupt handler if we are set to do interrupts.
879 if (brd->use_interrupts && brd->irq) {
881 rc = request_irq(brd->irq, dgap_intr, IRQF_SHARED, "DGAP", brd);
894 static int dgap_firmware_load(struct pci_dev *pdev, int card_type)
896 struct board_t *brd = dgap_Board[dgap_NumBoards - 1];
897 const struct firmware *fw;
901 dgap_do_reset_board(brd);
903 if ((fw_info[card_type].conf_name) &&
904 (dgap_driver_state == DRIVER_NEED_CONFIG_LOAD)) {
905 ret = request_firmware(&fw, fw_info[card_type].conf_name,
908 pr_err("dgap: config file %s not found\n",
909 fw_info[card_type].conf_name);
912 if (!dgap_config_buf) {
913 dgap_config_buf = kmalloc(fw->size + 1, GFP_ATOMIC);
914 if (!dgap_config_buf) {
915 release_firmware(fw);
920 memcpy(dgap_config_buf, fw->data, fw->size);
921 release_firmware(fw);
922 dgap_config_buf[fw->size + 1] = '\0';
924 if (dgap_parsefile(&dgap_config_buf, TRUE) != 0)
927 dgap_driver_state = -1;
930 ret = dgap_after_config_loaded(brd->boardnum);
934 * Match this board to a config the user created for us.
937 dgap_find_config(brd->type, brd->pci_bus, brd->pci_slot);
940 * Because the 4 port Xr products share the same PCI ID
941 * as the 8 port Xr products, if we receive a NULL config
942 * back, and this is a PAPORT8 board, retry with a
943 * PAPORT4 attempt as well.
945 if (brd->type == PAPORT8 && !brd->bd_config)
947 dgap_find_config(PAPORT4, brd->pci_bus, brd->pci_slot);
949 if (!brd->bd_config) {
950 pr_err("dgap: No valid configuration found\n");
954 dgap_tty_register(brd);
955 dgap_finalize_board_init(brd);
957 if (fw_info[card_type].bios_name) {
958 ret = request_firmware(&fw, fw_info[card_type].bios_name,
961 pr_err("dgap: bios file %s not found\n",
962 fw_info[card_type].bios_name);
965 dgap_do_bios_load(brd, (char *)fw->data, fw->size);
966 release_firmware(fw);
968 /* Wait for BIOS to test board... */
969 dgap_do_wait_for_bios(brd);
971 if (brd->state != FINISHED_BIOS_LOAD)
975 if (fw_info[card_type].fep_name) {
976 ret = request_firmware(&fw, fw_info[card_type].fep_name,
979 pr_err("dgap: fep file %s not found\n",
980 fw_info[card_type].fep_name);
983 dgap_do_fep_load(brd, (char *)fw->data, fw->size);
984 release_firmware(fw);
986 /* Wait for FEP to load on board... */
987 dgap_do_wait_for_fep(brd);
989 if (brd->state != FINISHED_FEP_LOAD)
993 #ifdef DIGI_CONCENTRATORS_SUPPORTED
995 * If this is a CX or EPCX, we need to see if the firmware
996 * is requesting a concentrator image from us.
998 if ((bd->type == PCX) || (bd->type == PEPC)) {
999 chk_addr = (u16 *) (vaddr + DOWNREQ);
1000 /* Nonzero if FEP is requesting concentrator image. */
1001 check = readw(chk_addr);
1002 vaddr = brd->re_map_membase;
1005 if (fw_info[card_type].con_name && check && vaddr) {
1006 ret = request_firmware(&fw, fw_info[card_type].con_name,
1009 pr_err("dgap: conc file %s not found\n",
1010 fw_info[card_type].con_name);
1013 /* Put concentrator firmware loading code here */
1014 offset = readw((u16 *) (vaddr + DOWNREQ));
1015 memcpy_toio(offset, fw->data, fw->size);
1017 dgap_do_conc_load(brd, (char *)fw->data, fw->size)
1018 release_firmware(fw);
1022 * Do tty device initialization.
1024 ret = dgap_tty_init(brd);
1026 dgap_tty_uninit(brd);
1030 ret = dgap_tty_register_ports(brd);
1034 brd->state = BOARD_READY;
1035 brd->dpastatus = BD_RUNNING;
1043 static int dgap_do_remap(struct board_t *brd)
1045 if (!brd || brd->magic != DGAP_BOARD_MAGIC)
1048 if (!request_mem_region(brd->membase, 0x200000, "dgap"))
1051 if (!request_mem_region(brd->membase + PCI_IO_OFFSET, 0x200000,
1053 release_mem_region(brd->membase, 0x200000);
1057 brd->re_map_membase = ioremap(brd->membase, 0x200000);
1058 if (!brd->re_map_membase) {
1059 release_mem_region(brd->membase, 0x200000);
1060 release_mem_region(brd->membase + PCI_IO_OFFSET, 0x200000);
1064 brd->re_map_port = ioremap((brd->membase + PCI_IO_OFFSET), 0x200000);
1065 if (!brd->re_map_port) {
1066 release_mem_region(brd->membase, 0x200000);
1067 release_mem_region(brd->membase + PCI_IO_OFFSET, 0x200000);
1068 iounmap(brd->re_map_membase);
1075 /*****************************************************************************
1095 * As each timer expires, it determines (a) whether the "transmit"
1096 * waiter needs to be woken up, and (b) whether the poller needs to
1099 ******************************************************************************/
1101 static void dgap_poll_handler(ulong dummy)
1104 struct board_t *brd;
1105 unsigned long lock_flags;
1108 dgap_poll_counter++;
1111 * Do not start the board state machine until
1112 * driver tells us its up and running, and has
1113 * everything it needs.
1115 if (dgap_driver_state != DRIVER_READY)
1116 goto schedule_poller;
1119 * If we have just 1 board, or the system is not SMP,
1120 * then use the typical old style poller.
1121 * Otherwise, use our new tasklet based poller, which should
1122 * speed things up for multiple boards.
1124 if ((dgap_NumBoards == 1) || (num_online_cpus() <= 1)) {
1125 for (i = 0; i < dgap_NumBoards; i++) {
1127 brd = dgap_Board[i];
1129 if (brd->state == BOARD_FAILED)
1131 if (!brd->intr_running)
1132 /* Call the real board poller directly */
1133 dgap_poll_tasklet((unsigned long) brd);
1137 * Go thru each board, kicking off a
1138 * tasklet for each if needed
1140 for (i = 0; i < dgap_NumBoards; i++) {
1141 brd = dgap_Board[i];
1144 * Attempt to grab the board lock.
1146 * If we can't get it, no big deal, the next poll
1147 * will get it. Basically, I just really don't want
1148 * to spin in here, because I want to kick off my
1149 * tasklets as fast as I can, and then get out the
1152 if (!spin_trylock(&brd->bd_lock))
1156 * If board is in a failed state, don't bother
1157 * scheduling a tasklet
1159 if (brd->state == BOARD_FAILED) {
1160 spin_unlock(&brd->bd_lock);
1164 /* Schedule a poll helper task */
1165 if (!brd->intr_running)
1166 tasklet_schedule(&brd->helper_tasklet);
1169 * Can't do DGAP_UNLOCK here, as we don't have
1170 * lock_flags because we did a trylock above.
1172 spin_unlock(&brd->bd_lock);
1179 * Schedule ourself back at the nominal wakeup interval.
1181 DGAP_LOCK(dgap_poll_lock, lock_flags);
1182 dgap_poll_time += dgap_jiffies_from_ms(dgap_poll_tick);
1184 new_time = dgap_poll_time - jiffies;
1186 if ((ulong) new_time >= 2 * dgap_poll_tick) {
1188 jiffies + dgap_jiffies_from_ms(dgap_poll_tick);
1191 dgap_poll_timer.function = dgap_poll_handler;
1192 dgap_poll_timer.data = 0;
1193 dgap_poll_timer.expires = dgap_poll_time;
1194 DGAP_UNLOCK(dgap_poll_lock, lock_flags);
1196 if (!dgap_poll_stop)
1197 add_timer(&dgap_poll_timer);
1203 * Driver interrupt handler.
1205 static irqreturn_t dgap_intr(int irq, void *voidbrd)
1207 struct board_t *brd = (struct board_t *) voidbrd;
1213 * Check to make sure its for us.
1215 if (brd->magic != DGAP_BOARD_MAGIC)
1221 * Schedule tasklet to run at a better time.
1223 tasklet_schedule(&brd->helper_tasklet);
1228 * dgap_init_globals()
1230 * This is where we initialize the globals from the static insmod
1231 * configuration variables. These are declared near the head of
1234 static void dgap_init_globals(void)
1238 for (i = 0; i < MAXBOARDS; i++)
1239 dgap_Board[i] = NULL;
1241 init_timer(&dgap_poll_timer);
1243 init_waitqueue_head(&dgap_dl_wait);
1247 /************************************************************************
1251 ************************************************************************/
1256 * Put the driver to sleep for x ms's
1258 * Returns 0 if timed out, !0 (showing signal) if interrupted by a signal.
1260 static int dgap_ms_sleep(ulong ms)
1262 current->state = TASK_INTERRUPTIBLE;
1263 schedule_timeout((ms * HZ) / 1000);
1264 return signal_pending(current);
1267 /************************************************************************
1269 * TTY Initialization/Cleanup Functions
1271 ************************************************************************/
1274 * dgap_tty_preinit()
1276 * Initialize any global tty related data before we download any boards.
1278 static int dgap_tty_preinit(void)
1281 * Allocate a buffer for doing the copy from user space to
1282 * kernel space in dgap_input(). We only use one buffer and
1283 * control access to it with a semaphore. If we are paging, we
1284 * are already in trouble so one buffer won't hurt much anyway.
1286 dgap_TmpWriteBuf = kmalloc(WRITEBUFLEN, GFP_ATOMIC);
1288 if (!dgap_TmpWriteBuf)
1295 * dgap_tty_register()
1297 * Init the tty subsystem for this board.
1299 static int dgap_tty_register(struct board_t *brd)
1303 brd->SerialDriver = alloc_tty_driver(MAXPORTS);
1305 snprintf(brd->SerialName, MAXTTYNAMELEN, "tty_dgap_%d_", brd->boardnum);
1306 brd->SerialDriver->name = brd->SerialName;
1307 brd->SerialDriver->name_base = 0;
1308 brd->SerialDriver->major = 0;
1309 brd->SerialDriver->minor_start = 0;
1310 brd->SerialDriver->type = TTY_DRIVER_TYPE_SERIAL;
1311 brd->SerialDriver->subtype = SERIAL_TYPE_NORMAL;
1312 brd->SerialDriver->init_termios = DgapDefaultTermios;
1313 brd->SerialDriver->driver_name = DRVSTR;
1314 brd->SerialDriver->flags = (TTY_DRIVER_REAL_RAW |
1315 TTY_DRIVER_DYNAMIC_DEV |
1316 TTY_DRIVER_HARDWARE_BREAK);
1318 /* The kernel wants space to store pointers to tty_structs */
1319 brd->SerialDriver->ttys =
1320 kzalloc(MAXPORTS * sizeof(struct tty_struct *), GFP_KERNEL);
1321 if (!brd->SerialDriver->ttys)
1325 * Entry points for driver. Called by the kernel from
1326 * tty_io.c and n_tty.c.
1328 tty_set_operations(brd->SerialDriver, &dgap_tty_ops);
1331 * If we're doing transparent print, we have to do all of the above
1332 * again, separately so we don't get the LD confused about what major
1333 * we are when we get into the dgap_tty_open() routine.
1335 brd->PrintDriver = alloc_tty_driver(MAXPORTS);
1337 snprintf(brd->PrintName, MAXTTYNAMELEN, "pr_dgap_%d_", brd->boardnum);
1338 brd->PrintDriver->name = brd->PrintName;
1339 brd->PrintDriver->name_base = 0;
1340 brd->PrintDriver->major = 0;
1341 brd->PrintDriver->minor_start = 0;
1342 brd->PrintDriver->type = TTY_DRIVER_TYPE_SERIAL;
1343 brd->PrintDriver->subtype = SERIAL_TYPE_NORMAL;
1344 brd->PrintDriver->init_termios = DgapDefaultTermios;
1345 brd->PrintDriver->driver_name = DRVSTR;
1346 brd->PrintDriver->flags = (TTY_DRIVER_REAL_RAW |
1347 TTY_DRIVER_DYNAMIC_DEV |
1348 TTY_DRIVER_HARDWARE_BREAK);
1350 /* The kernel wants space to store pointers to tty_structs */
1351 brd->PrintDriver->ttys =
1352 kzalloc(MAXPORTS * sizeof(struct tty_struct *), GFP_KERNEL);
1353 if (!brd->PrintDriver->ttys)
1357 * Entry points for driver. Called by the kernel from
1358 * tty_io.c and n_tty.c.
1360 tty_set_operations(brd->PrintDriver, &dgap_tty_ops);
1362 if (!brd->dgap_Major_Serial_Registered) {
1363 /* Register tty devices */
1364 rc = tty_register_driver(brd->SerialDriver);
1367 brd->dgap_Major_Serial_Registered = TRUE;
1368 dgap_BoardsByMajor[brd->SerialDriver->major] = brd;
1369 brd->dgap_Serial_Major = brd->SerialDriver->major;
1372 if (!brd->dgap_Major_TransparentPrint_Registered) {
1373 /* Register Transparent Print devices */
1374 rc = tty_register_driver(brd->PrintDriver);
1377 brd->dgap_Major_TransparentPrint_Registered = TRUE;
1378 dgap_BoardsByMajor[brd->PrintDriver->major] = brd;
1379 brd->dgap_TransparentPrint_Major = brd->PrintDriver->major;
1388 * Init the tty subsystem. Called once per board after board has been
1389 * downloaded and init'ed.
1391 static int dgap_tty_init(struct board_t *brd)
1395 uint true_count = 0;
1398 struct channel_t *ch;
1406 * Initialize board structure elements.
1409 vaddr = brd->re_map_membase;
1410 true_count = readw((vaddr + NCHAN));
1412 brd->nasync = dgap_config_get_number_of_ports(brd);
1415 brd->nasync = brd->maxports;
1417 if (brd->nasync > brd->maxports)
1418 brd->nasync = brd->maxports;
1420 if (true_count != brd->nasync) {
1421 if ((brd->type == PPCM) && (true_count == 64)) {
1422 pr_warn("dgap: %s configured for %d ports, has %d ports.\n",
1423 brd->name, brd->nasync, true_count);
1424 pr_warn("dgap: Please make SURE the EBI cable running from the card\n");
1425 pr_warn("dgap: to each EM module is plugged into EBI IN!\n");
1426 } else if ((brd->type == PPCM) && (true_count == 0)) {
1427 pr_warn("dgap: %s configured for %d ports, has %d ports.\n",
1428 brd->name, brd->nasync, true_count);
1429 pr_warn("dgap: Please make SURE the EBI cable running from the card\n");
1430 pr_warn("dgap: to each EM module is plugged into EBI IN!\n");
1432 pr_warn("dgap: %s configured for %d ports, has %d ports.\n",
1433 brd->name, brd->nasync, true_count);
1435 brd->nasync = true_count;
1437 /* If no ports, don't bother going any further */
1439 brd->state = BOARD_FAILED;
1440 brd->dpastatus = BD_NOFEP;
1446 * Allocate channel memory that might not have been allocated
1447 * when the driver was first loaded.
1449 for (i = 0; i < brd->nasync; i++) {
1450 if (!brd->channels[i]) {
1452 kzalloc(sizeof(struct channel_t), GFP_ATOMIC);
1453 if (!brd->channels[i])
1458 ch = brd->channels[0];
1459 vaddr = brd->re_map_membase;
1461 bs = (struct bs_t *) ((ulong) vaddr + CHANBUF);
1462 cm = (struct cm_t *) ((ulong) vaddr + CMDBUF);
1466 /* Set up channel variables */
1467 for (i = 0; i < brd->nasync; i++, ch = brd->channels[i], bs++) {
1469 if (!brd->channels[i])
1472 DGAP_SPINLOCK_INIT(ch->ch_lock);
1474 /* Store all our magic numbers */
1475 ch->magic = DGAP_CHANNEL_MAGIC;
1476 ch->ch_tun.magic = DGAP_UNIT_MAGIC;
1477 ch->ch_tun.un_type = DGAP_SERIAL;
1478 ch->ch_tun.un_ch = ch;
1479 ch->ch_tun.un_dev = i;
1481 ch->ch_pun.magic = DGAP_UNIT_MAGIC;
1482 ch->ch_pun.un_type = DGAP_PRINT;
1483 ch->ch_pun.un_ch = ch;
1484 ch->ch_pun.un_dev = i;
1486 ch->ch_vaddr = vaddr;
1491 ch->ch_digi = dgap_digi_init;
1494 * Set up digi dsr and dcd bits based on altpin flag.
1496 if (dgap_config_get_altpin(brd)) {
1499 ch->ch_digi.digi_flags |= DIGI_ALTPIN;
1502 ch->ch_dsr = DM_DSR;
1505 ch->ch_taddr = vaddr + ((ch->ch_bs->tx_seg) << 4);
1506 ch->ch_raddr = vaddr + ((ch->ch_bs->rx_seg) << 4);
1509 ch->ch_tsize = readw(&(ch->ch_bs->tx_max)) + 1;
1510 ch->ch_rsize = readw(&(ch->ch_bs->rx_max)) + 1;
1514 /* .25 second delay */
1515 ch->ch_close_delay = 250;
1518 * Set queue water marks, interrupt mask,
1519 * and general tty parameters.
1521 tlw = ch->ch_tsize >= 2000 ? ((ch->ch_tsize * 5) / 8) :
1525 dgap_cmdw(ch, STLOW, tlw, 0);
1527 dgap_cmdw(ch, SRLOW, ch->ch_rsize / 2, 0);
1529 dgap_cmdw(ch, SRHIGH, 7 * ch->ch_rsize / 8, 0);
1531 ch->ch_mistat = readb(&(ch->ch_bs->m_stat));
1533 init_waitqueue_head(&ch->ch_flags_wait);
1534 init_waitqueue_head(&ch->ch_tun.un_flags_wait);
1535 init_waitqueue_head(&ch->ch_pun.un_flags_wait);
1536 init_waitqueue_head(&ch->ch_sniff_wait);
1538 /* Turn on all modem interrupts for now */
1539 modem = (DM_CD | DM_DSR | DM_CTS | DM_RI);
1540 writeb(modem, &(ch->ch_bs->m_int));
1543 * Set edelay to 0 if interrupts are turned on,
1544 * otherwise set edelay to the usual 100.
1547 writew(0, &(ch->ch_bs->edelay));
1549 writew(100, &(ch->ch_bs->edelay));
1551 writeb(1, &(ch->ch_bs->idata));
1558 * dgap_tty_post_uninit()
1560 * UnInitialize any global tty related data.
1562 static void dgap_tty_post_uninit(void)
1564 kfree(dgap_TmpWriteBuf);
1565 dgap_TmpWriteBuf = NULL;
1571 * Uninitialize the TTY portion of this driver. Free all memory and
1574 static void dgap_tty_uninit(struct board_t *brd)
1579 if (brd->dgap_Major_Serial_Registered) {
1580 dgap_BoardsByMajor[brd->SerialDriver->major] = NULL;
1581 brd->dgap_Serial_Major = 0;
1582 for (i = 0; i < brd->nasync; i++) {
1583 tty_port_destroy(&brd->SerialPorts[i]);
1584 dev = brd->channels[i]->ch_tun.un_sysfs;
1585 dgap_remove_tty_sysfs(dev);
1586 tty_unregister_device(brd->SerialDriver, i);
1588 tty_unregister_driver(brd->SerialDriver);
1589 kfree(brd->SerialDriver->ttys);
1590 brd->SerialDriver->ttys = NULL;
1591 put_tty_driver(brd->SerialDriver);
1592 kfree(brd->SerialPorts);
1593 brd->dgap_Major_Serial_Registered = FALSE;
1596 if (brd->dgap_Major_TransparentPrint_Registered) {
1597 dgap_BoardsByMajor[brd->PrintDriver->major] = NULL;
1598 brd->dgap_TransparentPrint_Major = 0;
1599 for (i = 0; i < brd->nasync; i++) {
1600 tty_port_destroy(&brd->PrinterPorts[i]);
1601 dev = brd->channels[i]->ch_pun.un_sysfs;
1602 dgap_remove_tty_sysfs(dev);
1603 tty_unregister_device(brd->PrintDriver, i);
1605 tty_unregister_driver(brd->PrintDriver);
1606 kfree(brd->PrintDriver->ttys);
1607 brd->PrintDriver->ttys = NULL;
1608 put_tty_driver(brd->PrintDriver);
1609 kfree(brd->PrinterPorts);
1610 brd->dgap_Major_TransparentPrint_Registered = FALSE;
1614 #define TMPBUFLEN (1024)
1616 * dgap_sniff - Dump data out to the "sniff" buffer if the
1617 * proc sniff file is opened...
1619 static void dgap_sniff_nowait_nolock(struct channel_t *ch, uchar *text,
1620 uchar *buf, int len)
1628 char tmpbuf[TMPBUFLEN];
1632 /* Leave if sniff not open */
1633 if (!(ch->ch_sniff_flags & SNIFF_OPEN))
1636 do_gettimeofday(&tv);
1638 /* Create our header for data dump */
1639 p += sprintf(p, "<%ld %ld><%s><", tv.tv_sec, tv.tv_usec, text);
1640 tmpbuflen = p - tmpbuf;
1645 for (i = 0; i < len && tmpbuflen < (TMPBUFLEN - 4); i++) {
1646 p += sprintf(p, "%02x ", *buf);
1648 tmpbuflen = p - tmpbuf;
1651 if (tmpbuflen < (TMPBUFLEN - 4)) {
1653 p += sprintf(p - 1, "%s\n", ">");
1655 p += sprintf(p, "%s\n", ">");
1661 nbuf = strlen(tmpbuf);
1665 * Loop while data remains.
1667 while (nbuf > 0 && ch->ch_sniff_buf) {
1669 * Determine the amount of available space left in the
1670 * buffer. If there's none, wait until some appears.
1672 n = (ch->ch_sniff_out - ch->ch_sniff_in - 1) &
1676 * If there is no space left to write to in our sniff
1677 * buffer, we have no choice but to drop the data.
1678 * We *cannot* sleep here waiting for space, because
1679 * this function was probably called by the
1680 * interrupt/timer routines!
1686 * Copy as much data as will fit.
1692 r = SNIFF_MAX - ch->ch_sniff_in;
1695 memcpy(ch->ch_sniff_buf + ch->ch_sniff_in, p, r);
1698 ch->ch_sniff_in = 0;
1703 memcpy(ch->ch_sniff_buf + ch->ch_sniff_in, p, n);
1705 ch->ch_sniff_in += n;
1710 * Wakeup any thread waiting for data
1712 if (ch->ch_sniff_flags & SNIFF_WAIT_DATA) {
1713 ch->ch_sniff_flags &= ~SNIFF_WAIT_DATA;
1714 wake_up_interruptible(&ch->ch_sniff_wait);
1719 * If the user sent us too much data to push into our tmpbuf,
1720 * we need to keep looping around on all the data.
1722 if (too_much_data) {
1727 } while (too_much_data);
1730 /*=======================================================================
1732 * dgap_input - Process received data.
1734 * ch - Pointer to channel structure.
1736 *=======================================================================*/
1738 static void dgap_input(struct channel_t *ch)
1742 struct tty_struct *tp;
1743 struct tty_ldisc *ld;
1757 if (!ch || ch->magic != DGAP_CHANNEL_MAGIC)
1760 tp = ch->ch_tun.un_tty;
1767 if (!bd || bd->magic != DGAP_BOARD_MAGIC)
1770 DGAP_LOCK(bd->bd_lock, lock_flags);
1771 DGAP_LOCK(ch->ch_lock, lock_flags2);
1774 * Figure the number of characters in the buffer.
1775 * Exit immediately if none.
1778 rmask = ch->ch_rsize - 1;
1780 head = readw(&(bs->rx_head));
1782 tail = readw(&(bs->rx_tail));
1785 data_len = (head - tail) & rmask;
1787 if (data_len == 0) {
1788 writeb(1, &(bs->idata));
1789 DGAP_UNLOCK(ch->ch_lock, lock_flags2);
1790 DGAP_UNLOCK(bd->bd_lock, lock_flags);
1795 * If the device is not open, or CREAD is off, flush
1796 * input data and return immediately.
1798 if ((bd->state != BOARD_READY) || !tp ||
1799 (tp->magic != TTY_MAGIC) ||
1800 !(ch->ch_tun.un_flags & UN_ISOPEN) ||
1801 !(tp->termios.c_cflag & CREAD) ||
1802 (ch->ch_tun.un_flags & UN_CLOSING)) {
1804 writew(head, &(bs->rx_tail));
1805 writeb(1, &(bs->idata));
1806 DGAP_UNLOCK(ch->ch_lock, lock_flags2);
1807 DGAP_UNLOCK(bd->bd_lock, lock_flags);
1812 * If we are throttled, simply don't read any data.
1814 if (ch->ch_flags & CH_RXBLOCK) {
1815 writeb(1, &(bs->idata));
1816 DGAP_UNLOCK(ch->ch_lock, lock_flags2);
1817 DGAP_UNLOCK(bd->bd_lock, lock_flags);
1824 tmpchar = readb(&(bs->orun));
1826 ch->ch_err_overrun++;
1827 writeb(0, &(bs->orun));
1830 /* Decide how much data we can send into the tty layer */
1831 flip_len = TTY_FLIPBUF_SIZE;
1833 /* Chop down the length, if needed */
1834 len = min(data_len, flip_len);
1835 len = min(len, (N_TTY_BUF_SIZE - 1));
1837 ld = tty_ldisc_ref(tp);
1839 #ifdef TTY_DONT_FLIP
1841 * If the DONT_FLIP flag is on, don't flush our buffer, and act
1842 * like the ld doesn't have any space to put the data right now.
1844 if (test_bit(TTY_DONT_FLIP, &tp->flags))
1849 * If we were unable to get a reference to the ld,
1850 * don't flush our buffer, and act like the ld doesn't
1851 * have any space to put the data right now.
1857 * If ld doesn't have a pointer to a receive_buf function,
1858 * flush the data, then act like the ld doesn't have any
1859 * space to put the data right now.
1861 if (!ld->ops->receive_buf) {
1862 writew(head, &(bs->rx_tail));
1868 writeb(1, &(bs->idata));
1869 DGAP_UNLOCK(ch->ch_lock, lock_flags2);
1870 DGAP_UNLOCK(bd->bd_lock, lock_flags);
1872 tty_ldisc_deref(ld);
1876 buf = ch->ch_bd->flipbuf;
1880 * n now contains the most amount of data we can copy,
1881 * bounded either by our buffer size or the amount
1882 * of data the card actually has pending...
1886 s = ((head >= tail) ? head : ch->ch_rsize) - tail;
1892 memcpy_fromio(buf, (char *) ch->ch_raddr + tail, s);
1893 dgap_sniff_nowait_nolock(ch, "USER READ", buf, s);
1899 /* Flip queue if needed */
1903 writew(tail, &(bs->rx_tail));
1904 writeb(1, &(bs->idata));
1905 ch->ch_rxcount += len;
1908 * If we are completely raw, we don't need to go through a lot
1909 * of the tty layers that exist.
1910 * In this case, we take the shortest and fastest route we
1911 * can to relay the data to the user.
1913 * On the other hand, if we are not raw, we need to go through
1914 * the tty layer, which has its API more well defined.
1916 if (I_PARMRK(tp) || I_BRKINT(tp) || I_INPCK(tp)) {
1917 dgap_parity_scan(ch, ch->ch_bd->flipbuf,
1918 ch->ch_bd->flipflagbuf, &len);
1920 len = tty_buffer_request_room(tp->port, len);
1921 tty_insert_flip_string_flags(tp->port, ch->ch_bd->flipbuf,
1922 ch->ch_bd->flipflagbuf, len);
1924 len = tty_buffer_request_room(tp->port, len);
1925 tty_insert_flip_string(tp->port, ch->ch_bd->flipbuf, len);
1928 DGAP_UNLOCK(ch->ch_lock, lock_flags2);
1929 DGAP_UNLOCK(bd->bd_lock, lock_flags);
1931 /* Tell the tty layer its okay to "eat" the data now */
1932 tty_flip_buffer_push(tp->port);
1935 tty_ldisc_deref(ld);
1939 /************************************************************************
1940 * Determines when CARRIER changes state and takes appropriate
1942 ************************************************************************/
1943 static void dgap_carrier(struct channel_t *ch)
1947 int virt_carrier = 0;
1948 int phys_carrier = 0;
1950 if (!ch || ch->magic != DGAP_CHANNEL_MAGIC)
1955 if (!bd || bd->magic != DGAP_BOARD_MAGIC)
1958 /* Make sure altpin is always set correctly */
1959 if (ch->ch_digi.digi_flags & DIGI_ALTPIN) {
1963 ch->ch_dsr = DM_DSR;
1967 if (ch->ch_mistat & D_CD(ch))
1970 if (ch->ch_digi.digi_flags & DIGI_FORCEDCD)
1973 if (ch->ch_c_cflag & CLOCAL)
1977 * Test for a VIRTUAL carrier transition to HIGH.
1979 if (((ch->ch_flags & CH_FCAR) == 0) && (virt_carrier == 1)) {
1982 * When carrier rises, wake any threads waiting
1983 * for carrier in the open routine.
1986 if (waitqueue_active(&(ch->ch_flags_wait)))
1987 wake_up_interruptible(&ch->ch_flags_wait);
1991 * Test for a PHYSICAL carrier transition to HIGH.
1993 if (((ch->ch_flags & CH_CD) == 0) && (phys_carrier == 1)) {
1996 * When carrier rises, wake any threads waiting
1997 * for carrier in the open routine.
2000 if (waitqueue_active(&(ch->ch_flags_wait)))
2001 wake_up_interruptible(&ch->ch_flags_wait);
2005 * Test for a PHYSICAL transition to low, so long as we aren't
2006 * currently ignoring physical transitions (which is what "virtual
2007 * carrier" indicates).
2009 * The transition of the virtual carrier to low really doesn't
2010 * matter... it really only means "ignore carrier state", not
2011 * "make pretend that carrier is there".
2013 if ((virt_carrier == 0) &&
2014 ((ch->ch_flags & CH_CD) != 0) &&
2015 (phys_carrier == 0)) {
2018 * When carrier drops:
2020 * Drop carrier on all open units.
2022 * Flush queues, waking up any task waiting in the
2025 * Send a hangup to the control terminal.
2027 * Enable all select calls.
2029 if (waitqueue_active(&(ch->ch_flags_wait)))
2030 wake_up_interruptible(&ch->ch_flags_wait);
2032 if (ch->ch_tun.un_open_count > 0)
2033 tty_hangup(ch->ch_tun.un_tty);
2035 if (ch->ch_pun.un_open_count > 0)
2036 tty_hangup(ch->ch_pun.un_tty);
2040 * Make sure that our cached values reflect the current reality.
2042 if (virt_carrier == 1)
2043 ch->ch_flags |= CH_FCAR;
2045 ch->ch_flags &= ~CH_FCAR;
2047 if (phys_carrier == 1)
2048 ch->ch_flags |= CH_CD;
2050 ch->ch_flags &= ~CH_CD;
2053 /************************************************************************
2055 * TTY Entry points and helper functions
2057 ************************************************************************/
2063 static int dgap_tty_open(struct tty_struct *tty, struct file *file)
2065 struct board_t *brd;
2066 struct channel_t *ch;
2078 major = MAJOR(tty_devnum(tty));
2079 minor = MINOR(tty_devnum(tty));
2084 /* Get board pointer from our array of majors we have allocated */
2085 brd = dgap_BoardsByMajor[major];
2090 * If board is not yet up to a state of READY, go to
2091 * sleep waiting for it to happen or they cancel the open.
2093 rc = wait_event_interruptible(brd->state_wait,
2094 (brd->state & BOARD_READY));
2099 DGAP_LOCK(brd->bd_lock, lock_flags);
2101 /* The wait above should guarantee this cannot happen */
2102 if (brd->state != BOARD_READY) {
2103 DGAP_UNLOCK(brd->bd_lock, lock_flags);
2107 /* If opened device is greater than our number of ports, bail. */
2108 if (MINOR(tty_devnum(tty)) > brd->nasync) {
2109 DGAP_UNLOCK(brd->bd_lock, lock_flags);
2113 ch = brd->channels[minor];
2115 DGAP_UNLOCK(brd->bd_lock, lock_flags);
2119 /* Grab channel lock */
2120 DGAP_LOCK(ch->ch_lock, lock_flags2);
2122 /* Figure out our type */
2123 if (major == brd->dgap_Serial_Major) {
2124 un = &brd->channels[minor]->ch_tun;
2125 un->un_type = DGAP_SERIAL;
2126 } else if (major == brd->dgap_TransparentPrint_Major) {
2127 un = &brd->channels[minor]->ch_pun;
2128 un->un_type = DGAP_PRINT;
2130 DGAP_UNLOCK(ch->ch_lock, lock_flags2);
2131 DGAP_UNLOCK(brd->bd_lock, lock_flags);
2135 /* Store our unit into driver_data, so we always have it available. */
2136 tty->driver_data = un;
2139 * Error if channel info pointer is NULL.
2143 DGAP_UNLOCK(ch->ch_lock, lock_flags2);
2144 DGAP_UNLOCK(brd->bd_lock, lock_flags);
2151 if (!(un->un_flags & UN_ISOPEN)) {
2152 /* Store important variables. */
2155 /* Maybe do something here to the TTY struct as well? */
2159 * Initialize if neither terminal or printer is open.
2161 if (!((ch->ch_tun.un_flags | ch->ch_pun.un_flags) & UN_ISOPEN)) {
2167 * Flush input queue.
2169 head = readw(&(bs->rx_head));
2170 writew(head, &(bs->rx_tail));
2173 ch->pscan_state = 0;
2174 ch->pscan_savechar = 0;
2176 ch->ch_c_cflag = tty->termios.c_cflag;
2177 ch->ch_c_iflag = tty->termios.c_iflag;
2178 ch->ch_c_oflag = tty->termios.c_oflag;
2179 ch->ch_c_lflag = tty->termios.c_lflag;
2180 ch->ch_startc = tty->termios.c_cc[VSTART];
2181 ch->ch_stopc = tty->termios.c_cc[VSTOP];
2183 /* TODO: flush our TTY struct here? */
2188 * Run param in case we changed anything
2193 * follow protocol for opening port
2196 DGAP_UNLOCK(ch->ch_lock, lock_flags2);
2197 DGAP_UNLOCK(brd->bd_lock, lock_flags);
2199 rc = dgap_block_til_ready(tty, file, ch);
2204 /* No going back now, increment our unit and channel counters */
2205 DGAP_LOCK(ch->ch_lock, lock_flags);
2206 ch->ch_open_count++;
2207 un->un_open_count++;
2208 un->un_flags |= (UN_ISOPEN);
2209 DGAP_UNLOCK(ch->ch_lock, lock_flags);
2215 * dgap_block_til_ready()
2217 * Wait for DCD, if needed.
2219 static int dgap_block_til_ready(struct tty_struct *tty, struct file *file,
2220 struct channel_t *ch)
2223 struct un_t *un = NULL;
2226 int sleep_on_un_flags = 0;
2228 if (!tty || tty->magic != TTY_MAGIC || !file || !ch ||
2229 ch->magic != DGAP_CHANNEL_MAGIC)
2232 un = tty->driver_data;
2233 if (!un || un->magic != DGAP_UNIT_MAGIC)
2236 DGAP_LOCK(ch->ch_lock, lock_flags);
2243 sleep_on_un_flags = 0;
2246 * If board has failed somehow during our sleep,
2249 if (ch->ch_bd->state == BOARD_FAILED) {
2254 /* If tty was hung up, break out of loop and set error. */
2255 if (tty_hung_up_p(file)) {
2261 * If either unit is in the middle of the fragile part of close,
2262 * we just cannot touch the channel safely.
2263 * Go back to sleep, knowing that when the channel can be
2264 * touched safely, the close routine will signal the
2265 * ch_wait_flags to wake us back up.
2267 if (!((ch->ch_tun.un_flags | ch->ch_pun.un_flags) &
2271 * Our conditions to leave cleanly and happily:
2272 * 1) NONBLOCKING on the tty is set.
2274 * 3) DCD (fake or real) is active.
2277 if (file->f_flags & O_NONBLOCK)
2280 if (tty->flags & (1 << TTY_IO_ERROR))
2283 if (ch->ch_flags & CH_CD)
2286 if (ch->ch_flags & CH_FCAR)
2289 sleep_on_un_flags = 1;
2293 * If there is a signal pending, the user probably
2294 * interrupted (ctrl-c) us.
2295 * Leave loop with error set.
2297 if (signal_pending(current)) {
2298 retval = -ERESTARTSYS;
2303 * Store the flags before we let go of channel lock
2305 if (sleep_on_un_flags)
2306 old_flags = ch->ch_tun.un_flags | ch->ch_pun.un_flags;
2308 old_flags = ch->ch_flags;
2311 * Let go of channel lock before calling schedule.
2312 * Our poller will get any FEP events and wake us up when DCD
2313 * eventually goes active.
2316 DGAP_UNLOCK(ch->ch_lock, lock_flags);
2319 * Wait for something in the flags to change
2320 * from the current value.
2322 if (sleep_on_un_flags) {
2323 retval = wait_event_interruptible(un->un_flags_wait,
2324 (old_flags != (ch->ch_tun.un_flags |
2325 ch->ch_pun.un_flags)));
2327 retval = wait_event_interruptible(ch->ch_flags_wait,
2328 (old_flags != ch->ch_flags));
2332 * We got woken up for some reason.
2333 * Before looping around, grab our channel lock.
2335 DGAP_LOCK(ch->ch_lock, lock_flags);
2340 DGAP_UNLOCK(ch->ch_lock, lock_flags);
2351 * Hangup the port. Like a close, but don't wait for output to drain.
2353 static void dgap_tty_hangup(struct tty_struct *tty)
2356 struct channel_t *ch;
2359 if (!tty || tty->magic != TTY_MAGIC)
2362 un = tty->driver_data;
2363 if (!un || un->magic != DGAP_UNIT_MAGIC)
2367 if (!ch || ch->magic != DGAP_CHANNEL_MAGIC)
2371 if (!bd || bd->magic != DGAP_BOARD_MAGIC)
2374 /* flush the transmit queues */
2375 dgap_tty_flush_buffer(tty);
2383 static void dgap_tty_close(struct tty_struct *tty, struct file *file)
2385 struct ktermios *ts;
2387 struct channel_t *ch;
2392 if (!tty || tty->magic != TTY_MAGIC)
2395 un = tty->driver_data;
2396 if (!un || un->magic != DGAP_UNIT_MAGIC)
2400 if (!ch || ch->magic != DGAP_CHANNEL_MAGIC)
2404 if (!bd || bd->magic != DGAP_BOARD_MAGIC)
2409 DGAP_LOCK(ch->ch_lock, lock_flags);
2412 * Determine if this is the last close or not - and if we agree about
2413 * which type of close it is with the Line Discipline
2415 if ((tty->count == 1) && (un->un_open_count != 1)) {
2417 * Uh, oh. tty->count is 1, which means that the tty
2418 * structure will be freed. un_open_count should always
2419 * be one in these conditions. If it's greater than
2420 * one, we've got real problems, since it means the
2421 * serial port won't be shutdown.
2423 un->un_open_count = 1;
2426 if (--un->un_open_count < 0)
2427 un->un_open_count = 0;
2429 ch->ch_open_count--;
2431 if (ch->ch_open_count && un->un_open_count) {
2432 DGAP_UNLOCK(ch->ch_lock, lock_flags);
2436 /* OK, its the last close on the unit */
2438 un->un_flags |= UN_CLOSING;
2443 * Only officially close channel if count is 0 and
2444 * DIGI_PRINTER bit is not set.
2446 if ((ch->ch_open_count == 0) &&
2447 !(ch->ch_digi.digi_flags & DIGI_PRINTER)) {
2449 ch->ch_flags &= ~(CH_RXBLOCK);
2451 DGAP_UNLOCK(ch->ch_lock, lock_flags);
2453 /* wait for output to drain */
2454 /* This will also return if we take an interrupt */
2456 rc = dgap_wait_for_drain(tty);
2458 dgap_tty_flush_buffer(tty);
2459 tty_ldisc_flush(tty);
2461 DGAP_LOCK(ch->ch_lock, lock_flags);
2466 * If we have HUPCL set, lower DTR and RTS
2468 if (ch->ch_c_cflag & HUPCL) {
2469 ch->ch_mostat &= ~(D_RTS(ch)|D_DTR(ch));
2470 dgap_cmdb(ch, SMODEM, 0, D_DTR(ch)|D_RTS(ch), 0);
2473 * Go to sleep to ensure RTS/DTR
2474 * have been dropped for modems to see it.
2476 if (ch->ch_close_delay) {
2477 DGAP_UNLOCK(ch->ch_lock, lock_flags);
2478 dgap_ms_sleep(ch->ch_close_delay);
2479 DGAP_LOCK(ch->ch_lock, lock_flags);
2483 ch->pscan_state = 0;
2484 ch->pscan_savechar = 0;
2485 ch->ch_baud_info = 0;
2490 * turn off print device when closing print device.
2492 if ((un->un_type == DGAP_PRINT) && (ch->ch_flags & CH_PRON)) {
2493 dgap_wmove(ch, ch->ch_digi.digi_offstr,
2494 (int) ch->ch_digi.digi_offlen);
2495 ch->ch_flags &= ~CH_PRON;
2499 un->un_flags &= ~(UN_ISOPEN | UN_CLOSING);
2500 tty->driver_data = NULL;
2502 wake_up_interruptible(&ch->ch_flags_wait);
2503 wake_up_interruptible(&un->un_flags_wait);
2505 DGAP_UNLOCK(ch->ch_lock, lock_flags);
2509 * dgap_tty_chars_in_buffer()
2511 * Return number of characters that have not been transmitted yet.
2513 * This routine is used by the line discipline to determine if there
2514 * is data waiting to be transmitted/drained/flushed or not.
2516 static int dgap_tty_chars_in_buffer(struct tty_struct *tty)
2518 struct board_t *bd = NULL;
2519 struct channel_t *ch = NULL;
2520 struct un_t *un = NULL;
2521 struct bs_t *bs = NULL;
2524 u16 thead, ttail, tmask, chead, ctail;
2525 ulong lock_flags = 0;
2526 ulong lock_flags2 = 0;
2531 un = tty->driver_data;
2532 if (!un || un->magic != DGAP_UNIT_MAGIC)
2536 if (!ch || ch->magic != DGAP_CHANNEL_MAGIC)
2540 if (!bd || bd->magic != DGAP_BOARD_MAGIC)
2547 DGAP_LOCK(bd->bd_lock, lock_flags);
2548 DGAP_LOCK(ch->ch_lock, lock_flags2);
2550 tmask = (ch->ch_tsize - 1);
2552 /* Get Transmit queue pointers */
2553 thead = readw(&(bs->tx_head)) & tmask;
2554 ttail = readw(&(bs->tx_tail)) & tmask;
2556 /* Get tbusy flag */
2557 tbusy = readb(&(bs->tbusy));
2559 /* Get Command queue pointers */
2560 chead = readw(&(ch->ch_cm->cm_head));
2561 ctail = readw(&(ch->ch_cm->cm_tail));
2563 DGAP_UNLOCK(ch->ch_lock, lock_flags2);
2564 DGAP_UNLOCK(bd->bd_lock, lock_flags);
2567 * The only way we know for sure if there is no pending
2568 * data left to be transferred, is if:
2569 * 1) Transmit head and tail are equal (empty).
2570 * 2) Command queue head and tail are equal (empty).
2571 * 3) The "TBUSY" flag is 0. (Transmitter not busy).
2574 if ((ttail == thead) && (tbusy == 0) && (chead == ctail)) {
2578 chars = thead - ttail;
2580 chars = thead - ttail + ch->ch_tsize;
2582 * Fudge factor here.
2583 * If chars is zero, we know that the command queue had
2584 * something in it or tbusy was set. Because we cannot
2585 * be sure if there is still some data to be transmitted,
2586 * lets lie, and tell ld we have 1 byte left.
2590 * If TBUSY is still set, and our tx buffers are empty,
2591 * force the firmware to send me another wakeup after
2592 * TBUSY has been cleared.
2595 DGAP_LOCK(ch->ch_lock, lock_flags);
2596 un->un_flags |= UN_EMPTY;
2597 writeb(1, &(bs->iempty));
2598 DGAP_UNLOCK(ch->ch_lock, lock_flags);
2607 static int dgap_wait_for_drain(struct tty_struct *tty)
2609 struct channel_t *ch;
2614 ulong lock_flags = 0;
2616 if (!tty || tty->magic != TTY_MAGIC)
2619 un = tty->driver_data;
2620 if (!un || un->magic != DGAP_UNIT_MAGIC)
2624 if (!ch || ch->magic != DGAP_CHANNEL_MAGIC)
2633 /* Loop until data is drained */
2634 while (count != 0) {
2636 count = dgap_tty_chars_in_buffer(tty);
2641 /* Set flag waiting for drain */
2642 DGAP_LOCK(ch->ch_lock, lock_flags);
2643 un->un_flags |= UN_EMPTY;
2644 writeb(1, &(bs->iempty));
2645 DGAP_UNLOCK(ch->ch_lock, lock_flags);
2647 /* Go to sleep till we get woken up */
2648 ret = wait_event_interruptible(un->un_flags_wait,
2649 ((un->un_flags & UN_EMPTY) == 0));
2650 /* If ret is non-zero, user ctrl-c'ed us */
2655 DGAP_LOCK(ch->ch_lock, lock_flags);
2656 un->un_flags &= ~(UN_EMPTY);
2657 DGAP_UNLOCK(ch->ch_lock, lock_flags);
2665 * Reduces bytes_available to the max number of characters
2666 * that can be sent currently given the maxcps value, and
2667 * returns the new bytes_available. This only affects printer
2670 static int dgap_maxcps_room(struct tty_struct *tty, int bytes_available)
2672 struct channel_t *ch = NULL;
2673 struct un_t *un = NULL;
2676 return bytes_available;
2678 un = tty->driver_data;
2679 if (!un || un->magic != DGAP_UNIT_MAGIC)
2680 return bytes_available;
2683 if (!ch || ch->magic != DGAP_CHANNEL_MAGIC)
2684 return bytes_available;
2687 * If its not the Transparent print device, return
2688 * the full data amount.
2690 if (un->un_type != DGAP_PRINT)
2691 return bytes_available;
2693 if (ch->ch_digi.digi_maxcps > 0 && ch->ch_digi.digi_bufsize > 0) {
2695 unsigned long current_time = jiffies;
2696 unsigned long buffer_time = current_time +
2697 (HZ * ch->ch_digi.digi_bufsize) /
2698 ch->ch_digi.digi_maxcps;
2700 if (ch->ch_cpstime < current_time) {
2701 /* buffer is empty */
2702 ch->ch_cpstime = current_time; /* reset ch_cpstime */
2703 cps_limit = ch->ch_digi.digi_bufsize;
2704 } else if (ch->ch_cpstime < buffer_time) {
2705 /* still room in the buffer */
2706 cps_limit = ((buffer_time - ch->ch_cpstime) *
2707 ch->ch_digi.digi_maxcps) / HZ;
2709 /* no room in the buffer */
2713 bytes_available = min(cps_limit, bytes_available);
2716 return bytes_available;
2719 static inline void dgap_set_firmware_event(struct un_t *un, unsigned int event)
2721 struct channel_t *ch = NULL;
2722 struct bs_t *bs = NULL;
2724 if (!un || un->magic != DGAP_UNIT_MAGIC)
2727 if (!ch || ch->magic != DGAP_CHANNEL_MAGIC)
2733 if ((event & UN_LOW) != 0) {
2734 if ((un->un_flags & UN_LOW) == 0) {
2735 un->un_flags |= UN_LOW;
2736 writeb(1, &(bs->ilow));
2739 if ((event & UN_LOW) != 0) {
2740 if ((un->un_flags & UN_EMPTY) == 0) {
2741 un->un_flags |= UN_EMPTY;
2742 writeb(1, &(bs->iempty));
2748 * dgap_tty_write_room()
2750 * Return space available in Tx buffer
2752 static int dgap_tty_write_room(struct tty_struct *tty)
2754 struct channel_t *ch = NULL;
2755 struct un_t *un = NULL;
2756 struct bs_t *bs = NULL;
2757 u16 head, tail, tmask;
2759 ulong lock_flags = 0;
2761 if (tty == NULL || dgap_TmpWriteBuf == NULL)
2764 un = tty->driver_data;
2765 if (!un || un->magic != DGAP_UNIT_MAGIC)
2769 if (!ch || ch->magic != DGAP_CHANNEL_MAGIC)
2776 DGAP_LOCK(ch->ch_lock, lock_flags);
2778 tmask = ch->ch_tsize - 1;
2779 head = readw(&(bs->tx_head)) & tmask;
2780 tail = readw(&(bs->tx_tail)) & tmask;
2782 ret = tail - head - 1;
2784 ret += ch->ch_tsize;
2786 /* Limit printer to maxcps */
2787 ret = dgap_maxcps_room(tty, ret);
2790 * If we are printer device, leave space for
2791 * possibly both the on and off strings.
2793 if (un->un_type == DGAP_PRINT) {
2794 if (!(ch->ch_flags & CH_PRON))
2795 ret -= ch->ch_digi.digi_onlen;
2796 ret -= ch->ch_digi.digi_offlen;
2798 if (ch->ch_flags & CH_PRON)
2799 ret -= ch->ch_digi.digi_offlen;
2806 * Schedule FEP to wake us up if needed.
2808 * TODO: This might be overkill...
2809 * Do we really need to schedule callbacks from the FEP
2810 * in every case? Can we get smarter based on ret?
2812 dgap_set_firmware_event(un, UN_LOW | UN_EMPTY);
2813 DGAP_UNLOCK(ch->ch_lock, lock_flags);
2819 * dgap_tty_put_char()
2821 * Put a character into ch->ch_buf
2823 * - used by the line discipline for OPOST processing
2825 static int dgap_tty_put_char(struct tty_struct *tty, unsigned char c)
2828 * Simply call tty_write.
2830 dgap_tty_write(tty, &c, 1);
2837 * Take data from the user or kernel and send it out to the FEP.
2838 * In here exists all the Transparent Print magic as well.
2840 static int dgap_tty_write(struct tty_struct *tty, const unsigned char *buf,
2843 struct channel_t *ch = NULL;
2844 struct un_t *un = NULL;
2845 struct bs_t *bs = NULL;
2847 u16 head, tail, tmask, remain;
2848 int bufcount = 0, n = 0;
2853 if (tty == NULL || dgap_TmpWriteBuf == NULL)
2856 un = tty->driver_data;
2857 if (!un || un->magic != DGAP_UNIT_MAGIC)
2861 if (!ch || ch->magic != DGAP_CHANNEL_MAGIC)
2872 * Store original amount of characters passed in.
2873 * This helps to figure out if we should ask the FEP
2874 * to send us an event when it has more space available.
2878 DGAP_LOCK(ch->ch_lock, lock_flags);
2880 /* Get our space available for the channel from the board */
2881 tmask = ch->ch_tsize - 1;
2882 head = readw(&(bs->tx_head)) & tmask;
2883 tail = readw(&(bs->tx_tail)) & tmask;
2885 bufcount = tail - head - 1;
2887 bufcount += ch->ch_tsize;
2890 * Limit printer output to maxcps overall, with bursts allowed
2891 * up to bufsize characters.
2893 bufcount = dgap_maxcps_room(tty, bufcount);
2896 * Take minimum of what the user wants to send, and the
2897 * space available in the FEP buffer.
2899 count = min(count, bufcount);
2902 * Bail if no space left.
2905 dgap_set_firmware_event(un, UN_LOW | UN_EMPTY);
2906 DGAP_UNLOCK(ch->ch_lock, lock_flags);
2911 * Output the printer ON string, if we are in terminal mode, but
2912 * need to be in printer mode.
2914 if ((un->un_type == DGAP_PRINT) && !(ch->ch_flags & CH_PRON)) {
2915 dgap_wmove(ch, ch->ch_digi.digi_onstr,
2916 (int) ch->ch_digi.digi_onlen);
2917 head = readw(&(bs->tx_head)) & tmask;
2918 ch->ch_flags |= CH_PRON;
2922 * On the other hand, output the printer OFF string, if we are
2923 * currently in printer mode, but need to output to the terminal.
2925 if ((un->un_type != DGAP_PRINT) && (ch->ch_flags & CH_PRON)) {
2926 dgap_wmove(ch, ch->ch_digi.digi_offstr,
2927 (int) ch->ch_digi.digi_offlen);
2928 head = readw(&(bs->tx_head)) & tmask;
2929 ch->ch_flags &= ~CH_PRON;
2933 * If there is nothing left to copy, or
2934 * I can't handle any more data, leave.
2937 dgap_set_firmware_event(un, UN_LOW | UN_EMPTY);
2938 DGAP_UNLOCK(ch->ch_lock, lock_flags);
2944 count = min(count, WRITEBUFLEN);
2946 DGAP_UNLOCK(ch->ch_lock, lock_flags);
2949 * If data is coming from user space, copy it into a temporary
2950 * buffer so we don't get swapped out while doing the copy to
2953 /* we're allowed to block if it's from_user */
2954 if (down_interruptible(&dgap_TmpWriteSem))
2957 if (copy_from_user(dgap_TmpWriteBuf, (const uchar __user *)buf,
2959 up(&dgap_TmpWriteSem);
2963 DGAP_LOCK(ch->ch_lock, lock_flags);
2965 buf = dgap_TmpWriteBuf;
2971 * If the write wraps over the top of the circular buffer,
2972 * move the portion up to the wrap point, and reset the
2973 * pointers to the bottom.
2975 remain = ch->ch_tstart + ch->ch_tsize - head;
2979 vaddr = ch->ch_taddr + head;
2981 memcpy_toio(vaddr, (uchar *) buf, remain);
2982 dgap_sniff_nowait_nolock(ch, "USER WRITE", (uchar *) buf,
2985 head = ch->ch_tstart;
2992 * Move rest of data.
2994 vaddr = ch->ch_taddr + head;
2997 memcpy_toio(vaddr, (uchar *) buf, remain);
2998 dgap_sniff_nowait_nolock(ch, "USER WRITE", (uchar *)buf,
3006 ch->ch_txcount += count;
3008 writew(head, &(bs->tx_head));
3011 dgap_set_firmware_event(un, UN_LOW | UN_EMPTY);
3014 * If this is the print device, and the
3015 * printer is still on, we need to turn it
3016 * off before going idle. If the buffer is
3017 * non-empty, wait until it goes empty.
3018 * Otherwise turn it off right now.
3020 if ((un->un_type == DGAP_PRINT) && (ch->ch_flags & CH_PRON)) {
3021 tail = readw(&(bs->tx_tail)) & tmask;
3024 un->un_flags |= UN_EMPTY;
3025 writeb(1, &(bs->iempty));
3027 dgap_wmove(ch, ch->ch_digi.digi_offstr,
3028 (int) ch->ch_digi.digi_offlen);
3029 head = readw(&(bs->tx_head)) & tmask;
3030 ch->ch_flags &= ~CH_PRON;
3034 /* Update printer buffer empty time. */
3035 if ((un->un_type == DGAP_PRINT) && (ch->ch_digi.digi_maxcps > 0)
3036 && (ch->ch_digi.digi_bufsize > 0)) {
3037 ch->ch_cpstime += (HZ * count) / ch->ch_digi.digi_maxcps;
3041 DGAP_UNLOCK(ch->ch_lock, lock_flags);
3042 up(&dgap_TmpWriteSem);
3044 DGAP_UNLOCK(ch->ch_lock, lock_flags);
3050 * Return modem signals to ld.
3052 static int dgap_tty_tiocmget(struct tty_struct *tty)
3054 struct channel_t *ch;
3060 if (!tty || tty->magic != TTY_MAGIC)
3063 un = tty->driver_data;
3064 if (!un || un->magic != DGAP_UNIT_MAGIC)
3068 if (!ch || ch->magic != DGAP_CHANNEL_MAGIC)
3071 DGAP_LOCK(ch->ch_lock, lock_flags);
3073 mstat = readb(&(ch->ch_bs->m_stat));
3074 /* Append any outbound signals that might be pending... */
3075 mstat |= ch->ch_mostat;
3077 DGAP_UNLOCK(ch->ch_lock, lock_flags);
3081 if (mstat & D_DTR(ch))
3082 result |= TIOCM_DTR;
3083 if (mstat & D_RTS(ch))
3084 result |= TIOCM_RTS;
3085 if (mstat & D_CTS(ch))
3086 result |= TIOCM_CTS;
3087 if (mstat & D_DSR(ch))
3088 result |= TIOCM_DSR;
3089 if (mstat & D_RI(ch))
3091 if (mstat & D_CD(ch))
3098 * dgap_tty_tiocmset()
3100 * Set modem signals, called by ld.
3102 static int dgap_tty_tiocmset(struct tty_struct *tty,
3103 unsigned int set, unsigned int clear)
3106 struct channel_t *ch;
3112 if (!tty || tty->magic != TTY_MAGIC)
3115 un = tty->driver_data;
3116 if (!un || un->magic != DGAP_UNIT_MAGIC)
3120 if (!ch || ch->magic != DGAP_CHANNEL_MAGIC)
3124 if (!bd || bd->magic != DGAP_BOARD_MAGIC)
3127 DGAP_LOCK(bd->bd_lock, lock_flags);
3128 DGAP_LOCK(ch->ch_lock, lock_flags2);
3130 if (set & TIOCM_RTS) {
3131 ch->ch_mforce |= D_RTS(ch);
3132 ch->ch_mval |= D_RTS(ch);
3135 if (set & TIOCM_DTR) {
3136 ch->ch_mforce |= D_DTR(ch);
3137 ch->ch_mval |= D_DTR(ch);
3140 if (clear & TIOCM_RTS) {
3141 ch->ch_mforce |= D_RTS(ch);
3142 ch->ch_mval &= ~(D_RTS(ch));
3145 if (clear & TIOCM_DTR) {
3146 ch->ch_mforce |= D_DTR(ch);
3147 ch->ch_mval &= ~(D_DTR(ch));
3152 DGAP_UNLOCK(ch->ch_lock, lock_flags2);
3153 DGAP_UNLOCK(bd->bd_lock, lock_flags);
3159 * dgap_tty_send_break()
3161 * Send a Break, called by ld.
3163 static int dgap_tty_send_break(struct tty_struct *tty, int msec)
3166 struct channel_t *ch;
3172 if (!tty || tty->magic != TTY_MAGIC)
3175 un = tty->driver_data;
3176 if (!un || un->magic != DGAP_UNIT_MAGIC)
3180 if (!ch || ch->magic != DGAP_CHANNEL_MAGIC)
3184 if (!bd || bd->magic != DGAP_BOARD_MAGIC)
3199 DGAP_LOCK(bd->bd_lock, lock_flags);
3200 DGAP_LOCK(ch->ch_lock, lock_flags2);
3202 dgap_cmdw(ch, SBREAK, (u16) SBREAK_TIME, 0);
3204 dgap_cmdw(ch, SBREAK, (u16) msec, 0);
3206 DGAP_UNLOCK(ch->ch_lock, lock_flags2);
3207 DGAP_UNLOCK(bd->bd_lock, lock_flags);
3213 * dgap_tty_wait_until_sent()
3215 * wait until data has been transmitted, called by ld.
3217 static void dgap_tty_wait_until_sent(struct tty_struct *tty, int timeout)
3219 dgap_wait_for_drain(tty);
3225 * send a high priority character, called by ld.
3227 static void dgap_tty_send_xchar(struct tty_struct *tty, char c)
3230 struct channel_t *ch;
3235 if (!tty || tty->magic != TTY_MAGIC)
3238 un = tty->driver_data;
3239 if (!un || un->magic != DGAP_UNIT_MAGIC)
3243 if (!ch || ch->magic != DGAP_CHANNEL_MAGIC)
3247 if (!bd || bd->magic != DGAP_BOARD_MAGIC)
3250 DGAP_LOCK(bd->bd_lock, lock_flags);
3251 DGAP_LOCK(ch->ch_lock, lock_flags2);
3254 * This is technically what we should do.
3255 * However, the NIST tests specifically want
3256 * to see each XON or XOFF character that it
3257 * sends, so lets just send each character
3261 if (c == STOP_CHAR(tty))
3262 dgap_cmdw(ch, RPAUSE, 0, 0);
3263 else if (c == START_CHAR(tty))
3264 dgap_cmdw(ch, RRESUME, 0, 0);
3266 dgap_wmove(ch, &c, 1);
3268 dgap_wmove(ch, &c, 1);
3271 DGAP_UNLOCK(ch->ch_lock, lock_flags2);
3272 DGAP_UNLOCK(bd->bd_lock, lock_flags);
3278 * Return modem signals to ld.
3280 static int dgap_get_modem_info(struct channel_t *ch, unsigned int __user *value)
3287 if (!ch || ch->magic != DGAP_CHANNEL_MAGIC)
3290 DGAP_LOCK(ch->ch_lock, lock_flags);
3292 mstat = readb(&(ch->ch_bs->m_stat));
3293 /* Append any outbound signals that might be pending... */
3294 mstat |= ch->ch_mostat;
3296 DGAP_UNLOCK(ch->ch_lock, lock_flags);
3300 if (mstat & D_DTR(ch))
3301 result |= TIOCM_DTR;
3302 if (mstat & D_RTS(ch))
3303 result |= TIOCM_RTS;
3304 if (mstat & D_CTS(ch))
3305 result |= TIOCM_CTS;
3306 if (mstat & D_DSR(ch))
3307 result |= TIOCM_DSR;
3308 if (mstat & D_RI(ch))
3310 if (mstat & D_CD(ch))
3313 rc = put_user(result, value);
3319 * dgap_set_modem_info()
3321 * Set modem signals, called by ld.
3323 static int dgap_set_modem_info(struct tty_struct *tty, unsigned int command,
3324 unsigned int __user *value)
3327 struct channel_t *ch;
3330 unsigned int arg = 0;
3334 if (!tty || tty->magic != TTY_MAGIC)
3337 un = tty->driver_data;
3338 if (!un || un->magic != DGAP_UNIT_MAGIC)
3342 if (!ch || ch->magic != DGAP_CHANNEL_MAGIC)
3346 if (!bd || bd->magic != DGAP_BOARD_MAGIC)
3349 ret = get_user(arg, value);
3355 if (arg & TIOCM_RTS) {
3356 ch->ch_mforce |= D_RTS(ch);
3357 ch->ch_mval |= D_RTS(ch);
3360 if (arg & TIOCM_DTR) {
3361 ch->ch_mforce |= D_DTR(ch);
3362 ch->ch_mval |= D_DTR(ch);
3368 if (arg & TIOCM_RTS) {
3369 ch->ch_mforce |= D_RTS(ch);
3370 ch->ch_mval &= ~(D_RTS(ch));
3373 if (arg & TIOCM_DTR) {
3374 ch->ch_mforce |= D_DTR(ch);
3375 ch->ch_mval &= ~(D_DTR(ch));
3381 ch->ch_mforce = D_DTR(ch)|D_RTS(ch);
3383 if (arg & TIOCM_RTS)
3384 ch->ch_mval |= D_RTS(ch);
3386 ch->ch_mval &= ~(D_RTS(ch));
3388 if (arg & TIOCM_DTR)
3389 ch->ch_mval |= (D_DTR(ch));
3391 ch->ch_mval &= ~(D_DTR(ch));
3399 DGAP_LOCK(bd->bd_lock, lock_flags);
3400 DGAP_LOCK(ch->ch_lock, lock_flags2);
3404 DGAP_UNLOCK(ch->ch_lock, lock_flags2);
3405 DGAP_UNLOCK(bd->bd_lock, lock_flags);
3411 * dgap_tty_digigeta()
3413 * Ioctl to get the information for ditty.
3418 static int dgap_tty_digigeta(struct tty_struct *tty,
3419 struct digi_t __user *retinfo)
3421 struct channel_t *ch;
3429 if (!tty || tty->magic != TTY_MAGIC)
3432 un = tty->driver_data;
3433 if (!un || un->magic != DGAP_UNIT_MAGIC)
3437 if (!ch || ch->magic != DGAP_CHANNEL_MAGIC)
3440 memset(&tmp, 0, sizeof(tmp));
3442 DGAP_LOCK(ch->ch_lock, lock_flags);
3443 memcpy(&tmp, &ch->ch_digi, sizeof(tmp));
3444 DGAP_UNLOCK(ch->ch_lock, lock_flags);
3446 if (copy_to_user(retinfo, &tmp, sizeof(*retinfo)))
3453 * dgap_tty_digiseta()
3455 * Ioctl to set the information for ditty.
3460 static int dgap_tty_digiseta(struct tty_struct *tty,
3461 struct digi_t __user *new_info)
3464 struct channel_t *ch;
3466 struct digi_t new_digi;
3467 ulong lock_flags = 0;
3468 unsigned long lock_flags2;
3470 if (!tty || tty->magic != TTY_MAGIC)
3473 un = tty->driver_data;
3474 if (!un || un->magic != DGAP_UNIT_MAGIC)
3478 if (!ch || ch->magic != DGAP_CHANNEL_MAGIC)
3482 if (!bd || bd->magic != DGAP_BOARD_MAGIC)
3485 if (copy_from_user(&new_digi, new_info, sizeof(struct digi_t)))
3488 DGAP_LOCK(bd->bd_lock, lock_flags);
3489 DGAP_LOCK(ch->ch_lock, lock_flags2);
3491 memcpy(&ch->ch_digi, &new_digi, sizeof(struct digi_t));
3493 if (ch->ch_digi.digi_maxcps < 1)
3494 ch->ch_digi.digi_maxcps = 1;
3496 if (ch->ch_digi.digi_maxcps > 10000)
3497 ch->ch_digi.digi_maxcps = 10000;
3499 if (ch->ch_digi.digi_bufsize < 10)
3500 ch->ch_digi.digi_bufsize = 10;
3502 if (ch->ch_digi.digi_maxchar < 1)
3503 ch->ch_digi.digi_maxchar = 1;
3505 if (ch->ch_digi.digi_maxchar > ch->ch_digi.digi_bufsize)
3506 ch->ch_digi.digi_maxchar = ch->ch_digi.digi_bufsize;
3508 if (ch->ch_digi.digi_onlen > DIGI_PLEN)
3509 ch->ch_digi.digi_onlen = DIGI_PLEN;
3511 if (ch->ch_digi.digi_offlen > DIGI_PLEN)
3512 ch->ch_digi.digi_offlen = DIGI_PLEN;
3516 DGAP_UNLOCK(ch->ch_lock, lock_flags2);
3517 DGAP_UNLOCK(bd->bd_lock, lock_flags);
3523 * dgap_tty_digigetedelay()
3525 * Ioctl to get the current edelay setting.
3530 static int dgap_tty_digigetedelay(struct tty_struct *tty, int __user *retinfo)
3532 struct channel_t *ch;
3540 if (!tty || tty->magic != TTY_MAGIC)
3543 un = tty->driver_data;
3544 if (!un || un->magic != DGAP_UNIT_MAGIC)
3548 if (!ch || ch->magic != DGAP_CHANNEL_MAGIC)
3551 memset(&tmp, 0, sizeof(tmp));
3553 DGAP_LOCK(ch->ch_lock, lock_flags);
3554 tmp = readw(&(ch->ch_bs->edelay));
3555 DGAP_UNLOCK(ch->ch_lock, lock_flags);
3557 if (copy_to_user(retinfo, &tmp, sizeof(*retinfo)))
3564 * dgap_tty_digisetedelay()
3566 * Ioctl to set the EDELAY setting
3569 static int dgap_tty_digisetedelay(struct tty_struct *tty, int __user *new_info)
3572 struct channel_t *ch;
3578 if (!tty || tty->magic != TTY_MAGIC)
3581 un = tty->driver_data;
3582 if (!un || un->magic != DGAP_UNIT_MAGIC)
3586 if (!ch || ch->magic != DGAP_CHANNEL_MAGIC)
3590 if (!bd || bd->magic != DGAP_BOARD_MAGIC)
3593 if (copy_from_user(&new_digi, new_info, sizeof(int)))
3596 DGAP_LOCK(bd->bd_lock, lock_flags);
3597 DGAP_LOCK(ch->ch_lock, lock_flags2);
3599 writew((u16) new_digi, &(ch->ch_bs->edelay));
3603 DGAP_UNLOCK(ch->ch_lock, lock_flags2);
3604 DGAP_UNLOCK(bd->bd_lock, lock_flags);
3610 * dgap_tty_digigetcustombaud()
3612 * Ioctl to get the current custom baud rate setting.
3614 static int dgap_tty_digigetcustombaud(struct tty_struct *tty,
3615 int __user *retinfo)
3617 struct channel_t *ch;
3625 if (!tty || tty->magic != TTY_MAGIC)
3628 un = tty->driver_data;
3629 if (!un || un->magic != DGAP_UNIT_MAGIC)
3633 if (!ch || ch->magic != DGAP_CHANNEL_MAGIC)
3636 memset(&tmp, 0, sizeof(tmp));
3638 DGAP_LOCK(ch->ch_lock, lock_flags);
3639 tmp = dgap_get_custom_baud(ch);
3640 DGAP_UNLOCK(ch->ch_lock, lock_flags);
3642 if (copy_to_user(retinfo, &tmp, sizeof(*retinfo)))
3649 * dgap_tty_digisetcustombaud()
3651 * Ioctl to set the custom baud rate setting
3653 static int dgap_tty_digisetcustombaud(struct tty_struct *tty,
3654 int __user *new_info)
3657 struct channel_t *ch;
3663 if (!tty || tty->magic != TTY_MAGIC)
3666 un = tty->driver_data;
3667 if (!un || un->magic != DGAP_UNIT_MAGIC)
3671 if (!ch || ch->magic != DGAP_CHANNEL_MAGIC)
3675 if (!bd || bd->magic != DGAP_BOARD_MAGIC)
3679 if (copy_from_user(&new_rate, new_info, sizeof(unsigned int)))
3682 if (bd->bd_flags & BD_FEP5PLUS) {
3684 DGAP_LOCK(bd->bd_lock, lock_flags);
3685 DGAP_LOCK(ch->ch_lock, lock_flags2);
3687 ch->ch_custom_speed = new_rate;
3691 DGAP_UNLOCK(ch->ch_lock, lock_flags2);
3692 DGAP_UNLOCK(bd->bd_lock, lock_flags);
3699 * dgap_set_termios()
3701 static void dgap_tty_set_termios(struct tty_struct *tty,
3702 struct ktermios *old_termios)
3705 struct channel_t *ch;
3707 unsigned long lock_flags;
3708 unsigned long lock_flags2;
3710 if (!tty || tty->magic != TTY_MAGIC)
3713 un = tty->driver_data;
3714 if (!un || un->magic != DGAP_UNIT_MAGIC)
3718 if (!ch || ch->magic != DGAP_CHANNEL_MAGIC)
3722 if (!bd || bd->magic != DGAP_BOARD_MAGIC)
3725 DGAP_LOCK(bd->bd_lock, lock_flags);
3726 DGAP_LOCK(ch->ch_lock, lock_flags2);
3728 ch->ch_c_cflag = tty->termios.c_cflag;
3729 ch->ch_c_iflag = tty->termios.c_iflag;
3730 ch->ch_c_oflag = tty->termios.c_oflag;
3731 ch->ch_c_lflag = tty->termios.c_lflag;
3732 ch->ch_startc = tty->termios.c_cc[VSTART];
3733 ch->ch_stopc = tty->termios.c_cc[VSTOP];
3738 DGAP_UNLOCK(ch->ch_lock, lock_flags2);
3739 DGAP_UNLOCK(bd->bd_lock, lock_flags);
3742 static void dgap_tty_throttle(struct tty_struct *tty)
3745 struct channel_t *ch;
3750 if (!tty || tty->magic != TTY_MAGIC)
3753 un = tty->driver_data;
3754 if (!un || un->magic != DGAP_UNIT_MAGIC)
3758 if (!ch || ch->magic != DGAP_CHANNEL_MAGIC)
3762 if (!bd || bd->magic != DGAP_BOARD_MAGIC)
3765 DGAP_LOCK(bd->bd_lock, lock_flags);
3766 DGAP_LOCK(ch->ch_lock, lock_flags2);
3768 ch->ch_flags |= (CH_RXBLOCK);
3770 dgap_cmdw(ch, RPAUSE, 0, 0);
3773 DGAP_UNLOCK(ch->ch_lock, lock_flags2);
3774 DGAP_UNLOCK(bd->bd_lock, lock_flags);
3778 static void dgap_tty_unthrottle(struct tty_struct *tty)
3781 struct channel_t *ch;
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 DGAP_LOCK(bd->bd_lock, lock_flags);
3802 DGAP_LOCK(ch->ch_lock, lock_flags2);
3804 ch->ch_flags &= ~(CH_RXBLOCK);
3807 dgap_cmdw(ch, RRESUME, 0, 0);
3810 DGAP_UNLOCK(ch->ch_lock, lock_flags2);
3811 DGAP_UNLOCK(bd->bd_lock, lock_flags);
3814 static void dgap_tty_start(struct tty_struct *tty)
3817 struct channel_t *ch;
3822 if (!tty || tty->magic != TTY_MAGIC)
3825 un = tty->driver_data;
3826 if (!un || un->magic != DGAP_UNIT_MAGIC)
3830 if (!ch || ch->magic != DGAP_CHANNEL_MAGIC)
3834 if (!bd || bd->magic != DGAP_BOARD_MAGIC)
3837 DGAP_LOCK(bd->bd_lock, lock_flags);
3838 DGAP_LOCK(ch->ch_lock, lock_flags2);
3840 dgap_cmdw(ch, RESUMETX, 0, 0);
3842 DGAP_UNLOCK(ch->ch_lock, lock_flags2);
3843 DGAP_UNLOCK(bd->bd_lock, lock_flags);
3847 static void dgap_tty_stop(struct tty_struct *tty)
3850 struct channel_t *ch;
3855 if (!tty || tty->magic != TTY_MAGIC)
3858 un = tty->driver_data;
3859 if (!un || un->magic != DGAP_UNIT_MAGIC)
3863 if (!ch || ch->magic != DGAP_CHANNEL_MAGIC)
3867 if (!bd || bd->magic != DGAP_BOARD_MAGIC)
3870 DGAP_LOCK(bd->bd_lock, lock_flags);
3871 DGAP_LOCK(ch->ch_lock, lock_flags2);
3873 dgap_cmdw(ch, PAUSETX, 0, 0);
3875 DGAP_UNLOCK(ch->ch_lock, lock_flags2);
3876 DGAP_UNLOCK(bd->bd_lock, lock_flags);
3881 * dgap_tty_flush_chars()
3883 * Flush the cook buffer
3885 * Note to self, and any other poor souls who venture here:
3887 * flush in this case DOES NOT mean dispose of the data.
3888 * instead, it means "stop buffering and send it if you
3889 * haven't already." Just guess how I figured that out... SRW 2-Jun-98
3891 * It is also always called in interrupt context - JAR 8-Sept-99
3893 static void dgap_tty_flush_chars(struct tty_struct *tty)
3896 struct channel_t *ch;
3901 if (!tty || tty->magic != TTY_MAGIC)
3904 un = tty->driver_data;
3905 if (!un || un->magic != DGAP_UNIT_MAGIC)
3909 if (!ch || ch->magic != DGAP_CHANNEL_MAGIC)
3913 if (!bd || bd->magic != DGAP_BOARD_MAGIC)
3916 DGAP_LOCK(bd->bd_lock, lock_flags);
3917 DGAP_LOCK(ch->ch_lock, lock_flags2);
3919 /* TODO: Do something here */
3921 DGAP_UNLOCK(ch->ch_lock, lock_flags2);
3922 DGAP_UNLOCK(bd->bd_lock, lock_flags);
3926 * dgap_tty_flush_buffer()
3928 * Flush Tx buffer (make in == out)
3930 static void dgap_tty_flush_buffer(struct tty_struct *tty)
3933 struct channel_t *ch;
3939 if (!tty || tty->magic != TTY_MAGIC)
3942 un = tty->driver_data;
3943 if (!un || un->magic != DGAP_UNIT_MAGIC)
3947 if (!ch || ch->magic != DGAP_CHANNEL_MAGIC)
3951 if (!bd || bd->magic != DGAP_BOARD_MAGIC)
3954 DGAP_LOCK(bd->bd_lock, lock_flags);
3955 DGAP_LOCK(ch->ch_lock, lock_flags2);
3957 ch->ch_flags &= ~CH_STOP;
3958 head = readw(&(ch->ch_bs->tx_head));
3959 dgap_cmdw(ch, FLUSHTX, (u16) head, 0);
3960 dgap_cmdw(ch, RESUMETX, 0, 0);
3961 if (ch->ch_tun.un_flags & (UN_LOW|UN_EMPTY)) {
3962 ch->ch_tun.un_flags &= ~(UN_LOW|UN_EMPTY);
3963 wake_up_interruptible(&ch->ch_tun.un_flags_wait);
3965 if (ch->ch_pun.un_flags & (UN_LOW|UN_EMPTY)) {
3966 ch->ch_pun.un_flags &= ~(UN_LOW|UN_EMPTY);
3967 wake_up_interruptible(&ch->ch_pun.un_flags_wait);
3970 DGAP_UNLOCK(ch->ch_lock, lock_flags2);
3971 DGAP_UNLOCK(bd->bd_lock, lock_flags);
3972 if (waitqueue_active(&tty->write_wait))
3973 wake_up_interruptible(&tty->write_wait);
3977 /*****************************************************************************
3979 * The IOCTL function and all of its helpers
3981 *****************************************************************************/
3986 * The usual assortment of ioctl's
3988 static int dgap_tty_ioctl(struct tty_struct *tty, unsigned int cmd,
3992 struct channel_t *ch;
3996 ulong lock_flags = 0;
3997 ulong lock_flags2 = 0;
3998 void __user *uarg = (void __user *) arg;
4000 if (!tty || tty->magic != TTY_MAGIC)
4003 un = tty->driver_data;
4004 if (!un || un->magic != DGAP_UNIT_MAGIC)
4008 if (!ch || ch->magic != DGAP_CHANNEL_MAGIC)
4012 if (!bd || bd->magic != DGAP_BOARD_MAGIC)
4015 DGAP_LOCK(bd->bd_lock, lock_flags);
4016 DGAP_LOCK(ch->ch_lock, lock_flags2);
4018 if (un->un_open_count <= 0) {
4019 DGAP_UNLOCK(ch->ch_lock, lock_flags2);
4020 DGAP_UNLOCK(bd->bd_lock, lock_flags);
4026 /* Here are all the standard ioctl's that we MUST implement */
4030 * TCSBRK is SVID version: non-zero arg --> no break
4031 * this behaviour is exploited by tcdrain().
4033 * According to POSIX.1 spec (7.2.2.1.2) breaks should be
4034 * between 0.25 and 0.5 seconds so we'll ask for something
4035 * in the middle: 0.375 seconds.
4037 rc = tty_check_change(tty);
4038 DGAP_UNLOCK(ch->ch_lock, lock_flags2);
4039 DGAP_UNLOCK(bd->bd_lock, lock_flags);
4043 rc = dgap_wait_for_drain(tty);
4048 DGAP_LOCK(bd->bd_lock, lock_flags);
4049 DGAP_LOCK(ch->ch_lock, lock_flags2);
4051 if (((cmd == TCSBRK) && (!arg)) || (cmd == TCSBRKP))
4052 dgap_cmdw(ch, SBREAK, (u16) SBREAK_TIME, 0);
4054 DGAP_UNLOCK(ch->ch_lock, lock_flags2);
4055 DGAP_UNLOCK(bd->bd_lock, lock_flags);
4060 /* support for POSIX tcsendbreak()
4062 * According to POSIX.1 spec (7.2.2.1.2) breaks should be
4063 * between 0.25 and 0.5 seconds so we'll ask for something
4064 * in the middle: 0.375 seconds.
4066 rc = tty_check_change(tty);
4067 DGAP_UNLOCK(ch->ch_lock, lock_flags2);
4068 DGAP_UNLOCK(bd->bd_lock, lock_flags);
4072 rc = dgap_wait_for_drain(tty);
4076 DGAP_LOCK(bd->bd_lock, lock_flags);
4077 DGAP_LOCK(ch->ch_lock, lock_flags2);
4079 dgap_cmdw(ch, SBREAK, (u16) SBREAK_TIME, 0);
4081 DGAP_UNLOCK(ch->ch_lock, lock_flags2);
4082 DGAP_UNLOCK(bd->bd_lock, lock_flags);
4088 * FEP5 doesn't support turning on a break unconditionally.
4089 * The FEP5 device will stop sending a break automatically
4090 * after the specified time value that was sent when turning on
4093 rc = tty_check_change(tty);
4094 DGAP_UNLOCK(ch->ch_lock, lock_flags2);
4095 DGAP_UNLOCK(bd->bd_lock, lock_flags);
4099 rc = dgap_wait_for_drain(tty);
4103 DGAP_LOCK(bd->bd_lock, lock_flags);
4104 DGAP_LOCK(ch->ch_lock, lock_flags2);
4106 dgap_cmdw(ch, SBREAK, (u16) SBREAK_TIME, 0);
4108 DGAP_UNLOCK(ch->ch_lock, lock_flags2);
4109 DGAP_UNLOCK(bd->bd_lock, lock_flags);
4115 * FEP5 doesn't support turning off a break unconditionally.
4116 * The FEP5 device will stop sending a break automatically
4117 * after the specified time value that was sent when turning on
4120 DGAP_UNLOCK(ch->ch_lock, lock_flags2);
4121 DGAP_UNLOCK(bd->bd_lock, lock_flags);
4126 DGAP_UNLOCK(ch->ch_lock, lock_flags2);
4127 DGAP_UNLOCK(bd->bd_lock, lock_flags);
4129 rc = put_user(C_CLOCAL(tty) ? 1 : 0,
4130 (unsigned long __user *) arg);
4134 DGAP_UNLOCK(ch->ch_lock, lock_flags2);
4135 DGAP_UNLOCK(bd->bd_lock, lock_flags);
4137 rc = get_user(arg, (unsigned long __user *) arg);
4141 DGAP_LOCK(bd->bd_lock, lock_flags);
4142 DGAP_LOCK(ch->ch_lock, lock_flags2);
4143 tty->termios.c_cflag = ((tty->termios.c_cflag & ~CLOCAL) |
4144 (arg ? CLOCAL : 0));
4146 DGAP_UNLOCK(ch->ch_lock, lock_flags2);
4147 DGAP_UNLOCK(bd->bd_lock, lock_flags);
4152 DGAP_UNLOCK(ch->ch_lock, lock_flags2);
4153 DGAP_UNLOCK(bd->bd_lock, lock_flags);
4154 return dgap_get_modem_info(ch, uarg);
4159 DGAP_UNLOCK(ch->ch_lock, lock_flags2);
4160 DGAP_UNLOCK(bd->bd_lock, lock_flags);
4161 return dgap_set_modem_info(tty, cmd, uarg);
4164 * Here are any additional ioctl's that we want to implement
4169 * The linux tty driver doesn't have a flush
4170 * input routine for the driver, assuming all backed
4171 * up data is in the line disc. buffers. However,
4172 * we all know that's not the case. Here, we
4173 * act on the ioctl, but then lie and say we didn't
4174 * so the line discipline will process the flush
4177 rc = tty_check_change(tty);
4179 DGAP_UNLOCK(ch->ch_lock, lock_flags2);
4180 DGAP_UNLOCK(bd->bd_lock, lock_flags);
4184 if ((arg == TCIFLUSH) || (arg == TCIOFLUSH)) {
4185 if (!(un->un_type == DGAP_PRINT)) {
4186 head = readw(&(ch->ch_bs->rx_head));
4187 writew(head, &(ch->ch_bs->rx_tail));
4188 writeb(0, &(ch->ch_bs->orun));
4192 if ((arg == TCOFLUSH) || (arg == TCIOFLUSH)) {
4193 ch->ch_flags &= ~CH_STOP;
4194 head = readw(&(ch->ch_bs->tx_head));
4195 dgap_cmdw(ch, FLUSHTX, (u16) head, 0);
4196 dgap_cmdw(ch, RESUMETX, 0, 0);
4197 if (ch->ch_tun.un_flags & (UN_LOW|UN_EMPTY)) {
4198 ch->ch_tun.un_flags &= ~(UN_LOW|UN_EMPTY);
4199 wake_up_interruptible(&ch->ch_tun.un_flags_wait);
4201 if (ch->ch_pun.un_flags & (UN_LOW|UN_EMPTY)) {
4202 ch->ch_pun.un_flags &= ~(UN_LOW|UN_EMPTY);
4203 wake_up_interruptible(&ch->ch_pun.un_flags_wait);
4205 if (waitqueue_active(&tty->write_wait))
4206 wake_up_interruptible(&tty->write_wait);
4208 /* Can't hold any locks when calling tty_wakeup! */
4209 DGAP_UNLOCK(ch->ch_lock, lock_flags2);
4210 DGAP_UNLOCK(bd->bd_lock, lock_flags);
4212 DGAP_LOCK(bd->bd_lock, lock_flags);
4213 DGAP_LOCK(ch->ch_lock, lock_flags2);
4216 /* pretend we didn't recognize this IOCTL */
4217 DGAP_UNLOCK(ch->ch_lock, lock_flags2);
4218 DGAP_UNLOCK(bd->bd_lock, lock_flags);
4220 return -ENOIOCTLCMD;
4225 * The linux tty driver doesn't have a flush
4226 * input routine for the driver, assuming all backed
4227 * up data is in the line disc. buffers. However,
4228 * we all know that's not the case. Here, we
4229 * act on the ioctl, but then lie and say we didn't
4230 * so the line discipline will process the flush
4233 if (cmd == TCSETSF) {
4235 ch->ch_flags &= ~CH_STOP;
4236 head = readw(&(ch->ch_bs->rx_head));
4237 writew(head, &(ch->ch_bs->rx_tail));
4240 /* now wait for all the output to drain */
4241 DGAP_UNLOCK(ch->ch_lock, lock_flags2);
4242 DGAP_UNLOCK(bd->bd_lock, lock_flags);
4243 rc = dgap_wait_for_drain(tty);
4247 /* pretend we didn't recognize this */
4248 return -ENOIOCTLCMD;
4252 DGAP_UNLOCK(ch->ch_lock, lock_flags2);
4253 DGAP_UNLOCK(bd->bd_lock, lock_flags);
4254 rc = dgap_wait_for_drain(tty);
4258 /* pretend we didn't recognize this */
4259 return -ENOIOCTLCMD;
4263 * The Linux Line Discipline (LD) would do this for us if we
4264 * let it, but we have the special firmware options to do this
4265 * the "right way" regardless of hardware or software flow
4266 * control so we'll do it outselves instead of letting the LD
4269 rc = tty_check_change(tty);
4271 DGAP_UNLOCK(ch->ch_lock, lock_flags2);
4272 DGAP_UNLOCK(bd->bd_lock, lock_flags);
4279 DGAP_UNLOCK(ch->ch_lock, lock_flags2);
4280 DGAP_UNLOCK(bd->bd_lock, lock_flags);
4281 dgap_tty_start(tty);
4284 DGAP_UNLOCK(ch->ch_lock, lock_flags2);
4285 DGAP_UNLOCK(bd->bd_lock, lock_flags);
4289 DGAP_UNLOCK(ch->ch_lock, lock_flags2);
4290 DGAP_UNLOCK(bd->bd_lock, lock_flags);
4291 /* Make the ld do it */
4292 return -ENOIOCTLCMD;
4294 DGAP_UNLOCK(ch->ch_lock, lock_flags2);
4295 DGAP_UNLOCK(bd->bd_lock, lock_flags);
4296 /* Make the ld do it */
4297 return -ENOIOCTLCMD;
4299 DGAP_UNLOCK(ch->ch_lock, lock_flags2);
4300 DGAP_UNLOCK(bd->bd_lock, lock_flags);
4305 /* get information for ditty */
4306 DGAP_UNLOCK(ch->ch_lock, lock_flags2);
4307 DGAP_UNLOCK(bd->bd_lock, lock_flags);
4308 return dgap_tty_digigeta(tty, uarg);
4313 /* set information for ditty */
4314 if (cmd == (DIGI_SETAW)) {
4316 DGAP_UNLOCK(ch->ch_lock, lock_flags2);
4317 DGAP_UNLOCK(bd->bd_lock, lock_flags);
4318 rc = dgap_wait_for_drain(tty);
4321 DGAP_LOCK(bd->bd_lock, lock_flags);
4322 DGAP_LOCK(ch->ch_lock, lock_flags2);
4324 tty_ldisc_flush(tty);
4328 DGAP_UNLOCK(ch->ch_lock, lock_flags2);
4329 DGAP_UNLOCK(bd->bd_lock, lock_flags);
4330 return dgap_tty_digiseta(tty, uarg);
4333 DGAP_UNLOCK(ch->ch_lock, lock_flags2);
4334 DGAP_UNLOCK(bd->bd_lock, lock_flags);
4335 return dgap_tty_digigetedelay(tty, uarg);
4338 DGAP_UNLOCK(ch->ch_lock, lock_flags2);
4339 DGAP_UNLOCK(bd->bd_lock, lock_flags);
4340 return dgap_tty_digisetedelay(tty, uarg);
4342 case DIGI_GETCUSTOMBAUD:
4343 DGAP_UNLOCK(ch->ch_lock, lock_flags2);
4344 DGAP_UNLOCK(bd->bd_lock, lock_flags);
4345 return dgap_tty_digigetcustombaud(tty, uarg);
4347 case DIGI_SETCUSTOMBAUD:
4348 DGAP_UNLOCK(ch->ch_lock, lock_flags2);
4349 DGAP_UNLOCK(bd->bd_lock, lock_flags);
4350 return dgap_tty_digisetcustombaud(tty, uarg);
4352 case DIGI_RESET_PORT:
4353 dgap_firmware_reset_port(ch);
4355 DGAP_UNLOCK(ch->ch_lock, lock_flags2);
4356 DGAP_UNLOCK(bd->bd_lock, lock_flags);
4360 DGAP_UNLOCK(ch->ch_lock, lock_flags2);
4361 DGAP_UNLOCK(bd->bd_lock, lock_flags);
4363 return -ENOIOCTLCMD;
4367 static int dgap_after_config_loaded(int board)
4370 * Initialize KME waitqueues...
4372 init_waitqueue_head(&(dgap_Board[board]->kme_wait));
4375 * allocate flip buffer for board.
4377 dgap_Board[board]->flipbuf = kmalloc(MYFLIPLEN, GFP_ATOMIC);
4378 if (!dgap_Board[board]->flipbuf)
4381 dgap_Board[board]->flipflagbuf = kmalloc(MYFLIPLEN, GFP_ATOMIC);
4382 if (!dgap_Board[board]->flipflagbuf) {
4383 kfree(dgap_Board[board]->flipbuf);
4391 * Create pr and tty device entries
4393 static int dgap_tty_register_ports(struct board_t *brd)
4395 struct channel_t *ch;
4398 brd->SerialPorts = kcalloc(brd->nasync, sizeof(*brd->SerialPorts),
4400 if (brd->SerialPorts == NULL)
4402 for (i = 0; i < brd->nasync; i++)
4403 tty_port_init(&brd->SerialPorts[i]);
4405 brd->PrinterPorts = kcalloc(brd->nasync, sizeof(*brd->PrinterPorts),
4407 if (brd->PrinterPorts == NULL) {
4408 kfree(brd->SerialPorts);
4411 for (i = 0; i < brd->nasync; i++)
4412 tty_port_init(&brd->PrinterPorts[i]);
4414 ch = brd->channels[0];
4415 for (i = 0; i < brd->nasync; i++, ch = brd->channels[i]) {
4417 struct device *classp;
4419 classp = tty_port_register_device(&brd->SerialPorts[i],
4421 brd->firstminor + i, NULL);
4423 dgap_create_tty_sysfs(&ch->ch_tun, classp);
4424 ch->ch_tun.un_sysfs = classp;
4426 classp = tty_port_register_device(&brd->PrinterPorts[i],
4428 brd->firstminor + i, NULL);
4430 dgap_create_tty_sysfs(&ch->ch_pun, classp);
4431 ch->ch_pun.un_sysfs = classp;
4433 dgap_create_ports_sysfiles(brd);
4439 * Copies the BIOS code from the user to the board,
4440 * and starts the BIOS running.
4442 static void dgap_do_bios_load(struct board_t *brd, uchar __user *ubios, int len)
4448 if (!brd || (brd->magic != DGAP_BOARD_MAGIC) || !brd->re_map_membase)
4451 addr = brd->re_map_membase;
4456 for (i = 0; i < 16; i++)
4457 writeb(0, addr + POSTAREA + i);
4463 memcpy_toio(addr + offset, ubios, len);
4465 writel(0x0bf00401, addr);
4466 writel(0, (addr + 4));
4468 /* Clear the reset, and change states. */
4469 writeb(FEPCLR, brd->re_map_port);
4473 * Checks to see if the BIOS completed running on the card.
4475 static void dgap_do_wait_for_bios(struct board_t *brd)
4482 if (!brd || (brd->magic != DGAP_BOARD_MAGIC) || !brd->re_map_membase)
4485 addr = brd->re_map_membase;
4486 word = readw(addr + POSTAREA);
4489 * It can take 5-6 seconds for a board to
4490 * pass the bios self test and post results.
4491 * Give it 10 seconds.
4493 brd->wait_for_bios = 0;
4494 while (brd->wait_for_bios < 1000) {
4495 /* Check to see if BIOS thinks board is good. (GD). */
4496 if (word == *(u16 *) "GD") {
4497 brd->state = FINISHED_BIOS_LOAD;
4500 msleep_interruptible(10);
4501 brd->wait_for_bios++;
4502 word = readw(addr + POSTAREA);
4505 /* Gave up on board after too long of time taken */
4506 err1 = readw(addr + SEQUENCE);
4507 err2 = readw(addr + ERROR);
4508 pr_warn("dgap: %s failed diagnostics. Error #(%x,%x).\n",
4509 brd->name, err1, err2);
4510 brd->state = BOARD_FAILED;
4511 brd->dpastatus = BD_NOBIOS;
4515 * Copies the FEP code from the user to the board,
4516 * and starts the FEP running.
4518 static void dgap_do_fep_load(struct board_t *brd, uchar *ufep, int len)
4523 if (!brd || (brd->magic != DGAP_BOARD_MAGIC) || !brd->re_map_membase)
4526 addr = brd->re_map_membase;
4532 memcpy_toio(addr + offset, ufep, len);
4535 * If board is a concentrator product, we need to give
4536 * it its config string describing how the concentrators look.
4538 if ((brd->type == PCX) || (brd->type == PEPC)) {
4540 uchar *config, *xconfig;
4543 xconfig = dgap_create_config_string(brd, string);
4545 /* Write string to board memory */
4546 config = addr + CONFIG;
4547 for (; i < CONFIGSIZE; i++, config++, xconfig++) {
4548 writeb(*xconfig, config);
4549 if ((*xconfig & 0xff) == 0xff)
4554 writel(0xbfc01004, (addr + 0xc34));
4555 writel(0x3, (addr + 0xc30));
4560 * Waits for the FEP to report thats its ready for us to use.
4562 static void dgap_do_wait_for_fep(struct board_t *brd)
4569 if (!brd || (brd->magic != DGAP_BOARD_MAGIC) || !brd->re_map_membase)
4572 addr = brd->re_map_membase;
4573 word = readw(addr + FEPSTAT);
4576 * It can take 2-3 seconds for the FEP to
4577 * be up and running. Give it 5 secs.
4579 brd->wait_for_fep = 0;
4580 while (brd->wait_for_fep < 500) {
4581 /* Check to see if FEP is up and running now. */
4582 if (word == *(u16 *) "OS") {
4583 brd->state = FINISHED_FEP_LOAD;
4585 * Check to see if the board can support FEP5+ commands.
4587 word = readw(addr + FEP5_PLUS);
4588 if (word == *(u16 *) "5A")
4589 brd->bd_flags |= BD_FEP5PLUS;
4593 msleep_interruptible(10);
4594 brd->wait_for_fep++;
4595 word = readw(addr + FEPSTAT);
4598 /* Gave up on board after too long of time taken */
4599 err1 = readw(addr + SEQUENCE);
4600 err2 = readw(addr + ERROR);
4601 pr_warn("dgap: FEPOS for %s not functioning. Error #(%x,%x).\n",
4602 brd->name, err1, err2);
4603 brd->state = BOARD_FAILED;
4604 brd->dpastatus = BD_NOFEP;
4608 * Physically forces the FEP5 card to reset itself.
4610 static void dgap_do_reset_board(struct board_t *brd)
4617 if (!brd || (brd->magic != DGAP_BOARD_MAGIC) ||
4618 !brd->re_map_membase || !brd->re_map_port)
4621 /* FEPRST does not vary among supported boards */
4622 writeb(FEPRST, brd->re_map_port);
4624 for (i = 0; i <= 1000; i++) {
4625 check = readb(brd->re_map_port) & 0xe;
4626 if (check == FEPRST)
4632 pr_warn("dgap: Board not resetting... Failing board.\n");
4633 brd->state = BOARD_FAILED;
4634 brd->dpastatus = BD_NOFEP;
4639 * Make sure there really is memory out there.
4641 writel(0xa55a3cc3, (brd->re_map_membase + LOWMEM));
4642 writel(0x5aa5c33c, (brd->re_map_membase + HIGHMEM));
4643 check1 = readl(brd->re_map_membase + LOWMEM);
4644 check2 = readl(brd->re_map_membase + HIGHMEM);
4646 if ((check1 != 0xa55a3cc3) || (check2 != 0x5aa5c33c)) {
4647 pr_warn("dgap: No memory at %p for board.\n",
4648 brd->re_map_membase);
4649 brd->state = BOARD_FAILED;
4650 brd->dpastatus = BD_NOFEP;
4654 if (brd->state != BOARD_FAILED)
4655 brd->state = FINISHED_RESET;
4658 #ifdef DIGI_CONCENTRATORS_SUPPORTED
4660 * Sends a concentrator image into the FEP5 board.
4662 static void dgap_do_conc_load(struct board_t *brd, uchar *uaddr, int len)
4666 struct downld_t *to_dp;
4668 if (!brd || (brd->magic != DGAP_BOARD_MAGIC) || !brd->re_map_membase)
4671 vaddr = brd->re_map_membase;
4673 offset = readw((u16 *) (vaddr + DOWNREQ));
4674 to_dp = (struct downld_t *) (vaddr + (int) offset);
4675 memcpy_toio(to_dp, uaddr, len);
4677 /* Tell card we have data for it */
4678 writew(0, vaddr + (DOWNREQ));
4680 brd->conc_dl_status = NO_PENDING_CONCENTRATOR_REQUESTS;
4684 #define EXPANSION_ROM_SIZE (64 * 1024)
4685 #define FEP5_ROM_MAGIC (0xFEFFFFFF)
4687 static void dgap_get_vpd(struct board_t *brd)
4699 * Poke the magic number at the PCI Rom Address location.
4700 * If VPD is supported, the value read from that address
4703 magic = FEP5_ROM_MAGIC;
4704 pci_write_config_dword(brd->pdev, PCI_ROM_ADDRESS, magic);
4705 pci_read_config_dword(brd->pdev, PCI_ROM_ADDRESS, &magic);
4707 /* VPD not supported, bail */
4712 * To get to the OTPROM memory, we have to send the boards base
4713 * address or'ed with 1 into the PCI Rom Address location.
4715 magic = brd->membase | 0x01;
4716 pci_write_config_dword(brd->pdev, PCI_ROM_ADDRESS, magic);
4717 pci_read_config_dword(brd->pdev, PCI_ROM_ADDRESS, &magic);
4719 byte1 = readb(brd->re_map_membase);
4720 byte2 = readb(brd->re_map_membase + 1);
4723 * If the board correctly swapped to the OTPROM memory,
4724 * the first 2 bytes (header) should be 0x55, 0xAA
4726 if (byte1 == 0x55 && byte2 == 0xAA) {
4731 * We have to run through all the OTPROM memory looking
4732 * for the VPD offset.
4734 while (base_offset <= EXPANSION_ROM_SIZE) {
4737 * Lots of magic numbers here.
4739 * The VPD offset is located inside the ROM Data
4742 * We also have to remember the length of each
4743 * ROM Data Structure, so we can "hop" to the next
4744 * entry if the VPD isn't in the current
4745 * ROM Data Structure.
4747 rom_offset = readw(brd->re_map_membase +
4748 base_offset + 0x18);
4749 image_length = readw(brd->re_map_membase +
4750 rom_offset + 0x10) * 512;
4751 vpd_offset = readw(brd->re_map_membase +
4754 /* Found the VPD entry */
4758 /* We didn't find a VPD entry, go to next ROM entry. */
4759 base_offset += image_length;
4761 byte1 = readb(brd->re_map_membase + base_offset);
4762 byte2 = readb(brd->re_map_membase + base_offset + 1);
4765 * If the new ROM offset doesn't have 0x55, 0xAA
4766 * as its header, we have run out of ROM.
4768 if (byte1 != 0x55 || byte2 != 0xAA)
4773 * If we have a VPD offset, then mark the board
4774 * as having a valid VPD, and copy VPDSIZE (512) bytes of
4775 * that VPD to the buffer we have in our board structure.
4778 brd->bd_flags |= BD_HAS_VPD;
4779 for (i = 0; i < VPDSIZE; i++) {
4780 brd->vpd[i] = readb(brd->re_map_membase +
4787 * We MUST poke the magic number at the PCI Rom Address location again.
4788 * This makes the card report the regular board memory back to us,
4789 * rather than the OTPROM memory.
4791 magic = FEP5_ROM_MAGIC;
4792 pci_write_config_dword(brd->pdev, PCI_ROM_ADDRESS, magic);
4796 * Our board poller function.
4798 static void dgap_poll_tasklet(unsigned long data)
4800 struct board_t *bd = (struct board_t *) data;
4806 if (!bd || (bd->magic != DGAP_BOARD_MAGIC))
4809 if (bd->inhibit_poller)
4812 DGAP_LOCK(bd->bd_lock, lock_flags);
4814 vaddr = bd->re_map_membase;
4817 * If board is ready, parse deeper to see if there is anything to do.
4819 if (bd->state == BOARD_READY) {
4821 struct ev_t *eaddr = NULL;
4823 if (!bd->re_map_membase) {
4824 DGAP_UNLOCK(bd->bd_lock, lock_flags);
4827 if (!bd->re_map_port) {
4828 DGAP_UNLOCK(bd->bd_lock, lock_flags);
4835 eaddr = (struct ev_t *) (vaddr + EVBUF);
4837 /* Get our head and tail */
4838 head = readw(&(eaddr->ev_head));
4839 tail = readw(&(eaddr->ev_tail));
4842 * If there is an event pending. Go service it.
4845 DGAP_UNLOCK(bd->bd_lock, lock_flags);
4847 DGAP_LOCK(bd->bd_lock, lock_flags);
4852 * If board is doing interrupts, ACK the interrupt.
4854 if (bd && bd->intr_running)
4855 readb(bd->re_map_port + 2);
4857 DGAP_UNLOCK(bd->bd_lock, lock_flags);
4861 /* Our state machine to get the board up and running */
4864 if (bd->state == NEED_RESET) {
4869 dgap_do_reset_board(bd);
4872 /* Move to next state */
4873 if (bd->state == FINISHED_RESET)
4874 bd->state = NEED_CONFIG;
4876 if (bd->state == NEED_CONFIG) {
4878 * Match this board to a config the user created for us.
4880 bd->bd_config = dgap_find_config(bd->type, bd->pci_bus,
4884 * Because the 4 port Xr products share the same PCI ID
4885 * as the 8 port Xr products, if we receive a NULL config
4886 * back, and this is a PAPORT8 board, retry with a
4887 * PAPORT4 attempt as well.
4889 if (bd->type == PAPORT8 && !bd->bd_config)
4890 bd->bd_config = dgap_find_config(PAPORT4, bd->pci_bus,
4894 * Register the ttys (if any) into the kernel.
4897 bd->state = FINISHED_CONFIG;
4899 bd->state = CONFIG_NOT_FOUND;
4902 /* Move to next state */
4903 if (bd->state == FINISHED_CONFIG)
4904 bd->state = NEED_DEVICE_CREATION;
4906 /* Move to next state */
4907 if (bd->state == NEED_DEVICE_CREATION) {
4909 * Signal downloader, its got some work to do.
4911 DGAP_LOCK(dgap_dl_lock, lock_flags2);
4912 if (dgap_dl_action != 1) {
4914 wake_up_interruptible(&dgap_dl_wait);
4916 DGAP_UNLOCK(dgap_dl_lock, lock_flags2);
4919 /* Move to next state */
4920 if (bd->state == FINISHED_DEVICE_CREATION)
4921 bd->state = NEED_BIOS_LOAD;
4923 /* Move to next state */
4924 if (bd->state == NEED_BIOS_LOAD) {
4926 * Signal downloader, its got some work to do.
4928 DGAP_LOCK(dgap_dl_lock, lock_flags2);
4929 if (dgap_dl_action != 1) {
4931 wake_up_interruptible(&dgap_dl_wait);
4933 DGAP_UNLOCK(dgap_dl_lock, lock_flags2);
4936 /* Wait for BIOS to test board... */
4937 if (bd->state == WAIT_BIOS_LOAD)
4938 dgap_do_wait_for_bios(bd);
4940 /* Move to next state */
4941 if (bd->state == FINISHED_BIOS_LOAD) {
4942 bd->state = NEED_FEP_LOAD;
4945 * Signal downloader, its got some work to do.
4947 DGAP_LOCK(dgap_dl_lock, lock_flags2);
4948 if (dgap_dl_action != 1) {
4950 wake_up_interruptible(&dgap_dl_wait);
4952 DGAP_UNLOCK(dgap_dl_lock, lock_flags2);
4955 /* Wait for FEP to load on board... */
4956 if (bd->state == WAIT_FEP_LOAD)
4957 dgap_do_wait_for_fep(bd);
4959 /* Move to next state */
4960 if (bd->state == FINISHED_FEP_LOAD) {
4963 * Do tty device initialization.
4965 int rc = dgap_tty_init(bd);
4968 dgap_tty_uninit(bd);
4969 bd->state = BOARD_FAILED;
4970 bd->dpastatus = BD_NOFEP;
4972 bd->state = NEED_PROC_CREATION;
4975 * Signal downloader, its got some work to do.
4977 DGAP_LOCK(dgap_dl_lock, lock_flags2);
4978 if (dgap_dl_action != 1) {
4980 wake_up_interruptible(&dgap_dl_wait);
4982 DGAP_UNLOCK(dgap_dl_lock, lock_flags2);
4986 /* Move to next state */
4987 if (bd->state == FINISHED_PROC_CREATION) {
4989 bd->state = BOARD_READY;
4990 bd->dpastatus = BD_RUNNING;
4993 * If user requested the board to run in interrupt mode,
4994 * go and set it up on the board.
4996 if (bd->intr_used) {
4997 writew(1, (bd->re_map_membase + ENABLE_INTR));
4999 * Tell the board to poll the UARTS as fast as possible.
5001 writew(FEPPOLL_MIN, (bd->re_map_membase + FEPPOLL));
5002 bd->intr_running = 1;
5005 /* Wake up anyone waiting for board state to change to ready */
5006 wake_up_interruptible(&bd->state_wait);
5009 DGAP_UNLOCK(bd->bd_lock, lock_flags);
5012 /*=======================================================================
5014 * dgap_cmdb - Sends a 2 byte command to the FEP.
5016 * ch - Pointer to channel structure.
5017 * cmd - Command to be sent.
5018 * byte1 - Integer containing first byte to be sent.
5019 * byte2 - Integer containing second byte to be sent.
5020 * ncmds - Wait until ncmds or fewer cmds are left
5021 * in the cmd buffer before returning.
5023 *=======================================================================*/
5024 static void dgap_cmdb(struct channel_t *ch, uchar cmd, uchar byte1,
5025 uchar byte2, uint ncmds)
5028 struct cm_t *cm_addr = NULL;
5034 if (!ch || ch->magic != DGAP_CHANNEL_MAGIC)
5038 * Check if board is still alive.
5040 if (ch->ch_bd->state == BOARD_FAILED)
5044 * Make sure the pointers are in range before
5045 * writing to the FEP memory.
5047 vaddr = ch->ch_bd->re_map_membase;
5052 cm_addr = (struct cm_t *) (vaddr + CMDBUF);
5053 head = readw(&(cm_addr->cm_head));
5056 * Forget it if pointers out of range.
5058 if (head >= (CMDMAX - CMDSTART) || (head & 03)) {
5059 ch->ch_bd->state = BOARD_FAILED;
5064 * Put the data in the circular command buffer.
5066 writeb(cmd, (char *) (vaddr + head + CMDSTART + 0));
5067 writeb((uchar) ch->ch_portnum, (char *) (vaddr + head + CMDSTART + 1));
5068 writeb(byte1, (char *) (vaddr + head + CMDSTART + 2));
5069 writeb(byte2, (char *) (vaddr + head + CMDSTART + 3));
5071 head = (head + 4) & (CMDMAX - CMDSTART - 4);
5073 writew(head, &(cm_addr->cm_head));
5076 * Wait if necessary before updating the head
5077 * pointer to limit the number of outstanding
5078 * commands to the FEP. If the time spent waiting
5079 * is outlandish, declare the FEP dead.
5081 for (count = dgap_count ;;) {
5083 head = readw(&(cm_addr->cm_head));
5084 tail = readw(&(cm_addr->cm_tail));
5086 n = (head - tail) & (CMDMAX - CMDSTART - 4);
5088 if (n <= ncmds * sizeof(struct cm_t))
5092 ch->ch_bd->state = BOARD_FAILED;
5099 /*=======================================================================
5101 * dgap_cmdw - Sends a 1 word command to the FEP.
5103 * ch - Pointer to channel structure.
5104 * cmd - Command to be sent.
5105 * word - Integer containing word to be sent.
5106 * ncmds - Wait until ncmds or fewer cmds are left
5107 * in the cmd buffer before returning.
5109 *=======================================================================*/
5110 static void dgap_cmdw(struct channel_t *ch, uchar cmd, u16 word, uint ncmds)
5113 struct cm_t *cm_addr = NULL;
5119 if (!ch || ch->magic != DGAP_CHANNEL_MAGIC)
5123 * Check if board is still alive.
5125 if (ch->ch_bd->state == BOARD_FAILED)
5129 * Make sure the pointers are in range before
5130 * writing to the FEP memory.
5132 vaddr = ch->ch_bd->re_map_membase;
5136 cm_addr = (struct cm_t *) (vaddr + CMDBUF);
5137 head = readw(&(cm_addr->cm_head));
5140 * Forget it if pointers out of range.
5142 if (head >= (CMDMAX - CMDSTART) || (head & 03)) {
5143 ch->ch_bd->state = BOARD_FAILED;
5148 * Put the data in the circular command buffer.
5150 writeb(cmd, (char *) (vaddr + head + CMDSTART + 0));
5151 writeb((uchar) ch->ch_portnum, (char *) (vaddr + head + CMDSTART + 1));
5152 writew((u16) word, (char *) (vaddr + head + CMDSTART + 2));
5154 head = (head + 4) & (CMDMAX - CMDSTART - 4);
5156 writew(head, &(cm_addr->cm_head));
5159 * Wait if necessary before updating the head
5160 * pointer to limit the number of outstanding
5161 * commands to the FEP. If the time spent waiting
5162 * is outlandish, declare the FEP dead.
5164 for (count = dgap_count ;;) {
5166 head = readw(&(cm_addr->cm_head));
5167 tail = readw(&(cm_addr->cm_tail));
5169 n = (head - tail) & (CMDMAX - CMDSTART - 4);
5171 if (n <= ncmds * sizeof(struct cm_t))
5175 ch->ch_bd->state = BOARD_FAILED;
5182 /*=======================================================================
5184 * dgap_cmdw_ext - Sends a extended word command to the FEP.
5186 * ch - Pointer to channel structure.
5187 * cmd - Command to be sent.
5188 * word - Integer containing word to be sent.
5189 * ncmds - Wait until ncmds or fewer cmds are left
5190 * in the cmd buffer before returning.
5192 *=======================================================================*/
5193 static void dgap_cmdw_ext(struct channel_t *ch, u16 cmd, u16 word, uint ncmds)
5196 struct cm_t *cm_addr = NULL;
5202 if (!ch || ch->magic != DGAP_CHANNEL_MAGIC)
5206 * Check if board is still alive.
5208 if (ch->ch_bd->state == BOARD_FAILED)
5212 * Make sure the pointers are in range before
5213 * writing to the FEP memory.
5215 vaddr = ch->ch_bd->re_map_membase;
5219 cm_addr = (struct cm_t *) (vaddr + CMDBUF);
5220 head = readw(&(cm_addr->cm_head));
5223 * Forget it if pointers out of range.
5225 if (head >= (CMDMAX - CMDSTART) || (head & 03)) {
5226 ch->ch_bd->state = BOARD_FAILED;
5231 * Put the data in the circular command buffer.
5234 /* Write an FF to tell the FEP that we want an extended command */
5235 writeb((uchar) 0xff, (char *) (vaddr + head + CMDSTART + 0));
5237 writeb((uchar) ch->ch_portnum, (uchar *) (vaddr + head + CMDSTART + 1));
5238 writew((u16) cmd, (char *) (vaddr + head + CMDSTART + 2));
5241 * If the second part of the command won't fit,
5242 * put it at the beginning of the circular buffer.
5244 if (((head + 4) >= ((CMDMAX - CMDSTART)) || (head & 03)))
5245 writew((u16) word, (char *) (vaddr + CMDSTART));
5247 writew((u16) word, (char *) (vaddr + head + CMDSTART + 4));
5249 head = (head + 8) & (CMDMAX - CMDSTART - 4);
5251 writew(head, &(cm_addr->cm_head));
5254 * Wait if necessary before updating the head
5255 * pointer to limit the number of outstanding
5256 * commands to the FEP. If the time spent waiting
5257 * is outlandish, declare the FEP dead.
5259 for (count = dgap_count ;;) {
5261 head = readw(&(cm_addr->cm_head));
5262 tail = readw(&(cm_addr->cm_tail));
5264 n = (head - tail) & (CMDMAX - CMDSTART - 4);
5266 if (n <= ncmds * sizeof(struct cm_t))
5270 ch->ch_bd->state = BOARD_FAILED;
5277 /*=======================================================================
5279 * dgap_wmove - Write data to FEP buffer.
5281 * ch - Pointer to channel structure.
5282 * buf - Poiter to characters to be moved.
5283 * cnt - Number of characters to move.
5285 *=======================================================================*/
5286 static void dgap_wmove(struct channel_t *ch, char *buf, uint cnt)
5293 if (!ch || ch->magic != DGAP_CHANNEL_MAGIC)
5300 head = readw(&(bs->tx_head));
5303 * If pointers are out of range, just return.
5305 if ((cnt > ch->ch_tsize) ||
5306 (unsigned)(head - ch->ch_tstart) >= ch->ch_tsize)
5310 * If the write wraps over the top of the circular buffer,
5311 * move the portion up to the wrap point, and reset the
5312 * pointers to the bottom.
5314 n = ch->ch_tstart + ch->ch_tsize - head;
5318 taddr = ch->ch_taddr + head;
5319 memcpy_toio(taddr, buf, n);
5320 head = ch->ch_tstart;
5325 * Move rest of data.
5327 taddr = ch->ch_taddr + head;
5329 memcpy_toio(taddr, buf, n);
5332 writew(head, &(bs->tx_head));
5336 * Retrives the current custom baud rate from FEP memory,
5337 * and returns it back to the user.
5338 * Returns 0 on error.
5340 static uint dgap_get_custom_baud(struct channel_t *ch)
5346 if (!ch || ch->magic != DGAP_CHANNEL_MAGIC)
5349 if (!ch->ch_bd || ch->ch_bd->magic != DGAP_BOARD_MAGIC)
5352 if (!(ch->ch_bd->bd_flags & BD_FEP5PLUS))
5355 vaddr = ch->ch_bd->re_map_membase;
5361 * Go get from fep mem, what the fep
5362 * believes the custom baud rate is.
5364 offset = ((((*(unsigned short *)(vaddr + ECS_SEG)) << 4) +
5365 (ch->ch_portnum * 0x28) + LINE_SPEED));
5367 value = readw(vaddr + offset);
5372 * Calls the firmware to reset this channel.
5374 static void dgap_firmware_reset_port(struct channel_t *ch)
5376 dgap_cmdb(ch, CHRESET, 0, 0, 0);
5379 * Now that the channel is reset, we need to make sure
5380 * all the current settings get reapplied to the port
5383 * So we will set the driver's cache of firmware
5384 * settings all to 0, and then call param.
5386 ch->ch_fepiflag = 0;
5387 ch->ch_fepcflag = 0;
5388 ch->ch_fepoflag = 0;
5389 ch->ch_fepstartc = 0;
5390 ch->ch_fepstopc = 0;
5391 ch->ch_fepastartc = 0;
5392 ch->ch_fepastopc = 0;
5397 /*=======================================================================
5399 * dgap_param - Set Digi parameters.
5401 * struct tty_struct * - TTY for port.
5403 *=======================================================================*/
5404 static int dgap_param(struct tty_struct *tty)
5406 struct ktermios *ts;
5408 struct channel_t *ch;
5417 if (!tty || tty->magic != TTY_MAGIC)
5420 un = (struct un_t *) tty->driver_data;
5421 if (!un || un->magic != DGAP_UNIT_MAGIC)
5425 if (!ch || ch->magic != DGAP_CHANNEL_MAGIC)
5429 if (!bd || bd->magic != DGAP_BOARD_MAGIC)
5439 * If baud rate is zero, flush queues, and set mval to drop DTR.
5441 if ((ch->ch_c_cflag & (CBAUD)) == 0) {
5444 head = readw(&(ch->ch_bs->rx_head));
5445 writew(head, &(ch->ch_bs->rx_tail));
5448 head = readw(&(ch->ch_bs->tx_head));
5449 writew(head, &(ch->ch_bs->tx_tail));
5451 ch->ch_flags |= (CH_BAUD0);
5453 /* Drop RTS and DTR */
5454 ch->ch_mval &= ~(D_RTS(ch)|D_DTR(ch));
5455 mval = D_DTR(ch) | D_RTS(ch);
5456 ch->ch_baud_info = 0;
5458 } else if (ch->ch_custom_speed && (bd->bd_flags & BD_FEP5PLUS)) {
5460 * Tell the fep to do the command
5463 dgap_cmdw_ext(ch, 0xff01, ch->ch_custom_speed, 0);
5466 * Now go get from fep mem, what the fep
5467 * believes the custom baud rate is.
5469 ch->ch_custom_speed = dgap_get_custom_baud(ch);
5470 ch->ch_baud_info = ch->ch_custom_speed;
5472 /* Handle transition from B0 */
5473 if (ch->ch_flags & CH_BAUD0) {
5474 ch->ch_flags &= ~(CH_BAUD0);
5475 ch->ch_mval |= (D_RTS(ch)|D_DTR(ch));
5477 mval = D_DTR(ch) | D_RTS(ch);
5481 * Set baud rate, character size, and parity.
5489 ulong bauds[4][16] = {
5493 600, 1200, 1800, 2400,
5494 4800, 9600, 19200, 38400 },
5495 { /* slowbaud & CBAUDEX */
5496 0, 57600, 115200, 230400,
5497 460800, 150, 200, 921600,
5498 600, 1200, 1800, 2400,
5499 4800, 9600, 19200, 38400 },
5501 0, 57600, 76800, 115200,
5502 14400, 57600, 230400, 76800,
5503 115200, 230400, 28800, 460800,
5504 921600, 9600, 19200, 38400 },
5505 { /* fastbaud & CBAUDEX */
5506 0, 57600, 115200, 230400,
5507 460800, 150, 200, 921600,
5508 600, 1200, 1800, 2400,
5509 4800, 9600, 19200, 38400 }
5513 * Only use the TXPrint baud rate if the
5514 * terminal unit is NOT open
5516 if (!(ch->ch_tun.un_flags & UN_ISOPEN) &&
5517 (un->un_type == DGAP_PRINT))
5518 baud = C_BAUD(ch->ch_pun.un_tty) & 0xff;
5520 baud = C_BAUD(ch->ch_tun.un_tty) & 0xff;
5522 if (ch->ch_c_cflag & CBAUDEX)
5525 if (ch->ch_digi.digi_flags & DIGI_FAST)
5530 if ((iindex >= 0) && (iindex < 4) &&
5531 (jindex >= 0) && (jindex < 16))
5532 baud = bauds[iindex][jindex];
5539 ch->ch_baud_info = baud;
5542 * CBAUD has bit position 0x1000 set these days to
5543 * indicate Linux baud rate remap.
5544 * We use a different bit assignment for high speed.
5545 * Clear this bit out while grabbing the parts of
5548 cflag = ch->ch_c_cflag & ((CBAUD ^ CBAUDEX) | PARODD | PARENB |
5552 * HUPCL bit is used by FEP to indicate fast baud
5553 * table is to be used.
5555 if ((ch->ch_digi.digi_flags & DIGI_FAST) ||
5556 (ch->ch_c_cflag & CBAUDEX))
5559 if ((ch->ch_c_cflag & CBAUDEX) &&
5560 !(ch->ch_digi.digi_flags & DIGI_FAST)) {
5562 * The below code is trying to guarantee that only
5563 * baud rates 115200, 230400, 460800, 921600 are
5564 * remapped. We use exclusive or because the various
5565 * baud rates share common bit positions and therefore
5566 * can't be tested for easily.
5568 tcflag_t tcflag = (ch->ch_c_cflag & CBAUD) | CBAUDEX;
5572 * Map high speed requests to index
5573 * into FEP's baud table
5603 cflag = (cflag & ~(CBAUD | CBAUDEX)) | baudpart;
5608 if (cflag != ch->ch_fepcflag) {
5609 ch->ch_fepcflag = (u16) (cflag & 0xffff);
5612 * Okay to have channel and board
5613 * locks held calling this
5615 dgap_cmdw(ch, SCFLAG, (u16) cflag, 0);
5618 /* Handle transition from B0 */
5619 if (ch->ch_flags & CH_BAUD0) {
5620 ch->ch_flags &= ~(CH_BAUD0);
5621 ch->ch_mval |= (D_RTS(ch)|D_DTR(ch));
5623 mval = D_DTR(ch) | D_RTS(ch);
5629 iflag = ch->ch_c_iflag & (IGNBRK | BRKINT | IGNPAR | PARMRK |
5630 INPCK | ISTRIP | IXON | IXANY | IXOFF);
5632 if ((ch->ch_startc == _POSIX_VDISABLE) ||
5633 (ch->ch_stopc == _POSIX_VDISABLE)) {
5634 iflag &= ~(IXON | IXOFF);
5635 ch->ch_c_iflag &= ~(IXON | IXOFF);
5639 * Only the IBM Xr card can switch between
5640 * 232 and 422 modes on the fly
5642 if (bd->device == PCI_DEV_XR_IBM_DID) {
5643 if (ch->ch_digi.digi_flags & DIGI_422)
5644 dgap_cmdb(ch, SCOMMODE, MODE_422, 0, 0);
5646 dgap_cmdb(ch, SCOMMODE, MODE_232, 0, 0);
5649 if (ch->ch_digi.digi_flags & DIGI_ALTPIN)
5652 if (iflag != ch->ch_fepiflag) {
5653 ch->ch_fepiflag = iflag;
5655 /* Okay to have channel and board locks held calling this */
5656 dgap_cmdw(ch, SIFLAG, (u16) ch->ch_fepiflag, 0);
5660 * Select hardware handshaking.
5664 if (ch->ch_c_cflag & CRTSCTS)
5665 hflow |= (D_RTS(ch) | D_CTS(ch));
5666 if (ch->ch_digi.digi_flags & RTSPACE)
5668 if (ch->ch_digi.digi_flags & DTRPACE)
5670 if (ch->ch_digi.digi_flags & CTSPACE)
5672 if (ch->ch_digi.digi_flags & DSRPACE)
5674 if (ch->ch_digi.digi_flags & DCDPACE)
5677 if (hflow != ch->ch_hflow) {
5678 ch->ch_hflow = hflow;
5680 /* Okay to have channel and board locks held calling this */
5681 dgap_cmdb(ch, SHFLOW, (uchar) hflow, 0xff, 0);
5686 * Set RTS and/or DTR Toggle if needed,
5687 * but only if product is FEP5+ based.
5689 if (bd->bd_flags & BD_FEP5PLUS) {
5691 if (ch->ch_digi.digi_flags & DIGI_RTS_TOGGLE)
5692 hflow2 |= (D_RTS(ch));
5693 if (ch->ch_digi.digi_flags & DIGI_DTR_TOGGLE)
5694 hflow2 |= (D_DTR(ch));
5696 dgap_cmdw_ext(ch, 0xff03, hflow2, 0);
5700 * Set modem control lines.
5703 mval ^= ch->ch_mforce & (mval ^ ch->ch_mval);
5705 if (ch->ch_mostat ^ mval) {
5706 ch->ch_mostat = mval;
5708 /* Okay to have channel and board locks held calling this */
5709 dgap_cmdb(ch, SMODEM, (uchar) mval, D_RTS(ch)|D_DTR(ch), 0);
5713 * Read modem signals, and then call carrier function.
5715 ch->ch_mistat = readb(&(bs->m_stat));
5719 * Set the start and stop characters.
5721 if (ch->ch_startc != ch->ch_fepstartc ||
5722 ch->ch_stopc != ch->ch_fepstopc) {
5723 ch->ch_fepstartc = ch->ch_startc;
5724 ch->ch_fepstopc = ch->ch_stopc;
5726 /* Okay to have channel and board locks held calling this */
5727 dgap_cmdb(ch, SFLOWC, ch->ch_fepstartc, ch->ch_fepstopc, 0);
5731 * Set the Auxiliary start and stop characters.
5733 if (ch->ch_astartc != ch->ch_fepastartc ||
5734 ch->ch_astopc != ch->ch_fepastopc) {
5735 ch->ch_fepastartc = ch->ch_astartc;
5736 ch->ch_fepastopc = ch->ch_astopc;
5738 /* Okay to have channel and board locks held calling this */
5739 dgap_cmdb(ch, SAFLOWC, ch->ch_fepastartc, ch->ch_fepastopc, 0);
5746 * dgap_parity_scan()
5748 * Convert the FEP5 way of reporting parity errors and breaks into
5749 * the Linux line discipline way.
5751 static void dgap_parity_scan(struct channel_t *ch, unsigned char *cbuf,
5752 unsigned char *fbuf, int *len)
5756 unsigned char *in, *cout, *fout;
5763 if (!ch || ch->magic != DGAP_CHANNEL_MAGIC)
5768 switch (ch->pscan_state) {
5770 /* reset to sanity and fall through */
5771 ch->pscan_state = 0;
5774 /* No FF seen yet */
5775 if (c == (unsigned char) '\377')
5776 /* delete this character from stream */
5777 ch->pscan_state = 1;
5780 *fout++ = TTY_NORMAL;
5787 if (c == (unsigned char) '\377') {
5788 /* doubled ff, transform to single ff */
5790 *fout++ = TTY_NORMAL;
5792 ch->pscan_state = 0;
5794 /* save value examination in next state */
5795 ch->pscan_savechar = c;
5796 ch->pscan_state = 2;
5801 /* third character of ff sequence */
5805 if (ch->pscan_savechar == 0x0) {
5809 *fout++ = TTY_BREAK;
5811 ch->ch_err_parity++;
5812 *fout++ = TTY_PARITY;
5817 ch->pscan_state = 0;
5823 /*=======================================================================
5825 * dgap_event - FEP to host event processing routine.
5827 * bd - Board of current event.
5829 *=======================================================================*/
5830 static int dgap_event(struct board_t *bd)
5832 struct channel_t *ch;
5837 uchar *vaddr = NULL;
5838 struct ev_t *eaddr = NULL;
5846 if (!bd || bd->magic != DGAP_BOARD_MAGIC)
5849 DGAP_LOCK(bd->bd_lock, lock_flags);
5851 vaddr = bd->re_map_membase;
5854 DGAP_UNLOCK(bd->bd_lock, lock_flags);
5858 eaddr = (struct ev_t *) (vaddr + EVBUF);
5860 /* Get our head and tail */
5861 head = readw(&(eaddr->ev_head));
5862 tail = readw(&(eaddr->ev_tail));
5865 * Forget it if pointers out of range.
5868 if (head >= EVMAX - EVSTART || tail >= EVMAX - EVSTART ||
5869 (head | tail) & 03) {
5870 /* Let go of board lock */
5871 DGAP_UNLOCK(bd->bd_lock, lock_flags);
5876 * Loop to process all the events in the buffer.
5878 while (tail != head) {
5881 * Get interrupt information.
5884 event = bd->re_map_membase + tail + EVSTART;
5892 * Make sure the interrupt is valid.
5894 if (port >= bd->nasync)
5897 if (!(reason & (IFMODEM | IFBREAK | IFTLW | IFTEM | IFDATA)))
5900 ch = bd->channels[port];
5902 if (!ch || ch->magic != DGAP_CHANNEL_MAGIC)
5906 * If we have made it here, the event was valid.
5907 * Lock down the channel.
5909 DGAP_LOCK(ch->ch_lock, lock_flags2);
5914 DGAP_UNLOCK(ch->ch_lock, lock_flags2);
5919 * Process received data.
5921 if (reason & IFDATA) {
5924 * ALL LOCKS *MUST* BE DROPPED BEFORE CALLING INPUT!
5925 * input could send some data to ld, which in turn
5926 * could do a callback to one of our other functions.
5928 DGAP_UNLOCK(ch->ch_lock, lock_flags2);
5929 DGAP_UNLOCK(bd->bd_lock, lock_flags);
5933 DGAP_LOCK(bd->bd_lock, lock_flags);
5934 DGAP_LOCK(ch->ch_lock, lock_flags2);
5936 if (ch->ch_flags & CH_RACTIVE)
5937 ch->ch_flags |= CH_RENABLE;
5939 writeb(1, &(bs->idata));
5941 if (ch->ch_flags & CH_RWAIT) {
5942 ch->ch_flags &= ~CH_RWAIT;
5944 wake_up_interruptible(&ch->ch_tun.un_flags_wait);
5949 * Process Modem change signals.
5951 if (reason & IFMODEM) {
5952 ch->ch_mistat = modem;
5959 if (reason & IFBREAK) {
5961 if (ch->ch_tun.un_tty) {
5962 /* A break has been indicated */
5964 tty_buffer_request_room(ch->ch_tun.un_tty->port, 1);
5965 tty_insert_flip_char(ch->ch_tun.un_tty->port, 0, TTY_BREAK);
5966 tty_flip_buffer_push(ch->ch_tun.un_tty->port);
5971 * Process Transmit low.
5973 if (reason & IFTLW) {
5975 if (ch->ch_tun.un_flags & UN_LOW) {
5976 ch->ch_tun.un_flags &= ~UN_LOW;
5978 if (ch->ch_tun.un_flags & UN_ISOPEN) {
5979 if ((ch->ch_tun.un_tty->flags &
5980 (1 << TTY_DO_WRITE_WAKEUP)) &&
5981 ch->ch_tun.un_tty->ldisc->ops->write_wakeup) {
5982 DGAP_UNLOCK(ch->ch_lock, lock_flags2);
5983 DGAP_UNLOCK(bd->bd_lock, lock_flags);
5984 (ch->ch_tun.un_tty->ldisc->ops->write_wakeup)(ch->ch_tun.un_tty);
5985 DGAP_LOCK(bd->bd_lock, lock_flags);
5986 DGAP_LOCK(ch->ch_lock, lock_flags2);
5988 wake_up_interruptible(&ch->ch_tun.un_tty->write_wait);
5989 wake_up_interruptible(&ch->ch_tun.un_flags_wait);
5993 if (ch->ch_pun.un_flags & UN_LOW) {
5994 ch->ch_pun.un_flags &= ~UN_LOW;
5995 if (ch->ch_pun.un_flags & UN_ISOPEN) {
5996 if ((ch->ch_pun.un_tty->flags &
5997 (1 << TTY_DO_WRITE_WAKEUP)) &&
5998 ch->ch_pun.un_tty->ldisc->ops->write_wakeup) {
5999 DGAP_UNLOCK(ch->ch_lock, lock_flags2);
6000 DGAP_UNLOCK(bd->bd_lock, lock_flags);
6001 (ch->ch_pun.un_tty->ldisc->ops->write_wakeup)(ch->ch_pun.un_tty);
6002 DGAP_LOCK(bd->bd_lock, lock_flags);
6003 DGAP_LOCK(ch->ch_lock, lock_flags2);
6005 wake_up_interruptible(&ch->ch_pun.un_tty->write_wait);
6006 wake_up_interruptible(&ch->ch_pun.un_flags_wait);
6010 if (ch->ch_flags & CH_WLOW) {
6011 ch->ch_flags &= ~CH_WLOW;
6012 wake_up_interruptible(&ch->ch_flags_wait);
6017 * Process Transmit empty.
6019 if (reason & IFTEM) {
6020 if (ch->ch_tun.un_flags & UN_EMPTY) {
6021 ch->ch_tun.un_flags &= ~UN_EMPTY;
6022 if (ch->ch_tun.un_flags & UN_ISOPEN) {
6023 if ((ch->ch_tun.un_tty->flags &
6024 (1 << TTY_DO_WRITE_WAKEUP)) &&
6025 ch->ch_tun.un_tty->ldisc->ops->write_wakeup) {
6026 DGAP_UNLOCK(ch->ch_lock, lock_flags2);
6027 DGAP_UNLOCK(bd->bd_lock, lock_flags);
6029 (ch->ch_tun.un_tty->ldisc->ops->write_wakeup)(ch->ch_tun.un_tty);
6030 DGAP_LOCK(bd->bd_lock, lock_flags);
6031 DGAP_LOCK(ch->ch_lock, lock_flags2);
6033 wake_up_interruptible(&ch->ch_tun.un_tty->write_wait);
6034 wake_up_interruptible(&ch->ch_tun.un_flags_wait);
6038 if (ch->ch_pun.un_flags & UN_EMPTY) {
6039 ch->ch_pun.un_flags &= ~UN_EMPTY;
6040 if (ch->ch_pun.un_flags & UN_ISOPEN) {
6041 if ((ch->ch_pun.un_tty->flags &
6042 (1 << TTY_DO_WRITE_WAKEUP)) &&
6043 ch->ch_pun.un_tty->ldisc->ops->write_wakeup) {
6044 DGAP_UNLOCK(ch->ch_lock, lock_flags2);
6045 DGAP_UNLOCK(bd->bd_lock, lock_flags);
6046 (ch->ch_pun.un_tty->ldisc->ops->write_wakeup)(ch->ch_pun.un_tty);
6047 DGAP_LOCK(bd->bd_lock, lock_flags);
6048 DGAP_LOCK(ch->ch_lock, lock_flags2);
6050 wake_up_interruptible(&ch->ch_pun.un_tty->write_wait);
6051 wake_up_interruptible(&ch->ch_pun.un_flags_wait);
6056 if (ch->ch_flags & CH_WEMPTY) {
6057 ch->ch_flags &= ~CH_WEMPTY;
6058 wake_up_interruptible(&ch->ch_flags_wait);
6062 DGAP_UNLOCK(ch->ch_lock, lock_flags2);
6065 tail = (tail + 4) & (EVMAX - EVSTART - 4);
6068 writew(tail, &(eaddr->ev_tail));
6069 DGAP_UNLOCK(bd->bd_lock, lock_flags);
6074 static ssize_t dgap_driver_version_show(struct device_driver *ddp, char *buf)
6076 return snprintf(buf, PAGE_SIZE, "%s\n", DG_PART);
6078 static DRIVER_ATTR(version, S_IRUSR, dgap_driver_version_show, NULL);
6081 static ssize_t dgap_driver_boards_show(struct device_driver *ddp, char *buf)
6083 return snprintf(buf, PAGE_SIZE, "%d\n", dgap_NumBoards);
6085 static DRIVER_ATTR(boards, S_IRUSR, dgap_driver_boards_show, NULL);
6088 static ssize_t dgap_driver_maxboards_show(struct device_driver *ddp, char *buf)
6090 return snprintf(buf, PAGE_SIZE, "%d\n", MAXBOARDS);
6092 static DRIVER_ATTR(maxboards, S_IRUSR, dgap_driver_maxboards_show, NULL);
6095 static ssize_t dgap_driver_pollcounter_show(struct device_driver *ddp, char *buf)
6097 return snprintf(buf, PAGE_SIZE, "%ld\n", dgap_poll_counter);
6099 static DRIVER_ATTR(pollcounter, S_IRUSR, dgap_driver_pollcounter_show, NULL);
6102 static ssize_t dgap_driver_state_show(struct device_driver *ddp, char *buf)
6104 return snprintf(buf, PAGE_SIZE, "%s\n", dgap_driver_state_text[dgap_driver_state]);
6106 static DRIVER_ATTR(state, S_IRUSR, dgap_driver_state_show, NULL);
6108 static ssize_t dgap_driver_pollrate_show(struct device_driver *ddp, char *buf)
6110 return snprintf(buf, PAGE_SIZE, "%dms\n", dgap_poll_tick);
6113 static ssize_t dgap_driver_pollrate_store(struct device_driver *ddp, const char *buf, size_t count)
6115 if (sscanf(buf, "%d\n", &dgap_poll_tick) != 1)
6119 static DRIVER_ATTR(pollrate, (S_IRUSR | S_IWUSR), dgap_driver_pollrate_show, dgap_driver_pollrate_store);
6121 static void dgap_create_driver_sysfiles(struct pci_driver *dgap_driver)
6124 struct device_driver *driverfs = &dgap_driver->driver;
6126 rc |= driver_create_file(driverfs, &driver_attr_version);
6127 rc |= driver_create_file(driverfs, &driver_attr_boards);
6128 rc |= driver_create_file(driverfs, &driver_attr_maxboards);
6129 rc |= driver_create_file(driverfs, &driver_attr_pollrate);
6130 rc |= driver_create_file(driverfs, &driver_attr_pollcounter);
6131 rc |= driver_create_file(driverfs, &driver_attr_state);
6133 printk(KERN_ERR "DGAP: sysfs driver_create_file failed!\n");
6136 static void dgap_remove_driver_sysfiles(struct pci_driver *dgap_driver)
6138 struct device_driver *driverfs = &dgap_driver->driver;
6139 driver_remove_file(driverfs, &driver_attr_version);
6140 driver_remove_file(driverfs, &driver_attr_boards);
6141 driver_remove_file(driverfs, &driver_attr_maxboards);
6142 driver_remove_file(driverfs, &driver_attr_pollrate);
6143 driver_remove_file(driverfs, &driver_attr_pollcounter);
6144 driver_remove_file(driverfs, &driver_attr_state);
6147 static struct board_t *dgap_verify_board(struct device *p)
6154 bd = dev_get_drvdata(p);
6155 if (!bd || bd->magic != DGAP_BOARD_MAGIC || bd->state != BOARD_READY)
6161 static ssize_t dgap_ports_state_show(struct device *p, struct device_attribute *attr, char *buf)
6167 bd = dgap_verify_board(p);
6171 for (i = 0; i < bd->nasync; i++) {
6172 count += snprintf(buf + count, PAGE_SIZE - count,
6173 "%d %s\n", bd->channels[i]->ch_portnum,
6174 bd->channels[i]->ch_open_count ? "Open" : "Closed");
6178 static DEVICE_ATTR(ports_state, S_IRUSR, dgap_ports_state_show, NULL);
6180 static ssize_t dgap_ports_baud_show(struct device *p, struct device_attribute *attr, char *buf)
6186 bd = dgap_verify_board(p);
6190 for (i = 0; i < bd->nasync; i++) {
6191 count += snprintf(buf + count, PAGE_SIZE - count,
6192 "%d %d\n", bd->channels[i]->ch_portnum, bd->channels[i]->ch_baud_info);
6196 static DEVICE_ATTR(ports_baud, S_IRUSR, dgap_ports_baud_show, NULL);
6198 static ssize_t dgap_ports_msignals_show(struct device *p, struct device_attribute *attr, char *buf)
6204 bd = dgap_verify_board(p);
6208 for (i = 0; i < bd->nasync; i++) {
6209 if (bd->channels[i]->ch_open_count)
6210 count += snprintf(buf + count, PAGE_SIZE - count,
6211 "%d %s %s %s %s %s %s\n", bd->channels[i]->ch_portnum,
6212 (bd->channels[i]->ch_mostat & UART_MCR_RTS) ? "RTS" : "",
6213 (bd->channels[i]->ch_mistat & UART_MSR_CTS) ? "CTS" : "",
6214 (bd->channels[i]->ch_mostat & UART_MCR_DTR) ? "DTR" : "",
6215 (bd->channels[i]->ch_mistat & UART_MSR_DSR) ? "DSR" : "",
6216 (bd->channels[i]->ch_mistat & UART_MSR_DCD) ? "DCD" : "",
6217 (bd->channels[i]->ch_mistat & UART_MSR_RI) ? "RI" : "");
6219 count += snprintf(buf + count, PAGE_SIZE - count,
6220 "%d\n", bd->channels[i]->ch_portnum);
6224 static DEVICE_ATTR(ports_msignals, S_IRUSR, dgap_ports_msignals_show, NULL);
6226 static ssize_t dgap_ports_iflag_show(struct device *p, struct device_attribute *attr, char *buf)
6232 bd = dgap_verify_board(p);
6236 for (i = 0; i < bd->nasync; i++)
6237 count += snprintf(buf + count, PAGE_SIZE - count, "%d %x\n",
6238 bd->channels[i]->ch_portnum, bd->channels[i]->ch_c_iflag);
6241 static DEVICE_ATTR(ports_iflag, S_IRUSR, dgap_ports_iflag_show, NULL);
6243 static ssize_t dgap_ports_cflag_show(struct device *p, struct device_attribute *attr, char *buf)
6249 bd = dgap_verify_board(p);
6253 for (i = 0; i < bd->nasync; i++)
6254 count += snprintf(buf + count, PAGE_SIZE - count, "%d %x\n",
6255 bd->channels[i]->ch_portnum, bd->channels[i]->ch_c_cflag);
6258 static DEVICE_ATTR(ports_cflag, S_IRUSR, dgap_ports_cflag_show, NULL);
6260 static ssize_t dgap_ports_oflag_show(struct device *p, struct device_attribute *attr, char *buf)
6266 bd = dgap_verify_board(p);
6270 for (i = 0; i < bd->nasync; i++)
6271 count += snprintf(buf + count, PAGE_SIZE - count, "%d %x\n",
6272 bd->channels[i]->ch_portnum, bd->channels[i]->ch_c_oflag);
6275 static DEVICE_ATTR(ports_oflag, S_IRUSR, dgap_ports_oflag_show, NULL);
6277 static ssize_t dgap_ports_lflag_show(struct device *p, struct device_attribute *attr, char *buf)
6283 bd = dgap_verify_board(p);
6287 for (i = 0; i < bd->nasync; i++)
6288 count += snprintf(buf + count, PAGE_SIZE - count, "%d %x\n",
6289 bd->channels[i]->ch_portnum, bd->channels[i]->ch_c_lflag);
6292 static DEVICE_ATTR(ports_lflag, S_IRUSR, dgap_ports_lflag_show, NULL);
6294 static ssize_t dgap_ports_digi_flag_show(struct device *p, struct device_attribute *attr, char *buf)
6300 bd = dgap_verify_board(p);
6304 for (i = 0; i < bd->nasync; i++)
6305 count += snprintf(buf + count, PAGE_SIZE - count, "%d %x\n",
6306 bd->channels[i]->ch_portnum, bd->channels[i]->ch_digi.digi_flags);
6309 static DEVICE_ATTR(ports_digi_flag, S_IRUSR, dgap_ports_digi_flag_show, NULL);
6311 static ssize_t dgap_ports_rxcount_show(struct device *p, struct device_attribute *attr, char *buf)
6317 bd = dgap_verify_board(p);
6321 for (i = 0; i < bd->nasync; i++)
6322 count += snprintf(buf + count, PAGE_SIZE - count, "%d %ld\n",
6323 bd->channels[i]->ch_portnum, bd->channels[i]->ch_rxcount);
6326 static DEVICE_ATTR(ports_rxcount, S_IRUSR, dgap_ports_rxcount_show, NULL);
6328 static ssize_t dgap_ports_txcount_show(struct device *p, struct device_attribute *attr, char *buf)
6334 bd = dgap_verify_board(p);
6338 for (i = 0; i < bd->nasync; i++)
6339 count += snprintf(buf + count, PAGE_SIZE - count, "%d %ld\n",
6340 bd->channels[i]->ch_portnum, bd->channels[i]->ch_txcount);
6343 static DEVICE_ATTR(ports_txcount, S_IRUSR, dgap_ports_txcount_show, NULL);
6345 /* this function creates the sys files that will export each signal status
6346 * to sysfs each value will be put in a separate filename
6348 static void dgap_create_ports_sysfiles(struct board_t *bd)
6352 dev_set_drvdata(&bd->pdev->dev, bd);
6353 rc |= device_create_file(&(bd->pdev->dev), &dev_attr_ports_state);
6354 rc |= device_create_file(&(bd->pdev->dev), &dev_attr_ports_baud);
6355 rc |= device_create_file(&(bd->pdev->dev), &dev_attr_ports_msignals);
6356 rc |= device_create_file(&(bd->pdev->dev), &dev_attr_ports_iflag);
6357 rc |= device_create_file(&(bd->pdev->dev), &dev_attr_ports_cflag);
6358 rc |= device_create_file(&(bd->pdev->dev), &dev_attr_ports_oflag);
6359 rc |= device_create_file(&(bd->pdev->dev), &dev_attr_ports_lflag);
6360 rc |= device_create_file(&(bd->pdev->dev), &dev_attr_ports_digi_flag);
6361 rc |= device_create_file(&(bd->pdev->dev), &dev_attr_ports_rxcount);
6362 rc |= device_create_file(&(bd->pdev->dev), &dev_attr_ports_txcount);
6364 printk(KERN_ERR "DGAP: sysfs device_create_file failed!\n");
6367 /* removes all the sys files created for that port */
6368 static void dgap_remove_ports_sysfiles(struct board_t *bd)
6370 device_remove_file(&(bd->pdev->dev), &dev_attr_ports_state);
6371 device_remove_file(&(bd->pdev->dev), &dev_attr_ports_baud);
6372 device_remove_file(&(bd->pdev->dev), &dev_attr_ports_msignals);
6373 device_remove_file(&(bd->pdev->dev), &dev_attr_ports_iflag);
6374 device_remove_file(&(bd->pdev->dev), &dev_attr_ports_cflag);
6375 device_remove_file(&(bd->pdev->dev), &dev_attr_ports_oflag);
6376 device_remove_file(&(bd->pdev->dev), &dev_attr_ports_lflag);
6377 device_remove_file(&(bd->pdev->dev), &dev_attr_ports_digi_flag);
6378 device_remove_file(&(bd->pdev->dev), &dev_attr_ports_rxcount);
6379 device_remove_file(&(bd->pdev->dev), &dev_attr_ports_txcount);
6382 static ssize_t dgap_tty_state_show(struct device *d, struct device_attribute *attr, char *buf)
6385 struct channel_t *ch;
6390 un = dev_get_drvdata(d);
6391 if (!un || un->magic != DGAP_UNIT_MAGIC)
6394 if (!ch || ch->magic != DGAP_CHANNEL_MAGIC)
6397 if (!bd || bd->magic != DGAP_BOARD_MAGIC)
6399 if (bd->state != BOARD_READY)
6402 return snprintf(buf, PAGE_SIZE, "%s", un->un_open_count ? "Open" : "Closed");
6404 static DEVICE_ATTR(state, S_IRUSR, dgap_tty_state_show, NULL);
6406 static ssize_t dgap_tty_baud_show(struct device *d, struct device_attribute *attr, char *buf)
6409 struct channel_t *ch;
6414 un = dev_get_drvdata(d);
6415 if (!un || un->magic != DGAP_UNIT_MAGIC)
6418 if (!ch || ch->magic != DGAP_CHANNEL_MAGIC)
6421 if (!bd || bd->magic != DGAP_BOARD_MAGIC)
6423 if (bd->state != BOARD_READY)
6426 return snprintf(buf, PAGE_SIZE, "%d\n", ch->ch_baud_info);
6428 static DEVICE_ATTR(baud, S_IRUSR, dgap_tty_baud_show, NULL);
6430 static ssize_t dgap_tty_msignals_show(struct device *d, struct device_attribute *attr, char *buf)
6433 struct channel_t *ch;
6438 un = dev_get_drvdata(d);
6439 if (!un || un->magic != DGAP_UNIT_MAGIC)
6442 if (!ch || ch->magic != DGAP_CHANNEL_MAGIC)
6445 if (!bd || bd->magic != DGAP_BOARD_MAGIC)
6447 if (bd->state != BOARD_READY)
6450 if (ch->ch_open_count) {
6451 return snprintf(buf, PAGE_SIZE, "%s %s %s %s %s %s\n",
6452 (ch->ch_mostat & UART_MCR_RTS) ? "RTS" : "",
6453 (ch->ch_mistat & UART_MSR_CTS) ? "CTS" : "",
6454 (ch->ch_mostat & UART_MCR_DTR) ? "DTR" : "",
6455 (ch->ch_mistat & UART_MSR_DSR) ? "DSR" : "",
6456 (ch->ch_mistat & UART_MSR_DCD) ? "DCD" : "",
6457 (ch->ch_mistat & UART_MSR_RI) ? "RI" : "");
6461 static DEVICE_ATTR(msignals, S_IRUSR, dgap_tty_msignals_show, NULL);
6463 static ssize_t dgap_tty_iflag_show(struct device *d, struct device_attribute *attr, char *buf)
6466 struct channel_t *ch;
6471 un = dev_get_drvdata(d);
6472 if (!un || un->magic != DGAP_UNIT_MAGIC)
6475 if (!ch || ch->magic != DGAP_CHANNEL_MAGIC)
6478 if (!bd || bd->magic != DGAP_BOARD_MAGIC)
6480 if (bd->state != BOARD_READY)
6483 return snprintf(buf, PAGE_SIZE, "%x\n", ch->ch_c_iflag);
6485 static DEVICE_ATTR(iflag, S_IRUSR, dgap_tty_iflag_show, NULL);
6487 static ssize_t dgap_tty_cflag_show(struct device *d, struct device_attribute *attr, char *buf)
6490 struct channel_t *ch;
6495 un = dev_get_drvdata(d);
6496 if (!un || un->magic != DGAP_UNIT_MAGIC)
6499 if (!ch || ch->magic != DGAP_CHANNEL_MAGIC)
6502 if (!bd || bd->magic != DGAP_BOARD_MAGIC)
6504 if (bd->state != BOARD_READY)
6507 return snprintf(buf, PAGE_SIZE, "%x\n", ch->ch_c_cflag);
6509 static DEVICE_ATTR(cflag, S_IRUSR, dgap_tty_cflag_show, NULL);
6511 static ssize_t dgap_tty_oflag_show(struct device *d, struct device_attribute *attr, char *buf)
6514 struct channel_t *ch;
6519 un = dev_get_drvdata(d);
6520 if (!un || un->magic != DGAP_UNIT_MAGIC)
6523 if (!ch || ch->magic != DGAP_CHANNEL_MAGIC)
6526 if (!bd || bd->magic != DGAP_BOARD_MAGIC)
6528 if (bd->state != BOARD_READY)
6531 return snprintf(buf, PAGE_SIZE, "%x\n", ch->ch_c_oflag);
6533 static DEVICE_ATTR(oflag, S_IRUSR, dgap_tty_oflag_show, NULL);
6535 static ssize_t dgap_tty_lflag_show(struct device *d, struct device_attribute *attr, char *buf)
6538 struct channel_t *ch;
6543 un = dev_get_drvdata(d);
6544 if (!un || un->magic != DGAP_UNIT_MAGIC)
6547 if (!ch || ch->magic != DGAP_CHANNEL_MAGIC)
6550 if (!bd || bd->magic != DGAP_BOARD_MAGIC)
6552 if (bd->state != BOARD_READY)
6555 return snprintf(buf, PAGE_SIZE, "%x\n", ch->ch_c_lflag);
6557 static DEVICE_ATTR(lflag, S_IRUSR, dgap_tty_lflag_show, NULL);
6559 static ssize_t dgap_tty_digi_flag_show(struct device *d, struct device_attribute *attr, char *buf)
6562 struct channel_t *ch;
6567 un = dev_get_drvdata(d);
6568 if (!un || un->magic != DGAP_UNIT_MAGIC)
6571 if (!ch || ch->magic != DGAP_CHANNEL_MAGIC)
6574 if (!bd || bd->magic != DGAP_BOARD_MAGIC)
6576 if (bd->state != BOARD_READY)
6579 return snprintf(buf, PAGE_SIZE, "%x\n", ch->ch_digi.digi_flags);
6581 static DEVICE_ATTR(digi_flag, S_IRUSR, dgap_tty_digi_flag_show, NULL);
6583 static ssize_t dgap_tty_rxcount_show(struct device *d, struct device_attribute *attr, char *buf)
6586 struct channel_t *ch;
6591 un = dev_get_drvdata(d);
6592 if (!un || un->magic != DGAP_UNIT_MAGIC)
6595 if (!ch || ch->magic != DGAP_CHANNEL_MAGIC)
6598 if (!bd || bd->magic != DGAP_BOARD_MAGIC)
6600 if (bd->state != BOARD_READY)
6603 return snprintf(buf, PAGE_SIZE, "%ld\n", ch->ch_rxcount);
6605 static DEVICE_ATTR(rxcount, S_IRUSR, dgap_tty_rxcount_show, NULL);
6607 static ssize_t dgap_tty_txcount_show(struct device *d, struct device_attribute *attr, char *buf)
6610 struct channel_t *ch;
6615 un = dev_get_drvdata(d);
6616 if (!un || un->magic != DGAP_UNIT_MAGIC)
6619 if (!ch || ch->magic != DGAP_CHANNEL_MAGIC)
6622 if (!bd || bd->magic != DGAP_BOARD_MAGIC)
6624 if (bd->state != BOARD_READY)
6627 return snprintf(buf, PAGE_SIZE, "%ld\n", ch->ch_txcount);
6629 static DEVICE_ATTR(txcount, S_IRUSR, dgap_tty_txcount_show, NULL);
6631 static ssize_t dgap_tty_name_show(struct device *d, struct device_attribute *attr, char *buf)
6634 struct channel_t *ch;
6638 struct cnode *cptr = NULL;
6646 un = dev_get_drvdata(d);
6647 if (!un || un->magic != DGAP_UNIT_MAGIC)
6650 if (!ch || ch->magic != DGAP_CHANNEL_MAGIC)
6653 if (!bd || bd->magic != DGAP_BOARD_MAGIC)
6655 if (bd->state != BOARD_READY)
6659 cn = ch->ch_portnum;
6661 for (cptr = bd->bd_config; cptr; cptr = cptr->next) {
6663 if ((cptr->type == BNODE) &&
6664 ((cptr->u.board.type == APORT2_920P) || (cptr->u.board.type == APORT4_920P) ||
6665 (cptr->u.board.type == APORT8_920P) || (cptr->u.board.type == PAPORT4) ||
6666 (cptr->u.board.type == PAPORT8))) {
6669 if (cptr->u.board.v_start)
6670 starto = cptr->u.board.start;
6675 if (cptr->type == TNODE && found == TRUE) {
6677 if (strstr(cptr->u.ttyname, "tty")) {
6678 ptr1 = cptr->u.ttyname;
6681 ptr1 = cptr->u.ttyname;
6683 for (i = 0; i < dgap_config_get_number_of_ports(bd); i++) {
6685 return snprintf(buf, PAGE_SIZE, "%s%s%02d\n",
6686 (un->un_type == DGAP_PRINT) ? "pr" : "tty",
6691 if (cptr->type == CNODE) {
6693 for (i = 0; i < cptr->u.conc.nport; i++) {
6694 if (cn == (i + ncount))
6696 return snprintf(buf, PAGE_SIZE, "%s%s%02d\n",
6697 (un->un_type == DGAP_PRINT) ? "pr" : "tty",
6699 i + (cptr->u.conc.v_start ? cptr->u.conc.start : 1));
6702 ncount += cptr->u.conc.nport;
6705 if (cptr->type == MNODE) {
6707 for (i = 0; i < cptr->u.module.nport; i++) {
6708 if (cn == (i + ncount))
6709 return snprintf(buf, PAGE_SIZE, "%s%s%02d\n",
6710 (un->un_type == DGAP_PRINT) ? "pr" : "tty",
6712 i + (cptr->u.module.v_start ? cptr->u.module.start : 1));
6715 ncount += cptr->u.module.nport;
6720 return snprintf(buf, PAGE_SIZE, "%s_dgap_%d_%d\n",
6721 (un->un_type == DGAP_PRINT) ? "pr" : "tty", bn, cn);
6724 static DEVICE_ATTR(custom_name, S_IRUSR, dgap_tty_name_show, NULL);
6726 static struct attribute *dgap_sysfs_tty_entries[] = {
6727 &dev_attr_state.attr,
6728 &dev_attr_baud.attr,
6729 &dev_attr_msignals.attr,
6730 &dev_attr_iflag.attr,
6731 &dev_attr_cflag.attr,
6732 &dev_attr_oflag.attr,
6733 &dev_attr_lflag.attr,
6734 &dev_attr_digi_flag.attr,
6735 &dev_attr_rxcount.attr,
6736 &dev_attr_txcount.attr,
6737 &dev_attr_custom_name.attr,
6741 static struct attribute_group dgap_tty_attribute_group = {
6743 .attrs = dgap_sysfs_tty_entries,
6746 static void dgap_create_tty_sysfs(struct un_t *un, struct device *c)
6750 ret = sysfs_create_group(&c->kobj, &dgap_tty_attribute_group);
6754 dev_set_drvdata(c, un);
6758 static void dgap_remove_tty_sysfs(struct device *c)
6760 sysfs_remove_group(&c->kobj, &dgap_tty_attribute_group);
6764 * Parse a configuration file read into memory as a string.
6766 static int dgap_parsefile(char **in, int Remove)
6768 struct cnode *p, *brd, *line, *conc;
6770 char *s = NULL, *s2 = NULL;
6774 brd = line = conc = NULL;
6776 /* perhaps we are adding to an existing list? */
6777 while (p->next != NULL)
6780 /* file must start with a BEGIN */
6781 while ((rc = dgap_gettok(in, p)) != BEGIN) {
6783 dgap_err("unexpected EOF");
6789 rc = dgap_gettok(in, p);
6791 dgap_err("unexpected EOF");
6797 dgap_err("unexpected end of file");
6800 case BEGIN: /* should only be 1 begin */
6801 dgap_err("unexpected config_begin\n");
6807 case BOARD: /* board info */
6808 if (dgap_checknode(p))
6810 p->next = dgap_newnode(BNODE);
6812 dgap_err("out of memory");
6817 p->u.board.status = dgap_savestring("No");
6823 case APORT2_920P: /* AccelePort_4 */
6824 if (p->type != BNODE) {
6825 dgap_err("unexpected Digi_2r_920 string");
6828 p->u.board.type = APORT2_920P;
6829 p->u.board.v_type = 1;
6832 case APORT4_920P: /* AccelePort_4 */
6833 if (p->type != BNODE) {
6834 dgap_err("unexpected Digi_4r_920 string");
6837 p->u.board.type = APORT4_920P;
6838 p->u.board.v_type = 1;
6841 case APORT8_920P: /* AccelePort_8 */
6842 if (p->type != BNODE) {
6843 dgap_err("unexpected Digi_8r_920 string");
6846 p->u.board.type = APORT8_920P;
6847 p->u.board.v_type = 1;
6850 case PAPORT4: /* AccelePort_4 PCI */
6851 if (p->type != BNODE) {
6852 dgap_err("unexpected Digi_4r(PCI) string");
6855 p->u.board.type = PAPORT4;
6856 p->u.board.v_type = 1;
6859 case PAPORT8: /* AccelePort_8 PCI */
6860 if (p->type != BNODE) {
6861 dgap_err("unexpected Digi_8r string");
6864 p->u.board.type = PAPORT8;
6865 p->u.board.v_type = 1;
6868 case PCX: /* PCI C/X */
6869 if (p->type != BNODE) {
6870 dgap_err("unexpected Digi_C/X_(PCI) string");
6873 p->u.board.type = PCX;
6874 p->u.board.v_type = 1;
6875 p->u.board.conc1 = 0;
6876 p->u.board.conc2 = 0;
6877 p->u.board.module1 = 0;
6878 p->u.board.module2 = 0;
6881 case PEPC: /* PCI EPC/X */
6882 if (p->type != BNODE) {
6883 dgap_err("unexpected \"Digi_EPC/X_(PCI)\" string");
6886 p->u.board.type = PEPC;
6887 p->u.board.v_type = 1;
6888 p->u.board.conc1 = 0;
6889 p->u.board.conc2 = 0;
6890 p->u.board.module1 = 0;
6891 p->u.board.module2 = 0;
6894 case PPCM: /* PCI/Xem */
6895 if (p->type != BNODE) {
6896 dgap_err("unexpected PCI/Xem string");
6899 p->u.board.type = PPCM;
6900 p->u.board.v_type = 1;
6901 p->u.board.conc1 = 0;
6902 p->u.board.conc2 = 0;
6905 case IO: /* i/o port */
6906 if (p->type != BNODE) {
6907 dgap_err("IO port only vaild for boards");
6910 s = dgap_getword(in);
6912 dgap_err("unexpected end of file");
6915 p->u.board.portstr = dgap_savestring(s);
6916 p->u.board.port = (short)simple_strtol(s, &s2, 0);
6917 if ((short)strlen(s) > (short)(s2 - s)) {
6918 dgap_err("bad number for IO port");
6921 p->u.board.v_port = 1;
6924 case MEM: /* memory address */
6925 if (p->type != BNODE) {
6926 dgap_err("memory address only vaild for boards");
6929 s = dgap_getword(in);
6931 dgap_err("unexpected end of file");
6934 p->u.board.addrstr = dgap_savestring(s);
6935 p->u.board.addr = simple_strtoul(s, &s2, 0);
6936 if ((int)strlen(s) > (int)(s2 - s)) {
6937 dgap_err("bad number for memory address");
6940 p->u.board.v_addr = 1;
6943 case PCIINFO: /* pci information */
6944 if (p->type != BNODE) {
6945 dgap_err("memory address only vaild for boards");
6948 s = dgap_getword(in);
6950 dgap_err("unexpected end of file");
6953 p->u.board.pcibusstr = dgap_savestring(s);
6954 p->u.board.pcibus = simple_strtoul(s, &s2, 0);
6955 if ((int)strlen(s) > (int)(s2 - s)) {
6956 dgap_err("bad number for pci bus");
6959 p->u.board.v_pcibus = 1;
6960 s = dgap_getword(in);
6962 dgap_err("unexpected end of file");
6965 p->u.board.pcislotstr = dgap_savestring(s);
6966 p->u.board.pcislot = simple_strtoul(s, &s2, 0);
6967 if ((int)strlen(s) > (int)(s2 - s)) {
6968 dgap_err("bad number for pci slot");
6971 p->u.board.v_pcislot = 1;
6975 if (p->type != BNODE) {
6976 dgap_err("install method only vaild for boards");
6979 s = dgap_getword(in);
6981 dgap_err("unexpected end of file");
6984 p->u.board.method = dgap_savestring(s);
6985 p->u.board.v_method = 1;
6989 if (p->type != BNODE) {
6990 dgap_err("config status only vaild for boards");
6993 s = dgap_getword(in);
6995 dgap_err("unexpected end of file");
6998 p->u.board.status = dgap_savestring(s);
7001 case NPORTS: /* number of ports */
7002 if (p->type == BNODE) {
7003 s = dgap_getword(in);
7005 dgap_err("unexpected end of file");
7008 p->u.board.nport = (char)simple_strtol(s, &s2, 0);
7009 if ((int)strlen(s) > (int)(s2 - s)) {
7010 dgap_err("bad number for number of ports");
7013 p->u.board.v_nport = 1;
7014 } else if (p->type == CNODE) {
7015 s = dgap_getword(in);
7017 dgap_err("unexpected end of file");
7020 p->u.conc.nport = (char)simple_strtol(s, &s2, 0);
7021 if ((int)strlen(s) > (int)(s2 - s)) {
7022 dgap_err("bad number for number of ports");
7025 p->u.conc.v_nport = 1;
7026 } else if (p->type == MNODE) {
7027 s = dgap_getword(in);
7029 dgap_err("unexpected end of file");
7032 p->u.module.nport = (char)simple_strtol(s, &s2, 0);
7033 if ((int)strlen(s) > (int)(s2 - s)) {
7034 dgap_err("bad number for number of ports");
7037 p->u.module.v_nport = 1;
7039 dgap_err("nports only valid for concentrators or modules");
7044 case ID: /* letter ID used in tty name */
7045 s = dgap_getword(in);
7047 dgap_err("unexpected end of file");
7051 p->u.board.status = dgap_savestring(s);
7053 if (p->type == CNODE) {
7054 p->u.conc.id = dgap_savestring(s);
7056 } else if (p->type == MNODE) {
7057 p->u.module.id = dgap_savestring(s);
7058 p->u.module.v_id = 1;
7060 dgap_err("id only valid for concentrators or modules");
7065 case STARTO: /* start offset of ID */
7066 if (p->type == BNODE) {
7067 s = dgap_getword(in);
7069 dgap_err("unexpected end of file");
7072 p->u.board.start = simple_strtol(s, &s2, 0);
7073 if ((int)strlen(s) > (int)(s2 - s)) {
7074 dgap_err("bad number for start of tty count");
7077 p->u.board.v_start = 1;
7078 } else if (p->type == CNODE) {
7079 s = dgap_getword(in);
7081 dgap_err("unexpected end of file");
7084 p->u.conc.start = simple_strtol(s, &s2, 0);
7085 if ((int)strlen(s) > (int)(s2 - s)) {
7086 dgap_err("bad number for start of tty count");
7089 p->u.conc.v_start = 1;
7090 } else if (p->type == MNODE) {
7091 s = dgap_getword(in);
7093 dgap_err("unexpected end of file");
7096 p->u.module.start = simple_strtol(s, &s2, 0);
7097 if ((int)strlen(s) > (int)(s2 - s)) {
7098 dgap_err("bad number for start of tty count");
7101 p->u.module.v_start = 1;
7103 dgap_err("start only valid for concentrators or modules");
7108 case TTYN: /* tty name prefix */
7109 if (dgap_checknode(p))
7111 p->next = dgap_newnode(TNODE);
7113 dgap_err("out of memory");
7117 s = dgap_getword(in);
7119 dgap_err("unexpeced end of file");
7122 p->u.ttyname = dgap_savestring(s);
7123 if (!p->u.ttyname) {
7124 dgap_err("out of memory");
7129 case CU: /* cu name prefix */
7130 if (dgap_checknode(p))
7132 p->next = dgap_newnode(CUNODE);
7134 dgap_err("out of memory");
7138 s = dgap_getword(in);
7140 dgap_err("unexpeced end of file");
7143 p->u.cuname = dgap_savestring(s);
7145 dgap_err("out of memory");
7150 case LINE: /* line information */
7151 if (dgap_checknode(p))
7154 dgap_err("must specify board before line info");
7157 switch (brd->u.board.type) {
7159 dgap_err("line not vaild for PC/em");
7162 p->next = dgap_newnode(LNODE);
7164 dgap_err("out of memory");
7173 case CONC: /* concentrator information */
7174 if (dgap_checknode(p))
7177 dgap_err("must specify line info before concentrator");
7180 p->next = dgap_newnode(CNODE);
7182 dgap_err("out of memory");
7188 brd->u.board.conc2++;
7190 brd->u.board.conc1++;
7194 case CX: /* c/x type concentrator */
7195 if (p->type != CNODE) {
7196 dgap_err("cx only valid for concentrators");
7199 p->u.conc.type = CX;
7200 p->u.conc.v_type = 1;
7203 case EPC: /* epc type concentrator */
7204 if (p->type != CNODE) {
7205 dgap_err("cx only valid for concentrators");
7208 p->u.conc.type = EPC;
7209 p->u.conc.v_type = 1;
7212 case MOD: /* EBI module */
7213 if (dgap_checknode(p))
7216 dgap_err("must specify board info before EBI modules");
7219 switch (brd->u.board.type) {
7225 dgap_err("must specify concentrator info before EBI module");
7229 p->next = dgap_newnode(MNODE);
7231 dgap_err("out of memory");
7236 brd->u.board.module2++;
7238 brd->u.board.module1++;
7242 case PORTS: /* ports type EBI module */
7243 if (p->type != MNODE) {
7244 dgap_err("ports only valid for EBI modules");
7247 p->u.module.type = PORTS;
7248 p->u.module.v_type = 1;
7251 case MODEM: /* ports type EBI module */
7252 if (p->type != MNODE) {
7253 dgap_err("modem only valid for modem modules");
7256 p->u.module.type = MODEM;
7257 p->u.module.v_type = 1;
7261 if (p->type == LNODE) {
7262 s = dgap_getword(in);
7264 dgap_err("unexpected end of file");
7267 p->u.line.cable = dgap_savestring(s);
7268 p->u.line.v_cable = 1;
7272 case SPEED: /* sync line speed indication */
7273 if (p->type == LNODE) {
7274 s = dgap_getword(in);
7276 dgap_err("unexpected end of file");
7279 p->u.line.speed = (char)simple_strtol(s, &s2, 0);
7280 if ((short)strlen(s) > (short)(s2 - s)) {
7281 dgap_err("bad number for line speed");
7284 p->u.line.v_speed = 1;
7285 } else if (p->type == CNODE) {
7286 s = dgap_getword(in);
7288 dgap_err("unexpected end of file");
7291 p->u.conc.speed = (char)simple_strtol(s, &s2, 0);
7292 if ((short)strlen(s) > (short)(s2 - s)) {
7293 dgap_err("bad number for line speed");
7296 p->u.conc.v_speed = 1;
7298 dgap_err("speed valid only for lines or concentrators.");
7304 if (p->type == CNODE) {
7305 s = dgap_getword(in);
7307 dgap_err("unexpected end of file");
7310 p->u.conc.connect = dgap_savestring(s);
7311 p->u.conc.v_connect = 1;
7314 case PRINT: /* transparent print name prefix */
7315 if (dgap_checknode(p))
7317 p->next = dgap_newnode(PNODE);
7319 dgap_err("out of memory");
7323 s = dgap_getword(in);
7325 dgap_err("unexpeced end of file");
7328 p->u.printname = dgap_savestring(s);
7329 if (!p->u.printname) {
7330 dgap_err("out of memory");
7335 case CMAJOR: /* major number */
7336 if (dgap_checknode(p))
7338 p->next = dgap_newnode(JNODE);
7340 dgap_err("out of memory");
7344 s = dgap_getword(in);
7346 dgap_err("unexpected end of file");
7349 p->u.majornumber = simple_strtol(s, &s2, 0);
7350 if ((int)strlen(s) > (int)(s2 - s)) {
7351 dgap_err("bad number for major number");
7356 case ALTPIN: /* altpin setting */
7357 if (dgap_checknode(p))
7359 p->next = dgap_newnode(ANODE);
7361 dgap_err("out of memory");
7365 s = dgap_getword(in);
7367 dgap_err("unexpected end of file");
7370 p->u.altpin = simple_strtol(s, &s2, 0);
7371 if ((int)strlen(s) > (int)(s2 - s)) {
7372 dgap_err("bad number for altpin");
7377 case USEINTR: /* enable interrupt setting */
7378 if (dgap_checknode(p))
7380 p->next = dgap_newnode(INTRNODE);
7382 dgap_err("out of memory");
7386 s = dgap_getword(in);
7388 dgap_err("unexpected end of file");
7391 p->u.useintr = simple_strtol(s, &s2, 0);
7392 if ((int)strlen(s) > (int)(s2 - s)) {
7393 dgap_err("bad number for useintr");
7398 case TTSIZ: /* size of tty structure */
7399 if (dgap_checknode(p))
7401 p->next = dgap_newnode(TSNODE);
7403 dgap_err("out of memory");
7407 s = dgap_getword(in);
7409 dgap_err("unexpected end of file");
7412 p->u.ttysize = simple_strtol(s, &s2, 0);
7413 if ((int)strlen(s) > (int)(s2 - s)) {
7414 dgap_err("bad number for ttysize");
7419 case CHSIZ: /* channel structure size */
7420 if (dgap_checknode(p))
7422 p->next = dgap_newnode(CSNODE);
7424 dgap_err("out of memory");
7428 s = dgap_getword(in);
7430 dgap_err("unexpected end of file");
7433 p->u.chsize = simple_strtol(s, &s2, 0);
7434 if ((int)strlen(s) > (int)(s2 - s)) {
7435 dgap_err("bad number for chsize");
7440 case BSSIZ: /* board structure size */
7441 if (dgap_checknode(p))
7443 p->next = dgap_newnode(BSNODE);
7445 dgap_err("out of memory");
7449 s = dgap_getword(in);
7451 dgap_err("unexpected end of file");
7454 p->u.bssize = simple_strtol(s, &s2, 0);
7455 if ((int)strlen(s) > (int)(s2 - s)) {
7456 dgap_err("bad number for bssize");
7461 case UNTSIZ: /* sched structure size */
7462 if (dgap_checknode(p))
7464 p->next = dgap_newnode(USNODE);
7466 dgap_err("out of memory");
7470 s = dgap_getword(in);
7472 dgap_err("unexpected end of file");
7475 p->u.unsize = simple_strtol(s, &s2, 0);
7476 if ((int)strlen(s) > (int)(s2 - s)) {
7477 dgap_err("bad number for schedsize");
7482 case F2SIZ: /* f2200 structure size */
7483 if (dgap_checknode(p))
7485 p->next = dgap_newnode(FSNODE);
7487 dgap_err("out of memory");
7491 s = dgap_getword(in);
7493 dgap_err("unexpected end of file");
7496 p->u.f2size = simple_strtol(s, &s2, 0);
7497 if ((int)strlen(s) > (int)(s2 - s)) {
7498 dgap_err("bad number for f2200size");
7503 case VPSIZ: /* vpix structure size */
7504 if (dgap_checknode(p))
7506 p->next = dgap_newnode(VSNODE);
7508 dgap_err("out of memory");
7512 s = dgap_getword(in);
7514 dgap_err("unexpected end of file");
7517 p->u.vpixsize = simple_strtol(s, &s2, 0);
7518 if ((int)strlen(s) > (int)(s2 - s)) {
7519 dgap_err("bad number for vpixsize");
7528 * dgap_sindex: much like index(), but it looks for a match of any character in
7529 * the group, and returns that position. If the first character is a ^, then
7530 * this will match the first occurrence not in that group.
7532 static char *dgap_sindex(char *string, char *group)
7536 if (!string || !group)
7537 return (char *) NULL;
7539 if (*group == '^') {
7541 for (; *string; string++) {
7542 for (ptr = group; *ptr; ptr++) {
7543 if (*ptr == *string)
7550 for (; *string; string++) {
7551 for (ptr = group; *ptr; ptr++) {
7552 if (*ptr == *string)
7558 return (char *) NULL;
7562 * Get a token from the input file; return 0 if end of file is reached
7564 static int dgap_gettok(char **in, struct cnode *p)
7569 if (strstr(dgap_cword, "boar")) {
7570 w = dgap_getword(in);
7571 snprintf(dgap_cword, MAXCWORD, "%s", w);
7572 for (t = dgap_tlist; t->token != 0; t++) {
7573 if (!strcmp(w, t->string))
7576 dgap_err("board !!type not specified");
7579 while ((w = dgap_getword(in))) {
7580 snprintf(dgap_cword, MAXCWORD, "%s", w);
7581 for (t = dgap_tlist; t->token != 0; t++) {
7582 if (!strcmp(w, t->string))
7591 * get a word from the input stream, also keep track of current line number.
7592 * words are separated by whitespace.
7594 static char *dgap_getword(char **in)
7596 char *ret_ptr = *in;
7598 char *ptr = dgap_sindex(*in, " \t\n");
7600 /* If no word found, return null */
7604 /* Mark new location for our buffer */
7608 /* Eat any extra spaces/tabs/newlines that might be present */
7609 while (*in && **in && ((**in == ' ') || (**in == '\t') || (**in == '\n'))) {
7618 * print an error message, giving the line number in the file where
7619 * the error occurred.
7621 static void dgap_err(char *s)
7623 pr_err("dgap: parse: %s\n", s);
7627 * allocate a new configuration node of type t
7629 static struct cnode *dgap_newnode(int t)
7633 n = kmalloc(sizeof(struct cnode), GFP_ATOMIC);
7635 memset((char *)n, 0, sizeof(struct cnode));
7642 * dgap_checknode: see if all the necessary info has been supplied for a node
7643 * before creating the next node.
7645 static int dgap_checknode(struct cnode *p)
7649 if (p->u.board.v_type == 0) {
7650 dgap_err("board type !not specified");
7657 if (p->u.line.v_speed == 0) {
7658 dgap_err("line speed not specified");
7664 if (p->u.conc.v_type == 0) {
7665 dgap_err("concentrator type not specified");
7668 if (p->u.conc.v_speed == 0) {
7669 dgap_err("concentrator line speed not specified");
7672 if (p->u.conc.v_nport == 0) {
7673 dgap_err("number of ports on concentrator not specified");
7676 if (p->u.conc.v_id == 0) {
7677 dgap_err("concentrator id letter not specified");
7683 if (p->u.module.v_type == 0) {
7684 dgap_err("EBI module type not specified");
7687 if (p->u.module.v_nport == 0) {
7688 dgap_err("number of ports on EBI module not specified");
7691 if (p->u.module.v_id == 0) {
7692 dgap_err("EBI module id letter not specified");
7701 * save a string somewhere
7703 static char *dgap_savestring(char *s)
7707 p = kmalloc(strlen(s) + 1, GFP_ATOMIC);
7714 * Given a board pointer, returns whether we should use interrupts or not.
7716 static uint dgap_config_get_useintr(struct board_t *bd)
7718 struct cnode *p = NULL;
7723 for (p = bd->bd_config; p; p = p->next) {
7727 * check for pcxr types.
7729 return p->u.useintr;
7735 /* If not found, then don't turn on interrupts. */
7740 * Given a board pointer, returns whether we turn on altpin or not.
7742 static uint dgap_config_get_altpin(struct board_t *bd)
7744 struct cnode *p = NULL;
7749 for (p = bd->bd_config; p; p = p->next) {
7753 * check for pcxr types.
7761 /* If not found, then don't turn on interrupts. */
7766 * Given a specific type of board, if found, detached link and
7767 * returns the first occurrence in the list.
7769 static struct cnode *dgap_find_config(int type, int bus, int slot)
7771 struct cnode *p, *prev = NULL, *prev2 = NULL, *found = NULL;
7775 while (p->next != NULL) {
7779 if (p->type == BNODE) {
7781 if (p->u.board.type == type) {
7783 if (p->u.board.v_pcibus &&
7784 p->u.board.pcibus != bus)
7786 if (p->u.board.v_pcislot &&
7787 p->u.board.pcislot != slot)
7792 * Keep walking thru the list till we find the next board.
7794 while (p->next != NULL) {
7797 if (p->type == BNODE) {
7800 * Mark the end of our 1 board chain of configs.
7805 * Link the "next" board to the previous board,
7806 * effectively "unlinking" our board from the main config.
7814 * It must be the last board in the list.
7825 * Given a board pointer, walks the config link, counting up
7826 * all ports user specified should be on the board.
7827 * (This does NOT mean they are all actually present right now tho)
7829 static uint dgap_config_get_number_of_ports(struct board_t *bd)
7832 struct cnode *p = NULL;
7837 for (p = bd->bd_config; p; p = p->next) {
7842 * check for pcxr types.
7844 if (p->u.board.type > EPCFE)
7845 count += p->u.board.nport;
7848 count += p->u.conc.nport;
7851 count += p->u.module.nport;
7858 static char *dgap_create_config_string(struct board_t *bd, char *string)
7861 struct cnode *p = NULL;
7862 struct cnode *q = NULL;
7870 for (p = bd->bd_config; p; p = p->next) {
7876 *ptr = p->u.line.speed;
7881 * Because the EPC/con concentrators can have EM modules
7882 * hanging off of them, we have to walk ahead in the list
7883 * and keep adding the number of ports on each EM to the config.
7886 speed = p->u.conc.speed;
7888 if ((q != NULL) && (q->type == MNODE)) {
7889 *ptr = (p->u.conc.nport + 0x80);
7892 while ((q->next != NULL) && (q->next->type) == MNODE) {
7893 *ptr = (q->u.module.nport + 0x80);
7898 *ptr = q->u.module.nport;
7901 *ptr = p->u.conc.nport;