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 char *dgap_savestring(char *s);
154 static struct cnode *dgap_newnode(int t);
155 static int dgap_checknode(struct cnode *p);
156 static void dgap_err(char *s);
159 * Function prototypes from dgap_sysfs.h
167 static void dgap_create_ports_sysfiles(struct board_t *bd);
168 static void dgap_remove_ports_sysfiles(struct board_t *bd);
170 static int dgap_create_driver_sysfiles(struct pci_driver *);
171 static void dgap_remove_driver_sysfiles(struct pci_driver *);
173 static void dgap_create_tty_sysfs(struct un_t *un, struct device *c);
174 static void dgap_remove_tty_sysfs(struct device *c);
177 * Function prototypes from dgap_parse.h
179 static int dgap_parsefile(char **in, int remove);
180 static struct cnode *dgap_find_config(int type, int bus, int slot);
181 static uint dgap_config_get_num_prts(struct board_t *bd);
182 static char *dgap_create_config_string(struct board_t *bd, char *string);
183 static uint dgap_config_get_useintr(struct board_t *bd);
184 static uint dgap_config_get_altpin(struct board_t *bd);
186 static int dgap_ms_sleep(ulong ms);
187 static void dgap_do_bios_load(struct board_t *brd, const u8 *ubios, int len);
188 static void dgap_do_fep_load(struct board_t *brd, const u8 *ufep, int len);
189 #ifdef DIGI_CONCENTRATORS_SUPPORTED
190 static void dgap_do_conc_load(struct board_t *brd, u8 *uaddr, int len);
192 static int dgap_after_config_loaded(int board);
193 static int dgap_finalize_board_init(struct board_t *brd);
195 static void dgap_get_vpd(struct board_t *brd);
196 static void dgap_do_reset_board(struct board_t *brd);
197 static int dgap_test_bios(struct board_t *brd);
198 static int dgap_test_fep(struct board_t *brd);
199 static int dgap_tty_register_ports(struct board_t *brd);
200 static int dgap_firmware_load(struct pci_dev *pdev, int card_type);
202 static void dgap_cleanup_module(void);
204 module_exit(dgap_cleanup_module);
207 * File operations permitted on Control/Management major.
209 static const struct file_operations dgap_board_fops = {
210 .owner = THIS_MODULE,
213 static uint dgap_numboards;
214 static struct board_t *dgap_board[MAXBOARDS];
215 static ulong dgap_poll_counter;
216 static char *dgap_config_buf;
217 static int dgap_driver_state = DRIVER_INITIALIZED;
218 static wait_queue_head_t dgap_dl_wait;
219 static int dgap_poll_tick = 20; /* Poll interval - 20 ms */
221 static struct class *dgap_class;
223 static struct board_t *dgap_boards_by_major[256];
224 static uint dgap_count = 500;
229 static DEFINE_SPINLOCK(dgap_poll_lock); /* Poll scheduling lock */
230 static ulong dgap_poll_time; /* Time of next poll */
231 static uint dgap_poll_stop; /* Used to tell poller to stop */
232 static struct timer_list dgap_poll_timer;
237 Card Model Number of Ports Interface
238 ----------------------------------------------------------------
239 Acceleport Xem 4 - 64 (EIA232 & EIA422)
240 Acceleport Xr 4 & 8 (EIA232)
241 Acceleport Xr 920 4 & 8 (EIA232)
242 Acceleport C/X 8 - 128 (EIA232)
243 Acceleport EPC/X 8 - 224 (EIA232)
244 Acceleport Xr/422 4 & 8 (EIA422)
245 Acceleport 2r/920 2 (EIA232)
246 Acceleport 4r/920 4 (EIA232)
247 Acceleport 8r/920 8 (EIA232)
249 IBM 8-Port Asynchronous PCI Adapter (EIA232)
250 IBM 128-Port Asynchronous PCI Adapter (EIA232 & EIA422)
253 static struct pci_device_id dgap_pci_tbl[] = {
254 { DIGI_VID, PCI_DEV_XEM_DID, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0 },
255 { DIGI_VID, PCI_DEV_CX_DID, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 1 },
256 { DIGI_VID, PCI_DEV_CX_IBM_DID, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 2 },
257 { DIGI_VID, PCI_DEV_EPCJ_DID, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 3 },
258 { DIGI_VID, PCI_DEV_920_2_DID, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 4 },
259 { DIGI_VID, PCI_DEV_920_4_DID, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 5 },
260 { DIGI_VID, PCI_DEV_920_8_DID, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 6 },
261 { DIGI_VID, PCI_DEV_XR_DID, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 7 },
262 { DIGI_VID, PCI_DEV_XRJ_DID, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 8 },
263 { DIGI_VID, PCI_DEV_XR_422_DID, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 9 },
264 { DIGI_VID, PCI_DEV_XR_IBM_DID, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 10 },
265 { DIGI_VID, PCI_DEV_XR_SAIP_DID, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 11 },
266 { DIGI_VID, PCI_DEV_XR_BULL_DID, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 12 },
267 { DIGI_VID, PCI_DEV_920_8_HP_DID, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 13 },
268 { DIGI_VID, PCI_DEV_XEM_HP_DID, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 14 },
269 {0,} /* 0 terminated list. */
271 MODULE_DEVICE_TABLE(pci, dgap_pci_tbl);
274 * A generic list of Product names, PCI Vendor ID, and PCI Device ID.
283 static struct board_id dgap_ids[] = {
284 { PPCM, PCI_DEV_XEM_NAME, 64, (T_PCXM|T_PCLITE|T_PCIBUS) },
285 { PCX, PCI_DEV_CX_NAME, 128, (T_CX|T_PCIBUS) },
286 { PCX, PCI_DEV_CX_IBM_NAME, 128, (T_CX|T_PCIBUS) },
287 { PEPC, PCI_DEV_EPCJ_NAME, 224, (T_EPC|T_PCIBUS) },
288 { APORT2_920P, PCI_DEV_920_2_NAME, 2, (T_PCXR|T_PCLITE|T_PCIBUS) },
289 { APORT4_920P, PCI_DEV_920_4_NAME, 4, (T_PCXR|T_PCLITE|T_PCIBUS) },
290 { APORT8_920P, PCI_DEV_920_8_NAME, 8, (T_PCXR|T_PCLITE|T_PCIBUS) },
291 { PAPORT8, PCI_DEV_XR_NAME, 8, (T_PCXR|T_PCLITE|T_PCIBUS) },
292 { PAPORT8, PCI_DEV_XRJ_NAME, 8, (T_PCXR|T_PCLITE|T_PCIBUS) },
293 { PAPORT8, PCI_DEV_XR_422_NAME, 8, (T_PCXR|T_PCLITE|T_PCIBUS) },
294 { PAPORT8, PCI_DEV_XR_IBM_NAME, 8, (T_PCXR|T_PCLITE|T_PCIBUS) },
295 { PAPORT8, PCI_DEV_XR_SAIP_NAME, 8, (T_PCXR|T_PCLITE|T_PCIBUS) },
296 { PAPORT8, PCI_DEV_XR_BULL_NAME, 8, (T_PCXR|T_PCLITE|T_PCIBUS) },
297 { APORT8_920P, PCI_DEV_920_8_HP_NAME, 8, (T_PCXR|T_PCLITE|T_PCIBUS) },
298 { PPCM, PCI_DEV_XEM_HP_NAME, 64, (T_PCXM|T_PCLITE|T_PCIBUS) },
299 {0,} /* 0 terminated list. */
302 static struct pci_driver dgap_driver = {
304 .probe = dgap_init_one,
305 .id_table = dgap_pci_tbl,
306 .remove = dgap_remove_one,
309 struct firmware_info {
310 u8 *conf_name; /* dgap.conf */
311 u8 *bios_name; /* BIOS filename */
312 u8 *fep_name; /* FEP filename */
313 u8 *con_name; /* Concentrator filename FIXME*/
314 int num; /* sequence number */
318 * Firmware - BIOS, FEP, and CONC filenames
320 static struct firmware_info fw_info[] = {
321 { "dgap/dgap.conf", "dgap/sxbios.bin", "dgap/sxfep.bin", NULL, 0 },
322 { "dgap/dgap.conf", "dgap/cxpbios.bin", "dgap/cxpfep.bin", NULL, 1 },
323 { "dgap/dgap.conf", "dgap/cxpbios.bin", "dgap/cxpfep.bin", NULL, 2 },
324 { "dgap/dgap.conf", "dgap/pcibios.bin", "dgap/pcifep.bin", NULL, 3 },
325 { "dgap/dgap.conf", "dgap/xrbios.bin", "dgap/xrfep.bin", NULL, 4 },
326 { "dgap/dgap.conf", "dgap/xrbios.bin", "dgap/xrfep.bin", NULL, 5 },
327 { "dgap/dgap.conf", "dgap/xrbios.bin", "dgap/xrfep.bin", NULL, 6 },
328 { "dgap/dgap.conf", "dgap/xrbios.bin", "dgap/xrfep.bin", NULL, 7 },
329 { "dgap/dgap.conf", "dgap/xrbios.bin", "dgap/xrfep.bin", NULL, 8 },
330 { "dgap/dgap.conf", "dgap/xrbios.bin", "dgap/xrfep.bin", NULL, 9 },
331 { "dgap/dgap.conf", "dgap/xrbios.bin", "dgap/xrfep.bin", NULL, 10 },
332 { "dgap/dgap.conf", "dgap/xrbios.bin", "dgap/xrfep.bin", NULL, 11 },
333 { "dgap/dgap.conf", "dgap/xrbios.bin", "dgap/xrfep.bin", NULL, 12 },
334 { "dgap/dgap.conf", "dgap/xrbios.bin", "dgap/xrfep.bin", NULL, 13 },
335 { "dgap/dgap.conf", "dgap/sxbios.bin", "dgap/sxfep.bin", NULL, 14 },
340 * Default transparent print information.
342 static struct digi_t dgap_digi_init = {
343 .digi_flags = DIGI_COOK, /* Flags */
344 .digi_maxcps = 100, /* Max CPS */
345 .digi_maxchar = 50, /* Max chars in print queue */
346 .digi_bufsize = 100, /* Printer buffer size */
347 .digi_onlen = 4, /* size of printer on string */
348 .digi_offlen = 4, /* size of printer off string */
349 .digi_onstr = "\033[5i", /* ANSI printer on string ] */
350 .digi_offstr = "\033[4i", /* ANSI printer off string ] */
351 .digi_term = "ansi" /* default terminal type */
355 * Define a local default termios struct. All ports will be created
356 * with this termios initially.
358 * This defines a raw port at 9600 baud, 8 data bits, no parity,
362 static struct ktermios dgap_default_termios = {
363 .c_iflag = (DEFAULT_IFLAGS), /* iflags */
364 .c_oflag = (DEFAULT_OFLAGS), /* oflags */
365 .c_cflag = (DEFAULT_CFLAGS), /* cflags */
366 .c_lflag = (DEFAULT_LFLAGS), /* lflags */
371 static const struct tty_operations dgap_tty_ops = {
372 .open = dgap_tty_open,
373 .close = dgap_tty_close,
374 .write = dgap_tty_write,
375 .write_room = dgap_tty_write_room,
376 .flush_buffer = dgap_tty_flush_buffer,
377 .chars_in_buffer = dgap_tty_chars_in_buffer,
378 .flush_chars = dgap_tty_flush_chars,
379 .ioctl = dgap_tty_ioctl,
380 .set_termios = dgap_tty_set_termios,
381 .stop = dgap_tty_stop,
382 .start = dgap_tty_start,
383 .throttle = dgap_tty_throttle,
384 .unthrottle = dgap_tty_unthrottle,
385 .hangup = dgap_tty_hangup,
386 .put_char = dgap_tty_put_char,
387 .tiocmget = dgap_tty_tiocmget,
388 .tiocmset = dgap_tty_tiocmset,
389 .break_ctl = dgap_tty_send_break,
390 .wait_until_sent = dgap_tty_wait_until_sent,
391 .send_xchar = dgap_tty_send_xchar
395 * Our needed internal static variables from dgap_parse.c
397 static struct cnode dgap_head;
399 static char dgap_cword[MAXCWORD];
406 static struct toklist dgap_tlist[] = {
407 { BEGIN, "config_begin" },
408 { END, "config_end" },
410 { PCX, "Digi_AccelePort_C/X_PCI" },
411 { PEPC, "Digi_AccelePort_EPC/X_PCI" },
412 { PPCM, "Digi_AccelePort_Xem_PCI" },
413 { APORT2_920P, "Digi_AccelePort_2r_920_PCI" },
414 { APORT4_920P, "Digi_AccelePort_4r_920_PCI" },
415 { APORT8_920P, "Digi_AccelePort_8r_920_PCI" },
416 { PAPORT4, "Digi_AccelePort_4r_PCI(EIA-232/RS-422)" },
417 { PAPORT8, "Digi_AccelePort_8r_PCI(EIA-232/RS-422)" },
419 { PCIINFO, "pciinfo" },
422 { CONC, "concentrator" },
432 { CONNECT, "connect" },
433 { METHOD, "method" },
434 { STATUS, "status" },
435 { CUSTOM, "Custom" },
441 { NPORTS, "nports" },
446 { ALTPIN, "altpin" },
447 { USEINTR, "useintr" },
448 { TTSIZ, "ttysize" },
450 { BSSIZ, "boardsize" },
451 { UNTSIZ, "schedsize" },
452 { F2SIZ, "f2200size" },
453 { VPSIZ, "vpixsize" },
457 /************************************************************************
459 * Driver load/unload functions
461 ************************************************************************/
466 * Module load. This is where it all starts.
468 static int dgap_init_module(void)
472 pr_info("%s, Digi International Part Number %s\n", DG_NAME, DG_PART);
478 rc = dgap_init_pci();
482 rc = dgap_create_driver_sysfiles(&dgap_driver);
486 dgap_driver_state = DRIVER_READY;
492 dgap_cleanup_module();
496 module_init(dgap_init_module);
501 static int dgap_start(void)
505 struct device *device;
508 * make sure that the globals are
509 * init'd before we do anything else
515 pr_info("For the tools package please visit http://www.digi.com\n");
518 * Register our base character device into the kernel.
522 * Register management/dpa devices
524 rc = register_chrdev(DIGI_DGAP_MAJOR, "dgap", &dgap_board_fops);
528 dgap_class = class_create(THIS_MODULE, "dgap_mgmt");
529 if (IS_ERR(dgap_class)) {
530 rc = PTR_ERR(dgap_class);
534 device = device_create(dgap_class, NULL,
535 MKDEV(DIGI_DGAP_MAJOR, 0),
537 if (IS_ERR(device)) {
538 rc = PTR_ERR(device);
542 /* Start the poller */
543 spin_lock_irqsave(&dgap_poll_lock, flags);
544 init_timer(&dgap_poll_timer);
545 dgap_poll_timer.function = dgap_poll_handler;
546 dgap_poll_timer.data = 0;
547 dgap_poll_time = jiffies + dgap_jiffies_from_ms(dgap_poll_tick);
548 dgap_poll_timer.expires = dgap_poll_time;
549 spin_unlock_irqrestore(&dgap_poll_lock, flags);
551 add_timer(&dgap_poll_timer);
556 class_destroy(dgap_class);
558 unregister_chrdev(DIGI_DGAP_MAJOR, "dgap");
563 * Register pci driver, and return how many boards we have.
565 static int dgap_init_pci(void)
567 return pci_register_driver(&dgap_driver);
570 static int dgap_init_one(struct pci_dev *pdev, const struct pci_device_id *ent)
574 if (dgap_numboards >= MAXBOARDS)
577 rc = pci_enable_device(pdev);
581 rc = dgap_probe1(pdev, ent->driver_data);
586 return dgap_firmware_load(pdev, ent->driver_data);
589 static int dgap_probe1(struct pci_dev *pdev, int card_type)
591 return dgap_found_board(pdev, card_type);
594 static void dgap_remove_one(struct pci_dev *dev)
600 * dgap_cleanup_module()
602 * Module unload. This is where it all ends.
604 static void dgap_cleanup_module(void)
609 spin_lock_irqsave(&dgap_poll_lock, lock_flags);
611 spin_unlock_irqrestore(&dgap_poll_lock, lock_flags);
613 /* Turn off poller right away. */
614 del_timer_sync(&dgap_poll_timer);
616 dgap_remove_driver_sysfiles(&dgap_driver);
618 device_destroy(dgap_class, MKDEV(DIGI_DGAP_MAJOR, 0));
619 class_destroy(dgap_class);
620 unregister_chrdev(DIGI_DGAP_MAJOR, "dgap");
622 for (i = 0; i < dgap_numboards; ++i) {
623 dgap_remove_ports_sysfiles(dgap_board[i]);
624 dgap_tty_uninit(dgap_board[i]);
625 dgap_cleanup_board(dgap_board[i]);
629 pci_unregister_driver(&dgap_driver);
633 * dgap_cleanup_board()
635 * Free all the memory associated with a board
637 static void dgap_cleanup_board(struct board_t *brd)
641 if (!brd || brd->magic != DGAP_BOARD_MAGIC)
644 if (brd->intr_used && brd->irq)
645 free_irq(brd->irq, brd);
647 tasklet_kill(&brd->helper_tasklet);
649 if (brd->re_map_port) {
650 release_mem_region(brd->membase + 0x200000, 0x200000);
651 iounmap(brd->re_map_port);
652 brd->re_map_port = NULL;
655 if (brd->re_map_membase) {
656 release_mem_region(brd->membase, 0x200000);
657 iounmap(brd->re_map_membase);
658 brd->re_map_membase = NULL;
661 /* Free all allocated channels structs */
662 for (i = 0; i < MAXPORTS ; i++)
663 kfree(brd->channels[i]);
666 kfree(brd->flipflagbuf);
668 dgap_board[brd->boardnum] = NULL;
676 * A board has been found, init it.
678 static int dgap_found_board(struct pci_dev *pdev, int id)
681 unsigned int pci_irq;
684 /* get the board structure and prep it */
685 brd = kzalloc(sizeof(struct board_t), GFP_KERNEL);
689 dgap_board[dgap_numboards] = brd;
691 /* store the info for the board we've found */
692 brd->magic = DGAP_BOARD_MAGIC;
693 brd->boardnum = dgap_numboards;
695 brd->vendor = dgap_pci_tbl[id].vendor;
696 brd->device = dgap_pci_tbl[id].device;
698 brd->pci_bus = pdev->bus->number;
699 brd->pci_slot = PCI_SLOT(pdev->devfn);
700 brd->name = dgap_ids[id].name;
701 brd->maxports = dgap_ids[id].maxports;
702 brd->type = dgap_ids[id].config_type;
703 brd->dpatype = dgap_ids[id].dpatype;
704 brd->dpastatus = BD_NOFEP;
705 init_waitqueue_head(&brd->state_wait);
707 spin_lock_init(&brd->bd_lock);
710 brd->inhibit_poller = FALSE;
711 brd->wait_for_bios = 0;
712 brd->wait_for_fep = 0;
714 for (i = 0; i < MAXPORTS; i++)
715 brd->channels[i] = NULL;
717 /* store which card & revision we have */
718 pci_read_config_word(pdev, PCI_SUBSYSTEM_VENDOR_ID, &brd->subvendor);
719 pci_read_config_word(pdev, PCI_SUBSYSTEM_ID, &brd->subdevice);
720 pci_read_config_byte(pdev, PCI_REVISION_ID, &brd->rev);
725 /* get the PCI Base Address Registers */
727 /* Xr Jupiter and EPC use BAR 2 */
728 if (brd->device == PCI_DEV_XRJ_DID || brd->device == PCI_DEV_EPCJ_DID) {
729 brd->membase = pci_resource_start(pdev, 2);
730 brd->membase_end = pci_resource_end(pdev, 2);
732 /* Everyone else uses BAR 0 */
734 brd->membase = pci_resource_start(pdev, 0);
735 brd->membase_end = pci_resource_end(pdev, 0);
741 if (brd->membase & 1)
747 * On the PCI boards, there is no IO space allocated
748 * The I/O registers will be in the first 3 bytes of the
749 * upper 2MB of the 4MB memory space. The board memory
750 * will be mapped into the low 2MB of the 4MB memory space
752 brd->port = brd->membase + PCI_IO_OFFSET;
753 brd->port_end = brd->port + PCI_IO_SIZE;
756 * Special initialization for non-PLX boards
758 if (brd->device != PCI_DEV_XRJ_DID && brd->device != PCI_DEV_EPCJ_DID) {
761 pci_write_config_byte(pdev, 0x40, 0);
762 pci_write_config_byte(pdev, 0x46, 0);
764 /* Limit burst length to 2 doubleword transactions */
765 pci_write_config_byte(pdev, 0x42, 1);
768 * Enable IO and mem if not already done.
769 * This was needed for support on Itanium.
771 pci_read_config_word(pdev, PCI_COMMAND, &cmd);
772 cmd |= (PCI_COMMAND_IO | PCI_COMMAND_MEMORY);
773 pci_write_config_word(pdev, PCI_COMMAND, cmd);
776 /* init our poll helper tasklet */
777 tasklet_init(&brd->helper_tasklet, dgap_poll_tasklet,
778 (unsigned long) brd);
780 i = dgap_do_remap(brd);
782 brd->state = BOARD_FAILED;
784 pr_info("dgap: board %d: %s (rev %d), irq %ld\n",
785 dgap_numboards, brd->name, brd->rev, brd->irq);
791 static int dgap_finalize_board_init(struct board_t *brd)
795 if (!brd || brd->magic != DGAP_BOARD_MAGIC)
798 brd->use_interrupts = dgap_config_get_useintr(brd);
801 * Set up our interrupt handler if we are set to do interrupts.
803 if (brd->use_interrupts && brd->irq) {
805 rc = request_irq(brd->irq, dgap_intr, IRQF_SHARED, "DGAP", brd);
818 static int dgap_firmware_load(struct pci_dev *pdev, int card_type)
820 struct board_t *brd = dgap_board[dgap_numboards - 1];
821 const struct firmware *fw;
826 dgap_do_reset_board(brd);
828 if ((fw_info[card_type].conf_name) && !dgap_config_buf) {
829 ret = request_firmware(&fw, fw_info[card_type].conf_name,
832 pr_err("dgap: config file %s not found\n",
833 fw_info[card_type].conf_name);
837 dgap_config_buf = kzalloc(fw->size + 1, GFP_KERNEL);
838 if (!dgap_config_buf) {
839 release_firmware(fw);
843 memcpy(dgap_config_buf, fw->data, fw->size);
844 release_firmware(fw);
847 * preserve dgap_config_buf
848 * as dgap_parsefile would
849 * otherwise alter it.
851 tmp_ptr = dgap_config_buf;
853 if (dgap_parsefile(&tmp_ptr, TRUE) != 0) {
854 kfree(dgap_config_buf);
857 kfree(dgap_config_buf);
860 ret = dgap_after_config_loaded(brd->boardnum);
864 * Match this board to a config the user created for us.
867 dgap_find_config(brd->type, brd->pci_bus, brd->pci_slot);
870 * Because the 4 port Xr products share the same PCI ID
871 * as the 8 port Xr products, if we receive a NULL config
872 * back, and this is a PAPORT8 board, retry with a
873 * PAPORT4 attempt as well.
875 if (brd->type == PAPORT8 && !brd->bd_config)
877 dgap_find_config(PAPORT4, brd->pci_bus, brd->pci_slot);
879 if (!brd->bd_config) {
880 pr_err("dgap: No valid configuration found\n");
884 ret = dgap_tty_register(brd);
888 ret = dgap_finalize_board_init(brd);
892 if (fw_info[card_type].bios_name) {
893 ret = request_firmware(&fw, fw_info[card_type].bios_name,
896 pr_err("dgap: bios file %s not found\n",
897 fw_info[card_type].bios_name);
900 dgap_do_bios_load(brd, fw->data, fw->size);
901 release_firmware(fw);
903 /* Wait for BIOS to test board... */
904 ret = dgap_test_bios(brd);
909 if (fw_info[card_type].fep_name) {
910 ret = request_firmware(&fw, fw_info[card_type].fep_name,
913 pr_err("dgap: fep file %s not found\n",
914 fw_info[card_type].fep_name);
917 dgap_do_fep_load(brd, fw->data, fw->size);
918 release_firmware(fw);
920 /* Wait for FEP to load on board... */
921 ret = dgap_test_fep(brd);
926 #ifdef DIGI_CONCENTRATORS_SUPPORTED
928 * If this is a CX or EPCX, we need to see if the firmware
929 * is requesting a concentrator image from us.
931 if ((bd->type == PCX) || (bd->type == PEPC)) {
932 chk_addr = (u16 *) (vaddr + DOWNREQ);
933 /* Nonzero if FEP is requesting concentrator image. */
934 check = readw(chk_addr);
935 vaddr = brd->re_map_membase;
938 if (fw_info[card_type].con_name && check && vaddr) {
939 ret = request_firmware(&fw, fw_info[card_type].con_name,
942 pr_err("dgap: conc file %s not found\n",
943 fw_info[card_type].con_name);
946 /* Put concentrator firmware loading code here */
947 offset = readw((u16 *) (vaddr + DOWNREQ));
948 memcpy_toio(offset, fw->data, fw->size);
950 dgap_do_conc_load(brd, (char *)fw->data, fw->size)
951 release_firmware(fw);
955 * Do tty device initialization.
957 ret = dgap_tty_init(brd);
959 dgap_tty_uninit(brd);
963 ret = dgap_tty_register_ports(brd);
967 brd->state = BOARD_READY;
968 brd->dpastatus = BD_RUNNING;
976 static int dgap_do_remap(struct board_t *brd)
978 if (!brd || brd->magic != DGAP_BOARD_MAGIC)
981 if (!request_mem_region(brd->membase, 0x200000, "dgap"))
984 if (!request_mem_region(brd->membase + PCI_IO_OFFSET, 0x200000,
986 release_mem_region(brd->membase, 0x200000);
990 brd->re_map_membase = ioremap(brd->membase, 0x200000);
991 if (!brd->re_map_membase) {
992 release_mem_region(brd->membase, 0x200000);
993 release_mem_region(brd->membase + PCI_IO_OFFSET, 0x200000);
997 brd->re_map_port = ioremap((brd->membase + PCI_IO_OFFSET), 0x200000);
998 if (!brd->re_map_port) {
999 release_mem_region(brd->membase, 0x200000);
1000 release_mem_region(brd->membase + PCI_IO_OFFSET, 0x200000);
1001 iounmap(brd->re_map_membase);
1008 /*****************************************************************************
1028 * As each timer expires, it determines (a) whether the "transmit"
1029 * waiter needs to be woken up, and (b) whether the poller needs to
1032 ******************************************************************************/
1034 static void dgap_poll_handler(ulong dummy)
1037 struct board_t *brd;
1038 unsigned long lock_flags;
1041 dgap_poll_counter++;
1044 * Do not start the board state machine until
1045 * driver tells us its up and running, and has
1046 * everything it needs.
1048 if (dgap_driver_state != DRIVER_READY)
1049 goto schedule_poller;
1052 * If we have just 1 board, or the system is not SMP,
1053 * then use the typical old style poller.
1054 * Otherwise, use our new tasklet based poller, which should
1055 * speed things up for multiple boards.
1057 if ((dgap_numboards == 1) || (num_online_cpus() <= 1)) {
1058 for (i = 0; i < dgap_numboards; i++) {
1060 brd = dgap_board[i];
1062 if (brd->state == BOARD_FAILED)
1064 if (!brd->intr_running)
1065 /* Call the real board poller directly */
1066 dgap_poll_tasklet((unsigned long) brd);
1070 * Go thru each board, kicking off a
1071 * tasklet for each if needed
1073 for (i = 0; i < dgap_numboards; i++) {
1074 brd = dgap_board[i];
1077 * Attempt to grab the board lock.
1079 * If we can't get it, no big deal, the next poll
1080 * will get it. Basically, I just really don't want
1081 * to spin in here, because I want to kick off my
1082 * tasklets as fast as I can, and then get out the
1085 if (!spin_trylock(&brd->bd_lock))
1089 * If board is in a failed state, don't bother
1090 * scheduling a tasklet
1092 if (brd->state == BOARD_FAILED) {
1093 spin_unlock(&brd->bd_lock);
1097 /* Schedule a poll helper task */
1098 if (!brd->intr_running)
1099 tasklet_schedule(&brd->helper_tasklet);
1102 * Can't do DGAP_UNLOCK here, as we don't have
1103 * lock_flags because we did a trylock above.
1105 spin_unlock(&brd->bd_lock);
1112 * Schedule ourself back at the nominal wakeup interval.
1114 spin_lock_irqsave(&dgap_poll_lock, lock_flags);
1115 dgap_poll_time += dgap_jiffies_from_ms(dgap_poll_tick);
1117 new_time = dgap_poll_time - jiffies;
1119 if ((ulong) new_time >= 2 * dgap_poll_tick) {
1121 jiffies + dgap_jiffies_from_ms(dgap_poll_tick);
1124 dgap_poll_timer.function = dgap_poll_handler;
1125 dgap_poll_timer.data = 0;
1126 dgap_poll_timer.expires = dgap_poll_time;
1127 spin_unlock_irqrestore(&dgap_poll_lock, lock_flags);
1129 if (!dgap_poll_stop)
1130 add_timer(&dgap_poll_timer);
1136 * Driver interrupt handler.
1138 static irqreturn_t dgap_intr(int irq, void *voidbrd)
1140 struct board_t *brd = (struct board_t *) voidbrd;
1146 * Check to make sure its for us.
1148 if (brd->magic != DGAP_BOARD_MAGIC)
1154 * Schedule tasklet to run at a better time.
1156 tasklet_schedule(&brd->helper_tasklet);
1161 * dgap_init_globals()
1163 * This is where we initialize the globals from the static insmod
1164 * configuration variables. These are declared near the head of
1167 static void dgap_init_globals(void)
1171 for (i = 0; i < MAXBOARDS; i++)
1172 dgap_board[i] = NULL;
1174 init_timer(&dgap_poll_timer);
1176 init_waitqueue_head(&dgap_dl_wait);
1179 /************************************************************************
1183 ************************************************************************/
1188 * Put the driver to sleep for x ms's
1190 * Returns 0 if timed out, !0 (showing signal) if interrupted by a signal.
1192 static int dgap_ms_sleep(ulong ms)
1194 current->state = TASK_INTERRUPTIBLE;
1195 schedule_timeout((ms * HZ) / 1000);
1196 return signal_pending(current);
1199 /************************************************************************
1201 * TTY Initialization/Cleanup Functions
1203 ************************************************************************/
1206 * dgap_tty_register()
1208 * Init the tty subsystem for this board.
1210 static int dgap_tty_register(struct board_t *brd)
1214 brd->serial_driver = tty_alloc_driver(MAXPORTS, 0);
1215 if (IS_ERR(brd->serial_driver))
1216 return PTR_ERR(brd->serial_driver);
1218 snprintf(brd->serial_name, MAXTTYNAMELEN, "tty_dgap_%d_",
1220 brd->serial_driver->name = brd->serial_name;
1221 brd->serial_driver->name_base = 0;
1222 brd->serial_driver->major = 0;
1223 brd->serial_driver->minor_start = 0;
1224 brd->serial_driver->type = TTY_DRIVER_TYPE_SERIAL;
1225 brd->serial_driver->subtype = SERIAL_TYPE_NORMAL;
1226 brd->serial_driver->init_termios = dgap_default_termios;
1227 brd->serial_driver->driver_name = DRVSTR;
1228 brd->serial_driver->flags = (TTY_DRIVER_REAL_RAW |
1229 TTY_DRIVER_DYNAMIC_DEV |
1230 TTY_DRIVER_HARDWARE_BREAK);
1232 /* The kernel wants space to store pointers to tty_structs */
1233 brd->serial_driver->ttys =
1234 kzalloc(MAXPORTS * sizeof(struct tty_struct *), GFP_KERNEL);
1235 if (!brd->serial_driver->ttys) {
1237 goto free_serial_drv;
1241 * Entry points for driver. Called by the kernel from
1242 * tty_io.c and n_tty.c.
1244 tty_set_operations(brd->serial_driver, &dgap_tty_ops);
1247 * If we're doing transparent print, we have to do all of the above
1248 * again, separately so we don't get the LD confused about what major
1249 * we are when we get into the dgap_tty_open() routine.
1251 brd->print_driver = tty_alloc_driver(MAXPORTS, 0);
1252 if (IS_ERR(brd->print_driver)) {
1253 rc = PTR_ERR(brd->print_driver);
1254 goto free_serial_drv;
1257 snprintf(brd->print_name, MAXTTYNAMELEN, "pr_dgap_%d_",
1259 brd->print_driver->name = brd->print_name;
1260 brd->print_driver->name_base = 0;
1261 brd->print_driver->major = 0;
1262 brd->print_driver->minor_start = 0;
1263 brd->print_driver->type = TTY_DRIVER_TYPE_SERIAL;
1264 brd->print_driver->subtype = SERIAL_TYPE_NORMAL;
1265 brd->print_driver->init_termios = dgap_default_termios;
1266 brd->print_driver->driver_name = DRVSTR;
1267 brd->print_driver->flags = (TTY_DRIVER_REAL_RAW |
1268 TTY_DRIVER_DYNAMIC_DEV |
1269 TTY_DRIVER_HARDWARE_BREAK);
1271 /* The kernel wants space to store pointers to tty_structs */
1272 brd->print_driver->ttys =
1273 kzalloc(MAXPORTS * sizeof(struct tty_struct *), GFP_KERNEL);
1274 if (!brd->print_driver->ttys) {
1276 goto free_print_drv;
1280 * Entry points for driver. Called by the kernel from
1281 * tty_io.c and n_tty.c.
1283 tty_set_operations(brd->print_driver, &dgap_tty_ops);
1285 /* Register tty devices */
1286 rc = tty_register_driver(brd->serial_driver);
1288 goto free_print_drv;
1290 /* Register Transparent Print devices */
1291 rc = tty_register_driver(brd->print_driver);
1293 goto unregister_serial_drv;
1295 brd->dgap_major_serial_registered = TRUE;
1296 dgap_boards_by_major[brd->serial_driver->major] = brd;
1297 brd->dgap_serial_major = brd->serial_driver->major;
1299 brd->dgap_major_transparent_print_registered = TRUE;
1300 dgap_boards_by_major[brd->print_driver->major] = brd;
1301 brd->dgap_transparent_print_major = brd->print_driver->major;
1305 unregister_serial_drv:
1306 tty_unregister_driver(brd->serial_driver);
1308 put_tty_driver(brd->print_driver);
1310 put_tty_driver(brd->serial_driver);
1318 * Init the tty subsystem. Called once per board after board has been
1319 * downloaded and init'ed.
1321 static int dgap_tty_init(struct board_t *brd)
1325 uint true_count = 0;
1328 struct channel_t *ch;
1329 struct bs_t __iomem *bs;
1330 struct cm_t __iomem *cm;
1336 * Initialize board structure elements.
1339 vaddr = brd->re_map_membase;
1340 true_count = readw((vaddr + NCHAN));
1342 brd->nasync = dgap_config_get_num_prts(brd);
1345 brd->nasync = brd->maxports;
1347 if (brd->nasync > brd->maxports)
1348 brd->nasync = brd->maxports;
1350 if (true_count != brd->nasync) {
1351 if ((brd->type == PPCM) && (true_count == 64)) {
1352 pr_warn("dgap: %s configured for %d ports, has %d ports.\n",
1353 brd->name, brd->nasync, true_count);
1354 pr_warn("dgap: Please make SURE the EBI cable running from the card\n");
1355 pr_warn("dgap: to each EM module is plugged into EBI IN!\n");
1356 } else if ((brd->type == PPCM) && (true_count == 0)) {
1357 pr_warn("dgap: %s configured for %d ports, has %d ports.\n",
1358 brd->name, brd->nasync, true_count);
1359 pr_warn("dgap: Please make SURE the EBI cable running from the card\n");
1360 pr_warn("dgap: to each EM module is plugged into EBI IN!\n");
1362 pr_warn("dgap: %s configured for %d ports, has %d ports.\n",
1363 brd->name, brd->nasync, true_count);
1365 brd->nasync = true_count;
1367 /* If no ports, don't bother going any further */
1369 brd->state = BOARD_FAILED;
1370 brd->dpastatus = BD_NOFEP;
1376 * Allocate channel memory that might not have been allocated
1377 * when the driver was first loaded.
1379 for (i = 0; i < brd->nasync; i++) {
1380 if (!brd->channels[i]) {
1382 kzalloc(sizeof(struct channel_t), GFP_ATOMIC);
1383 if (!brd->channels[i])
1388 ch = brd->channels[0];
1389 vaddr = brd->re_map_membase;
1391 bs = (struct bs_t __iomem *) ((ulong) vaddr + CHANBUF);
1392 cm = (struct cm_t __iomem *) ((ulong) vaddr + CMDBUF);
1396 /* Set up channel variables */
1397 for (i = 0; i < brd->nasync; i++, ch = brd->channels[i], bs++) {
1399 if (!brd->channels[i])
1402 spin_lock_init(&ch->ch_lock);
1404 /* Store all our magic numbers */
1405 ch->magic = DGAP_CHANNEL_MAGIC;
1406 ch->ch_tun.magic = DGAP_UNIT_MAGIC;
1407 ch->ch_tun.un_type = DGAP_SERIAL;
1408 ch->ch_tun.un_ch = ch;
1409 ch->ch_tun.un_dev = i;
1411 ch->ch_pun.magic = DGAP_UNIT_MAGIC;
1412 ch->ch_pun.un_type = DGAP_PRINT;
1413 ch->ch_pun.un_ch = ch;
1414 ch->ch_pun.un_dev = i;
1416 ch->ch_vaddr = vaddr;
1421 ch->ch_digi = dgap_digi_init;
1424 * Set up digi dsr and dcd bits based on altpin flag.
1426 if (dgap_config_get_altpin(brd)) {
1429 ch->ch_digi.digi_flags |= DIGI_ALTPIN;
1432 ch->ch_dsr = DM_DSR;
1435 ch->ch_taddr = vaddr + ((ch->ch_bs->tx_seg) << 4);
1436 ch->ch_raddr = vaddr + ((ch->ch_bs->rx_seg) << 4);
1439 ch->ch_tsize = readw(&(ch->ch_bs->tx_max)) + 1;
1440 ch->ch_rsize = readw(&(ch->ch_bs->rx_max)) + 1;
1444 /* .25 second delay */
1445 ch->ch_close_delay = 250;
1448 * Set queue water marks, interrupt mask,
1449 * and general tty parameters.
1451 tlw = ch->ch_tsize >= 2000 ? ((ch->ch_tsize * 5) / 8) :
1455 dgap_cmdw(ch, STLOW, tlw, 0);
1457 dgap_cmdw(ch, SRLOW, ch->ch_rsize / 2, 0);
1459 dgap_cmdw(ch, SRHIGH, 7 * ch->ch_rsize / 8, 0);
1461 ch->ch_mistat = readb(&(ch->ch_bs->m_stat));
1463 init_waitqueue_head(&ch->ch_flags_wait);
1464 init_waitqueue_head(&ch->ch_tun.un_flags_wait);
1465 init_waitqueue_head(&ch->ch_pun.un_flags_wait);
1467 /* Turn on all modem interrupts for now */
1468 modem = (DM_CD | DM_DSR | DM_CTS | DM_RI);
1469 writeb(modem, &(ch->ch_bs->m_int));
1472 * Set edelay to 0 if interrupts are turned on,
1473 * otherwise set edelay to the usual 100.
1476 writew(0, &(ch->ch_bs->edelay));
1478 writew(100, &(ch->ch_bs->edelay));
1480 writeb(1, &(ch->ch_bs->idata));
1489 * Uninitialize the TTY portion of this driver. Free all memory and
1492 static void dgap_tty_uninit(struct board_t *brd)
1497 if (brd->dgap_major_serial_registered) {
1498 dgap_boards_by_major[brd->serial_driver->major] = NULL;
1499 brd->dgap_serial_major = 0;
1500 for (i = 0; i < brd->nasync; i++) {
1501 tty_port_destroy(&brd->serial_ports[i]);
1502 dev = brd->channels[i]->ch_tun.un_sysfs;
1503 dgap_remove_tty_sysfs(dev);
1504 tty_unregister_device(brd->serial_driver, i);
1506 tty_unregister_driver(brd->serial_driver);
1507 kfree(brd->serial_driver->ttys);
1508 brd->serial_driver->ttys = NULL;
1509 put_tty_driver(brd->serial_driver);
1510 kfree(brd->serial_ports);
1511 brd->dgap_major_serial_registered = FALSE;
1514 if (brd->dgap_major_transparent_print_registered) {
1515 dgap_boards_by_major[brd->print_driver->major] = NULL;
1516 brd->dgap_transparent_print_major = 0;
1517 for (i = 0; i < brd->nasync; i++) {
1518 tty_port_destroy(&brd->printer_ports[i]);
1519 dev = brd->channels[i]->ch_pun.un_sysfs;
1520 dgap_remove_tty_sysfs(dev);
1521 tty_unregister_device(brd->print_driver, i);
1523 tty_unregister_driver(brd->print_driver);
1524 kfree(brd->print_driver->ttys);
1525 brd->print_driver->ttys = NULL;
1526 put_tty_driver(brd->print_driver);
1527 kfree(brd->printer_ports);
1528 brd->dgap_major_transparent_print_registered = FALSE;
1532 /*=======================================================================
1534 * dgap_input - Process received data.
1536 * ch - Pointer to channel structure.
1538 *=======================================================================*/
1540 static void dgap_input(struct channel_t *ch)
1543 struct bs_t __iomem *bs;
1544 struct tty_struct *tp;
1545 struct tty_ldisc *ld;
1559 if (!ch || ch->magic != DGAP_CHANNEL_MAGIC)
1562 tp = ch->ch_tun.un_tty;
1569 if (!bd || bd->magic != DGAP_BOARD_MAGIC)
1572 spin_lock_irqsave(&bd->bd_lock, lock_flags);
1573 spin_lock_irqsave(&ch->ch_lock, lock_flags2);
1576 * Figure the number of characters in the buffer.
1577 * Exit immediately if none.
1580 rmask = ch->ch_rsize - 1;
1582 head = readw(&(bs->rx_head));
1584 tail = readw(&(bs->rx_tail));
1587 data_len = (head - tail) & rmask;
1589 if (data_len == 0) {
1590 writeb(1, &(bs->idata));
1591 spin_unlock_irqrestore(&ch->ch_lock, lock_flags2);
1592 spin_unlock_irqrestore(&bd->bd_lock, lock_flags);
1597 * If the device is not open, or CREAD is off, flush
1598 * input data and return immediately.
1600 if ((bd->state != BOARD_READY) || !tp ||
1601 (tp->magic != TTY_MAGIC) ||
1602 !(ch->ch_tun.un_flags & UN_ISOPEN) ||
1603 !(tp->termios.c_cflag & CREAD) ||
1604 (ch->ch_tun.un_flags & UN_CLOSING)) {
1606 writew(head, &(bs->rx_tail));
1607 writeb(1, &(bs->idata));
1608 spin_unlock_irqrestore(&ch->ch_lock, lock_flags2);
1609 spin_unlock_irqrestore(&bd->bd_lock, lock_flags);
1614 * If we are throttled, simply don't read any data.
1616 if (ch->ch_flags & CH_RXBLOCK) {
1617 writeb(1, &(bs->idata));
1618 spin_unlock_irqrestore(&ch->ch_lock, lock_flags2);
1619 spin_unlock_irqrestore(&bd->bd_lock, lock_flags);
1626 tmpchar = readb(&(bs->orun));
1628 ch->ch_err_overrun++;
1629 writeb(0, &(bs->orun));
1632 /* Decide how much data we can send into the tty layer */
1633 flip_len = TTY_FLIPBUF_SIZE;
1635 /* Chop down the length, if needed */
1636 len = min(data_len, flip_len);
1637 len = min(len, (N_TTY_BUF_SIZE - 1));
1639 ld = tty_ldisc_ref(tp);
1641 #ifdef TTY_DONT_FLIP
1643 * If the DONT_FLIP flag is on, don't flush our buffer, and act
1644 * like the ld doesn't have any space to put the data right now.
1646 if (test_bit(TTY_DONT_FLIP, &tp->flags))
1651 * If we were unable to get a reference to the ld,
1652 * don't flush our buffer, and act like the ld doesn't
1653 * have any space to put the data right now.
1659 * If ld doesn't have a pointer to a receive_buf function,
1660 * flush the data, then act like the ld doesn't have any
1661 * space to put the data right now.
1663 if (!ld->ops->receive_buf) {
1664 writew(head, &(bs->rx_tail));
1670 writeb(1, &(bs->idata));
1671 spin_unlock_irqrestore(&ch->ch_lock, lock_flags2);
1672 spin_unlock_irqrestore(&bd->bd_lock, lock_flags);
1674 tty_ldisc_deref(ld);
1678 buf = ch->ch_bd->flipbuf;
1682 * n now contains the most amount of data we can copy,
1683 * bounded either by our buffer size or the amount
1684 * of data the card actually has pending...
1688 s = ((head >= tail) ? head : ch->ch_rsize) - tail;
1694 memcpy_fromio(buf, ch->ch_raddr + tail, s);
1700 /* Flip queue if needed */
1704 writew(tail, &(bs->rx_tail));
1705 writeb(1, &(bs->idata));
1706 ch->ch_rxcount += len;
1709 * If we are completely raw, we don't need to go through a lot
1710 * of the tty layers that exist.
1711 * In this case, we take the shortest and fastest route we
1712 * can to relay the data to the user.
1714 * On the other hand, if we are not raw, we need to go through
1715 * the tty layer, which has its API more well defined.
1717 if (I_PARMRK(tp) || I_BRKINT(tp) || I_INPCK(tp)) {
1718 dgap_parity_scan(ch, ch->ch_bd->flipbuf,
1719 ch->ch_bd->flipflagbuf, &len);
1721 len = tty_buffer_request_room(tp->port, len);
1722 tty_insert_flip_string_flags(tp->port, ch->ch_bd->flipbuf,
1723 ch->ch_bd->flipflagbuf, len);
1725 len = tty_buffer_request_room(tp->port, len);
1726 tty_insert_flip_string(tp->port, ch->ch_bd->flipbuf, len);
1729 spin_unlock_irqrestore(&ch->ch_lock, lock_flags2);
1730 spin_unlock_irqrestore(&bd->bd_lock, lock_flags);
1732 /* Tell the tty layer its okay to "eat" the data now */
1733 tty_flip_buffer_push(tp->port);
1736 tty_ldisc_deref(ld);
1740 /************************************************************************
1741 * Determines when CARRIER changes state and takes appropriate
1743 ************************************************************************/
1744 static void dgap_carrier(struct channel_t *ch)
1748 int virt_carrier = 0;
1749 int phys_carrier = 0;
1751 if (!ch || ch->magic != DGAP_CHANNEL_MAGIC)
1756 if (!bd || bd->magic != DGAP_BOARD_MAGIC)
1759 /* Make sure altpin is always set correctly */
1760 if (ch->ch_digi.digi_flags & DIGI_ALTPIN) {
1764 ch->ch_dsr = DM_DSR;
1768 if (ch->ch_mistat & D_CD(ch))
1771 if (ch->ch_digi.digi_flags & DIGI_FORCEDCD)
1774 if (ch->ch_c_cflag & CLOCAL)
1778 * Test for a VIRTUAL carrier transition to HIGH.
1780 if (((ch->ch_flags & CH_FCAR) == 0) && (virt_carrier == 1)) {
1783 * When carrier rises, wake any threads waiting
1784 * for carrier in the open routine.
1787 if (waitqueue_active(&(ch->ch_flags_wait)))
1788 wake_up_interruptible(&ch->ch_flags_wait);
1792 * Test for a PHYSICAL carrier transition to HIGH.
1794 if (((ch->ch_flags & CH_CD) == 0) && (phys_carrier == 1)) {
1797 * When carrier rises, wake any threads waiting
1798 * for carrier in the open routine.
1801 if (waitqueue_active(&(ch->ch_flags_wait)))
1802 wake_up_interruptible(&ch->ch_flags_wait);
1806 * Test for a PHYSICAL transition to low, so long as we aren't
1807 * currently ignoring physical transitions (which is what "virtual
1808 * carrier" indicates).
1810 * The transition of the virtual carrier to low really doesn't
1811 * matter... it really only means "ignore carrier state", not
1812 * "make pretend that carrier is there".
1814 if ((virt_carrier == 0) &&
1815 ((ch->ch_flags & CH_CD) != 0) &&
1816 (phys_carrier == 0)) {
1819 * When carrier drops:
1821 * Drop carrier on all open units.
1823 * Flush queues, waking up any task waiting in the
1826 * Send a hangup to the control terminal.
1828 * Enable all select calls.
1830 if (waitqueue_active(&(ch->ch_flags_wait)))
1831 wake_up_interruptible(&ch->ch_flags_wait);
1833 if (ch->ch_tun.un_open_count > 0)
1834 tty_hangup(ch->ch_tun.un_tty);
1836 if (ch->ch_pun.un_open_count > 0)
1837 tty_hangup(ch->ch_pun.un_tty);
1841 * Make sure that our cached values reflect the current reality.
1843 if (virt_carrier == 1)
1844 ch->ch_flags |= CH_FCAR;
1846 ch->ch_flags &= ~CH_FCAR;
1848 if (phys_carrier == 1)
1849 ch->ch_flags |= CH_CD;
1851 ch->ch_flags &= ~CH_CD;
1854 /************************************************************************
1856 * TTY Entry points and helper functions
1858 ************************************************************************/
1864 static int dgap_tty_open(struct tty_struct *tty, struct file *file)
1866 struct board_t *brd;
1867 struct channel_t *ch;
1869 struct bs_t __iomem *bs;
1879 major = MAJOR(tty_devnum(tty));
1880 minor = MINOR(tty_devnum(tty));
1885 /* Get board pointer from our array of majors we have allocated */
1886 brd = dgap_boards_by_major[major];
1891 * If board is not yet up to a state of READY, go to
1892 * sleep waiting for it to happen or they cancel the open.
1894 rc = wait_event_interruptible(brd->state_wait,
1895 (brd->state & BOARD_READY));
1900 spin_lock_irqsave(&brd->bd_lock, lock_flags);
1902 /* The wait above should guarantee this cannot happen */
1903 if (brd->state != BOARD_READY) {
1904 spin_unlock_irqrestore(&brd->bd_lock, lock_flags);
1908 /* If opened device is greater than our number of ports, bail. */
1909 if (MINOR(tty_devnum(tty)) > brd->nasync) {
1910 spin_unlock_irqrestore(&brd->bd_lock, lock_flags);
1914 ch = brd->channels[minor];
1916 spin_unlock_irqrestore(&brd->bd_lock, lock_flags);
1920 /* Grab channel lock */
1921 spin_lock_irqsave(&ch->ch_lock, lock_flags2);
1923 /* Figure out our type */
1924 if (major == brd->dgap_serial_major) {
1925 un = &brd->channels[minor]->ch_tun;
1926 un->un_type = DGAP_SERIAL;
1927 } else if (major == brd->dgap_transparent_print_major) {
1928 un = &brd->channels[minor]->ch_pun;
1929 un->un_type = DGAP_PRINT;
1931 spin_unlock_irqrestore(&ch->ch_lock, lock_flags2);
1932 spin_unlock_irqrestore(&brd->bd_lock, lock_flags);
1936 /* Store our unit into driver_data, so we always have it available. */
1937 tty->driver_data = un;
1940 * Error if channel info pointer is NULL.
1944 spin_unlock_irqrestore(&ch->ch_lock, lock_flags2);
1945 spin_unlock_irqrestore(&brd->bd_lock, lock_flags);
1952 if (!(un->un_flags & UN_ISOPEN)) {
1953 /* Store important variables. */
1956 /* Maybe do something here to the TTY struct as well? */
1960 * Initialize if neither terminal or printer is open.
1962 if (!((ch->ch_tun.un_flags | ch->ch_pun.un_flags) & UN_ISOPEN)) {
1968 * Flush input queue.
1970 head = readw(&(bs->rx_head));
1971 writew(head, &(bs->rx_tail));
1974 ch->pscan_state = 0;
1975 ch->pscan_savechar = 0;
1977 ch->ch_c_cflag = tty->termios.c_cflag;
1978 ch->ch_c_iflag = tty->termios.c_iflag;
1979 ch->ch_c_oflag = tty->termios.c_oflag;
1980 ch->ch_c_lflag = tty->termios.c_lflag;
1981 ch->ch_startc = tty->termios.c_cc[VSTART];
1982 ch->ch_stopc = tty->termios.c_cc[VSTOP];
1984 /* TODO: flush our TTY struct here? */
1989 * Run param in case we changed anything
1994 * follow protocol for opening port
1997 spin_unlock_irqrestore(&ch->ch_lock, lock_flags2);
1998 spin_unlock_irqrestore(&brd->bd_lock, lock_flags);
2000 rc = dgap_block_til_ready(tty, file, ch);
2005 /* No going back now, increment our unit and channel counters */
2006 spin_lock_irqsave(&ch->ch_lock, lock_flags);
2007 ch->ch_open_count++;
2008 un->un_open_count++;
2009 un->un_flags |= (UN_ISOPEN);
2010 spin_unlock_irqrestore(&ch->ch_lock, lock_flags);
2016 * dgap_block_til_ready()
2018 * Wait for DCD, if needed.
2020 static int dgap_block_til_ready(struct tty_struct *tty, struct file *file,
2021 struct channel_t *ch)
2024 struct un_t *un = NULL;
2027 int sleep_on_un_flags = 0;
2029 if (!tty || tty->magic != TTY_MAGIC || !file || !ch ||
2030 ch->magic != DGAP_CHANNEL_MAGIC)
2033 un = tty->driver_data;
2034 if (!un || un->magic != DGAP_UNIT_MAGIC)
2037 spin_lock_irqsave(&ch->ch_lock, lock_flags);
2044 sleep_on_un_flags = 0;
2047 * If board has failed somehow during our sleep,
2050 if (ch->ch_bd->state == BOARD_FAILED) {
2055 /* If tty was hung up, break out of loop and set error. */
2056 if (tty_hung_up_p(file)) {
2062 * If either unit is in the middle of the fragile part of close,
2063 * we just cannot touch the channel safely.
2064 * Go back to sleep, knowing that when the channel can be
2065 * touched safely, the close routine will signal the
2066 * ch_wait_flags to wake us back up.
2068 if (!((ch->ch_tun.un_flags | ch->ch_pun.un_flags) &
2072 * Our conditions to leave cleanly and happily:
2073 * 1) NONBLOCKING on the tty is set.
2075 * 3) DCD (fake or real) is active.
2078 if (file->f_flags & O_NONBLOCK)
2081 if (tty->flags & (1 << TTY_IO_ERROR))
2084 if (ch->ch_flags & CH_CD)
2087 if (ch->ch_flags & CH_FCAR)
2090 sleep_on_un_flags = 1;
2094 * If there is a signal pending, the user probably
2095 * interrupted (ctrl-c) us.
2096 * Leave loop with error set.
2098 if (signal_pending(current)) {
2099 retval = -ERESTARTSYS;
2104 * Store the flags before we let go of channel lock
2106 if (sleep_on_un_flags)
2107 old_flags = ch->ch_tun.un_flags | ch->ch_pun.un_flags;
2109 old_flags = ch->ch_flags;
2112 * Let go of channel lock before calling schedule.
2113 * Our poller will get any FEP events and wake us up when DCD
2114 * eventually goes active.
2117 spin_unlock_irqrestore(&ch->ch_lock, lock_flags);
2120 * Wait for something in the flags to change
2121 * from the current value.
2123 if (sleep_on_un_flags) {
2124 retval = wait_event_interruptible(un->un_flags_wait,
2125 (old_flags != (ch->ch_tun.un_flags |
2126 ch->ch_pun.un_flags)));
2128 retval = wait_event_interruptible(ch->ch_flags_wait,
2129 (old_flags != ch->ch_flags));
2133 * We got woken up for some reason.
2134 * Before looping around, grab our channel lock.
2136 spin_lock_irqsave(&ch->ch_lock, lock_flags);
2141 spin_unlock_irqrestore(&ch->ch_lock, lock_flags);
2152 * Hangup the port. Like a close, but don't wait for output to drain.
2154 static void dgap_tty_hangup(struct tty_struct *tty)
2157 struct channel_t *ch;
2160 if (!tty || tty->magic != TTY_MAGIC)
2163 un = tty->driver_data;
2164 if (!un || un->magic != DGAP_UNIT_MAGIC)
2168 if (!ch || ch->magic != DGAP_CHANNEL_MAGIC)
2172 if (!bd || bd->magic != DGAP_BOARD_MAGIC)
2175 /* flush the transmit queues */
2176 dgap_tty_flush_buffer(tty);
2184 static void dgap_tty_close(struct tty_struct *tty, struct file *file)
2186 struct ktermios *ts;
2188 struct channel_t *ch;
2193 if (!tty || tty->magic != TTY_MAGIC)
2196 un = tty->driver_data;
2197 if (!un || un->magic != DGAP_UNIT_MAGIC)
2201 if (!ch || ch->magic != DGAP_CHANNEL_MAGIC)
2205 if (!bd || bd->magic != DGAP_BOARD_MAGIC)
2210 spin_lock_irqsave(&ch->ch_lock, lock_flags);
2213 * Determine if this is the last close or not - and if we agree about
2214 * which type of close it is with the Line Discipline
2216 if ((tty->count == 1) && (un->un_open_count != 1)) {
2218 * Uh, oh. tty->count is 1, which means that the tty
2219 * structure will be freed. un_open_count should always
2220 * be one in these conditions. If it's greater than
2221 * one, we've got real problems, since it means the
2222 * serial port won't be shutdown.
2224 un->un_open_count = 1;
2227 if (--un->un_open_count < 0)
2228 un->un_open_count = 0;
2230 ch->ch_open_count--;
2232 if (ch->ch_open_count && un->un_open_count) {
2233 spin_unlock_irqrestore(&ch->ch_lock, lock_flags);
2237 /* OK, its the last close on the unit */
2239 un->un_flags |= UN_CLOSING;
2244 * Only officially close channel if count is 0 and
2245 * DIGI_PRINTER bit is not set.
2247 if ((ch->ch_open_count == 0) &&
2248 !(ch->ch_digi.digi_flags & DIGI_PRINTER)) {
2250 ch->ch_flags &= ~(CH_RXBLOCK);
2252 spin_unlock_irqrestore(&ch->ch_lock, lock_flags);
2254 /* wait for output to drain */
2255 /* This will also return if we take an interrupt */
2257 rc = dgap_wait_for_drain(tty);
2259 dgap_tty_flush_buffer(tty);
2260 tty_ldisc_flush(tty);
2262 spin_lock_irqsave(&ch->ch_lock, lock_flags);
2267 * If we have HUPCL set, lower DTR and RTS
2269 if (ch->ch_c_cflag & HUPCL) {
2270 ch->ch_mostat &= ~(D_RTS(ch)|D_DTR(ch));
2271 dgap_cmdb(ch, SMODEM, 0, D_DTR(ch)|D_RTS(ch), 0);
2274 * Go to sleep to ensure RTS/DTR
2275 * have been dropped for modems to see it.
2277 if (ch->ch_close_delay) {
2278 spin_unlock_irqrestore(&ch->ch_lock,
2280 dgap_ms_sleep(ch->ch_close_delay);
2281 spin_lock_irqsave(&ch->ch_lock, lock_flags);
2285 ch->pscan_state = 0;
2286 ch->pscan_savechar = 0;
2287 ch->ch_baud_info = 0;
2292 * turn off print device when closing print device.
2294 if ((un->un_type == DGAP_PRINT) && (ch->ch_flags & CH_PRON)) {
2295 dgap_wmove(ch, ch->ch_digi.digi_offstr,
2296 (int) ch->ch_digi.digi_offlen);
2297 ch->ch_flags &= ~CH_PRON;
2301 un->un_flags &= ~(UN_ISOPEN | UN_CLOSING);
2302 tty->driver_data = NULL;
2304 wake_up_interruptible(&ch->ch_flags_wait);
2305 wake_up_interruptible(&un->un_flags_wait);
2307 spin_unlock_irqrestore(&ch->ch_lock, lock_flags);
2311 * dgap_tty_chars_in_buffer()
2313 * Return number of characters that have not been transmitted yet.
2315 * This routine is used by the line discipline to determine if there
2316 * is data waiting to be transmitted/drained/flushed or not.
2318 static int dgap_tty_chars_in_buffer(struct tty_struct *tty)
2320 struct board_t *bd = NULL;
2321 struct channel_t *ch = NULL;
2322 struct un_t *un = NULL;
2323 struct bs_t __iomem *bs;
2326 u16 thead, ttail, tmask, chead, ctail;
2327 ulong lock_flags = 0;
2328 ulong lock_flags2 = 0;
2333 un = tty->driver_data;
2334 if (!un || un->magic != DGAP_UNIT_MAGIC)
2338 if (!ch || ch->magic != DGAP_CHANNEL_MAGIC)
2342 if (!bd || bd->magic != DGAP_BOARD_MAGIC)
2349 spin_lock_irqsave(&bd->bd_lock, lock_flags);
2350 spin_lock_irqsave(&ch->ch_lock, lock_flags2);
2352 tmask = (ch->ch_tsize - 1);
2354 /* Get Transmit queue pointers */
2355 thead = readw(&(bs->tx_head)) & tmask;
2356 ttail = readw(&(bs->tx_tail)) & tmask;
2358 /* Get tbusy flag */
2359 tbusy = readb(&(bs->tbusy));
2361 /* Get Command queue pointers */
2362 chead = readw(&(ch->ch_cm->cm_head));
2363 ctail = readw(&(ch->ch_cm->cm_tail));
2365 spin_unlock_irqrestore(&ch->ch_lock, lock_flags2);
2366 spin_unlock_irqrestore(&bd->bd_lock, lock_flags);
2369 * The only way we know for sure if there is no pending
2370 * data left to be transferred, is if:
2371 * 1) Transmit head and tail are equal (empty).
2372 * 2) Command queue head and tail are equal (empty).
2373 * 3) The "TBUSY" flag is 0. (Transmitter not busy).
2376 if ((ttail == thead) && (tbusy == 0) && (chead == ctail)) {
2380 chars = thead - ttail;
2382 chars = thead - ttail + ch->ch_tsize;
2384 * Fudge factor here.
2385 * If chars is zero, we know that the command queue had
2386 * something in it or tbusy was set. Because we cannot
2387 * be sure if there is still some data to be transmitted,
2388 * lets lie, and tell ld we have 1 byte left.
2392 * If TBUSY is still set, and our tx buffers are empty,
2393 * force the firmware to send me another wakeup after
2394 * TBUSY has been cleared.
2397 spin_lock_irqsave(&ch->ch_lock, lock_flags);
2398 un->un_flags |= UN_EMPTY;
2399 writeb(1, &(bs->iempty));
2400 spin_unlock_irqrestore(&ch->ch_lock,
2410 static int dgap_wait_for_drain(struct tty_struct *tty)
2412 struct channel_t *ch;
2414 struct bs_t __iomem *bs;
2417 ulong lock_flags = 0;
2419 if (!tty || tty->magic != TTY_MAGIC)
2422 un = tty->driver_data;
2423 if (!un || un->magic != DGAP_UNIT_MAGIC)
2427 if (!ch || ch->magic != DGAP_CHANNEL_MAGIC)
2436 /* Loop until data is drained */
2437 while (count != 0) {
2439 count = dgap_tty_chars_in_buffer(tty);
2444 /* Set flag waiting for drain */
2445 spin_lock_irqsave(&ch->ch_lock, lock_flags);
2446 un->un_flags |= UN_EMPTY;
2447 writeb(1, &(bs->iempty));
2448 spin_unlock_irqrestore(&ch->ch_lock, lock_flags);
2450 /* Go to sleep till we get woken up */
2451 ret = wait_event_interruptible(un->un_flags_wait,
2452 ((un->un_flags & UN_EMPTY) == 0));
2453 /* If ret is non-zero, user ctrl-c'ed us */
2458 spin_lock_irqsave(&ch->ch_lock, lock_flags);
2459 un->un_flags &= ~(UN_EMPTY);
2460 spin_unlock_irqrestore(&ch->ch_lock, lock_flags);
2468 * Reduces bytes_available to the max number of characters
2469 * that can be sent currently given the maxcps value, and
2470 * returns the new bytes_available. This only affects printer
2473 static int dgap_maxcps_room(struct tty_struct *tty, int bytes_available)
2475 struct channel_t *ch = NULL;
2476 struct un_t *un = NULL;
2479 return bytes_available;
2481 un = tty->driver_data;
2482 if (!un || un->magic != DGAP_UNIT_MAGIC)
2483 return bytes_available;
2486 if (!ch || ch->magic != DGAP_CHANNEL_MAGIC)
2487 return bytes_available;
2490 * If its not the Transparent print device, return
2491 * the full data amount.
2493 if (un->un_type != DGAP_PRINT)
2494 return bytes_available;
2496 if (ch->ch_digi.digi_maxcps > 0 && ch->ch_digi.digi_bufsize > 0) {
2498 unsigned long current_time = jiffies;
2499 unsigned long buffer_time = current_time +
2500 (HZ * ch->ch_digi.digi_bufsize) /
2501 ch->ch_digi.digi_maxcps;
2503 if (ch->ch_cpstime < current_time) {
2504 /* buffer is empty */
2505 ch->ch_cpstime = current_time; /* reset ch_cpstime */
2506 cps_limit = ch->ch_digi.digi_bufsize;
2507 } else if (ch->ch_cpstime < buffer_time) {
2508 /* still room in the buffer */
2509 cps_limit = ((buffer_time - ch->ch_cpstime) *
2510 ch->ch_digi.digi_maxcps) / HZ;
2512 /* no room in the buffer */
2516 bytes_available = min(cps_limit, bytes_available);
2519 return bytes_available;
2522 static inline void dgap_set_firmware_event(struct un_t *un, unsigned int event)
2524 struct channel_t *ch = NULL;
2525 struct bs_t __iomem *bs = NULL;
2527 if (!un || un->magic != DGAP_UNIT_MAGIC)
2530 if (!ch || ch->magic != DGAP_CHANNEL_MAGIC)
2536 if ((event & UN_LOW) != 0) {
2537 if ((un->un_flags & UN_LOW) == 0) {
2538 un->un_flags |= UN_LOW;
2539 writeb(1, &(bs->ilow));
2542 if ((event & UN_LOW) != 0) {
2543 if ((un->un_flags & UN_EMPTY) == 0) {
2544 un->un_flags |= UN_EMPTY;
2545 writeb(1, &(bs->iempty));
2551 * dgap_tty_write_room()
2553 * Return space available in Tx buffer
2555 static int dgap_tty_write_room(struct tty_struct *tty)
2557 struct channel_t *ch = NULL;
2558 struct un_t *un = NULL;
2559 struct bs_t __iomem *bs;
2560 u16 head, tail, tmask;
2562 ulong lock_flags = 0;
2567 un = tty->driver_data;
2568 if (!un || un->magic != DGAP_UNIT_MAGIC)
2572 if (!ch || ch->magic != DGAP_CHANNEL_MAGIC)
2579 spin_lock_irqsave(&ch->ch_lock, lock_flags);
2581 tmask = ch->ch_tsize - 1;
2582 head = readw(&(bs->tx_head)) & tmask;
2583 tail = readw(&(bs->tx_tail)) & tmask;
2585 ret = tail - head - 1;
2587 ret += ch->ch_tsize;
2589 /* Limit printer to maxcps */
2590 ret = dgap_maxcps_room(tty, ret);
2593 * If we are printer device, leave space for
2594 * possibly both the on and off strings.
2596 if (un->un_type == DGAP_PRINT) {
2597 if (!(ch->ch_flags & CH_PRON))
2598 ret -= ch->ch_digi.digi_onlen;
2599 ret -= ch->ch_digi.digi_offlen;
2601 if (ch->ch_flags & CH_PRON)
2602 ret -= ch->ch_digi.digi_offlen;
2609 * Schedule FEP to wake us up if needed.
2611 * TODO: This might be overkill...
2612 * Do we really need to schedule callbacks from the FEP
2613 * in every case? Can we get smarter based on ret?
2615 dgap_set_firmware_event(un, UN_LOW | UN_EMPTY);
2616 spin_unlock_irqrestore(&ch->ch_lock, lock_flags);
2622 * dgap_tty_put_char()
2624 * Put a character into ch->ch_buf
2626 * - used by the line discipline for OPOST processing
2628 static int dgap_tty_put_char(struct tty_struct *tty, unsigned char c)
2631 * Simply call tty_write.
2633 dgap_tty_write(tty, &c, 1);
2640 * Take data from the user or kernel and send it out to the FEP.
2641 * In here exists all the Transparent Print magic as well.
2643 static int dgap_tty_write(struct tty_struct *tty, const unsigned char *buf,
2646 struct channel_t *ch = NULL;
2647 struct un_t *un = NULL;
2648 struct bs_t __iomem *bs;
2649 char __iomem *vaddr;
2650 u16 head, tail, tmask, remain;
2651 int bufcount = 0, n = 0;
2658 un = tty->driver_data;
2659 if (!un || un->magic != DGAP_UNIT_MAGIC)
2663 if (!ch || ch->magic != DGAP_CHANNEL_MAGIC)
2674 * Store original amount of characters passed in.
2675 * This helps to figure out if we should ask the FEP
2676 * to send us an event when it has more space available.
2680 spin_lock_irqsave(&ch->ch_lock, lock_flags);
2682 /* Get our space available for the channel from the board */
2683 tmask = ch->ch_tsize - 1;
2684 head = readw(&(bs->tx_head)) & tmask;
2685 tail = readw(&(bs->tx_tail)) & tmask;
2687 bufcount = tail - head - 1;
2689 bufcount += ch->ch_tsize;
2692 * Limit printer output to maxcps overall, with bursts allowed
2693 * up to bufsize characters.
2695 bufcount = dgap_maxcps_room(tty, bufcount);
2698 * Take minimum of what the user wants to send, and the
2699 * space available in the FEP buffer.
2701 count = min(count, bufcount);
2704 * Bail if no space left.
2707 dgap_set_firmware_event(un, UN_LOW | UN_EMPTY);
2708 spin_unlock_irqrestore(&ch->ch_lock, lock_flags);
2713 * Output the printer ON string, if we are in terminal mode, but
2714 * need to be in printer mode.
2716 if ((un->un_type == DGAP_PRINT) && !(ch->ch_flags & CH_PRON)) {
2717 dgap_wmove(ch, ch->ch_digi.digi_onstr,
2718 (int) ch->ch_digi.digi_onlen);
2719 head = readw(&(bs->tx_head)) & tmask;
2720 ch->ch_flags |= CH_PRON;
2724 * On the other hand, output the printer OFF string, if we are
2725 * currently in printer mode, but need to output to the terminal.
2727 if ((un->un_type != DGAP_PRINT) && (ch->ch_flags & CH_PRON)) {
2728 dgap_wmove(ch, ch->ch_digi.digi_offstr,
2729 (int) ch->ch_digi.digi_offlen);
2730 head = readw(&(bs->tx_head)) & tmask;
2731 ch->ch_flags &= ~CH_PRON;
2737 * If the write wraps over the top of the circular buffer,
2738 * move the portion up to the wrap point, and reset the
2739 * pointers to the bottom.
2741 remain = ch->ch_tstart + ch->ch_tsize - head;
2745 vaddr = ch->ch_taddr + head;
2747 memcpy_toio(vaddr, (u8 *) buf, remain);
2749 head = ch->ch_tstart;
2756 * Move rest of data.
2758 vaddr = ch->ch_taddr + head;
2761 memcpy_toio(vaddr, (u8 *) buf, remain);
2767 ch->ch_txcount += count;
2769 writew(head, &(bs->tx_head));
2772 dgap_set_firmware_event(un, UN_LOW | UN_EMPTY);
2775 * If this is the print device, and the
2776 * printer is still on, we need to turn it
2777 * off before going idle. If the buffer is
2778 * non-empty, wait until it goes empty.
2779 * Otherwise turn it off right now.
2781 if ((un->un_type == DGAP_PRINT) && (ch->ch_flags & CH_PRON)) {
2782 tail = readw(&(bs->tx_tail)) & tmask;
2785 un->un_flags |= UN_EMPTY;
2786 writeb(1, &(bs->iempty));
2788 dgap_wmove(ch, ch->ch_digi.digi_offstr,
2789 (int) ch->ch_digi.digi_offlen);
2790 head = readw(&(bs->tx_head)) & tmask;
2791 ch->ch_flags &= ~CH_PRON;
2795 /* Update printer buffer empty time. */
2796 if ((un->un_type == DGAP_PRINT) && (ch->ch_digi.digi_maxcps > 0)
2797 && (ch->ch_digi.digi_bufsize > 0)) {
2798 ch->ch_cpstime += (HZ * count) / ch->ch_digi.digi_maxcps;
2801 spin_unlock_irqrestore(&ch->ch_lock, lock_flags);
2807 * Return modem signals to ld.
2809 static int dgap_tty_tiocmget(struct tty_struct *tty)
2811 struct channel_t *ch;
2817 if (!tty || tty->magic != TTY_MAGIC)
2820 un = tty->driver_data;
2821 if (!un || un->magic != DGAP_UNIT_MAGIC)
2825 if (!ch || ch->magic != DGAP_CHANNEL_MAGIC)
2828 spin_lock_irqsave(&ch->ch_lock, lock_flags);
2830 mstat = readb(&(ch->ch_bs->m_stat));
2831 /* Append any outbound signals that might be pending... */
2832 mstat |= ch->ch_mostat;
2834 spin_unlock_irqrestore(&ch->ch_lock, lock_flags);
2838 if (mstat & D_DTR(ch))
2839 result |= TIOCM_DTR;
2840 if (mstat & D_RTS(ch))
2841 result |= TIOCM_RTS;
2842 if (mstat & D_CTS(ch))
2843 result |= TIOCM_CTS;
2844 if (mstat & D_DSR(ch))
2845 result |= TIOCM_DSR;
2846 if (mstat & D_RI(ch))
2848 if (mstat & D_CD(ch))
2855 * dgap_tty_tiocmset()
2857 * Set modem signals, called by ld.
2859 static int dgap_tty_tiocmset(struct tty_struct *tty,
2860 unsigned int set, unsigned int clear)
2863 struct channel_t *ch;
2869 if (!tty || tty->magic != TTY_MAGIC)
2872 un = tty->driver_data;
2873 if (!un || un->magic != DGAP_UNIT_MAGIC)
2877 if (!ch || ch->magic != DGAP_CHANNEL_MAGIC)
2881 if (!bd || bd->magic != DGAP_BOARD_MAGIC)
2884 spin_lock_irqsave(&bd->bd_lock, lock_flags);
2885 spin_lock_irqsave(&ch->ch_lock, lock_flags2);
2887 if (set & TIOCM_RTS) {
2888 ch->ch_mforce |= D_RTS(ch);
2889 ch->ch_mval |= D_RTS(ch);
2892 if (set & TIOCM_DTR) {
2893 ch->ch_mforce |= D_DTR(ch);
2894 ch->ch_mval |= D_DTR(ch);
2897 if (clear & TIOCM_RTS) {
2898 ch->ch_mforce |= D_RTS(ch);
2899 ch->ch_mval &= ~(D_RTS(ch));
2902 if (clear & TIOCM_DTR) {
2903 ch->ch_mforce |= D_DTR(ch);
2904 ch->ch_mval &= ~(D_DTR(ch));
2909 spin_unlock_irqrestore(&ch->ch_lock, lock_flags2);
2910 spin_unlock_irqrestore(&bd->bd_lock, lock_flags);
2916 * dgap_tty_send_break()
2918 * Send a Break, called by ld.
2920 static int dgap_tty_send_break(struct tty_struct *tty, int msec)
2923 struct channel_t *ch;
2929 if (!tty || tty->magic != TTY_MAGIC)
2932 un = tty->driver_data;
2933 if (!un || un->magic != DGAP_UNIT_MAGIC)
2937 if (!ch || ch->magic != DGAP_CHANNEL_MAGIC)
2941 if (!bd || bd->magic != DGAP_BOARD_MAGIC)
2956 spin_lock_irqsave(&bd->bd_lock, lock_flags);
2957 spin_lock_irqsave(&ch->ch_lock, lock_flags2);
2959 dgap_cmdw(ch, SBREAK, (u16) SBREAK_TIME, 0);
2961 dgap_cmdw(ch, SBREAK, (u16) msec, 0);
2963 spin_unlock_irqrestore(&ch->ch_lock, lock_flags2);
2964 spin_unlock_irqrestore(&bd->bd_lock, lock_flags);
2970 * dgap_tty_wait_until_sent()
2972 * wait until data has been transmitted, called by ld.
2974 static void dgap_tty_wait_until_sent(struct tty_struct *tty, int timeout)
2976 dgap_wait_for_drain(tty);
2982 * send a high priority character, called by ld.
2984 static void dgap_tty_send_xchar(struct tty_struct *tty, char c)
2987 struct channel_t *ch;
2992 if (!tty || tty->magic != TTY_MAGIC)
2995 un = tty->driver_data;
2996 if (!un || un->magic != DGAP_UNIT_MAGIC)
3000 if (!ch || ch->magic != DGAP_CHANNEL_MAGIC)
3004 if (!bd || bd->magic != DGAP_BOARD_MAGIC)
3007 spin_lock_irqsave(&bd->bd_lock, lock_flags);
3008 spin_lock_irqsave(&ch->ch_lock, lock_flags2);
3011 * This is technically what we should do.
3012 * However, the NIST tests specifically want
3013 * to see each XON or XOFF character that it
3014 * sends, so lets just send each character
3018 if (c == STOP_CHAR(tty))
3019 dgap_cmdw(ch, RPAUSE, 0, 0);
3020 else if (c == START_CHAR(tty))
3021 dgap_cmdw(ch, RRESUME, 0, 0);
3023 dgap_wmove(ch, &c, 1);
3025 dgap_wmove(ch, &c, 1);
3028 spin_unlock_irqrestore(&ch->ch_lock, lock_flags2);
3029 spin_unlock_irqrestore(&bd->bd_lock, lock_flags);
3035 * Return modem signals to ld.
3037 static int dgap_get_modem_info(struct channel_t *ch, unsigned int __user *value)
3044 if (!ch || ch->magic != DGAP_CHANNEL_MAGIC)
3047 spin_lock_irqsave(&ch->ch_lock, lock_flags);
3049 mstat = readb(&(ch->ch_bs->m_stat));
3050 /* Append any outbound signals that might be pending... */
3051 mstat |= ch->ch_mostat;
3053 spin_unlock_irqrestore(&ch->ch_lock, lock_flags);
3057 if (mstat & D_DTR(ch))
3058 result |= TIOCM_DTR;
3059 if (mstat & D_RTS(ch))
3060 result |= TIOCM_RTS;
3061 if (mstat & D_CTS(ch))
3062 result |= TIOCM_CTS;
3063 if (mstat & D_DSR(ch))
3064 result |= TIOCM_DSR;
3065 if (mstat & D_RI(ch))
3067 if (mstat & D_CD(ch))
3070 rc = put_user(result, value);
3076 * dgap_set_modem_info()
3078 * Set modem signals, called by ld.
3080 static int dgap_set_modem_info(struct tty_struct *tty, unsigned int command,
3081 unsigned int __user *value)
3084 struct channel_t *ch;
3087 unsigned int arg = 0;
3091 if (!tty || tty->magic != TTY_MAGIC)
3094 un = tty->driver_data;
3095 if (!un || un->magic != DGAP_UNIT_MAGIC)
3099 if (!ch || ch->magic != DGAP_CHANNEL_MAGIC)
3103 if (!bd || bd->magic != DGAP_BOARD_MAGIC)
3106 ret = get_user(arg, value);
3112 if (arg & TIOCM_RTS) {
3113 ch->ch_mforce |= D_RTS(ch);
3114 ch->ch_mval |= D_RTS(ch);
3117 if (arg & TIOCM_DTR) {
3118 ch->ch_mforce |= D_DTR(ch);
3119 ch->ch_mval |= D_DTR(ch);
3125 if (arg & TIOCM_RTS) {
3126 ch->ch_mforce |= D_RTS(ch);
3127 ch->ch_mval &= ~(D_RTS(ch));
3130 if (arg & TIOCM_DTR) {
3131 ch->ch_mforce |= D_DTR(ch);
3132 ch->ch_mval &= ~(D_DTR(ch));
3138 ch->ch_mforce = D_DTR(ch)|D_RTS(ch);
3140 if (arg & TIOCM_RTS)
3141 ch->ch_mval |= D_RTS(ch);
3143 ch->ch_mval &= ~(D_RTS(ch));
3145 if (arg & TIOCM_DTR)
3146 ch->ch_mval |= (D_DTR(ch));
3148 ch->ch_mval &= ~(D_DTR(ch));
3156 spin_lock_irqsave(&bd->bd_lock, lock_flags);
3157 spin_lock_irqsave(&ch->ch_lock, lock_flags2);
3161 spin_unlock_irqrestore(&ch->ch_lock, lock_flags2);
3162 spin_unlock_irqrestore(&bd->bd_lock, lock_flags);
3168 * dgap_tty_digigeta()
3170 * Ioctl to get the information for ditty.
3175 static int dgap_tty_digigeta(struct tty_struct *tty,
3176 struct digi_t __user *retinfo)
3178 struct channel_t *ch;
3186 if (!tty || tty->magic != TTY_MAGIC)
3189 un = tty->driver_data;
3190 if (!un || un->magic != DGAP_UNIT_MAGIC)
3194 if (!ch || ch->magic != DGAP_CHANNEL_MAGIC)
3197 memset(&tmp, 0, sizeof(tmp));
3199 spin_lock_irqsave(&ch->ch_lock, lock_flags);
3200 memcpy(&tmp, &ch->ch_digi, sizeof(tmp));
3201 spin_unlock_irqrestore(&ch->ch_lock, lock_flags);
3203 if (copy_to_user(retinfo, &tmp, sizeof(*retinfo)))
3210 * dgap_tty_digiseta()
3212 * Ioctl to set the information for ditty.
3217 static int dgap_tty_digiseta(struct tty_struct *tty,
3218 struct digi_t __user *new_info)
3221 struct channel_t *ch;
3223 struct digi_t new_digi;
3224 ulong lock_flags = 0;
3225 unsigned long lock_flags2;
3227 if (!tty || tty->magic != TTY_MAGIC)
3230 un = tty->driver_data;
3231 if (!un || un->magic != DGAP_UNIT_MAGIC)
3235 if (!ch || ch->magic != DGAP_CHANNEL_MAGIC)
3239 if (!bd || bd->magic != DGAP_BOARD_MAGIC)
3242 if (copy_from_user(&new_digi, new_info, sizeof(struct digi_t)))
3245 spin_lock_irqsave(&bd->bd_lock, lock_flags);
3246 spin_lock_irqsave(&ch->ch_lock, lock_flags2);
3248 memcpy(&ch->ch_digi, &new_digi, sizeof(struct digi_t));
3250 if (ch->ch_digi.digi_maxcps < 1)
3251 ch->ch_digi.digi_maxcps = 1;
3253 if (ch->ch_digi.digi_maxcps > 10000)
3254 ch->ch_digi.digi_maxcps = 10000;
3256 if (ch->ch_digi.digi_bufsize < 10)
3257 ch->ch_digi.digi_bufsize = 10;
3259 if (ch->ch_digi.digi_maxchar < 1)
3260 ch->ch_digi.digi_maxchar = 1;
3262 if (ch->ch_digi.digi_maxchar > ch->ch_digi.digi_bufsize)
3263 ch->ch_digi.digi_maxchar = ch->ch_digi.digi_bufsize;
3265 if (ch->ch_digi.digi_onlen > DIGI_PLEN)
3266 ch->ch_digi.digi_onlen = DIGI_PLEN;
3268 if (ch->ch_digi.digi_offlen > DIGI_PLEN)
3269 ch->ch_digi.digi_offlen = DIGI_PLEN;
3273 spin_unlock_irqrestore(&ch->ch_lock, lock_flags2);
3274 spin_unlock_irqrestore(&bd->bd_lock, lock_flags);
3280 * dgap_tty_digigetedelay()
3282 * Ioctl to get the current edelay setting.
3287 static int dgap_tty_digigetedelay(struct tty_struct *tty, int __user *retinfo)
3289 struct channel_t *ch;
3297 if (!tty || tty->magic != TTY_MAGIC)
3300 un = tty->driver_data;
3301 if (!un || un->magic != DGAP_UNIT_MAGIC)
3305 if (!ch || ch->magic != DGAP_CHANNEL_MAGIC)
3308 memset(&tmp, 0, sizeof(tmp));
3310 spin_lock_irqsave(&ch->ch_lock, lock_flags);
3311 tmp = readw(&(ch->ch_bs->edelay));
3312 spin_unlock_irqrestore(&ch->ch_lock, lock_flags);
3314 if (copy_to_user(retinfo, &tmp, sizeof(*retinfo)))
3321 * dgap_tty_digisetedelay()
3323 * Ioctl to set the EDELAY setting
3326 static int dgap_tty_digisetedelay(struct tty_struct *tty, int __user *new_info)
3329 struct channel_t *ch;
3335 if (!tty || tty->magic != TTY_MAGIC)
3338 un = tty->driver_data;
3339 if (!un || un->magic != DGAP_UNIT_MAGIC)
3343 if (!ch || ch->magic != DGAP_CHANNEL_MAGIC)
3347 if (!bd || bd->magic != DGAP_BOARD_MAGIC)
3350 if (copy_from_user(&new_digi, new_info, sizeof(int)))
3353 spin_lock_irqsave(&bd->bd_lock, lock_flags);
3354 spin_lock_irqsave(&ch->ch_lock, lock_flags2);
3356 writew((u16) new_digi, &(ch->ch_bs->edelay));
3360 spin_unlock_irqrestore(&ch->ch_lock, lock_flags2);
3361 spin_unlock_irqrestore(&bd->bd_lock, lock_flags);
3367 * dgap_tty_digigetcustombaud()
3369 * Ioctl to get the current custom baud rate setting.
3371 static int dgap_tty_digigetcustombaud(struct tty_struct *tty,
3372 int __user *retinfo)
3374 struct channel_t *ch;
3382 if (!tty || tty->magic != TTY_MAGIC)
3385 un = tty->driver_data;
3386 if (!un || un->magic != DGAP_UNIT_MAGIC)
3390 if (!ch || ch->magic != DGAP_CHANNEL_MAGIC)
3393 memset(&tmp, 0, sizeof(tmp));
3395 spin_lock_irqsave(&ch->ch_lock, lock_flags);
3396 tmp = dgap_get_custom_baud(ch);
3397 spin_unlock_irqrestore(&ch->ch_lock, lock_flags);
3399 if (copy_to_user(retinfo, &tmp, sizeof(*retinfo)))
3406 * dgap_tty_digisetcustombaud()
3408 * Ioctl to set the custom baud rate setting
3410 static int dgap_tty_digisetcustombaud(struct tty_struct *tty,
3411 int __user *new_info)
3414 struct channel_t *ch;
3420 if (!tty || tty->magic != TTY_MAGIC)
3423 un = tty->driver_data;
3424 if (!un || un->magic != DGAP_UNIT_MAGIC)
3428 if (!ch || ch->magic != DGAP_CHANNEL_MAGIC)
3432 if (!bd || bd->magic != DGAP_BOARD_MAGIC)
3436 if (copy_from_user(&new_rate, new_info, sizeof(unsigned int)))
3439 if (bd->bd_flags & BD_FEP5PLUS) {
3441 spin_lock_irqsave(&bd->bd_lock, lock_flags);
3442 spin_lock_irqsave(&ch->ch_lock, lock_flags2);
3444 ch->ch_custom_speed = new_rate;
3448 spin_unlock_irqrestore(&ch->ch_lock, lock_flags2);
3449 spin_unlock_irqrestore(&bd->bd_lock, lock_flags);
3456 * dgap_set_termios()
3458 static void dgap_tty_set_termios(struct tty_struct *tty,
3459 struct ktermios *old_termios)
3462 struct channel_t *ch;
3464 unsigned long lock_flags;
3465 unsigned long lock_flags2;
3467 if (!tty || tty->magic != TTY_MAGIC)
3470 un = tty->driver_data;
3471 if (!un || un->magic != DGAP_UNIT_MAGIC)
3475 if (!ch || ch->magic != DGAP_CHANNEL_MAGIC)
3479 if (!bd || bd->magic != DGAP_BOARD_MAGIC)
3482 spin_lock_irqsave(&bd->bd_lock, lock_flags);
3483 spin_lock_irqsave(&ch->ch_lock, lock_flags2);
3485 ch->ch_c_cflag = tty->termios.c_cflag;
3486 ch->ch_c_iflag = tty->termios.c_iflag;
3487 ch->ch_c_oflag = tty->termios.c_oflag;
3488 ch->ch_c_lflag = tty->termios.c_lflag;
3489 ch->ch_startc = tty->termios.c_cc[VSTART];
3490 ch->ch_stopc = tty->termios.c_cc[VSTOP];
3495 spin_unlock_irqrestore(&ch->ch_lock, lock_flags2);
3496 spin_unlock_irqrestore(&bd->bd_lock, lock_flags);
3499 static void dgap_tty_throttle(struct tty_struct *tty)
3502 struct channel_t *ch;
3507 if (!tty || tty->magic != TTY_MAGIC)
3510 un = tty->driver_data;
3511 if (!un || un->magic != DGAP_UNIT_MAGIC)
3515 if (!ch || ch->magic != DGAP_CHANNEL_MAGIC)
3519 if (!bd || bd->magic != DGAP_BOARD_MAGIC)
3522 spin_lock_irqsave(&bd->bd_lock, lock_flags);
3523 spin_lock_irqsave(&ch->ch_lock, lock_flags2);
3525 ch->ch_flags |= (CH_RXBLOCK);
3527 dgap_cmdw(ch, RPAUSE, 0, 0);
3530 spin_unlock_irqrestore(&ch->ch_lock, lock_flags2);
3531 spin_unlock_irqrestore(&bd->bd_lock, lock_flags);
3535 static void dgap_tty_unthrottle(struct tty_struct *tty)
3538 struct channel_t *ch;
3543 if (!tty || tty->magic != TTY_MAGIC)
3546 un = tty->driver_data;
3547 if (!un || un->magic != DGAP_UNIT_MAGIC)
3551 if (!ch || ch->magic != DGAP_CHANNEL_MAGIC)
3555 if (!bd || bd->magic != DGAP_BOARD_MAGIC)
3558 spin_lock_irqsave(&bd->bd_lock, lock_flags);
3559 spin_lock_irqsave(&ch->ch_lock, lock_flags2);
3561 ch->ch_flags &= ~(CH_RXBLOCK);
3564 dgap_cmdw(ch, RRESUME, 0, 0);
3567 spin_unlock_irqrestore(&ch->ch_lock, lock_flags2);
3568 spin_unlock_irqrestore(&bd->bd_lock, lock_flags);
3571 static void dgap_tty_start(struct tty_struct *tty)
3574 struct channel_t *ch;
3579 if (!tty || tty->magic != TTY_MAGIC)
3582 un = tty->driver_data;
3583 if (!un || un->magic != DGAP_UNIT_MAGIC)
3587 if (!ch || ch->magic != DGAP_CHANNEL_MAGIC)
3591 if (!bd || bd->magic != DGAP_BOARD_MAGIC)
3594 spin_lock_irqsave(&bd->bd_lock, lock_flags);
3595 spin_lock_irqsave(&ch->ch_lock, lock_flags2);
3597 dgap_cmdw(ch, RESUMETX, 0, 0);
3599 spin_unlock_irqrestore(&ch->ch_lock, lock_flags2);
3600 spin_unlock_irqrestore(&bd->bd_lock, lock_flags);
3604 static void dgap_tty_stop(struct tty_struct *tty)
3607 struct channel_t *ch;
3612 if (!tty || tty->magic != TTY_MAGIC)
3615 un = tty->driver_data;
3616 if (!un || un->magic != DGAP_UNIT_MAGIC)
3620 if (!ch || ch->magic != DGAP_CHANNEL_MAGIC)
3624 if (!bd || bd->magic != DGAP_BOARD_MAGIC)
3627 spin_lock_irqsave(&bd->bd_lock, lock_flags);
3628 spin_lock_irqsave(&ch->ch_lock, lock_flags2);
3630 dgap_cmdw(ch, PAUSETX, 0, 0);
3632 spin_unlock_irqrestore(&ch->ch_lock, lock_flags2);
3633 spin_unlock_irqrestore(&bd->bd_lock, lock_flags);
3638 * dgap_tty_flush_chars()
3640 * Flush the cook buffer
3642 * Note to self, and any other poor souls who venture here:
3644 * flush in this case DOES NOT mean dispose of the data.
3645 * instead, it means "stop buffering and send it if you
3646 * haven't already." Just guess how I figured that out... SRW 2-Jun-98
3648 * It is also always called in interrupt context - JAR 8-Sept-99
3650 static void dgap_tty_flush_chars(struct tty_struct *tty)
3653 struct channel_t *ch;
3658 if (!tty || tty->magic != TTY_MAGIC)
3661 un = tty->driver_data;
3662 if (!un || un->magic != DGAP_UNIT_MAGIC)
3666 if (!ch || ch->magic != DGAP_CHANNEL_MAGIC)
3670 if (!bd || bd->magic != DGAP_BOARD_MAGIC)
3673 spin_lock_irqsave(&bd->bd_lock, lock_flags);
3674 spin_lock_irqsave(&ch->ch_lock, lock_flags2);
3676 /* TODO: Do something here */
3678 spin_unlock_irqrestore(&ch->ch_lock, lock_flags2);
3679 spin_unlock_irqrestore(&bd->bd_lock, lock_flags);
3683 * dgap_tty_flush_buffer()
3685 * Flush Tx buffer (make in == out)
3687 static void dgap_tty_flush_buffer(struct tty_struct *tty)
3690 struct channel_t *ch;
3696 if (!tty || tty->magic != TTY_MAGIC)
3699 un = tty->driver_data;
3700 if (!un || un->magic != DGAP_UNIT_MAGIC)
3704 if (!ch || ch->magic != DGAP_CHANNEL_MAGIC)
3708 if (!bd || bd->magic != DGAP_BOARD_MAGIC)
3711 spin_lock_irqsave(&bd->bd_lock, lock_flags);
3712 spin_lock_irqsave(&ch->ch_lock, lock_flags2);
3714 ch->ch_flags &= ~CH_STOP;
3715 head = readw(&(ch->ch_bs->tx_head));
3716 dgap_cmdw(ch, FLUSHTX, (u16) head, 0);
3717 dgap_cmdw(ch, RESUMETX, 0, 0);
3718 if (ch->ch_tun.un_flags & (UN_LOW|UN_EMPTY)) {
3719 ch->ch_tun.un_flags &= ~(UN_LOW|UN_EMPTY);
3720 wake_up_interruptible(&ch->ch_tun.un_flags_wait);
3722 if (ch->ch_pun.un_flags & (UN_LOW|UN_EMPTY)) {
3723 ch->ch_pun.un_flags &= ~(UN_LOW|UN_EMPTY);
3724 wake_up_interruptible(&ch->ch_pun.un_flags_wait);
3727 spin_unlock_irqrestore(&ch->ch_lock, lock_flags2);
3728 spin_unlock_irqrestore(&bd->bd_lock, lock_flags);
3729 if (waitqueue_active(&tty->write_wait))
3730 wake_up_interruptible(&tty->write_wait);
3734 /*****************************************************************************
3736 * The IOCTL function and all of its helpers
3738 *****************************************************************************/
3743 * The usual assortment of ioctl's
3745 static int dgap_tty_ioctl(struct tty_struct *tty, unsigned int cmd,
3749 struct channel_t *ch;
3753 ulong lock_flags = 0;
3754 ulong lock_flags2 = 0;
3755 void __user *uarg = (void __user *) arg;
3757 if (!tty || tty->magic != TTY_MAGIC)
3760 un = tty->driver_data;
3761 if (!un || un->magic != DGAP_UNIT_MAGIC)
3765 if (!ch || ch->magic != DGAP_CHANNEL_MAGIC)
3769 if (!bd || bd->magic != DGAP_BOARD_MAGIC)
3772 spin_lock_irqsave(&bd->bd_lock, lock_flags);
3773 spin_lock_irqsave(&ch->ch_lock, lock_flags2);
3775 if (un->un_open_count <= 0) {
3776 spin_unlock_irqrestore(&ch->ch_lock, lock_flags2);
3777 spin_unlock_irqrestore(&bd->bd_lock, lock_flags);
3783 /* Here are all the standard ioctl's that we MUST implement */
3787 * TCSBRK is SVID version: non-zero arg --> no break
3788 * this behaviour is exploited by tcdrain().
3790 * According to POSIX.1 spec (7.2.2.1.2) breaks should be
3791 * between 0.25 and 0.5 seconds so we'll ask for something
3792 * in the middle: 0.375 seconds.
3794 rc = tty_check_change(tty);
3795 spin_unlock_irqrestore(&ch->ch_lock, lock_flags2);
3796 spin_unlock_irqrestore(&bd->bd_lock, lock_flags);
3800 rc = dgap_wait_for_drain(tty);
3805 spin_lock_irqsave(&bd->bd_lock, lock_flags);
3806 spin_lock_irqsave(&ch->ch_lock, lock_flags2);
3808 if (((cmd == TCSBRK) && (!arg)) || (cmd == TCSBRKP))
3809 dgap_cmdw(ch, SBREAK, (u16) SBREAK_TIME, 0);
3811 spin_unlock_irqrestore(&ch->ch_lock, lock_flags2);
3812 spin_unlock_irqrestore(&bd->bd_lock, lock_flags);
3817 /* support for POSIX tcsendbreak()
3819 * According to POSIX.1 spec (7.2.2.1.2) breaks should be
3820 * between 0.25 and 0.5 seconds so we'll ask for something
3821 * in the middle: 0.375 seconds.
3823 rc = tty_check_change(tty);
3824 spin_unlock_irqrestore(&ch->ch_lock, lock_flags2);
3825 spin_unlock_irqrestore(&bd->bd_lock, lock_flags);
3829 rc = dgap_wait_for_drain(tty);
3833 spin_lock_irqsave(&bd->bd_lock, lock_flags);
3834 spin_lock_irqsave(&ch->ch_lock, lock_flags2);
3836 dgap_cmdw(ch, SBREAK, (u16) SBREAK_TIME, 0);
3838 spin_unlock_irqrestore(&ch->ch_lock, lock_flags2);
3839 spin_unlock_irqrestore(&bd->bd_lock, lock_flags);
3845 * FEP5 doesn't support turning on a break unconditionally.
3846 * The FEP5 device will stop sending a break automatically
3847 * after the specified time value that was sent when turning on
3850 rc = tty_check_change(tty);
3851 spin_unlock_irqrestore(&ch->ch_lock, lock_flags2);
3852 spin_unlock_irqrestore(&bd->bd_lock, lock_flags);
3856 rc = dgap_wait_for_drain(tty);
3860 spin_lock_irqsave(&bd->bd_lock, lock_flags);
3861 spin_lock_irqsave(&ch->ch_lock, lock_flags2);
3863 dgap_cmdw(ch, SBREAK, (u16) SBREAK_TIME, 0);
3865 spin_unlock_irqrestore(&ch->ch_lock, lock_flags2);
3866 spin_unlock_irqrestore(&bd->bd_lock, lock_flags);
3872 * FEP5 doesn't support turning off a break unconditionally.
3873 * The FEP5 device will stop sending a break automatically
3874 * after the specified time value that was sent when turning on
3877 spin_unlock_irqrestore(&ch->ch_lock, lock_flags2);
3878 spin_unlock_irqrestore(&bd->bd_lock, lock_flags);
3883 spin_unlock_irqrestore(&ch->ch_lock, lock_flags2);
3884 spin_unlock_irqrestore(&bd->bd_lock, lock_flags);
3886 rc = put_user(C_CLOCAL(tty) ? 1 : 0,
3887 (unsigned long __user *) arg);
3891 spin_unlock_irqrestore(&ch->ch_lock, lock_flags2);
3892 spin_unlock_irqrestore(&bd->bd_lock, lock_flags);
3894 rc = get_user(arg, (unsigned long __user *) arg);
3898 spin_lock_irqsave(&bd->bd_lock, lock_flags);
3899 spin_lock_irqsave(&ch->ch_lock, lock_flags2);
3900 tty->termios.c_cflag = ((tty->termios.c_cflag & ~CLOCAL) |
3901 (arg ? CLOCAL : 0));
3903 spin_unlock_irqrestore(&ch->ch_lock, lock_flags2);
3904 spin_unlock_irqrestore(&bd->bd_lock, lock_flags);
3909 spin_unlock_irqrestore(&ch->ch_lock, lock_flags2);
3910 spin_unlock_irqrestore(&bd->bd_lock, lock_flags);
3911 return dgap_get_modem_info(ch, uarg);
3916 spin_unlock_irqrestore(&ch->ch_lock, lock_flags2);
3917 spin_unlock_irqrestore(&bd->bd_lock, lock_flags);
3918 return dgap_set_modem_info(tty, cmd, uarg);
3921 * Here are any additional ioctl's that we want to implement
3926 * The linux tty driver doesn't have a flush
3927 * input routine for the driver, assuming all backed
3928 * up data is in the line disc. buffers. However,
3929 * we all know that's not the case. Here, we
3930 * act on the ioctl, but then lie and say we didn't
3931 * so the line discipline will process the flush
3934 rc = tty_check_change(tty);
3936 spin_unlock_irqrestore(&ch->ch_lock, lock_flags2);
3937 spin_unlock_irqrestore(&bd->bd_lock, lock_flags);
3941 if ((arg == TCIFLUSH) || (arg == TCIOFLUSH)) {
3942 if (!(un->un_type == DGAP_PRINT)) {
3943 head = readw(&(ch->ch_bs->rx_head));
3944 writew(head, &(ch->ch_bs->rx_tail));
3945 writeb(0, &(ch->ch_bs->orun));
3949 if ((arg != TCOFLUSH) && (arg != TCIOFLUSH)) {
3950 /* pretend we didn't recognize this IOCTL */
3951 spin_unlock_irqrestore(&ch->ch_lock, lock_flags2);
3952 spin_unlock_irqrestore(&bd->bd_lock, lock_flags);
3954 return -ENOIOCTLCMD;
3957 ch->ch_flags &= ~CH_STOP;
3958 head = readw(&(ch->ch_bs->tx_head));
3959 dgap_cmdw(ch, FLUSHTX, (u16) head, 0);
3960 dgap_cmdw(ch, RESUMETX, 0, 0);
3961 if (ch->ch_tun.un_flags & (UN_LOW|UN_EMPTY)) {
3962 ch->ch_tun.un_flags &= ~(UN_LOW|UN_EMPTY);
3963 wake_up_interruptible(&ch->ch_tun.un_flags_wait);
3965 if (ch->ch_pun.un_flags & (UN_LOW|UN_EMPTY)) {
3966 ch->ch_pun.un_flags &= ~(UN_LOW|UN_EMPTY);
3967 wake_up_interruptible(&ch->ch_pun.un_flags_wait);
3969 if (waitqueue_active(&tty->write_wait))
3970 wake_up_interruptible(&tty->write_wait);
3972 /* Can't hold any locks when calling tty_wakeup! */
3973 spin_unlock_irqrestore(&ch->ch_lock, lock_flags2);
3974 spin_unlock_irqrestore(&bd->bd_lock, lock_flags);
3977 /* pretend we didn't recognize this IOCTL */
3978 return -ENOIOCTLCMD;
3983 * The linux tty driver doesn't have a flush
3984 * input routine for the driver, assuming all backed
3985 * up data is in the line disc. buffers. However,
3986 * we all know that's not the case. Here, we
3987 * act on the ioctl, but then lie and say we didn't
3988 * so the line discipline will process the flush
3991 if (cmd == TCSETSF) {
3993 ch->ch_flags &= ~CH_STOP;
3994 head = readw(&(ch->ch_bs->rx_head));
3995 writew(head, &(ch->ch_bs->rx_tail));
3998 /* now wait for all the output to drain */
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 spin_unlock_irqrestore(&ch->ch_lock, lock_flags2);
4011 spin_unlock_irqrestore(&bd->bd_lock, lock_flags);
4012 rc = dgap_wait_for_drain(tty);
4016 /* pretend we didn't recognize this */
4017 return -ENOIOCTLCMD;
4021 * The Linux Line Discipline (LD) would do this for us if we
4022 * let it, but we have the special firmware options to do this
4023 * the "right way" regardless of hardware or software flow
4024 * control so we'll do it outselves instead of letting the LD
4027 rc = tty_check_change(tty);
4029 spin_unlock_irqrestore(&ch->ch_lock, lock_flags2);
4030 spin_unlock_irqrestore(&bd->bd_lock, lock_flags);
4037 spin_unlock_irqrestore(&ch->ch_lock, lock_flags2);
4038 spin_unlock_irqrestore(&bd->bd_lock, lock_flags);
4039 dgap_tty_start(tty);
4042 spin_unlock_irqrestore(&ch->ch_lock, lock_flags2);
4043 spin_unlock_irqrestore(&bd->bd_lock, lock_flags);
4047 spin_unlock_irqrestore(&ch->ch_lock, lock_flags2);
4048 spin_unlock_irqrestore(&bd->bd_lock, lock_flags);
4049 /* Make the ld do it */
4050 return -ENOIOCTLCMD;
4052 spin_unlock_irqrestore(&ch->ch_lock, lock_flags2);
4053 spin_unlock_irqrestore(&bd->bd_lock, lock_flags);
4054 /* Make the ld do it */
4055 return -ENOIOCTLCMD;
4057 spin_unlock_irqrestore(&ch->ch_lock, lock_flags2);
4058 spin_unlock_irqrestore(&bd->bd_lock, lock_flags);
4063 /* get information for ditty */
4064 spin_unlock_irqrestore(&ch->ch_lock, lock_flags2);
4065 spin_unlock_irqrestore(&bd->bd_lock, lock_flags);
4066 return dgap_tty_digigeta(tty, uarg);
4071 /* set information for ditty */
4072 if (cmd == (DIGI_SETAW)) {
4074 spin_unlock_irqrestore(&ch->ch_lock, lock_flags2);
4075 spin_unlock_irqrestore(&bd->bd_lock, lock_flags);
4076 rc = dgap_wait_for_drain(tty);
4079 spin_lock_irqsave(&bd->bd_lock, lock_flags);
4080 spin_lock_irqsave(&ch->ch_lock, lock_flags2);
4082 tty_ldisc_flush(tty);
4086 spin_unlock_irqrestore(&ch->ch_lock, lock_flags2);
4087 spin_unlock_irqrestore(&bd->bd_lock, lock_flags);
4088 return dgap_tty_digiseta(tty, uarg);
4091 spin_unlock_irqrestore(&ch->ch_lock, lock_flags2);
4092 spin_unlock_irqrestore(&bd->bd_lock, lock_flags);
4093 return dgap_tty_digigetedelay(tty, uarg);
4096 spin_unlock_irqrestore(&ch->ch_lock, lock_flags2);
4097 spin_unlock_irqrestore(&bd->bd_lock, lock_flags);
4098 return dgap_tty_digisetedelay(tty, uarg);
4100 case DIGI_GETCUSTOMBAUD:
4101 spin_unlock_irqrestore(&ch->ch_lock, lock_flags2);
4102 spin_unlock_irqrestore(&bd->bd_lock, lock_flags);
4103 return dgap_tty_digigetcustombaud(tty, uarg);
4105 case DIGI_SETCUSTOMBAUD:
4106 spin_unlock_irqrestore(&ch->ch_lock, lock_flags2);
4107 spin_unlock_irqrestore(&bd->bd_lock, lock_flags);
4108 return dgap_tty_digisetcustombaud(tty, uarg);
4110 case DIGI_RESET_PORT:
4111 dgap_firmware_reset_port(ch);
4113 spin_unlock_irqrestore(&ch->ch_lock, lock_flags2);
4114 spin_unlock_irqrestore(&bd->bd_lock, lock_flags);
4118 spin_unlock_irqrestore(&ch->ch_lock, lock_flags2);
4119 spin_unlock_irqrestore(&bd->bd_lock, lock_flags);
4121 return -ENOIOCTLCMD;
4125 static int dgap_after_config_loaded(int board)
4128 * Initialize KME waitqueues...
4130 init_waitqueue_head(&(dgap_board[board]->kme_wait));
4133 * allocate flip buffer for board.
4135 dgap_board[board]->flipbuf = kmalloc(MYFLIPLEN, GFP_ATOMIC);
4136 if (!dgap_board[board]->flipbuf)
4139 dgap_board[board]->flipflagbuf = kmalloc(MYFLIPLEN, GFP_ATOMIC);
4140 if (!dgap_board[board]->flipflagbuf) {
4141 kfree(dgap_board[board]->flipbuf);
4149 * Create pr and tty device entries
4151 static int dgap_tty_register_ports(struct board_t *brd)
4153 struct channel_t *ch;
4156 brd->serial_ports = kcalloc(brd->nasync, sizeof(*brd->serial_ports),
4158 if (brd->serial_ports == NULL)
4160 for (i = 0; i < brd->nasync; i++)
4161 tty_port_init(&brd->serial_ports[i]);
4163 brd->printer_ports = kcalloc(brd->nasync, sizeof(*brd->printer_ports),
4165 if (brd->printer_ports == NULL) {
4166 kfree(brd->serial_ports);
4169 for (i = 0; i < brd->nasync; i++)
4170 tty_port_init(&brd->printer_ports[i]);
4172 ch = brd->channels[0];
4173 for (i = 0; i < brd->nasync; i++, ch = brd->channels[i]) {
4175 struct device *classp;
4177 classp = tty_port_register_device(&brd->serial_ports[i],
4179 brd->firstminor + i, NULL);
4181 dgap_create_tty_sysfs(&ch->ch_tun, classp);
4182 ch->ch_tun.un_sysfs = classp;
4184 classp = tty_port_register_device(&brd->printer_ports[i],
4186 brd->firstminor + i, NULL);
4188 dgap_create_tty_sysfs(&ch->ch_pun, classp);
4189 ch->ch_pun.un_sysfs = classp;
4191 dgap_create_ports_sysfiles(brd);
4197 * Copies the BIOS code from the user to the board,
4198 * and starts the BIOS running.
4200 static void dgap_do_bios_load(struct board_t *brd, const u8 *ubios, int len)
4206 if (!brd || (brd->magic != DGAP_BOARD_MAGIC) || !brd->re_map_membase)
4209 addr = brd->re_map_membase;
4214 for (i = 0; i < 16; i++)
4215 writeb(0, addr + POSTAREA + i);
4221 memcpy_toio(addr + offset, ubios, len);
4223 writel(0x0bf00401, addr);
4224 writel(0, (addr + 4));
4226 /* Clear the reset, and change states. */
4227 writeb(FEPCLR, brd->re_map_port);
4231 * Checks to see if the BIOS completed running on the card.
4233 static int dgap_test_bios(struct board_t *brd)
4240 if (!brd || (brd->magic != DGAP_BOARD_MAGIC) || !brd->re_map_membase)
4243 addr = brd->re_map_membase;
4244 word = readw(addr + POSTAREA);
4247 * It can take 5-6 seconds for a board to
4248 * pass the bios self test and post results.
4249 * Give it 10 seconds.
4251 brd->wait_for_bios = 0;
4252 while (brd->wait_for_bios < 1000) {
4253 /* Check to see if BIOS thinks board is good. (GD). */
4254 if (word == *(u16 *) "GD")
4256 msleep_interruptible(10);
4257 brd->wait_for_bios++;
4258 word = readw(addr + POSTAREA);
4261 /* Gave up on board after too long of time taken */
4262 err1 = readw(addr + SEQUENCE);
4263 err2 = readw(addr + ERROR);
4264 pr_warn("dgap: %s failed diagnostics. Error #(%x,%x).\n",
4265 brd->name, err1, err2);
4266 brd->state = BOARD_FAILED;
4267 brd->dpastatus = BD_NOBIOS;
4273 * Copies the FEP code from the user to the board,
4274 * and starts the FEP running.
4276 static void dgap_do_fep_load(struct board_t *brd, const u8 *ufep, int len)
4281 if (!brd || (brd->magic != DGAP_BOARD_MAGIC) || !brd->re_map_membase)
4284 addr = brd->re_map_membase;
4290 memcpy_toio(addr + offset, ufep, len);
4293 * If board is a concentrator product, we need to give
4294 * it its config string describing how the concentrators look.
4296 if ((brd->type == PCX) || (brd->type == PEPC)) {
4302 xconfig = dgap_create_config_string(brd, string);
4304 /* Write string to board memory */
4305 config = addr + CONFIG;
4306 for (; i < CONFIGSIZE; i++, config++, xconfig++) {
4307 writeb(*xconfig, config);
4308 if ((*xconfig & 0xff) == 0xff)
4313 writel(0xbfc01004, (addr + 0xc34));
4314 writel(0x3, (addr + 0xc30));
4319 * Waits for the FEP to report thats its ready for us to use.
4321 static int dgap_test_fep(struct board_t *brd)
4328 if (!brd || (brd->magic != DGAP_BOARD_MAGIC) || !brd->re_map_membase)
4331 addr = brd->re_map_membase;
4332 word = readw(addr + FEPSTAT);
4335 * It can take 2-3 seconds for the FEP to
4336 * be up and running. Give it 5 secs.
4338 brd->wait_for_fep = 0;
4339 while (brd->wait_for_fep < 500) {
4340 /* Check to see if FEP is up and running now. */
4341 if (word == *(u16 *) "OS") {
4343 * Check to see if the board can support FEP5+ commands.
4345 word = readw(addr + FEP5_PLUS);
4346 if (word == *(u16 *) "5A")
4347 brd->bd_flags |= BD_FEP5PLUS;
4351 msleep_interruptible(10);
4352 brd->wait_for_fep++;
4353 word = readw(addr + FEPSTAT);
4356 /* Gave up on board after too long of time taken */
4357 err1 = readw(addr + SEQUENCE);
4358 err2 = readw(addr + ERROR);
4359 pr_warn("dgap: FEPOS for %s not functioning. Error #(%x,%x).\n",
4360 brd->name, err1, err2);
4361 brd->state = BOARD_FAILED;
4362 brd->dpastatus = BD_NOFEP;
4368 * Physically forces the FEP5 card to reset itself.
4370 static void dgap_do_reset_board(struct board_t *brd)
4377 if (!brd || (brd->magic != DGAP_BOARD_MAGIC) ||
4378 !brd->re_map_membase || !brd->re_map_port)
4381 /* FEPRST does not vary among supported boards */
4382 writeb(FEPRST, brd->re_map_port);
4384 for (i = 0; i <= 1000; i++) {
4385 check = readb(brd->re_map_port) & 0xe;
4386 if (check == FEPRST)
4392 pr_warn("dgap: Board not resetting... Failing board.\n");
4393 brd->state = BOARD_FAILED;
4394 brd->dpastatus = BD_NOFEP;
4399 * Make sure there really is memory out there.
4401 writel(0xa55a3cc3, (brd->re_map_membase + LOWMEM));
4402 writel(0x5aa5c33c, (brd->re_map_membase + HIGHMEM));
4403 check1 = readl(brd->re_map_membase + LOWMEM);
4404 check2 = readl(brd->re_map_membase + HIGHMEM);
4406 if ((check1 != 0xa55a3cc3) || (check2 != 0x5aa5c33c)) {
4407 pr_warn("dgap: No memory at %p for board.\n",
4408 brd->re_map_membase);
4409 brd->state = BOARD_FAILED;
4410 brd->dpastatus = BD_NOFEP;
4416 #ifdef DIGI_CONCENTRATORS_SUPPORTED
4418 * Sends a concentrator image into the FEP5 board.
4420 static void dgap_do_conc_load(struct board_t *brd, u8 *uaddr, int len)
4422 char __iomem *vaddr;
4424 struct downld_t *to_dp;
4426 if (!brd || (brd->magic != DGAP_BOARD_MAGIC) || !brd->re_map_membase)
4429 vaddr = brd->re_map_membase;
4431 offset = readw((u16 *) (vaddr + DOWNREQ));
4432 to_dp = (struct downld_t *) (vaddr + (int) offset);
4433 memcpy_toio(to_dp, uaddr, len);
4435 /* Tell card we have data for it */
4436 writew(0, vaddr + (DOWNREQ));
4438 brd->conc_dl_status = NO_PENDING_CONCENTRATOR_REQUESTS;
4442 #define EXPANSION_ROM_SIZE (64 * 1024)
4443 #define FEP5_ROM_MAGIC (0xFEFFFFFF)
4445 static void dgap_get_vpd(struct board_t *brd)
4457 * Poke the magic number at the PCI Rom Address location.
4458 * If VPD is supported, the value read from that address
4461 magic = FEP5_ROM_MAGIC;
4462 pci_write_config_dword(brd->pdev, PCI_ROM_ADDRESS, magic);
4463 pci_read_config_dword(brd->pdev, PCI_ROM_ADDRESS, &magic);
4465 /* VPD not supported, bail */
4470 * To get to the OTPROM memory, we have to send the boards base
4471 * address or'ed with 1 into the PCI Rom Address location.
4473 magic = brd->membase | 0x01;
4474 pci_write_config_dword(brd->pdev, PCI_ROM_ADDRESS, magic);
4475 pci_read_config_dword(brd->pdev, PCI_ROM_ADDRESS, &magic);
4477 byte1 = readb(brd->re_map_membase);
4478 byte2 = readb(brd->re_map_membase + 1);
4481 * If the board correctly swapped to the OTPROM memory,
4482 * the first 2 bytes (header) should be 0x55, 0xAA
4484 if (byte1 == 0x55 && byte2 == 0xAA) {
4489 * We have to run through all the OTPROM memory looking
4490 * for the VPD offset.
4492 while (base_offset <= EXPANSION_ROM_SIZE) {
4495 * Lots of magic numbers here.
4497 * The VPD offset is located inside the ROM Data
4500 * We also have to remember the length of each
4501 * ROM Data Structure, so we can "hop" to the next
4502 * entry if the VPD isn't in the current
4503 * ROM Data Structure.
4505 rom_offset = readw(brd->re_map_membase +
4506 base_offset + 0x18);
4507 image_length = readw(brd->re_map_membase +
4508 rom_offset + 0x10) * 512;
4509 vpd_offset = readw(brd->re_map_membase +
4512 /* Found the VPD entry */
4516 /* We didn't find a VPD entry, go to next ROM entry. */
4517 base_offset += image_length;
4519 byte1 = readb(brd->re_map_membase + base_offset);
4520 byte2 = readb(brd->re_map_membase + base_offset + 1);
4523 * If the new ROM offset doesn't have 0x55, 0xAA
4524 * as its header, we have run out of ROM.
4526 if (byte1 != 0x55 || byte2 != 0xAA)
4531 * If we have a VPD offset, then mark the board
4532 * as having a valid VPD, and copy VPDSIZE (512) bytes of
4533 * that VPD to the buffer we have in our board structure.
4536 brd->bd_flags |= BD_HAS_VPD;
4537 for (i = 0; i < VPDSIZE; i++) {
4538 brd->vpd[i] = readb(brd->re_map_membase +
4545 * We MUST poke the magic number at the PCI Rom Address location again.
4546 * This makes the card report the regular board memory back to us,
4547 * rather than the OTPROM memory.
4549 magic = FEP5_ROM_MAGIC;
4550 pci_write_config_dword(brd->pdev, PCI_ROM_ADDRESS, magic);
4554 * Our board poller function.
4556 static void dgap_poll_tasklet(unsigned long data)
4558 struct board_t *bd = (struct board_t *) data;
4560 char __iomem *vaddr;
4563 if (!bd || (bd->magic != DGAP_BOARD_MAGIC))
4566 if (bd->inhibit_poller)
4569 spin_lock_irqsave(&bd->bd_lock, lock_flags);
4571 vaddr = bd->re_map_membase;
4574 * If board is ready, parse deeper to see if there is anything to do.
4576 if (bd->state == BOARD_READY) {
4578 struct ev_t __iomem *eaddr;
4580 if (!bd->re_map_membase) {
4581 spin_unlock_irqrestore(&bd->bd_lock, lock_flags);
4584 if (!bd->re_map_port) {
4585 spin_unlock_irqrestore(&bd->bd_lock, lock_flags);
4592 eaddr = (struct ev_t __iomem *) (vaddr + EVBUF);
4594 /* Get our head and tail */
4595 head = readw(&(eaddr->ev_head));
4596 tail = readw(&(eaddr->ev_tail));
4599 * If there is an event pending. Go service it.
4602 spin_unlock_irqrestore(&bd->bd_lock, lock_flags);
4604 spin_lock_irqsave(&bd->bd_lock, lock_flags);
4609 * If board is doing interrupts, ACK the interrupt.
4611 if (bd && bd->intr_running)
4612 readb(bd->re_map_port + 2);
4614 spin_unlock_irqrestore(&bd->bd_lock, lock_flags);
4618 spin_unlock_irqrestore(&bd->bd_lock, lock_flags);
4621 /*=======================================================================
4623 * dgap_cmdb - Sends a 2 byte command to the FEP.
4625 * ch - Pointer to channel structure.
4626 * cmd - Command to be sent.
4627 * byte1 - Integer containing first byte to be sent.
4628 * byte2 - Integer containing second byte to be sent.
4629 * ncmds - Wait until ncmds or fewer cmds are left
4630 * in the cmd buffer before returning.
4632 *=======================================================================*/
4633 static void dgap_cmdb(struct channel_t *ch, u8 cmd, u8 byte1,
4634 u8 byte2, uint ncmds)
4636 char __iomem *vaddr;
4637 struct __iomem cm_t *cm_addr;
4643 if (!ch || ch->magic != DGAP_CHANNEL_MAGIC)
4647 * Check if board is still alive.
4649 if (ch->ch_bd->state == BOARD_FAILED)
4653 * Make sure the pointers are in range before
4654 * writing to the FEP memory.
4656 vaddr = ch->ch_bd->re_map_membase;
4661 cm_addr = (struct cm_t __iomem *) (vaddr + CMDBUF);
4662 head = readw(&(cm_addr->cm_head));
4665 * Forget it if pointers out of range.
4667 if (head >= (CMDMAX - CMDSTART) || (head & 03)) {
4668 ch->ch_bd->state = BOARD_FAILED;
4673 * Put the data in the circular command buffer.
4675 writeb(cmd, (vaddr + head + CMDSTART + 0));
4676 writeb((u8) ch->ch_portnum, (vaddr + head + CMDSTART + 1));
4677 writeb(byte1, (vaddr + head + CMDSTART + 2));
4678 writeb(byte2, (vaddr + head + CMDSTART + 3));
4680 head = (head + 4) & (CMDMAX - CMDSTART - 4);
4682 writew(head, &(cm_addr->cm_head));
4685 * Wait if necessary before updating the head
4686 * pointer to limit the number of outstanding
4687 * commands to the FEP. If the time spent waiting
4688 * is outlandish, declare the FEP dead.
4690 for (count = dgap_count ;;) {
4692 head = readw(&(cm_addr->cm_head));
4693 tail = readw(&(cm_addr->cm_tail));
4695 n = (head - tail) & (CMDMAX - CMDSTART - 4);
4697 if (n <= ncmds * sizeof(struct cm_t))
4701 ch->ch_bd->state = BOARD_FAILED;
4708 /*=======================================================================
4710 * dgap_cmdw - Sends a 1 word command to the FEP.
4712 * ch - Pointer to channel structure.
4713 * cmd - Command to be sent.
4714 * word - Integer containing word to be sent.
4715 * ncmds - Wait until ncmds or fewer cmds are left
4716 * in the cmd buffer before returning.
4718 *=======================================================================*/
4719 static void dgap_cmdw(struct channel_t *ch, u8 cmd, u16 word, uint ncmds)
4721 char __iomem *vaddr;
4722 struct __iomem cm_t *cm_addr;
4728 if (!ch || ch->magic != DGAP_CHANNEL_MAGIC)
4732 * Check if board is still alive.
4734 if (ch->ch_bd->state == BOARD_FAILED)
4738 * Make sure the pointers are in range before
4739 * writing to the FEP memory.
4741 vaddr = ch->ch_bd->re_map_membase;
4745 cm_addr = (struct cm_t __iomem *) (vaddr + CMDBUF);
4746 head = readw(&(cm_addr->cm_head));
4749 * Forget it if pointers out of range.
4751 if (head >= (CMDMAX - CMDSTART) || (head & 03)) {
4752 ch->ch_bd->state = BOARD_FAILED;
4757 * Put the data in the circular command buffer.
4759 writeb(cmd, (vaddr + head + CMDSTART + 0));
4760 writeb((u8) ch->ch_portnum, (vaddr + head + CMDSTART + 1));
4761 writew((u16) word, (vaddr + head + CMDSTART + 2));
4763 head = (head + 4) & (CMDMAX - CMDSTART - 4);
4765 writew(head, &(cm_addr->cm_head));
4768 * Wait if necessary before updating the head
4769 * pointer to limit the number of outstanding
4770 * commands to the FEP. If the time spent waiting
4771 * is outlandish, declare the FEP dead.
4773 for (count = dgap_count ;;) {
4775 head = readw(&(cm_addr->cm_head));
4776 tail = readw(&(cm_addr->cm_tail));
4778 n = (head - tail) & (CMDMAX - CMDSTART - 4);
4780 if (n <= ncmds * sizeof(struct cm_t))
4784 ch->ch_bd->state = BOARD_FAILED;
4791 /*=======================================================================
4793 * dgap_cmdw_ext - Sends a extended word command to the FEP.
4795 * ch - Pointer to channel structure.
4796 * cmd - Command to be sent.
4797 * word - Integer containing word to be sent.
4798 * ncmds - Wait until ncmds or fewer cmds are left
4799 * in the cmd buffer before returning.
4801 *=======================================================================*/
4802 static void dgap_cmdw_ext(struct channel_t *ch, u16 cmd, u16 word, uint ncmds)
4804 char __iomem *vaddr;
4805 struct __iomem cm_t *cm_addr;
4811 if (!ch || ch->magic != DGAP_CHANNEL_MAGIC)
4815 * Check if board is still alive.
4817 if (ch->ch_bd->state == BOARD_FAILED)
4821 * Make sure the pointers are in range before
4822 * writing to the FEP memory.
4824 vaddr = ch->ch_bd->re_map_membase;
4828 cm_addr = (struct cm_t __iomem *) (vaddr + CMDBUF);
4829 head = readw(&(cm_addr->cm_head));
4832 * Forget it if pointers out of range.
4834 if (head >= (CMDMAX - CMDSTART) || (head & 03)) {
4835 ch->ch_bd->state = BOARD_FAILED;
4840 * Put the data in the circular command buffer.
4843 /* Write an FF to tell the FEP that we want an extended command */
4844 writeb((u8) 0xff, (vaddr + head + CMDSTART + 0));
4846 writeb((u8) ch->ch_portnum, (vaddr + head + CMDSTART + 1));
4847 writew((u16) cmd, (vaddr + head + CMDSTART + 2));
4850 * If the second part of the command won't fit,
4851 * put it at the beginning of the circular buffer.
4853 if (((head + 4) >= ((CMDMAX - CMDSTART)) || (head & 03)))
4854 writew((u16) word, (vaddr + CMDSTART));
4856 writew((u16) word, (vaddr + head + CMDSTART + 4));
4858 head = (head + 8) & (CMDMAX - CMDSTART - 4);
4860 writew(head, &(cm_addr->cm_head));
4863 * Wait if necessary before updating the head
4864 * pointer to limit the number of outstanding
4865 * commands to the FEP. If the time spent waiting
4866 * is outlandish, declare the FEP dead.
4868 for (count = dgap_count ;;) {
4870 head = readw(&(cm_addr->cm_head));
4871 tail = readw(&(cm_addr->cm_tail));
4873 n = (head - tail) & (CMDMAX - CMDSTART - 4);
4875 if (n <= ncmds * sizeof(struct cm_t))
4879 ch->ch_bd->state = BOARD_FAILED;
4886 /*=======================================================================
4888 * dgap_wmove - Write data to FEP buffer.
4890 * ch - Pointer to channel structure.
4891 * buf - Poiter to characters to be moved.
4892 * cnt - Number of characters to move.
4894 *=======================================================================*/
4895 static void dgap_wmove(struct channel_t *ch, char *buf, uint cnt)
4898 char __iomem *taddr;
4899 struct bs_t __iomem *bs;
4902 if (!ch || ch->magic != DGAP_CHANNEL_MAGIC)
4909 head = readw(&(bs->tx_head));
4912 * If pointers are out of range, just return.
4914 if ((cnt > ch->ch_tsize) ||
4915 (unsigned)(head - ch->ch_tstart) >= ch->ch_tsize)
4919 * If the write wraps over the top of the circular buffer,
4920 * move the portion up to the wrap point, and reset the
4921 * pointers to the bottom.
4923 n = ch->ch_tstart + ch->ch_tsize - head;
4927 taddr = ch->ch_taddr + head;
4928 memcpy_toio(taddr, buf, n);
4929 head = ch->ch_tstart;
4934 * Move rest of data.
4936 taddr = ch->ch_taddr + head;
4938 memcpy_toio(taddr, buf, n);
4941 writew(head, &(bs->tx_head));
4945 * Retrives the current custom baud rate from FEP memory,
4946 * and returns it back to the user.
4947 * Returns 0 on error.
4949 static uint dgap_get_custom_baud(struct channel_t *ch)
4955 if (!ch || ch->magic != DGAP_CHANNEL_MAGIC)
4958 if (!ch->ch_bd || ch->ch_bd->magic != DGAP_BOARD_MAGIC)
4961 if (!(ch->ch_bd->bd_flags & BD_FEP5PLUS))
4964 vaddr = ch->ch_bd->re_map_membase;
4970 * Go get from fep mem, what the fep
4971 * believes the custom baud rate is.
4973 offset = ((((*(unsigned short __iomem *)(vaddr + ECS_SEG)) << 4) +
4974 (ch->ch_portnum * 0x28) + LINE_SPEED));
4976 value = readw(vaddr + offset);
4981 * Calls the firmware to reset this channel.
4983 static void dgap_firmware_reset_port(struct channel_t *ch)
4985 dgap_cmdb(ch, CHRESET, 0, 0, 0);
4988 * Now that the channel is reset, we need to make sure
4989 * all the current settings get reapplied to the port
4992 * So we will set the driver's cache of firmware
4993 * settings all to 0, and then call param.
4995 ch->ch_fepiflag = 0;
4996 ch->ch_fepcflag = 0;
4997 ch->ch_fepoflag = 0;
4998 ch->ch_fepstartc = 0;
4999 ch->ch_fepstopc = 0;
5000 ch->ch_fepastartc = 0;
5001 ch->ch_fepastopc = 0;
5006 /*=======================================================================
5008 * dgap_param - Set Digi parameters.
5010 * struct tty_struct * - TTY for port.
5012 *=======================================================================*/
5013 static int dgap_param(struct tty_struct *tty)
5015 struct ktermios *ts;
5017 struct channel_t *ch;
5018 struct bs_t __iomem *bs;
5026 if (!tty || tty->magic != TTY_MAGIC)
5029 un = (struct un_t *) tty->driver_data;
5030 if (!un || un->magic != DGAP_UNIT_MAGIC)
5034 if (!ch || ch->magic != DGAP_CHANNEL_MAGIC)
5038 if (!bd || bd->magic != DGAP_BOARD_MAGIC)
5048 * If baud rate is zero, flush queues, and set mval to drop DTR.
5050 if ((ch->ch_c_cflag & (CBAUD)) == 0) {
5053 head = readw(&(ch->ch_bs->rx_head));
5054 writew(head, &(ch->ch_bs->rx_tail));
5057 head = readw(&(ch->ch_bs->tx_head));
5058 writew(head, &(ch->ch_bs->tx_tail));
5060 ch->ch_flags |= (CH_BAUD0);
5062 /* Drop RTS and DTR */
5063 ch->ch_mval &= ~(D_RTS(ch)|D_DTR(ch));
5064 mval = D_DTR(ch) | D_RTS(ch);
5065 ch->ch_baud_info = 0;
5067 } else if (ch->ch_custom_speed && (bd->bd_flags & BD_FEP5PLUS)) {
5069 * Tell the fep to do the command
5072 dgap_cmdw_ext(ch, 0xff01, ch->ch_custom_speed, 0);
5075 * Now go get from fep mem, what the fep
5076 * believes the custom baud rate is.
5078 ch->ch_custom_speed = dgap_get_custom_baud(ch);
5079 ch->ch_baud_info = ch->ch_custom_speed;
5081 /* Handle transition from B0 */
5082 if (ch->ch_flags & CH_BAUD0) {
5083 ch->ch_flags &= ~(CH_BAUD0);
5084 ch->ch_mval |= (D_RTS(ch)|D_DTR(ch));
5086 mval = D_DTR(ch) | D_RTS(ch);
5090 * Set baud rate, character size, and parity.
5098 ulong bauds[4][16] = {
5102 600, 1200, 1800, 2400,
5103 4800, 9600, 19200, 38400 },
5104 { /* slowbaud & CBAUDEX */
5105 0, 57600, 115200, 230400,
5106 460800, 150, 200, 921600,
5107 600, 1200, 1800, 2400,
5108 4800, 9600, 19200, 38400 },
5110 0, 57600, 76800, 115200,
5111 14400, 57600, 230400, 76800,
5112 115200, 230400, 28800, 460800,
5113 921600, 9600, 19200, 38400 },
5114 { /* fastbaud & CBAUDEX */
5115 0, 57600, 115200, 230400,
5116 460800, 150, 200, 921600,
5117 600, 1200, 1800, 2400,
5118 4800, 9600, 19200, 38400 }
5122 * Only use the TXPrint baud rate if the
5123 * terminal unit is NOT open
5125 if (!(ch->ch_tun.un_flags & UN_ISOPEN) &&
5126 (un->un_type == DGAP_PRINT))
5127 baud = C_BAUD(ch->ch_pun.un_tty) & 0xff;
5129 baud = C_BAUD(ch->ch_tun.un_tty) & 0xff;
5131 if (ch->ch_c_cflag & CBAUDEX)
5134 if (ch->ch_digi.digi_flags & DIGI_FAST)
5139 if ((iindex >= 0) && (iindex < 4) &&
5140 (jindex >= 0) && (jindex < 16))
5141 baud = bauds[iindex][jindex];
5148 ch->ch_baud_info = baud;
5151 * CBAUD has bit position 0x1000 set these days to
5152 * indicate Linux baud rate remap.
5153 * We use a different bit assignment for high speed.
5154 * Clear this bit out while grabbing the parts of
5157 cflag = ch->ch_c_cflag & ((CBAUD ^ CBAUDEX) | PARODD | PARENB |
5161 * HUPCL bit is used by FEP to indicate fast baud
5162 * table is to be used.
5164 if ((ch->ch_digi.digi_flags & DIGI_FAST) ||
5165 (ch->ch_c_cflag & CBAUDEX))
5168 if ((ch->ch_c_cflag & CBAUDEX) &&
5169 !(ch->ch_digi.digi_flags & DIGI_FAST)) {
5171 * The below code is trying to guarantee that only
5172 * baud rates 115200, 230400, 460800, 921600 are
5173 * remapped. We use exclusive or because the various
5174 * baud rates share common bit positions and therefore
5175 * can't be tested for easily.
5177 tcflag_t tcflag = (ch->ch_c_cflag & CBAUD) | CBAUDEX;
5181 * Map high speed requests to index
5182 * into FEP's baud table
5212 cflag = (cflag & ~(CBAUD | CBAUDEX)) | baudpart;
5217 if (cflag != ch->ch_fepcflag) {
5218 ch->ch_fepcflag = (u16) (cflag & 0xffff);
5221 * Okay to have channel and board
5222 * locks held calling this
5224 dgap_cmdw(ch, SCFLAG, (u16) cflag, 0);
5227 /* Handle transition from B0 */
5228 if (ch->ch_flags & CH_BAUD0) {
5229 ch->ch_flags &= ~(CH_BAUD0);
5230 ch->ch_mval |= (D_RTS(ch)|D_DTR(ch));
5232 mval = D_DTR(ch) | D_RTS(ch);
5238 iflag = ch->ch_c_iflag & (IGNBRK | BRKINT | IGNPAR | PARMRK |
5239 INPCK | ISTRIP | IXON | IXANY | IXOFF);
5241 if ((ch->ch_startc == _POSIX_VDISABLE) ||
5242 (ch->ch_stopc == _POSIX_VDISABLE)) {
5243 iflag &= ~(IXON | IXOFF);
5244 ch->ch_c_iflag &= ~(IXON | IXOFF);
5248 * Only the IBM Xr card can switch between
5249 * 232 and 422 modes on the fly
5251 if (bd->device == PCI_DEV_XR_IBM_DID) {
5252 if (ch->ch_digi.digi_flags & DIGI_422)
5253 dgap_cmdb(ch, SCOMMODE, MODE_422, 0, 0);
5255 dgap_cmdb(ch, SCOMMODE, MODE_232, 0, 0);
5258 if (ch->ch_digi.digi_flags & DIGI_ALTPIN)
5261 if (iflag != ch->ch_fepiflag) {
5262 ch->ch_fepiflag = iflag;
5264 /* Okay to have channel and board locks held calling this */
5265 dgap_cmdw(ch, SIFLAG, (u16) ch->ch_fepiflag, 0);
5269 * Select hardware handshaking.
5273 if (ch->ch_c_cflag & CRTSCTS)
5274 hflow |= (D_RTS(ch) | D_CTS(ch));
5275 if (ch->ch_digi.digi_flags & RTSPACE)
5277 if (ch->ch_digi.digi_flags & DTRPACE)
5279 if (ch->ch_digi.digi_flags & CTSPACE)
5281 if (ch->ch_digi.digi_flags & DSRPACE)
5283 if (ch->ch_digi.digi_flags & DCDPACE)
5286 if (hflow != ch->ch_hflow) {
5287 ch->ch_hflow = hflow;
5289 /* Okay to have channel and board locks held calling this */
5290 dgap_cmdb(ch, SHFLOW, (u8) hflow, 0xff, 0);
5295 * Set RTS and/or DTR Toggle if needed,
5296 * but only if product is FEP5+ based.
5298 if (bd->bd_flags & BD_FEP5PLUS) {
5300 if (ch->ch_digi.digi_flags & DIGI_RTS_TOGGLE)
5301 hflow2 |= (D_RTS(ch));
5302 if (ch->ch_digi.digi_flags & DIGI_DTR_TOGGLE)
5303 hflow2 |= (D_DTR(ch));
5305 dgap_cmdw_ext(ch, 0xff03, hflow2, 0);
5309 * Set modem control lines.
5312 mval ^= ch->ch_mforce & (mval ^ ch->ch_mval);
5314 if (ch->ch_mostat ^ mval) {
5315 ch->ch_mostat = mval;
5317 /* Okay to have channel and board locks held calling this */
5318 dgap_cmdb(ch, SMODEM, (u8) mval, D_RTS(ch)|D_DTR(ch), 0);
5322 * Read modem signals, and then call carrier function.
5324 ch->ch_mistat = readb(&(bs->m_stat));
5328 * Set the start and stop characters.
5330 if (ch->ch_startc != ch->ch_fepstartc ||
5331 ch->ch_stopc != ch->ch_fepstopc) {
5332 ch->ch_fepstartc = ch->ch_startc;
5333 ch->ch_fepstopc = ch->ch_stopc;
5335 /* Okay to have channel and board locks held calling this */
5336 dgap_cmdb(ch, SFLOWC, ch->ch_fepstartc, ch->ch_fepstopc, 0);
5340 * Set the Auxiliary start and stop characters.
5342 if (ch->ch_astartc != ch->ch_fepastartc ||
5343 ch->ch_astopc != ch->ch_fepastopc) {
5344 ch->ch_fepastartc = ch->ch_astartc;
5345 ch->ch_fepastopc = ch->ch_astopc;
5347 /* Okay to have channel and board locks held calling this */
5348 dgap_cmdb(ch, SAFLOWC, ch->ch_fepastartc, ch->ch_fepastopc, 0);
5355 * dgap_parity_scan()
5357 * Convert the FEP5 way of reporting parity errors and breaks into
5358 * the Linux line discipline way.
5360 static void dgap_parity_scan(struct channel_t *ch, unsigned char *cbuf,
5361 unsigned char *fbuf, int *len)
5365 unsigned char *in, *cout, *fout;
5372 if (!ch || ch->magic != DGAP_CHANNEL_MAGIC)
5377 switch (ch->pscan_state) {
5379 /* reset to sanity and fall through */
5380 ch->pscan_state = 0;
5383 /* No FF seen yet */
5384 if (c == (unsigned char) '\377')
5385 /* delete this character from stream */
5386 ch->pscan_state = 1;
5389 *fout++ = TTY_NORMAL;
5396 if (c == (unsigned char) '\377') {
5397 /* doubled ff, transform to single ff */
5399 *fout++ = TTY_NORMAL;
5401 ch->pscan_state = 0;
5403 /* save value examination in next state */
5404 ch->pscan_savechar = c;
5405 ch->pscan_state = 2;
5410 /* third character of ff sequence */
5414 if (ch->pscan_savechar == 0x0) {
5418 *fout++ = TTY_BREAK;
5420 ch->ch_err_parity++;
5421 *fout++ = TTY_PARITY;
5426 ch->pscan_state = 0;
5432 static void dgap_write_wakeup(struct board_t *bd, struct channel_t *ch,
5433 struct un_t *un, u32 mask,
5434 unsigned long *irq_flags1,
5435 unsigned long *irq_flags2)
5437 if (!(un->un_flags & mask))
5440 un->un_flags &= ~mask;
5442 if (!(un->un_flags & UN_ISOPEN))
5445 if ((un->un_tty->flags & (1 << TTY_DO_WRITE_WAKEUP)) &&
5446 un->un_tty->ldisc->ops->write_wakeup) {
5447 spin_unlock_irqrestore(&ch->ch_lock, *irq_flags2);
5448 spin_unlock_irqrestore(&bd->bd_lock, *irq_flags1);
5450 (un->un_tty->ldisc->ops->write_wakeup)(un->un_tty);
5452 spin_lock_irqsave(&bd->bd_lock, *irq_flags1);
5453 spin_lock_irqsave(&ch->ch_lock, *irq_flags2);
5455 wake_up_interruptible(&un->un_tty->write_wait);
5456 wake_up_interruptible(&un->un_flags_wait);
5459 /*=======================================================================
5461 * dgap_event - FEP to host event processing routine.
5463 * bd - Board of current event.
5465 *=======================================================================*/
5466 static int dgap_event(struct board_t *bd)
5468 struct channel_t *ch;
5471 struct bs_t __iomem *bs;
5474 struct ev_t __iomem *eaddr;
5482 if (!bd || bd->magic != DGAP_BOARD_MAGIC)
5485 spin_lock_irqsave(&bd->bd_lock, lock_flags);
5487 vaddr = bd->re_map_membase;
5490 spin_unlock_irqrestore(&bd->bd_lock, lock_flags);
5494 eaddr = (struct ev_t __iomem *) (vaddr + EVBUF);
5496 /* Get our head and tail */
5497 head = readw(&(eaddr->ev_head));
5498 tail = readw(&(eaddr->ev_tail));
5501 * Forget it if pointers out of range.
5504 if (head >= EVMAX - EVSTART || tail >= EVMAX - EVSTART ||
5505 (head | tail) & 03) {
5506 /* Let go of board lock */
5507 spin_unlock_irqrestore(&bd->bd_lock, lock_flags);
5512 * Loop to process all the events in the buffer.
5514 while (tail != head) {
5517 * Get interrupt information.
5520 event = bd->re_map_membase + tail + EVSTART;
5528 * Make sure the interrupt is valid.
5530 if (port >= bd->nasync)
5533 if (!(reason & (IFMODEM | IFBREAK | IFTLW | IFTEM | IFDATA)))
5536 ch = bd->channels[port];
5538 if (!ch || ch->magic != DGAP_CHANNEL_MAGIC)
5542 * If we have made it here, the event was valid.
5543 * Lock down the channel.
5545 spin_lock_irqsave(&ch->ch_lock, lock_flags2);
5550 spin_unlock_irqrestore(&ch->ch_lock, lock_flags2);
5555 * Process received data.
5557 if (reason & IFDATA) {
5560 * ALL LOCKS *MUST* BE DROPPED BEFORE CALLING INPUT!
5561 * input could send some data to ld, which in turn
5562 * could do a callback to one of our other functions.
5564 spin_unlock_irqrestore(&ch->ch_lock, lock_flags2);
5565 spin_unlock_irqrestore(&bd->bd_lock, lock_flags);
5569 spin_lock_irqsave(&bd->bd_lock, lock_flags);
5570 spin_lock_irqsave(&ch->ch_lock, lock_flags2);
5572 if (ch->ch_flags & CH_RACTIVE)
5573 ch->ch_flags |= CH_RENABLE;
5575 writeb(1, &(bs->idata));
5577 if (ch->ch_flags & CH_RWAIT) {
5578 ch->ch_flags &= ~CH_RWAIT;
5580 wake_up_interruptible
5581 (&ch->ch_tun.un_flags_wait);
5586 * Process Modem change signals.
5588 if (reason & IFMODEM) {
5589 ch->ch_mistat = modem;
5596 if (reason & IFBREAK) {
5598 if (ch->ch_tun.un_tty) {
5599 /* A break has been indicated */
5601 tty_buffer_request_room
5602 (ch->ch_tun.un_tty->port, 1);
5603 tty_insert_flip_char(ch->ch_tun.un_tty->port,
5605 tty_flip_buffer_push(ch->ch_tun.un_tty->port);
5610 * Process Transmit low.
5612 if (reason & IFTLW) {
5613 dgap_write_wakeup(bd, ch, &ch->ch_tun, UN_LOW,
5614 &lock_flags, &lock_flags2);
5615 dgap_write_wakeup(bd, ch, &ch->ch_pun, UN_LOW,
5616 &lock_flags, &lock_flags2);
5617 if (ch->ch_flags & CH_WLOW) {
5618 ch->ch_flags &= ~CH_WLOW;
5619 wake_up_interruptible(&ch->ch_flags_wait);
5624 * Process Transmit empty.
5626 if (reason & IFTEM) {
5627 dgap_write_wakeup(bd, ch, &ch->ch_tun, UN_EMPTY,
5628 &lock_flags, &lock_flags2);
5629 dgap_write_wakeup(bd, ch, &ch->ch_pun, UN_EMPTY,
5630 &lock_flags, &lock_flags2);
5631 if (ch->ch_flags & CH_WEMPTY) {
5632 ch->ch_flags &= ~CH_WEMPTY;
5633 wake_up_interruptible(&ch->ch_flags_wait);
5637 spin_unlock_irqrestore(&ch->ch_lock, lock_flags2);
5640 tail = (tail + 4) & (EVMAX - EVSTART - 4);
5643 writew(tail, &(eaddr->ev_tail));
5644 spin_unlock_irqrestore(&bd->bd_lock, lock_flags);
5649 static ssize_t dgap_driver_version_show(struct device_driver *ddp, char *buf)
5651 return snprintf(buf, PAGE_SIZE, "%s\n", DG_PART);
5653 static DRIVER_ATTR(version, S_IRUSR, dgap_driver_version_show, NULL);
5656 static ssize_t dgap_driver_boards_show(struct device_driver *ddp, char *buf)
5658 return snprintf(buf, PAGE_SIZE, "%d\n", dgap_numboards);
5660 static DRIVER_ATTR(boards, S_IRUSR, dgap_driver_boards_show, NULL);
5663 static ssize_t dgap_driver_maxboards_show(struct device_driver *ddp, char *buf)
5665 return snprintf(buf, PAGE_SIZE, "%d\n", MAXBOARDS);
5667 static DRIVER_ATTR(maxboards, S_IRUSR, dgap_driver_maxboards_show, NULL);
5670 static ssize_t dgap_driver_pollcounter_show(struct device_driver *ddp,
5673 return snprintf(buf, PAGE_SIZE, "%ld\n", dgap_poll_counter);
5675 static DRIVER_ATTR(pollcounter, S_IRUSR, dgap_driver_pollcounter_show, NULL);
5677 static ssize_t dgap_driver_pollrate_show(struct device_driver *ddp, char *buf)
5679 return snprintf(buf, PAGE_SIZE, "%dms\n", dgap_poll_tick);
5682 static ssize_t dgap_driver_pollrate_store(struct device_driver *ddp,
5683 const char *buf, size_t count)
5685 if (sscanf(buf, "%d\n", &dgap_poll_tick) != 1)
5689 static DRIVER_ATTR(pollrate, (S_IRUSR | S_IWUSR), dgap_driver_pollrate_show,
5690 dgap_driver_pollrate_store);
5692 static int dgap_create_driver_sysfiles(struct pci_driver *dgap_driver)
5695 struct device_driver *driverfs = &dgap_driver->driver;
5697 rc |= driver_create_file(driverfs, &driver_attr_version);
5698 rc |= driver_create_file(driverfs, &driver_attr_boards);
5699 rc |= driver_create_file(driverfs, &driver_attr_maxboards);
5700 rc |= driver_create_file(driverfs, &driver_attr_pollrate);
5701 rc |= driver_create_file(driverfs, &driver_attr_pollcounter);
5706 static void dgap_remove_driver_sysfiles(struct pci_driver *dgap_driver)
5708 struct device_driver *driverfs = &dgap_driver->driver;
5709 driver_remove_file(driverfs, &driver_attr_version);
5710 driver_remove_file(driverfs, &driver_attr_boards);
5711 driver_remove_file(driverfs, &driver_attr_maxboards);
5712 driver_remove_file(driverfs, &driver_attr_pollrate);
5713 driver_remove_file(driverfs, &driver_attr_pollcounter);
5716 static struct board_t *dgap_verify_board(struct device *p)
5723 bd = dev_get_drvdata(p);
5724 if (!bd || bd->magic != DGAP_BOARD_MAGIC || bd->state != BOARD_READY)
5730 static ssize_t dgap_ports_state_show(struct device *p,
5731 struct device_attribute *attr,
5738 bd = dgap_verify_board(p);
5742 for (i = 0; i < bd->nasync; i++) {
5743 count += snprintf(buf + count, PAGE_SIZE - count,
5744 "%d %s\n", bd->channels[i]->ch_portnum,
5745 bd->channels[i]->ch_open_count ? "Open" : "Closed");
5749 static DEVICE_ATTR(ports_state, S_IRUSR, dgap_ports_state_show, NULL);
5751 static ssize_t dgap_ports_baud_show(struct device *p,
5752 struct device_attribute *attr,
5759 bd = dgap_verify_board(p);
5763 for (i = 0; i < bd->nasync; i++) {
5764 count += snprintf(buf + count, PAGE_SIZE - count, "%d %d\n",
5765 bd->channels[i]->ch_portnum,
5766 bd->channels[i]->ch_baud_info);
5770 static DEVICE_ATTR(ports_baud, S_IRUSR, dgap_ports_baud_show, NULL);
5772 static ssize_t dgap_ports_msignals_show(struct device *p,
5773 struct device_attribute *attr,
5780 bd = dgap_verify_board(p);
5784 for (i = 0; i < bd->nasync; i++) {
5785 if (bd->channels[i]->ch_open_count)
5786 count += snprintf(buf + count, PAGE_SIZE - count,
5787 "%d %s %s %s %s %s %s\n",
5788 bd->channels[i]->ch_portnum,
5789 (bd->channels[i]->ch_mostat &
5790 UART_MCR_RTS) ? "RTS" : "",
5791 (bd->channels[i]->ch_mistat &
5792 UART_MSR_CTS) ? "CTS" : "",
5793 (bd->channels[i]->ch_mostat &
5794 UART_MCR_DTR) ? "DTR" : "",
5795 (bd->channels[i]->ch_mistat &
5796 UART_MSR_DSR) ? "DSR" : "",
5797 (bd->channels[i]->ch_mistat &
5798 UART_MSR_DCD) ? "DCD" : "",
5799 (bd->channels[i]->ch_mistat &
5800 UART_MSR_RI) ? "RI" : "");
5802 count += snprintf(buf + count, PAGE_SIZE - count,
5803 "%d\n", bd->channels[i]->ch_portnum);
5807 static DEVICE_ATTR(ports_msignals, S_IRUSR, dgap_ports_msignals_show, NULL);
5809 static ssize_t dgap_ports_iflag_show(struct device *p,
5810 struct device_attribute *attr,
5817 bd = dgap_verify_board(p);
5821 for (i = 0; i < bd->nasync; i++)
5822 count += snprintf(buf + count, PAGE_SIZE - count, "%d %x\n",
5823 bd->channels[i]->ch_portnum,
5824 bd->channels[i]->ch_c_iflag);
5827 static DEVICE_ATTR(ports_iflag, S_IRUSR, dgap_ports_iflag_show, NULL);
5829 static ssize_t dgap_ports_cflag_show(struct device *p,
5830 struct device_attribute *attr,
5837 bd = dgap_verify_board(p);
5841 for (i = 0; i < bd->nasync; i++)
5842 count += snprintf(buf + count, PAGE_SIZE - count, "%d %x\n",
5843 bd->channels[i]->ch_portnum,
5844 bd->channels[i]->ch_c_cflag);
5847 static DEVICE_ATTR(ports_cflag, S_IRUSR, dgap_ports_cflag_show, NULL);
5849 static ssize_t dgap_ports_oflag_show(struct device *p,
5850 struct device_attribute *attr,
5857 bd = dgap_verify_board(p);
5861 for (i = 0; i < bd->nasync; i++)
5862 count += snprintf(buf + count, PAGE_SIZE - count, "%d %x\n",
5863 bd->channels[i]->ch_portnum,
5864 bd->channels[i]->ch_c_oflag);
5867 static DEVICE_ATTR(ports_oflag, S_IRUSR, dgap_ports_oflag_show, NULL);
5869 static ssize_t dgap_ports_lflag_show(struct device *p,
5870 struct device_attribute *attr,
5877 bd = dgap_verify_board(p);
5881 for (i = 0; i < bd->nasync; i++)
5882 count += snprintf(buf + count, PAGE_SIZE - count, "%d %x\n",
5883 bd->channels[i]->ch_portnum,
5884 bd->channels[i]->ch_c_lflag);
5887 static DEVICE_ATTR(ports_lflag, S_IRUSR, dgap_ports_lflag_show, NULL);
5889 static ssize_t dgap_ports_digi_flag_show(struct device *p,
5890 struct device_attribute *attr,
5897 bd = dgap_verify_board(p);
5901 for (i = 0; i < bd->nasync; i++)
5902 count += snprintf(buf + count, PAGE_SIZE - count, "%d %x\n",
5903 bd->channels[i]->ch_portnum,
5904 bd->channels[i]->ch_digi.digi_flags);
5907 static DEVICE_ATTR(ports_digi_flag, S_IRUSR, dgap_ports_digi_flag_show, NULL);
5909 static ssize_t dgap_ports_rxcount_show(struct device *p,
5910 struct device_attribute *attr,
5917 bd = dgap_verify_board(p);
5921 for (i = 0; i < bd->nasync; i++)
5922 count += snprintf(buf + count, PAGE_SIZE - count, "%d %ld\n",
5923 bd->channels[i]->ch_portnum,
5924 bd->channels[i]->ch_rxcount);
5927 static DEVICE_ATTR(ports_rxcount, S_IRUSR, dgap_ports_rxcount_show, NULL);
5929 static ssize_t dgap_ports_txcount_show(struct device *p,
5930 struct device_attribute *attr,
5937 bd = dgap_verify_board(p);
5941 for (i = 0; i < bd->nasync; i++)
5942 count += snprintf(buf + count, PAGE_SIZE - count, "%d %ld\n",
5943 bd->channels[i]->ch_portnum,
5944 bd->channels[i]->ch_txcount);
5947 static DEVICE_ATTR(ports_txcount, S_IRUSR, dgap_ports_txcount_show, NULL);
5949 /* this function creates the sys files that will export each signal status
5950 * to sysfs each value will be put in a separate filename
5952 static void dgap_create_ports_sysfiles(struct board_t *bd)
5954 dev_set_drvdata(&bd->pdev->dev, bd);
5955 device_create_file(&(bd->pdev->dev), &dev_attr_ports_state);
5956 device_create_file(&(bd->pdev->dev), &dev_attr_ports_baud);
5957 device_create_file(&(bd->pdev->dev), &dev_attr_ports_msignals);
5958 device_create_file(&(bd->pdev->dev), &dev_attr_ports_iflag);
5959 device_create_file(&(bd->pdev->dev), &dev_attr_ports_cflag);
5960 device_create_file(&(bd->pdev->dev), &dev_attr_ports_oflag);
5961 device_create_file(&(bd->pdev->dev), &dev_attr_ports_lflag);
5962 device_create_file(&(bd->pdev->dev), &dev_attr_ports_digi_flag);
5963 device_create_file(&(bd->pdev->dev), &dev_attr_ports_rxcount);
5964 device_create_file(&(bd->pdev->dev), &dev_attr_ports_txcount);
5967 /* removes all the sys files created for that port */
5968 static void dgap_remove_ports_sysfiles(struct board_t *bd)
5970 device_remove_file(&(bd->pdev->dev), &dev_attr_ports_state);
5971 device_remove_file(&(bd->pdev->dev), &dev_attr_ports_baud);
5972 device_remove_file(&(bd->pdev->dev), &dev_attr_ports_msignals);
5973 device_remove_file(&(bd->pdev->dev), &dev_attr_ports_iflag);
5974 device_remove_file(&(bd->pdev->dev), &dev_attr_ports_cflag);
5975 device_remove_file(&(bd->pdev->dev), &dev_attr_ports_oflag);
5976 device_remove_file(&(bd->pdev->dev), &dev_attr_ports_lflag);
5977 device_remove_file(&(bd->pdev->dev), &dev_attr_ports_digi_flag);
5978 device_remove_file(&(bd->pdev->dev), &dev_attr_ports_rxcount);
5979 device_remove_file(&(bd->pdev->dev), &dev_attr_ports_txcount);
5982 static ssize_t dgap_tty_state_show(struct device *d,
5983 struct device_attribute *attr,
5987 struct channel_t *ch;
5992 un = dev_get_drvdata(d);
5993 if (!un || un->magic != DGAP_UNIT_MAGIC)
5996 if (!ch || ch->magic != DGAP_CHANNEL_MAGIC)
5999 if (!bd || bd->magic != DGAP_BOARD_MAGIC)
6001 if (bd->state != BOARD_READY)
6004 return snprintf(buf, PAGE_SIZE, "%s", un->un_open_count ?
6007 static DEVICE_ATTR(state, S_IRUSR, dgap_tty_state_show, NULL);
6009 static ssize_t dgap_tty_baud_show(struct device *d,
6010 struct device_attribute *attr,
6014 struct channel_t *ch;
6019 un = dev_get_drvdata(d);
6020 if (!un || un->magic != DGAP_UNIT_MAGIC)
6023 if (!ch || ch->magic != DGAP_CHANNEL_MAGIC)
6026 if (!bd || bd->magic != DGAP_BOARD_MAGIC)
6028 if (bd->state != BOARD_READY)
6031 return snprintf(buf, PAGE_SIZE, "%d\n", ch->ch_baud_info);
6033 static DEVICE_ATTR(baud, S_IRUSR, dgap_tty_baud_show, NULL);
6035 static ssize_t dgap_tty_msignals_show(struct device *d,
6036 struct device_attribute *attr,
6040 struct channel_t *ch;
6045 un = dev_get_drvdata(d);
6046 if (!un || un->magic != DGAP_UNIT_MAGIC)
6049 if (!ch || ch->magic != DGAP_CHANNEL_MAGIC)
6052 if (!bd || bd->magic != DGAP_BOARD_MAGIC)
6054 if (bd->state != BOARD_READY)
6057 if (ch->ch_open_count) {
6058 return snprintf(buf, PAGE_SIZE, "%s %s %s %s %s %s\n",
6059 (ch->ch_mostat & UART_MCR_RTS) ? "RTS" : "",
6060 (ch->ch_mistat & UART_MSR_CTS) ? "CTS" : "",
6061 (ch->ch_mostat & UART_MCR_DTR) ? "DTR" : "",
6062 (ch->ch_mistat & UART_MSR_DSR) ? "DSR" : "",
6063 (ch->ch_mistat & UART_MSR_DCD) ? "DCD" : "",
6064 (ch->ch_mistat & UART_MSR_RI) ? "RI" : "");
6068 static DEVICE_ATTR(msignals, S_IRUSR, dgap_tty_msignals_show, NULL);
6070 static ssize_t dgap_tty_iflag_show(struct device *d,
6071 struct device_attribute *attr,
6075 struct channel_t *ch;
6080 un = dev_get_drvdata(d);
6081 if (!un || un->magic != DGAP_UNIT_MAGIC)
6084 if (!ch || ch->magic != DGAP_CHANNEL_MAGIC)
6087 if (!bd || bd->magic != DGAP_BOARD_MAGIC)
6089 if (bd->state != BOARD_READY)
6092 return snprintf(buf, PAGE_SIZE, "%x\n", ch->ch_c_iflag);
6094 static DEVICE_ATTR(iflag, S_IRUSR, dgap_tty_iflag_show, NULL);
6096 static ssize_t dgap_tty_cflag_show(struct device *d,
6097 struct device_attribute *attr,
6101 struct channel_t *ch;
6106 un = dev_get_drvdata(d);
6107 if (!un || un->magic != DGAP_UNIT_MAGIC)
6110 if (!ch || ch->magic != DGAP_CHANNEL_MAGIC)
6113 if (!bd || bd->magic != DGAP_BOARD_MAGIC)
6115 if (bd->state != BOARD_READY)
6118 return snprintf(buf, PAGE_SIZE, "%x\n", ch->ch_c_cflag);
6120 static DEVICE_ATTR(cflag, S_IRUSR, dgap_tty_cflag_show, NULL);
6122 static ssize_t dgap_tty_oflag_show(struct device *d,
6123 struct device_attribute *attr,
6127 struct channel_t *ch;
6132 un = dev_get_drvdata(d);
6133 if (!un || un->magic != DGAP_UNIT_MAGIC)
6136 if (!ch || ch->magic != DGAP_CHANNEL_MAGIC)
6139 if (!bd || bd->magic != DGAP_BOARD_MAGIC)
6141 if (bd->state != BOARD_READY)
6144 return snprintf(buf, PAGE_SIZE, "%x\n", ch->ch_c_oflag);
6146 static DEVICE_ATTR(oflag, S_IRUSR, dgap_tty_oflag_show, NULL);
6148 static ssize_t dgap_tty_lflag_show(struct device *d,
6149 struct device_attribute *attr,
6153 struct channel_t *ch;
6158 un = dev_get_drvdata(d);
6159 if (!un || un->magic != DGAP_UNIT_MAGIC)
6162 if (!ch || ch->magic != DGAP_CHANNEL_MAGIC)
6165 if (!bd || bd->magic != DGAP_BOARD_MAGIC)
6167 if (bd->state != BOARD_READY)
6170 return snprintf(buf, PAGE_SIZE, "%x\n", ch->ch_c_lflag);
6172 static DEVICE_ATTR(lflag, S_IRUSR, dgap_tty_lflag_show, NULL);
6174 static ssize_t dgap_tty_digi_flag_show(struct device *d,
6175 struct device_attribute *attr,
6179 struct channel_t *ch;
6184 un = dev_get_drvdata(d);
6185 if (!un || un->magic != DGAP_UNIT_MAGIC)
6188 if (!ch || ch->magic != DGAP_CHANNEL_MAGIC)
6191 if (!bd || bd->magic != DGAP_BOARD_MAGIC)
6193 if (bd->state != BOARD_READY)
6196 return snprintf(buf, PAGE_SIZE, "%x\n", ch->ch_digi.digi_flags);
6198 static DEVICE_ATTR(digi_flag, S_IRUSR, dgap_tty_digi_flag_show, NULL);
6200 static ssize_t dgap_tty_rxcount_show(struct device *d,
6201 struct device_attribute *attr,
6205 struct channel_t *ch;
6210 un = dev_get_drvdata(d);
6211 if (!un || un->magic != DGAP_UNIT_MAGIC)
6214 if (!ch || ch->magic != DGAP_CHANNEL_MAGIC)
6217 if (!bd || bd->magic != DGAP_BOARD_MAGIC)
6219 if (bd->state != BOARD_READY)
6222 return snprintf(buf, PAGE_SIZE, "%ld\n", ch->ch_rxcount);
6224 static DEVICE_ATTR(rxcount, S_IRUSR, dgap_tty_rxcount_show, NULL);
6226 static ssize_t dgap_tty_txcount_show(struct device *d,
6227 struct device_attribute *attr,
6231 struct channel_t *ch;
6236 un = dev_get_drvdata(d);
6237 if (!un || un->magic != DGAP_UNIT_MAGIC)
6240 if (!ch || ch->magic != DGAP_CHANNEL_MAGIC)
6243 if (!bd || bd->magic != DGAP_BOARD_MAGIC)
6245 if (bd->state != BOARD_READY)
6248 return snprintf(buf, PAGE_SIZE, "%ld\n", ch->ch_txcount);
6250 static DEVICE_ATTR(txcount, S_IRUSR, dgap_tty_txcount_show, NULL);
6252 static ssize_t dgap_tty_name_show(struct device *d,
6253 struct device_attribute *attr,
6257 struct channel_t *ch;
6261 struct cnode *cptr = NULL;
6269 un = dev_get_drvdata(d);
6270 if (!un || un->magic != DGAP_UNIT_MAGIC)
6273 if (!ch || ch->magic != DGAP_CHANNEL_MAGIC)
6276 if (!bd || bd->magic != DGAP_BOARD_MAGIC)
6278 if (bd->state != BOARD_READY)
6282 cn = ch->ch_portnum;
6284 for (cptr = bd->bd_config; cptr; cptr = cptr->next) {
6286 if ((cptr->type == BNODE) &&
6287 ((cptr->u.board.type == APORT2_920P) ||
6288 (cptr->u.board.type == APORT4_920P) ||
6289 (cptr->u.board.type == APORT8_920P) ||
6290 (cptr->u.board.type == PAPORT4) ||
6291 (cptr->u.board.type == PAPORT8))) {
6294 if (cptr->u.board.v_start)
6295 starto = cptr->u.board.start;
6300 if (cptr->type == TNODE && found == TRUE) {
6302 if (strstr(cptr->u.ttyname, "tty")) {
6303 ptr1 = cptr->u.ttyname;
6306 ptr1 = cptr->u.ttyname;
6308 for (i = 0; i < dgap_config_get_num_prts(bd); i++) {
6312 return snprintf(buf, PAGE_SIZE, "%s%s%02d\n",
6313 (un->un_type == DGAP_PRINT) ?
6319 if (cptr->type == CNODE) {
6321 for (i = 0; i < cptr->u.conc.nport; i++) {
6322 if (cn != (i + ncount))
6325 return snprintf(buf, PAGE_SIZE, "%s%s%02ld\n",
6326 (un->un_type == DGAP_PRINT) ?
6329 i + (cptr->u.conc.v_start ?
6330 cptr->u.conc.start : 1));
6333 ncount += cptr->u.conc.nport;
6336 if (cptr->type == MNODE) {
6338 for (i = 0; i < cptr->u.module.nport; i++) {
6339 if (cn != (i + ncount))
6342 return snprintf(buf, PAGE_SIZE, "%s%s%02ld\n",
6343 (un->un_type == DGAP_PRINT) ?
6346 i + (cptr->u.module.v_start ?
6347 cptr->u.module.start : 1));
6350 ncount += cptr->u.module.nport;
6355 return snprintf(buf, PAGE_SIZE, "%s_dgap_%d_%d\n",
6356 (un->un_type == DGAP_PRINT) ? "pr" : "tty", bn, cn);
6359 static DEVICE_ATTR(custom_name, S_IRUSR, dgap_tty_name_show, NULL);
6361 static struct attribute *dgap_sysfs_tty_entries[] = {
6362 &dev_attr_state.attr,
6363 &dev_attr_baud.attr,
6364 &dev_attr_msignals.attr,
6365 &dev_attr_iflag.attr,
6366 &dev_attr_cflag.attr,
6367 &dev_attr_oflag.attr,
6368 &dev_attr_lflag.attr,
6369 &dev_attr_digi_flag.attr,
6370 &dev_attr_rxcount.attr,
6371 &dev_attr_txcount.attr,
6372 &dev_attr_custom_name.attr,
6376 static struct attribute_group dgap_tty_attribute_group = {
6378 .attrs = dgap_sysfs_tty_entries,
6381 static void dgap_create_tty_sysfs(struct un_t *un, struct device *c)
6385 ret = sysfs_create_group(&c->kobj, &dgap_tty_attribute_group);
6389 dev_set_drvdata(c, un);
6393 static void dgap_remove_tty_sysfs(struct device *c)
6395 sysfs_remove_group(&c->kobj, &dgap_tty_attribute_group);
6399 * Parse a configuration file read into memory as a string.
6401 static int dgap_parsefile(char **in, int remove)
6403 struct cnode *p, *brd, *line, *conc;
6409 brd = line = conc = NULL;
6411 /* perhaps we are adding to an existing list? */
6412 while (p->next != NULL)
6415 /* file must start with a BEGIN */
6416 while ((rc = dgap_gettok(in, p)) != BEGIN) {
6418 dgap_err("unexpected EOF");
6424 rc = dgap_gettok(in, p);
6426 dgap_err("unexpected EOF");
6432 dgap_err("unexpected end of file");
6435 case BEGIN: /* should only be 1 begin */
6436 dgap_err("unexpected config_begin\n");
6442 case BOARD: /* board info */
6443 if (dgap_checknode(p))
6445 p->next = dgap_newnode(BNODE);
6447 dgap_err("out of memory");
6452 p->u.board.status = dgap_savestring("No");
6458 case APORT2_920P: /* AccelePort_4 */
6459 if (p->type != BNODE) {
6460 dgap_err("unexpected Digi_2r_920 string");
6463 p->u.board.type = APORT2_920P;
6464 p->u.board.v_type = 1;
6467 case APORT4_920P: /* AccelePort_4 */
6468 if (p->type != BNODE) {
6469 dgap_err("unexpected Digi_4r_920 string");
6472 p->u.board.type = APORT4_920P;
6473 p->u.board.v_type = 1;
6476 case APORT8_920P: /* AccelePort_8 */
6477 if (p->type != BNODE) {
6478 dgap_err("unexpected Digi_8r_920 string");
6481 p->u.board.type = APORT8_920P;
6482 p->u.board.v_type = 1;
6485 case PAPORT4: /* AccelePort_4 PCI */
6486 if (p->type != BNODE) {
6487 dgap_err("unexpected Digi_4r(PCI) string");
6490 p->u.board.type = PAPORT4;
6491 p->u.board.v_type = 1;
6494 case PAPORT8: /* AccelePort_8 PCI */
6495 if (p->type != BNODE) {
6496 dgap_err("unexpected Digi_8r string");
6499 p->u.board.type = PAPORT8;
6500 p->u.board.v_type = 1;
6503 case PCX: /* PCI C/X */
6504 if (p->type != BNODE) {
6505 dgap_err("unexpected Digi_C/X_(PCI) string");
6508 p->u.board.type = PCX;
6509 p->u.board.v_type = 1;
6510 p->u.board.conc1 = 0;
6511 p->u.board.conc2 = 0;
6512 p->u.board.module1 = 0;
6513 p->u.board.module2 = 0;
6516 case PEPC: /* PCI EPC/X */
6517 if (p->type != BNODE) {
6518 dgap_err("unexpected \"Digi_EPC/X_(PCI)\" string");
6521 p->u.board.type = PEPC;
6522 p->u.board.v_type = 1;
6523 p->u.board.conc1 = 0;
6524 p->u.board.conc2 = 0;
6525 p->u.board.module1 = 0;
6526 p->u.board.module2 = 0;
6529 case PPCM: /* PCI/Xem */
6530 if (p->type != BNODE) {
6531 dgap_err("unexpected PCI/Xem string");
6534 p->u.board.type = PPCM;
6535 p->u.board.v_type = 1;
6536 p->u.board.conc1 = 0;
6537 p->u.board.conc2 = 0;
6540 case IO: /* i/o port */
6541 if (p->type != BNODE) {
6542 dgap_err("IO port only vaild for boards");
6545 s = dgap_getword(in);
6547 dgap_err("unexpected end of file");
6550 p->u.board.portstr = dgap_savestring(s);
6551 if (kstrtol(s, 0, &p->u.board.port)) {
6552 dgap_err("bad number for IO port");
6555 p->u.board.v_port = 1;
6558 case MEM: /* memory address */
6559 if (p->type != BNODE) {
6560 dgap_err("memory address only vaild for boards");
6563 s = dgap_getword(in);
6565 dgap_err("unexpected end of file");
6568 p->u.board.addrstr = dgap_savestring(s);
6569 if (kstrtoul(s, 0, &p->u.board.addr)) {
6570 dgap_err("bad number for memory address");
6573 p->u.board.v_addr = 1;
6576 case PCIINFO: /* pci information */
6577 if (p->type != BNODE) {
6578 dgap_err("memory address only vaild for boards");
6581 s = dgap_getword(in);
6583 dgap_err("unexpected end of file");
6586 p->u.board.pcibusstr = dgap_savestring(s);
6587 if (kstrtoul(s, 0, &p->u.board.pcibus)) {
6588 dgap_err("bad number for pci bus");
6591 p->u.board.v_pcibus = 1;
6592 s = dgap_getword(in);
6594 dgap_err("unexpected end of file");
6597 p->u.board.pcislotstr = dgap_savestring(s);
6598 if (kstrtoul(s, 0, &p->u.board.pcislot)) {
6599 dgap_err("bad number for pci slot");
6602 p->u.board.v_pcislot = 1;
6606 if (p->type != BNODE) {
6607 dgap_err("install method only vaild for boards");
6610 s = dgap_getword(in);
6612 dgap_err("unexpected end of file");
6615 p->u.board.method = dgap_savestring(s);
6616 p->u.board.v_method = 1;
6620 if (p->type != BNODE) {
6621 dgap_err("config status only vaild for boards");
6624 s = dgap_getword(in);
6626 dgap_err("unexpected end of file");
6629 p->u.board.status = dgap_savestring(s);
6632 case NPORTS: /* number of ports */
6633 if (p->type == BNODE) {
6634 s = dgap_getword(in);
6636 dgap_err("unexpected end of file");
6639 if (kstrtol(s, 0, &p->u.board.nport)) {
6640 dgap_err("bad number for number of ports");
6643 p->u.board.v_nport = 1;
6644 } else if (p->type == CNODE) {
6645 s = dgap_getword(in);
6647 dgap_err("unexpected end of file");
6650 if (kstrtol(s, 0, &p->u.conc.nport)) {
6651 dgap_err("bad number for number of ports");
6654 p->u.conc.v_nport = 1;
6655 } else if (p->type == MNODE) {
6656 s = dgap_getword(in);
6658 dgap_err("unexpected end of file");
6661 if (kstrtol(s, 0, &p->u.module.nport)) {
6662 dgap_err("bad number for number of ports");
6665 p->u.module.v_nport = 1;
6667 dgap_err("nports only valid for concentrators or modules");
6672 case ID: /* letter ID used in tty name */
6673 s = dgap_getword(in);
6675 dgap_err("unexpected end of file");
6679 p->u.board.status = dgap_savestring(s);
6681 if (p->type == CNODE) {
6682 p->u.conc.id = dgap_savestring(s);
6684 } else if (p->type == MNODE) {
6685 p->u.module.id = dgap_savestring(s);
6686 p->u.module.v_id = 1;
6688 dgap_err("id only valid for concentrators or modules");
6693 case STARTO: /* start offset of ID */
6694 if (p->type == BNODE) {
6695 s = dgap_getword(in);
6697 dgap_err("unexpected end of file");
6700 if (kstrtol(s, 0, &p->u.board.start)) {
6701 dgap_err("bad number for start of tty count");
6704 p->u.board.v_start = 1;
6705 } else if (p->type == CNODE) {
6706 s = dgap_getword(in);
6708 dgap_err("unexpected end of file");
6711 if (kstrtol(s, 0, &p->u.conc.start)) {
6712 dgap_err("bad number for start of tty count");
6715 p->u.conc.v_start = 1;
6716 } else if (p->type == MNODE) {
6717 s = dgap_getword(in);
6719 dgap_err("unexpected end of file");
6722 if (kstrtol(s, 0, &p->u.module.start)) {
6723 dgap_err("bad number for start of tty count");
6726 p->u.module.v_start = 1;
6728 dgap_err("start only valid for concentrators or modules");
6733 case TTYN: /* tty name prefix */
6734 if (dgap_checknode(p))
6736 p->next = dgap_newnode(TNODE);
6738 dgap_err("out of memory");
6742 s = dgap_getword(in);
6744 dgap_err("unexpeced end of file");
6747 p->u.ttyname = dgap_savestring(s);
6748 if (!p->u.ttyname) {
6749 dgap_err("out of memory");
6754 case CU: /* cu name prefix */
6755 if (dgap_checknode(p))
6757 p->next = dgap_newnode(CUNODE);
6759 dgap_err("out of memory");
6763 s = dgap_getword(in);
6765 dgap_err("unexpeced end of file");
6768 p->u.cuname = dgap_savestring(s);
6770 dgap_err("out of memory");
6775 case LINE: /* line information */
6776 if (dgap_checknode(p))
6779 dgap_err("must specify board before line info");
6782 switch (brd->u.board.type) {
6784 dgap_err("line not vaild for PC/em");
6787 p->next = dgap_newnode(LNODE);
6789 dgap_err("out of memory");
6798 case CONC: /* concentrator information */
6799 if (dgap_checknode(p))
6802 dgap_err("must specify line info before concentrator");
6805 p->next = dgap_newnode(CNODE);
6807 dgap_err("out of memory");
6813 brd->u.board.conc2++;
6815 brd->u.board.conc1++;
6819 case CX: /* c/x type concentrator */
6820 if (p->type != CNODE) {
6821 dgap_err("cx only valid for concentrators");
6824 p->u.conc.type = CX;
6825 p->u.conc.v_type = 1;
6828 case EPC: /* epc type concentrator */
6829 if (p->type != CNODE) {
6830 dgap_err("cx only valid for concentrators");
6833 p->u.conc.type = EPC;
6834 p->u.conc.v_type = 1;
6837 case MOD: /* EBI module */
6838 if (dgap_checknode(p))
6841 dgap_err("must specify board info before EBI modules");
6844 switch (brd->u.board.type) {
6850 dgap_err("must specify concentrator info before EBI module");
6854 p->next = dgap_newnode(MNODE);
6856 dgap_err("out of memory");
6861 brd->u.board.module2++;
6863 brd->u.board.module1++;
6867 case PORTS: /* ports type EBI module */
6868 if (p->type != MNODE) {
6869 dgap_err("ports only valid for EBI modules");
6872 p->u.module.type = PORTS;
6873 p->u.module.v_type = 1;
6876 case MODEM: /* ports type EBI module */
6877 if (p->type != MNODE) {
6878 dgap_err("modem only valid for modem modules");
6881 p->u.module.type = MODEM;
6882 p->u.module.v_type = 1;
6886 if (p->type == LNODE) {
6887 s = dgap_getword(in);
6889 dgap_err("unexpected end of file");
6892 p->u.line.cable = dgap_savestring(s);
6893 p->u.line.v_cable = 1;
6897 case SPEED: /* sync line speed indication */
6898 if (p->type == LNODE) {
6899 s = dgap_getword(in);
6901 dgap_err("unexpected end of file");
6904 if (kstrtol(s, 0, &p->u.line.speed)) {
6905 dgap_err("bad number for line speed");
6908 p->u.line.v_speed = 1;
6909 } else if (p->type == CNODE) {
6910 s = dgap_getword(in);
6912 dgap_err("unexpected end of file");
6915 if (kstrtol(s, 0, &p->u.conc.speed)) {
6916 dgap_err("bad number for line speed");
6919 p->u.conc.v_speed = 1;
6921 dgap_err("speed valid only for lines or concentrators.");
6927 if (p->type == CNODE) {
6928 s = dgap_getword(in);
6930 dgap_err("unexpected end of file");
6933 p->u.conc.connect = dgap_savestring(s);
6934 p->u.conc.v_connect = 1;
6937 case PRINT: /* transparent print name prefix */
6938 if (dgap_checknode(p))
6940 p->next = dgap_newnode(PNODE);
6942 dgap_err("out of memory");
6946 s = dgap_getword(in);
6948 dgap_err("unexpeced end of file");
6951 p->u.printname = dgap_savestring(s);
6952 if (!p->u.printname) {
6953 dgap_err("out of memory");
6958 case CMAJOR: /* major number */
6959 if (dgap_checknode(p))
6961 p->next = dgap_newnode(JNODE);
6963 dgap_err("out of memory");
6967 s = dgap_getword(in);
6969 dgap_err("unexpected end of file");
6972 if (kstrtol(s, 0, &p->u.majornumber)) {
6973 dgap_err("bad number for major number");
6978 case ALTPIN: /* altpin setting */
6979 if (dgap_checknode(p))
6981 p->next = dgap_newnode(ANODE);
6983 dgap_err("out of memory");
6987 s = dgap_getword(in);
6989 dgap_err("unexpected end of file");
6992 if (kstrtol(s, 0, &p->u.altpin)) {
6993 dgap_err("bad number for altpin");
6998 case USEINTR: /* enable interrupt setting */
6999 if (dgap_checknode(p))
7001 p->next = dgap_newnode(INTRNODE);
7003 dgap_err("out of memory");
7007 s = dgap_getword(in);
7009 dgap_err("unexpected end of file");
7012 if (kstrtol(s, 0, &p->u.useintr)) {
7013 dgap_err("bad number for useintr");
7018 case TTSIZ: /* size of tty structure */
7019 if (dgap_checknode(p))
7021 p->next = dgap_newnode(TSNODE);
7023 dgap_err("out of memory");
7027 s = dgap_getword(in);
7029 dgap_err("unexpected end of file");
7032 if (kstrtol(s, 0, &p->u.ttysize)) {
7033 dgap_err("bad number for ttysize");
7038 case CHSIZ: /* channel structure size */
7039 if (dgap_checknode(p))
7041 p->next = dgap_newnode(CSNODE);
7043 dgap_err("out of memory");
7047 s = dgap_getword(in);
7049 dgap_err("unexpected end of file");
7052 if (kstrtol(s, 0, &p->u.chsize)) {
7053 dgap_err("bad number for chsize");
7058 case BSSIZ: /* board structure size */
7059 if (dgap_checknode(p))
7061 p->next = dgap_newnode(BSNODE);
7063 dgap_err("out of memory");
7067 s = dgap_getword(in);
7069 dgap_err("unexpected end of file");
7072 if (kstrtol(s, 0, &p->u.bssize)) {
7073 dgap_err("bad number for bssize");
7078 case UNTSIZ: /* sched structure size */
7079 if (dgap_checknode(p))
7081 p->next = dgap_newnode(USNODE);
7083 dgap_err("out of memory");
7087 s = dgap_getword(in);
7089 dgap_err("unexpected end of file");
7092 if (kstrtol(s, 0, &p->u.unsize)) {
7093 dgap_err("bad number for schedsize");
7098 case F2SIZ: /* f2200 structure size */
7099 if (dgap_checknode(p))
7101 p->next = dgap_newnode(FSNODE);
7103 dgap_err("out of memory");
7107 s = dgap_getword(in);
7109 dgap_err("unexpected end of file");
7112 if (kstrtol(s, 0, &p->u.f2size)) {
7113 dgap_err("bad number for f2200size");
7118 case VPSIZ: /* vpix structure size */
7119 if (dgap_checknode(p))
7121 p->next = dgap_newnode(VSNODE);
7123 dgap_err("out of memory");
7127 s = dgap_getword(in);
7129 dgap_err("unexpected end of file");
7132 if (kstrtol(s, 0, &p->u.vpixsize)) {
7133 dgap_err("bad number for vpixsize");
7142 * dgap_sindex: much like index(), but it looks for a match of any character in
7143 * the group, and returns that position. If the first character is a ^, then
7144 * this will match the first occurrence not in that group.
7146 static char *dgap_sindex(char *string, char *group)
7150 if (!string || !group)
7151 return (char *) NULL;
7153 if (*group == '^') {
7155 for (; *string; string++) {
7156 for (ptr = group; *ptr; ptr++) {
7157 if (*ptr == *string)
7164 for (; *string; string++) {
7165 for (ptr = group; *ptr; ptr++) {
7166 if (*ptr == *string)
7172 return (char *) NULL;
7176 * Get a token from the input file; return 0 if end of file is reached
7178 static int dgap_gettok(char **in, struct cnode *p)
7183 if (strstr(dgap_cword, "boar")) {
7184 w = dgap_getword(in);
7185 snprintf(dgap_cword, MAXCWORD, "%s", w);
7186 for (t = dgap_tlist; t->token != 0; t++) {
7187 if (!strcmp(w, t->string))
7190 dgap_err("board !!type not specified");
7193 while ((w = dgap_getword(in))) {
7194 snprintf(dgap_cword, MAXCWORD, "%s", w);
7195 for (t = dgap_tlist; t->token != 0; t++) {
7196 if (!strcmp(w, t->string))
7205 * get a word from the input stream, also keep track of current line number.
7206 * words are separated by whitespace.
7208 static char *dgap_getword(char **in)
7210 char *ret_ptr = *in;
7212 char *ptr = dgap_sindex(*in, " \t\n");
7214 /* If no word found, return null */
7218 /* Mark new location for our buffer */
7222 /* Eat any extra spaces/tabs/newlines that might be present */
7223 while (*in && **in && ((**in == ' ') ||
7234 * print an error message, giving the line number in the file where
7235 * the error occurred.
7237 static void dgap_err(char *s)
7239 pr_err("dgap: parse: %s\n", s);
7243 * allocate a new configuration node of type t
7245 static struct cnode *dgap_newnode(int t)
7249 n = kmalloc(sizeof(struct cnode), GFP_ATOMIC);
7251 memset((char *)n, 0, sizeof(struct cnode));
7258 * dgap_checknode: see if all the necessary info has been supplied for a node
7259 * before creating the next node.
7261 static int dgap_checknode(struct cnode *p)
7265 if (p->u.board.v_type == 0) {
7266 dgap_err("board type !not specified");
7273 if (p->u.line.v_speed == 0) {
7274 dgap_err("line speed not specified");
7280 if (p->u.conc.v_type == 0) {
7281 dgap_err("concentrator type not specified");
7284 if (p->u.conc.v_speed == 0) {
7285 dgap_err("concentrator line speed not specified");
7288 if (p->u.conc.v_nport == 0) {
7289 dgap_err("number of ports on concentrator not specified");
7292 if (p->u.conc.v_id == 0) {
7293 dgap_err("concentrator id letter not specified");
7299 if (p->u.module.v_type == 0) {
7300 dgap_err("EBI module type not specified");
7303 if (p->u.module.v_nport == 0) {
7304 dgap_err("number of ports on EBI module not specified");
7307 if (p->u.module.v_id == 0) {
7308 dgap_err("EBI module id letter not specified");
7317 * save a string somewhere
7319 static char *dgap_savestring(char *s)
7323 p = kmalloc(strlen(s) + 1, GFP_ATOMIC);
7330 * Given a board pointer, returns whether we should use interrupts or not.
7332 static uint dgap_config_get_useintr(struct board_t *bd)
7334 struct cnode *p = NULL;
7339 for (p = bd->bd_config; p; p = p->next) {
7343 * check for pcxr types.
7345 return p->u.useintr;
7351 /* If not found, then don't turn on interrupts. */
7356 * Given a board pointer, returns whether we turn on altpin or not.
7358 static uint dgap_config_get_altpin(struct board_t *bd)
7360 struct cnode *p = NULL;
7365 for (p = bd->bd_config; p; p = p->next) {
7369 * check for pcxr types.
7377 /* If not found, then don't turn on interrupts. */
7382 * Given a specific type of board, if found, detached link and
7383 * returns the first occurrence in the list.
7385 static struct cnode *dgap_find_config(int type, int bus, int slot)
7387 struct cnode *p, *prev = NULL, *prev2 = NULL, *found = NULL;
7391 while (p->next != NULL) {
7395 if (p->type == BNODE) {
7397 if (p->u.board.type == type) {
7399 if (p->u.board.v_pcibus &&
7400 p->u.board.pcibus != bus)
7402 if (p->u.board.v_pcislot &&
7403 p->u.board.pcislot != slot)
7408 * Keep walking thru the list till we
7409 * find the next board.
7411 while (p->next != NULL) {
7414 if (p->type == BNODE) {
7417 * Mark the end of our 1 board
7423 * Link the "next" board to the
7424 * previous board, effectively
7425 * "unlinking" our board from
7434 * It must be the last board in the list.
7445 * Given a board pointer, walks the config link, counting up
7446 * all ports user specified should be on the board.
7447 * (This does NOT mean they are all actually present right now tho)
7449 static uint dgap_config_get_num_prts(struct board_t *bd)
7452 struct cnode *p = NULL;
7457 for (p = bd->bd_config; p; p = p->next) {
7462 * check for pcxr types.
7464 if (p->u.board.type > EPCFE)
7465 count += p->u.board.nport;
7468 count += p->u.conc.nport;
7471 count += p->u.module.nport;
7478 static char *dgap_create_config_string(struct board_t *bd, char *string)
7481 struct cnode *p = NULL;
7482 struct cnode *q = NULL;
7490 for (p = bd->bd_config; p; p = p->next) {
7496 *ptr = p->u.line.speed;
7501 * Because the EPC/con concentrators can have EM modules
7502 * hanging off of them, we have to walk ahead in the
7503 * list and keep adding the number of ports on each EM
7504 * to the config. UGH!
7506 speed = p->u.conc.speed;
7508 if ((q != NULL) && (q->type == MNODE)) {
7509 *ptr = (p->u.conc.nport + 0x80);
7512 while ((q->next != NULL) &&
7513 (q->next->type) == MNODE) {
7515 *ptr = (q->u.module.nport + 0x80);
7520 *ptr = q->u.module.nport;
7523 *ptr = p->u.conc.nport;