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 <asm/uaccess.h> /* For copy_from_user/copy_to_user */
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 <asm/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(debug, 0x00, 0644, "Driver debugging level");
97 PARM_INT(rawreadok, 1, 0644, "Bypass flip buffers on input");
98 PARM_INT(trcbuf_size, 0x100000, 0644, "Debugging trace buffer size.");
101 /**************************************************************************
103 * protos for this file
107 static int dgap_start(void);
108 static void dgap_init_globals(void);
109 static int dgap_found_board(struct pci_dev *pdev, int id);
110 static void dgap_cleanup_board(struct board_t *brd);
111 static void dgap_poll_handler(ulong dummy);
112 static int dgap_init_pci(void);
113 static int dgap_init_one(struct pci_dev *pdev, const struct pci_device_id *ent);
114 static void dgap_remove_one(struct pci_dev *dev);
115 static int dgap_probe1(struct pci_dev *pdev, int card_type);
116 static void dgap_mbuf(struct board_t *brd, const char *fmt, ...);
117 static int dgap_do_remap(struct board_t *brd);
118 static irqreturn_t dgap_intr(int irq, void *voidbrd);
120 /* Our function prototypes */
121 static int dgap_tty_open(struct tty_struct *tty, struct file *file);
122 static void dgap_tty_close(struct tty_struct *tty, struct file *file);
123 static int dgap_block_til_ready(struct tty_struct *tty, struct file *file, struct channel_t *ch);
124 static int dgap_tty_ioctl(struct tty_struct *tty, unsigned int cmd, unsigned long arg);
125 static int dgap_tty_digigeta(struct tty_struct *tty, struct digi_t __user *retinfo);
126 static int dgap_tty_digiseta(struct tty_struct *tty, struct digi_t __user *new_info);
127 static int dgap_tty_digigetedelay(struct tty_struct *tty, int __user *retinfo);
128 static int dgap_tty_digisetedelay(struct tty_struct *tty, int __user *new_info);
129 static int dgap_tty_write_room(struct tty_struct* tty);
130 static int dgap_tty_chars_in_buffer(struct tty_struct* tty);
131 static void dgap_tty_start(struct tty_struct *tty);
132 static void dgap_tty_stop(struct tty_struct *tty);
133 static void dgap_tty_throttle(struct tty_struct *tty);
134 static void dgap_tty_unthrottle(struct tty_struct *tty);
135 static void dgap_tty_flush_chars(struct tty_struct *tty);
136 static void dgap_tty_flush_buffer(struct tty_struct *tty);
137 static void dgap_tty_hangup(struct tty_struct *tty);
138 static int dgap_wait_for_drain(struct tty_struct *tty);
139 static int dgap_set_modem_info(struct tty_struct *tty, unsigned int command, unsigned int __user *value);
140 static int dgap_get_modem_info(struct channel_t *ch, unsigned int __user *value);
141 static int dgap_tty_digisetcustombaud(struct tty_struct *tty, int __user *new_info);
142 static int dgap_tty_digigetcustombaud(struct tty_struct *tty, int __user *retinfo);
143 static int dgap_tty_tiocmget(struct tty_struct *tty);
144 static int dgap_tty_tiocmset(struct tty_struct *tty, unsigned int set, unsigned int clear);
145 static int dgap_tty_send_break(struct tty_struct *tty, int msec);
146 static void dgap_tty_wait_until_sent(struct tty_struct *tty, int timeout);
147 static int dgap_tty_write(struct tty_struct *tty, const unsigned char *buf, int count);
148 static void dgap_tty_set_termios(struct tty_struct *tty, struct ktermios *old_termios);
149 static int dgap_tty_put_char(struct tty_struct *tty, unsigned char c);
150 static void dgap_tty_send_xchar(struct tty_struct *tty, char ch);
152 static int dgap_tty_register(struct board_t *brd);
153 static int dgap_tty_preinit(void);
154 static int dgap_tty_init(struct board_t *);
155 static void dgap_tty_post_uninit(void);
156 static void dgap_tty_uninit(struct board_t *);
157 static void dgap_carrier(struct channel_t *ch);
158 static void dgap_input(struct channel_t *ch);
161 * Our function prototypes from dgap_fep5
163 static void dgap_cmdw_ext(struct channel_t *ch, u16 cmd, u16 word, uint ncmds);
164 static int dgap_event(struct board_t *bd);
166 static void dgap_poll_tasklet(unsigned long data);
167 static void dgap_cmdb(struct channel_t *ch, uchar cmd, uchar byte1, uchar byte2, uint ncmds);
168 static void dgap_cmdw(struct channel_t *ch, uchar cmd, u16 word, uint ncmds);
169 static void dgap_wmove(struct channel_t *ch, char *buf, uint cnt);
170 static int dgap_param(struct tty_struct *tty);
171 static void dgap_parity_scan(struct channel_t *ch, unsigned char *cbuf, unsigned char *fbuf, int *len);
172 static uint dgap_get_custom_baud(struct channel_t *ch);
173 static void dgap_firmware_reset_port(struct channel_t *ch);
176 * Function prototypes from dgap_parse.c.
178 static int dgap_gettok(char **in, struct cnode *p);
179 static char *dgap_getword(char **in);
180 static char *dgap_savestring(char *s);
181 static struct cnode *dgap_newnode(int t);
182 static int dgap_checknode(struct cnode *p);
183 static void dgap_err(char *s);
186 * Function prototypes from dgap_sysfs.h
194 static void dgap_create_ports_sysfiles(struct board_t *bd);
195 static void dgap_remove_ports_sysfiles(struct board_t *bd);
197 static void dgap_create_driver_sysfiles(struct pci_driver *);
198 static void dgap_remove_driver_sysfiles(struct pci_driver *);
200 static void dgap_create_tty_sysfs(struct un_t *un, struct device *c);
201 static void dgap_remove_tty_sysfs(struct device *c);
204 * Function prototypes from dgap_parse.h
206 static int dgap_parsefile(char **in, int Remove);
207 static struct cnode *dgap_find_config(int type, int bus, int slot);
208 static uint dgap_config_get_number_of_ports(struct board_t *bd);
209 static char *dgap_create_config_string(struct board_t *bd, char *string);
210 static uint dgap_config_get_useintr(struct board_t *bd);
211 static uint dgap_config_get_altpin(struct board_t *bd);
213 static int dgap_ms_sleep(ulong ms);
214 static void dgap_do_bios_load(struct board_t *brd, uchar __user *ubios, int len);
215 static void dgap_do_fep_load(struct board_t *brd, uchar __user *ufep, int len);
216 #ifdef DIGI_CONCENTRATORS_SUPPORTED
217 static void dgap_do_conc_load(struct board_t *brd, uchar *uaddr, int len);
219 static int dgap_after_config_loaded(int board);
220 static int dgap_finalize_board_init(struct board_t *brd);
222 static void dgap_get_vpd(struct board_t *brd);
223 static void dgap_do_reset_board(struct board_t *brd);
224 static void dgap_do_wait_for_bios(struct board_t *brd);
225 static void dgap_do_wait_for_fep(struct board_t *brd);
226 static int dgap_tty_register_ports(struct board_t *brd);
227 static int dgap_firmware_load(struct pci_dev *pdev, int card_type);
229 /* Driver load/unload functions */
230 int dgap_init_module(void);
231 void dgap_cleanup_module(void);
233 module_init(dgap_init_module);
234 module_exit(dgap_cleanup_module);
238 * File operations permitted on Control/Management major.
240 static struct file_operations DgapBoardFops =
242 .owner = THIS_MODULE,
249 static uint dgap_NumBoards;
250 static struct board_t *dgap_Board[MAXBOARDS];
251 DEFINE_SPINLOCK(dgap_global_lock);
252 static ulong dgap_poll_counter;
253 static char *dgap_config_buf;
254 static int dgap_driver_state = DRIVER_INITIALIZED;
255 DEFINE_SPINLOCK(dgap_dl_lock);
256 static wait_queue_head_t dgap_dl_wait;
257 static int dgap_dl_action;
258 static int dgap_poll_tick = 20; /* Poll interval - 20 ms */
263 static int dgap_Major_Control_Registered = FALSE;
264 static uint dgap_driver_start = FALSE;
266 static struct class * dgap_class;
268 static struct board_t *dgap_BoardsByMajor[256];
269 static uchar *dgap_TmpWriteBuf = NULL;
270 DECLARE_MUTEX(dgap_TmpWriteSem);
271 static uint dgap_count = 500;
276 DEFINE_SPINLOCK(dgap_poll_lock); /* Poll scheduling lock */
277 static ulong dgap_poll_time; /* Time of next poll */
278 static uint dgap_poll_stop; /* Used to tell poller to stop */
279 static struct timer_list dgap_poll_timer;
284 Card Model Number of Ports Interface
285 ----------------------------------------------------------------
286 Acceleport Xem 4 - 64 (EIA232 & EIA422)
287 Acceleport Xr 4 & 8 (EIA232)
288 Acceleport Xr 920 4 & 8 (EIA232)
289 Acceleport C/X 8 - 128 (EIA232)
290 Acceleport EPC/X 8 - 224 (EIA232)
291 Acceleport Xr/422 4 & 8 (EIA422)
292 Acceleport 2r/920 2 (EIA232)
293 Acceleport 4r/920 4 (EIA232)
294 Acceleport 8r/920 8 (EIA232)
296 IBM 8-Port Asynchronous PCI Adapter (EIA232)
297 IBM 128-Port Asynchronous PCI Adapter (EIA232 & EIA422)
300 static struct pci_device_id dgap_pci_tbl[] = {
301 { DIGI_VID, PCI_DEVICE_XEM_DID, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0 },
302 { DIGI_VID, PCI_DEVICE_CX_DID, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 1 },
303 { DIGI_VID, PCI_DEVICE_CX_IBM_DID, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 2 },
304 { DIGI_VID, PCI_DEVICE_EPCJ_DID, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 3 },
305 { DIGI_VID, PCI_DEVICE_920_2_DID, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 4 },
306 { DIGI_VID, PCI_DEVICE_920_4_DID, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 5 },
307 { DIGI_VID, PCI_DEVICE_920_8_DID, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 6 },
308 { DIGI_VID, PCI_DEVICE_XR_DID, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 7 },
309 { DIGI_VID, PCI_DEVICE_XRJ_DID, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 8 },
310 { DIGI_VID, PCI_DEVICE_XR_422_DID, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 9 },
311 { DIGI_VID, PCI_DEVICE_XR_IBM_DID, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 10 },
312 { DIGI_VID, PCI_DEVICE_XR_SAIP_DID, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 11 },
313 { DIGI_VID, PCI_DEVICE_XR_BULL_DID, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 12 },
314 { DIGI_VID, PCI_DEVICE_920_8_HP_DID, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 13 },
315 { DIGI_VID, PCI_DEVICE_XEM_HP_DID, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 14 },
316 {0,} /* 0 terminated list. */
318 MODULE_DEVICE_TABLE(pci, dgap_pci_tbl);
322 * A generic list of Product names, PCI Vendor ID, and PCI Device ID.
331 static struct board_id dgap_Ids[] =
333 { PPCM, PCI_DEVICE_XEM_NAME, 64, (T_PCXM | T_PCLITE | T_PCIBUS) },
334 { PCX, PCI_DEVICE_CX_NAME, 128, (T_CX | T_PCIBUS) },
335 { PCX, PCI_DEVICE_CX_IBM_NAME, 128, (T_CX | T_PCIBUS) },
336 { PEPC, PCI_DEVICE_EPCJ_NAME, 224, (T_EPC | T_PCIBUS) },
337 { APORT2_920P, PCI_DEVICE_920_2_NAME, 2, (T_PCXR | T_PCLITE | T_PCIBUS) },
338 { APORT4_920P, PCI_DEVICE_920_4_NAME, 4, (T_PCXR | T_PCLITE | T_PCIBUS) },
339 { APORT8_920P, PCI_DEVICE_920_8_NAME, 8, (T_PCXR | T_PCLITE | T_PCIBUS) },
340 { PAPORT8, PCI_DEVICE_XR_NAME, 8, (T_PCXR | T_PCLITE | T_PCIBUS) },
341 { PAPORT8, PCI_DEVICE_XRJ_NAME, 8, (T_PCXR | T_PCLITE | T_PCIBUS) },
342 { PAPORT8, PCI_DEVICE_XR_422_NAME, 8, (T_PCXR | T_PCLITE | T_PCIBUS) },
343 { PAPORT8, PCI_DEVICE_XR_IBM_NAME, 8, (T_PCXR | T_PCLITE | T_PCIBUS) },
344 { PAPORT8, PCI_DEVICE_XR_SAIP_NAME, 8, (T_PCXR | T_PCLITE | T_PCIBUS) },
345 { PAPORT8, PCI_DEVICE_XR_BULL_NAME, 8, (T_PCXR | T_PCLITE | T_PCIBUS) },
346 { APORT8_920P, PCI_DEVICE_920_8_HP_NAME, 8, (T_PCXR | T_PCLITE | T_PCIBUS) },
347 { PPCM, PCI_DEVICE_XEM_HP_NAME, 64, (T_PCXM | T_PCLITE | T_PCIBUS) },
348 {0,} /* 0 terminated list. */
351 static struct pci_driver dgap_driver = {
353 .probe = dgap_init_one,
354 .id_table = dgap_pci_tbl,
355 .remove = dgap_remove_one,
358 struct firmware_info {
359 uchar *conf_name; /* dgap.conf */
360 uchar *bios_name; /* BIOS filename */
361 uchar *fep_name; /* FEP filename */
362 uchar *con_name; /* Concentrator filename FIXME*/
363 int num; /* sequence number */
367 * Firmware - BIOS, FEP, and CONC filenames
369 static struct firmware_info fw_info[] = {
370 { "dgap/dgap.conf", "dgap/sxbios.bin", "dgap/sxfep.bin", 0, 0 },
371 { "dgap/dgap.conf", "dgap/cxpbios.bin", "dgap/cxpfep.bin", 0, 1 },
372 { "dgap/dgap.conf", "dgap/cxpbios.bin", "dgap/cxpfep.bin", 0, 2 },
373 { "dgap/dgap.conf", "dgap/pcibios.bin", "dgap/pcifep.bin", 0, 3 },
374 { "dgap/dgap.conf", "dgap/xrbios.bin", "dgap/xrfep.bin", 0, 4 },
375 { "dgap/dgap.conf", "dgap/xrbios.bin", "dgap/xrfep.bin", 0, 5 },
376 { "dgap/dgap.conf", "dgap/xrbios.bin", "dgap/xrfep.bin", 0, 6 },
377 { "dgap/dgap.conf", "dgap/xrbios.bin", "dgap/xrfep.bin", 0, 7 },
378 { "dgap/dgap.conf", "dgap/xrbios.bin", "dgap/xrfep.bin", 0, 8 },
379 { "dgap/dgap.conf", "dgap/xrbios.bin", "dgap/xrfep.bin", 0, 9 },
380 { "dgap/dgap.conf", "dgap/xrbios.bin", "dgap/xrfep.bin", 0, 10 },
381 { "dgap/dgap.conf", "dgap/xrbios.bin", "dgap/xrfep.bin", 0, 11 },
382 { "dgap/dgap.conf", "dgap/xrbios.bin", "dgap/xrfep.bin", 0, 12 },
383 { "dgap/dgap.conf", "dgap/xrbios.bin", "dgap/xrfep.bin", 0, 13 },
384 { "dgap/dgap.conf", "dgap/sxbios.bin", "dgap/sxfep.bin", 0, 14 },
389 static char *dgap_driver_state_text[] = {
390 "Driver Initialized",
391 "Driver needs configuration load.",
392 "Driver requested configuration from download daemon.",
397 * Default transparent print information.
399 static struct digi_t dgap_digi_init = {
400 .digi_flags = DIGI_COOK, /* Flags */
401 .digi_maxcps = 100, /* Max CPS */
402 .digi_maxchar = 50, /* Max chars in print queue */
403 .digi_bufsize = 100, /* Printer buffer size */
404 .digi_onlen = 4, /* size of printer on string */
405 .digi_offlen = 4, /* size of printer off string */
406 .digi_onstr = "\033[5i", /* ANSI printer on string ] */
407 .digi_offstr = "\033[4i", /* ANSI printer off string ] */
408 .digi_term = "ansi" /* default terminal type */
413 * Define a local default termios struct. All ports will be created
414 * with this termios initially.
416 * This defines a raw port at 9600 baud, 8 data bits, no parity,
420 static struct ktermios DgapDefaultTermios =
422 .c_iflag = (DEFAULT_IFLAGS), /* iflags */
423 .c_oflag = (DEFAULT_OFLAGS), /* oflags */
424 .c_cflag = (DEFAULT_CFLAGS), /* cflags */
425 .c_lflag = (DEFAULT_LFLAGS), /* lflags */
430 static const struct tty_operations dgap_tty_ops = {
431 .open = dgap_tty_open,
432 .close = dgap_tty_close,
433 .write = dgap_tty_write,
434 .write_room = dgap_tty_write_room,
435 .flush_buffer = dgap_tty_flush_buffer,
436 .chars_in_buffer = dgap_tty_chars_in_buffer,
437 .flush_chars = dgap_tty_flush_chars,
438 .ioctl = dgap_tty_ioctl,
439 .set_termios = dgap_tty_set_termios,
440 .stop = dgap_tty_stop,
441 .start = dgap_tty_start,
442 .throttle = dgap_tty_throttle,
443 .unthrottle = dgap_tty_unthrottle,
444 .hangup = dgap_tty_hangup,
445 .put_char = dgap_tty_put_char,
446 .tiocmget = dgap_tty_tiocmget,
447 .tiocmset = dgap_tty_tiocmset,
448 .break_ctl = dgap_tty_send_break,
449 .wait_until_sent = dgap_tty_wait_until_sent,
450 .send_xchar = dgap_tty_send_xchar
454 * Our needed internal static variables from dgap_parse.c
456 static struct cnode dgap_head;
458 static char dgap_cword[MAXCWORD];
465 static struct toklist dgap_tlist[] = {
466 { BEGIN, "config_begin" },
467 { END, "config_end" },
469 { PCX, "Digi_AccelePort_C/X_PCI" }, /* C/X_PCI */
470 { PEPC, "Digi_AccelePort_EPC/X_PCI" }, /* EPC/X_PCI */
471 { PPCM, "Digi_AccelePort_Xem_PCI" }, /* PCI/Xem */
472 { APORT2_920P, "Digi_AccelePort_2r_920_PCI" },
473 { APORT4_920P, "Digi_AccelePort_4r_920_PCI" },
474 { APORT8_920P, "Digi_AccelePort_8r_920_PCI" },
475 { PAPORT4, "Digi_AccelePort_4r_PCI(EIA-232/RS-422)" },
476 { PAPORT8, "Digi_AccelePort_8r_PCI(EIA-232/RS-422)" },
478 { PCIINFO, "pciinfo" },
481 { CONC, "concentrator" },
491 { CONNECT, "connect" },
492 { METHOD, "method" },
493 { STATUS, "status" },
494 { CUSTOM, "Custom" },
500 { NPORTS, "nports" },
505 { ALTPIN, "altpin" },
506 { USEINTR, "useintr" },
507 { TTSIZ, "ttysize" },
509 { BSSIZ, "boardsize" },
510 { UNTSIZ, "schedsize" },
511 { F2SIZ, "f2200size" },
512 { VPSIZ, "vpixsize" },
516 /************************************************************************
518 * Driver load/unload functions
520 ************************************************************************/
525 * Module load. This is where it all starts.
527 int dgap_init_module(void)
531 APR(("%s, Digi International Part Number %s\n", DG_NAME, DG_PART));
533 dgap_driver_state = DRIVER_NEED_CONFIG_LOAD;
536 * Initialize global stuff
545 * Find and configure all the cards
547 rc = dgap_init_pci();
550 * If something went wrong in the scan, bail out of driver.
553 /* Only unregister the pci driver if it was actually registered. */
555 pci_unregister_driver(&dgap_driver);
557 printk("WARNING: dgap driver load failed. No DGAP boards found.\n");
559 dgap_cleanup_module();
562 dgap_create_driver_sysfiles(&dgap_driver);
563 dgap_driver_state = DRIVER_READY;
566 DPR_INIT(("Finished init_module. Returning %d\n", rc));
574 static int dgap_start(void)
579 if (dgap_driver_start == FALSE) {
581 dgap_driver_start = TRUE;
583 /* make sure that the globals are init'd before we do anything else */
588 APR(("For the tools package or updated drivers please visit http://www.digi.com\n"));
591 * Register our base character device into the kernel.
592 * This allows the download daemon to connect to the downld device
593 * before any of the boards are init'ed.
595 if (!dgap_Major_Control_Registered) {
597 * Register management/dpa devices
599 rc = register_chrdev(DIGI_DGAP_MAJOR, "dgap", &DgapBoardFops);
601 APR(("Can't register dgap driver device (%d)\n", rc));
605 dgap_class = class_create(THIS_MODULE, "dgap_mgmt");
606 device_create(dgap_class, NULL,
607 MKDEV(DIGI_DGAP_MAJOR, 0),
609 dgap_Major_Control_Registered = TRUE;
613 * Init any global tty stuff.
615 rc = dgap_tty_preinit();
618 APR(("tty preinit - not enough memory (%d)\n", rc));
622 /* Start the poller */
623 DGAP_LOCK(dgap_poll_lock, flags);
624 init_timer(&dgap_poll_timer);
625 dgap_poll_timer.function = dgap_poll_handler;
626 dgap_poll_timer.data = 0;
627 dgap_poll_time = jiffies + dgap_jiffies_from_ms(dgap_poll_tick);
628 dgap_poll_timer.expires = dgap_poll_time;
629 DGAP_UNLOCK(dgap_poll_lock, flags);
631 add_timer(&dgap_poll_timer);
633 dgap_driver_state = DRIVER_NEED_CONFIG_LOAD;
641 * Register pci driver, and return how many boards we have.
643 static int dgap_init_pci(void)
645 return pci_register_driver(&dgap_driver);
649 /* returns count (>= 0), or negative on error */
650 static int dgap_init_one(struct pci_dev *pdev, const struct pci_device_id *ent)
654 /* wake up and enable device */
655 rc = pci_enable_device(pdev);
660 rc = dgap_probe1(pdev, ent->driver_data);
663 DPR_INIT(("Incrementing numboards to %d\n", dgap_NumBoards));
664 rc = dgap_firmware_load(pdev, ent->driver_data);
671 static int dgap_probe1(struct pci_dev *pdev, int card_type)
673 return dgap_found_board(pdev, card_type);
677 static void dgap_remove_one(struct pci_dev *dev)
684 * dgap_cleanup_module()
686 * Module unload. This is where it all ends.
688 void dgap_cleanup_module(void)
693 DGAP_LOCK(dgap_poll_lock, lock_flags);
695 DGAP_UNLOCK(dgap_poll_lock, lock_flags);
697 /* Turn off poller right away. */
698 del_timer_sync( &dgap_poll_timer);
700 dgap_remove_driver_sysfiles(&dgap_driver);
703 if (dgap_Major_Control_Registered) {
704 device_destroy(dgap_class, MKDEV(DIGI_DGAP_MAJOR, 0));
705 device_destroy(dgap_class, MKDEV(DIGI_DGAP_MAJOR, 1));
706 class_destroy(dgap_class);
707 unregister_chrdev(DIGI_DGAP_MAJOR, "dgap");
710 kfree(dgap_config_buf);
712 for (i = 0; i < dgap_NumBoards; ++i) {
713 dgap_remove_ports_sysfiles(dgap_Board[i]);
714 dgap_tty_uninit(dgap_Board[i]);
715 dgap_cleanup_board(dgap_Board[i]);
718 dgap_tty_post_uninit();
720 #if defined(DGAP_TRACER)
721 /* last thing, make sure we release the tracebuffer */
725 pci_unregister_driver(&dgap_driver);
730 * dgap_cleanup_board()
732 * Free all the memory associated with a board
734 static void dgap_cleanup_board(struct board_t *brd)
738 if(!brd || brd->magic != DGAP_BOARD_MAGIC)
741 if (brd->intr_used && brd->irq)
742 free_irq(brd->irq, brd);
744 tasklet_kill(&brd->helper_tasklet);
746 if (brd->re_map_port) {
747 release_mem_region(brd->membase + 0x200000, 0x200000);
748 iounmap(brd->re_map_port);
749 brd->re_map_port = NULL;
752 if (brd->re_map_membase) {
753 release_mem_region(brd->membase, 0x200000);
754 iounmap(brd->re_map_membase);
755 brd->re_map_membase = NULL;
758 if (brd->msgbuf_head) {
761 DGAP_LOCK(dgap_global_lock, flags);
763 printk("%s", brd->msgbuf_head);
764 kfree(brd->msgbuf_head);
765 brd->msgbuf_head = NULL;
766 DGAP_UNLOCK(dgap_global_lock, flags);
769 /* Free all allocated channels structs */
770 for (i = 0; i < MAXPORTS ; i++) {
771 if (brd->channels[i]) {
772 kfree(brd->channels[i]);
773 brd->channels[i] = NULL;
778 kfree(brd->flipflagbuf);
780 dgap_Board[brd->boardnum] = NULL;
789 * A board has been found, init it.
791 static int dgap_found_board(struct pci_dev *pdev, int id)
794 unsigned int pci_irq;
798 /* get the board structure and prep it */
799 brd = dgap_Board[dgap_NumBoards] =
800 (struct board_t *) kzalloc(sizeof(struct board_t), GFP_KERNEL);
802 APR(("memory allocation for board structure failed\n"));
806 /* make a temporary message buffer for the boot messages */
807 brd->msgbuf = brd->msgbuf_head =
808 (char *) kzalloc(sizeof(char) * 8192, GFP_KERNEL);
811 APR(("memory allocation for board msgbuf failed\n"));
815 /* store the info for the board we've found */
816 brd->magic = DGAP_BOARD_MAGIC;
817 brd->boardnum = dgap_NumBoards;
819 brd->vendor = dgap_pci_tbl[id].vendor;
820 brd->device = dgap_pci_tbl[id].device;
822 brd->pci_bus = pdev->bus->number;
823 brd->pci_slot = PCI_SLOT(pdev->devfn);
824 brd->name = dgap_Ids[id].name;
825 brd->maxports = dgap_Ids[id].maxports;
826 brd->type = dgap_Ids[id].config_type;
827 brd->dpatype = dgap_Ids[id].dpatype;
828 brd->dpastatus = BD_NOFEP;
829 init_waitqueue_head(&brd->state_wait);
831 DGAP_SPINLOCK_INIT(brd->bd_lock);
833 brd->state = BOARD_FOUND;
835 brd->inhibit_poller = FALSE;
836 brd->wait_for_bios = 0;
837 brd->wait_for_fep = 0;
839 for (i = 0; i < MAXPORTS; i++) {
840 brd->channels[i] = NULL;
843 /* store which card & revision we have */
844 pci_read_config_word(pdev, PCI_SUBSYSTEM_VENDOR_ID, &brd->subvendor);
845 pci_read_config_word(pdev, PCI_SUBSYSTEM_ID, &brd->subdevice);
846 pci_read_config_byte(pdev, PCI_REVISION_ID, &brd->rev);
851 /* get the PCI Base Address Registers */
853 /* Xr Jupiter and EPC use BAR 2 */
854 if (brd->device == PCI_DEVICE_XRJ_DID || brd->device == PCI_DEVICE_EPCJ_DID) {
855 brd->membase = pci_resource_start(pdev, 2);
856 brd->membase_end = pci_resource_end(pdev, 2);
858 /* Everyone else uses BAR 0 */
860 brd->membase = pci_resource_start(pdev, 0);
861 brd->membase_end = pci_resource_end(pdev, 0);
865 APR(("card has no PCI IO resources, failing board.\n"));
869 if (brd->membase & 1)
875 * On the PCI boards, there is no IO space allocated
876 * The I/O registers will be in the first 3 bytes of the
877 * upper 2MB of the 4MB memory space. The board memory
878 * will be mapped into the low 2MB of the 4MB memory space
880 brd->port = brd->membase + PCI_IO_OFFSET;
881 brd->port_end = brd->port + PCI_IO_SIZE;
885 * Special initialization for non-PLX boards
887 if (brd->device != PCI_DEVICE_XRJ_DID && brd->device != PCI_DEVICE_EPCJ_DID) {
890 pci_write_config_byte(pdev, 0x40, 0);
891 pci_write_config_byte(pdev, 0x46, 0);
893 /* Limit burst length to 2 doubleword transactions */
894 pci_write_config_byte(pdev, 0x42, 1);
897 * Enable IO and mem if not already done.
898 * This was needed for support on Itanium.
900 pci_read_config_word(pdev, PCI_COMMAND, &cmd);
901 cmd |= (PCI_COMMAND_IO | PCI_COMMAND_MEMORY);
902 pci_write_config_word(pdev, PCI_COMMAND, cmd);
905 /* init our poll helper tasklet */
906 tasklet_init(&brd->helper_tasklet, dgap_poll_tasklet, (unsigned long) brd);
908 /* Log the information about the board */
909 dgap_mbuf(brd, DRVSTR": board %d: %s (rev %d), irq %d\n",
910 dgap_NumBoards, brd->name, brd->rev, brd->irq);
912 DPR_INIT(("dgap_scan(%d) - printing out the msgbuf\n", i));
913 DGAP_LOCK(dgap_global_lock, flags);
915 printk("%s", brd->msgbuf_head);
916 kfree(brd->msgbuf_head);
917 brd->msgbuf_head = NULL;
918 DGAP_UNLOCK(dgap_global_lock, flags);
920 i = dgap_do_remap(brd);
922 brd->state = BOARD_FAILED;
924 brd->state = NEED_RESET;
930 static int dgap_finalize_board_init(struct board_t *brd) {
934 DPR_INIT(("dgap_finalize_board_init() - start\n"));
936 if (!brd || brd->magic != DGAP_BOARD_MAGIC)
939 DPR_INIT(("dgap_finalize_board_init() - start #2\n"));
941 brd->use_interrupts = dgap_config_get_useintr(brd);
944 * Set up our interrupt handler if we are set to do interrupts.
946 if (brd->use_interrupts && brd->irq) {
948 rc = request_irq(brd->irq, dgap_intr, IRQF_SHARED, "DGAP", brd);
951 dgap_mbuf(brd, DRVSTR": Failed to hook IRQ %d. Board will work in poll mode.\n",
964 static int dgap_firmware_load(struct pci_dev *pdev, int card_type)
966 struct board_t *brd = dgap_Board[dgap_NumBoards - 1];
967 const struct firmware *fw;
971 dgap_do_reset_board(brd);
973 if ((fw_info[card_type].conf_name) &&
974 (dgap_driver_state == DRIVER_NEED_CONFIG_LOAD)) {
975 ret = request_firmware(&fw, fw_info[card_type].conf_name,
978 pr_err("dgap: config file %s not found\n",
979 fw_info[card_type].conf_name);
982 if (!dgap_config_buf) {
983 dgap_config_buf = kmalloc(fw->size + 1, GFP_ATOMIC);
984 if (!dgap_config_buf) {
985 release_firmware(fw);
990 memcpy(dgap_config_buf, fw->data, fw->size);
991 release_firmware(fw);
992 dgap_config_buf[fw->size + 1] = '\0';
994 if (dgap_parsefile(&dgap_config_buf, TRUE) != 0)
997 dgap_driver_state = -1;
1000 ret = dgap_after_config_loaded(brd->boardnum);
1004 * Match this board to a config the user created for us.
1007 dgap_find_config(brd->type, brd->pci_bus, brd->pci_slot);
1010 * Because the 4 port Xr products share the same PCI ID
1011 * as the 8 port Xr products, if we receive a NULL config
1012 * back, and this is a PAPORT8 board, retry with a
1013 * PAPORT4 attempt as well.
1015 if (brd->type == PAPORT8 && !brd->bd_config)
1017 dgap_find_config(PAPORT4, brd->pci_bus, brd->pci_slot);
1019 if (!brd->bd_config) {
1020 pr_err("dgap: No valid configuration found\n");
1024 dgap_tty_register(brd);
1025 dgap_finalize_board_init(brd);
1027 if (fw_info[card_type].bios_name) {
1028 ret = request_firmware(&fw, fw_info[card_type].bios_name,
1031 pr_err("dgap: bios file %s not found\n",
1032 fw_info[card_type].bios_name);
1035 dgap_do_bios_load(brd, (char *)fw->data, fw->size);
1036 release_firmware(fw);
1038 /* Wait for BIOS to test board... */
1039 dgap_do_wait_for_bios(brd);
1041 if (brd->state != FINISHED_BIOS_LOAD)
1045 if (fw_info[card_type].fep_name) {
1046 ret = request_firmware(&fw, fw_info[card_type].fep_name,
1049 pr_err("dgap: fep file %s not found\n",
1050 fw_info[card_type].fep_name);
1053 dgap_do_fep_load(brd, (char *)fw->data, fw->size);
1054 release_firmware(fw);
1056 /* Wait for FEP to load on board... */
1057 dgap_do_wait_for_fep(brd);
1059 if (brd->state != FINISHED_FEP_LOAD)
1063 #ifdef DIGI_CONCENTRATORS_SUPPORTED
1065 * If this is a CX or EPCX, we need to see if the firmware
1066 * is requesting a concentrator image from us.
1068 if ((bd->type == PCX) || (bd->type == PEPC)) {
1069 chk_addr = (u16 *) (vaddr + DOWNREQ);
1070 /* Nonzero if FEP is requesting concentrator image. */
1071 check = readw(chk_addr);
1072 vaddr = brd->re_map_membase;
1075 if (fw_info[card_type].con_name && check && vaddr) {
1076 ret = request_firmware(&fw, fw_info[card_type].con_name,
1079 pr_err("dgap: conc file %s not found\n",
1080 fw_info[card_type].con_name);
1083 /* Put concentrator firmware loading code here */
1084 offset = readw((u16 *) (vaddr + DOWNREQ));
1085 memcpy_toio(offset, fw->data, fw->size);
1087 dgap_do_conc_load(brd, (char *)fw->data, fw->size)
1088 release_firmware(fw);
1092 * Do tty device initialization.
1094 ret = dgap_tty_init(brd);
1096 dgap_tty_uninit(brd);
1097 pr_err("dgap: Can't init tty devices (%d)\n", ret);
1101 ret = dgap_tty_register_ports(brd);
1105 brd->state = BOARD_READY;
1106 brd->dpastatus = BD_RUNNING;
1114 static int dgap_do_remap(struct board_t *brd)
1116 if (!brd || brd->magic != DGAP_BOARD_MAGIC)
1119 if (!request_mem_region(brd->membase, 0x200000, "dgap")) {
1120 APR(("dgap: mem_region %lx already in use.\n", brd->membase));
1124 if (!request_mem_region(brd->membase + PCI_IO_OFFSET, 0x200000, "dgap")) {
1125 APR(("dgap: mem_region IO %lx already in use.\n",
1126 brd->membase + PCI_IO_OFFSET));
1127 release_mem_region(brd->membase, 0x200000);
1131 brd->re_map_membase = ioremap(brd->membase, 0x200000);
1132 if (!brd->re_map_membase) {
1133 APR(("dgap: ioremap mem %lx cannot be mapped.\n", brd->membase));
1134 release_mem_region(brd->membase, 0x200000);
1135 release_mem_region(brd->membase + PCI_IO_OFFSET, 0x200000);
1139 brd->re_map_port = ioremap((brd->membase + PCI_IO_OFFSET), 0x200000);
1140 if (!brd->re_map_port) {
1141 release_mem_region(brd->membase, 0x200000);
1142 release_mem_region(brd->membase + PCI_IO_OFFSET, 0x200000);
1143 iounmap(brd->re_map_membase);
1144 APR(("dgap: ioremap IO mem %lx cannot be mapped.\n",
1145 brd->membase + PCI_IO_OFFSET));
1149 DPR_INIT(("remapped io: 0x%p remapped mem: 0x%p\n",
1150 brd->re_map_port, brd->re_map_membase));
1155 /*****************************************************************************
1175 * As each timer expires, it determines (a) whether the "transmit"
1176 * waiter needs to be woken up, and (b) whether the poller needs to
1179 ******************************************************************************/
1181 static void dgap_poll_handler(ulong dummy)
1184 struct board_t *brd;
1185 unsigned long lock_flags;
1188 dgap_poll_counter++;
1192 * Do not start the board state machine until
1193 * driver tells us its up and running, and has
1194 * everything it needs.
1196 if (dgap_driver_state != DRIVER_READY)
1197 goto schedule_poller;
1200 * If we have just 1 board, or the system is not SMP,
1201 * then use the typical old style poller.
1202 * Otherwise, use our new tasklet based poller, which should
1203 * speed things up for multiple boards.
1205 if ( (dgap_NumBoards == 1) || (num_online_cpus() <= 1) ) {
1206 for (i = 0; i < dgap_NumBoards; i++) {
1208 brd = dgap_Board[i];
1210 if (brd->state == BOARD_FAILED) {
1213 if (!brd->intr_running) {
1214 /* Call the real board poller directly */
1215 dgap_poll_tasklet((unsigned long) brd);
1220 /* Go thru each board, kicking off a tasklet for each if needed */
1221 for (i = 0; i < dgap_NumBoards; i++) {
1222 brd = dgap_Board[i];
1225 * Attempt to grab the board lock.
1227 * If we can't get it, no big deal, the next poll will get it.
1228 * Basically, I just really don't want to spin in here, because I want
1229 * to kick off my tasklets as fast as I can, and then get out the poller.
1231 if (!spin_trylock(&brd->bd_lock)) {
1235 /* If board is in a failed state, don't bother scheduling a tasklet */
1236 if (brd->state == BOARD_FAILED) {
1237 spin_unlock(&brd->bd_lock);
1241 /* Schedule a poll helper task */
1242 if (!brd->intr_running) {
1243 tasklet_schedule(&brd->helper_tasklet);
1247 * Can't do DGAP_UNLOCK here, as we don't have
1248 * lock_flags because we did a trylock above.
1250 spin_unlock(&brd->bd_lock);
1257 * Schedule ourself back at the nominal wakeup interval.
1259 DGAP_LOCK(dgap_poll_lock, lock_flags );
1260 dgap_poll_time += dgap_jiffies_from_ms(dgap_poll_tick);
1262 new_time = dgap_poll_time - jiffies;
1264 if ((ulong) new_time >= 2 * dgap_poll_tick) {
1265 dgap_poll_time = jiffies + dgap_jiffies_from_ms(dgap_poll_tick);
1268 dgap_poll_timer.function = dgap_poll_handler;
1269 dgap_poll_timer.data = 0;
1270 dgap_poll_timer.expires = dgap_poll_time;
1271 DGAP_UNLOCK(dgap_poll_lock, lock_flags );
1273 if (!dgap_poll_stop)
1274 add_timer(&dgap_poll_timer);
1283 * Driver interrupt handler.
1285 static irqreturn_t dgap_intr(int irq, void *voidbrd)
1287 struct board_t *brd = (struct board_t *) voidbrd;
1290 APR(("Received interrupt (%d) with null board associated\n", irq));
1295 * Check to make sure its for us.
1297 if (brd->magic != DGAP_BOARD_MAGIC) {
1298 APR(("Received interrupt (%d) with a board pointer that wasn't ours!\n", irq));
1305 * Schedule tasklet to run at a better time.
1307 tasklet_schedule(&brd->helper_tasklet);
1313 * dgap_init_globals()
1315 * This is where we initialize the globals from the static insmod
1316 * configuration variables. These are declared near the head of
1319 static void dgap_init_globals(void)
1323 dgap_rawreadok = rawreadok;
1324 dgap_trcbuf_size = trcbuf_size;
1327 for (i = 0; i < MAXBOARDS; i++) {
1328 dgap_Board[i] = NULL;
1331 init_timer( &dgap_poll_timer );
1333 init_waitqueue_head(&dgap_dl_wait);
1338 /************************************************************************
1342 ************************************************************************/
1348 * Used to print to the message buffer during board init.
1350 static void dgap_mbuf(struct board_t *brd, const char *fmt, ...) {
1354 unsigned long flags;
1357 DGAP_LOCK(dgap_global_lock, flags);
1359 /* Format buf using fmt and arguments contained in ap. */
1361 i = vsnprintf(buf, sizeof(buf), fmt, ap);
1366 if (!brd || !brd->msgbuf) {
1368 DGAP_UNLOCK(dgap_global_lock, flags);
1372 length = strlen(buf) + 1;
1373 if (brd->msgbuf - brd->msgbuf_head < length)
1374 length = brd->msgbuf - brd->msgbuf_head;
1375 memcpy(brd->msgbuf, buf, length);
1376 brd->msgbuf += length;
1378 DGAP_UNLOCK(dgap_global_lock, flags);
1385 * Put the driver to sleep for x ms's
1387 * Returns 0 if timed out, !0 (showing signal) if interrupted by a signal.
1389 static int dgap_ms_sleep(ulong ms)
1391 current->state = TASK_INTERRUPTIBLE;
1392 schedule_timeout((ms * HZ) / 1000);
1393 return (signal_pending(current));
1399 /************************************************************************
1401 * TTY Initialization/Cleanup Functions
1403 ************************************************************************/
1406 * dgap_tty_preinit()
1408 * Initialize any global tty related data before we download any boards.
1410 static int dgap_tty_preinit(void)
1412 unsigned long flags;
1414 DGAP_LOCK(dgap_global_lock, flags);
1417 * Allocate a buffer for doing the copy from user space to
1418 * kernel space in dgap_input(). We only use one buffer and
1419 * control access to it with a semaphore. If we are paging, we
1420 * are already in trouble so one buffer won't hurt much anyway.
1422 dgap_TmpWriteBuf = kmalloc(WRITEBUFLEN, GFP_ATOMIC);
1424 if (!dgap_TmpWriteBuf) {
1425 DGAP_UNLOCK(dgap_global_lock, flags);
1426 DPR_INIT(("unable to allocate tmp write buf"));
1430 DGAP_UNLOCK(dgap_global_lock, flags);
1436 * dgap_tty_register()
1438 * Init the tty subsystem for this board.
1440 static int dgap_tty_register(struct board_t *brd)
1444 DPR_INIT(("tty_register start"));
1446 brd->SerialDriver = alloc_tty_driver(MAXPORTS);
1448 snprintf(brd->SerialName, MAXTTYNAMELEN, "tty_dgap_%d_", brd->boardnum);
1449 brd->SerialDriver->name = brd->SerialName;
1450 brd->SerialDriver->name_base = 0;
1451 brd->SerialDriver->major = 0;
1452 brd->SerialDriver->minor_start = 0;
1453 brd->SerialDriver->type = TTY_DRIVER_TYPE_SERIAL;
1454 brd->SerialDriver->subtype = SERIAL_TYPE_NORMAL;
1455 brd->SerialDriver->init_termios = DgapDefaultTermios;
1456 brd->SerialDriver->driver_name = DRVSTR;
1457 brd->SerialDriver->flags = (TTY_DRIVER_REAL_RAW | TTY_DRIVER_DYNAMIC_DEV | TTY_DRIVER_HARDWARE_BREAK);
1459 /* The kernel wants space to store pointers to tty_structs */
1460 brd->SerialDriver->ttys = kzalloc(MAXPORTS * sizeof(struct tty_struct *), GFP_KERNEL);
1461 if (!brd->SerialDriver->ttys)
1465 * Entry points for driver. Called by the kernel from
1466 * tty_io.c and n_tty.c.
1468 tty_set_operations(brd->SerialDriver, &dgap_tty_ops);
1471 * If we're doing transparent print, we have to do all of the above
1472 * again, separately so we don't get the LD confused about what major
1473 * we are when we get into the dgap_tty_open() routine.
1475 brd->PrintDriver = alloc_tty_driver(MAXPORTS);
1477 snprintf(brd->PrintName, MAXTTYNAMELEN, "pr_dgap_%d_", brd->boardnum);
1478 brd->PrintDriver->name = brd->PrintName;
1479 brd->PrintDriver->name_base = 0;
1480 brd->PrintDriver->major = 0;
1481 brd->PrintDriver->minor_start = 0;
1482 brd->PrintDriver->type = TTY_DRIVER_TYPE_SERIAL;
1483 brd->PrintDriver->subtype = SERIAL_TYPE_NORMAL;
1484 brd->PrintDriver->init_termios = DgapDefaultTermios;
1485 brd->PrintDriver->driver_name = DRVSTR;
1486 brd->PrintDriver->flags = (TTY_DRIVER_REAL_RAW | TTY_DRIVER_DYNAMIC_DEV | TTY_DRIVER_HARDWARE_BREAK);
1488 /* The kernel wants space to store pointers to tty_structs */
1489 brd->PrintDriver->ttys = kzalloc(MAXPORTS * sizeof(struct tty_struct *), GFP_KERNEL);
1490 if (!brd->PrintDriver->ttys)
1494 * Entry points for driver. Called by the kernel from
1495 * tty_io.c and n_tty.c.
1497 tty_set_operations(brd->PrintDriver, &dgap_tty_ops);
1499 if (!brd->dgap_Major_Serial_Registered) {
1500 /* Register tty devices */
1501 rc = tty_register_driver(brd->SerialDriver);
1503 APR(("Can't register tty device (%d)\n", rc));
1506 brd->dgap_Major_Serial_Registered = TRUE;
1507 dgap_BoardsByMajor[brd->SerialDriver->major] = brd;
1508 brd->dgap_Serial_Major = brd->SerialDriver->major;
1511 if (!brd->dgap_Major_TransparentPrint_Registered) {
1512 /* Register Transparent Print devices */
1513 rc = tty_register_driver(brd->PrintDriver);
1515 APR(("Can't register Transparent Print device (%d)\n", rc));
1518 brd->dgap_Major_TransparentPrint_Registered = TRUE;
1519 dgap_BoardsByMajor[brd->PrintDriver->major] = brd;
1520 brd->dgap_TransparentPrint_Major = brd->PrintDriver->major;
1523 DPR_INIT(("DGAP REGISTER TTY: MAJORS: %d %d\n", brd->SerialDriver->major,
1524 brd->PrintDriver->major));
1533 * Init the tty subsystem. Called once per board after board has been
1534 * downloaded and init'ed.
1536 static int dgap_tty_init(struct board_t *brd)
1540 uint true_count = 0;
1543 struct channel_t *ch;
1550 DPR_INIT(("dgap_tty_init start\n"));
1553 * Initialize board structure elements.
1556 vaddr = brd->re_map_membase;
1557 true_count = readw((vaddr + NCHAN));
1559 brd->nasync = dgap_config_get_number_of_ports(brd);
1562 brd->nasync = brd->maxports;
1565 if (brd->nasync > brd->maxports) {
1566 brd->nasync = brd->maxports;
1569 if (true_count != brd->nasync) {
1570 if ((brd->type == PPCM) && (true_count == 64)) {
1571 APR(("***WARNING**** %s configured for %d ports, has %d ports.\nPlease make SURE the EBI cable running from the card\nto each EM module is plugged into EBI IN!\n",
1572 brd->name, brd->nasync, true_count));
1574 else if ((brd->type == PPCM) && (true_count == 0)) {
1575 APR(("***WARNING**** %s configured for %d ports, has %d ports.\nPlease make SURE the EBI cable running from the card\nto each EM module is plugged into EBI IN!\n",
1576 brd->name, brd->nasync, true_count));
1579 APR(("***WARNING**** %s configured for %d ports, has %d ports.\n",
1580 brd->name, brd->nasync, true_count));
1583 brd->nasync = true_count;
1585 /* If no ports, don't bother going any further */
1587 brd->state = BOARD_FAILED;
1588 brd->dpastatus = BD_NOFEP;
1594 * Allocate channel memory that might not have been allocated
1595 * when the driver was first loaded.
1597 for (i = 0; i < brd->nasync; i++) {
1598 if (!brd->channels[i]) {
1599 brd->channels[i] = kzalloc(sizeof(struct channel_t), GFP_ATOMIC);
1600 if (!brd->channels[i]) {
1601 DPR_CORE(("%s:%d Unable to allocate memory for channel struct\n",
1602 __FILE__, __LINE__));
1607 ch = brd->channels[0];
1608 vaddr = brd->re_map_membase;
1610 bs = (struct bs_t *) ((ulong) vaddr + CHANBUF);
1611 cm = (struct cm_t *) ((ulong) vaddr + CMDBUF);
1615 /* Set up channel variables */
1616 for (i = 0; i < brd->nasync; i++, ch = brd->channels[i], bs++) {
1618 if (!brd->channels[i])
1621 DGAP_SPINLOCK_INIT(ch->ch_lock);
1623 /* Store all our magic numbers */
1624 ch->magic = DGAP_CHANNEL_MAGIC;
1625 ch->ch_tun.magic = DGAP_UNIT_MAGIC;
1626 ch->ch_tun.un_type = DGAP_SERIAL;
1627 ch->ch_tun.un_ch = ch;
1628 ch->ch_tun.un_dev = i;
1630 ch->ch_pun.magic = DGAP_UNIT_MAGIC;
1631 ch->ch_pun.un_type = DGAP_PRINT;
1632 ch->ch_pun.un_ch = ch;
1633 ch->ch_pun.un_dev = i;
1635 ch->ch_vaddr = vaddr;
1640 ch->ch_digi = dgap_digi_init;
1643 * Set up digi dsr and dcd bits based on altpin flag.
1645 if (dgap_config_get_altpin(brd)) {
1648 ch->ch_digi.digi_flags |= DIGI_ALTPIN;
1652 ch->ch_dsr = DM_DSR;
1655 ch->ch_taddr = vaddr + ((ch->ch_bs->tx_seg) << 4);
1656 ch->ch_raddr = vaddr + ((ch->ch_bs->rx_seg) << 4);
1659 ch->ch_tsize = readw(&(ch->ch_bs->tx_max)) + 1;
1660 ch->ch_rsize = readw(&(ch->ch_bs->rx_max)) + 1;
1664 /* .25 second delay */
1665 ch->ch_close_delay = 250;
1668 * Set queue water marks, interrupt mask,
1669 * and general tty parameters.
1671 ch->ch_tlw = tlw = ch->ch_tsize >= 2000 ? ((ch->ch_tsize * 5) / 8) : ch->ch_tsize / 2;
1673 dgap_cmdw(ch, STLOW, tlw, 0);
1675 dgap_cmdw(ch, SRLOW, ch->ch_rsize / 2, 0);
1677 dgap_cmdw(ch, SRHIGH, 7 * ch->ch_rsize / 8, 0);
1679 ch->ch_mistat = readb(&(ch->ch_bs->m_stat));
1681 init_waitqueue_head(&ch->ch_flags_wait);
1682 init_waitqueue_head(&ch->ch_tun.un_flags_wait);
1683 init_waitqueue_head(&ch->ch_pun.un_flags_wait);
1684 init_waitqueue_head(&ch->ch_sniff_wait);
1686 /* Turn on all modem interrupts for now */
1687 modem = (DM_CD | DM_DSR | DM_CTS | DM_RI);
1688 writeb(modem, &(ch->ch_bs->m_int));
1691 * Set edelay to 0 if interrupts are turned on,
1692 * otherwise set edelay to the usual 100.
1695 writew(0, &(ch->ch_bs->edelay));
1697 writew(100, &(ch->ch_bs->edelay));
1699 writeb(1, &(ch->ch_bs->idata));
1703 DPR_INIT(("dgap_tty_init finish\n"));
1710 * dgap_tty_post_uninit()
1712 * UnInitialize any global tty related data.
1714 static void dgap_tty_post_uninit(void)
1716 kfree(dgap_TmpWriteBuf);
1717 dgap_TmpWriteBuf = NULL;
1724 * Uninitialize the TTY portion of this driver. Free all memory and
1727 static void dgap_tty_uninit(struct board_t *brd)
1731 if (brd->dgap_Major_Serial_Registered) {
1732 dgap_BoardsByMajor[brd->SerialDriver->major] = NULL;
1733 brd->dgap_Serial_Major = 0;
1734 for (i = 0; i < brd->nasync; i++) {
1735 tty_port_destroy(&brd->SerialPorts[i]);
1736 dgap_remove_tty_sysfs(brd->channels[i]->ch_tun.un_sysfs);
1737 tty_unregister_device(brd->SerialDriver, i);
1739 tty_unregister_driver(brd->SerialDriver);
1740 kfree(brd->SerialDriver->ttys);
1741 brd->SerialDriver->ttys = NULL;
1742 put_tty_driver(brd->SerialDriver);
1743 kfree(brd->SerialPorts);
1744 brd->dgap_Major_Serial_Registered = FALSE;
1747 if (brd->dgap_Major_TransparentPrint_Registered) {
1748 dgap_BoardsByMajor[brd->PrintDriver->major] = NULL;
1749 brd->dgap_TransparentPrint_Major = 0;
1750 for (i = 0; i < brd->nasync; i++) {
1751 tty_port_destroy(&brd->PrinterPorts[i]);
1752 dgap_remove_tty_sysfs(brd->channels[i]->ch_pun.un_sysfs);
1753 tty_unregister_device(brd->PrintDriver, i);
1755 tty_unregister_driver(brd->PrintDriver);
1756 kfree(brd->PrintDriver->ttys);
1757 brd->PrintDriver->ttys = NULL;
1758 put_tty_driver(brd->PrintDriver);
1759 kfree(brd->PrinterPorts);
1760 brd->dgap_Major_TransparentPrint_Registered = FALSE;
1765 #define TMPBUFLEN (1024)
1768 * dgap_sniff - Dump data out to the "sniff" buffer if the
1769 * proc sniff file is opened...
1771 static void dgap_sniff_nowait_nolock(struct channel_t *ch, uchar *text, uchar *buf, int len)
1779 char tmpbuf[TMPBUFLEN];
1783 /* Leave if sniff not open */
1784 if (!(ch->ch_sniff_flags & SNIFF_OPEN))
1787 do_gettimeofday(&tv);
1789 /* Create our header for data dump */
1790 p += sprintf(p, "<%ld %ld><%s><", tv.tv_sec, tv.tv_usec, text);
1791 tmpbuflen = p - tmpbuf;
1796 for (i = 0; i < len && tmpbuflen < (TMPBUFLEN - 4); i++) {
1797 p += sprintf(p, "%02x ", *buf);
1799 tmpbuflen = p - tmpbuf;
1802 if (tmpbuflen < (TMPBUFLEN - 4)) {
1804 p += sprintf(p - 1, "%s\n", ">");
1806 p += sprintf(p, "%s\n", ">");
1812 nbuf = strlen(tmpbuf);
1816 * Loop while data remains.
1818 while (nbuf > 0 && ch->ch_sniff_buf) {
1820 * Determine the amount of available space left in the
1821 * buffer. If there's none, wait until some appears.
1823 n = (ch->ch_sniff_out - ch->ch_sniff_in - 1) & SNIFF_MASK;
1826 * If there is no space left to write to in our sniff buffer,
1827 * we have no choice but to drop the data.
1828 * We *cannot* sleep here waiting for space, because this
1829 * function was probably called by the interrupt/timer routines!
1836 * Copy as much data as will fit.
1842 r = SNIFF_MAX - ch->ch_sniff_in;
1845 memcpy(ch->ch_sniff_buf + ch->ch_sniff_in, p, r);
1848 ch->ch_sniff_in = 0;
1853 memcpy(ch->ch_sniff_buf + ch->ch_sniff_in, p, n);
1855 ch->ch_sniff_in += n;
1860 * Wakeup any thread waiting for data
1862 if (ch->ch_sniff_flags & SNIFF_WAIT_DATA) {
1863 ch->ch_sniff_flags &= ~SNIFF_WAIT_DATA;
1864 wake_up_interruptible(&ch->ch_sniff_wait);
1869 * If the user sent us too much data to push into our tmpbuf,
1870 * we need to keep looping around on all the data.
1872 if (too_much_data) {
1877 } while (too_much_data);
1881 /*=======================================================================
1883 * dgap_input - Process received data.
1885 * ch - Pointer to channel structure.
1887 *=======================================================================*/
1889 static void dgap_input(struct channel_t *ch)
1893 struct tty_struct *tp;
1894 struct tty_ldisc *ld;
1908 if (!ch || ch->magic != DGAP_CHANNEL_MAGIC)
1911 tp = ch->ch_tun.un_tty;
1919 if(!bd || bd->magic != DGAP_BOARD_MAGIC)
1922 DPR_READ(("dgap_input start\n"));
1924 DGAP_LOCK(bd->bd_lock, lock_flags);
1925 DGAP_LOCK(ch->ch_lock, lock_flags2);
1928 * Figure the number of characters in the buffer.
1929 * Exit immediately if none.
1932 rmask = ch->ch_rsize - 1;
1934 head = readw(&(bs->rx_head));
1936 tail = readw(&(bs->rx_tail));
1939 data_len = (head - tail) & rmask;
1941 if (data_len == 0) {
1942 writeb(1, &(bs->idata));
1943 DGAP_UNLOCK(ch->ch_lock, lock_flags2);
1944 DGAP_UNLOCK(bd->bd_lock, lock_flags);
1945 DPR_READ(("No data on port %d\n", ch->ch_portnum));
1950 * If the device is not open, or CREAD is off, flush
1951 * input data and return immediately.
1953 if ((bd->state != BOARD_READY) || !tp || (tp->magic != TTY_MAGIC) ||
1954 !(ch->ch_tun.un_flags & UN_ISOPEN) || !(tp->termios.c_cflag & CREAD) ||
1955 (ch->ch_tun.un_flags & UN_CLOSING)) {
1957 DPR_READ(("input. dropping %d bytes on port %d...\n", data_len, ch->ch_portnum));
1958 DPR_READ(("input. tp: %p tp->magic: %x MAGIC:%x ch flags: %x\n",
1959 tp, tp ? tp->magic : 0, TTY_MAGIC, ch->ch_tun.un_flags));
1960 writew(head, &(bs->rx_tail));
1961 writeb(1, &(bs->idata));
1962 DGAP_UNLOCK(ch->ch_lock, lock_flags2);
1963 DGAP_UNLOCK(bd->bd_lock, lock_flags);
1968 * If we are throttled, simply don't read any data.
1970 if (ch->ch_flags & CH_RXBLOCK) {
1971 writeb(1, &(bs->idata));
1972 DGAP_UNLOCK(ch->ch_lock, lock_flags2);
1973 DGAP_UNLOCK(bd->bd_lock, lock_flags);
1974 DPR_READ(("Port %d throttled, not reading any data. head: %x tail: %x\n",
1975 ch->ch_portnum, head, tail));
1982 tmpchar = readb(&(bs->orun));
1984 ch->ch_err_overrun++;
1985 writeb(0, &(bs->orun));
1988 DPR_READ(("dgap_input start 2\n"));
1990 /* Decide how much data we can send into the tty layer */
1991 flip_len = TTY_FLIPBUF_SIZE;
1993 /* Chop down the length, if needed */
1994 len = min(data_len, flip_len);
1995 len = min(len, (N_TTY_BUF_SIZE - 1));
1997 ld = tty_ldisc_ref(tp);
1999 #ifdef TTY_DONT_FLIP
2001 * If the DONT_FLIP flag is on, don't flush our buffer, and act
2002 * like the ld doesn't have any space to put the data right now.
2004 if (test_bit(TTY_DONT_FLIP, &tp->flags))
2009 * If we were unable to get a reference to the ld,
2010 * don't flush our buffer, and act like the ld doesn't
2011 * have any space to put the data right now.
2017 * If ld doesn't have a pointer to a receive_buf function,
2018 * flush the data, then act like the ld doesn't have any
2019 * space to put the data right now.
2021 if (!ld->ops->receive_buf) {
2022 writew(head, &(bs->rx_tail));
2028 writeb(1, &(bs->idata));
2029 DGAP_UNLOCK(ch->ch_lock, lock_flags2);
2030 DGAP_UNLOCK(bd->bd_lock, lock_flags);
2031 DPR_READ(("dgap_input 1 - finish\n"));
2033 tty_ldisc_deref(ld);
2037 buf = ch->ch_bd->flipbuf;
2041 * n now contains the most amount of data we can copy,
2042 * bounded either by our buffer size or the amount
2043 * of data the card actually has pending...
2047 s = ((head >= tail) ? head : ch->ch_rsize) - tail;
2053 memcpy_fromio(buf, (char *) ch->ch_raddr + tail, s);
2054 dgap_sniff_nowait_nolock(ch, "USER READ", buf, s);
2060 /* Flip queue if needed */
2064 writew(tail, &(bs->rx_tail));
2065 writeb(1, &(bs->idata));
2066 ch->ch_rxcount += len;
2069 * If we are completely raw, we don't need to go through a lot
2070 * of the tty layers that exist.
2071 * In this case, we take the shortest and fastest route we
2072 * can to relay the data to the user.
2074 * On the other hand, if we are not raw, we need to go through
2075 * the tty layer, which has its API more well defined.
2077 if (I_PARMRK(tp) || I_BRKINT(tp) || I_INPCK(tp)) {
2078 dgap_parity_scan(ch, ch->ch_bd->flipbuf, ch->ch_bd->flipflagbuf, &len);
2080 len = tty_buffer_request_room(tp->port, len);
2081 tty_insert_flip_string_flags(tp->port, ch->ch_bd->flipbuf,
2082 ch->ch_bd->flipflagbuf, len);
2085 len = tty_buffer_request_room(tp->port, len);
2086 tty_insert_flip_string(tp->port, ch->ch_bd->flipbuf, len);
2089 DGAP_UNLOCK(ch->ch_lock, lock_flags2);
2090 DGAP_UNLOCK(bd->bd_lock, lock_flags);
2092 /* Tell the tty layer its okay to "eat" the data now */
2093 tty_flip_buffer_push(tp->port);
2096 tty_ldisc_deref(ld);
2098 DPR_READ(("dgap_input - finish\n"));
2102 /************************************************************************
2103 * Determines when CARRIER changes state and takes appropriate
2105 ************************************************************************/
2106 static void dgap_carrier(struct channel_t *ch)
2110 int virt_carrier = 0;
2111 int phys_carrier = 0;
2113 DPR_CARR(("dgap_carrier called...\n"));
2115 if (!ch || ch->magic != DGAP_CHANNEL_MAGIC)
2120 if (!bd || bd->magic != DGAP_BOARD_MAGIC)
2123 /* Make sure altpin is always set correctly */
2124 if (ch->ch_digi.digi_flags & DIGI_ALTPIN) {
2129 ch->ch_dsr = DM_DSR;
2133 if (ch->ch_mistat & D_CD(ch)) {
2134 DPR_CARR(("mistat: %x D_CD: %x\n", ch->ch_mistat, D_CD(ch)));
2138 if (ch->ch_digi.digi_flags & DIGI_FORCEDCD) {
2142 if (ch->ch_c_cflag & CLOCAL) {
2147 DPR_CARR(("DCD: physical: %d virt: %d\n", phys_carrier, virt_carrier));
2150 * Test for a VIRTUAL carrier transition to HIGH.
2152 if (((ch->ch_flags & CH_FCAR) == 0) && (virt_carrier == 1)) {
2155 * When carrier rises, wake any threads waiting
2156 * for carrier in the open routine.
2159 DPR_CARR(("carrier: virt DCD rose\n"));
2161 if (waitqueue_active(&(ch->ch_flags_wait)))
2162 wake_up_interruptible(&ch->ch_flags_wait);
2166 * Test for a PHYSICAL carrier transition to HIGH.
2168 if (((ch->ch_flags & CH_CD) == 0) && (phys_carrier == 1)) {
2171 * When carrier rises, wake any threads waiting
2172 * for carrier in the open routine.
2175 DPR_CARR(("carrier: physical DCD rose\n"));
2177 if (waitqueue_active(&(ch->ch_flags_wait)))
2178 wake_up_interruptible(&ch->ch_flags_wait);
2182 * Test for a PHYSICAL transition to low, so long as we aren't
2183 * currently ignoring physical transitions (which is what "virtual
2184 * carrier" indicates).
2186 * The transition of the virtual carrier to low really doesn't
2187 * matter... it really only means "ignore carrier state", not
2188 * "make pretend that carrier is there".
2190 if ((virt_carrier == 0) && ((ch->ch_flags & CH_CD) != 0) &&
2191 (phys_carrier == 0))
2195 * When carrier drops:
2197 * Drop carrier on all open units.
2199 * Flush queues, waking up any task waiting in the
2202 * Send a hangup to the control terminal.
2204 * Enable all select calls.
2206 if (waitqueue_active(&(ch->ch_flags_wait)))
2207 wake_up_interruptible(&ch->ch_flags_wait);
2209 if (ch->ch_tun.un_open_count > 0) {
2210 DPR_CARR(("Sending tty hangup\n"));
2211 tty_hangup(ch->ch_tun.un_tty);
2214 if (ch->ch_pun.un_open_count > 0) {
2215 DPR_CARR(("Sending pr hangup\n"));
2216 tty_hangup(ch->ch_pun.un_tty);
2221 * Make sure that our cached values reflect the current reality.
2223 if (virt_carrier == 1)
2224 ch->ch_flags |= CH_FCAR;
2226 ch->ch_flags &= ~CH_FCAR;
2228 if (phys_carrier == 1)
2229 ch->ch_flags |= CH_CD;
2231 ch->ch_flags &= ~CH_CD;
2235 /************************************************************************
2237 * TTY Entry points and helper functions
2239 ************************************************************************/
2245 static int dgap_tty_open(struct tty_struct *tty, struct file *file)
2247 struct board_t *brd;
2248 struct channel_t *ch;
2260 major = MAJOR(tty_devnum(tty));
2261 minor = MINOR(tty_devnum(tty));
2267 /* Get board pointer from our array of majors we have allocated */
2268 brd = dgap_BoardsByMajor[major];
2274 * If board is not yet up to a state of READY, go to
2275 * sleep waiting for it to happen or they cancel the open.
2277 rc = wait_event_interruptible(brd->state_wait,
2278 (brd->state & BOARD_READY));
2284 DGAP_LOCK(brd->bd_lock, lock_flags);
2286 /* The wait above should guarantee this cannot happen */
2287 if (brd->state != BOARD_READY) {
2288 DGAP_UNLOCK(brd->bd_lock, lock_flags);
2292 /* If opened device is greater than our number of ports, bail. */
2293 if (MINOR(tty_devnum(tty)) > brd->nasync) {
2294 DGAP_UNLOCK(brd->bd_lock, lock_flags);
2298 ch = brd->channels[minor];
2300 DGAP_UNLOCK(brd->bd_lock, lock_flags);
2304 /* Grab channel lock */
2305 DGAP_LOCK(ch->ch_lock, lock_flags2);
2307 /* Figure out our type */
2308 if (major == brd->dgap_Serial_Major) {
2309 un = &brd->channels[minor]->ch_tun;
2310 un->un_type = DGAP_SERIAL;
2312 else if (major == brd->dgap_TransparentPrint_Major) {
2313 un = &brd->channels[minor]->ch_pun;
2314 un->un_type = DGAP_PRINT;
2317 DGAP_UNLOCK(ch->ch_lock, lock_flags2);
2318 DGAP_UNLOCK(brd->bd_lock, lock_flags);
2319 DPR_OPEN(("%d Unknown TYPE!\n", __LINE__));
2323 /* Store our unit into driver_data, so we always have it available. */
2324 tty->driver_data = un;
2326 DPR_OPEN(("Open called. MAJOR: %d MINOR:%d unit: %p NAME: %s\n",
2327 MAJOR(tty_devnum(tty)), MINOR(tty_devnum(tty)), un, brd->name));
2330 * Error if channel info pointer is NULL.
2334 DGAP_UNLOCK(ch->ch_lock, lock_flags2);
2335 DGAP_UNLOCK(brd->bd_lock, lock_flags);
2336 DPR_OPEN(("%d BS is 0!\n", __LINE__));
2340 DPR_OPEN(("%d: tflag=%x pflag=%x\n", __LINE__, ch->ch_tun.un_flags, ch->ch_pun.un_flags));
2345 if (!(un->un_flags & UN_ISOPEN)) {
2346 /* Store important variables. */
2349 /* Maybe do something here to the TTY struct as well? */
2353 * Initialize if neither terminal or printer is open.
2355 if (!((ch->ch_tun.un_flags | ch->ch_pun.un_flags) & UN_ISOPEN)) {
2357 DPR_OPEN(("dgap_open: initializing channel in open...\n"));
2363 * Flush input queue.
2365 head = readw(&(bs->rx_head));
2366 writew(head, &(bs->rx_tail));
2369 ch->pscan_state = 0;
2370 ch->pscan_savechar = 0;
2372 ch->ch_c_cflag = tty->termios.c_cflag;
2373 ch->ch_c_iflag = tty->termios.c_iflag;
2374 ch->ch_c_oflag = tty->termios.c_oflag;
2375 ch->ch_c_lflag = tty->termios.c_lflag;
2376 ch->ch_startc = tty->termios.c_cc[VSTART];
2377 ch->ch_stopc = tty->termios.c_cc[VSTOP];
2379 /* TODO: flush our TTY struct here? */
2384 * Run param in case we changed anything
2389 * follow protocol for opening port
2392 DGAP_UNLOCK(ch->ch_lock, lock_flags2);
2393 DGAP_UNLOCK(brd->bd_lock, lock_flags);
2395 rc = dgap_block_til_ready(tty, file, ch);
2402 DPR_OPEN(("dgap_tty_open returning after dgap_block_til_ready "
2406 /* No going back now, increment our unit and channel counters */
2407 DGAP_LOCK(ch->ch_lock, lock_flags);
2408 ch->ch_open_count++;
2409 un->un_open_count++;
2410 un->un_flags |= (UN_ISOPEN);
2411 DGAP_UNLOCK(ch->ch_lock, lock_flags);
2413 DPR_OPEN(("dgap_tty_open finished\n"));
2419 * dgap_block_til_ready()
2421 * Wait for DCD, if needed.
2423 static int dgap_block_til_ready(struct tty_struct *tty, struct file *file, struct channel_t *ch)
2426 struct un_t *un = NULL;
2429 int sleep_on_un_flags = 0;
2431 if (!tty || tty->magic != TTY_MAGIC || !file || !ch || ch->magic != DGAP_CHANNEL_MAGIC) {
2435 un = tty->driver_data;
2436 if (!un || un->magic != DGAP_UNIT_MAGIC) {
2440 DPR_OPEN(("dgap_block_til_ready - before block.\n"));
2442 DGAP_LOCK(ch->ch_lock, lock_flags);
2449 sleep_on_un_flags = 0;
2452 * If board has failed somehow during our sleep, bail with error.
2454 if (ch->ch_bd->state == BOARD_FAILED) {
2459 /* If tty was hung up, break out of loop and set error. */
2460 if (tty_hung_up_p(file)) {
2466 * If either unit is in the middle of the fragile part of close,
2467 * we just cannot touch the channel safely.
2468 * Go back to sleep, knowing that when the channel can be
2469 * touched safely, the close routine will signal the
2470 * ch_wait_flags to wake us back up.
2472 if (!((ch->ch_tun.un_flags | ch->ch_pun.un_flags) & UN_CLOSING)) {
2475 * Our conditions to leave cleanly and happily:
2476 * 1) NONBLOCKING on the tty is set.
2478 * 3) DCD (fake or real) is active.
2481 if (file->f_flags & O_NONBLOCK) {
2485 if (tty->flags & (1 << TTY_IO_ERROR)) {
2489 if (ch->ch_flags & CH_CD) {
2490 DPR_OPEN(("%d: ch_flags: %x\n", __LINE__, ch->ch_flags));
2494 if (ch->ch_flags & CH_FCAR) {
2495 DPR_OPEN(("%d: ch_flags: %x\n", __LINE__, ch->ch_flags));
2500 sleep_on_un_flags = 1;
2504 * If there is a signal pending, the user probably
2505 * interrupted (ctrl-c) us.
2506 * Leave loop with error set.
2508 if (signal_pending(current)) {
2509 DPR_OPEN(("%d: signal pending...\n", __LINE__));
2510 retval = -ERESTARTSYS;
2514 DPR_OPEN(("dgap_block_til_ready - blocking.\n"));
2517 * Store the flags before we let go of channel lock
2519 if (sleep_on_un_flags)
2520 old_flags = ch->ch_tun.un_flags | ch->ch_pun.un_flags;
2522 old_flags = ch->ch_flags;
2525 * Let go of channel lock before calling schedule.
2526 * Our poller will get any FEP events and wake us up when DCD
2527 * eventually goes active.
2530 DGAP_UNLOCK(ch->ch_lock, lock_flags);
2532 DPR_OPEN(("Going to sleep on %s flags...\n",
2533 (sleep_on_un_flags ? "un" : "ch")));
2536 * Wait for something in the flags to change from the current value.
2538 if (sleep_on_un_flags) {
2539 retval = wait_event_interruptible(un->un_flags_wait,
2540 (old_flags != (ch->ch_tun.un_flags | ch->ch_pun.un_flags)));
2543 retval = wait_event_interruptible(ch->ch_flags_wait,
2544 (old_flags != ch->ch_flags));
2547 DPR_OPEN(("After sleep... retval: %x\n", retval));
2550 * We got woken up for some reason.
2551 * Before looping around, grab our channel lock.
2553 DGAP_LOCK(ch->ch_lock, lock_flags);
2558 DGAP_UNLOCK(ch->ch_lock, lock_flags);
2560 DPR_OPEN(("dgap_block_til_ready - after blocking.\n"));
2563 DPR_OPEN(("dgap_block_til_ready - done. error. retval: %x\n", retval));
2567 DPR_OPEN(("dgap_block_til_ready - done no error. jiffies: %lu\n", jiffies));
2576 * Hangup the port. Like a close, but don't wait for output to drain.
2578 static void dgap_tty_hangup(struct tty_struct *tty)
2581 struct channel_t *ch;
2584 if (!tty || tty->magic != TTY_MAGIC)
2587 un = tty->driver_data;
2588 if (!un || un->magic != DGAP_UNIT_MAGIC)
2592 if (!ch || ch->magic != DGAP_CHANNEL_MAGIC)
2596 if (!bd || bd->magic != DGAP_BOARD_MAGIC)
2599 DPR_CLOSE(("dgap_hangup called. ch->ch_open_count: %d un->un_open_count: %d\n",
2600 ch->ch_open_count, un->un_open_count));
2602 /* flush the transmit queues */
2603 dgap_tty_flush_buffer(tty);
2605 DPR_CLOSE(("dgap_hangup finished. ch->ch_open_count: %d un->un_open_count: %d\n",
2606 ch->ch_open_count, un->un_open_count));
2615 static void dgap_tty_close(struct tty_struct *tty, struct file *file)
2617 struct ktermios *ts;
2619 struct channel_t *ch;
2624 if (!tty || tty->magic != TTY_MAGIC)
2627 un = tty->driver_data;
2628 if (!un || un->magic != DGAP_UNIT_MAGIC)
2632 if (!ch || ch->magic != DGAP_CHANNEL_MAGIC)
2636 if (!bd || bd->magic != DGAP_BOARD_MAGIC)
2641 DPR_CLOSE(("Close called\n"));
2643 DGAP_LOCK(ch->ch_lock, lock_flags);
2646 * Determine if this is the last close or not - and if we agree about
2647 * which type of close it is with the Line Discipline
2649 if ((tty->count == 1) && (un->un_open_count != 1)) {
2651 * Uh, oh. tty->count is 1, which means that the tty
2652 * structure will be freed. un_open_count should always
2653 * be one in these conditions. If it's greater than
2654 * one, we've got real problems, since it means the
2655 * serial port won't be shutdown.
2657 APR(("tty->count is 1, un open count is %d\n", un->un_open_count));
2658 un->un_open_count = 1;
2661 if (--un->un_open_count < 0) {
2662 APR(("bad serial port open count of %d\n", un->un_open_count));
2663 un->un_open_count = 0;
2666 ch->ch_open_count--;
2668 if (ch->ch_open_count && un->un_open_count) {
2669 DPR_CLOSE(("dgap_tty_close: not last close ch: %d un:%d\n",
2670 ch->ch_open_count, un->un_open_count));
2672 DGAP_UNLOCK(ch->ch_lock, lock_flags);
2676 /* OK, its the last close on the unit */
2677 DPR_CLOSE(("dgap_tty_close - last close on unit procedures\n"));
2679 un->un_flags |= UN_CLOSING;
2684 * Only officially close channel if count is 0 and
2685 * DIGI_PRINTER bit is not set.
2687 if ((ch->ch_open_count == 0) && !(ch->ch_digi.digi_flags & DIGI_PRINTER)) {
2689 ch->ch_flags &= ~(CH_RXBLOCK);
2691 DGAP_UNLOCK(ch->ch_lock, lock_flags);
2693 /* wait for output to drain */
2694 /* This will also return if we take an interrupt */
2696 DPR_CLOSE(("Calling wait_for_drain\n"));
2697 rc = dgap_wait_for_drain(tty);
2698 DPR_CLOSE(("After calling wait_for_drain\n"));
2701 DPR_BASIC(("dgap_tty_close - bad return: %d ", rc));
2704 dgap_tty_flush_buffer(tty);
2705 tty_ldisc_flush(tty);
2707 DGAP_LOCK(ch->ch_lock, lock_flags);
2712 * If we have HUPCL set, lower DTR and RTS
2714 if (ch->ch_c_cflag & HUPCL ) {
2715 DPR_CLOSE(("Close. HUPCL set, dropping DTR/RTS\n"));
2716 ch->ch_mostat &= ~(D_RTS(ch)|D_DTR(ch));
2717 dgap_cmdb( ch, SMODEM, 0, D_DTR(ch)|D_RTS(ch), 0 );
2720 * Go to sleep to ensure RTS/DTR
2721 * have been dropped for modems to see it.
2723 if (ch->ch_close_delay) {
2724 DPR_CLOSE(("Close. Sleeping for RTS/DTR drop\n"));
2726 DGAP_UNLOCK(ch->ch_lock, lock_flags);
2727 dgap_ms_sleep(ch->ch_close_delay);
2728 DGAP_LOCK(ch->ch_lock, lock_flags);
2730 DPR_CLOSE(("Close. After sleeping for RTS/DTR drop\n"));
2734 ch->pscan_state = 0;
2735 ch->pscan_savechar = 0;
2736 ch->ch_baud_info = 0;
2741 * turn off print device when closing print device.
2743 if ((un->un_type == DGAP_PRINT) && (ch->ch_flags & CH_PRON) ) {
2744 dgap_wmove(ch, ch->ch_digi.digi_offstr,
2745 (int) ch->ch_digi.digi_offlen);
2746 ch->ch_flags &= ~CH_PRON;
2750 un->un_flags &= ~(UN_ISOPEN | UN_CLOSING);
2751 tty->driver_data = NULL;
2753 DPR_CLOSE(("Close. Doing wakeups\n"));
2754 wake_up_interruptible(&ch->ch_flags_wait);
2755 wake_up_interruptible(&un->un_flags_wait);
2757 DGAP_UNLOCK(ch->ch_lock, lock_flags);
2759 DPR_BASIC(("dgap_tty_close - complete\n"));
2764 * dgap_tty_chars_in_buffer()
2766 * Return number of characters that have not been transmitted yet.
2768 * This routine is used by the line discipline to determine if there
2769 * is data waiting to be transmitted/drained/flushed or not.
2771 static int dgap_tty_chars_in_buffer(struct tty_struct *tty)
2773 struct board_t *bd = NULL;
2774 struct channel_t *ch = NULL;
2775 struct un_t *un = NULL;
2776 struct bs_t *bs = NULL;
2779 u16 thead, ttail, tmask, chead, ctail;
2780 ulong lock_flags = 0;
2781 ulong lock_flags2 = 0;
2786 un = tty->driver_data;
2787 if (!un || un->magic != DGAP_UNIT_MAGIC)
2791 if (!ch || ch->magic != DGAP_CHANNEL_MAGIC)
2795 if (!bd || bd->magic != DGAP_BOARD_MAGIC)
2802 DGAP_LOCK(bd->bd_lock, lock_flags);
2803 DGAP_LOCK(ch->ch_lock, lock_flags2);
2805 tmask = (ch->ch_tsize - 1);
2807 /* Get Transmit queue pointers */
2808 thead = readw(&(bs->tx_head)) & tmask;
2809 ttail = readw(&(bs->tx_tail)) & tmask;
2811 /* Get tbusy flag */
2812 tbusy = readb(&(bs->tbusy));
2814 /* Get Command queue pointers */
2815 chead = readw(&(ch->ch_cm->cm_head));
2816 ctail = readw(&(ch->ch_cm->cm_tail));
2818 DGAP_UNLOCK(ch->ch_lock, lock_flags2);
2819 DGAP_UNLOCK(bd->bd_lock, lock_flags);
2822 * The only way we know for sure if there is no pending
2823 * data left to be transferred, is if:
2824 * 1) Transmit head and tail are equal (empty).
2825 * 2) Command queue head and tail are equal (empty).
2826 * 3) The "TBUSY" flag is 0. (Transmitter not busy).
2829 if ((ttail == thead) && (tbusy == 0) && (chead == ctail)) {
2834 chars = thead - ttail;
2836 chars = thead - ttail + ch->ch_tsize;
2838 * Fudge factor here.
2839 * If chars is zero, we know that the command queue had
2840 * something in it or tbusy was set. Because we cannot
2841 * be sure if there is still some data to be transmitted,
2842 * lets lie, and tell ld we have 1 byte left.
2846 * If TBUSY is still set, and our tx buffers are empty,
2847 * force the firmware to send me another wakeup after
2848 * TBUSY has been cleared.
2851 DGAP_LOCK(ch->ch_lock, lock_flags);
2852 un->un_flags |= UN_EMPTY;
2853 writeb(1, &(bs->iempty));
2854 DGAP_UNLOCK(ch->ch_lock, lock_flags);
2860 DPR_WRITE(("dgap_tty_chars_in_buffer. Port: %x - %d (head: %d tail: %d tsize: %d)\n",
2861 ch->ch_portnum, chars, thead, ttail, ch->ch_tsize));
2866 static int dgap_wait_for_drain(struct tty_struct *tty)
2868 struct channel_t *ch;
2873 ulong lock_flags = 0;
2875 if (!tty || tty->magic != TTY_MAGIC)
2878 un = tty->driver_data;
2879 if (!un || un->magic != DGAP_UNIT_MAGIC)
2883 if (!ch || ch->magic != DGAP_CHANNEL_MAGIC)
2892 DPR_DRAIN(("dgap_wait_for_drain start\n"));
2894 /* Loop until data is drained */
2895 while (count != 0) {
2897 count = dgap_tty_chars_in_buffer(tty);
2902 /* Set flag waiting for drain */
2903 DGAP_LOCK(ch->ch_lock, lock_flags);
2904 un->un_flags |= UN_EMPTY;
2905 writeb(1, &(bs->iempty));
2906 DGAP_UNLOCK(ch->ch_lock, lock_flags);
2908 /* Go to sleep till we get woken up */
2909 ret = wait_event_interruptible(un->un_flags_wait, ((un->un_flags & UN_EMPTY) == 0));
2910 /* If ret is non-zero, user ctrl-c'ed us */
2916 DGAP_LOCK(ch->ch_lock, lock_flags);
2917 un->un_flags &= ~(UN_EMPTY);
2918 DGAP_UNLOCK(ch->ch_lock, lock_flags);
2920 DPR_DRAIN(("dgap_wait_for_drain finish\n"));
2928 * Reduces bytes_available to the max number of characters
2929 * that can be sent currently given the maxcps value, and
2930 * returns the new bytes_available. This only affects printer
2933 static int dgap_maxcps_room(struct tty_struct *tty, int bytes_available)
2935 struct channel_t *ch = NULL;
2936 struct un_t *un = NULL;
2939 return (bytes_available);
2941 un = tty->driver_data;
2942 if (!un || un->magic != DGAP_UNIT_MAGIC)
2943 return (bytes_available);
2946 if (!ch || ch->magic != DGAP_CHANNEL_MAGIC)
2947 return (bytes_available);
2950 * If its not the Transparent print device, return
2951 * the full data amount.
2953 if (un->un_type != DGAP_PRINT)
2954 return (bytes_available);
2956 if (ch->ch_digi.digi_maxcps > 0 && ch->ch_digi.digi_bufsize > 0 ) {
2958 unsigned long current_time = jiffies;
2959 unsigned long buffer_time = current_time +
2960 (HZ * ch->ch_digi.digi_bufsize) / ch->ch_digi.digi_maxcps;
2962 if (ch->ch_cpstime < current_time) {
2963 /* buffer is empty */
2964 ch->ch_cpstime = current_time; /* reset ch_cpstime */
2965 cps_limit = ch->ch_digi.digi_bufsize;
2967 else if (ch->ch_cpstime < buffer_time) {
2968 /* still room in the buffer */
2969 cps_limit = ((buffer_time - ch->ch_cpstime) * ch->ch_digi.digi_maxcps) / HZ;
2972 /* no room in the buffer */
2976 bytes_available = min(cps_limit, bytes_available);
2979 return (bytes_available);
2983 static inline void dgap_set_firmware_event(struct un_t *un, unsigned int event)
2985 struct channel_t *ch = NULL;
2986 struct bs_t *bs = NULL;
2988 if (!un || un->magic != DGAP_UNIT_MAGIC)
2991 if (!ch || ch->magic != DGAP_CHANNEL_MAGIC)
2997 if ((event & UN_LOW) != 0) {
2998 if ((un->un_flags & UN_LOW) == 0) {
2999 un->un_flags |= UN_LOW;
3000 writeb(1, &(bs->ilow));
3003 if ((event & UN_LOW) != 0) {
3004 if ((un->un_flags & UN_EMPTY) == 0) {
3005 un->un_flags |= UN_EMPTY;
3006 writeb(1, &(bs->iempty));
3013 * dgap_tty_write_room()
3015 * Return space available in Tx buffer
3017 static int dgap_tty_write_room(struct tty_struct *tty)
3019 struct channel_t *ch = NULL;
3020 struct un_t *un = NULL;
3021 struct bs_t *bs = NULL;
3022 u16 head, tail, tmask;
3024 ulong lock_flags = 0;
3026 if (tty == NULL || dgap_TmpWriteBuf == NULL)
3029 un = tty->driver_data;
3030 if (!un || un->magic != DGAP_UNIT_MAGIC)
3034 if (!ch || ch->magic != DGAP_CHANNEL_MAGIC)
3041 DGAP_LOCK(ch->ch_lock, lock_flags);
3043 tmask = ch->ch_tsize - 1;
3044 head = readw(&(bs->tx_head)) & tmask;
3045 tail = readw(&(bs->tx_tail)) & tmask;
3047 if ((ret = tail - head - 1) < 0)
3048 ret += ch->ch_tsize;
3050 /* Limit printer to maxcps */
3051 ret = dgap_maxcps_room(tty, ret);
3054 * If we are printer device, leave space for
3055 * possibly both the on and off strings.
3057 if (un->un_type == DGAP_PRINT) {
3058 if (!(ch->ch_flags & CH_PRON))
3059 ret -= ch->ch_digi.digi_onlen;
3060 ret -= ch->ch_digi.digi_offlen;
3063 if (ch->ch_flags & CH_PRON)
3064 ret -= ch->ch_digi.digi_offlen;
3071 * Schedule FEP to wake us up if needed.
3073 * TODO: This might be overkill...
3074 * Do we really need to schedule callbacks from the FEP
3075 * in every case? Can we get smarter based on ret?
3077 dgap_set_firmware_event(un, UN_LOW | UN_EMPTY);
3078 DGAP_UNLOCK(ch->ch_lock, lock_flags);
3080 DPR_WRITE(("dgap_tty_write_room - %d tail: %d head: %d\n", ret, tail, head));
3087 * dgap_tty_put_char()
3089 * Put a character into ch->ch_buf
3091 * - used by the line discipline for OPOST processing
3093 static int dgap_tty_put_char(struct tty_struct *tty, unsigned char c)
3096 * Simply call tty_write.
3098 DPR_WRITE(("dgap_tty_put_char called\n"));
3099 dgap_tty_write(tty, &c, 1);
3107 * Take data from the user or kernel and send it out to the FEP.
3108 * In here exists all the Transparent Print magic as well.
3110 static int dgap_tty_write(struct tty_struct *tty, const unsigned char *buf, int count)
3112 struct channel_t *ch = NULL;
3113 struct un_t *un = NULL;
3114 struct bs_t *bs = NULL;
3116 u16 head, tail, tmask, remain;
3117 int bufcount = 0, n = 0;
3122 if (tty == NULL || dgap_TmpWriteBuf == NULL)
3125 un = tty->driver_data;
3126 if (!un || un->magic != DGAP_UNIT_MAGIC)
3130 if (!ch || ch->magic != DGAP_CHANNEL_MAGIC)
3140 DPR_WRITE(("dgap_tty_write: Port: %x tty=%p user=%d len=%d\n",
3141 ch->ch_portnum, tty, from_user, count));
3144 * Store original amount of characters passed in.
3145 * This helps to figure out if we should ask the FEP
3146 * to send us an event when it has more space available.
3150 DGAP_LOCK(ch->ch_lock, lock_flags);
3152 /* Get our space available for the channel from the board */
3153 tmask = ch->ch_tsize - 1;
3154 head = readw(&(bs->tx_head)) & tmask;
3155 tail = readw(&(bs->tx_tail)) & tmask;
3157 if ((bufcount = tail - head - 1) < 0)
3158 bufcount += ch->ch_tsize;
3160 DPR_WRITE(("%d: bufcount: %x count: %x tail: %x head: %x tmask: %x\n",
3161 __LINE__, bufcount, count, tail, head, tmask));
3164 * Limit printer output to maxcps overall, with bursts allowed
3165 * up to bufsize characters.
3167 bufcount = dgap_maxcps_room(tty, bufcount);
3170 * Take minimum of what the user wants to send, and the
3171 * space available in the FEP buffer.
3173 count = min(count, bufcount);
3176 * Bail if no space left.
3179 dgap_set_firmware_event(un, UN_LOW | UN_EMPTY);
3180 DGAP_UNLOCK(ch->ch_lock, lock_flags);
3185 * Output the printer ON string, if we are in terminal mode, but
3186 * need to be in printer mode.
3188 if ((un->un_type == DGAP_PRINT) && !(ch->ch_flags & CH_PRON)) {
3189 dgap_wmove(ch, ch->ch_digi.digi_onstr,
3190 (int) ch->ch_digi.digi_onlen);
3191 head = readw(&(bs->tx_head)) & tmask;
3192 ch->ch_flags |= CH_PRON;
3196 * On the other hand, output the printer OFF string, if we are
3197 * currently in printer mode, but need to output to the terminal.
3199 if ((un->un_type != DGAP_PRINT) && (ch->ch_flags & CH_PRON)) {
3200 dgap_wmove(ch, ch->ch_digi.digi_offstr,
3201 (int) ch->ch_digi.digi_offlen);
3202 head = readw(&(bs->tx_head)) & tmask;
3203 ch->ch_flags &= ~CH_PRON;
3207 * If there is nothing left to copy, or I can't handle any more data, leave.
3210 dgap_set_firmware_event(un, UN_LOW | UN_EMPTY);
3211 DGAP_UNLOCK(ch->ch_lock, lock_flags);
3217 count = min(count, WRITEBUFLEN);
3219 DGAP_UNLOCK(ch->ch_lock, lock_flags);
3222 * If data is coming from user space, copy it into a temporary
3223 * buffer so we don't get swapped out while doing the copy to
3226 /* we're allowed to block if it's from_user */
3227 if (down_interruptible(&dgap_TmpWriteSem)) {
3231 if (copy_from_user(dgap_TmpWriteBuf, (const uchar __user *) buf, count)) {
3232 up(&dgap_TmpWriteSem);
3233 printk("Write: Copy from user failed!\n");
3237 DGAP_LOCK(ch->ch_lock, lock_flags);
3239 buf = dgap_TmpWriteBuf;
3245 * If the write wraps over the top of the circular buffer,
3246 * move the portion up to the wrap point, and reset the
3247 * pointers to the bottom.
3249 remain = ch->ch_tstart + ch->ch_tsize - head;
3253 vaddr = ch->ch_taddr + head;
3255 memcpy_toio(vaddr, (uchar *) buf, remain);
3256 dgap_sniff_nowait_nolock(ch, "USER WRITE", (uchar *) buf, remain);
3258 head = ch->ch_tstart;
3265 * Move rest of data.
3267 vaddr = ch->ch_taddr + head;
3270 memcpy_toio(vaddr, (uchar *) buf, remain);
3271 dgap_sniff_nowait_nolock(ch, "USER WRITE", (uchar *) buf, remain);
3278 ch->ch_txcount += count;
3280 writew(head, &(bs->tx_head));
3284 dgap_set_firmware_event(un, UN_LOW | UN_EMPTY);
3287 * If this is the print device, and the
3288 * printer is still on, we need to turn it
3289 * off before going idle. If the buffer is
3290 * non-empty, wait until it goes empty.
3291 * Otherwise turn it off right now.
3293 if ((un->un_type == DGAP_PRINT) && (ch->ch_flags & CH_PRON)) {
3294 tail = readw(&(bs->tx_tail)) & tmask;
3297 un->un_flags |= UN_EMPTY;
3298 writeb(1, &(bs->iempty));
3301 dgap_wmove(ch, ch->ch_digi.digi_offstr,
3302 (int) ch->ch_digi.digi_offlen);
3303 head = readw(&(bs->tx_head)) & tmask;
3304 ch->ch_flags &= ~CH_PRON;
3308 /* Update printer buffer empty time. */
3309 if ((un->un_type == DGAP_PRINT) && (ch->ch_digi.digi_maxcps > 0)
3310 && (ch->ch_digi.digi_bufsize > 0)) {
3311 ch->ch_cpstime += (HZ * count) / ch->ch_digi.digi_maxcps;
3315 DGAP_UNLOCK(ch->ch_lock, lock_flags);
3316 up(&dgap_TmpWriteSem);
3319 DGAP_UNLOCK(ch->ch_lock, lock_flags);
3322 DPR_WRITE(("Write finished - Write %d bytes of %d.\n", count, orig_count));
3330 * Return modem signals to ld.
3332 static int dgap_tty_tiocmget(struct tty_struct *tty)
3334 struct channel_t *ch;
3340 if (!tty || tty->magic != TTY_MAGIC)
3343 un = tty->driver_data;
3344 if (!un || un->magic != DGAP_UNIT_MAGIC)
3348 if (!ch || ch->magic != DGAP_CHANNEL_MAGIC)
3351 DPR_IOCTL(("dgap_tty_tiocmget start\n"));
3353 DGAP_LOCK(ch->ch_lock, lock_flags);
3355 mstat = readb(&(ch->ch_bs->m_stat));
3356 /* Append any outbound signals that might be pending... */
3357 mstat |= ch->ch_mostat;
3359 DGAP_UNLOCK(ch->ch_lock, lock_flags);
3363 if (mstat & D_DTR(ch))
3364 result |= TIOCM_DTR;
3365 if (mstat & D_RTS(ch))
3366 result |= TIOCM_RTS;
3367 if (mstat & D_CTS(ch))
3368 result |= TIOCM_CTS;
3369 if (mstat & D_DSR(ch))
3370 result |= TIOCM_DSR;
3371 if (mstat & D_RI(ch))
3373 if (mstat & D_CD(ch))
3376 DPR_IOCTL(("dgap_tty_tiocmget finish\n"));
3383 * dgap_tty_tiocmset()
3385 * Set modem signals, called by ld.
3388 static int dgap_tty_tiocmset(struct tty_struct *tty,
3389 unsigned int set, unsigned int clear)
3392 struct channel_t *ch;
3398 if (!tty || tty->magic != TTY_MAGIC)
3401 un = tty->driver_data;
3402 if (!un || un->magic != DGAP_UNIT_MAGIC)
3406 if (!ch || ch->magic != DGAP_CHANNEL_MAGIC)
3410 if (!bd || bd->magic != DGAP_BOARD_MAGIC)
3413 DPR_IOCTL(("dgap_tty_tiocmset start\n"));
3415 DGAP_LOCK(bd->bd_lock, lock_flags);
3416 DGAP_LOCK(ch->ch_lock, lock_flags2);
3418 if (set & TIOCM_RTS) {
3419 ch->ch_mforce |= D_RTS(ch);
3420 ch->ch_mval |= D_RTS(ch);
3423 if (set & TIOCM_DTR) {
3424 ch->ch_mforce |= D_DTR(ch);
3425 ch->ch_mval |= D_DTR(ch);
3428 if (clear & TIOCM_RTS) {
3429 ch->ch_mforce |= D_RTS(ch);
3430 ch->ch_mval &= ~(D_RTS(ch));
3433 if (clear & TIOCM_DTR) {
3434 ch->ch_mforce |= D_DTR(ch);
3435 ch->ch_mval &= ~(D_DTR(ch));
3440 DGAP_UNLOCK(ch->ch_lock, lock_flags2);
3441 DGAP_UNLOCK(bd->bd_lock, lock_flags);
3443 DPR_IOCTL(("dgap_tty_tiocmset finish\n"));
3451 * dgap_tty_send_break()
3453 * Send a Break, called by ld.
3455 static int dgap_tty_send_break(struct tty_struct *tty, int msec)
3458 struct channel_t *ch;
3464 if (!tty || tty->magic != TTY_MAGIC)
3467 un = tty->driver_data;
3468 if (!un || un->magic != DGAP_UNIT_MAGIC)
3472 if (!ch || ch->magic != DGAP_CHANNEL_MAGIC)
3476 if (!bd || bd->magic != DGAP_BOARD_MAGIC)
3491 DPR_IOCTL(("dgap_tty_send_break start 1. %lx\n", jiffies));
3493 DGAP_LOCK(bd->bd_lock, lock_flags);
3494 DGAP_LOCK(ch->ch_lock, lock_flags2);
3496 dgap_cmdw(ch, SBREAK, (u16) SBREAK_TIME, 0);
3498 dgap_cmdw(ch, SBREAK, (u16) msec, 0);
3500 DGAP_UNLOCK(ch->ch_lock, lock_flags2);
3501 DGAP_UNLOCK(bd->bd_lock, lock_flags);
3503 DPR_IOCTL(("dgap_tty_send_break finish\n"));
3512 * dgap_tty_wait_until_sent()
3514 * wait until data has been transmitted, called by ld.
3516 static void dgap_tty_wait_until_sent(struct tty_struct *tty, int timeout)
3519 rc = dgap_wait_for_drain(tty);
3521 DPR_IOCTL(("dgap_tty_ioctl - bad return: %d ", rc));
3532 * send a high priority character, called by ld.
3534 static void dgap_tty_send_xchar(struct tty_struct *tty, char c)
3537 struct channel_t *ch;
3542 if (!tty || tty->magic != TTY_MAGIC)
3545 un = tty->driver_data;
3546 if (!un || un->magic != DGAP_UNIT_MAGIC)
3550 if (!ch || ch->magic != DGAP_CHANNEL_MAGIC)
3554 if (!bd || bd->magic != DGAP_BOARD_MAGIC)
3557 DPR_IOCTL(("dgap_tty_send_xchar start 1. %lx\n", jiffies));
3559 DGAP_LOCK(bd->bd_lock, lock_flags);
3560 DGAP_LOCK(ch->ch_lock, lock_flags2);
3563 * This is technically what we should do.
3564 * However, the NIST tests specifically want
3565 * to see each XON or XOFF character that it
3566 * sends, so lets just send each character
3570 if (c == STOP_CHAR(tty)) {
3571 dgap_cmdw(ch, RPAUSE, 0, 0);
3573 else if (c == START_CHAR(tty)) {
3574 dgap_cmdw(ch, RRESUME, 0, 0);
3577 dgap_wmove(ch, &c, 1);
3580 dgap_wmove(ch, &c, 1);
3583 DGAP_UNLOCK(ch->ch_lock, lock_flags2);
3584 DGAP_UNLOCK(bd->bd_lock, lock_flags);
3586 DPR_IOCTL(("dgap_tty_send_xchar finish\n"));
3595 * Return modem signals to ld.
3597 static int dgap_get_modem_info(struct channel_t *ch, unsigned int __user *value)
3604 DPR_IOCTL(("dgap_get_modem_info start\n"));
3606 if (!ch || ch->magic != DGAP_CHANNEL_MAGIC)
3609 DGAP_LOCK(ch->ch_lock, lock_flags);
3611 mstat = readb(&(ch->ch_bs->m_stat));
3612 /* Append any outbound signals that might be pending... */
3613 mstat |= ch->ch_mostat;
3615 DGAP_UNLOCK(ch->ch_lock, lock_flags);
3619 if (mstat & D_DTR(ch))
3620 result |= TIOCM_DTR;
3621 if (mstat & D_RTS(ch))
3622 result |= TIOCM_RTS;
3623 if (mstat & D_CTS(ch))
3624 result |= TIOCM_CTS;
3625 if (mstat & D_DSR(ch))
3626 result |= TIOCM_DSR;
3627 if (mstat & D_RI(ch))
3629 if (mstat & D_CD(ch))
3632 rc = put_user(result, value);
3634 DPR_IOCTL(("dgap_get_modem_info finish\n"));
3640 * dgap_set_modem_info()
3642 * Set modem signals, called by ld.
3644 static int dgap_set_modem_info(struct tty_struct *tty, unsigned int command, unsigned int __user *value)
3647 struct channel_t *ch;
3650 unsigned int arg = 0;
3654 if (!tty || tty->magic != TTY_MAGIC)
3657 un = tty->driver_data;
3658 if (!un || un->magic != DGAP_UNIT_MAGIC)
3662 if (!ch || ch->magic != DGAP_CHANNEL_MAGIC)
3666 if (!bd || bd->magic != DGAP_BOARD_MAGIC)
3669 DPR_IOCTL(("dgap_set_modem_info() start\n"));
3671 ret = get_user(arg, value);
3673 DPR_IOCTL(("dgap_set_modem_info %d ret: %x. finished.\n", __LINE__, ret));
3677 DPR_IOCTL(("dgap_set_modem_info: command: %x arg: %x\n", command, arg));
3681 if (arg & TIOCM_RTS) {
3682 ch->ch_mforce |= D_RTS(ch);
3683 ch->ch_mval |= D_RTS(ch);
3686 if (arg & TIOCM_DTR) {
3687 ch->ch_mforce |= D_DTR(ch);
3688 ch->ch_mval |= D_DTR(ch);
3694 if (arg & TIOCM_RTS) {
3695 ch->ch_mforce |= D_RTS(ch);
3696 ch->ch_mval &= ~(D_RTS(ch));
3699 if (arg & TIOCM_DTR) {
3700 ch->ch_mforce |= D_DTR(ch);
3701 ch->ch_mval &= ~(D_DTR(ch));
3707 ch->ch_mforce = D_DTR(ch)|D_RTS(ch);
3709 if (arg & TIOCM_RTS) {
3710 ch->ch_mval |= D_RTS(ch);
3713 ch->ch_mval &= ~(D_RTS(ch));
3716 if (arg & TIOCM_DTR) {
3717 ch->ch_mval |= (D_DTR(ch));
3720 ch->ch_mval &= ~(D_DTR(ch));
3729 DGAP_LOCK(bd->bd_lock, lock_flags);
3730 DGAP_LOCK(ch->ch_lock, lock_flags2);
3734 DGAP_UNLOCK(ch->ch_lock, lock_flags2);
3735 DGAP_UNLOCK(bd->bd_lock, lock_flags);
3737 DPR_IOCTL(("dgap_set_modem_info finish\n"));
3744 * dgap_tty_digigeta()
3746 * Ioctl to get the information for ditty.
3751 static int dgap_tty_digigeta(struct tty_struct *tty, struct digi_t __user *retinfo)
3753 struct channel_t *ch;
3761 if (!tty || tty->magic != TTY_MAGIC)
3764 un = tty->driver_data;
3765 if (!un || un->magic != DGAP_UNIT_MAGIC)
3769 if (!ch || ch->magic != DGAP_CHANNEL_MAGIC)
3772 memset(&tmp, 0, sizeof(tmp));
3774 DGAP_LOCK(ch->ch_lock, lock_flags);
3775 memcpy(&tmp, &ch->ch_digi, sizeof(tmp));
3776 DGAP_UNLOCK(ch->ch_lock, lock_flags);
3778 if (copy_to_user(retinfo, &tmp, sizeof(*retinfo)))
3786 * dgap_tty_digiseta()
3788 * Ioctl to set the information for ditty.
3793 static int dgap_tty_digiseta(struct tty_struct *tty, struct digi_t __user *new_info)
3796 struct channel_t *ch;
3798 struct digi_t new_digi;
3799 ulong lock_flags = 0;
3800 unsigned long lock_flags2;
3802 DPR_IOCTL(("DIGI_SETA start\n"));
3804 if (!tty || tty->magic != TTY_MAGIC)
3807 un = tty->driver_data;
3808 if (!un || un->magic != DGAP_UNIT_MAGIC)
3812 if (!ch || ch->magic != DGAP_CHANNEL_MAGIC)
3816 if (!bd || bd->magic != DGAP_BOARD_MAGIC)
3819 if (copy_from_user(&new_digi, new_info, sizeof(struct digi_t))) {
3820 DPR_IOCTL(("DIGI_SETA failed copy_from_user\n"));
3824 DGAP_LOCK(bd->bd_lock, lock_flags);
3825 DGAP_LOCK(ch->ch_lock, lock_flags2);
3827 memcpy(&ch->ch_digi, &new_digi, sizeof(struct digi_t));
3829 if (ch->ch_digi.digi_maxcps < 1)
3830 ch->ch_digi.digi_maxcps = 1;
3832 if (ch->ch_digi.digi_maxcps > 10000)
3833 ch->ch_digi.digi_maxcps = 10000;
3835 if (ch->ch_digi.digi_bufsize < 10)
3836 ch->ch_digi.digi_bufsize = 10;
3838 if (ch->ch_digi.digi_maxchar < 1)
3839 ch->ch_digi.digi_maxchar = 1;
3841 if (ch->ch_digi.digi_maxchar > ch->ch_digi.digi_bufsize)
3842 ch->ch_digi.digi_maxchar = ch->ch_digi.digi_bufsize;
3844 if (ch->ch_digi.digi_onlen > DIGI_PLEN)
3845 ch->ch_digi.digi_onlen = DIGI_PLEN;
3847 if (ch->ch_digi.digi_offlen > DIGI_PLEN)
3848 ch->ch_digi.digi_offlen = DIGI_PLEN;
3852 DGAP_UNLOCK(ch->ch_lock, lock_flags2);
3853 DGAP_UNLOCK(bd->bd_lock, lock_flags);
3855 DPR_IOCTL(("DIGI_SETA finish\n"));
3862 * dgap_tty_digigetedelay()
3864 * Ioctl to get the current edelay setting.
3869 static int dgap_tty_digigetedelay(struct tty_struct *tty, int __user *retinfo)
3871 struct channel_t *ch;
3879 if (!tty || tty->magic != TTY_MAGIC)
3882 un = tty->driver_data;
3883 if (!un || un->magic != DGAP_UNIT_MAGIC)
3887 if (!ch || ch->magic != DGAP_CHANNEL_MAGIC)
3890 memset(&tmp, 0, sizeof(tmp));
3892 DGAP_LOCK(ch->ch_lock, lock_flags);
3893 tmp = readw(&(ch->ch_bs->edelay));
3894 DGAP_UNLOCK(ch->ch_lock, lock_flags);
3896 if (copy_to_user(retinfo, &tmp, sizeof(*retinfo)))
3904 * dgap_tty_digisetedelay()
3906 * Ioctl to set the EDELAY setting
3909 static int dgap_tty_digisetedelay(struct tty_struct *tty, int __user *new_info)
3912 struct channel_t *ch;
3918 DPR_IOCTL(("DIGI_SETA start\n"));
3920 if (!tty || tty->magic != TTY_MAGIC)
3923 un = tty->driver_data;
3924 if (!un || un->magic != DGAP_UNIT_MAGIC)
3928 if (!ch || ch->magic != DGAP_CHANNEL_MAGIC)
3932 if (!bd || bd->magic != DGAP_BOARD_MAGIC)
3935 if (copy_from_user(&new_digi, new_info, sizeof(int))) {
3936 DPR_IOCTL(("DIGI_SETEDELAY failed copy_from_user\n"));
3940 DGAP_LOCK(bd->bd_lock, lock_flags);
3941 DGAP_LOCK(ch->ch_lock, lock_flags2);
3943 writew((u16) new_digi, &(ch->ch_bs->edelay));
3947 DGAP_UNLOCK(ch->ch_lock, lock_flags2);
3948 DGAP_UNLOCK(bd->bd_lock, lock_flags);
3950 DPR_IOCTL(("DIGI_SETA finish\n"));
3957 * dgap_tty_digigetcustombaud()
3959 * Ioctl to get the current custom baud rate setting.
3961 static int dgap_tty_digigetcustombaud(struct tty_struct *tty, int __user *retinfo)
3963 struct channel_t *ch;
3971 if (!tty || tty->magic != TTY_MAGIC)
3974 un = tty->driver_data;
3975 if (!un || un->magic != DGAP_UNIT_MAGIC)
3979 if (!ch || ch->magic != DGAP_CHANNEL_MAGIC)
3982 memset(&tmp, 0, sizeof(tmp));
3984 DGAP_LOCK(ch->ch_lock, lock_flags);
3985 tmp = dgap_get_custom_baud(ch);
3986 DGAP_UNLOCK(ch->ch_lock, lock_flags);
3988 DPR_IOCTL(("DIGI_GETCUSTOMBAUD. Returning %d\n", tmp));
3990 if (copy_to_user(retinfo, &tmp, sizeof(*retinfo)))
3998 * dgap_tty_digisetcustombaud()
4000 * Ioctl to set the custom baud rate setting
4002 static int dgap_tty_digisetcustombaud(struct tty_struct *tty, int __user *new_info)
4005 struct channel_t *ch;
4011 DPR_IOCTL(("DIGI_SETCUSTOMBAUD start\n"));
4013 if (!tty || tty->magic != TTY_MAGIC)
4016 un = tty->driver_data;
4017 if (!un || un->magic != DGAP_UNIT_MAGIC)
4021 if (!ch || ch->magic != DGAP_CHANNEL_MAGIC)
4025 if (!bd || bd->magic != DGAP_BOARD_MAGIC)
4029 if (copy_from_user(&new_rate, new_info, sizeof(unsigned int))) {
4030 DPR_IOCTL(("DIGI_SETCUSTOMBAUD failed copy_from_user\n"));
4034 if (bd->bd_flags & BD_FEP5PLUS) {
4036 DPR_IOCTL(("DIGI_SETCUSTOMBAUD. Setting %d\n", new_rate));
4038 DGAP_LOCK(bd->bd_lock, lock_flags);
4039 DGAP_LOCK(ch->ch_lock, lock_flags2);
4041 ch->ch_custom_speed = new_rate;
4045 DGAP_UNLOCK(ch->ch_lock, lock_flags2);
4046 DGAP_UNLOCK(bd->bd_lock, lock_flags);
4049 DPR_IOCTL(("DIGI_SETCUSTOMBAUD finish\n"));
4056 * dgap_set_termios()
4058 static void dgap_tty_set_termios(struct tty_struct *tty, struct ktermios *old_termios)
4061 struct channel_t *ch;
4063 unsigned long lock_flags;
4064 unsigned long lock_flags2;
4066 if (!tty || tty->magic != TTY_MAGIC)
4069 un = tty->driver_data;
4070 if (!un || un->magic != DGAP_UNIT_MAGIC)
4074 if (!ch || ch->magic != DGAP_CHANNEL_MAGIC)
4078 if (!bd || bd->magic != DGAP_BOARD_MAGIC)
4081 DGAP_LOCK(bd->bd_lock, lock_flags);
4082 DGAP_LOCK(ch->ch_lock, lock_flags2);
4084 ch->ch_c_cflag = tty->termios.c_cflag;
4085 ch->ch_c_iflag = tty->termios.c_iflag;
4086 ch->ch_c_oflag = tty->termios.c_oflag;
4087 ch->ch_c_lflag = tty->termios.c_lflag;
4088 ch->ch_startc = tty->termios.c_cc[VSTART];
4089 ch->ch_stopc = tty->termios.c_cc[VSTOP];
4094 DGAP_UNLOCK(ch->ch_lock, lock_flags2);
4095 DGAP_UNLOCK(bd->bd_lock, lock_flags);
4099 static void dgap_tty_throttle(struct tty_struct *tty)
4102 struct channel_t *ch;
4107 if (!tty || tty->magic != TTY_MAGIC)
4110 un = tty->driver_data;
4111 if (!un || un->magic != DGAP_UNIT_MAGIC)
4115 if (!ch || ch->magic != DGAP_CHANNEL_MAGIC)
4119 if (!bd || bd->magic != DGAP_BOARD_MAGIC)
4122 DPR_IOCTL(("dgap_tty_throttle start\n"));
4124 DGAP_LOCK(bd->bd_lock, lock_flags);
4125 DGAP_LOCK(ch->ch_lock, lock_flags2);
4127 ch->ch_flags |= (CH_RXBLOCK);
4129 dgap_cmdw(ch, RPAUSE, 0, 0);
4132 DGAP_UNLOCK(ch->ch_lock, lock_flags2);
4133 DGAP_UNLOCK(bd->bd_lock, lock_flags);
4135 DPR_IOCTL(("dgap_tty_throttle finish\n"));
4139 static void dgap_tty_unthrottle(struct tty_struct *tty)
4142 struct channel_t *ch;
4147 if (!tty || tty->magic != TTY_MAGIC)
4150 un = tty->driver_data;
4151 if (!un || un->magic != DGAP_UNIT_MAGIC)
4155 if (!ch || ch->magic != DGAP_CHANNEL_MAGIC)
4159 if (!bd || bd->magic != DGAP_BOARD_MAGIC)
4162 DPR_IOCTL(("dgap_tty_unthrottle start\n"));
4164 DGAP_LOCK(bd->bd_lock, lock_flags);
4165 DGAP_LOCK(ch->ch_lock, lock_flags2);
4167 ch->ch_flags &= ~(CH_RXBLOCK);
4170 dgap_cmdw(ch, RRESUME, 0, 0);
4173 DGAP_UNLOCK(ch->ch_lock, lock_flags2);
4174 DGAP_UNLOCK(bd->bd_lock, lock_flags);
4176 DPR_IOCTL(("dgap_tty_unthrottle finish\n"));
4180 static void dgap_tty_start(struct tty_struct *tty)
4183 struct channel_t *ch;
4188 if (!tty || tty->magic != TTY_MAGIC)
4191 un = tty->driver_data;
4192 if (!un || un->magic != DGAP_UNIT_MAGIC)
4196 if (!ch || ch->magic != DGAP_CHANNEL_MAGIC)
4200 if (!bd || bd->magic != DGAP_BOARD_MAGIC)
4203 DPR_IOCTL(("dgap_tty_start start\n"));
4205 DGAP_LOCK(bd->bd_lock, lock_flags);
4206 DGAP_LOCK(ch->ch_lock, lock_flags2);
4208 dgap_cmdw(ch, RESUMETX, 0, 0);
4210 DGAP_UNLOCK(ch->ch_lock, lock_flags2);
4211 DGAP_UNLOCK(bd->bd_lock, lock_flags);
4213 DPR_IOCTL(("dgap_tty_start finish\n"));
4217 static void dgap_tty_stop(struct tty_struct *tty)
4220 struct channel_t *ch;
4225 if (!tty || tty->magic != TTY_MAGIC)
4228 un = tty->driver_data;
4229 if (!un || un->magic != DGAP_UNIT_MAGIC)
4233 if (!ch || ch->magic != DGAP_CHANNEL_MAGIC)
4237 if (!bd || bd->magic != DGAP_BOARD_MAGIC)
4240 DPR_IOCTL(("dgap_tty_stop start\n"));
4242 DGAP_LOCK(bd->bd_lock, lock_flags);
4243 DGAP_LOCK(ch->ch_lock, lock_flags2);
4245 dgap_cmdw(ch, PAUSETX, 0, 0);
4247 DGAP_UNLOCK(ch->ch_lock, lock_flags2);
4248 DGAP_UNLOCK(bd->bd_lock, lock_flags);
4250 DPR_IOCTL(("dgap_tty_stop finish\n"));
4255 * dgap_tty_flush_chars()
4257 * Flush the cook buffer
4259 * Note to self, and any other poor souls who venture here:
4261 * flush in this case DOES NOT mean dispose of the data.
4262 * instead, it means "stop buffering and send it if you
4263 * haven't already." Just guess how I figured that out... SRW 2-Jun-98
4265 * It is also always called in interrupt context - JAR 8-Sept-99
4267 static void dgap_tty_flush_chars(struct tty_struct *tty)
4270 struct channel_t *ch;
4275 if (!tty || tty->magic != TTY_MAGIC)
4278 un = tty->driver_data;
4279 if (!un || un->magic != DGAP_UNIT_MAGIC)
4283 if (!ch || ch->magic != DGAP_CHANNEL_MAGIC)
4287 if (!bd || bd->magic != DGAP_BOARD_MAGIC)
4290 DPR_IOCTL(("dgap_tty_flush_chars start\n"));
4292 DGAP_LOCK(bd->bd_lock, lock_flags);
4293 DGAP_LOCK(ch->ch_lock, lock_flags2);
4295 /* TODO: Do something here */
4297 DGAP_UNLOCK(ch->ch_lock, lock_flags2);
4298 DGAP_UNLOCK(bd->bd_lock, lock_flags);
4300 DPR_IOCTL(("dgap_tty_flush_chars finish\n"));
4306 * dgap_tty_flush_buffer()
4308 * Flush Tx buffer (make in == out)
4310 static void dgap_tty_flush_buffer(struct tty_struct *tty)
4313 struct channel_t *ch;
4319 if (!tty || tty->magic != TTY_MAGIC)
4322 un = tty->driver_data;
4323 if (!un || un->magic != DGAP_UNIT_MAGIC)
4327 if (!ch || ch->magic != DGAP_CHANNEL_MAGIC)
4331 if (!bd || bd->magic != DGAP_BOARD_MAGIC)
4334 DPR_IOCTL(("dgap_tty_flush_buffer on port: %d start\n", ch->ch_portnum));
4336 DGAP_LOCK(bd->bd_lock, lock_flags);
4337 DGAP_LOCK(ch->ch_lock, lock_flags2);
4339 ch->ch_flags &= ~CH_STOP;
4340 head = readw(&(ch->ch_bs->tx_head));
4341 dgap_cmdw(ch, FLUSHTX, (u16) head, 0);
4342 dgap_cmdw(ch, RESUMETX, 0, 0);
4343 if (ch->ch_tun.un_flags & (UN_LOW|UN_EMPTY)) {
4344 ch->ch_tun.un_flags &= ~(UN_LOW|UN_EMPTY);
4345 wake_up_interruptible(&ch->ch_tun.un_flags_wait);
4347 if (ch->ch_pun.un_flags & (UN_LOW|UN_EMPTY)) {
4348 ch->ch_pun.un_flags &= ~(UN_LOW|UN_EMPTY);
4349 wake_up_interruptible(&ch->ch_pun.un_flags_wait);
4352 DGAP_UNLOCK(ch->ch_lock, lock_flags2);
4353 DGAP_UNLOCK(bd->bd_lock, lock_flags);
4354 if (waitqueue_active(&tty->write_wait))
4355 wake_up_interruptible(&tty->write_wait);
4358 DPR_IOCTL(("dgap_tty_flush_buffer finish\n"));
4363 /*****************************************************************************
4365 * The IOCTL function and all of its helpers
4367 *****************************************************************************/
4372 * The usual assortment of ioctl's
4374 static int dgap_tty_ioctl(struct tty_struct *tty, unsigned int cmd,
4378 struct channel_t *ch;
4382 ulong lock_flags = 0;
4383 ulong lock_flags2 = 0;
4384 void __user *uarg = (void __user *) arg;
4386 if (!tty || tty->magic != TTY_MAGIC)
4389 un = tty->driver_data;
4390 if (!un || un->magic != DGAP_UNIT_MAGIC)
4394 if (!ch || ch->magic != DGAP_CHANNEL_MAGIC)
4398 if (!bd || bd->magic != DGAP_BOARD_MAGIC)
4401 DPR_IOCTL(("dgap_tty_ioctl start on port %d - cmd %s (%x), arg %lx\n",
4402 ch->ch_portnum, dgap_ioctl_name(cmd), cmd, arg));
4404 DGAP_LOCK(bd->bd_lock, lock_flags);
4405 DGAP_LOCK(ch->ch_lock, lock_flags2);
4407 if (un->un_open_count <= 0) {
4408 DPR_BASIC(("dgap_tty_ioctl - unit not open.\n"));
4409 DGAP_UNLOCK(ch->ch_lock, lock_flags2);
4410 DGAP_UNLOCK(bd->bd_lock, lock_flags);
4416 /* Here are all the standard ioctl's that we MUST implement */
4420 * TCSBRK is SVID version: non-zero arg --> no break
4421 * this behaviour is exploited by tcdrain().
4423 * According to POSIX.1 spec (7.2.2.1.2) breaks should be
4424 * between 0.25 and 0.5 seconds so we'll ask for something
4425 * in the middle: 0.375 seconds.
4427 rc = tty_check_change(tty);
4428 DGAP_UNLOCK(ch->ch_lock, lock_flags2);
4429 DGAP_UNLOCK(bd->bd_lock, lock_flags);
4434 rc = dgap_wait_for_drain(tty);
4437 DPR_IOCTL(("dgap_tty_ioctl - bad return: %d ", rc));
4441 DGAP_LOCK(bd->bd_lock, lock_flags);
4442 DGAP_LOCK(ch->ch_lock, lock_flags2);
4444 if(((cmd == TCSBRK) && (!arg)) || (cmd == TCSBRKP)) {
4445 dgap_cmdw(ch, SBREAK, (u16) SBREAK_TIME, 0);
4448 DGAP_UNLOCK(ch->ch_lock, lock_flags2);
4449 DGAP_UNLOCK(bd->bd_lock, lock_flags);
4451 DPR_IOCTL(("dgap_tty_ioctl finish on port %d - cmd %s (%x), arg %lx\n",
4452 ch->ch_portnum, dgap_ioctl_name(cmd), cmd, arg));
4458 /* support for POSIX tcsendbreak()
4460 * According to POSIX.1 spec (7.2.2.1.2) breaks should be
4461 * between 0.25 and 0.5 seconds so we'll ask for something
4462 * in the middle: 0.375 seconds.
4464 rc = tty_check_change(tty);
4465 DGAP_UNLOCK(ch->ch_lock, lock_flags2);
4466 DGAP_UNLOCK(bd->bd_lock, lock_flags);
4471 rc = dgap_wait_for_drain(tty);
4473 DPR_IOCTL(("dgap_tty_ioctl - bad return: %d ", rc));
4477 DGAP_LOCK(bd->bd_lock, lock_flags);
4478 DGAP_LOCK(ch->ch_lock, lock_flags2);
4480 dgap_cmdw(ch, SBREAK, (u16) SBREAK_TIME, 0);
4482 DGAP_UNLOCK(ch->ch_lock, lock_flags2);
4483 DGAP_UNLOCK(bd->bd_lock, lock_flags);
4485 DPR_IOCTL(("dgap_tty_ioctl finish on port %d - cmd %s (%x), arg %lx\n",
4486 ch->ch_portnum, dgap_ioctl_name(cmd), cmd, arg));
4492 * FEP5 doesn't support turning on a break unconditionally.
4493 * The FEP5 device will stop sending a break automatically
4494 * after the specified time value that was sent when turning on
4497 rc = tty_check_change(tty);
4498 DGAP_UNLOCK(ch->ch_lock, lock_flags2);
4499 DGAP_UNLOCK(bd->bd_lock, lock_flags);
4504 rc = dgap_wait_for_drain(tty);
4506 DPR_IOCTL(("dgap_tty_ioctl - bad return: %d ", rc));
4510 DGAP_LOCK(bd->bd_lock, lock_flags);
4511 DGAP_LOCK(ch->ch_lock, lock_flags2);
4513 dgap_cmdw(ch, SBREAK, (u16) SBREAK_TIME, 0);
4515 DGAP_UNLOCK(ch->ch_lock, lock_flags2);
4516 DGAP_UNLOCK(bd->bd_lock, lock_flags);
4518 DPR_IOCTL(("dgap_tty_ioctl finish on port %d - cmd %s (%x), arg %lx\n",
4519 ch->ch_portnum, dgap_ioctl_name(cmd), cmd, arg));
4525 * FEP5 doesn't support turning off a break unconditionally.
4526 * The FEP5 device will stop sending a break automatically
4527 * after the specified time value that was sent when turning on
4530 DGAP_UNLOCK(ch->ch_lock, lock_flags2);
4531 DGAP_UNLOCK(bd->bd_lock, lock_flags);
4536 DGAP_UNLOCK(ch->ch_lock, lock_flags2);
4537 DGAP_UNLOCK(bd->bd_lock, lock_flags);
4539 rc = put_user(C_CLOCAL(tty) ? 1 : 0, (unsigned long __user *) arg);
4543 DGAP_UNLOCK(ch->ch_lock, lock_flags2);
4544 DGAP_UNLOCK(bd->bd_lock, lock_flags);
4546 rc = get_user(arg, (unsigned long __user *) arg);
4550 DGAP_LOCK(bd->bd_lock, lock_flags);
4551 DGAP_LOCK(ch->ch_lock, lock_flags2);
4552 tty->termios.c_cflag = ((tty->termios.c_cflag & ~CLOCAL) | (arg ? CLOCAL : 0));
4554 DGAP_UNLOCK(ch->ch_lock, lock_flags2);
4555 DGAP_UNLOCK(bd->bd_lock, lock_flags);
4560 DGAP_UNLOCK(ch->ch_lock, lock_flags2);
4561 DGAP_UNLOCK(bd->bd_lock, lock_flags);
4562 return(dgap_get_modem_info(ch, uarg));
4567 DGAP_UNLOCK(ch->ch_lock, lock_flags2);
4568 DGAP_UNLOCK(bd->bd_lock, lock_flags);
4569 return(dgap_set_modem_info(tty, cmd, uarg));
4572 * Here are any additional ioctl's that we want to implement
4577 * The linux tty driver doesn't have a flush
4578 * input routine for the driver, assuming all backed
4579 * up data is in the line disc. buffers. However,
4580 * we all know that's not the case. Here, we
4581 * act on the ioctl, but then lie and say we didn't
4582 * so the line discipline will process the flush
4585 rc = tty_check_change(tty);
4587 DGAP_UNLOCK(ch->ch_lock, lock_flags2);
4588 DGAP_UNLOCK(bd->bd_lock, lock_flags);
4592 if ((arg == TCIFLUSH) || (arg == TCIOFLUSH)) {
4593 if (!(un->un_type == DGAP_PRINT)) {
4594 head = readw(&(ch->ch_bs->rx_head));
4595 writew(head, &(ch->ch_bs->rx_tail));
4596 writeb(0, &(ch->ch_bs->orun));
4600 if ((arg == TCOFLUSH) || (arg == TCIOFLUSH)) {
4601 ch->ch_flags &= ~CH_STOP;
4602 head = readw(&(ch->ch_bs->tx_head));
4603 dgap_cmdw(ch, FLUSHTX, (u16) head, 0 );
4604 dgap_cmdw(ch, RESUMETX, 0, 0);
4605 if (ch->ch_tun.un_flags & (UN_LOW|UN_EMPTY)) {
4606 ch->ch_tun.un_flags &= ~(UN_LOW|UN_EMPTY);
4607 wake_up_interruptible(&ch->ch_tun.un_flags_wait);
4609 if (ch->ch_pun.un_flags & (UN_LOW|UN_EMPTY)) {
4610 ch->ch_pun.un_flags &= ~(UN_LOW|UN_EMPTY);
4611 wake_up_interruptible(&ch->ch_pun.un_flags_wait);
4613 if (waitqueue_active(&tty->write_wait))
4614 wake_up_interruptible(&tty->write_wait);
4616 /* Can't hold any locks when calling tty_wakeup! */
4617 DGAP_UNLOCK(ch->ch_lock, lock_flags2);
4618 DGAP_UNLOCK(bd->bd_lock, lock_flags);
4620 DGAP_LOCK(bd->bd_lock, lock_flags);
4621 DGAP_LOCK(ch->ch_lock, lock_flags2);
4624 /* pretend we didn't recognize this IOCTL */
4625 DGAP_UNLOCK(ch->ch_lock, lock_flags2);
4626 DGAP_UNLOCK(bd->bd_lock, lock_flags);
4628 DPR_IOCTL(("dgap_tty_ioctl (LINE:%d) finish on port %d - cmd %s (%x), arg %lx\n",
4629 __LINE__, ch->ch_portnum, dgap_ioctl_name(cmd), cmd, arg));
4631 return(-ENOIOCTLCMD);
4636 * The linux tty driver doesn't have a flush
4637 * input routine for the driver, assuming all backed
4638 * up data is in the line disc. buffers. However,
4639 * we all know that's not the case. Here, we
4640 * act on the ioctl, but then lie and say we didn't
4641 * so the line discipline will process the flush
4644 if (cmd == TCSETSF) {
4646 ch->ch_flags &= ~CH_STOP;
4647 head = readw(&(ch->ch_bs->rx_head));
4648 writew(head, &(ch->ch_bs->rx_tail));
4651 /* now wait for all the output to drain */
4652 DGAP_UNLOCK(ch->ch_lock, lock_flags2);
4653 DGAP_UNLOCK(bd->bd_lock, lock_flags);
4654 rc = dgap_wait_for_drain(tty);
4656 DPR_IOCTL(("dgap_tty_ioctl - bad return: %d ", rc));
4660 DPR_IOCTL(("dgap_tty_ioctl finish on port %d - cmd %s (%x), arg %lx\n",
4661 ch->ch_portnum, dgap_ioctl_name(cmd), cmd, arg));
4663 /* pretend we didn't recognize this */
4664 return(-ENOIOCTLCMD);
4668 DGAP_UNLOCK(ch->ch_lock, lock_flags2);
4669 DGAP_UNLOCK(bd->bd_lock, lock_flags);
4670 rc = dgap_wait_for_drain(tty);
4672 DPR_IOCTL(("dgap_tty_ioctl - bad return: %d ", rc));
4676 /* pretend we didn't recognize this */
4677 return(-ENOIOCTLCMD);
4681 * The Linux Line Discipline (LD) would do this for us if we
4682 * let it, but we have the special firmware options to do this
4683 * the "right way" regardless of hardware or software flow
4684 * control so we'll do it outselves instead of letting the LD
4687 rc = tty_check_change(tty);
4689 DGAP_UNLOCK(ch->ch_lock, lock_flags2);
4690 DGAP_UNLOCK(bd->bd_lock, lock_flags);
4694 DPR_IOCTL(("dgap_ioctl - in TCXONC - %d\n", cmd));
4698 DGAP_UNLOCK(ch->ch_lock, lock_flags2);
4699 DGAP_UNLOCK(bd->bd_lock, lock_flags);
4700 dgap_tty_start(tty);
4703 DGAP_UNLOCK(ch->ch_lock, lock_flags2);
4704 DGAP_UNLOCK(bd->bd_lock, lock_flags);
4708 DGAP_UNLOCK(ch->ch_lock, lock_flags2);
4709 DGAP_UNLOCK(bd->bd_lock, lock_flags);
4710 /* Make the ld do it */
4711 return(-ENOIOCTLCMD);
4713 DGAP_UNLOCK(ch->ch_lock, lock_flags2);
4714 DGAP_UNLOCK(bd->bd_lock, lock_flags);
4715 /* Make the ld do it */
4716 return(-ENOIOCTLCMD);
4718 DGAP_UNLOCK(ch->ch_lock, lock_flags2);
4719 DGAP_UNLOCK(bd->bd_lock, lock_flags);
4724 /* get information for ditty */
4725 DGAP_UNLOCK(ch->ch_lock, lock_flags2);
4726 DGAP_UNLOCK(bd->bd_lock, lock_flags);
4727 return(dgap_tty_digigeta(tty, uarg));
4732 /* set information for ditty */
4733 if (cmd == (DIGI_SETAW)) {
4735 DGAP_UNLOCK(ch->ch_lock, lock_flags2);
4736 DGAP_UNLOCK(bd->bd_lock, lock_flags);
4737 rc = dgap_wait_for_drain(tty);
4739 DPR_IOCTL(("dgap_tty_ioctl - bad return: %d ", rc));
4742 DGAP_LOCK(bd->bd_lock, lock_flags);
4743 DGAP_LOCK(ch->ch_lock, lock_flags2);
4746 tty_ldisc_flush(tty);
4751 DGAP_UNLOCK(ch->ch_lock, lock_flags2);
4752 DGAP_UNLOCK(bd->bd_lock, lock_flags);
4753 return(dgap_tty_digiseta(tty, uarg));
4756 DGAP_UNLOCK(ch->ch_lock, lock_flags2);
4757 DGAP_UNLOCK(bd->bd_lock, lock_flags);
4758 return(dgap_tty_digigetedelay(tty, uarg));
4761 DGAP_UNLOCK(ch->ch_lock, lock_flags2);
4762 DGAP_UNLOCK(bd->bd_lock, lock_flags);
4763 return(dgap_tty_digisetedelay(tty, uarg));
4765 case DIGI_GETCUSTOMBAUD:
4766 DGAP_UNLOCK(ch->ch_lock, lock_flags2);
4767 DGAP_UNLOCK(bd->bd_lock, lock_flags);
4768 return(dgap_tty_digigetcustombaud(tty, uarg));
4770 case DIGI_SETCUSTOMBAUD:
4771 DGAP_UNLOCK(ch->ch_lock, lock_flags2);
4772 DGAP_UNLOCK(bd->bd_lock, lock_flags);
4773 return(dgap_tty_digisetcustombaud(tty, uarg));
4775 case DIGI_RESET_PORT:
4776 dgap_firmware_reset_port(ch);
4778 DGAP_UNLOCK(ch->ch_lock, lock_flags2);
4779 DGAP_UNLOCK(bd->bd_lock, lock_flags);
4783 DGAP_UNLOCK(ch->ch_lock, lock_flags2);
4784 DGAP_UNLOCK(bd->bd_lock, lock_flags);
4786 DPR_IOCTL(("dgap_tty_ioctl - in default\n"));
4787 DPR_IOCTL(("dgap_tty_ioctl end - cmd %s (%x), arg %lx\n",
4788 dgap_ioctl_name(cmd), cmd, arg));
4790 return(-ENOIOCTLCMD);
4794 static int dgap_after_config_loaded(int board)
4797 * Initialize KME waitqueues...
4799 init_waitqueue_head(&(dgap_Board[board]->kme_wait));
4802 * allocate flip buffer for board.
4804 dgap_Board[board]->flipbuf = kmalloc(MYFLIPLEN, GFP_ATOMIC);
4805 if (!dgap_Board[board]->flipbuf)
4808 dgap_Board[board]->flipflagbuf = kmalloc(MYFLIPLEN, GFP_ATOMIC);
4809 if (!dgap_Board[board]->flipflagbuf) {
4810 kfree(dgap_Board[board]->flipbuf);
4820 * Create pr and tty device entries
4822 static int dgap_tty_register_ports(struct board_t *brd)
4824 struct channel_t *ch;
4827 brd->SerialPorts = kcalloc(brd->nasync, sizeof(*brd->SerialPorts),
4829 if (brd->SerialPorts == NULL)
4831 for (i = 0; i < brd->nasync; i++)
4832 tty_port_init(&brd->SerialPorts[i]);
4834 brd->PrinterPorts = kcalloc(brd->nasync, sizeof(*brd->PrinterPorts),
4836 if (brd->PrinterPorts == NULL) {
4837 kfree(brd->SerialPorts);
4840 for (i = 0; i < brd->nasync; i++)
4841 tty_port_init(&brd->PrinterPorts[i]);
4843 ch = brd->channels[0];
4844 for (i = 0; i < brd->nasync; i++, ch = brd->channels[i]) {
4846 struct device *classp;
4848 classp = tty_port_register_device(&brd->SerialPorts[i],
4850 brd->firstminor + i, NULL);
4852 dgap_create_tty_sysfs(&ch->ch_tun, classp);
4853 ch->ch_tun.un_sysfs = classp;
4855 classp = tty_port_register_device(&brd->PrinterPorts[i],
4857 brd->firstminor + i, NULL);
4859 dgap_create_tty_sysfs(&ch->ch_pun, classp);
4860 ch->ch_pun.un_sysfs = classp;
4862 dgap_create_ports_sysfiles(brd);
4869 * Copies the BIOS code from the user to the board,
4870 * and starts the BIOS running.
4872 static void dgap_do_bios_load(struct board_t *brd, uchar __user *ubios, int len)
4878 if (!brd || (brd->magic != DGAP_BOARD_MAGIC) || !brd->re_map_membase)
4881 DPR_INIT(("dgap_do_bios_load() start\n"));
4883 addr = brd->re_map_membase;
4888 for (i = 0; i < 16; i++)
4889 writeb(0, addr + POSTAREA + i);
4895 memcpy_toio(addr + offset, ubios, len);
4897 writel(0x0bf00401, addr);
4898 writel(0, (addr + 4));
4900 /* Clear the reset, and change states. */
4901 writeb(FEPCLR, brd->re_map_port);
4906 * Checks to see if the BIOS completed running on the card.
4908 static void dgap_do_wait_for_bios(struct board_t *brd)
4915 if (!brd || (brd->magic != DGAP_BOARD_MAGIC) || !brd->re_map_membase)
4918 addr = brd->re_map_membase;
4919 word = readw(addr + POSTAREA);
4922 * It can take 5-6 seconds for a board to
4923 * pass the bios self test and post results.
4924 * Give it 10 seconds.
4926 brd->wait_for_bios = 0;
4927 while (brd->wait_for_bios < 1000) {
4928 /* Check to see if BIOS thinks board is good. (GD). */
4929 if (word == *(u16 *) "GD") {
4930 DPR_INIT(("GOT GD in memory, moving states.\n"));
4931 brd->state = FINISHED_BIOS_LOAD;
4934 msleep_interruptible(10);
4935 brd->wait_for_bios++;
4936 word = readw(addr + POSTAREA);
4939 /* Gave up on board after too long of time taken */
4940 err1 = readw(addr + SEQUENCE);
4941 err2 = readw(addr + ERROR);
4942 APR(("***WARNING*** %s failed diagnostics. Error #(%x,%x).\n",
4943 brd->name, err1, err2));
4944 brd->state = BOARD_FAILED;
4945 brd->dpastatus = BD_NOBIOS;
4950 * Copies the FEP code from the user to the board,
4951 * and starts the FEP running.
4953 static void dgap_do_fep_load(struct board_t *brd, uchar *ufep, int len)
4958 if (!brd || (brd->magic != DGAP_BOARD_MAGIC) || !brd->re_map_membase)
4961 addr = brd->re_map_membase;
4963 DPR_INIT(("dgap_do_fep_load() for board %s : start\n", brd->name));
4969 memcpy_toio(addr + offset, ufep, len);
4972 * If board is a concentrator product, we need to give
4973 * it its config string describing how the concentrators look.
4975 if ((brd->type == PCX) || (brd->type == PEPC)) {
4977 uchar *config, *xconfig;
4980 xconfig = dgap_create_config_string(brd, string);
4982 /* Write string to board memory */
4983 config = addr + CONFIG;
4984 for (; i < CONFIGSIZE; i++, config++, xconfig++) {
4985 writeb(*xconfig, config);
4986 if ((*xconfig & 0xff) == 0xff)
4991 writel(0xbfc01004, (addr + 0xc34));
4992 writel(0x3, (addr + 0xc30));
4994 DPR_INIT(("dgap_do_fep_load() for board %s : finish\n", brd->name));
5000 * Waits for the FEP to report thats its ready for us to use.
5002 static void dgap_do_wait_for_fep(struct board_t *brd)
5009 if (!brd || (brd->magic != DGAP_BOARD_MAGIC) || !brd->re_map_membase)
5012 addr = brd->re_map_membase;
5013 word = readw(addr + FEPSTAT);
5016 * It can take 2-3 seconds for the FEP to
5017 * be up and running. Give it 5 secs.
5019 brd->wait_for_fep = 0;
5020 while (brd->wait_for_fep < 500) {
5021 /* Check to see if FEP is up and running now. */
5022 if (word == *(u16 *) "OS") {
5023 brd->state = FINISHED_FEP_LOAD;
5025 * Check to see if the board can support FEP5+ commands.
5027 word = readw(addr + FEP5_PLUS);
5028 if (word == *(u16 *) "5A")
5029 brd->bd_flags |= BD_FEP5PLUS;
5033 msleep_interruptible(10);
5034 brd->wait_for_fep++;
5035 word = readw(addr + FEPSTAT);
5038 /* Gave up on board after too long of time taken */
5039 err1 = readw(addr + SEQUENCE);
5040 err2 = readw(addr + ERROR);
5041 APR(("***WARNING*** FEPOS for %s not functioning. Error #(%x,%x).\n",
5042 brd->name, err1, err2));
5043 brd->state = BOARD_FAILED;
5044 brd->dpastatus = BD_NOFEP;
5046 DPR_INIT(("dgap_do_wait_for_fep() for board %s : finish\n", brd->name));
5051 * Physically forces the FEP5 card to reset itself.
5053 static void dgap_do_reset_board(struct board_t *brd)
5060 if (!brd || (brd->magic != DGAP_BOARD_MAGIC) || !brd->re_map_membase || !brd->re_map_port) {
5061 DPR_INIT(("dgap_do_reset_board() start. bad values. brd: %p mem: %p io: %p\n",
5062 brd, brd ? brd->re_map_membase : 0, brd ? brd->re_map_port : 0));
5066 DPR_INIT(("dgap_do_reset_board() start. io: %p\n", brd->re_map_port));
5068 /* FEPRST does not vary among supported boards */
5069 writeb(FEPRST, brd->re_map_port);
5071 for (i = 0; i <= 1000; i++) {
5072 check = readb(brd->re_map_port) & 0xe;
5073 if (check == FEPRST)
5079 APR(("*** WARNING *** Board not resetting... Failing board.\n"));
5080 brd->state = BOARD_FAILED;
5081 brd->dpastatus = BD_NOFEP;
5086 * Make sure there really is memory out there.
5088 writel(0xa55a3cc3, (brd->re_map_membase + LOWMEM));
5089 writel(0x5aa5c33c, (brd->re_map_membase + HIGHMEM));
5090 check1 = readl(brd->re_map_membase + LOWMEM);
5091 check2 = readl(brd->re_map_membase + HIGHMEM);
5093 if ((check1 != 0xa55a3cc3) || (check2 != 0x5aa5c33c)) {
5094 APR(("*** Warning *** No memory at %p for board.\n", brd->re_map_membase));
5095 brd->state = BOARD_FAILED;
5096 brd->dpastatus = BD_NOFEP;
5100 if (brd->state != BOARD_FAILED)
5101 brd->state = FINISHED_RESET;
5104 DPR_INIT(("dgap_do_reset_board() finish\n"));
5108 #ifdef DIGI_CONCENTRATORS_SUPPORTED
5110 * Sends a concentrator image into the FEP5 board.
5112 static void dgap_do_conc_load(struct board_t *brd, uchar *uaddr, int len)
5116 struct downld_t *to_dp;
5118 if (!brd || (brd->magic != DGAP_BOARD_MAGIC) || !brd->re_map_membase)
5121 vaddr = brd->re_map_membase;
5123 offset = readw((u16 *) (vaddr + DOWNREQ));
5124 to_dp = (struct downld_t *) (vaddr + (int) offset);
5125 memcpy_toio(to_dp, uaddr, len);
5127 /* Tell card we have data for it */
5128 writew(0, vaddr + (DOWNREQ));
5130 brd->conc_dl_status = NO_PENDING_CONCENTRATOR_REQUESTS;
5134 #define EXPANSION_ROM_SIZE (64 * 1024)
5135 #define FEP5_ROM_MAGIC (0xFEFFFFFF)
5137 static void dgap_get_vpd(struct board_t *brd)
5149 * Poke the magic number at the PCI Rom Address location.
5150 * If VPD is supported, the value read from that address
5153 magic = FEP5_ROM_MAGIC;
5154 pci_write_config_dword(brd->pdev, PCI_ROM_ADDRESS, magic);
5155 pci_read_config_dword(brd->pdev, PCI_ROM_ADDRESS, &magic);
5157 /* VPD not supported, bail */
5162 * To get to the OTPROM memory, we have to send the boards base
5163 * address or'ed with 1 into the PCI Rom Address location.
5165 magic = brd->membase | 0x01;
5166 pci_write_config_dword(brd->pdev, PCI_ROM_ADDRESS, magic);
5167 pci_read_config_dword(brd->pdev, PCI_ROM_ADDRESS, &magic);
5169 byte1 = readb(brd->re_map_membase);
5170 byte2 = readb(brd->re_map_membase + 1);
5173 * If the board correctly swapped to the OTPROM memory,
5174 * the first 2 bytes (header) should be 0x55, 0xAA
5176 if (byte1 == 0x55 && byte2 == 0xAA) {
5181 * We have to run through all the OTPROM memory looking
5182 * for the VPD offset.
5184 while (base_offset <= EXPANSION_ROM_SIZE) {
5187 * Lots of magic numbers here.
5189 * The VPD offset is located inside the ROM Data Structure.
5190 * We also have to remember the length of each
5191 * ROM Data Structure, so we can "hop" to the next
5192 * entry if the VPD isn't in the current
5193 * ROM Data Structure.
5195 rom_offset = readw(brd->re_map_membase + base_offset + 0x18);
5196 image_length = readw(brd->re_map_membase + rom_offset + 0x10) * 512;
5197 vpd_offset = readw(brd->re_map_membase + rom_offset + 0x08);
5199 /* Found the VPD entry */
5203 /* We didn't find a VPD entry, go to next ROM entry. */
5204 base_offset += image_length;
5206 byte1 = readb(brd->re_map_membase + base_offset);
5207 byte2 = readb(brd->re_map_membase + base_offset + 1);
5210 * If the new ROM offset doesn't have 0x55, 0xAA
5211 * as its header, we have run out of ROM.
5213 if (byte1 != 0x55 || byte2 != 0xAA)
5218 * If we have a VPD offset, then mark the board
5219 * as having a valid VPD, and copy VPDSIZE (512) bytes of
5220 * that VPD to the buffer we have in our board structure.
5223 brd->bd_flags |= BD_HAS_VPD;
5224 for (i = 0; i < VPDSIZE; i++)
5225 brd->vpd[i] = readb(brd->re_map_membase + vpd_offset + i);
5230 * We MUST poke the magic number at the PCI Rom Address location again.
5231 * This makes the card report the regular board memory back to us,
5232 * rather than the OTPROM memory.
5234 magic = FEP5_ROM_MAGIC;
5235 pci_write_config_dword(brd->pdev, PCI_ROM_ADDRESS, magic);
5240 * Our board poller function.
5242 static void dgap_poll_tasklet(unsigned long data)
5244 struct board_t *bd = (struct board_t *) data;
5250 if (!bd || (bd->magic != DGAP_BOARD_MAGIC)) {
5251 APR(("dgap_poll_tasklet() - NULL or bad bd.\n"));
5255 if (bd->inhibit_poller)
5258 DGAP_LOCK(bd->bd_lock, lock_flags);
5260 vaddr = bd->re_map_membase;
5263 * If board is ready, parse deeper to see if there is anything to do.
5265 if (bd->state == BOARD_READY) {
5267 struct ev_t *eaddr = NULL;
5269 if (!bd->re_map_membase) {
5270 DGAP_UNLOCK(bd->bd_lock, lock_flags);
5273 if (!bd->re_map_port) {
5274 DGAP_UNLOCK(bd->bd_lock, lock_flags);
5282 eaddr = (struct ev_t *) (vaddr + EVBUF);
5284 /* Get our head and tail */
5285 head = readw(&(eaddr->ev_head));
5286 tail = readw(&(eaddr->ev_tail));
5289 * If there is an event pending. Go service it.
5292 DGAP_UNLOCK(bd->bd_lock, lock_flags);
5294 DGAP_LOCK(bd->bd_lock, lock_flags);
5299 * If board is doing interrupts, ACK the interrupt.
5301 if (bd && bd->intr_running) {
5302 readb(bd->re_map_port + 2);
5305 DGAP_UNLOCK(bd->bd_lock, lock_flags);
5309 /* Our state machine to get the board up and running */
5312 if (bd->state == NEED_RESET) {
5317 dgap_do_reset_board(bd);
5320 /* Move to next state */
5321 if (bd->state == FINISHED_RESET) {
5322 bd->state = NEED_CONFIG;
5325 if (bd->state == NEED_CONFIG) {
5327 * Match this board to a config the user created for us.
5329 bd->bd_config = dgap_find_config(bd->type, bd->pci_bus, bd->pci_slot);
5332 * Because the 4 port Xr products share the same PCI ID
5333 * as the 8 port Xr products, if we receive a NULL config
5334 * back, and this is a PAPORT8 board, retry with a
5335 * PAPORT4 attempt as well.
5337 if (bd->type == PAPORT8 && !bd->bd_config) {
5338 bd->bd_config = dgap_find_config(PAPORT4, bd->pci_bus, bd->pci_slot);
5342 * Register the ttys (if any) into the kernel.
5344 if (bd->bd_config) {
5345 bd->state = FINISHED_CONFIG;
5348 bd->state = CONFIG_NOT_FOUND;
5352 /* Move to next state */
5353 if (bd->state == FINISHED_CONFIG) {
5354 bd->state = NEED_DEVICE_CREATION;
5357 /* Move to next state */
5358 if (bd->state == NEED_DEVICE_CREATION) {
5360 * Signal downloader, its got some work to do.
5362 DGAP_LOCK(dgap_dl_lock, lock_flags2);
5363 if (dgap_dl_action != 1) {
5365 wake_up_interruptible(&dgap_dl_wait);
5367 DGAP_UNLOCK(dgap_dl_lock, lock_flags2);
5370 /* Move to next state */
5371 if (bd->state == FINISHED_DEVICE_CREATION) {
5372 bd->state = NEED_BIOS_LOAD;
5375 /* Move to next state */
5376 if (bd->state == NEED_BIOS_LOAD) {
5378 * Signal downloader, its got some work to do.
5380 DGAP_LOCK(dgap_dl_lock, lock_flags2);
5381 if (dgap_dl_action != 1) {
5383 wake_up_interruptible(&dgap_dl_wait);
5385 DGAP_UNLOCK(dgap_dl_lock, lock_flags2);
5388 /* Wait for BIOS to test board... */
5389 if (bd->state == WAIT_BIOS_LOAD) {
5390 dgap_do_wait_for_bios(bd);
5393 /* Move to next state */
5394 if (bd->state == FINISHED_BIOS_LOAD) {
5395 bd->state = NEED_FEP_LOAD;
5398 * Signal downloader, its got some work to do.
5400 DGAP_LOCK(dgap_dl_lock, lock_flags2);
5401 if (dgap_dl_action != 1) {
5403 wake_up_interruptible(&dgap_dl_wait);
5405 DGAP_UNLOCK(dgap_dl_lock, lock_flags2);
5408 /* Wait for FEP to load on board... */
5409 if (bd->state == WAIT_FEP_LOAD) {
5410 dgap_do_wait_for_fep(bd);
5414 /* Move to next state */
5415 if (bd->state == FINISHED_FEP_LOAD) {
5418 * Do tty device initialization.
5420 int rc = dgap_tty_init(bd);
5423 dgap_tty_uninit(bd);
5424 APR(("Can't init tty devices (%d)\n", rc));
5425 bd->state = BOARD_FAILED;
5426 bd->dpastatus = BD_NOFEP;
5429 bd->state = NEED_PROC_CREATION;
5432 * Signal downloader, its got some work to do.
5434 DGAP_LOCK(dgap_dl_lock, lock_flags2);
5435 if (dgap_dl_action != 1) {
5437 wake_up_interruptible(&dgap_dl_wait);
5439 DGAP_UNLOCK(dgap_dl_lock, lock_flags2);
5443 /* Move to next state */
5444 if (bd->state == FINISHED_PROC_CREATION) {
5446 bd->state = BOARD_READY;
5447 bd->dpastatus = BD_RUNNING;
5450 * If user requested the board to run in interrupt mode,
5451 * go and set it up on the board.
5453 if (bd->intr_used) {
5454 writew(1, (bd->re_map_membase + ENABLE_INTR));
5456 * Tell the board to poll the UARTS as fast as possible.
5458 writew(FEPPOLL_MIN, (bd->re_map_membase + FEPPOLL));
5459 bd->intr_running = 1;
5462 /* Wake up anyone waiting for board state to change to ready */
5463 wake_up_interruptible(&bd->state_wait);
5466 DGAP_UNLOCK(bd->bd_lock, lock_flags);
5470 /*=======================================================================
5472 * dgap_cmdb - Sends a 2 byte command to the FEP.
5474 * ch - Pointer to channel structure.
5475 * cmd - Command to be sent.
5476 * byte1 - Integer containing first byte to be sent.
5477 * byte2 - Integer containing second byte to be sent.
5478 * ncmds - Wait until ncmds or fewer cmds are left
5479 * in the cmd buffer before returning.
5481 *=======================================================================*/
5482 static void dgap_cmdb(struct channel_t *ch, uchar cmd, uchar byte1, uchar byte2, uint ncmds)
5485 struct cm_t *cm_addr = NULL;
5491 if (!ch || ch->magic != DGAP_CHANNEL_MAGIC)
5495 * Check if board is still alive.
5497 if (ch->ch_bd->state == BOARD_FAILED) {
5498 DPR_CORE(("%s:%d board is in failed state.\n", __FILE__, __LINE__));
5503 * Make sure the pointers are in range before
5504 * writing to the FEP memory.
5506 vaddr = ch->ch_bd->re_map_membase;
5511 cm_addr = (struct cm_t *) (vaddr + CMDBUF);
5512 head = readw(&(cm_addr->cm_head));
5515 * Forget it if pointers out of range.
5517 if (head >= (CMDMAX - CMDSTART) || (head & 03)) {
5518 DPR_CORE(("%s:%d pointers out of range, failing board!\n", __FILE__, __LINE__));
5519 ch->ch_bd->state = BOARD_FAILED;
5524 * Put the data in the circular command buffer.
5526 writeb(cmd, (char *) (vaddr + head + CMDSTART + 0));
5527 writeb((uchar) ch->ch_portnum, (char *) (vaddr + head + CMDSTART + 1));
5528 writeb(byte1, (char *) (vaddr + head + CMDSTART + 2));
5529 writeb(byte2, (char *) (vaddr + head + CMDSTART + 3));
5531 head = (head + 4) & (CMDMAX - CMDSTART - 4);
5533 writew(head, &(cm_addr->cm_head));
5536 * Wait if necessary before updating the head
5537 * pointer to limit the number of outstanding
5538 * commands to the FEP. If the time spent waiting
5539 * is outlandish, declare the FEP dead.
5541 for (count = dgap_count ;;) {
5543 head = readw(&(cm_addr->cm_head));
5544 tail = readw(&(cm_addr->cm_tail));
5546 n = (head - tail) & (CMDMAX - CMDSTART - 4);
5548 if (n <= ncmds * sizeof(struct cm_t))
5552 DPR_CORE(("%s:%d failing board.\n",__FILE__, __LINE__));
5553 ch->ch_bd->state = BOARD_FAILED;
5561 /*=======================================================================
5563 * dgap_cmdw - Sends a 1 word command to the FEP.
5565 * ch - Pointer to channel structure.
5566 * cmd - Command to be sent.
5567 * word - Integer containing word to be sent.
5568 * ncmds - Wait until ncmds or fewer cmds are left
5569 * in the cmd buffer before returning.
5571 *=======================================================================*/
5572 static void dgap_cmdw(struct channel_t *ch, uchar cmd, u16 word, uint ncmds)
5575 struct cm_t *cm_addr = NULL;
5581 if (!ch || ch->magic != DGAP_CHANNEL_MAGIC)
5585 * Check if board is still alive.
5587 if (ch->ch_bd->state == BOARD_FAILED) {
5588 DPR_CORE(("%s:%d board is failed!\n", __FILE__, __LINE__));
5593 * Make sure the pointers are in range before
5594 * writing to the FEP memory.
5596 vaddr = ch->ch_bd->re_map_membase;
5600 cm_addr = (struct cm_t *) (vaddr + CMDBUF);
5601 head = readw(&(cm_addr->cm_head));
5604 * Forget it if pointers out of range.
5606 if (head >= (CMDMAX - CMDSTART) || (head & 03)) {
5607 DPR_CORE(("%s:%d Pointers out of range. Failing board.\n",__FILE__, __LINE__));
5608 ch->ch_bd->state = BOARD_FAILED;
5613 * Put the data in the circular command buffer.
5615 writeb(cmd, (char *) (vaddr + head + CMDSTART + 0));
5616 writeb((uchar) ch->ch_portnum, (char *) (vaddr + head + CMDSTART + 1));
5617 writew((u16) word, (char *) (vaddr + head + CMDSTART + 2));
5619 head = (head + 4) & (CMDMAX - CMDSTART - 4);
5621 writew(head, &(cm_addr->cm_head));
5624 * Wait if necessary before updating the head
5625 * pointer to limit the number of outstanding
5626 * commands to the FEP. If the time spent waiting
5627 * is outlandish, declare the FEP dead.
5629 for (count = dgap_count ;;) {
5631 head = readw(&(cm_addr->cm_head));
5632 tail = readw(&(cm_addr->cm_tail));
5634 n = (head - tail) & (CMDMAX - CMDSTART - 4);
5636 if (n <= ncmds * sizeof(struct cm_t))
5640 DPR_CORE(("%s:%d Failing board.\n",__FILE__, __LINE__));
5641 ch->ch_bd->state = BOARD_FAILED;
5650 /*=======================================================================
5652 * dgap_cmdw_ext - Sends a extended word command to the FEP.
5654 * ch - Pointer to channel structure.
5655 * cmd - Command to be sent.
5656 * word - Integer containing word to be sent.
5657 * ncmds - Wait until ncmds or fewer cmds are left
5658 * in the cmd buffer before returning.
5660 *=======================================================================*/
5661 static void dgap_cmdw_ext(struct channel_t *ch, u16 cmd, u16 word, uint ncmds)
5664 struct cm_t *cm_addr = NULL;
5670 if (!ch || ch->magic != DGAP_CHANNEL_MAGIC)
5674 * Check if board is still alive.
5676 if (ch->ch_bd->state == BOARD_FAILED) {
5677 DPR_CORE(("%s:%d board is failed!\n", __FILE__, __LINE__));
5682 * Make sure the pointers are in range before
5683 * writing to the FEP memory.
5685 vaddr = ch->ch_bd->re_map_membase;
5689 cm_addr = (struct cm_t *) (vaddr + CMDBUF);
5690 head = readw(&(cm_addr->cm_head));
5693 * Forget it if pointers out of range.
5695 if (head >= (CMDMAX - CMDSTART) || (head & 03)) {
5696 DPR_CORE(("%s:%d Pointers out of range. Failing board.\n",__FILE__, __LINE__));
5697 ch->ch_bd->state = BOARD_FAILED;
5702 * Put the data in the circular command buffer.
5705 /* Write an FF to tell the FEP that we want an extended command */
5706 writeb((uchar) 0xff, (char *) (vaddr + head + CMDSTART + 0));
5708 writeb((uchar) ch->ch_portnum, (uchar *) (vaddr + head + CMDSTART + 1));
5709 writew((u16) cmd, (char *) (vaddr + head + CMDSTART + 2));
5712 * If the second part of the command won't fit,
5713 * put it at the beginning of the circular buffer.
5715 if (((head + 4) >= ((CMDMAX - CMDSTART)) || (head & 03))) {
5716 writew((u16) word, (char *) (vaddr + CMDSTART));
5718 writew((u16) word, (char *) (vaddr + head + CMDSTART + 4));
5721 head = (head + 8) & (CMDMAX - CMDSTART - 4);
5723 writew(head, &(cm_addr->cm_head));
5726 * Wait if necessary before updating the head
5727 * pointer to limit the number of outstanding
5728 * commands to the FEP. If the time spent waiting
5729 * is outlandish, declare the FEP dead.
5731 for (count = dgap_count ;;) {
5733 head = readw(&(cm_addr->cm_head));
5734 tail = readw(&(cm_addr->cm_tail));
5736 n = (head - tail) & (CMDMAX - CMDSTART - 4);
5738 if (n <= ncmds * sizeof(struct cm_t))
5742 DPR_CORE(("%s:%d Failing board.\n",__FILE__, __LINE__));
5743 ch->ch_bd->state = BOARD_FAILED;
5751 /*=======================================================================
5753 * dgap_wmove - Write data to FEP buffer.
5755 * ch - Pointer to channel structure.
5756 * buf - Poiter to characters to be moved.
5757 * cnt - Number of characters to move.
5759 *=======================================================================*/
5760 static void dgap_wmove(struct channel_t *ch, char *buf, uint cnt)
5767 if (!ch || ch->magic != DGAP_CHANNEL_MAGIC)
5774 head = readw(&(bs->tx_head));
5777 * If pointers are out of range, just return.
5779 if ((cnt > ch->ch_tsize) || (unsigned)(head - ch->ch_tstart) >= ch->ch_tsize) {
5780 DPR_CORE(("%s:%d pointer out of range", __FILE__, __LINE__));
5785 * If the write wraps over the top of the circular buffer,
5786 * move the portion up to the wrap point, and reset the
5787 * pointers to the bottom.
5789 n = ch->ch_tstart + ch->ch_tsize - head;
5793 taddr = ch->ch_taddr + head;
5794 memcpy_toio(taddr, buf, n);
5795 head = ch->ch_tstart;
5800 * Move rest of data.
5802 taddr = ch->ch_taddr + head;
5804 memcpy_toio(taddr, buf, n);
5807 writew(head, &(bs->tx_head));
5811 * Retrives the current custom baud rate from FEP memory,
5812 * and returns it back to the user.
5813 * Returns 0 on error.
5815 static uint dgap_get_custom_baud(struct channel_t *ch)
5821 if (!ch || ch->magic != DGAP_CHANNEL_MAGIC) {
5825 if (!ch->ch_bd || ch->ch_bd->magic != DGAP_BOARD_MAGIC) {
5829 if (!(ch->ch_bd->bd_flags & BD_FEP5PLUS))
5832 vaddr = ch->ch_bd->re_map_membase;
5838 * Go get from fep mem, what the fep
5839 * believes the custom baud rate is.
5841 offset = ((((*(unsigned short *)(vaddr + ECS_SEG)) << 4) +
5842 (ch->ch_portnum * 0x28) + LINE_SPEED));
5844 value = readw(vaddr + offset);
5850 * Calls the firmware to reset this channel.
5852 static void dgap_firmware_reset_port(struct channel_t *ch)
5854 dgap_cmdb(ch, CHRESET, 0, 0, 0);
5857 * Now that the channel is reset, we need to make sure
5858 * all the current settings get reapplied to the port
5861 * So we will set the driver's cache of firmware
5862 * settings all to 0, and then call param.
5864 ch->ch_fepiflag = 0;
5865 ch->ch_fepcflag = 0;
5866 ch->ch_fepoflag = 0;
5867 ch->ch_fepstartc = 0;
5868 ch->ch_fepstopc = 0;
5869 ch->ch_fepastartc = 0;
5870 ch->ch_fepastopc = 0;
5876 /*=======================================================================
5878 * dgap_param - Set Digi parameters.
5880 * struct tty_struct * - TTY for port.
5882 *=======================================================================*/
5883 static int dgap_param(struct tty_struct *tty)
5885 struct ktermios *ts;
5887 struct channel_t *ch;
5896 if (!tty || tty->magic != TTY_MAGIC)
5899 un = (struct un_t *) tty->driver_data;
5900 if (!un || un->magic != DGAP_UNIT_MAGIC)
5904 if (!ch || ch->magic != DGAP_CHANNEL_MAGIC)
5908 if (!bd || bd->magic != DGAP_BOARD_MAGIC)
5915 DPR_PARAM(("param start: tdev: %x cflags: %x oflags: %x iflags: %x\n",
5916 ch->ch_tun.un_dev, ch->ch_c_cflag, ch->ch_c_oflag, ch->ch_c_iflag));
5921 * If baud rate is zero, flush queues, and set mval to drop DTR.
5923 if ((ch->ch_c_cflag & (CBAUD)) == 0) {
5926 head = readw(&(ch->ch_bs->rx_head));
5927 writew(head, &(ch->ch_bs->rx_tail));
5930 head = readw(&(ch->ch_bs->tx_head));
5931 writew(head, &(ch->ch_bs->tx_tail));
5933 ch->ch_flags |= (CH_BAUD0);
5935 /* Drop RTS and DTR */
5936 ch->ch_mval &= ~(D_RTS(ch)|D_DTR(ch));
5937 mval = D_DTR(ch) | D_RTS(ch);
5938 ch->ch_baud_info = 0;
5940 } else if (ch->ch_custom_speed && (bd->bd_flags & BD_FEP5PLUS)) {
5942 * Tell the fep to do the command
5945 DPR_PARAM(("param: Want %d speed\n", ch->ch_custom_speed));
5947 dgap_cmdw_ext(ch, 0xff01, ch->ch_custom_speed, 0);
5950 * Now go get from fep mem, what the fep
5951 * believes the custom baud rate is.
5953 ch->ch_baud_info = ch->ch_custom_speed = dgap_get_custom_baud(ch);
5955 DPR_PARAM(("param: Got %d speed\n", ch->ch_custom_speed));
5957 /* Handle transition from B0 */
5958 if (ch->ch_flags & CH_BAUD0) {
5959 ch->ch_flags &= ~(CH_BAUD0);
5960 ch->ch_mval |= (D_RTS(ch)|D_DTR(ch));
5962 mval = D_DTR(ch) | D_RTS(ch);
5966 * Set baud rate, character size, and parity.
5974 ulong bauds[4][16] = {
5978 600, 1200, 1800, 2400,
5979 4800, 9600, 19200, 38400 },
5980 { /* slowbaud & CBAUDEX */
5981 0, 57600, 115200, 230400,
5982 460800, 150, 200, 921600,
5983 600, 1200, 1800, 2400,
5984 4800, 9600, 19200, 38400 },
5986 0, 57600, 76800, 115200,
5987 14400, 57600, 230400, 76800,
5988 115200, 230400, 28800, 460800,
5989 921600, 9600, 19200, 38400 },
5990 { /* fastbaud & CBAUDEX */
5991 0, 57600, 115200, 230400,
5992 460800, 150, 200, 921600,
5993 600, 1200, 1800, 2400,
5994 4800, 9600, 19200, 38400 }
5997 /* Only use the TXPrint baud rate if the terminal unit is NOT open */
5998 if (!(ch->ch_tun.un_flags & UN_ISOPEN) && (un->un_type == DGAP_PRINT))
5999 baud = C_BAUD(ch->ch_pun.un_tty) & 0xff;
6001 baud = C_BAUD(ch->ch_tun.un_tty) & 0xff;
6003 if (ch->ch_c_cflag & CBAUDEX)
6006 if (ch->ch_digi.digi_flags & DIGI_FAST)
6011 if ((iindex >= 0) && (iindex < 4) && (jindex >= 0) && (jindex < 16)) {
6012 baud = bauds[iindex][jindex];
6014 DPR_IOCTL(("baud indices were out of range (%d)(%d)",
6022 ch->ch_baud_info = baud;
6026 * CBAUD has bit position 0x1000 set these days to indicate Linux
6028 * We use a different bit assignment for high speed. Clear this
6029 * bit out while grabbing the parts of "cflag" we want.
6031 cflag = ch->ch_c_cflag & ((CBAUD ^ CBAUDEX) | PARODD | PARENB | CSTOPB | CSIZE);
6034 * HUPCL bit is used by FEP to indicate fast baud
6035 * table is to be used.
6037 if ((ch->ch_digi.digi_flags & DIGI_FAST) || (ch->ch_c_cflag & CBAUDEX))
6041 if ((ch->ch_c_cflag & CBAUDEX) && !(ch->ch_digi.digi_flags & DIGI_FAST)) {
6043 * The below code is trying to guarantee that only baud rates
6044 * 115200, 230400, 460800, 921600 are remapped. We use exclusive or
6045 * because the various baud rates share common bit positions
6046 * and therefore can't be tested for easily.
6048 tcflag_t tcflag = (ch->ch_c_cflag & CBAUD) | CBAUDEX;
6051 /* Map high speed requests to index into FEP's baud table */
6080 cflag = (cflag & ~(CBAUD | CBAUDEX)) | baudpart;
6085 if (cflag != ch->ch_fepcflag) {
6086 ch->ch_fepcflag = (u16) (cflag & 0xffff);
6088 /* Okay to have channel and board locks held calling this */
6089 dgap_cmdw(ch, SCFLAG, (u16) cflag, 0);
6092 /* Handle transition from B0 */
6093 if (ch->ch_flags & CH_BAUD0) {
6094 ch->ch_flags &= ~(CH_BAUD0);
6095 ch->ch_mval |= (D_RTS(ch)|D_DTR(ch));
6097 mval = D_DTR(ch) | D_RTS(ch);
6103 iflag = ch->ch_c_iflag & (IGNBRK | BRKINT | IGNPAR | PARMRK | INPCK | ISTRIP | IXON | IXANY | IXOFF);
6105 if ((ch->ch_startc == _POSIX_VDISABLE) || (ch->ch_stopc == _POSIX_VDISABLE)) {
6106 iflag &= ~(IXON | IXOFF);
6107 ch->ch_c_iflag &= ~(IXON | IXOFF);
6111 * Only the IBM Xr card can switch between
6112 * 232 and 422 modes on the fly
6114 if (bd->device == PCI_DEVICE_XR_IBM_DID) {
6115 if (ch->ch_digi.digi_flags & DIGI_422)
6116 dgap_cmdb(ch, SCOMMODE, MODE_422, 0, 0);
6118 dgap_cmdb(ch, SCOMMODE, MODE_232, 0, 0);
6121 if (ch->ch_digi.digi_flags & DIGI_ALTPIN)
6124 if (iflag != ch->ch_fepiflag) {
6125 ch->ch_fepiflag = iflag;
6127 /* Okay to have channel and board locks held calling this */
6128 dgap_cmdw(ch, SIFLAG, (u16) ch->ch_fepiflag, 0);
6132 * Select hardware handshaking.
6136 if (ch->ch_c_cflag & CRTSCTS) {
6137 hflow |= (D_RTS(ch) | D_CTS(ch));
6139 if (ch->ch_digi.digi_flags & RTSPACE)
6141 if (ch->ch_digi.digi_flags & DTRPACE)
6143 if (ch->ch_digi.digi_flags & CTSPACE)
6145 if (ch->ch_digi.digi_flags & DSRPACE)
6147 if (ch->ch_digi.digi_flags & DCDPACE)
6150 if (hflow != ch->ch_hflow) {
6151 ch->ch_hflow = hflow;
6153 /* Okay to have channel and board locks held calling this */
6154 dgap_cmdb(ch, SHFLOW, (uchar) hflow, 0xff, 0);
6159 * Set RTS and/or DTR Toggle if needed, but only if product is FEP5+ based.
6161 if (bd->bd_flags & BD_FEP5PLUS) {
6163 if (ch->ch_digi.digi_flags & DIGI_RTS_TOGGLE) {
6164 hflow2 |= (D_RTS(ch));
6166 if (ch->ch_digi.digi_flags & DIGI_DTR_TOGGLE) {
6167 hflow2 |= (D_DTR(ch));
6170 dgap_cmdw_ext(ch, 0xff03, hflow2, 0);
6174 * Set modem control lines.
6177 mval ^= ch->ch_mforce & (mval ^ ch->ch_mval);
6179 DPR_PARAM(("dgap_param: mval: %x ch_mforce: %x ch_mval: %x ch_mostat: %x\n",
6180 mval, ch->ch_mforce, ch->ch_mval, ch->ch_mostat));
6182 if (ch->ch_mostat ^ mval) {
6183 ch->ch_mostat = mval;
6185 /* Okay to have channel and board locks held calling this */
6186 DPR_PARAM(("dgap_param: Sending SMODEM mval: %x\n", mval));
6187 dgap_cmdb(ch, SMODEM, (uchar) mval, D_RTS(ch)|D_DTR(ch), 0);
6191 * Read modem signals, and then call carrier function.
6193 ch->ch_mistat = readb(&(bs->m_stat));
6197 * Set the start and stop characters.
6199 if (ch->ch_startc != ch->ch_fepstartc || ch->ch_stopc != ch->ch_fepstopc) {
6200 ch->ch_fepstartc = ch->ch_startc;
6201 ch->ch_fepstopc = ch->ch_stopc;
6203 /* Okay to have channel and board locks held calling this */
6204 dgap_cmdb(ch, SFLOWC, ch->ch_fepstartc, ch->ch_fepstopc, 0);
6208 * Set the Auxiliary start and stop characters.
6210 if (ch->ch_astartc != ch->ch_fepastartc || ch->ch_astopc != ch->ch_fepastopc) {
6211 ch->ch_fepastartc = ch->ch_astartc;
6212 ch->ch_fepastopc = ch->ch_astopc;
6214 /* Okay to have channel and board locks held calling this */
6215 dgap_cmdb(ch, SAFLOWC, ch->ch_fepastartc, ch->ch_fepastopc, 0);
6218 DPR_PARAM(("param finish\n"));
6225 * dgap_parity_scan()
6227 * Convert the FEP5 way of reporting parity errors and breaks into
6228 * the Linux line discipline way.
6230 static void dgap_parity_scan(struct channel_t *ch, unsigned char *cbuf, unsigned char *fbuf, int *len)
6234 unsigned char *in, *cout, *fout;
6241 DPR_PSCAN(("dgap_parity_scan start\n"));
6243 if (!ch || ch->magic != DGAP_CHANNEL_MAGIC)
6248 switch (ch->pscan_state) {
6250 /* reset to sanity and fall through */
6251 ch->pscan_state = 0;
6254 /* No FF seen yet */
6255 if (c == (unsigned char) '\377') {
6256 /* delete this character from stream */
6257 ch->pscan_state = 1;
6260 *fout++ = TTY_NORMAL;
6267 if (c == (unsigned char) '\377') {
6268 /* doubled ff, transform to single ff */
6270 *fout++ = TTY_NORMAL;
6272 ch->pscan_state = 0;
6274 /* save value examination in next state */
6275 ch->pscan_savechar = c;
6276 ch->pscan_state = 2;
6281 /* third character of ff sequence */
6285 if (ch->pscan_savechar == 0x0) {
6288 DPR_PSCAN(("dgap_parity_scan in 3rd char of ff seq. c: %x setting break.\n", c));
6290 *fout++ = TTY_BREAK;
6293 DPR_PSCAN(("dgap_parity_scan in 3rd char of ff seq. c: %x setting parity.\n", c));
6294 ch->ch_err_parity++;
6295 *fout++ = TTY_PARITY;
6299 DPR_PSCAN(("%s:%d Logic Error.\n", __FILE__, __LINE__));
6303 ch->pscan_state = 0;
6307 DPR_PSCAN(("dgap_parity_scan finish\n"));
6313 /*=======================================================================
6315 * dgap_event - FEP to host event processing routine.
6317 * bd - Board of current event.
6319 *=======================================================================*/
6320 static int dgap_event(struct board_t *bd)
6322 struct channel_t *ch;
6327 uchar *vaddr = NULL;
6328 struct ev_t *eaddr = NULL;
6336 if (!bd || bd->magic != DGAP_BOARD_MAGIC)
6339 DGAP_LOCK(bd->bd_lock, lock_flags);
6341 vaddr = bd->re_map_membase;
6344 DGAP_UNLOCK(bd->bd_lock, lock_flags);
6348 eaddr = (struct ev_t *) (vaddr + EVBUF);
6350 /* Get our head and tail */
6351 head = readw(&(eaddr->ev_head));
6352 tail = readw(&(eaddr->ev_tail));
6355 * Forget it if pointers out of range.
6358 if (head >= EVMAX - EVSTART || tail >= EVMAX - EVSTART ||
6359 (head | tail) & 03) {
6360 DPR_EVENT(("should be calling xxfail %d\n", __LINE__));
6361 /* Let go of board lock */
6362 DGAP_UNLOCK(bd->bd_lock, lock_flags);
6367 * Loop to process all the events in the buffer.
6369 while (tail != head) {
6372 * Get interrupt information.
6375 event = bd->re_map_membase + tail + EVSTART;
6382 DPR_EVENT(("event: jiffies: %ld port: %d reason: %x modem: %x\n",
6383 jiffies, port, reason, modem));
6386 * Make sure the interrupt is valid.
6388 if (port >= bd->nasync)
6391 if (!(reason & (IFMODEM | IFBREAK | IFTLW | IFTEM | IFDATA))) {
6395 ch = bd->channels[port];
6397 if (!ch || ch->magic != DGAP_CHANNEL_MAGIC) {
6402 * If we have made it here, the event was valid.
6403 * Lock down the channel.
6405 DGAP_LOCK(ch->ch_lock, lock_flags2);
6410 DGAP_UNLOCK(ch->ch_lock, lock_flags2);
6415 * Process received data.
6417 if (reason & IFDATA) {
6420 * ALL LOCKS *MUST* BE DROPPED BEFORE CALLING INPUT!
6421 * input could send some data to ld, which in turn
6422 * could do a callback to one of our other functions.
6424 DGAP_UNLOCK(ch->ch_lock, lock_flags2);
6425 DGAP_UNLOCK(bd->bd_lock, lock_flags);
6429 DGAP_LOCK(bd->bd_lock, lock_flags);
6430 DGAP_LOCK(ch->ch_lock, lock_flags2);
6432 if (ch->ch_flags & CH_RACTIVE)
6433 ch->ch_flags |= CH_RENABLE;
6435 writeb(1, &(bs->idata));
6437 if (ch->ch_flags & CH_RWAIT) {
6438 ch->ch_flags &= ~CH_RWAIT;
6440 wake_up_interruptible(&ch->ch_tun.un_flags_wait);
6445 * Process Modem change signals.
6447 if (reason & IFMODEM) {
6448 ch->ch_mistat = modem;
6455 if (reason & IFBREAK) {
6457 DPR_EVENT(("got IFBREAK\n"));
6459 if (ch->ch_tun.un_tty) {
6460 /* A break has been indicated */
6462 tty_buffer_request_room(ch->ch_tun.un_tty->port, 1);
6463 tty_insert_flip_char(ch->ch_tun.un_tty->port, 0, TTY_BREAK);
6464 tty_flip_buffer_push(ch->ch_tun.un_tty->port);
6469 * Process Transmit low.
6471 if (reason & IFTLW) {
6473 DPR_EVENT(("event: got low event\n"));
6475 if (ch->ch_tun.un_flags & UN_LOW) {
6476 ch->ch_tun.un_flags &= ~UN_LOW;
6478 if (ch->ch_tun.un_flags & UN_ISOPEN) {
6479 if ((ch->ch_tun.un_tty->flags &
6480 (1 << TTY_DO_WRITE_WAKEUP)) &&
6481 ch->ch_tun.un_tty->ldisc->ops->write_wakeup)
6483 DGAP_UNLOCK(ch->ch_lock, lock_flags2);
6484 DGAP_UNLOCK(bd->bd_lock, lock_flags);
6485 (ch->ch_tun.un_tty->ldisc->ops->write_wakeup)(ch->ch_tun.un_tty);
6486 DGAP_LOCK(bd->bd_lock, lock_flags);
6487 DGAP_LOCK(ch->ch_lock, lock_flags2);
6489 wake_up_interruptible(&ch->ch_tun.un_tty->write_wait);
6490 wake_up_interruptible(&ch->ch_tun.un_flags_wait);
6492 DPR_EVENT(("event: Got low event. jiffies: %lu\n", jiffies));
6496 if (ch->ch_pun.un_flags & UN_LOW) {
6497 ch->ch_pun.un_flags &= ~UN_LOW;
6498 if (ch->ch_pun.un_flags & UN_ISOPEN) {
6499 if ((ch->ch_pun.un_tty->flags &
6500 (1 << TTY_DO_WRITE_WAKEUP)) &&
6501 ch->ch_pun.un_tty->ldisc->ops->write_wakeup)
6503 DGAP_UNLOCK(ch->ch_lock, lock_flags2);
6504 DGAP_UNLOCK(bd->bd_lock, lock_flags);
6505 (ch->ch_pun.un_tty->ldisc->ops->write_wakeup)(ch->ch_pun.un_tty);
6506 DGAP_LOCK(bd->bd_lock, lock_flags);
6507 DGAP_LOCK(ch->ch_lock, lock_flags2);
6509 wake_up_interruptible(&ch->ch_pun.un_tty->write_wait);
6510 wake_up_interruptible(&ch->ch_pun.un_flags_wait);
6514 if (ch->ch_flags & CH_WLOW) {
6515 ch->ch_flags &= ~CH_WLOW;
6516 wake_up_interruptible(&ch->ch_flags_wait);
6521 * Process Transmit empty.
6523 if (reason & IFTEM) {
6524 DPR_EVENT(("event: got empty event\n"));
6526 if (ch->ch_tun.un_flags & UN_EMPTY) {
6527 ch->ch_tun.un_flags &= ~UN_EMPTY;
6528 if (ch->ch_tun.un_flags & UN_ISOPEN) {
6529 if ((ch->ch_tun.un_tty->flags &
6530 (1 << TTY_DO_WRITE_WAKEUP)) &&
6531 ch->ch_tun.un_tty->ldisc->ops->write_wakeup)
6533 DGAP_UNLOCK(ch->ch_lock, lock_flags2);
6534 DGAP_UNLOCK(bd->bd_lock, lock_flags);
6536 (ch->ch_tun.un_tty->ldisc->ops->write_wakeup)(ch->ch_tun.un_tty);
6537 DGAP_LOCK(bd->bd_lock, lock_flags);
6538 DGAP_LOCK(ch->ch_lock, lock_flags2);
6540 wake_up_interruptible(&ch->ch_tun.un_tty->write_wait);
6541 wake_up_interruptible(&ch->ch_tun.un_flags_wait);
6545 if (ch->ch_pun.un_flags & UN_EMPTY) {
6546 ch->ch_pun.un_flags &= ~UN_EMPTY;
6547 if (ch->ch_pun.un_flags & UN_ISOPEN) {
6548 if ((ch->ch_pun.un_tty->flags &
6549 (1 << TTY_DO_WRITE_WAKEUP)) &&
6550 ch->ch_pun.un_tty->ldisc->ops->write_wakeup)
6552 DGAP_UNLOCK(ch->ch_lock, lock_flags2);
6553 DGAP_UNLOCK(bd->bd_lock, lock_flags);
6554 (ch->ch_pun.un_tty->ldisc->ops->write_wakeup)(ch->ch_pun.un_tty);
6555 DGAP_LOCK(bd->bd_lock, lock_flags);
6556 DGAP_LOCK(ch->ch_lock, lock_flags2);
6558 wake_up_interruptible(&ch->ch_pun.un_tty->write_wait);
6559 wake_up_interruptible(&ch->ch_pun.un_flags_wait);
6564 if (ch->ch_flags & CH_WEMPTY) {
6565 ch->ch_flags &= ~CH_WEMPTY;
6566 wake_up_interruptible(&ch->ch_flags_wait);
6570 DGAP_UNLOCK(ch->ch_lock, lock_flags2);
6573 tail = (tail + 4) & (EVMAX - EVSTART - 4);
6576 writew(tail, &(eaddr->ev_tail));
6577 DGAP_UNLOCK(bd->bd_lock, lock_flags);
6582 static ssize_t dgap_driver_version_show(struct device_driver *ddp, char *buf)
6584 return snprintf(buf, PAGE_SIZE, "%s\n", DG_PART);
6586 static DRIVER_ATTR(version, S_IRUSR, dgap_driver_version_show, NULL);
6589 static ssize_t dgap_driver_boards_show(struct device_driver *ddp, char *buf)
6591 return snprintf(buf, PAGE_SIZE, "%d\n", dgap_NumBoards);
6593 static DRIVER_ATTR(boards, S_IRUSR, dgap_driver_boards_show, NULL);
6596 static ssize_t dgap_driver_maxboards_show(struct device_driver *ddp, char *buf)
6598 return snprintf(buf, PAGE_SIZE, "%d\n", MAXBOARDS);
6600 static DRIVER_ATTR(maxboards, S_IRUSR, dgap_driver_maxboards_show, NULL);
6603 static ssize_t dgap_driver_pollcounter_show(struct device_driver *ddp, char *buf)
6605 return snprintf(buf, PAGE_SIZE, "%ld\n", dgap_poll_counter);
6607 static DRIVER_ATTR(pollcounter, S_IRUSR, dgap_driver_pollcounter_show, NULL);
6610 static ssize_t dgap_driver_state_show(struct device_driver *ddp, char *buf)
6612 return snprintf(buf, PAGE_SIZE, "%s\n", dgap_driver_state_text[dgap_driver_state]);
6614 static DRIVER_ATTR(state, S_IRUSR, dgap_driver_state_show, NULL);
6617 static ssize_t dgap_driver_debug_show(struct device_driver *ddp, char *buf)
6619 return snprintf(buf, PAGE_SIZE, "0x%x\n", dgap_debug);
6622 static ssize_t dgap_driver_debug_store(struct device_driver *ddp, const char *buf, size_t count)
6624 sscanf(buf, "0x%x\n", &dgap_debug);
6627 static DRIVER_ATTR(debug, (S_IRUSR | S_IWUSR), dgap_driver_debug_show, dgap_driver_debug_store);
6630 static ssize_t dgap_driver_rawreadok_show(struct device_driver *ddp, char *buf)
6632 return snprintf(buf, PAGE_SIZE, "0x%x\n", dgap_rawreadok);
6635 static ssize_t dgap_driver_rawreadok_store(struct device_driver *ddp, const char *buf, size_t count)
6637 sscanf(buf, "0x%x\n", &dgap_rawreadok);
6640 static DRIVER_ATTR(rawreadok, (S_IRUSR | S_IWUSR), dgap_driver_rawreadok_show, dgap_driver_rawreadok_store);
6643 static ssize_t dgap_driver_pollrate_show(struct device_driver *ddp, char *buf)
6645 return snprintf(buf, PAGE_SIZE, "%dms\n", dgap_poll_tick);
6648 static ssize_t dgap_driver_pollrate_store(struct device_driver *ddp, const char *buf, size_t count)
6650 sscanf(buf, "%d\n", &dgap_poll_tick);
6653 static DRIVER_ATTR(pollrate, (S_IRUSR | S_IWUSR), dgap_driver_pollrate_show, dgap_driver_pollrate_store);
6656 static void dgap_create_driver_sysfiles(struct pci_driver *dgap_driver)
6659 struct device_driver *driverfs = &dgap_driver->driver;
6661 rc |= driver_create_file(driverfs, &driver_attr_version);
6662 rc |= driver_create_file(driverfs, &driver_attr_boards);
6663 rc |= driver_create_file(driverfs, &driver_attr_maxboards);
6664 rc |= driver_create_file(driverfs, &driver_attr_debug);
6665 rc |= driver_create_file(driverfs, &driver_attr_rawreadok);
6666 rc |= driver_create_file(driverfs, &driver_attr_pollrate);
6667 rc |= driver_create_file(driverfs, &driver_attr_pollcounter);
6668 rc |= driver_create_file(driverfs, &driver_attr_state);
6670 printk(KERN_ERR "DGAP: sysfs driver_create_file failed!\n");
6675 static void dgap_remove_driver_sysfiles(struct pci_driver *dgap_driver)
6677 struct device_driver *driverfs = &dgap_driver->driver;
6678 driver_remove_file(driverfs, &driver_attr_version);
6679 driver_remove_file(driverfs, &driver_attr_boards);
6680 driver_remove_file(driverfs, &driver_attr_maxboards);
6681 driver_remove_file(driverfs, &driver_attr_debug);
6682 driver_remove_file(driverfs, &driver_attr_rawreadok);
6683 driver_remove_file(driverfs, &driver_attr_pollrate);
6684 driver_remove_file(driverfs, &driver_attr_pollcounter);
6685 driver_remove_file(driverfs, &driver_attr_state);
6689 #define DGAP_VERIFY_BOARD(p, bd) \
6693 bd = dev_get_drvdata(p); \
6694 if (!bd || bd->magic != DGAP_BOARD_MAGIC) \
6696 if (bd->state != BOARD_READY) \
6700 static ssize_t dgap_ports_state_show(struct device *p, struct device_attribute *attr, char *buf)
6706 DGAP_VERIFY_BOARD(p, bd);
6708 for (i = 0; i < bd->nasync; i++) {
6709 count += snprintf(buf + count, PAGE_SIZE - count,
6710 "%d %s\n", bd->channels[i]->ch_portnum,
6711 bd->channels[i]->ch_open_count ? "Open" : "Closed");
6715 static DEVICE_ATTR(ports_state, S_IRUSR, dgap_ports_state_show, NULL);
6718 static ssize_t dgap_ports_baud_show(struct device *p, struct device_attribute *attr, char *buf)
6724 DGAP_VERIFY_BOARD(p, bd);
6726 for (i = 0; i < bd->nasync; i++) {
6727 count += snprintf(buf + count, PAGE_SIZE - count,
6728 "%d %d\n", bd->channels[i]->ch_portnum, bd->channels[i]->ch_baud_info);
6732 static DEVICE_ATTR(ports_baud, S_IRUSR, dgap_ports_baud_show, NULL);
6735 static ssize_t dgap_ports_msignals_show(struct device *p, struct device_attribute *attr, char *buf)
6741 DGAP_VERIFY_BOARD(p, bd);
6743 for (i = 0; i < bd->nasync; i++) {
6744 if (bd->channels[i]->ch_open_count) {
6745 count += snprintf(buf + count, PAGE_SIZE - count,
6746 "%d %s %s %s %s %s %s\n", bd->channels[i]->ch_portnum,
6747 (bd->channels[i]->ch_mostat & UART_MCR_RTS) ? "RTS" : "",
6748 (bd->channels[i]->ch_mistat & UART_MSR_CTS) ? "CTS" : "",
6749 (bd->channels[i]->ch_mostat & UART_MCR_DTR) ? "DTR" : "",
6750 (bd->channels[i]->ch_mistat & UART_MSR_DSR) ? "DSR" : "",
6751 (bd->channels[i]->ch_mistat & UART_MSR_DCD) ? "DCD" : "",
6752 (bd->channels[i]->ch_mistat & UART_MSR_RI) ? "RI" : "");
6754 count += snprintf(buf + count, PAGE_SIZE - count,
6755 "%d\n", bd->channels[i]->ch_portnum);
6760 static DEVICE_ATTR(ports_msignals, S_IRUSR, dgap_ports_msignals_show, NULL);
6763 static ssize_t dgap_ports_iflag_show(struct device *p, struct device_attribute *attr, char *buf)
6769 DGAP_VERIFY_BOARD(p, bd);
6771 for (i = 0; i < bd->nasync; i++) {
6772 count += snprintf(buf + count, PAGE_SIZE - count, "%d %x\n",
6773 bd->channels[i]->ch_portnum, bd->channels[i]->ch_c_iflag);
6777 static DEVICE_ATTR(ports_iflag, S_IRUSR, dgap_ports_iflag_show, NULL);
6780 static ssize_t dgap_ports_cflag_show(struct device *p, struct device_attribute *attr, char *buf)
6786 DGAP_VERIFY_BOARD(p, bd);
6788 for (i = 0; i < bd->nasync; i++) {
6789 count += snprintf(buf + count, PAGE_SIZE - count, "%d %x\n",
6790 bd->channels[i]->ch_portnum, bd->channels[i]->ch_c_cflag);
6794 static DEVICE_ATTR(ports_cflag, S_IRUSR, dgap_ports_cflag_show, NULL);
6797 static ssize_t dgap_ports_oflag_show(struct device *p, struct device_attribute *attr, char *buf)
6803 DGAP_VERIFY_BOARD(p, bd);
6805 for (i = 0; i < bd->nasync; i++) {
6806 count += snprintf(buf + count, PAGE_SIZE - count, "%d %x\n",
6807 bd->channels[i]->ch_portnum, bd->channels[i]->ch_c_oflag);
6811 static DEVICE_ATTR(ports_oflag, S_IRUSR, dgap_ports_oflag_show, NULL);
6814 static ssize_t dgap_ports_lflag_show(struct device *p, struct device_attribute *attr, char *buf)
6820 DGAP_VERIFY_BOARD(p, bd);
6822 for (i = 0; i < bd->nasync; i++) {
6823 count += snprintf(buf + count, PAGE_SIZE - count, "%d %x\n",
6824 bd->channels[i]->ch_portnum, bd->channels[i]->ch_c_lflag);
6828 static DEVICE_ATTR(ports_lflag, S_IRUSR, dgap_ports_lflag_show, NULL);
6831 static ssize_t dgap_ports_digi_flag_show(struct device *p, struct device_attribute *attr, char *buf)
6837 DGAP_VERIFY_BOARD(p, bd);
6839 for (i = 0; i < bd->nasync; i++) {
6840 count += snprintf(buf + count, PAGE_SIZE - count, "%d %x\n",
6841 bd->channels[i]->ch_portnum, bd->channels[i]->ch_digi.digi_flags);
6845 static DEVICE_ATTR(ports_digi_flag, S_IRUSR, dgap_ports_digi_flag_show, NULL);
6848 static ssize_t dgap_ports_rxcount_show(struct device *p, struct device_attribute *attr, char *buf)
6854 DGAP_VERIFY_BOARD(p, bd);
6856 for (i = 0; i < bd->nasync; i++) {
6857 count += snprintf(buf + count, PAGE_SIZE - count, "%d %ld\n",
6858 bd->channels[i]->ch_portnum, bd->channels[i]->ch_rxcount);
6862 static DEVICE_ATTR(ports_rxcount, S_IRUSR, dgap_ports_rxcount_show, NULL);
6865 static ssize_t dgap_ports_txcount_show(struct device *p, struct device_attribute *attr, char *buf)
6871 DGAP_VERIFY_BOARD(p, bd);
6873 for (i = 0; i < bd->nasync; i++) {
6874 count += snprintf(buf + count, PAGE_SIZE - count, "%d %ld\n",
6875 bd->channels[i]->ch_portnum, bd->channels[i]->ch_txcount);
6879 static DEVICE_ATTR(ports_txcount, S_IRUSR, dgap_ports_txcount_show, NULL);
6882 /* this function creates the sys files that will export each signal status
6883 * to sysfs each value will be put in a separate filename
6885 static void dgap_create_ports_sysfiles(struct board_t *bd)
6889 dev_set_drvdata(&bd->pdev->dev, bd);
6890 rc |= device_create_file(&(bd->pdev->dev), &dev_attr_ports_state);
6891 rc |= device_create_file(&(bd->pdev->dev), &dev_attr_ports_baud);
6892 rc |= device_create_file(&(bd->pdev->dev), &dev_attr_ports_msignals);
6893 rc |= device_create_file(&(bd->pdev->dev), &dev_attr_ports_iflag);
6894 rc |= device_create_file(&(bd->pdev->dev), &dev_attr_ports_cflag);
6895 rc |= device_create_file(&(bd->pdev->dev), &dev_attr_ports_oflag);
6896 rc |= device_create_file(&(bd->pdev->dev), &dev_attr_ports_lflag);
6897 rc |= device_create_file(&(bd->pdev->dev), &dev_attr_ports_digi_flag);
6898 rc |= device_create_file(&(bd->pdev->dev), &dev_attr_ports_rxcount);
6899 rc |= device_create_file(&(bd->pdev->dev), &dev_attr_ports_txcount);
6901 printk(KERN_ERR "DGAP: sysfs device_create_file failed!\n");
6906 /* removes all the sys files created for that port */
6907 static void dgap_remove_ports_sysfiles(struct board_t *bd)
6909 device_remove_file(&(bd->pdev->dev), &dev_attr_ports_state);
6910 device_remove_file(&(bd->pdev->dev), &dev_attr_ports_baud);
6911 device_remove_file(&(bd->pdev->dev), &dev_attr_ports_msignals);
6912 device_remove_file(&(bd->pdev->dev), &dev_attr_ports_iflag);
6913 device_remove_file(&(bd->pdev->dev), &dev_attr_ports_cflag);
6914 device_remove_file(&(bd->pdev->dev), &dev_attr_ports_oflag);
6915 device_remove_file(&(bd->pdev->dev), &dev_attr_ports_lflag);
6916 device_remove_file(&(bd->pdev->dev), &dev_attr_ports_digi_flag);
6917 device_remove_file(&(bd->pdev->dev), &dev_attr_ports_rxcount);
6918 device_remove_file(&(bd->pdev->dev), &dev_attr_ports_txcount);
6922 static ssize_t dgap_tty_state_show(struct device *d, struct device_attribute *attr, char *buf)
6925 struct channel_t *ch;
6930 un = dev_get_drvdata(d);
6931 if (!un || un->magic != DGAP_UNIT_MAGIC)
6934 if (!ch || ch->magic != DGAP_CHANNEL_MAGIC)
6937 if (!bd || bd->magic != DGAP_BOARD_MAGIC)
6939 if (bd->state != BOARD_READY)
6942 return snprintf(buf, PAGE_SIZE, "%s", un->un_open_count ? "Open" : "Closed");
6944 static DEVICE_ATTR(state, S_IRUSR, dgap_tty_state_show, NULL);
6947 static ssize_t dgap_tty_baud_show(struct device *d, struct device_attribute *attr, char *buf)
6950 struct channel_t *ch;
6955 un = dev_get_drvdata(d);
6956 if (!un || un->magic != DGAP_UNIT_MAGIC)
6959 if (!ch || ch->magic != DGAP_CHANNEL_MAGIC)
6962 if (!bd || bd->magic != DGAP_BOARD_MAGIC)
6964 if (bd->state != BOARD_READY)
6967 return snprintf(buf, PAGE_SIZE, "%d\n", ch->ch_baud_info);
6969 static DEVICE_ATTR(baud, S_IRUSR, dgap_tty_baud_show, NULL);
6972 static ssize_t dgap_tty_msignals_show(struct device *d, struct device_attribute *attr, char *buf)
6975 struct channel_t *ch;
6980 un = dev_get_drvdata(d);
6981 if (!un || un->magic != DGAP_UNIT_MAGIC)
6984 if (!ch || ch->magic != DGAP_CHANNEL_MAGIC)
6987 if (!bd || bd->magic != DGAP_BOARD_MAGIC)
6989 if (bd->state != BOARD_READY)
6992 if (ch->ch_open_count) {
6993 return snprintf(buf, PAGE_SIZE, "%s %s %s %s %s %s\n",
6994 (ch->ch_mostat & UART_MCR_RTS) ? "RTS" : "",
6995 (ch->ch_mistat & UART_MSR_CTS) ? "CTS" : "",
6996 (ch->ch_mostat & UART_MCR_DTR) ? "DTR" : "",
6997 (ch->ch_mistat & UART_MSR_DSR) ? "DSR" : "",
6998 (ch->ch_mistat & UART_MSR_DCD) ? "DCD" : "",
6999 (ch->ch_mistat & UART_MSR_RI) ? "RI" : "");
7003 static DEVICE_ATTR(msignals, S_IRUSR, dgap_tty_msignals_show, NULL);
7006 static ssize_t dgap_tty_iflag_show(struct device *d, struct device_attribute *attr, char *buf)
7009 struct channel_t *ch;
7014 un = dev_get_drvdata(d);
7015 if (!un || un->magic != DGAP_UNIT_MAGIC)
7018 if (!ch || ch->magic != DGAP_CHANNEL_MAGIC)
7021 if (!bd || bd->magic != DGAP_BOARD_MAGIC)
7023 if (bd->state != BOARD_READY)
7026 return snprintf(buf, PAGE_SIZE, "%x\n", ch->ch_c_iflag);
7028 static DEVICE_ATTR(iflag, S_IRUSR, dgap_tty_iflag_show, NULL);
7031 static ssize_t dgap_tty_cflag_show(struct device *d, struct device_attribute *attr, char *buf)
7034 struct channel_t *ch;
7039 un = dev_get_drvdata(d);
7040 if (!un || un->magic != DGAP_UNIT_MAGIC)
7043 if (!ch || ch->magic != DGAP_CHANNEL_MAGIC)
7046 if (!bd || bd->magic != DGAP_BOARD_MAGIC)
7048 if (bd->state != BOARD_READY)
7051 return snprintf(buf, PAGE_SIZE, "%x\n", ch->ch_c_cflag);
7053 static DEVICE_ATTR(cflag, S_IRUSR, dgap_tty_cflag_show, NULL);
7056 static ssize_t dgap_tty_oflag_show(struct device *d, struct device_attribute *attr, char *buf)
7059 struct channel_t *ch;
7064 un = dev_get_drvdata(d);
7065 if (!un || un->magic != DGAP_UNIT_MAGIC)
7068 if (!ch || ch->magic != DGAP_CHANNEL_MAGIC)
7071 if (!bd || bd->magic != DGAP_BOARD_MAGIC)
7073 if (bd->state != BOARD_READY)
7076 return snprintf(buf, PAGE_SIZE, "%x\n", ch->ch_c_oflag);
7078 static DEVICE_ATTR(oflag, S_IRUSR, dgap_tty_oflag_show, NULL);
7081 static ssize_t dgap_tty_lflag_show(struct device *d, struct device_attribute *attr, char *buf)
7084 struct channel_t *ch;
7089 un = dev_get_drvdata(d);
7090 if (!un || un->magic != DGAP_UNIT_MAGIC)
7093 if (!ch || ch->magic != DGAP_CHANNEL_MAGIC)
7096 if (!bd || bd->magic != DGAP_BOARD_MAGIC)
7098 if (bd->state != BOARD_READY)
7101 return snprintf(buf, PAGE_SIZE, "%x\n", ch->ch_c_lflag);
7103 static DEVICE_ATTR(lflag, S_IRUSR, dgap_tty_lflag_show, NULL);
7106 static ssize_t dgap_tty_digi_flag_show(struct device *d, struct device_attribute *attr, char *buf)
7109 struct channel_t *ch;
7114 un = dev_get_drvdata(d);
7115 if (!un || un->magic != DGAP_UNIT_MAGIC)
7118 if (!ch || ch->magic != DGAP_CHANNEL_MAGIC)
7121 if (!bd || bd->magic != DGAP_BOARD_MAGIC)
7123 if (bd->state != BOARD_READY)
7126 return snprintf(buf, PAGE_SIZE, "%x\n", ch->ch_digi.digi_flags);
7128 static DEVICE_ATTR(digi_flag, S_IRUSR, dgap_tty_digi_flag_show, NULL);
7131 static ssize_t dgap_tty_rxcount_show(struct device *d, struct device_attribute *attr, char *buf)
7134 struct channel_t *ch;
7139 un = dev_get_drvdata(d);
7140 if (!un || un->magic != DGAP_UNIT_MAGIC)
7143 if (!ch || ch->magic != DGAP_CHANNEL_MAGIC)
7146 if (!bd || bd->magic != DGAP_BOARD_MAGIC)
7148 if (bd->state != BOARD_READY)
7151 return snprintf(buf, PAGE_SIZE, "%ld\n", ch->ch_rxcount);
7153 static DEVICE_ATTR(rxcount, S_IRUSR, dgap_tty_rxcount_show, NULL);
7156 static ssize_t dgap_tty_txcount_show(struct device *d, struct device_attribute *attr, char *buf)
7159 struct channel_t *ch;
7164 un = dev_get_drvdata(d);
7165 if (!un || un->magic != DGAP_UNIT_MAGIC)
7168 if (!ch || ch->magic != DGAP_CHANNEL_MAGIC)
7171 if (!bd || bd->magic != DGAP_BOARD_MAGIC)
7173 if (bd->state != BOARD_READY)
7176 return snprintf(buf, PAGE_SIZE, "%ld\n", ch->ch_txcount);
7178 static DEVICE_ATTR(txcount, S_IRUSR, dgap_tty_txcount_show, NULL);
7181 static ssize_t dgap_tty_name_show(struct device *d, struct device_attribute *attr, char *buf)
7184 struct channel_t *ch;
7188 struct cnode *cptr = NULL;
7196 un = dev_get_drvdata(d);
7197 if (!un || un->magic != DGAP_UNIT_MAGIC)
7200 if (!ch || ch->magic != DGAP_CHANNEL_MAGIC)
7203 if (!bd || bd->magic != DGAP_BOARD_MAGIC)
7205 if (bd->state != BOARD_READY)
7209 cn = ch->ch_portnum;
7211 for (cptr = bd->bd_config; cptr; cptr = cptr->next) {
7213 if ((cptr->type == BNODE) &&
7214 ((cptr->u.board.type == APORT2_920P) || (cptr->u.board.type == APORT4_920P) ||
7215 (cptr->u.board.type == APORT8_920P) || (cptr->u.board.type == PAPORT4) ||
7216 (cptr->u.board.type == PAPORT8))) {
7219 if (cptr->u.board.v_start)
7220 starto = cptr->u.board.start;
7225 if (cptr->type == TNODE && found == TRUE) {
7227 if (strstr(cptr->u.ttyname, "tty")) {
7228 ptr1 = cptr->u.ttyname;
7232 ptr1 = cptr->u.ttyname;
7235 for (i = 0; i < dgap_config_get_number_of_ports(bd); i++) {
7237 return snprintf(buf, PAGE_SIZE, "%s%s%02d\n",
7238 (un->un_type == DGAP_PRINT) ? "pr" : "tty",
7244 if (cptr->type == CNODE) {
7246 for (i = 0; i < cptr->u.conc.nport; i++) {
7247 if (cn == (i + ncount)) {
7249 return snprintf(buf, PAGE_SIZE, "%s%s%02d\n",
7250 (un->un_type == DGAP_PRINT) ? "pr" : "tty",
7252 i + (cptr->u.conc.v_start ? cptr->u.conc.start : 1));
7256 ncount += cptr->u.conc.nport;
7259 if (cptr->type == MNODE) {
7261 for (i = 0; i < cptr->u.module.nport; i++) {
7262 if (cn == (i + ncount)) {
7263 return snprintf(buf, PAGE_SIZE, "%s%s%02d\n",
7264 (un->un_type == DGAP_PRINT) ? "pr" : "tty",
7266 i + (cptr->u.module.v_start ? cptr->u.module.start : 1));
7270 ncount += cptr->u.module.nport;
7275 return snprintf(buf, PAGE_SIZE, "%s_dgap_%d_%d\n",
7276 (un->un_type == DGAP_PRINT) ? "pr" : "tty", bn, cn);
7279 static DEVICE_ATTR(custom_name, S_IRUSR, dgap_tty_name_show, NULL);
7282 static struct attribute *dgap_sysfs_tty_entries[] = {
7283 &dev_attr_state.attr,
7284 &dev_attr_baud.attr,
7285 &dev_attr_msignals.attr,
7286 &dev_attr_iflag.attr,
7287 &dev_attr_cflag.attr,
7288 &dev_attr_oflag.attr,
7289 &dev_attr_lflag.attr,
7290 &dev_attr_digi_flag.attr,
7291 &dev_attr_rxcount.attr,
7292 &dev_attr_txcount.attr,
7293 &dev_attr_custom_name.attr,
7298 static struct attribute_group dgap_tty_attribute_group = {
7300 .attrs = dgap_sysfs_tty_entries,
7306 static void dgap_create_tty_sysfs(struct un_t *un, struct device *c)
7310 ret = sysfs_create_group(&c->kobj, &dgap_tty_attribute_group);
7312 printk(KERN_ERR "dgap: failed to create sysfs tty device attributes.\n");
7313 sysfs_remove_group(&c->kobj, &dgap_tty_attribute_group);
7317 dev_set_drvdata(c, un);
7322 static void dgap_remove_tty_sysfs(struct device *c)
7324 sysfs_remove_group(&c->kobj, &dgap_tty_attribute_group);
7328 * Parse a configuration file read into memory as a string.
7330 static int dgap_parsefile(char **in, int Remove)
7332 struct cnode *p, *brd, *line, *conc;
7334 char *s = NULL, *s2 = NULL;
7338 brd = line = conc = NULL;
7340 /* perhaps we are adding to an existing list? */
7341 while (p->next != NULL) {
7345 /* file must start with a BEGIN */
7346 while ( (rc = dgap_gettok(in,p)) != BEGIN ) {
7348 dgap_err("unexpected EOF");
7354 rc = dgap_gettok(in,p);
7356 dgap_err("unexpected EOF");
7362 dgap_err("unexpected end of file");
7365 case BEGIN: /* should only be 1 begin */
7366 dgap_err("unexpected config_begin\n");
7372 case BOARD: /* board info */
7373 if (dgap_checknode(p))
7375 if ( (p->next = dgap_newnode(BNODE)) == NULL ) {
7376 dgap_err("out of memory");
7381 p->u.board.status = dgap_savestring("No");
7387 case APORT2_920P: /* AccelePort_4 */
7388 if (p->type != BNODE) {
7389 dgap_err("unexpected Digi_2r_920 string");
7392 p->u.board.type = APORT2_920P;
7393 p->u.board.v_type = 1;
7394 DPR_INIT(("Adding Digi_2r_920 PCI to config...\n"));
7397 case APORT4_920P: /* AccelePort_4 */
7398 if (p->type != BNODE) {
7399 dgap_err("unexpected Digi_4r_920 string");
7402 p->u.board.type = APORT4_920P;
7403 p->u.board.v_type = 1;
7404 DPR_INIT(("Adding Digi_4r_920 PCI to config...\n"));
7407 case APORT8_920P: /* AccelePort_8 */
7408 if (p->type != BNODE) {
7409 dgap_err("unexpected Digi_8r_920 string");
7412 p->u.board.type = APORT8_920P;
7413 p->u.board.v_type = 1;
7414 DPR_INIT(("Adding Digi_8r_920 PCI to config...\n"));
7417 case PAPORT4: /* AccelePort_4 PCI */
7418 if (p->type != BNODE) {
7419 dgap_err("unexpected Digi_4r(PCI) string");
7422 p->u.board.type = PAPORT4;
7423 p->u.board.v_type = 1;
7424 DPR_INIT(("Adding Digi_4r PCI to config...\n"));
7427 case PAPORT8: /* AccelePort_8 PCI */
7428 if (p->type != BNODE) {
7429 dgap_err("unexpected Digi_8r string");
7432 p->u.board.type = PAPORT8;
7433 p->u.board.v_type = 1;
7434 DPR_INIT(("Adding Digi_8r PCI to config...\n"));
7437 case PCX: /* PCI C/X */
7438 if (p->type != BNODE) {
7439 dgap_err("unexpected Digi_C/X_(PCI) string");
7442 p->u.board.type = PCX;
7443 p->u.board.v_type = 1;
7444 p->u.board.conc1 = 0;
7445 p->u.board.conc2 = 0;
7446 p->u.board.module1 = 0;
7447 p->u.board.module2 = 0;
7448 DPR_INIT(("Adding PCI C/X to config...\n"));
7451 case PEPC: /* PCI EPC/X */
7452 if (p->type != BNODE) {
7453 dgap_err("unexpected \"Digi_EPC/X_(PCI)\" string");
7456 p->u.board.type = PEPC;
7457 p->u.board.v_type = 1;
7458 p->u.board.conc1 = 0;
7459 p->u.board.conc2 = 0;
7460 p->u.board.module1 = 0;
7461 p->u.board.module2 = 0;
7462 DPR_INIT(("Adding PCI EPC/X to config...\n"));
7465 case PPCM: /* PCI/Xem */
7466 if (p->type != BNODE) {
7467 dgap_err("unexpected PCI/Xem string");
7470 p->u.board.type = PPCM;
7471 p->u.board.v_type = 1;
7472 p->u.board.conc1 = 0;
7473 p->u.board.conc2 = 0;
7474 DPR_INIT(("Adding PCI XEM to config...\n"));
7477 case IO: /* i/o port */
7478 if (p->type != BNODE) {
7479 dgap_err("IO port only vaild for boards");
7482 s = dgap_getword(in);
7484 dgap_err("unexpected end of file");
7487 p->u.board.portstr = dgap_savestring(s);
7488 p->u.board.port = (short)simple_strtol(s, &s2, 0);
7489 if ((short)strlen(s) > (short)(s2 - s)) {
7490 dgap_err("bad number for IO port");
7493 p->u.board.v_port = 1;
7494 DPR_INIT(("Adding IO (%s) to config...\n", s));
7497 case MEM: /* memory address */
7498 if (p->type != BNODE) {
7499 dgap_err("memory address only vaild for boards");
7502 s = dgap_getword(in);
7504 dgap_err("unexpected end of file");
7507 p->u.board.addrstr = dgap_savestring(s);
7508 p->u.board.addr = simple_strtoul(s, &s2, 0);
7509 if ((int)strlen(s) > (int)(s2 - s)) {
7510 dgap_err("bad number for memory address");
7513 p->u.board.v_addr = 1;
7514 DPR_INIT(("Adding MEM (%s) to config...\n", s));
7517 case PCIINFO: /* pci information */
7518 if (p->type != BNODE) {
7519 dgap_err("memory address only vaild for boards");
7522 s = dgap_getword(in);
7524 dgap_err("unexpected end of file");
7527 p->u.board.pcibusstr = dgap_savestring(s);
7528 p->u.board.pcibus = simple_strtoul(s, &s2, 0);
7529 if ((int)strlen(s) > (int)(s2 - s)) {
7530 dgap_err("bad number for pci bus");
7533 p->u.board.v_pcibus = 1;
7534 s = dgap_getword(in);
7536 dgap_err("unexpected end of file");
7539 p->u.board.pcislotstr = dgap_savestring(s);
7540 p->u.board.pcislot = simple_strtoul(s, &s2, 0);
7541 if ((int)strlen(s) > (int)(s2 - s)) {
7542 dgap_err("bad number for pci slot");
7545 p->u.board.v_pcislot = 1;
7547 DPR_INIT(("Adding PCIINFO (%s %s) to config...\n", p->u.board.pcibusstr,
7548 p->u.board.pcislotstr));
7552 if (p->type != BNODE) {
7553 dgap_err("install method only vaild for boards");
7556 s = dgap_getword(in);
7558 dgap_err("unexpected end of file");
7561 p->u.board.method = dgap_savestring(s);
7562 p->u.board.v_method = 1;
7563 DPR_INIT(("Adding METHOD (%s) to config...\n", s));
7567 if (p->type != BNODE) {
7568 dgap_err("config status only vaild for boards");
7571 s = dgap_getword(in);
7573 dgap_err("unexpected end of file");
7576 p->u.board.status = dgap_savestring(s);
7577 DPR_INIT(("Adding STATUS (%s) to config...\n", s));
7580 case NPORTS: /* number of ports */
7581 if (p->type == BNODE) {
7582 s = dgap_getword(in);
7584 dgap_err("unexpected end of file");
7587 p->u.board.nport = (char)simple_strtol(s, &s2, 0);
7588 if ((int)strlen(s) > (int)(s2 - s)) {
7589 dgap_err("bad number for number of ports");
7592 p->u.board.v_nport = 1;
7593 } else if (p->type == CNODE) {
7594 s = dgap_getword(in);
7596 dgap_err("unexpected end of file");
7599 p->u.conc.nport = (char)simple_strtol(s, &s2, 0);
7600 if ((int)strlen(s) > (int)(s2 - s)) {
7601 dgap_err("bad number for number of ports");
7604 p->u.conc.v_nport = 1;
7605 } else if (p->type == MNODE) {
7606 s = dgap_getword(in);
7608 dgap_err("unexpected end of file");
7611 p->u.module.nport = (char)simple_strtol(s, &s2, 0);
7612 if ((int)strlen(s) > (int)(s2 - s)) {
7613 dgap_err("bad number for number of ports");
7616 p->u.module.v_nport = 1;
7618 dgap_err("nports only valid for concentrators or modules");
7621 DPR_INIT(("Adding NPORTS (%s) to config...\n", s));
7624 case ID: /* letter ID used in tty name */
7625 s = dgap_getword(in);
7627 dgap_err("unexpected end of file");
7631 p->u.board.status = dgap_savestring(s);
7633 if (p->type == CNODE) {
7634 p->u.conc.id = dgap_savestring(s);
7636 } else if (p->type == MNODE) {
7637 p->u.module.id = dgap_savestring(s);
7638 p->u.module.v_id = 1;
7640 dgap_err("id only valid for concentrators or modules");
7643 DPR_INIT(("Adding ID (%s) to config...\n", s));
7646 case STARTO: /* start offset of ID */
7647 if (p->type == BNODE) {
7648 s = dgap_getword(in);
7650 dgap_err("unexpected end of file");
7653 p->u.board.start = simple_strtol(s, &s2, 0);
7654 if ((int)strlen(s) > (int)(s2 - s)) {
7655 dgap_err("bad number for start of tty count");
7658 p->u.board.v_start = 1;
7659 } else if (p->type == CNODE) {
7660 s = dgap_getword(in);
7662 dgap_err("unexpected end of file");
7665 p->u.conc.start = simple_strtol(s, &s2, 0);
7666 if ((int)strlen(s) > (int)(s2 - s)) {
7667 dgap_err("bad number for start of tty count");
7670 p->u.conc.v_start = 1;
7671 } else if (p->type == MNODE) {
7672 s = dgap_getword(in);
7674 dgap_err("unexpected end of file");
7677 p->u.module.start = simple_strtol(s, &s2, 0);
7678 if ((int)strlen(s) > (int)(s2 - s)) {
7679 dgap_err("bad number for start of tty count");
7682 p->u.module.v_start = 1;
7684 dgap_err("start only valid for concentrators or modules");
7687 DPR_INIT(("Adding START (%s) to config...\n", s));
7690 case TTYN: /* tty name prefix */
7691 if (dgap_checknode(p))
7693 if ( (p->next = dgap_newnode(TNODE)) == NULL ) {
7694 dgap_err("out of memory");
7698 if ( (s = dgap_getword(in)) == NULL ) {
7699 dgap_err("unexpeced end of file");
7702 if ( (p->u.ttyname = dgap_savestring(s)) == NULL ) {
7703 dgap_err("out of memory");
7706 DPR_INIT(("Adding TTY (%s) to config...\n", s));
7709 case CU: /* cu name prefix */
7710 if (dgap_checknode(p))
7712 if ( (p->next = dgap_newnode(CUNODE)) == NULL ) {
7713 dgap_err("out of memory");
7717 if ( (s = dgap_getword(in)) == NULL ) {
7718 dgap_err("unexpeced end of file");
7721 if ( (p->u.cuname = dgap_savestring(s)) == NULL ) {
7722 dgap_err("out of memory");
7725 DPR_INIT(("Adding CU (%s) to config...\n", s));
7728 case LINE: /* line information */
7729 if (dgap_checknode(p))
7732 dgap_err("must specify board before line info");
7735 switch (brd->u.board.type) {
7737 dgap_err("line not vaild for PC/em");
7740 if ( (p->next = dgap_newnode(LNODE)) == NULL ) {
7741 dgap_err("out of memory");
7748 DPR_INIT(("Adding LINE to config...\n"));
7751 case CONC: /* concentrator information */
7752 if (dgap_checknode(p))
7755 dgap_err("must specify line info before concentrator");
7758 if ( (p->next = dgap_newnode(CNODE)) == NULL ) {
7759 dgap_err("out of memory");
7765 brd->u.board.conc2++;
7767 brd->u.board.conc1++;
7769 DPR_INIT(("Adding CONC to config...\n"));
7772 case CX: /* c/x type concentrator */
7773 if (p->type != CNODE) {
7774 dgap_err("cx only valid for concentrators");
7777 p->u.conc.type = CX;
7778 p->u.conc.v_type = 1;
7779 DPR_INIT(("Adding CX to config...\n"));
7782 case EPC: /* epc type concentrator */
7783 if (p->type != CNODE) {
7784 dgap_err("cx only valid for concentrators");
7787 p->u.conc.type = EPC;
7788 p->u.conc.v_type = 1;
7789 DPR_INIT(("Adding EPC to config...\n"));
7792 case MOD: /* EBI module */
7793 if (dgap_checknode(p))
7796 dgap_err("must specify board info before EBI modules");
7799 switch (brd->u.board.type) {
7805 dgap_err("must specify concentrator info before EBI module");
7809 if ( (p->next = dgap_newnode(MNODE)) == NULL ) {
7810 dgap_err("out of memory");
7815 brd->u.board.module2++;
7817 brd->u.board.module1++;
7819 DPR_INIT(("Adding MOD to config...\n"));
7822 case PORTS: /* ports type EBI module */
7823 if (p->type != MNODE) {
7824 dgap_err("ports only valid for EBI modules");
7827 p->u.module.type = PORTS;
7828 p->u.module.v_type = 1;
7829 DPR_INIT(("Adding PORTS to config...\n"));
7832 case MODEM: /* ports type EBI module */
7833 if (p->type != MNODE) {
7834 dgap_err("modem only valid for modem modules");
7837 p->u.module.type = MODEM;
7838 p->u.module.v_type = 1;
7839 DPR_INIT(("Adding MODEM to config...\n"));
7843 if (p->type == LNODE) {
7844 if ((s = dgap_getword(in)) == NULL) {
7845 dgap_err("unexpected end of file");
7848 p->u.line.cable = dgap_savestring(s);
7849 p->u.line.v_cable = 1;
7851 DPR_INIT(("Adding CABLE (%s) to config...\n", s));
7854 case SPEED: /* sync line speed indication */
7855 if (p->type == LNODE) {
7856 s = dgap_getword(in);
7858 dgap_err("unexpected end of file");
7861 p->u.line.speed = (char)simple_strtol(s, &s2, 0);
7862 if ((short)strlen(s) > (short)(s2 - s)) {
7863 dgap_err("bad number for line speed");
7866 p->u.line.v_speed = 1;
7867 } else if (p->type == CNODE) {
7868 s = dgap_getword(in);
7870 dgap_err("unexpected end of file");
7873 p->u.conc.speed = (char)simple_strtol(s, &s2, 0);
7874 if ((short)strlen(s) > (short)(s2 - s)) {
7875 dgap_err("bad number for line speed");
7878 p->u.conc.v_speed = 1;
7880 dgap_err("speed valid only for lines or concentrators.");
7883 DPR_INIT(("Adding SPEED (%s) to config...\n", s));
7887 if (p->type == CNODE) {
7888 if ((s = dgap_getword(in)) == NULL) {
7889 dgap_err("unexpected end of file");
7892 p->u.conc.connect = dgap_savestring(s);
7893 p->u.conc.v_connect = 1;
7895 DPR_INIT(("Adding CONNECT (%s) to config...\n", s));
7897 case PRINT: /* transparent print name prefix */
7898 if (dgap_checknode(p))
7900 if ( (p->next = dgap_newnode(PNODE)) == NULL ) {
7901 dgap_err("out of memory");
7905 if ( (s = dgap_getword(in)) == NULL ) {
7906 dgap_err("unexpeced end of file");
7909 if ( (p->u.printname = dgap_savestring(s)) == NULL ) {
7910 dgap_err("out of memory");
7913 DPR_INIT(("Adding PRINT (%s) to config...\n", s));
7916 case CMAJOR: /* major number */
7917 if (dgap_checknode(p))
7919 if ( (p->next = dgap_newnode(JNODE)) == NULL ) {
7920 dgap_err("out of memory");
7924 s = dgap_getword(in);
7926 dgap_err("unexpected end of file");
7929 p->u.majornumber = simple_strtol(s, &s2, 0);
7930 if ((int)strlen(s) > (int)(s2 - s)) {
7931 dgap_err("bad number for major number");
7934 DPR_INIT(("Adding CMAJOR (%s) to config...\n", s));
7937 case ALTPIN: /* altpin setting */
7938 if (dgap_checknode(p))
7940 if ( (p->next = dgap_newnode(ANODE)) == NULL ) {
7941 dgap_err("out of memory");
7945 s = dgap_getword(in);
7947 dgap_err("unexpected end of file");
7950 p->u.altpin = simple_strtol(s, &s2, 0);
7951 if ((int)strlen(s) > (int)(s2 - s)) {
7952 dgap_err("bad number for altpin");
7955 DPR_INIT(("Adding ALTPIN (%s) to config...\n", s));
7958 case USEINTR: /* enable interrupt setting */
7959 if (dgap_checknode(p))
7961 if ( (p->next = dgap_newnode(INTRNODE)) == NULL ) {
7962 dgap_err("out of memory");
7966 s = dgap_getword(in);
7968 dgap_err("unexpected end of file");
7971 p->u.useintr = simple_strtol(s, &s2, 0);
7972 if ((int)strlen(s) > (int)(s2 - s)) {
7973 dgap_err("bad number for useintr");
7976 DPR_INIT(("Adding USEINTR (%s) to config...\n", s));
7979 case TTSIZ: /* size of tty structure */
7980 if (dgap_checknode(p))
7982 if ( (p->next = dgap_newnode(TSNODE)) == NULL ) {
7983 dgap_err("out of memory");
7987 s = dgap_getword(in);
7989 dgap_err("unexpected end of file");
7992 p->u.ttysize = simple_strtol(s, &s2, 0);
7993 if ((int)strlen(s) > (int)(s2 - s)) {
7994 dgap_err("bad number for ttysize");
7997 DPR_INIT(("Adding TTSIZ (%s) to config...\n", s));
8000 case CHSIZ: /* channel structure size */
8001 if (dgap_checknode(p))
8003 if ( (p->next = dgap_newnode(CSNODE)) == NULL ) {
8004 dgap_err("out of memory");
8008 s = dgap_getword(in);
8010 dgap_err("unexpected end of file");
8013 p->u.chsize = simple_strtol(s, &s2, 0);
8014 if ((int)strlen(s) > (int)(s2 - s)) {
8015 dgap_err("bad number for chsize");
8018 DPR_INIT(("Adding CHSIZE (%s) to config...\n", s));
8021 case BSSIZ: /* board structure size */
8022 if (dgap_checknode(p))
8024 if ( (p->next = dgap_newnode(BSNODE)) == NULL ) {
8025 dgap_err("out of memory");
8029 s = dgap_getword(in);
8031 dgap_err("unexpected end of file");
8034 p->u.bssize = simple_strtol(s, &s2, 0);
8035 if ((int)strlen(s) > (int)(s2 - s)) {
8036 dgap_err("bad number for bssize");
8039 DPR_INIT(("Adding BSSIZ (%s) to config...\n", s));
8042 case UNTSIZ: /* sched structure size */
8043 if (dgap_checknode(p))
8045 if ( (p->next = dgap_newnode(USNODE)) == NULL ) {
8046 dgap_err("out of memory");
8050 s = dgap_getword(in);
8052 dgap_err("unexpected end of file");
8055 p->u.unsize = simple_strtol(s, &s2, 0);
8056 if ((int)strlen(s) > (int)(s2 - s)) {
8057 dgap_err("bad number for schedsize");
8060 DPR_INIT(("Adding UNTSIZ (%s) to config...\n", s));
8063 case F2SIZ: /* f2200 structure size */
8064 if (dgap_checknode(p))
8066 if ( (p->next = dgap_newnode(FSNODE)) == NULL ) {
8067 dgap_err("out of memory");
8071 s = dgap_getword(in);
8073 dgap_err("unexpected end of file");
8076 p->u.f2size = simple_strtol(s, &s2, 0);
8077 if ((int)strlen(s) > (int)(s2 - s)) {
8078 dgap_err("bad number for f2200size");
8081 DPR_INIT(("Adding F2SIZ (%s) to config...\n", s));
8084 case VPSIZ: /* vpix structure size */
8085 if (dgap_checknode(p))
8087 if ( (p->next = dgap_newnode(VSNODE)) == NULL ) {
8088 dgap_err("out of memory");
8092 s = dgap_getword(in);
8094 dgap_err("unexpected end of file");
8097 p->u.vpixsize = simple_strtol(s, &s2, 0);
8098 if ((int)strlen(s) > (int)(s2 - s)) {
8099 dgap_err("bad number for vpixsize");
8102 DPR_INIT(("Adding VPSIZ (%s) to config...\n", s));
8110 * dgap_sindex: much like index(), but it looks for a match of any character in
8111 * the group, and returns that position. If the first character is a ^, then
8112 * this will match the first occurrence not in that group.
8114 static char *dgap_sindex (char *string, char *group)
8118 if (!string || !group)
8119 return (char *) NULL;
8121 if (*group == '^') {
8123 for (; *string; string++) {
8124 for (ptr = group; *ptr; ptr++) {
8125 if (*ptr == *string)
8133 for (; *string; string++) {
8134 for (ptr = group; *ptr; ptr++) {
8135 if (*ptr == *string)
8141 return (char *) NULL;
8146 * Get a token from the input file; return 0 if end of file is reached
8148 static int dgap_gettok(char **in, struct cnode *p)
8153 if (strstr(dgap_cword, "boar")) {
8154 w = dgap_getword(in);
8155 snprintf(dgap_cword, MAXCWORD, "%s", w);
8156 for (t = dgap_tlist; t->token != 0; t++) {
8157 if ( !strcmp(w, t->string)) {
8161 dgap_err("board !!type not specified");
8165 while ( (w = dgap_getword(in)) != NULL ) {
8166 snprintf(dgap_cword, MAXCWORD, "%s", w);
8167 for (t = dgap_tlist; t->token != 0; t++) {
8168 if ( !strcmp(w, t->string) )
8178 * get a word from the input stream, also keep track of current line number.
8179 * words are separated by whitespace.
8181 static char *dgap_getword(char **in)
8183 char *ret_ptr = *in;
8185 char *ptr = dgap_sindex(*in, " \t\n");
8187 /* If no word found, return null */
8191 /* Mark new location for our buffer */
8195 /* Eat any extra spaces/tabs/newlines that might be present */
8196 while (*in && **in && ((**in == ' ') || (**in == '\t') || (**in == '\n'))) {
8206 * print an error message, giving the line number in the file where
8207 * the error occurred.
8209 static void dgap_err(char *s)
8211 printk("DGAP: parse: %s\n", s);
8216 * allocate a new configuration node of type t
8218 static struct cnode *dgap_newnode(int t)
8222 n = kmalloc(sizeof(struct cnode), GFP_ATOMIC);
8224 memset((char *)n, 0, sizeof(struct cnode));
8232 * dgap_checknode: see if all the necessary info has been supplied for a node
8233 * before creating the next node.
8235 static int dgap_checknode(struct cnode *p)
8239 if (p->u.board.v_type == 0) {
8240 dgap_err("board type !not specified");
8247 if (p->u.line.v_speed == 0) {
8248 dgap_err("line speed not specified");
8254 if (p->u.conc.v_type == 0) {
8255 dgap_err("concentrator type not specified");
8258 if (p->u.conc.v_speed == 0) {
8259 dgap_err("concentrator line speed not specified");
8262 if (p->u.conc.v_nport == 0) {
8263 dgap_err("number of ports on concentrator not specified");
8266 if (p->u.conc.v_id == 0) {
8267 dgap_err("concentrator id letter not specified");
8273 if (p->u.module.v_type == 0) {
8274 dgap_err("EBI module type not specified");
8277 if (p->u.module.v_nport == 0) {
8278 dgap_err("number of ports on EBI module not specified");
8281 if (p->u.module.v_id == 0) {
8282 dgap_err("EBI module id letter not specified");
8291 * save a string somewhere
8293 static char *dgap_savestring(char *s)
8296 if ( (p = kmalloc(strlen(s) + 1, GFP_ATOMIC) ) != NULL) {
8304 * Given a board pointer, returns whether we should use interrupts or not.
8306 static uint dgap_config_get_useintr(struct board_t *bd)
8308 struct cnode *p = NULL;
8313 for (p = bd->bd_config; p; p = p->next) {
8317 * check for pcxr types.
8319 return p->u.useintr;
8325 /* If not found, then don't turn on interrupts. */
8331 * Given a board pointer, returns whether we turn on altpin or not.
8333 static uint dgap_config_get_altpin(struct board_t *bd)
8335 struct cnode *p = NULL;
8340 for (p = bd->bd_config; p; p = p->next) {
8344 * check for pcxr types.
8352 /* If not found, then don't turn on interrupts. */
8359 * Given a specific type of board, if found, detached link and
8360 * returns the first occurrence in the list.
8362 static struct cnode *dgap_find_config(int type, int bus, int slot)
8364 struct cnode *p, *prev = NULL, *prev2 = NULL, *found = NULL;
8368 while (p->next != NULL) {
8372 if (p->type == BNODE) {
8374 if (p->u.board.type == type) {
8376 if (p->u.board.v_pcibus && p->u.board.pcibus != bus) {
8377 DPR(("Found matching board, but wrong bus position. System says bus %d, we want bus %ld\n",
8378 bus, p->u.board.pcibus));
8381 if (p->u.board.v_pcislot && p->u.board.pcislot != slot) {
8382 DPR_INIT(("Found matching board, but wrong slot position. System says slot %d, we want slot %ld\n",
8383 slot, p->u.board.pcislot));
8387 DPR_INIT(("Matched type in config file\n"));
8391 * Keep walking thru the list till we find the next board.
8393 while (p->next != NULL) {
8396 if (p->type == BNODE) {
8399 * Mark the end of our 1 board chain of configs.
8404 * Link the "next" board to the previous board,
8405 * effectively "unlinking" our board from the main config.
8413 * It must be the last board in the list.
8424 * Given a board pointer, walks the config link, counting up
8425 * all ports user specified should be on the board.
8426 * (This does NOT mean they are all actually present right now tho)
8428 static uint dgap_config_get_number_of_ports(struct board_t *bd)
8431 struct cnode *p = NULL;
8436 for (p = bd->bd_config; p; p = p->next) {
8441 * check for pcxr types.
8443 if (p->u.board.type > EPCFE)
8444 count += p->u.board.nport;
8447 count += p->u.conc.nport;
8450 count += p->u.module.nport;
8457 static char *dgap_create_config_string(struct board_t *bd, char *string)
8460 struct cnode *p = NULL;
8461 struct cnode *q = NULL;
8469 for (p = bd->bd_config; p; p = p->next) {
8475 *ptr = p->u.line.speed;
8480 * Because the EPC/con concentrators can have EM modules
8481 * hanging off of them, we have to walk ahead in the list
8482 * and keep adding the number of ports on each EM to the config.
8485 speed = p->u.conc.speed;
8487 if ((q != NULL) && (q->type == MNODE) ) {
8488 *ptr = (p->u.conc.nport + 0x80);
8491 while ((q->next != NULL) && (q->next->type) == MNODE) {
8492 *ptr = (q->u.module.nport + 0x80);
8497 *ptr = q->u.module.nport;
8500 *ptr = p->u.conc.nport;