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.
15 * You should have received a copy of the GNU General Public License
16 * along with this program; if not, write to the Free Software
17 * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
20 * NOTE TO LINUX KERNEL HACKERS: DO NOT REFORMAT THIS CODE!
22 * This is shared code between Digi's CVS archive and the
23 * Linux Kernel sources.
24 * Changing the source just for reformatting needlessly breaks
25 * our CVS diff history.
27 * Send any bug fixes/changes to: Eng.Linux at digi dot com.
33 * In the original out of kernel Digi dgap driver, firmware
34 * loading was done via user land to driver handshaking.
36 * For cards that support a concentrator (port expander),
37 * I believe the concentrator its self told the card which
38 * concentrator is actually attached and then that info
39 * was used to tell user land which concentrator firmware
40 * image was to be downloaded. I think even the BIOS or
41 * FEP images required could change with the connection
42 * of a particular concentrator.
44 * Since I have no access to any of these cards or
45 * concentrators, I cannot put the correct concentrator
46 * firmware file names into the firmware_info structure
47 * as is now done for the BIOS and FEP images.
49 * I think, but am not certain, that the cards supporting
50 * concentrators will function without them. So support
51 * of these cards has been left in this driver.
53 * In order to fully support those cards, they would
54 * either have to be acquired for dissection or maybe
55 * Digi International could provide some assistance.
57 #undef DIGI_CONCENTRATORS_SUPPORTED
59 #include <linux/kernel.h>
60 #include <linux/module.h>
61 #include <linux/pci.h>
62 #include <linux/delay.h> /* For udelay */
63 #include <linux/slab.h>
64 #include <linux/uaccess.h>
65 #include <linux/sched.h>
67 #include <linux/interrupt.h> /* For tasklet and interrupt structs/defines */
68 #include <linux/ctype.h>
69 #include <linux/tty.h>
70 #include <linux/tty_flip.h>
71 #include <linux/serial_reg.h>
72 #include <linux/io.h> /* For read[bwl]/write[bwl] */
74 #include <linux/string.h>
75 #include <linux/device.h>
76 #include <linux/kdev_t.h>
77 #include <linux/firmware.h>
81 #define init_MUTEX(sem) sema_init(sem, 1)
82 #define DECLARE_MUTEX(name) \
83 struct semaphore name = __SEMAPHORE_INITIALIZER(name, 1)
85 MODULE_LICENSE("GPL");
86 MODULE_AUTHOR("Digi International, http://www.digi.com");
87 MODULE_DESCRIPTION("Driver for the Digi International EPCA PCI based product line");
88 MODULE_SUPPORTED_DEVICE("dgap");
90 /**************************************************************************
92 * protos for this file
96 static int dgap_start(void);
97 static void dgap_init_globals(void);
98 static int dgap_found_board(struct pci_dev *pdev, int id);
99 static void dgap_cleanup_board(struct board_t *brd);
100 static void dgap_poll_handler(ulong dummy);
101 static int dgap_init_pci(void);
102 static int dgap_init_one(struct pci_dev *pdev, const struct pci_device_id *ent);
103 static void dgap_remove_one(struct pci_dev *dev);
104 static int dgap_probe1(struct pci_dev *pdev, int card_type);
105 static int dgap_do_remap(struct board_t *brd);
106 static irqreturn_t dgap_intr(int irq, void *voidbrd);
108 /* Our function prototypes */
109 static int dgap_tty_open(struct tty_struct *tty, struct file *file);
110 static void dgap_tty_close(struct tty_struct *tty, struct file *file);
111 static int dgap_block_til_ready(struct tty_struct *tty, struct file *file,
112 struct channel_t *ch);
113 static int dgap_tty_ioctl(struct tty_struct *tty, unsigned int cmd,
115 static int dgap_tty_digigeta(struct tty_struct *tty,
116 struct digi_t __user *retinfo);
117 static int dgap_tty_digiseta(struct tty_struct *tty,
118 struct digi_t __user *new_info);
119 static int dgap_tty_digigetedelay(struct tty_struct *tty, int __user *retinfo);
120 static int dgap_tty_digisetedelay(struct tty_struct *tty, int __user *new_info);
121 static int dgap_tty_write_room(struct tty_struct *tty);
122 static int dgap_tty_chars_in_buffer(struct tty_struct *tty);
123 static void dgap_tty_start(struct tty_struct *tty);
124 static void dgap_tty_stop(struct tty_struct *tty);
125 static void dgap_tty_throttle(struct tty_struct *tty);
126 static void dgap_tty_unthrottle(struct tty_struct *tty);
127 static void dgap_tty_flush_chars(struct tty_struct *tty);
128 static void dgap_tty_flush_buffer(struct tty_struct *tty);
129 static void dgap_tty_hangup(struct tty_struct *tty);
130 static int dgap_wait_for_drain(struct tty_struct *tty);
131 static int dgap_set_modem_info(struct tty_struct *tty, unsigned int command,
132 unsigned int __user *value);
133 static int dgap_get_modem_info(struct channel_t *ch,
134 unsigned int __user *value);
135 static int dgap_tty_digisetcustombaud(struct tty_struct *tty,
136 int __user *new_info);
137 static int dgap_tty_digigetcustombaud(struct tty_struct *tty,
138 int __user *retinfo);
139 static int dgap_tty_tiocmget(struct tty_struct *tty);
140 static int dgap_tty_tiocmset(struct tty_struct *tty, unsigned int set,
142 static int dgap_tty_send_break(struct tty_struct *tty, int msec);
143 static void dgap_tty_wait_until_sent(struct tty_struct *tty, int timeout);
144 static int dgap_tty_write(struct tty_struct *tty, const unsigned char *buf,
146 static void dgap_tty_set_termios(struct tty_struct *tty,
147 struct ktermios *old_termios);
148 static int dgap_tty_put_char(struct tty_struct *tty, unsigned char c);
149 static void dgap_tty_send_xchar(struct tty_struct *tty, char ch);
151 static int dgap_tty_register(struct board_t *brd);
152 static int dgap_tty_init(struct board_t *);
153 static void dgap_tty_uninit(struct board_t *);
154 static void dgap_carrier(struct channel_t *ch);
155 static void dgap_input(struct channel_t *ch);
158 * Our function prototypes from dgap_fep5
160 static void dgap_cmdw_ext(struct channel_t *ch, u16 cmd, u16 word, uint ncmds);
161 static int dgap_event(struct board_t *bd);
163 static void dgap_poll_tasklet(unsigned long data);
164 static void dgap_cmdb(struct channel_t *ch, uchar cmd, uchar byte1,
165 uchar byte2, uint ncmds);
166 static void dgap_cmdw(struct channel_t *ch, uchar cmd, u16 word, uint ncmds);
167 static void dgap_wmove(struct channel_t *ch, char *buf, uint cnt);
168 static int dgap_param(struct tty_struct *tty);
169 static void dgap_parity_scan(struct channel_t *ch, unsigned char *cbuf,
170 unsigned char *fbuf, int *len);
171 static uint dgap_get_custom_baud(struct channel_t *ch);
172 static void dgap_firmware_reset_port(struct channel_t *ch);
175 * Function prototypes from dgap_parse.c.
177 static int dgap_gettok(char **in, struct cnode *p);
178 static char *dgap_getword(char **in);
179 static char *dgap_savestring(char *s);
180 static struct cnode *dgap_newnode(int t);
181 static int dgap_checknode(struct cnode *p);
182 static void dgap_err(char *s);
185 * Function prototypes from dgap_sysfs.h
193 static void dgap_create_ports_sysfiles(struct board_t *bd);
194 static void dgap_remove_ports_sysfiles(struct board_t *bd);
196 static int dgap_create_driver_sysfiles(struct pci_driver *);
197 static void dgap_remove_driver_sysfiles(struct pci_driver *);
199 static void dgap_create_tty_sysfs(struct un_t *un, struct device *c);
200 static void dgap_remove_tty_sysfs(struct device *c);
203 * Function prototypes from dgap_parse.h
205 static int dgap_parsefile(char **in, int Remove);
206 static struct cnode *dgap_find_config(int type, int bus, int slot);
207 static uint dgap_config_get_number_of_ports(struct board_t *bd);
208 static char *dgap_create_config_string(struct board_t *bd, char *string);
209 static uint dgap_config_get_useintr(struct board_t *bd);
210 static uint dgap_config_get_altpin(struct board_t *bd);
212 static int dgap_ms_sleep(ulong ms);
213 static void dgap_do_bios_load(struct board_t *brd, uchar __user *ubios,
215 static void dgap_do_fep_load(struct board_t *brd, uchar __user *ufep, int len);
216 #ifdef DIGI_CONCENTRATORS_SUPPORTED
217 static void dgap_do_conc_load(struct board_t *brd, uchar *uaddr, int len);
219 static int dgap_after_config_loaded(int board);
220 static int dgap_finalize_board_init(struct board_t *brd);
222 static void dgap_get_vpd(struct board_t *brd);
223 static void dgap_do_reset_board(struct board_t *brd);
224 static void dgap_do_wait_for_bios(struct board_t *brd);
225 static void dgap_do_wait_for_fep(struct board_t *brd);
226 static int dgap_tty_register_ports(struct board_t *brd);
227 static int dgap_firmware_load(struct pci_dev *pdev, int card_type);
229 /* Driver unload function */
230 static void dgap_cleanup_module(void);
232 module_exit(dgap_cleanup_module);
235 * File operations permitted on Control/Management major.
237 static const struct file_operations DgapBoardFops = {
238 .owner = THIS_MODULE,
244 static uint dgap_NumBoards;
245 static struct board_t *dgap_Board[MAXBOARDS];
246 static ulong dgap_poll_counter;
247 static char *dgap_config_buf;
248 static int dgap_driver_state = DRIVER_INITIALIZED;
249 DEFINE_SPINLOCK(dgap_dl_lock);
250 static wait_queue_head_t dgap_dl_wait;
251 static int dgap_dl_action;
252 static int dgap_poll_tick = 20; /* Poll interval - 20 ms */
257 static struct class *dgap_class;
259 static struct board_t *dgap_BoardsByMajor[256];
260 static uint dgap_count = 500;
265 DEFINE_SPINLOCK(dgap_poll_lock); /* Poll scheduling lock */
266 static ulong dgap_poll_time; /* Time of next poll */
267 static uint dgap_poll_stop; /* Used to tell poller to stop */
268 static struct timer_list dgap_poll_timer;
273 Card Model Number of Ports Interface
274 ----------------------------------------------------------------
275 Acceleport Xem 4 - 64 (EIA232 & EIA422)
276 Acceleport Xr 4 & 8 (EIA232)
277 Acceleport Xr 920 4 & 8 (EIA232)
278 Acceleport C/X 8 - 128 (EIA232)
279 Acceleport EPC/X 8 - 224 (EIA232)
280 Acceleport Xr/422 4 & 8 (EIA422)
281 Acceleport 2r/920 2 (EIA232)
282 Acceleport 4r/920 4 (EIA232)
283 Acceleport 8r/920 8 (EIA232)
285 IBM 8-Port Asynchronous PCI Adapter (EIA232)
286 IBM 128-Port Asynchronous PCI Adapter (EIA232 & EIA422)
289 static struct pci_device_id dgap_pci_tbl[] = {
290 { DIGI_VID, PCI_DEV_XEM_DID, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0 },
291 { DIGI_VID, PCI_DEV_CX_DID, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 1 },
292 { DIGI_VID, PCI_DEV_CX_IBM_DID, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 2 },
293 { DIGI_VID, PCI_DEV_EPCJ_DID, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 3 },
294 { DIGI_VID, PCI_DEV_920_2_DID, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 4 },
295 { DIGI_VID, PCI_DEV_920_4_DID, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 5 },
296 { DIGI_VID, PCI_DEV_920_8_DID, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 6 },
297 { DIGI_VID, PCI_DEV_XR_DID, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 7 },
298 { DIGI_VID, PCI_DEV_XRJ_DID, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 8 },
299 { DIGI_VID, PCI_DEV_XR_422_DID, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 9 },
300 { DIGI_VID, PCI_DEV_XR_IBM_DID, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 10 },
301 { DIGI_VID, PCI_DEV_XR_SAIP_DID, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 11 },
302 { DIGI_VID, PCI_DEV_XR_BULL_DID, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 12 },
303 { DIGI_VID, PCI_DEV_920_8_HP_DID, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 13 },
304 { DIGI_VID, PCI_DEV_XEM_HP_DID, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 14 },
305 {0,} /* 0 terminated list. */
307 MODULE_DEVICE_TABLE(pci, dgap_pci_tbl);
310 * A generic list of Product names, PCI Vendor ID, and PCI Device ID.
319 static struct board_id dgap_Ids[] = {
320 { PPCM, PCI_DEV_XEM_NAME, 64, (T_PCXM|T_PCLITE|T_PCIBUS) },
321 { PCX, PCI_DEV_CX_NAME, 128, (T_CX|T_PCIBUS) },
322 { PCX, PCI_DEV_CX_IBM_NAME, 128, (T_CX|T_PCIBUS) },
323 { PEPC, PCI_DEV_EPCJ_NAME, 224, (T_EPC|T_PCIBUS) },
324 { APORT2_920P, PCI_DEV_920_2_NAME, 2, (T_PCXR|T_PCLITE|T_PCIBUS) },
325 { APORT4_920P, PCI_DEV_920_4_NAME, 4, (T_PCXR|T_PCLITE|T_PCIBUS) },
326 { APORT8_920P, PCI_DEV_920_8_NAME, 8, (T_PCXR|T_PCLITE|T_PCIBUS) },
327 { PAPORT8, PCI_DEV_XR_NAME, 8, (T_PCXR|T_PCLITE|T_PCIBUS) },
328 { PAPORT8, PCI_DEV_XRJ_NAME, 8, (T_PCXR|T_PCLITE|T_PCIBUS) },
329 { PAPORT8, PCI_DEV_XR_422_NAME, 8, (T_PCXR|T_PCLITE|T_PCIBUS) },
330 { PAPORT8, PCI_DEV_XR_IBM_NAME, 8, (T_PCXR|T_PCLITE|T_PCIBUS) },
331 { PAPORT8, PCI_DEV_XR_SAIP_NAME, 8, (T_PCXR|T_PCLITE|T_PCIBUS) },
332 { PAPORT8, PCI_DEV_XR_BULL_NAME, 8, (T_PCXR|T_PCLITE|T_PCIBUS) },
333 { APORT8_920P, PCI_DEV_920_8_HP_NAME, 8, (T_PCXR|T_PCLITE|T_PCIBUS) },
334 { PPCM, PCI_DEV_XEM_HP_NAME, 64, (T_PCXM|T_PCLITE|T_PCIBUS) },
335 {0,} /* 0 terminated list. */
338 static struct pci_driver dgap_driver = {
340 .probe = dgap_init_one,
341 .id_table = dgap_pci_tbl,
342 .remove = dgap_remove_one,
345 struct firmware_info {
346 uchar *conf_name; /* dgap.conf */
347 uchar *bios_name; /* BIOS filename */
348 uchar *fep_name; /* FEP filename */
349 uchar *con_name; /* Concentrator filename FIXME*/
350 int num; /* sequence number */
354 * Firmware - BIOS, FEP, and CONC filenames
356 static struct firmware_info fw_info[] = {
357 { "dgap/dgap.conf", "dgap/sxbios.bin", "dgap/sxfep.bin", 0, 0 },
358 { "dgap/dgap.conf", "dgap/cxpbios.bin", "dgap/cxpfep.bin", 0, 1 },
359 { "dgap/dgap.conf", "dgap/cxpbios.bin", "dgap/cxpfep.bin", 0, 2 },
360 { "dgap/dgap.conf", "dgap/pcibios.bin", "dgap/pcifep.bin", 0, 3 },
361 { "dgap/dgap.conf", "dgap/xrbios.bin", "dgap/xrfep.bin", 0, 4 },
362 { "dgap/dgap.conf", "dgap/xrbios.bin", "dgap/xrfep.bin", 0, 5 },
363 { "dgap/dgap.conf", "dgap/xrbios.bin", "dgap/xrfep.bin", 0, 6 },
364 { "dgap/dgap.conf", "dgap/xrbios.bin", "dgap/xrfep.bin", 0, 7 },
365 { "dgap/dgap.conf", "dgap/xrbios.bin", "dgap/xrfep.bin", 0, 8 },
366 { "dgap/dgap.conf", "dgap/xrbios.bin", "dgap/xrfep.bin", 0, 9 },
367 { "dgap/dgap.conf", "dgap/xrbios.bin", "dgap/xrfep.bin", 0, 10 },
368 { "dgap/dgap.conf", "dgap/xrbios.bin", "dgap/xrfep.bin", 0, 11 },
369 { "dgap/dgap.conf", "dgap/xrbios.bin", "dgap/xrfep.bin", 0, 12 },
370 { "dgap/dgap.conf", "dgap/xrbios.bin", "dgap/xrfep.bin", 0, 13 },
371 { "dgap/dgap.conf", "dgap/sxbios.bin", "dgap/sxfep.bin", 0, 14 },
376 * Default transparent print information.
378 static struct digi_t dgap_digi_init = {
379 .digi_flags = DIGI_COOK, /* Flags */
380 .digi_maxcps = 100, /* Max CPS */
381 .digi_maxchar = 50, /* Max chars in print queue */
382 .digi_bufsize = 100, /* Printer buffer size */
383 .digi_onlen = 4, /* size of printer on string */
384 .digi_offlen = 4, /* size of printer off string */
385 .digi_onstr = "\033[5i", /* ANSI printer on string ] */
386 .digi_offstr = "\033[4i", /* ANSI printer off string ] */
387 .digi_term = "ansi" /* default terminal type */
391 * Define a local default termios struct. All ports will be created
392 * with this termios initially.
394 * This defines a raw port at 9600 baud, 8 data bits, no parity,
398 static struct ktermios DgapDefaultTermios = {
399 .c_iflag = (DEFAULT_IFLAGS), /* iflags */
400 .c_oflag = (DEFAULT_OFLAGS), /* oflags */
401 .c_cflag = (DEFAULT_CFLAGS), /* cflags */
402 .c_lflag = (DEFAULT_LFLAGS), /* lflags */
407 static const struct tty_operations dgap_tty_ops = {
408 .open = dgap_tty_open,
409 .close = dgap_tty_close,
410 .write = dgap_tty_write,
411 .write_room = dgap_tty_write_room,
412 .flush_buffer = dgap_tty_flush_buffer,
413 .chars_in_buffer = dgap_tty_chars_in_buffer,
414 .flush_chars = dgap_tty_flush_chars,
415 .ioctl = dgap_tty_ioctl,
416 .set_termios = dgap_tty_set_termios,
417 .stop = dgap_tty_stop,
418 .start = dgap_tty_start,
419 .throttle = dgap_tty_throttle,
420 .unthrottle = dgap_tty_unthrottle,
421 .hangup = dgap_tty_hangup,
422 .put_char = dgap_tty_put_char,
423 .tiocmget = dgap_tty_tiocmget,
424 .tiocmset = dgap_tty_tiocmset,
425 .break_ctl = dgap_tty_send_break,
426 .wait_until_sent = dgap_tty_wait_until_sent,
427 .send_xchar = dgap_tty_send_xchar
431 * Our needed internal static variables from dgap_parse.c
433 static struct cnode dgap_head;
435 static char dgap_cword[MAXCWORD];
442 static struct toklist dgap_tlist[] = {
443 { BEGIN, "config_begin" },
444 { END, "config_end" },
446 { PCX, "Digi_AccelePort_C/X_PCI" },
447 { PEPC, "Digi_AccelePort_EPC/X_PCI" },
448 { PPCM, "Digi_AccelePort_Xem_PCI" },
449 { APORT2_920P, "Digi_AccelePort_2r_920_PCI" },
450 { APORT4_920P, "Digi_AccelePort_4r_920_PCI" },
451 { APORT8_920P, "Digi_AccelePort_8r_920_PCI" },
452 { PAPORT4, "Digi_AccelePort_4r_PCI(EIA-232/RS-422)" },
453 { PAPORT8, "Digi_AccelePort_8r_PCI(EIA-232/RS-422)" },
455 { PCIINFO, "pciinfo" },
458 { CONC, "concentrator" },
468 { CONNECT, "connect" },
469 { METHOD, "method" },
470 { STATUS, "status" },
471 { CUSTOM, "Custom" },
477 { NPORTS, "nports" },
482 { ALTPIN, "altpin" },
483 { USEINTR, "useintr" },
484 { TTSIZ, "ttysize" },
486 { BSSIZ, "boardsize" },
487 { UNTSIZ, "schedsize" },
488 { F2SIZ, "f2200size" },
489 { VPSIZ, "vpixsize" },
493 /************************************************************************
495 * Driver load/unload functions
497 ************************************************************************/
502 * Module load. This is where it all starts.
504 static int dgap_init_module(void)
508 pr_info("%s, Digi International Part Number %s\n", DG_NAME, DG_PART);
514 rc = dgap_init_pci();
518 rc = dgap_create_driver_sysfiles(&dgap_driver);
522 dgap_driver_state = DRIVER_READY;
528 dgap_cleanup_module();
532 module_init(dgap_init_module);
537 static int dgap_start(void)
541 struct device *device;
544 * make sure that the globals are
545 * init'd before we do anything else
551 pr_info("For the tools package please visit http://www.digi.com\n");
554 * Register our base character device into the kernel.
558 * Register management/dpa devices
560 rc = register_chrdev(DIGI_DGAP_MAJOR, "dgap", &DgapBoardFops);
564 dgap_class = class_create(THIS_MODULE, "dgap_mgmt");
565 if (IS_ERR(dgap_class)) {
566 rc = PTR_ERR(dgap_class);
570 device = device_create(dgap_class, NULL,
571 MKDEV(DIGI_DGAP_MAJOR, 0),
573 if (IS_ERR(device)) {
574 rc = PTR_ERR(device);
578 /* Start the poller */
579 DGAP_LOCK(dgap_poll_lock, flags);
580 init_timer(&dgap_poll_timer);
581 dgap_poll_timer.function = dgap_poll_handler;
582 dgap_poll_timer.data = 0;
583 dgap_poll_time = jiffies + dgap_jiffies_from_ms(dgap_poll_tick);
584 dgap_poll_timer.expires = dgap_poll_time;
585 DGAP_UNLOCK(dgap_poll_lock, flags);
587 add_timer(&dgap_poll_timer);
592 class_destroy(dgap_class);
594 unregister_chrdev(DIGI_DGAP_MAJOR, "dgap");
599 * Register pci driver, and return how many boards we have.
601 static int dgap_init_pci(void)
603 return pci_register_driver(&dgap_driver);
606 /* returns count (>= 0), or negative on error */
607 static int dgap_init_one(struct pci_dev *pdev, const struct pci_device_id *ent)
611 /* wake up and enable device */
612 rc = pci_enable_device(pdev);
617 rc = dgap_probe1(pdev, ent->driver_data);
620 rc = dgap_firmware_load(pdev, ent->driver_data);
626 static int dgap_probe1(struct pci_dev *pdev, int card_type)
628 return dgap_found_board(pdev, card_type);
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 DGAP_LOCK(dgap_poll_lock, lock_flags);
648 DGAP_UNLOCK(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 kfree(dgap_config_buf);
661 for (i = 0; i < dgap_NumBoards; ++i) {
662 dgap_remove_ports_sysfiles(dgap_Board[i]);
663 dgap_tty_uninit(dgap_Board[i]);
664 dgap_cleanup_board(dgap_Board[i]);
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)
683 if (brd->intr_used && brd->irq)
684 free_irq(brd->irq, brd);
686 tasklet_kill(&brd->helper_tasklet);
688 if (brd->re_map_port) {
689 release_mem_region(brd->membase + 0x200000, 0x200000);
690 iounmap(brd->re_map_port);
691 brd->re_map_port = NULL;
694 if (brd->re_map_membase) {
695 release_mem_region(brd->membase, 0x200000);
696 iounmap(brd->re_map_membase);
697 brd->re_map_membase = NULL;
700 /* Free all allocated channels structs */
701 for (i = 0; i < MAXPORTS ; i++)
702 kfree(brd->channels[i]);
705 kfree(brd->flipflagbuf);
707 dgap_Board[brd->boardnum] = NULL;
715 * A board has been found, init it.
717 static int dgap_found_board(struct pci_dev *pdev, int id)
720 unsigned int pci_irq;
723 /* get the board structure and prep it */
724 brd = kzalloc(sizeof(struct board_t), GFP_KERNEL);
728 dgap_Board[dgap_NumBoards] = brd;
730 /* store the info for the board we've found */
731 brd->magic = DGAP_BOARD_MAGIC;
732 brd->boardnum = dgap_NumBoards;
734 brd->vendor = dgap_pci_tbl[id].vendor;
735 brd->device = dgap_pci_tbl[id].device;
737 brd->pci_bus = pdev->bus->number;
738 brd->pci_slot = PCI_SLOT(pdev->devfn);
739 brd->name = dgap_Ids[id].name;
740 brd->maxports = dgap_Ids[id].maxports;
741 brd->type = dgap_Ids[id].config_type;
742 brd->dpatype = dgap_Ids[id].dpatype;
743 brd->dpastatus = BD_NOFEP;
744 init_waitqueue_head(&brd->state_wait);
746 spin_lock_init(&brd->bd_lock);
748 brd->state = BOARD_FOUND;
750 brd->inhibit_poller = FALSE;
751 brd->wait_for_bios = 0;
752 brd->wait_for_fep = 0;
754 for (i = 0; i < MAXPORTS; i++)
755 brd->channels[i] = NULL;
757 /* store which card & revision we have */
758 pci_read_config_word(pdev, PCI_SUBSYSTEM_VENDOR_ID, &brd->subvendor);
759 pci_read_config_word(pdev, PCI_SUBSYSTEM_ID, &brd->subdevice);
760 pci_read_config_byte(pdev, PCI_REVISION_ID, &brd->rev);
765 /* get the PCI Base Address Registers */
767 /* Xr Jupiter and EPC use BAR 2 */
768 if (brd->device == PCI_DEV_XRJ_DID || brd->device == PCI_DEV_EPCJ_DID) {
769 brd->membase = pci_resource_start(pdev, 2);
770 brd->membase_end = pci_resource_end(pdev, 2);
772 /* Everyone else uses BAR 0 */
774 brd->membase = pci_resource_start(pdev, 0);
775 brd->membase_end = pci_resource_end(pdev, 0);
781 if (brd->membase & 1)
787 * On the PCI boards, there is no IO space allocated
788 * The I/O registers will be in the first 3 bytes of the
789 * upper 2MB of the 4MB memory space. The board memory
790 * will be mapped into the low 2MB of the 4MB memory space
792 brd->port = brd->membase + PCI_IO_OFFSET;
793 brd->port_end = brd->port + PCI_IO_SIZE;
796 * Special initialization for non-PLX boards
798 if (brd->device != PCI_DEV_XRJ_DID && brd->device != PCI_DEV_EPCJ_DID) {
801 pci_write_config_byte(pdev, 0x40, 0);
802 pci_write_config_byte(pdev, 0x46, 0);
804 /* Limit burst length to 2 doubleword transactions */
805 pci_write_config_byte(pdev, 0x42, 1);
808 * Enable IO and mem if not already done.
809 * This was needed for support on Itanium.
811 pci_read_config_word(pdev, PCI_COMMAND, &cmd);
812 cmd |= (PCI_COMMAND_IO | PCI_COMMAND_MEMORY);
813 pci_write_config_word(pdev, PCI_COMMAND, cmd);
816 /* init our poll helper tasklet */
817 tasklet_init(&brd->helper_tasklet, dgap_poll_tasklet,
818 (unsigned long) brd);
820 i = dgap_do_remap(brd);
822 brd->state = BOARD_FAILED;
824 brd->state = NEED_RESET;
830 static int dgap_finalize_board_init(struct board_t *brd)
834 if (!brd || brd->magic != DGAP_BOARD_MAGIC)
837 brd->use_interrupts = dgap_config_get_useintr(brd);
840 * Set up our interrupt handler if we are set to do interrupts.
842 if (brd->use_interrupts && brd->irq) {
844 rc = request_irq(brd->irq, dgap_intr, IRQF_SHARED, "DGAP", brd);
857 static int dgap_firmware_load(struct pci_dev *pdev, int card_type)
859 struct board_t *brd = dgap_Board[dgap_NumBoards - 1];
860 const struct firmware *fw;
864 dgap_do_reset_board(brd);
866 if (fw_info[card_type].conf_name) {
867 ret = request_firmware(&fw, fw_info[card_type].conf_name,
870 pr_err("dgap: config file %s not found\n",
871 fw_info[card_type].conf_name);
874 if (!dgap_config_buf) {
875 dgap_config_buf = kmalloc(fw->size + 1, GFP_ATOMIC);
876 if (!dgap_config_buf) {
877 release_firmware(fw);
882 memcpy(dgap_config_buf, fw->data, fw->size);
883 release_firmware(fw);
884 dgap_config_buf[fw->size + 1] = '\0';
886 if (dgap_parsefile(&dgap_config_buf, TRUE) != 0)
890 ret = dgap_after_config_loaded(brd->boardnum);
894 * Match this board to a config the user created for us.
897 dgap_find_config(brd->type, brd->pci_bus, brd->pci_slot);
900 * Because the 4 port Xr products share the same PCI ID
901 * as the 8 port Xr products, if we receive a NULL config
902 * back, and this is a PAPORT8 board, retry with a
903 * PAPORT4 attempt as well.
905 if (brd->type == PAPORT8 && !brd->bd_config)
907 dgap_find_config(PAPORT4, brd->pci_bus, brd->pci_slot);
909 if (!brd->bd_config) {
910 pr_err("dgap: No valid configuration found\n");
914 dgap_tty_register(brd);
915 dgap_finalize_board_init(brd);
917 if (fw_info[card_type].bios_name) {
918 ret = request_firmware(&fw, fw_info[card_type].bios_name,
921 pr_err("dgap: bios file %s not found\n",
922 fw_info[card_type].bios_name);
925 dgap_do_bios_load(brd, (char *)fw->data, fw->size);
926 release_firmware(fw);
928 /* Wait for BIOS to test board... */
929 dgap_do_wait_for_bios(brd);
931 if (brd->state != FINISHED_BIOS_LOAD)
935 if (fw_info[card_type].fep_name) {
936 ret = request_firmware(&fw, fw_info[card_type].fep_name,
939 pr_err("dgap: fep file %s not found\n",
940 fw_info[card_type].fep_name);
943 dgap_do_fep_load(brd, (char *)fw->data, fw->size);
944 release_firmware(fw);
946 /* Wait for FEP to load on board... */
947 dgap_do_wait_for_fep(brd);
949 if (brd->state != FINISHED_FEP_LOAD)
953 #ifdef DIGI_CONCENTRATORS_SUPPORTED
955 * If this is a CX or EPCX, we need to see if the firmware
956 * is requesting a concentrator image from us.
958 if ((bd->type == PCX) || (bd->type == PEPC)) {
959 chk_addr = (u16 *) (vaddr + DOWNREQ);
960 /* Nonzero if FEP is requesting concentrator image. */
961 check = readw(chk_addr);
962 vaddr = brd->re_map_membase;
965 if (fw_info[card_type].con_name && check && vaddr) {
966 ret = request_firmware(&fw, fw_info[card_type].con_name,
969 pr_err("dgap: conc file %s not found\n",
970 fw_info[card_type].con_name);
973 /* Put concentrator firmware loading code here */
974 offset = readw((u16 *) (vaddr + DOWNREQ));
975 memcpy_toio(offset, fw->data, fw->size);
977 dgap_do_conc_load(brd, (char *)fw->data, fw->size)
978 release_firmware(fw);
982 * Do tty device initialization.
984 ret = dgap_tty_init(brd);
986 dgap_tty_uninit(brd);
990 ret = dgap_tty_register_ports(brd);
994 brd->state = BOARD_READY;
995 brd->dpastatus = BD_RUNNING;
1003 static int dgap_do_remap(struct board_t *brd)
1005 if (!brd || brd->magic != DGAP_BOARD_MAGIC)
1008 if (!request_mem_region(brd->membase, 0x200000, "dgap"))
1011 if (!request_mem_region(brd->membase + PCI_IO_OFFSET, 0x200000,
1013 release_mem_region(brd->membase, 0x200000);
1017 brd->re_map_membase = ioremap(brd->membase, 0x200000);
1018 if (!brd->re_map_membase) {
1019 release_mem_region(brd->membase, 0x200000);
1020 release_mem_region(brd->membase + PCI_IO_OFFSET, 0x200000);
1024 brd->re_map_port = ioremap((brd->membase + PCI_IO_OFFSET), 0x200000);
1025 if (!brd->re_map_port) {
1026 release_mem_region(brd->membase, 0x200000);
1027 release_mem_region(brd->membase + PCI_IO_OFFSET, 0x200000);
1028 iounmap(brd->re_map_membase);
1035 /*****************************************************************************
1055 * As each timer expires, it determines (a) whether the "transmit"
1056 * waiter needs to be woken up, and (b) whether the poller needs to
1059 ******************************************************************************/
1061 static void dgap_poll_handler(ulong dummy)
1064 struct board_t *brd;
1065 unsigned long lock_flags;
1068 dgap_poll_counter++;
1071 * Do not start the board state machine until
1072 * driver tells us its up and running, and has
1073 * everything it needs.
1075 if (dgap_driver_state != DRIVER_READY)
1076 goto schedule_poller;
1079 * If we have just 1 board, or the system is not SMP,
1080 * then use the typical old style poller.
1081 * Otherwise, use our new tasklet based poller, which should
1082 * speed things up for multiple boards.
1084 if ((dgap_NumBoards == 1) || (num_online_cpus() <= 1)) {
1085 for (i = 0; i < dgap_NumBoards; i++) {
1087 brd = dgap_Board[i];
1089 if (brd->state == BOARD_FAILED)
1091 if (!brd->intr_running)
1092 /* Call the real board poller directly */
1093 dgap_poll_tasklet((unsigned long) brd);
1097 * Go thru each board, kicking off a
1098 * tasklet for each if needed
1100 for (i = 0; i < dgap_NumBoards; i++) {
1101 brd = dgap_Board[i];
1104 * Attempt to grab the board lock.
1106 * If we can't get it, no big deal, the next poll
1107 * will get it. Basically, I just really don't want
1108 * to spin in here, because I want to kick off my
1109 * tasklets as fast as I can, and then get out the
1112 if (!spin_trylock(&brd->bd_lock))
1116 * If board is in a failed state, don't bother
1117 * scheduling a tasklet
1119 if (brd->state == BOARD_FAILED) {
1120 spin_unlock(&brd->bd_lock);
1124 /* Schedule a poll helper task */
1125 if (!brd->intr_running)
1126 tasklet_schedule(&brd->helper_tasklet);
1129 * Can't do DGAP_UNLOCK here, as we don't have
1130 * lock_flags because we did a trylock above.
1132 spin_unlock(&brd->bd_lock);
1139 * Schedule ourself back at the nominal wakeup interval.
1141 DGAP_LOCK(dgap_poll_lock, lock_flags);
1142 dgap_poll_time += dgap_jiffies_from_ms(dgap_poll_tick);
1144 new_time = dgap_poll_time - jiffies;
1146 if ((ulong) new_time >= 2 * dgap_poll_tick) {
1148 jiffies + dgap_jiffies_from_ms(dgap_poll_tick);
1151 dgap_poll_timer.function = dgap_poll_handler;
1152 dgap_poll_timer.data = 0;
1153 dgap_poll_timer.expires = dgap_poll_time;
1154 DGAP_UNLOCK(dgap_poll_lock, lock_flags);
1156 if (!dgap_poll_stop)
1157 add_timer(&dgap_poll_timer);
1163 * Driver interrupt handler.
1165 static irqreturn_t dgap_intr(int irq, void *voidbrd)
1167 struct board_t *brd = (struct board_t *) voidbrd;
1173 * Check to make sure its for us.
1175 if (brd->magic != DGAP_BOARD_MAGIC)
1181 * Schedule tasklet to run at a better time.
1183 tasklet_schedule(&brd->helper_tasklet);
1188 * dgap_init_globals()
1190 * This is where we initialize the globals from the static insmod
1191 * configuration variables. These are declared near the head of
1194 static void dgap_init_globals(void)
1198 for (i = 0; i < MAXBOARDS; i++)
1199 dgap_Board[i] = NULL;
1201 init_timer(&dgap_poll_timer);
1203 init_waitqueue_head(&dgap_dl_wait);
1207 /************************************************************************
1211 ************************************************************************/
1216 * Put the driver to sleep for x ms's
1218 * Returns 0 if timed out, !0 (showing signal) if interrupted by a signal.
1220 static int dgap_ms_sleep(ulong ms)
1222 current->state = TASK_INTERRUPTIBLE;
1223 schedule_timeout((ms * HZ) / 1000);
1224 return signal_pending(current);
1227 /************************************************************************
1229 * TTY Initialization/Cleanup Functions
1231 ************************************************************************/
1234 * dgap_tty_register()
1236 * Init the tty subsystem for this board.
1238 static int dgap_tty_register(struct board_t *brd)
1242 brd->SerialDriver = alloc_tty_driver(MAXPORTS);
1244 snprintf(brd->SerialName, MAXTTYNAMELEN, "tty_dgap_%d_", brd->boardnum);
1245 brd->SerialDriver->name = brd->SerialName;
1246 brd->SerialDriver->name_base = 0;
1247 brd->SerialDriver->major = 0;
1248 brd->SerialDriver->minor_start = 0;
1249 brd->SerialDriver->type = TTY_DRIVER_TYPE_SERIAL;
1250 brd->SerialDriver->subtype = SERIAL_TYPE_NORMAL;
1251 brd->SerialDriver->init_termios = DgapDefaultTermios;
1252 brd->SerialDriver->driver_name = DRVSTR;
1253 brd->SerialDriver->flags = (TTY_DRIVER_REAL_RAW |
1254 TTY_DRIVER_DYNAMIC_DEV |
1255 TTY_DRIVER_HARDWARE_BREAK);
1257 /* The kernel wants space to store pointers to tty_structs */
1258 brd->SerialDriver->ttys =
1259 kzalloc(MAXPORTS * sizeof(struct tty_struct *), GFP_KERNEL);
1260 if (!brd->SerialDriver->ttys)
1264 * Entry points for driver. Called by the kernel from
1265 * tty_io.c and n_tty.c.
1267 tty_set_operations(brd->SerialDriver, &dgap_tty_ops);
1270 * If we're doing transparent print, we have to do all of the above
1271 * again, separately so we don't get the LD confused about what major
1272 * we are when we get into the dgap_tty_open() routine.
1274 brd->PrintDriver = alloc_tty_driver(MAXPORTS);
1276 snprintf(brd->PrintName, MAXTTYNAMELEN, "pr_dgap_%d_", brd->boardnum);
1277 brd->PrintDriver->name = brd->PrintName;
1278 brd->PrintDriver->name_base = 0;
1279 brd->PrintDriver->major = 0;
1280 brd->PrintDriver->minor_start = 0;
1281 brd->PrintDriver->type = TTY_DRIVER_TYPE_SERIAL;
1282 brd->PrintDriver->subtype = SERIAL_TYPE_NORMAL;
1283 brd->PrintDriver->init_termios = DgapDefaultTermios;
1284 brd->PrintDriver->driver_name = DRVSTR;
1285 brd->PrintDriver->flags = (TTY_DRIVER_REAL_RAW |
1286 TTY_DRIVER_DYNAMIC_DEV |
1287 TTY_DRIVER_HARDWARE_BREAK);
1289 /* The kernel wants space to store pointers to tty_structs */
1290 brd->PrintDriver->ttys =
1291 kzalloc(MAXPORTS * sizeof(struct tty_struct *), GFP_KERNEL);
1292 if (!brd->PrintDriver->ttys)
1296 * Entry points for driver. Called by the kernel from
1297 * tty_io.c and n_tty.c.
1299 tty_set_operations(brd->PrintDriver, &dgap_tty_ops);
1301 if (!brd->dgap_Major_Serial_Registered) {
1302 /* Register tty devices */
1303 rc = tty_register_driver(brd->SerialDriver);
1306 brd->dgap_Major_Serial_Registered = TRUE;
1307 dgap_BoardsByMajor[brd->SerialDriver->major] = brd;
1308 brd->dgap_Serial_Major = brd->SerialDriver->major;
1311 if (!brd->dgap_Major_TransparentPrint_Registered) {
1312 /* Register Transparent Print devices */
1313 rc = tty_register_driver(brd->PrintDriver);
1316 brd->dgap_Major_TransparentPrint_Registered = TRUE;
1317 dgap_BoardsByMajor[brd->PrintDriver->major] = brd;
1318 brd->dgap_TransparentPrint_Major = brd->PrintDriver->major;
1327 * Init the tty subsystem. Called once per board after board has been
1328 * downloaded and init'ed.
1330 static int dgap_tty_init(struct board_t *brd)
1334 uint true_count = 0;
1337 struct channel_t *ch;
1345 * Initialize board structure elements.
1348 vaddr = brd->re_map_membase;
1349 true_count = readw((vaddr + NCHAN));
1351 brd->nasync = dgap_config_get_number_of_ports(brd);
1354 brd->nasync = brd->maxports;
1356 if (brd->nasync > brd->maxports)
1357 brd->nasync = brd->maxports;
1359 if (true_count != brd->nasync) {
1360 if ((brd->type == PPCM) && (true_count == 64)) {
1361 pr_warn("dgap: %s configured for %d ports, has %d ports.\n",
1362 brd->name, brd->nasync, true_count);
1363 pr_warn("dgap: Please make SURE the EBI cable running from the card\n");
1364 pr_warn("dgap: to each EM module is plugged into EBI IN!\n");
1365 } else if ((brd->type == PPCM) && (true_count == 0)) {
1366 pr_warn("dgap: %s configured for %d ports, has %d ports.\n",
1367 brd->name, brd->nasync, true_count);
1368 pr_warn("dgap: Please make SURE the EBI cable running from the card\n");
1369 pr_warn("dgap: to each EM module is plugged into EBI IN!\n");
1371 pr_warn("dgap: %s configured for %d ports, has %d ports.\n",
1372 brd->name, brd->nasync, true_count);
1374 brd->nasync = true_count;
1376 /* If no ports, don't bother going any further */
1378 brd->state = BOARD_FAILED;
1379 brd->dpastatus = BD_NOFEP;
1385 * Allocate channel memory that might not have been allocated
1386 * when the driver was first loaded.
1388 for (i = 0; i < brd->nasync; i++) {
1389 if (!brd->channels[i]) {
1391 kzalloc(sizeof(struct channel_t), GFP_ATOMIC);
1392 if (!brd->channels[i])
1397 ch = brd->channels[0];
1398 vaddr = brd->re_map_membase;
1400 bs = (struct bs_t *) ((ulong) vaddr + CHANBUF);
1401 cm = (struct cm_t *) ((ulong) vaddr + CMDBUF);
1405 /* Set up channel variables */
1406 for (i = 0; i < brd->nasync; i++, ch = brd->channels[i], bs++) {
1408 if (!brd->channels[i])
1411 spin_lock_init(&ch->ch_lock);
1413 /* Store all our magic numbers */
1414 ch->magic = DGAP_CHANNEL_MAGIC;
1415 ch->ch_tun.magic = DGAP_UNIT_MAGIC;
1416 ch->ch_tun.un_type = DGAP_SERIAL;
1417 ch->ch_tun.un_ch = ch;
1418 ch->ch_tun.un_dev = i;
1420 ch->ch_pun.magic = DGAP_UNIT_MAGIC;
1421 ch->ch_pun.un_type = DGAP_PRINT;
1422 ch->ch_pun.un_ch = ch;
1423 ch->ch_pun.un_dev = i;
1425 ch->ch_vaddr = vaddr;
1430 ch->ch_digi = dgap_digi_init;
1433 * Set up digi dsr and dcd bits based on altpin flag.
1435 if (dgap_config_get_altpin(brd)) {
1438 ch->ch_digi.digi_flags |= DIGI_ALTPIN;
1441 ch->ch_dsr = DM_DSR;
1444 ch->ch_taddr = vaddr + ((ch->ch_bs->tx_seg) << 4);
1445 ch->ch_raddr = vaddr + ((ch->ch_bs->rx_seg) << 4);
1448 ch->ch_tsize = readw(&(ch->ch_bs->tx_max)) + 1;
1449 ch->ch_rsize = readw(&(ch->ch_bs->rx_max)) + 1;
1453 /* .25 second delay */
1454 ch->ch_close_delay = 250;
1457 * Set queue water marks, interrupt mask,
1458 * and general tty parameters.
1460 tlw = ch->ch_tsize >= 2000 ? ((ch->ch_tsize * 5) / 8) :
1464 dgap_cmdw(ch, STLOW, tlw, 0);
1466 dgap_cmdw(ch, SRLOW, ch->ch_rsize / 2, 0);
1468 dgap_cmdw(ch, SRHIGH, 7 * ch->ch_rsize / 8, 0);
1470 ch->ch_mistat = readb(&(ch->ch_bs->m_stat));
1472 init_waitqueue_head(&ch->ch_flags_wait);
1473 init_waitqueue_head(&ch->ch_tun.un_flags_wait);
1474 init_waitqueue_head(&ch->ch_pun.un_flags_wait);
1475 init_waitqueue_head(&ch->ch_sniff_wait);
1477 /* Turn on all modem interrupts for now */
1478 modem = (DM_CD | DM_DSR | DM_CTS | DM_RI);
1479 writeb(modem, &(ch->ch_bs->m_int));
1482 * Set edelay to 0 if interrupts are turned on,
1483 * otherwise set edelay to the usual 100.
1486 writew(0, &(ch->ch_bs->edelay));
1488 writew(100, &(ch->ch_bs->edelay));
1490 writeb(1, &(ch->ch_bs->idata));
1499 * Uninitialize the TTY portion of this driver. Free all memory and
1502 static void dgap_tty_uninit(struct board_t *brd)
1507 if (brd->dgap_Major_Serial_Registered) {
1508 dgap_BoardsByMajor[brd->SerialDriver->major] = NULL;
1509 brd->dgap_Serial_Major = 0;
1510 for (i = 0; i < brd->nasync; i++) {
1511 tty_port_destroy(&brd->SerialPorts[i]);
1512 dev = brd->channels[i]->ch_tun.un_sysfs;
1513 dgap_remove_tty_sysfs(dev);
1514 tty_unregister_device(brd->SerialDriver, i);
1516 tty_unregister_driver(brd->SerialDriver);
1517 kfree(brd->SerialDriver->ttys);
1518 brd->SerialDriver->ttys = NULL;
1519 put_tty_driver(brd->SerialDriver);
1520 kfree(brd->SerialPorts);
1521 brd->dgap_Major_Serial_Registered = FALSE;
1524 if (brd->dgap_Major_TransparentPrint_Registered) {
1525 dgap_BoardsByMajor[brd->PrintDriver->major] = NULL;
1526 brd->dgap_TransparentPrint_Major = 0;
1527 for (i = 0; i < brd->nasync; i++) {
1528 tty_port_destroy(&brd->PrinterPorts[i]);
1529 dev = brd->channels[i]->ch_pun.un_sysfs;
1530 dgap_remove_tty_sysfs(dev);
1531 tty_unregister_device(brd->PrintDriver, i);
1533 tty_unregister_driver(brd->PrintDriver);
1534 kfree(brd->PrintDriver->ttys);
1535 brd->PrintDriver->ttys = NULL;
1536 put_tty_driver(brd->PrintDriver);
1537 kfree(brd->PrinterPorts);
1538 brd->dgap_Major_TransparentPrint_Registered = FALSE;
1542 #define TMPBUFLEN (1024)
1544 * dgap_sniff - Dump data out to the "sniff" buffer if the
1545 * proc sniff file is opened...
1547 static void dgap_sniff_nowait_nolock(struct channel_t *ch, uchar *text,
1548 uchar *buf, int len)
1556 char tmpbuf[TMPBUFLEN];
1560 /* Leave if sniff not open */
1561 if (!(ch->ch_sniff_flags & SNIFF_OPEN))
1564 do_gettimeofday(&tv);
1566 /* Create our header for data dump */
1567 p += sprintf(p, "<%ld %ld><%s><", tv.tv_sec, tv.tv_usec, text);
1568 tmpbuflen = p - tmpbuf;
1573 for (i = 0; i < len && tmpbuflen < (TMPBUFLEN - 4); i++) {
1574 p += sprintf(p, "%02x ", *buf);
1576 tmpbuflen = p - tmpbuf;
1579 if (tmpbuflen < (TMPBUFLEN - 4)) {
1581 p += sprintf(p - 1, "%s\n", ">");
1583 p += sprintf(p, "%s\n", ">");
1589 nbuf = strlen(tmpbuf);
1593 * Loop while data remains.
1595 while (nbuf > 0 && ch->ch_sniff_buf) {
1597 * Determine the amount of available space left in the
1598 * buffer. If there's none, wait until some appears.
1600 n = (ch->ch_sniff_out - ch->ch_sniff_in - 1) &
1604 * If there is no space left to write to in our sniff
1605 * buffer, we have no choice but to drop the data.
1606 * We *cannot* sleep here waiting for space, because
1607 * this function was probably called by the
1608 * interrupt/timer routines!
1614 * Copy as much data as will fit.
1620 r = SNIFF_MAX - ch->ch_sniff_in;
1623 memcpy(ch->ch_sniff_buf +
1624 ch->ch_sniff_in, p, r);
1627 ch->ch_sniff_in = 0;
1632 memcpy(ch->ch_sniff_buf + ch->ch_sniff_in, p, n);
1634 ch->ch_sniff_in += n;
1639 * Wakeup any thread waiting for data
1641 if (ch->ch_sniff_flags & SNIFF_WAIT_DATA) {
1642 ch->ch_sniff_flags &= ~SNIFF_WAIT_DATA;
1643 wake_up_interruptible(&ch->ch_sniff_wait);
1648 * If the user sent us too much data to push into our tmpbuf,
1649 * we need to keep looping around on all the data.
1651 if (too_much_data) {
1656 } while (too_much_data);
1659 /*=======================================================================
1661 * dgap_input - Process received data.
1663 * ch - Pointer to channel structure.
1665 *=======================================================================*/
1667 static void dgap_input(struct channel_t *ch)
1671 struct tty_struct *tp;
1672 struct tty_ldisc *ld;
1686 if (!ch || ch->magic != DGAP_CHANNEL_MAGIC)
1689 tp = ch->ch_tun.un_tty;
1696 if (!bd || bd->magic != DGAP_BOARD_MAGIC)
1699 DGAP_LOCK(bd->bd_lock, lock_flags);
1700 DGAP_LOCK(ch->ch_lock, lock_flags2);
1703 * Figure the number of characters in the buffer.
1704 * Exit immediately if none.
1707 rmask = ch->ch_rsize - 1;
1709 head = readw(&(bs->rx_head));
1711 tail = readw(&(bs->rx_tail));
1714 data_len = (head - tail) & rmask;
1716 if (data_len == 0) {
1717 writeb(1, &(bs->idata));
1718 DGAP_UNLOCK(ch->ch_lock, lock_flags2);
1719 DGAP_UNLOCK(bd->bd_lock, lock_flags);
1724 * If the device is not open, or CREAD is off, flush
1725 * input data and return immediately.
1727 if ((bd->state != BOARD_READY) || !tp ||
1728 (tp->magic != TTY_MAGIC) ||
1729 !(ch->ch_tun.un_flags & UN_ISOPEN) ||
1730 !(tp->termios.c_cflag & CREAD) ||
1731 (ch->ch_tun.un_flags & UN_CLOSING)) {
1733 writew(head, &(bs->rx_tail));
1734 writeb(1, &(bs->idata));
1735 DGAP_UNLOCK(ch->ch_lock, lock_flags2);
1736 DGAP_UNLOCK(bd->bd_lock, lock_flags);
1741 * If we are throttled, simply don't read any data.
1743 if (ch->ch_flags & CH_RXBLOCK) {
1744 writeb(1, &(bs->idata));
1745 DGAP_UNLOCK(ch->ch_lock, lock_flags2);
1746 DGAP_UNLOCK(bd->bd_lock, lock_flags);
1753 tmpchar = readb(&(bs->orun));
1755 ch->ch_err_overrun++;
1756 writeb(0, &(bs->orun));
1759 /* Decide how much data we can send into the tty layer */
1760 flip_len = TTY_FLIPBUF_SIZE;
1762 /* Chop down the length, if needed */
1763 len = min(data_len, flip_len);
1764 len = min(len, (N_TTY_BUF_SIZE - 1));
1766 ld = tty_ldisc_ref(tp);
1768 #ifdef TTY_DONT_FLIP
1770 * If the DONT_FLIP flag is on, don't flush our buffer, and act
1771 * like the ld doesn't have any space to put the data right now.
1773 if (test_bit(TTY_DONT_FLIP, &tp->flags))
1778 * If we were unable to get a reference to the ld,
1779 * don't flush our buffer, and act like the ld doesn't
1780 * have any space to put the data right now.
1786 * If ld doesn't have a pointer to a receive_buf function,
1787 * flush the data, then act like the ld doesn't have any
1788 * space to put the data right now.
1790 if (!ld->ops->receive_buf) {
1791 writew(head, &(bs->rx_tail));
1797 writeb(1, &(bs->idata));
1798 DGAP_UNLOCK(ch->ch_lock, lock_flags2);
1799 DGAP_UNLOCK(bd->bd_lock, lock_flags);
1801 tty_ldisc_deref(ld);
1805 buf = ch->ch_bd->flipbuf;
1809 * n now contains the most amount of data we can copy,
1810 * bounded either by our buffer size or the amount
1811 * of data the card actually has pending...
1815 s = ((head >= tail) ? head : ch->ch_rsize) - tail;
1821 memcpy_fromio(buf, (char *) ch->ch_raddr + tail, s);
1822 dgap_sniff_nowait_nolock(ch, "USER READ", buf, s);
1828 /* Flip queue if needed */
1832 writew(tail, &(bs->rx_tail));
1833 writeb(1, &(bs->idata));
1834 ch->ch_rxcount += len;
1837 * If we are completely raw, we don't need to go through a lot
1838 * of the tty layers that exist.
1839 * In this case, we take the shortest and fastest route we
1840 * can to relay the data to the user.
1842 * On the other hand, if we are not raw, we need to go through
1843 * the tty layer, which has its API more well defined.
1845 if (I_PARMRK(tp) || I_BRKINT(tp) || I_INPCK(tp)) {
1846 dgap_parity_scan(ch, ch->ch_bd->flipbuf,
1847 ch->ch_bd->flipflagbuf, &len);
1849 len = tty_buffer_request_room(tp->port, len);
1850 tty_insert_flip_string_flags(tp->port, ch->ch_bd->flipbuf,
1851 ch->ch_bd->flipflagbuf, len);
1853 len = tty_buffer_request_room(tp->port, len);
1854 tty_insert_flip_string(tp->port, ch->ch_bd->flipbuf, len);
1857 DGAP_UNLOCK(ch->ch_lock, lock_flags2);
1858 DGAP_UNLOCK(bd->bd_lock, lock_flags);
1860 /* Tell the tty layer its okay to "eat" the data now */
1861 tty_flip_buffer_push(tp->port);
1864 tty_ldisc_deref(ld);
1868 /************************************************************************
1869 * Determines when CARRIER changes state and takes appropriate
1871 ************************************************************************/
1872 static void dgap_carrier(struct channel_t *ch)
1876 int virt_carrier = 0;
1877 int phys_carrier = 0;
1879 if (!ch || ch->magic != DGAP_CHANNEL_MAGIC)
1884 if (!bd || bd->magic != DGAP_BOARD_MAGIC)
1887 /* Make sure altpin is always set correctly */
1888 if (ch->ch_digi.digi_flags & DIGI_ALTPIN) {
1892 ch->ch_dsr = DM_DSR;
1896 if (ch->ch_mistat & D_CD(ch))
1899 if (ch->ch_digi.digi_flags & DIGI_FORCEDCD)
1902 if (ch->ch_c_cflag & CLOCAL)
1906 * Test for a VIRTUAL carrier transition to HIGH.
1908 if (((ch->ch_flags & CH_FCAR) == 0) && (virt_carrier == 1)) {
1911 * When carrier rises, wake any threads waiting
1912 * for carrier in the open routine.
1915 if (waitqueue_active(&(ch->ch_flags_wait)))
1916 wake_up_interruptible(&ch->ch_flags_wait);
1920 * Test for a PHYSICAL carrier transition to HIGH.
1922 if (((ch->ch_flags & CH_CD) == 0) && (phys_carrier == 1)) {
1925 * When carrier rises, wake any threads waiting
1926 * for carrier in the open routine.
1929 if (waitqueue_active(&(ch->ch_flags_wait)))
1930 wake_up_interruptible(&ch->ch_flags_wait);
1934 * Test for a PHYSICAL transition to low, so long as we aren't
1935 * currently ignoring physical transitions (which is what "virtual
1936 * carrier" indicates).
1938 * The transition of the virtual carrier to low really doesn't
1939 * matter... it really only means "ignore carrier state", not
1940 * "make pretend that carrier is there".
1942 if ((virt_carrier == 0) &&
1943 ((ch->ch_flags & CH_CD) != 0) &&
1944 (phys_carrier == 0)) {
1947 * When carrier drops:
1949 * Drop carrier on all open units.
1951 * Flush queues, waking up any task waiting in the
1954 * Send a hangup to the control terminal.
1956 * Enable all select calls.
1958 if (waitqueue_active(&(ch->ch_flags_wait)))
1959 wake_up_interruptible(&ch->ch_flags_wait);
1961 if (ch->ch_tun.un_open_count > 0)
1962 tty_hangup(ch->ch_tun.un_tty);
1964 if (ch->ch_pun.un_open_count > 0)
1965 tty_hangup(ch->ch_pun.un_tty);
1969 * Make sure that our cached values reflect the current reality.
1971 if (virt_carrier == 1)
1972 ch->ch_flags |= CH_FCAR;
1974 ch->ch_flags &= ~CH_FCAR;
1976 if (phys_carrier == 1)
1977 ch->ch_flags |= CH_CD;
1979 ch->ch_flags &= ~CH_CD;
1982 /************************************************************************
1984 * TTY Entry points and helper functions
1986 ************************************************************************/
1992 static int dgap_tty_open(struct tty_struct *tty, struct file *file)
1994 struct board_t *brd;
1995 struct channel_t *ch;
2007 major = MAJOR(tty_devnum(tty));
2008 minor = MINOR(tty_devnum(tty));
2013 /* Get board pointer from our array of majors we have allocated */
2014 brd = dgap_BoardsByMajor[major];
2019 * If board is not yet up to a state of READY, go to
2020 * sleep waiting for it to happen or they cancel the open.
2022 rc = wait_event_interruptible(brd->state_wait,
2023 (brd->state & BOARD_READY));
2028 DGAP_LOCK(brd->bd_lock, lock_flags);
2030 /* The wait above should guarantee this cannot happen */
2031 if (brd->state != BOARD_READY) {
2032 DGAP_UNLOCK(brd->bd_lock, lock_flags);
2036 /* If opened device is greater than our number of ports, bail. */
2037 if (MINOR(tty_devnum(tty)) > brd->nasync) {
2038 DGAP_UNLOCK(brd->bd_lock, lock_flags);
2042 ch = brd->channels[minor];
2044 DGAP_UNLOCK(brd->bd_lock, lock_flags);
2048 /* Grab channel lock */
2049 DGAP_LOCK(ch->ch_lock, lock_flags2);
2051 /* Figure out our type */
2052 if (major == brd->dgap_Serial_Major) {
2053 un = &brd->channels[minor]->ch_tun;
2054 un->un_type = DGAP_SERIAL;
2055 } else if (major == brd->dgap_TransparentPrint_Major) {
2056 un = &brd->channels[minor]->ch_pun;
2057 un->un_type = DGAP_PRINT;
2059 DGAP_UNLOCK(ch->ch_lock, lock_flags2);
2060 DGAP_UNLOCK(brd->bd_lock, lock_flags);
2064 /* Store our unit into driver_data, so we always have it available. */
2065 tty->driver_data = un;
2068 * Error if channel info pointer is NULL.
2072 DGAP_UNLOCK(ch->ch_lock, lock_flags2);
2073 DGAP_UNLOCK(brd->bd_lock, lock_flags);
2080 if (!(un->un_flags & UN_ISOPEN)) {
2081 /* Store important variables. */
2084 /* Maybe do something here to the TTY struct as well? */
2088 * Initialize if neither terminal or printer is open.
2090 if (!((ch->ch_tun.un_flags | ch->ch_pun.un_flags) & UN_ISOPEN)) {
2096 * Flush input queue.
2098 head = readw(&(bs->rx_head));
2099 writew(head, &(bs->rx_tail));
2102 ch->pscan_state = 0;
2103 ch->pscan_savechar = 0;
2105 ch->ch_c_cflag = tty->termios.c_cflag;
2106 ch->ch_c_iflag = tty->termios.c_iflag;
2107 ch->ch_c_oflag = tty->termios.c_oflag;
2108 ch->ch_c_lflag = tty->termios.c_lflag;
2109 ch->ch_startc = tty->termios.c_cc[VSTART];
2110 ch->ch_stopc = tty->termios.c_cc[VSTOP];
2112 /* TODO: flush our TTY struct here? */
2117 * Run param in case we changed anything
2122 * follow protocol for opening port
2125 DGAP_UNLOCK(ch->ch_lock, lock_flags2);
2126 DGAP_UNLOCK(brd->bd_lock, lock_flags);
2128 rc = dgap_block_til_ready(tty, file, ch);
2133 /* No going back now, increment our unit and channel counters */
2134 DGAP_LOCK(ch->ch_lock, lock_flags);
2135 ch->ch_open_count++;
2136 un->un_open_count++;
2137 un->un_flags |= (UN_ISOPEN);
2138 DGAP_UNLOCK(ch->ch_lock, lock_flags);
2144 * dgap_block_til_ready()
2146 * Wait for DCD, if needed.
2148 static int dgap_block_til_ready(struct tty_struct *tty, struct file *file,
2149 struct channel_t *ch)
2152 struct un_t *un = NULL;
2155 int sleep_on_un_flags = 0;
2157 if (!tty || tty->magic != TTY_MAGIC || !file || !ch ||
2158 ch->magic != DGAP_CHANNEL_MAGIC)
2161 un = tty->driver_data;
2162 if (!un || un->magic != DGAP_UNIT_MAGIC)
2165 DGAP_LOCK(ch->ch_lock, lock_flags);
2172 sleep_on_un_flags = 0;
2175 * If board has failed somehow during our sleep,
2178 if (ch->ch_bd->state == BOARD_FAILED) {
2183 /* If tty was hung up, break out of loop and set error. */
2184 if (tty_hung_up_p(file)) {
2190 * If either unit is in the middle of the fragile part of close,
2191 * we just cannot touch the channel safely.
2192 * Go back to sleep, knowing that when the channel can be
2193 * touched safely, the close routine will signal the
2194 * ch_wait_flags to wake us back up.
2196 if (!((ch->ch_tun.un_flags | ch->ch_pun.un_flags) &
2200 * Our conditions to leave cleanly and happily:
2201 * 1) NONBLOCKING on the tty is set.
2203 * 3) DCD (fake or real) is active.
2206 if (file->f_flags & O_NONBLOCK)
2209 if (tty->flags & (1 << TTY_IO_ERROR))
2212 if (ch->ch_flags & CH_CD)
2215 if (ch->ch_flags & CH_FCAR)
2218 sleep_on_un_flags = 1;
2222 * If there is a signal pending, the user probably
2223 * interrupted (ctrl-c) us.
2224 * Leave loop with error set.
2226 if (signal_pending(current)) {
2227 retval = -ERESTARTSYS;
2232 * Store the flags before we let go of channel lock
2234 if (sleep_on_un_flags)
2235 old_flags = ch->ch_tun.un_flags | ch->ch_pun.un_flags;
2237 old_flags = ch->ch_flags;
2240 * Let go of channel lock before calling schedule.
2241 * Our poller will get any FEP events and wake us up when DCD
2242 * eventually goes active.
2245 DGAP_UNLOCK(ch->ch_lock, lock_flags);
2248 * Wait for something in the flags to change
2249 * from the current value.
2251 if (sleep_on_un_flags) {
2252 retval = wait_event_interruptible(un->un_flags_wait,
2253 (old_flags != (ch->ch_tun.un_flags |
2254 ch->ch_pun.un_flags)));
2256 retval = wait_event_interruptible(ch->ch_flags_wait,
2257 (old_flags != ch->ch_flags));
2261 * We got woken up for some reason.
2262 * Before looping around, grab our channel lock.
2264 DGAP_LOCK(ch->ch_lock, lock_flags);
2269 DGAP_UNLOCK(ch->ch_lock, lock_flags);
2280 * Hangup the port. Like a close, but don't wait for output to drain.
2282 static void dgap_tty_hangup(struct tty_struct *tty)
2285 struct channel_t *ch;
2288 if (!tty || tty->magic != TTY_MAGIC)
2291 un = tty->driver_data;
2292 if (!un || un->magic != DGAP_UNIT_MAGIC)
2296 if (!ch || ch->magic != DGAP_CHANNEL_MAGIC)
2300 if (!bd || bd->magic != DGAP_BOARD_MAGIC)
2303 /* flush the transmit queues */
2304 dgap_tty_flush_buffer(tty);
2312 static void dgap_tty_close(struct tty_struct *tty, struct file *file)
2314 struct ktermios *ts;
2316 struct channel_t *ch;
2321 if (!tty || tty->magic != TTY_MAGIC)
2324 un = tty->driver_data;
2325 if (!un || un->magic != DGAP_UNIT_MAGIC)
2329 if (!ch || ch->magic != DGAP_CHANNEL_MAGIC)
2333 if (!bd || bd->magic != DGAP_BOARD_MAGIC)
2338 DGAP_LOCK(ch->ch_lock, lock_flags);
2341 * Determine if this is the last close or not - and if we agree about
2342 * which type of close it is with the Line Discipline
2344 if ((tty->count == 1) && (un->un_open_count != 1)) {
2346 * Uh, oh. tty->count is 1, which means that the tty
2347 * structure will be freed. un_open_count should always
2348 * be one in these conditions. If it's greater than
2349 * one, we've got real problems, since it means the
2350 * serial port won't be shutdown.
2352 un->un_open_count = 1;
2355 if (--un->un_open_count < 0)
2356 un->un_open_count = 0;
2358 ch->ch_open_count--;
2360 if (ch->ch_open_count && un->un_open_count) {
2361 DGAP_UNLOCK(ch->ch_lock, lock_flags);
2365 /* OK, its the last close on the unit */
2367 un->un_flags |= UN_CLOSING;
2372 * Only officially close channel if count is 0 and
2373 * DIGI_PRINTER bit is not set.
2375 if ((ch->ch_open_count == 0) &&
2376 !(ch->ch_digi.digi_flags & DIGI_PRINTER)) {
2378 ch->ch_flags &= ~(CH_RXBLOCK);
2380 DGAP_UNLOCK(ch->ch_lock, lock_flags);
2382 /* wait for output to drain */
2383 /* This will also return if we take an interrupt */
2385 rc = dgap_wait_for_drain(tty);
2387 dgap_tty_flush_buffer(tty);
2388 tty_ldisc_flush(tty);
2390 DGAP_LOCK(ch->ch_lock, lock_flags);
2395 * If we have HUPCL set, lower DTR and RTS
2397 if (ch->ch_c_cflag & HUPCL) {
2398 ch->ch_mostat &= ~(D_RTS(ch)|D_DTR(ch));
2399 dgap_cmdb(ch, SMODEM, 0, D_DTR(ch)|D_RTS(ch), 0);
2402 * Go to sleep to ensure RTS/DTR
2403 * have been dropped for modems to see it.
2405 if (ch->ch_close_delay) {
2406 DGAP_UNLOCK(ch->ch_lock, lock_flags);
2407 dgap_ms_sleep(ch->ch_close_delay);
2408 DGAP_LOCK(ch->ch_lock, lock_flags);
2412 ch->pscan_state = 0;
2413 ch->pscan_savechar = 0;
2414 ch->ch_baud_info = 0;
2419 * turn off print device when closing print device.
2421 if ((un->un_type == DGAP_PRINT) && (ch->ch_flags & CH_PRON)) {
2422 dgap_wmove(ch, ch->ch_digi.digi_offstr,
2423 (int) ch->ch_digi.digi_offlen);
2424 ch->ch_flags &= ~CH_PRON;
2428 un->un_flags &= ~(UN_ISOPEN | UN_CLOSING);
2429 tty->driver_data = NULL;
2431 wake_up_interruptible(&ch->ch_flags_wait);
2432 wake_up_interruptible(&un->un_flags_wait);
2434 DGAP_UNLOCK(ch->ch_lock, lock_flags);
2438 * dgap_tty_chars_in_buffer()
2440 * Return number of characters that have not been transmitted yet.
2442 * This routine is used by the line discipline to determine if there
2443 * is data waiting to be transmitted/drained/flushed or not.
2445 static int dgap_tty_chars_in_buffer(struct tty_struct *tty)
2447 struct board_t *bd = NULL;
2448 struct channel_t *ch = NULL;
2449 struct un_t *un = NULL;
2450 struct bs_t *bs = NULL;
2453 u16 thead, ttail, tmask, chead, ctail;
2454 ulong lock_flags = 0;
2455 ulong lock_flags2 = 0;
2460 un = tty->driver_data;
2461 if (!un || un->magic != DGAP_UNIT_MAGIC)
2465 if (!ch || ch->magic != DGAP_CHANNEL_MAGIC)
2469 if (!bd || bd->magic != DGAP_BOARD_MAGIC)
2476 DGAP_LOCK(bd->bd_lock, lock_flags);
2477 DGAP_LOCK(ch->ch_lock, lock_flags2);
2479 tmask = (ch->ch_tsize - 1);
2481 /* Get Transmit queue pointers */
2482 thead = readw(&(bs->tx_head)) & tmask;
2483 ttail = readw(&(bs->tx_tail)) & tmask;
2485 /* Get tbusy flag */
2486 tbusy = readb(&(bs->tbusy));
2488 /* Get Command queue pointers */
2489 chead = readw(&(ch->ch_cm->cm_head));
2490 ctail = readw(&(ch->ch_cm->cm_tail));
2492 DGAP_UNLOCK(ch->ch_lock, lock_flags2);
2493 DGAP_UNLOCK(bd->bd_lock, lock_flags);
2496 * The only way we know for sure if there is no pending
2497 * data left to be transferred, is if:
2498 * 1) Transmit head and tail are equal (empty).
2499 * 2) Command queue head and tail are equal (empty).
2500 * 3) The "TBUSY" flag is 0. (Transmitter not busy).
2503 if ((ttail == thead) && (tbusy == 0) && (chead == ctail)) {
2507 chars = thead - ttail;
2509 chars = thead - ttail + ch->ch_tsize;
2511 * Fudge factor here.
2512 * If chars is zero, we know that the command queue had
2513 * something in it or tbusy was set. Because we cannot
2514 * be sure if there is still some data to be transmitted,
2515 * lets lie, and tell ld we have 1 byte left.
2519 * If TBUSY is still set, and our tx buffers are empty,
2520 * force the firmware to send me another wakeup after
2521 * TBUSY has been cleared.
2524 DGAP_LOCK(ch->ch_lock, lock_flags);
2525 un->un_flags |= UN_EMPTY;
2526 writeb(1, &(bs->iempty));
2527 DGAP_UNLOCK(ch->ch_lock, lock_flags);
2536 static int dgap_wait_for_drain(struct tty_struct *tty)
2538 struct channel_t *ch;
2543 ulong lock_flags = 0;
2545 if (!tty || tty->magic != TTY_MAGIC)
2548 un = tty->driver_data;
2549 if (!un || un->magic != DGAP_UNIT_MAGIC)
2553 if (!ch || ch->magic != DGAP_CHANNEL_MAGIC)
2562 /* Loop until data is drained */
2563 while (count != 0) {
2565 count = dgap_tty_chars_in_buffer(tty);
2570 /* Set flag waiting for drain */
2571 DGAP_LOCK(ch->ch_lock, lock_flags);
2572 un->un_flags |= UN_EMPTY;
2573 writeb(1, &(bs->iempty));
2574 DGAP_UNLOCK(ch->ch_lock, lock_flags);
2576 /* Go to sleep till we get woken up */
2577 ret = wait_event_interruptible(un->un_flags_wait,
2578 ((un->un_flags & UN_EMPTY) == 0));
2579 /* If ret is non-zero, user ctrl-c'ed us */
2584 DGAP_LOCK(ch->ch_lock, lock_flags);
2585 un->un_flags &= ~(UN_EMPTY);
2586 DGAP_UNLOCK(ch->ch_lock, lock_flags);
2594 * Reduces bytes_available to the max number of characters
2595 * that can be sent currently given the maxcps value, and
2596 * returns the new bytes_available. This only affects printer
2599 static int dgap_maxcps_room(struct tty_struct *tty, int bytes_available)
2601 struct channel_t *ch = NULL;
2602 struct un_t *un = NULL;
2605 return bytes_available;
2607 un = tty->driver_data;
2608 if (!un || un->magic != DGAP_UNIT_MAGIC)
2609 return bytes_available;
2612 if (!ch || ch->magic != DGAP_CHANNEL_MAGIC)
2613 return bytes_available;
2616 * If its not the Transparent print device, return
2617 * the full data amount.
2619 if (un->un_type != DGAP_PRINT)
2620 return bytes_available;
2622 if (ch->ch_digi.digi_maxcps > 0 && ch->ch_digi.digi_bufsize > 0) {
2624 unsigned long current_time = jiffies;
2625 unsigned long buffer_time = current_time +
2626 (HZ * ch->ch_digi.digi_bufsize) /
2627 ch->ch_digi.digi_maxcps;
2629 if (ch->ch_cpstime < current_time) {
2630 /* buffer is empty */
2631 ch->ch_cpstime = current_time; /* reset ch_cpstime */
2632 cps_limit = ch->ch_digi.digi_bufsize;
2633 } else if (ch->ch_cpstime < buffer_time) {
2634 /* still room in the buffer */
2635 cps_limit = ((buffer_time - ch->ch_cpstime) *
2636 ch->ch_digi.digi_maxcps) / HZ;
2638 /* no room in the buffer */
2642 bytes_available = min(cps_limit, bytes_available);
2645 return bytes_available;
2648 static inline void dgap_set_firmware_event(struct un_t *un, unsigned int event)
2650 struct channel_t *ch = NULL;
2651 struct bs_t *bs = NULL;
2653 if (!un || un->magic != DGAP_UNIT_MAGIC)
2656 if (!ch || ch->magic != DGAP_CHANNEL_MAGIC)
2662 if ((event & UN_LOW) != 0) {
2663 if ((un->un_flags & UN_LOW) == 0) {
2664 un->un_flags |= UN_LOW;
2665 writeb(1, &(bs->ilow));
2668 if ((event & UN_LOW) != 0) {
2669 if ((un->un_flags & UN_EMPTY) == 0) {
2670 un->un_flags |= UN_EMPTY;
2671 writeb(1, &(bs->iempty));
2677 * dgap_tty_write_room()
2679 * Return space available in Tx buffer
2681 static int dgap_tty_write_room(struct tty_struct *tty)
2683 struct channel_t *ch = NULL;
2684 struct un_t *un = NULL;
2685 struct bs_t *bs = NULL;
2686 u16 head, tail, tmask;
2688 ulong lock_flags = 0;
2693 un = tty->driver_data;
2694 if (!un || un->magic != DGAP_UNIT_MAGIC)
2698 if (!ch || ch->magic != DGAP_CHANNEL_MAGIC)
2705 DGAP_LOCK(ch->ch_lock, lock_flags);
2707 tmask = ch->ch_tsize - 1;
2708 head = readw(&(bs->tx_head)) & tmask;
2709 tail = readw(&(bs->tx_tail)) & tmask;
2711 ret = tail - head - 1;
2713 ret += ch->ch_tsize;
2715 /* Limit printer to maxcps */
2716 ret = dgap_maxcps_room(tty, ret);
2719 * If we are printer device, leave space for
2720 * possibly both the on and off strings.
2722 if (un->un_type == DGAP_PRINT) {
2723 if (!(ch->ch_flags & CH_PRON))
2724 ret -= ch->ch_digi.digi_onlen;
2725 ret -= ch->ch_digi.digi_offlen;
2727 if (ch->ch_flags & CH_PRON)
2728 ret -= ch->ch_digi.digi_offlen;
2735 * Schedule FEP to wake us up if needed.
2737 * TODO: This might be overkill...
2738 * Do we really need to schedule callbacks from the FEP
2739 * in every case? Can we get smarter based on ret?
2741 dgap_set_firmware_event(un, UN_LOW | UN_EMPTY);
2742 DGAP_UNLOCK(ch->ch_lock, lock_flags);
2748 * dgap_tty_put_char()
2750 * Put a character into ch->ch_buf
2752 * - used by the line discipline for OPOST processing
2754 static int dgap_tty_put_char(struct tty_struct *tty, unsigned char c)
2757 * Simply call tty_write.
2759 dgap_tty_write(tty, &c, 1);
2766 * Take data from the user or kernel and send it out to the FEP.
2767 * In here exists all the Transparent Print magic as well.
2769 static int dgap_tty_write(struct tty_struct *tty, const unsigned char *buf,
2772 struct channel_t *ch = NULL;
2773 struct un_t *un = NULL;
2774 struct bs_t *bs = NULL;
2776 u16 head, tail, tmask, remain;
2777 int bufcount = 0, n = 0;
2784 un = tty->driver_data;
2785 if (!un || un->magic != DGAP_UNIT_MAGIC)
2789 if (!ch || ch->magic != DGAP_CHANNEL_MAGIC)
2800 * Store original amount of characters passed in.
2801 * This helps to figure out if we should ask the FEP
2802 * to send us an event when it has more space available.
2806 DGAP_LOCK(ch->ch_lock, lock_flags);
2808 /* Get our space available for the channel from the board */
2809 tmask = ch->ch_tsize - 1;
2810 head = readw(&(bs->tx_head)) & tmask;
2811 tail = readw(&(bs->tx_tail)) & tmask;
2813 bufcount = tail - head - 1;
2815 bufcount += ch->ch_tsize;
2818 * Limit printer output to maxcps overall, with bursts allowed
2819 * up to bufsize characters.
2821 bufcount = dgap_maxcps_room(tty, bufcount);
2824 * Take minimum of what the user wants to send, and the
2825 * space available in the FEP buffer.
2827 count = min(count, bufcount);
2830 * Bail if no space left.
2833 dgap_set_firmware_event(un, UN_LOW | UN_EMPTY);
2834 DGAP_UNLOCK(ch->ch_lock, lock_flags);
2839 * Output the printer ON string, if we are in terminal mode, but
2840 * need to be in printer mode.
2842 if ((un->un_type == DGAP_PRINT) && !(ch->ch_flags & CH_PRON)) {
2843 dgap_wmove(ch, ch->ch_digi.digi_onstr,
2844 (int) ch->ch_digi.digi_onlen);
2845 head = readw(&(bs->tx_head)) & tmask;
2846 ch->ch_flags |= CH_PRON;
2850 * On the other hand, output the printer OFF string, if we are
2851 * currently in printer mode, but need to output to the terminal.
2853 if ((un->un_type != DGAP_PRINT) && (ch->ch_flags & CH_PRON)) {
2854 dgap_wmove(ch, ch->ch_digi.digi_offstr,
2855 (int) ch->ch_digi.digi_offlen);
2856 head = readw(&(bs->tx_head)) & tmask;
2857 ch->ch_flags &= ~CH_PRON;
2861 * If there is nothing left to copy, or
2862 * I can't handle any more data, leave.
2865 dgap_set_firmware_event(un, UN_LOW | UN_EMPTY);
2866 DGAP_UNLOCK(ch->ch_lock, lock_flags);
2873 * If the write wraps over the top of the circular buffer,
2874 * move the portion up to the wrap point, and reset the
2875 * pointers to the bottom.
2877 remain = ch->ch_tstart + ch->ch_tsize - head;
2881 vaddr = ch->ch_taddr + head;
2883 memcpy_toio(vaddr, (uchar *) buf, remain);
2884 dgap_sniff_nowait_nolock(ch, "USER WRITE", (uchar *) buf,
2887 head = ch->ch_tstart;
2894 * Move rest of data.
2896 vaddr = ch->ch_taddr + head;
2899 memcpy_toio(vaddr, (uchar *) buf, remain);
2900 dgap_sniff_nowait_nolock(ch, "USER WRITE", (uchar *)buf,
2908 ch->ch_txcount += count;
2910 writew(head, &(bs->tx_head));
2913 dgap_set_firmware_event(un, UN_LOW | UN_EMPTY);
2916 * If this is the print device, and the
2917 * printer is still on, we need to turn it
2918 * off before going idle. If the buffer is
2919 * non-empty, wait until it goes empty.
2920 * Otherwise turn it off right now.
2922 if ((un->un_type == DGAP_PRINT) && (ch->ch_flags & CH_PRON)) {
2923 tail = readw(&(bs->tx_tail)) & tmask;
2926 un->un_flags |= UN_EMPTY;
2927 writeb(1, &(bs->iempty));
2929 dgap_wmove(ch, ch->ch_digi.digi_offstr,
2930 (int) ch->ch_digi.digi_offlen);
2931 head = readw(&(bs->tx_head)) & tmask;
2932 ch->ch_flags &= ~CH_PRON;
2936 /* Update printer buffer empty time. */
2937 if ((un->un_type == DGAP_PRINT) && (ch->ch_digi.digi_maxcps > 0)
2938 && (ch->ch_digi.digi_bufsize > 0)) {
2939 ch->ch_cpstime += (HZ * count) / ch->ch_digi.digi_maxcps;
2942 DGAP_UNLOCK(ch->ch_lock, lock_flags);
2948 * Return modem signals to ld.
2950 static int dgap_tty_tiocmget(struct tty_struct *tty)
2952 struct channel_t *ch;
2958 if (!tty || tty->magic != TTY_MAGIC)
2961 un = tty->driver_data;
2962 if (!un || un->magic != DGAP_UNIT_MAGIC)
2966 if (!ch || ch->magic != DGAP_CHANNEL_MAGIC)
2969 DGAP_LOCK(ch->ch_lock, lock_flags);
2971 mstat = readb(&(ch->ch_bs->m_stat));
2972 /* Append any outbound signals that might be pending... */
2973 mstat |= ch->ch_mostat;
2975 DGAP_UNLOCK(ch->ch_lock, lock_flags);
2979 if (mstat & D_DTR(ch))
2980 result |= TIOCM_DTR;
2981 if (mstat & D_RTS(ch))
2982 result |= TIOCM_RTS;
2983 if (mstat & D_CTS(ch))
2984 result |= TIOCM_CTS;
2985 if (mstat & D_DSR(ch))
2986 result |= TIOCM_DSR;
2987 if (mstat & D_RI(ch))
2989 if (mstat & D_CD(ch))
2996 * dgap_tty_tiocmset()
2998 * Set modem signals, called by ld.
3000 static int dgap_tty_tiocmset(struct tty_struct *tty,
3001 unsigned int set, unsigned int clear)
3004 struct channel_t *ch;
3010 if (!tty || tty->magic != TTY_MAGIC)
3013 un = tty->driver_data;
3014 if (!un || un->magic != DGAP_UNIT_MAGIC)
3018 if (!ch || ch->magic != DGAP_CHANNEL_MAGIC)
3022 if (!bd || bd->magic != DGAP_BOARD_MAGIC)
3025 DGAP_LOCK(bd->bd_lock, lock_flags);
3026 DGAP_LOCK(ch->ch_lock, lock_flags2);
3028 if (set & TIOCM_RTS) {
3029 ch->ch_mforce |= D_RTS(ch);
3030 ch->ch_mval |= D_RTS(ch);
3033 if (set & TIOCM_DTR) {
3034 ch->ch_mforce |= D_DTR(ch);
3035 ch->ch_mval |= D_DTR(ch);
3038 if (clear & TIOCM_RTS) {
3039 ch->ch_mforce |= D_RTS(ch);
3040 ch->ch_mval &= ~(D_RTS(ch));
3043 if (clear & TIOCM_DTR) {
3044 ch->ch_mforce |= D_DTR(ch);
3045 ch->ch_mval &= ~(D_DTR(ch));
3050 DGAP_UNLOCK(ch->ch_lock, lock_flags2);
3051 DGAP_UNLOCK(bd->bd_lock, lock_flags);
3057 * dgap_tty_send_break()
3059 * Send a Break, called by ld.
3061 static int dgap_tty_send_break(struct tty_struct *tty, int msec)
3064 struct channel_t *ch;
3070 if (!tty || tty->magic != TTY_MAGIC)
3073 un = tty->driver_data;
3074 if (!un || un->magic != DGAP_UNIT_MAGIC)
3078 if (!ch || ch->magic != DGAP_CHANNEL_MAGIC)
3082 if (!bd || bd->magic != DGAP_BOARD_MAGIC)
3097 DGAP_LOCK(bd->bd_lock, lock_flags);
3098 DGAP_LOCK(ch->ch_lock, lock_flags2);
3100 dgap_cmdw(ch, SBREAK, (u16) SBREAK_TIME, 0);
3102 dgap_cmdw(ch, SBREAK, (u16) msec, 0);
3104 DGAP_UNLOCK(ch->ch_lock, lock_flags2);
3105 DGAP_UNLOCK(bd->bd_lock, lock_flags);
3111 * dgap_tty_wait_until_sent()
3113 * wait until data has been transmitted, called by ld.
3115 static void dgap_tty_wait_until_sent(struct tty_struct *tty, int timeout)
3117 dgap_wait_for_drain(tty);
3123 * send a high priority character, called by ld.
3125 static void dgap_tty_send_xchar(struct tty_struct *tty, char c)
3128 struct channel_t *ch;
3133 if (!tty || tty->magic != TTY_MAGIC)
3136 un = tty->driver_data;
3137 if (!un || un->magic != DGAP_UNIT_MAGIC)
3141 if (!ch || ch->magic != DGAP_CHANNEL_MAGIC)
3145 if (!bd || bd->magic != DGAP_BOARD_MAGIC)
3148 DGAP_LOCK(bd->bd_lock, lock_flags);
3149 DGAP_LOCK(ch->ch_lock, lock_flags2);
3152 * This is technically what we should do.
3153 * However, the NIST tests specifically want
3154 * to see each XON or XOFF character that it
3155 * sends, so lets just send each character
3159 if (c == STOP_CHAR(tty))
3160 dgap_cmdw(ch, RPAUSE, 0, 0);
3161 else if (c == START_CHAR(tty))
3162 dgap_cmdw(ch, RRESUME, 0, 0);
3164 dgap_wmove(ch, &c, 1);
3166 dgap_wmove(ch, &c, 1);
3169 DGAP_UNLOCK(ch->ch_lock, lock_flags2);
3170 DGAP_UNLOCK(bd->bd_lock, lock_flags);
3176 * Return modem signals to ld.
3178 static int dgap_get_modem_info(struct channel_t *ch, unsigned int __user *value)
3185 if (!ch || ch->magic != DGAP_CHANNEL_MAGIC)
3188 DGAP_LOCK(ch->ch_lock, lock_flags);
3190 mstat = readb(&(ch->ch_bs->m_stat));
3191 /* Append any outbound signals that might be pending... */
3192 mstat |= ch->ch_mostat;
3194 DGAP_UNLOCK(ch->ch_lock, lock_flags);
3198 if (mstat & D_DTR(ch))
3199 result |= TIOCM_DTR;
3200 if (mstat & D_RTS(ch))
3201 result |= TIOCM_RTS;
3202 if (mstat & D_CTS(ch))
3203 result |= TIOCM_CTS;
3204 if (mstat & D_DSR(ch))
3205 result |= TIOCM_DSR;
3206 if (mstat & D_RI(ch))
3208 if (mstat & D_CD(ch))
3211 rc = put_user(result, value);
3217 * dgap_set_modem_info()
3219 * Set modem signals, called by ld.
3221 static int dgap_set_modem_info(struct tty_struct *tty, unsigned int command,
3222 unsigned int __user *value)
3225 struct channel_t *ch;
3228 unsigned int arg = 0;
3232 if (!tty || tty->magic != TTY_MAGIC)
3235 un = tty->driver_data;
3236 if (!un || un->magic != DGAP_UNIT_MAGIC)
3240 if (!ch || ch->magic != DGAP_CHANNEL_MAGIC)
3244 if (!bd || bd->magic != DGAP_BOARD_MAGIC)
3247 ret = get_user(arg, value);
3253 if (arg & TIOCM_RTS) {
3254 ch->ch_mforce |= D_RTS(ch);
3255 ch->ch_mval |= D_RTS(ch);
3258 if (arg & TIOCM_DTR) {
3259 ch->ch_mforce |= D_DTR(ch);
3260 ch->ch_mval |= D_DTR(ch);
3266 if (arg & TIOCM_RTS) {
3267 ch->ch_mforce |= D_RTS(ch);
3268 ch->ch_mval &= ~(D_RTS(ch));
3271 if (arg & TIOCM_DTR) {
3272 ch->ch_mforce |= D_DTR(ch);
3273 ch->ch_mval &= ~(D_DTR(ch));
3279 ch->ch_mforce = D_DTR(ch)|D_RTS(ch);
3281 if (arg & TIOCM_RTS)
3282 ch->ch_mval |= D_RTS(ch);
3284 ch->ch_mval &= ~(D_RTS(ch));
3286 if (arg & TIOCM_DTR)
3287 ch->ch_mval |= (D_DTR(ch));
3289 ch->ch_mval &= ~(D_DTR(ch));
3297 DGAP_LOCK(bd->bd_lock, lock_flags);
3298 DGAP_LOCK(ch->ch_lock, lock_flags2);
3302 DGAP_UNLOCK(ch->ch_lock, lock_flags2);
3303 DGAP_UNLOCK(bd->bd_lock, lock_flags);
3309 * dgap_tty_digigeta()
3311 * Ioctl to get the information for ditty.
3316 static int dgap_tty_digigeta(struct tty_struct *tty,
3317 struct digi_t __user *retinfo)
3319 struct channel_t *ch;
3327 if (!tty || tty->magic != TTY_MAGIC)
3330 un = tty->driver_data;
3331 if (!un || un->magic != DGAP_UNIT_MAGIC)
3335 if (!ch || ch->magic != DGAP_CHANNEL_MAGIC)
3338 memset(&tmp, 0, sizeof(tmp));
3340 DGAP_LOCK(ch->ch_lock, lock_flags);
3341 memcpy(&tmp, &ch->ch_digi, sizeof(tmp));
3342 DGAP_UNLOCK(ch->ch_lock, lock_flags);
3344 if (copy_to_user(retinfo, &tmp, sizeof(*retinfo)))
3351 * dgap_tty_digiseta()
3353 * Ioctl to set the information for ditty.
3358 static int dgap_tty_digiseta(struct tty_struct *tty,
3359 struct digi_t __user *new_info)
3362 struct channel_t *ch;
3364 struct digi_t new_digi;
3365 ulong lock_flags = 0;
3366 unsigned long lock_flags2;
3368 if (!tty || tty->magic != TTY_MAGIC)
3371 un = tty->driver_data;
3372 if (!un || un->magic != DGAP_UNIT_MAGIC)
3376 if (!ch || ch->magic != DGAP_CHANNEL_MAGIC)
3380 if (!bd || bd->magic != DGAP_BOARD_MAGIC)
3383 if (copy_from_user(&new_digi, new_info, sizeof(struct digi_t)))
3386 DGAP_LOCK(bd->bd_lock, lock_flags);
3387 DGAP_LOCK(ch->ch_lock, lock_flags2);
3389 memcpy(&ch->ch_digi, &new_digi, sizeof(struct digi_t));
3391 if (ch->ch_digi.digi_maxcps < 1)
3392 ch->ch_digi.digi_maxcps = 1;
3394 if (ch->ch_digi.digi_maxcps > 10000)
3395 ch->ch_digi.digi_maxcps = 10000;
3397 if (ch->ch_digi.digi_bufsize < 10)
3398 ch->ch_digi.digi_bufsize = 10;
3400 if (ch->ch_digi.digi_maxchar < 1)
3401 ch->ch_digi.digi_maxchar = 1;
3403 if (ch->ch_digi.digi_maxchar > ch->ch_digi.digi_bufsize)
3404 ch->ch_digi.digi_maxchar = ch->ch_digi.digi_bufsize;
3406 if (ch->ch_digi.digi_onlen > DIGI_PLEN)
3407 ch->ch_digi.digi_onlen = DIGI_PLEN;
3409 if (ch->ch_digi.digi_offlen > DIGI_PLEN)
3410 ch->ch_digi.digi_offlen = DIGI_PLEN;
3414 DGAP_UNLOCK(ch->ch_lock, lock_flags2);
3415 DGAP_UNLOCK(bd->bd_lock, lock_flags);
3421 * dgap_tty_digigetedelay()
3423 * Ioctl to get the current edelay setting.
3428 static int dgap_tty_digigetedelay(struct tty_struct *tty, int __user *retinfo)
3430 struct channel_t *ch;
3438 if (!tty || tty->magic != TTY_MAGIC)
3441 un = tty->driver_data;
3442 if (!un || un->magic != DGAP_UNIT_MAGIC)
3446 if (!ch || ch->magic != DGAP_CHANNEL_MAGIC)
3449 memset(&tmp, 0, sizeof(tmp));
3451 DGAP_LOCK(ch->ch_lock, lock_flags);
3452 tmp = readw(&(ch->ch_bs->edelay));
3453 DGAP_UNLOCK(ch->ch_lock, lock_flags);
3455 if (copy_to_user(retinfo, &tmp, sizeof(*retinfo)))
3462 * dgap_tty_digisetedelay()
3464 * Ioctl to set the EDELAY setting
3467 static int dgap_tty_digisetedelay(struct tty_struct *tty, int __user *new_info)
3470 struct channel_t *ch;
3476 if (!tty || tty->magic != TTY_MAGIC)
3479 un = tty->driver_data;
3480 if (!un || un->magic != DGAP_UNIT_MAGIC)
3484 if (!ch || ch->magic != DGAP_CHANNEL_MAGIC)
3488 if (!bd || bd->magic != DGAP_BOARD_MAGIC)
3491 if (copy_from_user(&new_digi, new_info, sizeof(int)))
3494 DGAP_LOCK(bd->bd_lock, lock_flags);
3495 DGAP_LOCK(ch->ch_lock, lock_flags2);
3497 writew((u16) new_digi, &(ch->ch_bs->edelay));
3501 DGAP_UNLOCK(ch->ch_lock, lock_flags2);
3502 DGAP_UNLOCK(bd->bd_lock, lock_flags);
3508 * dgap_tty_digigetcustombaud()
3510 * Ioctl to get the current custom baud rate setting.
3512 static int dgap_tty_digigetcustombaud(struct tty_struct *tty,
3513 int __user *retinfo)
3515 struct channel_t *ch;
3523 if (!tty || tty->magic != TTY_MAGIC)
3526 un = tty->driver_data;
3527 if (!un || un->magic != DGAP_UNIT_MAGIC)
3531 if (!ch || ch->magic != DGAP_CHANNEL_MAGIC)
3534 memset(&tmp, 0, sizeof(tmp));
3536 DGAP_LOCK(ch->ch_lock, lock_flags);
3537 tmp = dgap_get_custom_baud(ch);
3538 DGAP_UNLOCK(ch->ch_lock, lock_flags);
3540 if (copy_to_user(retinfo, &tmp, sizeof(*retinfo)))
3547 * dgap_tty_digisetcustombaud()
3549 * Ioctl to set the custom baud rate setting
3551 static int dgap_tty_digisetcustombaud(struct tty_struct *tty,
3552 int __user *new_info)
3555 struct channel_t *ch;
3561 if (!tty || tty->magic != TTY_MAGIC)
3564 un = tty->driver_data;
3565 if (!un || un->magic != DGAP_UNIT_MAGIC)
3569 if (!ch || ch->magic != DGAP_CHANNEL_MAGIC)
3573 if (!bd || bd->magic != DGAP_BOARD_MAGIC)
3577 if (copy_from_user(&new_rate, new_info, sizeof(unsigned int)))
3580 if (bd->bd_flags & BD_FEP5PLUS) {
3582 DGAP_LOCK(bd->bd_lock, lock_flags);
3583 DGAP_LOCK(ch->ch_lock, lock_flags2);
3585 ch->ch_custom_speed = new_rate;
3589 DGAP_UNLOCK(ch->ch_lock, lock_flags2);
3590 DGAP_UNLOCK(bd->bd_lock, lock_flags);
3597 * dgap_set_termios()
3599 static void dgap_tty_set_termios(struct tty_struct *tty,
3600 struct ktermios *old_termios)
3603 struct channel_t *ch;
3605 unsigned long lock_flags;
3606 unsigned long lock_flags2;
3608 if (!tty || tty->magic != TTY_MAGIC)
3611 un = tty->driver_data;
3612 if (!un || un->magic != DGAP_UNIT_MAGIC)
3616 if (!ch || ch->magic != DGAP_CHANNEL_MAGIC)
3620 if (!bd || bd->magic != DGAP_BOARD_MAGIC)
3623 DGAP_LOCK(bd->bd_lock, lock_flags);
3624 DGAP_LOCK(ch->ch_lock, lock_flags2);
3626 ch->ch_c_cflag = tty->termios.c_cflag;
3627 ch->ch_c_iflag = tty->termios.c_iflag;
3628 ch->ch_c_oflag = tty->termios.c_oflag;
3629 ch->ch_c_lflag = tty->termios.c_lflag;
3630 ch->ch_startc = tty->termios.c_cc[VSTART];
3631 ch->ch_stopc = tty->termios.c_cc[VSTOP];
3636 DGAP_UNLOCK(ch->ch_lock, lock_flags2);
3637 DGAP_UNLOCK(bd->bd_lock, lock_flags);
3640 static void dgap_tty_throttle(struct tty_struct *tty)
3643 struct channel_t *ch;
3648 if (!tty || tty->magic != TTY_MAGIC)
3651 un = tty->driver_data;
3652 if (!un || un->magic != DGAP_UNIT_MAGIC)
3656 if (!ch || ch->magic != DGAP_CHANNEL_MAGIC)
3660 if (!bd || bd->magic != DGAP_BOARD_MAGIC)
3663 DGAP_LOCK(bd->bd_lock, lock_flags);
3664 DGAP_LOCK(ch->ch_lock, lock_flags2);
3666 ch->ch_flags |= (CH_RXBLOCK);
3668 dgap_cmdw(ch, RPAUSE, 0, 0);
3671 DGAP_UNLOCK(ch->ch_lock, lock_flags2);
3672 DGAP_UNLOCK(bd->bd_lock, lock_flags);
3676 static void dgap_tty_unthrottle(struct tty_struct *tty)
3679 struct channel_t *ch;
3684 if (!tty || tty->magic != TTY_MAGIC)
3687 un = tty->driver_data;
3688 if (!un || un->magic != DGAP_UNIT_MAGIC)
3692 if (!ch || ch->magic != DGAP_CHANNEL_MAGIC)
3696 if (!bd || bd->magic != DGAP_BOARD_MAGIC)
3699 DGAP_LOCK(bd->bd_lock, lock_flags);
3700 DGAP_LOCK(ch->ch_lock, lock_flags2);
3702 ch->ch_flags &= ~(CH_RXBLOCK);
3705 dgap_cmdw(ch, RRESUME, 0, 0);
3708 DGAP_UNLOCK(ch->ch_lock, lock_flags2);
3709 DGAP_UNLOCK(bd->bd_lock, lock_flags);
3712 static void dgap_tty_start(struct tty_struct *tty)
3715 struct channel_t *ch;
3720 if (!tty || tty->magic != TTY_MAGIC)
3723 un = tty->driver_data;
3724 if (!un || un->magic != DGAP_UNIT_MAGIC)
3728 if (!ch || ch->magic != DGAP_CHANNEL_MAGIC)
3732 if (!bd || bd->magic != DGAP_BOARD_MAGIC)
3735 DGAP_LOCK(bd->bd_lock, lock_flags);
3736 DGAP_LOCK(ch->ch_lock, lock_flags2);
3738 dgap_cmdw(ch, RESUMETX, 0, 0);
3740 DGAP_UNLOCK(ch->ch_lock, lock_flags2);
3741 DGAP_UNLOCK(bd->bd_lock, lock_flags);
3745 static void dgap_tty_stop(struct tty_struct *tty)
3748 struct channel_t *ch;
3753 if (!tty || tty->magic != TTY_MAGIC)
3756 un = tty->driver_data;
3757 if (!un || un->magic != DGAP_UNIT_MAGIC)
3761 if (!ch || ch->magic != DGAP_CHANNEL_MAGIC)
3765 if (!bd || bd->magic != DGAP_BOARD_MAGIC)
3768 DGAP_LOCK(bd->bd_lock, lock_flags);
3769 DGAP_LOCK(ch->ch_lock, lock_flags2);
3771 dgap_cmdw(ch, PAUSETX, 0, 0);
3773 DGAP_UNLOCK(ch->ch_lock, lock_flags2);
3774 DGAP_UNLOCK(bd->bd_lock, lock_flags);
3779 * dgap_tty_flush_chars()
3781 * Flush the cook buffer
3783 * Note to self, and any other poor souls who venture here:
3785 * flush in this case DOES NOT mean dispose of the data.
3786 * instead, it means "stop buffering and send it if you
3787 * haven't already." Just guess how I figured that out... SRW 2-Jun-98
3789 * It is also always called in interrupt context - JAR 8-Sept-99
3791 static void dgap_tty_flush_chars(struct tty_struct *tty)
3794 struct channel_t *ch;
3799 if (!tty || tty->magic != TTY_MAGIC)
3802 un = tty->driver_data;
3803 if (!un || un->magic != DGAP_UNIT_MAGIC)
3807 if (!ch || ch->magic != DGAP_CHANNEL_MAGIC)
3811 if (!bd || bd->magic != DGAP_BOARD_MAGIC)
3814 DGAP_LOCK(bd->bd_lock, lock_flags);
3815 DGAP_LOCK(ch->ch_lock, lock_flags2);
3817 /* TODO: Do something here */
3819 DGAP_UNLOCK(ch->ch_lock, lock_flags2);
3820 DGAP_UNLOCK(bd->bd_lock, lock_flags);
3824 * dgap_tty_flush_buffer()
3826 * Flush Tx buffer (make in == out)
3828 static void dgap_tty_flush_buffer(struct tty_struct *tty)
3831 struct channel_t *ch;
3837 if (!tty || tty->magic != TTY_MAGIC)
3840 un = tty->driver_data;
3841 if (!un || un->magic != DGAP_UNIT_MAGIC)
3845 if (!ch || ch->magic != DGAP_CHANNEL_MAGIC)
3849 if (!bd || bd->magic != DGAP_BOARD_MAGIC)
3852 DGAP_LOCK(bd->bd_lock, lock_flags);
3853 DGAP_LOCK(ch->ch_lock, lock_flags2);
3855 ch->ch_flags &= ~CH_STOP;
3856 head = readw(&(ch->ch_bs->tx_head));
3857 dgap_cmdw(ch, FLUSHTX, (u16) head, 0);
3858 dgap_cmdw(ch, RESUMETX, 0, 0);
3859 if (ch->ch_tun.un_flags & (UN_LOW|UN_EMPTY)) {
3860 ch->ch_tun.un_flags &= ~(UN_LOW|UN_EMPTY);
3861 wake_up_interruptible(&ch->ch_tun.un_flags_wait);
3863 if (ch->ch_pun.un_flags & (UN_LOW|UN_EMPTY)) {
3864 ch->ch_pun.un_flags &= ~(UN_LOW|UN_EMPTY);
3865 wake_up_interruptible(&ch->ch_pun.un_flags_wait);
3868 DGAP_UNLOCK(ch->ch_lock, lock_flags2);
3869 DGAP_UNLOCK(bd->bd_lock, lock_flags);
3870 if (waitqueue_active(&tty->write_wait))
3871 wake_up_interruptible(&tty->write_wait);
3875 /*****************************************************************************
3877 * The IOCTL function and all of its helpers
3879 *****************************************************************************/
3884 * The usual assortment of ioctl's
3886 static int dgap_tty_ioctl(struct tty_struct *tty, unsigned int cmd,
3890 struct channel_t *ch;
3894 ulong lock_flags = 0;
3895 ulong lock_flags2 = 0;
3896 void __user *uarg = (void __user *) arg;
3898 if (!tty || tty->magic != TTY_MAGIC)
3901 un = tty->driver_data;
3902 if (!un || un->magic != DGAP_UNIT_MAGIC)
3906 if (!ch || ch->magic != DGAP_CHANNEL_MAGIC)
3910 if (!bd || bd->magic != DGAP_BOARD_MAGIC)
3913 DGAP_LOCK(bd->bd_lock, lock_flags);
3914 DGAP_LOCK(ch->ch_lock, lock_flags2);
3916 if (un->un_open_count <= 0) {
3917 DGAP_UNLOCK(ch->ch_lock, lock_flags2);
3918 DGAP_UNLOCK(bd->bd_lock, lock_flags);
3924 /* Here are all the standard ioctl's that we MUST implement */
3928 * TCSBRK is SVID version: non-zero arg --> no break
3929 * this behaviour is exploited by tcdrain().
3931 * According to POSIX.1 spec (7.2.2.1.2) breaks should be
3932 * between 0.25 and 0.5 seconds so we'll ask for something
3933 * in the middle: 0.375 seconds.
3935 rc = tty_check_change(tty);
3936 DGAP_UNLOCK(ch->ch_lock, lock_flags2);
3937 DGAP_UNLOCK(bd->bd_lock, lock_flags);
3941 rc = dgap_wait_for_drain(tty);
3946 DGAP_LOCK(bd->bd_lock, lock_flags);
3947 DGAP_LOCK(ch->ch_lock, lock_flags2);
3949 if (((cmd == TCSBRK) && (!arg)) || (cmd == TCSBRKP))
3950 dgap_cmdw(ch, SBREAK, (u16) SBREAK_TIME, 0);
3952 DGAP_UNLOCK(ch->ch_lock, lock_flags2);
3953 DGAP_UNLOCK(bd->bd_lock, lock_flags);
3958 /* support for POSIX tcsendbreak()
3960 * According to POSIX.1 spec (7.2.2.1.2) breaks should be
3961 * between 0.25 and 0.5 seconds so we'll ask for something
3962 * in the middle: 0.375 seconds.
3964 rc = tty_check_change(tty);
3965 DGAP_UNLOCK(ch->ch_lock, lock_flags2);
3966 DGAP_UNLOCK(bd->bd_lock, lock_flags);
3970 rc = dgap_wait_for_drain(tty);
3974 DGAP_LOCK(bd->bd_lock, lock_flags);
3975 DGAP_LOCK(ch->ch_lock, lock_flags2);
3977 dgap_cmdw(ch, SBREAK, (u16) SBREAK_TIME, 0);
3979 DGAP_UNLOCK(ch->ch_lock, lock_flags2);
3980 DGAP_UNLOCK(bd->bd_lock, lock_flags);
3986 * FEP5 doesn't support turning on a break unconditionally.
3987 * The FEP5 device will stop sending a break automatically
3988 * after the specified time value that was sent when turning on
3991 rc = tty_check_change(tty);
3992 DGAP_UNLOCK(ch->ch_lock, lock_flags2);
3993 DGAP_UNLOCK(bd->bd_lock, lock_flags);
3997 rc = dgap_wait_for_drain(tty);
4001 DGAP_LOCK(bd->bd_lock, lock_flags);
4002 DGAP_LOCK(ch->ch_lock, lock_flags2);
4004 dgap_cmdw(ch, SBREAK, (u16) SBREAK_TIME, 0);
4006 DGAP_UNLOCK(ch->ch_lock, lock_flags2);
4007 DGAP_UNLOCK(bd->bd_lock, lock_flags);
4013 * FEP5 doesn't support turning off a break unconditionally.
4014 * The FEP5 device will stop sending a break automatically
4015 * after the specified time value that was sent when turning on
4018 DGAP_UNLOCK(ch->ch_lock, lock_flags2);
4019 DGAP_UNLOCK(bd->bd_lock, lock_flags);
4024 DGAP_UNLOCK(ch->ch_lock, lock_flags2);
4025 DGAP_UNLOCK(bd->bd_lock, lock_flags);
4027 rc = put_user(C_CLOCAL(tty) ? 1 : 0,
4028 (unsigned long __user *) arg);
4032 DGAP_UNLOCK(ch->ch_lock, lock_flags2);
4033 DGAP_UNLOCK(bd->bd_lock, lock_flags);
4035 rc = get_user(arg, (unsigned long __user *) arg);
4039 DGAP_LOCK(bd->bd_lock, lock_flags);
4040 DGAP_LOCK(ch->ch_lock, lock_flags2);
4041 tty->termios.c_cflag = ((tty->termios.c_cflag & ~CLOCAL) |
4042 (arg ? CLOCAL : 0));
4044 DGAP_UNLOCK(ch->ch_lock, lock_flags2);
4045 DGAP_UNLOCK(bd->bd_lock, lock_flags);
4050 DGAP_UNLOCK(ch->ch_lock, lock_flags2);
4051 DGAP_UNLOCK(bd->bd_lock, lock_flags);
4052 return dgap_get_modem_info(ch, uarg);
4057 DGAP_UNLOCK(ch->ch_lock, lock_flags2);
4058 DGAP_UNLOCK(bd->bd_lock, lock_flags);
4059 return dgap_set_modem_info(tty, cmd, uarg);
4062 * Here are any additional ioctl's that we want to implement
4067 * The linux tty driver doesn't have a flush
4068 * input routine for the driver, assuming all backed
4069 * up data is in the line disc. buffers. However,
4070 * we all know that's not the case. Here, we
4071 * act on the ioctl, but then lie and say we didn't
4072 * so the line discipline will process the flush
4075 rc = tty_check_change(tty);
4077 DGAP_UNLOCK(ch->ch_lock, lock_flags2);
4078 DGAP_UNLOCK(bd->bd_lock, lock_flags);
4082 if ((arg == TCIFLUSH) || (arg == TCIOFLUSH)) {
4083 if (!(un->un_type == DGAP_PRINT)) {
4084 head = readw(&(ch->ch_bs->rx_head));
4085 writew(head, &(ch->ch_bs->rx_tail));
4086 writeb(0, &(ch->ch_bs->orun));
4090 if ((arg != TCOFLUSH) && (arg != TCIOFLUSH)) {
4091 /* pretend we didn't recognize this IOCTL */
4092 DGAP_UNLOCK(ch->ch_lock, lock_flags2);
4093 DGAP_UNLOCK(bd->bd_lock, lock_flags);
4095 return -ENOIOCTLCMD;
4098 ch->ch_flags &= ~CH_STOP;
4099 head = readw(&(ch->ch_bs->tx_head));
4100 dgap_cmdw(ch, FLUSHTX, (u16) head, 0);
4101 dgap_cmdw(ch, RESUMETX, 0, 0);
4102 if (ch->ch_tun.un_flags & (UN_LOW|UN_EMPTY)) {
4103 ch->ch_tun.un_flags &= ~(UN_LOW|UN_EMPTY);
4104 wake_up_interruptible(&ch->ch_tun.un_flags_wait);
4106 if (ch->ch_pun.un_flags & (UN_LOW|UN_EMPTY)) {
4107 ch->ch_pun.un_flags &= ~(UN_LOW|UN_EMPTY);
4108 wake_up_interruptible(&ch->ch_pun.un_flags_wait);
4110 if (waitqueue_active(&tty->write_wait))
4111 wake_up_interruptible(&tty->write_wait);
4113 /* Can't hold any locks when calling tty_wakeup! */
4114 DGAP_UNLOCK(ch->ch_lock, lock_flags2);
4115 DGAP_UNLOCK(bd->bd_lock, lock_flags);
4118 /* pretend we didn't recognize this IOCTL */
4119 return -ENOIOCTLCMD;
4124 * The linux tty driver doesn't have a flush
4125 * input routine for the driver, assuming all backed
4126 * up data is in the line disc. buffers. However,
4127 * we all know that's not the case. Here, we
4128 * act on the ioctl, but then lie and say we didn't
4129 * so the line discipline will process the flush
4132 if (cmd == TCSETSF) {
4134 ch->ch_flags &= ~CH_STOP;
4135 head = readw(&(ch->ch_bs->rx_head));
4136 writew(head, &(ch->ch_bs->rx_tail));
4139 /* now wait for all the output to drain */
4140 DGAP_UNLOCK(ch->ch_lock, lock_flags2);
4141 DGAP_UNLOCK(bd->bd_lock, lock_flags);
4142 rc = dgap_wait_for_drain(tty);
4146 /* pretend we didn't recognize this */
4147 return -ENOIOCTLCMD;
4151 DGAP_UNLOCK(ch->ch_lock, lock_flags2);
4152 DGAP_UNLOCK(bd->bd_lock, lock_flags);
4153 rc = dgap_wait_for_drain(tty);
4157 /* pretend we didn't recognize this */
4158 return -ENOIOCTLCMD;
4162 * The Linux Line Discipline (LD) would do this for us if we
4163 * let it, but we have the special firmware options to do this
4164 * the "right way" regardless of hardware or software flow
4165 * control so we'll do it outselves instead of letting the LD
4168 rc = tty_check_change(tty);
4170 DGAP_UNLOCK(ch->ch_lock, lock_flags2);
4171 DGAP_UNLOCK(bd->bd_lock, lock_flags);
4178 DGAP_UNLOCK(ch->ch_lock, lock_flags2);
4179 DGAP_UNLOCK(bd->bd_lock, lock_flags);
4180 dgap_tty_start(tty);
4183 DGAP_UNLOCK(ch->ch_lock, lock_flags2);
4184 DGAP_UNLOCK(bd->bd_lock, lock_flags);
4188 DGAP_UNLOCK(ch->ch_lock, lock_flags2);
4189 DGAP_UNLOCK(bd->bd_lock, lock_flags);
4190 /* Make the ld do it */
4191 return -ENOIOCTLCMD;
4193 DGAP_UNLOCK(ch->ch_lock, lock_flags2);
4194 DGAP_UNLOCK(bd->bd_lock, lock_flags);
4195 /* Make the ld do it */
4196 return -ENOIOCTLCMD;
4198 DGAP_UNLOCK(ch->ch_lock, lock_flags2);
4199 DGAP_UNLOCK(bd->bd_lock, lock_flags);
4204 /* get information for ditty */
4205 DGAP_UNLOCK(ch->ch_lock, lock_flags2);
4206 DGAP_UNLOCK(bd->bd_lock, lock_flags);
4207 return dgap_tty_digigeta(tty, uarg);
4212 /* set information for ditty */
4213 if (cmd == (DIGI_SETAW)) {
4215 DGAP_UNLOCK(ch->ch_lock, lock_flags2);
4216 DGAP_UNLOCK(bd->bd_lock, lock_flags);
4217 rc = dgap_wait_for_drain(tty);
4220 DGAP_LOCK(bd->bd_lock, lock_flags);
4221 DGAP_LOCK(ch->ch_lock, lock_flags2);
4223 tty_ldisc_flush(tty);
4227 DGAP_UNLOCK(ch->ch_lock, lock_flags2);
4228 DGAP_UNLOCK(bd->bd_lock, lock_flags);
4229 return dgap_tty_digiseta(tty, uarg);
4232 DGAP_UNLOCK(ch->ch_lock, lock_flags2);
4233 DGAP_UNLOCK(bd->bd_lock, lock_flags);
4234 return dgap_tty_digigetedelay(tty, uarg);
4237 DGAP_UNLOCK(ch->ch_lock, lock_flags2);
4238 DGAP_UNLOCK(bd->bd_lock, lock_flags);
4239 return dgap_tty_digisetedelay(tty, uarg);
4241 case DIGI_GETCUSTOMBAUD:
4242 DGAP_UNLOCK(ch->ch_lock, lock_flags2);
4243 DGAP_UNLOCK(bd->bd_lock, lock_flags);
4244 return dgap_tty_digigetcustombaud(tty, uarg);
4246 case DIGI_SETCUSTOMBAUD:
4247 DGAP_UNLOCK(ch->ch_lock, lock_flags2);
4248 DGAP_UNLOCK(bd->bd_lock, lock_flags);
4249 return dgap_tty_digisetcustombaud(tty, uarg);
4251 case DIGI_RESET_PORT:
4252 dgap_firmware_reset_port(ch);
4254 DGAP_UNLOCK(ch->ch_lock, lock_flags2);
4255 DGAP_UNLOCK(bd->bd_lock, lock_flags);
4259 DGAP_UNLOCK(ch->ch_lock, lock_flags2);
4260 DGAP_UNLOCK(bd->bd_lock, lock_flags);
4262 return -ENOIOCTLCMD;
4266 static int dgap_after_config_loaded(int board)
4269 * Initialize KME waitqueues...
4271 init_waitqueue_head(&(dgap_Board[board]->kme_wait));
4274 * allocate flip buffer for board.
4276 dgap_Board[board]->flipbuf = kmalloc(MYFLIPLEN, GFP_ATOMIC);
4277 if (!dgap_Board[board]->flipbuf)
4280 dgap_Board[board]->flipflagbuf = kmalloc(MYFLIPLEN, GFP_ATOMIC);
4281 if (!dgap_Board[board]->flipflagbuf) {
4282 kfree(dgap_Board[board]->flipbuf);
4290 * Create pr and tty device entries
4292 static int dgap_tty_register_ports(struct board_t *brd)
4294 struct channel_t *ch;
4297 brd->SerialPorts = kcalloc(brd->nasync, sizeof(*brd->SerialPorts),
4299 if (brd->SerialPorts == NULL)
4301 for (i = 0; i < brd->nasync; i++)
4302 tty_port_init(&brd->SerialPorts[i]);
4304 brd->PrinterPorts = kcalloc(brd->nasync, sizeof(*brd->PrinterPorts),
4306 if (brd->PrinterPorts == NULL) {
4307 kfree(brd->SerialPorts);
4310 for (i = 0; i < brd->nasync; i++)
4311 tty_port_init(&brd->PrinterPorts[i]);
4313 ch = brd->channels[0];
4314 for (i = 0; i < brd->nasync; i++, ch = brd->channels[i]) {
4316 struct device *classp;
4318 classp = tty_port_register_device(&brd->SerialPorts[i],
4320 brd->firstminor + i, NULL);
4322 dgap_create_tty_sysfs(&ch->ch_tun, classp);
4323 ch->ch_tun.un_sysfs = classp;
4325 classp = tty_port_register_device(&brd->PrinterPorts[i],
4327 brd->firstminor + i, NULL);
4329 dgap_create_tty_sysfs(&ch->ch_pun, classp);
4330 ch->ch_pun.un_sysfs = classp;
4332 dgap_create_ports_sysfiles(brd);
4338 * Copies the BIOS code from the user to the board,
4339 * and starts the BIOS running.
4341 static void dgap_do_bios_load(struct board_t *brd, uchar __user *ubios, int len)
4347 if (!brd || (brd->magic != DGAP_BOARD_MAGIC) || !brd->re_map_membase)
4350 addr = brd->re_map_membase;
4355 for (i = 0; i < 16; i++)
4356 writeb(0, addr + POSTAREA + i);
4362 memcpy_toio(addr + offset, ubios, len);
4364 writel(0x0bf00401, addr);
4365 writel(0, (addr + 4));
4367 /* Clear the reset, and change states. */
4368 writeb(FEPCLR, brd->re_map_port);
4372 * Checks to see if the BIOS completed running on the card.
4374 static void dgap_do_wait_for_bios(struct board_t *brd)
4381 if (!brd || (brd->magic != DGAP_BOARD_MAGIC) || !brd->re_map_membase)
4384 addr = brd->re_map_membase;
4385 word = readw(addr + POSTAREA);
4388 * It can take 5-6 seconds for a board to
4389 * pass the bios self test and post results.
4390 * Give it 10 seconds.
4392 brd->wait_for_bios = 0;
4393 while (brd->wait_for_bios < 1000) {
4394 /* Check to see if BIOS thinks board is good. (GD). */
4395 if (word == *(u16 *) "GD") {
4396 brd->state = FINISHED_BIOS_LOAD;
4399 msleep_interruptible(10);
4400 brd->wait_for_bios++;
4401 word = readw(addr + POSTAREA);
4404 /* Gave up on board after too long of time taken */
4405 err1 = readw(addr + SEQUENCE);
4406 err2 = readw(addr + ERROR);
4407 pr_warn("dgap: %s failed diagnostics. Error #(%x,%x).\n",
4408 brd->name, err1, err2);
4409 brd->state = BOARD_FAILED;
4410 brd->dpastatus = BD_NOBIOS;
4414 * Copies the FEP code from the user to the board,
4415 * and starts the FEP running.
4417 static void dgap_do_fep_load(struct board_t *brd, uchar __user *ufep, int len)
4422 if (!brd || (brd->magic != DGAP_BOARD_MAGIC) || !brd->re_map_membase)
4425 addr = brd->re_map_membase;
4431 memcpy_toio(addr + offset, ufep, len);
4434 * If board is a concentrator product, we need to give
4435 * it its config string describing how the concentrators look.
4437 if ((brd->type == PCX) || (brd->type == PEPC)) {
4439 uchar *config, *xconfig;
4442 xconfig = dgap_create_config_string(brd, string);
4444 /* Write string to board memory */
4445 config = addr + CONFIG;
4446 for (; i < CONFIGSIZE; i++, config++, xconfig++) {
4447 writeb(*xconfig, config);
4448 if ((*xconfig & 0xff) == 0xff)
4453 writel(0xbfc01004, (addr + 0xc34));
4454 writel(0x3, (addr + 0xc30));
4459 * Waits for the FEP to report thats its ready for us to use.
4461 static void dgap_do_wait_for_fep(struct board_t *brd)
4468 if (!brd || (brd->magic != DGAP_BOARD_MAGIC) || !brd->re_map_membase)
4471 addr = brd->re_map_membase;
4472 word = readw(addr + FEPSTAT);
4475 * It can take 2-3 seconds for the FEP to
4476 * be up and running. Give it 5 secs.
4478 brd->wait_for_fep = 0;
4479 while (brd->wait_for_fep < 500) {
4480 /* Check to see if FEP is up and running now. */
4481 if (word == *(u16 *) "OS") {
4482 brd->state = FINISHED_FEP_LOAD;
4484 * Check to see if the board can support FEP5+ commands.
4486 word = readw(addr + FEP5_PLUS);
4487 if (word == *(u16 *) "5A")
4488 brd->bd_flags |= BD_FEP5PLUS;
4492 msleep_interruptible(10);
4493 brd->wait_for_fep++;
4494 word = readw(addr + FEPSTAT);
4497 /* Gave up on board after too long of time taken */
4498 err1 = readw(addr + SEQUENCE);
4499 err2 = readw(addr + ERROR);
4500 pr_warn("dgap: FEPOS for %s not functioning. Error #(%x,%x).\n",
4501 brd->name, err1, err2);
4502 brd->state = BOARD_FAILED;
4503 brd->dpastatus = BD_NOFEP;
4507 * Physically forces the FEP5 card to reset itself.
4509 static void dgap_do_reset_board(struct board_t *brd)
4516 if (!brd || (brd->magic != DGAP_BOARD_MAGIC) ||
4517 !brd->re_map_membase || !brd->re_map_port)
4520 /* FEPRST does not vary among supported boards */
4521 writeb(FEPRST, brd->re_map_port);
4523 for (i = 0; i <= 1000; i++) {
4524 check = readb(brd->re_map_port) & 0xe;
4525 if (check == FEPRST)
4531 pr_warn("dgap: Board not resetting... Failing board.\n");
4532 brd->state = BOARD_FAILED;
4533 brd->dpastatus = BD_NOFEP;
4538 * Make sure there really is memory out there.
4540 writel(0xa55a3cc3, (brd->re_map_membase + LOWMEM));
4541 writel(0x5aa5c33c, (brd->re_map_membase + HIGHMEM));
4542 check1 = readl(brd->re_map_membase + LOWMEM);
4543 check2 = readl(brd->re_map_membase + HIGHMEM);
4545 if ((check1 != 0xa55a3cc3) || (check2 != 0x5aa5c33c)) {
4546 pr_warn("dgap: No memory at %p for board.\n",
4547 brd->re_map_membase);
4548 brd->state = BOARD_FAILED;
4549 brd->dpastatus = BD_NOFEP;
4553 if (brd->state != BOARD_FAILED)
4554 brd->state = FINISHED_RESET;
4557 #ifdef DIGI_CONCENTRATORS_SUPPORTED
4559 * Sends a concentrator image into the FEP5 board.
4561 static void dgap_do_conc_load(struct board_t *brd, uchar *uaddr, int len)
4565 struct downld_t *to_dp;
4567 if (!brd || (brd->magic != DGAP_BOARD_MAGIC) || !brd->re_map_membase)
4570 vaddr = brd->re_map_membase;
4572 offset = readw((u16 *) (vaddr + DOWNREQ));
4573 to_dp = (struct downld_t *) (vaddr + (int) offset);
4574 memcpy_toio(to_dp, uaddr, len);
4576 /* Tell card we have data for it */
4577 writew(0, vaddr + (DOWNREQ));
4579 brd->conc_dl_status = NO_PENDING_CONCENTRATOR_REQUESTS;
4583 #define EXPANSION_ROM_SIZE (64 * 1024)
4584 #define FEP5_ROM_MAGIC (0xFEFFFFFF)
4586 static void dgap_get_vpd(struct board_t *brd)
4598 * Poke the magic number at the PCI Rom Address location.
4599 * If VPD is supported, the value read from that address
4602 magic = FEP5_ROM_MAGIC;
4603 pci_write_config_dword(brd->pdev, PCI_ROM_ADDRESS, magic);
4604 pci_read_config_dword(brd->pdev, PCI_ROM_ADDRESS, &magic);
4606 /* VPD not supported, bail */
4611 * To get to the OTPROM memory, we have to send the boards base
4612 * address or'ed with 1 into the PCI Rom Address location.
4614 magic = brd->membase | 0x01;
4615 pci_write_config_dword(brd->pdev, PCI_ROM_ADDRESS, magic);
4616 pci_read_config_dword(brd->pdev, PCI_ROM_ADDRESS, &magic);
4618 byte1 = readb(brd->re_map_membase);
4619 byte2 = readb(brd->re_map_membase + 1);
4622 * If the board correctly swapped to the OTPROM memory,
4623 * the first 2 bytes (header) should be 0x55, 0xAA
4625 if (byte1 == 0x55 && byte2 == 0xAA) {
4630 * We have to run through all the OTPROM memory looking
4631 * for the VPD offset.
4633 while (base_offset <= EXPANSION_ROM_SIZE) {
4636 * Lots of magic numbers here.
4638 * The VPD offset is located inside the ROM Data
4641 * We also have to remember the length of each
4642 * ROM Data Structure, so we can "hop" to the next
4643 * entry if the VPD isn't in the current
4644 * ROM Data Structure.
4646 rom_offset = readw(brd->re_map_membase +
4647 base_offset + 0x18);
4648 image_length = readw(brd->re_map_membase +
4649 rom_offset + 0x10) * 512;
4650 vpd_offset = readw(brd->re_map_membase +
4653 /* Found the VPD entry */
4657 /* We didn't find a VPD entry, go to next ROM entry. */
4658 base_offset += image_length;
4660 byte1 = readb(brd->re_map_membase + base_offset);
4661 byte2 = readb(brd->re_map_membase + base_offset + 1);
4664 * If the new ROM offset doesn't have 0x55, 0xAA
4665 * as its header, we have run out of ROM.
4667 if (byte1 != 0x55 || byte2 != 0xAA)
4672 * If we have a VPD offset, then mark the board
4673 * as having a valid VPD, and copy VPDSIZE (512) bytes of
4674 * that VPD to the buffer we have in our board structure.
4677 brd->bd_flags |= BD_HAS_VPD;
4678 for (i = 0; i < VPDSIZE; i++) {
4679 brd->vpd[i] = readb(brd->re_map_membase +
4686 * We MUST poke the magic number at the PCI Rom Address location again.
4687 * This makes the card report the regular board memory back to us,
4688 * rather than the OTPROM memory.
4690 magic = FEP5_ROM_MAGIC;
4691 pci_write_config_dword(brd->pdev, PCI_ROM_ADDRESS, magic);
4695 * Our board poller function.
4697 static void dgap_poll_tasklet(unsigned long data)
4699 struct board_t *bd = (struct board_t *) data;
4704 if (!bd || (bd->magic != DGAP_BOARD_MAGIC))
4707 if (bd->inhibit_poller)
4710 DGAP_LOCK(bd->bd_lock, lock_flags);
4712 vaddr = bd->re_map_membase;
4715 * If board is ready, parse deeper to see if there is anything to do.
4717 if (bd->state == BOARD_READY) {
4719 struct ev_t *eaddr = NULL;
4721 if (!bd->re_map_membase) {
4722 DGAP_UNLOCK(bd->bd_lock, lock_flags);
4725 if (!bd->re_map_port) {
4726 DGAP_UNLOCK(bd->bd_lock, lock_flags);
4733 eaddr = (struct ev_t *) (vaddr + EVBUF);
4735 /* Get our head and tail */
4736 head = readw(&(eaddr->ev_head));
4737 tail = readw(&(eaddr->ev_tail));
4740 * If there is an event pending. Go service it.
4743 DGAP_UNLOCK(bd->bd_lock, lock_flags);
4745 DGAP_LOCK(bd->bd_lock, lock_flags);
4750 * If board is doing interrupts, ACK the interrupt.
4752 if (bd && bd->intr_running)
4753 readb(bd->re_map_port + 2);
4755 DGAP_UNLOCK(bd->bd_lock, lock_flags);
4759 DGAP_UNLOCK(bd->bd_lock, lock_flags);
4762 /*=======================================================================
4764 * dgap_cmdb - Sends a 2 byte command to the FEP.
4766 * ch - Pointer to channel structure.
4767 * cmd - Command to be sent.
4768 * byte1 - Integer containing first byte to be sent.
4769 * byte2 - Integer containing second byte to be sent.
4770 * ncmds - Wait until ncmds or fewer cmds are left
4771 * in the cmd buffer before returning.
4773 *=======================================================================*/
4774 static void dgap_cmdb(struct channel_t *ch, uchar cmd, uchar byte1,
4775 uchar byte2, uint ncmds)
4778 struct cm_t *cm_addr = NULL;
4784 if (!ch || ch->magic != DGAP_CHANNEL_MAGIC)
4788 * Check if board is still alive.
4790 if (ch->ch_bd->state == BOARD_FAILED)
4794 * Make sure the pointers are in range before
4795 * writing to the FEP memory.
4797 vaddr = ch->ch_bd->re_map_membase;
4802 cm_addr = (struct cm_t *) (vaddr + CMDBUF);
4803 head = readw(&(cm_addr->cm_head));
4806 * Forget it if pointers out of range.
4808 if (head >= (CMDMAX - CMDSTART) || (head & 03)) {
4809 ch->ch_bd->state = BOARD_FAILED;
4814 * Put the data in the circular command buffer.
4816 writeb(cmd, (char *) (vaddr + head + CMDSTART + 0));
4817 writeb((uchar) ch->ch_portnum, (char *) (vaddr + head + CMDSTART + 1));
4818 writeb(byte1, (char *) (vaddr + head + CMDSTART + 2));
4819 writeb(byte2, (char *) (vaddr + head + CMDSTART + 3));
4821 head = (head + 4) & (CMDMAX - CMDSTART - 4);
4823 writew(head, &(cm_addr->cm_head));
4826 * Wait if necessary before updating the head
4827 * pointer to limit the number of outstanding
4828 * commands to the FEP. If the time spent waiting
4829 * is outlandish, declare the FEP dead.
4831 for (count = dgap_count ;;) {
4833 head = readw(&(cm_addr->cm_head));
4834 tail = readw(&(cm_addr->cm_tail));
4836 n = (head - tail) & (CMDMAX - CMDSTART - 4);
4838 if (n <= ncmds * sizeof(struct cm_t))
4842 ch->ch_bd->state = BOARD_FAILED;
4849 /*=======================================================================
4851 * dgap_cmdw - Sends a 1 word command to the FEP.
4853 * ch - Pointer to channel structure.
4854 * cmd - Command to be sent.
4855 * word - Integer containing word to be sent.
4856 * ncmds - Wait until ncmds or fewer cmds are left
4857 * in the cmd buffer before returning.
4859 *=======================================================================*/
4860 static void dgap_cmdw(struct channel_t *ch, uchar cmd, u16 word, uint ncmds)
4863 struct cm_t *cm_addr = NULL;
4869 if (!ch || ch->magic != DGAP_CHANNEL_MAGIC)
4873 * Check if board is still alive.
4875 if (ch->ch_bd->state == BOARD_FAILED)
4879 * Make sure the pointers are in range before
4880 * writing to the FEP memory.
4882 vaddr = ch->ch_bd->re_map_membase;
4886 cm_addr = (struct cm_t *) (vaddr + CMDBUF);
4887 head = readw(&(cm_addr->cm_head));
4890 * Forget it if pointers out of range.
4892 if (head >= (CMDMAX - CMDSTART) || (head & 03)) {
4893 ch->ch_bd->state = BOARD_FAILED;
4898 * Put the data in the circular command buffer.
4900 writeb(cmd, (char *) (vaddr + head + CMDSTART + 0));
4901 writeb((uchar) ch->ch_portnum, (char *) (vaddr + head + CMDSTART + 1));
4902 writew((u16) word, (char *) (vaddr + head + CMDSTART + 2));
4904 head = (head + 4) & (CMDMAX - CMDSTART - 4);
4906 writew(head, &(cm_addr->cm_head));
4909 * Wait if necessary before updating the head
4910 * pointer to limit the number of outstanding
4911 * commands to the FEP. If the time spent waiting
4912 * is outlandish, declare the FEP dead.
4914 for (count = dgap_count ;;) {
4916 head = readw(&(cm_addr->cm_head));
4917 tail = readw(&(cm_addr->cm_tail));
4919 n = (head - tail) & (CMDMAX - CMDSTART - 4);
4921 if (n <= ncmds * sizeof(struct cm_t))
4925 ch->ch_bd->state = BOARD_FAILED;
4932 /*=======================================================================
4934 * dgap_cmdw_ext - Sends a extended word command to the FEP.
4936 * ch - Pointer to channel structure.
4937 * cmd - Command to be sent.
4938 * word - Integer containing word to be sent.
4939 * ncmds - Wait until ncmds or fewer cmds are left
4940 * in the cmd buffer before returning.
4942 *=======================================================================*/
4943 static void dgap_cmdw_ext(struct channel_t *ch, u16 cmd, u16 word, uint ncmds)
4946 struct cm_t *cm_addr = NULL;
4952 if (!ch || ch->magic != DGAP_CHANNEL_MAGIC)
4956 * Check if board is still alive.
4958 if (ch->ch_bd->state == BOARD_FAILED)
4962 * Make sure the pointers are in range before
4963 * writing to the FEP memory.
4965 vaddr = ch->ch_bd->re_map_membase;
4969 cm_addr = (struct cm_t *) (vaddr + CMDBUF);
4970 head = readw(&(cm_addr->cm_head));
4973 * Forget it if pointers out of range.
4975 if (head >= (CMDMAX - CMDSTART) || (head & 03)) {
4976 ch->ch_bd->state = BOARD_FAILED;
4981 * Put the data in the circular command buffer.
4984 /* Write an FF to tell the FEP that we want an extended command */
4985 writeb((uchar) 0xff, (char *) (vaddr + head + CMDSTART + 0));
4987 writeb((uchar) ch->ch_portnum, (uchar *) (vaddr + head + CMDSTART + 1));
4988 writew((u16) cmd, (char *) (vaddr + head + CMDSTART + 2));
4991 * If the second part of the command won't fit,
4992 * put it at the beginning of the circular buffer.
4994 if (((head + 4) >= ((CMDMAX - CMDSTART)) || (head & 03)))
4995 writew((u16) word, (char *) (vaddr + CMDSTART));
4997 writew((u16) word, (char *) (vaddr + head + CMDSTART + 4));
4999 head = (head + 8) & (CMDMAX - CMDSTART - 4);
5001 writew(head, &(cm_addr->cm_head));
5004 * Wait if necessary before updating the head
5005 * pointer to limit the number of outstanding
5006 * commands to the FEP. If the time spent waiting
5007 * is outlandish, declare the FEP dead.
5009 for (count = dgap_count ;;) {
5011 head = readw(&(cm_addr->cm_head));
5012 tail = readw(&(cm_addr->cm_tail));
5014 n = (head - tail) & (CMDMAX - CMDSTART - 4);
5016 if (n <= ncmds * sizeof(struct cm_t))
5020 ch->ch_bd->state = BOARD_FAILED;
5027 /*=======================================================================
5029 * dgap_wmove - Write data to FEP buffer.
5031 * ch - Pointer to channel structure.
5032 * buf - Poiter to characters to be moved.
5033 * cnt - Number of characters to move.
5035 *=======================================================================*/
5036 static void dgap_wmove(struct channel_t *ch, char *buf, uint cnt)
5043 if (!ch || ch->magic != DGAP_CHANNEL_MAGIC)
5050 head = readw(&(bs->tx_head));
5053 * If pointers are out of range, just return.
5055 if ((cnt > ch->ch_tsize) ||
5056 (unsigned)(head - ch->ch_tstart) >= ch->ch_tsize)
5060 * If the write wraps over the top of the circular buffer,
5061 * move the portion up to the wrap point, and reset the
5062 * pointers to the bottom.
5064 n = ch->ch_tstart + ch->ch_tsize - head;
5068 taddr = ch->ch_taddr + head;
5069 memcpy_toio(taddr, buf, n);
5070 head = ch->ch_tstart;
5075 * Move rest of data.
5077 taddr = ch->ch_taddr + head;
5079 memcpy_toio(taddr, buf, n);
5082 writew(head, &(bs->tx_head));
5086 * Retrives the current custom baud rate from FEP memory,
5087 * and returns it back to the user.
5088 * Returns 0 on error.
5090 static uint dgap_get_custom_baud(struct channel_t *ch)
5096 if (!ch || ch->magic != DGAP_CHANNEL_MAGIC)
5099 if (!ch->ch_bd || ch->ch_bd->magic != DGAP_BOARD_MAGIC)
5102 if (!(ch->ch_bd->bd_flags & BD_FEP5PLUS))
5105 vaddr = ch->ch_bd->re_map_membase;
5111 * Go get from fep mem, what the fep
5112 * believes the custom baud rate is.
5114 offset = ((((*(unsigned short *)(vaddr + ECS_SEG)) << 4) +
5115 (ch->ch_portnum * 0x28) + LINE_SPEED));
5117 value = readw(vaddr + offset);
5122 * Calls the firmware to reset this channel.
5124 static void dgap_firmware_reset_port(struct channel_t *ch)
5126 dgap_cmdb(ch, CHRESET, 0, 0, 0);
5129 * Now that the channel is reset, we need to make sure
5130 * all the current settings get reapplied to the port
5133 * So we will set the driver's cache of firmware
5134 * settings all to 0, and then call param.
5136 ch->ch_fepiflag = 0;
5137 ch->ch_fepcflag = 0;
5138 ch->ch_fepoflag = 0;
5139 ch->ch_fepstartc = 0;
5140 ch->ch_fepstopc = 0;
5141 ch->ch_fepastartc = 0;
5142 ch->ch_fepastopc = 0;
5147 /*=======================================================================
5149 * dgap_param - Set Digi parameters.
5151 * struct tty_struct * - TTY for port.
5153 *=======================================================================*/
5154 static int dgap_param(struct tty_struct *tty)
5156 struct ktermios *ts;
5158 struct channel_t *ch;
5167 if (!tty || tty->magic != TTY_MAGIC)
5170 un = (struct un_t *) tty->driver_data;
5171 if (!un || un->magic != DGAP_UNIT_MAGIC)
5175 if (!ch || ch->magic != DGAP_CHANNEL_MAGIC)
5179 if (!bd || bd->magic != DGAP_BOARD_MAGIC)
5189 * If baud rate is zero, flush queues, and set mval to drop DTR.
5191 if ((ch->ch_c_cflag & (CBAUD)) == 0) {
5194 head = readw(&(ch->ch_bs->rx_head));
5195 writew(head, &(ch->ch_bs->rx_tail));
5198 head = readw(&(ch->ch_bs->tx_head));
5199 writew(head, &(ch->ch_bs->tx_tail));
5201 ch->ch_flags |= (CH_BAUD0);
5203 /* Drop RTS and DTR */
5204 ch->ch_mval &= ~(D_RTS(ch)|D_DTR(ch));
5205 mval = D_DTR(ch) | D_RTS(ch);
5206 ch->ch_baud_info = 0;
5208 } else if (ch->ch_custom_speed && (bd->bd_flags & BD_FEP5PLUS)) {
5210 * Tell the fep to do the command
5213 dgap_cmdw_ext(ch, 0xff01, ch->ch_custom_speed, 0);
5216 * Now go get from fep mem, what the fep
5217 * believes the custom baud rate is.
5219 ch->ch_custom_speed = dgap_get_custom_baud(ch);
5220 ch->ch_baud_info = ch->ch_custom_speed;
5222 /* Handle transition from B0 */
5223 if (ch->ch_flags & CH_BAUD0) {
5224 ch->ch_flags &= ~(CH_BAUD0);
5225 ch->ch_mval |= (D_RTS(ch)|D_DTR(ch));
5227 mval = D_DTR(ch) | D_RTS(ch);
5231 * Set baud rate, character size, and parity.
5239 ulong bauds[4][16] = {
5243 600, 1200, 1800, 2400,
5244 4800, 9600, 19200, 38400 },
5245 { /* slowbaud & CBAUDEX */
5246 0, 57600, 115200, 230400,
5247 460800, 150, 200, 921600,
5248 600, 1200, 1800, 2400,
5249 4800, 9600, 19200, 38400 },
5251 0, 57600, 76800, 115200,
5252 14400, 57600, 230400, 76800,
5253 115200, 230400, 28800, 460800,
5254 921600, 9600, 19200, 38400 },
5255 { /* fastbaud & CBAUDEX */
5256 0, 57600, 115200, 230400,
5257 460800, 150, 200, 921600,
5258 600, 1200, 1800, 2400,
5259 4800, 9600, 19200, 38400 }
5263 * Only use the TXPrint baud rate if the
5264 * terminal unit is NOT open
5266 if (!(ch->ch_tun.un_flags & UN_ISOPEN) &&
5267 (un->un_type == DGAP_PRINT))
5268 baud = C_BAUD(ch->ch_pun.un_tty) & 0xff;
5270 baud = C_BAUD(ch->ch_tun.un_tty) & 0xff;
5272 if (ch->ch_c_cflag & CBAUDEX)
5275 if (ch->ch_digi.digi_flags & DIGI_FAST)
5280 if ((iindex >= 0) && (iindex < 4) &&
5281 (jindex >= 0) && (jindex < 16))
5282 baud = bauds[iindex][jindex];
5289 ch->ch_baud_info = baud;
5292 * CBAUD has bit position 0x1000 set these days to
5293 * indicate Linux baud rate remap.
5294 * We use a different bit assignment for high speed.
5295 * Clear this bit out while grabbing the parts of
5298 cflag = ch->ch_c_cflag & ((CBAUD ^ CBAUDEX) | PARODD | PARENB |
5302 * HUPCL bit is used by FEP to indicate fast baud
5303 * table is to be used.
5305 if ((ch->ch_digi.digi_flags & DIGI_FAST) ||
5306 (ch->ch_c_cflag & CBAUDEX))
5309 if ((ch->ch_c_cflag & CBAUDEX) &&
5310 !(ch->ch_digi.digi_flags & DIGI_FAST)) {
5312 * The below code is trying to guarantee that only
5313 * baud rates 115200, 230400, 460800, 921600 are
5314 * remapped. We use exclusive or because the various
5315 * baud rates share common bit positions and therefore
5316 * can't be tested for easily.
5318 tcflag_t tcflag = (ch->ch_c_cflag & CBAUD) | CBAUDEX;
5322 * Map high speed requests to index
5323 * into FEP's baud table
5353 cflag = (cflag & ~(CBAUD | CBAUDEX)) | baudpart;
5358 if (cflag != ch->ch_fepcflag) {
5359 ch->ch_fepcflag = (u16) (cflag & 0xffff);
5362 * Okay to have channel and board
5363 * locks held calling this
5365 dgap_cmdw(ch, SCFLAG, (u16) cflag, 0);
5368 /* Handle transition from B0 */
5369 if (ch->ch_flags & CH_BAUD0) {
5370 ch->ch_flags &= ~(CH_BAUD0);
5371 ch->ch_mval |= (D_RTS(ch)|D_DTR(ch));
5373 mval = D_DTR(ch) | D_RTS(ch);
5379 iflag = ch->ch_c_iflag & (IGNBRK | BRKINT | IGNPAR | PARMRK |
5380 INPCK | ISTRIP | IXON | IXANY | IXOFF);
5382 if ((ch->ch_startc == _POSIX_VDISABLE) ||
5383 (ch->ch_stopc == _POSIX_VDISABLE)) {
5384 iflag &= ~(IXON | IXOFF);
5385 ch->ch_c_iflag &= ~(IXON | IXOFF);
5389 * Only the IBM Xr card can switch between
5390 * 232 and 422 modes on the fly
5392 if (bd->device == PCI_DEV_XR_IBM_DID) {
5393 if (ch->ch_digi.digi_flags & DIGI_422)
5394 dgap_cmdb(ch, SCOMMODE, MODE_422, 0, 0);
5396 dgap_cmdb(ch, SCOMMODE, MODE_232, 0, 0);
5399 if (ch->ch_digi.digi_flags & DIGI_ALTPIN)
5402 if (iflag != ch->ch_fepiflag) {
5403 ch->ch_fepiflag = iflag;
5405 /* Okay to have channel and board locks held calling this */
5406 dgap_cmdw(ch, SIFLAG, (u16) ch->ch_fepiflag, 0);
5410 * Select hardware handshaking.
5414 if (ch->ch_c_cflag & CRTSCTS)
5415 hflow |= (D_RTS(ch) | D_CTS(ch));
5416 if (ch->ch_digi.digi_flags & RTSPACE)
5418 if (ch->ch_digi.digi_flags & DTRPACE)
5420 if (ch->ch_digi.digi_flags & CTSPACE)
5422 if (ch->ch_digi.digi_flags & DSRPACE)
5424 if (ch->ch_digi.digi_flags & DCDPACE)
5427 if (hflow != ch->ch_hflow) {
5428 ch->ch_hflow = hflow;
5430 /* Okay to have channel and board locks held calling this */
5431 dgap_cmdb(ch, SHFLOW, (uchar) hflow, 0xff, 0);
5436 * Set RTS and/or DTR Toggle if needed,
5437 * but only if product is FEP5+ based.
5439 if (bd->bd_flags & BD_FEP5PLUS) {
5441 if (ch->ch_digi.digi_flags & DIGI_RTS_TOGGLE)
5442 hflow2 |= (D_RTS(ch));
5443 if (ch->ch_digi.digi_flags & DIGI_DTR_TOGGLE)
5444 hflow2 |= (D_DTR(ch));
5446 dgap_cmdw_ext(ch, 0xff03, hflow2, 0);
5450 * Set modem control lines.
5453 mval ^= ch->ch_mforce & (mval ^ ch->ch_mval);
5455 if (ch->ch_mostat ^ mval) {
5456 ch->ch_mostat = mval;
5458 /* Okay to have channel and board locks held calling this */
5459 dgap_cmdb(ch, SMODEM, (uchar) mval, D_RTS(ch)|D_DTR(ch), 0);
5463 * Read modem signals, and then call carrier function.
5465 ch->ch_mistat = readb(&(bs->m_stat));
5469 * Set the start and stop characters.
5471 if (ch->ch_startc != ch->ch_fepstartc ||
5472 ch->ch_stopc != ch->ch_fepstopc) {
5473 ch->ch_fepstartc = ch->ch_startc;
5474 ch->ch_fepstopc = ch->ch_stopc;
5476 /* Okay to have channel and board locks held calling this */
5477 dgap_cmdb(ch, SFLOWC, ch->ch_fepstartc, ch->ch_fepstopc, 0);
5481 * Set the Auxiliary start and stop characters.
5483 if (ch->ch_astartc != ch->ch_fepastartc ||
5484 ch->ch_astopc != ch->ch_fepastopc) {
5485 ch->ch_fepastartc = ch->ch_astartc;
5486 ch->ch_fepastopc = ch->ch_astopc;
5488 /* Okay to have channel and board locks held calling this */
5489 dgap_cmdb(ch, SAFLOWC, ch->ch_fepastartc, ch->ch_fepastopc, 0);
5496 * dgap_parity_scan()
5498 * Convert the FEP5 way of reporting parity errors and breaks into
5499 * the Linux line discipline way.
5501 static void dgap_parity_scan(struct channel_t *ch, unsigned char *cbuf,
5502 unsigned char *fbuf, int *len)
5506 unsigned char *in, *cout, *fout;
5513 if (!ch || ch->magic != DGAP_CHANNEL_MAGIC)
5518 switch (ch->pscan_state) {
5520 /* reset to sanity and fall through */
5521 ch->pscan_state = 0;
5524 /* No FF seen yet */
5525 if (c == (unsigned char) '\377')
5526 /* delete this character from stream */
5527 ch->pscan_state = 1;
5530 *fout++ = TTY_NORMAL;
5537 if (c == (unsigned char) '\377') {
5538 /* doubled ff, transform to single ff */
5540 *fout++ = TTY_NORMAL;
5542 ch->pscan_state = 0;
5544 /* save value examination in next state */
5545 ch->pscan_savechar = c;
5546 ch->pscan_state = 2;
5551 /* third character of ff sequence */
5555 if (ch->pscan_savechar == 0x0) {
5559 *fout++ = TTY_BREAK;
5561 ch->ch_err_parity++;
5562 *fout++ = TTY_PARITY;
5567 ch->pscan_state = 0;
5573 /*=======================================================================
5575 * dgap_event - FEP to host event processing routine.
5577 * bd - Board of current event.
5579 *=======================================================================*/
5580 static int dgap_event(struct board_t *bd)
5582 struct channel_t *ch;
5587 uchar *vaddr = NULL;
5588 struct ev_t *eaddr = NULL;
5596 if (!bd || bd->magic != DGAP_BOARD_MAGIC)
5599 DGAP_LOCK(bd->bd_lock, lock_flags);
5601 vaddr = bd->re_map_membase;
5604 DGAP_UNLOCK(bd->bd_lock, lock_flags);
5608 eaddr = (struct ev_t *) (vaddr + EVBUF);
5610 /* Get our head and tail */
5611 head = readw(&(eaddr->ev_head));
5612 tail = readw(&(eaddr->ev_tail));
5615 * Forget it if pointers out of range.
5618 if (head >= EVMAX - EVSTART || tail >= EVMAX - EVSTART ||
5619 (head | tail) & 03) {
5620 /* Let go of board lock */
5621 DGAP_UNLOCK(bd->bd_lock, lock_flags);
5626 * Loop to process all the events in the buffer.
5628 while (tail != head) {
5631 * Get interrupt information.
5634 event = bd->re_map_membase + tail + EVSTART;
5642 * Make sure the interrupt is valid.
5644 if (port >= bd->nasync)
5647 if (!(reason & (IFMODEM | IFBREAK | IFTLW | IFTEM | IFDATA)))
5650 ch = bd->channels[port];
5652 if (!ch || ch->magic != DGAP_CHANNEL_MAGIC)
5656 * If we have made it here, the event was valid.
5657 * Lock down the channel.
5659 DGAP_LOCK(ch->ch_lock, lock_flags2);
5664 DGAP_UNLOCK(ch->ch_lock, lock_flags2);
5669 * Process received data.
5671 if (reason & IFDATA) {
5674 * ALL LOCKS *MUST* BE DROPPED BEFORE CALLING INPUT!
5675 * input could send some data to ld, which in turn
5676 * could do a callback to one of our other functions.
5678 DGAP_UNLOCK(ch->ch_lock, lock_flags2);
5679 DGAP_UNLOCK(bd->bd_lock, lock_flags);
5683 DGAP_LOCK(bd->bd_lock, lock_flags);
5684 DGAP_LOCK(ch->ch_lock, lock_flags2);
5686 if (ch->ch_flags & CH_RACTIVE)
5687 ch->ch_flags |= CH_RENABLE;
5689 writeb(1, &(bs->idata));
5691 if (ch->ch_flags & CH_RWAIT) {
5692 ch->ch_flags &= ~CH_RWAIT;
5694 wake_up_interruptible
5695 (&ch->ch_tun.un_flags_wait);
5700 * Process Modem change signals.
5702 if (reason & IFMODEM) {
5703 ch->ch_mistat = modem;
5710 if (reason & IFBREAK) {
5712 if (ch->ch_tun.un_tty) {
5713 /* A break has been indicated */
5715 tty_buffer_request_room
5716 (ch->ch_tun.un_tty->port, 1);
5717 tty_insert_flip_char(ch->ch_tun.un_tty->port,
5719 tty_flip_buffer_push(ch->ch_tun.un_tty->port);
5724 * Process Transmit low.
5726 if (reason & IFTLW) {
5728 if (ch->ch_tun.un_flags & UN_LOW) {
5729 ch->ch_tun.un_flags &= ~UN_LOW;
5731 if (ch->ch_tun.un_flags & UN_ISOPEN) {
5732 if ((ch->ch_tun.un_tty->flags &
5733 (1 << TTY_DO_WRITE_WAKEUP)) &&
5734 ch->ch_tun.un_tty->ldisc->ops->write_wakeup) {
5735 DGAP_UNLOCK(ch->ch_lock, lock_flags2);
5736 DGAP_UNLOCK(bd->bd_lock, lock_flags);
5737 (ch->ch_tun.un_tty->ldisc->ops->write_wakeup)(ch->ch_tun.un_tty);
5738 DGAP_LOCK(bd->bd_lock, lock_flags);
5739 DGAP_LOCK(ch->ch_lock, lock_flags2);
5741 wake_up_interruptible(&ch->ch_tun.un_tty->write_wait);
5742 wake_up_interruptible(&ch->ch_tun.un_flags_wait);
5746 if (ch->ch_pun.un_flags & UN_LOW) {
5747 ch->ch_pun.un_flags &= ~UN_LOW;
5748 if (ch->ch_pun.un_flags & UN_ISOPEN) {
5749 if ((ch->ch_pun.un_tty->flags &
5750 (1 << TTY_DO_WRITE_WAKEUP)) &&
5751 ch->ch_pun.un_tty->ldisc->ops->write_wakeup) {
5752 DGAP_UNLOCK(ch->ch_lock, lock_flags2);
5753 DGAP_UNLOCK(bd->bd_lock, lock_flags);
5754 (ch->ch_pun.un_tty->ldisc->ops->write_wakeup)(ch->ch_pun.un_tty);
5755 DGAP_LOCK(bd->bd_lock, lock_flags);
5756 DGAP_LOCK(ch->ch_lock, lock_flags2);
5758 wake_up_interruptible(&ch->ch_pun.un_tty->write_wait);
5759 wake_up_interruptible(&ch->ch_pun.un_flags_wait);
5763 if (ch->ch_flags & CH_WLOW) {
5764 ch->ch_flags &= ~CH_WLOW;
5765 wake_up_interruptible(&ch->ch_flags_wait);
5770 * Process Transmit empty.
5772 if (reason & IFTEM) {
5773 if (ch->ch_tun.un_flags & UN_EMPTY) {
5774 ch->ch_tun.un_flags &= ~UN_EMPTY;
5775 if (ch->ch_tun.un_flags & UN_ISOPEN) {
5776 if ((ch->ch_tun.un_tty->flags &
5777 (1 << TTY_DO_WRITE_WAKEUP)) &&
5778 ch->ch_tun.un_tty->ldisc->ops->write_wakeup) {
5779 DGAP_UNLOCK(ch->ch_lock, lock_flags2);
5780 DGAP_UNLOCK(bd->bd_lock, lock_flags);
5782 (ch->ch_tun.un_tty->ldisc->ops->write_wakeup)(ch->ch_tun.un_tty);
5783 DGAP_LOCK(bd->bd_lock, lock_flags);
5784 DGAP_LOCK(ch->ch_lock, lock_flags2);
5786 wake_up_interruptible(&ch->ch_tun.un_tty->write_wait);
5787 wake_up_interruptible(&ch->ch_tun.un_flags_wait);
5791 if (ch->ch_pun.un_flags & UN_EMPTY) {
5792 ch->ch_pun.un_flags &= ~UN_EMPTY;
5793 if (ch->ch_pun.un_flags & UN_ISOPEN) {
5794 if ((ch->ch_pun.un_tty->flags &
5795 (1 << TTY_DO_WRITE_WAKEUP)) &&
5796 ch->ch_pun.un_tty->ldisc->ops->write_wakeup) {
5797 DGAP_UNLOCK(ch->ch_lock, lock_flags2);
5798 DGAP_UNLOCK(bd->bd_lock, lock_flags);
5799 (ch->ch_pun.un_tty->ldisc->ops->write_wakeup)(ch->ch_pun.un_tty);
5800 DGAP_LOCK(bd->bd_lock, lock_flags);
5801 DGAP_LOCK(ch->ch_lock, lock_flags2);
5803 wake_up_interruptible(&ch->ch_pun.un_tty->write_wait);
5804 wake_up_interruptible(&ch->ch_pun.un_flags_wait);
5809 if (ch->ch_flags & CH_WEMPTY) {
5810 ch->ch_flags &= ~CH_WEMPTY;
5811 wake_up_interruptible(&ch->ch_flags_wait);
5815 DGAP_UNLOCK(ch->ch_lock, lock_flags2);
5818 tail = (tail + 4) & (EVMAX - EVSTART - 4);
5821 writew(tail, &(eaddr->ev_tail));
5822 DGAP_UNLOCK(bd->bd_lock, lock_flags);
5827 static ssize_t dgap_driver_version_show(struct device_driver *ddp, char *buf)
5829 return snprintf(buf, PAGE_SIZE, "%s\n", DG_PART);
5831 static DRIVER_ATTR(version, S_IRUSR, dgap_driver_version_show, NULL);
5834 static ssize_t dgap_driver_boards_show(struct device_driver *ddp, char *buf)
5836 return snprintf(buf, PAGE_SIZE, "%d\n", dgap_NumBoards);
5838 static DRIVER_ATTR(boards, S_IRUSR, dgap_driver_boards_show, NULL);
5841 static ssize_t dgap_driver_maxboards_show(struct device_driver *ddp, char *buf)
5843 return snprintf(buf, PAGE_SIZE, "%d\n", MAXBOARDS);
5845 static DRIVER_ATTR(maxboards, S_IRUSR, dgap_driver_maxboards_show, NULL);
5848 static ssize_t dgap_driver_pollcounter_show(struct device_driver *ddp,
5851 return snprintf(buf, PAGE_SIZE, "%ld\n", dgap_poll_counter);
5853 static DRIVER_ATTR(pollcounter, S_IRUSR, dgap_driver_pollcounter_show, NULL);
5855 static ssize_t dgap_driver_pollrate_show(struct device_driver *ddp, char *buf)
5857 return snprintf(buf, PAGE_SIZE, "%dms\n", dgap_poll_tick);
5860 static ssize_t dgap_driver_pollrate_store(struct device_driver *ddp,
5861 const char *buf, size_t count)
5863 if (sscanf(buf, "%d\n", &dgap_poll_tick) != 1)
5867 static DRIVER_ATTR(pollrate, (S_IRUSR | S_IWUSR), dgap_driver_pollrate_show,
5868 dgap_driver_pollrate_store);
5870 static int dgap_create_driver_sysfiles(struct pci_driver *dgap_driver)
5873 struct device_driver *driverfs = &dgap_driver->driver;
5875 rc |= driver_create_file(driverfs, &driver_attr_version);
5876 rc |= driver_create_file(driverfs, &driver_attr_boards);
5877 rc |= driver_create_file(driverfs, &driver_attr_maxboards);
5878 rc |= driver_create_file(driverfs, &driver_attr_pollrate);
5879 rc |= driver_create_file(driverfs, &driver_attr_pollcounter);
5884 static void dgap_remove_driver_sysfiles(struct pci_driver *dgap_driver)
5886 struct device_driver *driverfs = &dgap_driver->driver;
5887 driver_remove_file(driverfs, &driver_attr_version);
5888 driver_remove_file(driverfs, &driver_attr_boards);
5889 driver_remove_file(driverfs, &driver_attr_maxboards);
5890 driver_remove_file(driverfs, &driver_attr_pollrate);
5891 driver_remove_file(driverfs, &driver_attr_pollcounter);
5894 static struct board_t *dgap_verify_board(struct device *p)
5901 bd = dev_get_drvdata(p);
5902 if (!bd || bd->magic != DGAP_BOARD_MAGIC || bd->state != BOARD_READY)
5908 static ssize_t dgap_ports_state_show(struct device *p,
5909 struct device_attribute *attr,
5916 bd = dgap_verify_board(p);
5920 for (i = 0; i < bd->nasync; i++) {
5921 count += snprintf(buf + count, PAGE_SIZE - count,
5922 "%d %s\n", bd->channels[i]->ch_portnum,
5923 bd->channels[i]->ch_open_count ? "Open" : "Closed");
5927 static DEVICE_ATTR(ports_state, S_IRUSR, dgap_ports_state_show, NULL);
5929 static ssize_t dgap_ports_baud_show(struct device *p,
5930 struct device_attribute *attr,
5937 bd = dgap_verify_board(p);
5941 for (i = 0; i < bd->nasync; i++) {
5942 count += snprintf(buf + count, PAGE_SIZE - count, "%d %d\n",
5943 bd->channels[i]->ch_portnum,
5944 bd->channels[i]->ch_baud_info);
5948 static DEVICE_ATTR(ports_baud, S_IRUSR, dgap_ports_baud_show, NULL);
5950 static ssize_t dgap_ports_msignals_show(struct device *p,
5951 struct device_attribute *attr,
5958 bd = dgap_verify_board(p);
5962 for (i = 0; i < bd->nasync; i++) {
5963 if (bd->channels[i]->ch_open_count)
5964 count += snprintf(buf + count, PAGE_SIZE - count,
5965 "%d %s %s %s %s %s %s\n",
5966 bd->channels[i]->ch_portnum,
5967 (bd->channels[i]->ch_mostat &
5968 UART_MCR_RTS) ? "RTS" : "",
5969 (bd->channels[i]->ch_mistat &
5970 UART_MSR_CTS) ? "CTS" : "",
5971 (bd->channels[i]->ch_mostat &
5972 UART_MCR_DTR) ? "DTR" : "",
5973 (bd->channels[i]->ch_mistat &
5974 UART_MSR_DSR) ? "DSR" : "",
5975 (bd->channels[i]->ch_mistat &
5976 UART_MSR_DCD) ? "DCD" : "",
5977 (bd->channels[i]->ch_mistat &
5978 UART_MSR_RI) ? "RI" : "");
5980 count += snprintf(buf + count, PAGE_SIZE - count,
5981 "%d\n", bd->channels[i]->ch_portnum);
5985 static DEVICE_ATTR(ports_msignals, S_IRUSR, dgap_ports_msignals_show, NULL);
5987 static ssize_t dgap_ports_iflag_show(struct device *p,
5988 struct device_attribute *attr,
5995 bd = dgap_verify_board(p);
5999 for (i = 0; i < bd->nasync; i++)
6000 count += snprintf(buf + count, PAGE_SIZE - count, "%d %x\n",
6001 bd->channels[i]->ch_portnum,
6002 bd->channels[i]->ch_c_iflag);
6005 static DEVICE_ATTR(ports_iflag, S_IRUSR, dgap_ports_iflag_show, NULL);
6007 static ssize_t dgap_ports_cflag_show(struct device *p,
6008 struct device_attribute *attr,
6015 bd = dgap_verify_board(p);
6019 for (i = 0; i < bd->nasync; i++)
6020 count += snprintf(buf + count, PAGE_SIZE - count, "%d %x\n",
6021 bd->channels[i]->ch_portnum,
6022 bd->channels[i]->ch_c_cflag);
6025 static DEVICE_ATTR(ports_cflag, S_IRUSR, dgap_ports_cflag_show, NULL);
6027 static ssize_t dgap_ports_oflag_show(struct device *p,
6028 struct device_attribute *attr,
6035 bd = dgap_verify_board(p);
6039 for (i = 0; i < bd->nasync; i++)
6040 count += snprintf(buf + count, PAGE_SIZE - count, "%d %x\n",
6041 bd->channels[i]->ch_portnum,
6042 bd->channels[i]->ch_c_oflag);
6045 static DEVICE_ATTR(ports_oflag, S_IRUSR, dgap_ports_oflag_show, NULL);
6047 static ssize_t dgap_ports_lflag_show(struct device *p,
6048 struct device_attribute *attr,
6055 bd = dgap_verify_board(p);
6059 for (i = 0; i < bd->nasync; i++)
6060 count += snprintf(buf + count, PAGE_SIZE - count, "%d %x\n",
6061 bd->channels[i]->ch_portnum,
6062 bd->channels[i]->ch_c_lflag);
6065 static DEVICE_ATTR(ports_lflag, S_IRUSR, dgap_ports_lflag_show, NULL);
6067 static ssize_t dgap_ports_digi_flag_show(struct device *p,
6068 struct device_attribute *attr,
6075 bd = dgap_verify_board(p);
6079 for (i = 0; i < bd->nasync; i++)
6080 count += snprintf(buf + count, PAGE_SIZE - count, "%d %x\n",
6081 bd->channels[i]->ch_portnum,
6082 bd->channels[i]->ch_digi.digi_flags);
6085 static DEVICE_ATTR(ports_digi_flag, S_IRUSR, dgap_ports_digi_flag_show, NULL);
6087 static ssize_t dgap_ports_rxcount_show(struct device *p,
6088 struct device_attribute *attr,
6095 bd = dgap_verify_board(p);
6099 for (i = 0; i < bd->nasync; i++)
6100 count += snprintf(buf + count, PAGE_SIZE - count, "%d %ld\n",
6101 bd->channels[i]->ch_portnum,
6102 bd->channels[i]->ch_rxcount);
6105 static DEVICE_ATTR(ports_rxcount, S_IRUSR, dgap_ports_rxcount_show, NULL);
6107 static ssize_t dgap_ports_txcount_show(struct device *p,
6108 struct device_attribute *attr,
6115 bd = dgap_verify_board(p);
6119 for (i = 0; i < bd->nasync; i++)
6120 count += snprintf(buf + count, PAGE_SIZE - count, "%d %ld\n",
6121 bd->channels[i]->ch_portnum,
6122 bd->channels[i]->ch_txcount);
6125 static DEVICE_ATTR(ports_txcount, S_IRUSR, dgap_ports_txcount_show, NULL);
6127 /* this function creates the sys files that will export each signal status
6128 * to sysfs each value will be put in a separate filename
6130 static void dgap_create_ports_sysfiles(struct board_t *bd)
6132 dev_set_drvdata(&bd->pdev->dev, bd);
6133 device_create_file(&(bd->pdev->dev), &dev_attr_ports_state);
6134 device_create_file(&(bd->pdev->dev), &dev_attr_ports_baud);
6135 device_create_file(&(bd->pdev->dev), &dev_attr_ports_msignals);
6136 device_create_file(&(bd->pdev->dev), &dev_attr_ports_iflag);
6137 device_create_file(&(bd->pdev->dev), &dev_attr_ports_cflag);
6138 device_create_file(&(bd->pdev->dev), &dev_attr_ports_oflag);
6139 device_create_file(&(bd->pdev->dev), &dev_attr_ports_lflag);
6140 device_create_file(&(bd->pdev->dev), &dev_attr_ports_digi_flag);
6141 device_create_file(&(bd->pdev->dev), &dev_attr_ports_rxcount);
6142 device_create_file(&(bd->pdev->dev), &dev_attr_ports_txcount);
6145 /* removes all the sys files created for that port */
6146 static void dgap_remove_ports_sysfiles(struct board_t *bd)
6148 device_remove_file(&(bd->pdev->dev), &dev_attr_ports_state);
6149 device_remove_file(&(bd->pdev->dev), &dev_attr_ports_baud);
6150 device_remove_file(&(bd->pdev->dev), &dev_attr_ports_msignals);
6151 device_remove_file(&(bd->pdev->dev), &dev_attr_ports_iflag);
6152 device_remove_file(&(bd->pdev->dev), &dev_attr_ports_cflag);
6153 device_remove_file(&(bd->pdev->dev), &dev_attr_ports_oflag);
6154 device_remove_file(&(bd->pdev->dev), &dev_attr_ports_lflag);
6155 device_remove_file(&(bd->pdev->dev), &dev_attr_ports_digi_flag);
6156 device_remove_file(&(bd->pdev->dev), &dev_attr_ports_rxcount);
6157 device_remove_file(&(bd->pdev->dev), &dev_attr_ports_txcount);
6160 static ssize_t dgap_tty_state_show(struct device *d,
6161 struct device_attribute *attr,
6165 struct channel_t *ch;
6170 un = dev_get_drvdata(d);
6171 if (!un || un->magic != DGAP_UNIT_MAGIC)
6174 if (!ch || ch->magic != DGAP_CHANNEL_MAGIC)
6177 if (!bd || bd->magic != DGAP_BOARD_MAGIC)
6179 if (bd->state != BOARD_READY)
6182 return snprintf(buf, PAGE_SIZE, "%s", un->un_open_count ?
6185 static DEVICE_ATTR(state, S_IRUSR, dgap_tty_state_show, NULL);
6187 static ssize_t dgap_tty_baud_show(struct device *d,
6188 struct device_attribute *attr,
6192 struct channel_t *ch;
6197 un = dev_get_drvdata(d);
6198 if (!un || un->magic != DGAP_UNIT_MAGIC)
6201 if (!ch || ch->magic != DGAP_CHANNEL_MAGIC)
6204 if (!bd || bd->magic != DGAP_BOARD_MAGIC)
6206 if (bd->state != BOARD_READY)
6209 return snprintf(buf, PAGE_SIZE, "%d\n", ch->ch_baud_info);
6211 static DEVICE_ATTR(baud, S_IRUSR, dgap_tty_baud_show, NULL);
6213 static ssize_t dgap_tty_msignals_show(struct device *d,
6214 struct device_attribute *attr,
6218 struct channel_t *ch;
6223 un = dev_get_drvdata(d);
6224 if (!un || un->magic != DGAP_UNIT_MAGIC)
6227 if (!ch || ch->magic != DGAP_CHANNEL_MAGIC)
6230 if (!bd || bd->magic != DGAP_BOARD_MAGIC)
6232 if (bd->state != BOARD_READY)
6235 if (ch->ch_open_count) {
6236 return snprintf(buf, PAGE_SIZE, "%s %s %s %s %s %s\n",
6237 (ch->ch_mostat & UART_MCR_RTS) ? "RTS" : "",
6238 (ch->ch_mistat & UART_MSR_CTS) ? "CTS" : "",
6239 (ch->ch_mostat & UART_MCR_DTR) ? "DTR" : "",
6240 (ch->ch_mistat & UART_MSR_DSR) ? "DSR" : "",
6241 (ch->ch_mistat & UART_MSR_DCD) ? "DCD" : "",
6242 (ch->ch_mistat & UART_MSR_RI) ? "RI" : "");
6246 static DEVICE_ATTR(msignals, S_IRUSR, dgap_tty_msignals_show, NULL);
6248 static ssize_t dgap_tty_iflag_show(struct device *d,
6249 struct device_attribute *attr,
6253 struct channel_t *ch;
6258 un = dev_get_drvdata(d);
6259 if (!un || un->magic != DGAP_UNIT_MAGIC)
6262 if (!ch || ch->magic != DGAP_CHANNEL_MAGIC)
6265 if (!bd || bd->magic != DGAP_BOARD_MAGIC)
6267 if (bd->state != BOARD_READY)
6270 return snprintf(buf, PAGE_SIZE, "%x\n", ch->ch_c_iflag);
6272 static DEVICE_ATTR(iflag, S_IRUSR, dgap_tty_iflag_show, NULL);
6274 static ssize_t dgap_tty_cflag_show(struct device *d,
6275 struct device_attribute *attr,
6279 struct channel_t *ch;
6284 un = dev_get_drvdata(d);
6285 if (!un || un->magic != DGAP_UNIT_MAGIC)
6288 if (!ch || ch->magic != DGAP_CHANNEL_MAGIC)
6291 if (!bd || bd->magic != DGAP_BOARD_MAGIC)
6293 if (bd->state != BOARD_READY)
6296 return snprintf(buf, PAGE_SIZE, "%x\n", ch->ch_c_cflag);
6298 static DEVICE_ATTR(cflag, S_IRUSR, dgap_tty_cflag_show, NULL);
6300 static ssize_t dgap_tty_oflag_show(struct device *d,
6301 struct device_attribute *attr,
6305 struct channel_t *ch;
6310 un = dev_get_drvdata(d);
6311 if (!un || un->magic != DGAP_UNIT_MAGIC)
6314 if (!ch || ch->magic != DGAP_CHANNEL_MAGIC)
6317 if (!bd || bd->magic != DGAP_BOARD_MAGIC)
6319 if (bd->state != BOARD_READY)
6322 return snprintf(buf, PAGE_SIZE, "%x\n", ch->ch_c_oflag);
6324 static DEVICE_ATTR(oflag, S_IRUSR, dgap_tty_oflag_show, NULL);
6326 static ssize_t dgap_tty_lflag_show(struct device *d,
6327 struct device_attribute *attr,
6331 struct channel_t *ch;
6336 un = dev_get_drvdata(d);
6337 if (!un || un->magic != DGAP_UNIT_MAGIC)
6340 if (!ch || ch->magic != DGAP_CHANNEL_MAGIC)
6343 if (!bd || bd->magic != DGAP_BOARD_MAGIC)
6345 if (bd->state != BOARD_READY)
6348 return snprintf(buf, PAGE_SIZE, "%x\n", ch->ch_c_lflag);
6350 static DEVICE_ATTR(lflag, S_IRUSR, dgap_tty_lflag_show, NULL);
6352 static ssize_t dgap_tty_digi_flag_show(struct device *d,
6353 struct device_attribute *attr,
6357 struct channel_t *ch;
6362 un = dev_get_drvdata(d);
6363 if (!un || un->magic != DGAP_UNIT_MAGIC)
6366 if (!ch || ch->magic != DGAP_CHANNEL_MAGIC)
6369 if (!bd || bd->magic != DGAP_BOARD_MAGIC)
6371 if (bd->state != BOARD_READY)
6374 return snprintf(buf, PAGE_SIZE, "%x\n", ch->ch_digi.digi_flags);
6376 static DEVICE_ATTR(digi_flag, S_IRUSR, dgap_tty_digi_flag_show, NULL);
6378 static ssize_t dgap_tty_rxcount_show(struct device *d,
6379 struct device_attribute *attr,
6383 struct channel_t *ch;
6388 un = dev_get_drvdata(d);
6389 if (!un || un->magic != DGAP_UNIT_MAGIC)
6392 if (!ch || ch->magic != DGAP_CHANNEL_MAGIC)
6395 if (!bd || bd->magic != DGAP_BOARD_MAGIC)
6397 if (bd->state != BOARD_READY)
6400 return snprintf(buf, PAGE_SIZE, "%ld\n", ch->ch_rxcount);
6402 static DEVICE_ATTR(rxcount, S_IRUSR, dgap_tty_rxcount_show, NULL);
6404 static ssize_t dgap_tty_txcount_show(struct device *d,
6405 struct device_attribute *attr,
6409 struct channel_t *ch;
6414 un = dev_get_drvdata(d);
6415 if (!un || un->magic != DGAP_UNIT_MAGIC)
6418 if (!ch || ch->magic != DGAP_CHANNEL_MAGIC)
6421 if (!bd || bd->magic != DGAP_BOARD_MAGIC)
6423 if (bd->state != BOARD_READY)
6426 return snprintf(buf, PAGE_SIZE, "%ld\n", ch->ch_txcount);
6428 static DEVICE_ATTR(txcount, S_IRUSR, dgap_tty_txcount_show, NULL);
6430 static ssize_t dgap_tty_name_show(struct device *d,
6431 struct device_attribute *attr,
6435 struct channel_t *ch;
6439 struct cnode *cptr = NULL;
6447 un = dev_get_drvdata(d);
6448 if (!un || un->magic != DGAP_UNIT_MAGIC)
6451 if (!ch || ch->magic != DGAP_CHANNEL_MAGIC)
6454 if (!bd || bd->magic != DGAP_BOARD_MAGIC)
6456 if (bd->state != BOARD_READY)
6460 cn = ch->ch_portnum;
6462 for (cptr = bd->bd_config; cptr; cptr = cptr->next) {
6464 if ((cptr->type == BNODE) &&
6465 ((cptr->u.board.type == APORT2_920P) ||
6466 (cptr->u.board.type == APORT4_920P) ||
6467 (cptr->u.board.type == APORT8_920P) ||
6468 (cptr->u.board.type == PAPORT4) ||
6469 (cptr->u.board.type == PAPORT8))) {
6472 if (cptr->u.board.v_start)
6473 starto = cptr->u.board.start;
6478 if (cptr->type == TNODE && found == TRUE) {
6480 if (strstr(cptr->u.ttyname, "tty")) {
6481 ptr1 = cptr->u.ttyname;
6484 ptr1 = cptr->u.ttyname;
6486 for (i = 0; i < dgap_config_get_number_of_ports(bd); i++) {
6488 return snprintf(buf, PAGE_SIZE, "%s%s%02d\n",
6489 (un->un_type == DGAP_PRINT) ? "pr" : "tty",
6494 if (cptr->type == CNODE) {
6496 for (i = 0; i < cptr->u.conc.nport; i++) {
6497 if (cn == (i + ncount))
6499 return snprintf(buf, PAGE_SIZE, "%s%s%02d\n",
6500 (un->un_type == DGAP_PRINT) ? "pr" : "tty",
6502 i + (cptr->u.conc.v_start ? cptr->u.conc.start : 1));
6505 ncount += cptr->u.conc.nport;
6508 if (cptr->type == MNODE) {
6510 for (i = 0; i < cptr->u.module.nport; i++) {
6511 if (cn == (i + ncount))
6512 return snprintf(buf, PAGE_SIZE, "%s%s%02d\n",
6513 (un->un_type == DGAP_PRINT) ? "pr" : "tty",
6515 i + (cptr->u.module.v_start ? cptr->u.module.start : 1));
6518 ncount += cptr->u.module.nport;
6523 return snprintf(buf, PAGE_SIZE, "%s_dgap_%d_%d\n",
6524 (un->un_type == DGAP_PRINT) ? "pr" : "tty", bn, cn);
6527 static DEVICE_ATTR(custom_name, S_IRUSR, dgap_tty_name_show, NULL);
6529 static struct attribute *dgap_sysfs_tty_entries[] = {
6530 &dev_attr_state.attr,
6531 &dev_attr_baud.attr,
6532 &dev_attr_msignals.attr,
6533 &dev_attr_iflag.attr,
6534 &dev_attr_cflag.attr,
6535 &dev_attr_oflag.attr,
6536 &dev_attr_lflag.attr,
6537 &dev_attr_digi_flag.attr,
6538 &dev_attr_rxcount.attr,
6539 &dev_attr_txcount.attr,
6540 &dev_attr_custom_name.attr,
6544 static struct attribute_group dgap_tty_attribute_group = {
6546 .attrs = dgap_sysfs_tty_entries,
6549 static void dgap_create_tty_sysfs(struct un_t *un, struct device *c)
6553 ret = sysfs_create_group(&c->kobj, &dgap_tty_attribute_group);
6557 dev_set_drvdata(c, un);
6561 static void dgap_remove_tty_sysfs(struct device *c)
6563 sysfs_remove_group(&c->kobj, &dgap_tty_attribute_group);
6567 * Parse a configuration file read into memory as a string.
6569 static int dgap_parsefile(char **in, int Remove)
6571 struct cnode *p, *brd, *line, *conc;
6573 char *s = NULL, *s2 = NULL;
6577 brd = line = conc = NULL;
6579 /* perhaps we are adding to an existing list? */
6580 while (p->next != NULL)
6583 /* file must start with a BEGIN */
6584 while ((rc = dgap_gettok(in, p)) != BEGIN) {
6586 dgap_err("unexpected EOF");
6592 rc = dgap_gettok(in, p);
6594 dgap_err("unexpected EOF");
6600 dgap_err("unexpected end of file");
6603 case BEGIN: /* should only be 1 begin */
6604 dgap_err("unexpected config_begin\n");
6610 case BOARD: /* board info */
6611 if (dgap_checknode(p))
6613 p->next = dgap_newnode(BNODE);
6615 dgap_err("out of memory");
6620 p->u.board.status = dgap_savestring("No");
6626 case APORT2_920P: /* AccelePort_4 */
6627 if (p->type != BNODE) {
6628 dgap_err("unexpected Digi_2r_920 string");
6631 p->u.board.type = APORT2_920P;
6632 p->u.board.v_type = 1;
6635 case APORT4_920P: /* AccelePort_4 */
6636 if (p->type != BNODE) {
6637 dgap_err("unexpected Digi_4r_920 string");
6640 p->u.board.type = APORT4_920P;
6641 p->u.board.v_type = 1;
6644 case APORT8_920P: /* AccelePort_8 */
6645 if (p->type != BNODE) {
6646 dgap_err("unexpected Digi_8r_920 string");
6649 p->u.board.type = APORT8_920P;
6650 p->u.board.v_type = 1;
6653 case PAPORT4: /* AccelePort_4 PCI */
6654 if (p->type != BNODE) {
6655 dgap_err("unexpected Digi_4r(PCI) string");
6658 p->u.board.type = PAPORT4;
6659 p->u.board.v_type = 1;
6662 case PAPORT8: /* AccelePort_8 PCI */
6663 if (p->type != BNODE) {
6664 dgap_err("unexpected Digi_8r string");
6667 p->u.board.type = PAPORT8;
6668 p->u.board.v_type = 1;
6671 case PCX: /* PCI C/X */
6672 if (p->type != BNODE) {
6673 dgap_err("unexpected Digi_C/X_(PCI) string");
6676 p->u.board.type = PCX;
6677 p->u.board.v_type = 1;
6678 p->u.board.conc1 = 0;
6679 p->u.board.conc2 = 0;
6680 p->u.board.module1 = 0;
6681 p->u.board.module2 = 0;
6684 case PEPC: /* PCI EPC/X */
6685 if (p->type != BNODE) {
6686 dgap_err("unexpected \"Digi_EPC/X_(PCI)\" string");
6689 p->u.board.type = PEPC;
6690 p->u.board.v_type = 1;
6691 p->u.board.conc1 = 0;
6692 p->u.board.conc2 = 0;
6693 p->u.board.module1 = 0;
6694 p->u.board.module2 = 0;
6697 case PPCM: /* PCI/Xem */
6698 if (p->type != BNODE) {
6699 dgap_err("unexpected PCI/Xem string");
6702 p->u.board.type = PPCM;
6703 p->u.board.v_type = 1;
6704 p->u.board.conc1 = 0;
6705 p->u.board.conc2 = 0;
6708 case IO: /* i/o port */
6709 if (p->type != BNODE) {
6710 dgap_err("IO port only vaild for boards");
6713 s = dgap_getword(in);
6715 dgap_err("unexpected end of file");
6718 p->u.board.portstr = dgap_savestring(s);
6719 p->u.board.port = (short)simple_strtol(s, &s2, 0);
6720 if ((short)strlen(s) > (short)(s2 - s)) {
6721 dgap_err("bad number for IO port");
6724 p->u.board.v_port = 1;
6727 case MEM: /* memory address */
6728 if (p->type != BNODE) {
6729 dgap_err("memory address only vaild for boards");
6732 s = dgap_getword(in);
6734 dgap_err("unexpected end of file");
6737 p->u.board.addrstr = dgap_savestring(s);
6738 p->u.board.addr = simple_strtoul(s, &s2, 0);
6739 if ((int)strlen(s) > (int)(s2 - s)) {
6740 dgap_err("bad number for memory address");
6743 p->u.board.v_addr = 1;
6746 case PCIINFO: /* pci information */
6747 if (p->type != BNODE) {
6748 dgap_err("memory address only vaild for boards");
6751 s = dgap_getword(in);
6753 dgap_err("unexpected end of file");
6756 p->u.board.pcibusstr = dgap_savestring(s);
6757 p->u.board.pcibus = simple_strtoul(s, &s2, 0);
6758 if ((int)strlen(s) > (int)(s2 - s)) {
6759 dgap_err("bad number for pci bus");
6762 p->u.board.v_pcibus = 1;
6763 s = dgap_getword(in);
6765 dgap_err("unexpected end of file");
6768 p->u.board.pcislotstr = dgap_savestring(s);
6769 p->u.board.pcislot = simple_strtoul(s, &s2, 0);
6770 if ((int)strlen(s) > (int)(s2 - s)) {
6771 dgap_err("bad number for pci slot");
6774 p->u.board.v_pcislot = 1;
6778 if (p->type != BNODE) {
6779 dgap_err("install method only vaild for boards");
6782 s = dgap_getword(in);
6784 dgap_err("unexpected end of file");
6787 p->u.board.method = dgap_savestring(s);
6788 p->u.board.v_method = 1;
6792 if (p->type != BNODE) {
6793 dgap_err("config status only vaild for boards");
6796 s = dgap_getword(in);
6798 dgap_err("unexpected end of file");
6801 p->u.board.status = dgap_savestring(s);
6804 case NPORTS: /* number of ports */
6805 if (p->type == BNODE) {
6806 s = dgap_getword(in);
6808 dgap_err("unexpected end of file");
6811 p->u.board.nport = (char)simple_strtol(s, &s2, 0);
6812 if ((int)strlen(s) > (int)(s2 - s)) {
6813 dgap_err("bad number for number of ports");
6816 p->u.board.v_nport = 1;
6817 } else if (p->type == CNODE) {
6818 s = dgap_getword(in);
6820 dgap_err("unexpected end of file");
6823 p->u.conc.nport = (char)simple_strtol(s, &s2, 0);
6824 if ((int)strlen(s) > (int)(s2 - s)) {
6825 dgap_err("bad number for number of ports");
6828 p->u.conc.v_nport = 1;
6829 } else if (p->type == MNODE) {
6830 s = dgap_getword(in);
6832 dgap_err("unexpected end of file");
6835 p->u.module.nport = (char)simple_strtol(s, &s2, 0);
6836 if ((int)strlen(s) > (int)(s2 - s)) {
6837 dgap_err("bad number for number of ports");
6840 p->u.module.v_nport = 1;
6842 dgap_err("nports only valid for concentrators or modules");
6847 case ID: /* letter ID used in tty name */
6848 s = dgap_getword(in);
6850 dgap_err("unexpected end of file");
6854 p->u.board.status = dgap_savestring(s);
6856 if (p->type == CNODE) {
6857 p->u.conc.id = dgap_savestring(s);
6859 } else if (p->type == MNODE) {
6860 p->u.module.id = dgap_savestring(s);
6861 p->u.module.v_id = 1;
6863 dgap_err("id only valid for concentrators or modules");
6868 case STARTO: /* start offset of ID */
6869 if (p->type == BNODE) {
6870 s = dgap_getword(in);
6872 dgap_err("unexpected end of file");
6875 p->u.board.start = simple_strtol(s, &s2, 0);
6876 if ((int)strlen(s) > (int)(s2 - s)) {
6877 dgap_err("bad number for start of tty count");
6880 p->u.board.v_start = 1;
6881 } else if (p->type == CNODE) {
6882 s = dgap_getword(in);
6884 dgap_err("unexpected end of file");
6887 p->u.conc.start = simple_strtol(s, &s2, 0);
6888 if ((int)strlen(s) > (int)(s2 - s)) {
6889 dgap_err("bad number for start of tty count");
6892 p->u.conc.v_start = 1;
6893 } else if (p->type == MNODE) {
6894 s = dgap_getword(in);
6896 dgap_err("unexpected end of file");
6899 p->u.module.start = simple_strtol(s, &s2, 0);
6900 if ((int)strlen(s) > (int)(s2 - s)) {
6901 dgap_err("bad number for start of tty count");
6904 p->u.module.v_start = 1;
6906 dgap_err("start only valid for concentrators or modules");
6911 case TTYN: /* tty name prefix */
6912 if (dgap_checknode(p))
6914 p->next = dgap_newnode(TNODE);
6916 dgap_err("out of memory");
6920 s = dgap_getword(in);
6922 dgap_err("unexpeced end of file");
6925 p->u.ttyname = dgap_savestring(s);
6926 if (!p->u.ttyname) {
6927 dgap_err("out of memory");
6932 case CU: /* cu name prefix */
6933 if (dgap_checknode(p))
6935 p->next = dgap_newnode(CUNODE);
6937 dgap_err("out of memory");
6941 s = dgap_getword(in);
6943 dgap_err("unexpeced end of file");
6946 p->u.cuname = dgap_savestring(s);
6948 dgap_err("out of memory");
6953 case LINE: /* line information */
6954 if (dgap_checknode(p))
6957 dgap_err("must specify board before line info");
6960 switch (brd->u.board.type) {
6962 dgap_err("line not vaild for PC/em");
6965 p->next = dgap_newnode(LNODE);
6967 dgap_err("out of memory");
6976 case CONC: /* concentrator information */
6977 if (dgap_checknode(p))
6980 dgap_err("must specify line info before concentrator");
6983 p->next = dgap_newnode(CNODE);
6985 dgap_err("out of memory");
6991 brd->u.board.conc2++;
6993 brd->u.board.conc1++;
6997 case CX: /* c/x type concentrator */
6998 if (p->type != CNODE) {
6999 dgap_err("cx only valid for concentrators");
7002 p->u.conc.type = CX;
7003 p->u.conc.v_type = 1;
7006 case EPC: /* epc type concentrator */
7007 if (p->type != CNODE) {
7008 dgap_err("cx only valid for concentrators");
7011 p->u.conc.type = EPC;
7012 p->u.conc.v_type = 1;
7015 case MOD: /* EBI module */
7016 if (dgap_checknode(p))
7019 dgap_err("must specify board info before EBI modules");
7022 switch (brd->u.board.type) {
7028 dgap_err("must specify concentrator info before EBI module");
7032 p->next = dgap_newnode(MNODE);
7034 dgap_err("out of memory");
7039 brd->u.board.module2++;
7041 brd->u.board.module1++;
7045 case PORTS: /* ports type EBI module */
7046 if (p->type != MNODE) {
7047 dgap_err("ports only valid for EBI modules");
7050 p->u.module.type = PORTS;
7051 p->u.module.v_type = 1;
7054 case MODEM: /* ports type EBI module */
7055 if (p->type != MNODE) {
7056 dgap_err("modem only valid for modem modules");
7059 p->u.module.type = MODEM;
7060 p->u.module.v_type = 1;
7064 if (p->type == LNODE) {
7065 s = dgap_getword(in);
7067 dgap_err("unexpected end of file");
7070 p->u.line.cable = dgap_savestring(s);
7071 p->u.line.v_cable = 1;
7075 case SPEED: /* sync line speed indication */
7076 if (p->type == LNODE) {
7077 s = dgap_getword(in);
7079 dgap_err("unexpected end of file");
7082 p->u.line.speed = (char)simple_strtol(s, &s2, 0);
7083 if ((short)strlen(s) > (short)(s2 - s)) {
7084 dgap_err("bad number for line speed");
7087 p->u.line.v_speed = 1;
7088 } else if (p->type == CNODE) {
7089 s = dgap_getword(in);
7091 dgap_err("unexpected end of file");
7094 p->u.conc.speed = (char)simple_strtol(s, &s2, 0);
7095 if ((short)strlen(s) > (short)(s2 - s)) {
7096 dgap_err("bad number for line speed");
7099 p->u.conc.v_speed = 1;
7101 dgap_err("speed valid only for lines or concentrators.");
7107 if (p->type == CNODE) {
7108 s = dgap_getword(in);
7110 dgap_err("unexpected end of file");
7113 p->u.conc.connect = dgap_savestring(s);
7114 p->u.conc.v_connect = 1;
7117 case PRINT: /* transparent print name prefix */
7118 if (dgap_checknode(p))
7120 p->next = dgap_newnode(PNODE);
7122 dgap_err("out of memory");
7126 s = dgap_getword(in);
7128 dgap_err("unexpeced end of file");
7131 p->u.printname = dgap_savestring(s);
7132 if (!p->u.printname) {
7133 dgap_err("out of memory");
7138 case CMAJOR: /* major number */
7139 if (dgap_checknode(p))
7141 p->next = dgap_newnode(JNODE);
7143 dgap_err("out of memory");
7147 s = dgap_getword(in);
7149 dgap_err("unexpected end of file");
7152 p->u.majornumber = simple_strtol(s, &s2, 0);
7153 if ((int)strlen(s) > (int)(s2 - s)) {
7154 dgap_err("bad number for major number");
7159 case ALTPIN: /* altpin setting */
7160 if (dgap_checknode(p))
7162 p->next = dgap_newnode(ANODE);
7164 dgap_err("out of memory");
7168 s = dgap_getword(in);
7170 dgap_err("unexpected end of file");
7173 p->u.altpin = simple_strtol(s, &s2, 0);
7174 if ((int)strlen(s) > (int)(s2 - s)) {
7175 dgap_err("bad number for altpin");
7180 case USEINTR: /* enable interrupt setting */
7181 if (dgap_checknode(p))
7183 p->next = dgap_newnode(INTRNODE);
7185 dgap_err("out of memory");
7189 s = dgap_getword(in);
7191 dgap_err("unexpected end of file");
7194 p->u.useintr = simple_strtol(s, &s2, 0);
7195 if ((int)strlen(s) > (int)(s2 - s)) {
7196 dgap_err("bad number for useintr");
7201 case TTSIZ: /* size of tty structure */
7202 if (dgap_checknode(p))
7204 p->next = dgap_newnode(TSNODE);
7206 dgap_err("out of memory");
7210 s = dgap_getword(in);
7212 dgap_err("unexpected end of file");
7215 p->u.ttysize = simple_strtol(s, &s2, 0);
7216 if ((int)strlen(s) > (int)(s2 - s)) {
7217 dgap_err("bad number for ttysize");
7222 case CHSIZ: /* channel structure size */
7223 if (dgap_checknode(p))
7225 p->next = dgap_newnode(CSNODE);
7227 dgap_err("out of memory");
7231 s = dgap_getword(in);
7233 dgap_err("unexpected end of file");
7236 p->u.chsize = simple_strtol(s, &s2, 0);
7237 if ((int)strlen(s) > (int)(s2 - s)) {
7238 dgap_err("bad number for chsize");
7243 case BSSIZ: /* board structure size */
7244 if (dgap_checknode(p))
7246 p->next = dgap_newnode(BSNODE);
7248 dgap_err("out of memory");
7252 s = dgap_getword(in);
7254 dgap_err("unexpected end of file");
7257 p->u.bssize = simple_strtol(s, &s2, 0);
7258 if ((int)strlen(s) > (int)(s2 - s)) {
7259 dgap_err("bad number for bssize");
7264 case UNTSIZ: /* sched structure size */
7265 if (dgap_checknode(p))
7267 p->next = dgap_newnode(USNODE);
7269 dgap_err("out of memory");
7273 s = dgap_getword(in);
7275 dgap_err("unexpected end of file");
7278 p->u.unsize = simple_strtol(s, &s2, 0);
7279 if ((int)strlen(s) > (int)(s2 - s)) {
7280 dgap_err("bad number for schedsize");
7285 case F2SIZ: /* f2200 structure size */
7286 if (dgap_checknode(p))
7288 p->next = dgap_newnode(FSNODE);
7290 dgap_err("out of memory");
7294 s = dgap_getword(in);
7296 dgap_err("unexpected end of file");
7299 p->u.f2size = simple_strtol(s, &s2, 0);
7300 if ((int)strlen(s) > (int)(s2 - s)) {
7301 dgap_err("bad number for f2200size");
7306 case VPSIZ: /* vpix structure size */
7307 if (dgap_checknode(p))
7309 p->next = dgap_newnode(VSNODE);
7311 dgap_err("out of memory");
7315 s = dgap_getword(in);
7317 dgap_err("unexpected end of file");
7320 p->u.vpixsize = simple_strtol(s, &s2, 0);
7321 if ((int)strlen(s) > (int)(s2 - s)) {
7322 dgap_err("bad number for vpixsize");
7331 * dgap_sindex: much like index(), but it looks for a match of any character in
7332 * the group, and returns that position. If the first character is a ^, then
7333 * this will match the first occurrence not in that group.
7335 static char *dgap_sindex(char *string, char *group)
7339 if (!string || !group)
7340 return (char *) NULL;
7342 if (*group == '^') {
7344 for (; *string; string++) {
7345 for (ptr = group; *ptr; ptr++) {
7346 if (*ptr == *string)
7353 for (; *string; string++) {
7354 for (ptr = group; *ptr; ptr++) {
7355 if (*ptr == *string)
7361 return (char *) NULL;
7365 * Get a token from the input file; return 0 if end of file is reached
7367 static int dgap_gettok(char **in, struct cnode *p)
7372 if (strstr(dgap_cword, "boar")) {
7373 w = dgap_getword(in);
7374 snprintf(dgap_cword, MAXCWORD, "%s", w);
7375 for (t = dgap_tlist; t->token != 0; t++) {
7376 if (!strcmp(w, t->string))
7379 dgap_err("board !!type not specified");
7382 while ((w = dgap_getword(in))) {
7383 snprintf(dgap_cword, MAXCWORD, "%s", w);
7384 for (t = dgap_tlist; t->token != 0; t++) {
7385 if (!strcmp(w, t->string))
7394 * get a word from the input stream, also keep track of current line number.
7395 * words are separated by whitespace.
7397 static char *dgap_getword(char **in)
7399 char *ret_ptr = *in;
7401 char *ptr = dgap_sindex(*in, " \t\n");
7403 /* If no word found, return null */
7407 /* Mark new location for our buffer */
7411 /* Eat any extra spaces/tabs/newlines that might be present */
7412 while (*in && **in && ((**in == ' ') ||
7423 * print an error message, giving the line number in the file where
7424 * the error occurred.
7426 static void dgap_err(char *s)
7428 pr_err("dgap: parse: %s\n", s);
7432 * allocate a new configuration node of type t
7434 static struct cnode *dgap_newnode(int t)
7438 n = kmalloc(sizeof(struct cnode), GFP_ATOMIC);
7440 memset((char *)n, 0, sizeof(struct cnode));
7447 * dgap_checknode: see if all the necessary info has been supplied for a node
7448 * before creating the next node.
7450 static int dgap_checknode(struct cnode *p)
7454 if (p->u.board.v_type == 0) {
7455 dgap_err("board type !not specified");
7462 if (p->u.line.v_speed == 0) {
7463 dgap_err("line speed not specified");
7469 if (p->u.conc.v_type == 0) {
7470 dgap_err("concentrator type not specified");
7473 if (p->u.conc.v_speed == 0) {
7474 dgap_err("concentrator line speed not specified");
7477 if (p->u.conc.v_nport == 0) {
7478 dgap_err("number of ports on concentrator not specified");
7481 if (p->u.conc.v_id == 0) {
7482 dgap_err("concentrator id letter not specified");
7488 if (p->u.module.v_type == 0) {
7489 dgap_err("EBI module type not specified");
7492 if (p->u.module.v_nport == 0) {
7493 dgap_err("number of ports on EBI module not specified");
7496 if (p->u.module.v_id == 0) {
7497 dgap_err("EBI module id letter not specified");
7506 * save a string somewhere
7508 static char *dgap_savestring(char *s)
7512 p = kmalloc(strlen(s) + 1, GFP_ATOMIC);
7519 * Given a board pointer, returns whether we should use interrupts or not.
7521 static uint dgap_config_get_useintr(struct board_t *bd)
7523 struct cnode *p = NULL;
7528 for (p = bd->bd_config; p; p = p->next) {
7532 * check for pcxr types.
7534 return p->u.useintr;
7540 /* If not found, then don't turn on interrupts. */
7545 * Given a board pointer, returns whether we turn on altpin or not.
7547 static uint dgap_config_get_altpin(struct board_t *bd)
7549 struct cnode *p = NULL;
7554 for (p = bd->bd_config; p; p = p->next) {
7558 * check for pcxr types.
7566 /* If not found, then don't turn on interrupts. */
7571 * Given a specific type of board, if found, detached link and
7572 * returns the first occurrence in the list.
7574 static struct cnode *dgap_find_config(int type, int bus, int slot)
7576 struct cnode *p, *prev = NULL, *prev2 = NULL, *found = NULL;
7580 while (p->next != NULL) {
7584 if (p->type == BNODE) {
7586 if (p->u.board.type == type) {
7588 if (p->u.board.v_pcibus &&
7589 p->u.board.pcibus != bus)
7591 if (p->u.board.v_pcislot &&
7592 p->u.board.pcislot != slot)
7597 * Keep walking thru the list till we
7598 * find the next board.
7600 while (p->next != NULL) {
7603 if (p->type == BNODE) {
7606 * Mark the end of our 1 board
7612 * Link the "next" board to the
7613 * previous board, effectively
7614 * "unlinking" our board from
7623 * It must be the last board in the list.
7634 * Given a board pointer, walks the config link, counting up
7635 * all ports user specified should be on the board.
7636 * (This does NOT mean they are all actually present right now tho)
7638 static uint dgap_config_get_number_of_ports(struct board_t *bd)
7641 struct cnode *p = NULL;
7646 for (p = bd->bd_config; p; p = p->next) {
7651 * check for pcxr types.
7653 if (p->u.board.type > EPCFE)
7654 count += p->u.board.nport;
7657 count += p->u.conc.nport;
7660 count += p->u.module.nport;
7667 static char *dgap_create_config_string(struct board_t *bd, char *string)
7670 struct cnode *p = NULL;
7671 struct cnode *q = NULL;
7679 for (p = bd->bd_config; p; p = p->next) {
7685 *ptr = p->u.line.speed;
7690 * Because the EPC/con concentrators can have EM modules
7691 * hanging off of them, we have to walk ahead in the
7692 * list and keep adding the number of ports on each EM
7693 * to the config. UGH!
7695 speed = p->u.conc.speed;
7697 if ((q != NULL) && (q->type == MNODE)) {
7698 *ptr = (p->u.conc.nport + 0x80);
7701 while ((q->next != NULL) &&
7702 (q->next->type) == MNODE) {
7704 *ptr = (q->u.module.nport + 0x80);
7709 *ptr = q->u.module.nport;
7712 *ptr = p->u.conc.nport;