2 * Copyright 2003 Digi International (www.digi.com)
3 * Scott H Kilau <Scott_Kilau at digi dot com>
5 * This program is free software; you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published by
7 * the Free Software Foundation; either version 2, or (at your option)
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY, EXPRESS OR IMPLIED; without even the
12 * implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
13 * PURPOSE. See the GNU General Public License for more details.
15 * You should have received a copy of the GNU General Public License
16 * along with this program; if not, write to the Free Software
17 * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
20 * NOTE TO LINUX KERNEL HACKERS: DO NOT REFORMAT THIS CODE!
22 * This is shared code between Digi's CVS archive and the
23 * Linux Kernel sources.
24 * Changing the source just for reformatting needlessly breaks
25 * our CVS diff history.
27 * Send any bug fixes/changes to: Eng.Linux at digi dot com.
33 * In the original out of kernel Digi dgap driver, firmware
34 * loading was done via user land to driver handshaking.
36 * For cards that support a concentrator (port expander),
37 * I believe the concentrator its self told the card which
38 * concentrator is actually attached and then that info
39 * was used to tell user land which concentrator firmware
40 * image was to be downloaded. I think even the BIOS or
41 * FEP images required could change with the connection
42 * of a particular concentrator.
44 * Since I have no access to any of these cards or
45 * concentrators, I cannot put the correct concentrator
46 * firmware file names into the firmware_info structure
47 * as is now done for the BIOS and FEP images.
49 * I think, but am not certain, that the cards supporting
50 * concentrators will function without them. So support
51 * of these cards has been left in this driver.
53 * In order to fully support those cards, they would
54 * either have to be acquired for dissection or maybe
55 * Digi International could provide some assistance.
57 #undef DIGI_CONCENTRATORS_SUPPORTED
59 #include <linux/kernel.h>
60 #include <linux/module.h>
61 #include <linux/pci.h>
62 #include <linux/delay.h> /* For udelay */
63 #include <linux/slab.h>
64 #include <linux/uaccess.h>
65 #include <linux/sched.h>
67 #include <linux/interrupt.h> /* For tasklet and interrupt structs/defines */
68 #include <linux/ctype.h>
69 #include <linux/tty.h>
70 #include <linux/tty_flip.h>
71 #include <linux/serial_reg.h>
72 #include <linux/io.h> /* For read[bwl]/write[bwl] */
74 #include <linux/string.h>
75 #include <linux/device.h>
76 #include <linux/kdev_t.h>
77 #include <linux/firmware.h>
81 #define init_MUTEX(sem) sema_init(sem, 1)
82 #define DECLARE_MUTEX(name) \
83 struct semaphore name = __SEMAPHORE_INITIALIZER(name, 1)
85 MODULE_LICENSE("GPL");
86 MODULE_AUTHOR("Digi International, http://www.digi.com");
87 MODULE_DESCRIPTION("Driver for the Digi International EPCA PCI based product line");
88 MODULE_SUPPORTED_DEVICE("dgap");
90 /**************************************************************************
92 * protos for this file
96 static int dgap_start(void);
97 static void dgap_init_globals(void);
98 static int dgap_found_board(struct pci_dev *pdev, int id);
99 static void dgap_cleanup_board(struct board_t *brd);
100 static void dgap_poll_handler(ulong dummy);
101 static int dgap_init_pci(void);
102 static int dgap_init_one(struct pci_dev *pdev, const struct pci_device_id *ent);
103 static void dgap_remove_one(struct pci_dev *dev);
104 static int dgap_probe1(struct pci_dev *pdev, int card_type);
105 static int dgap_do_remap(struct board_t *brd);
106 static irqreturn_t dgap_intr(int irq, void *voidbrd);
108 /* Our function prototypes */
109 static int dgap_tty_open(struct tty_struct *tty, struct file *file);
110 static void dgap_tty_close(struct tty_struct *tty, struct file *file);
111 static int dgap_block_til_ready(struct tty_struct *tty, struct file *file,
112 struct channel_t *ch);
113 static int dgap_tty_ioctl(struct tty_struct *tty, unsigned int cmd,
115 static int dgap_tty_digigeta(struct tty_struct *tty,
116 struct digi_t __user *retinfo);
117 static int dgap_tty_digiseta(struct tty_struct *tty,
118 struct digi_t __user *new_info);
119 static int dgap_tty_digigetedelay(struct tty_struct *tty, int __user *retinfo);
120 static int dgap_tty_digisetedelay(struct tty_struct *tty, int __user *new_info);
121 static int dgap_tty_write_room(struct tty_struct *tty);
122 static int dgap_tty_chars_in_buffer(struct tty_struct *tty);
123 static void dgap_tty_start(struct tty_struct *tty);
124 static void dgap_tty_stop(struct tty_struct *tty);
125 static void dgap_tty_throttle(struct tty_struct *tty);
126 static void dgap_tty_unthrottle(struct tty_struct *tty);
127 static void dgap_tty_flush_chars(struct tty_struct *tty);
128 static void dgap_tty_flush_buffer(struct tty_struct *tty);
129 static void dgap_tty_hangup(struct tty_struct *tty);
130 static int dgap_wait_for_drain(struct tty_struct *tty);
131 static int dgap_set_modem_info(struct tty_struct *tty, unsigned int command,
132 unsigned int __user *value);
133 static int dgap_get_modem_info(struct channel_t *ch,
134 unsigned int __user *value);
135 static int dgap_tty_digisetcustombaud(struct tty_struct *tty,
136 int __user *new_info);
137 static int dgap_tty_digigetcustombaud(struct tty_struct *tty,
138 int __user *retinfo);
139 static int dgap_tty_tiocmget(struct tty_struct *tty);
140 static int dgap_tty_tiocmset(struct tty_struct *tty, unsigned int set,
142 static int dgap_tty_send_break(struct tty_struct *tty, int msec);
143 static void dgap_tty_wait_until_sent(struct tty_struct *tty, int timeout);
144 static int dgap_tty_write(struct tty_struct *tty, const unsigned char *buf,
146 static void dgap_tty_set_termios(struct tty_struct *tty,
147 struct ktermios *old_termios);
148 static int dgap_tty_put_char(struct tty_struct *tty, unsigned char c);
149 static void dgap_tty_send_xchar(struct tty_struct *tty, char ch);
151 static int dgap_tty_register(struct board_t *brd);
152 static int dgap_tty_init(struct board_t *);
153 static void dgap_tty_uninit(struct board_t *);
154 static void dgap_carrier(struct channel_t *ch);
155 static void dgap_input(struct channel_t *ch);
158 * Our function prototypes from dgap_fep5
160 static void dgap_cmdw_ext(struct channel_t *ch, u16 cmd, u16 word, uint ncmds);
161 static int dgap_event(struct board_t *bd);
163 static void dgap_poll_tasklet(unsigned long data);
164 static void dgap_cmdb(struct channel_t *ch, uchar cmd, uchar byte1,
165 uchar byte2, uint ncmds);
166 static void dgap_cmdw(struct channel_t *ch, uchar cmd, u16 word, uint ncmds);
167 static void dgap_wmove(struct channel_t *ch, char *buf, uint cnt);
168 static int dgap_param(struct tty_struct *tty);
169 static void dgap_parity_scan(struct channel_t *ch, unsigned char *cbuf,
170 unsigned char *fbuf, int *len);
171 static uint dgap_get_custom_baud(struct channel_t *ch);
172 static void dgap_firmware_reset_port(struct channel_t *ch);
175 * Function prototypes from dgap_parse.c.
177 static int dgap_gettok(char **in, struct cnode *p);
178 static char *dgap_getword(char **in);
179 static char *dgap_savestring(char *s);
180 static struct cnode *dgap_newnode(int t);
181 static int dgap_checknode(struct cnode *p);
182 static void dgap_err(char *s);
185 * Function prototypes from dgap_sysfs.h
193 static void dgap_create_ports_sysfiles(struct board_t *bd);
194 static void dgap_remove_ports_sysfiles(struct board_t *bd);
196 static int dgap_create_driver_sysfiles(struct pci_driver *);
197 static void dgap_remove_driver_sysfiles(struct pci_driver *);
199 static void dgap_create_tty_sysfs(struct un_t *un, struct device *c);
200 static void dgap_remove_tty_sysfs(struct device *c);
203 * Function prototypes from dgap_parse.h
205 static int dgap_parsefile(char **in, int Remove);
206 static struct cnode *dgap_find_config(int type, int bus, int slot);
207 static uint dgap_config_get_number_of_ports(struct board_t *bd);
208 static char *dgap_create_config_string(struct board_t *bd, char *string);
209 static uint dgap_config_get_useintr(struct board_t *bd);
210 static uint dgap_config_get_altpin(struct board_t *bd);
212 static int dgap_ms_sleep(ulong ms);
213 static void dgap_do_bios_load(struct board_t *brd, uchar __user *ubios,
215 static void dgap_do_fep_load(struct board_t *brd, uchar __user *ufep, int len);
216 #ifdef DIGI_CONCENTRATORS_SUPPORTED
217 static void dgap_do_conc_load(struct board_t *brd, uchar *uaddr, int len);
219 static int dgap_after_config_loaded(int board);
220 static int dgap_finalize_board_init(struct board_t *brd);
222 static void dgap_get_vpd(struct board_t *brd);
223 static void dgap_do_reset_board(struct board_t *brd);
224 static void dgap_do_wait_for_bios(struct board_t *brd);
225 static void dgap_do_wait_for_fep(struct board_t *brd);
226 static int dgap_tty_register_ports(struct board_t *brd);
227 static int dgap_firmware_load(struct pci_dev *pdev, int card_type);
229 /* Driver unload function */
230 static void dgap_cleanup_module(void);
232 module_exit(dgap_cleanup_module);
235 * File operations permitted on Control/Management major.
237 static const struct file_operations DgapBoardFops = {
238 .owner = THIS_MODULE,
244 static uint dgap_NumBoards;
245 static struct board_t *dgap_Board[MAXBOARDS];
246 static ulong dgap_poll_counter;
247 static char *dgap_config_buf;
248 static int dgap_driver_state = DRIVER_INITIALIZED;
249 DEFINE_SPINLOCK(dgap_dl_lock);
250 static wait_queue_head_t dgap_dl_wait;
251 static int dgap_dl_action;
252 static int dgap_poll_tick = 20; /* Poll interval - 20 ms */
257 static struct class *dgap_class;
259 static struct board_t *dgap_BoardsByMajor[256];
260 static uint dgap_count = 500;
265 DEFINE_SPINLOCK(dgap_poll_lock); /* Poll scheduling lock */
266 static ulong dgap_poll_time; /* Time of next poll */
267 static uint dgap_poll_stop; /* Used to tell poller to stop */
268 static struct timer_list dgap_poll_timer;
273 Card Model Number of Ports Interface
274 ----------------------------------------------------------------
275 Acceleport Xem 4 - 64 (EIA232 & EIA422)
276 Acceleport Xr 4 & 8 (EIA232)
277 Acceleport Xr 920 4 & 8 (EIA232)
278 Acceleport C/X 8 - 128 (EIA232)
279 Acceleport EPC/X 8 - 224 (EIA232)
280 Acceleport Xr/422 4 & 8 (EIA422)
281 Acceleport 2r/920 2 (EIA232)
282 Acceleport 4r/920 4 (EIA232)
283 Acceleport 8r/920 8 (EIA232)
285 IBM 8-Port Asynchronous PCI Adapter (EIA232)
286 IBM 128-Port Asynchronous PCI Adapter (EIA232 & EIA422)
289 static struct pci_device_id dgap_pci_tbl[] = {
290 { DIGI_VID, PCI_DEV_XEM_DID, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0 },
291 { DIGI_VID, PCI_DEV_CX_DID, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 1 },
292 { DIGI_VID, PCI_DEV_CX_IBM_DID, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 2 },
293 { DIGI_VID, PCI_DEV_EPCJ_DID, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 3 },
294 { DIGI_VID, PCI_DEV_920_2_DID, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 4 },
295 { DIGI_VID, PCI_DEV_920_4_DID, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 5 },
296 { DIGI_VID, PCI_DEV_920_8_DID, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 6 },
297 { DIGI_VID, PCI_DEV_XR_DID, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 7 },
298 { DIGI_VID, PCI_DEV_XRJ_DID, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 8 },
299 { DIGI_VID, PCI_DEV_XR_422_DID, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 9 },
300 { DIGI_VID, PCI_DEV_XR_IBM_DID, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 10 },
301 { DIGI_VID, PCI_DEV_XR_SAIP_DID, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 11 },
302 { DIGI_VID, PCI_DEV_XR_BULL_DID, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 12 },
303 { DIGI_VID, PCI_DEV_920_8_HP_DID, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 13 },
304 { DIGI_VID, PCI_DEV_XEM_HP_DID, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 14 },
305 {0,} /* 0 terminated list. */
307 MODULE_DEVICE_TABLE(pci, dgap_pci_tbl);
310 * A generic list of Product names, PCI Vendor ID, and PCI Device ID.
319 static struct board_id dgap_Ids[] = {
320 { PPCM, PCI_DEV_XEM_NAME, 64, (T_PCXM|T_PCLITE|T_PCIBUS) },
321 { PCX, PCI_DEV_CX_NAME, 128, (T_CX|T_PCIBUS) },
322 { PCX, PCI_DEV_CX_IBM_NAME, 128, (T_CX|T_PCIBUS) },
323 { PEPC, PCI_DEV_EPCJ_NAME, 224, (T_EPC|T_PCIBUS) },
324 { APORT2_920P, PCI_DEV_920_2_NAME, 2, (T_PCXR|T_PCLITE|T_PCIBUS) },
325 { APORT4_920P, PCI_DEV_920_4_NAME, 4, (T_PCXR|T_PCLITE|T_PCIBUS) },
326 { APORT8_920P, PCI_DEV_920_8_NAME, 8, (T_PCXR|T_PCLITE|T_PCIBUS) },
327 { PAPORT8, PCI_DEV_XR_NAME, 8, (T_PCXR|T_PCLITE|T_PCIBUS) },
328 { PAPORT8, PCI_DEV_XRJ_NAME, 8, (T_PCXR|T_PCLITE|T_PCIBUS) },
329 { PAPORT8, PCI_DEV_XR_422_NAME, 8, (T_PCXR|T_PCLITE|T_PCIBUS) },
330 { PAPORT8, PCI_DEV_XR_IBM_NAME, 8, (T_PCXR|T_PCLITE|T_PCIBUS) },
331 { PAPORT8, PCI_DEV_XR_SAIP_NAME, 8, (T_PCXR|T_PCLITE|T_PCIBUS) },
332 { PAPORT8, PCI_DEV_XR_BULL_NAME, 8, (T_PCXR|T_PCLITE|T_PCIBUS) },
333 { APORT8_920P, PCI_DEV_920_8_HP_NAME, 8, (T_PCXR|T_PCLITE|T_PCIBUS) },
334 { PPCM, PCI_DEV_XEM_HP_NAME, 64, (T_PCXM|T_PCLITE|T_PCIBUS) },
335 {0,} /* 0 terminated list. */
338 static struct pci_driver dgap_driver = {
340 .probe = dgap_init_one,
341 .id_table = dgap_pci_tbl,
342 .remove = dgap_remove_one,
345 struct firmware_info {
346 uchar *conf_name; /* dgap.conf */
347 uchar *bios_name; /* BIOS filename */
348 uchar *fep_name; /* FEP filename */
349 uchar *con_name; /* Concentrator filename FIXME*/
350 int num; /* sequence number */
354 * Firmware - BIOS, FEP, and CONC filenames
356 static struct firmware_info fw_info[] = {
357 { "dgap/dgap.conf", "dgap/sxbios.bin", "dgap/sxfep.bin", 0, 0 },
358 { "dgap/dgap.conf", "dgap/cxpbios.bin", "dgap/cxpfep.bin", 0, 1 },
359 { "dgap/dgap.conf", "dgap/cxpbios.bin", "dgap/cxpfep.bin", 0, 2 },
360 { "dgap/dgap.conf", "dgap/pcibios.bin", "dgap/pcifep.bin", 0, 3 },
361 { "dgap/dgap.conf", "dgap/xrbios.bin", "dgap/xrfep.bin", 0, 4 },
362 { "dgap/dgap.conf", "dgap/xrbios.bin", "dgap/xrfep.bin", 0, 5 },
363 { "dgap/dgap.conf", "dgap/xrbios.bin", "dgap/xrfep.bin", 0, 6 },
364 { "dgap/dgap.conf", "dgap/xrbios.bin", "dgap/xrfep.bin", 0, 7 },
365 { "dgap/dgap.conf", "dgap/xrbios.bin", "dgap/xrfep.bin", 0, 8 },
366 { "dgap/dgap.conf", "dgap/xrbios.bin", "dgap/xrfep.bin", 0, 9 },
367 { "dgap/dgap.conf", "dgap/xrbios.bin", "dgap/xrfep.bin", 0, 10 },
368 { "dgap/dgap.conf", "dgap/xrbios.bin", "dgap/xrfep.bin", 0, 11 },
369 { "dgap/dgap.conf", "dgap/xrbios.bin", "dgap/xrfep.bin", 0, 12 },
370 { "dgap/dgap.conf", "dgap/xrbios.bin", "dgap/xrfep.bin", 0, 13 },
371 { "dgap/dgap.conf", "dgap/sxbios.bin", "dgap/sxfep.bin", 0, 14 },
375 static char *dgap_driver_state_text[] = {
376 "Driver Initialized",
377 "Driver needs configuration load.",
378 "Driver requested configuration from download daemon.",
383 * Default transparent print information.
385 static struct digi_t dgap_digi_init = {
386 .digi_flags = DIGI_COOK, /* Flags */
387 .digi_maxcps = 100, /* Max CPS */
388 .digi_maxchar = 50, /* Max chars in print queue */
389 .digi_bufsize = 100, /* Printer buffer size */
390 .digi_onlen = 4, /* size of printer on string */
391 .digi_offlen = 4, /* size of printer off string */
392 .digi_onstr = "\033[5i", /* ANSI printer on string ] */
393 .digi_offstr = "\033[4i", /* ANSI printer off string ] */
394 .digi_term = "ansi" /* default terminal type */
398 * Define a local default termios struct. All ports will be created
399 * with this termios initially.
401 * This defines a raw port at 9600 baud, 8 data bits, no parity,
405 static struct ktermios DgapDefaultTermios = {
406 .c_iflag = (DEFAULT_IFLAGS), /* iflags */
407 .c_oflag = (DEFAULT_OFLAGS), /* oflags */
408 .c_cflag = (DEFAULT_CFLAGS), /* cflags */
409 .c_lflag = (DEFAULT_LFLAGS), /* lflags */
414 static const struct tty_operations dgap_tty_ops = {
415 .open = dgap_tty_open,
416 .close = dgap_tty_close,
417 .write = dgap_tty_write,
418 .write_room = dgap_tty_write_room,
419 .flush_buffer = dgap_tty_flush_buffer,
420 .chars_in_buffer = dgap_tty_chars_in_buffer,
421 .flush_chars = dgap_tty_flush_chars,
422 .ioctl = dgap_tty_ioctl,
423 .set_termios = dgap_tty_set_termios,
424 .stop = dgap_tty_stop,
425 .start = dgap_tty_start,
426 .throttle = dgap_tty_throttle,
427 .unthrottle = dgap_tty_unthrottle,
428 .hangup = dgap_tty_hangup,
429 .put_char = dgap_tty_put_char,
430 .tiocmget = dgap_tty_tiocmget,
431 .tiocmset = dgap_tty_tiocmset,
432 .break_ctl = dgap_tty_send_break,
433 .wait_until_sent = dgap_tty_wait_until_sent,
434 .send_xchar = dgap_tty_send_xchar
438 * Our needed internal static variables from dgap_parse.c
440 static struct cnode dgap_head;
442 static char dgap_cword[MAXCWORD];
449 static struct toklist dgap_tlist[] = {
450 { BEGIN, "config_begin" },
451 { END, "config_end" },
453 { PCX, "Digi_AccelePort_C/X_PCI" },
454 { PEPC, "Digi_AccelePort_EPC/X_PCI" },
455 { PPCM, "Digi_AccelePort_Xem_PCI" },
456 { APORT2_920P, "Digi_AccelePort_2r_920_PCI" },
457 { APORT4_920P, "Digi_AccelePort_4r_920_PCI" },
458 { APORT8_920P, "Digi_AccelePort_8r_920_PCI" },
459 { PAPORT4, "Digi_AccelePort_4r_PCI(EIA-232/RS-422)" },
460 { PAPORT8, "Digi_AccelePort_8r_PCI(EIA-232/RS-422)" },
462 { PCIINFO, "pciinfo" },
465 { CONC, "concentrator" },
475 { CONNECT, "connect" },
476 { METHOD, "method" },
477 { STATUS, "status" },
478 { CUSTOM, "Custom" },
484 { NPORTS, "nports" },
489 { ALTPIN, "altpin" },
490 { USEINTR, "useintr" },
491 { TTSIZ, "ttysize" },
493 { BSSIZ, "boardsize" },
494 { UNTSIZ, "schedsize" },
495 { F2SIZ, "f2200size" },
496 { VPSIZ, "vpixsize" },
500 /************************************************************************
502 * Driver load/unload functions
504 ************************************************************************/
509 * Module load. This is where it all starts.
511 static int dgap_init_module(void)
515 pr_info("%s, Digi International Part Number %s\n", DG_NAME, DG_PART);
517 dgap_driver_state = DRIVER_NEED_CONFIG_LOAD;
523 rc = dgap_init_pci();
527 rc = dgap_create_driver_sysfiles(&dgap_driver);
531 dgap_driver_state = DRIVER_READY;
537 dgap_cleanup_module();
541 module_init(dgap_init_module);
546 static int dgap_start(void)
550 struct device *device;
553 * make sure that the globals are
554 * init'd before we do anything else
560 pr_info("For the tools package please visit http://www.digi.com\n");
563 * Register our base character device into the kernel.
567 * Register management/dpa devices
569 rc = register_chrdev(DIGI_DGAP_MAJOR, "dgap", &DgapBoardFops);
573 dgap_class = class_create(THIS_MODULE, "dgap_mgmt");
574 if (IS_ERR(dgap_class)) {
575 rc = PTR_ERR(dgap_class);
579 device = device_create(dgap_class, NULL,
580 MKDEV(DIGI_DGAP_MAJOR, 0),
582 if (IS_ERR(device)) {
583 rc = PTR_ERR(device);
587 /* Start the poller */
588 DGAP_LOCK(dgap_poll_lock, flags);
589 init_timer(&dgap_poll_timer);
590 dgap_poll_timer.function = dgap_poll_handler;
591 dgap_poll_timer.data = 0;
592 dgap_poll_time = jiffies + dgap_jiffies_from_ms(dgap_poll_tick);
593 dgap_poll_timer.expires = dgap_poll_time;
594 DGAP_UNLOCK(dgap_poll_lock, flags);
596 add_timer(&dgap_poll_timer);
598 dgap_driver_state = DRIVER_NEED_CONFIG_LOAD;
603 class_destroy(dgap_class);
605 unregister_chrdev(DIGI_DGAP_MAJOR, "dgap");
610 * Register pci driver, and return how many boards we have.
612 static int dgap_init_pci(void)
614 return pci_register_driver(&dgap_driver);
617 /* returns count (>= 0), or negative on error */
618 static int dgap_init_one(struct pci_dev *pdev, const struct pci_device_id *ent)
622 /* wake up and enable device */
623 rc = pci_enable_device(pdev);
628 rc = dgap_probe1(pdev, ent->driver_data);
631 rc = dgap_firmware_load(pdev, ent->driver_data);
637 static int dgap_probe1(struct pci_dev *pdev, int card_type)
639 return dgap_found_board(pdev, card_type);
642 static void dgap_remove_one(struct pci_dev *dev)
648 * dgap_cleanup_module()
650 * Module unload. This is where it all ends.
652 static void dgap_cleanup_module(void)
657 DGAP_LOCK(dgap_poll_lock, lock_flags);
659 DGAP_UNLOCK(dgap_poll_lock, lock_flags);
661 /* Turn off poller right away. */
662 del_timer_sync(&dgap_poll_timer);
664 dgap_remove_driver_sysfiles(&dgap_driver);
666 device_destroy(dgap_class, MKDEV(DIGI_DGAP_MAJOR, 0));
667 class_destroy(dgap_class);
668 unregister_chrdev(DIGI_DGAP_MAJOR, "dgap");
670 kfree(dgap_config_buf);
672 for (i = 0; i < dgap_NumBoards; ++i) {
673 dgap_remove_ports_sysfiles(dgap_Board[i]);
674 dgap_tty_uninit(dgap_Board[i]);
675 dgap_cleanup_board(dgap_Board[i]);
679 pci_unregister_driver(&dgap_driver);
683 * dgap_cleanup_board()
685 * Free all the memory associated with a board
687 static void dgap_cleanup_board(struct board_t *brd)
691 if (!brd || brd->magic != DGAP_BOARD_MAGIC)
694 if (brd->intr_used && brd->irq)
695 free_irq(brd->irq, brd);
697 tasklet_kill(&brd->helper_tasklet);
699 if (brd->re_map_port) {
700 release_mem_region(brd->membase + 0x200000, 0x200000);
701 iounmap(brd->re_map_port);
702 brd->re_map_port = NULL;
705 if (brd->re_map_membase) {
706 release_mem_region(brd->membase, 0x200000);
707 iounmap(brd->re_map_membase);
708 brd->re_map_membase = NULL;
711 /* Free all allocated channels structs */
712 for (i = 0; i < MAXPORTS ; i++)
713 kfree(brd->channels[i]);
716 kfree(brd->flipflagbuf);
718 dgap_Board[brd->boardnum] = NULL;
726 * A board has been found, init it.
728 static int dgap_found_board(struct pci_dev *pdev, int id)
731 unsigned int pci_irq;
734 /* get the board structure and prep it */
735 brd = kzalloc(sizeof(struct board_t), GFP_KERNEL);
739 dgap_Board[dgap_NumBoards] = brd;
741 /* store the info for the board we've found */
742 brd->magic = DGAP_BOARD_MAGIC;
743 brd->boardnum = dgap_NumBoards;
745 brd->vendor = dgap_pci_tbl[id].vendor;
746 brd->device = dgap_pci_tbl[id].device;
748 brd->pci_bus = pdev->bus->number;
749 brd->pci_slot = PCI_SLOT(pdev->devfn);
750 brd->name = dgap_Ids[id].name;
751 brd->maxports = dgap_Ids[id].maxports;
752 brd->type = dgap_Ids[id].config_type;
753 brd->dpatype = dgap_Ids[id].dpatype;
754 brd->dpastatus = BD_NOFEP;
755 init_waitqueue_head(&brd->state_wait);
757 DGAP_SPINLOCK_INIT(brd->bd_lock);
759 brd->state = BOARD_FOUND;
761 brd->inhibit_poller = FALSE;
762 brd->wait_for_bios = 0;
763 brd->wait_for_fep = 0;
765 for (i = 0; i < MAXPORTS; i++)
766 brd->channels[i] = NULL;
768 /* store which card & revision we have */
769 pci_read_config_word(pdev, PCI_SUBSYSTEM_VENDOR_ID, &brd->subvendor);
770 pci_read_config_word(pdev, PCI_SUBSYSTEM_ID, &brd->subdevice);
771 pci_read_config_byte(pdev, PCI_REVISION_ID, &brd->rev);
776 /* get the PCI Base Address Registers */
778 /* Xr Jupiter and EPC use BAR 2 */
779 if (brd->device == PCI_DEV_XRJ_DID || brd->device == PCI_DEV_EPCJ_DID) {
780 brd->membase = pci_resource_start(pdev, 2);
781 brd->membase_end = pci_resource_end(pdev, 2);
783 /* Everyone else uses BAR 0 */
785 brd->membase = pci_resource_start(pdev, 0);
786 brd->membase_end = pci_resource_end(pdev, 0);
792 if (brd->membase & 1)
798 * On the PCI boards, there is no IO space allocated
799 * The I/O registers will be in the first 3 bytes of the
800 * upper 2MB of the 4MB memory space. The board memory
801 * will be mapped into the low 2MB of the 4MB memory space
803 brd->port = brd->membase + PCI_IO_OFFSET;
804 brd->port_end = brd->port + PCI_IO_SIZE;
807 * Special initialization for non-PLX boards
809 if (brd->device != PCI_DEV_XRJ_DID && brd->device != PCI_DEV_EPCJ_DID) {
812 pci_write_config_byte(pdev, 0x40, 0);
813 pci_write_config_byte(pdev, 0x46, 0);
815 /* Limit burst length to 2 doubleword transactions */
816 pci_write_config_byte(pdev, 0x42, 1);
819 * Enable IO and mem if not already done.
820 * This was needed for support on Itanium.
822 pci_read_config_word(pdev, PCI_COMMAND, &cmd);
823 cmd |= (PCI_COMMAND_IO | PCI_COMMAND_MEMORY);
824 pci_write_config_word(pdev, PCI_COMMAND, cmd);
827 /* init our poll helper tasklet */
828 tasklet_init(&brd->helper_tasklet, dgap_poll_tasklet,
829 (unsigned long) brd);
831 i = dgap_do_remap(brd);
833 brd->state = BOARD_FAILED;
835 brd->state = NEED_RESET;
841 static int dgap_finalize_board_init(struct board_t *brd)
845 if (!brd || brd->magic != DGAP_BOARD_MAGIC)
848 brd->use_interrupts = dgap_config_get_useintr(brd);
851 * Set up our interrupt handler if we are set to do interrupts.
853 if (brd->use_interrupts && brd->irq) {
855 rc = request_irq(brd->irq, dgap_intr, IRQF_SHARED, "DGAP", brd);
868 static int dgap_firmware_load(struct pci_dev *pdev, int card_type)
870 struct board_t *brd = dgap_Board[dgap_NumBoards - 1];
871 const struct firmware *fw;
875 dgap_do_reset_board(brd);
877 if ((fw_info[card_type].conf_name) &&
878 (dgap_driver_state == DRIVER_NEED_CONFIG_LOAD)) {
879 ret = request_firmware(&fw, fw_info[card_type].conf_name,
882 pr_err("dgap: config file %s not found\n",
883 fw_info[card_type].conf_name);
886 if (!dgap_config_buf) {
887 dgap_config_buf = kmalloc(fw->size + 1, GFP_ATOMIC);
888 if (!dgap_config_buf) {
889 release_firmware(fw);
894 memcpy(dgap_config_buf, fw->data, fw->size);
895 release_firmware(fw);
896 dgap_config_buf[fw->size + 1] = '\0';
898 if (dgap_parsefile(&dgap_config_buf, TRUE) != 0)
901 dgap_driver_state = -1;
904 ret = dgap_after_config_loaded(brd->boardnum);
908 * Match this board to a config the user created for us.
911 dgap_find_config(brd->type, brd->pci_bus, brd->pci_slot);
914 * Because the 4 port Xr products share the same PCI ID
915 * as the 8 port Xr products, if we receive a NULL config
916 * back, and this is a PAPORT8 board, retry with a
917 * PAPORT4 attempt as well.
919 if (brd->type == PAPORT8 && !brd->bd_config)
921 dgap_find_config(PAPORT4, brd->pci_bus, brd->pci_slot);
923 if (!brd->bd_config) {
924 pr_err("dgap: No valid configuration found\n");
928 dgap_tty_register(brd);
929 dgap_finalize_board_init(brd);
931 if (fw_info[card_type].bios_name) {
932 ret = request_firmware(&fw, fw_info[card_type].bios_name,
935 pr_err("dgap: bios file %s not found\n",
936 fw_info[card_type].bios_name);
939 dgap_do_bios_load(brd, (char *)fw->data, fw->size);
940 release_firmware(fw);
942 /* Wait for BIOS to test board... */
943 dgap_do_wait_for_bios(brd);
945 if (brd->state != FINISHED_BIOS_LOAD)
949 if (fw_info[card_type].fep_name) {
950 ret = request_firmware(&fw, fw_info[card_type].fep_name,
953 pr_err("dgap: fep file %s not found\n",
954 fw_info[card_type].fep_name);
957 dgap_do_fep_load(brd, (char *)fw->data, fw->size);
958 release_firmware(fw);
960 /* Wait for FEP to load on board... */
961 dgap_do_wait_for_fep(brd);
963 if (brd->state != FINISHED_FEP_LOAD)
967 #ifdef DIGI_CONCENTRATORS_SUPPORTED
969 * If this is a CX or EPCX, we need to see if the firmware
970 * is requesting a concentrator image from us.
972 if ((bd->type == PCX) || (bd->type == PEPC)) {
973 chk_addr = (u16 *) (vaddr + DOWNREQ);
974 /* Nonzero if FEP is requesting concentrator image. */
975 check = readw(chk_addr);
976 vaddr = brd->re_map_membase;
979 if (fw_info[card_type].con_name && check && vaddr) {
980 ret = request_firmware(&fw, fw_info[card_type].con_name,
983 pr_err("dgap: conc file %s not found\n",
984 fw_info[card_type].con_name);
987 /* Put concentrator firmware loading code here */
988 offset = readw((u16 *) (vaddr + DOWNREQ));
989 memcpy_toio(offset, fw->data, fw->size);
991 dgap_do_conc_load(brd, (char *)fw->data, fw->size)
992 release_firmware(fw);
996 * Do tty device initialization.
998 ret = dgap_tty_init(brd);
1000 dgap_tty_uninit(brd);
1004 ret = dgap_tty_register_ports(brd);
1008 brd->state = BOARD_READY;
1009 brd->dpastatus = BD_RUNNING;
1017 static int dgap_do_remap(struct board_t *brd)
1019 if (!brd || brd->magic != DGAP_BOARD_MAGIC)
1022 if (!request_mem_region(brd->membase, 0x200000, "dgap"))
1025 if (!request_mem_region(brd->membase + PCI_IO_OFFSET, 0x200000,
1027 release_mem_region(brd->membase, 0x200000);
1031 brd->re_map_membase = ioremap(brd->membase, 0x200000);
1032 if (!brd->re_map_membase) {
1033 release_mem_region(brd->membase, 0x200000);
1034 release_mem_region(brd->membase + PCI_IO_OFFSET, 0x200000);
1038 brd->re_map_port = ioremap((brd->membase + PCI_IO_OFFSET), 0x200000);
1039 if (!brd->re_map_port) {
1040 release_mem_region(brd->membase, 0x200000);
1041 release_mem_region(brd->membase + PCI_IO_OFFSET, 0x200000);
1042 iounmap(brd->re_map_membase);
1049 /*****************************************************************************
1069 * As each timer expires, it determines (a) whether the "transmit"
1070 * waiter needs to be woken up, and (b) whether the poller needs to
1073 ******************************************************************************/
1075 static void dgap_poll_handler(ulong dummy)
1078 struct board_t *brd;
1079 unsigned long lock_flags;
1082 dgap_poll_counter++;
1085 * Do not start the board state machine until
1086 * driver tells us its up and running, and has
1087 * everything it needs.
1089 if (dgap_driver_state != DRIVER_READY)
1090 goto schedule_poller;
1093 * If we have just 1 board, or the system is not SMP,
1094 * then use the typical old style poller.
1095 * Otherwise, use our new tasklet based poller, which should
1096 * speed things up for multiple boards.
1098 if ((dgap_NumBoards == 1) || (num_online_cpus() <= 1)) {
1099 for (i = 0; i < dgap_NumBoards; i++) {
1101 brd = dgap_Board[i];
1103 if (brd->state == BOARD_FAILED)
1105 if (!brd->intr_running)
1106 /* Call the real board poller directly */
1107 dgap_poll_tasklet((unsigned long) brd);
1111 * Go thru each board, kicking off a
1112 * tasklet for each if needed
1114 for (i = 0; i < dgap_NumBoards; i++) {
1115 brd = dgap_Board[i];
1118 * Attempt to grab the board lock.
1120 * If we can't get it, no big deal, the next poll
1121 * will get it. Basically, I just really don't want
1122 * to spin in here, because I want to kick off my
1123 * tasklets as fast as I can, and then get out the
1126 if (!spin_trylock(&brd->bd_lock))
1130 * If board is in a failed state, don't bother
1131 * scheduling a tasklet
1133 if (brd->state == BOARD_FAILED) {
1134 spin_unlock(&brd->bd_lock);
1138 /* Schedule a poll helper task */
1139 if (!brd->intr_running)
1140 tasklet_schedule(&brd->helper_tasklet);
1143 * Can't do DGAP_UNLOCK here, as we don't have
1144 * lock_flags because we did a trylock above.
1146 spin_unlock(&brd->bd_lock);
1153 * Schedule ourself back at the nominal wakeup interval.
1155 DGAP_LOCK(dgap_poll_lock, lock_flags);
1156 dgap_poll_time += dgap_jiffies_from_ms(dgap_poll_tick);
1158 new_time = dgap_poll_time - jiffies;
1160 if ((ulong) new_time >= 2 * dgap_poll_tick) {
1162 jiffies + dgap_jiffies_from_ms(dgap_poll_tick);
1165 dgap_poll_timer.function = dgap_poll_handler;
1166 dgap_poll_timer.data = 0;
1167 dgap_poll_timer.expires = dgap_poll_time;
1168 DGAP_UNLOCK(dgap_poll_lock, lock_flags);
1170 if (!dgap_poll_stop)
1171 add_timer(&dgap_poll_timer);
1177 * Driver interrupt handler.
1179 static irqreturn_t dgap_intr(int irq, void *voidbrd)
1181 struct board_t *brd = (struct board_t *) voidbrd;
1187 * Check to make sure its for us.
1189 if (brd->magic != DGAP_BOARD_MAGIC)
1195 * Schedule tasklet to run at a better time.
1197 tasklet_schedule(&brd->helper_tasklet);
1202 * dgap_init_globals()
1204 * This is where we initialize the globals from the static insmod
1205 * configuration variables. These are declared near the head of
1208 static void dgap_init_globals(void)
1212 for (i = 0; i < MAXBOARDS; i++)
1213 dgap_Board[i] = NULL;
1215 init_timer(&dgap_poll_timer);
1217 init_waitqueue_head(&dgap_dl_wait);
1221 /************************************************************************
1225 ************************************************************************/
1230 * Put the driver to sleep for x ms's
1232 * Returns 0 if timed out, !0 (showing signal) if interrupted by a signal.
1234 static int dgap_ms_sleep(ulong ms)
1236 current->state = TASK_INTERRUPTIBLE;
1237 schedule_timeout((ms * HZ) / 1000);
1238 return signal_pending(current);
1241 /************************************************************************
1243 * TTY Initialization/Cleanup Functions
1245 ************************************************************************/
1248 * dgap_tty_register()
1250 * Init the tty subsystem for this board.
1252 static int dgap_tty_register(struct board_t *brd)
1256 brd->SerialDriver = alloc_tty_driver(MAXPORTS);
1258 snprintf(brd->SerialName, MAXTTYNAMELEN, "tty_dgap_%d_", brd->boardnum);
1259 brd->SerialDriver->name = brd->SerialName;
1260 brd->SerialDriver->name_base = 0;
1261 brd->SerialDriver->major = 0;
1262 brd->SerialDriver->minor_start = 0;
1263 brd->SerialDriver->type = TTY_DRIVER_TYPE_SERIAL;
1264 brd->SerialDriver->subtype = SERIAL_TYPE_NORMAL;
1265 brd->SerialDriver->init_termios = DgapDefaultTermios;
1266 brd->SerialDriver->driver_name = DRVSTR;
1267 brd->SerialDriver->flags = (TTY_DRIVER_REAL_RAW |
1268 TTY_DRIVER_DYNAMIC_DEV |
1269 TTY_DRIVER_HARDWARE_BREAK);
1271 /* The kernel wants space to store pointers to tty_structs */
1272 brd->SerialDriver->ttys =
1273 kzalloc(MAXPORTS * sizeof(struct tty_struct *), GFP_KERNEL);
1274 if (!brd->SerialDriver->ttys)
1278 * Entry points for driver. Called by the kernel from
1279 * tty_io.c and n_tty.c.
1281 tty_set_operations(brd->SerialDriver, &dgap_tty_ops);
1284 * If we're doing transparent print, we have to do all of the above
1285 * again, separately so we don't get the LD confused about what major
1286 * we are when we get into the dgap_tty_open() routine.
1288 brd->PrintDriver = alloc_tty_driver(MAXPORTS);
1290 snprintf(brd->PrintName, MAXTTYNAMELEN, "pr_dgap_%d_", brd->boardnum);
1291 brd->PrintDriver->name = brd->PrintName;
1292 brd->PrintDriver->name_base = 0;
1293 brd->PrintDriver->major = 0;
1294 brd->PrintDriver->minor_start = 0;
1295 brd->PrintDriver->type = TTY_DRIVER_TYPE_SERIAL;
1296 brd->PrintDriver->subtype = SERIAL_TYPE_NORMAL;
1297 brd->PrintDriver->init_termios = DgapDefaultTermios;
1298 brd->PrintDriver->driver_name = DRVSTR;
1299 brd->PrintDriver->flags = (TTY_DRIVER_REAL_RAW |
1300 TTY_DRIVER_DYNAMIC_DEV |
1301 TTY_DRIVER_HARDWARE_BREAK);
1303 /* The kernel wants space to store pointers to tty_structs */
1304 brd->PrintDriver->ttys =
1305 kzalloc(MAXPORTS * sizeof(struct tty_struct *), GFP_KERNEL);
1306 if (!brd->PrintDriver->ttys)
1310 * Entry points for driver. Called by the kernel from
1311 * tty_io.c and n_tty.c.
1313 tty_set_operations(brd->PrintDriver, &dgap_tty_ops);
1315 if (!brd->dgap_Major_Serial_Registered) {
1316 /* Register tty devices */
1317 rc = tty_register_driver(brd->SerialDriver);
1320 brd->dgap_Major_Serial_Registered = TRUE;
1321 dgap_BoardsByMajor[brd->SerialDriver->major] = brd;
1322 brd->dgap_Serial_Major = brd->SerialDriver->major;
1325 if (!brd->dgap_Major_TransparentPrint_Registered) {
1326 /* Register Transparent Print devices */
1327 rc = tty_register_driver(brd->PrintDriver);
1330 brd->dgap_Major_TransparentPrint_Registered = TRUE;
1331 dgap_BoardsByMajor[brd->PrintDriver->major] = brd;
1332 brd->dgap_TransparentPrint_Major = brd->PrintDriver->major;
1341 * Init the tty subsystem. Called once per board after board has been
1342 * downloaded and init'ed.
1344 static int dgap_tty_init(struct board_t *brd)
1348 uint true_count = 0;
1351 struct channel_t *ch;
1359 * Initialize board structure elements.
1362 vaddr = brd->re_map_membase;
1363 true_count = readw((vaddr + NCHAN));
1365 brd->nasync = dgap_config_get_number_of_ports(brd);
1368 brd->nasync = brd->maxports;
1370 if (brd->nasync > brd->maxports)
1371 brd->nasync = brd->maxports;
1373 if (true_count != brd->nasync) {
1374 if ((brd->type == PPCM) && (true_count == 64)) {
1375 pr_warn("dgap: %s configured for %d ports, has %d ports.\n",
1376 brd->name, brd->nasync, true_count);
1377 pr_warn("dgap: Please make SURE the EBI cable running from the card\n");
1378 pr_warn("dgap: to each EM module is plugged into EBI IN!\n");
1379 } else if ((brd->type == PPCM) && (true_count == 0)) {
1380 pr_warn("dgap: %s configured for %d ports, has %d ports.\n",
1381 brd->name, brd->nasync, true_count);
1382 pr_warn("dgap: Please make SURE the EBI cable running from the card\n");
1383 pr_warn("dgap: to each EM module is plugged into EBI IN!\n");
1385 pr_warn("dgap: %s configured for %d ports, has %d ports.\n",
1386 brd->name, brd->nasync, true_count);
1388 brd->nasync = true_count;
1390 /* If no ports, don't bother going any further */
1392 brd->state = BOARD_FAILED;
1393 brd->dpastatus = BD_NOFEP;
1399 * Allocate channel memory that might not have been allocated
1400 * when the driver was first loaded.
1402 for (i = 0; i < brd->nasync; i++) {
1403 if (!brd->channels[i]) {
1405 kzalloc(sizeof(struct channel_t), GFP_ATOMIC);
1406 if (!brd->channels[i])
1411 ch = brd->channels[0];
1412 vaddr = brd->re_map_membase;
1414 bs = (struct bs_t *) ((ulong) vaddr + CHANBUF);
1415 cm = (struct cm_t *) ((ulong) vaddr + CMDBUF);
1419 /* Set up channel variables */
1420 for (i = 0; i < brd->nasync; i++, ch = brd->channels[i], bs++) {
1422 if (!brd->channels[i])
1425 DGAP_SPINLOCK_INIT(ch->ch_lock);
1427 /* Store all our magic numbers */
1428 ch->magic = DGAP_CHANNEL_MAGIC;
1429 ch->ch_tun.magic = DGAP_UNIT_MAGIC;
1430 ch->ch_tun.un_type = DGAP_SERIAL;
1431 ch->ch_tun.un_ch = ch;
1432 ch->ch_tun.un_dev = i;
1434 ch->ch_pun.magic = DGAP_UNIT_MAGIC;
1435 ch->ch_pun.un_type = DGAP_PRINT;
1436 ch->ch_pun.un_ch = ch;
1437 ch->ch_pun.un_dev = i;
1439 ch->ch_vaddr = vaddr;
1444 ch->ch_digi = dgap_digi_init;
1447 * Set up digi dsr and dcd bits based on altpin flag.
1449 if (dgap_config_get_altpin(brd)) {
1452 ch->ch_digi.digi_flags |= DIGI_ALTPIN;
1455 ch->ch_dsr = DM_DSR;
1458 ch->ch_taddr = vaddr + ((ch->ch_bs->tx_seg) << 4);
1459 ch->ch_raddr = vaddr + ((ch->ch_bs->rx_seg) << 4);
1462 ch->ch_tsize = readw(&(ch->ch_bs->tx_max)) + 1;
1463 ch->ch_rsize = readw(&(ch->ch_bs->rx_max)) + 1;
1467 /* .25 second delay */
1468 ch->ch_close_delay = 250;
1471 * Set queue water marks, interrupt mask,
1472 * and general tty parameters.
1474 tlw = ch->ch_tsize >= 2000 ? ((ch->ch_tsize * 5) / 8) :
1478 dgap_cmdw(ch, STLOW, tlw, 0);
1480 dgap_cmdw(ch, SRLOW, ch->ch_rsize / 2, 0);
1482 dgap_cmdw(ch, SRHIGH, 7 * ch->ch_rsize / 8, 0);
1484 ch->ch_mistat = readb(&(ch->ch_bs->m_stat));
1486 init_waitqueue_head(&ch->ch_flags_wait);
1487 init_waitqueue_head(&ch->ch_tun.un_flags_wait);
1488 init_waitqueue_head(&ch->ch_pun.un_flags_wait);
1489 init_waitqueue_head(&ch->ch_sniff_wait);
1491 /* Turn on all modem interrupts for now */
1492 modem = (DM_CD | DM_DSR | DM_CTS | DM_RI);
1493 writeb(modem, &(ch->ch_bs->m_int));
1496 * Set edelay to 0 if interrupts are turned on,
1497 * otherwise set edelay to the usual 100.
1500 writew(0, &(ch->ch_bs->edelay));
1502 writew(100, &(ch->ch_bs->edelay));
1504 writeb(1, &(ch->ch_bs->idata));
1513 * Uninitialize the TTY portion of this driver. Free all memory and
1516 static void dgap_tty_uninit(struct board_t *brd)
1521 if (brd->dgap_Major_Serial_Registered) {
1522 dgap_BoardsByMajor[brd->SerialDriver->major] = NULL;
1523 brd->dgap_Serial_Major = 0;
1524 for (i = 0; i < brd->nasync; i++) {
1525 tty_port_destroy(&brd->SerialPorts[i]);
1526 dev = brd->channels[i]->ch_tun.un_sysfs;
1527 dgap_remove_tty_sysfs(dev);
1528 tty_unregister_device(brd->SerialDriver, i);
1530 tty_unregister_driver(brd->SerialDriver);
1531 kfree(brd->SerialDriver->ttys);
1532 brd->SerialDriver->ttys = NULL;
1533 put_tty_driver(brd->SerialDriver);
1534 kfree(brd->SerialPorts);
1535 brd->dgap_Major_Serial_Registered = FALSE;
1538 if (brd->dgap_Major_TransparentPrint_Registered) {
1539 dgap_BoardsByMajor[brd->PrintDriver->major] = NULL;
1540 brd->dgap_TransparentPrint_Major = 0;
1541 for (i = 0; i < brd->nasync; i++) {
1542 tty_port_destroy(&brd->PrinterPorts[i]);
1543 dev = brd->channels[i]->ch_pun.un_sysfs;
1544 dgap_remove_tty_sysfs(dev);
1545 tty_unregister_device(brd->PrintDriver, i);
1547 tty_unregister_driver(brd->PrintDriver);
1548 kfree(brd->PrintDriver->ttys);
1549 brd->PrintDriver->ttys = NULL;
1550 put_tty_driver(brd->PrintDriver);
1551 kfree(brd->PrinterPorts);
1552 brd->dgap_Major_TransparentPrint_Registered = FALSE;
1556 #define TMPBUFLEN (1024)
1558 * dgap_sniff - Dump data out to the "sniff" buffer if the
1559 * proc sniff file is opened...
1561 static void dgap_sniff_nowait_nolock(struct channel_t *ch, uchar *text,
1562 uchar *buf, int len)
1570 char tmpbuf[TMPBUFLEN];
1574 /* Leave if sniff not open */
1575 if (!(ch->ch_sniff_flags & SNIFF_OPEN))
1578 do_gettimeofday(&tv);
1580 /* Create our header for data dump */
1581 p += sprintf(p, "<%ld %ld><%s><", tv.tv_sec, tv.tv_usec, text);
1582 tmpbuflen = p - tmpbuf;
1587 for (i = 0; i < len && tmpbuflen < (TMPBUFLEN - 4); i++) {
1588 p += sprintf(p, "%02x ", *buf);
1590 tmpbuflen = p - tmpbuf;
1593 if (tmpbuflen < (TMPBUFLEN - 4)) {
1595 p += sprintf(p - 1, "%s\n", ">");
1597 p += sprintf(p, "%s\n", ">");
1603 nbuf = strlen(tmpbuf);
1607 * Loop while data remains.
1609 while (nbuf > 0 && ch->ch_sniff_buf) {
1611 * Determine the amount of available space left in the
1612 * buffer. If there's none, wait until some appears.
1614 n = (ch->ch_sniff_out - ch->ch_sniff_in - 1) &
1618 * If there is no space left to write to in our sniff
1619 * buffer, we have no choice but to drop the data.
1620 * We *cannot* sleep here waiting for space, because
1621 * this function was probably called by the
1622 * interrupt/timer routines!
1628 * Copy as much data as will fit.
1634 r = SNIFF_MAX - ch->ch_sniff_in;
1637 memcpy(ch->ch_sniff_buf +
1638 ch->ch_sniff_in, p, r);
1641 ch->ch_sniff_in = 0;
1646 memcpy(ch->ch_sniff_buf + ch->ch_sniff_in, p, n);
1648 ch->ch_sniff_in += n;
1653 * Wakeup any thread waiting for data
1655 if (ch->ch_sniff_flags & SNIFF_WAIT_DATA) {
1656 ch->ch_sniff_flags &= ~SNIFF_WAIT_DATA;
1657 wake_up_interruptible(&ch->ch_sniff_wait);
1662 * If the user sent us too much data to push into our tmpbuf,
1663 * we need to keep looping around on all the data.
1665 if (too_much_data) {
1670 } while (too_much_data);
1673 /*=======================================================================
1675 * dgap_input - Process received data.
1677 * ch - Pointer to channel structure.
1679 *=======================================================================*/
1681 static void dgap_input(struct channel_t *ch)
1685 struct tty_struct *tp;
1686 struct tty_ldisc *ld;
1700 if (!ch || ch->magic != DGAP_CHANNEL_MAGIC)
1703 tp = ch->ch_tun.un_tty;
1710 if (!bd || bd->magic != DGAP_BOARD_MAGIC)
1713 DGAP_LOCK(bd->bd_lock, lock_flags);
1714 DGAP_LOCK(ch->ch_lock, lock_flags2);
1717 * Figure the number of characters in the buffer.
1718 * Exit immediately if none.
1721 rmask = ch->ch_rsize - 1;
1723 head = readw(&(bs->rx_head));
1725 tail = readw(&(bs->rx_tail));
1728 data_len = (head - tail) & rmask;
1730 if (data_len == 0) {
1731 writeb(1, &(bs->idata));
1732 DGAP_UNLOCK(ch->ch_lock, lock_flags2);
1733 DGAP_UNLOCK(bd->bd_lock, lock_flags);
1738 * If the device is not open, or CREAD is off, flush
1739 * input data and return immediately.
1741 if ((bd->state != BOARD_READY) || !tp ||
1742 (tp->magic != TTY_MAGIC) ||
1743 !(ch->ch_tun.un_flags & UN_ISOPEN) ||
1744 !(tp->termios.c_cflag & CREAD) ||
1745 (ch->ch_tun.un_flags & UN_CLOSING)) {
1747 writew(head, &(bs->rx_tail));
1748 writeb(1, &(bs->idata));
1749 DGAP_UNLOCK(ch->ch_lock, lock_flags2);
1750 DGAP_UNLOCK(bd->bd_lock, lock_flags);
1755 * If we are throttled, simply don't read any data.
1757 if (ch->ch_flags & CH_RXBLOCK) {
1758 writeb(1, &(bs->idata));
1759 DGAP_UNLOCK(ch->ch_lock, lock_flags2);
1760 DGAP_UNLOCK(bd->bd_lock, lock_flags);
1767 tmpchar = readb(&(bs->orun));
1769 ch->ch_err_overrun++;
1770 writeb(0, &(bs->orun));
1773 /* Decide how much data we can send into the tty layer */
1774 flip_len = TTY_FLIPBUF_SIZE;
1776 /* Chop down the length, if needed */
1777 len = min(data_len, flip_len);
1778 len = min(len, (N_TTY_BUF_SIZE - 1));
1780 ld = tty_ldisc_ref(tp);
1782 #ifdef TTY_DONT_FLIP
1784 * If the DONT_FLIP flag is on, don't flush our buffer, and act
1785 * like the ld doesn't have any space to put the data right now.
1787 if (test_bit(TTY_DONT_FLIP, &tp->flags))
1792 * If we were unable to get a reference to the ld,
1793 * don't flush our buffer, and act like the ld doesn't
1794 * have any space to put the data right now.
1800 * If ld doesn't have a pointer to a receive_buf function,
1801 * flush the data, then act like the ld doesn't have any
1802 * space to put the data right now.
1804 if (!ld->ops->receive_buf) {
1805 writew(head, &(bs->rx_tail));
1811 writeb(1, &(bs->idata));
1812 DGAP_UNLOCK(ch->ch_lock, lock_flags2);
1813 DGAP_UNLOCK(bd->bd_lock, lock_flags);
1815 tty_ldisc_deref(ld);
1819 buf = ch->ch_bd->flipbuf;
1823 * n now contains the most amount of data we can copy,
1824 * bounded either by our buffer size or the amount
1825 * of data the card actually has pending...
1829 s = ((head >= tail) ? head : ch->ch_rsize) - tail;
1835 memcpy_fromio(buf, (char *) ch->ch_raddr + tail, s);
1836 dgap_sniff_nowait_nolock(ch, "USER READ", buf, s);
1842 /* Flip queue if needed */
1846 writew(tail, &(bs->rx_tail));
1847 writeb(1, &(bs->idata));
1848 ch->ch_rxcount += len;
1851 * If we are completely raw, we don't need to go through a lot
1852 * of the tty layers that exist.
1853 * In this case, we take the shortest and fastest route we
1854 * can to relay the data to the user.
1856 * On the other hand, if we are not raw, we need to go through
1857 * the tty layer, which has its API more well defined.
1859 if (I_PARMRK(tp) || I_BRKINT(tp) || I_INPCK(tp)) {
1860 dgap_parity_scan(ch, ch->ch_bd->flipbuf,
1861 ch->ch_bd->flipflagbuf, &len);
1863 len = tty_buffer_request_room(tp->port, len);
1864 tty_insert_flip_string_flags(tp->port, ch->ch_bd->flipbuf,
1865 ch->ch_bd->flipflagbuf, len);
1867 len = tty_buffer_request_room(tp->port, len);
1868 tty_insert_flip_string(tp->port, ch->ch_bd->flipbuf, len);
1871 DGAP_UNLOCK(ch->ch_lock, lock_flags2);
1872 DGAP_UNLOCK(bd->bd_lock, lock_flags);
1874 /* Tell the tty layer its okay to "eat" the data now */
1875 tty_flip_buffer_push(tp->port);
1878 tty_ldisc_deref(ld);
1882 /************************************************************************
1883 * Determines when CARRIER changes state and takes appropriate
1885 ************************************************************************/
1886 static void dgap_carrier(struct channel_t *ch)
1890 int virt_carrier = 0;
1891 int phys_carrier = 0;
1893 if (!ch || ch->magic != DGAP_CHANNEL_MAGIC)
1898 if (!bd || bd->magic != DGAP_BOARD_MAGIC)
1901 /* Make sure altpin is always set correctly */
1902 if (ch->ch_digi.digi_flags & DIGI_ALTPIN) {
1906 ch->ch_dsr = DM_DSR;
1910 if (ch->ch_mistat & D_CD(ch))
1913 if (ch->ch_digi.digi_flags & DIGI_FORCEDCD)
1916 if (ch->ch_c_cflag & CLOCAL)
1920 * Test for a VIRTUAL carrier transition to HIGH.
1922 if (((ch->ch_flags & CH_FCAR) == 0) && (virt_carrier == 1)) {
1925 * When carrier rises, wake any threads waiting
1926 * for carrier in the open routine.
1929 if (waitqueue_active(&(ch->ch_flags_wait)))
1930 wake_up_interruptible(&ch->ch_flags_wait);
1934 * Test for a PHYSICAL carrier transition to HIGH.
1936 if (((ch->ch_flags & CH_CD) == 0) && (phys_carrier == 1)) {
1939 * When carrier rises, wake any threads waiting
1940 * for carrier in the open routine.
1943 if (waitqueue_active(&(ch->ch_flags_wait)))
1944 wake_up_interruptible(&ch->ch_flags_wait);
1948 * Test for a PHYSICAL transition to low, so long as we aren't
1949 * currently ignoring physical transitions (which is what "virtual
1950 * carrier" indicates).
1952 * The transition of the virtual carrier to low really doesn't
1953 * matter... it really only means "ignore carrier state", not
1954 * "make pretend that carrier is there".
1956 if ((virt_carrier == 0) &&
1957 ((ch->ch_flags & CH_CD) != 0) &&
1958 (phys_carrier == 0)) {
1961 * When carrier drops:
1963 * Drop carrier on all open units.
1965 * Flush queues, waking up any task waiting in the
1968 * Send a hangup to the control terminal.
1970 * Enable all select calls.
1972 if (waitqueue_active(&(ch->ch_flags_wait)))
1973 wake_up_interruptible(&ch->ch_flags_wait);
1975 if (ch->ch_tun.un_open_count > 0)
1976 tty_hangup(ch->ch_tun.un_tty);
1978 if (ch->ch_pun.un_open_count > 0)
1979 tty_hangup(ch->ch_pun.un_tty);
1983 * Make sure that our cached values reflect the current reality.
1985 if (virt_carrier == 1)
1986 ch->ch_flags |= CH_FCAR;
1988 ch->ch_flags &= ~CH_FCAR;
1990 if (phys_carrier == 1)
1991 ch->ch_flags |= CH_CD;
1993 ch->ch_flags &= ~CH_CD;
1996 /************************************************************************
1998 * TTY Entry points and helper functions
2000 ************************************************************************/
2006 static int dgap_tty_open(struct tty_struct *tty, struct file *file)
2008 struct board_t *brd;
2009 struct channel_t *ch;
2021 major = MAJOR(tty_devnum(tty));
2022 minor = MINOR(tty_devnum(tty));
2027 /* Get board pointer from our array of majors we have allocated */
2028 brd = dgap_BoardsByMajor[major];
2033 * If board is not yet up to a state of READY, go to
2034 * sleep waiting for it to happen or they cancel the open.
2036 rc = wait_event_interruptible(brd->state_wait,
2037 (brd->state & BOARD_READY));
2042 DGAP_LOCK(brd->bd_lock, lock_flags);
2044 /* The wait above should guarantee this cannot happen */
2045 if (brd->state != BOARD_READY) {
2046 DGAP_UNLOCK(brd->bd_lock, lock_flags);
2050 /* If opened device is greater than our number of ports, bail. */
2051 if (MINOR(tty_devnum(tty)) > brd->nasync) {
2052 DGAP_UNLOCK(brd->bd_lock, lock_flags);
2056 ch = brd->channels[minor];
2058 DGAP_UNLOCK(brd->bd_lock, lock_flags);
2062 /* Grab channel lock */
2063 DGAP_LOCK(ch->ch_lock, lock_flags2);
2065 /* Figure out our type */
2066 if (major == brd->dgap_Serial_Major) {
2067 un = &brd->channels[minor]->ch_tun;
2068 un->un_type = DGAP_SERIAL;
2069 } else if (major == brd->dgap_TransparentPrint_Major) {
2070 un = &brd->channels[minor]->ch_pun;
2071 un->un_type = DGAP_PRINT;
2073 DGAP_UNLOCK(ch->ch_lock, lock_flags2);
2074 DGAP_UNLOCK(brd->bd_lock, lock_flags);
2078 /* Store our unit into driver_data, so we always have it available. */
2079 tty->driver_data = un;
2082 * Error if channel info pointer is NULL.
2086 DGAP_UNLOCK(ch->ch_lock, lock_flags2);
2087 DGAP_UNLOCK(brd->bd_lock, lock_flags);
2094 if (!(un->un_flags & UN_ISOPEN)) {
2095 /* Store important variables. */
2098 /* Maybe do something here to the TTY struct as well? */
2102 * Initialize if neither terminal or printer is open.
2104 if (!((ch->ch_tun.un_flags | ch->ch_pun.un_flags) & UN_ISOPEN)) {
2110 * Flush input queue.
2112 head = readw(&(bs->rx_head));
2113 writew(head, &(bs->rx_tail));
2116 ch->pscan_state = 0;
2117 ch->pscan_savechar = 0;
2119 ch->ch_c_cflag = tty->termios.c_cflag;
2120 ch->ch_c_iflag = tty->termios.c_iflag;
2121 ch->ch_c_oflag = tty->termios.c_oflag;
2122 ch->ch_c_lflag = tty->termios.c_lflag;
2123 ch->ch_startc = tty->termios.c_cc[VSTART];
2124 ch->ch_stopc = tty->termios.c_cc[VSTOP];
2126 /* TODO: flush our TTY struct here? */
2131 * Run param in case we changed anything
2136 * follow protocol for opening port
2139 DGAP_UNLOCK(ch->ch_lock, lock_flags2);
2140 DGAP_UNLOCK(brd->bd_lock, lock_flags);
2142 rc = dgap_block_til_ready(tty, file, ch);
2147 /* No going back now, increment our unit and channel counters */
2148 DGAP_LOCK(ch->ch_lock, lock_flags);
2149 ch->ch_open_count++;
2150 un->un_open_count++;
2151 un->un_flags |= (UN_ISOPEN);
2152 DGAP_UNLOCK(ch->ch_lock, lock_flags);
2158 * dgap_block_til_ready()
2160 * Wait for DCD, if needed.
2162 static int dgap_block_til_ready(struct tty_struct *tty, struct file *file,
2163 struct channel_t *ch)
2166 struct un_t *un = NULL;
2169 int sleep_on_un_flags = 0;
2171 if (!tty || tty->magic != TTY_MAGIC || !file || !ch ||
2172 ch->magic != DGAP_CHANNEL_MAGIC)
2175 un = tty->driver_data;
2176 if (!un || un->magic != DGAP_UNIT_MAGIC)
2179 DGAP_LOCK(ch->ch_lock, lock_flags);
2186 sleep_on_un_flags = 0;
2189 * If board has failed somehow during our sleep,
2192 if (ch->ch_bd->state == BOARD_FAILED) {
2197 /* If tty was hung up, break out of loop and set error. */
2198 if (tty_hung_up_p(file)) {
2204 * If either unit is in the middle of the fragile part of close,
2205 * we just cannot touch the channel safely.
2206 * Go back to sleep, knowing that when the channel can be
2207 * touched safely, the close routine will signal the
2208 * ch_wait_flags to wake us back up.
2210 if (!((ch->ch_tun.un_flags | ch->ch_pun.un_flags) &
2214 * Our conditions to leave cleanly and happily:
2215 * 1) NONBLOCKING on the tty is set.
2217 * 3) DCD (fake or real) is active.
2220 if (file->f_flags & O_NONBLOCK)
2223 if (tty->flags & (1 << TTY_IO_ERROR))
2226 if (ch->ch_flags & CH_CD)
2229 if (ch->ch_flags & CH_FCAR)
2232 sleep_on_un_flags = 1;
2236 * If there is a signal pending, the user probably
2237 * interrupted (ctrl-c) us.
2238 * Leave loop with error set.
2240 if (signal_pending(current)) {
2241 retval = -ERESTARTSYS;
2246 * Store the flags before we let go of channel lock
2248 if (sleep_on_un_flags)
2249 old_flags = ch->ch_tun.un_flags | ch->ch_pun.un_flags;
2251 old_flags = ch->ch_flags;
2254 * Let go of channel lock before calling schedule.
2255 * Our poller will get any FEP events and wake us up when DCD
2256 * eventually goes active.
2259 DGAP_UNLOCK(ch->ch_lock, lock_flags);
2262 * Wait for something in the flags to change
2263 * from the current value.
2265 if (sleep_on_un_flags) {
2266 retval = wait_event_interruptible(un->un_flags_wait,
2267 (old_flags != (ch->ch_tun.un_flags |
2268 ch->ch_pun.un_flags)));
2270 retval = wait_event_interruptible(ch->ch_flags_wait,
2271 (old_flags != ch->ch_flags));
2275 * We got woken up for some reason.
2276 * Before looping around, grab our channel lock.
2278 DGAP_LOCK(ch->ch_lock, lock_flags);
2283 DGAP_UNLOCK(ch->ch_lock, lock_flags);
2294 * Hangup the port. Like a close, but don't wait for output to drain.
2296 static void dgap_tty_hangup(struct tty_struct *tty)
2299 struct channel_t *ch;
2302 if (!tty || tty->magic != TTY_MAGIC)
2305 un = tty->driver_data;
2306 if (!un || un->magic != DGAP_UNIT_MAGIC)
2310 if (!ch || ch->magic != DGAP_CHANNEL_MAGIC)
2314 if (!bd || bd->magic != DGAP_BOARD_MAGIC)
2317 /* flush the transmit queues */
2318 dgap_tty_flush_buffer(tty);
2326 static void dgap_tty_close(struct tty_struct *tty, struct file *file)
2328 struct ktermios *ts;
2330 struct channel_t *ch;
2335 if (!tty || tty->magic != TTY_MAGIC)
2338 un = tty->driver_data;
2339 if (!un || un->magic != DGAP_UNIT_MAGIC)
2343 if (!ch || ch->magic != DGAP_CHANNEL_MAGIC)
2347 if (!bd || bd->magic != DGAP_BOARD_MAGIC)
2352 DGAP_LOCK(ch->ch_lock, lock_flags);
2355 * Determine if this is the last close or not - and if we agree about
2356 * which type of close it is with the Line Discipline
2358 if ((tty->count == 1) && (un->un_open_count != 1)) {
2360 * Uh, oh. tty->count is 1, which means that the tty
2361 * structure will be freed. un_open_count should always
2362 * be one in these conditions. If it's greater than
2363 * one, we've got real problems, since it means the
2364 * serial port won't be shutdown.
2366 un->un_open_count = 1;
2369 if (--un->un_open_count < 0)
2370 un->un_open_count = 0;
2372 ch->ch_open_count--;
2374 if (ch->ch_open_count && un->un_open_count) {
2375 DGAP_UNLOCK(ch->ch_lock, lock_flags);
2379 /* OK, its the last close on the unit */
2381 un->un_flags |= UN_CLOSING;
2386 * Only officially close channel if count is 0 and
2387 * DIGI_PRINTER bit is not set.
2389 if ((ch->ch_open_count == 0) &&
2390 !(ch->ch_digi.digi_flags & DIGI_PRINTER)) {
2392 ch->ch_flags &= ~(CH_RXBLOCK);
2394 DGAP_UNLOCK(ch->ch_lock, lock_flags);
2396 /* wait for output to drain */
2397 /* This will also return if we take an interrupt */
2399 rc = dgap_wait_for_drain(tty);
2401 dgap_tty_flush_buffer(tty);
2402 tty_ldisc_flush(tty);
2404 DGAP_LOCK(ch->ch_lock, lock_flags);
2409 * If we have HUPCL set, lower DTR and RTS
2411 if (ch->ch_c_cflag & HUPCL) {
2412 ch->ch_mostat &= ~(D_RTS(ch)|D_DTR(ch));
2413 dgap_cmdb(ch, SMODEM, 0, D_DTR(ch)|D_RTS(ch), 0);
2416 * Go to sleep to ensure RTS/DTR
2417 * have been dropped for modems to see it.
2419 if (ch->ch_close_delay) {
2420 DGAP_UNLOCK(ch->ch_lock, lock_flags);
2421 dgap_ms_sleep(ch->ch_close_delay);
2422 DGAP_LOCK(ch->ch_lock, lock_flags);
2426 ch->pscan_state = 0;
2427 ch->pscan_savechar = 0;
2428 ch->ch_baud_info = 0;
2433 * turn off print device when closing print device.
2435 if ((un->un_type == DGAP_PRINT) && (ch->ch_flags & CH_PRON)) {
2436 dgap_wmove(ch, ch->ch_digi.digi_offstr,
2437 (int) ch->ch_digi.digi_offlen);
2438 ch->ch_flags &= ~CH_PRON;
2442 un->un_flags &= ~(UN_ISOPEN | UN_CLOSING);
2443 tty->driver_data = NULL;
2445 wake_up_interruptible(&ch->ch_flags_wait);
2446 wake_up_interruptible(&un->un_flags_wait);
2448 DGAP_UNLOCK(ch->ch_lock, lock_flags);
2452 * dgap_tty_chars_in_buffer()
2454 * Return number of characters that have not been transmitted yet.
2456 * This routine is used by the line discipline to determine if there
2457 * is data waiting to be transmitted/drained/flushed or not.
2459 static int dgap_tty_chars_in_buffer(struct tty_struct *tty)
2461 struct board_t *bd = NULL;
2462 struct channel_t *ch = NULL;
2463 struct un_t *un = NULL;
2464 struct bs_t *bs = NULL;
2467 u16 thead, ttail, tmask, chead, ctail;
2468 ulong lock_flags = 0;
2469 ulong lock_flags2 = 0;
2474 un = tty->driver_data;
2475 if (!un || un->magic != DGAP_UNIT_MAGIC)
2479 if (!ch || ch->magic != DGAP_CHANNEL_MAGIC)
2483 if (!bd || bd->magic != DGAP_BOARD_MAGIC)
2490 DGAP_LOCK(bd->bd_lock, lock_flags);
2491 DGAP_LOCK(ch->ch_lock, lock_flags2);
2493 tmask = (ch->ch_tsize - 1);
2495 /* Get Transmit queue pointers */
2496 thead = readw(&(bs->tx_head)) & tmask;
2497 ttail = readw(&(bs->tx_tail)) & tmask;
2499 /* Get tbusy flag */
2500 tbusy = readb(&(bs->tbusy));
2502 /* Get Command queue pointers */
2503 chead = readw(&(ch->ch_cm->cm_head));
2504 ctail = readw(&(ch->ch_cm->cm_tail));
2506 DGAP_UNLOCK(ch->ch_lock, lock_flags2);
2507 DGAP_UNLOCK(bd->bd_lock, lock_flags);
2510 * The only way we know for sure if there is no pending
2511 * data left to be transferred, is if:
2512 * 1) Transmit head and tail are equal (empty).
2513 * 2) Command queue head and tail are equal (empty).
2514 * 3) The "TBUSY" flag is 0. (Transmitter not busy).
2517 if ((ttail == thead) && (tbusy == 0) && (chead == ctail)) {
2521 chars = thead - ttail;
2523 chars = thead - ttail + ch->ch_tsize;
2525 * Fudge factor here.
2526 * If chars is zero, we know that the command queue had
2527 * something in it or tbusy was set. Because we cannot
2528 * be sure if there is still some data to be transmitted,
2529 * lets lie, and tell ld we have 1 byte left.
2533 * If TBUSY is still set, and our tx buffers are empty,
2534 * force the firmware to send me another wakeup after
2535 * TBUSY has been cleared.
2538 DGAP_LOCK(ch->ch_lock, lock_flags);
2539 un->un_flags |= UN_EMPTY;
2540 writeb(1, &(bs->iempty));
2541 DGAP_UNLOCK(ch->ch_lock, lock_flags);
2550 static int dgap_wait_for_drain(struct tty_struct *tty)
2552 struct channel_t *ch;
2557 ulong lock_flags = 0;
2559 if (!tty || tty->magic != TTY_MAGIC)
2562 un = tty->driver_data;
2563 if (!un || un->magic != DGAP_UNIT_MAGIC)
2567 if (!ch || ch->magic != DGAP_CHANNEL_MAGIC)
2576 /* Loop until data is drained */
2577 while (count != 0) {
2579 count = dgap_tty_chars_in_buffer(tty);
2584 /* Set flag waiting for drain */
2585 DGAP_LOCK(ch->ch_lock, lock_flags);
2586 un->un_flags |= UN_EMPTY;
2587 writeb(1, &(bs->iempty));
2588 DGAP_UNLOCK(ch->ch_lock, lock_flags);
2590 /* Go to sleep till we get woken up */
2591 ret = wait_event_interruptible(un->un_flags_wait,
2592 ((un->un_flags & UN_EMPTY) == 0));
2593 /* If ret is non-zero, user ctrl-c'ed us */
2598 DGAP_LOCK(ch->ch_lock, lock_flags);
2599 un->un_flags &= ~(UN_EMPTY);
2600 DGAP_UNLOCK(ch->ch_lock, lock_flags);
2608 * Reduces bytes_available to the max number of characters
2609 * that can be sent currently given the maxcps value, and
2610 * returns the new bytes_available. This only affects printer
2613 static int dgap_maxcps_room(struct tty_struct *tty, int bytes_available)
2615 struct channel_t *ch = NULL;
2616 struct un_t *un = NULL;
2619 return bytes_available;
2621 un = tty->driver_data;
2622 if (!un || un->magic != DGAP_UNIT_MAGIC)
2623 return bytes_available;
2626 if (!ch || ch->magic != DGAP_CHANNEL_MAGIC)
2627 return bytes_available;
2630 * If its not the Transparent print device, return
2631 * the full data amount.
2633 if (un->un_type != DGAP_PRINT)
2634 return bytes_available;
2636 if (ch->ch_digi.digi_maxcps > 0 && ch->ch_digi.digi_bufsize > 0) {
2638 unsigned long current_time = jiffies;
2639 unsigned long buffer_time = current_time +
2640 (HZ * ch->ch_digi.digi_bufsize) /
2641 ch->ch_digi.digi_maxcps;
2643 if (ch->ch_cpstime < current_time) {
2644 /* buffer is empty */
2645 ch->ch_cpstime = current_time; /* reset ch_cpstime */
2646 cps_limit = ch->ch_digi.digi_bufsize;
2647 } else if (ch->ch_cpstime < buffer_time) {
2648 /* still room in the buffer */
2649 cps_limit = ((buffer_time - ch->ch_cpstime) *
2650 ch->ch_digi.digi_maxcps) / HZ;
2652 /* no room in the buffer */
2656 bytes_available = min(cps_limit, bytes_available);
2659 return bytes_available;
2662 static inline void dgap_set_firmware_event(struct un_t *un, unsigned int event)
2664 struct channel_t *ch = NULL;
2665 struct bs_t *bs = NULL;
2667 if (!un || un->magic != DGAP_UNIT_MAGIC)
2670 if (!ch || ch->magic != DGAP_CHANNEL_MAGIC)
2676 if ((event & UN_LOW) != 0) {
2677 if ((un->un_flags & UN_LOW) == 0) {
2678 un->un_flags |= UN_LOW;
2679 writeb(1, &(bs->ilow));
2682 if ((event & UN_LOW) != 0) {
2683 if ((un->un_flags & UN_EMPTY) == 0) {
2684 un->un_flags |= UN_EMPTY;
2685 writeb(1, &(bs->iempty));
2691 * dgap_tty_write_room()
2693 * Return space available in Tx buffer
2695 static int dgap_tty_write_room(struct tty_struct *tty)
2697 struct channel_t *ch = NULL;
2698 struct un_t *un = NULL;
2699 struct bs_t *bs = NULL;
2700 u16 head, tail, tmask;
2702 ulong lock_flags = 0;
2707 un = tty->driver_data;
2708 if (!un || un->magic != DGAP_UNIT_MAGIC)
2712 if (!ch || ch->magic != DGAP_CHANNEL_MAGIC)
2719 DGAP_LOCK(ch->ch_lock, lock_flags);
2721 tmask = ch->ch_tsize - 1;
2722 head = readw(&(bs->tx_head)) & tmask;
2723 tail = readw(&(bs->tx_tail)) & tmask;
2725 ret = tail - head - 1;
2727 ret += ch->ch_tsize;
2729 /* Limit printer to maxcps */
2730 ret = dgap_maxcps_room(tty, ret);
2733 * If we are printer device, leave space for
2734 * possibly both the on and off strings.
2736 if (un->un_type == DGAP_PRINT) {
2737 if (!(ch->ch_flags & CH_PRON))
2738 ret -= ch->ch_digi.digi_onlen;
2739 ret -= ch->ch_digi.digi_offlen;
2741 if (ch->ch_flags & CH_PRON)
2742 ret -= ch->ch_digi.digi_offlen;
2749 * Schedule FEP to wake us up if needed.
2751 * TODO: This might be overkill...
2752 * Do we really need to schedule callbacks from the FEP
2753 * in every case? Can we get smarter based on ret?
2755 dgap_set_firmware_event(un, UN_LOW | UN_EMPTY);
2756 DGAP_UNLOCK(ch->ch_lock, lock_flags);
2762 * dgap_tty_put_char()
2764 * Put a character into ch->ch_buf
2766 * - used by the line discipline for OPOST processing
2768 static int dgap_tty_put_char(struct tty_struct *tty, unsigned char c)
2771 * Simply call tty_write.
2773 dgap_tty_write(tty, &c, 1);
2780 * Take data from the user or kernel and send it out to the FEP.
2781 * In here exists all the Transparent Print magic as well.
2783 static int dgap_tty_write(struct tty_struct *tty, const unsigned char *buf,
2786 struct channel_t *ch = NULL;
2787 struct un_t *un = NULL;
2788 struct bs_t *bs = NULL;
2790 u16 head, tail, tmask, remain;
2791 int bufcount = 0, n = 0;
2798 un = tty->driver_data;
2799 if (!un || un->magic != DGAP_UNIT_MAGIC)
2803 if (!ch || ch->magic != DGAP_CHANNEL_MAGIC)
2814 * Store original amount of characters passed in.
2815 * This helps to figure out if we should ask the FEP
2816 * to send us an event when it has more space available.
2820 DGAP_LOCK(ch->ch_lock, lock_flags);
2822 /* Get our space available for the channel from the board */
2823 tmask = ch->ch_tsize - 1;
2824 head = readw(&(bs->tx_head)) & tmask;
2825 tail = readw(&(bs->tx_tail)) & tmask;
2827 bufcount = tail - head - 1;
2829 bufcount += ch->ch_tsize;
2832 * Limit printer output to maxcps overall, with bursts allowed
2833 * up to bufsize characters.
2835 bufcount = dgap_maxcps_room(tty, bufcount);
2838 * Take minimum of what the user wants to send, and the
2839 * space available in the FEP buffer.
2841 count = min(count, bufcount);
2844 * Bail if no space left.
2847 dgap_set_firmware_event(un, UN_LOW | UN_EMPTY);
2848 DGAP_UNLOCK(ch->ch_lock, lock_flags);
2853 * Output the printer ON string, if we are in terminal mode, but
2854 * need to be in printer mode.
2856 if ((un->un_type == DGAP_PRINT) && !(ch->ch_flags & CH_PRON)) {
2857 dgap_wmove(ch, ch->ch_digi.digi_onstr,
2858 (int) ch->ch_digi.digi_onlen);
2859 head = readw(&(bs->tx_head)) & tmask;
2860 ch->ch_flags |= CH_PRON;
2864 * On the other hand, output the printer OFF string, if we are
2865 * currently in printer mode, but need to output to the terminal.
2867 if ((un->un_type != DGAP_PRINT) && (ch->ch_flags & CH_PRON)) {
2868 dgap_wmove(ch, ch->ch_digi.digi_offstr,
2869 (int) ch->ch_digi.digi_offlen);
2870 head = readw(&(bs->tx_head)) & tmask;
2871 ch->ch_flags &= ~CH_PRON;
2875 * If there is nothing left to copy, or
2876 * I can't handle any more data, leave.
2879 dgap_set_firmware_event(un, UN_LOW | UN_EMPTY);
2880 DGAP_UNLOCK(ch->ch_lock, lock_flags);
2887 * If the write wraps over the top of the circular buffer,
2888 * move the portion up to the wrap point, and reset the
2889 * pointers to the bottom.
2891 remain = ch->ch_tstart + ch->ch_tsize - head;
2895 vaddr = ch->ch_taddr + head;
2897 memcpy_toio(vaddr, (uchar *) buf, remain);
2898 dgap_sniff_nowait_nolock(ch, "USER WRITE", (uchar *) buf,
2901 head = ch->ch_tstart;
2908 * Move rest of data.
2910 vaddr = ch->ch_taddr + head;
2913 memcpy_toio(vaddr, (uchar *) buf, remain);
2914 dgap_sniff_nowait_nolock(ch, "USER WRITE", (uchar *)buf,
2922 ch->ch_txcount += count;
2924 writew(head, &(bs->tx_head));
2927 dgap_set_firmware_event(un, UN_LOW | UN_EMPTY);
2930 * If this is the print device, and the
2931 * printer is still on, we need to turn it
2932 * off before going idle. If the buffer is
2933 * non-empty, wait until it goes empty.
2934 * Otherwise turn it off right now.
2936 if ((un->un_type == DGAP_PRINT) && (ch->ch_flags & CH_PRON)) {
2937 tail = readw(&(bs->tx_tail)) & tmask;
2940 un->un_flags |= UN_EMPTY;
2941 writeb(1, &(bs->iempty));
2943 dgap_wmove(ch, ch->ch_digi.digi_offstr,
2944 (int) ch->ch_digi.digi_offlen);
2945 head = readw(&(bs->tx_head)) & tmask;
2946 ch->ch_flags &= ~CH_PRON;
2950 /* Update printer buffer empty time. */
2951 if ((un->un_type == DGAP_PRINT) && (ch->ch_digi.digi_maxcps > 0)
2952 && (ch->ch_digi.digi_bufsize > 0)) {
2953 ch->ch_cpstime += (HZ * count) / ch->ch_digi.digi_maxcps;
2956 DGAP_UNLOCK(ch->ch_lock, lock_flags);
2962 * Return modem signals to ld.
2964 static int dgap_tty_tiocmget(struct tty_struct *tty)
2966 struct channel_t *ch;
2972 if (!tty || tty->magic != TTY_MAGIC)
2975 un = tty->driver_data;
2976 if (!un || un->magic != DGAP_UNIT_MAGIC)
2980 if (!ch || ch->magic != DGAP_CHANNEL_MAGIC)
2983 DGAP_LOCK(ch->ch_lock, lock_flags);
2985 mstat = readb(&(ch->ch_bs->m_stat));
2986 /* Append any outbound signals that might be pending... */
2987 mstat |= ch->ch_mostat;
2989 DGAP_UNLOCK(ch->ch_lock, lock_flags);
2993 if (mstat & D_DTR(ch))
2994 result |= TIOCM_DTR;
2995 if (mstat & D_RTS(ch))
2996 result |= TIOCM_RTS;
2997 if (mstat & D_CTS(ch))
2998 result |= TIOCM_CTS;
2999 if (mstat & D_DSR(ch))
3000 result |= TIOCM_DSR;
3001 if (mstat & D_RI(ch))
3003 if (mstat & D_CD(ch))
3010 * dgap_tty_tiocmset()
3012 * Set modem signals, called by ld.
3014 static int dgap_tty_tiocmset(struct tty_struct *tty,
3015 unsigned int set, unsigned int clear)
3018 struct channel_t *ch;
3024 if (!tty || tty->magic != TTY_MAGIC)
3027 un = tty->driver_data;
3028 if (!un || un->magic != DGAP_UNIT_MAGIC)
3032 if (!ch || ch->magic != DGAP_CHANNEL_MAGIC)
3036 if (!bd || bd->magic != DGAP_BOARD_MAGIC)
3039 DGAP_LOCK(bd->bd_lock, lock_flags);
3040 DGAP_LOCK(ch->ch_lock, lock_flags2);
3042 if (set & TIOCM_RTS) {
3043 ch->ch_mforce |= D_RTS(ch);
3044 ch->ch_mval |= D_RTS(ch);
3047 if (set & TIOCM_DTR) {
3048 ch->ch_mforce |= D_DTR(ch);
3049 ch->ch_mval |= D_DTR(ch);
3052 if (clear & TIOCM_RTS) {
3053 ch->ch_mforce |= D_RTS(ch);
3054 ch->ch_mval &= ~(D_RTS(ch));
3057 if (clear & TIOCM_DTR) {
3058 ch->ch_mforce |= D_DTR(ch);
3059 ch->ch_mval &= ~(D_DTR(ch));
3064 DGAP_UNLOCK(ch->ch_lock, lock_flags2);
3065 DGAP_UNLOCK(bd->bd_lock, lock_flags);
3071 * dgap_tty_send_break()
3073 * Send a Break, called by ld.
3075 static int dgap_tty_send_break(struct tty_struct *tty, int msec)
3078 struct channel_t *ch;
3084 if (!tty || tty->magic != TTY_MAGIC)
3087 un = tty->driver_data;
3088 if (!un || un->magic != DGAP_UNIT_MAGIC)
3092 if (!ch || ch->magic != DGAP_CHANNEL_MAGIC)
3096 if (!bd || bd->magic != DGAP_BOARD_MAGIC)
3111 DGAP_LOCK(bd->bd_lock, lock_flags);
3112 DGAP_LOCK(ch->ch_lock, lock_flags2);
3114 dgap_cmdw(ch, SBREAK, (u16) SBREAK_TIME, 0);
3116 dgap_cmdw(ch, SBREAK, (u16) msec, 0);
3118 DGAP_UNLOCK(ch->ch_lock, lock_flags2);
3119 DGAP_UNLOCK(bd->bd_lock, lock_flags);
3125 * dgap_tty_wait_until_sent()
3127 * wait until data has been transmitted, called by ld.
3129 static void dgap_tty_wait_until_sent(struct tty_struct *tty, int timeout)
3131 dgap_wait_for_drain(tty);
3137 * send a high priority character, called by ld.
3139 static void dgap_tty_send_xchar(struct tty_struct *tty, char c)
3142 struct channel_t *ch;
3147 if (!tty || tty->magic != TTY_MAGIC)
3150 un = tty->driver_data;
3151 if (!un || un->magic != DGAP_UNIT_MAGIC)
3155 if (!ch || ch->magic != DGAP_CHANNEL_MAGIC)
3159 if (!bd || bd->magic != DGAP_BOARD_MAGIC)
3162 DGAP_LOCK(bd->bd_lock, lock_flags);
3163 DGAP_LOCK(ch->ch_lock, lock_flags2);
3166 * This is technically what we should do.
3167 * However, the NIST tests specifically want
3168 * to see each XON or XOFF character that it
3169 * sends, so lets just send each character
3173 if (c == STOP_CHAR(tty))
3174 dgap_cmdw(ch, RPAUSE, 0, 0);
3175 else if (c == START_CHAR(tty))
3176 dgap_cmdw(ch, RRESUME, 0, 0);
3178 dgap_wmove(ch, &c, 1);
3180 dgap_wmove(ch, &c, 1);
3183 DGAP_UNLOCK(ch->ch_lock, lock_flags2);
3184 DGAP_UNLOCK(bd->bd_lock, lock_flags);
3190 * Return modem signals to ld.
3192 static int dgap_get_modem_info(struct channel_t *ch, unsigned int __user *value)
3199 if (!ch || ch->magic != DGAP_CHANNEL_MAGIC)
3202 DGAP_LOCK(ch->ch_lock, lock_flags);
3204 mstat = readb(&(ch->ch_bs->m_stat));
3205 /* Append any outbound signals that might be pending... */
3206 mstat |= ch->ch_mostat;
3208 DGAP_UNLOCK(ch->ch_lock, lock_flags);
3212 if (mstat & D_DTR(ch))
3213 result |= TIOCM_DTR;
3214 if (mstat & D_RTS(ch))
3215 result |= TIOCM_RTS;
3216 if (mstat & D_CTS(ch))
3217 result |= TIOCM_CTS;
3218 if (mstat & D_DSR(ch))
3219 result |= TIOCM_DSR;
3220 if (mstat & D_RI(ch))
3222 if (mstat & D_CD(ch))
3225 rc = put_user(result, value);
3231 * dgap_set_modem_info()
3233 * Set modem signals, called by ld.
3235 static int dgap_set_modem_info(struct tty_struct *tty, unsigned int command,
3236 unsigned int __user *value)
3239 struct channel_t *ch;
3242 unsigned int arg = 0;
3246 if (!tty || tty->magic != TTY_MAGIC)
3249 un = tty->driver_data;
3250 if (!un || un->magic != DGAP_UNIT_MAGIC)
3254 if (!ch || ch->magic != DGAP_CHANNEL_MAGIC)
3258 if (!bd || bd->magic != DGAP_BOARD_MAGIC)
3261 ret = get_user(arg, value);
3267 if (arg & TIOCM_RTS) {
3268 ch->ch_mforce |= D_RTS(ch);
3269 ch->ch_mval |= D_RTS(ch);
3272 if (arg & TIOCM_DTR) {
3273 ch->ch_mforce |= D_DTR(ch);
3274 ch->ch_mval |= D_DTR(ch);
3280 if (arg & TIOCM_RTS) {
3281 ch->ch_mforce |= D_RTS(ch);
3282 ch->ch_mval &= ~(D_RTS(ch));
3285 if (arg & TIOCM_DTR) {
3286 ch->ch_mforce |= D_DTR(ch);
3287 ch->ch_mval &= ~(D_DTR(ch));
3293 ch->ch_mforce = D_DTR(ch)|D_RTS(ch);
3295 if (arg & TIOCM_RTS)
3296 ch->ch_mval |= D_RTS(ch);
3298 ch->ch_mval &= ~(D_RTS(ch));
3300 if (arg & TIOCM_DTR)
3301 ch->ch_mval |= (D_DTR(ch));
3303 ch->ch_mval &= ~(D_DTR(ch));
3311 DGAP_LOCK(bd->bd_lock, lock_flags);
3312 DGAP_LOCK(ch->ch_lock, lock_flags2);
3316 DGAP_UNLOCK(ch->ch_lock, lock_flags2);
3317 DGAP_UNLOCK(bd->bd_lock, lock_flags);
3323 * dgap_tty_digigeta()
3325 * Ioctl to get the information for ditty.
3330 static int dgap_tty_digigeta(struct tty_struct *tty,
3331 struct digi_t __user *retinfo)
3333 struct channel_t *ch;
3341 if (!tty || tty->magic != TTY_MAGIC)
3344 un = tty->driver_data;
3345 if (!un || un->magic != DGAP_UNIT_MAGIC)
3349 if (!ch || ch->magic != DGAP_CHANNEL_MAGIC)
3352 memset(&tmp, 0, sizeof(tmp));
3354 DGAP_LOCK(ch->ch_lock, lock_flags);
3355 memcpy(&tmp, &ch->ch_digi, sizeof(tmp));
3356 DGAP_UNLOCK(ch->ch_lock, lock_flags);
3358 if (copy_to_user(retinfo, &tmp, sizeof(*retinfo)))
3365 * dgap_tty_digiseta()
3367 * Ioctl to set the information for ditty.
3372 static int dgap_tty_digiseta(struct tty_struct *tty,
3373 struct digi_t __user *new_info)
3376 struct channel_t *ch;
3378 struct digi_t new_digi;
3379 ulong lock_flags = 0;
3380 unsigned long lock_flags2;
3382 if (!tty || tty->magic != TTY_MAGIC)
3385 un = tty->driver_data;
3386 if (!un || un->magic != DGAP_UNIT_MAGIC)
3390 if (!ch || ch->magic != DGAP_CHANNEL_MAGIC)
3394 if (!bd || bd->magic != DGAP_BOARD_MAGIC)
3397 if (copy_from_user(&new_digi, new_info, sizeof(struct digi_t)))
3400 DGAP_LOCK(bd->bd_lock, lock_flags);
3401 DGAP_LOCK(ch->ch_lock, lock_flags2);
3403 memcpy(&ch->ch_digi, &new_digi, sizeof(struct digi_t));
3405 if (ch->ch_digi.digi_maxcps < 1)
3406 ch->ch_digi.digi_maxcps = 1;
3408 if (ch->ch_digi.digi_maxcps > 10000)
3409 ch->ch_digi.digi_maxcps = 10000;
3411 if (ch->ch_digi.digi_bufsize < 10)
3412 ch->ch_digi.digi_bufsize = 10;
3414 if (ch->ch_digi.digi_maxchar < 1)
3415 ch->ch_digi.digi_maxchar = 1;
3417 if (ch->ch_digi.digi_maxchar > ch->ch_digi.digi_bufsize)
3418 ch->ch_digi.digi_maxchar = ch->ch_digi.digi_bufsize;
3420 if (ch->ch_digi.digi_onlen > DIGI_PLEN)
3421 ch->ch_digi.digi_onlen = DIGI_PLEN;
3423 if (ch->ch_digi.digi_offlen > DIGI_PLEN)
3424 ch->ch_digi.digi_offlen = DIGI_PLEN;
3428 DGAP_UNLOCK(ch->ch_lock, lock_flags2);
3429 DGAP_UNLOCK(bd->bd_lock, lock_flags);
3435 * dgap_tty_digigetedelay()
3437 * Ioctl to get the current edelay setting.
3442 static int dgap_tty_digigetedelay(struct tty_struct *tty, int __user *retinfo)
3444 struct channel_t *ch;
3452 if (!tty || tty->magic != TTY_MAGIC)
3455 un = tty->driver_data;
3456 if (!un || un->magic != DGAP_UNIT_MAGIC)
3460 if (!ch || ch->magic != DGAP_CHANNEL_MAGIC)
3463 memset(&tmp, 0, sizeof(tmp));
3465 DGAP_LOCK(ch->ch_lock, lock_flags);
3466 tmp = readw(&(ch->ch_bs->edelay));
3467 DGAP_UNLOCK(ch->ch_lock, lock_flags);
3469 if (copy_to_user(retinfo, &tmp, sizeof(*retinfo)))
3476 * dgap_tty_digisetedelay()
3478 * Ioctl to set the EDELAY setting
3481 static int dgap_tty_digisetedelay(struct tty_struct *tty, int __user *new_info)
3484 struct channel_t *ch;
3490 if (!tty || tty->magic != TTY_MAGIC)
3493 un = tty->driver_data;
3494 if (!un || un->magic != DGAP_UNIT_MAGIC)
3498 if (!ch || ch->magic != DGAP_CHANNEL_MAGIC)
3502 if (!bd || bd->magic != DGAP_BOARD_MAGIC)
3505 if (copy_from_user(&new_digi, new_info, sizeof(int)))
3508 DGAP_LOCK(bd->bd_lock, lock_flags);
3509 DGAP_LOCK(ch->ch_lock, lock_flags2);
3511 writew((u16) new_digi, &(ch->ch_bs->edelay));
3515 DGAP_UNLOCK(ch->ch_lock, lock_flags2);
3516 DGAP_UNLOCK(bd->bd_lock, lock_flags);
3522 * dgap_tty_digigetcustombaud()
3524 * Ioctl to get the current custom baud rate setting.
3526 static int dgap_tty_digigetcustombaud(struct tty_struct *tty,
3527 int __user *retinfo)
3529 struct channel_t *ch;
3537 if (!tty || tty->magic != TTY_MAGIC)
3540 un = tty->driver_data;
3541 if (!un || un->magic != DGAP_UNIT_MAGIC)
3545 if (!ch || ch->magic != DGAP_CHANNEL_MAGIC)
3548 memset(&tmp, 0, sizeof(tmp));
3550 DGAP_LOCK(ch->ch_lock, lock_flags);
3551 tmp = dgap_get_custom_baud(ch);
3552 DGAP_UNLOCK(ch->ch_lock, lock_flags);
3554 if (copy_to_user(retinfo, &tmp, sizeof(*retinfo)))
3561 * dgap_tty_digisetcustombaud()
3563 * Ioctl to set the custom baud rate setting
3565 static int dgap_tty_digisetcustombaud(struct tty_struct *tty,
3566 int __user *new_info)
3569 struct channel_t *ch;
3575 if (!tty || tty->magic != TTY_MAGIC)
3578 un = tty->driver_data;
3579 if (!un || un->magic != DGAP_UNIT_MAGIC)
3583 if (!ch || ch->magic != DGAP_CHANNEL_MAGIC)
3587 if (!bd || bd->magic != DGAP_BOARD_MAGIC)
3591 if (copy_from_user(&new_rate, new_info, sizeof(unsigned int)))
3594 if (bd->bd_flags & BD_FEP5PLUS) {
3596 DGAP_LOCK(bd->bd_lock, lock_flags);
3597 DGAP_LOCK(ch->ch_lock, lock_flags2);
3599 ch->ch_custom_speed = new_rate;
3603 DGAP_UNLOCK(ch->ch_lock, lock_flags2);
3604 DGAP_UNLOCK(bd->bd_lock, lock_flags);
3611 * dgap_set_termios()
3613 static void dgap_tty_set_termios(struct tty_struct *tty,
3614 struct ktermios *old_termios)
3617 struct channel_t *ch;
3619 unsigned long lock_flags;
3620 unsigned long lock_flags2;
3622 if (!tty || tty->magic != TTY_MAGIC)
3625 un = tty->driver_data;
3626 if (!un || un->magic != DGAP_UNIT_MAGIC)
3630 if (!ch || ch->magic != DGAP_CHANNEL_MAGIC)
3634 if (!bd || bd->magic != DGAP_BOARD_MAGIC)
3637 DGAP_LOCK(bd->bd_lock, lock_flags);
3638 DGAP_LOCK(ch->ch_lock, lock_flags2);
3640 ch->ch_c_cflag = tty->termios.c_cflag;
3641 ch->ch_c_iflag = tty->termios.c_iflag;
3642 ch->ch_c_oflag = tty->termios.c_oflag;
3643 ch->ch_c_lflag = tty->termios.c_lflag;
3644 ch->ch_startc = tty->termios.c_cc[VSTART];
3645 ch->ch_stopc = tty->termios.c_cc[VSTOP];
3650 DGAP_UNLOCK(ch->ch_lock, lock_flags2);
3651 DGAP_UNLOCK(bd->bd_lock, lock_flags);
3654 static void dgap_tty_throttle(struct tty_struct *tty)
3657 struct channel_t *ch;
3662 if (!tty || tty->magic != TTY_MAGIC)
3665 un = tty->driver_data;
3666 if (!un || un->magic != DGAP_UNIT_MAGIC)
3670 if (!ch || ch->magic != DGAP_CHANNEL_MAGIC)
3674 if (!bd || bd->magic != DGAP_BOARD_MAGIC)
3677 DGAP_LOCK(bd->bd_lock, lock_flags);
3678 DGAP_LOCK(ch->ch_lock, lock_flags2);
3680 ch->ch_flags |= (CH_RXBLOCK);
3682 dgap_cmdw(ch, RPAUSE, 0, 0);
3685 DGAP_UNLOCK(ch->ch_lock, lock_flags2);
3686 DGAP_UNLOCK(bd->bd_lock, lock_flags);
3690 static void dgap_tty_unthrottle(struct tty_struct *tty)
3693 struct channel_t *ch;
3698 if (!tty || tty->magic != TTY_MAGIC)
3701 un = tty->driver_data;
3702 if (!un || un->magic != DGAP_UNIT_MAGIC)
3706 if (!ch || ch->magic != DGAP_CHANNEL_MAGIC)
3710 if (!bd || bd->magic != DGAP_BOARD_MAGIC)
3713 DGAP_LOCK(bd->bd_lock, lock_flags);
3714 DGAP_LOCK(ch->ch_lock, lock_flags2);
3716 ch->ch_flags &= ~(CH_RXBLOCK);
3719 dgap_cmdw(ch, RRESUME, 0, 0);
3722 DGAP_UNLOCK(ch->ch_lock, lock_flags2);
3723 DGAP_UNLOCK(bd->bd_lock, lock_flags);
3726 static void dgap_tty_start(struct tty_struct *tty)
3729 struct channel_t *ch;
3734 if (!tty || tty->magic != TTY_MAGIC)
3737 un = tty->driver_data;
3738 if (!un || un->magic != DGAP_UNIT_MAGIC)
3742 if (!ch || ch->magic != DGAP_CHANNEL_MAGIC)
3746 if (!bd || bd->magic != DGAP_BOARD_MAGIC)
3749 DGAP_LOCK(bd->bd_lock, lock_flags);
3750 DGAP_LOCK(ch->ch_lock, lock_flags2);
3752 dgap_cmdw(ch, RESUMETX, 0, 0);
3754 DGAP_UNLOCK(ch->ch_lock, lock_flags2);
3755 DGAP_UNLOCK(bd->bd_lock, lock_flags);
3759 static void dgap_tty_stop(struct tty_struct *tty)
3762 struct channel_t *ch;
3767 if (!tty || tty->magic != TTY_MAGIC)
3770 un = tty->driver_data;
3771 if (!un || un->magic != DGAP_UNIT_MAGIC)
3775 if (!ch || ch->magic != DGAP_CHANNEL_MAGIC)
3779 if (!bd || bd->magic != DGAP_BOARD_MAGIC)
3782 DGAP_LOCK(bd->bd_lock, lock_flags);
3783 DGAP_LOCK(ch->ch_lock, lock_flags2);
3785 dgap_cmdw(ch, PAUSETX, 0, 0);
3787 DGAP_UNLOCK(ch->ch_lock, lock_flags2);
3788 DGAP_UNLOCK(bd->bd_lock, lock_flags);
3793 * dgap_tty_flush_chars()
3795 * Flush the cook buffer
3797 * Note to self, and any other poor souls who venture here:
3799 * flush in this case DOES NOT mean dispose of the data.
3800 * instead, it means "stop buffering and send it if you
3801 * haven't already." Just guess how I figured that out... SRW 2-Jun-98
3803 * It is also always called in interrupt context - JAR 8-Sept-99
3805 static void dgap_tty_flush_chars(struct tty_struct *tty)
3808 struct channel_t *ch;
3813 if (!tty || tty->magic != TTY_MAGIC)
3816 un = tty->driver_data;
3817 if (!un || un->magic != DGAP_UNIT_MAGIC)
3821 if (!ch || ch->magic != DGAP_CHANNEL_MAGIC)
3825 if (!bd || bd->magic != DGAP_BOARD_MAGIC)
3828 DGAP_LOCK(bd->bd_lock, lock_flags);
3829 DGAP_LOCK(ch->ch_lock, lock_flags2);
3831 /* TODO: Do something here */
3833 DGAP_UNLOCK(ch->ch_lock, lock_flags2);
3834 DGAP_UNLOCK(bd->bd_lock, lock_flags);
3838 * dgap_tty_flush_buffer()
3840 * Flush Tx buffer (make in == out)
3842 static void dgap_tty_flush_buffer(struct tty_struct *tty)
3845 struct channel_t *ch;
3851 if (!tty || tty->magic != TTY_MAGIC)
3854 un = tty->driver_data;
3855 if (!un || un->magic != DGAP_UNIT_MAGIC)
3859 if (!ch || ch->magic != DGAP_CHANNEL_MAGIC)
3863 if (!bd || bd->magic != DGAP_BOARD_MAGIC)
3866 DGAP_LOCK(bd->bd_lock, lock_flags);
3867 DGAP_LOCK(ch->ch_lock, lock_flags2);
3869 ch->ch_flags &= ~CH_STOP;
3870 head = readw(&(ch->ch_bs->tx_head));
3871 dgap_cmdw(ch, FLUSHTX, (u16) head, 0);
3872 dgap_cmdw(ch, RESUMETX, 0, 0);
3873 if (ch->ch_tun.un_flags & (UN_LOW|UN_EMPTY)) {
3874 ch->ch_tun.un_flags &= ~(UN_LOW|UN_EMPTY);
3875 wake_up_interruptible(&ch->ch_tun.un_flags_wait);
3877 if (ch->ch_pun.un_flags & (UN_LOW|UN_EMPTY)) {
3878 ch->ch_pun.un_flags &= ~(UN_LOW|UN_EMPTY);
3879 wake_up_interruptible(&ch->ch_pun.un_flags_wait);
3882 DGAP_UNLOCK(ch->ch_lock, lock_flags2);
3883 DGAP_UNLOCK(bd->bd_lock, lock_flags);
3884 if (waitqueue_active(&tty->write_wait))
3885 wake_up_interruptible(&tty->write_wait);
3889 /*****************************************************************************
3891 * The IOCTL function and all of its helpers
3893 *****************************************************************************/
3898 * The usual assortment of ioctl's
3900 static int dgap_tty_ioctl(struct tty_struct *tty, unsigned int cmd,
3904 struct channel_t *ch;
3908 ulong lock_flags = 0;
3909 ulong lock_flags2 = 0;
3910 void __user *uarg = (void __user *) arg;
3912 if (!tty || tty->magic != TTY_MAGIC)
3915 un = tty->driver_data;
3916 if (!un || un->magic != DGAP_UNIT_MAGIC)
3920 if (!ch || ch->magic != DGAP_CHANNEL_MAGIC)
3924 if (!bd || bd->magic != DGAP_BOARD_MAGIC)
3927 DGAP_LOCK(bd->bd_lock, lock_flags);
3928 DGAP_LOCK(ch->ch_lock, lock_flags2);
3930 if (un->un_open_count <= 0) {
3931 DGAP_UNLOCK(ch->ch_lock, lock_flags2);
3932 DGAP_UNLOCK(bd->bd_lock, lock_flags);
3938 /* Here are all the standard ioctl's that we MUST implement */
3942 * TCSBRK is SVID version: non-zero arg --> no break
3943 * this behaviour is exploited by tcdrain().
3945 * According to POSIX.1 spec (7.2.2.1.2) breaks should be
3946 * between 0.25 and 0.5 seconds so we'll ask for something
3947 * in the middle: 0.375 seconds.
3949 rc = tty_check_change(tty);
3950 DGAP_UNLOCK(ch->ch_lock, lock_flags2);
3951 DGAP_UNLOCK(bd->bd_lock, lock_flags);
3955 rc = dgap_wait_for_drain(tty);
3960 DGAP_LOCK(bd->bd_lock, lock_flags);
3961 DGAP_LOCK(ch->ch_lock, lock_flags2);
3963 if (((cmd == TCSBRK) && (!arg)) || (cmd == TCSBRKP))
3964 dgap_cmdw(ch, SBREAK, (u16) SBREAK_TIME, 0);
3966 DGAP_UNLOCK(ch->ch_lock, lock_flags2);
3967 DGAP_UNLOCK(bd->bd_lock, lock_flags);
3972 /* support for POSIX tcsendbreak()
3974 * According to POSIX.1 spec (7.2.2.1.2) breaks should be
3975 * between 0.25 and 0.5 seconds so we'll ask for something
3976 * in the middle: 0.375 seconds.
3978 rc = tty_check_change(tty);
3979 DGAP_UNLOCK(ch->ch_lock, lock_flags2);
3980 DGAP_UNLOCK(bd->bd_lock, lock_flags);
3984 rc = dgap_wait_for_drain(tty);
3988 DGAP_LOCK(bd->bd_lock, lock_flags);
3989 DGAP_LOCK(ch->ch_lock, lock_flags2);
3991 dgap_cmdw(ch, SBREAK, (u16) SBREAK_TIME, 0);
3993 DGAP_UNLOCK(ch->ch_lock, lock_flags2);
3994 DGAP_UNLOCK(bd->bd_lock, lock_flags);
4000 * FEP5 doesn't support turning on a break unconditionally.
4001 * The FEP5 device will stop sending a break automatically
4002 * after the specified time value that was sent when turning on
4005 rc = tty_check_change(tty);
4006 DGAP_UNLOCK(ch->ch_lock, lock_flags2);
4007 DGAP_UNLOCK(bd->bd_lock, lock_flags);
4011 rc = dgap_wait_for_drain(tty);
4015 DGAP_LOCK(bd->bd_lock, lock_flags);
4016 DGAP_LOCK(ch->ch_lock, lock_flags2);
4018 dgap_cmdw(ch, SBREAK, (u16) SBREAK_TIME, 0);
4020 DGAP_UNLOCK(ch->ch_lock, lock_flags2);
4021 DGAP_UNLOCK(bd->bd_lock, lock_flags);
4027 * FEP5 doesn't support turning off a break unconditionally.
4028 * The FEP5 device will stop sending a break automatically
4029 * after the specified time value that was sent when turning on
4032 DGAP_UNLOCK(ch->ch_lock, lock_flags2);
4033 DGAP_UNLOCK(bd->bd_lock, lock_flags);
4038 DGAP_UNLOCK(ch->ch_lock, lock_flags2);
4039 DGAP_UNLOCK(bd->bd_lock, lock_flags);
4041 rc = put_user(C_CLOCAL(tty) ? 1 : 0,
4042 (unsigned long __user *) arg);
4046 DGAP_UNLOCK(ch->ch_lock, lock_flags2);
4047 DGAP_UNLOCK(bd->bd_lock, lock_flags);
4049 rc = get_user(arg, (unsigned long __user *) arg);
4053 DGAP_LOCK(bd->bd_lock, lock_flags);
4054 DGAP_LOCK(ch->ch_lock, lock_flags2);
4055 tty->termios.c_cflag = ((tty->termios.c_cflag & ~CLOCAL) |
4056 (arg ? CLOCAL : 0));
4058 DGAP_UNLOCK(ch->ch_lock, lock_flags2);
4059 DGAP_UNLOCK(bd->bd_lock, lock_flags);
4064 DGAP_UNLOCK(ch->ch_lock, lock_flags2);
4065 DGAP_UNLOCK(bd->bd_lock, lock_flags);
4066 return dgap_get_modem_info(ch, uarg);
4071 DGAP_UNLOCK(ch->ch_lock, lock_flags2);
4072 DGAP_UNLOCK(bd->bd_lock, lock_flags);
4073 return dgap_set_modem_info(tty, cmd, uarg);
4076 * Here are any additional ioctl's that we want to implement
4081 * The linux tty driver doesn't have a flush
4082 * input routine for the driver, assuming all backed
4083 * up data is in the line disc. buffers. However,
4084 * we all know that's not the case. Here, we
4085 * act on the ioctl, but then lie and say we didn't
4086 * so the line discipline will process the flush
4089 rc = tty_check_change(tty);
4091 DGAP_UNLOCK(ch->ch_lock, lock_flags2);
4092 DGAP_UNLOCK(bd->bd_lock, lock_flags);
4096 if ((arg == TCIFLUSH) || (arg == TCIOFLUSH)) {
4097 if (!(un->un_type == DGAP_PRINT)) {
4098 head = readw(&(ch->ch_bs->rx_head));
4099 writew(head, &(ch->ch_bs->rx_tail));
4100 writeb(0, &(ch->ch_bs->orun));
4104 if ((arg != TCOFLUSH) && (arg != TCIOFLUSH)) {
4105 /* pretend we didn't recognize this IOCTL */
4106 DGAP_UNLOCK(ch->ch_lock, lock_flags2);
4107 DGAP_UNLOCK(bd->bd_lock, lock_flags);
4109 return -ENOIOCTLCMD;
4112 ch->ch_flags &= ~CH_STOP;
4113 head = readw(&(ch->ch_bs->tx_head));
4114 dgap_cmdw(ch, FLUSHTX, (u16) head, 0);
4115 dgap_cmdw(ch, RESUMETX, 0, 0);
4116 if (ch->ch_tun.un_flags & (UN_LOW|UN_EMPTY)) {
4117 ch->ch_tun.un_flags &= ~(UN_LOW|UN_EMPTY);
4118 wake_up_interruptible(&ch->ch_tun.un_flags_wait);
4120 if (ch->ch_pun.un_flags & (UN_LOW|UN_EMPTY)) {
4121 ch->ch_pun.un_flags &= ~(UN_LOW|UN_EMPTY);
4122 wake_up_interruptible(&ch->ch_pun.un_flags_wait);
4124 if (waitqueue_active(&tty->write_wait))
4125 wake_up_interruptible(&tty->write_wait);
4127 /* Can't hold any locks when calling tty_wakeup! */
4128 DGAP_UNLOCK(ch->ch_lock, lock_flags2);
4129 DGAP_UNLOCK(bd->bd_lock, lock_flags);
4132 /* pretend we didn't recognize this IOCTL */
4133 return -ENOIOCTLCMD;
4138 * The linux tty driver doesn't have a flush
4139 * input routine for the driver, assuming all backed
4140 * up data is in the line disc. buffers. However,
4141 * we all know that's not the case. Here, we
4142 * act on the ioctl, but then lie and say we didn't
4143 * so the line discipline will process the flush
4146 if (cmd == TCSETSF) {
4148 ch->ch_flags &= ~CH_STOP;
4149 head = readw(&(ch->ch_bs->rx_head));
4150 writew(head, &(ch->ch_bs->rx_tail));
4153 /* now wait for all the output to drain */
4154 DGAP_UNLOCK(ch->ch_lock, lock_flags2);
4155 DGAP_UNLOCK(bd->bd_lock, lock_flags);
4156 rc = dgap_wait_for_drain(tty);
4160 /* pretend we didn't recognize this */
4161 return -ENOIOCTLCMD;
4165 DGAP_UNLOCK(ch->ch_lock, lock_flags2);
4166 DGAP_UNLOCK(bd->bd_lock, lock_flags);
4167 rc = dgap_wait_for_drain(tty);
4171 /* pretend we didn't recognize this */
4172 return -ENOIOCTLCMD;
4176 * The Linux Line Discipline (LD) would do this for us if we
4177 * let it, but we have the special firmware options to do this
4178 * the "right way" regardless of hardware or software flow
4179 * control so we'll do it outselves instead of letting the LD
4182 rc = tty_check_change(tty);
4184 DGAP_UNLOCK(ch->ch_lock, lock_flags2);
4185 DGAP_UNLOCK(bd->bd_lock, lock_flags);
4192 DGAP_UNLOCK(ch->ch_lock, lock_flags2);
4193 DGAP_UNLOCK(bd->bd_lock, lock_flags);
4194 dgap_tty_start(tty);
4197 DGAP_UNLOCK(ch->ch_lock, lock_flags2);
4198 DGAP_UNLOCK(bd->bd_lock, lock_flags);
4202 DGAP_UNLOCK(ch->ch_lock, lock_flags2);
4203 DGAP_UNLOCK(bd->bd_lock, lock_flags);
4204 /* Make the ld do it */
4205 return -ENOIOCTLCMD;
4207 DGAP_UNLOCK(ch->ch_lock, lock_flags2);
4208 DGAP_UNLOCK(bd->bd_lock, lock_flags);
4209 /* Make the ld do it */
4210 return -ENOIOCTLCMD;
4212 DGAP_UNLOCK(ch->ch_lock, lock_flags2);
4213 DGAP_UNLOCK(bd->bd_lock, lock_flags);
4218 /* get information for ditty */
4219 DGAP_UNLOCK(ch->ch_lock, lock_flags2);
4220 DGAP_UNLOCK(bd->bd_lock, lock_flags);
4221 return dgap_tty_digigeta(tty, uarg);
4226 /* set information for ditty */
4227 if (cmd == (DIGI_SETAW)) {
4229 DGAP_UNLOCK(ch->ch_lock, lock_flags2);
4230 DGAP_UNLOCK(bd->bd_lock, lock_flags);
4231 rc = dgap_wait_for_drain(tty);
4234 DGAP_LOCK(bd->bd_lock, lock_flags);
4235 DGAP_LOCK(ch->ch_lock, lock_flags2);
4237 tty_ldisc_flush(tty);
4241 DGAP_UNLOCK(ch->ch_lock, lock_flags2);
4242 DGAP_UNLOCK(bd->bd_lock, lock_flags);
4243 return dgap_tty_digiseta(tty, uarg);
4246 DGAP_UNLOCK(ch->ch_lock, lock_flags2);
4247 DGAP_UNLOCK(bd->bd_lock, lock_flags);
4248 return dgap_tty_digigetedelay(tty, uarg);
4251 DGAP_UNLOCK(ch->ch_lock, lock_flags2);
4252 DGAP_UNLOCK(bd->bd_lock, lock_flags);
4253 return dgap_tty_digisetedelay(tty, uarg);
4255 case DIGI_GETCUSTOMBAUD:
4256 DGAP_UNLOCK(ch->ch_lock, lock_flags2);
4257 DGAP_UNLOCK(bd->bd_lock, lock_flags);
4258 return dgap_tty_digigetcustombaud(tty, uarg);
4260 case DIGI_SETCUSTOMBAUD:
4261 DGAP_UNLOCK(ch->ch_lock, lock_flags2);
4262 DGAP_UNLOCK(bd->bd_lock, lock_flags);
4263 return dgap_tty_digisetcustombaud(tty, uarg);
4265 case DIGI_RESET_PORT:
4266 dgap_firmware_reset_port(ch);
4268 DGAP_UNLOCK(ch->ch_lock, lock_flags2);
4269 DGAP_UNLOCK(bd->bd_lock, lock_flags);
4273 DGAP_UNLOCK(ch->ch_lock, lock_flags2);
4274 DGAP_UNLOCK(bd->bd_lock, lock_flags);
4276 return -ENOIOCTLCMD;
4280 static int dgap_after_config_loaded(int board)
4283 * Initialize KME waitqueues...
4285 init_waitqueue_head(&(dgap_Board[board]->kme_wait));
4288 * allocate flip buffer for board.
4290 dgap_Board[board]->flipbuf = kmalloc(MYFLIPLEN, GFP_ATOMIC);
4291 if (!dgap_Board[board]->flipbuf)
4294 dgap_Board[board]->flipflagbuf = kmalloc(MYFLIPLEN, GFP_ATOMIC);
4295 if (!dgap_Board[board]->flipflagbuf) {
4296 kfree(dgap_Board[board]->flipbuf);
4304 * Create pr and tty device entries
4306 static int dgap_tty_register_ports(struct board_t *brd)
4308 struct channel_t *ch;
4311 brd->SerialPorts = kcalloc(brd->nasync, sizeof(*brd->SerialPorts),
4313 if (brd->SerialPorts == NULL)
4315 for (i = 0; i < brd->nasync; i++)
4316 tty_port_init(&brd->SerialPorts[i]);
4318 brd->PrinterPorts = kcalloc(brd->nasync, sizeof(*brd->PrinterPorts),
4320 if (brd->PrinterPorts == NULL) {
4321 kfree(brd->SerialPorts);
4324 for (i = 0; i < brd->nasync; i++)
4325 tty_port_init(&brd->PrinterPorts[i]);
4327 ch = brd->channels[0];
4328 for (i = 0; i < brd->nasync; i++, ch = brd->channels[i]) {
4330 struct device *classp;
4332 classp = tty_port_register_device(&brd->SerialPorts[i],
4334 brd->firstminor + i, NULL);
4336 dgap_create_tty_sysfs(&ch->ch_tun, classp);
4337 ch->ch_tun.un_sysfs = classp;
4339 classp = tty_port_register_device(&brd->PrinterPorts[i],
4341 brd->firstminor + i, NULL);
4343 dgap_create_tty_sysfs(&ch->ch_pun, classp);
4344 ch->ch_pun.un_sysfs = classp;
4346 dgap_create_ports_sysfiles(brd);
4352 * Copies the BIOS code from the user to the board,
4353 * and starts the BIOS running.
4355 static void dgap_do_bios_load(struct board_t *brd, uchar __user *ubios, int len)
4361 if (!brd || (brd->magic != DGAP_BOARD_MAGIC) || !brd->re_map_membase)
4364 addr = brd->re_map_membase;
4369 for (i = 0; i < 16; i++)
4370 writeb(0, addr + POSTAREA + i);
4376 memcpy_toio(addr + offset, ubios, len);
4378 writel(0x0bf00401, addr);
4379 writel(0, (addr + 4));
4381 /* Clear the reset, and change states. */
4382 writeb(FEPCLR, brd->re_map_port);
4386 * Checks to see if the BIOS completed running on the card.
4388 static void dgap_do_wait_for_bios(struct board_t *brd)
4395 if (!brd || (brd->magic != DGAP_BOARD_MAGIC) || !brd->re_map_membase)
4398 addr = brd->re_map_membase;
4399 word = readw(addr + POSTAREA);
4402 * It can take 5-6 seconds for a board to
4403 * pass the bios self test and post results.
4404 * Give it 10 seconds.
4406 brd->wait_for_bios = 0;
4407 while (brd->wait_for_bios < 1000) {
4408 /* Check to see if BIOS thinks board is good. (GD). */
4409 if (word == *(u16 *) "GD") {
4410 brd->state = FINISHED_BIOS_LOAD;
4413 msleep_interruptible(10);
4414 brd->wait_for_bios++;
4415 word = readw(addr + POSTAREA);
4418 /* Gave up on board after too long of time taken */
4419 err1 = readw(addr + SEQUENCE);
4420 err2 = readw(addr + ERROR);
4421 pr_warn("dgap: %s failed diagnostics. Error #(%x,%x).\n",
4422 brd->name, err1, err2);
4423 brd->state = BOARD_FAILED;
4424 brd->dpastatus = BD_NOBIOS;
4428 * Copies the FEP code from the user to the board,
4429 * and starts the FEP running.
4431 static void dgap_do_fep_load(struct board_t *brd, uchar __user *ufep, int len)
4436 if (!brd || (brd->magic != DGAP_BOARD_MAGIC) || !brd->re_map_membase)
4439 addr = brd->re_map_membase;
4445 memcpy_toio(addr + offset, ufep, len);
4448 * If board is a concentrator product, we need to give
4449 * it its config string describing how the concentrators look.
4451 if ((brd->type == PCX) || (brd->type == PEPC)) {
4453 uchar *config, *xconfig;
4456 xconfig = dgap_create_config_string(brd, string);
4458 /* Write string to board memory */
4459 config = addr + CONFIG;
4460 for (; i < CONFIGSIZE; i++, config++, xconfig++) {
4461 writeb(*xconfig, config);
4462 if ((*xconfig & 0xff) == 0xff)
4467 writel(0xbfc01004, (addr + 0xc34));
4468 writel(0x3, (addr + 0xc30));
4473 * Waits for the FEP to report thats its ready for us to use.
4475 static void dgap_do_wait_for_fep(struct board_t *brd)
4482 if (!brd || (brd->magic != DGAP_BOARD_MAGIC) || !brd->re_map_membase)
4485 addr = brd->re_map_membase;
4486 word = readw(addr + FEPSTAT);
4489 * It can take 2-3 seconds for the FEP to
4490 * be up and running. Give it 5 secs.
4492 brd->wait_for_fep = 0;
4493 while (brd->wait_for_fep < 500) {
4494 /* Check to see if FEP is up and running now. */
4495 if (word == *(u16 *) "OS") {
4496 brd->state = FINISHED_FEP_LOAD;
4498 * Check to see if the board can support FEP5+ commands.
4500 word = readw(addr + FEP5_PLUS);
4501 if (word == *(u16 *) "5A")
4502 brd->bd_flags |= BD_FEP5PLUS;
4506 msleep_interruptible(10);
4507 brd->wait_for_fep++;
4508 word = readw(addr + FEPSTAT);
4511 /* Gave up on board after too long of time taken */
4512 err1 = readw(addr + SEQUENCE);
4513 err2 = readw(addr + ERROR);
4514 pr_warn("dgap: FEPOS for %s not functioning. Error #(%x,%x).\n",
4515 brd->name, err1, err2);
4516 brd->state = BOARD_FAILED;
4517 brd->dpastatus = BD_NOFEP;
4521 * Physically forces the FEP5 card to reset itself.
4523 static void dgap_do_reset_board(struct board_t *brd)
4530 if (!brd || (brd->magic != DGAP_BOARD_MAGIC) ||
4531 !brd->re_map_membase || !brd->re_map_port)
4534 /* FEPRST does not vary among supported boards */
4535 writeb(FEPRST, brd->re_map_port);
4537 for (i = 0; i <= 1000; i++) {
4538 check = readb(brd->re_map_port) & 0xe;
4539 if (check == FEPRST)
4545 pr_warn("dgap: Board not resetting... Failing board.\n");
4546 brd->state = BOARD_FAILED;
4547 brd->dpastatus = BD_NOFEP;
4552 * Make sure there really is memory out there.
4554 writel(0xa55a3cc3, (brd->re_map_membase + LOWMEM));
4555 writel(0x5aa5c33c, (brd->re_map_membase + HIGHMEM));
4556 check1 = readl(brd->re_map_membase + LOWMEM);
4557 check2 = readl(brd->re_map_membase + HIGHMEM);
4559 if ((check1 != 0xa55a3cc3) || (check2 != 0x5aa5c33c)) {
4560 pr_warn("dgap: No memory at %p for board.\n",
4561 brd->re_map_membase);
4562 brd->state = BOARD_FAILED;
4563 brd->dpastatus = BD_NOFEP;
4567 if (brd->state != BOARD_FAILED)
4568 brd->state = FINISHED_RESET;
4571 #ifdef DIGI_CONCENTRATORS_SUPPORTED
4573 * Sends a concentrator image into the FEP5 board.
4575 static void dgap_do_conc_load(struct board_t *brd, uchar *uaddr, int len)
4579 struct downld_t *to_dp;
4581 if (!brd || (brd->magic != DGAP_BOARD_MAGIC) || !brd->re_map_membase)
4584 vaddr = brd->re_map_membase;
4586 offset = readw((u16 *) (vaddr + DOWNREQ));
4587 to_dp = (struct downld_t *) (vaddr + (int) offset);
4588 memcpy_toio(to_dp, uaddr, len);
4590 /* Tell card we have data for it */
4591 writew(0, vaddr + (DOWNREQ));
4593 brd->conc_dl_status = NO_PENDING_CONCENTRATOR_REQUESTS;
4597 #define EXPANSION_ROM_SIZE (64 * 1024)
4598 #define FEP5_ROM_MAGIC (0xFEFFFFFF)
4600 static void dgap_get_vpd(struct board_t *brd)
4612 * Poke the magic number at the PCI Rom Address location.
4613 * If VPD is supported, the value read from that address
4616 magic = FEP5_ROM_MAGIC;
4617 pci_write_config_dword(brd->pdev, PCI_ROM_ADDRESS, magic);
4618 pci_read_config_dword(brd->pdev, PCI_ROM_ADDRESS, &magic);
4620 /* VPD not supported, bail */
4625 * To get to the OTPROM memory, we have to send the boards base
4626 * address or'ed with 1 into the PCI Rom Address location.
4628 magic = brd->membase | 0x01;
4629 pci_write_config_dword(brd->pdev, PCI_ROM_ADDRESS, magic);
4630 pci_read_config_dword(brd->pdev, PCI_ROM_ADDRESS, &magic);
4632 byte1 = readb(brd->re_map_membase);
4633 byte2 = readb(brd->re_map_membase + 1);
4636 * If the board correctly swapped to the OTPROM memory,
4637 * the first 2 bytes (header) should be 0x55, 0xAA
4639 if (byte1 == 0x55 && byte2 == 0xAA) {
4644 * We have to run through all the OTPROM memory looking
4645 * for the VPD offset.
4647 while (base_offset <= EXPANSION_ROM_SIZE) {
4650 * Lots of magic numbers here.
4652 * The VPD offset is located inside the ROM Data
4655 * We also have to remember the length of each
4656 * ROM Data Structure, so we can "hop" to the next
4657 * entry if the VPD isn't in the current
4658 * ROM Data Structure.
4660 rom_offset = readw(brd->re_map_membase +
4661 base_offset + 0x18);
4662 image_length = readw(brd->re_map_membase +
4663 rom_offset + 0x10) * 512;
4664 vpd_offset = readw(brd->re_map_membase +
4667 /* Found the VPD entry */
4671 /* We didn't find a VPD entry, go to next ROM entry. */
4672 base_offset += image_length;
4674 byte1 = readb(brd->re_map_membase + base_offset);
4675 byte2 = readb(brd->re_map_membase + base_offset + 1);
4678 * If the new ROM offset doesn't have 0x55, 0xAA
4679 * as its header, we have run out of ROM.
4681 if (byte1 != 0x55 || byte2 != 0xAA)
4686 * If we have a VPD offset, then mark the board
4687 * as having a valid VPD, and copy VPDSIZE (512) bytes of
4688 * that VPD to the buffer we have in our board structure.
4691 brd->bd_flags |= BD_HAS_VPD;
4692 for (i = 0; i < VPDSIZE; i++) {
4693 brd->vpd[i] = readb(brd->re_map_membase +
4700 * We MUST poke the magic number at the PCI Rom Address location again.
4701 * This makes the card report the regular board memory back to us,
4702 * rather than the OTPROM memory.
4704 magic = FEP5_ROM_MAGIC;
4705 pci_write_config_dword(brd->pdev, PCI_ROM_ADDRESS, magic);
4709 * Our board poller function.
4711 static void dgap_poll_tasklet(unsigned long data)
4713 struct board_t *bd = (struct board_t *) data;
4719 if (!bd || (bd->magic != DGAP_BOARD_MAGIC))
4722 if (bd->inhibit_poller)
4725 DGAP_LOCK(bd->bd_lock, lock_flags);
4727 vaddr = bd->re_map_membase;
4730 * If board is ready, parse deeper to see if there is anything to do.
4732 if (bd->state == BOARD_READY) {
4734 struct ev_t *eaddr = NULL;
4736 if (!bd->re_map_membase) {
4737 DGAP_UNLOCK(bd->bd_lock, lock_flags);
4740 if (!bd->re_map_port) {
4741 DGAP_UNLOCK(bd->bd_lock, lock_flags);
4748 eaddr = (struct ev_t *) (vaddr + EVBUF);
4750 /* Get our head and tail */
4751 head = readw(&(eaddr->ev_head));
4752 tail = readw(&(eaddr->ev_tail));
4755 * If there is an event pending. Go service it.
4758 DGAP_UNLOCK(bd->bd_lock, lock_flags);
4760 DGAP_LOCK(bd->bd_lock, lock_flags);
4765 * If board is doing interrupts, ACK the interrupt.
4767 if (bd && bd->intr_running)
4768 readb(bd->re_map_port + 2);
4770 DGAP_UNLOCK(bd->bd_lock, lock_flags);
4774 /* Our state machine to get the board up and running */
4777 if (bd->state == NEED_RESET) {
4782 dgap_do_reset_board(bd);
4785 /* Move to next state */
4786 if (bd->state == FINISHED_RESET)
4787 bd->state = NEED_CONFIG;
4789 if (bd->state == NEED_CONFIG) {
4791 * Match this board to a config the user created for us.
4793 bd->bd_config = dgap_find_config(bd->type, bd->pci_bus,
4797 * Because the 4 port Xr products share the same PCI ID
4798 * as the 8 port Xr products, if we receive a NULL config
4799 * back, and this is a PAPORT8 board, retry with a
4800 * PAPORT4 attempt as well.
4802 if (bd->type == PAPORT8 && !bd->bd_config)
4803 bd->bd_config = dgap_find_config(PAPORT4, bd->pci_bus,
4807 * Register the ttys (if any) into the kernel.
4810 bd->state = FINISHED_CONFIG;
4812 bd->state = CONFIG_NOT_FOUND;
4815 /* Move to next state */
4816 if (bd->state == FINISHED_CONFIG)
4817 bd->state = NEED_DEVICE_CREATION;
4819 /* Move to next state */
4820 if (bd->state == NEED_DEVICE_CREATION) {
4822 * Signal downloader, its got some work to do.
4824 DGAP_LOCK(dgap_dl_lock, lock_flags2);
4825 if (dgap_dl_action != 1) {
4827 wake_up_interruptible(&dgap_dl_wait);
4829 DGAP_UNLOCK(dgap_dl_lock, lock_flags2);
4832 /* Move to next state */
4833 if (bd->state == FINISHED_DEVICE_CREATION)
4834 bd->state = NEED_BIOS_LOAD;
4836 /* Move to next state */
4837 if (bd->state == NEED_BIOS_LOAD) {
4839 * Signal downloader, its got some work to do.
4841 DGAP_LOCK(dgap_dl_lock, lock_flags2);
4842 if (dgap_dl_action != 1) {
4844 wake_up_interruptible(&dgap_dl_wait);
4846 DGAP_UNLOCK(dgap_dl_lock, lock_flags2);
4849 /* Wait for BIOS to test board... */
4850 if (bd->state == WAIT_BIOS_LOAD)
4851 dgap_do_wait_for_bios(bd);
4853 /* Move to next state */
4854 if (bd->state == FINISHED_BIOS_LOAD) {
4855 bd->state = NEED_FEP_LOAD;
4858 * Signal downloader, its got some work to do.
4860 DGAP_LOCK(dgap_dl_lock, lock_flags2);
4861 if (dgap_dl_action != 1) {
4863 wake_up_interruptible(&dgap_dl_wait);
4865 DGAP_UNLOCK(dgap_dl_lock, lock_flags2);
4868 /* Wait for FEP to load on board... */
4869 if (bd->state == WAIT_FEP_LOAD)
4870 dgap_do_wait_for_fep(bd);
4872 /* Move to next state */
4873 if (bd->state == FINISHED_FEP_LOAD) {
4876 * Do tty device initialization.
4878 int rc = dgap_tty_init(bd);
4881 dgap_tty_uninit(bd);
4882 bd->state = BOARD_FAILED;
4883 bd->dpastatus = BD_NOFEP;
4885 bd->state = NEED_PROC_CREATION;
4888 * Signal downloader, its got some work to do.
4890 DGAP_LOCK(dgap_dl_lock, lock_flags2);
4891 if (dgap_dl_action != 1) {
4893 wake_up_interruptible(&dgap_dl_wait);
4895 DGAP_UNLOCK(dgap_dl_lock, lock_flags2);
4899 /* Move to next state */
4900 if (bd->state == FINISHED_PROC_CREATION) {
4902 bd->state = BOARD_READY;
4903 bd->dpastatus = BD_RUNNING;
4906 * If user requested the board to run in interrupt mode,
4907 * go and set it up on the board.
4909 if (bd->intr_used) {
4910 writew(1, (bd->re_map_membase + ENABLE_INTR));
4912 * Tell the board to poll the UARTS as fast as possible.
4914 writew(FEPPOLL_MIN, (bd->re_map_membase + FEPPOLL));
4915 bd->intr_running = 1;
4918 /* Wake up anyone waiting for board state to change to ready */
4919 wake_up_interruptible(&bd->state_wait);
4922 DGAP_UNLOCK(bd->bd_lock, lock_flags);
4925 /*=======================================================================
4927 * dgap_cmdb - Sends a 2 byte command to the FEP.
4929 * ch - Pointer to channel structure.
4930 * cmd - Command to be sent.
4931 * byte1 - Integer containing first byte to be sent.
4932 * byte2 - Integer containing second byte to be sent.
4933 * ncmds - Wait until ncmds or fewer cmds are left
4934 * in the cmd buffer before returning.
4936 *=======================================================================*/
4937 static void dgap_cmdb(struct channel_t *ch, uchar cmd, uchar byte1,
4938 uchar byte2, uint ncmds)
4941 struct cm_t *cm_addr = NULL;
4947 if (!ch || ch->magic != DGAP_CHANNEL_MAGIC)
4951 * Check if board is still alive.
4953 if (ch->ch_bd->state == BOARD_FAILED)
4957 * Make sure the pointers are in range before
4958 * writing to the FEP memory.
4960 vaddr = ch->ch_bd->re_map_membase;
4965 cm_addr = (struct cm_t *) (vaddr + CMDBUF);
4966 head = readw(&(cm_addr->cm_head));
4969 * Forget it if pointers out of range.
4971 if (head >= (CMDMAX - CMDSTART) || (head & 03)) {
4972 ch->ch_bd->state = BOARD_FAILED;
4977 * Put the data in the circular command buffer.
4979 writeb(cmd, (char *) (vaddr + head + CMDSTART + 0));
4980 writeb((uchar) ch->ch_portnum, (char *) (vaddr + head + CMDSTART + 1));
4981 writeb(byte1, (char *) (vaddr + head + CMDSTART + 2));
4982 writeb(byte2, (char *) (vaddr + head + CMDSTART + 3));
4984 head = (head + 4) & (CMDMAX - CMDSTART - 4);
4986 writew(head, &(cm_addr->cm_head));
4989 * Wait if necessary before updating the head
4990 * pointer to limit the number of outstanding
4991 * commands to the FEP. If the time spent waiting
4992 * is outlandish, declare the FEP dead.
4994 for (count = dgap_count ;;) {
4996 head = readw(&(cm_addr->cm_head));
4997 tail = readw(&(cm_addr->cm_tail));
4999 n = (head - tail) & (CMDMAX - CMDSTART - 4);
5001 if (n <= ncmds * sizeof(struct cm_t))
5005 ch->ch_bd->state = BOARD_FAILED;
5012 /*=======================================================================
5014 * dgap_cmdw - Sends a 1 word command to the FEP.
5016 * ch - Pointer to channel structure.
5017 * cmd - Command to be sent.
5018 * word - Integer containing word to be sent.
5019 * ncmds - Wait until ncmds or fewer cmds are left
5020 * in the cmd buffer before returning.
5022 *=======================================================================*/
5023 static void dgap_cmdw(struct channel_t *ch, uchar cmd, u16 word, uint ncmds)
5026 struct cm_t *cm_addr = NULL;
5032 if (!ch || ch->magic != DGAP_CHANNEL_MAGIC)
5036 * Check if board is still alive.
5038 if (ch->ch_bd->state == BOARD_FAILED)
5042 * Make sure the pointers are in range before
5043 * writing to the FEP memory.
5045 vaddr = ch->ch_bd->re_map_membase;
5049 cm_addr = (struct cm_t *) (vaddr + CMDBUF);
5050 head = readw(&(cm_addr->cm_head));
5053 * Forget it if pointers out of range.
5055 if (head >= (CMDMAX - CMDSTART) || (head & 03)) {
5056 ch->ch_bd->state = BOARD_FAILED;
5061 * Put the data in the circular command buffer.
5063 writeb(cmd, (char *) (vaddr + head + CMDSTART + 0));
5064 writeb((uchar) ch->ch_portnum, (char *) (vaddr + head + CMDSTART + 1));
5065 writew((u16) word, (char *) (vaddr + head + CMDSTART + 2));
5067 head = (head + 4) & (CMDMAX - CMDSTART - 4);
5069 writew(head, &(cm_addr->cm_head));
5072 * Wait if necessary before updating the head
5073 * pointer to limit the number of outstanding
5074 * commands to the FEP. If the time spent waiting
5075 * is outlandish, declare the FEP dead.
5077 for (count = dgap_count ;;) {
5079 head = readw(&(cm_addr->cm_head));
5080 tail = readw(&(cm_addr->cm_tail));
5082 n = (head - tail) & (CMDMAX - CMDSTART - 4);
5084 if (n <= ncmds * sizeof(struct cm_t))
5088 ch->ch_bd->state = BOARD_FAILED;
5095 /*=======================================================================
5097 * dgap_cmdw_ext - Sends a extended word command to the FEP.
5099 * ch - Pointer to channel structure.
5100 * cmd - Command to be sent.
5101 * word - Integer containing word to be sent.
5102 * ncmds - Wait until ncmds or fewer cmds are left
5103 * in the cmd buffer before returning.
5105 *=======================================================================*/
5106 static void dgap_cmdw_ext(struct channel_t *ch, u16 cmd, u16 word, uint ncmds)
5109 struct cm_t *cm_addr = NULL;
5115 if (!ch || ch->magic != DGAP_CHANNEL_MAGIC)
5119 * Check if board is still alive.
5121 if (ch->ch_bd->state == BOARD_FAILED)
5125 * Make sure the pointers are in range before
5126 * writing to the FEP memory.
5128 vaddr = ch->ch_bd->re_map_membase;
5132 cm_addr = (struct cm_t *) (vaddr + CMDBUF);
5133 head = readw(&(cm_addr->cm_head));
5136 * Forget it if pointers out of range.
5138 if (head >= (CMDMAX - CMDSTART) || (head & 03)) {
5139 ch->ch_bd->state = BOARD_FAILED;
5144 * Put the data in the circular command buffer.
5147 /* Write an FF to tell the FEP that we want an extended command */
5148 writeb((uchar) 0xff, (char *) (vaddr + head + CMDSTART + 0));
5150 writeb((uchar) ch->ch_portnum, (uchar *) (vaddr + head + CMDSTART + 1));
5151 writew((u16) cmd, (char *) (vaddr + head + CMDSTART + 2));
5154 * If the second part of the command won't fit,
5155 * put it at the beginning of the circular buffer.
5157 if (((head + 4) >= ((CMDMAX - CMDSTART)) || (head & 03)))
5158 writew((u16) word, (char *) (vaddr + CMDSTART));
5160 writew((u16) word, (char *) (vaddr + head + CMDSTART + 4));
5162 head = (head + 8) & (CMDMAX - CMDSTART - 4);
5164 writew(head, &(cm_addr->cm_head));
5167 * Wait if necessary before updating the head
5168 * pointer to limit the number of outstanding
5169 * commands to the FEP. If the time spent waiting
5170 * is outlandish, declare the FEP dead.
5172 for (count = dgap_count ;;) {
5174 head = readw(&(cm_addr->cm_head));
5175 tail = readw(&(cm_addr->cm_tail));
5177 n = (head - tail) & (CMDMAX - CMDSTART - 4);
5179 if (n <= ncmds * sizeof(struct cm_t))
5183 ch->ch_bd->state = BOARD_FAILED;
5190 /*=======================================================================
5192 * dgap_wmove - Write data to FEP buffer.
5194 * ch - Pointer to channel structure.
5195 * buf - Poiter to characters to be moved.
5196 * cnt - Number of characters to move.
5198 *=======================================================================*/
5199 static void dgap_wmove(struct channel_t *ch, char *buf, uint cnt)
5206 if (!ch || ch->magic != DGAP_CHANNEL_MAGIC)
5213 head = readw(&(bs->tx_head));
5216 * If pointers are out of range, just return.
5218 if ((cnt > ch->ch_tsize) ||
5219 (unsigned)(head - ch->ch_tstart) >= ch->ch_tsize)
5223 * If the write wraps over the top of the circular buffer,
5224 * move the portion up to the wrap point, and reset the
5225 * pointers to the bottom.
5227 n = ch->ch_tstart + ch->ch_tsize - head;
5231 taddr = ch->ch_taddr + head;
5232 memcpy_toio(taddr, buf, n);
5233 head = ch->ch_tstart;
5238 * Move rest of data.
5240 taddr = ch->ch_taddr + head;
5242 memcpy_toio(taddr, buf, n);
5245 writew(head, &(bs->tx_head));
5249 * Retrives the current custom baud rate from FEP memory,
5250 * and returns it back to the user.
5251 * Returns 0 on error.
5253 static uint dgap_get_custom_baud(struct channel_t *ch)
5259 if (!ch || ch->magic != DGAP_CHANNEL_MAGIC)
5262 if (!ch->ch_bd || ch->ch_bd->magic != DGAP_BOARD_MAGIC)
5265 if (!(ch->ch_bd->bd_flags & BD_FEP5PLUS))
5268 vaddr = ch->ch_bd->re_map_membase;
5274 * Go get from fep mem, what the fep
5275 * believes the custom baud rate is.
5277 offset = ((((*(unsigned short *)(vaddr + ECS_SEG)) << 4) +
5278 (ch->ch_portnum * 0x28) + LINE_SPEED));
5280 value = readw(vaddr + offset);
5285 * Calls the firmware to reset this channel.
5287 static void dgap_firmware_reset_port(struct channel_t *ch)
5289 dgap_cmdb(ch, CHRESET, 0, 0, 0);
5292 * Now that the channel is reset, we need to make sure
5293 * all the current settings get reapplied to the port
5296 * So we will set the driver's cache of firmware
5297 * settings all to 0, and then call param.
5299 ch->ch_fepiflag = 0;
5300 ch->ch_fepcflag = 0;
5301 ch->ch_fepoflag = 0;
5302 ch->ch_fepstartc = 0;
5303 ch->ch_fepstopc = 0;
5304 ch->ch_fepastartc = 0;
5305 ch->ch_fepastopc = 0;
5310 /*=======================================================================
5312 * dgap_param - Set Digi parameters.
5314 * struct tty_struct * - TTY for port.
5316 *=======================================================================*/
5317 static int dgap_param(struct tty_struct *tty)
5319 struct ktermios *ts;
5321 struct channel_t *ch;
5330 if (!tty || tty->magic != TTY_MAGIC)
5333 un = (struct un_t *) tty->driver_data;
5334 if (!un || un->magic != DGAP_UNIT_MAGIC)
5338 if (!ch || ch->magic != DGAP_CHANNEL_MAGIC)
5342 if (!bd || bd->magic != DGAP_BOARD_MAGIC)
5352 * If baud rate is zero, flush queues, and set mval to drop DTR.
5354 if ((ch->ch_c_cflag & (CBAUD)) == 0) {
5357 head = readw(&(ch->ch_bs->rx_head));
5358 writew(head, &(ch->ch_bs->rx_tail));
5361 head = readw(&(ch->ch_bs->tx_head));
5362 writew(head, &(ch->ch_bs->tx_tail));
5364 ch->ch_flags |= (CH_BAUD0);
5366 /* Drop RTS and DTR */
5367 ch->ch_mval &= ~(D_RTS(ch)|D_DTR(ch));
5368 mval = D_DTR(ch) | D_RTS(ch);
5369 ch->ch_baud_info = 0;
5371 } else if (ch->ch_custom_speed && (bd->bd_flags & BD_FEP5PLUS)) {
5373 * Tell the fep to do the command
5376 dgap_cmdw_ext(ch, 0xff01, ch->ch_custom_speed, 0);
5379 * Now go get from fep mem, what the fep
5380 * believes the custom baud rate is.
5382 ch->ch_custom_speed = dgap_get_custom_baud(ch);
5383 ch->ch_baud_info = ch->ch_custom_speed;
5385 /* Handle transition from B0 */
5386 if (ch->ch_flags & CH_BAUD0) {
5387 ch->ch_flags &= ~(CH_BAUD0);
5388 ch->ch_mval |= (D_RTS(ch)|D_DTR(ch));
5390 mval = D_DTR(ch) | D_RTS(ch);
5394 * Set baud rate, character size, and parity.
5402 ulong bauds[4][16] = {
5406 600, 1200, 1800, 2400,
5407 4800, 9600, 19200, 38400 },
5408 { /* slowbaud & CBAUDEX */
5409 0, 57600, 115200, 230400,
5410 460800, 150, 200, 921600,
5411 600, 1200, 1800, 2400,
5412 4800, 9600, 19200, 38400 },
5414 0, 57600, 76800, 115200,
5415 14400, 57600, 230400, 76800,
5416 115200, 230400, 28800, 460800,
5417 921600, 9600, 19200, 38400 },
5418 { /* fastbaud & CBAUDEX */
5419 0, 57600, 115200, 230400,
5420 460800, 150, 200, 921600,
5421 600, 1200, 1800, 2400,
5422 4800, 9600, 19200, 38400 }
5426 * Only use the TXPrint baud rate if the
5427 * terminal unit is NOT open
5429 if (!(ch->ch_tun.un_flags & UN_ISOPEN) &&
5430 (un->un_type == DGAP_PRINT))
5431 baud = C_BAUD(ch->ch_pun.un_tty) & 0xff;
5433 baud = C_BAUD(ch->ch_tun.un_tty) & 0xff;
5435 if (ch->ch_c_cflag & CBAUDEX)
5438 if (ch->ch_digi.digi_flags & DIGI_FAST)
5443 if ((iindex >= 0) && (iindex < 4) &&
5444 (jindex >= 0) && (jindex < 16))
5445 baud = bauds[iindex][jindex];
5452 ch->ch_baud_info = baud;
5455 * CBAUD has bit position 0x1000 set these days to
5456 * indicate Linux baud rate remap.
5457 * We use a different bit assignment for high speed.
5458 * Clear this bit out while grabbing the parts of
5461 cflag = ch->ch_c_cflag & ((CBAUD ^ CBAUDEX) | PARODD | PARENB |
5465 * HUPCL bit is used by FEP to indicate fast baud
5466 * table is to be used.
5468 if ((ch->ch_digi.digi_flags & DIGI_FAST) ||
5469 (ch->ch_c_cflag & CBAUDEX))
5472 if ((ch->ch_c_cflag & CBAUDEX) &&
5473 !(ch->ch_digi.digi_flags & DIGI_FAST)) {
5475 * The below code is trying to guarantee that only
5476 * baud rates 115200, 230400, 460800, 921600 are
5477 * remapped. We use exclusive or because the various
5478 * baud rates share common bit positions and therefore
5479 * can't be tested for easily.
5481 tcflag_t tcflag = (ch->ch_c_cflag & CBAUD) | CBAUDEX;
5485 * Map high speed requests to index
5486 * into FEP's baud table
5516 cflag = (cflag & ~(CBAUD | CBAUDEX)) | baudpart;
5521 if (cflag != ch->ch_fepcflag) {
5522 ch->ch_fepcflag = (u16) (cflag & 0xffff);
5525 * Okay to have channel and board
5526 * locks held calling this
5528 dgap_cmdw(ch, SCFLAG, (u16) cflag, 0);
5531 /* Handle transition from B0 */
5532 if (ch->ch_flags & CH_BAUD0) {
5533 ch->ch_flags &= ~(CH_BAUD0);
5534 ch->ch_mval |= (D_RTS(ch)|D_DTR(ch));
5536 mval = D_DTR(ch) | D_RTS(ch);
5542 iflag = ch->ch_c_iflag & (IGNBRK | BRKINT | IGNPAR | PARMRK |
5543 INPCK | ISTRIP | IXON | IXANY | IXOFF);
5545 if ((ch->ch_startc == _POSIX_VDISABLE) ||
5546 (ch->ch_stopc == _POSIX_VDISABLE)) {
5547 iflag &= ~(IXON | IXOFF);
5548 ch->ch_c_iflag &= ~(IXON | IXOFF);
5552 * Only the IBM Xr card can switch between
5553 * 232 and 422 modes on the fly
5555 if (bd->device == PCI_DEV_XR_IBM_DID) {
5556 if (ch->ch_digi.digi_flags & DIGI_422)
5557 dgap_cmdb(ch, SCOMMODE, MODE_422, 0, 0);
5559 dgap_cmdb(ch, SCOMMODE, MODE_232, 0, 0);
5562 if (ch->ch_digi.digi_flags & DIGI_ALTPIN)
5565 if (iflag != ch->ch_fepiflag) {
5566 ch->ch_fepiflag = iflag;
5568 /* Okay to have channel and board locks held calling this */
5569 dgap_cmdw(ch, SIFLAG, (u16) ch->ch_fepiflag, 0);
5573 * Select hardware handshaking.
5577 if (ch->ch_c_cflag & CRTSCTS)
5578 hflow |= (D_RTS(ch) | D_CTS(ch));
5579 if (ch->ch_digi.digi_flags & RTSPACE)
5581 if (ch->ch_digi.digi_flags & DTRPACE)
5583 if (ch->ch_digi.digi_flags & CTSPACE)
5585 if (ch->ch_digi.digi_flags & DSRPACE)
5587 if (ch->ch_digi.digi_flags & DCDPACE)
5590 if (hflow != ch->ch_hflow) {
5591 ch->ch_hflow = hflow;
5593 /* Okay to have channel and board locks held calling this */
5594 dgap_cmdb(ch, SHFLOW, (uchar) hflow, 0xff, 0);
5599 * Set RTS and/or DTR Toggle if needed,
5600 * but only if product is FEP5+ based.
5602 if (bd->bd_flags & BD_FEP5PLUS) {
5604 if (ch->ch_digi.digi_flags & DIGI_RTS_TOGGLE)
5605 hflow2 |= (D_RTS(ch));
5606 if (ch->ch_digi.digi_flags & DIGI_DTR_TOGGLE)
5607 hflow2 |= (D_DTR(ch));
5609 dgap_cmdw_ext(ch, 0xff03, hflow2, 0);
5613 * Set modem control lines.
5616 mval ^= ch->ch_mforce & (mval ^ ch->ch_mval);
5618 if (ch->ch_mostat ^ mval) {
5619 ch->ch_mostat = mval;
5621 /* Okay to have channel and board locks held calling this */
5622 dgap_cmdb(ch, SMODEM, (uchar) mval, D_RTS(ch)|D_DTR(ch), 0);
5626 * Read modem signals, and then call carrier function.
5628 ch->ch_mistat = readb(&(bs->m_stat));
5632 * Set the start and stop characters.
5634 if (ch->ch_startc != ch->ch_fepstartc ||
5635 ch->ch_stopc != ch->ch_fepstopc) {
5636 ch->ch_fepstartc = ch->ch_startc;
5637 ch->ch_fepstopc = ch->ch_stopc;
5639 /* Okay to have channel and board locks held calling this */
5640 dgap_cmdb(ch, SFLOWC, ch->ch_fepstartc, ch->ch_fepstopc, 0);
5644 * Set the Auxiliary start and stop characters.
5646 if (ch->ch_astartc != ch->ch_fepastartc ||
5647 ch->ch_astopc != ch->ch_fepastopc) {
5648 ch->ch_fepastartc = ch->ch_astartc;
5649 ch->ch_fepastopc = ch->ch_astopc;
5651 /* Okay to have channel and board locks held calling this */
5652 dgap_cmdb(ch, SAFLOWC, ch->ch_fepastartc, ch->ch_fepastopc, 0);
5659 * dgap_parity_scan()
5661 * Convert the FEP5 way of reporting parity errors and breaks into
5662 * the Linux line discipline way.
5664 static void dgap_parity_scan(struct channel_t *ch, unsigned char *cbuf,
5665 unsigned char *fbuf, int *len)
5669 unsigned char *in, *cout, *fout;
5676 if (!ch || ch->magic != DGAP_CHANNEL_MAGIC)
5681 switch (ch->pscan_state) {
5683 /* reset to sanity and fall through */
5684 ch->pscan_state = 0;
5687 /* No FF seen yet */
5688 if (c == (unsigned char) '\377')
5689 /* delete this character from stream */
5690 ch->pscan_state = 1;
5693 *fout++ = TTY_NORMAL;
5700 if (c == (unsigned char) '\377') {
5701 /* doubled ff, transform to single ff */
5703 *fout++ = TTY_NORMAL;
5705 ch->pscan_state = 0;
5707 /* save value examination in next state */
5708 ch->pscan_savechar = c;
5709 ch->pscan_state = 2;
5714 /* third character of ff sequence */
5718 if (ch->pscan_savechar == 0x0) {
5722 *fout++ = TTY_BREAK;
5724 ch->ch_err_parity++;
5725 *fout++ = TTY_PARITY;
5730 ch->pscan_state = 0;
5736 /*=======================================================================
5738 * dgap_event - FEP to host event processing routine.
5740 * bd - Board of current event.
5742 *=======================================================================*/
5743 static int dgap_event(struct board_t *bd)
5745 struct channel_t *ch;
5750 uchar *vaddr = NULL;
5751 struct ev_t *eaddr = NULL;
5759 if (!bd || bd->magic != DGAP_BOARD_MAGIC)
5762 DGAP_LOCK(bd->bd_lock, lock_flags);
5764 vaddr = bd->re_map_membase;
5767 DGAP_UNLOCK(bd->bd_lock, lock_flags);
5771 eaddr = (struct ev_t *) (vaddr + EVBUF);
5773 /* Get our head and tail */
5774 head = readw(&(eaddr->ev_head));
5775 tail = readw(&(eaddr->ev_tail));
5778 * Forget it if pointers out of range.
5781 if (head >= EVMAX - EVSTART || tail >= EVMAX - EVSTART ||
5782 (head | tail) & 03) {
5783 /* Let go of board lock */
5784 DGAP_UNLOCK(bd->bd_lock, lock_flags);
5789 * Loop to process all the events in the buffer.
5791 while (tail != head) {
5794 * Get interrupt information.
5797 event = bd->re_map_membase + tail + EVSTART;
5805 * Make sure the interrupt is valid.
5807 if (port >= bd->nasync)
5810 if (!(reason & (IFMODEM | IFBREAK | IFTLW | IFTEM | IFDATA)))
5813 ch = bd->channels[port];
5815 if (!ch || ch->magic != DGAP_CHANNEL_MAGIC)
5819 * If we have made it here, the event was valid.
5820 * Lock down the channel.
5822 DGAP_LOCK(ch->ch_lock, lock_flags2);
5827 DGAP_UNLOCK(ch->ch_lock, lock_flags2);
5832 * Process received data.
5834 if (reason & IFDATA) {
5837 * ALL LOCKS *MUST* BE DROPPED BEFORE CALLING INPUT!
5838 * input could send some data to ld, which in turn
5839 * could do a callback to one of our other functions.
5841 DGAP_UNLOCK(ch->ch_lock, lock_flags2);
5842 DGAP_UNLOCK(bd->bd_lock, lock_flags);
5846 DGAP_LOCK(bd->bd_lock, lock_flags);
5847 DGAP_LOCK(ch->ch_lock, lock_flags2);
5849 if (ch->ch_flags & CH_RACTIVE)
5850 ch->ch_flags |= CH_RENABLE;
5852 writeb(1, &(bs->idata));
5854 if (ch->ch_flags & CH_RWAIT) {
5855 ch->ch_flags &= ~CH_RWAIT;
5857 wake_up_interruptible
5858 (&ch->ch_tun.un_flags_wait);
5863 * Process Modem change signals.
5865 if (reason & IFMODEM) {
5866 ch->ch_mistat = modem;
5873 if (reason & IFBREAK) {
5875 if (ch->ch_tun.un_tty) {
5876 /* A break has been indicated */
5878 tty_buffer_request_room
5879 (ch->ch_tun.un_tty->port, 1);
5880 tty_insert_flip_char(ch->ch_tun.un_tty->port,
5882 tty_flip_buffer_push(ch->ch_tun.un_tty->port);
5887 * Process Transmit low.
5889 if (reason & IFTLW) {
5891 if (ch->ch_tun.un_flags & UN_LOW) {
5892 ch->ch_tun.un_flags &= ~UN_LOW;
5894 if (ch->ch_tun.un_flags & UN_ISOPEN) {
5895 if ((ch->ch_tun.un_tty->flags &
5896 (1 << TTY_DO_WRITE_WAKEUP)) &&
5897 ch->ch_tun.un_tty->ldisc->ops->write_wakeup) {
5898 DGAP_UNLOCK(ch->ch_lock, lock_flags2);
5899 DGAP_UNLOCK(bd->bd_lock, lock_flags);
5900 (ch->ch_tun.un_tty->ldisc->ops->write_wakeup)(ch->ch_tun.un_tty);
5901 DGAP_LOCK(bd->bd_lock, lock_flags);
5902 DGAP_LOCK(ch->ch_lock, lock_flags2);
5904 wake_up_interruptible(&ch->ch_tun.un_tty->write_wait);
5905 wake_up_interruptible(&ch->ch_tun.un_flags_wait);
5909 if (ch->ch_pun.un_flags & UN_LOW) {
5910 ch->ch_pun.un_flags &= ~UN_LOW;
5911 if (ch->ch_pun.un_flags & UN_ISOPEN) {
5912 if ((ch->ch_pun.un_tty->flags &
5913 (1 << TTY_DO_WRITE_WAKEUP)) &&
5914 ch->ch_pun.un_tty->ldisc->ops->write_wakeup) {
5915 DGAP_UNLOCK(ch->ch_lock, lock_flags2);
5916 DGAP_UNLOCK(bd->bd_lock, lock_flags);
5917 (ch->ch_pun.un_tty->ldisc->ops->write_wakeup)(ch->ch_pun.un_tty);
5918 DGAP_LOCK(bd->bd_lock, lock_flags);
5919 DGAP_LOCK(ch->ch_lock, lock_flags2);
5921 wake_up_interruptible(&ch->ch_pun.un_tty->write_wait);
5922 wake_up_interruptible(&ch->ch_pun.un_flags_wait);
5926 if (ch->ch_flags & CH_WLOW) {
5927 ch->ch_flags &= ~CH_WLOW;
5928 wake_up_interruptible(&ch->ch_flags_wait);
5933 * Process Transmit empty.
5935 if (reason & IFTEM) {
5936 if (ch->ch_tun.un_flags & UN_EMPTY) {
5937 ch->ch_tun.un_flags &= ~UN_EMPTY;
5938 if (ch->ch_tun.un_flags & UN_ISOPEN) {
5939 if ((ch->ch_tun.un_tty->flags &
5940 (1 << TTY_DO_WRITE_WAKEUP)) &&
5941 ch->ch_tun.un_tty->ldisc->ops->write_wakeup) {
5942 DGAP_UNLOCK(ch->ch_lock, lock_flags2);
5943 DGAP_UNLOCK(bd->bd_lock, lock_flags);
5945 (ch->ch_tun.un_tty->ldisc->ops->write_wakeup)(ch->ch_tun.un_tty);
5946 DGAP_LOCK(bd->bd_lock, lock_flags);
5947 DGAP_LOCK(ch->ch_lock, lock_flags2);
5949 wake_up_interruptible(&ch->ch_tun.un_tty->write_wait);
5950 wake_up_interruptible(&ch->ch_tun.un_flags_wait);
5954 if (ch->ch_pun.un_flags & UN_EMPTY) {
5955 ch->ch_pun.un_flags &= ~UN_EMPTY;
5956 if (ch->ch_pun.un_flags & UN_ISOPEN) {
5957 if ((ch->ch_pun.un_tty->flags &
5958 (1 << TTY_DO_WRITE_WAKEUP)) &&
5959 ch->ch_pun.un_tty->ldisc->ops->write_wakeup) {
5960 DGAP_UNLOCK(ch->ch_lock, lock_flags2);
5961 DGAP_UNLOCK(bd->bd_lock, lock_flags);
5962 (ch->ch_pun.un_tty->ldisc->ops->write_wakeup)(ch->ch_pun.un_tty);
5963 DGAP_LOCK(bd->bd_lock, lock_flags);
5964 DGAP_LOCK(ch->ch_lock, lock_flags2);
5966 wake_up_interruptible(&ch->ch_pun.un_tty->write_wait);
5967 wake_up_interruptible(&ch->ch_pun.un_flags_wait);
5972 if (ch->ch_flags & CH_WEMPTY) {
5973 ch->ch_flags &= ~CH_WEMPTY;
5974 wake_up_interruptible(&ch->ch_flags_wait);
5978 DGAP_UNLOCK(ch->ch_lock, lock_flags2);
5981 tail = (tail + 4) & (EVMAX - EVSTART - 4);
5984 writew(tail, &(eaddr->ev_tail));
5985 DGAP_UNLOCK(bd->bd_lock, lock_flags);
5990 static ssize_t dgap_driver_version_show(struct device_driver *ddp, char *buf)
5992 return snprintf(buf, PAGE_SIZE, "%s\n", DG_PART);
5994 static DRIVER_ATTR(version, S_IRUSR, dgap_driver_version_show, NULL);
5997 static ssize_t dgap_driver_boards_show(struct device_driver *ddp, char *buf)
5999 return snprintf(buf, PAGE_SIZE, "%d\n", dgap_NumBoards);
6001 static DRIVER_ATTR(boards, S_IRUSR, dgap_driver_boards_show, NULL);
6004 static ssize_t dgap_driver_maxboards_show(struct device_driver *ddp, char *buf)
6006 return snprintf(buf, PAGE_SIZE, "%d\n", MAXBOARDS);
6008 static DRIVER_ATTR(maxboards, S_IRUSR, dgap_driver_maxboards_show, NULL);
6011 static ssize_t dgap_driver_pollcounter_show(struct device_driver *ddp, char *buf)
6013 return snprintf(buf, PAGE_SIZE, "%ld\n", dgap_poll_counter);
6015 static DRIVER_ATTR(pollcounter, S_IRUSR, dgap_driver_pollcounter_show, NULL);
6018 static ssize_t dgap_driver_state_show(struct device_driver *ddp, char *buf)
6020 return snprintf(buf, PAGE_SIZE, "%s\n", dgap_driver_state_text[dgap_driver_state]);
6022 static DRIVER_ATTR(state, S_IRUSR, dgap_driver_state_show, NULL);
6024 static ssize_t dgap_driver_pollrate_show(struct device_driver *ddp, char *buf)
6026 return snprintf(buf, PAGE_SIZE, "%dms\n", dgap_poll_tick);
6029 static ssize_t dgap_driver_pollrate_store(struct device_driver *ddp, const char *buf, size_t count)
6031 if (sscanf(buf, "%d\n", &dgap_poll_tick) != 1)
6035 static DRIVER_ATTR(pollrate, (S_IRUSR | S_IWUSR), dgap_driver_pollrate_show, dgap_driver_pollrate_store);
6037 static int dgap_create_driver_sysfiles(struct pci_driver *dgap_driver)
6040 struct device_driver *driverfs = &dgap_driver->driver;
6042 rc |= driver_create_file(driverfs, &driver_attr_version);
6043 rc |= driver_create_file(driverfs, &driver_attr_boards);
6044 rc |= driver_create_file(driverfs, &driver_attr_maxboards);
6045 rc |= driver_create_file(driverfs, &driver_attr_pollrate);
6046 rc |= driver_create_file(driverfs, &driver_attr_pollcounter);
6047 rc |= driver_create_file(driverfs, &driver_attr_state);
6052 static void dgap_remove_driver_sysfiles(struct pci_driver *dgap_driver)
6054 struct device_driver *driverfs = &dgap_driver->driver;
6055 driver_remove_file(driverfs, &driver_attr_version);
6056 driver_remove_file(driverfs, &driver_attr_boards);
6057 driver_remove_file(driverfs, &driver_attr_maxboards);
6058 driver_remove_file(driverfs, &driver_attr_pollrate);
6059 driver_remove_file(driverfs, &driver_attr_pollcounter);
6060 driver_remove_file(driverfs, &driver_attr_state);
6063 static struct board_t *dgap_verify_board(struct device *p)
6070 bd = dev_get_drvdata(p);
6071 if (!bd || bd->magic != DGAP_BOARD_MAGIC || bd->state != BOARD_READY)
6077 static ssize_t dgap_ports_state_show(struct device *p, struct device_attribute *attr, char *buf)
6083 bd = dgap_verify_board(p);
6087 for (i = 0; i < bd->nasync; i++) {
6088 count += snprintf(buf + count, PAGE_SIZE - count,
6089 "%d %s\n", bd->channels[i]->ch_portnum,
6090 bd->channels[i]->ch_open_count ? "Open" : "Closed");
6094 static DEVICE_ATTR(ports_state, S_IRUSR, dgap_ports_state_show, NULL);
6096 static ssize_t dgap_ports_baud_show(struct device *p, struct device_attribute *attr, char *buf)
6102 bd = dgap_verify_board(p);
6106 for (i = 0; i < bd->nasync; i++) {
6107 count += snprintf(buf + count, PAGE_SIZE - count,
6108 "%d %d\n", bd->channels[i]->ch_portnum, bd->channels[i]->ch_baud_info);
6112 static DEVICE_ATTR(ports_baud, S_IRUSR, dgap_ports_baud_show, NULL);
6114 static ssize_t dgap_ports_msignals_show(struct device *p, struct device_attribute *attr, char *buf)
6120 bd = dgap_verify_board(p);
6124 for (i = 0; i < bd->nasync; i++) {
6125 if (bd->channels[i]->ch_open_count)
6126 count += snprintf(buf + count, PAGE_SIZE - count,
6127 "%d %s %s %s %s %s %s\n", bd->channels[i]->ch_portnum,
6128 (bd->channels[i]->ch_mostat & UART_MCR_RTS) ? "RTS" : "",
6129 (bd->channels[i]->ch_mistat & UART_MSR_CTS) ? "CTS" : "",
6130 (bd->channels[i]->ch_mostat & UART_MCR_DTR) ? "DTR" : "",
6131 (bd->channels[i]->ch_mistat & UART_MSR_DSR) ? "DSR" : "",
6132 (bd->channels[i]->ch_mistat & UART_MSR_DCD) ? "DCD" : "",
6133 (bd->channels[i]->ch_mistat & UART_MSR_RI) ? "RI" : "");
6135 count += snprintf(buf + count, PAGE_SIZE - count,
6136 "%d\n", bd->channels[i]->ch_portnum);
6140 static DEVICE_ATTR(ports_msignals, S_IRUSR, dgap_ports_msignals_show, NULL);
6142 static ssize_t dgap_ports_iflag_show(struct device *p, struct device_attribute *attr, char *buf)
6148 bd = dgap_verify_board(p);
6152 for (i = 0; i < bd->nasync; i++)
6153 count += snprintf(buf + count, PAGE_SIZE - count, "%d %x\n",
6154 bd->channels[i]->ch_portnum, bd->channels[i]->ch_c_iflag);
6157 static DEVICE_ATTR(ports_iflag, S_IRUSR, dgap_ports_iflag_show, NULL);
6159 static ssize_t dgap_ports_cflag_show(struct device *p, struct device_attribute *attr, char *buf)
6165 bd = dgap_verify_board(p);
6169 for (i = 0; i < bd->nasync; i++)
6170 count += snprintf(buf + count, PAGE_SIZE - count, "%d %x\n",
6171 bd->channels[i]->ch_portnum, bd->channels[i]->ch_c_cflag);
6174 static DEVICE_ATTR(ports_cflag, S_IRUSR, dgap_ports_cflag_show, NULL);
6176 static ssize_t dgap_ports_oflag_show(struct device *p, struct device_attribute *attr, char *buf)
6182 bd = dgap_verify_board(p);
6186 for (i = 0; i < bd->nasync; i++)
6187 count += snprintf(buf + count, PAGE_SIZE - count, "%d %x\n",
6188 bd->channels[i]->ch_portnum, bd->channels[i]->ch_c_oflag);
6191 static DEVICE_ATTR(ports_oflag, S_IRUSR, dgap_ports_oflag_show, NULL);
6193 static ssize_t dgap_ports_lflag_show(struct device *p, struct device_attribute *attr, char *buf)
6199 bd = dgap_verify_board(p);
6203 for (i = 0; i < bd->nasync; i++)
6204 count += snprintf(buf + count, PAGE_SIZE - count, "%d %x\n",
6205 bd->channels[i]->ch_portnum, bd->channels[i]->ch_c_lflag);
6208 static DEVICE_ATTR(ports_lflag, S_IRUSR, dgap_ports_lflag_show, NULL);
6210 static ssize_t dgap_ports_digi_flag_show(struct device *p, struct device_attribute *attr, char *buf)
6216 bd = dgap_verify_board(p);
6220 for (i = 0; i < bd->nasync; i++)
6221 count += snprintf(buf + count, PAGE_SIZE - count, "%d %x\n",
6222 bd->channels[i]->ch_portnum, bd->channels[i]->ch_digi.digi_flags);
6225 static DEVICE_ATTR(ports_digi_flag, S_IRUSR, dgap_ports_digi_flag_show, NULL);
6227 static ssize_t dgap_ports_rxcount_show(struct device *p, struct device_attribute *attr, char *buf)
6233 bd = dgap_verify_board(p);
6237 for (i = 0; i < bd->nasync; i++)
6238 count += snprintf(buf + count, PAGE_SIZE - count, "%d %ld\n",
6239 bd->channels[i]->ch_portnum, bd->channels[i]->ch_rxcount);
6242 static DEVICE_ATTR(ports_rxcount, S_IRUSR, dgap_ports_rxcount_show, NULL);
6244 static ssize_t dgap_ports_txcount_show(struct device *p, struct device_attribute *attr, char *buf)
6250 bd = dgap_verify_board(p);
6254 for (i = 0; i < bd->nasync; i++)
6255 count += snprintf(buf + count, PAGE_SIZE - count, "%d %ld\n",
6256 bd->channels[i]->ch_portnum, bd->channels[i]->ch_txcount);
6259 static DEVICE_ATTR(ports_txcount, S_IRUSR, dgap_ports_txcount_show, NULL);
6261 /* this function creates the sys files that will export each signal status
6262 * to sysfs each value will be put in a separate filename
6264 static void dgap_create_ports_sysfiles(struct board_t *bd)
6266 dev_set_drvdata(&bd->pdev->dev, bd);
6267 device_create_file(&(bd->pdev->dev), &dev_attr_ports_state);
6268 device_create_file(&(bd->pdev->dev), &dev_attr_ports_baud);
6269 device_create_file(&(bd->pdev->dev), &dev_attr_ports_msignals);
6270 device_create_file(&(bd->pdev->dev), &dev_attr_ports_iflag);
6271 device_create_file(&(bd->pdev->dev), &dev_attr_ports_cflag);
6272 device_create_file(&(bd->pdev->dev), &dev_attr_ports_oflag);
6273 device_create_file(&(bd->pdev->dev), &dev_attr_ports_lflag);
6274 device_create_file(&(bd->pdev->dev), &dev_attr_ports_digi_flag);
6275 device_create_file(&(bd->pdev->dev), &dev_attr_ports_rxcount);
6276 device_create_file(&(bd->pdev->dev), &dev_attr_ports_txcount);
6279 /* removes all the sys files created for that port */
6280 static void dgap_remove_ports_sysfiles(struct board_t *bd)
6282 device_remove_file(&(bd->pdev->dev), &dev_attr_ports_state);
6283 device_remove_file(&(bd->pdev->dev), &dev_attr_ports_baud);
6284 device_remove_file(&(bd->pdev->dev), &dev_attr_ports_msignals);
6285 device_remove_file(&(bd->pdev->dev), &dev_attr_ports_iflag);
6286 device_remove_file(&(bd->pdev->dev), &dev_attr_ports_cflag);
6287 device_remove_file(&(bd->pdev->dev), &dev_attr_ports_oflag);
6288 device_remove_file(&(bd->pdev->dev), &dev_attr_ports_lflag);
6289 device_remove_file(&(bd->pdev->dev), &dev_attr_ports_digi_flag);
6290 device_remove_file(&(bd->pdev->dev), &dev_attr_ports_rxcount);
6291 device_remove_file(&(bd->pdev->dev), &dev_attr_ports_txcount);
6294 static ssize_t dgap_tty_state_show(struct device *d, struct device_attribute *attr, char *buf)
6297 struct channel_t *ch;
6302 un = dev_get_drvdata(d);
6303 if (!un || un->magic != DGAP_UNIT_MAGIC)
6306 if (!ch || ch->magic != DGAP_CHANNEL_MAGIC)
6309 if (!bd || bd->magic != DGAP_BOARD_MAGIC)
6311 if (bd->state != BOARD_READY)
6314 return snprintf(buf, PAGE_SIZE, "%s", un->un_open_count ? "Open" : "Closed");
6316 static DEVICE_ATTR(state, S_IRUSR, dgap_tty_state_show, NULL);
6318 static ssize_t dgap_tty_baud_show(struct device *d, struct device_attribute *attr, char *buf)
6321 struct channel_t *ch;
6326 un = dev_get_drvdata(d);
6327 if (!un || un->magic != DGAP_UNIT_MAGIC)
6330 if (!ch || ch->magic != DGAP_CHANNEL_MAGIC)
6333 if (!bd || bd->magic != DGAP_BOARD_MAGIC)
6335 if (bd->state != BOARD_READY)
6338 return snprintf(buf, PAGE_SIZE, "%d\n", ch->ch_baud_info);
6340 static DEVICE_ATTR(baud, S_IRUSR, dgap_tty_baud_show, NULL);
6342 static ssize_t dgap_tty_msignals_show(struct device *d, struct device_attribute *attr, char *buf)
6345 struct channel_t *ch;
6350 un = dev_get_drvdata(d);
6351 if (!un || un->magic != DGAP_UNIT_MAGIC)
6354 if (!ch || ch->magic != DGAP_CHANNEL_MAGIC)
6357 if (!bd || bd->magic != DGAP_BOARD_MAGIC)
6359 if (bd->state != BOARD_READY)
6362 if (ch->ch_open_count) {
6363 return snprintf(buf, PAGE_SIZE, "%s %s %s %s %s %s\n",
6364 (ch->ch_mostat & UART_MCR_RTS) ? "RTS" : "",
6365 (ch->ch_mistat & UART_MSR_CTS) ? "CTS" : "",
6366 (ch->ch_mostat & UART_MCR_DTR) ? "DTR" : "",
6367 (ch->ch_mistat & UART_MSR_DSR) ? "DSR" : "",
6368 (ch->ch_mistat & UART_MSR_DCD) ? "DCD" : "",
6369 (ch->ch_mistat & UART_MSR_RI) ? "RI" : "");
6373 static DEVICE_ATTR(msignals, S_IRUSR, dgap_tty_msignals_show, NULL);
6375 static ssize_t dgap_tty_iflag_show(struct device *d, struct device_attribute *attr, char *buf)
6378 struct channel_t *ch;
6383 un = dev_get_drvdata(d);
6384 if (!un || un->magic != DGAP_UNIT_MAGIC)
6387 if (!ch || ch->magic != DGAP_CHANNEL_MAGIC)
6390 if (!bd || bd->magic != DGAP_BOARD_MAGIC)
6392 if (bd->state != BOARD_READY)
6395 return snprintf(buf, PAGE_SIZE, "%x\n", ch->ch_c_iflag);
6397 static DEVICE_ATTR(iflag, S_IRUSR, dgap_tty_iflag_show, NULL);
6399 static ssize_t dgap_tty_cflag_show(struct device *d, struct device_attribute *attr, char *buf)
6402 struct channel_t *ch;
6407 un = dev_get_drvdata(d);
6408 if (!un || un->magic != DGAP_UNIT_MAGIC)
6411 if (!ch || ch->magic != DGAP_CHANNEL_MAGIC)
6414 if (!bd || bd->magic != DGAP_BOARD_MAGIC)
6416 if (bd->state != BOARD_READY)
6419 return snprintf(buf, PAGE_SIZE, "%x\n", ch->ch_c_cflag);
6421 static DEVICE_ATTR(cflag, S_IRUSR, dgap_tty_cflag_show, NULL);
6423 static ssize_t dgap_tty_oflag_show(struct device *d, struct device_attribute *attr, char *buf)
6426 struct channel_t *ch;
6431 un = dev_get_drvdata(d);
6432 if (!un || un->magic != DGAP_UNIT_MAGIC)
6435 if (!ch || ch->magic != DGAP_CHANNEL_MAGIC)
6438 if (!bd || bd->magic != DGAP_BOARD_MAGIC)
6440 if (bd->state != BOARD_READY)
6443 return snprintf(buf, PAGE_SIZE, "%x\n", ch->ch_c_oflag);
6445 static DEVICE_ATTR(oflag, S_IRUSR, dgap_tty_oflag_show, NULL);
6447 static ssize_t dgap_tty_lflag_show(struct device *d, struct device_attribute *attr, char *buf)
6450 struct channel_t *ch;
6455 un = dev_get_drvdata(d);
6456 if (!un || un->magic != DGAP_UNIT_MAGIC)
6459 if (!ch || ch->magic != DGAP_CHANNEL_MAGIC)
6462 if (!bd || bd->magic != DGAP_BOARD_MAGIC)
6464 if (bd->state != BOARD_READY)
6467 return snprintf(buf, PAGE_SIZE, "%x\n", ch->ch_c_lflag);
6469 static DEVICE_ATTR(lflag, S_IRUSR, dgap_tty_lflag_show, NULL);
6471 static ssize_t dgap_tty_digi_flag_show(struct device *d, struct device_attribute *attr, char *buf)
6474 struct channel_t *ch;
6479 un = dev_get_drvdata(d);
6480 if (!un || un->magic != DGAP_UNIT_MAGIC)
6483 if (!ch || ch->magic != DGAP_CHANNEL_MAGIC)
6486 if (!bd || bd->magic != DGAP_BOARD_MAGIC)
6488 if (bd->state != BOARD_READY)
6491 return snprintf(buf, PAGE_SIZE, "%x\n", ch->ch_digi.digi_flags);
6493 static DEVICE_ATTR(digi_flag, S_IRUSR, dgap_tty_digi_flag_show, NULL);
6495 static ssize_t dgap_tty_rxcount_show(struct device *d, struct device_attribute *attr, char *buf)
6498 struct channel_t *ch;
6503 un = dev_get_drvdata(d);
6504 if (!un || un->magic != DGAP_UNIT_MAGIC)
6507 if (!ch || ch->magic != DGAP_CHANNEL_MAGIC)
6510 if (!bd || bd->magic != DGAP_BOARD_MAGIC)
6512 if (bd->state != BOARD_READY)
6515 return snprintf(buf, PAGE_SIZE, "%ld\n", ch->ch_rxcount);
6517 static DEVICE_ATTR(rxcount, S_IRUSR, dgap_tty_rxcount_show, NULL);
6519 static ssize_t dgap_tty_txcount_show(struct device *d, struct device_attribute *attr, char *buf)
6522 struct channel_t *ch;
6527 un = dev_get_drvdata(d);
6528 if (!un || un->magic != DGAP_UNIT_MAGIC)
6531 if (!ch || ch->magic != DGAP_CHANNEL_MAGIC)
6534 if (!bd || bd->magic != DGAP_BOARD_MAGIC)
6536 if (bd->state != BOARD_READY)
6539 return snprintf(buf, PAGE_SIZE, "%ld\n", ch->ch_txcount);
6541 static DEVICE_ATTR(txcount, S_IRUSR, dgap_tty_txcount_show, NULL);
6543 static ssize_t dgap_tty_name_show(struct device *d, struct device_attribute *attr, char *buf)
6546 struct channel_t *ch;
6550 struct cnode *cptr = NULL;
6558 un = dev_get_drvdata(d);
6559 if (!un || un->magic != DGAP_UNIT_MAGIC)
6562 if (!ch || ch->magic != DGAP_CHANNEL_MAGIC)
6565 if (!bd || bd->magic != DGAP_BOARD_MAGIC)
6567 if (bd->state != BOARD_READY)
6571 cn = ch->ch_portnum;
6573 for (cptr = bd->bd_config; cptr; cptr = cptr->next) {
6575 if ((cptr->type == BNODE) &&
6576 ((cptr->u.board.type == APORT2_920P) || (cptr->u.board.type == APORT4_920P) ||
6577 (cptr->u.board.type == APORT8_920P) || (cptr->u.board.type == PAPORT4) ||
6578 (cptr->u.board.type == PAPORT8))) {
6581 if (cptr->u.board.v_start)
6582 starto = cptr->u.board.start;
6587 if (cptr->type == TNODE && found == TRUE) {
6589 if (strstr(cptr->u.ttyname, "tty")) {
6590 ptr1 = cptr->u.ttyname;
6593 ptr1 = cptr->u.ttyname;
6595 for (i = 0; i < dgap_config_get_number_of_ports(bd); i++) {
6597 return snprintf(buf, PAGE_SIZE, "%s%s%02d\n",
6598 (un->un_type == DGAP_PRINT) ? "pr" : "tty",
6603 if (cptr->type == CNODE) {
6605 for (i = 0; i < cptr->u.conc.nport; i++) {
6606 if (cn == (i + ncount))
6608 return snprintf(buf, PAGE_SIZE, "%s%s%02d\n",
6609 (un->un_type == DGAP_PRINT) ? "pr" : "tty",
6611 i + (cptr->u.conc.v_start ? cptr->u.conc.start : 1));
6614 ncount += cptr->u.conc.nport;
6617 if (cptr->type == MNODE) {
6619 for (i = 0; i < cptr->u.module.nport; i++) {
6620 if (cn == (i + ncount))
6621 return snprintf(buf, PAGE_SIZE, "%s%s%02d\n",
6622 (un->un_type == DGAP_PRINT) ? "pr" : "tty",
6624 i + (cptr->u.module.v_start ? cptr->u.module.start : 1));
6627 ncount += cptr->u.module.nport;
6632 return snprintf(buf, PAGE_SIZE, "%s_dgap_%d_%d\n",
6633 (un->un_type == DGAP_PRINT) ? "pr" : "tty", bn, cn);
6636 static DEVICE_ATTR(custom_name, S_IRUSR, dgap_tty_name_show, NULL);
6638 static struct attribute *dgap_sysfs_tty_entries[] = {
6639 &dev_attr_state.attr,
6640 &dev_attr_baud.attr,
6641 &dev_attr_msignals.attr,
6642 &dev_attr_iflag.attr,
6643 &dev_attr_cflag.attr,
6644 &dev_attr_oflag.attr,
6645 &dev_attr_lflag.attr,
6646 &dev_attr_digi_flag.attr,
6647 &dev_attr_rxcount.attr,
6648 &dev_attr_txcount.attr,
6649 &dev_attr_custom_name.attr,
6653 static struct attribute_group dgap_tty_attribute_group = {
6655 .attrs = dgap_sysfs_tty_entries,
6658 static void dgap_create_tty_sysfs(struct un_t *un, struct device *c)
6662 ret = sysfs_create_group(&c->kobj, &dgap_tty_attribute_group);
6666 dev_set_drvdata(c, un);
6670 static void dgap_remove_tty_sysfs(struct device *c)
6672 sysfs_remove_group(&c->kobj, &dgap_tty_attribute_group);
6676 * Parse a configuration file read into memory as a string.
6678 static int dgap_parsefile(char **in, int Remove)
6680 struct cnode *p, *brd, *line, *conc;
6682 char *s = NULL, *s2 = NULL;
6686 brd = line = conc = NULL;
6688 /* perhaps we are adding to an existing list? */
6689 while (p->next != NULL)
6692 /* file must start with a BEGIN */
6693 while ((rc = dgap_gettok(in, p)) != BEGIN) {
6695 dgap_err("unexpected EOF");
6701 rc = dgap_gettok(in, p);
6703 dgap_err("unexpected EOF");
6709 dgap_err("unexpected end of file");
6712 case BEGIN: /* should only be 1 begin */
6713 dgap_err("unexpected config_begin\n");
6719 case BOARD: /* board info */
6720 if (dgap_checknode(p))
6722 p->next = dgap_newnode(BNODE);
6724 dgap_err("out of memory");
6729 p->u.board.status = dgap_savestring("No");
6735 case APORT2_920P: /* AccelePort_4 */
6736 if (p->type != BNODE) {
6737 dgap_err("unexpected Digi_2r_920 string");
6740 p->u.board.type = APORT2_920P;
6741 p->u.board.v_type = 1;
6744 case APORT4_920P: /* AccelePort_4 */
6745 if (p->type != BNODE) {
6746 dgap_err("unexpected Digi_4r_920 string");
6749 p->u.board.type = APORT4_920P;
6750 p->u.board.v_type = 1;
6753 case APORT8_920P: /* AccelePort_8 */
6754 if (p->type != BNODE) {
6755 dgap_err("unexpected Digi_8r_920 string");
6758 p->u.board.type = APORT8_920P;
6759 p->u.board.v_type = 1;
6762 case PAPORT4: /* AccelePort_4 PCI */
6763 if (p->type != BNODE) {
6764 dgap_err("unexpected Digi_4r(PCI) string");
6767 p->u.board.type = PAPORT4;
6768 p->u.board.v_type = 1;
6771 case PAPORT8: /* AccelePort_8 PCI */
6772 if (p->type != BNODE) {
6773 dgap_err("unexpected Digi_8r string");
6776 p->u.board.type = PAPORT8;
6777 p->u.board.v_type = 1;
6780 case PCX: /* PCI C/X */
6781 if (p->type != BNODE) {
6782 dgap_err("unexpected Digi_C/X_(PCI) string");
6785 p->u.board.type = PCX;
6786 p->u.board.v_type = 1;
6787 p->u.board.conc1 = 0;
6788 p->u.board.conc2 = 0;
6789 p->u.board.module1 = 0;
6790 p->u.board.module2 = 0;
6793 case PEPC: /* PCI EPC/X */
6794 if (p->type != BNODE) {
6795 dgap_err("unexpected \"Digi_EPC/X_(PCI)\" string");
6798 p->u.board.type = PEPC;
6799 p->u.board.v_type = 1;
6800 p->u.board.conc1 = 0;
6801 p->u.board.conc2 = 0;
6802 p->u.board.module1 = 0;
6803 p->u.board.module2 = 0;
6806 case PPCM: /* PCI/Xem */
6807 if (p->type != BNODE) {
6808 dgap_err("unexpected PCI/Xem string");
6811 p->u.board.type = PPCM;
6812 p->u.board.v_type = 1;
6813 p->u.board.conc1 = 0;
6814 p->u.board.conc2 = 0;
6817 case IO: /* i/o port */
6818 if (p->type != BNODE) {
6819 dgap_err("IO port only vaild for boards");
6822 s = dgap_getword(in);
6824 dgap_err("unexpected end of file");
6827 p->u.board.portstr = dgap_savestring(s);
6828 p->u.board.port = (short)simple_strtol(s, &s2, 0);
6829 if ((short)strlen(s) > (short)(s2 - s)) {
6830 dgap_err("bad number for IO port");
6833 p->u.board.v_port = 1;
6836 case MEM: /* memory address */
6837 if (p->type != BNODE) {
6838 dgap_err("memory address only vaild for boards");
6841 s = dgap_getword(in);
6843 dgap_err("unexpected end of file");
6846 p->u.board.addrstr = dgap_savestring(s);
6847 p->u.board.addr = simple_strtoul(s, &s2, 0);
6848 if ((int)strlen(s) > (int)(s2 - s)) {
6849 dgap_err("bad number for memory address");
6852 p->u.board.v_addr = 1;
6855 case PCIINFO: /* pci information */
6856 if (p->type != BNODE) {
6857 dgap_err("memory address only vaild for boards");
6860 s = dgap_getword(in);
6862 dgap_err("unexpected end of file");
6865 p->u.board.pcibusstr = dgap_savestring(s);
6866 p->u.board.pcibus = simple_strtoul(s, &s2, 0);
6867 if ((int)strlen(s) > (int)(s2 - s)) {
6868 dgap_err("bad number for pci bus");
6871 p->u.board.v_pcibus = 1;
6872 s = dgap_getword(in);
6874 dgap_err("unexpected end of file");
6877 p->u.board.pcislotstr = dgap_savestring(s);
6878 p->u.board.pcislot = simple_strtoul(s, &s2, 0);
6879 if ((int)strlen(s) > (int)(s2 - s)) {
6880 dgap_err("bad number for pci slot");
6883 p->u.board.v_pcislot = 1;
6887 if (p->type != BNODE) {
6888 dgap_err("install method only vaild for boards");
6891 s = dgap_getword(in);
6893 dgap_err("unexpected end of file");
6896 p->u.board.method = dgap_savestring(s);
6897 p->u.board.v_method = 1;
6901 if (p->type != BNODE) {
6902 dgap_err("config status only vaild for boards");
6905 s = dgap_getword(in);
6907 dgap_err("unexpected end of file");
6910 p->u.board.status = dgap_savestring(s);
6913 case NPORTS: /* number of ports */
6914 if (p->type == BNODE) {
6915 s = dgap_getword(in);
6917 dgap_err("unexpected end of file");
6920 p->u.board.nport = (char)simple_strtol(s, &s2, 0);
6921 if ((int)strlen(s) > (int)(s2 - s)) {
6922 dgap_err("bad number for number of ports");
6925 p->u.board.v_nport = 1;
6926 } else if (p->type == CNODE) {
6927 s = dgap_getword(in);
6929 dgap_err("unexpected end of file");
6932 p->u.conc.nport = (char)simple_strtol(s, &s2, 0);
6933 if ((int)strlen(s) > (int)(s2 - s)) {
6934 dgap_err("bad number for number of ports");
6937 p->u.conc.v_nport = 1;
6938 } else if (p->type == MNODE) {
6939 s = dgap_getword(in);
6941 dgap_err("unexpected end of file");
6944 p->u.module.nport = (char)simple_strtol(s, &s2, 0);
6945 if ((int)strlen(s) > (int)(s2 - s)) {
6946 dgap_err("bad number for number of ports");
6949 p->u.module.v_nport = 1;
6951 dgap_err("nports only valid for concentrators or modules");
6956 case ID: /* letter ID used in tty name */
6957 s = dgap_getword(in);
6959 dgap_err("unexpected end of file");
6963 p->u.board.status = dgap_savestring(s);
6965 if (p->type == CNODE) {
6966 p->u.conc.id = dgap_savestring(s);
6968 } else if (p->type == MNODE) {
6969 p->u.module.id = dgap_savestring(s);
6970 p->u.module.v_id = 1;
6972 dgap_err("id only valid for concentrators or modules");
6977 case STARTO: /* start offset of ID */
6978 if (p->type == BNODE) {
6979 s = dgap_getword(in);
6981 dgap_err("unexpected end of file");
6984 p->u.board.start = simple_strtol(s, &s2, 0);
6985 if ((int)strlen(s) > (int)(s2 - s)) {
6986 dgap_err("bad number for start of tty count");
6989 p->u.board.v_start = 1;
6990 } else if (p->type == CNODE) {
6991 s = dgap_getword(in);
6993 dgap_err("unexpected end of file");
6996 p->u.conc.start = simple_strtol(s, &s2, 0);
6997 if ((int)strlen(s) > (int)(s2 - s)) {
6998 dgap_err("bad number for start of tty count");
7001 p->u.conc.v_start = 1;
7002 } else if (p->type == MNODE) {
7003 s = dgap_getword(in);
7005 dgap_err("unexpected end of file");
7008 p->u.module.start = simple_strtol(s, &s2, 0);
7009 if ((int)strlen(s) > (int)(s2 - s)) {
7010 dgap_err("bad number for start of tty count");
7013 p->u.module.v_start = 1;
7015 dgap_err("start only valid for concentrators or modules");
7020 case TTYN: /* tty name prefix */
7021 if (dgap_checknode(p))
7023 p->next = dgap_newnode(TNODE);
7025 dgap_err("out of memory");
7029 s = dgap_getword(in);
7031 dgap_err("unexpeced end of file");
7034 p->u.ttyname = dgap_savestring(s);
7035 if (!p->u.ttyname) {
7036 dgap_err("out of memory");
7041 case CU: /* cu name prefix */
7042 if (dgap_checknode(p))
7044 p->next = dgap_newnode(CUNODE);
7046 dgap_err("out of memory");
7050 s = dgap_getword(in);
7052 dgap_err("unexpeced end of file");
7055 p->u.cuname = dgap_savestring(s);
7057 dgap_err("out of memory");
7062 case LINE: /* line information */
7063 if (dgap_checknode(p))
7066 dgap_err("must specify board before line info");
7069 switch (brd->u.board.type) {
7071 dgap_err("line not vaild for PC/em");
7074 p->next = dgap_newnode(LNODE);
7076 dgap_err("out of memory");
7085 case CONC: /* concentrator information */
7086 if (dgap_checknode(p))
7089 dgap_err("must specify line info before concentrator");
7092 p->next = dgap_newnode(CNODE);
7094 dgap_err("out of memory");
7100 brd->u.board.conc2++;
7102 brd->u.board.conc1++;
7106 case CX: /* c/x type concentrator */
7107 if (p->type != CNODE) {
7108 dgap_err("cx only valid for concentrators");
7111 p->u.conc.type = CX;
7112 p->u.conc.v_type = 1;
7115 case EPC: /* epc type concentrator */
7116 if (p->type != CNODE) {
7117 dgap_err("cx only valid for concentrators");
7120 p->u.conc.type = EPC;
7121 p->u.conc.v_type = 1;
7124 case MOD: /* EBI module */
7125 if (dgap_checknode(p))
7128 dgap_err("must specify board info before EBI modules");
7131 switch (brd->u.board.type) {
7137 dgap_err("must specify concentrator info before EBI module");
7141 p->next = dgap_newnode(MNODE);
7143 dgap_err("out of memory");
7148 brd->u.board.module2++;
7150 brd->u.board.module1++;
7154 case PORTS: /* ports type EBI module */
7155 if (p->type != MNODE) {
7156 dgap_err("ports only valid for EBI modules");
7159 p->u.module.type = PORTS;
7160 p->u.module.v_type = 1;
7163 case MODEM: /* ports type EBI module */
7164 if (p->type != MNODE) {
7165 dgap_err("modem only valid for modem modules");
7168 p->u.module.type = MODEM;
7169 p->u.module.v_type = 1;
7173 if (p->type == LNODE) {
7174 s = dgap_getword(in);
7176 dgap_err("unexpected end of file");
7179 p->u.line.cable = dgap_savestring(s);
7180 p->u.line.v_cable = 1;
7184 case SPEED: /* sync line speed indication */
7185 if (p->type == LNODE) {
7186 s = dgap_getword(in);
7188 dgap_err("unexpected end of file");
7191 p->u.line.speed = (char)simple_strtol(s, &s2, 0);
7192 if ((short)strlen(s) > (short)(s2 - s)) {
7193 dgap_err("bad number for line speed");
7196 p->u.line.v_speed = 1;
7197 } else if (p->type == CNODE) {
7198 s = dgap_getword(in);
7200 dgap_err("unexpected end of file");
7203 p->u.conc.speed = (char)simple_strtol(s, &s2, 0);
7204 if ((short)strlen(s) > (short)(s2 - s)) {
7205 dgap_err("bad number for line speed");
7208 p->u.conc.v_speed = 1;
7210 dgap_err("speed valid only for lines or concentrators.");
7216 if (p->type == CNODE) {
7217 s = dgap_getword(in);
7219 dgap_err("unexpected end of file");
7222 p->u.conc.connect = dgap_savestring(s);
7223 p->u.conc.v_connect = 1;
7226 case PRINT: /* transparent print name prefix */
7227 if (dgap_checknode(p))
7229 p->next = dgap_newnode(PNODE);
7231 dgap_err("out of memory");
7235 s = dgap_getword(in);
7237 dgap_err("unexpeced end of file");
7240 p->u.printname = dgap_savestring(s);
7241 if (!p->u.printname) {
7242 dgap_err("out of memory");
7247 case CMAJOR: /* major number */
7248 if (dgap_checknode(p))
7250 p->next = dgap_newnode(JNODE);
7252 dgap_err("out of memory");
7256 s = dgap_getword(in);
7258 dgap_err("unexpected end of file");
7261 p->u.majornumber = simple_strtol(s, &s2, 0);
7262 if ((int)strlen(s) > (int)(s2 - s)) {
7263 dgap_err("bad number for major number");
7268 case ALTPIN: /* altpin setting */
7269 if (dgap_checknode(p))
7271 p->next = dgap_newnode(ANODE);
7273 dgap_err("out of memory");
7277 s = dgap_getword(in);
7279 dgap_err("unexpected end of file");
7282 p->u.altpin = simple_strtol(s, &s2, 0);
7283 if ((int)strlen(s) > (int)(s2 - s)) {
7284 dgap_err("bad number for altpin");
7289 case USEINTR: /* enable interrupt setting */
7290 if (dgap_checknode(p))
7292 p->next = dgap_newnode(INTRNODE);
7294 dgap_err("out of memory");
7298 s = dgap_getword(in);
7300 dgap_err("unexpected end of file");
7303 p->u.useintr = simple_strtol(s, &s2, 0);
7304 if ((int)strlen(s) > (int)(s2 - s)) {
7305 dgap_err("bad number for useintr");
7310 case TTSIZ: /* size of tty structure */
7311 if (dgap_checknode(p))
7313 p->next = dgap_newnode(TSNODE);
7315 dgap_err("out of memory");
7319 s = dgap_getword(in);
7321 dgap_err("unexpected end of file");
7324 p->u.ttysize = simple_strtol(s, &s2, 0);
7325 if ((int)strlen(s) > (int)(s2 - s)) {
7326 dgap_err("bad number for ttysize");
7331 case CHSIZ: /* channel structure size */
7332 if (dgap_checknode(p))
7334 p->next = dgap_newnode(CSNODE);
7336 dgap_err("out of memory");
7340 s = dgap_getword(in);
7342 dgap_err("unexpected end of file");
7345 p->u.chsize = simple_strtol(s, &s2, 0);
7346 if ((int)strlen(s) > (int)(s2 - s)) {
7347 dgap_err("bad number for chsize");
7352 case BSSIZ: /* board structure size */
7353 if (dgap_checknode(p))
7355 p->next = dgap_newnode(BSNODE);
7357 dgap_err("out of memory");
7361 s = dgap_getword(in);
7363 dgap_err("unexpected end of file");
7366 p->u.bssize = simple_strtol(s, &s2, 0);
7367 if ((int)strlen(s) > (int)(s2 - s)) {
7368 dgap_err("bad number for bssize");
7373 case UNTSIZ: /* sched structure size */
7374 if (dgap_checknode(p))
7376 p->next = dgap_newnode(USNODE);
7378 dgap_err("out of memory");
7382 s = dgap_getword(in);
7384 dgap_err("unexpected end of file");
7387 p->u.unsize = simple_strtol(s, &s2, 0);
7388 if ((int)strlen(s) > (int)(s2 - s)) {
7389 dgap_err("bad number for schedsize");
7394 case F2SIZ: /* f2200 structure size */
7395 if (dgap_checknode(p))
7397 p->next = dgap_newnode(FSNODE);
7399 dgap_err("out of memory");
7403 s = dgap_getword(in);
7405 dgap_err("unexpected end of file");
7408 p->u.f2size = simple_strtol(s, &s2, 0);
7409 if ((int)strlen(s) > (int)(s2 - s)) {
7410 dgap_err("bad number for f2200size");
7415 case VPSIZ: /* vpix structure size */
7416 if (dgap_checknode(p))
7418 p->next = dgap_newnode(VSNODE);
7420 dgap_err("out of memory");
7424 s = dgap_getword(in);
7426 dgap_err("unexpected end of file");
7429 p->u.vpixsize = simple_strtol(s, &s2, 0);
7430 if ((int)strlen(s) > (int)(s2 - s)) {
7431 dgap_err("bad number for vpixsize");
7440 * dgap_sindex: much like index(), but it looks for a match of any character in
7441 * the group, and returns that position. If the first character is a ^, then
7442 * this will match the first occurrence not in that group.
7444 static char *dgap_sindex(char *string, char *group)
7448 if (!string || !group)
7449 return (char *) NULL;
7451 if (*group == '^') {
7453 for (; *string; string++) {
7454 for (ptr = group; *ptr; ptr++) {
7455 if (*ptr == *string)
7462 for (; *string; string++) {
7463 for (ptr = group; *ptr; ptr++) {
7464 if (*ptr == *string)
7470 return (char *) NULL;
7474 * Get a token from the input file; return 0 if end of file is reached
7476 static int dgap_gettok(char **in, struct cnode *p)
7481 if (strstr(dgap_cword, "boar")) {
7482 w = dgap_getword(in);
7483 snprintf(dgap_cword, MAXCWORD, "%s", w);
7484 for (t = dgap_tlist; t->token != 0; t++) {
7485 if (!strcmp(w, t->string))
7488 dgap_err("board !!type not specified");
7491 while ((w = dgap_getword(in))) {
7492 snprintf(dgap_cword, MAXCWORD, "%s", w);
7493 for (t = dgap_tlist; t->token != 0; t++) {
7494 if (!strcmp(w, t->string))
7503 * get a word from the input stream, also keep track of current line number.
7504 * words are separated by whitespace.
7506 static char *dgap_getword(char **in)
7508 char *ret_ptr = *in;
7510 char *ptr = dgap_sindex(*in, " \t\n");
7512 /* If no word found, return null */
7516 /* Mark new location for our buffer */
7520 /* Eat any extra spaces/tabs/newlines that might be present */
7521 while (*in && **in && ((**in == ' ') || (**in == '\t') || (**in == '\n'))) {
7530 * print an error message, giving the line number in the file where
7531 * the error occurred.
7533 static void dgap_err(char *s)
7535 pr_err("dgap: parse: %s\n", s);
7539 * allocate a new configuration node of type t
7541 static struct cnode *dgap_newnode(int t)
7545 n = kmalloc(sizeof(struct cnode), GFP_ATOMIC);
7547 memset((char *)n, 0, sizeof(struct cnode));
7554 * dgap_checknode: see if all the necessary info has been supplied for a node
7555 * before creating the next node.
7557 static int dgap_checknode(struct cnode *p)
7561 if (p->u.board.v_type == 0) {
7562 dgap_err("board type !not specified");
7569 if (p->u.line.v_speed == 0) {
7570 dgap_err("line speed not specified");
7576 if (p->u.conc.v_type == 0) {
7577 dgap_err("concentrator type not specified");
7580 if (p->u.conc.v_speed == 0) {
7581 dgap_err("concentrator line speed not specified");
7584 if (p->u.conc.v_nport == 0) {
7585 dgap_err("number of ports on concentrator not specified");
7588 if (p->u.conc.v_id == 0) {
7589 dgap_err("concentrator id letter not specified");
7595 if (p->u.module.v_type == 0) {
7596 dgap_err("EBI module type not specified");
7599 if (p->u.module.v_nport == 0) {
7600 dgap_err("number of ports on EBI module not specified");
7603 if (p->u.module.v_id == 0) {
7604 dgap_err("EBI module id letter not specified");
7613 * save a string somewhere
7615 static char *dgap_savestring(char *s)
7619 p = kmalloc(strlen(s) + 1, GFP_ATOMIC);
7626 * Given a board pointer, returns whether we should use interrupts or not.
7628 static uint dgap_config_get_useintr(struct board_t *bd)
7630 struct cnode *p = NULL;
7635 for (p = bd->bd_config; p; p = p->next) {
7639 * check for pcxr types.
7641 return p->u.useintr;
7647 /* If not found, then don't turn on interrupts. */
7652 * Given a board pointer, returns whether we turn on altpin or not.
7654 static uint dgap_config_get_altpin(struct board_t *bd)
7656 struct cnode *p = NULL;
7661 for (p = bd->bd_config; p; p = p->next) {
7665 * check for pcxr types.
7673 /* If not found, then don't turn on interrupts. */
7678 * Given a specific type of board, if found, detached link and
7679 * returns the first occurrence in the list.
7681 static struct cnode *dgap_find_config(int type, int bus, int slot)
7683 struct cnode *p, *prev = NULL, *prev2 = NULL, *found = NULL;
7687 while (p->next != NULL) {
7691 if (p->type == BNODE) {
7693 if (p->u.board.type == type) {
7695 if (p->u.board.v_pcibus &&
7696 p->u.board.pcibus != bus)
7698 if (p->u.board.v_pcislot &&
7699 p->u.board.pcislot != slot)
7704 * Keep walking thru the list till we find the next board.
7706 while (p->next != NULL) {
7709 if (p->type == BNODE) {
7712 * Mark the end of our 1 board chain of configs.
7717 * Link the "next" board to the previous board,
7718 * effectively "unlinking" our board from the main config.
7726 * It must be the last board in the list.
7737 * Given a board pointer, walks the config link, counting up
7738 * all ports user specified should be on the board.
7739 * (This does NOT mean they are all actually present right now tho)
7741 static uint dgap_config_get_number_of_ports(struct board_t *bd)
7744 struct cnode *p = NULL;
7749 for (p = bd->bd_config; p; p = p->next) {
7754 * check for pcxr types.
7756 if (p->u.board.type > EPCFE)
7757 count += p->u.board.nport;
7760 count += p->u.conc.nport;
7763 count += p->u.module.nport;
7770 static char *dgap_create_config_string(struct board_t *bd, char *string)
7773 struct cnode *p = NULL;
7774 struct cnode *q = NULL;
7782 for (p = bd->bd_config; p; p = p->next) {
7788 *ptr = p->u.line.speed;
7793 * Because the EPC/con concentrators can have EM modules
7794 * hanging off of them, we have to walk ahead in the list
7795 * and keep adding the number of ports on each EM to the config.
7798 speed = p->u.conc.speed;
7800 if ((q != NULL) && (q->type == MNODE)) {
7801 *ptr = (p->u.conc.nport + 0x80);
7804 while ((q->next != NULL) && (q->next->type) == MNODE) {
7805 *ptr = (q->u.module.nport + 0x80);
7810 *ptr = q->u.module.nport;
7813 *ptr = p->u.conc.nport;