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 struct board_t *dgap_found_board(struct pci_dev *pdev, int id,
75 static void dgap_cleanup_board(struct board_t *brd);
76 static void dgap_poll_handler(ulong dummy);
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_do_remap(struct board_t *brd);
80 static void dgap_release_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 channel_t *ch, struct un_t *un,
90 struct digi_t __user *retinfo);
91 static int dgap_tty_digiseta(struct channel_t *ch, struct board_t *bd,
92 struct un_t *un, 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 void dgap_tty_unregister(struct board_t *brd);
127 static int dgap_tty_init(struct board_t *);
128 static void dgap_tty_free(struct board_t *);
129 static void dgap_cleanup_tty(struct board_t *);
130 static void dgap_carrier(struct channel_t *ch);
131 static void dgap_input(struct channel_t *ch);
134 * Our function prototypes from dgap_fep5
136 static void dgap_cmdw_ext(struct channel_t *ch, u16 cmd, u16 word, uint ncmds);
137 static int dgap_event(struct board_t *bd);
139 static void dgap_poll_tasklet(unsigned long data);
140 static void dgap_cmdb(struct channel_t *ch, u8 cmd, u8 byte1,
141 u8 byte2, uint ncmds);
142 static void dgap_cmdw(struct channel_t *ch, u8 cmd, u16 word, uint ncmds);
143 static void dgap_wmove(struct channel_t *ch, char *buf, uint cnt);
144 static int dgap_param(struct channel_t *ch, struct board_t *bd, u32 un_type);
145 static void dgap_parity_scan(struct channel_t *ch, unsigned char *cbuf,
146 unsigned char *fbuf, int *len);
147 static uint dgap_get_custom_baud(struct channel_t *ch);
148 static void dgap_firmware_reset_port(struct channel_t *ch);
151 * Function prototypes from dgap_parse.c.
153 static int dgap_gettok(char **in, struct cnode *p);
154 static char *dgap_getword(char **in);
155 static struct cnode *dgap_newnode(int t);
156 static int dgap_checknode(struct cnode *p);
157 static void dgap_err(char *s);
160 * Function prototypes from dgap_sysfs.h
168 static void dgap_create_ports_sysfiles(struct board_t *bd);
169 static void dgap_remove_ports_sysfiles(struct board_t *bd);
171 static int dgap_create_driver_sysfiles(struct pci_driver *);
172 static void dgap_remove_driver_sysfiles(struct pci_driver *);
174 static void dgap_create_tty_sysfs(struct un_t *un, struct device *c);
175 static void dgap_remove_tty_sysfs(struct device *c);
178 * Function prototypes from dgap_parse.h
180 static int dgap_parsefile(char **in);
181 static struct cnode *dgap_find_config(int type, int bus, int slot);
182 static uint dgap_config_get_num_prts(struct board_t *bd);
183 static char *dgap_create_config_string(struct board_t *bd, char *string);
184 static uint dgap_config_get_useintr(struct board_t *bd);
185 static uint dgap_config_get_altpin(struct board_t *bd);
187 static int dgap_ms_sleep(ulong ms);
188 static void dgap_do_bios_load(struct board_t *brd, const u8 *ubios, int len);
189 static void dgap_do_fep_load(struct board_t *brd, const u8 *ufep, int len);
190 #ifdef DIGI_CONCENTRATORS_SUPPORTED
191 static void dgap_do_conc_load(struct board_t *brd, u8 *uaddr, int len);
193 static int dgap_alloc_flipbuf(struct board_t *brd);
194 static void dgap_free_flipbuf(struct board_t *brd);
195 static int dgap_request_irq(struct board_t *brd);
196 static void dgap_free_irq(struct board_t *brd);
198 static void dgap_get_vpd(struct board_t *brd);
199 static void dgap_do_reset_board(struct board_t *brd);
200 static int dgap_test_bios(struct board_t *brd);
201 static int dgap_test_fep(struct board_t *brd);
202 static int dgap_tty_register_ports(struct board_t *brd);
203 static int dgap_firmware_load(struct pci_dev *pdev, int card_type,
204 struct board_t *brd);
206 static void dgap_cleanup_module(void);
208 module_exit(dgap_cleanup_module);
211 * File operations permitted on Control/Management major.
213 static const struct file_operations dgap_board_fops = {
214 .owner = THIS_MODULE,
217 static uint dgap_numboards;
218 static struct board_t *dgap_board[MAXBOARDS];
219 static ulong dgap_poll_counter;
220 static int dgap_driver_state = DRIVER_INITIALIZED;
221 static int dgap_poll_tick = 20; /* Poll interval - 20 ms */
223 static struct class *dgap_class;
225 static struct board_t *dgap_boards_by_major[256];
226 static uint dgap_count = 500;
231 static DEFINE_SPINLOCK(dgap_poll_lock); /* Poll scheduling lock */
232 static ulong dgap_poll_time; /* Time of next poll */
233 static uint dgap_poll_stop; /* Used to tell poller to stop */
234 static struct timer_list dgap_poll_timer;
239 Card Model Number of Ports Interface
240 ----------------------------------------------------------------
241 Acceleport Xem 4 - 64 (EIA232 & EIA422)
242 Acceleport Xr 4 & 8 (EIA232)
243 Acceleport Xr 920 4 & 8 (EIA232)
244 Acceleport C/X 8 - 128 (EIA232)
245 Acceleport EPC/X 8 - 224 (EIA232)
246 Acceleport Xr/422 4 & 8 (EIA422)
247 Acceleport 2r/920 2 (EIA232)
248 Acceleport 4r/920 4 (EIA232)
249 Acceleport 8r/920 8 (EIA232)
251 IBM 8-Port Asynchronous PCI Adapter (EIA232)
252 IBM 128-Port Asynchronous PCI Adapter (EIA232 & EIA422)
255 static struct pci_device_id dgap_pci_tbl[] = {
256 { DIGI_VID, PCI_DEV_XEM_DID, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0 },
257 { DIGI_VID, PCI_DEV_CX_DID, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 1 },
258 { DIGI_VID, PCI_DEV_CX_IBM_DID, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 2 },
259 { DIGI_VID, PCI_DEV_EPCJ_DID, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 3 },
260 { DIGI_VID, PCI_DEV_920_2_DID, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 4 },
261 { DIGI_VID, PCI_DEV_920_4_DID, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 5 },
262 { DIGI_VID, PCI_DEV_920_8_DID, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 6 },
263 { DIGI_VID, PCI_DEV_XR_DID, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 7 },
264 { DIGI_VID, PCI_DEV_XRJ_DID, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 8 },
265 { DIGI_VID, PCI_DEV_XR_422_DID, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 9 },
266 { DIGI_VID, PCI_DEV_XR_IBM_DID, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 10 },
267 { DIGI_VID, PCI_DEV_XR_SAIP_DID, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 11 },
268 { DIGI_VID, PCI_DEV_XR_BULL_DID, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 12 },
269 { DIGI_VID, PCI_DEV_920_8_HP_DID, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 13 },
270 { DIGI_VID, PCI_DEV_XEM_HP_DID, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 14 },
271 {0,} /* 0 terminated list. */
273 MODULE_DEVICE_TABLE(pci, dgap_pci_tbl);
276 * A generic list of Product names, PCI Vendor ID, and PCI Device ID.
285 static struct board_id dgap_ids[] = {
286 { PPCM, PCI_DEV_XEM_NAME, 64, (T_PCXM|T_PCLITE|T_PCIBUS) },
287 { PCX, PCI_DEV_CX_NAME, 128, (T_CX|T_PCIBUS) },
288 { PCX, PCI_DEV_CX_IBM_NAME, 128, (T_CX|T_PCIBUS) },
289 { PEPC, PCI_DEV_EPCJ_NAME, 224, (T_EPC|T_PCIBUS) },
290 { APORT2_920P, PCI_DEV_920_2_NAME, 2, (T_PCXR|T_PCLITE|T_PCIBUS) },
291 { APORT4_920P, PCI_DEV_920_4_NAME, 4, (T_PCXR|T_PCLITE|T_PCIBUS) },
292 { APORT8_920P, PCI_DEV_920_8_NAME, 8, (T_PCXR|T_PCLITE|T_PCIBUS) },
293 { PAPORT8, PCI_DEV_XR_NAME, 8, (T_PCXR|T_PCLITE|T_PCIBUS) },
294 { PAPORT8, PCI_DEV_XRJ_NAME, 8, (T_PCXR|T_PCLITE|T_PCIBUS) },
295 { PAPORT8, PCI_DEV_XR_422_NAME, 8, (T_PCXR|T_PCLITE|T_PCIBUS) },
296 { PAPORT8, PCI_DEV_XR_IBM_NAME, 8, (T_PCXR|T_PCLITE|T_PCIBUS) },
297 { PAPORT8, PCI_DEV_XR_SAIP_NAME, 8, (T_PCXR|T_PCLITE|T_PCIBUS) },
298 { PAPORT8, PCI_DEV_XR_BULL_NAME, 8, (T_PCXR|T_PCLITE|T_PCIBUS) },
299 { APORT8_920P, PCI_DEV_920_8_HP_NAME, 8, (T_PCXR|T_PCLITE|T_PCIBUS) },
300 { PPCM, PCI_DEV_XEM_HP_NAME, 64, (T_PCXM|T_PCLITE|T_PCIBUS) },
301 {0,} /* 0 terminated list. */
304 static struct pci_driver dgap_driver = {
306 .probe = dgap_init_one,
307 .id_table = dgap_pci_tbl,
308 .remove = dgap_remove_one,
311 struct firmware_info {
312 u8 *conf_name; /* dgap.conf */
313 u8 *bios_name; /* BIOS filename */
314 u8 *fep_name; /* FEP filename */
315 u8 *con_name; /* Concentrator filename FIXME*/
316 int num; /* sequence number */
320 * Firmware - BIOS, FEP, and CONC filenames
322 static struct firmware_info fw_info[] = {
323 { "dgap/dgap.conf", "dgap/sxbios.bin", "dgap/sxfep.bin", NULL, 0 },
324 { "dgap/dgap.conf", "dgap/cxpbios.bin", "dgap/cxpfep.bin", NULL, 1 },
325 { "dgap/dgap.conf", "dgap/cxpbios.bin", "dgap/cxpfep.bin", NULL, 2 },
326 { "dgap/dgap.conf", "dgap/pcibios.bin", "dgap/pcifep.bin", NULL, 3 },
327 { "dgap/dgap.conf", "dgap/xrbios.bin", "dgap/xrfep.bin", NULL, 4 },
328 { "dgap/dgap.conf", "dgap/xrbios.bin", "dgap/xrfep.bin", NULL, 5 },
329 { "dgap/dgap.conf", "dgap/xrbios.bin", "dgap/xrfep.bin", NULL, 6 },
330 { "dgap/dgap.conf", "dgap/xrbios.bin", "dgap/xrfep.bin", NULL, 7 },
331 { "dgap/dgap.conf", "dgap/xrbios.bin", "dgap/xrfep.bin", NULL, 8 },
332 { "dgap/dgap.conf", "dgap/xrbios.bin", "dgap/xrfep.bin", NULL, 9 },
333 { "dgap/dgap.conf", "dgap/xrbios.bin", "dgap/xrfep.bin", NULL, 10 },
334 { "dgap/dgap.conf", "dgap/xrbios.bin", "dgap/xrfep.bin", NULL, 11 },
335 { "dgap/dgap.conf", "dgap/xrbios.bin", "dgap/xrfep.bin", NULL, 12 },
336 { "dgap/dgap.conf", "dgap/xrbios.bin", "dgap/xrfep.bin", NULL, 13 },
337 { "dgap/dgap.conf", "dgap/sxbios.bin", "dgap/sxfep.bin", NULL, 14 },
342 * Default transparent print information.
344 static struct digi_t dgap_digi_init = {
345 .digi_flags = DIGI_COOK, /* Flags */
346 .digi_maxcps = 100, /* Max CPS */
347 .digi_maxchar = 50, /* Max chars in print queue */
348 .digi_bufsize = 100, /* Printer buffer size */
349 .digi_onlen = 4, /* size of printer on string */
350 .digi_offlen = 4, /* size of printer off string */
351 .digi_onstr = "\033[5i", /* ANSI printer on string ] */
352 .digi_offstr = "\033[4i", /* ANSI printer off string ] */
353 .digi_term = "ansi" /* default terminal type */
357 * Define a local default termios struct. All ports will be created
358 * with this termios initially.
360 * This defines a raw port at 9600 baud, 8 data bits, no parity,
364 static struct ktermios dgap_default_termios = {
365 .c_iflag = (DEFAULT_IFLAGS), /* iflags */
366 .c_oflag = (DEFAULT_OFLAGS), /* oflags */
367 .c_cflag = (DEFAULT_CFLAGS), /* cflags */
368 .c_lflag = (DEFAULT_LFLAGS), /* lflags */
373 static const struct tty_operations dgap_tty_ops = {
374 .open = dgap_tty_open,
375 .close = dgap_tty_close,
376 .write = dgap_tty_write,
377 .write_room = dgap_tty_write_room,
378 .flush_buffer = dgap_tty_flush_buffer,
379 .chars_in_buffer = dgap_tty_chars_in_buffer,
380 .flush_chars = dgap_tty_flush_chars,
381 .ioctl = dgap_tty_ioctl,
382 .set_termios = dgap_tty_set_termios,
383 .stop = dgap_tty_stop,
384 .start = dgap_tty_start,
385 .throttle = dgap_tty_throttle,
386 .unthrottle = dgap_tty_unthrottle,
387 .hangup = dgap_tty_hangup,
388 .put_char = dgap_tty_put_char,
389 .tiocmget = dgap_tty_tiocmget,
390 .tiocmset = dgap_tty_tiocmset,
391 .break_ctl = dgap_tty_send_break,
392 .wait_until_sent = dgap_tty_wait_until_sent,
393 .send_xchar = dgap_tty_send_xchar
397 * Our needed internal static variables from dgap_parse.c
399 static struct cnode dgap_head;
401 static char dgap_cword[MAXCWORD];
408 static struct toklist dgap_tlist[] = {
409 { BEGIN, "config_begin" },
410 { END, "config_end" },
412 { PCX, "Digi_AccelePort_C/X_PCI" },
413 { PEPC, "Digi_AccelePort_EPC/X_PCI" },
414 { PPCM, "Digi_AccelePort_Xem_PCI" },
415 { APORT2_920P, "Digi_AccelePort_2r_920_PCI" },
416 { APORT4_920P, "Digi_AccelePort_4r_920_PCI" },
417 { APORT8_920P, "Digi_AccelePort_8r_920_PCI" },
418 { PAPORT4, "Digi_AccelePort_4r_PCI(EIA-232/RS-422)" },
419 { PAPORT8, "Digi_AccelePort_8r_PCI(EIA-232/RS-422)" },
421 { PCIINFO, "pciinfo" },
424 { CONC, "concentrator" },
434 { CONNECT, "connect" },
435 { METHOD, "method" },
436 { STATUS, "status" },
437 { CUSTOM, "Custom" },
443 { NPORTS, "nports" },
448 { ALTPIN, "altpin" },
449 { USEINTR, "useintr" },
450 { TTSIZ, "ttysize" },
452 { BSSIZ, "boardsize" },
453 { UNTSIZ, "schedsize" },
454 { F2SIZ, "f2200size" },
455 { VPSIZ, "vpixsize" },
459 /************************************************************************
461 * Driver load/unload functions
463 ************************************************************************/
468 * Module load. This is where it all starts.
470 static int dgap_init_module(void)
474 pr_info("%s, Digi International Part Number %s\n", DG_NAME, DG_PART);
480 rc = pci_register_driver(&dgap_driver);
484 rc = dgap_create_driver_sysfiles(&dgap_driver);
488 dgap_driver_state = DRIVER_READY;
494 dgap_cleanup_module();
498 module_init(dgap_init_module);
503 static int dgap_start(void)
507 struct device *device;
510 * make sure that the globals are
511 * init'd before we do anything else
517 pr_info("For the tools package please visit http://www.digi.com\n");
520 * Register our base character device into the kernel.
524 * Register management/dpa devices
526 rc = register_chrdev(DIGI_DGAP_MAJOR, "dgap", &dgap_board_fops);
530 dgap_class = class_create(THIS_MODULE, "dgap_mgmt");
531 if (IS_ERR(dgap_class)) {
532 rc = PTR_ERR(dgap_class);
536 device = device_create(dgap_class, NULL,
537 MKDEV(DIGI_DGAP_MAJOR, 0),
539 if (IS_ERR(device)) {
540 rc = PTR_ERR(device);
544 /* Start the poller */
545 spin_lock_irqsave(&dgap_poll_lock, flags);
546 init_timer(&dgap_poll_timer);
547 dgap_poll_timer.function = dgap_poll_handler;
548 dgap_poll_timer.data = 0;
549 dgap_poll_time = jiffies + dgap_jiffies_from_ms(dgap_poll_tick);
550 dgap_poll_timer.expires = dgap_poll_time;
551 spin_unlock_irqrestore(&dgap_poll_lock, flags);
553 add_timer(&dgap_poll_timer);
558 class_destroy(dgap_class);
560 unregister_chrdev(DIGI_DGAP_MAJOR, "dgap");
564 static int dgap_init_one(struct pci_dev *pdev, const struct pci_device_id *ent)
569 if (dgap_numboards >= MAXBOARDS)
572 rc = pci_enable_device(pdev);
576 brd = dgap_found_board(pdev, ent->driver_data, dgap_numboards);
580 rc = dgap_firmware_load(pdev, ent->driver_data, brd);
584 rc = dgap_alloc_flipbuf(brd);
588 rc = dgap_tty_register(brd);
592 rc = dgap_request_irq(brd);
597 * Do tty device initialization.
599 rc = dgap_tty_init(brd);
603 rc = dgap_tty_register_ports(brd);
607 brd->state = BOARD_READY;
608 brd->dpastatus = BD_RUNNING;
610 dgap_board[dgap_numboards++] = brd;
619 dgap_tty_unregister(brd);
621 dgap_free_flipbuf(brd);
623 dgap_release_remap(brd);
629 static void dgap_remove_one(struct pci_dev *dev)
635 * dgap_cleanup_module()
637 * Module unload. This is where it all ends.
639 static void dgap_cleanup_module(void)
644 spin_lock_irqsave(&dgap_poll_lock, lock_flags);
646 spin_unlock_irqrestore(&dgap_poll_lock, lock_flags);
648 /* Turn off poller right away. */
649 del_timer_sync(&dgap_poll_timer);
651 dgap_remove_driver_sysfiles(&dgap_driver);
653 device_destroy(dgap_class, MKDEV(DIGI_DGAP_MAJOR, 0));
654 class_destroy(dgap_class);
655 unregister_chrdev(DIGI_DGAP_MAJOR, "dgap");
657 for (i = 0; i < dgap_numboards; ++i) {
658 dgap_remove_ports_sysfiles(dgap_board[i]);
659 dgap_cleanup_tty(dgap_board[i]);
660 dgap_cleanup_board(dgap_board[i]);
664 pci_unregister_driver(&dgap_driver);
668 * dgap_cleanup_board()
670 * Free all the memory associated with a board
672 static void dgap_cleanup_board(struct board_t *brd)
676 if (!brd || brd->magic != DGAP_BOARD_MAGIC)
681 tasklet_kill(&brd->helper_tasklet);
683 if (brd->re_map_port) {
684 release_mem_region(brd->membase + 0x200000, 0x200000);
685 iounmap(brd->re_map_port);
686 brd->re_map_port = NULL;
689 if (brd->re_map_membase) {
690 release_mem_region(brd->membase, 0x200000);
691 iounmap(brd->re_map_membase);
692 brd->re_map_membase = NULL;
695 /* Free all allocated channels structs */
696 for (i = 0; i < MAXPORTS ; i++)
697 kfree(brd->channels[i]);
700 kfree(brd->flipflagbuf);
702 dgap_board[brd->boardnum] = NULL;
710 * A board has been found, init it.
712 static struct board_t *dgap_found_board(struct pci_dev *pdev, int id,
716 unsigned int pci_irq;
720 /* get the board structure and prep it */
721 brd = kzalloc(sizeof(struct board_t), GFP_KERNEL);
723 return ERR_PTR(-ENOMEM);
725 /* store the info for the board we've found */
726 brd->magic = DGAP_BOARD_MAGIC;
727 brd->boardnum = boardnum;
728 brd->vendor = dgap_pci_tbl[id].vendor;
729 brd->device = dgap_pci_tbl[id].device;
731 brd->pci_bus = pdev->bus->number;
732 brd->pci_slot = PCI_SLOT(pdev->devfn);
733 brd->name = dgap_ids[id].name;
734 brd->maxports = dgap_ids[id].maxports;
735 brd->type = dgap_ids[id].config_type;
736 brd->dpatype = dgap_ids[id].dpatype;
737 brd->dpastatus = BD_NOFEP;
738 init_waitqueue_head(&brd->state_wait);
740 spin_lock_init(&brd->bd_lock);
743 brd->inhibit_poller = FALSE;
744 brd->wait_for_bios = 0;
745 brd->wait_for_fep = 0;
747 for (i = 0; i < MAXPORTS; i++)
748 brd->channels[i] = NULL;
750 /* store which card & revision we have */
751 pci_read_config_word(pdev, PCI_SUBSYSTEM_VENDOR_ID, &brd->subvendor);
752 pci_read_config_word(pdev, PCI_SUBSYSTEM_ID, &brd->subdevice);
753 pci_read_config_byte(pdev, PCI_REVISION_ID, &brd->rev);
758 /* get the PCI Base Address Registers */
760 /* Xr Jupiter and EPC use BAR 2 */
761 if (brd->device == PCI_DEV_XRJ_DID || brd->device == PCI_DEV_EPCJ_DID) {
762 brd->membase = pci_resource_start(pdev, 2);
763 brd->membase_end = pci_resource_end(pdev, 2);
765 /* Everyone else uses BAR 0 */
767 brd->membase = pci_resource_start(pdev, 0);
768 brd->membase_end = pci_resource_end(pdev, 0);
776 if (brd->membase & 1)
782 * On the PCI boards, there is no IO space allocated
783 * The I/O registers will be in the first 3 bytes of the
784 * upper 2MB of the 4MB memory space. The board memory
785 * will be mapped into the low 2MB of the 4MB memory space
787 brd->port = brd->membase + PCI_IO_OFFSET;
788 brd->port_end = brd->port + PCI_IO_SIZE;
791 * Special initialization for non-PLX boards
793 if (brd->device != PCI_DEV_XRJ_DID && brd->device != PCI_DEV_EPCJ_DID) {
796 pci_write_config_byte(pdev, 0x40, 0);
797 pci_write_config_byte(pdev, 0x46, 0);
799 /* Limit burst length to 2 doubleword transactions */
800 pci_write_config_byte(pdev, 0x42, 1);
803 * Enable IO and mem if not already done.
804 * This was needed for support on Itanium.
806 pci_read_config_word(pdev, PCI_COMMAND, &cmd);
807 cmd |= (PCI_COMMAND_IO | PCI_COMMAND_MEMORY);
808 pci_write_config_word(pdev, PCI_COMMAND, cmd);
811 /* init our poll helper tasklet */
812 tasklet_init(&brd->helper_tasklet, dgap_poll_tasklet,
813 (unsigned long) brd);
815 ret = dgap_do_remap(brd);
819 pr_info("dgap: board %d: %s (rev %d), irq %ld\n",
820 boardnum, brd->name, brd->rev, brd->irq);
831 static int dgap_request_irq(struct board_t *brd)
835 if (!brd || brd->magic != DGAP_BOARD_MAGIC)
838 brd->use_interrupts = dgap_config_get_useintr(brd);
841 * Set up our interrupt handler if we are set to do interrupts.
843 if (brd->use_interrupts && brd->irq) {
845 rc = request_irq(brd->irq, dgap_intr, IRQF_SHARED, "DGAP", brd);
858 static void dgap_free_irq(struct board_t *brd)
860 if (brd->intr_used && brd->irq)
861 free_irq(brd->irq, brd);
864 static int dgap_firmware_load(struct pci_dev *pdev, int card_type,
867 const struct firmware *fw;
870 char *dgap_config_buf;
873 dgap_do_reset_board(brd);
875 if (fw_info[card_type].conf_name) {
876 ret = request_firmware(&fw, fw_info[card_type].conf_name,
879 pr_err("dgap: config file %s not found\n",
880 fw_info[card_type].conf_name);
884 dgap_config_buf = kzalloc(fw->size + 1, GFP_KERNEL);
885 if (!dgap_config_buf) {
886 release_firmware(fw);
890 memcpy(dgap_config_buf, fw->data, fw->size);
891 release_firmware(fw);
894 * preserve dgap_config_buf
895 * as dgap_parsefile would
896 * otherwise alter it.
898 tmp_ptr = dgap_config_buf;
900 if (dgap_parsefile(&tmp_ptr) != 0) {
901 kfree(dgap_config_buf);
904 kfree(dgap_config_buf);
908 * Match this board to a config the user created for us.
911 dgap_find_config(brd->type, brd->pci_bus, brd->pci_slot);
914 * Because the 4 port Xr products share the same PCI ID
915 * as the 8 port Xr products, if we receive a NULL config
916 * back, and this is a PAPORT8 board, retry with a
917 * PAPORT4 attempt as well.
919 if (brd->type == PAPORT8 && !brd->bd_config)
921 dgap_find_config(PAPORT4, brd->pci_bus, brd->pci_slot);
923 if (!brd->bd_config) {
924 pr_err("dgap: No valid configuration found\n");
928 if (fw_info[card_type].bios_name) {
929 ret = request_firmware(&fw, fw_info[card_type].bios_name,
932 pr_err("dgap: bios file %s not found\n",
933 fw_info[card_type].bios_name);
936 dgap_do_bios_load(brd, fw->data, fw->size);
937 release_firmware(fw);
939 /* Wait for BIOS to test board... */
940 ret = dgap_test_bios(brd);
945 if (fw_info[card_type].fep_name) {
946 ret = request_firmware(&fw, fw_info[card_type].fep_name,
949 pr_err("dgap: fep file %s not found\n",
950 fw_info[card_type].fep_name);
953 dgap_do_fep_load(brd, fw->data, fw->size);
954 release_firmware(fw);
956 /* Wait for FEP to load on board... */
957 ret = dgap_test_fep(brd);
962 #ifdef DIGI_CONCENTRATORS_SUPPORTED
964 * If this is a CX or EPCX, we need to see if the firmware
965 * is requesting a concentrator image from us.
967 if ((bd->type == PCX) || (bd->type == PEPC)) {
968 chk_addr = (u16 *) (vaddr + DOWNREQ);
969 /* Nonzero if FEP is requesting concentrator image. */
970 check = readw(chk_addr);
971 vaddr = brd->re_map_membase;
974 if (fw_info[card_type].con_name && check && vaddr) {
975 ret = request_firmware(&fw, fw_info[card_type].con_name,
978 pr_err("dgap: conc file %s not found\n",
979 fw_info[card_type].con_name);
982 /* Put concentrator firmware loading code here */
983 offset = readw((u16 *) (vaddr + DOWNREQ));
984 memcpy_toio(offset, fw->data, fw->size);
986 dgap_do_conc_load(brd, (char *)fw->data, fw->size)
987 release_firmware(fw);
997 static int dgap_do_remap(struct board_t *brd)
999 if (!brd || brd->magic != DGAP_BOARD_MAGIC)
1002 if (!request_mem_region(brd->membase, 0x200000, "dgap"))
1005 if (!request_mem_region(brd->membase + PCI_IO_OFFSET, 0x200000,
1007 release_mem_region(brd->membase, 0x200000);
1011 brd->re_map_membase = ioremap(brd->membase, 0x200000);
1012 if (!brd->re_map_membase) {
1013 release_mem_region(brd->membase, 0x200000);
1014 release_mem_region(brd->membase + PCI_IO_OFFSET, 0x200000);
1018 brd->re_map_port = ioremap((brd->membase + PCI_IO_OFFSET), 0x200000);
1019 if (!brd->re_map_port) {
1020 release_mem_region(brd->membase, 0x200000);
1021 release_mem_region(brd->membase + PCI_IO_OFFSET, 0x200000);
1022 iounmap(brd->re_map_membase);
1029 static void dgap_release_remap(struct board_t *brd)
1031 release_mem_region(brd->membase, 0x200000);
1032 release_mem_region(brd->membase + PCI_IO_OFFSET, 0x200000);
1033 iounmap(brd->re_map_membase);
1035 /*****************************************************************************
1055 * As each timer expires, it determines (a) whether the "transmit"
1056 * waiter needs to be woken up, and (b) whether the poller needs to
1059 ******************************************************************************/
1061 static void dgap_poll_handler(ulong dummy)
1064 struct board_t *brd;
1065 unsigned long lock_flags;
1068 dgap_poll_counter++;
1071 * Do not start the board state machine until
1072 * driver tells us its up and running, and has
1073 * everything it needs.
1075 if (dgap_driver_state != DRIVER_READY)
1076 goto schedule_poller;
1079 * If we have just 1 board, or the system is not SMP,
1080 * then use the typical old style poller.
1081 * Otherwise, use our new tasklet based poller, which should
1082 * speed things up for multiple boards.
1084 if ((dgap_numboards == 1) || (num_online_cpus() <= 1)) {
1085 for (i = 0; i < dgap_numboards; i++) {
1087 brd = dgap_board[i];
1089 if (brd->state == BOARD_FAILED)
1091 if (!brd->intr_running)
1092 /* Call the real board poller directly */
1093 dgap_poll_tasklet((unsigned long) brd);
1097 * Go thru each board, kicking off a
1098 * tasklet for each if needed
1100 for (i = 0; i < dgap_numboards; i++) {
1101 brd = dgap_board[i];
1104 * Attempt to grab the board lock.
1106 * If we can't get it, no big deal, the next poll
1107 * will get it. Basically, I just really don't want
1108 * to spin in here, because I want to kick off my
1109 * tasklets as fast as I can, and then get out the
1112 if (!spin_trylock(&brd->bd_lock))
1116 * If board is in a failed state, don't bother
1117 * scheduling a tasklet
1119 if (brd->state == BOARD_FAILED) {
1120 spin_unlock(&brd->bd_lock);
1124 /* Schedule a poll helper task */
1125 if (!brd->intr_running)
1126 tasklet_schedule(&brd->helper_tasklet);
1129 * Can't do DGAP_UNLOCK here, as we don't have
1130 * lock_flags because we did a trylock above.
1132 spin_unlock(&brd->bd_lock);
1139 * Schedule ourself back at the nominal wakeup interval.
1141 spin_lock_irqsave(&dgap_poll_lock, lock_flags);
1142 dgap_poll_time += dgap_jiffies_from_ms(dgap_poll_tick);
1144 new_time = dgap_poll_time - jiffies;
1146 if ((ulong) new_time >= 2 * dgap_poll_tick) {
1148 jiffies + dgap_jiffies_from_ms(dgap_poll_tick);
1151 dgap_poll_timer.function = dgap_poll_handler;
1152 dgap_poll_timer.data = 0;
1153 dgap_poll_timer.expires = dgap_poll_time;
1154 spin_unlock_irqrestore(&dgap_poll_lock, lock_flags);
1156 if (!dgap_poll_stop)
1157 add_timer(&dgap_poll_timer);
1163 * Driver interrupt handler.
1165 static irqreturn_t dgap_intr(int irq, void *voidbrd)
1167 struct board_t *brd = (struct board_t *) voidbrd;
1173 * Check to make sure its for us.
1175 if (brd->magic != DGAP_BOARD_MAGIC)
1181 * Schedule tasklet to run at a better time.
1183 tasklet_schedule(&brd->helper_tasklet);
1188 * dgap_init_globals()
1190 * This is where we initialize the globals from the static insmod
1191 * configuration variables. These are declared near the head of
1194 static void dgap_init_globals(void)
1198 for (i = 0; i < MAXBOARDS; i++)
1199 dgap_board[i] = NULL;
1201 init_timer(&dgap_poll_timer);
1204 /************************************************************************
1208 ************************************************************************/
1213 * Put the driver to sleep for x ms's
1215 * Returns 0 if timed out, !0 (showing signal) if interrupted by a signal.
1217 static int dgap_ms_sleep(ulong ms)
1219 current->state = TASK_INTERRUPTIBLE;
1220 schedule_timeout((ms * HZ) / 1000);
1221 return signal_pending(current);
1224 /************************************************************************
1226 * TTY Initialization/Cleanup Functions
1228 ************************************************************************/
1231 * dgap_tty_register()
1233 * Init the tty subsystem for this board.
1235 static int dgap_tty_register(struct board_t *brd)
1239 brd->serial_driver = tty_alloc_driver(MAXPORTS, 0);
1240 if (IS_ERR(brd->serial_driver))
1241 return PTR_ERR(brd->serial_driver);
1243 snprintf(brd->serial_name, MAXTTYNAMELEN, "tty_dgap_%d_",
1245 brd->serial_driver->name = brd->serial_name;
1246 brd->serial_driver->name_base = 0;
1247 brd->serial_driver->major = 0;
1248 brd->serial_driver->minor_start = 0;
1249 brd->serial_driver->type = TTY_DRIVER_TYPE_SERIAL;
1250 brd->serial_driver->subtype = SERIAL_TYPE_NORMAL;
1251 brd->serial_driver->init_termios = dgap_default_termios;
1252 brd->serial_driver->driver_name = DRVSTR;
1253 brd->serial_driver->flags = (TTY_DRIVER_REAL_RAW |
1254 TTY_DRIVER_DYNAMIC_DEV |
1255 TTY_DRIVER_HARDWARE_BREAK);
1257 /* The kernel wants space to store pointers to tty_structs */
1258 brd->serial_driver->ttys =
1259 kzalloc(MAXPORTS * sizeof(struct tty_struct *), GFP_KERNEL);
1260 if (!brd->serial_driver->ttys) {
1262 goto free_serial_drv;
1266 * Entry points for driver. Called by the kernel from
1267 * tty_io.c and n_tty.c.
1269 tty_set_operations(brd->serial_driver, &dgap_tty_ops);
1272 * If we're doing transparent print, we have to do all of the above
1273 * again, separately so we don't get the LD confused about what major
1274 * we are when we get into the dgap_tty_open() routine.
1276 brd->print_driver = tty_alloc_driver(MAXPORTS, 0);
1277 if (IS_ERR(brd->print_driver)) {
1278 rc = PTR_ERR(brd->print_driver);
1279 goto free_serial_drv;
1282 snprintf(brd->print_name, MAXTTYNAMELEN, "pr_dgap_%d_",
1284 brd->print_driver->name = brd->print_name;
1285 brd->print_driver->name_base = 0;
1286 brd->print_driver->major = 0;
1287 brd->print_driver->minor_start = 0;
1288 brd->print_driver->type = TTY_DRIVER_TYPE_SERIAL;
1289 brd->print_driver->subtype = SERIAL_TYPE_NORMAL;
1290 brd->print_driver->init_termios = dgap_default_termios;
1291 brd->print_driver->driver_name = DRVSTR;
1292 brd->print_driver->flags = (TTY_DRIVER_REAL_RAW |
1293 TTY_DRIVER_DYNAMIC_DEV |
1294 TTY_DRIVER_HARDWARE_BREAK);
1296 /* The kernel wants space to store pointers to tty_structs */
1297 brd->print_driver->ttys =
1298 kzalloc(MAXPORTS * sizeof(struct tty_struct *), GFP_KERNEL);
1299 if (!brd->print_driver->ttys) {
1301 goto free_print_drv;
1305 * Entry points for driver. Called by the kernel from
1306 * tty_io.c and n_tty.c.
1308 tty_set_operations(brd->print_driver, &dgap_tty_ops);
1310 /* Register tty devices */
1311 rc = tty_register_driver(brd->serial_driver);
1313 goto free_print_drv;
1315 /* Register Transparent Print devices */
1316 rc = tty_register_driver(brd->print_driver);
1318 goto unregister_serial_drv;
1320 brd->dgap_major_serial_registered = TRUE;
1321 dgap_boards_by_major[brd->serial_driver->major] = brd;
1322 brd->dgap_serial_major = brd->serial_driver->major;
1324 brd->dgap_major_transparent_print_registered = TRUE;
1325 dgap_boards_by_major[brd->print_driver->major] = brd;
1326 brd->dgap_transparent_print_major = brd->print_driver->major;
1330 unregister_serial_drv:
1331 tty_unregister_driver(brd->serial_driver);
1333 put_tty_driver(brd->print_driver);
1335 put_tty_driver(brd->serial_driver);
1340 static void dgap_tty_unregister(struct board_t *brd)
1342 tty_unregister_driver(brd->print_driver);
1343 tty_unregister_driver(brd->serial_driver);
1344 put_tty_driver(brd->print_driver);
1345 put_tty_driver(brd->serial_driver);
1351 * Init the tty subsystem. Called once per board after board has been
1352 * downloaded and init'ed.
1354 static int dgap_tty_init(struct board_t *brd)
1361 struct channel_t *ch;
1362 struct bs_t __iomem *bs;
1363 struct cm_t __iomem *cm;
1367 * Initialize board structure elements.
1370 vaddr = brd->re_map_membase;
1371 true_count = readw((vaddr + NCHAN));
1373 brd->nasync = dgap_config_get_num_prts(brd);
1376 brd->nasync = brd->maxports;
1378 if (brd->nasync > brd->maxports)
1379 brd->nasync = brd->maxports;
1381 if (true_count != brd->nasync) {
1382 if ((brd->type == PPCM) && (true_count == 64)) {
1383 pr_warn("dgap: %s configured for %d ports, has %d ports.\n",
1384 brd->name, brd->nasync, true_count);
1385 pr_warn("dgap: Please make SURE the EBI cable running from the card\n");
1386 pr_warn("dgap: to each EM module is plugged into EBI IN!\n");
1387 } else if ((brd->type == PPCM) && (true_count == 0)) {
1388 pr_warn("dgap: %s configured for %d ports, has %d ports.\n",
1389 brd->name, brd->nasync, true_count);
1390 pr_warn("dgap: Please make SURE the EBI cable running from the card\n");
1391 pr_warn("dgap: to each EM module is plugged into EBI IN!\n");
1393 pr_warn("dgap: %s configured for %d ports, has %d ports.\n",
1394 brd->name, brd->nasync, true_count);
1396 brd->nasync = true_count;
1398 /* If no ports, don't bother going any further */
1400 brd->state = BOARD_FAILED;
1401 brd->dpastatus = BD_NOFEP;
1407 * Allocate channel memory that might not have been allocated
1408 * when the driver was first loaded.
1410 for (i = 0; i < brd->nasync; i++) {
1412 kzalloc(sizeof(struct channel_t), GFP_KERNEL);
1413 if (!brd->channels[i]) {
1419 ch = brd->channels[0];
1420 vaddr = brd->re_map_membase;
1422 bs = (struct bs_t __iomem *) ((ulong) vaddr + CHANBUF);
1423 cm = (struct cm_t __iomem *) ((ulong) vaddr + CMDBUF);
1427 /* Set up channel variables */
1428 for (i = 0; i < brd->nasync; i++, ch = brd->channels[i], bs++) {
1430 spin_lock_init(&ch->ch_lock);
1432 /* Store all our magic numbers */
1433 ch->magic = DGAP_CHANNEL_MAGIC;
1434 ch->ch_tun.magic = DGAP_UNIT_MAGIC;
1435 ch->ch_tun.un_type = DGAP_SERIAL;
1436 ch->ch_tun.un_ch = ch;
1437 ch->ch_tun.un_dev = i;
1439 ch->ch_pun.magic = DGAP_UNIT_MAGIC;
1440 ch->ch_pun.un_type = DGAP_PRINT;
1441 ch->ch_pun.un_ch = ch;
1442 ch->ch_pun.un_dev = i;
1444 ch->ch_vaddr = vaddr;
1449 ch->ch_digi = dgap_digi_init;
1452 * Set up digi dsr and dcd bits based on altpin flag.
1454 if (dgap_config_get_altpin(brd)) {
1457 ch->ch_digi.digi_flags |= DIGI_ALTPIN;
1460 ch->ch_dsr = DM_DSR;
1463 ch->ch_taddr = vaddr + (ioread16(&(ch->ch_bs->tx_seg)) << 4);
1464 ch->ch_raddr = vaddr + (ioread16(&(ch->ch_bs->rx_seg)) << 4);
1467 ch->ch_tsize = readw(&(ch->ch_bs->tx_max)) + 1;
1468 ch->ch_rsize = readw(&(ch->ch_bs->rx_max)) + 1;
1472 /* .25 second delay */
1473 ch->ch_close_delay = 250;
1476 * Set queue water marks, interrupt mask,
1477 * and general tty parameters.
1479 tlw = ch->ch_tsize >= 2000 ? ((ch->ch_tsize * 5) / 8) :
1483 dgap_cmdw(ch, STLOW, tlw, 0);
1485 dgap_cmdw(ch, SRLOW, ch->ch_rsize / 2, 0);
1487 dgap_cmdw(ch, SRHIGH, 7 * ch->ch_rsize / 8, 0);
1489 ch->ch_mistat = readb(&(ch->ch_bs->m_stat));
1491 init_waitqueue_head(&ch->ch_flags_wait);
1492 init_waitqueue_head(&ch->ch_tun.un_flags_wait);
1493 init_waitqueue_head(&ch->ch_pun.un_flags_wait);
1495 /* Turn on all modem interrupts for now */
1496 modem = (DM_CD | DM_DSR | DM_CTS | DM_RI);
1497 writeb(modem, &(ch->ch_bs->m_int));
1500 * Set edelay to 0 if interrupts are turned on,
1501 * otherwise set edelay to the usual 100.
1504 writew(0, &(ch->ch_bs->edelay));
1506 writew(100, &(ch->ch_bs->edelay));
1508 writeb(1, &(ch->ch_bs->idata));
1515 kfree(brd->channels[i]);
1516 brd->channels[i] = NULL;
1524 * Free the channles which are allocated in dgap_tty_init().
1526 static void dgap_tty_free(struct board_t *brd)
1530 for (i = 0; i < brd->nasync; i++)
1531 kfree(brd->channels[i]);
1534 * dgap_cleanup_tty()
1536 * Uninitialize the TTY portion of this driver. Free all memory and
1539 static void dgap_cleanup_tty(struct board_t *brd)
1544 if (brd->dgap_major_serial_registered) {
1545 dgap_boards_by_major[brd->serial_driver->major] = NULL;
1546 brd->dgap_serial_major = 0;
1547 for (i = 0; i < brd->nasync; i++) {
1548 tty_port_destroy(&brd->serial_ports[i]);
1549 dev = brd->channels[i]->ch_tun.un_sysfs;
1550 dgap_remove_tty_sysfs(dev);
1551 tty_unregister_device(brd->serial_driver, i);
1553 tty_unregister_driver(brd->serial_driver);
1554 put_tty_driver(brd->serial_driver);
1555 kfree(brd->serial_ports);
1556 brd->dgap_major_serial_registered = FALSE;
1559 if (brd->dgap_major_transparent_print_registered) {
1560 dgap_boards_by_major[brd->print_driver->major] = NULL;
1561 brd->dgap_transparent_print_major = 0;
1562 for (i = 0; i < brd->nasync; i++) {
1563 tty_port_destroy(&brd->printer_ports[i]);
1564 dev = brd->channels[i]->ch_pun.un_sysfs;
1565 dgap_remove_tty_sysfs(dev);
1566 tty_unregister_device(brd->print_driver, i);
1568 tty_unregister_driver(brd->print_driver);
1569 put_tty_driver(brd->print_driver);
1570 kfree(brd->printer_ports);
1571 brd->dgap_major_transparent_print_registered = FALSE;
1575 /*=======================================================================
1577 * dgap_input - Process received data.
1579 * ch - Pointer to channel structure.
1581 *=======================================================================*/
1583 static void dgap_input(struct channel_t *ch)
1586 struct bs_t __iomem *bs;
1587 struct tty_struct *tp;
1588 struct tty_ldisc *ld;
1602 if (!ch || ch->magic != DGAP_CHANNEL_MAGIC)
1605 tp = ch->ch_tun.un_tty;
1612 if (!bd || bd->magic != DGAP_BOARD_MAGIC)
1615 spin_lock_irqsave(&bd->bd_lock, lock_flags);
1616 spin_lock_irqsave(&ch->ch_lock, lock_flags2);
1619 * Figure the number of characters in the buffer.
1620 * Exit immediately if none.
1623 rmask = ch->ch_rsize - 1;
1625 head = readw(&(bs->rx_head));
1627 tail = readw(&(bs->rx_tail));
1630 data_len = (head - tail) & rmask;
1632 if (data_len == 0) {
1633 writeb(1, &(bs->idata));
1634 spin_unlock_irqrestore(&ch->ch_lock, lock_flags2);
1635 spin_unlock_irqrestore(&bd->bd_lock, lock_flags);
1640 * If the device is not open, or CREAD is off, flush
1641 * input data and return immediately.
1643 if ((bd->state != BOARD_READY) || !tp ||
1644 (tp->magic != TTY_MAGIC) ||
1645 !(ch->ch_tun.un_flags & UN_ISOPEN) ||
1646 !(tp->termios.c_cflag & CREAD) ||
1647 (ch->ch_tun.un_flags & UN_CLOSING)) {
1649 writew(head, &(bs->rx_tail));
1650 writeb(1, &(bs->idata));
1651 spin_unlock_irqrestore(&ch->ch_lock, lock_flags2);
1652 spin_unlock_irqrestore(&bd->bd_lock, lock_flags);
1657 * If we are throttled, simply don't read any data.
1659 if (ch->ch_flags & CH_RXBLOCK) {
1660 writeb(1, &(bs->idata));
1661 spin_unlock_irqrestore(&ch->ch_lock, lock_flags2);
1662 spin_unlock_irqrestore(&bd->bd_lock, lock_flags);
1669 tmpchar = readb(&(bs->orun));
1671 ch->ch_err_overrun++;
1672 writeb(0, &(bs->orun));
1675 /* Decide how much data we can send into the tty layer */
1676 flip_len = TTY_FLIPBUF_SIZE;
1678 /* Chop down the length, if needed */
1679 len = min(data_len, flip_len);
1680 len = min(len, (N_TTY_BUF_SIZE - 1));
1682 ld = tty_ldisc_ref(tp);
1684 #ifdef TTY_DONT_FLIP
1686 * If the DONT_FLIP flag is on, don't flush our buffer, and act
1687 * like the ld doesn't have any space to put the data right now.
1689 if (test_bit(TTY_DONT_FLIP, &tp->flags))
1694 * If we were unable to get a reference to the ld,
1695 * don't flush our buffer, and act like the ld doesn't
1696 * have any space to put the data right now.
1702 * If ld doesn't have a pointer to a receive_buf function,
1703 * flush the data, then act like the ld doesn't have any
1704 * space to put the data right now.
1706 if (!ld->ops->receive_buf) {
1707 writew(head, &(bs->rx_tail));
1713 writeb(1, &(bs->idata));
1714 spin_unlock_irqrestore(&ch->ch_lock, lock_flags2);
1715 spin_unlock_irqrestore(&bd->bd_lock, lock_flags);
1717 tty_ldisc_deref(ld);
1721 buf = ch->ch_bd->flipbuf;
1725 * n now contains the most amount of data we can copy,
1726 * bounded either by our buffer size or the amount
1727 * of data the card actually has pending...
1731 s = ((head >= tail) ? head : ch->ch_rsize) - tail;
1737 memcpy_fromio(buf, ch->ch_raddr + tail, s);
1743 /* Flip queue if needed */
1747 writew(tail, &(bs->rx_tail));
1748 writeb(1, &(bs->idata));
1749 ch->ch_rxcount += len;
1752 * If we are completely raw, we don't need to go through a lot
1753 * of the tty layers that exist.
1754 * In this case, we take the shortest and fastest route we
1755 * can to relay the data to the user.
1757 * On the other hand, if we are not raw, we need to go through
1758 * the tty layer, which has its API more well defined.
1760 if (I_PARMRK(tp) || I_BRKINT(tp) || I_INPCK(tp)) {
1761 dgap_parity_scan(ch, ch->ch_bd->flipbuf,
1762 ch->ch_bd->flipflagbuf, &len);
1764 len = tty_buffer_request_room(tp->port, len);
1765 tty_insert_flip_string_flags(tp->port, ch->ch_bd->flipbuf,
1766 ch->ch_bd->flipflagbuf, len);
1768 len = tty_buffer_request_room(tp->port, len);
1769 tty_insert_flip_string(tp->port, ch->ch_bd->flipbuf, len);
1772 spin_unlock_irqrestore(&ch->ch_lock, lock_flags2);
1773 spin_unlock_irqrestore(&bd->bd_lock, lock_flags);
1775 /* Tell the tty layer its okay to "eat" the data now */
1776 tty_flip_buffer_push(tp->port);
1779 tty_ldisc_deref(ld);
1783 /************************************************************************
1784 * Determines when CARRIER changes state and takes appropriate
1786 ************************************************************************/
1787 static void dgap_carrier(struct channel_t *ch)
1791 int virt_carrier = 0;
1792 int phys_carrier = 0;
1794 if (!ch || ch->magic != DGAP_CHANNEL_MAGIC)
1799 if (!bd || bd->magic != DGAP_BOARD_MAGIC)
1802 /* Make sure altpin is always set correctly */
1803 if (ch->ch_digi.digi_flags & DIGI_ALTPIN) {
1807 ch->ch_dsr = DM_DSR;
1811 if (ch->ch_mistat & D_CD(ch))
1814 if (ch->ch_digi.digi_flags & DIGI_FORCEDCD)
1817 if (ch->ch_c_cflag & CLOCAL)
1821 * Test for a VIRTUAL carrier transition to HIGH.
1823 if (((ch->ch_flags & CH_FCAR) == 0) && (virt_carrier == 1)) {
1826 * When carrier rises, wake any threads waiting
1827 * for carrier in the open routine.
1830 if (waitqueue_active(&(ch->ch_flags_wait)))
1831 wake_up_interruptible(&ch->ch_flags_wait);
1835 * Test for a PHYSICAL carrier transition to HIGH.
1837 if (((ch->ch_flags & CH_CD) == 0) && (phys_carrier == 1)) {
1840 * When carrier rises, wake any threads waiting
1841 * for carrier in the open routine.
1844 if (waitqueue_active(&(ch->ch_flags_wait)))
1845 wake_up_interruptible(&ch->ch_flags_wait);
1849 * Test for a PHYSICAL transition to low, so long as we aren't
1850 * currently ignoring physical transitions (which is what "virtual
1851 * carrier" indicates).
1853 * The transition of the virtual carrier to low really doesn't
1854 * matter... it really only means "ignore carrier state", not
1855 * "make pretend that carrier is there".
1857 if ((virt_carrier == 0) &&
1858 ((ch->ch_flags & CH_CD) != 0) &&
1859 (phys_carrier == 0)) {
1862 * When carrier drops:
1864 * Drop carrier on all open units.
1866 * Flush queues, waking up any task waiting in the
1869 * Send a hangup to the control terminal.
1871 * Enable all select calls.
1873 if (waitqueue_active(&(ch->ch_flags_wait)))
1874 wake_up_interruptible(&ch->ch_flags_wait);
1876 if (ch->ch_tun.un_open_count > 0)
1877 tty_hangup(ch->ch_tun.un_tty);
1879 if (ch->ch_pun.un_open_count > 0)
1880 tty_hangup(ch->ch_pun.un_tty);
1884 * Make sure that our cached values reflect the current reality.
1886 if (virt_carrier == 1)
1887 ch->ch_flags |= CH_FCAR;
1889 ch->ch_flags &= ~CH_FCAR;
1891 if (phys_carrier == 1)
1892 ch->ch_flags |= CH_CD;
1894 ch->ch_flags &= ~CH_CD;
1897 /************************************************************************
1899 * TTY Entry points and helper functions
1901 ************************************************************************/
1907 static int dgap_tty_open(struct tty_struct *tty, struct file *file)
1909 struct board_t *brd;
1910 struct channel_t *ch;
1912 struct bs_t __iomem *bs;
1920 major = MAJOR(tty_devnum(tty));
1921 minor = MINOR(tty_devnum(tty));
1926 /* Get board pointer from our array of majors we have allocated */
1927 brd = dgap_boards_by_major[major];
1932 * If board is not yet up to a state of READY, go to
1933 * sleep waiting for it to happen or they cancel the open.
1935 rc = wait_event_interruptible(brd->state_wait,
1936 (brd->state & BOARD_READY));
1941 spin_lock_irqsave(&brd->bd_lock, lock_flags);
1943 /* The wait above should guarantee this cannot happen */
1944 if (brd->state != BOARD_READY) {
1945 spin_unlock_irqrestore(&brd->bd_lock, lock_flags);
1949 /* If opened device is greater than our number of ports, bail. */
1950 if (MINOR(tty_devnum(tty)) > brd->nasync) {
1951 spin_unlock_irqrestore(&brd->bd_lock, lock_flags);
1955 ch = brd->channels[minor];
1957 spin_unlock_irqrestore(&brd->bd_lock, lock_flags);
1961 /* Grab channel lock */
1962 spin_lock_irqsave(&ch->ch_lock, lock_flags2);
1964 /* Figure out our type */
1965 if (major == brd->dgap_serial_major) {
1966 un = &brd->channels[minor]->ch_tun;
1967 un->un_type = DGAP_SERIAL;
1968 } else if (major == brd->dgap_transparent_print_major) {
1969 un = &brd->channels[minor]->ch_pun;
1970 un->un_type = DGAP_PRINT;
1972 spin_unlock_irqrestore(&ch->ch_lock, lock_flags2);
1973 spin_unlock_irqrestore(&brd->bd_lock, lock_flags);
1977 /* Store our unit into driver_data, so we always have it available. */
1978 tty->driver_data = un;
1981 * Error if channel info pointer is NULL.
1985 spin_unlock_irqrestore(&ch->ch_lock, lock_flags2);
1986 spin_unlock_irqrestore(&brd->bd_lock, lock_flags);
1993 if (!(un->un_flags & UN_ISOPEN)) {
1994 /* Store important variables. */
1997 /* Maybe do something here to the TTY struct as well? */
2001 * Initialize if neither terminal or printer is open.
2003 if (!((ch->ch_tun.un_flags | ch->ch_pun.un_flags) & UN_ISOPEN)) {
2009 * Flush input queue.
2011 head = readw(&(bs->rx_head));
2012 writew(head, &(bs->rx_tail));
2015 ch->pscan_state = 0;
2016 ch->pscan_savechar = 0;
2018 ch->ch_c_cflag = tty->termios.c_cflag;
2019 ch->ch_c_iflag = tty->termios.c_iflag;
2020 ch->ch_c_oflag = tty->termios.c_oflag;
2021 ch->ch_c_lflag = tty->termios.c_lflag;
2022 ch->ch_startc = tty->termios.c_cc[VSTART];
2023 ch->ch_stopc = tty->termios.c_cc[VSTOP];
2025 /* TODO: flush our TTY struct here? */
2030 * Run param in case we changed anything
2032 dgap_param(ch, brd, un->un_type);
2035 * follow protocol for opening port
2038 spin_unlock_irqrestore(&ch->ch_lock, lock_flags2);
2039 spin_unlock_irqrestore(&brd->bd_lock, lock_flags);
2041 rc = dgap_block_til_ready(tty, file, ch);
2046 /* No going back now, increment our unit and channel counters */
2047 spin_lock_irqsave(&ch->ch_lock, lock_flags);
2048 ch->ch_open_count++;
2049 un->un_open_count++;
2050 un->un_flags |= (UN_ISOPEN);
2051 spin_unlock_irqrestore(&ch->ch_lock, lock_flags);
2057 * dgap_block_til_ready()
2059 * Wait for DCD, if needed.
2061 static int dgap_block_til_ready(struct tty_struct *tty, struct file *file,
2062 struct channel_t *ch)
2068 int sleep_on_un_flags;
2070 if (!tty || tty->magic != TTY_MAGIC || !file || !ch ||
2071 ch->magic != DGAP_CHANNEL_MAGIC)
2074 un = tty->driver_data;
2075 if (!un || un->magic != DGAP_UNIT_MAGIC)
2078 spin_lock_irqsave(&ch->ch_lock, lock_flags);
2085 sleep_on_un_flags = 0;
2088 * If board has failed somehow during our sleep,
2091 if (ch->ch_bd->state == BOARD_FAILED) {
2096 /* If tty was hung up, break out of loop and set error. */
2097 if (tty_hung_up_p(file)) {
2103 * If either unit is in the middle of the fragile part of close,
2104 * we just cannot touch the channel safely.
2105 * Go back to sleep, knowing that when the channel can be
2106 * touched safely, the close routine will signal the
2107 * ch_wait_flags to wake us back up.
2109 if (!((ch->ch_tun.un_flags | ch->ch_pun.un_flags) &
2113 * Our conditions to leave cleanly and happily:
2114 * 1) NONBLOCKING on the tty is set.
2116 * 3) DCD (fake or real) is active.
2119 if (file->f_flags & O_NONBLOCK)
2122 if (tty->flags & (1 << TTY_IO_ERROR))
2125 if (ch->ch_flags & CH_CD)
2128 if (ch->ch_flags & CH_FCAR)
2131 sleep_on_un_flags = 1;
2135 * If there is a signal pending, the user probably
2136 * interrupted (ctrl-c) us.
2137 * Leave loop with error set.
2139 if (signal_pending(current)) {
2140 retval = -ERESTARTSYS;
2145 * Store the flags before we let go of channel lock
2147 if (sleep_on_un_flags)
2148 old_flags = ch->ch_tun.un_flags | ch->ch_pun.un_flags;
2150 old_flags = ch->ch_flags;
2153 * Let go of channel lock before calling schedule.
2154 * Our poller will get any FEP events and wake us up when DCD
2155 * eventually goes active.
2158 spin_unlock_irqrestore(&ch->ch_lock, lock_flags);
2161 * Wait for something in the flags to change
2162 * from the current value.
2164 if (sleep_on_un_flags) {
2165 retval = wait_event_interruptible(un->un_flags_wait,
2166 (old_flags != (ch->ch_tun.un_flags |
2167 ch->ch_pun.un_flags)));
2169 retval = wait_event_interruptible(ch->ch_flags_wait,
2170 (old_flags != ch->ch_flags));
2174 * We got woken up for some reason.
2175 * Before looping around, grab our channel lock.
2177 spin_lock_irqsave(&ch->ch_lock, lock_flags);
2182 spin_unlock_irqrestore(&ch->ch_lock, lock_flags);
2193 * Hangup the port. Like a close, but don't wait for output to drain.
2195 static void dgap_tty_hangup(struct tty_struct *tty)
2198 struct channel_t *ch;
2201 if (!tty || tty->magic != TTY_MAGIC)
2204 un = tty->driver_data;
2205 if (!un || un->magic != DGAP_UNIT_MAGIC)
2209 if (!ch || ch->magic != DGAP_CHANNEL_MAGIC)
2213 if (!bd || bd->magic != DGAP_BOARD_MAGIC)
2216 /* flush the transmit queues */
2217 dgap_tty_flush_buffer(tty);
2224 static void dgap_tty_close(struct tty_struct *tty, struct file *file)
2226 struct ktermios *ts;
2228 struct channel_t *ch;
2232 if (!tty || tty->magic != TTY_MAGIC)
2235 un = tty->driver_data;
2236 if (!un || un->magic != DGAP_UNIT_MAGIC)
2240 if (!ch || ch->magic != DGAP_CHANNEL_MAGIC)
2244 if (!bd || bd->magic != DGAP_BOARD_MAGIC)
2249 spin_lock_irqsave(&ch->ch_lock, lock_flags);
2252 * Determine if this is the last close or not - and if we agree about
2253 * which type of close it is with the Line Discipline
2255 if ((tty->count == 1) && (un->un_open_count != 1)) {
2257 * Uh, oh. tty->count is 1, which means that the tty
2258 * structure will be freed. un_open_count should always
2259 * be one in these conditions. If it's greater than
2260 * one, we've got real problems, since it means the
2261 * serial port won't be shutdown.
2263 un->un_open_count = 1;
2266 if (--un->un_open_count < 0)
2267 un->un_open_count = 0;
2269 ch->ch_open_count--;
2271 if (ch->ch_open_count && un->un_open_count) {
2272 spin_unlock_irqrestore(&ch->ch_lock, lock_flags);
2276 /* OK, its the last close on the unit */
2278 un->un_flags |= UN_CLOSING;
2283 * Only officially close channel if count is 0 and
2284 * DIGI_PRINTER bit is not set.
2286 if ((ch->ch_open_count == 0) &&
2287 !(ch->ch_digi.digi_flags & DIGI_PRINTER)) {
2289 ch->ch_flags &= ~(CH_RXBLOCK);
2291 spin_unlock_irqrestore(&ch->ch_lock, lock_flags);
2293 /* wait for output to drain */
2294 /* This will also return if we take an interrupt */
2296 dgap_wait_for_drain(tty);
2298 dgap_tty_flush_buffer(tty);
2299 tty_ldisc_flush(tty);
2301 spin_lock_irqsave(&ch->ch_lock, lock_flags);
2306 * If we have HUPCL set, lower DTR and RTS
2308 if (ch->ch_c_cflag & HUPCL) {
2309 ch->ch_mostat &= ~(D_RTS(ch)|D_DTR(ch));
2310 dgap_cmdb(ch, SMODEM, 0, D_DTR(ch)|D_RTS(ch), 0);
2313 * Go to sleep to ensure RTS/DTR
2314 * have been dropped for modems to see it.
2316 if (ch->ch_close_delay) {
2317 spin_unlock_irqrestore(&ch->ch_lock,
2319 dgap_ms_sleep(ch->ch_close_delay);
2320 spin_lock_irqsave(&ch->ch_lock, lock_flags);
2324 ch->pscan_state = 0;
2325 ch->pscan_savechar = 0;
2326 ch->ch_baud_info = 0;
2331 * turn off print device when closing print device.
2333 if ((un->un_type == DGAP_PRINT) && (ch->ch_flags & CH_PRON)) {
2334 dgap_wmove(ch, ch->ch_digi.digi_offstr,
2335 (int) ch->ch_digi.digi_offlen);
2336 ch->ch_flags &= ~CH_PRON;
2340 un->un_flags &= ~(UN_ISOPEN | UN_CLOSING);
2341 tty->driver_data = NULL;
2343 wake_up_interruptible(&ch->ch_flags_wait);
2344 wake_up_interruptible(&un->un_flags_wait);
2346 spin_unlock_irqrestore(&ch->ch_lock, lock_flags);
2350 * dgap_tty_chars_in_buffer()
2352 * Return number of characters that have not been transmitted yet.
2354 * This routine is used by the line discipline to determine if there
2355 * is data waiting to be transmitted/drained/flushed or not.
2357 static int dgap_tty_chars_in_buffer(struct tty_struct *tty)
2360 struct channel_t *ch;
2362 struct bs_t __iomem *bs;
2365 u16 thead, ttail, tmask, chead, ctail;
2366 ulong lock_flags = 0;
2367 ulong lock_flags2 = 0;
2372 un = tty->driver_data;
2373 if (!un || un->magic != DGAP_UNIT_MAGIC)
2377 if (!ch || ch->magic != DGAP_CHANNEL_MAGIC)
2381 if (!bd || bd->magic != DGAP_BOARD_MAGIC)
2388 spin_lock_irqsave(&bd->bd_lock, lock_flags);
2389 spin_lock_irqsave(&ch->ch_lock, lock_flags2);
2391 tmask = (ch->ch_tsize - 1);
2393 /* Get Transmit queue pointers */
2394 thead = readw(&(bs->tx_head)) & tmask;
2395 ttail = readw(&(bs->tx_tail)) & tmask;
2397 /* Get tbusy flag */
2398 tbusy = readb(&(bs->tbusy));
2400 /* Get Command queue pointers */
2401 chead = readw(&(ch->ch_cm->cm_head));
2402 ctail = readw(&(ch->ch_cm->cm_tail));
2404 spin_unlock_irqrestore(&ch->ch_lock, lock_flags2);
2405 spin_unlock_irqrestore(&bd->bd_lock, lock_flags);
2408 * The only way we know for sure if there is no pending
2409 * data left to be transferred, is if:
2410 * 1) Transmit head and tail are equal (empty).
2411 * 2) Command queue head and tail are equal (empty).
2412 * 3) The "TBUSY" flag is 0. (Transmitter not busy).
2415 if ((ttail == thead) && (tbusy == 0) && (chead == ctail)) {
2419 chars = thead - ttail;
2421 chars = thead - ttail + ch->ch_tsize;
2423 * Fudge factor here.
2424 * If chars is zero, we know that the command queue had
2425 * something in it or tbusy was set. Because we cannot
2426 * be sure if there is still some data to be transmitted,
2427 * lets lie, and tell ld we have 1 byte left.
2431 * If TBUSY is still set, and our tx buffers are empty,
2432 * force the firmware to send me another wakeup after
2433 * TBUSY has been cleared.
2436 spin_lock_irqsave(&ch->ch_lock, lock_flags);
2437 un->un_flags |= UN_EMPTY;
2438 writeb(1, &(bs->iempty));
2439 spin_unlock_irqrestore(&ch->ch_lock,
2449 static int dgap_wait_for_drain(struct tty_struct *tty)
2451 struct channel_t *ch;
2453 struct bs_t __iomem *bs;
2456 ulong lock_flags = 0;
2458 if (!tty || tty->magic != TTY_MAGIC)
2461 un = tty->driver_data;
2462 if (!un || un->magic != DGAP_UNIT_MAGIC)
2466 if (!ch || ch->magic != DGAP_CHANNEL_MAGIC)
2473 /* Loop until data is drained */
2474 while (count != 0) {
2476 count = dgap_tty_chars_in_buffer(tty);
2481 /* Set flag waiting for drain */
2482 spin_lock_irqsave(&ch->ch_lock, lock_flags);
2483 un->un_flags |= UN_EMPTY;
2484 writeb(1, &(bs->iempty));
2485 spin_unlock_irqrestore(&ch->ch_lock, lock_flags);
2487 /* Go to sleep till we get woken up */
2488 ret = wait_event_interruptible(un->un_flags_wait,
2489 ((un->un_flags & UN_EMPTY) == 0));
2490 /* If ret is non-zero, user ctrl-c'ed us */
2495 spin_lock_irqsave(&ch->ch_lock, lock_flags);
2496 un->un_flags &= ~(UN_EMPTY);
2497 spin_unlock_irqrestore(&ch->ch_lock, lock_flags);
2505 * Reduces bytes_available to the max number of characters
2506 * that can be sent currently given the maxcps value, and
2507 * returns the new bytes_available. This only affects printer
2510 static int dgap_maxcps_room(struct channel_t *ch, struct un_t *un,
2511 int bytes_available)
2514 * If its not the Transparent print device, return
2515 * the full data amount.
2517 if (un->un_type != DGAP_PRINT)
2518 return bytes_available;
2520 if (ch->ch_digi.digi_maxcps > 0 && ch->ch_digi.digi_bufsize > 0) {
2522 unsigned long current_time = jiffies;
2523 unsigned long buffer_time = current_time +
2524 (HZ * ch->ch_digi.digi_bufsize) /
2525 ch->ch_digi.digi_maxcps;
2527 if (ch->ch_cpstime < current_time) {
2528 /* buffer is empty */
2529 ch->ch_cpstime = current_time; /* reset ch_cpstime */
2530 cps_limit = ch->ch_digi.digi_bufsize;
2531 } else if (ch->ch_cpstime < buffer_time) {
2532 /* still room in the buffer */
2533 cps_limit = ((buffer_time - ch->ch_cpstime) *
2534 ch->ch_digi.digi_maxcps) / HZ;
2536 /* no room in the buffer */
2540 bytes_available = min(cps_limit, bytes_available);
2543 return bytes_available;
2546 static inline void dgap_set_firmware_event(struct un_t *un, unsigned int event)
2548 struct channel_t *ch;
2549 struct bs_t __iomem *bs;
2551 if (!un || un->magic != DGAP_UNIT_MAGIC)
2554 if (!ch || ch->magic != DGAP_CHANNEL_MAGIC)
2560 if ((event & UN_LOW) != 0) {
2561 if ((un->un_flags & UN_LOW) == 0) {
2562 un->un_flags |= UN_LOW;
2563 writeb(1, &(bs->ilow));
2566 if ((event & UN_LOW) != 0) {
2567 if ((un->un_flags & UN_EMPTY) == 0) {
2568 un->un_flags |= UN_EMPTY;
2569 writeb(1, &(bs->iempty));
2575 * dgap_tty_write_room()
2577 * Return space available in Tx buffer
2579 static int dgap_tty_write_room(struct tty_struct *tty)
2581 struct channel_t *ch;
2583 struct bs_t __iomem *bs;
2584 u16 head, tail, tmask;
2586 ulong lock_flags = 0;
2591 un = tty->driver_data;
2592 if (!un || un->magic != DGAP_UNIT_MAGIC)
2596 if (!ch || ch->magic != DGAP_CHANNEL_MAGIC)
2603 spin_lock_irqsave(&ch->ch_lock, lock_flags);
2605 tmask = ch->ch_tsize - 1;
2606 head = readw(&(bs->tx_head)) & tmask;
2607 tail = readw(&(bs->tx_tail)) & tmask;
2609 ret = tail - head - 1;
2611 ret += ch->ch_tsize;
2613 /* Limit printer to maxcps */
2614 ret = dgap_maxcps_room(ch, un, ret);
2617 * If we are printer device, leave space for
2618 * possibly both the on and off strings.
2620 if (un->un_type == DGAP_PRINT) {
2621 if (!(ch->ch_flags & CH_PRON))
2622 ret -= ch->ch_digi.digi_onlen;
2623 ret -= ch->ch_digi.digi_offlen;
2625 if (ch->ch_flags & CH_PRON)
2626 ret -= ch->ch_digi.digi_offlen;
2633 * Schedule FEP to wake us up if needed.
2635 * TODO: This might be overkill...
2636 * Do we really need to schedule callbacks from the FEP
2637 * in every case? Can we get smarter based on ret?
2639 dgap_set_firmware_event(un, UN_LOW | UN_EMPTY);
2640 spin_unlock_irqrestore(&ch->ch_lock, lock_flags);
2646 * dgap_tty_put_char()
2648 * Put a character into ch->ch_buf
2650 * - used by the line discipline for OPOST processing
2652 static int dgap_tty_put_char(struct tty_struct *tty, unsigned char c)
2655 * Simply call tty_write.
2657 dgap_tty_write(tty, &c, 1);
2664 * Take data from the user or kernel and send it out to the FEP.
2665 * In here exists all the Transparent Print magic as well.
2667 static int dgap_tty_write(struct tty_struct *tty, const unsigned char *buf,
2670 struct channel_t *ch;
2672 struct bs_t __iomem *bs;
2673 char __iomem *vaddr;
2674 u16 head, tail, tmask, remain;
2682 un = tty->driver_data;
2683 if (!un || un->magic != DGAP_UNIT_MAGIC)
2687 if (!ch || ch->magic != DGAP_CHANNEL_MAGIC)
2698 * Store original amount of characters passed in.
2699 * This helps to figure out if we should ask the FEP
2700 * to send us an event when it has more space available.
2704 spin_lock_irqsave(&ch->ch_lock, lock_flags);
2706 /* Get our space available for the channel from the board */
2707 tmask = ch->ch_tsize - 1;
2708 head = readw(&(bs->tx_head)) & tmask;
2709 tail = readw(&(bs->tx_tail)) & tmask;
2711 bufcount = tail - head - 1;
2713 bufcount += ch->ch_tsize;
2716 * Limit printer output to maxcps overall, with bursts allowed
2717 * up to bufsize characters.
2719 bufcount = dgap_maxcps_room(ch, un, bufcount);
2722 * Take minimum of what the user wants to send, and the
2723 * space available in the FEP buffer.
2725 count = min(count, bufcount);
2728 * Bail if no space left.
2731 dgap_set_firmware_event(un, UN_LOW | UN_EMPTY);
2732 spin_unlock_irqrestore(&ch->ch_lock, lock_flags);
2737 * Output the printer ON string, if we are in terminal mode, but
2738 * need to be in printer mode.
2740 if ((un->un_type == DGAP_PRINT) && !(ch->ch_flags & CH_PRON)) {
2741 dgap_wmove(ch, ch->ch_digi.digi_onstr,
2742 (int) ch->ch_digi.digi_onlen);
2743 head = readw(&(bs->tx_head)) & tmask;
2744 ch->ch_flags |= CH_PRON;
2748 * On the other hand, output the printer OFF string, if we are
2749 * currently in printer mode, but need to output to the terminal.
2751 if ((un->un_type != DGAP_PRINT) && (ch->ch_flags & CH_PRON)) {
2752 dgap_wmove(ch, ch->ch_digi.digi_offstr,
2753 (int) ch->ch_digi.digi_offlen);
2754 head = readw(&(bs->tx_head)) & tmask;
2755 ch->ch_flags &= ~CH_PRON;
2761 * If the write wraps over the top of the circular buffer,
2762 * move the portion up to the wrap point, and reset the
2763 * pointers to the bottom.
2765 remain = ch->ch_tstart + ch->ch_tsize - head;
2769 vaddr = ch->ch_taddr + head;
2771 memcpy_toio(vaddr, (u8 *) buf, remain);
2773 head = ch->ch_tstart;
2780 * Move rest of data.
2782 vaddr = ch->ch_taddr + head;
2785 memcpy_toio(vaddr, (u8 *) buf, remain);
2791 ch->ch_txcount += count;
2793 writew(head, &(bs->tx_head));
2796 dgap_set_firmware_event(un, UN_LOW | UN_EMPTY);
2799 * If this is the print device, and the
2800 * printer is still on, we need to turn it
2801 * off before going idle. If the buffer is
2802 * non-empty, wait until it goes empty.
2803 * Otherwise turn it off right now.
2805 if ((un->un_type == DGAP_PRINT) && (ch->ch_flags & CH_PRON)) {
2806 tail = readw(&(bs->tx_tail)) & tmask;
2809 un->un_flags |= UN_EMPTY;
2810 writeb(1, &(bs->iempty));
2812 dgap_wmove(ch, ch->ch_digi.digi_offstr,
2813 (int) ch->ch_digi.digi_offlen);
2814 head = readw(&(bs->tx_head)) & tmask;
2815 ch->ch_flags &= ~CH_PRON;
2819 /* Update printer buffer empty time. */
2820 if ((un->un_type == DGAP_PRINT) && (ch->ch_digi.digi_maxcps > 0)
2821 && (ch->ch_digi.digi_bufsize > 0)) {
2822 ch->ch_cpstime += (HZ * count) / ch->ch_digi.digi_maxcps;
2825 spin_unlock_irqrestore(&ch->ch_lock, lock_flags);
2831 * Return modem signals to ld.
2833 static int dgap_tty_tiocmget(struct tty_struct *tty)
2835 struct channel_t *ch;
2841 if (!tty || tty->magic != TTY_MAGIC)
2844 un = tty->driver_data;
2845 if (!un || un->magic != DGAP_UNIT_MAGIC)
2849 if (!ch || ch->magic != DGAP_CHANNEL_MAGIC)
2852 spin_lock_irqsave(&ch->ch_lock, lock_flags);
2854 mstat = readb(&(ch->ch_bs->m_stat));
2855 /* Append any outbound signals that might be pending... */
2856 mstat |= ch->ch_mostat;
2858 spin_unlock_irqrestore(&ch->ch_lock, lock_flags);
2862 if (mstat & D_DTR(ch))
2863 result |= TIOCM_DTR;
2864 if (mstat & D_RTS(ch))
2865 result |= TIOCM_RTS;
2866 if (mstat & D_CTS(ch))
2867 result |= TIOCM_CTS;
2868 if (mstat & D_DSR(ch))
2869 result |= TIOCM_DSR;
2870 if (mstat & D_RI(ch))
2872 if (mstat & D_CD(ch))
2879 * dgap_tty_tiocmset()
2881 * Set modem signals, called by ld.
2883 static int dgap_tty_tiocmset(struct tty_struct *tty,
2884 unsigned int set, unsigned int clear)
2887 struct channel_t *ch;
2892 if (!tty || tty->magic != TTY_MAGIC)
2895 un = tty->driver_data;
2896 if (!un || un->magic != DGAP_UNIT_MAGIC)
2900 if (!ch || ch->magic != DGAP_CHANNEL_MAGIC)
2904 if (!bd || bd->magic != DGAP_BOARD_MAGIC)
2907 spin_lock_irqsave(&bd->bd_lock, lock_flags);
2908 spin_lock_irqsave(&ch->ch_lock, lock_flags2);
2910 if (set & TIOCM_RTS) {
2911 ch->ch_mforce |= D_RTS(ch);
2912 ch->ch_mval |= D_RTS(ch);
2915 if (set & TIOCM_DTR) {
2916 ch->ch_mforce |= D_DTR(ch);
2917 ch->ch_mval |= D_DTR(ch);
2920 if (clear & TIOCM_RTS) {
2921 ch->ch_mforce |= D_RTS(ch);
2922 ch->ch_mval &= ~(D_RTS(ch));
2925 if (clear & TIOCM_DTR) {
2926 ch->ch_mforce |= D_DTR(ch);
2927 ch->ch_mval &= ~(D_DTR(ch));
2930 dgap_param(ch, bd, un->un_type);
2932 spin_unlock_irqrestore(&ch->ch_lock, lock_flags2);
2933 spin_unlock_irqrestore(&bd->bd_lock, lock_flags);
2939 * dgap_tty_send_break()
2941 * Send a Break, called by ld.
2943 static int dgap_tty_send_break(struct tty_struct *tty, int msec)
2946 struct channel_t *ch;
2951 if (!tty || tty->magic != TTY_MAGIC)
2954 un = tty->driver_data;
2955 if (!un || un->magic != DGAP_UNIT_MAGIC)
2959 if (!ch || ch->magic != DGAP_CHANNEL_MAGIC)
2963 if (!bd || bd->magic != DGAP_BOARD_MAGIC)
2978 spin_lock_irqsave(&bd->bd_lock, lock_flags);
2979 spin_lock_irqsave(&ch->ch_lock, lock_flags2);
2981 dgap_cmdw(ch, SBREAK, (u16) SBREAK_TIME, 0);
2983 dgap_cmdw(ch, SBREAK, (u16) msec, 0);
2985 spin_unlock_irqrestore(&ch->ch_lock, lock_flags2);
2986 spin_unlock_irqrestore(&bd->bd_lock, lock_flags);
2992 * dgap_tty_wait_until_sent()
2994 * wait until data has been transmitted, called by ld.
2996 static void dgap_tty_wait_until_sent(struct tty_struct *tty, int timeout)
2998 dgap_wait_for_drain(tty);
3004 * send a high priority character, called by ld.
3006 static void dgap_tty_send_xchar(struct tty_struct *tty, char c)
3009 struct channel_t *ch;
3014 if (!tty || tty->magic != TTY_MAGIC)
3017 un = tty->driver_data;
3018 if (!un || un->magic != DGAP_UNIT_MAGIC)
3022 if (!ch || ch->magic != DGAP_CHANNEL_MAGIC)
3026 if (!bd || bd->magic != DGAP_BOARD_MAGIC)
3029 spin_lock_irqsave(&bd->bd_lock, lock_flags);
3030 spin_lock_irqsave(&ch->ch_lock, lock_flags2);
3033 * This is technically what we should do.
3034 * However, the NIST tests specifically want
3035 * to see each XON or XOFF character that it
3036 * sends, so lets just send each character
3040 if (c == STOP_CHAR(tty))
3041 dgap_cmdw(ch, RPAUSE, 0, 0);
3042 else if (c == START_CHAR(tty))
3043 dgap_cmdw(ch, RRESUME, 0, 0);
3045 dgap_wmove(ch, &c, 1);
3047 dgap_wmove(ch, &c, 1);
3050 spin_unlock_irqrestore(&ch->ch_lock, lock_flags2);
3051 spin_unlock_irqrestore(&bd->bd_lock, lock_flags);
3055 * Return modem signals to ld.
3057 static int dgap_get_modem_info(struct channel_t *ch, unsigned int __user *value)
3064 spin_lock_irqsave(&ch->ch_lock, lock_flags);
3066 mstat = readb(&(ch->ch_bs->m_stat));
3067 /* Append any outbound signals that might be pending... */
3068 mstat |= ch->ch_mostat;
3070 spin_unlock_irqrestore(&ch->ch_lock, lock_flags);
3074 if (mstat & D_DTR(ch))
3075 result |= TIOCM_DTR;
3076 if (mstat & D_RTS(ch))
3077 result |= TIOCM_RTS;
3078 if (mstat & D_CTS(ch))
3079 result |= TIOCM_CTS;
3080 if (mstat & D_DSR(ch))
3081 result |= TIOCM_DSR;
3082 if (mstat & D_RI(ch))
3084 if (mstat & D_CD(ch))
3087 rc = put_user(result, value);
3093 * dgap_set_modem_info()
3095 * Set modem signals, called by ld.
3097 static int dgap_set_modem_info(struct tty_struct *tty, unsigned int command,
3098 unsigned int __user *value)
3101 struct channel_t *ch;
3108 if (!tty || tty->magic != TTY_MAGIC)
3111 un = tty->driver_data;
3112 if (!un || un->magic != DGAP_UNIT_MAGIC)
3116 if (!ch || ch->magic != DGAP_CHANNEL_MAGIC)
3120 if (!bd || bd->magic != DGAP_BOARD_MAGIC)
3123 ret = get_user(arg, value);
3129 if (arg & TIOCM_RTS) {
3130 ch->ch_mforce |= D_RTS(ch);
3131 ch->ch_mval |= D_RTS(ch);
3134 if (arg & TIOCM_DTR) {
3135 ch->ch_mforce |= D_DTR(ch);
3136 ch->ch_mval |= D_DTR(ch);
3142 if (arg & TIOCM_RTS) {
3143 ch->ch_mforce |= D_RTS(ch);
3144 ch->ch_mval &= ~(D_RTS(ch));
3147 if (arg & TIOCM_DTR) {
3148 ch->ch_mforce |= D_DTR(ch);
3149 ch->ch_mval &= ~(D_DTR(ch));
3155 ch->ch_mforce = D_DTR(ch)|D_RTS(ch);
3157 if (arg & TIOCM_RTS)
3158 ch->ch_mval |= D_RTS(ch);
3160 ch->ch_mval &= ~(D_RTS(ch));
3162 if (arg & TIOCM_DTR)
3163 ch->ch_mval |= (D_DTR(ch));
3165 ch->ch_mval &= ~(D_DTR(ch));
3173 spin_lock_irqsave(&bd->bd_lock, lock_flags);
3174 spin_lock_irqsave(&ch->ch_lock, lock_flags2);
3176 dgap_param(ch, bd, un->un_type);
3178 spin_unlock_irqrestore(&ch->ch_lock, lock_flags2);
3179 spin_unlock_irqrestore(&bd->bd_lock, lock_flags);
3185 * dgap_tty_digigeta()
3187 * Ioctl to get the information for ditty.
3192 static int dgap_tty_digigeta(struct channel_t *ch, struct un_t *un,
3193 struct digi_t __user *retinfo)
3201 memset(&tmp, 0, sizeof(tmp));
3203 spin_lock_irqsave(&ch->ch_lock, lock_flags);
3204 memcpy(&tmp, &ch->ch_digi, sizeof(tmp));
3205 spin_unlock_irqrestore(&ch->ch_lock, lock_flags);
3207 if (copy_to_user(retinfo, &tmp, sizeof(*retinfo)))
3214 * dgap_tty_digiseta()
3216 * Ioctl to set the information for ditty.
3221 static int dgap_tty_digiseta(struct channel_t *ch, struct board_t *bd,
3222 struct un_t *un, struct digi_t __user *new_info)
3224 struct digi_t new_digi;
3225 ulong lock_flags = 0;
3226 unsigned long lock_flags2;
3228 if (copy_from_user(&new_digi, new_info, sizeof(struct digi_t)))
3231 spin_lock_irqsave(&bd->bd_lock, lock_flags);
3232 spin_lock_irqsave(&ch->ch_lock, lock_flags2);
3234 memcpy(&ch->ch_digi, &new_digi, sizeof(struct digi_t));
3236 if (ch->ch_digi.digi_maxcps < 1)
3237 ch->ch_digi.digi_maxcps = 1;
3239 if (ch->ch_digi.digi_maxcps > 10000)
3240 ch->ch_digi.digi_maxcps = 10000;
3242 if (ch->ch_digi.digi_bufsize < 10)
3243 ch->ch_digi.digi_bufsize = 10;
3245 if (ch->ch_digi.digi_maxchar < 1)
3246 ch->ch_digi.digi_maxchar = 1;
3248 if (ch->ch_digi.digi_maxchar > ch->ch_digi.digi_bufsize)
3249 ch->ch_digi.digi_maxchar = ch->ch_digi.digi_bufsize;
3251 if (ch->ch_digi.digi_onlen > DIGI_PLEN)
3252 ch->ch_digi.digi_onlen = DIGI_PLEN;
3254 if (ch->ch_digi.digi_offlen > DIGI_PLEN)
3255 ch->ch_digi.digi_offlen = DIGI_PLEN;
3257 dgap_param(ch, bd, un->un_type);
3259 spin_unlock_irqrestore(&ch->ch_lock, lock_flags2);
3260 spin_unlock_irqrestore(&bd->bd_lock, lock_flags);
3266 * dgap_tty_digigetedelay()
3268 * Ioctl to get the current edelay setting.
3273 static int dgap_tty_digigetedelay(struct tty_struct *tty, int __user *retinfo)
3275 struct channel_t *ch;
3283 if (!tty || tty->magic != TTY_MAGIC)
3286 un = tty->driver_data;
3287 if (!un || un->magic != DGAP_UNIT_MAGIC)
3291 if (!ch || ch->magic != DGAP_CHANNEL_MAGIC)
3294 memset(&tmp, 0, sizeof(tmp));
3296 spin_lock_irqsave(&ch->ch_lock, lock_flags);
3297 tmp = readw(&(ch->ch_bs->edelay));
3298 spin_unlock_irqrestore(&ch->ch_lock, lock_flags);
3300 if (copy_to_user(retinfo, &tmp, sizeof(*retinfo)))
3307 * dgap_tty_digisetedelay()
3309 * Ioctl to set the EDELAY setting
3312 static int dgap_tty_digisetedelay(struct tty_struct *tty, int __user *new_info)
3315 struct channel_t *ch;
3321 if (!tty || tty->magic != TTY_MAGIC)
3324 un = tty->driver_data;
3325 if (!un || un->magic != DGAP_UNIT_MAGIC)
3329 if (!ch || ch->magic != DGAP_CHANNEL_MAGIC)
3333 if (!bd || bd->magic != DGAP_BOARD_MAGIC)
3336 if (copy_from_user(&new_digi, new_info, sizeof(int)))
3339 spin_lock_irqsave(&bd->bd_lock, lock_flags);
3340 spin_lock_irqsave(&ch->ch_lock, lock_flags2);
3342 writew((u16) new_digi, &(ch->ch_bs->edelay));
3344 dgap_param(ch, bd, un->un_type);
3346 spin_unlock_irqrestore(&ch->ch_lock, lock_flags2);
3347 spin_unlock_irqrestore(&bd->bd_lock, lock_flags);
3353 * dgap_tty_digigetcustombaud()
3355 * Ioctl to get the current custom baud rate setting.
3357 static int dgap_tty_digigetcustombaud(struct tty_struct *tty,
3358 int __user *retinfo)
3360 struct channel_t *ch;
3368 if (!tty || tty->magic != TTY_MAGIC)
3371 un = tty->driver_data;
3372 if (!un || un->magic != DGAP_UNIT_MAGIC)
3376 if (!ch || ch->magic != DGAP_CHANNEL_MAGIC)
3379 memset(&tmp, 0, sizeof(tmp));
3381 spin_lock_irqsave(&ch->ch_lock, lock_flags);
3382 tmp = dgap_get_custom_baud(ch);
3383 spin_unlock_irqrestore(&ch->ch_lock, lock_flags);
3385 if (copy_to_user(retinfo, &tmp, sizeof(*retinfo)))
3392 * dgap_tty_digisetcustombaud()
3394 * Ioctl to set the custom baud rate setting
3396 static int dgap_tty_digisetcustombaud(struct tty_struct *tty,
3397 int __user *new_info)
3400 struct channel_t *ch;
3406 if (!tty || tty->magic != TTY_MAGIC)
3409 un = tty->driver_data;
3410 if (!un || un->magic != DGAP_UNIT_MAGIC)
3414 if (!ch || ch->magic != DGAP_CHANNEL_MAGIC)
3418 if (!bd || bd->magic != DGAP_BOARD_MAGIC)
3422 if (copy_from_user(&new_rate, new_info, sizeof(unsigned int)))
3425 if (bd->bd_flags & BD_FEP5PLUS) {
3427 spin_lock_irqsave(&bd->bd_lock, lock_flags);
3428 spin_lock_irqsave(&ch->ch_lock, lock_flags2);
3430 ch->ch_custom_speed = new_rate;
3432 dgap_param(ch, bd, un->un_type);
3434 spin_unlock_irqrestore(&ch->ch_lock, lock_flags2);
3435 spin_unlock_irqrestore(&bd->bd_lock, lock_flags);
3442 * dgap_set_termios()
3444 static void dgap_tty_set_termios(struct tty_struct *tty,
3445 struct ktermios *old_termios)
3448 struct channel_t *ch;
3450 unsigned long lock_flags;
3451 unsigned long lock_flags2;
3453 if (!tty || tty->magic != TTY_MAGIC)
3456 un = tty->driver_data;
3457 if (!un || un->magic != DGAP_UNIT_MAGIC)
3461 if (!ch || ch->magic != DGAP_CHANNEL_MAGIC)
3465 if (!bd || bd->magic != DGAP_BOARD_MAGIC)
3468 spin_lock_irqsave(&bd->bd_lock, lock_flags);
3469 spin_lock_irqsave(&ch->ch_lock, lock_flags2);
3471 ch->ch_c_cflag = tty->termios.c_cflag;
3472 ch->ch_c_iflag = tty->termios.c_iflag;
3473 ch->ch_c_oflag = tty->termios.c_oflag;
3474 ch->ch_c_lflag = tty->termios.c_lflag;
3475 ch->ch_startc = tty->termios.c_cc[VSTART];
3476 ch->ch_stopc = tty->termios.c_cc[VSTOP];
3479 dgap_param(ch, bd, un->un_type);
3481 spin_unlock_irqrestore(&ch->ch_lock, lock_flags2);
3482 spin_unlock_irqrestore(&bd->bd_lock, lock_flags);
3485 static void dgap_tty_throttle(struct tty_struct *tty)
3488 struct channel_t *ch;
3493 if (!tty || tty->magic != TTY_MAGIC)
3496 un = tty->driver_data;
3497 if (!un || un->magic != DGAP_UNIT_MAGIC)
3501 if (!ch || ch->magic != DGAP_CHANNEL_MAGIC)
3505 if (!bd || bd->magic != DGAP_BOARD_MAGIC)
3508 spin_lock_irqsave(&bd->bd_lock, lock_flags);
3509 spin_lock_irqsave(&ch->ch_lock, lock_flags2);
3511 ch->ch_flags |= (CH_RXBLOCK);
3513 dgap_cmdw(ch, RPAUSE, 0, 0);
3516 spin_unlock_irqrestore(&ch->ch_lock, lock_flags2);
3517 spin_unlock_irqrestore(&bd->bd_lock, lock_flags);
3521 static void dgap_tty_unthrottle(struct tty_struct *tty)
3524 struct channel_t *ch;
3529 if (!tty || tty->magic != TTY_MAGIC)
3532 un = tty->driver_data;
3533 if (!un || un->magic != DGAP_UNIT_MAGIC)
3537 if (!ch || ch->magic != DGAP_CHANNEL_MAGIC)
3541 if (!bd || bd->magic != DGAP_BOARD_MAGIC)
3544 spin_lock_irqsave(&bd->bd_lock, lock_flags);
3545 spin_lock_irqsave(&ch->ch_lock, lock_flags2);
3547 ch->ch_flags &= ~(CH_RXBLOCK);
3550 dgap_cmdw(ch, RRESUME, 0, 0);
3553 spin_unlock_irqrestore(&ch->ch_lock, lock_flags2);
3554 spin_unlock_irqrestore(&bd->bd_lock, lock_flags);
3557 static void dgap_tty_start(struct tty_struct *tty)
3560 struct channel_t *ch;
3565 if (!tty || tty->magic != TTY_MAGIC)
3568 un = tty->driver_data;
3569 if (!un || un->magic != DGAP_UNIT_MAGIC)
3573 if (!ch || ch->magic != DGAP_CHANNEL_MAGIC)
3577 if (!bd || bd->magic != DGAP_BOARD_MAGIC)
3580 spin_lock_irqsave(&bd->bd_lock, lock_flags);
3581 spin_lock_irqsave(&ch->ch_lock, lock_flags2);
3583 dgap_cmdw(ch, RESUMETX, 0, 0);
3585 spin_unlock_irqrestore(&ch->ch_lock, lock_flags2);
3586 spin_unlock_irqrestore(&bd->bd_lock, lock_flags);
3589 static void dgap_tty_stop(struct tty_struct *tty)
3592 struct channel_t *ch;
3597 if (!tty || tty->magic != TTY_MAGIC)
3600 un = tty->driver_data;
3601 if (!un || un->magic != DGAP_UNIT_MAGIC)
3605 if (!ch || ch->magic != DGAP_CHANNEL_MAGIC)
3609 if (!bd || bd->magic != DGAP_BOARD_MAGIC)
3612 spin_lock_irqsave(&bd->bd_lock, lock_flags);
3613 spin_lock_irqsave(&ch->ch_lock, lock_flags2);
3615 dgap_cmdw(ch, PAUSETX, 0, 0);
3617 spin_unlock_irqrestore(&ch->ch_lock, lock_flags2);
3618 spin_unlock_irqrestore(&bd->bd_lock, lock_flags);
3622 * dgap_tty_flush_chars()
3624 * Flush the cook buffer
3626 * Note to self, and any other poor souls who venture here:
3628 * flush in this case DOES NOT mean dispose of the data.
3629 * instead, it means "stop buffering and send it if you
3630 * haven't already." Just guess how I figured that out... SRW 2-Jun-98
3632 * It is also always called in interrupt context - JAR 8-Sept-99
3634 static void dgap_tty_flush_chars(struct tty_struct *tty)
3637 struct channel_t *ch;
3642 if (!tty || tty->magic != TTY_MAGIC)
3645 un = tty->driver_data;
3646 if (!un || un->magic != DGAP_UNIT_MAGIC)
3650 if (!ch || ch->magic != DGAP_CHANNEL_MAGIC)
3654 if (!bd || bd->magic != DGAP_BOARD_MAGIC)
3657 spin_lock_irqsave(&bd->bd_lock, lock_flags);
3658 spin_lock_irqsave(&ch->ch_lock, lock_flags2);
3660 /* TODO: Do something here */
3662 spin_unlock_irqrestore(&ch->ch_lock, lock_flags2);
3663 spin_unlock_irqrestore(&bd->bd_lock, lock_flags);
3667 * dgap_tty_flush_buffer()
3669 * Flush Tx buffer (make in == out)
3671 static void dgap_tty_flush_buffer(struct tty_struct *tty)
3674 struct channel_t *ch;
3680 if (!tty || tty->magic != TTY_MAGIC)
3683 un = tty->driver_data;
3684 if (!un || un->magic != DGAP_UNIT_MAGIC)
3688 if (!ch || ch->magic != DGAP_CHANNEL_MAGIC)
3692 if (!bd || bd->magic != DGAP_BOARD_MAGIC)
3695 spin_lock_irqsave(&bd->bd_lock, lock_flags);
3696 spin_lock_irqsave(&ch->ch_lock, lock_flags2);
3698 ch->ch_flags &= ~CH_STOP;
3699 head = readw(&(ch->ch_bs->tx_head));
3700 dgap_cmdw(ch, FLUSHTX, (u16) head, 0);
3701 dgap_cmdw(ch, RESUMETX, 0, 0);
3702 if (ch->ch_tun.un_flags & (UN_LOW|UN_EMPTY)) {
3703 ch->ch_tun.un_flags &= ~(UN_LOW|UN_EMPTY);
3704 wake_up_interruptible(&ch->ch_tun.un_flags_wait);
3706 if (ch->ch_pun.un_flags & (UN_LOW|UN_EMPTY)) {
3707 ch->ch_pun.un_flags &= ~(UN_LOW|UN_EMPTY);
3708 wake_up_interruptible(&ch->ch_pun.un_flags_wait);
3711 spin_unlock_irqrestore(&ch->ch_lock, lock_flags2);
3712 spin_unlock_irqrestore(&bd->bd_lock, lock_flags);
3713 if (waitqueue_active(&tty->write_wait))
3714 wake_up_interruptible(&tty->write_wait);
3718 /*****************************************************************************
3720 * The IOCTL function and all of its helpers
3722 *****************************************************************************/
3727 * The usual assortment of ioctl's
3729 static int dgap_tty_ioctl(struct tty_struct *tty, unsigned int cmd,
3733 struct channel_t *ch;
3737 ulong lock_flags = 0;
3738 ulong lock_flags2 = 0;
3739 void __user *uarg = (void __user *) arg;
3741 if (!tty || tty->magic != TTY_MAGIC)
3744 un = tty->driver_data;
3745 if (!un || un->magic != DGAP_UNIT_MAGIC)
3749 if (!ch || ch->magic != DGAP_CHANNEL_MAGIC)
3753 if (!bd || bd->magic != DGAP_BOARD_MAGIC)
3756 spin_lock_irqsave(&bd->bd_lock, lock_flags);
3757 spin_lock_irqsave(&ch->ch_lock, lock_flags2);
3759 if (un->un_open_count <= 0) {
3760 spin_unlock_irqrestore(&ch->ch_lock, lock_flags2);
3761 spin_unlock_irqrestore(&bd->bd_lock, lock_flags);
3767 /* Here are all the standard ioctl's that we MUST implement */
3771 * TCSBRK is SVID version: non-zero arg --> no break
3772 * this behaviour is exploited by tcdrain().
3774 * According to POSIX.1 spec (7.2.2.1.2) breaks should be
3775 * between 0.25 and 0.5 seconds so we'll ask for something
3776 * in the middle: 0.375 seconds.
3778 rc = tty_check_change(tty);
3779 spin_unlock_irqrestore(&ch->ch_lock, lock_flags2);
3780 spin_unlock_irqrestore(&bd->bd_lock, lock_flags);
3784 rc = dgap_wait_for_drain(tty);
3789 spin_lock_irqsave(&bd->bd_lock, lock_flags);
3790 spin_lock_irqsave(&ch->ch_lock, lock_flags2);
3792 if (((cmd == TCSBRK) && (!arg)) || (cmd == TCSBRKP))
3793 dgap_cmdw(ch, SBREAK, (u16) SBREAK_TIME, 0);
3795 spin_unlock_irqrestore(&ch->ch_lock, lock_flags2);
3796 spin_unlock_irqrestore(&bd->bd_lock, lock_flags);
3801 /* support for POSIX tcsendbreak()
3803 * According to POSIX.1 spec (7.2.2.1.2) breaks should be
3804 * between 0.25 and 0.5 seconds so we'll ask for something
3805 * in the middle: 0.375 seconds.
3807 rc = tty_check_change(tty);
3808 spin_unlock_irqrestore(&ch->ch_lock, lock_flags2);
3809 spin_unlock_irqrestore(&bd->bd_lock, lock_flags);
3813 rc = dgap_wait_for_drain(tty);
3817 spin_lock_irqsave(&bd->bd_lock, lock_flags);
3818 spin_lock_irqsave(&ch->ch_lock, lock_flags2);
3820 dgap_cmdw(ch, SBREAK, (u16) SBREAK_TIME, 0);
3822 spin_unlock_irqrestore(&ch->ch_lock, lock_flags2);
3823 spin_unlock_irqrestore(&bd->bd_lock, lock_flags);
3829 * FEP5 doesn't support turning on a break unconditionally.
3830 * The FEP5 device will stop sending a break automatically
3831 * after the specified time value that was sent when turning on
3834 rc = tty_check_change(tty);
3835 spin_unlock_irqrestore(&ch->ch_lock, lock_flags2);
3836 spin_unlock_irqrestore(&bd->bd_lock, lock_flags);
3840 rc = dgap_wait_for_drain(tty);
3844 spin_lock_irqsave(&bd->bd_lock, lock_flags);
3845 spin_lock_irqsave(&ch->ch_lock, lock_flags2);
3847 dgap_cmdw(ch, SBREAK, (u16) SBREAK_TIME, 0);
3849 spin_unlock_irqrestore(&ch->ch_lock, lock_flags2);
3850 spin_unlock_irqrestore(&bd->bd_lock, lock_flags);
3856 * FEP5 doesn't support turning off a break unconditionally.
3857 * The FEP5 device will stop sending a break automatically
3858 * after the specified time value that was sent when turning on
3861 spin_unlock_irqrestore(&ch->ch_lock, lock_flags2);
3862 spin_unlock_irqrestore(&bd->bd_lock, lock_flags);
3867 spin_unlock_irqrestore(&ch->ch_lock, lock_flags2);
3868 spin_unlock_irqrestore(&bd->bd_lock, lock_flags);
3870 rc = put_user(C_CLOCAL(tty) ? 1 : 0,
3871 (unsigned long __user *) arg);
3875 spin_unlock_irqrestore(&ch->ch_lock, lock_flags2);
3876 spin_unlock_irqrestore(&bd->bd_lock, lock_flags);
3878 rc = get_user(arg, (unsigned long __user *) arg);
3882 spin_lock_irqsave(&bd->bd_lock, lock_flags);
3883 spin_lock_irqsave(&ch->ch_lock, lock_flags2);
3884 tty->termios.c_cflag = ((tty->termios.c_cflag & ~CLOCAL) |
3885 (arg ? CLOCAL : 0));
3886 dgap_param(ch, bd, un->un_type);
3887 spin_unlock_irqrestore(&ch->ch_lock, lock_flags2);
3888 spin_unlock_irqrestore(&bd->bd_lock, lock_flags);
3893 spin_unlock_irqrestore(&ch->ch_lock, lock_flags2);
3894 spin_unlock_irqrestore(&bd->bd_lock, lock_flags);
3895 return dgap_get_modem_info(ch, uarg);
3900 spin_unlock_irqrestore(&ch->ch_lock, lock_flags2);
3901 spin_unlock_irqrestore(&bd->bd_lock, lock_flags);
3902 return dgap_set_modem_info(tty, cmd, uarg);
3905 * Here are any additional ioctl's that we want to implement
3910 * The linux tty driver doesn't have a flush
3911 * input routine for the driver, assuming all backed
3912 * up data is in the line disc. buffers. However,
3913 * we all know that's not the case. Here, we
3914 * act on the ioctl, but then lie and say we didn't
3915 * so the line discipline will process the flush
3918 rc = tty_check_change(tty);
3920 spin_unlock_irqrestore(&ch->ch_lock, lock_flags2);
3921 spin_unlock_irqrestore(&bd->bd_lock, lock_flags);
3925 if ((arg == TCIFLUSH) || (arg == TCIOFLUSH)) {
3926 if (!(un->un_type == DGAP_PRINT)) {
3927 head = readw(&(ch->ch_bs->rx_head));
3928 writew(head, &(ch->ch_bs->rx_tail));
3929 writeb(0, &(ch->ch_bs->orun));
3933 if ((arg != TCOFLUSH) && (arg != TCIOFLUSH)) {
3934 /* pretend we didn't recognize this IOCTL */
3935 spin_unlock_irqrestore(&ch->ch_lock, lock_flags2);
3936 spin_unlock_irqrestore(&bd->bd_lock, lock_flags);
3938 return -ENOIOCTLCMD;
3941 ch->ch_flags &= ~CH_STOP;
3942 head = readw(&(ch->ch_bs->tx_head));
3943 dgap_cmdw(ch, FLUSHTX, (u16) head, 0);
3944 dgap_cmdw(ch, RESUMETX, 0, 0);
3945 if (ch->ch_tun.un_flags & (UN_LOW|UN_EMPTY)) {
3946 ch->ch_tun.un_flags &= ~(UN_LOW|UN_EMPTY);
3947 wake_up_interruptible(&ch->ch_tun.un_flags_wait);
3949 if (ch->ch_pun.un_flags & (UN_LOW|UN_EMPTY)) {
3950 ch->ch_pun.un_flags &= ~(UN_LOW|UN_EMPTY);
3951 wake_up_interruptible(&ch->ch_pun.un_flags_wait);
3953 if (waitqueue_active(&tty->write_wait))
3954 wake_up_interruptible(&tty->write_wait);
3956 /* Can't hold any locks when calling tty_wakeup! */
3957 spin_unlock_irqrestore(&ch->ch_lock, lock_flags2);
3958 spin_unlock_irqrestore(&bd->bd_lock, lock_flags);
3961 /* pretend we didn't recognize this IOCTL */
3962 return -ENOIOCTLCMD;
3967 * The linux tty driver doesn't have a flush
3968 * input routine for the driver, assuming all backed
3969 * up data is in the line disc. buffers. However,
3970 * we all know that's not the case. Here, we
3971 * act on the ioctl, but then lie and say we didn't
3972 * so the line discipline will process the flush
3975 if (cmd == TCSETSF) {
3977 ch->ch_flags &= ~CH_STOP;
3978 head = readw(&(ch->ch_bs->rx_head));
3979 writew(head, &(ch->ch_bs->rx_tail));
3982 /* now wait for all the output to drain */
3983 spin_unlock_irqrestore(&ch->ch_lock, lock_flags2);
3984 spin_unlock_irqrestore(&bd->bd_lock, lock_flags);
3985 rc = dgap_wait_for_drain(tty);
3989 /* pretend we didn't recognize this */
3990 return -ENOIOCTLCMD;
3994 spin_unlock_irqrestore(&ch->ch_lock, lock_flags2);
3995 spin_unlock_irqrestore(&bd->bd_lock, lock_flags);
3996 rc = dgap_wait_for_drain(tty);
4000 /* pretend we didn't recognize this */
4001 return -ENOIOCTLCMD;
4005 * The Linux Line Discipline (LD) would do this for us if we
4006 * let it, but we have the special firmware options to do this
4007 * the "right way" regardless of hardware or software flow
4008 * control so we'll do it outselves instead of letting the LD
4011 rc = tty_check_change(tty);
4013 spin_unlock_irqrestore(&ch->ch_lock, lock_flags2);
4014 spin_unlock_irqrestore(&bd->bd_lock, lock_flags);
4021 spin_unlock_irqrestore(&ch->ch_lock, lock_flags2);
4022 spin_unlock_irqrestore(&bd->bd_lock, lock_flags);
4023 dgap_tty_start(tty);
4026 spin_unlock_irqrestore(&ch->ch_lock, lock_flags2);
4027 spin_unlock_irqrestore(&bd->bd_lock, lock_flags);
4031 spin_unlock_irqrestore(&ch->ch_lock, lock_flags2);
4032 spin_unlock_irqrestore(&bd->bd_lock, lock_flags);
4033 /* Make the ld do it */
4034 return -ENOIOCTLCMD;
4036 spin_unlock_irqrestore(&ch->ch_lock, lock_flags2);
4037 spin_unlock_irqrestore(&bd->bd_lock, lock_flags);
4038 /* Make the ld do it */
4039 return -ENOIOCTLCMD;
4041 spin_unlock_irqrestore(&ch->ch_lock, lock_flags2);
4042 spin_unlock_irqrestore(&bd->bd_lock, lock_flags);
4047 /* get information for ditty */
4048 spin_unlock_irqrestore(&ch->ch_lock, lock_flags2);
4049 spin_unlock_irqrestore(&bd->bd_lock, lock_flags);
4050 return dgap_tty_digigeta(ch, un, uarg);
4055 /* set information for ditty */
4056 if (cmd == (DIGI_SETAW)) {
4058 spin_unlock_irqrestore(&ch->ch_lock, lock_flags2);
4059 spin_unlock_irqrestore(&bd->bd_lock, lock_flags);
4060 rc = dgap_wait_for_drain(tty);
4063 spin_lock_irqsave(&bd->bd_lock, lock_flags);
4064 spin_lock_irqsave(&ch->ch_lock, lock_flags2);
4066 tty_ldisc_flush(tty);
4070 spin_unlock_irqrestore(&ch->ch_lock, lock_flags2);
4071 spin_unlock_irqrestore(&bd->bd_lock, lock_flags);
4072 return dgap_tty_digiseta(ch, bd, un, uarg);
4075 spin_unlock_irqrestore(&ch->ch_lock, lock_flags2);
4076 spin_unlock_irqrestore(&bd->bd_lock, lock_flags);
4077 return dgap_tty_digigetedelay(tty, uarg);
4080 spin_unlock_irqrestore(&ch->ch_lock, lock_flags2);
4081 spin_unlock_irqrestore(&bd->bd_lock, lock_flags);
4082 return dgap_tty_digisetedelay(tty, uarg);
4084 case DIGI_GETCUSTOMBAUD:
4085 spin_unlock_irqrestore(&ch->ch_lock, lock_flags2);
4086 spin_unlock_irqrestore(&bd->bd_lock, lock_flags);
4087 return dgap_tty_digigetcustombaud(tty, uarg);
4089 case DIGI_SETCUSTOMBAUD:
4090 spin_unlock_irqrestore(&ch->ch_lock, lock_flags2);
4091 spin_unlock_irqrestore(&bd->bd_lock, lock_flags);
4092 return dgap_tty_digisetcustombaud(tty, uarg);
4094 case DIGI_RESET_PORT:
4095 dgap_firmware_reset_port(ch);
4096 dgap_param(ch, bd, un->un_type);
4097 spin_unlock_irqrestore(&ch->ch_lock, lock_flags2);
4098 spin_unlock_irqrestore(&bd->bd_lock, lock_flags);
4102 spin_unlock_irqrestore(&ch->ch_lock, lock_flags2);
4103 spin_unlock_irqrestore(&bd->bd_lock, lock_flags);
4105 return -ENOIOCTLCMD;
4109 static int dgap_alloc_flipbuf(struct board_t *brd)
4112 * allocate flip buffer for board.
4114 brd->flipbuf = kmalloc(MYFLIPLEN, GFP_KERNEL);
4118 brd->flipflagbuf = kmalloc(MYFLIPLEN, GFP_KERNEL);
4119 if (!brd->flipflagbuf) {
4120 kfree(brd->flipbuf);
4127 static void dgap_free_flipbuf(struct board_t *brd)
4129 kfree(brd->flipbuf);
4130 kfree(brd->flipflagbuf);
4134 * Create pr and tty device entries
4136 static int dgap_tty_register_ports(struct board_t *brd)
4138 struct channel_t *ch;
4142 brd->serial_ports = kcalloc(brd->nasync, sizeof(*brd->serial_ports),
4144 if (!brd->serial_ports)
4147 brd->printer_ports = kcalloc(brd->nasync, sizeof(*brd->printer_ports),
4149 if (!brd->printer_ports) {
4151 goto free_serial_ports;
4154 for (i = 0; i < brd->nasync; i++) {
4155 tty_port_init(&brd->serial_ports[i]);
4156 tty_port_init(&brd->printer_ports[i]);
4159 ch = brd->channels[0];
4160 for (i = 0; i < brd->nasync; i++, ch = brd->channels[i]) {
4162 struct device *classp;
4164 classp = tty_port_register_device(&brd->serial_ports[i],
4168 if (IS_ERR(classp)) {
4169 ret = PTR_ERR(classp);
4170 goto unregister_ttys;
4173 dgap_create_tty_sysfs(&ch->ch_tun, classp);
4174 ch->ch_tun.un_sysfs = classp;
4176 classp = tty_port_register_device(&brd->printer_ports[i],
4180 if (IS_ERR(classp)) {
4181 ret = PTR_ERR(classp);
4182 goto unregister_ttys;
4185 dgap_create_tty_sysfs(&ch->ch_pun, classp);
4186 ch->ch_pun.un_sysfs = classp;
4188 dgap_create_ports_sysfiles(brd);
4194 ch = brd->channels[i];
4195 if (ch->ch_tun.un_sysfs) {
4196 dgap_remove_tty_sysfs(ch->ch_tun.un_sysfs);
4197 tty_unregister_device(brd->serial_driver, i);
4200 if (ch->ch_pun.un_sysfs) {
4201 dgap_remove_tty_sysfs(ch->ch_pun.un_sysfs);
4202 tty_unregister_device(brd->print_driver, i);
4207 for (i = 0; i < brd->nasync; i++) {
4208 tty_port_destroy(&brd->serial_ports[i]);
4209 tty_port_destroy(&brd->printer_ports[i]);
4212 kfree(brd->printer_ports);
4213 brd->printer_ports = NULL;
4216 kfree(brd->serial_ports);
4217 brd->serial_ports = NULL;
4223 * Copies the BIOS code from the user to the board,
4224 * and starts the BIOS running.
4226 static void dgap_do_bios_load(struct board_t *brd, const u8 *ubios, int len)
4232 if (!brd || (brd->magic != DGAP_BOARD_MAGIC) || !brd->re_map_membase)
4235 addr = brd->re_map_membase;
4240 for (i = 0; i < 16; i++)
4241 writeb(0, addr + POSTAREA + i);
4247 memcpy_toio(addr + offset, ubios, len);
4249 writel(0x0bf00401, addr);
4250 writel(0, (addr + 4));
4252 /* Clear the reset, and change states. */
4253 writeb(FEPCLR, brd->re_map_port);
4257 * Checks to see if the BIOS completed running on the card.
4259 static int dgap_test_bios(struct board_t *brd)
4266 if (!brd || (brd->magic != DGAP_BOARD_MAGIC) || !brd->re_map_membase)
4269 addr = brd->re_map_membase;
4270 word = readw(addr + POSTAREA);
4273 * It can take 5-6 seconds for a board to
4274 * pass the bios self test and post results.
4275 * Give it 10 seconds.
4277 brd->wait_for_bios = 0;
4278 while (brd->wait_for_bios < 1000) {
4279 /* Check to see if BIOS thinks board is good. (GD). */
4280 if (word == *(u16 *) "GD")
4282 msleep_interruptible(10);
4283 brd->wait_for_bios++;
4284 word = readw(addr + POSTAREA);
4287 /* Gave up on board after too long of time taken */
4288 err1 = readw(addr + SEQUENCE);
4289 err2 = readw(addr + ERROR);
4290 pr_warn("dgap: %s failed diagnostics. Error #(%x,%x).\n",
4291 brd->name, err1, err2);
4292 brd->state = BOARD_FAILED;
4293 brd->dpastatus = BD_NOBIOS;
4299 * Copies the FEP code from the user to the board,
4300 * and starts the FEP running.
4302 static void dgap_do_fep_load(struct board_t *brd, const u8 *ufep, int len)
4307 if (!brd || (brd->magic != DGAP_BOARD_MAGIC) || !brd->re_map_membase)
4310 addr = brd->re_map_membase;
4316 memcpy_toio(addr + offset, ufep, len);
4319 * If board is a concentrator product, we need to give
4320 * it its config string describing how the concentrators look.
4322 if ((brd->type == PCX) || (brd->type == PEPC)) {
4328 xconfig = dgap_create_config_string(brd, string);
4330 /* Write string to board memory */
4331 config = addr + CONFIG;
4332 for (; i < CONFIGSIZE; i++, config++, xconfig++) {
4333 writeb(*xconfig, config);
4334 if ((*xconfig & 0xff) == 0xff)
4339 writel(0xbfc01004, (addr + 0xc34));
4340 writel(0x3, (addr + 0xc30));
4345 * Waits for the FEP to report thats its ready for us to use.
4347 static int dgap_test_fep(struct board_t *brd)
4354 if (!brd || (brd->magic != DGAP_BOARD_MAGIC) || !brd->re_map_membase)
4357 addr = brd->re_map_membase;
4358 word = readw(addr + FEPSTAT);
4361 * It can take 2-3 seconds for the FEP to
4362 * be up and running. Give it 5 secs.
4364 brd->wait_for_fep = 0;
4365 while (brd->wait_for_fep < 500) {
4366 /* Check to see if FEP is up and running now. */
4367 if (word == *(u16 *) "OS") {
4369 * Check to see if the board can support FEP5+ commands.
4371 word = readw(addr + FEP5_PLUS);
4372 if (word == *(u16 *) "5A")
4373 brd->bd_flags |= BD_FEP5PLUS;
4377 msleep_interruptible(10);
4378 brd->wait_for_fep++;
4379 word = readw(addr + FEPSTAT);
4382 /* Gave up on board after too long of time taken */
4383 err1 = readw(addr + SEQUENCE);
4384 err2 = readw(addr + ERROR);
4385 pr_warn("dgap: FEPOS for %s not functioning. Error #(%x,%x).\n",
4386 brd->name, err1, err2);
4387 brd->state = BOARD_FAILED;
4388 brd->dpastatus = BD_NOFEP;
4394 * Physically forces the FEP5 card to reset itself.
4396 static void dgap_do_reset_board(struct board_t *brd)
4403 if (!brd || (brd->magic != DGAP_BOARD_MAGIC) ||
4404 !brd->re_map_membase || !brd->re_map_port)
4407 /* FEPRST does not vary among supported boards */
4408 writeb(FEPRST, brd->re_map_port);
4410 for (i = 0; i <= 1000; i++) {
4411 check = readb(brd->re_map_port) & 0xe;
4412 if (check == FEPRST)
4418 pr_warn("dgap: Board not resetting... Failing board.\n");
4419 brd->state = BOARD_FAILED;
4420 brd->dpastatus = BD_NOFEP;
4425 * Make sure there really is memory out there.
4427 writel(0xa55a3cc3, (brd->re_map_membase + LOWMEM));
4428 writel(0x5aa5c33c, (brd->re_map_membase + HIGHMEM));
4429 check1 = readl(brd->re_map_membase + LOWMEM);
4430 check2 = readl(brd->re_map_membase + HIGHMEM);
4432 if ((check1 != 0xa55a3cc3) || (check2 != 0x5aa5c33c)) {
4433 pr_warn("dgap: No memory at %p for board.\n",
4434 brd->re_map_membase);
4435 brd->state = BOARD_FAILED;
4436 brd->dpastatus = BD_NOFEP;
4441 #ifdef DIGI_CONCENTRATORS_SUPPORTED
4443 * Sends a concentrator image into the FEP5 board.
4445 static void dgap_do_conc_load(struct board_t *brd, u8 *uaddr, int len)
4447 char __iomem *vaddr;
4449 struct downld_t *to_dp;
4451 if (!brd || (brd->magic != DGAP_BOARD_MAGIC) || !brd->re_map_membase)
4454 vaddr = brd->re_map_membase;
4456 offset = readw((u16 *) (vaddr + DOWNREQ));
4457 to_dp = (struct downld_t *) (vaddr + (int) offset);
4458 memcpy_toio(to_dp, uaddr, len);
4460 /* Tell card we have data for it */
4461 writew(0, vaddr + (DOWNREQ));
4463 brd->conc_dl_status = NO_PENDING_CONCENTRATOR_REQUESTS;
4467 #define EXPANSION_ROM_SIZE (64 * 1024)
4468 #define FEP5_ROM_MAGIC (0xFEFFFFFF)
4470 static void dgap_get_vpd(struct board_t *brd)
4482 * Poke the magic number at the PCI Rom Address location.
4483 * If VPD is supported, the value read from that address
4486 magic = FEP5_ROM_MAGIC;
4487 pci_write_config_dword(brd->pdev, PCI_ROM_ADDRESS, magic);
4488 pci_read_config_dword(brd->pdev, PCI_ROM_ADDRESS, &magic);
4490 /* VPD not supported, bail */
4495 * To get to the OTPROM memory, we have to send the boards base
4496 * address or'ed with 1 into the PCI Rom Address location.
4498 magic = brd->membase | 0x01;
4499 pci_write_config_dword(brd->pdev, PCI_ROM_ADDRESS, magic);
4500 pci_read_config_dword(brd->pdev, PCI_ROM_ADDRESS, &magic);
4502 byte1 = readb(brd->re_map_membase);
4503 byte2 = readb(brd->re_map_membase + 1);
4506 * If the board correctly swapped to the OTPROM memory,
4507 * the first 2 bytes (header) should be 0x55, 0xAA
4509 if (byte1 == 0x55 && byte2 == 0xAA) {
4514 * We have to run through all the OTPROM memory looking
4515 * for the VPD offset.
4517 while (base_offset <= EXPANSION_ROM_SIZE) {
4520 * Lots of magic numbers here.
4522 * The VPD offset is located inside the ROM Data
4525 * We also have to remember the length of each
4526 * ROM Data Structure, so we can "hop" to the next
4527 * entry if the VPD isn't in the current
4528 * ROM Data Structure.
4530 rom_offset = readw(brd->re_map_membase +
4531 base_offset + 0x18);
4532 image_length = readw(brd->re_map_membase +
4533 rom_offset + 0x10) * 512;
4534 vpd_offset = readw(brd->re_map_membase +
4537 /* Found the VPD entry */
4541 /* We didn't find a VPD entry, go to next ROM entry. */
4542 base_offset += image_length;
4544 byte1 = readb(brd->re_map_membase + base_offset);
4545 byte2 = readb(brd->re_map_membase + base_offset + 1);
4548 * If the new ROM offset doesn't have 0x55, 0xAA
4549 * as its header, we have run out of ROM.
4551 if (byte1 != 0x55 || byte2 != 0xAA)
4556 * If we have a VPD offset, then mark the board
4557 * as having a valid VPD, and copy VPDSIZE (512) bytes of
4558 * that VPD to the buffer we have in our board structure.
4561 brd->bd_flags |= BD_HAS_VPD;
4562 for (i = 0; i < VPDSIZE; i++) {
4563 brd->vpd[i] = readb(brd->re_map_membase +
4570 * We MUST poke the magic number at the PCI Rom Address location again.
4571 * This makes the card report the regular board memory back to us,
4572 * rather than the OTPROM memory.
4574 magic = FEP5_ROM_MAGIC;
4575 pci_write_config_dword(brd->pdev, PCI_ROM_ADDRESS, magic);
4579 * Our board poller function.
4581 static void dgap_poll_tasklet(unsigned long data)
4583 struct board_t *bd = (struct board_t *) data;
4585 char __iomem *vaddr;
4588 if (!bd || (bd->magic != DGAP_BOARD_MAGIC))
4591 if (bd->inhibit_poller)
4594 spin_lock_irqsave(&bd->bd_lock, lock_flags);
4596 vaddr = bd->re_map_membase;
4599 * If board is ready, parse deeper to see if there is anything to do.
4601 if (bd->state == BOARD_READY) {
4603 struct ev_t __iomem *eaddr;
4605 if (!bd->re_map_membase) {
4606 spin_unlock_irqrestore(&bd->bd_lock, lock_flags);
4609 if (!bd->re_map_port) {
4610 spin_unlock_irqrestore(&bd->bd_lock, lock_flags);
4617 eaddr = (struct ev_t __iomem *) (vaddr + EVBUF);
4619 /* Get our head and tail */
4620 head = readw(&(eaddr->ev_head));
4621 tail = readw(&(eaddr->ev_tail));
4624 * If there is an event pending. Go service it.
4627 spin_unlock_irqrestore(&bd->bd_lock, lock_flags);
4629 spin_lock_irqsave(&bd->bd_lock, lock_flags);
4634 * If board is doing interrupts, ACK the interrupt.
4636 if (bd && bd->intr_running)
4637 readb(bd->re_map_port + 2);
4639 spin_unlock_irqrestore(&bd->bd_lock, lock_flags);
4643 spin_unlock_irqrestore(&bd->bd_lock, lock_flags);
4646 /*=======================================================================
4648 * dgap_cmdb - Sends a 2 byte command to the FEP.
4650 * ch - Pointer to channel structure.
4651 * cmd - Command to be sent.
4652 * byte1 - Integer containing first byte to be sent.
4653 * byte2 - Integer containing second byte to be sent.
4654 * ncmds - Wait until ncmds or fewer cmds are left
4655 * in the cmd buffer before returning.
4657 *=======================================================================*/
4658 static void dgap_cmdb(struct channel_t *ch, u8 cmd, u8 byte1,
4659 u8 byte2, uint ncmds)
4661 char __iomem *vaddr;
4662 struct __iomem cm_t *cm_addr;
4668 if (!ch || ch->magic != DGAP_CHANNEL_MAGIC)
4672 * Check if board is still alive.
4674 if (ch->ch_bd->state == BOARD_FAILED)
4678 * Make sure the pointers are in range before
4679 * writing to the FEP memory.
4681 vaddr = ch->ch_bd->re_map_membase;
4686 cm_addr = (struct cm_t __iomem *) (vaddr + CMDBUF);
4687 head = readw(&(cm_addr->cm_head));
4690 * Forget it if pointers out of range.
4692 if (head >= (CMDMAX - CMDSTART) || (head & 03)) {
4693 ch->ch_bd->state = BOARD_FAILED;
4698 * Put the data in the circular command buffer.
4700 writeb(cmd, (vaddr + head + CMDSTART + 0));
4701 writeb((u8) ch->ch_portnum, (vaddr + head + CMDSTART + 1));
4702 writeb(byte1, (vaddr + head + CMDSTART + 2));
4703 writeb(byte2, (vaddr + head + CMDSTART + 3));
4705 head = (head + 4) & (CMDMAX - CMDSTART - 4);
4707 writew(head, &(cm_addr->cm_head));
4710 * Wait if necessary before updating the head
4711 * pointer to limit the number of outstanding
4712 * commands to the FEP. If the time spent waiting
4713 * is outlandish, declare the FEP dead.
4715 for (count = dgap_count ;;) {
4717 head = readw(&(cm_addr->cm_head));
4718 tail = readw(&(cm_addr->cm_tail));
4720 n = (head - tail) & (CMDMAX - CMDSTART - 4);
4722 if (n <= ncmds * sizeof(struct cm_t))
4726 ch->ch_bd->state = BOARD_FAILED;
4733 /*=======================================================================
4735 * dgap_cmdw - Sends a 1 word command to the FEP.
4737 * ch - Pointer to channel structure.
4738 * cmd - Command to be sent.
4739 * word - Integer containing word to be sent.
4740 * ncmds - Wait until ncmds or fewer cmds are left
4741 * in the cmd buffer before returning.
4743 *=======================================================================*/
4744 static void dgap_cmdw(struct channel_t *ch, u8 cmd, u16 word, uint ncmds)
4746 char __iomem *vaddr;
4747 struct __iomem cm_t *cm_addr;
4753 if (!ch || ch->magic != DGAP_CHANNEL_MAGIC)
4757 * Check if board is still alive.
4759 if (ch->ch_bd->state == BOARD_FAILED)
4763 * Make sure the pointers are in range before
4764 * writing to the FEP memory.
4766 vaddr = ch->ch_bd->re_map_membase;
4770 cm_addr = (struct cm_t __iomem *) (vaddr + CMDBUF);
4771 head = readw(&(cm_addr->cm_head));
4774 * Forget it if pointers out of range.
4776 if (head >= (CMDMAX - CMDSTART) || (head & 03)) {
4777 ch->ch_bd->state = BOARD_FAILED;
4782 * Put the data in the circular command buffer.
4784 writeb(cmd, (vaddr + head + CMDSTART + 0));
4785 writeb((u8) ch->ch_portnum, (vaddr + head + CMDSTART + 1));
4786 writew((u16) word, (vaddr + head + CMDSTART + 2));
4788 head = (head + 4) & (CMDMAX - CMDSTART - 4);
4790 writew(head, &(cm_addr->cm_head));
4793 * Wait if necessary before updating the head
4794 * pointer to limit the number of outstanding
4795 * commands to the FEP. If the time spent waiting
4796 * is outlandish, declare the FEP dead.
4798 for (count = dgap_count ;;) {
4800 head = readw(&(cm_addr->cm_head));
4801 tail = readw(&(cm_addr->cm_tail));
4803 n = (head - tail) & (CMDMAX - CMDSTART - 4);
4805 if (n <= ncmds * sizeof(struct cm_t))
4809 ch->ch_bd->state = BOARD_FAILED;
4816 /*=======================================================================
4818 * dgap_cmdw_ext - Sends a extended word command to the FEP.
4820 * ch - Pointer to channel structure.
4821 * cmd - Command to be sent.
4822 * word - Integer containing word to be sent.
4823 * ncmds - Wait until ncmds or fewer cmds are left
4824 * in the cmd buffer before returning.
4826 *=======================================================================*/
4827 static void dgap_cmdw_ext(struct channel_t *ch, u16 cmd, u16 word, uint ncmds)
4829 char __iomem *vaddr;
4830 struct __iomem cm_t *cm_addr;
4836 if (!ch || ch->magic != DGAP_CHANNEL_MAGIC)
4840 * Check if board is still alive.
4842 if (ch->ch_bd->state == BOARD_FAILED)
4846 * Make sure the pointers are in range before
4847 * writing to the FEP memory.
4849 vaddr = ch->ch_bd->re_map_membase;
4853 cm_addr = (struct cm_t __iomem *) (vaddr + CMDBUF);
4854 head = readw(&(cm_addr->cm_head));
4857 * Forget it if pointers out of range.
4859 if (head >= (CMDMAX - CMDSTART) || (head & 03)) {
4860 ch->ch_bd->state = BOARD_FAILED;
4865 * Put the data in the circular command buffer.
4868 /* Write an FF to tell the FEP that we want an extended command */
4869 writeb((u8) 0xff, (vaddr + head + CMDSTART + 0));
4871 writeb((u8) ch->ch_portnum, (vaddr + head + CMDSTART + 1));
4872 writew((u16) cmd, (vaddr + head + CMDSTART + 2));
4875 * If the second part of the command won't fit,
4876 * put it at the beginning of the circular buffer.
4878 if (((head + 4) >= ((CMDMAX - CMDSTART)) || (head & 03)))
4879 writew((u16) word, (vaddr + CMDSTART));
4881 writew((u16) word, (vaddr + head + CMDSTART + 4));
4883 head = (head + 8) & (CMDMAX - CMDSTART - 4);
4885 writew(head, &(cm_addr->cm_head));
4888 * Wait if necessary before updating the head
4889 * pointer to limit the number of outstanding
4890 * commands to the FEP. If the time spent waiting
4891 * is outlandish, declare the FEP dead.
4893 for (count = dgap_count ;;) {
4895 head = readw(&(cm_addr->cm_head));
4896 tail = readw(&(cm_addr->cm_tail));
4898 n = (head - tail) & (CMDMAX - CMDSTART - 4);
4900 if (n <= ncmds * sizeof(struct cm_t))
4904 ch->ch_bd->state = BOARD_FAILED;
4911 /*=======================================================================
4913 * dgap_wmove - Write data to FEP buffer.
4915 * ch - Pointer to channel structure.
4916 * buf - Poiter to characters to be moved.
4917 * cnt - Number of characters to move.
4919 *=======================================================================*/
4920 static void dgap_wmove(struct channel_t *ch, char *buf, uint cnt)
4923 char __iomem *taddr;
4924 struct bs_t __iomem *bs;
4927 if (!ch || ch->magic != DGAP_CHANNEL_MAGIC)
4934 head = readw(&(bs->tx_head));
4937 * If pointers are out of range, just return.
4939 if ((cnt > ch->ch_tsize) ||
4940 (unsigned)(head - ch->ch_tstart) >= ch->ch_tsize)
4944 * If the write wraps over the top of the circular buffer,
4945 * move the portion up to the wrap point, and reset the
4946 * pointers to the bottom.
4948 n = ch->ch_tstart + ch->ch_tsize - head;
4952 taddr = ch->ch_taddr + head;
4953 memcpy_toio(taddr, buf, n);
4954 head = ch->ch_tstart;
4959 * Move rest of data.
4961 taddr = ch->ch_taddr + head;
4963 memcpy_toio(taddr, buf, n);
4966 writew(head, &(bs->tx_head));
4970 * Retrives the current custom baud rate from FEP memory,
4971 * and returns it back to the user.
4972 * Returns 0 on error.
4974 static uint dgap_get_custom_baud(struct channel_t *ch)
4980 if (!ch || ch->magic != DGAP_CHANNEL_MAGIC)
4983 if (!ch->ch_bd || ch->ch_bd->magic != DGAP_BOARD_MAGIC)
4986 if (!(ch->ch_bd->bd_flags & BD_FEP5PLUS))
4989 vaddr = ch->ch_bd->re_map_membase;
4995 * Go get from fep mem, what the fep
4996 * believes the custom baud rate is.
4998 offset = (ioread16(vaddr + ECS_SEG) << 4) + (ch->ch_portnum * 0x28)
5001 value = readw(vaddr + offset);
5006 * Calls the firmware to reset this channel.
5008 static void dgap_firmware_reset_port(struct channel_t *ch)
5010 dgap_cmdb(ch, CHRESET, 0, 0, 0);
5013 * Now that the channel is reset, we need to make sure
5014 * all the current settings get reapplied to the port
5017 * So we will set the driver's cache of firmware
5018 * settings all to 0, and then call param.
5020 ch->ch_fepiflag = 0;
5021 ch->ch_fepcflag = 0;
5022 ch->ch_fepoflag = 0;
5023 ch->ch_fepstartc = 0;
5024 ch->ch_fepstopc = 0;
5025 ch->ch_fepastartc = 0;
5026 ch->ch_fepastopc = 0;
5031 /*=======================================================================
5033 * dgap_param - Set Digi parameters.
5035 * struct tty_struct * - TTY for port.
5037 *=======================================================================*/
5038 static int dgap_param(struct channel_t *ch, struct board_t *bd, u32 un_type)
5047 * If baud rate is zero, flush queues, and set mval to drop DTR.
5049 if ((ch->ch_c_cflag & (CBAUD)) == 0) {
5052 head = readw(&(ch->ch_bs->rx_head));
5053 writew(head, &(ch->ch_bs->rx_tail));
5056 head = readw(&(ch->ch_bs->tx_head));
5057 writew(head, &(ch->ch_bs->tx_tail));
5059 ch->ch_flags |= (CH_BAUD0);
5061 /* Drop RTS and DTR */
5062 ch->ch_mval &= ~(D_RTS(ch)|D_DTR(ch));
5063 mval = D_DTR(ch) | D_RTS(ch);
5064 ch->ch_baud_info = 0;
5066 } else if (ch->ch_custom_speed && (bd->bd_flags & BD_FEP5PLUS)) {
5068 * Tell the fep to do the command
5071 dgap_cmdw_ext(ch, 0xff01, ch->ch_custom_speed, 0);
5074 * Now go get from fep mem, what the fep
5075 * believes the custom baud rate is.
5077 ch->ch_custom_speed = dgap_get_custom_baud(ch);
5078 ch->ch_baud_info = ch->ch_custom_speed;
5080 /* Handle transition from B0 */
5081 if (ch->ch_flags & CH_BAUD0) {
5082 ch->ch_flags &= ~(CH_BAUD0);
5083 ch->ch_mval |= (D_RTS(ch)|D_DTR(ch));
5085 mval = D_DTR(ch) | D_RTS(ch);
5089 * Set baud rate, character size, and parity.
5097 ulong bauds[4][16] = {
5101 600, 1200, 1800, 2400,
5102 4800, 9600, 19200, 38400 },
5103 { /* slowbaud & CBAUDEX */
5104 0, 57600, 115200, 230400,
5105 460800, 150, 200, 921600,
5106 600, 1200, 1800, 2400,
5107 4800, 9600, 19200, 38400 },
5109 0, 57600, 76800, 115200,
5110 14400, 57600, 230400, 76800,
5111 115200, 230400, 28800, 460800,
5112 921600, 9600, 19200, 38400 },
5113 { /* fastbaud & CBAUDEX */
5114 0, 57600, 115200, 230400,
5115 460800, 150, 200, 921600,
5116 600, 1200, 1800, 2400,
5117 4800, 9600, 19200, 38400 }
5121 * Only use the TXPrint baud rate if the
5122 * terminal unit is NOT open
5124 if (!(ch->ch_tun.un_flags & UN_ISOPEN) &&
5125 un_type == DGAP_PRINT)
5126 baud = C_BAUD(ch->ch_pun.un_tty) & 0xff;
5128 baud = C_BAUD(ch->ch_tun.un_tty) & 0xff;
5130 if (ch->ch_c_cflag & CBAUDEX)
5133 if (ch->ch_digi.digi_flags & DIGI_FAST)
5138 if ((iindex >= 0) && (iindex < 4) &&
5139 (jindex >= 0) && (jindex < 16))
5140 baud = bauds[iindex][jindex];
5147 ch->ch_baud_info = baud;
5150 * CBAUD has bit position 0x1000 set these days to
5151 * indicate Linux baud rate remap.
5152 * We use a different bit assignment for high speed.
5153 * Clear this bit out while grabbing the parts of
5156 cflag = ch->ch_c_cflag & ((CBAUD ^ CBAUDEX) | PARODD | PARENB |
5160 * HUPCL bit is used by FEP to indicate fast baud
5161 * table is to be used.
5163 if ((ch->ch_digi.digi_flags & DIGI_FAST) ||
5164 (ch->ch_c_cflag & CBAUDEX))
5167 if ((ch->ch_c_cflag & CBAUDEX) &&
5168 !(ch->ch_digi.digi_flags & DIGI_FAST)) {
5170 * The below code is trying to guarantee that only
5171 * baud rates 115200, 230400, 460800, 921600 are
5172 * remapped. We use exclusive or because the various
5173 * baud rates share common bit positions and therefore
5174 * can't be tested for easily.
5176 tcflag_t tcflag = (ch->ch_c_cflag & CBAUD) | CBAUDEX;
5180 * Map high speed requests to index
5181 * into FEP's baud table
5211 cflag = (cflag & ~(CBAUD | CBAUDEX)) | baudpart;
5216 if (cflag != ch->ch_fepcflag) {
5217 ch->ch_fepcflag = (u16) (cflag & 0xffff);
5220 * Okay to have channel and board
5221 * locks held calling this
5223 dgap_cmdw(ch, SCFLAG, (u16) cflag, 0);
5226 /* Handle transition from B0 */
5227 if (ch->ch_flags & CH_BAUD0) {
5228 ch->ch_flags &= ~(CH_BAUD0);
5229 ch->ch_mval |= (D_RTS(ch)|D_DTR(ch));
5231 mval = D_DTR(ch) | D_RTS(ch);
5237 iflag = ch->ch_c_iflag & (IGNBRK | BRKINT | IGNPAR | PARMRK |
5238 INPCK | ISTRIP | IXON | IXANY | IXOFF);
5240 if ((ch->ch_startc == _POSIX_VDISABLE) ||
5241 (ch->ch_stopc == _POSIX_VDISABLE)) {
5242 iflag &= ~(IXON | IXOFF);
5243 ch->ch_c_iflag &= ~(IXON | IXOFF);
5247 * Only the IBM Xr card can switch between
5248 * 232 and 422 modes on the fly
5250 if (bd->device == PCI_DEV_XR_IBM_DID) {
5251 if (ch->ch_digi.digi_flags & DIGI_422)
5252 dgap_cmdb(ch, SCOMMODE, MODE_422, 0, 0);
5254 dgap_cmdb(ch, SCOMMODE, MODE_232, 0, 0);
5257 if (ch->ch_digi.digi_flags & DIGI_ALTPIN)
5260 if (iflag != ch->ch_fepiflag) {
5261 ch->ch_fepiflag = iflag;
5263 /* Okay to have channel and board locks held calling this */
5264 dgap_cmdw(ch, SIFLAG, (u16) ch->ch_fepiflag, 0);
5268 * Select hardware handshaking.
5272 if (ch->ch_c_cflag & CRTSCTS)
5273 hflow |= (D_RTS(ch) | D_CTS(ch));
5274 if (ch->ch_digi.digi_flags & RTSPACE)
5276 if (ch->ch_digi.digi_flags & DTRPACE)
5278 if (ch->ch_digi.digi_flags & CTSPACE)
5280 if (ch->ch_digi.digi_flags & DSRPACE)
5282 if (ch->ch_digi.digi_flags & DCDPACE)
5285 if (hflow != ch->ch_hflow) {
5286 ch->ch_hflow = hflow;
5288 /* Okay to have channel and board locks held calling this */
5289 dgap_cmdb(ch, SHFLOW, (u8) hflow, 0xff, 0);
5293 * Set RTS and/or DTR Toggle if needed,
5294 * but only if product is FEP5+ based.
5296 if (bd->bd_flags & BD_FEP5PLUS) {
5299 if (ch->ch_digi.digi_flags & DIGI_RTS_TOGGLE)
5300 hflow2 |= (D_RTS(ch));
5301 if (ch->ch_digi.digi_flags & DIGI_DTR_TOGGLE)
5302 hflow2 |= (D_DTR(ch));
5304 dgap_cmdw_ext(ch, 0xff03, hflow2, 0);
5308 * Set modem control lines.
5311 mval ^= ch->ch_mforce & (mval ^ ch->ch_mval);
5313 if (ch->ch_mostat ^ mval) {
5314 ch->ch_mostat = mval;
5316 /* Okay to have channel and board locks held calling this */
5317 dgap_cmdb(ch, SMODEM, (u8) mval, D_RTS(ch)|D_DTR(ch), 0);
5321 * Read modem signals, and then call carrier function.
5323 ch->ch_mistat = readb(&(ch->ch_bs->m_stat));
5327 * Set the start and stop characters.
5329 if (ch->ch_startc != ch->ch_fepstartc ||
5330 ch->ch_stopc != ch->ch_fepstopc) {
5331 ch->ch_fepstartc = ch->ch_startc;
5332 ch->ch_fepstopc = ch->ch_stopc;
5334 /* Okay to have channel and board locks held calling this */
5335 dgap_cmdb(ch, SFLOWC, ch->ch_fepstartc, ch->ch_fepstopc, 0);
5339 * Set the Auxiliary start and stop characters.
5341 if (ch->ch_astartc != ch->ch_fepastartc ||
5342 ch->ch_astopc != ch->ch_fepastopc) {
5343 ch->ch_fepastartc = ch->ch_astartc;
5344 ch->ch_fepastopc = ch->ch_astopc;
5346 /* Okay to have channel and board locks held calling this */
5347 dgap_cmdb(ch, SAFLOWC, ch->ch_fepastartc, ch->ch_fepastopc, 0);
5354 * dgap_parity_scan()
5356 * Convert the FEP5 way of reporting parity errors and breaks into
5357 * the Linux line discipline way.
5359 static void dgap_parity_scan(struct channel_t *ch, unsigned char *cbuf,
5360 unsigned char *fbuf, int *len)
5364 unsigned char *in, *cout, *fout;
5371 if (!ch || ch->magic != DGAP_CHANNEL_MAGIC)
5376 switch (ch->pscan_state) {
5378 /* reset to sanity and fall through */
5379 ch->pscan_state = 0;
5382 /* No FF seen yet */
5383 if (c == (unsigned char) '\377')
5384 /* delete this character from stream */
5385 ch->pscan_state = 1;
5388 *fout++ = TTY_NORMAL;
5395 if (c == (unsigned char) '\377') {
5396 /* doubled ff, transform to single ff */
5398 *fout++ = TTY_NORMAL;
5400 ch->pscan_state = 0;
5402 /* save value examination in next state */
5403 ch->pscan_savechar = c;
5404 ch->pscan_state = 2;
5409 /* third character of ff sequence */
5413 if (ch->pscan_savechar == 0x0) {
5417 *fout++ = TTY_BREAK;
5419 ch->ch_err_parity++;
5420 *fout++ = TTY_PARITY;
5425 ch->pscan_state = 0;
5431 static void dgap_write_wakeup(struct board_t *bd, struct channel_t *ch,
5432 struct un_t *un, u32 mask,
5433 unsigned long *irq_flags1,
5434 unsigned long *irq_flags2)
5436 if (!(un->un_flags & mask))
5439 un->un_flags &= ~mask;
5441 if (!(un->un_flags & UN_ISOPEN))
5444 if ((un->un_tty->flags & (1 << TTY_DO_WRITE_WAKEUP)) &&
5445 un->un_tty->ldisc->ops->write_wakeup) {
5446 spin_unlock_irqrestore(&ch->ch_lock, *irq_flags2);
5447 spin_unlock_irqrestore(&bd->bd_lock, *irq_flags1);
5449 (un->un_tty->ldisc->ops->write_wakeup)(un->un_tty);
5451 spin_lock_irqsave(&bd->bd_lock, *irq_flags1);
5452 spin_lock_irqsave(&ch->ch_lock, *irq_flags2);
5454 wake_up_interruptible(&un->un_tty->write_wait);
5455 wake_up_interruptible(&un->un_flags_wait);
5458 /*=======================================================================
5460 * dgap_event - FEP to host event processing routine.
5462 * bd - Board of current event.
5464 *=======================================================================*/
5465 static int dgap_event(struct board_t *bd)
5467 struct channel_t *ch;
5470 struct bs_t __iomem *bs;
5473 struct ev_t __iomem *eaddr;
5481 if (!bd || bd->magic != DGAP_BOARD_MAGIC)
5484 spin_lock_irqsave(&bd->bd_lock, lock_flags);
5486 vaddr = bd->re_map_membase;
5489 spin_unlock_irqrestore(&bd->bd_lock, lock_flags);
5493 eaddr = (struct ev_t __iomem *) (vaddr + EVBUF);
5495 /* Get our head and tail */
5496 head = readw(&(eaddr->ev_head));
5497 tail = readw(&(eaddr->ev_tail));
5500 * Forget it if pointers out of range.
5503 if (head >= EVMAX - EVSTART || tail >= EVMAX - EVSTART ||
5504 (head | tail) & 03) {
5505 /* Let go of board lock */
5506 spin_unlock_irqrestore(&bd->bd_lock, lock_flags);
5511 * Loop to process all the events in the buffer.
5513 while (tail != head) {
5516 * Get interrupt information.
5519 event = bd->re_map_membase + tail + EVSTART;
5521 port = ioread8(event);
5522 reason = ioread8(event + 1);
5523 modem = ioread8(event + 2);
5524 b1 = ioread8(event + 3);
5527 * Make sure the interrupt is valid.
5529 if (port >= bd->nasync)
5532 if (!(reason & (IFMODEM | IFBREAK | IFTLW | IFTEM | IFDATA)))
5535 ch = bd->channels[port];
5537 if (!ch || ch->magic != DGAP_CHANNEL_MAGIC)
5541 * If we have made it here, the event was valid.
5542 * Lock down the channel.
5544 spin_lock_irqsave(&ch->ch_lock, lock_flags2);
5549 spin_unlock_irqrestore(&ch->ch_lock, lock_flags2);
5554 * Process received data.
5556 if (reason & IFDATA) {
5559 * ALL LOCKS *MUST* BE DROPPED BEFORE CALLING INPUT!
5560 * input could send some data to ld, which in turn
5561 * could do a callback to one of our other functions.
5563 spin_unlock_irqrestore(&ch->ch_lock, lock_flags2);
5564 spin_unlock_irqrestore(&bd->bd_lock, lock_flags);
5568 spin_lock_irqsave(&bd->bd_lock, lock_flags);
5569 spin_lock_irqsave(&ch->ch_lock, lock_flags2);
5571 if (ch->ch_flags & CH_RACTIVE)
5572 ch->ch_flags |= CH_RENABLE;
5574 writeb(1, &(bs->idata));
5576 if (ch->ch_flags & CH_RWAIT) {
5577 ch->ch_flags &= ~CH_RWAIT;
5579 wake_up_interruptible
5580 (&ch->ch_tun.un_flags_wait);
5585 * Process Modem change signals.
5587 if (reason & IFMODEM) {
5588 ch->ch_mistat = modem;
5595 if (reason & IFBREAK) {
5597 if (ch->ch_tun.un_tty) {
5598 /* A break has been indicated */
5600 tty_buffer_request_room
5601 (ch->ch_tun.un_tty->port, 1);
5602 tty_insert_flip_char(ch->ch_tun.un_tty->port,
5604 tty_flip_buffer_push(ch->ch_tun.un_tty->port);
5609 * Process Transmit low.
5611 if (reason & IFTLW) {
5612 dgap_write_wakeup(bd, ch, &ch->ch_tun, UN_LOW,
5613 &lock_flags, &lock_flags2);
5614 dgap_write_wakeup(bd, ch, &ch->ch_pun, UN_LOW,
5615 &lock_flags, &lock_flags2);
5616 if (ch->ch_flags & CH_WLOW) {
5617 ch->ch_flags &= ~CH_WLOW;
5618 wake_up_interruptible(&ch->ch_flags_wait);
5623 * Process Transmit empty.
5625 if (reason & IFTEM) {
5626 dgap_write_wakeup(bd, ch, &ch->ch_tun, UN_EMPTY,
5627 &lock_flags, &lock_flags2);
5628 dgap_write_wakeup(bd, ch, &ch->ch_pun, UN_EMPTY,
5629 &lock_flags, &lock_flags2);
5630 if (ch->ch_flags & CH_WEMPTY) {
5631 ch->ch_flags &= ~CH_WEMPTY;
5632 wake_up_interruptible(&ch->ch_flags_wait);
5636 spin_unlock_irqrestore(&ch->ch_lock, lock_flags2);
5639 tail = (tail + 4) & (EVMAX - EVSTART - 4);
5642 writew(tail, &(eaddr->ev_tail));
5643 spin_unlock_irqrestore(&bd->bd_lock, lock_flags);
5648 static ssize_t dgap_driver_version_show(struct device_driver *ddp, char *buf)
5650 return snprintf(buf, PAGE_SIZE, "%s\n", DG_PART);
5652 static DRIVER_ATTR(version, S_IRUSR, dgap_driver_version_show, NULL);
5655 static ssize_t dgap_driver_boards_show(struct device_driver *ddp, char *buf)
5657 return snprintf(buf, PAGE_SIZE, "%d\n", dgap_numboards);
5659 static DRIVER_ATTR(boards, S_IRUSR, dgap_driver_boards_show, NULL);
5662 static ssize_t dgap_driver_maxboards_show(struct device_driver *ddp, char *buf)
5664 return snprintf(buf, PAGE_SIZE, "%d\n", MAXBOARDS);
5666 static DRIVER_ATTR(maxboards, S_IRUSR, dgap_driver_maxboards_show, NULL);
5669 static ssize_t dgap_driver_pollcounter_show(struct device_driver *ddp,
5672 return snprintf(buf, PAGE_SIZE, "%ld\n", dgap_poll_counter);
5674 static DRIVER_ATTR(pollcounter, S_IRUSR, dgap_driver_pollcounter_show, NULL);
5676 static ssize_t dgap_driver_pollrate_show(struct device_driver *ddp, char *buf)
5678 return snprintf(buf, PAGE_SIZE, "%dms\n", dgap_poll_tick);
5681 static ssize_t dgap_driver_pollrate_store(struct device_driver *ddp,
5682 const char *buf, size_t count)
5684 if (sscanf(buf, "%d\n", &dgap_poll_tick) != 1)
5688 static DRIVER_ATTR(pollrate, (S_IRUSR | S_IWUSR), dgap_driver_pollrate_show,
5689 dgap_driver_pollrate_store);
5691 static int dgap_create_driver_sysfiles(struct pci_driver *dgap_driver)
5694 struct device_driver *driverfs = &dgap_driver->driver;
5696 rc |= driver_create_file(driverfs, &driver_attr_version);
5697 rc |= driver_create_file(driverfs, &driver_attr_boards);
5698 rc |= driver_create_file(driverfs, &driver_attr_maxboards);
5699 rc |= driver_create_file(driverfs, &driver_attr_pollrate);
5700 rc |= driver_create_file(driverfs, &driver_attr_pollcounter);
5705 static void dgap_remove_driver_sysfiles(struct pci_driver *dgap_driver)
5707 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;
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) {
6303 if (strstr(cptr->u.ttyname, "tty")) {
6304 ptr1 = cptr->u.ttyname;
6307 ptr1 = cptr->u.ttyname;
6309 for (i = 0; i < dgap_config_get_num_prts(bd); i++) {
6313 return snprintf(buf, PAGE_SIZE, "%s%s%02d\n",
6314 (un->un_type == DGAP_PRINT) ?
6320 if (cptr->type == CNODE) {
6322 for (i = 0; i < cptr->u.conc.nport; i++) {
6323 if (cn != (i + ncount))
6326 return snprintf(buf, PAGE_SIZE, "%s%s%02ld\n",
6327 (un->un_type == DGAP_PRINT) ?
6330 i + (cptr->u.conc.v_start ?
6331 cptr->u.conc.start : 1));
6334 ncount += cptr->u.conc.nport;
6337 if (cptr->type == MNODE) {
6339 for (i = 0; i < cptr->u.module.nport; i++) {
6340 if (cn != (i + ncount))
6343 return snprintf(buf, PAGE_SIZE, "%s%s%02ld\n",
6344 (un->un_type == DGAP_PRINT) ?
6347 i + (cptr->u.module.v_start ?
6348 cptr->u.module.start : 1));
6351 ncount += cptr->u.module.nport;
6356 return snprintf(buf, PAGE_SIZE, "%s_dgap_%d_%d\n",
6357 (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)
6403 struct cnode *p, *brd, *line, *conc;
6409 brd = line = conc = NULL;
6411 /* perhaps we are adding to an existing list? */
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 = kstrdup("No", GFP_KERNEL);
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 = kstrdup(s, GFP_KERNEL);
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 = kstrdup(s, GFP_KERNEL);
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 = kstrdup(s, GFP_KERNEL);
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 = kstrdup(s, GFP_KERNEL);
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 = kstrdup(s, GFP_KERNEL);
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 = kstrdup(s, GFP_KERNEL);
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 = kstrdup(s, GFP_KERNEL);
6681 if (p->type == CNODE) {
6682 p->u.conc.id = kstrdup(s, GFP_KERNEL);
6684 } else if (p->type == MNODE) {
6685 p->u.module.id = kstrdup(s, GFP_KERNEL);
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 = kstrdup(s, GFP_KERNEL);
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 = kstrdup(s, GFP_KERNEL);
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 = kstrdup(s, GFP_KERNEL);
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 = kstrdup(s, GFP_KERNEL);
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 = kstrdup(s, GFP_KERNEL);
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 = kzalloc(sizeof(struct cnode), GFP_KERNEL);
7256 * dgap_checknode: see if all the necessary info has been supplied for a node
7257 * before creating the next node.
7259 static int dgap_checknode(struct cnode *p)
7263 if (p->u.board.v_type == 0) {
7264 dgap_err("board type !not specified");
7271 if (p->u.line.v_speed == 0) {
7272 dgap_err("line speed not specified");
7278 if (p->u.conc.v_type == 0) {
7279 dgap_err("concentrator type not specified");
7282 if (p->u.conc.v_speed == 0) {
7283 dgap_err("concentrator line speed not specified");
7286 if (p->u.conc.v_nport == 0) {
7287 dgap_err("number of ports on concentrator not specified");
7290 if (p->u.conc.v_id == 0) {
7291 dgap_err("concentrator id letter not specified");
7297 if (p->u.module.v_type == 0) {
7298 dgap_err("EBI module type not specified");
7301 if (p->u.module.v_nport == 0) {
7302 dgap_err("number of ports on EBI module not specified");
7305 if (p->u.module.v_id == 0) {
7306 dgap_err("EBI module id letter not specified");
7315 * Given a board pointer, returns whether we should use interrupts or not.
7317 static uint dgap_config_get_useintr(struct board_t *bd)
7324 for (p = bd->bd_config; p; p = p->next) {
7325 if (p->type == INTRNODE) {
7327 * check for pcxr types.
7329 return p->u.useintr;
7333 /* If not found, then don't turn on interrupts. */
7338 * Given a board pointer, returns whether we turn on altpin or not.
7340 static uint dgap_config_get_altpin(struct board_t *bd)
7347 for (p = bd->bd_config; p; p = p->next) {
7348 if (p->type == ANODE) {
7350 * check for pcxr types.
7356 /* If not found, then don't turn on interrupts. */
7361 * Given a specific type of board, if found, detached link and
7362 * returns the first occurrence in the list.
7364 static struct cnode *dgap_find_config(int type, int bus, int slot)
7366 struct cnode *p, *prev, *prev2, *found;
7374 if (p->type != BNODE)
7377 if (p->u.board.type != type)
7380 if (p->u.board.v_pcibus &&
7381 p->u.board.pcibus != bus)
7384 if (p->u.board.v_pcislot &&
7385 p->u.board.pcislot != slot)
7390 * Keep walking thru the list till we
7391 * find the next board.
7397 if (p->type != BNODE)
7401 * Mark the end of our 1 board
7407 * Link the "next" board to the
7408 * previous board, effectively
7409 * "unlinking" our board from
7417 * It must be the last board in the list.
7426 * Given a board pointer, walks the config link, counting up
7427 * all ports user specified should be on the board.
7428 * (This does NOT mean they are all actually present right now tho)
7430 static uint dgap_config_get_num_prts(struct board_t *bd)
7438 for (p = bd->bd_config; p; p = p->next) {
7443 * check for pcxr types.
7445 if (p->u.board.type > EPCFE)
7446 count += p->u.board.nport;
7449 count += p->u.conc.nport;
7452 count += p->u.module.nport;
7459 static char *dgap_create_config_string(struct board_t *bd, char *string)
7471 for (p = bd->bd_config; p; p = p->next) {
7477 *ptr = p->u.line.speed;
7482 * Because the EPC/con concentrators can have EM modules
7483 * hanging off of them, we have to walk ahead in the
7484 * list and keep adding the number of ports on each EM
7485 * to the config. UGH!
7487 speed = p->u.conc.speed;
7489 if (q && (q->type == MNODE)) {
7490 *ptr = (p->u.conc.nport + 0x80);
7493 while (q->next && (q->next->type) == MNODE) {
7494 *ptr = (q->u.module.nport + 0x80);
7499 *ptr = q->u.module.nport;
7502 *ptr = p->u.conc.nport;