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 MODULE_LICENSE("GPL");
82 MODULE_AUTHOR("Digi International, http://www.digi.com");
83 MODULE_DESCRIPTION("Driver for the Digi International EPCA PCI based product line");
84 MODULE_SUPPORTED_DEVICE("dgap");
86 /**************************************************************************
88 * protos for this file
92 static int dgap_start(void);
93 static void dgap_init_globals(void);
94 static int dgap_found_board(struct pci_dev *pdev, int id);
95 static void dgap_cleanup_board(struct board_t *brd);
96 static void dgap_poll_handler(ulong dummy);
97 static int dgap_init_pci(void);
98 static int dgap_init_one(struct pci_dev *pdev, const struct pci_device_id *ent);
99 static void dgap_remove_one(struct pci_dev *dev);
100 static int dgap_probe1(struct pci_dev *pdev, int card_type);
101 static int dgap_do_remap(struct board_t *brd);
102 static irqreturn_t dgap_intr(int irq, void *voidbrd);
104 /* Our function prototypes */
105 static int dgap_tty_open(struct tty_struct *tty, struct file *file);
106 static void dgap_tty_close(struct tty_struct *tty, struct file *file);
107 static int dgap_block_til_ready(struct tty_struct *tty, struct file *file,
108 struct channel_t *ch);
109 static int dgap_tty_ioctl(struct tty_struct *tty, unsigned int cmd,
111 static int dgap_tty_digigeta(struct tty_struct *tty,
112 struct digi_t __user *retinfo);
113 static int dgap_tty_digiseta(struct tty_struct *tty,
114 struct digi_t __user *new_info);
115 static int dgap_tty_digigetedelay(struct tty_struct *tty, int __user *retinfo);
116 static int dgap_tty_digisetedelay(struct tty_struct *tty, int __user *new_info);
117 static int dgap_tty_write_room(struct tty_struct *tty);
118 static int dgap_tty_chars_in_buffer(struct tty_struct *tty);
119 static void dgap_tty_start(struct tty_struct *tty);
120 static void dgap_tty_stop(struct tty_struct *tty);
121 static void dgap_tty_throttle(struct tty_struct *tty);
122 static void dgap_tty_unthrottle(struct tty_struct *tty);
123 static void dgap_tty_flush_chars(struct tty_struct *tty);
124 static void dgap_tty_flush_buffer(struct tty_struct *tty);
125 static void dgap_tty_hangup(struct tty_struct *tty);
126 static int dgap_wait_for_drain(struct tty_struct *tty);
127 static int dgap_set_modem_info(struct tty_struct *tty, unsigned int command,
128 unsigned int __user *value);
129 static int dgap_get_modem_info(struct channel_t *ch,
130 unsigned int __user *value);
131 static int dgap_tty_digisetcustombaud(struct tty_struct *tty,
132 int __user *new_info);
133 static int dgap_tty_digigetcustombaud(struct tty_struct *tty,
134 int __user *retinfo);
135 static int dgap_tty_tiocmget(struct tty_struct *tty);
136 static int dgap_tty_tiocmset(struct tty_struct *tty, unsigned int set,
138 static int dgap_tty_send_break(struct tty_struct *tty, int msec);
139 static void dgap_tty_wait_until_sent(struct tty_struct *tty, int timeout);
140 static int dgap_tty_write(struct tty_struct *tty, const unsigned char *buf,
142 static void dgap_tty_set_termios(struct tty_struct *tty,
143 struct ktermios *old_termios);
144 static int dgap_tty_put_char(struct tty_struct *tty, unsigned char c);
145 static void dgap_tty_send_xchar(struct tty_struct *tty, char ch);
147 static int dgap_tty_register(struct board_t *brd);
148 static int dgap_tty_init(struct board_t *);
149 static void dgap_tty_uninit(struct board_t *);
150 static void dgap_carrier(struct channel_t *ch);
151 static void dgap_input(struct channel_t *ch);
154 * Our function prototypes from dgap_fep5
156 static void dgap_cmdw_ext(struct channel_t *ch, u16 cmd, u16 word, uint ncmds);
157 static int dgap_event(struct board_t *bd);
159 static void dgap_poll_tasklet(unsigned long data);
160 static void dgap_cmdb(struct channel_t *ch, uchar cmd, uchar byte1,
161 uchar byte2, uint ncmds);
162 static void dgap_cmdw(struct channel_t *ch, uchar cmd, u16 word, uint ncmds);
163 static void dgap_wmove(struct channel_t *ch, char *buf, uint cnt);
164 static int dgap_param(struct tty_struct *tty);
165 static void dgap_parity_scan(struct channel_t *ch, unsigned char *cbuf,
166 unsigned char *fbuf, int *len);
167 static uint dgap_get_custom_baud(struct channel_t *ch);
168 static void dgap_firmware_reset_port(struct channel_t *ch);
171 * Function prototypes from dgap_parse.c.
173 static int dgap_gettok(char **in, struct cnode *p);
174 static char *dgap_getword(char **in);
175 static char *dgap_savestring(char *s);
176 static struct cnode *dgap_newnode(int t);
177 static int dgap_checknode(struct cnode *p);
178 static void dgap_err(char *s);
181 * Function prototypes from dgap_sysfs.h
189 static void dgap_create_ports_sysfiles(struct board_t *bd);
190 static void dgap_remove_ports_sysfiles(struct board_t *bd);
192 static int dgap_create_driver_sysfiles(struct pci_driver *);
193 static void dgap_remove_driver_sysfiles(struct pci_driver *);
195 static void dgap_create_tty_sysfs(struct un_t *un, struct device *c);
196 static void dgap_remove_tty_sysfs(struct device *c);
199 * Function prototypes from dgap_parse.h
201 static int dgap_parsefile(char **in, int Remove);
202 static struct cnode *dgap_find_config(int type, int bus, int slot);
203 static uint dgap_config_get_num_prts(struct board_t *bd);
204 static char *dgap_create_config_string(struct board_t *bd, char *string);
205 static uint dgap_config_get_useintr(struct board_t *bd);
206 static uint dgap_config_get_altpin(struct board_t *bd);
208 static int dgap_ms_sleep(ulong ms);
209 static void dgap_do_bios_load(struct board_t *brd, const uchar *ubios, int len);
210 static void dgap_do_fep_load(struct board_t *brd, const uchar *ufep, int len);
211 #ifdef DIGI_CONCENTRATORS_SUPPORTED
212 static void dgap_do_conc_load(struct board_t *brd, uchar *uaddr, int len);
214 static int dgap_after_config_loaded(int board);
215 static int dgap_finalize_board_init(struct board_t *brd);
217 static void dgap_get_vpd(struct board_t *brd);
218 static void dgap_do_reset_board(struct board_t *brd);
219 static int dgap_do_wait_for_bios(struct board_t *brd);
220 static int dgap_do_wait_for_fep(struct board_t *brd);
221 static int dgap_tty_register_ports(struct board_t *brd);
222 static int dgap_firmware_load(struct pci_dev *pdev, int card_type);
224 /* Driver unload function */
225 static void dgap_cleanup_module(void);
227 module_exit(dgap_cleanup_module);
230 * File operations permitted on Control/Management major.
232 static const struct file_operations DgapBoardFops = {
233 .owner = THIS_MODULE,
239 static uint dgap_NumBoards;
240 static struct board_t *dgap_Board[MAXBOARDS];
241 static ulong dgap_poll_counter;
242 static char *dgap_config_buf;
243 static int dgap_driver_state = DRIVER_INITIALIZED;
244 static wait_queue_head_t dgap_dl_wait;
245 static int dgap_poll_tick = 20; /* Poll interval - 20 ms */
250 static struct class *dgap_class;
252 static struct board_t *dgap_BoardsByMajor[256];
253 static uint dgap_count = 500;
258 DEFINE_SPINLOCK(dgap_poll_lock); /* Poll scheduling lock */
259 static ulong dgap_poll_time; /* Time of next poll */
260 static uint dgap_poll_stop; /* Used to tell poller to stop */
261 static struct timer_list dgap_poll_timer;
266 Card Model Number of Ports Interface
267 ----------------------------------------------------------------
268 Acceleport Xem 4 - 64 (EIA232 & EIA422)
269 Acceleport Xr 4 & 8 (EIA232)
270 Acceleport Xr 920 4 & 8 (EIA232)
271 Acceleport C/X 8 - 128 (EIA232)
272 Acceleport EPC/X 8 - 224 (EIA232)
273 Acceleport Xr/422 4 & 8 (EIA422)
274 Acceleport 2r/920 2 (EIA232)
275 Acceleport 4r/920 4 (EIA232)
276 Acceleport 8r/920 8 (EIA232)
278 IBM 8-Port Asynchronous PCI Adapter (EIA232)
279 IBM 128-Port Asynchronous PCI Adapter (EIA232 & EIA422)
282 static struct pci_device_id dgap_pci_tbl[] = {
283 { DIGI_VID, PCI_DEV_XEM_DID, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0 },
284 { DIGI_VID, PCI_DEV_CX_DID, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 1 },
285 { DIGI_VID, PCI_DEV_CX_IBM_DID, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 2 },
286 { DIGI_VID, PCI_DEV_EPCJ_DID, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 3 },
287 { DIGI_VID, PCI_DEV_920_2_DID, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 4 },
288 { DIGI_VID, PCI_DEV_920_4_DID, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 5 },
289 { DIGI_VID, PCI_DEV_920_8_DID, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 6 },
290 { DIGI_VID, PCI_DEV_XR_DID, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 7 },
291 { DIGI_VID, PCI_DEV_XRJ_DID, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 8 },
292 { DIGI_VID, PCI_DEV_XR_422_DID, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 9 },
293 { DIGI_VID, PCI_DEV_XR_IBM_DID, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 10 },
294 { DIGI_VID, PCI_DEV_XR_SAIP_DID, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 11 },
295 { DIGI_VID, PCI_DEV_XR_BULL_DID, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 12 },
296 { DIGI_VID, PCI_DEV_920_8_HP_DID, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 13 },
297 { DIGI_VID, PCI_DEV_XEM_HP_DID, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 14 },
298 {0,} /* 0 terminated list. */
300 MODULE_DEVICE_TABLE(pci, dgap_pci_tbl);
303 * A generic list of Product names, PCI Vendor ID, and PCI Device ID.
312 static struct board_id dgap_Ids[] = {
313 { PPCM, PCI_DEV_XEM_NAME, 64, (T_PCXM|T_PCLITE|T_PCIBUS) },
314 { PCX, PCI_DEV_CX_NAME, 128, (T_CX|T_PCIBUS) },
315 { PCX, PCI_DEV_CX_IBM_NAME, 128, (T_CX|T_PCIBUS) },
316 { PEPC, PCI_DEV_EPCJ_NAME, 224, (T_EPC|T_PCIBUS) },
317 { APORT2_920P, PCI_DEV_920_2_NAME, 2, (T_PCXR|T_PCLITE|T_PCIBUS) },
318 { APORT4_920P, PCI_DEV_920_4_NAME, 4, (T_PCXR|T_PCLITE|T_PCIBUS) },
319 { APORT8_920P, PCI_DEV_920_8_NAME, 8, (T_PCXR|T_PCLITE|T_PCIBUS) },
320 { PAPORT8, PCI_DEV_XR_NAME, 8, (T_PCXR|T_PCLITE|T_PCIBUS) },
321 { PAPORT8, PCI_DEV_XRJ_NAME, 8, (T_PCXR|T_PCLITE|T_PCIBUS) },
322 { PAPORT8, PCI_DEV_XR_422_NAME, 8, (T_PCXR|T_PCLITE|T_PCIBUS) },
323 { PAPORT8, PCI_DEV_XR_IBM_NAME, 8, (T_PCXR|T_PCLITE|T_PCIBUS) },
324 { PAPORT8, PCI_DEV_XR_SAIP_NAME, 8, (T_PCXR|T_PCLITE|T_PCIBUS) },
325 { PAPORT8, PCI_DEV_XR_BULL_NAME, 8, (T_PCXR|T_PCLITE|T_PCIBUS) },
326 { APORT8_920P, PCI_DEV_920_8_HP_NAME, 8, (T_PCXR|T_PCLITE|T_PCIBUS) },
327 { PPCM, PCI_DEV_XEM_HP_NAME, 64, (T_PCXM|T_PCLITE|T_PCIBUS) },
328 {0,} /* 0 terminated list. */
331 static struct pci_driver dgap_driver = {
333 .probe = dgap_init_one,
334 .id_table = dgap_pci_tbl,
335 .remove = dgap_remove_one,
338 struct firmware_info {
339 uchar *conf_name; /* dgap.conf */
340 uchar *bios_name; /* BIOS filename */
341 uchar *fep_name; /* FEP filename */
342 uchar *con_name; /* Concentrator filename FIXME*/
343 int num; /* sequence number */
347 * Firmware - BIOS, FEP, and CONC filenames
349 static struct firmware_info fw_info[] = {
350 { "dgap/dgap.conf", "dgap/sxbios.bin", "dgap/sxfep.bin", 0, 0 },
351 { "dgap/dgap.conf", "dgap/cxpbios.bin", "dgap/cxpfep.bin", 0, 1 },
352 { "dgap/dgap.conf", "dgap/cxpbios.bin", "dgap/cxpfep.bin", 0, 2 },
353 { "dgap/dgap.conf", "dgap/pcibios.bin", "dgap/pcifep.bin", 0, 3 },
354 { "dgap/dgap.conf", "dgap/xrbios.bin", "dgap/xrfep.bin", 0, 4 },
355 { "dgap/dgap.conf", "dgap/xrbios.bin", "dgap/xrfep.bin", 0, 5 },
356 { "dgap/dgap.conf", "dgap/xrbios.bin", "dgap/xrfep.bin", 0, 6 },
357 { "dgap/dgap.conf", "dgap/xrbios.bin", "dgap/xrfep.bin", 0, 7 },
358 { "dgap/dgap.conf", "dgap/xrbios.bin", "dgap/xrfep.bin", 0, 8 },
359 { "dgap/dgap.conf", "dgap/xrbios.bin", "dgap/xrfep.bin", 0, 9 },
360 { "dgap/dgap.conf", "dgap/xrbios.bin", "dgap/xrfep.bin", 0, 10 },
361 { "dgap/dgap.conf", "dgap/xrbios.bin", "dgap/xrfep.bin", 0, 11 },
362 { "dgap/dgap.conf", "dgap/xrbios.bin", "dgap/xrfep.bin", 0, 12 },
363 { "dgap/dgap.conf", "dgap/xrbios.bin", "dgap/xrfep.bin", 0, 13 },
364 { "dgap/dgap.conf", "dgap/sxbios.bin", "dgap/sxfep.bin", 0, 14 },
369 * Default transparent print information.
371 static struct digi_t dgap_digi_init = {
372 .digi_flags = DIGI_COOK, /* Flags */
373 .digi_maxcps = 100, /* Max CPS */
374 .digi_maxchar = 50, /* Max chars in print queue */
375 .digi_bufsize = 100, /* Printer buffer size */
376 .digi_onlen = 4, /* size of printer on string */
377 .digi_offlen = 4, /* size of printer off string */
378 .digi_onstr = "\033[5i", /* ANSI printer on string ] */
379 .digi_offstr = "\033[4i", /* ANSI printer off string ] */
380 .digi_term = "ansi" /* default terminal type */
384 * Define a local default termios struct. All ports will be created
385 * with this termios initially.
387 * This defines a raw port at 9600 baud, 8 data bits, no parity,
391 static struct ktermios DgapDefaultTermios = {
392 .c_iflag = (DEFAULT_IFLAGS), /* iflags */
393 .c_oflag = (DEFAULT_OFLAGS), /* oflags */
394 .c_cflag = (DEFAULT_CFLAGS), /* cflags */
395 .c_lflag = (DEFAULT_LFLAGS), /* lflags */
400 static const struct tty_operations dgap_tty_ops = {
401 .open = dgap_tty_open,
402 .close = dgap_tty_close,
403 .write = dgap_tty_write,
404 .write_room = dgap_tty_write_room,
405 .flush_buffer = dgap_tty_flush_buffer,
406 .chars_in_buffer = dgap_tty_chars_in_buffer,
407 .flush_chars = dgap_tty_flush_chars,
408 .ioctl = dgap_tty_ioctl,
409 .set_termios = dgap_tty_set_termios,
410 .stop = dgap_tty_stop,
411 .start = dgap_tty_start,
412 .throttle = dgap_tty_throttle,
413 .unthrottle = dgap_tty_unthrottle,
414 .hangup = dgap_tty_hangup,
415 .put_char = dgap_tty_put_char,
416 .tiocmget = dgap_tty_tiocmget,
417 .tiocmset = dgap_tty_tiocmset,
418 .break_ctl = dgap_tty_send_break,
419 .wait_until_sent = dgap_tty_wait_until_sent,
420 .send_xchar = dgap_tty_send_xchar
424 * Our needed internal static variables from dgap_parse.c
426 static struct cnode dgap_head;
428 static char dgap_cword[MAXCWORD];
435 static struct toklist dgap_tlist[] = {
436 { BEGIN, "config_begin" },
437 { END, "config_end" },
439 { PCX, "Digi_AccelePort_C/X_PCI" },
440 { PEPC, "Digi_AccelePort_EPC/X_PCI" },
441 { PPCM, "Digi_AccelePort_Xem_PCI" },
442 { APORT2_920P, "Digi_AccelePort_2r_920_PCI" },
443 { APORT4_920P, "Digi_AccelePort_4r_920_PCI" },
444 { APORT8_920P, "Digi_AccelePort_8r_920_PCI" },
445 { PAPORT4, "Digi_AccelePort_4r_PCI(EIA-232/RS-422)" },
446 { PAPORT8, "Digi_AccelePort_8r_PCI(EIA-232/RS-422)" },
448 { PCIINFO, "pciinfo" },
451 { CONC, "concentrator" },
461 { CONNECT, "connect" },
462 { METHOD, "method" },
463 { STATUS, "status" },
464 { CUSTOM, "Custom" },
470 { NPORTS, "nports" },
475 { ALTPIN, "altpin" },
476 { USEINTR, "useintr" },
477 { TTSIZ, "ttysize" },
479 { BSSIZ, "boardsize" },
480 { UNTSIZ, "schedsize" },
481 { F2SIZ, "f2200size" },
482 { VPSIZ, "vpixsize" },
486 /************************************************************************
488 * Driver load/unload functions
490 ************************************************************************/
495 * Module load. This is where it all starts.
497 static int dgap_init_module(void)
501 pr_info("%s, Digi International Part Number %s\n", DG_NAME, DG_PART);
507 rc = dgap_init_pci();
511 rc = dgap_create_driver_sysfiles(&dgap_driver);
515 dgap_driver_state = DRIVER_READY;
521 dgap_cleanup_module();
525 module_init(dgap_init_module);
530 static int dgap_start(void)
534 struct device *device;
537 * make sure that the globals are
538 * init'd before we do anything else
544 pr_info("For the tools package please visit http://www.digi.com\n");
547 * Register our base character device into the kernel.
551 * Register management/dpa devices
553 rc = register_chrdev(DIGI_DGAP_MAJOR, "dgap", &DgapBoardFops);
557 dgap_class = class_create(THIS_MODULE, "dgap_mgmt");
558 if (IS_ERR(dgap_class)) {
559 rc = PTR_ERR(dgap_class);
563 device = device_create(dgap_class, NULL,
564 MKDEV(DIGI_DGAP_MAJOR, 0),
566 if (IS_ERR(device)) {
567 rc = PTR_ERR(device);
571 /* Start the poller */
572 spin_lock_irqsave(&dgap_poll_lock, flags);
573 init_timer(&dgap_poll_timer);
574 dgap_poll_timer.function = dgap_poll_handler;
575 dgap_poll_timer.data = 0;
576 dgap_poll_time = jiffies + dgap_jiffies_from_ms(dgap_poll_tick);
577 dgap_poll_timer.expires = dgap_poll_time;
578 spin_unlock_irqrestore(&dgap_poll_lock, flags);
580 add_timer(&dgap_poll_timer);
585 class_destroy(dgap_class);
587 unregister_chrdev(DIGI_DGAP_MAJOR, "dgap");
592 * Register pci driver, and return how many boards we have.
594 static int dgap_init_pci(void)
596 return pci_register_driver(&dgap_driver);
599 /* returns count (>= 0), or negative on error */
600 static int dgap_init_one(struct pci_dev *pdev, const struct pci_device_id *ent)
604 /* wake up and enable device */
605 rc = pci_enable_device(pdev);
610 rc = dgap_probe1(pdev, ent->driver_data);
613 rc = dgap_firmware_load(pdev, ent->driver_data);
619 static int dgap_probe1(struct pci_dev *pdev, int card_type)
621 return dgap_found_board(pdev, card_type);
624 static void dgap_remove_one(struct pci_dev *dev)
630 * dgap_cleanup_module()
632 * Module unload. This is where it all ends.
634 static void dgap_cleanup_module(void)
639 spin_lock_irqsave(&dgap_poll_lock, lock_flags);
641 spin_unlock_irqrestore(&dgap_poll_lock, lock_flags);
643 /* Turn off poller right away. */
644 del_timer_sync(&dgap_poll_timer);
646 dgap_remove_driver_sysfiles(&dgap_driver);
648 device_destroy(dgap_class, MKDEV(DIGI_DGAP_MAJOR, 0));
649 class_destroy(dgap_class);
650 unregister_chrdev(DIGI_DGAP_MAJOR, "dgap");
652 kfree(dgap_config_buf);
654 for (i = 0; i < dgap_NumBoards; ++i) {
655 dgap_remove_ports_sysfiles(dgap_Board[i]);
656 dgap_tty_uninit(dgap_Board[i]);
657 dgap_cleanup_board(dgap_Board[i]);
661 pci_unregister_driver(&dgap_driver);
665 * dgap_cleanup_board()
667 * Free all the memory associated with a board
669 static void dgap_cleanup_board(struct board_t *brd)
673 if (!brd || brd->magic != DGAP_BOARD_MAGIC)
676 if (brd->intr_used && brd->irq)
677 free_irq(brd->irq, brd);
679 tasklet_kill(&brd->helper_tasklet);
681 if (brd->re_map_port) {
682 release_mem_region(brd->membase + 0x200000, 0x200000);
683 iounmap(brd->re_map_port);
684 brd->re_map_port = NULL;
687 if (brd->re_map_membase) {
688 release_mem_region(brd->membase, 0x200000);
689 iounmap(brd->re_map_membase);
690 brd->re_map_membase = NULL;
693 /* Free all allocated channels structs */
694 for (i = 0; i < MAXPORTS ; i++)
695 kfree(brd->channels[i]);
698 kfree(brd->flipflagbuf);
700 dgap_Board[brd->boardnum] = NULL;
708 * A board has been found, init it.
710 static int dgap_found_board(struct pci_dev *pdev, int id)
713 unsigned int pci_irq;
716 /* get the board structure and prep it */
717 brd = kzalloc(sizeof(struct board_t), GFP_KERNEL);
721 dgap_Board[dgap_NumBoards] = brd;
723 /* store the info for the board we've found */
724 brd->magic = DGAP_BOARD_MAGIC;
725 brd->boardnum = dgap_NumBoards;
727 brd->vendor = dgap_pci_tbl[id].vendor;
728 brd->device = dgap_pci_tbl[id].device;
730 brd->pci_bus = pdev->bus->number;
731 brd->pci_slot = PCI_SLOT(pdev->devfn);
732 brd->name = dgap_Ids[id].name;
733 brd->maxports = dgap_Ids[id].maxports;
734 brd->type = dgap_Ids[id].config_type;
735 brd->dpatype = dgap_Ids[id].dpatype;
736 brd->dpastatus = BD_NOFEP;
737 init_waitqueue_head(&brd->state_wait);
739 spin_lock_init(&brd->bd_lock);
742 brd->inhibit_poller = FALSE;
743 brd->wait_for_bios = 0;
744 brd->wait_for_fep = 0;
746 for (i = 0; i < MAXPORTS; i++)
747 brd->channels[i] = NULL;
749 /* store which card & revision we have */
750 pci_read_config_word(pdev, PCI_SUBSYSTEM_VENDOR_ID, &brd->subvendor);
751 pci_read_config_word(pdev, PCI_SUBSYSTEM_ID, &brd->subdevice);
752 pci_read_config_byte(pdev, PCI_REVISION_ID, &brd->rev);
757 /* get the PCI Base Address Registers */
759 /* Xr Jupiter and EPC use BAR 2 */
760 if (brd->device == PCI_DEV_XRJ_DID || brd->device == PCI_DEV_EPCJ_DID) {
761 brd->membase = pci_resource_start(pdev, 2);
762 brd->membase_end = pci_resource_end(pdev, 2);
764 /* Everyone else uses BAR 0 */
766 brd->membase = pci_resource_start(pdev, 0);
767 brd->membase_end = pci_resource_end(pdev, 0);
773 if (brd->membase & 1)
779 * On the PCI boards, there is no IO space allocated
780 * The I/O registers will be in the first 3 bytes of the
781 * upper 2MB of the 4MB memory space. The board memory
782 * will be mapped into the low 2MB of the 4MB memory space
784 brd->port = brd->membase + PCI_IO_OFFSET;
785 brd->port_end = brd->port + PCI_IO_SIZE;
788 * Special initialization for non-PLX boards
790 if (brd->device != PCI_DEV_XRJ_DID && brd->device != PCI_DEV_EPCJ_DID) {
793 pci_write_config_byte(pdev, 0x40, 0);
794 pci_write_config_byte(pdev, 0x46, 0);
796 /* Limit burst length to 2 doubleword transactions */
797 pci_write_config_byte(pdev, 0x42, 1);
800 * Enable IO and mem if not already done.
801 * This was needed for support on Itanium.
803 pci_read_config_word(pdev, PCI_COMMAND, &cmd);
804 cmd |= (PCI_COMMAND_IO | PCI_COMMAND_MEMORY);
805 pci_write_config_word(pdev, PCI_COMMAND, cmd);
808 /* init our poll helper tasklet */
809 tasklet_init(&brd->helper_tasklet, dgap_poll_tasklet,
810 (unsigned long) brd);
812 i = dgap_do_remap(brd);
814 brd->state = BOARD_FAILED;
816 pr_info("dgap: board %d: %s (rev %d), irq %ld, %s\n",
817 dgap_NumBoards, brd->name, brd->rev, brd->irq,
818 brd->state ? "NOT READY\0" : "READY\0");
824 static int dgap_finalize_board_init(struct board_t *brd)
828 if (!brd || brd->magic != DGAP_BOARD_MAGIC)
831 brd->use_interrupts = dgap_config_get_useintr(brd);
834 * Set up our interrupt handler if we are set to do interrupts.
836 if (brd->use_interrupts && brd->irq) {
838 rc = request_irq(brd->irq, dgap_intr, IRQF_SHARED, "DGAP", brd);
851 static int dgap_firmware_load(struct pci_dev *pdev, int card_type)
853 struct board_t *brd = dgap_Board[dgap_NumBoards - 1];
854 const struct firmware *fw;
858 dgap_do_reset_board(brd);
860 if (fw_info[card_type].conf_name) {
861 ret = request_firmware(&fw, fw_info[card_type].conf_name,
864 pr_err("dgap: config file %s not found\n",
865 fw_info[card_type].conf_name);
868 if (!dgap_config_buf) {
869 dgap_config_buf = kmalloc(fw->size + 1, GFP_ATOMIC);
870 if (!dgap_config_buf) {
871 release_firmware(fw);
876 memcpy(dgap_config_buf, fw->data, fw->size);
877 release_firmware(fw);
878 dgap_config_buf[fw->size + 1] = '\0';
880 if (dgap_parsefile(&dgap_config_buf, TRUE) != 0)
884 ret = dgap_after_config_loaded(brd->boardnum);
888 * Match this board to a config the user created for us.
891 dgap_find_config(brd->type, brd->pci_bus, brd->pci_slot);
894 * Because the 4 port Xr products share the same PCI ID
895 * as the 8 port Xr products, if we receive a NULL config
896 * back, and this is a PAPORT8 board, retry with a
897 * PAPORT4 attempt as well.
899 if (brd->type == PAPORT8 && !brd->bd_config)
901 dgap_find_config(PAPORT4, brd->pci_bus, brd->pci_slot);
903 if (!brd->bd_config) {
904 pr_err("dgap: No valid configuration found\n");
908 dgap_tty_register(brd);
909 dgap_finalize_board_init(brd);
911 if (fw_info[card_type].bios_name) {
912 ret = request_firmware(&fw, fw_info[card_type].bios_name,
915 pr_err("dgap: bios file %s not found\n",
916 fw_info[card_type].bios_name);
919 dgap_do_bios_load(brd, fw->data, fw->size);
920 release_firmware(fw);
922 /* Wait for BIOS to test board... */
923 if (!dgap_do_wait_for_bios(brd))
927 if (fw_info[card_type].fep_name) {
928 ret = request_firmware(&fw, fw_info[card_type].fep_name,
931 pr_err("dgap: fep file %s not found\n",
932 fw_info[card_type].fep_name);
935 dgap_do_fep_load(brd, fw->data, fw->size);
936 release_firmware(fw);
938 /* Wait for FEP to load on board... */
939 if (!dgap_do_wait_for_fep(brd))
943 #ifdef DIGI_CONCENTRATORS_SUPPORTED
945 * If this is a CX or EPCX, we need to see if the firmware
946 * is requesting a concentrator image from us.
948 if ((bd->type == PCX) || (bd->type == PEPC)) {
949 chk_addr = (u16 *) (vaddr + DOWNREQ);
950 /* Nonzero if FEP is requesting concentrator image. */
951 check = readw(chk_addr);
952 vaddr = brd->re_map_membase;
955 if (fw_info[card_type].con_name && check && vaddr) {
956 ret = request_firmware(&fw, fw_info[card_type].con_name,
959 pr_err("dgap: conc file %s not found\n",
960 fw_info[card_type].con_name);
963 /* Put concentrator firmware loading code here */
964 offset = readw((u16 *) (vaddr + DOWNREQ));
965 memcpy_toio(offset, fw->data, fw->size);
967 dgap_do_conc_load(brd, (char *)fw->data, fw->size)
968 release_firmware(fw);
972 * Do tty device initialization.
974 ret = dgap_tty_init(brd);
976 dgap_tty_uninit(brd);
980 ret = dgap_tty_register_ports(brd);
984 brd->state = BOARD_READY;
985 brd->dpastatus = BD_RUNNING;
993 static int dgap_do_remap(struct board_t *brd)
995 if (!brd || brd->magic != DGAP_BOARD_MAGIC)
998 if (!request_mem_region(brd->membase, 0x200000, "dgap"))
1001 if (!request_mem_region(brd->membase + PCI_IO_OFFSET, 0x200000,
1003 release_mem_region(brd->membase, 0x200000);
1007 brd->re_map_membase = ioremap(brd->membase, 0x200000);
1008 if (!brd->re_map_membase) {
1009 release_mem_region(brd->membase, 0x200000);
1010 release_mem_region(brd->membase + PCI_IO_OFFSET, 0x200000);
1014 brd->re_map_port = ioremap((brd->membase + PCI_IO_OFFSET), 0x200000);
1015 if (!brd->re_map_port) {
1016 release_mem_region(brd->membase, 0x200000);
1017 release_mem_region(brd->membase + PCI_IO_OFFSET, 0x200000);
1018 iounmap(brd->re_map_membase);
1025 /*****************************************************************************
1045 * As each timer expires, it determines (a) whether the "transmit"
1046 * waiter needs to be woken up, and (b) whether the poller needs to
1049 ******************************************************************************/
1051 static void dgap_poll_handler(ulong dummy)
1054 struct board_t *brd;
1055 unsigned long lock_flags;
1058 dgap_poll_counter++;
1061 * Do not start the board state machine until
1062 * driver tells us its up and running, and has
1063 * everything it needs.
1065 if (dgap_driver_state != DRIVER_READY)
1066 goto schedule_poller;
1069 * If we have just 1 board, or the system is not SMP,
1070 * then use the typical old style poller.
1071 * Otherwise, use our new tasklet based poller, which should
1072 * speed things up for multiple boards.
1074 if ((dgap_NumBoards == 1) || (num_online_cpus() <= 1)) {
1075 for (i = 0; i < dgap_NumBoards; i++) {
1077 brd = dgap_Board[i];
1079 if (brd->state == BOARD_FAILED)
1081 if (!brd->intr_running)
1082 /* Call the real board poller directly */
1083 dgap_poll_tasklet((unsigned long) brd);
1087 * Go thru each board, kicking off a
1088 * tasklet for each if needed
1090 for (i = 0; i < dgap_NumBoards; i++) {
1091 brd = dgap_Board[i];
1094 * Attempt to grab the board lock.
1096 * If we can't get it, no big deal, the next poll
1097 * will get it. Basically, I just really don't want
1098 * to spin in here, because I want to kick off my
1099 * tasklets as fast as I can, and then get out the
1102 if (!spin_trylock(&brd->bd_lock))
1106 * If board is in a failed state, don't bother
1107 * scheduling a tasklet
1109 if (brd->state == BOARD_FAILED) {
1110 spin_unlock(&brd->bd_lock);
1114 /* Schedule a poll helper task */
1115 if (!brd->intr_running)
1116 tasklet_schedule(&brd->helper_tasklet);
1119 * Can't do DGAP_UNLOCK here, as we don't have
1120 * lock_flags because we did a trylock above.
1122 spin_unlock(&brd->bd_lock);
1129 * Schedule ourself back at the nominal wakeup interval.
1131 spin_lock_irqsave(&dgap_poll_lock, lock_flags);
1132 dgap_poll_time += dgap_jiffies_from_ms(dgap_poll_tick);
1134 new_time = dgap_poll_time - jiffies;
1136 if ((ulong) new_time >= 2 * dgap_poll_tick) {
1138 jiffies + dgap_jiffies_from_ms(dgap_poll_tick);
1141 dgap_poll_timer.function = dgap_poll_handler;
1142 dgap_poll_timer.data = 0;
1143 dgap_poll_timer.expires = dgap_poll_time;
1144 spin_unlock_irqrestore(&dgap_poll_lock, lock_flags);
1146 if (!dgap_poll_stop)
1147 add_timer(&dgap_poll_timer);
1153 * Driver interrupt handler.
1155 static irqreturn_t dgap_intr(int irq, void *voidbrd)
1157 struct board_t *brd = (struct board_t *) voidbrd;
1163 * Check to make sure its for us.
1165 if (brd->magic != DGAP_BOARD_MAGIC)
1171 * Schedule tasklet to run at a better time.
1173 tasklet_schedule(&brd->helper_tasklet);
1178 * dgap_init_globals()
1180 * This is where we initialize the globals from the static insmod
1181 * configuration variables. These are declared near the head of
1184 static void dgap_init_globals(void)
1188 for (i = 0; i < MAXBOARDS; i++)
1189 dgap_Board[i] = NULL;
1191 init_timer(&dgap_poll_timer);
1193 init_waitqueue_head(&dgap_dl_wait);
1196 /************************************************************************
1200 ************************************************************************/
1205 * Put the driver to sleep for x ms's
1207 * Returns 0 if timed out, !0 (showing signal) if interrupted by a signal.
1209 static int dgap_ms_sleep(ulong ms)
1211 current->state = TASK_INTERRUPTIBLE;
1212 schedule_timeout((ms * HZ) / 1000);
1213 return signal_pending(current);
1216 /************************************************************************
1218 * TTY Initialization/Cleanup Functions
1220 ************************************************************************/
1223 * dgap_tty_register()
1225 * Init the tty subsystem for this board.
1227 static int dgap_tty_register(struct board_t *brd)
1231 brd->SerialDriver = alloc_tty_driver(MAXPORTS);
1233 snprintf(brd->SerialName, MAXTTYNAMELEN, "tty_dgap_%d_", brd->boardnum);
1234 brd->SerialDriver->name = brd->SerialName;
1235 brd->SerialDriver->name_base = 0;
1236 brd->SerialDriver->major = 0;
1237 brd->SerialDriver->minor_start = 0;
1238 brd->SerialDriver->type = TTY_DRIVER_TYPE_SERIAL;
1239 brd->SerialDriver->subtype = SERIAL_TYPE_NORMAL;
1240 brd->SerialDriver->init_termios = DgapDefaultTermios;
1241 brd->SerialDriver->driver_name = DRVSTR;
1242 brd->SerialDriver->flags = (TTY_DRIVER_REAL_RAW |
1243 TTY_DRIVER_DYNAMIC_DEV |
1244 TTY_DRIVER_HARDWARE_BREAK);
1246 /* The kernel wants space to store pointers to tty_structs */
1247 brd->SerialDriver->ttys =
1248 kzalloc(MAXPORTS * sizeof(struct tty_struct *), GFP_KERNEL);
1249 if (!brd->SerialDriver->ttys)
1253 * Entry points for driver. Called by the kernel from
1254 * tty_io.c and n_tty.c.
1256 tty_set_operations(brd->SerialDriver, &dgap_tty_ops);
1259 * If we're doing transparent print, we have to do all of the above
1260 * again, separately so we don't get the LD confused about what major
1261 * we are when we get into the dgap_tty_open() routine.
1263 brd->PrintDriver = alloc_tty_driver(MAXPORTS);
1265 snprintf(brd->PrintName, MAXTTYNAMELEN, "pr_dgap_%d_", brd->boardnum);
1266 brd->PrintDriver->name = brd->PrintName;
1267 brd->PrintDriver->name_base = 0;
1268 brd->PrintDriver->major = 0;
1269 brd->PrintDriver->minor_start = 0;
1270 brd->PrintDriver->type = TTY_DRIVER_TYPE_SERIAL;
1271 brd->PrintDriver->subtype = SERIAL_TYPE_NORMAL;
1272 brd->PrintDriver->init_termios = DgapDefaultTermios;
1273 brd->PrintDriver->driver_name = DRVSTR;
1274 brd->PrintDriver->flags = (TTY_DRIVER_REAL_RAW |
1275 TTY_DRIVER_DYNAMIC_DEV |
1276 TTY_DRIVER_HARDWARE_BREAK);
1278 /* The kernel wants space to store pointers to tty_structs */
1279 brd->PrintDriver->ttys =
1280 kzalloc(MAXPORTS * sizeof(struct tty_struct *), GFP_KERNEL);
1281 if (!brd->PrintDriver->ttys)
1285 * Entry points for driver. Called by the kernel from
1286 * tty_io.c and n_tty.c.
1288 tty_set_operations(brd->PrintDriver, &dgap_tty_ops);
1290 if (!brd->dgap_Major_Serial_Registered) {
1291 /* Register tty devices */
1292 rc = tty_register_driver(brd->SerialDriver);
1295 brd->dgap_Major_Serial_Registered = TRUE;
1296 dgap_BoardsByMajor[brd->SerialDriver->major] = brd;
1297 brd->dgap_Serial_Major = brd->SerialDriver->major;
1300 if (!brd->dgap_Major_TransparentPrint_Registered) {
1301 /* Register Transparent Print devices */
1302 rc = tty_register_driver(brd->PrintDriver);
1305 brd->dgap_Major_TransparentPrint_Registered = TRUE;
1306 dgap_BoardsByMajor[brd->PrintDriver->major] = brd;
1307 brd->dgap_TransparentPrint_Major = brd->PrintDriver->major;
1316 * Init the tty subsystem. Called once per board after board has been
1317 * downloaded and init'ed.
1319 static int dgap_tty_init(struct board_t *brd)
1323 uint true_count = 0;
1326 struct channel_t *ch;
1334 * Initialize board structure elements.
1337 vaddr = brd->re_map_membase;
1338 true_count = readw((vaddr + NCHAN));
1340 brd->nasync = dgap_config_get_num_prts(brd);
1343 brd->nasync = brd->maxports;
1345 if (brd->nasync > brd->maxports)
1346 brd->nasync = brd->maxports;
1348 if (true_count != brd->nasync) {
1349 if ((brd->type == PPCM) && (true_count == 64)) {
1350 pr_warn("dgap: %s configured for %d ports, has %d ports.\n",
1351 brd->name, brd->nasync, true_count);
1352 pr_warn("dgap: Please make SURE the EBI cable running from the card\n");
1353 pr_warn("dgap: to each EM module is plugged into EBI IN!\n");
1354 } else if ((brd->type == PPCM) && (true_count == 0)) {
1355 pr_warn("dgap: %s configured for %d ports, has %d ports.\n",
1356 brd->name, brd->nasync, true_count);
1357 pr_warn("dgap: Please make SURE the EBI cable running from the card\n");
1358 pr_warn("dgap: to each EM module is plugged into EBI IN!\n");
1360 pr_warn("dgap: %s configured for %d ports, has %d ports.\n",
1361 brd->name, brd->nasync, true_count);
1363 brd->nasync = true_count;
1365 /* If no ports, don't bother going any further */
1367 brd->state = BOARD_FAILED;
1368 brd->dpastatus = BD_NOFEP;
1374 * Allocate channel memory that might not have been allocated
1375 * when the driver was first loaded.
1377 for (i = 0; i < brd->nasync; i++) {
1378 if (!brd->channels[i]) {
1380 kzalloc(sizeof(struct channel_t), GFP_ATOMIC);
1381 if (!brd->channels[i])
1386 ch = brd->channels[0];
1387 vaddr = brd->re_map_membase;
1389 bs = (struct bs_t *) ((ulong) vaddr + CHANBUF);
1390 cm = (struct cm_t *) ((ulong) vaddr + CMDBUF);
1394 /* Set up channel variables */
1395 for (i = 0; i < brd->nasync; i++, ch = brd->channels[i], bs++) {
1397 if (!brd->channels[i])
1400 spin_lock_init(&ch->ch_lock);
1402 /* Store all our magic numbers */
1403 ch->magic = DGAP_CHANNEL_MAGIC;
1404 ch->ch_tun.magic = DGAP_UNIT_MAGIC;
1405 ch->ch_tun.un_type = DGAP_SERIAL;
1406 ch->ch_tun.un_ch = ch;
1407 ch->ch_tun.un_dev = i;
1409 ch->ch_pun.magic = DGAP_UNIT_MAGIC;
1410 ch->ch_pun.un_type = DGAP_PRINT;
1411 ch->ch_pun.un_ch = ch;
1412 ch->ch_pun.un_dev = i;
1414 ch->ch_vaddr = vaddr;
1419 ch->ch_digi = dgap_digi_init;
1422 * Set up digi dsr and dcd bits based on altpin flag.
1424 if (dgap_config_get_altpin(brd)) {
1427 ch->ch_digi.digi_flags |= DIGI_ALTPIN;
1430 ch->ch_dsr = DM_DSR;
1433 ch->ch_taddr = vaddr + ((ch->ch_bs->tx_seg) << 4);
1434 ch->ch_raddr = vaddr + ((ch->ch_bs->rx_seg) << 4);
1437 ch->ch_tsize = readw(&(ch->ch_bs->tx_max)) + 1;
1438 ch->ch_rsize = readw(&(ch->ch_bs->rx_max)) + 1;
1442 /* .25 second delay */
1443 ch->ch_close_delay = 250;
1446 * Set queue water marks, interrupt mask,
1447 * and general tty parameters.
1449 tlw = ch->ch_tsize >= 2000 ? ((ch->ch_tsize * 5) / 8) :
1453 dgap_cmdw(ch, STLOW, tlw, 0);
1455 dgap_cmdw(ch, SRLOW, ch->ch_rsize / 2, 0);
1457 dgap_cmdw(ch, SRHIGH, 7 * ch->ch_rsize / 8, 0);
1459 ch->ch_mistat = readb(&(ch->ch_bs->m_stat));
1461 init_waitqueue_head(&ch->ch_flags_wait);
1462 init_waitqueue_head(&ch->ch_tun.un_flags_wait);
1463 init_waitqueue_head(&ch->ch_pun.un_flags_wait);
1464 init_waitqueue_head(&ch->ch_sniff_wait);
1466 /* Turn on all modem interrupts for now */
1467 modem = (DM_CD | DM_DSR | DM_CTS | DM_RI);
1468 writeb(modem, &(ch->ch_bs->m_int));
1471 * Set edelay to 0 if interrupts are turned on,
1472 * otherwise set edelay to the usual 100.
1475 writew(0, &(ch->ch_bs->edelay));
1477 writew(100, &(ch->ch_bs->edelay));
1479 writeb(1, &(ch->ch_bs->idata));
1488 * Uninitialize the TTY portion of this driver. Free all memory and
1491 static void dgap_tty_uninit(struct board_t *brd)
1496 if (brd->dgap_Major_Serial_Registered) {
1497 dgap_BoardsByMajor[brd->SerialDriver->major] = NULL;
1498 brd->dgap_Serial_Major = 0;
1499 for (i = 0; i < brd->nasync; i++) {
1500 tty_port_destroy(&brd->SerialPorts[i]);
1501 dev = brd->channels[i]->ch_tun.un_sysfs;
1502 dgap_remove_tty_sysfs(dev);
1503 tty_unregister_device(brd->SerialDriver, i);
1505 tty_unregister_driver(brd->SerialDriver);
1506 kfree(brd->SerialDriver->ttys);
1507 brd->SerialDriver->ttys = NULL;
1508 put_tty_driver(brd->SerialDriver);
1509 kfree(brd->SerialPorts);
1510 brd->dgap_Major_Serial_Registered = FALSE;
1513 if (brd->dgap_Major_TransparentPrint_Registered) {
1514 dgap_BoardsByMajor[brd->PrintDriver->major] = NULL;
1515 brd->dgap_TransparentPrint_Major = 0;
1516 for (i = 0; i < brd->nasync; i++) {
1517 tty_port_destroy(&brd->PrinterPorts[i]);
1518 dev = brd->channels[i]->ch_pun.un_sysfs;
1519 dgap_remove_tty_sysfs(dev);
1520 tty_unregister_device(brd->PrintDriver, i);
1522 tty_unregister_driver(brd->PrintDriver);
1523 kfree(brd->PrintDriver->ttys);
1524 brd->PrintDriver->ttys = NULL;
1525 put_tty_driver(brd->PrintDriver);
1526 kfree(brd->PrinterPorts);
1527 brd->dgap_Major_TransparentPrint_Registered = FALSE;
1531 #define TMPBUFLEN (1024)
1533 * dgap_sniff - Dump data out to the "sniff" buffer if the
1534 * proc sniff file is opened...
1536 static void dgap_sniff_nowait_nolock(struct channel_t *ch, uchar *text,
1537 uchar *buf, int len)
1545 char tmpbuf[TMPBUFLEN];
1549 /* Leave if sniff not open */
1550 if (!(ch->ch_sniff_flags & SNIFF_OPEN))
1553 do_gettimeofday(&tv);
1555 /* Create our header for data dump */
1556 p += sprintf(p, "<%ld %ld><%s><", tv.tv_sec, tv.tv_usec, text);
1557 tmpbuflen = p - tmpbuf;
1562 for (i = 0; i < len && tmpbuflen < (TMPBUFLEN - 4); i++) {
1563 p += sprintf(p, "%02x ", *buf);
1565 tmpbuflen = p - tmpbuf;
1568 if (tmpbuflen < (TMPBUFLEN - 4)) {
1570 p += sprintf(p - 1, "%s\n", ">");
1572 p += sprintf(p, "%s\n", ">");
1578 nbuf = strlen(tmpbuf);
1582 * Loop while data remains.
1584 while (nbuf > 0 && ch->ch_sniff_buf) {
1586 * Determine the amount of available space left in the
1587 * buffer. If there's none, wait until some appears.
1589 n = (ch->ch_sniff_out - ch->ch_sniff_in - 1) &
1593 * If there is no space left to write to in our sniff
1594 * buffer, we have no choice but to drop the data.
1595 * We *cannot* sleep here waiting for space, because
1596 * this function was probably called by the
1597 * interrupt/timer routines!
1603 * Copy as much data as will fit.
1609 r = SNIFF_MAX - ch->ch_sniff_in;
1612 memcpy(ch->ch_sniff_buf +
1613 ch->ch_sniff_in, p, r);
1616 ch->ch_sniff_in = 0;
1621 memcpy(ch->ch_sniff_buf + ch->ch_sniff_in, p, n);
1623 ch->ch_sniff_in += n;
1628 * Wakeup any thread waiting for data
1630 if (ch->ch_sniff_flags & SNIFF_WAIT_DATA) {
1631 ch->ch_sniff_flags &= ~SNIFF_WAIT_DATA;
1632 wake_up_interruptible(&ch->ch_sniff_wait);
1637 * If the user sent us too much data to push into our tmpbuf,
1638 * we need to keep looping around on all the data.
1640 if (too_much_data) {
1645 } while (too_much_data);
1648 /*=======================================================================
1650 * dgap_input - Process received data.
1652 * ch - Pointer to channel structure.
1654 *=======================================================================*/
1656 static void dgap_input(struct channel_t *ch)
1660 struct tty_struct *tp;
1661 struct tty_ldisc *ld;
1675 if (!ch || ch->magic != DGAP_CHANNEL_MAGIC)
1678 tp = ch->ch_tun.un_tty;
1685 if (!bd || bd->magic != DGAP_BOARD_MAGIC)
1688 spin_lock_irqsave(&bd->bd_lock, lock_flags);
1689 spin_lock_irqsave(&ch->ch_lock, lock_flags2);
1692 * Figure the number of characters in the buffer.
1693 * Exit immediately if none.
1696 rmask = ch->ch_rsize - 1;
1698 head = readw(&(bs->rx_head));
1700 tail = readw(&(bs->rx_tail));
1703 data_len = (head - tail) & rmask;
1705 if (data_len == 0) {
1706 writeb(1, &(bs->idata));
1707 spin_unlock_irqrestore(&ch->ch_lock, lock_flags2);
1708 spin_unlock_irqrestore(&bd->bd_lock, lock_flags);
1713 * If the device is not open, or CREAD is off, flush
1714 * input data and return immediately.
1716 if ((bd->state != BOARD_READY) || !tp ||
1717 (tp->magic != TTY_MAGIC) ||
1718 !(ch->ch_tun.un_flags & UN_ISOPEN) ||
1719 !(tp->termios.c_cflag & CREAD) ||
1720 (ch->ch_tun.un_flags & UN_CLOSING)) {
1722 writew(head, &(bs->rx_tail));
1723 writeb(1, &(bs->idata));
1724 spin_unlock_irqrestore(&ch->ch_lock, lock_flags2);
1725 spin_unlock_irqrestore(&bd->bd_lock, lock_flags);
1730 * If we are throttled, simply don't read any data.
1732 if (ch->ch_flags & CH_RXBLOCK) {
1733 writeb(1, &(bs->idata));
1734 spin_unlock_irqrestore(&ch->ch_lock, lock_flags2);
1735 spin_unlock_irqrestore(&bd->bd_lock, lock_flags);
1742 tmpchar = readb(&(bs->orun));
1744 ch->ch_err_overrun++;
1745 writeb(0, &(bs->orun));
1748 /* Decide how much data we can send into the tty layer */
1749 flip_len = TTY_FLIPBUF_SIZE;
1751 /* Chop down the length, if needed */
1752 len = min(data_len, flip_len);
1753 len = min(len, (N_TTY_BUF_SIZE - 1));
1755 ld = tty_ldisc_ref(tp);
1757 #ifdef TTY_DONT_FLIP
1759 * If the DONT_FLIP flag is on, don't flush our buffer, and act
1760 * like the ld doesn't have any space to put the data right now.
1762 if (test_bit(TTY_DONT_FLIP, &tp->flags))
1767 * If we were unable to get a reference to the ld,
1768 * don't flush our buffer, and act like the ld doesn't
1769 * have any space to put the data right now.
1775 * If ld doesn't have a pointer to a receive_buf function,
1776 * flush the data, then act like the ld doesn't have any
1777 * space to put the data right now.
1779 if (!ld->ops->receive_buf) {
1780 writew(head, &(bs->rx_tail));
1786 writeb(1, &(bs->idata));
1787 spin_unlock_irqrestore(&ch->ch_lock, lock_flags2);
1788 spin_unlock_irqrestore(&bd->bd_lock, lock_flags);
1790 tty_ldisc_deref(ld);
1794 buf = ch->ch_bd->flipbuf;
1798 * n now contains the most amount of data we can copy,
1799 * bounded either by our buffer size or the amount
1800 * of data the card actually has pending...
1804 s = ((head >= tail) ? head : ch->ch_rsize) - tail;
1810 memcpy_fromio(buf, (char *) ch->ch_raddr + tail, s);
1811 dgap_sniff_nowait_nolock(ch, "USER READ", buf, s);
1817 /* Flip queue if needed */
1821 writew(tail, &(bs->rx_tail));
1822 writeb(1, &(bs->idata));
1823 ch->ch_rxcount += len;
1826 * If we are completely raw, we don't need to go through a lot
1827 * of the tty layers that exist.
1828 * In this case, we take the shortest and fastest route we
1829 * can to relay the data to the user.
1831 * On the other hand, if we are not raw, we need to go through
1832 * the tty layer, which has its API more well defined.
1834 if (I_PARMRK(tp) || I_BRKINT(tp) || I_INPCK(tp)) {
1835 dgap_parity_scan(ch, ch->ch_bd->flipbuf,
1836 ch->ch_bd->flipflagbuf, &len);
1838 len = tty_buffer_request_room(tp->port, len);
1839 tty_insert_flip_string_flags(tp->port, ch->ch_bd->flipbuf,
1840 ch->ch_bd->flipflagbuf, len);
1842 len = tty_buffer_request_room(tp->port, len);
1843 tty_insert_flip_string(tp->port, ch->ch_bd->flipbuf, len);
1846 spin_unlock_irqrestore(&ch->ch_lock, lock_flags2);
1847 spin_unlock_irqrestore(&bd->bd_lock, lock_flags);
1849 /* Tell the tty layer its okay to "eat" the data now */
1850 tty_flip_buffer_push(tp->port);
1853 tty_ldisc_deref(ld);
1857 /************************************************************************
1858 * Determines when CARRIER changes state and takes appropriate
1860 ************************************************************************/
1861 static void dgap_carrier(struct channel_t *ch)
1865 int virt_carrier = 0;
1866 int phys_carrier = 0;
1868 if (!ch || ch->magic != DGAP_CHANNEL_MAGIC)
1873 if (!bd || bd->magic != DGAP_BOARD_MAGIC)
1876 /* Make sure altpin is always set correctly */
1877 if (ch->ch_digi.digi_flags & DIGI_ALTPIN) {
1881 ch->ch_dsr = DM_DSR;
1885 if (ch->ch_mistat & D_CD(ch))
1888 if (ch->ch_digi.digi_flags & DIGI_FORCEDCD)
1891 if (ch->ch_c_cflag & CLOCAL)
1895 * Test for a VIRTUAL carrier transition to HIGH.
1897 if (((ch->ch_flags & CH_FCAR) == 0) && (virt_carrier == 1)) {
1900 * When carrier rises, wake any threads waiting
1901 * for carrier in the open routine.
1904 if (waitqueue_active(&(ch->ch_flags_wait)))
1905 wake_up_interruptible(&ch->ch_flags_wait);
1909 * Test for a PHYSICAL carrier transition to HIGH.
1911 if (((ch->ch_flags & CH_CD) == 0) && (phys_carrier == 1)) {
1914 * When carrier rises, wake any threads waiting
1915 * for carrier in the open routine.
1918 if (waitqueue_active(&(ch->ch_flags_wait)))
1919 wake_up_interruptible(&ch->ch_flags_wait);
1923 * Test for a PHYSICAL transition to low, so long as we aren't
1924 * currently ignoring physical transitions (which is what "virtual
1925 * carrier" indicates).
1927 * The transition of the virtual carrier to low really doesn't
1928 * matter... it really only means "ignore carrier state", not
1929 * "make pretend that carrier is there".
1931 if ((virt_carrier == 0) &&
1932 ((ch->ch_flags & CH_CD) != 0) &&
1933 (phys_carrier == 0)) {
1936 * When carrier drops:
1938 * Drop carrier on all open units.
1940 * Flush queues, waking up any task waiting in the
1943 * Send a hangup to the control terminal.
1945 * Enable all select calls.
1947 if (waitqueue_active(&(ch->ch_flags_wait)))
1948 wake_up_interruptible(&ch->ch_flags_wait);
1950 if (ch->ch_tun.un_open_count > 0)
1951 tty_hangup(ch->ch_tun.un_tty);
1953 if (ch->ch_pun.un_open_count > 0)
1954 tty_hangup(ch->ch_pun.un_tty);
1958 * Make sure that our cached values reflect the current reality.
1960 if (virt_carrier == 1)
1961 ch->ch_flags |= CH_FCAR;
1963 ch->ch_flags &= ~CH_FCAR;
1965 if (phys_carrier == 1)
1966 ch->ch_flags |= CH_CD;
1968 ch->ch_flags &= ~CH_CD;
1971 /************************************************************************
1973 * TTY Entry points and helper functions
1975 ************************************************************************/
1981 static int dgap_tty_open(struct tty_struct *tty, struct file *file)
1983 struct board_t *brd;
1984 struct channel_t *ch;
1996 major = MAJOR(tty_devnum(tty));
1997 minor = MINOR(tty_devnum(tty));
2002 /* Get board pointer from our array of majors we have allocated */
2003 brd = dgap_BoardsByMajor[major];
2008 * If board is not yet up to a state of READY, go to
2009 * sleep waiting for it to happen or they cancel the open.
2011 rc = wait_event_interruptible(brd->state_wait,
2012 (brd->state & BOARD_READY));
2017 spin_lock_irqsave(&brd->bd_lock, lock_flags);
2019 /* The wait above should guarantee this cannot happen */
2020 if (brd->state != BOARD_READY) {
2021 spin_unlock_irqrestore(&brd->bd_lock, lock_flags);
2025 /* If opened device is greater than our number of ports, bail. */
2026 if (MINOR(tty_devnum(tty)) > brd->nasync) {
2027 spin_unlock_irqrestore(&brd->bd_lock, lock_flags);
2031 ch = brd->channels[minor];
2033 spin_unlock_irqrestore(&brd->bd_lock, lock_flags);
2037 /* Grab channel lock */
2038 spin_lock_irqsave(&ch->ch_lock, lock_flags2);
2040 /* Figure out our type */
2041 if (major == brd->dgap_Serial_Major) {
2042 un = &brd->channels[minor]->ch_tun;
2043 un->un_type = DGAP_SERIAL;
2044 } else if (major == brd->dgap_TransparentPrint_Major) {
2045 un = &brd->channels[minor]->ch_pun;
2046 un->un_type = DGAP_PRINT;
2048 spin_unlock_irqrestore(&ch->ch_lock, lock_flags2);
2049 spin_unlock_irqrestore(&brd->bd_lock, lock_flags);
2053 /* Store our unit into driver_data, so we always have it available. */
2054 tty->driver_data = un;
2057 * Error if channel info pointer is NULL.
2061 spin_unlock_irqrestore(&ch->ch_lock, lock_flags2);
2062 spin_unlock_irqrestore(&brd->bd_lock, lock_flags);
2069 if (!(un->un_flags & UN_ISOPEN)) {
2070 /* Store important variables. */
2073 /* Maybe do something here to the TTY struct as well? */
2077 * Initialize if neither terminal or printer is open.
2079 if (!((ch->ch_tun.un_flags | ch->ch_pun.un_flags) & UN_ISOPEN)) {
2085 * Flush input queue.
2087 head = readw(&(bs->rx_head));
2088 writew(head, &(bs->rx_tail));
2091 ch->pscan_state = 0;
2092 ch->pscan_savechar = 0;
2094 ch->ch_c_cflag = tty->termios.c_cflag;
2095 ch->ch_c_iflag = tty->termios.c_iflag;
2096 ch->ch_c_oflag = tty->termios.c_oflag;
2097 ch->ch_c_lflag = tty->termios.c_lflag;
2098 ch->ch_startc = tty->termios.c_cc[VSTART];
2099 ch->ch_stopc = tty->termios.c_cc[VSTOP];
2101 /* TODO: flush our TTY struct here? */
2106 * Run param in case we changed anything
2111 * follow protocol for opening port
2114 spin_unlock_irqrestore(&ch->ch_lock, lock_flags2);
2115 spin_unlock_irqrestore(&brd->bd_lock, lock_flags);
2117 rc = dgap_block_til_ready(tty, file, ch);
2122 /* No going back now, increment our unit and channel counters */
2123 spin_lock_irqsave(&ch->ch_lock, lock_flags);
2124 ch->ch_open_count++;
2125 un->un_open_count++;
2126 un->un_flags |= (UN_ISOPEN);
2127 spin_unlock_irqrestore(&ch->ch_lock, lock_flags);
2133 * dgap_block_til_ready()
2135 * Wait for DCD, if needed.
2137 static int dgap_block_til_ready(struct tty_struct *tty, struct file *file,
2138 struct channel_t *ch)
2141 struct un_t *un = NULL;
2144 int sleep_on_un_flags = 0;
2146 if (!tty || tty->magic != TTY_MAGIC || !file || !ch ||
2147 ch->magic != DGAP_CHANNEL_MAGIC)
2150 un = tty->driver_data;
2151 if (!un || un->magic != DGAP_UNIT_MAGIC)
2154 spin_lock_irqsave(&ch->ch_lock, lock_flags);
2161 sleep_on_un_flags = 0;
2164 * If board has failed somehow during our sleep,
2167 if (ch->ch_bd->state == BOARD_FAILED) {
2172 /* If tty was hung up, break out of loop and set error. */
2173 if (tty_hung_up_p(file)) {
2179 * If either unit is in the middle of the fragile part of close,
2180 * we just cannot touch the channel safely.
2181 * Go back to sleep, knowing that when the channel can be
2182 * touched safely, the close routine will signal the
2183 * ch_wait_flags to wake us back up.
2185 if (!((ch->ch_tun.un_flags | ch->ch_pun.un_flags) &
2189 * Our conditions to leave cleanly and happily:
2190 * 1) NONBLOCKING on the tty is set.
2192 * 3) DCD (fake or real) is active.
2195 if (file->f_flags & O_NONBLOCK)
2198 if (tty->flags & (1 << TTY_IO_ERROR))
2201 if (ch->ch_flags & CH_CD)
2204 if (ch->ch_flags & CH_FCAR)
2207 sleep_on_un_flags = 1;
2211 * If there is a signal pending, the user probably
2212 * interrupted (ctrl-c) us.
2213 * Leave loop with error set.
2215 if (signal_pending(current)) {
2216 retval = -ERESTARTSYS;
2221 * Store the flags before we let go of channel lock
2223 if (sleep_on_un_flags)
2224 old_flags = ch->ch_tun.un_flags | ch->ch_pun.un_flags;
2226 old_flags = ch->ch_flags;
2229 * Let go of channel lock before calling schedule.
2230 * Our poller will get any FEP events and wake us up when DCD
2231 * eventually goes active.
2234 spin_unlock_irqrestore(&ch->ch_lock, lock_flags);
2237 * Wait for something in the flags to change
2238 * from the current value.
2240 if (sleep_on_un_flags) {
2241 retval = wait_event_interruptible(un->un_flags_wait,
2242 (old_flags != (ch->ch_tun.un_flags |
2243 ch->ch_pun.un_flags)));
2245 retval = wait_event_interruptible(ch->ch_flags_wait,
2246 (old_flags != ch->ch_flags));
2250 * We got woken up for some reason.
2251 * Before looping around, grab our channel lock.
2253 spin_lock_irqsave(&ch->ch_lock, lock_flags);
2258 spin_unlock_irqrestore(&ch->ch_lock, lock_flags);
2269 * Hangup the port. Like a close, but don't wait for output to drain.
2271 static void dgap_tty_hangup(struct tty_struct *tty)
2274 struct channel_t *ch;
2277 if (!tty || tty->magic != TTY_MAGIC)
2280 un = tty->driver_data;
2281 if (!un || un->magic != DGAP_UNIT_MAGIC)
2285 if (!ch || ch->magic != DGAP_CHANNEL_MAGIC)
2289 if (!bd || bd->magic != DGAP_BOARD_MAGIC)
2292 /* flush the transmit queues */
2293 dgap_tty_flush_buffer(tty);
2301 static void dgap_tty_close(struct tty_struct *tty, struct file *file)
2303 struct ktermios *ts;
2305 struct channel_t *ch;
2310 if (!tty || tty->magic != TTY_MAGIC)
2313 un = tty->driver_data;
2314 if (!un || un->magic != DGAP_UNIT_MAGIC)
2318 if (!ch || ch->magic != DGAP_CHANNEL_MAGIC)
2322 if (!bd || bd->magic != DGAP_BOARD_MAGIC)
2327 spin_lock_irqsave(&ch->ch_lock, lock_flags);
2330 * Determine if this is the last close or not - and if we agree about
2331 * which type of close it is with the Line Discipline
2333 if ((tty->count == 1) && (un->un_open_count != 1)) {
2335 * Uh, oh. tty->count is 1, which means that the tty
2336 * structure will be freed. un_open_count should always
2337 * be one in these conditions. If it's greater than
2338 * one, we've got real problems, since it means the
2339 * serial port won't be shutdown.
2341 un->un_open_count = 1;
2344 if (--un->un_open_count < 0)
2345 un->un_open_count = 0;
2347 ch->ch_open_count--;
2349 if (ch->ch_open_count && un->un_open_count) {
2350 spin_unlock_irqrestore(&ch->ch_lock, lock_flags);
2354 /* OK, its the last close on the unit */
2356 un->un_flags |= UN_CLOSING;
2361 * Only officially close channel if count is 0 and
2362 * DIGI_PRINTER bit is not set.
2364 if ((ch->ch_open_count == 0) &&
2365 !(ch->ch_digi.digi_flags & DIGI_PRINTER)) {
2367 ch->ch_flags &= ~(CH_RXBLOCK);
2369 spin_unlock_irqrestore(&ch->ch_lock, lock_flags);
2371 /* wait for output to drain */
2372 /* This will also return if we take an interrupt */
2374 rc = dgap_wait_for_drain(tty);
2376 dgap_tty_flush_buffer(tty);
2377 tty_ldisc_flush(tty);
2379 spin_lock_irqsave(&ch->ch_lock, lock_flags);
2384 * If we have HUPCL set, lower DTR and RTS
2386 if (ch->ch_c_cflag & HUPCL) {
2387 ch->ch_mostat &= ~(D_RTS(ch)|D_DTR(ch));
2388 dgap_cmdb(ch, SMODEM, 0, D_DTR(ch)|D_RTS(ch), 0);
2391 * Go to sleep to ensure RTS/DTR
2392 * have been dropped for modems to see it.
2394 if (ch->ch_close_delay) {
2395 spin_unlock_irqrestore(&ch->ch_lock,
2397 dgap_ms_sleep(ch->ch_close_delay);
2398 spin_lock_irqsave(&ch->ch_lock, lock_flags);
2402 ch->pscan_state = 0;
2403 ch->pscan_savechar = 0;
2404 ch->ch_baud_info = 0;
2409 * turn off print device when closing print device.
2411 if ((un->un_type == DGAP_PRINT) && (ch->ch_flags & CH_PRON)) {
2412 dgap_wmove(ch, ch->ch_digi.digi_offstr,
2413 (int) ch->ch_digi.digi_offlen);
2414 ch->ch_flags &= ~CH_PRON;
2418 un->un_flags &= ~(UN_ISOPEN | UN_CLOSING);
2419 tty->driver_data = NULL;
2421 wake_up_interruptible(&ch->ch_flags_wait);
2422 wake_up_interruptible(&un->un_flags_wait);
2424 spin_unlock_irqrestore(&ch->ch_lock, lock_flags);
2428 * dgap_tty_chars_in_buffer()
2430 * Return number of characters that have not been transmitted yet.
2432 * This routine is used by the line discipline to determine if there
2433 * is data waiting to be transmitted/drained/flushed or not.
2435 static int dgap_tty_chars_in_buffer(struct tty_struct *tty)
2437 struct board_t *bd = NULL;
2438 struct channel_t *ch = NULL;
2439 struct un_t *un = NULL;
2440 struct bs_t *bs = NULL;
2443 u16 thead, ttail, tmask, chead, ctail;
2444 ulong lock_flags = 0;
2445 ulong lock_flags2 = 0;
2450 un = tty->driver_data;
2451 if (!un || un->magic != DGAP_UNIT_MAGIC)
2455 if (!ch || ch->magic != DGAP_CHANNEL_MAGIC)
2459 if (!bd || bd->magic != DGAP_BOARD_MAGIC)
2466 spin_lock_irqsave(&bd->bd_lock, lock_flags);
2467 spin_lock_irqsave(&ch->ch_lock, lock_flags2);
2469 tmask = (ch->ch_tsize - 1);
2471 /* Get Transmit queue pointers */
2472 thead = readw(&(bs->tx_head)) & tmask;
2473 ttail = readw(&(bs->tx_tail)) & tmask;
2475 /* Get tbusy flag */
2476 tbusy = readb(&(bs->tbusy));
2478 /* Get Command queue pointers */
2479 chead = readw(&(ch->ch_cm->cm_head));
2480 ctail = readw(&(ch->ch_cm->cm_tail));
2482 spin_unlock_irqrestore(&ch->ch_lock, lock_flags2);
2483 spin_unlock_irqrestore(&bd->bd_lock, lock_flags);
2486 * The only way we know for sure if there is no pending
2487 * data left to be transferred, is if:
2488 * 1) Transmit head and tail are equal (empty).
2489 * 2) Command queue head and tail are equal (empty).
2490 * 3) The "TBUSY" flag is 0. (Transmitter not busy).
2493 if ((ttail == thead) && (tbusy == 0) && (chead == ctail)) {
2497 chars = thead - ttail;
2499 chars = thead - ttail + ch->ch_tsize;
2501 * Fudge factor here.
2502 * If chars is zero, we know that the command queue had
2503 * something in it or tbusy was set. Because we cannot
2504 * be sure if there is still some data to be transmitted,
2505 * lets lie, and tell ld we have 1 byte left.
2509 * If TBUSY is still set, and our tx buffers are empty,
2510 * force the firmware to send me another wakeup after
2511 * TBUSY has been cleared.
2514 spin_lock_irqsave(&ch->ch_lock, lock_flags);
2515 un->un_flags |= UN_EMPTY;
2516 writeb(1, &(bs->iempty));
2517 spin_unlock_irqrestore(&ch->ch_lock,
2527 static int dgap_wait_for_drain(struct tty_struct *tty)
2529 struct channel_t *ch;
2534 ulong lock_flags = 0;
2536 if (!tty || tty->magic != TTY_MAGIC)
2539 un = tty->driver_data;
2540 if (!un || un->magic != DGAP_UNIT_MAGIC)
2544 if (!ch || ch->magic != DGAP_CHANNEL_MAGIC)
2553 /* Loop until data is drained */
2554 while (count != 0) {
2556 count = dgap_tty_chars_in_buffer(tty);
2561 /* Set flag waiting for drain */
2562 spin_lock_irqsave(&ch->ch_lock, lock_flags);
2563 un->un_flags |= UN_EMPTY;
2564 writeb(1, &(bs->iempty));
2565 spin_unlock_irqrestore(&ch->ch_lock, lock_flags);
2567 /* Go to sleep till we get woken up */
2568 ret = wait_event_interruptible(un->un_flags_wait,
2569 ((un->un_flags & UN_EMPTY) == 0));
2570 /* If ret is non-zero, user ctrl-c'ed us */
2575 spin_lock_irqsave(&ch->ch_lock, lock_flags);
2576 un->un_flags &= ~(UN_EMPTY);
2577 spin_unlock_irqrestore(&ch->ch_lock, lock_flags);
2585 * Reduces bytes_available to the max number of characters
2586 * that can be sent currently given the maxcps value, and
2587 * returns the new bytes_available. This only affects printer
2590 static int dgap_maxcps_room(struct tty_struct *tty, int bytes_available)
2592 struct channel_t *ch = NULL;
2593 struct un_t *un = NULL;
2596 return bytes_available;
2598 un = tty->driver_data;
2599 if (!un || un->magic != DGAP_UNIT_MAGIC)
2600 return bytes_available;
2603 if (!ch || ch->magic != DGAP_CHANNEL_MAGIC)
2604 return bytes_available;
2607 * If its not the Transparent print device, return
2608 * the full data amount.
2610 if (un->un_type != DGAP_PRINT)
2611 return bytes_available;
2613 if (ch->ch_digi.digi_maxcps > 0 && ch->ch_digi.digi_bufsize > 0) {
2615 unsigned long current_time = jiffies;
2616 unsigned long buffer_time = current_time +
2617 (HZ * ch->ch_digi.digi_bufsize) /
2618 ch->ch_digi.digi_maxcps;
2620 if (ch->ch_cpstime < current_time) {
2621 /* buffer is empty */
2622 ch->ch_cpstime = current_time; /* reset ch_cpstime */
2623 cps_limit = ch->ch_digi.digi_bufsize;
2624 } else if (ch->ch_cpstime < buffer_time) {
2625 /* still room in the buffer */
2626 cps_limit = ((buffer_time - ch->ch_cpstime) *
2627 ch->ch_digi.digi_maxcps) / HZ;
2629 /* no room in the buffer */
2633 bytes_available = min(cps_limit, bytes_available);
2636 return bytes_available;
2639 static inline void dgap_set_firmware_event(struct un_t *un, unsigned int event)
2641 struct channel_t *ch = NULL;
2642 struct bs_t *bs = NULL;
2644 if (!un || un->magic != DGAP_UNIT_MAGIC)
2647 if (!ch || ch->magic != DGAP_CHANNEL_MAGIC)
2653 if ((event & UN_LOW) != 0) {
2654 if ((un->un_flags & UN_LOW) == 0) {
2655 un->un_flags |= UN_LOW;
2656 writeb(1, &(bs->ilow));
2659 if ((event & UN_LOW) != 0) {
2660 if ((un->un_flags & UN_EMPTY) == 0) {
2661 un->un_flags |= UN_EMPTY;
2662 writeb(1, &(bs->iempty));
2668 * dgap_tty_write_room()
2670 * Return space available in Tx buffer
2672 static int dgap_tty_write_room(struct tty_struct *tty)
2674 struct channel_t *ch = NULL;
2675 struct un_t *un = NULL;
2676 struct bs_t *bs = NULL;
2677 u16 head, tail, tmask;
2679 ulong lock_flags = 0;
2684 un = tty->driver_data;
2685 if (!un || un->magic != DGAP_UNIT_MAGIC)
2689 if (!ch || ch->magic != DGAP_CHANNEL_MAGIC)
2696 spin_lock_irqsave(&ch->ch_lock, lock_flags);
2698 tmask = ch->ch_tsize - 1;
2699 head = readw(&(bs->tx_head)) & tmask;
2700 tail = readw(&(bs->tx_tail)) & tmask;
2702 ret = tail - head - 1;
2704 ret += ch->ch_tsize;
2706 /* Limit printer to maxcps */
2707 ret = dgap_maxcps_room(tty, ret);
2710 * If we are printer device, leave space for
2711 * possibly both the on and off strings.
2713 if (un->un_type == DGAP_PRINT) {
2714 if (!(ch->ch_flags & CH_PRON))
2715 ret -= ch->ch_digi.digi_onlen;
2716 ret -= ch->ch_digi.digi_offlen;
2718 if (ch->ch_flags & CH_PRON)
2719 ret -= ch->ch_digi.digi_offlen;
2726 * Schedule FEP to wake us up if needed.
2728 * TODO: This might be overkill...
2729 * Do we really need to schedule callbacks from the FEP
2730 * in every case? Can we get smarter based on ret?
2732 dgap_set_firmware_event(un, UN_LOW | UN_EMPTY);
2733 spin_unlock_irqrestore(&ch->ch_lock, lock_flags);
2739 * dgap_tty_put_char()
2741 * Put a character into ch->ch_buf
2743 * - used by the line discipline for OPOST processing
2745 static int dgap_tty_put_char(struct tty_struct *tty, unsigned char c)
2748 * Simply call tty_write.
2750 dgap_tty_write(tty, &c, 1);
2757 * Take data from the user or kernel and send it out to the FEP.
2758 * In here exists all the Transparent Print magic as well.
2760 static int dgap_tty_write(struct tty_struct *tty, const unsigned char *buf,
2763 struct channel_t *ch = NULL;
2764 struct un_t *un = NULL;
2765 struct bs_t *bs = NULL;
2767 u16 head, tail, tmask, remain;
2768 int bufcount = 0, n = 0;
2775 un = tty->driver_data;
2776 if (!un || un->magic != DGAP_UNIT_MAGIC)
2780 if (!ch || ch->magic != DGAP_CHANNEL_MAGIC)
2791 * Store original amount of characters passed in.
2792 * This helps to figure out if we should ask the FEP
2793 * to send us an event when it has more space available.
2797 spin_lock_irqsave(&ch->ch_lock, lock_flags);
2799 /* Get our space available for the channel from the board */
2800 tmask = ch->ch_tsize - 1;
2801 head = readw(&(bs->tx_head)) & tmask;
2802 tail = readw(&(bs->tx_tail)) & tmask;
2804 bufcount = tail - head - 1;
2806 bufcount += ch->ch_tsize;
2809 * Limit printer output to maxcps overall, with bursts allowed
2810 * up to bufsize characters.
2812 bufcount = dgap_maxcps_room(tty, bufcount);
2815 * Take minimum of what the user wants to send, and the
2816 * space available in the FEP buffer.
2818 count = min(count, bufcount);
2821 * Bail if no space left.
2824 dgap_set_firmware_event(un, UN_LOW | UN_EMPTY);
2825 spin_unlock_irqrestore(&ch->ch_lock, lock_flags);
2830 * Output the printer ON string, if we are in terminal mode, but
2831 * need to be in printer mode.
2833 if ((un->un_type == DGAP_PRINT) && !(ch->ch_flags & CH_PRON)) {
2834 dgap_wmove(ch, ch->ch_digi.digi_onstr,
2835 (int) ch->ch_digi.digi_onlen);
2836 head = readw(&(bs->tx_head)) & tmask;
2837 ch->ch_flags |= CH_PRON;
2841 * On the other hand, output the printer OFF string, if we are
2842 * currently in printer mode, but need to output to the terminal.
2844 if ((un->un_type != DGAP_PRINT) && (ch->ch_flags & CH_PRON)) {
2845 dgap_wmove(ch, ch->ch_digi.digi_offstr,
2846 (int) ch->ch_digi.digi_offlen);
2847 head = readw(&(bs->tx_head)) & tmask;
2848 ch->ch_flags &= ~CH_PRON;
2852 * If there is nothing left to copy, or
2853 * I can't handle any more data, leave.
2856 dgap_set_firmware_event(un, UN_LOW | UN_EMPTY);
2857 spin_unlock_irqrestore(&ch->ch_lock, lock_flags);
2864 * If the write wraps over the top of the circular buffer,
2865 * move the portion up to the wrap point, and reset the
2866 * pointers to the bottom.
2868 remain = ch->ch_tstart + ch->ch_tsize - head;
2872 vaddr = ch->ch_taddr + head;
2874 memcpy_toio(vaddr, (uchar *) buf, remain);
2875 dgap_sniff_nowait_nolock(ch, "USER WRITE", (uchar *) buf,
2878 head = ch->ch_tstart;
2885 * Move rest of data.
2887 vaddr = ch->ch_taddr + head;
2890 memcpy_toio(vaddr, (uchar *) buf, remain);
2891 dgap_sniff_nowait_nolock(ch, "USER WRITE", (uchar *)buf,
2899 ch->ch_txcount += count;
2901 writew(head, &(bs->tx_head));
2904 dgap_set_firmware_event(un, UN_LOW | UN_EMPTY);
2907 * If this is the print device, and the
2908 * printer is still on, we need to turn it
2909 * off before going idle. If the buffer is
2910 * non-empty, wait until it goes empty.
2911 * Otherwise turn it off right now.
2913 if ((un->un_type == DGAP_PRINT) && (ch->ch_flags & CH_PRON)) {
2914 tail = readw(&(bs->tx_tail)) & tmask;
2917 un->un_flags |= UN_EMPTY;
2918 writeb(1, &(bs->iempty));
2920 dgap_wmove(ch, ch->ch_digi.digi_offstr,
2921 (int) ch->ch_digi.digi_offlen);
2922 head = readw(&(bs->tx_head)) & tmask;
2923 ch->ch_flags &= ~CH_PRON;
2927 /* Update printer buffer empty time. */
2928 if ((un->un_type == DGAP_PRINT) && (ch->ch_digi.digi_maxcps > 0)
2929 && (ch->ch_digi.digi_bufsize > 0)) {
2930 ch->ch_cpstime += (HZ * count) / ch->ch_digi.digi_maxcps;
2933 spin_unlock_irqrestore(&ch->ch_lock, lock_flags);
2939 * Return modem signals to ld.
2941 static int dgap_tty_tiocmget(struct tty_struct *tty)
2943 struct channel_t *ch;
2949 if (!tty || tty->magic != TTY_MAGIC)
2952 un = tty->driver_data;
2953 if (!un || un->magic != DGAP_UNIT_MAGIC)
2957 if (!ch || ch->magic != DGAP_CHANNEL_MAGIC)
2960 spin_lock_irqsave(&ch->ch_lock, lock_flags);
2962 mstat = readb(&(ch->ch_bs->m_stat));
2963 /* Append any outbound signals that might be pending... */
2964 mstat |= ch->ch_mostat;
2966 spin_unlock_irqrestore(&ch->ch_lock, lock_flags);
2970 if (mstat & D_DTR(ch))
2971 result |= TIOCM_DTR;
2972 if (mstat & D_RTS(ch))
2973 result |= TIOCM_RTS;
2974 if (mstat & D_CTS(ch))
2975 result |= TIOCM_CTS;
2976 if (mstat & D_DSR(ch))
2977 result |= TIOCM_DSR;
2978 if (mstat & D_RI(ch))
2980 if (mstat & D_CD(ch))
2987 * dgap_tty_tiocmset()
2989 * Set modem signals, called by ld.
2991 static int dgap_tty_tiocmset(struct tty_struct *tty,
2992 unsigned int set, unsigned int clear)
2995 struct channel_t *ch;
3001 if (!tty || tty->magic != TTY_MAGIC)
3004 un = tty->driver_data;
3005 if (!un || un->magic != DGAP_UNIT_MAGIC)
3009 if (!ch || ch->magic != DGAP_CHANNEL_MAGIC)
3013 if (!bd || bd->magic != DGAP_BOARD_MAGIC)
3016 spin_lock_irqsave(&bd->bd_lock, lock_flags);
3017 spin_lock_irqsave(&ch->ch_lock, lock_flags2);
3019 if (set & TIOCM_RTS) {
3020 ch->ch_mforce |= D_RTS(ch);
3021 ch->ch_mval |= D_RTS(ch);
3024 if (set & TIOCM_DTR) {
3025 ch->ch_mforce |= D_DTR(ch);
3026 ch->ch_mval |= D_DTR(ch);
3029 if (clear & TIOCM_RTS) {
3030 ch->ch_mforce |= D_RTS(ch);
3031 ch->ch_mval &= ~(D_RTS(ch));
3034 if (clear & TIOCM_DTR) {
3035 ch->ch_mforce |= D_DTR(ch);
3036 ch->ch_mval &= ~(D_DTR(ch));
3041 spin_unlock_irqrestore(&ch->ch_lock, lock_flags2);
3042 spin_unlock_irqrestore(&bd->bd_lock, lock_flags);
3048 * dgap_tty_send_break()
3050 * Send a Break, called by ld.
3052 static int dgap_tty_send_break(struct tty_struct *tty, int msec)
3055 struct channel_t *ch;
3061 if (!tty || tty->magic != TTY_MAGIC)
3064 un = tty->driver_data;
3065 if (!un || un->magic != DGAP_UNIT_MAGIC)
3069 if (!ch || ch->magic != DGAP_CHANNEL_MAGIC)
3073 if (!bd || bd->magic != DGAP_BOARD_MAGIC)
3088 spin_lock_irqsave(&bd->bd_lock, lock_flags);
3089 spin_lock_irqsave(&ch->ch_lock, lock_flags2);
3091 dgap_cmdw(ch, SBREAK, (u16) SBREAK_TIME, 0);
3093 dgap_cmdw(ch, SBREAK, (u16) msec, 0);
3095 spin_unlock_irqrestore(&ch->ch_lock, lock_flags2);
3096 spin_unlock_irqrestore(&bd->bd_lock, lock_flags);
3102 * dgap_tty_wait_until_sent()
3104 * wait until data has been transmitted, called by ld.
3106 static void dgap_tty_wait_until_sent(struct tty_struct *tty, int timeout)
3108 dgap_wait_for_drain(tty);
3114 * send a high priority character, called by ld.
3116 static void dgap_tty_send_xchar(struct tty_struct *tty, char c)
3119 struct channel_t *ch;
3124 if (!tty || tty->magic != TTY_MAGIC)
3127 un = tty->driver_data;
3128 if (!un || un->magic != DGAP_UNIT_MAGIC)
3132 if (!ch || ch->magic != DGAP_CHANNEL_MAGIC)
3136 if (!bd || bd->magic != DGAP_BOARD_MAGIC)
3139 spin_lock_irqsave(&bd->bd_lock, lock_flags);
3140 spin_lock_irqsave(&ch->ch_lock, lock_flags2);
3143 * This is technically what we should do.
3144 * However, the NIST tests specifically want
3145 * to see each XON or XOFF character that it
3146 * sends, so lets just send each character
3150 if (c == STOP_CHAR(tty))
3151 dgap_cmdw(ch, RPAUSE, 0, 0);
3152 else if (c == START_CHAR(tty))
3153 dgap_cmdw(ch, RRESUME, 0, 0);
3155 dgap_wmove(ch, &c, 1);
3157 dgap_wmove(ch, &c, 1);
3160 spin_unlock_irqrestore(&ch->ch_lock, lock_flags2);
3161 spin_unlock_irqrestore(&bd->bd_lock, lock_flags);
3167 * Return modem signals to ld.
3169 static int dgap_get_modem_info(struct channel_t *ch, unsigned int __user *value)
3176 if (!ch || ch->magic != DGAP_CHANNEL_MAGIC)
3179 spin_lock_irqsave(&ch->ch_lock, lock_flags);
3181 mstat = readb(&(ch->ch_bs->m_stat));
3182 /* Append any outbound signals that might be pending... */
3183 mstat |= ch->ch_mostat;
3185 spin_unlock_irqrestore(&ch->ch_lock, lock_flags);
3189 if (mstat & D_DTR(ch))
3190 result |= TIOCM_DTR;
3191 if (mstat & D_RTS(ch))
3192 result |= TIOCM_RTS;
3193 if (mstat & D_CTS(ch))
3194 result |= TIOCM_CTS;
3195 if (mstat & D_DSR(ch))
3196 result |= TIOCM_DSR;
3197 if (mstat & D_RI(ch))
3199 if (mstat & D_CD(ch))
3202 rc = put_user(result, value);
3208 * dgap_set_modem_info()
3210 * Set modem signals, called by ld.
3212 static int dgap_set_modem_info(struct tty_struct *tty, unsigned int command,
3213 unsigned int __user *value)
3216 struct channel_t *ch;
3219 unsigned int arg = 0;
3223 if (!tty || tty->magic != TTY_MAGIC)
3226 un = tty->driver_data;
3227 if (!un || un->magic != DGAP_UNIT_MAGIC)
3231 if (!ch || ch->magic != DGAP_CHANNEL_MAGIC)
3235 if (!bd || bd->magic != DGAP_BOARD_MAGIC)
3238 ret = get_user(arg, value);
3244 if (arg & TIOCM_RTS) {
3245 ch->ch_mforce |= D_RTS(ch);
3246 ch->ch_mval |= D_RTS(ch);
3249 if (arg & TIOCM_DTR) {
3250 ch->ch_mforce |= D_DTR(ch);
3251 ch->ch_mval |= D_DTR(ch);
3257 if (arg & TIOCM_RTS) {
3258 ch->ch_mforce |= D_RTS(ch);
3259 ch->ch_mval &= ~(D_RTS(ch));
3262 if (arg & TIOCM_DTR) {
3263 ch->ch_mforce |= D_DTR(ch);
3264 ch->ch_mval &= ~(D_DTR(ch));
3270 ch->ch_mforce = D_DTR(ch)|D_RTS(ch);
3272 if (arg & TIOCM_RTS)
3273 ch->ch_mval |= D_RTS(ch);
3275 ch->ch_mval &= ~(D_RTS(ch));
3277 if (arg & TIOCM_DTR)
3278 ch->ch_mval |= (D_DTR(ch));
3280 ch->ch_mval &= ~(D_DTR(ch));
3288 spin_lock_irqsave(&bd->bd_lock, lock_flags);
3289 spin_lock_irqsave(&ch->ch_lock, lock_flags2);
3293 spin_unlock_irqrestore(&ch->ch_lock, lock_flags2);
3294 spin_unlock_irqrestore(&bd->bd_lock, lock_flags);
3300 * dgap_tty_digigeta()
3302 * Ioctl to get the information for ditty.
3307 static int dgap_tty_digigeta(struct tty_struct *tty,
3308 struct digi_t __user *retinfo)
3310 struct channel_t *ch;
3318 if (!tty || tty->magic != TTY_MAGIC)
3321 un = tty->driver_data;
3322 if (!un || un->magic != DGAP_UNIT_MAGIC)
3326 if (!ch || ch->magic != DGAP_CHANNEL_MAGIC)
3329 memset(&tmp, 0, sizeof(tmp));
3331 spin_lock_irqsave(&ch->ch_lock, lock_flags);
3332 memcpy(&tmp, &ch->ch_digi, sizeof(tmp));
3333 spin_unlock_irqrestore(&ch->ch_lock, lock_flags);
3335 if (copy_to_user(retinfo, &tmp, sizeof(*retinfo)))
3342 * dgap_tty_digiseta()
3344 * Ioctl to set the information for ditty.
3349 static int dgap_tty_digiseta(struct tty_struct *tty,
3350 struct digi_t __user *new_info)
3353 struct channel_t *ch;
3355 struct digi_t new_digi;
3356 ulong lock_flags = 0;
3357 unsigned long lock_flags2;
3359 if (!tty || tty->magic != TTY_MAGIC)
3362 un = tty->driver_data;
3363 if (!un || un->magic != DGAP_UNIT_MAGIC)
3367 if (!ch || ch->magic != DGAP_CHANNEL_MAGIC)
3371 if (!bd || bd->magic != DGAP_BOARD_MAGIC)
3374 if (copy_from_user(&new_digi, new_info, sizeof(struct digi_t)))
3377 spin_lock_irqsave(&bd->bd_lock, lock_flags);
3378 spin_lock_irqsave(&ch->ch_lock, lock_flags2);
3380 memcpy(&ch->ch_digi, &new_digi, sizeof(struct digi_t));
3382 if (ch->ch_digi.digi_maxcps < 1)
3383 ch->ch_digi.digi_maxcps = 1;
3385 if (ch->ch_digi.digi_maxcps > 10000)
3386 ch->ch_digi.digi_maxcps = 10000;
3388 if (ch->ch_digi.digi_bufsize < 10)
3389 ch->ch_digi.digi_bufsize = 10;
3391 if (ch->ch_digi.digi_maxchar < 1)
3392 ch->ch_digi.digi_maxchar = 1;
3394 if (ch->ch_digi.digi_maxchar > ch->ch_digi.digi_bufsize)
3395 ch->ch_digi.digi_maxchar = ch->ch_digi.digi_bufsize;
3397 if (ch->ch_digi.digi_onlen > DIGI_PLEN)
3398 ch->ch_digi.digi_onlen = DIGI_PLEN;
3400 if (ch->ch_digi.digi_offlen > DIGI_PLEN)
3401 ch->ch_digi.digi_offlen = DIGI_PLEN;
3405 spin_unlock_irqrestore(&ch->ch_lock, lock_flags2);
3406 spin_unlock_irqrestore(&bd->bd_lock, lock_flags);
3412 * dgap_tty_digigetedelay()
3414 * Ioctl to get the current edelay setting.
3419 static int dgap_tty_digigetedelay(struct tty_struct *tty, int __user *retinfo)
3421 struct channel_t *ch;
3429 if (!tty || tty->magic != TTY_MAGIC)
3432 un = tty->driver_data;
3433 if (!un || un->magic != DGAP_UNIT_MAGIC)
3437 if (!ch || ch->magic != DGAP_CHANNEL_MAGIC)
3440 memset(&tmp, 0, sizeof(tmp));
3442 spin_lock_irqsave(&ch->ch_lock, lock_flags);
3443 tmp = readw(&(ch->ch_bs->edelay));
3444 spin_unlock_irqrestore(&ch->ch_lock, lock_flags);
3446 if (copy_to_user(retinfo, &tmp, sizeof(*retinfo)))
3453 * dgap_tty_digisetedelay()
3455 * Ioctl to set the EDELAY setting
3458 static int dgap_tty_digisetedelay(struct tty_struct *tty, int __user *new_info)
3461 struct channel_t *ch;
3467 if (!tty || tty->magic != TTY_MAGIC)
3470 un = tty->driver_data;
3471 if (!un || un->magic != DGAP_UNIT_MAGIC)
3475 if (!ch || ch->magic != DGAP_CHANNEL_MAGIC)
3479 if (!bd || bd->magic != DGAP_BOARD_MAGIC)
3482 if (copy_from_user(&new_digi, new_info, sizeof(int)))
3485 spin_lock_irqsave(&bd->bd_lock, lock_flags);
3486 spin_lock_irqsave(&ch->ch_lock, lock_flags2);
3488 writew((u16) new_digi, &(ch->ch_bs->edelay));
3492 spin_unlock_irqrestore(&ch->ch_lock, lock_flags2);
3493 spin_unlock_irqrestore(&bd->bd_lock, lock_flags);
3499 * dgap_tty_digigetcustombaud()
3501 * Ioctl to get the current custom baud rate setting.
3503 static int dgap_tty_digigetcustombaud(struct tty_struct *tty,
3504 int __user *retinfo)
3506 struct channel_t *ch;
3514 if (!tty || tty->magic != TTY_MAGIC)
3517 un = tty->driver_data;
3518 if (!un || un->magic != DGAP_UNIT_MAGIC)
3522 if (!ch || ch->magic != DGAP_CHANNEL_MAGIC)
3525 memset(&tmp, 0, sizeof(tmp));
3527 spin_lock_irqsave(&ch->ch_lock, lock_flags);
3528 tmp = dgap_get_custom_baud(ch);
3529 spin_unlock_irqrestore(&ch->ch_lock, lock_flags);
3531 if (copy_to_user(retinfo, &tmp, sizeof(*retinfo)))
3538 * dgap_tty_digisetcustombaud()
3540 * Ioctl to set the custom baud rate setting
3542 static int dgap_tty_digisetcustombaud(struct tty_struct *tty,
3543 int __user *new_info)
3546 struct channel_t *ch;
3552 if (!tty || tty->magic != TTY_MAGIC)
3555 un = tty->driver_data;
3556 if (!un || un->magic != DGAP_UNIT_MAGIC)
3560 if (!ch || ch->magic != DGAP_CHANNEL_MAGIC)
3564 if (!bd || bd->magic != DGAP_BOARD_MAGIC)
3568 if (copy_from_user(&new_rate, new_info, sizeof(unsigned int)))
3571 if (bd->bd_flags & BD_FEP5PLUS) {
3573 spin_lock_irqsave(&bd->bd_lock, lock_flags);
3574 spin_lock_irqsave(&ch->ch_lock, lock_flags2);
3576 ch->ch_custom_speed = new_rate;
3580 spin_unlock_irqrestore(&ch->ch_lock, lock_flags2);
3581 spin_unlock_irqrestore(&bd->bd_lock, lock_flags);
3588 * dgap_set_termios()
3590 static void dgap_tty_set_termios(struct tty_struct *tty,
3591 struct ktermios *old_termios)
3594 struct channel_t *ch;
3596 unsigned long lock_flags;
3597 unsigned long lock_flags2;
3599 if (!tty || tty->magic != TTY_MAGIC)
3602 un = tty->driver_data;
3603 if (!un || un->magic != DGAP_UNIT_MAGIC)
3607 if (!ch || ch->magic != DGAP_CHANNEL_MAGIC)
3611 if (!bd || bd->magic != DGAP_BOARD_MAGIC)
3614 spin_lock_irqsave(&bd->bd_lock, lock_flags);
3615 spin_lock_irqsave(&ch->ch_lock, lock_flags2);
3617 ch->ch_c_cflag = tty->termios.c_cflag;
3618 ch->ch_c_iflag = tty->termios.c_iflag;
3619 ch->ch_c_oflag = tty->termios.c_oflag;
3620 ch->ch_c_lflag = tty->termios.c_lflag;
3621 ch->ch_startc = tty->termios.c_cc[VSTART];
3622 ch->ch_stopc = tty->termios.c_cc[VSTOP];
3627 spin_unlock_irqrestore(&ch->ch_lock, lock_flags2);
3628 spin_unlock_irqrestore(&bd->bd_lock, lock_flags);
3631 static void dgap_tty_throttle(struct tty_struct *tty)
3634 struct channel_t *ch;
3639 if (!tty || tty->magic != TTY_MAGIC)
3642 un = tty->driver_data;
3643 if (!un || un->magic != DGAP_UNIT_MAGIC)
3647 if (!ch || ch->magic != DGAP_CHANNEL_MAGIC)
3651 if (!bd || bd->magic != DGAP_BOARD_MAGIC)
3654 spin_lock_irqsave(&bd->bd_lock, lock_flags);
3655 spin_lock_irqsave(&ch->ch_lock, lock_flags2);
3657 ch->ch_flags |= (CH_RXBLOCK);
3659 dgap_cmdw(ch, RPAUSE, 0, 0);
3662 spin_unlock_irqrestore(&ch->ch_lock, lock_flags2);
3663 spin_unlock_irqrestore(&bd->bd_lock, lock_flags);
3667 static void dgap_tty_unthrottle(struct tty_struct *tty)
3670 struct channel_t *ch;
3675 if (!tty || tty->magic != TTY_MAGIC)
3678 un = tty->driver_data;
3679 if (!un || un->magic != DGAP_UNIT_MAGIC)
3683 if (!ch || ch->magic != DGAP_CHANNEL_MAGIC)
3687 if (!bd || bd->magic != DGAP_BOARD_MAGIC)
3690 spin_lock_irqsave(&bd->bd_lock, lock_flags);
3691 spin_lock_irqsave(&ch->ch_lock, lock_flags2);
3693 ch->ch_flags &= ~(CH_RXBLOCK);
3696 dgap_cmdw(ch, RRESUME, 0, 0);
3699 spin_unlock_irqrestore(&ch->ch_lock, lock_flags2);
3700 spin_unlock_irqrestore(&bd->bd_lock, lock_flags);
3703 static void dgap_tty_start(struct tty_struct *tty)
3706 struct channel_t *ch;
3711 if (!tty || tty->magic != TTY_MAGIC)
3714 un = tty->driver_data;
3715 if (!un || un->magic != DGAP_UNIT_MAGIC)
3719 if (!ch || ch->magic != DGAP_CHANNEL_MAGIC)
3723 if (!bd || bd->magic != DGAP_BOARD_MAGIC)
3726 spin_lock_irqsave(&bd->bd_lock, lock_flags);
3727 spin_lock_irqsave(&ch->ch_lock, lock_flags2);
3729 dgap_cmdw(ch, RESUMETX, 0, 0);
3731 spin_unlock_irqrestore(&ch->ch_lock, lock_flags2);
3732 spin_unlock_irqrestore(&bd->bd_lock, lock_flags);
3736 static void dgap_tty_stop(struct tty_struct *tty)
3739 struct channel_t *ch;
3744 if (!tty || tty->magic != TTY_MAGIC)
3747 un = tty->driver_data;
3748 if (!un || un->magic != DGAP_UNIT_MAGIC)
3752 if (!ch || ch->magic != DGAP_CHANNEL_MAGIC)
3756 if (!bd || bd->magic != DGAP_BOARD_MAGIC)
3759 spin_lock_irqsave(&bd->bd_lock, lock_flags);
3760 spin_lock_irqsave(&ch->ch_lock, lock_flags2);
3762 dgap_cmdw(ch, PAUSETX, 0, 0);
3764 spin_unlock_irqrestore(&ch->ch_lock, lock_flags2);
3765 spin_unlock_irqrestore(&bd->bd_lock, lock_flags);
3770 * dgap_tty_flush_chars()
3772 * Flush the cook buffer
3774 * Note to self, and any other poor souls who venture here:
3776 * flush in this case DOES NOT mean dispose of the data.
3777 * instead, it means "stop buffering and send it if you
3778 * haven't already." Just guess how I figured that out... SRW 2-Jun-98
3780 * It is also always called in interrupt context - JAR 8-Sept-99
3782 static void dgap_tty_flush_chars(struct tty_struct *tty)
3785 struct channel_t *ch;
3790 if (!tty || tty->magic != TTY_MAGIC)
3793 un = tty->driver_data;
3794 if (!un || un->magic != DGAP_UNIT_MAGIC)
3798 if (!ch || ch->magic != DGAP_CHANNEL_MAGIC)
3802 if (!bd || bd->magic != DGAP_BOARD_MAGIC)
3805 spin_lock_irqsave(&bd->bd_lock, lock_flags);
3806 spin_lock_irqsave(&ch->ch_lock, lock_flags2);
3808 /* TODO: Do something here */
3810 spin_unlock_irqrestore(&ch->ch_lock, lock_flags2);
3811 spin_unlock_irqrestore(&bd->bd_lock, lock_flags);
3815 * dgap_tty_flush_buffer()
3817 * Flush Tx buffer (make in == out)
3819 static void dgap_tty_flush_buffer(struct tty_struct *tty)
3822 struct channel_t *ch;
3828 if (!tty || tty->magic != TTY_MAGIC)
3831 un = tty->driver_data;
3832 if (!un || un->magic != DGAP_UNIT_MAGIC)
3836 if (!ch || ch->magic != DGAP_CHANNEL_MAGIC)
3840 if (!bd || bd->magic != DGAP_BOARD_MAGIC)
3843 spin_lock_irqsave(&bd->bd_lock, lock_flags);
3844 spin_lock_irqsave(&ch->ch_lock, lock_flags2);
3846 ch->ch_flags &= ~CH_STOP;
3847 head = readw(&(ch->ch_bs->tx_head));
3848 dgap_cmdw(ch, FLUSHTX, (u16) head, 0);
3849 dgap_cmdw(ch, RESUMETX, 0, 0);
3850 if (ch->ch_tun.un_flags & (UN_LOW|UN_EMPTY)) {
3851 ch->ch_tun.un_flags &= ~(UN_LOW|UN_EMPTY);
3852 wake_up_interruptible(&ch->ch_tun.un_flags_wait);
3854 if (ch->ch_pun.un_flags & (UN_LOW|UN_EMPTY)) {
3855 ch->ch_pun.un_flags &= ~(UN_LOW|UN_EMPTY);
3856 wake_up_interruptible(&ch->ch_pun.un_flags_wait);
3859 spin_unlock_irqrestore(&ch->ch_lock, lock_flags2);
3860 spin_unlock_irqrestore(&bd->bd_lock, lock_flags);
3861 if (waitqueue_active(&tty->write_wait))
3862 wake_up_interruptible(&tty->write_wait);
3866 /*****************************************************************************
3868 * The IOCTL function and all of its helpers
3870 *****************************************************************************/
3875 * The usual assortment of ioctl's
3877 static int dgap_tty_ioctl(struct tty_struct *tty, unsigned int cmd,
3881 struct channel_t *ch;
3885 ulong lock_flags = 0;
3886 ulong lock_flags2 = 0;
3887 void __user *uarg = (void __user *) arg;
3889 if (!tty || tty->magic != TTY_MAGIC)
3892 un = tty->driver_data;
3893 if (!un || un->magic != DGAP_UNIT_MAGIC)
3897 if (!ch || ch->magic != DGAP_CHANNEL_MAGIC)
3901 if (!bd || bd->magic != DGAP_BOARD_MAGIC)
3904 spin_lock_irqsave(&bd->bd_lock, lock_flags);
3905 spin_lock_irqsave(&ch->ch_lock, lock_flags2);
3907 if (un->un_open_count <= 0) {
3908 spin_unlock_irqrestore(&ch->ch_lock, lock_flags2);
3909 spin_unlock_irqrestore(&bd->bd_lock, lock_flags);
3915 /* Here are all the standard ioctl's that we MUST implement */
3919 * TCSBRK is SVID version: non-zero arg --> no break
3920 * this behaviour is exploited by tcdrain().
3922 * According to POSIX.1 spec (7.2.2.1.2) breaks should be
3923 * between 0.25 and 0.5 seconds so we'll ask for something
3924 * in the middle: 0.375 seconds.
3926 rc = tty_check_change(tty);
3927 spin_unlock_irqrestore(&ch->ch_lock, lock_flags2);
3928 spin_unlock_irqrestore(&bd->bd_lock, lock_flags);
3932 rc = dgap_wait_for_drain(tty);
3937 spin_lock_irqsave(&bd->bd_lock, lock_flags);
3938 spin_lock_irqsave(&ch->ch_lock, lock_flags2);
3940 if (((cmd == TCSBRK) && (!arg)) || (cmd == TCSBRKP))
3941 dgap_cmdw(ch, SBREAK, (u16) SBREAK_TIME, 0);
3943 spin_unlock_irqrestore(&ch->ch_lock, lock_flags2);
3944 spin_unlock_irqrestore(&bd->bd_lock, lock_flags);
3949 /* support for POSIX tcsendbreak()
3951 * According to POSIX.1 spec (7.2.2.1.2) breaks should be
3952 * between 0.25 and 0.5 seconds so we'll ask for something
3953 * in the middle: 0.375 seconds.
3955 rc = tty_check_change(tty);
3956 spin_unlock_irqrestore(&ch->ch_lock, lock_flags2);
3957 spin_unlock_irqrestore(&bd->bd_lock, lock_flags);
3961 rc = dgap_wait_for_drain(tty);
3965 spin_lock_irqsave(&bd->bd_lock, lock_flags);
3966 spin_lock_irqsave(&ch->ch_lock, lock_flags2);
3968 dgap_cmdw(ch, SBREAK, (u16) SBREAK_TIME, 0);
3970 spin_unlock_irqrestore(&ch->ch_lock, lock_flags2);
3971 spin_unlock_irqrestore(&bd->bd_lock, lock_flags);
3977 * FEP5 doesn't support turning on a break unconditionally.
3978 * The FEP5 device will stop sending a break automatically
3979 * after the specified time value that was sent when turning on
3982 rc = tty_check_change(tty);
3983 spin_unlock_irqrestore(&ch->ch_lock, lock_flags2);
3984 spin_unlock_irqrestore(&bd->bd_lock, lock_flags);
3988 rc = dgap_wait_for_drain(tty);
3992 spin_lock_irqsave(&bd->bd_lock, lock_flags);
3993 spin_lock_irqsave(&ch->ch_lock, lock_flags2);
3995 dgap_cmdw(ch, SBREAK, (u16) SBREAK_TIME, 0);
3997 spin_unlock_irqrestore(&ch->ch_lock, lock_flags2);
3998 spin_unlock_irqrestore(&bd->bd_lock, lock_flags);
4004 * FEP5 doesn't support turning off a break unconditionally.
4005 * The FEP5 device will stop sending a break automatically
4006 * after the specified time value that was sent when turning on
4009 spin_unlock_irqrestore(&ch->ch_lock, lock_flags2);
4010 spin_unlock_irqrestore(&bd->bd_lock, lock_flags);
4015 spin_unlock_irqrestore(&ch->ch_lock, lock_flags2);
4016 spin_unlock_irqrestore(&bd->bd_lock, lock_flags);
4018 rc = put_user(C_CLOCAL(tty) ? 1 : 0,
4019 (unsigned long __user *) arg);
4023 spin_unlock_irqrestore(&ch->ch_lock, lock_flags2);
4024 spin_unlock_irqrestore(&bd->bd_lock, lock_flags);
4026 rc = get_user(arg, (unsigned long __user *) arg);
4030 spin_lock_irqsave(&bd->bd_lock, lock_flags);
4031 spin_lock_irqsave(&ch->ch_lock, lock_flags2);
4032 tty->termios.c_cflag = ((tty->termios.c_cflag & ~CLOCAL) |
4033 (arg ? CLOCAL : 0));
4035 spin_unlock_irqrestore(&ch->ch_lock, lock_flags2);
4036 spin_unlock_irqrestore(&bd->bd_lock, lock_flags);
4041 spin_unlock_irqrestore(&ch->ch_lock, lock_flags2);
4042 spin_unlock_irqrestore(&bd->bd_lock, lock_flags);
4043 return dgap_get_modem_info(ch, uarg);
4048 spin_unlock_irqrestore(&ch->ch_lock, lock_flags2);
4049 spin_unlock_irqrestore(&bd->bd_lock, lock_flags);
4050 return dgap_set_modem_info(tty, cmd, uarg);
4053 * Here are any additional ioctl's that we want to implement
4058 * The linux tty driver doesn't have a flush
4059 * input routine for the driver, assuming all backed
4060 * up data is in the line disc. buffers. However,
4061 * we all know that's not the case. Here, we
4062 * act on the ioctl, but then lie and say we didn't
4063 * so the line discipline will process the flush
4066 rc = tty_check_change(tty);
4068 spin_unlock_irqrestore(&ch->ch_lock, lock_flags2);
4069 spin_unlock_irqrestore(&bd->bd_lock, lock_flags);
4073 if ((arg == TCIFLUSH) || (arg == TCIOFLUSH)) {
4074 if (!(un->un_type == DGAP_PRINT)) {
4075 head = readw(&(ch->ch_bs->rx_head));
4076 writew(head, &(ch->ch_bs->rx_tail));
4077 writeb(0, &(ch->ch_bs->orun));
4081 if ((arg != TCOFLUSH) && (arg != TCIOFLUSH)) {
4082 /* pretend we didn't recognize this IOCTL */
4083 spin_unlock_irqrestore(&ch->ch_lock, lock_flags2);
4084 spin_unlock_irqrestore(&bd->bd_lock, lock_flags);
4086 return -ENOIOCTLCMD;
4089 ch->ch_flags &= ~CH_STOP;
4090 head = readw(&(ch->ch_bs->tx_head));
4091 dgap_cmdw(ch, FLUSHTX, (u16) head, 0);
4092 dgap_cmdw(ch, RESUMETX, 0, 0);
4093 if (ch->ch_tun.un_flags & (UN_LOW|UN_EMPTY)) {
4094 ch->ch_tun.un_flags &= ~(UN_LOW|UN_EMPTY);
4095 wake_up_interruptible(&ch->ch_tun.un_flags_wait);
4097 if (ch->ch_pun.un_flags & (UN_LOW|UN_EMPTY)) {
4098 ch->ch_pun.un_flags &= ~(UN_LOW|UN_EMPTY);
4099 wake_up_interruptible(&ch->ch_pun.un_flags_wait);
4101 if (waitqueue_active(&tty->write_wait))
4102 wake_up_interruptible(&tty->write_wait);
4104 /* Can't hold any locks when calling tty_wakeup! */
4105 spin_unlock_irqrestore(&ch->ch_lock, lock_flags2);
4106 spin_unlock_irqrestore(&bd->bd_lock, lock_flags);
4109 /* pretend we didn't recognize this IOCTL */
4110 return -ENOIOCTLCMD;
4115 * The linux tty driver doesn't have a flush
4116 * input routine for the driver, assuming all backed
4117 * up data is in the line disc. buffers. However,
4118 * we all know that's not the case. Here, we
4119 * act on the ioctl, but then lie and say we didn't
4120 * so the line discipline will process the flush
4123 if (cmd == TCSETSF) {
4125 ch->ch_flags &= ~CH_STOP;
4126 head = readw(&(ch->ch_bs->rx_head));
4127 writew(head, &(ch->ch_bs->rx_tail));
4130 /* now wait for all the output to drain */
4131 spin_unlock_irqrestore(&ch->ch_lock, lock_flags2);
4132 spin_unlock_irqrestore(&bd->bd_lock, lock_flags);
4133 rc = dgap_wait_for_drain(tty);
4137 /* pretend we didn't recognize this */
4138 return -ENOIOCTLCMD;
4142 spin_unlock_irqrestore(&ch->ch_lock, lock_flags2);
4143 spin_unlock_irqrestore(&bd->bd_lock, lock_flags);
4144 rc = dgap_wait_for_drain(tty);
4148 /* pretend we didn't recognize this */
4149 return -ENOIOCTLCMD;
4153 * The Linux Line Discipline (LD) would do this for us if we
4154 * let it, but we have the special firmware options to do this
4155 * the "right way" regardless of hardware or software flow
4156 * control so we'll do it outselves instead of letting the LD
4159 rc = tty_check_change(tty);
4161 spin_unlock_irqrestore(&ch->ch_lock, lock_flags2);
4162 spin_unlock_irqrestore(&bd->bd_lock, lock_flags);
4169 spin_unlock_irqrestore(&ch->ch_lock, lock_flags2);
4170 spin_unlock_irqrestore(&bd->bd_lock, lock_flags);
4171 dgap_tty_start(tty);
4174 spin_unlock_irqrestore(&ch->ch_lock, lock_flags2);
4175 spin_unlock_irqrestore(&bd->bd_lock, lock_flags);
4179 spin_unlock_irqrestore(&ch->ch_lock, lock_flags2);
4180 spin_unlock_irqrestore(&bd->bd_lock, lock_flags);
4181 /* Make the ld do it */
4182 return -ENOIOCTLCMD;
4184 spin_unlock_irqrestore(&ch->ch_lock, lock_flags2);
4185 spin_unlock_irqrestore(&bd->bd_lock, lock_flags);
4186 /* Make the ld do it */
4187 return -ENOIOCTLCMD;
4189 spin_unlock_irqrestore(&ch->ch_lock, lock_flags2);
4190 spin_unlock_irqrestore(&bd->bd_lock, lock_flags);
4195 /* get information for ditty */
4196 spin_unlock_irqrestore(&ch->ch_lock, lock_flags2);
4197 spin_unlock_irqrestore(&bd->bd_lock, lock_flags);
4198 return dgap_tty_digigeta(tty, uarg);
4203 /* set information for ditty */
4204 if (cmd == (DIGI_SETAW)) {
4206 spin_unlock_irqrestore(&ch->ch_lock, lock_flags2);
4207 spin_unlock_irqrestore(&bd->bd_lock, lock_flags);
4208 rc = dgap_wait_for_drain(tty);
4211 spin_lock_irqsave(&bd->bd_lock, lock_flags);
4212 spin_lock_irqsave(&ch->ch_lock, lock_flags2);
4214 tty_ldisc_flush(tty);
4218 spin_unlock_irqrestore(&ch->ch_lock, lock_flags2);
4219 spin_unlock_irqrestore(&bd->bd_lock, lock_flags);
4220 return dgap_tty_digiseta(tty, uarg);
4223 spin_unlock_irqrestore(&ch->ch_lock, lock_flags2);
4224 spin_unlock_irqrestore(&bd->bd_lock, lock_flags);
4225 return dgap_tty_digigetedelay(tty, uarg);
4228 spin_unlock_irqrestore(&ch->ch_lock, lock_flags2);
4229 spin_unlock_irqrestore(&bd->bd_lock, lock_flags);
4230 return dgap_tty_digisetedelay(tty, uarg);
4232 case DIGI_GETCUSTOMBAUD:
4233 spin_unlock_irqrestore(&ch->ch_lock, lock_flags2);
4234 spin_unlock_irqrestore(&bd->bd_lock, lock_flags);
4235 return dgap_tty_digigetcustombaud(tty, uarg);
4237 case DIGI_SETCUSTOMBAUD:
4238 spin_unlock_irqrestore(&ch->ch_lock, lock_flags2);
4239 spin_unlock_irqrestore(&bd->bd_lock, lock_flags);
4240 return dgap_tty_digisetcustombaud(tty, uarg);
4242 case DIGI_RESET_PORT:
4243 dgap_firmware_reset_port(ch);
4245 spin_unlock_irqrestore(&ch->ch_lock, lock_flags2);
4246 spin_unlock_irqrestore(&bd->bd_lock, lock_flags);
4250 spin_unlock_irqrestore(&ch->ch_lock, lock_flags2);
4251 spin_unlock_irqrestore(&bd->bd_lock, lock_flags);
4253 return -ENOIOCTLCMD;
4257 static int dgap_after_config_loaded(int board)
4260 * Initialize KME waitqueues...
4262 init_waitqueue_head(&(dgap_Board[board]->kme_wait));
4265 * allocate flip buffer for board.
4267 dgap_Board[board]->flipbuf = kmalloc(MYFLIPLEN, GFP_ATOMIC);
4268 if (!dgap_Board[board]->flipbuf)
4271 dgap_Board[board]->flipflagbuf = kmalloc(MYFLIPLEN, GFP_ATOMIC);
4272 if (!dgap_Board[board]->flipflagbuf) {
4273 kfree(dgap_Board[board]->flipbuf);
4281 * Create pr and tty device entries
4283 static int dgap_tty_register_ports(struct board_t *brd)
4285 struct channel_t *ch;
4288 brd->SerialPorts = kcalloc(brd->nasync, sizeof(*brd->SerialPorts),
4290 if (brd->SerialPorts == NULL)
4292 for (i = 0; i < brd->nasync; i++)
4293 tty_port_init(&brd->SerialPorts[i]);
4295 brd->PrinterPorts = kcalloc(brd->nasync, sizeof(*brd->PrinterPorts),
4297 if (brd->PrinterPorts == NULL) {
4298 kfree(brd->SerialPorts);
4301 for (i = 0; i < brd->nasync; i++)
4302 tty_port_init(&brd->PrinterPorts[i]);
4304 ch = brd->channels[0];
4305 for (i = 0; i < brd->nasync; i++, ch = brd->channels[i]) {
4307 struct device *classp;
4309 classp = tty_port_register_device(&brd->SerialPorts[i],
4311 brd->firstminor + i, NULL);
4313 dgap_create_tty_sysfs(&ch->ch_tun, classp);
4314 ch->ch_tun.un_sysfs = classp;
4316 classp = tty_port_register_device(&brd->PrinterPorts[i],
4318 brd->firstminor + i, NULL);
4320 dgap_create_tty_sysfs(&ch->ch_pun, classp);
4321 ch->ch_pun.un_sysfs = classp;
4323 dgap_create_ports_sysfiles(brd);
4329 * Copies the BIOS code from the user to the board,
4330 * and starts the BIOS running.
4332 static void dgap_do_bios_load(struct board_t *brd, const uchar *ubios, int len)
4338 if (!brd || (brd->magic != DGAP_BOARD_MAGIC) || !brd->re_map_membase)
4341 addr = brd->re_map_membase;
4346 for (i = 0; i < 16; i++)
4347 writeb(0, addr + POSTAREA + i);
4353 memcpy_toio(addr + offset, ubios, len);
4355 writel(0x0bf00401, addr);
4356 writel(0, (addr + 4));
4358 /* Clear the reset, and change states. */
4359 writeb(FEPCLR, brd->re_map_port);
4363 * Checks to see if the BIOS completed running on the card.
4365 static int dgap_do_wait_for_bios(struct board_t *brd)
4373 if (!brd || (brd->magic != DGAP_BOARD_MAGIC) || !brd->re_map_membase)
4376 addr = brd->re_map_membase;
4377 word = readw(addr + POSTAREA);
4380 * It can take 5-6 seconds for a board to
4381 * pass the bios self test and post results.
4382 * Give it 10 seconds.
4384 brd->wait_for_bios = 0;
4385 while (brd->wait_for_bios < 1000) {
4386 /* Check to see if BIOS thinks board is good. (GD). */
4387 if (word == *(u16 *) "GD")
4389 msleep_interruptible(10);
4390 brd->wait_for_bios++;
4391 word = readw(addr + POSTAREA);
4394 /* Gave up on board after too long of time taken */
4395 err1 = readw(addr + SEQUENCE);
4396 err2 = readw(addr + ERROR);
4397 pr_warn("dgap: %s failed diagnostics. Error #(%x,%x).\n",
4398 brd->name, err1, err2);
4399 brd->state = BOARD_FAILED;
4400 brd->dpastatus = BD_NOBIOS;
4406 * Copies the FEP code from the user to the board,
4407 * and starts the FEP running.
4409 static void dgap_do_fep_load(struct board_t *brd, const uchar *ufep, int len)
4414 if (!brd || (brd->magic != DGAP_BOARD_MAGIC) || !brd->re_map_membase)
4417 addr = brd->re_map_membase;
4423 memcpy_toio(addr + offset, ufep, len);
4426 * If board is a concentrator product, we need to give
4427 * it its config string describing how the concentrators look.
4429 if ((brd->type == PCX) || (brd->type == PEPC)) {
4431 uchar *config, *xconfig;
4434 xconfig = dgap_create_config_string(brd, string);
4436 /* Write string to board memory */
4437 config = addr + CONFIG;
4438 for (; i < CONFIGSIZE; i++, config++, xconfig++) {
4439 writeb(*xconfig, config);
4440 if ((*xconfig & 0xff) == 0xff)
4445 writel(0xbfc01004, (addr + 0xc34));
4446 writel(0x3, (addr + 0xc30));
4451 * Waits for the FEP to report thats its ready for us to use.
4453 static int dgap_do_wait_for_fep(struct board_t *brd)
4461 if (!brd || (brd->magic != DGAP_BOARD_MAGIC) || !brd->re_map_membase)
4464 addr = brd->re_map_membase;
4465 word = readw(addr + FEPSTAT);
4468 * It can take 2-3 seconds for the FEP to
4469 * be up and running. Give it 5 secs.
4471 brd->wait_for_fep = 0;
4472 while (brd->wait_for_fep < 500) {
4473 /* Check to see if FEP is up and running now. */
4474 if (word == *(u16 *) "OS") {
4476 * Check to see if the board can support FEP5+ commands.
4478 word = readw(addr + FEP5_PLUS);
4479 if (word == *(u16 *) "5A")
4480 brd->bd_flags |= BD_FEP5PLUS;
4484 msleep_interruptible(10);
4485 brd->wait_for_fep++;
4486 word = readw(addr + FEPSTAT);
4489 /* Gave up on board after too long of time taken */
4490 err1 = readw(addr + SEQUENCE);
4491 err2 = readw(addr + ERROR);
4492 pr_warn("dgap: FEPOS for %s not functioning. Error #(%x,%x).\n",
4493 brd->name, err1, err2);
4494 brd->state = BOARD_FAILED;
4495 brd->dpastatus = BD_NOFEP;
4501 * Physically forces the FEP5 card to reset itself.
4503 static void dgap_do_reset_board(struct board_t *brd)
4510 if (!brd || (brd->magic != DGAP_BOARD_MAGIC) ||
4511 !brd->re_map_membase || !brd->re_map_port)
4514 /* FEPRST does not vary among supported boards */
4515 writeb(FEPRST, brd->re_map_port);
4517 for (i = 0; i <= 1000; i++) {
4518 check = readb(brd->re_map_port) & 0xe;
4519 if (check == FEPRST)
4525 pr_warn("dgap: Board not resetting... Failing board.\n");
4526 brd->state = BOARD_FAILED;
4527 brd->dpastatus = BD_NOFEP;
4532 * Make sure there really is memory out there.
4534 writel(0xa55a3cc3, (brd->re_map_membase + LOWMEM));
4535 writel(0x5aa5c33c, (brd->re_map_membase + HIGHMEM));
4536 check1 = readl(brd->re_map_membase + LOWMEM);
4537 check2 = readl(brd->re_map_membase + HIGHMEM);
4539 if ((check1 != 0xa55a3cc3) || (check2 != 0x5aa5c33c)) {
4540 pr_warn("dgap: No memory at %p for board.\n",
4541 brd->re_map_membase);
4542 brd->state = BOARD_FAILED;
4543 brd->dpastatus = BD_NOFEP;
4549 #ifdef DIGI_CONCENTRATORS_SUPPORTED
4551 * Sends a concentrator image into the FEP5 board.
4553 static void dgap_do_conc_load(struct board_t *brd, uchar *uaddr, int len)
4557 struct downld_t *to_dp;
4559 if (!brd || (brd->magic != DGAP_BOARD_MAGIC) || !brd->re_map_membase)
4562 vaddr = brd->re_map_membase;
4564 offset = readw((u16 *) (vaddr + DOWNREQ));
4565 to_dp = (struct downld_t *) (vaddr + (int) offset);
4566 memcpy_toio(to_dp, uaddr, len);
4568 /* Tell card we have data for it */
4569 writew(0, vaddr + (DOWNREQ));
4571 brd->conc_dl_status = NO_PENDING_CONCENTRATOR_REQUESTS;
4575 #define EXPANSION_ROM_SIZE (64 * 1024)
4576 #define FEP5_ROM_MAGIC (0xFEFFFFFF)
4578 static void dgap_get_vpd(struct board_t *brd)
4590 * Poke the magic number at the PCI Rom Address location.
4591 * If VPD is supported, the value read from that address
4594 magic = FEP5_ROM_MAGIC;
4595 pci_write_config_dword(brd->pdev, PCI_ROM_ADDRESS, magic);
4596 pci_read_config_dword(brd->pdev, PCI_ROM_ADDRESS, &magic);
4598 /* VPD not supported, bail */
4603 * To get to the OTPROM memory, we have to send the boards base
4604 * address or'ed with 1 into the PCI Rom Address location.
4606 magic = brd->membase | 0x01;
4607 pci_write_config_dword(brd->pdev, PCI_ROM_ADDRESS, magic);
4608 pci_read_config_dword(brd->pdev, PCI_ROM_ADDRESS, &magic);
4610 byte1 = readb(brd->re_map_membase);
4611 byte2 = readb(brd->re_map_membase + 1);
4614 * If the board correctly swapped to the OTPROM memory,
4615 * the first 2 bytes (header) should be 0x55, 0xAA
4617 if (byte1 == 0x55 && byte2 == 0xAA) {
4622 * We have to run through all the OTPROM memory looking
4623 * for the VPD offset.
4625 while (base_offset <= EXPANSION_ROM_SIZE) {
4628 * Lots of magic numbers here.
4630 * The VPD offset is located inside the ROM Data
4633 * We also have to remember the length of each
4634 * ROM Data Structure, so we can "hop" to the next
4635 * entry if the VPD isn't in the current
4636 * ROM Data Structure.
4638 rom_offset = readw(brd->re_map_membase +
4639 base_offset + 0x18);
4640 image_length = readw(brd->re_map_membase +
4641 rom_offset + 0x10) * 512;
4642 vpd_offset = readw(brd->re_map_membase +
4645 /* Found the VPD entry */
4649 /* We didn't find a VPD entry, go to next ROM entry. */
4650 base_offset += image_length;
4652 byte1 = readb(brd->re_map_membase + base_offset);
4653 byte2 = readb(brd->re_map_membase + base_offset + 1);
4656 * If the new ROM offset doesn't have 0x55, 0xAA
4657 * as its header, we have run out of ROM.
4659 if (byte1 != 0x55 || byte2 != 0xAA)
4664 * If we have a VPD offset, then mark the board
4665 * as having a valid VPD, and copy VPDSIZE (512) bytes of
4666 * that VPD to the buffer we have in our board structure.
4669 brd->bd_flags |= BD_HAS_VPD;
4670 for (i = 0; i < VPDSIZE; i++) {
4671 brd->vpd[i] = readb(brd->re_map_membase +
4678 * We MUST poke the magic number at the PCI Rom Address location again.
4679 * This makes the card report the regular board memory back to us,
4680 * rather than the OTPROM memory.
4682 magic = FEP5_ROM_MAGIC;
4683 pci_write_config_dword(brd->pdev, PCI_ROM_ADDRESS, magic);
4687 * Our board poller function.
4689 static void dgap_poll_tasklet(unsigned long data)
4691 struct board_t *bd = (struct board_t *) data;
4696 if (!bd || (bd->magic != DGAP_BOARD_MAGIC))
4699 if (bd->inhibit_poller)
4702 spin_lock_irqsave(&bd->bd_lock, lock_flags);
4704 vaddr = bd->re_map_membase;
4707 * If board is ready, parse deeper to see if there is anything to do.
4709 if (bd->state == BOARD_READY) {
4711 struct ev_t *eaddr = NULL;
4713 if (!bd->re_map_membase) {
4714 spin_unlock_irqrestore(&bd->bd_lock, lock_flags);
4717 if (!bd->re_map_port) {
4718 spin_unlock_irqrestore(&bd->bd_lock, lock_flags);
4725 eaddr = (struct ev_t *) (vaddr + EVBUF);
4727 /* Get our head and tail */
4728 head = readw(&(eaddr->ev_head));
4729 tail = readw(&(eaddr->ev_tail));
4732 * If there is an event pending. Go service it.
4735 spin_unlock_irqrestore(&bd->bd_lock, lock_flags);
4737 spin_lock_irqsave(&bd->bd_lock, lock_flags);
4742 * If board is doing interrupts, ACK the interrupt.
4744 if (bd && bd->intr_running)
4745 readb(bd->re_map_port + 2);
4747 spin_unlock_irqrestore(&bd->bd_lock, lock_flags);
4751 spin_unlock_irqrestore(&bd->bd_lock, lock_flags);
4754 /*=======================================================================
4756 * dgap_cmdb - Sends a 2 byte command to the FEP.
4758 * ch - Pointer to channel structure.
4759 * cmd - Command to be sent.
4760 * byte1 - Integer containing first byte to be sent.
4761 * byte2 - Integer containing second byte to be sent.
4762 * ncmds - Wait until ncmds or fewer cmds are left
4763 * in the cmd buffer before returning.
4765 *=======================================================================*/
4766 static void dgap_cmdb(struct channel_t *ch, uchar cmd, uchar byte1,
4767 uchar byte2, uint ncmds)
4770 struct cm_t *cm_addr = NULL;
4776 if (!ch || ch->magic != DGAP_CHANNEL_MAGIC)
4780 * Check if board is still alive.
4782 if (ch->ch_bd->state == BOARD_FAILED)
4786 * Make sure the pointers are in range before
4787 * writing to the FEP memory.
4789 vaddr = ch->ch_bd->re_map_membase;
4794 cm_addr = (struct cm_t *) (vaddr + CMDBUF);
4795 head = readw(&(cm_addr->cm_head));
4798 * Forget it if pointers out of range.
4800 if (head >= (CMDMAX - CMDSTART) || (head & 03)) {
4801 ch->ch_bd->state = BOARD_FAILED;
4806 * Put the data in the circular command buffer.
4808 writeb(cmd, (char *) (vaddr + head + CMDSTART + 0));
4809 writeb((uchar) ch->ch_portnum, (char *) (vaddr + head + CMDSTART + 1));
4810 writeb(byte1, (char *) (vaddr + head + CMDSTART + 2));
4811 writeb(byte2, (char *) (vaddr + head + CMDSTART + 3));
4813 head = (head + 4) & (CMDMAX - CMDSTART - 4);
4815 writew(head, &(cm_addr->cm_head));
4818 * Wait if necessary before updating the head
4819 * pointer to limit the number of outstanding
4820 * commands to the FEP. If the time spent waiting
4821 * is outlandish, declare the FEP dead.
4823 for (count = dgap_count ;;) {
4825 head = readw(&(cm_addr->cm_head));
4826 tail = readw(&(cm_addr->cm_tail));
4828 n = (head - tail) & (CMDMAX - CMDSTART - 4);
4830 if (n <= ncmds * sizeof(struct cm_t))
4834 ch->ch_bd->state = BOARD_FAILED;
4841 /*=======================================================================
4843 * dgap_cmdw - Sends a 1 word command to the FEP.
4845 * ch - Pointer to channel structure.
4846 * cmd - Command to be sent.
4847 * word - Integer containing word to be sent.
4848 * ncmds - Wait until ncmds or fewer cmds are left
4849 * in the cmd buffer before returning.
4851 *=======================================================================*/
4852 static void dgap_cmdw(struct channel_t *ch, uchar cmd, u16 word, uint ncmds)
4855 struct cm_t *cm_addr = NULL;
4861 if (!ch || ch->magic != DGAP_CHANNEL_MAGIC)
4865 * Check if board is still alive.
4867 if (ch->ch_bd->state == BOARD_FAILED)
4871 * Make sure the pointers are in range before
4872 * writing to the FEP memory.
4874 vaddr = ch->ch_bd->re_map_membase;
4878 cm_addr = (struct cm_t *) (vaddr + CMDBUF);
4879 head = readw(&(cm_addr->cm_head));
4882 * Forget it if pointers out of range.
4884 if (head >= (CMDMAX - CMDSTART) || (head & 03)) {
4885 ch->ch_bd->state = BOARD_FAILED;
4890 * Put the data in the circular command buffer.
4892 writeb(cmd, (char *) (vaddr + head + CMDSTART + 0));
4893 writeb((uchar) ch->ch_portnum, (char *) (vaddr + head + CMDSTART + 1));
4894 writew((u16) word, (char *) (vaddr + head + CMDSTART + 2));
4896 head = (head + 4) & (CMDMAX - CMDSTART - 4);
4898 writew(head, &(cm_addr->cm_head));
4901 * Wait if necessary before updating the head
4902 * pointer to limit the number of outstanding
4903 * commands to the FEP. If the time spent waiting
4904 * is outlandish, declare the FEP dead.
4906 for (count = dgap_count ;;) {
4908 head = readw(&(cm_addr->cm_head));
4909 tail = readw(&(cm_addr->cm_tail));
4911 n = (head - tail) & (CMDMAX - CMDSTART - 4);
4913 if (n <= ncmds * sizeof(struct cm_t))
4917 ch->ch_bd->state = BOARD_FAILED;
4924 /*=======================================================================
4926 * dgap_cmdw_ext - Sends a extended word command to the FEP.
4928 * ch - Pointer to channel structure.
4929 * cmd - Command to be sent.
4930 * word - Integer containing word to be sent.
4931 * ncmds - Wait until ncmds or fewer cmds are left
4932 * in the cmd buffer before returning.
4934 *=======================================================================*/
4935 static void dgap_cmdw_ext(struct channel_t *ch, u16 cmd, u16 word, uint ncmds)
4938 struct cm_t *cm_addr = NULL;
4944 if (!ch || ch->magic != DGAP_CHANNEL_MAGIC)
4948 * Check if board is still alive.
4950 if (ch->ch_bd->state == BOARD_FAILED)
4954 * Make sure the pointers are in range before
4955 * writing to the FEP memory.
4957 vaddr = ch->ch_bd->re_map_membase;
4961 cm_addr = (struct cm_t *) (vaddr + CMDBUF);
4962 head = readw(&(cm_addr->cm_head));
4965 * Forget it if pointers out of range.
4967 if (head >= (CMDMAX - CMDSTART) || (head & 03)) {
4968 ch->ch_bd->state = BOARD_FAILED;
4973 * Put the data in the circular command buffer.
4976 /* Write an FF to tell the FEP that we want an extended command */
4977 writeb((uchar) 0xff, (char *) (vaddr + head + CMDSTART + 0));
4979 writeb((uchar) ch->ch_portnum, (uchar *) (vaddr + head + CMDSTART + 1));
4980 writew((u16) cmd, (char *) (vaddr + head + CMDSTART + 2));
4983 * If the second part of the command won't fit,
4984 * put it at the beginning of the circular buffer.
4986 if (((head + 4) >= ((CMDMAX - CMDSTART)) || (head & 03)))
4987 writew((u16) word, (char *) (vaddr + CMDSTART));
4989 writew((u16) word, (char *) (vaddr + head + CMDSTART + 4));
4991 head = (head + 8) & (CMDMAX - CMDSTART - 4);
4993 writew(head, &(cm_addr->cm_head));
4996 * Wait if necessary before updating the head
4997 * pointer to limit the number of outstanding
4998 * commands to the FEP. If the time spent waiting
4999 * is outlandish, declare the FEP dead.
5001 for (count = dgap_count ;;) {
5003 head = readw(&(cm_addr->cm_head));
5004 tail = readw(&(cm_addr->cm_tail));
5006 n = (head - tail) & (CMDMAX - CMDSTART - 4);
5008 if (n <= ncmds * sizeof(struct cm_t))
5012 ch->ch_bd->state = BOARD_FAILED;
5019 /*=======================================================================
5021 * dgap_wmove - Write data to FEP buffer.
5023 * ch - Pointer to channel structure.
5024 * buf - Poiter to characters to be moved.
5025 * cnt - Number of characters to move.
5027 *=======================================================================*/
5028 static void dgap_wmove(struct channel_t *ch, char *buf, uint cnt)
5035 if (!ch || ch->magic != DGAP_CHANNEL_MAGIC)
5042 head = readw(&(bs->tx_head));
5045 * If pointers are out of range, just return.
5047 if ((cnt > ch->ch_tsize) ||
5048 (unsigned)(head - ch->ch_tstart) >= ch->ch_tsize)
5052 * If the write wraps over the top of the circular buffer,
5053 * move the portion up to the wrap point, and reset the
5054 * pointers to the bottom.
5056 n = ch->ch_tstart + ch->ch_tsize - head;
5060 taddr = ch->ch_taddr + head;
5061 memcpy_toio(taddr, buf, n);
5062 head = ch->ch_tstart;
5067 * Move rest of data.
5069 taddr = ch->ch_taddr + head;
5071 memcpy_toio(taddr, buf, n);
5074 writew(head, &(bs->tx_head));
5078 * Retrives the current custom baud rate from FEP memory,
5079 * and returns it back to the user.
5080 * Returns 0 on error.
5082 static uint dgap_get_custom_baud(struct channel_t *ch)
5088 if (!ch || ch->magic != DGAP_CHANNEL_MAGIC)
5091 if (!ch->ch_bd || ch->ch_bd->magic != DGAP_BOARD_MAGIC)
5094 if (!(ch->ch_bd->bd_flags & BD_FEP5PLUS))
5097 vaddr = ch->ch_bd->re_map_membase;
5103 * Go get from fep mem, what the fep
5104 * believes the custom baud rate is.
5106 offset = ((((*(unsigned short *)(vaddr + ECS_SEG)) << 4) +
5107 (ch->ch_portnum * 0x28) + LINE_SPEED));
5109 value = readw(vaddr + offset);
5114 * Calls the firmware to reset this channel.
5116 static void dgap_firmware_reset_port(struct channel_t *ch)
5118 dgap_cmdb(ch, CHRESET, 0, 0, 0);
5121 * Now that the channel is reset, we need to make sure
5122 * all the current settings get reapplied to the port
5125 * So we will set the driver's cache of firmware
5126 * settings all to 0, and then call param.
5128 ch->ch_fepiflag = 0;
5129 ch->ch_fepcflag = 0;
5130 ch->ch_fepoflag = 0;
5131 ch->ch_fepstartc = 0;
5132 ch->ch_fepstopc = 0;
5133 ch->ch_fepastartc = 0;
5134 ch->ch_fepastopc = 0;
5139 /*=======================================================================
5141 * dgap_param - Set Digi parameters.
5143 * struct tty_struct * - TTY for port.
5145 *=======================================================================*/
5146 static int dgap_param(struct tty_struct *tty)
5148 struct ktermios *ts;
5150 struct channel_t *ch;
5159 if (!tty || tty->magic != TTY_MAGIC)
5162 un = (struct un_t *) tty->driver_data;
5163 if (!un || un->magic != DGAP_UNIT_MAGIC)
5167 if (!ch || ch->magic != DGAP_CHANNEL_MAGIC)
5171 if (!bd || bd->magic != DGAP_BOARD_MAGIC)
5181 * If baud rate is zero, flush queues, and set mval to drop DTR.
5183 if ((ch->ch_c_cflag & (CBAUD)) == 0) {
5186 head = readw(&(ch->ch_bs->rx_head));
5187 writew(head, &(ch->ch_bs->rx_tail));
5190 head = readw(&(ch->ch_bs->tx_head));
5191 writew(head, &(ch->ch_bs->tx_tail));
5193 ch->ch_flags |= (CH_BAUD0);
5195 /* Drop RTS and DTR */
5196 ch->ch_mval &= ~(D_RTS(ch)|D_DTR(ch));
5197 mval = D_DTR(ch) | D_RTS(ch);
5198 ch->ch_baud_info = 0;
5200 } else if (ch->ch_custom_speed && (bd->bd_flags & BD_FEP5PLUS)) {
5202 * Tell the fep to do the command
5205 dgap_cmdw_ext(ch, 0xff01, ch->ch_custom_speed, 0);
5208 * Now go get from fep mem, what the fep
5209 * believes the custom baud rate is.
5211 ch->ch_custom_speed = dgap_get_custom_baud(ch);
5212 ch->ch_baud_info = ch->ch_custom_speed;
5214 /* Handle transition from B0 */
5215 if (ch->ch_flags & CH_BAUD0) {
5216 ch->ch_flags &= ~(CH_BAUD0);
5217 ch->ch_mval |= (D_RTS(ch)|D_DTR(ch));
5219 mval = D_DTR(ch) | D_RTS(ch);
5223 * Set baud rate, character size, and parity.
5231 ulong bauds[4][16] = {
5235 600, 1200, 1800, 2400,
5236 4800, 9600, 19200, 38400 },
5237 { /* slowbaud & CBAUDEX */
5238 0, 57600, 115200, 230400,
5239 460800, 150, 200, 921600,
5240 600, 1200, 1800, 2400,
5241 4800, 9600, 19200, 38400 },
5243 0, 57600, 76800, 115200,
5244 14400, 57600, 230400, 76800,
5245 115200, 230400, 28800, 460800,
5246 921600, 9600, 19200, 38400 },
5247 { /* fastbaud & CBAUDEX */
5248 0, 57600, 115200, 230400,
5249 460800, 150, 200, 921600,
5250 600, 1200, 1800, 2400,
5251 4800, 9600, 19200, 38400 }
5255 * Only use the TXPrint baud rate if the
5256 * terminal unit is NOT open
5258 if (!(ch->ch_tun.un_flags & UN_ISOPEN) &&
5259 (un->un_type == DGAP_PRINT))
5260 baud = C_BAUD(ch->ch_pun.un_tty) & 0xff;
5262 baud = C_BAUD(ch->ch_tun.un_tty) & 0xff;
5264 if (ch->ch_c_cflag & CBAUDEX)
5267 if (ch->ch_digi.digi_flags & DIGI_FAST)
5272 if ((iindex >= 0) && (iindex < 4) &&
5273 (jindex >= 0) && (jindex < 16))
5274 baud = bauds[iindex][jindex];
5281 ch->ch_baud_info = baud;
5284 * CBAUD has bit position 0x1000 set these days to
5285 * indicate Linux baud rate remap.
5286 * We use a different bit assignment for high speed.
5287 * Clear this bit out while grabbing the parts of
5290 cflag = ch->ch_c_cflag & ((CBAUD ^ CBAUDEX) | PARODD | PARENB |
5294 * HUPCL bit is used by FEP to indicate fast baud
5295 * table is to be used.
5297 if ((ch->ch_digi.digi_flags & DIGI_FAST) ||
5298 (ch->ch_c_cflag & CBAUDEX))
5301 if ((ch->ch_c_cflag & CBAUDEX) &&
5302 !(ch->ch_digi.digi_flags & DIGI_FAST)) {
5304 * The below code is trying to guarantee that only
5305 * baud rates 115200, 230400, 460800, 921600 are
5306 * remapped. We use exclusive or because the various
5307 * baud rates share common bit positions and therefore
5308 * can't be tested for easily.
5310 tcflag_t tcflag = (ch->ch_c_cflag & CBAUD) | CBAUDEX;
5314 * Map high speed requests to index
5315 * into FEP's baud table
5345 cflag = (cflag & ~(CBAUD | CBAUDEX)) | baudpart;
5350 if (cflag != ch->ch_fepcflag) {
5351 ch->ch_fepcflag = (u16) (cflag & 0xffff);
5354 * Okay to have channel and board
5355 * locks held calling this
5357 dgap_cmdw(ch, SCFLAG, (u16) cflag, 0);
5360 /* Handle transition from B0 */
5361 if (ch->ch_flags & CH_BAUD0) {
5362 ch->ch_flags &= ~(CH_BAUD0);
5363 ch->ch_mval |= (D_RTS(ch)|D_DTR(ch));
5365 mval = D_DTR(ch) | D_RTS(ch);
5371 iflag = ch->ch_c_iflag & (IGNBRK | BRKINT | IGNPAR | PARMRK |
5372 INPCK | ISTRIP | IXON | IXANY | IXOFF);
5374 if ((ch->ch_startc == _POSIX_VDISABLE) ||
5375 (ch->ch_stopc == _POSIX_VDISABLE)) {
5376 iflag &= ~(IXON | IXOFF);
5377 ch->ch_c_iflag &= ~(IXON | IXOFF);
5381 * Only the IBM Xr card can switch between
5382 * 232 and 422 modes on the fly
5384 if (bd->device == PCI_DEV_XR_IBM_DID) {
5385 if (ch->ch_digi.digi_flags & DIGI_422)
5386 dgap_cmdb(ch, SCOMMODE, MODE_422, 0, 0);
5388 dgap_cmdb(ch, SCOMMODE, MODE_232, 0, 0);
5391 if (ch->ch_digi.digi_flags & DIGI_ALTPIN)
5394 if (iflag != ch->ch_fepiflag) {
5395 ch->ch_fepiflag = iflag;
5397 /* Okay to have channel and board locks held calling this */
5398 dgap_cmdw(ch, SIFLAG, (u16) ch->ch_fepiflag, 0);
5402 * Select hardware handshaking.
5406 if (ch->ch_c_cflag & CRTSCTS)
5407 hflow |= (D_RTS(ch) | D_CTS(ch));
5408 if (ch->ch_digi.digi_flags & RTSPACE)
5410 if (ch->ch_digi.digi_flags & DTRPACE)
5412 if (ch->ch_digi.digi_flags & CTSPACE)
5414 if (ch->ch_digi.digi_flags & DSRPACE)
5416 if (ch->ch_digi.digi_flags & DCDPACE)
5419 if (hflow != ch->ch_hflow) {
5420 ch->ch_hflow = hflow;
5422 /* Okay to have channel and board locks held calling this */
5423 dgap_cmdb(ch, SHFLOW, (uchar) hflow, 0xff, 0);
5428 * Set RTS and/or DTR Toggle if needed,
5429 * but only if product is FEP5+ based.
5431 if (bd->bd_flags & BD_FEP5PLUS) {
5433 if (ch->ch_digi.digi_flags & DIGI_RTS_TOGGLE)
5434 hflow2 |= (D_RTS(ch));
5435 if (ch->ch_digi.digi_flags & DIGI_DTR_TOGGLE)
5436 hflow2 |= (D_DTR(ch));
5438 dgap_cmdw_ext(ch, 0xff03, hflow2, 0);
5442 * Set modem control lines.
5445 mval ^= ch->ch_mforce & (mval ^ ch->ch_mval);
5447 if (ch->ch_mostat ^ mval) {
5448 ch->ch_mostat = mval;
5450 /* Okay to have channel and board locks held calling this */
5451 dgap_cmdb(ch, SMODEM, (uchar) mval, D_RTS(ch)|D_DTR(ch), 0);
5455 * Read modem signals, and then call carrier function.
5457 ch->ch_mistat = readb(&(bs->m_stat));
5461 * Set the start and stop characters.
5463 if (ch->ch_startc != ch->ch_fepstartc ||
5464 ch->ch_stopc != ch->ch_fepstopc) {
5465 ch->ch_fepstartc = ch->ch_startc;
5466 ch->ch_fepstopc = ch->ch_stopc;
5468 /* Okay to have channel and board locks held calling this */
5469 dgap_cmdb(ch, SFLOWC, ch->ch_fepstartc, ch->ch_fepstopc, 0);
5473 * Set the Auxiliary start and stop characters.
5475 if (ch->ch_astartc != ch->ch_fepastartc ||
5476 ch->ch_astopc != ch->ch_fepastopc) {
5477 ch->ch_fepastartc = ch->ch_astartc;
5478 ch->ch_fepastopc = ch->ch_astopc;
5480 /* Okay to have channel and board locks held calling this */
5481 dgap_cmdb(ch, SAFLOWC, ch->ch_fepastartc, ch->ch_fepastopc, 0);
5488 * dgap_parity_scan()
5490 * Convert the FEP5 way of reporting parity errors and breaks into
5491 * the Linux line discipline way.
5493 static void dgap_parity_scan(struct channel_t *ch, unsigned char *cbuf,
5494 unsigned char *fbuf, int *len)
5498 unsigned char *in, *cout, *fout;
5505 if (!ch || ch->magic != DGAP_CHANNEL_MAGIC)
5510 switch (ch->pscan_state) {
5512 /* reset to sanity and fall through */
5513 ch->pscan_state = 0;
5516 /* No FF seen yet */
5517 if (c == (unsigned char) '\377')
5518 /* delete this character from stream */
5519 ch->pscan_state = 1;
5522 *fout++ = TTY_NORMAL;
5529 if (c == (unsigned char) '\377') {
5530 /* doubled ff, transform to single ff */
5532 *fout++ = TTY_NORMAL;
5534 ch->pscan_state = 0;
5536 /* save value examination in next state */
5537 ch->pscan_savechar = c;
5538 ch->pscan_state = 2;
5543 /* third character of ff sequence */
5547 if (ch->pscan_savechar == 0x0) {
5551 *fout++ = TTY_BREAK;
5553 ch->ch_err_parity++;
5554 *fout++ = TTY_PARITY;
5559 ch->pscan_state = 0;
5565 static void dgap_write_wakeup(struct board_t *bd, struct channel_t *ch,
5566 struct un_t *un, u32 mask,
5567 unsigned long *irq_flags1,
5568 unsigned long *irq_flags2)
5570 if (!(un->un_flags & mask))
5573 un->un_flags &= ~mask;
5575 if (!(un->un_flags & UN_ISOPEN))
5578 if ((un->un_tty->flags & (1 << TTY_DO_WRITE_WAKEUP)) &&
5579 un->un_tty->ldisc->ops->write_wakeup) {
5580 spin_unlock_irqrestore(&ch->ch_lock, *irq_flags2);
5581 spin_unlock_irqrestore(&bd->bd_lock, *irq_flags1);
5583 (un->un_tty->ldisc->ops->write_wakeup)(un->un_tty);
5585 spin_lock_irqsave(&bd->bd_lock, *irq_flags1);
5586 spin_lock_irqsave(&ch->ch_lock, *irq_flags2);
5588 wake_up_interruptible(&un->un_tty->write_wait);
5589 wake_up_interruptible(&un->un_flags_wait);
5592 /*=======================================================================
5594 * dgap_event - FEP to host event processing routine.
5596 * bd - Board of current event.
5598 *=======================================================================*/
5599 static int dgap_event(struct board_t *bd)
5601 struct channel_t *ch;
5606 uchar *vaddr = NULL;
5607 struct ev_t *eaddr = NULL;
5615 if (!bd || bd->magic != DGAP_BOARD_MAGIC)
5618 spin_lock_irqsave(&bd->bd_lock, lock_flags);
5620 vaddr = bd->re_map_membase;
5623 spin_unlock_irqrestore(&bd->bd_lock, lock_flags);
5627 eaddr = (struct ev_t *) (vaddr + EVBUF);
5629 /* Get our head and tail */
5630 head = readw(&(eaddr->ev_head));
5631 tail = readw(&(eaddr->ev_tail));
5634 * Forget it if pointers out of range.
5637 if (head >= EVMAX - EVSTART || tail >= EVMAX - EVSTART ||
5638 (head | tail) & 03) {
5639 /* Let go of board lock */
5640 spin_unlock_irqrestore(&bd->bd_lock, lock_flags);
5645 * Loop to process all the events in the buffer.
5647 while (tail != head) {
5650 * Get interrupt information.
5653 event = bd->re_map_membase + tail + EVSTART;
5661 * Make sure the interrupt is valid.
5663 if (port >= bd->nasync)
5666 if (!(reason & (IFMODEM | IFBREAK | IFTLW | IFTEM | IFDATA)))
5669 ch = bd->channels[port];
5671 if (!ch || ch->magic != DGAP_CHANNEL_MAGIC)
5675 * If we have made it here, the event was valid.
5676 * Lock down the channel.
5678 spin_lock_irqsave(&ch->ch_lock, lock_flags2);
5683 spin_unlock_irqrestore(&ch->ch_lock, lock_flags2);
5688 * Process received data.
5690 if (reason & IFDATA) {
5693 * ALL LOCKS *MUST* BE DROPPED BEFORE CALLING INPUT!
5694 * input could send some data to ld, which in turn
5695 * could do a callback to one of our other functions.
5697 spin_unlock_irqrestore(&ch->ch_lock, lock_flags2);
5698 spin_unlock_irqrestore(&bd->bd_lock, lock_flags);
5702 spin_lock_irqsave(&bd->bd_lock, lock_flags);
5703 spin_lock_irqsave(&ch->ch_lock, lock_flags2);
5705 if (ch->ch_flags & CH_RACTIVE)
5706 ch->ch_flags |= CH_RENABLE;
5708 writeb(1, &(bs->idata));
5710 if (ch->ch_flags & CH_RWAIT) {
5711 ch->ch_flags &= ~CH_RWAIT;
5713 wake_up_interruptible
5714 (&ch->ch_tun.un_flags_wait);
5719 * Process Modem change signals.
5721 if (reason & IFMODEM) {
5722 ch->ch_mistat = modem;
5729 if (reason & IFBREAK) {
5731 if (ch->ch_tun.un_tty) {
5732 /* A break has been indicated */
5734 tty_buffer_request_room
5735 (ch->ch_tun.un_tty->port, 1);
5736 tty_insert_flip_char(ch->ch_tun.un_tty->port,
5738 tty_flip_buffer_push(ch->ch_tun.un_tty->port);
5743 * Process Transmit low.
5745 if (reason & IFTLW) {
5746 dgap_write_wakeup(bd, ch, &ch->ch_tun, UN_LOW,
5747 &lock_flags, &lock_flags2);
5748 dgap_write_wakeup(bd, ch, &ch->ch_pun, UN_LOW,
5749 &lock_flags, &lock_flags2);
5750 if (ch->ch_flags & CH_WLOW) {
5751 ch->ch_flags &= ~CH_WLOW;
5752 wake_up_interruptible(&ch->ch_flags_wait);
5757 * Process Transmit empty.
5759 if (reason & IFTEM) {
5760 dgap_write_wakeup(bd, ch, &ch->ch_tun, UN_EMPTY,
5761 &lock_flags, &lock_flags2);
5762 dgap_write_wakeup(bd, ch, &ch->ch_pun, UN_EMPTY,
5763 &lock_flags, &lock_flags2);
5764 if (ch->ch_flags & CH_WEMPTY) {
5765 ch->ch_flags &= ~CH_WEMPTY;
5766 wake_up_interruptible(&ch->ch_flags_wait);
5770 spin_unlock_irqrestore(&ch->ch_lock, lock_flags2);
5773 tail = (tail + 4) & (EVMAX - EVSTART - 4);
5776 writew(tail, &(eaddr->ev_tail));
5777 spin_unlock_irqrestore(&bd->bd_lock, lock_flags);
5782 static ssize_t dgap_driver_version_show(struct device_driver *ddp, char *buf)
5784 return snprintf(buf, PAGE_SIZE, "%s\n", DG_PART);
5786 static DRIVER_ATTR(version, S_IRUSR, dgap_driver_version_show, NULL);
5789 static ssize_t dgap_driver_boards_show(struct device_driver *ddp, char *buf)
5791 return snprintf(buf, PAGE_SIZE, "%d\n", dgap_NumBoards);
5793 static DRIVER_ATTR(boards, S_IRUSR, dgap_driver_boards_show, NULL);
5796 static ssize_t dgap_driver_maxboards_show(struct device_driver *ddp, char *buf)
5798 return snprintf(buf, PAGE_SIZE, "%d\n", MAXBOARDS);
5800 static DRIVER_ATTR(maxboards, S_IRUSR, dgap_driver_maxboards_show, NULL);
5803 static ssize_t dgap_driver_pollcounter_show(struct device_driver *ddp,
5806 return snprintf(buf, PAGE_SIZE, "%ld\n", dgap_poll_counter);
5808 static DRIVER_ATTR(pollcounter, S_IRUSR, dgap_driver_pollcounter_show, NULL);
5810 static ssize_t dgap_driver_pollrate_show(struct device_driver *ddp, char *buf)
5812 return snprintf(buf, PAGE_SIZE, "%dms\n", dgap_poll_tick);
5815 static ssize_t dgap_driver_pollrate_store(struct device_driver *ddp,
5816 const char *buf, size_t count)
5818 if (sscanf(buf, "%d\n", &dgap_poll_tick) != 1)
5822 static DRIVER_ATTR(pollrate, (S_IRUSR | S_IWUSR), dgap_driver_pollrate_show,
5823 dgap_driver_pollrate_store);
5825 static int dgap_create_driver_sysfiles(struct pci_driver *dgap_driver)
5828 struct device_driver *driverfs = &dgap_driver->driver;
5830 rc |= driver_create_file(driverfs, &driver_attr_version);
5831 rc |= driver_create_file(driverfs, &driver_attr_boards);
5832 rc |= driver_create_file(driverfs, &driver_attr_maxboards);
5833 rc |= driver_create_file(driverfs, &driver_attr_pollrate);
5834 rc |= driver_create_file(driverfs, &driver_attr_pollcounter);
5839 static void dgap_remove_driver_sysfiles(struct pci_driver *dgap_driver)
5841 struct device_driver *driverfs = &dgap_driver->driver;
5842 driver_remove_file(driverfs, &driver_attr_version);
5843 driver_remove_file(driverfs, &driver_attr_boards);
5844 driver_remove_file(driverfs, &driver_attr_maxboards);
5845 driver_remove_file(driverfs, &driver_attr_pollrate);
5846 driver_remove_file(driverfs, &driver_attr_pollcounter);
5849 static struct board_t *dgap_verify_board(struct device *p)
5856 bd = dev_get_drvdata(p);
5857 if (!bd || bd->magic != DGAP_BOARD_MAGIC || bd->state != BOARD_READY)
5863 static ssize_t dgap_ports_state_show(struct device *p,
5864 struct device_attribute *attr,
5871 bd = dgap_verify_board(p);
5875 for (i = 0; i < bd->nasync; i++) {
5876 count += snprintf(buf + count, PAGE_SIZE - count,
5877 "%d %s\n", bd->channels[i]->ch_portnum,
5878 bd->channels[i]->ch_open_count ? "Open" : "Closed");
5882 static DEVICE_ATTR(ports_state, S_IRUSR, dgap_ports_state_show, NULL);
5884 static ssize_t dgap_ports_baud_show(struct device *p,
5885 struct device_attribute *attr,
5892 bd = dgap_verify_board(p);
5896 for (i = 0; i < bd->nasync; i++) {
5897 count += snprintf(buf + count, PAGE_SIZE - count, "%d %d\n",
5898 bd->channels[i]->ch_portnum,
5899 bd->channels[i]->ch_baud_info);
5903 static DEVICE_ATTR(ports_baud, S_IRUSR, dgap_ports_baud_show, NULL);
5905 static ssize_t dgap_ports_msignals_show(struct device *p,
5906 struct device_attribute *attr,
5913 bd = dgap_verify_board(p);
5917 for (i = 0; i < bd->nasync; i++) {
5918 if (bd->channels[i]->ch_open_count)
5919 count += snprintf(buf + count, PAGE_SIZE - count,
5920 "%d %s %s %s %s %s %s\n",
5921 bd->channels[i]->ch_portnum,
5922 (bd->channels[i]->ch_mostat &
5923 UART_MCR_RTS) ? "RTS" : "",
5924 (bd->channels[i]->ch_mistat &
5925 UART_MSR_CTS) ? "CTS" : "",
5926 (bd->channels[i]->ch_mostat &
5927 UART_MCR_DTR) ? "DTR" : "",
5928 (bd->channels[i]->ch_mistat &
5929 UART_MSR_DSR) ? "DSR" : "",
5930 (bd->channels[i]->ch_mistat &
5931 UART_MSR_DCD) ? "DCD" : "",
5932 (bd->channels[i]->ch_mistat &
5933 UART_MSR_RI) ? "RI" : "");
5935 count += snprintf(buf + count, PAGE_SIZE - count,
5936 "%d\n", bd->channels[i]->ch_portnum);
5940 static DEVICE_ATTR(ports_msignals, S_IRUSR, dgap_ports_msignals_show, NULL);
5942 static ssize_t dgap_ports_iflag_show(struct device *p,
5943 struct device_attribute *attr,
5950 bd = dgap_verify_board(p);
5954 for (i = 0; i < bd->nasync; i++)
5955 count += snprintf(buf + count, PAGE_SIZE - count, "%d %x\n",
5956 bd->channels[i]->ch_portnum,
5957 bd->channels[i]->ch_c_iflag);
5960 static DEVICE_ATTR(ports_iflag, S_IRUSR, dgap_ports_iflag_show, NULL);
5962 static ssize_t dgap_ports_cflag_show(struct device *p,
5963 struct device_attribute *attr,
5970 bd = dgap_verify_board(p);
5974 for (i = 0; i < bd->nasync; i++)
5975 count += snprintf(buf + count, PAGE_SIZE - count, "%d %x\n",
5976 bd->channels[i]->ch_portnum,
5977 bd->channels[i]->ch_c_cflag);
5980 static DEVICE_ATTR(ports_cflag, S_IRUSR, dgap_ports_cflag_show, NULL);
5982 static ssize_t dgap_ports_oflag_show(struct device *p,
5983 struct device_attribute *attr,
5990 bd = dgap_verify_board(p);
5994 for (i = 0; i < bd->nasync; i++)
5995 count += snprintf(buf + count, PAGE_SIZE - count, "%d %x\n",
5996 bd->channels[i]->ch_portnum,
5997 bd->channels[i]->ch_c_oflag);
6000 static DEVICE_ATTR(ports_oflag, S_IRUSR, dgap_ports_oflag_show, NULL);
6002 static ssize_t dgap_ports_lflag_show(struct device *p,
6003 struct device_attribute *attr,
6010 bd = dgap_verify_board(p);
6014 for (i = 0; i < bd->nasync; i++)
6015 count += snprintf(buf + count, PAGE_SIZE - count, "%d %x\n",
6016 bd->channels[i]->ch_portnum,
6017 bd->channels[i]->ch_c_lflag);
6020 static DEVICE_ATTR(ports_lflag, S_IRUSR, dgap_ports_lflag_show, NULL);
6022 static ssize_t dgap_ports_digi_flag_show(struct device *p,
6023 struct device_attribute *attr,
6030 bd = dgap_verify_board(p);
6034 for (i = 0; i < bd->nasync; i++)
6035 count += snprintf(buf + count, PAGE_SIZE - count, "%d %x\n",
6036 bd->channels[i]->ch_portnum,
6037 bd->channels[i]->ch_digi.digi_flags);
6040 static DEVICE_ATTR(ports_digi_flag, S_IRUSR, dgap_ports_digi_flag_show, NULL);
6042 static ssize_t dgap_ports_rxcount_show(struct device *p,
6043 struct device_attribute *attr,
6050 bd = dgap_verify_board(p);
6054 for (i = 0; i < bd->nasync; i++)
6055 count += snprintf(buf + count, PAGE_SIZE - count, "%d %ld\n",
6056 bd->channels[i]->ch_portnum,
6057 bd->channels[i]->ch_rxcount);
6060 static DEVICE_ATTR(ports_rxcount, S_IRUSR, dgap_ports_rxcount_show, NULL);
6062 static ssize_t dgap_ports_txcount_show(struct device *p,
6063 struct device_attribute *attr,
6070 bd = dgap_verify_board(p);
6074 for (i = 0; i < bd->nasync; i++)
6075 count += snprintf(buf + count, PAGE_SIZE - count, "%d %ld\n",
6076 bd->channels[i]->ch_portnum,
6077 bd->channels[i]->ch_txcount);
6080 static DEVICE_ATTR(ports_txcount, S_IRUSR, dgap_ports_txcount_show, NULL);
6082 /* this function creates the sys files that will export each signal status
6083 * to sysfs each value will be put in a separate filename
6085 static void dgap_create_ports_sysfiles(struct board_t *bd)
6087 dev_set_drvdata(&bd->pdev->dev, bd);
6088 device_create_file(&(bd->pdev->dev), &dev_attr_ports_state);
6089 device_create_file(&(bd->pdev->dev), &dev_attr_ports_baud);
6090 device_create_file(&(bd->pdev->dev), &dev_attr_ports_msignals);
6091 device_create_file(&(bd->pdev->dev), &dev_attr_ports_iflag);
6092 device_create_file(&(bd->pdev->dev), &dev_attr_ports_cflag);
6093 device_create_file(&(bd->pdev->dev), &dev_attr_ports_oflag);
6094 device_create_file(&(bd->pdev->dev), &dev_attr_ports_lflag);
6095 device_create_file(&(bd->pdev->dev), &dev_attr_ports_digi_flag);
6096 device_create_file(&(bd->pdev->dev), &dev_attr_ports_rxcount);
6097 device_create_file(&(bd->pdev->dev), &dev_attr_ports_txcount);
6100 /* removes all the sys files created for that port */
6101 static void dgap_remove_ports_sysfiles(struct board_t *bd)
6103 device_remove_file(&(bd->pdev->dev), &dev_attr_ports_state);
6104 device_remove_file(&(bd->pdev->dev), &dev_attr_ports_baud);
6105 device_remove_file(&(bd->pdev->dev), &dev_attr_ports_msignals);
6106 device_remove_file(&(bd->pdev->dev), &dev_attr_ports_iflag);
6107 device_remove_file(&(bd->pdev->dev), &dev_attr_ports_cflag);
6108 device_remove_file(&(bd->pdev->dev), &dev_attr_ports_oflag);
6109 device_remove_file(&(bd->pdev->dev), &dev_attr_ports_lflag);
6110 device_remove_file(&(bd->pdev->dev), &dev_attr_ports_digi_flag);
6111 device_remove_file(&(bd->pdev->dev), &dev_attr_ports_rxcount);
6112 device_remove_file(&(bd->pdev->dev), &dev_attr_ports_txcount);
6115 static ssize_t dgap_tty_state_show(struct device *d,
6116 struct device_attribute *attr,
6120 struct channel_t *ch;
6125 un = dev_get_drvdata(d);
6126 if (!un || un->magic != DGAP_UNIT_MAGIC)
6129 if (!ch || ch->magic != DGAP_CHANNEL_MAGIC)
6132 if (!bd || bd->magic != DGAP_BOARD_MAGIC)
6134 if (bd->state != BOARD_READY)
6137 return snprintf(buf, PAGE_SIZE, "%s", un->un_open_count ?
6140 static DEVICE_ATTR(state, S_IRUSR, dgap_tty_state_show, NULL);
6142 static ssize_t dgap_tty_baud_show(struct device *d,
6143 struct device_attribute *attr,
6147 struct channel_t *ch;
6152 un = dev_get_drvdata(d);
6153 if (!un || un->magic != DGAP_UNIT_MAGIC)
6156 if (!ch || ch->magic != DGAP_CHANNEL_MAGIC)
6159 if (!bd || bd->magic != DGAP_BOARD_MAGIC)
6161 if (bd->state != BOARD_READY)
6164 return snprintf(buf, PAGE_SIZE, "%d\n", ch->ch_baud_info);
6166 static DEVICE_ATTR(baud, S_IRUSR, dgap_tty_baud_show, NULL);
6168 static ssize_t dgap_tty_msignals_show(struct device *d,
6169 struct device_attribute *attr,
6173 struct channel_t *ch;
6178 un = dev_get_drvdata(d);
6179 if (!un || un->magic != DGAP_UNIT_MAGIC)
6182 if (!ch || ch->magic != DGAP_CHANNEL_MAGIC)
6185 if (!bd || bd->magic != DGAP_BOARD_MAGIC)
6187 if (bd->state != BOARD_READY)
6190 if (ch->ch_open_count) {
6191 return snprintf(buf, PAGE_SIZE, "%s %s %s %s %s %s\n",
6192 (ch->ch_mostat & UART_MCR_RTS) ? "RTS" : "",
6193 (ch->ch_mistat & UART_MSR_CTS) ? "CTS" : "",
6194 (ch->ch_mostat & UART_MCR_DTR) ? "DTR" : "",
6195 (ch->ch_mistat & UART_MSR_DSR) ? "DSR" : "",
6196 (ch->ch_mistat & UART_MSR_DCD) ? "DCD" : "",
6197 (ch->ch_mistat & UART_MSR_RI) ? "RI" : "");
6201 static DEVICE_ATTR(msignals, S_IRUSR, dgap_tty_msignals_show, NULL);
6203 static ssize_t dgap_tty_iflag_show(struct device *d,
6204 struct device_attribute *attr,
6208 struct channel_t *ch;
6213 un = dev_get_drvdata(d);
6214 if (!un || un->magic != DGAP_UNIT_MAGIC)
6217 if (!ch || ch->magic != DGAP_CHANNEL_MAGIC)
6220 if (!bd || bd->magic != DGAP_BOARD_MAGIC)
6222 if (bd->state != BOARD_READY)
6225 return snprintf(buf, PAGE_SIZE, "%x\n", ch->ch_c_iflag);
6227 static DEVICE_ATTR(iflag, S_IRUSR, dgap_tty_iflag_show, NULL);
6229 static ssize_t dgap_tty_cflag_show(struct device *d,
6230 struct device_attribute *attr,
6234 struct channel_t *ch;
6239 un = dev_get_drvdata(d);
6240 if (!un || un->magic != DGAP_UNIT_MAGIC)
6243 if (!ch || ch->magic != DGAP_CHANNEL_MAGIC)
6246 if (!bd || bd->magic != DGAP_BOARD_MAGIC)
6248 if (bd->state != BOARD_READY)
6251 return snprintf(buf, PAGE_SIZE, "%x\n", ch->ch_c_cflag);
6253 static DEVICE_ATTR(cflag, S_IRUSR, dgap_tty_cflag_show, NULL);
6255 static ssize_t dgap_tty_oflag_show(struct device *d,
6256 struct device_attribute *attr,
6260 struct channel_t *ch;
6265 un = dev_get_drvdata(d);
6266 if (!un || un->magic != DGAP_UNIT_MAGIC)
6269 if (!ch || ch->magic != DGAP_CHANNEL_MAGIC)
6272 if (!bd || bd->magic != DGAP_BOARD_MAGIC)
6274 if (bd->state != BOARD_READY)
6277 return snprintf(buf, PAGE_SIZE, "%x\n", ch->ch_c_oflag);
6279 static DEVICE_ATTR(oflag, S_IRUSR, dgap_tty_oflag_show, NULL);
6281 static ssize_t dgap_tty_lflag_show(struct device *d,
6282 struct device_attribute *attr,
6286 struct channel_t *ch;
6291 un = dev_get_drvdata(d);
6292 if (!un || un->magic != DGAP_UNIT_MAGIC)
6295 if (!ch || ch->magic != DGAP_CHANNEL_MAGIC)
6298 if (!bd || bd->magic != DGAP_BOARD_MAGIC)
6300 if (bd->state != BOARD_READY)
6303 return snprintf(buf, PAGE_SIZE, "%x\n", ch->ch_c_lflag);
6305 static DEVICE_ATTR(lflag, S_IRUSR, dgap_tty_lflag_show, NULL);
6307 static ssize_t dgap_tty_digi_flag_show(struct device *d,
6308 struct device_attribute *attr,
6312 struct channel_t *ch;
6317 un = dev_get_drvdata(d);
6318 if (!un || un->magic != DGAP_UNIT_MAGIC)
6321 if (!ch || ch->magic != DGAP_CHANNEL_MAGIC)
6324 if (!bd || bd->magic != DGAP_BOARD_MAGIC)
6326 if (bd->state != BOARD_READY)
6329 return snprintf(buf, PAGE_SIZE, "%x\n", ch->ch_digi.digi_flags);
6331 static DEVICE_ATTR(digi_flag, S_IRUSR, dgap_tty_digi_flag_show, NULL);
6333 static ssize_t dgap_tty_rxcount_show(struct device *d,
6334 struct device_attribute *attr,
6338 struct channel_t *ch;
6343 un = dev_get_drvdata(d);
6344 if (!un || un->magic != DGAP_UNIT_MAGIC)
6347 if (!ch || ch->magic != DGAP_CHANNEL_MAGIC)
6350 if (!bd || bd->magic != DGAP_BOARD_MAGIC)
6352 if (bd->state != BOARD_READY)
6355 return snprintf(buf, PAGE_SIZE, "%ld\n", ch->ch_rxcount);
6357 static DEVICE_ATTR(rxcount, S_IRUSR, dgap_tty_rxcount_show, NULL);
6359 static ssize_t dgap_tty_txcount_show(struct device *d,
6360 struct device_attribute *attr,
6364 struct channel_t *ch;
6369 un = dev_get_drvdata(d);
6370 if (!un || un->magic != DGAP_UNIT_MAGIC)
6373 if (!ch || ch->magic != DGAP_CHANNEL_MAGIC)
6376 if (!bd || bd->magic != DGAP_BOARD_MAGIC)
6378 if (bd->state != BOARD_READY)
6381 return snprintf(buf, PAGE_SIZE, "%ld\n", ch->ch_txcount);
6383 static DEVICE_ATTR(txcount, S_IRUSR, dgap_tty_txcount_show, NULL);
6385 static ssize_t dgap_tty_name_show(struct device *d,
6386 struct device_attribute *attr,
6390 struct channel_t *ch;
6394 struct cnode *cptr = NULL;
6402 un = dev_get_drvdata(d);
6403 if (!un || un->magic != DGAP_UNIT_MAGIC)
6406 if (!ch || ch->magic != DGAP_CHANNEL_MAGIC)
6409 if (!bd || bd->magic != DGAP_BOARD_MAGIC)
6411 if (bd->state != BOARD_READY)
6415 cn = ch->ch_portnum;
6417 for (cptr = bd->bd_config; cptr; cptr = cptr->next) {
6419 if ((cptr->type == BNODE) &&
6420 ((cptr->u.board.type == APORT2_920P) ||
6421 (cptr->u.board.type == APORT4_920P) ||
6422 (cptr->u.board.type == APORT8_920P) ||
6423 (cptr->u.board.type == PAPORT4) ||
6424 (cptr->u.board.type == PAPORT8))) {
6427 if (cptr->u.board.v_start)
6428 starto = cptr->u.board.start;
6433 if (cptr->type == TNODE && found == TRUE) {
6435 if (strstr(cptr->u.ttyname, "tty")) {
6436 ptr1 = cptr->u.ttyname;
6439 ptr1 = cptr->u.ttyname;
6441 for (i = 0; i < dgap_config_get_num_prts(bd); i++) {
6445 return snprintf(buf, PAGE_SIZE, "%s%s%02d\n",
6446 (un->un_type == DGAP_PRINT) ?
6452 if (cptr->type == CNODE) {
6454 for (i = 0; i < cptr->u.conc.nport; i++) {
6455 if (cn != (i + ncount))
6458 return snprintf(buf, PAGE_SIZE, "%s%s%02ld\n",
6459 (un->un_type == DGAP_PRINT) ?
6462 i + (cptr->u.conc.v_start ?
6463 cptr->u.conc.start : 1));
6466 ncount += cptr->u.conc.nport;
6469 if (cptr->type == MNODE) {
6471 for (i = 0; i < cptr->u.module.nport; i++) {
6472 if (cn != (i + ncount))
6475 return snprintf(buf, PAGE_SIZE, "%s%s%02ld\n",
6476 (un->un_type == DGAP_PRINT) ?
6479 i + (cptr->u.module.v_start ?
6480 cptr->u.module.start : 1));
6483 ncount += cptr->u.module.nport;
6488 return snprintf(buf, PAGE_SIZE, "%s_dgap_%d_%d\n",
6489 (un->un_type == DGAP_PRINT) ? "pr" : "tty", bn, cn);
6492 static DEVICE_ATTR(custom_name, S_IRUSR, dgap_tty_name_show, NULL);
6494 static struct attribute *dgap_sysfs_tty_entries[] = {
6495 &dev_attr_state.attr,
6496 &dev_attr_baud.attr,
6497 &dev_attr_msignals.attr,
6498 &dev_attr_iflag.attr,
6499 &dev_attr_cflag.attr,
6500 &dev_attr_oflag.attr,
6501 &dev_attr_lflag.attr,
6502 &dev_attr_digi_flag.attr,
6503 &dev_attr_rxcount.attr,
6504 &dev_attr_txcount.attr,
6505 &dev_attr_custom_name.attr,
6509 static struct attribute_group dgap_tty_attribute_group = {
6511 .attrs = dgap_sysfs_tty_entries,
6514 static void dgap_create_tty_sysfs(struct un_t *un, struct device *c)
6518 ret = sysfs_create_group(&c->kobj, &dgap_tty_attribute_group);
6522 dev_set_drvdata(c, un);
6526 static void dgap_remove_tty_sysfs(struct device *c)
6528 sysfs_remove_group(&c->kobj, &dgap_tty_attribute_group);
6532 * Parse a configuration file read into memory as a string.
6534 static int dgap_parsefile(char **in, int Remove)
6536 struct cnode *p, *brd, *line, *conc;
6542 brd = line = conc = NULL;
6544 /* perhaps we are adding to an existing list? */
6545 while (p->next != NULL)
6548 /* file must start with a BEGIN */
6549 while ((rc = dgap_gettok(in, p)) != BEGIN) {
6551 dgap_err("unexpected EOF");
6557 rc = dgap_gettok(in, p);
6559 dgap_err("unexpected EOF");
6565 dgap_err("unexpected end of file");
6568 case BEGIN: /* should only be 1 begin */
6569 dgap_err("unexpected config_begin\n");
6575 case BOARD: /* board info */
6576 if (dgap_checknode(p))
6578 p->next = dgap_newnode(BNODE);
6580 dgap_err("out of memory");
6585 p->u.board.status = dgap_savestring("No");
6591 case APORT2_920P: /* AccelePort_4 */
6592 if (p->type != BNODE) {
6593 dgap_err("unexpected Digi_2r_920 string");
6596 p->u.board.type = APORT2_920P;
6597 p->u.board.v_type = 1;
6600 case APORT4_920P: /* AccelePort_4 */
6601 if (p->type != BNODE) {
6602 dgap_err("unexpected Digi_4r_920 string");
6605 p->u.board.type = APORT4_920P;
6606 p->u.board.v_type = 1;
6609 case APORT8_920P: /* AccelePort_8 */
6610 if (p->type != BNODE) {
6611 dgap_err("unexpected Digi_8r_920 string");
6614 p->u.board.type = APORT8_920P;
6615 p->u.board.v_type = 1;
6618 case PAPORT4: /* AccelePort_4 PCI */
6619 if (p->type != BNODE) {
6620 dgap_err("unexpected Digi_4r(PCI) string");
6623 p->u.board.type = PAPORT4;
6624 p->u.board.v_type = 1;
6627 case PAPORT8: /* AccelePort_8 PCI */
6628 if (p->type != BNODE) {
6629 dgap_err("unexpected Digi_8r string");
6632 p->u.board.type = PAPORT8;
6633 p->u.board.v_type = 1;
6636 case PCX: /* PCI C/X */
6637 if (p->type != BNODE) {
6638 dgap_err("unexpected Digi_C/X_(PCI) string");
6641 p->u.board.type = PCX;
6642 p->u.board.v_type = 1;
6643 p->u.board.conc1 = 0;
6644 p->u.board.conc2 = 0;
6645 p->u.board.module1 = 0;
6646 p->u.board.module2 = 0;
6649 case PEPC: /* PCI EPC/X */
6650 if (p->type != BNODE) {
6651 dgap_err("unexpected \"Digi_EPC/X_(PCI)\" string");
6654 p->u.board.type = PEPC;
6655 p->u.board.v_type = 1;
6656 p->u.board.conc1 = 0;
6657 p->u.board.conc2 = 0;
6658 p->u.board.module1 = 0;
6659 p->u.board.module2 = 0;
6662 case PPCM: /* PCI/Xem */
6663 if (p->type != BNODE) {
6664 dgap_err("unexpected PCI/Xem string");
6667 p->u.board.type = PPCM;
6668 p->u.board.v_type = 1;
6669 p->u.board.conc1 = 0;
6670 p->u.board.conc2 = 0;
6673 case IO: /* i/o port */
6674 if (p->type != BNODE) {
6675 dgap_err("IO port only vaild for boards");
6678 s = dgap_getword(in);
6680 dgap_err("unexpected end of file");
6683 p->u.board.portstr = dgap_savestring(s);
6684 if (kstrtol(s, 0, &p->u.board.port)) {
6685 dgap_err("bad number for IO port");
6688 p->u.board.v_port = 1;
6691 case MEM: /* memory address */
6692 if (p->type != BNODE) {
6693 dgap_err("memory address only vaild for boards");
6696 s = dgap_getword(in);
6698 dgap_err("unexpected end of file");
6701 p->u.board.addrstr = dgap_savestring(s);
6702 if (kstrtoul(s, 0, &p->u.board.addr)) {
6703 dgap_err("bad number for memory address");
6706 p->u.board.v_addr = 1;
6709 case PCIINFO: /* pci information */
6710 if (p->type != BNODE) {
6711 dgap_err("memory address only vaild for boards");
6714 s = dgap_getword(in);
6716 dgap_err("unexpected end of file");
6719 p->u.board.pcibusstr = dgap_savestring(s);
6720 if (kstrtoul(s, 0, &p->u.board.pcibus)) {
6721 dgap_err("bad number for pci bus");
6724 p->u.board.v_pcibus = 1;
6725 s = dgap_getword(in);
6727 dgap_err("unexpected end of file");
6730 p->u.board.pcislotstr = dgap_savestring(s);
6731 if (kstrtoul(s, 0, &p->u.board.pcislot)) {
6732 dgap_err("bad number for pci slot");
6735 p->u.board.v_pcislot = 1;
6739 if (p->type != BNODE) {
6740 dgap_err("install method only vaild for boards");
6743 s = dgap_getword(in);
6745 dgap_err("unexpected end of file");
6748 p->u.board.method = dgap_savestring(s);
6749 p->u.board.v_method = 1;
6753 if (p->type != BNODE) {
6754 dgap_err("config status only vaild for boards");
6757 s = dgap_getword(in);
6759 dgap_err("unexpected end of file");
6762 p->u.board.status = dgap_savestring(s);
6765 case NPORTS: /* number of ports */
6766 if (p->type == BNODE) {
6767 s = dgap_getword(in);
6769 dgap_err("unexpected end of file");
6772 if (kstrtol(s, 0, &p->u.board.nport)) {
6773 dgap_err("bad number for number of ports");
6776 p->u.board.v_nport = 1;
6777 } else if (p->type == CNODE) {
6778 s = dgap_getword(in);
6780 dgap_err("unexpected end of file");
6783 if (kstrtol(s, 0, &p->u.conc.nport)) {
6784 dgap_err("bad number for number of ports");
6787 p->u.conc.v_nport = 1;
6788 } else if (p->type == MNODE) {
6789 s = dgap_getword(in);
6791 dgap_err("unexpected end of file");
6794 if (kstrtol(s, 0, &p->u.module.nport)) {
6795 dgap_err("bad number for number of ports");
6798 p->u.module.v_nport = 1;
6800 dgap_err("nports only valid for concentrators or modules");
6805 case ID: /* letter ID used in tty name */
6806 s = dgap_getword(in);
6808 dgap_err("unexpected end of file");
6812 p->u.board.status = dgap_savestring(s);
6814 if (p->type == CNODE) {
6815 p->u.conc.id = dgap_savestring(s);
6817 } else if (p->type == MNODE) {
6818 p->u.module.id = dgap_savestring(s);
6819 p->u.module.v_id = 1;
6821 dgap_err("id only valid for concentrators or modules");
6826 case STARTO: /* start offset of ID */
6827 if (p->type == BNODE) {
6828 s = dgap_getword(in);
6830 dgap_err("unexpected end of file");
6833 if (kstrtol(s, 0, &p->u.board.start)) {
6834 dgap_err("bad number for start of tty count");
6837 p->u.board.v_start = 1;
6838 } else if (p->type == CNODE) {
6839 s = dgap_getword(in);
6841 dgap_err("unexpected end of file");
6844 if (kstrtol(s, 0, &p->u.conc.start)) {
6845 dgap_err("bad number for start of tty count");
6848 p->u.conc.v_start = 1;
6849 } else if (p->type == MNODE) {
6850 s = dgap_getword(in);
6852 dgap_err("unexpected end of file");
6855 if (kstrtol(s, 0, &p->u.module.start)) {
6856 dgap_err("bad number for start of tty count");
6859 p->u.module.v_start = 1;
6861 dgap_err("start only valid for concentrators or modules");
6866 case TTYN: /* tty name prefix */
6867 if (dgap_checknode(p))
6869 p->next = dgap_newnode(TNODE);
6871 dgap_err("out of memory");
6875 s = dgap_getword(in);
6877 dgap_err("unexpeced end of file");
6880 p->u.ttyname = dgap_savestring(s);
6881 if (!p->u.ttyname) {
6882 dgap_err("out of memory");
6887 case CU: /* cu name prefix */
6888 if (dgap_checknode(p))
6890 p->next = dgap_newnode(CUNODE);
6892 dgap_err("out of memory");
6896 s = dgap_getword(in);
6898 dgap_err("unexpeced end of file");
6901 p->u.cuname = dgap_savestring(s);
6903 dgap_err("out of memory");
6908 case LINE: /* line information */
6909 if (dgap_checknode(p))
6912 dgap_err("must specify board before line info");
6915 switch (brd->u.board.type) {
6917 dgap_err("line not vaild for PC/em");
6920 p->next = dgap_newnode(LNODE);
6922 dgap_err("out of memory");
6931 case CONC: /* concentrator information */
6932 if (dgap_checknode(p))
6935 dgap_err("must specify line info before concentrator");
6938 p->next = dgap_newnode(CNODE);
6940 dgap_err("out of memory");
6946 brd->u.board.conc2++;
6948 brd->u.board.conc1++;
6952 case CX: /* c/x type concentrator */
6953 if (p->type != CNODE) {
6954 dgap_err("cx only valid for concentrators");
6957 p->u.conc.type = CX;
6958 p->u.conc.v_type = 1;
6961 case EPC: /* epc type concentrator */
6962 if (p->type != CNODE) {
6963 dgap_err("cx only valid for concentrators");
6966 p->u.conc.type = EPC;
6967 p->u.conc.v_type = 1;
6970 case MOD: /* EBI module */
6971 if (dgap_checknode(p))
6974 dgap_err("must specify board info before EBI modules");
6977 switch (brd->u.board.type) {
6983 dgap_err("must specify concentrator info before EBI module");
6987 p->next = dgap_newnode(MNODE);
6989 dgap_err("out of memory");
6994 brd->u.board.module2++;
6996 brd->u.board.module1++;
7000 case PORTS: /* ports type EBI module */
7001 if (p->type != MNODE) {
7002 dgap_err("ports only valid for EBI modules");
7005 p->u.module.type = PORTS;
7006 p->u.module.v_type = 1;
7009 case MODEM: /* ports type EBI module */
7010 if (p->type != MNODE) {
7011 dgap_err("modem only valid for modem modules");
7014 p->u.module.type = MODEM;
7015 p->u.module.v_type = 1;
7019 if (p->type == LNODE) {
7020 s = dgap_getword(in);
7022 dgap_err("unexpected end of file");
7025 p->u.line.cable = dgap_savestring(s);
7026 p->u.line.v_cable = 1;
7030 case SPEED: /* sync line speed indication */
7031 if (p->type == LNODE) {
7032 s = dgap_getword(in);
7034 dgap_err("unexpected end of file");
7037 if (kstrtol(s, 0, &p->u.line.speed)) {
7038 dgap_err("bad number for line speed");
7041 p->u.line.v_speed = 1;
7042 } else if (p->type == CNODE) {
7043 s = dgap_getword(in);
7045 dgap_err("unexpected end of file");
7048 if (kstrtol(s, 0, &p->u.conc.speed)) {
7049 dgap_err("bad number for line speed");
7052 p->u.conc.v_speed = 1;
7054 dgap_err("speed valid only for lines or concentrators.");
7060 if (p->type == CNODE) {
7061 s = dgap_getword(in);
7063 dgap_err("unexpected end of file");
7066 p->u.conc.connect = dgap_savestring(s);
7067 p->u.conc.v_connect = 1;
7070 case PRINT: /* transparent print name prefix */
7071 if (dgap_checknode(p))
7073 p->next = dgap_newnode(PNODE);
7075 dgap_err("out of memory");
7079 s = dgap_getword(in);
7081 dgap_err("unexpeced end of file");
7084 p->u.printname = dgap_savestring(s);
7085 if (!p->u.printname) {
7086 dgap_err("out of memory");
7091 case CMAJOR: /* major number */
7092 if (dgap_checknode(p))
7094 p->next = dgap_newnode(JNODE);
7096 dgap_err("out of memory");
7100 s = dgap_getword(in);
7102 dgap_err("unexpected end of file");
7105 if (kstrtol(s, 0, &p->u.majornumber)) {
7106 dgap_err("bad number for major number");
7111 case ALTPIN: /* altpin setting */
7112 if (dgap_checknode(p))
7114 p->next = dgap_newnode(ANODE);
7116 dgap_err("out of memory");
7120 s = dgap_getword(in);
7122 dgap_err("unexpected end of file");
7125 if (kstrtol(s, 0, &p->u.altpin)) {
7126 dgap_err("bad number for altpin");
7131 case USEINTR: /* enable interrupt setting */
7132 if (dgap_checknode(p))
7134 p->next = dgap_newnode(INTRNODE);
7136 dgap_err("out of memory");
7140 s = dgap_getword(in);
7142 dgap_err("unexpected end of file");
7145 if (kstrtol(s, 0, &p->u.useintr)) {
7146 dgap_err("bad number for useintr");
7151 case TTSIZ: /* size of tty structure */
7152 if (dgap_checknode(p))
7154 p->next = dgap_newnode(TSNODE);
7156 dgap_err("out of memory");
7160 s = dgap_getword(in);
7162 dgap_err("unexpected end of file");
7165 if (kstrtol(s, 0, &p->u.ttysize)) {
7166 dgap_err("bad number for ttysize");
7171 case CHSIZ: /* channel structure size */
7172 if (dgap_checknode(p))
7174 p->next = dgap_newnode(CSNODE);
7176 dgap_err("out of memory");
7180 s = dgap_getword(in);
7182 dgap_err("unexpected end of file");
7185 if (kstrtol(s, 0, &p->u.chsize)) {
7186 dgap_err("bad number for chsize");
7191 case BSSIZ: /* board structure size */
7192 if (dgap_checknode(p))
7194 p->next = dgap_newnode(BSNODE);
7196 dgap_err("out of memory");
7200 s = dgap_getword(in);
7202 dgap_err("unexpected end of file");
7205 if (kstrtol(s, 0, &p->u.bssize)) {
7206 dgap_err("bad number for bssize");
7211 case UNTSIZ: /* sched structure size */
7212 if (dgap_checknode(p))
7214 p->next = dgap_newnode(USNODE);
7216 dgap_err("out of memory");
7220 s = dgap_getword(in);
7222 dgap_err("unexpected end of file");
7225 if (kstrtol(s, 0, &p->u.unsize)) {
7226 dgap_err("bad number for schedsize");
7231 case F2SIZ: /* f2200 structure size */
7232 if (dgap_checknode(p))
7234 p->next = dgap_newnode(FSNODE);
7236 dgap_err("out of memory");
7240 s = dgap_getword(in);
7242 dgap_err("unexpected end of file");
7245 if (kstrtol(s, 0, &p->u.f2size)) {
7246 dgap_err("bad number for f2200size");
7251 case VPSIZ: /* vpix structure size */
7252 if (dgap_checknode(p))
7254 p->next = dgap_newnode(VSNODE);
7256 dgap_err("out of memory");
7260 s = dgap_getword(in);
7262 dgap_err("unexpected end of file");
7265 if (kstrtol(s, 0, &p->u.vpixsize)) {
7266 dgap_err("bad number for vpixsize");
7275 * dgap_sindex: much like index(), but it looks for a match of any character in
7276 * the group, and returns that position. If the first character is a ^, then
7277 * this will match the first occurrence not in that group.
7279 static char *dgap_sindex(char *string, char *group)
7283 if (!string || !group)
7284 return (char *) NULL;
7286 if (*group == '^') {
7288 for (; *string; string++) {
7289 for (ptr = group; *ptr; ptr++) {
7290 if (*ptr == *string)
7297 for (; *string; string++) {
7298 for (ptr = group; *ptr; ptr++) {
7299 if (*ptr == *string)
7305 return (char *) NULL;
7309 * Get a token from the input file; return 0 if end of file is reached
7311 static int dgap_gettok(char **in, struct cnode *p)
7316 if (strstr(dgap_cword, "boar")) {
7317 w = dgap_getword(in);
7318 snprintf(dgap_cword, MAXCWORD, "%s", w);
7319 for (t = dgap_tlist; t->token != 0; t++) {
7320 if (!strcmp(w, t->string))
7323 dgap_err("board !!type not specified");
7326 while ((w = dgap_getword(in))) {
7327 snprintf(dgap_cword, MAXCWORD, "%s", w);
7328 for (t = dgap_tlist; t->token != 0; t++) {
7329 if (!strcmp(w, t->string))
7338 * get a word from the input stream, also keep track of current line number.
7339 * words are separated by whitespace.
7341 static char *dgap_getword(char **in)
7343 char *ret_ptr = *in;
7345 char *ptr = dgap_sindex(*in, " \t\n");
7347 /* If no word found, return null */
7351 /* Mark new location for our buffer */
7355 /* Eat any extra spaces/tabs/newlines that might be present */
7356 while (*in && **in && ((**in == ' ') ||
7367 * print an error message, giving the line number in the file where
7368 * the error occurred.
7370 static void dgap_err(char *s)
7372 pr_err("dgap: parse: %s\n", s);
7376 * allocate a new configuration node of type t
7378 static struct cnode *dgap_newnode(int t)
7382 n = kmalloc(sizeof(struct cnode), GFP_ATOMIC);
7384 memset((char *)n, 0, sizeof(struct cnode));
7391 * dgap_checknode: see if all the necessary info has been supplied for a node
7392 * before creating the next node.
7394 static int dgap_checknode(struct cnode *p)
7398 if (p->u.board.v_type == 0) {
7399 dgap_err("board type !not specified");
7406 if (p->u.line.v_speed == 0) {
7407 dgap_err("line speed not specified");
7413 if (p->u.conc.v_type == 0) {
7414 dgap_err("concentrator type not specified");
7417 if (p->u.conc.v_speed == 0) {
7418 dgap_err("concentrator line speed not specified");
7421 if (p->u.conc.v_nport == 0) {
7422 dgap_err("number of ports on concentrator not specified");
7425 if (p->u.conc.v_id == 0) {
7426 dgap_err("concentrator id letter not specified");
7432 if (p->u.module.v_type == 0) {
7433 dgap_err("EBI module type not specified");
7436 if (p->u.module.v_nport == 0) {
7437 dgap_err("number of ports on EBI module not specified");
7440 if (p->u.module.v_id == 0) {
7441 dgap_err("EBI module id letter not specified");
7450 * save a string somewhere
7452 static char *dgap_savestring(char *s)
7456 p = kmalloc(strlen(s) + 1, GFP_ATOMIC);
7463 * Given a board pointer, returns whether we should use interrupts or not.
7465 static uint dgap_config_get_useintr(struct board_t *bd)
7467 struct cnode *p = NULL;
7472 for (p = bd->bd_config; p; p = p->next) {
7476 * check for pcxr types.
7478 return p->u.useintr;
7484 /* If not found, then don't turn on interrupts. */
7489 * Given a board pointer, returns whether we turn on altpin or not.
7491 static uint dgap_config_get_altpin(struct board_t *bd)
7493 struct cnode *p = NULL;
7498 for (p = bd->bd_config; p; p = p->next) {
7502 * check for pcxr types.
7510 /* If not found, then don't turn on interrupts. */
7515 * Given a specific type of board, if found, detached link and
7516 * returns the first occurrence in the list.
7518 static struct cnode *dgap_find_config(int type, int bus, int slot)
7520 struct cnode *p, *prev = NULL, *prev2 = NULL, *found = NULL;
7524 while (p->next != NULL) {
7528 if (p->type == BNODE) {
7530 if (p->u.board.type == type) {
7532 if (p->u.board.v_pcibus &&
7533 p->u.board.pcibus != bus)
7535 if (p->u.board.v_pcislot &&
7536 p->u.board.pcislot != slot)
7541 * Keep walking thru the list till we
7542 * find the next board.
7544 while (p->next != NULL) {
7547 if (p->type == BNODE) {
7550 * Mark the end of our 1 board
7556 * Link the "next" board to the
7557 * previous board, effectively
7558 * "unlinking" our board from
7567 * It must be the last board in the list.
7578 * Given a board pointer, walks the config link, counting up
7579 * all ports user specified should be on the board.
7580 * (This does NOT mean they are all actually present right now tho)
7582 static uint dgap_config_get_num_prts(struct board_t *bd)
7585 struct cnode *p = NULL;
7590 for (p = bd->bd_config; p; p = p->next) {
7595 * check for pcxr types.
7597 if (p->u.board.type > EPCFE)
7598 count += p->u.board.nport;
7601 count += p->u.conc.nport;
7604 count += p->u.module.nport;
7611 static char *dgap_create_config_string(struct board_t *bd, char *string)
7614 struct cnode *p = NULL;
7615 struct cnode *q = NULL;
7623 for (p = bd->bd_config; p; p = p->next) {
7629 *ptr = p->u.line.speed;
7634 * Because the EPC/con concentrators can have EM modules
7635 * hanging off of them, we have to walk ahead in the
7636 * list and keep adding the number of ports on each EM
7637 * to the config. UGH!
7639 speed = p->u.conc.speed;
7641 if ((q != NULL) && (q->type == MNODE)) {
7642 *ptr = (p->u.conc.nport + 0x80);
7645 while ((q->next != NULL) &&
7646 (q->next->type) == MNODE) {
7648 *ptr = (q->u.module.nport + 0x80);
7653 *ptr = q->u.module.nport;
7656 *ptr = p->u.conc.nport;