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 #define pr_fmt(fmt) "dgap: " fmt
46 #include <linux/kernel.h>
47 #include <linux/module.h>
48 #include <linux/pci.h>
49 #include <linux/delay.h> /* For udelay */
50 #include <linux/slab.h>
51 #include <linux/uaccess.h>
52 #include <linux/sched.h>
54 #include <linux/interrupt.h> /* For tasklet and interrupt structs/defines */
55 #include <linux/ctype.h>
56 #include <linux/tty.h>
57 #include <linux/tty_flip.h>
58 #include <linux/serial_reg.h>
59 #include <linux/io.h> /* For read[bwl]/write[bwl] */
61 #include <linux/string.h>
62 #include <linux/device.h>
63 #include <linux/kdev_t.h>
64 #include <linux/firmware.h>
68 MODULE_LICENSE("GPL");
69 MODULE_AUTHOR("Digi International, http://www.digi.com");
70 MODULE_DESCRIPTION("Driver for the Digi International EPCA PCI based product line");
71 MODULE_SUPPORTED_DEVICE("dgap");
73 static int dgap_start(void);
74 static void dgap_init_globals(void);
75 static struct board_t *dgap_found_board(struct pci_dev *pdev, int id,
77 static void dgap_cleanup_board(struct board_t *brd);
78 static void dgap_poll_handler(ulong dummy);
79 static int dgap_init_one(struct pci_dev *pdev, const struct pci_device_id *ent);
80 static void dgap_remove_one(struct pci_dev *dev);
81 static int dgap_do_remap(struct board_t *brd);
82 static void dgap_release_remap(struct board_t *brd);
83 static irqreturn_t dgap_intr(int irq, void *voidbrd);
85 static int dgap_tty_open(struct tty_struct *tty, struct file *file);
86 static void dgap_tty_close(struct tty_struct *tty, struct file *file);
87 static int dgap_block_til_ready(struct tty_struct *tty, struct file *file,
88 struct channel_t *ch);
89 static int dgap_tty_ioctl(struct tty_struct *tty, unsigned int cmd,
91 static int dgap_tty_digigeta(struct channel_t *ch,
92 struct digi_t __user *retinfo);
93 static int dgap_tty_digiseta(struct channel_t *ch, struct board_t *bd,
94 struct un_t *un, struct digi_t __user *new_info);
95 static int dgap_tty_digigetedelay(struct tty_struct *tty, int __user *retinfo);
96 static int dgap_tty_digisetedelay(struct channel_t *ch, struct board_t *bd,
97 struct un_t *un, int __user *new_info);
98 static int dgap_tty_write_room(struct tty_struct *tty);
99 static int dgap_tty_chars_in_buffer(struct tty_struct *tty);
100 static void dgap_tty_start(struct tty_struct *tty);
101 static void dgap_tty_stop(struct tty_struct *tty);
102 static void dgap_tty_throttle(struct tty_struct *tty);
103 static void dgap_tty_unthrottle(struct tty_struct *tty);
104 static void dgap_tty_flush_chars(struct tty_struct *tty);
105 static void dgap_tty_flush_buffer(struct tty_struct *tty);
106 static void dgap_tty_hangup(struct tty_struct *tty);
107 static int dgap_wait_for_drain(struct tty_struct *tty);
108 static int dgap_set_modem_info(struct channel_t *ch, struct board_t *bd,
109 struct un_t *un, unsigned int command,
110 unsigned int __user *value);
111 static int dgap_get_modem_info(struct channel_t *ch,
112 unsigned int __user *value);
113 static int dgap_tty_digisetcustombaud(struct channel_t *ch, struct board_t *bd,
114 struct un_t *un, int __user *new_info);
115 static int dgap_tty_digigetcustombaud(struct channel_t *ch, struct un_t *un,
116 int __user *retinfo);
117 static int dgap_tty_tiocmget(struct tty_struct *tty);
118 static int dgap_tty_tiocmset(struct tty_struct *tty, unsigned int set,
120 static int dgap_tty_send_break(struct tty_struct *tty, int msec);
121 static void dgap_tty_wait_until_sent(struct tty_struct *tty, int timeout);
122 static int dgap_tty_write(struct tty_struct *tty, const unsigned char *buf,
124 static void dgap_tty_set_termios(struct tty_struct *tty,
125 struct ktermios *old_termios);
126 static int dgap_tty_put_char(struct tty_struct *tty, unsigned char c);
127 static void dgap_tty_send_xchar(struct tty_struct *tty, char ch);
129 static int dgap_tty_register(struct board_t *brd);
130 static void dgap_tty_unregister(struct board_t *brd);
131 static int dgap_tty_init(struct board_t *);
132 static void dgap_tty_free(struct board_t *);
133 static void dgap_cleanup_tty(struct board_t *);
134 static void dgap_carrier(struct channel_t *ch);
135 static void dgap_input(struct channel_t *ch);
138 * Our function prototypes from dgap_fep5
140 static void dgap_cmdw_ext(struct channel_t *ch, u16 cmd, u16 word, uint ncmds);
141 static int dgap_event(struct board_t *bd);
143 static void dgap_poll_tasklet(unsigned long data);
144 static void dgap_cmdb(struct channel_t *ch, u8 cmd, u8 byte1,
145 u8 byte2, uint ncmds);
146 static void dgap_cmdw(struct channel_t *ch, u8 cmd, u16 word, uint ncmds);
147 static void dgap_wmove(struct channel_t *ch, char *buf, uint cnt);
148 static int dgap_param(struct channel_t *ch, struct board_t *bd, u32 un_type);
149 static void dgap_parity_scan(struct channel_t *ch, unsigned char *cbuf,
150 unsigned char *fbuf, int *len);
151 static uint dgap_get_custom_baud(struct channel_t *ch);
152 static void dgap_firmware_reset_port(struct channel_t *ch);
155 * Function prototypes from dgap_parse.c.
157 static int dgap_gettok(char **in);
158 static char *dgap_getword(char **in);
159 static int dgap_checknode(struct cnode *p);
162 * Function prototypes from dgap_sysfs.h
164 static void dgap_create_ports_sysfiles(struct board_t *bd);
165 static void dgap_remove_ports_sysfiles(struct board_t *bd);
167 static int dgap_create_driver_sysfiles(struct pci_driver *);
168 static void dgap_remove_driver_sysfiles(struct pci_driver *);
170 static void dgap_create_tty_sysfs(struct un_t *un, struct device *c);
171 static void dgap_remove_tty_sysfs(struct device *c);
174 * Function prototypes from dgap_parse.h
176 static int dgap_parsefile(char **in);
177 static struct cnode *dgap_find_config(int type, int bus, int slot);
178 static uint dgap_config_get_num_prts(struct board_t *bd);
179 static char *dgap_create_config_string(struct board_t *bd, char *string);
180 static uint dgap_config_get_useintr(struct board_t *bd);
181 static uint dgap_config_get_altpin(struct board_t *bd);
183 static int dgap_ms_sleep(ulong ms);
184 static void dgap_do_bios_load(struct board_t *brd, const u8 *ubios, int len);
185 static void dgap_do_fep_load(struct board_t *brd, const u8 *ufep, int len);
186 #ifdef DIGI_CONCENTRATORS_SUPPORTED
187 static void dgap_do_conc_load(struct board_t *brd, u8 *uaddr, int len);
189 static int dgap_alloc_flipbuf(struct board_t *brd);
190 static void dgap_free_flipbuf(struct board_t *brd);
191 static int dgap_request_irq(struct board_t *brd);
192 static void dgap_free_irq(struct board_t *brd);
194 static void dgap_get_vpd(struct board_t *brd);
195 static void dgap_do_reset_board(struct board_t *brd);
196 static int dgap_test_bios(struct board_t *brd);
197 static int dgap_test_fep(struct board_t *brd);
198 static int dgap_tty_register_ports(struct board_t *brd);
199 static int dgap_firmware_load(struct pci_dev *pdev, int card_type,
200 struct board_t *brd);
201 static void dgap_cleanup_nodes(void);
203 static void dgap_cleanup_module(void);
205 module_exit(dgap_cleanup_module);
208 * File operations permitted on Control/Management major.
210 static const struct file_operations dgap_board_fops = {
211 .owner = THIS_MODULE,
214 static uint dgap_numboards;
215 static struct board_t *dgap_board[MAXBOARDS];
216 static ulong dgap_poll_counter;
217 static int dgap_driver_state = DRIVER_INITIALIZED;
218 static int dgap_poll_tick = 20; /* Poll interval - 20 ms */
220 static struct class *dgap_class;
222 static struct board_t *dgap_boards_by_major[256];
223 static uint dgap_count = 500;
228 static DEFINE_SPINLOCK(dgap_poll_lock); /* Poll scheduling lock */
229 static ulong dgap_poll_time; /* Time of next poll */
230 static uint dgap_poll_stop; /* Used to tell poller to stop */
231 static struct timer_list dgap_poll_timer;
236 Card Model Number of Ports Interface
237 ----------------------------------------------------------------
238 Acceleport Xem 4 - 64 (EIA232 & EIA422)
239 Acceleport Xr 4 & 8 (EIA232)
240 Acceleport Xr 920 4 & 8 (EIA232)
241 Acceleport C/X 8 - 128 (EIA232)
242 Acceleport EPC/X 8 - 224 (EIA232)
243 Acceleport Xr/422 4 & 8 (EIA422)
244 Acceleport 2r/920 2 (EIA232)
245 Acceleport 4r/920 4 (EIA232)
246 Acceleport 8r/920 8 (EIA232)
248 IBM 8-Port Asynchronous PCI Adapter (EIA232)
249 IBM 128-Port Asynchronous PCI Adapter (EIA232 & EIA422)
252 static struct pci_device_id dgap_pci_tbl[] = {
253 { DIGI_VID, PCI_DEV_XEM_DID, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0 },
254 { DIGI_VID, PCI_DEV_CX_DID, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 1 },
255 { DIGI_VID, PCI_DEV_CX_IBM_DID, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 2 },
256 { DIGI_VID, PCI_DEV_EPCJ_DID, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 3 },
257 { DIGI_VID, PCI_DEV_920_2_DID, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 4 },
258 { DIGI_VID, PCI_DEV_920_4_DID, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 5 },
259 { DIGI_VID, PCI_DEV_920_8_DID, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 6 },
260 { DIGI_VID, PCI_DEV_XR_DID, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 7 },
261 { DIGI_VID, PCI_DEV_XRJ_DID, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 8 },
262 { DIGI_VID, PCI_DEV_XR_422_DID, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 9 },
263 { DIGI_VID, PCI_DEV_XR_IBM_DID, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 10 },
264 { DIGI_VID, PCI_DEV_XR_SAIP_DID, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 11 },
265 { DIGI_VID, PCI_DEV_XR_BULL_DID, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 12 },
266 { DIGI_VID, PCI_DEV_920_8_HP_DID, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 13 },
267 { DIGI_VID, PCI_DEV_XEM_HP_DID, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 14 },
268 {0,} /* 0 terminated list. */
270 MODULE_DEVICE_TABLE(pci, dgap_pci_tbl);
273 * A generic list of Product names, PCI Vendor ID, and PCI Device ID.
282 static struct board_id dgap_ids[] = {
283 { PPCM, PCI_DEV_XEM_NAME, 64, (T_PCXM|T_PCLITE|T_PCIBUS) },
284 { PCX, PCI_DEV_CX_NAME, 128, (T_CX|T_PCIBUS) },
285 { PCX, PCI_DEV_CX_IBM_NAME, 128, (T_CX|T_PCIBUS) },
286 { PEPC, PCI_DEV_EPCJ_NAME, 224, (T_EPC|T_PCIBUS) },
287 { APORT2_920P, PCI_DEV_920_2_NAME, 2, (T_PCXR|T_PCLITE|T_PCIBUS) },
288 { APORT4_920P, PCI_DEV_920_4_NAME, 4, (T_PCXR|T_PCLITE|T_PCIBUS) },
289 { APORT8_920P, PCI_DEV_920_8_NAME, 8, (T_PCXR|T_PCLITE|T_PCIBUS) },
290 { PAPORT8, PCI_DEV_XR_NAME, 8, (T_PCXR|T_PCLITE|T_PCIBUS) },
291 { PAPORT8, PCI_DEV_XRJ_NAME, 8, (T_PCXR|T_PCLITE|T_PCIBUS) },
292 { PAPORT8, PCI_DEV_XR_422_NAME, 8, (T_PCXR|T_PCLITE|T_PCIBUS) },
293 { PAPORT8, PCI_DEV_XR_IBM_NAME, 8, (T_PCXR|T_PCLITE|T_PCIBUS) },
294 { PAPORT8, PCI_DEV_XR_SAIP_NAME, 8, (T_PCXR|T_PCLITE|T_PCIBUS) },
295 { PAPORT8, PCI_DEV_XR_BULL_NAME, 8, (T_PCXR|T_PCLITE|T_PCIBUS) },
296 { APORT8_920P, PCI_DEV_920_8_HP_NAME, 8, (T_PCXR|T_PCLITE|T_PCIBUS) },
297 { PPCM, PCI_DEV_XEM_HP_NAME, 64, (T_PCXM|T_PCLITE|T_PCIBUS) },
298 {0,} /* 0 terminated list. */
301 static struct pci_driver dgap_driver = {
303 .probe = dgap_init_one,
304 .id_table = dgap_pci_tbl,
305 .remove = dgap_remove_one,
308 struct firmware_info {
309 u8 *conf_name; /* dgap.conf */
310 u8 *bios_name; /* BIOS filename */
311 u8 *fep_name; /* FEP filename */
312 u8 *con_name; /* Concentrator filename FIXME*/
313 int num; /* sequence number */
317 * Firmware - BIOS, FEP, and CONC filenames
319 static struct firmware_info fw_info[] = {
320 { "dgap/dgap.conf", "dgap/sxbios.bin", "dgap/sxfep.bin", NULL, 0 },
321 { "dgap/dgap.conf", "dgap/cxpbios.bin", "dgap/cxpfep.bin", NULL, 1 },
322 { "dgap/dgap.conf", "dgap/cxpbios.bin", "dgap/cxpfep.bin", NULL, 2 },
323 { "dgap/dgap.conf", "dgap/pcibios.bin", "dgap/pcifep.bin", NULL, 3 },
324 { "dgap/dgap.conf", "dgap/xrbios.bin", "dgap/xrfep.bin", NULL, 4 },
325 { "dgap/dgap.conf", "dgap/xrbios.bin", "dgap/xrfep.bin", NULL, 5 },
326 { "dgap/dgap.conf", "dgap/xrbios.bin", "dgap/xrfep.bin", NULL, 6 },
327 { "dgap/dgap.conf", "dgap/xrbios.bin", "dgap/xrfep.bin", NULL, 7 },
328 { "dgap/dgap.conf", "dgap/xrbios.bin", "dgap/xrfep.bin", NULL, 8 },
329 { "dgap/dgap.conf", "dgap/xrbios.bin", "dgap/xrfep.bin", NULL, 9 },
330 { "dgap/dgap.conf", "dgap/xrbios.bin", "dgap/xrfep.bin", NULL, 10 },
331 { "dgap/dgap.conf", "dgap/xrbios.bin", "dgap/xrfep.bin", NULL, 11 },
332 { "dgap/dgap.conf", "dgap/xrbios.bin", "dgap/xrfep.bin", NULL, 12 },
333 { "dgap/dgap.conf", "dgap/xrbios.bin", "dgap/xrfep.bin", NULL, 13 },
334 { "dgap/dgap.conf", "dgap/sxbios.bin", "dgap/sxfep.bin", NULL, 14 },
339 * Default transparent print information.
341 static struct digi_t dgap_digi_init = {
342 .digi_flags = DIGI_COOK, /* Flags */
343 .digi_maxcps = 100, /* Max CPS */
344 .digi_maxchar = 50, /* Max chars in print queue */
345 .digi_bufsize = 100, /* Printer buffer size */
346 .digi_onlen = 4, /* size of printer on string */
347 .digi_offlen = 4, /* size of printer off string */
348 .digi_onstr = "\033[5i", /* ANSI printer on string ] */
349 .digi_offstr = "\033[4i", /* ANSI printer off string ] */
350 .digi_term = "ansi" /* default terminal type */
354 * Define a local default termios struct. All ports will be created
355 * with this termios initially.
357 * This defines a raw port at 9600 baud, 8 data bits, no parity,
361 static struct ktermios dgap_default_termios = {
362 .c_iflag = (DEFAULT_IFLAGS), /* iflags */
363 .c_oflag = (DEFAULT_OFLAGS), /* oflags */
364 .c_cflag = (DEFAULT_CFLAGS), /* cflags */
365 .c_lflag = (DEFAULT_LFLAGS), /* lflags */
370 static const struct tty_operations dgap_tty_ops = {
371 .open = dgap_tty_open,
372 .close = dgap_tty_close,
373 .write = dgap_tty_write,
374 .write_room = dgap_tty_write_room,
375 .flush_buffer = dgap_tty_flush_buffer,
376 .chars_in_buffer = dgap_tty_chars_in_buffer,
377 .flush_chars = dgap_tty_flush_chars,
378 .ioctl = dgap_tty_ioctl,
379 .set_termios = dgap_tty_set_termios,
380 .stop = dgap_tty_stop,
381 .start = dgap_tty_start,
382 .throttle = dgap_tty_throttle,
383 .unthrottle = dgap_tty_unthrottle,
384 .hangup = dgap_tty_hangup,
385 .put_char = dgap_tty_put_char,
386 .tiocmget = dgap_tty_tiocmget,
387 .tiocmset = dgap_tty_tiocmset,
388 .break_ctl = dgap_tty_send_break,
389 .wait_until_sent = dgap_tty_wait_until_sent,
390 .send_xchar = dgap_tty_send_xchar
394 * Our needed internal static variables from dgap_parse.c
396 static struct cnode dgap_head;
398 static char dgap_cword[MAXCWORD];
405 static struct toklist dgap_brdtype[] = {
406 { PCX, "Digi_AccelePort_C/X_PCI" },
407 { PEPC, "Digi_AccelePort_EPC/X_PCI" },
408 { PPCM, "Digi_AccelePort_Xem_PCI" },
409 { APORT2_920P, "Digi_AccelePort_2r_920_PCI" },
410 { APORT4_920P, "Digi_AccelePort_4r_920_PCI" },
411 { APORT8_920P, "Digi_AccelePort_8r_920_PCI" },
412 { PAPORT4, "Digi_AccelePort_4r_PCI(EIA-232/RS-422)" },
413 { PAPORT8, "Digi_AccelePort_8r_PCI(EIA-232/RS-422)" },
417 static struct toklist dgap_tlist[] = {
418 { BEGIN, "config_begin" },
419 { END, "config_end" },
422 { PCIINFO, "pciinfo" },
425 { CONC, "concentrator" },
435 { CONNECT, "connect" },
436 { METHOD, "method" },
437 { STATUS, "status" },
438 { CUSTOM, "Custom" },
444 { NPORTS, "nports" },
449 { ALTPIN, "altpin" },
450 { USEINTR, "useintr" },
451 { TTSIZ, "ttysize" },
453 { BSSIZ, "boardsize" },
454 { UNTSIZ, "schedsize" },
455 { F2SIZ, "f2200size" },
456 { VPSIZ, "vpixsize" },
460 /************************************************************************
462 * Driver load/unload functions
464 ************************************************************************/
469 * Module load. This is where it all starts.
471 static int dgap_init_module(void)
475 pr_info("%s, Digi International Part Number %s\n", DG_NAME, DG_PART);
481 rc = pci_register_driver(&dgap_driver);
485 rc = dgap_create_driver_sysfiles(&dgap_driver);
489 dgap_driver_state = DRIVER_READY;
495 dgap_cleanup_module();
499 module_init(dgap_init_module);
504 static int dgap_start(void)
508 struct device *device;
511 * make sure that the globals are
512 * init'd before we do anything else
518 pr_info("For the tools package please visit http://www.digi.com\n");
521 * Register our base character device into the kernel.
525 * Register management/dpa devices
527 rc = register_chrdev(DIGI_DGAP_MAJOR, "dgap", &dgap_board_fops);
531 dgap_class = class_create(THIS_MODULE, "dgap_mgmt");
532 if (IS_ERR(dgap_class)) {
533 rc = PTR_ERR(dgap_class);
537 device = device_create(dgap_class, NULL,
538 MKDEV(DIGI_DGAP_MAJOR, 0),
540 if (IS_ERR(device)) {
541 rc = PTR_ERR(device);
545 /* Start the poller */
546 spin_lock_irqsave(&dgap_poll_lock, flags);
547 init_timer(&dgap_poll_timer);
548 dgap_poll_timer.function = dgap_poll_handler;
549 dgap_poll_timer.data = 0;
550 dgap_poll_time = jiffies + dgap_jiffies_from_ms(dgap_poll_tick);
551 dgap_poll_timer.expires = dgap_poll_time;
552 spin_unlock_irqrestore(&dgap_poll_lock, flags);
554 add_timer(&dgap_poll_timer);
559 class_destroy(dgap_class);
561 unregister_chrdev(DIGI_DGAP_MAJOR, "dgap");
565 static int dgap_init_one(struct pci_dev *pdev, const struct pci_device_id *ent)
570 if (dgap_numboards >= MAXBOARDS)
573 rc = pci_enable_device(pdev);
577 brd = dgap_found_board(pdev, ent->driver_data, dgap_numboards);
581 rc = dgap_firmware_load(pdev, ent->driver_data, brd);
585 rc = dgap_alloc_flipbuf(brd);
589 rc = dgap_tty_register(brd);
593 rc = dgap_request_irq(brd);
598 * Do tty device initialization.
600 rc = dgap_tty_init(brd);
604 rc = dgap_tty_register_ports(brd);
608 brd->state = BOARD_READY;
609 brd->dpastatus = BD_RUNNING;
611 dgap_board[dgap_numboards++] = brd;
620 dgap_tty_unregister(brd);
622 dgap_free_flipbuf(brd);
624 dgap_cleanup_nodes();
625 dgap_release_remap(brd);
631 static void dgap_remove_one(struct pci_dev *dev)
637 * dgap_cleanup_module()
639 * Module unload. This is where it all ends.
641 static void dgap_cleanup_module(void)
646 spin_lock_irqsave(&dgap_poll_lock, lock_flags);
648 spin_unlock_irqrestore(&dgap_poll_lock, lock_flags);
650 /* Turn off poller right away. */
651 del_timer_sync(&dgap_poll_timer);
653 dgap_remove_driver_sysfiles(&dgap_driver);
655 device_destroy(dgap_class, MKDEV(DIGI_DGAP_MAJOR, 0));
656 class_destroy(dgap_class);
657 unregister_chrdev(DIGI_DGAP_MAJOR, "dgap");
659 for (i = 0; i < dgap_numboards; ++i) {
660 dgap_remove_ports_sysfiles(dgap_board[i]);
661 dgap_cleanup_tty(dgap_board[i]);
662 dgap_cleanup_board(dgap_board[i]);
665 dgap_cleanup_nodes();
668 pci_unregister_driver(&dgap_driver);
672 * dgap_cleanup_board()
674 * Free all the memory associated with a board
676 static void dgap_cleanup_board(struct board_t *brd)
680 if (!brd || brd->magic != DGAP_BOARD_MAGIC)
685 tasklet_kill(&brd->helper_tasklet);
687 if (brd->re_map_port) {
688 release_mem_region(brd->membase + 0x200000, 0x200000);
689 iounmap(brd->re_map_port);
690 brd->re_map_port = NULL;
693 if (brd->re_map_membase) {
694 release_mem_region(brd->membase, 0x200000);
695 iounmap(brd->re_map_membase);
696 brd->re_map_membase = NULL;
699 /* Free all allocated channels structs */
700 for (i = 0; i < MAXPORTS ; i++)
701 kfree(brd->channels[i]);
704 kfree(brd->flipflagbuf);
706 dgap_board[brd->boardnum] = NULL;
714 * A board has been found, init it.
716 static struct board_t *dgap_found_board(struct pci_dev *pdev, int id,
720 unsigned int pci_irq;
724 /* get the board structure and prep it */
725 brd = kzalloc(sizeof(struct board_t), GFP_KERNEL);
727 return ERR_PTR(-ENOMEM);
729 /* store the info for the board we've found */
730 brd->magic = DGAP_BOARD_MAGIC;
731 brd->boardnum = boardnum;
732 brd->vendor = dgap_pci_tbl[id].vendor;
733 brd->device = dgap_pci_tbl[id].device;
735 brd->pci_bus = pdev->bus->number;
736 brd->pci_slot = PCI_SLOT(pdev->devfn);
737 brd->name = dgap_ids[id].name;
738 brd->maxports = dgap_ids[id].maxports;
739 brd->type = dgap_ids[id].config_type;
740 brd->dpatype = dgap_ids[id].dpatype;
741 brd->dpastatus = BD_NOFEP;
742 init_waitqueue_head(&brd->state_wait);
744 spin_lock_init(&brd->bd_lock);
747 brd->inhibit_poller = FALSE;
748 brd->wait_for_bios = 0;
749 brd->wait_for_fep = 0;
751 for (i = 0; i < MAXPORTS; i++)
752 brd->channels[i] = NULL;
754 /* store which card & revision we have */
755 pci_read_config_word(pdev, PCI_SUBSYSTEM_VENDOR_ID, &brd->subvendor);
756 pci_read_config_word(pdev, PCI_SUBSYSTEM_ID, &brd->subdevice);
757 pci_read_config_byte(pdev, PCI_REVISION_ID, &brd->rev);
762 /* get the PCI Base Address Registers */
764 /* Xr Jupiter and EPC use BAR 2 */
765 if (brd->device == PCI_DEV_XRJ_DID || brd->device == PCI_DEV_EPCJ_DID) {
766 brd->membase = pci_resource_start(pdev, 2);
767 brd->membase_end = pci_resource_end(pdev, 2);
769 /* Everyone else uses BAR 0 */
771 brd->membase = pci_resource_start(pdev, 0);
772 brd->membase_end = pci_resource_end(pdev, 0);
780 if (brd->membase & 1)
786 * On the PCI boards, there is no IO space allocated
787 * The I/O registers will be in the first 3 bytes of the
788 * upper 2MB of the 4MB memory space. The board memory
789 * will be mapped into the low 2MB of the 4MB memory space
791 brd->port = brd->membase + PCI_IO_OFFSET;
792 brd->port_end = brd->port + PCI_IO_SIZE;
795 * Special initialization for non-PLX boards
797 if (brd->device != PCI_DEV_XRJ_DID && brd->device != PCI_DEV_EPCJ_DID) {
800 pci_write_config_byte(pdev, 0x40, 0);
801 pci_write_config_byte(pdev, 0x46, 0);
803 /* Limit burst length to 2 doubleword transactions */
804 pci_write_config_byte(pdev, 0x42, 1);
807 * Enable IO and mem if not already done.
808 * This was needed for support on Itanium.
810 pci_read_config_word(pdev, PCI_COMMAND, &cmd);
811 cmd |= (PCI_COMMAND_IO | PCI_COMMAND_MEMORY);
812 pci_write_config_word(pdev, PCI_COMMAND, cmd);
815 /* init our poll helper tasklet */
816 tasklet_init(&brd->helper_tasklet, dgap_poll_tasklet,
817 (unsigned long) brd);
819 ret = dgap_do_remap(brd);
823 pr_info("dgap: board %d: %s (rev %d), irq %ld\n",
824 boardnum, brd->name, brd->rev, brd->irq);
835 static int dgap_request_irq(struct board_t *brd)
839 if (!brd || brd->magic != DGAP_BOARD_MAGIC)
843 * Set up our interrupt handler if we are set to do interrupts.
845 if (dgap_config_get_useintr(brd) && brd->irq) {
847 rc = request_irq(brd->irq, dgap_intr, IRQF_SHARED, "DGAP", brd);
855 static void dgap_free_irq(struct board_t *brd)
857 if (brd->intr_used && brd->irq)
858 free_irq(brd->irq, brd);
861 static int dgap_firmware_load(struct pci_dev *pdev, int card_type,
864 const struct firmware *fw;
867 char *dgap_config_buf;
870 dgap_do_reset_board(brd);
872 if (fw_info[card_type].conf_name) {
873 ret = request_firmware(&fw, fw_info[card_type].conf_name,
876 dev_err(&pdev->dev, "config file %s not found\n",
877 fw_info[card_type].conf_name);
881 dgap_config_buf = kzalloc(fw->size + 1, GFP_KERNEL);
882 if (!dgap_config_buf) {
883 release_firmware(fw);
887 memcpy(dgap_config_buf, fw->data, fw->size);
888 release_firmware(fw);
891 * preserve dgap_config_buf
892 * as dgap_parsefile would
893 * otherwise alter it.
895 tmp_ptr = dgap_config_buf;
897 if (dgap_parsefile(&tmp_ptr) != 0) {
898 kfree(dgap_config_buf);
901 kfree(dgap_config_buf);
905 * Match this board to a config the user created for us.
908 dgap_find_config(brd->type, brd->pci_bus, brd->pci_slot);
911 * Because the 4 port Xr products share the same PCI ID
912 * as the 8 port Xr products, if we receive a NULL config
913 * back, and this is a PAPORT8 board, retry with a
914 * PAPORT4 attempt as well.
916 if (brd->type == PAPORT8 && !brd->bd_config)
918 dgap_find_config(PAPORT4, brd->pci_bus, brd->pci_slot);
920 if (!brd->bd_config) {
921 dev_err(&pdev->dev, "No valid configuration found\n");
925 if (fw_info[card_type].bios_name) {
926 ret = request_firmware(&fw, fw_info[card_type].bios_name,
929 dev_err(&pdev->dev, "bios file %s not found\n",
930 fw_info[card_type].bios_name);
933 dgap_do_bios_load(brd, fw->data, fw->size);
934 release_firmware(fw);
936 /* Wait for BIOS to test board... */
937 ret = dgap_test_bios(brd);
942 if (fw_info[card_type].fep_name) {
943 ret = request_firmware(&fw, fw_info[card_type].fep_name,
946 dev_err(&pdev->dev, "dgap: fep file %s not found\n",
947 fw_info[card_type].fep_name);
950 dgap_do_fep_load(brd, fw->data, fw->size);
951 release_firmware(fw);
953 /* Wait for FEP to load on board... */
954 ret = dgap_test_fep(brd);
959 #ifdef DIGI_CONCENTRATORS_SUPPORTED
961 * If this is a CX or EPCX, we need to see if the firmware
962 * is requesting a concentrator image from us.
964 if ((bd->type == PCX) || (bd->type == PEPC)) {
965 chk_addr = (u16 *) (vaddr + DOWNREQ);
966 /* Nonzero if FEP is requesting concentrator image. */
967 check = readw(chk_addr);
968 vaddr = brd->re_map_membase;
971 if (fw_info[card_type].con_name && check && vaddr) {
972 ret = request_firmware(&fw, fw_info[card_type].con_name,
975 dev_err(&pdev->dev, "conc file %s not found\n",
976 fw_info[card_type].con_name);
979 /* Put concentrator firmware loading code here */
980 offset = readw((u16 *) (vaddr + DOWNREQ));
981 memcpy_toio(offset, fw->data, fw->size);
983 dgap_do_conc_load(brd, (char *)fw->data, fw->size)
984 release_firmware(fw);
994 static int dgap_do_remap(struct board_t *brd)
996 if (!brd || brd->magic != DGAP_BOARD_MAGIC)
999 if (!request_mem_region(brd->membase, 0x200000, "dgap"))
1002 if (!request_mem_region(brd->membase + PCI_IO_OFFSET, 0x200000,
1004 release_mem_region(brd->membase, 0x200000);
1008 brd->re_map_membase = ioremap(brd->membase, 0x200000);
1009 if (!brd->re_map_membase) {
1010 release_mem_region(brd->membase, 0x200000);
1011 release_mem_region(brd->membase + PCI_IO_OFFSET, 0x200000);
1015 brd->re_map_port = ioremap((brd->membase + PCI_IO_OFFSET), 0x200000);
1016 if (!brd->re_map_port) {
1017 release_mem_region(brd->membase, 0x200000);
1018 release_mem_region(brd->membase + PCI_IO_OFFSET, 0x200000);
1019 iounmap(brd->re_map_membase);
1026 static void dgap_release_remap(struct board_t *brd)
1028 release_mem_region(brd->membase, 0x200000);
1029 release_mem_region(brd->membase + PCI_IO_OFFSET, 0x200000);
1030 iounmap(brd->re_map_membase);
1032 /*****************************************************************************
1052 * As each timer expires, it determines (a) whether the "transmit"
1053 * waiter needs to be woken up, and (b) whether the poller needs to
1056 ******************************************************************************/
1058 static void dgap_poll_handler(ulong dummy)
1061 struct board_t *brd;
1062 unsigned long lock_flags;
1065 dgap_poll_counter++;
1068 * Do not start the board state machine until
1069 * driver tells us its up and running, and has
1070 * everything it needs.
1072 if (dgap_driver_state != DRIVER_READY)
1073 goto schedule_poller;
1076 * If we have just 1 board, or the system is not SMP,
1077 * then use the typical old style poller.
1078 * Otherwise, use our new tasklet based poller, which should
1079 * speed things up for multiple boards.
1081 if ((dgap_numboards == 1) || (num_online_cpus() <= 1)) {
1082 for (i = 0; i < dgap_numboards; i++) {
1084 brd = dgap_board[i];
1086 if (brd->state == BOARD_FAILED)
1088 if (!brd->intr_running)
1089 /* Call the real board poller directly */
1090 dgap_poll_tasklet((unsigned long) brd);
1094 * Go thru each board, kicking off a
1095 * tasklet for each if needed
1097 for (i = 0; i < dgap_numboards; i++) {
1098 brd = dgap_board[i];
1101 * Attempt to grab the board lock.
1103 * If we can't get it, no big deal, the next poll
1104 * will get it. Basically, I just really don't want
1105 * to spin in here, because I want to kick off my
1106 * tasklets as fast as I can, and then get out the
1109 if (!spin_trylock(&brd->bd_lock))
1113 * If board is in a failed state, don't bother
1114 * scheduling a tasklet
1116 if (brd->state == BOARD_FAILED) {
1117 spin_unlock(&brd->bd_lock);
1121 /* Schedule a poll helper task */
1122 if (!brd->intr_running)
1123 tasklet_schedule(&brd->helper_tasklet);
1126 * Can't do DGAP_UNLOCK here, as we don't have
1127 * lock_flags because we did a trylock above.
1129 spin_unlock(&brd->bd_lock);
1136 * Schedule ourself back at the nominal wakeup interval.
1138 spin_lock_irqsave(&dgap_poll_lock, lock_flags);
1139 dgap_poll_time += dgap_jiffies_from_ms(dgap_poll_tick);
1141 new_time = dgap_poll_time - jiffies;
1143 if ((ulong) new_time >= 2 * dgap_poll_tick) {
1145 jiffies + dgap_jiffies_from_ms(dgap_poll_tick);
1148 dgap_poll_timer.function = dgap_poll_handler;
1149 dgap_poll_timer.data = 0;
1150 dgap_poll_timer.expires = dgap_poll_time;
1151 spin_unlock_irqrestore(&dgap_poll_lock, lock_flags);
1153 if (!dgap_poll_stop)
1154 add_timer(&dgap_poll_timer);
1160 * Driver interrupt handler.
1162 static irqreturn_t dgap_intr(int irq, void *voidbrd)
1164 struct board_t *brd = (struct board_t *) voidbrd;
1170 * Check to make sure its for us.
1172 if (brd->magic != DGAP_BOARD_MAGIC)
1178 * Schedule tasklet to run at a better time.
1180 tasklet_schedule(&brd->helper_tasklet);
1185 * dgap_init_globals()
1187 * This is where we initialize the globals from the static insmod
1188 * configuration variables. These are declared near the head of
1191 static void dgap_init_globals(void)
1195 for (i = 0; i < MAXBOARDS; i++)
1196 dgap_board[i] = NULL;
1198 init_timer(&dgap_poll_timer);
1201 /************************************************************************
1205 ************************************************************************/
1210 * Put the driver to sleep for x ms's
1212 * Returns 0 if timed out, !0 (showing signal) if interrupted by a signal.
1214 static int dgap_ms_sleep(ulong ms)
1216 current->state = TASK_INTERRUPTIBLE;
1217 schedule_timeout((ms * HZ) / 1000);
1218 return signal_pending(current);
1221 /************************************************************************
1223 * TTY Initialization/Cleanup Functions
1225 ************************************************************************/
1228 * dgap_tty_register()
1230 * Init the tty subsystem for this board.
1232 static int dgap_tty_register(struct board_t *brd)
1236 brd->serial_driver = tty_alloc_driver(MAXPORTS, 0);
1237 if (IS_ERR(brd->serial_driver))
1238 return PTR_ERR(brd->serial_driver);
1240 snprintf(brd->serial_name, MAXTTYNAMELEN, "tty_dgap_%d_",
1242 brd->serial_driver->name = brd->serial_name;
1243 brd->serial_driver->name_base = 0;
1244 brd->serial_driver->major = 0;
1245 brd->serial_driver->minor_start = 0;
1246 brd->serial_driver->type = TTY_DRIVER_TYPE_SERIAL;
1247 brd->serial_driver->subtype = SERIAL_TYPE_NORMAL;
1248 brd->serial_driver->init_termios = dgap_default_termios;
1249 brd->serial_driver->driver_name = DRVSTR;
1250 brd->serial_driver->flags = (TTY_DRIVER_REAL_RAW |
1251 TTY_DRIVER_DYNAMIC_DEV |
1252 TTY_DRIVER_HARDWARE_BREAK);
1254 /* The kernel wants space to store pointers to tty_structs */
1255 brd->serial_driver->ttys =
1256 kzalloc(MAXPORTS * sizeof(struct tty_struct *), GFP_KERNEL);
1257 if (!brd->serial_driver->ttys) {
1259 goto free_serial_drv;
1263 * Entry points for driver. Called by the kernel from
1264 * tty_io.c and n_tty.c.
1266 tty_set_operations(brd->serial_driver, &dgap_tty_ops);
1269 * If we're doing transparent print, we have to do all of the above
1270 * again, separately so we don't get the LD confused about what major
1271 * we are when we get into the dgap_tty_open() routine.
1273 brd->print_driver = tty_alloc_driver(MAXPORTS, 0);
1274 if (IS_ERR(brd->print_driver)) {
1275 rc = PTR_ERR(brd->print_driver);
1276 goto free_serial_drv;
1279 snprintf(brd->print_name, MAXTTYNAMELEN, "pr_dgap_%d_",
1281 brd->print_driver->name = brd->print_name;
1282 brd->print_driver->name_base = 0;
1283 brd->print_driver->major = 0;
1284 brd->print_driver->minor_start = 0;
1285 brd->print_driver->type = TTY_DRIVER_TYPE_SERIAL;
1286 brd->print_driver->subtype = SERIAL_TYPE_NORMAL;
1287 brd->print_driver->init_termios = dgap_default_termios;
1288 brd->print_driver->driver_name = DRVSTR;
1289 brd->print_driver->flags = (TTY_DRIVER_REAL_RAW |
1290 TTY_DRIVER_DYNAMIC_DEV |
1291 TTY_DRIVER_HARDWARE_BREAK);
1293 /* The kernel wants space to store pointers to tty_structs */
1294 brd->print_driver->ttys =
1295 kzalloc(MAXPORTS * sizeof(struct tty_struct *), GFP_KERNEL);
1296 if (!brd->print_driver->ttys) {
1298 goto free_print_drv;
1302 * Entry points for driver. Called by the kernel from
1303 * tty_io.c and n_tty.c.
1305 tty_set_operations(brd->print_driver, &dgap_tty_ops);
1307 /* Register tty devices */
1308 rc = tty_register_driver(brd->serial_driver);
1310 goto free_print_drv;
1312 /* Register Transparent Print devices */
1313 rc = tty_register_driver(brd->print_driver);
1315 goto unregister_serial_drv;
1317 dgap_boards_by_major[brd->serial_driver->major] = brd;
1318 brd->dgap_serial_major = brd->serial_driver->major;
1320 dgap_boards_by_major[brd->print_driver->major] = brd;
1321 brd->dgap_transparent_print_major = brd->print_driver->major;
1325 unregister_serial_drv:
1326 tty_unregister_driver(brd->serial_driver);
1328 put_tty_driver(brd->print_driver);
1330 put_tty_driver(brd->serial_driver);
1335 static void dgap_tty_unregister(struct board_t *brd)
1337 tty_unregister_driver(brd->print_driver);
1338 tty_unregister_driver(brd->serial_driver);
1339 put_tty_driver(brd->print_driver);
1340 put_tty_driver(brd->serial_driver);
1346 * Init the tty subsystem. Called once per board after board has been
1347 * downloaded and init'ed.
1349 static int dgap_tty_init(struct board_t *brd)
1356 struct channel_t *ch;
1357 struct bs_t __iomem *bs;
1358 struct cm_t __iomem *cm;
1362 * Initialize board structure elements.
1365 vaddr = brd->re_map_membase;
1366 true_count = readw((vaddr + NCHAN));
1368 brd->nasync = dgap_config_get_num_prts(brd);
1371 brd->nasync = brd->maxports;
1373 if (brd->nasync > brd->maxports)
1374 brd->nasync = brd->maxports;
1376 if (true_count != brd->nasync) {
1377 dev_warn(&brd->pdev->dev,
1378 "%s configured for %d ports, has %d ports.\n",
1379 brd->name, brd->nasync, true_count);
1381 if ((brd->type == PPCM) &&
1382 (true_count == 64 || true_count == 0)) {
1383 dev_warn(&brd->pdev->dev,
1384 "Please make SURE the EBI cable running from the card\n");
1385 dev_warn(&brd->pdev->dev,
1386 "to each EM module is plugged into EBI IN!\n");
1389 brd->nasync = true_count;
1391 /* If no ports, don't bother going any further */
1393 brd->state = BOARD_FAILED;
1394 brd->dpastatus = BD_NOFEP;
1400 * Allocate channel memory that might not have been allocated
1401 * when the driver was first loaded.
1403 for (i = 0; i < brd->nasync; i++) {
1405 kzalloc(sizeof(struct channel_t), GFP_KERNEL);
1406 if (!brd->channels[i]) {
1412 ch = brd->channels[0];
1413 vaddr = brd->re_map_membase;
1415 bs = (struct bs_t __iomem *) ((ulong) vaddr + CHANBUF);
1416 cm = (struct cm_t __iomem *) ((ulong) vaddr + CMDBUF);
1420 /* Set up channel variables */
1421 for (i = 0; i < brd->nasync; i++, ch = brd->channels[i], bs++) {
1423 spin_lock_init(&ch->ch_lock);
1425 /* Store all our magic numbers */
1426 ch->magic = DGAP_CHANNEL_MAGIC;
1427 ch->ch_tun.magic = DGAP_UNIT_MAGIC;
1428 ch->ch_tun.un_type = DGAP_SERIAL;
1429 ch->ch_tun.un_ch = ch;
1430 ch->ch_tun.un_dev = i;
1432 ch->ch_pun.magic = DGAP_UNIT_MAGIC;
1433 ch->ch_pun.un_type = DGAP_PRINT;
1434 ch->ch_pun.un_ch = ch;
1435 ch->ch_pun.un_dev = i;
1437 ch->ch_vaddr = vaddr;
1442 ch->ch_digi = dgap_digi_init;
1445 * Set up digi dsr and dcd bits based on altpin flag.
1447 if (dgap_config_get_altpin(brd)) {
1450 ch->ch_digi.digi_flags |= DIGI_ALTPIN;
1453 ch->ch_dsr = DM_DSR;
1456 ch->ch_taddr = vaddr + (ioread16(&(ch->ch_bs->tx_seg)) << 4);
1457 ch->ch_raddr = vaddr + (ioread16(&(ch->ch_bs->rx_seg)) << 4);
1460 ch->ch_tsize = readw(&(ch->ch_bs->tx_max)) + 1;
1461 ch->ch_rsize = readw(&(ch->ch_bs->rx_max)) + 1;
1465 /* .25 second delay */
1466 ch->ch_close_delay = 250;
1469 * Set queue water marks, interrupt mask,
1470 * and general tty parameters.
1472 tlw = ch->ch_tsize >= 2000 ? ((ch->ch_tsize * 5) / 8) :
1476 dgap_cmdw(ch, STLOW, tlw, 0);
1478 dgap_cmdw(ch, SRLOW, ch->ch_rsize / 2, 0);
1480 dgap_cmdw(ch, SRHIGH, 7 * ch->ch_rsize / 8, 0);
1482 ch->ch_mistat = readb(&(ch->ch_bs->m_stat));
1484 init_waitqueue_head(&ch->ch_flags_wait);
1485 init_waitqueue_head(&ch->ch_tun.un_flags_wait);
1486 init_waitqueue_head(&ch->ch_pun.un_flags_wait);
1488 /* Turn on all modem interrupts for now */
1489 modem = (DM_CD | DM_DSR | DM_CTS | DM_RI);
1490 writeb(modem, &(ch->ch_bs->m_int));
1493 * Set edelay to 0 if interrupts are turned on,
1494 * otherwise set edelay to the usual 100.
1497 writew(0, &(ch->ch_bs->edelay));
1499 writew(100, &(ch->ch_bs->edelay));
1501 writeb(1, &(ch->ch_bs->idata));
1508 kfree(brd->channels[i]);
1509 brd->channels[i] = NULL;
1517 * Free the channles which are allocated in dgap_tty_init().
1519 static void dgap_tty_free(struct board_t *brd)
1523 for (i = 0; i < brd->nasync; i++)
1524 kfree(brd->channels[i]);
1527 * dgap_cleanup_tty()
1529 * Uninitialize the TTY portion of this driver. Free all memory and
1532 static void dgap_cleanup_tty(struct board_t *brd)
1537 dgap_boards_by_major[brd->serial_driver->major] = NULL;
1538 brd->dgap_serial_major = 0;
1539 for (i = 0; i < brd->nasync; i++) {
1540 tty_port_destroy(&brd->serial_ports[i]);
1541 dev = brd->channels[i]->ch_tun.un_sysfs;
1542 dgap_remove_tty_sysfs(dev);
1543 tty_unregister_device(brd->serial_driver, i);
1545 tty_unregister_driver(brd->serial_driver);
1546 put_tty_driver(brd->serial_driver);
1547 kfree(brd->serial_ports);
1549 dgap_boards_by_major[brd->print_driver->major] = NULL;
1550 brd->dgap_transparent_print_major = 0;
1551 for (i = 0; i < brd->nasync; i++) {
1552 tty_port_destroy(&brd->printer_ports[i]);
1553 dev = brd->channels[i]->ch_pun.un_sysfs;
1554 dgap_remove_tty_sysfs(dev);
1555 tty_unregister_device(brd->print_driver, i);
1557 tty_unregister_driver(brd->print_driver);
1558 put_tty_driver(brd->print_driver);
1559 kfree(brd->printer_ports);
1562 /*=======================================================================
1564 * dgap_input - Process received data.
1566 * ch - Pointer to channel structure.
1568 *=======================================================================*/
1570 static void dgap_input(struct channel_t *ch)
1573 struct bs_t __iomem *bs;
1574 struct tty_struct *tp;
1575 struct tty_ldisc *ld;
1589 if (!ch || ch->magic != DGAP_CHANNEL_MAGIC)
1592 tp = ch->ch_tun.un_tty;
1599 if (!bd || bd->magic != DGAP_BOARD_MAGIC)
1602 spin_lock_irqsave(&bd->bd_lock, lock_flags);
1603 spin_lock_irqsave(&ch->ch_lock, lock_flags2);
1606 * Figure the number of characters in the buffer.
1607 * Exit immediately if none.
1610 rmask = ch->ch_rsize - 1;
1612 head = readw(&(bs->rx_head));
1614 tail = readw(&(bs->rx_tail));
1617 data_len = (head - tail) & rmask;
1619 if (data_len == 0) {
1620 writeb(1, &(bs->idata));
1621 spin_unlock_irqrestore(&ch->ch_lock, lock_flags2);
1622 spin_unlock_irqrestore(&bd->bd_lock, lock_flags);
1627 * If the device is not open, or CREAD is off, flush
1628 * input data and return immediately.
1630 if ((bd->state != BOARD_READY) || !tp ||
1631 (tp->magic != TTY_MAGIC) ||
1632 !(ch->ch_tun.un_flags & UN_ISOPEN) ||
1633 !(tp->termios.c_cflag & CREAD) ||
1634 (ch->ch_tun.un_flags & UN_CLOSING)) {
1636 writew(head, &(bs->rx_tail));
1637 writeb(1, &(bs->idata));
1638 spin_unlock_irqrestore(&ch->ch_lock, lock_flags2);
1639 spin_unlock_irqrestore(&bd->bd_lock, lock_flags);
1644 * If we are throttled, simply don't read any data.
1646 if (ch->ch_flags & CH_RXBLOCK) {
1647 writeb(1, &(bs->idata));
1648 spin_unlock_irqrestore(&ch->ch_lock, lock_flags2);
1649 spin_unlock_irqrestore(&bd->bd_lock, lock_flags);
1656 tmpchar = readb(&(bs->orun));
1658 ch->ch_err_overrun++;
1659 writeb(0, &(bs->orun));
1662 /* Decide how much data we can send into the tty layer */
1663 flip_len = TTY_FLIPBUF_SIZE;
1665 /* Chop down the length, if needed */
1666 len = min(data_len, flip_len);
1667 len = min(len, (N_TTY_BUF_SIZE - 1));
1669 ld = tty_ldisc_ref(tp);
1671 #ifdef TTY_DONT_FLIP
1673 * If the DONT_FLIP flag is on, don't flush our buffer, and act
1674 * like the ld doesn't have any space to put the data right now.
1676 if (test_bit(TTY_DONT_FLIP, &tp->flags))
1681 * If we were unable to get a reference to the ld,
1682 * don't flush our buffer, and act like the ld doesn't
1683 * have any space to put the data right now.
1689 * If ld doesn't have a pointer to a receive_buf function,
1690 * flush the data, then act like the ld doesn't have any
1691 * space to put the data right now.
1693 if (!ld->ops->receive_buf) {
1694 writew(head, &(bs->rx_tail));
1700 writeb(1, &(bs->idata));
1701 spin_unlock_irqrestore(&ch->ch_lock, lock_flags2);
1702 spin_unlock_irqrestore(&bd->bd_lock, lock_flags);
1704 tty_ldisc_deref(ld);
1708 buf = ch->ch_bd->flipbuf;
1712 * n now contains the most amount of data we can copy,
1713 * bounded either by our buffer size or the amount
1714 * of data the card actually has pending...
1718 s = ((head >= tail) ? head : ch->ch_rsize) - tail;
1724 memcpy_fromio(buf, ch->ch_raddr + tail, s);
1730 /* Flip queue if needed */
1734 writew(tail, &(bs->rx_tail));
1735 writeb(1, &(bs->idata));
1736 ch->ch_rxcount += len;
1739 * If we are completely raw, we don't need to go through a lot
1740 * of the tty layers that exist.
1741 * In this case, we take the shortest and fastest route we
1742 * can to relay the data to the user.
1744 * On the other hand, if we are not raw, we need to go through
1745 * the tty layer, which has its API more well defined.
1747 if (I_PARMRK(tp) || I_BRKINT(tp) || I_INPCK(tp)) {
1748 dgap_parity_scan(ch, ch->ch_bd->flipbuf,
1749 ch->ch_bd->flipflagbuf, &len);
1751 len = tty_buffer_request_room(tp->port, len);
1752 tty_insert_flip_string_flags(tp->port, ch->ch_bd->flipbuf,
1753 ch->ch_bd->flipflagbuf, len);
1755 len = tty_buffer_request_room(tp->port, len);
1756 tty_insert_flip_string(tp->port, ch->ch_bd->flipbuf, len);
1759 spin_unlock_irqrestore(&ch->ch_lock, lock_flags2);
1760 spin_unlock_irqrestore(&bd->bd_lock, lock_flags);
1762 /* Tell the tty layer its okay to "eat" the data now */
1763 tty_flip_buffer_push(tp->port);
1766 tty_ldisc_deref(ld);
1770 /************************************************************************
1771 * Determines when CARRIER changes state and takes appropriate
1773 ************************************************************************/
1774 static void dgap_carrier(struct channel_t *ch)
1778 int virt_carrier = 0;
1779 int phys_carrier = 0;
1781 if (!ch || ch->magic != DGAP_CHANNEL_MAGIC)
1786 if (!bd || bd->magic != DGAP_BOARD_MAGIC)
1789 /* Make sure altpin is always set correctly */
1790 if (ch->ch_digi.digi_flags & DIGI_ALTPIN) {
1794 ch->ch_dsr = DM_DSR;
1798 if (ch->ch_mistat & D_CD(ch))
1801 if (ch->ch_digi.digi_flags & DIGI_FORCEDCD)
1804 if (ch->ch_c_cflag & CLOCAL)
1808 * Test for a VIRTUAL carrier transition to HIGH.
1810 if (((ch->ch_flags & CH_FCAR) == 0) && (virt_carrier == 1)) {
1813 * When carrier rises, wake any threads waiting
1814 * for carrier in the open routine.
1817 if (waitqueue_active(&(ch->ch_flags_wait)))
1818 wake_up_interruptible(&ch->ch_flags_wait);
1822 * Test for a PHYSICAL carrier transition to HIGH.
1824 if (((ch->ch_flags & CH_CD) == 0) && (phys_carrier == 1)) {
1827 * When carrier rises, wake any threads waiting
1828 * for carrier in the open routine.
1831 if (waitqueue_active(&(ch->ch_flags_wait)))
1832 wake_up_interruptible(&ch->ch_flags_wait);
1836 * Test for a PHYSICAL transition to low, so long as we aren't
1837 * currently ignoring physical transitions (which is what "virtual
1838 * carrier" indicates).
1840 * The transition of the virtual carrier to low really doesn't
1841 * matter... it really only means "ignore carrier state", not
1842 * "make pretend that carrier is there".
1844 if ((virt_carrier == 0) &&
1845 ((ch->ch_flags & CH_CD) != 0) &&
1846 (phys_carrier == 0)) {
1849 * When carrier drops:
1851 * Drop carrier on all open units.
1853 * Flush queues, waking up any task waiting in the
1856 * Send a hangup to the control terminal.
1858 * Enable all select calls.
1860 if (waitqueue_active(&(ch->ch_flags_wait)))
1861 wake_up_interruptible(&ch->ch_flags_wait);
1863 if (ch->ch_tun.un_open_count > 0)
1864 tty_hangup(ch->ch_tun.un_tty);
1866 if (ch->ch_pun.un_open_count > 0)
1867 tty_hangup(ch->ch_pun.un_tty);
1871 * Make sure that our cached values reflect the current reality.
1873 if (virt_carrier == 1)
1874 ch->ch_flags |= CH_FCAR;
1876 ch->ch_flags &= ~CH_FCAR;
1878 if (phys_carrier == 1)
1879 ch->ch_flags |= CH_CD;
1881 ch->ch_flags &= ~CH_CD;
1884 /************************************************************************
1886 * TTY Entry points and helper functions
1888 ************************************************************************/
1894 static int dgap_tty_open(struct tty_struct *tty, struct file *file)
1896 struct board_t *brd;
1897 struct channel_t *ch;
1899 struct bs_t __iomem *bs;
1907 major = MAJOR(tty_devnum(tty));
1908 minor = MINOR(tty_devnum(tty));
1913 /* Get board pointer from our array of majors we have allocated */
1914 brd = dgap_boards_by_major[major];
1919 * If board is not yet up to a state of READY, go to
1920 * sleep waiting for it to happen or they cancel the open.
1922 rc = wait_event_interruptible(brd->state_wait,
1923 (brd->state & BOARD_READY));
1928 spin_lock_irqsave(&brd->bd_lock, lock_flags);
1930 /* The wait above should guarantee this cannot happen */
1931 if (brd->state != BOARD_READY) {
1932 spin_unlock_irqrestore(&brd->bd_lock, lock_flags);
1936 /* If opened device is greater than our number of ports, bail. */
1937 if (MINOR(tty_devnum(tty)) > brd->nasync) {
1938 spin_unlock_irqrestore(&brd->bd_lock, lock_flags);
1942 ch = brd->channels[minor];
1944 spin_unlock_irqrestore(&brd->bd_lock, lock_flags);
1948 /* Grab channel lock */
1949 spin_lock_irqsave(&ch->ch_lock, lock_flags2);
1951 /* Figure out our type */
1952 if (major == brd->dgap_serial_major) {
1953 un = &brd->channels[minor]->ch_tun;
1954 un->un_type = DGAP_SERIAL;
1955 } else if (major == brd->dgap_transparent_print_major) {
1956 un = &brd->channels[minor]->ch_pun;
1957 un->un_type = DGAP_PRINT;
1959 spin_unlock_irqrestore(&ch->ch_lock, lock_flags2);
1960 spin_unlock_irqrestore(&brd->bd_lock, lock_flags);
1964 /* Store our unit into driver_data, so we always have it available. */
1965 tty->driver_data = un;
1968 * Error if channel info pointer is NULL.
1972 spin_unlock_irqrestore(&ch->ch_lock, lock_flags2);
1973 spin_unlock_irqrestore(&brd->bd_lock, lock_flags);
1980 if (!(un->un_flags & UN_ISOPEN)) {
1981 /* Store important variables. */
1984 /* Maybe do something here to the TTY struct as well? */
1988 * Initialize if neither terminal or printer is open.
1990 if (!((ch->ch_tun.un_flags | ch->ch_pun.un_flags) & UN_ISOPEN)) {
1996 * Flush input queue.
1998 head = readw(&(bs->rx_head));
1999 writew(head, &(bs->rx_tail));
2002 ch->pscan_state = 0;
2003 ch->pscan_savechar = 0;
2005 ch->ch_c_cflag = tty->termios.c_cflag;
2006 ch->ch_c_iflag = tty->termios.c_iflag;
2007 ch->ch_c_oflag = tty->termios.c_oflag;
2008 ch->ch_c_lflag = tty->termios.c_lflag;
2009 ch->ch_startc = tty->termios.c_cc[VSTART];
2010 ch->ch_stopc = tty->termios.c_cc[VSTOP];
2012 /* TODO: flush our TTY struct here? */
2017 * Run param in case we changed anything
2019 dgap_param(ch, brd, un->un_type);
2022 * follow protocol for opening port
2025 spin_unlock_irqrestore(&ch->ch_lock, lock_flags2);
2026 spin_unlock_irqrestore(&brd->bd_lock, lock_flags);
2028 rc = dgap_block_til_ready(tty, file, ch);
2033 /* No going back now, increment our unit and channel counters */
2034 spin_lock_irqsave(&ch->ch_lock, lock_flags);
2035 ch->ch_open_count++;
2036 un->un_open_count++;
2037 un->un_flags |= (UN_ISOPEN);
2038 spin_unlock_irqrestore(&ch->ch_lock, lock_flags);
2044 * dgap_block_til_ready()
2046 * Wait for DCD, if needed.
2048 static int dgap_block_til_ready(struct tty_struct *tty, struct file *file,
2049 struct channel_t *ch)
2055 int sleep_on_un_flags;
2057 if (!tty || tty->magic != TTY_MAGIC || !file || !ch ||
2058 ch->magic != DGAP_CHANNEL_MAGIC)
2061 un = tty->driver_data;
2062 if (!un || un->magic != DGAP_UNIT_MAGIC)
2065 spin_lock_irqsave(&ch->ch_lock, lock_flags);
2072 sleep_on_un_flags = 0;
2075 * If board has failed somehow during our sleep,
2078 if (ch->ch_bd->state == BOARD_FAILED) {
2083 /* If tty was hung up, break out of loop and set error. */
2084 if (tty_hung_up_p(file)) {
2090 * If either unit is in the middle of the fragile part of close,
2091 * we just cannot touch the channel safely.
2092 * Go back to sleep, knowing that when the channel can be
2093 * touched safely, the close routine will signal the
2094 * ch_wait_flags to wake us back up.
2096 if (!((ch->ch_tun.un_flags | ch->ch_pun.un_flags) &
2100 * Our conditions to leave cleanly and happily:
2101 * 1) NONBLOCKING on the tty is set.
2103 * 3) DCD (fake or real) is active.
2106 if (file->f_flags & O_NONBLOCK)
2109 if (tty->flags & (1 << TTY_IO_ERROR))
2112 if (ch->ch_flags & CH_CD)
2115 if (ch->ch_flags & CH_FCAR)
2118 sleep_on_un_flags = 1;
2122 * If there is a signal pending, the user probably
2123 * interrupted (ctrl-c) us.
2124 * Leave loop with error set.
2126 if (signal_pending(current)) {
2127 retval = -ERESTARTSYS;
2132 * Store the flags before we let go of channel lock
2134 if (sleep_on_un_flags)
2135 old_flags = ch->ch_tun.un_flags | ch->ch_pun.un_flags;
2137 old_flags = ch->ch_flags;
2140 * Let go of channel lock before calling schedule.
2141 * Our poller will get any FEP events and wake us up when DCD
2142 * eventually goes active.
2145 spin_unlock_irqrestore(&ch->ch_lock, lock_flags);
2148 * Wait for something in the flags to change
2149 * from the current value.
2151 if (sleep_on_un_flags) {
2152 retval = wait_event_interruptible(un->un_flags_wait,
2153 (old_flags != (ch->ch_tun.un_flags |
2154 ch->ch_pun.un_flags)));
2156 retval = wait_event_interruptible(ch->ch_flags_wait,
2157 (old_flags != ch->ch_flags));
2161 * We got woken up for some reason.
2162 * Before looping around, grab our channel lock.
2164 spin_lock_irqsave(&ch->ch_lock, lock_flags);
2169 spin_unlock_irqrestore(&ch->ch_lock, lock_flags);
2177 * Hangup the port. Like a close, but don't wait for output to drain.
2179 static void dgap_tty_hangup(struct tty_struct *tty)
2182 struct channel_t *ch;
2185 if (!tty || tty->magic != TTY_MAGIC)
2188 un = tty->driver_data;
2189 if (!un || un->magic != DGAP_UNIT_MAGIC)
2193 if (!ch || ch->magic != DGAP_CHANNEL_MAGIC)
2197 if (!bd || bd->magic != DGAP_BOARD_MAGIC)
2200 /* flush the transmit queues */
2201 dgap_tty_flush_buffer(tty);
2208 static void dgap_tty_close(struct tty_struct *tty, struct file *file)
2210 struct ktermios *ts;
2212 struct channel_t *ch;
2216 if (!tty || tty->magic != TTY_MAGIC)
2219 un = tty->driver_data;
2220 if (!un || un->magic != DGAP_UNIT_MAGIC)
2224 if (!ch || ch->magic != DGAP_CHANNEL_MAGIC)
2228 if (!bd || bd->magic != DGAP_BOARD_MAGIC)
2233 spin_lock_irqsave(&ch->ch_lock, lock_flags);
2236 * Determine if this is the last close or not - and if we agree about
2237 * which type of close it is with the Line Discipline
2239 if ((tty->count == 1) && (un->un_open_count != 1)) {
2241 * Uh, oh. tty->count is 1, which means that the tty
2242 * structure will be freed. un_open_count should always
2243 * be one in these conditions. If it's greater than
2244 * one, we've got real problems, since it means the
2245 * serial port won't be shutdown.
2247 un->un_open_count = 1;
2250 if (--un->un_open_count < 0)
2251 un->un_open_count = 0;
2253 ch->ch_open_count--;
2255 if (ch->ch_open_count && un->un_open_count) {
2256 spin_unlock_irqrestore(&ch->ch_lock, lock_flags);
2260 /* OK, its the last close on the unit */
2262 un->un_flags |= UN_CLOSING;
2267 * Only officially close channel if count is 0 and
2268 * DIGI_PRINTER bit is not set.
2270 if ((ch->ch_open_count == 0) &&
2271 !(ch->ch_digi.digi_flags & DIGI_PRINTER)) {
2273 ch->ch_flags &= ~(CH_RXBLOCK);
2275 spin_unlock_irqrestore(&ch->ch_lock, lock_flags);
2277 /* wait for output to drain */
2278 /* This will also return if we take an interrupt */
2280 dgap_wait_for_drain(tty);
2282 dgap_tty_flush_buffer(tty);
2283 tty_ldisc_flush(tty);
2285 spin_lock_irqsave(&ch->ch_lock, lock_flags);
2290 * If we have HUPCL set, lower DTR and RTS
2292 if (ch->ch_c_cflag & HUPCL) {
2293 ch->ch_mostat &= ~(D_RTS(ch)|D_DTR(ch));
2294 dgap_cmdb(ch, SMODEM, 0, D_DTR(ch)|D_RTS(ch), 0);
2297 * Go to sleep to ensure RTS/DTR
2298 * have been dropped for modems to see it.
2300 if (ch->ch_close_delay) {
2301 spin_unlock_irqrestore(&ch->ch_lock,
2303 dgap_ms_sleep(ch->ch_close_delay);
2304 spin_lock_irqsave(&ch->ch_lock, lock_flags);
2308 ch->pscan_state = 0;
2309 ch->pscan_savechar = 0;
2310 ch->ch_baud_info = 0;
2315 * turn off print device when closing print device.
2317 if ((un->un_type == DGAP_PRINT) && (ch->ch_flags & CH_PRON)) {
2318 dgap_wmove(ch, ch->ch_digi.digi_offstr,
2319 (int) ch->ch_digi.digi_offlen);
2320 ch->ch_flags &= ~CH_PRON;
2324 un->un_flags &= ~(UN_ISOPEN | UN_CLOSING);
2325 tty->driver_data = NULL;
2327 wake_up_interruptible(&ch->ch_flags_wait);
2328 wake_up_interruptible(&un->un_flags_wait);
2330 spin_unlock_irqrestore(&ch->ch_lock, lock_flags);
2334 * dgap_tty_chars_in_buffer()
2336 * Return number of characters that have not been transmitted yet.
2338 * This routine is used by the line discipline to determine if there
2339 * is data waiting to be transmitted/drained/flushed or not.
2341 static int dgap_tty_chars_in_buffer(struct tty_struct *tty)
2344 struct channel_t *ch;
2346 struct bs_t __iomem *bs;
2349 u16 thead, ttail, tmask, chead, ctail;
2350 ulong lock_flags = 0;
2351 ulong lock_flags2 = 0;
2356 un = tty->driver_data;
2357 if (!un || un->magic != DGAP_UNIT_MAGIC)
2361 if (!ch || ch->magic != DGAP_CHANNEL_MAGIC)
2365 if (!bd || bd->magic != DGAP_BOARD_MAGIC)
2372 spin_lock_irqsave(&bd->bd_lock, lock_flags);
2373 spin_lock_irqsave(&ch->ch_lock, lock_flags2);
2375 tmask = (ch->ch_tsize - 1);
2377 /* Get Transmit queue pointers */
2378 thead = readw(&(bs->tx_head)) & tmask;
2379 ttail = readw(&(bs->tx_tail)) & tmask;
2381 /* Get tbusy flag */
2382 tbusy = readb(&(bs->tbusy));
2384 /* Get Command queue pointers */
2385 chead = readw(&(ch->ch_cm->cm_head));
2386 ctail = readw(&(ch->ch_cm->cm_tail));
2388 spin_unlock_irqrestore(&ch->ch_lock, lock_flags2);
2389 spin_unlock_irqrestore(&bd->bd_lock, lock_flags);
2392 * The only way we know for sure if there is no pending
2393 * data left to be transferred, is if:
2394 * 1) Transmit head and tail are equal (empty).
2395 * 2) Command queue head and tail are equal (empty).
2396 * 3) The "TBUSY" flag is 0. (Transmitter not busy).
2399 if ((ttail == thead) && (tbusy == 0) && (chead == ctail)) {
2403 chars = thead - ttail;
2405 chars = thead - ttail + ch->ch_tsize;
2407 * Fudge factor here.
2408 * If chars is zero, we know that the command queue had
2409 * something in it or tbusy was set. Because we cannot
2410 * be sure if there is still some data to be transmitted,
2411 * lets lie, and tell ld we have 1 byte left.
2415 * If TBUSY is still set, and our tx buffers are empty,
2416 * force the firmware to send me another wakeup after
2417 * TBUSY has been cleared.
2420 spin_lock_irqsave(&ch->ch_lock, lock_flags);
2421 un->un_flags |= UN_EMPTY;
2422 writeb(1, &(bs->iempty));
2423 spin_unlock_irqrestore(&ch->ch_lock,
2433 static int dgap_wait_for_drain(struct tty_struct *tty)
2435 struct channel_t *ch;
2437 struct bs_t __iomem *bs;
2440 ulong lock_flags = 0;
2442 if (!tty || tty->magic != TTY_MAGIC)
2445 un = tty->driver_data;
2446 if (!un || un->magic != DGAP_UNIT_MAGIC)
2450 if (!ch || ch->magic != DGAP_CHANNEL_MAGIC)
2457 /* Loop until data is drained */
2458 while (count != 0) {
2460 count = dgap_tty_chars_in_buffer(tty);
2465 /* Set flag waiting for drain */
2466 spin_lock_irqsave(&ch->ch_lock, lock_flags);
2467 un->un_flags |= UN_EMPTY;
2468 writeb(1, &(bs->iempty));
2469 spin_unlock_irqrestore(&ch->ch_lock, lock_flags);
2471 /* Go to sleep till we get woken up */
2472 ret = wait_event_interruptible(un->un_flags_wait,
2473 ((un->un_flags & UN_EMPTY) == 0));
2474 /* If ret is non-zero, user ctrl-c'ed us */
2479 spin_lock_irqsave(&ch->ch_lock, lock_flags);
2480 un->un_flags &= ~(UN_EMPTY);
2481 spin_unlock_irqrestore(&ch->ch_lock, lock_flags);
2489 * Reduces bytes_available to the max number of characters
2490 * that can be sent currently given the maxcps value, and
2491 * returns the new bytes_available. This only affects printer
2494 static int dgap_maxcps_room(struct channel_t *ch, struct un_t *un,
2495 int bytes_available)
2498 * If its not the Transparent print device, return
2499 * the full data amount.
2501 if (un->un_type != DGAP_PRINT)
2502 return bytes_available;
2504 if (ch->ch_digi.digi_maxcps > 0 && ch->ch_digi.digi_bufsize > 0) {
2506 unsigned long current_time = jiffies;
2507 unsigned long buffer_time = current_time +
2508 (HZ * ch->ch_digi.digi_bufsize) /
2509 ch->ch_digi.digi_maxcps;
2511 if (ch->ch_cpstime < current_time) {
2512 /* buffer is empty */
2513 ch->ch_cpstime = current_time; /* reset ch_cpstime */
2514 cps_limit = ch->ch_digi.digi_bufsize;
2515 } else if (ch->ch_cpstime < buffer_time) {
2516 /* still room in the buffer */
2517 cps_limit = ((buffer_time - ch->ch_cpstime) *
2518 ch->ch_digi.digi_maxcps) / HZ;
2520 /* no room in the buffer */
2524 bytes_available = min(cps_limit, bytes_available);
2527 return bytes_available;
2530 static inline void dgap_set_firmware_event(struct un_t *un, unsigned int event)
2532 struct channel_t *ch;
2533 struct bs_t __iomem *bs;
2535 if (!un || un->magic != DGAP_UNIT_MAGIC)
2538 if (!ch || ch->magic != DGAP_CHANNEL_MAGIC)
2544 if ((event & UN_LOW) != 0) {
2545 if ((un->un_flags & UN_LOW) == 0) {
2546 un->un_flags |= UN_LOW;
2547 writeb(1, &(bs->ilow));
2550 if ((event & UN_LOW) != 0) {
2551 if ((un->un_flags & UN_EMPTY) == 0) {
2552 un->un_flags |= UN_EMPTY;
2553 writeb(1, &(bs->iempty));
2559 * dgap_tty_write_room()
2561 * Return space available in Tx buffer
2563 static int dgap_tty_write_room(struct tty_struct *tty)
2565 struct channel_t *ch;
2567 struct bs_t __iomem *bs;
2568 u16 head, tail, tmask;
2570 ulong lock_flags = 0;
2575 un = tty->driver_data;
2576 if (!un || un->magic != DGAP_UNIT_MAGIC)
2580 if (!ch || ch->magic != DGAP_CHANNEL_MAGIC)
2587 spin_lock_irqsave(&ch->ch_lock, lock_flags);
2589 tmask = ch->ch_tsize - 1;
2590 head = readw(&(bs->tx_head)) & tmask;
2591 tail = readw(&(bs->tx_tail)) & tmask;
2593 ret = tail - head - 1;
2595 ret += ch->ch_tsize;
2597 /* Limit printer to maxcps */
2598 ret = dgap_maxcps_room(ch, un, ret);
2601 * If we are printer device, leave space for
2602 * possibly both the on and off strings.
2604 if (un->un_type == DGAP_PRINT) {
2605 if (!(ch->ch_flags & CH_PRON))
2606 ret -= ch->ch_digi.digi_onlen;
2607 ret -= ch->ch_digi.digi_offlen;
2609 if (ch->ch_flags & CH_PRON)
2610 ret -= ch->ch_digi.digi_offlen;
2617 * Schedule FEP to wake us up if needed.
2619 * TODO: This might be overkill...
2620 * Do we really need to schedule callbacks from the FEP
2621 * in every case? Can we get smarter based on ret?
2623 dgap_set_firmware_event(un, UN_LOW | UN_EMPTY);
2624 spin_unlock_irqrestore(&ch->ch_lock, lock_flags);
2630 * dgap_tty_put_char()
2632 * Put a character into ch->ch_buf
2634 * - used by the line discipline for OPOST processing
2636 static int dgap_tty_put_char(struct tty_struct *tty, unsigned char c)
2639 * Simply call tty_write.
2641 dgap_tty_write(tty, &c, 1);
2648 * Take data from the user or kernel and send it out to the FEP.
2649 * In here exists all the Transparent Print magic as well.
2651 static int dgap_tty_write(struct tty_struct *tty, const unsigned char *buf,
2654 struct channel_t *ch;
2656 struct bs_t __iomem *bs;
2657 char __iomem *vaddr;
2658 u16 head, tail, tmask, remain;
2666 un = tty->driver_data;
2667 if (!un || un->magic != DGAP_UNIT_MAGIC)
2671 if (!ch || ch->magic != DGAP_CHANNEL_MAGIC)
2682 * Store original amount of characters passed in.
2683 * This helps to figure out if we should ask the FEP
2684 * to send us an event when it has more space available.
2688 spin_lock_irqsave(&ch->ch_lock, lock_flags);
2690 /* Get our space available for the channel from the board */
2691 tmask = ch->ch_tsize - 1;
2692 head = readw(&(bs->tx_head)) & tmask;
2693 tail = readw(&(bs->tx_tail)) & tmask;
2695 bufcount = tail - head - 1;
2697 bufcount += ch->ch_tsize;
2700 * Limit printer output to maxcps overall, with bursts allowed
2701 * up to bufsize characters.
2703 bufcount = dgap_maxcps_room(ch, un, bufcount);
2706 * Take minimum of what the user wants to send, and the
2707 * space available in the FEP buffer.
2709 count = min(count, bufcount);
2712 * Bail if no space left.
2715 dgap_set_firmware_event(un, UN_LOW | UN_EMPTY);
2716 spin_unlock_irqrestore(&ch->ch_lock, lock_flags);
2721 * Output the printer ON string, if we are in terminal mode, but
2722 * need to be in printer mode.
2724 if ((un->un_type == DGAP_PRINT) && !(ch->ch_flags & CH_PRON)) {
2725 dgap_wmove(ch, ch->ch_digi.digi_onstr,
2726 (int) ch->ch_digi.digi_onlen);
2727 head = readw(&(bs->tx_head)) & tmask;
2728 ch->ch_flags |= CH_PRON;
2732 * On the other hand, output the printer OFF string, if we are
2733 * currently in printer mode, but need to output to the terminal.
2735 if ((un->un_type != DGAP_PRINT) && (ch->ch_flags & CH_PRON)) {
2736 dgap_wmove(ch, ch->ch_digi.digi_offstr,
2737 (int) ch->ch_digi.digi_offlen);
2738 head = readw(&(bs->tx_head)) & tmask;
2739 ch->ch_flags &= ~CH_PRON;
2745 * If the write wraps over the top of the circular buffer,
2746 * move the portion up to the wrap point, and reset the
2747 * pointers to the bottom.
2749 remain = ch->ch_tstart + ch->ch_tsize - head;
2753 vaddr = ch->ch_taddr + head;
2755 memcpy_toio(vaddr, (u8 *) buf, remain);
2757 head = ch->ch_tstart;
2764 * Move rest of data.
2766 vaddr = ch->ch_taddr + head;
2769 memcpy_toio(vaddr, (u8 *) buf, remain);
2775 ch->ch_txcount += count;
2777 writew(head, &(bs->tx_head));
2780 dgap_set_firmware_event(un, UN_LOW | UN_EMPTY);
2783 * If this is the print device, and the
2784 * printer is still on, we need to turn it
2785 * off before going idle. If the buffer is
2786 * non-empty, wait until it goes empty.
2787 * Otherwise turn it off right now.
2789 if ((un->un_type == DGAP_PRINT) && (ch->ch_flags & CH_PRON)) {
2790 tail = readw(&(bs->tx_tail)) & tmask;
2793 un->un_flags |= UN_EMPTY;
2794 writeb(1, &(bs->iempty));
2796 dgap_wmove(ch, ch->ch_digi.digi_offstr,
2797 (int) ch->ch_digi.digi_offlen);
2798 head = readw(&(bs->tx_head)) & tmask;
2799 ch->ch_flags &= ~CH_PRON;
2803 /* Update printer buffer empty time. */
2804 if ((un->un_type == DGAP_PRINT) && (ch->ch_digi.digi_maxcps > 0)
2805 && (ch->ch_digi.digi_bufsize > 0)) {
2806 ch->ch_cpstime += (HZ * count) / ch->ch_digi.digi_maxcps;
2809 spin_unlock_irqrestore(&ch->ch_lock, lock_flags);
2815 * Return modem signals to ld.
2817 static int dgap_tty_tiocmget(struct tty_struct *tty)
2819 struct channel_t *ch;
2825 if (!tty || tty->magic != TTY_MAGIC)
2828 un = tty->driver_data;
2829 if (!un || un->magic != DGAP_UNIT_MAGIC)
2833 if (!ch || ch->magic != DGAP_CHANNEL_MAGIC)
2836 spin_lock_irqsave(&ch->ch_lock, lock_flags);
2838 mstat = readb(&(ch->ch_bs->m_stat));
2839 /* Append any outbound signals that might be pending... */
2840 mstat |= ch->ch_mostat;
2842 spin_unlock_irqrestore(&ch->ch_lock, lock_flags);
2846 if (mstat & D_DTR(ch))
2847 result |= TIOCM_DTR;
2848 if (mstat & D_RTS(ch))
2849 result |= TIOCM_RTS;
2850 if (mstat & D_CTS(ch))
2851 result |= TIOCM_CTS;
2852 if (mstat & D_DSR(ch))
2853 result |= TIOCM_DSR;
2854 if (mstat & D_RI(ch))
2856 if (mstat & D_CD(ch))
2863 * dgap_tty_tiocmset()
2865 * Set modem signals, called by ld.
2867 static int dgap_tty_tiocmset(struct tty_struct *tty,
2868 unsigned int set, unsigned int clear)
2871 struct channel_t *ch;
2876 if (!tty || tty->magic != TTY_MAGIC)
2879 un = tty->driver_data;
2880 if (!un || un->magic != DGAP_UNIT_MAGIC)
2884 if (!ch || ch->magic != DGAP_CHANNEL_MAGIC)
2888 if (!bd || bd->magic != DGAP_BOARD_MAGIC)
2891 spin_lock_irqsave(&bd->bd_lock, lock_flags);
2892 spin_lock_irqsave(&ch->ch_lock, lock_flags2);
2894 if (set & TIOCM_RTS) {
2895 ch->ch_mforce |= D_RTS(ch);
2896 ch->ch_mval |= D_RTS(ch);
2899 if (set & TIOCM_DTR) {
2900 ch->ch_mforce |= D_DTR(ch);
2901 ch->ch_mval |= D_DTR(ch);
2904 if (clear & TIOCM_RTS) {
2905 ch->ch_mforce |= D_RTS(ch);
2906 ch->ch_mval &= ~(D_RTS(ch));
2909 if (clear & TIOCM_DTR) {
2910 ch->ch_mforce |= D_DTR(ch);
2911 ch->ch_mval &= ~(D_DTR(ch));
2914 dgap_param(ch, bd, un->un_type);
2916 spin_unlock_irqrestore(&ch->ch_lock, lock_flags2);
2917 spin_unlock_irqrestore(&bd->bd_lock, lock_flags);
2923 * dgap_tty_send_break()
2925 * Send a Break, called by ld.
2927 static int dgap_tty_send_break(struct tty_struct *tty, int msec)
2930 struct channel_t *ch;
2935 if (!tty || tty->magic != TTY_MAGIC)
2938 un = tty->driver_data;
2939 if (!un || un->magic != DGAP_UNIT_MAGIC)
2943 if (!ch || ch->magic != DGAP_CHANNEL_MAGIC)
2947 if (!bd || bd->magic != DGAP_BOARD_MAGIC)
2962 spin_lock_irqsave(&bd->bd_lock, lock_flags);
2963 spin_lock_irqsave(&ch->ch_lock, lock_flags2);
2965 dgap_cmdw(ch, SBREAK, (u16) SBREAK_TIME, 0);
2967 dgap_cmdw(ch, SBREAK, (u16) msec, 0);
2969 spin_unlock_irqrestore(&ch->ch_lock, lock_flags2);
2970 spin_unlock_irqrestore(&bd->bd_lock, lock_flags);
2976 * dgap_tty_wait_until_sent()
2978 * wait until data has been transmitted, called by ld.
2980 static void dgap_tty_wait_until_sent(struct tty_struct *tty, int timeout)
2982 dgap_wait_for_drain(tty);
2988 * send a high priority character, called by ld.
2990 static void dgap_tty_send_xchar(struct tty_struct *tty, char c)
2993 struct channel_t *ch;
2998 if (!tty || tty->magic != TTY_MAGIC)
3001 un = tty->driver_data;
3002 if (!un || un->magic != DGAP_UNIT_MAGIC)
3006 if (!ch || ch->magic != DGAP_CHANNEL_MAGIC)
3010 if (!bd || bd->magic != DGAP_BOARD_MAGIC)
3013 spin_lock_irqsave(&bd->bd_lock, lock_flags);
3014 spin_lock_irqsave(&ch->ch_lock, lock_flags2);
3017 * This is technically what we should do.
3018 * However, the NIST tests specifically want
3019 * to see each XON or XOFF character that it
3020 * sends, so lets just send each character
3024 if (c == STOP_CHAR(tty))
3025 dgap_cmdw(ch, RPAUSE, 0, 0);
3026 else if (c == START_CHAR(tty))
3027 dgap_cmdw(ch, RRESUME, 0, 0);
3029 dgap_wmove(ch, &c, 1);
3031 dgap_wmove(ch, &c, 1);
3034 spin_unlock_irqrestore(&ch->ch_lock, lock_flags2);
3035 spin_unlock_irqrestore(&bd->bd_lock, lock_flags);
3039 * Return modem signals to ld.
3041 static int dgap_get_modem_info(struct channel_t *ch, unsigned int __user *value)
3048 spin_lock_irqsave(&ch->ch_lock, lock_flags);
3050 mstat = readb(&(ch->ch_bs->m_stat));
3051 /* Append any outbound signals that might be pending... */
3052 mstat |= ch->ch_mostat;
3054 spin_unlock_irqrestore(&ch->ch_lock, lock_flags);
3058 if (mstat & D_DTR(ch))
3059 result |= TIOCM_DTR;
3060 if (mstat & D_RTS(ch))
3061 result |= TIOCM_RTS;
3062 if (mstat & D_CTS(ch))
3063 result |= TIOCM_CTS;
3064 if (mstat & D_DSR(ch))
3065 result |= TIOCM_DSR;
3066 if (mstat & D_RI(ch))
3068 if (mstat & D_CD(ch))
3071 rc = put_user(result, value);
3077 * dgap_set_modem_info()
3079 * Set modem signals, called by ld.
3081 static int dgap_set_modem_info(struct channel_t *ch, struct board_t *bd,
3082 struct un_t *un, unsigned int command,
3083 unsigned int __user *value)
3090 ret = get_user(arg, value);
3096 if (arg & TIOCM_RTS) {
3097 ch->ch_mforce |= D_RTS(ch);
3098 ch->ch_mval |= D_RTS(ch);
3101 if (arg & TIOCM_DTR) {
3102 ch->ch_mforce |= D_DTR(ch);
3103 ch->ch_mval |= D_DTR(ch);
3109 if (arg & TIOCM_RTS) {
3110 ch->ch_mforce |= D_RTS(ch);
3111 ch->ch_mval &= ~(D_RTS(ch));
3114 if (arg & TIOCM_DTR) {
3115 ch->ch_mforce |= D_DTR(ch);
3116 ch->ch_mval &= ~(D_DTR(ch));
3122 ch->ch_mforce = D_DTR(ch)|D_RTS(ch);
3124 if (arg & TIOCM_RTS)
3125 ch->ch_mval |= D_RTS(ch);
3127 ch->ch_mval &= ~(D_RTS(ch));
3129 if (arg & TIOCM_DTR)
3130 ch->ch_mval |= (D_DTR(ch));
3132 ch->ch_mval &= ~(D_DTR(ch));
3140 spin_lock_irqsave(&bd->bd_lock, lock_flags);
3141 spin_lock_irqsave(&ch->ch_lock, lock_flags2);
3143 dgap_param(ch, bd, un->un_type);
3145 spin_unlock_irqrestore(&ch->ch_lock, lock_flags2);
3146 spin_unlock_irqrestore(&bd->bd_lock, lock_flags);
3152 * dgap_tty_digigeta()
3154 * Ioctl to get the information for ditty.
3159 static int dgap_tty_digigeta(struct channel_t *ch,
3160 struct digi_t __user *retinfo)
3168 memset(&tmp, 0, sizeof(tmp));
3170 spin_lock_irqsave(&ch->ch_lock, lock_flags);
3171 memcpy(&tmp, &ch->ch_digi, sizeof(tmp));
3172 spin_unlock_irqrestore(&ch->ch_lock, lock_flags);
3174 if (copy_to_user(retinfo, &tmp, sizeof(*retinfo)))
3181 * dgap_tty_digiseta()
3183 * Ioctl to set the information for ditty.
3188 static int dgap_tty_digiseta(struct channel_t *ch, struct board_t *bd,
3189 struct un_t *un, struct digi_t __user *new_info)
3191 struct digi_t new_digi;
3192 ulong lock_flags = 0;
3193 unsigned long lock_flags2;
3195 if (copy_from_user(&new_digi, new_info, sizeof(struct digi_t)))
3198 spin_lock_irqsave(&bd->bd_lock, lock_flags);
3199 spin_lock_irqsave(&ch->ch_lock, lock_flags2);
3201 memcpy(&ch->ch_digi, &new_digi, sizeof(struct digi_t));
3203 if (ch->ch_digi.digi_maxcps < 1)
3204 ch->ch_digi.digi_maxcps = 1;
3206 if (ch->ch_digi.digi_maxcps > 10000)
3207 ch->ch_digi.digi_maxcps = 10000;
3209 if (ch->ch_digi.digi_bufsize < 10)
3210 ch->ch_digi.digi_bufsize = 10;
3212 if (ch->ch_digi.digi_maxchar < 1)
3213 ch->ch_digi.digi_maxchar = 1;
3215 if (ch->ch_digi.digi_maxchar > ch->ch_digi.digi_bufsize)
3216 ch->ch_digi.digi_maxchar = ch->ch_digi.digi_bufsize;
3218 if (ch->ch_digi.digi_onlen > DIGI_PLEN)
3219 ch->ch_digi.digi_onlen = DIGI_PLEN;
3221 if (ch->ch_digi.digi_offlen > DIGI_PLEN)
3222 ch->ch_digi.digi_offlen = DIGI_PLEN;
3224 dgap_param(ch, bd, un->un_type);
3226 spin_unlock_irqrestore(&ch->ch_lock, lock_flags2);
3227 spin_unlock_irqrestore(&bd->bd_lock, lock_flags);
3233 * dgap_tty_digigetedelay()
3235 * Ioctl to get the current edelay setting.
3240 static int dgap_tty_digigetedelay(struct tty_struct *tty, int __user *retinfo)
3242 struct channel_t *ch;
3250 if (!tty || tty->magic != TTY_MAGIC)
3253 un = tty->driver_data;
3254 if (!un || un->magic != DGAP_UNIT_MAGIC)
3258 if (!ch || ch->magic != DGAP_CHANNEL_MAGIC)
3261 memset(&tmp, 0, sizeof(tmp));
3263 spin_lock_irqsave(&ch->ch_lock, lock_flags);
3264 tmp = readw(&(ch->ch_bs->edelay));
3265 spin_unlock_irqrestore(&ch->ch_lock, lock_flags);
3267 if (copy_to_user(retinfo, &tmp, sizeof(*retinfo)))
3274 * dgap_tty_digisetedelay()
3276 * Ioctl to set the EDELAY setting
3279 static int dgap_tty_digisetedelay(struct channel_t *ch, struct board_t *bd,
3280 struct un_t *un, int __user *new_info)
3286 if (copy_from_user(&new_digi, new_info, sizeof(int)))
3289 spin_lock_irqsave(&bd->bd_lock, lock_flags);
3290 spin_lock_irqsave(&ch->ch_lock, lock_flags2);
3292 writew((u16) new_digi, &(ch->ch_bs->edelay));
3294 dgap_param(ch, bd, un->un_type);
3296 spin_unlock_irqrestore(&ch->ch_lock, lock_flags2);
3297 spin_unlock_irqrestore(&bd->bd_lock, lock_flags);
3303 * dgap_tty_digigetcustombaud()
3305 * Ioctl to get the current custom baud rate setting.
3307 static int dgap_tty_digigetcustombaud(struct channel_t *ch, struct un_t *un,
3308 int __user *retinfo)
3316 memset(&tmp, 0, sizeof(tmp));
3318 spin_lock_irqsave(&ch->ch_lock, lock_flags);
3319 tmp = dgap_get_custom_baud(ch);
3320 spin_unlock_irqrestore(&ch->ch_lock, lock_flags);
3322 if (copy_to_user(retinfo, &tmp, sizeof(*retinfo)))
3329 * dgap_tty_digisetcustombaud()
3331 * Ioctl to set the custom baud rate setting
3333 static int dgap_tty_digisetcustombaud(struct channel_t *ch, struct board_t *bd,
3334 struct un_t *un, int __user *new_info)
3340 if (copy_from_user(&new_rate, new_info, sizeof(unsigned int)))
3343 if (bd->bd_flags & BD_FEP5PLUS) {
3345 spin_lock_irqsave(&bd->bd_lock, lock_flags);
3346 spin_lock_irqsave(&ch->ch_lock, lock_flags2);
3348 ch->ch_custom_speed = new_rate;
3350 dgap_param(ch, bd, un->un_type);
3352 spin_unlock_irqrestore(&ch->ch_lock, lock_flags2);
3353 spin_unlock_irqrestore(&bd->bd_lock, lock_flags);
3360 * dgap_set_termios()
3362 static void dgap_tty_set_termios(struct tty_struct *tty,
3363 struct ktermios *old_termios)
3366 struct channel_t *ch;
3368 unsigned long lock_flags;
3369 unsigned long lock_flags2;
3371 if (!tty || tty->magic != TTY_MAGIC)
3374 un = tty->driver_data;
3375 if (!un || un->magic != DGAP_UNIT_MAGIC)
3379 if (!ch || ch->magic != DGAP_CHANNEL_MAGIC)
3383 if (!bd || bd->magic != DGAP_BOARD_MAGIC)
3386 spin_lock_irqsave(&bd->bd_lock, lock_flags);
3387 spin_lock_irqsave(&ch->ch_lock, lock_flags2);
3389 ch->ch_c_cflag = tty->termios.c_cflag;
3390 ch->ch_c_iflag = tty->termios.c_iflag;
3391 ch->ch_c_oflag = tty->termios.c_oflag;
3392 ch->ch_c_lflag = tty->termios.c_lflag;
3393 ch->ch_startc = tty->termios.c_cc[VSTART];
3394 ch->ch_stopc = tty->termios.c_cc[VSTOP];
3397 dgap_param(ch, bd, un->un_type);
3399 spin_unlock_irqrestore(&ch->ch_lock, lock_flags2);
3400 spin_unlock_irqrestore(&bd->bd_lock, lock_flags);
3403 static void dgap_tty_throttle(struct tty_struct *tty)
3406 struct channel_t *ch;
3411 if (!tty || tty->magic != TTY_MAGIC)
3414 un = tty->driver_data;
3415 if (!un || un->magic != DGAP_UNIT_MAGIC)
3419 if (!ch || ch->magic != DGAP_CHANNEL_MAGIC)
3423 if (!bd || bd->magic != DGAP_BOARD_MAGIC)
3426 spin_lock_irqsave(&bd->bd_lock, lock_flags);
3427 spin_lock_irqsave(&ch->ch_lock, lock_flags2);
3429 ch->ch_flags |= (CH_RXBLOCK);
3431 dgap_cmdw(ch, RPAUSE, 0, 0);
3434 spin_unlock_irqrestore(&ch->ch_lock, lock_flags2);
3435 spin_unlock_irqrestore(&bd->bd_lock, lock_flags);
3439 static void dgap_tty_unthrottle(struct tty_struct *tty)
3442 struct channel_t *ch;
3447 if (!tty || tty->magic != TTY_MAGIC)
3450 un = tty->driver_data;
3451 if (!un || un->magic != DGAP_UNIT_MAGIC)
3455 if (!ch || ch->magic != DGAP_CHANNEL_MAGIC)
3459 if (!bd || bd->magic != DGAP_BOARD_MAGIC)
3462 spin_lock_irqsave(&bd->bd_lock, lock_flags);
3463 spin_lock_irqsave(&ch->ch_lock, lock_flags2);
3465 ch->ch_flags &= ~(CH_RXBLOCK);
3468 dgap_cmdw(ch, RRESUME, 0, 0);
3471 spin_unlock_irqrestore(&ch->ch_lock, lock_flags2);
3472 spin_unlock_irqrestore(&bd->bd_lock, lock_flags);
3475 static void dgap_tty_start(struct tty_struct *tty)
3478 struct channel_t *ch;
3483 if (!tty || tty->magic != TTY_MAGIC)
3486 un = tty->driver_data;
3487 if (!un || un->magic != DGAP_UNIT_MAGIC)
3491 if (!ch || ch->magic != DGAP_CHANNEL_MAGIC)
3495 if (!bd || bd->magic != DGAP_BOARD_MAGIC)
3498 spin_lock_irqsave(&bd->bd_lock, lock_flags);
3499 spin_lock_irqsave(&ch->ch_lock, lock_flags2);
3501 dgap_cmdw(ch, RESUMETX, 0, 0);
3503 spin_unlock_irqrestore(&ch->ch_lock, lock_flags2);
3504 spin_unlock_irqrestore(&bd->bd_lock, lock_flags);
3507 static void dgap_tty_stop(struct tty_struct *tty)
3510 struct channel_t *ch;
3515 if (!tty || tty->magic != TTY_MAGIC)
3518 un = tty->driver_data;
3519 if (!un || un->magic != DGAP_UNIT_MAGIC)
3523 if (!ch || ch->magic != DGAP_CHANNEL_MAGIC)
3527 if (!bd || bd->magic != DGAP_BOARD_MAGIC)
3530 spin_lock_irqsave(&bd->bd_lock, lock_flags);
3531 spin_lock_irqsave(&ch->ch_lock, lock_flags2);
3533 dgap_cmdw(ch, PAUSETX, 0, 0);
3535 spin_unlock_irqrestore(&ch->ch_lock, lock_flags2);
3536 spin_unlock_irqrestore(&bd->bd_lock, lock_flags);
3540 * dgap_tty_flush_chars()
3542 * Flush the cook buffer
3544 * Note to self, and any other poor souls who venture here:
3546 * flush in this case DOES NOT mean dispose of the data.
3547 * instead, it means "stop buffering and send it if you
3548 * haven't already." Just guess how I figured that out... SRW 2-Jun-98
3550 * It is also always called in interrupt context - JAR 8-Sept-99
3552 static void dgap_tty_flush_chars(struct tty_struct *tty)
3555 struct channel_t *ch;
3560 if (!tty || tty->magic != TTY_MAGIC)
3563 un = tty->driver_data;
3564 if (!un || un->magic != DGAP_UNIT_MAGIC)
3568 if (!ch || ch->magic != DGAP_CHANNEL_MAGIC)
3572 if (!bd || bd->magic != DGAP_BOARD_MAGIC)
3575 spin_lock_irqsave(&bd->bd_lock, lock_flags);
3576 spin_lock_irqsave(&ch->ch_lock, lock_flags2);
3578 /* TODO: Do something here */
3580 spin_unlock_irqrestore(&ch->ch_lock, lock_flags2);
3581 spin_unlock_irqrestore(&bd->bd_lock, lock_flags);
3585 * dgap_tty_flush_buffer()
3587 * Flush Tx buffer (make in == out)
3589 static void dgap_tty_flush_buffer(struct tty_struct *tty)
3592 struct channel_t *ch;
3598 if (!tty || tty->magic != TTY_MAGIC)
3601 un = tty->driver_data;
3602 if (!un || un->magic != DGAP_UNIT_MAGIC)
3606 if (!ch || ch->magic != DGAP_CHANNEL_MAGIC)
3610 if (!bd || bd->magic != DGAP_BOARD_MAGIC)
3613 spin_lock_irqsave(&bd->bd_lock, lock_flags);
3614 spin_lock_irqsave(&ch->ch_lock, lock_flags2);
3616 ch->ch_flags &= ~CH_STOP;
3617 head = readw(&(ch->ch_bs->tx_head));
3618 dgap_cmdw(ch, FLUSHTX, (u16) head, 0);
3619 dgap_cmdw(ch, RESUMETX, 0, 0);
3620 if (ch->ch_tun.un_flags & (UN_LOW|UN_EMPTY)) {
3621 ch->ch_tun.un_flags &= ~(UN_LOW|UN_EMPTY);
3622 wake_up_interruptible(&ch->ch_tun.un_flags_wait);
3624 if (ch->ch_pun.un_flags & (UN_LOW|UN_EMPTY)) {
3625 ch->ch_pun.un_flags &= ~(UN_LOW|UN_EMPTY);
3626 wake_up_interruptible(&ch->ch_pun.un_flags_wait);
3629 spin_unlock_irqrestore(&ch->ch_lock, lock_flags2);
3630 spin_unlock_irqrestore(&bd->bd_lock, lock_flags);
3631 if (waitqueue_active(&tty->write_wait))
3632 wake_up_interruptible(&tty->write_wait);
3636 /*****************************************************************************
3638 * The IOCTL function and all of its helpers
3640 *****************************************************************************/
3645 * The usual assortment of ioctl's
3647 static int dgap_tty_ioctl(struct tty_struct *tty, unsigned int cmd,
3651 struct channel_t *ch;
3655 ulong lock_flags = 0;
3656 ulong lock_flags2 = 0;
3657 void __user *uarg = (void __user *) arg;
3659 if (!tty || tty->magic != TTY_MAGIC)
3662 un = tty->driver_data;
3663 if (!un || un->magic != DGAP_UNIT_MAGIC)
3667 if (!ch || ch->magic != DGAP_CHANNEL_MAGIC)
3671 if (!bd || bd->magic != DGAP_BOARD_MAGIC)
3674 spin_lock_irqsave(&bd->bd_lock, lock_flags);
3675 spin_lock_irqsave(&ch->ch_lock, lock_flags2);
3677 if (un->un_open_count <= 0) {
3678 spin_unlock_irqrestore(&ch->ch_lock, lock_flags2);
3679 spin_unlock_irqrestore(&bd->bd_lock, lock_flags);
3685 /* Here are all the standard ioctl's that we MUST implement */
3689 * TCSBRK is SVID version: non-zero arg --> no break
3690 * this behaviour is exploited by tcdrain().
3692 * According to POSIX.1 spec (7.2.2.1.2) breaks should be
3693 * between 0.25 and 0.5 seconds so we'll ask for something
3694 * in the middle: 0.375 seconds.
3696 rc = tty_check_change(tty);
3697 spin_unlock_irqrestore(&ch->ch_lock, lock_flags2);
3698 spin_unlock_irqrestore(&bd->bd_lock, lock_flags);
3702 rc = dgap_wait_for_drain(tty);
3707 spin_lock_irqsave(&bd->bd_lock, lock_flags);
3708 spin_lock_irqsave(&ch->ch_lock, lock_flags2);
3710 if (((cmd == TCSBRK) && (!arg)) || (cmd == TCSBRKP))
3711 dgap_cmdw(ch, SBREAK, (u16) SBREAK_TIME, 0);
3713 spin_unlock_irqrestore(&ch->ch_lock, lock_flags2);
3714 spin_unlock_irqrestore(&bd->bd_lock, lock_flags);
3719 /* support for POSIX tcsendbreak()
3721 * According to POSIX.1 spec (7.2.2.1.2) breaks should be
3722 * between 0.25 and 0.5 seconds so we'll ask for something
3723 * in the middle: 0.375 seconds.
3725 rc = tty_check_change(tty);
3726 spin_unlock_irqrestore(&ch->ch_lock, lock_flags2);
3727 spin_unlock_irqrestore(&bd->bd_lock, lock_flags);
3731 rc = dgap_wait_for_drain(tty);
3735 spin_lock_irqsave(&bd->bd_lock, lock_flags);
3736 spin_lock_irqsave(&ch->ch_lock, lock_flags2);
3738 dgap_cmdw(ch, SBREAK, (u16) SBREAK_TIME, 0);
3740 spin_unlock_irqrestore(&ch->ch_lock, lock_flags2);
3741 spin_unlock_irqrestore(&bd->bd_lock, lock_flags);
3747 * FEP5 doesn't support turning on a break unconditionally.
3748 * The FEP5 device will stop sending a break automatically
3749 * after the specified time value that was sent when turning on
3752 rc = tty_check_change(tty);
3753 spin_unlock_irqrestore(&ch->ch_lock, lock_flags2);
3754 spin_unlock_irqrestore(&bd->bd_lock, lock_flags);
3758 rc = dgap_wait_for_drain(tty);
3762 spin_lock_irqsave(&bd->bd_lock, lock_flags);
3763 spin_lock_irqsave(&ch->ch_lock, lock_flags2);
3765 dgap_cmdw(ch, SBREAK, (u16) SBREAK_TIME, 0);
3767 spin_unlock_irqrestore(&ch->ch_lock, lock_flags2);
3768 spin_unlock_irqrestore(&bd->bd_lock, lock_flags);
3774 * FEP5 doesn't support turning off a break unconditionally.
3775 * The FEP5 device will stop sending a break automatically
3776 * after the specified time value that was sent when turning on
3779 spin_unlock_irqrestore(&ch->ch_lock, lock_flags2);
3780 spin_unlock_irqrestore(&bd->bd_lock, lock_flags);
3785 spin_unlock_irqrestore(&ch->ch_lock, lock_flags2);
3786 spin_unlock_irqrestore(&bd->bd_lock, lock_flags);
3788 rc = put_user(C_CLOCAL(tty) ? 1 : 0,
3789 (unsigned long __user *) arg);
3793 spin_unlock_irqrestore(&ch->ch_lock, lock_flags2);
3794 spin_unlock_irqrestore(&bd->bd_lock, lock_flags);
3796 rc = get_user(arg, (unsigned long __user *) arg);
3800 spin_lock_irqsave(&bd->bd_lock, lock_flags);
3801 spin_lock_irqsave(&ch->ch_lock, lock_flags2);
3802 tty->termios.c_cflag = ((tty->termios.c_cflag & ~CLOCAL) |
3803 (arg ? CLOCAL : 0));
3804 dgap_param(ch, bd, un->un_type);
3805 spin_unlock_irqrestore(&ch->ch_lock, lock_flags2);
3806 spin_unlock_irqrestore(&bd->bd_lock, lock_flags);
3811 spin_unlock_irqrestore(&ch->ch_lock, lock_flags2);
3812 spin_unlock_irqrestore(&bd->bd_lock, lock_flags);
3813 return dgap_get_modem_info(ch, uarg);
3818 spin_unlock_irqrestore(&ch->ch_lock, lock_flags2);
3819 spin_unlock_irqrestore(&bd->bd_lock, lock_flags);
3820 return dgap_set_modem_info(ch, bd, un, cmd, uarg);
3823 * Here are any additional ioctl's that we want to implement
3828 * The linux tty driver doesn't have a flush
3829 * input routine for the driver, assuming all backed
3830 * up data is in the line disc. buffers. However,
3831 * we all know that's not the case. Here, we
3832 * act on the ioctl, but then lie and say we didn't
3833 * so the line discipline will process the flush
3836 rc = tty_check_change(tty);
3838 spin_unlock_irqrestore(&ch->ch_lock, lock_flags2);
3839 spin_unlock_irqrestore(&bd->bd_lock, lock_flags);
3843 if ((arg == TCIFLUSH) || (arg == TCIOFLUSH)) {
3844 if (!(un->un_type == DGAP_PRINT)) {
3845 head = readw(&(ch->ch_bs->rx_head));
3846 writew(head, &(ch->ch_bs->rx_tail));
3847 writeb(0, &(ch->ch_bs->orun));
3851 if ((arg != TCOFLUSH) && (arg != TCIOFLUSH)) {
3852 /* pretend we didn't recognize this IOCTL */
3853 spin_unlock_irqrestore(&ch->ch_lock, lock_flags2);
3854 spin_unlock_irqrestore(&bd->bd_lock, lock_flags);
3856 return -ENOIOCTLCMD;
3859 ch->ch_flags &= ~CH_STOP;
3860 head = readw(&(ch->ch_bs->tx_head));
3861 dgap_cmdw(ch, FLUSHTX, (u16) head, 0);
3862 dgap_cmdw(ch, RESUMETX, 0, 0);
3863 if (ch->ch_tun.un_flags & (UN_LOW|UN_EMPTY)) {
3864 ch->ch_tun.un_flags &= ~(UN_LOW|UN_EMPTY);
3865 wake_up_interruptible(&ch->ch_tun.un_flags_wait);
3867 if (ch->ch_pun.un_flags & (UN_LOW|UN_EMPTY)) {
3868 ch->ch_pun.un_flags &= ~(UN_LOW|UN_EMPTY);
3869 wake_up_interruptible(&ch->ch_pun.un_flags_wait);
3871 if (waitqueue_active(&tty->write_wait))
3872 wake_up_interruptible(&tty->write_wait);
3874 /* Can't hold any locks when calling tty_wakeup! */
3875 spin_unlock_irqrestore(&ch->ch_lock, lock_flags2);
3876 spin_unlock_irqrestore(&bd->bd_lock, lock_flags);
3879 /* pretend we didn't recognize this IOCTL */
3880 return -ENOIOCTLCMD;
3885 * The linux tty driver doesn't have a flush
3886 * input routine for the driver, assuming all backed
3887 * up data is in the line disc. buffers. However,
3888 * we all know that's not the case. Here, we
3889 * act on the ioctl, but then lie and say we didn't
3890 * so the line discipline will process the flush
3893 if (cmd == TCSETSF) {
3895 ch->ch_flags &= ~CH_STOP;
3896 head = readw(&(ch->ch_bs->rx_head));
3897 writew(head, &(ch->ch_bs->rx_tail));
3900 /* now wait for all the output to drain */
3901 spin_unlock_irqrestore(&ch->ch_lock, lock_flags2);
3902 spin_unlock_irqrestore(&bd->bd_lock, lock_flags);
3903 rc = dgap_wait_for_drain(tty);
3907 /* pretend we didn't recognize this */
3908 return -ENOIOCTLCMD;
3912 spin_unlock_irqrestore(&ch->ch_lock, lock_flags2);
3913 spin_unlock_irqrestore(&bd->bd_lock, lock_flags);
3914 rc = dgap_wait_for_drain(tty);
3918 /* pretend we didn't recognize this */
3919 return -ENOIOCTLCMD;
3923 * The Linux Line Discipline (LD) would do this for us if we
3924 * let it, but we have the special firmware options to do this
3925 * the "right way" regardless of hardware or software flow
3926 * control so we'll do it outselves instead of letting the LD
3929 rc = tty_check_change(tty);
3931 spin_unlock_irqrestore(&ch->ch_lock, lock_flags2);
3932 spin_unlock_irqrestore(&bd->bd_lock, lock_flags);
3939 spin_unlock_irqrestore(&ch->ch_lock, lock_flags2);
3940 spin_unlock_irqrestore(&bd->bd_lock, lock_flags);
3941 dgap_tty_start(tty);
3944 spin_unlock_irqrestore(&ch->ch_lock, lock_flags2);
3945 spin_unlock_irqrestore(&bd->bd_lock, lock_flags);
3949 spin_unlock_irqrestore(&ch->ch_lock, lock_flags2);
3950 spin_unlock_irqrestore(&bd->bd_lock, lock_flags);
3951 /* Make the ld do it */
3952 return -ENOIOCTLCMD;
3954 spin_unlock_irqrestore(&ch->ch_lock, lock_flags2);
3955 spin_unlock_irqrestore(&bd->bd_lock, lock_flags);
3956 /* Make the ld do it */
3957 return -ENOIOCTLCMD;
3959 spin_unlock_irqrestore(&ch->ch_lock, lock_flags2);
3960 spin_unlock_irqrestore(&bd->bd_lock, lock_flags);
3965 /* get information for ditty */
3966 spin_unlock_irqrestore(&ch->ch_lock, lock_flags2);
3967 spin_unlock_irqrestore(&bd->bd_lock, lock_flags);
3968 return dgap_tty_digigeta(ch, uarg);
3973 /* set information for ditty */
3974 if (cmd == (DIGI_SETAW)) {
3976 spin_unlock_irqrestore(&ch->ch_lock, lock_flags2);
3977 spin_unlock_irqrestore(&bd->bd_lock, lock_flags);
3978 rc = dgap_wait_for_drain(tty);
3981 spin_lock_irqsave(&bd->bd_lock, lock_flags);
3982 spin_lock_irqsave(&ch->ch_lock, lock_flags2);
3984 tty_ldisc_flush(tty);
3988 spin_unlock_irqrestore(&ch->ch_lock, lock_flags2);
3989 spin_unlock_irqrestore(&bd->bd_lock, lock_flags);
3990 return dgap_tty_digiseta(ch, bd, un, uarg);
3993 spin_unlock_irqrestore(&ch->ch_lock, lock_flags2);
3994 spin_unlock_irqrestore(&bd->bd_lock, lock_flags);
3995 return dgap_tty_digigetedelay(tty, uarg);
3998 spin_unlock_irqrestore(&ch->ch_lock, lock_flags2);
3999 spin_unlock_irqrestore(&bd->bd_lock, lock_flags);
4000 return dgap_tty_digisetedelay(ch, bd, un, uarg);
4002 case DIGI_GETCUSTOMBAUD:
4003 spin_unlock_irqrestore(&ch->ch_lock, lock_flags2);
4004 spin_unlock_irqrestore(&bd->bd_lock, lock_flags);
4005 return dgap_tty_digigetcustombaud(ch, un, uarg);
4007 case DIGI_SETCUSTOMBAUD:
4008 spin_unlock_irqrestore(&ch->ch_lock, lock_flags2);
4009 spin_unlock_irqrestore(&bd->bd_lock, lock_flags);
4010 return dgap_tty_digisetcustombaud(ch, bd, un, uarg);
4012 case DIGI_RESET_PORT:
4013 dgap_firmware_reset_port(ch);
4014 dgap_param(ch, bd, un->un_type);
4015 spin_unlock_irqrestore(&ch->ch_lock, lock_flags2);
4016 spin_unlock_irqrestore(&bd->bd_lock, lock_flags);
4020 spin_unlock_irqrestore(&ch->ch_lock, lock_flags2);
4021 spin_unlock_irqrestore(&bd->bd_lock, lock_flags);
4023 return -ENOIOCTLCMD;
4027 static int dgap_alloc_flipbuf(struct board_t *brd)
4030 * allocate flip buffer for board.
4032 brd->flipbuf = kmalloc(MYFLIPLEN, GFP_KERNEL);
4036 brd->flipflagbuf = kmalloc(MYFLIPLEN, GFP_KERNEL);
4037 if (!brd->flipflagbuf) {
4038 kfree(brd->flipbuf);
4045 static void dgap_free_flipbuf(struct board_t *brd)
4047 kfree(brd->flipbuf);
4048 kfree(brd->flipflagbuf);
4052 * Create pr and tty device entries
4054 static int dgap_tty_register_ports(struct board_t *brd)
4056 struct channel_t *ch;
4060 brd->serial_ports = kcalloc(brd->nasync, sizeof(*brd->serial_ports),
4062 if (!brd->serial_ports)
4065 brd->printer_ports = kcalloc(brd->nasync, sizeof(*brd->printer_ports),
4067 if (!brd->printer_ports) {
4069 goto free_serial_ports;
4072 for (i = 0; i < brd->nasync; i++) {
4073 tty_port_init(&brd->serial_ports[i]);
4074 tty_port_init(&brd->printer_ports[i]);
4077 ch = brd->channels[0];
4078 for (i = 0; i < brd->nasync; i++, ch = brd->channels[i]) {
4080 struct device *classp;
4082 classp = tty_port_register_device(&brd->serial_ports[i],
4086 if (IS_ERR(classp)) {
4087 ret = PTR_ERR(classp);
4088 goto unregister_ttys;
4091 dgap_create_tty_sysfs(&ch->ch_tun, classp);
4092 ch->ch_tun.un_sysfs = classp;
4094 classp = tty_port_register_device(&brd->printer_ports[i],
4098 if (IS_ERR(classp)) {
4099 ret = PTR_ERR(classp);
4100 goto unregister_ttys;
4103 dgap_create_tty_sysfs(&ch->ch_pun, classp);
4104 ch->ch_pun.un_sysfs = classp;
4106 dgap_create_ports_sysfiles(brd);
4112 ch = brd->channels[i];
4113 if (ch->ch_tun.un_sysfs) {
4114 dgap_remove_tty_sysfs(ch->ch_tun.un_sysfs);
4115 tty_unregister_device(brd->serial_driver, i);
4118 if (ch->ch_pun.un_sysfs) {
4119 dgap_remove_tty_sysfs(ch->ch_pun.un_sysfs);
4120 tty_unregister_device(brd->print_driver, i);
4125 for (i = 0; i < brd->nasync; i++) {
4126 tty_port_destroy(&brd->serial_ports[i]);
4127 tty_port_destroy(&brd->printer_ports[i]);
4130 kfree(brd->printer_ports);
4131 brd->printer_ports = NULL;
4134 kfree(brd->serial_ports);
4135 brd->serial_ports = NULL;
4141 * Copies the BIOS code from the user to the board,
4142 * and starts the BIOS running.
4144 static void dgap_do_bios_load(struct board_t *brd, const u8 *ubios, int len)
4150 if (!brd || (brd->magic != DGAP_BOARD_MAGIC) || !brd->re_map_membase)
4153 addr = brd->re_map_membase;
4158 for (i = 0; i < 16; i++)
4159 writeb(0, addr + POSTAREA + i);
4165 memcpy_toio(addr + offset, ubios, len);
4167 writel(0x0bf00401, addr);
4168 writel(0, (addr + 4));
4170 /* Clear the reset, and change states. */
4171 writeb(FEPCLR, brd->re_map_port);
4175 * Checks to see if the BIOS completed running on the card.
4177 static int dgap_test_bios(struct board_t *brd)
4184 if (!brd || (brd->magic != DGAP_BOARD_MAGIC) || !brd->re_map_membase)
4187 addr = brd->re_map_membase;
4188 word = readw(addr + POSTAREA);
4191 * It can take 5-6 seconds for a board to
4192 * pass the bios self test and post results.
4193 * Give it 10 seconds.
4195 brd->wait_for_bios = 0;
4196 while (brd->wait_for_bios < 1000) {
4197 /* Check to see if BIOS thinks board is good. (GD). */
4198 if (word == *(u16 *) "GD")
4200 msleep_interruptible(10);
4201 brd->wait_for_bios++;
4202 word = readw(addr + POSTAREA);
4205 /* Gave up on board after too long of time taken */
4206 err1 = readw(addr + SEQUENCE);
4207 err2 = readw(addr + ERROR);
4208 dev_warn(&brd->pdev->dev, "%s failed diagnostics. Error #(%x,%x).\n",
4209 brd->name, err1, err2);
4210 brd->state = BOARD_FAILED;
4211 brd->dpastatus = BD_NOBIOS;
4217 * Copies the FEP code from the user to the board,
4218 * and starts the FEP running.
4220 static void dgap_do_fep_load(struct board_t *brd, const u8 *ufep, int len)
4225 if (!brd || (brd->magic != DGAP_BOARD_MAGIC) || !brd->re_map_membase)
4228 addr = brd->re_map_membase;
4234 memcpy_toio(addr + offset, ufep, len);
4237 * If board is a concentrator product, we need to give
4238 * it its config string describing how the concentrators look.
4240 if ((brd->type == PCX) || (brd->type == PEPC)) {
4246 xconfig = dgap_create_config_string(brd, string);
4248 /* Write string to board memory */
4249 config = addr + CONFIG;
4250 for (; i < CONFIGSIZE; i++, config++, xconfig++) {
4251 writeb(*xconfig, config);
4252 if ((*xconfig & 0xff) == 0xff)
4257 writel(0xbfc01004, (addr + 0xc34));
4258 writel(0x3, (addr + 0xc30));
4263 * Waits for the FEP to report thats its ready for us to use.
4265 static int dgap_test_fep(struct board_t *brd)
4272 if (!brd || (brd->magic != DGAP_BOARD_MAGIC) || !brd->re_map_membase)
4275 addr = brd->re_map_membase;
4276 word = readw(addr + FEPSTAT);
4279 * It can take 2-3 seconds for the FEP to
4280 * be up and running. Give it 5 secs.
4282 brd->wait_for_fep = 0;
4283 while (brd->wait_for_fep < 500) {
4284 /* Check to see if FEP is up and running now. */
4285 if (word == *(u16 *) "OS") {
4287 * Check to see if the board can support FEP5+ commands.
4289 word = readw(addr + FEP5_PLUS);
4290 if (word == *(u16 *) "5A")
4291 brd->bd_flags |= BD_FEP5PLUS;
4295 msleep_interruptible(10);
4296 brd->wait_for_fep++;
4297 word = readw(addr + FEPSTAT);
4300 /* Gave up on board after too long of time taken */
4301 err1 = readw(addr + SEQUENCE);
4302 err2 = readw(addr + ERROR);
4303 dev_warn(&brd->pdev->dev,
4304 "FEPOS for %s not functioning. Error #(%x,%x).\n",
4305 brd->name, err1, err2);
4306 brd->state = BOARD_FAILED;
4307 brd->dpastatus = BD_NOFEP;
4313 * Physically forces the FEP5 card to reset itself.
4315 static void dgap_do_reset_board(struct board_t *brd)
4322 if (!brd || (brd->magic != DGAP_BOARD_MAGIC) ||
4323 !brd->re_map_membase || !brd->re_map_port)
4326 /* FEPRST does not vary among supported boards */
4327 writeb(FEPRST, brd->re_map_port);
4329 for (i = 0; i <= 1000; i++) {
4330 check = readb(brd->re_map_port) & 0xe;
4331 if (check == FEPRST)
4337 dev_warn(&brd->pdev->dev,
4338 "dgap: Board not resetting... Failing board.\n");
4339 brd->state = BOARD_FAILED;
4340 brd->dpastatus = BD_NOFEP;
4345 * Make sure there really is memory out there.
4347 writel(0xa55a3cc3, (brd->re_map_membase + LOWMEM));
4348 writel(0x5aa5c33c, (brd->re_map_membase + HIGHMEM));
4349 check1 = readl(brd->re_map_membase + LOWMEM);
4350 check2 = readl(brd->re_map_membase + HIGHMEM);
4352 if ((check1 != 0xa55a3cc3) || (check2 != 0x5aa5c33c)) {
4353 dev_warn(&brd->pdev->dev,
4354 "No memory at %p for board.\n",
4355 brd->re_map_membase);
4356 brd->state = BOARD_FAILED;
4357 brd->dpastatus = BD_NOFEP;
4362 #ifdef DIGI_CONCENTRATORS_SUPPORTED
4364 * Sends a concentrator image into the FEP5 board.
4366 static void dgap_do_conc_load(struct board_t *brd, u8 *uaddr, int len)
4368 char __iomem *vaddr;
4370 struct downld_t *to_dp;
4372 if (!brd || (brd->magic != DGAP_BOARD_MAGIC) || !brd->re_map_membase)
4375 vaddr = brd->re_map_membase;
4377 offset = readw((u16 *) (vaddr + DOWNREQ));
4378 to_dp = (struct downld_t *) (vaddr + (int) offset);
4379 memcpy_toio(to_dp, uaddr, len);
4381 /* Tell card we have data for it */
4382 writew(0, vaddr + (DOWNREQ));
4384 brd->conc_dl_status = NO_PENDING_CONCENTRATOR_REQUESTS;
4388 #define EXPANSION_ROM_SIZE (64 * 1024)
4389 #define FEP5_ROM_MAGIC (0xFEFFFFFF)
4391 static void dgap_get_vpd(struct board_t *brd)
4403 * Poke the magic number at the PCI Rom Address location.
4404 * If VPD is supported, the value read from that address
4407 magic = FEP5_ROM_MAGIC;
4408 pci_write_config_dword(brd->pdev, PCI_ROM_ADDRESS, magic);
4409 pci_read_config_dword(brd->pdev, PCI_ROM_ADDRESS, &magic);
4411 /* VPD not supported, bail */
4416 * To get to the OTPROM memory, we have to send the boards base
4417 * address or'ed with 1 into the PCI Rom Address location.
4419 magic = brd->membase | 0x01;
4420 pci_write_config_dword(brd->pdev, PCI_ROM_ADDRESS, magic);
4421 pci_read_config_dword(brd->pdev, PCI_ROM_ADDRESS, &magic);
4423 byte1 = readb(brd->re_map_membase);
4424 byte2 = readb(brd->re_map_membase + 1);
4427 * If the board correctly swapped to the OTPROM memory,
4428 * the first 2 bytes (header) should be 0x55, 0xAA
4430 if (byte1 == 0x55 && byte2 == 0xAA) {
4435 * We have to run through all the OTPROM memory looking
4436 * for the VPD offset.
4438 while (base_offset <= EXPANSION_ROM_SIZE) {
4441 * Lots of magic numbers here.
4443 * The VPD offset is located inside the ROM Data
4446 * We also have to remember the length of each
4447 * ROM Data Structure, so we can "hop" to the next
4448 * entry if the VPD isn't in the current
4449 * ROM Data Structure.
4451 rom_offset = readw(brd->re_map_membase +
4452 base_offset + 0x18);
4453 image_length = readw(brd->re_map_membase +
4454 rom_offset + 0x10) * 512;
4455 vpd_offset = readw(brd->re_map_membase +
4458 /* Found the VPD entry */
4462 /* We didn't find a VPD entry, go to next ROM entry. */
4463 base_offset += image_length;
4465 byte1 = readb(brd->re_map_membase + base_offset);
4466 byte2 = readb(brd->re_map_membase + base_offset + 1);
4469 * If the new ROM offset doesn't have 0x55, 0xAA
4470 * as its header, we have run out of ROM.
4472 if (byte1 != 0x55 || byte2 != 0xAA)
4477 * If we have a VPD offset, then mark the board
4478 * as having a valid VPD, and copy VPDSIZE (512) bytes of
4479 * that VPD to the buffer we have in our board structure.
4482 brd->bd_flags |= BD_HAS_VPD;
4483 for (i = 0; i < VPDSIZE; i++) {
4484 brd->vpd[i] = readb(brd->re_map_membase +
4491 * We MUST poke the magic number at the PCI Rom Address location again.
4492 * This makes the card report the regular board memory back to us,
4493 * rather than the OTPROM memory.
4495 magic = FEP5_ROM_MAGIC;
4496 pci_write_config_dword(brd->pdev, PCI_ROM_ADDRESS, magic);
4500 * Our board poller function.
4502 static void dgap_poll_tasklet(unsigned long data)
4504 struct board_t *bd = (struct board_t *) data;
4506 char __iomem *vaddr;
4509 if (!bd || (bd->magic != DGAP_BOARD_MAGIC))
4512 if (bd->inhibit_poller)
4515 spin_lock_irqsave(&bd->bd_lock, lock_flags);
4517 vaddr = bd->re_map_membase;
4520 * If board is ready, parse deeper to see if there is anything to do.
4522 if (bd->state == BOARD_READY) {
4524 struct ev_t __iomem *eaddr;
4526 if (!bd->re_map_membase) {
4527 spin_unlock_irqrestore(&bd->bd_lock, lock_flags);
4530 if (!bd->re_map_port) {
4531 spin_unlock_irqrestore(&bd->bd_lock, lock_flags);
4538 eaddr = (struct ev_t __iomem *) (vaddr + EVBUF);
4540 /* Get our head and tail */
4541 head = readw(&(eaddr->ev_head));
4542 tail = readw(&(eaddr->ev_tail));
4545 * If there is an event pending. Go service it.
4548 spin_unlock_irqrestore(&bd->bd_lock, lock_flags);
4550 spin_lock_irqsave(&bd->bd_lock, lock_flags);
4555 * If board is doing interrupts, ACK the interrupt.
4557 if (bd && bd->intr_running)
4558 readb(bd->re_map_port + 2);
4560 spin_unlock_irqrestore(&bd->bd_lock, lock_flags);
4564 spin_unlock_irqrestore(&bd->bd_lock, lock_flags);
4567 /*=======================================================================
4569 * dgap_cmdb - Sends a 2 byte command to the FEP.
4571 * ch - Pointer to channel structure.
4572 * cmd - Command to be sent.
4573 * byte1 - Integer containing first byte to be sent.
4574 * byte2 - Integer containing second byte to be sent.
4575 * ncmds - Wait until ncmds or fewer cmds are left
4576 * in the cmd buffer before returning.
4578 *=======================================================================*/
4579 static void dgap_cmdb(struct channel_t *ch, u8 cmd, u8 byte1,
4580 u8 byte2, uint ncmds)
4582 char __iomem *vaddr;
4583 struct __iomem cm_t *cm_addr;
4589 if (!ch || ch->magic != DGAP_CHANNEL_MAGIC)
4593 * Check if board is still alive.
4595 if (ch->ch_bd->state == BOARD_FAILED)
4599 * Make sure the pointers are in range before
4600 * writing to the FEP memory.
4602 vaddr = ch->ch_bd->re_map_membase;
4607 cm_addr = (struct cm_t __iomem *) (vaddr + CMDBUF);
4608 head = readw(&(cm_addr->cm_head));
4611 * Forget it if pointers out of range.
4613 if (head >= (CMDMAX - CMDSTART) || (head & 03)) {
4614 ch->ch_bd->state = BOARD_FAILED;
4619 * Put the data in the circular command buffer.
4621 writeb(cmd, (vaddr + head + CMDSTART + 0));
4622 writeb((u8) ch->ch_portnum, (vaddr + head + CMDSTART + 1));
4623 writeb(byte1, (vaddr + head + CMDSTART + 2));
4624 writeb(byte2, (vaddr + head + CMDSTART + 3));
4626 head = (head + 4) & (CMDMAX - CMDSTART - 4);
4628 writew(head, &(cm_addr->cm_head));
4631 * Wait if necessary before updating the head
4632 * pointer to limit the number of outstanding
4633 * commands to the FEP. If the time spent waiting
4634 * is outlandish, declare the FEP dead.
4636 for (count = dgap_count ;;) {
4638 head = readw(&(cm_addr->cm_head));
4639 tail = readw(&(cm_addr->cm_tail));
4641 n = (head - tail) & (CMDMAX - CMDSTART - 4);
4643 if (n <= ncmds * sizeof(struct cm_t))
4647 ch->ch_bd->state = BOARD_FAILED;
4654 /*=======================================================================
4656 * dgap_cmdw - Sends a 1 word command to the FEP.
4658 * ch - Pointer to channel structure.
4659 * cmd - Command to be sent.
4660 * word - Integer containing word to be sent.
4661 * ncmds - Wait until ncmds or fewer cmds are left
4662 * in the cmd buffer before returning.
4664 *=======================================================================*/
4665 static void dgap_cmdw(struct channel_t *ch, u8 cmd, u16 word, uint ncmds)
4667 char __iomem *vaddr;
4668 struct __iomem cm_t *cm_addr;
4674 if (!ch || ch->magic != DGAP_CHANNEL_MAGIC)
4678 * Check if board is still alive.
4680 if (ch->ch_bd->state == BOARD_FAILED)
4684 * Make sure the pointers are in range before
4685 * writing to the FEP memory.
4687 vaddr = ch->ch_bd->re_map_membase;
4691 cm_addr = (struct cm_t __iomem *) (vaddr + CMDBUF);
4692 head = readw(&(cm_addr->cm_head));
4695 * Forget it if pointers out of range.
4697 if (head >= (CMDMAX - CMDSTART) || (head & 03)) {
4698 ch->ch_bd->state = BOARD_FAILED;
4703 * Put the data in the circular command buffer.
4705 writeb(cmd, (vaddr + head + CMDSTART + 0));
4706 writeb((u8) ch->ch_portnum, (vaddr + head + CMDSTART + 1));
4707 writew((u16) word, (vaddr + head + CMDSTART + 2));
4709 head = (head + 4) & (CMDMAX - CMDSTART - 4);
4711 writew(head, &(cm_addr->cm_head));
4714 * Wait if necessary before updating the head
4715 * pointer to limit the number of outstanding
4716 * commands to the FEP. If the time spent waiting
4717 * is outlandish, declare the FEP dead.
4719 for (count = dgap_count ;;) {
4721 head = readw(&(cm_addr->cm_head));
4722 tail = readw(&(cm_addr->cm_tail));
4724 n = (head - tail) & (CMDMAX - CMDSTART - 4);
4726 if (n <= ncmds * sizeof(struct cm_t))
4730 ch->ch_bd->state = BOARD_FAILED;
4737 /*=======================================================================
4739 * dgap_cmdw_ext - Sends a extended word command to the FEP.
4741 * ch - Pointer to channel structure.
4742 * cmd - Command to be sent.
4743 * word - Integer containing word to be sent.
4744 * ncmds - Wait until ncmds or fewer cmds are left
4745 * in the cmd buffer before returning.
4747 *=======================================================================*/
4748 static void dgap_cmdw_ext(struct channel_t *ch, u16 cmd, u16 word, uint ncmds)
4750 char __iomem *vaddr;
4751 struct __iomem cm_t *cm_addr;
4757 if (!ch || ch->magic != DGAP_CHANNEL_MAGIC)
4761 * Check if board is still alive.
4763 if (ch->ch_bd->state == BOARD_FAILED)
4767 * Make sure the pointers are in range before
4768 * writing to the FEP memory.
4770 vaddr = ch->ch_bd->re_map_membase;
4774 cm_addr = (struct cm_t __iomem *) (vaddr + CMDBUF);
4775 head = readw(&(cm_addr->cm_head));
4778 * Forget it if pointers out of range.
4780 if (head >= (CMDMAX - CMDSTART) || (head & 03)) {
4781 ch->ch_bd->state = BOARD_FAILED;
4786 * Put the data in the circular command buffer.
4789 /* Write an FF to tell the FEP that we want an extended command */
4790 writeb((u8) 0xff, (vaddr + head + CMDSTART + 0));
4792 writeb((u8) ch->ch_portnum, (vaddr + head + CMDSTART + 1));
4793 writew((u16) cmd, (vaddr + head + CMDSTART + 2));
4796 * If the second part of the command won't fit,
4797 * put it at the beginning of the circular buffer.
4799 if (((head + 4) >= ((CMDMAX - CMDSTART)) || (head & 03)))
4800 writew((u16) word, (vaddr + CMDSTART));
4802 writew((u16) word, (vaddr + head + CMDSTART + 4));
4804 head = (head + 8) & (CMDMAX - CMDSTART - 4);
4806 writew(head, &(cm_addr->cm_head));
4809 * Wait if necessary before updating the head
4810 * pointer to limit the number of outstanding
4811 * commands to the FEP. If the time spent waiting
4812 * is outlandish, declare the FEP dead.
4814 for (count = dgap_count ;;) {
4816 head = readw(&(cm_addr->cm_head));
4817 tail = readw(&(cm_addr->cm_tail));
4819 n = (head - tail) & (CMDMAX - CMDSTART - 4);
4821 if (n <= ncmds * sizeof(struct cm_t))
4825 ch->ch_bd->state = BOARD_FAILED;
4832 /*=======================================================================
4834 * dgap_wmove - Write data to FEP buffer.
4836 * ch - Pointer to channel structure.
4837 * buf - Poiter to characters to be moved.
4838 * cnt - Number of characters to move.
4840 *=======================================================================*/
4841 static void dgap_wmove(struct channel_t *ch, char *buf, uint cnt)
4844 char __iomem *taddr;
4845 struct bs_t __iomem *bs;
4848 if (!ch || ch->magic != DGAP_CHANNEL_MAGIC)
4855 head = readw(&(bs->tx_head));
4858 * If pointers are out of range, just return.
4860 if ((cnt > ch->ch_tsize) ||
4861 (unsigned)(head - ch->ch_tstart) >= ch->ch_tsize)
4865 * If the write wraps over the top of the circular buffer,
4866 * move the portion up to the wrap point, and reset the
4867 * pointers to the bottom.
4869 n = ch->ch_tstart + ch->ch_tsize - head;
4873 taddr = ch->ch_taddr + head;
4874 memcpy_toio(taddr, buf, n);
4875 head = ch->ch_tstart;
4880 * Move rest of data.
4882 taddr = ch->ch_taddr + head;
4884 memcpy_toio(taddr, buf, n);
4887 writew(head, &(bs->tx_head));
4891 * Retrives the current custom baud rate from FEP memory,
4892 * and returns it back to the user.
4893 * Returns 0 on error.
4895 static uint dgap_get_custom_baud(struct channel_t *ch)
4901 if (!ch || ch->magic != DGAP_CHANNEL_MAGIC)
4904 if (!ch->ch_bd || ch->ch_bd->magic != DGAP_BOARD_MAGIC)
4907 if (!(ch->ch_bd->bd_flags & BD_FEP5PLUS))
4910 vaddr = ch->ch_bd->re_map_membase;
4916 * Go get from fep mem, what the fep
4917 * believes the custom baud rate is.
4919 offset = (ioread16(vaddr + ECS_SEG) << 4) + (ch->ch_portnum * 0x28)
4922 value = readw(vaddr + offset);
4927 * Calls the firmware to reset this channel.
4929 static void dgap_firmware_reset_port(struct channel_t *ch)
4931 dgap_cmdb(ch, CHRESET, 0, 0, 0);
4934 * Now that the channel is reset, we need to make sure
4935 * all the current settings get reapplied to the port
4938 * So we will set the driver's cache of firmware
4939 * settings all to 0, and then call param.
4941 ch->ch_fepiflag = 0;
4942 ch->ch_fepcflag = 0;
4943 ch->ch_fepoflag = 0;
4944 ch->ch_fepstartc = 0;
4945 ch->ch_fepstopc = 0;
4946 ch->ch_fepastartc = 0;
4947 ch->ch_fepastopc = 0;
4952 /*=======================================================================
4954 * dgap_param - Set Digi parameters.
4956 * struct tty_struct * - TTY for port.
4958 *=======================================================================*/
4959 static int dgap_param(struct channel_t *ch, struct board_t *bd, u32 un_type)
4968 * If baud rate is zero, flush queues, and set mval to drop DTR.
4970 if ((ch->ch_c_cflag & (CBAUD)) == 0) {
4973 head = readw(&(ch->ch_bs->rx_head));
4974 writew(head, &(ch->ch_bs->rx_tail));
4977 head = readw(&(ch->ch_bs->tx_head));
4978 writew(head, &(ch->ch_bs->tx_tail));
4980 ch->ch_flags |= (CH_BAUD0);
4982 /* Drop RTS and DTR */
4983 ch->ch_mval &= ~(D_RTS(ch)|D_DTR(ch));
4984 mval = D_DTR(ch) | D_RTS(ch);
4985 ch->ch_baud_info = 0;
4987 } else if (ch->ch_custom_speed && (bd->bd_flags & BD_FEP5PLUS)) {
4989 * Tell the fep to do the command
4992 dgap_cmdw_ext(ch, 0xff01, ch->ch_custom_speed, 0);
4995 * Now go get from fep mem, what the fep
4996 * believes the custom baud rate is.
4998 ch->ch_custom_speed = dgap_get_custom_baud(ch);
4999 ch->ch_baud_info = ch->ch_custom_speed;
5001 /* Handle transition from B0 */
5002 if (ch->ch_flags & CH_BAUD0) {
5003 ch->ch_flags &= ~(CH_BAUD0);
5004 ch->ch_mval |= (D_RTS(ch)|D_DTR(ch));
5006 mval = D_DTR(ch) | D_RTS(ch);
5010 * Set baud rate, character size, and parity.
5018 ulong bauds[4][16] = {
5022 600, 1200, 1800, 2400,
5023 4800, 9600, 19200, 38400 },
5024 { /* slowbaud & CBAUDEX */
5025 0, 57600, 115200, 230400,
5026 460800, 150, 200, 921600,
5027 600, 1200, 1800, 2400,
5028 4800, 9600, 19200, 38400 },
5030 0, 57600, 76800, 115200,
5031 14400, 57600, 230400, 76800,
5032 115200, 230400, 28800, 460800,
5033 921600, 9600, 19200, 38400 },
5034 { /* fastbaud & CBAUDEX */
5035 0, 57600, 115200, 230400,
5036 460800, 150, 200, 921600,
5037 600, 1200, 1800, 2400,
5038 4800, 9600, 19200, 38400 }
5042 * Only use the TXPrint baud rate if the
5043 * terminal unit is NOT open
5045 if (!(ch->ch_tun.un_flags & UN_ISOPEN) &&
5046 un_type == DGAP_PRINT)
5047 baud = C_BAUD(ch->ch_pun.un_tty) & 0xff;
5049 baud = C_BAUD(ch->ch_tun.un_tty) & 0xff;
5051 if (ch->ch_c_cflag & CBAUDEX)
5054 if (ch->ch_digi.digi_flags & DIGI_FAST)
5059 if ((iindex >= 0) && (iindex < 4) &&
5060 (jindex >= 0) && (jindex < 16))
5061 baud = bauds[iindex][jindex];
5068 ch->ch_baud_info = baud;
5071 * CBAUD has bit position 0x1000 set these days to
5072 * indicate Linux baud rate remap.
5073 * We use a different bit assignment for high speed.
5074 * Clear this bit out while grabbing the parts of
5077 cflag = ch->ch_c_cflag & ((CBAUD ^ CBAUDEX) | PARODD | PARENB |
5081 * HUPCL bit is used by FEP to indicate fast baud
5082 * table is to be used.
5084 if ((ch->ch_digi.digi_flags & DIGI_FAST) ||
5085 (ch->ch_c_cflag & CBAUDEX))
5088 if ((ch->ch_c_cflag & CBAUDEX) &&
5089 !(ch->ch_digi.digi_flags & DIGI_FAST)) {
5091 * The below code is trying to guarantee that only
5092 * baud rates 115200, 230400, 460800, 921600 are
5093 * remapped. We use exclusive or because the various
5094 * baud rates share common bit positions and therefore
5095 * can't be tested for easily.
5097 tcflag_t tcflag = (ch->ch_c_cflag & CBAUD) | CBAUDEX;
5101 * Map high speed requests to index
5102 * into FEP's baud table
5132 cflag = (cflag & ~(CBAUD | CBAUDEX)) | baudpart;
5137 if (cflag != ch->ch_fepcflag) {
5138 ch->ch_fepcflag = (u16) (cflag & 0xffff);
5141 * Okay to have channel and board
5142 * locks held calling this
5144 dgap_cmdw(ch, SCFLAG, (u16) cflag, 0);
5147 /* Handle transition from B0 */
5148 if (ch->ch_flags & CH_BAUD0) {
5149 ch->ch_flags &= ~(CH_BAUD0);
5150 ch->ch_mval |= (D_RTS(ch)|D_DTR(ch));
5152 mval = D_DTR(ch) | D_RTS(ch);
5158 iflag = ch->ch_c_iflag & (IGNBRK | BRKINT | IGNPAR | PARMRK |
5159 INPCK | ISTRIP | IXON | IXANY | IXOFF);
5161 if ((ch->ch_startc == _POSIX_VDISABLE) ||
5162 (ch->ch_stopc == _POSIX_VDISABLE)) {
5163 iflag &= ~(IXON | IXOFF);
5164 ch->ch_c_iflag &= ~(IXON | IXOFF);
5168 * Only the IBM Xr card can switch between
5169 * 232 and 422 modes on the fly
5171 if (bd->device == PCI_DEV_XR_IBM_DID) {
5172 if (ch->ch_digi.digi_flags & DIGI_422)
5173 dgap_cmdb(ch, SCOMMODE, MODE_422, 0, 0);
5175 dgap_cmdb(ch, SCOMMODE, MODE_232, 0, 0);
5178 if (ch->ch_digi.digi_flags & DIGI_ALTPIN)
5181 if (iflag != ch->ch_fepiflag) {
5182 ch->ch_fepiflag = iflag;
5184 /* Okay to have channel and board locks held calling this */
5185 dgap_cmdw(ch, SIFLAG, (u16) ch->ch_fepiflag, 0);
5189 * Select hardware handshaking.
5193 if (ch->ch_c_cflag & CRTSCTS)
5194 hflow |= (D_RTS(ch) | D_CTS(ch));
5195 if (ch->ch_digi.digi_flags & RTSPACE)
5197 if (ch->ch_digi.digi_flags & DTRPACE)
5199 if (ch->ch_digi.digi_flags & CTSPACE)
5201 if (ch->ch_digi.digi_flags & DSRPACE)
5203 if (ch->ch_digi.digi_flags & DCDPACE)
5206 if (hflow != ch->ch_hflow) {
5207 ch->ch_hflow = hflow;
5209 /* Okay to have channel and board locks held calling this */
5210 dgap_cmdb(ch, SHFLOW, (u8) hflow, 0xff, 0);
5214 * Set RTS and/or DTR Toggle if needed,
5215 * but only if product is FEP5+ based.
5217 if (bd->bd_flags & BD_FEP5PLUS) {
5220 if (ch->ch_digi.digi_flags & DIGI_RTS_TOGGLE)
5221 hflow2 |= (D_RTS(ch));
5222 if (ch->ch_digi.digi_flags & DIGI_DTR_TOGGLE)
5223 hflow2 |= (D_DTR(ch));
5225 dgap_cmdw_ext(ch, 0xff03, hflow2, 0);
5229 * Set modem control lines.
5232 mval ^= ch->ch_mforce & (mval ^ ch->ch_mval);
5234 if (ch->ch_mostat ^ mval) {
5235 ch->ch_mostat = mval;
5237 /* Okay to have channel and board locks held calling this */
5238 dgap_cmdb(ch, SMODEM, (u8) mval, D_RTS(ch)|D_DTR(ch), 0);
5242 * Read modem signals, and then call carrier function.
5244 ch->ch_mistat = readb(&(ch->ch_bs->m_stat));
5248 * Set the start and stop characters.
5250 if (ch->ch_startc != ch->ch_fepstartc ||
5251 ch->ch_stopc != ch->ch_fepstopc) {
5252 ch->ch_fepstartc = ch->ch_startc;
5253 ch->ch_fepstopc = ch->ch_stopc;
5255 /* Okay to have channel and board locks held calling this */
5256 dgap_cmdb(ch, SFLOWC, ch->ch_fepstartc, ch->ch_fepstopc, 0);
5260 * Set the Auxiliary start and stop characters.
5262 if (ch->ch_astartc != ch->ch_fepastartc ||
5263 ch->ch_astopc != ch->ch_fepastopc) {
5264 ch->ch_fepastartc = ch->ch_astartc;
5265 ch->ch_fepastopc = ch->ch_astopc;
5267 /* Okay to have channel and board locks held calling this */
5268 dgap_cmdb(ch, SAFLOWC, ch->ch_fepastartc, ch->ch_fepastopc, 0);
5275 * dgap_parity_scan()
5277 * Convert the FEP5 way of reporting parity errors and breaks into
5278 * the Linux line discipline way.
5280 static void dgap_parity_scan(struct channel_t *ch, unsigned char *cbuf,
5281 unsigned char *fbuf, int *len)
5285 unsigned char *in, *cout, *fout;
5292 if (!ch || ch->magic != DGAP_CHANNEL_MAGIC)
5297 switch (ch->pscan_state) {
5299 /* reset to sanity and fall through */
5300 ch->pscan_state = 0;
5303 /* No FF seen yet */
5304 if (c == (unsigned char) '\377')
5305 /* delete this character from stream */
5306 ch->pscan_state = 1;
5309 *fout++ = TTY_NORMAL;
5316 if (c == (unsigned char) '\377') {
5317 /* doubled ff, transform to single ff */
5319 *fout++ = TTY_NORMAL;
5321 ch->pscan_state = 0;
5323 /* save value examination in next state */
5324 ch->pscan_savechar = c;
5325 ch->pscan_state = 2;
5330 /* third character of ff sequence */
5334 if (ch->pscan_savechar == 0x0) {
5338 *fout++ = TTY_BREAK;
5340 ch->ch_err_parity++;
5341 *fout++ = TTY_PARITY;
5346 ch->pscan_state = 0;
5352 static void dgap_write_wakeup(struct board_t *bd, struct channel_t *ch,
5353 struct un_t *un, u32 mask,
5354 unsigned long *irq_flags1,
5355 unsigned long *irq_flags2)
5357 if (!(un->un_flags & mask))
5360 un->un_flags &= ~mask;
5362 if (!(un->un_flags & UN_ISOPEN))
5365 if ((un->un_tty->flags & (1 << TTY_DO_WRITE_WAKEUP)) &&
5366 un->un_tty->ldisc->ops->write_wakeup) {
5367 spin_unlock_irqrestore(&ch->ch_lock, *irq_flags2);
5368 spin_unlock_irqrestore(&bd->bd_lock, *irq_flags1);
5370 (un->un_tty->ldisc->ops->write_wakeup)(un->un_tty);
5372 spin_lock_irqsave(&bd->bd_lock, *irq_flags1);
5373 spin_lock_irqsave(&ch->ch_lock, *irq_flags2);
5375 wake_up_interruptible(&un->un_tty->write_wait);
5376 wake_up_interruptible(&un->un_flags_wait);
5379 /*=======================================================================
5381 * dgap_event - FEP to host event processing routine.
5383 * bd - Board of current event.
5385 *=======================================================================*/
5386 static int dgap_event(struct board_t *bd)
5388 struct channel_t *ch;
5391 struct bs_t __iomem *bs;
5394 struct ev_t __iomem *eaddr;
5402 if (!bd || bd->magic != DGAP_BOARD_MAGIC)
5405 spin_lock_irqsave(&bd->bd_lock, lock_flags);
5407 vaddr = bd->re_map_membase;
5410 spin_unlock_irqrestore(&bd->bd_lock, lock_flags);
5414 eaddr = (struct ev_t __iomem *) (vaddr + EVBUF);
5416 /* Get our head and tail */
5417 head = readw(&(eaddr->ev_head));
5418 tail = readw(&(eaddr->ev_tail));
5421 * Forget it if pointers out of range.
5424 if (head >= EVMAX - EVSTART || tail >= EVMAX - EVSTART ||
5425 (head | tail) & 03) {
5426 /* Let go of board lock */
5427 spin_unlock_irqrestore(&bd->bd_lock, lock_flags);
5432 * Loop to process all the events in the buffer.
5434 while (tail != head) {
5437 * Get interrupt information.
5440 event = bd->re_map_membase + tail + EVSTART;
5442 port = ioread8(event);
5443 reason = ioread8(event + 1);
5444 modem = ioread8(event + 2);
5445 b1 = ioread8(event + 3);
5448 * Make sure the interrupt is valid.
5450 if (port >= bd->nasync)
5453 if (!(reason & (IFMODEM | IFBREAK | IFTLW | IFTEM | IFDATA)))
5456 ch = bd->channels[port];
5458 if (!ch || ch->magic != DGAP_CHANNEL_MAGIC)
5462 * If we have made it here, the event was valid.
5463 * Lock down the channel.
5465 spin_lock_irqsave(&ch->ch_lock, lock_flags2);
5470 spin_unlock_irqrestore(&ch->ch_lock, lock_flags2);
5475 * Process received data.
5477 if (reason & IFDATA) {
5480 * ALL LOCKS *MUST* BE DROPPED BEFORE CALLING INPUT!
5481 * input could send some data to ld, which in turn
5482 * could do a callback to one of our other functions.
5484 spin_unlock_irqrestore(&ch->ch_lock, lock_flags2);
5485 spin_unlock_irqrestore(&bd->bd_lock, lock_flags);
5489 spin_lock_irqsave(&bd->bd_lock, lock_flags);
5490 spin_lock_irqsave(&ch->ch_lock, lock_flags2);
5492 if (ch->ch_flags & CH_RACTIVE)
5493 ch->ch_flags |= CH_RENABLE;
5495 writeb(1, &(bs->idata));
5497 if (ch->ch_flags & CH_RWAIT) {
5498 ch->ch_flags &= ~CH_RWAIT;
5500 wake_up_interruptible
5501 (&ch->ch_tun.un_flags_wait);
5506 * Process Modem change signals.
5508 if (reason & IFMODEM) {
5509 ch->ch_mistat = modem;
5516 if (reason & IFBREAK) {
5518 if (ch->ch_tun.un_tty) {
5519 /* A break has been indicated */
5521 tty_buffer_request_room
5522 (ch->ch_tun.un_tty->port, 1);
5523 tty_insert_flip_char(ch->ch_tun.un_tty->port,
5525 tty_flip_buffer_push(ch->ch_tun.un_tty->port);
5530 * Process Transmit low.
5532 if (reason & IFTLW) {
5533 dgap_write_wakeup(bd, ch, &ch->ch_tun, UN_LOW,
5534 &lock_flags, &lock_flags2);
5535 dgap_write_wakeup(bd, ch, &ch->ch_pun, UN_LOW,
5536 &lock_flags, &lock_flags2);
5537 if (ch->ch_flags & CH_WLOW) {
5538 ch->ch_flags &= ~CH_WLOW;
5539 wake_up_interruptible(&ch->ch_flags_wait);
5544 * Process Transmit empty.
5546 if (reason & IFTEM) {
5547 dgap_write_wakeup(bd, ch, &ch->ch_tun, UN_EMPTY,
5548 &lock_flags, &lock_flags2);
5549 dgap_write_wakeup(bd, ch, &ch->ch_pun, UN_EMPTY,
5550 &lock_flags, &lock_flags2);
5551 if (ch->ch_flags & CH_WEMPTY) {
5552 ch->ch_flags &= ~CH_WEMPTY;
5553 wake_up_interruptible(&ch->ch_flags_wait);
5557 spin_unlock_irqrestore(&ch->ch_lock, lock_flags2);
5560 tail = (tail + 4) & (EVMAX - EVSTART - 4);
5563 writew(tail, &(eaddr->ev_tail));
5564 spin_unlock_irqrestore(&bd->bd_lock, lock_flags);
5569 static ssize_t dgap_driver_version_show(struct device_driver *ddp, char *buf)
5571 return snprintf(buf, PAGE_SIZE, "%s\n", DG_PART);
5573 static DRIVER_ATTR(version, S_IRUSR, dgap_driver_version_show, NULL);
5576 static ssize_t dgap_driver_boards_show(struct device_driver *ddp, char *buf)
5578 return snprintf(buf, PAGE_SIZE, "%d\n", dgap_numboards);
5580 static DRIVER_ATTR(boards, S_IRUSR, dgap_driver_boards_show, NULL);
5583 static ssize_t dgap_driver_maxboards_show(struct device_driver *ddp, char *buf)
5585 return snprintf(buf, PAGE_SIZE, "%d\n", MAXBOARDS);
5587 static DRIVER_ATTR(maxboards, S_IRUSR, dgap_driver_maxboards_show, NULL);
5590 static ssize_t dgap_driver_pollcounter_show(struct device_driver *ddp,
5593 return snprintf(buf, PAGE_SIZE, "%ld\n", dgap_poll_counter);
5595 static DRIVER_ATTR(pollcounter, S_IRUSR, dgap_driver_pollcounter_show, NULL);
5597 static ssize_t dgap_driver_pollrate_show(struct device_driver *ddp, char *buf)
5599 return snprintf(buf, PAGE_SIZE, "%dms\n", dgap_poll_tick);
5602 static ssize_t dgap_driver_pollrate_store(struct device_driver *ddp,
5603 const char *buf, size_t count)
5605 if (sscanf(buf, "%d\n", &dgap_poll_tick) != 1)
5609 static DRIVER_ATTR(pollrate, (S_IRUSR | S_IWUSR), dgap_driver_pollrate_show,
5610 dgap_driver_pollrate_store);
5612 static int dgap_create_driver_sysfiles(struct pci_driver *dgap_driver)
5615 struct device_driver *driverfs = &dgap_driver->driver;
5617 rc |= driver_create_file(driverfs, &driver_attr_version);
5618 rc |= driver_create_file(driverfs, &driver_attr_boards);
5619 rc |= driver_create_file(driverfs, &driver_attr_maxboards);
5620 rc |= driver_create_file(driverfs, &driver_attr_pollrate);
5621 rc |= driver_create_file(driverfs, &driver_attr_pollcounter);
5626 static void dgap_remove_driver_sysfiles(struct pci_driver *dgap_driver)
5628 struct device_driver *driverfs = &dgap_driver->driver;
5630 driver_remove_file(driverfs, &driver_attr_version);
5631 driver_remove_file(driverfs, &driver_attr_boards);
5632 driver_remove_file(driverfs, &driver_attr_maxboards);
5633 driver_remove_file(driverfs, &driver_attr_pollrate);
5634 driver_remove_file(driverfs, &driver_attr_pollcounter);
5637 static struct board_t *dgap_verify_board(struct device *p)
5644 bd = dev_get_drvdata(p);
5645 if (!bd || bd->magic != DGAP_BOARD_MAGIC || bd->state != BOARD_READY)
5651 static ssize_t dgap_ports_state_show(struct device *p,
5652 struct device_attribute *attr,
5659 bd = dgap_verify_board(p);
5663 for (i = 0; i < bd->nasync; i++) {
5664 count += snprintf(buf + count, PAGE_SIZE - count,
5665 "%d %s\n", bd->channels[i]->ch_portnum,
5666 bd->channels[i]->ch_open_count ? "Open" : "Closed");
5670 static DEVICE_ATTR(ports_state, S_IRUSR, dgap_ports_state_show, NULL);
5672 static ssize_t dgap_ports_baud_show(struct device *p,
5673 struct device_attribute *attr,
5680 bd = dgap_verify_board(p);
5684 for (i = 0; i < bd->nasync; i++) {
5685 count += snprintf(buf + count, PAGE_SIZE - count, "%d %d\n",
5686 bd->channels[i]->ch_portnum,
5687 bd->channels[i]->ch_baud_info);
5691 static DEVICE_ATTR(ports_baud, S_IRUSR, dgap_ports_baud_show, NULL);
5693 static ssize_t dgap_ports_msignals_show(struct device *p,
5694 struct device_attribute *attr,
5701 bd = dgap_verify_board(p);
5705 for (i = 0; i < bd->nasync; i++) {
5706 if (bd->channels[i]->ch_open_count)
5707 count += snprintf(buf + count, PAGE_SIZE - count,
5708 "%d %s %s %s %s %s %s\n",
5709 bd->channels[i]->ch_portnum,
5710 (bd->channels[i]->ch_mostat &
5711 UART_MCR_RTS) ? "RTS" : "",
5712 (bd->channels[i]->ch_mistat &
5713 UART_MSR_CTS) ? "CTS" : "",
5714 (bd->channels[i]->ch_mostat &
5715 UART_MCR_DTR) ? "DTR" : "",
5716 (bd->channels[i]->ch_mistat &
5717 UART_MSR_DSR) ? "DSR" : "",
5718 (bd->channels[i]->ch_mistat &
5719 UART_MSR_DCD) ? "DCD" : "",
5720 (bd->channels[i]->ch_mistat &
5721 UART_MSR_RI) ? "RI" : "");
5723 count += snprintf(buf + count, PAGE_SIZE - count,
5724 "%d\n", bd->channels[i]->ch_portnum);
5728 static DEVICE_ATTR(ports_msignals, S_IRUSR, dgap_ports_msignals_show, NULL);
5730 static ssize_t dgap_ports_iflag_show(struct device *p,
5731 struct device_attribute *attr,
5738 bd = dgap_verify_board(p);
5742 for (i = 0; i < bd->nasync; i++)
5743 count += snprintf(buf + count, PAGE_SIZE - count, "%d %x\n",
5744 bd->channels[i]->ch_portnum,
5745 bd->channels[i]->ch_c_iflag);
5748 static DEVICE_ATTR(ports_iflag, S_IRUSR, dgap_ports_iflag_show, NULL);
5750 static ssize_t dgap_ports_cflag_show(struct device *p,
5751 struct device_attribute *attr,
5758 bd = dgap_verify_board(p);
5762 for (i = 0; i < bd->nasync; i++)
5763 count += snprintf(buf + count, PAGE_SIZE - count, "%d %x\n",
5764 bd->channels[i]->ch_portnum,
5765 bd->channels[i]->ch_c_cflag);
5768 static DEVICE_ATTR(ports_cflag, S_IRUSR, dgap_ports_cflag_show, NULL);
5770 static ssize_t dgap_ports_oflag_show(struct device *p,
5771 struct device_attribute *attr,
5778 bd = dgap_verify_board(p);
5782 for (i = 0; i < bd->nasync; i++)
5783 count += snprintf(buf + count, PAGE_SIZE - count, "%d %x\n",
5784 bd->channels[i]->ch_portnum,
5785 bd->channels[i]->ch_c_oflag);
5788 static DEVICE_ATTR(ports_oflag, S_IRUSR, dgap_ports_oflag_show, NULL);
5790 static ssize_t dgap_ports_lflag_show(struct device *p,
5791 struct device_attribute *attr,
5798 bd = dgap_verify_board(p);
5802 for (i = 0; i < bd->nasync; i++)
5803 count += snprintf(buf + count, PAGE_SIZE - count, "%d %x\n",
5804 bd->channels[i]->ch_portnum,
5805 bd->channels[i]->ch_c_lflag);
5808 static DEVICE_ATTR(ports_lflag, S_IRUSR, dgap_ports_lflag_show, NULL);
5810 static ssize_t dgap_ports_digi_flag_show(struct device *p,
5811 struct device_attribute *attr,
5818 bd = dgap_verify_board(p);
5822 for (i = 0; i < bd->nasync; i++)
5823 count += snprintf(buf + count, PAGE_SIZE - count, "%d %x\n",
5824 bd->channels[i]->ch_portnum,
5825 bd->channels[i]->ch_digi.digi_flags);
5828 static DEVICE_ATTR(ports_digi_flag, S_IRUSR, dgap_ports_digi_flag_show, NULL);
5830 static ssize_t dgap_ports_rxcount_show(struct device *p,
5831 struct device_attribute *attr,
5838 bd = dgap_verify_board(p);
5842 for (i = 0; i < bd->nasync; i++)
5843 count += snprintf(buf + count, PAGE_SIZE - count, "%d %ld\n",
5844 bd->channels[i]->ch_portnum,
5845 bd->channels[i]->ch_rxcount);
5848 static DEVICE_ATTR(ports_rxcount, S_IRUSR, dgap_ports_rxcount_show, NULL);
5850 static ssize_t dgap_ports_txcount_show(struct device *p,
5851 struct device_attribute *attr,
5858 bd = dgap_verify_board(p);
5862 for (i = 0; i < bd->nasync; i++)
5863 count += snprintf(buf + count, PAGE_SIZE - count, "%d %ld\n",
5864 bd->channels[i]->ch_portnum,
5865 bd->channels[i]->ch_txcount);
5868 static DEVICE_ATTR(ports_txcount, S_IRUSR, dgap_ports_txcount_show, NULL);
5870 /* this function creates the sys files that will export each signal status
5871 * to sysfs each value will be put in a separate filename
5873 static void dgap_create_ports_sysfiles(struct board_t *bd)
5875 dev_set_drvdata(&bd->pdev->dev, bd);
5876 device_create_file(&(bd->pdev->dev), &dev_attr_ports_state);
5877 device_create_file(&(bd->pdev->dev), &dev_attr_ports_baud);
5878 device_create_file(&(bd->pdev->dev), &dev_attr_ports_msignals);
5879 device_create_file(&(bd->pdev->dev), &dev_attr_ports_iflag);
5880 device_create_file(&(bd->pdev->dev), &dev_attr_ports_cflag);
5881 device_create_file(&(bd->pdev->dev), &dev_attr_ports_oflag);
5882 device_create_file(&(bd->pdev->dev), &dev_attr_ports_lflag);
5883 device_create_file(&(bd->pdev->dev), &dev_attr_ports_digi_flag);
5884 device_create_file(&(bd->pdev->dev), &dev_attr_ports_rxcount);
5885 device_create_file(&(bd->pdev->dev), &dev_attr_ports_txcount);
5888 /* removes all the sys files created for that port */
5889 static void dgap_remove_ports_sysfiles(struct board_t *bd)
5891 device_remove_file(&(bd->pdev->dev), &dev_attr_ports_state);
5892 device_remove_file(&(bd->pdev->dev), &dev_attr_ports_baud);
5893 device_remove_file(&(bd->pdev->dev), &dev_attr_ports_msignals);
5894 device_remove_file(&(bd->pdev->dev), &dev_attr_ports_iflag);
5895 device_remove_file(&(bd->pdev->dev), &dev_attr_ports_cflag);
5896 device_remove_file(&(bd->pdev->dev), &dev_attr_ports_oflag);
5897 device_remove_file(&(bd->pdev->dev), &dev_attr_ports_lflag);
5898 device_remove_file(&(bd->pdev->dev), &dev_attr_ports_digi_flag);
5899 device_remove_file(&(bd->pdev->dev), &dev_attr_ports_rxcount);
5900 device_remove_file(&(bd->pdev->dev), &dev_attr_ports_txcount);
5903 static ssize_t dgap_tty_state_show(struct device *d,
5904 struct device_attribute *attr,
5908 struct channel_t *ch;
5913 un = dev_get_drvdata(d);
5914 if (!un || un->magic != DGAP_UNIT_MAGIC)
5917 if (!ch || ch->magic != DGAP_CHANNEL_MAGIC)
5920 if (!bd || bd->magic != DGAP_BOARD_MAGIC)
5922 if (bd->state != BOARD_READY)
5925 return snprintf(buf, PAGE_SIZE, "%s", un->un_open_count ?
5928 static DEVICE_ATTR(state, S_IRUSR, dgap_tty_state_show, NULL);
5930 static ssize_t dgap_tty_baud_show(struct device *d,
5931 struct device_attribute *attr,
5935 struct channel_t *ch;
5940 un = dev_get_drvdata(d);
5941 if (!un || un->magic != DGAP_UNIT_MAGIC)
5944 if (!ch || ch->magic != DGAP_CHANNEL_MAGIC)
5947 if (!bd || bd->magic != DGAP_BOARD_MAGIC)
5949 if (bd->state != BOARD_READY)
5952 return snprintf(buf, PAGE_SIZE, "%d\n", ch->ch_baud_info);
5954 static DEVICE_ATTR(baud, S_IRUSR, dgap_tty_baud_show, NULL);
5956 static ssize_t dgap_tty_msignals_show(struct device *d,
5957 struct device_attribute *attr,
5961 struct channel_t *ch;
5966 un = dev_get_drvdata(d);
5967 if (!un || un->magic != DGAP_UNIT_MAGIC)
5970 if (!ch || ch->magic != DGAP_CHANNEL_MAGIC)
5973 if (!bd || bd->magic != DGAP_BOARD_MAGIC)
5975 if (bd->state != BOARD_READY)
5978 if (ch->ch_open_count) {
5979 return snprintf(buf, PAGE_SIZE, "%s %s %s %s %s %s\n",
5980 (ch->ch_mostat & UART_MCR_RTS) ? "RTS" : "",
5981 (ch->ch_mistat & UART_MSR_CTS) ? "CTS" : "",
5982 (ch->ch_mostat & UART_MCR_DTR) ? "DTR" : "",
5983 (ch->ch_mistat & UART_MSR_DSR) ? "DSR" : "",
5984 (ch->ch_mistat & UART_MSR_DCD) ? "DCD" : "",
5985 (ch->ch_mistat & UART_MSR_RI) ? "RI" : "");
5989 static DEVICE_ATTR(msignals, S_IRUSR, dgap_tty_msignals_show, NULL);
5991 static ssize_t dgap_tty_iflag_show(struct device *d,
5992 struct device_attribute *attr,
5996 struct channel_t *ch;
6001 un = dev_get_drvdata(d);
6002 if (!un || un->magic != DGAP_UNIT_MAGIC)
6005 if (!ch || ch->magic != DGAP_CHANNEL_MAGIC)
6008 if (!bd || bd->magic != DGAP_BOARD_MAGIC)
6010 if (bd->state != BOARD_READY)
6013 return snprintf(buf, PAGE_SIZE, "%x\n", ch->ch_c_iflag);
6015 static DEVICE_ATTR(iflag, S_IRUSR, dgap_tty_iflag_show, NULL);
6017 static ssize_t dgap_tty_cflag_show(struct device *d,
6018 struct device_attribute *attr,
6022 struct channel_t *ch;
6027 un = dev_get_drvdata(d);
6028 if (!un || un->magic != DGAP_UNIT_MAGIC)
6031 if (!ch || ch->magic != DGAP_CHANNEL_MAGIC)
6034 if (!bd || bd->magic != DGAP_BOARD_MAGIC)
6036 if (bd->state != BOARD_READY)
6039 return snprintf(buf, PAGE_SIZE, "%x\n", ch->ch_c_cflag);
6041 static DEVICE_ATTR(cflag, S_IRUSR, dgap_tty_cflag_show, NULL);
6043 static ssize_t dgap_tty_oflag_show(struct device *d,
6044 struct device_attribute *attr,
6048 struct channel_t *ch;
6053 un = dev_get_drvdata(d);
6054 if (!un || un->magic != DGAP_UNIT_MAGIC)
6057 if (!ch || ch->magic != DGAP_CHANNEL_MAGIC)
6060 if (!bd || bd->magic != DGAP_BOARD_MAGIC)
6062 if (bd->state != BOARD_READY)
6065 return snprintf(buf, PAGE_SIZE, "%x\n", ch->ch_c_oflag);
6067 static DEVICE_ATTR(oflag, S_IRUSR, dgap_tty_oflag_show, NULL);
6069 static ssize_t dgap_tty_lflag_show(struct device *d,
6070 struct device_attribute *attr,
6074 struct channel_t *ch;
6079 un = dev_get_drvdata(d);
6080 if (!un || un->magic != DGAP_UNIT_MAGIC)
6083 if (!ch || ch->magic != DGAP_CHANNEL_MAGIC)
6086 if (!bd || bd->magic != DGAP_BOARD_MAGIC)
6088 if (bd->state != BOARD_READY)
6091 return snprintf(buf, PAGE_SIZE, "%x\n", ch->ch_c_lflag);
6093 static DEVICE_ATTR(lflag, S_IRUSR, dgap_tty_lflag_show, NULL);
6095 static ssize_t dgap_tty_digi_flag_show(struct device *d,
6096 struct device_attribute *attr,
6100 struct channel_t *ch;
6105 un = dev_get_drvdata(d);
6106 if (!un || un->magic != DGAP_UNIT_MAGIC)
6109 if (!ch || ch->magic != DGAP_CHANNEL_MAGIC)
6112 if (!bd || bd->magic != DGAP_BOARD_MAGIC)
6114 if (bd->state != BOARD_READY)
6117 return snprintf(buf, PAGE_SIZE, "%x\n", ch->ch_digi.digi_flags);
6119 static DEVICE_ATTR(digi_flag, S_IRUSR, dgap_tty_digi_flag_show, NULL);
6121 static ssize_t dgap_tty_rxcount_show(struct device *d,
6122 struct device_attribute *attr,
6126 struct channel_t *ch;
6131 un = dev_get_drvdata(d);
6132 if (!un || un->magic != DGAP_UNIT_MAGIC)
6135 if (!ch || ch->magic != DGAP_CHANNEL_MAGIC)
6138 if (!bd || bd->magic != DGAP_BOARD_MAGIC)
6140 if (bd->state != BOARD_READY)
6143 return snprintf(buf, PAGE_SIZE, "%ld\n", ch->ch_rxcount);
6145 static DEVICE_ATTR(rxcount, S_IRUSR, dgap_tty_rxcount_show, NULL);
6147 static ssize_t dgap_tty_txcount_show(struct device *d,
6148 struct device_attribute *attr,
6152 struct channel_t *ch;
6157 un = dev_get_drvdata(d);
6158 if (!un || un->magic != DGAP_UNIT_MAGIC)
6161 if (!ch || ch->magic != DGAP_CHANNEL_MAGIC)
6164 if (!bd || bd->magic != DGAP_BOARD_MAGIC)
6166 if (bd->state != BOARD_READY)
6169 return snprintf(buf, PAGE_SIZE, "%ld\n", ch->ch_txcount);
6171 static DEVICE_ATTR(txcount, S_IRUSR, dgap_tty_txcount_show, NULL);
6173 static ssize_t dgap_tty_name_show(struct device *d,
6174 struct device_attribute *attr,
6178 struct channel_t *ch;
6190 un = dev_get_drvdata(d);
6191 if (!un || un->magic != DGAP_UNIT_MAGIC)
6194 if (!ch || ch->magic != DGAP_CHANNEL_MAGIC)
6197 if (!bd || bd->magic != DGAP_BOARD_MAGIC)
6199 if (bd->state != BOARD_READY)
6203 cn = ch->ch_portnum;
6205 for (cptr = bd->bd_config; cptr; cptr = cptr->next) {
6207 if ((cptr->type == BNODE) &&
6208 ((cptr->u.board.type == APORT2_920P) ||
6209 (cptr->u.board.type == APORT4_920P) ||
6210 (cptr->u.board.type == APORT8_920P) ||
6211 (cptr->u.board.type == PAPORT4) ||
6212 (cptr->u.board.type == PAPORT8))) {
6215 if (cptr->u.board.v_start)
6216 starto = cptr->u.board.start;
6221 if (cptr->type == TNODE && found == TRUE) {
6224 if (strstr(cptr->u.ttyname, "tty")) {
6225 ptr1 = cptr->u.ttyname;
6228 ptr1 = cptr->u.ttyname;
6230 for (i = 0; i < dgap_config_get_num_prts(bd); i++) {
6234 return snprintf(buf, PAGE_SIZE, "%s%s%02d\n",
6235 (un->un_type == DGAP_PRINT) ?
6241 if (cptr->type == CNODE) {
6243 for (i = 0; i < cptr->u.conc.nport; i++) {
6244 if (cn != (i + ncount))
6247 return snprintf(buf, PAGE_SIZE, "%s%s%02ld\n",
6248 (un->un_type == DGAP_PRINT) ?
6251 i + (cptr->u.conc.v_start ?
6252 cptr->u.conc.start : 1));
6255 ncount += cptr->u.conc.nport;
6258 if (cptr->type == MNODE) {
6260 for (i = 0; i < cptr->u.module.nport; i++) {
6261 if (cn != (i + ncount))
6264 return snprintf(buf, PAGE_SIZE, "%s%s%02ld\n",
6265 (un->un_type == DGAP_PRINT) ?
6268 i + (cptr->u.module.v_start ?
6269 cptr->u.module.start : 1));
6272 ncount += cptr->u.module.nport;
6277 return snprintf(buf, PAGE_SIZE, "%s_dgap_%d_%d\n",
6278 (un->un_type == DGAP_PRINT) ? "pr" : "tty", bn, cn);
6280 static DEVICE_ATTR(custom_name, S_IRUSR, dgap_tty_name_show, NULL);
6282 static struct attribute *dgap_sysfs_tty_entries[] = {
6283 &dev_attr_state.attr,
6284 &dev_attr_baud.attr,
6285 &dev_attr_msignals.attr,
6286 &dev_attr_iflag.attr,
6287 &dev_attr_cflag.attr,
6288 &dev_attr_oflag.attr,
6289 &dev_attr_lflag.attr,
6290 &dev_attr_digi_flag.attr,
6291 &dev_attr_rxcount.attr,
6292 &dev_attr_txcount.attr,
6293 &dev_attr_custom_name.attr,
6297 static struct attribute_group dgap_tty_attribute_group = {
6299 .attrs = dgap_sysfs_tty_entries,
6302 static void dgap_create_tty_sysfs(struct un_t *un, struct device *c)
6306 ret = sysfs_create_group(&c->kobj, &dgap_tty_attribute_group);
6310 dev_set_drvdata(c, un);
6314 static void dgap_remove_tty_sysfs(struct device *c)
6316 sysfs_remove_group(&c->kobj, &dgap_tty_attribute_group);
6319 static void dgap_cleanup_nodes(void)
6326 struct cnode *tmp = p->next;
6328 if (p->type == NULLNODE) {
6335 kfree(p->u.board.portstr);
6336 kfree(p->u.board.addrstr);
6337 kfree(p->u.board.pcibusstr);
6338 kfree(p->u.board.pcislotstr);
6339 kfree(p->u.board.method);
6342 kfree(p->u.conc.id);
6343 kfree(p->u.conc.connect);
6346 kfree(p->u.module.id);
6349 kfree(p->u.ttyname);
6355 kfree(p->u.line.cable);
6358 kfree(p->u.printname);
6362 kfree(p->u.board.status);
6368 * Parse a configuration file read into memory as a string.
6370 static int dgap_parsefile(char **in)
6372 struct cnode *p, *brd, *line, *conc;
6378 brd = line = conc = NULL;
6380 /* perhaps we are adding to an existing list? */
6384 /* file must start with a BEGIN */
6385 while ((rc = dgap_gettok(in)) != BEGIN) {
6387 pr_err("unexpected EOF");
6395 int module_type = 0;
6397 rc = dgap_gettok(in);
6399 pr_err("unexpected EOF");
6404 case BEGIN: /* should only be 1 begin */
6405 pr_err("unexpected config_begin\n");
6411 case BOARD: /* board info */
6412 if (dgap_checknode(p))
6415 p->next = kzalloc(sizeof(struct cnode), GFP_KERNEL);
6422 p->u.board.status = kstrdup("No", GFP_KERNEL);
6427 board_type = dgap_gettok(in);
6428 if (board_type == 0) {
6429 pr_err("board !!type not specified");
6433 p->u.board.type = board_type;
6437 case IO: /* i/o port */
6438 if (p->type != BNODE) {
6439 pr_err("IO port only vaild for boards");
6442 s = dgap_getword(in);
6444 pr_err("unexpected end of file");
6447 p->u.board.portstr = kstrdup(s, GFP_KERNEL);
6448 if (kstrtol(s, 0, &p->u.board.port)) {
6449 pr_err("bad number for IO port");
6452 p->u.board.v_port = 1;
6455 case MEM: /* memory address */
6456 if (p->type != BNODE) {
6457 pr_err("memory address only vaild for boards");
6460 s = dgap_getword(in);
6462 pr_err("unexpected end of file");
6465 p->u.board.addrstr = kstrdup(s, GFP_KERNEL);
6466 if (kstrtoul(s, 0, &p->u.board.addr)) {
6467 pr_err("bad number for memory address");
6470 p->u.board.v_addr = 1;
6473 case PCIINFO: /* pci information */
6474 if (p->type != BNODE) {
6475 pr_err("memory address only vaild for boards");
6478 s = dgap_getword(in);
6480 pr_err("unexpected end of file");
6483 p->u.board.pcibusstr = kstrdup(s, GFP_KERNEL);
6484 if (kstrtoul(s, 0, &p->u.board.pcibus)) {
6485 pr_err("bad number for pci bus");
6488 p->u.board.v_pcibus = 1;
6489 s = dgap_getword(in);
6491 pr_err("unexpected end of file");
6494 p->u.board.pcislotstr = kstrdup(s, GFP_KERNEL);
6495 if (kstrtoul(s, 0, &p->u.board.pcislot)) {
6496 pr_err("bad number for pci slot");
6499 p->u.board.v_pcislot = 1;
6503 if (p->type != BNODE) {
6504 pr_err("install method only vaild for boards");
6507 s = dgap_getword(in);
6509 pr_err("unexpected end of file");
6512 p->u.board.method = kstrdup(s, GFP_KERNEL);
6513 p->u.board.v_method = 1;
6517 if (p->type != BNODE) {
6518 pr_err("config status only vaild for boards");
6521 s = dgap_getword(in);
6523 pr_err("unexpected end of file");
6526 p->u.board.status = kstrdup(s, GFP_KERNEL);
6529 case NPORTS: /* number of ports */
6530 if (p->type == BNODE) {
6531 s = dgap_getword(in);
6533 pr_err("unexpected end of file");
6536 if (kstrtol(s, 0, &p->u.board.nport)) {
6537 pr_err("bad number for number of ports");
6540 p->u.board.v_nport = 1;
6541 } else if (p->type == CNODE) {
6542 s = dgap_getword(in);
6544 pr_err("unexpected end of file");
6547 if (kstrtol(s, 0, &p->u.conc.nport)) {
6548 pr_err("bad number for number of ports");
6551 p->u.conc.v_nport = 1;
6552 } else if (p->type == MNODE) {
6553 s = dgap_getword(in);
6555 pr_err("unexpected end of file");
6558 if (kstrtol(s, 0, &p->u.module.nport)) {
6559 pr_err("bad number for number of ports");
6562 p->u.module.v_nport = 1;
6564 pr_err("nports only valid for concentrators or modules");
6569 case ID: /* letter ID used in tty name */
6570 s = dgap_getword(in);
6572 pr_err("unexpected end of file");
6576 p->u.board.status = kstrdup(s, GFP_KERNEL);
6578 if (p->type == CNODE) {
6579 p->u.conc.id = kstrdup(s, GFP_KERNEL);
6581 } else if (p->type == MNODE) {
6582 p->u.module.id = kstrdup(s, GFP_KERNEL);
6583 p->u.module.v_id = 1;
6585 pr_err("id only valid for concentrators or modules");
6590 case STARTO: /* start offset of ID */
6591 if (p->type == BNODE) {
6592 s = dgap_getword(in);
6594 pr_err("unexpected end of file");
6597 if (kstrtol(s, 0, &p->u.board.start)) {
6598 pr_err("bad number for start of tty count");
6601 p->u.board.v_start = 1;
6602 } else if (p->type == CNODE) {
6603 s = dgap_getword(in);
6605 pr_err("unexpected end of file");
6608 if (kstrtol(s, 0, &p->u.conc.start)) {
6609 pr_err("bad number for start of tty count");
6612 p->u.conc.v_start = 1;
6613 } else if (p->type == MNODE) {
6614 s = dgap_getword(in);
6616 pr_err("unexpected end of file");
6619 if (kstrtol(s, 0, &p->u.module.start)) {
6620 pr_err("bad number for start of tty count");
6623 p->u.module.v_start = 1;
6625 pr_err("start only valid for concentrators or modules");
6630 case TTYN: /* tty name prefix */
6631 if (dgap_checknode(p))
6634 p->next = kzalloc(sizeof(struct cnode), GFP_KERNEL);
6641 s = dgap_getword(in);
6643 pr_err("unexpeced end of file");
6646 p->u.ttyname = kstrdup(s, GFP_KERNEL);
6652 case CU: /* cu name prefix */
6653 if (dgap_checknode(p))
6656 p->next = kzalloc(sizeof(struct cnode), GFP_KERNEL);
6663 s = dgap_getword(in);
6665 pr_err("unexpeced end of file");
6668 p->u.cuname = kstrdup(s, GFP_KERNEL);
6674 case LINE: /* line information */
6675 if (dgap_checknode(p))
6678 pr_err("must specify board before line info");
6681 switch (brd->u.board.type) {
6683 pr_err("line not vaild for PC/em");
6687 p->next = kzalloc(sizeof(struct cnode), GFP_KERNEL);
6698 case CONC: /* concentrator information */
6699 if (dgap_checknode(p))
6702 pr_err("must specify line info before concentrator");
6706 p->next = kzalloc(sizeof(struct cnode), GFP_KERNEL);
6715 brd->u.board.conc2++;
6717 brd->u.board.conc1++;
6719 conc_type = dgap_gettok(in);
6720 if (conc_type == 0 || conc_type != CX ||
6722 pr_err("failed to set a type of concentratros");
6726 p->u.conc.type = conc_type;
6730 case MOD: /* EBI module */
6731 if (dgap_checknode(p))
6734 pr_err("must specify board info before EBI modules");
6737 switch (brd->u.board.type) {
6743 pr_err("must specify concentrator info before EBI module");
6748 p->next = kzalloc(sizeof(struct cnode), GFP_KERNEL);
6756 brd->u.board.module2++;
6758 brd->u.board.module1++;
6760 module_type = dgap_gettok(in);
6761 if (module_type == 0 || module_type != PORTS ||
6762 module_type != MODEM) {
6763 pr_err("failed to set a type of module");
6767 p->u.module.type = module_type;
6772 if (p->type == LNODE) {
6773 s = dgap_getword(in);
6775 pr_err("unexpected end of file");
6778 p->u.line.cable = kstrdup(s, GFP_KERNEL);
6779 p->u.line.v_cable = 1;
6783 case SPEED: /* sync line speed indication */
6784 if (p->type == LNODE) {
6785 s = dgap_getword(in);
6787 pr_err("unexpected end of file");
6790 if (kstrtol(s, 0, &p->u.line.speed)) {
6791 pr_err("bad number for line speed");
6794 p->u.line.v_speed = 1;
6795 } else if (p->type == CNODE) {
6796 s = dgap_getword(in);
6798 pr_err("unexpected end of file");
6801 if (kstrtol(s, 0, &p->u.conc.speed)) {
6802 pr_err("bad number for line speed");
6805 p->u.conc.v_speed = 1;
6807 pr_err("speed valid only for lines or concentrators.");
6813 if (p->type == CNODE) {
6814 s = dgap_getword(in);
6816 pr_err("unexpected end of file");
6819 p->u.conc.connect = kstrdup(s, GFP_KERNEL);
6820 p->u.conc.v_connect = 1;
6823 case PRINT: /* transparent print name prefix */
6824 if (dgap_checknode(p))
6827 p->next = kzalloc(sizeof(struct cnode), GFP_KERNEL);
6834 s = dgap_getword(in);
6836 pr_err("unexpeced end of file");
6839 p->u.printname = kstrdup(s, GFP_KERNEL);
6840 if (!p->u.printname)
6845 case CMAJOR: /* major number */
6846 if (dgap_checknode(p))
6849 p->next = kzalloc(sizeof(struct cnode), GFP_KERNEL);
6856 s = dgap_getword(in);
6858 pr_err("unexpected end of file");
6861 if (kstrtol(s, 0, &p->u.majornumber)) {
6862 pr_err("bad number for major number");
6867 case ALTPIN: /* altpin setting */
6868 if (dgap_checknode(p))
6871 p->next = kzalloc(sizeof(struct cnode), GFP_KERNEL);
6878 s = dgap_getword(in);
6880 pr_err("unexpected end of file");
6883 if (kstrtol(s, 0, &p->u.altpin)) {
6884 pr_err("bad number for altpin");
6889 case USEINTR: /* enable interrupt setting */
6890 if (dgap_checknode(p))
6893 p->next = kzalloc(sizeof(struct cnode), GFP_KERNEL);
6899 s = dgap_getword(in);
6901 pr_err("unexpected end of file");
6904 if (kstrtol(s, 0, &p->u.useintr)) {
6905 pr_err("bad number for useintr");
6910 case TTSIZ: /* size of tty structure */
6911 if (dgap_checknode(p))
6914 p->next = kzalloc(sizeof(struct cnode), GFP_KERNEL);
6921 s = dgap_getword(in);
6923 pr_err("unexpected end of file");
6926 if (kstrtol(s, 0, &p->u.ttysize)) {
6927 pr_err("bad number for ttysize");
6932 case CHSIZ: /* channel structure size */
6933 if (dgap_checknode(p))
6936 p->next = kzalloc(sizeof(struct cnode), GFP_KERNEL);
6943 s = dgap_getword(in);
6945 pr_err("unexpected end of file");
6948 if (kstrtol(s, 0, &p->u.chsize)) {
6949 pr_err("bad number for chsize");
6954 case BSSIZ: /* board structure size */
6955 if (dgap_checknode(p))
6958 p->next = kzalloc(sizeof(struct cnode), GFP_KERNEL);
6965 s = dgap_getword(in);
6967 pr_err("unexpected end of file");
6970 if (kstrtol(s, 0, &p->u.bssize)) {
6971 pr_err("bad number for bssize");
6976 case UNTSIZ: /* sched structure size */
6977 if (dgap_checknode(p))
6980 p->next = kzalloc(sizeof(struct cnode), GFP_KERNEL);
6987 s = dgap_getword(in);
6989 pr_err("unexpected end of file");
6992 if (kstrtol(s, 0, &p->u.unsize)) {
6993 pr_err("bad number for schedsize");
6998 case F2SIZ: /* f2200 structure size */
6999 if (dgap_checknode(p))
7002 p->next = kzalloc(sizeof(struct cnode), GFP_KERNEL);
7009 s = dgap_getword(in);
7011 pr_err("unexpected end of file");
7014 if (kstrtol(s, 0, &p->u.f2size)) {
7015 pr_err("bad number for f2200size");
7020 case VPSIZ: /* vpix structure size */
7021 if (dgap_checknode(p))
7024 p->next = kzalloc(sizeof(struct cnode), GFP_KERNEL);
7031 s = dgap_getword(in);
7033 pr_err("unexpected end of file");
7036 if (kstrtol(s, 0, &p->u.vpixsize)) {
7037 pr_err("bad number for vpixsize");
7046 * dgap_sindex: much like index(), but it looks for a match of any character in
7047 * the group, and returns that position. If the first character is a ^, then
7048 * this will match the first occurrence not in that group.
7050 static char *dgap_sindex(char *string, char *group)
7054 if (!string || !group)
7055 return (char *) NULL;
7057 if (*group == '^') {
7059 for (; *string; string++) {
7060 for (ptr = group; *ptr; ptr++) {
7061 if (*ptr == *string)
7068 for (; *string; string++) {
7069 for (ptr = group; *ptr; ptr++) {
7070 if (*ptr == *string)
7076 return (char *) NULL;
7080 * Get a token from the input file; return 0 if end of file is reached
7082 static int dgap_gettok(char **in)
7087 if (strstr(dgap_cword, "board")) {
7088 w = dgap_getword(in);
7089 snprintf(dgap_cword, MAXCWORD, "%s", w);
7090 for (t = dgap_brdtype; t->token != 0; t++) {
7091 if (!strcmp(w, t->string))
7095 while ((w = dgap_getword(in))) {
7096 snprintf(dgap_cword, MAXCWORD, "%s", w);
7097 for (t = dgap_tlist; t->token != 0; t++) {
7098 if (!strcmp(w, t->string))
7108 * get a word from the input stream, also keep track of current line number.
7109 * words are separated by whitespace.
7111 static char *dgap_getword(char **in)
7113 char *ret_ptr = *in;
7115 char *ptr = dgap_sindex(*in, " \t\n");
7117 /* If no word found, return null */
7121 /* Mark new location for our buffer */
7125 /* Eat any extra spaces/tabs/newlines that might be present */
7126 while (*in && **in && ((**in == ' ') ||
7137 * dgap_checknode: see if all the necessary info has been supplied for a node
7138 * before creating the next node.
7140 static int dgap_checknode(struct cnode *p)
7144 if (p->u.line.v_speed == 0) {
7145 pr_err("line speed not specified");
7151 if (p->u.conc.v_speed == 0) {
7152 pr_err("concentrator line speed not specified");
7155 if (p->u.conc.v_nport == 0) {
7156 pr_err("number of ports on concentrator not specified");
7159 if (p->u.conc.v_id == 0) {
7160 pr_err("concentrator id letter not specified");
7166 if (p->u.module.v_nport == 0) {
7167 pr_err("number of ports on EBI module not specified");
7170 if (p->u.module.v_id == 0) {
7171 pr_err("EBI module id letter not specified");
7180 * Given a board pointer, returns whether we should use interrupts or not.
7182 static uint dgap_config_get_useintr(struct board_t *bd)
7189 for (p = bd->bd_config; p; p = p->next) {
7190 if (p->type == INTRNODE) {
7192 * check for pcxr types.
7194 return p->u.useintr;
7198 /* If not found, then don't turn on interrupts. */
7203 * Given a board pointer, returns whether we turn on altpin or not.
7205 static uint dgap_config_get_altpin(struct board_t *bd)
7212 for (p = bd->bd_config; p; p = p->next) {
7213 if (p->type == ANODE) {
7215 * check for pcxr types.
7221 /* If not found, then don't turn on interrupts. */
7226 * Given a specific type of board, if found, detached link and
7227 * returns the first occurrence in the list.
7229 static struct cnode *dgap_find_config(int type, int bus, int slot)
7231 struct cnode *p, *prev, *prev2, *found;
7239 if (p->type != BNODE)
7242 if (p->u.board.type != type)
7245 if (p->u.board.v_pcibus &&
7246 p->u.board.pcibus != bus)
7249 if (p->u.board.v_pcislot &&
7250 p->u.board.pcislot != slot)
7255 * Keep walking thru the list till we
7256 * find the next board.
7262 if (p->type != BNODE)
7266 * Mark the end of our 1 board
7272 * Link the "next" board to the
7273 * previous board, effectively
7274 * "unlinking" our board from
7282 * It must be the last board in the list.
7291 * Given a board pointer, walks the config link, counting up
7292 * all ports user specified should be on the board.
7293 * (This does NOT mean they are all actually present right now tho)
7295 static uint dgap_config_get_num_prts(struct board_t *bd)
7303 for (p = bd->bd_config; p; p = p->next) {
7308 * check for pcxr types.
7310 if (p->u.board.type > EPCFE)
7311 count += p->u.board.nport;
7314 count += p->u.conc.nport;
7317 count += p->u.module.nport;
7324 static char *dgap_create_config_string(struct board_t *bd, char *string)
7336 for (p = bd->bd_config; p; p = p->next) {
7342 *ptr = p->u.line.speed;
7347 * Because the EPC/con concentrators can have EM modules
7348 * hanging off of them, we have to walk ahead in the
7349 * list and keep adding the number of ports on each EM
7350 * to the config. UGH!
7352 speed = p->u.conc.speed;
7354 if (q && (q->type == MNODE)) {
7355 *ptr = (p->u.conc.nport + 0x80);
7358 while (q->next && (q->next->type) == MNODE) {
7359 *ptr = (q->u.module.nport + 0x80);
7364 *ptr = q->u.module.nport;
7367 *ptr = p->u.conc.nport;