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 int dgap_do_wait_for_bios(struct board_t *brd);
225 static int 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);
749 brd->inhibit_poller = FALSE;
750 brd->wait_for_bios = 0;
751 brd->wait_for_fep = 0;
753 for (i = 0; i < MAXPORTS; i++)
754 brd->channels[i] = NULL;
756 /* store which card & revision we have */
757 pci_read_config_word(pdev, PCI_SUBSYSTEM_VENDOR_ID, &brd->subvendor);
758 pci_read_config_word(pdev, PCI_SUBSYSTEM_ID, &brd->subdevice);
759 pci_read_config_byte(pdev, PCI_REVISION_ID, &brd->rev);
764 /* get the PCI Base Address Registers */
766 /* Xr Jupiter and EPC use BAR 2 */
767 if (brd->device == PCI_DEV_XRJ_DID || brd->device == PCI_DEV_EPCJ_DID) {
768 brd->membase = pci_resource_start(pdev, 2);
769 brd->membase_end = pci_resource_end(pdev, 2);
771 /* Everyone else uses BAR 0 */
773 brd->membase = pci_resource_start(pdev, 0);
774 brd->membase_end = pci_resource_end(pdev, 0);
780 if (brd->membase & 1)
786 * On the PCI boards, there is no IO space allocated
787 * The I/O registers will be in the first 3 bytes of the
788 * upper 2MB of the 4MB memory space. The board memory
789 * will be mapped into the low 2MB of the 4MB memory space
791 brd->port = brd->membase + PCI_IO_OFFSET;
792 brd->port_end = brd->port + PCI_IO_SIZE;
795 * Special initialization for non-PLX boards
797 if (brd->device != PCI_DEV_XRJ_DID && brd->device != PCI_DEV_EPCJ_DID) {
800 pci_write_config_byte(pdev, 0x40, 0);
801 pci_write_config_byte(pdev, 0x46, 0);
803 /* Limit burst length to 2 doubleword transactions */
804 pci_write_config_byte(pdev, 0x42, 1);
807 * Enable IO and mem if not already done.
808 * This was needed for support on Itanium.
810 pci_read_config_word(pdev, PCI_COMMAND, &cmd);
811 cmd |= (PCI_COMMAND_IO | PCI_COMMAND_MEMORY);
812 pci_write_config_word(pdev, PCI_COMMAND, cmd);
815 /* init our poll helper tasklet */
816 tasklet_init(&brd->helper_tasklet, dgap_poll_tasklet,
817 (unsigned long) brd);
819 i = dgap_do_remap(brd);
821 brd->state = BOARD_FAILED;
827 static int dgap_finalize_board_init(struct board_t *brd)
831 if (!brd || brd->magic != DGAP_BOARD_MAGIC)
834 brd->use_interrupts = dgap_config_get_useintr(brd);
837 * Set up our interrupt handler if we are set to do interrupts.
839 if (brd->use_interrupts && brd->irq) {
841 rc = request_irq(brd->irq, dgap_intr, IRQF_SHARED, "DGAP", brd);
854 static int dgap_firmware_load(struct pci_dev *pdev, int card_type)
856 struct board_t *brd = dgap_Board[dgap_NumBoards - 1];
857 const struct firmware *fw;
861 dgap_do_reset_board(brd);
863 if (fw_info[card_type].conf_name) {
864 ret = request_firmware(&fw, fw_info[card_type].conf_name,
867 pr_err("dgap: config file %s not found\n",
868 fw_info[card_type].conf_name);
871 if (!dgap_config_buf) {
872 dgap_config_buf = kmalloc(fw->size + 1, GFP_ATOMIC);
873 if (!dgap_config_buf) {
874 release_firmware(fw);
879 memcpy(dgap_config_buf, fw->data, fw->size);
880 release_firmware(fw);
881 dgap_config_buf[fw->size + 1] = '\0';
883 if (dgap_parsefile(&dgap_config_buf, TRUE) != 0)
887 ret = dgap_after_config_loaded(brd->boardnum);
891 * Match this board to a config the user created for us.
894 dgap_find_config(brd->type, brd->pci_bus, brd->pci_slot);
897 * Because the 4 port Xr products share the same PCI ID
898 * as the 8 port Xr products, if we receive a NULL config
899 * back, and this is a PAPORT8 board, retry with a
900 * PAPORT4 attempt as well.
902 if (brd->type == PAPORT8 && !brd->bd_config)
904 dgap_find_config(PAPORT4, brd->pci_bus, brd->pci_slot);
906 if (!brd->bd_config) {
907 pr_err("dgap: No valid configuration found\n");
911 dgap_tty_register(brd);
912 dgap_finalize_board_init(brd);
914 if (fw_info[card_type].bios_name) {
915 ret = request_firmware(&fw, fw_info[card_type].bios_name,
918 pr_err("dgap: bios file %s not found\n",
919 fw_info[card_type].bios_name);
922 dgap_do_bios_load(brd, (char *)fw->data, fw->size);
923 release_firmware(fw);
925 /* Wait for BIOS to test board... */
926 if (!dgap_do_wait_for_bios(brd))
930 if (fw_info[card_type].fep_name) {
931 ret = request_firmware(&fw, fw_info[card_type].fep_name,
934 pr_err("dgap: fep file %s not found\n",
935 fw_info[card_type].fep_name);
938 dgap_do_fep_load(brd, (char *)fw->data, fw->size);
939 release_firmware(fw);
941 /* Wait for FEP to load on board... */
942 if (!dgap_do_wait_for_fep(brd))
946 #ifdef DIGI_CONCENTRATORS_SUPPORTED
948 * If this is a CX or EPCX, we need to see if the firmware
949 * is requesting a concentrator image from us.
951 if ((bd->type == PCX) || (bd->type == PEPC)) {
952 chk_addr = (u16 *) (vaddr + DOWNREQ);
953 /* Nonzero if FEP is requesting concentrator image. */
954 check = readw(chk_addr);
955 vaddr = brd->re_map_membase;
958 if (fw_info[card_type].con_name && check && vaddr) {
959 ret = request_firmware(&fw, fw_info[card_type].con_name,
962 pr_err("dgap: conc file %s not found\n",
963 fw_info[card_type].con_name);
966 /* Put concentrator firmware loading code here */
967 offset = readw((u16 *) (vaddr + DOWNREQ));
968 memcpy_toio(offset, fw->data, fw->size);
970 dgap_do_conc_load(brd, (char *)fw->data, fw->size)
971 release_firmware(fw);
975 * Do tty device initialization.
977 ret = dgap_tty_init(brd);
979 dgap_tty_uninit(brd);
983 ret = dgap_tty_register_ports(brd);
987 brd->state = BOARD_READY;
988 brd->dpastatus = BD_RUNNING;
996 static int dgap_do_remap(struct board_t *brd)
998 if (!brd || brd->magic != DGAP_BOARD_MAGIC)
1001 if (!request_mem_region(brd->membase, 0x200000, "dgap"))
1004 if (!request_mem_region(brd->membase + PCI_IO_OFFSET, 0x200000,
1006 release_mem_region(brd->membase, 0x200000);
1010 brd->re_map_membase = ioremap(brd->membase, 0x200000);
1011 if (!brd->re_map_membase) {
1012 release_mem_region(brd->membase, 0x200000);
1013 release_mem_region(brd->membase + PCI_IO_OFFSET, 0x200000);
1017 brd->re_map_port = ioremap((brd->membase + PCI_IO_OFFSET), 0x200000);
1018 if (!brd->re_map_port) {
1019 release_mem_region(brd->membase, 0x200000);
1020 release_mem_region(brd->membase + PCI_IO_OFFSET, 0x200000);
1021 iounmap(brd->re_map_membase);
1028 /*****************************************************************************
1048 * As each timer expires, it determines (a) whether the "transmit"
1049 * waiter needs to be woken up, and (b) whether the poller needs to
1052 ******************************************************************************/
1054 static void dgap_poll_handler(ulong dummy)
1057 struct board_t *brd;
1058 unsigned long lock_flags;
1061 dgap_poll_counter++;
1064 * Do not start the board state machine until
1065 * driver tells us its up and running, and has
1066 * everything it needs.
1068 if (dgap_driver_state != DRIVER_READY)
1069 goto schedule_poller;
1072 * If we have just 1 board, or the system is not SMP,
1073 * then use the typical old style poller.
1074 * Otherwise, use our new tasklet based poller, which should
1075 * speed things up for multiple boards.
1077 if ((dgap_NumBoards == 1) || (num_online_cpus() <= 1)) {
1078 for (i = 0; i < dgap_NumBoards; i++) {
1080 brd = dgap_Board[i];
1082 if (brd->state == BOARD_FAILED)
1084 if (!brd->intr_running)
1085 /* Call the real board poller directly */
1086 dgap_poll_tasklet((unsigned long) brd);
1090 * Go thru each board, kicking off a
1091 * tasklet for each if needed
1093 for (i = 0; i < dgap_NumBoards; i++) {
1094 brd = dgap_Board[i];
1097 * Attempt to grab the board lock.
1099 * If we can't get it, no big deal, the next poll
1100 * will get it. Basically, I just really don't want
1101 * to spin in here, because I want to kick off my
1102 * tasklets as fast as I can, and then get out the
1105 if (!spin_trylock(&brd->bd_lock))
1109 * If board is in a failed state, don't bother
1110 * scheduling a tasklet
1112 if (brd->state == BOARD_FAILED) {
1113 spin_unlock(&brd->bd_lock);
1117 /* Schedule a poll helper task */
1118 if (!brd->intr_running)
1119 tasklet_schedule(&brd->helper_tasklet);
1122 * Can't do DGAP_UNLOCK here, as we don't have
1123 * lock_flags because we did a trylock above.
1125 spin_unlock(&brd->bd_lock);
1132 * Schedule ourself back at the nominal wakeup interval.
1134 DGAP_LOCK(dgap_poll_lock, lock_flags);
1135 dgap_poll_time += dgap_jiffies_from_ms(dgap_poll_tick);
1137 new_time = dgap_poll_time - jiffies;
1139 if ((ulong) new_time >= 2 * dgap_poll_tick) {
1141 jiffies + dgap_jiffies_from_ms(dgap_poll_tick);
1144 dgap_poll_timer.function = dgap_poll_handler;
1145 dgap_poll_timer.data = 0;
1146 dgap_poll_timer.expires = dgap_poll_time;
1147 DGAP_UNLOCK(dgap_poll_lock, lock_flags);
1149 if (!dgap_poll_stop)
1150 add_timer(&dgap_poll_timer);
1156 * Driver interrupt handler.
1158 static irqreturn_t dgap_intr(int irq, void *voidbrd)
1160 struct board_t *brd = (struct board_t *) voidbrd;
1166 * Check to make sure its for us.
1168 if (brd->magic != DGAP_BOARD_MAGIC)
1174 * Schedule tasklet to run at a better time.
1176 tasklet_schedule(&brd->helper_tasklet);
1181 * dgap_init_globals()
1183 * This is where we initialize the globals from the static insmod
1184 * configuration variables. These are declared near the head of
1187 static void dgap_init_globals(void)
1191 for (i = 0; i < MAXBOARDS; i++)
1192 dgap_Board[i] = NULL;
1194 init_timer(&dgap_poll_timer);
1196 init_waitqueue_head(&dgap_dl_wait);
1200 /************************************************************************
1204 ************************************************************************/
1209 * Put the driver to sleep for x ms's
1211 * Returns 0 if timed out, !0 (showing signal) if interrupted by a signal.
1213 static int dgap_ms_sleep(ulong ms)
1215 current->state = TASK_INTERRUPTIBLE;
1216 schedule_timeout((ms * HZ) / 1000);
1217 return signal_pending(current);
1220 /************************************************************************
1222 * TTY Initialization/Cleanup Functions
1224 ************************************************************************/
1227 * dgap_tty_register()
1229 * Init the tty subsystem for this board.
1231 static int dgap_tty_register(struct board_t *brd)
1235 brd->SerialDriver = alloc_tty_driver(MAXPORTS);
1237 snprintf(brd->SerialName, MAXTTYNAMELEN, "tty_dgap_%d_", brd->boardnum);
1238 brd->SerialDriver->name = brd->SerialName;
1239 brd->SerialDriver->name_base = 0;
1240 brd->SerialDriver->major = 0;
1241 brd->SerialDriver->minor_start = 0;
1242 brd->SerialDriver->type = TTY_DRIVER_TYPE_SERIAL;
1243 brd->SerialDriver->subtype = SERIAL_TYPE_NORMAL;
1244 brd->SerialDriver->init_termios = DgapDefaultTermios;
1245 brd->SerialDriver->driver_name = DRVSTR;
1246 brd->SerialDriver->flags = (TTY_DRIVER_REAL_RAW |
1247 TTY_DRIVER_DYNAMIC_DEV |
1248 TTY_DRIVER_HARDWARE_BREAK);
1250 /* The kernel wants space to store pointers to tty_structs */
1251 brd->SerialDriver->ttys =
1252 kzalloc(MAXPORTS * sizeof(struct tty_struct *), GFP_KERNEL);
1253 if (!brd->SerialDriver->ttys)
1257 * Entry points for driver. Called by the kernel from
1258 * tty_io.c and n_tty.c.
1260 tty_set_operations(brd->SerialDriver, &dgap_tty_ops);
1263 * If we're doing transparent print, we have to do all of the above
1264 * again, separately so we don't get the LD confused about what major
1265 * we are when we get into the dgap_tty_open() routine.
1267 brd->PrintDriver = alloc_tty_driver(MAXPORTS);
1269 snprintf(brd->PrintName, MAXTTYNAMELEN, "pr_dgap_%d_", brd->boardnum);
1270 brd->PrintDriver->name = brd->PrintName;
1271 brd->PrintDriver->name_base = 0;
1272 brd->PrintDriver->major = 0;
1273 brd->PrintDriver->minor_start = 0;
1274 brd->PrintDriver->type = TTY_DRIVER_TYPE_SERIAL;
1275 brd->PrintDriver->subtype = SERIAL_TYPE_NORMAL;
1276 brd->PrintDriver->init_termios = DgapDefaultTermios;
1277 brd->PrintDriver->driver_name = DRVSTR;
1278 brd->PrintDriver->flags = (TTY_DRIVER_REAL_RAW |
1279 TTY_DRIVER_DYNAMIC_DEV |
1280 TTY_DRIVER_HARDWARE_BREAK);
1282 /* The kernel wants space to store pointers to tty_structs */
1283 brd->PrintDriver->ttys =
1284 kzalloc(MAXPORTS * sizeof(struct tty_struct *), GFP_KERNEL);
1285 if (!brd->PrintDriver->ttys)
1289 * Entry points for driver. Called by the kernel from
1290 * tty_io.c and n_tty.c.
1292 tty_set_operations(brd->PrintDriver, &dgap_tty_ops);
1294 if (!brd->dgap_Major_Serial_Registered) {
1295 /* Register tty devices */
1296 rc = tty_register_driver(brd->SerialDriver);
1299 brd->dgap_Major_Serial_Registered = TRUE;
1300 dgap_BoardsByMajor[brd->SerialDriver->major] = brd;
1301 brd->dgap_Serial_Major = brd->SerialDriver->major;
1304 if (!brd->dgap_Major_TransparentPrint_Registered) {
1305 /* Register Transparent Print devices */
1306 rc = tty_register_driver(brd->PrintDriver);
1309 brd->dgap_Major_TransparentPrint_Registered = TRUE;
1310 dgap_BoardsByMajor[brd->PrintDriver->major] = brd;
1311 brd->dgap_TransparentPrint_Major = brd->PrintDriver->major;
1320 * Init the tty subsystem. Called once per board after board has been
1321 * downloaded and init'ed.
1323 static int dgap_tty_init(struct board_t *brd)
1327 uint true_count = 0;
1330 struct channel_t *ch;
1338 * Initialize board structure elements.
1341 vaddr = brd->re_map_membase;
1342 true_count = readw((vaddr + NCHAN));
1344 brd->nasync = dgap_config_get_number_of_ports(brd);
1347 brd->nasync = brd->maxports;
1349 if (brd->nasync > brd->maxports)
1350 brd->nasync = brd->maxports;
1352 if (true_count != brd->nasync) {
1353 if ((brd->type == PPCM) && (true_count == 64)) {
1354 pr_warn("dgap: %s configured for %d ports, has %d ports.\n",
1355 brd->name, brd->nasync, true_count);
1356 pr_warn("dgap: Please make SURE the EBI cable running from the card\n");
1357 pr_warn("dgap: to each EM module is plugged into EBI IN!\n");
1358 } else if ((brd->type == PPCM) && (true_count == 0)) {
1359 pr_warn("dgap: %s configured for %d ports, has %d ports.\n",
1360 brd->name, brd->nasync, true_count);
1361 pr_warn("dgap: Please make SURE the EBI cable running from the card\n");
1362 pr_warn("dgap: to each EM module is plugged into EBI IN!\n");
1364 pr_warn("dgap: %s configured for %d ports, has %d ports.\n",
1365 brd->name, brd->nasync, true_count);
1367 brd->nasync = true_count;
1369 /* If no ports, don't bother going any further */
1371 brd->state = BOARD_FAILED;
1372 brd->dpastatus = BD_NOFEP;
1378 * Allocate channel memory that might not have been allocated
1379 * when the driver was first loaded.
1381 for (i = 0; i < brd->nasync; i++) {
1382 if (!brd->channels[i]) {
1384 kzalloc(sizeof(struct channel_t), GFP_ATOMIC);
1385 if (!brd->channels[i])
1390 ch = brd->channels[0];
1391 vaddr = brd->re_map_membase;
1393 bs = (struct bs_t *) ((ulong) vaddr + CHANBUF);
1394 cm = (struct cm_t *) ((ulong) vaddr + CMDBUF);
1398 /* Set up channel variables */
1399 for (i = 0; i < brd->nasync; i++, ch = brd->channels[i], bs++) {
1401 if (!brd->channels[i])
1404 spin_lock_init(&ch->ch_lock);
1406 /* Store all our magic numbers */
1407 ch->magic = DGAP_CHANNEL_MAGIC;
1408 ch->ch_tun.magic = DGAP_UNIT_MAGIC;
1409 ch->ch_tun.un_type = DGAP_SERIAL;
1410 ch->ch_tun.un_ch = ch;
1411 ch->ch_tun.un_dev = i;
1413 ch->ch_pun.magic = DGAP_UNIT_MAGIC;
1414 ch->ch_pun.un_type = DGAP_PRINT;
1415 ch->ch_pun.un_ch = ch;
1416 ch->ch_pun.un_dev = i;
1418 ch->ch_vaddr = vaddr;
1423 ch->ch_digi = dgap_digi_init;
1426 * Set up digi dsr and dcd bits based on altpin flag.
1428 if (dgap_config_get_altpin(brd)) {
1431 ch->ch_digi.digi_flags |= DIGI_ALTPIN;
1434 ch->ch_dsr = DM_DSR;
1437 ch->ch_taddr = vaddr + ((ch->ch_bs->tx_seg) << 4);
1438 ch->ch_raddr = vaddr + ((ch->ch_bs->rx_seg) << 4);
1441 ch->ch_tsize = readw(&(ch->ch_bs->tx_max)) + 1;
1442 ch->ch_rsize = readw(&(ch->ch_bs->rx_max)) + 1;
1446 /* .25 second delay */
1447 ch->ch_close_delay = 250;
1450 * Set queue water marks, interrupt mask,
1451 * and general tty parameters.
1453 tlw = ch->ch_tsize >= 2000 ? ((ch->ch_tsize * 5) / 8) :
1457 dgap_cmdw(ch, STLOW, tlw, 0);
1459 dgap_cmdw(ch, SRLOW, ch->ch_rsize / 2, 0);
1461 dgap_cmdw(ch, SRHIGH, 7 * ch->ch_rsize / 8, 0);
1463 ch->ch_mistat = readb(&(ch->ch_bs->m_stat));
1465 init_waitqueue_head(&ch->ch_flags_wait);
1466 init_waitqueue_head(&ch->ch_tun.un_flags_wait);
1467 init_waitqueue_head(&ch->ch_pun.un_flags_wait);
1468 init_waitqueue_head(&ch->ch_sniff_wait);
1470 /* Turn on all modem interrupts for now */
1471 modem = (DM_CD | DM_DSR | DM_CTS | DM_RI);
1472 writeb(modem, &(ch->ch_bs->m_int));
1475 * Set edelay to 0 if interrupts are turned on,
1476 * otherwise set edelay to the usual 100.
1479 writew(0, &(ch->ch_bs->edelay));
1481 writew(100, &(ch->ch_bs->edelay));
1483 writeb(1, &(ch->ch_bs->idata));
1492 * Uninitialize the TTY portion of this driver. Free all memory and
1495 static void dgap_tty_uninit(struct board_t *brd)
1500 if (brd->dgap_Major_Serial_Registered) {
1501 dgap_BoardsByMajor[brd->SerialDriver->major] = NULL;
1502 brd->dgap_Serial_Major = 0;
1503 for (i = 0; i < brd->nasync; i++) {
1504 tty_port_destroy(&brd->SerialPorts[i]);
1505 dev = brd->channels[i]->ch_tun.un_sysfs;
1506 dgap_remove_tty_sysfs(dev);
1507 tty_unregister_device(brd->SerialDriver, i);
1509 tty_unregister_driver(brd->SerialDriver);
1510 kfree(brd->SerialDriver->ttys);
1511 brd->SerialDriver->ttys = NULL;
1512 put_tty_driver(brd->SerialDriver);
1513 kfree(brd->SerialPorts);
1514 brd->dgap_Major_Serial_Registered = FALSE;
1517 if (brd->dgap_Major_TransparentPrint_Registered) {
1518 dgap_BoardsByMajor[brd->PrintDriver->major] = NULL;
1519 brd->dgap_TransparentPrint_Major = 0;
1520 for (i = 0; i < brd->nasync; i++) {
1521 tty_port_destroy(&brd->PrinterPorts[i]);
1522 dev = brd->channels[i]->ch_pun.un_sysfs;
1523 dgap_remove_tty_sysfs(dev);
1524 tty_unregister_device(brd->PrintDriver, i);
1526 tty_unregister_driver(brd->PrintDriver);
1527 kfree(brd->PrintDriver->ttys);
1528 brd->PrintDriver->ttys = NULL;
1529 put_tty_driver(brd->PrintDriver);
1530 kfree(brd->PrinterPorts);
1531 brd->dgap_Major_TransparentPrint_Registered = FALSE;
1535 #define TMPBUFLEN (1024)
1537 * dgap_sniff - Dump data out to the "sniff" buffer if the
1538 * proc sniff file is opened...
1540 static void dgap_sniff_nowait_nolock(struct channel_t *ch, uchar *text,
1541 uchar *buf, int len)
1549 char tmpbuf[TMPBUFLEN];
1553 /* Leave if sniff not open */
1554 if (!(ch->ch_sniff_flags & SNIFF_OPEN))
1557 do_gettimeofday(&tv);
1559 /* Create our header for data dump */
1560 p += sprintf(p, "<%ld %ld><%s><", tv.tv_sec, tv.tv_usec, text);
1561 tmpbuflen = p - tmpbuf;
1566 for (i = 0; i < len && tmpbuflen < (TMPBUFLEN - 4); i++) {
1567 p += sprintf(p, "%02x ", *buf);
1569 tmpbuflen = p - tmpbuf;
1572 if (tmpbuflen < (TMPBUFLEN - 4)) {
1574 p += sprintf(p - 1, "%s\n", ">");
1576 p += sprintf(p, "%s\n", ">");
1582 nbuf = strlen(tmpbuf);
1586 * Loop while data remains.
1588 while (nbuf > 0 && ch->ch_sniff_buf) {
1590 * Determine the amount of available space left in the
1591 * buffer. If there's none, wait until some appears.
1593 n = (ch->ch_sniff_out - ch->ch_sniff_in - 1) &
1597 * If there is no space left to write to in our sniff
1598 * buffer, we have no choice but to drop the data.
1599 * We *cannot* sleep here waiting for space, because
1600 * this function was probably called by the
1601 * interrupt/timer routines!
1607 * Copy as much data as will fit.
1613 r = SNIFF_MAX - ch->ch_sniff_in;
1616 memcpy(ch->ch_sniff_buf +
1617 ch->ch_sniff_in, p, r);
1620 ch->ch_sniff_in = 0;
1625 memcpy(ch->ch_sniff_buf + ch->ch_sniff_in, p, n);
1627 ch->ch_sniff_in += n;
1632 * Wakeup any thread waiting for data
1634 if (ch->ch_sniff_flags & SNIFF_WAIT_DATA) {
1635 ch->ch_sniff_flags &= ~SNIFF_WAIT_DATA;
1636 wake_up_interruptible(&ch->ch_sniff_wait);
1641 * If the user sent us too much data to push into our tmpbuf,
1642 * we need to keep looping around on all the data.
1644 if (too_much_data) {
1649 } while (too_much_data);
1652 /*=======================================================================
1654 * dgap_input - Process received data.
1656 * ch - Pointer to channel structure.
1658 *=======================================================================*/
1660 static void dgap_input(struct channel_t *ch)
1664 struct tty_struct *tp;
1665 struct tty_ldisc *ld;
1679 if (!ch || ch->magic != DGAP_CHANNEL_MAGIC)
1682 tp = ch->ch_tun.un_tty;
1689 if (!bd || bd->magic != DGAP_BOARD_MAGIC)
1692 DGAP_LOCK(bd->bd_lock, lock_flags);
1693 DGAP_LOCK(ch->ch_lock, lock_flags2);
1696 * Figure the number of characters in the buffer.
1697 * Exit immediately if none.
1700 rmask = ch->ch_rsize - 1;
1702 head = readw(&(bs->rx_head));
1704 tail = readw(&(bs->rx_tail));
1707 data_len = (head - tail) & rmask;
1709 if (data_len == 0) {
1710 writeb(1, &(bs->idata));
1711 DGAP_UNLOCK(ch->ch_lock, lock_flags2);
1712 DGAP_UNLOCK(bd->bd_lock, lock_flags);
1717 * If the device is not open, or CREAD is off, flush
1718 * input data and return immediately.
1720 if ((bd->state != BOARD_READY) || !tp ||
1721 (tp->magic != TTY_MAGIC) ||
1722 !(ch->ch_tun.un_flags & UN_ISOPEN) ||
1723 !(tp->termios.c_cflag & CREAD) ||
1724 (ch->ch_tun.un_flags & UN_CLOSING)) {
1726 writew(head, &(bs->rx_tail));
1727 writeb(1, &(bs->idata));
1728 DGAP_UNLOCK(ch->ch_lock, lock_flags2);
1729 DGAP_UNLOCK(bd->bd_lock, lock_flags);
1734 * If we are throttled, simply don't read any data.
1736 if (ch->ch_flags & CH_RXBLOCK) {
1737 writeb(1, &(bs->idata));
1738 DGAP_UNLOCK(ch->ch_lock, lock_flags2);
1739 DGAP_UNLOCK(bd->bd_lock, lock_flags);
1746 tmpchar = readb(&(bs->orun));
1748 ch->ch_err_overrun++;
1749 writeb(0, &(bs->orun));
1752 /* Decide how much data we can send into the tty layer */
1753 flip_len = TTY_FLIPBUF_SIZE;
1755 /* Chop down the length, if needed */
1756 len = min(data_len, flip_len);
1757 len = min(len, (N_TTY_BUF_SIZE - 1));
1759 ld = tty_ldisc_ref(tp);
1761 #ifdef TTY_DONT_FLIP
1763 * If the DONT_FLIP flag is on, don't flush our buffer, and act
1764 * like the ld doesn't have any space to put the data right now.
1766 if (test_bit(TTY_DONT_FLIP, &tp->flags))
1771 * If we were unable to get a reference to the ld,
1772 * don't flush our buffer, and act like the ld doesn't
1773 * have any space to put the data right now.
1779 * If ld doesn't have a pointer to a receive_buf function,
1780 * flush the data, then act like the ld doesn't have any
1781 * space to put the data right now.
1783 if (!ld->ops->receive_buf) {
1784 writew(head, &(bs->rx_tail));
1790 writeb(1, &(bs->idata));
1791 DGAP_UNLOCK(ch->ch_lock, lock_flags2);
1792 DGAP_UNLOCK(bd->bd_lock, lock_flags);
1794 tty_ldisc_deref(ld);
1798 buf = ch->ch_bd->flipbuf;
1802 * n now contains the most amount of data we can copy,
1803 * bounded either by our buffer size or the amount
1804 * of data the card actually has pending...
1808 s = ((head >= tail) ? head : ch->ch_rsize) - tail;
1814 memcpy_fromio(buf, (char *) ch->ch_raddr + tail, s);
1815 dgap_sniff_nowait_nolock(ch, "USER READ", buf, s);
1821 /* Flip queue if needed */
1825 writew(tail, &(bs->rx_tail));
1826 writeb(1, &(bs->idata));
1827 ch->ch_rxcount += len;
1830 * If we are completely raw, we don't need to go through a lot
1831 * of the tty layers that exist.
1832 * In this case, we take the shortest and fastest route we
1833 * can to relay the data to the user.
1835 * On the other hand, if we are not raw, we need to go through
1836 * the tty layer, which has its API more well defined.
1838 if (I_PARMRK(tp) || I_BRKINT(tp) || I_INPCK(tp)) {
1839 dgap_parity_scan(ch, ch->ch_bd->flipbuf,
1840 ch->ch_bd->flipflagbuf, &len);
1842 len = tty_buffer_request_room(tp->port, len);
1843 tty_insert_flip_string_flags(tp->port, ch->ch_bd->flipbuf,
1844 ch->ch_bd->flipflagbuf, len);
1846 len = tty_buffer_request_room(tp->port, len);
1847 tty_insert_flip_string(tp->port, ch->ch_bd->flipbuf, len);
1850 DGAP_UNLOCK(ch->ch_lock, lock_flags2);
1851 DGAP_UNLOCK(bd->bd_lock, lock_flags);
1853 /* Tell the tty layer its okay to "eat" the data now */
1854 tty_flip_buffer_push(tp->port);
1857 tty_ldisc_deref(ld);
1861 /************************************************************************
1862 * Determines when CARRIER changes state and takes appropriate
1864 ************************************************************************/
1865 static void dgap_carrier(struct channel_t *ch)
1869 int virt_carrier = 0;
1870 int phys_carrier = 0;
1872 if (!ch || ch->magic != DGAP_CHANNEL_MAGIC)
1877 if (!bd || bd->magic != DGAP_BOARD_MAGIC)
1880 /* Make sure altpin is always set correctly */
1881 if (ch->ch_digi.digi_flags & DIGI_ALTPIN) {
1885 ch->ch_dsr = DM_DSR;
1889 if (ch->ch_mistat & D_CD(ch))
1892 if (ch->ch_digi.digi_flags & DIGI_FORCEDCD)
1895 if (ch->ch_c_cflag & CLOCAL)
1899 * Test for a VIRTUAL carrier transition to HIGH.
1901 if (((ch->ch_flags & CH_FCAR) == 0) && (virt_carrier == 1)) {
1904 * When carrier rises, wake any threads waiting
1905 * for carrier in the open routine.
1908 if (waitqueue_active(&(ch->ch_flags_wait)))
1909 wake_up_interruptible(&ch->ch_flags_wait);
1913 * Test for a PHYSICAL carrier transition to HIGH.
1915 if (((ch->ch_flags & CH_CD) == 0) && (phys_carrier == 1)) {
1918 * When carrier rises, wake any threads waiting
1919 * for carrier in the open routine.
1922 if (waitqueue_active(&(ch->ch_flags_wait)))
1923 wake_up_interruptible(&ch->ch_flags_wait);
1927 * Test for a PHYSICAL transition to low, so long as we aren't
1928 * currently ignoring physical transitions (which is what "virtual
1929 * carrier" indicates).
1931 * The transition of the virtual carrier to low really doesn't
1932 * matter... it really only means "ignore carrier state", not
1933 * "make pretend that carrier is there".
1935 if ((virt_carrier == 0) &&
1936 ((ch->ch_flags & CH_CD) != 0) &&
1937 (phys_carrier == 0)) {
1940 * When carrier drops:
1942 * Drop carrier on all open units.
1944 * Flush queues, waking up any task waiting in the
1947 * Send a hangup to the control terminal.
1949 * Enable all select calls.
1951 if (waitqueue_active(&(ch->ch_flags_wait)))
1952 wake_up_interruptible(&ch->ch_flags_wait);
1954 if (ch->ch_tun.un_open_count > 0)
1955 tty_hangup(ch->ch_tun.un_tty);
1957 if (ch->ch_pun.un_open_count > 0)
1958 tty_hangup(ch->ch_pun.un_tty);
1962 * Make sure that our cached values reflect the current reality.
1964 if (virt_carrier == 1)
1965 ch->ch_flags |= CH_FCAR;
1967 ch->ch_flags &= ~CH_FCAR;
1969 if (phys_carrier == 1)
1970 ch->ch_flags |= CH_CD;
1972 ch->ch_flags &= ~CH_CD;
1975 /************************************************************************
1977 * TTY Entry points and helper functions
1979 ************************************************************************/
1985 static int dgap_tty_open(struct tty_struct *tty, struct file *file)
1987 struct board_t *brd;
1988 struct channel_t *ch;
2000 major = MAJOR(tty_devnum(tty));
2001 minor = MINOR(tty_devnum(tty));
2006 /* Get board pointer from our array of majors we have allocated */
2007 brd = dgap_BoardsByMajor[major];
2012 * If board is not yet up to a state of READY, go to
2013 * sleep waiting for it to happen or they cancel the open.
2015 rc = wait_event_interruptible(brd->state_wait,
2016 (brd->state & BOARD_READY));
2021 DGAP_LOCK(brd->bd_lock, lock_flags);
2023 /* The wait above should guarantee this cannot happen */
2024 if (brd->state != BOARD_READY) {
2025 DGAP_UNLOCK(brd->bd_lock, lock_flags);
2029 /* If opened device is greater than our number of ports, bail. */
2030 if (MINOR(tty_devnum(tty)) > brd->nasync) {
2031 DGAP_UNLOCK(brd->bd_lock, lock_flags);
2035 ch = brd->channels[minor];
2037 DGAP_UNLOCK(brd->bd_lock, lock_flags);
2041 /* Grab channel lock */
2042 DGAP_LOCK(ch->ch_lock, lock_flags2);
2044 /* Figure out our type */
2045 if (major == brd->dgap_Serial_Major) {
2046 un = &brd->channels[minor]->ch_tun;
2047 un->un_type = DGAP_SERIAL;
2048 } else if (major == brd->dgap_TransparentPrint_Major) {
2049 un = &brd->channels[minor]->ch_pun;
2050 un->un_type = DGAP_PRINT;
2052 DGAP_UNLOCK(ch->ch_lock, lock_flags2);
2053 DGAP_UNLOCK(brd->bd_lock, lock_flags);
2057 /* Store our unit into driver_data, so we always have it available. */
2058 tty->driver_data = un;
2061 * Error if channel info pointer is NULL.
2065 DGAP_UNLOCK(ch->ch_lock, lock_flags2);
2066 DGAP_UNLOCK(brd->bd_lock, lock_flags);
2073 if (!(un->un_flags & UN_ISOPEN)) {
2074 /* Store important variables. */
2077 /* Maybe do something here to the TTY struct as well? */
2081 * Initialize if neither terminal or printer is open.
2083 if (!((ch->ch_tun.un_flags | ch->ch_pun.un_flags) & UN_ISOPEN)) {
2089 * Flush input queue.
2091 head = readw(&(bs->rx_head));
2092 writew(head, &(bs->rx_tail));
2095 ch->pscan_state = 0;
2096 ch->pscan_savechar = 0;
2098 ch->ch_c_cflag = tty->termios.c_cflag;
2099 ch->ch_c_iflag = tty->termios.c_iflag;
2100 ch->ch_c_oflag = tty->termios.c_oflag;
2101 ch->ch_c_lflag = tty->termios.c_lflag;
2102 ch->ch_startc = tty->termios.c_cc[VSTART];
2103 ch->ch_stopc = tty->termios.c_cc[VSTOP];
2105 /* TODO: flush our TTY struct here? */
2110 * Run param in case we changed anything
2115 * follow protocol for opening port
2118 DGAP_UNLOCK(ch->ch_lock, lock_flags2);
2119 DGAP_UNLOCK(brd->bd_lock, lock_flags);
2121 rc = dgap_block_til_ready(tty, file, ch);
2126 /* No going back now, increment our unit and channel counters */
2127 DGAP_LOCK(ch->ch_lock, lock_flags);
2128 ch->ch_open_count++;
2129 un->un_open_count++;
2130 un->un_flags |= (UN_ISOPEN);
2131 DGAP_UNLOCK(ch->ch_lock, lock_flags);
2137 * dgap_block_til_ready()
2139 * Wait for DCD, if needed.
2141 static int dgap_block_til_ready(struct tty_struct *tty, struct file *file,
2142 struct channel_t *ch)
2145 struct un_t *un = NULL;
2148 int sleep_on_un_flags = 0;
2150 if (!tty || tty->magic != TTY_MAGIC || !file || !ch ||
2151 ch->magic != DGAP_CHANNEL_MAGIC)
2154 un = tty->driver_data;
2155 if (!un || un->magic != DGAP_UNIT_MAGIC)
2158 DGAP_LOCK(ch->ch_lock, lock_flags);
2165 sleep_on_un_flags = 0;
2168 * If board has failed somehow during our sleep,
2171 if (ch->ch_bd->state == BOARD_FAILED) {
2176 /* If tty was hung up, break out of loop and set error. */
2177 if (tty_hung_up_p(file)) {
2183 * If either unit is in the middle of the fragile part of close,
2184 * we just cannot touch the channel safely.
2185 * Go back to sleep, knowing that when the channel can be
2186 * touched safely, the close routine will signal the
2187 * ch_wait_flags to wake us back up.
2189 if (!((ch->ch_tun.un_flags | ch->ch_pun.un_flags) &
2193 * Our conditions to leave cleanly and happily:
2194 * 1) NONBLOCKING on the tty is set.
2196 * 3) DCD (fake or real) is active.
2199 if (file->f_flags & O_NONBLOCK)
2202 if (tty->flags & (1 << TTY_IO_ERROR))
2205 if (ch->ch_flags & CH_CD)
2208 if (ch->ch_flags & CH_FCAR)
2211 sleep_on_un_flags = 1;
2215 * If there is a signal pending, the user probably
2216 * interrupted (ctrl-c) us.
2217 * Leave loop with error set.
2219 if (signal_pending(current)) {
2220 retval = -ERESTARTSYS;
2225 * Store the flags before we let go of channel lock
2227 if (sleep_on_un_flags)
2228 old_flags = ch->ch_tun.un_flags | ch->ch_pun.un_flags;
2230 old_flags = ch->ch_flags;
2233 * Let go of channel lock before calling schedule.
2234 * Our poller will get any FEP events and wake us up when DCD
2235 * eventually goes active.
2238 DGAP_UNLOCK(ch->ch_lock, lock_flags);
2241 * Wait for something in the flags to change
2242 * from the current value.
2244 if (sleep_on_un_flags) {
2245 retval = wait_event_interruptible(un->un_flags_wait,
2246 (old_flags != (ch->ch_tun.un_flags |
2247 ch->ch_pun.un_flags)));
2249 retval = wait_event_interruptible(ch->ch_flags_wait,
2250 (old_flags != ch->ch_flags));
2254 * We got woken up for some reason.
2255 * Before looping around, grab our channel lock.
2257 DGAP_LOCK(ch->ch_lock, lock_flags);
2262 DGAP_UNLOCK(ch->ch_lock, lock_flags);
2273 * Hangup the port. Like a close, but don't wait for output to drain.
2275 static void dgap_tty_hangup(struct tty_struct *tty)
2278 struct channel_t *ch;
2281 if (!tty || tty->magic != TTY_MAGIC)
2284 un = tty->driver_data;
2285 if (!un || un->magic != DGAP_UNIT_MAGIC)
2289 if (!ch || ch->magic != DGAP_CHANNEL_MAGIC)
2293 if (!bd || bd->magic != DGAP_BOARD_MAGIC)
2296 /* flush the transmit queues */
2297 dgap_tty_flush_buffer(tty);
2305 static void dgap_tty_close(struct tty_struct *tty, struct file *file)
2307 struct ktermios *ts;
2309 struct channel_t *ch;
2314 if (!tty || tty->magic != TTY_MAGIC)
2317 un = tty->driver_data;
2318 if (!un || un->magic != DGAP_UNIT_MAGIC)
2322 if (!ch || ch->magic != DGAP_CHANNEL_MAGIC)
2326 if (!bd || bd->magic != DGAP_BOARD_MAGIC)
2331 DGAP_LOCK(ch->ch_lock, lock_flags);
2334 * Determine if this is the last close or not - and if we agree about
2335 * which type of close it is with the Line Discipline
2337 if ((tty->count == 1) && (un->un_open_count != 1)) {
2339 * Uh, oh. tty->count is 1, which means that the tty
2340 * structure will be freed. un_open_count should always
2341 * be one in these conditions. If it's greater than
2342 * one, we've got real problems, since it means the
2343 * serial port won't be shutdown.
2345 un->un_open_count = 1;
2348 if (--un->un_open_count < 0)
2349 un->un_open_count = 0;
2351 ch->ch_open_count--;
2353 if (ch->ch_open_count && un->un_open_count) {
2354 DGAP_UNLOCK(ch->ch_lock, lock_flags);
2358 /* OK, its the last close on the unit */
2360 un->un_flags |= UN_CLOSING;
2365 * Only officially close channel if count is 0 and
2366 * DIGI_PRINTER bit is not set.
2368 if ((ch->ch_open_count == 0) &&
2369 !(ch->ch_digi.digi_flags & DIGI_PRINTER)) {
2371 ch->ch_flags &= ~(CH_RXBLOCK);
2373 DGAP_UNLOCK(ch->ch_lock, lock_flags);
2375 /* wait for output to drain */
2376 /* This will also return if we take an interrupt */
2378 rc = dgap_wait_for_drain(tty);
2380 dgap_tty_flush_buffer(tty);
2381 tty_ldisc_flush(tty);
2383 DGAP_LOCK(ch->ch_lock, lock_flags);
2388 * If we have HUPCL set, lower DTR and RTS
2390 if (ch->ch_c_cflag & HUPCL) {
2391 ch->ch_mostat &= ~(D_RTS(ch)|D_DTR(ch));
2392 dgap_cmdb(ch, SMODEM, 0, D_DTR(ch)|D_RTS(ch), 0);
2395 * Go to sleep to ensure RTS/DTR
2396 * have been dropped for modems to see it.
2398 if (ch->ch_close_delay) {
2399 DGAP_UNLOCK(ch->ch_lock, lock_flags);
2400 dgap_ms_sleep(ch->ch_close_delay);
2401 DGAP_LOCK(ch->ch_lock, lock_flags);
2405 ch->pscan_state = 0;
2406 ch->pscan_savechar = 0;
2407 ch->ch_baud_info = 0;
2412 * turn off print device when closing print device.
2414 if ((un->un_type == DGAP_PRINT) && (ch->ch_flags & CH_PRON)) {
2415 dgap_wmove(ch, ch->ch_digi.digi_offstr,
2416 (int) ch->ch_digi.digi_offlen);
2417 ch->ch_flags &= ~CH_PRON;
2421 un->un_flags &= ~(UN_ISOPEN | UN_CLOSING);
2422 tty->driver_data = NULL;
2424 wake_up_interruptible(&ch->ch_flags_wait);
2425 wake_up_interruptible(&un->un_flags_wait);
2427 DGAP_UNLOCK(ch->ch_lock, lock_flags);
2431 * dgap_tty_chars_in_buffer()
2433 * Return number of characters that have not been transmitted yet.
2435 * This routine is used by the line discipline to determine if there
2436 * is data waiting to be transmitted/drained/flushed or not.
2438 static int dgap_tty_chars_in_buffer(struct tty_struct *tty)
2440 struct board_t *bd = NULL;
2441 struct channel_t *ch = NULL;
2442 struct un_t *un = NULL;
2443 struct bs_t *bs = NULL;
2446 u16 thead, ttail, tmask, chead, ctail;
2447 ulong lock_flags = 0;
2448 ulong lock_flags2 = 0;
2453 un = tty->driver_data;
2454 if (!un || un->magic != DGAP_UNIT_MAGIC)
2458 if (!ch || ch->magic != DGAP_CHANNEL_MAGIC)
2462 if (!bd || bd->magic != DGAP_BOARD_MAGIC)
2469 DGAP_LOCK(bd->bd_lock, lock_flags);
2470 DGAP_LOCK(ch->ch_lock, lock_flags2);
2472 tmask = (ch->ch_tsize - 1);
2474 /* Get Transmit queue pointers */
2475 thead = readw(&(bs->tx_head)) & tmask;
2476 ttail = readw(&(bs->tx_tail)) & tmask;
2478 /* Get tbusy flag */
2479 tbusy = readb(&(bs->tbusy));
2481 /* Get Command queue pointers */
2482 chead = readw(&(ch->ch_cm->cm_head));
2483 ctail = readw(&(ch->ch_cm->cm_tail));
2485 DGAP_UNLOCK(ch->ch_lock, lock_flags2);
2486 DGAP_UNLOCK(bd->bd_lock, lock_flags);
2489 * The only way we know for sure if there is no pending
2490 * data left to be transferred, is if:
2491 * 1) Transmit head and tail are equal (empty).
2492 * 2) Command queue head and tail are equal (empty).
2493 * 3) The "TBUSY" flag is 0. (Transmitter not busy).
2496 if ((ttail == thead) && (tbusy == 0) && (chead == ctail)) {
2500 chars = thead - ttail;
2502 chars = thead - ttail + ch->ch_tsize;
2504 * Fudge factor here.
2505 * If chars is zero, we know that the command queue had
2506 * something in it or tbusy was set. Because we cannot
2507 * be sure if there is still some data to be transmitted,
2508 * lets lie, and tell ld we have 1 byte left.
2512 * If TBUSY is still set, and our tx buffers are empty,
2513 * force the firmware to send me another wakeup after
2514 * TBUSY has been cleared.
2517 DGAP_LOCK(ch->ch_lock, lock_flags);
2518 un->un_flags |= UN_EMPTY;
2519 writeb(1, &(bs->iempty));
2520 DGAP_UNLOCK(ch->ch_lock, lock_flags);
2529 static int dgap_wait_for_drain(struct tty_struct *tty)
2531 struct channel_t *ch;
2536 ulong lock_flags = 0;
2538 if (!tty || tty->magic != TTY_MAGIC)
2541 un = tty->driver_data;
2542 if (!un || un->magic != DGAP_UNIT_MAGIC)
2546 if (!ch || ch->magic != DGAP_CHANNEL_MAGIC)
2555 /* Loop until data is drained */
2556 while (count != 0) {
2558 count = dgap_tty_chars_in_buffer(tty);
2563 /* Set flag waiting for drain */
2564 DGAP_LOCK(ch->ch_lock, lock_flags);
2565 un->un_flags |= UN_EMPTY;
2566 writeb(1, &(bs->iempty));
2567 DGAP_UNLOCK(ch->ch_lock, lock_flags);
2569 /* Go to sleep till we get woken up */
2570 ret = wait_event_interruptible(un->un_flags_wait,
2571 ((un->un_flags & UN_EMPTY) == 0));
2572 /* If ret is non-zero, user ctrl-c'ed us */
2577 DGAP_LOCK(ch->ch_lock, lock_flags);
2578 un->un_flags &= ~(UN_EMPTY);
2579 DGAP_UNLOCK(ch->ch_lock, lock_flags);
2587 * Reduces bytes_available to the max number of characters
2588 * that can be sent currently given the maxcps value, and
2589 * returns the new bytes_available. This only affects printer
2592 static int dgap_maxcps_room(struct tty_struct *tty, int bytes_available)
2594 struct channel_t *ch = NULL;
2595 struct un_t *un = NULL;
2598 return bytes_available;
2600 un = tty->driver_data;
2601 if (!un || un->magic != DGAP_UNIT_MAGIC)
2602 return bytes_available;
2605 if (!ch || ch->magic != DGAP_CHANNEL_MAGIC)
2606 return bytes_available;
2609 * If its not the Transparent print device, return
2610 * the full data amount.
2612 if (un->un_type != DGAP_PRINT)
2613 return bytes_available;
2615 if (ch->ch_digi.digi_maxcps > 0 && ch->ch_digi.digi_bufsize > 0) {
2617 unsigned long current_time = jiffies;
2618 unsigned long buffer_time = current_time +
2619 (HZ * ch->ch_digi.digi_bufsize) /
2620 ch->ch_digi.digi_maxcps;
2622 if (ch->ch_cpstime < current_time) {
2623 /* buffer is empty */
2624 ch->ch_cpstime = current_time; /* reset ch_cpstime */
2625 cps_limit = ch->ch_digi.digi_bufsize;
2626 } else if (ch->ch_cpstime < buffer_time) {
2627 /* still room in the buffer */
2628 cps_limit = ((buffer_time - ch->ch_cpstime) *
2629 ch->ch_digi.digi_maxcps) / HZ;
2631 /* no room in the buffer */
2635 bytes_available = min(cps_limit, bytes_available);
2638 return bytes_available;
2641 static inline void dgap_set_firmware_event(struct un_t *un, unsigned int event)
2643 struct channel_t *ch = NULL;
2644 struct bs_t *bs = NULL;
2646 if (!un || un->magic != DGAP_UNIT_MAGIC)
2649 if (!ch || ch->magic != DGAP_CHANNEL_MAGIC)
2655 if ((event & UN_LOW) != 0) {
2656 if ((un->un_flags & UN_LOW) == 0) {
2657 un->un_flags |= UN_LOW;
2658 writeb(1, &(bs->ilow));
2661 if ((event & UN_LOW) != 0) {
2662 if ((un->un_flags & UN_EMPTY) == 0) {
2663 un->un_flags |= UN_EMPTY;
2664 writeb(1, &(bs->iempty));
2670 * dgap_tty_write_room()
2672 * Return space available in Tx buffer
2674 static int dgap_tty_write_room(struct tty_struct *tty)
2676 struct channel_t *ch = NULL;
2677 struct un_t *un = NULL;
2678 struct bs_t *bs = NULL;
2679 u16 head, tail, tmask;
2681 ulong lock_flags = 0;
2686 un = tty->driver_data;
2687 if (!un || un->magic != DGAP_UNIT_MAGIC)
2691 if (!ch || ch->magic != DGAP_CHANNEL_MAGIC)
2698 DGAP_LOCK(ch->ch_lock, lock_flags);
2700 tmask = ch->ch_tsize - 1;
2701 head = readw(&(bs->tx_head)) & tmask;
2702 tail = readw(&(bs->tx_tail)) & tmask;
2704 ret = tail - head - 1;
2706 ret += ch->ch_tsize;
2708 /* Limit printer to maxcps */
2709 ret = dgap_maxcps_room(tty, ret);
2712 * If we are printer device, leave space for
2713 * possibly both the on and off strings.
2715 if (un->un_type == DGAP_PRINT) {
2716 if (!(ch->ch_flags & CH_PRON))
2717 ret -= ch->ch_digi.digi_onlen;
2718 ret -= ch->ch_digi.digi_offlen;
2720 if (ch->ch_flags & CH_PRON)
2721 ret -= ch->ch_digi.digi_offlen;
2728 * Schedule FEP to wake us up if needed.
2730 * TODO: This might be overkill...
2731 * Do we really need to schedule callbacks from the FEP
2732 * in every case? Can we get smarter based on ret?
2734 dgap_set_firmware_event(un, UN_LOW | UN_EMPTY);
2735 DGAP_UNLOCK(ch->ch_lock, lock_flags);
2741 * dgap_tty_put_char()
2743 * Put a character into ch->ch_buf
2745 * - used by the line discipline for OPOST processing
2747 static int dgap_tty_put_char(struct tty_struct *tty, unsigned char c)
2750 * Simply call tty_write.
2752 dgap_tty_write(tty, &c, 1);
2759 * Take data from the user or kernel and send it out to the FEP.
2760 * In here exists all the Transparent Print magic as well.
2762 static int dgap_tty_write(struct tty_struct *tty, const unsigned char *buf,
2765 struct channel_t *ch = NULL;
2766 struct un_t *un = NULL;
2767 struct bs_t *bs = NULL;
2769 u16 head, tail, tmask, remain;
2770 int bufcount = 0, n = 0;
2777 un = tty->driver_data;
2778 if (!un || un->magic != DGAP_UNIT_MAGIC)
2782 if (!ch || ch->magic != DGAP_CHANNEL_MAGIC)
2793 * Store original amount of characters passed in.
2794 * This helps to figure out if we should ask the FEP
2795 * to send us an event when it has more space available.
2799 DGAP_LOCK(ch->ch_lock, lock_flags);
2801 /* Get our space available for the channel from the board */
2802 tmask = ch->ch_tsize - 1;
2803 head = readw(&(bs->tx_head)) & tmask;
2804 tail = readw(&(bs->tx_tail)) & tmask;
2806 bufcount = tail - head - 1;
2808 bufcount += ch->ch_tsize;
2811 * Limit printer output to maxcps overall, with bursts allowed
2812 * up to bufsize characters.
2814 bufcount = dgap_maxcps_room(tty, bufcount);
2817 * Take minimum of what the user wants to send, and the
2818 * space available in the FEP buffer.
2820 count = min(count, bufcount);
2823 * Bail if no space left.
2826 dgap_set_firmware_event(un, UN_LOW | UN_EMPTY);
2827 DGAP_UNLOCK(ch->ch_lock, lock_flags);
2832 * Output the printer ON string, if we are in terminal mode, but
2833 * need to be in printer mode.
2835 if ((un->un_type == DGAP_PRINT) && !(ch->ch_flags & CH_PRON)) {
2836 dgap_wmove(ch, ch->ch_digi.digi_onstr,
2837 (int) ch->ch_digi.digi_onlen);
2838 head = readw(&(bs->tx_head)) & tmask;
2839 ch->ch_flags |= CH_PRON;
2843 * On the other hand, output the printer OFF string, if we are
2844 * currently in printer mode, but need to output to the terminal.
2846 if ((un->un_type != DGAP_PRINT) && (ch->ch_flags & CH_PRON)) {
2847 dgap_wmove(ch, ch->ch_digi.digi_offstr,
2848 (int) ch->ch_digi.digi_offlen);
2849 head = readw(&(bs->tx_head)) & tmask;
2850 ch->ch_flags &= ~CH_PRON;
2854 * If there is nothing left to copy, or
2855 * I can't handle any more data, leave.
2858 dgap_set_firmware_event(un, UN_LOW | UN_EMPTY);
2859 DGAP_UNLOCK(ch->ch_lock, lock_flags);
2866 * If the write wraps over the top of the circular buffer,
2867 * move the portion up to the wrap point, and reset the
2868 * pointers to the bottom.
2870 remain = ch->ch_tstart + ch->ch_tsize - head;
2874 vaddr = ch->ch_taddr + head;
2876 memcpy_toio(vaddr, (uchar *) buf, remain);
2877 dgap_sniff_nowait_nolock(ch, "USER WRITE", (uchar *) buf,
2880 head = ch->ch_tstart;
2887 * Move rest of data.
2889 vaddr = ch->ch_taddr + head;
2892 memcpy_toio(vaddr, (uchar *) buf, remain);
2893 dgap_sniff_nowait_nolock(ch, "USER WRITE", (uchar *)buf,
2901 ch->ch_txcount += count;
2903 writew(head, &(bs->tx_head));
2906 dgap_set_firmware_event(un, UN_LOW | UN_EMPTY);
2909 * If this is the print device, and the
2910 * printer is still on, we need to turn it
2911 * off before going idle. If the buffer is
2912 * non-empty, wait until it goes empty.
2913 * Otherwise turn it off right now.
2915 if ((un->un_type == DGAP_PRINT) && (ch->ch_flags & CH_PRON)) {
2916 tail = readw(&(bs->tx_tail)) & tmask;
2919 un->un_flags |= UN_EMPTY;
2920 writeb(1, &(bs->iempty));
2922 dgap_wmove(ch, ch->ch_digi.digi_offstr,
2923 (int) ch->ch_digi.digi_offlen);
2924 head = readw(&(bs->tx_head)) & tmask;
2925 ch->ch_flags &= ~CH_PRON;
2929 /* Update printer buffer empty time. */
2930 if ((un->un_type == DGAP_PRINT) && (ch->ch_digi.digi_maxcps > 0)
2931 && (ch->ch_digi.digi_bufsize > 0)) {
2932 ch->ch_cpstime += (HZ * count) / ch->ch_digi.digi_maxcps;
2935 DGAP_UNLOCK(ch->ch_lock, lock_flags);
2941 * Return modem signals to ld.
2943 static int dgap_tty_tiocmget(struct tty_struct *tty)
2945 struct channel_t *ch;
2951 if (!tty || tty->magic != TTY_MAGIC)
2954 un = tty->driver_data;
2955 if (!un || un->magic != DGAP_UNIT_MAGIC)
2959 if (!ch || ch->magic != DGAP_CHANNEL_MAGIC)
2962 DGAP_LOCK(ch->ch_lock, lock_flags);
2964 mstat = readb(&(ch->ch_bs->m_stat));
2965 /* Append any outbound signals that might be pending... */
2966 mstat |= ch->ch_mostat;
2968 DGAP_UNLOCK(ch->ch_lock, lock_flags);
2972 if (mstat & D_DTR(ch))
2973 result |= TIOCM_DTR;
2974 if (mstat & D_RTS(ch))
2975 result |= TIOCM_RTS;
2976 if (mstat & D_CTS(ch))
2977 result |= TIOCM_CTS;
2978 if (mstat & D_DSR(ch))
2979 result |= TIOCM_DSR;
2980 if (mstat & D_RI(ch))
2982 if (mstat & D_CD(ch))
2989 * dgap_tty_tiocmset()
2991 * Set modem signals, called by ld.
2993 static int dgap_tty_tiocmset(struct tty_struct *tty,
2994 unsigned int set, unsigned int clear)
2997 struct channel_t *ch;
3003 if (!tty || tty->magic != TTY_MAGIC)
3006 un = tty->driver_data;
3007 if (!un || un->magic != DGAP_UNIT_MAGIC)
3011 if (!ch || ch->magic != DGAP_CHANNEL_MAGIC)
3015 if (!bd || bd->magic != DGAP_BOARD_MAGIC)
3018 DGAP_LOCK(bd->bd_lock, lock_flags);
3019 DGAP_LOCK(ch->ch_lock, lock_flags2);
3021 if (set & TIOCM_RTS) {
3022 ch->ch_mforce |= D_RTS(ch);
3023 ch->ch_mval |= D_RTS(ch);
3026 if (set & TIOCM_DTR) {
3027 ch->ch_mforce |= D_DTR(ch);
3028 ch->ch_mval |= D_DTR(ch);
3031 if (clear & TIOCM_RTS) {
3032 ch->ch_mforce |= D_RTS(ch);
3033 ch->ch_mval &= ~(D_RTS(ch));
3036 if (clear & TIOCM_DTR) {
3037 ch->ch_mforce |= D_DTR(ch);
3038 ch->ch_mval &= ~(D_DTR(ch));
3043 DGAP_UNLOCK(ch->ch_lock, lock_flags2);
3044 DGAP_UNLOCK(bd->bd_lock, lock_flags);
3050 * dgap_tty_send_break()
3052 * Send a Break, called by ld.
3054 static int dgap_tty_send_break(struct tty_struct *tty, int msec)
3057 struct channel_t *ch;
3063 if (!tty || tty->magic != TTY_MAGIC)
3066 un = tty->driver_data;
3067 if (!un || un->magic != DGAP_UNIT_MAGIC)
3071 if (!ch || ch->magic != DGAP_CHANNEL_MAGIC)
3075 if (!bd || bd->magic != DGAP_BOARD_MAGIC)
3090 DGAP_LOCK(bd->bd_lock, lock_flags);
3091 DGAP_LOCK(ch->ch_lock, lock_flags2);
3093 dgap_cmdw(ch, SBREAK, (u16) SBREAK_TIME, 0);
3095 dgap_cmdw(ch, SBREAK, (u16) msec, 0);
3097 DGAP_UNLOCK(ch->ch_lock, lock_flags2);
3098 DGAP_UNLOCK(bd->bd_lock, lock_flags);
3104 * dgap_tty_wait_until_sent()
3106 * wait until data has been transmitted, called by ld.
3108 static void dgap_tty_wait_until_sent(struct tty_struct *tty, int timeout)
3110 dgap_wait_for_drain(tty);
3116 * send a high priority character, called by ld.
3118 static void dgap_tty_send_xchar(struct tty_struct *tty, char c)
3121 struct channel_t *ch;
3126 if (!tty || tty->magic != TTY_MAGIC)
3129 un = tty->driver_data;
3130 if (!un || un->magic != DGAP_UNIT_MAGIC)
3134 if (!ch || ch->magic != DGAP_CHANNEL_MAGIC)
3138 if (!bd || bd->magic != DGAP_BOARD_MAGIC)
3141 DGAP_LOCK(bd->bd_lock, lock_flags);
3142 DGAP_LOCK(ch->ch_lock, lock_flags2);
3145 * This is technically what we should do.
3146 * However, the NIST tests specifically want
3147 * to see each XON or XOFF character that it
3148 * sends, so lets just send each character
3152 if (c == STOP_CHAR(tty))
3153 dgap_cmdw(ch, RPAUSE, 0, 0);
3154 else if (c == START_CHAR(tty))
3155 dgap_cmdw(ch, RRESUME, 0, 0);
3157 dgap_wmove(ch, &c, 1);
3159 dgap_wmove(ch, &c, 1);
3162 DGAP_UNLOCK(ch->ch_lock, lock_flags2);
3163 DGAP_UNLOCK(bd->bd_lock, lock_flags);
3169 * Return modem signals to ld.
3171 static int dgap_get_modem_info(struct channel_t *ch, unsigned int __user *value)
3178 if (!ch || ch->magic != DGAP_CHANNEL_MAGIC)
3181 DGAP_LOCK(ch->ch_lock, lock_flags);
3183 mstat = readb(&(ch->ch_bs->m_stat));
3184 /* Append any outbound signals that might be pending... */
3185 mstat |= ch->ch_mostat;
3187 DGAP_UNLOCK(ch->ch_lock, lock_flags);
3191 if (mstat & D_DTR(ch))
3192 result |= TIOCM_DTR;
3193 if (mstat & D_RTS(ch))
3194 result |= TIOCM_RTS;
3195 if (mstat & D_CTS(ch))
3196 result |= TIOCM_CTS;
3197 if (mstat & D_DSR(ch))
3198 result |= TIOCM_DSR;
3199 if (mstat & D_RI(ch))
3201 if (mstat & D_CD(ch))
3204 rc = put_user(result, value);
3210 * dgap_set_modem_info()
3212 * Set modem signals, called by ld.
3214 static int dgap_set_modem_info(struct tty_struct *tty, unsigned int command,
3215 unsigned int __user *value)
3218 struct channel_t *ch;
3221 unsigned int arg = 0;
3225 if (!tty || tty->magic != TTY_MAGIC)
3228 un = tty->driver_data;
3229 if (!un || un->magic != DGAP_UNIT_MAGIC)
3233 if (!ch || ch->magic != DGAP_CHANNEL_MAGIC)
3237 if (!bd || bd->magic != DGAP_BOARD_MAGIC)
3240 ret = get_user(arg, value);
3246 if (arg & TIOCM_RTS) {
3247 ch->ch_mforce |= D_RTS(ch);
3248 ch->ch_mval |= D_RTS(ch);
3251 if (arg & TIOCM_DTR) {
3252 ch->ch_mforce |= D_DTR(ch);
3253 ch->ch_mval |= D_DTR(ch);
3259 if (arg & TIOCM_RTS) {
3260 ch->ch_mforce |= D_RTS(ch);
3261 ch->ch_mval &= ~(D_RTS(ch));
3264 if (arg & TIOCM_DTR) {
3265 ch->ch_mforce |= D_DTR(ch);
3266 ch->ch_mval &= ~(D_DTR(ch));
3272 ch->ch_mforce = D_DTR(ch)|D_RTS(ch);
3274 if (arg & TIOCM_RTS)
3275 ch->ch_mval |= D_RTS(ch);
3277 ch->ch_mval &= ~(D_RTS(ch));
3279 if (arg & TIOCM_DTR)
3280 ch->ch_mval |= (D_DTR(ch));
3282 ch->ch_mval &= ~(D_DTR(ch));
3290 DGAP_LOCK(bd->bd_lock, lock_flags);
3291 DGAP_LOCK(ch->ch_lock, lock_flags2);
3295 DGAP_UNLOCK(ch->ch_lock, lock_flags2);
3296 DGAP_UNLOCK(bd->bd_lock, lock_flags);
3302 * dgap_tty_digigeta()
3304 * Ioctl to get the information for ditty.
3309 static int dgap_tty_digigeta(struct tty_struct *tty,
3310 struct digi_t __user *retinfo)
3312 struct channel_t *ch;
3320 if (!tty || tty->magic != TTY_MAGIC)
3323 un = tty->driver_data;
3324 if (!un || un->magic != DGAP_UNIT_MAGIC)
3328 if (!ch || ch->magic != DGAP_CHANNEL_MAGIC)
3331 memset(&tmp, 0, sizeof(tmp));
3333 DGAP_LOCK(ch->ch_lock, lock_flags);
3334 memcpy(&tmp, &ch->ch_digi, sizeof(tmp));
3335 DGAP_UNLOCK(ch->ch_lock, lock_flags);
3337 if (copy_to_user(retinfo, &tmp, sizeof(*retinfo)))
3344 * dgap_tty_digiseta()
3346 * Ioctl to set the information for ditty.
3351 static int dgap_tty_digiseta(struct tty_struct *tty,
3352 struct digi_t __user *new_info)
3355 struct channel_t *ch;
3357 struct digi_t new_digi;
3358 ulong lock_flags = 0;
3359 unsigned long lock_flags2;
3361 if (!tty || tty->magic != TTY_MAGIC)
3364 un = tty->driver_data;
3365 if (!un || un->magic != DGAP_UNIT_MAGIC)
3369 if (!ch || ch->magic != DGAP_CHANNEL_MAGIC)
3373 if (!bd || bd->magic != DGAP_BOARD_MAGIC)
3376 if (copy_from_user(&new_digi, new_info, sizeof(struct digi_t)))
3379 DGAP_LOCK(bd->bd_lock, lock_flags);
3380 DGAP_LOCK(ch->ch_lock, lock_flags2);
3382 memcpy(&ch->ch_digi, &new_digi, sizeof(struct digi_t));
3384 if (ch->ch_digi.digi_maxcps < 1)
3385 ch->ch_digi.digi_maxcps = 1;
3387 if (ch->ch_digi.digi_maxcps > 10000)
3388 ch->ch_digi.digi_maxcps = 10000;
3390 if (ch->ch_digi.digi_bufsize < 10)
3391 ch->ch_digi.digi_bufsize = 10;
3393 if (ch->ch_digi.digi_maxchar < 1)
3394 ch->ch_digi.digi_maxchar = 1;
3396 if (ch->ch_digi.digi_maxchar > ch->ch_digi.digi_bufsize)
3397 ch->ch_digi.digi_maxchar = ch->ch_digi.digi_bufsize;
3399 if (ch->ch_digi.digi_onlen > DIGI_PLEN)
3400 ch->ch_digi.digi_onlen = DIGI_PLEN;
3402 if (ch->ch_digi.digi_offlen > DIGI_PLEN)
3403 ch->ch_digi.digi_offlen = DIGI_PLEN;
3407 DGAP_UNLOCK(ch->ch_lock, lock_flags2);
3408 DGAP_UNLOCK(bd->bd_lock, lock_flags);
3414 * dgap_tty_digigetedelay()
3416 * Ioctl to get the current edelay setting.
3421 static int dgap_tty_digigetedelay(struct tty_struct *tty, int __user *retinfo)
3423 struct channel_t *ch;
3431 if (!tty || tty->magic != TTY_MAGIC)
3434 un = tty->driver_data;
3435 if (!un || un->magic != DGAP_UNIT_MAGIC)
3439 if (!ch || ch->magic != DGAP_CHANNEL_MAGIC)
3442 memset(&tmp, 0, sizeof(tmp));
3444 DGAP_LOCK(ch->ch_lock, lock_flags);
3445 tmp = readw(&(ch->ch_bs->edelay));
3446 DGAP_UNLOCK(ch->ch_lock, lock_flags);
3448 if (copy_to_user(retinfo, &tmp, sizeof(*retinfo)))
3455 * dgap_tty_digisetedelay()
3457 * Ioctl to set the EDELAY setting
3460 static int dgap_tty_digisetedelay(struct tty_struct *tty, int __user *new_info)
3463 struct channel_t *ch;
3469 if (!tty || tty->magic != TTY_MAGIC)
3472 un = tty->driver_data;
3473 if (!un || un->magic != DGAP_UNIT_MAGIC)
3477 if (!ch || ch->magic != DGAP_CHANNEL_MAGIC)
3481 if (!bd || bd->magic != DGAP_BOARD_MAGIC)
3484 if (copy_from_user(&new_digi, new_info, sizeof(int)))
3487 DGAP_LOCK(bd->bd_lock, lock_flags);
3488 DGAP_LOCK(ch->ch_lock, lock_flags2);
3490 writew((u16) new_digi, &(ch->ch_bs->edelay));
3494 DGAP_UNLOCK(ch->ch_lock, lock_flags2);
3495 DGAP_UNLOCK(bd->bd_lock, lock_flags);
3501 * dgap_tty_digigetcustombaud()
3503 * Ioctl to get the current custom baud rate setting.
3505 static int dgap_tty_digigetcustombaud(struct tty_struct *tty,
3506 int __user *retinfo)
3508 struct channel_t *ch;
3516 if (!tty || tty->magic != TTY_MAGIC)
3519 un = tty->driver_data;
3520 if (!un || un->magic != DGAP_UNIT_MAGIC)
3524 if (!ch || ch->magic != DGAP_CHANNEL_MAGIC)
3527 memset(&tmp, 0, sizeof(tmp));
3529 DGAP_LOCK(ch->ch_lock, lock_flags);
3530 tmp = dgap_get_custom_baud(ch);
3531 DGAP_UNLOCK(ch->ch_lock, lock_flags);
3533 if (copy_to_user(retinfo, &tmp, sizeof(*retinfo)))
3540 * dgap_tty_digisetcustombaud()
3542 * Ioctl to set the custom baud rate setting
3544 static int dgap_tty_digisetcustombaud(struct tty_struct *tty,
3545 int __user *new_info)
3548 struct channel_t *ch;
3554 if (!tty || tty->magic != TTY_MAGIC)
3557 un = tty->driver_data;
3558 if (!un || un->magic != DGAP_UNIT_MAGIC)
3562 if (!ch || ch->magic != DGAP_CHANNEL_MAGIC)
3566 if (!bd || bd->magic != DGAP_BOARD_MAGIC)
3570 if (copy_from_user(&new_rate, new_info, sizeof(unsigned int)))
3573 if (bd->bd_flags & BD_FEP5PLUS) {
3575 DGAP_LOCK(bd->bd_lock, lock_flags);
3576 DGAP_LOCK(ch->ch_lock, lock_flags2);
3578 ch->ch_custom_speed = new_rate;
3582 DGAP_UNLOCK(ch->ch_lock, lock_flags2);
3583 DGAP_UNLOCK(bd->bd_lock, lock_flags);
3590 * dgap_set_termios()
3592 static void dgap_tty_set_termios(struct tty_struct *tty,
3593 struct ktermios *old_termios)
3596 struct channel_t *ch;
3598 unsigned long lock_flags;
3599 unsigned long lock_flags2;
3601 if (!tty || tty->magic != TTY_MAGIC)
3604 un = tty->driver_data;
3605 if (!un || un->magic != DGAP_UNIT_MAGIC)
3609 if (!ch || ch->magic != DGAP_CHANNEL_MAGIC)
3613 if (!bd || bd->magic != DGAP_BOARD_MAGIC)
3616 DGAP_LOCK(bd->bd_lock, lock_flags);
3617 DGAP_LOCK(ch->ch_lock, lock_flags2);
3619 ch->ch_c_cflag = tty->termios.c_cflag;
3620 ch->ch_c_iflag = tty->termios.c_iflag;
3621 ch->ch_c_oflag = tty->termios.c_oflag;
3622 ch->ch_c_lflag = tty->termios.c_lflag;
3623 ch->ch_startc = tty->termios.c_cc[VSTART];
3624 ch->ch_stopc = tty->termios.c_cc[VSTOP];
3629 DGAP_UNLOCK(ch->ch_lock, lock_flags2);
3630 DGAP_UNLOCK(bd->bd_lock, lock_flags);
3633 static void dgap_tty_throttle(struct tty_struct *tty)
3636 struct channel_t *ch;
3641 if (!tty || tty->magic != TTY_MAGIC)
3644 un = tty->driver_data;
3645 if (!un || un->magic != DGAP_UNIT_MAGIC)
3649 if (!ch || ch->magic != DGAP_CHANNEL_MAGIC)
3653 if (!bd || bd->magic != DGAP_BOARD_MAGIC)
3656 DGAP_LOCK(bd->bd_lock, lock_flags);
3657 DGAP_LOCK(ch->ch_lock, lock_flags2);
3659 ch->ch_flags |= (CH_RXBLOCK);
3661 dgap_cmdw(ch, RPAUSE, 0, 0);
3664 DGAP_UNLOCK(ch->ch_lock, lock_flags2);
3665 DGAP_UNLOCK(bd->bd_lock, lock_flags);
3669 static void dgap_tty_unthrottle(struct tty_struct *tty)
3672 struct channel_t *ch;
3677 if (!tty || tty->magic != TTY_MAGIC)
3680 un = tty->driver_data;
3681 if (!un || un->magic != DGAP_UNIT_MAGIC)
3685 if (!ch || ch->magic != DGAP_CHANNEL_MAGIC)
3689 if (!bd || bd->magic != DGAP_BOARD_MAGIC)
3692 DGAP_LOCK(bd->bd_lock, lock_flags);
3693 DGAP_LOCK(ch->ch_lock, lock_flags2);
3695 ch->ch_flags &= ~(CH_RXBLOCK);
3698 dgap_cmdw(ch, RRESUME, 0, 0);
3701 DGAP_UNLOCK(ch->ch_lock, lock_flags2);
3702 DGAP_UNLOCK(bd->bd_lock, lock_flags);
3705 static void dgap_tty_start(struct tty_struct *tty)
3708 struct channel_t *ch;
3713 if (!tty || tty->magic != TTY_MAGIC)
3716 un = tty->driver_data;
3717 if (!un || un->magic != DGAP_UNIT_MAGIC)
3721 if (!ch || ch->magic != DGAP_CHANNEL_MAGIC)
3725 if (!bd || bd->magic != DGAP_BOARD_MAGIC)
3728 DGAP_LOCK(bd->bd_lock, lock_flags);
3729 DGAP_LOCK(ch->ch_lock, lock_flags2);
3731 dgap_cmdw(ch, RESUMETX, 0, 0);
3733 DGAP_UNLOCK(ch->ch_lock, lock_flags2);
3734 DGAP_UNLOCK(bd->bd_lock, lock_flags);
3738 static void dgap_tty_stop(struct tty_struct *tty)
3741 struct channel_t *ch;
3746 if (!tty || tty->magic != TTY_MAGIC)
3749 un = tty->driver_data;
3750 if (!un || un->magic != DGAP_UNIT_MAGIC)
3754 if (!ch || ch->magic != DGAP_CHANNEL_MAGIC)
3758 if (!bd || bd->magic != DGAP_BOARD_MAGIC)
3761 DGAP_LOCK(bd->bd_lock, lock_flags);
3762 DGAP_LOCK(ch->ch_lock, lock_flags2);
3764 dgap_cmdw(ch, PAUSETX, 0, 0);
3766 DGAP_UNLOCK(ch->ch_lock, lock_flags2);
3767 DGAP_UNLOCK(bd->bd_lock, lock_flags);
3772 * dgap_tty_flush_chars()
3774 * Flush the cook buffer
3776 * Note to self, and any other poor souls who venture here:
3778 * flush in this case DOES NOT mean dispose of the data.
3779 * instead, it means "stop buffering and send it if you
3780 * haven't already." Just guess how I figured that out... SRW 2-Jun-98
3782 * It is also always called in interrupt context - JAR 8-Sept-99
3784 static void dgap_tty_flush_chars(struct tty_struct *tty)
3787 struct channel_t *ch;
3792 if (!tty || tty->magic != TTY_MAGIC)
3795 un = tty->driver_data;
3796 if (!un || un->magic != DGAP_UNIT_MAGIC)
3800 if (!ch || ch->magic != DGAP_CHANNEL_MAGIC)
3804 if (!bd || bd->magic != DGAP_BOARD_MAGIC)
3807 DGAP_LOCK(bd->bd_lock, lock_flags);
3808 DGAP_LOCK(ch->ch_lock, lock_flags2);
3810 /* TODO: Do something here */
3812 DGAP_UNLOCK(ch->ch_lock, lock_flags2);
3813 DGAP_UNLOCK(bd->bd_lock, lock_flags);
3817 * dgap_tty_flush_buffer()
3819 * Flush Tx buffer (make in == out)
3821 static void dgap_tty_flush_buffer(struct tty_struct *tty)
3824 struct channel_t *ch;
3830 if (!tty || tty->magic != TTY_MAGIC)
3833 un = tty->driver_data;
3834 if (!un || un->magic != DGAP_UNIT_MAGIC)
3838 if (!ch || ch->magic != DGAP_CHANNEL_MAGIC)
3842 if (!bd || bd->magic != DGAP_BOARD_MAGIC)
3845 DGAP_LOCK(bd->bd_lock, lock_flags);
3846 DGAP_LOCK(ch->ch_lock, lock_flags2);
3848 ch->ch_flags &= ~CH_STOP;
3849 head = readw(&(ch->ch_bs->tx_head));
3850 dgap_cmdw(ch, FLUSHTX, (u16) head, 0);
3851 dgap_cmdw(ch, RESUMETX, 0, 0);
3852 if (ch->ch_tun.un_flags & (UN_LOW|UN_EMPTY)) {
3853 ch->ch_tun.un_flags &= ~(UN_LOW|UN_EMPTY);
3854 wake_up_interruptible(&ch->ch_tun.un_flags_wait);
3856 if (ch->ch_pun.un_flags & (UN_LOW|UN_EMPTY)) {
3857 ch->ch_pun.un_flags &= ~(UN_LOW|UN_EMPTY);
3858 wake_up_interruptible(&ch->ch_pun.un_flags_wait);
3861 DGAP_UNLOCK(ch->ch_lock, lock_flags2);
3862 DGAP_UNLOCK(bd->bd_lock, lock_flags);
3863 if (waitqueue_active(&tty->write_wait))
3864 wake_up_interruptible(&tty->write_wait);
3868 /*****************************************************************************
3870 * The IOCTL function and all of its helpers
3872 *****************************************************************************/
3877 * The usual assortment of ioctl's
3879 static int dgap_tty_ioctl(struct tty_struct *tty, unsigned int cmd,
3883 struct channel_t *ch;
3887 ulong lock_flags = 0;
3888 ulong lock_flags2 = 0;
3889 void __user *uarg = (void __user *) arg;
3891 if (!tty || tty->magic != TTY_MAGIC)
3894 un = tty->driver_data;
3895 if (!un || un->magic != DGAP_UNIT_MAGIC)
3899 if (!ch || ch->magic != DGAP_CHANNEL_MAGIC)
3903 if (!bd || bd->magic != DGAP_BOARD_MAGIC)
3906 DGAP_LOCK(bd->bd_lock, lock_flags);
3907 DGAP_LOCK(ch->ch_lock, lock_flags2);
3909 if (un->un_open_count <= 0) {
3910 DGAP_UNLOCK(ch->ch_lock, lock_flags2);
3911 DGAP_UNLOCK(bd->bd_lock, lock_flags);
3917 /* Here are all the standard ioctl's that we MUST implement */
3921 * TCSBRK is SVID version: non-zero arg --> no break
3922 * this behaviour is exploited by tcdrain().
3924 * According to POSIX.1 spec (7.2.2.1.2) breaks should be
3925 * between 0.25 and 0.5 seconds so we'll ask for something
3926 * in the middle: 0.375 seconds.
3928 rc = tty_check_change(tty);
3929 DGAP_UNLOCK(ch->ch_lock, lock_flags2);
3930 DGAP_UNLOCK(bd->bd_lock, lock_flags);
3934 rc = dgap_wait_for_drain(tty);
3939 DGAP_LOCK(bd->bd_lock, lock_flags);
3940 DGAP_LOCK(ch->ch_lock, lock_flags2);
3942 if (((cmd == TCSBRK) && (!arg)) || (cmd == TCSBRKP))
3943 dgap_cmdw(ch, SBREAK, (u16) SBREAK_TIME, 0);
3945 DGAP_UNLOCK(ch->ch_lock, lock_flags2);
3946 DGAP_UNLOCK(bd->bd_lock, lock_flags);
3951 /* support for POSIX tcsendbreak()
3953 * According to POSIX.1 spec (7.2.2.1.2) breaks should be
3954 * between 0.25 and 0.5 seconds so we'll ask for something
3955 * in the middle: 0.375 seconds.
3957 rc = tty_check_change(tty);
3958 DGAP_UNLOCK(ch->ch_lock, lock_flags2);
3959 DGAP_UNLOCK(bd->bd_lock, lock_flags);
3963 rc = dgap_wait_for_drain(tty);
3967 DGAP_LOCK(bd->bd_lock, lock_flags);
3968 DGAP_LOCK(ch->ch_lock, lock_flags2);
3970 dgap_cmdw(ch, SBREAK, (u16) SBREAK_TIME, 0);
3972 DGAP_UNLOCK(ch->ch_lock, lock_flags2);
3973 DGAP_UNLOCK(bd->bd_lock, lock_flags);
3979 * FEP5 doesn't support turning on a break unconditionally.
3980 * The FEP5 device will stop sending a break automatically
3981 * after the specified time value that was sent when turning on
3984 rc = tty_check_change(tty);
3985 DGAP_UNLOCK(ch->ch_lock, lock_flags2);
3986 DGAP_UNLOCK(bd->bd_lock, lock_flags);
3990 rc = dgap_wait_for_drain(tty);
3994 DGAP_LOCK(bd->bd_lock, lock_flags);
3995 DGAP_LOCK(ch->ch_lock, lock_flags2);
3997 dgap_cmdw(ch, SBREAK, (u16) SBREAK_TIME, 0);
3999 DGAP_UNLOCK(ch->ch_lock, lock_flags2);
4000 DGAP_UNLOCK(bd->bd_lock, lock_flags);
4006 * FEP5 doesn't support turning off a break unconditionally.
4007 * The FEP5 device will stop sending a break automatically
4008 * after the specified time value that was sent when turning on
4011 DGAP_UNLOCK(ch->ch_lock, lock_flags2);
4012 DGAP_UNLOCK(bd->bd_lock, lock_flags);
4017 DGAP_UNLOCK(ch->ch_lock, lock_flags2);
4018 DGAP_UNLOCK(bd->bd_lock, lock_flags);
4020 rc = put_user(C_CLOCAL(tty) ? 1 : 0,
4021 (unsigned long __user *) arg);
4025 DGAP_UNLOCK(ch->ch_lock, lock_flags2);
4026 DGAP_UNLOCK(bd->bd_lock, lock_flags);
4028 rc = get_user(arg, (unsigned long __user *) arg);
4032 DGAP_LOCK(bd->bd_lock, lock_flags);
4033 DGAP_LOCK(ch->ch_lock, lock_flags2);
4034 tty->termios.c_cflag = ((tty->termios.c_cflag & ~CLOCAL) |
4035 (arg ? CLOCAL : 0));
4037 DGAP_UNLOCK(ch->ch_lock, lock_flags2);
4038 DGAP_UNLOCK(bd->bd_lock, lock_flags);
4043 DGAP_UNLOCK(ch->ch_lock, lock_flags2);
4044 DGAP_UNLOCK(bd->bd_lock, lock_flags);
4045 return dgap_get_modem_info(ch, uarg);
4050 DGAP_UNLOCK(ch->ch_lock, lock_flags2);
4051 DGAP_UNLOCK(bd->bd_lock, lock_flags);
4052 return dgap_set_modem_info(tty, cmd, uarg);
4055 * Here are any additional ioctl's that we want to implement
4060 * The linux tty driver doesn't have a flush
4061 * input routine for the driver, assuming all backed
4062 * up data is in the line disc. buffers. However,
4063 * we all know that's not the case. Here, we
4064 * act on the ioctl, but then lie and say we didn't
4065 * so the line discipline will process the flush
4068 rc = tty_check_change(tty);
4070 DGAP_UNLOCK(ch->ch_lock, lock_flags2);
4071 DGAP_UNLOCK(bd->bd_lock, lock_flags);
4075 if ((arg == TCIFLUSH) || (arg == TCIOFLUSH)) {
4076 if (!(un->un_type == DGAP_PRINT)) {
4077 head = readw(&(ch->ch_bs->rx_head));
4078 writew(head, &(ch->ch_bs->rx_tail));
4079 writeb(0, &(ch->ch_bs->orun));
4083 if ((arg != TCOFLUSH) && (arg != TCIOFLUSH)) {
4084 /* pretend we didn't recognize this IOCTL */
4085 DGAP_UNLOCK(ch->ch_lock, lock_flags2);
4086 DGAP_UNLOCK(bd->bd_lock, lock_flags);
4088 return -ENOIOCTLCMD;
4091 ch->ch_flags &= ~CH_STOP;
4092 head = readw(&(ch->ch_bs->tx_head));
4093 dgap_cmdw(ch, FLUSHTX, (u16) head, 0);
4094 dgap_cmdw(ch, RESUMETX, 0, 0);
4095 if (ch->ch_tun.un_flags & (UN_LOW|UN_EMPTY)) {
4096 ch->ch_tun.un_flags &= ~(UN_LOW|UN_EMPTY);
4097 wake_up_interruptible(&ch->ch_tun.un_flags_wait);
4099 if (ch->ch_pun.un_flags & (UN_LOW|UN_EMPTY)) {
4100 ch->ch_pun.un_flags &= ~(UN_LOW|UN_EMPTY);
4101 wake_up_interruptible(&ch->ch_pun.un_flags_wait);
4103 if (waitqueue_active(&tty->write_wait))
4104 wake_up_interruptible(&tty->write_wait);
4106 /* Can't hold any locks when calling tty_wakeup! */
4107 DGAP_UNLOCK(ch->ch_lock, lock_flags2);
4108 DGAP_UNLOCK(bd->bd_lock, lock_flags);
4111 /* pretend we didn't recognize this IOCTL */
4112 return -ENOIOCTLCMD;
4117 * The linux tty driver doesn't have a flush
4118 * input routine for the driver, assuming all backed
4119 * up data is in the line disc. buffers. However,
4120 * we all know that's not the case. Here, we
4121 * act on the ioctl, but then lie and say we didn't
4122 * so the line discipline will process the flush
4125 if (cmd == TCSETSF) {
4127 ch->ch_flags &= ~CH_STOP;
4128 head = readw(&(ch->ch_bs->rx_head));
4129 writew(head, &(ch->ch_bs->rx_tail));
4132 /* now wait for all the output to drain */
4133 DGAP_UNLOCK(ch->ch_lock, lock_flags2);
4134 DGAP_UNLOCK(bd->bd_lock, lock_flags);
4135 rc = dgap_wait_for_drain(tty);
4139 /* pretend we didn't recognize this */
4140 return -ENOIOCTLCMD;
4144 DGAP_UNLOCK(ch->ch_lock, lock_flags2);
4145 DGAP_UNLOCK(bd->bd_lock, lock_flags);
4146 rc = dgap_wait_for_drain(tty);
4150 /* pretend we didn't recognize this */
4151 return -ENOIOCTLCMD;
4155 * The Linux Line Discipline (LD) would do this for us if we
4156 * let it, but we have the special firmware options to do this
4157 * the "right way" regardless of hardware or software flow
4158 * control so we'll do it outselves instead of letting the LD
4161 rc = tty_check_change(tty);
4163 DGAP_UNLOCK(ch->ch_lock, lock_flags2);
4164 DGAP_UNLOCK(bd->bd_lock, lock_flags);
4171 DGAP_UNLOCK(ch->ch_lock, lock_flags2);
4172 DGAP_UNLOCK(bd->bd_lock, lock_flags);
4173 dgap_tty_start(tty);
4176 DGAP_UNLOCK(ch->ch_lock, lock_flags2);
4177 DGAP_UNLOCK(bd->bd_lock, lock_flags);
4181 DGAP_UNLOCK(ch->ch_lock, lock_flags2);
4182 DGAP_UNLOCK(bd->bd_lock, lock_flags);
4183 /* Make the ld do it */
4184 return -ENOIOCTLCMD;
4186 DGAP_UNLOCK(ch->ch_lock, lock_flags2);
4187 DGAP_UNLOCK(bd->bd_lock, lock_flags);
4188 /* Make the ld do it */
4189 return -ENOIOCTLCMD;
4191 DGAP_UNLOCK(ch->ch_lock, lock_flags2);
4192 DGAP_UNLOCK(bd->bd_lock, lock_flags);
4197 /* get information for ditty */
4198 DGAP_UNLOCK(ch->ch_lock, lock_flags2);
4199 DGAP_UNLOCK(bd->bd_lock, lock_flags);
4200 return dgap_tty_digigeta(tty, uarg);
4205 /* set information for ditty */
4206 if (cmd == (DIGI_SETAW)) {
4208 DGAP_UNLOCK(ch->ch_lock, lock_flags2);
4209 DGAP_UNLOCK(bd->bd_lock, lock_flags);
4210 rc = dgap_wait_for_drain(tty);
4213 DGAP_LOCK(bd->bd_lock, lock_flags);
4214 DGAP_LOCK(ch->ch_lock, lock_flags2);
4216 tty_ldisc_flush(tty);
4220 DGAP_UNLOCK(ch->ch_lock, lock_flags2);
4221 DGAP_UNLOCK(bd->bd_lock, lock_flags);
4222 return dgap_tty_digiseta(tty, uarg);
4225 DGAP_UNLOCK(ch->ch_lock, lock_flags2);
4226 DGAP_UNLOCK(bd->bd_lock, lock_flags);
4227 return dgap_tty_digigetedelay(tty, uarg);
4230 DGAP_UNLOCK(ch->ch_lock, lock_flags2);
4231 DGAP_UNLOCK(bd->bd_lock, lock_flags);
4232 return dgap_tty_digisetedelay(tty, uarg);
4234 case DIGI_GETCUSTOMBAUD:
4235 DGAP_UNLOCK(ch->ch_lock, lock_flags2);
4236 DGAP_UNLOCK(bd->bd_lock, lock_flags);
4237 return dgap_tty_digigetcustombaud(tty, uarg);
4239 case DIGI_SETCUSTOMBAUD:
4240 DGAP_UNLOCK(ch->ch_lock, lock_flags2);
4241 DGAP_UNLOCK(bd->bd_lock, lock_flags);
4242 return dgap_tty_digisetcustombaud(tty, uarg);
4244 case DIGI_RESET_PORT:
4245 dgap_firmware_reset_port(ch);
4247 DGAP_UNLOCK(ch->ch_lock, lock_flags2);
4248 DGAP_UNLOCK(bd->bd_lock, lock_flags);
4252 DGAP_UNLOCK(ch->ch_lock, lock_flags2);
4253 DGAP_UNLOCK(bd->bd_lock, lock_flags);
4255 return -ENOIOCTLCMD;
4259 static int dgap_after_config_loaded(int board)
4262 * Initialize KME waitqueues...
4264 init_waitqueue_head(&(dgap_Board[board]->kme_wait));
4267 * allocate flip buffer for board.
4269 dgap_Board[board]->flipbuf = kmalloc(MYFLIPLEN, GFP_ATOMIC);
4270 if (!dgap_Board[board]->flipbuf)
4273 dgap_Board[board]->flipflagbuf = kmalloc(MYFLIPLEN, GFP_ATOMIC);
4274 if (!dgap_Board[board]->flipflagbuf) {
4275 kfree(dgap_Board[board]->flipbuf);
4283 * Create pr and tty device entries
4285 static int dgap_tty_register_ports(struct board_t *brd)
4287 struct channel_t *ch;
4290 brd->SerialPorts = kcalloc(brd->nasync, sizeof(*brd->SerialPorts),
4292 if (brd->SerialPorts == NULL)
4294 for (i = 0; i < brd->nasync; i++)
4295 tty_port_init(&brd->SerialPorts[i]);
4297 brd->PrinterPorts = kcalloc(brd->nasync, sizeof(*brd->PrinterPorts),
4299 if (brd->PrinterPorts == NULL) {
4300 kfree(brd->SerialPorts);
4303 for (i = 0; i < brd->nasync; i++)
4304 tty_port_init(&brd->PrinterPorts[i]);
4306 ch = brd->channels[0];
4307 for (i = 0; i < brd->nasync; i++, ch = brd->channels[i]) {
4309 struct device *classp;
4311 classp = tty_port_register_device(&brd->SerialPorts[i],
4313 brd->firstminor + i, NULL);
4315 dgap_create_tty_sysfs(&ch->ch_tun, classp);
4316 ch->ch_tun.un_sysfs = classp;
4318 classp = tty_port_register_device(&brd->PrinterPorts[i],
4320 brd->firstminor + i, NULL);
4322 dgap_create_tty_sysfs(&ch->ch_pun, classp);
4323 ch->ch_pun.un_sysfs = classp;
4325 dgap_create_ports_sysfiles(brd);
4331 * Copies the BIOS code from the user to the board,
4332 * and starts the BIOS running.
4334 static void dgap_do_bios_load(struct board_t *brd, uchar __user *ubios, int len)
4340 if (!brd || (brd->magic != DGAP_BOARD_MAGIC) || !brd->re_map_membase)
4343 addr = brd->re_map_membase;
4348 for (i = 0; i < 16; i++)
4349 writeb(0, addr + POSTAREA + i);
4355 memcpy_toio(addr + offset, ubios, len);
4357 writel(0x0bf00401, addr);
4358 writel(0, (addr + 4));
4360 /* Clear the reset, and change states. */
4361 writeb(FEPCLR, brd->re_map_port);
4365 * Checks to see if the BIOS completed running on the card.
4367 static int dgap_do_wait_for_bios(struct board_t *brd)
4375 if (!brd || (brd->magic != DGAP_BOARD_MAGIC) || !brd->re_map_membase)
4378 addr = brd->re_map_membase;
4379 word = readw(addr + POSTAREA);
4382 * It can take 5-6 seconds for a board to
4383 * pass the bios self test and post results.
4384 * Give it 10 seconds.
4386 brd->wait_for_bios = 0;
4387 while (brd->wait_for_bios < 1000) {
4388 /* Check to see if BIOS thinks board is good. (GD). */
4389 if (word == *(u16 *) "GD")
4391 msleep_interruptible(10);
4392 brd->wait_for_bios++;
4393 word = readw(addr + POSTAREA);
4396 /* Gave up on board after too long of time taken */
4397 err1 = readw(addr + SEQUENCE);
4398 err2 = readw(addr + ERROR);
4399 pr_warn("dgap: %s failed diagnostics. Error #(%x,%x).\n",
4400 brd->name, err1, err2);
4401 brd->state = BOARD_FAILED;
4402 brd->dpastatus = BD_NOBIOS;
4408 * Copies the FEP code from the user to the board,
4409 * and starts the FEP running.
4411 static void dgap_do_fep_load(struct board_t *brd, uchar __user *ufep, int len)
4416 if (!brd || (brd->magic != DGAP_BOARD_MAGIC) || !brd->re_map_membase)
4419 addr = brd->re_map_membase;
4425 memcpy_toio(addr + offset, ufep, len);
4428 * If board is a concentrator product, we need to give
4429 * it its config string describing how the concentrators look.
4431 if ((brd->type == PCX) || (brd->type == PEPC)) {
4433 uchar *config, *xconfig;
4436 xconfig = dgap_create_config_string(brd, string);
4438 /* Write string to board memory */
4439 config = addr + CONFIG;
4440 for (; i < CONFIGSIZE; i++, config++, xconfig++) {
4441 writeb(*xconfig, config);
4442 if ((*xconfig & 0xff) == 0xff)
4447 writel(0xbfc01004, (addr + 0xc34));
4448 writel(0x3, (addr + 0xc30));
4453 * Waits for the FEP to report thats its ready for us to use.
4455 static int dgap_do_wait_for_fep(struct board_t *brd)
4463 if (!brd || (brd->magic != DGAP_BOARD_MAGIC) || !brd->re_map_membase)
4466 addr = brd->re_map_membase;
4467 word = readw(addr + FEPSTAT);
4470 * It can take 2-3 seconds for the FEP to
4471 * be up and running. Give it 5 secs.
4473 brd->wait_for_fep = 0;
4474 while (brd->wait_for_fep < 500) {
4475 /* Check to see if FEP is up and running now. */
4476 if (word == *(u16 *) "OS") {
4478 * Check to see if the board can support FEP5+ commands.
4480 word = readw(addr + FEP5_PLUS);
4481 if (word == *(u16 *) "5A")
4482 brd->bd_flags |= BD_FEP5PLUS;
4486 msleep_interruptible(10);
4487 brd->wait_for_fep++;
4488 word = readw(addr + FEPSTAT);
4491 /* Gave up on board after too long of time taken */
4492 err1 = readw(addr + SEQUENCE);
4493 err2 = readw(addr + ERROR);
4494 pr_warn("dgap: FEPOS for %s not functioning. Error #(%x,%x).\n",
4495 brd->name, err1, err2);
4496 brd->state = BOARD_FAILED;
4497 brd->dpastatus = BD_NOFEP;
4503 * Physically forces the FEP5 card to reset itself.
4505 static void dgap_do_reset_board(struct board_t *brd)
4512 if (!brd || (brd->magic != DGAP_BOARD_MAGIC) ||
4513 !brd->re_map_membase || !brd->re_map_port)
4516 /* FEPRST does not vary among supported boards */
4517 writeb(FEPRST, brd->re_map_port);
4519 for (i = 0; i <= 1000; i++) {
4520 check = readb(brd->re_map_port) & 0xe;
4521 if (check == FEPRST)
4527 pr_warn("dgap: Board not resetting... Failing board.\n");
4528 brd->state = BOARD_FAILED;
4529 brd->dpastatus = BD_NOFEP;
4534 * Make sure there really is memory out there.
4536 writel(0xa55a3cc3, (brd->re_map_membase + LOWMEM));
4537 writel(0x5aa5c33c, (brd->re_map_membase + HIGHMEM));
4538 check1 = readl(brd->re_map_membase + LOWMEM);
4539 check2 = readl(brd->re_map_membase + HIGHMEM);
4541 if ((check1 != 0xa55a3cc3) || (check2 != 0x5aa5c33c)) {
4542 pr_warn("dgap: No memory at %p for board.\n",
4543 brd->re_map_membase);
4544 brd->state = BOARD_FAILED;
4545 brd->dpastatus = BD_NOFEP;
4551 #ifdef DIGI_CONCENTRATORS_SUPPORTED
4553 * Sends a concentrator image into the FEP5 board.
4555 static void dgap_do_conc_load(struct board_t *brd, uchar *uaddr, int len)
4559 struct downld_t *to_dp;
4561 if (!brd || (brd->magic != DGAP_BOARD_MAGIC) || !brd->re_map_membase)
4564 vaddr = brd->re_map_membase;
4566 offset = readw((u16 *) (vaddr + DOWNREQ));
4567 to_dp = (struct downld_t *) (vaddr + (int) offset);
4568 memcpy_toio(to_dp, uaddr, len);
4570 /* Tell card we have data for it */
4571 writew(0, vaddr + (DOWNREQ));
4573 brd->conc_dl_status = NO_PENDING_CONCENTRATOR_REQUESTS;
4577 #define EXPANSION_ROM_SIZE (64 * 1024)
4578 #define FEP5_ROM_MAGIC (0xFEFFFFFF)
4580 static void dgap_get_vpd(struct board_t *brd)
4592 * Poke the magic number at the PCI Rom Address location.
4593 * If VPD is supported, the value read from that address
4596 magic = FEP5_ROM_MAGIC;
4597 pci_write_config_dword(brd->pdev, PCI_ROM_ADDRESS, magic);
4598 pci_read_config_dword(brd->pdev, PCI_ROM_ADDRESS, &magic);
4600 /* VPD not supported, bail */
4605 * To get to the OTPROM memory, we have to send the boards base
4606 * address or'ed with 1 into the PCI Rom Address location.
4608 magic = brd->membase | 0x01;
4609 pci_write_config_dword(brd->pdev, PCI_ROM_ADDRESS, magic);
4610 pci_read_config_dword(brd->pdev, PCI_ROM_ADDRESS, &magic);
4612 byte1 = readb(brd->re_map_membase);
4613 byte2 = readb(brd->re_map_membase + 1);
4616 * If the board correctly swapped to the OTPROM memory,
4617 * the first 2 bytes (header) should be 0x55, 0xAA
4619 if (byte1 == 0x55 && byte2 == 0xAA) {
4624 * We have to run through all the OTPROM memory looking
4625 * for the VPD offset.
4627 while (base_offset <= EXPANSION_ROM_SIZE) {
4630 * Lots of magic numbers here.
4632 * The VPD offset is located inside the ROM Data
4635 * We also have to remember the length of each
4636 * ROM Data Structure, so we can "hop" to the next
4637 * entry if the VPD isn't in the current
4638 * ROM Data Structure.
4640 rom_offset = readw(brd->re_map_membase +
4641 base_offset + 0x18);
4642 image_length = readw(brd->re_map_membase +
4643 rom_offset + 0x10) * 512;
4644 vpd_offset = readw(brd->re_map_membase +
4647 /* Found the VPD entry */
4651 /* We didn't find a VPD entry, go to next ROM entry. */
4652 base_offset += image_length;
4654 byte1 = readb(brd->re_map_membase + base_offset);
4655 byte2 = readb(brd->re_map_membase + base_offset + 1);
4658 * If the new ROM offset doesn't have 0x55, 0xAA
4659 * as its header, we have run out of ROM.
4661 if (byte1 != 0x55 || byte2 != 0xAA)
4666 * If we have a VPD offset, then mark the board
4667 * as having a valid VPD, and copy VPDSIZE (512) bytes of
4668 * that VPD to the buffer we have in our board structure.
4671 brd->bd_flags |= BD_HAS_VPD;
4672 for (i = 0; i < VPDSIZE; i++) {
4673 brd->vpd[i] = readb(brd->re_map_membase +
4680 * We MUST poke the magic number at the PCI Rom Address location again.
4681 * This makes the card report the regular board memory back to us,
4682 * rather than the OTPROM memory.
4684 magic = FEP5_ROM_MAGIC;
4685 pci_write_config_dword(brd->pdev, PCI_ROM_ADDRESS, magic);
4689 * Our board poller function.
4691 static void dgap_poll_tasklet(unsigned long data)
4693 struct board_t *bd = (struct board_t *) data;
4698 if (!bd || (bd->magic != DGAP_BOARD_MAGIC))
4701 if (bd->inhibit_poller)
4704 DGAP_LOCK(bd->bd_lock, lock_flags);
4706 vaddr = bd->re_map_membase;
4709 * If board is ready, parse deeper to see if there is anything to do.
4711 if (bd->state == BOARD_READY) {
4713 struct ev_t *eaddr = NULL;
4715 if (!bd->re_map_membase) {
4716 DGAP_UNLOCK(bd->bd_lock, lock_flags);
4719 if (!bd->re_map_port) {
4720 DGAP_UNLOCK(bd->bd_lock, lock_flags);
4727 eaddr = (struct ev_t *) (vaddr + EVBUF);
4729 /* Get our head and tail */
4730 head = readw(&(eaddr->ev_head));
4731 tail = readw(&(eaddr->ev_tail));
4734 * If there is an event pending. Go service it.
4737 DGAP_UNLOCK(bd->bd_lock, lock_flags);
4739 DGAP_LOCK(bd->bd_lock, lock_flags);
4744 * If board is doing interrupts, ACK the interrupt.
4746 if (bd && bd->intr_running)
4747 readb(bd->re_map_port + 2);
4749 DGAP_UNLOCK(bd->bd_lock, lock_flags);
4753 DGAP_UNLOCK(bd->bd_lock, lock_flags);
4756 /*=======================================================================
4758 * dgap_cmdb - Sends a 2 byte command to the FEP.
4760 * ch - Pointer to channel structure.
4761 * cmd - Command to be sent.
4762 * byte1 - Integer containing first byte to be sent.
4763 * byte2 - Integer containing second byte to be sent.
4764 * ncmds - Wait until ncmds or fewer cmds are left
4765 * in the cmd buffer before returning.
4767 *=======================================================================*/
4768 static void dgap_cmdb(struct channel_t *ch, uchar cmd, uchar byte1,
4769 uchar byte2, uint ncmds)
4772 struct cm_t *cm_addr = NULL;
4778 if (!ch || ch->magic != DGAP_CHANNEL_MAGIC)
4782 * Check if board is still alive.
4784 if (ch->ch_bd->state == BOARD_FAILED)
4788 * Make sure the pointers are in range before
4789 * writing to the FEP memory.
4791 vaddr = ch->ch_bd->re_map_membase;
4796 cm_addr = (struct cm_t *) (vaddr + CMDBUF);
4797 head = readw(&(cm_addr->cm_head));
4800 * Forget it if pointers out of range.
4802 if (head >= (CMDMAX - CMDSTART) || (head & 03)) {
4803 ch->ch_bd->state = BOARD_FAILED;
4808 * Put the data in the circular command buffer.
4810 writeb(cmd, (char *) (vaddr + head + CMDSTART + 0));
4811 writeb((uchar) ch->ch_portnum, (char *) (vaddr + head + CMDSTART + 1));
4812 writeb(byte1, (char *) (vaddr + head + CMDSTART + 2));
4813 writeb(byte2, (char *) (vaddr + head + CMDSTART + 3));
4815 head = (head + 4) & (CMDMAX - CMDSTART - 4);
4817 writew(head, &(cm_addr->cm_head));
4820 * Wait if necessary before updating the head
4821 * pointer to limit the number of outstanding
4822 * commands to the FEP. If the time spent waiting
4823 * is outlandish, declare the FEP dead.
4825 for (count = dgap_count ;;) {
4827 head = readw(&(cm_addr->cm_head));
4828 tail = readw(&(cm_addr->cm_tail));
4830 n = (head - tail) & (CMDMAX - CMDSTART - 4);
4832 if (n <= ncmds * sizeof(struct cm_t))
4836 ch->ch_bd->state = BOARD_FAILED;
4843 /*=======================================================================
4845 * dgap_cmdw - Sends a 1 word command to the FEP.
4847 * ch - Pointer to channel structure.
4848 * cmd - Command to be sent.
4849 * word - Integer containing word to be sent.
4850 * ncmds - Wait until ncmds or fewer cmds are left
4851 * in the cmd buffer before returning.
4853 *=======================================================================*/
4854 static void dgap_cmdw(struct channel_t *ch, uchar cmd, u16 word, uint ncmds)
4857 struct cm_t *cm_addr = NULL;
4863 if (!ch || ch->magic != DGAP_CHANNEL_MAGIC)
4867 * Check if board is still alive.
4869 if (ch->ch_bd->state == BOARD_FAILED)
4873 * Make sure the pointers are in range before
4874 * writing to the FEP memory.
4876 vaddr = ch->ch_bd->re_map_membase;
4880 cm_addr = (struct cm_t *) (vaddr + CMDBUF);
4881 head = readw(&(cm_addr->cm_head));
4884 * Forget it if pointers out of range.
4886 if (head >= (CMDMAX - CMDSTART) || (head & 03)) {
4887 ch->ch_bd->state = BOARD_FAILED;
4892 * Put the data in the circular command buffer.
4894 writeb(cmd, (char *) (vaddr + head + CMDSTART + 0));
4895 writeb((uchar) ch->ch_portnum, (char *) (vaddr + head + CMDSTART + 1));
4896 writew((u16) word, (char *) (vaddr + head + CMDSTART + 2));
4898 head = (head + 4) & (CMDMAX - CMDSTART - 4);
4900 writew(head, &(cm_addr->cm_head));
4903 * Wait if necessary before updating the head
4904 * pointer to limit the number of outstanding
4905 * commands to the FEP. If the time spent waiting
4906 * is outlandish, declare the FEP dead.
4908 for (count = dgap_count ;;) {
4910 head = readw(&(cm_addr->cm_head));
4911 tail = readw(&(cm_addr->cm_tail));
4913 n = (head - tail) & (CMDMAX - CMDSTART - 4);
4915 if (n <= ncmds * sizeof(struct cm_t))
4919 ch->ch_bd->state = BOARD_FAILED;
4926 /*=======================================================================
4928 * dgap_cmdw_ext - Sends a extended word command to the FEP.
4930 * ch - Pointer to channel structure.
4931 * cmd - Command to be sent.
4932 * word - Integer containing word to be sent.
4933 * ncmds - Wait until ncmds or fewer cmds are left
4934 * in the cmd buffer before returning.
4936 *=======================================================================*/
4937 static void dgap_cmdw_ext(struct channel_t *ch, u16 cmd, u16 word, uint ncmds)
4940 struct cm_t *cm_addr = NULL;
4946 if (!ch || ch->magic != DGAP_CHANNEL_MAGIC)
4950 * Check if board is still alive.
4952 if (ch->ch_bd->state == BOARD_FAILED)
4956 * Make sure the pointers are in range before
4957 * writing to the FEP memory.
4959 vaddr = ch->ch_bd->re_map_membase;
4963 cm_addr = (struct cm_t *) (vaddr + CMDBUF);
4964 head = readw(&(cm_addr->cm_head));
4967 * Forget it if pointers out of range.
4969 if (head >= (CMDMAX - CMDSTART) || (head & 03)) {
4970 ch->ch_bd->state = BOARD_FAILED;
4975 * Put the data in the circular command buffer.
4978 /* Write an FF to tell the FEP that we want an extended command */
4979 writeb((uchar) 0xff, (char *) (vaddr + head + CMDSTART + 0));
4981 writeb((uchar) ch->ch_portnum, (uchar *) (vaddr + head + CMDSTART + 1));
4982 writew((u16) cmd, (char *) (vaddr + head + CMDSTART + 2));
4985 * If the second part of the command won't fit,
4986 * put it at the beginning of the circular buffer.
4988 if (((head + 4) >= ((CMDMAX - CMDSTART)) || (head & 03)))
4989 writew((u16) word, (char *) (vaddr + CMDSTART));
4991 writew((u16) word, (char *) (vaddr + head + CMDSTART + 4));
4993 head = (head + 8) & (CMDMAX - CMDSTART - 4);
4995 writew(head, &(cm_addr->cm_head));
4998 * Wait if necessary before updating the head
4999 * pointer to limit the number of outstanding
5000 * commands to the FEP. If the time spent waiting
5001 * is outlandish, declare the FEP dead.
5003 for (count = dgap_count ;;) {
5005 head = readw(&(cm_addr->cm_head));
5006 tail = readw(&(cm_addr->cm_tail));
5008 n = (head - tail) & (CMDMAX - CMDSTART - 4);
5010 if (n <= ncmds * sizeof(struct cm_t))
5014 ch->ch_bd->state = BOARD_FAILED;
5021 /*=======================================================================
5023 * dgap_wmove - Write data to FEP buffer.
5025 * ch - Pointer to channel structure.
5026 * buf - Poiter to characters to be moved.
5027 * cnt - Number of characters to move.
5029 *=======================================================================*/
5030 static void dgap_wmove(struct channel_t *ch, char *buf, uint cnt)
5037 if (!ch || ch->magic != DGAP_CHANNEL_MAGIC)
5044 head = readw(&(bs->tx_head));
5047 * If pointers are out of range, just return.
5049 if ((cnt > ch->ch_tsize) ||
5050 (unsigned)(head - ch->ch_tstart) >= ch->ch_tsize)
5054 * If the write wraps over the top of the circular buffer,
5055 * move the portion up to the wrap point, and reset the
5056 * pointers to the bottom.
5058 n = ch->ch_tstart + ch->ch_tsize - head;
5062 taddr = ch->ch_taddr + head;
5063 memcpy_toio(taddr, buf, n);
5064 head = ch->ch_tstart;
5069 * Move rest of data.
5071 taddr = ch->ch_taddr + head;
5073 memcpy_toio(taddr, buf, n);
5076 writew(head, &(bs->tx_head));
5080 * Retrives the current custom baud rate from FEP memory,
5081 * and returns it back to the user.
5082 * Returns 0 on error.
5084 static uint dgap_get_custom_baud(struct channel_t *ch)
5090 if (!ch || ch->magic != DGAP_CHANNEL_MAGIC)
5093 if (!ch->ch_bd || ch->ch_bd->magic != DGAP_BOARD_MAGIC)
5096 if (!(ch->ch_bd->bd_flags & BD_FEP5PLUS))
5099 vaddr = ch->ch_bd->re_map_membase;
5105 * Go get from fep mem, what the fep
5106 * believes the custom baud rate is.
5108 offset = ((((*(unsigned short *)(vaddr + ECS_SEG)) << 4) +
5109 (ch->ch_portnum * 0x28) + LINE_SPEED));
5111 value = readw(vaddr + offset);
5116 * Calls the firmware to reset this channel.
5118 static void dgap_firmware_reset_port(struct channel_t *ch)
5120 dgap_cmdb(ch, CHRESET, 0, 0, 0);
5123 * Now that the channel is reset, we need to make sure
5124 * all the current settings get reapplied to the port
5127 * So we will set the driver's cache of firmware
5128 * settings all to 0, and then call param.
5130 ch->ch_fepiflag = 0;
5131 ch->ch_fepcflag = 0;
5132 ch->ch_fepoflag = 0;
5133 ch->ch_fepstartc = 0;
5134 ch->ch_fepstopc = 0;
5135 ch->ch_fepastartc = 0;
5136 ch->ch_fepastopc = 0;
5141 /*=======================================================================
5143 * dgap_param - Set Digi parameters.
5145 * struct tty_struct * - TTY for port.
5147 *=======================================================================*/
5148 static int dgap_param(struct tty_struct *tty)
5150 struct ktermios *ts;
5152 struct channel_t *ch;
5161 if (!tty || tty->magic != TTY_MAGIC)
5164 un = (struct un_t *) tty->driver_data;
5165 if (!un || un->magic != DGAP_UNIT_MAGIC)
5169 if (!ch || ch->magic != DGAP_CHANNEL_MAGIC)
5173 if (!bd || bd->magic != DGAP_BOARD_MAGIC)
5183 * If baud rate is zero, flush queues, and set mval to drop DTR.
5185 if ((ch->ch_c_cflag & (CBAUD)) == 0) {
5188 head = readw(&(ch->ch_bs->rx_head));
5189 writew(head, &(ch->ch_bs->rx_tail));
5192 head = readw(&(ch->ch_bs->tx_head));
5193 writew(head, &(ch->ch_bs->tx_tail));
5195 ch->ch_flags |= (CH_BAUD0);
5197 /* Drop RTS and DTR */
5198 ch->ch_mval &= ~(D_RTS(ch)|D_DTR(ch));
5199 mval = D_DTR(ch) | D_RTS(ch);
5200 ch->ch_baud_info = 0;
5202 } else if (ch->ch_custom_speed && (bd->bd_flags & BD_FEP5PLUS)) {
5204 * Tell the fep to do the command
5207 dgap_cmdw_ext(ch, 0xff01, ch->ch_custom_speed, 0);
5210 * Now go get from fep mem, what the fep
5211 * believes the custom baud rate is.
5213 ch->ch_custom_speed = dgap_get_custom_baud(ch);
5214 ch->ch_baud_info = ch->ch_custom_speed;
5216 /* Handle transition from B0 */
5217 if (ch->ch_flags & CH_BAUD0) {
5218 ch->ch_flags &= ~(CH_BAUD0);
5219 ch->ch_mval |= (D_RTS(ch)|D_DTR(ch));
5221 mval = D_DTR(ch) | D_RTS(ch);
5225 * Set baud rate, character size, and parity.
5233 ulong bauds[4][16] = {
5237 600, 1200, 1800, 2400,
5238 4800, 9600, 19200, 38400 },
5239 { /* slowbaud & CBAUDEX */
5240 0, 57600, 115200, 230400,
5241 460800, 150, 200, 921600,
5242 600, 1200, 1800, 2400,
5243 4800, 9600, 19200, 38400 },
5245 0, 57600, 76800, 115200,
5246 14400, 57600, 230400, 76800,
5247 115200, 230400, 28800, 460800,
5248 921600, 9600, 19200, 38400 },
5249 { /* fastbaud & CBAUDEX */
5250 0, 57600, 115200, 230400,
5251 460800, 150, 200, 921600,
5252 600, 1200, 1800, 2400,
5253 4800, 9600, 19200, 38400 }
5257 * Only use the TXPrint baud rate if the
5258 * terminal unit is NOT open
5260 if (!(ch->ch_tun.un_flags & UN_ISOPEN) &&
5261 (un->un_type == DGAP_PRINT))
5262 baud = C_BAUD(ch->ch_pun.un_tty) & 0xff;
5264 baud = C_BAUD(ch->ch_tun.un_tty) & 0xff;
5266 if (ch->ch_c_cflag & CBAUDEX)
5269 if (ch->ch_digi.digi_flags & DIGI_FAST)
5274 if ((iindex >= 0) && (iindex < 4) &&
5275 (jindex >= 0) && (jindex < 16))
5276 baud = bauds[iindex][jindex];
5283 ch->ch_baud_info = baud;
5286 * CBAUD has bit position 0x1000 set these days to
5287 * indicate Linux baud rate remap.
5288 * We use a different bit assignment for high speed.
5289 * Clear this bit out while grabbing the parts of
5292 cflag = ch->ch_c_cflag & ((CBAUD ^ CBAUDEX) | PARODD | PARENB |
5296 * HUPCL bit is used by FEP to indicate fast baud
5297 * table is to be used.
5299 if ((ch->ch_digi.digi_flags & DIGI_FAST) ||
5300 (ch->ch_c_cflag & CBAUDEX))
5303 if ((ch->ch_c_cflag & CBAUDEX) &&
5304 !(ch->ch_digi.digi_flags & DIGI_FAST)) {
5306 * The below code is trying to guarantee that only
5307 * baud rates 115200, 230400, 460800, 921600 are
5308 * remapped. We use exclusive or because the various
5309 * baud rates share common bit positions and therefore
5310 * can't be tested for easily.
5312 tcflag_t tcflag = (ch->ch_c_cflag & CBAUD) | CBAUDEX;
5316 * Map high speed requests to index
5317 * into FEP's baud table
5347 cflag = (cflag & ~(CBAUD | CBAUDEX)) | baudpart;
5352 if (cflag != ch->ch_fepcflag) {
5353 ch->ch_fepcflag = (u16) (cflag & 0xffff);
5356 * Okay to have channel and board
5357 * locks held calling this
5359 dgap_cmdw(ch, SCFLAG, (u16) cflag, 0);
5362 /* Handle transition from B0 */
5363 if (ch->ch_flags & CH_BAUD0) {
5364 ch->ch_flags &= ~(CH_BAUD0);
5365 ch->ch_mval |= (D_RTS(ch)|D_DTR(ch));
5367 mval = D_DTR(ch) | D_RTS(ch);
5373 iflag = ch->ch_c_iflag & (IGNBRK | BRKINT | IGNPAR | PARMRK |
5374 INPCK | ISTRIP | IXON | IXANY | IXOFF);
5376 if ((ch->ch_startc == _POSIX_VDISABLE) ||
5377 (ch->ch_stopc == _POSIX_VDISABLE)) {
5378 iflag &= ~(IXON | IXOFF);
5379 ch->ch_c_iflag &= ~(IXON | IXOFF);
5383 * Only the IBM Xr card can switch between
5384 * 232 and 422 modes on the fly
5386 if (bd->device == PCI_DEV_XR_IBM_DID) {
5387 if (ch->ch_digi.digi_flags & DIGI_422)
5388 dgap_cmdb(ch, SCOMMODE, MODE_422, 0, 0);
5390 dgap_cmdb(ch, SCOMMODE, MODE_232, 0, 0);
5393 if (ch->ch_digi.digi_flags & DIGI_ALTPIN)
5396 if (iflag != ch->ch_fepiflag) {
5397 ch->ch_fepiflag = iflag;
5399 /* Okay to have channel and board locks held calling this */
5400 dgap_cmdw(ch, SIFLAG, (u16) ch->ch_fepiflag, 0);
5404 * Select hardware handshaking.
5408 if (ch->ch_c_cflag & CRTSCTS)
5409 hflow |= (D_RTS(ch) | D_CTS(ch));
5410 if (ch->ch_digi.digi_flags & RTSPACE)
5412 if (ch->ch_digi.digi_flags & DTRPACE)
5414 if (ch->ch_digi.digi_flags & CTSPACE)
5416 if (ch->ch_digi.digi_flags & DSRPACE)
5418 if (ch->ch_digi.digi_flags & DCDPACE)
5421 if (hflow != ch->ch_hflow) {
5422 ch->ch_hflow = hflow;
5424 /* Okay to have channel and board locks held calling this */
5425 dgap_cmdb(ch, SHFLOW, (uchar) hflow, 0xff, 0);
5430 * Set RTS and/or DTR Toggle if needed,
5431 * but only if product is FEP5+ based.
5433 if (bd->bd_flags & BD_FEP5PLUS) {
5435 if (ch->ch_digi.digi_flags & DIGI_RTS_TOGGLE)
5436 hflow2 |= (D_RTS(ch));
5437 if (ch->ch_digi.digi_flags & DIGI_DTR_TOGGLE)
5438 hflow2 |= (D_DTR(ch));
5440 dgap_cmdw_ext(ch, 0xff03, hflow2, 0);
5444 * Set modem control lines.
5447 mval ^= ch->ch_mforce & (mval ^ ch->ch_mval);
5449 if (ch->ch_mostat ^ mval) {
5450 ch->ch_mostat = mval;
5452 /* Okay to have channel and board locks held calling this */
5453 dgap_cmdb(ch, SMODEM, (uchar) mval, D_RTS(ch)|D_DTR(ch), 0);
5457 * Read modem signals, and then call carrier function.
5459 ch->ch_mistat = readb(&(bs->m_stat));
5463 * Set the start and stop characters.
5465 if (ch->ch_startc != ch->ch_fepstartc ||
5466 ch->ch_stopc != ch->ch_fepstopc) {
5467 ch->ch_fepstartc = ch->ch_startc;
5468 ch->ch_fepstopc = ch->ch_stopc;
5470 /* Okay to have channel and board locks held calling this */
5471 dgap_cmdb(ch, SFLOWC, ch->ch_fepstartc, ch->ch_fepstopc, 0);
5475 * Set the Auxiliary start and stop characters.
5477 if (ch->ch_astartc != ch->ch_fepastartc ||
5478 ch->ch_astopc != ch->ch_fepastopc) {
5479 ch->ch_fepastartc = ch->ch_astartc;
5480 ch->ch_fepastopc = ch->ch_astopc;
5482 /* Okay to have channel and board locks held calling this */
5483 dgap_cmdb(ch, SAFLOWC, ch->ch_fepastartc, ch->ch_fepastopc, 0);
5490 * dgap_parity_scan()
5492 * Convert the FEP5 way of reporting parity errors and breaks into
5493 * the Linux line discipline way.
5495 static void dgap_parity_scan(struct channel_t *ch, unsigned char *cbuf,
5496 unsigned char *fbuf, int *len)
5500 unsigned char *in, *cout, *fout;
5507 if (!ch || ch->magic != DGAP_CHANNEL_MAGIC)
5512 switch (ch->pscan_state) {
5514 /* reset to sanity and fall through */
5515 ch->pscan_state = 0;
5518 /* No FF seen yet */
5519 if (c == (unsigned char) '\377')
5520 /* delete this character from stream */
5521 ch->pscan_state = 1;
5524 *fout++ = TTY_NORMAL;
5531 if (c == (unsigned char) '\377') {
5532 /* doubled ff, transform to single ff */
5534 *fout++ = TTY_NORMAL;
5536 ch->pscan_state = 0;
5538 /* save value examination in next state */
5539 ch->pscan_savechar = c;
5540 ch->pscan_state = 2;
5545 /* third character of ff sequence */
5549 if (ch->pscan_savechar == 0x0) {
5553 *fout++ = TTY_BREAK;
5555 ch->ch_err_parity++;
5556 *fout++ = TTY_PARITY;
5561 ch->pscan_state = 0;
5567 /*=======================================================================
5569 * dgap_event - FEP to host event processing routine.
5571 * bd - Board of current event.
5573 *=======================================================================*/
5574 static int dgap_event(struct board_t *bd)
5576 struct channel_t *ch;
5581 uchar *vaddr = NULL;
5582 struct ev_t *eaddr = NULL;
5590 if (!bd || bd->magic != DGAP_BOARD_MAGIC)
5593 DGAP_LOCK(bd->bd_lock, lock_flags);
5595 vaddr = bd->re_map_membase;
5598 DGAP_UNLOCK(bd->bd_lock, lock_flags);
5602 eaddr = (struct ev_t *) (vaddr + EVBUF);
5604 /* Get our head and tail */
5605 head = readw(&(eaddr->ev_head));
5606 tail = readw(&(eaddr->ev_tail));
5609 * Forget it if pointers out of range.
5612 if (head >= EVMAX - EVSTART || tail >= EVMAX - EVSTART ||
5613 (head | tail) & 03) {
5614 /* Let go of board lock */
5615 DGAP_UNLOCK(bd->bd_lock, lock_flags);
5620 * Loop to process all the events in the buffer.
5622 while (tail != head) {
5625 * Get interrupt information.
5628 event = bd->re_map_membase + tail + EVSTART;
5636 * Make sure the interrupt is valid.
5638 if (port >= bd->nasync)
5641 if (!(reason & (IFMODEM | IFBREAK | IFTLW | IFTEM | IFDATA)))
5644 ch = bd->channels[port];
5646 if (!ch || ch->magic != DGAP_CHANNEL_MAGIC)
5650 * If we have made it here, the event was valid.
5651 * Lock down the channel.
5653 DGAP_LOCK(ch->ch_lock, lock_flags2);
5658 DGAP_UNLOCK(ch->ch_lock, lock_flags2);
5663 * Process received data.
5665 if (reason & IFDATA) {
5668 * ALL LOCKS *MUST* BE DROPPED BEFORE CALLING INPUT!
5669 * input could send some data to ld, which in turn
5670 * could do a callback to one of our other functions.
5672 DGAP_UNLOCK(ch->ch_lock, lock_flags2);
5673 DGAP_UNLOCK(bd->bd_lock, lock_flags);
5677 DGAP_LOCK(bd->bd_lock, lock_flags);
5678 DGAP_LOCK(ch->ch_lock, lock_flags2);
5680 if (ch->ch_flags & CH_RACTIVE)
5681 ch->ch_flags |= CH_RENABLE;
5683 writeb(1, &(bs->idata));
5685 if (ch->ch_flags & CH_RWAIT) {
5686 ch->ch_flags &= ~CH_RWAIT;
5688 wake_up_interruptible
5689 (&ch->ch_tun.un_flags_wait);
5694 * Process Modem change signals.
5696 if (reason & IFMODEM) {
5697 ch->ch_mistat = modem;
5704 if (reason & IFBREAK) {
5706 if (ch->ch_tun.un_tty) {
5707 /* A break has been indicated */
5709 tty_buffer_request_room
5710 (ch->ch_tun.un_tty->port, 1);
5711 tty_insert_flip_char(ch->ch_tun.un_tty->port,
5713 tty_flip_buffer_push(ch->ch_tun.un_tty->port);
5718 * Process Transmit low.
5720 if (reason & IFTLW) {
5722 if (ch->ch_tun.un_flags & UN_LOW) {
5723 ch->ch_tun.un_flags &= ~UN_LOW;
5725 if (ch->ch_tun.un_flags & UN_ISOPEN) {
5726 if ((ch->ch_tun.un_tty->flags &
5727 (1 << TTY_DO_WRITE_WAKEUP)) &&
5728 ch->ch_tun.un_tty->ldisc->ops->write_wakeup) {
5729 DGAP_UNLOCK(ch->ch_lock, lock_flags2);
5730 DGAP_UNLOCK(bd->bd_lock, lock_flags);
5731 (ch->ch_tun.un_tty->ldisc->ops->write_wakeup)(ch->ch_tun.un_tty);
5732 DGAP_LOCK(bd->bd_lock, lock_flags);
5733 DGAP_LOCK(ch->ch_lock, lock_flags2);
5735 wake_up_interruptible(&ch->ch_tun.un_tty->write_wait);
5736 wake_up_interruptible(&ch->ch_tun.un_flags_wait);
5740 if (ch->ch_pun.un_flags & UN_LOW) {
5741 ch->ch_pun.un_flags &= ~UN_LOW;
5742 if (ch->ch_pun.un_flags & UN_ISOPEN) {
5743 if ((ch->ch_pun.un_tty->flags &
5744 (1 << TTY_DO_WRITE_WAKEUP)) &&
5745 ch->ch_pun.un_tty->ldisc->ops->write_wakeup) {
5746 DGAP_UNLOCK(ch->ch_lock, lock_flags2);
5747 DGAP_UNLOCK(bd->bd_lock, lock_flags);
5748 (ch->ch_pun.un_tty->ldisc->ops->write_wakeup)(ch->ch_pun.un_tty);
5749 DGAP_LOCK(bd->bd_lock, lock_flags);
5750 DGAP_LOCK(ch->ch_lock, lock_flags2);
5752 wake_up_interruptible(&ch->ch_pun.un_tty->write_wait);
5753 wake_up_interruptible(&ch->ch_pun.un_flags_wait);
5757 if (ch->ch_flags & CH_WLOW) {
5758 ch->ch_flags &= ~CH_WLOW;
5759 wake_up_interruptible(&ch->ch_flags_wait);
5764 * Process Transmit empty.
5766 if (reason & IFTEM) {
5767 if (ch->ch_tun.un_flags & UN_EMPTY) {
5768 ch->ch_tun.un_flags &= ~UN_EMPTY;
5769 if (ch->ch_tun.un_flags & UN_ISOPEN) {
5770 if ((ch->ch_tun.un_tty->flags &
5771 (1 << TTY_DO_WRITE_WAKEUP)) &&
5772 ch->ch_tun.un_tty->ldisc->ops->write_wakeup) {
5773 DGAP_UNLOCK(ch->ch_lock, lock_flags2);
5774 DGAP_UNLOCK(bd->bd_lock, lock_flags);
5776 (ch->ch_tun.un_tty->ldisc->ops->write_wakeup)(ch->ch_tun.un_tty);
5777 DGAP_LOCK(bd->bd_lock, lock_flags);
5778 DGAP_LOCK(ch->ch_lock, lock_flags2);
5780 wake_up_interruptible(&ch->ch_tun.un_tty->write_wait);
5781 wake_up_interruptible(&ch->ch_tun.un_flags_wait);
5785 if (ch->ch_pun.un_flags & UN_EMPTY) {
5786 ch->ch_pun.un_flags &= ~UN_EMPTY;
5787 if (ch->ch_pun.un_flags & UN_ISOPEN) {
5788 if ((ch->ch_pun.un_tty->flags &
5789 (1 << TTY_DO_WRITE_WAKEUP)) &&
5790 ch->ch_pun.un_tty->ldisc->ops->write_wakeup) {
5791 DGAP_UNLOCK(ch->ch_lock, lock_flags2);
5792 DGAP_UNLOCK(bd->bd_lock, lock_flags);
5793 (ch->ch_pun.un_tty->ldisc->ops->write_wakeup)(ch->ch_pun.un_tty);
5794 DGAP_LOCK(bd->bd_lock, lock_flags);
5795 DGAP_LOCK(ch->ch_lock, lock_flags2);
5797 wake_up_interruptible(&ch->ch_pun.un_tty->write_wait);
5798 wake_up_interruptible(&ch->ch_pun.un_flags_wait);
5803 if (ch->ch_flags & CH_WEMPTY) {
5804 ch->ch_flags &= ~CH_WEMPTY;
5805 wake_up_interruptible(&ch->ch_flags_wait);
5809 DGAP_UNLOCK(ch->ch_lock, lock_flags2);
5812 tail = (tail + 4) & (EVMAX - EVSTART - 4);
5815 writew(tail, &(eaddr->ev_tail));
5816 DGAP_UNLOCK(bd->bd_lock, lock_flags);
5821 static ssize_t dgap_driver_version_show(struct device_driver *ddp, char *buf)
5823 return snprintf(buf, PAGE_SIZE, "%s\n", DG_PART);
5825 static DRIVER_ATTR(version, S_IRUSR, dgap_driver_version_show, NULL);
5828 static ssize_t dgap_driver_boards_show(struct device_driver *ddp, char *buf)
5830 return snprintf(buf, PAGE_SIZE, "%d\n", dgap_NumBoards);
5832 static DRIVER_ATTR(boards, S_IRUSR, dgap_driver_boards_show, NULL);
5835 static ssize_t dgap_driver_maxboards_show(struct device_driver *ddp, char *buf)
5837 return snprintf(buf, PAGE_SIZE, "%d\n", MAXBOARDS);
5839 static DRIVER_ATTR(maxboards, S_IRUSR, dgap_driver_maxboards_show, NULL);
5842 static ssize_t dgap_driver_pollcounter_show(struct device_driver *ddp,
5845 return snprintf(buf, PAGE_SIZE, "%ld\n", dgap_poll_counter);
5847 static DRIVER_ATTR(pollcounter, S_IRUSR, dgap_driver_pollcounter_show, NULL);
5849 static ssize_t dgap_driver_pollrate_show(struct device_driver *ddp, char *buf)
5851 return snprintf(buf, PAGE_SIZE, "%dms\n", dgap_poll_tick);
5854 static ssize_t dgap_driver_pollrate_store(struct device_driver *ddp,
5855 const char *buf, size_t count)
5857 if (sscanf(buf, "%d\n", &dgap_poll_tick) != 1)
5861 static DRIVER_ATTR(pollrate, (S_IRUSR | S_IWUSR), dgap_driver_pollrate_show,
5862 dgap_driver_pollrate_store);
5864 static int dgap_create_driver_sysfiles(struct pci_driver *dgap_driver)
5867 struct device_driver *driverfs = &dgap_driver->driver;
5869 rc |= driver_create_file(driverfs, &driver_attr_version);
5870 rc |= driver_create_file(driverfs, &driver_attr_boards);
5871 rc |= driver_create_file(driverfs, &driver_attr_maxboards);
5872 rc |= driver_create_file(driverfs, &driver_attr_pollrate);
5873 rc |= driver_create_file(driverfs, &driver_attr_pollcounter);
5878 static void dgap_remove_driver_sysfiles(struct pci_driver *dgap_driver)
5880 struct device_driver *driverfs = &dgap_driver->driver;
5881 driver_remove_file(driverfs, &driver_attr_version);
5882 driver_remove_file(driverfs, &driver_attr_boards);
5883 driver_remove_file(driverfs, &driver_attr_maxboards);
5884 driver_remove_file(driverfs, &driver_attr_pollrate);
5885 driver_remove_file(driverfs, &driver_attr_pollcounter);
5888 static struct board_t *dgap_verify_board(struct device *p)
5895 bd = dev_get_drvdata(p);
5896 if (!bd || bd->magic != DGAP_BOARD_MAGIC || bd->state != BOARD_READY)
5902 static ssize_t dgap_ports_state_show(struct device *p,
5903 struct device_attribute *attr,
5910 bd = dgap_verify_board(p);
5914 for (i = 0; i < bd->nasync; i++) {
5915 count += snprintf(buf + count, PAGE_SIZE - count,
5916 "%d %s\n", bd->channels[i]->ch_portnum,
5917 bd->channels[i]->ch_open_count ? "Open" : "Closed");
5921 static DEVICE_ATTR(ports_state, S_IRUSR, dgap_ports_state_show, NULL);
5923 static ssize_t dgap_ports_baud_show(struct device *p,
5924 struct device_attribute *attr,
5931 bd = dgap_verify_board(p);
5935 for (i = 0; i < bd->nasync; i++) {
5936 count += snprintf(buf + count, PAGE_SIZE - count, "%d %d\n",
5937 bd->channels[i]->ch_portnum,
5938 bd->channels[i]->ch_baud_info);
5942 static DEVICE_ATTR(ports_baud, S_IRUSR, dgap_ports_baud_show, NULL);
5944 static ssize_t dgap_ports_msignals_show(struct device *p,
5945 struct device_attribute *attr,
5952 bd = dgap_verify_board(p);
5956 for (i = 0; i < bd->nasync; i++) {
5957 if (bd->channels[i]->ch_open_count)
5958 count += snprintf(buf + count, PAGE_SIZE - count,
5959 "%d %s %s %s %s %s %s\n",
5960 bd->channels[i]->ch_portnum,
5961 (bd->channels[i]->ch_mostat &
5962 UART_MCR_RTS) ? "RTS" : "",
5963 (bd->channels[i]->ch_mistat &
5964 UART_MSR_CTS) ? "CTS" : "",
5965 (bd->channels[i]->ch_mostat &
5966 UART_MCR_DTR) ? "DTR" : "",
5967 (bd->channels[i]->ch_mistat &
5968 UART_MSR_DSR) ? "DSR" : "",
5969 (bd->channels[i]->ch_mistat &
5970 UART_MSR_DCD) ? "DCD" : "",
5971 (bd->channels[i]->ch_mistat &
5972 UART_MSR_RI) ? "RI" : "");
5974 count += snprintf(buf + count, PAGE_SIZE - count,
5975 "%d\n", bd->channels[i]->ch_portnum);
5979 static DEVICE_ATTR(ports_msignals, S_IRUSR, dgap_ports_msignals_show, NULL);
5981 static ssize_t dgap_ports_iflag_show(struct device *p,
5982 struct device_attribute *attr,
5989 bd = dgap_verify_board(p);
5993 for (i = 0; i < bd->nasync; i++)
5994 count += snprintf(buf + count, PAGE_SIZE - count, "%d %x\n",
5995 bd->channels[i]->ch_portnum,
5996 bd->channels[i]->ch_c_iflag);
5999 static DEVICE_ATTR(ports_iflag, S_IRUSR, dgap_ports_iflag_show, NULL);
6001 static ssize_t dgap_ports_cflag_show(struct device *p,
6002 struct device_attribute *attr,
6009 bd = dgap_verify_board(p);
6013 for (i = 0; i < bd->nasync; i++)
6014 count += snprintf(buf + count, PAGE_SIZE - count, "%d %x\n",
6015 bd->channels[i]->ch_portnum,
6016 bd->channels[i]->ch_c_cflag);
6019 static DEVICE_ATTR(ports_cflag, S_IRUSR, dgap_ports_cflag_show, NULL);
6021 static ssize_t dgap_ports_oflag_show(struct device *p,
6022 struct device_attribute *attr,
6029 bd = dgap_verify_board(p);
6033 for (i = 0; i < bd->nasync; i++)
6034 count += snprintf(buf + count, PAGE_SIZE - count, "%d %x\n",
6035 bd->channels[i]->ch_portnum,
6036 bd->channels[i]->ch_c_oflag);
6039 static DEVICE_ATTR(ports_oflag, S_IRUSR, dgap_ports_oflag_show, NULL);
6041 static ssize_t dgap_ports_lflag_show(struct device *p,
6042 struct device_attribute *attr,
6049 bd = dgap_verify_board(p);
6053 for (i = 0; i < bd->nasync; i++)
6054 count += snprintf(buf + count, PAGE_SIZE - count, "%d %x\n",
6055 bd->channels[i]->ch_portnum,
6056 bd->channels[i]->ch_c_lflag);
6059 static DEVICE_ATTR(ports_lflag, S_IRUSR, dgap_ports_lflag_show, NULL);
6061 static ssize_t dgap_ports_digi_flag_show(struct device *p,
6062 struct device_attribute *attr,
6069 bd = dgap_verify_board(p);
6073 for (i = 0; i < bd->nasync; i++)
6074 count += snprintf(buf + count, PAGE_SIZE - count, "%d %x\n",
6075 bd->channels[i]->ch_portnum,
6076 bd->channels[i]->ch_digi.digi_flags);
6079 static DEVICE_ATTR(ports_digi_flag, S_IRUSR, dgap_ports_digi_flag_show, NULL);
6081 static ssize_t dgap_ports_rxcount_show(struct device *p,
6082 struct device_attribute *attr,
6089 bd = dgap_verify_board(p);
6093 for (i = 0; i < bd->nasync; i++)
6094 count += snprintf(buf + count, PAGE_SIZE - count, "%d %ld\n",
6095 bd->channels[i]->ch_portnum,
6096 bd->channels[i]->ch_rxcount);
6099 static DEVICE_ATTR(ports_rxcount, S_IRUSR, dgap_ports_rxcount_show, NULL);
6101 static ssize_t dgap_ports_txcount_show(struct device *p,
6102 struct device_attribute *attr,
6109 bd = dgap_verify_board(p);
6113 for (i = 0; i < bd->nasync; i++)
6114 count += snprintf(buf + count, PAGE_SIZE - count, "%d %ld\n",
6115 bd->channels[i]->ch_portnum,
6116 bd->channels[i]->ch_txcount);
6119 static DEVICE_ATTR(ports_txcount, S_IRUSR, dgap_ports_txcount_show, NULL);
6121 /* this function creates the sys files that will export each signal status
6122 * to sysfs each value will be put in a separate filename
6124 static void dgap_create_ports_sysfiles(struct board_t *bd)
6126 dev_set_drvdata(&bd->pdev->dev, bd);
6127 device_create_file(&(bd->pdev->dev), &dev_attr_ports_state);
6128 device_create_file(&(bd->pdev->dev), &dev_attr_ports_baud);
6129 device_create_file(&(bd->pdev->dev), &dev_attr_ports_msignals);
6130 device_create_file(&(bd->pdev->dev), &dev_attr_ports_iflag);
6131 device_create_file(&(bd->pdev->dev), &dev_attr_ports_cflag);
6132 device_create_file(&(bd->pdev->dev), &dev_attr_ports_oflag);
6133 device_create_file(&(bd->pdev->dev), &dev_attr_ports_lflag);
6134 device_create_file(&(bd->pdev->dev), &dev_attr_ports_digi_flag);
6135 device_create_file(&(bd->pdev->dev), &dev_attr_ports_rxcount);
6136 device_create_file(&(bd->pdev->dev), &dev_attr_ports_txcount);
6139 /* removes all the sys files created for that port */
6140 static void dgap_remove_ports_sysfiles(struct board_t *bd)
6142 device_remove_file(&(bd->pdev->dev), &dev_attr_ports_state);
6143 device_remove_file(&(bd->pdev->dev), &dev_attr_ports_baud);
6144 device_remove_file(&(bd->pdev->dev), &dev_attr_ports_msignals);
6145 device_remove_file(&(bd->pdev->dev), &dev_attr_ports_iflag);
6146 device_remove_file(&(bd->pdev->dev), &dev_attr_ports_cflag);
6147 device_remove_file(&(bd->pdev->dev), &dev_attr_ports_oflag);
6148 device_remove_file(&(bd->pdev->dev), &dev_attr_ports_lflag);
6149 device_remove_file(&(bd->pdev->dev), &dev_attr_ports_digi_flag);
6150 device_remove_file(&(bd->pdev->dev), &dev_attr_ports_rxcount);
6151 device_remove_file(&(bd->pdev->dev), &dev_attr_ports_txcount);
6154 static ssize_t dgap_tty_state_show(struct device *d,
6155 struct device_attribute *attr,
6159 struct channel_t *ch;
6164 un = dev_get_drvdata(d);
6165 if (!un || un->magic != DGAP_UNIT_MAGIC)
6168 if (!ch || ch->magic != DGAP_CHANNEL_MAGIC)
6171 if (!bd || bd->magic != DGAP_BOARD_MAGIC)
6173 if (bd->state != BOARD_READY)
6176 return snprintf(buf, PAGE_SIZE, "%s", un->un_open_count ?
6179 static DEVICE_ATTR(state, S_IRUSR, dgap_tty_state_show, NULL);
6181 static ssize_t dgap_tty_baud_show(struct device *d,
6182 struct device_attribute *attr,
6186 struct channel_t *ch;
6191 un = dev_get_drvdata(d);
6192 if (!un || un->magic != DGAP_UNIT_MAGIC)
6195 if (!ch || ch->magic != DGAP_CHANNEL_MAGIC)
6198 if (!bd || bd->magic != DGAP_BOARD_MAGIC)
6200 if (bd->state != BOARD_READY)
6203 return snprintf(buf, PAGE_SIZE, "%d\n", ch->ch_baud_info);
6205 static DEVICE_ATTR(baud, S_IRUSR, dgap_tty_baud_show, NULL);
6207 static ssize_t dgap_tty_msignals_show(struct device *d,
6208 struct device_attribute *attr,
6212 struct channel_t *ch;
6217 un = dev_get_drvdata(d);
6218 if (!un || un->magic != DGAP_UNIT_MAGIC)
6221 if (!ch || ch->magic != DGAP_CHANNEL_MAGIC)
6224 if (!bd || bd->magic != DGAP_BOARD_MAGIC)
6226 if (bd->state != BOARD_READY)
6229 if (ch->ch_open_count) {
6230 return snprintf(buf, PAGE_SIZE, "%s %s %s %s %s %s\n",
6231 (ch->ch_mostat & UART_MCR_RTS) ? "RTS" : "",
6232 (ch->ch_mistat & UART_MSR_CTS) ? "CTS" : "",
6233 (ch->ch_mostat & UART_MCR_DTR) ? "DTR" : "",
6234 (ch->ch_mistat & UART_MSR_DSR) ? "DSR" : "",
6235 (ch->ch_mistat & UART_MSR_DCD) ? "DCD" : "",
6236 (ch->ch_mistat & UART_MSR_RI) ? "RI" : "");
6240 static DEVICE_ATTR(msignals, S_IRUSR, dgap_tty_msignals_show, NULL);
6242 static ssize_t dgap_tty_iflag_show(struct device *d,
6243 struct device_attribute *attr,
6247 struct channel_t *ch;
6252 un = dev_get_drvdata(d);
6253 if (!un || un->magic != DGAP_UNIT_MAGIC)
6256 if (!ch || ch->magic != DGAP_CHANNEL_MAGIC)
6259 if (!bd || bd->magic != DGAP_BOARD_MAGIC)
6261 if (bd->state != BOARD_READY)
6264 return snprintf(buf, PAGE_SIZE, "%x\n", ch->ch_c_iflag);
6266 static DEVICE_ATTR(iflag, S_IRUSR, dgap_tty_iflag_show, NULL);
6268 static ssize_t dgap_tty_cflag_show(struct device *d,
6269 struct device_attribute *attr,
6273 struct channel_t *ch;
6278 un = dev_get_drvdata(d);
6279 if (!un || un->magic != DGAP_UNIT_MAGIC)
6282 if (!ch || ch->magic != DGAP_CHANNEL_MAGIC)
6285 if (!bd || bd->magic != DGAP_BOARD_MAGIC)
6287 if (bd->state != BOARD_READY)
6290 return snprintf(buf, PAGE_SIZE, "%x\n", ch->ch_c_cflag);
6292 static DEVICE_ATTR(cflag, S_IRUSR, dgap_tty_cflag_show, NULL);
6294 static ssize_t dgap_tty_oflag_show(struct device *d,
6295 struct device_attribute *attr,
6299 struct channel_t *ch;
6304 un = dev_get_drvdata(d);
6305 if (!un || un->magic != DGAP_UNIT_MAGIC)
6308 if (!ch || ch->magic != DGAP_CHANNEL_MAGIC)
6311 if (!bd || bd->magic != DGAP_BOARD_MAGIC)
6313 if (bd->state != BOARD_READY)
6316 return snprintf(buf, PAGE_SIZE, "%x\n", ch->ch_c_oflag);
6318 static DEVICE_ATTR(oflag, S_IRUSR, dgap_tty_oflag_show, NULL);
6320 static ssize_t dgap_tty_lflag_show(struct device *d,
6321 struct device_attribute *attr,
6325 struct channel_t *ch;
6330 un = dev_get_drvdata(d);
6331 if (!un || un->magic != DGAP_UNIT_MAGIC)
6334 if (!ch || ch->magic != DGAP_CHANNEL_MAGIC)
6337 if (!bd || bd->magic != DGAP_BOARD_MAGIC)
6339 if (bd->state != BOARD_READY)
6342 return snprintf(buf, PAGE_SIZE, "%x\n", ch->ch_c_lflag);
6344 static DEVICE_ATTR(lflag, S_IRUSR, dgap_tty_lflag_show, NULL);
6346 static ssize_t dgap_tty_digi_flag_show(struct device *d,
6347 struct device_attribute *attr,
6351 struct channel_t *ch;
6356 un = dev_get_drvdata(d);
6357 if (!un || un->magic != DGAP_UNIT_MAGIC)
6360 if (!ch || ch->magic != DGAP_CHANNEL_MAGIC)
6363 if (!bd || bd->magic != DGAP_BOARD_MAGIC)
6365 if (bd->state != BOARD_READY)
6368 return snprintf(buf, PAGE_SIZE, "%x\n", ch->ch_digi.digi_flags);
6370 static DEVICE_ATTR(digi_flag, S_IRUSR, dgap_tty_digi_flag_show, NULL);
6372 static ssize_t dgap_tty_rxcount_show(struct device *d,
6373 struct device_attribute *attr,
6377 struct channel_t *ch;
6382 un = dev_get_drvdata(d);
6383 if (!un || un->magic != DGAP_UNIT_MAGIC)
6386 if (!ch || ch->magic != DGAP_CHANNEL_MAGIC)
6389 if (!bd || bd->magic != DGAP_BOARD_MAGIC)
6391 if (bd->state != BOARD_READY)
6394 return snprintf(buf, PAGE_SIZE, "%ld\n", ch->ch_rxcount);
6396 static DEVICE_ATTR(rxcount, S_IRUSR, dgap_tty_rxcount_show, NULL);
6398 static ssize_t dgap_tty_txcount_show(struct device *d,
6399 struct device_attribute *attr,
6403 struct channel_t *ch;
6408 un = dev_get_drvdata(d);
6409 if (!un || un->magic != DGAP_UNIT_MAGIC)
6412 if (!ch || ch->magic != DGAP_CHANNEL_MAGIC)
6415 if (!bd || bd->magic != DGAP_BOARD_MAGIC)
6417 if (bd->state != BOARD_READY)
6420 return snprintf(buf, PAGE_SIZE, "%ld\n", ch->ch_txcount);
6422 static DEVICE_ATTR(txcount, S_IRUSR, dgap_tty_txcount_show, NULL);
6424 static ssize_t dgap_tty_name_show(struct device *d,
6425 struct device_attribute *attr,
6429 struct channel_t *ch;
6433 struct cnode *cptr = NULL;
6441 un = dev_get_drvdata(d);
6442 if (!un || un->magic != DGAP_UNIT_MAGIC)
6445 if (!ch || ch->magic != DGAP_CHANNEL_MAGIC)
6448 if (!bd || bd->magic != DGAP_BOARD_MAGIC)
6450 if (bd->state != BOARD_READY)
6454 cn = ch->ch_portnum;
6456 for (cptr = bd->bd_config; cptr; cptr = cptr->next) {
6458 if ((cptr->type == BNODE) &&
6459 ((cptr->u.board.type == APORT2_920P) ||
6460 (cptr->u.board.type == APORT4_920P) ||
6461 (cptr->u.board.type == APORT8_920P) ||
6462 (cptr->u.board.type == PAPORT4) ||
6463 (cptr->u.board.type == PAPORT8))) {
6466 if (cptr->u.board.v_start)
6467 starto = cptr->u.board.start;
6472 if (cptr->type == TNODE && found == TRUE) {
6474 if (strstr(cptr->u.ttyname, "tty")) {
6475 ptr1 = cptr->u.ttyname;
6478 ptr1 = cptr->u.ttyname;
6480 for (i = 0; i < dgap_config_get_number_of_ports(bd); i++) {
6482 return snprintf(buf, PAGE_SIZE, "%s%s%02d\n",
6483 (un->un_type == DGAP_PRINT) ? "pr" : "tty",
6488 if (cptr->type == CNODE) {
6490 for (i = 0; i < cptr->u.conc.nport; i++) {
6491 if (cn == (i + ncount))
6493 return snprintf(buf, PAGE_SIZE, "%s%s%02d\n",
6494 (un->un_type == DGAP_PRINT) ? "pr" : "tty",
6496 i + (cptr->u.conc.v_start ? cptr->u.conc.start : 1));
6499 ncount += cptr->u.conc.nport;
6502 if (cptr->type == MNODE) {
6504 for (i = 0; i < cptr->u.module.nport; i++) {
6505 if (cn == (i + ncount))
6506 return snprintf(buf, PAGE_SIZE, "%s%s%02d\n",
6507 (un->un_type == DGAP_PRINT) ? "pr" : "tty",
6509 i + (cptr->u.module.v_start ? cptr->u.module.start : 1));
6512 ncount += cptr->u.module.nport;
6517 return snprintf(buf, PAGE_SIZE, "%s_dgap_%d_%d\n",
6518 (un->un_type == DGAP_PRINT) ? "pr" : "tty", bn, cn);
6521 static DEVICE_ATTR(custom_name, S_IRUSR, dgap_tty_name_show, NULL);
6523 static struct attribute *dgap_sysfs_tty_entries[] = {
6524 &dev_attr_state.attr,
6525 &dev_attr_baud.attr,
6526 &dev_attr_msignals.attr,
6527 &dev_attr_iflag.attr,
6528 &dev_attr_cflag.attr,
6529 &dev_attr_oflag.attr,
6530 &dev_attr_lflag.attr,
6531 &dev_attr_digi_flag.attr,
6532 &dev_attr_rxcount.attr,
6533 &dev_attr_txcount.attr,
6534 &dev_attr_custom_name.attr,
6538 static struct attribute_group dgap_tty_attribute_group = {
6540 .attrs = dgap_sysfs_tty_entries,
6543 static void dgap_create_tty_sysfs(struct un_t *un, struct device *c)
6547 ret = sysfs_create_group(&c->kobj, &dgap_tty_attribute_group);
6551 dev_set_drvdata(c, un);
6555 static void dgap_remove_tty_sysfs(struct device *c)
6557 sysfs_remove_group(&c->kobj, &dgap_tty_attribute_group);
6561 * Parse a configuration file read into memory as a string.
6563 static int dgap_parsefile(char **in, int Remove)
6565 struct cnode *p, *brd, *line, *conc;
6567 char *s = NULL, *s2 = NULL;
6571 brd = line = conc = NULL;
6573 /* perhaps we are adding to an existing list? */
6574 while (p->next != NULL)
6577 /* file must start with a BEGIN */
6578 while ((rc = dgap_gettok(in, p)) != BEGIN) {
6580 dgap_err("unexpected EOF");
6586 rc = dgap_gettok(in, p);
6588 dgap_err("unexpected EOF");
6594 dgap_err("unexpected end of file");
6597 case BEGIN: /* should only be 1 begin */
6598 dgap_err("unexpected config_begin\n");
6604 case BOARD: /* board info */
6605 if (dgap_checknode(p))
6607 p->next = dgap_newnode(BNODE);
6609 dgap_err("out of memory");
6614 p->u.board.status = dgap_savestring("No");
6620 case APORT2_920P: /* AccelePort_4 */
6621 if (p->type != BNODE) {
6622 dgap_err("unexpected Digi_2r_920 string");
6625 p->u.board.type = APORT2_920P;
6626 p->u.board.v_type = 1;
6629 case APORT4_920P: /* AccelePort_4 */
6630 if (p->type != BNODE) {
6631 dgap_err("unexpected Digi_4r_920 string");
6634 p->u.board.type = APORT4_920P;
6635 p->u.board.v_type = 1;
6638 case APORT8_920P: /* AccelePort_8 */
6639 if (p->type != BNODE) {
6640 dgap_err("unexpected Digi_8r_920 string");
6643 p->u.board.type = APORT8_920P;
6644 p->u.board.v_type = 1;
6647 case PAPORT4: /* AccelePort_4 PCI */
6648 if (p->type != BNODE) {
6649 dgap_err("unexpected Digi_4r(PCI) string");
6652 p->u.board.type = PAPORT4;
6653 p->u.board.v_type = 1;
6656 case PAPORT8: /* AccelePort_8 PCI */
6657 if (p->type != BNODE) {
6658 dgap_err("unexpected Digi_8r string");
6661 p->u.board.type = PAPORT8;
6662 p->u.board.v_type = 1;
6665 case PCX: /* PCI C/X */
6666 if (p->type != BNODE) {
6667 dgap_err("unexpected Digi_C/X_(PCI) string");
6670 p->u.board.type = PCX;
6671 p->u.board.v_type = 1;
6672 p->u.board.conc1 = 0;
6673 p->u.board.conc2 = 0;
6674 p->u.board.module1 = 0;
6675 p->u.board.module2 = 0;
6678 case PEPC: /* PCI EPC/X */
6679 if (p->type != BNODE) {
6680 dgap_err("unexpected \"Digi_EPC/X_(PCI)\" string");
6683 p->u.board.type = PEPC;
6684 p->u.board.v_type = 1;
6685 p->u.board.conc1 = 0;
6686 p->u.board.conc2 = 0;
6687 p->u.board.module1 = 0;
6688 p->u.board.module2 = 0;
6691 case PPCM: /* PCI/Xem */
6692 if (p->type != BNODE) {
6693 dgap_err("unexpected PCI/Xem string");
6696 p->u.board.type = PPCM;
6697 p->u.board.v_type = 1;
6698 p->u.board.conc1 = 0;
6699 p->u.board.conc2 = 0;
6702 case IO: /* i/o port */
6703 if (p->type != BNODE) {
6704 dgap_err("IO port only vaild for boards");
6707 s = dgap_getword(in);
6709 dgap_err("unexpected end of file");
6712 p->u.board.portstr = dgap_savestring(s);
6713 p->u.board.port = (short)simple_strtol(s, &s2, 0);
6714 if ((short)strlen(s) > (short)(s2 - s)) {
6715 dgap_err("bad number for IO port");
6718 p->u.board.v_port = 1;
6721 case MEM: /* memory address */
6722 if (p->type != BNODE) {
6723 dgap_err("memory address only vaild for boards");
6726 s = dgap_getword(in);
6728 dgap_err("unexpected end of file");
6731 p->u.board.addrstr = dgap_savestring(s);
6732 p->u.board.addr = simple_strtoul(s, &s2, 0);
6733 if ((int)strlen(s) > (int)(s2 - s)) {
6734 dgap_err("bad number for memory address");
6737 p->u.board.v_addr = 1;
6740 case PCIINFO: /* pci information */
6741 if (p->type != BNODE) {
6742 dgap_err("memory address only vaild for boards");
6745 s = dgap_getword(in);
6747 dgap_err("unexpected end of file");
6750 p->u.board.pcibusstr = dgap_savestring(s);
6751 p->u.board.pcibus = simple_strtoul(s, &s2, 0);
6752 if ((int)strlen(s) > (int)(s2 - s)) {
6753 dgap_err("bad number for pci bus");
6756 p->u.board.v_pcibus = 1;
6757 s = dgap_getword(in);
6759 dgap_err("unexpected end of file");
6762 p->u.board.pcislotstr = dgap_savestring(s);
6763 p->u.board.pcislot = simple_strtoul(s, &s2, 0);
6764 if ((int)strlen(s) > (int)(s2 - s)) {
6765 dgap_err("bad number for pci slot");
6768 p->u.board.v_pcislot = 1;
6772 if (p->type != BNODE) {
6773 dgap_err("install method only vaild for boards");
6776 s = dgap_getword(in);
6778 dgap_err("unexpected end of file");
6781 p->u.board.method = dgap_savestring(s);
6782 p->u.board.v_method = 1;
6786 if (p->type != BNODE) {
6787 dgap_err("config status only vaild for boards");
6790 s = dgap_getword(in);
6792 dgap_err("unexpected end of file");
6795 p->u.board.status = dgap_savestring(s);
6798 case NPORTS: /* number of ports */
6799 if (p->type == BNODE) {
6800 s = dgap_getword(in);
6802 dgap_err("unexpected end of file");
6805 p->u.board.nport = (char)simple_strtol(s, &s2, 0);
6806 if ((int)strlen(s) > (int)(s2 - s)) {
6807 dgap_err("bad number for number of ports");
6810 p->u.board.v_nport = 1;
6811 } else if (p->type == CNODE) {
6812 s = dgap_getword(in);
6814 dgap_err("unexpected end of file");
6817 p->u.conc.nport = (char)simple_strtol(s, &s2, 0);
6818 if ((int)strlen(s) > (int)(s2 - s)) {
6819 dgap_err("bad number for number of ports");
6822 p->u.conc.v_nport = 1;
6823 } else if (p->type == MNODE) {
6824 s = dgap_getword(in);
6826 dgap_err("unexpected end of file");
6829 p->u.module.nport = (char)simple_strtol(s, &s2, 0);
6830 if ((int)strlen(s) > (int)(s2 - s)) {
6831 dgap_err("bad number for number of ports");
6834 p->u.module.v_nport = 1;
6836 dgap_err("nports only valid for concentrators or modules");
6841 case ID: /* letter ID used in tty name */
6842 s = dgap_getword(in);
6844 dgap_err("unexpected end of file");
6848 p->u.board.status = dgap_savestring(s);
6850 if (p->type == CNODE) {
6851 p->u.conc.id = dgap_savestring(s);
6853 } else if (p->type == MNODE) {
6854 p->u.module.id = dgap_savestring(s);
6855 p->u.module.v_id = 1;
6857 dgap_err("id only valid for concentrators or modules");
6862 case STARTO: /* start offset of ID */
6863 if (p->type == BNODE) {
6864 s = dgap_getword(in);
6866 dgap_err("unexpected end of file");
6869 p->u.board.start = simple_strtol(s, &s2, 0);
6870 if ((int)strlen(s) > (int)(s2 - s)) {
6871 dgap_err("bad number for start of tty count");
6874 p->u.board.v_start = 1;
6875 } else if (p->type == CNODE) {
6876 s = dgap_getword(in);
6878 dgap_err("unexpected end of file");
6881 p->u.conc.start = simple_strtol(s, &s2, 0);
6882 if ((int)strlen(s) > (int)(s2 - s)) {
6883 dgap_err("bad number for start of tty count");
6886 p->u.conc.v_start = 1;
6887 } else if (p->type == MNODE) {
6888 s = dgap_getword(in);
6890 dgap_err("unexpected end of file");
6893 p->u.module.start = simple_strtol(s, &s2, 0);
6894 if ((int)strlen(s) > (int)(s2 - s)) {
6895 dgap_err("bad number for start of tty count");
6898 p->u.module.v_start = 1;
6900 dgap_err("start only valid for concentrators or modules");
6905 case TTYN: /* tty name prefix */
6906 if (dgap_checknode(p))
6908 p->next = dgap_newnode(TNODE);
6910 dgap_err("out of memory");
6914 s = dgap_getword(in);
6916 dgap_err("unexpeced end of file");
6919 p->u.ttyname = dgap_savestring(s);
6920 if (!p->u.ttyname) {
6921 dgap_err("out of memory");
6926 case CU: /* cu name prefix */
6927 if (dgap_checknode(p))
6929 p->next = dgap_newnode(CUNODE);
6931 dgap_err("out of memory");
6935 s = dgap_getword(in);
6937 dgap_err("unexpeced end of file");
6940 p->u.cuname = dgap_savestring(s);
6942 dgap_err("out of memory");
6947 case LINE: /* line information */
6948 if (dgap_checknode(p))
6951 dgap_err("must specify board before line info");
6954 switch (brd->u.board.type) {
6956 dgap_err("line not vaild for PC/em");
6959 p->next = dgap_newnode(LNODE);
6961 dgap_err("out of memory");
6970 case CONC: /* concentrator information */
6971 if (dgap_checknode(p))
6974 dgap_err("must specify line info before concentrator");
6977 p->next = dgap_newnode(CNODE);
6979 dgap_err("out of memory");
6985 brd->u.board.conc2++;
6987 brd->u.board.conc1++;
6991 case CX: /* c/x type concentrator */
6992 if (p->type != CNODE) {
6993 dgap_err("cx only valid for concentrators");
6996 p->u.conc.type = CX;
6997 p->u.conc.v_type = 1;
7000 case EPC: /* epc type concentrator */
7001 if (p->type != CNODE) {
7002 dgap_err("cx only valid for concentrators");
7005 p->u.conc.type = EPC;
7006 p->u.conc.v_type = 1;
7009 case MOD: /* EBI module */
7010 if (dgap_checknode(p))
7013 dgap_err("must specify board info before EBI modules");
7016 switch (brd->u.board.type) {
7022 dgap_err("must specify concentrator info before EBI module");
7026 p->next = dgap_newnode(MNODE);
7028 dgap_err("out of memory");
7033 brd->u.board.module2++;
7035 brd->u.board.module1++;
7039 case PORTS: /* ports type EBI module */
7040 if (p->type != MNODE) {
7041 dgap_err("ports only valid for EBI modules");
7044 p->u.module.type = PORTS;
7045 p->u.module.v_type = 1;
7048 case MODEM: /* ports type EBI module */
7049 if (p->type != MNODE) {
7050 dgap_err("modem only valid for modem modules");
7053 p->u.module.type = MODEM;
7054 p->u.module.v_type = 1;
7058 if (p->type == LNODE) {
7059 s = dgap_getword(in);
7061 dgap_err("unexpected end of file");
7064 p->u.line.cable = dgap_savestring(s);
7065 p->u.line.v_cable = 1;
7069 case SPEED: /* sync line speed indication */
7070 if (p->type == LNODE) {
7071 s = dgap_getword(in);
7073 dgap_err("unexpected end of file");
7076 p->u.line.speed = (char)simple_strtol(s, &s2, 0);
7077 if ((short)strlen(s) > (short)(s2 - s)) {
7078 dgap_err("bad number for line speed");
7081 p->u.line.v_speed = 1;
7082 } else if (p->type == CNODE) {
7083 s = dgap_getword(in);
7085 dgap_err("unexpected end of file");
7088 p->u.conc.speed = (char)simple_strtol(s, &s2, 0);
7089 if ((short)strlen(s) > (short)(s2 - s)) {
7090 dgap_err("bad number for line speed");
7093 p->u.conc.v_speed = 1;
7095 dgap_err("speed valid only for lines or concentrators.");
7101 if (p->type == CNODE) {
7102 s = dgap_getword(in);
7104 dgap_err("unexpected end of file");
7107 p->u.conc.connect = dgap_savestring(s);
7108 p->u.conc.v_connect = 1;
7111 case PRINT: /* transparent print name prefix */
7112 if (dgap_checknode(p))
7114 p->next = dgap_newnode(PNODE);
7116 dgap_err("out of memory");
7120 s = dgap_getword(in);
7122 dgap_err("unexpeced end of file");
7125 p->u.printname = dgap_savestring(s);
7126 if (!p->u.printname) {
7127 dgap_err("out of memory");
7132 case CMAJOR: /* major number */
7133 if (dgap_checknode(p))
7135 p->next = dgap_newnode(JNODE);
7137 dgap_err("out of memory");
7141 s = dgap_getword(in);
7143 dgap_err("unexpected end of file");
7146 p->u.majornumber = simple_strtol(s, &s2, 0);
7147 if ((int)strlen(s) > (int)(s2 - s)) {
7148 dgap_err("bad number for major number");
7153 case ALTPIN: /* altpin setting */
7154 if (dgap_checknode(p))
7156 p->next = dgap_newnode(ANODE);
7158 dgap_err("out of memory");
7162 s = dgap_getword(in);
7164 dgap_err("unexpected end of file");
7167 p->u.altpin = simple_strtol(s, &s2, 0);
7168 if ((int)strlen(s) > (int)(s2 - s)) {
7169 dgap_err("bad number for altpin");
7174 case USEINTR: /* enable interrupt setting */
7175 if (dgap_checknode(p))
7177 p->next = dgap_newnode(INTRNODE);
7179 dgap_err("out of memory");
7183 s = dgap_getword(in);
7185 dgap_err("unexpected end of file");
7188 p->u.useintr = simple_strtol(s, &s2, 0);
7189 if ((int)strlen(s) > (int)(s2 - s)) {
7190 dgap_err("bad number for useintr");
7195 case TTSIZ: /* size of tty structure */
7196 if (dgap_checknode(p))
7198 p->next = dgap_newnode(TSNODE);
7200 dgap_err("out of memory");
7204 s = dgap_getword(in);
7206 dgap_err("unexpected end of file");
7209 p->u.ttysize = simple_strtol(s, &s2, 0);
7210 if ((int)strlen(s) > (int)(s2 - s)) {
7211 dgap_err("bad number for ttysize");
7216 case CHSIZ: /* channel structure size */
7217 if (dgap_checknode(p))
7219 p->next = dgap_newnode(CSNODE);
7221 dgap_err("out of memory");
7225 s = dgap_getword(in);
7227 dgap_err("unexpected end of file");
7230 p->u.chsize = simple_strtol(s, &s2, 0);
7231 if ((int)strlen(s) > (int)(s2 - s)) {
7232 dgap_err("bad number for chsize");
7237 case BSSIZ: /* board structure size */
7238 if (dgap_checknode(p))
7240 p->next = dgap_newnode(BSNODE);
7242 dgap_err("out of memory");
7246 s = dgap_getword(in);
7248 dgap_err("unexpected end of file");
7251 p->u.bssize = simple_strtol(s, &s2, 0);
7252 if ((int)strlen(s) > (int)(s2 - s)) {
7253 dgap_err("bad number for bssize");
7258 case UNTSIZ: /* sched structure size */
7259 if (dgap_checknode(p))
7261 p->next = dgap_newnode(USNODE);
7263 dgap_err("out of memory");
7267 s = dgap_getword(in);
7269 dgap_err("unexpected end of file");
7272 p->u.unsize = simple_strtol(s, &s2, 0);
7273 if ((int)strlen(s) > (int)(s2 - s)) {
7274 dgap_err("bad number for schedsize");
7279 case F2SIZ: /* f2200 structure size */
7280 if (dgap_checknode(p))
7282 p->next = dgap_newnode(FSNODE);
7284 dgap_err("out of memory");
7288 s = dgap_getword(in);
7290 dgap_err("unexpected end of file");
7293 p->u.f2size = simple_strtol(s, &s2, 0);
7294 if ((int)strlen(s) > (int)(s2 - s)) {
7295 dgap_err("bad number for f2200size");
7300 case VPSIZ: /* vpix structure size */
7301 if (dgap_checknode(p))
7303 p->next = dgap_newnode(VSNODE);
7305 dgap_err("out of memory");
7309 s = dgap_getword(in);
7311 dgap_err("unexpected end of file");
7314 p->u.vpixsize = simple_strtol(s, &s2, 0);
7315 if ((int)strlen(s) > (int)(s2 - s)) {
7316 dgap_err("bad number for vpixsize");
7325 * dgap_sindex: much like index(), but it looks for a match of any character in
7326 * the group, and returns that position. If the first character is a ^, then
7327 * this will match the first occurrence not in that group.
7329 static char *dgap_sindex(char *string, char *group)
7333 if (!string || !group)
7334 return (char *) NULL;
7336 if (*group == '^') {
7338 for (; *string; string++) {
7339 for (ptr = group; *ptr; ptr++) {
7340 if (*ptr == *string)
7347 for (; *string; string++) {
7348 for (ptr = group; *ptr; ptr++) {
7349 if (*ptr == *string)
7355 return (char *) NULL;
7359 * Get a token from the input file; return 0 if end of file is reached
7361 static int dgap_gettok(char **in, struct cnode *p)
7366 if (strstr(dgap_cword, "boar")) {
7367 w = dgap_getword(in);
7368 snprintf(dgap_cword, MAXCWORD, "%s", w);
7369 for (t = dgap_tlist; t->token != 0; t++) {
7370 if (!strcmp(w, t->string))
7373 dgap_err("board !!type not specified");
7376 while ((w = dgap_getword(in))) {
7377 snprintf(dgap_cword, MAXCWORD, "%s", w);
7378 for (t = dgap_tlist; t->token != 0; t++) {
7379 if (!strcmp(w, t->string))
7388 * get a word from the input stream, also keep track of current line number.
7389 * words are separated by whitespace.
7391 static char *dgap_getword(char **in)
7393 char *ret_ptr = *in;
7395 char *ptr = dgap_sindex(*in, " \t\n");
7397 /* If no word found, return null */
7401 /* Mark new location for our buffer */
7405 /* Eat any extra spaces/tabs/newlines that might be present */
7406 while (*in && **in && ((**in == ' ') ||
7417 * print an error message, giving the line number in the file where
7418 * the error occurred.
7420 static void dgap_err(char *s)
7422 pr_err("dgap: parse: %s\n", s);
7426 * allocate a new configuration node of type t
7428 static struct cnode *dgap_newnode(int t)
7432 n = kmalloc(sizeof(struct cnode), GFP_ATOMIC);
7434 memset((char *)n, 0, sizeof(struct cnode));
7441 * dgap_checknode: see if all the necessary info has been supplied for a node
7442 * before creating the next node.
7444 static int dgap_checknode(struct cnode *p)
7448 if (p->u.board.v_type == 0) {
7449 dgap_err("board type !not specified");
7456 if (p->u.line.v_speed == 0) {
7457 dgap_err("line speed not specified");
7463 if (p->u.conc.v_type == 0) {
7464 dgap_err("concentrator type not specified");
7467 if (p->u.conc.v_speed == 0) {
7468 dgap_err("concentrator line speed not specified");
7471 if (p->u.conc.v_nport == 0) {
7472 dgap_err("number of ports on concentrator not specified");
7475 if (p->u.conc.v_id == 0) {
7476 dgap_err("concentrator id letter not specified");
7482 if (p->u.module.v_type == 0) {
7483 dgap_err("EBI module type not specified");
7486 if (p->u.module.v_nport == 0) {
7487 dgap_err("number of ports on EBI module not specified");
7490 if (p->u.module.v_id == 0) {
7491 dgap_err("EBI module id letter not specified");
7500 * save a string somewhere
7502 static char *dgap_savestring(char *s)
7506 p = kmalloc(strlen(s) + 1, GFP_ATOMIC);
7513 * Given a board pointer, returns whether we should use interrupts or not.
7515 static uint dgap_config_get_useintr(struct board_t *bd)
7517 struct cnode *p = NULL;
7522 for (p = bd->bd_config; p; p = p->next) {
7526 * check for pcxr types.
7528 return p->u.useintr;
7534 /* If not found, then don't turn on interrupts. */
7539 * Given a board pointer, returns whether we turn on altpin or not.
7541 static uint dgap_config_get_altpin(struct board_t *bd)
7543 struct cnode *p = NULL;
7548 for (p = bd->bd_config; p; p = p->next) {
7552 * check for pcxr types.
7560 /* If not found, then don't turn on interrupts. */
7565 * Given a specific type of board, if found, detached link and
7566 * returns the first occurrence in the list.
7568 static struct cnode *dgap_find_config(int type, int bus, int slot)
7570 struct cnode *p, *prev = NULL, *prev2 = NULL, *found = NULL;
7574 while (p->next != NULL) {
7578 if (p->type == BNODE) {
7580 if (p->u.board.type == type) {
7582 if (p->u.board.v_pcibus &&
7583 p->u.board.pcibus != bus)
7585 if (p->u.board.v_pcislot &&
7586 p->u.board.pcislot != slot)
7591 * Keep walking thru the list till we
7592 * find the next board.
7594 while (p->next != NULL) {
7597 if (p->type == BNODE) {
7600 * Mark the end of our 1 board
7606 * Link the "next" board to the
7607 * previous board, effectively
7608 * "unlinking" our board from
7617 * It must be the last board in the list.
7628 * Given a board pointer, walks the config link, counting up
7629 * all ports user specified should be on the board.
7630 * (This does NOT mean they are all actually present right now tho)
7632 static uint dgap_config_get_number_of_ports(struct board_t *bd)
7635 struct cnode *p = NULL;
7640 for (p = bd->bd_config; p; p = p->next) {
7645 * check for pcxr types.
7647 if (p->u.board.type > EPCFE)
7648 count += p->u.board.nport;
7651 count += p->u.conc.nport;
7654 count += p->u.module.nport;
7661 static char *dgap_create_config_string(struct board_t *bd, char *string)
7664 struct cnode *p = NULL;
7665 struct cnode *q = NULL;
7673 for (p = bd->bd_config; p; p = p->next) {
7679 *ptr = p->u.line.speed;
7684 * Because the EPC/con concentrators can have EM modules
7685 * hanging off of them, we have to walk ahead in the
7686 * list and keep adding the number of ports on each EM
7687 * to the config. UGH!
7689 speed = p->u.conc.speed;
7691 if ((q != NULL) && (q->type == MNODE)) {
7692 *ptr = (p->u.conc.nport + 0x80);
7695 while ((q->next != NULL) &&
7696 (q->next->type) == MNODE) {
7698 *ptr = (q->u.module.nport + 0x80);
7703 *ptr = q->u.module.nport;
7706 *ptr = p->u.conc.nport;