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 tty_struct *tty,
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 tty_struct *tty,
3193 struct digi_t __user *retinfo)
3195 struct channel_t *ch;
3203 if (!tty || tty->magic != TTY_MAGIC)
3206 un = tty->driver_data;
3207 if (!un || un->magic != DGAP_UNIT_MAGIC)
3211 if (!ch || ch->magic != DGAP_CHANNEL_MAGIC)
3214 memset(&tmp, 0, sizeof(tmp));
3216 spin_lock_irqsave(&ch->ch_lock, lock_flags);
3217 memcpy(&tmp, &ch->ch_digi, sizeof(tmp));
3218 spin_unlock_irqrestore(&ch->ch_lock, lock_flags);
3220 if (copy_to_user(retinfo, &tmp, sizeof(*retinfo)))
3227 * dgap_tty_digiseta()
3229 * Ioctl to set the information for ditty.
3234 static int dgap_tty_digiseta(struct channel_t *ch, struct board_t *bd,
3235 struct un_t *un, struct digi_t __user *new_info)
3237 struct digi_t new_digi;
3238 ulong lock_flags = 0;
3239 unsigned long lock_flags2;
3241 if (copy_from_user(&new_digi, new_info, sizeof(struct digi_t)))
3244 spin_lock_irqsave(&bd->bd_lock, lock_flags);
3245 spin_lock_irqsave(&ch->ch_lock, lock_flags2);
3247 memcpy(&ch->ch_digi, &new_digi, sizeof(struct digi_t));
3249 if (ch->ch_digi.digi_maxcps < 1)
3250 ch->ch_digi.digi_maxcps = 1;
3252 if (ch->ch_digi.digi_maxcps > 10000)
3253 ch->ch_digi.digi_maxcps = 10000;
3255 if (ch->ch_digi.digi_bufsize < 10)
3256 ch->ch_digi.digi_bufsize = 10;
3258 if (ch->ch_digi.digi_maxchar < 1)
3259 ch->ch_digi.digi_maxchar = 1;
3261 if (ch->ch_digi.digi_maxchar > ch->ch_digi.digi_bufsize)
3262 ch->ch_digi.digi_maxchar = ch->ch_digi.digi_bufsize;
3264 if (ch->ch_digi.digi_onlen > DIGI_PLEN)
3265 ch->ch_digi.digi_onlen = DIGI_PLEN;
3267 if (ch->ch_digi.digi_offlen > DIGI_PLEN)
3268 ch->ch_digi.digi_offlen = DIGI_PLEN;
3270 dgap_param(ch, bd, un->un_type);
3272 spin_unlock_irqrestore(&ch->ch_lock, lock_flags2);
3273 spin_unlock_irqrestore(&bd->bd_lock, lock_flags);
3279 * dgap_tty_digigetedelay()
3281 * Ioctl to get the current edelay setting.
3286 static int dgap_tty_digigetedelay(struct tty_struct *tty, int __user *retinfo)
3288 struct channel_t *ch;
3296 if (!tty || tty->magic != TTY_MAGIC)
3299 un = tty->driver_data;
3300 if (!un || un->magic != DGAP_UNIT_MAGIC)
3304 if (!ch || ch->magic != DGAP_CHANNEL_MAGIC)
3307 memset(&tmp, 0, sizeof(tmp));
3309 spin_lock_irqsave(&ch->ch_lock, lock_flags);
3310 tmp = readw(&(ch->ch_bs->edelay));
3311 spin_unlock_irqrestore(&ch->ch_lock, lock_flags);
3313 if (copy_to_user(retinfo, &tmp, sizeof(*retinfo)))
3320 * dgap_tty_digisetedelay()
3322 * Ioctl to set the EDELAY setting
3325 static int dgap_tty_digisetedelay(struct tty_struct *tty, int __user *new_info)
3328 struct channel_t *ch;
3334 if (!tty || tty->magic != TTY_MAGIC)
3337 un = tty->driver_data;
3338 if (!un || un->magic != DGAP_UNIT_MAGIC)
3342 if (!ch || ch->magic != DGAP_CHANNEL_MAGIC)
3346 if (!bd || bd->magic != DGAP_BOARD_MAGIC)
3349 if (copy_from_user(&new_digi, new_info, sizeof(int)))
3352 spin_lock_irqsave(&bd->bd_lock, lock_flags);
3353 spin_lock_irqsave(&ch->ch_lock, lock_flags2);
3355 writew((u16) new_digi, &(ch->ch_bs->edelay));
3357 dgap_param(ch, bd, un->un_type);
3359 spin_unlock_irqrestore(&ch->ch_lock, lock_flags2);
3360 spin_unlock_irqrestore(&bd->bd_lock, lock_flags);
3366 * dgap_tty_digigetcustombaud()
3368 * Ioctl to get the current custom baud rate setting.
3370 static int dgap_tty_digigetcustombaud(struct tty_struct *tty,
3371 int __user *retinfo)
3373 struct channel_t *ch;
3381 if (!tty || tty->magic != TTY_MAGIC)
3384 un = tty->driver_data;
3385 if (!un || un->magic != DGAP_UNIT_MAGIC)
3389 if (!ch || ch->magic != DGAP_CHANNEL_MAGIC)
3392 memset(&tmp, 0, sizeof(tmp));
3394 spin_lock_irqsave(&ch->ch_lock, lock_flags);
3395 tmp = dgap_get_custom_baud(ch);
3396 spin_unlock_irqrestore(&ch->ch_lock, lock_flags);
3398 if (copy_to_user(retinfo, &tmp, sizeof(*retinfo)))
3405 * dgap_tty_digisetcustombaud()
3407 * Ioctl to set the custom baud rate setting
3409 static int dgap_tty_digisetcustombaud(struct tty_struct *tty,
3410 int __user *new_info)
3413 struct channel_t *ch;
3419 if (!tty || tty->magic != TTY_MAGIC)
3422 un = tty->driver_data;
3423 if (!un || un->magic != DGAP_UNIT_MAGIC)
3427 if (!ch || ch->magic != DGAP_CHANNEL_MAGIC)
3431 if (!bd || bd->magic != DGAP_BOARD_MAGIC)
3435 if (copy_from_user(&new_rate, new_info, sizeof(unsigned int)))
3438 if (bd->bd_flags & BD_FEP5PLUS) {
3440 spin_lock_irqsave(&bd->bd_lock, lock_flags);
3441 spin_lock_irqsave(&ch->ch_lock, lock_flags2);
3443 ch->ch_custom_speed = new_rate;
3445 dgap_param(ch, bd, un->un_type);
3447 spin_unlock_irqrestore(&ch->ch_lock, lock_flags2);
3448 spin_unlock_irqrestore(&bd->bd_lock, lock_flags);
3455 * dgap_set_termios()
3457 static void dgap_tty_set_termios(struct tty_struct *tty,
3458 struct ktermios *old_termios)
3461 struct channel_t *ch;
3463 unsigned long lock_flags;
3464 unsigned long lock_flags2;
3466 if (!tty || tty->magic != TTY_MAGIC)
3469 un = tty->driver_data;
3470 if (!un || un->magic != DGAP_UNIT_MAGIC)
3474 if (!ch || ch->magic != DGAP_CHANNEL_MAGIC)
3478 if (!bd || bd->magic != DGAP_BOARD_MAGIC)
3481 spin_lock_irqsave(&bd->bd_lock, lock_flags);
3482 spin_lock_irqsave(&ch->ch_lock, lock_flags2);
3484 ch->ch_c_cflag = tty->termios.c_cflag;
3485 ch->ch_c_iflag = tty->termios.c_iflag;
3486 ch->ch_c_oflag = tty->termios.c_oflag;
3487 ch->ch_c_lflag = tty->termios.c_lflag;
3488 ch->ch_startc = tty->termios.c_cc[VSTART];
3489 ch->ch_stopc = tty->termios.c_cc[VSTOP];
3492 dgap_param(ch, bd, un->un_type);
3494 spin_unlock_irqrestore(&ch->ch_lock, lock_flags2);
3495 spin_unlock_irqrestore(&bd->bd_lock, lock_flags);
3498 static void dgap_tty_throttle(struct tty_struct *tty)
3501 struct channel_t *ch;
3506 if (!tty || tty->magic != TTY_MAGIC)
3509 un = tty->driver_data;
3510 if (!un || un->magic != DGAP_UNIT_MAGIC)
3514 if (!ch || ch->magic != DGAP_CHANNEL_MAGIC)
3518 if (!bd || bd->magic != DGAP_BOARD_MAGIC)
3521 spin_lock_irqsave(&bd->bd_lock, lock_flags);
3522 spin_lock_irqsave(&ch->ch_lock, lock_flags2);
3524 ch->ch_flags |= (CH_RXBLOCK);
3526 dgap_cmdw(ch, RPAUSE, 0, 0);
3529 spin_unlock_irqrestore(&ch->ch_lock, lock_flags2);
3530 spin_unlock_irqrestore(&bd->bd_lock, lock_flags);
3534 static void dgap_tty_unthrottle(struct tty_struct *tty)
3537 struct channel_t *ch;
3542 if (!tty || tty->magic != TTY_MAGIC)
3545 un = tty->driver_data;
3546 if (!un || un->magic != DGAP_UNIT_MAGIC)
3550 if (!ch || ch->magic != DGAP_CHANNEL_MAGIC)
3554 if (!bd || bd->magic != DGAP_BOARD_MAGIC)
3557 spin_lock_irqsave(&bd->bd_lock, lock_flags);
3558 spin_lock_irqsave(&ch->ch_lock, lock_flags2);
3560 ch->ch_flags &= ~(CH_RXBLOCK);
3563 dgap_cmdw(ch, RRESUME, 0, 0);
3566 spin_unlock_irqrestore(&ch->ch_lock, lock_flags2);
3567 spin_unlock_irqrestore(&bd->bd_lock, lock_flags);
3570 static void dgap_tty_start(struct tty_struct *tty)
3573 struct channel_t *ch;
3578 if (!tty || tty->magic != TTY_MAGIC)
3581 un = tty->driver_data;
3582 if (!un || un->magic != DGAP_UNIT_MAGIC)
3586 if (!ch || ch->magic != DGAP_CHANNEL_MAGIC)
3590 if (!bd || bd->magic != DGAP_BOARD_MAGIC)
3593 spin_lock_irqsave(&bd->bd_lock, lock_flags);
3594 spin_lock_irqsave(&ch->ch_lock, lock_flags2);
3596 dgap_cmdw(ch, RESUMETX, 0, 0);
3598 spin_unlock_irqrestore(&ch->ch_lock, lock_flags2);
3599 spin_unlock_irqrestore(&bd->bd_lock, lock_flags);
3602 static void dgap_tty_stop(struct tty_struct *tty)
3605 struct channel_t *ch;
3610 if (!tty || tty->magic != TTY_MAGIC)
3613 un = tty->driver_data;
3614 if (!un || un->magic != DGAP_UNIT_MAGIC)
3618 if (!ch || ch->magic != DGAP_CHANNEL_MAGIC)
3622 if (!bd || bd->magic != DGAP_BOARD_MAGIC)
3625 spin_lock_irqsave(&bd->bd_lock, lock_flags);
3626 spin_lock_irqsave(&ch->ch_lock, lock_flags2);
3628 dgap_cmdw(ch, PAUSETX, 0, 0);
3630 spin_unlock_irqrestore(&ch->ch_lock, lock_flags2);
3631 spin_unlock_irqrestore(&bd->bd_lock, lock_flags);
3635 * dgap_tty_flush_chars()
3637 * Flush the cook buffer
3639 * Note to self, and any other poor souls who venture here:
3641 * flush in this case DOES NOT mean dispose of the data.
3642 * instead, it means "stop buffering and send it if you
3643 * haven't already." Just guess how I figured that out... SRW 2-Jun-98
3645 * It is also always called in interrupt context - JAR 8-Sept-99
3647 static void dgap_tty_flush_chars(struct tty_struct *tty)
3650 struct channel_t *ch;
3655 if (!tty || tty->magic != TTY_MAGIC)
3658 un = tty->driver_data;
3659 if (!un || un->magic != DGAP_UNIT_MAGIC)
3663 if (!ch || ch->magic != DGAP_CHANNEL_MAGIC)
3667 if (!bd || bd->magic != DGAP_BOARD_MAGIC)
3670 spin_lock_irqsave(&bd->bd_lock, lock_flags);
3671 spin_lock_irqsave(&ch->ch_lock, lock_flags2);
3673 /* TODO: Do something here */
3675 spin_unlock_irqrestore(&ch->ch_lock, lock_flags2);
3676 spin_unlock_irqrestore(&bd->bd_lock, lock_flags);
3680 * dgap_tty_flush_buffer()
3682 * Flush Tx buffer (make in == out)
3684 static void dgap_tty_flush_buffer(struct tty_struct *tty)
3687 struct channel_t *ch;
3693 if (!tty || tty->magic != TTY_MAGIC)
3696 un = tty->driver_data;
3697 if (!un || un->magic != DGAP_UNIT_MAGIC)
3701 if (!ch || ch->magic != DGAP_CHANNEL_MAGIC)
3705 if (!bd || bd->magic != DGAP_BOARD_MAGIC)
3708 spin_lock_irqsave(&bd->bd_lock, lock_flags);
3709 spin_lock_irqsave(&ch->ch_lock, lock_flags2);
3711 ch->ch_flags &= ~CH_STOP;
3712 head = readw(&(ch->ch_bs->tx_head));
3713 dgap_cmdw(ch, FLUSHTX, (u16) head, 0);
3714 dgap_cmdw(ch, RESUMETX, 0, 0);
3715 if (ch->ch_tun.un_flags & (UN_LOW|UN_EMPTY)) {
3716 ch->ch_tun.un_flags &= ~(UN_LOW|UN_EMPTY);
3717 wake_up_interruptible(&ch->ch_tun.un_flags_wait);
3719 if (ch->ch_pun.un_flags & (UN_LOW|UN_EMPTY)) {
3720 ch->ch_pun.un_flags &= ~(UN_LOW|UN_EMPTY);
3721 wake_up_interruptible(&ch->ch_pun.un_flags_wait);
3724 spin_unlock_irqrestore(&ch->ch_lock, lock_flags2);
3725 spin_unlock_irqrestore(&bd->bd_lock, lock_flags);
3726 if (waitqueue_active(&tty->write_wait))
3727 wake_up_interruptible(&tty->write_wait);
3731 /*****************************************************************************
3733 * The IOCTL function and all of its helpers
3735 *****************************************************************************/
3740 * The usual assortment of ioctl's
3742 static int dgap_tty_ioctl(struct tty_struct *tty, unsigned int cmd,
3746 struct channel_t *ch;
3750 ulong lock_flags = 0;
3751 ulong lock_flags2 = 0;
3752 void __user *uarg = (void __user *) arg;
3754 if (!tty || tty->magic != TTY_MAGIC)
3757 un = tty->driver_data;
3758 if (!un || un->magic != DGAP_UNIT_MAGIC)
3762 if (!ch || ch->magic != DGAP_CHANNEL_MAGIC)
3766 if (!bd || bd->magic != DGAP_BOARD_MAGIC)
3769 spin_lock_irqsave(&bd->bd_lock, lock_flags);
3770 spin_lock_irqsave(&ch->ch_lock, lock_flags2);
3772 if (un->un_open_count <= 0) {
3773 spin_unlock_irqrestore(&ch->ch_lock, lock_flags2);
3774 spin_unlock_irqrestore(&bd->bd_lock, lock_flags);
3780 /* Here are all the standard ioctl's that we MUST implement */
3784 * TCSBRK is SVID version: non-zero arg --> no break
3785 * this behaviour is exploited by tcdrain().
3787 * According to POSIX.1 spec (7.2.2.1.2) breaks should be
3788 * between 0.25 and 0.5 seconds so we'll ask for something
3789 * in the middle: 0.375 seconds.
3791 rc = tty_check_change(tty);
3792 spin_unlock_irqrestore(&ch->ch_lock, lock_flags2);
3793 spin_unlock_irqrestore(&bd->bd_lock, lock_flags);
3797 rc = dgap_wait_for_drain(tty);
3802 spin_lock_irqsave(&bd->bd_lock, lock_flags);
3803 spin_lock_irqsave(&ch->ch_lock, lock_flags2);
3805 if (((cmd == TCSBRK) && (!arg)) || (cmd == TCSBRKP))
3806 dgap_cmdw(ch, SBREAK, (u16) SBREAK_TIME, 0);
3808 spin_unlock_irqrestore(&ch->ch_lock, lock_flags2);
3809 spin_unlock_irqrestore(&bd->bd_lock, lock_flags);
3814 /* support for POSIX tcsendbreak()
3816 * According to POSIX.1 spec (7.2.2.1.2) breaks should be
3817 * between 0.25 and 0.5 seconds so we'll ask for something
3818 * in the middle: 0.375 seconds.
3820 rc = tty_check_change(tty);
3821 spin_unlock_irqrestore(&ch->ch_lock, lock_flags2);
3822 spin_unlock_irqrestore(&bd->bd_lock, lock_flags);
3826 rc = dgap_wait_for_drain(tty);
3830 spin_lock_irqsave(&bd->bd_lock, lock_flags);
3831 spin_lock_irqsave(&ch->ch_lock, lock_flags2);
3833 dgap_cmdw(ch, SBREAK, (u16) SBREAK_TIME, 0);
3835 spin_unlock_irqrestore(&ch->ch_lock, lock_flags2);
3836 spin_unlock_irqrestore(&bd->bd_lock, lock_flags);
3842 * FEP5 doesn't support turning on a break unconditionally.
3843 * The FEP5 device will stop sending a break automatically
3844 * after the specified time value that was sent when turning on
3847 rc = tty_check_change(tty);
3848 spin_unlock_irqrestore(&ch->ch_lock, lock_flags2);
3849 spin_unlock_irqrestore(&bd->bd_lock, lock_flags);
3853 rc = dgap_wait_for_drain(tty);
3857 spin_lock_irqsave(&bd->bd_lock, lock_flags);
3858 spin_lock_irqsave(&ch->ch_lock, lock_flags2);
3860 dgap_cmdw(ch, SBREAK, (u16) SBREAK_TIME, 0);
3862 spin_unlock_irqrestore(&ch->ch_lock, lock_flags2);
3863 spin_unlock_irqrestore(&bd->bd_lock, lock_flags);
3869 * FEP5 doesn't support turning off a break unconditionally.
3870 * The FEP5 device will stop sending a break automatically
3871 * after the specified time value that was sent when turning on
3874 spin_unlock_irqrestore(&ch->ch_lock, lock_flags2);
3875 spin_unlock_irqrestore(&bd->bd_lock, lock_flags);
3880 spin_unlock_irqrestore(&ch->ch_lock, lock_flags2);
3881 spin_unlock_irqrestore(&bd->bd_lock, lock_flags);
3883 rc = put_user(C_CLOCAL(tty) ? 1 : 0,
3884 (unsigned long __user *) arg);
3888 spin_unlock_irqrestore(&ch->ch_lock, lock_flags2);
3889 spin_unlock_irqrestore(&bd->bd_lock, lock_flags);
3891 rc = get_user(arg, (unsigned long __user *) arg);
3895 spin_lock_irqsave(&bd->bd_lock, lock_flags);
3896 spin_lock_irqsave(&ch->ch_lock, lock_flags2);
3897 tty->termios.c_cflag = ((tty->termios.c_cflag & ~CLOCAL) |
3898 (arg ? CLOCAL : 0));
3899 dgap_param(ch, bd, un->un_type);
3900 spin_unlock_irqrestore(&ch->ch_lock, lock_flags2);
3901 spin_unlock_irqrestore(&bd->bd_lock, lock_flags);
3906 spin_unlock_irqrestore(&ch->ch_lock, lock_flags2);
3907 spin_unlock_irqrestore(&bd->bd_lock, lock_flags);
3908 return dgap_get_modem_info(ch, uarg);
3913 spin_unlock_irqrestore(&ch->ch_lock, lock_flags2);
3914 spin_unlock_irqrestore(&bd->bd_lock, lock_flags);
3915 return dgap_set_modem_info(tty, cmd, uarg);
3918 * Here are any additional ioctl's that we want to implement
3923 * The linux tty driver doesn't have a flush
3924 * input routine for the driver, assuming all backed
3925 * up data is in the line disc. buffers. However,
3926 * we all know that's not the case. Here, we
3927 * act on the ioctl, but then lie and say we didn't
3928 * so the line discipline will process the flush
3931 rc = tty_check_change(tty);
3933 spin_unlock_irqrestore(&ch->ch_lock, lock_flags2);
3934 spin_unlock_irqrestore(&bd->bd_lock, lock_flags);
3938 if ((arg == TCIFLUSH) || (arg == TCIOFLUSH)) {
3939 if (!(un->un_type == DGAP_PRINT)) {
3940 head = readw(&(ch->ch_bs->rx_head));
3941 writew(head, &(ch->ch_bs->rx_tail));
3942 writeb(0, &(ch->ch_bs->orun));
3946 if ((arg != TCOFLUSH) && (arg != TCIOFLUSH)) {
3947 /* pretend we didn't recognize this IOCTL */
3948 spin_unlock_irqrestore(&ch->ch_lock, lock_flags2);
3949 spin_unlock_irqrestore(&bd->bd_lock, lock_flags);
3951 return -ENOIOCTLCMD;
3954 ch->ch_flags &= ~CH_STOP;
3955 head = readw(&(ch->ch_bs->tx_head));
3956 dgap_cmdw(ch, FLUSHTX, (u16) head, 0);
3957 dgap_cmdw(ch, RESUMETX, 0, 0);
3958 if (ch->ch_tun.un_flags & (UN_LOW|UN_EMPTY)) {
3959 ch->ch_tun.un_flags &= ~(UN_LOW|UN_EMPTY);
3960 wake_up_interruptible(&ch->ch_tun.un_flags_wait);
3962 if (ch->ch_pun.un_flags & (UN_LOW|UN_EMPTY)) {
3963 ch->ch_pun.un_flags &= ~(UN_LOW|UN_EMPTY);
3964 wake_up_interruptible(&ch->ch_pun.un_flags_wait);
3966 if (waitqueue_active(&tty->write_wait))
3967 wake_up_interruptible(&tty->write_wait);
3969 /* Can't hold any locks when calling tty_wakeup! */
3970 spin_unlock_irqrestore(&ch->ch_lock, lock_flags2);
3971 spin_unlock_irqrestore(&bd->bd_lock, lock_flags);
3974 /* pretend we didn't recognize this IOCTL */
3975 return -ENOIOCTLCMD;
3980 * The linux tty driver doesn't have a flush
3981 * input routine for the driver, assuming all backed
3982 * up data is in the line disc. buffers. However,
3983 * we all know that's not the case. Here, we
3984 * act on the ioctl, but then lie and say we didn't
3985 * so the line discipline will process the flush
3988 if (cmd == TCSETSF) {
3990 ch->ch_flags &= ~CH_STOP;
3991 head = readw(&(ch->ch_bs->rx_head));
3992 writew(head, &(ch->ch_bs->rx_tail));
3995 /* now wait for all the output to drain */
3996 spin_unlock_irqrestore(&ch->ch_lock, lock_flags2);
3997 spin_unlock_irqrestore(&bd->bd_lock, lock_flags);
3998 rc = dgap_wait_for_drain(tty);
4002 /* pretend we didn't recognize this */
4003 return -ENOIOCTLCMD;
4007 spin_unlock_irqrestore(&ch->ch_lock, lock_flags2);
4008 spin_unlock_irqrestore(&bd->bd_lock, lock_flags);
4009 rc = dgap_wait_for_drain(tty);
4013 /* pretend we didn't recognize this */
4014 return -ENOIOCTLCMD;
4018 * The Linux Line Discipline (LD) would do this for us if we
4019 * let it, but we have the special firmware options to do this
4020 * the "right way" regardless of hardware or software flow
4021 * control so we'll do it outselves instead of letting the LD
4024 rc = tty_check_change(tty);
4026 spin_unlock_irqrestore(&ch->ch_lock, lock_flags2);
4027 spin_unlock_irqrestore(&bd->bd_lock, lock_flags);
4034 spin_unlock_irqrestore(&ch->ch_lock, lock_flags2);
4035 spin_unlock_irqrestore(&bd->bd_lock, lock_flags);
4036 dgap_tty_start(tty);
4039 spin_unlock_irqrestore(&ch->ch_lock, lock_flags2);
4040 spin_unlock_irqrestore(&bd->bd_lock, lock_flags);
4044 spin_unlock_irqrestore(&ch->ch_lock, lock_flags2);
4045 spin_unlock_irqrestore(&bd->bd_lock, lock_flags);
4046 /* Make the ld do it */
4047 return -ENOIOCTLCMD;
4049 spin_unlock_irqrestore(&ch->ch_lock, lock_flags2);
4050 spin_unlock_irqrestore(&bd->bd_lock, lock_flags);
4051 /* Make the ld do it */
4052 return -ENOIOCTLCMD;
4054 spin_unlock_irqrestore(&ch->ch_lock, lock_flags2);
4055 spin_unlock_irqrestore(&bd->bd_lock, lock_flags);
4060 /* get information for ditty */
4061 spin_unlock_irqrestore(&ch->ch_lock, lock_flags2);
4062 spin_unlock_irqrestore(&bd->bd_lock, lock_flags);
4063 return dgap_tty_digigeta(tty, uarg);
4068 /* set information for ditty */
4069 if (cmd == (DIGI_SETAW)) {
4071 spin_unlock_irqrestore(&ch->ch_lock, lock_flags2);
4072 spin_unlock_irqrestore(&bd->bd_lock, lock_flags);
4073 rc = dgap_wait_for_drain(tty);
4076 spin_lock_irqsave(&bd->bd_lock, lock_flags);
4077 spin_lock_irqsave(&ch->ch_lock, lock_flags2);
4079 tty_ldisc_flush(tty);
4083 spin_unlock_irqrestore(&ch->ch_lock, lock_flags2);
4084 spin_unlock_irqrestore(&bd->bd_lock, lock_flags);
4085 return dgap_tty_digiseta(ch, bd, un, uarg);
4088 spin_unlock_irqrestore(&ch->ch_lock, lock_flags2);
4089 spin_unlock_irqrestore(&bd->bd_lock, lock_flags);
4090 return dgap_tty_digigetedelay(tty, uarg);
4093 spin_unlock_irqrestore(&ch->ch_lock, lock_flags2);
4094 spin_unlock_irqrestore(&bd->bd_lock, lock_flags);
4095 return dgap_tty_digisetedelay(tty, uarg);
4097 case DIGI_GETCUSTOMBAUD:
4098 spin_unlock_irqrestore(&ch->ch_lock, lock_flags2);
4099 spin_unlock_irqrestore(&bd->bd_lock, lock_flags);
4100 return dgap_tty_digigetcustombaud(tty, uarg);
4102 case DIGI_SETCUSTOMBAUD:
4103 spin_unlock_irqrestore(&ch->ch_lock, lock_flags2);
4104 spin_unlock_irqrestore(&bd->bd_lock, lock_flags);
4105 return dgap_tty_digisetcustombaud(tty, uarg);
4107 case DIGI_RESET_PORT:
4108 dgap_firmware_reset_port(ch);
4109 dgap_param(ch, bd, un->un_type);
4110 spin_unlock_irqrestore(&ch->ch_lock, lock_flags2);
4111 spin_unlock_irqrestore(&bd->bd_lock, lock_flags);
4115 spin_unlock_irqrestore(&ch->ch_lock, lock_flags2);
4116 spin_unlock_irqrestore(&bd->bd_lock, lock_flags);
4118 return -ENOIOCTLCMD;
4122 static int dgap_alloc_flipbuf(struct board_t *brd)
4125 * allocate flip buffer for board.
4127 brd->flipbuf = kmalloc(MYFLIPLEN, GFP_KERNEL);
4131 brd->flipflagbuf = kmalloc(MYFLIPLEN, GFP_KERNEL);
4132 if (!brd->flipflagbuf) {
4133 kfree(brd->flipbuf);
4140 static void dgap_free_flipbuf(struct board_t *brd)
4142 kfree(brd->flipbuf);
4143 kfree(brd->flipflagbuf);
4147 * Create pr and tty device entries
4149 static int dgap_tty_register_ports(struct board_t *brd)
4151 struct channel_t *ch;
4155 brd->serial_ports = kcalloc(brd->nasync, sizeof(*brd->serial_ports),
4157 if (!brd->serial_ports)
4160 brd->printer_ports = kcalloc(brd->nasync, sizeof(*brd->printer_ports),
4162 if (!brd->printer_ports) {
4164 goto free_serial_ports;
4167 for (i = 0; i < brd->nasync; i++) {
4168 tty_port_init(&brd->serial_ports[i]);
4169 tty_port_init(&brd->printer_ports[i]);
4172 ch = brd->channels[0];
4173 for (i = 0; i < brd->nasync; i++, ch = brd->channels[i]) {
4175 struct device *classp;
4177 classp = tty_port_register_device(&brd->serial_ports[i],
4181 if (IS_ERR(classp)) {
4182 ret = PTR_ERR(classp);
4183 goto unregister_ttys;
4186 dgap_create_tty_sysfs(&ch->ch_tun, classp);
4187 ch->ch_tun.un_sysfs = classp;
4189 classp = tty_port_register_device(&brd->printer_ports[i],
4193 if (IS_ERR(classp)) {
4194 ret = PTR_ERR(classp);
4195 goto unregister_ttys;
4198 dgap_create_tty_sysfs(&ch->ch_pun, classp);
4199 ch->ch_pun.un_sysfs = classp;
4201 dgap_create_ports_sysfiles(brd);
4207 ch = brd->channels[i];
4208 if (ch->ch_tun.un_sysfs) {
4209 dgap_remove_tty_sysfs(ch->ch_tun.un_sysfs);
4210 tty_unregister_device(brd->serial_driver, i);
4213 if (ch->ch_pun.un_sysfs) {
4214 dgap_remove_tty_sysfs(ch->ch_pun.un_sysfs);
4215 tty_unregister_device(brd->print_driver, i);
4220 for (i = 0; i < brd->nasync; i++) {
4221 tty_port_destroy(&brd->serial_ports[i]);
4222 tty_port_destroy(&brd->printer_ports[i]);
4225 kfree(brd->printer_ports);
4226 brd->printer_ports = NULL;
4229 kfree(brd->serial_ports);
4230 brd->serial_ports = NULL;
4236 * Copies the BIOS code from the user to the board,
4237 * and starts the BIOS running.
4239 static void dgap_do_bios_load(struct board_t *brd, const u8 *ubios, int len)
4245 if (!brd || (brd->magic != DGAP_BOARD_MAGIC) || !brd->re_map_membase)
4248 addr = brd->re_map_membase;
4253 for (i = 0; i < 16; i++)
4254 writeb(0, addr + POSTAREA + i);
4260 memcpy_toio(addr + offset, ubios, len);
4262 writel(0x0bf00401, addr);
4263 writel(0, (addr + 4));
4265 /* Clear the reset, and change states. */
4266 writeb(FEPCLR, brd->re_map_port);
4270 * Checks to see if the BIOS completed running on the card.
4272 static int dgap_test_bios(struct board_t *brd)
4279 if (!brd || (brd->magic != DGAP_BOARD_MAGIC) || !brd->re_map_membase)
4282 addr = brd->re_map_membase;
4283 word = readw(addr + POSTAREA);
4286 * It can take 5-6 seconds for a board to
4287 * pass the bios self test and post results.
4288 * Give it 10 seconds.
4290 brd->wait_for_bios = 0;
4291 while (brd->wait_for_bios < 1000) {
4292 /* Check to see if BIOS thinks board is good. (GD). */
4293 if (word == *(u16 *) "GD")
4295 msleep_interruptible(10);
4296 brd->wait_for_bios++;
4297 word = readw(addr + POSTAREA);
4300 /* Gave up on board after too long of time taken */
4301 err1 = readw(addr + SEQUENCE);
4302 err2 = readw(addr + ERROR);
4303 pr_warn("dgap: %s failed diagnostics. Error #(%x,%x).\n",
4304 brd->name, err1, err2);
4305 brd->state = BOARD_FAILED;
4306 brd->dpastatus = BD_NOBIOS;
4312 * Copies the FEP code from the user to the board,
4313 * and starts the FEP running.
4315 static void dgap_do_fep_load(struct board_t *brd, const u8 *ufep, int len)
4320 if (!brd || (brd->magic != DGAP_BOARD_MAGIC) || !brd->re_map_membase)
4323 addr = brd->re_map_membase;
4329 memcpy_toio(addr + offset, ufep, len);
4332 * If board is a concentrator product, we need to give
4333 * it its config string describing how the concentrators look.
4335 if ((brd->type == PCX) || (brd->type == PEPC)) {
4341 xconfig = dgap_create_config_string(brd, string);
4343 /* Write string to board memory */
4344 config = addr + CONFIG;
4345 for (; i < CONFIGSIZE; i++, config++, xconfig++) {
4346 writeb(*xconfig, config);
4347 if ((*xconfig & 0xff) == 0xff)
4352 writel(0xbfc01004, (addr + 0xc34));
4353 writel(0x3, (addr + 0xc30));
4358 * Waits for the FEP to report thats its ready for us to use.
4360 static int dgap_test_fep(struct board_t *brd)
4367 if (!brd || (brd->magic != DGAP_BOARD_MAGIC) || !brd->re_map_membase)
4370 addr = brd->re_map_membase;
4371 word = readw(addr + FEPSTAT);
4374 * It can take 2-3 seconds for the FEP to
4375 * be up and running. Give it 5 secs.
4377 brd->wait_for_fep = 0;
4378 while (brd->wait_for_fep < 500) {
4379 /* Check to see if FEP is up and running now. */
4380 if (word == *(u16 *) "OS") {
4382 * Check to see if the board can support FEP5+ commands.
4384 word = readw(addr + FEP5_PLUS);
4385 if (word == *(u16 *) "5A")
4386 brd->bd_flags |= BD_FEP5PLUS;
4390 msleep_interruptible(10);
4391 brd->wait_for_fep++;
4392 word = readw(addr + FEPSTAT);
4395 /* Gave up on board after too long of time taken */
4396 err1 = readw(addr + SEQUENCE);
4397 err2 = readw(addr + ERROR);
4398 pr_warn("dgap: FEPOS for %s not functioning. Error #(%x,%x).\n",
4399 brd->name, err1, err2);
4400 brd->state = BOARD_FAILED;
4401 brd->dpastatus = BD_NOFEP;
4407 * Physically forces the FEP5 card to reset itself.
4409 static void dgap_do_reset_board(struct board_t *brd)
4416 if (!brd || (brd->magic != DGAP_BOARD_MAGIC) ||
4417 !brd->re_map_membase || !brd->re_map_port)
4420 /* FEPRST does not vary among supported boards */
4421 writeb(FEPRST, brd->re_map_port);
4423 for (i = 0; i <= 1000; i++) {
4424 check = readb(brd->re_map_port) & 0xe;
4425 if (check == FEPRST)
4431 pr_warn("dgap: Board not resetting... Failing board.\n");
4432 brd->state = BOARD_FAILED;
4433 brd->dpastatus = BD_NOFEP;
4438 * Make sure there really is memory out there.
4440 writel(0xa55a3cc3, (brd->re_map_membase + LOWMEM));
4441 writel(0x5aa5c33c, (brd->re_map_membase + HIGHMEM));
4442 check1 = readl(brd->re_map_membase + LOWMEM);
4443 check2 = readl(brd->re_map_membase + HIGHMEM);
4445 if ((check1 != 0xa55a3cc3) || (check2 != 0x5aa5c33c)) {
4446 pr_warn("dgap: No memory at %p for board.\n",
4447 brd->re_map_membase);
4448 brd->state = BOARD_FAILED;
4449 brd->dpastatus = BD_NOFEP;
4454 #ifdef DIGI_CONCENTRATORS_SUPPORTED
4456 * Sends a concentrator image into the FEP5 board.
4458 static void dgap_do_conc_load(struct board_t *brd, u8 *uaddr, int len)
4460 char __iomem *vaddr;
4462 struct downld_t *to_dp;
4464 if (!brd || (brd->magic != DGAP_BOARD_MAGIC) || !brd->re_map_membase)
4467 vaddr = brd->re_map_membase;
4469 offset = readw((u16 *) (vaddr + DOWNREQ));
4470 to_dp = (struct downld_t *) (vaddr + (int) offset);
4471 memcpy_toio(to_dp, uaddr, len);
4473 /* Tell card we have data for it */
4474 writew(0, vaddr + (DOWNREQ));
4476 brd->conc_dl_status = NO_PENDING_CONCENTRATOR_REQUESTS;
4480 #define EXPANSION_ROM_SIZE (64 * 1024)
4481 #define FEP5_ROM_MAGIC (0xFEFFFFFF)
4483 static void dgap_get_vpd(struct board_t *brd)
4495 * Poke the magic number at the PCI Rom Address location.
4496 * If VPD is supported, the value read from that address
4499 magic = FEP5_ROM_MAGIC;
4500 pci_write_config_dword(brd->pdev, PCI_ROM_ADDRESS, magic);
4501 pci_read_config_dword(brd->pdev, PCI_ROM_ADDRESS, &magic);
4503 /* VPD not supported, bail */
4508 * To get to the OTPROM memory, we have to send the boards base
4509 * address or'ed with 1 into the PCI Rom Address location.
4511 magic = brd->membase | 0x01;
4512 pci_write_config_dword(brd->pdev, PCI_ROM_ADDRESS, magic);
4513 pci_read_config_dword(brd->pdev, PCI_ROM_ADDRESS, &magic);
4515 byte1 = readb(brd->re_map_membase);
4516 byte2 = readb(brd->re_map_membase + 1);
4519 * If the board correctly swapped to the OTPROM memory,
4520 * the first 2 bytes (header) should be 0x55, 0xAA
4522 if (byte1 == 0x55 && byte2 == 0xAA) {
4527 * We have to run through all the OTPROM memory looking
4528 * for the VPD offset.
4530 while (base_offset <= EXPANSION_ROM_SIZE) {
4533 * Lots of magic numbers here.
4535 * The VPD offset is located inside the ROM Data
4538 * We also have to remember the length of each
4539 * ROM Data Structure, so we can "hop" to the next
4540 * entry if the VPD isn't in the current
4541 * ROM Data Structure.
4543 rom_offset = readw(brd->re_map_membase +
4544 base_offset + 0x18);
4545 image_length = readw(brd->re_map_membase +
4546 rom_offset + 0x10) * 512;
4547 vpd_offset = readw(brd->re_map_membase +
4550 /* Found the VPD entry */
4554 /* We didn't find a VPD entry, go to next ROM entry. */
4555 base_offset += image_length;
4557 byte1 = readb(brd->re_map_membase + base_offset);
4558 byte2 = readb(brd->re_map_membase + base_offset + 1);
4561 * If the new ROM offset doesn't have 0x55, 0xAA
4562 * as its header, we have run out of ROM.
4564 if (byte1 != 0x55 || byte2 != 0xAA)
4569 * If we have a VPD offset, then mark the board
4570 * as having a valid VPD, and copy VPDSIZE (512) bytes of
4571 * that VPD to the buffer we have in our board structure.
4574 brd->bd_flags |= BD_HAS_VPD;
4575 for (i = 0; i < VPDSIZE; i++) {
4576 brd->vpd[i] = readb(brd->re_map_membase +
4583 * We MUST poke the magic number at the PCI Rom Address location again.
4584 * This makes the card report the regular board memory back to us,
4585 * rather than the OTPROM memory.
4587 magic = FEP5_ROM_MAGIC;
4588 pci_write_config_dword(brd->pdev, PCI_ROM_ADDRESS, magic);
4592 * Our board poller function.
4594 static void dgap_poll_tasklet(unsigned long data)
4596 struct board_t *bd = (struct board_t *) data;
4598 char __iomem *vaddr;
4601 if (!bd || (bd->magic != DGAP_BOARD_MAGIC))
4604 if (bd->inhibit_poller)
4607 spin_lock_irqsave(&bd->bd_lock, lock_flags);
4609 vaddr = bd->re_map_membase;
4612 * If board is ready, parse deeper to see if there is anything to do.
4614 if (bd->state == BOARD_READY) {
4616 struct ev_t __iomem *eaddr;
4618 if (!bd->re_map_membase) {
4619 spin_unlock_irqrestore(&bd->bd_lock, lock_flags);
4622 if (!bd->re_map_port) {
4623 spin_unlock_irqrestore(&bd->bd_lock, lock_flags);
4630 eaddr = (struct ev_t __iomem *) (vaddr + EVBUF);
4632 /* Get our head and tail */
4633 head = readw(&(eaddr->ev_head));
4634 tail = readw(&(eaddr->ev_tail));
4637 * If there is an event pending. Go service it.
4640 spin_unlock_irqrestore(&bd->bd_lock, lock_flags);
4642 spin_lock_irqsave(&bd->bd_lock, lock_flags);
4647 * If board is doing interrupts, ACK the interrupt.
4649 if (bd && bd->intr_running)
4650 readb(bd->re_map_port + 2);
4652 spin_unlock_irqrestore(&bd->bd_lock, lock_flags);
4656 spin_unlock_irqrestore(&bd->bd_lock, lock_flags);
4659 /*=======================================================================
4661 * dgap_cmdb - Sends a 2 byte command to the FEP.
4663 * ch - Pointer to channel structure.
4664 * cmd - Command to be sent.
4665 * byte1 - Integer containing first byte to be sent.
4666 * byte2 - Integer containing second byte to be sent.
4667 * ncmds - Wait until ncmds or fewer cmds are left
4668 * in the cmd buffer before returning.
4670 *=======================================================================*/
4671 static void dgap_cmdb(struct channel_t *ch, u8 cmd, u8 byte1,
4672 u8 byte2, uint ncmds)
4674 char __iomem *vaddr;
4675 struct __iomem cm_t *cm_addr;
4681 if (!ch || ch->magic != DGAP_CHANNEL_MAGIC)
4685 * Check if board is still alive.
4687 if (ch->ch_bd->state == BOARD_FAILED)
4691 * Make sure the pointers are in range before
4692 * writing to the FEP memory.
4694 vaddr = ch->ch_bd->re_map_membase;
4699 cm_addr = (struct cm_t __iomem *) (vaddr + CMDBUF);
4700 head = readw(&(cm_addr->cm_head));
4703 * Forget it if pointers out of range.
4705 if (head >= (CMDMAX - CMDSTART) || (head & 03)) {
4706 ch->ch_bd->state = BOARD_FAILED;
4711 * Put the data in the circular command buffer.
4713 writeb(cmd, (vaddr + head + CMDSTART + 0));
4714 writeb((u8) ch->ch_portnum, (vaddr + head + CMDSTART + 1));
4715 writeb(byte1, (vaddr + head + CMDSTART + 2));
4716 writeb(byte2, (vaddr + head + CMDSTART + 3));
4718 head = (head + 4) & (CMDMAX - CMDSTART - 4);
4720 writew(head, &(cm_addr->cm_head));
4723 * Wait if necessary before updating the head
4724 * pointer to limit the number of outstanding
4725 * commands to the FEP. If the time spent waiting
4726 * is outlandish, declare the FEP dead.
4728 for (count = dgap_count ;;) {
4730 head = readw(&(cm_addr->cm_head));
4731 tail = readw(&(cm_addr->cm_tail));
4733 n = (head - tail) & (CMDMAX - CMDSTART - 4);
4735 if (n <= ncmds * sizeof(struct cm_t))
4739 ch->ch_bd->state = BOARD_FAILED;
4746 /*=======================================================================
4748 * dgap_cmdw - Sends a 1 word command to the FEP.
4750 * ch - Pointer to channel structure.
4751 * cmd - Command to be sent.
4752 * word - Integer containing word to be sent.
4753 * ncmds - Wait until ncmds or fewer cmds are left
4754 * in the cmd buffer before returning.
4756 *=======================================================================*/
4757 static void dgap_cmdw(struct channel_t *ch, u8 cmd, u16 word, uint ncmds)
4759 char __iomem *vaddr;
4760 struct __iomem cm_t *cm_addr;
4766 if (!ch || ch->magic != DGAP_CHANNEL_MAGIC)
4770 * Check if board is still alive.
4772 if (ch->ch_bd->state == BOARD_FAILED)
4776 * Make sure the pointers are in range before
4777 * writing to the FEP memory.
4779 vaddr = ch->ch_bd->re_map_membase;
4783 cm_addr = (struct cm_t __iomem *) (vaddr + CMDBUF);
4784 head = readw(&(cm_addr->cm_head));
4787 * Forget it if pointers out of range.
4789 if (head >= (CMDMAX - CMDSTART) || (head & 03)) {
4790 ch->ch_bd->state = BOARD_FAILED;
4795 * Put the data in the circular command buffer.
4797 writeb(cmd, (vaddr + head + CMDSTART + 0));
4798 writeb((u8) ch->ch_portnum, (vaddr + head + CMDSTART + 1));
4799 writew((u16) word, (vaddr + head + CMDSTART + 2));
4801 head = (head + 4) & (CMDMAX - CMDSTART - 4);
4803 writew(head, &(cm_addr->cm_head));
4806 * Wait if necessary before updating the head
4807 * pointer to limit the number of outstanding
4808 * commands to the FEP. If the time spent waiting
4809 * is outlandish, declare the FEP dead.
4811 for (count = dgap_count ;;) {
4813 head = readw(&(cm_addr->cm_head));
4814 tail = readw(&(cm_addr->cm_tail));
4816 n = (head - tail) & (CMDMAX - CMDSTART - 4);
4818 if (n <= ncmds * sizeof(struct cm_t))
4822 ch->ch_bd->state = BOARD_FAILED;
4829 /*=======================================================================
4831 * dgap_cmdw_ext - Sends a extended word command to the FEP.
4833 * ch - Pointer to channel structure.
4834 * cmd - Command to be sent.
4835 * word - Integer containing word to be sent.
4836 * ncmds - Wait until ncmds or fewer cmds are left
4837 * in the cmd buffer before returning.
4839 *=======================================================================*/
4840 static void dgap_cmdw_ext(struct channel_t *ch, u16 cmd, u16 word, uint ncmds)
4842 char __iomem *vaddr;
4843 struct __iomem cm_t *cm_addr;
4849 if (!ch || ch->magic != DGAP_CHANNEL_MAGIC)
4853 * Check if board is still alive.
4855 if (ch->ch_bd->state == BOARD_FAILED)
4859 * Make sure the pointers are in range before
4860 * writing to the FEP memory.
4862 vaddr = ch->ch_bd->re_map_membase;
4866 cm_addr = (struct cm_t __iomem *) (vaddr + CMDBUF);
4867 head = readw(&(cm_addr->cm_head));
4870 * Forget it if pointers out of range.
4872 if (head >= (CMDMAX - CMDSTART) || (head & 03)) {
4873 ch->ch_bd->state = BOARD_FAILED;
4878 * Put the data in the circular command buffer.
4881 /* Write an FF to tell the FEP that we want an extended command */
4882 writeb((u8) 0xff, (vaddr + head + CMDSTART + 0));
4884 writeb((u8) ch->ch_portnum, (vaddr + head + CMDSTART + 1));
4885 writew((u16) cmd, (vaddr + head + CMDSTART + 2));
4888 * If the second part of the command won't fit,
4889 * put it at the beginning of the circular buffer.
4891 if (((head + 4) >= ((CMDMAX - CMDSTART)) || (head & 03)))
4892 writew((u16) word, (vaddr + CMDSTART));
4894 writew((u16) word, (vaddr + head + CMDSTART + 4));
4896 head = (head + 8) & (CMDMAX - CMDSTART - 4);
4898 writew(head, &(cm_addr->cm_head));
4901 * Wait if necessary before updating the head
4902 * pointer to limit the number of outstanding
4903 * commands to the FEP. If the time spent waiting
4904 * is outlandish, declare the FEP dead.
4906 for (count = dgap_count ;;) {
4908 head = readw(&(cm_addr->cm_head));
4909 tail = readw(&(cm_addr->cm_tail));
4911 n = (head - tail) & (CMDMAX - CMDSTART - 4);
4913 if (n <= ncmds * sizeof(struct cm_t))
4917 ch->ch_bd->state = BOARD_FAILED;
4924 /*=======================================================================
4926 * dgap_wmove - Write data to FEP buffer.
4928 * ch - Pointer to channel structure.
4929 * buf - Poiter to characters to be moved.
4930 * cnt - Number of characters to move.
4932 *=======================================================================*/
4933 static void dgap_wmove(struct channel_t *ch, char *buf, uint cnt)
4936 char __iomem *taddr;
4937 struct bs_t __iomem *bs;
4940 if (!ch || ch->magic != DGAP_CHANNEL_MAGIC)
4947 head = readw(&(bs->tx_head));
4950 * If pointers are out of range, just return.
4952 if ((cnt > ch->ch_tsize) ||
4953 (unsigned)(head - ch->ch_tstart) >= ch->ch_tsize)
4957 * If the write wraps over the top of the circular buffer,
4958 * move the portion up to the wrap point, and reset the
4959 * pointers to the bottom.
4961 n = ch->ch_tstart + ch->ch_tsize - head;
4965 taddr = ch->ch_taddr + head;
4966 memcpy_toio(taddr, buf, n);
4967 head = ch->ch_tstart;
4972 * Move rest of data.
4974 taddr = ch->ch_taddr + head;
4976 memcpy_toio(taddr, buf, n);
4979 writew(head, &(bs->tx_head));
4983 * Retrives the current custom baud rate from FEP memory,
4984 * and returns it back to the user.
4985 * Returns 0 on error.
4987 static uint dgap_get_custom_baud(struct channel_t *ch)
4993 if (!ch || ch->magic != DGAP_CHANNEL_MAGIC)
4996 if (!ch->ch_bd || ch->ch_bd->magic != DGAP_BOARD_MAGIC)
4999 if (!(ch->ch_bd->bd_flags & BD_FEP5PLUS))
5002 vaddr = ch->ch_bd->re_map_membase;
5008 * Go get from fep mem, what the fep
5009 * believes the custom baud rate is.
5011 offset = (ioread16(vaddr + ECS_SEG) << 4) + (ch->ch_portnum * 0x28)
5014 value = readw(vaddr + offset);
5019 * Calls the firmware to reset this channel.
5021 static void dgap_firmware_reset_port(struct channel_t *ch)
5023 dgap_cmdb(ch, CHRESET, 0, 0, 0);
5026 * Now that the channel is reset, we need to make sure
5027 * all the current settings get reapplied to the port
5030 * So we will set the driver's cache of firmware
5031 * settings all to 0, and then call param.
5033 ch->ch_fepiflag = 0;
5034 ch->ch_fepcflag = 0;
5035 ch->ch_fepoflag = 0;
5036 ch->ch_fepstartc = 0;
5037 ch->ch_fepstopc = 0;
5038 ch->ch_fepastartc = 0;
5039 ch->ch_fepastopc = 0;
5044 /*=======================================================================
5046 * dgap_param - Set Digi parameters.
5048 * struct tty_struct * - TTY for port.
5050 *=======================================================================*/
5051 static int dgap_param(struct channel_t *ch, struct board_t *bd, u32 un_type)
5060 * If baud rate is zero, flush queues, and set mval to drop DTR.
5062 if ((ch->ch_c_cflag & (CBAUD)) == 0) {
5065 head = readw(&(ch->ch_bs->rx_head));
5066 writew(head, &(ch->ch_bs->rx_tail));
5069 head = readw(&(ch->ch_bs->tx_head));
5070 writew(head, &(ch->ch_bs->tx_tail));
5072 ch->ch_flags |= (CH_BAUD0);
5074 /* Drop RTS and DTR */
5075 ch->ch_mval &= ~(D_RTS(ch)|D_DTR(ch));
5076 mval = D_DTR(ch) | D_RTS(ch);
5077 ch->ch_baud_info = 0;
5079 } else if (ch->ch_custom_speed && (bd->bd_flags & BD_FEP5PLUS)) {
5081 * Tell the fep to do the command
5084 dgap_cmdw_ext(ch, 0xff01, ch->ch_custom_speed, 0);
5087 * Now go get from fep mem, what the fep
5088 * believes the custom baud rate is.
5090 ch->ch_custom_speed = dgap_get_custom_baud(ch);
5091 ch->ch_baud_info = ch->ch_custom_speed;
5093 /* Handle transition from B0 */
5094 if (ch->ch_flags & CH_BAUD0) {
5095 ch->ch_flags &= ~(CH_BAUD0);
5096 ch->ch_mval |= (D_RTS(ch)|D_DTR(ch));
5098 mval = D_DTR(ch) | D_RTS(ch);
5102 * Set baud rate, character size, and parity.
5110 ulong bauds[4][16] = {
5114 600, 1200, 1800, 2400,
5115 4800, 9600, 19200, 38400 },
5116 { /* slowbaud & CBAUDEX */
5117 0, 57600, 115200, 230400,
5118 460800, 150, 200, 921600,
5119 600, 1200, 1800, 2400,
5120 4800, 9600, 19200, 38400 },
5122 0, 57600, 76800, 115200,
5123 14400, 57600, 230400, 76800,
5124 115200, 230400, 28800, 460800,
5125 921600, 9600, 19200, 38400 },
5126 { /* fastbaud & CBAUDEX */
5127 0, 57600, 115200, 230400,
5128 460800, 150, 200, 921600,
5129 600, 1200, 1800, 2400,
5130 4800, 9600, 19200, 38400 }
5134 * Only use the TXPrint baud rate if the
5135 * terminal unit is NOT open
5137 if (!(ch->ch_tun.un_flags & UN_ISOPEN) &&
5138 un_type == DGAP_PRINT)
5139 baud = C_BAUD(ch->ch_pun.un_tty) & 0xff;
5141 baud = C_BAUD(ch->ch_tun.un_tty) & 0xff;
5143 if (ch->ch_c_cflag & CBAUDEX)
5146 if (ch->ch_digi.digi_flags & DIGI_FAST)
5151 if ((iindex >= 0) && (iindex < 4) &&
5152 (jindex >= 0) && (jindex < 16))
5153 baud = bauds[iindex][jindex];
5160 ch->ch_baud_info = baud;
5163 * CBAUD has bit position 0x1000 set these days to
5164 * indicate Linux baud rate remap.
5165 * We use a different bit assignment for high speed.
5166 * Clear this bit out while grabbing the parts of
5169 cflag = ch->ch_c_cflag & ((CBAUD ^ CBAUDEX) | PARODD | PARENB |
5173 * HUPCL bit is used by FEP to indicate fast baud
5174 * table is to be used.
5176 if ((ch->ch_digi.digi_flags & DIGI_FAST) ||
5177 (ch->ch_c_cflag & CBAUDEX))
5180 if ((ch->ch_c_cflag & CBAUDEX) &&
5181 !(ch->ch_digi.digi_flags & DIGI_FAST)) {
5183 * The below code is trying to guarantee that only
5184 * baud rates 115200, 230400, 460800, 921600 are
5185 * remapped. We use exclusive or because the various
5186 * baud rates share common bit positions and therefore
5187 * can't be tested for easily.
5189 tcflag_t tcflag = (ch->ch_c_cflag & CBAUD) | CBAUDEX;
5193 * Map high speed requests to index
5194 * into FEP's baud table
5224 cflag = (cflag & ~(CBAUD | CBAUDEX)) | baudpart;
5229 if (cflag != ch->ch_fepcflag) {
5230 ch->ch_fepcflag = (u16) (cflag & 0xffff);
5233 * Okay to have channel and board
5234 * locks held calling this
5236 dgap_cmdw(ch, SCFLAG, (u16) cflag, 0);
5239 /* Handle transition from B0 */
5240 if (ch->ch_flags & CH_BAUD0) {
5241 ch->ch_flags &= ~(CH_BAUD0);
5242 ch->ch_mval |= (D_RTS(ch)|D_DTR(ch));
5244 mval = D_DTR(ch) | D_RTS(ch);
5250 iflag = ch->ch_c_iflag & (IGNBRK | BRKINT | IGNPAR | PARMRK |
5251 INPCK | ISTRIP | IXON | IXANY | IXOFF);
5253 if ((ch->ch_startc == _POSIX_VDISABLE) ||
5254 (ch->ch_stopc == _POSIX_VDISABLE)) {
5255 iflag &= ~(IXON | IXOFF);
5256 ch->ch_c_iflag &= ~(IXON | IXOFF);
5260 * Only the IBM Xr card can switch between
5261 * 232 and 422 modes on the fly
5263 if (bd->device == PCI_DEV_XR_IBM_DID) {
5264 if (ch->ch_digi.digi_flags & DIGI_422)
5265 dgap_cmdb(ch, SCOMMODE, MODE_422, 0, 0);
5267 dgap_cmdb(ch, SCOMMODE, MODE_232, 0, 0);
5270 if (ch->ch_digi.digi_flags & DIGI_ALTPIN)
5273 if (iflag != ch->ch_fepiflag) {
5274 ch->ch_fepiflag = iflag;
5276 /* Okay to have channel and board locks held calling this */
5277 dgap_cmdw(ch, SIFLAG, (u16) ch->ch_fepiflag, 0);
5281 * Select hardware handshaking.
5285 if (ch->ch_c_cflag & CRTSCTS)
5286 hflow |= (D_RTS(ch) | D_CTS(ch));
5287 if (ch->ch_digi.digi_flags & RTSPACE)
5289 if (ch->ch_digi.digi_flags & DTRPACE)
5291 if (ch->ch_digi.digi_flags & CTSPACE)
5293 if (ch->ch_digi.digi_flags & DSRPACE)
5295 if (ch->ch_digi.digi_flags & DCDPACE)
5298 if (hflow != ch->ch_hflow) {
5299 ch->ch_hflow = hflow;
5301 /* Okay to have channel and board locks held calling this */
5302 dgap_cmdb(ch, SHFLOW, (u8) hflow, 0xff, 0);
5306 * Set RTS and/or DTR Toggle if needed,
5307 * but only if product is FEP5+ based.
5309 if (bd->bd_flags & BD_FEP5PLUS) {
5312 if (ch->ch_digi.digi_flags & DIGI_RTS_TOGGLE)
5313 hflow2 |= (D_RTS(ch));
5314 if (ch->ch_digi.digi_flags & DIGI_DTR_TOGGLE)
5315 hflow2 |= (D_DTR(ch));
5317 dgap_cmdw_ext(ch, 0xff03, hflow2, 0);
5321 * Set modem control lines.
5324 mval ^= ch->ch_mforce & (mval ^ ch->ch_mval);
5326 if (ch->ch_mostat ^ mval) {
5327 ch->ch_mostat = mval;
5329 /* Okay to have channel and board locks held calling this */
5330 dgap_cmdb(ch, SMODEM, (u8) mval, D_RTS(ch)|D_DTR(ch), 0);
5334 * Read modem signals, and then call carrier function.
5336 ch->ch_mistat = readb(&(ch->ch_bs->m_stat));
5340 * Set the start and stop characters.
5342 if (ch->ch_startc != ch->ch_fepstartc ||
5343 ch->ch_stopc != ch->ch_fepstopc) {
5344 ch->ch_fepstartc = ch->ch_startc;
5345 ch->ch_fepstopc = ch->ch_stopc;
5347 /* Okay to have channel and board locks held calling this */
5348 dgap_cmdb(ch, SFLOWC, ch->ch_fepstartc, ch->ch_fepstopc, 0);
5352 * Set the Auxiliary start and stop characters.
5354 if (ch->ch_astartc != ch->ch_fepastartc ||
5355 ch->ch_astopc != ch->ch_fepastopc) {
5356 ch->ch_fepastartc = ch->ch_astartc;
5357 ch->ch_fepastopc = ch->ch_astopc;
5359 /* Okay to have channel and board locks held calling this */
5360 dgap_cmdb(ch, SAFLOWC, ch->ch_fepastartc, ch->ch_fepastopc, 0);
5367 * dgap_parity_scan()
5369 * Convert the FEP5 way of reporting parity errors and breaks into
5370 * the Linux line discipline way.
5372 static void dgap_parity_scan(struct channel_t *ch, unsigned char *cbuf,
5373 unsigned char *fbuf, int *len)
5377 unsigned char *in, *cout, *fout;
5384 if (!ch || ch->magic != DGAP_CHANNEL_MAGIC)
5389 switch (ch->pscan_state) {
5391 /* reset to sanity and fall through */
5392 ch->pscan_state = 0;
5395 /* No FF seen yet */
5396 if (c == (unsigned char) '\377')
5397 /* delete this character from stream */
5398 ch->pscan_state = 1;
5401 *fout++ = TTY_NORMAL;
5408 if (c == (unsigned char) '\377') {
5409 /* doubled ff, transform to single ff */
5411 *fout++ = TTY_NORMAL;
5413 ch->pscan_state = 0;
5415 /* save value examination in next state */
5416 ch->pscan_savechar = c;
5417 ch->pscan_state = 2;
5422 /* third character of ff sequence */
5426 if (ch->pscan_savechar == 0x0) {
5430 *fout++ = TTY_BREAK;
5432 ch->ch_err_parity++;
5433 *fout++ = TTY_PARITY;
5438 ch->pscan_state = 0;
5444 static void dgap_write_wakeup(struct board_t *bd, struct channel_t *ch,
5445 struct un_t *un, u32 mask,
5446 unsigned long *irq_flags1,
5447 unsigned long *irq_flags2)
5449 if (!(un->un_flags & mask))
5452 un->un_flags &= ~mask;
5454 if (!(un->un_flags & UN_ISOPEN))
5457 if ((un->un_tty->flags & (1 << TTY_DO_WRITE_WAKEUP)) &&
5458 un->un_tty->ldisc->ops->write_wakeup) {
5459 spin_unlock_irqrestore(&ch->ch_lock, *irq_flags2);
5460 spin_unlock_irqrestore(&bd->bd_lock, *irq_flags1);
5462 (un->un_tty->ldisc->ops->write_wakeup)(un->un_tty);
5464 spin_lock_irqsave(&bd->bd_lock, *irq_flags1);
5465 spin_lock_irqsave(&ch->ch_lock, *irq_flags2);
5467 wake_up_interruptible(&un->un_tty->write_wait);
5468 wake_up_interruptible(&un->un_flags_wait);
5471 /*=======================================================================
5473 * dgap_event - FEP to host event processing routine.
5475 * bd - Board of current event.
5477 *=======================================================================*/
5478 static int dgap_event(struct board_t *bd)
5480 struct channel_t *ch;
5483 struct bs_t __iomem *bs;
5486 struct ev_t __iomem *eaddr;
5494 if (!bd || bd->magic != DGAP_BOARD_MAGIC)
5497 spin_lock_irqsave(&bd->bd_lock, lock_flags);
5499 vaddr = bd->re_map_membase;
5502 spin_unlock_irqrestore(&bd->bd_lock, lock_flags);
5506 eaddr = (struct ev_t __iomem *) (vaddr + EVBUF);
5508 /* Get our head and tail */
5509 head = readw(&(eaddr->ev_head));
5510 tail = readw(&(eaddr->ev_tail));
5513 * Forget it if pointers out of range.
5516 if (head >= EVMAX - EVSTART || tail >= EVMAX - EVSTART ||
5517 (head | tail) & 03) {
5518 /* Let go of board lock */
5519 spin_unlock_irqrestore(&bd->bd_lock, lock_flags);
5524 * Loop to process all the events in the buffer.
5526 while (tail != head) {
5529 * Get interrupt information.
5532 event = bd->re_map_membase + tail + EVSTART;
5534 port = ioread8(event);
5535 reason = ioread8(event + 1);
5536 modem = ioread8(event + 2);
5537 b1 = ioread8(event + 3);
5540 * Make sure the interrupt is valid.
5542 if (port >= bd->nasync)
5545 if (!(reason & (IFMODEM | IFBREAK | IFTLW | IFTEM | IFDATA)))
5548 ch = bd->channels[port];
5550 if (!ch || ch->magic != DGAP_CHANNEL_MAGIC)
5554 * If we have made it here, the event was valid.
5555 * Lock down the channel.
5557 spin_lock_irqsave(&ch->ch_lock, lock_flags2);
5562 spin_unlock_irqrestore(&ch->ch_lock, lock_flags2);
5567 * Process received data.
5569 if (reason & IFDATA) {
5572 * ALL LOCKS *MUST* BE DROPPED BEFORE CALLING INPUT!
5573 * input could send some data to ld, which in turn
5574 * could do a callback to one of our other functions.
5576 spin_unlock_irqrestore(&ch->ch_lock, lock_flags2);
5577 spin_unlock_irqrestore(&bd->bd_lock, lock_flags);
5581 spin_lock_irqsave(&bd->bd_lock, lock_flags);
5582 spin_lock_irqsave(&ch->ch_lock, lock_flags2);
5584 if (ch->ch_flags & CH_RACTIVE)
5585 ch->ch_flags |= CH_RENABLE;
5587 writeb(1, &(bs->idata));
5589 if (ch->ch_flags & CH_RWAIT) {
5590 ch->ch_flags &= ~CH_RWAIT;
5592 wake_up_interruptible
5593 (&ch->ch_tun.un_flags_wait);
5598 * Process Modem change signals.
5600 if (reason & IFMODEM) {
5601 ch->ch_mistat = modem;
5608 if (reason & IFBREAK) {
5610 if (ch->ch_tun.un_tty) {
5611 /* A break has been indicated */
5613 tty_buffer_request_room
5614 (ch->ch_tun.un_tty->port, 1);
5615 tty_insert_flip_char(ch->ch_tun.un_tty->port,
5617 tty_flip_buffer_push(ch->ch_tun.un_tty->port);
5622 * Process Transmit low.
5624 if (reason & IFTLW) {
5625 dgap_write_wakeup(bd, ch, &ch->ch_tun, UN_LOW,
5626 &lock_flags, &lock_flags2);
5627 dgap_write_wakeup(bd, ch, &ch->ch_pun, UN_LOW,
5628 &lock_flags, &lock_flags2);
5629 if (ch->ch_flags & CH_WLOW) {
5630 ch->ch_flags &= ~CH_WLOW;
5631 wake_up_interruptible(&ch->ch_flags_wait);
5636 * Process Transmit empty.
5638 if (reason & IFTEM) {
5639 dgap_write_wakeup(bd, ch, &ch->ch_tun, UN_EMPTY,
5640 &lock_flags, &lock_flags2);
5641 dgap_write_wakeup(bd, ch, &ch->ch_pun, UN_EMPTY,
5642 &lock_flags, &lock_flags2);
5643 if (ch->ch_flags & CH_WEMPTY) {
5644 ch->ch_flags &= ~CH_WEMPTY;
5645 wake_up_interruptible(&ch->ch_flags_wait);
5649 spin_unlock_irqrestore(&ch->ch_lock, lock_flags2);
5652 tail = (tail + 4) & (EVMAX - EVSTART - 4);
5655 writew(tail, &(eaddr->ev_tail));
5656 spin_unlock_irqrestore(&bd->bd_lock, lock_flags);
5661 static ssize_t dgap_driver_version_show(struct device_driver *ddp, char *buf)
5663 return snprintf(buf, PAGE_SIZE, "%s\n", DG_PART);
5665 static DRIVER_ATTR(version, S_IRUSR, dgap_driver_version_show, NULL);
5668 static ssize_t dgap_driver_boards_show(struct device_driver *ddp, char *buf)
5670 return snprintf(buf, PAGE_SIZE, "%d\n", dgap_numboards);
5672 static DRIVER_ATTR(boards, S_IRUSR, dgap_driver_boards_show, NULL);
5675 static ssize_t dgap_driver_maxboards_show(struct device_driver *ddp, char *buf)
5677 return snprintf(buf, PAGE_SIZE, "%d\n", MAXBOARDS);
5679 static DRIVER_ATTR(maxboards, S_IRUSR, dgap_driver_maxboards_show, NULL);
5682 static ssize_t dgap_driver_pollcounter_show(struct device_driver *ddp,
5685 return snprintf(buf, PAGE_SIZE, "%ld\n", dgap_poll_counter);
5687 static DRIVER_ATTR(pollcounter, S_IRUSR, dgap_driver_pollcounter_show, NULL);
5689 static ssize_t dgap_driver_pollrate_show(struct device_driver *ddp, char *buf)
5691 return snprintf(buf, PAGE_SIZE, "%dms\n", dgap_poll_tick);
5694 static ssize_t dgap_driver_pollrate_store(struct device_driver *ddp,
5695 const char *buf, size_t count)
5697 if (sscanf(buf, "%d\n", &dgap_poll_tick) != 1)
5701 static DRIVER_ATTR(pollrate, (S_IRUSR | S_IWUSR), dgap_driver_pollrate_show,
5702 dgap_driver_pollrate_store);
5704 static int dgap_create_driver_sysfiles(struct pci_driver *dgap_driver)
5707 struct device_driver *driverfs = &dgap_driver->driver;
5709 rc |= driver_create_file(driverfs, &driver_attr_version);
5710 rc |= driver_create_file(driverfs, &driver_attr_boards);
5711 rc |= driver_create_file(driverfs, &driver_attr_maxboards);
5712 rc |= driver_create_file(driverfs, &driver_attr_pollrate);
5713 rc |= driver_create_file(driverfs, &driver_attr_pollcounter);
5718 static void dgap_remove_driver_sysfiles(struct pci_driver *dgap_driver)
5720 struct device_driver *driverfs = &dgap_driver->driver;
5722 driver_remove_file(driverfs, &driver_attr_version);
5723 driver_remove_file(driverfs, &driver_attr_boards);
5724 driver_remove_file(driverfs, &driver_attr_maxboards);
5725 driver_remove_file(driverfs, &driver_attr_pollrate);
5726 driver_remove_file(driverfs, &driver_attr_pollcounter);
5729 static struct board_t *dgap_verify_board(struct device *p)
5736 bd = dev_get_drvdata(p);
5737 if (!bd || bd->magic != DGAP_BOARD_MAGIC || bd->state != BOARD_READY)
5743 static ssize_t dgap_ports_state_show(struct device *p,
5744 struct device_attribute *attr,
5751 bd = dgap_verify_board(p);
5755 for (i = 0; i < bd->nasync; i++) {
5756 count += snprintf(buf + count, PAGE_SIZE - count,
5757 "%d %s\n", bd->channels[i]->ch_portnum,
5758 bd->channels[i]->ch_open_count ? "Open" : "Closed");
5762 static DEVICE_ATTR(ports_state, S_IRUSR, dgap_ports_state_show, NULL);
5764 static ssize_t dgap_ports_baud_show(struct device *p,
5765 struct device_attribute *attr,
5772 bd = dgap_verify_board(p);
5776 for (i = 0; i < bd->nasync; i++) {
5777 count += snprintf(buf + count, PAGE_SIZE - count, "%d %d\n",
5778 bd->channels[i]->ch_portnum,
5779 bd->channels[i]->ch_baud_info);
5783 static DEVICE_ATTR(ports_baud, S_IRUSR, dgap_ports_baud_show, NULL);
5785 static ssize_t dgap_ports_msignals_show(struct device *p,
5786 struct device_attribute *attr,
5793 bd = dgap_verify_board(p);
5797 for (i = 0; i < bd->nasync; i++) {
5798 if (bd->channels[i]->ch_open_count)
5799 count += snprintf(buf + count, PAGE_SIZE - count,
5800 "%d %s %s %s %s %s %s\n",
5801 bd->channels[i]->ch_portnum,
5802 (bd->channels[i]->ch_mostat &
5803 UART_MCR_RTS) ? "RTS" : "",
5804 (bd->channels[i]->ch_mistat &
5805 UART_MSR_CTS) ? "CTS" : "",
5806 (bd->channels[i]->ch_mostat &
5807 UART_MCR_DTR) ? "DTR" : "",
5808 (bd->channels[i]->ch_mistat &
5809 UART_MSR_DSR) ? "DSR" : "",
5810 (bd->channels[i]->ch_mistat &
5811 UART_MSR_DCD) ? "DCD" : "",
5812 (bd->channels[i]->ch_mistat &
5813 UART_MSR_RI) ? "RI" : "");
5815 count += snprintf(buf + count, PAGE_SIZE - count,
5816 "%d\n", bd->channels[i]->ch_portnum);
5820 static DEVICE_ATTR(ports_msignals, S_IRUSR, dgap_ports_msignals_show, NULL);
5822 static ssize_t dgap_ports_iflag_show(struct device *p,
5823 struct device_attribute *attr,
5830 bd = dgap_verify_board(p);
5834 for (i = 0; i < bd->nasync; i++)
5835 count += snprintf(buf + count, PAGE_SIZE - count, "%d %x\n",
5836 bd->channels[i]->ch_portnum,
5837 bd->channels[i]->ch_c_iflag);
5840 static DEVICE_ATTR(ports_iflag, S_IRUSR, dgap_ports_iflag_show, NULL);
5842 static ssize_t dgap_ports_cflag_show(struct device *p,
5843 struct device_attribute *attr,
5850 bd = dgap_verify_board(p);
5854 for (i = 0; i < bd->nasync; i++)
5855 count += snprintf(buf + count, PAGE_SIZE - count, "%d %x\n",
5856 bd->channels[i]->ch_portnum,
5857 bd->channels[i]->ch_c_cflag);
5860 static DEVICE_ATTR(ports_cflag, S_IRUSR, dgap_ports_cflag_show, NULL);
5862 static ssize_t dgap_ports_oflag_show(struct device *p,
5863 struct device_attribute *attr,
5870 bd = dgap_verify_board(p);
5874 for (i = 0; i < bd->nasync; i++)
5875 count += snprintf(buf + count, PAGE_SIZE - count, "%d %x\n",
5876 bd->channels[i]->ch_portnum,
5877 bd->channels[i]->ch_c_oflag);
5880 static DEVICE_ATTR(ports_oflag, S_IRUSR, dgap_ports_oflag_show, NULL);
5882 static ssize_t dgap_ports_lflag_show(struct device *p,
5883 struct device_attribute *attr,
5890 bd = dgap_verify_board(p);
5894 for (i = 0; i < bd->nasync; i++)
5895 count += snprintf(buf + count, PAGE_SIZE - count, "%d %x\n",
5896 bd->channels[i]->ch_portnum,
5897 bd->channels[i]->ch_c_lflag);
5900 static DEVICE_ATTR(ports_lflag, S_IRUSR, dgap_ports_lflag_show, NULL);
5902 static ssize_t dgap_ports_digi_flag_show(struct device *p,
5903 struct device_attribute *attr,
5910 bd = dgap_verify_board(p);
5914 for (i = 0; i < bd->nasync; i++)
5915 count += snprintf(buf + count, PAGE_SIZE - count, "%d %x\n",
5916 bd->channels[i]->ch_portnum,
5917 bd->channels[i]->ch_digi.digi_flags);
5920 static DEVICE_ATTR(ports_digi_flag, S_IRUSR, dgap_ports_digi_flag_show, NULL);
5922 static ssize_t dgap_ports_rxcount_show(struct device *p,
5923 struct device_attribute *attr,
5930 bd = dgap_verify_board(p);
5934 for (i = 0; i < bd->nasync; i++)
5935 count += snprintf(buf + count, PAGE_SIZE - count, "%d %ld\n",
5936 bd->channels[i]->ch_portnum,
5937 bd->channels[i]->ch_rxcount);
5940 static DEVICE_ATTR(ports_rxcount, S_IRUSR, dgap_ports_rxcount_show, NULL);
5942 static ssize_t dgap_ports_txcount_show(struct device *p,
5943 struct device_attribute *attr,
5950 bd = dgap_verify_board(p);
5954 for (i = 0; i < bd->nasync; i++)
5955 count += snprintf(buf + count, PAGE_SIZE - count, "%d %ld\n",
5956 bd->channels[i]->ch_portnum,
5957 bd->channels[i]->ch_txcount);
5960 static DEVICE_ATTR(ports_txcount, S_IRUSR, dgap_ports_txcount_show, NULL);
5962 /* this function creates the sys files that will export each signal status
5963 * to sysfs each value will be put in a separate filename
5965 static void dgap_create_ports_sysfiles(struct board_t *bd)
5967 dev_set_drvdata(&bd->pdev->dev, bd);
5968 device_create_file(&(bd->pdev->dev), &dev_attr_ports_state);
5969 device_create_file(&(bd->pdev->dev), &dev_attr_ports_baud);
5970 device_create_file(&(bd->pdev->dev), &dev_attr_ports_msignals);
5971 device_create_file(&(bd->pdev->dev), &dev_attr_ports_iflag);
5972 device_create_file(&(bd->pdev->dev), &dev_attr_ports_cflag);
5973 device_create_file(&(bd->pdev->dev), &dev_attr_ports_oflag);
5974 device_create_file(&(bd->pdev->dev), &dev_attr_ports_lflag);
5975 device_create_file(&(bd->pdev->dev), &dev_attr_ports_digi_flag);
5976 device_create_file(&(bd->pdev->dev), &dev_attr_ports_rxcount);
5977 device_create_file(&(bd->pdev->dev), &dev_attr_ports_txcount);
5980 /* removes all the sys files created for that port */
5981 static void dgap_remove_ports_sysfiles(struct board_t *bd)
5983 device_remove_file(&(bd->pdev->dev), &dev_attr_ports_state);
5984 device_remove_file(&(bd->pdev->dev), &dev_attr_ports_baud);
5985 device_remove_file(&(bd->pdev->dev), &dev_attr_ports_msignals);
5986 device_remove_file(&(bd->pdev->dev), &dev_attr_ports_iflag);
5987 device_remove_file(&(bd->pdev->dev), &dev_attr_ports_cflag);
5988 device_remove_file(&(bd->pdev->dev), &dev_attr_ports_oflag);
5989 device_remove_file(&(bd->pdev->dev), &dev_attr_ports_lflag);
5990 device_remove_file(&(bd->pdev->dev), &dev_attr_ports_digi_flag);
5991 device_remove_file(&(bd->pdev->dev), &dev_attr_ports_rxcount);
5992 device_remove_file(&(bd->pdev->dev), &dev_attr_ports_txcount);
5995 static ssize_t dgap_tty_state_show(struct device *d,
5996 struct device_attribute *attr,
6000 struct channel_t *ch;
6005 un = dev_get_drvdata(d);
6006 if (!un || un->magic != DGAP_UNIT_MAGIC)
6009 if (!ch || ch->magic != DGAP_CHANNEL_MAGIC)
6012 if (!bd || bd->magic != DGAP_BOARD_MAGIC)
6014 if (bd->state != BOARD_READY)
6017 return snprintf(buf, PAGE_SIZE, "%s", un->un_open_count ?
6020 static DEVICE_ATTR(state, S_IRUSR, dgap_tty_state_show, NULL);
6022 static ssize_t dgap_tty_baud_show(struct device *d,
6023 struct device_attribute *attr,
6027 struct channel_t *ch;
6032 un = dev_get_drvdata(d);
6033 if (!un || un->magic != DGAP_UNIT_MAGIC)
6036 if (!ch || ch->magic != DGAP_CHANNEL_MAGIC)
6039 if (!bd || bd->magic != DGAP_BOARD_MAGIC)
6041 if (bd->state != BOARD_READY)
6044 return snprintf(buf, PAGE_SIZE, "%d\n", ch->ch_baud_info);
6046 static DEVICE_ATTR(baud, S_IRUSR, dgap_tty_baud_show, NULL);
6048 static ssize_t dgap_tty_msignals_show(struct device *d,
6049 struct device_attribute *attr,
6053 struct channel_t *ch;
6058 un = dev_get_drvdata(d);
6059 if (!un || un->magic != DGAP_UNIT_MAGIC)
6062 if (!ch || ch->magic != DGAP_CHANNEL_MAGIC)
6065 if (!bd || bd->magic != DGAP_BOARD_MAGIC)
6067 if (bd->state != BOARD_READY)
6070 if (ch->ch_open_count) {
6071 return snprintf(buf, PAGE_SIZE, "%s %s %s %s %s %s\n",
6072 (ch->ch_mostat & UART_MCR_RTS) ? "RTS" : "",
6073 (ch->ch_mistat & UART_MSR_CTS) ? "CTS" : "",
6074 (ch->ch_mostat & UART_MCR_DTR) ? "DTR" : "",
6075 (ch->ch_mistat & UART_MSR_DSR) ? "DSR" : "",
6076 (ch->ch_mistat & UART_MSR_DCD) ? "DCD" : "",
6077 (ch->ch_mistat & UART_MSR_RI) ? "RI" : "");
6081 static DEVICE_ATTR(msignals, S_IRUSR, dgap_tty_msignals_show, NULL);
6083 static ssize_t dgap_tty_iflag_show(struct device *d,
6084 struct device_attribute *attr,
6088 struct channel_t *ch;
6093 un = dev_get_drvdata(d);
6094 if (!un || un->magic != DGAP_UNIT_MAGIC)
6097 if (!ch || ch->magic != DGAP_CHANNEL_MAGIC)
6100 if (!bd || bd->magic != DGAP_BOARD_MAGIC)
6102 if (bd->state != BOARD_READY)
6105 return snprintf(buf, PAGE_SIZE, "%x\n", ch->ch_c_iflag);
6107 static DEVICE_ATTR(iflag, S_IRUSR, dgap_tty_iflag_show, NULL);
6109 static ssize_t dgap_tty_cflag_show(struct device *d,
6110 struct device_attribute *attr,
6114 struct channel_t *ch;
6119 un = dev_get_drvdata(d);
6120 if (!un || un->magic != DGAP_UNIT_MAGIC)
6123 if (!ch || ch->magic != DGAP_CHANNEL_MAGIC)
6126 if (!bd || bd->magic != DGAP_BOARD_MAGIC)
6128 if (bd->state != BOARD_READY)
6131 return snprintf(buf, PAGE_SIZE, "%x\n", ch->ch_c_cflag);
6133 static DEVICE_ATTR(cflag, S_IRUSR, dgap_tty_cflag_show, NULL);
6135 static ssize_t dgap_tty_oflag_show(struct device *d,
6136 struct device_attribute *attr,
6140 struct channel_t *ch;
6145 un = dev_get_drvdata(d);
6146 if (!un || un->magic != DGAP_UNIT_MAGIC)
6149 if (!ch || ch->magic != DGAP_CHANNEL_MAGIC)
6152 if (!bd || bd->magic != DGAP_BOARD_MAGIC)
6154 if (bd->state != BOARD_READY)
6157 return snprintf(buf, PAGE_SIZE, "%x\n", ch->ch_c_oflag);
6159 static DEVICE_ATTR(oflag, S_IRUSR, dgap_tty_oflag_show, NULL);
6161 static ssize_t dgap_tty_lflag_show(struct device *d,
6162 struct device_attribute *attr,
6166 struct channel_t *ch;
6171 un = dev_get_drvdata(d);
6172 if (!un || un->magic != DGAP_UNIT_MAGIC)
6175 if (!ch || ch->magic != DGAP_CHANNEL_MAGIC)
6178 if (!bd || bd->magic != DGAP_BOARD_MAGIC)
6180 if (bd->state != BOARD_READY)
6183 return snprintf(buf, PAGE_SIZE, "%x\n", ch->ch_c_lflag);
6185 static DEVICE_ATTR(lflag, S_IRUSR, dgap_tty_lflag_show, NULL);
6187 static ssize_t dgap_tty_digi_flag_show(struct device *d,
6188 struct device_attribute *attr,
6192 struct channel_t *ch;
6197 un = dev_get_drvdata(d);
6198 if (!un || un->magic != DGAP_UNIT_MAGIC)
6201 if (!ch || ch->magic != DGAP_CHANNEL_MAGIC)
6204 if (!bd || bd->magic != DGAP_BOARD_MAGIC)
6206 if (bd->state != BOARD_READY)
6209 return snprintf(buf, PAGE_SIZE, "%x\n", ch->ch_digi.digi_flags);
6211 static DEVICE_ATTR(digi_flag, S_IRUSR, dgap_tty_digi_flag_show, NULL);
6213 static ssize_t dgap_tty_rxcount_show(struct device *d,
6214 struct device_attribute *attr,
6218 struct channel_t *ch;
6223 un = dev_get_drvdata(d);
6224 if (!un || un->magic != DGAP_UNIT_MAGIC)
6227 if (!ch || ch->magic != DGAP_CHANNEL_MAGIC)
6230 if (!bd || bd->magic != DGAP_BOARD_MAGIC)
6232 if (bd->state != BOARD_READY)
6235 return snprintf(buf, PAGE_SIZE, "%ld\n", ch->ch_rxcount);
6237 static DEVICE_ATTR(rxcount, S_IRUSR, dgap_tty_rxcount_show, NULL);
6239 static ssize_t dgap_tty_txcount_show(struct device *d,
6240 struct device_attribute *attr,
6244 struct channel_t *ch;
6249 un = dev_get_drvdata(d);
6250 if (!un || un->magic != DGAP_UNIT_MAGIC)
6253 if (!ch || ch->magic != DGAP_CHANNEL_MAGIC)
6256 if (!bd || bd->magic != DGAP_BOARD_MAGIC)
6258 if (bd->state != BOARD_READY)
6261 return snprintf(buf, PAGE_SIZE, "%ld\n", ch->ch_txcount);
6263 static DEVICE_ATTR(txcount, S_IRUSR, dgap_tty_txcount_show, NULL);
6265 static ssize_t dgap_tty_name_show(struct device *d,
6266 struct device_attribute *attr,
6270 struct channel_t *ch;
6282 un = dev_get_drvdata(d);
6283 if (!un || un->magic != DGAP_UNIT_MAGIC)
6286 if (!ch || ch->magic != DGAP_CHANNEL_MAGIC)
6289 if (!bd || bd->magic != DGAP_BOARD_MAGIC)
6291 if (bd->state != BOARD_READY)
6295 cn = ch->ch_portnum;
6297 for (cptr = bd->bd_config; cptr; cptr = cptr->next) {
6299 if ((cptr->type == BNODE) &&
6300 ((cptr->u.board.type == APORT2_920P) ||
6301 (cptr->u.board.type == APORT4_920P) ||
6302 (cptr->u.board.type == APORT8_920P) ||
6303 (cptr->u.board.type == PAPORT4) ||
6304 (cptr->u.board.type == PAPORT8))) {
6307 if (cptr->u.board.v_start)
6308 starto = cptr->u.board.start;
6313 if (cptr->type == TNODE && found == TRUE) {
6316 if (strstr(cptr->u.ttyname, "tty")) {
6317 ptr1 = cptr->u.ttyname;
6320 ptr1 = cptr->u.ttyname;
6322 for (i = 0; i < dgap_config_get_num_prts(bd); i++) {
6326 return snprintf(buf, PAGE_SIZE, "%s%s%02d\n",
6327 (un->un_type == DGAP_PRINT) ?
6333 if (cptr->type == CNODE) {
6335 for (i = 0; i < cptr->u.conc.nport; i++) {
6336 if (cn != (i + ncount))
6339 return snprintf(buf, PAGE_SIZE, "%s%s%02ld\n",
6340 (un->un_type == DGAP_PRINT) ?
6343 i + (cptr->u.conc.v_start ?
6344 cptr->u.conc.start : 1));
6347 ncount += cptr->u.conc.nport;
6350 if (cptr->type == MNODE) {
6352 for (i = 0; i < cptr->u.module.nport; i++) {
6353 if (cn != (i + ncount))
6356 return snprintf(buf, PAGE_SIZE, "%s%s%02ld\n",
6357 (un->un_type == DGAP_PRINT) ?
6360 i + (cptr->u.module.v_start ?
6361 cptr->u.module.start : 1));
6364 ncount += cptr->u.module.nport;
6369 return snprintf(buf, PAGE_SIZE, "%s_dgap_%d_%d\n",
6370 (un->un_type == DGAP_PRINT) ? "pr" : "tty", bn, cn);
6372 static DEVICE_ATTR(custom_name, S_IRUSR, dgap_tty_name_show, NULL);
6374 static struct attribute *dgap_sysfs_tty_entries[] = {
6375 &dev_attr_state.attr,
6376 &dev_attr_baud.attr,
6377 &dev_attr_msignals.attr,
6378 &dev_attr_iflag.attr,
6379 &dev_attr_cflag.attr,
6380 &dev_attr_oflag.attr,
6381 &dev_attr_lflag.attr,
6382 &dev_attr_digi_flag.attr,
6383 &dev_attr_rxcount.attr,
6384 &dev_attr_txcount.attr,
6385 &dev_attr_custom_name.attr,
6389 static struct attribute_group dgap_tty_attribute_group = {
6391 .attrs = dgap_sysfs_tty_entries,
6394 static void dgap_create_tty_sysfs(struct un_t *un, struct device *c)
6398 ret = sysfs_create_group(&c->kobj, &dgap_tty_attribute_group);
6402 dev_set_drvdata(c, un);
6406 static void dgap_remove_tty_sysfs(struct device *c)
6408 sysfs_remove_group(&c->kobj, &dgap_tty_attribute_group);
6412 * Parse a configuration file read into memory as a string.
6414 static int dgap_parsefile(char **in)
6416 struct cnode *p, *brd, *line, *conc;
6422 brd = line = conc = NULL;
6424 /* perhaps we are adding to an existing list? */
6428 /* file must start with a BEGIN */
6429 while ((rc = dgap_gettok(in, p)) != BEGIN) {
6431 dgap_err("unexpected EOF");
6437 rc = dgap_gettok(in, p);
6439 dgap_err("unexpected EOF");
6445 dgap_err("unexpected end of file");
6448 case BEGIN: /* should only be 1 begin */
6449 dgap_err("unexpected config_begin\n");
6455 case BOARD: /* board info */
6456 if (dgap_checknode(p))
6458 p->next = dgap_newnode(BNODE);
6460 dgap_err("out of memory");
6465 p->u.board.status = kstrdup("No", GFP_KERNEL);
6471 case APORT2_920P: /* AccelePort_4 */
6472 if (p->type != BNODE) {
6473 dgap_err("unexpected Digi_2r_920 string");
6476 p->u.board.type = APORT2_920P;
6477 p->u.board.v_type = 1;
6480 case APORT4_920P: /* AccelePort_4 */
6481 if (p->type != BNODE) {
6482 dgap_err("unexpected Digi_4r_920 string");
6485 p->u.board.type = APORT4_920P;
6486 p->u.board.v_type = 1;
6489 case APORT8_920P: /* AccelePort_8 */
6490 if (p->type != BNODE) {
6491 dgap_err("unexpected Digi_8r_920 string");
6494 p->u.board.type = APORT8_920P;
6495 p->u.board.v_type = 1;
6498 case PAPORT4: /* AccelePort_4 PCI */
6499 if (p->type != BNODE) {
6500 dgap_err("unexpected Digi_4r(PCI) string");
6503 p->u.board.type = PAPORT4;
6504 p->u.board.v_type = 1;
6507 case PAPORT8: /* AccelePort_8 PCI */
6508 if (p->type != BNODE) {
6509 dgap_err("unexpected Digi_8r string");
6512 p->u.board.type = PAPORT8;
6513 p->u.board.v_type = 1;
6516 case PCX: /* PCI C/X */
6517 if (p->type != BNODE) {
6518 dgap_err("unexpected Digi_C/X_(PCI) string");
6521 p->u.board.type = PCX;
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 PEPC: /* PCI EPC/X */
6530 if (p->type != BNODE) {
6531 dgap_err("unexpected \"Digi_EPC/X_(PCI)\" string");
6534 p->u.board.type = PEPC;
6535 p->u.board.v_type = 1;
6536 p->u.board.conc1 = 0;
6537 p->u.board.conc2 = 0;
6538 p->u.board.module1 = 0;
6539 p->u.board.module2 = 0;
6542 case PPCM: /* PCI/Xem */
6543 if (p->type != BNODE) {
6544 dgap_err("unexpected PCI/Xem string");
6547 p->u.board.type = PPCM;
6548 p->u.board.v_type = 1;
6549 p->u.board.conc1 = 0;
6550 p->u.board.conc2 = 0;
6553 case IO: /* i/o port */
6554 if (p->type != BNODE) {
6555 dgap_err("IO port only vaild for boards");
6558 s = dgap_getword(in);
6560 dgap_err("unexpected end of file");
6563 p->u.board.portstr = kstrdup(s, GFP_KERNEL);
6564 if (kstrtol(s, 0, &p->u.board.port)) {
6565 dgap_err("bad number for IO port");
6568 p->u.board.v_port = 1;
6571 case MEM: /* memory address */
6572 if (p->type != BNODE) {
6573 dgap_err("memory address only vaild for boards");
6576 s = dgap_getword(in);
6578 dgap_err("unexpected end of file");
6581 p->u.board.addrstr = kstrdup(s, GFP_KERNEL);
6582 if (kstrtoul(s, 0, &p->u.board.addr)) {
6583 dgap_err("bad number for memory address");
6586 p->u.board.v_addr = 1;
6589 case PCIINFO: /* pci information */
6590 if (p->type != BNODE) {
6591 dgap_err("memory address only vaild for boards");
6594 s = dgap_getword(in);
6596 dgap_err("unexpected end of file");
6599 p->u.board.pcibusstr = kstrdup(s, GFP_KERNEL);
6600 if (kstrtoul(s, 0, &p->u.board.pcibus)) {
6601 dgap_err("bad number for pci bus");
6604 p->u.board.v_pcibus = 1;
6605 s = dgap_getword(in);
6607 dgap_err("unexpected end of file");
6610 p->u.board.pcislotstr = kstrdup(s, GFP_KERNEL);
6611 if (kstrtoul(s, 0, &p->u.board.pcislot)) {
6612 dgap_err("bad number for pci slot");
6615 p->u.board.v_pcislot = 1;
6619 if (p->type != BNODE) {
6620 dgap_err("install method only vaild for boards");
6623 s = dgap_getword(in);
6625 dgap_err("unexpected end of file");
6628 p->u.board.method = kstrdup(s, GFP_KERNEL);
6629 p->u.board.v_method = 1;
6633 if (p->type != BNODE) {
6634 dgap_err("config status only vaild for boards");
6637 s = dgap_getword(in);
6639 dgap_err("unexpected end of file");
6642 p->u.board.status = kstrdup(s, GFP_KERNEL);
6645 case NPORTS: /* number of ports */
6646 if (p->type == BNODE) {
6647 s = dgap_getword(in);
6649 dgap_err("unexpected end of file");
6652 if (kstrtol(s, 0, &p->u.board.nport)) {
6653 dgap_err("bad number for number of ports");
6656 p->u.board.v_nport = 1;
6657 } else if (p->type == CNODE) {
6658 s = dgap_getword(in);
6660 dgap_err("unexpected end of file");
6663 if (kstrtol(s, 0, &p->u.conc.nport)) {
6664 dgap_err("bad number for number of ports");
6667 p->u.conc.v_nport = 1;
6668 } else if (p->type == MNODE) {
6669 s = dgap_getword(in);
6671 dgap_err("unexpected end of file");
6674 if (kstrtol(s, 0, &p->u.module.nport)) {
6675 dgap_err("bad number for number of ports");
6678 p->u.module.v_nport = 1;
6680 dgap_err("nports only valid for concentrators or modules");
6685 case ID: /* letter ID used in tty name */
6686 s = dgap_getword(in);
6688 dgap_err("unexpected end of file");
6692 p->u.board.status = kstrdup(s, GFP_KERNEL);
6694 if (p->type == CNODE) {
6695 p->u.conc.id = kstrdup(s, GFP_KERNEL);
6697 } else if (p->type == MNODE) {
6698 p->u.module.id = kstrdup(s, GFP_KERNEL);
6699 p->u.module.v_id = 1;
6701 dgap_err("id only valid for concentrators or modules");
6706 case STARTO: /* start offset of ID */
6707 if (p->type == BNODE) {
6708 s = dgap_getword(in);
6710 dgap_err("unexpected end of file");
6713 if (kstrtol(s, 0, &p->u.board.start)) {
6714 dgap_err("bad number for start of tty count");
6717 p->u.board.v_start = 1;
6718 } else if (p->type == CNODE) {
6719 s = dgap_getword(in);
6721 dgap_err("unexpected end of file");
6724 if (kstrtol(s, 0, &p->u.conc.start)) {
6725 dgap_err("bad number for start of tty count");
6728 p->u.conc.v_start = 1;
6729 } else if (p->type == MNODE) {
6730 s = dgap_getword(in);
6732 dgap_err("unexpected end of file");
6735 if (kstrtol(s, 0, &p->u.module.start)) {
6736 dgap_err("bad number for start of tty count");
6739 p->u.module.v_start = 1;
6741 dgap_err("start only valid for concentrators or modules");
6746 case TTYN: /* tty name prefix */
6747 if (dgap_checknode(p))
6749 p->next = dgap_newnode(TNODE);
6751 dgap_err("out of memory");
6755 s = dgap_getword(in);
6757 dgap_err("unexpeced end of file");
6760 p->u.ttyname = kstrdup(s, GFP_KERNEL);
6761 if (!p->u.ttyname) {
6762 dgap_err("out of memory");
6767 case CU: /* cu name prefix */
6768 if (dgap_checknode(p))
6770 p->next = dgap_newnode(CUNODE);
6772 dgap_err("out of memory");
6776 s = dgap_getword(in);
6778 dgap_err("unexpeced end of file");
6781 p->u.cuname = kstrdup(s, GFP_KERNEL);
6783 dgap_err("out of memory");
6788 case LINE: /* line information */
6789 if (dgap_checknode(p))
6792 dgap_err("must specify board before line info");
6795 switch (brd->u.board.type) {
6797 dgap_err("line not vaild for PC/em");
6800 p->next = dgap_newnode(LNODE);
6802 dgap_err("out of memory");
6811 case CONC: /* concentrator information */
6812 if (dgap_checknode(p))
6815 dgap_err("must specify line info before concentrator");
6818 p->next = dgap_newnode(CNODE);
6820 dgap_err("out of memory");
6826 brd->u.board.conc2++;
6828 brd->u.board.conc1++;
6832 case CX: /* c/x type concentrator */
6833 if (p->type != CNODE) {
6834 dgap_err("cx only valid for concentrators");
6837 p->u.conc.type = CX;
6838 p->u.conc.v_type = 1;
6841 case EPC: /* epc type concentrator */
6842 if (p->type != CNODE) {
6843 dgap_err("cx only valid for concentrators");
6846 p->u.conc.type = EPC;
6847 p->u.conc.v_type = 1;
6850 case MOD: /* EBI module */
6851 if (dgap_checknode(p))
6854 dgap_err("must specify board info before EBI modules");
6857 switch (brd->u.board.type) {
6863 dgap_err("must specify concentrator info before EBI module");
6867 p->next = dgap_newnode(MNODE);
6869 dgap_err("out of memory");
6874 brd->u.board.module2++;
6876 brd->u.board.module1++;
6880 case PORTS: /* ports type EBI module */
6881 if (p->type != MNODE) {
6882 dgap_err("ports only valid for EBI modules");
6885 p->u.module.type = PORTS;
6886 p->u.module.v_type = 1;
6889 case MODEM: /* ports type EBI module */
6890 if (p->type != MNODE) {
6891 dgap_err("modem only valid for modem modules");
6894 p->u.module.type = MODEM;
6895 p->u.module.v_type = 1;
6899 if (p->type == LNODE) {
6900 s = dgap_getword(in);
6902 dgap_err("unexpected end of file");
6905 p->u.line.cable = kstrdup(s, GFP_KERNEL);
6906 p->u.line.v_cable = 1;
6910 case SPEED: /* sync line speed indication */
6911 if (p->type == LNODE) {
6912 s = dgap_getword(in);
6914 dgap_err("unexpected end of file");
6917 if (kstrtol(s, 0, &p->u.line.speed)) {
6918 dgap_err("bad number for line speed");
6921 p->u.line.v_speed = 1;
6922 } else if (p->type == CNODE) {
6923 s = dgap_getword(in);
6925 dgap_err("unexpected end of file");
6928 if (kstrtol(s, 0, &p->u.conc.speed)) {
6929 dgap_err("bad number for line speed");
6932 p->u.conc.v_speed = 1;
6934 dgap_err("speed valid only for lines or concentrators.");
6940 if (p->type == CNODE) {
6941 s = dgap_getword(in);
6943 dgap_err("unexpected end of file");
6946 p->u.conc.connect = kstrdup(s, GFP_KERNEL);
6947 p->u.conc.v_connect = 1;
6950 case PRINT: /* transparent print name prefix */
6951 if (dgap_checknode(p))
6953 p->next = dgap_newnode(PNODE);
6955 dgap_err("out of memory");
6959 s = dgap_getword(in);
6961 dgap_err("unexpeced end of file");
6964 p->u.printname = kstrdup(s, GFP_KERNEL);
6965 if (!p->u.printname) {
6966 dgap_err("out of memory");
6971 case CMAJOR: /* major number */
6972 if (dgap_checknode(p))
6974 p->next = dgap_newnode(JNODE);
6976 dgap_err("out of memory");
6980 s = dgap_getword(in);
6982 dgap_err("unexpected end of file");
6985 if (kstrtol(s, 0, &p->u.majornumber)) {
6986 dgap_err("bad number for major number");
6991 case ALTPIN: /* altpin setting */
6992 if (dgap_checknode(p))
6994 p->next = dgap_newnode(ANODE);
6996 dgap_err("out of memory");
7000 s = dgap_getword(in);
7002 dgap_err("unexpected end of file");
7005 if (kstrtol(s, 0, &p->u.altpin)) {
7006 dgap_err("bad number for altpin");
7011 case USEINTR: /* enable interrupt setting */
7012 if (dgap_checknode(p))
7014 p->next = dgap_newnode(INTRNODE);
7016 dgap_err("out of memory");
7020 s = dgap_getword(in);
7022 dgap_err("unexpected end of file");
7025 if (kstrtol(s, 0, &p->u.useintr)) {
7026 dgap_err("bad number for useintr");
7031 case TTSIZ: /* size of tty structure */
7032 if (dgap_checknode(p))
7034 p->next = dgap_newnode(TSNODE);
7036 dgap_err("out of memory");
7040 s = dgap_getword(in);
7042 dgap_err("unexpected end of file");
7045 if (kstrtol(s, 0, &p->u.ttysize)) {
7046 dgap_err("bad number for ttysize");
7051 case CHSIZ: /* channel structure size */
7052 if (dgap_checknode(p))
7054 p->next = dgap_newnode(CSNODE);
7056 dgap_err("out of memory");
7060 s = dgap_getword(in);
7062 dgap_err("unexpected end of file");
7065 if (kstrtol(s, 0, &p->u.chsize)) {
7066 dgap_err("bad number for chsize");
7071 case BSSIZ: /* board structure size */
7072 if (dgap_checknode(p))
7074 p->next = dgap_newnode(BSNODE);
7076 dgap_err("out of memory");
7080 s = dgap_getword(in);
7082 dgap_err("unexpected end of file");
7085 if (kstrtol(s, 0, &p->u.bssize)) {
7086 dgap_err("bad number for bssize");
7091 case UNTSIZ: /* sched structure size */
7092 if (dgap_checknode(p))
7094 p->next = dgap_newnode(USNODE);
7096 dgap_err("out of memory");
7100 s = dgap_getword(in);
7102 dgap_err("unexpected end of file");
7105 if (kstrtol(s, 0, &p->u.unsize)) {
7106 dgap_err("bad number for schedsize");
7111 case F2SIZ: /* f2200 structure size */
7112 if (dgap_checknode(p))
7114 p->next = dgap_newnode(FSNODE);
7116 dgap_err("out of memory");
7120 s = dgap_getword(in);
7122 dgap_err("unexpected end of file");
7125 if (kstrtol(s, 0, &p->u.f2size)) {
7126 dgap_err("bad number for f2200size");
7131 case VPSIZ: /* vpix structure size */
7132 if (dgap_checknode(p))
7134 p->next = dgap_newnode(VSNODE);
7136 dgap_err("out of memory");
7140 s = dgap_getword(in);
7142 dgap_err("unexpected end of file");
7145 if (kstrtol(s, 0, &p->u.vpixsize)) {
7146 dgap_err("bad number for vpixsize");
7155 * dgap_sindex: much like index(), but it looks for a match of any character in
7156 * the group, and returns that position. If the first character is a ^, then
7157 * this will match the first occurrence not in that group.
7159 static char *dgap_sindex(char *string, char *group)
7163 if (!string || !group)
7164 return (char *) NULL;
7166 if (*group == '^') {
7168 for (; *string; string++) {
7169 for (ptr = group; *ptr; ptr++) {
7170 if (*ptr == *string)
7177 for (; *string; string++) {
7178 for (ptr = group; *ptr; ptr++) {
7179 if (*ptr == *string)
7185 return (char *) NULL;
7189 * Get a token from the input file; return 0 if end of file is reached
7191 static int dgap_gettok(char **in, struct cnode *p)
7196 if (strstr(dgap_cword, "boar")) {
7197 w = dgap_getword(in);
7198 snprintf(dgap_cword, MAXCWORD, "%s", w);
7199 for (t = dgap_tlist; t->token != 0; t++) {
7200 if (!strcmp(w, t->string))
7203 dgap_err("board !!type not specified");
7206 while ((w = dgap_getword(in))) {
7207 snprintf(dgap_cword, MAXCWORD, "%s", w);
7208 for (t = dgap_tlist; t->token != 0; t++) {
7209 if (!strcmp(w, t->string))
7218 * get a word from the input stream, also keep track of current line number.
7219 * words are separated by whitespace.
7221 static char *dgap_getword(char **in)
7223 char *ret_ptr = *in;
7225 char *ptr = dgap_sindex(*in, " \t\n");
7227 /* If no word found, return null */
7231 /* Mark new location for our buffer */
7235 /* Eat any extra spaces/tabs/newlines that might be present */
7236 while (*in && **in && ((**in == ' ') ||
7247 * print an error message, giving the line number in the file where
7248 * the error occurred.
7250 static void dgap_err(char *s)
7252 pr_err("dgap: parse: %s\n", s);
7256 * allocate a new configuration node of type t
7258 static struct cnode *dgap_newnode(int t)
7262 n = kzalloc(sizeof(struct cnode), GFP_KERNEL);
7269 * dgap_checknode: see if all the necessary info has been supplied for a node
7270 * before creating the next node.
7272 static int dgap_checknode(struct cnode *p)
7276 if (p->u.board.v_type == 0) {
7277 dgap_err("board type !not specified");
7284 if (p->u.line.v_speed == 0) {
7285 dgap_err("line speed not specified");
7291 if (p->u.conc.v_type == 0) {
7292 dgap_err("concentrator type not specified");
7295 if (p->u.conc.v_speed == 0) {
7296 dgap_err("concentrator line speed not specified");
7299 if (p->u.conc.v_nport == 0) {
7300 dgap_err("number of ports on concentrator not specified");
7303 if (p->u.conc.v_id == 0) {
7304 dgap_err("concentrator id letter not specified");
7310 if (p->u.module.v_type == 0) {
7311 dgap_err("EBI module type not specified");
7314 if (p->u.module.v_nport == 0) {
7315 dgap_err("number of ports on EBI module not specified");
7318 if (p->u.module.v_id == 0) {
7319 dgap_err("EBI module id letter not specified");
7328 * Given a board pointer, returns whether we should use interrupts or not.
7330 static uint dgap_config_get_useintr(struct board_t *bd)
7337 for (p = bd->bd_config; p; p = p->next) {
7338 if (p->type == INTRNODE) {
7340 * check for pcxr types.
7342 return p->u.useintr;
7346 /* If not found, then don't turn on interrupts. */
7351 * Given a board pointer, returns whether we turn on altpin or not.
7353 static uint dgap_config_get_altpin(struct board_t *bd)
7360 for (p = bd->bd_config; p; p = p->next) {
7361 if (p->type == ANODE) {
7363 * check for pcxr types.
7369 /* If not found, then don't turn on interrupts. */
7374 * Given a specific type of board, if found, detached link and
7375 * returns the first occurrence in the list.
7377 static struct cnode *dgap_find_config(int type, int bus, int slot)
7379 struct cnode *p, *prev, *prev2, *found;
7387 if (p->type != BNODE)
7390 if (p->u.board.type != type)
7393 if (p->u.board.v_pcibus &&
7394 p->u.board.pcibus != bus)
7397 if (p->u.board.v_pcislot &&
7398 p->u.board.pcislot != slot)
7403 * Keep walking thru the list till we
7404 * find the next board.
7410 if (p->type != BNODE)
7414 * Mark the end of our 1 board
7420 * Link the "next" board to the
7421 * previous board, effectively
7422 * "unlinking" our board from
7430 * It must be the last board in the list.
7439 * Given a board pointer, walks the config link, counting up
7440 * all ports user specified should be on the board.
7441 * (This does NOT mean they are all actually present right now tho)
7443 static uint dgap_config_get_num_prts(struct board_t *bd)
7451 for (p = bd->bd_config; p; p = p->next) {
7456 * check for pcxr types.
7458 if (p->u.board.type > EPCFE)
7459 count += p->u.board.nport;
7462 count += p->u.conc.nport;
7465 count += p->u.module.nport;
7472 static char *dgap_create_config_string(struct board_t *bd, char *string)
7484 for (p = bd->bd_config; p; p = p->next) {
7490 *ptr = p->u.line.speed;
7495 * Because the EPC/con concentrators can have EM modules
7496 * hanging off of them, we have to walk ahead in the
7497 * list and keep adding the number of ports on each EM
7498 * to the config. UGH!
7500 speed = p->u.conc.speed;
7502 if (q && (q->type == MNODE)) {
7503 *ptr = (p->u.conc.nport + 0x80);
7506 while (q->next && (q->next->type) == MNODE) {
7507 *ptr = (q->u.module.nport + 0x80);
7512 *ptr = q->u.module.nport;
7515 *ptr = p->u.conc.nport;