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");
91 * insmod command line overrideable parameters
93 * NOTE: we use a set of macros to create the variables, which allows
94 * us to specify the variable type, name, initial value, and description.
96 PARM_INT(rawreadok, 1, 0644, "Bypass flip buffers on input");
99 /**************************************************************************
101 * protos for this file
105 static int dgap_start(void);
106 static void dgap_init_globals(void);
107 static int dgap_found_board(struct pci_dev *pdev, int id);
108 static void dgap_cleanup_board(struct board_t *brd);
109 static void dgap_poll_handler(ulong dummy);
110 static int dgap_init_pci(void);
111 static int dgap_init_one(struct pci_dev *pdev, const struct pci_device_id *ent);
112 static void dgap_remove_one(struct pci_dev *dev);
113 static int dgap_probe1(struct pci_dev *pdev, int card_type);
114 static int dgap_do_remap(struct board_t *brd);
115 static irqreturn_t dgap_intr(int irq, void *voidbrd);
117 /* Our function prototypes */
118 static int dgap_tty_open(struct tty_struct *tty, struct file *file);
119 static void dgap_tty_close(struct tty_struct *tty, struct file *file);
120 static int dgap_block_til_ready(struct tty_struct *tty, struct file *file, struct channel_t *ch);
121 static int dgap_tty_ioctl(struct tty_struct *tty, unsigned int cmd, unsigned long arg);
122 static int dgap_tty_digigeta(struct tty_struct *tty, struct digi_t __user *retinfo);
123 static int dgap_tty_digiseta(struct tty_struct *tty, struct digi_t __user *new_info);
124 static int dgap_tty_digigetedelay(struct tty_struct *tty, int __user *retinfo);
125 static int dgap_tty_digisetedelay(struct tty_struct *tty, int __user *new_info);
126 static int dgap_tty_write_room(struct tty_struct *tty);
127 static int dgap_tty_chars_in_buffer(struct tty_struct *tty);
128 static void dgap_tty_start(struct tty_struct *tty);
129 static void dgap_tty_stop(struct tty_struct *tty);
130 static void dgap_tty_throttle(struct tty_struct *tty);
131 static void dgap_tty_unthrottle(struct tty_struct *tty);
132 static void dgap_tty_flush_chars(struct tty_struct *tty);
133 static void dgap_tty_flush_buffer(struct tty_struct *tty);
134 static void dgap_tty_hangup(struct tty_struct *tty);
135 static int dgap_wait_for_drain(struct tty_struct *tty);
136 static int dgap_set_modem_info(struct tty_struct *tty, unsigned int command, unsigned int __user *value);
137 static int dgap_get_modem_info(struct channel_t *ch, unsigned int __user *value);
138 static int dgap_tty_digisetcustombaud(struct tty_struct *tty, int __user *new_info);
139 static int dgap_tty_digigetcustombaud(struct tty_struct *tty, int __user *retinfo);
140 static int dgap_tty_tiocmget(struct tty_struct *tty);
141 static int dgap_tty_tiocmset(struct tty_struct *tty, unsigned int set, unsigned int clear);
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, int count);
145 static void dgap_tty_set_termios(struct tty_struct *tty, struct ktermios *old_termios);
146 static int dgap_tty_put_char(struct tty_struct *tty, unsigned char c);
147 static void dgap_tty_send_xchar(struct tty_struct *tty, char ch);
149 static int dgap_tty_register(struct board_t *brd);
150 static int dgap_tty_preinit(void);
151 static int dgap_tty_init(struct board_t *);
152 static void dgap_tty_post_uninit(void);
153 static void dgap_tty_uninit(struct board_t *);
154 static void dgap_carrier(struct channel_t *ch);
155 static void dgap_input(struct channel_t *ch);
158 * Our function prototypes from dgap_fep5
160 static void dgap_cmdw_ext(struct channel_t *ch, u16 cmd, u16 word, uint ncmds);
161 static int dgap_event(struct board_t *bd);
163 static void dgap_poll_tasklet(unsigned long data);
164 static void dgap_cmdb(struct channel_t *ch, uchar cmd, uchar byte1, uchar byte2, uint ncmds);
165 static void dgap_cmdw(struct channel_t *ch, uchar cmd, u16 word, uint ncmds);
166 static void dgap_wmove(struct channel_t *ch, char *buf, uint cnt);
167 static int dgap_param(struct tty_struct *tty);
168 static void dgap_parity_scan(struct channel_t *ch, unsigned char *cbuf, unsigned char *fbuf, int *len);
169 static uint dgap_get_custom_baud(struct channel_t *ch);
170 static void dgap_firmware_reset_port(struct channel_t *ch);
173 * Function prototypes from dgap_parse.c.
175 static int dgap_gettok(char **in, struct cnode *p);
176 static char *dgap_getword(char **in);
177 static char *dgap_savestring(char *s);
178 static struct cnode *dgap_newnode(int t);
179 static int dgap_checknode(struct cnode *p);
180 static void dgap_err(char *s);
183 * Function prototypes from dgap_sysfs.h
191 static void dgap_create_ports_sysfiles(struct board_t *bd);
192 static void dgap_remove_ports_sysfiles(struct board_t *bd);
194 static void dgap_create_driver_sysfiles(struct pci_driver *);
195 static void dgap_remove_driver_sysfiles(struct pci_driver *);
197 static void dgap_create_tty_sysfs(struct un_t *un, struct device *c);
198 static void dgap_remove_tty_sysfs(struct device *c);
201 * Function prototypes from dgap_parse.h
203 static int dgap_parsefile(char **in, int Remove);
204 static struct cnode *dgap_find_config(int type, int bus, int slot);
205 static uint dgap_config_get_number_of_ports(struct board_t *bd);
206 static char *dgap_create_config_string(struct board_t *bd, char *string);
207 static uint dgap_config_get_useintr(struct board_t *bd);
208 static uint dgap_config_get_altpin(struct board_t *bd);
210 static int dgap_ms_sleep(ulong ms);
211 static void dgap_do_bios_load(struct board_t *brd, uchar __user *ubios, int len);
212 static void dgap_do_fep_load(struct board_t *brd, uchar __user *ufep, int len);
213 #ifdef DIGI_CONCENTRATORS_SUPPORTED
214 static void dgap_do_conc_load(struct board_t *brd, uchar *uaddr, int len);
216 static int dgap_after_config_loaded(int board);
217 static int dgap_finalize_board_init(struct board_t *brd);
219 static void dgap_get_vpd(struct board_t *brd);
220 static void dgap_do_reset_board(struct board_t *brd);
221 static void dgap_do_wait_for_bios(struct board_t *brd);
222 static void dgap_do_wait_for_fep(struct board_t *brd);
223 static int dgap_tty_register_ports(struct board_t *brd);
224 static int dgap_firmware_load(struct pci_dev *pdev, int card_type);
226 /* Driver load/unload functions */
227 int dgap_init_module(void);
228 void dgap_cleanup_module(void);
230 module_init(dgap_init_module);
231 module_exit(dgap_cleanup_module);
234 * File operations permitted on Control/Management major.
236 static const struct file_operations DgapBoardFops = {
237 .owner = THIS_MODULE,
243 static uint dgap_NumBoards;
244 static struct board_t *dgap_Board[MAXBOARDS];
245 DEFINE_SPINLOCK(dgap_global_lock);
246 static ulong dgap_poll_counter;
247 static char *dgap_config_buf;
248 static int dgap_driver_state = DRIVER_INITIALIZED;
249 DEFINE_SPINLOCK(dgap_dl_lock);
250 static wait_queue_head_t dgap_dl_wait;
251 static int dgap_dl_action;
252 static int dgap_poll_tick = 20; /* Poll interval - 20 ms */
257 static int dgap_Major_Control_Registered = FALSE;
258 static uint dgap_driver_start = FALSE;
260 static struct class *dgap_class;
262 static struct board_t *dgap_BoardsByMajor[256];
263 static uchar *dgap_TmpWriteBuf = NULL;
264 DECLARE_MUTEX(dgap_TmpWriteSem);
265 static uint dgap_count = 500;
270 DEFINE_SPINLOCK(dgap_poll_lock); /* Poll scheduling lock */
271 static ulong dgap_poll_time; /* Time of next poll */
272 static uint dgap_poll_stop; /* Used to tell poller to stop */
273 static struct timer_list dgap_poll_timer;
278 Card Model Number of Ports Interface
279 ----------------------------------------------------------------
280 Acceleport Xem 4 - 64 (EIA232 & EIA422)
281 Acceleport Xr 4 & 8 (EIA232)
282 Acceleport Xr 920 4 & 8 (EIA232)
283 Acceleport C/X 8 - 128 (EIA232)
284 Acceleport EPC/X 8 - 224 (EIA232)
285 Acceleport Xr/422 4 & 8 (EIA422)
286 Acceleport 2r/920 2 (EIA232)
287 Acceleport 4r/920 4 (EIA232)
288 Acceleport 8r/920 8 (EIA232)
290 IBM 8-Port Asynchronous PCI Adapter (EIA232)
291 IBM 128-Port Asynchronous PCI Adapter (EIA232 & EIA422)
294 static struct pci_device_id dgap_pci_tbl[] = {
295 { DIGI_VID, PCI_DEVICE_XEM_DID, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0 },
296 { DIGI_VID, PCI_DEVICE_CX_DID, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 1 },
297 { DIGI_VID, PCI_DEVICE_CX_IBM_DID, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 2 },
298 { DIGI_VID, PCI_DEVICE_EPCJ_DID, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 3 },
299 { DIGI_VID, PCI_DEVICE_920_2_DID, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 4 },
300 { DIGI_VID, PCI_DEVICE_920_4_DID, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 5 },
301 { DIGI_VID, PCI_DEVICE_920_8_DID, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 6 },
302 { DIGI_VID, PCI_DEVICE_XR_DID, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 7 },
303 { DIGI_VID, PCI_DEVICE_XRJ_DID, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 8 },
304 { DIGI_VID, PCI_DEVICE_XR_422_DID, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 9 },
305 { DIGI_VID, PCI_DEVICE_XR_IBM_DID, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 10 },
306 { DIGI_VID, PCI_DEVICE_XR_SAIP_DID, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 11 },
307 { DIGI_VID, PCI_DEVICE_XR_BULL_DID, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 12 },
308 { DIGI_VID, PCI_DEVICE_920_8_HP_DID, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 13 },
309 { DIGI_VID, PCI_DEVICE_XEM_HP_DID, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 14 },
310 {0,} /* 0 terminated list. */
312 MODULE_DEVICE_TABLE(pci, dgap_pci_tbl);
315 * A generic list of Product names, PCI Vendor ID, and PCI Device ID.
324 static struct board_id dgap_Ids[] = {
325 { PPCM, PCI_DEVICE_XEM_NAME, 64, (T_PCXM | T_PCLITE | T_PCIBUS) },
326 { PCX, PCI_DEVICE_CX_NAME, 128, (T_CX | T_PCIBUS) },
327 { PCX, PCI_DEVICE_CX_IBM_NAME, 128, (T_CX | T_PCIBUS) },
328 { PEPC, PCI_DEVICE_EPCJ_NAME, 224, (T_EPC | T_PCIBUS) },
329 { APORT2_920P, PCI_DEVICE_920_2_NAME, 2, (T_PCXR | T_PCLITE | T_PCIBUS) },
330 { APORT4_920P, PCI_DEVICE_920_4_NAME, 4, (T_PCXR | T_PCLITE | T_PCIBUS) },
331 { APORT8_920P, PCI_DEVICE_920_8_NAME, 8, (T_PCXR | T_PCLITE | T_PCIBUS) },
332 { PAPORT8, PCI_DEVICE_XR_NAME, 8, (T_PCXR | T_PCLITE | T_PCIBUS) },
333 { PAPORT8, PCI_DEVICE_XRJ_NAME, 8, (T_PCXR | T_PCLITE | T_PCIBUS) },
334 { PAPORT8, PCI_DEVICE_XR_422_NAME, 8, (T_PCXR | T_PCLITE | T_PCIBUS) },
335 { PAPORT8, PCI_DEVICE_XR_IBM_NAME, 8, (T_PCXR | T_PCLITE | T_PCIBUS) },
336 { PAPORT8, PCI_DEVICE_XR_SAIP_NAME, 8, (T_PCXR | T_PCLITE | T_PCIBUS) },
337 { PAPORT8, PCI_DEVICE_XR_BULL_NAME, 8, (T_PCXR | T_PCLITE | T_PCIBUS) },
338 { APORT8_920P, PCI_DEVICE_920_8_HP_NAME, 8, (T_PCXR | T_PCLITE | T_PCIBUS) },
339 { PPCM, PCI_DEVICE_XEM_HP_NAME, 64, (T_PCXM | T_PCLITE | T_PCIBUS) },
340 {0,} /* 0 terminated list. */
343 static struct pci_driver dgap_driver = {
345 .probe = dgap_init_one,
346 .id_table = dgap_pci_tbl,
347 .remove = dgap_remove_one,
350 struct firmware_info {
351 uchar *conf_name; /* dgap.conf */
352 uchar *bios_name; /* BIOS filename */
353 uchar *fep_name; /* FEP filename */
354 uchar *con_name; /* Concentrator filename FIXME*/
355 int num; /* sequence number */
359 * Firmware - BIOS, FEP, and CONC filenames
361 static struct firmware_info fw_info[] = {
362 { "dgap/dgap.conf", "dgap/sxbios.bin", "dgap/sxfep.bin", 0, 0 },
363 { "dgap/dgap.conf", "dgap/cxpbios.bin", "dgap/cxpfep.bin", 0, 1 },
364 { "dgap/dgap.conf", "dgap/cxpbios.bin", "dgap/cxpfep.bin", 0, 2 },
365 { "dgap/dgap.conf", "dgap/pcibios.bin", "dgap/pcifep.bin", 0, 3 },
366 { "dgap/dgap.conf", "dgap/xrbios.bin", "dgap/xrfep.bin", 0, 4 },
367 { "dgap/dgap.conf", "dgap/xrbios.bin", "dgap/xrfep.bin", 0, 5 },
368 { "dgap/dgap.conf", "dgap/xrbios.bin", "dgap/xrfep.bin", 0, 6 },
369 { "dgap/dgap.conf", "dgap/xrbios.bin", "dgap/xrfep.bin", 0, 7 },
370 { "dgap/dgap.conf", "dgap/xrbios.bin", "dgap/xrfep.bin", 0, 8 },
371 { "dgap/dgap.conf", "dgap/xrbios.bin", "dgap/xrfep.bin", 0, 9 },
372 { "dgap/dgap.conf", "dgap/xrbios.bin", "dgap/xrfep.bin", 0, 10 },
373 { "dgap/dgap.conf", "dgap/xrbios.bin", "dgap/xrfep.bin", 0, 11 },
374 { "dgap/dgap.conf", "dgap/xrbios.bin", "dgap/xrfep.bin", 0, 12 },
375 { "dgap/dgap.conf", "dgap/xrbios.bin", "dgap/xrfep.bin", 0, 13 },
376 { "dgap/dgap.conf", "dgap/sxbios.bin", "dgap/sxfep.bin", 0, 14 },
380 static char *dgap_driver_state_text[] = {
381 "Driver Initialized",
382 "Driver needs configuration load.",
383 "Driver requested configuration from download daemon.",
388 * Default transparent print information.
390 static struct digi_t dgap_digi_init = {
391 .digi_flags = DIGI_COOK, /* Flags */
392 .digi_maxcps = 100, /* Max CPS */
393 .digi_maxchar = 50, /* Max chars in print queue */
394 .digi_bufsize = 100, /* Printer buffer size */
395 .digi_onlen = 4, /* size of printer on string */
396 .digi_offlen = 4, /* size of printer off string */
397 .digi_onstr = "\033[5i", /* ANSI printer on string ] */
398 .digi_offstr = "\033[4i", /* ANSI printer off string ] */
399 .digi_term = "ansi" /* default terminal type */
403 * Define a local default termios struct. All ports will be created
404 * with this termios initially.
406 * This defines a raw port at 9600 baud, 8 data bits, no parity,
410 static struct ktermios DgapDefaultTermios = {
411 .c_iflag = (DEFAULT_IFLAGS), /* iflags */
412 .c_oflag = (DEFAULT_OFLAGS), /* oflags */
413 .c_cflag = (DEFAULT_CFLAGS), /* cflags */
414 .c_lflag = (DEFAULT_LFLAGS), /* lflags */
419 static const struct tty_operations dgap_tty_ops = {
420 .open = dgap_tty_open,
421 .close = dgap_tty_close,
422 .write = dgap_tty_write,
423 .write_room = dgap_tty_write_room,
424 .flush_buffer = dgap_tty_flush_buffer,
425 .chars_in_buffer = dgap_tty_chars_in_buffer,
426 .flush_chars = dgap_tty_flush_chars,
427 .ioctl = dgap_tty_ioctl,
428 .set_termios = dgap_tty_set_termios,
429 .stop = dgap_tty_stop,
430 .start = dgap_tty_start,
431 .throttle = dgap_tty_throttle,
432 .unthrottle = dgap_tty_unthrottle,
433 .hangup = dgap_tty_hangup,
434 .put_char = dgap_tty_put_char,
435 .tiocmget = dgap_tty_tiocmget,
436 .tiocmset = dgap_tty_tiocmset,
437 .break_ctl = dgap_tty_send_break,
438 .wait_until_sent = dgap_tty_wait_until_sent,
439 .send_xchar = dgap_tty_send_xchar
443 * Our needed internal static variables from dgap_parse.c
445 static struct cnode dgap_head;
447 static char dgap_cword[MAXCWORD];
454 static struct toklist dgap_tlist[] = {
455 { BEGIN, "config_begin" },
456 { END, "config_end" },
458 { PCX, "Digi_AccelePort_C/X_PCI" }, /* C/X_PCI */
459 { PEPC, "Digi_AccelePort_EPC/X_PCI" }, /* EPC/X_PCI */
460 { PPCM, "Digi_AccelePort_Xem_PCI" }, /* PCI/Xem */
461 { APORT2_920P, "Digi_AccelePort_2r_920_PCI" },
462 { APORT4_920P, "Digi_AccelePort_4r_920_PCI" },
463 { APORT8_920P, "Digi_AccelePort_8r_920_PCI" },
464 { PAPORT4, "Digi_AccelePort_4r_PCI(EIA-232/RS-422)" },
465 { PAPORT8, "Digi_AccelePort_8r_PCI(EIA-232/RS-422)" },
467 { PCIINFO, "pciinfo" },
470 { CONC, "concentrator" },
480 { CONNECT, "connect" },
481 { METHOD, "method" },
482 { STATUS, "status" },
483 { CUSTOM, "Custom" },
489 { NPORTS, "nports" },
494 { ALTPIN, "altpin" },
495 { USEINTR, "useintr" },
496 { TTSIZ, "ttysize" },
498 { BSSIZ, "boardsize" },
499 { UNTSIZ, "schedsize" },
500 { F2SIZ, "f2200size" },
501 { VPSIZ, "vpixsize" },
505 /************************************************************************
507 * Driver load/unload functions
509 ************************************************************************/
514 * Module load. This is where it all starts.
516 int dgap_init_module(void)
520 pr_info("%s, Digi International Part Number %s\n", DG_NAME, DG_PART);
522 dgap_driver_state = DRIVER_NEED_CONFIG_LOAD;
525 * Initialize global stuff
533 * Find and configure all the cards
535 rc = dgap_init_pci();
538 * If something went wrong in the scan, bail out of driver.
541 /* Only unregister the pci driver if it was actually registered. */
543 pci_unregister_driver(&dgap_driver);
545 printk("WARNING: dgap driver load failed. No DGAP boards found.\n");
547 dgap_cleanup_module();
549 dgap_create_driver_sysfiles(&dgap_driver);
550 dgap_driver_state = DRIVER_READY;
559 static int dgap_start(void)
564 if (dgap_driver_start == FALSE) {
566 dgap_driver_start = TRUE;
569 * make sure that the globals are
570 * init'd before we do anything else
576 pr_info("For the tools package please visit http://www.digi.com\n");
579 * Register our base character device into the kernel.
580 * This allows the download daemon to connect to the downld device
581 * before any of the boards are init'ed.
583 if (!dgap_Major_Control_Registered) {
585 * Register management/dpa devices
587 rc = register_chrdev(DIGI_DGAP_MAJOR, "dgap", &DgapBoardFops);
591 dgap_class = class_create(THIS_MODULE, "dgap_mgmt");
592 device_create(dgap_class, NULL,
593 MKDEV(DIGI_DGAP_MAJOR, 0),
595 dgap_Major_Control_Registered = TRUE;
599 * Init any global tty stuff.
601 rc = dgap_tty_preinit();
606 /* Start the poller */
607 DGAP_LOCK(dgap_poll_lock, flags);
608 init_timer(&dgap_poll_timer);
609 dgap_poll_timer.function = dgap_poll_handler;
610 dgap_poll_timer.data = 0;
611 dgap_poll_time = jiffies + dgap_jiffies_from_ms(dgap_poll_tick);
612 dgap_poll_timer.expires = dgap_poll_time;
613 DGAP_UNLOCK(dgap_poll_lock, flags);
615 add_timer(&dgap_poll_timer);
617 dgap_driver_state = DRIVER_NEED_CONFIG_LOAD;
624 * Register pci driver, and return how many boards we have.
626 static int dgap_init_pci(void)
628 return pci_register_driver(&dgap_driver);
631 /* returns count (>= 0), or negative on error */
632 static int dgap_init_one(struct pci_dev *pdev, const struct pci_device_id *ent)
636 /* wake up and enable device */
637 rc = pci_enable_device(pdev);
642 rc = dgap_probe1(pdev, ent->driver_data);
645 rc = dgap_firmware_load(pdev, ent->driver_data);
651 static int dgap_probe1(struct pci_dev *pdev, int card_type)
653 return dgap_found_board(pdev, card_type);
656 static void dgap_remove_one(struct pci_dev *dev)
662 * dgap_cleanup_module()
664 * Module unload. This is where it all ends.
666 void dgap_cleanup_module(void)
671 DGAP_LOCK(dgap_poll_lock, lock_flags);
673 DGAP_UNLOCK(dgap_poll_lock, lock_flags);
675 /* Turn off poller right away. */
676 del_timer_sync(&dgap_poll_timer);
678 dgap_remove_driver_sysfiles(&dgap_driver);
681 if (dgap_Major_Control_Registered) {
682 device_destroy(dgap_class, MKDEV(DIGI_DGAP_MAJOR, 0));
683 device_destroy(dgap_class, MKDEV(DIGI_DGAP_MAJOR, 1));
684 class_destroy(dgap_class);
685 unregister_chrdev(DIGI_DGAP_MAJOR, "dgap");
688 kfree(dgap_config_buf);
690 for (i = 0; i < dgap_NumBoards; ++i) {
691 dgap_remove_ports_sysfiles(dgap_Board[i]);
692 dgap_tty_uninit(dgap_Board[i]);
693 dgap_cleanup_board(dgap_Board[i]);
696 dgap_tty_post_uninit();
698 #if defined(DGAP_TRACER)
699 /* last thing, make sure we release the tracebuffer */
703 pci_unregister_driver(&dgap_driver);
707 * dgap_cleanup_board()
709 * Free all the memory associated with a board
711 static void dgap_cleanup_board(struct board_t *brd)
715 if (!brd || brd->magic != DGAP_BOARD_MAGIC)
718 if (brd->intr_used && brd->irq)
719 free_irq(brd->irq, brd);
721 tasklet_kill(&brd->helper_tasklet);
723 if (brd->re_map_port) {
724 release_mem_region(brd->membase + 0x200000, 0x200000);
725 iounmap(brd->re_map_port);
726 brd->re_map_port = NULL;
729 if (brd->re_map_membase) {
730 release_mem_region(brd->membase, 0x200000);
731 iounmap(brd->re_map_membase);
732 brd->re_map_membase = NULL;
735 if (brd->msgbuf_head) {
738 DGAP_LOCK(dgap_global_lock, flags);
740 printk("%s", brd->msgbuf_head);
741 kfree(brd->msgbuf_head);
742 brd->msgbuf_head = NULL;
743 DGAP_UNLOCK(dgap_global_lock, flags);
746 /* Free all allocated channels structs */
747 for (i = 0; i < MAXPORTS ; i++) {
748 if (brd->channels[i]) {
749 kfree(brd->channels[i]);
750 brd->channels[i] = NULL;
755 kfree(brd->flipflagbuf);
757 dgap_Board[brd->boardnum] = NULL;
765 * A board has been found, init it.
767 static int dgap_found_board(struct pci_dev *pdev, int id)
770 unsigned int pci_irq;
774 /* get the board structure and prep it */
775 brd = dgap_Board[dgap_NumBoards] =
776 (struct board_t *) kzalloc(sizeof(struct board_t), GFP_KERNEL);
780 /* make a temporary message buffer for the boot messages */
781 brd->msgbuf = brd->msgbuf_head =
782 (char *) kzalloc(sizeof(char) * 8192, GFP_KERNEL);
788 /* store the info for the board we've found */
789 brd->magic = DGAP_BOARD_MAGIC;
790 brd->boardnum = dgap_NumBoards;
792 brd->vendor = dgap_pci_tbl[id].vendor;
793 brd->device = dgap_pci_tbl[id].device;
795 brd->pci_bus = pdev->bus->number;
796 brd->pci_slot = PCI_SLOT(pdev->devfn);
797 brd->name = dgap_Ids[id].name;
798 brd->maxports = dgap_Ids[id].maxports;
799 brd->type = dgap_Ids[id].config_type;
800 brd->dpatype = dgap_Ids[id].dpatype;
801 brd->dpastatus = BD_NOFEP;
802 init_waitqueue_head(&brd->state_wait);
804 DGAP_SPINLOCK_INIT(brd->bd_lock);
806 brd->state = BOARD_FOUND;
808 brd->inhibit_poller = FALSE;
809 brd->wait_for_bios = 0;
810 brd->wait_for_fep = 0;
812 for (i = 0; i < MAXPORTS; i++)
813 brd->channels[i] = NULL;
815 /* store which card & revision we have */
816 pci_read_config_word(pdev, PCI_SUBSYSTEM_VENDOR_ID, &brd->subvendor);
817 pci_read_config_word(pdev, PCI_SUBSYSTEM_ID, &brd->subdevice);
818 pci_read_config_byte(pdev, PCI_REVISION_ID, &brd->rev);
823 /* get the PCI Base Address Registers */
825 /* Xr Jupiter and EPC use BAR 2 */
826 if (brd->device == PCI_DEVICE_XRJ_DID || brd->device == PCI_DEVICE_EPCJ_DID) {
827 brd->membase = pci_resource_start(pdev, 2);
828 brd->membase_end = pci_resource_end(pdev, 2);
830 /* Everyone else uses BAR 0 */
832 brd->membase = pci_resource_start(pdev, 0);
833 brd->membase_end = pci_resource_end(pdev, 0);
839 if (brd->membase & 1)
845 * On the PCI boards, there is no IO space allocated
846 * The I/O registers will be in the first 3 bytes of the
847 * upper 2MB of the 4MB memory space. The board memory
848 * will be mapped into the low 2MB of the 4MB memory space
850 brd->port = brd->membase + PCI_IO_OFFSET;
851 brd->port_end = brd->port + PCI_IO_SIZE;
854 * Special initialization for non-PLX boards
856 if (brd->device != PCI_DEVICE_XRJ_DID && brd->device != PCI_DEVICE_EPCJ_DID) {
859 pci_write_config_byte(pdev, 0x40, 0);
860 pci_write_config_byte(pdev, 0x46, 0);
862 /* Limit burst length to 2 doubleword transactions */
863 pci_write_config_byte(pdev, 0x42, 1);
866 * Enable IO and mem if not already done.
867 * This was needed for support on Itanium.
869 pci_read_config_word(pdev, PCI_COMMAND, &cmd);
870 cmd |= (PCI_COMMAND_IO | PCI_COMMAND_MEMORY);
871 pci_write_config_word(pdev, PCI_COMMAND, cmd);
874 /* init our poll helper tasklet */
875 tasklet_init(&brd->helper_tasklet, dgap_poll_tasklet, (unsigned long) brd);
877 DGAP_LOCK(dgap_global_lock, flags);
879 printk("%s", brd->msgbuf_head);
880 kfree(brd->msgbuf_head);
881 brd->msgbuf_head = NULL;
882 DGAP_UNLOCK(dgap_global_lock, flags);
884 i = dgap_do_remap(brd);
886 brd->state = BOARD_FAILED;
888 brd->state = NEED_RESET;
894 static int dgap_finalize_board_init(struct board_t *brd)
898 if (!brd || brd->magic != DGAP_BOARD_MAGIC)
901 brd->use_interrupts = dgap_config_get_useintr(brd);
904 * Set up our interrupt handler if we are set to do interrupts.
906 if (brd->use_interrupts && brd->irq) {
908 rc = request_irq(brd->irq, dgap_intr, IRQF_SHARED, "DGAP", brd);
921 static int dgap_firmware_load(struct pci_dev *pdev, int card_type)
923 struct board_t *brd = dgap_Board[dgap_NumBoards - 1];
924 const struct firmware *fw;
928 dgap_do_reset_board(brd);
930 if ((fw_info[card_type].conf_name) &&
931 (dgap_driver_state == DRIVER_NEED_CONFIG_LOAD)) {
932 ret = request_firmware(&fw, fw_info[card_type].conf_name,
935 pr_err("dgap: config file %s not found\n",
936 fw_info[card_type].conf_name);
939 if (!dgap_config_buf) {
940 dgap_config_buf = kmalloc(fw->size + 1, GFP_ATOMIC);
941 if (!dgap_config_buf) {
942 release_firmware(fw);
947 memcpy(dgap_config_buf, fw->data, fw->size);
948 release_firmware(fw);
949 dgap_config_buf[fw->size + 1] = '\0';
951 if (dgap_parsefile(&dgap_config_buf, TRUE) != 0)
954 dgap_driver_state = -1;
957 ret = dgap_after_config_loaded(brd->boardnum);
961 * Match this board to a config the user created for us.
964 dgap_find_config(brd->type, brd->pci_bus, brd->pci_slot);
967 * Because the 4 port Xr products share the same PCI ID
968 * as the 8 port Xr products, if we receive a NULL config
969 * back, and this is a PAPORT8 board, retry with a
970 * PAPORT4 attempt as well.
972 if (brd->type == PAPORT8 && !brd->bd_config)
974 dgap_find_config(PAPORT4, brd->pci_bus, brd->pci_slot);
976 if (!brd->bd_config) {
977 pr_err("dgap: No valid configuration found\n");
981 dgap_tty_register(brd);
982 dgap_finalize_board_init(brd);
984 if (fw_info[card_type].bios_name) {
985 ret = request_firmware(&fw, fw_info[card_type].bios_name,
988 pr_err("dgap: bios file %s not found\n",
989 fw_info[card_type].bios_name);
992 dgap_do_bios_load(brd, (char *)fw->data, fw->size);
993 release_firmware(fw);
995 /* Wait for BIOS to test board... */
996 dgap_do_wait_for_bios(brd);
998 if (brd->state != FINISHED_BIOS_LOAD)
1002 if (fw_info[card_type].fep_name) {
1003 ret = request_firmware(&fw, fw_info[card_type].fep_name,
1006 pr_err("dgap: fep file %s not found\n",
1007 fw_info[card_type].fep_name);
1010 dgap_do_fep_load(brd, (char *)fw->data, fw->size);
1011 release_firmware(fw);
1013 /* Wait for FEP to load on board... */
1014 dgap_do_wait_for_fep(brd);
1016 if (brd->state != FINISHED_FEP_LOAD)
1020 #ifdef DIGI_CONCENTRATORS_SUPPORTED
1022 * If this is a CX or EPCX, we need to see if the firmware
1023 * is requesting a concentrator image from us.
1025 if ((bd->type == PCX) || (bd->type == PEPC)) {
1026 chk_addr = (u16 *) (vaddr + DOWNREQ);
1027 /* Nonzero if FEP is requesting concentrator image. */
1028 check = readw(chk_addr);
1029 vaddr = brd->re_map_membase;
1032 if (fw_info[card_type].con_name && check && vaddr) {
1033 ret = request_firmware(&fw, fw_info[card_type].con_name,
1036 pr_err("dgap: conc file %s not found\n",
1037 fw_info[card_type].con_name);
1040 /* Put concentrator firmware loading code here */
1041 offset = readw((u16 *) (vaddr + DOWNREQ));
1042 memcpy_toio(offset, fw->data, fw->size);
1044 dgap_do_conc_load(brd, (char *)fw->data, fw->size)
1045 release_firmware(fw);
1049 * Do tty device initialization.
1051 ret = dgap_tty_init(brd);
1053 dgap_tty_uninit(brd);
1057 ret = dgap_tty_register_ports(brd);
1061 brd->state = BOARD_READY;
1062 brd->dpastatus = BD_RUNNING;
1070 static int dgap_do_remap(struct board_t *brd)
1072 if (!brd || brd->magic != DGAP_BOARD_MAGIC)
1075 if (!request_mem_region(brd->membase, 0x200000, "dgap"))
1078 if (!request_mem_region(brd->membase + PCI_IO_OFFSET, 0x200000, "dgap")) {
1079 release_mem_region(brd->membase, 0x200000);
1083 brd->re_map_membase = ioremap(brd->membase, 0x200000);
1084 if (!brd->re_map_membase) {
1085 release_mem_region(brd->membase, 0x200000);
1086 release_mem_region(brd->membase + PCI_IO_OFFSET, 0x200000);
1090 brd->re_map_port = ioremap((brd->membase + PCI_IO_OFFSET), 0x200000);
1091 if (!brd->re_map_port) {
1092 release_mem_region(brd->membase, 0x200000);
1093 release_mem_region(brd->membase + PCI_IO_OFFSET, 0x200000);
1094 iounmap(brd->re_map_membase);
1101 /*****************************************************************************
1121 * As each timer expires, it determines (a) whether the "transmit"
1122 * waiter needs to be woken up, and (b) whether the poller needs to
1125 ******************************************************************************/
1127 static void dgap_poll_handler(ulong dummy)
1130 struct board_t *brd;
1131 unsigned long lock_flags;
1134 dgap_poll_counter++;
1137 * Do not start the board state machine until
1138 * driver tells us its up and running, and has
1139 * everything it needs.
1141 if (dgap_driver_state != DRIVER_READY)
1142 goto schedule_poller;
1145 * If we have just 1 board, or the system is not SMP,
1146 * then use the typical old style poller.
1147 * Otherwise, use our new tasklet based poller, which should
1148 * speed things up for multiple boards.
1150 if ((dgap_NumBoards == 1) || (num_online_cpus() <= 1)) {
1151 for (i = 0; i < dgap_NumBoards; i++) {
1153 brd = dgap_Board[i];
1155 if (brd->state == BOARD_FAILED)
1157 if (!brd->intr_running)
1158 /* Call the real board poller directly */
1159 dgap_poll_tasklet((unsigned long) brd);
1162 /* Go thru each board, kicking off a tasklet for each if needed */
1163 for (i = 0; i < dgap_NumBoards; i++) {
1164 brd = dgap_Board[i];
1167 * Attempt to grab the board lock.
1169 * If we can't get it, no big deal, the next poll will get it.
1170 * Basically, I just really don't want to spin in here, because I want
1171 * to kick off my tasklets as fast as I can, and then get out the poller.
1173 if (!spin_trylock(&brd->bd_lock))
1176 /* If board is in a failed state, don't bother scheduling a tasklet */
1177 if (brd->state == BOARD_FAILED) {
1178 spin_unlock(&brd->bd_lock);
1182 /* Schedule a poll helper task */
1183 if (!brd->intr_running)
1184 tasklet_schedule(&brd->helper_tasklet);
1187 * Can't do DGAP_UNLOCK here, as we don't have
1188 * lock_flags because we did a trylock above.
1190 spin_unlock(&brd->bd_lock);
1197 * Schedule ourself back at the nominal wakeup interval.
1199 DGAP_LOCK(dgap_poll_lock, lock_flags);
1200 dgap_poll_time += dgap_jiffies_from_ms(dgap_poll_tick);
1202 new_time = dgap_poll_time - jiffies;
1204 if ((ulong) new_time >= 2 * dgap_poll_tick)
1205 dgap_poll_time = jiffies + dgap_jiffies_from_ms(dgap_poll_tick);
1207 dgap_poll_timer.function = dgap_poll_handler;
1208 dgap_poll_timer.data = 0;
1209 dgap_poll_timer.expires = dgap_poll_time;
1210 DGAP_UNLOCK(dgap_poll_lock, lock_flags);
1212 if (!dgap_poll_stop)
1213 add_timer(&dgap_poll_timer);
1219 * Driver interrupt handler.
1221 static irqreturn_t dgap_intr(int irq, void *voidbrd)
1223 struct board_t *brd = (struct board_t *) voidbrd;
1229 * Check to make sure its for us.
1231 if (brd->magic != DGAP_BOARD_MAGIC)
1237 * Schedule tasklet to run at a better time.
1239 tasklet_schedule(&brd->helper_tasklet);
1244 * dgap_init_globals()
1246 * This is where we initialize the globals from the static insmod
1247 * configuration variables. These are declared near the head of
1250 static void dgap_init_globals(void)
1254 dgap_rawreadok = rawreadok;
1256 for (i = 0; i < MAXBOARDS; i++)
1257 dgap_Board[i] = NULL;
1259 init_timer(&dgap_poll_timer);
1261 init_waitqueue_head(&dgap_dl_wait);
1265 /************************************************************************
1269 ************************************************************************/
1274 * Put the driver to sleep for x ms's
1276 * Returns 0 if timed out, !0 (showing signal) if interrupted by a signal.
1278 static int dgap_ms_sleep(ulong ms)
1280 current->state = TASK_INTERRUPTIBLE;
1281 schedule_timeout((ms * HZ) / 1000);
1282 return signal_pending(current);
1285 /************************************************************************
1287 * TTY Initialization/Cleanup Functions
1289 ************************************************************************/
1292 * dgap_tty_preinit()
1294 * Initialize any global tty related data before we download any boards.
1296 static int dgap_tty_preinit(void)
1298 unsigned long flags;
1300 DGAP_LOCK(dgap_global_lock, flags);
1303 * Allocate a buffer for doing the copy from user space to
1304 * kernel space in dgap_input(). We only use one buffer and
1305 * control access to it with a semaphore. If we are paging, we
1306 * are already in trouble so one buffer won't hurt much anyway.
1308 dgap_TmpWriteBuf = kmalloc(WRITEBUFLEN, GFP_ATOMIC);
1310 if (!dgap_TmpWriteBuf) {
1311 DGAP_UNLOCK(dgap_global_lock, flags);
1315 DGAP_UNLOCK(dgap_global_lock, flags);
1320 * dgap_tty_register()
1322 * Init the tty subsystem for this board.
1324 static int dgap_tty_register(struct board_t *brd)
1328 brd->SerialDriver = alloc_tty_driver(MAXPORTS);
1330 snprintf(brd->SerialName, MAXTTYNAMELEN, "tty_dgap_%d_", brd->boardnum);
1331 brd->SerialDriver->name = brd->SerialName;
1332 brd->SerialDriver->name_base = 0;
1333 brd->SerialDriver->major = 0;
1334 brd->SerialDriver->minor_start = 0;
1335 brd->SerialDriver->type = TTY_DRIVER_TYPE_SERIAL;
1336 brd->SerialDriver->subtype = SERIAL_TYPE_NORMAL;
1337 brd->SerialDriver->init_termios = DgapDefaultTermios;
1338 brd->SerialDriver->driver_name = DRVSTR;
1339 brd->SerialDriver->flags = (TTY_DRIVER_REAL_RAW | TTY_DRIVER_DYNAMIC_DEV | TTY_DRIVER_HARDWARE_BREAK);
1341 /* The kernel wants space to store pointers to tty_structs */
1342 brd->SerialDriver->ttys = kzalloc(MAXPORTS * sizeof(struct tty_struct *), GFP_KERNEL);
1343 if (!brd->SerialDriver->ttys)
1347 * Entry points for driver. Called by the kernel from
1348 * tty_io.c and n_tty.c.
1350 tty_set_operations(brd->SerialDriver, &dgap_tty_ops);
1353 * If we're doing transparent print, we have to do all of the above
1354 * again, separately so we don't get the LD confused about what major
1355 * we are when we get into the dgap_tty_open() routine.
1357 brd->PrintDriver = alloc_tty_driver(MAXPORTS);
1359 snprintf(brd->PrintName, MAXTTYNAMELEN, "pr_dgap_%d_", brd->boardnum);
1360 brd->PrintDriver->name = brd->PrintName;
1361 brd->PrintDriver->name_base = 0;
1362 brd->PrintDriver->major = 0;
1363 brd->PrintDriver->minor_start = 0;
1364 brd->PrintDriver->type = TTY_DRIVER_TYPE_SERIAL;
1365 brd->PrintDriver->subtype = SERIAL_TYPE_NORMAL;
1366 brd->PrintDriver->init_termios = DgapDefaultTermios;
1367 brd->PrintDriver->driver_name = DRVSTR;
1368 brd->PrintDriver->flags = (TTY_DRIVER_REAL_RAW | TTY_DRIVER_DYNAMIC_DEV | TTY_DRIVER_HARDWARE_BREAK);
1370 /* The kernel wants space to store pointers to tty_structs */
1371 brd->PrintDriver->ttys = kzalloc(MAXPORTS * sizeof(struct tty_struct *), GFP_KERNEL);
1372 if (!brd->PrintDriver->ttys)
1376 * Entry points for driver. Called by the kernel from
1377 * tty_io.c and n_tty.c.
1379 tty_set_operations(brd->PrintDriver, &dgap_tty_ops);
1381 if (!brd->dgap_Major_Serial_Registered) {
1382 /* Register tty devices */
1383 rc = tty_register_driver(brd->SerialDriver);
1386 brd->dgap_Major_Serial_Registered = TRUE;
1387 dgap_BoardsByMajor[brd->SerialDriver->major] = brd;
1388 brd->dgap_Serial_Major = brd->SerialDriver->major;
1391 if (!brd->dgap_Major_TransparentPrint_Registered) {
1392 /* Register Transparent Print devices */
1393 rc = tty_register_driver(brd->PrintDriver);
1396 brd->dgap_Major_TransparentPrint_Registered = TRUE;
1397 dgap_BoardsByMajor[brd->PrintDriver->major] = brd;
1398 brd->dgap_TransparentPrint_Major = brd->PrintDriver->major;
1407 * Init the tty subsystem. Called once per board after board has been
1408 * downloaded and init'ed.
1410 static int dgap_tty_init(struct board_t *brd)
1414 uint true_count = 0;
1417 struct channel_t *ch;
1425 * Initialize board structure elements.
1428 vaddr = brd->re_map_membase;
1429 true_count = readw((vaddr + NCHAN));
1431 brd->nasync = dgap_config_get_number_of_ports(brd);
1434 brd->nasync = brd->maxports;
1436 if (brd->nasync > brd->maxports)
1437 brd->nasync = brd->maxports;
1439 if (true_count != brd->nasync) {
1440 if ((brd->type == PPCM) && (true_count == 64))
1441 pr_warn("dgap: %s configured for %d ports, has %d ports.\nPlease make SURE the EBI cable running from the card\nto each EM module is plugged into EBI IN!\n",
1442 brd->name, brd->nasync, true_count);
1443 else if ((brd->type == PPCM) && (true_count == 0))
1444 pr_warn("dgap: %s configured for %d ports, has %d ports.\nPlease make SURE the EBI cable running from the card\nto each EM module is plugged into EBI IN!\n",
1445 brd->name, brd->nasync, true_count);
1447 pr_warn("dgap: %s configured for %d ports, has %d ports.\n",
1448 brd->name, brd->nasync, true_count);
1450 brd->nasync = true_count;
1452 /* If no ports, don't bother going any further */
1454 brd->state = BOARD_FAILED;
1455 brd->dpastatus = BD_NOFEP;
1461 * Allocate channel memory that might not have been allocated
1462 * when the driver was first loaded.
1464 for (i = 0; i < brd->nasync; i++) {
1465 if (!brd->channels[i]) {
1466 brd->channels[i] = kzalloc(sizeof(struct channel_t), GFP_ATOMIC);
1467 if (!brd->channels[i])
1472 ch = brd->channels[0];
1473 vaddr = brd->re_map_membase;
1475 bs = (struct bs_t *) ((ulong) vaddr + CHANBUF);
1476 cm = (struct cm_t *) ((ulong) vaddr + CMDBUF);
1480 /* Set up channel variables */
1481 for (i = 0; i < brd->nasync; i++, ch = brd->channels[i], bs++) {
1483 if (!brd->channels[i])
1486 DGAP_SPINLOCK_INIT(ch->ch_lock);
1488 /* Store all our magic numbers */
1489 ch->magic = DGAP_CHANNEL_MAGIC;
1490 ch->ch_tun.magic = DGAP_UNIT_MAGIC;
1491 ch->ch_tun.un_type = DGAP_SERIAL;
1492 ch->ch_tun.un_ch = ch;
1493 ch->ch_tun.un_dev = i;
1495 ch->ch_pun.magic = DGAP_UNIT_MAGIC;
1496 ch->ch_pun.un_type = DGAP_PRINT;
1497 ch->ch_pun.un_ch = ch;
1498 ch->ch_pun.un_dev = i;
1500 ch->ch_vaddr = vaddr;
1505 ch->ch_digi = dgap_digi_init;
1508 * Set up digi dsr and dcd bits based on altpin flag.
1510 if (dgap_config_get_altpin(brd)) {
1513 ch->ch_digi.digi_flags |= DIGI_ALTPIN;
1516 ch->ch_dsr = DM_DSR;
1519 ch->ch_taddr = vaddr + ((ch->ch_bs->tx_seg) << 4);
1520 ch->ch_raddr = vaddr + ((ch->ch_bs->rx_seg) << 4);
1523 ch->ch_tsize = readw(&(ch->ch_bs->tx_max)) + 1;
1524 ch->ch_rsize = readw(&(ch->ch_bs->rx_max)) + 1;
1528 /* .25 second delay */
1529 ch->ch_close_delay = 250;
1532 * Set queue water marks, interrupt mask,
1533 * and general tty parameters.
1535 ch->ch_tlw = tlw = ch->ch_tsize >= 2000 ? ((ch->ch_tsize * 5) / 8) : ch->ch_tsize / 2;
1537 dgap_cmdw(ch, STLOW, tlw, 0);
1539 dgap_cmdw(ch, SRLOW, ch->ch_rsize / 2, 0);
1541 dgap_cmdw(ch, SRHIGH, 7 * ch->ch_rsize / 8, 0);
1543 ch->ch_mistat = readb(&(ch->ch_bs->m_stat));
1545 init_waitqueue_head(&ch->ch_flags_wait);
1546 init_waitqueue_head(&ch->ch_tun.un_flags_wait);
1547 init_waitqueue_head(&ch->ch_pun.un_flags_wait);
1548 init_waitqueue_head(&ch->ch_sniff_wait);
1550 /* Turn on all modem interrupts for now */
1551 modem = (DM_CD | DM_DSR | DM_CTS | DM_RI);
1552 writeb(modem, &(ch->ch_bs->m_int));
1555 * Set edelay to 0 if interrupts are turned on,
1556 * otherwise set edelay to the usual 100.
1559 writew(0, &(ch->ch_bs->edelay));
1561 writew(100, &(ch->ch_bs->edelay));
1563 writeb(1, &(ch->ch_bs->idata));
1570 * dgap_tty_post_uninit()
1572 * UnInitialize any global tty related data.
1574 static void dgap_tty_post_uninit(void)
1576 kfree(dgap_TmpWriteBuf);
1577 dgap_TmpWriteBuf = NULL;
1583 * Uninitialize the TTY portion of this driver. Free all memory and
1586 static void dgap_tty_uninit(struct board_t *brd)
1590 if (brd->dgap_Major_Serial_Registered) {
1591 dgap_BoardsByMajor[brd->SerialDriver->major] = NULL;
1592 brd->dgap_Serial_Major = 0;
1593 for (i = 0; i < brd->nasync; i++) {
1594 tty_port_destroy(&brd->SerialPorts[i]);
1595 dgap_remove_tty_sysfs(brd->channels[i]->ch_tun.un_sysfs);
1596 tty_unregister_device(brd->SerialDriver, i);
1598 tty_unregister_driver(brd->SerialDriver);
1599 kfree(brd->SerialDriver->ttys);
1600 brd->SerialDriver->ttys = NULL;
1601 put_tty_driver(brd->SerialDriver);
1602 kfree(brd->SerialPorts);
1603 brd->dgap_Major_Serial_Registered = FALSE;
1606 if (brd->dgap_Major_TransparentPrint_Registered) {
1607 dgap_BoardsByMajor[brd->PrintDriver->major] = NULL;
1608 brd->dgap_TransparentPrint_Major = 0;
1609 for (i = 0; i < brd->nasync; i++) {
1610 tty_port_destroy(&brd->PrinterPorts[i]);
1611 dgap_remove_tty_sysfs(brd->channels[i]->ch_pun.un_sysfs);
1612 tty_unregister_device(brd->PrintDriver, i);
1614 tty_unregister_driver(brd->PrintDriver);
1615 kfree(brd->PrintDriver->ttys);
1616 brd->PrintDriver->ttys = NULL;
1617 put_tty_driver(brd->PrintDriver);
1618 kfree(brd->PrinterPorts);
1619 brd->dgap_Major_TransparentPrint_Registered = FALSE;
1623 #define TMPBUFLEN (1024)
1625 * dgap_sniff - Dump data out to the "sniff" buffer if the
1626 * proc sniff file is opened...
1628 static void dgap_sniff_nowait_nolock(struct channel_t *ch, uchar *text, uchar *buf, int len)
1636 char tmpbuf[TMPBUFLEN];
1640 /* Leave if sniff not open */
1641 if (!(ch->ch_sniff_flags & SNIFF_OPEN))
1644 do_gettimeofday(&tv);
1646 /* Create our header for data dump */
1647 p += sprintf(p, "<%ld %ld><%s><", tv.tv_sec, tv.tv_usec, text);
1648 tmpbuflen = p - tmpbuf;
1653 for (i = 0; i < len && tmpbuflen < (TMPBUFLEN - 4); i++) {
1654 p += sprintf(p, "%02x ", *buf);
1656 tmpbuflen = p - tmpbuf;
1659 if (tmpbuflen < (TMPBUFLEN - 4)) {
1661 p += sprintf(p - 1, "%s\n", ">");
1663 p += sprintf(p, "%s\n", ">");
1669 nbuf = strlen(tmpbuf);
1673 * Loop while data remains.
1675 while (nbuf > 0 && ch->ch_sniff_buf) {
1677 * Determine the amount of available space left in the
1678 * buffer. If there's none, wait until some appears.
1680 n = (ch->ch_sniff_out - ch->ch_sniff_in - 1) & SNIFF_MASK;
1683 * If there is no space left to write to in our sniff buffer,
1684 * we have no choice but to drop the data.
1685 * We *cannot* sleep here waiting for space, because this
1686 * function was probably called by the interrupt/timer routines!
1692 * Copy as much data as will fit.
1698 r = SNIFF_MAX - ch->ch_sniff_in;
1701 memcpy(ch->ch_sniff_buf + ch->ch_sniff_in, p, r);
1704 ch->ch_sniff_in = 0;
1709 memcpy(ch->ch_sniff_buf + ch->ch_sniff_in, p, n);
1711 ch->ch_sniff_in += n;
1716 * Wakeup any thread waiting for data
1718 if (ch->ch_sniff_flags & SNIFF_WAIT_DATA) {
1719 ch->ch_sniff_flags &= ~SNIFF_WAIT_DATA;
1720 wake_up_interruptible(&ch->ch_sniff_wait);
1725 * If the user sent us too much data to push into our tmpbuf,
1726 * we need to keep looping around on all the data.
1728 if (too_much_data) {
1733 } while (too_much_data);
1736 /*=======================================================================
1738 * dgap_input - Process received data.
1740 * ch - Pointer to channel structure.
1742 *=======================================================================*/
1744 static void dgap_input(struct channel_t *ch)
1748 struct tty_struct *tp;
1749 struct tty_ldisc *ld;
1763 if (!ch || ch->magic != DGAP_CHANNEL_MAGIC)
1766 tp = ch->ch_tun.un_tty;
1773 if (!bd || bd->magic != DGAP_BOARD_MAGIC)
1776 DGAP_LOCK(bd->bd_lock, lock_flags);
1777 DGAP_LOCK(ch->ch_lock, lock_flags2);
1780 * Figure the number of characters in the buffer.
1781 * Exit immediately if none.
1784 rmask = ch->ch_rsize - 1;
1786 head = readw(&(bs->rx_head));
1788 tail = readw(&(bs->rx_tail));
1791 data_len = (head - tail) & rmask;
1793 if (data_len == 0) {
1794 writeb(1, &(bs->idata));
1795 DGAP_UNLOCK(ch->ch_lock, lock_flags2);
1796 DGAP_UNLOCK(bd->bd_lock, lock_flags);
1801 * If the device is not open, or CREAD is off, flush
1802 * input data and return immediately.
1804 if ((bd->state != BOARD_READY) || !tp ||
1805 (tp->magic != TTY_MAGIC) ||
1806 !(ch->ch_tun.un_flags & UN_ISOPEN) ||
1807 !(tp->termios.c_cflag & CREAD) ||
1808 (ch->ch_tun.un_flags & UN_CLOSING)) {
1810 writew(head, &(bs->rx_tail));
1811 writeb(1, &(bs->idata));
1812 DGAP_UNLOCK(ch->ch_lock, lock_flags2);
1813 DGAP_UNLOCK(bd->bd_lock, lock_flags);
1818 * If we are throttled, simply don't read any data.
1820 if (ch->ch_flags & CH_RXBLOCK) {
1821 writeb(1, &(bs->idata));
1822 DGAP_UNLOCK(ch->ch_lock, lock_flags2);
1823 DGAP_UNLOCK(bd->bd_lock, lock_flags);
1830 tmpchar = readb(&(bs->orun));
1832 ch->ch_err_overrun++;
1833 writeb(0, &(bs->orun));
1836 /* Decide how much data we can send into the tty layer */
1837 flip_len = TTY_FLIPBUF_SIZE;
1839 /* Chop down the length, if needed */
1840 len = min(data_len, flip_len);
1841 len = min(len, (N_TTY_BUF_SIZE - 1));
1843 ld = tty_ldisc_ref(tp);
1845 #ifdef TTY_DONT_FLIP
1847 * If the DONT_FLIP flag is on, don't flush our buffer, and act
1848 * like the ld doesn't have any space to put the data right now.
1850 if (test_bit(TTY_DONT_FLIP, &tp->flags))
1855 * If we were unable to get a reference to the ld,
1856 * don't flush our buffer, and act like the ld doesn't
1857 * have any space to put the data right now.
1863 * If ld doesn't have a pointer to a receive_buf function,
1864 * flush the data, then act like the ld doesn't have any
1865 * space to put the data right now.
1867 if (!ld->ops->receive_buf) {
1868 writew(head, &(bs->rx_tail));
1874 writeb(1, &(bs->idata));
1875 DGAP_UNLOCK(ch->ch_lock, lock_flags2);
1876 DGAP_UNLOCK(bd->bd_lock, lock_flags);
1878 tty_ldisc_deref(ld);
1882 buf = ch->ch_bd->flipbuf;
1886 * n now contains the most amount of data we can copy,
1887 * bounded either by our buffer size or the amount
1888 * of data the card actually has pending...
1892 s = ((head >= tail) ? head : ch->ch_rsize) - tail;
1898 memcpy_fromio(buf, (char *) ch->ch_raddr + tail, s);
1899 dgap_sniff_nowait_nolock(ch, "USER READ", buf, s);
1905 /* Flip queue if needed */
1909 writew(tail, &(bs->rx_tail));
1910 writeb(1, &(bs->idata));
1911 ch->ch_rxcount += len;
1914 * If we are completely raw, we don't need to go through a lot
1915 * of the tty layers that exist.
1916 * In this case, we take the shortest and fastest route we
1917 * can to relay the data to the user.
1919 * On the other hand, if we are not raw, we need to go through
1920 * the tty layer, which has its API more well defined.
1922 if (I_PARMRK(tp) || I_BRKINT(tp) || I_INPCK(tp)) {
1923 dgap_parity_scan(ch, ch->ch_bd->flipbuf, ch->ch_bd->flipflagbuf, &len);
1925 len = tty_buffer_request_room(tp->port, len);
1926 tty_insert_flip_string_flags(tp->port, ch->ch_bd->flipbuf,
1927 ch->ch_bd->flipflagbuf, len);
1929 len = tty_buffer_request_room(tp->port, len);
1930 tty_insert_flip_string(tp->port, ch->ch_bd->flipbuf, len);
1933 DGAP_UNLOCK(ch->ch_lock, lock_flags2);
1934 DGAP_UNLOCK(bd->bd_lock, lock_flags);
1936 /* Tell the tty layer its okay to "eat" the data now */
1937 tty_flip_buffer_push(tp->port);
1940 tty_ldisc_deref(ld);
1944 /************************************************************************
1945 * Determines when CARRIER changes state and takes appropriate
1947 ************************************************************************/
1948 static void dgap_carrier(struct channel_t *ch)
1952 int virt_carrier = 0;
1953 int phys_carrier = 0;
1955 if (!ch || ch->magic != DGAP_CHANNEL_MAGIC)
1960 if (!bd || bd->magic != DGAP_BOARD_MAGIC)
1963 /* Make sure altpin is always set correctly */
1964 if (ch->ch_digi.digi_flags & DIGI_ALTPIN) {
1968 ch->ch_dsr = DM_DSR;
1972 if (ch->ch_mistat & D_CD(ch))
1975 if (ch->ch_digi.digi_flags & DIGI_FORCEDCD)
1978 if (ch->ch_c_cflag & CLOCAL)
1982 * Test for a VIRTUAL carrier transition to HIGH.
1984 if (((ch->ch_flags & CH_FCAR) == 0) && (virt_carrier == 1)) {
1987 * When carrier rises, wake any threads waiting
1988 * for carrier in the open routine.
1991 if (waitqueue_active(&(ch->ch_flags_wait)))
1992 wake_up_interruptible(&ch->ch_flags_wait);
1996 * Test for a PHYSICAL carrier transition to HIGH.
1998 if (((ch->ch_flags & CH_CD) == 0) && (phys_carrier == 1)) {
2001 * When carrier rises, wake any threads waiting
2002 * for carrier in the open routine.
2005 if (waitqueue_active(&(ch->ch_flags_wait)))
2006 wake_up_interruptible(&ch->ch_flags_wait);
2010 * Test for a PHYSICAL transition to low, so long as we aren't
2011 * currently ignoring physical transitions (which is what "virtual
2012 * carrier" indicates).
2014 * The transition of the virtual carrier to low really doesn't
2015 * matter... it really only means "ignore carrier state", not
2016 * "make pretend that carrier is there".
2018 if ((virt_carrier == 0) &&
2019 ((ch->ch_flags & CH_CD) != 0) &&
2020 (phys_carrier == 0)) {
2023 * When carrier drops:
2025 * Drop carrier on all open units.
2027 * Flush queues, waking up any task waiting in the
2030 * Send a hangup to the control terminal.
2032 * Enable all select calls.
2034 if (waitqueue_active(&(ch->ch_flags_wait)))
2035 wake_up_interruptible(&ch->ch_flags_wait);
2037 if (ch->ch_tun.un_open_count > 0)
2038 tty_hangup(ch->ch_tun.un_tty);
2040 if (ch->ch_pun.un_open_count > 0)
2041 tty_hangup(ch->ch_pun.un_tty);
2045 * Make sure that our cached values reflect the current reality.
2047 if (virt_carrier == 1)
2048 ch->ch_flags |= CH_FCAR;
2050 ch->ch_flags &= ~CH_FCAR;
2052 if (phys_carrier == 1)
2053 ch->ch_flags |= CH_CD;
2055 ch->ch_flags &= ~CH_CD;
2058 /************************************************************************
2060 * TTY Entry points and helper functions
2062 ************************************************************************/
2068 static int dgap_tty_open(struct tty_struct *tty, struct file *file)
2070 struct board_t *brd;
2071 struct channel_t *ch;
2083 major = MAJOR(tty_devnum(tty));
2084 minor = MINOR(tty_devnum(tty));
2089 /* Get board pointer from our array of majors we have allocated */
2090 brd = dgap_BoardsByMajor[major];
2095 * If board is not yet up to a state of READY, go to
2096 * sleep waiting for it to happen or they cancel the open.
2098 rc = wait_event_interruptible(brd->state_wait,
2099 (brd->state & BOARD_READY));
2104 DGAP_LOCK(brd->bd_lock, lock_flags);
2106 /* The wait above should guarantee this cannot happen */
2107 if (brd->state != BOARD_READY) {
2108 DGAP_UNLOCK(brd->bd_lock, lock_flags);
2112 /* If opened device is greater than our number of ports, bail. */
2113 if (MINOR(tty_devnum(tty)) > brd->nasync) {
2114 DGAP_UNLOCK(brd->bd_lock, lock_flags);
2118 ch = brd->channels[minor];
2120 DGAP_UNLOCK(brd->bd_lock, lock_flags);
2124 /* Grab channel lock */
2125 DGAP_LOCK(ch->ch_lock, lock_flags2);
2127 /* Figure out our type */
2128 if (major == brd->dgap_Serial_Major) {
2129 un = &brd->channels[minor]->ch_tun;
2130 un->un_type = DGAP_SERIAL;
2131 } else if (major == brd->dgap_TransparentPrint_Major) {
2132 un = &brd->channels[minor]->ch_pun;
2133 un->un_type = DGAP_PRINT;
2135 DGAP_UNLOCK(ch->ch_lock, lock_flags2);
2136 DGAP_UNLOCK(brd->bd_lock, lock_flags);
2140 /* Store our unit into driver_data, so we always have it available. */
2141 tty->driver_data = un;
2144 * Error if channel info pointer is NULL.
2148 DGAP_UNLOCK(ch->ch_lock, lock_flags2);
2149 DGAP_UNLOCK(brd->bd_lock, lock_flags);
2156 if (!(un->un_flags & UN_ISOPEN)) {
2157 /* Store important variables. */
2160 /* Maybe do something here to the TTY struct as well? */
2164 * Initialize if neither terminal or printer is open.
2166 if (!((ch->ch_tun.un_flags | ch->ch_pun.un_flags) & UN_ISOPEN)) {
2172 * Flush input queue.
2174 head = readw(&(bs->rx_head));
2175 writew(head, &(bs->rx_tail));
2178 ch->pscan_state = 0;
2179 ch->pscan_savechar = 0;
2181 ch->ch_c_cflag = tty->termios.c_cflag;
2182 ch->ch_c_iflag = tty->termios.c_iflag;
2183 ch->ch_c_oflag = tty->termios.c_oflag;
2184 ch->ch_c_lflag = tty->termios.c_lflag;
2185 ch->ch_startc = tty->termios.c_cc[VSTART];
2186 ch->ch_stopc = tty->termios.c_cc[VSTOP];
2188 /* TODO: flush our TTY struct here? */
2193 * Run param in case we changed anything
2198 * follow protocol for opening port
2201 DGAP_UNLOCK(ch->ch_lock, lock_flags2);
2202 DGAP_UNLOCK(brd->bd_lock, lock_flags);
2204 rc = dgap_block_til_ready(tty, file, ch);
2209 /* No going back now, increment our unit and channel counters */
2210 DGAP_LOCK(ch->ch_lock, lock_flags);
2211 ch->ch_open_count++;
2212 un->un_open_count++;
2213 un->un_flags |= (UN_ISOPEN);
2214 DGAP_UNLOCK(ch->ch_lock, lock_flags);
2220 * dgap_block_til_ready()
2222 * Wait for DCD, if needed.
2224 static int dgap_block_til_ready(struct tty_struct *tty, struct file *file, struct channel_t *ch)
2227 struct un_t *un = NULL;
2230 int sleep_on_un_flags = 0;
2232 if (!tty || tty->magic != TTY_MAGIC || !file || !ch ||
2233 ch->magic != DGAP_CHANNEL_MAGIC)
2236 un = tty->driver_data;
2237 if (!un || un->magic != DGAP_UNIT_MAGIC)
2240 DGAP_LOCK(ch->ch_lock, lock_flags);
2247 sleep_on_un_flags = 0;
2250 * If board has failed somehow during our sleep, bail with error.
2252 if (ch->ch_bd->state == BOARD_FAILED) {
2257 /* If tty was hung up, break out of loop and set error. */
2258 if (tty_hung_up_p(file)) {
2264 * If either unit is in the middle of the fragile part of close,
2265 * we just cannot touch the channel safely.
2266 * Go back to sleep, knowing that when the channel can be
2267 * touched safely, the close routine will signal the
2268 * ch_wait_flags to wake us back up.
2270 if (!((ch->ch_tun.un_flags | ch->ch_pun.un_flags) & UN_CLOSING)) {
2273 * Our conditions to leave cleanly and happily:
2274 * 1) NONBLOCKING on the tty is set.
2276 * 3) DCD (fake or real) is active.
2279 if (file->f_flags & O_NONBLOCK)
2282 if (tty->flags & (1 << TTY_IO_ERROR))
2285 if (ch->ch_flags & CH_CD)
2288 if (ch->ch_flags & CH_FCAR)
2291 sleep_on_un_flags = 1;
2295 * If there is a signal pending, the user probably
2296 * interrupted (ctrl-c) us.
2297 * Leave loop with error set.
2299 if (signal_pending(current)) {
2300 retval = -ERESTARTSYS;
2305 * Store the flags before we let go of channel lock
2307 if (sleep_on_un_flags)
2308 old_flags = ch->ch_tun.un_flags | ch->ch_pun.un_flags;
2310 old_flags = ch->ch_flags;
2313 * Let go of channel lock before calling schedule.
2314 * Our poller will get any FEP events and wake us up when DCD
2315 * eventually goes active.
2318 DGAP_UNLOCK(ch->ch_lock, lock_flags);
2321 * Wait for something in the flags to change from the current value.
2323 if (sleep_on_un_flags) {
2324 retval = wait_event_interruptible(un->un_flags_wait,
2325 (old_flags != (ch->ch_tun.un_flags | 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;
2425 if (--un->un_open_count < 0)
2426 un->un_open_count = 0;
2428 ch->ch_open_count--;
2430 if (ch->ch_open_count && un->un_open_count) {
2431 DGAP_UNLOCK(ch->ch_lock, lock_flags);
2435 /* OK, its the last close on the unit */
2437 un->un_flags |= UN_CLOSING;
2442 * Only officially close channel if count is 0 and
2443 * DIGI_PRINTER bit is not set.
2445 if ((ch->ch_open_count == 0) && !(ch->ch_digi.digi_flags & DIGI_PRINTER)) {
2447 ch->ch_flags &= ~(CH_RXBLOCK);
2449 DGAP_UNLOCK(ch->ch_lock, lock_flags);
2451 /* wait for output to drain */
2452 /* This will also return if we take an interrupt */
2454 rc = dgap_wait_for_drain(tty);
2456 dgap_tty_flush_buffer(tty);
2457 tty_ldisc_flush(tty);
2459 DGAP_LOCK(ch->ch_lock, lock_flags);
2464 * If we have HUPCL set, lower DTR and RTS
2466 if (ch->ch_c_cflag & HUPCL) {
2467 ch->ch_mostat &= ~(D_RTS(ch)|D_DTR(ch));
2468 dgap_cmdb(ch, SMODEM, 0, D_DTR(ch)|D_RTS(ch), 0);
2471 * Go to sleep to ensure RTS/DTR
2472 * have been dropped for modems to see it.
2474 if (ch->ch_close_delay) {
2475 DGAP_UNLOCK(ch->ch_lock, lock_flags);
2476 dgap_ms_sleep(ch->ch_close_delay);
2477 DGAP_LOCK(ch->ch_lock, lock_flags);
2481 ch->pscan_state = 0;
2482 ch->pscan_savechar = 0;
2483 ch->ch_baud_info = 0;
2488 * turn off print device when closing print device.
2490 if ((un->un_type == DGAP_PRINT) && (ch->ch_flags & CH_PRON)) {
2491 dgap_wmove(ch, ch->ch_digi.digi_offstr,
2492 (int) ch->ch_digi.digi_offlen);
2493 ch->ch_flags &= ~CH_PRON;
2497 un->un_flags &= ~(UN_ISOPEN | UN_CLOSING);
2498 tty->driver_data = NULL;
2500 wake_up_interruptible(&ch->ch_flags_wait);
2501 wake_up_interruptible(&un->un_flags_wait);
2503 DGAP_UNLOCK(ch->ch_lock, lock_flags);
2507 * dgap_tty_chars_in_buffer()
2509 * Return number of characters that have not been transmitted yet.
2511 * This routine is used by the line discipline to determine if there
2512 * is data waiting to be transmitted/drained/flushed or not.
2514 static int dgap_tty_chars_in_buffer(struct tty_struct *tty)
2516 struct board_t *bd = NULL;
2517 struct channel_t *ch = NULL;
2518 struct un_t *un = NULL;
2519 struct bs_t *bs = NULL;
2522 u16 thead, ttail, tmask, chead, ctail;
2523 ulong lock_flags = 0;
2524 ulong lock_flags2 = 0;
2529 un = tty->driver_data;
2530 if (!un || un->magic != DGAP_UNIT_MAGIC)
2534 if (!ch || ch->magic != DGAP_CHANNEL_MAGIC)
2538 if (!bd || bd->magic != DGAP_BOARD_MAGIC)
2545 DGAP_LOCK(bd->bd_lock, lock_flags);
2546 DGAP_LOCK(ch->ch_lock, lock_flags2);
2548 tmask = (ch->ch_tsize - 1);
2550 /* Get Transmit queue pointers */
2551 thead = readw(&(bs->tx_head)) & tmask;
2552 ttail = readw(&(bs->tx_tail)) & tmask;
2554 /* Get tbusy flag */
2555 tbusy = readb(&(bs->tbusy));
2557 /* Get Command queue pointers */
2558 chead = readw(&(ch->ch_cm->cm_head));
2559 ctail = readw(&(ch->ch_cm->cm_tail));
2561 DGAP_UNLOCK(ch->ch_lock, lock_flags2);
2562 DGAP_UNLOCK(bd->bd_lock, lock_flags);
2565 * The only way we know for sure if there is no pending
2566 * data left to be transferred, is if:
2567 * 1) Transmit head and tail are equal (empty).
2568 * 2) Command queue head and tail are equal (empty).
2569 * 3) The "TBUSY" flag is 0. (Transmitter not busy).
2572 if ((ttail == thead) && (tbusy == 0) && (chead == ctail)) {
2576 chars = thead - ttail;
2578 chars = thead - ttail + ch->ch_tsize;
2580 * Fudge factor here.
2581 * If chars is zero, we know that the command queue had
2582 * something in it or tbusy was set. Because we cannot
2583 * be sure if there is still some data to be transmitted,
2584 * lets lie, and tell ld we have 1 byte left.
2588 * If TBUSY is still set, and our tx buffers are empty,
2589 * force the firmware to send me another wakeup after
2590 * TBUSY has been cleared.
2593 DGAP_LOCK(ch->ch_lock, lock_flags);
2594 un->un_flags |= UN_EMPTY;
2595 writeb(1, &(bs->iempty));
2596 DGAP_UNLOCK(ch->ch_lock, lock_flags);
2605 static int dgap_wait_for_drain(struct tty_struct *tty)
2607 struct channel_t *ch;
2612 ulong lock_flags = 0;
2614 if (!tty || tty->magic != TTY_MAGIC)
2617 un = tty->driver_data;
2618 if (!un || un->magic != DGAP_UNIT_MAGIC)
2622 if (!ch || ch->magic != DGAP_CHANNEL_MAGIC)
2631 /* Loop until data is drained */
2632 while (count != 0) {
2634 count = dgap_tty_chars_in_buffer(tty);
2639 /* Set flag waiting for drain */
2640 DGAP_LOCK(ch->ch_lock, lock_flags);
2641 un->un_flags |= UN_EMPTY;
2642 writeb(1, &(bs->iempty));
2643 DGAP_UNLOCK(ch->ch_lock, lock_flags);
2645 /* Go to sleep till we get woken up */
2646 ret = wait_event_interruptible(un->un_flags_wait, ((un->un_flags & UN_EMPTY) == 0));
2647 /* If ret is non-zero, user ctrl-c'ed us */
2652 DGAP_LOCK(ch->ch_lock, lock_flags);
2653 un->un_flags &= ~(UN_EMPTY);
2654 DGAP_UNLOCK(ch->ch_lock, lock_flags);
2662 * Reduces bytes_available to the max number of characters
2663 * that can be sent currently given the maxcps value, and
2664 * returns the new bytes_available. This only affects printer
2667 static int dgap_maxcps_room(struct tty_struct *tty, int bytes_available)
2669 struct channel_t *ch = NULL;
2670 struct un_t *un = NULL;
2673 return bytes_available;
2675 un = tty->driver_data;
2676 if (!un || un->magic != DGAP_UNIT_MAGIC)
2677 return bytes_available;
2680 if (!ch || ch->magic != DGAP_CHANNEL_MAGIC)
2681 return bytes_available;
2684 * If its not the Transparent print device, return
2685 * the full data amount.
2687 if (un->un_type != DGAP_PRINT)
2688 return bytes_available;
2690 if (ch->ch_digi.digi_maxcps > 0 && ch->ch_digi.digi_bufsize > 0) {
2692 unsigned long current_time = jiffies;
2693 unsigned long buffer_time = current_time +
2694 (HZ * ch->ch_digi.digi_bufsize) / ch->ch_digi.digi_maxcps;
2696 if (ch->ch_cpstime < current_time) {
2697 /* buffer is empty */
2698 ch->ch_cpstime = current_time; /* reset ch_cpstime */
2699 cps_limit = ch->ch_digi.digi_bufsize;
2700 } else if (ch->ch_cpstime < buffer_time) {
2701 /* still room in the buffer */
2702 cps_limit = ((buffer_time - ch->ch_cpstime) * ch->ch_digi.digi_maxcps) / HZ;
2704 /* no room in the buffer */
2708 bytes_available = min(cps_limit, bytes_available);
2711 return bytes_available;
2714 static inline void dgap_set_firmware_event(struct un_t *un, unsigned int event)
2716 struct channel_t *ch = NULL;
2717 struct bs_t *bs = NULL;
2719 if (!un || un->magic != DGAP_UNIT_MAGIC)
2722 if (!ch || ch->magic != DGAP_CHANNEL_MAGIC)
2728 if ((event & UN_LOW) != 0) {
2729 if ((un->un_flags & UN_LOW) == 0) {
2730 un->un_flags |= UN_LOW;
2731 writeb(1, &(bs->ilow));
2734 if ((event & UN_LOW) != 0) {
2735 if ((un->un_flags & UN_EMPTY) == 0) {
2736 un->un_flags |= UN_EMPTY;
2737 writeb(1, &(bs->iempty));
2743 * dgap_tty_write_room()
2745 * Return space available in Tx buffer
2747 static int dgap_tty_write_room(struct tty_struct *tty)
2749 struct channel_t *ch = NULL;
2750 struct un_t *un = NULL;
2751 struct bs_t *bs = NULL;
2752 u16 head, tail, tmask;
2754 ulong lock_flags = 0;
2756 if (tty == NULL || dgap_TmpWriteBuf == NULL)
2759 un = tty->driver_data;
2760 if (!un || un->magic != DGAP_UNIT_MAGIC)
2764 if (!ch || ch->magic != DGAP_CHANNEL_MAGIC)
2771 DGAP_LOCK(ch->ch_lock, lock_flags);
2773 tmask = ch->ch_tsize - 1;
2774 head = readw(&(bs->tx_head)) & tmask;
2775 tail = readw(&(bs->tx_tail)) & tmask;
2777 ret = tail - head - 1;
2779 ret += ch->ch_tsize;
2781 /* Limit printer to maxcps */
2782 ret = dgap_maxcps_room(tty, ret);
2785 * If we are printer device, leave space for
2786 * possibly both the on and off strings.
2788 if (un->un_type == DGAP_PRINT) {
2789 if (!(ch->ch_flags & CH_PRON))
2790 ret -= ch->ch_digi.digi_onlen;
2791 ret -= ch->ch_digi.digi_offlen;
2793 if (ch->ch_flags & CH_PRON)
2794 ret -= ch->ch_digi.digi_offlen;
2801 * Schedule FEP to wake us up if needed.
2803 * TODO: This might be overkill...
2804 * Do we really need to schedule callbacks from the FEP
2805 * in every case? Can we get smarter based on ret?
2807 dgap_set_firmware_event(un, UN_LOW | UN_EMPTY);
2808 DGAP_UNLOCK(ch->ch_lock, lock_flags);
2814 * dgap_tty_put_char()
2816 * Put a character into ch->ch_buf
2818 * - used by the line discipline for OPOST processing
2820 static int dgap_tty_put_char(struct tty_struct *tty, unsigned char c)
2823 * Simply call tty_write.
2825 dgap_tty_write(tty, &c, 1);
2832 * Take data from the user or kernel and send it out to the FEP.
2833 * In here exists all the Transparent Print magic as well.
2835 static int dgap_tty_write(struct tty_struct *tty, const unsigned char *buf, int count)
2837 struct channel_t *ch = NULL;
2838 struct un_t *un = NULL;
2839 struct bs_t *bs = NULL;
2841 u16 head, tail, tmask, remain;
2842 int bufcount = 0, n = 0;
2847 if (tty == NULL || dgap_TmpWriteBuf == NULL)
2850 un = tty->driver_data;
2851 if (!un || un->magic != DGAP_UNIT_MAGIC)
2855 if (!ch || ch->magic != DGAP_CHANNEL_MAGIC)
2866 * Store original amount of characters passed in.
2867 * This helps to figure out if we should ask the FEP
2868 * to send us an event when it has more space available.
2872 DGAP_LOCK(ch->ch_lock, lock_flags);
2874 /* Get our space available for the channel from the board */
2875 tmask = ch->ch_tsize - 1;
2876 head = readw(&(bs->tx_head)) & tmask;
2877 tail = readw(&(bs->tx_tail)) & tmask;
2879 if ((bufcount = tail - head - 1) < 0)
2880 bufcount += ch->ch_tsize;
2883 * Limit printer output to maxcps overall, with bursts allowed
2884 * up to bufsize characters.
2886 bufcount = dgap_maxcps_room(tty, bufcount);
2889 * Take minimum of what the user wants to send, and the
2890 * space available in the FEP buffer.
2892 count = min(count, bufcount);
2895 * Bail if no space left.
2898 dgap_set_firmware_event(un, UN_LOW | UN_EMPTY);
2899 DGAP_UNLOCK(ch->ch_lock, lock_flags);
2904 * Output the printer ON string, if we are in terminal mode, but
2905 * need to be in printer mode.
2907 if ((un->un_type == DGAP_PRINT) && !(ch->ch_flags & CH_PRON)) {
2908 dgap_wmove(ch, ch->ch_digi.digi_onstr,
2909 (int) ch->ch_digi.digi_onlen);
2910 head = readw(&(bs->tx_head)) & tmask;
2911 ch->ch_flags |= CH_PRON;
2915 * On the other hand, output the printer OFF string, if we are
2916 * currently in printer mode, but need to output to the terminal.
2918 if ((un->un_type != DGAP_PRINT) && (ch->ch_flags & CH_PRON)) {
2919 dgap_wmove(ch, ch->ch_digi.digi_offstr,
2920 (int) ch->ch_digi.digi_offlen);
2921 head = readw(&(bs->tx_head)) & tmask;
2922 ch->ch_flags &= ~CH_PRON;
2926 * If there is nothing left to copy, or I can't handle any more data, leave.
2929 dgap_set_firmware_event(un, UN_LOW | UN_EMPTY);
2930 DGAP_UNLOCK(ch->ch_lock, lock_flags);
2936 count = min(count, WRITEBUFLEN);
2938 DGAP_UNLOCK(ch->ch_lock, lock_flags);
2941 * If data is coming from user space, copy it into a temporary
2942 * buffer so we don't get swapped out while doing the copy to
2945 /* we're allowed to block if it's from_user */
2946 if (down_interruptible(&dgap_TmpWriteSem))
2949 if (copy_from_user(dgap_TmpWriteBuf, (const uchar __user *) buf, count)) {
2950 up(&dgap_TmpWriteSem);
2951 printk("Write: Copy from user failed!\n");
2955 DGAP_LOCK(ch->ch_lock, lock_flags);
2957 buf = dgap_TmpWriteBuf;
2963 * If the write wraps over the top of the circular buffer,
2964 * move the portion up to the wrap point, and reset the
2965 * pointers to the bottom.
2967 remain = ch->ch_tstart + ch->ch_tsize - head;
2971 vaddr = ch->ch_taddr + head;
2973 memcpy_toio(vaddr, (uchar *) buf, remain);
2974 dgap_sniff_nowait_nolock(ch, "USER WRITE", (uchar *) buf, remain);
2976 head = ch->ch_tstart;
2983 * Move rest of data.
2985 vaddr = ch->ch_taddr + head;
2988 memcpy_toio(vaddr, (uchar *) buf, remain);
2989 dgap_sniff_nowait_nolock(ch, "USER WRITE", (uchar *) buf, remain);
2996 ch->ch_txcount += count;
2998 writew(head, &(bs->tx_head));
3001 dgap_set_firmware_event(un, UN_LOW | UN_EMPTY);
3004 * If this is the print device, and the
3005 * printer is still on, we need to turn it
3006 * off before going idle. If the buffer is
3007 * non-empty, wait until it goes empty.
3008 * Otherwise turn it off right now.
3010 if ((un->un_type == DGAP_PRINT) && (ch->ch_flags & CH_PRON)) {
3011 tail = readw(&(bs->tx_tail)) & tmask;
3014 un->un_flags |= UN_EMPTY;
3015 writeb(1, &(bs->iempty));
3017 dgap_wmove(ch, ch->ch_digi.digi_offstr,
3018 (int) ch->ch_digi.digi_offlen);
3019 head = readw(&(bs->tx_head)) & tmask;
3020 ch->ch_flags &= ~CH_PRON;
3024 /* Update printer buffer empty time. */
3025 if ((un->un_type == DGAP_PRINT) && (ch->ch_digi.digi_maxcps > 0)
3026 && (ch->ch_digi.digi_bufsize > 0)) {
3027 ch->ch_cpstime += (HZ * count) / ch->ch_digi.digi_maxcps;
3031 DGAP_UNLOCK(ch->ch_lock, lock_flags);
3032 up(&dgap_TmpWriteSem);
3034 DGAP_UNLOCK(ch->ch_lock, lock_flags);
3040 * Return modem signals to ld.
3042 static int dgap_tty_tiocmget(struct tty_struct *tty)
3044 struct channel_t *ch;
3050 if (!tty || tty->magic != TTY_MAGIC)
3053 un = tty->driver_data;
3054 if (!un || un->magic != DGAP_UNIT_MAGIC)
3058 if (!ch || ch->magic != DGAP_CHANNEL_MAGIC)
3061 DGAP_LOCK(ch->ch_lock, lock_flags);
3063 mstat = readb(&(ch->ch_bs->m_stat));
3064 /* Append any outbound signals that might be pending... */
3065 mstat |= ch->ch_mostat;
3067 DGAP_UNLOCK(ch->ch_lock, lock_flags);
3071 if (mstat & D_DTR(ch))
3072 result |= TIOCM_DTR;
3073 if (mstat & D_RTS(ch))
3074 result |= TIOCM_RTS;
3075 if (mstat & D_CTS(ch))
3076 result |= TIOCM_CTS;
3077 if (mstat & D_DSR(ch))
3078 result |= TIOCM_DSR;
3079 if (mstat & D_RI(ch))
3081 if (mstat & D_CD(ch))
3088 * dgap_tty_tiocmset()
3090 * Set modem signals, called by ld.
3092 static int dgap_tty_tiocmset(struct tty_struct *tty,
3093 unsigned int set, unsigned int clear)
3096 struct channel_t *ch;
3102 if (!tty || tty->magic != TTY_MAGIC)
3105 un = tty->driver_data;
3106 if (!un || un->magic != DGAP_UNIT_MAGIC)
3110 if (!ch || ch->magic != DGAP_CHANNEL_MAGIC)
3114 if (!bd || bd->magic != DGAP_BOARD_MAGIC)
3117 DGAP_LOCK(bd->bd_lock, lock_flags);
3118 DGAP_LOCK(ch->ch_lock, lock_flags2);
3120 if (set & TIOCM_RTS) {
3121 ch->ch_mforce |= D_RTS(ch);
3122 ch->ch_mval |= D_RTS(ch);
3125 if (set & TIOCM_DTR) {
3126 ch->ch_mforce |= D_DTR(ch);
3127 ch->ch_mval |= D_DTR(ch);
3130 if (clear & TIOCM_RTS) {
3131 ch->ch_mforce |= D_RTS(ch);
3132 ch->ch_mval &= ~(D_RTS(ch));
3135 if (clear & TIOCM_DTR) {
3136 ch->ch_mforce |= D_DTR(ch);
3137 ch->ch_mval &= ~(D_DTR(ch));
3142 DGAP_UNLOCK(ch->ch_lock, lock_flags2);
3143 DGAP_UNLOCK(bd->bd_lock, lock_flags);
3149 * dgap_tty_send_break()
3151 * Send a Break, called by ld.
3153 static int dgap_tty_send_break(struct tty_struct *tty, int msec)
3156 struct channel_t *ch;
3162 if (!tty || tty->magic != TTY_MAGIC)
3165 un = tty->driver_data;
3166 if (!un || un->magic != DGAP_UNIT_MAGIC)
3170 if (!ch || ch->magic != DGAP_CHANNEL_MAGIC)
3174 if (!bd || bd->magic != DGAP_BOARD_MAGIC)
3189 DGAP_LOCK(bd->bd_lock, lock_flags);
3190 DGAP_LOCK(ch->ch_lock, lock_flags2);
3192 dgap_cmdw(ch, SBREAK, (u16) SBREAK_TIME, 0);
3194 dgap_cmdw(ch, SBREAK, (u16) msec, 0);
3196 DGAP_UNLOCK(ch->ch_lock, lock_flags2);
3197 DGAP_UNLOCK(bd->bd_lock, lock_flags);
3203 * dgap_tty_wait_until_sent()
3205 * wait until data has been transmitted, called by ld.
3207 static void dgap_tty_wait_until_sent(struct tty_struct *tty, int timeout)
3209 dgap_wait_for_drain(tty);
3215 * send a high priority character, called by ld.
3217 static void dgap_tty_send_xchar(struct tty_struct *tty, char c)
3220 struct channel_t *ch;
3225 if (!tty || tty->magic != TTY_MAGIC)
3228 un = tty->driver_data;
3229 if (!un || un->magic != DGAP_UNIT_MAGIC)
3233 if (!ch || ch->magic != DGAP_CHANNEL_MAGIC)
3237 if (!bd || bd->magic != DGAP_BOARD_MAGIC)
3240 DGAP_LOCK(bd->bd_lock, lock_flags);
3241 DGAP_LOCK(ch->ch_lock, lock_flags2);
3244 * This is technically what we should do.
3245 * However, the NIST tests specifically want
3246 * to see each XON or XOFF character that it
3247 * sends, so lets just send each character
3251 if (c == STOP_CHAR(tty))
3252 dgap_cmdw(ch, RPAUSE, 0, 0);
3253 else if (c == START_CHAR(tty))
3254 dgap_cmdw(ch, RRESUME, 0, 0);
3256 dgap_wmove(ch, &c, 1);
3258 dgap_wmove(ch, &c, 1);
3261 DGAP_UNLOCK(ch->ch_lock, lock_flags2);
3262 DGAP_UNLOCK(bd->bd_lock, lock_flags);
3268 * Return modem signals to ld.
3270 static int dgap_get_modem_info(struct channel_t *ch, unsigned int __user *value)
3277 if (!ch || ch->magic != DGAP_CHANNEL_MAGIC)
3280 DGAP_LOCK(ch->ch_lock, lock_flags);
3282 mstat = readb(&(ch->ch_bs->m_stat));
3283 /* Append any outbound signals that might be pending... */
3284 mstat |= ch->ch_mostat;
3286 DGAP_UNLOCK(ch->ch_lock, lock_flags);
3290 if (mstat & D_DTR(ch))
3291 result |= TIOCM_DTR;
3292 if (mstat & D_RTS(ch))
3293 result |= TIOCM_RTS;
3294 if (mstat & D_CTS(ch))
3295 result |= TIOCM_CTS;
3296 if (mstat & D_DSR(ch))
3297 result |= TIOCM_DSR;
3298 if (mstat & D_RI(ch))
3300 if (mstat & D_CD(ch))
3303 rc = put_user(result, value);
3309 * dgap_set_modem_info()
3311 * Set modem signals, called by ld.
3313 static int dgap_set_modem_info(struct tty_struct *tty, unsigned int command, unsigned int __user *value)
3316 struct channel_t *ch;
3319 unsigned int arg = 0;
3323 if (!tty || tty->magic != TTY_MAGIC)
3326 un = tty->driver_data;
3327 if (!un || un->magic != DGAP_UNIT_MAGIC)
3331 if (!ch || ch->magic != DGAP_CHANNEL_MAGIC)
3335 if (!bd || bd->magic != DGAP_BOARD_MAGIC)
3338 ret = get_user(arg, value);
3344 if (arg & TIOCM_RTS) {
3345 ch->ch_mforce |= D_RTS(ch);
3346 ch->ch_mval |= D_RTS(ch);
3349 if (arg & TIOCM_DTR) {
3350 ch->ch_mforce |= D_DTR(ch);
3351 ch->ch_mval |= D_DTR(ch);
3357 if (arg & TIOCM_RTS) {
3358 ch->ch_mforce |= D_RTS(ch);
3359 ch->ch_mval &= ~(D_RTS(ch));
3362 if (arg & TIOCM_DTR) {
3363 ch->ch_mforce |= D_DTR(ch);
3364 ch->ch_mval &= ~(D_DTR(ch));
3370 ch->ch_mforce = D_DTR(ch)|D_RTS(ch);
3372 if (arg & TIOCM_RTS)
3373 ch->ch_mval |= D_RTS(ch);
3375 ch->ch_mval &= ~(D_RTS(ch));
3377 if (arg & TIOCM_DTR)
3378 ch->ch_mval |= (D_DTR(ch));
3380 ch->ch_mval &= ~(D_DTR(ch));
3388 DGAP_LOCK(bd->bd_lock, lock_flags);
3389 DGAP_LOCK(ch->ch_lock, lock_flags2);
3393 DGAP_UNLOCK(ch->ch_lock, lock_flags2);
3394 DGAP_UNLOCK(bd->bd_lock, lock_flags);
3400 * dgap_tty_digigeta()
3402 * Ioctl to get the information for ditty.
3407 static int dgap_tty_digigeta(struct tty_struct *tty, struct digi_t __user *retinfo)
3409 struct channel_t *ch;
3417 if (!tty || tty->magic != TTY_MAGIC)
3420 un = tty->driver_data;
3421 if (!un || un->magic != DGAP_UNIT_MAGIC)
3425 if (!ch || ch->magic != DGAP_CHANNEL_MAGIC)
3428 memset(&tmp, 0, sizeof(tmp));
3430 DGAP_LOCK(ch->ch_lock, lock_flags);
3431 memcpy(&tmp, &ch->ch_digi, sizeof(tmp));
3432 DGAP_UNLOCK(ch->ch_lock, lock_flags);
3434 if (copy_to_user(retinfo, &tmp, sizeof(*retinfo)))
3441 * dgap_tty_digiseta()
3443 * Ioctl to set the information for ditty.
3448 static int dgap_tty_digiseta(struct tty_struct *tty, struct digi_t __user *new_info)
3451 struct channel_t *ch;
3453 struct digi_t new_digi;
3454 ulong lock_flags = 0;
3455 unsigned long lock_flags2;
3457 if (!tty || tty->magic != TTY_MAGIC)
3460 un = tty->driver_data;
3461 if (!un || un->magic != DGAP_UNIT_MAGIC)
3465 if (!ch || ch->magic != DGAP_CHANNEL_MAGIC)
3469 if (!bd || bd->magic != DGAP_BOARD_MAGIC)
3472 if (copy_from_user(&new_digi, new_info, sizeof(struct digi_t)))
3475 DGAP_LOCK(bd->bd_lock, lock_flags);
3476 DGAP_LOCK(ch->ch_lock, lock_flags2);
3478 memcpy(&ch->ch_digi, &new_digi, sizeof(struct digi_t));
3480 if (ch->ch_digi.digi_maxcps < 1)
3481 ch->ch_digi.digi_maxcps = 1;
3483 if (ch->ch_digi.digi_maxcps > 10000)
3484 ch->ch_digi.digi_maxcps = 10000;
3486 if (ch->ch_digi.digi_bufsize < 10)
3487 ch->ch_digi.digi_bufsize = 10;
3489 if (ch->ch_digi.digi_maxchar < 1)
3490 ch->ch_digi.digi_maxchar = 1;
3492 if (ch->ch_digi.digi_maxchar > ch->ch_digi.digi_bufsize)
3493 ch->ch_digi.digi_maxchar = ch->ch_digi.digi_bufsize;
3495 if (ch->ch_digi.digi_onlen > DIGI_PLEN)
3496 ch->ch_digi.digi_onlen = DIGI_PLEN;
3498 if (ch->ch_digi.digi_offlen > DIGI_PLEN)
3499 ch->ch_digi.digi_offlen = DIGI_PLEN;
3503 DGAP_UNLOCK(ch->ch_lock, lock_flags2);
3504 DGAP_UNLOCK(bd->bd_lock, lock_flags);
3510 * dgap_tty_digigetedelay()
3512 * Ioctl to get the current edelay setting.
3517 static int dgap_tty_digigetedelay(struct tty_struct *tty, int __user *retinfo)
3519 struct channel_t *ch;
3527 if (!tty || tty->magic != TTY_MAGIC)
3530 un = tty->driver_data;
3531 if (!un || un->magic != DGAP_UNIT_MAGIC)
3535 if (!ch || ch->magic != DGAP_CHANNEL_MAGIC)
3538 memset(&tmp, 0, sizeof(tmp));
3540 DGAP_LOCK(ch->ch_lock, lock_flags);
3541 tmp = readw(&(ch->ch_bs->edelay));
3542 DGAP_UNLOCK(ch->ch_lock, lock_flags);
3544 if (copy_to_user(retinfo, &tmp, sizeof(*retinfo)))
3551 * dgap_tty_digisetedelay()
3553 * Ioctl to set the EDELAY setting
3556 static int dgap_tty_digisetedelay(struct tty_struct *tty, int __user *new_info)
3559 struct channel_t *ch;
3565 if (!tty || tty->magic != TTY_MAGIC)
3568 un = tty->driver_data;
3569 if (!un || un->magic != DGAP_UNIT_MAGIC)
3573 if (!ch || ch->magic != DGAP_CHANNEL_MAGIC)
3577 if (!bd || bd->magic != DGAP_BOARD_MAGIC)
3580 if (copy_from_user(&new_digi, new_info, sizeof(int)))
3583 DGAP_LOCK(bd->bd_lock, lock_flags);
3584 DGAP_LOCK(ch->ch_lock, lock_flags2);
3586 writew((u16) new_digi, &(ch->ch_bs->edelay));
3590 DGAP_UNLOCK(ch->ch_lock, lock_flags2);
3591 DGAP_UNLOCK(bd->bd_lock, lock_flags);
3597 * dgap_tty_digigetcustombaud()
3599 * Ioctl to get the current custom baud rate setting.
3601 static int dgap_tty_digigetcustombaud(struct tty_struct *tty, int __user *retinfo)
3603 struct channel_t *ch;
3611 if (!tty || tty->magic != TTY_MAGIC)
3614 un = tty->driver_data;
3615 if (!un || un->magic != DGAP_UNIT_MAGIC)
3619 if (!ch || ch->magic != DGAP_CHANNEL_MAGIC)
3622 memset(&tmp, 0, sizeof(tmp));
3624 DGAP_LOCK(ch->ch_lock, lock_flags);
3625 tmp = dgap_get_custom_baud(ch);
3626 DGAP_UNLOCK(ch->ch_lock, lock_flags);
3628 if (copy_to_user(retinfo, &tmp, sizeof(*retinfo)))
3635 * dgap_tty_digisetcustombaud()
3637 * Ioctl to set the custom baud rate setting
3639 static int dgap_tty_digisetcustombaud(struct tty_struct *tty, int __user *new_info)
3642 struct channel_t *ch;
3648 if (!tty || tty->magic != TTY_MAGIC)
3651 un = tty->driver_data;
3652 if (!un || un->magic != DGAP_UNIT_MAGIC)
3656 if (!ch || ch->magic != DGAP_CHANNEL_MAGIC)
3660 if (!bd || bd->magic != DGAP_BOARD_MAGIC)
3664 if (copy_from_user(&new_rate, new_info, sizeof(unsigned int)))
3667 if (bd->bd_flags & BD_FEP5PLUS) {
3669 DGAP_LOCK(bd->bd_lock, lock_flags);
3670 DGAP_LOCK(ch->ch_lock, lock_flags2);
3672 ch->ch_custom_speed = new_rate;
3676 DGAP_UNLOCK(ch->ch_lock, lock_flags2);
3677 DGAP_UNLOCK(bd->bd_lock, lock_flags);
3684 * dgap_set_termios()
3686 static void dgap_tty_set_termios(struct tty_struct *tty, struct ktermios *old_termios)
3689 struct channel_t *ch;
3691 unsigned long lock_flags;
3692 unsigned long lock_flags2;
3694 if (!tty || tty->magic != TTY_MAGIC)
3697 un = tty->driver_data;
3698 if (!un || un->magic != DGAP_UNIT_MAGIC)
3702 if (!ch || ch->magic != DGAP_CHANNEL_MAGIC)
3706 if (!bd || bd->magic != DGAP_BOARD_MAGIC)
3709 DGAP_LOCK(bd->bd_lock, lock_flags);
3710 DGAP_LOCK(ch->ch_lock, lock_flags2);
3712 ch->ch_c_cflag = tty->termios.c_cflag;
3713 ch->ch_c_iflag = tty->termios.c_iflag;
3714 ch->ch_c_oflag = tty->termios.c_oflag;
3715 ch->ch_c_lflag = tty->termios.c_lflag;
3716 ch->ch_startc = tty->termios.c_cc[VSTART];
3717 ch->ch_stopc = tty->termios.c_cc[VSTOP];
3722 DGAP_UNLOCK(ch->ch_lock, lock_flags2);
3723 DGAP_UNLOCK(bd->bd_lock, lock_flags);
3726 static void dgap_tty_throttle(struct tty_struct *tty)
3729 struct channel_t *ch;
3734 if (!tty || tty->magic != TTY_MAGIC)
3737 un = tty->driver_data;
3738 if (!un || un->magic != DGAP_UNIT_MAGIC)
3742 if (!ch || ch->magic != DGAP_CHANNEL_MAGIC)
3746 if (!bd || bd->magic != DGAP_BOARD_MAGIC)
3749 DGAP_LOCK(bd->bd_lock, lock_flags);
3750 DGAP_LOCK(ch->ch_lock, lock_flags2);
3752 ch->ch_flags |= (CH_RXBLOCK);
3754 dgap_cmdw(ch, RPAUSE, 0, 0);
3757 DGAP_UNLOCK(ch->ch_lock, lock_flags2);
3758 DGAP_UNLOCK(bd->bd_lock, lock_flags);
3762 static void dgap_tty_unthrottle(struct tty_struct *tty)
3765 struct channel_t *ch;
3770 if (!tty || tty->magic != TTY_MAGIC)
3773 un = tty->driver_data;
3774 if (!un || un->magic != DGAP_UNIT_MAGIC)
3778 if (!ch || ch->magic != DGAP_CHANNEL_MAGIC)
3782 if (!bd || bd->magic != DGAP_BOARD_MAGIC)
3785 DGAP_LOCK(bd->bd_lock, lock_flags);
3786 DGAP_LOCK(ch->ch_lock, lock_flags2);
3788 ch->ch_flags &= ~(CH_RXBLOCK);
3791 dgap_cmdw(ch, RRESUME, 0, 0);
3794 DGAP_UNLOCK(ch->ch_lock, lock_flags2);
3795 DGAP_UNLOCK(bd->bd_lock, lock_flags);
3798 static void dgap_tty_start(struct tty_struct *tty)
3801 struct channel_t *ch;
3806 if (!tty || tty->magic != TTY_MAGIC)
3809 un = tty->driver_data;
3810 if (!un || un->magic != DGAP_UNIT_MAGIC)
3814 if (!ch || ch->magic != DGAP_CHANNEL_MAGIC)
3818 if (!bd || bd->magic != DGAP_BOARD_MAGIC)
3821 DGAP_LOCK(bd->bd_lock, lock_flags);
3822 DGAP_LOCK(ch->ch_lock, lock_flags2);
3824 dgap_cmdw(ch, RESUMETX, 0, 0);
3826 DGAP_UNLOCK(ch->ch_lock, lock_flags2);
3827 DGAP_UNLOCK(bd->bd_lock, lock_flags);
3831 static void dgap_tty_stop(struct tty_struct *tty)
3834 struct channel_t *ch;
3839 if (!tty || tty->magic != TTY_MAGIC)
3842 un = tty->driver_data;
3843 if (!un || un->magic != DGAP_UNIT_MAGIC)
3847 if (!ch || ch->magic != DGAP_CHANNEL_MAGIC)
3851 if (!bd || bd->magic != DGAP_BOARD_MAGIC)
3854 DGAP_LOCK(bd->bd_lock, lock_flags);
3855 DGAP_LOCK(ch->ch_lock, lock_flags2);
3857 dgap_cmdw(ch, PAUSETX, 0, 0);
3859 DGAP_UNLOCK(ch->ch_lock, lock_flags2);
3860 DGAP_UNLOCK(bd->bd_lock, lock_flags);
3865 * dgap_tty_flush_chars()
3867 * Flush the cook buffer
3869 * Note to self, and any other poor souls who venture here:
3871 * flush in this case DOES NOT mean dispose of the data.
3872 * instead, it means "stop buffering and send it if you
3873 * haven't already." Just guess how I figured that out... SRW 2-Jun-98
3875 * It is also always called in interrupt context - JAR 8-Sept-99
3877 static void dgap_tty_flush_chars(struct tty_struct *tty)
3880 struct channel_t *ch;
3885 if (!tty || tty->magic != TTY_MAGIC)
3888 un = tty->driver_data;
3889 if (!un || un->magic != DGAP_UNIT_MAGIC)
3893 if (!ch || ch->magic != DGAP_CHANNEL_MAGIC)
3897 if (!bd || bd->magic != DGAP_BOARD_MAGIC)
3900 DGAP_LOCK(bd->bd_lock, lock_flags);
3901 DGAP_LOCK(ch->ch_lock, lock_flags2);
3903 /* TODO: Do something here */
3905 DGAP_UNLOCK(ch->ch_lock, lock_flags2);
3906 DGAP_UNLOCK(bd->bd_lock, lock_flags);
3910 * dgap_tty_flush_buffer()
3912 * Flush Tx buffer (make in == out)
3914 static void dgap_tty_flush_buffer(struct tty_struct *tty)
3917 struct channel_t *ch;
3923 if (!tty || tty->magic != TTY_MAGIC)
3926 un = tty->driver_data;
3927 if (!un || un->magic != DGAP_UNIT_MAGIC)
3931 if (!ch || ch->magic != DGAP_CHANNEL_MAGIC)
3935 if (!bd || bd->magic != DGAP_BOARD_MAGIC)
3938 DGAP_LOCK(bd->bd_lock, lock_flags);
3939 DGAP_LOCK(ch->ch_lock, lock_flags2);
3941 ch->ch_flags &= ~CH_STOP;
3942 head = readw(&(ch->ch_bs->tx_head));
3943 dgap_cmdw(ch, FLUSHTX, (u16) head, 0);
3944 dgap_cmdw(ch, RESUMETX, 0, 0);
3945 if (ch->ch_tun.un_flags & (UN_LOW|UN_EMPTY)) {
3946 ch->ch_tun.un_flags &= ~(UN_LOW|UN_EMPTY);
3947 wake_up_interruptible(&ch->ch_tun.un_flags_wait);
3949 if (ch->ch_pun.un_flags & (UN_LOW|UN_EMPTY)) {
3950 ch->ch_pun.un_flags &= ~(UN_LOW|UN_EMPTY);
3951 wake_up_interruptible(&ch->ch_pun.un_flags_wait);
3954 DGAP_UNLOCK(ch->ch_lock, lock_flags2);
3955 DGAP_UNLOCK(bd->bd_lock, lock_flags);
3956 if (waitqueue_active(&tty->write_wait))
3957 wake_up_interruptible(&tty->write_wait);
3961 /*****************************************************************************
3963 * The IOCTL function and all of its helpers
3965 *****************************************************************************/
3970 * The usual assortment of ioctl's
3972 static int dgap_tty_ioctl(struct tty_struct *tty, unsigned int cmd,
3976 struct channel_t *ch;
3980 ulong lock_flags = 0;
3981 ulong lock_flags2 = 0;
3982 void __user *uarg = (void __user *) arg;
3984 if (!tty || tty->magic != TTY_MAGIC)
3987 un = tty->driver_data;
3988 if (!un || un->magic != DGAP_UNIT_MAGIC)
3992 if (!ch || ch->magic != DGAP_CHANNEL_MAGIC)
3996 if (!bd || bd->magic != DGAP_BOARD_MAGIC)
3999 DGAP_LOCK(bd->bd_lock, lock_flags);
4000 DGAP_LOCK(ch->ch_lock, lock_flags2);
4002 if (un->un_open_count <= 0) {
4003 DGAP_UNLOCK(ch->ch_lock, lock_flags2);
4004 DGAP_UNLOCK(bd->bd_lock, lock_flags);
4010 /* Here are all the standard ioctl's that we MUST implement */
4014 * TCSBRK is SVID version: non-zero arg --> no break
4015 * this behaviour is exploited by tcdrain().
4017 * According to POSIX.1 spec (7.2.2.1.2) breaks should be
4018 * between 0.25 and 0.5 seconds so we'll ask for something
4019 * in the middle: 0.375 seconds.
4021 rc = tty_check_change(tty);
4022 DGAP_UNLOCK(ch->ch_lock, lock_flags2);
4023 DGAP_UNLOCK(bd->bd_lock, lock_flags);
4027 rc = dgap_wait_for_drain(tty);
4032 DGAP_LOCK(bd->bd_lock, lock_flags);
4033 DGAP_LOCK(ch->ch_lock, lock_flags2);
4035 if (((cmd == TCSBRK) && (!arg)) || (cmd == TCSBRKP))
4036 dgap_cmdw(ch, SBREAK, (u16) SBREAK_TIME, 0);
4038 DGAP_UNLOCK(ch->ch_lock, lock_flags2);
4039 DGAP_UNLOCK(bd->bd_lock, lock_flags);
4044 /* support for POSIX tcsendbreak()
4046 * According to POSIX.1 spec (7.2.2.1.2) breaks should be
4047 * between 0.25 and 0.5 seconds so we'll ask for something
4048 * in the middle: 0.375 seconds.
4050 rc = tty_check_change(tty);
4051 DGAP_UNLOCK(ch->ch_lock, lock_flags2);
4052 DGAP_UNLOCK(bd->bd_lock, lock_flags);
4056 rc = dgap_wait_for_drain(tty);
4060 DGAP_LOCK(bd->bd_lock, lock_flags);
4061 DGAP_LOCK(ch->ch_lock, lock_flags2);
4063 dgap_cmdw(ch, SBREAK, (u16) SBREAK_TIME, 0);
4065 DGAP_UNLOCK(ch->ch_lock, lock_flags2);
4066 DGAP_UNLOCK(bd->bd_lock, lock_flags);
4072 * FEP5 doesn't support turning on a break unconditionally.
4073 * The FEP5 device will stop sending a break automatically
4074 * after the specified time value that was sent when turning on
4077 rc = tty_check_change(tty);
4078 DGAP_UNLOCK(ch->ch_lock, lock_flags2);
4079 DGAP_UNLOCK(bd->bd_lock, lock_flags);
4083 rc = dgap_wait_for_drain(tty);
4087 DGAP_LOCK(bd->bd_lock, lock_flags);
4088 DGAP_LOCK(ch->ch_lock, lock_flags2);
4090 dgap_cmdw(ch, SBREAK, (u16) SBREAK_TIME, 0);
4092 DGAP_UNLOCK(ch->ch_lock, lock_flags2);
4093 DGAP_UNLOCK(bd->bd_lock, lock_flags);
4099 * FEP5 doesn't support turning off a break unconditionally.
4100 * The FEP5 device will stop sending a break automatically
4101 * after the specified time value that was sent when turning on
4104 DGAP_UNLOCK(ch->ch_lock, lock_flags2);
4105 DGAP_UNLOCK(bd->bd_lock, lock_flags);
4110 DGAP_UNLOCK(ch->ch_lock, lock_flags2);
4111 DGAP_UNLOCK(bd->bd_lock, lock_flags);
4113 rc = put_user(C_CLOCAL(tty) ? 1 : 0, (unsigned long __user *) arg);
4117 DGAP_UNLOCK(ch->ch_lock, lock_flags2);
4118 DGAP_UNLOCK(bd->bd_lock, lock_flags);
4120 rc = get_user(arg, (unsigned long __user *) arg);
4124 DGAP_LOCK(bd->bd_lock, lock_flags);
4125 DGAP_LOCK(ch->ch_lock, lock_flags2);
4126 tty->termios.c_cflag = ((tty->termios.c_cflag & ~CLOCAL) | (arg ? CLOCAL : 0));
4128 DGAP_UNLOCK(ch->ch_lock, lock_flags2);
4129 DGAP_UNLOCK(bd->bd_lock, lock_flags);
4134 DGAP_UNLOCK(ch->ch_lock, lock_flags2);
4135 DGAP_UNLOCK(bd->bd_lock, lock_flags);
4136 return dgap_get_modem_info(ch, uarg);
4141 DGAP_UNLOCK(ch->ch_lock, lock_flags2);
4142 DGAP_UNLOCK(bd->bd_lock, lock_flags);
4143 return dgap_set_modem_info(tty, cmd, uarg);
4146 * Here are any additional ioctl's that we want to implement
4151 * The linux tty driver doesn't have a flush
4152 * input routine for the driver, assuming all backed
4153 * up data is in the line disc. buffers. However,
4154 * we all know that's not the case. Here, we
4155 * act on the ioctl, but then lie and say we didn't
4156 * so the line discipline will process the flush
4159 rc = tty_check_change(tty);
4161 DGAP_UNLOCK(ch->ch_lock, lock_flags2);
4162 DGAP_UNLOCK(bd->bd_lock, lock_flags);
4166 if ((arg == TCIFLUSH) || (arg == TCIOFLUSH)) {
4167 if (!(un->un_type == DGAP_PRINT)) {
4168 head = readw(&(ch->ch_bs->rx_head));
4169 writew(head, &(ch->ch_bs->rx_tail));
4170 writeb(0, &(ch->ch_bs->orun));
4174 if ((arg == TCOFLUSH) || (arg == TCIOFLUSH)) {
4175 ch->ch_flags &= ~CH_STOP;
4176 head = readw(&(ch->ch_bs->tx_head));
4177 dgap_cmdw(ch, FLUSHTX, (u16) head, 0);
4178 dgap_cmdw(ch, RESUMETX, 0, 0);
4179 if (ch->ch_tun.un_flags & (UN_LOW|UN_EMPTY)) {
4180 ch->ch_tun.un_flags &= ~(UN_LOW|UN_EMPTY);
4181 wake_up_interruptible(&ch->ch_tun.un_flags_wait);
4183 if (ch->ch_pun.un_flags & (UN_LOW|UN_EMPTY)) {
4184 ch->ch_pun.un_flags &= ~(UN_LOW|UN_EMPTY);
4185 wake_up_interruptible(&ch->ch_pun.un_flags_wait);
4187 if (waitqueue_active(&tty->write_wait))
4188 wake_up_interruptible(&tty->write_wait);
4190 /* Can't hold any locks when calling tty_wakeup! */
4191 DGAP_UNLOCK(ch->ch_lock, lock_flags2);
4192 DGAP_UNLOCK(bd->bd_lock, lock_flags);
4194 DGAP_LOCK(bd->bd_lock, lock_flags);
4195 DGAP_LOCK(ch->ch_lock, lock_flags2);
4198 /* pretend we didn't recognize this IOCTL */
4199 DGAP_UNLOCK(ch->ch_lock, lock_flags2);
4200 DGAP_UNLOCK(bd->bd_lock, lock_flags);
4202 return -ENOIOCTLCMD;
4207 * The linux tty driver doesn't have a flush
4208 * input routine for the driver, assuming all backed
4209 * up data is in the line disc. buffers. However,
4210 * we all know that's not the case. Here, we
4211 * act on the ioctl, but then lie and say we didn't
4212 * so the line discipline will process the flush
4215 if (cmd == TCSETSF) {
4217 ch->ch_flags &= ~CH_STOP;
4218 head = readw(&(ch->ch_bs->rx_head));
4219 writew(head, &(ch->ch_bs->rx_tail));
4222 /* now wait for all the output to drain */
4223 DGAP_UNLOCK(ch->ch_lock, lock_flags2);
4224 DGAP_UNLOCK(bd->bd_lock, lock_flags);
4225 rc = dgap_wait_for_drain(tty);
4229 /* pretend we didn't recognize this */
4230 return -ENOIOCTLCMD;
4234 DGAP_UNLOCK(ch->ch_lock, lock_flags2);
4235 DGAP_UNLOCK(bd->bd_lock, lock_flags);
4236 rc = dgap_wait_for_drain(tty);
4240 /* pretend we didn't recognize this */
4241 return -ENOIOCTLCMD;
4245 * The Linux Line Discipline (LD) would do this for us if we
4246 * let it, but we have the special firmware options to do this
4247 * the "right way" regardless of hardware or software flow
4248 * control so we'll do it outselves instead of letting the LD
4251 rc = tty_check_change(tty);
4253 DGAP_UNLOCK(ch->ch_lock, lock_flags2);
4254 DGAP_UNLOCK(bd->bd_lock, lock_flags);
4261 DGAP_UNLOCK(ch->ch_lock, lock_flags2);
4262 DGAP_UNLOCK(bd->bd_lock, lock_flags);
4263 dgap_tty_start(tty);
4266 DGAP_UNLOCK(ch->ch_lock, lock_flags2);
4267 DGAP_UNLOCK(bd->bd_lock, lock_flags);
4271 DGAP_UNLOCK(ch->ch_lock, lock_flags2);
4272 DGAP_UNLOCK(bd->bd_lock, lock_flags);
4273 /* Make the ld do it */
4274 return -ENOIOCTLCMD;
4276 DGAP_UNLOCK(ch->ch_lock, lock_flags2);
4277 DGAP_UNLOCK(bd->bd_lock, lock_flags);
4278 /* Make the ld do it */
4279 return -ENOIOCTLCMD;
4281 DGAP_UNLOCK(ch->ch_lock, lock_flags2);
4282 DGAP_UNLOCK(bd->bd_lock, lock_flags);
4287 /* get information for ditty */
4288 DGAP_UNLOCK(ch->ch_lock, lock_flags2);
4289 DGAP_UNLOCK(bd->bd_lock, lock_flags);
4290 return dgap_tty_digigeta(tty, uarg);
4295 /* set information for ditty */
4296 if (cmd == (DIGI_SETAW)) {
4298 DGAP_UNLOCK(ch->ch_lock, lock_flags2);
4299 DGAP_UNLOCK(bd->bd_lock, lock_flags);
4300 rc = dgap_wait_for_drain(tty);
4303 DGAP_LOCK(bd->bd_lock, lock_flags);
4304 DGAP_LOCK(ch->ch_lock, lock_flags2);
4306 tty_ldisc_flush(tty);
4310 DGAP_UNLOCK(ch->ch_lock, lock_flags2);
4311 DGAP_UNLOCK(bd->bd_lock, lock_flags);
4312 return dgap_tty_digiseta(tty, uarg);
4315 DGAP_UNLOCK(ch->ch_lock, lock_flags2);
4316 DGAP_UNLOCK(bd->bd_lock, lock_flags);
4317 return dgap_tty_digigetedelay(tty, uarg);
4320 DGAP_UNLOCK(ch->ch_lock, lock_flags2);
4321 DGAP_UNLOCK(bd->bd_lock, lock_flags);
4322 return dgap_tty_digisetedelay(tty, uarg);
4324 case DIGI_GETCUSTOMBAUD:
4325 DGAP_UNLOCK(ch->ch_lock, lock_flags2);
4326 DGAP_UNLOCK(bd->bd_lock, lock_flags);
4327 return dgap_tty_digigetcustombaud(tty, uarg);
4329 case DIGI_SETCUSTOMBAUD:
4330 DGAP_UNLOCK(ch->ch_lock, lock_flags2);
4331 DGAP_UNLOCK(bd->bd_lock, lock_flags);
4332 return dgap_tty_digisetcustombaud(tty, uarg);
4334 case DIGI_RESET_PORT:
4335 dgap_firmware_reset_port(ch);
4337 DGAP_UNLOCK(ch->ch_lock, lock_flags2);
4338 DGAP_UNLOCK(bd->bd_lock, lock_flags);
4342 DGAP_UNLOCK(ch->ch_lock, lock_flags2);
4343 DGAP_UNLOCK(bd->bd_lock, lock_flags);
4345 return -ENOIOCTLCMD;
4349 static int dgap_after_config_loaded(int board)
4352 * Initialize KME waitqueues...
4354 init_waitqueue_head(&(dgap_Board[board]->kme_wait));
4357 * allocate flip buffer for board.
4359 dgap_Board[board]->flipbuf = kmalloc(MYFLIPLEN, GFP_ATOMIC);
4360 if (!dgap_Board[board]->flipbuf)
4363 dgap_Board[board]->flipflagbuf = kmalloc(MYFLIPLEN, GFP_ATOMIC);
4364 if (!dgap_Board[board]->flipflagbuf) {
4365 kfree(dgap_Board[board]->flipbuf);
4373 * Create pr and tty device entries
4375 static int dgap_tty_register_ports(struct board_t *brd)
4377 struct channel_t *ch;
4380 brd->SerialPorts = kcalloc(brd->nasync, sizeof(*brd->SerialPorts),
4382 if (brd->SerialPorts == NULL)
4384 for (i = 0; i < brd->nasync; i++)
4385 tty_port_init(&brd->SerialPorts[i]);
4387 brd->PrinterPorts = kcalloc(brd->nasync, sizeof(*brd->PrinterPorts),
4389 if (brd->PrinterPorts == NULL) {
4390 kfree(brd->SerialPorts);
4393 for (i = 0; i < brd->nasync; i++)
4394 tty_port_init(&brd->PrinterPorts[i]);
4396 ch = brd->channels[0];
4397 for (i = 0; i < brd->nasync; i++, ch = brd->channels[i]) {
4399 struct device *classp;
4401 classp = tty_port_register_device(&brd->SerialPorts[i],
4403 brd->firstminor + i, NULL);
4405 dgap_create_tty_sysfs(&ch->ch_tun, classp);
4406 ch->ch_tun.un_sysfs = classp;
4408 classp = tty_port_register_device(&brd->PrinterPorts[i],
4410 brd->firstminor + i, NULL);
4412 dgap_create_tty_sysfs(&ch->ch_pun, classp);
4413 ch->ch_pun.un_sysfs = classp;
4415 dgap_create_ports_sysfiles(brd);
4421 * Copies the BIOS code from the user to the board,
4422 * and starts the BIOS running.
4424 static void dgap_do_bios_load(struct board_t *brd, uchar __user *ubios, int len)
4430 if (!brd || (brd->magic != DGAP_BOARD_MAGIC) || !brd->re_map_membase)
4433 addr = brd->re_map_membase;
4438 for (i = 0; i < 16; i++)
4439 writeb(0, addr + POSTAREA + i);
4445 memcpy_toio(addr + offset, ubios, len);
4447 writel(0x0bf00401, addr);
4448 writel(0, (addr + 4));
4450 /* Clear the reset, and change states. */
4451 writeb(FEPCLR, brd->re_map_port);
4455 * Checks to see if the BIOS completed running on the card.
4457 static void dgap_do_wait_for_bios(struct board_t *brd)
4464 if (!brd || (brd->magic != DGAP_BOARD_MAGIC) || !brd->re_map_membase)
4467 addr = brd->re_map_membase;
4468 word = readw(addr + POSTAREA);
4471 * It can take 5-6 seconds for a board to
4472 * pass the bios self test and post results.
4473 * Give it 10 seconds.
4475 brd->wait_for_bios = 0;
4476 while (brd->wait_for_bios < 1000) {
4477 /* Check to see if BIOS thinks board is good. (GD). */
4478 if (word == *(u16 *) "GD") {
4479 brd->state = FINISHED_BIOS_LOAD;
4482 msleep_interruptible(10);
4483 brd->wait_for_bios++;
4484 word = readw(addr + POSTAREA);
4487 /* Gave up on board after too long of time taken */
4488 err1 = readw(addr + SEQUENCE);
4489 err2 = readw(addr + ERROR);
4490 pr_warn("dgap: %s failed diagnostics. Error #(%x,%x).\n",
4491 brd->name, err1, err2);
4492 brd->state = BOARD_FAILED;
4493 brd->dpastatus = BD_NOBIOS;
4497 * Copies the FEP code from the user to the board,
4498 * and starts the FEP running.
4500 static void dgap_do_fep_load(struct board_t *brd, uchar *ufep, int len)
4505 if (!brd || (brd->magic != DGAP_BOARD_MAGIC) || !brd->re_map_membase)
4508 addr = brd->re_map_membase;
4514 memcpy_toio(addr + offset, ufep, len);
4517 * If board is a concentrator product, we need to give
4518 * it its config string describing how the concentrators look.
4520 if ((brd->type == PCX) || (brd->type == PEPC)) {
4522 uchar *config, *xconfig;
4525 xconfig = dgap_create_config_string(brd, string);
4527 /* Write string to board memory */
4528 config = addr + CONFIG;
4529 for (; i < CONFIGSIZE; i++, config++, xconfig++) {
4530 writeb(*xconfig, config);
4531 if ((*xconfig & 0xff) == 0xff)
4536 writel(0xbfc01004, (addr + 0xc34));
4537 writel(0x3, (addr + 0xc30));
4542 * Waits for the FEP to report thats its ready for us to use.
4544 static void dgap_do_wait_for_fep(struct board_t *brd)
4551 if (!brd || (brd->magic != DGAP_BOARD_MAGIC) || !brd->re_map_membase)
4554 addr = brd->re_map_membase;
4555 word = readw(addr + FEPSTAT);
4558 * It can take 2-3 seconds for the FEP to
4559 * be up and running. Give it 5 secs.
4561 brd->wait_for_fep = 0;
4562 while (brd->wait_for_fep < 500) {
4563 /* Check to see if FEP is up and running now. */
4564 if (word == *(u16 *) "OS") {
4565 brd->state = FINISHED_FEP_LOAD;
4567 * Check to see if the board can support FEP5+ commands.
4569 word = readw(addr + FEP5_PLUS);
4570 if (word == *(u16 *) "5A")
4571 brd->bd_flags |= BD_FEP5PLUS;
4575 msleep_interruptible(10);
4576 brd->wait_for_fep++;
4577 word = readw(addr + FEPSTAT);
4580 /* Gave up on board after too long of time taken */
4581 err1 = readw(addr + SEQUENCE);
4582 err2 = readw(addr + ERROR);
4583 pr_warn("dgap: FEPOS for %s not functioning. Error #(%x,%x).\n",
4584 brd->name, err1, err2);
4585 brd->state = BOARD_FAILED;
4586 brd->dpastatus = BD_NOFEP;
4590 * Physically forces the FEP5 card to reset itself.
4592 static void dgap_do_reset_board(struct board_t *brd)
4599 if (!brd || (brd->magic != DGAP_BOARD_MAGIC) ||
4600 !brd->re_map_membase || !brd->re_map_port)
4603 /* FEPRST does not vary among supported boards */
4604 writeb(FEPRST, brd->re_map_port);
4606 for (i = 0; i <= 1000; i++) {
4607 check = readb(brd->re_map_port) & 0xe;
4608 if (check == FEPRST)
4614 pr_warn("dgap: Board not resetting... Failing board.\n");
4615 brd->state = BOARD_FAILED;
4616 brd->dpastatus = BD_NOFEP;
4621 * Make sure there really is memory out there.
4623 writel(0xa55a3cc3, (brd->re_map_membase + LOWMEM));
4624 writel(0x5aa5c33c, (brd->re_map_membase + HIGHMEM));
4625 check1 = readl(brd->re_map_membase + LOWMEM);
4626 check2 = readl(brd->re_map_membase + HIGHMEM);
4628 if ((check1 != 0xa55a3cc3) || (check2 != 0x5aa5c33c)) {
4629 pr_warn("dgap: No memory at %p for board.\n",
4630 brd->re_map_membase);
4631 brd->state = BOARD_FAILED;
4632 brd->dpastatus = BD_NOFEP;
4636 if (brd->state != BOARD_FAILED)
4637 brd->state = FINISHED_RESET;
4640 #ifdef DIGI_CONCENTRATORS_SUPPORTED
4642 * Sends a concentrator image into the FEP5 board.
4644 static void dgap_do_conc_load(struct board_t *brd, uchar *uaddr, int len)
4648 struct downld_t *to_dp;
4650 if (!brd || (brd->magic != DGAP_BOARD_MAGIC) || !brd->re_map_membase)
4653 vaddr = brd->re_map_membase;
4655 offset = readw((u16 *) (vaddr + DOWNREQ));
4656 to_dp = (struct downld_t *) (vaddr + (int) offset);
4657 memcpy_toio(to_dp, uaddr, len);
4659 /* Tell card we have data for it */
4660 writew(0, vaddr + (DOWNREQ));
4662 brd->conc_dl_status = NO_PENDING_CONCENTRATOR_REQUESTS;
4666 #define EXPANSION_ROM_SIZE (64 * 1024)
4667 #define FEP5_ROM_MAGIC (0xFEFFFFFF)
4669 static void dgap_get_vpd(struct board_t *brd)
4681 * Poke the magic number at the PCI Rom Address location.
4682 * If VPD is supported, the value read from that address
4685 magic = FEP5_ROM_MAGIC;
4686 pci_write_config_dword(brd->pdev, PCI_ROM_ADDRESS, magic);
4687 pci_read_config_dword(brd->pdev, PCI_ROM_ADDRESS, &magic);
4689 /* VPD not supported, bail */
4694 * To get to the OTPROM memory, we have to send the boards base
4695 * address or'ed with 1 into the PCI Rom Address location.
4697 magic = brd->membase | 0x01;
4698 pci_write_config_dword(brd->pdev, PCI_ROM_ADDRESS, magic);
4699 pci_read_config_dword(brd->pdev, PCI_ROM_ADDRESS, &magic);
4701 byte1 = readb(brd->re_map_membase);
4702 byte2 = readb(brd->re_map_membase + 1);
4705 * If the board correctly swapped to the OTPROM memory,
4706 * the first 2 bytes (header) should be 0x55, 0xAA
4708 if (byte1 == 0x55 && byte2 == 0xAA) {
4713 * We have to run through all the OTPROM memory looking
4714 * for the VPD offset.
4716 while (base_offset <= EXPANSION_ROM_SIZE) {
4719 * Lots of magic numbers here.
4721 * The VPD offset is located inside the ROM Data Structure.
4722 * We also have to remember the length of each
4723 * ROM Data Structure, so we can "hop" to the next
4724 * entry if the VPD isn't in the current
4725 * ROM Data Structure.
4727 rom_offset = readw(brd->re_map_membase + base_offset + 0x18);
4728 image_length = readw(brd->re_map_membase + rom_offset + 0x10) * 512;
4729 vpd_offset = readw(brd->re_map_membase + rom_offset + 0x08);
4731 /* Found the VPD entry */
4735 /* We didn't find a VPD entry, go to next ROM entry. */
4736 base_offset += image_length;
4738 byte1 = readb(brd->re_map_membase + base_offset);
4739 byte2 = readb(brd->re_map_membase + base_offset + 1);
4742 * If the new ROM offset doesn't have 0x55, 0xAA
4743 * as its header, we have run out of ROM.
4745 if (byte1 != 0x55 || byte2 != 0xAA)
4750 * If we have a VPD offset, then mark the board
4751 * as having a valid VPD, and copy VPDSIZE (512) bytes of
4752 * that VPD to the buffer we have in our board structure.
4755 brd->bd_flags |= BD_HAS_VPD;
4756 for (i = 0; i < VPDSIZE; i++)
4757 brd->vpd[i] = readb(brd->re_map_membase + vpd_offset + i);
4762 * We MUST poke the magic number at the PCI Rom Address location again.
4763 * This makes the card report the regular board memory back to us,
4764 * rather than the OTPROM memory.
4766 magic = FEP5_ROM_MAGIC;
4767 pci_write_config_dword(brd->pdev, PCI_ROM_ADDRESS, magic);
4771 * Our board poller function.
4773 static void dgap_poll_tasklet(unsigned long data)
4775 struct board_t *bd = (struct board_t *) data;
4781 if (!bd || (bd->magic != DGAP_BOARD_MAGIC))
4784 if (bd->inhibit_poller)
4787 DGAP_LOCK(bd->bd_lock, lock_flags);
4789 vaddr = bd->re_map_membase;
4792 * If board is ready, parse deeper to see if there is anything to do.
4794 if (bd->state == BOARD_READY) {
4796 struct ev_t *eaddr = NULL;
4798 if (!bd->re_map_membase) {
4799 DGAP_UNLOCK(bd->bd_lock, lock_flags);
4802 if (!bd->re_map_port) {
4803 DGAP_UNLOCK(bd->bd_lock, lock_flags);
4810 eaddr = (struct ev_t *) (vaddr + EVBUF);
4812 /* Get our head and tail */
4813 head = readw(&(eaddr->ev_head));
4814 tail = readw(&(eaddr->ev_tail));
4817 * If there is an event pending. Go service it.
4820 DGAP_UNLOCK(bd->bd_lock, lock_flags);
4822 DGAP_LOCK(bd->bd_lock, lock_flags);
4827 * If board is doing interrupts, ACK the interrupt.
4829 if (bd && bd->intr_running)
4830 readb(bd->re_map_port + 2);
4832 DGAP_UNLOCK(bd->bd_lock, lock_flags);
4836 /* Our state machine to get the board up and running */
4839 if (bd->state == NEED_RESET) {
4844 dgap_do_reset_board(bd);
4847 /* Move to next state */
4848 if (bd->state == FINISHED_RESET)
4849 bd->state = NEED_CONFIG;
4851 if (bd->state == NEED_CONFIG) {
4853 * Match this board to a config the user created for us.
4855 bd->bd_config = dgap_find_config(bd->type, bd->pci_bus, bd->pci_slot);
4858 * Because the 4 port Xr products share the same PCI ID
4859 * as the 8 port Xr products, if we receive a NULL config
4860 * back, and this is a PAPORT8 board, retry with a
4861 * PAPORT4 attempt as well.
4863 if (bd->type == PAPORT8 && !bd->bd_config)
4864 bd->bd_config = dgap_find_config(PAPORT4, bd->pci_bus, bd->pci_slot);
4867 * Register the ttys (if any) into the kernel.
4870 bd->state = FINISHED_CONFIG;
4872 bd->state = CONFIG_NOT_FOUND;
4875 /* Move to next state */
4876 if (bd->state == FINISHED_CONFIG)
4877 bd->state = NEED_DEVICE_CREATION;
4879 /* Move to next state */
4880 if (bd->state == NEED_DEVICE_CREATION) {
4882 * Signal downloader, its got some work to do.
4884 DGAP_LOCK(dgap_dl_lock, lock_flags2);
4885 if (dgap_dl_action != 1) {
4887 wake_up_interruptible(&dgap_dl_wait);
4889 DGAP_UNLOCK(dgap_dl_lock, lock_flags2);
4892 /* Move to next state */
4893 if (bd->state == FINISHED_DEVICE_CREATION)
4894 bd->state = NEED_BIOS_LOAD;
4896 /* Move to next state */
4897 if (bd->state == NEED_BIOS_LOAD) {
4899 * Signal downloader, its got some work to do.
4901 DGAP_LOCK(dgap_dl_lock, lock_flags2);
4902 if (dgap_dl_action != 1) {
4904 wake_up_interruptible(&dgap_dl_wait);
4906 DGAP_UNLOCK(dgap_dl_lock, lock_flags2);
4909 /* Wait for BIOS to test board... */
4910 if (bd->state == WAIT_BIOS_LOAD)
4911 dgap_do_wait_for_bios(bd);
4913 /* Move to next state */
4914 if (bd->state == FINISHED_BIOS_LOAD) {
4915 bd->state = NEED_FEP_LOAD;
4918 * Signal downloader, its got some work to do.
4920 DGAP_LOCK(dgap_dl_lock, lock_flags2);
4921 if (dgap_dl_action != 1) {
4923 wake_up_interruptible(&dgap_dl_wait);
4925 DGAP_UNLOCK(dgap_dl_lock, lock_flags2);
4928 /* Wait for FEP to load on board... */
4929 if (bd->state == WAIT_FEP_LOAD)
4930 dgap_do_wait_for_fep(bd);
4932 /* Move to next state */
4933 if (bd->state == FINISHED_FEP_LOAD) {
4936 * Do tty device initialization.
4938 int rc = dgap_tty_init(bd);
4941 dgap_tty_uninit(bd);
4942 bd->state = BOARD_FAILED;
4943 bd->dpastatus = BD_NOFEP;
4945 bd->state = NEED_PROC_CREATION;
4948 * Signal downloader, its got some work to do.
4950 DGAP_LOCK(dgap_dl_lock, lock_flags2);
4951 if (dgap_dl_action != 1) {
4953 wake_up_interruptible(&dgap_dl_wait);
4955 DGAP_UNLOCK(dgap_dl_lock, lock_flags2);
4959 /* Move to next state */
4960 if (bd->state == FINISHED_PROC_CREATION) {
4962 bd->state = BOARD_READY;
4963 bd->dpastatus = BD_RUNNING;
4966 * If user requested the board to run in interrupt mode,
4967 * go and set it up on the board.
4969 if (bd->intr_used) {
4970 writew(1, (bd->re_map_membase + ENABLE_INTR));
4972 * Tell the board to poll the UARTS as fast as possible.
4974 writew(FEPPOLL_MIN, (bd->re_map_membase + FEPPOLL));
4975 bd->intr_running = 1;
4978 /* Wake up anyone waiting for board state to change to ready */
4979 wake_up_interruptible(&bd->state_wait);
4982 DGAP_UNLOCK(bd->bd_lock, lock_flags);
4985 /*=======================================================================
4987 * dgap_cmdb - Sends a 2 byte command to the FEP.
4989 * ch - Pointer to channel structure.
4990 * cmd - Command to be sent.
4991 * byte1 - Integer containing first byte to be sent.
4992 * byte2 - Integer containing second byte to be sent.
4993 * ncmds - Wait until ncmds or fewer cmds are left
4994 * in the cmd buffer before returning.
4996 *=======================================================================*/
4997 static void dgap_cmdb(struct channel_t *ch, uchar cmd, uchar byte1, uchar byte2, uint ncmds)
5000 struct cm_t *cm_addr = NULL;
5006 if (!ch || ch->magic != DGAP_CHANNEL_MAGIC)
5010 * Check if board is still alive.
5012 if (ch->ch_bd->state == BOARD_FAILED)
5016 * Make sure the pointers are in range before
5017 * writing to the FEP memory.
5019 vaddr = ch->ch_bd->re_map_membase;
5024 cm_addr = (struct cm_t *) (vaddr + CMDBUF);
5025 head = readw(&(cm_addr->cm_head));
5028 * Forget it if pointers out of range.
5030 if (head >= (CMDMAX - CMDSTART) || (head & 03)) {
5031 ch->ch_bd->state = BOARD_FAILED;
5036 * Put the data in the circular command buffer.
5038 writeb(cmd, (char *) (vaddr + head + CMDSTART + 0));
5039 writeb((uchar) ch->ch_portnum, (char *) (vaddr + head + CMDSTART + 1));
5040 writeb(byte1, (char *) (vaddr + head + CMDSTART + 2));
5041 writeb(byte2, (char *) (vaddr + head + CMDSTART + 3));
5043 head = (head + 4) & (CMDMAX - CMDSTART - 4);
5045 writew(head, &(cm_addr->cm_head));
5048 * Wait if necessary before updating the head
5049 * pointer to limit the number of outstanding
5050 * commands to the FEP. If the time spent waiting
5051 * is outlandish, declare the FEP dead.
5053 for (count = dgap_count ;;) {
5055 head = readw(&(cm_addr->cm_head));
5056 tail = readw(&(cm_addr->cm_tail));
5058 n = (head - tail) & (CMDMAX - CMDSTART - 4);
5060 if (n <= ncmds * sizeof(struct cm_t))
5064 ch->ch_bd->state = BOARD_FAILED;
5071 /*=======================================================================
5073 * dgap_cmdw - Sends a 1 word command to the FEP.
5075 * ch - Pointer to channel structure.
5076 * cmd - Command to be sent.
5077 * word - Integer containing word to be sent.
5078 * ncmds - Wait until ncmds or fewer cmds are left
5079 * in the cmd buffer before returning.
5081 *=======================================================================*/
5082 static void dgap_cmdw(struct channel_t *ch, uchar cmd, u16 word, uint ncmds)
5085 struct cm_t *cm_addr = NULL;
5091 if (!ch || ch->magic != DGAP_CHANNEL_MAGIC)
5095 * Check if board is still alive.
5097 if (ch->ch_bd->state == BOARD_FAILED)
5101 * Make sure the pointers are in range before
5102 * writing to the FEP memory.
5104 vaddr = ch->ch_bd->re_map_membase;
5108 cm_addr = (struct cm_t *) (vaddr + CMDBUF);
5109 head = readw(&(cm_addr->cm_head));
5112 * Forget it if pointers out of range.
5114 if (head >= (CMDMAX - CMDSTART) || (head & 03)) {
5115 ch->ch_bd->state = BOARD_FAILED;
5120 * Put the data in the circular command buffer.
5122 writeb(cmd, (char *) (vaddr + head + CMDSTART + 0));
5123 writeb((uchar) ch->ch_portnum, (char *) (vaddr + head + CMDSTART + 1));
5124 writew((u16) word, (char *) (vaddr + head + CMDSTART + 2));
5126 head = (head + 4) & (CMDMAX - CMDSTART - 4);
5128 writew(head, &(cm_addr->cm_head));
5131 * Wait if necessary before updating the head
5132 * pointer to limit the number of outstanding
5133 * commands to the FEP. If the time spent waiting
5134 * is outlandish, declare the FEP dead.
5136 for (count = dgap_count ;;) {
5138 head = readw(&(cm_addr->cm_head));
5139 tail = readw(&(cm_addr->cm_tail));
5141 n = (head - tail) & (CMDMAX - CMDSTART - 4);
5143 if (n <= ncmds * sizeof(struct cm_t))
5147 ch->ch_bd->state = BOARD_FAILED;
5154 /*=======================================================================
5156 * dgap_cmdw_ext - Sends a extended word command to the FEP.
5158 * ch - Pointer to channel structure.
5159 * cmd - Command to be sent.
5160 * word - Integer containing word to be sent.
5161 * ncmds - Wait until ncmds or fewer cmds are left
5162 * in the cmd buffer before returning.
5164 *=======================================================================*/
5165 static void dgap_cmdw_ext(struct channel_t *ch, u16 cmd, u16 word, uint ncmds)
5168 struct cm_t *cm_addr = NULL;
5174 if (!ch || ch->magic != DGAP_CHANNEL_MAGIC)
5178 * Check if board is still alive.
5180 if (ch->ch_bd->state == BOARD_FAILED)
5184 * Make sure the pointers are in range before
5185 * writing to the FEP memory.
5187 vaddr = ch->ch_bd->re_map_membase;
5191 cm_addr = (struct cm_t *) (vaddr + CMDBUF);
5192 head = readw(&(cm_addr->cm_head));
5195 * Forget it if pointers out of range.
5197 if (head >= (CMDMAX - CMDSTART) || (head & 03)) {
5198 ch->ch_bd->state = BOARD_FAILED;
5203 * Put the data in the circular command buffer.
5206 /* Write an FF to tell the FEP that we want an extended command */
5207 writeb((uchar) 0xff, (char *) (vaddr + head + CMDSTART + 0));
5209 writeb((uchar) ch->ch_portnum, (uchar *) (vaddr + head + CMDSTART + 1));
5210 writew((u16) cmd, (char *) (vaddr + head + CMDSTART + 2));
5213 * If the second part of the command won't fit,
5214 * put it at the beginning of the circular buffer.
5216 if (((head + 4) >= ((CMDMAX - CMDSTART)) || (head & 03)))
5217 writew((u16) word, (char *) (vaddr + CMDSTART));
5219 writew((u16) word, (char *) (vaddr + head + CMDSTART + 4));
5221 head = (head + 8) & (CMDMAX - CMDSTART - 4);
5223 writew(head, &(cm_addr->cm_head));
5226 * Wait if necessary before updating the head
5227 * pointer to limit the number of outstanding
5228 * commands to the FEP. If the time spent waiting
5229 * is outlandish, declare the FEP dead.
5231 for (count = dgap_count ;;) {
5233 head = readw(&(cm_addr->cm_head));
5234 tail = readw(&(cm_addr->cm_tail));
5236 n = (head - tail) & (CMDMAX - CMDSTART - 4);
5238 if (n <= ncmds * sizeof(struct cm_t))
5242 ch->ch_bd->state = BOARD_FAILED;
5249 /*=======================================================================
5251 * dgap_wmove - Write data to FEP buffer.
5253 * ch - Pointer to channel structure.
5254 * buf - Poiter to characters to be moved.
5255 * cnt - Number of characters to move.
5257 *=======================================================================*/
5258 static void dgap_wmove(struct channel_t *ch, char *buf, uint cnt)
5265 if (!ch || ch->magic != DGAP_CHANNEL_MAGIC)
5272 head = readw(&(bs->tx_head));
5275 * If pointers are out of range, just return.
5277 if ((cnt > ch->ch_tsize) ||
5278 (unsigned)(head - ch->ch_tstart) >= ch->ch_tsize)
5282 * If the write wraps over the top of the circular buffer,
5283 * move the portion up to the wrap point, and reset the
5284 * pointers to the bottom.
5286 n = ch->ch_tstart + ch->ch_tsize - head;
5290 taddr = ch->ch_taddr + head;
5291 memcpy_toio(taddr, buf, n);
5292 head = ch->ch_tstart;
5297 * Move rest of data.
5299 taddr = ch->ch_taddr + head;
5301 memcpy_toio(taddr, buf, n);
5304 writew(head, &(bs->tx_head));
5308 * Retrives the current custom baud rate from FEP memory,
5309 * and returns it back to the user.
5310 * Returns 0 on error.
5312 static uint dgap_get_custom_baud(struct channel_t *ch)
5318 if (!ch || ch->magic != DGAP_CHANNEL_MAGIC)
5321 if (!ch->ch_bd || ch->ch_bd->magic != DGAP_BOARD_MAGIC)
5324 if (!(ch->ch_bd->bd_flags & BD_FEP5PLUS))
5327 vaddr = ch->ch_bd->re_map_membase;
5333 * Go get from fep mem, what the fep
5334 * believes the custom baud rate is.
5336 offset = ((((*(unsigned short *)(vaddr + ECS_SEG)) << 4) +
5337 (ch->ch_portnum * 0x28) + LINE_SPEED));
5339 value = readw(vaddr + offset);
5344 * Calls the firmware to reset this channel.
5346 static void dgap_firmware_reset_port(struct channel_t *ch)
5348 dgap_cmdb(ch, CHRESET, 0, 0, 0);
5351 * Now that the channel is reset, we need to make sure
5352 * all the current settings get reapplied to the port
5355 * So we will set the driver's cache of firmware
5356 * settings all to 0, and then call param.
5358 ch->ch_fepiflag = 0;
5359 ch->ch_fepcflag = 0;
5360 ch->ch_fepoflag = 0;
5361 ch->ch_fepstartc = 0;
5362 ch->ch_fepstopc = 0;
5363 ch->ch_fepastartc = 0;
5364 ch->ch_fepastopc = 0;
5369 /*=======================================================================
5371 * dgap_param - Set Digi parameters.
5373 * struct tty_struct * - TTY for port.
5375 *=======================================================================*/
5376 static int dgap_param(struct tty_struct *tty)
5378 struct ktermios *ts;
5380 struct channel_t *ch;
5389 if (!tty || tty->magic != TTY_MAGIC)
5392 un = (struct un_t *) tty->driver_data;
5393 if (!un || un->magic != DGAP_UNIT_MAGIC)
5397 if (!ch || ch->magic != DGAP_CHANNEL_MAGIC)
5401 if (!bd || bd->magic != DGAP_BOARD_MAGIC)
5411 * If baud rate is zero, flush queues, and set mval to drop DTR.
5413 if ((ch->ch_c_cflag & (CBAUD)) == 0) {
5416 head = readw(&(ch->ch_bs->rx_head));
5417 writew(head, &(ch->ch_bs->rx_tail));
5420 head = readw(&(ch->ch_bs->tx_head));
5421 writew(head, &(ch->ch_bs->tx_tail));
5423 ch->ch_flags |= (CH_BAUD0);
5425 /* Drop RTS and DTR */
5426 ch->ch_mval &= ~(D_RTS(ch)|D_DTR(ch));
5427 mval = D_DTR(ch) | D_RTS(ch);
5428 ch->ch_baud_info = 0;
5430 } else if (ch->ch_custom_speed && (bd->bd_flags & BD_FEP5PLUS)) {
5432 * Tell the fep to do the command
5435 dgap_cmdw_ext(ch, 0xff01, ch->ch_custom_speed, 0);
5438 * Now go get from fep mem, what the fep
5439 * believes the custom baud rate is.
5441 ch->ch_baud_info = ch->ch_custom_speed = dgap_get_custom_baud(ch);
5443 /* Handle transition from B0 */
5444 if (ch->ch_flags & CH_BAUD0) {
5445 ch->ch_flags &= ~(CH_BAUD0);
5446 ch->ch_mval |= (D_RTS(ch)|D_DTR(ch));
5448 mval = D_DTR(ch) | D_RTS(ch);
5452 * Set baud rate, character size, and parity.
5460 ulong bauds[4][16] = {
5464 600, 1200, 1800, 2400,
5465 4800, 9600, 19200, 38400 },
5466 { /* slowbaud & CBAUDEX */
5467 0, 57600, 115200, 230400,
5468 460800, 150, 200, 921600,
5469 600, 1200, 1800, 2400,
5470 4800, 9600, 19200, 38400 },
5472 0, 57600, 76800, 115200,
5473 14400, 57600, 230400, 76800,
5474 115200, 230400, 28800, 460800,
5475 921600, 9600, 19200, 38400 },
5476 { /* fastbaud & CBAUDEX */
5477 0, 57600, 115200, 230400,
5478 460800, 150, 200, 921600,
5479 600, 1200, 1800, 2400,
5480 4800, 9600, 19200, 38400 }
5483 /* Only use the TXPrint baud rate if the terminal unit is NOT open */
5484 if (!(ch->ch_tun.un_flags & UN_ISOPEN) && (un->un_type == DGAP_PRINT))
5485 baud = C_BAUD(ch->ch_pun.un_tty) & 0xff;
5487 baud = C_BAUD(ch->ch_tun.un_tty) & 0xff;
5489 if (ch->ch_c_cflag & CBAUDEX)
5492 if (ch->ch_digi.digi_flags & DIGI_FAST)
5497 if ((iindex >= 0) && (iindex < 4) &&
5498 (jindex >= 0) && (jindex < 16))
5499 baud = bauds[iindex][jindex];
5506 ch->ch_baud_info = baud;
5509 * CBAUD has bit position 0x1000 set these days to indicate Linux
5511 * We use a different bit assignment for high speed. Clear this
5512 * bit out while grabbing the parts of "cflag" we want.
5514 cflag = ch->ch_c_cflag & ((CBAUD ^ CBAUDEX) | PARODD | PARENB | CSTOPB | CSIZE);
5517 * HUPCL bit is used by FEP to indicate fast baud
5518 * table is to be used.
5520 if ((ch->ch_digi.digi_flags & DIGI_FAST) || (ch->ch_c_cflag & CBAUDEX))
5523 if ((ch->ch_c_cflag & CBAUDEX) && !(ch->ch_digi.digi_flags & DIGI_FAST)) {
5525 * The below code is trying to guarantee that only baud rates
5526 * 115200, 230400, 460800, 921600 are remapped. We use exclusive or
5527 * because the various baud rates share common bit positions
5528 * and therefore can't be tested for easily.
5530 tcflag_t tcflag = (ch->ch_c_cflag & CBAUD) | CBAUDEX;
5533 /* Map high speed requests to index into FEP's baud table */
5562 cflag = (cflag & ~(CBAUD | CBAUDEX)) | baudpart;
5567 if (cflag != ch->ch_fepcflag) {
5568 ch->ch_fepcflag = (u16) (cflag & 0xffff);
5570 /* Okay to have channel and board locks held calling this */
5571 dgap_cmdw(ch, SCFLAG, (u16) cflag, 0);
5574 /* Handle transition from B0 */
5575 if (ch->ch_flags & CH_BAUD0) {
5576 ch->ch_flags &= ~(CH_BAUD0);
5577 ch->ch_mval |= (D_RTS(ch)|D_DTR(ch));
5579 mval = D_DTR(ch) | D_RTS(ch);
5585 iflag = ch->ch_c_iflag & (IGNBRK | BRKINT | IGNPAR | PARMRK | INPCK | ISTRIP | IXON | IXANY | IXOFF);
5587 if ((ch->ch_startc == _POSIX_VDISABLE) || (ch->ch_stopc == _POSIX_VDISABLE)) {
5588 iflag &= ~(IXON | IXOFF);
5589 ch->ch_c_iflag &= ~(IXON | IXOFF);
5593 * Only the IBM Xr card can switch between
5594 * 232 and 422 modes on the fly
5596 if (bd->device == PCI_DEVICE_XR_IBM_DID) {
5597 if (ch->ch_digi.digi_flags & DIGI_422)
5598 dgap_cmdb(ch, SCOMMODE, MODE_422, 0, 0);
5600 dgap_cmdb(ch, SCOMMODE, MODE_232, 0, 0);
5603 if (ch->ch_digi.digi_flags & DIGI_ALTPIN)
5606 if (iflag != ch->ch_fepiflag) {
5607 ch->ch_fepiflag = iflag;
5609 /* Okay to have channel and board locks held calling this */
5610 dgap_cmdw(ch, SIFLAG, (u16) ch->ch_fepiflag, 0);
5614 * Select hardware handshaking.
5618 if (ch->ch_c_cflag & CRTSCTS)
5619 hflow |= (D_RTS(ch) | D_CTS(ch));
5620 if (ch->ch_digi.digi_flags & RTSPACE)
5622 if (ch->ch_digi.digi_flags & DTRPACE)
5624 if (ch->ch_digi.digi_flags & CTSPACE)
5626 if (ch->ch_digi.digi_flags & DSRPACE)
5628 if (ch->ch_digi.digi_flags & DCDPACE)
5631 if (hflow != ch->ch_hflow) {
5632 ch->ch_hflow = hflow;
5634 /* Okay to have channel and board locks held calling this */
5635 dgap_cmdb(ch, SHFLOW, (uchar) hflow, 0xff, 0);
5640 * Set RTS and/or DTR Toggle if needed, but only if product is FEP5+ based.
5642 if (bd->bd_flags & BD_FEP5PLUS) {
5644 if (ch->ch_digi.digi_flags & DIGI_RTS_TOGGLE)
5645 hflow2 |= (D_RTS(ch));
5646 if (ch->ch_digi.digi_flags & DIGI_DTR_TOGGLE)
5647 hflow2 |= (D_DTR(ch));
5649 dgap_cmdw_ext(ch, 0xff03, hflow2, 0);
5653 * Set modem control lines.
5656 mval ^= ch->ch_mforce & (mval ^ ch->ch_mval);
5658 if (ch->ch_mostat ^ mval) {
5659 ch->ch_mostat = mval;
5661 /* Okay to have channel and board locks held calling this */
5662 dgap_cmdb(ch, SMODEM, (uchar) mval, D_RTS(ch)|D_DTR(ch), 0);
5666 * Read modem signals, and then call carrier function.
5668 ch->ch_mistat = readb(&(bs->m_stat));
5672 * Set the start and stop characters.
5674 if (ch->ch_startc != ch->ch_fepstartc || ch->ch_stopc != ch->ch_fepstopc) {
5675 ch->ch_fepstartc = ch->ch_startc;
5676 ch->ch_fepstopc = ch->ch_stopc;
5678 /* Okay to have channel and board locks held calling this */
5679 dgap_cmdb(ch, SFLOWC, ch->ch_fepstartc, ch->ch_fepstopc, 0);
5683 * Set the Auxiliary start and stop characters.
5685 if (ch->ch_astartc != ch->ch_fepastartc || ch->ch_astopc != ch->ch_fepastopc) {
5686 ch->ch_fepastartc = ch->ch_astartc;
5687 ch->ch_fepastopc = ch->ch_astopc;
5689 /* Okay to have channel and board locks held calling this */
5690 dgap_cmdb(ch, SAFLOWC, ch->ch_fepastartc, ch->ch_fepastopc, 0);
5697 * dgap_parity_scan()
5699 * Convert the FEP5 way of reporting parity errors and breaks into
5700 * the Linux line discipline way.
5702 static void dgap_parity_scan(struct channel_t *ch, unsigned char *cbuf, unsigned char *fbuf, int *len)
5706 unsigned char *in, *cout, *fout;
5713 if (!ch || ch->magic != DGAP_CHANNEL_MAGIC)
5718 switch (ch->pscan_state) {
5720 /* reset to sanity and fall through */
5721 ch->pscan_state = 0;
5724 /* No FF seen yet */
5725 if (c == (unsigned char) '\377')
5726 /* delete this character from stream */
5727 ch->pscan_state = 1;
5730 *fout++ = TTY_NORMAL;
5737 if (c == (unsigned char) '\377') {
5738 /* doubled ff, transform to single ff */
5740 *fout++ = TTY_NORMAL;
5742 ch->pscan_state = 0;
5744 /* save value examination in next state */
5745 ch->pscan_savechar = c;
5746 ch->pscan_state = 2;
5751 /* third character of ff sequence */
5755 if (ch->pscan_savechar == 0x0) {
5759 *fout++ = TTY_BREAK;
5761 ch->ch_err_parity++;
5762 *fout++ = TTY_PARITY;
5767 ch->pscan_state = 0;
5773 /*=======================================================================
5775 * dgap_event - FEP to host event processing routine.
5777 * bd - Board of current event.
5779 *=======================================================================*/
5780 static int dgap_event(struct board_t *bd)
5782 struct channel_t *ch;
5787 uchar *vaddr = NULL;
5788 struct ev_t *eaddr = NULL;
5796 if (!bd || bd->magic != DGAP_BOARD_MAGIC)
5799 DGAP_LOCK(bd->bd_lock, lock_flags);
5801 vaddr = bd->re_map_membase;
5804 DGAP_UNLOCK(bd->bd_lock, lock_flags);
5808 eaddr = (struct ev_t *) (vaddr + EVBUF);
5810 /* Get our head and tail */
5811 head = readw(&(eaddr->ev_head));
5812 tail = readw(&(eaddr->ev_tail));
5815 * Forget it if pointers out of range.
5818 if (head >= EVMAX - EVSTART || tail >= EVMAX - EVSTART ||
5819 (head | tail) & 03) {
5820 /* Let go of board lock */
5821 DGAP_UNLOCK(bd->bd_lock, lock_flags);
5826 * Loop to process all the events in the buffer.
5828 while (tail != head) {
5831 * Get interrupt information.
5834 event = bd->re_map_membase + tail + EVSTART;
5842 * Make sure the interrupt is valid.
5844 if (port >= bd->nasync)
5847 if (!(reason & (IFMODEM | IFBREAK | IFTLW | IFTEM | IFDATA)))
5850 ch = bd->channels[port];
5852 if (!ch || ch->magic != DGAP_CHANNEL_MAGIC)
5856 * If we have made it here, the event was valid.
5857 * Lock down the channel.
5859 DGAP_LOCK(ch->ch_lock, lock_flags2);
5864 DGAP_UNLOCK(ch->ch_lock, lock_flags2);
5869 * Process received data.
5871 if (reason & IFDATA) {
5874 * ALL LOCKS *MUST* BE DROPPED BEFORE CALLING INPUT!
5875 * input could send some data to ld, which in turn
5876 * could do a callback to one of our other functions.
5878 DGAP_UNLOCK(ch->ch_lock, lock_flags2);
5879 DGAP_UNLOCK(bd->bd_lock, lock_flags);
5883 DGAP_LOCK(bd->bd_lock, lock_flags);
5884 DGAP_LOCK(ch->ch_lock, lock_flags2);
5886 if (ch->ch_flags & CH_RACTIVE)
5887 ch->ch_flags |= CH_RENABLE;
5889 writeb(1, &(bs->idata));
5891 if (ch->ch_flags & CH_RWAIT) {
5892 ch->ch_flags &= ~CH_RWAIT;
5894 wake_up_interruptible(&ch->ch_tun.un_flags_wait);
5899 * Process Modem change signals.
5901 if (reason & IFMODEM) {
5902 ch->ch_mistat = modem;
5909 if (reason & IFBREAK) {
5911 if (ch->ch_tun.un_tty) {
5912 /* A break has been indicated */
5914 tty_buffer_request_room(ch->ch_tun.un_tty->port, 1);
5915 tty_insert_flip_char(ch->ch_tun.un_tty->port, 0, TTY_BREAK);
5916 tty_flip_buffer_push(ch->ch_tun.un_tty->port);
5921 * Process Transmit low.
5923 if (reason & IFTLW) {
5925 if (ch->ch_tun.un_flags & UN_LOW) {
5926 ch->ch_tun.un_flags &= ~UN_LOW;
5928 if (ch->ch_tun.un_flags & UN_ISOPEN) {
5929 if ((ch->ch_tun.un_tty->flags &
5930 (1 << TTY_DO_WRITE_WAKEUP)) &&
5931 ch->ch_tun.un_tty->ldisc->ops->write_wakeup) {
5932 DGAP_UNLOCK(ch->ch_lock, lock_flags2);
5933 DGAP_UNLOCK(bd->bd_lock, lock_flags);
5934 (ch->ch_tun.un_tty->ldisc->ops->write_wakeup)(ch->ch_tun.un_tty);
5935 DGAP_LOCK(bd->bd_lock, lock_flags);
5936 DGAP_LOCK(ch->ch_lock, lock_flags2);
5938 wake_up_interruptible(&ch->ch_tun.un_tty->write_wait);
5939 wake_up_interruptible(&ch->ch_tun.un_flags_wait);
5943 if (ch->ch_pun.un_flags & UN_LOW) {
5944 ch->ch_pun.un_flags &= ~UN_LOW;
5945 if (ch->ch_pun.un_flags & UN_ISOPEN) {
5946 if ((ch->ch_pun.un_tty->flags &
5947 (1 << TTY_DO_WRITE_WAKEUP)) &&
5948 ch->ch_pun.un_tty->ldisc->ops->write_wakeup) {
5949 DGAP_UNLOCK(ch->ch_lock, lock_flags2);
5950 DGAP_UNLOCK(bd->bd_lock, lock_flags);
5951 (ch->ch_pun.un_tty->ldisc->ops->write_wakeup)(ch->ch_pun.un_tty);
5952 DGAP_LOCK(bd->bd_lock, lock_flags);
5953 DGAP_LOCK(ch->ch_lock, lock_flags2);
5955 wake_up_interruptible(&ch->ch_pun.un_tty->write_wait);
5956 wake_up_interruptible(&ch->ch_pun.un_flags_wait);
5960 if (ch->ch_flags & CH_WLOW) {
5961 ch->ch_flags &= ~CH_WLOW;
5962 wake_up_interruptible(&ch->ch_flags_wait);
5967 * Process Transmit empty.
5969 if (reason & IFTEM) {
5970 if (ch->ch_tun.un_flags & UN_EMPTY) {
5971 ch->ch_tun.un_flags &= ~UN_EMPTY;
5972 if (ch->ch_tun.un_flags & UN_ISOPEN) {
5973 if ((ch->ch_tun.un_tty->flags &
5974 (1 << TTY_DO_WRITE_WAKEUP)) &&
5975 ch->ch_tun.un_tty->ldisc->ops->write_wakeup) {
5976 DGAP_UNLOCK(ch->ch_lock, lock_flags2);
5977 DGAP_UNLOCK(bd->bd_lock, lock_flags);
5979 (ch->ch_tun.un_tty->ldisc->ops->write_wakeup)(ch->ch_tun.un_tty);
5980 DGAP_LOCK(bd->bd_lock, lock_flags);
5981 DGAP_LOCK(ch->ch_lock, lock_flags2);
5983 wake_up_interruptible(&ch->ch_tun.un_tty->write_wait);
5984 wake_up_interruptible(&ch->ch_tun.un_flags_wait);
5988 if (ch->ch_pun.un_flags & UN_EMPTY) {
5989 ch->ch_pun.un_flags &= ~UN_EMPTY;
5990 if (ch->ch_pun.un_flags & UN_ISOPEN) {
5991 if ((ch->ch_pun.un_tty->flags &
5992 (1 << TTY_DO_WRITE_WAKEUP)) &&
5993 ch->ch_pun.un_tty->ldisc->ops->write_wakeup) {
5994 DGAP_UNLOCK(ch->ch_lock, lock_flags2);
5995 DGAP_UNLOCK(bd->bd_lock, lock_flags);
5996 (ch->ch_pun.un_tty->ldisc->ops->write_wakeup)(ch->ch_pun.un_tty);
5997 DGAP_LOCK(bd->bd_lock, lock_flags);
5998 DGAP_LOCK(ch->ch_lock, lock_flags2);
6000 wake_up_interruptible(&ch->ch_pun.un_tty->write_wait);
6001 wake_up_interruptible(&ch->ch_pun.un_flags_wait);
6006 if (ch->ch_flags & CH_WEMPTY) {
6007 ch->ch_flags &= ~CH_WEMPTY;
6008 wake_up_interruptible(&ch->ch_flags_wait);
6012 DGAP_UNLOCK(ch->ch_lock, lock_flags2);
6015 tail = (tail + 4) & (EVMAX - EVSTART - 4);
6018 writew(tail, &(eaddr->ev_tail));
6019 DGAP_UNLOCK(bd->bd_lock, lock_flags);
6024 static ssize_t dgap_driver_version_show(struct device_driver *ddp, char *buf)
6026 return snprintf(buf, PAGE_SIZE, "%s\n", DG_PART);
6028 static DRIVER_ATTR(version, S_IRUSR, dgap_driver_version_show, NULL);
6031 static ssize_t dgap_driver_boards_show(struct device_driver *ddp, char *buf)
6033 return snprintf(buf, PAGE_SIZE, "%d\n", dgap_NumBoards);
6035 static DRIVER_ATTR(boards, S_IRUSR, dgap_driver_boards_show, NULL);
6038 static ssize_t dgap_driver_maxboards_show(struct device_driver *ddp, char *buf)
6040 return snprintf(buf, PAGE_SIZE, "%d\n", MAXBOARDS);
6042 static DRIVER_ATTR(maxboards, S_IRUSR, dgap_driver_maxboards_show, NULL);
6045 static ssize_t dgap_driver_pollcounter_show(struct device_driver *ddp, char *buf)
6047 return snprintf(buf, PAGE_SIZE, "%ld\n", dgap_poll_counter);
6049 static DRIVER_ATTR(pollcounter, S_IRUSR, dgap_driver_pollcounter_show, NULL);
6052 static ssize_t dgap_driver_state_show(struct device_driver *ddp, char *buf)
6054 return snprintf(buf, PAGE_SIZE, "%s\n", dgap_driver_state_text[dgap_driver_state]);
6056 static DRIVER_ATTR(state, S_IRUSR, dgap_driver_state_show, NULL);
6058 static ssize_t dgap_driver_rawreadok_show(struct device_driver *ddp, char *buf)
6060 return snprintf(buf, PAGE_SIZE, "0x%x\n", dgap_rawreadok);
6063 static ssize_t dgap_driver_rawreadok_store(struct device_driver *ddp, const char *buf, size_t count)
6065 sscanf(buf, "0x%x\n", &dgap_rawreadok);
6068 static DRIVER_ATTR(rawreadok, (S_IRUSR | S_IWUSR), dgap_driver_rawreadok_show, dgap_driver_rawreadok_store);
6071 static ssize_t dgap_driver_pollrate_show(struct device_driver *ddp, char *buf)
6073 return snprintf(buf, PAGE_SIZE, "%dms\n", dgap_poll_tick);
6076 static ssize_t dgap_driver_pollrate_store(struct device_driver *ddp, const char *buf, size_t count)
6078 sscanf(buf, "%d\n", &dgap_poll_tick);
6081 static DRIVER_ATTR(pollrate, (S_IRUSR | S_IWUSR), dgap_driver_pollrate_show, dgap_driver_pollrate_store);
6083 static void dgap_create_driver_sysfiles(struct pci_driver *dgap_driver)
6086 struct device_driver *driverfs = &dgap_driver->driver;
6088 rc |= driver_create_file(driverfs, &driver_attr_version);
6089 rc |= driver_create_file(driverfs, &driver_attr_boards);
6090 rc |= driver_create_file(driverfs, &driver_attr_maxboards);
6091 rc |= driver_create_file(driverfs, &driver_attr_rawreadok);
6092 rc |= driver_create_file(driverfs, &driver_attr_pollrate);
6093 rc |= driver_create_file(driverfs, &driver_attr_pollcounter);
6094 rc |= driver_create_file(driverfs, &driver_attr_state);
6096 printk(KERN_ERR "DGAP: sysfs driver_create_file failed!\n");
6099 static void dgap_remove_driver_sysfiles(struct pci_driver *dgap_driver)
6101 struct device_driver *driverfs = &dgap_driver->driver;
6102 driver_remove_file(driverfs, &driver_attr_version);
6103 driver_remove_file(driverfs, &driver_attr_boards);
6104 driver_remove_file(driverfs, &driver_attr_maxboards);
6105 driver_remove_file(driverfs, &driver_attr_rawreadok);
6106 driver_remove_file(driverfs, &driver_attr_pollrate);
6107 driver_remove_file(driverfs, &driver_attr_pollcounter);
6108 driver_remove_file(driverfs, &driver_attr_state);
6111 #define DGAP_VERIFY_BOARD(p, bd) \
6115 bd = dev_get_drvdata(p); \
6116 if (!bd || bd->magic != DGAP_BOARD_MAGIC) \
6118 if (bd->state != BOARD_READY) \
6121 static ssize_t dgap_ports_state_show(struct device *p, struct device_attribute *attr, char *buf)
6127 DGAP_VERIFY_BOARD(p, bd);
6129 for (i = 0; i < bd->nasync; i++) {
6130 count += snprintf(buf + count, PAGE_SIZE - count,
6131 "%d %s\n", bd->channels[i]->ch_portnum,
6132 bd->channels[i]->ch_open_count ? "Open" : "Closed");
6136 static DEVICE_ATTR(ports_state, S_IRUSR, dgap_ports_state_show, NULL);
6138 static ssize_t dgap_ports_baud_show(struct device *p, struct device_attribute *attr, char *buf)
6144 DGAP_VERIFY_BOARD(p, bd);
6146 for (i = 0; i < bd->nasync; i++) {
6147 count += snprintf(buf + count, PAGE_SIZE - count,
6148 "%d %d\n", bd->channels[i]->ch_portnum, bd->channels[i]->ch_baud_info);
6152 static DEVICE_ATTR(ports_baud, S_IRUSR, dgap_ports_baud_show, NULL);
6154 static ssize_t dgap_ports_msignals_show(struct device *p, struct device_attribute *attr, char *buf)
6160 DGAP_VERIFY_BOARD(p, bd);
6162 for (i = 0; i < bd->nasync; i++) {
6163 if (bd->channels[i]->ch_open_count)
6164 count += snprintf(buf + count, PAGE_SIZE - count,
6165 "%d %s %s %s %s %s %s\n", bd->channels[i]->ch_portnum,
6166 (bd->channels[i]->ch_mostat & UART_MCR_RTS) ? "RTS" : "",
6167 (bd->channels[i]->ch_mistat & UART_MSR_CTS) ? "CTS" : "",
6168 (bd->channels[i]->ch_mostat & UART_MCR_DTR) ? "DTR" : "",
6169 (bd->channels[i]->ch_mistat & UART_MSR_DSR) ? "DSR" : "",
6170 (bd->channels[i]->ch_mistat & UART_MSR_DCD) ? "DCD" : "",
6171 (bd->channels[i]->ch_mistat & UART_MSR_RI) ? "RI" : "");
6173 count += snprintf(buf + count, PAGE_SIZE - count,
6174 "%d\n", bd->channels[i]->ch_portnum);
6178 static DEVICE_ATTR(ports_msignals, S_IRUSR, dgap_ports_msignals_show, NULL);
6180 static ssize_t dgap_ports_iflag_show(struct device *p, struct device_attribute *attr, char *buf)
6186 DGAP_VERIFY_BOARD(p, bd);
6188 for (i = 0; i < bd->nasync; i++)
6189 count += snprintf(buf + count, PAGE_SIZE - count, "%d %x\n",
6190 bd->channels[i]->ch_portnum, bd->channels[i]->ch_c_iflag);
6193 static DEVICE_ATTR(ports_iflag, S_IRUSR, dgap_ports_iflag_show, NULL);
6195 static ssize_t dgap_ports_cflag_show(struct device *p, struct device_attribute *attr, char *buf)
6201 DGAP_VERIFY_BOARD(p, bd);
6203 for (i = 0; i < bd->nasync; i++)
6204 count += snprintf(buf + count, PAGE_SIZE - count, "%d %x\n",
6205 bd->channels[i]->ch_portnum, bd->channels[i]->ch_c_cflag);
6208 static DEVICE_ATTR(ports_cflag, S_IRUSR, dgap_ports_cflag_show, NULL);
6210 static ssize_t dgap_ports_oflag_show(struct device *p, struct device_attribute *attr, char *buf)
6216 DGAP_VERIFY_BOARD(p, bd);
6218 for (i = 0; i < bd->nasync; i++)
6219 count += snprintf(buf + count, PAGE_SIZE - count, "%d %x\n",
6220 bd->channels[i]->ch_portnum, bd->channels[i]->ch_c_oflag);
6223 static DEVICE_ATTR(ports_oflag, S_IRUSR, dgap_ports_oflag_show, NULL);
6225 static ssize_t dgap_ports_lflag_show(struct device *p, struct device_attribute *attr, char *buf)
6231 DGAP_VERIFY_BOARD(p, bd);
6233 for (i = 0; i < bd->nasync; i++)
6234 count += snprintf(buf + count, PAGE_SIZE - count, "%d %x\n",
6235 bd->channels[i]->ch_portnum, bd->channels[i]->ch_c_lflag);
6238 static DEVICE_ATTR(ports_lflag, S_IRUSR, dgap_ports_lflag_show, NULL);
6240 static ssize_t dgap_ports_digi_flag_show(struct device *p, struct device_attribute *attr, char *buf)
6246 DGAP_VERIFY_BOARD(p, bd);
6248 for (i = 0; i < bd->nasync; i++)
6249 count += snprintf(buf + count, PAGE_SIZE - count, "%d %x\n",
6250 bd->channels[i]->ch_portnum, bd->channels[i]->ch_digi.digi_flags);
6253 static DEVICE_ATTR(ports_digi_flag, S_IRUSR, dgap_ports_digi_flag_show, NULL);
6255 static ssize_t dgap_ports_rxcount_show(struct device *p, struct device_attribute *attr, char *buf)
6261 DGAP_VERIFY_BOARD(p, bd);
6263 for (i = 0; i < bd->nasync; i++)
6264 count += snprintf(buf + count, PAGE_SIZE - count, "%d %ld\n",
6265 bd->channels[i]->ch_portnum, bd->channels[i]->ch_rxcount);
6268 static DEVICE_ATTR(ports_rxcount, S_IRUSR, dgap_ports_rxcount_show, NULL);
6270 static ssize_t dgap_ports_txcount_show(struct device *p, struct device_attribute *attr, char *buf)
6276 DGAP_VERIFY_BOARD(p, bd);
6278 for (i = 0; i < bd->nasync; i++)
6279 count += snprintf(buf + count, PAGE_SIZE - count, "%d %ld\n",
6280 bd->channels[i]->ch_portnum, bd->channels[i]->ch_txcount);
6283 static DEVICE_ATTR(ports_txcount, S_IRUSR, dgap_ports_txcount_show, NULL);
6285 /* this function creates the sys files that will export each signal status
6286 * to sysfs each value will be put in a separate filename
6288 static void dgap_create_ports_sysfiles(struct board_t *bd)
6292 dev_set_drvdata(&bd->pdev->dev, bd);
6293 rc |= device_create_file(&(bd->pdev->dev), &dev_attr_ports_state);
6294 rc |= device_create_file(&(bd->pdev->dev), &dev_attr_ports_baud);
6295 rc |= device_create_file(&(bd->pdev->dev), &dev_attr_ports_msignals);
6296 rc |= device_create_file(&(bd->pdev->dev), &dev_attr_ports_iflag);
6297 rc |= device_create_file(&(bd->pdev->dev), &dev_attr_ports_cflag);
6298 rc |= device_create_file(&(bd->pdev->dev), &dev_attr_ports_oflag);
6299 rc |= device_create_file(&(bd->pdev->dev), &dev_attr_ports_lflag);
6300 rc |= device_create_file(&(bd->pdev->dev), &dev_attr_ports_digi_flag);
6301 rc |= device_create_file(&(bd->pdev->dev), &dev_attr_ports_rxcount);
6302 rc |= device_create_file(&(bd->pdev->dev), &dev_attr_ports_txcount);
6304 printk(KERN_ERR "DGAP: sysfs device_create_file failed!\n");
6307 /* removes all the sys files created for that port */
6308 static void dgap_remove_ports_sysfiles(struct board_t *bd)
6310 device_remove_file(&(bd->pdev->dev), &dev_attr_ports_state);
6311 device_remove_file(&(bd->pdev->dev), &dev_attr_ports_baud);
6312 device_remove_file(&(bd->pdev->dev), &dev_attr_ports_msignals);
6313 device_remove_file(&(bd->pdev->dev), &dev_attr_ports_iflag);
6314 device_remove_file(&(bd->pdev->dev), &dev_attr_ports_cflag);
6315 device_remove_file(&(bd->pdev->dev), &dev_attr_ports_oflag);
6316 device_remove_file(&(bd->pdev->dev), &dev_attr_ports_lflag);
6317 device_remove_file(&(bd->pdev->dev), &dev_attr_ports_digi_flag);
6318 device_remove_file(&(bd->pdev->dev), &dev_attr_ports_rxcount);
6319 device_remove_file(&(bd->pdev->dev), &dev_attr_ports_txcount);
6322 static ssize_t dgap_tty_state_show(struct device *d, struct device_attribute *attr, char *buf)
6325 struct channel_t *ch;
6330 un = dev_get_drvdata(d);
6331 if (!un || un->magic != DGAP_UNIT_MAGIC)
6334 if (!ch || ch->magic != DGAP_CHANNEL_MAGIC)
6337 if (!bd || bd->magic != DGAP_BOARD_MAGIC)
6339 if (bd->state != BOARD_READY)
6342 return snprintf(buf, PAGE_SIZE, "%s", un->un_open_count ? "Open" : "Closed");
6344 static DEVICE_ATTR(state, S_IRUSR, dgap_tty_state_show, NULL);
6346 static ssize_t dgap_tty_baud_show(struct device *d, struct device_attribute *attr, char *buf)
6349 struct channel_t *ch;
6354 un = dev_get_drvdata(d);
6355 if (!un || un->magic != DGAP_UNIT_MAGIC)
6358 if (!ch || ch->magic != DGAP_CHANNEL_MAGIC)
6361 if (!bd || bd->magic != DGAP_BOARD_MAGIC)
6363 if (bd->state != BOARD_READY)
6366 return snprintf(buf, PAGE_SIZE, "%d\n", ch->ch_baud_info);
6368 static DEVICE_ATTR(baud, S_IRUSR, dgap_tty_baud_show, NULL);
6370 static ssize_t dgap_tty_msignals_show(struct device *d, struct device_attribute *attr, char *buf)
6373 struct channel_t *ch;
6378 un = dev_get_drvdata(d);
6379 if (!un || un->magic != DGAP_UNIT_MAGIC)
6382 if (!ch || ch->magic != DGAP_CHANNEL_MAGIC)
6385 if (!bd || bd->magic != DGAP_BOARD_MAGIC)
6387 if (bd->state != BOARD_READY)
6390 if (ch->ch_open_count) {
6391 return snprintf(buf, PAGE_SIZE, "%s %s %s %s %s %s\n",
6392 (ch->ch_mostat & UART_MCR_RTS) ? "RTS" : "",
6393 (ch->ch_mistat & UART_MSR_CTS) ? "CTS" : "",
6394 (ch->ch_mostat & UART_MCR_DTR) ? "DTR" : "",
6395 (ch->ch_mistat & UART_MSR_DSR) ? "DSR" : "",
6396 (ch->ch_mistat & UART_MSR_DCD) ? "DCD" : "",
6397 (ch->ch_mistat & UART_MSR_RI) ? "RI" : "");
6401 static DEVICE_ATTR(msignals, S_IRUSR, dgap_tty_msignals_show, NULL);
6403 static ssize_t dgap_tty_iflag_show(struct device *d, struct device_attribute *attr, char *buf)
6406 struct channel_t *ch;
6411 un = dev_get_drvdata(d);
6412 if (!un || un->magic != DGAP_UNIT_MAGIC)
6415 if (!ch || ch->magic != DGAP_CHANNEL_MAGIC)
6418 if (!bd || bd->magic != DGAP_BOARD_MAGIC)
6420 if (bd->state != BOARD_READY)
6423 return snprintf(buf, PAGE_SIZE, "%x\n", ch->ch_c_iflag);
6425 static DEVICE_ATTR(iflag, S_IRUSR, dgap_tty_iflag_show, NULL);
6427 static ssize_t dgap_tty_cflag_show(struct device *d, struct device_attribute *attr, char *buf)
6430 struct channel_t *ch;
6435 un = dev_get_drvdata(d);
6436 if (!un || un->magic != DGAP_UNIT_MAGIC)
6439 if (!ch || ch->magic != DGAP_CHANNEL_MAGIC)
6442 if (!bd || bd->magic != DGAP_BOARD_MAGIC)
6444 if (bd->state != BOARD_READY)
6447 return snprintf(buf, PAGE_SIZE, "%x\n", ch->ch_c_cflag);
6449 static DEVICE_ATTR(cflag, S_IRUSR, dgap_tty_cflag_show, NULL);
6451 static ssize_t dgap_tty_oflag_show(struct device *d, struct device_attribute *attr, char *buf)
6454 struct channel_t *ch;
6459 un = dev_get_drvdata(d);
6460 if (!un || un->magic != DGAP_UNIT_MAGIC)
6463 if (!ch || ch->magic != DGAP_CHANNEL_MAGIC)
6466 if (!bd || bd->magic != DGAP_BOARD_MAGIC)
6468 if (bd->state != BOARD_READY)
6471 return snprintf(buf, PAGE_SIZE, "%x\n", ch->ch_c_oflag);
6473 static DEVICE_ATTR(oflag, S_IRUSR, dgap_tty_oflag_show, NULL);
6475 static ssize_t dgap_tty_lflag_show(struct device *d, struct device_attribute *attr, char *buf)
6478 struct channel_t *ch;
6483 un = dev_get_drvdata(d);
6484 if (!un || un->magic != DGAP_UNIT_MAGIC)
6487 if (!ch || ch->magic != DGAP_CHANNEL_MAGIC)
6490 if (!bd || bd->magic != DGAP_BOARD_MAGIC)
6492 if (bd->state != BOARD_READY)
6495 return snprintf(buf, PAGE_SIZE, "%x\n", ch->ch_c_lflag);
6497 static DEVICE_ATTR(lflag, S_IRUSR, dgap_tty_lflag_show, NULL);
6499 static ssize_t dgap_tty_digi_flag_show(struct device *d, struct device_attribute *attr, char *buf)
6502 struct channel_t *ch;
6507 un = dev_get_drvdata(d);
6508 if (!un || un->magic != DGAP_UNIT_MAGIC)
6511 if (!ch || ch->magic != DGAP_CHANNEL_MAGIC)
6514 if (!bd || bd->magic != DGAP_BOARD_MAGIC)
6516 if (bd->state != BOARD_READY)
6519 return snprintf(buf, PAGE_SIZE, "%x\n", ch->ch_digi.digi_flags);
6521 static DEVICE_ATTR(digi_flag, S_IRUSR, dgap_tty_digi_flag_show, NULL);
6523 static ssize_t dgap_tty_rxcount_show(struct device *d, struct device_attribute *attr, char *buf)
6526 struct channel_t *ch;
6531 un = dev_get_drvdata(d);
6532 if (!un || un->magic != DGAP_UNIT_MAGIC)
6535 if (!ch || ch->magic != DGAP_CHANNEL_MAGIC)
6538 if (!bd || bd->magic != DGAP_BOARD_MAGIC)
6540 if (bd->state != BOARD_READY)
6543 return snprintf(buf, PAGE_SIZE, "%ld\n", ch->ch_rxcount);
6545 static DEVICE_ATTR(rxcount, S_IRUSR, dgap_tty_rxcount_show, NULL);
6547 static ssize_t dgap_tty_txcount_show(struct device *d, struct device_attribute *attr, char *buf)
6550 struct channel_t *ch;
6555 un = dev_get_drvdata(d);
6556 if (!un || un->magic != DGAP_UNIT_MAGIC)
6559 if (!ch || ch->magic != DGAP_CHANNEL_MAGIC)
6562 if (!bd || bd->magic != DGAP_BOARD_MAGIC)
6564 if (bd->state != BOARD_READY)
6567 return snprintf(buf, PAGE_SIZE, "%ld\n", ch->ch_txcount);
6569 static DEVICE_ATTR(txcount, S_IRUSR, dgap_tty_txcount_show, NULL);
6571 static ssize_t dgap_tty_name_show(struct device *d, struct device_attribute *attr, char *buf)
6574 struct channel_t *ch;
6578 struct cnode *cptr = NULL;
6586 un = dev_get_drvdata(d);
6587 if (!un || un->magic != DGAP_UNIT_MAGIC)
6590 if (!ch || ch->magic != DGAP_CHANNEL_MAGIC)
6593 if (!bd || bd->magic != DGAP_BOARD_MAGIC)
6595 if (bd->state != BOARD_READY)
6599 cn = ch->ch_portnum;
6601 for (cptr = bd->bd_config; cptr; cptr = cptr->next) {
6603 if ((cptr->type == BNODE) &&
6604 ((cptr->u.board.type == APORT2_920P) || (cptr->u.board.type == APORT4_920P) ||
6605 (cptr->u.board.type == APORT8_920P) || (cptr->u.board.type == PAPORT4) ||
6606 (cptr->u.board.type == PAPORT8))) {
6609 if (cptr->u.board.v_start)
6610 starto = cptr->u.board.start;
6615 if (cptr->type == TNODE && found == TRUE) {
6617 if (strstr(cptr->u.ttyname, "tty")) {
6618 ptr1 = cptr->u.ttyname;
6621 ptr1 = cptr->u.ttyname;
6623 for (i = 0; i < dgap_config_get_number_of_ports(bd); i++) {
6625 return snprintf(buf, PAGE_SIZE, "%s%s%02d\n",
6626 (un->un_type == DGAP_PRINT) ? "pr" : "tty",
6631 if (cptr->type == CNODE) {
6633 for (i = 0; i < cptr->u.conc.nport; i++) {
6634 if (cn == (i + ncount))
6636 return snprintf(buf, PAGE_SIZE, "%s%s%02d\n",
6637 (un->un_type == DGAP_PRINT) ? "pr" : "tty",
6639 i + (cptr->u.conc.v_start ? cptr->u.conc.start : 1));
6642 ncount += cptr->u.conc.nport;
6645 if (cptr->type == MNODE) {
6647 for (i = 0; i < cptr->u.module.nport; i++) {
6648 if (cn == (i + ncount))
6649 return snprintf(buf, PAGE_SIZE, "%s%s%02d\n",
6650 (un->un_type == DGAP_PRINT) ? "pr" : "tty",
6652 i + (cptr->u.module.v_start ? cptr->u.module.start : 1));
6655 ncount += cptr->u.module.nport;
6660 return snprintf(buf, PAGE_SIZE, "%s_dgap_%d_%d\n",
6661 (un->un_type == DGAP_PRINT) ? "pr" : "tty", bn, cn);
6664 static DEVICE_ATTR(custom_name, S_IRUSR, dgap_tty_name_show, NULL);
6666 static struct attribute *dgap_sysfs_tty_entries[] = {
6667 &dev_attr_state.attr,
6668 &dev_attr_baud.attr,
6669 &dev_attr_msignals.attr,
6670 &dev_attr_iflag.attr,
6671 &dev_attr_cflag.attr,
6672 &dev_attr_oflag.attr,
6673 &dev_attr_lflag.attr,
6674 &dev_attr_digi_flag.attr,
6675 &dev_attr_rxcount.attr,
6676 &dev_attr_txcount.attr,
6677 &dev_attr_custom_name.attr,
6681 static struct attribute_group dgap_tty_attribute_group = {
6683 .attrs = dgap_sysfs_tty_entries,
6686 static void dgap_create_tty_sysfs(struct un_t *un, struct device *c)
6690 ret = sysfs_create_group(&c->kobj, &dgap_tty_attribute_group);
6692 printk(KERN_ERR "dgap: failed to create sysfs tty device attributes.\n");
6693 sysfs_remove_group(&c->kobj, &dgap_tty_attribute_group);
6697 dev_set_drvdata(c, un);
6701 static void dgap_remove_tty_sysfs(struct device *c)
6703 sysfs_remove_group(&c->kobj, &dgap_tty_attribute_group);
6707 * Parse a configuration file read into memory as a string.
6709 static int dgap_parsefile(char **in, int Remove)
6711 struct cnode *p, *brd, *line, *conc;
6713 char *s = NULL, *s2 = NULL;
6717 brd = line = conc = NULL;
6719 /* perhaps we are adding to an existing list? */
6720 while (p->next != NULL)
6723 /* file must start with a BEGIN */
6724 while ((rc = dgap_gettok(in, p)) != BEGIN) {
6726 dgap_err("unexpected EOF");
6732 rc = dgap_gettok(in, p);
6734 dgap_err("unexpected EOF");
6740 dgap_err("unexpected end of file");
6743 case BEGIN: /* should only be 1 begin */
6744 dgap_err("unexpected config_begin\n");
6750 case BOARD: /* board info */
6751 if (dgap_checknode(p))
6753 if ((p->next = dgap_newnode(BNODE)) == NULL) {
6754 dgap_err("out of memory");
6759 p->u.board.status = dgap_savestring("No");
6765 case APORT2_920P: /* AccelePort_4 */
6766 if (p->type != BNODE) {
6767 dgap_err("unexpected Digi_2r_920 string");
6770 p->u.board.type = APORT2_920P;
6771 p->u.board.v_type = 1;
6774 case APORT4_920P: /* AccelePort_4 */
6775 if (p->type != BNODE) {
6776 dgap_err("unexpected Digi_4r_920 string");
6779 p->u.board.type = APORT4_920P;
6780 p->u.board.v_type = 1;
6783 case APORT8_920P: /* AccelePort_8 */
6784 if (p->type != BNODE) {
6785 dgap_err("unexpected Digi_8r_920 string");
6788 p->u.board.type = APORT8_920P;
6789 p->u.board.v_type = 1;
6792 case PAPORT4: /* AccelePort_4 PCI */
6793 if (p->type != BNODE) {
6794 dgap_err("unexpected Digi_4r(PCI) string");
6797 p->u.board.type = PAPORT4;
6798 p->u.board.v_type = 1;
6801 case PAPORT8: /* AccelePort_8 PCI */
6802 if (p->type != BNODE) {
6803 dgap_err("unexpected Digi_8r string");
6806 p->u.board.type = PAPORT8;
6807 p->u.board.v_type = 1;
6810 case PCX: /* PCI C/X */
6811 if (p->type != BNODE) {
6812 dgap_err("unexpected Digi_C/X_(PCI) string");
6815 p->u.board.type = PCX;
6816 p->u.board.v_type = 1;
6817 p->u.board.conc1 = 0;
6818 p->u.board.conc2 = 0;
6819 p->u.board.module1 = 0;
6820 p->u.board.module2 = 0;
6823 case PEPC: /* PCI EPC/X */
6824 if (p->type != BNODE) {
6825 dgap_err("unexpected \"Digi_EPC/X_(PCI)\" string");
6828 p->u.board.type = PEPC;
6829 p->u.board.v_type = 1;
6830 p->u.board.conc1 = 0;
6831 p->u.board.conc2 = 0;
6832 p->u.board.module1 = 0;
6833 p->u.board.module2 = 0;
6836 case PPCM: /* PCI/Xem */
6837 if (p->type != BNODE) {
6838 dgap_err("unexpected PCI/Xem string");
6841 p->u.board.type = PPCM;
6842 p->u.board.v_type = 1;
6843 p->u.board.conc1 = 0;
6844 p->u.board.conc2 = 0;
6847 case IO: /* i/o port */
6848 if (p->type != BNODE) {
6849 dgap_err("IO port only vaild for boards");
6852 s = dgap_getword(in);
6854 dgap_err("unexpected end of file");
6857 p->u.board.portstr = dgap_savestring(s);
6858 p->u.board.port = (short)simple_strtol(s, &s2, 0);
6859 if ((short)strlen(s) > (short)(s2 - s)) {
6860 dgap_err("bad number for IO port");
6863 p->u.board.v_port = 1;
6866 case MEM: /* memory address */
6867 if (p->type != BNODE) {
6868 dgap_err("memory address only vaild for boards");
6871 s = dgap_getword(in);
6873 dgap_err("unexpected end of file");
6876 p->u.board.addrstr = dgap_savestring(s);
6877 p->u.board.addr = simple_strtoul(s, &s2, 0);
6878 if ((int)strlen(s) > (int)(s2 - s)) {
6879 dgap_err("bad number for memory address");
6882 p->u.board.v_addr = 1;
6885 case PCIINFO: /* pci information */
6886 if (p->type != BNODE) {
6887 dgap_err("memory address only vaild for boards");
6890 s = dgap_getword(in);
6892 dgap_err("unexpected end of file");
6895 p->u.board.pcibusstr = dgap_savestring(s);
6896 p->u.board.pcibus = simple_strtoul(s, &s2, 0);
6897 if ((int)strlen(s) > (int)(s2 - s)) {
6898 dgap_err("bad number for pci bus");
6901 p->u.board.v_pcibus = 1;
6902 s = dgap_getword(in);
6904 dgap_err("unexpected end of file");
6907 p->u.board.pcislotstr = dgap_savestring(s);
6908 p->u.board.pcislot = simple_strtoul(s, &s2, 0);
6909 if ((int)strlen(s) > (int)(s2 - s)) {
6910 dgap_err("bad number for pci slot");
6913 p->u.board.v_pcislot = 1;
6917 if (p->type != BNODE) {
6918 dgap_err("install method only vaild for boards");
6921 s = dgap_getword(in);
6923 dgap_err("unexpected end of file");
6926 p->u.board.method = dgap_savestring(s);
6927 p->u.board.v_method = 1;
6931 if (p->type != BNODE) {
6932 dgap_err("config status only vaild for boards");
6935 s = dgap_getword(in);
6937 dgap_err("unexpected end of file");
6940 p->u.board.status = dgap_savestring(s);
6943 case NPORTS: /* number of ports */
6944 if (p->type == BNODE) {
6945 s = dgap_getword(in);
6947 dgap_err("unexpected end of file");
6950 p->u.board.nport = (char)simple_strtol(s, &s2, 0);
6951 if ((int)strlen(s) > (int)(s2 - s)) {
6952 dgap_err("bad number for number of ports");
6955 p->u.board.v_nport = 1;
6956 } else if (p->type == CNODE) {
6957 s = dgap_getword(in);
6959 dgap_err("unexpected end of file");
6962 p->u.conc.nport = (char)simple_strtol(s, &s2, 0);
6963 if ((int)strlen(s) > (int)(s2 - s)) {
6964 dgap_err("bad number for number of ports");
6967 p->u.conc.v_nport = 1;
6968 } else if (p->type == MNODE) {
6969 s = dgap_getword(in);
6971 dgap_err("unexpected end of file");
6974 p->u.module.nport = (char)simple_strtol(s, &s2, 0);
6975 if ((int)strlen(s) > (int)(s2 - s)) {
6976 dgap_err("bad number for number of ports");
6979 p->u.module.v_nport = 1;
6981 dgap_err("nports only valid for concentrators or modules");
6986 case ID: /* letter ID used in tty name */
6987 s = dgap_getword(in);
6989 dgap_err("unexpected end of file");
6993 p->u.board.status = dgap_savestring(s);
6995 if (p->type == CNODE) {
6996 p->u.conc.id = dgap_savestring(s);
6998 } else if (p->type == MNODE) {
6999 p->u.module.id = dgap_savestring(s);
7000 p->u.module.v_id = 1;
7002 dgap_err("id only valid for concentrators or modules");
7007 case STARTO: /* start offset of ID */
7008 if (p->type == BNODE) {
7009 s = dgap_getword(in);
7011 dgap_err("unexpected end of file");
7014 p->u.board.start = simple_strtol(s, &s2, 0);
7015 if ((int)strlen(s) > (int)(s2 - s)) {
7016 dgap_err("bad number for start of tty count");
7019 p->u.board.v_start = 1;
7020 } else if (p->type == CNODE) {
7021 s = dgap_getword(in);
7023 dgap_err("unexpected end of file");
7026 p->u.conc.start = simple_strtol(s, &s2, 0);
7027 if ((int)strlen(s) > (int)(s2 - s)) {
7028 dgap_err("bad number for start of tty count");
7031 p->u.conc.v_start = 1;
7032 } else if (p->type == MNODE) {
7033 s = dgap_getword(in);
7035 dgap_err("unexpected end of file");
7038 p->u.module.start = simple_strtol(s, &s2, 0);
7039 if ((int)strlen(s) > (int)(s2 - s)) {
7040 dgap_err("bad number for start of tty count");
7043 p->u.module.v_start = 1;
7045 dgap_err("start only valid for concentrators or modules");
7050 case TTYN: /* tty name prefix */
7051 if (dgap_checknode(p))
7053 if ((p->next = dgap_newnode(TNODE)) == NULL) {
7054 dgap_err("out of memory");
7058 if ((s = dgap_getword(in)) == NULL) {
7059 dgap_err("unexpeced end of file");
7062 if ((p->u.ttyname = dgap_savestring(s)) == NULL) {
7063 dgap_err("out of memory");
7068 case CU: /* cu name prefix */
7069 if (dgap_checknode(p))
7071 if ((p->next = dgap_newnode(CUNODE)) == NULL) {
7072 dgap_err("out of memory");
7076 if ((s = dgap_getword(in)) == NULL) {
7077 dgap_err("unexpeced end of file");
7080 if ((p->u.cuname = dgap_savestring(s)) == NULL) {
7081 dgap_err("out of memory");
7086 case LINE: /* line information */
7087 if (dgap_checknode(p))
7090 dgap_err("must specify board before line info");
7093 switch (brd->u.board.type) {
7095 dgap_err("line not vaild for PC/em");
7098 if ((p->next = dgap_newnode(LNODE)) == NULL) {
7099 dgap_err("out of memory");
7108 case CONC: /* concentrator information */
7109 if (dgap_checknode(p))
7112 dgap_err("must specify line info before concentrator");
7115 if ((p->next = dgap_newnode(CNODE)) == NULL) {
7116 dgap_err("out of memory");
7122 brd->u.board.conc2++;
7124 brd->u.board.conc1++;
7128 case CX: /* c/x type concentrator */
7129 if (p->type != CNODE) {
7130 dgap_err("cx only valid for concentrators");
7133 p->u.conc.type = CX;
7134 p->u.conc.v_type = 1;
7137 case EPC: /* epc type concentrator */
7138 if (p->type != CNODE) {
7139 dgap_err("cx only valid for concentrators");
7142 p->u.conc.type = EPC;
7143 p->u.conc.v_type = 1;
7146 case MOD: /* EBI module */
7147 if (dgap_checknode(p))
7150 dgap_err("must specify board info before EBI modules");
7153 switch (brd->u.board.type) {
7159 dgap_err("must specify concentrator info before EBI module");
7163 if ((p->next = dgap_newnode(MNODE)) == NULL) {
7164 dgap_err("out of memory");
7169 brd->u.board.module2++;
7171 brd->u.board.module1++;
7175 case PORTS: /* ports type EBI module */
7176 if (p->type != MNODE) {
7177 dgap_err("ports only valid for EBI modules");
7180 p->u.module.type = PORTS;
7181 p->u.module.v_type = 1;
7184 case MODEM: /* ports type EBI module */
7185 if (p->type != MNODE) {
7186 dgap_err("modem only valid for modem modules");
7189 p->u.module.type = MODEM;
7190 p->u.module.v_type = 1;
7194 if (p->type == LNODE) {
7195 if ((s = dgap_getword(in)) == NULL) {
7196 dgap_err("unexpected end of file");
7199 p->u.line.cable = dgap_savestring(s);
7200 p->u.line.v_cable = 1;
7204 case SPEED: /* sync line speed indication */
7205 if (p->type == LNODE) {
7206 s = dgap_getword(in);
7208 dgap_err("unexpected end of file");
7211 p->u.line.speed = (char)simple_strtol(s, &s2, 0);
7212 if ((short)strlen(s) > (short)(s2 - s)) {
7213 dgap_err("bad number for line speed");
7216 p->u.line.v_speed = 1;
7217 } else if (p->type == CNODE) {
7218 s = dgap_getword(in);
7220 dgap_err("unexpected end of file");
7223 p->u.conc.speed = (char)simple_strtol(s, &s2, 0);
7224 if ((short)strlen(s) > (short)(s2 - s)) {
7225 dgap_err("bad number for line speed");
7228 p->u.conc.v_speed = 1;
7230 dgap_err("speed valid only for lines or concentrators.");
7236 if (p->type == CNODE) {
7237 if ((s = dgap_getword(in)) == NULL) {
7238 dgap_err("unexpected end of file");
7241 p->u.conc.connect = dgap_savestring(s);
7242 p->u.conc.v_connect = 1;
7245 case PRINT: /* transparent print name prefix */
7246 if (dgap_checknode(p))
7248 if ((p->next = dgap_newnode(PNODE)) == NULL) {
7249 dgap_err("out of memory");
7253 if ((s = dgap_getword(in)) == NULL) {
7254 dgap_err("unexpeced end of file");
7257 if ((p->u.printname = dgap_savestring(s)) == NULL) {
7258 dgap_err("out of memory");
7263 case CMAJOR: /* major number */
7264 if (dgap_checknode(p))
7266 if ((p->next = dgap_newnode(JNODE)) == NULL) {
7267 dgap_err("out of memory");
7271 s = dgap_getword(in);
7273 dgap_err("unexpected end of file");
7276 p->u.majornumber = simple_strtol(s, &s2, 0);
7277 if ((int)strlen(s) > (int)(s2 - s)) {
7278 dgap_err("bad number for major number");
7283 case ALTPIN: /* altpin setting */
7284 if (dgap_checknode(p))
7286 if ((p->next = dgap_newnode(ANODE)) == NULL) {
7287 dgap_err("out of memory");
7291 s = dgap_getword(in);
7293 dgap_err("unexpected end of file");
7296 p->u.altpin = simple_strtol(s, &s2, 0);
7297 if ((int)strlen(s) > (int)(s2 - s)) {
7298 dgap_err("bad number for altpin");
7303 case USEINTR: /* enable interrupt setting */
7304 if (dgap_checknode(p))
7306 if ((p->next = dgap_newnode(INTRNODE)) == NULL) {
7307 dgap_err("out of memory");
7311 s = dgap_getword(in);
7313 dgap_err("unexpected end of file");
7316 p->u.useintr = simple_strtol(s, &s2, 0);
7317 if ((int)strlen(s) > (int)(s2 - s)) {
7318 dgap_err("bad number for useintr");
7323 case TTSIZ: /* size of tty structure */
7324 if (dgap_checknode(p))
7326 if ((p->next = dgap_newnode(TSNODE)) == NULL) {
7327 dgap_err("out of memory");
7331 s = dgap_getword(in);
7333 dgap_err("unexpected end of file");
7336 p->u.ttysize = simple_strtol(s, &s2, 0);
7337 if ((int)strlen(s) > (int)(s2 - s)) {
7338 dgap_err("bad number for ttysize");
7343 case CHSIZ: /* channel structure size */
7344 if (dgap_checknode(p))
7346 if ((p->next = dgap_newnode(CSNODE)) == NULL) {
7347 dgap_err("out of memory");
7351 s = dgap_getword(in);
7353 dgap_err("unexpected end of file");
7356 p->u.chsize = simple_strtol(s, &s2, 0);
7357 if ((int)strlen(s) > (int)(s2 - s)) {
7358 dgap_err("bad number for chsize");
7363 case BSSIZ: /* board structure size */
7364 if (dgap_checknode(p))
7366 if ((p->next = dgap_newnode(BSNODE)) == NULL) {
7367 dgap_err("out of memory");
7371 s = dgap_getword(in);
7373 dgap_err("unexpected end of file");
7376 p->u.bssize = simple_strtol(s, &s2, 0);
7377 if ((int)strlen(s) > (int)(s2 - s)) {
7378 dgap_err("bad number for bssize");
7383 case UNTSIZ: /* sched structure size */
7384 if (dgap_checknode(p))
7386 if ((p->next = dgap_newnode(USNODE)) == NULL) {
7387 dgap_err("out of memory");
7391 s = dgap_getword(in);
7393 dgap_err("unexpected end of file");
7396 p->u.unsize = simple_strtol(s, &s2, 0);
7397 if ((int)strlen(s) > (int)(s2 - s)) {
7398 dgap_err("bad number for schedsize");
7403 case F2SIZ: /* f2200 structure size */
7404 if (dgap_checknode(p))
7406 if ((p->next = dgap_newnode(FSNODE)) == NULL) {
7407 dgap_err("out of memory");
7411 s = dgap_getword(in);
7413 dgap_err("unexpected end of file");
7416 p->u.f2size = simple_strtol(s, &s2, 0);
7417 if ((int)strlen(s) > (int)(s2 - s)) {
7418 dgap_err("bad number for f2200size");
7423 case VPSIZ: /* vpix structure size */
7424 if (dgap_checknode(p))
7426 if ((p->next = dgap_newnode(VSNODE)) == NULL) {
7427 dgap_err("out of memory");
7431 s = dgap_getword(in);
7433 dgap_err("unexpected end of file");
7436 p->u.vpixsize = simple_strtol(s, &s2, 0);
7437 if ((int)strlen(s) > (int)(s2 - s)) {
7438 dgap_err("bad number for vpixsize");
7447 * dgap_sindex: much like index(), but it looks for a match of any character in
7448 * the group, and returns that position. If the first character is a ^, then
7449 * this will match the first occurrence not in that group.
7451 static char *dgap_sindex (char *string, char *group)
7455 if (!string || !group)
7456 return (char *) NULL;
7458 if (*group == '^') {
7460 for (; *string; string++) {
7461 for (ptr = group; *ptr; ptr++) {
7462 if (*ptr == *string)
7469 for (; *string; string++) {
7470 for (ptr = group; *ptr; ptr++) {
7471 if (*ptr == *string)
7477 return (char *) NULL;
7481 * Get a token from the input file; return 0 if end of file is reached
7483 static int dgap_gettok(char **in, struct cnode *p)
7488 if (strstr(dgap_cword, "boar")) {
7489 w = dgap_getword(in);
7490 snprintf(dgap_cword, MAXCWORD, "%s", w);
7491 for (t = dgap_tlist; t->token != 0; t++) {
7492 if (!strcmp(w, t->string))
7495 dgap_err("board !!type not specified");
7498 while ( (w = dgap_getword(in)) != NULL ) {
7499 snprintf(dgap_cword, MAXCWORD, "%s", w);
7500 for (t = dgap_tlist; t->token != 0; t++) {
7501 if (!strcmp(w, t->string))
7510 * get a word from the input stream, also keep track of current line number.
7511 * words are separated by whitespace.
7513 static char *dgap_getword(char **in)
7515 char *ret_ptr = *in;
7517 char *ptr = dgap_sindex(*in, " \t\n");
7519 /* If no word found, return null */
7523 /* Mark new location for our buffer */
7527 /* Eat any extra spaces/tabs/newlines that might be present */
7528 while (*in && **in && ((**in == ' ') || (**in == '\t') || (**in == '\n'))) {
7537 * print an error message, giving the line number in the file where
7538 * the error occurred.
7540 static void dgap_err(char *s)
7542 printk("DGAP: parse: %s\n", s);
7546 * allocate a new configuration node of type t
7548 static struct cnode *dgap_newnode(int t)
7552 n = kmalloc(sizeof(struct cnode), GFP_ATOMIC);
7554 memset((char *)n, 0, sizeof(struct cnode));
7561 * dgap_checknode: see if all the necessary info has been supplied for a node
7562 * before creating the next node.
7564 static int dgap_checknode(struct cnode *p)
7568 if (p->u.board.v_type == 0) {
7569 dgap_err("board type !not specified");
7576 if (p->u.line.v_speed == 0) {
7577 dgap_err("line speed not specified");
7583 if (p->u.conc.v_type == 0) {
7584 dgap_err("concentrator type not specified");
7587 if (p->u.conc.v_speed == 0) {
7588 dgap_err("concentrator line speed not specified");
7591 if (p->u.conc.v_nport == 0) {
7592 dgap_err("number of ports on concentrator not specified");
7595 if (p->u.conc.v_id == 0) {
7596 dgap_err("concentrator id letter not specified");
7602 if (p->u.module.v_type == 0) {
7603 dgap_err("EBI module type not specified");
7606 if (p->u.module.v_nport == 0) {
7607 dgap_err("number of ports on EBI module not specified");
7610 if (p->u.module.v_id == 0) {
7611 dgap_err("EBI module id letter not specified");
7620 * save a string somewhere
7622 static char *dgap_savestring(char *s)
7626 p = kmalloc(strlen(s) + 1, GFP_ATOMIC);
7633 * Given a board pointer, returns whether we should use interrupts or not.
7635 static uint dgap_config_get_useintr(struct board_t *bd)
7637 struct cnode *p = NULL;
7642 for (p = bd->bd_config; p; p = p->next) {
7646 * check for pcxr types.
7648 return p->u.useintr;
7654 /* If not found, then don't turn on interrupts. */
7659 * Given a board pointer, returns whether we turn on altpin or not.
7661 static uint dgap_config_get_altpin(struct board_t *bd)
7663 struct cnode *p = NULL;
7668 for (p = bd->bd_config; p; p = p->next) {
7672 * check for pcxr types.
7680 /* If not found, then don't turn on interrupts. */
7685 * Given a specific type of board, if found, detached link and
7686 * returns the first occurrence in the list.
7688 static struct cnode *dgap_find_config(int type, int bus, int slot)
7690 struct cnode *p, *prev = NULL, *prev2 = NULL, *found = NULL;
7694 while (p->next != NULL) {
7698 if (p->type == BNODE) {
7700 if (p->u.board.type == type) {
7702 if (p->u.board.v_pcibus &&
7703 p->u.board.pcibus != bus)
7705 if (p->u.board.v_pcislot &&
7706 p->u.board.pcislot != slot)
7711 * Keep walking thru the list till we find the next board.
7713 while (p->next != NULL) {
7716 if (p->type == BNODE) {
7719 * Mark the end of our 1 board chain of configs.
7724 * Link the "next" board to the previous board,
7725 * effectively "unlinking" our board from the main config.
7733 * It must be the last board in the list.
7744 * Given a board pointer, walks the config link, counting up
7745 * all ports user specified should be on the board.
7746 * (This does NOT mean they are all actually present right now tho)
7748 static uint dgap_config_get_number_of_ports(struct board_t *bd)
7751 struct cnode *p = NULL;
7756 for (p = bd->bd_config; p; p = p->next) {
7761 * check for pcxr types.
7763 if (p->u.board.type > EPCFE)
7764 count += p->u.board.nport;
7767 count += p->u.conc.nport;
7770 count += p->u.module.nport;
7777 static char *dgap_create_config_string(struct board_t *bd, char *string)
7780 struct cnode *p = NULL;
7781 struct cnode *q = NULL;
7789 for (p = bd->bd_config; p; p = p->next) {
7795 *ptr = p->u.line.speed;
7800 * Because the EPC/con concentrators can have EM modules
7801 * hanging off of them, we have to walk ahead in the list
7802 * and keep adding the number of ports on each EM to the config.
7805 speed = p->u.conc.speed;
7807 if ((q != NULL) && (q->type == MNODE)) {
7808 *ptr = (p->u.conc.nport + 0x80);
7811 while ((q->next != NULL) && (q->next->type) == MNODE) {
7812 *ptr = (q->u.module.nport + 0x80);
7817 *ptr = q->u.module.nport;
7820 *ptr = p->u.conc.nport;