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 void dgap_sysfs_create(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 dgap_sysfs_create(brd);
1103 brd->state = BOARD_READY;
1104 brd->dpastatus = BD_RUNNING;
1112 static int dgap_do_remap(struct board_t *brd)
1114 if (!brd || brd->magic != DGAP_BOARD_MAGIC)
1117 if (!request_mem_region(brd->membase, 0x200000, "dgap")) {
1118 APR(("dgap: mem_region %lx already in use.\n", brd->membase));
1122 if (!request_mem_region(brd->membase + PCI_IO_OFFSET, 0x200000, "dgap")) {
1123 APR(("dgap: mem_region IO %lx already in use.\n",
1124 brd->membase + PCI_IO_OFFSET));
1125 release_mem_region(brd->membase, 0x200000);
1129 brd->re_map_membase = ioremap(brd->membase, 0x200000);
1130 if (!brd->re_map_membase) {
1131 APR(("dgap: ioremap mem %lx cannot be mapped.\n", brd->membase));
1132 release_mem_region(brd->membase, 0x200000);
1133 release_mem_region(brd->membase + PCI_IO_OFFSET, 0x200000);
1137 brd->re_map_port = ioremap((brd->membase + PCI_IO_OFFSET), 0x200000);
1138 if (!brd->re_map_port) {
1139 release_mem_region(brd->membase, 0x200000);
1140 release_mem_region(brd->membase + PCI_IO_OFFSET, 0x200000);
1141 iounmap(brd->re_map_membase);
1142 APR(("dgap: ioremap IO mem %lx cannot be mapped.\n",
1143 brd->membase + PCI_IO_OFFSET));
1147 DPR_INIT(("remapped io: 0x%p remapped mem: 0x%p\n",
1148 brd->re_map_port, brd->re_map_membase));
1153 /*****************************************************************************
1173 * As each timer expires, it determines (a) whether the "transmit"
1174 * waiter needs to be woken up, and (b) whether the poller needs to
1177 ******************************************************************************/
1179 static void dgap_poll_handler(ulong dummy)
1182 struct board_t *brd;
1183 unsigned long lock_flags;
1186 dgap_poll_counter++;
1190 * Do not start the board state machine until
1191 * driver tells us its up and running, and has
1192 * everything it needs.
1194 if (dgap_driver_state != DRIVER_READY)
1195 goto schedule_poller;
1198 * If we have just 1 board, or the system is not SMP,
1199 * then use the typical old style poller.
1200 * Otherwise, use our new tasklet based poller, which should
1201 * speed things up for multiple boards.
1203 if ( (dgap_NumBoards == 1) || (num_online_cpus() <= 1) ) {
1204 for (i = 0; i < dgap_NumBoards; i++) {
1206 brd = dgap_Board[i];
1208 if (brd->state == BOARD_FAILED) {
1211 if (!brd->intr_running) {
1212 /* Call the real board poller directly */
1213 dgap_poll_tasklet((unsigned long) brd);
1218 /* Go thru each board, kicking off a tasklet for each if needed */
1219 for (i = 0; i < dgap_NumBoards; i++) {
1220 brd = dgap_Board[i];
1223 * Attempt to grab the board lock.
1225 * If we can't get it, no big deal, the next poll will get it.
1226 * Basically, I just really don't want to spin in here, because I want
1227 * to kick off my tasklets as fast as I can, and then get out the poller.
1229 if (!spin_trylock(&brd->bd_lock)) {
1233 /* If board is in a failed state, don't bother scheduling a tasklet */
1234 if (brd->state == BOARD_FAILED) {
1235 spin_unlock(&brd->bd_lock);
1239 /* Schedule a poll helper task */
1240 if (!brd->intr_running) {
1241 tasklet_schedule(&brd->helper_tasklet);
1245 * Can't do DGAP_UNLOCK here, as we don't have
1246 * lock_flags because we did a trylock above.
1248 spin_unlock(&brd->bd_lock);
1255 * Schedule ourself back at the nominal wakeup interval.
1257 DGAP_LOCK(dgap_poll_lock, lock_flags );
1258 dgap_poll_time += dgap_jiffies_from_ms(dgap_poll_tick);
1260 new_time = dgap_poll_time - jiffies;
1262 if ((ulong) new_time >= 2 * dgap_poll_tick) {
1263 dgap_poll_time = jiffies + dgap_jiffies_from_ms(dgap_poll_tick);
1266 dgap_poll_timer.function = dgap_poll_handler;
1267 dgap_poll_timer.data = 0;
1268 dgap_poll_timer.expires = dgap_poll_time;
1269 DGAP_UNLOCK(dgap_poll_lock, lock_flags );
1271 if (!dgap_poll_stop)
1272 add_timer(&dgap_poll_timer);
1281 * Driver interrupt handler.
1283 static irqreturn_t dgap_intr(int irq, void *voidbrd)
1285 struct board_t *brd = (struct board_t *) voidbrd;
1288 APR(("Received interrupt (%d) with null board associated\n", irq));
1293 * Check to make sure its for us.
1295 if (brd->magic != DGAP_BOARD_MAGIC) {
1296 APR(("Received interrupt (%d) with a board pointer that wasn't ours!\n", irq));
1303 * Schedule tasklet to run at a better time.
1305 tasklet_schedule(&brd->helper_tasklet);
1311 * dgap_init_globals()
1313 * This is where we initialize the globals from the static insmod
1314 * configuration variables. These are declared near the head of
1317 static void dgap_init_globals(void)
1321 dgap_rawreadok = rawreadok;
1322 dgap_trcbuf_size = trcbuf_size;
1325 for (i = 0; i < MAXBOARDS; i++) {
1326 dgap_Board[i] = NULL;
1329 init_timer( &dgap_poll_timer );
1331 init_waitqueue_head(&dgap_dl_wait);
1336 /************************************************************************
1340 ************************************************************************/
1346 * Used to print to the message buffer during board init.
1348 static void dgap_mbuf(struct board_t *brd, const char *fmt, ...) {
1352 unsigned long flags;
1355 DGAP_LOCK(dgap_global_lock, flags);
1357 /* Format buf using fmt and arguments contained in ap. */
1359 i = vsnprintf(buf, sizeof(buf), fmt, ap);
1364 if (!brd || !brd->msgbuf) {
1366 DGAP_UNLOCK(dgap_global_lock, flags);
1370 length = strlen(buf) + 1;
1371 if (brd->msgbuf - brd->msgbuf_head < length)
1372 length = brd->msgbuf - brd->msgbuf_head;
1373 memcpy(brd->msgbuf, buf, length);
1374 brd->msgbuf += length;
1376 DGAP_UNLOCK(dgap_global_lock, flags);
1383 * Put the driver to sleep for x ms's
1385 * Returns 0 if timed out, !0 (showing signal) if interrupted by a signal.
1387 static int dgap_ms_sleep(ulong ms)
1389 current->state = TASK_INTERRUPTIBLE;
1390 schedule_timeout((ms * HZ) / 1000);
1391 return (signal_pending(current));
1397 /************************************************************************
1399 * TTY Initialization/Cleanup Functions
1401 ************************************************************************/
1404 * dgap_tty_preinit()
1406 * Initialize any global tty related data before we download any boards.
1408 static int dgap_tty_preinit(void)
1410 unsigned long flags;
1412 DGAP_LOCK(dgap_global_lock, flags);
1415 * Allocate a buffer for doing the copy from user space to
1416 * kernel space in dgap_input(). We only use one buffer and
1417 * control access to it with a semaphore. If we are paging, we
1418 * are already in trouble so one buffer won't hurt much anyway.
1420 dgap_TmpWriteBuf = kmalloc(WRITEBUFLEN, GFP_ATOMIC);
1422 if (!dgap_TmpWriteBuf) {
1423 DGAP_UNLOCK(dgap_global_lock, flags);
1424 DPR_INIT(("unable to allocate tmp write buf"));
1428 DGAP_UNLOCK(dgap_global_lock, flags);
1434 * dgap_tty_register()
1436 * Init the tty subsystem for this board.
1438 static int dgap_tty_register(struct board_t *brd)
1442 DPR_INIT(("tty_register start"));
1444 brd->SerialDriver = alloc_tty_driver(MAXPORTS);
1446 snprintf(brd->SerialName, MAXTTYNAMELEN, "tty_dgap_%d_", brd->boardnum);
1447 brd->SerialDriver->name = brd->SerialName;
1448 brd->SerialDriver->name_base = 0;
1449 brd->SerialDriver->major = 0;
1450 brd->SerialDriver->minor_start = 0;
1451 brd->SerialDriver->type = TTY_DRIVER_TYPE_SERIAL;
1452 brd->SerialDriver->subtype = SERIAL_TYPE_NORMAL;
1453 brd->SerialDriver->init_termios = DgapDefaultTermios;
1454 brd->SerialDriver->driver_name = DRVSTR;
1455 brd->SerialDriver->flags = (TTY_DRIVER_REAL_RAW | TTY_DRIVER_DYNAMIC_DEV | TTY_DRIVER_HARDWARE_BREAK);
1457 /* The kernel wants space to store pointers to tty_structs */
1458 brd->SerialDriver->ttys = kzalloc(MAXPORTS * sizeof(struct tty_struct *), GFP_KERNEL);
1459 if (!brd->SerialDriver->ttys)
1463 * Entry points for driver. Called by the kernel from
1464 * tty_io.c and n_tty.c.
1466 tty_set_operations(brd->SerialDriver, &dgap_tty_ops);
1469 * If we're doing transparent print, we have to do all of the above
1470 * again, separately so we don't get the LD confused about what major
1471 * we are when we get into the dgap_tty_open() routine.
1473 brd->PrintDriver = alloc_tty_driver(MAXPORTS);
1475 snprintf(brd->PrintName, MAXTTYNAMELEN, "pr_dgap_%d_", brd->boardnum);
1476 brd->PrintDriver->name = brd->PrintName;
1477 brd->PrintDriver->name_base = 0;
1478 brd->PrintDriver->major = 0;
1479 brd->PrintDriver->minor_start = 0;
1480 brd->PrintDriver->type = TTY_DRIVER_TYPE_SERIAL;
1481 brd->PrintDriver->subtype = SERIAL_TYPE_NORMAL;
1482 brd->PrintDriver->init_termios = DgapDefaultTermios;
1483 brd->PrintDriver->driver_name = DRVSTR;
1484 brd->PrintDriver->flags = (TTY_DRIVER_REAL_RAW | TTY_DRIVER_DYNAMIC_DEV | TTY_DRIVER_HARDWARE_BREAK);
1486 /* The kernel wants space to store pointers to tty_structs */
1487 brd->PrintDriver->ttys = kzalloc(MAXPORTS * sizeof(struct tty_struct *), GFP_KERNEL);
1488 if (!brd->PrintDriver->ttys)
1492 * Entry points for driver. Called by the kernel from
1493 * tty_io.c and n_tty.c.
1495 tty_set_operations(brd->PrintDriver, &dgap_tty_ops);
1497 if (!brd->dgap_Major_Serial_Registered) {
1498 /* Register tty devices */
1499 rc = tty_register_driver(brd->SerialDriver);
1501 APR(("Can't register tty device (%d)\n", rc));
1504 brd->dgap_Major_Serial_Registered = TRUE;
1505 dgap_BoardsByMajor[brd->SerialDriver->major] = brd;
1506 brd->dgap_Serial_Major = brd->SerialDriver->major;
1509 if (!brd->dgap_Major_TransparentPrint_Registered) {
1510 /* Register Transparent Print devices */
1511 rc = tty_register_driver(brd->PrintDriver);
1513 APR(("Can't register Transparent Print device (%d)\n", rc));
1516 brd->dgap_Major_TransparentPrint_Registered = TRUE;
1517 dgap_BoardsByMajor[brd->PrintDriver->major] = brd;
1518 brd->dgap_TransparentPrint_Major = brd->PrintDriver->major;
1521 DPR_INIT(("DGAP REGISTER TTY: MAJORS: %d %d\n", brd->SerialDriver->major,
1522 brd->PrintDriver->major));
1531 * Init the tty subsystem. Called once per board after board has been
1532 * downloaded and init'ed.
1534 static int dgap_tty_init(struct board_t *brd)
1538 uint true_count = 0;
1541 struct channel_t *ch;
1548 DPR_INIT(("dgap_tty_init start\n"));
1551 * Initialize board structure elements.
1554 vaddr = brd->re_map_membase;
1555 true_count = readw((vaddr + NCHAN));
1557 brd->nasync = dgap_config_get_number_of_ports(brd);
1560 brd->nasync = brd->maxports;
1563 if (brd->nasync > brd->maxports) {
1564 brd->nasync = brd->maxports;
1567 if (true_count != brd->nasync) {
1568 if ((brd->type == PPCM) && (true_count == 64)) {
1569 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",
1570 brd->name, brd->nasync, true_count));
1572 else if ((brd->type == PPCM) && (true_count == 0)) {
1573 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",
1574 brd->name, brd->nasync, true_count));
1577 APR(("***WARNING**** %s configured for %d ports, has %d ports.\n",
1578 brd->name, brd->nasync, true_count));
1581 brd->nasync = true_count;
1583 /* If no ports, don't bother going any further */
1585 brd->state = BOARD_FAILED;
1586 brd->dpastatus = BD_NOFEP;
1592 * Allocate channel memory that might not have been allocated
1593 * when the driver was first loaded.
1595 for (i = 0; i < brd->nasync; i++) {
1596 if (!brd->channels[i]) {
1597 brd->channels[i] = kzalloc(sizeof(struct channel_t), GFP_ATOMIC);
1598 if (!brd->channels[i]) {
1599 DPR_CORE(("%s:%d Unable to allocate memory for channel struct\n",
1600 __FILE__, __LINE__));
1605 ch = brd->channels[0];
1606 vaddr = brd->re_map_membase;
1608 bs = (struct bs_t *) ((ulong) vaddr + CHANBUF);
1609 cm = (struct cm_t *) ((ulong) vaddr + CMDBUF);
1613 /* Set up channel variables */
1614 for (i = 0; i < brd->nasync; i++, ch = brd->channels[i], bs++) {
1616 if (!brd->channels[i])
1619 DGAP_SPINLOCK_INIT(ch->ch_lock);
1621 /* Store all our magic numbers */
1622 ch->magic = DGAP_CHANNEL_MAGIC;
1623 ch->ch_tun.magic = DGAP_UNIT_MAGIC;
1624 ch->ch_tun.un_type = DGAP_SERIAL;
1625 ch->ch_tun.un_ch = ch;
1626 ch->ch_tun.un_dev = i;
1628 ch->ch_pun.magic = DGAP_UNIT_MAGIC;
1629 ch->ch_pun.un_type = DGAP_PRINT;
1630 ch->ch_pun.un_ch = ch;
1631 ch->ch_pun.un_dev = i;
1633 ch->ch_vaddr = vaddr;
1638 ch->ch_digi = dgap_digi_init;
1641 * Set up digi dsr and dcd bits based on altpin flag.
1643 if (dgap_config_get_altpin(brd)) {
1646 ch->ch_digi.digi_flags |= DIGI_ALTPIN;
1650 ch->ch_dsr = DM_DSR;
1653 ch->ch_taddr = vaddr + ((ch->ch_bs->tx_seg) << 4);
1654 ch->ch_raddr = vaddr + ((ch->ch_bs->rx_seg) << 4);
1657 ch->ch_tsize = readw(&(ch->ch_bs->tx_max)) + 1;
1658 ch->ch_rsize = readw(&(ch->ch_bs->rx_max)) + 1;
1662 /* .25 second delay */
1663 ch->ch_close_delay = 250;
1666 * Set queue water marks, interrupt mask,
1667 * and general tty parameters.
1669 ch->ch_tlw = tlw = ch->ch_tsize >= 2000 ? ((ch->ch_tsize * 5) / 8) : ch->ch_tsize / 2;
1671 dgap_cmdw(ch, STLOW, tlw, 0);
1673 dgap_cmdw(ch, SRLOW, ch->ch_rsize / 2, 0);
1675 dgap_cmdw(ch, SRHIGH, 7 * ch->ch_rsize / 8, 0);
1677 ch->ch_mistat = readb(&(ch->ch_bs->m_stat));
1679 init_waitqueue_head(&ch->ch_flags_wait);
1680 init_waitqueue_head(&ch->ch_tun.un_flags_wait);
1681 init_waitqueue_head(&ch->ch_pun.un_flags_wait);
1682 init_waitqueue_head(&ch->ch_sniff_wait);
1684 /* Turn on all modem interrupts for now */
1685 modem = (DM_CD | DM_DSR | DM_CTS | DM_RI);
1686 writeb(modem, &(ch->ch_bs->m_int));
1689 * Set edelay to 0 if interrupts are turned on,
1690 * otherwise set edelay to the usual 100.
1693 writew(0, &(ch->ch_bs->edelay));
1695 writew(100, &(ch->ch_bs->edelay));
1697 writeb(1, &(ch->ch_bs->idata));
1701 DPR_INIT(("dgap_tty_init finish\n"));
1708 * dgap_tty_post_uninit()
1710 * UnInitialize any global tty related data.
1712 static void dgap_tty_post_uninit(void)
1714 kfree(dgap_TmpWriteBuf);
1715 dgap_TmpWriteBuf = NULL;
1722 * Uninitialize the TTY portion of this driver. Free all memory and
1725 static void dgap_tty_uninit(struct board_t *brd)
1729 if (brd->dgap_Major_Serial_Registered) {
1730 dgap_BoardsByMajor[brd->SerialDriver->major] = NULL;
1731 brd->dgap_Serial_Major = 0;
1732 for (i = 0; i < brd->nasync; i++) {
1733 dgap_remove_tty_sysfs(brd->channels[i]->ch_tun.un_sysfs);
1734 tty_unregister_device(brd->SerialDriver, i);
1736 tty_unregister_driver(brd->SerialDriver);
1737 kfree(brd->SerialDriver->ttys);
1738 brd->SerialDriver->ttys = NULL;
1739 put_tty_driver(brd->SerialDriver);
1740 brd->dgap_Major_Serial_Registered = FALSE;
1743 if (brd->dgap_Major_TransparentPrint_Registered) {
1744 dgap_BoardsByMajor[brd->PrintDriver->major] = NULL;
1745 brd->dgap_TransparentPrint_Major = 0;
1746 for (i = 0; i < brd->nasync; i++) {
1747 dgap_remove_tty_sysfs(brd->channels[i]->ch_pun.un_sysfs);
1748 tty_unregister_device(brd->PrintDriver, i);
1750 tty_unregister_driver(brd->PrintDriver);
1751 kfree(brd->PrintDriver->ttys);
1752 brd->PrintDriver->ttys = NULL;
1753 put_tty_driver(brd->PrintDriver);
1754 brd->dgap_Major_TransparentPrint_Registered = FALSE;
1759 #define TMPBUFLEN (1024)
1762 * dgap_sniff - Dump data out to the "sniff" buffer if the
1763 * proc sniff file is opened...
1765 static void dgap_sniff_nowait_nolock(struct channel_t *ch, uchar *text, uchar *buf, int len)
1773 char tmpbuf[TMPBUFLEN];
1777 /* Leave if sniff not open */
1778 if (!(ch->ch_sniff_flags & SNIFF_OPEN))
1781 do_gettimeofday(&tv);
1783 /* Create our header for data dump */
1784 p += sprintf(p, "<%ld %ld><%s><", tv.tv_sec, tv.tv_usec, text);
1785 tmpbuflen = p - tmpbuf;
1790 for (i = 0; i < len && tmpbuflen < (TMPBUFLEN - 4); i++) {
1791 p += sprintf(p, "%02x ", *buf);
1793 tmpbuflen = p - tmpbuf;
1796 if (tmpbuflen < (TMPBUFLEN - 4)) {
1798 p += sprintf(p - 1, "%s\n", ">");
1800 p += sprintf(p, "%s\n", ">");
1806 nbuf = strlen(tmpbuf);
1810 * Loop while data remains.
1812 while (nbuf > 0 && ch->ch_sniff_buf) {
1814 * Determine the amount of available space left in the
1815 * buffer. If there's none, wait until some appears.
1817 n = (ch->ch_sniff_out - ch->ch_sniff_in - 1) & SNIFF_MASK;
1820 * If there is no space left to write to in our sniff buffer,
1821 * we have no choice but to drop the data.
1822 * We *cannot* sleep here waiting for space, because this
1823 * function was probably called by the interrupt/timer routines!
1830 * Copy as much data as will fit.
1836 r = SNIFF_MAX - ch->ch_sniff_in;
1839 memcpy(ch->ch_sniff_buf + ch->ch_sniff_in, p, r);
1842 ch->ch_sniff_in = 0;
1847 memcpy(ch->ch_sniff_buf + ch->ch_sniff_in, p, n);
1849 ch->ch_sniff_in += n;
1854 * Wakeup any thread waiting for data
1856 if (ch->ch_sniff_flags & SNIFF_WAIT_DATA) {
1857 ch->ch_sniff_flags &= ~SNIFF_WAIT_DATA;
1858 wake_up_interruptible(&ch->ch_sniff_wait);
1863 * If the user sent us too much data to push into our tmpbuf,
1864 * we need to keep looping around on all the data.
1866 if (too_much_data) {
1871 } while (too_much_data);
1875 /*=======================================================================
1877 * dgap_input - Process received data.
1879 * ch - Pointer to channel structure.
1881 *=======================================================================*/
1883 static void dgap_input(struct channel_t *ch)
1887 struct tty_struct *tp;
1888 struct tty_ldisc *ld;
1902 if (!ch || ch->magic != DGAP_CHANNEL_MAGIC)
1905 tp = ch->ch_tun.un_tty;
1913 if(!bd || bd->magic != DGAP_BOARD_MAGIC)
1916 DPR_READ(("dgap_input start\n"));
1918 DGAP_LOCK(bd->bd_lock, lock_flags);
1919 DGAP_LOCK(ch->ch_lock, lock_flags2);
1922 * Figure the number of characters in the buffer.
1923 * Exit immediately if none.
1926 rmask = ch->ch_rsize - 1;
1928 head = readw(&(bs->rx_head));
1930 tail = readw(&(bs->rx_tail));
1933 data_len = (head - tail) & rmask;
1935 if (data_len == 0) {
1936 writeb(1, &(bs->idata));
1937 DGAP_UNLOCK(ch->ch_lock, lock_flags2);
1938 DGAP_UNLOCK(bd->bd_lock, lock_flags);
1939 DPR_READ(("No data on port %d\n", ch->ch_portnum));
1944 * If the device is not open, or CREAD is off, flush
1945 * input data and return immediately.
1947 if ((bd->state != BOARD_READY) || !tp || (tp->magic != TTY_MAGIC) ||
1948 !(ch->ch_tun.un_flags & UN_ISOPEN) || !(tp->termios.c_cflag & CREAD) ||
1949 (ch->ch_tun.un_flags & UN_CLOSING)) {
1951 DPR_READ(("input. dropping %d bytes on port %d...\n", data_len, ch->ch_portnum));
1952 DPR_READ(("input. tp: %p tp->magic: %x MAGIC:%x ch flags: %x\n",
1953 tp, tp ? tp->magic : 0, TTY_MAGIC, ch->ch_tun.un_flags));
1954 writew(head, &(bs->rx_tail));
1955 writeb(1, &(bs->idata));
1956 DGAP_UNLOCK(ch->ch_lock, lock_flags2);
1957 DGAP_UNLOCK(bd->bd_lock, lock_flags);
1962 * If we are throttled, simply don't read any data.
1964 if (ch->ch_flags & CH_RXBLOCK) {
1965 writeb(1, &(bs->idata));
1966 DGAP_UNLOCK(ch->ch_lock, lock_flags2);
1967 DGAP_UNLOCK(bd->bd_lock, lock_flags);
1968 DPR_READ(("Port %d throttled, not reading any data. head: %x tail: %x\n",
1969 ch->ch_portnum, head, tail));
1976 tmpchar = readb(&(bs->orun));
1978 ch->ch_err_overrun++;
1979 writeb(0, &(bs->orun));
1982 DPR_READ(("dgap_input start 2\n"));
1984 /* Decide how much data we can send into the tty layer */
1985 flip_len = TTY_FLIPBUF_SIZE;
1987 /* Chop down the length, if needed */
1988 len = min(data_len, flip_len);
1989 len = min(len, (N_TTY_BUF_SIZE - 1));
1991 ld = tty_ldisc_ref(tp);
1993 #ifdef TTY_DONT_FLIP
1995 * If the DONT_FLIP flag is on, don't flush our buffer, and act
1996 * like the ld doesn't have any space to put the data right now.
1998 if (test_bit(TTY_DONT_FLIP, &tp->flags))
2003 * If we were unable to get a reference to the ld,
2004 * don't flush our buffer, and act like the ld doesn't
2005 * have any space to put the data right now.
2011 * If ld doesn't have a pointer to a receive_buf function,
2012 * flush the data, then act like the ld doesn't have any
2013 * space to put the data right now.
2015 if (!ld->ops->receive_buf) {
2016 writew(head, &(bs->rx_tail));
2022 writeb(1, &(bs->idata));
2023 DGAP_UNLOCK(ch->ch_lock, lock_flags2);
2024 DGAP_UNLOCK(bd->bd_lock, lock_flags);
2025 DPR_READ(("dgap_input 1 - finish\n"));
2027 tty_ldisc_deref(ld);
2031 buf = ch->ch_bd->flipbuf;
2035 * n now contains the most amount of data we can copy,
2036 * bounded either by our buffer size or the amount
2037 * of data the card actually has pending...
2041 s = ((head >= tail) ? head : ch->ch_rsize) - tail;
2047 memcpy_fromio(buf, (char *) ch->ch_raddr + tail, s);
2048 dgap_sniff_nowait_nolock(ch, "USER READ", buf, s);
2054 /* Flip queue if needed */
2058 writew(tail, &(bs->rx_tail));
2059 writeb(1, &(bs->idata));
2060 ch->ch_rxcount += len;
2063 * If we are completely raw, we don't need to go through a lot
2064 * of the tty layers that exist.
2065 * In this case, we take the shortest and fastest route we
2066 * can to relay the data to the user.
2068 * On the other hand, if we are not raw, we need to go through
2069 * the tty layer, which has its API more well defined.
2071 if (I_PARMRK(tp) || I_BRKINT(tp) || I_INPCK(tp)) {
2072 dgap_parity_scan(ch, ch->ch_bd->flipbuf, ch->ch_bd->flipflagbuf, &len);
2074 len = tty_buffer_request_room(tp->port, len);
2075 tty_insert_flip_string_flags(tp->port, ch->ch_bd->flipbuf,
2076 ch->ch_bd->flipflagbuf, len);
2079 len = tty_buffer_request_room(tp->port, len);
2080 tty_insert_flip_string(tp->port, ch->ch_bd->flipbuf, len);
2083 DGAP_UNLOCK(ch->ch_lock, lock_flags2);
2084 DGAP_UNLOCK(bd->bd_lock, lock_flags);
2086 /* Tell the tty layer its okay to "eat" the data now */
2087 tty_flip_buffer_push(tp->port);
2090 tty_ldisc_deref(ld);
2092 DPR_READ(("dgap_input - finish\n"));
2096 /************************************************************************
2097 * Determines when CARRIER changes state and takes appropriate
2099 ************************************************************************/
2100 static void dgap_carrier(struct channel_t *ch)
2104 int virt_carrier = 0;
2105 int phys_carrier = 0;
2107 DPR_CARR(("dgap_carrier called...\n"));
2109 if (!ch || ch->magic != DGAP_CHANNEL_MAGIC)
2114 if (!bd || bd->magic != DGAP_BOARD_MAGIC)
2117 /* Make sure altpin is always set correctly */
2118 if (ch->ch_digi.digi_flags & DIGI_ALTPIN) {
2123 ch->ch_dsr = DM_DSR;
2127 if (ch->ch_mistat & D_CD(ch)) {
2128 DPR_CARR(("mistat: %x D_CD: %x\n", ch->ch_mistat, D_CD(ch)));
2132 if (ch->ch_digi.digi_flags & DIGI_FORCEDCD) {
2136 if (ch->ch_c_cflag & CLOCAL) {
2141 DPR_CARR(("DCD: physical: %d virt: %d\n", phys_carrier, virt_carrier));
2144 * Test for a VIRTUAL carrier transition to HIGH.
2146 if (((ch->ch_flags & CH_FCAR) == 0) && (virt_carrier == 1)) {
2149 * When carrier rises, wake any threads waiting
2150 * for carrier in the open routine.
2153 DPR_CARR(("carrier: virt DCD rose\n"));
2155 if (waitqueue_active(&(ch->ch_flags_wait)))
2156 wake_up_interruptible(&ch->ch_flags_wait);
2160 * Test for a PHYSICAL carrier transition to HIGH.
2162 if (((ch->ch_flags & CH_CD) == 0) && (phys_carrier == 1)) {
2165 * When carrier rises, wake any threads waiting
2166 * for carrier in the open routine.
2169 DPR_CARR(("carrier: physical DCD rose\n"));
2171 if (waitqueue_active(&(ch->ch_flags_wait)))
2172 wake_up_interruptible(&ch->ch_flags_wait);
2176 * Test for a PHYSICAL transition to low, so long as we aren't
2177 * currently ignoring physical transitions (which is what "virtual
2178 * carrier" indicates).
2180 * The transition of the virtual carrier to low really doesn't
2181 * matter... it really only means "ignore carrier state", not
2182 * "make pretend that carrier is there".
2184 if ((virt_carrier == 0) && ((ch->ch_flags & CH_CD) != 0) &&
2185 (phys_carrier == 0))
2189 * When carrier drops:
2191 * Drop carrier on all open units.
2193 * Flush queues, waking up any task waiting in the
2196 * Send a hangup to the control terminal.
2198 * Enable all select calls.
2200 if (waitqueue_active(&(ch->ch_flags_wait)))
2201 wake_up_interruptible(&ch->ch_flags_wait);
2203 if (ch->ch_tun.un_open_count > 0) {
2204 DPR_CARR(("Sending tty hangup\n"));
2205 tty_hangup(ch->ch_tun.un_tty);
2208 if (ch->ch_pun.un_open_count > 0) {
2209 DPR_CARR(("Sending pr hangup\n"));
2210 tty_hangup(ch->ch_pun.un_tty);
2215 * Make sure that our cached values reflect the current reality.
2217 if (virt_carrier == 1)
2218 ch->ch_flags |= CH_FCAR;
2220 ch->ch_flags &= ~CH_FCAR;
2222 if (phys_carrier == 1)
2223 ch->ch_flags |= CH_CD;
2225 ch->ch_flags &= ~CH_CD;
2229 /************************************************************************
2231 * TTY Entry points and helper functions
2233 ************************************************************************/
2239 static int dgap_tty_open(struct tty_struct *tty, struct file *file)
2241 struct board_t *brd;
2242 struct channel_t *ch;
2254 major = MAJOR(tty_devnum(tty));
2255 minor = MINOR(tty_devnum(tty));
2261 /* Get board pointer from our array of majors we have allocated */
2262 brd = dgap_BoardsByMajor[major];
2268 * If board is not yet up to a state of READY, go to
2269 * sleep waiting for it to happen or they cancel the open.
2271 rc = wait_event_interruptible(brd->state_wait,
2272 (brd->state & BOARD_READY));
2278 DGAP_LOCK(brd->bd_lock, lock_flags);
2280 /* The wait above should guarantee this cannot happen */
2281 if (brd->state != BOARD_READY) {
2282 DGAP_UNLOCK(brd->bd_lock, lock_flags);
2286 /* If opened device is greater than our number of ports, bail. */
2287 if (MINOR(tty_devnum(tty)) > brd->nasync) {
2288 DGAP_UNLOCK(brd->bd_lock, lock_flags);
2292 ch = brd->channels[minor];
2294 DGAP_UNLOCK(brd->bd_lock, lock_flags);
2298 /* Grab channel lock */
2299 DGAP_LOCK(ch->ch_lock, lock_flags2);
2301 /* Figure out our type */
2302 if (major == brd->dgap_Serial_Major) {
2303 un = &brd->channels[minor]->ch_tun;
2304 un->un_type = DGAP_SERIAL;
2306 else if (major == brd->dgap_TransparentPrint_Major) {
2307 un = &brd->channels[minor]->ch_pun;
2308 un->un_type = DGAP_PRINT;
2311 DGAP_UNLOCK(ch->ch_lock, lock_flags2);
2312 DGAP_UNLOCK(brd->bd_lock, lock_flags);
2313 DPR_OPEN(("%d Unknown TYPE!\n", __LINE__));
2317 /* Store our unit into driver_data, so we always have it available. */
2318 tty->driver_data = un;
2320 DPR_OPEN(("Open called. MAJOR: %d MINOR:%d unit: %p NAME: %s\n",
2321 MAJOR(tty_devnum(tty)), MINOR(tty_devnum(tty)), un, brd->name));
2324 * Error if channel info pointer is NULL.
2328 DGAP_UNLOCK(ch->ch_lock, lock_flags2);
2329 DGAP_UNLOCK(brd->bd_lock, lock_flags);
2330 DPR_OPEN(("%d BS is 0!\n", __LINE__));
2334 DPR_OPEN(("%d: tflag=%x pflag=%x\n", __LINE__, ch->ch_tun.un_flags, ch->ch_pun.un_flags));
2339 if (!(un->un_flags & UN_ISOPEN)) {
2340 /* Store important variables. */
2343 /* Maybe do something here to the TTY struct as well? */
2347 * Initialize if neither terminal or printer is open.
2349 if (!((ch->ch_tun.un_flags | ch->ch_pun.un_flags) & UN_ISOPEN)) {
2351 DPR_OPEN(("dgap_open: initializing channel in open...\n"));
2357 * Flush input queue.
2359 head = readw(&(bs->rx_head));
2360 writew(head, &(bs->rx_tail));
2363 ch->pscan_state = 0;
2364 ch->pscan_savechar = 0;
2366 ch->ch_c_cflag = tty->termios.c_cflag;
2367 ch->ch_c_iflag = tty->termios.c_iflag;
2368 ch->ch_c_oflag = tty->termios.c_oflag;
2369 ch->ch_c_lflag = tty->termios.c_lflag;
2370 ch->ch_startc = tty->termios.c_cc[VSTART];
2371 ch->ch_stopc = tty->termios.c_cc[VSTOP];
2373 /* TODO: flush our TTY struct here? */
2378 * Run param in case we changed anything
2383 * follow protocol for opening port
2386 DGAP_UNLOCK(ch->ch_lock, lock_flags2);
2387 DGAP_UNLOCK(brd->bd_lock, lock_flags);
2389 rc = dgap_block_til_ready(tty, file, ch);
2396 DPR_OPEN(("dgap_tty_open returning after dgap_block_til_ready "
2400 /* No going back now, increment our unit and channel counters */
2401 DGAP_LOCK(ch->ch_lock, lock_flags);
2402 ch->ch_open_count++;
2403 un->un_open_count++;
2404 un->un_flags |= (UN_ISOPEN);
2405 DGAP_UNLOCK(ch->ch_lock, lock_flags);
2407 DPR_OPEN(("dgap_tty_open finished\n"));
2413 * dgap_block_til_ready()
2415 * Wait for DCD, if needed.
2417 static int dgap_block_til_ready(struct tty_struct *tty, struct file *file, struct channel_t *ch)
2420 struct un_t *un = NULL;
2423 int sleep_on_un_flags = 0;
2425 if (!tty || tty->magic != TTY_MAGIC || !file || !ch || ch->magic != DGAP_CHANNEL_MAGIC) {
2429 un = tty->driver_data;
2430 if (!un || un->magic != DGAP_UNIT_MAGIC) {
2434 DPR_OPEN(("dgap_block_til_ready - before block.\n"));
2436 DGAP_LOCK(ch->ch_lock, lock_flags);
2443 sleep_on_un_flags = 0;
2446 * If board has failed somehow during our sleep, bail with error.
2448 if (ch->ch_bd->state == BOARD_FAILED) {
2453 /* If tty was hung up, break out of loop and set error. */
2454 if (tty_hung_up_p(file)) {
2460 * If either unit is in the middle of the fragile part of close,
2461 * we just cannot touch the channel safely.
2462 * Go back to sleep, knowing that when the channel can be
2463 * touched safely, the close routine will signal the
2464 * ch_wait_flags to wake us back up.
2466 if (!((ch->ch_tun.un_flags | ch->ch_pun.un_flags) & UN_CLOSING)) {
2469 * Our conditions to leave cleanly and happily:
2470 * 1) NONBLOCKING on the tty is set.
2472 * 3) DCD (fake or real) is active.
2475 if (file->f_flags & O_NONBLOCK) {
2479 if (tty->flags & (1 << TTY_IO_ERROR)) {
2483 if (ch->ch_flags & CH_CD) {
2484 DPR_OPEN(("%d: ch_flags: %x\n", __LINE__, ch->ch_flags));
2488 if (ch->ch_flags & CH_FCAR) {
2489 DPR_OPEN(("%d: ch_flags: %x\n", __LINE__, ch->ch_flags));
2494 sleep_on_un_flags = 1;
2498 * If there is a signal pending, the user probably
2499 * interrupted (ctrl-c) us.
2500 * Leave loop with error set.
2502 if (signal_pending(current)) {
2503 DPR_OPEN(("%d: signal pending...\n", __LINE__));
2504 retval = -ERESTARTSYS;
2508 DPR_OPEN(("dgap_block_til_ready - blocking.\n"));
2511 * Store the flags before we let go of channel lock
2513 if (sleep_on_un_flags)
2514 old_flags = ch->ch_tun.un_flags | ch->ch_pun.un_flags;
2516 old_flags = ch->ch_flags;
2519 * Let go of channel lock before calling schedule.
2520 * Our poller will get any FEP events and wake us up when DCD
2521 * eventually goes active.
2524 DGAP_UNLOCK(ch->ch_lock, lock_flags);
2526 DPR_OPEN(("Going to sleep on %s flags...\n",
2527 (sleep_on_un_flags ? "un" : "ch")));
2530 * Wait for something in the flags to change from the current value.
2532 if (sleep_on_un_flags) {
2533 retval = wait_event_interruptible(un->un_flags_wait,
2534 (old_flags != (ch->ch_tun.un_flags | ch->ch_pun.un_flags)));
2537 retval = wait_event_interruptible(ch->ch_flags_wait,
2538 (old_flags != ch->ch_flags));
2541 DPR_OPEN(("After sleep... retval: %x\n", retval));
2544 * We got woken up for some reason.
2545 * Before looping around, grab our channel lock.
2547 DGAP_LOCK(ch->ch_lock, lock_flags);
2552 DGAP_UNLOCK(ch->ch_lock, lock_flags);
2554 DPR_OPEN(("dgap_block_til_ready - after blocking.\n"));
2557 DPR_OPEN(("dgap_block_til_ready - done. error. retval: %x\n", retval));
2561 DPR_OPEN(("dgap_block_til_ready - done no error. jiffies: %lu\n", jiffies));
2570 * Hangup the port. Like a close, but don't wait for output to drain.
2572 static void dgap_tty_hangup(struct tty_struct *tty)
2575 struct channel_t *ch;
2578 if (!tty || tty->magic != TTY_MAGIC)
2581 un = tty->driver_data;
2582 if (!un || un->magic != DGAP_UNIT_MAGIC)
2586 if (!ch || ch->magic != DGAP_CHANNEL_MAGIC)
2590 if (!bd || bd->magic != DGAP_BOARD_MAGIC)
2593 DPR_CLOSE(("dgap_hangup called. ch->ch_open_count: %d un->un_open_count: %d\n",
2594 ch->ch_open_count, un->un_open_count));
2596 /* flush the transmit queues */
2597 dgap_tty_flush_buffer(tty);
2599 DPR_CLOSE(("dgap_hangup finished. ch->ch_open_count: %d un->un_open_count: %d\n",
2600 ch->ch_open_count, un->un_open_count));
2609 static void dgap_tty_close(struct tty_struct *tty, struct file *file)
2611 struct ktermios *ts;
2613 struct channel_t *ch;
2618 if (!tty || tty->magic != TTY_MAGIC)
2621 un = tty->driver_data;
2622 if (!un || un->magic != DGAP_UNIT_MAGIC)
2626 if (!ch || ch->magic != DGAP_CHANNEL_MAGIC)
2630 if (!bd || bd->magic != DGAP_BOARD_MAGIC)
2635 DPR_CLOSE(("Close called\n"));
2637 DGAP_LOCK(ch->ch_lock, lock_flags);
2640 * Determine if this is the last close or not - and if we agree about
2641 * which type of close it is with the Line Discipline
2643 if ((tty->count == 1) && (un->un_open_count != 1)) {
2645 * Uh, oh. tty->count is 1, which means that the tty
2646 * structure will be freed. un_open_count should always
2647 * be one in these conditions. If it's greater than
2648 * one, we've got real problems, since it means the
2649 * serial port won't be shutdown.
2651 APR(("tty->count is 1, un open count is %d\n", un->un_open_count));
2652 un->un_open_count = 1;
2655 if (--un->un_open_count < 0) {
2656 APR(("bad serial port open count of %d\n", un->un_open_count));
2657 un->un_open_count = 0;
2660 ch->ch_open_count--;
2662 if (ch->ch_open_count && un->un_open_count) {
2663 DPR_CLOSE(("dgap_tty_close: not last close ch: %d un:%d\n",
2664 ch->ch_open_count, un->un_open_count));
2666 DGAP_UNLOCK(ch->ch_lock, lock_flags);
2670 /* OK, its the last close on the unit */
2671 DPR_CLOSE(("dgap_tty_close - last close on unit procedures\n"));
2673 un->un_flags |= UN_CLOSING;
2678 * Only officially close channel if count is 0 and
2679 * DIGI_PRINTER bit is not set.
2681 if ((ch->ch_open_count == 0) && !(ch->ch_digi.digi_flags & DIGI_PRINTER)) {
2683 ch->ch_flags &= ~(CH_RXBLOCK);
2685 DGAP_UNLOCK(ch->ch_lock, lock_flags);
2687 /* wait for output to drain */
2688 /* This will also return if we take an interrupt */
2690 DPR_CLOSE(("Calling wait_for_drain\n"));
2691 rc = dgap_wait_for_drain(tty);
2692 DPR_CLOSE(("After calling wait_for_drain\n"));
2695 DPR_BASIC(("dgap_tty_close - bad return: %d ", rc));
2698 dgap_tty_flush_buffer(tty);
2699 tty_ldisc_flush(tty);
2701 DGAP_LOCK(ch->ch_lock, lock_flags);
2706 * If we have HUPCL set, lower DTR and RTS
2708 if (ch->ch_c_cflag & HUPCL ) {
2709 DPR_CLOSE(("Close. HUPCL set, dropping DTR/RTS\n"));
2710 ch->ch_mostat &= ~(D_RTS(ch)|D_DTR(ch));
2711 dgap_cmdb( ch, SMODEM, 0, D_DTR(ch)|D_RTS(ch), 0 );
2714 * Go to sleep to ensure RTS/DTR
2715 * have been dropped for modems to see it.
2717 if (ch->ch_close_delay) {
2718 DPR_CLOSE(("Close. Sleeping for RTS/DTR drop\n"));
2720 DGAP_UNLOCK(ch->ch_lock, lock_flags);
2721 dgap_ms_sleep(ch->ch_close_delay);
2722 DGAP_LOCK(ch->ch_lock, lock_flags);
2724 DPR_CLOSE(("Close. After sleeping for RTS/DTR drop\n"));
2728 ch->pscan_state = 0;
2729 ch->pscan_savechar = 0;
2730 ch->ch_baud_info = 0;
2735 * turn off print device when closing print device.
2737 if ((un->un_type == DGAP_PRINT) && (ch->ch_flags & CH_PRON) ) {
2738 dgap_wmove(ch, ch->ch_digi.digi_offstr,
2739 (int) ch->ch_digi.digi_offlen);
2740 ch->ch_flags &= ~CH_PRON;
2744 un->un_flags &= ~(UN_ISOPEN | UN_CLOSING);
2745 tty->driver_data = NULL;
2747 DPR_CLOSE(("Close. Doing wakeups\n"));
2748 wake_up_interruptible(&ch->ch_flags_wait);
2749 wake_up_interruptible(&un->un_flags_wait);
2751 DGAP_UNLOCK(ch->ch_lock, lock_flags);
2753 DPR_BASIC(("dgap_tty_close - complete\n"));
2758 * dgap_tty_chars_in_buffer()
2760 * Return number of characters that have not been transmitted yet.
2762 * This routine is used by the line discipline to determine if there
2763 * is data waiting to be transmitted/drained/flushed or not.
2765 static int dgap_tty_chars_in_buffer(struct tty_struct *tty)
2767 struct board_t *bd = NULL;
2768 struct channel_t *ch = NULL;
2769 struct un_t *un = NULL;
2770 struct bs_t *bs = NULL;
2773 u16 thead, ttail, tmask, chead, ctail;
2774 ulong lock_flags = 0;
2775 ulong lock_flags2 = 0;
2780 un = tty->driver_data;
2781 if (!un || un->magic != DGAP_UNIT_MAGIC)
2785 if (!ch || ch->magic != DGAP_CHANNEL_MAGIC)
2789 if (!bd || bd->magic != DGAP_BOARD_MAGIC)
2796 DGAP_LOCK(bd->bd_lock, lock_flags);
2797 DGAP_LOCK(ch->ch_lock, lock_flags2);
2799 tmask = (ch->ch_tsize - 1);
2801 /* Get Transmit queue pointers */
2802 thead = readw(&(bs->tx_head)) & tmask;
2803 ttail = readw(&(bs->tx_tail)) & tmask;
2805 /* Get tbusy flag */
2806 tbusy = readb(&(bs->tbusy));
2808 /* Get Command queue pointers */
2809 chead = readw(&(ch->ch_cm->cm_head));
2810 ctail = readw(&(ch->ch_cm->cm_tail));
2812 DGAP_UNLOCK(ch->ch_lock, lock_flags2);
2813 DGAP_UNLOCK(bd->bd_lock, lock_flags);
2816 * The only way we know for sure if there is no pending
2817 * data left to be transferred, is if:
2818 * 1) Transmit head and tail are equal (empty).
2819 * 2) Command queue head and tail are equal (empty).
2820 * 3) The "TBUSY" flag is 0. (Transmitter not busy).
2823 if ((ttail == thead) && (tbusy == 0) && (chead == ctail)) {
2828 chars = thead - ttail;
2830 chars = thead - ttail + ch->ch_tsize;
2832 * Fudge factor here.
2833 * If chars is zero, we know that the command queue had
2834 * something in it or tbusy was set. Because we cannot
2835 * be sure if there is still some data to be transmitted,
2836 * lets lie, and tell ld we have 1 byte left.
2840 * If TBUSY is still set, and our tx buffers are empty,
2841 * force the firmware to send me another wakeup after
2842 * TBUSY has been cleared.
2845 DGAP_LOCK(ch->ch_lock, lock_flags);
2846 un->un_flags |= UN_EMPTY;
2847 writeb(1, &(bs->iempty));
2848 DGAP_UNLOCK(ch->ch_lock, lock_flags);
2854 DPR_WRITE(("dgap_tty_chars_in_buffer. Port: %x - %d (head: %d tail: %d tsize: %d)\n",
2855 ch->ch_portnum, chars, thead, ttail, ch->ch_tsize));
2860 static int dgap_wait_for_drain(struct tty_struct *tty)
2862 struct channel_t *ch;
2867 ulong lock_flags = 0;
2869 if (!tty || tty->magic != TTY_MAGIC)
2872 un = tty->driver_data;
2873 if (!un || un->magic != DGAP_UNIT_MAGIC)
2877 if (!ch || ch->magic != DGAP_CHANNEL_MAGIC)
2886 DPR_DRAIN(("dgap_wait_for_drain start\n"));
2888 /* Loop until data is drained */
2889 while (count != 0) {
2891 count = dgap_tty_chars_in_buffer(tty);
2896 /* Set flag waiting for drain */
2897 DGAP_LOCK(ch->ch_lock, lock_flags);
2898 un->un_flags |= UN_EMPTY;
2899 writeb(1, &(bs->iempty));
2900 DGAP_UNLOCK(ch->ch_lock, lock_flags);
2902 /* Go to sleep till we get woken up */
2903 ret = wait_event_interruptible(un->un_flags_wait, ((un->un_flags & UN_EMPTY) == 0));
2904 /* If ret is non-zero, user ctrl-c'ed us */
2910 DGAP_LOCK(ch->ch_lock, lock_flags);
2911 un->un_flags &= ~(UN_EMPTY);
2912 DGAP_UNLOCK(ch->ch_lock, lock_flags);
2914 DPR_DRAIN(("dgap_wait_for_drain finish\n"));
2922 * Reduces bytes_available to the max number of characters
2923 * that can be sent currently given the maxcps value, and
2924 * returns the new bytes_available. This only affects printer
2927 static int dgap_maxcps_room(struct tty_struct *tty, int bytes_available)
2929 struct channel_t *ch = NULL;
2930 struct un_t *un = NULL;
2933 return (bytes_available);
2935 un = tty->driver_data;
2936 if (!un || un->magic != DGAP_UNIT_MAGIC)
2937 return (bytes_available);
2940 if (!ch || ch->magic != DGAP_CHANNEL_MAGIC)
2941 return (bytes_available);
2944 * If its not the Transparent print device, return
2945 * the full data amount.
2947 if (un->un_type != DGAP_PRINT)
2948 return (bytes_available);
2950 if (ch->ch_digi.digi_maxcps > 0 && ch->ch_digi.digi_bufsize > 0 ) {
2952 unsigned long current_time = jiffies;
2953 unsigned long buffer_time = current_time +
2954 (HZ * ch->ch_digi.digi_bufsize) / ch->ch_digi.digi_maxcps;
2956 if (ch->ch_cpstime < current_time) {
2957 /* buffer is empty */
2958 ch->ch_cpstime = current_time; /* reset ch_cpstime */
2959 cps_limit = ch->ch_digi.digi_bufsize;
2961 else if (ch->ch_cpstime < buffer_time) {
2962 /* still room in the buffer */
2963 cps_limit = ((buffer_time - ch->ch_cpstime) * ch->ch_digi.digi_maxcps) / HZ;
2966 /* no room in the buffer */
2970 bytes_available = min(cps_limit, bytes_available);
2973 return (bytes_available);
2977 static inline void dgap_set_firmware_event(struct un_t *un, unsigned int event)
2979 struct channel_t *ch = NULL;
2980 struct bs_t *bs = NULL;
2982 if (!un || un->magic != DGAP_UNIT_MAGIC)
2985 if (!ch || ch->magic != DGAP_CHANNEL_MAGIC)
2991 if ((event & UN_LOW) != 0) {
2992 if ((un->un_flags & UN_LOW) == 0) {
2993 un->un_flags |= UN_LOW;
2994 writeb(1, &(bs->ilow));
2997 if ((event & UN_LOW) != 0) {
2998 if ((un->un_flags & UN_EMPTY) == 0) {
2999 un->un_flags |= UN_EMPTY;
3000 writeb(1, &(bs->iempty));
3007 * dgap_tty_write_room()
3009 * Return space available in Tx buffer
3011 static int dgap_tty_write_room(struct tty_struct *tty)
3013 struct channel_t *ch = NULL;
3014 struct un_t *un = NULL;
3015 struct bs_t *bs = NULL;
3016 u16 head, tail, tmask;
3018 ulong lock_flags = 0;
3020 if (tty == NULL || dgap_TmpWriteBuf == NULL)
3023 un = tty->driver_data;
3024 if (!un || un->magic != DGAP_UNIT_MAGIC)
3028 if (!ch || ch->magic != DGAP_CHANNEL_MAGIC)
3035 DGAP_LOCK(ch->ch_lock, lock_flags);
3037 tmask = ch->ch_tsize - 1;
3038 head = readw(&(bs->tx_head)) & tmask;
3039 tail = readw(&(bs->tx_tail)) & tmask;
3041 if ((ret = tail - head - 1) < 0)
3042 ret += ch->ch_tsize;
3044 /* Limit printer to maxcps */
3045 ret = dgap_maxcps_room(tty, ret);
3048 * If we are printer device, leave space for
3049 * possibly both the on and off strings.
3051 if (un->un_type == DGAP_PRINT) {
3052 if (!(ch->ch_flags & CH_PRON))
3053 ret -= ch->ch_digi.digi_onlen;
3054 ret -= ch->ch_digi.digi_offlen;
3057 if (ch->ch_flags & CH_PRON)
3058 ret -= ch->ch_digi.digi_offlen;
3065 * Schedule FEP to wake us up if needed.
3067 * TODO: This might be overkill...
3068 * Do we really need to schedule callbacks from the FEP
3069 * in every case? Can we get smarter based on ret?
3071 dgap_set_firmware_event(un, UN_LOW | UN_EMPTY);
3072 DGAP_UNLOCK(ch->ch_lock, lock_flags);
3074 DPR_WRITE(("dgap_tty_write_room - %d tail: %d head: %d\n", ret, tail, head));
3081 * dgap_tty_put_char()
3083 * Put a character into ch->ch_buf
3085 * - used by the line discipline for OPOST processing
3087 static int dgap_tty_put_char(struct tty_struct *tty, unsigned char c)
3090 * Simply call tty_write.
3092 DPR_WRITE(("dgap_tty_put_char called\n"));
3093 dgap_tty_write(tty, &c, 1);
3101 * Take data from the user or kernel and send it out to the FEP.
3102 * In here exists all the Transparent Print magic as well.
3104 static int dgap_tty_write(struct tty_struct *tty, const unsigned char *buf, int count)
3106 struct channel_t *ch = NULL;
3107 struct un_t *un = NULL;
3108 struct bs_t *bs = NULL;
3110 u16 head, tail, tmask, remain;
3111 int bufcount = 0, n = 0;
3116 if (tty == NULL || dgap_TmpWriteBuf == NULL)
3119 un = tty->driver_data;
3120 if (!un || un->magic != DGAP_UNIT_MAGIC)
3124 if (!ch || ch->magic != DGAP_CHANNEL_MAGIC)
3134 DPR_WRITE(("dgap_tty_write: Port: %x tty=%p user=%d len=%d\n",
3135 ch->ch_portnum, tty, from_user, count));
3138 * Store original amount of characters passed in.
3139 * This helps to figure out if we should ask the FEP
3140 * to send us an event when it has more space available.
3144 DGAP_LOCK(ch->ch_lock, lock_flags);
3146 /* Get our space available for the channel from the board */
3147 tmask = ch->ch_tsize - 1;
3148 head = readw(&(bs->tx_head)) & tmask;
3149 tail = readw(&(bs->tx_tail)) & tmask;
3151 if ((bufcount = tail - head - 1) < 0)
3152 bufcount += ch->ch_tsize;
3154 DPR_WRITE(("%d: bufcount: %x count: %x tail: %x head: %x tmask: %x\n",
3155 __LINE__, bufcount, count, tail, head, tmask));
3158 * Limit printer output to maxcps overall, with bursts allowed
3159 * up to bufsize characters.
3161 bufcount = dgap_maxcps_room(tty, bufcount);
3164 * Take minimum of what the user wants to send, and the
3165 * space available in the FEP buffer.
3167 count = min(count, bufcount);
3170 * Bail if no space left.
3173 dgap_set_firmware_event(un, UN_LOW | UN_EMPTY);
3174 DGAP_UNLOCK(ch->ch_lock, lock_flags);
3179 * Output the printer ON string, if we are in terminal mode, but
3180 * need to be in printer mode.
3182 if ((un->un_type == DGAP_PRINT) && !(ch->ch_flags & CH_PRON)) {
3183 dgap_wmove(ch, ch->ch_digi.digi_onstr,
3184 (int) ch->ch_digi.digi_onlen);
3185 head = readw(&(bs->tx_head)) & tmask;
3186 ch->ch_flags |= CH_PRON;
3190 * On the other hand, output the printer OFF string, if we are
3191 * currently in printer mode, but need to output to the terminal.
3193 if ((un->un_type != DGAP_PRINT) && (ch->ch_flags & CH_PRON)) {
3194 dgap_wmove(ch, ch->ch_digi.digi_offstr,
3195 (int) ch->ch_digi.digi_offlen);
3196 head = readw(&(bs->tx_head)) & tmask;
3197 ch->ch_flags &= ~CH_PRON;
3201 * If there is nothing left to copy, or I can't handle any more data, leave.
3204 dgap_set_firmware_event(un, UN_LOW | UN_EMPTY);
3205 DGAP_UNLOCK(ch->ch_lock, lock_flags);
3211 count = min(count, WRITEBUFLEN);
3213 DGAP_UNLOCK(ch->ch_lock, lock_flags);
3216 * If data is coming from user space, copy it into a temporary
3217 * buffer so we don't get swapped out while doing the copy to
3220 /* we're allowed to block if it's from_user */
3221 if (down_interruptible(&dgap_TmpWriteSem)) {
3225 if (copy_from_user(dgap_TmpWriteBuf, (const uchar __user *) buf, count)) {
3226 up(&dgap_TmpWriteSem);
3227 printk("Write: Copy from user failed!\n");
3231 DGAP_LOCK(ch->ch_lock, lock_flags);
3233 buf = dgap_TmpWriteBuf;
3239 * If the write wraps over the top of the circular buffer,
3240 * move the portion up to the wrap point, and reset the
3241 * pointers to the bottom.
3243 remain = ch->ch_tstart + ch->ch_tsize - head;
3247 vaddr = ch->ch_taddr + head;
3249 memcpy_toio(vaddr, (uchar *) buf, remain);
3250 dgap_sniff_nowait_nolock(ch, "USER WRITE", (uchar *) buf, remain);
3252 head = ch->ch_tstart;
3259 * Move rest of data.
3261 vaddr = ch->ch_taddr + head;
3264 memcpy_toio(vaddr, (uchar *) buf, remain);
3265 dgap_sniff_nowait_nolock(ch, "USER WRITE", (uchar *) buf, remain);
3272 ch->ch_txcount += count;
3274 writew(head, &(bs->tx_head));
3278 dgap_set_firmware_event(un, UN_LOW | UN_EMPTY);
3281 * If this is the print device, and the
3282 * printer is still on, we need to turn it
3283 * off before going idle. If the buffer is
3284 * non-empty, wait until it goes empty.
3285 * Otherwise turn it off right now.
3287 if ((un->un_type == DGAP_PRINT) && (ch->ch_flags & CH_PRON)) {
3288 tail = readw(&(bs->tx_tail)) & tmask;
3291 un->un_flags |= UN_EMPTY;
3292 writeb(1, &(bs->iempty));
3295 dgap_wmove(ch, ch->ch_digi.digi_offstr,
3296 (int) ch->ch_digi.digi_offlen);
3297 head = readw(&(bs->tx_head)) & tmask;
3298 ch->ch_flags &= ~CH_PRON;
3302 /* Update printer buffer empty time. */
3303 if ((un->un_type == DGAP_PRINT) && (ch->ch_digi.digi_maxcps > 0)
3304 && (ch->ch_digi.digi_bufsize > 0)) {
3305 ch->ch_cpstime += (HZ * count) / ch->ch_digi.digi_maxcps;
3309 DGAP_UNLOCK(ch->ch_lock, lock_flags);
3310 up(&dgap_TmpWriteSem);
3313 DGAP_UNLOCK(ch->ch_lock, lock_flags);
3316 DPR_WRITE(("Write finished - Write %d bytes of %d.\n", count, orig_count));
3324 * Return modem signals to ld.
3326 static int dgap_tty_tiocmget(struct tty_struct *tty)
3328 struct channel_t *ch;
3334 if (!tty || tty->magic != TTY_MAGIC)
3337 un = tty->driver_data;
3338 if (!un || un->magic != DGAP_UNIT_MAGIC)
3342 if (!ch || ch->magic != DGAP_CHANNEL_MAGIC)
3345 DPR_IOCTL(("dgap_tty_tiocmget start\n"));
3347 DGAP_LOCK(ch->ch_lock, lock_flags);
3349 mstat = readb(&(ch->ch_bs->m_stat));
3350 /* Append any outbound signals that might be pending... */
3351 mstat |= ch->ch_mostat;
3353 DGAP_UNLOCK(ch->ch_lock, lock_flags);
3357 if (mstat & D_DTR(ch))
3358 result |= TIOCM_DTR;
3359 if (mstat & D_RTS(ch))
3360 result |= TIOCM_RTS;
3361 if (mstat & D_CTS(ch))
3362 result |= TIOCM_CTS;
3363 if (mstat & D_DSR(ch))
3364 result |= TIOCM_DSR;
3365 if (mstat & D_RI(ch))
3367 if (mstat & D_CD(ch))
3370 DPR_IOCTL(("dgap_tty_tiocmget finish\n"));
3377 * dgap_tty_tiocmset()
3379 * Set modem signals, called by ld.
3382 static int dgap_tty_tiocmset(struct tty_struct *tty,
3383 unsigned int set, unsigned int clear)
3386 struct channel_t *ch;
3392 if (!tty || tty->magic != TTY_MAGIC)
3395 un = tty->driver_data;
3396 if (!un || un->magic != DGAP_UNIT_MAGIC)
3400 if (!ch || ch->magic != DGAP_CHANNEL_MAGIC)
3404 if (!bd || bd->magic != DGAP_BOARD_MAGIC)
3407 DPR_IOCTL(("dgap_tty_tiocmset start\n"));
3409 DGAP_LOCK(bd->bd_lock, lock_flags);
3410 DGAP_LOCK(ch->ch_lock, lock_flags2);
3412 if (set & TIOCM_RTS) {
3413 ch->ch_mforce |= D_RTS(ch);
3414 ch->ch_mval |= D_RTS(ch);
3417 if (set & TIOCM_DTR) {
3418 ch->ch_mforce |= D_DTR(ch);
3419 ch->ch_mval |= D_DTR(ch);
3422 if (clear & TIOCM_RTS) {
3423 ch->ch_mforce |= D_RTS(ch);
3424 ch->ch_mval &= ~(D_RTS(ch));
3427 if (clear & TIOCM_DTR) {
3428 ch->ch_mforce |= D_DTR(ch);
3429 ch->ch_mval &= ~(D_DTR(ch));
3434 DGAP_UNLOCK(ch->ch_lock, lock_flags2);
3435 DGAP_UNLOCK(bd->bd_lock, lock_flags);
3437 DPR_IOCTL(("dgap_tty_tiocmset finish\n"));
3445 * dgap_tty_send_break()
3447 * Send a Break, called by ld.
3449 static int dgap_tty_send_break(struct tty_struct *tty, int msec)
3452 struct channel_t *ch;
3458 if (!tty || tty->magic != TTY_MAGIC)
3461 un = tty->driver_data;
3462 if (!un || un->magic != DGAP_UNIT_MAGIC)
3466 if (!ch || ch->magic != DGAP_CHANNEL_MAGIC)
3470 if (!bd || bd->magic != DGAP_BOARD_MAGIC)
3485 DPR_IOCTL(("dgap_tty_send_break start 1. %lx\n", jiffies));
3487 DGAP_LOCK(bd->bd_lock, lock_flags);
3488 DGAP_LOCK(ch->ch_lock, lock_flags2);
3490 dgap_cmdw(ch, SBREAK, (u16) SBREAK_TIME, 0);
3492 dgap_cmdw(ch, SBREAK, (u16) msec, 0);
3494 DGAP_UNLOCK(ch->ch_lock, lock_flags2);
3495 DGAP_UNLOCK(bd->bd_lock, lock_flags);
3497 DPR_IOCTL(("dgap_tty_send_break finish\n"));
3506 * dgap_tty_wait_until_sent()
3508 * wait until data has been transmitted, called by ld.
3510 static void dgap_tty_wait_until_sent(struct tty_struct *tty, int timeout)
3513 rc = dgap_wait_for_drain(tty);
3515 DPR_IOCTL(("dgap_tty_ioctl - bad return: %d ", rc));
3526 * send a high priority character, called by ld.
3528 static void dgap_tty_send_xchar(struct tty_struct *tty, char c)
3531 struct channel_t *ch;
3536 if (!tty || tty->magic != TTY_MAGIC)
3539 un = tty->driver_data;
3540 if (!un || un->magic != DGAP_UNIT_MAGIC)
3544 if (!ch || ch->magic != DGAP_CHANNEL_MAGIC)
3548 if (!bd || bd->magic != DGAP_BOARD_MAGIC)
3551 DPR_IOCTL(("dgap_tty_send_xchar start 1. %lx\n", jiffies));
3553 DGAP_LOCK(bd->bd_lock, lock_flags);
3554 DGAP_LOCK(ch->ch_lock, lock_flags2);
3557 * This is technically what we should do.
3558 * However, the NIST tests specifically want
3559 * to see each XON or XOFF character that it
3560 * sends, so lets just send each character
3564 if (c == STOP_CHAR(tty)) {
3565 dgap_cmdw(ch, RPAUSE, 0, 0);
3567 else if (c == START_CHAR(tty)) {
3568 dgap_cmdw(ch, RRESUME, 0, 0);
3571 dgap_wmove(ch, &c, 1);
3574 dgap_wmove(ch, &c, 1);
3577 DGAP_UNLOCK(ch->ch_lock, lock_flags2);
3578 DGAP_UNLOCK(bd->bd_lock, lock_flags);
3580 DPR_IOCTL(("dgap_tty_send_xchar finish\n"));
3589 * Return modem signals to ld.
3591 static int dgap_get_modem_info(struct channel_t *ch, unsigned int __user *value)
3598 DPR_IOCTL(("dgap_get_modem_info start\n"));
3600 if (!ch || ch->magic != DGAP_CHANNEL_MAGIC)
3603 DGAP_LOCK(ch->ch_lock, lock_flags);
3605 mstat = readb(&(ch->ch_bs->m_stat));
3606 /* Append any outbound signals that might be pending... */
3607 mstat |= ch->ch_mostat;
3609 DGAP_UNLOCK(ch->ch_lock, lock_flags);
3613 if (mstat & D_DTR(ch))
3614 result |= TIOCM_DTR;
3615 if (mstat & D_RTS(ch))
3616 result |= TIOCM_RTS;
3617 if (mstat & D_CTS(ch))
3618 result |= TIOCM_CTS;
3619 if (mstat & D_DSR(ch))
3620 result |= TIOCM_DSR;
3621 if (mstat & D_RI(ch))
3623 if (mstat & D_CD(ch))
3626 rc = put_user(result, value);
3628 DPR_IOCTL(("dgap_get_modem_info finish\n"));
3634 * dgap_set_modem_info()
3636 * Set modem signals, called by ld.
3638 static int dgap_set_modem_info(struct tty_struct *tty, unsigned int command, unsigned int __user *value)
3641 struct channel_t *ch;
3644 unsigned int arg = 0;
3648 if (!tty || tty->magic != TTY_MAGIC)
3651 un = tty->driver_data;
3652 if (!un || un->magic != DGAP_UNIT_MAGIC)
3656 if (!ch || ch->magic != DGAP_CHANNEL_MAGIC)
3660 if (!bd || bd->magic != DGAP_BOARD_MAGIC)
3663 DPR_IOCTL(("dgap_set_modem_info() start\n"));
3665 ret = get_user(arg, value);
3667 DPR_IOCTL(("dgap_set_modem_info %d ret: %x. finished.\n", __LINE__, ret));
3671 DPR_IOCTL(("dgap_set_modem_info: command: %x arg: %x\n", command, arg));
3675 if (arg & TIOCM_RTS) {
3676 ch->ch_mforce |= D_RTS(ch);
3677 ch->ch_mval |= D_RTS(ch);
3680 if (arg & TIOCM_DTR) {
3681 ch->ch_mforce |= D_DTR(ch);
3682 ch->ch_mval |= D_DTR(ch);
3688 if (arg & TIOCM_RTS) {
3689 ch->ch_mforce |= D_RTS(ch);
3690 ch->ch_mval &= ~(D_RTS(ch));
3693 if (arg & TIOCM_DTR) {
3694 ch->ch_mforce |= D_DTR(ch);
3695 ch->ch_mval &= ~(D_DTR(ch));
3701 ch->ch_mforce = D_DTR(ch)|D_RTS(ch);
3703 if (arg & TIOCM_RTS) {
3704 ch->ch_mval |= D_RTS(ch);
3707 ch->ch_mval &= ~(D_RTS(ch));
3710 if (arg & TIOCM_DTR) {
3711 ch->ch_mval |= (D_DTR(ch));
3714 ch->ch_mval &= ~(D_DTR(ch));
3723 DGAP_LOCK(bd->bd_lock, lock_flags);
3724 DGAP_LOCK(ch->ch_lock, lock_flags2);
3728 DGAP_UNLOCK(ch->ch_lock, lock_flags2);
3729 DGAP_UNLOCK(bd->bd_lock, lock_flags);
3731 DPR_IOCTL(("dgap_set_modem_info finish\n"));
3738 * dgap_tty_digigeta()
3740 * Ioctl to get the information for ditty.
3745 static int dgap_tty_digigeta(struct tty_struct *tty, struct digi_t __user *retinfo)
3747 struct channel_t *ch;
3755 if (!tty || tty->magic != TTY_MAGIC)
3758 un = tty->driver_data;
3759 if (!un || un->magic != DGAP_UNIT_MAGIC)
3763 if (!ch || ch->magic != DGAP_CHANNEL_MAGIC)
3766 memset(&tmp, 0, sizeof(tmp));
3768 DGAP_LOCK(ch->ch_lock, lock_flags);
3769 memcpy(&tmp, &ch->ch_digi, sizeof(tmp));
3770 DGAP_UNLOCK(ch->ch_lock, lock_flags);
3772 if (copy_to_user(retinfo, &tmp, sizeof(*retinfo)))
3780 * dgap_tty_digiseta()
3782 * Ioctl to set the information for ditty.
3787 static int dgap_tty_digiseta(struct tty_struct *tty, struct digi_t __user *new_info)
3790 struct channel_t *ch;
3792 struct digi_t new_digi;
3793 ulong lock_flags = 0;
3794 unsigned long lock_flags2;
3796 DPR_IOCTL(("DIGI_SETA start\n"));
3798 if (!tty || tty->magic != TTY_MAGIC)
3801 un = tty->driver_data;
3802 if (!un || un->magic != DGAP_UNIT_MAGIC)
3806 if (!ch || ch->magic != DGAP_CHANNEL_MAGIC)
3810 if (!bd || bd->magic != DGAP_BOARD_MAGIC)
3813 if (copy_from_user(&new_digi, new_info, sizeof(struct digi_t))) {
3814 DPR_IOCTL(("DIGI_SETA failed copy_from_user\n"));
3818 DGAP_LOCK(bd->bd_lock, lock_flags);
3819 DGAP_LOCK(ch->ch_lock, lock_flags2);
3821 memcpy(&ch->ch_digi, &new_digi, sizeof(struct digi_t));
3823 if (ch->ch_digi.digi_maxcps < 1)
3824 ch->ch_digi.digi_maxcps = 1;
3826 if (ch->ch_digi.digi_maxcps > 10000)
3827 ch->ch_digi.digi_maxcps = 10000;
3829 if (ch->ch_digi.digi_bufsize < 10)
3830 ch->ch_digi.digi_bufsize = 10;
3832 if (ch->ch_digi.digi_maxchar < 1)
3833 ch->ch_digi.digi_maxchar = 1;
3835 if (ch->ch_digi.digi_maxchar > ch->ch_digi.digi_bufsize)
3836 ch->ch_digi.digi_maxchar = ch->ch_digi.digi_bufsize;
3838 if (ch->ch_digi.digi_onlen > DIGI_PLEN)
3839 ch->ch_digi.digi_onlen = DIGI_PLEN;
3841 if (ch->ch_digi.digi_offlen > DIGI_PLEN)
3842 ch->ch_digi.digi_offlen = DIGI_PLEN;
3846 DGAP_UNLOCK(ch->ch_lock, lock_flags2);
3847 DGAP_UNLOCK(bd->bd_lock, lock_flags);
3849 DPR_IOCTL(("DIGI_SETA finish\n"));
3856 * dgap_tty_digigetedelay()
3858 * Ioctl to get the current edelay setting.
3863 static int dgap_tty_digigetedelay(struct tty_struct *tty, int __user *retinfo)
3865 struct channel_t *ch;
3873 if (!tty || tty->magic != TTY_MAGIC)
3876 un = tty->driver_data;
3877 if (!un || un->magic != DGAP_UNIT_MAGIC)
3881 if (!ch || ch->magic != DGAP_CHANNEL_MAGIC)
3884 memset(&tmp, 0, sizeof(tmp));
3886 DGAP_LOCK(ch->ch_lock, lock_flags);
3887 tmp = readw(&(ch->ch_bs->edelay));
3888 DGAP_UNLOCK(ch->ch_lock, lock_flags);
3890 if (copy_to_user(retinfo, &tmp, sizeof(*retinfo)))
3898 * dgap_tty_digisetedelay()
3900 * Ioctl to set the EDELAY setting
3903 static int dgap_tty_digisetedelay(struct tty_struct *tty, int __user *new_info)
3906 struct channel_t *ch;
3912 DPR_IOCTL(("DIGI_SETA start\n"));
3914 if (!tty || tty->magic != TTY_MAGIC)
3917 un = tty->driver_data;
3918 if (!un || un->magic != DGAP_UNIT_MAGIC)
3922 if (!ch || ch->magic != DGAP_CHANNEL_MAGIC)
3926 if (!bd || bd->magic != DGAP_BOARD_MAGIC)
3929 if (copy_from_user(&new_digi, new_info, sizeof(int))) {
3930 DPR_IOCTL(("DIGI_SETEDELAY failed copy_from_user\n"));
3934 DGAP_LOCK(bd->bd_lock, lock_flags);
3935 DGAP_LOCK(ch->ch_lock, lock_flags2);
3937 writew((u16) new_digi, &(ch->ch_bs->edelay));
3941 DGAP_UNLOCK(ch->ch_lock, lock_flags2);
3942 DGAP_UNLOCK(bd->bd_lock, lock_flags);
3944 DPR_IOCTL(("DIGI_SETA finish\n"));
3951 * dgap_tty_digigetcustombaud()
3953 * Ioctl to get the current custom baud rate setting.
3955 static int dgap_tty_digigetcustombaud(struct tty_struct *tty, int __user *retinfo)
3957 struct channel_t *ch;
3965 if (!tty || tty->magic != TTY_MAGIC)
3968 un = tty->driver_data;
3969 if (!un || un->magic != DGAP_UNIT_MAGIC)
3973 if (!ch || ch->magic != DGAP_CHANNEL_MAGIC)
3976 memset(&tmp, 0, sizeof(tmp));
3978 DGAP_LOCK(ch->ch_lock, lock_flags);
3979 tmp = dgap_get_custom_baud(ch);
3980 DGAP_UNLOCK(ch->ch_lock, lock_flags);
3982 DPR_IOCTL(("DIGI_GETCUSTOMBAUD. Returning %d\n", tmp));
3984 if (copy_to_user(retinfo, &tmp, sizeof(*retinfo)))
3992 * dgap_tty_digisetcustombaud()
3994 * Ioctl to set the custom baud rate setting
3996 static int dgap_tty_digisetcustombaud(struct tty_struct *tty, int __user *new_info)
3999 struct channel_t *ch;
4005 DPR_IOCTL(("DIGI_SETCUSTOMBAUD start\n"));
4007 if (!tty || tty->magic != TTY_MAGIC)
4010 un = tty->driver_data;
4011 if (!un || un->magic != DGAP_UNIT_MAGIC)
4015 if (!ch || ch->magic != DGAP_CHANNEL_MAGIC)
4019 if (!bd || bd->magic != DGAP_BOARD_MAGIC)
4023 if (copy_from_user(&new_rate, new_info, sizeof(unsigned int))) {
4024 DPR_IOCTL(("DIGI_SETCUSTOMBAUD failed copy_from_user\n"));
4028 if (bd->bd_flags & BD_FEP5PLUS) {
4030 DPR_IOCTL(("DIGI_SETCUSTOMBAUD. Setting %d\n", new_rate));
4032 DGAP_LOCK(bd->bd_lock, lock_flags);
4033 DGAP_LOCK(ch->ch_lock, lock_flags2);
4035 ch->ch_custom_speed = new_rate;
4039 DGAP_UNLOCK(ch->ch_lock, lock_flags2);
4040 DGAP_UNLOCK(bd->bd_lock, lock_flags);
4043 DPR_IOCTL(("DIGI_SETCUSTOMBAUD finish\n"));
4050 * dgap_set_termios()
4052 static void dgap_tty_set_termios(struct tty_struct *tty, struct ktermios *old_termios)
4055 struct channel_t *ch;
4057 unsigned long lock_flags;
4058 unsigned long lock_flags2;
4060 if (!tty || tty->magic != TTY_MAGIC)
4063 un = tty->driver_data;
4064 if (!un || un->magic != DGAP_UNIT_MAGIC)
4068 if (!ch || ch->magic != DGAP_CHANNEL_MAGIC)
4072 if (!bd || bd->magic != DGAP_BOARD_MAGIC)
4075 DGAP_LOCK(bd->bd_lock, lock_flags);
4076 DGAP_LOCK(ch->ch_lock, lock_flags2);
4078 ch->ch_c_cflag = tty->termios.c_cflag;
4079 ch->ch_c_iflag = tty->termios.c_iflag;
4080 ch->ch_c_oflag = tty->termios.c_oflag;
4081 ch->ch_c_lflag = tty->termios.c_lflag;
4082 ch->ch_startc = tty->termios.c_cc[VSTART];
4083 ch->ch_stopc = tty->termios.c_cc[VSTOP];
4088 DGAP_UNLOCK(ch->ch_lock, lock_flags2);
4089 DGAP_UNLOCK(bd->bd_lock, lock_flags);
4093 static void dgap_tty_throttle(struct tty_struct *tty)
4096 struct channel_t *ch;
4101 if (!tty || tty->magic != TTY_MAGIC)
4104 un = tty->driver_data;
4105 if (!un || un->magic != DGAP_UNIT_MAGIC)
4109 if (!ch || ch->magic != DGAP_CHANNEL_MAGIC)
4113 if (!bd || bd->magic != DGAP_BOARD_MAGIC)
4116 DPR_IOCTL(("dgap_tty_throttle start\n"));
4118 DGAP_LOCK(bd->bd_lock, lock_flags);
4119 DGAP_LOCK(ch->ch_lock, lock_flags2);
4121 ch->ch_flags |= (CH_RXBLOCK);
4123 dgap_cmdw(ch, RPAUSE, 0, 0);
4126 DGAP_UNLOCK(ch->ch_lock, lock_flags2);
4127 DGAP_UNLOCK(bd->bd_lock, lock_flags);
4129 DPR_IOCTL(("dgap_tty_throttle finish\n"));
4133 static void dgap_tty_unthrottle(struct tty_struct *tty)
4136 struct channel_t *ch;
4141 if (!tty || tty->magic != TTY_MAGIC)
4144 un = tty->driver_data;
4145 if (!un || un->magic != DGAP_UNIT_MAGIC)
4149 if (!ch || ch->magic != DGAP_CHANNEL_MAGIC)
4153 if (!bd || bd->magic != DGAP_BOARD_MAGIC)
4156 DPR_IOCTL(("dgap_tty_unthrottle start\n"));
4158 DGAP_LOCK(bd->bd_lock, lock_flags);
4159 DGAP_LOCK(ch->ch_lock, lock_flags2);
4161 ch->ch_flags &= ~(CH_RXBLOCK);
4164 dgap_cmdw(ch, RRESUME, 0, 0);
4167 DGAP_UNLOCK(ch->ch_lock, lock_flags2);
4168 DGAP_UNLOCK(bd->bd_lock, lock_flags);
4170 DPR_IOCTL(("dgap_tty_unthrottle finish\n"));
4174 static void dgap_tty_start(struct tty_struct *tty)
4177 struct channel_t *ch;
4182 if (!tty || tty->magic != TTY_MAGIC)
4185 un = tty->driver_data;
4186 if (!un || un->magic != DGAP_UNIT_MAGIC)
4190 if (!ch || ch->magic != DGAP_CHANNEL_MAGIC)
4194 if (!bd || bd->magic != DGAP_BOARD_MAGIC)
4197 DPR_IOCTL(("dgap_tty_start start\n"));
4199 DGAP_LOCK(bd->bd_lock, lock_flags);
4200 DGAP_LOCK(ch->ch_lock, lock_flags2);
4202 dgap_cmdw(ch, RESUMETX, 0, 0);
4204 DGAP_UNLOCK(ch->ch_lock, lock_flags2);
4205 DGAP_UNLOCK(bd->bd_lock, lock_flags);
4207 DPR_IOCTL(("dgap_tty_start finish\n"));
4211 static void dgap_tty_stop(struct tty_struct *tty)
4214 struct channel_t *ch;
4219 if (!tty || tty->magic != TTY_MAGIC)
4222 un = tty->driver_data;
4223 if (!un || un->magic != DGAP_UNIT_MAGIC)
4227 if (!ch || ch->magic != DGAP_CHANNEL_MAGIC)
4231 if (!bd || bd->magic != DGAP_BOARD_MAGIC)
4234 DPR_IOCTL(("dgap_tty_stop start\n"));
4236 DGAP_LOCK(bd->bd_lock, lock_flags);
4237 DGAP_LOCK(ch->ch_lock, lock_flags2);
4239 dgap_cmdw(ch, PAUSETX, 0, 0);
4241 DGAP_UNLOCK(ch->ch_lock, lock_flags2);
4242 DGAP_UNLOCK(bd->bd_lock, lock_flags);
4244 DPR_IOCTL(("dgap_tty_stop finish\n"));
4249 * dgap_tty_flush_chars()
4251 * Flush the cook buffer
4253 * Note to self, and any other poor souls who venture here:
4255 * flush in this case DOES NOT mean dispose of the data.
4256 * instead, it means "stop buffering and send it if you
4257 * haven't already." Just guess how I figured that out... SRW 2-Jun-98
4259 * It is also always called in interrupt context - JAR 8-Sept-99
4261 static void dgap_tty_flush_chars(struct tty_struct *tty)
4264 struct channel_t *ch;
4269 if (!tty || tty->magic != TTY_MAGIC)
4272 un = tty->driver_data;
4273 if (!un || un->magic != DGAP_UNIT_MAGIC)
4277 if (!ch || ch->magic != DGAP_CHANNEL_MAGIC)
4281 if (!bd || bd->magic != DGAP_BOARD_MAGIC)
4284 DPR_IOCTL(("dgap_tty_flush_chars start\n"));
4286 DGAP_LOCK(bd->bd_lock, lock_flags);
4287 DGAP_LOCK(ch->ch_lock, lock_flags2);
4289 /* TODO: Do something here */
4291 DGAP_UNLOCK(ch->ch_lock, lock_flags2);
4292 DGAP_UNLOCK(bd->bd_lock, lock_flags);
4294 DPR_IOCTL(("dgap_tty_flush_chars finish\n"));
4300 * dgap_tty_flush_buffer()
4302 * Flush Tx buffer (make in == out)
4304 static void dgap_tty_flush_buffer(struct tty_struct *tty)
4307 struct channel_t *ch;
4313 if (!tty || tty->magic != TTY_MAGIC)
4316 un = tty->driver_data;
4317 if (!un || un->magic != DGAP_UNIT_MAGIC)
4321 if (!ch || ch->magic != DGAP_CHANNEL_MAGIC)
4325 if (!bd || bd->magic != DGAP_BOARD_MAGIC)
4328 DPR_IOCTL(("dgap_tty_flush_buffer on port: %d start\n", ch->ch_portnum));
4330 DGAP_LOCK(bd->bd_lock, lock_flags);
4331 DGAP_LOCK(ch->ch_lock, lock_flags2);
4333 ch->ch_flags &= ~CH_STOP;
4334 head = readw(&(ch->ch_bs->tx_head));
4335 dgap_cmdw(ch, FLUSHTX, (u16) head, 0);
4336 dgap_cmdw(ch, RESUMETX, 0, 0);
4337 if (ch->ch_tun.un_flags & (UN_LOW|UN_EMPTY)) {
4338 ch->ch_tun.un_flags &= ~(UN_LOW|UN_EMPTY);
4339 wake_up_interruptible(&ch->ch_tun.un_flags_wait);
4341 if (ch->ch_pun.un_flags & (UN_LOW|UN_EMPTY)) {
4342 ch->ch_pun.un_flags &= ~(UN_LOW|UN_EMPTY);
4343 wake_up_interruptible(&ch->ch_pun.un_flags_wait);
4346 DGAP_UNLOCK(ch->ch_lock, lock_flags2);
4347 DGAP_UNLOCK(bd->bd_lock, lock_flags);
4348 if (waitqueue_active(&tty->write_wait))
4349 wake_up_interruptible(&tty->write_wait);
4352 DPR_IOCTL(("dgap_tty_flush_buffer finish\n"));
4357 /*****************************************************************************
4359 * The IOCTL function and all of its helpers
4361 *****************************************************************************/
4366 * The usual assortment of ioctl's
4368 static int dgap_tty_ioctl(struct tty_struct *tty, unsigned int cmd,
4372 struct channel_t *ch;
4376 ulong lock_flags = 0;
4377 ulong lock_flags2 = 0;
4378 void __user *uarg = (void __user *) arg;
4380 if (!tty || tty->magic != TTY_MAGIC)
4383 un = tty->driver_data;
4384 if (!un || un->magic != DGAP_UNIT_MAGIC)
4388 if (!ch || ch->magic != DGAP_CHANNEL_MAGIC)
4392 if (!bd || bd->magic != DGAP_BOARD_MAGIC)
4395 DPR_IOCTL(("dgap_tty_ioctl start on port %d - cmd %s (%x), arg %lx\n",
4396 ch->ch_portnum, dgap_ioctl_name(cmd), cmd, arg));
4398 DGAP_LOCK(bd->bd_lock, lock_flags);
4399 DGAP_LOCK(ch->ch_lock, lock_flags2);
4401 if (un->un_open_count <= 0) {
4402 DPR_BASIC(("dgap_tty_ioctl - unit not open.\n"));
4403 DGAP_UNLOCK(ch->ch_lock, lock_flags2);
4404 DGAP_UNLOCK(bd->bd_lock, lock_flags);
4410 /* Here are all the standard ioctl's that we MUST implement */
4414 * TCSBRK is SVID version: non-zero arg --> no break
4415 * this behaviour is exploited by tcdrain().
4417 * According to POSIX.1 spec (7.2.2.1.2) breaks should be
4418 * between 0.25 and 0.5 seconds so we'll ask for something
4419 * in the middle: 0.375 seconds.
4421 rc = tty_check_change(tty);
4422 DGAP_UNLOCK(ch->ch_lock, lock_flags2);
4423 DGAP_UNLOCK(bd->bd_lock, lock_flags);
4428 rc = dgap_wait_for_drain(tty);
4431 DPR_IOCTL(("dgap_tty_ioctl - bad return: %d ", rc));
4435 DGAP_LOCK(bd->bd_lock, lock_flags);
4436 DGAP_LOCK(ch->ch_lock, lock_flags2);
4438 if(((cmd == TCSBRK) && (!arg)) || (cmd == TCSBRKP)) {
4439 dgap_cmdw(ch, SBREAK, (u16) SBREAK_TIME, 0);
4442 DGAP_UNLOCK(ch->ch_lock, lock_flags2);
4443 DGAP_UNLOCK(bd->bd_lock, lock_flags);
4445 DPR_IOCTL(("dgap_tty_ioctl finish on port %d - cmd %s (%x), arg %lx\n",
4446 ch->ch_portnum, dgap_ioctl_name(cmd), cmd, arg));
4452 /* support for POSIX tcsendbreak()
4454 * According to POSIX.1 spec (7.2.2.1.2) breaks should be
4455 * between 0.25 and 0.5 seconds so we'll ask for something
4456 * in the middle: 0.375 seconds.
4458 rc = tty_check_change(tty);
4459 DGAP_UNLOCK(ch->ch_lock, lock_flags2);
4460 DGAP_UNLOCK(bd->bd_lock, lock_flags);
4465 rc = dgap_wait_for_drain(tty);
4467 DPR_IOCTL(("dgap_tty_ioctl - bad return: %d ", rc));
4471 DGAP_LOCK(bd->bd_lock, lock_flags);
4472 DGAP_LOCK(ch->ch_lock, lock_flags2);
4474 dgap_cmdw(ch, SBREAK, (u16) SBREAK_TIME, 0);
4476 DGAP_UNLOCK(ch->ch_lock, lock_flags2);
4477 DGAP_UNLOCK(bd->bd_lock, lock_flags);
4479 DPR_IOCTL(("dgap_tty_ioctl finish on port %d - cmd %s (%x), arg %lx\n",
4480 ch->ch_portnum, dgap_ioctl_name(cmd), cmd, arg));
4486 * FEP5 doesn't support turning on a break unconditionally.
4487 * The FEP5 device will stop sending a break automatically
4488 * after the specified time value that was sent when turning on
4491 rc = tty_check_change(tty);
4492 DGAP_UNLOCK(ch->ch_lock, lock_flags2);
4493 DGAP_UNLOCK(bd->bd_lock, lock_flags);
4498 rc = dgap_wait_for_drain(tty);
4500 DPR_IOCTL(("dgap_tty_ioctl - bad return: %d ", rc));
4504 DGAP_LOCK(bd->bd_lock, lock_flags);
4505 DGAP_LOCK(ch->ch_lock, lock_flags2);
4507 dgap_cmdw(ch, SBREAK, (u16) SBREAK_TIME, 0);
4509 DGAP_UNLOCK(ch->ch_lock, lock_flags2);
4510 DGAP_UNLOCK(bd->bd_lock, lock_flags);
4512 DPR_IOCTL(("dgap_tty_ioctl finish on port %d - cmd %s (%x), arg %lx\n",
4513 ch->ch_portnum, dgap_ioctl_name(cmd), cmd, arg));
4519 * FEP5 doesn't support turning off a break unconditionally.
4520 * The FEP5 device will stop sending a break automatically
4521 * after the specified time value that was sent when turning on
4524 DGAP_UNLOCK(ch->ch_lock, lock_flags2);
4525 DGAP_UNLOCK(bd->bd_lock, lock_flags);
4530 DGAP_UNLOCK(ch->ch_lock, lock_flags2);
4531 DGAP_UNLOCK(bd->bd_lock, lock_flags);
4533 rc = put_user(C_CLOCAL(tty) ? 1 : 0, (unsigned long __user *) arg);
4537 DGAP_UNLOCK(ch->ch_lock, lock_flags2);
4538 DGAP_UNLOCK(bd->bd_lock, lock_flags);
4540 rc = get_user(arg, (unsigned long __user *) arg);
4544 DGAP_LOCK(bd->bd_lock, lock_flags);
4545 DGAP_LOCK(ch->ch_lock, lock_flags2);
4546 tty->termios.c_cflag = ((tty->termios.c_cflag & ~CLOCAL) | (arg ? CLOCAL : 0));
4548 DGAP_UNLOCK(ch->ch_lock, lock_flags2);
4549 DGAP_UNLOCK(bd->bd_lock, lock_flags);
4554 DGAP_UNLOCK(ch->ch_lock, lock_flags2);
4555 DGAP_UNLOCK(bd->bd_lock, lock_flags);
4556 return(dgap_get_modem_info(ch, uarg));
4561 DGAP_UNLOCK(ch->ch_lock, lock_flags2);
4562 DGAP_UNLOCK(bd->bd_lock, lock_flags);
4563 return(dgap_set_modem_info(tty, cmd, uarg));
4566 * Here are any additional ioctl's that we want to implement
4571 * The linux tty driver doesn't have a flush
4572 * input routine for the driver, assuming all backed
4573 * up data is in the line disc. buffers. However,
4574 * we all know that's not the case. Here, we
4575 * act on the ioctl, but then lie and say we didn't
4576 * so the line discipline will process the flush
4579 rc = tty_check_change(tty);
4581 DGAP_UNLOCK(ch->ch_lock, lock_flags2);
4582 DGAP_UNLOCK(bd->bd_lock, lock_flags);
4586 if ((arg == TCIFLUSH) || (arg == TCIOFLUSH)) {
4587 if (!(un->un_type == DGAP_PRINT)) {
4588 head = readw(&(ch->ch_bs->rx_head));
4589 writew(head, &(ch->ch_bs->rx_tail));
4590 writeb(0, &(ch->ch_bs->orun));
4594 if ((arg == TCOFLUSH) || (arg == TCIOFLUSH)) {
4595 ch->ch_flags &= ~CH_STOP;
4596 head = readw(&(ch->ch_bs->tx_head));
4597 dgap_cmdw(ch, FLUSHTX, (u16) head, 0 );
4598 dgap_cmdw(ch, RESUMETX, 0, 0);
4599 if (ch->ch_tun.un_flags & (UN_LOW|UN_EMPTY)) {
4600 ch->ch_tun.un_flags &= ~(UN_LOW|UN_EMPTY);
4601 wake_up_interruptible(&ch->ch_tun.un_flags_wait);
4603 if (ch->ch_pun.un_flags & (UN_LOW|UN_EMPTY)) {
4604 ch->ch_pun.un_flags &= ~(UN_LOW|UN_EMPTY);
4605 wake_up_interruptible(&ch->ch_pun.un_flags_wait);
4607 if (waitqueue_active(&tty->write_wait))
4608 wake_up_interruptible(&tty->write_wait);
4610 /* Can't hold any locks when calling tty_wakeup! */
4611 DGAP_UNLOCK(ch->ch_lock, lock_flags2);
4612 DGAP_UNLOCK(bd->bd_lock, lock_flags);
4614 DGAP_LOCK(bd->bd_lock, lock_flags);
4615 DGAP_LOCK(ch->ch_lock, lock_flags2);
4618 /* pretend we didn't recognize this IOCTL */
4619 DGAP_UNLOCK(ch->ch_lock, lock_flags2);
4620 DGAP_UNLOCK(bd->bd_lock, lock_flags);
4622 DPR_IOCTL(("dgap_tty_ioctl (LINE:%d) finish on port %d - cmd %s (%x), arg %lx\n",
4623 __LINE__, ch->ch_portnum, dgap_ioctl_name(cmd), cmd, arg));
4625 return(-ENOIOCTLCMD);
4630 * The linux tty driver doesn't have a flush
4631 * input routine for the driver, assuming all backed
4632 * up data is in the line disc. buffers. However,
4633 * we all know that's not the case. Here, we
4634 * act on the ioctl, but then lie and say we didn't
4635 * so the line discipline will process the flush
4638 if (cmd == TCSETSF) {
4640 ch->ch_flags &= ~CH_STOP;
4641 head = readw(&(ch->ch_bs->rx_head));
4642 writew(head, &(ch->ch_bs->rx_tail));
4645 /* now wait for all the output to drain */
4646 DGAP_UNLOCK(ch->ch_lock, lock_flags2);
4647 DGAP_UNLOCK(bd->bd_lock, lock_flags);
4648 rc = dgap_wait_for_drain(tty);
4650 DPR_IOCTL(("dgap_tty_ioctl - bad return: %d ", rc));
4654 DPR_IOCTL(("dgap_tty_ioctl finish on port %d - cmd %s (%x), arg %lx\n",
4655 ch->ch_portnum, dgap_ioctl_name(cmd), cmd, arg));
4657 /* pretend we didn't recognize this */
4658 return(-ENOIOCTLCMD);
4662 DGAP_UNLOCK(ch->ch_lock, lock_flags2);
4663 DGAP_UNLOCK(bd->bd_lock, lock_flags);
4664 rc = dgap_wait_for_drain(tty);
4666 DPR_IOCTL(("dgap_tty_ioctl - bad return: %d ", rc));
4670 /* pretend we didn't recognize this */
4671 return(-ENOIOCTLCMD);
4675 * The Linux Line Discipline (LD) would do this for us if we
4676 * let it, but we have the special firmware options to do this
4677 * the "right way" regardless of hardware or software flow
4678 * control so we'll do it outselves instead of letting the LD
4681 rc = tty_check_change(tty);
4683 DGAP_UNLOCK(ch->ch_lock, lock_flags2);
4684 DGAP_UNLOCK(bd->bd_lock, lock_flags);
4688 DPR_IOCTL(("dgap_ioctl - in TCXONC - %d\n", cmd));
4692 DGAP_UNLOCK(ch->ch_lock, lock_flags2);
4693 DGAP_UNLOCK(bd->bd_lock, lock_flags);
4694 dgap_tty_start(tty);
4697 DGAP_UNLOCK(ch->ch_lock, lock_flags2);
4698 DGAP_UNLOCK(bd->bd_lock, lock_flags);
4702 DGAP_UNLOCK(ch->ch_lock, lock_flags2);
4703 DGAP_UNLOCK(bd->bd_lock, lock_flags);
4704 /* Make the ld do it */
4705 return(-ENOIOCTLCMD);
4707 DGAP_UNLOCK(ch->ch_lock, lock_flags2);
4708 DGAP_UNLOCK(bd->bd_lock, lock_flags);
4709 /* Make the ld do it */
4710 return(-ENOIOCTLCMD);
4712 DGAP_UNLOCK(ch->ch_lock, lock_flags2);
4713 DGAP_UNLOCK(bd->bd_lock, lock_flags);
4718 /* get information for ditty */
4719 DGAP_UNLOCK(ch->ch_lock, lock_flags2);
4720 DGAP_UNLOCK(bd->bd_lock, lock_flags);
4721 return(dgap_tty_digigeta(tty, uarg));
4726 /* set information for ditty */
4727 if (cmd == (DIGI_SETAW)) {
4729 DGAP_UNLOCK(ch->ch_lock, lock_flags2);
4730 DGAP_UNLOCK(bd->bd_lock, lock_flags);
4731 rc = dgap_wait_for_drain(tty);
4733 DPR_IOCTL(("dgap_tty_ioctl - bad return: %d ", rc));
4736 DGAP_LOCK(bd->bd_lock, lock_flags);
4737 DGAP_LOCK(ch->ch_lock, lock_flags2);
4740 tty_ldisc_flush(tty);
4745 DGAP_UNLOCK(ch->ch_lock, lock_flags2);
4746 DGAP_UNLOCK(bd->bd_lock, lock_flags);
4747 return(dgap_tty_digiseta(tty, uarg));
4750 DGAP_UNLOCK(ch->ch_lock, lock_flags2);
4751 DGAP_UNLOCK(bd->bd_lock, lock_flags);
4752 return(dgap_tty_digigetedelay(tty, uarg));
4755 DGAP_UNLOCK(ch->ch_lock, lock_flags2);
4756 DGAP_UNLOCK(bd->bd_lock, lock_flags);
4757 return(dgap_tty_digisetedelay(tty, uarg));
4759 case DIGI_GETCUSTOMBAUD:
4760 DGAP_UNLOCK(ch->ch_lock, lock_flags2);
4761 DGAP_UNLOCK(bd->bd_lock, lock_flags);
4762 return(dgap_tty_digigetcustombaud(tty, uarg));
4764 case DIGI_SETCUSTOMBAUD:
4765 DGAP_UNLOCK(ch->ch_lock, lock_flags2);
4766 DGAP_UNLOCK(bd->bd_lock, lock_flags);
4767 return(dgap_tty_digisetcustombaud(tty, uarg));
4769 case DIGI_RESET_PORT:
4770 dgap_firmware_reset_port(ch);
4772 DGAP_UNLOCK(ch->ch_lock, lock_flags2);
4773 DGAP_UNLOCK(bd->bd_lock, lock_flags);
4777 DGAP_UNLOCK(ch->ch_lock, lock_flags2);
4778 DGAP_UNLOCK(bd->bd_lock, lock_flags);
4780 DPR_IOCTL(("dgap_tty_ioctl - in default\n"));
4781 DPR_IOCTL(("dgap_tty_ioctl end - cmd %s (%x), arg %lx\n",
4782 dgap_ioctl_name(cmd), cmd, arg));
4784 return(-ENOIOCTLCMD);
4788 static int dgap_after_config_loaded(int board)
4791 * Initialize KME waitqueues...
4793 init_waitqueue_head(&(dgap_Board[board]->kme_wait));
4796 * allocate flip buffer for board.
4798 dgap_Board[board]->flipbuf = kmalloc(MYFLIPLEN, GFP_ATOMIC);
4799 if (!dgap_Board[board]->flipbuf)
4802 dgap_Board[board]->flipflagbuf = kmalloc(MYFLIPLEN, GFP_ATOMIC);
4803 if (!dgap_Board[board]->flipflagbuf) {
4804 kfree(dgap_Board[board]->flipbuf);
4814 * Create pr and tty device entries
4816 static void dgap_sysfs_create(struct board_t *brd)
4818 struct channel_t *ch;
4821 ch = brd->channels[0];
4822 for (j = 0; j < brd->nasync; j++, ch = brd->channels[j]) {
4823 struct device *classp;
4824 classp = tty_register_device(brd->SerialDriver, j,
4825 &(ch->ch_bd->pdev->dev));
4826 ch->ch_tun.un_sysfs = classp;
4827 dgap_create_tty_sysfs(&ch->ch_tun, classp);
4829 classp = tty_register_device(brd->PrintDriver, j,
4830 &(ch->ch_bd->pdev->dev));
4831 ch->ch_pun.un_sysfs = classp;
4832 dgap_create_tty_sysfs(&ch->ch_pun, classp);
4834 dgap_create_ports_sysfiles(brd);
4839 * Copies the BIOS code from the user to the board,
4840 * and starts the BIOS running.
4842 static void dgap_do_bios_load(struct board_t *brd, uchar __user *ubios, int len)
4848 if (!brd || (brd->magic != DGAP_BOARD_MAGIC) || !brd->re_map_membase)
4851 DPR_INIT(("dgap_do_bios_load() start\n"));
4853 addr = brd->re_map_membase;
4858 for (i = 0; i < 16; i++)
4859 writeb(0, addr + POSTAREA + i);
4865 memcpy_toio(addr + offset, ubios, len);
4867 writel(0x0bf00401, addr);
4868 writel(0, (addr + 4));
4870 /* Clear the reset, and change states. */
4871 writeb(FEPCLR, brd->re_map_port);
4876 * Checks to see if the BIOS completed running on the card.
4878 static void dgap_do_wait_for_bios(struct board_t *brd)
4885 if (!brd || (brd->magic != DGAP_BOARD_MAGIC) || !brd->re_map_membase)
4888 addr = brd->re_map_membase;
4889 word = readw(addr + POSTAREA);
4892 * It can take 5-6 seconds for a board to
4893 * pass the bios self test and post results.
4894 * Give it 10 seconds.
4896 brd->wait_for_bios = 0;
4897 while (brd->wait_for_bios < 1000) {
4898 /* Check to see if BIOS thinks board is good. (GD). */
4899 if (word == *(u16 *) "GD") {
4900 DPR_INIT(("GOT GD in memory, moving states.\n"));
4901 brd->state = FINISHED_BIOS_LOAD;
4904 msleep_interruptible(10);
4905 brd->wait_for_bios++;
4906 word = readw(addr + POSTAREA);
4909 /* Gave up on board after too long of time taken */
4910 err1 = readw(addr + SEQUENCE);
4911 err2 = readw(addr + ERROR);
4912 APR(("***WARNING*** %s failed diagnostics. Error #(%x,%x).\n",
4913 brd->name, err1, err2));
4914 brd->state = BOARD_FAILED;
4915 brd->dpastatus = BD_NOBIOS;
4920 * Copies the FEP code from the user to the board,
4921 * and starts the FEP running.
4923 static void dgap_do_fep_load(struct board_t *brd, uchar *ufep, int len)
4928 if (!brd || (brd->magic != DGAP_BOARD_MAGIC) || !brd->re_map_membase)
4931 addr = brd->re_map_membase;
4933 DPR_INIT(("dgap_do_fep_load() for board %s : start\n", brd->name));
4939 memcpy_toio(addr + offset, ufep, len);
4942 * If board is a concentrator product, we need to give
4943 * it its config string describing how the concentrators look.
4945 if ((brd->type == PCX) || (brd->type == PEPC)) {
4947 uchar *config, *xconfig;
4950 xconfig = dgap_create_config_string(brd, string);
4952 /* Write string to board memory */
4953 config = addr + CONFIG;
4954 for (; i < CONFIGSIZE; i++, config++, xconfig++) {
4955 writeb(*xconfig, config);
4956 if ((*xconfig & 0xff) == 0xff)
4961 writel(0xbfc01004, (addr + 0xc34));
4962 writel(0x3, (addr + 0xc30));
4964 DPR_INIT(("dgap_do_fep_load() for board %s : finish\n", brd->name));
4970 * Waits for the FEP to report thats its ready for us to use.
4972 static void dgap_do_wait_for_fep(struct board_t *brd)
4979 if (!brd || (brd->magic != DGAP_BOARD_MAGIC) || !brd->re_map_membase)
4982 addr = brd->re_map_membase;
4983 word = readw(addr + FEPSTAT);
4986 * It can take 2-3 seconds for the FEP to
4987 * be up and running. Give it 5 secs.
4989 brd->wait_for_fep = 0;
4990 while (brd->wait_for_fep < 500) {
4991 /* Check to see if FEP is up and running now. */
4992 if (word == *(u16 *) "OS") {
4993 brd->state = FINISHED_FEP_LOAD;
4995 * Check to see if the board can support FEP5+ commands.
4997 word = readw(addr + FEP5_PLUS);
4998 if (word == *(u16 *) "5A")
4999 brd->bd_flags |= BD_FEP5PLUS;
5003 msleep_interruptible(10);
5004 brd->wait_for_fep++;
5005 word = readw(addr + FEPSTAT);
5008 /* Gave up on board after too long of time taken */
5009 err1 = readw(addr + SEQUENCE);
5010 err2 = readw(addr + ERROR);
5011 APR(("***WARNING*** FEPOS for %s not functioning. Error #(%x,%x).\n",
5012 brd->name, err1, err2));
5013 brd->state = BOARD_FAILED;
5014 brd->dpastatus = BD_NOFEP;
5016 DPR_INIT(("dgap_do_wait_for_fep() for board %s : finish\n", brd->name));
5021 * Physically forces the FEP5 card to reset itself.
5023 static void dgap_do_reset_board(struct board_t *brd)
5030 if (!brd || (brd->magic != DGAP_BOARD_MAGIC) || !brd->re_map_membase || !brd->re_map_port) {
5031 DPR_INIT(("dgap_do_reset_board() start. bad values. brd: %p mem: %p io: %p\n",
5032 brd, brd ? brd->re_map_membase : 0, brd ? brd->re_map_port : 0));
5036 DPR_INIT(("dgap_do_reset_board() start. io: %p\n", brd->re_map_port));
5038 /* FEPRST does not vary among supported boards */
5039 writeb(FEPRST, brd->re_map_port);
5041 for (i = 0; i <= 1000; i++) {
5042 check = readb(brd->re_map_port) & 0xe;
5043 if (check == FEPRST)
5049 APR(("*** WARNING *** Board not resetting... Failing board.\n"));
5050 brd->state = BOARD_FAILED;
5051 brd->dpastatus = BD_NOFEP;
5056 * Make sure there really is memory out there.
5058 writel(0xa55a3cc3, (brd->re_map_membase + LOWMEM));
5059 writel(0x5aa5c33c, (brd->re_map_membase + HIGHMEM));
5060 check1 = readl(brd->re_map_membase + LOWMEM);
5061 check2 = readl(brd->re_map_membase + HIGHMEM);
5063 if ((check1 != 0xa55a3cc3) || (check2 != 0x5aa5c33c)) {
5064 APR(("*** Warning *** No memory at %p for board.\n", brd->re_map_membase));
5065 brd->state = BOARD_FAILED;
5066 brd->dpastatus = BD_NOFEP;
5070 if (brd->state != BOARD_FAILED)
5071 brd->state = FINISHED_RESET;
5074 DPR_INIT(("dgap_do_reset_board() finish\n"));
5078 #ifdef DIGI_CONCENTRATORS_SUPPORTED
5080 * Sends a concentrator image into the FEP5 board.
5082 static void dgap_do_conc_load(struct board_t *brd, uchar *uaddr, int len)
5086 struct downld_t *to_dp;
5088 if (!brd || (brd->magic != DGAP_BOARD_MAGIC) || !brd->re_map_membase)
5091 vaddr = brd->re_map_membase;
5093 offset = readw((u16 *) (vaddr + DOWNREQ));
5094 to_dp = (struct downld_t *) (vaddr + (int) offset);
5095 memcpy_toio(to_dp, uaddr, len);
5097 /* Tell card we have data for it */
5098 writew(0, vaddr + (DOWNREQ));
5100 brd->conc_dl_status = NO_PENDING_CONCENTRATOR_REQUESTS;
5104 #define EXPANSION_ROM_SIZE (64 * 1024)
5105 #define FEP5_ROM_MAGIC (0xFEFFFFFF)
5107 static void dgap_get_vpd(struct board_t *brd)
5119 * Poke the magic number at the PCI Rom Address location.
5120 * If VPD is supported, the value read from that address
5123 magic = FEP5_ROM_MAGIC;
5124 pci_write_config_dword(brd->pdev, PCI_ROM_ADDRESS, magic);
5125 pci_read_config_dword(brd->pdev, PCI_ROM_ADDRESS, &magic);
5127 /* VPD not supported, bail */
5132 * To get to the OTPROM memory, we have to send the boards base
5133 * address or'ed with 1 into the PCI Rom Address location.
5135 magic = brd->membase | 0x01;
5136 pci_write_config_dword(brd->pdev, PCI_ROM_ADDRESS, magic);
5137 pci_read_config_dword(brd->pdev, PCI_ROM_ADDRESS, &magic);
5139 byte1 = readb(brd->re_map_membase);
5140 byte2 = readb(brd->re_map_membase + 1);
5143 * If the board correctly swapped to the OTPROM memory,
5144 * the first 2 bytes (header) should be 0x55, 0xAA
5146 if (byte1 == 0x55 && byte2 == 0xAA) {
5151 * We have to run through all the OTPROM memory looking
5152 * for the VPD offset.
5154 while (base_offset <= EXPANSION_ROM_SIZE) {
5157 * Lots of magic numbers here.
5159 * The VPD offset is located inside the ROM Data Structure.
5160 * We also have to remember the length of each
5161 * ROM Data Structure, so we can "hop" to the next
5162 * entry if the VPD isn't in the current
5163 * ROM Data Structure.
5165 rom_offset = readw(brd->re_map_membase + base_offset + 0x18);
5166 image_length = readw(brd->re_map_membase + rom_offset + 0x10) * 512;
5167 vpd_offset = readw(brd->re_map_membase + rom_offset + 0x08);
5169 /* Found the VPD entry */
5173 /* We didn't find a VPD entry, go to next ROM entry. */
5174 base_offset += image_length;
5176 byte1 = readb(brd->re_map_membase + base_offset);
5177 byte2 = readb(brd->re_map_membase + base_offset + 1);
5180 * If the new ROM offset doesn't have 0x55, 0xAA
5181 * as its header, we have run out of ROM.
5183 if (byte1 != 0x55 || byte2 != 0xAA)
5188 * If we have a VPD offset, then mark the board
5189 * as having a valid VPD, and copy VPDSIZE (512) bytes of
5190 * that VPD to the buffer we have in our board structure.
5193 brd->bd_flags |= BD_HAS_VPD;
5194 for (i = 0; i < VPDSIZE; i++)
5195 brd->vpd[i] = readb(brd->re_map_membase + vpd_offset + i);
5200 * We MUST poke the magic number at the PCI Rom Address location again.
5201 * This makes the card report the regular board memory back to us,
5202 * rather than the OTPROM memory.
5204 magic = FEP5_ROM_MAGIC;
5205 pci_write_config_dword(brd->pdev, PCI_ROM_ADDRESS, magic);
5210 * Our board poller function.
5212 static void dgap_poll_tasklet(unsigned long data)
5214 struct board_t *bd = (struct board_t *) data;
5220 if (!bd || (bd->magic != DGAP_BOARD_MAGIC)) {
5221 APR(("dgap_poll_tasklet() - NULL or bad bd.\n"));
5225 if (bd->inhibit_poller)
5228 DGAP_LOCK(bd->bd_lock, lock_flags);
5230 vaddr = bd->re_map_membase;
5233 * If board is ready, parse deeper to see if there is anything to do.
5235 if (bd->state == BOARD_READY) {
5237 struct ev_t *eaddr = NULL;
5239 if (!bd->re_map_membase) {
5240 DGAP_UNLOCK(bd->bd_lock, lock_flags);
5243 if (!bd->re_map_port) {
5244 DGAP_UNLOCK(bd->bd_lock, lock_flags);
5252 eaddr = (struct ev_t *) (vaddr + EVBUF);
5254 /* Get our head and tail */
5255 head = readw(&(eaddr->ev_head));
5256 tail = readw(&(eaddr->ev_tail));
5259 * If there is an event pending. Go service it.
5262 DGAP_UNLOCK(bd->bd_lock, lock_flags);
5264 DGAP_LOCK(bd->bd_lock, lock_flags);
5269 * If board is doing interrupts, ACK the interrupt.
5271 if (bd && bd->intr_running) {
5272 readb(bd->re_map_port + 2);
5275 DGAP_UNLOCK(bd->bd_lock, lock_flags);
5279 /* Our state machine to get the board up and running */
5282 if (bd->state == NEED_RESET) {
5287 dgap_do_reset_board(bd);
5290 /* Move to next state */
5291 if (bd->state == FINISHED_RESET) {
5292 bd->state = NEED_CONFIG;
5295 if (bd->state == NEED_CONFIG) {
5297 * Match this board to a config the user created for us.
5299 bd->bd_config = dgap_find_config(bd->type, bd->pci_bus, bd->pci_slot);
5302 * Because the 4 port Xr products share the same PCI ID
5303 * as the 8 port Xr products, if we receive a NULL config
5304 * back, and this is a PAPORT8 board, retry with a
5305 * PAPORT4 attempt as well.
5307 if (bd->type == PAPORT8 && !bd->bd_config) {
5308 bd->bd_config = dgap_find_config(PAPORT4, bd->pci_bus, bd->pci_slot);
5312 * Register the ttys (if any) into the kernel.
5314 if (bd->bd_config) {
5315 bd->state = FINISHED_CONFIG;
5318 bd->state = CONFIG_NOT_FOUND;
5322 /* Move to next state */
5323 if (bd->state == FINISHED_CONFIG) {
5324 bd->state = NEED_DEVICE_CREATION;
5327 /* Move to next state */
5328 if (bd->state == NEED_DEVICE_CREATION) {
5330 * Signal downloader, its got some work to do.
5332 DGAP_LOCK(dgap_dl_lock, lock_flags2);
5333 if (dgap_dl_action != 1) {
5335 wake_up_interruptible(&dgap_dl_wait);
5337 DGAP_UNLOCK(dgap_dl_lock, lock_flags2);
5340 /* Move to next state */
5341 if (bd->state == FINISHED_DEVICE_CREATION) {
5342 bd->state = NEED_BIOS_LOAD;
5345 /* Move to next state */
5346 if (bd->state == NEED_BIOS_LOAD) {
5348 * Signal downloader, its got some work to do.
5350 DGAP_LOCK(dgap_dl_lock, lock_flags2);
5351 if (dgap_dl_action != 1) {
5353 wake_up_interruptible(&dgap_dl_wait);
5355 DGAP_UNLOCK(dgap_dl_lock, lock_flags2);
5358 /* Wait for BIOS to test board... */
5359 if (bd->state == WAIT_BIOS_LOAD) {
5360 dgap_do_wait_for_bios(bd);
5363 /* Move to next state */
5364 if (bd->state == FINISHED_BIOS_LOAD) {
5365 bd->state = NEED_FEP_LOAD;
5368 * Signal downloader, its got some work to do.
5370 DGAP_LOCK(dgap_dl_lock, lock_flags2);
5371 if (dgap_dl_action != 1) {
5373 wake_up_interruptible(&dgap_dl_wait);
5375 DGAP_UNLOCK(dgap_dl_lock, lock_flags2);
5378 /* Wait for FEP to load on board... */
5379 if (bd->state == WAIT_FEP_LOAD) {
5380 dgap_do_wait_for_fep(bd);
5384 /* Move to next state */
5385 if (bd->state == FINISHED_FEP_LOAD) {
5388 * Do tty device initialization.
5390 int rc = dgap_tty_init(bd);
5393 dgap_tty_uninit(bd);
5394 APR(("Can't init tty devices (%d)\n", rc));
5395 bd->state = BOARD_FAILED;
5396 bd->dpastatus = BD_NOFEP;
5399 bd->state = NEED_PROC_CREATION;
5402 * Signal downloader, its got some work to do.
5404 DGAP_LOCK(dgap_dl_lock, lock_flags2);
5405 if (dgap_dl_action != 1) {
5407 wake_up_interruptible(&dgap_dl_wait);
5409 DGAP_UNLOCK(dgap_dl_lock, lock_flags2);
5413 /* Move to next state */
5414 if (bd->state == FINISHED_PROC_CREATION) {
5416 bd->state = BOARD_READY;
5417 bd->dpastatus = BD_RUNNING;
5420 * If user requested the board to run in interrupt mode,
5421 * go and set it up on the board.
5423 if (bd->intr_used) {
5424 writew(1, (bd->re_map_membase + ENABLE_INTR));
5426 * Tell the board to poll the UARTS as fast as possible.
5428 writew(FEPPOLL_MIN, (bd->re_map_membase + FEPPOLL));
5429 bd->intr_running = 1;
5432 /* Wake up anyone waiting for board state to change to ready */
5433 wake_up_interruptible(&bd->state_wait);
5436 DGAP_UNLOCK(bd->bd_lock, lock_flags);
5440 /*=======================================================================
5442 * dgap_cmdb - Sends a 2 byte command to the FEP.
5444 * ch - Pointer to channel structure.
5445 * cmd - Command to be sent.
5446 * byte1 - Integer containing first byte to be sent.
5447 * byte2 - Integer containing second byte to be sent.
5448 * ncmds - Wait until ncmds or fewer cmds are left
5449 * in the cmd buffer before returning.
5451 *=======================================================================*/
5452 static void dgap_cmdb(struct channel_t *ch, uchar cmd, uchar byte1, uchar byte2, uint ncmds)
5455 struct cm_t *cm_addr = NULL;
5461 if (!ch || ch->magic != DGAP_CHANNEL_MAGIC)
5465 * Check if board is still alive.
5467 if (ch->ch_bd->state == BOARD_FAILED) {
5468 DPR_CORE(("%s:%d board is in failed state.\n", __FILE__, __LINE__));
5473 * Make sure the pointers are in range before
5474 * writing to the FEP memory.
5476 vaddr = ch->ch_bd->re_map_membase;
5481 cm_addr = (struct cm_t *) (vaddr + CMDBUF);
5482 head = readw(&(cm_addr->cm_head));
5485 * Forget it if pointers out of range.
5487 if (head >= (CMDMAX - CMDSTART) || (head & 03)) {
5488 DPR_CORE(("%s:%d pointers out of range, failing board!\n", __FILE__, __LINE__));
5489 ch->ch_bd->state = BOARD_FAILED;
5494 * Put the data in the circular command buffer.
5496 writeb(cmd, (char *) (vaddr + head + CMDSTART + 0));
5497 writeb((uchar) ch->ch_portnum, (char *) (vaddr + head + CMDSTART + 1));
5498 writeb(byte1, (char *) (vaddr + head + CMDSTART + 2));
5499 writeb(byte2, (char *) (vaddr + head + CMDSTART + 3));
5501 head = (head + 4) & (CMDMAX - CMDSTART - 4);
5503 writew(head, &(cm_addr->cm_head));
5506 * Wait if necessary before updating the head
5507 * pointer to limit the number of outstanding
5508 * commands to the FEP. If the time spent waiting
5509 * is outlandish, declare the FEP dead.
5511 for (count = dgap_count ;;) {
5513 head = readw(&(cm_addr->cm_head));
5514 tail = readw(&(cm_addr->cm_tail));
5516 n = (head - tail) & (CMDMAX - CMDSTART - 4);
5518 if (n <= ncmds * sizeof(struct cm_t))
5522 DPR_CORE(("%s:%d failing board.\n",__FILE__, __LINE__));
5523 ch->ch_bd->state = BOARD_FAILED;
5531 /*=======================================================================
5533 * dgap_cmdw - Sends a 1 word command to the FEP.
5535 * ch - Pointer to channel structure.
5536 * cmd - Command to be sent.
5537 * word - Integer containing word to be sent.
5538 * ncmds - Wait until ncmds or fewer cmds are left
5539 * in the cmd buffer before returning.
5541 *=======================================================================*/
5542 static void dgap_cmdw(struct channel_t *ch, uchar cmd, u16 word, uint ncmds)
5545 struct cm_t *cm_addr = NULL;
5551 if (!ch || ch->magic != DGAP_CHANNEL_MAGIC)
5555 * Check if board is still alive.
5557 if (ch->ch_bd->state == BOARD_FAILED) {
5558 DPR_CORE(("%s:%d board is failed!\n", __FILE__, __LINE__));
5563 * Make sure the pointers are in range before
5564 * writing to the FEP memory.
5566 vaddr = ch->ch_bd->re_map_membase;
5570 cm_addr = (struct cm_t *) (vaddr + CMDBUF);
5571 head = readw(&(cm_addr->cm_head));
5574 * Forget it if pointers out of range.
5576 if (head >= (CMDMAX - CMDSTART) || (head & 03)) {
5577 DPR_CORE(("%s:%d Pointers out of range. Failing board.\n",__FILE__, __LINE__));
5578 ch->ch_bd->state = BOARD_FAILED;
5583 * Put the data in the circular command buffer.
5585 writeb(cmd, (char *) (vaddr + head + CMDSTART + 0));
5586 writeb((uchar) ch->ch_portnum, (char *) (vaddr + head + CMDSTART + 1));
5587 writew((u16) word, (char *) (vaddr + head + CMDSTART + 2));
5589 head = (head + 4) & (CMDMAX - CMDSTART - 4);
5591 writew(head, &(cm_addr->cm_head));
5594 * Wait if necessary before updating the head
5595 * pointer to limit the number of outstanding
5596 * commands to the FEP. If the time spent waiting
5597 * is outlandish, declare the FEP dead.
5599 for (count = dgap_count ;;) {
5601 head = readw(&(cm_addr->cm_head));
5602 tail = readw(&(cm_addr->cm_tail));
5604 n = (head - tail) & (CMDMAX - CMDSTART - 4);
5606 if (n <= ncmds * sizeof(struct cm_t))
5610 DPR_CORE(("%s:%d Failing board.\n",__FILE__, __LINE__));
5611 ch->ch_bd->state = BOARD_FAILED;
5620 /*=======================================================================
5622 * dgap_cmdw_ext - Sends a extended word command to the FEP.
5624 * ch - Pointer to channel structure.
5625 * cmd - Command to be sent.
5626 * word - Integer containing word to be sent.
5627 * ncmds - Wait until ncmds or fewer cmds are left
5628 * in the cmd buffer before returning.
5630 *=======================================================================*/
5631 static void dgap_cmdw_ext(struct channel_t *ch, u16 cmd, u16 word, uint ncmds)
5634 struct cm_t *cm_addr = NULL;
5640 if (!ch || ch->magic != DGAP_CHANNEL_MAGIC)
5644 * Check if board is still alive.
5646 if (ch->ch_bd->state == BOARD_FAILED) {
5647 DPR_CORE(("%s:%d board is failed!\n", __FILE__, __LINE__));
5652 * Make sure the pointers are in range before
5653 * writing to the FEP memory.
5655 vaddr = ch->ch_bd->re_map_membase;
5659 cm_addr = (struct cm_t *) (vaddr + CMDBUF);
5660 head = readw(&(cm_addr->cm_head));
5663 * Forget it if pointers out of range.
5665 if (head >= (CMDMAX - CMDSTART) || (head & 03)) {
5666 DPR_CORE(("%s:%d Pointers out of range. Failing board.\n",__FILE__, __LINE__));
5667 ch->ch_bd->state = BOARD_FAILED;
5672 * Put the data in the circular command buffer.
5675 /* Write an FF to tell the FEP that we want an extended command */
5676 writeb((uchar) 0xff, (char *) (vaddr + head + CMDSTART + 0));
5678 writeb((uchar) ch->ch_portnum, (uchar *) (vaddr + head + CMDSTART + 1));
5679 writew((u16) cmd, (char *) (vaddr + head + CMDSTART + 2));
5682 * If the second part of the command won't fit,
5683 * put it at the beginning of the circular buffer.
5685 if (((head + 4) >= ((CMDMAX - CMDSTART)) || (head & 03))) {
5686 writew((u16) word, (char *) (vaddr + CMDSTART));
5688 writew((u16) word, (char *) (vaddr + head + CMDSTART + 4));
5691 head = (head + 8) & (CMDMAX - CMDSTART - 4);
5693 writew(head, &(cm_addr->cm_head));
5696 * Wait if necessary before updating the head
5697 * pointer to limit the number of outstanding
5698 * commands to the FEP. If the time spent waiting
5699 * is outlandish, declare the FEP dead.
5701 for (count = dgap_count ;;) {
5703 head = readw(&(cm_addr->cm_head));
5704 tail = readw(&(cm_addr->cm_tail));
5706 n = (head - tail) & (CMDMAX - CMDSTART - 4);
5708 if (n <= ncmds * sizeof(struct cm_t))
5712 DPR_CORE(("%s:%d Failing board.\n",__FILE__, __LINE__));
5713 ch->ch_bd->state = BOARD_FAILED;
5721 /*=======================================================================
5723 * dgap_wmove - Write data to FEP buffer.
5725 * ch - Pointer to channel structure.
5726 * buf - Poiter to characters to be moved.
5727 * cnt - Number of characters to move.
5729 *=======================================================================*/
5730 static void dgap_wmove(struct channel_t *ch, char *buf, uint cnt)
5737 if (!ch || ch->magic != DGAP_CHANNEL_MAGIC)
5744 head = readw(&(bs->tx_head));
5747 * If pointers are out of range, just return.
5749 if ((cnt > ch->ch_tsize) || (unsigned)(head - ch->ch_tstart) >= ch->ch_tsize) {
5750 DPR_CORE(("%s:%d pointer out of range", __FILE__, __LINE__));
5755 * If the write wraps over the top of the circular buffer,
5756 * move the portion up to the wrap point, and reset the
5757 * pointers to the bottom.
5759 n = ch->ch_tstart + ch->ch_tsize - head;
5763 taddr = ch->ch_taddr + head;
5764 memcpy_toio(taddr, buf, n);
5765 head = ch->ch_tstart;
5770 * Move rest of data.
5772 taddr = ch->ch_taddr + head;
5774 memcpy_toio(taddr, buf, n);
5777 writew(head, &(bs->tx_head));
5781 * Retrives the current custom baud rate from FEP memory,
5782 * and returns it back to the user.
5783 * Returns 0 on error.
5785 static uint dgap_get_custom_baud(struct channel_t *ch)
5791 if (!ch || ch->magic != DGAP_CHANNEL_MAGIC) {
5795 if (!ch->ch_bd || ch->ch_bd->magic != DGAP_BOARD_MAGIC) {
5799 if (!(ch->ch_bd->bd_flags & BD_FEP5PLUS))
5802 vaddr = ch->ch_bd->re_map_membase;
5808 * Go get from fep mem, what the fep
5809 * believes the custom baud rate is.
5811 offset = ((((*(unsigned short *)(vaddr + ECS_SEG)) << 4) +
5812 (ch->ch_portnum * 0x28) + LINE_SPEED));
5814 value = readw(vaddr + offset);
5820 * Calls the firmware to reset this channel.
5822 static void dgap_firmware_reset_port(struct channel_t *ch)
5824 dgap_cmdb(ch, CHRESET, 0, 0, 0);
5827 * Now that the channel is reset, we need to make sure
5828 * all the current settings get reapplied to the port
5831 * So we will set the driver's cache of firmware
5832 * settings all to 0, and then call param.
5834 ch->ch_fepiflag = 0;
5835 ch->ch_fepcflag = 0;
5836 ch->ch_fepoflag = 0;
5837 ch->ch_fepstartc = 0;
5838 ch->ch_fepstopc = 0;
5839 ch->ch_fepastartc = 0;
5840 ch->ch_fepastopc = 0;
5846 /*=======================================================================
5848 * dgap_param - Set Digi parameters.
5850 * struct tty_struct * - TTY for port.
5852 *=======================================================================*/
5853 static int dgap_param(struct tty_struct *tty)
5855 struct ktermios *ts;
5857 struct channel_t *ch;
5866 if (!tty || tty->magic != TTY_MAGIC)
5869 un = (struct un_t *) tty->driver_data;
5870 if (!un || un->magic != DGAP_UNIT_MAGIC)
5874 if (!ch || ch->magic != DGAP_CHANNEL_MAGIC)
5878 if (!bd || bd->magic != DGAP_BOARD_MAGIC)
5885 DPR_PARAM(("param start: tdev: %x cflags: %x oflags: %x iflags: %x\n",
5886 ch->ch_tun.un_dev, ch->ch_c_cflag, ch->ch_c_oflag, ch->ch_c_iflag));
5891 * If baud rate is zero, flush queues, and set mval to drop DTR.
5893 if ((ch->ch_c_cflag & (CBAUD)) == 0) {
5896 head = readw(&(ch->ch_bs->rx_head));
5897 writew(head, &(ch->ch_bs->rx_tail));
5900 head = readw(&(ch->ch_bs->tx_head));
5901 writew(head, &(ch->ch_bs->tx_tail));
5903 ch->ch_flags |= (CH_BAUD0);
5905 /* Drop RTS and DTR */
5906 ch->ch_mval &= ~(D_RTS(ch)|D_DTR(ch));
5907 mval = D_DTR(ch) | D_RTS(ch);
5908 ch->ch_baud_info = 0;
5910 } else if (ch->ch_custom_speed && (bd->bd_flags & BD_FEP5PLUS)) {
5912 * Tell the fep to do the command
5915 DPR_PARAM(("param: Want %d speed\n", ch->ch_custom_speed));
5917 dgap_cmdw_ext(ch, 0xff01, ch->ch_custom_speed, 0);
5920 * Now go get from fep mem, what the fep
5921 * believes the custom baud rate is.
5923 ch->ch_baud_info = ch->ch_custom_speed = dgap_get_custom_baud(ch);
5925 DPR_PARAM(("param: Got %d speed\n", ch->ch_custom_speed));
5927 /* Handle transition from B0 */
5928 if (ch->ch_flags & CH_BAUD0) {
5929 ch->ch_flags &= ~(CH_BAUD0);
5930 ch->ch_mval |= (D_RTS(ch)|D_DTR(ch));
5932 mval = D_DTR(ch) | D_RTS(ch);
5936 * Set baud rate, character size, and parity.
5944 ulong bauds[4][16] = {
5948 600, 1200, 1800, 2400,
5949 4800, 9600, 19200, 38400 },
5950 { /* slowbaud & CBAUDEX */
5951 0, 57600, 115200, 230400,
5952 460800, 150, 200, 921600,
5953 600, 1200, 1800, 2400,
5954 4800, 9600, 19200, 38400 },
5956 0, 57600, 76800, 115200,
5957 14400, 57600, 230400, 76800,
5958 115200, 230400, 28800, 460800,
5959 921600, 9600, 19200, 38400 },
5960 { /* fastbaud & CBAUDEX */
5961 0, 57600, 115200, 230400,
5962 460800, 150, 200, 921600,
5963 600, 1200, 1800, 2400,
5964 4800, 9600, 19200, 38400 }
5967 /* Only use the TXPrint baud rate if the terminal unit is NOT open */
5968 if (!(ch->ch_tun.un_flags & UN_ISOPEN) && (un->un_type == DGAP_PRINT))
5969 baud = C_BAUD(ch->ch_pun.un_tty) & 0xff;
5971 baud = C_BAUD(ch->ch_tun.un_tty) & 0xff;
5973 if (ch->ch_c_cflag & CBAUDEX)
5976 if (ch->ch_digi.digi_flags & DIGI_FAST)
5981 if ((iindex >= 0) && (iindex < 4) && (jindex >= 0) && (jindex < 16)) {
5982 baud = bauds[iindex][jindex];
5984 DPR_IOCTL(("baud indices were out of range (%d)(%d)",
5992 ch->ch_baud_info = baud;
5996 * CBAUD has bit position 0x1000 set these days to indicate Linux
5998 * We use a different bit assignment for high speed. Clear this
5999 * bit out while grabbing the parts of "cflag" we want.
6001 cflag = ch->ch_c_cflag & ((CBAUD ^ CBAUDEX) | PARODD | PARENB | CSTOPB | CSIZE);
6004 * HUPCL bit is used by FEP to indicate fast baud
6005 * table is to be used.
6007 if ((ch->ch_digi.digi_flags & DIGI_FAST) || (ch->ch_c_cflag & CBAUDEX))
6011 if ((ch->ch_c_cflag & CBAUDEX) && !(ch->ch_digi.digi_flags & DIGI_FAST)) {
6013 * The below code is trying to guarantee that only baud rates
6014 * 115200, 230400, 460800, 921600 are remapped. We use exclusive or
6015 * because the various baud rates share common bit positions
6016 * and therefore can't be tested for easily.
6018 tcflag_t tcflag = (ch->ch_c_cflag & CBAUD) | CBAUDEX;
6021 /* Map high speed requests to index into FEP's baud table */
6050 cflag = (cflag & ~(CBAUD | CBAUDEX)) | baudpart;
6055 if (cflag != ch->ch_fepcflag) {
6056 ch->ch_fepcflag = (u16) (cflag & 0xffff);
6058 /* Okay to have channel and board locks held calling this */
6059 dgap_cmdw(ch, SCFLAG, (u16) cflag, 0);
6062 /* Handle transition from B0 */
6063 if (ch->ch_flags & CH_BAUD0) {
6064 ch->ch_flags &= ~(CH_BAUD0);
6065 ch->ch_mval |= (D_RTS(ch)|D_DTR(ch));
6067 mval = D_DTR(ch) | D_RTS(ch);
6073 iflag = ch->ch_c_iflag & (IGNBRK | BRKINT | IGNPAR | PARMRK | INPCK | ISTRIP | IXON | IXANY | IXOFF);
6075 if ((ch->ch_startc == _POSIX_VDISABLE) || (ch->ch_stopc == _POSIX_VDISABLE)) {
6076 iflag &= ~(IXON | IXOFF);
6077 ch->ch_c_iflag &= ~(IXON | IXOFF);
6081 * Only the IBM Xr card can switch between
6082 * 232 and 422 modes on the fly
6084 if (bd->device == PCI_DEVICE_XR_IBM_DID) {
6085 if (ch->ch_digi.digi_flags & DIGI_422)
6086 dgap_cmdb(ch, SCOMMODE, MODE_422, 0, 0);
6088 dgap_cmdb(ch, SCOMMODE, MODE_232, 0, 0);
6091 if (ch->ch_digi.digi_flags & DIGI_ALTPIN)
6094 if (iflag != ch->ch_fepiflag) {
6095 ch->ch_fepiflag = iflag;
6097 /* Okay to have channel and board locks held calling this */
6098 dgap_cmdw(ch, SIFLAG, (u16) ch->ch_fepiflag, 0);
6102 * Select hardware handshaking.
6106 if (ch->ch_c_cflag & CRTSCTS) {
6107 hflow |= (D_RTS(ch) | D_CTS(ch));
6109 if (ch->ch_digi.digi_flags & RTSPACE)
6111 if (ch->ch_digi.digi_flags & DTRPACE)
6113 if (ch->ch_digi.digi_flags & CTSPACE)
6115 if (ch->ch_digi.digi_flags & DSRPACE)
6117 if (ch->ch_digi.digi_flags & DCDPACE)
6120 if (hflow != ch->ch_hflow) {
6121 ch->ch_hflow = hflow;
6123 /* Okay to have channel and board locks held calling this */
6124 dgap_cmdb(ch, SHFLOW, (uchar) hflow, 0xff, 0);
6129 * Set RTS and/or DTR Toggle if needed, but only if product is FEP5+ based.
6131 if (bd->bd_flags & BD_FEP5PLUS) {
6133 if (ch->ch_digi.digi_flags & DIGI_RTS_TOGGLE) {
6134 hflow2 |= (D_RTS(ch));
6136 if (ch->ch_digi.digi_flags & DIGI_DTR_TOGGLE) {
6137 hflow2 |= (D_DTR(ch));
6140 dgap_cmdw_ext(ch, 0xff03, hflow2, 0);
6144 * Set modem control lines.
6147 mval ^= ch->ch_mforce & (mval ^ ch->ch_mval);
6149 DPR_PARAM(("dgap_param: mval: %x ch_mforce: %x ch_mval: %x ch_mostat: %x\n",
6150 mval, ch->ch_mforce, ch->ch_mval, ch->ch_mostat));
6152 if (ch->ch_mostat ^ mval) {
6153 ch->ch_mostat = mval;
6155 /* Okay to have channel and board locks held calling this */
6156 DPR_PARAM(("dgap_param: Sending SMODEM mval: %x\n", mval));
6157 dgap_cmdb(ch, SMODEM, (uchar) mval, D_RTS(ch)|D_DTR(ch), 0);
6161 * Read modem signals, and then call carrier function.
6163 ch->ch_mistat = readb(&(bs->m_stat));
6167 * Set the start and stop characters.
6169 if (ch->ch_startc != ch->ch_fepstartc || ch->ch_stopc != ch->ch_fepstopc) {
6170 ch->ch_fepstartc = ch->ch_startc;
6171 ch->ch_fepstopc = ch->ch_stopc;
6173 /* Okay to have channel and board locks held calling this */
6174 dgap_cmdb(ch, SFLOWC, ch->ch_fepstartc, ch->ch_fepstopc, 0);
6178 * Set the Auxiliary start and stop characters.
6180 if (ch->ch_astartc != ch->ch_fepastartc || ch->ch_astopc != ch->ch_fepastopc) {
6181 ch->ch_fepastartc = ch->ch_astartc;
6182 ch->ch_fepastopc = ch->ch_astopc;
6184 /* Okay to have channel and board locks held calling this */
6185 dgap_cmdb(ch, SAFLOWC, ch->ch_fepastartc, ch->ch_fepastopc, 0);
6188 DPR_PARAM(("param finish\n"));
6195 * dgap_parity_scan()
6197 * Convert the FEP5 way of reporting parity errors and breaks into
6198 * the Linux line discipline way.
6200 static void dgap_parity_scan(struct channel_t *ch, unsigned char *cbuf, unsigned char *fbuf, int *len)
6204 unsigned char *in, *cout, *fout;
6211 DPR_PSCAN(("dgap_parity_scan start\n"));
6213 if (!ch || ch->magic != DGAP_CHANNEL_MAGIC)
6218 switch (ch->pscan_state) {
6220 /* reset to sanity and fall through */
6221 ch->pscan_state = 0;
6224 /* No FF seen yet */
6225 if (c == (unsigned char) '\377') {
6226 /* delete this character from stream */
6227 ch->pscan_state = 1;
6230 *fout++ = TTY_NORMAL;
6237 if (c == (unsigned char) '\377') {
6238 /* doubled ff, transform to single ff */
6240 *fout++ = TTY_NORMAL;
6242 ch->pscan_state = 0;
6244 /* save value examination in next state */
6245 ch->pscan_savechar = c;
6246 ch->pscan_state = 2;
6251 /* third character of ff sequence */
6255 if (ch->pscan_savechar == 0x0) {
6258 DPR_PSCAN(("dgap_parity_scan in 3rd char of ff seq. c: %x setting break.\n", c));
6260 *fout++ = TTY_BREAK;
6263 DPR_PSCAN(("dgap_parity_scan in 3rd char of ff seq. c: %x setting parity.\n", c));
6264 ch->ch_err_parity++;
6265 *fout++ = TTY_PARITY;
6269 DPR_PSCAN(("%s:%d Logic Error.\n", __FILE__, __LINE__));
6273 ch->pscan_state = 0;
6277 DPR_PSCAN(("dgap_parity_scan finish\n"));
6283 /*=======================================================================
6285 * dgap_event - FEP to host event processing routine.
6287 * bd - Board of current event.
6289 *=======================================================================*/
6290 static int dgap_event(struct board_t *bd)
6292 struct channel_t *ch;
6297 uchar *vaddr = NULL;
6298 struct ev_t *eaddr = NULL;
6306 if (!bd || bd->magic != DGAP_BOARD_MAGIC)
6309 DGAP_LOCK(bd->bd_lock, lock_flags);
6311 vaddr = bd->re_map_membase;
6314 DGAP_UNLOCK(bd->bd_lock, lock_flags);
6318 eaddr = (struct ev_t *) (vaddr + EVBUF);
6320 /* Get our head and tail */
6321 head = readw(&(eaddr->ev_head));
6322 tail = readw(&(eaddr->ev_tail));
6325 * Forget it if pointers out of range.
6328 if (head >= EVMAX - EVSTART || tail >= EVMAX - EVSTART ||
6329 (head | tail) & 03) {
6330 DPR_EVENT(("should be calling xxfail %d\n", __LINE__));
6331 /* Let go of board lock */
6332 DGAP_UNLOCK(bd->bd_lock, lock_flags);
6337 * Loop to process all the events in the buffer.
6339 while (tail != head) {
6342 * Get interrupt information.
6345 event = bd->re_map_membase + tail + EVSTART;
6352 DPR_EVENT(("event: jiffies: %ld port: %d reason: %x modem: %x\n",
6353 jiffies, port, reason, modem));
6356 * Make sure the interrupt is valid.
6358 if (port >= bd->nasync)
6361 if (!(reason & (IFMODEM | IFBREAK | IFTLW | IFTEM | IFDATA))) {
6365 ch = bd->channels[port];
6367 if (!ch || ch->magic != DGAP_CHANNEL_MAGIC) {
6372 * If we have made it here, the event was valid.
6373 * Lock down the channel.
6375 DGAP_LOCK(ch->ch_lock, lock_flags2);
6380 DGAP_UNLOCK(ch->ch_lock, lock_flags2);
6385 * Process received data.
6387 if (reason & IFDATA) {
6390 * ALL LOCKS *MUST* BE DROPPED BEFORE CALLING INPUT!
6391 * input could send some data to ld, which in turn
6392 * could do a callback to one of our other functions.
6394 DGAP_UNLOCK(ch->ch_lock, lock_flags2);
6395 DGAP_UNLOCK(bd->bd_lock, lock_flags);
6399 DGAP_LOCK(bd->bd_lock, lock_flags);
6400 DGAP_LOCK(ch->ch_lock, lock_flags2);
6402 if (ch->ch_flags & CH_RACTIVE)
6403 ch->ch_flags |= CH_RENABLE;
6405 writeb(1, &(bs->idata));
6407 if (ch->ch_flags & CH_RWAIT) {
6408 ch->ch_flags &= ~CH_RWAIT;
6410 wake_up_interruptible(&ch->ch_tun.un_flags_wait);
6415 * Process Modem change signals.
6417 if (reason & IFMODEM) {
6418 ch->ch_mistat = modem;
6425 if (reason & IFBREAK) {
6427 DPR_EVENT(("got IFBREAK\n"));
6429 if (ch->ch_tun.un_tty) {
6430 /* A break has been indicated */
6432 tty_buffer_request_room(ch->ch_tun.un_tty->port, 1);
6433 tty_insert_flip_char(ch->ch_tun.un_tty->port, 0, TTY_BREAK);
6434 tty_flip_buffer_push(ch->ch_tun.un_tty->port);
6439 * Process Transmit low.
6441 if (reason & IFTLW) {
6443 DPR_EVENT(("event: got low event\n"));
6445 if (ch->ch_tun.un_flags & UN_LOW) {
6446 ch->ch_tun.un_flags &= ~UN_LOW;
6448 if (ch->ch_tun.un_flags & UN_ISOPEN) {
6449 if ((ch->ch_tun.un_tty->flags &
6450 (1 << TTY_DO_WRITE_WAKEUP)) &&
6451 ch->ch_tun.un_tty->ldisc->ops->write_wakeup)
6453 DGAP_UNLOCK(ch->ch_lock, lock_flags2);
6454 DGAP_UNLOCK(bd->bd_lock, lock_flags);
6455 (ch->ch_tun.un_tty->ldisc->ops->write_wakeup)(ch->ch_tun.un_tty);
6456 DGAP_LOCK(bd->bd_lock, lock_flags);
6457 DGAP_LOCK(ch->ch_lock, lock_flags2);
6459 wake_up_interruptible(&ch->ch_tun.un_tty->write_wait);
6460 wake_up_interruptible(&ch->ch_tun.un_flags_wait);
6462 DPR_EVENT(("event: Got low event. jiffies: %lu\n", jiffies));
6466 if (ch->ch_pun.un_flags & UN_LOW) {
6467 ch->ch_pun.un_flags &= ~UN_LOW;
6468 if (ch->ch_pun.un_flags & UN_ISOPEN) {
6469 if ((ch->ch_pun.un_tty->flags &
6470 (1 << TTY_DO_WRITE_WAKEUP)) &&
6471 ch->ch_pun.un_tty->ldisc->ops->write_wakeup)
6473 DGAP_UNLOCK(ch->ch_lock, lock_flags2);
6474 DGAP_UNLOCK(bd->bd_lock, lock_flags);
6475 (ch->ch_pun.un_tty->ldisc->ops->write_wakeup)(ch->ch_pun.un_tty);
6476 DGAP_LOCK(bd->bd_lock, lock_flags);
6477 DGAP_LOCK(ch->ch_lock, lock_flags2);
6479 wake_up_interruptible(&ch->ch_pun.un_tty->write_wait);
6480 wake_up_interruptible(&ch->ch_pun.un_flags_wait);
6484 if (ch->ch_flags & CH_WLOW) {
6485 ch->ch_flags &= ~CH_WLOW;
6486 wake_up_interruptible(&ch->ch_flags_wait);
6491 * Process Transmit empty.
6493 if (reason & IFTEM) {
6494 DPR_EVENT(("event: got empty event\n"));
6496 if (ch->ch_tun.un_flags & UN_EMPTY) {
6497 ch->ch_tun.un_flags &= ~UN_EMPTY;
6498 if (ch->ch_tun.un_flags & UN_ISOPEN) {
6499 if ((ch->ch_tun.un_tty->flags &
6500 (1 << TTY_DO_WRITE_WAKEUP)) &&
6501 ch->ch_tun.un_tty->ldisc->ops->write_wakeup)
6503 DGAP_UNLOCK(ch->ch_lock, lock_flags2);
6504 DGAP_UNLOCK(bd->bd_lock, lock_flags);
6506 (ch->ch_tun.un_tty->ldisc->ops->write_wakeup)(ch->ch_tun.un_tty);
6507 DGAP_LOCK(bd->bd_lock, lock_flags);
6508 DGAP_LOCK(ch->ch_lock, lock_flags2);
6510 wake_up_interruptible(&ch->ch_tun.un_tty->write_wait);
6511 wake_up_interruptible(&ch->ch_tun.un_flags_wait);
6515 if (ch->ch_pun.un_flags & UN_EMPTY) {
6516 ch->ch_pun.un_flags &= ~UN_EMPTY;
6517 if (ch->ch_pun.un_flags & UN_ISOPEN) {
6518 if ((ch->ch_pun.un_tty->flags &
6519 (1 << TTY_DO_WRITE_WAKEUP)) &&
6520 ch->ch_pun.un_tty->ldisc->ops->write_wakeup)
6522 DGAP_UNLOCK(ch->ch_lock, lock_flags2);
6523 DGAP_UNLOCK(bd->bd_lock, lock_flags);
6524 (ch->ch_pun.un_tty->ldisc->ops->write_wakeup)(ch->ch_pun.un_tty);
6525 DGAP_LOCK(bd->bd_lock, lock_flags);
6526 DGAP_LOCK(ch->ch_lock, lock_flags2);
6528 wake_up_interruptible(&ch->ch_pun.un_tty->write_wait);
6529 wake_up_interruptible(&ch->ch_pun.un_flags_wait);
6534 if (ch->ch_flags & CH_WEMPTY) {
6535 ch->ch_flags &= ~CH_WEMPTY;
6536 wake_up_interruptible(&ch->ch_flags_wait);
6540 DGAP_UNLOCK(ch->ch_lock, lock_flags2);
6543 tail = (tail + 4) & (EVMAX - EVSTART - 4);
6546 writew(tail, &(eaddr->ev_tail));
6547 DGAP_UNLOCK(bd->bd_lock, lock_flags);
6552 static ssize_t dgap_driver_version_show(struct device_driver *ddp, char *buf)
6554 return snprintf(buf, PAGE_SIZE, "%s\n", DG_PART);
6556 static DRIVER_ATTR(version, S_IRUSR, dgap_driver_version_show, NULL);
6559 static ssize_t dgap_driver_boards_show(struct device_driver *ddp, char *buf)
6561 return snprintf(buf, PAGE_SIZE, "%d\n", dgap_NumBoards);
6563 static DRIVER_ATTR(boards, S_IRUSR, dgap_driver_boards_show, NULL);
6566 static ssize_t dgap_driver_maxboards_show(struct device_driver *ddp, char *buf)
6568 return snprintf(buf, PAGE_SIZE, "%d\n", MAXBOARDS);
6570 static DRIVER_ATTR(maxboards, S_IRUSR, dgap_driver_maxboards_show, NULL);
6573 static ssize_t dgap_driver_pollcounter_show(struct device_driver *ddp, char *buf)
6575 return snprintf(buf, PAGE_SIZE, "%ld\n", dgap_poll_counter);
6577 static DRIVER_ATTR(pollcounter, S_IRUSR, dgap_driver_pollcounter_show, NULL);
6580 static ssize_t dgap_driver_state_show(struct device_driver *ddp, char *buf)
6582 return snprintf(buf, PAGE_SIZE, "%s\n", dgap_driver_state_text[dgap_driver_state]);
6584 static DRIVER_ATTR(state, S_IRUSR, dgap_driver_state_show, NULL);
6587 static ssize_t dgap_driver_debug_show(struct device_driver *ddp, char *buf)
6589 return snprintf(buf, PAGE_SIZE, "0x%x\n", dgap_debug);
6592 static ssize_t dgap_driver_debug_store(struct device_driver *ddp, const char *buf, size_t count)
6594 sscanf(buf, "0x%x\n", &dgap_debug);
6597 static DRIVER_ATTR(debug, (S_IRUSR | S_IWUSR), dgap_driver_debug_show, dgap_driver_debug_store);
6600 static ssize_t dgap_driver_rawreadok_show(struct device_driver *ddp, char *buf)
6602 return snprintf(buf, PAGE_SIZE, "0x%x\n", dgap_rawreadok);
6605 static ssize_t dgap_driver_rawreadok_store(struct device_driver *ddp, const char *buf, size_t count)
6607 sscanf(buf, "0x%x\n", &dgap_rawreadok);
6610 static DRIVER_ATTR(rawreadok, (S_IRUSR | S_IWUSR), dgap_driver_rawreadok_show, dgap_driver_rawreadok_store);
6613 static ssize_t dgap_driver_pollrate_show(struct device_driver *ddp, char *buf)
6615 return snprintf(buf, PAGE_SIZE, "%dms\n", dgap_poll_tick);
6618 static ssize_t dgap_driver_pollrate_store(struct device_driver *ddp, const char *buf, size_t count)
6620 sscanf(buf, "%d\n", &dgap_poll_tick);
6623 static DRIVER_ATTR(pollrate, (S_IRUSR | S_IWUSR), dgap_driver_pollrate_show, dgap_driver_pollrate_store);
6626 static void dgap_create_driver_sysfiles(struct pci_driver *dgap_driver)
6629 struct device_driver *driverfs = &dgap_driver->driver;
6631 rc |= driver_create_file(driverfs, &driver_attr_version);
6632 rc |= driver_create_file(driverfs, &driver_attr_boards);
6633 rc |= driver_create_file(driverfs, &driver_attr_maxboards);
6634 rc |= driver_create_file(driverfs, &driver_attr_debug);
6635 rc |= driver_create_file(driverfs, &driver_attr_rawreadok);
6636 rc |= driver_create_file(driverfs, &driver_attr_pollrate);
6637 rc |= driver_create_file(driverfs, &driver_attr_pollcounter);
6638 rc |= driver_create_file(driverfs, &driver_attr_state);
6640 printk(KERN_ERR "DGAP: sysfs driver_create_file failed!\n");
6645 static void dgap_remove_driver_sysfiles(struct pci_driver *dgap_driver)
6647 struct device_driver *driverfs = &dgap_driver->driver;
6648 driver_remove_file(driverfs, &driver_attr_version);
6649 driver_remove_file(driverfs, &driver_attr_boards);
6650 driver_remove_file(driverfs, &driver_attr_maxboards);
6651 driver_remove_file(driverfs, &driver_attr_debug);
6652 driver_remove_file(driverfs, &driver_attr_rawreadok);
6653 driver_remove_file(driverfs, &driver_attr_pollrate);
6654 driver_remove_file(driverfs, &driver_attr_pollcounter);
6655 driver_remove_file(driverfs, &driver_attr_state);
6659 #define DGAP_VERIFY_BOARD(p, bd) \
6663 bd = dev_get_drvdata(p); \
6664 if (!bd || bd->magic != DGAP_BOARD_MAGIC) \
6666 if (bd->state != BOARD_READY) \
6670 static ssize_t dgap_ports_state_show(struct device *p, struct device_attribute *attr, char *buf)
6676 DGAP_VERIFY_BOARD(p, bd);
6678 for (i = 0; i < bd->nasync; i++) {
6679 count += snprintf(buf + count, PAGE_SIZE - count,
6680 "%d %s\n", bd->channels[i]->ch_portnum,
6681 bd->channels[i]->ch_open_count ? "Open" : "Closed");
6685 static DEVICE_ATTR(ports_state, S_IRUSR, dgap_ports_state_show, NULL);
6688 static ssize_t dgap_ports_baud_show(struct device *p, struct device_attribute *attr, char *buf)
6694 DGAP_VERIFY_BOARD(p, bd);
6696 for (i = 0; i < bd->nasync; i++) {
6697 count += snprintf(buf + count, PAGE_SIZE - count,
6698 "%d %d\n", bd->channels[i]->ch_portnum, bd->channels[i]->ch_baud_info);
6702 static DEVICE_ATTR(ports_baud, S_IRUSR, dgap_ports_baud_show, NULL);
6705 static ssize_t dgap_ports_msignals_show(struct device *p, struct device_attribute *attr, char *buf)
6711 DGAP_VERIFY_BOARD(p, bd);
6713 for (i = 0; i < bd->nasync; i++) {
6714 if (bd->channels[i]->ch_open_count) {
6715 count += snprintf(buf + count, PAGE_SIZE - count,
6716 "%d %s %s %s %s %s %s\n", bd->channels[i]->ch_portnum,
6717 (bd->channels[i]->ch_mostat & UART_MCR_RTS) ? "RTS" : "",
6718 (bd->channels[i]->ch_mistat & UART_MSR_CTS) ? "CTS" : "",
6719 (bd->channels[i]->ch_mostat & UART_MCR_DTR) ? "DTR" : "",
6720 (bd->channels[i]->ch_mistat & UART_MSR_DSR) ? "DSR" : "",
6721 (bd->channels[i]->ch_mistat & UART_MSR_DCD) ? "DCD" : "",
6722 (bd->channels[i]->ch_mistat & UART_MSR_RI) ? "RI" : "");
6724 count += snprintf(buf + count, PAGE_SIZE - count,
6725 "%d\n", bd->channels[i]->ch_portnum);
6730 static DEVICE_ATTR(ports_msignals, S_IRUSR, dgap_ports_msignals_show, NULL);
6733 static ssize_t dgap_ports_iflag_show(struct device *p, struct device_attribute *attr, char *buf)
6739 DGAP_VERIFY_BOARD(p, bd);
6741 for (i = 0; i < bd->nasync; i++) {
6742 count += snprintf(buf + count, PAGE_SIZE - count, "%d %x\n",
6743 bd->channels[i]->ch_portnum, bd->channels[i]->ch_c_iflag);
6747 static DEVICE_ATTR(ports_iflag, S_IRUSR, dgap_ports_iflag_show, NULL);
6750 static ssize_t dgap_ports_cflag_show(struct device *p, struct device_attribute *attr, char *buf)
6756 DGAP_VERIFY_BOARD(p, bd);
6758 for (i = 0; i < bd->nasync; i++) {
6759 count += snprintf(buf + count, PAGE_SIZE - count, "%d %x\n",
6760 bd->channels[i]->ch_portnum, bd->channels[i]->ch_c_cflag);
6764 static DEVICE_ATTR(ports_cflag, S_IRUSR, dgap_ports_cflag_show, NULL);
6767 static ssize_t dgap_ports_oflag_show(struct device *p, struct device_attribute *attr, char *buf)
6773 DGAP_VERIFY_BOARD(p, bd);
6775 for (i = 0; i < bd->nasync; i++) {
6776 count += snprintf(buf + count, PAGE_SIZE - count, "%d %x\n",
6777 bd->channels[i]->ch_portnum, bd->channels[i]->ch_c_oflag);
6781 static DEVICE_ATTR(ports_oflag, S_IRUSR, dgap_ports_oflag_show, NULL);
6784 static ssize_t dgap_ports_lflag_show(struct device *p, struct device_attribute *attr, char *buf)
6790 DGAP_VERIFY_BOARD(p, bd);
6792 for (i = 0; i < bd->nasync; i++) {
6793 count += snprintf(buf + count, PAGE_SIZE - count, "%d %x\n",
6794 bd->channels[i]->ch_portnum, bd->channels[i]->ch_c_lflag);
6798 static DEVICE_ATTR(ports_lflag, S_IRUSR, dgap_ports_lflag_show, NULL);
6801 static ssize_t dgap_ports_digi_flag_show(struct device *p, struct device_attribute *attr, char *buf)
6807 DGAP_VERIFY_BOARD(p, bd);
6809 for (i = 0; i < bd->nasync; i++) {
6810 count += snprintf(buf + count, PAGE_SIZE - count, "%d %x\n",
6811 bd->channels[i]->ch_portnum, bd->channels[i]->ch_digi.digi_flags);
6815 static DEVICE_ATTR(ports_digi_flag, S_IRUSR, dgap_ports_digi_flag_show, NULL);
6818 static ssize_t dgap_ports_rxcount_show(struct device *p, struct device_attribute *attr, char *buf)
6824 DGAP_VERIFY_BOARD(p, bd);
6826 for (i = 0; i < bd->nasync; i++) {
6827 count += snprintf(buf + count, PAGE_SIZE - count, "%d %ld\n",
6828 bd->channels[i]->ch_portnum, bd->channels[i]->ch_rxcount);
6832 static DEVICE_ATTR(ports_rxcount, S_IRUSR, dgap_ports_rxcount_show, NULL);
6835 static ssize_t dgap_ports_txcount_show(struct device *p, struct device_attribute *attr, char *buf)
6841 DGAP_VERIFY_BOARD(p, bd);
6843 for (i = 0; i < bd->nasync; i++) {
6844 count += snprintf(buf + count, PAGE_SIZE - count, "%d %ld\n",
6845 bd->channels[i]->ch_portnum, bd->channels[i]->ch_txcount);
6849 static DEVICE_ATTR(ports_txcount, S_IRUSR, dgap_ports_txcount_show, NULL);
6852 /* this function creates the sys files that will export each signal status
6853 * to sysfs each value will be put in a separate filename
6855 static void dgap_create_ports_sysfiles(struct board_t *bd)
6859 dev_set_drvdata(&bd->pdev->dev, bd);
6860 rc |= device_create_file(&(bd->pdev->dev), &dev_attr_ports_state);
6861 rc |= device_create_file(&(bd->pdev->dev), &dev_attr_ports_baud);
6862 rc |= device_create_file(&(bd->pdev->dev), &dev_attr_ports_msignals);
6863 rc |= device_create_file(&(bd->pdev->dev), &dev_attr_ports_iflag);
6864 rc |= device_create_file(&(bd->pdev->dev), &dev_attr_ports_cflag);
6865 rc |= device_create_file(&(bd->pdev->dev), &dev_attr_ports_oflag);
6866 rc |= device_create_file(&(bd->pdev->dev), &dev_attr_ports_lflag);
6867 rc |= device_create_file(&(bd->pdev->dev), &dev_attr_ports_digi_flag);
6868 rc |= device_create_file(&(bd->pdev->dev), &dev_attr_ports_rxcount);
6869 rc |= device_create_file(&(bd->pdev->dev), &dev_attr_ports_txcount);
6871 printk(KERN_ERR "DGAP: sysfs device_create_file failed!\n");
6876 /* removes all the sys files created for that port */
6877 static void dgap_remove_ports_sysfiles(struct board_t *bd)
6879 device_remove_file(&(bd->pdev->dev), &dev_attr_ports_state);
6880 device_remove_file(&(bd->pdev->dev), &dev_attr_ports_baud);
6881 device_remove_file(&(bd->pdev->dev), &dev_attr_ports_msignals);
6882 device_remove_file(&(bd->pdev->dev), &dev_attr_ports_iflag);
6883 device_remove_file(&(bd->pdev->dev), &dev_attr_ports_cflag);
6884 device_remove_file(&(bd->pdev->dev), &dev_attr_ports_oflag);
6885 device_remove_file(&(bd->pdev->dev), &dev_attr_ports_lflag);
6886 device_remove_file(&(bd->pdev->dev), &dev_attr_ports_digi_flag);
6887 device_remove_file(&(bd->pdev->dev), &dev_attr_ports_rxcount);
6888 device_remove_file(&(bd->pdev->dev), &dev_attr_ports_txcount);
6892 static ssize_t dgap_tty_state_show(struct device *d, struct device_attribute *attr, char *buf)
6895 struct channel_t *ch;
6900 un = dev_get_drvdata(d);
6901 if (!un || un->magic != DGAP_UNIT_MAGIC)
6904 if (!ch || ch->magic != DGAP_CHANNEL_MAGIC)
6907 if (!bd || bd->magic != DGAP_BOARD_MAGIC)
6909 if (bd->state != BOARD_READY)
6912 return snprintf(buf, PAGE_SIZE, "%s", un->un_open_count ? "Open" : "Closed");
6914 static DEVICE_ATTR(state, S_IRUSR, dgap_tty_state_show, NULL);
6917 static ssize_t dgap_tty_baud_show(struct device *d, struct device_attribute *attr, char *buf)
6920 struct channel_t *ch;
6925 un = dev_get_drvdata(d);
6926 if (!un || un->magic != DGAP_UNIT_MAGIC)
6929 if (!ch || ch->magic != DGAP_CHANNEL_MAGIC)
6932 if (!bd || bd->magic != DGAP_BOARD_MAGIC)
6934 if (bd->state != BOARD_READY)
6937 return snprintf(buf, PAGE_SIZE, "%d\n", ch->ch_baud_info);
6939 static DEVICE_ATTR(baud, S_IRUSR, dgap_tty_baud_show, NULL);
6942 static ssize_t dgap_tty_msignals_show(struct device *d, struct device_attribute *attr, char *buf)
6945 struct channel_t *ch;
6950 un = dev_get_drvdata(d);
6951 if (!un || un->magic != DGAP_UNIT_MAGIC)
6954 if (!ch || ch->magic != DGAP_CHANNEL_MAGIC)
6957 if (!bd || bd->magic != DGAP_BOARD_MAGIC)
6959 if (bd->state != BOARD_READY)
6962 if (ch->ch_open_count) {
6963 return snprintf(buf, PAGE_SIZE, "%s %s %s %s %s %s\n",
6964 (ch->ch_mostat & UART_MCR_RTS) ? "RTS" : "",
6965 (ch->ch_mistat & UART_MSR_CTS) ? "CTS" : "",
6966 (ch->ch_mostat & UART_MCR_DTR) ? "DTR" : "",
6967 (ch->ch_mistat & UART_MSR_DSR) ? "DSR" : "",
6968 (ch->ch_mistat & UART_MSR_DCD) ? "DCD" : "",
6969 (ch->ch_mistat & UART_MSR_RI) ? "RI" : "");
6973 static DEVICE_ATTR(msignals, S_IRUSR, dgap_tty_msignals_show, NULL);
6976 static ssize_t dgap_tty_iflag_show(struct device *d, struct device_attribute *attr, char *buf)
6979 struct channel_t *ch;
6984 un = dev_get_drvdata(d);
6985 if (!un || un->magic != DGAP_UNIT_MAGIC)
6988 if (!ch || ch->magic != DGAP_CHANNEL_MAGIC)
6991 if (!bd || bd->magic != DGAP_BOARD_MAGIC)
6993 if (bd->state != BOARD_READY)
6996 return snprintf(buf, PAGE_SIZE, "%x\n", ch->ch_c_iflag);
6998 static DEVICE_ATTR(iflag, S_IRUSR, dgap_tty_iflag_show, NULL);
7001 static ssize_t dgap_tty_cflag_show(struct device *d, struct device_attribute *attr, char *buf)
7004 struct channel_t *ch;
7009 un = dev_get_drvdata(d);
7010 if (!un || un->magic != DGAP_UNIT_MAGIC)
7013 if (!ch || ch->magic != DGAP_CHANNEL_MAGIC)
7016 if (!bd || bd->magic != DGAP_BOARD_MAGIC)
7018 if (bd->state != BOARD_READY)
7021 return snprintf(buf, PAGE_SIZE, "%x\n", ch->ch_c_cflag);
7023 static DEVICE_ATTR(cflag, S_IRUSR, dgap_tty_cflag_show, NULL);
7026 static ssize_t dgap_tty_oflag_show(struct device *d, struct device_attribute *attr, char *buf)
7029 struct channel_t *ch;
7034 un = dev_get_drvdata(d);
7035 if (!un || un->magic != DGAP_UNIT_MAGIC)
7038 if (!ch || ch->magic != DGAP_CHANNEL_MAGIC)
7041 if (!bd || bd->magic != DGAP_BOARD_MAGIC)
7043 if (bd->state != BOARD_READY)
7046 return snprintf(buf, PAGE_SIZE, "%x\n", ch->ch_c_oflag);
7048 static DEVICE_ATTR(oflag, S_IRUSR, dgap_tty_oflag_show, NULL);
7051 static ssize_t dgap_tty_lflag_show(struct device *d, struct device_attribute *attr, char *buf)
7054 struct channel_t *ch;
7059 un = dev_get_drvdata(d);
7060 if (!un || un->magic != DGAP_UNIT_MAGIC)
7063 if (!ch || ch->magic != DGAP_CHANNEL_MAGIC)
7066 if (!bd || bd->magic != DGAP_BOARD_MAGIC)
7068 if (bd->state != BOARD_READY)
7071 return snprintf(buf, PAGE_SIZE, "%x\n", ch->ch_c_lflag);
7073 static DEVICE_ATTR(lflag, S_IRUSR, dgap_tty_lflag_show, NULL);
7076 static ssize_t dgap_tty_digi_flag_show(struct device *d, struct device_attribute *attr, char *buf)
7079 struct channel_t *ch;
7084 un = dev_get_drvdata(d);
7085 if (!un || un->magic != DGAP_UNIT_MAGIC)
7088 if (!ch || ch->magic != DGAP_CHANNEL_MAGIC)
7091 if (!bd || bd->magic != DGAP_BOARD_MAGIC)
7093 if (bd->state != BOARD_READY)
7096 return snprintf(buf, PAGE_SIZE, "%x\n", ch->ch_digi.digi_flags);
7098 static DEVICE_ATTR(digi_flag, S_IRUSR, dgap_tty_digi_flag_show, NULL);
7101 static ssize_t dgap_tty_rxcount_show(struct device *d, struct device_attribute *attr, char *buf)
7104 struct channel_t *ch;
7109 un = dev_get_drvdata(d);
7110 if (!un || un->magic != DGAP_UNIT_MAGIC)
7113 if (!ch || ch->magic != DGAP_CHANNEL_MAGIC)
7116 if (!bd || bd->magic != DGAP_BOARD_MAGIC)
7118 if (bd->state != BOARD_READY)
7121 return snprintf(buf, PAGE_SIZE, "%ld\n", ch->ch_rxcount);
7123 static DEVICE_ATTR(rxcount, S_IRUSR, dgap_tty_rxcount_show, NULL);
7126 static ssize_t dgap_tty_txcount_show(struct device *d, struct device_attribute *attr, char *buf)
7129 struct channel_t *ch;
7134 un = dev_get_drvdata(d);
7135 if (!un || un->magic != DGAP_UNIT_MAGIC)
7138 if (!ch || ch->magic != DGAP_CHANNEL_MAGIC)
7141 if (!bd || bd->magic != DGAP_BOARD_MAGIC)
7143 if (bd->state != BOARD_READY)
7146 return snprintf(buf, PAGE_SIZE, "%ld\n", ch->ch_txcount);
7148 static DEVICE_ATTR(txcount, S_IRUSR, dgap_tty_txcount_show, NULL);
7151 static ssize_t dgap_tty_name_show(struct device *d, struct device_attribute *attr, char *buf)
7154 struct channel_t *ch;
7158 struct cnode *cptr = NULL;
7166 un = dev_get_drvdata(d);
7167 if (!un || un->magic != DGAP_UNIT_MAGIC)
7170 if (!ch || ch->magic != DGAP_CHANNEL_MAGIC)
7173 if (!bd || bd->magic != DGAP_BOARD_MAGIC)
7175 if (bd->state != BOARD_READY)
7179 cn = ch->ch_portnum;
7181 for (cptr = bd->bd_config; cptr; cptr = cptr->next) {
7183 if ((cptr->type == BNODE) &&
7184 ((cptr->u.board.type == APORT2_920P) || (cptr->u.board.type == APORT4_920P) ||
7185 (cptr->u.board.type == APORT8_920P) || (cptr->u.board.type == PAPORT4) ||
7186 (cptr->u.board.type == PAPORT8))) {
7189 if (cptr->u.board.v_start)
7190 starto = cptr->u.board.start;
7195 if (cptr->type == TNODE && found == TRUE) {
7197 if (strstr(cptr->u.ttyname, "tty")) {
7198 ptr1 = cptr->u.ttyname;
7202 ptr1 = cptr->u.ttyname;
7205 for (i = 0; i < dgap_config_get_number_of_ports(bd); i++) {
7207 return snprintf(buf, PAGE_SIZE, "%s%s%02d\n",
7208 (un->un_type == DGAP_PRINT) ? "pr" : "tty",
7214 if (cptr->type == CNODE) {
7216 for (i = 0; i < cptr->u.conc.nport; i++) {
7217 if (cn == (i + ncount)) {
7219 return snprintf(buf, PAGE_SIZE, "%s%s%02d\n",
7220 (un->un_type == DGAP_PRINT) ? "pr" : "tty",
7222 i + (cptr->u.conc.v_start ? cptr->u.conc.start : 1));
7226 ncount += cptr->u.conc.nport;
7229 if (cptr->type == MNODE) {
7231 for (i = 0; i < cptr->u.module.nport; i++) {
7232 if (cn == (i + ncount)) {
7233 return snprintf(buf, PAGE_SIZE, "%s%s%02d\n",
7234 (un->un_type == DGAP_PRINT) ? "pr" : "tty",
7236 i + (cptr->u.module.v_start ? cptr->u.module.start : 1));
7240 ncount += cptr->u.module.nport;
7245 return snprintf(buf, PAGE_SIZE, "%s_dgap_%d_%d\n",
7246 (un->un_type == DGAP_PRINT) ? "pr" : "tty", bn, cn);
7249 static DEVICE_ATTR(custom_name, S_IRUSR, dgap_tty_name_show, NULL);
7252 static struct attribute *dgap_sysfs_tty_entries[] = {
7253 &dev_attr_state.attr,
7254 &dev_attr_baud.attr,
7255 &dev_attr_msignals.attr,
7256 &dev_attr_iflag.attr,
7257 &dev_attr_cflag.attr,
7258 &dev_attr_oflag.attr,
7259 &dev_attr_lflag.attr,
7260 &dev_attr_digi_flag.attr,
7261 &dev_attr_rxcount.attr,
7262 &dev_attr_txcount.attr,
7263 &dev_attr_custom_name.attr,
7268 static struct attribute_group dgap_tty_attribute_group = {
7270 .attrs = dgap_sysfs_tty_entries,
7276 static void dgap_create_tty_sysfs(struct un_t *un, struct device *c)
7280 ret = sysfs_create_group(&c->kobj, &dgap_tty_attribute_group);
7282 printk(KERN_ERR "dgap: failed to create sysfs tty device attributes.\n");
7283 sysfs_remove_group(&c->kobj, &dgap_tty_attribute_group);
7287 dev_set_drvdata(c, un);
7292 static void dgap_remove_tty_sysfs(struct device *c)
7294 sysfs_remove_group(&c->kobj, &dgap_tty_attribute_group);
7298 * Parse a configuration file read into memory as a string.
7300 static int dgap_parsefile(char **in, int Remove)
7302 struct cnode *p, *brd, *line, *conc;
7304 char *s = NULL, *s2 = NULL;
7308 brd = line = conc = NULL;
7310 /* perhaps we are adding to an existing list? */
7311 while (p->next != NULL) {
7315 /* file must start with a BEGIN */
7316 while ( (rc = dgap_gettok(in,p)) != BEGIN ) {
7318 dgap_err("unexpected EOF");
7324 rc = dgap_gettok(in,p);
7326 dgap_err("unexpected EOF");
7332 dgap_err("unexpected end of file");
7335 case BEGIN: /* should only be 1 begin */
7336 dgap_err("unexpected config_begin\n");
7342 case BOARD: /* board info */
7343 if (dgap_checknode(p))
7345 if ( (p->next = dgap_newnode(BNODE)) == NULL ) {
7346 dgap_err("out of memory");
7351 p->u.board.status = dgap_savestring("No");
7357 case APORT2_920P: /* AccelePort_4 */
7358 if (p->type != BNODE) {
7359 dgap_err("unexpected Digi_2r_920 string");
7362 p->u.board.type = APORT2_920P;
7363 p->u.board.v_type = 1;
7364 DPR_INIT(("Adding Digi_2r_920 PCI to config...\n"));
7367 case APORT4_920P: /* AccelePort_4 */
7368 if (p->type != BNODE) {
7369 dgap_err("unexpected Digi_4r_920 string");
7372 p->u.board.type = APORT4_920P;
7373 p->u.board.v_type = 1;
7374 DPR_INIT(("Adding Digi_4r_920 PCI to config...\n"));
7377 case APORT8_920P: /* AccelePort_8 */
7378 if (p->type != BNODE) {
7379 dgap_err("unexpected Digi_8r_920 string");
7382 p->u.board.type = APORT8_920P;
7383 p->u.board.v_type = 1;
7384 DPR_INIT(("Adding Digi_8r_920 PCI to config...\n"));
7387 case PAPORT4: /* AccelePort_4 PCI */
7388 if (p->type != BNODE) {
7389 dgap_err("unexpected Digi_4r(PCI) string");
7392 p->u.board.type = PAPORT4;
7393 p->u.board.v_type = 1;
7394 DPR_INIT(("Adding Digi_4r PCI to config...\n"));
7397 case PAPORT8: /* AccelePort_8 PCI */
7398 if (p->type != BNODE) {
7399 dgap_err("unexpected Digi_8r string");
7402 p->u.board.type = PAPORT8;
7403 p->u.board.v_type = 1;
7404 DPR_INIT(("Adding Digi_8r PCI to config...\n"));
7407 case PCX: /* PCI C/X */
7408 if (p->type != BNODE) {
7409 dgap_err("unexpected Digi_C/X_(PCI) string");
7412 p->u.board.type = PCX;
7413 p->u.board.v_type = 1;
7414 p->u.board.conc1 = 0;
7415 p->u.board.conc2 = 0;
7416 p->u.board.module1 = 0;
7417 p->u.board.module2 = 0;
7418 DPR_INIT(("Adding PCI C/X to config...\n"));
7421 case PEPC: /* PCI EPC/X */
7422 if (p->type != BNODE) {
7423 dgap_err("unexpected \"Digi_EPC/X_(PCI)\" string");
7426 p->u.board.type = PEPC;
7427 p->u.board.v_type = 1;
7428 p->u.board.conc1 = 0;
7429 p->u.board.conc2 = 0;
7430 p->u.board.module1 = 0;
7431 p->u.board.module2 = 0;
7432 DPR_INIT(("Adding PCI EPC/X to config...\n"));
7435 case PPCM: /* PCI/Xem */
7436 if (p->type != BNODE) {
7437 dgap_err("unexpected PCI/Xem string");
7440 p->u.board.type = PPCM;
7441 p->u.board.v_type = 1;
7442 p->u.board.conc1 = 0;
7443 p->u.board.conc2 = 0;
7444 DPR_INIT(("Adding PCI XEM to config...\n"));
7447 case IO: /* i/o port */
7448 if (p->type != BNODE) {
7449 dgap_err("IO port only vaild for boards");
7452 s = dgap_getword(in);
7454 dgap_err("unexpected end of file");
7457 p->u.board.portstr = dgap_savestring(s);
7458 p->u.board.port = (short)simple_strtol(s, &s2, 0);
7459 if ((short)strlen(s) > (short)(s2 - s)) {
7460 dgap_err("bad number for IO port");
7463 p->u.board.v_port = 1;
7464 DPR_INIT(("Adding IO (%s) to config...\n", s));
7467 case MEM: /* memory address */
7468 if (p->type != BNODE) {
7469 dgap_err("memory address only vaild for boards");
7472 s = dgap_getword(in);
7474 dgap_err("unexpected end of file");
7477 p->u.board.addrstr = dgap_savestring(s);
7478 p->u.board.addr = simple_strtoul(s, &s2, 0);
7479 if ((int)strlen(s) > (int)(s2 - s)) {
7480 dgap_err("bad number for memory address");
7483 p->u.board.v_addr = 1;
7484 DPR_INIT(("Adding MEM (%s) to config...\n", s));
7487 case PCIINFO: /* pci information */
7488 if (p->type != BNODE) {
7489 dgap_err("memory address only vaild for boards");
7492 s = dgap_getword(in);
7494 dgap_err("unexpected end of file");
7497 p->u.board.pcibusstr = dgap_savestring(s);
7498 p->u.board.pcibus = simple_strtoul(s, &s2, 0);
7499 if ((int)strlen(s) > (int)(s2 - s)) {
7500 dgap_err("bad number for pci bus");
7503 p->u.board.v_pcibus = 1;
7504 s = dgap_getword(in);
7506 dgap_err("unexpected end of file");
7509 p->u.board.pcislotstr = dgap_savestring(s);
7510 p->u.board.pcislot = simple_strtoul(s, &s2, 0);
7511 if ((int)strlen(s) > (int)(s2 - s)) {
7512 dgap_err("bad number for pci slot");
7515 p->u.board.v_pcislot = 1;
7517 DPR_INIT(("Adding PCIINFO (%s %s) to config...\n", p->u.board.pcibusstr,
7518 p->u.board.pcislotstr));
7522 if (p->type != BNODE) {
7523 dgap_err("install method only vaild for boards");
7526 s = dgap_getword(in);
7528 dgap_err("unexpected end of file");
7531 p->u.board.method = dgap_savestring(s);
7532 p->u.board.v_method = 1;
7533 DPR_INIT(("Adding METHOD (%s) to config...\n", s));
7537 if (p->type != BNODE) {
7538 dgap_err("config status only vaild for boards");
7541 s = dgap_getword(in);
7543 dgap_err("unexpected end of file");
7546 p->u.board.status = dgap_savestring(s);
7547 DPR_INIT(("Adding STATUS (%s) to config...\n", s));
7550 case NPORTS: /* number of ports */
7551 if (p->type == BNODE) {
7552 s = dgap_getword(in);
7554 dgap_err("unexpected end of file");
7557 p->u.board.nport = (char)simple_strtol(s, &s2, 0);
7558 if ((int)strlen(s) > (int)(s2 - s)) {
7559 dgap_err("bad number for number of ports");
7562 p->u.board.v_nport = 1;
7563 } else if (p->type == CNODE) {
7564 s = dgap_getword(in);
7566 dgap_err("unexpected end of file");
7569 p->u.conc.nport = (char)simple_strtol(s, &s2, 0);
7570 if ((int)strlen(s) > (int)(s2 - s)) {
7571 dgap_err("bad number for number of ports");
7574 p->u.conc.v_nport = 1;
7575 } else if (p->type == MNODE) {
7576 s = dgap_getword(in);
7578 dgap_err("unexpected end of file");
7581 p->u.module.nport = (char)simple_strtol(s, &s2, 0);
7582 if ((int)strlen(s) > (int)(s2 - s)) {
7583 dgap_err("bad number for number of ports");
7586 p->u.module.v_nport = 1;
7588 dgap_err("nports only valid for concentrators or modules");
7591 DPR_INIT(("Adding NPORTS (%s) to config...\n", s));
7594 case ID: /* letter ID used in tty name */
7595 s = dgap_getword(in);
7597 dgap_err("unexpected end of file");
7601 p->u.board.status = dgap_savestring(s);
7603 if (p->type == CNODE) {
7604 p->u.conc.id = dgap_savestring(s);
7606 } else if (p->type == MNODE) {
7607 p->u.module.id = dgap_savestring(s);
7608 p->u.module.v_id = 1;
7610 dgap_err("id only valid for concentrators or modules");
7613 DPR_INIT(("Adding ID (%s) to config...\n", s));
7616 case STARTO: /* start offset of ID */
7617 if (p->type == BNODE) {
7618 s = dgap_getword(in);
7620 dgap_err("unexpected end of file");
7623 p->u.board.start = simple_strtol(s, &s2, 0);
7624 if ((int)strlen(s) > (int)(s2 - s)) {
7625 dgap_err("bad number for start of tty count");
7628 p->u.board.v_start = 1;
7629 } else if (p->type == CNODE) {
7630 s = dgap_getword(in);
7632 dgap_err("unexpected end of file");
7635 p->u.conc.start = simple_strtol(s, &s2, 0);
7636 if ((int)strlen(s) > (int)(s2 - s)) {
7637 dgap_err("bad number for start of tty count");
7640 p->u.conc.v_start = 1;
7641 } else if (p->type == MNODE) {
7642 s = dgap_getword(in);
7644 dgap_err("unexpected end of file");
7647 p->u.module.start = simple_strtol(s, &s2, 0);
7648 if ((int)strlen(s) > (int)(s2 - s)) {
7649 dgap_err("bad number for start of tty count");
7652 p->u.module.v_start = 1;
7654 dgap_err("start only valid for concentrators or modules");
7657 DPR_INIT(("Adding START (%s) to config...\n", s));
7660 case TTYN: /* tty name prefix */
7661 if (dgap_checknode(p))
7663 if ( (p->next = dgap_newnode(TNODE)) == NULL ) {
7664 dgap_err("out of memory");
7668 if ( (s = dgap_getword(in)) == NULL ) {
7669 dgap_err("unexpeced end of file");
7672 if ( (p->u.ttyname = dgap_savestring(s)) == NULL ) {
7673 dgap_err("out of memory");
7676 DPR_INIT(("Adding TTY (%s) to config...\n", s));
7679 case CU: /* cu name prefix */
7680 if (dgap_checknode(p))
7682 if ( (p->next = dgap_newnode(CUNODE)) == NULL ) {
7683 dgap_err("out of memory");
7687 if ( (s = dgap_getword(in)) == NULL ) {
7688 dgap_err("unexpeced end of file");
7691 if ( (p->u.cuname = dgap_savestring(s)) == NULL ) {
7692 dgap_err("out of memory");
7695 DPR_INIT(("Adding CU (%s) to config...\n", s));
7698 case LINE: /* line information */
7699 if (dgap_checknode(p))
7702 dgap_err("must specify board before line info");
7705 switch (brd->u.board.type) {
7707 dgap_err("line not vaild for PC/em");
7710 if ( (p->next = dgap_newnode(LNODE)) == NULL ) {
7711 dgap_err("out of memory");
7718 DPR_INIT(("Adding LINE to config...\n"));
7721 case CONC: /* concentrator information */
7722 if (dgap_checknode(p))
7725 dgap_err("must specify line info before concentrator");
7728 if ( (p->next = dgap_newnode(CNODE)) == NULL ) {
7729 dgap_err("out of memory");
7735 brd->u.board.conc2++;
7737 brd->u.board.conc1++;
7739 DPR_INIT(("Adding CONC to config...\n"));
7742 case CX: /* c/x type concentrator */
7743 if (p->type != CNODE) {
7744 dgap_err("cx only valid for concentrators");
7747 p->u.conc.type = CX;
7748 p->u.conc.v_type = 1;
7749 DPR_INIT(("Adding CX to config...\n"));
7752 case EPC: /* epc type concentrator */
7753 if (p->type != CNODE) {
7754 dgap_err("cx only valid for concentrators");
7757 p->u.conc.type = EPC;
7758 p->u.conc.v_type = 1;
7759 DPR_INIT(("Adding EPC to config...\n"));
7762 case MOD: /* EBI module */
7763 if (dgap_checknode(p))
7766 dgap_err("must specify board info before EBI modules");
7769 switch (brd->u.board.type) {
7775 dgap_err("must specify concentrator info before EBI module");
7779 if ( (p->next = dgap_newnode(MNODE)) == NULL ) {
7780 dgap_err("out of memory");
7785 brd->u.board.module2++;
7787 brd->u.board.module1++;
7789 DPR_INIT(("Adding MOD to config...\n"));
7792 case PORTS: /* ports type EBI module */
7793 if (p->type != MNODE) {
7794 dgap_err("ports only valid for EBI modules");
7797 p->u.module.type = PORTS;
7798 p->u.module.v_type = 1;
7799 DPR_INIT(("Adding PORTS to config...\n"));
7802 case MODEM: /* ports type EBI module */
7803 if (p->type != MNODE) {
7804 dgap_err("modem only valid for modem modules");
7807 p->u.module.type = MODEM;
7808 p->u.module.v_type = 1;
7809 DPR_INIT(("Adding MODEM to config...\n"));
7813 if (p->type == LNODE) {
7814 if ((s = dgap_getword(in)) == NULL) {
7815 dgap_err("unexpected end of file");
7818 p->u.line.cable = dgap_savestring(s);
7819 p->u.line.v_cable = 1;
7821 DPR_INIT(("Adding CABLE (%s) to config...\n", s));
7824 case SPEED: /* sync line speed indication */
7825 if (p->type == LNODE) {
7826 s = dgap_getword(in);
7828 dgap_err("unexpected end of file");
7831 p->u.line.speed = (char)simple_strtol(s, &s2, 0);
7832 if ((short)strlen(s) > (short)(s2 - s)) {
7833 dgap_err("bad number for line speed");
7836 p->u.line.v_speed = 1;
7837 } else if (p->type == CNODE) {
7838 s = dgap_getword(in);
7840 dgap_err("unexpected end of file");
7843 p->u.conc.speed = (char)simple_strtol(s, &s2, 0);
7844 if ((short)strlen(s) > (short)(s2 - s)) {
7845 dgap_err("bad number for line speed");
7848 p->u.conc.v_speed = 1;
7850 dgap_err("speed valid only for lines or concentrators.");
7853 DPR_INIT(("Adding SPEED (%s) to config...\n", s));
7857 if (p->type == CNODE) {
7858 if ((s = dgap_getword(in)) == NULL) {
7859 dgap_err("unexpected end of file");
7862 p->u.conc.connect = dgap_savestring(s);
7863 p->u.conc.v_connect = 1;
7865 DPR_INIT(("Adding CONNECT (%s) to config...\n", s));
7867 case PRINT: /* transparent print name prefix */
7868 if (dgap_checknode(p))
7870 if ( (p->next = dgap_newnode(PNODE)) == NULL ) {
7871 dgap_err("out of memory");
7875 if ( (s = dgap_getword(in)) == NULL ) {
7876 dgap_err("unexpeced end of file");
7879 if ( (p->u.printname = dgap_savestring(s)) == NULL ) {
7880 dgap_err("out of memory");
7883 DPR_INIT(("Adding PRINT (%s) to config...\n", s));
7886 case CMAJOR: /* major number */
7887 if (dgap_checknode(p))
7889 if ( (p->next = dgap_newnode(JNODE)) == NULL ) {
7890 dgap_err("out of memory");
7894 s = dgap_getword(in);
7896 dgap_err("unexpected end of file");
7899 p->u.majornumber = simple_strtol(s, &s2, 0);
7900 if ((int)strlen(s) > (int)(s2 - s)) {
7901 dgap_err("bad number for major number");
7904 DPR_INIT(("Adding CMAJOR (%s) to config...\n", s));
7907 case ALTPIN: /* altpin setting */
7908 if (dgap_checknode(p))
7910 if ( (p->next = dgap_newnode(ANODE)) == NULL ) {
7911 dgap_err("out of memory");
7915 s = dgap_getword(in);
7917 dgap_err("unexpected end of file");
7920 p->u.altpin = simple_strtol(s, &s2, 0);
7921 if ((int)strlen(s) > (int)(s2 - s)) {
7922 dgap_err("bad number for altpin");
7925 DPR_INIT(("Adding ALTPIN (%s) to config...\n", s));
7928 case USEINTR: /* enable interrupt setting */
7929 if (dgap_checknode(p))
7931 if ( (p->next = dgap_newnode(INTRNODE)) == NULL ) {
7932 dgap_err("out of memory");
7936 s = dgap_getword(in);
7938 dgap_err("unexpected end of file");
7941 p->u.useintr = simple_strtol(s, &s2, 0);
7942 if ((int)strlen(s) > (int)(s2 - s)) {
7943 dgap_err("bad number for useintr");
7946 DPR_INIT(("Adding USEINTR (%s) to config...\n", s));
7949 case TTSIZ: /* size of tty structure */
7950 if (dgap_checknode(p))
7952 if ( (p->next = dgap_newnode(TSNODE)) == NULL ) {
7953 dgap_err("out of memory");
7957 s = dgap_getword(in);
7959 dgap_err("unexpected end of file");
7962 p->u.ttysize = simple_strtol(s, &s2, 0);
7963 if ((int)strlen(s) > (int)(s2 - s)) {
7964 dgap_err("bad number for ttysize");
7967 DPR_INIT(("Adding TTSIZ (%s) to config...\n", s));
7970 case CHSIZ: /* channel structure size */
7971 if (dgap_checknode(p))
7973 if ( (p->next = dgap_newnode(CSNODE)) == NULL ) {
7974 dgap_err("out of memory");
7978 s = dgap_getword(in);
7980 dgap_err("unexpected end of file");
7983 p->u.chsize = simple_strtol(s, &s2, 0);
7984 if ((int)strlen(s) > (int)(s2 - s)) {
7985 dgap_err("bad number for chsize");
7988 DPR_INIT(("Adding CHSIZE (%s) to config...\n", s));
7991 case BSSIZ: /* board structure size */
7992 if (dgap_checknode(p))
7994 if ( (p->next = dgap_newnode(BSNODE)) == NULL ) {
7995 dgap_err("out of memory");
7999 s = dgap_getword(in);
8001 dgap_err("unexpected end of file");
8004 p->u.bssize = simple_strtol(s, &s2, 0);
8005 if ((int)strlen(s) > (int)(s2 - s)) {
8006 dgap_err("bad number for bssize");
8009 DPR_INIT(("Adding BSSIZ (%s) to config...\n", s));
8012 case UNTSIZ: /* sched structure size */
8013 if (dgap_checknode(p))
8015 if ( (p->next = dgap_newnode(USNODE)) == NULL ) {
8016 dgap_err("out of memory");
8020 s = dgap_getword(in);
8022 dgap_err("unexpected end of file");
8025 p->u.unsize = simple_strtol(s, &s2, 0);
8026 if ((int)strlen(s) > (int)(s2 - s)) {
8027 dgap_err("bad number for schedsize");
8030 DPR_INIT(("Adding UNTSIZ (%s) to config...\n", s));
8033 case F2SIZ: /* f2200 structure size */
8034 if (dgap_checknode(p))
8036 if ( (p->next = dgap_newnode(FSNODE)) == NULL ) {
8037 dgap_err("out of memory");
8041 s = dgap_getword(in);
8043 dgap_err("unexpected end of file");
8046 p->u.f2size = simple_strtol(s, &s2, 0);
8047 if ((int)strlen(s) > (int)(s2 - s)) {
8048 dgap_err("bad number for f2200size");
8051 DPR_INIT(("Adding F2SIZ (%s) to config...\n", s));
8054 case VPSIZ: /* vpix structure size */
8055 if (dgap_checknode(p))
8057 if ( (p->next = dgap_newnode(VSNODE)) == NULL ) {
8058 dgap_err("out of memory");
8062 s = dgap_getword(in);
8064 dgap_err("unexpected end of file");
8067 p->u.vpixsize = simple_strtol(s, &s2, 0);
8068 if ((int)strlen(s) > (int)(s2 - s)) {
8069 dgap_err("bad number for vpixsize");
8072 DPR_INIT(("Adding VPSIZ (%s) to config...\n", s));
8080 * dgap_sindex: much like index(), but it looks for a match of any character in
8081 * the group, and returns that position. If the first character is a ^, then
8082 * this will match the first occurrence not in that group.
8084 static char *dgap_sindex (char *string, char *group)
8088 if (!string || !group)
8089 return (char *) NULL;
8091 if (*group == '^') {
8093 for (; *string; string++) {
8094 for (ptr = group; *ptr; ptr++) {
8095 if (*ptr == *string)
8103 for (; *string; string++) {
8104 for (ptr = group; *ptr; ptr++) {
8105 if (*ptr == *string)
8111 return (char *) NULL;
8116 * Get a token from the input file; return 0 if end of file is reached
8118 static int dgap_gettok(char **in, struct cnode *p)
8123 if (strstr(dgap_cword, "boar")) {
8124 w = dgap_getword(in);
8125 snprintf(dgap_cword, MAXCWORD, "%s", w);
8126 for (t = dgap_tlist; t->token != 0; t++) {
8127 if ( !strcmp(w, t->string)) {
8131 dgap_err("board !!type not specified");
8135 while ( (w = dgap_getword(in)) != NULL ) {
8136 snprintf(dgap_cword, MAXCWORD, "%s", w);
8137 for (t = dgap_tlist; t->token != 0; t++) {
8138 if ( !strcmp(w, t->string) )
8148 * get a word from the input stream, also keep track of current line number.
8149 * words are separated by whitespace.
8151 static char *dgap_getword(char **in)
8153 char *ret_ptr = *in;
8155 char *ptr = dgap_sindex(*in, " \t\n");
8157 /* If no word found, return null */
8161 /* Mark new location for our buffer */
8165 /* Eat any extra spaces/tabs/newlines that might be present */
8166 while (*in && **in && ((**in == ' ') || (**in == '\t') || (**in == '\n'))) {
8176 * print an error message, giving the line number in the file where
8177 * the error occurred.
8179 static void dgap_err(char *s)
8181 printk("DGAP: parse: %s\n", s);
8186 * allocate a new configuration node of type t
8188 static struct cnode *dgap_newnode(int t)
8192 n = kmalloc(sizeof(struct cnode), GFP_ATOMIC);
8194 memset((char *)n, 0, sizeof(struct cnode));
8202 * dgap_checknode: see if all the necessary info has been supplied for a node
8203 * before creating the next node.
8205 static int dgap_checknode(struct cnode *p)
8209 if (p->u.board.v_type == 0) {
8210 dgap_err("board type !not specified");
8217 if (p->u.line.v_speed == 0) {
8218 dgap_err("line speed not specified");
8224 if (p->u.conc.v_type == 0) {
8225 dgap_err("concentrator type not specified");
8228 if (p->u.conc.v_speed == 0) {
8229 dgap_err("concentrator line speed not specified");
8232 if (p->u.conc.v_nport == 0) {
8233 dgap_err("number of ports on concentrator not specified");
8236 if (p->u.conc.v_id == 0) {
8237 dgap_err("concentrator id letter not specified");
8243 if (p->u.module.v_type == 0) {
8244 dgap_err("EBI module type not specified");
8247 if (p->u.module.v_nport == 0) {
8248 dgap_err("number of ports on EBI module not specified");
8251 if (p->u.module.v_id == 0) {
8252 dgap_err("EBI module id letter not specified");
8261 * save a string somewhere
8263 static char *dgap_savestring(char *s)
8266 if ( (p = kmalloc(strlen(s) + 1, GFP_ATOMIC) ) != NULL) {
8274 * Given a board pointer, returns whether we should use interrupts or not.
8276 static uint dgap_config_get_useintr(struct board_t *bd)
8278 struct cnode *p = NULL;
8283 for (p = bd->bd_config; p; p = p->next) {
8287 * check for pcxr types.
8289 return p->u.useintr;
8295 /* If not found, then don't turn on interrupts. */
8301 * Given a board pointer, returns whether we turn on altpin or not.
8303 static uint dgap_config_get_altpin(struct board_t *bd)
8305 struct cnode *p = NULL;
8310 for (p = bd->bd_config; p; p = p->next) {
8314 * check for pcxr types.
8322 /* If not found, then don't turn on interrupts. */
8329 * Given a specific type of board, if found, detached link and
8330 * returns the first occurrence in the list.
8332 static struct cnode *dgap_find_config(int type, int bus, int slot)
8334 struct cnode *p, *prev = NULL, *prev2 = NULL, *found = NULL;
8338 while (p->next != NULL) {
8342 if (p->type == BNODE) {
8344 if (p->u.board.type == type) {
8346 if (p->u.board.v_pcibus && p->u.board.pcibus != bus) {
8347 DPR(("Found matching board, but wrong bus position. System says bus %d, we want bus %ld\n",
8348 bus, p->u.board.pcibus));
8351 if (p->u.board.v_pcislot && p->u.board.pcislot != slot) {
8352 DPR_INIT(("Found matching board, but wrong slot position. System says slot %d, we want slot %ld\n",
8353 slot, p->u.board.pcislot));
8357 DPR_INIT(("Matched type in config file\n"));
8361 * Keep walking thru the list till we find the next board.
8363 while (p->next != NULL) {
8366 if (p->type == BNODE) {
8369 * Mark the end of our 1 board chain of configs.
8374 * Link the "next" board to the previous board,
8375 * effectively "unlinking" our board from the main config.
8383 * It must be the last board in the list.
8394 * Given a board pointer, walks the config link, counting up
8395 * all ports user specified should be on the board.
8396 * (This does NOT mean they are all actually present right now tho)
8398 static uint dgap_config_get_number_of_ports(struct board_t *bd)
8401 struct cnode *p = NULL;
8406 for (p = bd->bd_config; p; p = p->next) {
8411 * check for pcxr types.
8413 if (p->u.board.type > EPCFE)
8414 count += p->u.board.nport;
8417 count += p->u.conc.nport;
8420 count += p->u.module.nport;
8427 static char *dgap_create_config_string(struct board_t *bd, char *string)
8430 struct cnode *p = NULL;
8431 struct cnode *q = NULL;
8439 for (p = bd->bd_config; p; p = p->next) {
8445 *ptr = p->u.line.speed;
8450 * Because the EPC/con concentrators can have EM modules
8451 * hanging off of them, we have to walk ahead in the list
8452 * and keep adding the number of ports on each EM to the config.
8455 speed = p->u.conc.speed;
8457 if ((q != NULL) && (q->type == MNODE) ) {
8458 *ptr = (p->u.conc.nport + 0x80);
8461 while ((q->next != NULL) && (q->next->type) == MNODE) {
8462 *ptr = (q->u.module.nport + 0x80);
8467 *ptr = q->u.module.nport;
8470 *ptr = p->u.conc.nport;