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_ATOMIC);
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 + ((ch->ch_bs->tx_seg) << 4);
1435 ch->ch_raddr = vaddr + ((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 kfree(brd->serial_driver->ttys);
1507 brd->serial_driver->ttys = NULL;
1508 put_tty_driver(brd->serial_driver);
1509 kfree(brd->serial_ports);
1510 brd->dgap_major_serial_registered = FALSE;
1513 if (brd->dgap_major_transparent_print_registered) {
1514 dgap_boards_by_major[brd->print_driver->major] = NULL;
1515 brd->dgap_transparent_print_major = 0;
1516 for (i = 0; i < brd->nasync; i++) {
1517 tty_port_destroy(&brd->printer_ports[i]);
1518 dev = brd->channels[i]->ch_pun.un_sysfs;
1519 dgap_remove_tty_sysfs(dev);
1520 tty_unregister_device(brd->print_driver, i);
1522 tty_unregister_driver(brd->print_driver);
1523 kfree(brd->print_driver->ttys);
1524 brd->print_driver->ttys = NULL;
1525 put_tty_driver(brd->print_driver);
1526 kfree(brd->printer_ports);
1527 brd->dgap_major_transparent_print_registered = FALSE;
1531 /*=======================================================================
1533 * dgap_input - Process received data.
1535 * ch - Pointer to channel structure.
1537 *=======================================================================*/
1539 static void dgap_input(struct channel_t *ch)
1542 struct bs_t __iomem *bs;
1543 struct tty_struct *tp;
1544 struct tty_ldisc *ld;
1558 if (!ch || ch->magic != DGAP_CHANNEL_MAGIC)
1561 tp = ch->ch_tun.un_tty;
1568 if (!bd || bd->magic != DGAP_BOARD_MAGIC)
1571 spin_lock_irqsave(&bd->bd_lock, lock_flags);
1572 spin_lock_irqsave(&ch->ch_lock, lock_flags2);
1575 * Figure the number of characters in the buffer.
1576 * Exit immediately if none.
1579 rmask = ch->ch_rsize - 1;
1581 head = readw(&(bs->rx_head));
1583 tail = readw(&(bs->rx_tail));
1586 data_len = (head - tail) & rmask;
1588 if (data_len == 0) {
1589 writeb(1, &(bs->idata));
1590 spin_unlock_irqrestore(&ch->ch_lock, lock_flags2);
1591 spin_unlock_irqrestore(&bd->bd_lock, lock_flags);
1596 * If the device is not open, or CREAD is off, flush
1597 * input data and return immediately.
1599 if ((bd->state != BOARD_READY) || !tp ||
1600 (tp->magic != TTY_MAGIC) ||
1601 !(ch->ch_tun.un_flags & UN_ISOPEN) ||
1602 !(tp->termios.c_cflag & CREAD) ||
1603 (ch->ch_tun.un_flags & UN_CLOSING)) {
1605 writew(head, &(bs->rx_tail));
1606 writeb(1, &(bs->idata));
1607 spin_unlock_irqrestore(&ch->ch_lock, lock_flags2);
1608 spin_unlock_irqrestore(&bd->bd_lock, lock_flags);
1613 * If we are throttled, simply don't read any data.
1615 if (ch->ch_flags & CH_RXBLOCK) {
1616 writeb(1, &(bs->idata));
1617 spin_unlock_irqrestore(&ch->ch_lock, lock_flags2);
1618 spin_unlock_irqrestore(&bd->bd_lock, lock_flags);
1625 tmpchar = readb(&(bs->orun));
1627 ch->ch_err_overrun++;
1628 writeb(0, &(bs->orun));
1631 /* Decide how much data we can send into the tty layer */
1632 flip_len = TTY_FLIPBUF_SIZE;
1634 /* Chop down the length, if needed */
1635 len = min(data_len, flip_len);
1636 len = min(len, (N_TTY_BUF_SIZE - 1));
1638 ld = tty_ldisc_ref(tp);
1640 #ifdef TTY_DONT_FLIP
1642 * If the DONT_FLIP flag is on, don't flush our buffer, and act
1643 * like the ld doesn't have any space to put the data right now.
1645 if (test_bit(TTY_DONT_FLIP, &tp->flags))
1650 * If we were unable to get a reference to the ld,
1651 * don't flush our buffer, and act like the ld doesn't
1652 * have any space to put the data right now.
1658 * If ld doesn't have a pointer to a receive_buf function,
1659 * flush the data, then act like the ld doesn't have any
1660 * space to put the data right now.
1662 if (!ld->ops->receive_buf) {
1663 writew(head, &(bs->rx_tail));
1669 writeb(1, &(bs->idata));
1670 spin_unlock_irqrestore(&ch->ch_lock, lock_flags2);
1671 spin_unlock_irqrestore(&bd->bd_lock, lock_flags);
1673 tty_ldisc_deref(ld);
1677 buf = ch->ch_bd->flipbuf;
1681 * n now contains the most amount of data we can copy,
1682 * bounded either by our buffer size or the amount
1683 * of data the card actually has pending...
1687 s = ((head >= tail) ? head : ch->ch_rsize) - tail;
1693 memcpy_fromio(buf, ch->ch_raddr + tail, s);
1699 /* Flip queue if needed */
1703 writew(tail, &(bs->rx_tail));
1704 writeb(1, &(bs->idata));
1705 ch->ch_rxcount += len;
1708 * If we are completely raw, we don't need to go through a lot
1709 * of the tty layers that exist.
1710 * In this case, we take the shortest and fastest route we
1711 * can to relay the data to the user.
1713 * On the other hand, if we are not raw, we need to go through
1714 * the tty layer, which has its API more well defined.
1716 if (I_PARMRK(tp) || I_BRKINT(tp) || I_INPCK(tp)) {
1717 dgap_parity_scan(ch, ch->ch_bd->flipbuf,
1718 ch->ch_bd->flipflagbuf, &len);
1720 len = tty_buffer_request_room(tp->port, len);
1721 tty_insert_flip_string_flags(tp->port, ch->ch_bd->flipbuf,
1722 ch->ch_bd->flipflagbuf, len);
1724 len = tty_buffer_request_room(tp->port, len);
1725 tty_insert_flip_string(tp->port, ch->ch_bd->flipbuf, len);
1728 spin_unlock_irqrestore(&ch->ch_lock, lock_flags2);
1729 spin_unlock_irqrestore(&bd->bd_lock, lock_flags);
1731 /* Tell the tty layer its okay to "eat" the data now */
1732 tty_flip_buffer_push(tp->port);
1735 tty_ldisc_deref(ld);
1739 /************************************************************************
1740 * Determines when CARRIER changes state and takes appropriate
1742 ************************************************************************/
1743 static void dgap_carrier(struct channel_t *ch)
1747 int virt_carrier = 0;
1748 int phys_carrier = 0;
1750 if (!ch || ch->magic != DGAP_CHANNEL_MAGIC)
1755 if (!bd || bd->magic != DGAP_BOARD_MAGIC)
1758 /* Make sure altpin is always set correctly */
1759 if (ch->ch_digi.digi_flags & DIGI_ALTPIN) {
1763 ch->ch_dsr = DM_DSR;
1767 if (ch->ch_mistat & D_CD(ch))
1770 if (ch->ch_digi.digi_flags & DIGI_FORCEDCD)
1773 if (ch->ch_c_cflag & CLOCAL)
1777 * Test for a VIRTUAL carrier transition to HIGH.
1779 if (((ch->ch_flags & CH_FCAR) == 0) && (virt_carrier == 1)) {
1782 * When carrier rises, wake any threads waiting
1783 * for carrier in the open routine.
1786 if (waitqueue_active(&(ch->ch_flags_wait)))
1787 wake_up_interruptible(&ch->ch_flags_wait);
1791 * Test for a PHYSICAL carrier transition to HIGH.
1793 if (((ch->ch_flags & CH_CD) == 0) && (phys_carrier == 1)) {
1796 * When carrier rises, wake any threads waiting
1797 * for carrier in the open routine.
1800 if (waitqueue_active(&(ch->ch_flags_wait)))
1801 wake_up_interruptible(&ch->ch_flags_wait);
1805 * Test for a PHYSICAL transition to low, so long as we aren't
1806 * currently ignoring physical transitions (which is what "virtual
1807 * carrier" indicates).
1809 * The transition of the virtual carrier to low really doesn't
1810 * matter... it really only means "ignore carrier state", not
1811 * "make pretend that carrier is there".
1813 if ((virt_carrier == 0) &&
1814 ((ch->ch_flags & CH_CD) != 0) &&
1815 (phys_carrier == 0)) {
1818 * When carrier drops:
1820 * Drop carrier on all open units.
1822 * Flush queues, waking up any task waiting in the
1825 * Send a hangup to the control terminal.
1827 * Enable all select calls.
1829 if (waitqueue_active(&(ch->ch_flags_wait)))
1830 wake_up_interruptible(&ch->ch_flags_wait);
1832 if (ch->ch_tun.un_open_count > 0)
1833 tty_hangup(ch->ch_tun.un_tty);
1835 if (ch->ch_pun.un_open_count > 0)
1836 tty_hangup(ch->ch_pun.un_tty);
1840 * Make sure that our cached values reflect the current reality.
1842 if (virt_carrier == 1)
1843 ch->ch_flags |= CH_FCAR;
1845 ch->ch_flags &= ~CH_FCAR;
1847 if (phys_carrier == 1)
1848 ch->ch_flags |= CH_CD;
1850 ch->ch_flags &= ~CH_CD;
1853 /************************************************************************
1855 * TTY Entry points and helper functions
1857 ************************************************************************/
1863 static int dgap_tty_open(struct tty_struct *tty, struct file *file)
1865 struct board_t *brd;
1866 struct channel_t *ch;
1868 struct bs_t __iomem *bs;
1876 major = MAJOR(tty_devnum(tty));
1877 minor = MINOR(tty_devnum(tty));
1882 /* Get board pointer from our array of majors we have allocated */
1883 brd = dgap_boards_by_major[major];
1888 * If board is not yet up to a state of READY, go to
1889 * sleep waiting for it to happen or they cancel the open.
1891 rc = wait_event_interruptible(brd->state_wait,
1892 (brd->state & BOARD_READY));
1897 spin_lock_irqsave(&brd->bd_lock, lock_flags);
1899 /* The wait above should guarantee this cannot happen */
1900 if (brd->state != BOARD_READY) {
1901 spin_unlock_irqrestore(&brd->bd_lock, lock_flags);
1905 /* If opened device is greater than our number of ports, bail. */
1906 if (MINOR(tty_devnum(tty)) > brd->nasync) {
1907 spin_unlock_irqrestore(&brd->bd_lock, lock_flags);
1911 ch = brd->channels[minor];
1913 spin_unlock_irqrestore(&brd->bd_lock, lock_flags);
1917 /* Grab channel lock */
1918 spin_lock_irqsave(&ch->ch_lock, lock_flags2);
1920 /* Figure out our type */
1921 if (major == brd->dgap_serial_major) {
1922 un = &brd->channels[minor]->ch_tun;
1923 un->un_type = DGAP_SERIAL;
1924 } else if (major == brd->dgap_transparent_print_major) {
1925 un = &brd->channels[minor]->ch_pun;
1926 un->un_type = DGAP_PRINT;
1928 spin_unlock_irqrestore(&ch->ch_lock, lock_flags2);
1929 spin_unlock_irqrestore(&brd->bd_lock, lock_flags);
1933 /* Store our unit into driver_data, so we always have it available. */
1934 tty->driver_data = un;
1937 * Error if channel info pointer is NULL.
1941 spin_unlock_irqrestore(&ch->ch_lock, lock_flags2);
1942 spin_unlock_irqrestore(&brd->bd_lock, lock_flags);
1949 if (!(un->un_flags & UN_ISOPEN)) {
1950 /* Store important variables. */
1953 /* Maybe do something here to the TTY struct as well? */
1957 * Initialize if neither terminal or printer is open.
1959 if (!((ch->ch_tun.un_flags | ch->ch_pun.un_flags) & UN_ISOPEN)) {
1965 * Flush input queue.
1967 head = readw(&(bs->rx_head));
1968 writew(head, &(bs->rx_tail));
1971 ch->pscan_state = 0;
1972 ch->pscan_savechar = 0;
1974 ch->ch_c_cflag = tty->termios.c_cflag;
1975 ch->ch_c_iflag = tty->termios.c_iflag;
1976 ch->ch_c_oflag = tty->termios.c_oflag;
1977 ch->ch_c_lflag = tty->termios.c_lflag;
1978 ch->ch_startc = tty->termios.c_cc[VSTART];
1979 ch->ch_stopc = tty->termios.c_cc[VSTOP];
1981 /* TODO: flush our TTY struct here? */
1986 * Run param in case we changed anything
1991 * follow protocol for opening port
1994 spin_unlock_irqrestore(&ch->ch_lock, lock_flags2);
1995 spin_unlock_irqrestore(&brd->bd_lock, lock_flags);
1997 rc = dgap_block_til_ready(tty, file, ch);
2002 /* No going back now, increment our unit and channel counters */
2003 spin_lock_irqsave(&ch->ch_lock, lock_flags);
2004 ch->ch_open_count++;
2005 un->un_open_count++;
2006 un->un_flags |= (UN_ISOPEN);
2007 spin_unlock_irqrestore(&ch->ch_lock, lock_flags);
2013 * dgap_block_til_ready()
2015 * Wait for DCD, if needed.
2017 static int dgap_block_til_ready(struct tty_struct *tty, struct file *file,
2018 struct channel_t *ch)
2024 int sleep_on_un_flags;
2026 if (!tty || tty->magic != TTY_MAGIC || !file || !ch ||
2027 ch->magic != DGAP_CHANNEL_MAGIC)
2030 un = tty->driver_data;
2031 if (!un || un->magic != DGAP_UNIT_MAGIC)
2034 spin_lock_irqsave(&ch->ch_lock, lock_flags);
2041 sleep_on_un_flags = 0;
2044 * If board has failed somehow during our sleep,
2047 if (ch->ch_bd->state == BOARD_FAILED) {
2052 /* If tty was hung up, break out of loop and set error. */
2053 if (tty_hung_up_p(file)) {
2059 * If either unit is in the middle of the fragile part of close,
2060 * we just cannot touch the channel safely.
2061 * Go back to sleep, knowing that when the channel can be
2062 * touched safely, the close routine will signal the
2063 * ch_wait_flags to wake us back up.
2065 if (!((ch->ch_tun.un_flags | ch->ch_pun.un_flags) &
2069 * Our conditions to leave cleanly and happily:
2070 * 1) NONBLOCKING on the tty is set.
2072 * 3) DCD (fake or real) is active.
2075 if (file->f_flags & O_NONBLOCK)
2078 if (tty->flags & (1 << TTY_IO_ERROR))
2081 if (ch->ch_flags & CH_CD)
2084 if (ch->ch_flags & CH_FCAR)
2087 sleep_on_un_flags = 1;
2091 * If there is a signal pending, the user probably
2092 * interrupted (ctrl-c) us.
2093 * Leave loop with error set.
2095 if (signal_pending(current)) {
2096 retval = -ERESTARTSYS;
2101 * Store the flags before we let go of channel lock
2103 if (sleep_on_un_flags)
2104 old_flags = ch->ch_tun.un_flags | ch->ch_pun.un_flags;
2106 old_flags = ch->ch_flags;
2109 * Let go of channel lock before calling schedule.
2110 * Our poller will get any FEP events and wake us up when DCD
2111 * eventually goes active.
2114 spin_unlock_irqrestore(&ch->ch_lock, lock_flags);
2117 * Wait for something in the flags to change
2118 * from the current value.
2120 if (sleep_on_un_flags) {
2121 retval = wait_event_interruptible(un->un_flags_wait,
2122 (old_flags != (ch->ch_tun.un_flags |
2123 ch->ch_pun.un_flags)));
2125 retval = wait_event_interruptible(ch->ch_flags_wait,
2126 (old_flags != ch->ch_flags));
2130 * We got woken up for some reason.
2131 * Before looping around, grab our channel lock.
2133 spin_lock_irqsave(&ch->ch_lock, lock_flags);
2138 spin_unlock_irqrestore(&ch->ch_lock, lock_flags);
2149 * Hangup the port. Like a close, but don't wait for output to drain.
2151 static void dgap_tty_hangup(struct tty_struct *tty)
2154 struct channel_t *ch;
2157 if (!tty || tty->magic != TTY_MAGIC)
2160 un = tty->driver_data;
2161 if (!un || un->magic != DGAP_UNIT_MAGIC)
2165 if (!ch || ch->magic != DGAP_CHANNEL_MAGIC)
2169 if (!bd || bd->magic != DGAP_BOARD_MAGIC)
2172 /* flush the transmit queues */
2173 dgap_tty_flush_buffer(tty);
2180 static void dgap_tty_close(struct tty_struct *tty, struct file *file)
2182 struct ktermios *ts;
2184 struct channel_t *ch;
2188 if (!tty || tty->magic != TTY_MAGIC)
2191 un = tty->driver_data;
2192 if (!un || un->magic != DGAP_UNIT_MAGIC)
2196 if (!ch || ch->magic != DGAP_CHANNEL_MAGIC)
2200 if (!bd || bd->magic != DGAP_BOARD_MAGIC)
2205 spin_lock_irqsave(&ch->ch_lock, lock_flags);
2208 * Determine if this is the last close or not - and if we agree about
2209 * which type of close it is with the Line Discipline
2211 if ((tty->count == 1) && (un->un_open_count != 1)) {
2213 * Uh, oh. tty->count is 1, which means that the tty
2214 * structure will be freed. un_open_count should always
2215 * be one in these conditions. If it's greater than
2216 * one, we've got real problems, since it means the
2217 * serial port won't be shutdown.
2219 un->un_open_count = 1;
2222 if (--un->un_open_count < 0)
2223 un->un_open_count = 0;
2225 ch->ch_open_count--;
2227 if (ch->ch_open_count && un->un_open_count) {
2228 spin_unlock_irqrestore(&ch->ch_lock, lock_flags);
2232 /* OK, its the last close on the unit */
2234 un->un_flags |= UN_CLOSING;
2239 * Only officially close channel if count is 0 and
2240 * DIGI_PRINTER bit is not set.
2242 if ((ch->ch_open_count == 0) &&
2243 !(ch->ch_digi.digi_flags & DIGI_PRINTER)) {
2245 ch->ch_flags &= ~(CH_RXBLOCK);
2247 spin_unlock_irqrestore(&ch->ch_lock, lock_flags);
2249 /* wait for output to drain */
2250 /* This will also return if we take an interrupt */
2252 dgap_wait_for_drain(tty);
2254 dgap_tty_flush_buffer(tty);
2255 tty_ldisc_flush(tty);
2257 spin_lock_irqsave(&ch->ch_lock, lock_flags);
2262 * If we have HUPCL set, lower DTR and RTS
2264 if (ch->ch_c_cflag & HUPCL) {
2265 ch->ch_mostat &= ~(D_RTS(ch)|D_DTR(ch));
2266 dgap_cmdb(ch, SMODEM, 0, D_DTR(ch)|D_RTS(ch), 0);
2269 * Go to sleep to ensure RTS/DTR
2270 * have been dropped for modems to see it.
2272 if (ch->ch_close_delay) {
2273 spin_unlock_irqrestore(&ch->ch_lock,
2275 dgap_ms_sleep(ch->ch_close_delay);
2276 spin_lock_irqsave(&ch->ch_lock, lock_flags);
2280 ch->pscan_state = 0;
2281 ch->pscan_savechar = 0;
2282 ch->ch_baud_info = 0;
2287 * turn off print device when closing print device.
2289 if ((un->un_type == DGAP_PRINT) && (ch->ch_flags & CH_PRON)) {
2290 dgap_wmove(ch, ch->ch_digi.digi_offstr,
2291 (int) ch->ch_digi.digi_offlen);
2292 ch->ch_flags &= ~CH_PRON;
2296 un->un_flags &= ~(UN_ISOPEN | UN_CLOSING);
2297 tty->driver_data = NULL;
2299 wake_up_interruptible(&ch->ch_flags_wait);
2300 wake_up_interruptible(&un->un_flags_wait);
2302 spin_unlock_irqrestore(&ch->ch_lock, lock_flags);
2306 * dgap_tty_chars_in_buffer()
2308 * Return number of characters that have not been transmitted yet.
2310 * This routine is used by the line discipline to determine if there
2311 * is data waiting to be transmitted/drained/flushed or not.
2313 static int dgap_tty_chars_in_buffer(struct tty_struct *tty)
2316 struct channel_t *ch;
2318 struct bs_t __iomem *bs;
2321 u16 thead, ttail, tmask, chead, ctail;
2322 ulong lock_flags = 0;
2323 ulong lock_flags2 = 0;
2328 un = tty->driver_data;
2329 if (!un || un->magic != DGAP_UNIT_MAGIC)
2333 if (!ch || ch->magic != DGAP_CHANNEL_MAGIC)
2337 if (!bd || bd->magic != DGAP_BOARD_MAGIC)
2344 spin_lock_irqsave(&bd->bd_lock, lock_flags);
2345 spin_lock_irqsave(&ch->ch_lock, lock_flags2);
2347 tmask = (ch->ch_tsize - 1);
2349 /* Get Transmit queue pointers */
2350 thead = readw(&(bs->tx_head)) & tmask;
2351 ttail = readw(&(bs->tx_tail)) & tmask;
2353 /* Get tbusy flag */
2354 tbusy = readb(&(bs->tbusy));
2356 /* Get Command queue pointers */
2357 chead = readw(&(ch->ch_cm->cm_head));
2358 ctail = readw(&(ch->ch_cm->cm_tail));
2360 spin_unlock_irqrestore(&ch->ch_lock, lock_flags2);
2361 spin_unlock_irqrestore(&bd->bd_lock, lock_flags);
2364 * The only way we know for sure if there is no pending
2365 * data left to be transferred, is if:
2366 * 1) Transmit head and tail are equal (empty).
2367 * 2) Command queue head and tail are equal (empty).
2368 * 3) The "TBUSY" flag is 0. (Transmitter not busy).
2371 if ((ttail == thead) && (tbusy == 0) && (chead == ctail)) {
2375 chars = thead - ttail;
2377 chars = thead - ttail + ch->ch_tsize;
2379 * Fudge factor here.
2380 * If chars is zero, we know that the command queue had
2381 * something in it or tbusy was set. Because we cannot
2382 * be sure if there is still some data to be transmitted,
2383 * lets lie, and tell ld we have 1 byte left.
2387 * If TBUSY is still set, and our tx buffers are empty,
2388 * force the firmware to send me another wakeup after
2389 * TBUSY has been cleared.
2392 spin_lock_irqsave(&ch->ch_lock, lock_flags);
2393 un->un_flags |= UN_EMPTY;
2394 writeb(1, &(bs->iempty));
2395 spin_unlock_irqrestore(&ch->ch_lock,
2405 static int dgap_wait_for_drain(struct tty_struct *tty)
2407 struct channel_t *ch;
2409 struct bs_t __iomem *bs;
2412 ulong lock_flags = 0;
2414 if (!tty || tty->magic != TTY_MAGIC)
2417 un = tty->driver_data;
2418 if (!un || un->magic != DGAP_UNIT_MAGIC)
2422 if (!ch || ch->magic != DGAP_CHANNEL_MAGIC)
2429 /* Loop until data is drained */
2430 while (count != 0) {
2432 count = dgap_tty_chars_in_buffer(tty);
2437 /* Set flag waiting for drain */
2438 spin_lock_irqsave(&ch->ch_lock, lock_flags);
2439 un->un_flags |= UN_EMPTY;
2440 writeb(1, &(bs->iempty));
2441 spin_unlock_irqrestore(&ch->ch_lock, lock_flags);
2443 /* Go to sleep till we get woken up */
2444 ret = wait_event_interruptible(un->un_flags_wait,
2445 ((un->un_flags & UN_EMPTY) == 0));
2446 /* If ret is non-zero, user ctrl-c'ed us */
2451 spin_lock_irqsave(&ch->ch_lock, lock_flags);
2452 un->un_flags &= ~(UN_EMPTY);
2453 spin_unlock_irqrestore(&ch->ch_lock, lock_flags);
2461 * Reduces bytes_available to the max number of characters
2462 * that can be sent currently given the maxcps value, and
2463 * returns the new bytes_available. This only affects printer
2466 static int dgap_maxcps_room(struct tty_struct *tty, int bytes_available)
2468 struct channel_t *ch;
2472 return bytes_available;
2474 un = tty->driver_data;
2475 if (!un || un->magic != DGAP_UNIT_MAGIC)
2476 return bytes_available;
2479 if (!ch || ch->magic != DGAP_CHANNEL_MAGIC)
2480 return bytes_available;
2483 * If its not the Transparent print device, return
2484 * the full data amount.
2486 if (un->un_type != DGAP_PRINT)
2487 return bytes_available;
2489 if (ch->ch_digi.digi_maxcps > 0 && ch->ch_digi.digi_bufsize > 0) {
2491 unsigned long current_time = jiffies;
2492 unsigned long buffer_time = current_time +
2493 (HZ * ch->ch_digi.digi_bufsize) /
2494 ch->ch_digi.digi_maxcps;
2496 if (ch->ch_cpstime < current_time) {
2497 /* buffer is empty */
2498 ch->ch_cpstime = current_time; /* reset ch_cpstime */
2499 cps_limit = ch->ch_digi.digi_bufsize;
2500 } else if (ch->ch_cpstime < buffer_time) {
2501 /* still room in the buffer */
2502 cps_limit = ((buffer_time - ch->ch_cpstime) *
2503 ch->ch_digi.digi_maxcps) / HZ;
2505 /* no room in the buffer */
2509 bytes_available = min(cps_limit, bytes_available);
2512 return bytes_available;
2515 static inline void dgap_set_firmware_event(struct un_t *un, unsigned int event)
2517 struct channel_t *ch;
2518 struct bs_t __iomem *bs;
2520 if (!un || un->magic != DGAP_UNIT_MAGIC)
2523 if (!ch || ch->magic != DGAP_CHANNEL_MAGIC)
2529 if ((event & UN_LOW) != 0) {
2530 if ((un->un_flags & UN_LOW) == 0) {
2531 un->un_flags |= UN_LOW;
2532 writeb(1, &(bs->ilow));
2535 if ((event & UN_LOW) != 0) {
2536 if ((un->un_flags & UN_EMPTY) == 0) {
2537 un->un_flags |= UN_EMPTY;
2538 writeb(1, &(bs->iempty));
2544 * dgap_tty_write_room()
2546 * Return space available in Tx buffer
2548 static int dgap_tty_write_room(struct tty_struct *tty)
2550 struct channel_t *ch;
2552 struct bs_t __iomem *bs;
2553 u16 head, tail, tmask;
2555 ulong lock_flags = 0;
2560 un = tty->driver_data;
2561 if (!un || un->magic != DGAP_UNIT_MAGIC)
2565 if (!ch || ch->magic != DGAP_CHANNEL_MAGIC)
2572 spin_lock_irqsave(&ch->ch_lock, lock_flags);
2574 tmask = ch->ch_tsize - 1;
2575 head = readw(&(bs->tx_head)) & tmask;
2576 tail = readw(&(bs->tx_tail)) & tmask;
2578 ret = tail - head - 1;
2580 ret += ch->ch_tsize;
2582 /* Limit printer to maxcps */
2583 ret = dgap_maxcps_room(tty, ret);
2586 * If we are printer device, leave space for
2587 * possibly both the on and off strings.
2589 if (un->un_type == DGAP_PRINT) {
2590 if (!(ch->ch_flags & CH_PRON))
2591 ret -= ch->ch_digi.digi_onlen;
2592 ret -= ch->ch_digi.digi_offlen;
2594 if (ch->ch_flags & CH_PRON)
2595 ret -= ch->ch_digi.digi_offlen;
2602 * Schedule FEP to wake us up if needed.
2604 * TODO: This might be overkill...
2605 * Do we really need to schedule callbacks from the FEP
2606 * in every case? Can we get smarter based on ret?
2608 dgap_set_firmware_event(un, UN_LOW | UN_EMPTY);
2609 spin_unlock_irqrestore(&ch->ch_lock, lock_flags);
2615 * dgap_tty_put_char()
2617 * Put a character into ch->ch_buf
2619 * - used by the line discipline for OPOST processing
2621 static int dgap_tty_put_char(struct tty_struct *tty, unsigned char c)
2624 * Simply call tty_write.
2626 dgap_tty_write(tty, &c, 1);
2633 * Take data from the user or kernel and send it out to the FEP.
2634 * In here exists all the Transparent Print magic as well.
2636 static int dgap_tty_write(struct tty_struct *tty, const unsigned char *buf,
2639 struct channel_t *ch;
2641 struct bs_t __iomem *bs;
2642 char __iomem *vaddr;
2643 u16 head, tail, tmask, remain;
2651 un = tty->driver_data;
2652 if (!un || un->magic != DGAP_UNIT_MAGIC)
2656 if (!ch || ch->magic != DGAP_CHANNEL_MAGIC)
2667 * Store original amount of characters passed in.
2668 * This helps to figure out if we should ask the FEP
2669 * to send us an event when it has more space available.
2673 spin_lock_irqsave(&ch->ch_lock, lock_flags);
2675 /* Get our space available for the channel from the board */
2676 tmask = ch->ch_tsize - 1;
2677 head = readw(&(bs->tx_head)) & tmask;
2678 tail = readw(&(bs->tx_tail)) & tmask;
2680 bufcount = tail - head - 1;
2682 bufcount += ch->ch_tsize;
2685 * Limit printer output to maxcps overall, with bursts allowed
2686 * up to bufsize characters.
2688 bufcount = dgap_maxcps_room(tty, bufcount);
2691 * Take minimum of what the user wants to send, and the
2692 * space available in the FEP buffer.
2694 count = min(count, bufcount);
2697 * Bail if no space left.
2700 dgap_set_firmware_event(un, UN_LOW | UN_EMPTY);
2701 spin_unlock_irqrestore(&ch->ch_lock, lock_flags);
2706 * Output the printer ON string, if we are in terminal mode, but
2707 * need to be in printer mode.
2709 if ((un->un_type == DGAP_PRINT) && !(ch->ch_flags & CH_PRON)) {
2710 dgap_wmove(ch, ch->ch_digi.digi_onstr,
2711 (int) ch->ch_digi.digi_onlen);
2712 head = readw(&(bs->tx_head)) & tmask;
2713 ch->ch_flags |= CH_PRON;
2717 * On the other hand, output the printer OFF string, if we are
2718 * currently in printer mode, but need to output to the terminal.
2720 if ((un->un_type != DGAP_PRINT) && (ch->ch_flags & CH_PRON)) {
2721 dgap_wmove(ch, ch->ch_digi.digi_offstr,
2722 (int) ch->ch_digi.digi_offlen);
2723 head = readw(&(bs->tx_head)) & tmask;
2724 ch->ch_flags &= ~CH_PRON;
2730 * If the write wraps over the top of the circular buffer,
2731 * move the portion up to the wrap point, and reset the
2732 * pointers to the bottom.
2734 remain = ch->ch_tstart + ch->ch_tsize - head;
2738 vaddr = ch->ch_taddr + head;
2740 memcpy_toio(vaddr, (u8 *) buf, remain);
2742 head = ch->ch_tstart;
2749 * Move rest of data.
2751 vaddr = ch->ch_taddr + head;
2754 memcpy_toio(vaddr, (u8 *) buf, remain);
2760 ch->ch_txcount += count;
2762 writew(head, &(bs->tx_head));
2765 dgap_set_firmware_event(un, UN_LOW | UN_EMPTY);
2768 * If this is the print device, and the
2769 * printer is still on, we need to turn it
2770 * off before going idle. If the buffer is
2771 * non-empty, wait until it goes empty.
2772 * Otherwise turn it off right now.
2774 if ((un->un_type == DGAP_PRINT) && (ch->ch_flags & CH_PRON)) {
2775 tail = readw(&(bs->tx_tail)) & tmask;
2778 un->un_flags |= UN_EMPTY;
2779 writeb(1, &(bs->iempty));
2781 dgap_wmove(ch, ch->ch_digi.digi_offstr,
2782 (int) ch->ch_digi.digi_offlen);
2783 head = readw(&(bs->tx_head)) & tmask;
2784 ch->ch_flags &= ~CH_PRON;
2788 /* Update printer buffer empty time. */
2789 if ((un->un_type == DGAP_PRINT) && (ch->ch_digi.digi_maxcps > 0)
2790 && (ch->ch_digi.digi_bufsize > 0)) {
2791 ch->ch_cpstime += (HZ * count) / ch->ch_digi.digi_maxcps;
2794 spin_unlock_irqrestore(&ch->ch_lock, lock_flags);
2800 * Return modem signals to ld.
2802 static int dgap_tty_tiocmget(struct tty_struct *tty)
2804 struct channel_t *ch;
2810 if (!tty || tty->magic != TTY_MAGIC)
2813 un = tty->driver_data;
2814 if (!un || un->magic != DGAP_UNIT_MAGIC)
2818 if (!ch || ch->magic != DGAP_CHANNEL_MAGIC)
2821 spin_lock_irqsave(&ch->ch_lock, lock_flags);
2823 mstat = readb(&(ch->ch_bs->m_stat));
2824 /* Append any outbound signals that might be pending... */
2825 mstat |= ch->ch_mostat;
2827 spin_unlock_irqrestore(&ch->ch_lock, lock_flags);
2831 if (mstat & D_DTR(ch))
2832 result |= TIOCM_DTR;
2833 if (mstat & D_RTS(ch))
2834 result |= TIOCM_RTS;
2835 if (mstat & D_CTS(ch))
2836 result |= TIOCM_CTS;
2837 if (mstat & D_DSR(ch))
2838 result |= TIOCM_DSR;
2839 if (mstat & D_RI(ch))
2841 if (mstat & D_CD(ch))
2848 * dgap_tty_tiocmset()
2850 * Set modem signals, called by ld.
2852 static int dgap_tty_tiocmset(struct tty_struct *tty,
2853 unsigned int set, unsigned int clear)
2856 struct channel_t *ch;
2861 if (!tty || tty->magic != TTY_MAGIC)
2864 un = tty->driver_data;
2865 if (!un || un->magic != DGAP_UNIT_MAGIC)
2869 if (!ch || ch->magic != DGAP_CHANNEL_MAGIC)
2873 if (!bd || bd->magic != DGAP_BOARD_MAGIC)
2876 spin_lock_irqsave(&bd->bd_lock, lock_flags);
2877 spin_lock_irqsave(&ch->ch_lock, lock_flags2);
2879 if (set & TIOCM_RTS) {
2880 ch->ch_mforce |= D_RTS(ch);
2881 ch->ch_mval |= D_RTS(ch);
2884 if (set & TIOCM_DTR) {
2885 ch->ch_mforce |= D_DTR(ch);
2886 ch->ch_mval |= D_DTR(ch);
2889 if (clear & TIOCM_RTS) {
2890 ch->ch_mforce |= D_RTS(ch);
2891 ch->ch_mval &= ~(D_RTS(ch));
2894 if (clear & TIOCM_DTR) {
2895 ch->ch_mforce |= D_DTR(ch);
2896 ch->ch_mval &= ~(D_DTR(ch));
2901 spin_unlock_irqrestore(&ch->ch_lock, lock_flags2);
2902 spin_unlock_irqrestore(&bd->bd_lock, lock_flags);
2908 * dgap_tty_send_break()
2910 * Send a Break, called by ld.
2912 static int dgap_tty_send_break(struct tty_struct *tty, int msec)
2915 struct channel_t *ch;
2920 if (!tty || tty->magic != TTY_MAGIC)
2923 un = tty->driver_data;
2924 if (!un || un->magic != DGAP_UNIT_MAGIC)
2928 if (!ch || ch->magic != DGAP_CHANNEL_MAGIC)
2932 if (!bd || bd->magic != DGAP_BOARD_MAGIC)
2947 spin_lock_irqsave(&bd->bd_lock, lock_flags);
2948 spin_lock_irqsave(&ch->ch_lock, lock_flags2);
2950 dgap_cmdw(ch, SBREAK, (u16) SBREAK_TIME, 0);
2952 dgap_cmdw(ch, SBREAK, (u16) msec, 0);
2954 spin_unlock_irqrestore(&ch->ch_lock, lock_flags2);
2955 spin_unlock_irqrestore(&bd->bd_lock, lock_flags);
2961 * dgap_tty_wait_until_sent()
2963 * wait until data has been transmitted, called by ld.
2965 static void dgap_tty_wait_until_sent(struct tty_struct *tty, int timeout)
2967 dgap_wait_for_drain(tty);
2973 * send a high priority character, called by ld.
2975 static void dgap_tty_send_xchar(struct tty_struct *tty, char c)
2978 struct channel_t *ch;
2983 if (!tty || tty->magic != TTY_MAGIC)
2986 un = tty->driver_data;
2987 if (!un || un->magic != DGAP_UNIT_MAGIC)
2991 if (!ch || ch->magic != DGAP_CHANNEL_MAGIC)
2995 if (!bd || bd->magic != DGAP_BOARD_MAGIC)
2998 spin_lock_irqsave(&bd->bd_lock, lock_flags);
2999 spin_lock_irqsave(&ch->ch_lock, lock_flags2);
3002 * This is technically what we should do.
3003 * However, the NIST tests specifically want
3004 * to see each XON or XOFF character that it
3005 * sends, so lets just send each character
3009 if (c == STOP_CHAR(tty))
3010 dgap_cmdw(ch, RPAUSE, 0, 0);
3011 else if (c == START_CHAR(tty))
3012 dgap_cmdw(ch, RRESUME, 0, 0);
3014 dgap_wmove(ch, &c, 1);
3016 dgap_wmove(ch, &c, 1);
3019 spin_unlock_irqrestore(&ch->ch_lock, lock_flags2);
3020 spin_unlock_irqrestore(&bd->bd_lock, lock_flags);
3026 * Return modem signals to ld.
3028 static int dgap_get_modem_info(struct channel_t *ch, unsigned int __user *value)
3035 if (!ch || ch->magic != DGAP_CHANNEL_MAGIC)
3038 spin_lock_irqsave(&ch->ch_lock, lock_flags);
3040 mstat = readb(&(ch->ch_bs->m_stat));
3041 /* Append any outbound signals that might be pending... */
3042 mstat |= ch->ch_mostat;
3044 spin_unlock_irqrestore(&ch->ch_lock, lock_flags);
3048 if (mstat & D_DTR(ch))
3049 result |= TIOCM_DTR;
3050 if (mstat & D_RTS(ch))
3051 result |= TIOCM_RTS;
3052 if (mstat & D_CTS(ch))
3053 result |= TIOCM_CTS;
3054 if (mstat & D_DSR(ch))
3055 result |= TIOCM_DSR;
3056 if (mstat & D_RI(ch))
3058 if (mstat & D_CD(ch))
3061 rc = put_user(result, value);
3067 * dgap_set_modem_info()
3069 * Set modem signals, called by ld.
3071 static int dgap_set_modem_info(struct tty_struct *tty, unsigned int command,
3072 unsigned int __user *value)
3075 struct channel_t *ch;
3082 if (!tty || tty->magic != TTY_MAGIC)
3085 un = tty->driver_data;
3086 if (!un || un->magic != DGAP_UNIT_MAGIC)
3090 if (!ch || ch->magic != DGAP_CHANNEL_MAGIC)
3094 if (!bd || bd->magic != DGAP_BOARD_MAGIC)
3097 ret = get_user(arg, value);
3103 if (arg & TIOCM_RTS) {
3104 ch->ch_mforce |= D_RTS(ch);
3105 ch->ch_mval |= D_RTS(ch);
3108 if (arg & TIOCM_DTR) {
3109 ch->ch_mforce |= D_DTR(ch);
3110 ch->ch_mval |= D_DTR(ch);
3116 if (arg & TIOCM_RTS) {
3117 ch->ch_mforce |= D_RTS(ch);
3118 ch->ch_mval &= ~(D_RTS(ch));
3121 if (arg & TIOCM_DTR) {
3122 ch->ch_mforce |= D_DTR(ch);
3123 ch->ch_mval &= ~(D_DTR(ch));
3129 ch->ch_mforce = D_DTR(ch)|D_RTS(ch);
3131 if (arg & TIOCM_RTS)
3132 ch->ch_mval |= D_RTS(ch);
3134 ch->ch_mval &= ~(D_RTS(ch));
3136 if (arg & TIOCM_DTR)
3137 ch->ch_mval |= (D_DTR(ch));
3139 ch->ch_mval &= ~(D_DTR(ch));
3147 spin_lock_irqsave(&bd->bd_lock, lock_flags);
3148 spin_lock_irqsave(&ch->ch_lock, lock_flags2);
3152 spin_unlock_irqrestore(&ch->ch_lock, lock_flags2);
3153 spin_unlock_irqrestore(&bd->bd_lock, lock_flags);
3159 * dgap_tty_digigeta()
3161 * Ioctl to get the information for ditty.
3166 static int dgap_tty_digigeta(struct tty_struct *tty,
3167 struct digi_t __user *retinfo)
3169 struct channel_t *ch;
3177 if (!tty || tty->magic != TTY_MAGIC)
3180 un = tty->driver_data;
3181 if (!un || un->magic != DGAP_UNIT_MAGIC)
3185 if (!ch || ch->magic != DGAP_CHANNEL_MAGIC)
3188 memset(&tmp, 0, sizeof(tmp));
3190 spin_lock_irqsave(&ch->ch_lock, lock_flags);
3191 memcpy(&tmp, &ch->ch_digi, sizeof(tmp));
3192 spin_unlock_irqrestore(&ch->ch_lock, lock_flags);
3194 if (copy_to_user(retinfo, &tmp, sizeof(*retinfo)))
3201 * dgap_tty_digiseta()
3203 * Ioctl to set the information for ditty.
3208 static int dgap_tty_digiseta(struct tty_struct *tty,
3209 struct digi_t __user *new_info)
3212 struct channel_t *ch;
3214 struct digi_t new_digi;
3215 ulong lock_flags = 0;
3216 unsigned long lock_flags2;
3218 if (!tty || tty->magic != TTY_MAGIC)
3221 un = tty->driver_data;
3222 if (!un || un->magic != DGAP_UNIT_MAGIC)
3226 if (!ch || ch->magic != DGAP_CHANNEL_MAGIC)
3230 if (!bd || bd->magic != DGAP_BOARD_MAGIC)
3233 if (copy_from_user(&new_digi, new_info, sizeof(struct digi_t)))
3236 spin_lock_irqsave(&bd->bd_lock, lock_flags);
3237 spin_lock_irqsave(&ch->ch_lock, lock_flags2);
3239 memcpy(&ch->ch_digi, &new_digi, sizeof(struct digi_t));
3241 if (ch->ch_digi.digi_maxcps < 1)
3242 ch->ch_digi.digi_maxcps = 1;
3244 if (ch->ch_digi.digi_maxcps > 10000)
3245 ch->ch_digi.digi_maxcps = 10000;
3247 if (ch->ch_digi.digi_bufsize < 10)
3248 ch->ch_digi.digi_bufsize = 10;
3250 if (ch->ch_digi.digi_maxchar < 1)
3251 ch->ch_digi.digi_maxchar = 1;
3253 if (ch->ch_digi.digi_maxchar > ch->ch_digi.digi_bufsize)
3254 ch->ch_digi.digi_maxchar = ch->ch_digi.digi_bufsize;
3256 if (ch->ch_digi.digi_onlen > DIGI_PLEN)
3257 ch->ch_digi.digi_onlen = DIGI_PLEN;
3259 if (ch->ch_digi.digi_offlen > DIGI_PLEN)
3260 ch->ch_digi.digi_offlen = DIGI_PLEN;
3264 spin_unlock_irqrestore(&ch->ch_lock, lock_flags2);
3265 spin_unlock_irqrestore(&bd->bd_lock, lock_flags);
3271 * dgap_tty_digigetedelay()
3273 * Ioctl to get the current edelay setting.
3278 static int dgap_tty_digigetedelay(struct tty_struct *tty, int __user *retinfo)
3280 struct channel_t *ch;
3288 if (!tty || tty->magic != TTY_MAGIC)
3291 un = tty->driver_data;
3292 if (!un || un->magic != DGAP_UNIT_MAGIC)
3296 if (!ch || ch->magic != DGAP_CHANNEL_MAGIC)
3299 memset(&tmp, 0, sizeof(tmp));
3301 spin_lock_irqsave(&ch->ch_lock, lock_flags);
3302 tmp = readw(&(ch->ch_bs->edelay));
3303 spin_unlock_irqrestore(&ch->ch_lock, lock_flags);
3305 if (copy_to_user(retinfo, &tmp, sizeof(*retinfo)))
3312 * dgap_tty_digisetedelay()
3314 * Ioctl to set the EDELAY setting
3317 static int dgap_tty_digisetedelay(struct tty_struct *tty, int __user *new_info)
3320 struct channel_t *ch;
3326 if (!tty || tty->magic != TTY_MAGIC)
3329 un = tty->driver_data;
3330 if (!un || un->magic != DGAP_UNIT_MAGIC)
3334 if (!ch || ch->magic != DGAP_CHANNEL_MAGIC)
3338 if (!bd || bd->magic != DGAP_BOARD_MAGIC)
3341 if (copy_from_user(&new_digi, new_info, sizeof(int)))
3344 spin_lock_irqsave(&bd->bd_lock, lock_flags);
3345 spin_lock_irqsave(&ch->ch_lock, lock_flags2);
3347 writew((u16) new_digi, &(ch->ch_bs->edelay));
3351 spin_unlock_irqrestore(&ch->ch_lock, lock_flags2);
3352 spin_unlock_irqrestore(&bd->bd_lock, lock_flags);
3358 * dgap_tty_digigetcustombaud()
3360 * Ioctl to get the current custom baud rate setting.
3362 static int dgap_tty_digigetcustombaud(struct tty_struct *tty,
3363 int __user *retinfo)
3365 struct channel_t *ch;
3373 if (!tty || tty->magic != TTY_MAGIC)
3376 un = tty->driver_data;
3377 if (!un || un->magic != DGAP_UNIT_MAGIC)
3381 if (!ch || ch->magic != DGAP_CHANNEL_MAGIC)
3384 memset(&tmp, 0, sizeof(tmp));
3386 spin_lock_irqsave(&ch->ch_lock, lock_flags);
3387 tmp = dgap_get_custom_baud(ch);
3388 spin_unlock_irqrestore(&ch->ch_lock, lock_flags);
3390 if (copy_to_user(retinfo, &tmp, sizeof(*retinfo)))
3397 * dgap_tty_digisetcustombaud()
3399 * Ioctl to set the custom baud rate setting
3401 static int dgap_tty_digisetcustombaud(struct tty_struct *tty,
3402 int __user *new_info)
3405 struct channel_t *ch;
3411 if (!tty || tty->magic != TTY_MAGIC)
3414 un = tty->driver_data;
3415 if (!un || un->magic != DGAP_UNIT_MAGIC)
3419 if (!ch || ch->magic != DGAP_CHANNEL_MAGIC)
3423 if (!bd || bd->magic != DGAP_BOARD_MAGIC)
3427 if (copy_from_user(&new_rate, new_info, sizeof(unsigned int)))
3430 if (bd->bd_flags & BD_FEP5PLUS) {
3432 spin_lock_irqsave(&bd->bd_lock, lock_flags);
3433 spin_lock_irqsave(&ch->ch_lock, lock_flags2);
3435 ch->ch_custom_speed = new_rate;
3439 spin_unlock_irqrestore(&ch->ch_lock, lock_flags2);
3440 spin_unlock_irqrestore(&bd->bd_lock, lock_flags);
3447 * dgap_set_termios()
3449 static void dgap_tty_set_termios(struct tty_struct *tty,
3450 struct ktermios *old_termios)
3453 struct channel_t *ch;
3455 unsigned long lock_flags;
3456 unsigned long lock_flags2;
3458 if (!tty || tty->magic != TTY_MAGIC)
3461 un = tty->driver_data;
3462 if (!un || un->magic != DGAP_UNIT_MAGIC)
3466 if (!ch || ch->magic != DGAP_CHANNEL_MAGIC)
3470 if (!bd || bd->magic != DGAP_BOARD_MAGIC)
3473 spin_lock_irqsave(&bd->bd_lock, lock_flags);
3474 spin_lock_irqsave(&ch->ch_lock, lock_flags2);
3476 ch->ch_c_cflag = tty->termios.c_cflag;
3477 ch->ch_c_iflag = tty->termios.c_iflag;
3478 ch->ch_c_oflag = tty->termios.c_oflag;
3479 ch->ch_c_lflag = tty->termios.c_lflag;
3480 ch->ch_startc = tty->termios.c_cc[VSTART];
3481 ch->ch_stopc = tty->termios.c_cc[VSTOP];
3486 spin_unlock_irqrestore(&ch->ch_lock, lock_flags2);
3487 spin_unlock_irqrestore(&bd->bd_lock, lock_flags);
3490 static void dgap_tty_throttle(struct tty_struct *tty)
3493 struct channel_t *ch;
3498 if (!tty || tty->magic != TTY_MAGIC)
3501 un = tty->driver_data;
3502 if (!un || un->magic != DGAP_UNIT_MAGIC)
3506 if (!ch || ch->magic != DGAP_CHANNEL_MAGIC)
3510 if (!bd || bd->magic != DGAP_BOARD_MAGIC)
3513 spin_lock_irqsave(&bd->bd_lock, lock_flags);
3514 spin_lock_irqsave(&ch->ch_lock, lock_flags2);
3516 ch->ch_flags |= (CH_RXBLOCK);
3518 dgap_cmdw(ch, RPAUSE, 0, 0);
3521 spin_unlock_irqrestore(&ch->ch_lock, lock_flags2);
3522 spin_unlock_irqrestore(&bd->bd_lock, lock_flags);
3526 static void dgap_tty_unthrottle(struct tty_struct *tty)
3529 struct channel_t *ch;
3534 if (!tty || tty->magic != TTY_MAGIC)
3537 un = tty->driver_data;
3538 if (!un || un->magic != DGAP_UNIT_MAGIC)
3542 if (!ch || ch->magic != DGAP_CHANNEL_MAGIC)
3546 if (!bd || bd->magic != DGAP_BOARD_MAGIC)
3549 spin_lock_irqsave(&bd->bd_lock, lock_flags);
3550 spin_lock_irqsave(&ch->ch_lock, lock_flags2);
3552 ch->ch_flags &= ~(CH_RXBLOCK);
3555 dgap_cmdw(ch, RRESUME, 0, 0);
3558 spin_unlock_irqrestore(&ch->ch_lock, lock_flags2);
3559 spin_unlock_irqrestore(&bd->bd_lock, lock_flags);
3562 static void dgap_tty_start(struct tty_struct *tty)
3565 struct channel_t *ch;
3570 if (!tty || tty->magic != TTY_MAGIC)
3573 un = tty->driver_data;
3574 if (!un || un->magic != DGAP_UNIT_MAGIC)
3578 if (!ch || ch->magic != DGAP_CHANNEL_MAGIC)
3582 if (!bd || bd->magic != DGAP_BOARD_MAGIC)
3585 spin_lock_irqsave(&bd->bd_lock, lock_flags);
3586 spin_lock_irqsave(&ch->ch_lock, lock_flags2);
3588 dgap_cmdw(ch, RESUMETX, 0, 0);
3590 spin_unlock_irqrestore(&ch->ch_lock, lock_flags2);
3591 spin_unlock_irqrestore(&bd->bd_lock, lock_flags);
3594 static void dgap_tty_stop(struct tty_struct *tty)
3597 struct channel_t *ch;
3602 if (!tty || tty->magic != TTY_MAGIC)
3605 un = tty->driver_data;
3606 if (!un || un->magic != DGAP_UNIT_MAGIC)
3610 if (!ch || ch->magic != DGAP_CHANNEL_MAGIC)
3614 if (!bd || bd->magic != DGAP_BOARD_MAGIC)
3617 spin_lock_irqsave(&bd->bd_lock, lock_flags);
3618 spin_lock_irqsave(&ch->ch_lock, lock_flags2);
3620 dgap_cmdw(ch, PAUSETX, 0, 0);
3622 spin_unlock_irqrestore(&ch->ch_lock, lock_flags2);
3623 spin_unlock_irqrestore(&bd->bd_lock, lock_flags);
3627 * dgap_tty_flush_chars()
3629 * Flush the cook buffer
3631 * Note to self, and any other poor souls who venture here:
3633 * flush in this case DOES NOT mean dispose of the data.
3634 * instead, it means "stop buffering and send it if you
3635 * haven't already." Just guess how I figured that out... SRW 2-Jun-98
3637 * It is also always called in interrupt context - JAR 8-Sept-99
3639 static void dgap_tty_flush_chars(struct tty_struct *tty)
3642 struct channel_t *ch;
3647 if (!tty || tty->magic != TTY_MAGIC)
3650 un = tty->driver_data;
3651 if (!un || un->magic != DGAP_UNIT_MAGIC)
3655 if (!ch || ch->magic != DGAP_CHANNEL_MAGIC)
3659 if (!bd || bd->magic != DGAP_BOARD_MAGIC)
3662 spin_lock_irqsave(&bd->bd_lock, lock_flags);
3663 spin_lock_irqsave(&ch->ch_lock, lock_flags2);
3665 /* TODO: Do something here */
3667 spin_unlock_irqrestore(&ch->ch_lock, lock_flags2);
3668 spin_unlock_irqrestore(&bd->bd_lock, lock_flags);
3672 * dgap_tty_flush_buffer()
3674 * Flush Tx buffer (make in == out)
3676 static void dgap_tty_flush_buffer(struct tty_struct *tty)
3679 struct channel_t *ch;
3685 if (!tty || tty->magic != TTY_MAGIC)
3688 un = tty->driver_data;
3689 if (!un || un->magic != DGAP_UNIT_MAGIC)
3693 if (!ch || ch->magic != DGAP_CHANNEL_MAGIC)
3697 if (!bd || bd->magic != DGAP_BOARD_MAGIC)
3700 spin_lock_irqsave(&bd->bd_lock, lock_flags);
3701 spin_lock_irqsave(&ch->ch_lock, lock_flags2);
3703 ch->ch_flags &= ~CH_STOP;
3704 head = readw(&(ch->ch_bs->tx_head));
3705 dgap_cmdw(ch, FLUSHTX, (u16) head, 0);
3706 dgap_cmdw(ch, RESUMETX, 0, 0);
3707 if (ch->ch_tun.un_flags & (UN_LOW|UN_EMPTY)) {
3708 ch->ch_tun.un_flags &= ~(UN_LOW|UN_EMPTY);
3709 wake_up_interruptible(&ch->ch_tun.un_flags_wait);
3711 if (ch->ch_pun.un_flags & (UN_LOW|UN_EMPTY)) {
3712 ch->ch_pun.un_flags &= ~(UN_LOW|UN_EMPTY);
3713 wake_up_interruptible(&ch->ch_pun.un_flags_wait);
3716 spin_unlock_irqrestore(&ch->ch_lock, lock_flags2);
3717 spin_unlock_irqrestore(&bd->bd_lock, lock_flags);
3718 if (waitqueue_active(&tty->write_wait))
3719 wake_up_interruptible(&tty->write_wait);
3723 /*****************************************************************************
3725 * The IOCTL function and all of its helpers
3727 *****************************************************************************/
3732 * The usual assortment of ioctl's
3734 static int dgap_tty_ioctl(struct tty_struct *tty, unsigned int cmd,
3738 struct channel_t *ch;
3742 ulong lock_flags = 0;
3743 ulong lock_flags2 = 0;
3744 void __user *uarg = (void __user *) arg;
3746 if (!tty || tty->magic != TTY_MAGIC)
3749 un = tty->driver_data;
3750 if (!un || un->magic != DGAP_UNIT_MAGIC)
3754 if (!ch || ch->magic != DGAP_CHANNEL_MAGIC)
3758 if (!bd || bd->magic != DGAP_BOARD_MAGIC)
3761 spin_lock_irqsave(&bd->bd_lock, lock_flags);
3762 spin_lock_irqsave(&ch->ch_lock, lock_flags2);
3764 if (un->un_open_count <= 0) {
3765 spin_unlock_irqrestore(&ch->ch_lock, lock_flags2);
3766 spin_unlock_irqrestore(&bd->bd_lock, lock_flags);
3772 /* Here are all the standard ioctl's that we MUST implement */
3776 * TCSBRK is SVID version: non-zero arg --> no break
3777 * this behaviour is exploited by tcdrain().
3779 * According to POSIX.1 spec (7.2.2.1.2) breaks should be
3780 * between 0.25 and 0.5 seconds so we'll ask for something
3781 * in the middle: 0.375 seconds.
3783 rc = tty_check_change(tty);
3784 spin_unlock_irqrestore(&ch->ch_lock, lock_flags2);
3785 spin_unlock_irqrestore(&bd->bd_lock, lock_flags);
3789 rc = dgap_wait_for_drain(tty);
3794 spin_lock_irqsave(&bd->bd_lock, lock_flags);
3795 spin_lock_irqsave(&ch->ch_lock, lock_flags2);
3797 if (((cmd == TCSBRK) && (!arg)) || (cmd == TCSBRKP))
3798 dgap_cmdw(ch, SBREAK, (u16) SBREAK_TIME, 0);
3800 spin_unlock_irqrestore(&ch->ch_lock, lock_flags2);
3801 spin_unlock_irqrestore(&bd->bd_lock, lock_flags);
3806 /* support for POSIX tcsendbreak()
3808 * According to POSIX.1 spec (7.2.2.1.2) breaks should be
3809 * between 0.25 and 0.5 seconds so we'll ask for something
3810 * in the middle: 0.375 seconds.
3812 rc = tty_check_change(tty);
3813 spin_unlock_irqrestore(&ch->ch_lock, lock_flags2);
3814 spin_unlock_irqrestore(&bd->bd_lock, lock_flags);
3818 rc = dgap_wait_for_drain(tty);
3822 spin_lock_irqsave(&bd->bd_lock, lock_flags);
3823 spin_lock_irqsave(&ch->ch_lock, lock_flags2);
3825 dgap_cmdw(ch, SBREAK, (u16) SBREAK_TIME, 0);
3827 spin_unlock_irqrestore(&ch->ch_lock, lock_flags2);
3828 spin_unlock_irqrestore(&bd->bd_lock, lock_flags);
3834 * FEP5 doesn't support turning on a break unconditionally.
3835 * The FEP5 device will stop sending a break automatically
3836 * after the specified time value that was sent when turning on
3839 rc = tty_check_change(tty);
3840 spin_unlock_irqrestore(&ch->ch_lock, lock_flags2);
3841 spin_unlock_irqrestore(&bd->bd_lock, lock_flags);
3845 rc = dgap_wait_for_drain(tty);
3849 spin_lock_irqsave(&bd->bd_lock, lock_flags);
3850 spin_lock_irqsave(&ch->ch_lock, lock_flags2);
3852 dgap_cmdw(ch, SBREAK, (u16) SBREAK_TIME, 0);
3854 spin_unlock_irqrestore(&ch->ch_lock, lock_flags2);
3855 spin_unlock_irqrestore(&bd->bd_lock, lock_flags);
3861 * FEP5 doesn't support turning off a break unconditionally.
3862 * The FEP5 device will stop sending a break automatically
3863 * after the specified time value that was sent when turning on
3866 spin_unlock_irqrestore(&ch->ch_lock, lock_flags2);
3867 spin_unlock_irqrestore(&bd->bd_lock, lock_flags);
3872 spin_unlock_irqrestore(&ch->ch_lock, lock_flags2);
3873 spin_unlock_irqrestore(&bd->bd_lock, lock_flags);
3875 rc = put_user(C_CLOCAL(tty) ? 1 : 0,
3876 (unsigned long __user *) arg);
3880 spin_unlock_irqrestore(&ch->ch_lock, lock_flags2);
3881 spin_unlock_irqrestore(&bd->bd_lock, lock_flags);
3883 rc = get_user(arg, (unsigned long __user *) arg);
3887 spin_lock_irqsave(&bd->bd_lock, lock_flags);
3888 spin_lock_irqsave(&ch->ch_lock, lock_flags2);
3889 tty->termios.c_cflag = ((tty->termios.c_cflag & ~CLOCAL) |
3890 (arg ? CLOCAL : 0));
3892 spin_unlock_irqrestore(&ch->ch_lock, lock_flags2);
3893 spin_unlock_irqrestore(&bd->bd_lock, lock_flags);
3898 spin_unlock_irqrestore(&ch->ch_lock, lock_flags2);
3899 spin_unlock_irqrestore(&bd->bd_lock, lock_flags);
3900 return dgap_get_modem_info(ch, uarg);
3905 spin_unlock_irqrestore(&ch->ch_lock, lock_flags2);
3906 spin_unlock_irqrestore(&bd->bd_lock, lock_flags);
3907 return dgap_set_modem_info(tty, cmd, uarg);
3910 * Here are any additional ioctl's that we want to implement
3915 * The linux tty driver doesn't have a flush
3916 * input routine for the driver, assuming all backed
3917 * up data is in the line disc. buffers. However,
3918 * we all know that's not the case. Here, we
3919 * act on the ioctl, but then lie and say we didn't
3920 * so the line discipline will process the flush
3923 rc = tty_check_change(tty);
3925 spin_unlock_irqrestore(&ch->ch_lock, lock_flags2);
3926 spin_unlock_irqrestore(&bd->bd_lock, lock_flags);
3930 if ((arg == TCIFLUSH) || (arg == TCIOFLUSH)) {
3931 if (!(un->un_type == DGAP_PRINT)) {
3932 head = readw(&(ch->ch_bs->rx_head));
3933 writew(head, &(ch->ch_bs->rx_tail));
3934 writeb(0, &(ch->ch_bs->orun));
3938 if ((arg != TCOFLUSH) && (arg != TCIOFLUSH)) {
3939 /* pretend we didn't recognize this IOCTL */
3940 spin_unlock_irqrestore(&ch->ch_lock, lock_flags2);
3941 spin_unlock_irqrestore(&bd->bd_lock, lock_flags);
3943 return -ENOIOCTLCMD;
3946 ch->ch_flags &= ~CH_STOP;
3947 head = readw(&(ch->ch_bs->tx_head));
3948 dgap_cmdw(ch, FLUSHTX, (u16) head, 0);
3949 dgap_cmdw(ch, RESUMETX, 0, 0);
3950 if (ch->ch_tun.un_flags & (UN_LOW|UN_EMPTY)) {
3951 ch->ch_tun.un_flags &= ~(UN_LOW|UN_EMPTY);
3952 wake_up_interruptible(&ch->ch_tun.un_flags_wait);
3954 if (ch->ch_pun.un_flags & (UN_LOW|UN_EMPTY)) {
3955 ch->ch_pun.un_flags &= ~(UN_LOW|UN_EMPTY);
3956 wake_up_interruptible(&ch->ch_pun.un_flags_wait);
3958 if (waitqueue_active(&tty->write_wait))
3959 wake_up_interruptible(&tty->write_wait);
3961 /* Can't hold any locks when calling tty_wakeup! */
3962 spin_unlock_irqrestore(&ch->ch_lock, lock_flags2);
3963 spin_unlock_irqrestore(&bd->bd_lock, lock_flags);
3966 /* pretend we didn't recognize this IOCTL */
3967 return -ENOIOCTLCMD;
3972 * The linux tty driver doesn't have a flush
3973 * input routine for the driver, assuming all backed
3974 * up data is in the line disc. buffers. However,
3975 * we all know that's not the case. Here, we
3976 * act on the ioctl, but then lie and say we didn't
3977 * so the line discipline will process the flush
3980 if (cmd == TCSETSF) {
3982 ch->ch_flags &= ~CH_STOP;
3983 head = readw(&(ch->ch_bs->rx_head));
3984 writew(head, &(ch->ch_bs->rx_tail));
3987 /* now wait for all the output to drain */
3988 spin_unlock_irqrestore(&ch->ch_lock, lock_flags2);
3989 spin_unlock_irqrestore(&bd->bd_lock, lock_flags);
3990 rc = dgap_wait_for_drain(tty);
3994 /* pretend we didn't recognize this */
3995 return -ENOIOCTLCMD;
3999 spin_unlock_irqrestore(&ch->ch_lock, lock_flags2);
4000 spin_unlock_irqrestore(&bd->bd_lock, lock_flags);
4001 rc = dgap_wait_for_drain(tty);
4005 /* pretend we didn't recognize this */
4006 return -ENOIOCTLCMD;
4010 * The Linux Line Discipline (LD) would do this for us if we
4011 * let it, but we have the special firmware options to do this
4012 * the "right way" regardless of hardware or software flow
4013 * control so we'll do it outselves instead of letting the LD
4016 rc = tty_check_change(tty);
4018 spin_unlock_irqrestore(&ch->ch_lock, lock_flags2);
4019 spin_unlock_irqrestore(&bd->bd_lock, lock_flags);
4026 spin_unlock_irqrestore(&ch->ch_lock, lock_flags2);
4027 spin_unlock_irqrestore(&bd->bd_lock, lock_flags);
4028 dgap_tty_start(tty);
4031 spin_unlock_irqrestore(&ch->ch_lock, lock_flags2);
4032 spin_unlock_irqrestore(&bd->bd_lock, lock_flags);
4036 spin_unlock_irqrestore(&ch->ch_lock, lock_flags2);
4037 spin_unlock_irqrestore(&bd->bd_lock, lock_flags);
4038 /* Make the ld do it */
4039 return -ENOIOCTLCMD;
4041 spin_unlock_irqrestore(&ch->ch_lock, lock_flags2);
4042 spin_unlock_irqrestore(&bd->bd_lock, lock_flags);
4043 /* Make the ld do it */
4044 return -ENOIOCTLCMD;
4046 spin_unlock_irqrestore(&ch->ch_lock, lock_flags2);
4047 spin_unlock_irqrestore(&bd->bd_lock, lock_flags);
4052 /* get information for ditty */
4053 spin_unlock_irqrestore(&ch->ch_lock, lock_flags2);
4054 spin_unlock_irqrestore(&bd->bd_lock, lock_flags);
4055 return dgap_tty_digigeta(tty, uarg);
4060 /* set information for ditty */
4061 if (cmd == (DIGI_SETAW)) {
4063 spin_unlock_irqrestore(&ch->ch_lock, lock_flags2);
4064 spin_unlock_irqrestore(&bd->bd_lock, lock_flags);
4065 rc = dgap_wait_for_drain(tty);
4068 spin_lock_irqsave(&bd->bd_lock, lock_flags);
4069 spin_lock_irqsave(&ch->ch_lock, lock_flags2);
4071 tty_ldisc_flush(tty);
4075 spin_unlock_irqrestore(&ch->ch_lock, lock_flags2);
4076 spin_unlock_irqrestore(&bd->bd_lock, lock_flags);
4077 return dgap_tty_digiseta(tty, uarg);
4080 spin_unlock_irqrestore(&ch->ch_lock, lock_flags2);
4081 spin_unlock_irqrestore(&bd->bd_lock, lock_flags);
4082 return dgap_tty_digigetedelay(tty, uarg);
4085 spin_unlock_irqrestore(&ch->ch_lock, lock_flags2);
4086 spin_unlock_irqrestore(&bd->bd_lock, lock_flags);
4087 return dgap_tty_digisetedelay(tty, uarg);
4089 case DIGI_GETCUSTOMBAUD:
4090 spin_unlock_irqrestore(&ch->ch_lock, lock_flags2);
4091 spin_unlock_irqrestore(&bd->bd_lock, lock_flags);
4092 return dgap_tty_digigetcustombaud(tty, uarg);
4094 case DIGI_SETCUSTOMBAUD:
4095 spin_unlock_irqrestore(&ch->ch_lock, lock_flags2);
4096 spin_unlock_irqrestore(&bd->bd_lock, lock_flags);
4097 return dgap_tty_digisetcustombaud(tty, uarg);
4099 case DIGI_RESET_PORT:
4100 dgap_firmware_reset_port(ch);
4102 spin_unlock_irqrestore(&ch->ch_lock, lock_flags2);
4103 spin_unlock_irqrestore(&bd->bd_lock, lock_flags);
4107 spin_unlock_irqrestore(&ch->ch_lock, lock_flags2);
4108 spin_unlock_irqrestore(&bd->bd_lock, lock_flags);
4110 return -ENOIOCTLCMD;
4114 static int dgap_after_config_loaded(int board)
4117 * Initialize KME waitqueues...
4119 init_waitqueue_head(&(dgap_board[board]->kme_wait));
4122 * allocate flip buffer for board.
4124 dgap_board[board]->flipbuf = kmalloc(MYFLIPLEN, GFP_ATOMIC);
4125 if (!dgap_board[board]->flipbuf)
4128 dgap_board[board]->flipflagbuf = kmalloc(MYFLIPLEN, GFP_ATOMIC);
4129 if (!dgap_board[board]->flipflagbuf) {
4130 kfree(dgap_board[board]->flipbuf);
4138 * Create pr and tty device entries
4140 static int dgap_tty_register_ports(struct board_t *brd)
4142 struct channel_t *ch;
4145 brd->serial_ports = kcalloc(brd->nasync, sizeof(*brd->serial_ports),
4147 if (brd->serial_ports == NULL)
4149 for (i = 0; i < brd->nasync; i++)
4150 tty_port_init(&brd->serial_ports[i]);
4152 brd->printer_ports = kcalloc(brd->nasync, sizeof(*brd->printer_ports),
4154 if (brd->printer_ports == NULL) {
4155 kfree(brd->serial_ports);
4158 for (i = 0; i < brd->nasync; i++)
4159 tty_port_init(&brd->printer_ports[i]);
4161 ch = brd->channels[0];
4162 for (i = 0; i < brd->nasync; i++, ch = brd->channels[i]) {
4164 struct device *classp;
4166 classp = tty_port_register_device(&brd->serial_ports[i],
4168 brd->firstminor + i, NULL);
4170 dgap_create_tty_sysfs(&ch->ch_tun, classp);
4171 ch->ch_tun.un_sysfs = classp;
4173 classp = tty_port_register_device(&brd->printer_ports[i],
4175 brd->firstminor + i, NULL);
4177 dgap_create_tty_sysfs(&ch->ch_pun, classp);
4178 ch->ch_pun.un_sysfs = classp;
4180 dgap_create_ports_sysfiles(brd);
4186 * Copies the BIOS code from the user to the board,
4187 * and starts the BIOS running.
4189 static void dgap_do_bios_load(struct board_t *brd, const u8 *ubios, int len)
4195 if (!brd || (brd->magic != DGAP_BOARD_MAGIC) || !brd->re_map_membase)
4198 addr = brd->re_map_membase;
4203 for (i = 0; i < 16; i++)
4204 writeb(0, addr + POSTAREA + i);
4210 memcpy_toio(addr + offset, ubios, len);
4212 writel(0x0bf00401, addr);
4213 writel(0, (addr + 4));
4215 /* Clear the reset, and change states. */
4216 writeb(FEPCLR, brd->re_map_port);
4220 * Checks to see if the BIOS completed running on the card.
4222 static int dgap_test_bios(struct board_t *brd)
4229 if (!brd || (brd->magic != DGAP_BOARD_MAGIC) || !brd->re_map_membase)
4232 addr = brd->re_map_membase;
4233 word = readw(addr + POSTAREA);
4236 * It can take 5-6 seconds for a board to
4237 * pass the bios self test and post results.
4238 * Give it 10 seconds.
4240 brd->wait_for_bios = 0;
4241 while (brd->wait_for_bios < 1000) {
4242 /* Check to see if BIOS thinks board is good. (GD). */
4243 if (word == *(u16 *) "GD")
4245 msleep_interruptible(10);
4246 brd->wait_for_bios++;
4247 word = readw(addr + POSTAREA);
4250 /* Gave up on board after too long of time taken */
4251 err1 = readw(addr + SEQUENCE);
4252 err2 = readw(addr + ERROR);
4253 pr_warn("dgap: %s failed diagnostics. Error #(%x,%x).\n",
4254 brd->name, err1, err2);
4255 brd->state = BOARD_FAILED;
4256 brd->dpastatus = BD_NOBIOS;
4262 * Copies the FEP code from the user to the board,
4263 * and starts the FEP running.
4265 static void dgap_do_fep_load(struct board_t *brd, const u8 *ufep, int len)
4270 if (!brd || (brd->magic != DGAP_BOARD_MAGIC) || !brd->re_map_membase)
4273 addr = brd->re_map_membase;
4279 memcpy_toio(addr + offset, ufep, len);
4282 * If board is a concentrator product, we need to give
4283 * it its config string describing how the concentrators look.
4285 if ((brd->type == PCX) || (brd->type == PEPC)) {
4291 xconfig = dgap_create_config_string(brd, string);
4293 /* Write string to board memory */
4294 config = addr + CONFIG;
4295 for (; i < CONFIGSIZE; i++, config++, xconfig++) {
4296 writeb(*xconfig, config);
4297 if ((*xconfig & 0xff) == 0xff)
4302 writel(0xbfc01004, (addr + 0xc34));
4303 writel(0x3, (addr + 0xc30));
4308 * Waits for the FEP to report thats its ready for us to use.
4310 static int dgap_test_fep(struct board_t *brd)
4317 if (!brd || (brd->magic != DGAP_BOARD_MAGIC) || !brd->re_map_membase)
4320 addr = brd->re_map_membase;
4321 word = readw(addr + FEPSTAT);
4324 * It can take 2-3 seconds for the FEP to
4325 * be up and running. Give it 5 secs.
4327 brd->wait_for_fep = 0;
4328 while (brd->wait_for_fep < 500) {
4329 /* Check to see if FEP is up and running now. */
4330 if (word == *(u16 *) "OS") {
4332 * Check to see if the board can support FEP5+ commands.
4334 word = readw(addr + FEP5_PLUS);
4335 if (word == *(u16 *) "5A")
4336 brd->bd_flags |= BD_FEP5PLUS;
4340 msleep_interruptible(10);
4341 brd->wait_for_fep++;
4342 word = readw(addr + FEPSTAT);
4345 /* Gave up on board after too long of time taken */
4346 err1 = readw(addr + SEQUENCE);
4347 err2 = readw(addr + ERROR);
4348 pr_warn("dgap: FEPOS for %s not functioning. Error #(%x,%x).\n",
4349 brd->name, err1, err2);
4350 brd->state = BOARD_FAILED;
4351 brd->dpastatus = BD_NOFEP;
4357 * Physically forces the FEP5 card to reset itself.
4359 static void dgap_do_reset_board(struct board_t *brd)
4366 if (!brd || (brd->magic != DGAP_BOARD_MAGIC) ||
4367 !brd->re_map_membase || !brd->re_map_port)
4370 /* FEPRST does not vary among supported boards */
4371 writeb(FEPRST, brd->re_map_port);
4373 for (i = 0; i <= 1000; i++) {
4374 check = readb(brd->re_map_port) & 0xe;
4375 if (check == FEPRST)
4381 pr_warn("dgap: Board not resetting... Failing board.\n");
4382 brd->state = BOARD_FAILED;
4383 brd->dpastatus = BD_NOFEP;
4388 * Make sure there really is memory out there.
4390 writel(0xa55a3cc3, (brd->re_map_membase + LOWMEM));
4391 writel(0x5aa5c33c, (brd->re_map_membase + HIGHMEM));
4392 check1 = readl(brd->re_map_membase + LOWMEM);
4393 check2 = readl(brd->re_map_membase + HIGHMEM);
4395 if ((check1 != 0xa55a3cc3) || (check2 != 0x5aa5c33c)) {
4396 pr_warn("dgap: No memory at %p for board.\n",
4397 brd->re_map_membase);
4398 brd->state = BOARD_FAILED;
4399 brd->dpastatus = BD_NOFEP;
4404 #ifdef DIGI_CONCENTRATORS_SUPPORTED
4406 * Sends a concentrator image into the FEP5 board.
4408 static void dgap_do_conc_load(struct board_t *brd, u8 *uaddr, int len)
4410 char __iomem *vaddr;
4412 struct downld_t *to_dp;
4414 if (!brd || (brd->magic != DGAP_BOARD_MAGIC) || !brd->re_map_membase)
4417 vaddr = brd->re_map_membase;
4419 offset = readw((u16 *) (vaddr + DOWNREQ));
4420 to_dp = (struct downld_t *) (vaddr + (int) offset);
4421 memcpy_toio(to_dp, uaddr, len);
4423 /* Tell card we have data for it */
4424 writew(0, vaddr + (DOWNREQ));
4426 brd->conc_dl_status = NO_PENDING_CONCENTRATOR_REQUESTS;
4430 #define EXPANSION_ROM_SIZE (64 * 1024)
4431 #define FEP5_ROM_MAGIC (0xFEFFFFFF)
4433 static void dgap_get_vpd(struct board_t *brd)
4445 * Poke the magic number at the PCI Rom Address location.
4446 * If VPD is supported, the value read from that address
4449 magic = FEP5_ROM_MAGIC;
4450 pci_write_config_dword(brd->pdev, PCI_ROM_ADDRESS, magic);
4451 pci_read_config_dword(brd->pdev, PCI_ROM_ADDRESS, &magic);
4453 /* VPD not supported, bail */
4458 * To get to the OTPROM memory, we have to send the boards base
4459 * address or'ed with 1 into the PCI Rom Address location.
4461 magic = brd->membase | 0x01;
4462 pci_write_config_dword(brd->pdev, PCI_ROM_ADDRESS, magic);
4463 pci_read_config_dword(brd->pdev, PCI_ROM_ADDRESS, &magic);
4465 byte1 = readb(brd->re_map_membase);
4466 byte2 = readb(brd->re_map_membase + 1);
4469 * If the board correctly swapped to the OTPROM memory,
4470 * the first 2 bytes (header) should be 0x55, 0xAA
4472 if (byte1 == 0x55 && byte2 == 0xAA) {
4477 * We have to run through all the OTPROM memory looking
4478 * for the VPD offset.
4480 while (base_offset <= EXPANSION_ROM_SIZE) {
4483 * Lots of magic numbers here.
4485 * The VPD offset is located inside the ROM Data
4488 * We also have to remember the length of each
4489 * ROM Data Structure, so we can "hop" to the next
4490 * entry if the VPD isn't in the current
4491 * ROM Data Structure.
4493 rom_offset = readw(brd->re_map_membase +
4494 base_offset + 0x18);
4495 image_length = readw(brd->re_map_membase +
4496 rom_offset + 0x10) * 512;
4497 vpd_offset = readw(brd->re_map_membase +
4500 /* Found the VPD entry */
4504 /* We didn't find a VPD entry, go to next ROM entry. */
4505 base_offset += image_length;
4507 byte1 = readb(brd->re_map_membase + base_offset);
4508 byte2 = readb(brd->re_map_membase + base_offset + 1);
4511 * If the new ROM offset doesn't have 0x55, 0xAA
4512 * as its header, we have run out of ROM.
4514 if (byte1 != 0x55 || byte2 != 0xAA)
4519 * If we have a VPD offset, then mark the board
4520 * as having a valid VPD, and copy VPDSIZE (512) bytes of
4521 * that VPD to the buffer we have in our board structure.
4524 brd->bd_flags |= BD_HAS_VPD;
4525 for (i = 0; i < VPDSIZE; i++) {
4526 brd->vpd[i] = readb(brd->re_map_membase +
4533 * We MUST poke the magic number at the PCI Rom Address location again.
4534 * This makes the card report the regular board memory back to us,
4535 * rather than the OTPROM memory.
4537 magic = FEP5_ROM_MAGIC;
4538 pci_write_config_dword(brd->pdev, PCI_ROM_ADDRESS, magic);
4542 * Our board poller function.
4544 static void dgap_poll_tasklet(unsigned long data)
4546 struct board_t *bd = (struct board_t *) data;
4548 char __iomem *vaddr;
4551 if (!bd || (bd->magic != DGAP_BOARD_MAGIC))
4554 if (bd->inhibit_poller)
4557 spin_lock_irqsave(&bd->bd_lock, lock_flags);
4559 vaddr = bd->re_map_membase;
4562 * If board is ready, parse deeper to see if there is anything to do.
4564 if (bd->state == BOARD_READY) {
4566 struct ev_t __iomem *eaddr;
4568 if (!bd->re_map_membase) {
4569 spin_unlock_irqrestore(&bd->bd_lock, lock_flags);
4572 if (!bd->re_map_port) {
4573 spin_unlock_irqrestore(&bd->bd_lock, lock_flags);
4580 eaddr = (struct ev_t __iomem *) (vaddr + EVBUF);
4582 /* Get our head and tail */
4583 head = readw(&(eaddr->ev_head));
4584 tail = readw(&(eaddr->ev_tail));
4587 * If there is an event pending. Go service it.
4590 spin_unlock_irqrestore(&bd->bd_lock, lock_flags);
4592 spin_lock_irqsave(&bd->bd_lock, lock_flags);
4597 * If board is doing interrupts, ACK the interrupt.
4599 if (bd && bd->intr_running)
4600 readb(bd->re_map_port + 2);
4602 spin_unlock_irqrestore(&bd->bd_lock, lock_flags);
4606 spin_unlock_irqrestore(&bd->bd_lock, lock_flags);
4609 /*=======================================================================
4611 * dgap_cmdb - Sends a 2 byte command to the FEP.
4613 * ch - Pointer to channel structure.
4614 * cmd - Command to be sent.
4615 * byte1 - Integer containing first byte to be sent.
4616 * byte2 - Integer containing second byte to be sent.
4617 * ncmds - Wait until ncmds or fewer cmds are left
4618 * in the cmd buffer before returning.
4620 *=======================================================================*/
4621 static void dgap_cmdb(struct channel_t *ch, u8 cmd, u8 byte1,
4622 u8 byte2, uint ncmds)
4624 char __iomem *vaddr;
4625 struct __iomem cm_t *cm_addr;
4631 if (!ch || ch->magic != DGAP_CHANNEL_MAGIC)
4635 * Check if board is still alive.
4637 if (ch->ch_bd->state == BOARD_FAILED)
4641 * Make sure the pointers are in range before
4642 * writing to the FEP memory.
4644 vaddr = ch->ch_bd->re_map_membase;
4649 cm_addr = (struct cm_t __iomem *) (vaddr + CMDBUF);
4650 head = readw(&(cm_addr->cm_head));
4653 * Forget it if pointers out of range.
4655 if (head >= (CMDMAX - CMDSTART) || (head & 03)) {
4656 ch->ch_bd->state = BOARD_FAILED;
4661 * Put the data in the circular command buffer.
4663 writeb(cmd, (vaddr + head + CMDSTART + 0));
4664 writeb((u8) ch->ch_portnum, (vaddr + head + CMDSTART + 1));
4665 writeb(byte1, (vaddr + head + CMDSTART + 2));
4666 writeb(byte2, (vaddr + head + CMDSTART + 3));
4668 head = (head + 4) & (CMDMAX - CMDSTART - 4);
4670 writew(head, &(cm_addr->cm_head));
4673 * Wait if necessary before updating the head
4674 * pointer to limit the number of outstanding
4675 * commands to the FEP. If the time spent waiting
4676 * is outlandish, declare the FEP dead.
4678 for (count = dgap_count ;;) {
4680 head = readw(&(cm_addr->cm_head));
4681 tail = readw(&(cm_addr->cm_tail));
4683 n = (head - tail) & (CMDMAX - CMDSTART - 4);
4685 if (n <= ncmds * sizeof(struct cm_t))
4689 ch->ch_bd->state = BOARD_FAILED;
4696 /*=======================================================================
4698 * dgap_cmdw - Sends a 1 word command to the FEP.
4700 * ch - Pointer to channel structure.
4701 * cmd - Command to be sent.
4702 * word - Integer containing word to be sent.
4703 * ncmds - Wait until ncmds or fewer cmds are left
4704 * in the cmd buffer before returning.
4706 *=======================================================================*/
4707 static void dgap_cmdw(struct channel_t *ch, u8 cmd, u16 word, uint ncmds)
4709 char __iomem *vaddr;
4710 struct __iomem cm_t *cm_addr;
4716 if (!ch || ch->magic != DGAP_CHANNEL_MAGIC)
4720 * Check if board is still alive.
4722 if (ch->ch_bd->state == BOARD_FAILED)
4726 * Make sure the pointers are in range before
4727 * writing to the FEP memory.
4729 vaddr = ch->ch_bd->re_map_membase;
4733 cm_addr = (struct cm_t __iomem *) (vaddr + CMDBUF);
4734 head = readw(&(cm_addr->cm_head));
4737 * Forget it if pointers out of range.
4739 if (head >= (CMDMAX - CMDSTART) || (head & 03)) {
4740 ch->ch_bd->state = BOARD_FAILED;
4745 * Put the data in the circular command buffer.
4747 writeb(cmd, (vaddr + head + CMDSTART + 0));
4748 writeb((u8) ch->ch_portnum, (vaddr + head + CMDSTART + 1));
4749 writew((u16) word, (vaddr + head + CMDSTART + 2));
4751 head = (head + 4) & (CMDMAX - CMDSTART - 4);
4753 writew(head, &(cm_addr->cm_head));
4756 * Wait if necessary before updating the head
4757 * pointer to limit the number of outstanding
4758 * commands to the FEP. If the time spent waiting
4759 * is outlandish, declare the FEP dead.
4761 for (count = dgap_count ;;) {
4763 head = readw(&(cm_addr->cm_head));
4764 tail = readw(&(cm_addr->cm_tail));
4766 n = (head - tail) & (CMDMAX - CMDSTART - 4);
4768 if (n <= ncmds * sizeof(struct cm_t))
4772 ch->ch_bd->state = BOARD_FAILED;
4779 /*=======================================================================
4781 * dgap_cmdw_ext - Sends a extended word command to the FEP.
4783 * ch - Pointer to channel structure.
4784 * cmd - Command to be sent.
4785 * word - Integer containing word to be sent.
4786 * ncmds - Wait until ncmds or fewer cmds are left
4787 * in the cmd buffer before returning.
4789 *=======================================================================*/
4790 static void dgap_cmdw_ext(struct channel_t *ch, u16 cmd, u16 word, uint ncmds)
4792 char __iomem *vaddr;
4793 struct __iomem cm_t *cm_addr;
4799 if (!ch || ch->magic != DGAP_CHANNEL_MAGIC)
4803 * Check if board is still alive.
4805 if (ch->ch_bd->state == BOARD_FAILED)
4809 * Make sure the pointers are in range before
4810 * writing to the FEP memory.
4812 vaddr = ch->ch_bd->re_map_membase;
4816 cm_addr = (struct cm_t __iomem *) (vaddr + CMDBUF);
4817 head = readw(&(cm_addr->cm_head));
4820 * Forget it if pointers out of range.
4822 if (head >= (CMDMAX - CMDSTART) || (head & 03)) {
4823 ch->ch_bd->state = BOARD_FAILED;
4828 * Put the data in the circular command buffer.
4831 /* Write an FF to tell the FEP that we want an extended command */
4832 writeb((u8) 0xff, (vaddr + head + CMDSTART + 0));
4834 writeb((u8) ch->ch_portnum, (vaddr + head + CMDSTART + 1));
4835 writew((u16) cmd, (vaddr + head + CMDSTART + 2));
4838 * If the second part of the command won't fit,
4839 * put it at the beginning of the circular buffer.
4841 if (((head + 4) >= ((CMDMAX - CMDSTART)) || (head & 03)))
4842 writew((u16) word, (vaddr + CMDSTART));
4844 writew((u16) word, (vaddr + head + CMDSTART + 4));
4846 head = (head + 8) & (CMDMAX - CMDSTART - 4);
4848 writew(head, &(cm_addr->cm_head));
4851 * Wait if necessary before updating the head
4852 * pointer to limit the number of outstanding
4853 * commands to the FEP. If the time spent waiting
4854 * is outlandish, declare the FEP dead.
4856 for (count = dgap_count ;;) {
4858 head = readw(&(cm_addr->cm_head));
4859 tail = readw(&(cm_addr->cm_tail));
4861 n = (head - tail) & (CMDMAX - CMDSTART - 4);
4863 if (n <= ncmds * sizeof(struct cm_t))
4867 ch->ch_bd->state = BOARD_FAILED;
4874 /*=======================================================================
4876 * dgap_wmove - Write data to FEP buffer.
4878 * ch - Pointer to channel structure.
4879 * buf - Poiter to characters to be moved.
4880 * cnt - Number of characters to move.
4882 *=======================================================================*/
4883 static void dgap_wmove(struct channel_t *ch, char *buf, uint cnt)
4886 char __iomem *taddr;
4887 struct bs_t __iomem *bs;
4890 if (!ch || ch->magic != DGAP_CHANNEL_MAGIC)
4897 head = readw(&(bs->tx_head));
4900 * If pointers are out of range, just return.
4902 if ((cnt > ch->ch_tsize) ||
4903 (unsigned)(head - ch->ch_tstart) >= ch->ch_tsize)
4907 * If the write wraps over the top of the circular buffer,
4908 * move the portion up to the wrap point, and reset the
4909 * pointers to the bottom.
4911 n = ch->ch_tstart + ch->ch_tsize - head;
4915 taddr = ch->ch_taddr + head;
4916 memcpy_toio(taddr, buf, n);
4917 head = ch->ch_tstart;
4922 * Move rest of data.
4924 taddr = ch->ch_taddr + head;
4926 memcpy_toio(taddr, buf, n);
4929 writew(head, &(bs->tx_head));
4933 * Retrives the current custom baud rate from FEP memory,
4934 * and returns it back to the user.
4935 * Returns 0 on error.
4937 static uint dgap_get_custom_baud(struct channel_t *ch)
4943 if (!ch || ch->magic != DGAP_CHANNEL_MAGIC)
4946 if (!ch->ch_bd || ch->ch_bd->magic != DGAP_BOARD_MAGIC)
4949 if (!(ch->ch_bd->bd_flags & BD_FEP5PLUS))
4952 vaddr = ch->ch_bd->re_map_membase;
4958 * Go get from fep mem, what the fep
4959 * believes the custom baud rate is.
4961 offset = ((((*(unsigned short __iomem *)(vaddr + ECS_SEG)) << 4) +
4962 (ch->ch_portnum * 0x28) + LINE_SPEED));
4964 value = readw(vaddr + offset);
4969 * Calls the firmware to reset this channel.
4971 static void dgap_firmware_reset_port(struct channel_t *ch)
4973 dgap_cmdb(ch, CHRESET, 0, 0, 0);
4976 * Now that the channel is reset, we need to make sure
4977 * all the current settings get reapplied to the port
4980 * So we will set the driver's cache of firmware
4981 * settings all to 0, and then call param.
4983 ch->ch_fepiflag = 0;
4984 ch->ch_fepcflag = 0;
4985 ch->ch_fepoflag = 0;
4986 ch->ch_fepstartc = 0;
4987 ch->ch_fepstopc = 0;
4988 ch->ch_fepastartc = 0;
4989 ch->ch_fepastopc = 0;
4994 /*=======================================================================
4996 * dgap_param - Set Digi parameters.
4998 * struct tty_struct * - TTY for port.
5000 *=======================================================================*/
5001 static int dgap_param(struct tty_struct *tty)
5003 struct ktermios *ts;
5005 struct channel_t *ch;
5006 struct bs_t __iomem *bs;
5014 if (!tty || tty->magic != TTY_MAGIC)
5017 un = (struct un_t *) tty->driver_data;
5018 if (!un || un->magic != DGAP_UNIT_MAGIC)
5022 if (!ch || ch->magic != DGAP_CHANNEL_MAGIC)
5026 if (!bd || bd->magic != DGAP_BOARD_MAGIC)
5036 * If baud rate is zero, flush queues, and set mval to drop DTR.
5038 if ((ch->ch_c_cflag & (CBAUD)) == 0) {
5041 head = readw(&(ch->ch_bs->rx_head));
5042 writew(head, &(ch->ch_bs->rx_tail));
5045 head = readw(&(ch->ch_bs->tx_head));
5046 writew(head, &(ch->ch_bs->tx_tail));
5048 ch->ch_flags |= (CH_BAUD0);
5050 /* Drop RTS and DTR */
5051 ch->ch_mval &= ~(D_RTS(ch)|D_DTR(ch));
5052 mval = D_DTR(ch) | D_RTS(ch);
5053 ch->ch_baud_info = 0;
5055 } else if (ch->ch_custom_speed && (bd->bd_flags & BD_FEP5PLUS)) {
5057 * Tell the fep to do the command
5060 dgap_cmdw_ext(ch, 0xff01, ch->ch_custom_speed, 0);
5063 * Now go get from fep mem, what the fep
5064 * believes the custom baud rate is.
5066 ch->ch_custom_speed = dgap_get_custom_baud(ch);
5067 ch->ch_baud_info = ch->ch_custom_speed;
5069 /* Handle transition from B0 */
5070 if (ch->ch_flags & CH_BAUD0) {
5071 ch->ch_flags &= ~(CH_BAUD0);
5072 ch->ch_mval |= (D_RTS(ch)|D_DTR(ch));
5074 mval = D_DTR(ch) | D_RTS(ch);
5078 * Set baud rate, character size, and parity.
5086 ulong bauds[4][16] = {
5090 600, 1200, 1800, 2400,
5091 4800, 9600, 19200, 38400 },
5092 { /* slowbaud & CBAUDEX */
5093 0, 57600, 115200, 230400,
5094 460800, 150, 200, 921600,
5095 600, 1200, 1800, 2400,
5096 4800, 9600, 19200, 38400 },
5098 0, 57600, 76800, 115200,
5099 14400, 57600, 230400, 76800,
5100 115200, 230400, 28800, 460800,
5101 921600, 9600, 19200, 38400 },
5102 { /* fastbaud & CBAUDEX */
5103 0, 57600, 115200, 230400,
5104 460800, 150, 200, 921600,
5105 600, 1200, 1800, 2400,
5106 4800, 9600, 19200, 38400 }
5110 * Only use the TXPrint baud rate if the
5111 * terminal unit is NOT open
5113 if (!(ch->ch_tun.un_flags & UN_ISOPEN) &&
5114 (un->un_type == DGAP_PRINT))
5115 baud = C_BAUD(ch->ch_pun.un_tty) & 0xff;
5117 baud = C_BAUD(ch->ch_tun.un_tty) & 0xff;
5119 if (ch->ch_c_cflag & CBAUDEX)
5122 if (ch->ch_digi.digi_flags & DIGI_FAST)
5127 if ((iindex >= 0) && (iindex < 4) &&
5128 (jindex >= 0) && (jindex < 16))
5129 baud = bauds[iindex][jindex];
5136 ch->ch_baud_info = baud;
5139 * CBAUD has bit position 0x1000 set these days to
5140 * indicate Linux baud rate remap.
5141 * We use a different bit assignment for high speed.
5142 * Clear this bit out while grabbing the parts of
5145 cflag = ch->ch_c_cflag & ((CBAUD ^ CBAUDEX) | PARODD | PARENB |
5149 * HUPCL bit is used by FEP to indicate fast baud
5150 * table is to be used.
5152 if ((ch->ch_digi.digi_flags & DIGI_FAST) ||
5153 (ch->ch_c_cflag & CBAUDEX))
5156 if ((ch->ch_c_cflag & CBAUDEX) &&
5157 !(ch->ch_digi.digi_flags & DIGI_FAST)) {
5159 * The below code is trying to guarantee that only
5160 * baud rates 115200, 230400, 460800, 921600 are
5161 * remapped. We use exclusive or because the various
5162 * baud rates share common bit positions and therefore
5163 * can't be tested for easily.
5165 tcflag_t tcflag = (ch->ch_c_cflag & CBAUD) | CBAUDEX;
5169 * Map high speed requests to index
5170 * into FEP's baud table
5200 cflag = (cflag & ~(CBAUD | CBAUDEX)) | baudpart;
5205 if (cflag != ch->ch_fepcflag) {
5206 ch->ch_fepcflag = (u16) (cflag & 0xffff);
5209 * Okay to have channel and board
5210 * locks held calling this
5212 dgap_cmdw(ch, SCFLAG, (u16) cflag, 0);
5215 /* Handle transition from B0 */
5216 if (ch->ch_flags & CH_BAUD0) {
5217 ch->ch_flags &= ~(CH_BAUD0);
5218 ch->ch_mval |= (D_RTS(ch)|D_DTR(ch));
5220 mval = D_DTR(ch) | D_RTS(ch);
5226 iflag = ch->ch_c_iflag & (IGNBRK | BRKINT | IGNPAR | PARMRK |
5227 INPCK | ISTRIP | IXON | IXANY | IXOFF);
5229 if ((ch->ch_startc == _POSIX_VDISABLE) ||
5230 (ch->ch_stopc == _POSIX_VDISABLE)) {
5231 iflag &= ~(IXON | IXOFF);
5232 ch->ch_c_iflag &= ~(IXON | IXOFF);
5236 * Only the IBM Xr card can switch between
5237 * 232 and 422 modes on the fly
5239 if (bd->device == PCI_DEV_XR_IBM_DID) {
5240 if (ch->ch_digi.digi_flags & DIGI_422)
5241 dgap_cmdb(ch, SCOMMODE, MODE_422, 0, 0);
5243 dgap_cmdb(ch, SCOMMODE, MODE_232, 0, 0);
5246 if (ch->ch_digi.digi_flags & DIGI_ALTPIN)
5249 if (iflag != ch->ch_fepiflag) {
5250 ch->ch_fepiflag = iflag;
5252 /* Okay to have channel and board locks held calling this */
5253 dgap_cmdw(ch, SIFLAG, (u16) ch->ch_fepiflag, 0);
5257 * Select hardware handshaking.
5261 if (ch->ch_c_cflag & CRTSCTS)
5262 hflow |= (D_RTS(ch) | D_CTS(ch));
5263 if (ch->ch_digi.digi_flags & RTSPACE)
5265 if (ch->ch_digi.digi_flags & DTRPACE)
5267 if (ch->ch_digi.digi_flags & CTSPACE)
5269 if (ch->ch_digi.digi_flags & DSRPACE)
5271 if (ch->ch_digi.digi_flags & DCDPACE)
5274 if (hflow != ch->ch_hflow) {
5275 ch->ch_hflow = hflow;
5277 /* Okay to have channel and board locks held calling this */
5278 dgap_cmdb(ch, SHFLOW, (u8) hflow, 0xff, 0);
5282 * Set RTS and/or DTR Toggle if needed,
5283 * but only if product is FEP5+ based.
5285 if (bd->bd_flags & BD_FEP5PLUS) {
5287 if (ch->ch_digi.digi_flags & DIGI_RTS_TOGGLE)
5288 hflow2 |= (D_RTS(ch));
5289 if (ch->ch_digi.digi_flags & DIGI_DTR_TOGGLE)
5290 hflow2 |= (D_DTR(ch));
5292 dgap_cmdw_ext(ch, 0xff03, hflow2, 0);
5296 * Set modem control lines.
5299 mval ^= ch->ch_mforce & (mval ^ ch->ch_mval);
5301 if (ch->ch_mostat ^ mval) {
5302 ch->ch_mostat = mval;
5304 /* Okay to have channel and board locks held calling this */
5305 dgap_cmdb(ch, SMODEM, (u8) mval, D_RTS(ch)|D_DTR(ch), 0);
5309 * Read modem signals, and then call carrier function.
5311 ch->ch_mistat = readb(&(bs->m_stat));
5315 * Set the start and stop characters.
5317 if (ch->ch_startc != ch->ch_fepstartc ||
5318 ch->ch_stopc != ch->ch_fepstopc) {
5319 ch->ch_fepstartc = ch->ch_startc;
5320 ch->ch_fepstopc = ch->ch_stopc;
5322 /* Okay to have channel and board locks held calling this */
5323 dgap_cmdb(ch, SFLOWC, ch->ch_fepstartc, ch->ch_fepstopc, 0);
5327 * Set the Auxiliary start and stop characters.
5329 if (ch->ch_astartc != ch->ch_fepastartc ||
5330 ch->ch_astopc != ch->ch_fepastopc) {
5331 ch->ch_fepastartc = ch->ch_astartc;
5332 ch->ch_fepastopc = ch->ch_astopc;
5334 /* Okay to have channel and board locks held calling this */
5335 dgap_cmdb(ch, SAFLOWC, ch->ch_fepastartc, ch->ch_fepastopc, 0);
5342 * dgap_parity_scan()
5344 * Convert the FEP5 way of reporting parity errors and breaks into
5345 * the Linux line discipline way.
5347 static void dgap_parity_scan(struct channel_t *ch, unsigned char *cbuf,
5348 unsigned char *fbuf, int *len)
5352 unsigned char *in, *cout, *fout;
5359 if (!ch || ch->magic != DGAP_CHANNEL_MAGIC)
5364 switch (ch->pscan_state) {
5366 /* reset to sanity and fall through */
5367 ch->pscan_state = 0;
5370 /* No FF seen yet */
5371 if (c == (unsigned char) '\377')
5372 /* delete this character from stream */
5373 ch->pscan_state = 1;
5376 *fout++ = TTY_NORMAL;
5383 if (c == (unsigned char) '\377') {
5384 /* doubled ff, transform to single ff */
5386 *fout++ = TTY_NORMAL;
5388 ch->pscan_state = 0;
5390 /* save value examination in next state */
5391 ch->pscan_savechar = c;
5392 ch->pscan_state = 2;
5397 /* third character of ff sequence */
5401 if (ch->pscan_savechar == 0x0) {
5405 *fout++ = TTY_BREAK;
5407 ch->ch_err_parity++;
5408 *fout++ = TTY_PARITY;
5413 ch->pscan_state = 0;
5419 static void dgap_write_wakeup(struct board_t *bd, struct channel_t *ch,
5420 struct un_t *un, u32 mask,
5421 unsigned long *irq_flags1,
5422 unsigned long *irq_flags2)
5424 if (!(un->un_flags & mask))
5427 un->un_flags &= ~mask;
5429 if (!(un->un_flags & UN_ISOPEN))
5432 if ((un->un_tty->flags & (1 << TTY_DO_WRITE_WAKEUP)) &&
5433 un->un_tty->ldisc->ops->write_wakeup) {
5434 spin_unlock_irqrestore(&ch->ch_lock, *irq_flags2);
5435 spin_unlock_irqrestore(&bd->bd_lock, *irq_flags1);
5437 (un->un_tty->ldisc->ops->write_wakeup)(un->un_tty);
5439 spin_lock_irqsave(&bd->bd_lock, *irq_flags1);
5440 spin_lock_irqsave(&ch->ch_lock, *irq_flags2);
5442 wake_up_interruptible(&un->un_tty->write_wait);
5443 wake_up_interruptible(&un->un_flags_wait);
5446 /*=======================================================================
5448 * dgap_event - FEP to host event processing routine.
5450 * bd - Board of current event.
5452 *=======================================================================*/
5453 static int dgap_event(struct board_t *bd)
5455 struct channel_t *ch;
5458 struct bs_t __iomem *bs;
5461 struct ev_t __iomem *eaddr;
5469 if (!bd || bd->magic != DGAP_BOARD_MAGIC)
5472 spin_lock_irqsave(&bd->bd_lock, lock_flags);
5474 vaddr = bd->re_map_membase;
5477 spin_unlock_irqrestore(&bd->bd_lock, lock_flags);
5481 eaddr = (struct ev_t __iomem *) (vaddr + EVBUF);
5483 /* Get our head and tail */
5484 head = readw(&(eaddr->ev_head));
5485 tail = readw(&(eaddr->ev_tail));
5488 * Forget it if pointers out of range.
5491 if (head >= EVMAX - EVSTART || tail >= EVMAX - EVSTART ||
5492 (head | tail) & 03) {
5493 /* Let go of board lock */
5494 spin_unlock_irqrestore(&bd->bd_lock, lock_flags);
5499 * Loop to process all the events in the buffer.
5501 while (tail != head) {
5504 * Get interrupt information.
5507 event = bd->re_map_membase + tail + EVSTART;
5515 * Make sure the interrupt is valid.
5517 if (port >= bd->nasync)
5520 if (!(reason & (IFMODEM | IFBREAK | IFTLW | IFTEM | IFDATA)))
5523 ch = bd->channels[port];
5525 if (!ch || ch->magic != DGAP_CHANNEL_MAGIC)
5529 * If we have made it here, the event was valid.
5530 * Lock down the channel.
5532 spin_lock_irqsave(&ch->ch_lock, lock_flags2);
5537 spin_unlock_irqrestore(&ch->ch_lock, lock_flags2);
5542 * Process received data.
5544 if (reason & IFDATA) {
5547 * ALL LOCKS *MUST* BE DROPPED BEFORE CALLING INPUT!
5548 * input could send some data to ld, which in turn
5549 * could do a callback to one of our other functions.
5551 spin_unlock_irqrestore(&ch->ch_lock, lock_flags2);
5552 spin_unlock_irqrestore(&bd->bd_lock, lock_flags);
5556 spin_lock_irqsave(&bd->bd_lock, lock_flags);
5557 spin_lock_irqsave(&ch->ch_lock, lock_flags2);
5559 if (ch->ch_flags & CH_RACTIVE)
5560 ch->ch_flags |= CH_RENABLE;
5562 writeb(1, &(bs->idata));
5564 if (ch->ch_flags & CH_RWAIT) {
5565 ch->ch_flags &= ~CH_RWAIT;
5567 wake_up_interruptible
5568 (&ch->ch_tun.un_flags_wait);
5573 * Process Modem change signals.
5575 if (reason & IFMODEM) {
5576 ch->ch_mistat = modem;
5583 if (reason & IFBREAK) {
5585 if (ch->ch_tun.un_tty) {
5586 /* A break has been indicated */
5588 tty_buffer_request_room
5589 (ch->ch_tun.un_tty->port, 1);
5590 tty_insert_flip_char(ch->ch_tun.un_tty->port,
5592 tty_flip_buffer_push(ch->ch_tun.un_tty->port);
5597 * Process Transmit low.
5599 if (reason & IFTLW) {
5600 dgap_write_wakeup(bd, ch, &ch->ch_tun, UN_LOW,
5601 &lock_flags, &lock_flags2);
5602 dgap_write_wakeup(bd, ch, &ch->ch_pun, UN_LOW,
5603 &lock_flags, &lock_flags2);
5604 if (ch->ch_flags & CH_WLOW) {
5605 ch->ch_flags &= ~CH_WLOW;
5606 wake_up_interruptible(&ch->ch_flags_wait);
5611 * Process Transmit empty.
5613 if (reason & IFTEM) {
5614 dgap_write_wakeup(bd, ch, &ch->ch_tun, UN_EMPTY,
5615 &lock_flags, &lock_flags2);
5616 dgap_write_wakeup(bd, ch, &ch->ch_pun, UN_EMPTY,
5617 &lock_flags, &lock_flags2);
5618 if (ch->ch_flags & CH_WEMPTY) {
5619 ch->ch_flags &= ~CH_WEMPTY;
5620 wake_up_interruptible(&ch->ch_flags_wait);
5624 spin_unlock_irqrestore(&ch->ch_lock, lock_flags2);
5627 tail = (tail + 4) & (EVMAX - EVSTART - 4);
5630 writew(tail, &(eaddr->ev_tail));
5631 spin_unlock_irqrestore(&bd->bd_lock, lock_flags);
5636 static ssize_t dgap_driver_version_show(struct device_driver *ddp, char *buf)
5638 return snprintf(buf, PAGE_SIZE, "%s\n", DG_PART);
5640 static DRIVER_ATTR(version, S_IRUSR, dgap_driver_version_show, NULL);
5643 static ssize_t dgap_driver_boards_show(struct device_driver *ddp, char *buf)
5645 return snprintf(buf, PAGE_SIZE, "%d\n", dgap_numboards);
5647 static DRIVER_ATTR(boards, S_IRUSR, dgap_driver_boards_show, NULL);
5650 static ssize_t dgap_driver_maxboards_show(struct device_driver *ddp, char *buf)
5652 return snprintf(buf, PAGE_SIZE, "%d\n", MAXBOARDS);
5654 static DRIVER_ATTR(maxboards, S_IRUSR, dgap_driver_maxboards_show, NULL);
5657 static ssize_t dgap_driver_pollcounter_show(struct device_driver *ddp,
5660 return snprintf(buf, PAGE_SIZE, "%ld\n", dgap_poll_counter);
5662 static DRIVER_ATTR(pollcounter, S_IRUSR, dgap_driver_pollcounter_show, NULL);
5664 static ssize_t dgap_driver_pollrate_show(struct device_driver *ddp, char *buf)
5666 return snprintf(buf, PAGE_SIZE, "%dms\n", dgap_poll_tick);
5669 static ssize_t dgap_driver_pollrate_store(struct device_driver *ddp,
5670 const char *buf, size_t count)
5672 if (sscanf(buf, "%d\n", &dgap_poll_tick) != 1)
5676 static DRIVER_ATTR(pollrate, (S_IRUSR | S_IWUSR), dgap_driver_pollrate_show,
5677 dgap_driver_pollrate_store);
5679 static int dgap_create_driver_sysfiles(struct pci_driver *dgap_driver)
5682 struct device_driver *driverfs = &dgap_driver->driver;
5684 rc |= driver_create_file(driverfs, &driver_attr_version);
5685 rc |= driver_create_file(driverfs, &driver_attr_boards);
5686 rc |= driver_create_file(driverfs, &driver_attr_maxboards);
5687 rc |= driver_create_file(driverfs, &driver_attr_pollrate);
5688 rc |= driver_create_file(driverfs, &driver_attr_pollcounter);
5693 static void dgap_remove_driver_sysfiles(struct pci_driver *dgap_driver)
5695 struct device_driver *driverfs = &dgap_driver->driver;
5696 driver_remove_file(driverfs, &driver_attr_version);
5697 driver_remove_file(driverfs, &driver_attr_boards);
5698 driver_remove_file(driverfs, &driver_attr_maxboards);
5699 driver_remove_file(driverfs, &driver_attr_pollrate);
5700 driver_remove_file(driverfs, &driver_attr_pollcounter);
5703 static struct board_t *dgap_verify_board(struct device *p)
5710 bd = dev_get_drvdata(p);
5711 if (!bd || bd->magic != DGAP_BOARD_MAGIC || bd->state != BOARD_READY)
5717 static ssize_t dgap_ports_state_show(struct device *p,
5718 struct device_attribute *attr,
5725 bd = dgap_verify_board(p);
5729 for (i = 0; i < bd->nasync; i++) {
5730 count += snprintf(buf + count, PAGE_SIZE - count,
5731 "%d %s\n", bd->channels[i]->ch_portnum,
5732 bd->channels[i]->ch_open_count ? "Open" : "Closed");
5736 static DEVICE_ATTR(ports_state, S_IRUSR, dgap_ports_state_show, NULL);
5738 static ssize_t dgap_ports_baud_show(struct device *p,
5739 struct device_attribute *attr,
5746 bd = dgap_verify_board(p);
5750 for (i = 0; i < bd->nasync; i++) {
5751 count += snprintf(buf + count, PAGE_SIZE - count, "%d %d\n",
5752 bd->channels[i]->ch_portnum,
5753 bd->channels[i]->ch_baud_info);
5757 static DEVICE_ATTR(ports_baud, S_IRUSR, dgap_ports_baud_show, NULL);
5759 static ssize_t dgap_ports_msignals_show(struct device *p,
5760 struct device_attribute *attr,
5767 bd = dgap_verify_board(p);
5771 for (i = 0; i < bd->nasync; i++) {
5772 if (bd->channels[i]->ch_open_count)
5773 count += snprintf(buf + count, PAGE_SIZE - count,
5774 "%d %s %s %s %s %s %s\n",
5775 bd->channels[i]->ch_portnum,
5776 (bd->channels[i]->ch_mostat &
5777 UART_MCR_RTS) ? "RTS" : "",
5778 (bd->channels[i]->ch_mistat &
5779 UART_MSR_CTS) ? "CTS" : "",
5780 (bd->channels[i]->ch_mostat &
5781 UART_MCR_DTR) ? "DTR" : "",
5782 (bd->channels[i]->ch_mistat &
5783 UART_MSR_DSR) ? "DSR" : "",
5784 (bd->channels[i]->ch_mistat &
5785 UART_MSR_DCD) ? "DCD" : "",
5786 (bd->channels[i]->ch_mistat &
5787 UART_MSR_RI) ? "RI" : "");
5789 count += snprintf(buf + count, PAGE_SIZE - count,
5790 "%d\n", bd->channels[i]->ch_portnum);
5794 static DEVICE_ATTR(ports_msignals, S_IRUSR, dgap_ports_msignals_show, NULL);
5796 static ssize_t dgap_ports_iflag_show(struct device *p,
5797 struct device_attribute *attr,
5804 bd = dgap_verify_board(p);
5808 for (i = 0; i < bd->nasync; i++)
5809 count += snprintf(buf + count, PAGE_SIZE - count, "%d %x\n",
5810 bd->channels[i]->ch_portnum,
5811 bd->channels[i]->ch_c_iflag);
5814 static DEVICE_ATTR(ports_iflag, S_IRUSR, dgap_ports_iflag_show, NULL);
5816 static ssize_t dgap_ports_cflag_show(struct device *p,
5817 struct device_attribute *attr,
5824 bd = dgap_verify_board(p);
5828 for (i = 0; i < bd->nasync; i++)
5829 count += snprintf(buf + count, PAGE_SIZE - count, "%d %x\n",
5830 bd->channels[i]->ch_portnum,
5831 bd->channels[i]->ch_c_cflag);
5834 static DEVICE_ATTR(ports_cflag, S_IRUSR, dgap_ports_cflag_show, NULL);
5836 static ssize_t dgap_ports_oflag_show(struct device *p,
5837 struct device_attribute *attr,
5844 bd = dgap_verify_board(p);
5848 for (i = 0; i < bd->nasync; i++)
5849 count += snprintf(buf + count, PAGE_SIZE - count, "%d %x\n",
5850 bd->channels[i]->ch_portnum,
5851 bd->channels[i]->ch_c_oflag);
5854 static DEVICE_ATTR(ports_oflag, S_IRUSR, dgap_ports_oflag_show, NULL);
5856 static ssize_t dgap_ports_lflag_show(struct device *p,
5857 struct device_attribute *attr,
5864 bd = dgap_verify_board(p);
5868 for (i = 0; i < bd->nasync; i++)
5869 count += snprintf(buf + count, PAGE_SIZE - count, "%d %x\n",
5870 bd->channels[i]->ch_portnum,
5871 bd->channels[i]->ch_c_lflag);
5874 static DEVICE_ATTR(ports_lflag, S_IRUSR, dgap_ports_lflag_show, NULL);
5876 static ssize_t dgap_ports_digi_flag_show(struct device *p,
5877 struct device_attribute *attr,
5884 bd = dgap_verify_board(p);
5888 for (i = 0; i < bd->nasync; i++)
5889 count += snprintf(buf + count, PAGE_SIZE - count, "%d %x\n",
5890 bd->channels[i]->ch_portnum,
5891 bd->channels[i]->ch_digi.digi_flags);
5894 static DEVICE_ATTR(ports_digi_flag, S_IRUSR, dgap_ports_digi_flag_show, NULL);
5896 static ssize_t dgap_ports_rxcount_show(struct device *p,
5897 struct device_attribute *attr,
5904 bd = dgap_verify_board(p);
5908 for (i = 0; i < bd->nasync; i++)
5909 count += snprintf(buf + count, PAGE_SIZE - count, "%d %ld\n",
5910 bd->channels[i]->ch_portnum,
5911 bd->channels[i]->ch_rxcount);
5914 static DEVICE_ATTR(ports_rxcount, S_IRUSR, dgap_ports_rxcount_show, NULL);
5916 static ssize_t dgap_ports_txcount_show(struct device *p,
5917 struct device_attribute *attr,
5924 bd = dgap_verify_board(p);
5928 for (i = 0; i < bd->nasync; i++)
5929 count += snprintf(buf + count, PAGE_SIZE - count, "%d %ld\n",
5930 bd->channels[i]->ch_portnum,
5931 bd->channels[i]->ch_txcount);
5934 static DEVICE_ATTR(ports_txcount, S_IRUSR, dgap_ports_txcount_show, NULL);
5936 /* this function creates the sys files that will export each signal status
5937 * to sysfs each value will be put in a separate filename
5939 static void dgap_create_ports_sysfiles(struct board_t *bd)
5941 dev_set_drvdata(&bd->pdev->dev, bd);
5942 device_create_file(&(bd->pdev->dev), &dev_attr_ports_state);
5943 device_create_file(&(bd->pdev->dev), &dev_attr_ports_baud);
5944 device_create_file(&(bd->pdev->dev), &dev_attr_ports_msignals);
5945 device_create_file(&(bd->pdev->dev), &dev_attr_ports_iflag);
5946 device_create_file(&(bd->pdev->dev), &dev_attr_ports_cflag);
5947 device_create_file(&(bd->pdev->dev), &dev_attr_ports_oflag);
5948 device_create_file(&(bd->pdev->dev), &dev_attr_ports_lflag);
5949 device_create_file(&(bd->pdev->dev), &dev_attr_ports_digi_flag);
5950 device_create_file(&(bd->pdev->dev), &dev_attr_ports_rxcount);
5951 device_create_file(&(bd->pdev->dev), &dev_attr_ports_txcount);
5954 /* removes all the sys files created for that port */
5955 static void dgap_remove_ports_sysfiles(struct board_t *bd)
5957 device_remove_file(&(bd->pdev->dev), &dev_attr_ports_state);
5958 device_remove_file(&(bd->pdev->dev), &dev_attr_ports_baud);
5959 device_remove_file(&(bd->pdev->dev), &dev_attr_ports_msignals);
5960 device_remove_file(&(bd->pdev->dev), &dev_attr_ports_iflag);
5961 device_remove_file(&(bd->pdev->dev), &dev_attr_ports_cflag);
5962 device_remove_file(&(bd->pdev->dev), &dev_attr_ports_oflag);
5963 device_remove_file(&(bd->pdev->dev), &dev_attr_ports_lflag);
5964 device_remove_file(&(bd->pdev->dev), &dev_attr_ports_digi_flag);
5965 device_remove_file(&(bd->pdev->dev), &dev_attr_ports_rxcount);
5966 device_remove_file(&(bd->pdev->dev), &dev_attr_ports_txcount);
5969 static ssize_t dgap_tty_state_show(struct device *d,
5970 struct device_attribute *attr,
5974 struct channel_t *ch;
5979 un = dev_get_drvdata(d);
5980 if (!un || un->magic != DGAP_UNIT_MAGIC)
5983 if (!ch || ch->magic != DGAP_CHANNEL_MAGIC)
5986 if (!bd || bd->magic != DGAP_BOARD_MAGIC)
5988 if (bd->state != BOARD_READY)
5991 return snprintf(buf, PAGE_SIZE, "%s", un->un_open_count ?
5994 static DEVICE_ATTR(state, S_IRUSR, dgap_tty_state_show, NULL);
5996 static ssize_t dgap_tty_baud_show(struct device *d,
5997 struct device_attribute *attr,
6001 struct channel_t *ch;
6006 un = dev_get_drvdata(d);
6007 if (!un || un->magic != DGAP_UNIT_MAGIC)
6010 if (!ch || ch->magic != DGAP_CHANNEL_MAGIC)
6013 if (!bd || bd->magic != DGAP_BOARD_MAGIC)
6015 if (bd->state != BOARD_READY)
6018 return snprintf(buf, PAGE_SIZE, "%d\n", ch->ch_baud_info);
6020 static DEVICE_ATTR(baud, S_IRUSR, dgap_tty_baud_show, NULL);
6022 static ssize_t dgap_tty_msignals_show(struct device *d,
6023 struct device_attribute *attr,
6027 struct channel_t *ch;
6032 un = dev_get_drvdata(d);
6033 if (!un || un->magic != DGAP_UNIT_MAGIC)
6036 if (!ch || ch->magic != DGAP_CHANNEL_MAGIC)
6039 if (!bd || bd->magic != DGAP_BOARD_MAGIC)
6041 if (bd->state != BOARD_READY)
6044 if (ch->ch_open_count) {
6045 return snprintf(buf, PAGE_SIZE, "%s %s %s %s %s %s\n",
6046 (ch->ch_mostat & UART_MCR_RTS) ? "RTS" : "",
6047 (ch->ch_mistat & UART_MSR_CTS) ? "CTS" : "",
6048 (ch->ch_mostat & UART_MCR_DTR) ? "DTR" : "",
6049 (ch->ch_mistat & UART_MSR_DSR) ? "DSR" : "",
6050 (ch->ch_mistat & UART_MSR_DCD) ? "DCD" : "",
6051 (ch->ch_mistat & UART_MSR_RI) ? "RI" : "");
6055 static DEVICE_ATTR(msignals, S_IRUSR, dgap_tty_msignals_show, NULL);
6057 static ssize_t dgap_tty_iflag_show(struct device *d,
6058 struct device_attribute *attr,
6062 struct channel_t *ch;
6067 un = dev_get_drvdata(d);
6068 if (!un || un->magic != DGAP_UNIT_MAGIC)
6071 if (!ch || ch->magic != DGAP_CHANNEL_MAGIC)
6074 if (!bd || bd->magic != DGAP_BOARD_MAGIC)
6076 if (bd->state != BOARD_READY)
6079 return snprintf(buf, PAGE_SIZE, "%x\n", ch->ch_c_iflag);
6081 static DEVICE_ATTR(iflag, S_IRUSR, dgap_tty_iflag_show, NULL);
6083 static ssize_t dgap_tty_cflag_show(struct device *d,
6084 struct device_attribute *attr,
6088 struct channel_t *ch;
6093 un = dev_get_drvdata(d);
6094 if (!un || un->magic != DGAP_UNIT_MAGIC)
6097 if (!ch || ch->magic != DGAP_CHANNEL_MAGIC)
6100 if (!bd || bd->magic != DGAP_BOARD_MAGIC)
6102 if (bd->state != BOARD_READY)
6105 return snprintf(buf, PAGE_SIZE, "%x\n", ch->ch_c_cflag);
6107 static DEVICE_ATTR(cflag, S_IRUSR, dgap_tty_cflag_show, NULL);
6109 static ssize_t dgap_tty_oflag_show(struct device *d,
6110 struct device_attribute *attr,
6114 struct channel_t *ch;
6119 un = dev_get_drvdata(d);
6120 if (!un || un->magic != DGAP_UNIT_MAGIC)
6123 if (!ch || ch->magic != DGAP_CHANNEL_MAGIC)
6126 if (!bd || bd->magic != DGAP_BOARD_MAGIC)
6128 if (bd->state != BOARD_READY)
6131 return snprintf(buf, PAGE_SIZE, "%x\n", ch->ch_c_oflag);
6133 static DEVICE_ATTR(oflag, S_IRUSR, dgap_tty_oflag_show, NULL);
6135 static ssize_t dgap_tty_lflag_show(struct device *d,
6136 struct device_attribute *attr,
6140 struct channel_t *ch;
6145 un = dev_get_drvdata(d);
6146 if (!un || un->magic != DGAP_UNIT_MAGIC)
6149 if (!ch || ch->magic != DGAP_CHANNEL_MAGIC)
6152 if (!bd || bd->magic != DGAP_BOARD_MAGIC)
6154 if (bd->state != BOARD_READY)
6157 return snprintf(buf, PAGE_SIZE, "%x\n", ch->ch_c_lflag);
6159 static DEVICE_ATTR(lflag, S_IRUSR, dgap_tty_lflag_show, NULL);
6161 static ssize_t dgap_tty_digi_flag_show(struct device *d,
6162 struct device_attribute *attr,
6166 struct channel_t *ch;
6171 un = dev_get_drvdata(d);
6172 if (!un || un->magic != DGAP_UNIT_MAGIC)
6175 if (!ch || ch->magic != DGAP_CHANNEL_MAGIC)
6178 if (!bd || bd->magic != DGAP_BOARD_MAGIC)
6180 if (bd->state != BOARD_READY)
6183 return snprintf(buf, PAGE_SIZE, "%x\n", ch->ch_digi.digi_flags);
6185 static DEVICE_ATTR(digi_flag, S_IRUSR, dgap_tty_digi_flag_show, NULL);
6187 static ssize_t dgap_tty_rxcount_show(struct device *d,
6188 struct device_attribute *attr,
6192 struct channel_t *ch;
6197 un = dev_get_drvdata(d);
6198 if (!un || un->magic != DGAP_UNIT_MAGIC)
6201 if (!ch || ch->magic != DGAP_CHANNEL_MAGIC)
6204 if (!bd || bd->magic != DGAP_BOARD_MAGIC)
6206 if (bd->state != BOARD_READY)
6209 return snprintf(buf, PAGE_SIZE, "%ld\n", ch->ch_rxcount);
6211 static DEVICE_ATTR(rxcount, S_IRUSR, dgap_tty_rxcount_show, NULL);
6213 static ssize_t dgap_tty_txcount_show(struct device *d,
6214 struct device_attribute *attr,
6218 struct channel_t *ch;
6223 un = dev_get_drvdata(d);
6224 if (!un || un->magic != DGAP_UNIT_MAGIC)
6227 if (!ch || ch->magic != DGAP_CHANNEL_MAGIC)
6230 if (!bd || bd->magic != DGAP_BOARD_MAGIC)
6232 if (bd->state != BOARD_READY)
6235 return snprintf(buf, PAGE_SIZE, "%ld\n", ch->ch_txcount);
6237 static DEVICE_ATTR(txcount, S_IRUSR, dgap_tty_txcount_show, NULL);
6239 static ssize_t dgap_tty_name_show(struct device *d,
6240 struct device_attribute *attr,
6244 struct channel_t *ch;
6256 un = dev_get_drvdata(d);
6257 if (!un || un->magic != DGAP_UNIT_MAGIC)
6260 if (!ch || ch->magic != DGAP_CHANNEL_MAGIC)
6263 if (!bd || bd->magic != DGAP_BOARD_MAGIC)
6265 if (bd->state != BOARD_READY)
6269 cn = ch->ch_portnum;
6271 for (cptr = bd->bd_config; cptr; cptr = cptr->next) {
6273 if ((cptr->type == BNODE) &&
6274 ((cptr->u.board.type == APORT2_920P) ||
6275 (cptr->u.board.type == APORT4_920P) ||
6276 (cptr->u.board.type == APORT8_920P) ||
6277 (cptr->u.board.type == PAPORT4) ||
6278 (cptr->u.board.type == PAPORT8))) {
6281 if (cptr->u.board.v_start)
6282 starto = cptr->u.board.start;
6287 if (cptr->type == TNODE && found == TRUE) {
6289 if (strstr(cptr->u.ttyname, "tty")) {
6290 ptr1 = cptr->u.ttyname;
6293 ptr1 = cptr->u.ttyname;
6295 for (i = 0; i < dgap_config_get_num_prts(bd); i++) {
6299 return snprintf(buf, PAGE_SIZE, "%s%s%02d\n",
6300 (un->un_type == DGAP_PRINT) ?
6306 if (cptr->type == CNODE) {
6308 for (i = 0; i < cptr->u.conc.nport; i++) {
6309 if (cn != (i + ncount))
6312 return snprintf(buf, PAGE_SIZE, "%s%s%02ld\n",
6313 (un->un_type == DGAP_PRINT) ?
6316 i + (cptr->u.conc.v_start ?
6317 cptr->u.conc.start : 1));
6320 ncount += cptr->u.conc.nport;
6323 if (cptr->type == MNODE) {
6325 for (i = 0; i < cptr->u.module.nport; i++) {
6326 if (cn != (i + ncount))
6329 return snprintf(buf, PAGE_SIZE, "%s%s%02ld\n",
6330 (un->un_type == DGAP_PRINT) ?
6333 i + (cptr->u.module.v_start ?
6334 cptr->u.module.start : 1));
6337 ncount += cptr->u.module.nport;
6342 return snprintf(buf, PAGE_SIZE, "%s_dgap_%d_%d\n",
6343 (un->un_type == DGAP_PRINT) ? "pr" : "tty", bn, cn);
6345 static DEVICE_ATTR(custom_name, S_IRUSR, dgap_tty_name_show, NULL);
6347 static struct attribute *dgap_sysfs_tty_entries[] = {
6348 &dev_attr_state.attr,
6349 &dev_attr_baud.attr,
6350 &dev_attr_msignals.attr,
6351 &dev_attr_iflag.attr,
6352 &dev_attr_cflag.attr,
6353 &dev_attr_oflag.attr,
6354 &dev_attr_lflag.attr,
6355 &dev_attr_digi_flag.attr,
6356 &dev_attr_rxcount.attr,
6357 &dev_attr_txcount.attr,
6358 &dev_attr_custom_name.attr,
6362 static struct attribute_group dgap_tty_attribute_group = {
6364 .attrs = dgap_sysfs_tty_entries,
6367 static void dgap_create_tty_sysfs(struct un_t *un, struct device *c)
6371 ret = sysfs_create_group(&c->kobj, &dgap_tty_attribute_group);
6375 dev_set_drvdata(c, un);
6379 static void dgap_remove_tty_sysfs(struct device *c)
6381 sysfs_remove_group(&c->kobj, &dgap_tty_attribute_group);
6385 * Parse a configuration file read into memory as a string.
6387 static int dgap_parsefile(char **in, int remove)
6389 struct cnode *p, *brd, *line, *conc;
6395 brd = line = conc = NULL;
6397 /* perhaps we are adding to an existing list? */
6401 /* file must start with a BEGIN */
6402 while ((rc = dgap_gettok(in, p)) != BEGIN) {
6404 dgap_err("unexpected EOF");
6410 rc = dgap_gettok(in, p);
6412 dgap_err("unexpected EOF");
6418 dgap_err("unexpected end of file");
6421 case BEGIN: /* should only be 1 begin */
6422 dgap_err("unexpected config_begin\n");
6428 case BOARD: /* board info */
6429 if (dgap_checknode(p))
6431 p->next = dgap_newnode(BNODE);
6433 dgap_err("out of memory");
6438 p->u.board.status = kstrdup("No", GFP_KERNEL);
6444 case APORT2_920P: /* AccelePort_4 */
6445 if (p->type != BNODE) {
6446 dgap_err("unexpected Digi_2r_920 string");
6449 p->u.board.type = APORT2_920P;
6450 p->u.board.v_type = 1;
6453 case APORT4_920P: /* AccelePort_4 */
6454 if (p->type != BNODE) {
6455 dgap_err("unexpected Digi_4r_920 string");
6458 p->u.board.type = APORT4_920P;
6459 p->u.board.v_type = 1;
6462 case APORT8_920P: /* AccelePort_8 */
6463 if (p->type != BNODE) {
6464 dgap_err("unexpected Digi_8r_920 string");
6467 p->u.board.type = APORT8_920P;
6468 p->u.board.v_type = 1;
6471 case PAPORT4: /* AccelePort_4 PCI */
6472 if (p->type != BNODE) {
6473 dgap_err("unexpected Digi_4r(PCI) string");
6476 p->u.board.type = PAPORT4;
6477 p->u.board.v_type = 1;
6480 case PAPORT8: /* AccelePort_8 PCI */
6481 if (p->type != BNODE) {
6482 dgap_err("unexpected Digi_8r string");
6485 p->u.board.type = PAPORT8;
6486 p->u.board.v_type = 1;
6489 case PCX: /* PCI C/X */
6490 if (p->type != BNODE) {
6491 dgap_err("unexpected Digi_C/X_(PCI) string");
6494 p->u.board.type = PCX;
6495 p->u.board.v_type = 1;
6496 p->u.board.conc1 = 0;
6497 p->u.board.conc2 = 0;
6498 p->u.board.module1 = 0;
6499 p->u.board.module2 = 0;
6502 case PEPC: /* PCI EPC/X */
6503 if (p->type != BNODE) {
6504 dgap_err("unexpected \"Digi_EPC/X_(PCI)\" string");
6507 p->u.board.type = PEPC;
6508 p->u.board.v_type = 1;
6509 p->u.board.conc1 = 0;
6510 p->u.board.conc2 = 0;
6511 p->u.board.module1 = 0;
6512 p->u.board.module2 = 0;
6515 case PPCM: /* PCI/Xem */
6516 if (p->type != BNODE) {
6517 dgap_err("unexpected PCI/Xem string");
6520 p->u.board.type = PPCM;
6521 p->u.board.v_type = 1;
6522 p->u.board.conc1 = 0;
6523 p->u.board.conc2 = 0;
6526 case IO: /* i/o port */
6527 if (p->type != BNODE) {
6528 dgap_err("IO port only vaild for boards");
6531 s = dgap_getword(in);
6533 dgap_err("unexpected end of file");
6536 p->u.board.portstr = kstrdup(s, GFP_KERNEL);
6537 if (kstrtol(s, 0, &p->u.board.port)) {
6538 dgap_err("bad number for IO port");
6541 p->u.board.v_port = 1;
6544 case MEM: /* memory address */
6545 if (p->type != BNODE) {
6546 dgap_err("memory address only vaild for boards");
6549 s = dgap_getword(in);
6551 dgap_err("unexpected end of file");
6554 p->u.board.addrstr = kstrdup(s, GFP_KERNEL);
6555 if (kstrtoul(s, 0, &p->u.board.addr)) {
6556 dgap_err("bad number for memory address");
6559 p->u.board.v_addr = 1;
6562 case PCIINFO: /* pci information */
6563 if (p->type != BNODE) {
6564 dgap_err("memory address only vaild for boards");
6567 s = dgap_getword(in);
6569 dgap_err("unexpected end of file");
6572 p->u.board.pcibusstr = kstrdup(s, GFP_KERNEL);
6573 if (kstrtoul(s, 0, &p->u.board.pcibus)) {
6574 dgap_err("bad number for pci bus");
6577 p->u.board.v_pcibus = 1;
6578 s = dgap_getword(in);
6580 dgap_err("unexpected end of file");
6583 p->u.board.pcislotstr = kstrdup(s, GFP_KERNEL);
6584 if (kstrtoul(s, 0, &p->u.board.pcislot)) {
6585 dgap_err("bad number for pci slot");
6588 p->u.board.v_pcislot = 1;
6592 if (p->type != BNODE) {
6593 dgap_err("install method only vaild for boards");
6596 s = dgap_getword(in);
6598 dgap_err("unexpected end of file");
6601 p->u.board.method = kstrdup(s, GFP_KERNEL);
6602 p->u.board.v_method = 1;
6606 if (p->type != BNODE) {
6607 dgap_err("config status only vaild for boards");
6610 s = dgap_getword(in);
6612 dgap_err("unexpected end of file");
6615 p->u.board.status = kstrdup(s, GFP_KERNEL);
6618 case NPORTS: /* number of ports */
6619 if (p->type == BNODE) {
6620 s = dgap_getword(in);
6622 dgap_err("unexpected end of file");
6625 if (kstrtol(s, 0, &p->u.board.nport)) {
6626 dgap_err("bad number for number of ports");
6629 p->u.board.v_nport = 1;
6630 } else if (p->type == CNODE) {
6631 s = dgap_getword(in);
6633 dgap_err("unexpected end of file");
6636 if (kstrtol(s, 0, &p->u.conc.nport)) {
6637 dgap_err("bad number for number of ports");
6640 p->u.conc.v_nport = 1;
6641 } else if (p->type == MNODE) {
6642 s = dgap_getword(in);
6644 dgap_err("unexpected end of file");
6647 if (kstrtol(s, 0, &p->u.module.nport)) {
6648 dgap_err("bad number for number of ports");
6651 p->u.module.v_nport = 1;
6653 dgap_err("nports only valid for concentrators or modules");
6658 case ID: /* letter ID used in tty name */
6659 s = dgap_getword(in);
6661 dgap_err("unexpected end of file");
6665 p->u.board.status = kstrdup(s, GFP_KERNEL);
6667 if (p->type == CNODE) {
6668 p->u.conc.id = kstrdup(s, GFP_KERNEL);
6670 } else if (p->type == MNODE) {
6671 p->u.module.id = kstrdup(s, GFP_KERNEL);
6672 p->u.module.v_id = 1;
6674 dgap_err("id only valid for concentrators or modules");
6679 case STARTO: /* start offset of ID */
6680 if (p->type == BNODE) {
6681 s = dgap_getword(in);
6683 dgap_err("unexpected end of file");
6686 if (kstrtol(s, 0, &p->u.board.start)) {
6687 dgap_err("bad number for start of tty count");
6690 p->u.board.v_start = 1;
6691 } else if (p->type == CNODE) {
6692 s = dgap_getword(in);
6694 dgap_err("unexpected end of file");
6697 if (kstrtol(s, 0, &p->u.conc.start)) {
6698 dgap_err("bad number for start of tty count");
6701 p->u.conc.v_start = 1;
6702 } else if (p->type == MNODE) {
6703 s = dgap_getword(in);
6705 dgap_err("unexpected end of file");
6708 if (kstrtol(s, 0, &p->u.module.start)) {
6709 dgap_err("bad number for start of tty count");
6712 p->u.module.v_start = 1;
6714 dgap_err("start only valid for concentrators or modules");
6719 case TTYN: /* tty name prefix */
6720 if (dgap_checknode(p))
6722 p->next = dgap_newnode(TNODE);
6724 dgap_err("out of memory");
6728 s = dgap_getword(in);
6730 dgap_err("unexpeced end of file");
6733 p->u.ttyname = kstrdup(s, GFP_KERNEL);
6734 if (!p->u.ttyname) {
6735 dgap_err("out of memory");
6740 case CU: /* cu name prefix */
6741 if (dgap_checknode(p))
6743 p->next = dgap_newnode(CUNODE);
6745 dgap_err("out of memory");
6749 s = dgap_getword(in);
6751 dgap_err("unexpeced end of file");
6754 p->u.cuname = kstrdup(s, GFP_KERNEL);
6756 dgap_err("out of memory");
6761 case LINE: /* line information */
6762 if (dgap_checknode(p))
6765 dgap_err("must specify board before line info");
6768 switch (brd->u.board.type) {
6770 dgap_err("line not vaild for PC/em");
6773 p->next = dgap_newnode(LNODE);
6775 dgap_err("out of memory");
6784 case CONC: /* concentrator information */
6785 if (dgap_checknode(p))
6788 dgap_err("must specify line info before concentrator");
6791 p->next = dgap_newnode(CNODE);
6793 dgap_err("out of memory");
6799 brd->u.board.conc2++;
6801 brd->u.board.conc1++;
6805 case CX: /* c/x type concentrator */
6806 if (p->type != CNODE) {
6807 dgap_err("cx only valid for concentrators");
6810 p->u.conc.type = CX;
6811 p->u.conc.v_type = 1;
6814 case EPC: /* epc type concentrator */
6815 if (p->type != CNODE) {
6816 dgap_err("cx only valid for concentrators");
6819 p->u.conc.type = EPC;
6820 p->u.conc.v_type = 1;
6823 case MOD: /* EBI module */
6824 if (dgap_checknode(p))
6827 dgap_err("must specify board info before EBI modules");
6830 switch (brd->u.board.type) {
6836 dgap_err("must specify concentrator info before EBI module");
6840 p->next = dgap_newnode(MNODE);
6842 dgap_err("out of memory");
6847 brd->u.board.module2++;
6849 brd->u.board.module1++;
6853 case PORTS: /* ports type EBI module */
6854 if (p->type != MNODE) {
6855 dgap_err("ports only valid for EBI modules");
6858 p->u.module.type = PORTS;
6859 p->u.module.v_type = 1;
6862 case MODEM: /* ports type EBI module */
6863 if (p->type != MNODE) {
6864 dgap_err("modem only valid for modem modules");
6867 p->u.module.type = MODEM;
6868 p->u.module.v_type = 1;
6872 if (p->type == LNODE) {
6873 s = dgap_getword(in);
6875 dgap_err("unexpected end of file");
6878 p->u.line.cable = kstrdup(s, GFP_KERNEL);
6879 p->u.line.v_cable = 1;
6883 case SPEED: /* sync line speed indication */
6884 if (p->type == LNODE) {
6885 s = dgap_getword(in);
6887 dgap_err("unexpected end of file");
6890 if (kstrtol(s, 0, &p->u.line.speed)) {
6891 dgap_err("bad number for line speed");
6894 p->u.line.v_speed = 1;
6895 } else if (p->type == CNODE) {
6896 s = dgap_getword(in);
6898 dgap_err("unexpected end of file");
6901 if (kstrtol(s, 0, &p->u.conc.speed)) {
6902 dgap_err("bad number for line speed");
6905 p->u.conc.v_speed = 1;
6907 dgap_err("speed valid only for lines or concentrators.");
6913 if (p->type == CNODE) {
6914 s = dgap_getword(in);
6916 dgap_err("unexpected end of file");
6919 p->u.conc.connect = kstrdup(s, GFP_KERNEL);
6920 p->u.conc.v_connect = 1;
6923 case PRINT: /* transparent print name prefix */
6924 if (dgap_checknode(p))
6926 p->next = dgap_newnode(PNODE);
6928 dgap_err("out of memory");
6932 s = dgap_getword(in);
6934 dgap_err("unexpeced end of file");
6937 p->u.printname = kstrdup(s, GFP_KERNEL);
6938 if (!p->u.printname) {
6939 dgap_err("out of memory");
6944 case CMAJOR: /* major number */
6945 if (dgap_checknode(p))
6947 p->next = dgap_newnode(JNODE);
6949 dgap_err("out of memory");
6953 s = dgap_getword(in);
6955 dgap_err("unexpected end of file");
6958 if (kstrtol(s, 0, &p->u.majornumber)) {
6959 dgap_err("bad number for major number");
6964 case ALTPIN: /* altpin setting */
6965 if (dgap_checknode(p))
6967 p->next = dgap_newnode(ANODE);
6969 dgap_err("out of memory");
6973 s = dgap_getword(in);
6975 dgap_err("unexpected end of file");
6978 if (kstrtol(s, 0, &p->u.altpin)) {
6979 dgap_err("bad number for altpin");
6984 case USEINTR: /* enable interrupt setting */
6985 if (dgap_checknode(p))
6987 p->next = dgap_newnode(INTRNODE);
6989 dgap_err("out of memory");
6993 s = dgap_getword(in);
6995 dgap_err("unexpected end of file");
6998 if (kstrtol(s, 0, &p->u.useintr)) {
6999 dgap_err("bad number for useintr");
7004 case TTSIZ: /* size of tty structure */
7005 if (dgap_checknode(p))
7007 p->next = dgap_newnode(TSNODE);
7009 dgap_err("out of memory");
7013 s = dgap_getword(in);
7015 dgap_err("unexpected end of file");
7018 if (kstrtol(s, 0, &p->u.ttysize)) {
7019 dgap_err("bad number for ttysize");
7024 case CHSIZ: /* channel structure size */
7025 if (dgap_checknode(p))
7027 p->next = dgap_newnode(CSNODE);
7029 dgap_err("out of memory");
7033 s = dgap_getword(in);
7035 dgap_err("unexpected end of file");
7038 if (kstrtol(s, 0, &p->u.chsize)) {
7039 dgap_err("bad number for chsize");
7044 case BSSIZ: /* board structure size */
7045 if (dgap_checknode(p))
7047 p->next = dgap_newnode(BSNODE);
7049 dgap_err("out of memory");
7053 s = dgap_getword(in);
7055 dgap_err("unexpected end of file");
7058 if (kstrtol(s, 0, &p->u.bssize)) {
7059 dgap_err("bad number for bssize");
7064 case UNTSIZ: /* sched structure size */
7065 if (dgap_checknode(p))
7067 p->next = dgap_newnode(USNODE);
7069 dgap_err("out of memory");
7073 s = dgap_getword(in);
7075 dgap_err("unexpected end of file");
7078 if (kstrtol(s, 0, &p->u.unsize)) {
7079 dgap_err("bad number for schedsize");
7084 case F2SIZ: /* f2200 structure size */
7085 if (dgap_checknode(p))
7087 p->next = dgap_newnode(FSNODE);
7089 dgap_err("out of memory");
7093 s = dgap_getword(in);
7095 dgap_err("unexpected end of file");
7098 if (kstrtol(s, 0, &p->u.f2size)) {
7099 dgap_err("bad number for f2200size");
7104 case VPSIZ: /* vpix structure size */
7105 if (dgap_checknode(p))
7107 p->next = dgap_newnode(VSNODE);
7109 dgap_err("out of memory");
7113 s = dgap_getword(in);
7115 dgap_err("unexpected end of file");
7118 if (kstrtol(s, 0, &p->u.vpixsize)) {
7119 dgap_err("bad number for vpixsize");
7128 * dgap_sindex: much like index(), but it looks for a match of any character in
7129 * the group, and returns that position. If the first character is a ^, then
7130 * this will match the first occurrence not in that group.
7132 static char *dgap_sindex(char *string, char *group)
7136 if (!string || !group)
7137 return (char *) NULL;
7139 if (*group == '^') {
7141 for (; *string; string++) {
7142 for (ptr = group; *ptr; ptr++) {
7143 if (*ptr == *string)
7150 for (; *string; string++) {
7151 for (ptr = group; *ptr; ptr++) {
7152 if (*ptr == *string)
7158 return (char *) NULL;
7162 * Get a token from the input file; return 0 if end of file is reached
7164 static int dgap_gettok(char **in, struct cnode *p)
7169 if (strstr(dgap_cword, "boar")) {
7170 w = dgap_getword(in);
7171 snprintf(dgap_cword, MAXCWORD, "%s", w);
7172 for (t = dgap_tlist; t->token != 0; t++) {
7173 if (!strcmp(w, t->string))
7176 dgap_err("board !!type not specified");
7179 while ((w = dgap_getword(in))) {
7180 snprintf(dgap_cword, MAXCWORD, "%s", w);
7181 for (t = dgap_tlist; t->token != 0; t++) {
7182 if (!strcmp(w, t->string))
7191 * get a word from the input stream, also keep track of current line number.
7192 * words are separated by whitespace.
7194 static char *dgap_getword(char **in)
7196 char *ret_ptr = *in;
7198 char *ptr = dgap_sindex(*in, " \t\n");
7200 /* If no word found, return null */
7204 /* Mark new location for our buffer */
7208 /* Eat any extra spaces/tabs/newlines that might be present */
7209 while (*in && **in && ((**in == ' ') ||
7220 * print an error message, giving the line number in the file where
7221 * the error occurred.
7223 static void dgap_err(char *s)
7225 pr_err("dgap: parse: %s\n", s);
7229 * allocate a new configuration node of type t
7231 static struct cnode *dgap_newnode(int t)
7235 n = kmalloc(sizeof(struct cnode), GFP_ATOMIC);
7237 memset((char *)n, 0, sizeof(struct cnode));
7244 * dgap_checknode: see if all the necessary info has been supplied for a node
7245 * before creating the next node.
7247 static int dgap_checknode(struct cnode *p)
7251 if (p->u.board.v_type == 0) {
7252 dgap_err("board type !not specified");
7259 if (p->u.line.v_speed == 0) {
7260 dgap_err("line speed not specified");
7266 if (p->u.conc.v_type == 0) {
7267 dgap_err("concentrator type not specified");
7270 if (p->u.conc.v_speed == 0) {
7271 dgap_err("concentrator line speed not specified");
7274 if (p->u.conc.v_nport == 0) {
7275 dgap_err("number of ports on concentrator not specified");
7278 if (p->u.conc.v_id == 0) {
7279 dgap_err("concentrator id letter not specified");
7285 if (p->u.module.v_type == 0) {
7286 dgap_err("EBI module type not specified");
7289 if (p->u.module.v_nport == 0) {
7290 dgap_err("number of ports on EBI module not specified");
7293 if (p->u.module.v_id == 0) {
7294 dgap_err("EBI module id letter not specified");
7303 * Given a board pointer, returns whether we should use interrupts or not.
7305 static uint dgap_config_get_useintr(struct board_t *bd)
7312 for (p = bd->bd_config; p; p = p->next) {
7313 if (p->type == INTRNODE) {
7315 * check for pcxr types.
7317 return p->u.useintr;
7321 /* If not found, then don't turn on interrupts. */
7326 * Given a board pointer, returns whether we turn on altpin or not.
7328 static uint dgap_config_get_altpin(struct board_t *bd)
7335 for (p = bd->bd_config; p; p = p->next) {
7336 if (p->type == ANODE) {
7338 * check for pcxr types.
7344 /* If not found, then don't turn on interrupts. */
7349 * Given a specific type of board, if found, detached link and
7350 * returns the first occurrence in the list.
7352 static struct cnode *dgap_find_config(int type, int bus, int slot)
7354 struct cnode *p, *prev, *prev2, *found;
7362 if (p->type == BNODE) {
7364 if (p->u.board.type == type) {
7366 if (p->u.board.v_pcibus &&
7367 p->u.board.pcibus != bus)
7369 if (p->u.board.v_pcislot &&
7370 p->u.board.pcislot != slot)
7375 * Keep walking thru the list till we
7376 * find the next board.
7381 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
7401 * It must be the last board in the list.
7412 * Given a board pointer, walks the config link, counting up
7413 * all ports user specified should be on the board.
7414 * (This does NOT mean they are all actually present right now tho)
7416 static uint dgap_config_get_num_prts(struct board_t *bd)
7424 for (p = bd->bd_config; p; p = p->next) {
7429 * check for pcxr types.
7431 if (p->u.board.type > EPCFE)
7432 count += p->u.board.nport;
7435 count += p->u.conc.nport;
7438 count += p->u.module.nport;
7445 static char *dgap_create_config_string(struct board_t *bd, char *string)
7457 for (p = bd->bd_config; p; p = p->next) {
7463 *ptr = p->u.line.speed;
7468 * Because the EPC/con concentrators can have EM modules
7469 * hanging off of them, we have to walk ahead in the
7470 * list and keep adding the number of ports on each EM
7471 * to the config. UGH!
7473 speed = p->u.conc.speed;
7475 if (q && (q->type == MNODE)) {
7476 *ptr = (p->u.conc.nport + 0x80);
7479 while (q->next && (q->next->type) == MNODE) {
7480 *ptr = (q->u.module.nport + 0x80);
7485 *ptr = q->u.module.nport;
7488 *ptr = p->u.conc.nport;