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;
823 pr_info("dgap: board %d: %s (rev %d), irq %ld, %s\n",
824 dgap_NumBoards, brd->name, brd->rev, brd->irq,
825 brd->state ? "NOT READY\0" : "READY\0");
831 static int dgap_finalize_board_init(struct board_t *brd)
835 if (!brd || brd->magic != DGAP_BOARD_MAGIC)
838 brd->use_interrupts = dgap_config_get_useintr(brd);
841 * Set up our interrupt handler if we are set to do interrupts.
843 if (brd->use_interrupts && brd->irq) {
845 rc = request_irq(brd->irq, dgap_intr, IRQF_SHARED, "DGAP", brd);
858 static int dgap_firmware_load(struct pci_dev *pdev, int card_type)
860 struct board_t *brd = dgap_Board[dgap_NumBoards - 1];
861 const struct firmware *fw;
865 dgap_do_reset_board(brd);
867 if (fw_info[card_type].conf_name) {
868 ret = request_firmware(&fw, fw_info[card_type].conf_name,
871 pr_err("dgap: config file %s not found\n",
872 fw_info[card_type].conf_name);
875 if (!dgap_config_buf) {
876 dgap_config_buf = kmalloc(fw->size + 1, GFP_ATOMIC);
877 if (!dgap_config_buf) {
878 release_firmware(fw);
883 memcpy(dgap_config_buf, fw->data, fw->size);
884 release_firmware(fw);
885 dgap_config_buf[fw->size + 1] = '\0';
887 if (dgap_parsefile(&dgap_config_buf, TRUE) != 0)
891 ret = dgap_after_config_loaded(brd->boardnum);
895 * Match this board to a config the user created for us.
898 dgap_find_config(brd->type, brd->pci_bus, brd->pci_slot);
901 * Because the 4 port Xr products share the same PCI ID
902 * as the 8 port Xr products, if we receive a NULL config
903 * back, and this is a PAPORT8 board, retry with a
904 * PAPORT4 attempt as well.
906 if (brd->type == PAPORT8 && !brd->bd_config)
908 dgap_find_config(PAPORT4, brd->pci_bus, brd->pci_slot);
910 if (!brd->bd_config) {
911 pr_err("dgap: No valid configuration found\n");
915 dgap_tty_register(brd);
916 dgap_finalize_board_init(brd);
918 if (fw_info[card_type].bios_name) {
919 ret = request_firmware(&fw, fw_info[card_type].bios_name,
922 pr_err("dgap: bios file %s not found\n",
923 fw_info[card_type].bios_name);
926 dgap_do_bios_load(brd, (char *)fw->data, fw->size);
927 release_firmware(fw);
929 /* Wait for BIOS to test board... */
930 if (!dgap_do_wait_for_bios(brd))
934 if (fw_info[card_type].fep_name) {
935 ret = request_firmware(&fw, fw_info[card_type].fep_name,
938 pr_err("dgap: fep file %s not found\n",
939 fw_info[card_type].fep_name);
942 dgap_do_fep_load(brd, (char *)fw->data, fw->size);
943 release_firmware(fw);
945 /* Wait for FEP to load on board... */
946 if (!dgap_do_wait_for_fep(brd))
950 #ifdef DIGI_CONCENTRATORS_SUPPORTED
952 * If this is a CX or EPCX, we need to see if the firmware
953 * is requesting a concentrator image from us.
955 if ((bd->type == PCX) || (bd->type == PEPC)) {
956 chk_addr = (u16 *) (vaddr + DOWNREQ);
957 /* Nonzero if FEP is requesting concentrator image. */
958 check = readw(chk_addr);
959 vaddr = brd->re_map_membase;
962 if (fw_info[card_type].con_name && check && vaddr) {
963 ret = request_firmware(&fw, fw_info[card_type].con_name,
966 pr_err("dgap: conc file %s not found\n",
967 fw_info[card_type].con_name);
970 /* Put concentrator firmware loading code here */
971 offset = readw((u16 *) (vaddr + DOWNREQ));
972 memcpy_toio(offset, fw->data, fw->size);
974 dgap_do_conc_load(brd, (char *)fw->data, fw->size)
975 release_firmware(fw);
979 * Do tty device initialization.
981 ret = dgap_tty_init(brd);
983 dgap_tty_uninit(brd);
987 ret = dgap_tty_register_ports(brd);
991 brd->state = BOARD_READY;
992 brd->dpastatus = BD_RUNNING;
1000 static int dgap_do_remap(struct board_t *brd)
1002 if (!brd || brd->magic != DGAP_BOARD_MAGIC)
1005 if (!request_mem_region(brd->membase, 0x200000, "dgap"))
1008 if (!request_mem_region(brd->membase + PCI_IO_OFFSET, 0x200000,
1010 release_mem_region(brd->membase, 0x200000);
1014 brd->re_map_membase = ioremap(brd->membase, 0x200000);
1015 if (!brd->re_map_membase) {
1016 release_mem_region(brd->membase, 0x200000);
1017 release_mem_region(brd->membase + PCI_IO_OFFSET, 0x200000);
1021 brd->re_map_port = ioremap((brd->membase + PCI_IO_OFFSET), 0x200000);
1022 if (!brd->re_map_port) {
1023 release_mem_region(brd->membase, 0x200000);
1024 release_mem_region(brd->membase + PCI_IO_OFFSET, 0x200000);
1025 iounmap(brd->re_map_membase);
1032 /*****************************************************************************
1052 * As each timer expires, it determines (a) whether the "transmit"
1053 * waiter needs to be woken up, and (b) whether the poller needs to
1056 ******************************************************************************/
1058 static void dgap_poll_handler(ulong dummy)
1061 struct board_t *brd;
1062 unsigned long lock_flags;
1065 dgap_poll_counter++;
1068 * Do not start the board state machine until
1069 * driver tells us its up and running, and has
1070 * everything it needs.
1072 if (dgap_driver_state != DRIVER_READY)
1073 goto schedule_poller;
1076 * If we have just 1 board, or the system is not SMP,
1077 * then use the typical old style poller.
1078 * Otherwise, use our new tasklet based poller, which should
1079 * speed things up for multiple boards.
1081 if ((dgap_NumBoards == 1) || (num_online_cpus() <= 1)) {
1082 for (i = 0; i < dgap_NumBoards; i++) {
1084 brd = dgap_Board[i];
1086 if (brd->state == BOARD_FAILED)
1088 if (!brd->intr_running)
1089 /* Call the real board poller directly */
1090 dgap_poll_tasklet((unsigned long) brd);
1094 * Go thru each board, kicking off a
1095 * tasklet for each if needed
1097 for (i = 0; i < dgap_NumBoards; i++) {
1098 brd = dgap_Board[i];
1101 * Attempt to grab the board lock.
1103 * If we can't get it, no big deal, the next poll
1104 * will get it. Basically, I just really don't want
1105 * to spin in here, because I want to kick off my
1106 * tasklets as fast as I can, and then get out the
1109 if (!spin_trylock(&brd->bd_lock))
1113 * If board is in a failed state, don't bother
1114 * scheduling a tasklet
1116 if (brd->state == BOARD_FAILED) {
1117 spin_unlock(&brd->bd_lock);
1121 /* Schedule a poll helper task */
1122 if (!brd->intr_running)
1123 tasklet_schedule(&brd->helper_tasklet);
1126 * Can't do DGAP_UNLOCK here, as we don't have
1127 * lock_flags because we did a trylock above.
1129 spin_unlock(&brd->bd_lock);
1136 * Schedule ourself back at the nominal wakeup interval.
1138 DGAP_LOCK(dgap_poll_lock, lock_flags);
1139 dgap_poll_time += dgap_jiffies_from_ms(dgap_poll_tick);
1141 new_time = dgap_poll_time - jiffies;
1143 if ((ulong) new_time >= 2 * dgap_poll_tick) {
1145 jiffies + dgap_jiffies_from_ms(dgap_poll_tick);
1148 dgap_poll_timer.function = dgap_poll_handler;
1149 dgap_poll_timer.data = 0;
1150 dgap_poll_timer.expires = dgap_poll_time;
1151 DGAP_UNLOCK(dgap_poll_lock, lock_flags);
1153 if (!dgap_poll_stop)
1154 add_timer(&dgap_poll_timer);
1160 * Driver interrupt handler.
1162 static irqreturn_t dgap_intr(int irq, void *voidbrd)
1164 struct board_t *brd = (struct board_t *) voidbrd;
1170 * Check to make sure its for us.
1172 if (brd->magic != DGAP_BOARD_MAGIC)
1178 * Schedule tasklet to run at a better time.
1180 tasklet_schedule(&brd->helper_tasklet);
1185 * dgap_init_globals()
1187 * This is where we initialize the globals from the static insmod
1188 * configuration variables. These are declared near the head of
1191 static void dgap_init_globals(void)
1195 for (i = 0; i < MAXBOARDS; i++)
1196 dgap_Board[i] = NULL;
1198 init_timer(&dgap_poll_timer);
1200 init_waitqueue_head(&dgap_dl_wait);
1204 /************************************************************************
1208 ************************************************************************/
1213 * Put the driver to sleep for x ms's
1215 * Returns 0 if timed out, !0 (showing signal) if interrupted by a signal.
1217 static int dgap_ms_sleep(ulong ms)
1219 current->state = TASK_INTERRUPTIBLE;
1220 schedule_timeout((ms * HZ) / 1000);
1221 return signal_pending(current);
1224 /************************************************************************
1226 * TTY Initialization/Cleanup Functions
1228 ************************************************************************/
1231 * dgap_tty_register()
1233 * Init the tty subsystem for this board.
1235 static int dgap_tty_register(struct board_t *brd)
1239 brd->SerialDriver = alloc_tty_driver(MAXPORTS);
1241 snprintf(brd->SerialName, MAXTTYNAMELEN, "tty_dgap_%d_", brd->boardnum);
1242 brd->SerialDriver->name = brd->SerialName;
1243 brd->SerialDriver->name_base = 0;
1244 brd->SerialDriver->major = 0;
1245 brd->SerialDriver->minor_start = 0;
1246 brd->SerialDriver->type = TTY_DRIVER_TYPE_SERIAL;
1247 brd->SerialDriver->subtype = SERIAL_TYPE_NORMAL;
1248 brd->SerialDriver->init_termios = DgapDefaultTermios;
1249 brd->SerialDriver->driver_name = DRVSTR;
1250 brd->SerialDriver->flags = (TTY_DRIVER_REAL_RAW |
1251 TTY_DRIVER_DYNAMIC_DEV |
1252 TTY_DRIVER_HARDWARE_BREAK);
1254 /* The kernel wants space to store pointers to tty_structs */
1255 brd->SerialDriver->ttys =
1256 kzalloc(MAXPORTS * sizeof(struct tty_struct *), GFP_KERNEL);
1257 if (!brd->SerialDriver->ttys)
1261 * Entry points for driver. Called by the kernel from
1262 * tty_io.c and n_tty.c.
1264 tty_set_operations(brd->SerialDriver, &dgap_tty_ops);
1267 * If we're doing transparent print, we have to do all of the above
1268 * again, separately so we don't get the LD confused about what major
1269 * we are when we get into the dgap_tty_open() routine.
1271 brd->PrintDriver = alloc_tty_driver(MAXPORTS);
1273 snprintf(brd->PrintName, MAXTTYNAMELEN, "pr_dgap_%d_", brd->boardnum);
1274 brd->PrintDriver->name = brd->PrintName;
1275 brd->PrintDriver->name_base = 0;
1276 brd->PrintDriver->major = 0;
1277 brd->PrintDriver->minor_start = 0;
1278 brd->PrintDriver->type = TTY_DRIVER_TYPE_SERIAL;
1279 brd->PrintDriver->subtype = SERIAL_TYPE_NORMAL;
1280 brd->PrintDriver->init_termios = DgapDefaultTermios;
1281 brd->PrintDriver->driver_name = DRVSTR;
1282 brd->PrintDriver->flags = (TTY_DRIVER_REAL_RAW |
1283 TTY_DRIVER_DYNAMIC_DEV |
1284 TTY_DRIVER_HARDWARE_BREAK);
1286 /* The kernel wants space to store pointers to tty_structs */
1287 brd->PrintDriver->ttys =
1288 kzalloc(MAXPORTS * sizeof(struct tty_struct *), GFP_KERNEL);
1289 if (!brd->PrintDriver->ttys)
1293 * Entry points for driver. Called by the kernel from
1294 * tty_io.c and n_tty.c.
1296 tty_set_operations(brd->PrintDriver, &dgap_tty_ops);
1298 if (!brd->dgap_Major_Serial_Registered) {
1299 /* Register tty devices */
1300 rc = tty_register_driver(brd->SerialDriver);
1303 brd->dgap_Major_Serial_Registered = TRUE;
1304 dgap_BoardsByMajor[brd->SerialDriver->major] = brd;
1305 brd->dgap_Serial_Major = brd->SerialDriver->major;
1308 if (!brd->dgap_Major_TransparentPrint_Registered) {
1309 /* Register Transparent Print devices */
1310 rc = tty_register_driver(brd->PrintDriver);
1313 brd->dgap_Major_TransparentPrint_Registered = TRUE;
1314 dgap_BoardsByMajor[brd->PrintDriver->major] = brd;
1315 brd->dgap_TransparentPrint_Major = brd->PrintDriver->major;
1324 * Init the tty subsystem. Called once per board after board has been
1325 * downloaded and init'ed.
1327 static int dgap_tty_init(struct board_t *brd)
1331 uint true_count = 0;
1334 struct channel_t *ch;
1342 * Initialize board structure elements.
1345 vaddr = brd->re_map_membase;
1346 true_count = readw((vaddr + NCHAN));
1348 brd->nasync = dgap_config_get_number_of_ports(brd);
1351 brd->nasync = brd->maxports;
1353 if (brd->nasync > brd->maxports)
1354 brd->nasync = brd->maxports;
1356 if (true_count != brd->nasync) {
1357 if ((brd->type == PPCM) && (true_count == 64)) {
1358 pr_warn("dgap: %s configured for %d ports, has %d ports.\n",
1359 brd->name, brd->nasync, true_count);
1360 pr_warn("dgap: Please make SURE the EBI cable running from the card\n");
1361 pr_warn("dgap: to each EM module is plugged into EBI IN!\n");
1362 } else if ((brd->type == PPCM) && (true_count == 0)) {
1363 pr_warn("dgap: %s configured for %d ports, has %d ports.\n",
1364 brd->name, brd->nasync, true_count);
1365 pr_warn("dgap: Please make SURE the EBI cable running from the card\n");
1366 pr_warn("dgap: to each EM module is plugged into EBI IN!\n");
1368 pr_warn("dgap: %s configured for %d ports, has %d ports.\n",
1369 brd->name, brd->nasync, true_count);
1371 brd->nasync = true_count;
1373 /* If no ports, don't bother going any further */
1375 brd->state = BOARD_FAILED;
1376 brd->dpastatus = BD_NOFEP;
1382 * Allocate channel memory that might not have been allocated
1383 * when the driver was first loaded.
1385 for (i = 0; i < brd->nasync; i++) {
1386 if (!brd->channels[i]) {
1388 kzalloc(sizeof(struct channel_t), GFP_ATOMIC);
1389 if (!brd->channels[i])
1394 ch = brd->channels[0];
1395 vaddr = brd->re_map_membase;
1397 bs = (struct bs_t *) ((ulong) vaddr + CHANBUF);
1398 cm = (struct cm_t *) ((ulong) vaddr + CMDBUF);
1402 /* Set up channel variables */
1403 for (i = 0; i < brd->nasync; i++, ch = brd->channels[i], bs++) {
1405 if (!brd->channels[i])
1408 spin_lock_init(&ch->ch_lock);
1410 /* Store all our magic numbers */
1411 ch->magic = DGAP_CHANNEL_MAGIC;
1412 ch->ch_tun.magic = DGAP_UNIT_MAGIC;
1413 ch->ch_tun.un_type = DGAP_SERIAL;
1414 ch->ch_tun.un_ch = ch;
1415 ch->ch_tun.un_dev = i;
1417 ch->ch_pun.magic = DGAP_UNIT_MAGIC;
1418 ch->ch_pun.un_type = DGAP_PRINT;
1419 ch->ch_pun.un_ch = ch;
1420 ch->ch_pun.un_dev = i;
1422 ch->ch_vaddr = vaddr;
1427 ch->ch_digi = dgap_digi_init;
1430 * Set up digi dsr and dcd bits based on altpin flag.
1432 if (dgap_config_get_altpin(brd)) {
1435 ch->ch_digi.digi_flags |= DIGI_ALTPIN;
1438 ch->ch_dsr = DM_DSR;
1441 ch->ch_taddr = vaddr + ((ch->ch_bs->tx_seg) << 4);
1442 ch->ch_raddr = vaddr + ((ch->ch_bs->rx_seg) << 4);
1445 ch->ch_tsize = readw(&(ch->ch_bs->tx_max)) + 1;
1446 ch->ch_rsize = readw(&(ch->ch_bs->rx_max)) + 1;
1450 /* .25 second delay */
1451 ch->ch_close_delay = 250;
1454 * Set queue water marks, interrupt mask,
1455 * and general tty parameters.
1457 tlw = ch->ch_tsize >= 2000 ? ((ch->ch_tsize * 5) / 8) :
1461 dgap_cmdw(ch, STLOW, tlw, 0);
1463 dgap_cmdw(ch, SRLOW, ch->ch_rsize / 2, 0);
1465 dgap_cmdw(ch, SRHIGH, 7 * ch->ch_rsize / 8, 0);
1467 ch->ch_mistat = readb(&(ch->ch_bs->m_stat));
1469 init_waitqueue_head(&ch->ch_flags_wait);
1470 init_waitqueue_head(&ch->ch_tun.un_flags_wait);
1471 init_waitqueue_head(&ch->ch_pun.un_flags_wait);
1472 init_waitqueue_head(&ch->ch_sniff_wait);
1474 /* Turn on all modem interrupts for now */
1475 modem = (DM_CD | DM_DSR | DM_CTS | DM_RI);
1476 writeb(modem, &(ch->ch_bs->m_int));
1479 * Set edelay to 0 if interrupts are turned on,
1480 * otherwise set edelay to the usual 100.
1483 writew(0, &(ch->ch_bs->edelay));
1485 writew(100, &(ch->ch_bs->edelay));
1487 writeb(1, &(ch->ch_bs->idata));
1496 * Uninitialize the TTY portion of this driver. Free all memory and
1499 static void dgap_tty_uninit(struct board_t *brd)
1504 if (brd->dgap_Major_Serial_Registered) {
1505 dgap_BoardsByMajor[brd->SerialDriver->major] = NULL;
1506 brd->dgap_Serial_Major = 0;
1507 for (i = 0; i < brd->nasync; i++) {
1508 tty_port_destroy(&brd->SerialPorts[i]);
1509 dev = brd->channels[i]->ch_tun.un_sysfs;
1510 dgap_remove_tty_sysfs(dev);
1511 tty_unregister_device(brd->SerialDriver, i);
1513 tty_unregister_driver(brd->SerialDriver);
1514 kfree(brd->SerialDriver->ttys);
1515 brd->SerialDriver->ttys = NULL;
1516 put_tty_driver(brd->SerialDriver);
1517 kfree(brd->SerialPorts);
1518 brd->dgap_Major_Serial_Registered = FALSE;
1521 if (brd->dgap_Major_TransparentPrint_Registered) {
1522 dgap_BoardsByMajor[brd->PrintDriver->major] = NULL;
1523 brd->dgap_TransparentPrint_Major = 0;
1524 for (i = 0; i < brd->nasync; i++) {
1525 tty_port_destroy(&brd->PrinterPorts[i]);
1526 dev = brd->channels[i]->ch_pun.un_sysfs;
1527 dgap_remove_tty_sysfs(dev);
1528 tty_unregister_device(brd->PrintDriver, i);
1530 tty_unregister_driver(brd->PrintDriver);
1531 kfree(brd->PrintDriver->ttys);
1532 brd->PrintDriver->ttys = NULL;
1533 put_tty_driver(brd->PrintDriver);
1534 kfree(brd->PrinterPorts);
1535 brd->dgap_Major_TransparentPrint_Registered = FALSE;
1539 #define TMPBUFLEN (1024)
1541 * dgap_sniff - Dump data out to the "sniff" buffer if the
1542 * proc sniff file is opened...
1544 static void dgap_sniff_nowait_nolock(struct channel_t *ch, uchar *text,
1545 uchar *buf, int len)
1553 char tmpbuf[TMPBUFLEN];
1557 /* Leave if sniff not open */
1558 if (!(ch->ch_sniff_flags & SNIFF_OPEN))
1561 do_gettimeofday(&tv);
1563 /* Create our header for data dump */
1564 p += sprintf(p, "<%ld %ld><%s><", tv.tv_sec, tv.tv_usec, text);
1565 tmpbuflen = p - tmpbuf;
1570 for (i = 0; i < len && tmpbuflen < (TMPBUFLEN - 4); i++) {
1571 p += sprintf(p, "%02x ", *buf);
1573 tmpbuflen = p - tmpbuf;
1576 if (tmpbuflen < (TMPBUFLEN - 4)) {
1578 p += sprintf(p - 1, "%s\n", ">");
1580 p += sprintf(p, "%s\n", ">");
1586 nbuf = strlen(tmpbuf);
1590 * Loop while data remains.
1592 while (nbuf > 0 && ch->ch_sniff_buf) {
1594 * Determine the amount of available space left in the
1595 * buffer. If there's none, wait until some appears.
1597 n = (ch->ch_sniff_out - ch->ch_sniff_in - 1) &
1601 * If there is no space left to write to in our sniff
1602 * buffer, we have no choice but to drop the data.
1603 * We *cannot* sleep here waiting for space, because
1604 * this function was probably called by the
1605 * interrupt/timer routines!
1611 * Copy as much data as will fit.
1617 r = SNIFF_MAX - ch->ch_sniff_in;
1620 memcpy(ch->ch_sniff_buf +
1621 ch->ch_sniff_in, p, r);
1624 ch->ch_sniff_in = 0;
1629 memcpy(ch->ch_sniff_buf + ch->ch_sniff_in, p, n);
1631 ch->ch_sniff_in += n;
1636 * Wakeup any thread waiting for data
1638 if (ch->ch_sniff_flags & SNIFF_WAIT_DATA) {
1639 ch->ch_sniff_flags &= ~SNIFF_WAIT_DATA;
1640 wake_up_interruptible(&ch->ch_sniff_wait);
1645 * If the user sent us too much data to push into our tmpbuf,
1646 * we need to keep looping around on all the data.
1648 if (too_much_data) {
1653 } while (too_much_data);
1656 /*=======================================================================
1658 * dgap_input - Process received data.
1660 * ch - Pointer to channel structure.
1662 *=======================================================================*/
1664 static void dgap_input(struct channel_t *ch)
1668 struct tty_struct *tp;
1669 struct tty_ldisc *ld;
1683 if (!ch || ch->magic != DGAP_CHANNEL_MAGIC)
1686 tp = ch->ch_tun.un_tty;
1693 if (!bd || bd->magic != DGAP_BOARD_MAGIC)
1696 DGAP_LOCK(bd->bd_lock, lock_flags);
1697 DGAP_LOCK(ch->ch_lock, lock_flags2);
1700 * Figure the number of characters in the buffer.
1701 * Exit immediately if none.
1704 rmask = ch->ch_rsize - 1;
1706 head = readw(&(bs->rx_head));
1708 tail = readw(&(bs->rx_tail));
1711 data_len = (head - tail) & rmask;
1713 if (data_len == 0) {
1714 writeb(1, &(bs->idata));
1715 DGAP_UNLOCK(ch->ch_lock, lock_flags2);
1716 DGAP_UNLOCK(bd->bd_lock, lock_flags);
1721 * If the device is not open, or CREAD is off, flush
1722 * input data and return immediately.
1724 if ((bd->state != BOARD_READY) || !tp ||
1725 (tp->magic != TTY_MAGIC) ||
1726 !(ch->ch_tun.un_flags & UN_ISOPEN) ||
1727 !(tp->termios.c_cflag & CREAD) ||
1728 (ch->ch_tun.un_flags & UN_CLOSING)) {
1730 writew(head, &(bs->rx_tail));
1731 writeb(1, &(bs->idata));
1732 DGAP_UNLOCK(ch->ch_lock, lock_flags2);
1733 DGAP_UNLOCK(bd->bd_lock, lock_flags);
1738 * If we are throttled, simply don't read any data.
1740 if (ch->ch_flags & CH_RXBLOCK) {
1741 writeb(1, &(bs->idata));
1742 DGAP_UNLOCK(ch->ch_lock, lock_flags2);
1743 DGAP_UNLOCK(bd->bd_lock, lock_flags);
1750 tmpchar = readb(&(bs->orun));
1752 ch->ch_err_overrun++;
1753 writeb(0, &(bs->orun));
1756 /* Decide how much data we can send into the tty layer */
1757 flip_len = TTY_FLIPBUF_SIZE;
1759 /* Chop down the length, if needed */
1760 len = min(data_len, flip_len);
1761 len = min(len, (N_TTY_BUF_SIZE - 1));
1763 ld = tty_ldisc_ref(tp);
1765 #ifdef TTY_DONT_FLIP
1767 * If the DONT_FLIP flag is on, don't flush our buffer, and act
1768 * like the ld doesn't have any space to put the data right now.
1770 if (test_bit(TTY_DONT_FLIP, &tp->flags))
1775 * If we were unable to get a reference to the ld,
1776 * don't flush our buffer, and act like the ld doesn't
1777 * have any space to put the data right now.
1783 * If ld doesn't have a pointer to a receive_buf function,
1784 * flush the data, then act like the ld doesn't have any
1785 * space to put the data right now.
1787 if (!ld->ops->receive_buf) {
1788 writew(head, &(bs->rx_tail));
1794 writeb(1, &(bs->idata));
1795 DGAP_UNLOCK(ch->ch_lock, lock_flags2);
1796 DGAP_UNLOCK(bd->bd_lock, lock_flags);
1798 tty_ldisc_deref(ld);
1802 buf = ch->ch_bd->flipbuf;
1806 * n now contains the most amount of data we can copy,
1807 * bounded either by our buffer size or the amount
1808 * of data the card actually has pending...
1812 s = ((head >= tail) ? head : ch->ch_rsize) - tail;
1818 memcpy_fromio(buf, (char *) ch->ch_raddr + tail, s);
1819 dgap_sniff_nowait_nolock(ch, "USER READ", buf, s);
1825 /* Flip queue if needed */
1829 writew(tail, &(bs->rx_tail));
1830 writeb(1, &(bs->idata));
1831 ch->ch_rxcount += len;
1834 * If we are completely raw, we don't need to go through a lot
1835 * of the tty layers that exist.
1836 * In this case, we take the shortest and fastest route we
1837 * can to relay the data to the user.
1839 * On the other hand, if we are not raw, we need to go through
1840 * the tty layer, which has its API more well defined.
1842 if (I_PARMRK(tp) || I_BRKINT(tp) || I_INPCK(tp)) {
1843 dgap_parity_scan(ch, ch->ch_bd->flipbuf,
1844 ch->ch_bd->flipflagbuf, &len);
1846 len = tty_buffer_request_room(tp->port, len);
1847 tty_insert_flip_string_flags(tp->port, ch->ch_bd->flipbuf,
1848 ch->ch_bd->flipflagbuf, len);
1850 len = tty_buffer_request_room(tp->port, len);
1851 tty_insert_flip_string(tp->port, ch->ch_bd->flipbuf, len);
1854 DGAP_UNLOCK(ch->ch_lock, lock_flags2);
1855 DGAP_UNLOCK(bd->bd_lock, lock_flags);
1857 /* Tell the tty layer its okay to "eat" the data now */
1858 tty_flip_buffer_push(tp->port);
1861 tty_ldisc_deref(ld);
1865 /************************************************************************
1866 * Determines when CARRIER changes state and takes appropriate
1868 ************************************************************************/
1869 static void dgap_carrier(struct channel_t *ch)
1873 int virt_carrier = 0;
1874 int phys_carrier = 0;
1876 if (!ch || ch->magic != DGAP_CHANNEL_MAGIC)
1881 if (!bd || bd->magic != DGAP_BOARD_MAGIC)
1884 /* Make sure altpin is always set correctly */
1885 if (ch->ch_digi.digi_flags & DIGI_ALTPIN) {
1889 ch->ch_dsr = DM_DSR;
1893 if (ch->ch_mistat & D_CD(ch))
1896 if (ch->ch_digi.digi_flags & DIGI_FORCEDCD)
1899 if (ch->ch_c_cflag & CLOCAL)
1903 * Test for a VIRTUAL carrier transition to HIGH.
1905 if (((ch->ch_flags & CH_FCAR) == 0) && (virt_carrier == 1)) {
1908 * When carrier rises, wake any threads waiting
1909 * for carrier in the open routine.
1912 if (waitqueue_active(&(ch->ch_flags_wait)))
1913 wake_up_interruptible(&ch->ch_flags_wait);
1917 * Test for a PHYSICAL carrier transition to HIGH.
1919 if (((ch->ch_flags & CH_CD) == 0) && (phys_carrier == 1)) {
1922 * When carrier rises, wake any threads waiting
1923 * for carrier in the open routine.
1926 if (waitqueue_active(&(ch->ch_flags_wait)))
1927 wake_up_interruptible(&ch->ch_flags_wait);
1931 * Test for a PHYSICAL transition to low, so long as we aren't
1932 * currently ignoring physical transitions (which is what "virtual
1933 * carrier" indicates).
1935 * The transition of the virtual carrier to low really doesn't
1936 * matter... it really only means "ignore carrier state", not
1937 * "make pretend that carrier is there".
1939 if ((virt_carrier == 0) &&
1940 ((ch->ch_flags & CH_CD) != 0) &&
1941 (phys_carrier == 0)) {
1944 * When carrier drops:
1946 * Drop carrier on all open units.
1948 * Flush queues, waking up any task waiting in the
1951 * Send a hangup to the control terminal.
1953 * Enable all select calls.
1955 if (waitqueue_active(&(ch->ch_flags_wait)))
1956 wake_up_interruptible(&ch->ch_flags_wait);
1958 if (ch->ch_tun.un_open_count > 0)
1959 tty_hangup(ch->ch_tun.un_tty);
1961 if (ch->ch_pun.un_open_count > 0)
1962 tty_hangup(ch->ch_pun.un_tty);
1966 * Make sure that our cached values reflect the current reality.
1968 if (virt_carrier == 1)
1969 ch->ch_flags |= CH_FCAR;
1971 ch->ch_flags &= ~CH_FCAR;
1973 if (phys_carrier == 1)
1974 ch->ch_flags |= CH_CD;
1976 ch->ch_flags &= ~CH_CD;
1979 /************************************************************************
1981 * TTY Entry points and helper functions
1983 ************************************************************************/
1989 static int dgap_tty_open(struct tty_struct *tty, struct file *file)
1991 struct board_t *brd;
1992 struct channel_t *ch;
2004 major = MAJOR(tty_devnum(tty));
2005 minor = MINOR(tty_devnum(tty));
2010 /* Get board pointer from our array of majors we have allocated */
2011 brd = dgap_BoardsByMajor[major];
2016 * If board is not yet up to a state of READY, go to
2017 * sleep waiting for it to happen or they cancel the open.
2019 rc = wait_event_interruptible(brd->state_wait,
2020 (brd->state & BOARD_READY));
2025 DGAP_LOCK(brd->bd_lock, lock_flags);
2027 /* The wait above should guarantee this cannot happen */
2028 if (brd->state != BOARD_READY) {
2029 DGAP_UNLOCK(brd->bd_lock, lock_flags);
2033 /* If opened device is greater than our number of ports, bail. */
2034 if (MINOR(tty_devnum(tty)) > brd->nasync) {
2035 DGAP_UNLOCK(brd->bd_lock, lock_flags);
2039 ch = brd->channels[minor];
2041 DGAP_UNLOCK(brd->bd_lock, lock_flags);
2045 /* Grab channel lock */
2046 DGAP_LOCK(ch->ch_lock, lock_flags2);
2048 /* Figure out our type */
2049 if (major == brd->dgap_Serial_Major) {
2050 un = &brd->channels[minor]->ch_tun;
2051 un->un_type = DGAP_SERIAL;
2052 } else if (major == brd->dgap_TransparentPrint_Major) {
2053 un = &brd->channels[minor]->ch_pun;
2054 un->un_type = DGAP_PRINT;
2056 DGAP_UNLOCK(ch->ch_lock, lock_flags2);
2057 DGAP_UNLOCK(brd->bd_lock, lock_flags);
2061 /* Store our unit into driver_data, so we always have it available. */
2062 tty->driver_data = un;
2065 * Error if channel info pointer is NULL.
2069 DGAP_UNLOCK(ch->ch_lock, lock_flags2);
2070 DGAP_UNLOCK(brd->bd_lock, lock_flags);
2077 if (!(un->un_flags & UN_ISOPEN)) {
2078 /* Store important variables. */
2081 /* Maybe do something here to the TTY struct as well? */
2085 * Initialize if neither terminal or printer is open.
2087 if (!((ch->ch_tun.un_flags | ch->ch_pun.un_flags) & UN_ISOPEN)) {
2093 * Flush input queue.
2095 head = readw(&(bs->rx_head));
2096 writew(head, &(bs->rx_tail));
2099 ch->pscan_state = 0;
2100 ch->pscan_savechar = 0;
2102 ch->ch_c_cflag = tty->termios.c_cflag;
2103 ch->ch_c_iflag = tty->termios.c_iflag;
2104 ch->ch_c_oflag = tty->termios.c_oflag;
2105 ch->ch_c_lflag = tty->termios.c_lflag;
2106 ch->ch_startc = tty->termios.c_cc[VSTART];
2107 ch->ch_stopc = tty->termios.c_cc[VSTOP];
2109 /* TODO: flush our TTY struct here? */
2114 * Run param in case we changed anything
2119 * follow protocol for opening port
2122 DGAP_UNLOCK(ch->ch_lock, lock_flags2);
2123 DGAP_UNLOCK(brd->bd_lock, lock_flags);
2125 rc = dgap_block_til_ready(tty, file, ch);
2130 /* No going back now, increment our unit and channel counters */
2131 DGAP_LOCK(ch->ch_lock, lock_flags);
2132 ch->ch_open_count++;
2133 un->un_open_count++;
2134 un->un_flags |= (UN_ISOPEN);
2135 DGAP_UNLOCK(ch->ch_lock, lock_flags);
2141 * dgap_block_til_ready()
2143 * Wait for DCD, if needed.
2145 static int dgap_block_til_ready(struct tty_struct *tty, struct file *file,
2146 struct channel_t *ch)
2149 struct un_t *un = NULL;
2152 int sleep_on_un_flags = 0;
2154 if (!tty || tty->magic != TTY_MAGIC || !file || !ch ||
2155 ch->magic != DGAP_CHANNEL_MAGIC)
2158 un = tty->driver_data;
2159 if (!un || un->magic != DGAP_UNIT_MAGIC)
2162 DGAP_LOCK(ch->ch_lock, lock_flags);
2169 sleep_on_un_flags = 0;
2172 * If board has failed somehow during our sleep,
2175 if (ch->ch_bd->state == BOARD_FAILED) {
2180 /* If tty was hung up, break out of loop and set error. */
2181 if (tty_hung_up_p(file)) {
2187 * If either unit is in the middle of the fragile part of close,
2188 * we just cannot touch the channel safely.
2189 * Go back to sleep, knowing that when the channel can be
2190 * touched safely, the close routine will signal the
2191 * ch_wait_flags to wake us back up.
2193 if (!((ch->ch_tun.un_flags | ch->ch_pun.un_flags) &
2197 * Our conditions to leave cleanly and happily:
2198 * 1) NONBLOCKING on the tty is set.
2200 * 3) DCD (fake or real) is active.
2203 if (file->f_flags & O_NONBLOCK)
2206 if (tty->flags & (1 << TTY_IO_ERROR))
2209 if (ch->ch_flags & CH_CD)
2212 if (ch->ch_flags & CH_FCAR)
2215 sleep_on_un_flags = 1;
2219 * If there is a signal pending, the user probably
2220 * interrupted (ctrl-c) us.
2221 * Leave loop with error set.
2223 if (signal_pending(current)) {
2224 retval = -ERESTARTSYS;
2229 * Store the flags before we let go of channel lock
2231 if (sleep_on_un_flags)
2232 old_flags = ch->ch_tun.un_flags | ch->ch_pun.un_flags;
2234 old_flags = ch->ch_flags;
2237 * Let go of channel lock before calling schedule.
2238 * Our poller will get any FEP events and wake us up when DCD
2239 * eventually goes active.
2242 DGAP_UNLOCK(ch->ch_lock, lock_flags);
2245 * Wait for something in the flags to change
2246 * from the current value.
2248 if (sleep_on_un_flags) {
2249 retval = wait_event_interruptible(un->un_flags_wait,
2250 (old_flags != (ch->ch_tun.un_flags |
2251 ch->ch_pun.un_flags)));
2253 retval = wait_event_interruptible(ch->ch_flags_wait,
2254 (old_flags != ch->ch_flags));
2258 * We got woken up for some reason.
2259 * Before looping around, grab our channel lock.
2261 DGAP_LOCK(ch->ch_lock, lock_flags);
2266 DGAP_UNLOCK(ch->ch_lock, lock_flags);
2277 * Hangup the port. Like a close, but don't wait for output to drain.
2279 static void dgap_tty_hangup(struct tty_struct *tty)
2282 struct channel_t *ch;
2285 if (!tty || tty->magic != TTY_MAGIC)
2288 un = tty->driver_data;
2289 if (!un || un->magic != DGAP_UNIT_MAGIC)
2293 if (!ch || ch->magic != DGAP_CHANNEL_MAGIC)
2297 if (!bd || bd->magic != DGAP_BOARD_MAGIC)
2300 /* flush the transmit queues */
2301 dgap_tty_flush_buffer(tty);
2309 static void dgap_tty_close(struct tty_struct *tty, struct file *file)
2311 struct ktermios *ts;
2313 struct channel_t *ch;
2318 if (!tty || tty->magic != TTY_MAGIC)
2321 un = tty->driver_data;
2322 if (!un || un->magic != DGAP_UNIT_MAGIC)
2326 if (!ch || ch->magic != DGAP_CHANNEL_MAGIC)
2330 if (!bd || bd->magic != DGAP_BOARD_MAGIC)
2335 DGAP_LOCK(ch->ch_lock, lock_flags);
2338 * Determine if this is the last close or not - and if we agree about
2339 * which type of close it is with the Line Discipline
2341 if ((tty->count == 1) && (un->un_open_count != 1)) {
2343 * Uh, oh. tty->count is 1, which means that the tty
2344 * structure will be freed. un_open_count should always
2345 * be one in these conditions. If it's greater than
2346 * one, we've got real problems, since it means the
2347 * serial port won't be shutdown.
2349 un->un_open_count = 1;
2352 if (--un->un_open_count < 0)
2353 un->un_open_count = 0;
2355 ch->ch_open_count--;
2357 if (ch->ch_open_count && un->un_open_count) {
2358 DGAP_UNLOCK(ch->ch_lock, lock_flags);
2362 /* OK, its the last close on the unit */
2364 un->un_flags |= UN_CLOSING;
2369 * Only officially close channel if count is 0 and
2370 * DIGI_PRINTER bit is not set.
2372 if ((ch->ch_open_count == 0) &&
2373 !(ch->ch_digi.digi_flags & DIGI_PRINTER)) {
2375 ch->ch_flags &= ~(CH_RXBLOCK);
2377 DGAP_UNLOCK(ch->ch_lock, lock_flags);
2379 /* wait for output to drain */
2380 /* This will also return if we take an interrupt */
2382 rc = dgap_wait_for_drain(tty);
2384 dgap_tty_flush_buffer(tty);
2385 tty_ldisc_flush(tty);
2387 DGAP_LOCK(ch->ch_lock, lock_flags);
2392 * If we have HUPCL set, lower DTR and RTS
2394 if (ch->ch_c_cflag & HUPCL) {
2395 ch->ch_mostat &= ~(D_RTS(ch)|D_DTR(ch));
2396 dgap_cmdb(ch, SMODEM, 0, D_DTR(ch)|D_RTS(ch), 0);
2399 * Go to sleep to ensure RTS/DTR
2400 * have been dropped for modems to see it.
2402 if (ch->ch_close_delay) {
2403 DGAP_UNLOCK(ch->ch_lock, lock_flags);
2404 dgap_ms_sleep(ch->ch_close_delay);
2405 DGAP_LOCK(ch->ch_lock, lock_flags);
2409 ch->pscan_state = 0;
2410 ch->pscan_savechar = 0;
2411 ch->ch_baud_info = 0;
2416 * turn off print device when closing print device.
2418 if ((un->un_type == DGAP_PRINT) && (ch->ch_flags & CH_PRON)) {
2419 dgap_wmove(ch, ch->ch_digi.digi_offstr,
2420 (int) ch->ch_digi.digi_offlen);
2421 ch->ch_flags &= ~CH_PRON;
2425 un->un_flags &= ~(UN_ISOPEN | UN_CLOSING);
2426 tty->driver_data = NULL;
2428 wake_up_interruptible(&ch->ch_flags_wait);
2429 wake_up_interruptible(&un->un_flags_wait);
2431 DGAP_UNLOCK(ch->ch_lock, lock_flags);
2435 * dgap_tty_chars_in_buffer()
2437 * Return number of characters that have not been transmitted yet.
2439 * This routine is used by the line discipline to determine if there
2440 * is data waiting to be transmitted/drained/flushed or not.
2442 static int dgap_tty_chars_in_buffer(struct tty_struct *tty)
2444 struct board_t *bd = NULL;
2445 struct channel_t *ch = NULL;
2446 struct un_t *un = NULL;
2447 struct bs_t *bs = NULL;
2450 u16 thead, ttail, tmask, chead, ctail;
2451 ulong lock_flags = 0;
2452 ulong lock_flags2 = 0;
2457 un = tty->driver_data;
2458 if (!un || un->magic != DGAP_UNIT_MAGIC)
2462 if (!ch || ch->magic != DGAP_CHANNEL_MAGIC)
2466 if (!bd || bd->magic != DGAP_BOARD_MAGIC)
2473 DGAP_LOCK(bd->bd_lock, lock_flags);
2474 DGAP_LOCK(ch->ch_lock, lock_flags2);
2476 tmask = (ch->ch_tsize - 1);
2478 /* Get Transmit queue pointers */
2479 thead = readw(&(bs->tx_head)) & tmask;
2480 ttail = readw(&(bs->tx_tail)) & tmask;
2482 /* Get tbusy flag */
2483 tbusy = readb(&(bs->tbusy));
2485 /* Get Command queue pointers */
2486 chead = readw(&(ch->ch_cm->cm_head));
2487 ctail = readw(&(ch->ch_cm->cm_tail));
2489 DGAP_UNLOCK(ch->ch_lock, lock_flags2);
2490 DGAP_UNLOCK(bd->bd_lock, lock_flags);
2493 * The only way we know for sure if there is no pending
2494 * data left to be transferred, is if:
2495 * 1) Transmit head and tail are equal (empty).
2496 * 2) Command queue head and tail are equal (empty).
2497 * 3) The "TBUSY" flag is 0. (Transmitter not busy).
2500 if ((ttail == thead) && (tbusy == 0) && (chead == ctail)) {
2504 chars = thead - ttail;
2506 chars = thead - ttail + ch->ch_tsize;
2508 * Fudge factor here.
2509 * If chars is zero, we know that the command queue had
2510 * something in it or tbusy was set. Because we cannot
2511 * be sure if there is still some data to be transmitted,
2512 * lets lie, and tell ld we have 1 byte left.
2516 * If TBUSY is still set, and our tx buffers are empty,
2517 * force the firmware to send me another wakeup after
2518 * TBUSY has been cleared.
2521 DGAP_LOCK(ch->ch_lock, lock_flags);
2522 un->un_flags |= UN_EMPTY;
2523 writeb(1, &(bs->iempty));
2524 DGAP_UNLOCK(ch->ch_lock, lock_flags);
2533 static int dgap_wait_for_drain(struct tty_struct *tty)
2535 struct channel_t *ch;
2540 ulong lock_flags = 0;
2542 if (!tty || tty->magic != TTY_MAGIC)
2545 un = tty->driver_data;
2546 if (!un || un->magic != DGAP_UNIT_MAGIC)
2550 if (!ch || ch->magic != DGAP_CHANNEL_MAGIC)
2559 /* Loop until data is drained */
2560 while (count != 0) {
2562 count = dgap_tty_chars_in_buffer(tty);
2567 /* Set flag waiting for drain */
2568 DGAP_LOCK(ch->ch_lock, lock_flags);
2569 un->un_flags |= UN_EMPTY;
2570 writeb(1, &(bs->iempty));
2571 DGAP_UNLOCK(ch->ch_lock, lock_flags);
2573 /* Go to sleep till we get woken up */
2574 ret = wait_event_interruptible(un->un_flags_wait,
2575 ((un->un_flags & UN_EMPTY) == 0));
2576 /* If ret is non-zero, user ctrl-c'ed us */
2581 DGAP_LOCK(ch->ch_lock, lock_flags);
2582 un->un_flags &= ~(UN_EMPTY);
2583 DGAP_UNLOCK(ch->ch_lock, lock_flags);
2591 * Reduces bytes_available to the max number of characters
2592 * that can be sent currently given the maxcps value, and
2593 * returns the new bytes_available. This only affects printer
2596 static int dgap_maxcps_room(struct tty_struct *tty, int bytes_available)
2598 struct channel_t *ch = NULL;
2599 struct un_t *un = NULL;
2602 return bytes_available;
2604 un = tty->driver_data;
2605 if (!un || un->magic != DGAP_UNIT_MAGIC)
2606 return bytes_available;
2609 if (!ch || ch->magic != DGAP_CHANNEL_MAGIC)
2610 return bytes_available;
2613 * If its not the Transparent print device, return
2614 * the full data amount.
2616 if (un->un_type != DGAP_PRINT)
2617 return bytes_available;
2619 if (ch->ch_digi.digi_maxcps > 0 && ch->ch_digi.digi_bufsize > 0) {
2621 unsigned long current_time = jiffies;
2622 unsigned long buffer_time = current_time +
2623 (HZ * ch->ch_digi.digi_bufsize) /
2624 ch->ch_digi.digi_maxcps;
2626 if (ch->ch_cpstime < current_time) {
2627 /* buffer is empty */
2628 ch->ch_cpstime = current_time; /* reset ch_cpstime */
2629 cps_limit = ch->ch_digi.digi_bufsize;
2630 } else if (ch->ch_cpstime < buffer_time) {
2631 /* still room in the buffer */
2632 cps_limit = ((buffer_time - ch->ch_cpstime) *
2633 ch->ch_digi.digi_maxcps) / HZ;
2635 /* no room in the buffer */
2639 bytes_available = min(cps_limit, bytes_available);
2642 return bytes_available;
2645 static inline void dgap_set_firmware_event(struct un_t *un, unsigned int event)
2647 struct channel_t *ch = NULL;
2648 struct bs_t *bs = NULL;
2650 if (!un || un->magic != DGAP_UNIT_MAGIC)
2653 if (!ch || ch->magic != DGAP_CHANNEL_MAGIC)
2659 if ((event & UN_LOW) != 0) {
2660 if ((un->un_flags & UN_LOW) == 0) {
2661 un->un_flags |= UN_LOW;
2662 writeb(1, &(bs->ilow));
2665 if ((event & UN_LOW) != 0) {
2666 if ((un->un_flags & UN_EMPTY) == 0) {
2667 un->un_flags |= UN_EMPTY;
2668 writeb(1, &(bs->iempty));
2674 * dgap_tty_write_room()
2676 * Return space available in Tx buffer
2678 static int dgap_tty_write_room(struct tty_struct *tty)
2680 struct channel_t *ch = NULL;
2681 struct un_t *un = NULL;
2682 struct bs_t *bs = NULL;
2683 u16 head, tail, tmask;
2685 ulong lock_flags = 0;
2690 un = tty->driver_data;
2691 if (!un || un->magic != DGAP_UNIT_MAGIC)
2695 if (!ch || ch->magic != DGAP_CHANNEL_MAGIC)
2702 DGAP_LOCK(ch->ch_lock, lock_flags);
2704 tmask = ch->ch_tsize - 1;
2705 head = readw(&(bs->tx_head)) & tmask;
2706 tail = readw(&(bs->tx_tail)) & tmask;
2708 ret = tail - head - 1;
2710 ret += ch->ch_tsize;
2712 /* Limit printer to maxcps */
2713 ret = dgap_maxcps_room(tty, ret);
2716 * If we are printer device, leave space for
2717 * possibly both the on and off strings.
2719 if (un->un_type == DGAP_PRINT) {
2720 if (!(ch->ch_flags & CH_PRON))
2721 ret -= ch->ch_digi.digi_onlen;
2722 ret -= ch->ch_digi.digi_offlen;
2724 if (ch->ch_flags & CH_PRON)
2725 ret -= ch->ch_digi.digi_offlen;
2732 * Schedule FEP to wake us up if needed.
2734 * TODO: This might be overkill...
2735 * Do we really need to schedule callbacks from the FEP
2736 * in every case? Can we get smarter based on ret?
2738 dgap_set_firmware_event(un, UN_LOW | UN_EMPTY);
2739 DGAP_UNLOCK(ch->ch_lock, lock_flags);
2745 * dgap_tty_put_char()
2747 * Put a character into ch->ch_buf
2749 * - used by the line discipline for OPOST processing
2751 static int dgap_tty_put_char(struct tty_struct *tty, unsigned char c)
2754 * Simply call tty_write.
2756 dgap_tty_write(tty, &c, 1);
2763 * Take data from the user or kernel and send it out to the FEP.
2764 * In here exists all the Transparent Print magic as well.
2766 static int dgap_tty_write(struct tty_struct *tty, const unsigned char *buf,
2769 struct channel_t *ch = NULL;
2770 struct un_t *un = NULL;
2771 struct bs_t *bs = NULL;
2773 u16 head, tail, tmask, remain;
2774 int bufcount = 0, n = 0;
2781 un = tty->driver_data;
2782 if (!un || un->magic != DGAP_UNIT_MAGIC)
2786 if (!ch || ch->magic != DGAP_CHANNEL_MAGIC)
2797 * Store original amount of characters passed in.
2798 * This helps to figure out if we should ask the FEP
2799 * to send us an event when it has more space available.
2803 DGAP_LOCK(ch->ch_lock, lock_flags);
2805 /* Get our space available for the channel from the board */
2806 tmask = ch->ch_tsize - 1;
2807 head = readw(&(bs->tx_head)) & tmask;
2808 tail = readw(&(bs->tx_tail)) & tmask;
2810 bufcount = tail - head - 1;
2812 bufcount += ch->ch_tsize;
2815 * Limit printer output to maxcps overall, with bursts allowed
2816 * up to bufsize characters.
2818 bufcount = dgap_maxcps_room(tty, bufcount);
2821 * Take minimum of what the user wants to send, and the
2822 * space available in the FEP buffer.
2824 count = min(count, bufcount);
2827 * Bail if no space left.
2830 dgap_set_firmware_event(un, UN_LOW | UN_EMPTY);
2831 DGAP_UNLOCK(ch->ch_lock, lock_flags);
2836 * Output the printer ON string, if we are in terminal mode, but
2837 * need to be in printer mode.
2839 if ((un->un_type == DGAP_PRINT) && !(ch->ch_flags & CH_PRON)) {
2840 dgap_wmove(ch, ch->ch_digi.digi_onstr,
2841 (int) ch->ch_digi.digi_onlen);
2842 head = readw(&(bs->tx_head)) & tmask;
2843 ch->ch_flags |= CH_PRON;
2847 * On the other hand, output the printer OFF string, if we are
2848 * currently in printer mode, but need to output to the terminal.
2850 if ((un->un_type != DGAP_PRINT) && (ch->ch_flags & CH_PRON)) {
2851 dgap_wmove(ch, ch->ch_digi.digi_offstr,
2852 (int) ch->ch_digi.digi_offlen);
2853 head = readw(&(bs->tx_head)) & tmask;
2854 ch->ch_flags &= ~CH_PRON;
2858 * If there is nothing left to copy, or
2859 * I can't handle any more data, leave.
2862 dgap_set_firmware_event(un, UN_LOW | UN_EMPTY);
2863 DGAP_UNLOCK(ch->ch_lock, lock_flags);
2870 * If the write wraps over the top of the circular buffer,
2871 * move the portion up to the wrap point, and reset the
2872 * pointers to the bottom.
2874 remain = ch->ch_tstart + ch->ch_tsize - head;
2878 vaddr = ch->ch_taddr + head;
2880 memcpy_toio(vaddr, (uchar *) buf, remain);
2881 dgap_sniff_nowait_nolock(ch, "USER WRITE", (uchar *) buf,
2884 head = ch->ch_tstart;
2891 * Move rest of data.
2893 vaddr = ch->ch_taddr + head;
2896 memcpy_toio(vaddr, (uchar *) buf, remain);
2897 dgap_sniff_nowait_nolock(ch, "USER WRITE", (uchar *)buf,
2905 ch->ch_txcount += count;
2907 writew(head, &(bs->tx_head));
2910 dgap_set_firmware_event(un, UN_LOW | UN_EMPTY);
2913 * If this is the print device, and the
2914 * printer is still on, we need to turn it
2915 * off before going idle. If the buffer is
2916 * non-empty, wait until it goes empty.
2917 * Otherwise turn it off right now.
2919 if ((un->un_type == DGAP_PRINT) && (ch->ch_flags & CH_PRON)) {
2920 tail = readw(&(bs->tx_tail)) & tmask;
2923 un->un_flags |= UN_EMPTY;
2924 writeb(1, &(bs->iempty));
2926 dgap_wmove(ch, ch->ch_digi.digi_offstr,
2927 (int) ch->ch_digi.digi_offlen);
2928 head = readw(&(bs->tx_head)) & tmask;
2929 ch->ch_flags &= ~CH_PRON;
2933 /* Update printer buffer empty time. */
2934 if ((un->un_type == DGAP_PRINT) && (ch->ch_digi.digi_maxcps > 0)
2935 && (ch->ch_digi.digi_bufsize > 0)) {
2936 ch->ch_cpstime += (HZ * count) / ch->ch_digi.digi_maxcps;
2939 DGAP_UNLOCK(ch->ch_lock, lock_flags);
2945 * Return modem signals to ld.
2947 static int dgap_tty_tiocmget(struct tty_struct *tty)
2949 struct channel_t *ch;
2955 if (!tty || tty->magic != TTY_MAGIC)
2958 un = tty->driver_data;
2959 if (!un || un->magic != DGAP_UNIT_MAGIC)
2963 if (!ch || ch->magic != DGAP_CHANNEL_MAGIC)
2966 DGAP_LOCK(ch->ch_lock, lock_flags);
2968 mstat = readb(&(ch->ch_bs->m_stat));
2969 /* Append any outbound signals that might be pending... */
2970 mstat |= ch->ch_mostat;
2972 DGAP_UNLOCK(ch->ch_lock, lock_flags);
2976 if (mstat & D_DTR(ch))
2977 result |= TIOCM_DTR;
2978 if (mstat & D_RTS(ch))
2979 result |= TIOCM_RTS;
2980 if (mstat & D_CTS(ch))
2981 result |= TIOCM_CTS;
2982 if (mstat & D_DSR(ch))
2983 result |= TIOCM_DSR;
2984 if (mstat & D_RI(ch))
2986 if (mstat & D_CD(ch))
2993 * dgap_tty_tiocmset()
2995 * Set modem signals, called by ld.
2997 static int dgap_tty_tiocmset(struct tty_struct *tty,
2998 unsigned int set, unsigned int clear)
3001 struct channel_t *ch;
3007 if (!tty || tty->magic != TTY_MAGIC)
3010 un = tty->driver_data;
3011 if (!un || un->magic != DGAP_UNIT_MAGIC)
3015 if (!ch || ch->magic != DGAP_CHANNEL_MAGIC)
3019 if (!bd || bd->magic != DGAP_BOARD_MAGIC)
3022 DGAP_LOCK(bd->bd_lock, lock_flags);
3023 DGAP_LOCK(ch->ch_lock, lock_flags2);
3025 if (set & TIOCM_RTS) {
3026 ch->ch_mforce |= D_RTS(ch);
3027 ch->ch_mval |= D_RTS(ch);
3030 if (set & TIOCM_DTR) {
3031 ch->ch_mforce |= D_DTR(ch);
3032 ch->ch_mval |= D_DTR(ch);
3035 if (clear & TIOCM_RTS) {
3036 ch->ch_mforce |= D_RTS(ch);
3037 ch->ch_mval &= ~(D_RTS(ch));
3040 if (clear & TIOCM_DTR) {
3041 ch->ch_mforce |= D_DTR(ch);
3042 ch->ch_mval &= ~(D_DTR(ch));
3047 DGAP_UNLOCK(ch->ch_lock, lock_flags2);
3048 DGAP_UNLOCK(bd->bd_lock, lock_flags);
3054 * dgap_tty_send_break()
3056 * Send a Break, called by ld.
3058 static int dgap_tty_send_break(struct tty_struct *tty, int msec)
3061 struct channel_t *ch;
3067 if (!tty || tty->magic != TTY_MAGIC)
3070 un = tty->driver_data;
3071 if (!un || un->magic != DGAP_UNIT_MAGIC)
3075 if (!ch || ch->magic != DGAP_CHANNEL_MAGIC)
3079 if (!bd || bd->magic != DGAP_BOARD_MAGIC)
3094 DGAP_LOCK(bd->bd_lock, lock_flags);
3095 DGAP_LOCK(ch->ch_lock, lock_flags2);
3097 dgap_cmdw(ch, SBREAK, (u16) SBREAK_TIME, 0);
3099 dgap_cmdw(ch, SBREAK, (u16) msec, 0);
3101 DGAP_UNLOCK(ch->ch_lock, lock_flags2);
3102 DGAP_UNLOCK(bd->bd_lock, lock_flags);
3108 * dgap_tty_wait_until_sent()
3110 * wait until data has been transmitted, called by ld.
3112 static void dgap_tty_wait_until_sent(struct tty_struct *tty, int timeout)
3114 dgap_wait_for_drain(tty);
3120 * send a high priority character, called by ld.
3122 static void dgap_tty_send_xchar(struct tty_struct *tty, char c)
3125 struct channel_t *ch;
3130 if (!tty || tty->magic != TTY_MAGIC)
3133 un = tty->driver_data;
3134 if (!un || un->magic != DGAP_UNIT_MAGIC)
3138 if (!ch || ch->magic != DGAP_CHANNEL_MAGIC)
3142 if (!bd || bd->magic != DGAP_BOARD_MAGIC)
3145 DGAP_LOCK(bd->bd_lock, lock_flags);
3146 DGAP_LOCK(ch->ch_lock, lock_flags2);
3149 * This is technically what we should do.
3150 * However, the NIST tests specifically want
3151 * to see each XON or XOFF character that it
3152 * sends, so lets just send each character
3156 if (c == STOP_CHAR(tty))
3157 dgap_cmdw(ch, RPAUSE, 0, 0);
3158 else if (c == START_CHAR(tty))
3159 dgap_cmdw(ch, RRESUME, 0, 0);
3161 dgap_wmove(ch, &c, 1);
3163 dgap_wmove(ch, &c, 1);
3166 DGAP_UNLOCK(ch->ch_lock, lock_flags2);
3167 DGAP_UNLOCK(bd->bd_lock, lock_flags);
3173 * Return modem signals to ld.
3175 static int dgap_get_modem_info(struct channel_t *ch, unsigned int __user *value)
3182 if (!ch || ch->magic != DGAP_CHANNEL_MAGIC)
3185 DGAP_LOCK(ch->ch_lock, lock_flags);
3187 mstat = readb(&(ch->ch_bs->m_stat));
3188 /* Append any outbound signals that might be pending... */
3189 mstat |= ch->ch_mostat;
3191 DGAP_UNLOCK(ch->ch_lock, lock_flags);
3195 if (mstat & D_DTR(ch))
3196 result |= TIOCM_DTR;
3197 if (mstat & D_RTS(ch))
3198 result |= TIOCM_RTS;
3199 if (mstat & D_CTS(ch))
3200 result |= TIOCM_CTS;
3201 if (mstat & D_DSR(ch))
3202 result |= TIOCM_DSR;
3203 if (mstat & D_RI(ch))
3205 if (mstat & D_CD(ch))
3208 rc = put_user(result, value);
3214 * dgap_set_modem_info()
3216 * Set modem signals, called by ld.
3218 static int dgap_set_modem_info(struct tty_struct *tty, unsigned int command,
3219 unsigned int __user *value)
3222 struct channel_t *ch;
3225 unsigned int arg = 0;
3229 if (!tty || tty->magic != TTY_MAGIC)
3232 un = tty->driver_data;
3233 if (!un || un->magic != DGAP_UNIT_MAGIC)
3237 if (!ch || ch->magic != DGAP_CHANNEL_MAGIC)
3241 if (!bd || bd->magic != DGAP_BOARD_MAGIC)
3244 ret = get_user(arg, value);
3250 if (arg & TIOCM_RTS) {
3251 ch->ch_mforce |= D_RTS(ch);
3252 ch->ch_mval |= D_RTS(ch);
3255 if (arg & TIOCM_DTR) {
3256 ch->ch_mforce |= D_DTR(ch);
3257 ch->ch_mval |= D_DTR(ch);
3263 if (arg & TIOCM_RTS) {
3264 ch->ch_mforce |= D_RTS(ch);
3265 ch->ch_mval &= ~(D_RTS(ch));
3268 if (arg & TIOCM_DTR) {
3269 ch->ch_mforce |= D_DTR(ch);
3270 ch->ch_mval &= ~(D_DTR(ch));
3276 ch->ch_mforce = D_DTR(ch)|D_RTS(ch);
3278 if (arg & TIOCM_RTS)
3279 ch->ch_mval |= D_RTS(ch);
3281 ch->ch_mval &= ~(D_RTS(ch));
3283 if (arg & TIOCM_DTR)
3284 ch->ch_mval |= (D_DTR(ch));
3286 ch->ch_mval &= ~(D_DTR(ch));
3294 DGAP_LOCK(bd->bd_lock, lock_flags);
3295 DGAP_LOCK(ch->ch_lock, lock_flags2);
3299 DGAP_UNLOCK(ch->ch_lock, lock_flags2);
3300 DGAP_UNLOCK(bd->bd_lock, lock_flags);
3306 * dgap_tty_digigeta()
3308 * Ioctl to get the information for ditty.
3313 static int dgap_tty_digigeta(struct tty_struct *tty,
3314 struct digi_t __user *retinfo)
3316 struct channel_t *ch;
3324 if (!tty || tty->magic != TTY_MAGIC)
3327 un = tty->driver_data;
3328 if (!un || un->magic != DGAP_UNIT_MAGIC)
3332 if (!ch || ch->magic != DGAP_CHANNEL_MAGIC)
3335 memset(&tmp, 0, sizeof(tmp));
3337 DGAP_LOCK(ch->ch_lock, lock_flags);
3338 memcpy(&tmp, &ch->ch_digi, sizeof(tmp));
3339 DGAP_UNLOCK(ch->ch_lock, lock_flags);
3341 if (copy_to_user(retinfo, &tmp, sizeof(*retinfo)))
3348 * dgap_tty_digiseta()
3350 * Ioctl to set the information for ditty.
3355 static int dgap_tty_digiseta(struct tty_struct *tty,
3356 struct digi_t __user *new_info)
3359 struct channel_t *ch;
3361 struct digi_t new_digi;
3362 ulong lock_flags = 0;
3363 unsigned long lock_flags2;
3365 if (!tty || tty->magic != TTY_MAGIC)
3368 un = tty->driver_data;
3369 if (!un || un->magic != DGAP_UNIT_MAGIC)
3373 if (!ch || ch->magic != DGAP_CHANNEL_MAGIC)
3377 if (!bd || bd->magic != DGAP_BOARD_MAGIC)
3380 if (copy_from_user(&new_digi, new_info, sizeof(struct digi_t)))
3383 DGAP_LOCK(bd->bd_lock, lock_flags);
3384 DGAP_LOCK(ch->ch_lock, lock_flags2);
3386 memcpy(&ch->ch_digi, &new_digi, sizeof(struct digi_t));
3388 if (ch->ch_digi.digi_maxcps < 1)
3389 ch->ch_digi.digi_maxcps = 1;
3391 if (ch->ch_digi.digi_maxcps > 10000)
3392 ch->ch_digi.digi_maxcps = 10000;
3394 if (ch->ch_digi.digi_bufsize < 10)
3395 ch->ch_digi.digi_bufsize = 10;
3397 if (ch->ch_digi.digi_maxchar < 1)
3398 ch->ch_digi.digi_maxchar = 1;
3400 if (ch->ch_digi.digi_maxchar > ch->ch_digi.digi_bufsize)
3401 ch->ch_digi.digi_maxchar = ch->ch_digi.digi_bufsize;
3403 if (ch->ch_digi.digi_onlen > DIGI_PLEN)
3404 ch->ch_digi.digi_onlen = DIGI_PLEN;
3406 if (ch->ch_digi.digi_offlen > DIGI_PLEN)
3407 ch->ch_digi.digi_offlen = DIGI_PLEN;
3411 DGAP_UNLOCK(ch->ch_lock, lock_flags2);
3412 DGAP_UNLOCK(bd->bd_lock, lock_flags);
3418 * dgap_tty_digigetedelay()
3420 * Ioctl to get the current edelay setting.
3425 static int dgap_tty_digigetedelay(struct tty_struct *tty, int __user *retinfo)
3427 struct channel_t *ch;
3435 if (!tty || tty->magic != TTY_MAGIC)
3438 un = tty->driver_data;
3439 if (!un || un->magic != DGAP_UNIT_MAGIC)
3443 if (!ch || ch->magic != DGAP_CHANNEL_MAGIC)
3446 memset(&tmp, 0, sizeof(tmp));
3448 DGAP_LOCK(ch->ch_lock, lock_flags);
3449 tmp = readw(&(ch->ch_bs->edelay));
3450 DGAP_UNLOCK(ch->ch_lock, lock_flags);
3452 if (copy_to_user(retinfo, &tmp, sizeof(*retinfo)))
3459 * dgap_tty_digisetedelay()
3461 * Ioctl to set the EDELAY setting
3464 static int dgap_tty_digisetedelay(struct tty_struct *tty, int __user *new_info)
3467 struct channel_t *ch;
3473 if (!tty || tty->magic != TTY_MAGIC)
3476 un = tty->driver_data;
3477 if (!un || un->magic != DGAP_UNIT_MAGIC)
3481 if (!ch || ch->magic != DGAP_CHANNEL_MAGIC)
3485 if (!bd || bd->magic != DGAP_BOARD_MAGIC)
3488 if (copy_from_user(&new_digi, new_info, sizeof(int)))
3491 DGAP_LOCK(bd->bd_lock, lock_flags);
3492 DGAP_LOCK(ch->ch_lock, lock_flags2);
3494 writew((u16) new_digi, &(ch->ch_bs->edelay));
3498 DGAP_UNLOCK(ch->ch_lock, lock_flags2);
3499 DGAP_UNLOCK(bd->bd_lock, lock_flags);
3505 * dgap_tty_digigetcustombaud()
3507 * Ioctl to get the current custom baud rate setting.
3509 static int dgap_tty_digigetcustombaud(struct tty_struct *tty,
3510 int __user *retinfo)
3512 struct channel_t *ch;
3520 if (!tty || tty->magic != TTY_MAGIC)
3523 un = tty->driver_data;
3524 if (!un || un->magic != DGAP_UNIT_MAGIC)
3528 if (!ch || ch->magic != DGAP_CHANNEL_MAGIC)
3531 memset(&tmp, 0, sizeof(tmp));
3533 DGAP_LOCK(ch->ch_lock, lock_flags);
3534 tmp = dgap_get_custom_baud(ch);
3535 DGAP_UNLOCK(ch->ch_lock, lock_flags);
3537 if (copy_to_user(retinfo, &tmp, sizeof(*retinfo)))
3544 * dgap_tty_digisetcustombaud()
3546 * Ioctl to set the custom baud rate setting
3548 static int dgap_tty_digisetcustombaud(struct tty_struct *tty,
3549 int __user *new_info)
3552 struct channel_t *ch;
3558 if (!tty || tty->magic != TTY_MAGIC)
3561 un = tty->driver_data;
3562 if (!un || un->magic != DGAP_UNIT_MAGIC)
3566 if (!ch || ch->magic != DGAP_CHANNEL_MAGIC)
3570 if (!bd || bd->magic != DGAP_BOARD_MAGIC)
3574 if (copy_from_user(&new_rate, new_info, sizeof(unsigned int)))
3577 if (bd->bd_flags & BD_FEP5PLUS) {
3579 DGAP_LOCK(bd->bd_lock, lock_flags);
3580 DGAP_LOCK(ch->ch_lock, lock_flags2);
3582 ch->ch_custom_speed = new_rate;
3586 DGAP_UNLOCK(ch->ch_lock, lock_flags2);
3587 DGAP_UNLOCK(bd->bd_lock, lock_flags);
3594 * dgap_set_termios()
3596 static void dgap_tty_set_termios(struct tty_struct *tty,
3597 struct ktermios *old_termios)
3600 struct channel_t *ch;
3602 unsigned long lock_flags;
3603 unsigned long lock_flags2;
3605 if (!tty || tty->magic != TTY_MAGIC)
3608 un = tty->driver_data;
3609 if (!un || un->magic != DGAP_UNIT_MAGIC)
3613 if (!ch || ch->magic != DGAP_CHANNEL_MAGIC)
3617 if (!bd || bd->magic != DGAP_BOARD_MAGIC)
3620 DGAP_LOCK(bd->bd_lock, lock_flags);
3621 DGAP_LOCK(ch->ch_lock, lock_flags2);
3623 ch->ch_c_cflag = tty->termios.c_cflag;
3624 ch->ch_c_iflag = tty->termios.c_iflag;
3625 ch->ch_c_oflag = tty->termios.c_oflag;
3626 ch->ch_c_lflag = tty->termios.c_lflag;
3627 ch->ch_startc = tty->termios.c_cc[VSTART];
3628 ch->ch_stopc = tty->termios.c_cc[VSTOP];
3633 DGAP_UNLOCK(ch->ch_lock, lock_flags2);
3634 DGAP_UNLOCK(bd->bd_lock, lock_flags);
3637 static void dgap_tty_throttle(struct tty_struct *tty)
3640 struct channel_t *ch;
3645 if (!tty || tty->magic != TTY_MAGIC)
3648 un = tty->driver_data;
3649 if (!un || un->magic != DGAP_UNIT_MAGIC)
3653 if (!ch || ch->magic != DGAP_CHANNEL_MAGIC)
3657 if (!bd || bd->magic != DGAP_BOARD_MAGIC)
3660 DGAP_LOCK(bd->bd_lock, lock_flags);
3661 DGAP_LOCK(ch->ch_lock, lock_flags2);
3663 ch->ch_flags |= (CH_RXBLOCK);
3665 dgap_cmdw(ch, RPAUSE, 0, 0);
3668 DGAP_UNLOCK(ch->ch_lock, lock_flags2);
3669 DGAP_UNLOCK(bd->bd_lock, lock_flags);
3673 static void dgap_tty_unthrottle(struct tty_struct *tty)
3676 struct channel_t *ch;
3681 if (!tty || tty->magic != TTY_MAGIC)
3684 un = tty->driver_data;
3685 if (!un || un->magic != DGAP_UNIT_MAGIC)
3689 if (!ch || ch->magic != DGAP_CHANNEL_MAGIC)
3693 if (!bd || bd->magic != DGAP_BOARD_MAGIC)
3696 DGAP_LOCK(bd->bd_lock, lock_flags);
3697 DGAP_LOCK(ch->ch_lock, lock_flags2);
3699 ch->ch_flags &= ~(CH_RXBLOCK);
3702 dgap_cmdw(ch, RRESUME, 0, 0);
3705 DGAP_UNLOCK(ch->ch_lock, lock_flags2);
3706 DGAP_UNLOCK(bd->bd_lock, lock_flags);
3709 static void dgap_tty_start(struct tty_struct *tty)
3712 struct channel_t *ch;
3717 if (!tty || tty->magic != TTY_MAGIC)
3720 un = tty->driver_data;
3721 if (!un || un->magic != DGAP_UNIT_MAGIC)
3725 if (!ch || ch->magic != DGAP_CHANNEL_MAGIC)
3729 if (!bd || bd->magic != DGAP_BOARD_MAGIC)
3732 DGAP_LOCK(bd->bd_lock, lock_flags);
3733 DGAP_LOCK(ch->ch_lock, lock_flags2);
3735 dgap_cmdw(ch, RESUMETX, 0, 0);
3737 DGAP_UNLOCK(ch->ch_lock, lock_flags2);
3738 DGAP_UNLOCK(bd->bd_lock, lock_flags);
3742 static void dgap_tty_stop(struct tty_struct *tty)
3745 struct channel_t *ch;
3750 if (!tty || tty->magic != TTY_MAGIC)
3753 un = tty->driver_data;
3754 if (!un || un->magic != DGAP_UNIT_MAGIC)
3758 if (!ch || ch->magic != DGAP_CHANNEL_MAGIC)
3762 if (!bd || bd->magic != DGAP_BOARD_MAGIC)
3765 DGAP_LOCK(bd->bd_lock, lock_flags);
3766 DGAP_LOCK(ch->ch_lock, lock_flags2);
3768 dgap_cmdw(ch, PAUSETX, 0, 0);
3770 DGAP_UNLOCK(ch->ch_lock, lock_flags2);
3771 DGAP_UNLOCK(bd->bd_lock, lock_flags);
3776 * dgap_tty_flush_chars()
3778 * Flush the cook buffer
3780 * Note to self, and any other poor souls who venture here:
3782 * flush in this case DOES NOT mean dispose of the data.
3783 * instead, it means "stop buffering and send it if you
3784 * haven't already." Just guess how I figured that out... SRW 2-Jun-98
3786 * It is also always called in interrupt context - JAR 8-Sept-99
3788 static void dgap_tty_flush_chars(struct tty_struct *tty)
3791 struct channel_t *ch;
3796 if (!tty || tty->magic != TTY_MAGIC)
3799 un = tty->driver_data;
3800 if (!un || un->magic != DGAP_UNIT_MAGIC)
3804 if (!ch || ch->magic != DGAP_CHANNEL_MAGIC)
3808 if (!bd || bd->magic != DGAP_BOARD_MAGIC)
3811 DGAP_LOCK(bd->bd_lock, lock_flags);
3812 DGAP_LOCK(ch->ch_lock, lock_flags2);
3814 /* TODO: Do something here */
3816 DGAP_UNLOCK(ch->ch_lock, lock_flags2);
3817 DGAP_UNLOCK(bd->bd_lock, lock_flags);
3821 * dgap_tty_flush_buffer()
3823 * Flush Tx buffer (make in == out)
3825 static void dgap_tty_flush_buffer(struct tty_struct *tty)
3828 struct channel_t *ch;
3834 if (!tty || tty->magic != TTY_MAGIC)
3837 un = tty->driver_data;
3838 if (!un || un->magic != DGAP_UNIT_MAGIC)
3842 if (!ch || ch->magic != DGAP_CHANNEL_MAGIC)
3846 if (!bd || bd->magic != DGAP_BOARD_MAGIC)
3849 DGAP_LOCK(bd->bd_lock, lock_flags);
3850 DGAP_LOCK(ch->ch_lock, lock_flags2);
3852 ch->ch_flags &= ~CH_STOP;
3853 head = readw(&(ch->ch_bs->tx_head));
3854 dgap_cmdw(ch, FLUSHTX, (u16) head, 0);
3855 dgap_cmdw(ch, RESUMETX, 0, 0);
3856 if (ch->ch_tun.un_flags & (UN_LOW|UN_EMPTY)) {
3857 ch->ch_tun.un_flags &= ~(UN_LOW|UN_EMPTY);
3858 wake_up_interruptible(&ch->ch_tun.un_flags_wait);
3860 if (ch->ch_pun.un_flags & (UN_LOW|UN_EMPTY)) {
3861 ch->ch_pun.un_flags &= ~(UN_LOW|UN_EMPTY);
3862 wake_up_interruptible(&ch->ch_pun.un_flags_wait);
3865 DGAP_UNLOCK(ch->ch_lock, lock_flags2);
3866 DGAP_UNLOCK(bd->bd_lock, lock_flags);
3867 if (waitqueue_active(&tty->write_wait))
3868 wake_up_interruptible(&tty->write_wait);
3872 /*****************************************************************************
3874 * The IOCTL function and all of its helpers
3876 *****************************************************************************/
3881 * The usual assortment of ioctl's
3883 static int dgap_tty_ioctl(struct tty_struct *tty, unsigned int cmd,
3887 struct channel_t *ch;
3891 ulong lock_flags = 0;
3892 ulong lock_flags2 = 0;
3893 void __user *uarg = (void __user *) arg;
3895 if (!tty || tty->magic != TTY_MAGIC)
3898 un = tty->driver_data;
3899 if (!un || un->magic != DGAP_UNIT_MAGIC)
3903 if (!ch || ch->magic != DGAP_CHANNEL_MAGIC)
3907 if (!bd || bd->magic != DGAP_BOARD_MAGIC)
3910 DGAP_LOCK(bd->bd_lock, lock_flags);
3911 DGAP_LOCK(ch->ch_lock, lock_flags2);
3913 if (un->un_open_count <= 0) {
3914 DGAP_UNLOCK(ch->ch_lock, lock_flags2);
3915 DGAP_UNLOCK(bd->bd_lock, lock_flags);
3921 /* Here are all the standard ioctl's that we MUST implement */
3925 * TCSBRK is SVID version: non-zero arg --> no break
3926 * this behaviour is exploited by tcdrain().
3928 * According to POSIX.1 spec (7.2.2.1.2) breaks should be
3929 * between 0.25 and 0.5 seconds so we'll ask for something
3930 * in the middle: 0.375 seconds.
3932 rc = tty_check_change(tty);
3933 DGAP_UNLOCK(ch->ch_lock, lock_flags2);
3934 DGAP_UNLOCK(bd->bd_lock, lock_flags);
3938 rc = dgap_wait_for_drain(tty);
3943 DGAP_LOCK(bd->bd_lock, lock_flags);
3944 DGAP_LOCK(ch->ch_lock, lock_flags2);
3946 if (((cmd == TCSBRK) && (!arg)) || (cmd == TCSBRKP))
3947 dgap_cmdw(ch, SBREAK, (u16) SBREAK_TIME, 0);
3949 DGAP_UNLOCK(ch->ch_lock, lock_flags2);
3950 DGAP_UNLOCK(bd->bd_lock, lock_flags);
3955 /* support for POSIX tcsendbreak()
3957 * According to POSIX.1 spec (7.2.2.1.2) breaks should be
3958 * between 0.25 and 0.5 seconds so we'll ask for something
3959 * in the middle: 0.375 seconds.
3961 rc = tty_check_change(tty);
3962 DGAP_UNLOCK(ch->ch_lock, lock_flags2);
3963 DGAP_UNLOCK(bd->bd_lock, lock_flags);
3967 rc = dgap_wait_for_drain(tty);
3971 DGAP_LOCK(bd->bd_lock, lock_flags);
3972 DGAP_LOCK(ch->ch_lock, lock_flags2);
3974 dgap_cmdw(ch, SBREAK, (u16) SBREAK_TIME, 0);
3976 DGAP_UNLOCK(ch->ch_lock, lock_flags2);
3977 DGAP_UNLOCK(bd->bd_lock, lock_flags);
3983 * FEP5 doesn't support turning on a break unconditionally.
3984 * The FEP5 device will stop sending a break automatically
3985 * after the specified time value that was sent when turning on
3988 rc = tty_check_change(tty);
3989 DGAP_UNLOCK(ch->ch_lock, lock_flags2);
3990 DGAP_UNLOCK(bd->bd_lock, lock_flags);
3994 rc = dgap_wait_for_drain(tty);
3998 DGAP_LOCK(bd->bd_lock, lock_flags);
3999 DGAP_LOCK(ch->ch_lock, lock_flags2);
4001 dgap_cmdw(ch, SBREAK, (u16) SBREAK_TIME, 0);
4003 DGAP_UNLOCK(ch->ch_lock, lock_flags2);
4004 DGAP_UNLOCK(bd->bd_lock, lock_flags);
4010 * FEP5 doesn't support turning off a break unconditionally.
4011 * The FEP5 device will stop sending a break automatically
4012 * after the specified time value that was sent when turning on
4015 DGAP_UNLOCK(ch->ch_lock, lock_flags2);
4016 DGAP_UNLOCK(bd->bd_lock, lock_flags);
4021 DGAP_UNLOCK(ch->ch_lock, lock_flags2);
4022 DGAP_UNLOCK(bd->bd_lock, lock_flags);
4024 rc = put_user(C_CLOCAL(tty) ? 1 : 0,
4025 (unsigned long __user *) arg);
4029 DGAP_UNLOCK(ch->ch_lock, lock_flags2);
4030 DGAP_UNLOCK(bd->bd_lock, lock_flags);
4032 rc = get_user(arg, (unsigned long __user *) arg);
4036 DGAP_LOCK(bd->bd_lock, lock_flags);
4037 DGAP_LOCK(ch->ch_lock, lock_flags2);
4038 tty->termios.c_cflag = ((tty->termios.c_cflag & ~CLOCAL) |
4039 (arg ? CLOCAL : 0));
4041 DGAP_UNLOCK(ch->ch_lock, lock_flags2);
4042 DGAP_UNLOCK(bd->bd_lock, lock_flags);
4047 DGAP_UNLOCK(ch->ch_lock, lock_flags2);
4048 DGAP_UNLOCK(bd->bd_lock, lock_flags);
4049 return dgap_get_modem_info(ch, uarg);
4054 DGAP_UNLOCK(ch->ch_lock, lock_flags2);
4055 DGAP_UNLOCK(bd->bd_lock, lock_flags);
4056 return dgap_set_modem_info(tty, cmd, uarg);
4059 * Here are any additional ioctl's that we want to implement
4064 * The linux tty driver doesn't have a flush
4065 * input routine for the driver, assuming all backed
4066 * up data is in the line disc. buffers. However,
4067 * we all know that's not the case. Here, we
4068 * act on the ioctl, but then lie and say we didn't
4069 * so the line discipline will process the flush
4072 rc = tty_check_change(tty);
4074 DGAP_UNLOCK(ch->ch_lock, lock_flags2);
4075 DGAP_UNLOCK(bd->bd_lock, lock_flags);
4079 if ((arg == TCIFLUSH) || (arg == TCIOFLUSH)) {
4080 if (!(un->un_type == DGAP_PRINT)) {
4081 head = readw(&(ch->ch_bs->rx_head));
4082 writew(head, &(ch->ch_bs->rx_tail));
4083 writeb(0, &(ch->ch_bs->orun));
4087 if ((arg != TCOFLUSH) && (arg != TCIOFLUSH)) {
4088 /* pretend we didn't recognize this IOCTL */
4089 DGAP_UNLOCK(ch->ch_lock, lock_flags2);
4090 DGAP_UNLOCK(bd->bd_lock, lock_flags);
4092 return -ENOIOCTLCMD;
4095 ch->ch_flags &= ~CH_STOP;
4096 head = readw(&(ch->ch_bs->tx_head));
4097 dgap_cmdw(ch, FLUSHTX, (u16) head, 0);
4098 dgap_cmdw(ch, RESUMETX, 0, 0);
4099 if (ch->ch_tun.un_flags & (UN_LOW|UN_EMPTY)) {
4100 ch->ch_tun.un_flags &= ~(UN_LOW|UN_EMPTY);
4101 wake_up_interruptible(&ch->ch_tun.un_flags_wait);
4103 if (ch->ch_pun.un_flags & (UN_LOW|UN_EMPTY)) {
4104 ch->ch_pun.un_flags &= ~(UN_LOW|UN_EMPTY);
4105 wake_up_interruptible(&ch->ch_pun.un_flags_wait);
4107 if (waitqueue_active(&tty->write_wait))
4108 wake_up_interruptible(&tty->write_wait);
4110 /* Can't hold any locks when calling tty_wakeup! */
4111 DGAP_UNLOCK(ch->ch_lock, lock_flags2);
4112 DGAP_UNLOCK(bd->bd_lock, lock_flags);
4115 /* pretend we didn't recognize this IOCTL */
4116 return -ENOIOCTLCMD;
4121 * The linux tty driver doesn't have a flush
4122 * input routine for the driver, assuming all backed
4123 * up data is in the line disc. buffers. However,
4124 * we all know that's not the case. Here, we
4125 * act on the ioctl, but then lie and say we didn't
4126 * so the line discipline will process the flush
4129 if (cmd == TCSETSF) {
4131 ch->ch_flags &= ~CH_STOP;
4132 head = readw(&(ch->ch_bs->rx_head));
4133 writew(head, &(ch->ch_bs->rx_tail));
4136 /* now wait for all the output to drain */
4137 DGAP_UNLOCK(ch->ch_lock, lock_flags2);
4138 DGAP_UNLOCK(bd->bd_lock, lock_flags);
4139 rc = dgap_wait_for_drain(tty);
4143 /* pretend we didn't recognize this */
4144 return -ENOIOCTLCMD;
4148 DGAP_UNLOCK(ch->ch_lock, lock_flags2);
4149 DGAP_UNLOCK(bd->bd_lock, lock_flags);
4150 rc = dgap_wait_for_drain(tty);
4154 /* pretend we didn't recognize this */
4155 return -ENOIOCTLCMD;
4159 * The Linux Line Discipline (LD) would do this for us if we
4160 * let it, but we have the special firmware options to do this
4161 * the "right way" regardless of hardware or software flow
4162 * control so we'll do it outselves instead of letting the LD
4165 rc = tty_check_change(tty);
4167 DGAP_UNLOCK(ch->ch_lock, lock_flags2);
4168 DGAP_UNLOCK(bd->bd_lock, lock_flags);
4175 DGAP_UNLOCK(ch->ch_lock, lock_flags2);
4176 DGAP_UNLOCK(bd->bd_lock, lock_flags);
4177 dgap_tty_start(tty);
4180 DGAP_UNLOCK(ch->ch_lock, lock_flags2);
4181 DGAP_UNLOCK(bd->bd_lock, lock_flags);
4185 DGAP_UNLOCK(ch->ch_lock, lock_flags2);
4186 DGAP_UNLOCK(bd->bd_lock, lock_flags);
4187 /* Make the ld do it */
4188 return -ENOIOCTLCMD;
4190 DGAP_UNLOCK(ch->ch_lock, lock_flags2);
4191 DGAP_UNLOCK(bd->bd_lock, lock_flags);
4192 /* Make the ld do it */
4193 return -ENOIOCTLCMD;
4195 DGAP_UNLOCK(ch->ch_lock, lock_flags2);
4196 DGAP_UNLOCK(bd->bd_lock, lock_flags);
4201 /* get information for ditty */
4202 DGAP_UNLOCK(ch->ch_lock, lock_flags2);
4203 DGAP_UNLOCK(bd->bd_lock, lock_flags);
4204 return dgap_tty_digigeta(tty, uarg);
4209 /* set information for ditty */
4210 if (cmd == (DIGI_SETAW)) {
4212 DGAP_UNLOCK(ch->ch_lock, lock_flags2);
4213 DGAP_UNLOCK(bd->bd_lock, lock_flags);
4214 rc = dgap_wait_for_drain(tty);
4217 DGAP_LOCK(bd->bd_lock, lock_flags);
4218 DGAP_LOCK(ch->ch_lock, lock_flags2);
4220 tty_ldisc_flush(tty);
4224 DGAP_UNLOCK(ch->ch_lock, lock_flags2);
4225 DGAP_UNLOCK(bd->bd_lock, lock_flags);
4226 return dgap_tty_digiseta(tty, uarg);
4229 DGAP_UNLOCK(ch->ch_lock, lock_flags2);
4230 DGAP_UNLOCK(bd->bd_lock, lock_flags);
4231 return dgap_tty_digigetedelay(tty, uarg);
4234 DGAP_UNLOCK(ch->ch_lock, lock_flags2);
4235 DGAP_UNLOCK(bd->bd_lock, lock_flags);
4236 return dgap_tty_digisetedelay(tty, uarg);
4238 case DIGI_GETCUSTOMBAUD:
4239 DGAP_UNLOCK(ch->ch_lock, lock_flags2);
4240 DGAP_UNLOCK(bd->bd_lock, lock_flags);
4241 return dgap_tty_digigetcustombaud(tty, uarg);
4243 case DIGI_SETCUSTOMBAUD:
4244 DGAP_UNLOCK(ch->ch_lock, lock_flags2);
4245 DGAP_UNLOCK(bd->bd_lock, lock_flags);
4246 return dgap_tty_digisetcustombaud(tty, uarg);
4248 case DIGI_RESET_PORT:
4249 dgap_firmware_reset_port(ch);
4251 DGAP_UNLOCK(ch->ch_lock, lock_flags2);
4252 DGAP_UNLOCK(bd->bd_lock, lock_flags);
4256 DGAP_UNLOCK(ch->ch_lock, lock_flags2);
4257 DGAP_UNLOCK(bd->bd_lock, lock_flags);
4259 return -ENOIOCTLCMD;
4263 static int dgap_after_config_loaded(int board)
4266 * Initialize KME waitqueues...
4268 init_waitqueue_head(&(dgap_Board[board]->kme_wait));
4271 * allocate flip buffer for board.
4273 dgap_Board[board]->flipbuf = kmalloc(MYFLIPLEN, GFP_ATOMIC);
4274 if (!dgap_Board[board]->flipbuf)
4277 dgap_Board[board]->flipflagbuf = kmalloc(MYFLIPLEN, GFP_ATOMIC);
4278 if (!dgap_Board[board]->flipflagbuf) {
4279 kfree(dgap_Board[board]->flipbuf);
4287 * Create pr and tty device entries
4289 static int dgap_tty_register_ports(struct board_t *brd)
4291 struct channel_t *ch;
4294 brd->SerialPorts = kcalloc(brd->nasync, sizeof(*brd->SerialPorts),
4296 if (brd->SerialPorts == NULL)
4298 for (i = 0; i < brd->nasync; i++)
4299 tty_port_init(&brd->SerialPorts[i]);
4301 brd->PrinterPorts = kcalloc(brd->nasync, sizeof(*brd->PrinterPorts),
4303 if (brd->PrinterPorts == NULL) {
4304 kfree(brd->SerialPorts);
4307 for (i = 0; i < brd->nasync; i++)
4308 tty_port_init(&brd->PrinterPorts[i]);
4310 ch = brd->channels[0];
4311 for (i = 0; i < brd->nasync; i++, ch = brd->channels[i]) {
4313 struct device *classp;
4315 classp = tty_port_register_device(&brd->SerialPorts[i],
4317 brd->firstminor + i, NULL);
4319 dgap_create_tty_sysfs(&ch->ch_tun, classp);
4320 ch->ch_tun.un_sysfs = classp;
4322 classp = tty_port_register_device(&brd->PrinterPorts[i],
4324 brd->firstminor + i, NULL);
4326 dgap_create_tty_sysfs(&ch->ch_pun, classp);
4327 ch->ch_pun.un_sysfs = classp;
4329 dgap_create_ports_sysfiles(brd);
4335 * Copies the BIOS code from the user to the board,
4336 * and starts the BIOS running.
4338 static void dgap_do_bios_load(struct board_t *brd, uchar __user *ubios, int len)
4344 if (!brd || (brd->magic != DGAP_BOARD_MAGIC) || !brd->re_map_membase)
4347 addr = brd->re_map_membase;
4352 for (i = 0; i < 16; i++)
4353 writeb(0, addr + POSTAREA + i);
4359 memcpy_toio(addr + offset, ubios, len);
4361 writel(0x0bf00401, addr);
4362 writel(0, (addr + 4));
4364 /* Clear the reset, and change states. */
4365 writeb(FEPCLR, brd->re_map_port);
4369 * Checks to see if the BIOS completed running on the card.
4371 static int dgap_do_wait_for_bios(struct board_t *brd)
4379 if (!brd || (brd->magic != DGAP_BOARD_MAGIC) || !brd->re_map_membase)
4382 addr = brd->re_map_membase;
4383 word = readw(addr + POSTAREA);
4386 * It can take 5-6 seconds for a board to
4387 * pass the bios self test and post results.
4388 * Give it 10 seconds.
4390 brd->wait_for_bios = 0;
4391 while (brd->wait_for_bios < 1000) {
4392 /* Check to see if BIOS thinks board is good. (GD). */
4393 if (word == *(u16 *) "GD")
4395 msleep_interruptible(10);
4396 brd->wait_for_bios++;
4397 word = readw(addr + POSTAREA);
4400 /* Gave up on board after too long of time taken */
4401 err1 = readw(addr + SEQUENCE);
4402 err2 = readw(addr + ERROR);
4403 pr_warn("dgap: %s failed diagnostics. Error #(%x,%x).\n",
4404 brd->name, err1, err2);
4405 brd->state = BOARD_FAILED;
4406 brd->dpastatus = BD_NOBIOS;
4412 * Copies the FEP code from the user to the board,
4413 * and starts the FEP running.
4415 static void dgap_do_fep_load(struct board_t *brd, uchar __user *ufep, int len)
4420 if (!brd || (brd->magic != DGAP_BOARD_MAGIC) || !brd->re_map_membase)
4423 addr = brd->re_map_membase;
4429 memcpy_toio(addr + offset, ufep, len);
4432 * If board is a concentrator product, we need to give
4433 * it its config string describing how the concentrators look.
4435 if ((brd->type == PCX) || (brd->type == PEPC)) {
4437 uchar *config, *xconfig;
4440 xconfig = dgap_create_config_string(brd, string);
4442 /* Write string to board memory */
4443 config = addr + CONFIG;
4444 for (; i < CONFIGSIZE; i++, config++, xconfig++) {
4445 writeb(*xconfig, config);
4446 if ((*xconfig & 0xff) == 0xff)
4451 writel(0xbfc01004, (addr + 0xc34));
4452 writel(0x3, (addr + 0xc30));
4457 * Waits for the FEP to report thats its ready for us to use.
4459 static int dgap_do_wait_for_fep(struct board_t *brd)
4467 if (!brd || (brd->magic != DGAP_BOARD_MAGIC) || !brd->re_map_membase)
4470 addr = brd->re_map_membase;
4471 word = readw(addr + FEPSTAT);
4474 * It can take 2-3 seconds for the FEP to
4475 * be up and running. Give it 5 secs.
4477 brd->wait_for_fep = 0;
4478 while (brd->wait_for_fep < 500) {
4479 /* Check to see if FEP is up and running now. */
4480 if (word == *(u16 *) "OS") {
4482 * Check to see if the board can support FEP5+ commands.
4484 word = readw(addr + FEP5_PLUS);
4485 if (word == *(u16 *) "5A")
4486 brd->bd_flags |= BD_FEP5PLUS;
4490 msleep_interruptible(10);
4491 brd->wait_for_fep++;
4492 word = readw(addr + FEPSTAT);
4495 /* Gave up on board after too long of time taken */
4496 err1 = readw(addr + SEQUENCE);
4497 err2 = readw(addr + ERROR);
4498 pr_warn("dgap: FEPOS for %s not functioning. Error #(%x,%x).\n",
4499 brd->name, err1, err2);
4500 brd->state = BOARD_FAILED;
4501 brd->dpastatus = BD_NOFEP;
4507 * Physically forces the FEP5 card to reset itself.
4509 static void dgap_do_reset_board(struct board_t *brd)
4516 if (!brd || (brd->magic != DGAP_BOARD_MAGIC) ||
4517 !brd->re_map_membase || !brd->re_map_port)
4520 /* FEPRST does not vary among supported boards */
4521 writeb(FEPRST, brd->re_map_port);
4523 for (i = 0; i <= 1000; i++) {
4524 check = readb(brd->re_map_port) & 0xe;
4525 if (check == FEPRST)
4531 pr_warn("dgap: Board not resetting... Failing board.\n");
4532 brd->state = BOARD_FAILED;
4533 brd->dpastatus = BD_NOFEP;
4538 * Make sure there really is memory out there.
4540 writel(0xa55a3cc3, (brd->re_map_membase + LOWMEM));
4541 writel(0x5aa5c33c, (brd->re_map_membase + HIGHMEM));
4542 check1 = readl(brd->re_map_membase + LOWMEM);
4543 check2 = readl(brd->re_map_membase + HIGHMEM);
4545 if ((check1 != 0xa55a3cc3) || (check2 != 0x5aa5c33c)) {
4546 pr_warn("dgap: No memory at %p for board.\n",
4547 brd->re_map_membase);
4548 brd->state = BOARD_FAILED;
4549 brd->dpastatus = BD_NOFEP;
4555 #ifdef DIGI_CONCENTRATORS_SUPPORTED
4557 * Sends a concentrator image into the FEP5 board.
4559 static void dgap_do_conc_load(struct board_t *brd, uchar *uaddr, int len)
4563 struct downld_t *to_dp;
4565 if (!brd || (brd->magic != DGAP_BOARD_MAGIC) || !brd->re_map_membase)
4568 vaddr = brd->re_map_membase;
4570 offset = readw((u16 *) (vaddr + DOWNREQ));
4571 to_dp = (struct downld_t *) (vaddr + (int) offset);
4572 memcpy_toio(to_dp, uaddr, len);
4574 /* Tell card we have data for it */
4575 writew(0, vaddr + (DOWNREQ));
4577 brd->conc_dl_status = NO_PENDING_CONCENTRATOR_REQUESTS;
4581 #define EXPANSION_ROM_SIZE (64 * 1024)
4582 #define FEP5_ROM_MAGIC (0xFEFFFFFF)
4584 static void dgap_get_vpd(struct board_t *brd)
4596 * Poke the magic number at the PCI Rom Address location.
4597 * If VPD is supported, the value read from that address
4600 magic = FEP5_ROM_MAGIC;
4601 pci_write_config_dword(brd->pdev, PCI_ROM_ADDRESS, magic);
4602 pci_read_config_dword(brd->pdev, PCI_ROM_ADDRESS, &magic);
4604 /* VPD not supported, bail */
4609 * To get to the OTPROM memory, we have to send the boards base
4610 * address or'ed with 1 into the PCI Rom Address location.
4612 magic = brd->membase | 0x01;
4613 pci_write_config_dword(brd->pdev, PCI_ROM_ADDRESS, magic);
4614 pci_read_config_dword(brd->pdev, PCI_ROM_ADDRESS, &magic);
4616 byte1 = readb(brd->re_map_membase);
4617 byte2 = readb(brd->re_map_membase + 1);
4620 * If the board correctly swapped to the OTPROM memory,
4621 * the first 2 bytes (header) should be 0x55, 0xAA
4623 if (byte1 == 0x55 && byte2 == 0xAA) {
4628 * We have to run through all the OTPROM memory looking
4629 * for the VPD offset.
4631 while (base_offset <= EXPANSION_ROM_SIZE) {
4634 * Lots of magic numbers here.
4636 * The VPD offset is located inside the ROM Data
4639 * We also have to remember the length of each
4640 * ROM Data Structure, so we can "hop" to the next
4641 * entry if the VPD isn't in the current
4642 * ROM Data Structure.
4644 rom_offset = readw(brd->re_map_membase +
4645 base_offset + 0x18);
4646 image_length = readw(brd->re_map_membase +
4647 rom_offset + 0x10) * 512;
4648 vpd_offset = readw(brd->re_map_membase +
4651 /* Found the VPD entry */
4655 /* We didn't find a VPD entry, go to next ROM entry. */
4656 base_offset += image_length;
4658 byte1 = readb(brd->re_map_membase + base_offset);
4659 byte2 = readb(brd->re_map_membase + base_offset + 1);
4662 * If the new ROM offset doesn't have 0x55, 0xAA
4663 * as its header, we have run out of ROM.
4665 if (byte1 != 0x55 || byte2 != 0xAA)
4670 * If we have a VPD offset, then mark the board
4671 * as having a valid VPD, and copy VPDSIZE (512) bytes of
4672 * that VPD to the buffer we have in our board structure.
4675 brd->bd_flags |= BD_HAS_VPD;
4676 for (i = 0; i < VPDSIZE; i++) {
4677 brd->vpd[i] = readb(brd->re_map_membase +
4684 * We MUST poke the magic number at the PCI Rom Address location again.
4685 * This makes the card report the regular board memory back to us,
4686 * rather than the OTPROM memory.
4688 magic = FEP5_ROM_MAGIC;
4689 pci_write_config_dword(brd->pdev, PCI_ROM_ADDRESS, magic);
4693 * Our board poller function.
4695 static void dgap_poll_tasklet(unsigned long data)
4697 struct board_t *bd = (struct board_t *) data;
4702 if (!bd || (bd->magic != DGAP_BOARD_MAGIC))
4705 if (bd->inhibit_poller)
4708 DGAP_LOCK(bd->bd_lock, lock_flags);
4710 vaddr = bd->re_map_membase;
4713 * If board is ready, parse deeper to see if there is anything to do.
4715 if (bd->state == BOARD_READY) {
4717 struct ev_t *eaddr = NULL;
4719 if (!bd->re_map_membase) {
4720 DGAP_UNLOCK(bd->bd_lock, lock_flags);
4723 if (!bd->re_map_port) {
4724 DGAP_UNLOCK(bd->bd_lock, lock_flags);
4731 eaddr = (struct ev_t *) (vaddr + EVBUF);
4733 /* Get our head and tail */
4734 head = readw(&(eaddr->ev_head));
4735 tail = readw(&(eaddr->ev_tail));
4738 * If there is an event pending. Go service it.
4741 DGAP_UNLOCK(bd->bd_lock, lock_flags);
4743 DGAP_LOCK(bd->bd_lock, lock_flags);
4748 * If board is doing interrupts, ACK the interrupt.
4750 if (bd && bd->intr_running)
4751 readb(bd->re_map_port + 2);
4753 DGAP_UNLOCK(bd->bd_lock, lock_flags);
4757 DGAP_UNLOCK(bd->bd_lock, lock_flags);
4760 /*=======================================================================
4762 * dgap_cmdb - Sends a 2 byte command to the FEP.
4764 * ch - Pointer to channel structure.
4765 * cmd - Command to be sent.
4766 * byte1 - Integer containing first byte to be sent.
4767 * byte2 - Integer containing second byte to be sent.
4768 * ncmds - Wait until ncmds or fewer cmds are left
4769 * in the cmd buffer before returning.
4771 *=======================================================================*/
4772 static void dgap_cmdb(struct channel_t *ch, uchar cmd, uchar byte1,
4773 uchar byte2, uint ncmds)
4776 struct cm_t *cm_addr = NULL;
4782 if (!ch || ch->magic != DGAP_CHANNEL_MAGIC)
4786 * Check if board is still alive.
4788 if (ch->ch_bd->state == BOARD_FAILED)
4792 * Make sure the pointers are in range before
4793 * writing to the FEP memory.
4795 vaddr = ch->ch_bd->re_map_membase;
4800 cm_addr = (struct cm_t *) (vaddr + CMDBUF);
4801 head = readw(&(cm_addr->cm_head));
4804 * Forget it if pointers out of range.
4806 if (head >= (CMDMAX - CMDSTART) || (head & 03)) {
4807 ch->ch_bd->state = BOARD_FAILED;
4812 * Put the data in the circular command buffer.
4814 writeb(cmd, (char *) (vaddr + head + CMDSTART + 0));
4815 writeb((uchar) ch->ch_portnum, (char *) (vaddr + head + CMDSTART + 1));
4816 writeb(byte1, (char *) (vaddr + head + CMDSTART + 2));
4817 writeb(byte2, (char *) (vaddr + head + CMDSTART + 3));
4819 head = (head + 4) & (CMDMAX - CMDSTART - 4);
4821 writew(head, &(cm_addr->cm_head));
4824 * Wait if necessary before updating the head
4825 * pointer to limit the number of outstanding
4826 * commands to the FEP. If the time spent waiting
4827 * is outlandish, declare the FEP dead.
4829 for (count = dgap_count ;;) {
4831 head = readw(&(cm_addr->cm_head));
4832 tail = readw(&(cm_addr->cm_tail));
4834 n = (head - tail) & (CMDMAX - CMDSTART - 4);
4836 if (n <= ncmds * sizeof(struct cm_t))
4840 ch->ch_bd->state = BOARD_FAILED;
4847 /*=======================================================================
4849 * dgap_cmdw - Sends a 1 word command to the FEP.
4851 * ch - Pointer to channel structure.
4852 * cmd - Command to be sent.
4853 * word - Integer containing word to be sent.
4854 * ncmds - Wait until ncmds or fewer cmds are left
4855 * in the cmd buffer before returning.
4857 *=======================================================================*/
4858 static void dgap_cmdw(struct channel_t *ch, uchar cmd, u16 word, uint ncmds)
4861 struct cm_t *cm_addr = NULL;
4867 if (!ch || ch->magic != DGAP_CHANNEL_MAGIC)
4871 * Check if board is still alive.
4873 if (ch->ch_bd->state == BOARD_FAILED)
4877 * Make sure the pointers are in range before
4878 * writing to the FEP memory.
4880 vaddr = ch->ch_bd->re_map_membase;
4884 cm_addr = (struct cm_t *) (vaddr + CMDBUF);
4885 head = readw(&(cm_addr->cm_head));
4888 * Forget it if pointers out of range.
4890 if (head >= (CMDMAX - CMDSTART) || (head & 03)) {
4891 ch->ch_bd->state = BOARD_FAILED;
4896 * Put the data in the circular command buffer.
4898 writeb(cmd, (char *) (vaddr + head + CMDSTART + 0));
4899 writeb((uchar) ch->ch_portnum, (char *) (vaddr + head + CMDSTART + 1));
4900 writew((u16) word, (char *) (vaddr + head + CMDSTART + 2));
4902 head = (head + 4) & (CMDMAX - CMDSTART - 4);
4904 writew(head, &(cm_addr->cm_head));
4907 * Wait if necessary before updating the head
4908 * pointer to limit the number of outstanding
4909 * commands to the FEP. If the time spent waiting
4910 * is outlandish, declare the FEP dead.
4912 for (count = dgap_count ;;) {
4914 head = readw(&(cm_addr->cm_head));
4915 tail = readw(&(cm_addr->cm_tail));
4917 n = (head - tail) & (CMDMAX - CMDSTART - 4);
4919 if (n <= ncmds * sizeof(struct cm_t))
4923 ch->ch_bd->state = BOARD_FAILED;
4930 /*=======================================================================
4932 * dgap_cmdw_ext - Sends a extended word command to the FEP.
4934 * ch - Pointer to channel structure.
4935 * cmd - Command to be sent.
4936 * word - Integer containing word to be sent.
4937 * ncmds - Wait until ncmds or fewer cmds are left
4938 * in the cmd buffer before returning.
4940 *=======================================================================*/
4941 static void dgap_cmdw_ext(struct channel_t *ch, u16 cmd, u16 word, uint ncmds)
4944 struct cm_t *cm_addr = NULL;
4950 if (!ch || ch->magic != DGAP_CHANNEL_MAGIC)
4954 * Check if board is still alive.
4956 if (ch->ch_bd->state == BOARD_FAILED)
4960 * Make sure the pointers are in range before
4961 * writing to the FEP memory.
4963 vaddr = ch->ch_bd->re_map_membase;
4967 cm_addr = (struct cm_t *) (vaddr + CMDBUF);
4968 head = readw(&(cm_addr->cm_head));
4971 * Forget it if pointers out of range.
4973 if (head >= (CMDMAX - CMDSTART) || (head & 03)) {
4974 ch->ch_bd->state = BOARD_FAILED;
4979 * Put the data in the circular command buffer.
4982 /* Write an FF to tell the FEP that we want an extended command */
4983 writeb((uchar) 0xff, (char *) (vaddr + head + CMDSTART + 0));
4985 writeb((uchar) ch->ch_portnum, (uchar *) (vaddr + head + CMDSTART + 1));
4986 writew((u16) cmd, (char *) (vaddr + head + CMDSTART + 2));
4989 * If the second part of the command won't fit,
4990 * put it at the beginning of the circular buffer.
4992 if (((head + 4) >= ((CMDMAX - CMDSTART)) || (head & 03)))
4993 writew((u16) word, (char *) (vaddr + CMDSTART));
4995 writew((u16) word, (char *) (vaddr + head + CMDSTART + 4));
4997 head = (head + 8) & (CMDMAX - CMDSTART - 4);
4999 writew(head, &(cm_addr->cm_head));
5002 * Wait if necessary before updating the head
5003 * pointer to limit the number of outstanding
5004 * commands to the FEP. If the time spent waiting
5005 * is outlandish, declare the FEP dead.
5007 for (count = dgap_count ;;) {
5009 head = readw(&(cm_addr->cm_head));
5010 tail = readw(&(cm_addr->cm_tail));
5012 n = (head - tail) & (CMDMAX - CMDSTART - 4);
5014 if (n <= ncmds * sizeof(struct cm_t))
5018 ch->ch_bd->state = BOARD_FAILED;
5025 /*=======================================================================
5027 * dgap_wmove - Write data to FEP buffer.
5029 * ch - Pointer to channel structure.
5030 * buf - Poiter to characters to be moved.
5031 * cnt - Number of characters to move.
5033 *=======================================================================*/
5034 static void dgap_wmove(struct channel_t *ch, char *buf, uint cnt)
5041 if (!ch || ch->magic != DGAP_CHANNEL_MAGIC)
5048 head = readw(&(bs->tx_head));
5051 * If pointers are out of range, just return.
5053 if ((cnt > ch->ch_tsize) ||
5054 (unsigned)(head - ch->ch_tstart) >= ch->ch_tsize)
5058 * If the write wraps over the top of the circular buffer,
5059 * move the portion up to the wrap point, and reset the
5060 * pointers to the bottom.
5062 n = ch->ch_tstart + ch->ch_tsize - head;
5066 taddr = ch->ch_taddr + head;
5067 memcpy_toio(taddr, buf, n);
5068 head = ch->ch_tstart;
5073 * Move rest of data.
5075 taddr = ch->ch_taddr + head;
5077 memcpy_toio(taddr, buf, n);
5080 writew(head, &(bs->tx_head));
5084 * Retrives the current custom baud rate from FEP memory,
5085 * and returns it back to the user.
5086 * Returns 0 on error.
5088 static uint dgap_get_custom_baud(struct channel_t *ch)
5094 if (!ch || ch->magic != DGAP_CHANNEL_MAGIC)
5097 if (!ch->ch_bd || ch->ch_bd->magic != DGAP_BOARD_MAGIC)
5100 if (!(ch->ch_bd->bd_flags & BD_FEP5PLUS))
5103 vaddr = ch->ch_bd->re_map_membase;
5109 * Go get from fep mem, what the fep
5110 * believes the custom baud rate is.
5112 offset = ((((*(unsigned short *)(vaddr + ECS_SEG)) << 4) +
5113 (ch->ch_portnum * 0x28) + LINE_SPEED));
5115 value = readw(vaddr + offset);
5120 * Calls the firmware to reset this channel.
5122 static void dgap_firmware_reset_port(struct channel_t *ch)
5124 dgap_cmdb(ch, CHRESET, 0, 0, 0);
5127 * Now that the channel is reset, we need to make sure
5128 * all the current settings get reapplied to the port
5131 * So we will set the driver's cache of firmware
5132 * settings all to 0, and then call param.
5134 ch->ch_fepiflag = 0;
5135 ch->ch_fepcflag = 0;
5136 ch->ch_fepoflag = 0;
5137 ch->ch_fepstartc = 0;
5138 ch->ch_fepstopc = 0;
5139 ch->ch_fepastartc = 0;
5140 ch->ch_fepastopc = 0;
5145 /*=======================================================================
5147 * dgap_param - Set Digi parameters.
5149 * struct tty_struct * - TTY for port.
5151 *=======================================================================*/
5152 static int dgap_param(struct tty_struct *tty)
5154 struct ktermios *ts;
5156 struct channel_t *ch;
5165 if (!tty || tty->magic != TTY_MAGIC)
5168 un = (struct un_t *) tty->driver_data;
5169 if (!un || un->magic != DGAP_UNIT_MAGIC)
5173 if (!ch || ch->magic != DGAP_CHANNEL_MAGIC)
5177 if (!bd || bd->magic != DGAP_BOARD_MAGIC)
5187 * If baud rate is zero, flush queues, and set mval to drop DTR.
5189 if ((ch->ch_c_cflag & (CBAUD)) == 0) {
5192 head = readw(&(ch->ch_bs->rx_head));
5193 writew(head, &(ch->ch_bs->rx_tail));
5196 head = readw(&(ch->ch_bs->tx_head));
5197 writew(head, &(ch->ch_bs->tx_tail));
5199 ch->ch_flags |= (CH_BAUD0);
5201 /* Drop RTS and DTR */
5202 ch->ch_mval &= ~(D_RTS(ch)|D_DTR(ch));
5203 mval = D_DTR(ch) | D_RTS(ch);
5204 ch->ch_baud_info = 0;
5206 } else if (ch->ch_custom_speed && (bd->bd_flags & BD_FEP5PLUS)) {
5208 * Tell the fep to do the command
5211 dgap_cmdw_ext(ch, 0xff01, ch->ch_custom_speed, 0);
5214 * Now go get from fep mem, what the fep
5215 * believes the custom baud rate is.
5217 ch->ch_custom_speed = dgap_get_custom_baud(ch);
5218 ch->ch_baud_info = ch->ch_custom_speed;
5220 /* Handle transition from B0 */
5221 if (ch->ch_flags & CH_BAUD0) {
5222 ch->ch_flags &= ~(CH_BAUD0);
5223 ch->ch_mval |= (D_RTS(ch)|D_DTR(ch));
5225 mval = D_DTR(ch) | D_RTS(ch);
5229 * Set baud rate, character size, and parity.
5237 ulong bauds[4][16] = {
5241 600, 1200, 1800, 2400,
5242 4800, 9600, 19200, 38400 },
5243 { /* slowbaud & CBAUDEX */
5244 0, 57600, 115200, 230400,
5245 460800, 150, 200, 921600,
5246 600, 1200, 1800, 2400,
5247 4800, 9600, 19200, 38400 },
5249 0, 57600, 76800, 115200,
5250 14400, 57600, 230400, 76800,
5251 115200, 230400, 28800, 460800,
5252 921600, 9600, 19200, 38400 },
5253 { /* fastbaud & CBAUDEX */
5254 0, 57600, 115200, 230400,
5255 460800, 150, 200, 921600,
5256 600, 1200, 1800, 2400,
5257 4800, 9600, 19200, 38400 }
5261 * Only use the TXPrint baud rate if the
5262 * terminal unit is NOT open
5264 if (!(ch->ch_tun.un_flags & UN_ISOPEN) &&
5265 (un->un_type == DGAP_PRINT))
5266 baud = C_BAUD(ch->ch_pun.un_tty) & 0xff;
5268 baud = C_BAUD(ch->ch_tun.un_tty) & 0xff;
5270 if (ch->ch_c_cflag & CBAUDEX)
5273 if (ch->ch_digi.digi_flags & DIGI_FAST)
5278 if ((iindex >= 0) && (iindex < 4) &&
5279 (jindex >= 0) && (jindex < 16))
5280 baud = bauds[iindex][jindex];
5287 ch->ch_baud_info = baud;
5290 * CBAUD has bit position 0x1000 set these days to
5291 * indicate Linux baud rate remap.
5292 * We use a different bit assignment for high speed.
5293 * Clear this bit out while grabbing the parts of
5296 cflag = ch->ch_c_cflag & ((CBAUD ^ CBAUDEX) | PARODD | PARENB |
5300 * HUPCL bit is used by FEP to indicate fast baud
5301 * table is to be used.
5303 if ((ch->ch_digi.digi_flags & DIGI_FAST) ||
5304 (ch->ch_c_cflag & CBAUDEX))
5307 if ((ch->ch_c_cflag & CBAUDEX) &&
5308 !(ch->ch_digi.digi_flags & DIGI_FAST)) {
5310 * The below code is trying to guarantee that only
5311 * baud rates 115200, 230400, 460800, 921600 are
5312 * remapped. We use exclusive or because the various
5313 * baud rates share common bit positions and therefore
5314 * can't be tested for easily.
5316 tcflag_t tcflag = (ch->ch_c_cflag & CBAUD) | CBAUDEX;
5320 * Map high speed requests to index
5321 * into FEP's baud table
5351 cflag = (cflag & ~(CBAUD | CBAUDEX)) | baudpart;
5356 if (cflag != ch->ch_fepcflag) {
5357 ch->ch_fepcflag = (u16) (cflag & 0xffff);
5360 * Okay to have channel and board
5361 * locks held calling this
5363 dgap_cmdw(ch, SCFLAG, (u16) cflag, 0);
5366 /* Handle transition from B0 */
5367 if (ch->ch_flags & CH_BAUD0) {
5368 ch->ch_flags &= ~(CH_BAUD0);
5369 ch->ch_mval |= (D_RTS(ch)|D_DTR(ch));
5371 mval = D_DTR(ch) | D_RTS(ch);
5377 iflag = ch->ch_c_iflag & (IGNBRK | BRKINT | IGNPAR | PARMRK |
5378 INPCK | ISTRIP | IXON | IXANY | IXOFF);
5380 if ((ch->ch_startc == _POSIX_VDISABLE) ||
5381 (ch->ch_stopc == _POSIX_VDISABLE)) {
5382 iflag &= ~(IXON | IXOFF);
5383 ch->ch_c_iflag &= ~(IXON | IXOFF);
5387 * Only the IBM Xr card can switch between
5388 * 232 and 422 modes on the fly
5390 if (bd->device == PCI_DEV_XR_IBM_DID) {
5391 if (ch->ch_digi.digi_flags & DIGI_422)
5392 dgap_cmdb(ch, SCOMMODE, MODE_422, 0, 0);
5394 dgap_cmdb(ch, SCOMMODE, MODE_232, 0, 0);
5397 if (ch->ch_digi.digi_flags & DIGI_ALTPIN)
5400 if (iflag != ch->ch_fepiflag) {
5401 ch->ch_fepiflag = iflag;
5403 /* Okay to have channel and board locks held calling this */
5404 dgap_cmdw(ch, SIFLAG, (u16) ch->ch_fepiflag, 0);
5408 * Select hardware handshaking.
5412 if (ch->ch_c_cflag & CRTSCTS)
5413 hflow |= (D_RTS(ch) | D_CTS(ch));
5414 if (ch->ch_digi.digi_flags & RTSPACE)
5416 if (ch->ch_digi.digi_flags & DTRPACE)
5418 if (ch->ch_digi.digi_flags & CTSPACE)
5420 if (ch->ch_digi.digi_flags & DSRPACE)
5422 if (ch->ch_digi.digi_flags & DCDPACE)
5425 if (hflow != ch->ch_hflow) {
5426 ch->ch_hflow = hflow;
5428 /* Okay to have channel and board locks held calling this */
5429 dgap_cmdb(ch, SHFLOW, (uchar) hflow, 0xff, 0);
5434 * Set RTS and/or DTR Toggle if needed,
5435 * but only if product is FEP5+ based.
5437 if (bd->bd_flags & BD_FEP5PLUS) {
5439 if (ch->ch_digi.digi_flags & DIGI_RTS_TOGGLE)
5440 hflow2 |= (D_RTS(ch));
5441 if (ch->ch_digi.digi_flags & DIGI_DTR_TOGGLE)
5442 hflow2 |= (D_DTR(ch));
5444 dgap_cmdw_ext(ch, 0xff03, hflow2, 0);
5448 * Set modem control lines.
5451 mval ^= ch->ch_mforce & (mval ^ ch->ch_mval);
5453 if (ch->ch_mostat ^ mval) {
5454 ch->ch_mostat = mval;
5456 /* Okay to have channel and board locks held calling this */
5457 dgap_cmdb(ch, SMODEM, (uchar) mval, D_RTS(ch)|D_DTR(ch), 0);
5461 * Read modem signals, and then call carrier function.
5463 ch->ch_mistat = readb(&(bs->m_stat));
5467 * Set the start and stop characters.
5469 if (ch->ch_startc != ch->ch_fepstartc ||
5470 ch->ch_stopc != ch->ch_fepstopc) {
5471 ch->ch_fepstartc = ch->ch_startc;
5472 ch->ch_fepstopc = ch->ch_stopc;
5474 /* Okay to have channel and board locks held calling this */
5475 dgap_cmdb(ch, SFLOWC, ch->ch_fepstartc, ch->ch_fepstopc, 0);
5479 * Set the Auxiliary start and stop characters.
5481 if (ch->ch_astartc != ch->ch_fepastartc ||
5482 ch->ch_astopc != ch->ch_fepastopc) {
5483 ch->ch_fepastartc = ch->ch_astartc;
5484 ch->ch_fepastopc = ch->ch_astopc;
5486 /* Okay to have channel and board locks held calling this */
5487 dgap_cmdb(ch, SAFLOWC, ch->ch_fepastartc, ch->ch_fepastopc, 0);
5494 * dgap_parity_scan()
5496 * Convert the FEP5 way of reporting parity errors and breaks into
5497 * the Linux line discipline way.
5499 static void dgap_parity_scan(struct channel_t *ch, unsigned char *cbuf,
5500 unsigned char *fbuf, int *len)
5504 unsigned char *in, *cout, *fout;
5511 if (!ch || ch->magic != DGAP_CHANNEL_MAGIC)
5516 switch (ch->pscan_state) {
5518 /* reset to sanity and fall through */
5519 ch->pscan_state = 0;
5522 /* No FF seen yet */
5523 if (c == (unsigned char) '\377')
5524 /* delete this character from stream */
5525 ch->pscan_state = 1;
5528 *fout++ = TTY_NORMAL;
5535 if (c == (unsigned char) '\377') {
5536 /* doubled ff, transform to single ff */
5538 *fout++ = TTY_NORMAL;
5540 ch->pscan_state = 0;
5542 /* save value examination in next state */
5543 ch->pscan_savechar = c;
5544 ch->pscan_state = 2;
5549 /* third character of ff sequence */
5553 if (ch->pscan_savechar == 0x0) {
5557 *fout++ = TTY_BREAK;
5559 ch->ch_err_parity++;
5560 *fout++ = TTY_PARITY;
5565 ch->pscan_state = 0;
5571 /*=======================================================================
5573 * dgap_event - FEP to host event processing routine.
5575 * bd - Board of current event.
5577 *=======================================================================*/
5578 static int dgap_event(struct board_t *bd)
5580 struct channel_t *ch;
5585 uchar *vaddr = NULL;
5586 struct ev_t *eaddr = NULL;
5594 if (!bd || bd->magic != DGAP_BOARD_MAGIC)
5597 DGAP_LOCK(bd->bd_lock, lock_flags);
5599 vaddr = bd->re_map_membase;
5602 DGAP_UNLOCK(bd->bd_lock, lock_flags);
5606 eaddr = (struct ev_t *) (vaddr + EVBUF);
5608 /* Get our head and tail */
5609 head = readw(&(eaddr->ev_head));
5610 tail = readw(&(eaddr->ev_tail));
5613 * Forget it if pointers out of range.
5616 if (head >= EVMAX - EVSTART || tail >= EVMAX - EVSTART ||
5617 (head | tail) & 03) {
5618 /* Let go of board lock */
5619 DGAP_UNLOCK(bd->bd_lock, lock_flags);
5624 * Loop to process all the events in the buffer.
5626 while (tail != head) {
5629 * Get interrupt information.
5632 event = bd->re_map_membase + tail + EVSTART;
5640 * Make sure the interrupt is valid.
5642 if (port >= bd->nasync)
5645 if (!(reason & (IFMODEM | IFBREAK | IFTLW | IFTEM | IFDATA)))
5648 ch = bd->channels[port];
5650 if (!ch || ch->magic != DGAP_CHANNEL_MAGIC)
5654 * If we have made it here, the event was valid.
5655 * Lock down the channel.
5657 DGAP_LOCK(ch->ch_lock, lock_flags2);
5662 DGAP_UNLOCK(ch->ch_lock, lock_flags2);
5667 * Process received data.
5669 if (reason & IFDATA) {
5672 * ALL LOCKS *MUST* BE DROPPED BEFORE CALLING INPUT!
5673 * input could send some data to ld, which in turn
5674 * could do a callback to one of our other functions.
5676 DGAP_UNLOCK(ch->ch_lock, lock_flags2);
5677 DGAP_UNLOCK(bd->bd_lock, lock_flags);
5681 DGAP_LOCK(bd->bd_lock, lock_flags);
5682 DGAP_LOCK(ch->ch_lock, lock_flags2);
5684 if (ch->ch_flags & CH_RACTIVE)
5685 ch->ch_flags |= CH_RENABLE;
5687 writeb(1, &(bs->idata));
5689 if (ch->ch_flags & CH_RWAIT) {
5690 ch->ch_flags &= ~CH_RWAIT;
5692 wake_up_interruptible
5693 (&ch->ch_tun.un_flags_wait);
5698 * Process Modem change signals.
5700 if (reason & IFMODEM) {
5701 ch->ch_mistat = modem;
5708 if (reason & IFBREAK) {
5710 if (ch->ch_tun.un_tty) {
5711 /* A break has been indicated */
5713 tty_buffer_request_room
5714 (ch->ch_tun.un_tty->port, 1);
5715 tty_insert_flip_char(ch->ch_tun.un_tty->port,
5717 tty_flip_buffer_push(ch->ch_tun.un_tty->port);
5722 * Process Transmit low.
5724 if (reason & IFTLW) {
5726 if (ch->ch_tun.un_flags & UN_LOW) {
5727 ch->ch_tun.un_flags &= ~UN_LOW;
5729 if (ch->ch_tun.un_flags & UN_ISOPEN) {
5730 if ((ch->ch_tun.un_tty->flags &
5731 (1 << TTY_DO_WRITE_WAKEUP)) &&
5732 ch->ch_tun.un_tty->ldisc->ops->write_wakeup) {
5733 DGAP_UNLOCK(ch->ch_lock, lock_flags2);
5734 DGAP_UNLOCK(bd->bd_lock, lock_flags);
5735 (ch->ch_tun.un_tty->ldisc->ops->write_wakeup)(ch->ch_tun.un_tty);
5736 DGAP_LOCK(bd->bd_lock, lock_flags);
5737 DGAP_LOCK(ch->ch_lock, lock_flags2);
5739 wake_up_interruptible(&ch->ch_tun.un_tty->write_wait);
5740 wake_up_interruptible(&ch->ch_tun.un_flags_wait);
5744 if (ch->ch_pun.un_flags & UN_LOW) {
5745 ch->ch_pun.un_flags &= ~UN_LOW;
5746 if (ch->ch_pun.un_flags & UN_ISOPEN) {
5747 if ((ch->ch_pun.un_tty->flags &
5748 (1 << TTY_DO_WRITE_WAKEUP)) &&
5749 ch->ch_pun.un_tty->ldisc->ops->write_wakeup) {
5750 DGAP_UNLOCK(ch->ch_lock, lock_flags2);
5751 DGAP_UNLOCK(bd->bd_lock, lock_flags);
5752 (ch->ch_pun.un_tty->ldisc->ops->write_wakeup)(ch->ch_pun.un_tty);
5753 DGAP_LOCK(bd->bd_lock, lock_flags);
5754 DGAP_LOCK(ch->ch_lock, lock_flags2);
5756 wake_up_interruptible(&ch->ch_pun.un_tty->write_wait);
5757 wake_up_interruptible(&ch->ch_pun.un_flags_wait);
5761 if (ch->ch_flags & CH_WLOW) {
5762 ch->ch_flags &= ~CH_WLOW;
5763 wake_up_interruptible(&ch->ch_flags_wait);
5768 * Process Transmit empty.
5770 if (reason & IFTEM) {
5771 if (ch->ch_tun.un_flags & UN_EMPTY) {
5772 ch->ch_tun.un_flags &= ~UN_EMPTY;
5773 if (ch->ch_tun.un_flags & UN_ISOPEN) {
5774 if ((ch->ch_tun.un_tty->flags &
5775 (1 << TTY_DO_WRITE_WAKEUP)) &&
5776 ch->ch_tun.un_tty->ldisc->ops->write_wakeup) {
5777 DGAP_UNLOCK(ch->ch_lock, lock_flags2);
5778 DGAP_UNLOCK(bd->bd_lock, lock_flags);
5780 (ch->ch_tun.un_tty->ldisc->ops->write_wakeup)(ch->ch_tun.un_tty);
5781 DGAP_LOCK(bd->bd_lock, lock_flags);
5782 DGAP_LOCK(ch->ch_lock, lock_flags2);
5784 wake_up_interruptible(&ch->ch_tun.un_tty->write_wait);
5785 wake_up_interruptible(&ch->ch_tun.un_flags_wait);
5789 if (ch->ch_pun.un_flags & UN_EMPTY) {
5790 ch->ch_pun.un_flags &= ~UN_EMPTY;
5791 if (ch->ch_pun.un_flags & UN_ISOPEN) {
5792 if ((ch->ch_pun.un_tty->flags &
5793 (1 << TTY_DO_WRITE_WAKEUP)) &&
5794 ch->ch_pun.un_tty->ldisc->ops->write_wakeup) {
5795 DGAP_UNLOCK(ch->ch_lock, lock_flags2);
5796 DGAP_UNLOCK(bd->bd_lock, lock_flags);
5797 (ch->ch_pun.un_tty->ldisc->ops->write_wakeup)(ch->ch_pun.un_tty);
5798 DGAP_LOCK(bd->bd_lock, lock_flags);
5799 DGAP_LOCK(ch->ch_lock, lock_flags2);
5801 wake_up_interruptible(&ch->ch_pun.un_tty->write_wait);
5802 wake_up_interruptible(&ch->ch_pun.un_flags_wait);
5807 if (ch->ch_flags & CH_WEMPTY) {
5808 ch->ch_flags &= ~CH_WEMPTY;
5809 wake_up_interruptible(&ch->ch_flags_wait);
5813 DGAP_UNLOCK(ch->ch_lock, lock_flags2);
5816 tail = (tail + 4) & (EVMAX - EVSTART - 4);
5819 writew(tail, &(eaddr->ev_tail));
5820 DGAP_UNLOCK(bd->bd_lock, lock_flags);
5825 static ssize_t dgap_driver_version_show(struct device_driver *ddp, char *buf)
5827 return snprintf(buf, PAGE_SIZE, "%s\n", DG_PART);
5829 static DRIVER_ATTR(version, S_IRUSR, dgap_driver_version_show, NULL);
5832 static ssize_t dgap_driver_boards_show(struct device_driver *ddp, char *buf)
5834 return snprintf(buf, PAGE_SIZE, "%d\n", dgap_NumBoards);
5836 static DRIVER_ATTR(boards, S_IRUSR, dgap_driver_boards_show, NULL);
5839 static ssize_t dgap_driver_maxboards_show(struct device_driver *ddp, char *buf)
5841 return snprintf(buf, PAGE_SIZE, "%d\n", MAXBOARDS);
5843 static DRIVER_ATTR(maxboards, S_IRUSR, dgap_driver_maxboards_show, NULL);
5846 static ssize_t dgap_driver_pollcounter_show(struct device_driver *ddp,
5849 return snprintf(buf, PAGE_SIZE, "%ld\n", dgap_poll_counter);
5851 static DRIVER_ATTR(pollcounter, S_IRUSR, dgap_driver_pollcounter_show, NULL);
5853 static ssize_t dgap_driver_pollrate_show(struct device_driver *ddp, char *buf)
5855 return snprintf(buf, PAGE_SIZE, "%dms\n", dgap_poll_tick);
5858 static ssize_t dgap_driver_pollrate_store(struct device_driver *ddp,
5859 const char *buf, size_t count)
5861 if (sscanf(buf, "%d\n", &dgap_poll_tick) != 1)
5865 static DRIVER_ATTR(pollrate, (S_IRUSR | S_IWUSR), dgap_driver_pollrate_show,
5866 dgap_driver_pollrate_store);
5868 static int dgap_create_driver_sysfiles(struct pci_driver *dgap_driver)
5871 struct device_driver *driverfs = &dgap_driver->driver;
5873 rc |= driver_create_file(driverfs, &driver_attr_version);
5874 rc |= driver_create_file(driverfs, &driver_attr_boards);
5875 rc |= driver_create_file(driverfs, &driver_attr_maxboards);
5876 rc |= driver_create_file(driverfs, &driver_attr_pollrate);
5877 rc |= driver_create_file(driverfs, &driver_attr_pollcounter);
5882 static void dgap_remove_driver_sysfiles(struct pci_driver *dgap_driver)
5884 struct device_driver *driverfs = &dgap_driver->driver;
5885 driver_remove_file(driverfs, &driver_attr_version);
5886 driver_remove_file(driverfs, &driver_attr_boards);
5887 driver_remove_file(driverfs, &driver_attr_maxboards);
5888 driver_remove_file(driverfs, &driver_attr_pollrate);
5889 driver_remove_file(driverfs, &driver_attr_pollcounter);
5892 static struct board_t *dgap_verify_board(struct device *p)
5899 bd = dev_get_drvdata(p);
5900 if (!bd || bd->magic != DGAP_BOARD_MAGIC || bd->state != BOARD_READY)
5906 static ssize_t dgap_ports_state_show(struct device *p,
5907 struct device_attribute *attr,
5914 bd = dgap_verify_board(p);
5918 for (i = 0; i < bd->nasync; i++) {
5919 count += snprintf(buf + count, PAGE_SIZE - count,
5920 "%d %s\n", bd->channels[i]->ch_portnum,
5921 bd->channels[i]->ch_open_count ? "Open" : "Closed");
5925 static DEVICE_ATTR(ports_state, S_IRUSR, dgap_ports_state_show, NULL);
5927 static ssize_t dgap_ports_baud_show(struct device *p,
5928 struct device_attribute *attr,
5935 bd = dgap_verify_board(p);
5939 for (i = 0; i < bd->nasync; i++) {
5940 count += snprintf(buf + count, PAGE_SIZE - count, "%d %d\n",
5941 bd->channels[i]->ch_portnum,
5942 bd->channels[i]->ch_baud_info);
5946 static DEVICE_ATTR(ports_baud, S_IRUSR, dgap_ports_baud_show, NULL);
5948 static ssize_t dgap_ports_msignals_show(struct device *p,
5949 struct device_attribute *attr,
5956 bd = dgap_verify_board(p);
5960 for (i = 0; i < bd->nasync; i++) {
5961 if (bd->channels[i]->ch_open_count)
5962 count += snprintf(buf + count, PAGE_SIZE - count,
5963 "%d %s %s %s %s %s %s\n",
5964 bd->channels[i]->ch_portnum,
5965 (bd->channels[i]->ch_mostat &
5966 UART_MCR_RTS) ? "RTS" : "",
5967 (bd->channels[i]->ch_mistat &
5968 UART_MSR_CTS) ? "CTS" : "",
5969 (bd->channels[i]->ch_mostat &
5970 UART_MCR_DTR) ? "DTR" : "",
5971 (bd->channels[i]->ch_mistat &
5972 UART_MSR_DSR) ? "DSR" : "",
5973 (bd->channels[i]->ch_mistat &
5974 UART_MSR_DCD) ? "DCD" : "",
5975 (bd->channels[i]->ch_mistat &
5976 UART_MSR_RI) ? "RI" : "");
5978 count += snprintf(buf + count, PAGE_SIZE - count,
5979 "%d\n", bd->channels[i]->ch_portnum);
5983 static DEVICE_ATTR(ports_msignals, S_IRUSR, dgap_ports_msignals_show, NULL);
5985 static ssize_t dgap_ports_iflag_show(struct device *p,
5986 struct device_attribute *attr,
5993 bd = dgap_verify_board(p);
5997 for (i = 0; i < bd->nasync; i++)
5998 count += snprintf(buf + count, PAGE_SIZE - count, "%d %x\n",
5999 bd->channels[i]->ch_portnum,
6000 bd->channels[i]->ch_c_iflag);
6003 static DEVICE_ATTR(ports_iflag, S_IRUSR, dgap_ports_iflag_show, NULL);
6005 static ssize_t dgap_ports_cflag_show(struct device *p,
6006 struct device_attribute *attr,
6013 bd = dgap_verify_board(p);
6017 for (i = 0; i < bd->nasync; i++)
6018 count += snprintf(buf + count, PAGE_SIZE - count, "%d %x\n",
6019 bd->channels[i]->ch_portnum,
6020 bd->channels[i]->ch_c_cflag);
6023 static DEVICE_ATTR(ports_cflag, S_IRUSR, dgap_ports_cflag_show, NULL);
6025 static ssize_t dgap_ports_oflag_show(struct device *p,
6026 struct device_attribute *attr,
6033 bd = dgap_verify_board(p);
6037 for (i = 0; i < bd->nasync; i++)
6038 count += snprintf(buf + count, PAGE_SIZE - count, "%d %x\n",
6039 bd->channels[i]->ch_portnum,
6040 bd->channels[i]->ch_c_oflag);
6043 static DEVICE_ATTR(ports_oflag, S_IRUSR, dgap_ports_oflag_show, NULL);
6045 static ssize_t dgap_ports_lflag_show(struct device *p,
6046 struct device_attribute *attr,
6053 bd = dgap_verify_board(p);
6057 for (i = 0; i < bd->nasync; i++)
6058 count += snprintf(buf + count, PAGE_SIZE - count, "%d %x\n",
6059 bd->channels[i]->ch_portnum,
6060 bd->channels[i]->ch_c_lflag);
6063 static DEVICE_ATTR(ports_lflag, S_IRUSR, dgap_ports_lflag_show, NULL);
6065 static ssize_t dgap_ports_digi_flag_show(struct device *p,
6066 struct device_attribute *attr,
6073 bd = dgap_verify_board(p);
6077 for (i = 0; i < bd->nasync; i++)
6078 count += snprintf(buf + count, PAGE_SIZE - count, "%d %x\n",
6079 bd->channels[i]->ch_portnum,
6080 bd->channels[i]->ch_digi.digi_flags);
6083 static DEVICE_ATTR(ports_digi_flag, S_IRUSR, dgap_ports_digi_flag_show, NULL);
6085 static ssize_t dgap_ports_rxcount_show(struct device *p,
6086 struct device_attribute *attr,
6093 bd = dgap_verify_board(p);
6097 for (i = 0; i < bd->nasync; i++)
6098 count += snprintf(buf + count, PAGE_SIZE - count, "%d %ld\n",
6099 bd->channels[i]->ch_portnum,
6100 bd->channels[i]->ch_rxcount);
6103 static DEVICE_ATTR(ports_rxcount, S_IRUSR, dgap_ports_rxcount_show, NULL);
6105 static ssize_t dgap_ports_txcount_show(struct device *p,
6106 struct device_attribute *attr,
6113 bd = dgap_verify_board(p);
6117 for (i = 0; i < bd->nasync; i++)
6118 count += snprintf(buf + count, PAGE_SIZE - count, "%d %ld\n",
6119 bd->channels[i]->ch_portnum,
6120 bd->channels[i]->ch_txcount);
6123 static DEVICE_ATTR(ports_txcount, S_IRUSR, dgap_ports_txcount_show, NULL);
6125 /* this function creates the sys files that will export each signal status
6126 * to sysfs each value will be put in a separate filename
6128 static void dgap_create_ports_sysfiles(struct board_t *bd)
6130 dev_set_drvdata(&bd->pdev->dev, bd);
6131 device_create_file(&(bd->pdev->dev), &dev_attr_ports_state);
6132 device_create_file(&(bd->pdev->dev), &dev_attr_ports_baud);
6133 device_create_file(&(bd->pdev->dev), &dev_attr_ports_msignals);
6134 device_create_file(&(bd->pdev->dev), &dev_attr_ports_iflag);
6135 device_create_file(&(bd->pdev->dev), &dev_attr_ports_cflag);
6136 device_create_file(&(bd->pdev->dev), &dev_attr_ports_oflag);
6137 device_create_file(&(bd->pdev->dev), &dev_attr_ports_lflag);
6138 device_create_file(&(bd->pdev->dev), &dev_attr_ports_digi_flag);
6139 device_create_file(&(bd->pdev->dev), &dev_attr_ports_rxcount);
6140 device_create_file(&(bd->pdev->dev), &dev_attr_ports_txcount);
6143 /* removes all the sys files created for that port */
6144 static void dgap_remove_ports_sysfiles(struct board_t *bd)
6146 device_remove_file(&(bd->pdev->dev), &dev_attr_ports_state);
6147 device_remove_file(&(bd->pdev->dev), &dev_attr_ports_baud);
6148 device_remove_file(&(bd->pdev->dev), &dev_attr_ports_msignals);
6149 device_remove_file(&(bd->pdev->dev), &dev_attr_ports_iflag);
6150 device_remove_file(&(bd->pdev->dev), &dev_attr_ports_cflag);
6151 device_remove_file(&(bd->pdev->dev), &dev_attr_ports_oflag);
6152 device_remove_file(&(bd->pdev->dev), &dev_attr_ports_lflag);
6153 device_remove_file(&(bd->pdev->dev), &dev_attr_ports_digi_flag);
6154 device_remove_file(&(bd->pdev->dev), &dev_attr_ports_rxcount);
6155 device_remove_file(&(bd->pdev->dev), &dev_attr_ports_txcount);
6158 static ssize_t dgap_tty_state_show(struct device *d,
6159 struct device_attribute *attr,
6163 struct channel_t *ch;
6168 un = dev_get_drvdata(d);
6169 if (!un || un->magic != DGAP_UNIT_MAGIC)
6172 if (!ch || ch->magic != DGAP_CHANNEL_MAGIC)
6175 if (!bd || bd->magic != DGAP_BOARD_MAGIC)
6177 if (bd->state != BOARD_READY)
6180 return snprintf(buf, PAGE_SIZE, "%s", un->un_open_count ?
6183 static DEVICE_ATTR(state, S_IRUSR, dgap_tty_state_show, NULL);
6185 static ssize_t dgap_tty_baud_show(struct device *d,
6186 struct device_attribute *attr,
6190 struct channel_t *ch;
6195 un = dev_get_drvdata(d);
6196 if (!un || un->magic != DGAP_UNIT_MAGIC)
6199 if (!ch || ch->magic != DGAP_CHANNEL_MAGIC)
6202 if (!bd || bd->magic != DGAP_BOARD_MAGIC)
6204 if (bd->state != BOARD_READY)
6207 return snprintf(buf, PAGE_SIZE, "%d\n", ch->ch_baud_info);
6209 static DEVICE_ATTR(baud, S_IRUSR, dgap_tty_baud_show, NULL);
6211 static ssize_t dgap_tty_msignals_show(struct device *d,
6212 struct device_attribute *attr,
6216 struct channel_t *ch;
6221 un = dev_get_drvdata(d);
6222 if (!un || un->magic != DGAP_UNIT_MAGIC)
6225 if (!ch || ch->magic != DGAP_CHANNEL_MAGIC)
6228 if (!bd || bd->magic != DGAP_BOARD_MAGIC)
6230 if (bd->state != BOARD_READY)
6233 if (ch->ch_open_count) {
6234 return snprintf(buf, PAGE_SIZE, "%s %s %s %s %s %s\n",
6235 (ch->ch_mostat & UART_MCR_RTS) ? "RTS" : "",
6236 (ch->ch_mistat & UART_MSR_CTS) ? "CTS" : "",
6237 (ch->ch_mostat & UART_MCR_DTR) ? "DTR" : "",
6238 (ch->ch_mistat & UART_MSR_DSR) ? "DSR" : "",
6239 (ch->ch_mistat & UART_MSR_DCD) ? "DCD" : "",
6240 (ch->ch_mistat & UART_MSR_RI) ? "RI" : "");
6244 static DEVICE_ATTR(msignals, S_IRUSR, dgap_tty_msignals_show, NULL);
6246 static ssize_t dgap_tty_iflag_show(struct device *d,
6247 struct device_attribute *attr,
6251 struct channel_t *ch;
6256 un = dev_get_drvdata(d);
6257 if (!un || un->magic != DGAP_UNIT_MAGIC)
6260 if (!ch || ch->magic != DGAP_CHANNEL_MAGIC)
6263 if (!bd || bd->magic != DGAP_BOARD_MAGIC)
6265 if (bd->state != BOARD_READY)
6268 return snprintf(buf, PAGE_SIZE, "%x\n", ch->ch_c_iflag);
6270 static DEVICE_ATTR(iflag, S_IRUSR, dgap_tty_iflag_show, NULL);
6272 static ssize_t dgap_tty_cflag_show(struct device *d,
6273 struct device_attribute *attr,
6277 struct channel_t *ch;
6282 un = dev_get_drvdata(d);
6283 if (!un || un->magic != DGAP_UNIT_MAGIC)
6286 if (!ch || ch->magic != DGAP_CHANNEL_MAGIC)
6289 if (!bd || bd->magic != DGAP_BOARD_MAGIC)
6291 if (bd->state != BOARD_READY)
6294 return snprintf(buf, PAGE_SIZE, "%x\n", ch->ch_c_cflag);
6296 static DEVICE_ATTR(cflag, S_IRUSR, dgap_tty_cflag_show, NULL);
6298 static ssize_t dgap_tty_oflag_show(struct device *d,
6299 struct device_attribute *attr,
6303 struct channel_t *ch;
6308 un = dev_get_drvdata(d);
6309 if (!un || un->magic != DGAP_UNIT_MAGIC)
6312 if (!ch || ch->magic != DGAP_CHANNEL_MAGIC)
6315 if (!bd || bd->magic != DGAP_BOARD_MAGIC)
6317 if (bd->state != BOARD_READY)
6320 return snprintf(buf, PAGE_SIZE, "%x\n", ch->ch_c_oflag);
6322 static DEVICE_ATTR(oflag, S_IRUSR, dgap_tty_oflag_show, NULL);
6324 static ssize_t dgap_tty_lflag_show(struct device *d,
6325 struct device_attribute *attr,
6329 struct channel_t *ch;
6334 un = dev_get_drvdata(d);
6335 if (!un || un->magic != DGAP_UNIT_MAGIC)
6338 if (!ch || ch->magic != DGAP_CHANNEL_MAGIC)
6341 if (!bd || bd->magic != DGAP_BOARD_MAGIC)
6343 if (bd->state != BOARD_READY)
6346 return snprintf(buf, PAGE_SIZE, "%x\n", ch->ch_c_lflag);
6348 static DEVICE_ATTR(lflag, S_IRUSR, dgap_tty_lflag_show, NULL);
6350 static ssize_t dgap_tty_digi_flag_show(struct device *d,
6351 struct device_attribute *attr,
6355 struct channel_t *ch;
6360 un = dev_get_drvdata(d);
6361 if (!un || un->magic != DGAP_UNIT_MAGIC)
6364 if (!ch || ch->magic != DGAP_CHANNEL_MAGIC)
6367 if (!bd || bd->magic != DGAP_BOARD_MAGIC)
6369 if (bd->state != BOARD_READY)
6372 return snprintf(buf, PAGE_SIZE, "%x\n", ch->ch_digi.digi_flags);
6374 static DEVICE_ATTR(digi_flag, S_IRUSR, dgap_tty_digi_flag_show, NULL);
6376 static ssize_t dgap_tty_rxcount_show(struct device *d,
6377 struct device_attribute *attr,
6381 struct channel_t *ch;
6386 un = dev_get_drvdata(d);
6387 if (!un || un->magic != DGAP_UNIT_MAGIC)
6390 if (!ch || ch->magic != DGAP_CHANNEL_MAGIC)
6393 if (!bd || bd->magic != DGAP_BOARD_MAGIC)
6395 if (bd->state != BOARD_READY)
6398 return snprintf(buf, PAGE_SIZE, "%ld\n", ch->ch_rxcount);
6400 static DEVICE_ATTR(rxcount, S_IRUSR, dgap_tty_rxcount_show, NULL);
6402 static ssize_t dgap_tty_txcount_show(struct device *d,
6403 struct device_attribute *attr,
6407 struct channel_t *ch;
6412 un = dev_get_drvdata(d);
6413 if (!un || un->magic != DGAP_UNIT_MAGIC)
6416 if (!ch || ch->magic != DGAP_CHANNEL_MAGIC)
6419 if (!bd || bd->magic != DGAP_BOARD_MAGIC)
6421 if (bd->state != BOARD_READY)
6424 return snprintf(buf, PAGE_SIZE, "%ld\n", ch->ch_txcount);
6426 static DEVICE_ATTR(txcount, S_IRUSR, dgap_tty_txcount_show, NULL);
6428 static ssize_t dgap_tty_name_show(struct device *d,
6429 struct device_attribute *attr,
6433 struct channel_t *ch;
6437 struct cnode *cptr = NULL;
6445 un = dev_get_drvdata(d);
6446 if (!un || un->magic != DGAP_UNIT_MAGIC)
6449 if (!ch || ch->magic != DGAP_CHANNEL_MAGIC)
6452 if (!bd || bd->magic != DGAP_BOARD_MAGIC)
6454 if (bd->state != BOARD_READY)
6458 cn = ch->ch_portnum;
6460 for (cptr = bd->bd_config; cptr; cptr = cptr->next) {
6462 if ((cptr->type == BNODE) &&
6463 ((cptr->u.board.type == APORT2_920P) ||
6464 (cptr->u.board.type == APORT4_920P) ||
6465 (cptr->u.board.type == APORT8_920P) ||
6466 (cptr->u.board.type == PAPORT4) ||
6467 (cptr->u.board.type == PAPORT8))) {
6470 if (cptr->u.board.v_start)
6471 starto = cptr->u.board.start;
6476 if (cptr->type == TNODE && found == TRUE) {
6478 if (strstr(cptr->u.ttyname, "tty")) {
6479 ptr1 = cptr->u.ttyname;
6482 ptr1 = cptr->u.ttyname;
6484 for (i = 0; i < dgap_config_get_number_of_ports(bd); i++) {
6486 return snprintf(buf, PAGE_SIZE, "%s%s%02d\n",
6487 (un->un_type == DGAP_PRINT) ? "pr" : "tty",
6492 if (cptr->type == CNODE) {
6494 for (i = 0; i < cptr->u.conc.nport; i++) {
6495 if (cn == (i + ncount))
6497 return snprintf(buf, PAGE_SIZE, "%s%s%02d\n",
6498 (un->un_type == DGAP_PRINT) ? "pr" : "tty",
6500 i + (cptr->u.conc.v_start ? cptr->u.conc.start : 1));
6503 ncount += cptr->u.conc.nport;
6506 if (cptr->type == MNODE) {
6508 for (i = 0; i < cptr->u.module.nport; i++) {
6509 if (cn == (i + ncount))
6510 return snprintf(buf, PAGE_SIZE, "%s%s%02d\n",
6511 (un->un_type == DGAP_PRINT) ? "pr" : "tty",
6513 i + (cptr->u.module.v_start ? cptr->u.module.start : 1));
6516 ncount += cptr->u.module.nport;
6521 return snprintf(buf, PAGE_SIZE, "%s_dgap_%d_%d\n",
6522 (un->un_type == DGAP_PRINT) ? "pr" : "tty", bn, cn);
6525 static DEVICE_ATTR(custom_name, S_IRUSR, dgap_tty_name_show, NULL);
6527 static struct attribute *dgap_sysfs_tty_entries[] = {
6528 &dev_attr_state.attr,
6529 &dev_attr_baud.attr,
6530 &dev_attr_msignals.attr,
6531 &dev_attr_iflag.attr,
6532 &dev_attr_cflag.attr,
6533 &dev_attr_oflag.attr,
6534 &dev_attr_lflag.attr,
6535 &dev_attr_digi_flag.attr,
6536 &dev_attr_rxcount.attr,
6537 &dev_attr_txcount.attr,
6538 &dev_attr_custom_name.attr,
6542 static struct attribute_group dgap_tty_attribute_group = {
6544 .attrs = dgap_sysfs_tty_entries,
6547 static void dgap_create_tty_sysfs(struct un_t *un, struct device *c)
6551 ret = sysfs_create_group(&c->kobj, &dgap_tty_attribute_group);
6555 dev_set_drvdata(c, un);
6559 static void dgap_remove_tty_sysfs(struct device *c)
6561 sysfs_remove_group(&c->kobj, &dgap_tty_attribute_group);
6565 * Parse a configuration file read into memory as a string.
6567 static int dgap_parsefile(char **in, int Remove)
6569 struct cnode *p, *brd, *line, *conc;
6571 char *s = NULL, *s2 = NULL;
6575 brd = line = conc = NULL;
6577 /* perhaps we are adding to an existing list? */
6578 while (p->next != NULL)
6581 /* file must start with a BEGIN */
6582 while ((rc = dgap_gettok(in, p)) != BEGIN) {
6584 dgap_err("unexpected EOF");
6590 rc = dgap_gettok(in, p);
6592 dgap_err("unexpected EOF");
6598 dgap_err("unexpected end of file");
6601 case BEGIN: /* should only be 1 begin */
6602 dgap_err("unexpected config_begin\n");
6608 case BOARD: /* board info */
6609 if (dgap_checknode(p))
6611 p->next = dgap_newnode(BNODE);
6613 dgap_err("out of memory");
6618 p->u.board.status = dgap_savestring("No");
6624 case APORT2_920P: /* AccelePort_4 */
6625 if (p->type != BNODE) {
6626 dgap_err("unexpected Digi_2r_920 string");
6629 p->u.board.type = APORT2_920P;
6630 p->u.board.v_type = 1;
6633 case APORT4_920P: /* AccelePort_4 */
6634 if (p->type != BNODE) {
6635 dgap_err("unexpected Digi_4r_920 string");
6638 p->u.board.type = APORT4_920P;
6639 p->u.board.v_type = 1;
6642 case APORT8_920P: /* AccelePort_8 */
6643 if (p->type != BNODE) {
6644 dgap_err("unexpected Digi_8r_920 string");
6647 p->u.board.type = APORT8_920P;
6648 p->u.board.v_type = 1;
6651 case PAPORT4: /* AccelePort_4 PCI */
6652 if (p->type != BNODE) {
6653 dgap_err("unexpected Digi_4r(PCI) string");
6656 p->u.board.type = PAPORT4;
6657 p->u.board.v_type = 1;
6660 case PAPORT8: /* AccelePort_8 PCI */
6661 if (p->type != BNODE) {
6662 dgap_err("unexpected Digi_8r string");
6665 p->u.board.type = PAPORT8;
6666 p->u.board.v_type = 1;
6669 case PCX: /* PCI C/X */
6670 if (p->type != BNODE) {
6671 dgap_err("unexpected Digi_C/X_(PCI) string");
6674 p->u.board.type = PCX;
6675 p->u.board.v_type = 1;
6676 p->u.board.conc1 = 0;
6677 p->u.board.conc2 = 0;
6678 p->u.board.module1 = 0;
6679 p->u.board.module2 = 0;
6682 case PEPC: /* PCI EPC/X */
6683 if (p->type != BNODE) {
6684 dgap_err("unexpected \"Digi_EPC/X_(PCI)\" string");
6687 p->u.board.type = PEPC;
6688 p->u.board.v_type = 1;
6689 p->u.board.conc1 = 0;
6690 p->u.board.conc2 = 0;
6691 p->u.board.module1 = 0;
6692 p->u.board.module2 = 0;
6695 case PPCM: /* PCI/Xem */
6696 if (p->type != BNODE) {
6697 dgap_err("unexpected PCI/Xem string");
6700 p->u.board.type = PPCM;
6701 p->u.board.v_type = 1;
6702 p->u.board.conc1 = 0;
6703 p->u.board.conc2 = 0;
6706 case IO: /* i/o port */
6707 if (p->type != BNODE) {
6708 dgap_err("IO port only vaild for boards");
6711 s = dgap_getword(in);
6713 dgap_err("unexpected end of file");
6716 p->u.board.portstr = dgap_savestring(s);
6717 p->u.board.port = (short)simple_strtol(s, &s2, 0);
6718 if ((short)strlen(s) > (short)(s2 - s)) {
6719 dgap_err("bad number for IO port");
6722 p->u.board.v_port = 1;
6725 case MEM: /* memory address */
6726 if (p->type != BNODE) {
6727 dgap_err("memory address only vaild for boards");
6730 s = dgap_getword(in);
6732 dgap_err("unexpected end of file");
6735 p->u.board.addrstr = dgap_savestring(s);
6736 p->u.board.addr = simple_strtoul(s, &s2, 0);
6737 if ((int)strlen(s) > (int)(s2 - s)) {
6738 dgap_err("bad number for memory address");
6741 p->u.board.v_addr = 1;
6744 case PCIINFO: /* pci information */
6745 if (p->type != BNODE) {
6746 dgap_err("memory address only vaild for boards");
6749 s = dgap_getword(in);
6751 dgap_err("unexpected end of file");
6754 p->u.board.pcibusstr = dgap_savestring(s);
6755 p->u.board.pcibus = simple_strtoul(s, &s2, 0);
6756 if ((int)strlen(s) > (int)(s2 - s)) {
6757 dgap_err("bad number for pci bus");
6760 p->u.board.v_pcibus = 1;
6761 s = dgap_getword(in);
6763 dgap_err("unexpected end of file");
6766 p->u.board.pcislotstr = dgap_savestring(s);
6767 p->u.board.pcislot = simple_strtoul(s, &s2, 0);
6768 if ((int)strlen(s) > (int)(s2 - s)) {
6769 dgap_err("bad number for pci slot");
6772 p->u.board.v_pcislot = 1;
6776 if (p->type != BNODE) {
6777 dgap_err("install method only vaild for boards");
6780 s = dgap_getword(in);
6782 dgap_err("unexpected end of file");
6785 p->u.board.method = dgap_savestring(s);
6786 p->u.board.v_method = 1;
6790 if (p->type != BNODE) {
6791 dgap_err("config status only vaild for boards");
6794 s = dgap_getword(in);
6796 dgap_err("unexpected end of file");
6799 p->u.board.status = dgap_savestring(s);
6802 case NPORTS: /* number of ports */
6803 if (p->type == BNODE) {
6804 s = dgap_getword(in);
6806 dgap_err("unexpected end of file");
6809 p->u.board.nport = (char)simple_strtol(s, &s2, 0);
6810 if ((int)strlen(s) > (int)(s2 - s)) {
6811 dgap_err("bad number for number of ports");
6814 p->u.board.v_nport = 1;
6815 } else if (p->type == CNODE) {
6816 s = dgap_getword(in);
6818 dgap_err("unexpected end of file");
6821 p->u.conc.nport = (char)simple_strtol(s, &s2, 0);
6822 if ((int)strlen(s) > (int)(s2 - s)) {
6823 dgap_err("bad number for number of ports");
6826 p->u.conc.v_nport = 1;
6827 } else if (p->type == MNODE) {
6828 s = dgap_getword(in);
6830 dgap_err("unexpected end of file");
6833 p->u.module.nport = (char)simple_strtol(s, &s2, 0);
6834 if ((int)strlen(s) > (int)(s2 - s)) {
6835 dgap_err("bad number for number of ports");
6838 p->u.module.v_nport = 1;
6840 dgap_err("nports only valid for concentrators or modules");
6845 case ID: /* letter ID used in tty name */
6846 s = dgap_getword(in);
6848 dgap_err("unexpected end of file");
6852 p->u.board.status = dgap_savestring(s);
6854 if (p->type == CNODE) {
6855 p->u.conc.id = dgap_savestring(s);
6857 } else if (p->type == MNODE) {
6858 p->u.module.id = dgap_savestring(s);
6859 p->u.module.v_id = 1;
6861 dgap_err("id only valid for concentrators or modules");
6866 case STARTO: /* start offset of ID */
6867 if (p->type == BNODE) {
6868 s = dgap_getword(in);
6870 dgap_err("unexpected end of file");
6873 p->u.board.start = simple_strtol(s, &s2, 0);
6874 if ((int)strlen(s) > (int)(s2 - s)) {
6875 dgap_err("bad number for start of tty count");
6878 p->u.board.v_start = 1;
6879 } else if (p->type == CNODE) {
6880 s = dgap_getword(in);
6882 dgap_err("unexpected end of file");
6885 p->u.conc.start = simple_strtol(s, &s2, 0);
6886 if ((int)strlen(s) > (int)(s2 - s)) {
6887 dgap_err("bad number for start of tty count");
6890 p->u.conc.v_start = 1;
6891 } else if (p->type == MNODE) {
6892 s = dgap_getword(in);
6894 dgap_err("unexpected end of file");
6897 p->u.module.start = simple_strtol(s, &s2, 0);
6898 if ((int)strlen(s) > (int)(s2 - s)) {
6899 dgap_err("bad number for start of tty count");
6902 p->u.module.v_start = 1;
6904 dgap_err("start only valid for concentrators or modules");
6909 case TTYN: /* tty name prefix */
6910 if (dgap_checknode(p))
6912 p->next = dgap_newnode(TNODE);
6914 dgap_err("out of memory");
6918 s = dgap_getword(in);
6920 dgap_err("unexpeced end of file");
6923 p->u.ttyname = dgap_savestring(s);
6924 if (!p->u.ttyname) {
6925 dgap_err("out of memory");
6930 case CU: /* cu name prefix */
6931 if (dgap_checknode(p))
6933 p->next = dgap_newnode(CUNODE);
6935 dgap_err("out of memory");
6939 s = dgap_getword(in);
6941 dgap_err("unexpeced end of file");
6944 p->u.cuname = dgap_savestring(s);
6946 dgap_err("out of memory");
6951 case LINE: /* line information */
6952 if (dgap_checknode(p))
6955 dgap_err("must specify board before line info");
6958 switch (brd->u.board.type) {
6960 dgap_err("line not vaild for PC/em");
6963 p->next = dgap_newnode(LNODE);
6965 dgap_err("out of memory");
6974 case CONC: /* concentrator information */
6975 if (dgap_checknode(p))
6978 dgap_err("must specify line info before concentrator");
6981 p->next = dgap_newnode(CNODE);
6983 dgap_err("out of memory");
6989 brd->u.board.conc2++;
6991 brd->u.board.conc1++;
6995 case CX: /* c/x type concentrator */
6996 if (p->type != CNODE) {
6997 dgap_err("cx only valid for concentrators");
7000 p->u.conc.type = CX;
7001 p->u.conc.v_type = 1;
7004 case EPC: /* epc type concentrator */
7005 if (p->type != CNODE) {
7006 dgap_err("cx only valid for concentrators");
7009 p->u.conc.type = EPC;
7010 p->u.conc.v_type = 1;
7013 case MOD: /* EBI module */
7014 if (dgap_checknode(p))
7017 dgap_err("must specify board info before EBI modules");
7020 switch (brd->u.board.type) {
7026 dgap_err("must specify concentrator info before EBI module");
7030 p->next = dgap_newnode(MNODE);
7032 dgap_err("out of memory");
7037 brd->u.board.module2++;
7039 brd->u.board.module1++;
7043 case PORTS: /* ports type EBI module */
7044 if (p->type != MNODE) {
7045 dgap_err("ports only valid for EBI modules");
7048 p->u.module.type = PORTS;
7049 p->u.module.v_type = 1;
7052 case MODEM: /* ports type EBI module */
7053 if (p->type != MNODE) {
7054 dgap_err("modem only valid for modem modules");
7057 p->u.module.type = MODEM;
7058 p->u.module.v_type = 1;
7062 if (p->type == LNODE) {
7063 s = dgap_getword(in);
7065 dgap_err("unexpected end of file");
7068 p->u.line.cable = dgap_savestring(s);
7069 p->u.line.v_cable = 1;
7073 case SPEED: /* sync line speed indication */
7074 if (p->type == LNODE) {
7075 s = dgap_getword(in);
7077 dgap_err("unexpected end of file");
7080 p->u.line.speed = (char)simple_strtol(s, &s2, 0);
7081 if ((short)strlen(s) > (short)(s2 - s)) {
7082 dgap_err("bad number for line speed");
7085 p->u.line.v_speed = 1;
7086 } else if (p->type == CNODE) {
7087 s = dgap_getword(in);
7089 dgap_err("unexpected end of file");
7092 p->u.conc.speed = (char)simple_strtol(s, &s2, 0);
7093 if ((short)strlen(s) > (short)(s2 - s)) {
7094 dgap_err("bad number for line speed");
7097 p->u.conc.v_speed = 1;
7099 dgap_err("speed valid only for lines or concentrators.");
7105 if (p->type == CNODE) {
7106 s = dgap_getword(in);
7108 dgap_err("unexpected end of file");
7111 p->u.conc.connect = dgap_savestring(s);
7112 p->u.conc.v_connect = 1;
7115 case PRINT: /* transparent print name prefix */
7116 if (dgap_checknode(p))
7118 p->next = dgap_newnode(PNODE);
7120 dgap_err("out of memory");
7124 s = dgap_getword(in);
7126 dgap_err("unexpeced end of file");
7129 p->u.printname = dgap_savestring(s);
7130 if (!p->u.printname) {
7131 dgap_err("out of memory");
7136 case CMAJOR: /* major number */
7137 if (dgap_checknode(p))
7139 p->next = dgap_newnode(JNODE);
7141 dgap_err("out of memory");
7145 s = dgap_getword(in);
7147 dgap_err("unexpected end of file");
7150 p->u.majornumber = simple_strtol(s, &s2, 0);
7151 if ((int)strlen(s) > (int)(s2 - s)) {
7152 dgap_err("bad number for major number");
7157 case ALTPIN: /* altpin setting */
7158 if (dgap_checknode(p))
7160 p->next = dgap_newnode(ANODE);
7162 dgap_err("out of memory");
7166 s = dgap_getword(in);
7168 dgap_err("unexpected end of file");
7171 p->u.altpin = simple_strtol(s, &s2, 0);
7172 if ((int)strlen(s) > (int)(s2 - s)) {
7173 dgap_err("bad number for altpin");
7178 case USEINTR: /* enable interrupt setting */
7179 if (dgap_checknode(p))
7181 p->next = dgap_newnode(INTRNODE);
7183 dgap_err("out of memory");
7187 s = dgap_getword(in);
7189 dgap_err("unexpected end of file");
7192 p->u.useintr = simple_strtol(s, &s2, 0);
7193 if ((int)strlen(s) > (int)(s2 - s)) {
7194 dgap_err("bad number for useintr");
7199 case TTSIZ: /* size of tty structure */
7200 if (dgap_checknode(p))
7202 p->next = dgap_newnode(TSNODE);
7204 dgap_err("out of memory");
7208 s = dgap_getword(in);
7210 dgap_err("unexpected end of file");
7213 p->u.ttysize = simple_strtol(s, &s2, 0);
7214 if ((int)strlen(s) > (int)(s2 - s)) {
7215 dgap_err("bad number for ttysize");
7220 case CHSIZ: /* channel structure size */
7221 if (dgap_checknode(p))
7223 p->next = dgap_newnode(CSNODE);
7225 dgap_err("out of memory");
7229 s = dgap_getword(in);
7231 dgap_err("unexpected end of file");
7234 p->u.chsize = simple_strtol(s, &s2, 0);
7235 if ((int)strlen(s) > (int)(s2 - s)) {
7236 dgap_err("bad number for chsize");
7241 case BSSIZ: /* board structure size */
7242 if (dgap_checknode(p))
7244 p->next = dgap_newnode(BSNODE);
7246 dgap_err("out of memory");
7250 s = dgap_getword(in);
7252 dgap_err("unexpected end of file");
7255 p->u.bssize = simple_strtol(s, &s2, 0);
7256 if ((int)strlen(s) > (int)(s2 - s)) {
7257 dgap_err("bad number for bssize");
7262 case UNTSIZ: /* sched structure size */
7263 if (dgap_checknode(p))
7265 p->next = dgap_newnode(USNODE);
7267 dgap_err("out of memory");
7271 s = dgap_getword(in);
7273 dgap_err("unexpected end of file");
7276 p->u.unsize = simple_strtol(s, &s2, 0);
7277 if ((int)strlen(s) > (int)(s2 - s)) {
7278 dgap_err("bad number for schedsize");
7283 case F2SIZ: /* f2200 structure size */
7284 if (dgap_checknode(p))
7286 p->next = dgap_newnode(FSNODE);
7288 dgap_err("out of memory");
7292 s = dgap_getword(in);
7294 dgap_err("unexpected end of file");
7297 p->u.f2size = simple_strtol(s, &s2, 0);
7298 if ((int)strlen(s) > (int)(s2 - s)) {
7299 dgap_err("bad number for f2200size");
7304 case VPSIZ: /* vpix structure size */
7305 if (dgap_checknode(p))
7307 p->next = dgap_newnode(VSNODE);
7309 dgap_err("out of memory");
7313 s = dgap_getword(in);
7315 dgap_err("unexpected end of file");
7318 p->u.vpixsize = simple_strtol(s, &s2, 0);
7319 if ((int)strlen(s) > (int)(s2 - s)) {
7320 dgap_err("bad number for vpixsize");
7329 * dgap_sindex: much like index(), but it looks for a match of any character in
7330 * the group, and returns that position. If the first character is a ^, then
7331 * this will match the first occurrence not in that group.
7333 static char *dgap_sindex(char *string, char *group)
7337 if (!string || !group)
7338 return (char *) NULL;
7340 if (*group == '^') {
7342 for (; *string; string++) {
7343 for (ptr = group; *ptr; ptr++) {
7344 if (*ptr == *string)
7351 for (; *string; string++) {
7352 for (ptr = group; *ptr; ptr++) {
7353 if (*ptr == *string)
7359 return (char *) NULL;
7363 * Get a token from the input file; return 0 if end of file is reached
7365 static int dgap_gettok(char **in, struct cnode *p)
7370 if (strstr(dgap_cword, "boar")) {
7371 w = dgap_getword(in);
7372 snprintf(dgap_cword, MAXCWORD, "%s", w);
7373 for (t = dgap_tlist; t->token != 0; t++) {
7374 if (!strcmp(w, t->string))
7377 dgap_err("board !!type not specified");
7380 while ((w = dgap_getword(in))) {
7381 snprintf(dgap_cword, MAXCWORD, "%s", w);
7382 for (t = dgap_tlist; t->token != 0; t++) {
7383 if (!strcmp(w, t->string))
7392 * get a word from the input stream, also keep track of current line number.
7393 * words are separated by whitespace.
7395 static char *dgap_getword(char **in)
7397 char *ret_ptr = *in;
7399 char *ptr = dgap_sindex(*in, " \t\n");
7401 /* If no word found, return null */
7405 /* Mark new location for our buffer */
7409 /* Eat any extra spaces/tabs/newlines that might be present */
7410 while (*in && **in && ((**in == ' ') ||
7421 * print an error message, giving the line number in the file where
7422 * the error occurred.
7424 static void dgap_err(char *s)
7426 pr_err("dgap: parse: %s\n", s);
7430 * allocate a new configuration node of type t
7432 static struct cnode *dgap_newnode(int t)
7436 n = kmalloc(sizeof(struct cnode), GFP_ATOMIC);
7438 memset((char *)n, 0, sizeof(struct cnode));
7445 * dgap_checknode: see if all the necessary info has been supplied for a node
7446 * before creating the next node.
7448 static int dgap_checknode(struct cnode *p)
7452 if (p->u.board.v_type == 0) {
7453 dgap_err("board type !not specified");
7460 if (p->u.line.v_speed == 0) {
7461 dgap_err("line speed not specified");
7467 if (p->u.conc.v_type == 0) {
7468 dgap_err("concentrator type not specified");
7471 if (p->u.conc.v_speed == 0) {
7472 dgap_err("concentrator line speed not specified");
7475 if (p->u.conc.v_nport == 0) {
7476 dgap_err("number of ports on concentrator not specified");
7479 if (p->u.conc.v_id == 0) {
7480 dgap_err("concentrator id letter not specified");
7486 if (p->u.module.v_type == 0) {
7487 dgap_err("EBI module type not specified");
7490 if (p->u.module.v_nport == 0) {
7491 dgap_err("number of ports on EBI module not specified");
7494 if (p->u.module.v_id == 0) {
7495 dgap_err("EBI module id letter not specified");
7504 * save a string somewhere
7506 static char *dgap_savestring(char *s)
7510 p = kmalloc(strlen(s) + 1, GFP_ATOMIC);
7517 * Given a board pointer, returns whether we should use interrupts or not.
7519 static uint dgap_config_get_useintr(struct board_t *bd)
7521 struct cnode *p = NULL;
7526 for (p = bd->bd_config; p; p = p->next) {
7530 * check for pcxr types.
7532 return p->u.useintr;
7538 /* If not found, then don't turn on interrupts. */
7543 * Given a board pointer, returns whether we turn on altpin or not.
7545 static uint dgap_config_get_altpin(struct board_t *bd)
7547 struct cnode *p = NULL;
7552 for (p = bd->bd_config; p; p = p->next) {
7556 * check for pcxr types.
7564 /* If not found, then don't turn on interrupts. */
7569 * Given a specific type of board, if found, detached link and
7570 * returns the first occurrence in the list.
7572 static struct cnode *dgap_find_config(int type, int bus, int slot)
7574 struct cnode *p, *prev = NULL, *prev2 = NULL, *found = NULL;
7578 while (p->next != NULL) {
7582 if (p->type == BNODE) {
7584 if (p->u.board.type == type) {
7586 if (p->u.board.v_pcibus &&
7587 p->u.board.pcibus != bus)
7589 if (p->u.board.v_pcislot &&
7590 p->u.board.pcislot != slot)
7595 * Keep walking thru the list till we
7596 * find the next board.
7598 while (p->next != NULL) {
7601 if (p->type == BNODE) {
7604 * Mark the end of our 1 board
7610 * Link the "next" board to the
7611 * previous board, effectively
7612 * "unlinking" our board from
7621 * It must be the last board in the list.
7632 * Given a board pointer, walks the config link, counting up
7633 * all ports user specified should be on the board.
7634 * (This does NOT mean they are all actually present right now tho)
7636 static uint dgap_config_get_number_of_ports(struct board_t *bd)
7639 struct cnode *p = NULL;
7644 for (p = bd->bd_config; p; p = p->next) {
7649 * check for pcxr types.
7651 if (p->u.board.type > EPCFE)
7652 count += p->u.board.nport;
7655 count += p->u.conc.nport;
7658 count += p->u.module.nport;
7665 static char *dgap_create_config_string(struct board_t *bd, char *string)
7668 struct cnode *p = NULL;
7669 struct cnode *q = NULL;
7677 for (p = bd->bd_config; p; p = p->next) {
7683 *ptr = p->u.line.speed;
7688 * Because the EPC/con concentrators can have EM modules
7689 * hanging off of them, we have to walk ahead in the
7690 * list and keep adding the number of ports on each EM
7691 * to the config. UGH!
7693 speed = p->u.conc.speed;
7695 if ((q != NULL) && (q->type == MNODE)) {
7696 *ptr = (p->u.conc.nport + 0x80);
7699 while ((q->next != NULL) &&
7700 (q->next->type) == MNODE) {
7702 *ptr = (q->u.module.nport + 0x80);
7707 *ptr = q->u.module.nport;
7710 *ptr = p->u.conc.nport;