2 * Copyright 2003 Digi International (www.digi.com)
3 * Scott H Kilau <Scott_Kilau at digi dot com>
5 * This program is free software; you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published by
7 * the Free Software Foundation; either version 2, or (at your option)
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY, EXPRESS OR IMPLIED; without even the
12 * implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
13 * PURPOSE. See the GNU General Public License for more details.
15 * You should have received a copy of the GNU General Public License
16 * along with this program; if not, write to the Free Software
17 * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
20 * NOTE TO LINUX KERNEL HACKERS: DO NOT REFORMAT THIS CODE!
22 * This is shared code between Digi's CVS archive and the
23 * Linux Kernel sources.
24 * Changing the source just for reformatting needlessly breaks
25 * our CVS diff history.
27 * Send any bug fixes/changes to: Eng.Linux at digi dot com.
33 * In the original out of kernel Digi dgap driver, firmware
34 * loading was done via user land to driver handshaking.
36 * For cards that support a concentrator (port expander),
37 * I believe the concentrator its self told the card which
38 * concentrator is actually attached and then that info
39 * was used to tell user land which concentrator firmware
40 * image was to be downloaded. I think even the BIOS or
41 * FEP images required could change with the connection
42 * of a particular concentrator.
44 * Since I have no access to any of these cards or
45 * concentrators, I cannot put the correct concentrator
46 * firmware file names into the firmware_info structure
47 * as is now done for the BIOS and FEP images.
49 * I think, but am not certain, that the cards supporting
50 * concentrators will function without them. So support
51 * of these cards has been left in this driver.
53 * In order to fully support those cards, they would
54 * either have to be acquired for dissection or maybe
55 * Digi International could provide some assistance.
57 #undef DIGI_CONCENTRATORS_SUPPORTED
59 #include <linux/kernel.h>
60 #include <linux/module.h>
61 #include <linux/pci.h>
62 #include <linux/delay.h> /* For udelay */
63 #include <linux/slab.h>
64 #include <linux/uaccess.h>
65 #include <linux/sched.h>
67 #include <linux/interrupt.h> /* For tasklet and interrupt structs/defines */
68 #include <linux/ctype.h>
69 #include <linux/tty.h>
70 #include <linux/tty_flip.h>
71 #include <linux/serial_reg.h>
72 #include <linux/io.h> /* For read[bwl]/write[bwl] */
74 #include <linux/string.h>
75 #include <linux/device.h>
76 #include <linux/kdev_t.h>
77 #include <linux/firmware.h>
81 #define init_MUTEX(sem) sema_init(sem, 1)
82 #define DECLARE_MUTEX(name) \
83 struct semaphore name = __SEMAPHORE_INITIALIZER(name, 1)
85 MODULE_LICENSE("GPL");
86 MODULE_AUTHOR("Digi International, http://www.digi.com");
87 MODULE_DESCRIPTION("Driver for the Digi International EPCA PCI based product line");
88 MODULE_SUPPORTED_DEVICE("dgap");
90 /**************************************************************************
92 * protos for this file
96 static int dgap_start(void);
97 static void dgap_init_globals(void);
98 static int dgap_found_board(struct pci_dev *pdev, int id);
99 static void dgap_cleanup_board(struct board_t *brd);
100 static void dgap_poll_handler(ulong dummy);
101 static int dgap_init_pci(void);
102 static int dgap_init_one(struct pci_dev *pdev, const struct pci_device_id *ent);
103 static void dgap_remove_one(struct pci_dev *dev);
104 static int dgap_probe1(struct pci_dev *pdev, int card_type);
105 static int dgap_do_remap(struct board_t *brd);
106 static irqreturn_t dgap_intr(int irq, void *voidbrd);
108 /* Our function prototypes */
109 static int dgap_tty_open(struct tty_struct *tty, struct file *file);
110 static void dgap_tty_close(struct tty_struct *tty, struct file *file);
111 static int dgap_block_til_ready(struct tty_struct *tty, struct file *file,
112 struct channel_t *ch);
113 static int dgap_tty_ioctl(struct tty_struct *tty, unsigned int cmd,
115 static int dgap_tty_digigeta(struct tty_struct *tty,
116 struct digi_t __user *retinfo);
117 static int dgap_tty_digiseta(struct tty_struct *tty,
118 struct digi_t __user *new_info);
119 static int dgap_tty_digigetedelay(struct tty_struct *tty, int __user *retinfo);
120 static int dgap_tty_digisetedelay(struct tty_struct *tty, int __user *new_info);
121 static int dgap_tty_write_room(struct tty_struct *tty);
122 static int dgap_tty_chars_in_buffer(struct tty_struct *tty);
123 static void dgap_tty_start(struct tty_struct *tty);
124 static void dgap_tty_stop(struct tty_struct *tty);
125 static void dgap_tty_throttle(struct tty_struct *tty);
126 static void dgap_tty_unthrottle(struct tty_struct *tty);
127 static void dgap_tty_flush_chars(struct tty_struct *tty);
128 static void dgap_tty_flush_buffer(struct tty_struct *tty);
129 static void dgap_tty_hangup(struct tty_struct *tty);
130 static int dgap_wait_for_drain(struct tty_struct *tty);
131 static int dgap_set_modem_info(struct tty_struct *tty, unsigned int command,
132 unsigned int __user *value);
133 static int dgap_get_modem_info(struct channel_t *ch,
134 unsigned int __user *value);
135 static int dgap_tty_digisetcustombaud(struct tty_struct *tty,
136 int __user *new_info);
137 static int dgap_tty_digigetcustombaud(struct tty_struct *tty,
138 int __user *retinfo);
139 static int dgap_tty_tiocmget(struct tty_struct *tty);
140 static int dgap_tty_tiocmset(struct tty_struct *tty, unsigned int set,
142 static int dgap_tty_send_break(struct tty_struct *tty, int msec);
143 static void dgap_tty_wait_until_sent(struct tty_struct *tty, int timeout);
144 static int dgap_tty_write(struct tty_struct *tty, const unsigned char *buf,
146 static void dgap_tty_set_termios(struct tty_struct *tty,
147 struct ktermios *old_termios);
148 static int dgap_tty_put_char(struct tty_struct *tty, unsigned char c);
149 static void dgap_tty_send_xchar(struct tty_struct *tty, char ch);
151 static int dgap_tty_register(struct board_t *brd);
152 static int dgap_tty_init(struct board_t *);
153 static void dgap_tty_uninit(struct board_t *);
154 static void dgap_carrier(struct channel_t *ch);
155 static void dgap_input(struct channel_t *ch);
158 * Our function prototypes from dgap_fep5
160 static void dgap_cmdw_ext(struct channel_t *ch, u16 cmd, u16 word, uint ncmds);
161 static int dgap_event(struct board_t *bd);
163 static void dgap_poll_tasklet(unsigned long data);
164 static void dgap_cmdb(struct channel_t *ch, uchar cmd, uchar byte1,
165 uchar byte2, uint ncmds);
166 static void dgap_cmdw(struct channel_t *ch, uchar cmd, u16 word, uint ncmds);
167 static void dgap_wmove(struct channel_t *ch, char *buf, uint cnt);
168 static int dgap_param(struct tty_struct *tty);
169 static void dgap_parity_scan(struct channel_t *ch, unsigned char *cbuf,
170 unsigned char *fbuf, int *len);
171 static uint dgap_get_custom_baud(struct channel_t *ch);
172 static void dgap_firmware_reset_port(struct channel_t *ch);
175 * Function prototypes from dgap_parse.c.
177 static int dgap_gettok(char **in, struct cnode *p);
178 static char *dgap_getword(char **in);
179 static char *dgap_savestring(char *s);
180 static struct cnode *dgap_newnode(int t);
181 static int dgap_checknode(struct cnode *p);
182 static void dgap_err(char *s);
185 * Function prototypes from dgap_sysfs.h
193 static void dgap_create_ports_sysfiles(struct board_t *bd);
194 static void dgap_remove_ports_sysfiles(struct board_t *bd);
196 static int dgap_create_driver_sysfiles(struct pci_driver *);
197 static void dgap_remove_driver_sysfiles(struct pci_driver *);
199 static void dgap_create_tty_sysfs(struct un_t *un, struct device *c);
200 static void dgap_remove_tty_sysfs(struct device *c);
203 * Function prototypes from dgap_parse.h
205 static int dgap_parsefile(char **in, int Remove);
206 static struct cnode *dgap_find_config(int type, int bus, int slot);
207 static uint dgap_config_get_number_of_ports(struct board_t *bd);
208 static char *dgap_create_config_string(struct board_t *bd, char *string);
209 static uint dgap_config_get_useintr(struct board_t *bd);
210 static uint dgap_config_get_altpin(struct board_t *bd);
212 static int dgap_ms_sleep(ulong ms);
213 static void dgap_do_bios_load(struct board_t *brd, uchar __user *ubios,
215 static void dgap_do_fep_load(struct board_t *brd, uchar __user *ufep, int len);
216 #ifdef DIGI_CONCENTRATORS_SUPPORTED
217 static void dgap_do_conc_load(struct board_t *brd, uchar *uaddr, int len);
219 static int dgap_after_config_loaded(int board);
220 static int dgap_finalize_board_init(struct board_t *brd);
222 static void dgap_get_vpd(struct board_t *brd);
223 static void dgap_do_reset_board(struct board_t *brd);
224 static void dgap_do_wait_for_bios(struct board_t *brd);
225 static void dgap_do_wait_for_fep(struct board_t *brd);
226 static int dgap_tty_register_ports(struct board_t *brd);
227 static int dgap_firmware_load(struct pci_dev *pdev, int card_type);
229 /* Driver unload function */
230 static void dgap_cleanup_module(void);
232 module_exit(dgap_cleanup_module);
235 * File operations permitted on Control/Management major.
237 static const struct file_operations DgapBoardFops = {
238 .owner = THIS_MODULE,
244 static uint dgap_NumBoards;
245 static struct board_t *dgap_Board[MAXBOARDS];
246 static ulong dgap_poll_counter;
247 static char *dgap_config_buf;
248 static int dgap_driver_state = DRIVER_INITIALIZED;
249 DEFINE_SPINLOCK(dgap_dl_lock);
250 static wait_queue_head_t dgap_dl_wait;
251 static int dgap_dl_action;
252 static int dgap_poll_tick = 20; /* Poll interval - 20 ms */
257 static struct class *dgap_class;
259 static struct board_t *dgap_BoardsByMajor[256];
260 static uint dgap_count = 500;
265 DEFINE_SPINLOCK(dgap_poll_lock); /* Poll scheduling lock */
266 static ulong dgap_poll_time; /* Time of next poll */
267 static uint dgap_poll_stop; /* Used to tell poller to stop */
268 static struct timer_list dgap_poll_timer;
273 Card Model Number of Ports Interface
274 ----------------------------------------------------------------
275 Acceleport Xem 4 - 64 (EIA232 & EIA422)
276 Acceleport Xr 4 & 8 (EIA232)
277 Acceleport Xr 920 4 & 8 (EIA232)
278 Acceleport C/X 8 - 128 (EIA232)
279 Acceleport EPC/X 8 - 224 (EIA232)
280 Acceleport Xr/422 4 & 8 (EIA422)
281 Acceleport 2r/920 2 (EIA232)
282 Acceleport 4r/920 4 (EIA232)
283 Acceleport 8r/920 8 (EIA232)
285 IBM 8-Port Asynchronous PCI Adapter (EIA232)
286 IBM 128-Port Asynchronous PCI Adapter (EIA232 & EIA422)
289 static struct pci_device_id dgap_pci_tbl[] = {
290 { DIGI_VID, PCI_DEV_XEM_DID, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0 },
291 { DIGI_VID, PCI_DEV_CX_DID, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 1 },
292 { DIGI_VID, PCI_DEV_CX_IBM_DID, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 2 },
293 { DIGI_VID, PCI_DEV_EPCJ_DID, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 3 },
294 { DIGI_VID, PCI_DEV_920_2_DID, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 4 },
295 { DIGI_VID, PCI_DEV_920_4_DID, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 5 },
296 { DIGI_VID, PCI_DEV_920_8_DID, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 6 },
297 { DIGI_VID, PCI_DEV_XR_DID, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 7 },
298 { DIGI_VID, PCI_DEV_XRJ_DID, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 8 },
299 { DIGI_VID, PCI_DEV_XR_422_DID, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 9 },
300 { DIGI_VID, PCI_DEV_XR_IBM_DID, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 10 },
301 { DIGI_VID, PCI_DEV_XR_SAIP_DID, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 11 },
302 { DIGI_VID, PCI_DEV_XR_BULL_DID, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 12 },
303 { DIGI_VID, PCI_DEV_920_8_HP_DID, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 13 },
304 { DIGI_VID, PCI_DEV_XEM_HP_DID, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 14 },
305 {0,} /* 0 terminated list. */
307 MODULE_DEVICE_TABLE(pci, dgap_pci_tbl);
310 * A generic list of Product names, PCI Vendor ID, and PCI Device ID.
319 static struct board_id dgap_Ids[] = {
320 { PPCM, PCI_DEV_XEM_NAME, 64, (T_PCXM|T_PCLITE|T_PCIBUS) },
321 { PCX, PCI_DEV_CX_NAME, 128, (T_CX|T_PCIBUS) },
322 { PCX, PCI_DEV_CX_IBM_NAME, 128, (T_CX|T_PCIBUS) },
323 { PEPC, PCI_DEV_EPCJ_NAME, 224, (T_EPC|T_PCIBUS) },
324 { APORT2_920P, PCI_DEV_920_2_NAME, 2, (T_PCXR|T_PCLITE|T_PCIBUS) },
325 { APORT4_920P, PCI_DEV_920_4_NAME, 4, (T_PCXR|T_PCLITE|T_PCIBUS) },
326 { APORT8_920P, PCI_DEV_920_8_NAME, 8, (T_PCXR|T_PCLITE|T_PCIBUS) },
327 { PAPORT8, PCI_DEV_XR_NAME, 8, (T_PCXR|T_PCLITE|T_PCIBUS) },
328 { PAPORT8, PCI_DEV_XRJ_NAME, 8, (T_PCXR|T_PCLITE|T_PCIBUS) },
329 { PAPORT8, PCI_DEV_XR_422_NAME, 8, (T_PCXR|T_PCLITE|T_PCIBUS) },
330 { PAPORT8, PCI_DEV_XR_IBM_NAME, 8, (T_PCXR|T_PCLITE|T_PCIBUS) },
331 { PAPORT8, PCI_DEV_XR_SAIP_NAME, 8, (T_PCXR|T_PCLITE|T_PCIBUS) },
332 { PAPORT8, PCI_DEV_XR_BULL_NAME, 8, (T_PCXR|T_PCLITE|T_PCIBUS) },
333 { APORT8_920P, PCI_DEV_920_8_HP_NAME, 8, (T_PCXR|T_PCLITE|T_PCIBUS) },
334 { PPCM, PCI_DEV_XEM_HP_NAME, 64, (T_PCXM|T_PCLITE|T_PCIBUS) },
335 {0,} /* 0 terminated list. */
338 static struct pci_driver dgap_driver = {
340 .probe = dgap_init_one,
341 .id_table = dgap_pci_tbl,
342 .remove = dgap_remove_one,
345 struct firmware_info {
346 uchar *conf_name; /* dgap.conf */
347 uchar *bios_name; /* BIOS filename */
348 uchar *fep_name; /* FEP filename */
349 uchar *con_name; /* Concentrator filename FIXME*/
350 int num; /* sequence number */
354 * Firmware - BIOS, FEP, and CONC filenames
356 static struct firmware_info fw_info[] = {
357 { "dgap/dgap.conf", "dgap/sxbios.bin", "dgap/sxfep.bin", 0, 0 },
358 { "dgap/dgap.conf", "dgap/cxpbios.bin", "dgap/cxpfep.bin", 0, 1 },
359 { "dgap/dgap.conf", "dgap/cxpbios.bin", "dgap/cxpfep.bin", 0, 2 },
360 { "dgap/dgap.conf", "dgap/pcibios.bin", "dgap/pcifep.bin", 0, 3 },
361 { "dgap/dgap.conf", "dgap/xrbios.bin", "dgap/xrfep.bin", 0, 4 },
362 { "dgap/dgap.conf", "dgap/xrbios.bin", "dgap/xrfep.bin", 0, 5 },
363 { "dgap/dgap.conf", "dgap/xrbios.bin", "dgap/xrfep.bin", 0, 6 },
364 { "dgap/dgap.conf", "dgap/xrbios.bin", "dgap/xrfep.bin", 0, 7 },
365 { "dgap/dgap.conf", "dgap/xrbios.bin", "dgap/xrfep.bin", 0, 8 },
366 { "dgap/dgap.conf", "dgap/xrbios.bin", "dgap/xrfep.bin", 0, 9 },
367 { "dgap/dgap.conf", "dgap/xrbios.bin", "dgap/xrfep.bin", 0, 10 },
368 { "dgap/dgap.conf", "dgap/xrbios.bin", "dgap/xrfep.bin", 0, 11 },
369 { "dgap/dgap.conf", "dgap/xrbios.bin", "dgap/xrfep.bin", 0, 12 },
370 { "dgap/dgap.conf", "dgap/xrbios.bin", "dgap/xrfep.bin", 0, 13 },
371 { "dgap/dgap.conf", "dgap/sxbios.bin", "dgap/sxfep.bin", 0, 14 },
375 static char *dgap_driver_state_text[] = {
376 "Driver Initialized",
377 "Driver needs configuration load.",
378 "Driver requested configuration from download daemon.",
383 * Default transparent print information.
385 static struct digi_t dgap_digi_init = {
386 .digi_flags = DIGI_COOK, /* Flags */
387 .digi_maxcps = 100, /* Max CPS */
388 .digi_maxchar = 50, /* Max chars in print queue */
389 .digi_bufsize = 100, /* Printer buffer size */
390 .digi_onlen = 4, /* size of printer on string */
391 .digi_offlen = 4, /* size of printer off string */
392 .digi_onstr = "\033[5i", /* ANSI printer on string ] */
393 .digi_offstr = "\033[4i", /* ANSI printer off string ] */
394 .digi_term = "ansi" /* default terminal type */
398 * Define a local default termios struct. All ports will be created
399 * with this termios initially.
401 * This defines a raw port at 9600 baud, 8 data bits, no parity,
405 static struct ktermios DgapDefaultTermios = {
406 .c_iflag = (DEFAULT_IFLAGS), /* iflags */
407 .c_oflag = (DEFAULT_OFLAGS), /* oflags */
408 .c_cflag = (DEFAULT_CFLAGS), /* cflags */
409 .c_lflag = (DEFAULT_LFLAGS), /* lflags */
414 static const struct tty_operations dgap_tty_ops = {
415 .open = dgap_tty_open,
416 .close = dgap_tty_close,
417 .write = dgap_tty_write,
418 .write_room = dgap_tty_write_room,
419 .flush_buffer = dgap_tty_flush_buffer,
420 .chars_in_buffer = dgap_tty_chars_in_buffer,
421 .flush_chars = dgap_tty_flush_chars,
422 .ioctl = dgap_tty_ioctl,
423 .set_termios = dgap_tty_set_termios,
424 .stop = dgap_tty_stop,
425 .start = dgap_tty_start,
426 .throttle = dgap_tty_throttle,
427 .unthrottle = dgap_tty_unthrottle,
428 .hangup = dgap_tty_hangup,
429 .put_char = dgap_tty_put_char,
430 .tiocmget = dgap_tty_tiocmget,
431 .tiocmset = dgap_tty_tiocmset,
432 .break_ctl = dgap_tty_send_break,
433 .wait_until_sent = dgap_tty_wait_until_sent,
434 .send_xchar = dgap_tty_send_xchar
438 * Our needed internal static variables from dgap_parse.c
440 static struct cnode dgap_head;
442 static char dgap_cword[MAXCWORD];
449 static struct toklist dgap_tlist[] = {
450 { BEGIN, "config_begin" },
451 { END, "config_end" },
453 { PCX, "Digi_AccelePort_C/X_PCI" },
454 { PEPC, "Digi_AccelePort_EPC/X_PCI" },
455 { PPCM, "Digi_AccelePort_Xem_PCI" },
456 { APORT2_920P, "Digi_AccelePort_2r_920_PCI" },
457 { APORT4_920P, "Digi_AccelePort_4r_920_PCI" },
458 { APORT8_920P, "Digi_AccelePort_8r_920_PCI" },
459 { PAPORT4, "Digi_AccelePort_4r_PCI(EIA-232/RS-422)" },
460 { PAPORT8, "Digi_AccelePort_8r_PCI(EIA-232/RS-422)" },
462 { PCIINFO, "pciinfo" },
465 { CONC, "concentrator" },
475 { CONNECT, "connect" },
476 { METHOD, "method" },
477 { STATUS, "status" },
478 { CUSTOM, "Custom" },
484 { NPORTS, "nports" },
489 { ALTPIN, "altpin" },
490 { USEINTR, "useintr" },
491 { TTSIZ, "ttysize" },
493 { BSSIZ, "boardsize" },
494 { UNTSIZ, "schedsize" },
495 { F2SIZ, "f2200size" },
496 { VPSIZ, "vpixsize" },
500 /************************************************************************
502 * Driver load/unload functions
504 ************************************************************************/
509 * Module load. This is where it all starts.
511 static int dgap_init_module(void)
515 pr_info("%s, Digi International Part Number %s\n", DG_NAME, DG_PART);
517 dgap_driver_state = DRIVER_NEED_CONFIG_LOAD;
523 rc = dgap_init_pci();
527 rc = dgap_create_driver_sysfiles(&dgap_driver);
531 dgap_driver_state = DRIVER_READY;
537 dgap_cleanup_module();
541 module_init(dgap_init_module);
546 static int dgap_start(void)
550 struct device *device;
553 * make sure that the globals are
554 * init'd before we do anything else
560 pr_info("For the tools package please visit http://www.digi.com\n");
563 * Register our base character device into the kernel.
567 * Register management/dpa devices
569 rc = register_chrdev(DIGI_DGAP_MAJOR, "dgap", &DgapBoardFops);
573 dgap_class = class_create(THIS_MODULE, "dgap_mgmt");
574 if (IS_ERR(dgap_class)) {
575 rc = PTR_ERR(dgap_class);
579 device = device_create(dgap_class, NULL,
580 MKDEV(DIGI_DGAP_MAJOR, 0),
582 if (IS_ERR(device)) {
583 rc = PTR_ERR(device);
587 /* Start the poller */
588 DGAP_LOCK(dgap_poll_lock, flags);
589 init_timer(&dgap_poll_timer);
590 dgap_poll_timer.function = dgap_poll_handler;
591 dgap_poll_timer.data = 0;
592 dgap_poll_time = jiffies + dgap_jiffies_from_ms(dgap_poll_tick);
593 dgap_poll_timer.expires = dgap_poll_time;
594 DGAP_UNLOCK(dgap_poll_lock, flags);
596 add_timer(&dgap_poll_timer);
598 dgap_driver_state = DRIVER_NEED_CONFIG_LOAD;
603 class_destroy(dgap_class);
605 unregister_chrdev(DIGI_DGAP_MAJOR, "dgap");
610 * Register pci driver, and return how many boards we have.
612 static int dgap_init_pci(void)
614 return pci_register_driver(&dgap_driver);
617 /* returns count (>= 0), or negative on error */
618 static int dgap_init_one(struct pci_dev *pdev, const struct pci_device_id *ent)
622 /* wake up and enable device */
623 rc = pci_enable_device(pdev);
628 rc = dgap_probe1(pdev, ent->driver_data);
631 rc = dgap_firmware_load(pdev, ent->driver_data);
637 static int dgap_probe1(struct pci_dev *pdev, int card_type)
639 return dgap_found_board(pdev, card_type);
642 static void dgap_remove_one(struct pci_dev *dev)
648 * dgap_cleanup_module()
650 * Module unload. This is where it all ends.
652 static void dgap_cleanup_module(void)
657 DGAP_LOCK(dgap_poll_lock, lock_flags);
659 DGAP_UNLOCK(dgap_poll_lock, lock_flags);
661 /* Turn off poller right away. */
662 del_timer_sync(&dgap_poll_timer);
664 dgap_remove_driver_sysfiles(&dgap_driver);
666 device_destroy(dgap_class, MKDEV(DIGI_DGAP_MAJOR, 0));
667 class_destroy(dgap_class);
668 unregister_chrdev(DIGI_DGAP_MAJOR, "dgap");
670 kfree(dgap_config_buf);
672 for (i = 0; i < dgap_NumBoards; ++i) {
673 dgap_remove_ports_sysfiles(dgap_Board[i]);
674 dgap_tty_uninit(dgap_Board[i]);
675 dgap_cleanup_board(dgap_Board[i]);
679 pci_unregister_driver(&dgap_driver);
683 * dgap_cleanup_board()
685 * Free all the memory associated with a board
687 static void dgap_cleanup_board(struct board_t *brd)
691 if (!brd || brd->magic != DGAP_BOARD_MAGIC)
694 if (brd->intr_used && brd->irq)
695 free_irq(brd->irq, brd);
697 tasklet_kill(&brd->helper_tasklet);
699 if (brd->re_map_port) {
700 release_mem_region(brd->membase + 0x200000, 0x200000);
701 iounmap(brd->re_map_port);
702 brd->re_map_port = NULL;
705 if (brd->re_map_membase) {
706 release_mem_region(brd->membase, 0x200000);
707 iounmap(brd->re_map_membase);
708 brd->re_map_membase = NULL;
711 /* Free all allocated channels structs */
712 for (i = 0; i < MAXPORTS ; i++)
713 kfree(brd->channels[i]);
716 kfree(brd->flipflagbuf);
718 dgap_Board[brd->boardnum] = NULL;
726 * A board has been found, init it.
728 static int dgap_found_board(struct pci_dev *pdev, int id)
731 unsigned int pci_irq;
734 /* get the board structure and prep it */
735 brd = kzalloc(sizeof(struct board_t), GFP_KERNEL);
739 dgap_Board[dgap_NumBoards] = brd;
741 /* store the info for the board we've found */
742 brd->magic = DGAP_BOARD_MAGIC;
743 brd->boardnum = dgap_NumBoards;
745 brd->vendor = dgap_pci_tbl[id].vendor;
746 brd->device = dgap_pci_tbl[id].device;
748 brd->pci_bus = pdev->bus->number;
749 brd->pci_slot = PCI_SLOT(pdev->devfn);
750 brd->name = dgap_Ids[id].name;
751 brd->maxports = dgap_Ids[id].maxports;
752 brd->type = dgap_Ids[id].config_type;
753 brd->dpatype = dgap_Ids[id].dpatype;
754 brd->dpastatus = BD_NOFEP;
755 init_waitqueue_head(&brd->state_wait);
757 DGAP_SPINLOCK_INIT(brd->bd_lock);
759 brd->state = BOARD_FOUND;
761 brd->inhibit_poller = FALSE;
762 brd->wait_for_bios = 0;
763 brd->wait_for_fep = 0;
765 for (i = 0; i < MAXPORTS; i++)
766 brd->channels[i] = NULL;
768 /* store which card & revision we have */
769 pci_read_config_word(pdev, PCI_SUBSYSTEM_VENDOR_ID, &brd->subvendor);
770 pci_read_config_word(pdev, PCI_SUBSYSTEM_ID, &brd->subdevice);
771 pci_read_config_byte(pdev, PCI_REVISION_ID, &brd->rev);
776 /* get the PCI Base Address Registers */
778 /* Xr Jupiter and EPC use BAR 2 */
779 if (brd->device == PCI_DEV_XRJ_DID || brd->device == PCI_DEV_EPCJ_DID) {
780 brd->membase = pci_resource_start(pdev, 2);
781 brd->membase_end = pci_resource_end(pdev, 2);
783 /* Everyone else uses BAR 0 */
785 brd->membase = pci_resource_start(pdev, 0);
786 brd->membase_end = pci_resource_end(pdev, 0);
792 if (brd->membase & 1)
798 * On the PCI boards, there is no IO space allocated
799 * The I/O registers will be in the first 3 bytes of the
800 * upper 2MB of the 4MB memory space. The board memory
801 * will be mapped into the low 2MB of the 4MB memory space
803 brd->port = brd->membase + PCI_IO_OFFSET;
804 brd->port_end = brd->port + PCI_IO_SIZE;
807 * Special initialization for non-PLX boards
809 if (brd->device != PCI_DEV_XRJ_DID && brd->device != PCI_DEV_EPCJ_DID) {
812 pci_write_config_byte(pdev, 0x40, 0);
813 pci_write_config_byte(pdev, 0x46, 0);
815 /* Limit burst length to 2 doubleword transactions */
816 pci_write_config_byte(pdev, 0x42, 1);
819 * Enable IO and mem if not already done.
820 * This was needed for support on Itanium.
822 pci_read_config_word(pdev, PCI_COMMAND, &cmd);
823 cmd |= (PCI_COMMAND_IO | PCI_COMMAND_MEMORY);
824 pci_write_config_word(pdev, PCI_COMMAND, cmd);
827 /* init our poll helper tasklet */
828 tasklet_init(&brd->helper_tasklet, dgap_poll_tasklet,
829 (unsigned long) brd);
831 i = dgap_do_remap(brd);
833 brd->state = BOARD_FAILED;
835 brd->state = NEED_RESET;
841 static int dgap_finalize_board_init(struct board_t *brd)
845 if (!brd || brd->magic != DGAP_BOARD_MAGIC)
848 brd->use_interrupts = dgap_config_get_useintr(brd);
851 * Set up our interrupt handler if we are set to do interrupts.
853 if (brd->use_interrupts && brd->irq) {
855 rc = request_irq(brd->irq, dgap_intr, IRQF_SHARED, "DGAP", brd);
868 static int dgap_firmware_load(struct pci_dev *pdev, int card_type)
870 struct board_t *brd = dgap_Board[dgap_NumBoards - 1];
871 const struct firmware *fw;
875 dgap_do_reset_board(brd);
877 if ((fw_info[card_type].conf_name) &&
878 (dgap_driver_state == DRIVER_NEED_CONFIG_LOAD)) {
879 ret = request_firmware(&fw, fw_info[card_type].conf_name,
882 pr_err("dgap: config file %s not found\n",
883 fw_info[card_type].conf_name);
886 if (!dgap_config_buf) {
887 dgap_config_buf = kmalloc(fw->size + 1, GFP_ATOMIC);
888 if (!dgap_config_buf) {
889 release_firmware(fw);
894 memcpy(dgap_config_buf, fw->data, fw->size);
895 release_firmware(fw);
896 dgap_config_buf[fw->size + 1] = '\0';
898 if (dgap_parsefile(&dgap_config_buf, TRUE) != 0)
901 dgap_driver_state = -1;
904 ret = dgap_after_config_loaded(brd->boardnum);
908 * Match this board to a config the user created for us.
911 dgap_find_config(brd->type, brd->pci_bus, brd->pci_slot);
914 * Because the 4 port Xr products share the same PCI ID
915 * as the 8 port Xr products, if we receive a NULL config
916 * back, and this is a PAPORT8 board, retry with a
917 * PAPORT4 attempt as well.
919 if (brd->type == PAPORT8 && !brd->bd_config)
921 dgap_find_config(PAPORT4, brd->pci_bus, brd->pci_slot);
923 if (!brd->bd_config) {
924 pr_err("dgap: No valid configuration found\n");
928 dgap_tty_register(brd);
929 dgap_finalize_board_init(brd);
931 if (fw_info[card_type].bios_name) {
932 ret = request_firmware(&fw, fw_info[card_type].bios_name,
935 pr_err("dgap: bios file %s not found\n",
936 fw_info[card_type].bios_name);
939 dgap_do_bios_load(brd, (char *)fw->data, fw->size);
940 release_firmware(fw);
942 /* Wait for BIOS to test board... */
943 dgap_do_wait_for_bios(brd);
945 if (brd->state != FINISHED_BIOS_LOAD)
949 if (fw_info[card_type].fep_name) {
950 ret = request_firmware(&fw, fw_info[card_type].fep_name,
953 pr_err("dgap: fep file %s not found\n",
954 fw_info[card_type].fep_name);
957 dgap_do_fep_load(brd, (char *)fw->data, fw->size);
958 release_firmware(fw);
960 /* Wait for FEP to load on board... */
961 dgap_do_wait_for_fep(brd);
963 if (brd->state != FINISHED_FEP_LOAD)
967 #ifdef DIGI_CONCENTRATORS_SUPPORTED
969 * If this is a CX or EPCX, we need to see if the firmware
970 * is requesting a concentrator image from us.
972 if ((bd->type == PCX) || (bd->type == PEPC)) {
973 chk_addr = (u16 *) (vaddr + DOWNREQ);
974 /* Nonzero if FEP is requesting concentrator image. */
975 check = readw(chk_addr);
976 vaddr = brd->re_map_membase;
979 if (fw_info[card_type].con_name && check && vaddr) {
980 ret = request_firmware(&fw, fw_info[card_type].con_name,
983 pr_err("dgap: conc file %s not found\n",
984 fw_info[card_type].con_name);
987 /* Put concentrator firmware loading code here */
988 offset = readw((u16 *) (vaddr + DOWNREQ));
989 memcpy_toio(offset, fw->data, fw->size);
991 dgap_do_conc_load(brd, (char *)fw->data, fw->size)
992 release_firmware(fw);
996 * Do tty device initialization.
998 ret = dgap_tty_init(brd);
1000 dgap_tty_uninit(brd);
1004 ret = dgap_tty_register_ports(brd);
1008 brd->state = BOARD_READY;
1009 brd->dpastatus = BD_RUNNING;
1017 static int dgap_do_remap(struct board_t *brd)
1019 if (!brd || brd->magic != DGAP_BOARD_MAGIC)
1022 if (!request_mem_region(brd->membase, 0x200000, "dgap"))
1025 if (!request_mem_region(brd->membase + PCI_IO_OFFSET, 0x200000,
1027 release_mem_region(brd->membase, 0x200000);
1031 brd->re_map_membase = ioremap(brd->membase, 0x200000);
1032 if (!brd->re_map_membase) {
1033 release_mem_region(brd->membase, 0x200000);
1034 release_mem_region(brd->membase + PCI_IO_OFFSET, 0x200000);
1038 brd->re_map_port = ioremap((brd->membase + PCI_IO_OFFSET), 0x200000);
1039 if (!brd->re_map_port) {
1040 release_mem_region(brd->membase, 0x200000);
1041 release_mem_region(brd->membase + PCI_IO_OFFSET, 0x200000);
1042 iounmap(brd->re_map_membase);
1049 /*****************************************************************************
1069 * As each timer expires, it determines (a) whether the "transmit"
1070 * waiter needs to be woken up, and (b) whether the poller needs to
1073 ******************************************************************************/
1075 static void dgap_poll_handler(ulong dummy)
1078 struct board_t *brd;
1079 unsigned long lock_flags;
1082 dgap_poll_counter++;
1085 * Do not start the board state machine until
1086 * driver tells us its up and running, and has
1087 * everything it needs.
1089 if (dgap_driver_state != DRIVER_READY)
1090 goto schedule_poller;
1093 * If we have just 1 board, or the system is not SMP,
1094 * then use the typical old style poller.
1095 * Otherwise, use our new tasklet based poller, which should
1096 * speed things up for multiple boards.
1098 if ((dgap_NumBoards == 1) || (num_online_cpus() <= 1)) {
1099 for (i = 0; i < dgap_NumBoards; i++) {
1101 brd = dgap_Board[i];
1103 if (brd->state == BOARD_FAILED)
1105 if (!brd->intr_running)
1106 /* Call the real board poller directly */
1107 dgap_poll_tasklet((unsigned long) brd);
1111 * Go thru each board, kicking off a
1112 * tasklet for each if needed
1114 for (i = 0; i < dgap_NumBoards; i++) {
1115 brd = dgap_Board[i];
1118 * Attempt to grab the board lock.
1120 * If we can't get it, no big deal, the next poll
1121 * will get it. Basically, I just really don't want
1122 * to spin in here, because I want to kick off my
1123 * tasklets as fast as I can, and then get out the
1126 if (!spin_trylock(&brd->bd_lock))
1130 * If board is in a failed state, don't bother
1131 * scheduling a tasklet
1133 if (brd->state == BOARD_FAILED) {
1134 spin_unlock(&brd->bd_lock);
1138 /* Schedule a poll helper task */
1139 if (!brd->intr_running)
1140 tasklet_schedule(&brd->helper_tasklet);
1143 * Can't do DGAP_UNLOCK here, as we don't have
1144 * lock_flags because we did a trylock above.
1146 spin_unlock(&brd->bd_lock);
1153 * Schedule ourself back at the nominal wakeup interval.
1155 DGAP_LOCK(dgap_poll_lock, lock_flags);
1156 dgap_poll_time += dgap_jiffies_from_ms(dgap_poll_tick);
1158 new_time = dgap_poll_time - jiffies;
1160 if ((ulong) new_time >= 2 * dgap_poll_tick) {
1162 jiffies + dgap_jiffies_from_ms(dgap_poll_tick);
1165 dgap_poll_timer.function = dgap_poll_handler;
1166 dgap_poll_timer.data = 0;
1167 dgap_poll_timer.expires = dgap_poll_time;
1168 DGAP_UNLOCK(dgap_poll_lock, lock_flags);
1170 if (!dgap_poll_stop)
1171 add_timer(&dgap_poll_timer);
1177 * Driver interrupt handler.
1179 static irqreturn_t dgap_intr(int irq, void *voidbrd)
1181 struct board_t *brd = (struct board_t *) voidbrd;
1187 * Check to make sure its for us.
1189 if (brd->magic != DGAP_BOARD_MAGIC)
1195 * Schedule tasklet to run at a better time.
1197 tasklet_schedule(&brd->helper_tasklet);
1202 * dgap_init_globals()
1204 * This is where we initialize the globals from the static insmod
1205 * configuration variables. These are declared near the head of
1208 static void dgap_init_globals(void)
1212 for (i = 0; i < MAXBOARDS; i++)
1213 dgap_Board[i] = NULL;
1215 init_timer(&dgap_poll_timer);
1217 init_waitqueue_head(&dgap_dl_wait);
1221 /************************************************************************
1225 ************************************************************************/
1230 * Put the driver to sleep for x ms's
1232 * Returns 0 if timed out, !0 (showing signal) if interrupted by a signal.
1234 static int dgap_ms_sleep(ulong ms)
1236 current->state = TASK_INTERRUPTIBLE;
1237 schedule_timeout((ms * HZ) / 1000);
1238 return signal_pending(current);
1241 /************************************************************************
1243 * TTY Initialization/Cleanup Functions
1245 ************************************************************************/
1248 * dgap_tty_register()
1250 * Init the tty subsystem for this board.
1252 static int dgap_tty_register(struct board_t *brd)
1256 brd->SerialDriver = alloc_tty_driver(MAXPORTS);
1258 snprintf(brd->SerialName, MAXTTYNAMELEN, "tty_dgap_%d_", brd->boardnum);
1259 brd->SerialDriver->name = brd->SerialName;
1260 brd->SerialDriver->name_base = 0;
1261 brd->SerialDriver->major = 0;
1262 brd->SerialDriver->minor_start = 0;
1263 brd->SerialDriver->type = TTY_DRIVER_TYPE_SERIAL;
1264 brd->SerialDriver->subtype = SERIAL_TYPE_NORMAL;
1265 brd->SerialDriver->init_termios = DgapDefaultTermios;
1266 brd->SerialDriver->driver_name = DRVSTR;
1267 brd->SerialDriver->flags = (TTY_DRIVER_REAL_RAW |
1268 TTY_DRIVER_DYNAMIC_DEV |
1269 TTY_DRIVER_HARDWARE_BREAK);
1271 /* The kernel wants space to store pointers to tty_structs */
1272 brd->SerialDriver->ttys =
1273 kzalloc(MAXPORTS * sizeof(struct tty_struct *), GFP_KERNEL);
1274 if (!brd->SerialDriver->ttys)
1278 * Entry points for driver. Called by the kernel from
1279 * tty_io.c and n_tty.c.
1281 tty_set_operations(brd->SerialDriver, &dgap_tty_ops);
1284 * If we're doing transparent print, we have to do all of the above
1285 * again, separately so we don't get the LD confused about what major
1286 * we are when we get into the dgap_tty_open() routine.
1288 brd->PrintDriver = alloc_tty_driver(MAXPORTS);
1290 snprintf(brd->PrintName, MAXTTYNAMELEN, "pr_dgap_%d_", brd->boardnum);
1291 brd->PrintDriver->name = brd->PrintName;
1292 brd->PrintDriver->name_base = 0;
1293 brd->PrintDriver->major = 0;
1294 brd->PrintDriver->minor_start = 0;
1295 brd->PrintDriver->type = TTY_DRIVER_TYPE_SERIAL;
1296 brd->PrintDriver->subtype = SERIAL_TYPE_NORMAL;
1297 brd->PrintDriver->init_termios = DgapDefaultTermios;
1298 brd->PrintDriver->driver_name = DRVSTR;
1299 brd->PrintDriver->flags = (TTY_DRIVER_REAL_RAW |
1300 TTY_DRIVER_DYNAMIC_DEV |
1301 TTY_DRIVER_HARDWARE_BREAK);
1303 /* The kernel wants space to store pointers to tty_structs */
1304 brd->PrintDriver->ttys =
1305 kzalloc(MAXPORTS * sizeof(struct tty_struct *), GFP_KERNEL);
1306 if (!brd->PrintDriver->ttys)
1310 * Entry points for driver. Called by the kernel from
1311 * tty_io.c and n_tty.c.
1313 tty_set_operations(brd->PrintDriver, &dgap_tty_ops);
1315 if (!brd->dgap_Major_Serial_Registered) {
1316 /* Register tty devices */
1317 rc = tty_register_driver(brd->SerialDriver);
1320 brd->dgap_Major_Serial_Registered = TRUE;
1321 dgap_BoardsByMajor[brd->SerialDriver->major] = brd;
1322 brd->dgap_Serial_Major = brd->SerialDriver->major;
1325 if (!brd->dgap_Major_TransparentPrint_Registered) {
1326 /* Register Transparent Print devices */
1327 rc = tty_register_driver(brd->PrintDriver);
1330 brd->dgap_Major_TransparentPrint_Registered = TRUE;
1331 dgap_BoardsByMajor[brd->PrintDriver->major] = brd;
1332 brd->dgap_TransparentPrint_Major = brd->PrintDriver->major;
1341 * Init the tty subsystem. Called once per board after board has been
1342 * downloaded and init'ed.
1344 static int dgap_tty_init(struct board_t *brd)
1348 uint true_count = 0;
1351 struct channel_t *ch;
1359 * Initialize board structure elements.
1362 vaddr = brd->re_map_membase;
1363 true_count = readw((vaddr + NCHAN));
1365 brd->nasync = dgap_config_get_number_of_ports(brd);
1368 brd->nasync = brd->maxports;
1370 if (brd->nasync > brd->maxports)
1371 brd->nasync = brd->maxports;
1373 if (true_count != brd->nasync) {
1374 if ((brd->type == PPCM) && (true_count == 64)) {
1375 pr_warn("dgap: %s configured for %d ports, has %d ports.\n",
1376 brd->name, brd->nasync, true_count);
1377 pr_warn("dgap: Please make SURE the EBI cable running from the card\n");
1378 pr_warn("dgap: to each EM module is plugged into EBI IN!\n");
1379 } else if ((brd->type == PPCM) && (true_count == 0)) {
1380 pr_warn("dgap: %s configured for %d ports, has %d ports.\n",
1381 brd->name, brd->nasync, true_count);
1382 pr_warn("dgap: Please make SURE the EBI cable running from the card\n");
1383 pr_warn("dgap: to each EM module is plugged into EBI IN!\n");
1385 pr_warn("dgap: %s configured for %d ports, has %d ports.\n",
1386 brd->name, brd->nasync, true_count);
1388 brd->nasync = true_count;
1390 /* If no ports, don't bother going any further */
1392 brd->state = BOARD_FAILED;
1393 brd->dpastatus = BD_NOFEP;
1399 * Allocate channel memory that might not have been allocated
1400 * when the driver was first loaded.
1402 for (i = 0; i < brd->nasync; i++) {
1403 if (!brd->channels[i]) {
1405 kzalloc(sizeof(struct channel_t), GFP_ATOMIC);
1406 if (!brd->channels[i])
1411 ch = brd->channels[0];
1412 vaddr = brd->re_map_membase;
1414 bs = (struct bs_t *) ((ulong) vaddr + CHANBUF);
1415 cm = (struct cm_t *) ((ulong) vaddr + CMDBUF);
1419 /* Set up channel variables */
1420 for (i = 0; i < brd->nasync; i++, ch = brd->channels[i], bs++) {
1422 if (!brd->channels[i])
1425 DGAP_SPINLOCK_INIT(ch->ch_lock);
1427 /* Store all our magic numbers */
1428 ch->magic = DGAP_CHANNEL_MAGIC;
1429 ch->ch_tun.magic = DGAP_UNIT_MAGIC;
1430 ch->ch_tun.un_type = DGAP_SERIAL;
1431 ch->ch_tun.un_ch = ch;
1432 ch->ch_tun.un_dev = i;
1434 ch->ch_pun.magic = DGAP_UNIT_MAGIC;
1435 ch->ch_pun.un_type = DGAP_PRINT;
1436 ch->ch_pun.un_ch = ch;
1437 ch->ch_pun.un_dev = i;
1439 ch->ch_vaddr = vaddr;
1444 ch->ch_digi = dgap_digi_init;
1447 * Set up digi dsr and dcd bits based on altpin flag.
1449 if (dgap_config_get_altpin(brd)) {
1452 ch->ch_digi.digi_flags |= DIGI_ALTPIN;
1455 ch->ch_dsr = DM_DSR;
1458 ch->ch_taddr = vaddr + ((ch->ch_bs->tx_seg) << 4);
1459 ch->ch_raddr = vaddr + ((ch->ch_bs->rx_seg) << 4);
1462 ch->ch_tsize = readw(&(ch->ch_bs->tx_max)) + 1;
1463 ch->ch_rsize = readw(&(ch->ch_bs->rx_max)) + 1;
1467 /* .25 second delay */
1468 ch->ch_close_delay = 250;
1471 * Set queue water marks, interrupt mask,
1472 * and general tty parameters.
1474 tlw = ch->ch_tsize >= 2000 ? ((ch->ch_tsize * 5) / 8) :
1478 dgap_cmdw(ch, STLOW, tlw, 0);
1480 dgap_cmdw(ch, SRLOW, ch->ch_rsize / 2, 0);
1482 dgap_cmdw(ch, SRHIGH, 7 * ch->ch_rsize / 8, 0);
1484 ch->ch_mistat = readb(&(ch->ch_bs->m_stat));
1486 init_waitqueue_head(&ch->ch_flags_wait);
1487 init_waitqueue_head(&ch->ch_tun.un_flags_wait);
1488 init_waitqueue_head(&ch->ch_pun.un_flags_wait);
1489 init_waitqueue_head(&ch->ch_sniff_wait);
1491 /* Turn on all modem interrupts for now */
1492 modem = (DM_CD | DM_DSR | DM_CTS | DM_RI);
1493 writeb(modem, &(ch->ch_bs->m_int));
1496 * Set edelay to 0 if interrupts are turned on,
1497 * otherwise set edelay to the usual 100.
1500 writew(0, &(ch->ch_bs->edelay));
1502 writew(100, &(ch->ch_bs->edelay));
1504 writeb(1, &(ch->ch_bs->idata));
1513 * Uninitialize the TTY portion of this driver. Free all memory and
1516 static void dgap_tty_uninit(struct board_t *brd)
1521 if (brd->dgap_Major_Serial_Registered) {
1522 dgap_BoardsByMajor[brd->SerialDriver->major] = NULL;
1523 brd->dgap_Serial_Major = 0;
1524 for (i = 0; i < brd->nasync; i++) {
1525 tty_port_destroy(&brd->SerialPorts[i]);
1526 dev = brd->channels[i]->ch_tun.un_sysfs;
1527 dgap_remove_tty_sysfs(dev);
1528 tty_unregister_device(brd->SerialDriver, i);
1530 tty_unregister_driver(brd->SerialDriver);
1531 kfree(brd->SerialDriver->ttys);
1532 brd->SerialDriver->ttys = NULL;
1533 put_tty_driver(brd->SerialDriver);
1534 kfree(brd->SerialPorts);
1535 brd->dgap_Major_Serial_Registered = FALSE;
1538 if (brd->dgap_Major_TransparentPrint_Registered) {
1539 dgap_BoardsByMajor[brd->PrintDriver->major] = NULL;
1540 brd->dgap_TransparentPrint_Major = 0;
1541 for (i = 0; i < brd->nasync; i++) {
1542 tty_port_destroy(&brd->PrinterPorts[i]);
1543 dev = brd->channels[i]->ch_pun.un_sysfs;
1544 dgap_remove_tty_sysfs(dev);
1545 tty_unregister_device(brd->PrintDriver, i);
1547 tty_unregister_driver(brd->PrintDriver);
1548 kfree(brd->PrintDriver->ttys);
1549 brd->PrintDriver->ttys = NULL;
1550 put_tty_driver(brd->PrintDriver);
1551 kfree(brd->PrinterPorts);
1552 brd->dgap_Major_TransparentPrint_Registered = FALSE;
1556 #define TMPBUFLEN (1024)
1558 * dgap_sniff - Dump data out to the "sniff" buffer if the
1559 * proc sniff file is opened...
1561 static void dgap_sniff_nowait_nolock(struct channel_t *ch, uchar *text,
1562 uchar *buf, int len)
1570 char tmpbuf[TMPBUFLEN];
1574 /* Leave if sniff not open */
1575 if (!(ch->ch_sniff_flags & SNIFF_OPEN))
1578 do_gettimeofday(&tv);
1580 /* Create our header for data dump */
1581 p += sprintf(p, "<%ld %ld><%s><", tv.tv_sec, tv.tv_usec, text);
1582 tmpbuflen = p - tmpbuf;
1587 for (i = 0; i < len && tmpbuflen < (TMPBUFLEN - 4); i++) {
1588 p += sprintf(p, "%02x ", *buf);
1590 tmpbuflen = p - tmpbuf;
1593 if (tmpbuflen < (TMPBUFLEN - 4)) {
1595 p += sprintf(p - 1, "%s\n", ">");
1597 p += sprintf(p, "%s\n", ">");
1603 nbuf = strlen(tmpbuf);
1607 * Loop while data remains.
1609 while (nbuf > 0 && ch->ch_sniff_buf) {
1611 * Determine the amount of available space left in the
1612 * buffer. If there's none, wait until some appears.
1614 n = (ch->ch_sniff_out - ch->ch_sniff_in - 1) &
1618 * If there is no space left to write to in our sniff
1619 * buffer, we have no choice but to drop the data.
1620 * We *cannot* sleep here waiting for space, because
1621 * this function was probably called by the
1622 * interrupt/timer routines!
1628 * Copy as much data as will fit.
1634 r = SNIFF_MAX - ch->ch_sniff_in;
1637 memcpy(ch->ch_sniff_buf + ch->ch_sniff_in, p, r);
1640 ch->ch_sniff_in = 0;
1645 memcpy(ch->ch_sniff_buf + ch->ch_sniff_in, p, n);
1647 ch->ch_sniff_in += n;
1652 * Wakeup any thread waiting for data
1654 if (ch->ch_sniff_flags & SNIFF_WAIT_DATA) {
1655 ch->ch_sniff_flags &= ~SNIFF_WAIT_DATA;
1656 wake_up_interruptible(&ch->ch_sniff_wait);
1661 * If the user sent us too much data to push into our tmpbuf,
1662 * we need to keep looping around on all the data.
1664 if (too_much_data) {
1669 } while (too_much_data);
1672 /*=======================================================================
1674 * dgap_input - Process received data.
1676 * ch - Pointer to channel structure.
1678 *=======================================================================*/
1680 static void dgap_input(struct channel_t *ch)
1684 struct tty_struct *tp;
1685 struct tty_ldisc *ld;
1699 if (!ch || ch->magic != DGAP_CHANNEL_MAGIC)
1702 tp = ch->ch_tun.un_tty;
1709 if (!bd || bd->magic != DGAP_BOARD_MAGIC)
1712 DGAP_LOCK(bd->bd_lock, lock_flags);
1713 DGAP_LOCK(ch->ch_lock, lock_flags2);
1716 * Figure the number of characters in the buffer.
1717 * Exit immediately if none.
1720 rmask = ch->ch_rsize - 1;
1722 head = readw(&(bs->rx_head));
1724 tail = readw(&(bs->rx_tail));
1727 data_len = (head - tail) & rmask;
1729 if (data_len == 0) {
1730 writeb(1, &(bs->idata));
1731 DGAP_UNLOCK(ch->ch_lock, lock_flags2);
1732 DGAP_UNLOCK(bd->bd_lock, lock_flags);
1737 * If the device is not open, or CREAD is off, flush
1738 * input data and return immediately.
1740 if ((bd->state != BOARD_READY) || !tp ||
1741 (tp->magic != TTY_MAGIC) ||
1742 !(ch->ch_tun.un_flags & UN_ISOPEN) ||
1743 !(tp->termios.c_cflag & CREAD) ||
1744 (ch->ch_tun.un_flags & UN_CLOSING)) {
1746 writew(head, &(bs->rx_tail));
1747 writeb(1, &(bs->idata));
1748 DGAP_UNLOCK(ch->ch_lock, lock_flags2);
1749 DGAP_UNLOCK(bd->bd_lock, lock_flags);
1754 * If we are throttled, simply don't read any data.
1756 if (ch->ch_flags & CH_RXBLOCK) {
1757 writeb(1, &(bs->idata));
1758 DGAP_UNLOCK(ch->ch_lock, lock_flags2);
1759 DGAP_UNLOCK(bd->bd_lock, lock_flags);
1766 tmpchar = readb(&(bs->orun));
1768 ch->ch_err_overrun++;
1769 writeb(0, &(bs->orun));
1772 /* Decide how much data we can send into the tty layer */
1773 flip_len = TTY_FLIPBUF_SIZE;
1775 /* Chop down the length, if needed */
1776 len = min(data_len, flip_len);
1777 len = min(len, (N_TTY_BUF_SIZE - 1));
1779 ld = tty_ldisc_ref(tp);
1781 #ifdef TTY_DONT_FLIP
1783 * If the DONT_FLIP flag is on, don't flush our buffer, and act
1784 * like the ld doesn't have any space to put the data right now.
1786 if (test_bit(TTY_DONT_FLIP, &tp->flags))
1791 * If we were unable to get a reference to the ld,
1792 * don't flush our buffer, and act like the ld doesn't
1793 * have any space to put the data right now.
1799 * If ld doesn't have a pointer to a receive_buf function,
1800 * flush the data, then act like the ld doesn't have any
1801 * space to put the data right now.
1803 if (!ld->ops->receive_buf) {
1804 writew(head, &(bs->rx_tail));
1810 writeb(1, &(bs->idata));
1811 DGAP_UNLOCK(ch->ch_lock, lock_flags2);
1812 DGAP_UNLOCK(bd->bd_lock, lock_flags);
1814 tty_ldisc_deref(ld);
1818 buf = ch->ch_bd->flipbuf;
1822 * n now contains the most amount of data we can copy,
1823 * bounded either by our buffer size or the amount
1824 * of data the card actually has pending...
1828 s = ((head >= tail) ? head : ch->ch_rsize) - tail;
1834 memcpy_fromio(buf, (char *) ch->ch_raddr + tail, s);
1835 dgap_sniff_nowait_nolock(ch, "USER READ", buf, s);
1841 /* Flip queue if needed */
1845 writew(tail, &(bs->rx_tail));
1846 writeb(1, &(bs->idata));
1847 ch->ch_rxcount += len;
1850 * If we are completely raw, we don't need to go through a lot
1851 * of the tty layers that exist.
1852 * In this case, we take the shortest and fastest route we
1853 * can to relay the data to the user.
1855 * On the other hand, if we are not raw, we need to go through
1856 * the tty layer, which has its API more well defined.
1858 if (I_PARMRK(tp) || I_BRKINT(tp) || I_INPCK(tp)) {
1859 dgap_parity_scan(ch, ch->ch_bd->flipbuf,
1860 ch->ch_bd->flipflagbuf, &len);
1862 len = tty_buffer_request_room(tp->port, len);
1863 tty_insert_flip_string_flags(tp->port, ch->ch_bd->flipbuf,
1864 ch->ch_bd->flipflagbuf, len);
1866 len = tty_buffer_request_room(tp->port, len);
1867 tty_insert_flip_string(tp->port, ch->ch_bd->flipbuf, len);
1870 DGAP_UNLOCK(ch->ch_lock, lock_flags2);
1871 DGAP_UNLOCK(bd->bd_lock, lock_flags);
1873 /* Tell the tty layer its okay to "eat" the data now */
1874 tty_flip_buffer_push(tp->port);
1877 tty_ldisc_deref(ld);
1881 /************************************************************************
1882 * Determines when CARRIER changes state and takes appropriate
1884 ************************************************************************/
1885 static void dgap_carrier(struct channel_t *ch)
1889 int virt_carrier = 0;
1890 int phys_carrier = 0;
1892 if (!ch || ch->magic != DGAP_CHANNEL_MAGIC)
1897 if (!bd || bd->magic != DGAP_BOARD_MAGIC)
1900 /* Make sure altpin is always set correctly */
1901 if (ch->ch_digi.digi_flags & DIGI_ALTPIN) {
1905 ch->ch_dsr = DM_DSR;
1909 if (ch->ch_mistat & D_CD(ch))
1912 if (ch->ch_digi.digi_flags & DIGI_FORCEDCD)
1915 if (ch->ch_c_cflag & CLOCAL)
1919 * Test for a VIRTUAL carrier transition to HIGH.
1921 if (((ch->ch_flags & CH_FCAR) == 0) && (virt_carrier == 1)) {
1924 * When carrier rises, wake any threads waiting
1925 * for carrier in the open routine.
1928 if (waitqueue_active(&(ch->ch_flags_wait)))
1929 wake_up_interruptible(&ch->ch_flags_wait);
1933 * Test for a PHYSICAL carrier transition to HIGH.
1935 if (((ch->ch_flags & CH_CD) == 0) && (phys_carrier == 1)) {
1938 * When carrier rises, wake any threads waiting
1939 * for carrier in the open routine.
1942 if (waitqueue_active(&(ch->ch_flags_wait)))
1943 wake_up_interruptible(&ch->ch_flags_wait);
1947 * Test for a PHYSICAL transition to low, so long as we aren't
1948 * currently ignoring physical transitions (which is what "virtual
1949 * carrier" indicates).
1951 * The transition of the virtual carrier to low really doesn't
1952 * matter... it really only means "ignore carrier state", not
1953 * "make pretend that carrier is there".
1955 if ((virt_carrier == 0) &&
1956 ((ch->ch_flags & CH_CD) != 0) &&
1957 (phys_carrier == 0)) {
1960 * When carrier drops:
1962 * Drop carrier on all open units.
1964 * Flush queues, waking up any task waiting in the
1967 * Send a hangup to the control terminal.
1969 * Enable all select calls.
1971 if (waitqueue_active(&(ch->ch_flags_wait)))
1972 wake_up_interruptible(&ch->ch_flags_wait);
1974 if (ch->ch_tun.un_open_count > 0)
1975 tty_hangup(ch->ch_tun.un_tty);
1977 if (ch->ch_pun.un_open_count > 0)
1978 tty_hangup(ch->ch_pun.un_tty);
1982 * Make sure that our cached values reflect the current reality.
1984 if (virt_carrier == 1)
1985 ch->ch_flags |= CH_FCAR;
1987 ch->ch_flags &= ~CH_FCAR;
1989 if (phys_carrier == 1)
1990 ch->ch_flags |= CH_CD;
1992 ch->ch_flags &= ~CH_CD;
1995 /************************************************************************
1997 * TTY Entry points and helper functions
1999 ************************************************************************/
2005 static int dgap_tty_open(struct tty_struct *tty, struct file *file)
2007 struct board_t *brd;
2008 struct channel_t *ch;
2020 major = MAJOR(tty_devnum(tty));
2021 minor = MINOR(tty_devnum(tty));
2026 /* Get board pointer from our array of majors we have allocated */
2027 brd = dgap_BoardsByMajor[major];
2032 * If board is not yet up to a state of READY, go to
2033 * sleep waiting for it to happen or they cancel the open.
2035 rc = wait_event_interruptible(brd->state_wait,
2036 (brd->state & BOARD_READY));
2041 DGAP_LOCK(brd->bd_lock, lock_flags);
2043 /* The wait above should guarantee this cannot happen */
2044 if (brd->state != BOARD_READY) {
2045 DGAP_UNLOCK(brd->bd_lock, lock_flags);
2049 /* If opened device is greater than our number of ports, bail. */
2050 if (MINOR(tty_devnum(tty)) > brd->nasync) {
2051 DGAP_UNLOCK(brd->bd_lock, lock_flags);
2055 ch = brd->channels[minor];
2057 DGAP_UNLOCK(brd->bd_lock, lock_flags);
2061 /* Grab channel lock */
2062 DGAP_LOCK(ch->ch_lock, lock_flags2);
2064 /* Figure out our type */
2065 if (major == brd->dgap_Serial_Major) {
2066 un = &brd->channels[minor]->ch_tun;
2067 un->un_type = DGAP_SERIAL;
2068 } else if (major == brd->dgap_TransparentPrint_Major) {
2069 un = &brd->channels[minor]->ch_pun;
2070 un->un_type = DGAP_PRINT;
2072 DGAP_UNLOCK(ch->ch_lock, lock_flags2);
2073 DGAP_UNLOCK(brd->bd_lock, lock_flags);
2077 /* Store our unit into driver_data, so we always have it available. */
2078 tty->driver_data = un;
2081 * Error if channel info pointer is NULL.
2085 DGAP_UNLOCK(ch->ch_lock, lock_flags2);
2086 DGAP_UNLOCK(brd->bd_lock, lock_flags);
2093 if (!(un->un_flags & UN_ISOPEN)) {
2094 /* Store important variables. */
2097 /* Maybe do something here to the TTY struct as well? */
2101 * Initialize if neither terminal or printer is open.
2103 if (!((ch->ch_tun.un_flags | ch->ch_pun.un_flags) & UN_ISOPEN)) {
2109 * Flush input queue.
2111 head = readw(&(bs->rx_head));
2112 writew(head, &(bs->rx_tail));
2115 ch->pscan_state = 0;
2116 ch->pscan_savechar = 0;
2118 ch->ch_c_cflag = tty->termios.c_cflag;
2119 ch->ch_c_iflag = tty->termios.c_iflag;
2120 ch->ch_c_oflag = tty->termios.c_oflag;
2121 ch->ch_c_lflag = tty->termios.c_lflag;
2122 ch->ch_startc = tty->termios.c_cc[VSTART];
2123 ch->ch_stopc = tty->termios.c_cc[VSTOP];
2125 /* TODO: flush our TTY struct here? */
2130 * Run param in case we changed anything
2135 * follow protocol for opening port
2138 DGAP_UNLOCK(ch->ch_lock, lock_flags2);
2139 DGAP_UNLOCK(brd->bd_lock, lock_flags);
2141 rc = dgap_block_til_ready(tty, file, ch);
2146 /* No going back now, increment our unit and channel counters */
2147 DGAP_LOCK(ch->ch_lock, lock_flags);
2148 ch->ch_open_count++;
2149 un->un_open_count++;
2150 un->un_flags |= (UN_ISOPEN);
2151 DGAP_UNLOCK(ch->ch_lock, lock_flags);
2157 * dgap_block_til_ready()
2159 * Wait for DCD, if needed.
2161 static int dgap_block_til_ready(struct tty_struct *tty, struct file *file,
2162 struct channel_t *ch)
2165 struct un_t *un = NULL;
2168 int sleep_on_un_flags = 0;
2170 if (!tty || tty->magic != TTY_MAGIC || !file || !ch ||
2171 ch->magic != DGAP_CHANNEL_MAGIC)
2174 un = tty->driver_data;
2175 if (!un || un->magic != DGAP_UNIT_MAGIC)
2178 DGAP_LOCK(ch->ch_lock, lock_flags);
2185 sleep_on_un_flags = 0;
2188 * If board has failed somehow during our sleep,
2191 if (ch->ch_bd->state == BOARD_FAILED) {
2196 /* If tty was hung up, break out of loop and set error. */
2197 if (tty_hung_up_p(file)) {
2203 * If either unit is in the middle of the fragile part of close,
2204 * we just cannot touch the channel safely.
2205 * Go back to sleep, knowing that when the channel can be
2206 * touched safely, the close routine will signal the
2207 * ch_wait_flags to wake us back up.
2209 if (!((ch->ch_tun.un_flags | ch->ch_pun.un_flags) &
2213 * Our conditions to leave cleanly and happily:
2214 * 1) NONBLOCKING on the tty is set.
2216 * 3) DCD (fake or real) is active.
2219 if (file->f_flags & O_NONBLOCK)
2222 if (tty->flags & (1 << TTY_IO_ERROR))
2225 if (ch->ch_flags & CH_CD)
2228 if (ch->ch_flags & CH_FCAR)
2231 sleep_on_un_flags = 1;
2235 * If there is a signal pending, the user probably
2236 * interrupted (ctrl-c) us.
2237 * Leave loop with error set.
2239 if (signal_pending(current)) {
2240 retval = -ERESTARTSYS;
2245 * Store the flags before we let go of channel lock
2247 if (sleep_on_un_flags)
2248 old_flags = ch->ch_tun.un_flags | ch->ch_pun.un_flags;
2250 old_flags = ch->ch_flags;
2253 * Let go of channel lock before calling schedule.
2254 * Our poller will get any FEP events and wake us up when DCD
2255 * eventually goes active.
2258 DGAP_UNLOCK(ch->ch_lock, lock_flags);
2261 * Wait for something in the flags to change
2262 * from the current value.
2264 if (sleep_on_un_flags) {
2265 retval = wait_event_interruptible(un->un_flags_wait,
2266 (old_flags != (ch->ch_tun.un_flags |
2267 ch->ch_pun.un_flags)));
2269 retval = wait_event_interruptible(ch->ch_flags_wait,
2270 (old_flags != ch->ch_flags));
2274 * We got woken up for some reason.
2275 * Before looping around, grab our channel lock.
2277 DGAP_LOCK(ch->ch_lock, lock_flags);
2282 DGAP_UNLOCK(ch->ch_lock, lock_flags);
2293 * Hangup the port. Like a close, but don't wait for output to drain.
2295 static void dgap_tty_hangup(struct tty_struct *tty)
2298 struct channel_t *ch;
2301 if (!tty || tty->magic != TTY_MAGIC)
2304 un = tty->driver_data;
2305 if (!un || un->magic != DGAP_UNIT_MAGIC)
2309 if (!ch || ch->magic != DGAP_CHANNEL_MAGIC)
2313 if (!bd || bd->magic != DGAP_BOARD_MAGIC)
2316 /* flush the transmit queues */
2317 dgap_tty_flush_buffer(tty);
2325 static void dgap_tty_close(struct tty_struct *tty, struct file *file)
2327 struct ktermios *ts;
2329 struct channel_t *ch;
2334 if (!tty || tty->magic != TTY_MAGIC)
2337 un = tty->driver_data;
2338 if (!un || un->magic != DGAP_UNIT_MAGIC)
2342 if (!ch || ch->magic != DGAP_CHANNEL_MAGIC)
2346 if (!bd || bd->magic != DGAP_BOARD_MAGIC)
2351 DGAP_LOCK(ch->ch_lock, lock_flags);
2354 * Determine if this is the last close or not - and if we agree about
2355 * which type of close it is with the Line Discipline
2357 if ((tty->count == 1) && (un->un_open_count != 1)) {
2359 * Uh, oh. tty->count is 1, which means that the tty
2360 * structure will be freed. un_open_count should always
2361 * be one in these conditions. If it's greater than
2362 * one, we've got real problems, since it means the
2363 * serial port won't be shutdown.
2365 un->un_open_count = 1;
2368 if (--un->un_open_count < 0)
2369 un->un_open_count = 0;
2371 ch->ch_open_count--;
2373 if (ch->ch_open_count && un->un_open_count) {
2374 DGAP_UNLOCK(ch->ch_lock, lock_flags);
2378 /* OK, its the last close on the unit */
2380 un->un_flags |= UN_CLOSING;
2385 * Only officially close channel if count is 0 and
2386 * DIGI_PRINTER bit is not set.
2388 if ((ch->ch_open_count == 0) &&
2389 !(ch->ch_digi.digi_flags & DIGI_PRINTER)) {
2391 ch->ch_flags &= ~(CH_RXBLOCK);
2393 DGAP_UNLOCK(ch->ch_lock, lock_flags);
2395 /* wait for output to drain */
2396 /* This will also return if we take an interrupt */
2398 rc = dgap_wait_for_drain(tty);
2400 dgap_tty_flush_buffer(tty);
2401 tty_ldisc_flush(tty);
2403 DGAP_LOCK(ch->ch_lock, lock_flags);
2408 * If we have HUPCL set, lower DTR and RTS
2410 if (ch->ch_c_cflag & HUPCL) {
2411 ch->ch_mostat &= ~(D_RTS(ch)|D_DTR(ch));
2412 dgap_cmdb(ch, SMODEM, 0, D_DTR(ch)|D_RTS(ch), 0);
2415 * Go to sleep to ensure RTS/DTR
2416 * have been dropped for modems to see it.
2418 if (ch->ch_close_delay) {
2419 DGAP_UNLOCK(ch->ch_lock, lock_flags);
2420 dgap_ms_sleep(ch->ch_close_delay);
2421 DGAP_LOCK(ch->ch_lock, lock_flags);
2425 ch->pscan_state = 0;
2426 ch->pscan_savechar = 0;
2427 ch->ch_baud_info = 0;
2432 * turn off print device when closing print device.
2434 if ((un->un_type == DGAP_PRINT) && (ch->ch_flags & CH_PRON)) {
2435 dgap_wmove(ch, ch->ch_digi.digi_offstr,
2436 (int) ch->ch_digi.digi_offlen);
2437 ch->ch_flags &= ~CH_PRON;
2441 un->un_flags &= ~(UN_ISOPEN | UN_CLOSING);
2442 tty->driver_data = NULL;
2444 wake_up_interruptible(&ch->ch_flags_wait);
2445 wake_up_interruptible(&un->un_flags_wait);
2447 DGAP_UNLOCK(ch->ch_lock, lock_flags);
2451 * dgap_tty_chars_in_buffer()
2453 * Return number of characters that have not been transmitted yet.
2455 * This routine is used by the line discipline to determine if there
2456 * is data waiting to be transmitted/drained/flushed or not.
2458 static int dgap_tty_chars_in_buffer(struct tty_struct *tty)
2460 struct board_t *bd = NULL;
2461 struct channel_t *ch = NULL;
2462 struct un_t *un = NULL;
2463 struct bs_t *bs = NULL;
2466 u16 thead, ttail, tmask, chead, ctail;
2467 ulong lock_flags = 0;
2468 ulong lock_flags2 = 0;
2473 un = tty->driver_data;
2474 if (!un || un->magic != DGAP_UNIT_MAGIC)
2478 if (!ch || ch->magic != DGAP_CHANNEL_MAGIC)
2482 if (!bd || bd->magic != DGAP_BOARD_MAGIC)
2489 DGAP_LOCK(bd->bd_lock, lock_flags);
2490 DGAP_LOCK(ch->ch_lock, lock_flags2);
2492 tmask = (ch->ch_tsize - 1);
2494 /* Get Transmit queue pointers */
2495 thead = readw(&(bs->tx_head)) & tmask;
2496 ttail = readw(&(bs->tx_tail)) & tmask;
2498 /* Get tbusy flag */
2499 tbusy = readb(&(bs->tbusy));
2501 /* Get Command queue pointers */
2502 chead = readw(&(ch->ch_cm->cm_head));
2503 ctail = readw(&(ch->ch_cm->cm_tail));
2505 DGAP_UNLOCK(ch->ch_lock, lock_flags2);
2506 DGAP_UNLOCK(bd->bd_lock, lock_flags);
2509 * The only way we know for sure if there is no pending
2510 * data left to be transferred, is if:
2511 * 1) Transmit head and tail are equal (empty).
2512 * 2) Command queue head and tail are equal (empty).
2513 * 3) The "TBUSY" flag is 0. (Transmitter not busy).
2516 if ((ttail == thead) && (tbusy == 0) && (chead == ctail)) {
2520 chars = thead - ttail;
2522 chars = thead - ttail + ch->ch_tsize;
2524 * Fudge factor here.
2525 * If chars is zero, we know that the command queue had
2526 * something in it or tbusy was set. Because we cannot
2527 * be sure if there is still some data to be transmitted,
2528 * lets lie, and tell ld we have 1 byte left.
2532 * If TBUSY is still set, and our tx buffers are empty,
2533 * force the firmware to send me another wakeup after
2534 * TBUSY has been cleared.
2537 DGAP_LOCK(ch->ch_lock, lock_flags);
2538 un->un_flags |= UN_EMPTY;
2539 writeb(1, &(bs->iempty));
2540 DGAP_UNLOCK(ch->ch_lock, lock_flags);
2549 static int dgap_wait_for_drain(struct tty_struct *tty)
2551 struct channel_t *ch;
2556 ulong lock_flags = 0;
2558 if (!tty || tty->magic != TTY_MAGIC)
2561 un = tty->driver_data;
2562 if (!un || un->magic != DGAP_UNIT_MAGIC)
2566 if (!ch || ch->magic != DGAP_CHANNEL_MAGIC)
2575 /* Loop until data is drained */
2576 while (count != 0) {
2578 count = dgap_tty_chars_in_buffer(tty);
2583 /* Set flag waiting for drain */
2584 DGAP_LOCK(ch->ch_lock, lock_flags);
2585 un->un_flags |= UN_EMPTY;
2586 writeb(1, &(bs->iempty));
2587 DGAP_UNLOCK(ch->ch_lock, lock_flags);
2589 /* Go to sleep till we get woken up */
2590 ret = wait_event_interruptible(un->un_flags_wait,
2591 ((un->un_flags & UN_EMPTY) == 0));
2592 /* If ret is non-zero, user ctrl-c'ed us */
2597 DGAP_LOCK(ch->ch_lock, lock_flags);
2598 un->un_flags &= ~(UN_EMPTY);
2599 DGAP_UNLOCK(ch->ch_lock, lock_flags);
2607 * Reduces bytes_available to the max number of characters
2608 * that can be sent currently given the maxcps value, and
2609 * returns the new bytes_available. This only affects printer
2612 static int dgap_maxcps_room(struct tty_struct *tty, int bytes_available)
2614 struct channel_t *ch = NULL;
2615 struct un_t *un = NULL;
2618 return bytes_available;
2620 un = tty->driver_data;
2621 if (!un || un->magic != DGAP_UNIT_MAGIC)
2622 return bytes_available;
2625 if (!ch || ch->magic != DGAP_CHANNEL_MAGIC)
2626 return bytes_available;
2629 * If its not the Transparent print device, return
2630 * the full data amount.
2632 if (un->un_type != DGAP_PRINT)
2633 return bytes_available;
2635 if (ch->ch_digi.digi_maxcps > 0 && ch->ch_digi.digi_bufsize > 0) {
2637 unsigned long current_time = jiffies;
2638 unsigned long buffer_time = current_time +
2639 (HZ * ch->ch_digi.digi_bufsize) /
2640 ch->ch_digi.digi_maxcps;
2642 if (ch->ch_cpstime < current_time) {
2643 /* buffer is empty */
2644 ch->ch_cpstime = current_time; /* reset ch_cpstime */
2645 cps_limit = ch->ch_digi.digi_bufsize;
2646 } else if (ch->ch_cpstime < buffer_time) {
2647 /* still room in the buffer */
2648 cps_limit = ((buffer_time - ch->ch_cpstime) *
2649 ch->ch_digi.digi_maxcps) / HZ;
2651 /* no room in the buffer */
2655 bytes_available = min(cps_limit, bytes_available);
2658 return bytes_available;
2661 static inline void dgap_set_firmware_event(struct un_t *un, unsigned int event)
2663 struct channel_t *ch = NULL;
2664 struct bs_t *bs = NULL;
2666 if (!un || un->magic != DGAP_UNIT_MAGIC)
2669 if (!ch || ch->magic != DGAP_CHANNEL_MAGIC)
2675 if ((event & UN_LOW) != 0) {
2676 if ((un->un_flags & UN_LOW) == 0) {
2677 un->un_flags |= UN_LOW;
2678 writeb(1, &(bs->ilow));
2681 if ((event & UN_LOW) != 0) {
2682 if ((un->un_flags & UN_EMPTY) == 0) {
2683 un->un_flags |= UN_EMPTY;
2684 writeb(1, &(bs->iempty));
2690 * dgap_tty_write_room()
2692 * Return space available in Tx buffer
2694 static int dgap_tty_write_room(struct tty_struct *tty)
2696 struct channel_t *ch = NULL;
2697 struct un_t *un = NULL;
2698 struct bs_t *bs = NULL;
2699 u16 head, tail, tmask;
2701 ulong lock_flags = 0;
2706 un = tty->driver_data;
2707 if (!un || un->magic != DGAP_UNIT_MAGIC)
2711 if (!ch || ch->magic != DGAP_CHANNEL_MAGIC)
2718 DGAP_LOCK(ch->ch_lock, lock_flags);
2720 tmask = ch->ch_tsize - 1;
2721 head = readw(&(bs->tx_head)) & tmask;
2722 tail = readw(&(bs->tx_tail)) & tmask;
2724 ret = tail - head - 1;
2726 ret += ch->ch_tsize;
2728 /* Limit printer to maxcps */
2729 ret = dgap_maxcps_room(tty, ret);
2732 * If we are printer device, leave space for
2733 * possibly both the on and off strings.
2735 if (un->un_type == DGAP_PRINT) {
2736 if (!(ch->ch_flags & CH_PRON))
2737 ret -= ch->ch_digi.digi_onlen;
2738 ret -= ch->ch_digi.digi_offlen;
2740 if (ch->ch_flags & CH_PRON)
2741 ret -= ch->ch_digi.digi_offlen;
2748 * Schedule FEP to wake us up if needed.
2750 * TODO: This might be overkill...
2751 * Do we really need to schedule callbacks from the FEP
2752 * in every case? Can we get smarter based on ret?
2754 dgap_set_firmware_event(un, UN_LOW | UN_EMPTY);
2755 DGAP_UNLOCK(ch->ch_lock, lock_flags);
2761 * dgap_tty_put_char()
2763 * Put a character into ch->ch_buf
2765 * - used by the line discipline for OPOST processing
2767 static int dgap_tty_put_char(struct tty_struct *tty, unsigned char c)
2770 * Simply call tty_write.
2772 dgap_tty_write(tty, &c, 1);
2779 * Take data from the user or kernel and send it out to the FEP.
2780 * In here exists all the Transparent Print magic as well.
2782 static int dgap_tty_write(struct tty_struct *tty, const unsigned char *buf,
2785 struct channel_t *ch = NULL;
2786 struct un_t *un = NULL;
2787 struct bs_t *bs = NULL;
2789 u16 head, tail, tmask, remain;
2790 int bufcount = 0, n = 0;
2797 un = tty->driver_data;
2798 if (!un || un->magic != DGAP_UNIT_MAGIC)
2802 if (!ch || ch->magic != DGAP_CHANNEL_MAGIC)
2813 * Store original amount of characters passed in.
2814 * This helps to figure out if we should ask the FEP
2815 * to send us an event when it has more space available.
2819 DGAP_LOCK(ch->ch_lock, lock_flags);
2821 /* Get our space available for the channel from the board */
2822 tmask = ch->ch_tsize - 1;
2823 head = readw(&(bs->tx_head)) & tmask;
2824 tail = readw(&(bs->tx_tail)) & tmask;
2826 bufcount = tail - head - 1;
2828 bufcount += ch->ch_tsize;
2831 * Limit printer output to maxcps overall, with bursts allowed
2832 * up to bufsize characters.
2834 bufcount = dgap_maxcps_room(tty, bufcount);
2837 * Take minimum of what the user wants to send, and the
2838 * space available in the FEP buffer.
2840 count = min(count, bufcount);
2843 * Bail if no space left.
2846 dgap_set_firmware_event(un, UN_LOW | UN_EMPTY);
2847 DGAP_UNLOCK(ch->ch_lock, lock_flags);
2852 * Output the printer ON string, if we are in terminal mode, but
2853 * need to be in printer mode.
2855 if ((un->un_type == DGAP_PRINT) && !(ch->ch_flags & CH_PRON)) {
2856 dgap_wmove(ch, ch->ch_digi.digi_onstr,
2857 (int) ch->ch_digi.digi_onlen);
2858 head = readw(&(bs->tx_head)) & tmask;
2859 ch->ch_flags |= CH_PRON;
2863 * On the other hand, output the printer OFF string, if we are
2864 * currently in printer mode, but need to output to the terminal.
2866 if ((un->un_type != DGAP_PRINT) && (ch->ch_flags & CH_PRON)) {
2867 dgap_wmove(ch, ch->ch_digi.digi_offstr,
2868 (int) ch->ch_digi.digi_offlen);
2869 head = readw(&(bs->tx_head)) & tmask;
2870 ch->ch_flags &= ~CH_PRON;
2874 * If there is nothing left to copy, or
2875 * I can't handle any more data, leave.
2878 dgap_set_firmware_event(un, UN_LOW | UN_EMPTY);
2879 DGAP_UNLOCK(ch->ch_lock, lock_flags);
2886 * If the write wraps over the top of the circular buffer,
2887 * move the portion up to the wrap point, and reset the
2888 * pointers to the bottom.
2890 remain = ch->ch_tstart + ch->ch_tsize - head;
2894 vaddr = ch->ch_taddr + head;
2896 memcpy_toio(vaddr, (uchar *) buf, remain);
2897 dgap_sniff_nowait_nolock(ch, "USER WRITE", (uchar *) buf,
2900 head = ch->ch_tstart;
2907 * Move rest of data.
2909 vaddr = ch->ch_taddr + head;
2912 memcpy_toio(vaddr, (uchar *) buf, remain);
2913 dgap_sniff_nowait_nolock(ch, "USER WRITE", (uchar *)buf,
2921 ch->ch_txcount += count;
2923 writew(head, &(bs->tx_head));
2926 dgap_set_firmware_event(un, UN_LOW | UN_EMPTY);
2929 * If this is the print device, and the
2930 * printer is still on, we need to turn it
2931 * off before going idle. If the buffer is
2932 * non-empty, wait until it goes empty.
2933 * Otherwise turn it off right now.
2935 if ((un->un_type == DGAP_PRINT) && (ch->ch_flags & CH_PRON)) {
2936 tail = readw(&(bs->tx_tail)) & tmask;
2939 un->un_flags |= UN_EMPTY;
2940 writeb(1, &(bs->iempty));
2942 dgap_wmove(ch, ch->ch_digi.digi_offstr,
2943 (int) ch->ch_digi.digi_offlen);
2944 head = readw(&(bs->tx_head)) & tmask;
2945 ch->ch_flags &= ~CH_PRON;
2949 /* Update printer buffer empty time. */
2950 if ((un->un_type == DGAP_PRINT) && (ch->ch_digi.digi_maxcps > 0)
2951 && (ch->ch_digi.digi_bufsize > 0)) {
2952 ch->ch_cpstime += (HZ * count) / ch->ch_digi.digi_maxcps;
2955 DGAP_UNLOCK(ch->ch_lock, lock_flags);
2961 * Return modem signals to ld.
2963 static int dgap_tty_tiocmget(struct tty_struct *tty)
2965 struct channel_t *ch;
2971 if (!tty || tty->magic != TTY_MAGIC)
2974 un = tty->driver_data;
2975 if (!un || un->magic != DGAP_UNIT_MAGIC)
2979 if (!ch || ch->magic != DGAP_CHANNEL_MAGIC)
2982 DGAP_LOCK(ch->ch_lock, lock_flags);
2984 mstat = readb(&(ch->ch_bs->m_stat));
2985 /* Append any outbound signals that might be pending... */
2986 mstat |= ch->ch_mostat;
2988 DGAP_UNLOCK(ch->ch_lock, lock_flags);
2992 if (mstat & D_DTR(ch))
2993 result |= TIOCM_DTR;
2994 if (mstat & D_RTS(ch))
2995 result |= TIOCM_RTS;
2996 if (mstat & D_CTS(ch))
2997 result |= TIOCM_CTS;
2998 if (mstat & D_DSR(ch))
2999 result |= TIOCM_DSR;
3000 if (mstat & D_RI(ch))
3002 if (mstat & D_CD(ch))
3009 * dgap_tty_tiocmset()
3011 * Set modem signals, called by ld.
3013 static int dgap_tty_tiocmset(struct tty_struct *tty,
3014 unsigned int set, unsigned int clear)
3017 struct channel_t *ch;
3023 if (!tty || tty->magic != TTY_MAGIC)
3026 un = tty->driver_data;
3027 if (!un || un->magic != DGAP_UNIT_MAGIC)
3031 if (!ch || ch->magic != DGAP_CHANNEL_MAGIC)
3035 if (!bd || bd->magic != DGAP_BOARD_MAGIC)
3038 DGAP_LOCK(bd->bd_lock, lock_flags);
3039 DGAP_LOCK(ch->ch_lock, lock_flags2);
3041 if (set & TIOCM_RTS) {
3042 ch->ch_mforce |= D_RTS(ch);
3043 ch->ch_mval |= D_RTS(ch);
3046 if (set & TIOCM_DTR) {
3047 ch->ch_mforce |= D_DTR(ch);
3048 ch->ch_mval |= D_DTR(ch);
3051 if (clear & TIOCM_RTS) {
3052 ch->ch_mforce |= D_RTS(ch);
3053 ch->ch_mval &= ~(D_RTS(ch));
3056 if (clear & TIOCM_DTR) {
3057 ch->ch_mforce |= D_DTR(ch);
3058 ch->ch_mval &= ~(D_DTR(ch));
3063 DGAP_UNLOCK(ch->ch_lock, lock_flags2);
3064 DGAP_UNLOCK(bd->bd_lock, lock_flags);
3070 * dgap_tty_send_break()
3072 * Send a Break, called by ld.
3074 static int dgap_tty_send_break(struct tty_struct *tty, int msec)
3077 struct channel_t *ch;
3083 if (!tty || tty->magic != TTY_MAGIC)
3086 un = tty->driver_data;
3087 if (!un || un->magic != DGAP_UNIT_MAGIC)
3091 if (!ch || ch->magic != DGAP_CHANNEL_MAGIC)
3095 if (!bd || bd->magic != DGAP_BOARD_MAGIC)
3110 DGAP_LOCK(bd->bd_lock, lock_flags);
3111 DGAP_LOCK(ch->ch_lock, lock_flags2);
3113 dgap_cmdw(ch, SBREAK, (u16) SBREAK_TIME, 0);
3115 dgap_cmdw(ch, SBREAK, (u16) msec, 0);
3117 DGAP_UNLOCK(ch->ch_lock, lock_flags2);
3118 DGAP_UNLOCK(bd->bd_lock, lock_flags);
3124 * dgap_tty_wait_until_sent()
3126 * wait until data has been transmitted, called by ld.
3128 static void dgap_tty_wait_until_sent(struct tty_struct *tty, int timeout)
3130 dgap_wait_for_drain(tty);
3136 * send a high priority character, called by ld.
3138 static void dgap_tty_send_xchar(struct tty_struct *tty, char c)
3141 struct channel_t *ch;
3146 if (!tty || tty->magic != TTY_MAGIC)
3149 un = tty->driver_data;
3150 if (!un || un->magic != DGAP_UNIT_MAGIC)
3154 if (!ch || ch->magic != DGAP_CHANNEL_MAGIC)
3158 if (!bd || bd->magic != DGAP_BOARD_MAGIC)
3161 DGAP_LOCK(bd->bd_lock, lock_flags);
3162 DGAP_LOCK(ch->ch_lock, lock_flags2);
3165 * This is technically what we should do.
3166 * However, the NIST tests specifically want
3167 * to see each XON or XOFF character that it
3168 * sends, so lets just send each character
3172 if (c == STOP_CHAR(tty))
3173 dgap_cmdw(ch, RPAUSE, 0, 0);
3174 else if (c == START_CHAR(tty))
3175 dgap_cmdw(ch, RRESUME, 0, 0);
3177 dgap_wmove(ch, &c, 1);
3179 dgap_wmove(ch, &c, 1);
3182 DGAP_UNLOCK(ch->ch_lock, lock_flags2);
3183 DGAP_UNLOCK(bd->bd_lock, lock_flags);
3189 * Return modem signals to ld.
3191 static int dgap_get_modem_info(struct channel_t *ch, unsigned int __user *value)
3198 if (!ch || ch->magic != DGAP_CHANNEL_MAGIC)
3201 DGAP_LOCK(ch->ch_lock, lock_flags);
3203 mstat = readb(&(ch->ch_bs->m_stat));
3204 /* Append any outbound signals that might be pending... */
3205 mstat |= ch->ch_mostat;
3207 DGAP_UNLOCK(ch->ch_lock, lock_flags);
3211 if (mstat & D_DTR(ch))
3212 result |= TIOCM_DTR;
3213 if (mstat & D_RTS(ch))
3214 result |= TIOCM_RTS;
3215 if (mstat & D_CTS(ch))
3216 result |= TIOCM_CTS;
3217 if (mstat & D_DSR(ch))
3218 result |= TIOCM_DSR;
3219 if (mstat & D_RI(ch))
3221 if (mstat & D_CD(ch))
3224 rc = put_user(result, value);
3230 * dgap_set_modem_info()
3232 * Set modem signals, called by ld.
3234 static int dgap_set_modem_info(struct tty_struct *tty, unsigned int command,
3235 unsigned int __user *value)
3238 struct channel_t *ch;
3241 unsigned int arg = 0;
3245 if (!tty || tty->magic != TTY_MAGIC)
3248 un = tty->driver_data;
3249 if (!un || un->magic != DGAP_UNIT_MAGIC)
3253 if (!ch || ch->magic != DGAP_CHANNEL_MAGIC)
3257 if (!bd || bd->magic != DGAP_BOARD_MAGIC)
3260 ret = get_user(arg, value);
3266 if (arg & TIOCM_RTS) {
3267 ch->ch_mforce |= D_RTS(ch);
3268 ch->ch_mval |= D_RTS(ch);
3271 if (arg & TIOCM_DTR) {
3272 ch->ch_mforce |= D_DTR(ch);
3273 ch->ch_mval |= D_DTR(ch);
3279 if (arg & TIOCM_RTS) {
3280 ch->ch_mforce |= D_RTS(ch);
3281 ch->ch_mval &= ~(D_RTS(ch));
3284 if (arg & TIOCM_DTR) {
3285 ch->ch_mforce |= D_DTR(ch);
3286 ch->ch_mval &= ~(D_DTR(ch));
3292 ch->ch_mforce = D_DTR(ch)|D_RTS(ch);
3294 if (arg & TIOCM_RTS)
3295 ch->ch_mval |= D_RTS(ch);
3297 ch->ch_mval &= ~(D_RTS(ch));
3299 if (arg & TIOCM_DTR)
3300 ch->ch_mval |= (D_DTR(ch));
3302 ch->ch_mval &= ~(D_DTR(ch));
3310 DGAP_LOCK(bd->bd_lock, lock_flags);
3311 DGAP_LOCK(ch->ch_lock, lock_flags2);
3315 DGAP_UNLOCK(ch->ch_lock, lock_flags2);
3316 DGAP_UNLOCK(bd->bd_lock, lock_flags);
3322 * dgap_tty_digigeta()
3324 * Ioctl to get the information for ditty.
3329 static int dgap_tty_digigeta(struct tty_struct *tty,
3330 struct digi_t __user *retinfo)
3332 struct channel_t *ch;
3340 if (!tty || tty->magic != TTY_MAGIC)
3343 un = tty->driver_data;
3344 if (!un || un->magic != DGAP_UNIT_MAGIC)
3348 if (!ch || ch->magic != DGAP_CHANNEL_MAGIC)
3351 memset(&tmp, 0, sizeof(tmp));
3353 DGAP_LOCK(ch->ch_lock, lock_flags);
3354 memcpy(&tmp, &ch->ch_digi, sizeof(tmp));
3355 DGAP_UNLOCK(ch->ch_lock, lock_flags);
3357 if (copy_to_user(retinfo, &tmp, sizeof(*retinfo)))
3364 * dgap_tty_digiseta()
3366 * Ioctl to set the information for ditty.
3371 static int dgap_tty_digiseta(struct tty_struct *tty,
3372 struct digi_t __user *new_info)
3375 struct channel_t *ch;
3377 struct digi_t new_digi;
3378 ulong lock_flags = 0;
3379 unsigned long lock_flags2;
3381 if (!tty || tty->magic != TTY_MAGIC)
3384 un = tty->driver_data;
3385 if (!un || un->magic != DGAP_UNIT_MAGIC)
3389 if (!ch || ch->magic != DGAP_CHANNEL_MAGIC)
3393 if (!bd || bd->magic != DGAP_BOARD_MAGIC)
3396 if (copy_from_user(&new_digi, new_info, sizeof(struct digi_t)))
3399 DGAP_LOCK(bd->bd_lock, lock_flags);
3400 DGAP_LOCK(ch->ch_lock, lock_flags2);
3402 memcpy(&ch->ch_digi, &new_digi, sizeof(struct digi_t));
3404 if (ch->ch_digi.digi_maxcps < 1)
3405 ch->ch_digi.digi_maxcps = 1;
3407 if (ch->ch_digi.digi_maxcps > 10000)
3408 ch->ch_digi.digi_maxcps = 10000;
3410 if (ch->ch_digi.digi_bufsize < 10)
3411 ch->ch_digi.digi_bufsize = 10;
3413 if (ch->ch_digi.digi_maxchar < 1)
3414 ch->ch_digi.digi_maxchar = 1;
3416 if (ch->ch_digi.digi_maxchar > ch->ch_digi.digi_bufsize)
3417 ch->ch_digi.digi_maxchar = ch->ch_digi.digi_bufsize;
3419 if (ch->ch_digi.digi_onlen > DIGI_PLEN)
3420 ch->ch_digi.digi_onlen = DIGI_PLEN;
3422 if (ch->ch_digi.digi_offlen > DIGI_PLEN)
3423 ch->ch_digi.digi_offlen = DIGI_PLEN;
3427 DGAP_UNLOCK(ch->ch_lock, lock_flags2);
3428 DGAP_UNLOCK(bd->bd_lock, lock_flags);
3434 * dgap_tty_digigetedelay()
3436 * Ioctl to get the current edelay setting.
3441 static int dgap_tty_digigetedelay(struct tty_struct *tty, int __user *retinfo)
3443 struct channel_t *ch;
3451 if (!tty || tty->magic != TTY_MAGIC)
3454 un = tty->driver_data;
3455 if (!un || un->magic != DGAP_UNIT_MAGIC)
3459 if (!ch || ch->magic != DGAP_CHANNEL_MAGIC)
3462 memset(&tmp, 0, sizeof(tmp));
3464 DGAP_LOCK(ch->ch_lock, lock_flags);
3465 tmp = readw(&(ch->ch_bs->edelay));
3466 DGAP_UNLOCK(ch->ch_lock, lock_flags);
3468 if (copy_to_user(retinfo, &tmp, sizeof(*retinfo)))
3475 * dgap_tty_digisetedelay()
3477 * Ioctl to set the EDELAY setting
3480 static int dgap_tty_digisetedelay(struct tty_struct *tty, int __user *new_info)
3483 struct channel_t *ch;
3489 if (!tty || tty->magic != TTY_MAGIC)
3492 un = tty->driver_data;
3493 if (!un || un->magic != DGAP_UNIT_MAGIC)
3497 if (!ch || ch->magic != DGAP_CHANNEL_MAGIC)
3501 if (!bd || bd->magic != DGAP_BOARD_MAGIC)
3504 if (copy_from_user(&new_digi, new_info, sizeof(int)))
3507 DGAP_LOCK(bd->bd_lock, lock_flags);
3508 DGAP_LOCK(ch->ch_lock, lock_flags2);
3510 writew((u16) new_digi, &(ch->ch_bs->edelay));
3514 DGAP_UNLOCK(ch->ch_lock, lock_flags2);
3515 DGAP_UNLOCK(bd->bd_lock, lock_flags);
3521 * dgap_tty_digigetcustombaud()
3523 * Ioctl to get the current custom baud rate setting.
3525 static int dgap_tty_digigetcustombaud(struct tty_struct *tty,
3526 int __user *retinfo)
3528 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)
3547 memset(&tmp, 0, sizeof(tmp));
3549 DGAP_LOCK(ch->ch_lock, lock_flags);
3550 tmp = dgap_get_custom_baud(ch);
3551 DGAP_UNLOCK(ch->ch_lock, lock_flags);
3553 if (copy_to_user(retinfo, &tmp, sizeof(*retinfo)))
3560 * dgap_tty_digisetcustombaud()
3562 * Ioctl to set the custom baud rate setting
3564 static int dgap_tty_digisetcustombaud(struct tty_struct *tty,
3565 int __user *new_info)
3568 struct channel_t *ch;
3574 if (!tty || tty->magic != TTY_MAGIC)
3577 un = tty->driver_data;
3578 if (!un || un->magic != DGAP_UNIT_MAGIC)
3582 if (!ch || ch->magic != DGAP_CHANNEL_MAGIC)
3586 if (!bd || bd->magic != DGAP_BOARD_MAGIC)
3590 if (copy_from_user(&new_rate, new_info, sizeof(unsigned int)))
3593 if (bd->bd_flags & BD_FEP5PLUS) {
3595 DGAP_LOCK(bd->bd_lock, lock_flags);
3596 DGAP_LOCK(ch->ch_lock, lock_flags2);
3598 ch->ch_custom_speed = new_rate;
3602 DGAP_UNLOCK(ch->ch_lock, lock_flags2);
3603 DGAP_UNLOCK(bd->bd_lock, lock_flags);
3610 * dgap_set_termios()
3612 static void dgap_tty_set_termios(struct tty_struct *tty,
3613 struct ktermios *old_termios)
3616 struct channel_t *ch;
3618 unsigned long lock_flags;
3619 unsigned long lock_flags2;
3621 if (!tty || tty->magic != TTY_MAGIC)
3624 un = tty->driver_data;
3625 if (!un || un->magic != DGAP_UNIT_MAGIC)
3629 if (!ch || ch->magic != DGAP_CHANNEL_MAGIC)
3633 if (!bd || bd->magic != DGAP_BOARD_MAGIC)
3636 DGAP_LOCK(bd->bd_lock, lock_flags);
3637 DGAP_LOCK(ch->ch_lock, lock_flags2);
3639 ch->ch_c_cflag = tty->termios.c_cflag;
3640 ch->ch_c_iflag = tty->termios.c_iflag;
3641 ch->ch_c_oflag = tty->termios.c_oflag;
3642 ch->ch_c_lflag = tty->termios.c_lflag;
3643 ch->ch_startc = tty->termios.c_cc[VSTART];
3644 ch->ch_stopc = tty->termios.c_cc[VSTOP];
3649 DGAP_UNLOCK(ch->ch_lock, lock_flags2);
3650 DGAP_UNLOCK(bd->bd_lock, lock_flags);
3653 static void dgap_tty_throttle(struct tty_struct *tty)
3656 struct channel_t *ch;
3661 if (!tty || tty->magic != TTY_MAGIC)
3664 un = tty->driver_data;
3665 if (!un || un->magic != DGAP_UNIT_MAGIC)
3669 if (!ch || ch->magic != DGAP_CHANNEL_MAGIC)
3673 if (!bd || bd->magic != DGAP_BOARD_MAGIC)
3676 DGAP_LOCK(bd->bd_lock, lock_flags);
3677 DGAP_LOCK(ch->ch_lock, lock_flags2);
3679 ch->ch_flags |= (CH_RXBLOCK);
3681 dgap_cmdw(ch, RPAUSE, 0, 0);
3684 DGAP_UNLOCK(ch->ch_lock, lock_flags2);
3685 DGAP_UNLOCK(bd->bd_lock, lock_flags);
3689 static void dgap_tty_unthrottle(struct tty_struct *tty)
3692 struct channel_t *ch;
3697 if (!tty || tty->magic != TTY_MAGIC)
3700 un = tty->driver_data;
3701 if (!un || un->magic != DGAP_UNIT_MAGIC)
3705 if (!ch || ch->magic != DGAP_CHANNEL_MAGIC)
3709 if (!bd || bd->magic != DGAP_BOARD_MAGIC)
3712 DGAP_LOCK(bd->bd_lock, lock_flags);
3713 DGAP_LOCK(ch->ch_lock, lock_flags2);
3715 ch->ch_flags &= ~(CH_RXBLOCK);
3718 dgap_cmdw(ch, RRESUME, 0, 0);
3721 DGAP_UNLOCK(ch->ch_lock, lock_flags2);
3722 DGAP_UNLOCK(bd->bd_lock, lock_flags);
3725 static void dgap_tty_start(struct tty_struct *tty)
3728 struct channel_t *ch;
3733 if (!tty || tty->magic != TTY_MAGIC)
3736 un = tty->driver_data;
3737 if (!un || un->magic != DGAP_UNIT_MAGIC)
3741 if (!ch || ch->magic != DGAP_CHANNEL_MAGIC)
3745 if (!bd || bd->magic != DGAP_BOARD_MAGIC)
3748 DGAP_LOCK(bd->bd_lock, lock_flags);
3749 DGAP_LOCK(ch->ch_lock, lock_flags2);
3751 dgap_cmdw(ch, RESUMETX, 0, 0);
3753 DGAP_UNLOCK(ch->ch_lock, lock_flags2);
3754 DGAP_UNLOCK(bd->bd_lock, lock_flags);
3758 static void dgap_tty_stop(struct tty_struct *tty)
3761 struct channel_t *ch;
3766 if (!tty || tty->magic != TTY_MAGIC)
3769 un = tty->driver_data;
3770 if (!un || un->magic != DGAP_UNIT_MAGIC)
3774 if (!ch || ch->magic != DGAP_CHANNEL_MAGIC)
3778 if (!bd || bd->magic != DGAP_BOARD_MAGIC)
3781 DGAP_LOCK(bd->bd_lock, lock_flags);
3782 DGAP_LOCK(ch->ch_lock, lock_flags2);
3784 dgap_cmdw(ch, PAUSETX, 0, 0);
3786 DGAP_UNLOCK(ch->ch_lock, lock_flags2);
3787 DGAP_UNLOCK(bd->bd_lock, lock_flags);
3792 * dgap_tty_flush_chars()
3794 * Flush the cook buffer
3796 * Note to self, and any other poor souls who venture here:
3798 * flush in this case DOES NOT mean dispose of the data.
3799 * instead, it means "stop buffering and send it if you
3800 * haven't already." Just guess how I figured that out... SRW 2-Jun-98
3802 * It is also always called in interrupt context - JAR 8-Sept-99
3804 static void dgap_tty_flush_chars(struct tty_struct *tty)
3807 struct channel_t *ch;
3812 if (!tty || tty->magic != TTY_MAGIC)
3815 un = tty->driver_data;
3816 if (!un || un->magic != DGAP_UNIT_MAGIC)
3820 if (!ch || ch->magic != DGAP_CHANNEL_MAGIC)
3824 if (!bd || bd->magic != DGAP_BOARD_MAGIC)
3827 DGAP_LOCK(bd->bd_lock, lock_flags);
3828 DGAP_LOCK(ch->ch_lock, lock_flags2);
3830 /* TODO: Do something here */
3832 DGAP_UNLOCK(ch->ch_lock, lock_flags2);
3833 DGAP_UNLOCK(bd->bd_lock, lock_flags);
3837 * dgap_tty_flush_buffer()
3839 * Flush Tx buffer (make in == out)
3841 static void dgap_tty_flush_buffer(struct tty_struct *tty)
3844 struct channel_t *ch;
3850 if (!tty || tty->magic != TTY_MAGIC)
3853 un = tty->driver_data;
3854 if (!un || un->magic != DGAP_UNIT_MAGIC)
3858 if (!ch || ch->magic != DGAP_CHANNEL_MAGIC)
3862 if (!bd || bd->magic != DGAP_BOARD_MAGIC)
3865 DGAP_LOCK(bd->bd_lock, lock_flags);
3866 DGAP_LOCK(ch->ch_lock, lock_flags2);
3868 ch->ch_flags &= ~CH_STOP;
3869 head = readw(&(ch->ch_bs->tx_head));
3870 dgap_cmdw(ch, FLUSHTX, (u16) head, 0);
3871 dgap_cmdw(ch, RESUMETX, 0, 0);
3872 if (ch->ch_tun.un_flags & (UN_LOW|UN_EMPTY)) {
3873 ch->ch_tun.un_flags &= ~(UN_LOW|UN_EMPTY);
3874 wake_up_interruptible(&ch->ch_tun.un_flags_wait);
3876 if (ch->ch_pun.un_flags & (UN_LOW|UN_EMPTY)) {
3877 ch->ch_pun.un_flags &= ~(UN_LOW|UN_EMPTY);
3878 wake_up_interruptible(&ch->ch_pun.un_flags_wait);
3881 DGAP_UNLOCK(ch->ch_lock, lock_flags2);
3882 DGAP_UNLOCK(bd->bd_lock, lock_flags);
3883 if (waitqueue_active(&tty->write_wait))
3884 wake_up_interruptible(&tty->write_wait);
3888 /*****************************************************************************
3890 * The IOCTL function and all of its helpers
3892 *****************************************************************************/
3897 * The usual assortment of ioctl's
3899 static int dgap_tty_ioctl(struct tty_struct *tty, unsigned int cmd,
3903 struct channel_t *ch;
3907 ulong lock_flags = 0;
3908 ulong lock_flags2 = 0;
3909 void __user *uarg = (void __user *) arg;
3911 if (!tty || tty->magic != TTY_MAGIC)
3914 un = tty->driver_data;
3915 if (!un || un->magic != DGAP_UNIT_MAGIC)
3919 if (!ch || ch->magic != DGAP_CHANNEL_MAGIC)
3923 if (!bd || bd->magic != DGAP_BOARD_MAGIC)
3926 DGAP_LOCK(bd->bd_lock, lock_flags);
3927 DGAP_LOCK(ch->ch_lock, lock_flags2);
3929 if (un->un_open_count <= 0) {
3930 DGAP_UNLOCK(ch->ch_lock, lock_flags2);
3931 DGAP_UNLOCK(bd->bd_lock, lock_flags);
3937 /* Here are all the standard ioctl's that we MUST implement */
3941 * TCSBRK is SVID version: non-zero arg --> no break
3942 * this behaviour is exploited by tcdrain().
3944 * According to POSIX.1 spec (7.2.2.1.2) breaks should be
3945 * between 0.25 and 0.5 seconds so we'll ask for something
3946 * in the middle: 0.375 seconds.
3948 rc = tty_check_change(tty);
3949 DGAP_UNLOCK(ch->ch_lock, lock_flags2);
3950 DGAP_UNLOCK(bd->bd_lock, lock_flags);
3954 rc = dgap_wait_for_drain(tty);
3959 DGAP_LOCK(bd->bd_lock, lock_flags);
3960 DGAP_LOCK(ch->ch_lock, lock_flags2);
3962 if (((cmd == TCSBRK) && (!arg)) || (cmd == TCSBRKP))
3963 dgap_cmdw(ch, SBREAK, (u16) SBREAK_TIME, 0);
3965 DGAP_UNLOCK(ch->ch_lock, lock_flags2);
3966 DGAP_UNLOCK(bd->bd_lock, lock_flags);
3971 /* support for POSIX tcsendbreak()
3973 * According to POSIX.1 spec (7.2.2.1.2) breaks should be
3974 * between 0.25 and 0.5 seconds so we'll ask for something
3975 * in the middle: 0.375 seconds.
3977 rc = tty_check_change(tty);
3978 DGAP_UNLOCK(ch->ch_lock, lock_flags2);
3979 DGAP_UNLOCK(bd->bd_lock, lock_flags);
3983 rc = dgap_wait_for_drain(tty);
3987 DGAP_LOCK(bd->bd_lock, lock_flags);
3988 DGAP_LOCK(ch->ch_lock, lock_flags2);
3990 dgap_cmdw(ch, SBREAK, (u16) SBREAK_TIME, 0);
3992 DGAP_UNLOCK(ch->ch_lock, lock_flags2);
3993 DGAP_UNLOCK(bd->bd_lock, lock_flags);
3999 * FEP5 doesn't support turning on a break unconditionally.
4000 * The FEP5 device will stop sending a break automatically
4001 * after the specified time value that was sent when turning on
4004 rc = tty_check_change(tty);
4005 DGAP_UNLOCK(ch->ch_lock, lock_flags2);
4006 DGAP_UNLOCK(bd->bd_lock, lock_flags);
4010 rc = dgap_wait_for_drain(tty);
4014 DGAP_LOCK(bd->bd_lock, lock_flags);
4015 DGAP_LOCK(ch->ch_lock, lock_flags2);
4017 dgap_cmdw(ch, SBREAK, (u16) SBREAK_TIME, 0);
4019 DGAP_UNLOCK(ch->ch_lock, lock_flags2);
4020 DGAP_UNLOCK(bd->bd_lock, lock_flags);
4026 * FEP5 doesn't support turning off a break unconditionally.
4027 * The FEP5 device will stop sending a break automatically
4028 * after the specified time value that was sent when turning on
4031 DGAP_UNLOCK(ch->ch_lock, lock_flags2);
4032 DGAP_UNLOCK(bd->bd_lock, lock_flags);
4037 DGAP_UNLOCK(ch->ch_lock, lock_flags2);
4038 DGAP_UNLOCK(bd->bd_lock, lock_flags);
4040 rc = put_user(C_CLOCAL(tty) ? 1 : 0,
4041 (unsigned long __user *) arg);
4045 DGAP_UNLOCK(ch->ch_lock, lock_flags2);
4046 DGAP_UNLOCK(bd->bd_lock, lock_flags);
4048 rc = get_user(arg, (unsigned long __user *) arg);
4052 DGAP_LOCK(bd->bd_lock, lock_flags);
4053 DGAP_LOCK(ch->ch_lock, lock_flags2);
4054 tty->termios.c_cflag = ((tty->termios.c_cflag & ~CLOCAL) |
4055 (arg ? CLOCAL : 0));
4057 DGAP_UNLOCK(ch->ch_lock, lock_flags2);
4058 DGAP_UNLOCK(bd->bd_lock, lock_flags);
4063 DGAP_UNLOCK(ch->ch_lock, lock_flags2);
4064 DGAP_UNLOCK(bd->bd_lock, lock_flags);
4065 return dgap_get_modem_info(ch, uarg);
4070 DGAP_UNLOCK(ch->ch_lock, lock_flags2);
4071 DGAP_UNLOCK(bd->bd_lock, lock_flags);
4072 return dgap_set_modem_info(tty, cmd, uarg);
4075 * Here are any additional ioctl's that we want to implement
4080 * The linux tty driver doesn't have a flush
4081 * input routine for the driver, assuming all backed
4082 * up data is in the line disc. buffers. However,
4083 * we all know that's not the case. Here, we
4084 * act on the ioctl, but then lie and say we didn't
4085 * so the line discipline will process the flush
4088 rc = tty_check_change(tty);
4090 DGAP_UNLOCK(ch->ch_lock, lock_flags2);
4091 DGAP_UNLOCK(bd->bd_lock, lock_flags);
4095 if ((arg == TCIFLUSH) || (arg == TCIOFLUSH)) {
4096 if (!(un->un_type == DGAP_PRINT)) {
4097 head = readw(&(ch->ch_bs->rx_head));
4098 writew(head, &(ch->ch_bs->rx_tail));
4099 writeb(0, &(ch->ch_bs->orun));
4103 if ((arg == TCOFLUSH) || (arg == TCIOFLUSH)) {
4104 ch->ch_flags &= ~CH_STOP;
4105 head = readw(&(ch->ch_bs->tx_head));
4106 dgap_cmdw(ch, FLUSHTX, (u16) head, 0);
4107 dgap_cmdw(ch, RESUMETX, 0, 0);
4108 if (ch->ch_tun.un_flags & (UN_LOW|UN_EMPTY)) {
4109 ch->ch_tun.un_flags &= ~(UN_LOW|UN_EMPTY);
4110 wake_up_interruptible(&ch->ch_tun.un_flags_wait);
4112 if (ch->ch_pun.un_flags & (UN_LOW|UN_EMPTY)) {
4113 ch->ch_pun.un_flags &= ~(UN_LOW|UN_EMPTY);
4114 wake_up_interruptible(&ch->ch_pun.un_flags_wait);
4116 if (waitqueue_active(&tty->write_wait))
4117 wake_up_interruptible(&tty->write_wait);
4119 /* Can't hold any locks when calling tty_wakeup! */
4120 DGAP_UNLOCK(ch->ch_lock, lock_flags2);
4121 DGAP_UNLOCK(bd->bd_lock, lock_flags);
4123 DGAP_LOCK(bd->bd_lock, lock_flags);
4124 DGAP_LOCK(ch->ch_lock, lock_flags2);
4127 /* pretend we didn't recognize this IOCTL */
4128 DGAP_UNLOCK(ch->ch_lock, lock_flags2);
4129 DGAP_UNLOCK(bd->bd_lock, lock_flags);
4131 return -ENOIOCTLCMD;
4136 * The linux tty driver doesn't have a flush
4137 * input routine for the driver, assuming all backed
4138 * up data is in the line disc. buffers. However,
4139 * we all know that's not the case. Here, we
4140 * act on the ioctl, but then lie and say we didn't
4141 * so the line discipline will process the flush
4144 if (cmd == TCSETSF) {
4146 ch->ch_flags &= ~CH_STOP;
4147 head = readw(&(ch->ch_bs->rx_head));
4148 writew(head, &(ch->ch_bs->rx_tail));
4151 /* now wait for all the output to drain */
4152 DGAP_UNLOCK(ch->ch_lock, lock_flags2);
4153 DGAP_UNLOCK(bd->bd_lock, lock_flags);
4154 rc = dgap_wait_for_drain(tty);
4158 /* pretend we didn't recognize this */
4159 return -ENOIOCTLCMD;
4163 DGAP_UNLOCK(ch->ch_lock, lock_flags2);
4164 DGAP_UNLOCK(bd->bd_lock, lock_flags);
4165 rc = dgap_wait_for_drain(tty);
4169 /* pretend we didn't recognize this */
4170 return -ENOIOCTLCMD;
4174 * The Linux Line Discipline (LD) would do this for us if we
4175 * let it, but we have the special firmware options to do this
4176 * the "right way" regardless of hardware or software flow
4177 * control so we'll do it outselves instead of letting the LD
4180 rc = tty_check_change(tty);
4182 DGAP_UNLOCK(ch->ch_lock, lock_flags2);
4183 DGAP_UNLOCK(bd->bd_lock, lock_flags);
4190 DGAP_UNLOCK(ch->ch_lock, lock_flags2);
4191 DGAP_UNLOCK(bd->bd_lock, lock_flags);
4192 dgap_tty_start(tty);
4195 DGAP_UNLOCK(ch->ch_lock, lock_flags2);
4196 DGAP_UNLOCK(bd->bd_lock, lock_flags);
4200 DGAP_UNLOCK(ch->ch_lock, lock_flags2);
4201 DGAP_UNLOCK(bd->bd_lock, lock_flags);
4202 /* Make the ld do it */
4203 return -ENOIOCTLCMD;
4205 DGAP_UNLOCK(ch->ch_lock, lock_flags2);
4206 DGAP_UNLOCK(bd->bd_lock, lock_flags);
4207 /* Make the ld do it */
4208 return -ENOIOCTLCMD;
4210 DGAP_UNLOCK(ch->ch_lock, lock_flags2);
4211 DGAP_UNLOCK(bd->bd_lock, lock_flags);
4216 /* get information for ditty */
4217 DGAP_UNLOCK(ch->ch_lock, lock_flags2);
4218 DGAP_UNLOCK(bd->bd_lock, lock_flags);
4219 return dgap_tty_digigeta(tty, uarg);
4224 /* set information for ditty */
4225 if (cmd == (DIGI_SETAW)) {
4227 DGAP_UNLOCK(ch->ch_lock, lock_flags2);
4228 DGAP_UNLOCK(bd->bd_lock, lock_flags);
4229 rc = dgap_wait_for_drain(tty);
4232 DGAP_LOCK(bd->bd_lock, lock_flags);
4233 DGAP_LOCK(ch->ch_lock, lock_flags2);
4235 tty_ldisc_flush(tty);
4239 DGAP_UNLOCK(ch->ch_lock, lock_flags2);
4240 DGAP_UNLOCK(bd->bd_lock, lock_flags);
4241 return dgap_tty_digiseta(tty, uarg);
4244 DGAP_UNLOCK(ch->ch_lock, lock_flags2);
4245 DGAP_UNLOCK(bd->bd_lock, lock_flags);
4246 return dgap_tty_digigetedelay(tty, uarg);
4249 DGAP_UNLOCK(ch->ch_lock, lock_flags2);
4250 DGAP_UNLOCK(bd->bd_lock, lock_flags);
4251 return dgap_tty_digisetedelay(tty, uarg);
4253 case DIGI_GETCUSTOMBAUD:
4254 DGAP_UNLOCK(ch->ch_lock, lock_flags2);
4255 DGAP_UNLOCK(bd->bd_lock, lock_flags);
4256 return dgap_tty_digigetcustombaud(tty, uarg);
4258 case DIGI_SETCUSTOMBAUD:
4259 DGAP_UNLOCK(ch->ch_lock, lock_flags2);
4260 DGAP_UNLOCK(bd->bd_lock, lock_flags);
4261 return dgap_tty_digisetcustombaud(tty, uarg);
4263 case DIGI_RESET_PORT:
4264 dgap_firmware_reset_port(ch);
4266 DGAP_UNLOCK(ch->ch_lock, lock_flags2);
4267 DGAP_UNLOCK(bd->bd_lock, lock_flags);
4271 DGAP_UNLOCK(ch->ch_lock, lock_flags2);
4272 DGAP_UNLOCK(bd->bd_lock, lock_flags);
4274 return -ENOIOCTLCMD;
4278 static int dgap_after_config_loaded(int board)
4281 * Initialize KME waitqueues...
4283 init_waitqueue_head(&(dgap_Board[board]->kme_wait));
4286 * allocate flip buffer for board.
4288 dgap_Board[board]->flipbuf = kmalloc(MYFLIPLEN, GFP_ATOMIC);
4289 if (!dgap_Board[board]->flipbuf)
4292 dgap_Board[board]->flipflagbuf = kmalloc(MYFLIPLEN, GFP_ATOMIC);
4293 if (!dgap_Board[board]->flipflagbuf) {
4294 kfree(dgap_Board[board]->flipbuf);
4302 * Create pr and tty device entries
4304 static int dgap_tty_register_ports(struct board_t *brd)
4306 struct channel_t *ch;
4309 brd->SerialPorts = kcalloc(brd->nasync, sizeof(*brd->SerialPorts),
4311 if (brd->SerialPorts == NULL)
4313 for (i = 0; i < brd->nasync; i++)
4314 tty_port_init(&brd->SerialPorts[i]);
4316 brd->PrinterPorts = kcalloc(brd->nasync, sizeof(*brd->PrinterPorts),
4318 if (brd->PrinterPorts == NULL) {
4319 kfree(brd->SerialPorts);
4322 for (i = 0; i < brd->nasync; i++)
4323 tty_port_init(&brd->PrinterPorts[i]);
4325 ch = brd->channels[0];
4326 for (i = 0; i < brd->nasync; i++, ch = brd->channels[i]) {
4328 struct device *classp;
4330 classp = tty_port_register_device(&brd->SerialPorts[i],
4332 brd->firstminor + i, NULL);
4334 dgap_create_tty_sysfs(&ch->ch_tun, classp);
4335 ch->ch_tun.un_sysfs = classp;
4337 classp = tty_port_register_device(&brd->PrinterPorts[i],
4339 brd->firstminor + i, NULL);
4341 dgap_create_tty_sysfs(&ch->ch_pun, classp);
4342 ch->ch_pun.un_sysfs = classp;
4344 dgap_create_ports_sysfiles(brd);
4350 * Copies the BIOS code from the user to the board,
4351 * and starts the BIOS running.
4353 static void dgap_do_bios_load(struct board_t *brd, uchar __user *ubios, int len)
4359 if (!brd || (brd->magic != DGAP_BOARD_MAGIC) || !brd->re_map_membase)
4362 addr = brd->re_map_membase;
4367 for (i = 0; i < 16; i++)
4368 writeb(0, addr + POSTAREA + i);
4374 memcpy_toio(addr + offset, ubios, len);
4376 writel(0x0bf00401, addr);
4377 writel(0, (addr + 4));
4379 /* Clear the reset, and change states. */
4380 writeb(FEPCLR, brd->re_map_port);
4384 * Checks to see if the BIOS completed running on the card.
4386 static void dgap_do_wait_for_bios(struct board_t *brd)
4393 if (!brd || (brd->magic != DGAP_BOARD_MAGIC) || !brd->re_map_membase)
4396 addr = brd->re_map_membase;
4397 word = readw(addr + POSTAREA);
4400 * It can take 5-6 seconds for a board to
4401 * pass the bios self test and post results.
4402 * Give it 10 seconds.
4404 brd->wait_for_bios = 0;
4405 while (brd->wait_for_bios < 1000) {
4406 /* Check to see if BIOS thinks board is good. (GD). */
4407 if (word == *(u16 *) "GD") {
4408 brd->state = FINISHED_BIOS_LOAD;
4411 msleep_interruptible(10);
4412 brd->wait_for_bios++;
4413 word = readw(addr + POSTAREA);
4416 /* Gave up on board after too long of time taken */
4417 err1 = readw(addr + SEQUENCE);
4418 err2 = readw(addr + ERROR);
4419 pr_warn("dgap: %s failed diagnostics. Error #(%x,%x).\n",
4420 brd->name, err1, err2);
4421 brd->state = BOARD_FAILED;
4422 brd->dpastatus = BD_NOBIOS;
4426 * Copies the FEP code from the user to the board,
4427 * and starts the FEP running.
4429 static void dgap_do_fep_load(struct board_t *brd, uchar __user *ufep, int len)
4434 if (!brd || (brd->magic != DGAP_BOARD_MAGIC) || !brd->re_map_membase)
4437 addr = brd->re_map_membase;
4443 memcpy_toio(addr + offset, ufep, len);
4446 * If board is a concentrator product, we need to give
4447 * it its config string describing how the concentrators look.
4449 if ((brd->type == PCX) || (brd->type == PEPC)) {
4451 uchar *config, *xconfig;
4454 xconfig = dgap_create_config_string(brd, string);
4456 /* Write string to board memory */
4457 config = addr + CONFIG;
4458 for (; i < CONFIGSIZE; i++, config++, xconfig++) {
4459 writeb(*xconfig, config);
4460 if ((*xconfig & 0xff) == 0xff)
4465 writel(0xbfc01004, (addr + 0xc34));
4466 writel(0x3, (addr + 0xc30));
4471 * Waits for the FEP to report thats its ready for us to use.
4473 static void dgap_do_wait_for_fep(struct board_t *brd)
4480 if (!brd || (brd->magic != DGAP_BOARD_MAGIC) || !brd->re_map_membase)
4483 addr = brd->re_map_membase;
4484 word = readw(addr + FEPSTAT);
4487 * It can take 2-3 seconds for the FEP to
4488 * be up and running. Give it 5 secs.
4490 brd->wait_for_fep = 0;
4491 while (brd->wait_for_fep < 500) {
4492 /* Check to see if FEP is up and running now. */
4493 if (word == *(u16 *) "OS") {
4494 brd->state = FINISHED_FEP_LOAD;
4496 * Check to see if the board can support FEP5+ commands.
4498 word = readw(addr + FEP5_PLUS);
4499 if (word == *(u16 *) "5A")
4500 brd->bd_flags |= BD_FEP5PLUS;
4504 msleep_interruptible(10);
4505 brd->wait_for_fep++;
4506 word = readw(addr + FEPSTAT);
4509 /* Gave up on board after too long of time taken */
4510 err1 = readw(addr + SEQUENCE);
4511 err2 = readw(addr + ERROR);
4512 pr_warn("dgap: FEPOS for %s not functioning. Error #(%x,%x).\n",
4513 brd->name, err1, err2);
4514 brd->state = BOARD_FAILED;
4515 brd->dpastatus = BD_NOFEP;
4519 * Physically forces the FEP5 card to reset itself.
4521 static void dgap_do_reset_board(struct board_t *brd)
4528 if (!brd || (brd->magic != DGAP_BOARD_MAGIC) ||
4529 !brd->re_map_membase || !brd->re_map_port)
4532 /* FEPRST does not vary among supported boards */
4533 writeb(FEPRST, brd->re_map_port);
4535 for (i = 0; i <= 1000; i++) {
4536 check = readb(brd->re_map_port) & 0xe;
4537 if (check == FEPRST)
4543 pr_warn("dgap: Board not resetting... Failing board.\n");
4544 brd->state = BOARD_FAILED;
4545 brd->dpastatus = BD_NOFEP;
4550 * Make sure there really is memory out there.
4552 writel(0xa55a3cc3, (brd->re_map_membase + LOWMEM));
4553 writel(0x5aa5c33c, (brd->re_map_membase + HIGHMEM));
4554 check1 = readl(brd->re_map_membase + LOWMEM);
4555 check2 = readl(brd->re_map_membase + HIGHMEM);
4557 if ((check1 != 0xa55a3cc3) || (check2 != 0x5aa5c33c)) {
4558 pr_warn("dgap: No memory at %p for board.\n",
4559 brd->re_map_membase);
4560 brd->state = BOARD_FAILED;
4561 brd->dpastatus = BD_NOFEP;
4565 if (brd->state != BOARD_FAILED)
4566 brd->state = FINISHED_RESET;
4569 #ifdef DIGI_CONCENTRATORS_SUPPORTED
4571 * Sends a concentrator image into the FEP5 board.
4573 static void dgap_do_conc_load(struct board_t *brd, uchar *uaddr, int len)
4577 struct downld_t *to_dp;
4579 if (!brd || (brd->magic != DGAP_BOARD_MAGIC) || !brd->re_map_membase)
4582 vaddr = brd->re_map_membase;
4584 offset = readw((u16 *) (vaddr + DOWNREQ));
4585 to_dp = (struct downld_t *) (vaddr + (int) offset);
4586 memcpy_toio(to_dp, uaddr, len);
4588 /* Tell card we have data for it */
4589 writew(0, vaddr + (DOWNREQ));
4591 brd->conc_dl_status = NO_PENDING_CONCENTRATOR_REQUESTS;
4595 #define EXPANSION_ROM_SIZE (64 * 1024)
4596 #define FEP5_ROM_MAGIC (0xFEFFFFFF)
4598 static void dgap_get_vpd(struct board_t *brd)
4610 * Poke the magic number at the PCI Rom Address location.
4611 * If VPD is supported, the value read from that address
4614 magic = FEP5_ROM_MAGIC;
4615 pci_write_config_dword(brd->pdev, PCI_ROM_ADDRESS, magic);
4616 pci_read_config_dword(brd->pdev, PCI_ROM_ADDRESS, &magic);
4618 /* VPD not supported, bail */
4623 * To get to the OTPROM memory, we have to send the boards base
4624 * address or'ed with 1 into the PCI Rom Address location.
4626 magic = brd->membase | 0x01;
4627 pci_write_config_dword(brd->pdev, PCI_ROM_ADDRESS, magic);
4628 pci_read_config_dword(brd->pdev, PCI_ROM_ADDRESS, &magic);
4630 byte1 = readb(brd->re_map_membase);
4631 byte2 = readb(brd->re_map_membase + 1);
4634 * If the board correctly swapped to the OTPROM memory,
4635 * the first 2 bytes (header) should be 0x55, 0xAA
4637 if (byte1 == 0x55 && byte2 == 0xAA) {
4642 * We have to run through all the OTPROM memory looking
4643 * for the VPD offset.
4645 while (base_offset <= EXPANSION_ROM_SIZE) {
4648 * Lots of magic numbers here.
4650 * The VPD offset is located inside the ROM Data
4653 * We also have to remember the length of each
4654 * ROM Data Structure, so we can "hop" to the next
4655 * entry if the VPD isn't in the current
4656 * ROM Data Structure.
4658 rom_offset = readw(brd->re_map_membase +
4659 base_offset + 0x18);
4660 image_length = readw(brd->re_map_membase +
4661 rom_offset + 0x10) * 512;
4662 vpd_offset = readw(brd->re_map_membase +
4665 /* Found the VPD entry */
4669 /* We didn't find a VPD entry, go to next ROM entry. */
4670 base_offset += image_length;
4672 byte1 = readb(brd->re_map_membase + base_offset);
4673 byte2 = readb(brd->re_map_membase + base_offset + 1);
4676 * If the new ROM offset doesn't have 0x55, 0xAA
4677 * as its header, we have run out of ROM.
4679 if (byte1 != 0x55 || byte2 != 0xAA)
4684 * If we have a VPD offset, then mark the board
4685 * as having a valid VPD, and copy VPDSIZE (512) bytes of
4686 * that VPD to the buffer we have in our board structure.
4689 brd->bd_flags |= BD_HAS_VPD;
4690 for (i = 0; i < VPDSIZE; i++) {
4691 brd->vpd[i] = readb(brd->re_map_membase +
4698 * We MUST poke the magic number at the PCI Rom Address location again.
4699 * This makes the card report the regular board memory back to us,
4700 * rather than the OTPROM memory.
4702 magic = FEP5_ROM_MAGIC;
4703 pci_write_config_dword(brd->pdev, PCI_ROM_ADDRESS, magic);
4707 * Our board poller function.
4709 static void dgap_poll_tasklet(unsigned long data)
4711 struct board_t *bd = (struct board_t *) data;
4717 if (!bd || (bd->magic != DGAP_BOARD_MAGIC))
4720 if (bd->inhibit_poller)
4723 DGAP_LOCK(bd->bd_lock, lock_flags);
4725 vaddr = bd->re_map_membase;
4728 * If board is ready, parse deeper to see if there is anything to do.
4730 if (bd->state == BOARD_READY) {
4732 struct ev_t *eaddr = NULL;
4734 if (!bd->re_map_membase) {
4735 DGAP_UNLOCK(bd->bd_lock, lock_flags);
4738 if (!bd->re_map_port) {
4739 DGAP_UNLOCK(bd->bd_lock, lock_flags);
4746 eaddr = (struct ev_t *) (vaddr + EVBUF);
4748 /* Get our head and tail */
4749 head = readw(&(eaddr->ev_head));
4750 tail = readw(&(eaddr->ev_tail));
4753 * If there is an event pending. Go service it.
4756 DGAP_UNLOCK(bd->bd_lock, lock_flags);
4758 DGAP_LOCK(bd->bd_lock, lock_flags);
4763 * If board is doing interrupts, ACK the interrupt.
4765 if (bd && bd->intr_running)
4766 readb(bd->re_map_port + 2);
4768 DGAP_UNLOCK(bd->bd_lock, lock_flags);
4772 /* Our state machine to get the board up and running */
4775 if (bd->state == NEED_RESET) {
4780 dgap_do_reset_board(bd);
4783 /* Move to next state */
4784 if (bd->state == FINISHED_RESET)
4785 bd->state = NEED_CONFIG;
4787 if (bd->state == NEED_CONFIG) {
4789 * Match this board to a config the user created for us.
4791 bd->bd_config = dgap_find_config(bd->type, bd->pci_bus,
4795 * Because the 4 port Xr products share the same PCI ID
4796 * as the 8 port Xr products, if we receive a NULL config
4797 * back, and this is a PAPORT8 board, retry with a
4798 * PAPORT4 attempt as well.
4800 if (bd->type == PAPORT8 && !bd->bd_config)
4801 bd->bd_config = dgap_find_config(PAPORT4, bd->pci_bus,
4805 * Register the ttys (if any) into the kernel.
4808 bd->state = FINISHED_CONFIG;
4810 bd->state = CONFIG_NOT_FOUND;
4813 /* Move to next state */
4814 if (bd->state == FINISHED_CONFIG)
4815 bd->state = NEED_DEVICE_CREATION;
4817 /* Move to next state */
4818 if (bd->state == NEED_DEVICE_CREATION) {
4820 * Signal downloader, its got some work to do.
4822 DGAP_LOCK(dgap_dl_lock, lock_flags2);
4823 if (dgap_dl_action != 1) {
4825 wake_up_interruptible(&dgap_dl_wait);
4827 DGAP_UNLOCK(dgap_dl_lock, lock_flags2);
4830 /* Move to next state */
4831 if (bd->state == FINISHED_DEVICE_CREATION)
4832 bd->state = NEED_BIOS_LOAD;
4834 /* Move to next state */
4835 if (bd->state == NEED_BIOS_LOAD) {
4837 * Signal downloader, its got some work to do.
4839 DGAP_LOCK(dgap_dl_lock, lock_flags2);
4840 if (dgap_dl_action != 1) {
4842 wake_up_interruptible(&dgap_dl_wait);
4844 DGAP_UNLOCK(dgap_dl_lock, lock_flags2);
4847 /* Wait for BIOS to test board... */
4848 if (bd->state == WAIT_BIOS_LOAD)
4849 dgap_do_wait_for_bios(bd);
4851 /* Move to next state */
4852 if (bd->state == FINISHED_BIOS_LOAD) {
4853 bd->state = NEED_FEP_LOAD;
4856 * Signal downloader, its got some work to do.
4858 DGAP_LOCK(dgap_dl_lock, lock_flags2);
4859 if (dgap_dl_action != 1) {
4861 wake_up_interruptible(&dgap_dl_wait);
4863 DGAP_UNLOCK(dgap_dl_lock, lock_flags2);
4866 /* Wait for FEP to load on board... */
4867 if (bd->state == WAIT_FEP_LOAD)
4868 dgap_do_wait_for_fep(bd);
4870 /* Move to next state */
4871 if (bd->state == FINISHED_FEP_LOAD) {
4874 * Do tty device initialization.
4876 int rc = dgap_tty_init(bd);
4879 dgap_tty_uninit(bd);
4880 bd->state = BOARD_FAILED;
4881 bd->dpastatus = BD_NOFEP;
4883 bd->state = NEED_PROC_CREATION;
4886 * Signal downloader, its got some work to do.
4888 DGAP_LOCK(dgap_dl_lock, lock_flags2);
4889 if (dgap_dl_action != 1) {
4891 wake_up_interruptible(&dgap_dl_wait);
4893 DGAP_UNLOCK(dgap_dl_lock, lock_flags2);
4897 /* Move to next state */
4898 if (bd->state == FINISHED_PROC_CREATION) {
4900 bd->state = BOARD_READY;
4901 bd->dpastatus = BD_RUNNING;
4904 * If user requested the board to run in interrupt mode,
4905 * go and set it up on the board.
4907 if (bd->intr_used) {
4908 writew(1, (bd->re_map_membase + ENABLE_INTR));
4910 * Tell the board to poll the UARTS as fast as possible.
4912 writew(FEPPOLL_MIN, (bd->re_map_membase + FEPPOLL));
4913 bd->intr_running = 1;
4916 /* Wake up anyone waiting for board state to change to ready */
4917 wake_up_interruptible(&bd->state_wait);
4920 DGAP_UNLOCK(bd->bd_lock, lock_flags);
4923 /*=======================================================================
4925 * dgap_cmdb - Sends a 2 byte command to the FEP.
4927 * ch - Pointer to channel structure.
4928 * cmd - Command to be sent.
4929 * byte1 - Integer containing first byte to be sent.
4930 * byte2 - Integer containing second byte to be sent.
4931 * ncmds - Wait until ncmds or fewer cmds are left
4932 * in the cmd buffer before returning.
4934 *=======================================================================*/
4935 static void dgap_cmdb(struct channel_t *ch, uchar cmd, uchar byte1,
4936 uchar byte2, uint ncmds)
4939 struct cm_t *cm_addr = NULL;
4945 if (!ch || ch->magic != DGAP_CHANNEL_MAGIC)
4949 * Check if board is still alive.
4951 if (ch->ch_bd->state == BOARD_FAILED)
4955 * Make sure the pointers are in range before
4956 * writing to the FEP memory.
4958 vaddr = ch->ch_bd->re_map_membase;
4963 cm_addr = (struct cm_t *) (vaddr + CMDBUF);
4964 head = readw(&(cm_addr->cm_head));
4967 * Forget it if pointers out of range.
4969 if (head >= (CMDMAX - CMDSTART) || (head & 03)) {
4970 ch->ch_bd->state = BOARD_FAILED;
4975 * Put the data in the circular command buffer.
4977 writeb(cmd, (char *) (vaddr + head + CMDSTART + 0));
4978 writeb((uchar) ch->ch_portnum, (char *) (vaddr + head + CMDSTART + 1));
4979 writeb(byte1, (char *) (vaddr + head + CMDSTART + 2));
4980 writeb(byte2, (char *) (vaddr + head + CMDSTART + 3));
4982 head = (head + 4) & (CMDMAX - CMDSTART - 4);
4984 writew(head, &(cm_addr->cm_head));
4987 * Wait if necessary before updating the head
4988 * pointer to limit the number of outstanding
4989 * commands to the FEP. If the time spent waiting
4990 * is outlandish, declare the FEP dead.
4992 for (count = dgap_count ;;) {
4994 head = readw(&(cm_addr->cm_head));
4995 tail = readw(&(cm_addr->cm_tail));
4997 n = (head - tail) & (CMDMAX - CMDSTART - 4);
4999 if (n <= ncmds * sizeof(struct cm_t))
5003 ch->ch_bd->state = BOARD_FAILED;
5010 /*=======================================================================
5012 * dgap_cmdw - Sends a 1 word command to the FEP.
5014 * ch - Pointer to channel structure.
5015 * cmd - Command to be sent.
5016 * word - Integer containing word to be sent.
5017 * ncmds - Wait until ncmds or fewer cmds are left
5018 * in the cmd buffer before returning.
5020 *=======================================================================*/
5021 static void dgap_cmdw(struct channel_t *ch, uchar cmd, u16 word, uint ncmds)
5024 struct cm_t *cm_addr = NULL;
5030 if (!ch || ch->magic != DGAP_CHANNEL_MAGIC)
5034 * Check if board is still alive.
5036 if (ch->ch_bd->state == BOARD_FAILED)
5040 * Make sure the pointers are in range before
5041 * writing to the FEP memory.
5043 vaddr = ch->ch_bd->re_map_membase;
5047 cm_addr = (struct cm_t *) (vaddr + CMDBUF);
5048 head = readw(&(cm_addr->cm_head));
5051 * Forget it if pointers out of range.
5053 if (head >= (CMDMAX - CMDSTART) || (head & 03)) {
5054 ch->ch_bd->state = BOARD_FAILED;
5059 * Put the data in the circular command buffer.
5061 writeb(cmd, (char *) (vaddr + head + CMDSTART + 0));
5062 writeb((uchar) ch->ch_portnum, (char *) (vaddr + head + CMDSTART + 1));
5063 writew((u16) word, (char *) (vaddr + head + CMDSTART + 2));
5065 head = (head + 4) & (CMDMAX - CMDSTART - 4);
5067 writew(head, &(cm_addr->cm_head));
5070 * Wait if necessary before updating the head
5071 * pointer to limit the number of outstanding
5072 * commands to the FEP. If the time spent waiting
5073 * is outlandish, declare the FEP dead.
5075 for (count = dgap_count ;;) {
5077 head = readw(&(cm_addr->cm_head));
5078 tail = readw(&(cm_addr->cm_tail));
5080 n = (head - tail) & (CMDMAX - CMDSTART - 4);
5082 if (n <= ncmds * sizeof(struct cm_t))
5086 ch->ch_bd->state = BOARD_FAILED;
5093 /*=======================================================================
5095 * dgap_cmdw_ext - Sends a extended word command to the FEP.
5097 * ch - Pointer to channel structure.
5098 * cmd - Command to be sent.
5099 * word - Integer containing word to be sent.
5100 * ncmds - Wait until ncmds or fewer cmds are left
5101 * in the cmd buffer before returning.
5103 *=======================================================================*/
5104 static void dgap_cmdw_ext(struct channel_t *ch, u16 cmd, u16 word, uint ncmds)
5107 struct cm_t *cm_addr = NULL;
5113 if (!ch || ch->magic != DGAP_CHANNEL_MAGIC)
5117 * Check if board is still alive.
5119 if (ch->ch_bd->state == BOARD_FAILED)
5123 * Make sure the pointers are in range before
5124 * writing to the FEP memory.
5126 vaddr = ch->ch_bd->re_map_membase;
5130 cm_addr = (struct cm_t *) (vaddr + CMDBUF);
5131 head = readw(&(cm_addr->cm_head));
5134 * Forget it if pointers out of range.
5136 if (head >= (CMDMAX - CMDSTART) || (head & 03)) {
5137 ch->ch_bd->state = BOARD_FAILED;
5142 * Put the data in the circular command buffer.
5145 /* Write an FF to tell the FEP that we want an extended command */
5146 writeb((uchar) 0xff, (char *) (vaddr + head + CMDSTART + 0));
5148 writeb((uchar) ch->ch_portnum, (uchar *) (vaddr + head + CMDSTART + 1));
5149 writew((u16) cmd, (char *) (vaddr + head + CMDSTART + 2));
5152 * If the second part of the command won't fit,
5153 * put it at the beginning of the circular buffer.
5155 if (((head + 4) >= ((CMDMAX - CMDSTART)) || (head & 03)))
5156 writew((u16) word, (char *) (vaddr + CMDSTART));
5158 writew((u16) word, (char *) (vaddr + head + CMDSTART + 4));
5160 head = (head + 8) & (CMDMAX - CMDSTART - 4);
5162 writew(head, &(cm_addr->cm_head));
5165 * Wait if necessary before updating the head
5166 * pointer to limit the number of outstanding
5167 * commands to the FEP. If the time spent waiting
5168 * is outlandish, declare the FEP dead.
5170 for (count = dgap_count ;;) {
5172 head = readw(&(cm_addr->cm_head));
5173 tail = readw(&(cm_addr->cm_tail));
5175 n = (head - tail) & (CMDMAX - CMDSTART - 4);
5177 if (n <= ncmds * sizeof(struct cm_t))
5181 ch->ch_bd->state = BOARD_FAILED;
5188 /*=======================================================================
5190 * dgap_wmove - Write data to FEP buffer.
5192 * ch - Pointer to channel structure.
5193 * buf - Poiter to characters to be moved.
5194 * cnt - Number of characters to move.
5196 *=======================================================================*/
5197 static void dgap_wmove(struct channel_t *ch, char *buf, uint cnt)
5204 if (!ch || ch->magic != DGAP_CHANNEL_MAGIC)
5211 head = readw(&(bs->tx_head));
5214 * If pointers are out of range, just return.
5216 if ((cnt > ch->ch_tsize) ||
5217 (unsigned)(head - ch->ch_tstart) >= ch->ch_tsize)
5221 * If the write wraps over the top of the circular buffer,
5222 * move the portion up to the wrap point, and reset the
5223 * pointers to the bottom.
5225 n = ch->ch_tstart + ch->ch_tsize - head;
5229 taddr = ch->ch_taddr + head;
5230 memcpy_toio(taddr, buf, n);
5231 head = ch->ch_tstart;
5236 * Move rest of data.
5238 taddr = ch->ch_taddr + head;
5240 memcpy_toio(taddr, buf, n);
5243 writew(head, &(bs->tx_head));
5247 * Retrives the current custom baud rate from FEP memory,
5248 * and returns it back to the user.
5249 * Returns 0 on error.
5251 static uint dgap_get_custom_baud(struct channel_t *ch)
5257 if (!ch || ch->magic != DGAP_CHANNEL_MAGIC)
5260 if (!ch->ch_bd || ch->ch_bd->magic != DGAP_BOARD_MAGIC)
5263 if (!(ch->ch_bd->bd_flags & BD_FEP5PLUS))
5266 vaddr = ch->ch_bd->re_map_membase;
5272 * Go get from fep mem, what the fep
5273 * believes the custom baud rate is.
5275 offset = ((((*(unsigned short *)(vaddr + ECS_SEG)) << 4) +
5276 (ch->ch_portnum * 0x28) + LINE_SPEED));
5278 value = readw(vaddr + offset);
5283 * Calls the firmware to reset this channel.
5285 static void dgap_firmware_reset_port(struct channel_t *ch)
5287 dgap_cmdb(ch, CHRESET, 0, 0, 0);
5290 * Now that the channel is reset, we need to make sure
5291 * all the current settings get reapplied to the port
5294 * So we will set the driver's cache of firmware
5295 * settings all to 0, and then call param.
5297 ch->ch_fepiflag = 0;
5298 ch->ch_fepcflag = 0;
5299 ch->ch_fepoflag = 0;
5300 ch->ch_fepstartc = 0;
5301 ch->ch_fepstopc = 0;
5302 ch->ch_fepastartc = 0;
5303 ch->ch_fepastopc = 0;
5308 /*=======================================================================
5310 * dgap_param - Set Digi parameters.
5312 * struct tty_struct * - TTY for port.
5314 *=======================================================================*/
5315 static int dgap_param(struct tty_struct *tty)
5317 struct ktermios *ts;
5319 struct channel_t *ch;
5328 if (!tty || tty->magic != TTY_MAGIC)
5331 un = (struct un_t *) tty->driver_data;
5332 if (!un || un->magic != DGAP_UNIT_MAGIC)
5336 if (!ch || ch->magic != DGAP_CHANNEL_MAGIC)
5340 if (!bd || bd->magic != DGAP_BOARD_MAGIC)
5350 * If baud rate is zero, flush queues, and set mval to drop DTR.
5352 if ((ch->ch_c_cflag & (CBAUD)) == 0) {
5355 head = readw(&(ch->ch_bs->rx_head));
5356 writew(head, &(ch->ch_bs->rx_tail));
5359 head = readw(&(ch->ch_bs->tx_head));
5360 writew(head, &(ch->ch_bs->tx_tail));
5362 ch->ch_flags |= (CH_BAUD0);
5364 /* Drop RTS and DTR */
5365 ch->ch_mval &= ~(D_RTS(ch)|D_DTR(ch));
5366 mval = D_DTR(ch) | D_RTS(ch);
5367 ch->ch_baud_info = 0;
5369 } else if (ch->ch_custom_speed && (bd->bd_flags & BD_FEP5PLUS)) {
5371 * Tell the fep to do the command
5374 dgap_cmdw_ext(ch, 0xff01, ch->ch_custom_speed, 0);
5377 * Now go get from fep mem, what the fep
5378 * believes the custom baud rate is.
5380 ch->ch_custom_speed = dgap_get_custom_baud(ch);
5381 ch->ch_baud_info = ch->ch_custom_speed;
5383 /* Handle transition from B0 */
5384 if (ch->ch_flags & CH_BAUD0) {
5385 ch->ch_flags &= ~(CH_BAUD0);
5386 ch->ch_mval |= (D_RTS(ch)|D_DTR(ch));
5388 mval = D_DTR(ch) | D_RTS(ch);
5392 * Set baud rate, character size, and parity.
5400 ulong bauds[4][16] = {
5404 600, 1200, 1800, 2400,
5405 4800, 9600, 19200, 38400 },
5406 { /* slowbaud & CBAUDEX */
5407 0, 57600, 115200, 230400,
5408 460800, 150, 200, 921600,
5409 600, 1200, 1800, 2400,
5410 4800, 9600, 19200, 38400 },
5412 0, 57600, 76800, 115200,
5413 14400, 57600, 230400, 76800,
5414 115200, 230400, 28800, 460800,
5415 921600, 9600, 19200, 38400 },
5416 { /* fastbaud & CBAUDEX */
5417 0, 57600, 115200, 230400,
5418 460800, 150, 200, 921600,
5419 600, 1200, 1800, 2400,
5420 4800, 9600, 19200, 38400 }
5424 * Only use the TXPrint baud rate if the
5425 * terminal unit is NOT open
5427 if (!(ch->ch_tun.un_flags & UN_ISOPEN) &&
5428 (un->un_type == DGAP_PRINT))
5429 baud = C_BAUD(ch->ch_pun.un_tty) & 0xff;
5431 baud = C_BAUD(ch->ch_tun.un_tty) & 0xff;
5433 if (ch->ch_c_cflag & CBAUDEX)
5436 if (ch->ch_digi.digi_flags & DIGI_FAST)
5441 if ((iindex >= 0) && (iindex < 4) &&
5442 (jindex >= 0) && (jindex < 16))
5443 baud = bauds[iindex][jindex];
5450 ch->ch_baud_info = baud;
5453 * CBAUD has bit position 0x1000 set these days to
5454 * indicate Linux baud rate remap.
5455 * We use a different bit assignment for high speed.
5456 * Clear this bit out while grabbing the parts of
5459 cflag = ch->ch_c_cflag & ((CBAUD ^ CBAUDEX) | PARODD | PARENB |
5463 * HUPCL bit is used by FEP to indicate fast baud
5464 * table is to be used.
5466 if ((ch->ch_digi.digi_flags & DIGI_FAST) ||
5467 (ch->ch_c_cflag & CBAUDEX))
5470 if ((ch->ch_c_cflag & CBAUDEX) &&
5471 !(ch->ch_digi.digi_flags & DIGI_FAST)) {
5473 * The below code is trying to guarantee that only
5474 * baud rates 115200, 230400, 460800, 921600 are
5475 * remapped. We use exclusive or because the various
5476 * baud rates share common bit positions and therefore
5477 * can't be tested for easily.
5479 tcflag_t tcflag = (ch->ch_c_cflag & CBAUD) | CBAUDEX;
5483 * Map high speed requests to index
5484 * into FEP's baud table
5514 cflag = (cflag & ~(CBAUD | CBAUDEX)) | baudpart;
5519 if (cflag != ch->ch_fepcflag) {
5520 ch->ch_fepcflag = (u16) (cflag & 0xffff);
5523 * Okay to have channel and board
5524 * locks held calling this
5526 dgap_cmdw(ch, SCFLAG, (u16) cflag, 0);
5529 /* Handle transition from B0 */
5530 if (ch->ch_flags & CH_BAUD0) {
5531 ch->ch_flags &= ~(CH_BAUD0);
5532 ch->ch_mval |= (D_RTS(ch)|D_DTR(ch));
5534 mval = D_DTR(ch) | D_RTS(ch);
5540 iflag = ch->ch_c_iflag & (IGNBRK | BRKINT | IGNPAR | PARMRK |
5541 INPCK | ISTRIP | IXON | IXANY | IXOFF);
5543 if ((ch->ch_startc == _POSIX_VDISABLE) ||
5544 (ch->ch_stopc == _POSIX_VDISABLE)) {
5545 iflag &= ~(IXON | IXOFF);
5546 ch->ch_c_iflag &= ~(IXON | IXOFF);
5550 * Only the IBM Xr card can switch between
5551 * 232 and 422 modes on the fly
5553 if (bd->device == PCI_DEV_XR_IBM_DID) {
5554 if (ch->ch_digi.digi_flags & DIGI_422)
5555 dgap_cmdb(ch, SCOMMODE, MODE_422, 0, 0);
5557 dgap_cmdb(ch, SCOMMODE, MODE_232, 0, 0);
5560 if (ch->ch_digi.digi_flags & DIGI_ALTPIN)
5563 if (iflag != ch->ch_fepiflag) {
5564 ch->ch_fepiflag = iflag;
5566 /* Okay to have channel and board locks held calling this */
5567 dgap_cmdw(ch, SIFLAG, (u16) ch->ch_fepiflag, 0);
5571 * Select hardware handshaking.
5575 if (ch->ch_c_cflag & CRTSCTS)
5576 hflow |= (D_RTS(ch) | D_CTS(ch));
5577 if (ch->ch_digi.digi_flags & RTSPACE)
5579 if (ch->ch_digi.digi_flags & DTRPACE)
5581 if (ch->ch_digi.digi_flags & CTSPACE)
5583 if (ch->ch_digi.digi_flags & DSRPACE)
5585 if (ch->ch_digi.digi_flags & DCDPACE)
5588 if (hflow != ch->ch_hflow) {
5589 ch->ch_hflow = hflow;
5591 /* Okay to have channel and board locks held calling this */
5592 dgap_cmdb(ch, SHFLOW, (uchar) hflow, 0xff, 0);
5597 * Set RTS and/or DTR Toggle if needed,
5598 * but only if product is FEP5+ based.
5600 if (bd->bd_flags & BD_FEP5PLUS) {
5602 if (ch->ch_digi.digi_flags & DIGI_RTS_TOGGLE)
5603 hflow2 |= (D_RTS(ch));
5604 if (ch->ch_digi.digi_flags & DIGI_DTR_TOGGLE)
5605 hflow2 |= (D_DTR(ch));
5607 dgap_cmdw_ext(ch, 0xff03, hflow2, 0);
5611 * Set modem control lines.
5614 mval ^= ch->ch_mforce & (mval ^ ch->ch_mval);
5616 if (ch->ch_mostat ^ mval) {
5617 ch->ch_mostat = mval;
5619 /* Okay to have channel and board locks held calling this */
5620 dgap_cmdb(ch, SMODEM, (uchar) mval, D_RTS(ch)|D_DTR(ch), 0);
5624 * Read modem signals, and then call carrier function.
5626 ch->ch_mistat = readb(&(bs->m_stat));
5630 * Set the start and stop characters.
5632 if (ch->ch_startc != ch->ch_fepstartc ||
5633 ch->ch_stopc != ch->ch_fepstopc) {
5634 ch->ch_fepstartc = ch->ch_startc;
5635 ch->ch_fepstopc = ch->ch_stopc;
5637 /* Okay to have channel and board locks held calling this */
5638 dgap_cmdb(ch, SFLOWC, ch->ch_fepstartc, ch->ch_fepstopc, 0);
5642 * Set the Auxiliary start and stop characters.
5644 if (ch->ch_astartc != ch->ch_fepastartc ||
5645 ch->ch_astopc != ch->ch_fepastopc) {
5646 ch->ch_fepastartc = ch->ch_astartc;
5647 ch->ch_fepastopc = ch->ch_astopc;
5649 /* Okay to have channel and board locks held calling this */
5650 dgap_cmdb(ch, SAFLOWC, ch->ch_fepastartc, ch->ch_fepastopc, 0);
5657 * dgap_parity_scan()
5659 * Convert the FEP5 way of reporting parity errors and breaks into
5660 * the Linux line discipline way.
5662 static void dgap_parity_scan(struct channel_t *ch, unsigned char *cbuf,
5663 unsigned char *fbuf, int *len)
5667 unsigned char *in, *cout, *fout;
5674 if (!ch || ch->magic != DGAP_CHANNEL_MAGIC)
5679 switch (ch->pscan_state) {
5681 /* reset to sanity and fall through */
5682 ch->pscan_state = 0;
5685 /* No FF seen yet */
5686 if (c == (unsigned char) '\377')
5687 /* delete this character from stream */
5688 ch->pscan_state = 1;
5691 *fout++ = TTY_NORMAL;
5698 if (c == (unsigned char) '\377') {
5699 /* doubled ff, transform to single ff */
5701 *fout++ = TTY_NORMAL;
5703 ch->pscan_state = 0;
5705 /* save value examination in next state */
5706 ch->pscan_savechar = c;
5707 ch->pscan_state = 2;
5712 /* third character of ff sequence */
5716 if (ch->pscan_savechar == 0x0) {
5720 *fout++ = TTY_BREAK;
5722 ch->ch_err_parity++;
5723 *fout++ = TTY_PARITY;
5728 ch->pscan_state = 0;
5734 /*=======================================================================
5736 * dgap_event - FEP to host event processing routine.
5738 * bd - Board of current event.
5740 *=======================================================================*/
5741 static int dgap_event(struct board_t *bd)
5743 struct channel_t *ch;
5748 uchar *vaddr = NULL;
5749 struct ev_t *eaddr = NULL;
5757 if (!bd || bd->magic != DGAP_BOARD_MAGIC)
5760 DGAP_LOCK(bd->bd_lock, lock_flags);
5762 vaddr = bd->re_map_membase;
5765 DGAP_UNLOCK(bd->bd_lock, lock_flags);
5769 eaddr = (struct ev_t *) (vaddr + EVBUF);
5771 /* Get our head and tail */
5772 head = readw(&(eaddr->ev_head));
5773 tail = readw(&(eaddr->ev_tail));
5776 * Forget it if pointers out of range.
5779 if (head >= EVMAX - EVSTART || tail >= EVMAX - EVSTART ||
5780 (head | tail) & 03) {
5781 /* Let go of board lock */
5782 DGAP_UNLOCK(bd->bd_lock, lock_flags);
5787 * Loop to process all the events in the buffer.
5789 while (tail != head) {
5792 * Get interrupt information.
5795 event = bd->re_map_membase + tail + EVSTART;
5803 * Make sure the interrupt is valid.
5805 if (port >= bd->nasync)
5808 if (!(reason & (IFMODEM | IFBREAK | IFTLW | IFTEM | IFDATA)))
5811 ch = bd->channels[port];
5813 if (!ch || ch->magic != DGAP_CHANNEL_MAGIC)
5817 * If we have made it here, the event was valid.
5818 * Lock down the channel.
5820 DGAP_LOCK(ch->ch_lock, lock_flags2);
5825 DGAP_UNLOCK(ch->ch_lock, lock_flags2);
5830 * Process received data.
5832 if (reason & IFDATA) {
5835 * ALL LOCKS *MUST* BE DROPPED BEFORE CALLING INPUT!
5836 * input could send some data to ld, which in turn
5837 * could do a callback to one of our other functions.
5839 DGAP_UNLOCK(ch->ch_lock, lock_flags2);
5840 DGAP_UNLOCK(bd->bd_lock, lock_flags);
5844 DGAP_LOCK(bd->bd_lock, lock_flags);
5845 DGAP_LOCK(ch->ch_lock, lock_flags2);
5847 if (ch->ch_flags & CH_RACTIVE)
5848 ch->ch_flags |= CH_RENABLE;
5850 writeb(1, &(bs->idata));
5852 if (ch->ch_flags & CH_RWAIT) {
5853 ch->ch_flags &= ~CH_RWAIT;
5855 wake_up_interruptible(&ch->ch_tun.un_flags_wait);
5860 * Process Modem change signals.
5862 if (reason & IFMODEM) {
5863 ch->ch_mistat = modem;
5870 if (reason & IFBREAK) {
5872 if (ch->ch_tun.un_tty) {
5873 /* A break has been indicated */
5875 tty_buffer_request_room(ch->ch_tun.un_tty->port, 1);
5876 tty_insert_flip_char(ch->ch_tun.un_tty->port, 0, TTY_BREAK);
5877 tty_flip_buffer_push(ch->ch_tun.un_tty->port);
5882 * Process Transmit low.
5884 if (reason & IFTLW) {
5886 if (ch->ch_tun.un_flags & UN_LOW) {
5887 ch->ch_tun.un_flags &= ~UN_LOW;
5889 if (ch->ch_tun.un_flags & UN_ISOPEN) {
5890 if ((ch->ch_tun.un_tty->flags &
5891 (1 << TTY_DO_WRITE_WAKEUP)) &&
5892 ch->ch_tun.un_tty->ldisc->ops->write_wakeup) {
5893 DGAP_UNLOCK(ch->ch_lock, lock_flags2);
5894 DGAP_UNLOCK(bd->bd_lock, lock_flags);
5895 (ch->ch_tun.un_tty->ldisc->ops->write_wakeup)(ch->ch_tun.un_tty);
5896 DGAP_LOCK(bd->bd_lock, lock_flags);
5897 DGAP_LOCK(ch->ch_lock, lock_flags2);
5899 wake_up_interruptible(&ch->ch_tun.un_tty->write_wait);
5900 wake_up_interruptible(&ch->ch_tun.un_flags_wait);
5904 if (ch->ch_pun.un_flags & UN_LOW) {
5905 ch->ch_pun.un_flags &= ~UN_LOW;
5906 if (ch->ch_pun.un_flags & UN_ISOPEN) {
5907 if ((ch->ch_pun.un_tty->flags &
5908 (1 << TTY_DO_WRITE_WAKEUP)) &&
5909 ch->ch_pun.un_tty->ldisc->ops->write_wakeup) {
5910 DGAP_UNLOCK(ch->ch_lock, lock_flags2);
5911 DGAP_UNLOCK(bd->bd_lock, lock_flags);
5912 (ch->ch_pun.un_tty->ldisc->ops->write_wakeup)(ch->ch_pun.un_tty);
5913 DGAP_LOCK(bd->bd_lock, lock_flags);
5914 DGAP_LOCK(ch->ch_lock, lock_flags2);
5916 wake_up_interruptible(&ch->ch_pun.un_tty->write_wait);
5917 wake_up_interruptible(&ch->ch_pun.un_flags_wait);
5921 if (ch->ch_flags & CH_WLOW) {
5922 ch->ch_flags &= ~CH_WLOW;
5923 wake_up_interruptible(&ch->ch_flags_wait);
5928 * Process Transmit empty.
5930 if (reason & IFTEM) {
5931 if (ch->ch_tun.un_flags & UN_EMPTY) {
5932 ch->ch_tun.un_flags &= ~UN_EMPTY;
5933 if (ch->ch_tun.un_flags & UN_ISOPEN) {
5934 if ((ch->ch_tun.un_tty->flags &
5935 (1 << TTY_DO_WRITE_WAKEUP)) &&
5936 ch->ch_tun.un_tty->ldisc->ops->write_wakeup) {
5937 DGAP_UNLOCK(ch->ch_lock, lock_flags2);
5938 DGAP_UNLOCK(bd->bd_lock, lock_flags);
5940 (ch->ch_tun.un_tty->ldisc->ops->write_wakeup)(ch->ch_tun.un_tty);
5941 DGAP_LOCK(bd->bd_lock, lock_flags);
5942 DGAP_LOCK(ch->ch_lock, lock_flags2);
5944 wake_up_interruptible(&ch->ch_tun.un_tty->write_wait);
5945 wake_up_interruptible(&ch->ch_tun.un_flags_wait);
5949 if (ch->ch_pun.un_flags & UN_EMPTY) {
5950 ch->ch_pun.un_flags &= ~UN_EMPTY;
5951 if (ch->ch_pun.un_flags & UN_ISOPEN) {
5952 if ((ch->ch_pun.un_tty->flags &
5953 (1 << TTY_DO_WRITE_WAKEUP)) &&
5954 ch->ch_pun.un_tty->ldisc->ops->write_wakeup) {
5955 DGAP_UNLOCK(ch->ch_lock, lock_flags2);
5956 DGAP_UNLOCK(bd->bd_lock, lock_flags);
5957 (ch->ch_pun.un_tty->ldisc->ops->write_wakeup)(ch->ch_pun.un_tty);
5958 DGAP_LOCK(bd->bd_lock, lock_flags);
5959 DGAP_LOCK(ch->ch_lock, lock_flags2);
5961 wake_up_interruptible(&ch->ch_pun.un_tty->write_wait);
5962 wake_up_interruptible(&ch->ch_pun.un_flags_wait);
5967 if (ch->ch_flags & CH_WEMPTY) {
5968 ch->ch_flags &= ~CH_WEMPTY;
5969 wake_up_interruptible(&ch->ch_flags_wait);
5973 DGAP_UNLOCK(ch->ch_lock, lock_flags2);
5976 tail = (tail + 4) & (EVMAX - EVSTART - 4);
5979 writew(tail, &(eaddr->ev_tail));
5980 DGAP_UNLOCK(bd->bd_lock, lock_flags);
5985 static ssize_t dgap_driver_version_show(struct device_driver *ddp, char *buf)
5987 return snprintf(buf, PAGE_SIZE, "%s\n", DG_PART);
5989 static DRIVER_ATTR(version, S_IRUSR, dgap_driver_version_show, NULL);
5992 static ssize_t dgap_driver_boards_show(struct device_driver *ddp, char *buf)
5994 return snprintf(buf, PAGE_SIZE, "%d\n", dgap_NumBoards);
5996 static DRIVER_ATTR(boards, S_IRUSR, dgap_driver_boards_show, NULL);
5999 static ssize_t dgap_driver_maxboards_show(struct device_driver *ddp, char *buf)
6001 return snprintf(buf, PAGE_SIZE, "%d\n", MAXBOARDS);
6003 static DRIVER_ATTR(maxboards, S_IRUSR, dgap_driver_maxboards_show, NULL);
6006 static ssize_t dgap_driver_pollcounter_show(struct device_driver *ddp, char *buf)
6008 return snprintf(buf, PAGE_SIZE, "%ld\n", dgap_poll_counter);
6010 static DRIVER_ATTR(pollcounter, S_IRUSR, dgap_driver_pollcounter_show, NULL);
6013 static ssize_t dgap_driver_state_show(struct device_driver *ddp, char *buf)
6015 return snprintf(buf, PAGE_SIZE, "%s\n", dgap_driver_state_text[dgap_driver_state]);
6017 static DRIVER_ATTR(state, S_IRUSR, dgap_driver_state_show, NULL);
6019 static ssize_t dgap_driver_pollrate_show(struct device_driver *ddp, char *buf)
6021 return snprintf(buf, PAGE_SIZE, "%dms\n", dgap_poll_tick);
6024 static ssize_t dgap_driver_pollrate_store(struct device_driver *ddp, const char *buf, size_t count)
6026 if (sscanf(buf, "%d\n", &dgap_poll_tick) != 1)
6030 static DRIVER_ATTR(pollrate, (S_IRUSR | S_IWUSR), dgap_driver_pollrate_show, dgap_driver_pollrate_store);
6032 static int dgap_create_driver_sysfiles(struct pci_driver *dgap_driver)
6035 struct device_driver *driverfs = &dgap_driver->driver;
6037 rc |= driver_create_file(driverfs, &driver_attr_version);
6038 rc |= driver_create_file(driverfs, &driver_attr_boards);
6039 rc |= driver_create_file(driverfs, &driver_attr_maxboards);
6040 rc |= driver_create_file(driverfs, &driver_attr_pollrate);
6041 rc |= driver_create_file(driverfs, &driver_attr_pollcounter);
6042 rc |= driver_create_file(driverfs, &driver_attr_state);
6047 static void dgap_remove_driver_sysfiles(struct pci_driver *dgap_driver)
6049 struct device_driver *driverfs = &dgap_driver->driver;
6050 driver_remove_file(driverfs, &driver_attr_version);
6051 driver_remove_file(driverfs, &driver_attr_boards);
6052 driver_remove_file(driverfs, &driver_attr_maxboards);
6053 driver_remove_file(driverfs, &driver_attr_pollrate);
6054 driver_remove_file(driverfs, &driver_attr_pollcounter);
6055 driver_remove_file(driverfs, &driver_attr_state);
6058 static struct board_t *dgap_verify_board(struct device *p)
6065 bd = dev_get_drvdata(p);
6066 if (!bd || bd->magic != DGAP_BOARD_MAGIC || bd->state != BOARD_READY)
6072 static ssize_t dgap_ports_state_show(struct device *p, struct device_attribute *attr, char *buf)
6078 bd = dgap_verify_board(p);
6082 for (i = 0; i < bd->nasync; i++) {
6083 count += snprintf(buf + count, PAGE_SIZE - count,
6084 "%d %s\n", bd->channels[i]->ch_portnum,
6085 bd->channels[i]->ch_open_count ? "Open" : "Closed");
6089 static DEVICE_ATTR(ports_state, S_IRUSR, dgap_ports_state_show, NULL);
6091 static ssize_t dgap_ports_baud_show(struct device *p, struct device_attribute *attr, char *buf)
6097 bd = dgap_verify_board(p);
6101 for (i = 0; i < bd->nasync; i++) {
6102 count += snprintf(buf + count, PAGE_SIZE - count,
6103 "%d %d\n", bd->channels[i]->ch_portnum, bd->channels[i]->ch_baud_info);
6107 static DEVICE_ATTR(ports_baud, S_IRUSR, dgap_ports_baud_show, NULL);
6109 static ssize_t dgap_ports_msignals_show(struct device *p, struct device_attribute *attr, char *buf)
6115 bd = dgap_verify_board(p);
6119 for (i = 0; i < bd->nasync; i++) {
6120 if (bd->channels[i]->ch_open_count)
6121 count += snprintf(buf + count, PAGE_SIZE - count,
6122 "%d %s %s %s %s %s %s\n", bd->channels[i]->ch_portnum,
6123 (bd->channels[i]->ch_mostat & UART_MCR_RTS) ? "RTS" : "",
6124 (bd->channels[i]->ch_mistat & UART_MSR_CTS) ? "CTS" : "",
6125 (bd->channels[i]->ch_mostat & UART_MCR_DTR) ? "DTR" : "",
6126 (bd->channels[i]->ch_mistat & UART_MSR_DSR) ? "DSR" : "",
6127 (bd->channels[i]->ch_mistat & UART_MSR_DCD) ? "DCD" : "",
6128 (bd->channels[i]->ch_mistat & UART_MSR_RI) ? "RI" : "");
6130 count += snprintf(buf + count, PAGE_SIZE - count,
6131 "%d\n", bd->channels[i]->ch_portnum);
6135 static DEVICE_ATTR(ports_msignals, S_IRUSR, dgap_ports_msignals_show, NULL);
6137 static ssize_t dgap_ports_iflag_show(struct device *p, struct device_attribute *attr, char *buf)
6143 bd = dgap_verify_board(p);
6147 for (i = 0; i < bd->nasync; i++)
6148 count += snprintf(buf + count, PAGE_SIZE - count, "%d %x\n",
6149 bd->channels[i]->ch_portnum, bd->channels[i]->ch_c_iflag);
6152 static DEVICE_ATTR(ports_iflag, S_IRUSR, dgap_ports_iflag_show, NULL);
6154 static ssize_t dgap_ports_cflag_show(struct device *p, struct device_attribute *attr, char *buf)
6160 bd = dgap_verify_board(p);
6164 for (i = 0; i < bd->nasync; i++)
6165 count += snprintf(buf + count, PAGE_SIZE - count, "%d %x\n",
6166 bd->channels[i]->ch_portnum, bd->channels[i]->ch_c_cflag);
6169 static DEVICE_ATTR(ports_cflag, S_IRUSR, dgap_ports_cflag_show, NULL);
6171 static ssize_t dgap_ports_oflag_show(struct device *p, struct device_attribute *attr, char *buf)
6177 bd = dgap_verify_board(p);
6181 for (i = 0; i < bd->nasync; i++)
6182 count += snprintf(buf + count, PAGE_SIZE - count, "%d %x\n",
6183 bd->channels[i]->ch_portnum, bd->channels[i]->ch_c_oflag);
6186 static DEVICE_ATTR(ports_oflag, S_IRUSR, dgap_ports_oflag_show, NULL);
6188 static ssize_t dgap_ports_lflag_show(struct device *p, struct device_attribute *attr, char *buf)
6194 bd = dgap_verify_board(p);
6198 for (i = 0; i < bd->nasync; i++)
6199 count += snprintf(buf + count, PAGE_SIZE - count, "%d %x\n",
6200 bd->channels[i]->ch_portnum, bd->channels[i]->ch_c_lflag);
6203 static DEVICE_ATTR(ports_lflag, S_IRUSR, dgap_ports_lflag_show, NULL);
6205 static ssize_t dgap_ports_digi_flag_show(struct device *p, struct device_attribute *attr, char *buf)
6211 bd = dgap_verify_board(p);
6215 for (i = 0; i < bd->nasync; i++)
6216 count += snprintf(buf + count, PAGE_SIZE - count, "%d %x\n",
6217 bd->channels[i]->ch_portnum, bd->channels[i]->ch_digi.digi_flags);
6220 static DEVICE_ATTR(ports_digi_flag, S_IRUSR, dgap_ports_digi_flag_show, NULL);
6222 static ssize_t dgap_ports_rxcount_show(struct device *p, struct device_attribute *attr, char *buf)
6228 bd = dgap_verify_board(p);
6232 for (i = 0; i < bd->nasync; i++)
6233 count += snprintf(buf + count, PAGE_SIZE - count, "%d %ld\n",
6234 bd->channels[i]->ch_portnum, bd->channels[i]->ch_rxcount);
6237 static DEVICE_ATTR(ports_rxcount, S_IRUSR, dgap_ports_rxcount_show, NULL);
6239 static ssize_t dgap_ports_txcount_show(struct device *p, struct device_attribute *attr, char *buf)
6245 bd = dgap_verify_board(p);
6249 for (i = 0; i < bd->nasync; i++)
6250 count += snprintf(buf + count, PAGE_SIZE - count, "%d %ld\n",
6251 bd->channels[i]->ch_portnum, bd->channels[i]->ch_txcount);
6254 static DEVICE_ATTR(ports_txcount, S_IRUSR, dgap_ports_txcount_show, NULL);
6256 /* this function creates the sys files that will export each signal status
6257 * to sysfs each value will be put in a separate filename
6259 static void dgap_create_ports_sysfiles(struct board_t *bd)
6261 dev_set_drvdata(&bd->pdev->dev, bd);
6262 device_create_file(&(bd->pdev->dev), &dev_attr_ports_state);
6263 device_create_file(&(bd->pdev->dev), &dev_attr_ports_baud);
6264 device_create_file(&(bd->pdev->dev), &dev_attr_ports_msignals);
6265 device_create_file(&(bd->pdev->dev), &dev_attr_ports_iflag);
6266 device_create_file(&(bd->pdev->dev), &dev_attr_ports_cflag);
6267 device_create_file(&(bd->pdev->dev), &dev_attr_ports_oflag);
6268 device_create_file(&(bd->pdev->dev), &dev_attr_ports_lflag);
6269 device_create_file(&(bd->pdev->dev), &dev_attr_ports_digi_flag);
6270 device_create_file(&(bd->pdev->dev), &dev_attr_ports_rxcount);
6271 device_create_file(&(bd->pdev->dev), &dev_attr_ports_txcount);
6274 /* removes all the sys files created for that port */
6275 static void dgap_remove_ports_sysfiles(struct board_t *bd)
6277 device_remove_file(&(bd->pdev->dev), &dev_attr_ports_state);
6278 device_remove_file(&(bd->pdev->dev), &dev_attr_ports_baud);
6279 device_remove_file(&(bd->pdev->dev), &dev_attr_ports_msignals);
6280 device_remove_file(&(bd->pdev->dev), &dev_attr_ports_iflag);
6281 device_remove_file(&(bd->pdev->dev), &dev_attr_ports_cflag);
6282 device_remove_file(&(bd->pdev->dev), &dev_attr_ports_oflag);
6283 device_remove_file(&(bd->pdev->dev), &dev_attr_ports_lflag);
6284 device_remove_file(&(bd->pdev->dev), &dev_attr_ports_digi_flag);
6285 device_remove_file(&(bd->pdev->dev), &dev_attr_ports_rxcount);
6286 device_remove_file(&(bd->pdev->dev), &dev_attr_ports_txcount);
6289 static ssize_t dgap_tty_state_show(struct device *d, struct device_attribute *attr, char *buf)
6292 struct channel_t *ch;
6297 un = dev_get_drvdata(d);
6298 if (!un || un->magic != DGAP_UNIT_MAGIC)
6301 if (!ch || ch->magic != DGAP_CHANNEL_MAGIC)
6304 if (!bd || bd->magic != DGAP_BOARD_MAGIC)
6306 if (bd->state != BOARD_READY)
6309 return snprintf(buf, PAGE_SIZE, "%s", un->un_open_count ? "Open" : "Closed");
6311 static DEVICE_ATTR(state, S_IRUSR, dgap_tty_state_show, NULL);
6313 static ssize_t dgap_tty_baud_show(struct device *d, struct device_attribute *attr, char *buf)
6316 struct channel_t *ch;
6321 un = dev_get_drvdata(d);
6322 if (!un || un->magic != DGAP_UNIT_MAGIC)
6325 if (!ch || ch->magic != DGAP_CHANNEL_MAGIC)
6328 if (!bd || bd->magic != DGAP_BOARD_MAGIC)
6330 if (bd->state != BOARD_READY)
6333 return snprintf(buf, PAGE_SIZE, "%d\n", ch->ch_baud_info);
6335 static DEVICE_ATTR(baud, S_IRUSR, dgap_tty_baud_show, NULL);
6337 static ssize_t dgap_tty_msignals_show(struct device *d, struct device_attribute *attr, char *buf)
6340 struct channel_t *ch;
6345 un = dev_get_drvdata(d);
6346 if (!un || un->magic != DGAP_UNIT_MAGIC)
6349 if (!ch || ch->magic != DGAP_CHANNEL_MAGIC)
6352 if (!bd || bd->magic != DGAP_BOARD_MAGIC)
6354 if (bd->state != BOARD_READY)
6357 if (ch->ch_open_count) {
6358 return snprintf(buf, PAGE_SIZE, "%s %s %s %s %s %s\n",
6359 (ch->ch_mostat & UART_MCR_RTS) ? "RTS" : "",
6360 (ch->ch_mistat & UART_MSR_CTS) ? "CTS" : "",
6361 (ch->ch_mostat & UART_MCR_DTR) ? "DTR" : "",
6362 (ch->ch_mistat & UART_MSR_DSR) ? "DSR" : "",
6363 (ch->ch_mistat & UART_MSR_DCD) ? "DCD" : "",
6364 (ch->ch_mistat & UART_MSR_RI) ? "RI" : "");
6368 static DEVICE_ATTR(msignals, S_IRUSR, dgap_tty_msignals_show, NULL);
6370 static ssize_t dgap_tty_iflag_show(struct device *d, struct device_attribute *attr, char *buf)
6373 struct channel_t *ch;
6378 un = dev_get_drvdata(d);
6379 if (!un || un->magic != DGAP_UNIT_MAGIC)
6382 if (!ch || ch->magic != DGAP_CHANNEL_MAGIC)
6385 if (!bd || bd->magic != DGAP_BOARD_MAGIC)
6387 if (bd->state != BOARD_READY)
6390 return snprintf(buf, PAGE_SIZE, "%x\n", ch->ch_c_iflag);
6392 static DEVICE_ATTR(iflag, S_IRUSR, dgap_tty_iflag_show, NULL);
6394 static ssize_t dgap_tty_cflag_show(struct device *d, struct device_attribute *attr, char *buf)
6397 struct channel_t *ch;
6402 un = dev_get_drvdata(d);
6403 if (!un || un->magic != DGAP_UNIT_MAGIC)
6406 if (!ch || ch->magic != DGAP_CHANNEL_MAGIC)
6409 if (!bd || bd->magic != DGAP_BOARD_MAGIC)
6411 if (bd->state != BOARD_READY)
6414 return snprintf(buf, PAGE_SIZE, "%x\n", ch->ch_c_cflag);
6416 static DEVICE_ATTR(cflag, S_IRUSR, dgap_tty_cflag_show, NULL);
6418 static ssize_t dgap_tty_oflag_show(struct device *d, struct device_attribute *attr, char *buf)
6421 struct channel_t *ch;
6426 un = dev_get_drvdata(d);
6427 if (!un || un->magic != DGAP_UNIT_MAGIC)
6430 if (!ch || ch->magic != DGAP_CHANNEL_MAGIC)
6433 if (!bd || bd->magic != DGAP_BOARD_MAGIC)
6435 if (bd->state != BOARD_READY)
6438 return snprintf(buf, PAGE_SIZE, "%x\n", ch->ch_c_oflag);
6440 static DEVICE_ATTR(oflag, S_IRUSR, dgap_tty_oflag_show, NULL);
6442 static ssize_t dgap_tty_lflag_show(struct device *d, struct device_attribute *attr, char *buf)
6445 struct channel_t *ch;
6450 un = dev_get_drvdata(d);
6451 if (!un || un->magic != DGAP_UNIT_MAGIC)
6454 if (!ch || ch->magic != DGAP_CHANNEL_MAGIC)
6457 if (!bd || bd->magic != DGAP_BOARD_MAGIC)
6459 if (bd->state != BOARD_READY)
6462 return snprintf(buf, PAGE_SIZE, "%x\n", ch->ch_c_lflag);
6464 static DEVICE_ATTR(lflag, S_IRUSR, dgap_tty_lflag_show, NULL);
6466 static ssize_t dgap_tty_digi_flag_show(struct device *d, struct device_attribute *attr, char *buf)
6469 struct channel_t *ch;
6474 un = dev_get_drvdata(d);
6475 if (!un || un->magic != DGAP_UNIT_MAGIC)
6478 if (!ch || ch->magic != DGAP_CHANNEL_MAGIC)
6481 if (!bd || bd->magic != DGAP_BOARD_MAGIC)
6483 if (bd->state != BOARD_READY)
6486 return snprintf(buf, PAGE_SIZE, "%x\n", ch->ch_digi.digi_flags);
6488 static DEVICE_ATTR(digi_flag, S_IRUSR, dgap_tty_digi_flag_show, NULL);
6490 static ssize_t dgap_tty_rxcount_show(struct device *d, struct device_attribute *attr, char *buf)
6493 struct channel_t *ch;
6498 un = dev_get_drvdata(d);
6499 if (!un || un->magic != DGAP_UNIT_MAGIC)
6502 if (!ch || ch->magic != DGAP_CHANNEL_MAGIC)
6505 if (!bd || bd->magic != DGAP_BOARD_MAGIC)
6507 if (bd->state != BOARD_READY)
6510 return snprintf(buf, PAGE_SIZE, "%ld\n", ch->ch_rxcount);
6512 static DEVICE_ATTR(rxcount, S_IRUSR, dgap_tty_rxcount_show, NULL);
6514 static ssize_t dgap_tty_txcount_show(struct device *d, struct device_attribute *attr, char *buf)
6517 struct channel_t *ch;
6522 un = dev_get_drvdata(d);
6523 if (!un || un->magic != DGAP_UNIT_MAGIC)
6526 if (!ch || ch->magic != DGAP_CHANNEL_MAGIC)
6529 if (!bd || bd->magic != DGAP_BOARD_MAGIC)
6531 if (bd->state != BOARD_READY)
6534 return snprintf(buf, PAGE_SIZE, "%ld\n", ch->ch_txcount);
6536 static DEVICE_ATTR(txcount, S_IRUSR, dgap_tty_txcount_show, NULL);
6538 static ssize_t dgap_tty_name_show(struct device *d, struct device_attribute *attr, char *buf)
6541 struct channel_t *ch;
6545 struct cnode *cptr = NULL;
6553 un = dev_get_drvdata(d);
6554 if (!un || un->magic != DGAP_UNIT_MAGIC)
6557 if (!ch || ch->magic != DGAP_CHANNEL_MAGIC)
6560 if (!bd || bd->magic != DGAP_BOARD_MAGIC)
6562 if (bd->state != BOARD_READY)
6566 cn = ch->ch_portnum;
6568 for (cptr = bd->bd_config; cptr; cptr = cptr->next) {
6570 if ((cptr->type == BNODE) &&
6571 ((cptr->u.board.type == APORT2_920P) || (cptr->u.board.type == APORT4_920P) ||
6572 (cptr->u.board.type == APORT8_920P) || (cptr->u.board.type == PAPORT4) ||
6573 (cptr->u.board.type == PAPORT8))) {
6576 if (cptr->u.board.v_start)
6577 starto = cptr->u.board.start;
6582 if (cptr->type == TNODE && found == TRUE) {
6584 if (strstr(cptr->u.ttyname, "tty")) {
6585 ptr1 = cptr->u.ttyname;
6588 ptr1 = cptr->u.ttyname;
6590 for (i = 0; i < dgap_config_get_number_of_ports(bd); i++) {
6592 return snprintf(buf, PAGE_SIZE, "%s%s%02d\n",
6593 (un->un_type == DGAP_PRINT) ? "pr" : "tty",
6598 if (cptr->type == CNODE) {
6600 for (i = 0; i < cptr->u.conc.nport; i++) {
6601 if (cn == (i + ncount))
6603 return snprintf(buf, PAGE_SIZE, "%s%s%02d\n",
6604 (un->un_type == DGAP_PRINT) ? "pr" : "tty",
6606 i + (cptr->u.conc.v_start ? cptr->u.conc.start : 1));
6609 ncount += cptr->u.conc.nport;
6612 if (cptr->type == MNODE) {
6614 for (i = 0; i < cptr->u.module.nport; i++) {
6615 if (cn == (i + ncount))
6616 return snprintf(buf, PAGE_SIZE, "%s%s%02d\n",
6617 (un->un_type == DGAP_PRINT) ? "pr" : "tty",
6619 i + (cptr->u.module.v_start ? cptr->u.module.start : 1));
6622 ncount += cptr->u.module.nport;
6627 return snprintf(buf, PAGE_SIZE, "%s_dgap_%d_%d\n",
6628 (un->un_type == DGAP_PRINT) ? "pr" : "tty", bn, cn);
6631 static DEVICE_ATTR(custom_name, S_IRUSR, dgap_tty_name_show, NULL);
6633 static struct attribute *dgap_sysfs_tty_entries[] = {
6634 &dev_attr_state.attr,
6635 &dev_attr_baud.attr,
6636 &dev_attr_msignals.attr,
6637 &dev_attr_iflag.attr,
6638 &dev_attr_cflag.attr,
6639 &dev_attr_oflag.attr,
6640 &dev_attr_lflag.attr,
6641 &dev_attr_digi_flag.attr,
6642 &dev_attr_rxcount.attr,
6643 &dev_attr_txcount.attr,
6644 &dev_attr_custom_name.attr,
6648 static struct attribute_group dgap_tty_attribute_group = {
6650 .attrs = dgap_sysfs_tty_entries,
6653 static void dgap_create_tty_sysfs(struct un_t *un, struct device *c)
6657 ret = sysfs_create_group(&c->kobj, &dgap_tty_attribute_group);
6661 dev_set_drvdata(c, un);
6665 static void dgap_remove_tty_sysfs(struct device *c)
6667 sysfs_remove_group(&c->kobj, &dgap_tty_attribute_group);
6671 * Parse a configuration file read into memory as a string.
6673 static int dgap_parsefile(char **in, int Remove)
6675 struct cnode *p, *brd, *line, *conc;
6677 char *s = NULL, *s2 = NULL;
6681 brd = line = conc = NULL;
6683 /* perhaps we are adding to an existing list? */
6684 while (p->next != NULL)
6687 /* file must start with a BEGIN */
6688 while ((rc = dgap_gettok(in, p)) != BEGIN) {
6690 dgap_err("unexpected EOF");
6696 rc = dgap_gettok(in, p);
6698 dgap_err("unexpected EOF");
6704 dgap_err("unexpected end of file");
6707 case BEGIN: /* should only be 1 begin */
6708 dgap_err("unexpected config_begin\n");
6714 case BOARD: /* board info */
6715 if (dgap_checknode(p))
6717 p->next = dgap_newnode(BNODE);
6719 dgap_err("out of memory");
6724 p->u.board.status = dgap_savestring("No");
6730 case APORT2_920P: /* AccelePort_4 */
6731 if (p->type != BNODE) {
6732 dgap_err("unexpected Digi_2r_920 string");
6735 p->u.board.type = APORT2_920P;
6736 p->u.board.v_type = 1;
6739 case APORT4_920P: /* AccelePort_4 */
6740 if (p->type != BNODE) {
6741 dgap_err("unexpected Digi_4r_920 string");
6744 p->u.board.type = APORT4_920P;
6745 p->u.board.v_type = 1;
6748 case APORT8_920P: /* AccelePort_8 */
6749 if (p->type != BNODE) {
6750 dgap_err("unexpected Digi_8r_920 string");
6753 p->u.board.type = APORT8_920P;
6754 p->u.board.v_type = 1;
6757 case PAPORT4: /* AccelePort_4 PCI */
6758 if (p->type != BNODE) {
6759 dgap_err("unexpected Digi_4r(PCI) string");
6762 p->u.board.type = PAPORT4;
6763 p->u.board.v_type = 1;
6766 case PAPORT8: /* AccelePort_8 PCI */
6767 if (p->type != BNODE) {
6768 dgap_err("unexpected Digi_8r string");
6771 p->u.board.type = PAPORT8;
6772 p->u.board.v_type = 1;
6775 case PCX: /* PCI C/X */
6776 if (p->type != BNODE) {
6777 dgap_err("unexpected Digi_C/X_(PCI) string");
6780 p->u.board.type = PCX;
6781 p->u.board.v_type = 1;
6782 p->u.board.conc1 = 0;
6783 p->u.board.conc2 = 0;
6784 p->u.board.module1 = 0;
6785 p->u.board.module2 = 0;
6788 case PEPC: /* PCI EPC/X */
6789 if (p->type != BNODE) {
6790 dgap_err("unexpected \"Digi_EPC/X_(PCI)\" string");
6793 p->u.board.type = PEPC;
6794 p->u.board.v_type = 1;
6795 p->u.board.conc1 = 0;
6796 p->u.board.conc2 = 0;
6797 p->u.board.module1 = 0;
6798 p->u.board.module2 = 0;
6801 case PPCM: /* PCI/Xem */
6802 if (p->type != BNODE) {
6803 dgap_err("unexpected PCI/Xem string");
6806 p->u.board.type = PPCM;
6807 p->u.board.v_type = 1;
6808 p->u.board.conc1 = 0;
6809 p->u.board.conc2 = 0;
6812 case IO: /* i/o port */
6813 if (p->type != BNODE) {
6814 dgap_err("IO port only vaild for boards");
6817 s = dgap_getword(in);
6819 dgap_err("unexpected end of file");
6822 p->u.board.portstr = dgap_savestring(s);
6823 p->u.board.port = (short)simple_strtol(s, &s2, 0);
6824 if ((short)strlen(s) > (short)(s2 - s)) {
6825 dgap_err("bad number for IO port");
6828 p->u.board.v_port = 1;
6831 case MEM: /* memory address */
6832 if (p->type != BNODE) {
6833 dgap_err("memory address only vaild for boards");
6836 s = dgap_getword(in);
6838 dgap_err("unexpected end of file");
6841 p->u.board.addrstr = dgap_savestring(s);
6842 p->u.board.addr = simple_strtoul(s, &s2, 0);
6843 if ((int)strlen(s) > (int)(s2 - s)) {
6844 dgap_err("bad number for memory address");
6847 p->u.board.v_addr = 1;
6850 case PCIINFO: /* pci information */
6851 if (p->type != BNODE) {
6852 dgap_err("memory address only vaild for boards");
6855 s = dgap_getword(in);
6857 dgap_err("unexpected end of file");
6860 p->u.board.pcibusstr = dgap_savestring(s);
6861 p->u.board.pcibus = simple_strtoul(s, &s2, 0);
6862 if ((int)strlen(s) > (int)(s2 - s)) {
6863 dgap_err("bad number for pci bus");
6866 p->u.board.v_pcibus = 1;
6867 s = dgap_getword(in);
6869 dgap_err("unexpected end of file");
6872 p->u.board.pcislotstr = dgap_savestring(s);
6873 p->u.board.pcislot = simple_strtoul(s, &s2, 0);
6874 if ((int)strlen(s) > (int)(s2 - s)) {
6875 dgap_err("bad number for pci slot");
6878 p->u.board.v_pcislot = 1;
6882 if (p->type != BNODE) {
6883 dgap_err("install method only vaild for boards");
6886 s = dgap_getword(in);
6888 dgap_err("unexpected end of file");
6891 p->u.board.method = dgap_savestring(s);
6892 p->u.board.v_method = 1;
6896 if (p->type != BNODE) {
6897 dgap_err("config status only vaild for boards");
6900 s = dgap_getword(in);
6902 dgap_err("unexpected end of file");
6905 p->u.board.status = dgap_savestring(s);
6908 case NPORTS: /* number of ports */
6909 if (p->type == BNODE) {
6910 s = dgap_getword(in);
6912 dgap_err("unexpected end of file");
6915 p->u.board.nport = (char)simple_strtol(s, &s2, 0);
6916 if ((int)strlen(s) > (int)(s2 - s)) {
6917 dgap_err("bad number for number of ports");
6920 p->u.board.v_nport = 1;
6921 } else if (p->type == CNODE) {
6922 s = dgap_getword(in);
6924 dgap_err("unexpected end of file");
6927 p->u.conc.nport = (char)simple_strtol(s, &s2, 0);
6928 if ((int)strlen(s) > (int)(s2 - s)) {
6929 dgap_err("bad number for number of ports");
6932 p->u.conc.v_nport = 1;
6933 } else if (p->type == MNODE) {
6934 s = dgap_getword(in);
6936 dgap_err("unexpected end of file");
6939 p->u.module.nport = (char)simple_strtol(s, &s2, 0);
6940 if ((int)strlen(s) > (int)(s2 - s)) {
6941 dgap_err("bad number for number of ports");
6944 p->u.module.v_nport = 1;
6946 dgap_err("nports only valid for concentrators or modules");
6951 case ID: /* letter ID used in tty name */
6952 s = dgap_getword(in);
6954 dgap_err("unexpected end of file");
6958 p->u.board.status = dgap_savestring(s);
6960 if (p->type == CNODE) {
6961 p->u.conc.id = dgap_savestring(s);
6963 } else if (p->type == MNODE) {
6964 p->u.module.id = dgap_savestring(s);
6965 p->u.module.v_id = 1;
6967 dgap_err("id only valid for concentrators or modules");
6972 case STARTO: /* start offset of ID */
6973 if (p->type == BNODE) {
6974 s = dgap_getword(in);
6976 dgap_err("unexpected end of file");
6979 p->u.board.start = simple_strtol(s, &s2, 0);
6980 if ((int)strlen(s) > (int)(s2 - s)) {
6981 dgap_err("bad number for start of tty count");
6984 p->u.board.v_start = 1;
6985 } else if (p->type == CNODE) {
6986 s = dgap_getword(in);
6988 dgap_err("unexpected end of file");
6991 p->u.conc.start = simple_strtol(s, &s2, 0);
6992 if ((int)strlen(s) > (int)(s2 - s)) {
6993 dgap_err("bad number for start of tty count");
6996 p->u.conc.v_start = 1;
6997 } else if (p->type == MNODE) {
6998 s = dgap_getword(in);
7000 dgap_err("unexpected end of file");
7003 p->u.module.start = simple_strtol(s, &s2, 0);
7004 if ((int)strlen(s) > (int)(s2 - s)) {
7005 dgap_err("bad number for start of tty count");
7008 p->u.module.v_start = 1;
7010 dgap_err("start only valid for concentrators or modules");
7015 case TTYN: /* tty name prefix */
7016 if (dgap_checknode(p))
7018 p->next = dgap_newnode(TNODE);
7020 dgap_err("out of memory");
7024 s = dgap_getword(in);
7026 dgap_err("unexpeced end of file");
7029 p->u.ttyname = dgap_savestring(s);
7030 if (!p->u.ttyname) {
7031 dgap_err("out of memory");
7036 case CU: /* cu name prefix */
7037 if (dgap_checknode(p))
7039 p->next = dgap_newnode(CUNODE);
7041 dgap_err("out of memory");
7045 s = dgap_getword(in);
7047 dgap_err("unexpeced end of file");
7050 p->u.cuname = dgap_savestring(s);
7052 dgap_err("out of memory");
7057 case LINE: /* line information */
7058 if (dgap_checknode(p))
7061 dgap_err("must specify board before line info");
7064 switch (brd->u.board.type) {
7066 dgap_err("line not vaild for PC/em");
7069 p->next = dgap_newnode(LNODE);
7071 dgap_err("out of memory");
7080 case CONC: /* concentrator information */
7081 if (dgap_checknode(p))
7084 dgap_err("must specify line info before concentrator");
7087 p->next = dgap_newnode(CNODE);
7089 dgap_err("out of memory");
7095 brd->u.board.conc2++;
7097 brd->u.board.conc1++;
7101 case CX: /* c/x type concentrator */
7102 if (p->type != CNODE) {
7103 dgap_err("cx only valid for concentrators");
7106 p->u.conc.type = CX;
7107 p->u.conc.v_type = 1;
7110 case EPC: /* epc type concentrator */
7111 if (p->type != CNODE) {
7112 dgap_err("cx only valid for concentrators");
7115 p->u.conc.type = EPC;
7116 p->u.conc.v_type = 1;
7119 case MOD: /* EBI module */
7120 if (dgap_checknode(p))
7123 dgap_err("must specify board info before EBI modules");
7126 switch (brd->u.board.type) {
7132 dgap_err("must specify concentrator info before EBI module");
7136 p->next = dgap_newnode(MNODE);
7138 dgap_err("out of memory");
7143 brd->u.board.module2++;
7145 brd->u.board.module1++;
7149 case PORTS: /* ports type EBI module */
7150 if (p->type != MNODE) {
7151 dgap_err("ports only valid for EBI modules");
7154 p->u.module.type = PORTS;
7155 p->u.module.v_type = 1;
7158 case MODEM: /* ports type EBI module */
7159 if (p->type != MNODE) {
7160 dgap_err("modem only valid for modem modules");
7163 p->u.module.type = MODEM;
7164 p->u.module.v_type = 1;
7168 if (p->type == LNODE) {
7169 s = dgap_getword(in);
7171 dgap_err("unexpected end of file");
7174 p->u.line.cable = dgap_savestring(s);
7175 p->u.line.v_cable = 1;
7179 case SPEED: /* sync line speed indication */
7180 if (p->type == LNODE) {
7181 s = dgap_getword(in);
7183 dgap_err("unexpected end of file");
7186 p->u.line.speed = (char)simple_strtol(s, &s2, 0);
7187 if ((short)strlen(s) > (short)(s2 - s)) {
7188 dgap_err("bad number for line speed");
7191 p->u.line.v_speed = 1;
7192 } else if (p->type == CNODE) {
7193 s = dgap_getword(in);
7195 dgap_err("unexpected end of file");
7198 p->u.conc.speed = (char)simple_strtol(s, &s2, 0);
7199 if ((short)strlen(s) > (short)(s2 - s)) {
7200 dgap_err("bad number for line speed");
7203 p->u.conc.v_speed = 1;
7205 dgap_err("speed valid only for lines or concentrators.");
7211 if (p->type == CNODE) {
7212 s = dgap_getword(in);
7214 dgap_err("unexpected end of file");
7217 p->u.conc.connect = dgap_savestring(s);
7218 p->u.conc.v_connect = 1;
7221 case PRINT: /* transparent print name prefix */
7222 if (dgap_checknode(p))
7224 p->next = dgap_newnode(PNODE);
7226 dgap_err("out of memory");
7230 s = dgap_getword(in);
7232 dgap_err("unexpeced end of file");
7235 p->u.printname = dgap_savestring(s);
7236 if (!p->u.printname) {
7237 dgap_err("out of memory");
7242 case CMAJOR: /* major number */
7243 if (dgap_checknode(p))
7245 p->next = dgap_newnode(JNODE);
7247 dgap_err("out of memory");
7251 s = dgap_getword(in);
7253 dgap_err("unexpected end of file");
7256 p->u.majornumber = simple_strtol(s, &s2, 0);
7257 if ((int)strlen(s) > (int)(s2 - s)) {
7258 dgap_err("bad number for major number");
7263 case ALTPIN: /* altpin setting */
7264 if (dgap_checknode(p))
7266 p->next = dgap_newnode(ANODE);
7268 dgap_err("out of memory");
7272 s = dgap_getword(in);
7274 dgap_err("unexpected end of file");
7277 p->u.altpin = simple_strtol(s, &s2, 0);
7278 if ((int)strlen(s) > (int)(s2 - s)) {
7279 dgap_err("bad number for altpin");
7284 case USEINTR: /* enable interrupt setting */
7285 if (dgap_checknode(p))
7287 p->next = dgap_newnode(INTRNODE);
7289 dgap_err("out of memory");
7293 s = dgap_getword(in);
7295 dgap_err("unexpected end of file");
7298 p->u.useintr = simple_strtol(s, &s2, 0);
7299 if ((int)strlen(s) > (int)(s2 - s)) {
7300 dgap_err("bad number for useintr");
7305 case TTSIZ: /* size of tty structure */
7306 if (dgap_checknode(p))
7308 p->next = dgap_newnode(TSNODE);
7310 dgap_err("out of memory");
7314 s = dgap_getword(in);
7316 dgap_err("unexpected end of file");
7319 p->u.ttysize = simple_strtol(s, &s2, 0);
7320 if ((int)strlen(s) > (int)(s2 - s)) {
7321 dgap_err("bad number for ttysize");
7326 case CHSIZ: /* channel structure size */
7327 if (dgap_checknode(p))
7329 p->next = dgap_newnode(CSNODE);
7331 dgap_err("out of memory");
7335 s = dgap_getword(in);
7337 dgap_err("unexpected end of file");
7340 p->u.chsize = simple_strtol(s, &s2, 0);
7341 if ((int)strlen(s) > (int)(s2 - s)) {
7342 dgap_err("bad number for chsize");
7347 case BSSIZ: /* board structure size */
7348 if (dgap_checknode(p))
7350 p->next = dgap_newnode(BSNODE);
7352 dgap_err("out of memory");
7356 s = dgap_getword(in);
7358 dgap_err("unexpected end of file");
7361 p->u.bssize = simple_strtol(s, &s2, 0);
7362 if ((int)strlen(s) > (int)(s2 - s)) {
7363 dgap_err("bad number for bssize");
7368 case UNTSIZ: /* sched structure size */
7369 if (dgap_checknode(p))
7371 p->next = dgap_newnode(USNODE);
7373 dgap_err("out of memory");
7377 s = dgap_getword(in);
7379 dgap_err("unexpected end of file");
7382 p->u.unsize = simple_strtol(s, &s2, 0);
7383 if ((int)strlen(s) > (int)(s2 - s)) {
7384 dgap_err("bad number for schedsize");
7389 case F2SIZ: /* f2200 structure size */
7390 if (dgap_checknode(p))
7392 p->next = dgap_newnode(FSNODE);
7394 dgap_err("out of memory");
7398 s = dgap_getword(in);
7400 dgap_err("unexpected end of file");
7403 p->u.f2size = simple_strtol(s, &s2, 0);
7404 if ((int)strlen(s) > (int)(s2 - s)) {
7405 dgap_err("bad number for f2200size");
7410 case VPSIZ: /* vpix structure size */
7411 if (dgap_checknode(p))
7413 p->next = dgap_newnode(VSNODE);
7415 dgap_err("out of memory");
7419 s = dgap_getword(in);
7421 dgap_err("unexpected end of file");
7424 p->u.vpixsize = simple_strtol(s, &s2, 0);
7425 if ((int)strlen(s) > (int)(s2 - s)) {
7426 dgap_err("bad number for vpixsize");
7435 * dgap_sindex: much like index(), but it looks for a match of any character in
7436 * the group, and returns that position. If the first character is a ^, then
7437 * this will match the first occurrence not in that group.
7439 static char *dgap_sindex(char *string, char *group)
7443 if (!string || !group)
7444 return (char *) NULL;
7446 if (*group == '^') {
7448 for (; *string; string++) {
7449 for (ptr = group; *ptr; ptr++) {
7450 if (*ptr == *string)
7457 for (; *string; string++) {
7458 for (ptr = group; *ptr; ptr++) {
7459 if (*ptr == *string)
7465 return (char *) NULL;
7469 * Get a token from the input file; return 0 if end of file is reached
7471 static int dgap_gettok(char **in, struct cnode *p)
7476 if (strstr(dgap_cword, "boar")) {
7477 w = dgap_getword(in);
7478 snprintf(dgap_cword, MAXCWORD, "%s", w);
7479 for (t = dgap_tlist; t->token != 0; t++) {
7480 if (!strcmp(w, t->string))
7483 dgap_err("board !!type not specified");
7486 while ((w = dgap_getword(in))) {
7487 snprintf(dgap_cword, MAXCWORD, "%s", w);
7488 for (t = dgap_tlist; t->token != 0; t++) {
7489 if (!strcmp(w, t->string))
7498 * get a word from the input stream, also keep track of current line number.
7499 * words are separated by whitespace.
7501 static char *dgap_getword(char **in)
7503 char *ret_ptr = *in;
7505 char *ptr = dgap_sindex(*in, " \t\n");
7507 /* If no word found, return null */
7511 /* Mark new location for our buffer */
7515 /* Eat any extra spaces/tabs/newlines that might be present */
7516 while (*in && **in && ((**in == ' ') || (**in == '\t') || (**in == '\n'))) {
7525 * print an error message, giving the line number in the file where
7526 * the error occurred.
7528 static void dgap_err(char *s)
7530 pr_err("dgap: parse: %s\n", s);
7534 * allocate a new configuration node of type t
7536 static struct cnode *dgap_newnode(int t)
7540 n = kmalloc(sizeof(struct cnode), GFP_ATOMIC);
7542 memset((char *)n, 0, sizeof(struct cnode));
7549 * dgap_checknode: see if all the necessary info has been supplied for a node
7550 * before creating the next node.
7552 static int dgap_checknode(struct cnode *p)
7556 if (p->u.board.v_type == 0) {
7557 dgap_err("board type !not specified");
7564 if (p->u.line.v_speed == 0) {
7565 dgap_err("line speed not specified");
7571 if (p->u.conc.v_type == 0) {
7572 dgap_err("concentrator type not specified");
7575 if (p->u.conc.v_speed == 0) {
7576 dgap_err("concentrator line speed not specified");
7579 if (p->u.conc.v_nport == 0) {
7580 dgap_err("number of ports on concentrator not specified");
7583 if (p->u.conc.v_id == 0) {
7584 dgap_err("concentrator id letter not specified");
7590 if (p->u.module.v_type == 0) {
7591 dgap_err("EBI module type not specified");
7594 if (p->u.module.v_nport == 0) {
7595 dgap_err("number of ports on EBI module not specified");
7598 if (p->u.module.v_id == 0) {
7599 dgap_err("EBI module id letter not specified");
7608 * save a string somewhere
7610 static char *dgap_savestring(char *s)
7614 p = kmalloc(strlen(s) + 1, GFP_ATOMIC);
7621 * Given a board pointer, returns whether we should use interrupts or not.
7623 static uint dgap_config_get_useintr(struct board_t *bd)
7625 struct cnode *p = NULL;
7630 for (p = bd->bd_config; p; p = p->next) {
7634 * check for pcxr types.
7636 return p->u.useintr;
7642 /* If not found, then don't turn on interrupts. */
7647 * Given a board pointer, returns whether we turn on altpin or not.
7649 static uint dgap_config_get_altpin(struct board_t *bd)
7651 struct cnode *p = NULL;
7656 for (p = bd->bd_config; p; p = p->next) {
7660 * check for pcxr types.
7668 /* If not found, then don't turn on interrupts. */
7673 * Given a specific type of board, if found, detached link and
7674 * returns the first occurrence in the list.
7676 static struct cnode *dgap_find_config(int type, int bus, int slot)
7678 struct cnode *p, *prev = NULL, *prev2 = NULL, *found = NULL;
7682 while (p->next != NULL) {
7686 if (p->type == BNODE) {
7688 if (p->u.board.type == type) {
7690 if (p->u.board.v_pcibus &&
7691 p->u.board.pcibus != bus)
7693 if (p->u.board.v_pcislot &&
7694 p->u.board.pcislot != slot)
7699 * Keep walking thru the list till we find the next board.
7701 while (p->next != NULL) {
7704 if (p->type == BNODE) {
7707 * Mark the end of our 1 board chain of configs.
7712 * Link the "next" board to the previous board,
7713 * effectively "unlinking" our board from the main config.
7721 * It must be the last board in the list.
7732 * Given a board pointer, walks the config link, counting up
7733 * all ports user specified should be on the board.
7734 * (This does NOT mean they are all actually present right now tho)
7736 static uint dgap_config_get_number_of_ports(struct board_t *bd)
7739 struct cnode *p = NULL;
7744 for (p = bd->bd_config; p; p = p->next) {
7749 * check for pcxr types.
7751 if (p->u.board.type > EPCFE)
7752 count += p->u.board.nport;
7755 count += p->u.conc.nport;
7758 count += p->u.module.nport;
7765 static char *dgap_create_config_string(struct board_t *bd, char *string)
7768 struct cnode *p = NULL;
7769 struct cnode *q = NULL;
7777 for (p = bd->bd_config; p; p = p->next) {
7783 *ptr = p->u.line.speed;
7788 * Because the EPC/con concentrators can have EM modules
7789 * hanging off of them, we have to walk ahead in the list
7790 * and keep adding the number of ports on each EM to the config.
7793 speed = p->u.conc.speed;
7795 if ((q != NULL) && (q->type == MNODE)) {
7796 *ptr = (p->u.conc.nport + 0x80);
7799 while ((q->next != NULL) && (q->next->type) == MNODE) {
7800 *ptr = (q->u.module.nport + 0x80);
7805 *ptr = q->u.module.nport;
7808 *ptr = p->u.conc.nport;