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.
18 * In the original out of kernel Digi dgap driver, firmware
19 * loading was done via user land to driver handshaking.
21 * For cards that support a concentrator (port expander),
22 * I believe the concentrator its self told the card which
23 * concentrator is actually attached and then that info
24 * was used to tell user land which concentrator firmware
25 * image was to be downloaded. I think even the BIOS or
26 * FEP images required could change with the connection
27 * of a particular concentrator.
29 * Since I have no access to any of these cards or
30 * concentrators, I cannot put the correct concentrator
31 * firmware file names into the firmware_info structure
32 * as is now done for the BIOS and FEP images.
34 * I think, but am not certain, that the cards supporting
35 * concentrators will function without them. So support
36 * of these cards has been left in this driver.
38 * In order to fully support those cards, they would
39 * either have to be acquired for dissection or maybe
40 * Digi International could provide some assistance.
42 #undef DIGI_CONCENTRATORS_SUPPORTED
44 #include <linux/kernel.h>
45 #include <linux/module.h>
46 #include <linux/pci.h>
47 #include <linux/delay.h> /* For udelay */
48 #include <linux/slab.h>
49 #include <linux/uaccess.h>
50 #include <linux/sched.h>
52 #include <linux/interrupt.h> /* For tasklet and interrupt structs/defines */
53 #include <linux/ctype.h>
54 #include <linux/tty.h>
55 #include <linux/tty_flip.h>
56 #include <linux/serial_reg.h>
57 #include <linux/io.h> /* For read[bwl]/write[bwl] */
59 #include <linux/string.h>
60 #include <linux/device.h>
61 #include <linux/kdev_t.h>
62 #include <linux/firmware.h>
66 MODULE_LICENSE("GPL");
67 MODULE_AUTHOR("Digi International, http://www.digi.com");
68 MODULE_DESCRIPTION("Driver for the Digi International EPCA PCI based product line");
69 MODULE_SUPPORTED_DEVICE("dgap");
71 static int dgap_start(void);
72 static void dgap_init_globals(void);
73 static int dgap_found_board(struct pci_dev *pdev, int id);
74 static void dgap_cleanup_board(struct board_t *brd);
75 static void dgap_poll_handler(ulong dummy);
76 static int dgap_init_pci(void);
77 static int dgap_init_one(struct pci_dev *pdev, const struct pci_device_id *ent);
78 static void dgap_remove_one(struct pci_dev *dev);
79 static int dgap_probe1(struct pci_dev *pdev, int card_type);
80 static int dgap_do_remap(struct board_t *brd);
81 static irqreturn_t dgap_intr(int irq, void *voidbrd);
83 static int dgap_tty_open(struct tty_struct *tty, struct file *file);
84 static void dgap_tty_close(struct tty_struct *tty, struct file *file);
85 static int dgap_block_til_ready(struct tty_struct *tty, struct file *file,
86 struct channel_t *ch);
87 static int dgap_tty_ioctl(struct tty_struct *tty, unsigned int cmd,
89 static int dgap_tty_digigeta(struct tty_struct *tty,
90 struct digi_t __user *retinfo);
91 static int dgap_tty_digiseta(struct tty_struct *tty,
92 struct digi_t __user *new_info);
93 static int dgap_tty_digigetedelay(struct tty_struct *tty, int __user *retinfo);
94 static int dgap_tty_digisetedelay(struct tty_struct *tty, int __user *new_info);
95 static int dgap_tty_write_room(struct tty_struct *tty);
96 static int dgap_tty_chars_in_buffer(struct tty_struct *tty);
97 static void dgap_tty_start(struct tty_struct *tty);
98 static void dgap_tty_stop(struct tty_struct *tty);
99 static void dgap_tty_throttle(struct tty_struct *tty);
100 static void dgap_tty_unthrottle(struct tty_struct *tty);
101 static void dgap_tty_flush_chars(struct tty_struct *tty);
102 static void dgap_tty_flush_buffer(struct tty_struct *tty);
103 static void dgap_tty_hangup(struct tty_struct *tty);
104 static int dgap_wait_for_drain(struct tty_struct *tty);
105 static int dgap_set_modem_info(struct tty_struct *tty, unsigned int command,
106 unsigned int __user *value);
107 static int dgap_get_modem_info(struct channel_t *ch,
108 unsigned int __user *value);
109 static int dgap_tty_digisetcustombaud(struct tty_struct *tty,
110 int __user *new_info);
111 static int dgap_tty_digigetcustombaud(struct tty_struct *tty,
112 int __user *retinfo);
113 static int dgap_tty_tiocmget(struct tty_struct *tty);
114 static int dgap_tty_tiocmset(struct tty_struct *tty, unsigned int set,
116 static int dgap_tty_send_break(struct tty_struct *tty, int msec);
117 static void dgap_tty_wait_until_sent(struct tty_struct *tty, int timeout);
118 static int dgap_tty_write(struct tty_struct *tty, const unsigned char *buf,
120 static void dgap_tty_set_termios(struct tty_struct *tty,
121 struct ktermios *old_termios);
122 static int dgap_tty_put_char(struct tty_struct *tty, unsigned char c);
123 static void dgap_tty_send_xchar(struct tty_struct *tty, char ch);
125 static int dgap_tty_register(struct board_t *brd);
126 static int dgap_tty_init(struct board_t *);
127 static void dgap_tty_uninit(struct board_t *);
128 static void dgap_carrier(struct channel_t *ch);
129 static void dgap_input(struct channel_t *ch);
132 * Our function prototypes from dgap_fep5
134 static void dgap_cmdw_ext(struct channel_t *ch, u16 cmd, u16 word, uint ncmds);
135 static int dgap_event(struct board_t *bd);
137 static void dgap_poll_tasklet(unsigned long data);
138 static void dgap_cmdb(struct channel_t *ch, u8 cmd, u8 byte1,
139 u8 byte2, uint ncmds);
140 static void dgap_cmdw(struct channel_t *ch, u8 cmd, u16 word, uint ncmds);
141 static void dgap_wmove(struct channel_t *ch, char *buf, uint cnt);
142 static int dgap_param(struct tty_struct *tty);
143 static void dgap_parity_scan(struct channel_t *ch, unsigned char *cbuf,
144 unsigned char *fbuf, int *len);
145 static uint dgap_get_custom_baud(struct channel_t *ch);
146 static void dgap_firmware_reset_port(struct channel_t *ch);
149 * Function prototypes from dgap_parse.c.
151 static int dgap_gettok(char **in, struct cnode *p);
152 static char *dgap_getword(char **in);
153 static struct cnode *dgap_newnode(int t);
154 static int dgap_checknode(struct cnode *p);
155 static void dgap_err(char *s);
158 * Function prototypes from dgap_sysfs.h
166 static void dgap_create_ports_sysfiles(struct board_t *bd);
167 static void dgap_remove_ports_sysfiles(struct board_t *bd);
169 static int dgap_create_driver_sysfiles(struct pci_driver *);
170 static void dgap_remove_driver_sysfiles(struct pci_driver *);
172 static void dgap_create_tty_sysfs(struct un_t *un, struct device *c);
173 static void dgap_remove_tty_sysfs(struct device *c);
176 * Function prototypes from dgap_parse.h
178 static int dgap_parsefile(char **in, int remove);
179 static struct cnode *dgap_find_config(int type, int bus, int slot);
180 static uint dgap_config_get_num_prts(struct board_t *bd);
181 static char *dgap_create_config_string(struct board_t *bd, char *string);
182 static uint dgap_config_get_useintr(struct board_t *bd);
183 static uint dgap_config_get_altpin(struct board_t *bd);
185 static int dgap_ms_sleep(ulong ms);
186 static void dgap_do_bios_load(struct board_t *brd, const u8 *ubios, int len);
187 static void dgap_do_fep_load(struct board_t *brd, const u8 *ufep, int len);
188 #ifdef DIGI_CONCENTRATORS_SUPPORTED
189 static void dgap_do_conc_load(struct board_t *brd, u8 *uaddr, int len);
191 static int dgap_after_config_loaded(int board);
192 static int dgap_finalize_board_init(struct board_t *brd);
194 static void dgap_get_vpd(struct board_t *brd);
195 static void dgap_do_reset_board(struct board_t *brd);
196 static int dgap_test_bios(struct board_t *brd);
197 static int dgap_test_fep(struct board_t *brd);
198 static int dgap_tty_register_ports(struct board_t *brd);
199 static int dgap_firmware_load(struct pci_dev *pdev, int card_type);
201 static void dgap_cleanup_module(void);
203 module_exit(dgap_cleanup_module);
206 * File operations permitted on Control/Management major.
208 static const struct file_operations dgap_board_fops = {
209 .owner = THIS_MODULE,
212 static uint dgap_numboards;
213 static struct board_t *dgap_board[MAXBOARDS];
214 static ulong dgap_poll_counter;
215 static char *dgap_config_buf;
216 static int dgap_driver_state = DRIVER_INITIALIZED;
217 static wait_queue_head_t dgap_dl_wait;
218 static int dgap_poll_tick = 20; /* Poll interval - 20 ms */
220 static struct class *dgap_class;
222 static struct board_t *dgap_boards_by_major[256];
223 static uint dgap_count = 500;
228 static DEFINE_SPINLOCK(dgap_poll_lock); /* Poll scheduling lock */
229 static ulong dgap_poll_time; /* Time of next poll */
230 static uint dgap_poll_stop; /* Used to tell poller to stop */
231 static struct timer_list dgap_poll_timer;
236 Card Model Number of Ports Interface
237 ----------------------------------------------------------------
238 Acceleport Xem 4 - 64 (EIA232 & EIA422)
239 Acceleport Xr 4 & 8 (EIA232)
240 Acceleport Xr 920 4 & 8 (EIA232)
241 Acceleport C/X 8 - 128 (EIA232)
242 Acceleport EPC/X 8 - 224 (EIA232)
243 Acceleport Xr/422 4 & 8 (EIA422)
244 Acceleport 2r/920 2 (EIA232)
245 Acceleport 4r/920 4 (EIA232)
246 Acceleport 8r/920 8 (EIA232)
248 IBM 8-Port Asynchronous PCI Adapter (EIA232)
249 IBM 128-Port Asynchronous PCI Adapter (EIA232 & EIA422)
252 static struct pci_device_id dgap_pci_tbl[] = {
253 { DIGI_VID, PCI_DEV_XEM_DID, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0 },
254 { DIGI_VID, PCI_DEV_CX_DID, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 1 },
255 { DIGI_VID, PCI_DEV_CX_IBM_DID, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 2 },
256 { DIGI_VID, PCI_DEV_EPCJ_DID, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 3 },
257 { DIGI_VID, PCI_DEV_920_2_DID, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 4 },
258 { DIGI_VID, PCI_DEV_920_4_DID, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 5 },
259 { DIGI_VID, PCI_DEV_920_8_DID, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 6 },
260 { DIGI_VID, PCI_DEV_XR_DID, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 7 },
261 { DIGI_VID, PCI_DEV_XRJ_DID, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 8 },
262 { DIGI_VID, PCI_DEV_XR_422_DID, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 9 },
263 { DIGI_VID, PCI_DEV_XR_IBM_DID, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 10 },
264 { DIGI_VID, PCI_DEV_XR_SAIP_DID, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 11 },
265 { DIGI_VID, PCI_DEV_XR_BULL_DID, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 12 },
266 { DIGI_VID, PCI_DEV_920_8_HP_DID, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 13 },
267 { DIGI_VID, PCI_DEV_XEM_HP_DID, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 14 },
268 {0,} /* 0 terminated list. */
270 MODULE_DEVICE_TABLE(pci, dgap_pci_tbl);
273 * A generic list of Product names, PCI Vendor ID, and PCI Device ID.
282 static struct board_id dgap_ids[] = {
283 { PPCM, PCI_DEV_XEM_NAME, 64, (T_PCXM|T_PCLITE|T_PCIBUS) },
284 { PCX, PCI_DEV_CX_NAME, 128, (T_CX|T_PCIBUS) },
285 { PCX, PCI_DEV_CX_IBM_NAME, 128, (T_CX|T_PCIBUS) },
286 { PEPC, PCI_DEV_EPCJ_NAME, 224, (T_EPC|T_PCIBUS) },
287 { APORT2_920P, PCI_DEV_920_2_NAME, 2, (T_PCXR|T_PCLITE|T_PCIBUS) },
288 { APORT4_920P, PCI_DEV_920_4_NAME, 4, (T_PCXR|T_PCLITE|T_PCIBUS) },
289 { APORT8_920P, PCI_DEV_920_8_NAME, 8, (T_PCXR|T_PCLITE|T_PCIBUS) },
290 { PAPORT8, PCI_DEV_XR_NAME, 8, (T_PCXR|T_PCLITE|T_PCIBUS) },
291 { PAPORT8, PCI_DEV_XRJ_NAME, 8, (T_PCXR|T_PCLITE|T_PCIBUS) },
292 { PAPORT8, PCI_DEV_XR_422_NAME, 8, (T_PCXR|T_PCLITE|T_PCIBUS) },
293 { PAPORT8, PCI_DEV_XR_IBM_NAME, 8, (T_PCXR|T_PCLITE|T_PCIBUS) },
294 { PAPORT8, PCI_DEV_XR_SAIP_NAME, 8, (T_PCXR|T_PCLITE|T_PCIBUS) },
295 { PAPORT8, PCI_DEV_XR_BULL_NAME, 8, (T_PCXR|T_PCLITE|T_PCIBUS) },
296 { APORT8_920P, PCI_DEV_920_8_HP_NAME, 8, (T_PCXR|T_PCLITE|T_PCIBUS) },
297 { PPCM, PCI_DEV_XEM_HP_NAME, 64, (T_PCXM|T_PCLITE|T_PCIBUS) },
298 {0,} /* 0 terminated list. */
301 static struct pci_driver dgap_driver = {
303 .probe = dgap_init_one,
304 .id_table = dgap_pci_tbl,
305 .remove = dgap_remove_one,
308 struct firmware_info {
309 u8 *conf_name; /* dgap.conf */
310 u8 *bios_name; /* BIOS filename */
311 u8 *fep_name; /* FEP filename */
312 u8 *con_name; /* Concentrator filename FIXME*/
313 int num; /* sequence number */
317 * Firmware - BIOS, FEP, and CONC filenames
319 static struct firmware_info fw_info[] = {
320 { "dgap/dgap.conf", "dgap/sxbios.bin", "dgap/sxfep.bin", NULL, 0 },
321 { "dgap/dgap.conf", "dgap/cxpbios.bin", "dgap/cxpfep.bin", NULL, 1 },
322 { "dgap/dgap.conf", "dgap/cxpbios.bin", "dgap/cxpfep.bin", NULL, 2 },
323 { "dgap/dgap.conf", "dgap/pcibios.bin", "dgap/pcifep.bin", NULL, 3 },
324 { "dgap/dgap.conf", "dgap/xrbios.bin", "dgap/xrfep.bin", NULL, 4 },
325 { "dgap/dgap.conf", "dgap/xrbios.bin", "dgap/xrfep.bin", NULL, 5 },
326 { "dgap/dgap.conf", "dgap/xrbios.bin", "dgap/xrfep.bin", NULL, 6 },
327 { "dgap/dgap.conf", "dgap/xrbios.bin", "dgap/xrfep.bin", NULL, 7 },
328 { "dgap/dgap.conf", "dgap/xrbios.bin", "dgap/xrfep.bin", NULL, 8 },
329 { "dgap/dgap.conf", "dgap/xrbios.bin", "dgap/xrfep.bin", NULL, 9 },
330 { "dgap/dgap.conf", "dgap/xrbios.bin", "dgap/xrfep.bin", NULL, 10 },
331 { "dgap/dgap.conf", "dgap/xrbios.bin", "dgap/xrfep.bin", NULL, 11 },
332 { "dgap/dgap.conf", "dgap/xrbios.bin", "dgap/xrfep.bin", NULL, 12 },
333 { "dgap/dgap.conf", "dgap/xrbios.bin", "dgap/xrfep.bin", NULL, 13 },
334 { "dgap/dgap.conf", "dgap/sxbios.bin", "dgap/sxfep.bin", NULL, 14 },
339 * Default transparent print information.
341 static struct digi_t dgap_digi_init = {
342 .digi_flags = DIGI_COOK, /* Flags */
343 .digi_maxcps = 100, /* Max CPS */
344 .digi_maxchar = 50, /* Max chars in print queue */
345 .digi_bufsize = 100, /* Printer buffer size */
346 .digi_onlen = 4, /* size of printer on string */
347 .digi_offlen = 4, /* size of printer off string */
348 .digi_onstr = "\033[5i", /* ANSI printer on string ] */
349 .digi_offstr = "\033[4i", /* ANSI printer off string ] */
350 .digi_term = "ansi" /* default terminal type */
354 * Define a local default termios struct. All ports will be created
355 * with this termios initially.
357 * This defines a raw port at 9600 baud, 8 data bits, no parity,
361 static struct ktermios dgap_default_termios = {
362 .c_iflag = (DEFAULT_IFLAGS), /* iflags */
363 .c_oflag = (DEFAULT_OFLAGS), /* oflags */
364 .c_cflag = (DEFAULT_CFLAGS), /* cflags */
365 .c_lflag = (DEFAULT_LFLAGS), /* lflags */
370 static const struct tty_operations dgap_tty_ops = {
371 .open = dgap_tty_open,
372 .close = dgap_tty_close,
373 .write = dgap_tty_write,
374 .write_room = dgap_tty_write_room,
375 .flush_buffer = dgap_tty_flush_buffer,
376 .chars_in_buffer = dgap_tty_chars_in_buffer,
377 .flush_chars = dgap_tty_flush_chars,
378 .ioctl = dgap_tty_ioctl,
379 .set_termios = dgap_tty_set_termios,
380 .stop = dgap_tty_stop,
381 .start = dgap_tty_start,
382 .throttle = dgap_tty_throttle,
383 .unthrottle = dgap_tty_unthrottle,
384 .hangup = dgap_tty_hangup,
385 .put_char = dgap_tty_put_char,
386 .tiocmget = dgap_tty_tiocmget,
387 .tiocmset = dgap_tty_tiocmset,
388 .break_ctl = dgap_tty_send_break,
389 .wait_until_sent = dgap_tty_wait_until_sent,
390 .send_xchar = dgap_tty_send_xchar
394 * Our needed internal static variables from dgap_parse.c
396 static struct cnode dgap_head;
398 static char dgap_cword[MAXCWORD];
405 static struct toklist dgap_tlist[] = {
406 { BEGIN, "config_begin" },
407 { END, "config_end" },
409 { PCX, "Digi_AccelePort_C/X_PCI" },
410 { PEPC, "Digi_AccelePort_EPC/X_PCI" },
411 { PPCM, "Digi_AccelePort_Xem_PCI" },
412 { APORT2_920P, "Digi_AccelePort_2r_920_PCI" },
413 { APORT4_920P, "Digi_AccelePort_4r_920_PCI" },
414 { APORT8_920P, "Digi_AccelePort_8r_920_PCI" },
415 { PAPORT4, "Digi_AccelePort_4r_PCI(EIA-232/RS-422)" },
416 { PAPORT8, "Digi_AccelePort_8r_PCI(EIA-232/RS-422)" },
418 { PCIINFO, "pciinfo" },
421 { CONC, "concentrator" },
431 { CONNECT, "connect" },
432 { METHOD, "method" },
433 { STATUS, "status" },
434 { CUSTOM, "Custom" },
440 { NPORTS, "nports" },
445 { ALTPIN, "altpin" },
446 { USEINTR, "useintr" },
447 { TTSIZ, "ttysize" },
449 { BSSIZ, "boardsize" },
450 { UNTSIZ, "schedsize" },
451 { F2SIZ, "f2200size" },
452 { VPSIZ, "vpixsize" },
456 /************************************************************************
458 * Driver load/unload functions
460 ************************************************************************/
465 * Module load. This is where it all starts.
467 static int dgap_init_module(void)
471 pr_info("%s, Digi International Part Number %s\n", DG_NAME, DG_PART);
477 rc = dgap_init_pci();
481 rc = dgap_create_driver_sysfiles(&dgap_driver);
485 dgap_driver_state = DRIVER_READY;
491 dgap_cleanup_module();
495 module_init(dgap_init_module);
500 static int dgap_start(void)
504 struct device *device;
507 * make sure that the globals are
508 * init'd before we do anything else
514 pr_info("For the tools package please visit http://www.digi.com\n");
517 * Register our base character device into the kernel.
521 * Register management/dpa devices
523 rc = register_chrdev(DIGI_DGAP_MAJOR, "dgap", &dgap_board_fops);
527 dgap_class = class_create(THIS_MODULE, "dgap_mgmt");
528 if (IS_ERR(dgap_class)) {
529 rc = PTR_ERR(dgap_class);
533 device = device_create(dgap_class, NULL,
534 MKDEV(DIGI_DGAP_MAJOR, 0),
536 if (IS_ERR(device)) {
537 rc = PTR_ERR(device);
541 /* Start the poller */
542 spin_lock_irqsave(&dgap_poll_lock, flags);
543 init_timer(&dgap_poll_timer);
544 dgap_poll_timer.function = dgap_poll_handler;
545 dgap_poll_timer.data = 0;
546 dgap_poll_time = jiffies + dgap_jiffies_from_ms(dgap_poll_tick);
547 dgap_poll_timer.expires = dgap_poll_time;
548 spin_unlock_irqrestore(&dgap_poll_lock, flags);
550 add_timer(&dgap_poll_timer);
555 class_destroy(dgap_class);
557 unregister_chrdev(DIGI_DGAP_MAJOR, "dgap");
562 * Register pci driver, and return how many boards we have.
564 static int dgap_init_pci(void)
566 return pci_register_driver(&dgap_driver);
569 static int dgap_init_one(struct pci_dev *pdev, const struct pci_device_id *ent)
573 if (dgap_numboards >= MAXBOARDS)
576 rc = pci_enable_device(pdev);
580 rc = dgap_probe1(pdev, ent->driver_data);
585 return dgap_firmware_load(pdev, ent->driver_data);
588 static int dgap_probe1(struct pci_dev *pdev, int card_type)
590 return dgap_found_board(pdev, card_type);
593 static void dgap_remove_one(struct pci_dev *dev)
599 * dgap_cleanup_module()
601 * Module unload. This is where it all ends.
603 static void dgap_cleanup_module(void)
608 spin_lock_irqsave(&dgap_poll_lock, lock_flags);
610 spin_unlock_irqrestore(&dgap_poll_lock, lock_flags);
612 /* Turn off poller right away. */
613 del_timer_sync(&dgap_poll_timer);
615 dgap_remove_driver_sysfiles(&dgap_driver);
617 device_destroy(dgap_class, MKDEV(DIGI_DGAP_MAJOR, 0));
618 class_destroy(dgap_class);
619 unregister_chrdev(DIGI_DGAP_MAJOR, "dgap");
621 for (i = 0; i < dgap_numboards; ++i) {
622 dgap_remove_ports_sysfiles(dgap_board[i]);
623 dgap_tty_uninit(dgap_board[i]);
624 dgap_cleanup_board(dgap_board[i]);
628 pci_unregister_driver(&dgap_driver);
632 * dgap_cleanup_board()
634 * Free all the memory associated with a board
636 static void dgap_cleanup_board(struct board_t *brd)
640 if (!brd || brd->magic != DGAP_BOARD_MAGIC)
643 if (brd->intr_used && brd->irq)
644 free_irq(brd->irq, brd);
646 tasklet_kill(&brd->helper_tasklet);
648 if (brd->re_map_port) {
649 release_mem_region(brd->membase + 0x200000, 0x200000);
650 iounmap(brd->re_map_port);
651 brd->re_map_port = NULL;
654 if (brd->re_map_membase) {
655 release_mem_region(brd->membase, 0x200000);
656 iounmap(brd->re_map_membase);
657 brd->re_map_membase = NULL;
660 /* Free all allocated channels structs */
661 for (i = 0; i < MAXPORTS ; i++)
662 kfree(brd->channels[i]);
665 kfree(brd->flipflagbuf);
667 dgap_board[brd->boardnum] = NULL;
675 * A board has been found, init it.
677 static int dgap_found_board(struct pci_dev *pdev, int id)
680 unsigned int pci_irq;
683 /* get the board structure and prep it */
684 brd = kzalloc(sizeof(struct board_t), GFP_KERNEL);
688 dgap_board[dgap_numboards] = brd;
690 /* store the info for the board we've found */
691 brd->magic = DGAP_BOARD_MAGIC;
692 brd->boardnum = dgap_numboards;
694 brd->vendor = dgap_pci_tbl[id].vendor;
695 brd->device = dgap_pci_tbl[id].device;
697 brd->pci_bus = pdev->bus->number;
698 brd->pci_slot = PCI_SLOT(pdev->devfn);
699 brd->name = dgap_ids[id].name;
700 brd->maxports = dgap_ids[id].maxports;
701 brd->type = dgap_ids[id].config_type;
702 brd->dpatype = dgap_ids[id].dpatype;
703 brd->dpastatus = BD_NOFEP;
704 init_waitqueue_head(&brd->state_wait);
706 spin_lock_init(&brd->bd_lock);
709 brd->inhibit_poller = FALSE;
710 brd->wait_for_bios = 0;
711 brd->wait_for_fep = 0;
713 for (i = 0; i < MAXPORTS; i++)
714 brd->channels[i] = NULL;
716 /* store which card & revision we have */
717 pci_read_config_word(pdev, PCI_SUBSYSTEM_VENDOR_ID, &brd->subvendor);
718 pci_read_config_word(pdev, PCI_SUBSYSTEM_ID, &brd->subdevice);
719 pci_read_config_byte(pdev, PCI_REVISION_ID, &brd->rev);
724 /* get the PCI Base Address Registers */
726 /* Xr Jupiter and EPC use BAR 2 */
727 if (brd->device == PCI_DEV_XRJ_DID || brd->device == PCI_DEV_EPCJ_DID) {
728 brd->membase = pci_resource_start(pdev, 2);
729 brd->membase_end = pci_resource_end(pdev, 2);
731 /* Everyone else uses BAR 0 */
733 brd->membase = pci_resource_start(pdev, 0);
734 brd->membase_end = pci_resource_end(pdev, 0);
740 if (brd->membase & 1)
746 * On the PCI boards, there is no IO space allocated
747 * The I/O registers will be in the first 3 bytes of the
748 * upper 2MB of the 4MB memory space. The board memory
749 * will be mapped into the low 2MB of the 4MB memory space
751 brd->port = brd->membase + PCI_IO_OFFSET;
752 brd->port_end = brd->port + PCI_IO_SIZE;
755 * Special initialization for non-PLX boards
757 if (brd->device != PCI_DEV_XRJ_DID && brd->device != PCI_DEV_EPCJ_DID) {
760 pci_write_config_byte(pdev, 0x40, 0);
761 pci_write_config_byte(pdev, 0x46, 0);
763 /* Limit burst length to 2 doubleword transactions */
764 pci_write_config_byte(pdev, 0x42, 1);
767 * Enable IO and mem if not already done.
768 * This was needed for support on Itanium.
770 pci_read_config_word(pdev, PCI_COMMAND, &cmd);
771 cmd |= (PCI_COMMAND_IO | PCI_COMMAND_MEMORY);
772 pci_write_config_word(pdev, PCI_COMMAND, cmd);
775 /* init our poll helper tasklet */
776 tasklet_init(&brd->helper_tasklet, dgap_poll_tasklet,
777 (unsigned long) brd);
779 i = dgap_do_remap(brd);
781 brd->state = BOARD_FAILED;
783 pr_info("dgap: board %d: %s (rev %d), irq %ld\n",
784 dgap_numboards, brd->name, brd->rev, brd->irq);
790 static int dgap_finalize_board_init(struct board_t *brd)
794 if (!brd || brd->magic != DGAP_BOARD_MAGIC)
797 brd->use_interrupts = dgap_config_get_useintr(brd);
800 * Set up our interrupt handler if we are set to do interrupts.
802 if (brd->use_interrupts && brd->irq) {
804 rc = request_irq(brd->irq, dgap_intr, IRQF_SHARED, "DGAP", brd);
817 static int dgap_firmware_load(struct pci_dev *pdev, int card_type)
819 struct board_t *brd = dgap_board[dgap_numboards - 1];
820 const struct firmware *fw;
825 dgap_do_reset_board(brd);
827 if ((fw_info[card_type].conf_name) && !dgap_config_buf) {
828 ret = request_firmware(&fw, fw_info[card_type].conf_name,
831 pr_err("dgap: config file %s not found\n",
832 fw_info[card_type].conf_name);
836 dgap_config_buf = kzalloc(fw->size + 1, GFP_KERNEL);
837 if (!dgap_config_buf) {
838 release_firmware(fw);
842 memcpy(dgap_config_buf, fw->data, fw->size);
843 release_firmware(fw);
846 * preserve dgap_config_buf
847 * as dgap_parsefile would
848 * otherwise alter it.
850 tmp_ptr = dgap_config_buf;
852 if (dgap_parsefile(&tmp_ptr, TRUE) != 0) {
853 kfree(dgap_config_buf);
856 kfree(dgap_config_buf);
859 ret = dgap_after_config_loaded(brd->boardnum);
863 * Match this board to a config the user created for us.
866 dgap_find_config(brd->type, brd->pci_bus, brd->pci_slot);
869 * Because the 4 port Xr products share the same PCI ID
870 * as the 8 port Xr products, if we receive a NULL config
871 * back, and this is a PAPORT8 board, retry with a
872 * PAPORT4 attempt as well.
874 if (brd->type == PAPORT8 && !brd->bd_config)
876 dgap_find_config(PAPORT4, brd->pci_bus, brd->pci_slot);
878 if (!brd->bd_config) {
879 pr_err("dgap: No valid configuration found\n");
883 ret = dgap_tty_register(brd);
887 ret = dgap_finalize_board_init(brd);
891 if (fw_info[card_type].bios_name) {
892 ret = request_firmware(&fw, fw_info[card_type].bios_name,
895 pr_err("dgap: bios file %s not found\n",
896 fw_info[card_type].bios_name);
899 dgap_do_bios_load(brd, fw->data, fw->size);
900 release_firmware(fw);
902 /* Wait for BIOS to test board... */
903 ret = dgap_test_bios(brd);
908 if (fw_info[card_type].fep_name) {
909 ret = request_firmware(&fw, fw_info[card_type].fep_name,
912 pr_err("dgap: fep file %s not found\n",
913 fw_info[card_type].fep_name);
916 dgap_do_fep_load(brd, fw->data, fw->size);
917 release_firmware(fw);
919 /* Wait for FEP to load on board... */
920 ret = dgap_test_fep(brd);
925 #ifdef DIGI_CONCENTRATORS_SUPPORTED
927 * If this is a CX or EPCX, we need to see if the firmware
928 * is requesting a concentrator image from us.
930 if ((bd->type == PCX) || (bd->type == PEPC)) {
931 chk_addr = (u16 *) (vaddr + DOWNREQ);
932 /* Nonzero if FEP is requesting concentrator image. */
933 check = readw(chk_addr);
934 vaddr = brd->re_map_membase;
937 if (fw_info[card_type].con_name && check && vaddr) {
938 ret = request_firmware(&fw, fw_info[card_type].con_name,
941 pr_err("dgap: conc file %s not found\n",
942 fw_info[card_type].con_name);
945 /* Put concentrator firmware loading code here */
946 offset = readw((u16 *) (vaddr + DOWNREQ));
947 memcpy_toio(offset, fw->data, fw->size);
949 dgap_do_conc_load(brd, (char *)fw->data, fw->size)
950 release_firmware(fw);
954 * Do tty device initialization.
956 ret = dgap_tty_init(brd);
958 dgap_tty_uninit(brd);
962 ret = dgap_tty_register_ports(brd);
966 brd->state = BOARD_READY;
967 brd->dpastatus = BD_RUNNING;
975 static int dgap_do_remap(struct board_t *brd)
977 if (!brd || brd->magic != DGAP_BOARD_MAGIC)
980 if (!request_mem_region(brd->membase, 0x200000, "dgap"))
983 if (!request_mem_region(brd->membase + PCI_IO_OFFSET, 0x200000,
985 release_mem_region(brd->membase, 0x200000);
989 brd->re_map_membase = ioremap(brd->membase, 0x200000);
990 if (!brd->re_map_membase) {
991 release_mem_region(brd->membase, 0x200000);
992 release_mem_region(brd->membase + PCI_IO_OFFSET, 0x200000);
996 brd->re_map_port = ioremap((brd->membase + PCI_IO_OFFSET), 0x200000);
997 if (!brd->re_map_port) {
998 release_mem_region(brd->membase, 0x200000);
999 release_mem_region(brd->membase + PCI_IO_OFFSET, 0x200000);
1000 iounmap(brd->re_map_membase);
1007 /*****************************************************************************
1027 * As each timer expires, it determines (a) whether the "transmit"
1028 * waiter needs to be woken up, and (b) whether the poller needs to
1031 ******************************************************************************/
1033 static void dgap_poll_handler(ulong dummy)
1036 struct board_t *brd;
1037 unsigned long lock_flags;
1040 dgap_poll_counter++;
1043 * Do not start the board state machine until
1044 * driver tells us its up and running, and has
1045 * everything it needs.
1047 if (dgap_driver_state != DRIVER_READY)
1048 goto schedule_poller;
1051 * If we have just 1 board, or the system is not SMP,
1052 * then use the typical old style poller.
1053 * Otherwise, use our new tasklet based poller, which should
1054 * speed things up for multiple boards.
1056 if ((dgap_numboards == 1) || (num_online_cpus() <= 1)) {
1057 for (i = 0; i < dgap_numboards; i++) {
1059 brd = dgap_board[i];
1061 if (brd->state == BOARD_FAILED)
1063 if (!brd->intr_running)
1064 /* Call the real board poller directly */
1065 dgap_poll_tasklet((unsigned long) brd);
1069 * Go thru each board, kicking off a
1070 * tasklet for each if needed
1072 for (i = 0; i < dgap_numboards; i++) {
1073 brd = dgap_board[i];
1076 * Attempt to grab the board lock.
1078 * If we can't get it, no big deal, the next poll
1079 * will get it. Basically, I just really don't want
1080 * to spin in here, because I want to kick off my
1081 * tasklets as fast as I can, and then get out the
1084 if (!spin_trylock(&brd->bd_lock))
1088 * If board is in a failed state, don't bother
1089 * scheduling a tasklet
1091 if (brd->state == BOARD_FAILED) {
1092 spin_unlock(&brd->bd_lock);
1096 /* Schedule a poll helper task */
1097 if (!brd->intr_running)
1098 tasklet_schedule(&brd->helper_tasklet);
1101 * Can't do DGAP_UNLOCK here, as we don't have
1102 * lock_flags because we did a trylock above.
1104 spin_unlock(&brd->bd_lock);
1111 * Schedule ourself back at the nominal wakeup interval.
1113 spin_lock_irqsave(&dgap_poll_lock, lock_flags);
1114 dgap_poll_time += dgap_jiffies_from_ms(dgap_poll_tick);
1116 new_time = dgap_poll_time - jiffies;
1118 if ((ulong) new_time >= 2 * dgap_poll_tick) {
1120 jiffies + dgap_jiffies_from_ms(dgap_poll_tick);
1123 dgap_poll_timer.function = dgap_poll_handler;
1124 dgap_poll_timer.data = 0;
1125 dgap_poll_timer.expires = dgap_poll_time;
1126 spin_unlock_irqrestore(&dgap_poll_lock, lock_flags);
1128 if (!dgap_poll_stop)
1129 add_timer(&dgap_poll_timer);
1135 * Driver interrupt handler.
1137 static irqreturn_t dgap_intr(int irq, void *voidbrd)
1139 struct board_t *brd = (struct board_t *) voidbrd;
1145 * Check to make sure its for us.
1147 if (brd->magic != DGAP_BOARD_MAGIC)
1153 * Schedule tasklet to run at a better time.
1155 tasklet_schedule(&brd->helper_tasklet);
1160 * dgap_init_globals()
1162 * This is where we initialize the globals from the static insmod
1163 * configuration variables. These are declared near the head of
1166 static void dgap_init_globals(void)
1170 for (i = 0; i < MAXBOARDS; i++)
1171 dgap_board[i] = NULL;
1173 init_timer(&dgap_poll_timer);
1175 init_waitqueue_head(&dgap_dl_wait);
1178 /************************************************************************
1182 ************************************************************************/
1187 * Put the driver to sleep for x ms's
1189 * Returns 0 if timed out, !0 (showing signal) if interrupted by a signal.
1191 static int dgap_ms_sleep(ulong ms)
1193 current->state = TASK_INTERRUPTIBLE;
1194 schedule_timeout((ms * HZ) / 1000);
1195 return signal_pending(current);
1198 /************************************************************************
1200 * TTY Initialization/Cleanup Functions
1202 ************************************************************************/
1205 * dgap_tty_register()
1207 * Init the tty subsystem for this board.
1209 static int dgap_tty_register(struct board_t *brd)
1213 brd->serial_driver = tty_alloc_driver(MAXPORTS, 0);
1214 if (IS_ERR(brd->serial_driver))
1215 return PTR_ERR(brd->serial_driver);
1217 snprintf(brd->serial_name, MAXTTYNAMELEN, "tty_dgap_%d_",
1219 brd->serial_driver->name = brd->serial_name;
1220 brd->serial_driver->name_base = 0;
1221 brd->serial_driver->major = 0;
1222 brd->serial_driver->minor_start = 0;
1223 brd->serial_driver->type = TTY_DRIVER_TYPE_SERIAL;
1224 brd->serial_driver->subtype = SERIAL_TYPE_NORMAL;
1225 brd->serial_driver->init_termios = dgap_default_termios;
1226 brd->serial_driver->driver_name = DRVSTR;
1227 brd->serial_driver->flags = (TTY_DRIVER_REAL_RAW |
1228 TTY_DRIVER_DYNAMIC_DEV |
1229 TTY_DRIVER_HARDWARE_BREAK);
1231 /* The kernel wants space to store pointers to tty_structs */
1232 brd->serial_driver->ttys =
1233 kzalloc(MAXPORTS * sizeof(struct tty_struct *), GFP_KERNEL);
1234 if (!brd->serial_driver->ttys) {
1236 goto free_serial_drv;
1240 * Entry points for driver. Called by the kernel from
1241 * tty_io.c and n_tty.c.
1243 tty_set_operations(brd->serial_driver, &dgap_tty_ops);
1246 * If we're doing transparent print, we have to do all of the above
1247 * again, separately so we don't get the LD confused about what major
1248 * we are when we get into the dgap_tty_open() routine.
1250 brd->print_driver = tty_alloc_driver(MAXPORTS, 0);
1251 if (IS_ERR(brd->print_driver)) {
1252 rc = PTR_ERR(brd->print_driver);
1253 goto free_serial_drv;
1256 snprintf(brd->print_name, MAXTTYNAMELEN, "pr_dgap_%d_",
1258 brd->print_driver->name = brd->print_name;
1259 brd->print_driver->name_base = 0;
1260 brd->print_driver->major = 0;
1261 brd->print_driver->minor_start = 0;
1262 brd->print_driver->type = TTY_DRIVER_TYPE_SERIAL;
1263 brd->print_driver->subtype = SERIAL_TYPE_NORMAL;
1264 brd->print_driver->init_termios = dgap_default_termios;
1265 brd->print_driver->driver_name = DRVSTR;
1266 brd->print_driver->flags = (TTY_DRIVER_REAL_RAW |
1267 TTY_DRIVER_DYNAMIC_DEV |
1268 TTY_DRIVER_HARDWARE_BREAK);
1270 /* The kernel wants space to store pointers to tty_structs */
1271 brd->print_driver->ttys =
1272 kzalloc(MAXPORTS * sizeof(struct tty_struct *), GFP_KERNEL);
1273 if (!brd->print_driver->ttys) {
1275 goto free_print_drv;
1279 * Entry points for driver. Called by the kernel from
1280 * tty_io.c and n_tty.c.
1282 tty_set_operations(brd->print_driver, &dgap_tty_ops);
1284 /* Register tty devices */
1285 rc = tty_register_driver(brd->serial_driver);
1287 goto free_print_drv;
1289 /* Register Transparent Print devices */
1290 rc = tty_register_driver(brd->print_driver);
1292 goto unregister_serial_drv;
1294 brd->dgap_major_serial_registered = TRUE;
1295 dgap_boards_by_major[brd->serial_driver->major] = brd;
1296 brd->dgap_serial_major = brd->serial_driver->major;
1298 brd->dgap_major_transparent_print_registered = TRUE;
1299 dgap_boards_by_major[brd->print_driver->major] = brd;
1300 brd->dgap_transparent_print_major = brd->print_driver->major;
1304 unregister_serial_drv:
1305 tty_unregister_driver(brd->serial_driver);
1307 put_tty_driver(brd->print_driver);
1309 put_tty_driver(brd->serial_driver);
1317 * Init the tty subsystem. Called once per board after board has been
1318 * downloaded and init'ed.
1320 static int dgap_tty_init(struct board_t *brd)
1327 struct channel_t *ch;
1328 struct bs_t __iomem *bs;
1329 struct cm_t __iomem *cm;
1335 * Initialize board structure elements.
1338 vaddr = brd->re_map_membase;
1339 true_count = readw((vaddr + NCHAN));
1341 brd->nasync = dgap_config_get_num_prts(brd);
1344 brd->nasync = brd->maxports;
1346 if (brd->nasync > brd->maxports)
1347 brd->nasync = brd->maxports;
1349 if (true_count != brd->nasync) {
1350 if ((brd->type == PPCM) && (true_count == 64)) {
1351 pr_warn("dgap: %s configured for %d ports, has %d ports.\n",
1352 brd->name, brd->nasync, true_count);
1353 pr_warn("dgap: Please make SURE the EBI cable running from the card\n");
1354 pr_warn("dgap: to each EM module is plugged into EBI IN!\n");
1355 } else if ((brd->type == PPCM) && (true_count == 0)) {
1356 pr_warn("dgap: %s configured for %d ports, has %d ports.\n",
1357 brd->name, brd->nasync, true_count);
1358 pr_warn("dgap: Please make SURE the EBI cable running from the card\n");
1359 pr_warn("dgap: to each EM module is plugged into EBI IN!\n");
1361 pr_warn("dgap: %s configured for %d ports, has %d ports.\n",
1362 brd->name, brd->nasync, true_count);
1364 brd->nasync = true_count;
1366 /* If no ports, don't bother going any further */
1368 brd->state = BOARD_FAILED;
1369 brd->dpastatus = BD_NOFEP;
1375 * Allocate channel memory that might not have been allocated
1376 * when the driver was first loaded.
1378 for (i = 0; i < brd->nasync; i++) {
1379 if (!brd->channels[i]) {
1381 kzalloc(sizeof(struct channel_t), GFP_KERNEL);
1382 if (!brd->channels[i])
1387 ch = brd->channels[0];
1388 vaddr = brd->re_map_membase;
1390 bs = (struct bs_t __iomem *) ((ulong) vaddr + CHANBUF);
1391 cm = (struct cm_t __iomem *) ((ulong) vaddr + CMDBUF);
1395 /* Set up channel variables */
1396 for (i = 0; i < brd->nasync; i++, ch = brd->channels[i], bs++) {
1398 if (!brd->channels[i])
1401 spin_lock_init(&ch->ch_lock);
1403 /* Store all our magic numbers */
1404 ch->magic = DGAP_CHANNEL_MAGIC;
1405 ch->ch_tun.magic = DGAP_UNIT_MAGIC;
1406 ch->ch_tun.un_type = DGAP_SERIAL;
1407 ch->ch_tun.un_ch = ch;
1408 ch->ch_tun.un_dev = i;
1410 ch->ch_pun.magic = DGAP_UNIT_MAGIC;
1411 ch->ch_pun.un_type = DGAP_PRINT;
1412 ch->ch_pun.un_ch = ch;
1413 ch->ch_pun.un_dev = i;
1415 ch->ch_vaddr = vaddr;
1420 ch->ch_digi = dgap_digi_init;
1423 * Set up digi dsr and dcd bits based on altpin flag.
1425 if (dgap_config_get_altpin(brd)) {
1428 ch->ch_digi.digi_flags |= DIGI_ALTPIN;
1431 ch->ch_dsr = DM_DSR;
1434 ch->ch_taddr = vaddr + (ioread16(&(ch->ch_bs->tx_seg)) << 4);
1435 ch->ch_raddr = vaddr + (ioread16(&(ch->ch_bs->rx_seg)) << 4);
1438 ch->ch_tsize = readw(&(ch->ch_bs->tx_max)) + 1;
1439 ch->ch_rsize = readw(&(ch->ch_bs->rx_max)) + 1;
1443 /* .25 second delay */
1444 ch->ch_close_delay = 250;
1447 * Set queue water marks, interrupt mask,
1448 * and general tty parameters.
1450 tlw = ch->ch_tsize >= 2000 ? ((ch->ch_tsize * 5) / 8) :
1454 dgap_cmdw(ch, STLOW, tlw, 0);
1456 dgap_cmdw(ch, SRLOW, ch->ch_rsize / 2, 0);
1458 dgap_cmdw(ch, SRHIGH, 7 * ch->ch_rsize / 8, 0);
1460 ch->ch_mistat = readb(&(ch->ch_bs->m_stat));
1462 init_waitqueue_head(&ch->ch_flags_wait);
1463 init_waitqueue_head(&ch->ch_tun.un_flags_wait);
1464 init_waitqueue_head(&ch->ch_pun.un_flags_wait);
1466 /* Turn on all modem interrupts for now */
1467 modem = (DM_CD | DM_DSR | DM_CTS | DM_RI);
1468 writeb(modem, &(ch->ch_bs->m_int));
1471 * Set edelay to 0 if interrupts are turned on,
1472 * otherwise set edelay to the usual 100.
1475 writew(0, &(ch->ch_bs->edelay));
1477 writew(100, &(ch->ch_bs->edelay));
1479 writeb(1, &(ch->ch_bs->idata));
1488 * Uninitialize the TTY portion of this driver. Free all memory and
1491 static void dgap_tty_uninit(struct board_t *brd)
1496 if (brd->dgap_major_serial_registered) {
1497 dgap_boards_by_major[brd->serial_driver->major] = NULL;
1498 brd->dgap_serial_major = 0;
1499 for (i = 0; i < brd->nasync; i++) {
1500 tty_port_destroy(&brd->serial_ports[i]);
1501 dev = brd->channels[i]->ch_tun.un_sysfs;
1502 dgap_remove_tty_sysfs(dev);
1503 tty_unregister_device(brd->serial_driver, i);
1505 tty_unregister_driver(brd->serial_driver);
1506 put_tty_driver(brd->serial_driver);
1507 kfree(brd->serial_ports);
1508 brd->dgap_major_serial_registered = FALSE;
1511 if (brd->dgap_major_transparent_print_registered) {
1512 dgap_boards_by_major[brd->print_driver->major] = NULL;
1513 brd->dgap_transparent_print_major = 0;
1514 for (i = 0; i < brd->nasync; i++) {
1515 tty_port_destroy(&brd->printer_ports[i]);
1516 dev = brd->channels[i]->ch_pun.un_sysfs;
1517 dgap_remove_tty_sysfs(dev);
1518 tty_unregister_device(brd->print_driver, i);
1520 tty_unregister_driver(brd->print_driver);
1521 put_tty_driver(brd->print_driver);
1522 kfree(brd->printer_ports);
1523 brd->dgap_major_transparent_print_registered = FALSE;
1527 /*=======================================================================
1529 * dgap_input - Process received data.
1531 * ch - Pointer to channel structure.
1533 *=======================================================================*/
1535 static void dgap_input(struct channel_t *ch)
1538 struct bs_t __iomem *bs;
1539 struct tty_struct *tp;
1540 struct tty_ldisc *ld;
1554 if (!ch || ch->magic != DGAP_CHANNEL_MAGIC)
1557 tp = ch->ch_tun.un_tty;
1564 if (!bd || bd->magic != DGAP_BOARD_MAGIC)
1567 spin_lock_irqsave(&bd->bd_lock, lock_flags);
1568 spin_lock_irqsave(&ch->ch_lock, lock_flags2);
1571 * Figure the number of characters in the buffer.
1572 * Exit immediately if none.
1575 rmask = ch->ch_rsize - 1;
1577 head = readw(&(bs->rx_head));
1579 tail = readw(&(bs->rx_tail));
1582 data_len = (head - tail) & rmask;
1584 if (data_len == 0) {
1585 writeb(1, &(bs->idata));
1586 spin_unlock_irqrestore(&ch->ch_lock, lock_flags2);
1587 spin_unlock_irqrestore(&bd->bd_lock, lock_flags);
1592 * If the device is not open, or CREAD is off, flush
1593 * input data and return immediately.
1595 if ((bd->state != BOARD_READY) || !tp ||
1596 (tp->magic != TTY_MAGIC) ||
1597 !(ch->ch_tun.un_flags & UN_ISOPEN) ||
1598 !(tp->termios.c_cflag & CREAD) ||
1599 (ch->ch_tun.un_flags & UN_CLOSING)) {
1601 writew(head, &(bs->rx_tail));
1602 writeb(1, &(bs->idata));
1603 spin_unlock_irqrestore(&ch->ch_lock, lock_flags2);
1604 spin_unlock_irqrestore(&bd->bd_lock, lock_flags);
1609 * If we are throttled, simply don't read any data.
1611 if (ch->ch_flags & CH_RXBLOCK) {
1612 writeb(1, &(bs->idata));
1613 spin_unlock_irqrestore(&ch->ch_lock, lock_flags2);
1614 spin_unlock_irqrestore(&bd->bd_lock, lock_flags);
1621 tmpchar = readb(&(bs->orun));
1623 ch->ch_err_overrun++;
1624 writeb(0, &(bs->orun));
1627 /* Decide how much data we can send into the tty layer */
1628 flip_len = TTY_FLIPBUF_SIZE;
1630 /* Chop down the length, if needed */
1631 len = min(data_len, flip_len);
1632 len = min(len, (N_TTY_BUF_SIZE - 1));
1634 ld = tty_ldisc_ref(tp);
1636 #ifdef TTY_DONT_FLIP
1638 * If the DONT_FLIP flag is on, don't flush our buffer, and act
1639 * like the ld doesn't have any space to put the data right now.
1641 if (test_bit(TTY_DONT_FLIP, &tp->flags))
1646 * If we were unable to get a reference to the ld,
1647 * don't flush our buffer, and act like the ld doesn't
1648 * have any space to put the data right now.
1654 * If ld doesn't have a pointer to a receive_buf function,
1655 * flush the data, then act like the ld doesn't have any
1656 * space to put the data right now.
1658 if (!ld->ops->receive_buf) {
1659 writew(head, &(bs->rx_tail));
1665 writeb(1, &(bs->idata));
1666 spin_unlock_irqrestore(&ch->ch_lock, lock_flags2);
1667 spin_unlock_irqrestore(&bd->bd_lock, lock_flags);
1669 tty_ldisc_deref(ld);
1673 buf = ch->ch_bd->flipbuf;
1677 * n now contains the most amount of data we can copy,
1678 * bounded either by our buffer size or the amount
1679 * of data the card actually has pending...
1683 s = ((head >= tail) ? head : ch->ch_rsize) - tail;
1689 memcpy_fromio(buf, ch->ch_raddr + tail, s);
1695 /* Flip queue if needed */
1699 writew(tail, &(bs->rx_tail));
1700 writeb(1, &(bs->idata));
1701 ch->ch_rxcount += len;
1704 * If we are completely raw, we don't need to go through a lot
1705 * of the tty layers that exist.
1706 * In this case, we take the shortest and fastest route we
1707 * can to relay the data to the user.
1709 * On the other hand, if we are not raw, we need to go through
1710 * the tty layer, which has its API more well defined.
1712 if (I_PARMRK(tp) || I_BRKINT(tp) || I_INPCK(tp)) {
1713 dgap_parity_scan(ch, ch->ch_bd->flipbuf,
1714 ch->ch_bd->flipflagbuf, &len);
1716 len = tty_buffer_request_room(tp->port, len);
1717 tty_insert_flip_string_flags(tp->port, ch->ch_bd->flipbuf,
1718 ch->ch_bd->flipflagbuf, len);
1720 len = tty_buffer_request_room(tp->port, len);
1721 tty_insert_flip_string(tp->port, ch->ch_bd->flipbuf, len);
1724 spin_unlock_irqrestore(&ch->ch_lock, lock_flags2);
1725 spin_unlock_irqrestore(&bd->bd_lock, lock_flags);
1727 /* Tell the tty layer its okay to "eat" the data now */
1728 tty_flip_buffer_push(tp->port);
1731 tty_ldisc_deref(ld);
1735 /************************************************************************
1736 * Determines when CARRIER changes state and takes appropriate
1738 ************************************************************************/
1739 static void dgap_carrier(struct channel_t *ch)
1743 int virt_carrier = 0;
1744 int phys_carrier = 0;
1746 if (!ch || ch->magic != DGAP_CHANNEL_MAGIC)
1751 if (!bd || bd->magic != DGAP_BOARD_MAGIC)
1754 /* Make sure altpin is always set correctly */
1755 if (ch->ch_digi.digi_flags & DIGI_ALTPIN) {
1759 ch->ch_dsr = DM_DSR;
1763 if (ch->ch_mistat & D_CD(ch))
1766 if (ch->ch_digi.digi_flags & DIGI_FORCEDCD)
1769 if (ch->ch_c_cflag & CLOCAL)
1773 * Test for a VIRTUAL carrier transition to HIGH.
1775 if (((ch->ch_flags & CH_FCAR) == 0) && (virt_carrier == 1)) {
1778 * When carrier rises, wake any threads waiting
1779 * for carrier in the open routine.
1782 if (waitqueue_active(&(ch->ch_flags_wait)))
1783 wake_up_interruptible(&ch->ch_flags_wait);
1787 * Test for a PHYSICAL carrier transition to HIGH.
1789 if (((ch->ch_flags & CH_CD) == 0) && (phys_carrier == 1)) {
1792 * When carrier rises, wake any threads waiting
1793 * for carrier in the open routine.
1796 if (waitqueue_active(&(ch->ch_flags_wait)))
1797 wake_up_interruptible(&ch->ch_flags_wait);
1801 * Test for a PHYSICAL transition to low, so long as we aren't
1802 * currently ignoring physical transitions (which is what "virtual
1803 * carrier" indicates).
1805 * The transition of the virtual carrier to low really doesn't
1806 * matter... it really only means "ignore carrier state", not
1807 * "make pretend that carrier is there".
1809 if ((virt_carrier == 0) &&
1810 ((ch->ch_flags & CH_CD) != 0) &&
1811 (phys_carrier == 0)) {
1814 * When carrier drops:
1816 * Drop carrier on all open units.
1818 * Flush queues, waking up any task waiting in the
1821 * Send a hangup to the control terminal.
1823 * Enable all select calls.
1825 if (waitqueue_active(&(ch->ch_flags_wait)))
1826 wake_up_interruptible(&ch->ch_flags_wait);
1828 if (ch->ch_tun.un_open_count > 0)
1829 tty_hangup(ch->ch_tun.un_tty);
1831 if (ch->ch_pun.un_open_count > 0)
1832 tty_hangup(ch->ch_pun.un_tty);
1836 * Make sure that our cached values reflect the current reality.
1838 if (virt_carrier == 1)
1839 ch->ch_flags |= CH_FCAR;
1841 ch->ch_flags &= ~CH_FCAR;
1843 if (phys_carrier == 1)
1844 ch->ch_flags |= CH_CD;
1846 ch->ch_flags &= ~CH_CD;
1849 /************************************************************************
1851 * TTY Entry points and helper functions
1853 ************************************************************************/
1859 static int dgap_tty_open(struct tty_struct *tty, struct file *file)
1861 struct board_t *brd;
1862 struct channel_t *ch;
1864 struct bs_t __iomem *bs;
1872 major = MAJOR(tty_devnum(tty));
1873 minor = MINOR(tty_devnum(tty));
1878 /* Get board pointer from our array of majors we have allocated */
1879 brd = dgap_boards_by_major[major];
1884 * If board is not yet up to a state of READY, go to
1885 * sleep waiting for it to happen or they cancel the open.
1887 rc = wait_event_interruptible(brd->state_wait,
1888 (brd->state & BOARD_READY));
1893 spin_lock_irqsave(&brd->bd_lock, lock_flags);
1895 /* The wait above should guarantee this cannot happen */
1896 if (brd->state != BOARD_READY) {
1897 spin_unlock_irqrestore(&brd->bd_lock, lock_flags);
1901 /* If opened device is greater than our number of ports, bail. */
1902 if (MINOR(tty_devnum(tty)) > brd->nasync) {
1903 spin_unlock_irqrestore(&brd->bd_lock, lock_flags);
1907 ch = brd->channels[minor];
1909 spin_unlock_irqrestore(&brd->bd_lock, lock_flags);
1913 /* Grab channel lock */
1914 spin_lock_irqsave(&ch->ch_lock, lock_flags2);
1916 /* Figure out our type */
1917 if (major == brd->dgap_serial_major) {
1918 un = &brd->channels[minor]->ch_tun;
1919 un->un_type = DGAP_SERIAL;
1920 } else if (major == brd->dgap_transparent_print_major) {
1921 un = &brd->channels[minor]->ch_pun;
1922 un->un_type = DGAP_PRINT;
1924 spin_unlock_irqrestore(&ch->ch_lock, lock_flags2);
1925 spin_unlock_irqrestore(&brd->bd_lock, lock_flags);
1929 /* Store our unit into driver_data, so we always have it available. */
1930 tty->driver_data = un;
1933 * Error if channel info pointer is NULL.
1937 spin_unlock_irqrestore(&ch->ch_lock, lock_flags2);
1938 spin_unlock_irqrestore(&brd->bd_lock, lock_flags);
1945 if (!(un->un_flags & UN_ISOPEN)) {
1946 /* Store important variables. */
1949 /* Maybe do something here to the TTY struct as well? */
1953 * Initialize if neither terminal or printer is open.
1955 if (!((ch->ch_tun.un_flags | ch->ch_pun.un_flags) & UN_ISOPEN)) {
1961 * Flush input queue.
1963 head = readw(&(bs->rx_head));
1964 writew(head, &(bs->rx_tail));
1967 ch->pscan_state = 0;
1968 ch->pscan_savechar = 0;
1970 ch->ch_c_cflag = tty->termios.c_cflag;
1971 ch->ch_c_iflag = tty->termios.c_iflag;
1972 ch->ch_c_oflag = tty->termios.c_oflag;
1973 ch->ch_c_lflag = tty->termios.c_lflag;
1974 ch->ch_startc = tty->termios.c_cc[VSTART];
1975 ch->ch_stopc = tty->termios.c_cc[VSTOP];
1977 /* TODO: flush our TTY struct here? */
1982 * Run param in case we changed anything
1987 * follow protocol for opening port
1990 spin_unlock_irqrestore(&ch->ch_lock, lock_flags2);
1991 spin_unlock_irqrestore(&brd->bd_lock, lock_flags);
1993 rc = dgap_block_til_ready(tty, file, ch);
1998 /* No going back now, increment our unit and channel counters */
1999 spin_lock_irqsave(&ch->ch_lock, lock_flags);
2000 ch->ch_open_count++;
2001 un->un_open_count++;
2002 un->un_flags |= (UN_ISOPEN);
2003 spin_unlock_irqrestore(&ch->ch_lock, lock_flags);
2009 * dgap_block_til_ready()
2011 * Wait for DCD, if needed.
2013 static int dgap_block_til_ready(struct tty_struct *tty, struct file *file,
2014 struct channel_t *ch)
2020 int sleep_on_un_flags;
2022 if (!tty || tty->magic != TTY_MAGIC || !file || !ch ||
2023 ch->magic != DGAP_CHANNEL_MAGIC)
2026 un = tty->driver_data;
2027 if (!un || un->magic != DGAP_UNIT_MAGIC)
2030 spin_lock_irqsave(&ch->ch_lock, lock_flags);
2037 sleep_on_un_flags = 0;
2040 * If board has failed somehow during our sleep,
2043 if (ch->ch_bd->state == BOARD_FAILED) {
2048 /* If tty was hung up, break out of loop and set error. */
2049 if (tty_hung_up_p(file)) {
2055 * If either unit is in the middle of the fragile part of close,
2056 * we just cannot touch the channel safely.
2057 * Go back to sleep, knowing that when the channel can be
2058 * touched safely, the close routine will signal the
2059 * ch_wait_flags to wake us back up.
2061 if (!((ch->ch_tun.un_flags | ch->ch_pun.un_flags) &
2065 * Our conditions to leave cleanly and happily:
2066 * 1) NONBLOCKING on the tty is set.
2068 * 3) DCD (fake or real) is active.
2071 if (file->f_flags & O_NONBLOCK)
2074 if (tty->flags & (1 << TTY_IO_ERROR))
2077 if (ch->ch_flags & CH_CD)
2080 if (ch->ch_flags & CH_FCAR)
2083 sleep_on_un_flags = 1;
2087 * If there is a signal pending, the user probably
2088 * interrupted (ctrl-c) us.
2089 * Leave loop with error set.
2091 if (signal_pending(current)) {
2092 retval = -ERESTARTSYS;
2097 * Store the flags before we let go of channel lock
2099 if (sleep_on_un_flags)
2100 old_flags = ch->ch_tun.un_flags | ch->ch_pun.un_flags;
2102 old_flags = ch->ch_flags;
2105 * Let go of channel lock before calling schedule.
2106 * Our poller will get any FEP events and wake us up when DCD
2107 * eventually goes active.
2110 spin_unlock_irqrestore(&ch->ch_lock, lock_flags);
2113 * Wait for something in the flags to change
2114 * from the current value.
2116 if (sleep_on_un_flags) {
2117 retval = wait_event_interruptible(un->un_flags_wait,
2118 (old_flags != (ch->ch_tun.un_flags |
2119 ch->ch_pun.un_flags)));
2121 retval = wait_event_interruptible(ch->ch_flags_wait,
2122 (old_flags != ch->ch_flags));
2126 * We got woken up for some reason.
2127 * Before looping around, grab our channel lock.
2129 spin_lock_irqsave(&ch->ch_lock, lock_flags);
2134 spin_unlock_irqrestore(&ch->ch_lock, lock_flags);
2145 * Hangup the port. Like a close, but don't wait for output to drain.
2147 static void dgap_tty_hangup(struct tty_struct *tty)
2150 struct channel_t *ch;
2153 if (!tty || tty->magic != TTY_MAGIC)
2156 un = tty->driver_data;
2157 if (!un || un->magic != DGAP_UNIT_MAGIC)
2161 if (!ch || ch->magic != DGAP_CHANNEL_MAGIC)
2165 if (!bd || bd->magic != DGAP_BOARD_MAGIC)
2168 /* flush the transmit queues */
2169 dgap_tty_flush_buffer(tty);
2176 static void dgap_tty_close(struct tty_struct *tty, struct file *file)
2178 struct ktermios *ts;
2180 struct channel_t *ch;
2184 if (!tty || tty->magic != TTY_MAGIC)
2187 un = tty->driver_data;
2188 if (!un || un->magic != DGAP_UNIT_MAGIC)
2192 if (!ch || ch->magic != DGAP_CHANNEL_MAGIC)
2196 if (!bd || bd->magic != DGAP_BOARD_MAGIC)
2201 spin_lock_irqsave(&ch->ch_lock, lock_flags);
2204 * Determine if this is the last close or not - and if we agree about
2205 * which type of close it is with the Line Discipline
2207 if ((tty->count == 1) && (un->un_open_count != 1)) {
2209 * Uh, oh. tty->count is 1, which means that the tty
2210 * structure will be freed. un_open_count should always
2211 * be one in these conditions. If it's greater than
2212 * one, we've got real problems, since it means the
2213 * serial port won't be shutdown.
2215 un->un_open_count = 1;
2218 if (--un->un_open_count < 0)
2219 un->un_open_count = 0;
2221 ch->ch_open_count--;
2223 if (ch->ch_open_count && un->un_open_count) {
2224 spin_unlock_irqrestore(&ch->ch_lock, lock_flags);
2228 /* OK, its the last close on the unit */
2230 un->un_flags |= UN_CLOSING;
2235 * Only officially close channel if count is 0 and
2236 * DIGI_PRINTER bit is not set.
2238 if ((ch->ch_open_count == 0) &&
2239 !(ch->ch_digi.digi_flags & DIGI_PRINTER)) {
2241 ch->ch_flags &= ~(CH_RXBLOCK);
2243 spin_unlock_irqrestore(&ch->ch_lock, lock_flags);
2245 /* wait for output to drain */
2246 /* This will also return if we take an interrupt */
2248 dgap_wait_for_drain(tty);
2250 dgap_tty_flush_buffer(tty);
2251 tty_ldisc_flush(tty);
2253 spin_lock_irqsave(&ch->ch_lock, lock_flags);
2258 * If we have HUPCL set, lower DTR and RTS
2260 if (ch->ch_c_cflag & HUPCL) {
2261 ch->ch_mostat &= ~(D_RTS(ch)|D_DTR(ch));
2262 dgap_cmdb(ch, SMODEM, 0, D_DTR(ch)|D_RTS(ch), 0);
2265 * Go to sleep to ensure RTS/DTR
2266 * have been dropped for modems to see it.
2268 if (ch->ch_close_delay) {
2269 spin_unlock_irqrestore(&ch->ch_lock,
2271 dgap_ms_sleep(ch->ch_close_delay);
2272 spin_lock_irqsave(&ch->ch_lock, lock_flags);
2276 ch->pscan_state = 0;
2277 ch->pscan_savechar = 0;
2278 ch->ch_baud_info = 0;
2283 * turn off print device when closing print device.
2285 if ((un->un_type == DGAP_PRINT) && (ch->ch_flags & CH_PRON)) {
2286 dgap_wmove(ch, ch->ch_digi.digi_offstr,
2287 (int) ch->ch_digi.digi_offlen);
2288 ch->ch_flags &= ~CH_PRON;
2292 un->un_flags &= ~(UN_ISOPEN | UN_CLOSING);
2293 tty->driver_data = NULL;
2295 wake_up_interruptible(&ch->ch_flags_wait);
2296 wake_up_interruptible(&un->un_flags_wait);
2298 spin_unlock_irqrestore(&ch->ch_lock, lock_flags);
2302 * dgap_tty_chars_in_buffer()
2304 * Return number of characters that have not been transmitted yet.
2306 * This routine is used by the line discipline to determine if there
2307 * is data waiting to be transmitted/drained/flushed or not.
2309 static int dgap_tty_chars_in_buffer(struct tty_struct *tty)
2312 struct channel_t *ch;
2314 struct bs_t __iomem *bs;
2317 u16 thead, ttail, tmask, chead, ctail;
2318 ulong lock_flags = 0;
2319 ulong lock_flags2 = 0;
2324 un = tty->driver_data;
2325 if (!un || un->magic != DGAP_UNIT_MAGIC)
2329 if (!ch || ch->magic != DGAP_CHANNEL_MAGIC)
2333 if (!bd || bd->magic != DGAP_BOARD_MAGIC)
2340 spin_lock_irqsave(&bd->bd_lock, lock_flags);
2341 spin_lock_irqsave(&ch->ch_lock, lock_flags2);
2343 tmask = (ch->ch_tsize - 1);
2345 /* Get Transmit queue pointers */
2346 thead = readw(&(bs->tx_head)) & tmask;
2347 ttail = readw(&(bs->tx_tail)) & tmask;
2349 /* Get tbusy flag */
2350 tbusy = readb(&(bs->tbusy));
2352 /* Get Command queue pointers */
2353 chead = readw(&(ch->ch_cm->cm_head));
2354 ctail = readw(&(ch->ch_cm->cm_tail));
2356 spin_unlock_irqrestore(&ch->ch_lock, lock_flags2);
2357 spin_unlock_irqrestore(&bd->bd_lock, lock_flags);
2360 * The only way we know for sure if there is no pending
2361 * data left to be transferred, is if:
2362 * 1) Transmit head and tail are equal (empty).
2363 * 2) Command queue head and tail are equal (empty).
2364 * 3) The "TBUSY" flag is 0. (Transmitter not busy).
2367 if ((ttail == thead) && (tbusy == 0) && (chead == ctail)) {
2371 chars = thead - ttail;
2373 chars = thead - ttail + ch->ch_tsize;
2375 * Fudge factor here.
2376 * If chars is zero, we know that the command queue had
2377 * something in it or tbusy was set. Because we cannot
2378 * be sure if there is still some data to be transmitted,
2379 * lets lie, and tell ld we have 1 byte left.
2383 * If TBUSY is still set, and our tx buffers are empty,
2384 * force the firmware to send me another wakeup after
2385 * TBUSY has been cleared.
2388 spin_lock_irqsave(&ch->ch_lock, lock_flags);
2389 un->un_flags |= UN_EMPTY;
2390 writeb(1, &(bs->iempty));
2391 spin_unlock_irqrestore(&ch->ch_lock,
2401 static int dgap_wait_for_drain(struct tty_struct *tty)
2403 struct channel_t *ch;
2405 struct bs_t __iomem *bs;
2408 ulong lock_flags = 0;
2410 if (!tty || tty->magic != TTY_MAGIC)
2413 un = tty->driver_data;
2414 if (!un || un->magic != DGAP_UNIT_MAGIC)
2418 if (!ch || ch->magic != DGAP_CHANNEL_MAGIC)
2425 /* Loop until data is drained */
2426 while (count != 0) {
2428 count = dgap_tty_chars_in_buffer(tty);
2433 /* Set flag waiting for drain */
2434 spin_lock_irqsave(&ch->ch_lock, lock_flags);
2435 un->un_flags |= UN_EMPTY;
2436 writeb(1, &(bs->iempty));
2437 spin_unlock_irqrestore(&ch->ch_lock, lock_flags);
2439 /* Go to sleep till we get woken up */
2440 ret = wait_event_interruptible(un->un_flags_wait,
2441 ((un->un_flags & UN_EMPTY) == 0));
2442 /* If ret is non-zero, user ctrl-c'ed us */
2447 spin_lock_irqsave(&ch->ch_lock, lock_flags);
2448 un->un_flags &= ~(UN_EMPTY);
2449 spin_unlock_irqrestore(&ch->ch_lock, lock_flags);
2457 * Reduces bytes_available to the max number of characters
2458 * that can be sent currently given the maxcps value, and
2459 * returns the new bytes_available. This only affects printer
2462 static int dgap_maxcps_room(struct tty_struct *tty, int bytes_available)
2464 struct channel_t *ch;
2468 return bytes_available;
2470 un = tty->driver_data;
2471 if (!un || un->magic != DGAP_UNIT_MAGIC)
2472 return bytes_available;
2475 if (!ch || ch->magic != DGAP_CHANNEL_MAGIC)
2476 return bytes_available;
2479 * If its not the Transparent print device, return
2480 * the full data amount.
2482 if (un->un_type != DGAP_PRINT)
2483 return bytes_available;
2485 if (ch->ch_digi.digi_maxcps > 0 && ch->ch_digi.digi_bufsize > 0) {
2487 unsigned long current_time = jiffies;
2488 unsigned long buffer_time = current_time +
2489 (HZ * ch->ch_digi.digi_bufsize) /
2490 ch->ch_digi.digi_maxcps;
2492 if (ch->ch_cpstime < current_time) {
2493 /* buffer is empty */
2494 ch->ch_cpstime = current_time; /* reset ch_cpstime */
2495 cps_limit = ch->ch_digi.digi_bufsize;
2496 } else if (ch->ch_cpstime < buffer_time) {
2497 /* still room in the buffer */
2498 cps_limit = ((buffer_time - ch->ch_cpstime) *
2499 ch->ch_digi.digi_maxcps) / HZ;
2501 /* no room in the buffer */
2505 bytes_available = min(cps_limit, bytes_available);
2508 return bytes_available;
2511 static inline void dgap_set_firmware_event(struct un_t *un, unsigned int event)
2513 struct channel_t *ch;
2514 struct bs_t __iomem *bs;
2516 if (!un || un->magic != DGAP_UNIT_MAGIC)
2519 if (!ch || ch->magic != DGAP_CHANNEL_MAGIC)
2525 if ((event & UN_LOW) != 0) {
2526 if ((un->un_flags & UN_LOW) == 0) {
2527 un->un_flags |= UN_LOW;
2528 writeb(1, &(bs->ilow));
2531 if ((event & UN_LOW) != 0) {
2532 if ((un->un_flags & UN_EMPTY) == 0) {
2533 un->un_flags |= UN_EMPTY;
2534 writeb(1, &(bs->iempty));
2540 * dgap_tty_write_room()
2542 * Return space available in Tx buffer
2544 static int dgap_tty_write_room(struct tty_struct *tty)
2546 struct channel_t *ch;
2548 struct bs_t __iomem *bs;
2549 u16 head, tail, tmask;
2551 ulong lock_flags = 0;
2556 un = tty->driver_data;
2557 if (!un || un->magic != DGAP_UNIT_MAGIC)
2561 if (!ch || ch->magic != DGAP_CHANNEL_MAGIC)
2568 spin_lock_irqsave(&ch->ch_lock, lock_flags);
2570 tmask = ch->ch_tsize - 1;
2571 head = readw(&(bs->tx_head)) & tmask;
2572 tail = readw(&(bs->tx_tail)) & tmask;
2574 ret = tail - head - 1;
2576 ret += ch->ch_tsize;
2578 /* Limit printer to maxcps */
2579 ret = dgap_maxcps_room(tty, ret);
2582 * If we are printer device, leave space for
2583 * possibly both the on and off strings.
2585 if (un->un_type == DGAP_PRINT) {
2586 if (!(ch->ch_flags & CH_PRON))
2587 ret -= ch->ch_digi.digi_onlen;
2588 ret -= ch->ch_digi.digi_offlen;
2590 if (ch->ch_flags & CH_PRON)
2591 ret -= ch->ch_digi.digi_offlen;
2598 * Schedule FEP to wake us up if needed.
2600 * TODO: This might be overkill...
2601 * Do we really need to schedule callbacks from the FEP
2602 * in every case? Can we get smarter based on ret?
2604 dgap_set_firmware_event(un, UN_LOW | UN_EMPTY);
2605 spin_unlock_irqrestore(&ch->ch_lock, lock_flags);
2611 * dgap_tty_put_char()
2613 * Put a character into ch->ch_buf
2615 * - used by the line discipline for OPOST processing
2617 static int dgap_tty_put_char(struct tty_struct *tty, unsigned char c)
2620 * Simply call tty_write.
2622 dgap_tty_write(tty, &c, 1);
2629 * Take data from the user or kernel and send it out to the FEP.
2630 * In here exists all the Transparent Print magic as well.
2632 static int dgap_tty_write(struct tty_struct *tty, const unsigned char *buf,
2635 struct channel_t *ch;
2637 struct bs_t __iomem *bs;
2638 char __iomem *vaddr;
2639 u16 head, tail, tmask, remain;
2647 un = tty->driver_data;
2648 if (!un || un->magic != DGAP_UNIT_MAGIC)
2652 if (!ch || ch->magic != DGAP_CHANNEL_MAGIC)
2663 * Store original amount of characters passed in.
2664 * This helps to figure out if we should ask the FEP
2665 * to send us an event when it has more space available.
2669 spin_lock_irqsave(&ch->ch_lock, lock_flags);
2671 /* Get our space available for the channel from the board */
2672 tmask = ch->ch_tsize - 1;
2673 head = readw(&(bs->tx_head)) & tmask;
2674 tail = readw(&(bs->tx_tail)) & tmask;
2676 bufcount = tail - head - 1;
2678 bufcount += ch->ch_tsize;
2681 * Limit printer output to maxcps overall, with bursts allowed
2682 * up to bufsize characters.
2684 bufcount = dgap_maxcps_room(tty, bufcount);
2687 * Take minimum of what the user wants to send, and the
2688 * space available in the FEP buffer.
2690 count = min(count, bufcount);
2693 * Bail if no space left.
2696 dgap_set_firmware_event(un, UN_LOW | UN_EMPTY);
2697 spin_unlock_irqrestore(&ch->ch_lock, lock_flags);
2702 * Output the printer ON string, if we are in terminal mode, but
2703 * need to be in printer mode.
2705 if ((un->un_type == DGAP_PRINT) && !(ch->ch_flags & CH_PRON)) {
2706 dgap_wmove(ch, ch->ch_digi.digi_onstr,
2707 (int) ch->ch_digi.digi_onlen);
2708 head = readw(&(bs->tx_head)) & tmask;
2709 ch->ch_flags |= CH_PRON;
2713 * On the other hand, output the printer OFF string, if we are
2714 * currently in printer mode, but need to output to the terminal.
2716 if ((un->un_type != DGAP_PRINT) && (ch->ch_flags & CH_PRON)) {
2717 dgap_wmove(ch, ch->ch_digi.digi_offstr,
2718 (int) ch->ch_digi.digi_offlen);
2719 head = readw(&(bs->tx_head)) & tmask;
2720 ch->ch_flags &= ~CH_PRON;
2726 * If the write wraps over the top of the circular buffer,
2727 * move the portion up to the wrap point, and reset the
2728 * pointers to the bottom.
2730 remain = ch->ch_tstart + ch->ch_tsize - head;
2734 vaddr = ch->ch_taddr + head;
2736 memcpy_toio(vaddr, (u8 *) buf, remain);
2738 head = ch->ch_tstart;
2745 * Move rest of data.
2747 vaddr = ch->ch_taddr + head;
2750 memcpy_toio(vaddr, (u8 *) buf, remain);
2756 ch->ch_txcount += count;
2758 writew(head, &(bs->tx_head));
2761 dgap_set_firmware_event(un, UN_LOW | UN_EMPTY);
2764 * If this is the print device, and the
2765 * printer is still on, we need to turn it
2766 * off before going idle. If the buffer is
2767 * non-empty, wait until it goes empty.
2768 * Otherwise turn it off right now.
2770 if ((un->un_type == DGAP_PRINT) && (ch->ch_flags & CH_PRON)) {
2771 tail = readw(&(bs->tx_tail)) & tmask;
2774 un->un_flags |= UN_EMPTY;
2775 writeb(1, &(bs->iempty));
2777 dgap_wmove(ch, ch->ch_digi.digi_offstr,
2778 (int) ch->ch_digi.digi_offlen);
2779 head = readw(&(bs->tx_head)) & tmask;
2780 ch->ch_flags &= ~CH_PRON;
2784 /* Update printer buffer empty time. */
2785 if ((un->un_type == DGAP_PRINT) && (ch->ch_digi.digi_maxcps > 0)
2786 && (ch->ch_digi.digi_bufsize > 0)) {
2787 ch->ch_cpstime += (HZ * count) / ch->ch_digi.digi_maxcps;
2790 spin_unlock_irqrestore(&ch->ch_lock, lock_flags);
2796 * Return modem signals to ld.
2798 static int dgap_tty_tiocmget(struct tty_struct *tty)
2800 struct channel_t *ch;
2806 if (!tty || tty->magic != TTY_MAGIC)
2809 un = tty->driver_data;
2810 if (!un || un->magic != DGAP_UNIT_MAGIC)
2814 if (!ch || ch->magic != DGAP_CHANNEL_MAGIC)
2817 spin_lock_irqsave(&ch->ch_lock, lock_flags);
2819 mstat = readb(&(ch->ch_bs->m_stat));
2820 /* Append any outbound signals that might be pending... */
2821 mstat |= ch->ch_mostat;
2823 spin_unlock_irqrestore(&ch->ch_lock, lock_flags);
2827 if (mstat & D_DTR(ch))
2828 result |= TIOCM_DTR;
2829 if (mstat & D_RTS(ch))
2830 result |= TIOCM_RTS;
2831 if (mstat & D_CTS(ch))
2832 result |= TIOCM_CTS;
2833 if (mstat & D_DSR(ch))
2834 result |= TIOCM_DSR;
2835 if (mstat & D_RI(ch))
2837 if (mstat & D_CD(ch))
2844 * dgap_tty_tiocmset()
2846 * Set modem signals, called by ld.
2848 static int dgap_tty_tiocmset(struct tty_struct *tty,
2849 unsigned int set, unsigned int clear)
2852 struct channel_t *ch;
2857 if (!tty || tty->magic != TTY_MAGIC)
2860 un = tty->driver_data;
2861 if (!un || un->magic != DGAP_UNIT_MAGIC)
2865 if (!ch || ch->magic != DGAP_CHANNEL_MAGIC)
2869 if (!bd || bd->magic != DGAP_BOARD_MAGIC)
2872 spin_lock_irqsave(&bd->bd_lock, lock_flags);
2873 spin_lock_irqsave(&ch->ch_lock, lock_flags2);
2875 if (set & TIOCM_RTS) {
2876 ch->ch_mforce |= D_RTS(ch);
2877 ch->ch_mval |= D_RTS(ch);
2880 if (set & TIOCM_DTR) {
2881 ch->ch_mforce |= D_DTR(ch);
2882 ch->ch_mval |= D_DTR(ch);
2885 if (clear & TIOCM_RTS) {
2886 ch->ch_mforce |= D_RTS(ch);
2887 ch->ch_mval &= ~(D_RTS(ch));
2890 if (clear & TIOCM_DTR) {
2891 ch->ch_mforce |= D_DTR(ch);
2892 ch->ch_mval &= ~(D_DTR(ch));
2897 spin_unlock_irqrestore(&ch->ch_lock, lock_flags2);
2898 spin_unlock_irqrestore(&bd->bd_lock, lock_flags);
2904 * dgap_tty_send_break()
2906 * Send a Break, called by ld.
2908 static int dgap_tty_send_break(struct tty_struct *tty, int msec)
2911 struct channel_t *ch;
2916 if (!tty || tty->magic != TTY_MAGIC)
2919 un = tty->driver_data;
2920 if (!un || un->magic != DGAP_UNIT_MAGIC)
2924 if (!ch || ch->magic != DGAP_CHANNEL_MAGIC)
2928 if (!bd || bd->magic != DGAP_BOARD_MAGIC)
2943 spin_lock_irqsave(&bd->bd_lock, lock_flags);
2944 spin_lock_irqsave(&ch->ch_lock, lock_flags2);
2946 dgap_cmdw(ch, SBREAK, (u16) SBREAK_TIME, 0);
2948 dgap_cmdw(ch, SBREAK, (u16) msec, 0);
2950 spin_unlock_irqrestore(&ch->ch_lock, lock_flags2);
2951 spin_unlock_irqrestore(&bd->bd_lock, lock_flags);
2957 * dgap_tty_wait_until_sent()
2959 * wait until data has been transmitted, called by ld.
2961 static void dgap_tty_wait_until_sent(struct tty_struct *tty, int timeout)
2963 dgap_wait_for_drain(tty);
2969 * send a high priority character, called by ld.
2971 static void dgap_tty_send_xchar(struct tty_struct *tty, char c)
2974 struct channel_t *ch;
2979 if (!tty || tty->magic != TTY_MAGIC)
2982 un = tty->driver_data;
2983 if (!un || un->magic != DGAP_UNIT_MAGIC)
2987 if (!ch || ch->magic != DGAP_CHANNEL_MAGIC)
2991 if (!bd || bd->magic != DGAP_BOARD_MAGIC)
2994 spin_lock_irqsave(&bd->bd_lock, lock_flags);
2995 spin_lock_irqsave(&ch->ch_lock, lock_flags2);
2998 * This is technically what we should do.
2999 * However, the NIST tests specifically want
3000 * to see each XON or XOFF character that it
3001 * sends, so lets just send each character
3005 if (c == STOP_CHAR(tty))
3006 dgap_cmdw(ch, RPAUSE, 0, 0);
3007 else if (c == START_CHAR(tty))
3008 dgap_cmdw(ch, RRESUME, 0, 0);
3010 dgap_wmove(ch, &c, 1);
3012 dgap_wmove(ch, &c, 1);
3015 spin_unlock_irqrestore(&ch->ch_lock, lock_flags2);
3016 spin_unlock_irqrestore(&bd->bd_lock, lock_flags);
3022 * Return modem signals to ld.
3024 static int dgap_get_modem_info(struct channel_t *ch, unsigned int __user *value)
3031 if (!ch || ch->magic != DGAP_CHANNEL_MAGIC)
3034 spin_lock_irqsave(&ch->ch_lock, lock_flags);
3036 mstat = readb(&(ch->ch_bs->m_stat));
3037 /* Append any outbound signals that might be pending... */
3038 mstat |= ch->ch_mostat;
3040 spin_unlock_irqrestore(&ch->ch_lock, lock_flags);
3044 if (mstat & D_DTR(ch))
3045 result |= TIOCM_DTR;
3046 if (mstat & D_RTS(ch))
3047 result |= TIOCM_RTS;
3048 if (mstat & D_CTS(ch))
3049 result |= TIOCM_CTS;
3050 if (mstat & D_DSR(ch))
3051 result |= TIOCM_DSR;
3052 if (mstat & D_RI(ch))
3054 if (mstat & D_CD(ch))
3057 rc = put_user(result, value);
3063 * dgap_set_modem_info()
3065 * Set modem signals, called by ld.
3067 static int dgap_set_modem_info(struct tty_struct *tty, unsigned int command,
3068 unsigned int __user *value)
3071 struct channel_t *ch;
3078 if (!tty || tty->magic != TTY_MAGIC)
3081 un = tty->driver_data;
3082 if (!un || un->magic != DGAP_UNIT_MAGIC)
3086 if (!ch || ch->magic != DGAP_CHANNEL_MAGIC)
3090 if (!bd || bd->magic != DGAP_BOARD_MAGIC)
3093 ret = get_user(arg, value);
3099 if (arg & TIOCM_RTS) {
3100 ch->ch_mforce |= D_RTS(ch);
3101 ch->ch_mval |= D_RTS(ch);
3104 if (arg & TIOCM_DTR) {
3105 ch->ch_mforce |= D_DTR(ch);
3106 ch->ch_mval |= D_DTR(ch);
3112 if (arg & TIOCM_RTS) {
3113 ch->ch_mforce |= D_RTS(ch);
3114 ch->ch_mval &= ~(D_RTS(ch));
3117 if (arg & TIOCM_DTR) {
3118 ch->ch_mforce |= D_DTR(ch);
3119 ch->ch_mval &= ~(D_DTR(ch));
3125 ch->ch_mforce = D_DTR(ch)|D_RTS(ch);
3127 if (arg & TIOCM_RTS)
3128 ch->ch_mval |= D_RTS(ch);
3130 ch->ch_mval &= ~(D_RTS(ch));
3132 if (arg & TIOCM_DTR)
3133 ch->ch_mval |= (D_DTR(ch));
3135 ch->ch_mval &= ~(D_DTR(ch));
3143 spin_lock_irqsave(&bd->bd_lock, lock_flags);
3144 spin_lock_irqsave(&ch->ch_lock, lock_flags2);
3148 spin_unlock_irqrestore(&ch->ch_lock, lock_flags2);
3149 spin_unlock_irqrestore(&bd->bd_lock, lock_flags);
3155 * dgap_tty_digigeta()
3157 * Ioctl to get the information for ditty.
3162 static int dgap_tty_digigeta(struct tty_struct *tty,
3163 struct digi_t __user *retinfo)
3165 struct channel_t *ch;
3173 if (!tty || tty->magic != TTY_MAGIC)
3176 un = tty->driver_data;
3177 if (!un || un->magic != DGAP_UNIT_MAGIC)
3181 if (!ch || ch->magic != DGAP_CHANNEL_MAGIC)
3184 memset(&tmp, 0, sizeof(tmp));
3186 spin_lock_irqsave(&ch->ch_lock, lock_flags);
3187 memcpy(&tmp, &ch->ch_digi, sizeof(tmp));
3188 spin_unlock_irqrestore(&ch->ch_lock, lock_flags);
3190 if (copy_to_user(retinfo, &tmp, sizeof(*retinfo)))
3197 * dgap_tty_digiseta()
3199 * Ioctl to set the information for ditty.
3204 static int dgap_tty_digiseta(struct tty_struct *tty,
3205 struct digi_t __user *new_info)
3208 struct channel_t *ch;
3210 struct digi_t new_digi;
3211 ulong lock_flags = 0;
3212 unsigned long lock_flags2;
3214 if (!tty || tty->magic != TTY_MAGIC)
3217 un = tty->driver_data;
3218 if (!un || un->magic != DGAP_UNIT_MAGIC)
3222 if (!ch || ch->magic != DGAP_CHANNEL_MAGIC)
3226 if (!bd || bd->magic != DGAP_BOARD_MAGIC)
3229 if (copy_from_user(&new_digi, new_info, sizeof(struct digi_t)))
3232 spin_lock_irqsave(&bd->bd_lock, lock_flags);
3233 spin_lock_irqsave(&ch->ch_lock, lock_flags2);
3235 memcpy(&ch->ch_digi, &new_digi, sizeof(struct digi_t));
3237 if (ch->ch_digi.digi_maxcps < 1)
3238 ch->ch_digi.digi_maxcps = 1;
3240 if (ch->ch_digi.digi_maxcps > 10000)
3241 ch->ch_digi.digi_maxcps = 10000;
3243 if (ch->ch_digi.digi_bufsize < 10)
3244 ch->ch_digi.digi_bufsize = 10;
3246 if (ch->ch_digi.digi_maxchar < 1)
3247 ch->ch_digi.digi_maxchar = 1;
3249 if (ch->ch_digi.digi_maxchar > ch->ch_digi.digi_bufsize)
3250 ch->ch_digi.digi_maxchar = ch->ch_digi.digi_bufsize;
3252 if (ch->ch_digi.digi_onlen > DIGI_PLEN)
3253 ch->ch_digi.digi_onlen = DIGI_PLEN;
3255 if (ch->ch_digi.digi_offlen > DIGI_PLEN)
3256 ch->ch_digi.digi_offlen = DIGI_PLEN;
3260 spin_unlock_irqrestore(&ch->ch_lock, lock_flags2);
3261 spin_unlock_irqrestore(&bd->bd_lock, lock_flags);
3267 * dgap_tty_digigetedelay()
3269 * Ioctl to get the current edelay setting.
3274 static int dgap_tty_digigetedelay(struct tty_struct *tty, int __user *retinfo)
3276 struct channel_t *ch;
3284 if (!tty || tty->magic != TTY_MAGIC)
3287 un = tty->driver_data;
3288 if (!un || un->magic != DGAP_UNIT_MAGIC)
3292 if (!ch || ch->magic != DGAP_CHANNEL_MAGIC)
3295 memset(&tmp, 0, sizeof(tmp));
3297 spin_lock_irqsave(&ch->ch_lock, lock_flags);
3298 tmp = readw(&(ch->ch_bs->edelay));
3299 spin_unlock_irqrestore(&ch->ch_lock, lock_flags);
3301 if (copy_to_user(retinfo, &tmp, sizeof(*retinfo)))
3308 * dgap_tty_digisetedelay()
3310 * Ioctl to set the EDELAY setting
3313 static int dgap_tty_digisetedelay(struct tty_struct *tty, int __user *new_info)
3316 struct channel_t *ch;
3322 if (!tty || tty->magic != TTY_MAGIC)
3325 un = tty->driver_data;
3326 if (!un || un->magic != DGAP_UNIT_MAGIC)
3330 if (!ch || ch->magic != DGAP_CHANNEL_MAGIC)
3334 if (!bd || bd->magic != DGAP_BOARD_MAGIC)
3337 if (copy_from_user(&new_digi, new_info, sizeof(int)))
3340 spin_lock_irqsave(&bd->bd_lock, lock_flags);
3341 spin_lock_irqsave(&ch->ch_lock, lock_flags2);
3343 writew((u16) new_digi, &(ch->ch_bs->edelay));
3347 spin_unlock_irqrestore(&ch->ch_lock, lock_flags2);
3348 spin_unlock_irqrestore(&bd->bd_lock, lock_flags);
3354 * dgap_tty_digigetcustombaud()
3356 * Ioctl to get the current custom baud rate setting.
3358 static int dgap_tty_digigetcustombaud(struct tty_struct *tty,
3359 int __user *retinfo)
3361 struct channel_t *ch;
3369 if (!tty || tty->magic != TTY_MAGIC)
3372 un = tty->driver_data;
3373 if (!un || un->magic != DGAP_UNIT_MAGIC)
3377 if (!ch || ch->magic != DGAP_CHANNEL_MAGIC)
3380 memset(&tmp, 0, sizeof(tmp));
3382 spin_lock_irqsave(&ch->ch_lock, lock_flags);
3383 tmp = dgap_get_custom_baud(ch);
3384 spin_unlock_irqrestore(&ch->ch_lock, lock_flags);
3386 if (copy_to_user(retinfo, &tmp, sizeof(*retinfo)))
3393 * dgap_tty_digisetcustombaud()
3395 * Ioctl to set the custom baud rate setting
3397 static int dgap_tty_digisetcustombaud(struct tty_struct *tty,
3398 int __user *new_info)
3401 struct channel_t *ch;
3407 if (!tty || tty->magic != TTY_MAGIC)
3410 un = tty->driver_data;
3411 if (!un || un->magic != DGAP_UNIT_MAGIC)
3415 if (!ch || ch->magic != DGAP_CHANNEL_MAGIC)
3419 if (!bd || bd->magic != DGAP_BOARD_MAGIC)
3423 if (copy_from_user(&new_rate, new_info, sizeof(unsigned int)))
3426 if (bd->bd_flags & BD_FEP5PLUS) {
3428 spin_lock_irqsave(&bd->bd_lock, lock_flags);
3429 spin_lock_irqsave(&ch->ch_lock, lock_flags2);
3431 ch->ch_custom_speed = new_rate;
3435 spin_unlock_irqrestore(&ch->ch_lock, lock_flags2);
3436 spin_unlock_irqrestore(&bd->bd_lock, lock_flags);
3443 * dgap_set_termios()
3445 static void dgap_tty_set_termios(struct tty_struct *tty,
3446 struct ktermios *old_termios)
3449 struct channel_t *ch;
3451 unsigned long lock_flags;
3452 unsigned long lock_flags2;
3454 if (!tty || tty->magic != TTY_MAGIC)
3457 un = tty->driver_data;
3458 if (!un || un->magic != DGAP_UNIT_MAGIC)
3462 if (!ch || ch->magic != DGAP_CHANNEL_MAGIC)
3466 if (!bd || bd->magic != DGAP_BOARD_MAGIC)
3469 spin_lock_irqsave(&bd->bd_lock, lock_flags);
3470 spin_lock_irqsave(&ch->ch_lock, lock_flags2);
3472 ch->ch_c_cflag = tty->termios.c_cflag;
3473 ch->ch_c_iflag = tty->termios.c_iflag;
3474 ch->ch_c_oflag = tty->termios.c_oflag;
3475 ch->ch_c_lflag = tty->termios.c_lflag;
3476 ch->ch_startc = tty->termios.c_cc[VSTART];
3477 ch->ch_stopc = tty->termios.c_cc[VSTOP];
3482 spin_unlock_irqrestore(&ch->ch_lock, lock_flags2);
3483 spin_unlock_irqrestore(&bd->bd_lock, lock_flags);
3486 static void dgap_tty_throttle(struct tty_struct *tty)
3489 struct channel_t *ch;
3494 if (!tty || tty->magic != TTY_MAGIC)
3497 un = tty->driver_data;
3498 if (!un || un->magic != DGAP_UNIT_MAGIC)
3502 if (!ch || ch->magic != DGAP_CHANNEL_MAGIC)
3506 if (!bd || bd->magic != DGAP_BOARD_MAGIC)
3509 spin_lock_irqsave(&bd->bd_lock, lock_flags);
3510 spin_lock_irqsave(&ch->ch_lock, lock_flags2);
3512 ch->ch_flags |= (CH_RXBLOCK);
3514 dgap_cmdw(ch, RPAUSE, 0, 0);
3517 spin_unlock_irqrestore(&ch->ch_lock, lock_flags2);
3518 spin_unlock_irqrestore(&bd->bd_lock, lock_flags);
3522 static void dgap_tty_unthrottle(struct tty_struct *tty)
3525 struct channel_t *ch;
3530 if (!tty || tty->magic != TTY_MAGIC)
3533 un = tty->driver_data;
3534 if (!un || un->magic != DGAP_UNIT_MAGIC)
3538 if (!ch || ch->magic != DGAP_CHANNEL_MAGIC)
3542 if (!bd || bd->magic != DGAP_BOARD_MAGIC)
3545 spin_lock_irqsave(&bd->bd_lock, lock_flags);
3546 spin_lock_irqsave(&ch->ch_lock, lock_flags2);
3548 ch->ch_flags &= ~(CH_RXBLOCK);
3551 dgap_cmdw(ch, RRESUME, 0, 0);
3554 spin_unlock_irqrestore(&ch->ch_lock, lock_flags2);
3555 spin_unlock_irqrestore(&bd->bd_lock, lock_flags);
3558 static void dgap_tty_start(struct tty_struct *tty)
3561 struct channel_t *ch;
3566 if (!tty || tty->magic != TTY_MAGIC)
3569 un = tty->driver_data;
3570 if (!un || un->magic != DGAP_UNIT_MAGIC)
3574 if (!ch || ch->magic != DGAP_CHANNEL_MAGIC)
3578 if (!bd || bd->magic != DGAP_BOARD_MAGIC)
3581 spin_lock_irqsave(&bd->bd_lock, lock_flags);
3582 spin_lock_irqsave(&ch->ch_lock, lock_flags2);
3584 dgap_cmdw(ch, RESUMETX, 0, 0);
3586 spin_unlock_irqrestore(&ch->ch_lock, lock_flags2);
3587 spin_unlock_irqrestore(&bd->bd_lock, lock_flags);
3590 static void dgap_tty_stop(struct tty_struct *tty)
3593 struct channel_t *ch;
3598 if (!tty || tty->magic != TTY_MAGIC)
3601 un = tty->driver_data;
3602 if (!un || un->magic != DGAP_UNIT_MAGIC)
3606 if (!ch || ch->magic != DGAP_CHANNEL_MAGIC)
3610 if (!bd || bd->magic != DGAP_BOARD_MAGIC)
3613 spin_lock_irqsave(&bd->bd_lock, lock_flags);
3614 spin_lock_irqsave(&ch->ch_lock, lock_flags2);
3616 dgap_cmdw(ch, PAUSETX, 0, 0);
3618 spin_unlock_irqrestore(&ch->ch_lock, lock_flags2);
3619 spin_unlock_irqrestore(&bd->bd_lock, lock_flags);
3623 * dgap_tty_flush_chars()
3625 * Flush the cook buffer
3627 * Note to self, and any other poor souls who venture here:
3629 * flush in this case DOES NOT mean dispose of the data.
3630 * instead, it means "stop buffering and send it if you
3631 * haven't already." Just guess how I figured that out... SRW 2-Jun-98
3633 * It is also always called in interrupt context - JAR 8-Sept-99
3635 static void dgap_tty_flush_chars(struct tty_struct *tty)
3638 struct channel_t *ch;
3643 if (!tty || tty->magic != TTY_MAGIC)
3646 un = tty->driver_data;
3647 if (!un || un->magic != DGAP_UNIT_MAGIC)
3651 if (!ch || ch->magic != DGAP_CHANNEL_MAGIC)
3655 if (!bd || bd->magic != DGAP_BOARD_MAGIC)
3658 spin_lock_irqsave(&bd->bd_lock, lock_flags);
3659 spin_lock_irqsave(&ch->ch_lock, lock_flags2);
3661 /* TODO: Do something here */
3663 spin_unlock_irqrestore(&ch->ch_lock, lock_flags2);
3664 spin_unlock_irqrestore(&bd->bd_lock, lock_flags);
3668 * dgap_tty_flush_buffer()
3670 * Flush Tx buffer (make in == out)
3672 static void dgap_tty_flush_buffer(struct tty_struct *tty)
3675 struct channel_t *ch;
3681 if (!tty || tty->magic != TTY_MAGIC)
3684 un = tty->driver_data;
3685 if (!un || un->magic != DGAP_UNIT_MAGIC)
3689 if (!ch || ch->magic != DGAP_CHANNEL_MAGIC)
3693 if (!bd || bd->magic != DGAP_BOARD_MAGIC)
3696 spin_lock_irqsave(&bd->bd_lock, lock_flags);
3697 spin_lock_irqsave(&ch->ch_lock, lock_flags2);
3699 ch->ch_flags &= ~CH_STOP;
3700 head = readw(&(ch->ch_bs->tx_head));
3701 dgap_cmdw(ch, FLUSHTX, (u16) head, 0);
3702 dgap_cmdw(ch, RESUMETX, 0, 0);
3703 if (ch->ch_tun.un_flags & (UN_LOW|UN_EMPTY)) {
3704 ch->ch_tun.un_flags &= ~(UN_LOW|UN_EMPTY);
3705 wake_up_interruptible(&ch->ch_tun.un_flags_wait);
3707 if (ch->ch_pun.un_flags & (UN_LOW|UN_EMPTY)) {
3708 ch->ch_pun.un_flags &= ~(UN_LOW|UN_EMPTY);
3709 wake_up_interruptible(&ch->ch_pun.un_flags_wait);
3712 spin_unlock_irqrestore(&ch->ch_lock, lock_flags2);
3713 spin_unlock_irqrestore(&bd->bd_lock, lock_flags);
3714 if (waitqueue_active(&tty->write_wait))
3715 wake_up_interruptible(&tty->write_wait);
3719 /*****************************************************************************
3721 * The IOCTL function and all of its helpers
3723 *****************************************************************************/
3728 * The usual assortment of ioctl's
3730 static int dgap_tty_ioctl(struct tty_struct *tty, unsigned int cmd,
3734 struct channel_t *ch;
3738 ulong lock_flags = 0;
3739 ulong lock_flags2 = 0;
3740 void __user *uarg = (void __user *) arg;
3742 if (!tty || tty->magic != TTY_MAGIC)
3745 un = tty->driver_data;
3746 if (!un || un->magic != DGAP_UNIT_MAGIC)
3750 if (!ch || ch->magic != DGAP_CHANNEL_MAGIC)
3754 if (!bd || bd->magic != DGAP_BOARD_MAGIC)
3757 spin_lock_irqsave(&bd->bd_lock, lock_flags);
3758 spin_lock_irqsave(&ch->ch_lock, lock_flags2);
3760 if (un->un_open_count <= 0) {
3761 spin_unlock_irqrestore(&ch->ch_lock, lock_flags2);
3762 spin_unlock_irqrestore(&bd->bd_lock, lock_flags);
3768 /* Here are all the standard ioctl's that we MUST implement */
3772 * TCSBRK is SVID version: non-zero arg --> no break
3773 * this behaviour is exploited by tcdrain().
3775 * According to POSIX.1 spec (7.2.2.1.2) breaks should be
3776 * between 0.25 and 0.5 seconds so we'll ask for something
3777 * in the middle: 0.375 seconds.
3779 rc = tty_check_change(tty);
3780 spin_unlock_irqrestore(&ch->ch_lock, lock_flags2);
3781 spin_unlock_irqrestore(&bd->bd_lock, lock_flags);
3785 rc = dgap_wait_for_drain(tty);
3790 spin_lock_irqsave(&bd->bd_lock, lock_flags);
3791 spin_lock_irqsave(&ch->ch_lock, lock_flags2);
3793 if (((cmd == TCSBRK) && (!arg)) || (cmd == TCSBRKP))
3794 dgap_cmdw(ch, SBREAK, (u16) SBREAK_TIME, 0);
3796 spin_unlock_irqrestore(&ch->ch_lock, lock_flags2);
3797 spin_unlock_irqrestore(&bd->bd_lock, lock_flags);
3802 /* support for POSIX tcsendbreak()
3804 * According to POSIX.1 spec (7.2.2.1.2) breaks should be
3805 * between 0.25 and 0.5 seconds so we'll ask for something
3806 * in the middle: 0.375 seconds.
3808 rc = tty_check_change(tty);
3809 spin_unlock_irqrestore(&ch->ch_lock, lock_flags2);
3810 spin_unlock_irqrestore(&bd->bd_lock, lock_flags);
3814 rc = dgap_wait_for_drain(tty);
3818 spin_lock_irqsave(&bd->bd_lock, lock_flags);
3819 spin_lock_irqsave(&ch->ch_lock, lock_flags2);
3821 dgap_cmdw(ch, SBREAK, (u16) SBREAK_TIME, 0);
3823 spin_unlock_irqrestore(&ch->ch_lock, lock_flags2);
3824 spin_unlock_irqrestore(&bd->bd_lock, lock_flags);
3830 * FEP5 doesn't support turning on a break unconditionally.
3831 * The FEP5 device will stop sending a break automatically
3832 * after the specified time value that was sent when turning on
3835 rc = tty_check_change(tty);
3836 spin_unlock_irqrestore(&ch->ch_lock, lock_flags2);
3837 spin_unlock_irqrestore(&bd->bd_lock, lock_flags);
3841 rc = dgap_wait_for_drain(tty);
3845 spin_lock_irqsave(&bd->bd_lock, lock_flags);
3846 spin_lock_irqsave(&ch->ch_lock, lock_flags2);
3848 dgap_cmdw(ch, SBREAK, (u16) SBREAK_TIME, 0);
3850 spin_unlock_irqrestore(&ch->ch_lock, lock_flags2);
3851 spin_unlock_irqrestore(&bd->bd_lock, lock_flags);
3857 * FEP5 doesn't support turning off a break unconditionally.
3858 * The FEP5 device will stop sending a break automatically
3859 * after the specified time value that was sent when turning on
3862 spin_unlock_irqrestore(&ch->ch_lock, lock_flags2);
3863 spin_unlock_irqrestore(&bd->bd_lock, lock_flags);
3868 spin_unlock_irqrestore(&ch->ch_lock, lock_flags2);
3869 spin_unlock_irqrestore(&bd->bd_lock, lock_flags);
3871 rc = put_user(C_CLOCAL(tty) ? 1 : 0,
3872 (unsigned long __user *) arg);
3876 spin_unlock_irqrestore(&ch->ch_lock, lock_flags2);
3877 spin_unlock_irqrestore(&bd->bd_lock, lock_flags);
3879 rc = get_user(arg, (unsigned long __user *) arg);
3883 spin_lock_irqsave(&bd->bd_lock, lock_flags);
3884 spin_lock_irqsave(&ch->ch_lock, lock_flags2);
3885 tty->termios.c_cflag = ((tty->termios.c_cflag & ~CLOCAL) |
3886 (arg ? CLOCAL : 0));
3888 spin_unlock_irqrestore(&ch->ch_lock, lock_flags2);
3889 spin_unlock_irqrestore(&bd->bd_lock, lock_flags);
3894 spin_unlock_irqrestore(&ch->ch_lock, lock_flags2);
3895 spin_unlock_irqrestore(&bd->bd_lock, lock_flags);
3896 return dgap_get_modem_info(ch, uarg);
3901 spin_unlock_irqrestore(&ch->ch_lock, lock_flags2);
3902 spin_unlock_irqrestore(&bd->bd_lock, lock_flags);
3903 return dgap_set_modem_info(tty, cmd, uarg);
3906 * Here are any additional ioctl's that we want to implement
3911 * The linux tty driver doesn't have a flush
3912 * input routine for the driver, assuming all backed
3913 * up data is in the line disc. buffers. However,
3914 * we all know that's not the case. Here, we
3915 * act on the ioctl, but then lie and say we didn't
3916 * so the line discipline will process the flush
3919 rc = tty_check_change(tty);
3921 spin_unlock_irqrestore(&ch->ch_lock, lock_flags2);
3922 spin_unlock_irqrestore(&bd->bd_lock, lock_flags);
3926 if ((arg == TCIFLUSH) || (arg == TCIOFLUSH)) {
3927 if (!(un->un_type == DGAP_PRINT)) {
3928 head = readw(&(ch->ch_bs->rx_head));
3929 writew(head, &(ch->ch_bs->rx_tail));
3930 writeb(0, &(ch->ch_bs->orun));
3934 if ((arg != TCOFLUSH) && (arg != TCIOFLUSH)) {
3935 /* pretend we didn't recognize this IOCTL */
3936 spin_unlock_irqrestore(&ch->ch_lock, lock_flags2);
3937 spin_unlock_irqrestore(&bd->bd_lock, lock_flags);
3939 return -ENOIOCTLCMD;
3942 ch->ch_flags &= ~CH_STOP;
3943 head = readw(&(ch->ch_bs->tx_head));
3944 dgap_cmdw(ch, FLUSHTX, (u16) head, 0);
3945 dgap_cmdw(ch, RESUMETX, 0, 0);
3946 if (ch->ch_tun.un_flags & (UN_LOW|UN_EMPTY)) {
3947 ch->ch_tun.un_flags &= ~(UN_LOW|UN_EMPTY);
3948 wake_up_interruptible(&ch->ch_tun.un_flags_wait);
3950 if (ch->ch_pun.un_flags & (UN_LOW|UN_EMPTY)) {
3951 ch->ch_pun.un_flags &= ~(UN_LOW|UN_EMPTY);
3952 wake_up_interruptible(&ch->ch_pun.un_flags_wait);
3954 if (waitqueue_active(&tty->write_wait))
3955 wake_up_interruptible(&tty->write_wait);
3957 /* Can't hold any locks when calling tty_wakeup! */
3958 spin_unlock_irqrestore(&ch->ch_lock, lock_flags2);
3959 spin_unlock_irqrestore(&bd->bd_lock, lock_flags);
3962 /* pretend we didn't recognize this IOCTL */
3963 return -ENOIOCTLCMD;
3968 * The linux tty driver doesn't have a flush
3969 * input routine for the driver, assuming all backed
3970 * up data is in the line disc. buffers. However,
3971 * we all know that's not the case. Here, we
3972 * act on the ioctl, but then lie and say we didn't
3973 * so the line discipline will process the flush
3976 if (cmd == TCSETSF) {
3978 ch->ch_flags &= ~CH_STOP;
3979 head = readw(&(ch->ch_bs->rx_head));
3980 writew(head, &(ch->ch_bs->rx_tail));
3983 /* now wait for all the output to drain */
3984 spin_unlock_irqrestore(&ch->ch_lock, lock_flags2);
3985 spin_unlock_irqrestore(&bd->bd_lock, lock_flags);
3986 rc = dgap_wait_for_drain(tty);
3990 /* pretend we didn't recognize this */
3991 return -ENOIOCTLCMD;
3995 spin_unlock_irqrestore(&ch->ch_lock, lock_flags2);
3996 spin_unlock_irqrestore(&bd->bd_lock, lock_flags);
3997 rc = dgap_wait_for_drain(tty);
4001 /* pretend we didn't recognize this */
4002 return -ENOIOCTLCMD;
4006 * The Linux Line Discipline (LD) would do this for us if we
4007 * let it, but we have the special firmware options to do this
4008 * the "right way" regardless of hardware or software flow
4009 * control so we'll do it outselves instead of letting the LD
4012 rc = tty_check_change(tty);
4014 spin_unlock_irqrestore(&ch->ch_lock, lock_flags2);
4015 spin_unlock_irqrestore(&bd->bd_lock, lock_flags);
4022 spin_unlock_irqrestore(&ch->ch_lock, lock_flags2);
4023 spin_unlock_irqrestore(&bd->bd_lock, lock_flags);
4024 dgap_tty_start(tty);
4027 spin_unlock_irqrestore(&ch->ch_lock, lock_flags2);
4028 spin_unlock_irqrestore(&bd->bd_lock, lock_flags);
4032 spin_unlock_irqrestore(&ch->ch_lock, lock_flags2);
4033 spin_unlock_irqrestore(&bd->bd_lock, lock_flags);
4034 /* Make the ld do it */
4035 return -ENOIOCTLCMD;
4037 spin_unlock_irqrestore(&ch->ch_lock, lock_flags2);
4038 spin_unlock_irqrestore(&bd->bd_lock, lock_flags);
4039 /* Make the ld do it */
4040 return -ENOIOCTLCMD;
4042 spin_unlock_irqrestore(&ch->ch_lock, lock_flags2);
4043 spin_unlock_irqrestore(&bd->bd_lock, lock_flags);
4048 /* get information for ditty */
4049 spin_unlock_irqrestore(&ch->ch_lock, lock_flags2);
4050 spin_unlock_irqrestore(&bd->bd_lock, lock_flags);
4051 return dgap_tty_digigeta(tty, uarg);
4056 /* set information for ditty */
4057 if (cmd == (DIGI_SETAW)) {
4059 spin_unlock_irqrestore(&ch->ch_lock, lock_flags2);
4060 spin_unlock_irqrestore(&bd->bd_lock, lock_flags);
4061 rc = dgap_wait_for_drain(tty);
4064 spin_lock_irqsave(&bd->bd_lock, lock_flags);
4065 spin_lock_irqsave(&ch->ch_lock, lock_flags2);
4067 tty_ldisc_flush(tty);
4071 spin_unlock_irqrestore(&ch->ch_lock, lock_flags2);
4072 spin_unlock_irqrestore(&bd->bd_lock, lock_flags);
4073 return dgap_tty_digiseta(tty, uarg);
4076 spin_unlock_irqrestore(&ch->ch_lock, lock_flags2);
4077 spin_unlock_irqrestore(&bd->bd_lock, lock_flags);
4078 return dgap_tty_digigetedelay(tty, uarg);
4081 spin_unlock_irqrestore(&ch->ch_lock, lock_flags2);
4082 spin_unlock_irqrestore(&bd->bd_lock, lock_flags);
4083 return dgap_tty_digisetedelay(tty, uarg);
4085 case DIGI_GETCUSTOMBAUD:
4086 spin_unlock_irqrestore(&ch->ch_lock, lock_flags2);
4087 spin_unlock_irqrestore(&bd->bd_lock, lock_flags);
4088 return dgap_tty_digigetcustombaud(tty, uarg);
4090 case DIGI_SETCUSTOMBAUD:
4091 spin_unlock_irqrestore(&ch->ch_lock, lock_flags2);
4092 spin_unlock_irqrestore(&bd->bd_lock, lock_flags);
4093 return dgap_tty_digisetcustombaud(tty, uarg);
4095 case DIGI_RESET_PORT:
4096 dgap_firmware_reset_port(ch);
4098 spin_unlock_irqrestore(&ch->ch_lock, lock_flags2);
4099 spin_unlock_irqrestore(&bd->bd_lock, lock_flags);
4103 spin_unlock_irqrestore(&ch->ch_lock, lock_flags2);
4104 spin_unlock_irqrestore(&bd->bd_lock, lock_flags);
4106 return -ENOIOCTLCMD;
4110 static int dgap_after_config_loaded(int board)
4113 * Initialize KME waitqueues...
4115 init_waitqueue_head(&(dgap_board[board]->kme_wait));
4118 * allocate flip buffer for board.
4120 dgap_board[board]->flipbuf = kmalloc(MYFLIPLEN, GFP_KERNEL);
4121 if (!dgap_board[board]->flipbuf)
4124 dgap_board[board]->flipflagbuf = kmalloc(MYFLIPLEN, GFP_KERNEL);
4125 if (!dgap_board[board]->flipflagbuf) {
4126 kfree(dgap_board[board]->flipbuf);
4134 * Create pr and tty device entries
4136 static int dgap_tty_register_ports(struct board_t *brd)
4138 struct channel_t *ch;
4141 brd->serial_ports = kcalloc(brd->nasync, sizeof(*brd->serial_ports),
4143 if (!brd->serial_ports)
4146 brd->printer_ports = kcalloc(brd->nasync, sizeof(*brd->printer_ports),
4148 if (!brd->printer_ports)
4151 for (i = 0; i < brd->nasync; i++) {
4152 tty_port_init(&brd->serial_ports[i]);
4153 tty_port_init(&brd->printer_ports[i]);
4156 ch = brd->channels[0];
4157 for (i = 0; i < brd->nasync; i++, ch = brd->channels[i]) {
4159 struct device *classp;
4161 classp = tty_port_register_device(&brd->serial_ports[i],
4163 brd->firstminor + i, NULL);
4165 dgap_create_tty_sysfs(&ch->ch_tun, classp);
4166 ch->ch_tun.un_sysfs = classp;
4168 classp = tty_port_register_device(&brd->printer_ports[i],
4170 brd->firstminor + i, NULL);
4172 dgap_create_tty_sysfs(&ch->ch_pun, classp);
4173 ch->ch_pun.un_sysfs = classp;
4175 dgap_create_ports_sysfiles(brd);
4181 * Copies the BIOS code from the user to the board,
4182 * and starts the BIOS running.
4184 static void dgap_do_bios_load(struct board_t *brd, const u8 *ubios, int len)
4190 if (!brd || (brd->magic != DGAP_BOARD_MAGIC) || !brd->re_map_membase)
4193 addr = brd->re_map_membase;
4198 for (i = 0; i < 16; i++)
4199 writeb(0, addr + POSTAREA + i);
4205 memcpy_toio(addr + offset, ubios, len);
4207 writel(0x0bf00401, addr);
4208 writel(0, (addr + 4));
4210 /* Clear the reset, and change states. */
4211 writeb(FEPCLR, brd->re_map_port);
4215 * Checks to see if the BIOS completed running on the card.
4217 static int dgap_test_bios(struct board_t *brd)
4224 if (!brd || (brd->magic != DGAP_BOARD_MAGIC) || !brd->re_map_membase)
4227 addr = brd->re_map_membase;
4228 word = readw(addr + POSTAREA);
4231 * It can take 5-6 seconds for a board to
4232 * pass the bios self test and post results.
4233 * Give it 10 seconds.
4235 brd->wait_for_bios = 0;
4236 while (brd->wait_for_bios < 1000) {
4237 /* Check to see if BIOS thinks board is good. (GD). */
4238 if (word == *(u16 *) "GD")
4240 msleep_interruptible(10);
4241 brd->wait_for_bios++;
4242 word = readw(addr + POSTAREA);
4245 /* Gave up on board after too long of time taken */
4246 err1 = readw(addr + SEQUENCE);
4247 err2 = readw(addr + ERROR);
4248 pr_warn("dgap: %s failed diagnostics. Error #(%x,%x).\n",
4249 brd->name, err1, err2);
4250 brd->state = BOARD_FAILED;
4251 brd->dpastatus = BD_NOBIOS;
4257 * Copies the FEP code from the user to the board,
4258 * and starts the FEP running.
4260 static void dgap_do_fep_load(struct board_t *brd, const u8 *ufep, int len)
4265 if (!brd || (brd->magic != DGAP_BOARD_MAGIC) || !brd->re_map_membase)
4268 addr = brd->re_map_membase;
4274 memcpy_toio(addr + offset, ufep, len);
4277 * If board is a concentrator product, we need to give
4278 * it its config string describing how the concentrators look.
4280 if ((brd->type == PCX) || (brd->type == PEPC)) {
4286 xconfig = dgap_create_config_string(brd, string);
4288 /* Write string to board memory */
4289 config = addr + CONFIG;
4290 for (; i < CONFIGSIZE; i++, config++, xconfig++) {
4291 writeb(*xconfig, config);
4292 if ((*xconfig & 0xff) == 0xff)
4297 writel(0xbfc01004, (addr + 0xc34));
4298 writel(0x3, (addr + 0xc30));
4303 * Waits for the FEP to report thats its ready for us to use.
4305 static int dgap_test_fep(struct board_t *brd)
4312 if (!brd || (brd->magic != DGAP_BOARD_MAGIC) || !brd->re_map_membase)
4315 addr = brd->re_map_membase;
4316 word = readw(addr + FEPSTAT);
4319 * It can take 2-3 seconds for the FEP to
4320 * be up and running. Give it 5 secs.
4322 brd->wait_for_fep = 0;
4323 while (brd->wait_for_fep < 500) {
4324 /* Check to see if FEP is up and running now. */
4325 if (word == *(u16 *) "OS") {
4327 * Check to see if the board can support FEP5+ commands.
4329 word = readw(addr + FEP5_PLUS);
4330 if (word == *(u16 *) "5A")
4331 brd->bd_flags |= BD_FEP5PLUS;
4335 msleep_interruptible(10);
4336 brd->wait_for_fep++;
4337 word = readw(addr + FEPSTAT);
4340 /* Gave up on board after too long of time taken */
4341 err1 = readw(addr + SEQUENCE);
4342 err2 = readw(addr + ERROR);
4343 pr_warn("dgap: FEPOS for %s not functioning. Error #(%x,%x).\n",
4344 brd->name, err1, err2);
4345 brd->state = BOARD_FAILED;
4346 brd->dpastatus = BD_NOFEP;
4352 * Physically forces the FEP5 card to reset itself.
4354 static void dgap_do_reset_board(struct board_t *brd)
4361 if (!brd || (brd->magic != DGAP_BOARD_MAGIC) ||
4362 !brd->re_map_membase || !brd->re_map_port)
4365 /* FEPRST does not vary among supported boards */
4366 writeb(FEPRST, brd->re_map_port);
4368 for (i = 0; i <= 1000; i++) {
4369 check = readb(brd->re_map_port) & 0xe;
4370 if (check == FEPRST)
4376 pr_warn("dgap: Board not resetting... Failing board.\n");
4377 brd->state = BOARD_FAILED;
4378 brd->dpastatus = BD_NOFEP;
4383 * Make sure there really is memory out there.
4385 writel(0xa55a3cc3, (brd->re_map_membase + LOWMEM));
4386 writel(0x5aa5c33c, (brd->re_map_membase + HIGHMEM));
4387 check1 = readl(brd->re_map_membase + LOWMEM);
4388 check2 = readl(brd->re_map_membase + HIGHMEM);
4390 if ((check1 != 0xa55a3cc3) || (check2 != 0x5aa5c33c)) {
4391 pr_warn("dgap: No memory at %p for board.\n",
4392 brd->re_map_membase);
4393 brd->state = BOARD_FAILED;
4394 brd->dpastatus = BD_NOFEP;
4399 #ifdef DIGI_CONCENTRATORS_SUPPORTED
4401 * Sends a concentrator image into the FEP5 board.
4403 static void dgap_do_conc_load(struct board_t *brd, u8 *uaddr, int len)
4405 char __iomem *vaddr;
4407 struct downld_t *to_dp;
4409 if (!brd || (brd->magic != DGAP_BOARD_MAGIC) || !brd->re_map_membase)
4412 vaddr = brd->re_map_membase;
4414 offset = readw((u16 *) (vaddr + DOWNREQ));
4415 to_dp = (struct downld_t *) (vaddr + (int) offset);
4416 memcpy_toio(to_dp, uaddr, len);
4418 /* Tell card we have data for it */
4419 writew(0, vaddr + (DOWNREQ));
4421 brd->conc_dl_status = NO_PENDING_CONCENTRATOR_REQUESTS;
4425 #define EXPANSION_ROM_SIZE (64 * 1024)
4426 #define FEP5_ROM_MAGIC (0xFEFFFFFF)
4428 static void dgap_get_vpd(struct board_t *brd)
4440 * Poke the magic number at the PCI Rom Address location.
4441 * If VPD is supported, the value read from that address
4444 magic = FEP5_ROM_MAGIC;
4445 pci_write_config_dword(brd->pdev, PCI_ROM_ADDRESS, magic);
4446 pci_read_config_dword(brd->pdev, PCI_ROM_ADDRESS, &magic);
4448 /* VPD not supported, bail */
4453 * To get to the OTPROM memory, we have to send the boards base
4454 * address or'ed with 1 into the PCI Rom Address location.
4456 magic = brd->membase | 0x01;
4457 pci_write_config_dword(brd->pdev, PCI_ROM_ADDRESS, magic);
4458 pci_read_config_dword(brd->pdev, PCI_ROM_ADDRESS, &magic);
4460 byte1 = readb(brd->re_map_membase);
4461 byte2 = readb(brd->re_map_membase + 1);
4464 * If the board correctly swapped to the OTPROM memory,
4465 * the first 2 bytes (header) should be 0x55, 0xAA
4467 if (byte1 == 0x55 && byte2 == 0xAA) {
4472 * We have to run through all the OTPROM memory looking
4473 * for the VPD offset.
4475 while (base_offset <= EXPANSION_ROM_SIZE) {
4478 * Lots of magic numbers here.
4480 * The VPD offset is located inside the ROM Data
4483 * We also have to remember the length of each
4484 * ROM Data Structure, so we can "hop" to the next
4485 * entry if the VPD isn't in the current
4486 * ROM Data Structure.
4488 rom_offset = readw(brd->re_map_membase +
4489 base_offset + 0x18);
4490 image_length = readw(brd->re_map_membase +
4491 rom_offset + 0x10) * 512;
4492 vpd_offset = readw(brd->re_map_membase +
4495 /* Found the VPD entry */
4499 /* We didn't find a VPD entry, go to next ROM entry. */
4500 base_offset += image_length;
4502 byte1 = readb(brd->re_map_membase + base_offset);
4503 byte2 = readb(brd->re_map_membase + base_offset + 1);
4506 * If the new ROM offset doesn't have 0x55, 0xAA
4507 * as its header, we have run out of ROM.
4509 if (byte1 != 0x55 || byte2 != 0xAA)
4514 * If we have a VPD offset, then mark the board
4515 * as having a valid VPD, and copy VPDSIZE (512) bytes of
4516 * that VPD to the buffer we have in our board structure.
4519 brd->bd_flags |= BD_HAS_VPD;
4520 for (i = 0; i < VPDSIZE; i++) {
4521 brd->vpd[i] = readb(brd->re_map_membase +
4528 * We MUST poke the magic number at the PCI Rom Address location again.
4529 * This makes the card report the regular board memory back to us,
4530 * rather than the OTPROM memory.
4532 magic = FEP5_ROM_MAGIC;
4533 pci_write_config_dword(brd->pdev, PCI_ROM_ADDRESS, magic);
4537 * Our board poller function.
4539 static void dgap_poll_tasklet(unsigned long data)
4541 struct board_t *bd = (struct board_t *) data;
4543 char __iomem *vaddr;
4546 if (!bd || (bd->magic != DGAP_BOARD_MAGIC))
4549 if (bd->inhibit_poller)
4552 spin_lock_irqsave(&bd->bd_lock, lock_flags);
4554 vaddr = bd->re_map_membase;
4557 * If board is ready, parse deeper to see if there is anything to do.
4559 if (bd->state == BOARD_READY) {
4561 struct ev_t __iomem *eaddr;
4563 if (!bd->re_map_membase) {
4564 spin_unlock_irqrestore(&bd->bd_lock, lock_flags);
4567 if (!bd->re_map_port) {
4568 spin_unlock_irqrestore(&bd->bd_lock, lock_flags);
4575 eaddr = (struct ev_t __iomem *) (vaddr + EVBUF);
4577 /* Get our head and tail */
4578 head = readw(&(eaddr->ev_head));
4579 tail = readw(&(eaddr->ev_tail));
4582 * If there is an event pending. Go service it.
4585 spin_unlock_irqrestore(&bd->bd_lock, lock_flags);
4587 spin_lock_irqsave(&bd->bd_lock, lock_flags);
4592 * If board is doing interrupts, ACK the interrupt.
4594 if (bd && bd->intr_running)
4595 readb(bd->re_map_port + 2);
4597 spin_unlock_irqrestore(&bd->bd_lock, lock_flags);
4601 spin_unlock_irqrestore(&bd->bd_lock, lock_flags);
4604 /*=======================================================================
4606 * dgap_cmdb - Sends a 2 byte command to the FEP.
4608 * ch - Pointer to channel structure.
4609 * cmd - Command to be sent.
4610 * byte1 - Integer containing first byte to be sent.
4611 * byte2 - Integer containing second byte to be sent.
4612 * ncmds - Wait until ncmds or fewer cmds are left
4613 * in the cmd buffer before returning.
4615 *=======================================================================*/
4616 static void dgap_cmdb(struct channel_t *ch, u8 cmd, u8 byte1,
4617 u8 byte2, uint ncmds)
4619 char __iomem *vaddr;
4620 struct __iomem cm_t *cm_addr;
4626 if (!ch || ch->magic != DGAP_CHANNEL_MAGIC)
4630 * Check if board is still alive.
4632 if (ch->ch_bd->state == BOARD_FAILED)
4636 * Make sure the pointers are in range before
4637 * writing to the FEP memory.
4639 vaddr = ch->ch_bd->re_map_membase;
4644 cm_addr = (struct cm_t __iomem *) (vaddr + CMDBUF);
4645 head = readw(&(cm_addr->cm_head));
4648 * Forget it if pointers out of range.
4650 if (head >= (CMDMAX - CMDSTART) || (head & 03)) {
4651 ch->ch_bd->state = BOARD_FAILED;
4656 * Put the data in the circular command buffer.
4658 writeb(cmd, (vaddr + head + CMDSTART + 0));
4659 writeb((u8) ch->ch_portnum, (vaddr + head + CMDSTART + 1));
4660 writeb(byte1, (vaddr + head + CMDSTART + 2));
4661 writeb(byte2, (vaddr + head + CMDSTART + 3));
4663 head = (head + 4) & (CMDMAX - CMDSTART - 4);
4665 writew(head, &(cm_addr->cm_head));
4668 * Wait if necessary before updating the head
4669 * pointer to limit the number of outstanding
4670 * commands to the FEP. If the time spent waiting
4671 * is outlandish, declare the FEP dead.
4673 for (count = dgap_count ;;) {
4675 head = readw(&(cm_addr->cm_head));
4676 tail = readw(&(cm_addr->cm_tail));
4678 n = (head - tail) & (CMDMAX - CMDSTART - 4);
4680 if (n <= ncmds * sizeof(struct cm_t))
4684 ch->ch_bd->state = BOARD_FAILED;
4691 /*=======================================================================
4693 * dgap_cmdw - Sends a 1 word command to the FEP.
4695 * ch - Pointer to channel structure.
4696 * cmd - Command to be sent.
4697 * word - Integer containing word to be sent.
4698 * ncmds - Wait until ncmds or fewer cmds are left
4699 * in the cmd buffer before returning.
4701 *=======================================================================*/
4702 static void dgap_cmdw(struct channel_t *ch, u8 cmd, u16 word, uint ncmds)
4704 char __iomem *vaddr;
4705 struct __iomem cm_t *cm_addr;
4711 if (!ch || ch->magic != DGAP_CHANNEL_MAGIC)
4715 * Check if board is still alive.
4717 if (ch->ch_bd->state == BOARD_FAILED)
4721 * Make sure the pointers are in range before
4722 * writing to the FEP memory.
4724 vaddr = ch->ch_bd->re_map_membase;
4728 cm_addr = (struct cm_t __iomem *) (vaddr + CMDBUF);
4729 head = readw(&(cm_addr->cm_head));
4732 * Forget it if pointers out of range.
4734 if (head >= (CMDMAX - CMDSTART) || (head & 03)) {
4735 ch->ch_bd->state = BOARD_FAILED;
4740 * Put the data in the circular command buffer.
4742 writeb(cmd, (vaddr + head + CMDSTART + 0));
4743 writeb((u8) ch->ch_portnum, (vaddr + head + CMDSTART + 1));
4744 writew((u16) word, (vaddr + head + CMDSTART + 2));
4746 head = (head + 4) & (CMDMAX - CMDSTART - 4);
4748 writew(head, &(cm_addr->cm_head));
4751 * Wait if necessary before updating the head
4752 * pointer to limit the number of outstanding
4753 * commands to the FEP. If the time spent waiting
4754 * is outlandish, declare the FEP dead.
4756 for (count = dgap_count ;;) {
4758 head = readw(&(cm_addr->cm_head));
4759 tail = readw(&(cm_addr->cm_tail));
4761 n = (head - tail) & (CMDMAX - CMDSTART - 4);
4763 if (n <= ncmds * sizeof(struct cm_t))
4767 ch->ch_bd->state = BOARD_FAILED;
4774 /*=======================================================================
4776 * dgap_cmdw_ext - Sends a extended word command to the FEP.
4778 * ch - Pointer to channel structure.
4779 * cmd - Command to be sent.
4780 * word - Integer containing word to be sent.
4781 * ncmds - Wait until ncmds or fewer cmds are left
4782 * in the cmd buffer before returning.
4784 *=======================================================================*/
4785 static void dgap_cmdw_ext(struct channel_t *ch, u16 cmd, u16 word, uint ncmds)
4787 char __iomem *vaddr;
4788 struct __iomem cm_t *cm_addr;
4794 if (!ch || ch->magic != DGAP_CHANNEL_MAGIC)
4798 * Check if board is still alive.
4800 if (ch->ch_bd->state == BOARD_FAILED)
4804 * Make sure the pointers are in range before
4805 * writing to the FEP memory.
4807 vaddr = ch->ch_bd->re_map_membase;
4811 cm_addr = (struct cm_t __iomem *) (vaddr + CMDBUF);
4812 head = readw(&(cm_addr->cm_head));
4815 * Forget it if pointers out of range.
4817 if (head >= (CMDMAX - CMDSTART) || (head & 03)) {
4818 ch->ch_bd->state = BOARD_FAILED;
4823 * Put the data in the circular command buffer.
4826 /* Write an FF to tell the FEP that we want an extended command */
4827 writeb((u8) 0xff, (vaddr + head + CMDSTART + 0));
4829 writeb((u8) ch->ch_portnum, (vaddr + head + CMDSTART + 1));
4830 writew((u16) cmd, (vaddr + head + CMDSTART + 2));
4833 * If the second part of the command won't fit,
4834 * put it at the beginning of the circular buffer.
4836 if (((head + 4) >= ((CMDMAX - CMDSTART)) || (head & 03)))
4837 writew((u16) word, (vaddr + CMDSTART));
4839 writew((u16) word, (vaddr + head + CMDSTART + 4));
4841 head = (head + 8) & (CMDMAX - CMDSTART - 4);
4843 writew(head, &(cm_addr->cm_head));
4846 * Wait if necessary before updating the head
4847 * pointer to limit the number of outstanding
4848 * commands to the FEP. If the time spent waiting
4849 * is outlandish, declare the FEP dead.
4851 for (count = dgap_count ;;) {
4853 head = readw(&(cm_addr->cm_head));
4854 tail = readw(&(cm_addr->cm_tail));
4856 n = (head - tail) & (CMDMAX - CMDSTART - 4);
4858 if (n <= ncmds * sizeof(struct cm_t))
4862 ch->ch_bd->state = BOARD_FAILED;
4869 /*=======================================================================
4871 * dgap_wmove - Write data to FEP buffer.
4873 * ch - Pointer to channel structure.
4874 * buf - Poiter to characters to be moved.
4875 * cnt - Number of characters to move.
4877 *=======================================================================*/
4878 static void dgap_wmove(struct channel_t *ch, char *buf, uint cnt)
4881 char __iomem *taddr;
4882 struct bs_t __iomem *bs;
4885 if (!ch || ch->magic != DGAP_CHANNEL_MAGIC)
4892 head = readw(&(bs->tx_head));
4895 * If pointers are out of range, just return.
4897 if ((cnt > ch->ch_tsize) ||
4898 (unsigned)(head - ch->ch_tstart) >= ch->ch_tsize)
4902 * If the write wraps over the top of the circular buffer,
4903 * move the portion up to the wrap point, and reset the
4904 * pointers to the bottom.
4906 n = ch->ch_tstart + ch->ch_tsize - head;
4910 taddr = ch->ch_taddr + head;
4911 memcpy_toio(taddr, buf, n);
4912 head = ch->ch_tstart;
4917 * Move rest of data.
4919 taddr = ch->ch_taddr + head;
4921 memcpy_toio(taddr, buf, n);
4924 writew(head, &(bs->tx_head));
4928 * Retrives the current custom baud rate from FEP memory,
4929 * and returns it back to the user.
4930 * Returns 0 on error.
4932 static uint dgap_get_custom_baud(struct channel_t *ch)
4938 if (!ch || ch->magic != DGAP_CHANNEL_MAGIC)
4941 if (!ch->ch_bd || ch->ch_bd->magic != DGAP_BOARD_MAGIC)
4944 if (!(ch->ch_bd->bd_flags & BD_FEP5PLUS))
4947 vaddr = ch->ch_bd->re_map_membase;
4953 * Go get from fep mem, what the fep
4954 * believes the custom baud rate is.
4956 offset = (ioread16(vaddr + ECS_SEG) << 4) + (ch->ch_portnum * 0x28)
4959 value = readw(vaddr + offset);
4964 * Calls the firmware to reset this channel.
4966 static void dgap_firmware_reset_port(struct channel_t *ch)
4968 dgap_cmdb(ch, CHRESET, 0, 0, 0);
4971 * Now that the channel is reset, we need to make sure
4972 * all the current settings get reapplied to the port
4975 * So we will set the driver's cache of firmware
4976 * settings all to 0, and then call param.
4978 ch->ch_fepiflag = 0;
4979 ch->ch_fepcflag = 0;
4980 ch->ch_fepoflag = 0;
4981 ch->ch_fepstartc = 0;
4982 ch->ch_fepstopc = 0;
4983 ch->ch_fepastartc = 0;
4984 ch->ch_fepastopc = 0;
4989 /*=======================================================================
4991 * dgap_param - Set Digi parameters.
4993 * struct tty_struct * - TTY for port.
4995 *=======================================================================*/
4996 static int dgap_param(struct tty_struct *tty)
4998 struct ktermios *ts;
5000 struct channel_t *ch;
5001 struct bs_t __iomem *bs;
5009 if (!tty || tty->magic != TTY_MAGIC)
5012 un = (struct un_t *) tty->driver_data;
5013 if (!un || un->magic != DGAP_UNIT_MAGIC)
5017 if (!ch || ch->magic != DGAP_CHANNEL_MAGIC)
5021 if (!bd || bd->magic != DGAP_BOARD_MAGIC)
5031 * If baud rate is zero, flush queues, and set mval to drop DTR.
5033 if ((ch->ch_c_cflag & (CBAUD)) == 0) {
5036 head = readw(&(ch->ch_bs->rx_head));
5037 writew(head, &(ch->ch_bs->rx_tail));
5040 head = readw(&(ch->ch_bs->tx_head));
5041 writew(head, &(ch->ch_bs->tx_tail));
5043 ch->ch_flags |= (CH_BAUD0);
5045 /* Drop RTS and DTR */
5046 ch->ch_mval &= ~(D_RTS(ch)|D_DTR(ch));
5047 mval = D_DTR(ch) | D_RTS(ch);
5048 ch->ch_baud_info = 0;
5050 } else if (ch->ch_custom_speed && (bd->bd_flags & BD_FEP5PLUS)) {
5052 * Tell the fep to do the command
5055 dgap_cmdw_ext(ch, 0xff01, ch->ch_custom_speed, 0);
5058 * Now go get from fep mem, what the fep
5059 * believes the custom baud rate is.
5061 ch->ch_custom_speed = dgap_get_custom_baud(ch);
5062 ch->ch_baud_info = ch->ch_custom_speed;
5064 /* Handle transition from B0 */
5065 if (ch->ch_flags & CH_BAUD0) {
5066 ch->ch_flags &= ~(CH_BAUD0);
5067 ch->ch_mval |= (D_RTS(ch)|D_DTR(ch));
5069 mval = D_DTR(ch) | D_RTS(ch);
5073 * Set baud rate, character size, and parity.
5081 ulong bauds[4][16] = {
5085 600, 1200, 1800, 2400,
5086 4800, 9600, 19200, 38400 },
5087 { /* slowbaud & CBAUDEX */
5088 0, 57600, 115200, 230400,
5089 460800, 150, 200, 921600,
5090 600, 1200, 1800, 2400,
5091 4800, 9600, 19200, 38400 },
5093 0, 57600, 76800, 115200,
5094 14400, 57600, 230400, 76800,
5095 115200, 230400, 28800, 460800,
5096 921600, 9600, 19200, 38400 },
5097 { /* fastbaud & CBAUDEX */
5098 0, 57600, 115200, 230400,
5099 460800, 150, 200, 921600,
5100 600, 1200, 1800, 2400,
5101 4800, 9600, 19200, 38400 }
5105 * Only use the TXPrint baud rate if the
5106 * terminal unit is NOT open
5108 if (!(ch->ch_tun.un_flags & UN_ISOPEN) &&
5109 (un->un_type == DGAP_PRINT))
5110 baud = C_BAUD(ch->ch_pun.un_tty) & 0xff;
5112 baud = C_BAUD(ch->ch_tun.un_tty) & 0xff;
5114 if (ch->ch_c_cflag & CBAUDEX)
5117 if (ch->ch_digi.digi_flags & DIGI_FAST)
5122 if ((iindex >= 0) && (iindex < 4) &&
5123 (jindex >= 0) && (jindex < 16))
5124 baud = bauds[iindex][jindex];
5131 ch->ch_baud_info = baud;
5134 * CBAUD has bit position 0x1000 set these days to
5135 * indicate Linux baud rate remap.
5136 * We use a different bit assignment for high speed.
5137 * Clear this bit out while grabbing the parts of
5140 cflag = ch->ch_c_cflag & ((CBAUD ^ CBAUDEX) | PARODD | PARENB |
5144 * HUPCL bit is used by FEP to indicate fast baud
5145 * table is to be used.
5147 if ((ch->ch_digi.digi_flags & DIGI_FAST) ||
5148 (ch->ch_c_cflag & CBAUDEX))
5151 if ((ch->ch_c_cflag & CBAUDEX) &&
5152 !(ch->ch_digi.digi_flags & DIGI_FAST)) {
5154 * The below code is trying to guarantee that only
5155 * baud rates 115200, 230400, 460800, 921600 are
5156 * remapped. We use exclusive or because the various
5157 * baud rates share common bit positions and therefore
5158 * can't be tested for easily.
5160 tcflag_t tcflag = (ch->ch_c_cflag & CBAUD) | CBAUDEX;
5164 * Map high speed requests to index
5165 * into FEP's baud table
5195 cflag = (cflag & ~(CBAUD | CBAUDEX)) | baudpart;
5200 if (cflag != ch->ch_fepcflag) {
5201 ch->ch_fepcflag = (u16) (cflag & 0xffff);
5204 * Okay to have channel and board
5205 * locks held calling this
5207 dgap_cmdw(ch, SCFLAG, (u16) cflag, 0);
5210 /* Handle transition from B0 */
5211 if (ch->ch_flags & CH_BAUD0) {
5212 ch->ch_flags &= ~(CH_BAUD0);
5213 ch->ch_mval |= (D_RTS(ch)|D_DTR(ch));
5215 mval = D_DTR(ch) | D_RTS(ch);
5221 iflag = ch->ch_c_iflag & (IGNBRK | BRKINT | IGNPAR | PARMRK |
5222 INPCK | ISTRIP | IXON | IXANY | IXOFF);
5224 if ((ch->ch_startc == _POSIX_VDISABLE) ||
5225 (ch->ch_stopc == _POSIX_VDISABLE)) {
5226 iflag &= ~(IXON | IXOFF);
5227 ch->ch_c_iflag &= ~(IXON | IXOFF);
5231 * Only the IBM Xr card can switch between
5232 * 232 and 422 modes on the fly
5234 if (bd->device == PCI_DEV_XR_IBM_DID) {
5235 if (ch->ch_digi.digi_flags & DIGI_422)
5236 dgap_cmdb(ch, SCOMMODE, MODE_422, 0, 0);
5238 dgap_cmdb(ch, SCOMMODE, MODE_232, 0, 0);
5241 if (ch->ch_digi.digi_flags & DIGI_ALTPIN)
5244 if (iflag != ch->ch_fepiflag) {
5245 ch->ch_fepiflag = iflag;
5247 /* Okay to have channel and board locks held calling this */
5248 dgap_cmdw(ch, SIFLAG, (u16) ch->ch_fepiflag, 0);
5252 * Select hardware handshaking.
5256 if (ch->ch_c_cflag & CRTSCTS)
5257 hflow |= (D_RTS(ch) | D_CTS(ch));
5258 if (ch->ch_digi.digi_flags & RTSPACE)
5260 if (ch->ch_digi.digi_flags & DTRPACE)
5262 if (ch->ch_digi.digi_flags & CTSPACE)
5264 if (ch->ch_digi.digi_flags & DSRPACE)
5266 if (ch->ch_digi.digi_flags & DCDPACE)
5269 if (hflow != ch->ch_hflow) {
5270 ch->ch_hflow = hflow;
5272 /* Okay to have channel and board locks held calling this */
5273 dgap_cmdb(ch, SHFLOW, (u8) hflow, 0xff, 0);
5277 * Set RTS and/or DTR Toggle if needed,
5278 * but only if product is FEP5+ based.
5280 if (bd->bd_flags & BD_FEP5PLUS) {
5282 if (ch->ch_digi.digi_flags & DIGI_RTS_TOGGLE)
5283 hflow2 |= (D_RTS(ch));
5284 if (ch->ch_digi.digi_flags & DIGI_DTR_TOGGLE)
5285 hflow2 |= (D_DTR(ch));
5287 dgap_cmdw_ext(ch, 0xff03, hflow2, 0);
5291 * Set modem control lines.
5294 mval ^= ch->ch_mforce & (mval ^ ch->ch_mval);
5296 if (ch->ch_mostat ^ mval) {
5297 ch->ch_mostat = mval;
5299 /* Okay to have channel and board locks held calling this */
5300 dgap_cmdb(ch, SMODEM, (u8) mval, D_RTS(ch)|D_DTR(ch), 0);
5304 * Read modem signals, and then call carrier function.
5306 ch->ch_mistat = readb(&(bs->m_stat));
5310 * Set the start and stop characters.
5312 if (ch->ch_startc != ch->ch_fepstartc ||
5313 ch->ch_stopc != ch->ch_fepstopc) {
5314 ch->ch_fepstartc = ch->ch_startc;
5315 ch->ch_fepstopc = ch->ch_stopc;
5317 /* Okay to have channel and board locks held calling this */
5318 dgap_cmdb(ch, SFLOWC, ch->ch_fepstartc, ch->ch_fepstopc, 0);
5322 * Set the Auxiliary start and stop characters.
5324 if (ch->ch_astartc != ch->ch_fepastartc ||
5325 ch->ch_astopc != ch->ch_fepastopc) {
5326 ch->ch_fepastartc = ch->ch_astartc;
5327 ch->ch_fepastopc = ch->ch_astopc;
5329 /* Okay to have channel and board locks held calling this */
5330 dgap_cmdb(ch, SAFLOWC, ch->ch_fepastartc, ch->ch_fepastopc, 0);
5337 * dgap_parity_scan()
5339 * Convert the FEP5 way of reporting parity errors and breaks into
5340 * the Linux line discipline way.
5342 static void dgap_parity_scan(struct channel_t *ch, unsigned char *cbuf,
5343 unsigned char *fbuf, int *len)
5347 unsigned char *in, *cout, *fout;
5354 if (!ch || ch->magic != DGAP_CHANNEL_MAGIC)
5359 switch (ch->pscan_state) {
5361 /* reset to sanity and fall through */
5362 ch->pscan_state = 0;
5365 /* No FF seen yet */
5366 if (c == (unsigned char) '\377')
5367 /* delete this character from stream */
5368 ch->pscan_state = 1;
5371 *fout++ = TTY_NORMAL;
5378 if (c == (unsigned char) '\377') {
5379 /* doubled ff, transform to single ff */
5381 *fout++ = TTY_NORMAL;
5383 ch->pscan_state = 0;
5385 /* save value examination in next state */
5386 ch->pscan_savechar = c;
5387 ch->pscan_state = 2;
5392 /* third character of ff sequence */
5396 if (ch->pscan_savechar == 0x0) {
5400 *fout++ = TTY_BREAK;
5402 ch->ch_err_parity++;
5403 *fout++ = TTY_PARITY;
5408 ch->pscan_state = 0;
5414 static void dgap_write_wakeup(struct board_t *bd, struct channel_t *ch,
5415 struct un_t *un, u32 mask,
5416 unsigned long *irq_flags1,
5417 unsigned long *irq_flags2)
5419 if (!(un->un_flags & mask))
5422 un->un_flags &= ~mask;
5424 if (!(un->un_flags & UN_ISOPEN))
5427 if ((un->un_tty->flags & (1 << TTY_DO_WRITE_WAKEUP)) &&
5428 un->un_tty->ldisc->ops->write_wakeup) {
5429 spin_unlock_irqrestore(&ch->ch_lock, *irq_flags2);
5430 spin_unlock_irqrestore(&bd->bd_lock, *irq_flags1);
5432 (un->un_tty->ldisc->ops->write_wakeup)(un->un_tty);
5434 spin_lock_irqsave(&bd->bd_lock, *irq_flags1);
5435 spin_lock_irqsave(&ch->ch_lock, *irq_flags2);
5437 wake_up_interruptible(&un->un_tty->write_wait);
5438 wake_up_interruptible(&un->un_flags_wait);
5441 /*=======================================================================
5443 * dgap_event - FEP to host event processing routine.
5445 * bd - Board of current event.
5447 *=======================================================================*/
5448 static int dgap_event(struct board_t *bd)
5450 struct channel_t *ch;
5453 struct bs_t __iomem *bs;
5456 struct ev_t __iomem *eaddr;
5464 if (!bd || bd->magic != DGAP_BOARD_MAGIC)
5467 spin_lock_irqsave(&bd->bd_lock, lock_flags);
5469 vaddr = bd->re_map_membase;
5472 spin_unlock_irqrestore(&bd->bd_lock, lock_flags);
5476 eaddr = (struct ev_t __iomem *) (vaddr + EVBUF);
5478 /* Get our head and tail */
5479 head = readw(&(eaddr->ev_head));
5480 tail = readw(&(eaddr->ev_tail));
5483 * Forget it if pointers out of range.
5486 if (head >= EVMAX - EVSTART || tail >= EVMAX - EVSTART ||
5487 (head | tail) & 03) {
5488 /* Let go of board lock */
5489 spin_unlock_irqrestore(&bd->bd_lock, lock_flags);
5494 * Loop to process all the events in the buffer.
5496 while (tail != head) {
5499 * Get interrupt information.
5502 event = bd->re_map_membase + tail + EVSTART;
5504 port = ioread8(event);
5505 reason = ioread8(event + 1);
5506 modem = ioread8(event + 2);
5507 b1 = ioread8(event + 3);
5510 * Make sure the interrupt is valid.
5512 if (port >= bd->nasync)
5515 if (!(reason & (IFMODEM | IFBREAK | IFTLW | IFTEM | IFDATA)))
5518 ch = bd->channels[port];
5520 if (!ch || ch->magic != DGAP_CHANNEL_MAGIC)
5524 * If we have made it here, the event was valid.
5525 * Lock down the channel.
5527 spin_lock_irqsave(&ch->ch_lock, lock_flags2);
5532 spin_unlock_irqrestore(&ch->ch_lock, lock_flags2);
5537 * Process received data.
5539 if (reason & IFDATA) {
5542 * ALL LOCKS *MUST* BE DROPPED BEFORE CALLING INPUT!
5543 * input could send some data to ld, which in turn
5544 * could do a callback to one of our other functions.
5546 spin_unlock_irqrestore(&ch->ch_lock, lock_flags2);
5547 spin_unlock_irqrestore(&bd->bd_lock, lock_flags);
5551 spin_lock_irqsave(&bd->bd_lock, lock_flags);
5552 spin_lock_irqsave(&ch->ch_lock, lock_flags2);
5554 if (ch->ch_flags & CH_RACTIVE)
5555 ch->ch_flags |= CH_RENABLE;
5557 writeb(1, &(bs->idata));
5559 if (ch->ch_flags & CH_RWAIT) {
5560 ch->ch_flags &= ~CH_RWAIT;
5562 wake_up_interruptible
5563 (&ch->ch_tun.un_flags_wait);
5568 * Process Modem change signals.
5570 if (reason & IFMODEM) {
5571 ch->ch_mistat = modem;
5578 if (reason & IFBREAK) {
5580 if (ch->ch_tun.un_tty) {
5581 /* A break has been indicated */
5583 tty_buffer_request_room
5584 (ch->ch_tun.un_tty->port, 1);
5585 tty_insert_flip_char(ch->ch_tun.un_tty->port,
5587 tty_flip_buffer_push(ch->ch_tun.un_tty->port);
5592 * Process Transmit low.
5594 if (reason & IFTLW) {
5595 dgap_write_wakeup(bd, ch, &ch->ch_tun, UN_LOW,
5596 &lock_flags, &lock_flags2);
5597 dgap_write_wakeup(bd, ch, &ch->ch_pun, UN_LOW,
5598 &lock_flags, &lock_flags2);
5599 if (ch->ch_flags & CH_WLOW) {
5600 ch->ch_flags &= ~CH_WLOW;
5601 wake_up_interruptible(&ch->ch_flags_wait);
5606 * Process Transmit empty.
5608 if (reason & IFTEM) {
5609 dgap_write_wakeup(bd, ch, &ch->ch_tun, UN_EMPTY,
5610 &lock_flags, &lock_flags2);
5611 dgap_write_wakeup(bd, ch, &ch->ch_pun, UN_EMPTY,
5612 &lock_flags, &lock_flags2);
5613 if (ch->ch_flags & CH_WEMPTY) {
5614 ch->ch_flags &= ~CH_WEMPTY;
5615 wake_up_interruptible(&ch->ch_flags_wait);
5619 spin_unlock_irqrestore(&ch->ch_lock, lock_flags2);
5622 tail = (tail + 4) & (EVMAX - EVSTART - 4);
5625 writew(tail, &(eaddr->ev_tail));
5626 spin_unlock_irqrestore(&bd->bd_lock, lock_flags);
5631 static ssize_t dgap_driver_version_show(struct device_driver *ddp, char *buf)
5633 return snprintf(buf, PAGE_SIZE, "%s\n", DG_PART);
5635 static DRIVER_ATTR(version, S_IRUSR, dgap_driver_version_show, NULL);
5638 static ssize_t dgap_driver_boards_show(struct device_driver *ddp, char *buf)
5640 return snprintf(buf, PAGE_SIZE, "%d\n", dgap_numboards);
5642 static DRIVER_ATTR(boards, S_IRUSR, dgap_driver_boards_show, NULL);
5645 static ssize_t dgap_driver_maxboards_show(struct device_driver *ddp, char *buf)
5647 return snprintf(buf, PAGE_SIZE, "%d\n", MAXBOARDS);
5649 static DRIVER_ATTR(maxboards, S_IRUSR, dgap_driver_maxboards_show, NULL);
5652 static ssize_t dgap_driver_pollcounter_show(struct device_driver *ddp,
5655 return snprintf(buf, PAGE_SIZE, "%ld\n", dgap_poll_counter);
5657 static DRIVER_ATTR(pollcounter, S_IRUSR, dgap_driver_pollcounter_show, NULL);
5659 static ssize_t dgap_driver_pollrate_show(struct device_driver *ddp, char *buf)
5661 return snprintf(buf, PAGE_SIZE, "%dms\n", dgap_poll_tick);
5664 static ssize_t dgap_driver_pollrate_store(struct device_driver *ddp,
5665 const char *buf, size_t count)
5667 if (sscanf(buf, "%d\n", &dgap_poll_tick) != 1)
5671 static DRIVER_ATTR(pollrate, (S_IRUSR | S_IWUSR), dgap_driver_pollrate_show,
5672 dgap_driver_pollrate_store);
5674 static int dgap_create_driver_sysfiles(struct pci_driver *dgap_driver)
5677 struct device_driver *driverfs = &dgap_driver->driver;
5679 rc |= driver_create_file(driverfs, &driver_attr_version);
5680 rc |= driver_create_file(driverfs, &driver_attr_boards);
5681 rc |= driver_create_file(driverfs, &driver_attr_maxboards);
5682 rc |= driver_create_file(driverfs, &driver_attr_pollrate);
5683 rc |= driver_create_file(driverfs, &driver_attr_pollcounter);
5688 static void dgap_remove_driver_sysfiles(struct pci_driver *dgap_driver)
5690 struct device_driver *driverfs = &dgap_driver->driver;
5691 driver_remove_file(driverfs, &driver_attr_version);
5692 driver_remove_file(driverfs, &driver_attr_boards);
5693 driver_remove_file(driverfs, &driver_attr_maxboards);
5694 driver_remove_file(driverfs, &driver_attr_pollrate);
5695 driver_remove_file(driverfs, &driver_attr_pollcounter);
5698 static struct board_t *dgap_verify_board(struct device *p)
5705 bd = dev_get_drvdata(p);
5706 if (!bd || bd->magic != DGAP_BOARD_MAGIC || bd->state != BOARD_READY)
5712 static ssize_t dgap_ports_state_show(struct device *p,
5713 struct device_attribute *attr,
5720 bd = dgap_verify_board(p);
5724 for (i = 0; i < bd->nasync; i++) {
5725 count += snprintf(buf + count, PAGE_SIZE - count,
5726 "%d %s\n", bd->channels[i]->ch_portnum,
5727 bd->channels[i]->ch_open_count ? "Open" : "Closed");
5731 static DEVICE_ATTR(ports_state, S_IRUSR, dgap_ports_state_show, NULL);
5733 static ssize_t dgap_ports_baud_show(struct device *p,
5734 struct device_attribute *attr,
5741 bd = dgap_verify_board(p);
5745 for (i = 0; i < bd->nasync; i++) {
5746 count += snprintf(buf + count, PAGE_SIZE - count, "%d %d\n",
5747 bd->channels[i]->ch_portnum,
5748 bd->channels[i]->ch_baud_info);
5752 static DEVICE_ATTR(ports_baud, S_IRUSR, dgap_ports_baud_show, NULL);
5754 static ssize_t dgap_ports_msignals_show(struct device *p,
5755 struct device_attribute *attr,
5762 bd = dgap_verify_board(p);
5766 for (i = 0; i < bd->nasync; i++) {
5767 if (bd->channels[i]->ch_open_count)
5768 count += snprintf(buf + count, PAGE_SIZE - count,
5769 "%d %s %s %s %s %s %s\n",
5770 bd->channels[i]->ch_portnum,
5771 (bd->channels[i]->ch_mostat &
5772 UART_MCR_RTS) ? "RTS" : "",
5773 (bd->channels[i]->ch_mistat &
5774 UART_MSR_CTS) ? "CTS" : "",
5775 (bd->channels[i]->ch_mostat &
5776 UART_MCR_DTR) ? "DTR" : "",
5777 (bd->channels[i]->ch_mistat &
5778 UART_MSR_DSR) ? "DSR" : "",
5779 (bd->channels[i]->ch_mistat &
5780 UART_MSR_DCD) ? "DCD" : "",
5781 (bd->channels[i]->ch_mistat &
5782 UART_MSR_RI) ? "RI" : "");
5784 count += snprintf(buf + count, PAGE_SIZE - count,
5785 "%d\n", bd->channels[i]->ch_portnum);
5789 static DEVICE_ATTR(ports_msignals, S_IRUSR, dgap_ports_msignals_show, NULL);
5791 static ssize_t dgap_ports_iflag_show(struct device *p,
5792 struct device_attribute *attr,
5799 bd = dgap_verify_board(p);
5803 for (i = 0; i < bd->nasync; i++)
5804 count += snprintf(buf + count, PAGE_SIZE - count, "%d %x\n",
5805 bd->channels[i]->ch_portnum,
5806 bd->channels[i]->ch_c_iflag);
5809 static DEVICE_ATTR(ports_iflag, S_IRUSR, dgap_ports_iflag_show, NULL);
5811 static ssize_t dgap_ports_cflag_show(struct device *p,
5812 struct device_attribute *attr,
5819 bd = dgap_verify_board(p);
5823 for (i = 0; i < bd->nasync; i++)
5824 count += snprintf(buf + count, PAGE_SIZE - count, "%d %x\n",
5825 bd->channels[i]->ch_portnum,
5826 bd->channels[i]->ch_c_cflag);
5829 static DEVICE_ATTR(ports_cflag, S_IRUSR, dgap_ports_cflag_show, NULL);
5831 static ssize_t dgap_ports_oflag_show(struct device *p,
5832 struct device_attribute *attr,
5839 bd = dgap_verify_board(p);
5843 for (i = 0; i < bd->nasync; i++)
5844 count += snprintf(buf + count, PAGE_SIZE - count, "%d %x\n",
5845 bd->channels[i]->ch_portnum,
5846 bd->channels[i]->ch_c_oflag);
5849 static DEVICE_ATTR(ports_oflag, S_IRUSR, dgap_ports_oflag_show, NULL);
5851 static ssize_t dgap_ports_lflag_show(struct device *p,
5852 struct device_attribute *attr,
5859 bd = dgap_verify_board(p);
5863 for (i = 0; i < bd->nasync; i++)
5864 count += snprintf(buf + count, PAGE_SIZE - count, "%d %x\n",
5865 bd->channels[i]->ch_portnum,
5866 bd->channels[i]->ch_c_lflag);
5869 static DEVICE_ATTR(ports_lflag, S_IRUSR, dgap_ports_lflag_show, NULL);
5871 static ssize_t dgap_ports_digi_flag_show(struct device *p,
5872 struct device_attribute *attr,
5879 bd = dgap_verify_board(p);
5883 for (i = 0; i < bd->nasync; i++)
5884 count += snprintf(buf + count, PAGE_SIZE - count, "%d %x\n",
5885 bd->channels[i]->ch_portnum,
5886 bd->channels[i]->ch_digi.digi_flags);
5889 static DEVICE_ATTR(ports_digi_flag, S_IRUSR, dgap_ports_digi_flag_show, NULL);
5891 static ssize_t dgap_ports_rxcount_show(struct device *p,
5892 struct device_attribute *attr,
5899 bd = dgap_verify_board(p);
5903 for (i = 0; i < bd->nasync; i++)
5904 count += snprintf(buf + count, PAGE_SIZE - count, "%d %ld\n",
5905 bd->channels[i]->ch_portnum,
5906 bd->channels[i]->ch_rxcount);
5909 static DEVICE_ATTR(ports_rxcount, S_IRUSR, dgap_ports_rxcount_show, NULL);
5911 static ssize_t dgap_ports_txcount_show(struct device *p,
5912 struct device_attribute *attr,
5919 bd = dgap_verify_board(p);
5923 for (i = 0; i < bd->nasync; i++)
5924 count += snprintf(buf + count, PAGE_SIZE - count, "%d %ld\n",
5925 bd->channels[i]->ch_portnum,
5926 bd->channels[i]->ch_txcount);
5929 static DEVICE_ATTR(ports_txcount, S_IRUSR, dgap_ports_txcount_show, NULL);
5931 /* this function creates the sys files that will export each signal status
5932 * to sysfs each value will be put in a separate filename
5934 static void dgap_create_ports_sysfiles(struct board_t *bd)
5936 dev_set_drvdata(&bd->pdev->dev, bd);
5937 device_create_file(&(bd->pdev->dev), &dev_attr_ports_state);
5938 device_create_file(&(bd->pdev->dev), &dev_attr_ports_baud);
5939 device_create_file(&(bd->pdev->dev), &dev_attr_ports_msignals);
5940 device_create_file(&(bd->pdev->dev), &dev_attr_ports_iflag);
5941 device_create_file(&(bd->pdev->dev), &dev_attr_ports_cflag);
5942 device_create_file(&(bd->pdev->dev), &dev_attr_ports_oflag);
5943 device_create_file(&(bd->pdev->dev), &dev_attr_ports_lflag);
5944 device_create_file(&(bd->pdev->dev), &dev_attr_ports_digi_flag);
5945 device_create_file(&(bd->pdev->dev), &dev_attr_ports_rxcount);
5946 device_create_file(&(bd->pdev->dev), &dev_attr_ports_txcount);
5949 /* removes all the sys files created for that port */
5950 static void dgap_remove_ports_sysfiles(struct board_t *bd)
5952 device_remove_file(&(bd->pdev->dev), &dev_attr_ports_state);
5953 device_remove_file(&(bd->pdev->dev), &dev_attr_ports_baud);
5954 device_remove_file(&(bd->pdev->dev), &dev_attr_ports_msignals);
5955 device_remove_file(&(bd->pdev->dev), &dev_attr_ports_iflag);
5956 device_remove_file(&(bd->pdev->dev), &dev_attr_ports_cflag);
5957 device_remove_file(&(bd->pdev->dev), &dev_attr_ports_oflag);
5958 device_remove_file(&(bd->pdev->dev), &dev_attr_ports_lflag);
5959 device_remove_file(&(bd->pdev->dev), &dev_attr_ports_digi_flag);
5960 device_remove_file(&(bd->pdev->dev), &dev_attr_ports_rxcount);
5961 device_remove_file(&(bd->pdev->dev), &dev_attr_ports_txcount);
5964 static ssize_t dgap_tty_state_show(struct device *d,
5965 struct device_attribute *attr,
5969 struct channel_t *ch;
5974 un = dev_get_drvdata(d);
5975 if (!un || un->magic != DGAP_UNIT_MAGIC)
5978 if (!ch || ch->magic != DGAP_CHANNEL_MAGIC)
5981 if (!bd || bd->magic != DGAP_BOARD_MAGIC)
5983 if (bd->state != BOARD_READY)
5986 return snprintf(buf, PAGE_SIZE, "%s", un->un_open_count ?
5989 static DEVICE_ATTR(state, S_IRUSR, dgap_tty_state_show, NULL);
5991 static ssize_t dgap_tty_baud_show(struct device *d,
5992 struct device_attribute *attr,
5996 struct channel_t *ch;
6001 un = dev_get_drvdata(d);
6002 if (!un || un->magic != DGAP_UNIT_MAGIC)
6005 if (!ch || ch->magic != DGAP_CHANNEL_MAGIC)
6008 if (!bd || bd->magic != DGAP_BOARD_MAGIC)
6010 if (bd->state != BOARD_READY)
6013 return snprintf(buf, PAGE_SIZE, "%d\n", ch->ch_baud_info);
6015 static DEVICE_ATTR(baud, S_IRUSR, dgap_tty_baud_show, NULL);
6017 static ssize_t dgap_tty_msignals_show(struct device *d,
6018 struct device_attribute *attr,
6022 struct channel_t *ch;
6027 un = dev_get_drvdata(d);
6028 if (!un || un->magic != DGAP_UNIT_MAGIC)
6031 if (!ch || ch->magic != DGAP_CHANNEL_MAGIC)
6034 if (!bd || bd->magic != DGAP_BOARD_MAGIC)
6036 if (bd->state != BOARD_READY)
6039 if (ch->ch_open_count) {
6040 return snprintf(buf, PAGE_SIZE, "%s %s %s %s %s %s\n",
6041 (ch->ch_mostat & UART_MCR_RTS) ? "RTS" : "",
6042 (ch->ch_mistat & UART_MSR_CTS) ? "CTS" : "",
6043 (ch->ch_mostat & UART_MCR_DTR) ? "DTR" : "",
6044 (ch->ch_mistat & UART_MSR_DSR) ? "DSR" : "",
6045 (ch->ch_mistat & UART_MSR_DCD) ? "DCD" : "",
6046 (ch->ch_mistat & UART_MSR_RI) ? "RI" : "");
6050 static DEVICE_ATTR(msignals, S_IRUSR, dgap_tty_msignals_show, NULL);
6052 static ssize_t dgap_tty_iflag_show(struct device *d,
6053 struct device_attribute *attr,
6057 struct channel_t *ch;
6062 un = dev_get_drvdata(d);
6063 if (!un || un->magic != DGAP_UNIT_MAGIC)
6066 if (!ch || ch->magic != DGAP_CHANNEL_MAGIC)
6069 if (!bd || bd->magic != DGAP_BOARD_MAGIC)
6071 if (bd->state != BOARD_READY)
6074 return snprintf(buf, PAGE_SIZE, "%x\n", ch->ch_c_iflag);
6076 static DEVICE_ATTR(iflag, S_IRUSR, dgap_tty_iflag_show, NULL);
6078 static ssize_t dgap_tty_cflag_show(struct device *d,
6079 struct device_attribute *attr,
6083 struct channel_t *ch;
6088 un = dev_get_drvdata(d);
6089 if (!un || un->magic != DGAP_UNIT_MAGIC)
6092 if (!ch || ch->magic != DGAP_CHANNEL_MAGIC)
6095 if (!bd || bd->magic != DGAP_BOARD_MAGIC)
6097 if (bd->state != BOARD_READY)
6100 return snprintf(buf, PAGE_SIZE, "%x\n", ch->ch_c_cflag);
6102 static DEVICE_ATTR(cflag, S_IRUSR, dgap_tty_cflag_show, NULL);
6104 static ssize_t dgap_tty_oflag_show(struct device *d,
6105 struct device_attribute *attr,
6109 struct channel_t *ch;
6114 un = dev_get_drvdata(d);
6115 if (!un || un->magic != DGAP_UNIT_MAGIC)
6118 if (!ch || ch->magic != DGAP_CHANNEL_MAGIC)
6121 if (!bd || bd->magic != DGAP_BOARD_MAGIC)
6123 if (bd->state != BOARD_READY)
6126 return snprintf(buf, PAGE_SIZE, "%x\n", ch->ch_c_oflag);
6128 static DEVICE_ATTR(oflag, S_IRUSR, dgap_tty_oflag_show, NULL);
6130 static ssize_t dgap_tty_lflag_show(struct device *d,
6131 struct device_attribute *attr,
6135 struct channel_t *ch;
6140 un = dev_get_drvdata(d);
6141 if (!un || un->magic != DGAP_UNIT_MAGIC)
6144 if (!ch || ch->magic != DGAP_CHANNEL_MAGIC)
6147 if (!bd || bd->magic != DGAP_BOARD_MAGIC)
6149 if (bd->state != BOARD_READY)
6152 return snprintf(buf, PAGE_SIZE, "%x\n", ch->ch_c_lflag);
6154 static DEVICE_ATTR(lflag, S_IRUSR, dgap_tty_lflag_show, NULL);
6156 static ssize_t dgap_tty_digi_flag_show(struct device *d,
6157 struct device_attribute *attr,
6161 struct channel_t *ch;
6166 un = dev_get_drvdata(d);
6167 if (!un || un->magic != DGAP_UNIT_MAGIC)
6170 if (!ch || ch->magic != DGAP_CHANNEL_MAGIC)
6173 if (!bd || bd->magic != DGAP_BOARD_MAGIC)
6175 if (bd->state != BOARD_READY)
6178 return snprintf(buf, PAGE_SIZE, "%x\n", ch->ch_digi.digi_flags);
6180 static DEVICE_ATTR(digi_flag, S_IRUSR, dgap_tty_digi_flag_show, NULL);
6182 static ssize_t dgap_tty_rxcount_show(struct device *d,
6183 struct device_attribute *attr,
6187 struct channel_t *ch;
6192 un = dev_get_drvdata(d);
6193 if (!un || un->magic != DGAP_UNIT_MAGIC)
6196 if (!ch || ch->magic != DGAP_CHANNEL_MAGIC)
6199 if (!bd || bd->magic != DGAP_BOARD_MAGIC)
6201 if (bd->state != BOARD_READY)
6204 return snprintf(buf, PAGE_SIZE, "%ld\n", ch->ch_rxcount);
6206 static DEVICE_ATTR(rxcount, S_IRUSR, dgap_tty_rxcount_show, NULL);
6208 static ssize_t dgap_tty_txcount_show(struct device *d,
6209 struct device_attribute *attr,
6213 struct channel_t *ch;
6218 un = dev_get_drvdata(d);
6219 if (!un || un->magic != DGAP_UNIT_MAGIC)
6222 if (!ch || ch->magic != DGAP_CHANNEL_MAGIC)
6225 if (!bd || bd->magic != DGAP_BOARD_MAGIC)
6227 if (bd->state != BOARD_READY)
6230 return snprintf(buf, PAGE_SIZE, "%ld\n", ch->ch_txcount);
6232 static DEVICE_ATTR(txcount, S_IRUSR, dgap_tty_txcount_show, NULL);
6234 static ssize_t dgap_tty_name_show(struct device *d,
6235 struct device_attribute *attr,
6239 struct channel_t *ch;
6251 un = dev_get_drvdata(d);
6252 if (!un || un->magic != DGAP_UNIT_MAGIC)
6255 if (!ch || ch->magic != DGAP_CHANNEL_MAGIC)
6258 if (!bd || bd->magic != DGAP_BOARD_MAGIC)
6260 if (bd->state != BOARD_READY)
6264 cn = ch->ch_portnum;
6266 for (cptr = bd->bd_config; cptr; cptr = cptr->next) {
6268 if ((cptr->type == BNODE) &&
6269 ((cptr->u.board.type == APORT2_920P) ||
6270 (cptr->u.board.type == APORT4_920P) ||
6271 (cptr->u.board.type == APORT8_920P) ||
6272 (cptr->u.board.type == PAPORT4) ||
6273 (cptr->u.board.type == PAPORT8))) {
6276 if (cptr->u.board.v_start)
6277 starto = cptr->u.board.start;
6282 if (cptr->type == TNODE && found == TRUE) {
6284 if (strstr(cptr->u.ttyname, "tty")) {
6285 ptr1 = cptr->u.ttyname;
6288 ptr1 = cptr->u.ttyname;
6290 for (i = 0; i < dgap_config_get_num_prts(bd); i++) {
6294 return snprintf(buf, PAGE_SIZE, "%s%s%02d\n",
6295 (un->un_type == DGAP_PRINT) ?
6301 if (cptr->type == CNODE) {
6303 for (i = 0; i < cptr->u.conc.nport; i++) {
6304 if (cn != (i + ncount))
6307 return snprintf(buf, PAGE_SIZE, "%s%s%02ld\n",
6308 (un->un_type == DGAP_PRINT) ?
6311 i + (cptr->u.conc.v_start ?
6312 cptr->u.conc.start : 1));
6315 ncount += cptr->u.conc.nport;
6318 if (cptr->type == MNODE) {
6320 for (i = 0; i < cptr->u.module.nport; i++) {
6321 if (cn != (i + ncount))
6324 return snprintf(buf, PAGE_SIZE, "%s%s%02ld\n",
6325 (un->un_type == DGAP_PRINT) ?
6328 i + (cptr->u.module.v_start ?
6329 cptr->u.module.start : 1));
6332 ncount += cptr->u.module.nport;
6337 return snprintf(buf, PAGE_SIZE, "%s_dgap_%d_%d\n",
6338 (un->un_type == DGAP_PRINT) ? "pr" : "tty", bn, cn);
6340 static DEVICE_ATTR(custom_name, S_IRUSR, dgap_tty_name_show, NULL);
6342 static struct attribute *dgap_sysfs_tty_entries[] = {
6343 &dev_attr_state.attr,
6344 &dev_attr_baud.attr,
6345 &dev_attr_msignals.attr,
6346 &dev_attr_iflag.attr,
6347 &dev_attr_cflag.attr,
6348 &dev_attr_oflag.attr,
6349 &dev_attr_lflag.attr,
6350 &dev_attr_digi_flag.attr,
6351 &dev_attr_rxcount.attr,
6352 &dev_attr_txcount.attr,
6353 &dev_attr_custom_name.attr,
6357 static struct attribute_group dgap_tty_attribute_group = {
6359 .attrs = dgap_sysfs_tty_entries,
6362 static void dgap_create_tty_sysfs(struct un_t *un, struct device *c)
6366 ret = sysfs_create_group(&c->kobj, &dgap_tty_attribute_group);
6370 dev_set_drvdata(c, un);
6374 static void dgap_remove_tty_sysfs(struct device *c)
6376 sysfs_remove_group(&c->kobj, &dgap_tty_attribute_group);
6380 * Parse a configuration file read into memory as a string.
6382 static int dgap_parsefile(char **in, int remove)
6384 struct cnode *p, *brd, *line, *conc;
6390 brd = line = conc = NULL;
6392 /* perhaps we are adding to an existing list? */
6396 /* file must start with a BEGIN */
6397 while ((rc = dgap_gettok(in, p)) != BEGIN) {
6399 dgap_err("unexpected EOF");
6405 rc = dgap_gettok(in, p);
6407 dgap_err("unexpected EOF");
6413 dgap_err("unexpected end of file");
6416 case BEGIN: /* should only be 1 begin */
6417 dgap_err("unexpected config_begin\n");
6423 case BOARD: /* board info */
6424 if (dgap_checknode(p))
6426 p->next = dgap_newnode(BNODE);
6428 dgap_err("out of memory");
6433 p->u.board.status = kstrdup("No", GFP_KERNEL);
6439 case APORT2_920P: /* AccelePort_4 */
6440 if (p->type != BNODE) {
6441 dgap_err("unexpected Digi_2r_920 string");
6444 p->u.board.type = APORT2_920P;
6445 p->u.board.v_type = 1;
6448 case APORT4_920P: /* AccelePort_4 */
6449 if (p->type != BNODE) {
6450 dgap_err("unexpected Digi_4r_920 string");
6453 p->u.board.type = APORT4_920P;
6454 p->u.board.v_type = 1;
6457 case APORT8_920P: /* AccelePort_8 */
6458 if (p->type != BNODE) {
6459 dgap_err("unexpected Digi_8r_920 string");
6462 p->u.board.type = APORT8_920P;
6463 p->u.board.v_type = 1;
6466 case PAPORT4: /* AccelePort_4 PCI */
6467 if (p->type != BNODE) {
6468 dgap_err("unexpected Digi_4r(PCI) string");
6471 p->u.board.type = PAPORT4;
6472 p->u.board.v_type = 1;
6475 case PAPORT8: /* AccelePort_8 PCI */
6476 if (p->type != BNODE) {
6477 dgap_err("unexpected Digi_8r string");
6480 p->u.board.type = PAPORT8;
6481 p->u.board.v_type = 1;
6484 case PCX: /* PCI C/X */
6485 if (p->type != BNODE) {
6486 dgap_err("unexpected Digi_C/X_(PCI) string");
6489 p->u.board.type = PCX;
6490 p->u.board.v_type = 1;
6491 p->u.board.conc1 = 0;
6492 p->u.board.conc2 = 0;
6493 p->u.board.module1 = 0;
6494 p->u.board.module2 = 0;
6497 case PEPC: /* PCI EPC/X */
6498 if (p->type != BNODE) {
6499 dgap_err("unexpected \"Digi_EPC/X_(PCI)\" string");
6502 p->u.board.type = PEPC;
6503 p->u.board.v_type = 1;
6504 p->u.board.conc1 = 0;
6505 p->u.board.conc2 = 0;
6506 p->u.board.module1 = 0;
6507 p->u.board.module2 = 0;
6510 case PPCM: /* PCI/Xem */
6511 if (p->type != BNODE) {
6512 dgap_err("unexpected PCI/Xem string");
6515 p->u.board.type = PPCM;
6516 p->u.board.v_type = 1;
6517 p->u.board.conc1 = 0;
6518 p->u.board.conc2 = 0;
6521 case IO: /* i/o port */
6522 if (p->type != BNODE) {
6523 dgap_err("IO port only vaild for boards");
6526 s = dgap_getword(in);
6528 dgap_err("unexpected end of file");
6531 p->u.board.portstr = kstrdup(s, GFP_KERNEL);
6532 if (kstrtol(s, 0, &p->u.board.port)) {
6533 dgap_err("bad number for IO port");
6536 p->u.board.v_port = 1;
6539 case MEM: /* memory address */
6540 if (p->type != BNODE) {
6541 dgap_err("memory address only vaild for boards");
6544 s = dgap_getword(in);
6546 dgap_err("unexpected end of file");
6549 p->u.board.addrstr = kstrdup(s, GFP_KERNEL);
6550 if (kstrtoul(s, 0, &p->u.board.addr)) {
6551 dgap_err("bad number for memory address");
6554 p->u.board.v_addr = 1;
6557 case PCIINFO: /* pci information */
6558 if (p->type != BNODE) {
6559 dgap_err("memory address only vaild for boards");
6562 s = dgap_getword(in);
6564 dgap_err("unexpected end of file");
6567 p->u.board.pcibusstr = kstrdup(s, GFP_KERNEL);
6568 if (kstrtoul(s, 0, &p->u.board.pcibus)) {
6569 dgap_err("bad number for pci bus");
6572 p->u.board.v_pcibus = 1;
6573 s = dgap_getword(in);
6575 dgap_err("unexpected end of file");
6578 p->u.board.pcislotstr = kstrdup(s, GFP_KERNEL);
6579 if (kstrtoul(s, 0, &p->u.board.pcislot)) {
6580 dgap_err("bad number for pci slot");
6583 p->u.board.v_pcislot = 1;
6587 if (p->type != BNODE) {
6588 dgap_err("install method only vaild for boards");
6591 s = dgap_getword(in);
6593 dgap_err("unexpected end of file");
6596 p->u.board.method = kstrdup(s, GFP_KERNEL);
6597 p->u.board.v_method = 1;
6601 if (p->type != BNODE) {
6602 dgap_err("config status only vaild for boards");
6605 s = dgap_getword(in);
6607 dgap_err("unexpected end of file");
6610 p->u.board.status = kstrdup(s, GFP_KERNEL);
6613 case NPORTS: /* number of ports */
6614 if (p->type == BNODE) {
6615 s = dgap_getword(in);
6617 dgap_err("unexpected end of file");
6620 if (kstrtol(s, 0, &p->u.board.nport)) {
6621 dgap_err("bad number for number of ports");
6624 p->u.board.v_nport = 1;
6625 } else if (p->type == CNODE) {
6626 s = dgap_getword(in);
6628 dgap_err("unexpected end of file");
6631 if (kstrtol(s, 0, &p->u.conc.nport)) {
6632 dgap_err("bad number for number of ports");
6635 p->u.conc.v_nport = 1;
6636 } else if (p->type == MNODE) {
6637 s = dgap_getword(in);
6639 dgap_err("unexpected end of file");
6642 if (kstrtol(s, 0, &p->u.module.nport)) {
6643 dgap_err("bad number for number of ports");
6646 p->u.module.v_nport = 1;
6648 dgap_err("nports only valid for concentrators or modules");
6653 case ID: /* letter ID used in tty name */
6654 s = dgap_getword(in);
6656 dgap_err("unexpected end of file");
6660 p->u.board.status = kstrdup(s, GFP_KERNEL);
6662 if (p->type == CNODE) {
6663 p->u.conc.id = kstrdup(s, GFP_KERNEL);
6665 } else if (p->type == MNODE) {
6666 p->u.module.id = kstrdup(s, GFP_KERNEL);
6667 p->u.module.v_id = 1;
6669 dgap_err("id only valid for concentrators or modules");
6674 case STARTO: /* start offset of ID */
6675 if (p->type == BNODE) {
6676 s = dgap_getword(in);
6678 dgap_err("unexpected end of file");
6681 if (kstrtol(s, 0, &p->u.board.start)) {
6682 dgap_err("bad number for start of tty count");
6685 p->u.board.v_start = 1;
6686 } else if (p->type == CNODE) {
6687 s = dgap_getword(in);
6689 dgap_err("unexpected end of file");
6692 if (kstrtol(s, 0, &p->u.conc.start)) {
6693 dgap_err("bad number for start of tty count");
6696 p->u.conc.v_start = 1;
6697 } else if (p->type == MNODE) {
6698 s = dgap_getword(in);
6700 dgap_err("unexpected end of file");
6703 if (kstrtol(s, 0, &p->u.module.start)) {
6704 dgap_err("bad number for start of tty count");
6707 p->u.module.v_start = 1;
6709 dgap_err("start only valid for concentrators or modules");
6714 case TTYN: /* tty name prefix */
6715 if (dgap_checknode(p))
6717 p->next = dgap_newnode(TNODE);
6719 dgap_err("out of memory");
6723 s = dgap_getword(in);
6725 dgap_err("unexpeced end of file");
6728 p->u.ttyname = kstrdup(s, GFP_KERNEL);
6729 if (!p->u.ttyname) {
6730 dgap_err("out of memory");
6735 case CU: /* cu name prefix */
6736 if (dgap_checknode(p))
6738 p->next = dgap_newnode(CUNODE);
6740 dgap_err("out of memory");
6744 s = dgap_getword(in);
6746 dgap_err("unexpeced end of file");
6749 p->u.cuname = kstrdup(s, GFP_KERNEL);
6751 dgap_err("out of memory");
6756 case LINE: /* line information */
6757 if (dgap_checknode(p))
6760 dgap_err("must specify board before line info");
6763 switch (brd->u.board.type) {
6765 dgap_err("line not vaild for PC/em");
6768 p->next = dgap_newnode(LNODE);
6770 dgap_err("out of memory");
6779 case CONC: /* concentrator information */
6780 if (dgap_checknode(p))
6783 dgap_err("must specify line info before concentrator");
6786 p->next = dgap_newnode(CNODE);
6788 dgap_err("out of memory");
6794 brd->u.board.conc2++;
6796 brd->u.board.conc1++;
6800 case CX: /* c/x type concentrator */
6801 if (p->type != CNODE) {
6802 dgap_err("cx only valid for concentrators");
6805 p->u.conc.type = CX;
6806 p->u.conc.v_type = 1;
6809 case EPC: /* epc type concentrator */
6810 if (p->type != CNODE) {
6811 dgap_err("cx only valid for concentrators");
6814 p->u.conc.type = EPC;
6815 p->u.conc.v_type = 1;
6818 case MOD: /* EBI module */
6819 if (dgap_checknode(p))
6822 dgap_err("must specify board info before EBI modules");
6825 switch (brd->u.board.type) {
6831 dgap_err("must specify concentrator info before EBI module");
6835 p->next = dgap_newnode(MNODE);
6837 dgap_err("out of memory");
6842 brd->u.board.module2++;
6844 brd->u.board.module1++;
6848 case PORTS: /* ports type EBI module */
6849 if (p->type != MNODE) {
6850 dgap_err("ports only valid for EBI modules");
6853 p->u.module.type = PORTS;
6854 p->u.module.v_type = 1;
6857 case MODEM: /* ports type EBI module */
6858 if (p->type != MNODE) {
6859 dgap_err("modem only valid for modem modules");
6862 p->u.module.type = MODEM;
6863 p->u.module.v_type = 1;
6867 if (p->type == LNODE) {
6868 s = dgap_getword(in);
6870 dgap_err("unexpected end of file");
6873 p->u.line.cable = kstrdup(s, GFP_KERNEL);
6874 p->u.line.v_cable = 1;
6878 case SPEED: /* sync line speed indication */
6879 if (p->type == LNODE) {
6880 s = dgap_getword(in);
6882 dgap_err("unexpected end of file");
6885 if (kstrtol(s, 0, &p->u.line.speed)) {
6886 dgap_err("bad number for line speed");
6889 p->u.line.v_speed = 1;
6890 } else if (p->type == CNODE) {
6891 s = dgap_getword(in);
6893 dgap_err("unexpected end of file");
6896 if (kstrtol(s, 0, &p->u.conc.speed)) {
6897 dgap_err("bad number for line speed");
6900 p->u.conc.v_speed = 1;
6902 dgap_err("speed valid only for lines or concentrators.");
6908 if (p->type == CNODE) {
6909 s = dgap_getword(in);
6911 dgap_err("unexpected end of file");
6914 p->u.conc.connect = kstrdup(s, GFP_KERNEL);
6915 p->u.conc.v_connect = 1;
6918 case PRINT: /* transparent print name prefix */
6919 if (dgap_checknode(p))
6921 p->next = dgap_newnode(PNODE);
6923 dgap_err("out of memory");
6927 s = dgap_getword(in);
6929 dgap_err("unexpeced end of file");
6932 p->u.printname = kstrdup(s, GFP_KERNEL);
6933 if (!p->u.printname) {
6934 dgap_err("out of memory");
6939 case CMAJOR: /* major number */
6940 if (dgap_checknode(p))
6942 p->next = dgap_newnode(JNODE);
6944 dgap_err("out of memory");
6948 s = dgap_getword(in);
6950 dgap_err("unexpected end of file");
6953 if (kstrtol(s, 0, &p->u.majornumber)) {
6954 dgap_err("bad number for major number");
6959 case ALTPIN: /* altpin setting */
6960 if (dgap_checknode(p))
6962 p->next = dgap_newnode(ANODE);
6964 dgap_err("out of memory");
6968 s = dgap_getword(in);
6970 dgap_err("unexpected end of file");
6973 if (kstrtol(s, 0, &p->u.altpin)) {
6974 dgap_err("bad number for altpin");
6979 case USEINTR: /* enable interrupt setting */
6980 if (dgap_checknode(p))
6982 p->next = dgap_newnode(INTRNODE);
6984 dgap_err("out of memory");
6988 s = dgap_getword(in);
6990 dgap_err("unexpected end of file");
6993 if (kstrtol(s, 0, &p->u.useintr)) {
6994 dgap_err("bad number for useintr");
6999 case TTSIZ: /* size of tty structure */
7000 if (dgap_checknode(p))
7002 p->next = dgap_newnode(TSNODE);
7004 dgap_err("out of memory");
7008 s = dgap_getword(in);
7010 dgap_err("unexpected end of file");
7013 if (kstrtol(s, 0, &p->u.ttysize)) {
7014 dgap_err("bad number for ttysize");
7019 case CHSIZ: /* channel structure size */
7020 if (dgap_checknode(p))
7022 p->next = dgap_newnode(CSNODE);
7024 dgap_err("out of memory");
7028 s = dgap_getword(in);
7030 dgap_err("unexpected end of file");
7033 if (kstrtol(s, 0, &p->u.chsize)) {
7034 dgap_err("bad number for chsize");
7039 case BSSIZ: /* board structure size */
7040 if (dgap_checknode(p))
7042 p->next = dgap_newnode(BSNODE);
7044 dgap_err("out of memory");
7048 s = dgap_getword(in);
7050 dgap_err("unexpected end of file");
7053 if (kstrtol(s, 0, &p->u.bssize)) {
7054 dgap_err("bad number for bssize");
7059 case UNTSIZ: /* sched structure size */
7060 if (dgap_checknode(p))
7062 p->next = dgap_newnode(USNODE);
7064 dgap_err("out of memory");
7068 s = dgap_getword(in);
7070 dgap_err("unexpected end of file");
7073 if (kstrtol(s, 0, &p->u.unsize)) {
7074 dgap_err("bad number for schedsize");
7079 case F2SIZ: /* f2200 structure size */
7080 if (dgap_checknode(p))
7082 p->next = dgap_newnode(FSNODE);
7084 dgap_err("out of memory");
7088 s = dgap_getword(in);
7090 dgap_err("unexpected end of file");
7093 if (kstrtol(s, 0, &p->u.f2size)) {
7094 dgap_err("bad number for f2200size");
7099 case VPSIZ: /* vpix structure size */
7100 if (dgap_checknode(p))
7102 p->next = dgap_newnode(VSNODE);
7104 dgap_err("out of memory");
7108 s = dgap_getword(in);
7110 dgap_err("unexpected end of file");
7113 if (kstrtol(s, 0, &p->u.vpixsize)) {
7114 dgap_err("bad number for vpixsize");
7123 * dgap_sindex: much like index(), but it looks for a match of any character in
7124 * the group, and returns that position. If the first character is a ^, then
7125 * this will match the first occurrence not in that group.
7127 static char *dgap_sindex(char *string, char *group)
7131 if (!string || !group)
7132 return (char *) NULL;
7134 if (*group == '^') {
7136 for (; *string; string++) {
7137 for (ptr = group; *ptr; ptr++) {
7138 if (*ptr == *string)
7145 for (; *string; string++) {
7146 for (ptr = group; *ptr; ptr++) {
7147 if (*ptr == *string)
7153 return (char *) NULL;
7157 * Get a token from the input file; return 0 if end of file is reached
7159 static int dgap_gettok(char **in, struct cnode *p)
7164 if (strstr(dgap_cword, "boar")) {
7165 w = dgap_getword(in);
7166 snprintf(dgap_cword, MAXCWORD, "%s", w);
7167 for (t = dgap_tlist; t->token != 0; t++) {
7168 if (!strcmp(w, t->string))
7171 dgap_err("board !!type not specified");
7174 while ((w = dgap_getword(in))) {
7175 snprintf(dgap_cword, MAXCWORD, "%s", w);
7176 for (t = dgap_tlist; t->token != 0; t++) {
7177 if (!strcmp(w, t->string))
7186 * get a word from the input stream, also keep track of current line number.
7187 * words are separated by whitespace.
7189 static char *dgap_getword(char **in)
7191 char *ret_ptr = *in;
7193 char *ptr = dgap_sindex(*in, " \t\n");
7195 /* If no word found, return null */
7199 /* Mark new location for our buffer */
7203 /* Eat any extra spaces/tabs/newlines that might be present */
7204 while (*in && **in && ((**in == ' ') ||
7215 * print an error message, giving the line number in the file where
7216 * the error occurred.
7218 static void dgap_err(char *s)
7220 pr_err("dgap: parse: %s\n", s);
7224 * allocate a new configuration node of type t
7226 static struct cnode *dgap_newnode(int t)
7230 n = kmalloc(sizeof(struct cnode), GFP_KERNEL);
7232 memset((char *)n, 0, sizeof(struct cnode));
7239 * dgap_checknode: see if all the necessary info has been supplied for a node
7240 * before creating the next node.
7242 static int dgap_checknode(struct cnode *p)
7246 if (p->u.board.v_type == 0) {
7247 dgap_err("board type !not specified");
7254 if (p->u.line.v_speed == 0) {
7255 dgap_err("line speed not specified");
7261 if (p->u.conc.v_type == 0) {
7262 dgap_err("concentrator type not specified");
7265 if (p->u.conc.v_speed == 0) {
7266 dgap_err("concentrator line speed not specified");
7269 if (p->u.conc.v_nport == 0) {
7270 dgap_err("number of ports on concentrator not specified");
7273 if (p->u.conc.v_id == 0) {
7274 dgap_err("concentrator id letter not specified");
7280 if (p->u.module.v_type == 0) {
7281 dgap_err("EBI module type not specified");
7284 if (p->u.module.v_nport == 0) {
7285 dgap_err("number of ports on EBI module not specified");
7288 if (p->u.module.v_id == 0) {
7289 dgap_err("EBI module id letter not specified");
7298 * Given a board pointer, returns whether we should use interrupts or not.
7300 static uint dgap_config_get_useintr(struct board_t *bd)
7307 for (p = bd->bd_config; p; p = p->next) {
7308 if (p->type == INTRNODE) {
7310 * check for pcxr types.
7312 return p->u.useintr;
7316 /* If not found, then don't turn on interrupts. */
7321 * Given a board pointer, returns whether we turn on altpin or not.
7323 static uint dgap_config_get_altpin(struct board_t *bd)
7330 for (p = bd->bd_config; p; p = p->next) {
7331 if (p->type == ANODE) {
7333 * check for pcxr types.
7339 /* If not found, then don't turn on interrupts. */
7344 * Given a specific type of board, if found, detached link and
7345 * returns the first occurrence in the list.
7347 static struct cnode *dgap_find_config(int type, int bus, int slot)
7349 struct cnode *p, *prev, *prev2, *found;
7357 if (p->type != BNODE)
7360 if (p->u.board.type != type)
7363 if (p->u.board.v_pcibus &&
7364 p->u.board.pcibus != bus)
7367 if (p->u.board.v_pcislot &&
7368 p->u.board.pcislot != slot)
7373 * Keep walking thru the list till we
7374 * find the next board.
7380 if (p->type != BNODE)
7384 * Mark the end of our 1 board
7390 * Link the "next" board to the
7391 * previous board, effectively
7392 * "unlinking" our board from
7400 * It must be the last board in the list.
7409 * Given a board pointer, walks the config link, counting up
7410 * all ports user specified should be on the board.
7411 * (This does NOT mean they are all actually present right now tho)
7413 static uint dgap_config_get_num_prts(struct board_t *bd)
7421 for (p = bd->bd_config; p; p = p->next) {
7426 * check for pcxr types.
7428 if (p->u.board.type > EPCFE)
7429 count += p->u.board.nport;
7432 count += p->u.conc.nport;
7435 count += p->u.module.nport;
7442 static char *dgap_create_config_string(struct board_t *bd, char *string)
7454 for (p = bd->bd_config; p; p = p->next) {
7460 *ptr = p->u.line.speed;
7465 * Because the EPC/con concentrators can have EM modules
7466 * hanging off of them, we have to walk ahead in the
7467 * list and keep adding the number of ports on each EM
7468 * to the config. UGH!
7470 speed = p->u.conc.speed;
7472 if (q && (q->type == MNODE)) {
7473 *ptr = (p->u.conc.nport + 0x80);
7476 while (q->next && (q->next->type) == MNODE) {
7477 *ptr = (q->u.module.nport + 0x80);
7482 *ptr = q->u.module.nport;
7485 *ptr = p->u.conc.nport;