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.
18 * In the original out of kernel Digi dgap driver, firmware
19 * loading was done via user land to driver handshaking.
21 * For cards that support a concentrator (port expander),
22 * I believe the concentrator its self told the card which
23 * concentrator is actually attached and then that info
24 * was used to tell user land which concentrator firmware
25 * image was to be downloaded. I think even the BIOS or
26 * FEP images required could change with the connection
27 * of a particular concentrator.
29 * Since I have no access to any of these cards or
30 * concentrators, I cannot put the correct concentrator
31 * firmware file names into the firmware_info structure
32 * as is now done for the BIOS and FEP images.
34 * I think, but am not certain, that the cards supporting
35 * concentrators will function without them. So support
36 * of these cards has been left in this driver.
38 * In order to fully support those cards, they would
39 * either have to be acquired for dissection or maybe
40 * Digi International could provide some assistance.
42 #undef DIGI_CONCENTRATORS_SUPPORTED
44 #include <linux/kernel.h>
45 #include <linux/module.h>
46 #include <linux/pci.h>
47 #include <linux/delay.h> /* For udelay */
48 #include <linux/slab.h>
49 #include <linux/uaccess.h>
50 #include <linux/sched.h>
52 #include <linux/interrupt.h> /* For tasklet and interrupt structs/defines */
53 #include <linux/ctype.h>
54 #include <linux/tty.h>
55 #include <linux/tty_flip.h>
56 #include <linux/serial_reg.h>
57 #include <linux/io.h> /* For read[bwl]/write[bwl] */
59 #include <linux/string.h>
60 #include <linux/device.h>
61 #include <linux/kdev_t.h>
62 #include <linux/firmware.h>
66 MODULE_LICENSE("GPL");
67 MODULE_AUTHOR("Digi International, http://www.digi.com");
68 MODULE_DESCRIPTION("Driver for the Digi International EPCA PCI based product line");
69 MODULE_SUPPORTED_DEVICE("dgap");
71 static int dgap_start(void);
72 static void dgap_init_globals(void);
73 static int dgap_found_board(struct pci_dev *pdev, int id);
74 static void dgap_cleanup_board(struct board_t *brd);
75 static void dgap_poll_handler(ulong dummy);
76 static int dgap_init_pci(void);
77 static int dgap_init_one(struct pci_dev *pdev, const struct pci_device_id *ent);
78 static void dgap_remove_one(struct pci_dev *dev);
79 static int dgap_probe1(struct pci_dev *pdev, int card_type);
80 static int dgap_do_remap(struct board_t *brd);
81 static irqreturn_t dgap_intr(int irq, void *voidbrd);
83 static int dgap_tty_open(struct tty_struct *tty, struct file *file);
84 static void dgap_tty_close(struct tty_struct *tty, struct file *file);
85 static int dgap_block_til_ready(struct tty_struct *tty, struct file *file,
86 struct channel_t *ch);
87 static int dgap_tty_ioctl(struct tty_struct *tty, unsigned int cmd,
89 static int dgap_tty_digigeta(struct tty_struct *tty,
90 struct digi_t __user *retinfo);
91 static int dgap_tty_digiseta(struct tty_struct *tty,
92 struct digi_t __user *new_info);
93 static int dgap_tty_digigetedelay(struct tty_struct *tty, int __user *retinfo);
94 static int dgap_tty_digisetedelay(struct tty_struct *tty, int __user *new_info);
95 static int dgap_tty_write_room(struct tty_struct *tty);
96 static int dgap_tty_chars_in_buffer(struct tty_struct *tty);
97 static void dgap_tty_start(struct tty_struct *tty);
98 static void dgap_tty_stop(struct tty_struct *tty);
99 static void dgap_tty_throttle(struct tty_struct *tty);
100 static void dgap_tty_unthrottle(struct tty_struct *tty);
101 static void dgap_tty_flush_chars(struct tty_struct *tty);
102 static void dgap_tty_flush_buffer(struct tty_struct *tty);
103 static void dgap_tty_hangup(struct tty_struct *tty);
104 static int dgap_wait_for_drain(struct tty_struct *tty);
105 static int dgap_set_modem_info(struct tty_struct *tty, unsigned int command,
106 unsigned int __user *value);
107 static int dgap_get_modem_info(struct channel_t *ch,
108 unsigned int __user *value);
109 static int dgap_tty_digisetcustombaud(struct tty_struct *tty,
110 int __user *new_info);
111 static int dgap_tty_digigetcustombaud(struct tty_struct *tty,
112 int __user *retinfo);
113 static int dgap_tty_tiocmget(struct tty_struct *tty);
114 static int dgap_tty_tiocmset(struct tty_struct *tty, unsigned int set,
116 static int dgap_tty_send_break(struct tty_struct *tty, int msec);
117 static void dgap_tty_wait_until_sent(struct tty_struct *tty, int timeout);
118 static int dgap_tty_write(struct tty_struct *tty, const unsigned char *buf,
120 static void dgap_tty_set_termios(struct tty_struct *tty,
121 struct ktermios *old_termios);
122 static int dgap_tty_put_char(struct tty_struct *tty, unsigned char c);
123 static void dgap_tty_send_xchar(struct tty_struct *tty, char ch);
125 static int dgap_tty_register(struct board_t *brd);
126 static int dgap_tty_init(struct board_t *);
127 static void dgap_tty_uninit(struct board_t *);
128 static void dgap_carrier(struct channel_t *ch);
129 static void dgap_input(struct channel_t *ch);
132 * Our function prototypes from dgap_fep5
134 static void dgap_cmdw_ext(struct channel_t *ch, u16 cmd, u16 word, uint ncmds);
135 static int dgap_event(struct board_t *bd);
137 static void dgap_poll_tasklet(unsigned long data);
138 static void dgap_cmdb(struct channel_t *ch, u8 cmd, u8 byte1,
139 u8 byte2, uint ncmds);
140 static void dgap_cmdw(struct channel_t *ch, u8 cmd, u16 word, uint ncmds);
141 static void dgap_wmove(struct channel_t *ch, char *buf, uint cnt);
142 static int dgap_param(struct tty_struct *tty);
143 static void dgap_parity_scan(struct channel_t *ch, unsigned char *cbuf,
144 unsigned char *fbuf, int *len);
145 static uint dgap_get_custom_baud(struct channel_t *ch);
146 static void dgap_firmware_reset_port(struct channel_t *ch);
149 * Function prototypes from dgap_parse.c.
151 static int dgap_gettok(char **in, struct cnode *p);
152 static char *dgap_getword(char **in);
153 static char *dgap_savestring(char *s);
154 static struct cnode *dgap_newnode(int t);
155 static int dgap_checknode(struct cnode *p);
156 static void dgap_err(char *s);
159 * Function prototypes from dgap_sysfs.h
167 static void dgap_create_ports_sysfiles(struct board_t *bd);
168 static void dgap_remove_ports_sysfiles(struct board_t *bd);
170 static int dgap_create_driver_sysfiles(struct pci_driver *);
171 static void dgap_remove_driver_sysfiles(struct pci_driver *);
173 static void dgap_create_tty_sysfs(struct un_t *un, struct device *c);
174 static void dgap_remove_tty_sysfs(struct device *c);
177 * Function prototypes from dgap_parse.h
179 static int dgap_parsefile(char **in, int Remove);
180 static struct cnode *dgap_find_config(int type, int bus, int slot);
181 static uint dgap_config_get_num_prts(struct board_t *bd);
182 static char *dgap_create_config_string(struct board_t *bd, char *string);
183 static uint dgap_config_get_useintr(struct board_t *bd);
184 static uint dgap_config_get_altpin(struct board_t *bd);
186 static int dgap_ms_sleep(ulong ms);
187 static void dgap_do_bios_load(struct board_t *brd, const u8 *ubios, int len);
188 static void dgap_do_fep_load(struct board_t *brd, const u8 *ufep, int len);
189 #ifdef DIGI_CONCENTRATORS_SUPPORTED
190 static void dgap_do_conc_load(struct board_t *brd, u8 *uaddr, int len);
192 static int dgap_after_config_loaded(int board);
193 static int dgap_finalize_board_init(struct board_t *brd);
195 static void dgap_get_vpd(struct board_t *brd);
196 static void dgap_do_reset_board(struct board_t *brd);
197 static int dgap_test_bios(struct board_t *brd);
198 static int dgap_test_fep(struct board_t *brd);
199 static int dgap_tty_register_ports(struct board_t *brd);
200 static int dgap_firmware_load(struct pci_dev *pdev, int card_type);
202 static void dgap_cleanup_module(void);
204 module_exit(dgap_cleanup_module);
207 * File operations permitted on Control/Management major.
209 static const struct file_operations DgapBoardFops = {
210 .owner = THIS_MODULE,
213 static uint dgap_NumBoards;
214 static struct board_t *dgap_Board[MAXBOARDS];
215 static ulong dgap_poll_counter;
216 static char *dgap_config_buf;
217 static int dgap_driver_state = DRIVER_INITIALIZED;
218 static wait_queue_head_t dgap_dl_wait;
219 static int dgap_poll_tick = 20; /* Poll interval - 20 ms */
221 static struct class *dgap_class;
223 static struct board_t *dgap_BoardsByMajor[256];
224 static uint dgap_count = 500;
229 DEFINE_SPINLOCK(dgap_poll_lock); /* Poll scheduling lock */
230 static ulong dgap_poll_time; /* Time of next poll */
231 static uint dgap_poll_stop; /* Used to tell poller to stop */
232 static struct timer_list dgap_poll_timer;
237 Card Model Number of Ports Interface
238 ----------------------------------------------------------------
239 Acceleport Xem 4 - 64 (EIA232 & EIA422)
240 Acceleport Xr 4 & 8 (EIA232)
241 Acceleport Xr 920 4 & 8 (EIA232)
242 Acceleport C/X 8 - 128 (EIA232)
243 Acceleport EPC/X 8 - 224 (EIA232)
244 Acceleport Xr/422 4 & 8 (EIA422)
245 Acceleport 2r/920 2 (EIA232)
246 Acceleport 4r/920 4 (EIA232)
247 Acceleport 8r/920 8 (EIA232)
249 IBM 8-Port Asynchronous PCI Adapter (EIA232)
250 IBM 128-Port Asynchronous PCI Adapter (EIA232 & EIA422)
253 static struct pci_device_id dgap_pci_tbl[] = {
254 { DIGI_VID, PCI_DEV_XEM_DID, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0 },
255 { DIGI_VID, PCI_DEV_CX_DID, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 1 },
256 { DIGI_VID, PCI_DEV_CX_IBM_DID, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 2 },
257 { DIGI_VID, PCI_DEV_EPCJ_DID, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 3 },
258 { DIGI_VID, PCI_DEV_920_2_DID, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 4 },
259 { DIGI_VID, PCI_DEV_920_4_DID, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 5 },
260 { DIGI_VID, PCI_DEV_920_8_DID, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 6 },
261 { DIGI_VID, PCI_DEV_XR_DID, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 7 },
262 { DIGI_VID, PCI_DEV_XRJ_DID, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 8 },
263 { DIGI_VID, PCI_DEV_XR_422_DID, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 9 },
264 { DIGI_VID, PCI_DEV_XR_IBM_DID, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 10 },
265 { DIGI_VID, PCI_DEV_XR_SAIP_DID, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 11 },
266 { DIGI_VID, PCI_DEV_XR_BULL_DID, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 12 },
267 { DIGI_VID, PCI_DEV_920_8_HP_DID, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 13 },
268 { DIGI_VID, PCI_DEV_XEM_HP_DID, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 14 },
269 {0,} /* 0 terminated list. */
271 MODULE_DEVICE_TABLE(pci, dgap_pci_tbl);
274 * A generic list of Product names, PCI Vendor ID, and PCI Device ID.
283 static struct board_id dgap_Ids[] = {
284 { PPCM, PCI_DEV_XEM_NAME, 64, (T_PCXM|T_PCLITE|T_PCIBUS) },
285 { PCX, PCI_DEV_CX_NAME, 128, (T_CX|T_PCIBUS) },
286 { PCX, PCI_DEV_CX_IBM_NAME, 128, (T_CX|T_PCIBUS) },
287 { PEPC, PCI_DEV_EPCJ_NAME, 224, (T_EPC|T_PCIBUS) },
288 { APORT2_920P, PCI_DEV_920_2_NAME, 2, (T_PCXR|T_PCLITE|T_PCIBUS) },
289 { APORT4_920P, PCI_DEV_920_4_NAME, 4, (T_PCXR|T_PCLITE|T_PCIBUS) },
290 { APORT8_920P, PCI_DEV_920_8_NAME, 8, (T_PCXR|T_PCLITE|T_PCIBUS) },
291 { PAPORT8, PCI_DEV_XR_NAME, 8, (T_PCXR|T_PCLITE|T_PCIBUS) },
292 { PAPORT8, PCI_DEV_XRJ_NAME, 8, (T_PCXR|T_PCLITE|T_PCIBUS) },
293 { PAPORT8, PCI_DEV_XR_422_NAME, 8, (T_PCXR|T_PCLITE|T_PCIBUS) },
294 { PAPORT8, PCI_DEV_XR_IBM_NAME, 8, (T_PCXR|T_PCLITE|T_PCIBUS) },
295 { PAPORT8, PCI_DEV_XR_SAIP_NAME, 8, (T_PCXR|T_PCLITE|T_PCIBUS) },
296 { PAPORT8, PCI_DEV_XR_BULL_NAME, 8, (T_PCXR|T_PCLITE|T_PCIBUS) },
297 { APORT8_920P, PCI_DEV_920_8_HP_NAME, 8, (T_PCXR|T_PCLITE|T_PCIBUS) },
298 { PPCM, PCI_DEV_XEM_HP_NAME, 64, (T_PCXM|T_PCLITE|T_PCIBUS) },
299 {0,} /* 0 terminated list. */
302 static struct pci_driver dgap_driver = {
304 .probe = dgap_init_one,
305 .id_table = dgap_pci_tbl,
306 .remove = dgap_remove_one,
309 struct firmware_info {
310 u8 *conf_name; /* dgap.conf */
311 u8 *bios_name; /* BIOS filename */
312 u8 *fep_name; /* FEP filename */
313 u8 *con_name; /* Concentrator filename FIXME*/
314 int num; /* sequence number */
318 * Firmware - BIOS, FEP, and CONC filenames
320 static struct firmware_info fw_info[] = {
321 { "dgap/dgap.conf", "dgap/sxbios.bin", "dgap/sxfep.bin", 0, 0 },
322 { "dgap/dgap.conf", "dgap/cxpbios.bin", "dgap/cxpfep.bin", 0, 1 },
323 { "dgap/dgap.conf", "dgap/cxpbios.bin", "dgap/cxpfep.bin", 0, 2 },
324 { "dgap/dgap.conf", "dgap/pcibios.bin", "dgap/pcifep.bin", 0, 3 },
325 { "dgap/dgap.conf", "dgap/xrbios.bin", "dgap/xrfep.bin", 0, 4 },
326 { "dgap/dgap.conf", "dgap/xrbios.bin", "dgap/xrfep.bin", 0, 5 },
327 { "dgap/dgap.conf", "dgap/xrbios.bin", "dgap/xrfep.bin", 0, 6 },
328 { "dgap/dgap.conf", "dgap/xrbios.bin", "dgap/xrfep.bin", 0, 7 },
329 { "dgap/dgap.conf", "dgap/xrbios.bin", "dgap/xrfep.bin", 0, 8 },
330 { "dgap/dgap.conf", "dgap/xrbios.bin", "dgap/xrfep.bin", 0, 9 },
331 { "dgap/dgap.conf", "dgap/xrbios.bin", "dgap/xrfep.bin", 0, 10 },
332 { "dgap/dgap.conf", "dgap/xrbios.bin", "dgap/xrfep.bin", 0, 11 },
333 { "dgap/dgap.conf", "dgap/xrbios.bin", "dgap/xrfep.bin", 0, 12 },
334 { "dgap/dgap.conf", "dgap/xrbios.bin", "dgap/xrfep.bin", 0, 13 },
335 { "dgap/dgap.conf", "dgap/sxbios.bin", "dgap/sxfep.bin", 0, 14 },
340 * Default transparent print information.
342 static struct digi_t dgap_digi_init = {
343 .digi_flags = DIGI_COOK, /* Flags */
344 .digi_maxcps = 100, /* Max CPS */
345 .digi_maxchar = 50, /* Max chars in print queue */
346 .digi_bufsize = 100, /* Printer buffer size */
347 .digi_onlen = 4, /* size of printer on string */
348 .digi_offlen = 4, /* size of printer off string */
349 .digi_onstr = "\033[5i", /* ANSI printer on string ] */
350 .digi_offstr = "\033[4i", /* ANSI printer off string ] */
351 .digi_term = "ansi" /* default terminal type */
355 * Define a local default termios struct. All ports will be created
356 * with this termios initially.
358 * This defines a raw port at 9600 baud, 8 data bits, no parity,
362 static struct ktermios DgapDefaultTermios = {
363 .c_iflag = (DEFAULT_IFLAGS), /* iflags */
364 .c_oflag = (DEFAULT_OFLAGS), /* oflags */
365 .c_cflag = (DEFAULT_CFLAGS), /* cflags */
366 .c_lflag = (DEFAULT_LFLAGS), /* lflags */
371 static const struct tty_operations dgap_tty_ops = {
372 .open = dgap_tty_open,
373 .close = dgap_tty_close,
374 .write = dgap_tty_write,
375 .write_room = dgap_tty_write_room,
376 .flush_buffer = dgap_tty_flush_buffer,
377 .chars_in_buffer = dgap_tty_chars_in_buffer,
378 .flush_chars = dgap_tty_flush_chars,
379 .ioctl = dgap_tty_ioctl,
380 .set_termios = dgap_tty_set_termios,
381 .stop = dgap_tty_stop,
382 .start = dgap_tty_start,
383 .throttle = dgap_tty_throttle,
384 .unthrottle = dgap_tty_unthrottle,
385 .hangup = dgap_tty_hangup,
386 .put_char = dgap_tty_put_char,
387 .tiocmget = dgap_tty_tiocmget,
388 .tiocmset = dgap_tty_tiocmset,
389 .break_ctl = dgap_tty_send_break,
390 .wait_until_sent = dgap_tty_wait_until_sent,
391 .send_xchar = dgap_tty_send_xchar
395 * Our needed internal static variables from dgap_parse.c
397 static struct cnode dgap_head;
399 static char dgap_cword[MAXCWORD];
406 static struct toklist dgap_tlist[] = {
407 { BEGIN, "config_begin" },
408 { END, "config_end" },
410 { PCX, "Digi_AccelePort_C/X_PCI" },
411 { PEPC, "Digi_AccelePort_EPC/X_PCI" },
412 { PPCM, "Digi_AccelePort_Xem_PCI" },
413 { APORT2_920P, "Digi_AccelePort_2r_920_PCI" },
414 { APORT4_920P, "Digi_AccelePort_4r_920_PCI" },
415 { APORT8_920P, "Digi_AccelePort_8r_920_PCI" },
416 { PAPORT4, "Digi_AccelePort_4r_PCI(EIA-232/RS-422)" },
417 { PAPORT8, "Digi_AccelePort_8r_PCI(EIA-232/RS-422)" },
419 { PCIINFO, "pciinfo" },
422 { CONC, "concentrator" },
432 { CONNECT, "connect" },
433 { METHOD, "method" },
434 { STATUS, "status" },
435 { CUSTOM, "Custom" },
441 { NPORTS, "nports" },
446 { ALTPIN, "altpin" },
447 { USEINTR, "useintr" },
448 { TTSIZ, "ttysize" },
450 { BSSIZ, "boardsize" },
451 { UNTSIZ, "schedsize" },
452 { F2SIZ, "f2200size" },
453 { VPSIZ, "vpixsize" },
457 /************************************************************************
459 * Driver load/unload functions
461 ************************************************************************/
466 * Module load. This is where it all starts.
468 static int dgap_init_module(void)
472 pr_info("%s, Digi International Part Number %s\n", DG_NAME, DG_PART);
478 rc = dgap_init_pci();
482 rc = dgap_create_driver_sysfiles(&dgap_driver);
486 dgap_driver_state = DRIVER_READY;
492 dgap_cleanup_module();
496 module_init(dgap_init_module);
501 static int dgap_start(void)
505 struct device *device;
508 * make sure that the globals are
509 * init'd before we do anything else
515 pr_info("For the tools package please visit http://www.digi.com\n");
518 * Register our base character device into the kernel.
522 * Register management/dpa devices
524 rc = register_chrdev(DIGI_DGAP_MAJOR, "dgap", &DgapBoardFops);
528 dgap_class = class_create(THIS_MODULE, "dgap_mgmt");
529 if (IS_ERR(dgap_class)) {
530 rc = PTR_ERR(dgap_class);
534 device = device_create(dgap_class, NULL,
535 MKDEV(DIGI_DGAP_MAJOR, 0),
537 if (IS_ERR(device)) {
538 rc = PTR_ERR(device);
542 /* Start the poller */
543 spin_lock_irqsave(&dgap_poll_lock, flags);
544 init_timer(&dgap_poll_timer);
545 dgap_poll_timer.function = dgap_poll_handler;
546 dgap_poll_timer.data = 0;
547 dgap_poll_time = jiffies + dgap_jiffies_from_ms(dgap_poll_tick);
548 dgap_poll_timer.expires = dgap_poll_time;
549 spin_unlock_irqrestore(&dgap_poll_lock, flags);
551 add_timer(&dgap_poll_timer);
556 class_destroy(dgap_class);
558 unregister_chrdev(DIGI_DGAP_MAJOR, "dgap");
563 * Register pci driver, and return how many boards we have.
565 static int dgap_init_pci(void)
567 return pci_register_driver(&dgap_driver);
570 /* returns count (>= 0), or negative on error */
571 static int dgap_init_one(struct pci_dev *pdev, const struct pci_device_id *ent)
575 /* wake up and enable device */
576 rc = pci_enable_device(pdev);
581 rc = dgap_probe1(pdev, ent->driver_data);
584 rc = dgap_firmware_load(pdev, ent->driver_data);
590 static int dgap_probe1(struct pci_dev *pdev, int card_type)
592 return dgap_found_board(pdev, card_type);
595 static void dgap_remove_one(struct pci_dev *dev)
601 * dgap_cleanup_module()
603 * Module unload. This is where it all ends.
605 static void dgap_cleanup_module(void)
610 spin_lock_irqsave(&dgap_poll_lock, lock_flags);
612 spin_unlock_irqrestore(&dgap_poll_lock, lock_flags);
614 /* Turn off poller right away. */
615 del_timer_sync(&dgap_poll_timer);
617 dgap_remove_driver_sysfiles(&dgap_driver);
619 device_destroy(dgap_class, MKDEV(DIGI_DGAP_MAJOR, 0));
620 class_destroy(dgap_class);
621 unregister_chrdev(DIGI_DGAP_MAJOR, "dgap");
623 for (i = 0; i < dgap_NumBoards; ++i) {
624 dgap_remove_ports_sysfiles(dgap_Board[i]);
625 dgap_tty_uninit(dgap_Board[i]);
626 dgap_cleanup_board(dgap_Board[i]);
630 pci_unregister_driver(&dgap_driver);
634 * dgap_cleanup_board()
636 * Free all the memory associated with a board
638 static void dgap_cleanup_board(struct board_t *brd)
642 if (!brd || brd->magic != DGAP_BOARD_MAGIC)
645 if (brd->intr_used && brd->irq)
646 free_irq(brd->irq, brd);
648 tasklet_kill(&brd->helper_tasklet);
650 if (brd->re_map_port) {
651 release_mem_region(brd->membase + 0x200000, 0x200000);
652 iounmap(brd->re_map_port);
653 brd->re_map_port = NULL;
656 if (brd->re_map_membase) {
657 release_mem_region(brd->membase, 0x200000);
658 iounmap(brd->re_map_membase);
659 brd->re_map_membase = NULL;
662 /* Free all allocated channels structs */
663 for (i = 0; i < MAXPORTS ; i++)
664 kfree(brd->channels[i]);
667 kfree(brd->flipflagbuf);
669 dgap_Board[brd->boardnum] = NULL;
677 * A board has been found, init it.
679 static int dgap_found_board(struct pci_dev *pdev, int id)
682 unsigned int pci_irq;
685 /* get the board structure and prep it */
686 brd = kzalloc(sizeof(struct board_t), GFP_KERNEL);
690 dgap_Board[dgap_NumBoards] = brd;
692 /* store the info for the board we've found */
693 brd->magic = DGAP_BOARD_MAGIC;
694 brd->boardnum = dgap_NumBoards;
696 brd->vendor = dgap_pci_tbl[id].vendor;
697 brd->device = dgap_pci_tbl[id].device;
699 brd->pci_bus = pdev->bus->number;
700 brd->pci_slot = PCI_SLOT(pdev->devfn);
701 brd->name = dgap_Ids[id].name;
702 brd->maxports = dgap_Ids[id].maxports;
703 brd->type = dgap_Ids[id].config_type;
704 brd->dpatype = dgap_Ids[id].dpatype;
705 brd->dpastatus = BD_NOFEP;
706 init_waitqueue_head(&brd->state_wait);
708 spin_lock_init(&brd->bd_lock);
711 brd->inhibit_poller = FALSE;
712 brd->wait_for_bios = 0;
713 brd->wait_for_fep = 0;
715 for (i = 0; i < MAXPORTS; i++)
716 brd->channels[i] = NULL;
718 /* store which card & revision we have */
719 pci_read_config_word(pdev, PCI_SUBSYSTEM_VENDOR_ID, &brd->subvendor);
720 pci_read_config_word(pdev, PCI_SUBSYSTEM_ID, &brd->subdevice);
721 pci_read_config_byte(pdev, PCI_REVISION_ID, &brd->rev);
726 /* get the PCI Base Address Registers */
728 /* Xr Jupiter and EPC use BAR 2 */
729 if (brd->device == PCI_DEV_XRJ_DID || brd->device == PCI_DEV_EPCJ_DID) {
730 brd->membase = pci_resource_start(pdev, 2);
731 brd->membase_end = pci_resource_end(pdev, 2);
733 /* Everyone else uses BAR 0 */
735 brd->membase = pci_resource_start(pdev, 0);
736 brd->membase_end = pci_resource_end(pdev, 0);
742 if (brd->membase & 1)
748 * On the PCI boards, there is no IO space allocated
749 * The I/O registers will be in the first 3 bytes of the
750 * upper 2MB of the 4MB memory space. The board memory
751 * will be mapped into the low 2MB of the 4MB memory space
753 brd->port = brd->membase + PCI_IO_OFFSET;
754 brd->port_end = brd->port + PCI_IO_SIZE;
757 * Special initialization for non-PLX boards
759 if (brd->device != PCI_DEV_XRJ_DID && brd->device != PCI_DEV_EPCJ_DID) {
762 pci_write_config_byte(pdev, 0x40, 0);
763 pci_write_config_byte(pdev, 0x46, 0);
765 /* Limit burst length to 2 doubleword transactions */
766 pci_write_config_byte(pdev, 0x42, 1);
769 * Enable IO and mem if not already done.
770 * This was needed for support on Itanium.
772 pci_read_config_word(pdev, PCI_COMMAND, &cmd);
773 cmd |= (PCI_COMMAND_IO | PCI_COMMAND_MEMORY);
774 pci_write_config_word(pdev, PCI_COMMAND, cmd);
777 /* init our poll helper tasklet */
778 tasklet_init(&brd->helper_tasklet, dgap_poll_tasklet,
779 (unsigned long) brd);
781 i = dgap_do_remap(brd);
783 brd->state = BOARD_FAILED;
785 pr_info("dgap: board %d: %s (rev %d), irq %ld\n",
786 dgap_NumBoards, brd->name, brd->rev, brd->irq);
792 static int dgap_finalize_board_init(struct board_t *brd)
796 if (!brd || brd->magic != DGAP_BOARD_MAGIC)
799 brd->use_interrupts = dgap_config_get_useintr(brd);
802 * Set up our interrupt handler if we are set to do interrupts.
804 if (brd->use_interrupts && brd->irq) {
806 rc = request_irq(brd->irq, dgap_intr, IRQF_SHARED, "DGAP", brd);
819 static int dgap_firmware_load(struct pci_dev *pdev, int card_type)
821 struct board_t *brd = dgap_Board[dgap_NumBoards - 1];
822 const struct firmware *fw;
827 dgap_do_reset_board(brd);
829 if ((fw_info[card_type].conf_name) && !dgap_config_buf) {
830 ret = request_firmware(&fw, fw_info[card_type].conf_name,
833 pr_err("dgap: config file %s not found\n",
834 fw_info[card_type].conf_name);
838 dgap_config_buf = kzalloc(fw->size + 1, GFP_KERNEL);
839 if (!dgap_config_buf) {
840 release_firmware(fw);
844 memcpy(dgap_config_buf, fw->data, fw->size);
845 release_firmware(fw);
848 * preserve dgap_config_buf
849 * as dgap_parsefile would
850 * otherwise alter it.
852 tmp_ptr = dgap_config_buf;
854 if (dgap_parsefile(&tmp_ptr, TRUE) != 0) {
855 kfree(dgap_config_buf);
858 kfree(dgap_config_buf);
861 ret = dgap_after_config_loaded(brd->boardnum);
865 * Match this board to a config the user created for us.
868 dgap_find_config(brd->type, brd->pci_bus, brd->pci_slot);
871 * Because the 4 port Xr products share the same PCI ID
872 * as the 8 port Xr products, if we receive a NULL config
873 * back, and this is a PAPORT8 board, retry with a
874 * PAPORT4 attempt as well.
876 if (brd->type == PAPORT8 && !brd->bd_config)
878 dgap_find_config(PAPORT4, brd->pci_bus, brd->pci_slot);
880 if (!brd->bd_config) {
881 pr_err("dgap: No valid configuration found\n");
885 dgap_tty_register(brd);
886 dgap_finalize_board_init(brd);
888 if (fw_info[card_type].bios_name) {
889 ret = request_firmware(&fw, fw_info[card_type].bios_name,
892 pr_err("dgap: bios file %s not found\n",
893 fw_info[card_type].bios_name);
896 dgap_do_bios_load(brd, fw->data, fw->size);
897 release_firmware(fw);
899 /* Wait for BIOS to test board... */
900 ret = dgap_test_bios(brd);
905 if (fw_info[card_type].fep_name) {
906 ret = request_firmware(&fw, fw_info[card_type].fep_name,
909 pr_err("dgap: fep file %s not found\n",
910 fw_info[card_type].fep_name);
913 dgap_do_fep_load(brd, fw->data, fw->size);
914 release_firmware(fw);
916 /* Wait for FEP to load on board... */
917 ret = dgap_test_fep(brd);
922 #ifdef DIGI_CONCENTRATORS_SUPPORTED
924 * If this is a CX or EPCX, we need to see if the firmware
925 * is requesting a concentrator image from us.
927 if ((bd->type == PCX) || (bd->type == PEPC)) {
928 chk_addr = (u16 *) (vaddr + DOWNREQ);
929 /* Nonzero if FEP is requesting concentrator image. */
930 check = readw(chk_addr);
931 vaddr = brd->re_map_membase;
934 if (fw_info[card_type].con_name && check && vaddr) {
935 ret = request_firmware(&fw, fw_info[card_type].con_name,
938 pr_err("dgap: conc file %s not found\n",
939 fw_info[card_type].con_name);
942 /* Put concentrator firmware loading code here */
943 offset = readw((u16 *) (vaddr + DOWNREQ));
944 memcpy_toio(offset, fw->data, fw->size);
946 dgap_do_conc_load(brd, (char *)fw->data, fw->size)
947 release_firmware(fw);
951 * Do tty device initialization.
953 ret = dgap_tty_init(brd);
955 dgap_tty_uninit(brd);
959 ret = dgap_tty_register_ports(brd);
963 brd->state = BOARD_READY;
964 brd->dpastatus = BD_RUNNING;
972 static int dgap_do_remap(struct board_t *brd)
974 if (!brd || brd->magic != DGAP_BOARD_MAGIC)
977 if (!request_mem_region(brd->membase, 0x200000, "dgap"))
980 if (!request_mem_region(brd->membase + PCI_IO_OFFSET, 0x200000,
982 release_mem_region(brd->membase, 0x200000);
986 brd->re_map_membase = ioremap(brd->membase, 0x200000);
987 if (!brd->re_map_membase) {
988 release_mem_region(brd->membase, 0x200000);
989 release_mem_region(brd->membase + PCI_IO_OFFSET, 0x200000);
993 brd->re_map_port = ioremap((brd->membase + PCI_IO_OFFSET), 0x200000);
994 if (!brd->re_map_port) {
995 release_mem_region(brd->membase, 0x200000);
996 release_mem_region(brd->membase + PCI_IO_OFFSET, 0x200000);
997 iounmap(brd->re_map_membase);
1004 /*****************************************************************************
1024 * As each timer expires, it determines (a) whether the "transmit"
1025 * waiter needs to be woken up, and (b) whether the poller needs to
1028 ******************************************************************************/
1030 static void dgap_poll_handler(ulong dummy)
1033 struct board_t *brd;
1034 unsigned long lock_flags;
1037 dgap_poll_counter++;
1040 * Do not start the board state machine until
1041 * driver tells us its up and running, and has
1042 * everything it needs.
1044 if (dgap_driver_state != DRIVER_READY)
1045 goto schedule_poller;
1048 * If we have just 1 board, or the system is not SMP,
1049 * then use the typical old style poller.
1050 * Otherwise, use our new tasklet based poller, which should
1051 * speed things up for multiple boards.
1053 if ((dgap_NumBoards == 1) || (num_online_cpus() <= 1)) {
1054 for (i = 0; i < dgap_NumBoards; i++) {
1056 brd = dgap_Board[i];
1058 if (brd->state == BOARD_FAILED)
1060 if (!brd->intr_running)
1061 /* Call the real board poller directly */
1062 dgap_poll_tasklet((unsigned long) brd);
1066 * Go thru each board, kicking off a
1067 * tasklet for each if needed
1069 for (i = 0; i < dgap_NumBoards; i++) {
1070 brd = dgap_Board[i];
1073 * Attempt to grab the board lock.
1075 * If we can't get it, no big deal, the next poll
1076 * will get it. Basically, I just really don't want
1077 * to spin in here, because I want to kick off my
1078 * tasklets as fast as I can, and then get out the
1081 if (!spin_trylock(&brd->bd_lock))
1085 * If board is in a failed state, don't bother
1086 * scheduling a tasklet
1088 if (brd->state == BOARD_FAILED) {
1089 spin_unlock(&brd->bd_lock);
1093 /* Schedule a poll helper task */
1094 if (!brd->intr_running)
1095 tasklet_schedule(&brd->helper_tasklet);
1098 * Can't do DGAP_UNLOCK here, as we don't have
1099 * lock_flags because we did a trylock above.
1101 spin_unlock(&brd->bd_lock);
1108 * Schedule ourself back at the nominal wakeup interval.
1110 spin_lock_irqsave(&dgap_poll_lock, lock_flags);
1111 dgap_poll_time += dgap_jiffies_from_ms(dgap_poll_tick);
1113 new_time = dgap_poll_time - jiffies;
1115 if ((ulong) new_time >= 2 * dgap_poll_tick) {
1117 jiffies + dgap_jiffies_from_ms(dgap_poll_tick);
1120 dgap_poll_timer.function = dgap_poll_handler;
1121 dgap_poll_timer.data = 0;
1122 dgap_poll_timer.expires = dgap_poll_time;
1123 spin_unlock_irqrestore(&dgap_poll_lock, lock_flags);
1125 if (!dgap_poll_stop)
1126 add_timer(&dgap_poll_timer);
1132 * Driver interrupt handler.
1134 static irqreturn_t dgap_intr(int irq, void *voidbrd)
1136 struct board_t *brd = (struct board_t *) voidbrd;
1142 * Check to make sure its for us.
1144 if (brd->magic != DGAP_BOARD_MAGIC)
1150 * Schedule tasklet to run at a better time.
1152 tasklet_schedule(&brd->helper_tasklet);
1157 * dgap_init_globals()
1159 * This is where we initialize the globals from the static insmod
1160 * configuration variables. These are declared near the head of
1163 static void dgap_init_globals(void)
1167 for (i = 0; i < MAXBOARDS; i++)
1168 dgap_Board[i] = NULL;
1170 init_timer(&dgap_poll_timer);
1172 init_waitqueue_head(&dgap_dl_wait);
1175 /************************************************************************
1179 ************************************************************************/
1184 * Put the driver to sleep for x ms's
1186 * Returns 0 if timed out, !0 (showing signal) if interrupted by a signal.
1188 static int dgap_ms_sleep(ulong ms)
1190 current->state = TASK_INTERRUPTIBLE;
1191 schedule_timeout((ms * HZ) / 1000);
1192 return signal_pending(current);
1195 /************************************************************************
1197 * TTY Initialization/Cleanup Functions
1199 ************************************************************************/
1202 * dgap_tty_register()
1204 * Init the tty subsystem for this board.
1206 static int dgap_tty_register(struct board_t *brd)
1210 brd->SerialDriver = alloc_tty_driver(MAXPORTS);
1212 snprintf(brd->SerialName, MAXTTYNAMELEN, "tty_dgap_%d_", brd->boardnum);
1213 brd->SerialDriver->name = brd->SerialName;
1214 brd->SerialDriver->name_base = 0;
1215 brd->SerialDriver->major = 0;
1216 brd->SerialDriver->minor_start = 0;
1217 brd->SerialDriver->type = TTY_DRIVER_TYPE_SERIAL;
1218 brd->SerialDriver->subtype = SERIAL_TYPE_NORMAL;
1219 brd->SerialDriver->init_termios = DgapDefaultTermios;
1220 brd->SerialDriver->driver_name = DRVSTR;
1221 brd->SerialDriver->flags = (TTY_DRIVER_REAL_RAW |
1222 TTY_DRIVER_DYNAMIC_DEV |
1223 TTY_DRIVER_HARDWARE_BREAK);
1225 /* The kernel wants space to store pointers to tty_structs */
1226 brd->SerialDriver->ttys =
1227 kzalloc(MAXPORTS * sizeof(struct tty_struct *), GFP_KERNEL);
1228 if (!brd->SerialDriver->ttys)
1232 * Entry points for driver. Called by the kernel from
1233 * tty_io.c and n_tty.c.
1235 tty_set_operations(brd->SerialDriver, &dgap_tty_ops);
1238 * If we're doing transparent print, we have to do all of the above
1239 * again, separately so we don't get the LD confused about what major
1240 * we are when we get into the dgap_tty_open() routine.
1242 brd->PrintDriver = alloc_tty_driver(MAXPORTS);
1244 snprintf(brd->PrintName, MAXTTYNAMELEN, "pr_dgap_%d_", brd->boardnum);
1245 brd->PrintDriver->name = brd->PrintName;
1246 brd->PrintDriver->name_base = 0;
1247 brd->PrintDriver->major = 0;
1248 brd->PrintDriver->minor_start = 0;
1249 brd->PrintDriver->type = TTY_DRIVER_TYPE_SERIAL;
1250 brd->PrintDriver->subtype = SERIAL_TYPE_NORMAL;
1251 brd->PrintDriver->init_termios = DgapDefaultTermios;
1252 brd->PrintDriver->driver_name = DRVSTR;
1253 brd->PrintDriver->flags = (TTY_DRIVER_REAL_RAW |
1254 TTY_DRIVER_DYNAMIC_DEV |
1255 TTY_DRIVER_HARDWARE_BREAK);
1257 /* The kernel wants space to store pointers to tty_structs */
1258 brd->PrintDriver->ttys =
1259 kzalloc(MAXPORTS * sizeof(struct tty_struct *), GFP_KERNEL);
1260 if (!brd->PrintDriver->ttys)
1264 * Entry points for driver. Called by the kernel from
1265 * tty_io.c and n_tty.c.
1267 tty_set_operations(brd->PrintDriver, &dgap_tty_ops);
1269 if (!brd->dgap_Major_Serial_Registered) {
1270 /* Register tty devices */
1271 rc = tty_register_driver(brd->SerialDriver);
1274 brd->dgap_Major_Serial_Registered = TRUE;
1275 dgap_BoardsByMajor[brd->SerialDriver->major] = brd;
1276 brd->dgap_Serial_Major = brd->SerialDriver->major;
1279 if (!brd->dgap_Major_TransparentPrint_Registered) {
1280 /* Register Transparent Print devices */
1281 rc = tty_register_driver(brd->PrintDriver);
1284 brd->dgap_Major_TransparentPrint_Registered = TRUE;
1285 dgap_BoardsByMajor[brd->PrintDriver->major] = brd;
1286 brd->dgap_TransparentPrint_Major = brd->PrintDriver->major;
1295 * Init the tty subsystem. Called once per board after board has been
1296 * downloaded and init'ed.
1298 static int dgap_tty_init(struct board_t *brd)
1302 uint true_count = 0;
1305 struct channel_t *ch;
1313 * Initialize board structure elements.
1316 vaddr = brd->re_map_membase;
1317 true_count = readw((vaddr + NCHAN));
1319 brd->nasync = dgap_config_get_num_prts(brd);
1322 brd->nasync = brd->maxports;
1324 if (brd->nasync > brd->maxports)
1325 brd->nasync = brd->maxports;
1327 if (true_count != brd->nasync) {
1328 if ((brd->type == PPCM) && (true_count == 64)) {
1329 pr_warn("dgap: %s configured for %d ports, has %d ports.\n",
1330 brd->name, brd->nasync, true_count);
1331 pr_warn("dgap: Please make SURE the EBI cable running from the card\n");
1332 pr_warn("dgap: to each EM module is plugged into EBI IN!\n");
1333 } else if ((brd->type == PPCM) && (true_count == 0)) {
1334 pr_warn("dgap: %s configured for %d ports, has %d ports.\n",
1335 brd->name, brd->nasync, true_count);
1336 pr_warn("dgap: Please make SURE the EBI cable running from the card\n");
1337 pr_warn("dgap: to each EM module is plugged into EBI IN!\n");
1339 pr_warn("dgap: %s configured for %d ports, has %d ports.\n",
1340 brd->name, brd->nasync, true_count);
1342 brd->nasync = true_count;
1344 /* If no ports, don't bother going any further */
1346 brd->state = BOARD_FAILED;
1347 brd->dpastatus = BD_NOFEP;
1353 * Allocate channel memory that might not have been allocated
1354 * when the driver was first loaded.
1356 for (i = 0; i < brd->nasync; i++) {
1357 if (!brd->channels[i]) {
1359 kzalloc(sizeof(struct channel_t), GFP_ATOMIC);
1360 if (!brd->channels[i])
1365 ch = brd->channels[0];
1366 vaddr = brd->re_map_membase;
1368 bs = (struct bs_t *) ((ulong) vaddr + CHANBUF);
1369 cm = (struct cm_t *) ((ulong) vaddr + CMDBUF);
1373 /* Set up channel variables */
1374 for (i = 0; i < brd->nasync; i++, ch = brd->channels[i], bs++) {
1376 if (!brd->channels[i])
1379 spin_lock_init(&ch->ch_lock);
1381 /* Store all our magic numbers */
1382 ch->magic = DGAP_CHANNEL_MAGIC;
1383 ch->ch_tun.magic = DGAP_UNIT_MAGIC;
1384 ch->ch_tun.un_type = DGAP_SERIAL;
1385 ch->ch_tun.un_ch = ch;
1386 ch->ch_tun.un_dev = i;
1388 ch->ch_pun.magic = DGAP_UNIT_MAGIC;
1389 ch->ch_pun.un_type = DGAP_PRINT;
1390 ch->ch_pun.un_ch = ch;
1391 ch->ch_pun.un_dev = i;
1393 ch->ch_vaddr = vaddr;
1398 ch->ch_digi = dgap_digi_init;
1401 * Set up digi dsr and dcd bits based on altpin flag.
1403 if (dgap_config_get_altpin(brd)) {
1406 ch->ch_digi.digi_flags |= DIGI_ALTPIN;
1409 ch->ch_dsr = DM_DSR;
1412 ch->ch_taddr = vaddr + ((ch->ch_bs->tx_seg) << 4);
1413 ch->ch_raddr = vaddr + ((ch->ch_bs->rx_seg) << 4);
1416 ch->ch_tsize = readw(&(ch->ch_bs->tx_max)) + 1;
1417 ch->ch_rsize = readw(&(ch->ch_bs->rx_max)) + 1;
1421 /* .25 second delay */
1422 ch->ch_close_delay = 250;
1425 * Set queue water marks, interrupt mask,
1426 * and general tty parameters.
1428 tlw = ch->ch_tsize >= 2000 ? ((ch->ch_tsize * 5) / 8) :
1432 dgap_cmdw(ch, STLOW, tlw, 0);
1434 dgap_cmdw(ch, SRLOW, ch->ch_rsize / 2, 0);
1436 dgap_cmdw(ch, SRHIGH, 7 * ch->ch_rsize / 8, 0);
1438 ch->ch_mistat = readb(&(ch->ch_bs->m_stat));
1440 init_waitqueue_head(&ch->ch_flags_wait);
1441 init_waitqueue_head(&ch->ch_tun.un_flags_wait);
1442 init_waitqueue_head(&ch->ch_pun.un_flags_wait);
1443 init_waitqueue_head(&ch->ch_sniff_wait);
1445 /* Turn on all modem interrupts for now */
1446 modem = (DM_CD | DM_DSR | DM_CTS | DM_RI);
1447 writeb(modem, &(ch->ch_bs->m_int));
1450 * Set edelay to 0 if interrupts are turned on,
1451 * otherwise set edelay to the usual 100.
1454 writew(0, &(ch->ch_bs->edelay));
1456 writew(100, &(ch->ch_bs->edelay));
1458 writeb(1, &(ch->ch_bs->idata));
1467 * Uninitialize the TTY portion of this driver. Free all memory and
1470 static void dgap_tty_uninit(struct board_t *brd)
1475 if (brd->dgap_Major_Serial_Registered) {
1476 dgap_BoardsByMajor[brd->SerialDriver->major] = NULL;
1477 brd->dgap_Serial_Major = 0;
1478 for (i = 0; i < brd->nasync; i++) {
1479 tty_port_destroy(&brd->SerialPorts[i]);
1480 dev = brd->channels[i]->ch_tun.un_sysfs;
1481 dgap_remove_tty_sysfs(dev);
1482 tty_unregister_device(brd->SerialDriver, i);
1484 tty_unregister_driver(brd->SerialDriver);
1485 kfree(brd->SerialDriver->ttys);
1486 brd->SerialDriver->ttys = NULL;
1487 put_tty_driver(brd->SerialDriver);
1488 kfree(brd->SerialPorts);
1489 brd->dgap_Major_Serial_Registered = FALSE;
1492 if (brd->dgap_Major_TransparentPrint_Registered) {
1493 dgap_BoardsByMajor[brd->PrintDriver->major] = NULL;
1494 brd->dgap_TransparentPrint_Major = 0;
1495 for (i = 0; i < brd->nasync; i++) {
1496 tty_port_destroy(&brd->PrinterPorts[i]);
1497 dev = brd->channels[i]->ch_pun.un_sysfs;
1498 dgap_remove_tty_sysfs(dev);
1499 tty_unregister_device(brd->PrintDriver, i);
1501 tty_unregister_driver(brd->PrintDriver);
1502 kfree(brd->PrintDriver->ttys);
1503 brd->PrintDriver->ttys = NULL;
1504 put_tty_driver(brd->PrintDriver);
1505 kfree(brd->PrinterPorts);
1506 brd->dgap_Major_TransparentPrint_Registered = FALSE;
1510 #define TMPBUFLEN (1024)
1512 * dgap_sniff - Dump data out to the "sniff" buffer if the
1513 * proc sniff file is opened...
1515 static void dgap_sniff_nowait_nolock(struct channel_t *ch, u8 *text,
1524 char tmpbuf[TMPBUFLEN];
1528 /* Leave if sniff not open */
1529 if (!(ch->ch_sniff_flags & SNIFF_OPEN))
1532 do_gettimeofday(&tv);
1534 /* Create our header for data dump */
1535 p += sprintf(p, "<%ld %ld><%s><", tv.tv_sec, tv.tv_usec, text);
1536 tmpbuflen = p - tmpbuf;
1541 for (i = 0; i < len && tmpbuflen < (TMPBUFLEN - 4); i++) {
1542 p += sprintf(p, "%02x ", *buf);
1544 tmpbuflen = p - tmpbuf;
1547 if (tmpbuflen < (TMPBUFLEN - 4)) {
1549 p += sprintf(p - 1, "%s\n", ">");
1551 p += sprintf(p, "%s\n", ">");
1557 nbuf = strlen(tmpbuf);
1561 * Loop while data remains.
1563 while (nbuf > 0 && ch->ch_sniff_buf) {
1565 * Determine the amount of available space left in the
1566 * buffer. If there's none, wait until some appears.
1568 n = (ch->ch_sniff_out - ch->ch_sniff_in - 1) &
1572 * If there is no space left to write to in our sniff
1573 * buffer, we have no choice but to drop the data.
1574 * We *cannot* sleep here waiting for space, because
1575 * this function was probably called by the
1576 * interrupt/timer routines!
1582 * Copy as much data as will fit.
1588 r = SNIFF_MAX - ch->ch_sniff_in;
1591 memcpy(ch->ch_sniff_buf +
1592 ch->ch_sniff_in, p, r);
1595 ch->ch_sniff_in = 0;
1600 memcpy(ch->ch_sniff_buf + ch->ch_sniff_in, p, n);
1602 ch->ch_sniff_in += n;
1607 * Wakeup any thread waiting for data
1609 if (ch->ch_sniff_flags & SNIFF_WAIT_DATA) {
1610 ch->ch_sniff_flags &= ~SNIFF_WAIT_DATA;
1611 wake_up_interruptible(&ch->ch_sniff_wait);
1616 * If the user sent us too much data to push into our tmpbuf,
1617 * we need to keep looping around on all the data.
1619 if (too_much_data) {
1624 } while (too_much_data);
1627 /*=======================================================================
1629 * dgap_input - Process received data.
1631 * ch - Pointer to channel structure.
1633 *=======================================================================*/
1635 static void dgap_input(struct channel_t *ch)
1639 struct tty_struct *tp;
1640 struct tty_ldisc *ld;
1654 if (!ch || ch->magic != DGAP_CHANNEL_MAGIC)
1657 tp = ch->ch_tun.un_tty;
1664 if (!bd || bd->magic != DGAP_BOARD_MAGIC)
1667 spin_lock_irqsave(&bd->bd_lock, lock_flags);
1668 spin_lock_irqsave(&ch->ch_lock, lock_flags2);
1671 * Figure the number of characters in the buffer.
1672 * Exit immediately if none.
1675 rmask = ch->ch_rsize - 1;
1677 head = readw(&(bs->rx_head));
1679 tail = readw(&(bs->rx_tail));
1682 data_len = (head - tail) & rmask;
1684 if (data_len == 0) {
1685 writeb(1, &(bs->idata));
1686 spin_unlock_irqrestore(&ch->ch_lock, lock_flags2);
1687 spin_unlock_irqrestore(&bd->bd_lock, lock_flags);
1692 * If the device is not open, or CREAD is off, flush
1693 * input data and return immediately.
1695 if ((bd->state != BOARD_READY) || !tp ||
1696 (tp->magic != TTY_MAGIC) ||
1697 !(ch->ch_tun.un_flags & UN_ISOPEN) ||
1698 !(tp->termios.c_cflag & CREAD) ||
1699 (ch->ch_tun.un_flags & UN_CLOSING)) {
1701 writew(head, &(bs->rx_tail));
1702 writeb(1, &(bs->idata));
1703 spin_unlock_irqrestore(&ch->ch_lock, lock_flags2);
1704 spin_unlock_irqrestore(&bd->bd_lock, lock_flags);
1709 * If we are throttled, simply don't read any data.
1711 if (ch->ch_flags & CH_RXBLOCK) {
1712 writeb(1, &(bs->idata));
1713 spin_unlock_irqrestore(&ch->ch_lock, lock_flags2);
1714 spin_unlock_irqrestore(&bd->bd_lock, lock_flags);
1721 tmpchar = readb(&(bs->orun));
1723 ch->ch_err_overrun++;
1724 writeb(0, &(bs->orun));
1727 /* Decide how much data we can send into the tty layer */
1728 flip_len = TTY_FLIPBUF_SIZE;
1730 /* Chop down the length, if needed */
1731 len = min(data_len, flip_len);
1732 len = min(len, (N_TTY_BUF_SIZE - 1));
1734 ld = tty_ldisc_ref(tp);
1736 #ifdef TTY_DONT_FLIP
1738 * If the DONT_FLIP flag is on, don't flush our buffer, and act
1739 * like the ld doesn't have any space to put the data right now.
1741 if (test_bit(TTY_DONT_FLIP, &tp->flags))
1746 * If we were unable to get a reference to the ld,
1747 * don't flush our buffer, and act like the ld doesn't
1748 * have any space to put the data right now.
1754 * If ld doesn't have a pointer to a receive_buf function,
1755 * flush the data, then act like the ld doesn't have any
1756 * space to put the data right now.
1758 if (!ld->ops->receive_buf) {
1759 writew(head, &(bs->rx_tail));
1765 writeb(1, &(bs->idata));
1766 spin_unlock_irqrestore(&ch->ch_lock, lock_flags2);
1767 spin_unlock_irqrestore(&bd->bd_lock, lock_flags);
1769 tty_ldisc_deref(ld);
1773 buf = ch->ch_bd->flipbuf;
1777 * n now contains the most amount of data we can copy,
1778 * bounded either by our buffer size or the amount
1779 * of data the card actually has pending...
1783 s = ((head >= tail) ? head : ch->ch_rsize) - tail;
1789 memcpy_fromio(buf, (char *) ch->ch_raddr + tail, s);
1790 dgap_sniff_nowait_nolock(ch, "USER READ", buf, s);
1796 /* Flip queue if needed */
1800 writew(tail, &(bs->rx_tail));
1801 writeb(1, &(bs->idata));
1802 ch->ch_rxcount += len;
1805 * If we are completely raw, we don't need to go through a lot
1806 * of the tty layers that exist.
1807 * In this case, we take the shortest and fastest route we
1808 * can to relay the data to the user.
1810 * On the other hand, if we are not raw, we need to go through
1811 * the tty layer, which has its API more well defined.
1813 if (I_PARMRK(tp) || I_BRKINT(tp) || I_INPCK(tp)) {
1814 dgap_parity_scan(ch, ch->ch_bd->flipbuf,
1815 ch->ch_bd->flipflagbuf, &len);
1817 len = tty_buffer_request_room(tp->port, len);
1818 tty_insert_flip_string_flags(tp->port, ch->ch_bd->flipbuf,
1819 ch->ch_bd->flipflagbuf, len);
1821 len = tty_buffer_request_room(tp->port, len);
1822 tty_insert_flip_string(tp->port, ch->ch_bd->flipbuf, len);
1825 spin_unlock_irqrestore(&ch->ch_lock, lock_flags2);
1826 spin_unlock_irqrestore(&bd->bd_lock, lock_flags);
1828 /* Tell the tty layer its okay to "eat" the data now */
1829 tty_flip_buffer_push(tp->port);
1832 tty_ldisc_deref(ld);
1836 /************************************************************************
1837 * Determines when CARRIER changes state and takes appropriate
1839 ************************************************************************/
1840 static void dgap_carrier(struct channel_t *ch)
1844 int virt_carrier = 0;
1845 int phys_carrier = 0;
1847 if (!ch || ch->magic != DGAP_CHANNEL_MAGIC)
1852 if (!bd || bd->magic != DGAP_BOARD_MAGIC)
1855 /* Make sure altpin is always set correctly */
1856 if (ch->ch_digi.digi_flags & DIGI_ALTPIN) {
1860 ch->ch_dsr = DM_DSR;
1864 if (ch->ch_mistat & D_CD(ch))
1867 if (ch->ch_digi.digi_flags & DIGI_FORCEDCD)
1870 if (ch->ch_c_cflag & CLOCAL)
1874 * Test for a VIRTUAL carrier transition to HIGH.
1876 if (((ch->ch_flags & CH_FCAR) == 0) && (virt_carrier == 1)) {
1879 * When carrier rises, wake any threads waiting
1880 * for carrier in the open routine.
1883 if (waitqueue_active(&(ch->ch_flags_wait)))
1884 wake_up_interruptible(&ch->ch_flags_wait);
1888 * Test for a PHYSICAL carrier transition to HIGH.
1890 if (((ch->ch_flags & CH_CD) == 0) && (phys_carrier == 1)) {
1893 * When carrier rises, wake any threads waiting
1894 * for carrier in the open routine.
1897 if (waitqueue_active(&(ch->ch_flags_wait)))
1898 wake_up_interruptible(&ch->ch_flags_wait);
1902 * Test for a PHYSICAL transition to low, so long as we aren't
1903 * currently ignoring physical transitions (which is what "virtual
1904 * carrier" indicates).
1906 * The transition of the virtual carrier to low really doesn't
1907 * matter... it really only means "ignore carrier state", not
1908 * "make pretend that carrier is there".
1910 if ((virt_carrier == 0) &&
1911 ((ch->ch_flags & CH_CD) != 0) &&
1912 (phys_carrier == 0)) {
1915 * When carrier drops:
1917 * Drop carrier on all open units.
1919 * Flush queues, waking up any task waiting in the
1922 * Send a hangup to the control terminal.
1924 * Enable all select calls.
1926 if (waitqueue_active(&(ch->ch_flags_wait)))
1927 wake_up_interruptible(&ch->ch_flags_wait);
1929 if (ch->ch_tun.un_open_count > 0)
1930 tty_hangup(ch->ch_tun.un_tty);
1932 if (ch->ch_pun.un_open_count > 0)
1933 tty_hangup(ch->ch_pun.un_tty);
1937 * Make sure that our cached values reflect the current reality.
1939 if (virt_carrier == 1)
1940 ch->ch_flags |= CH_FCAR;
1942 ch->ch_flags &= ~CH_FCAR;
1944 if (phys_carrier == 1)
1945 ch->ch_flags |= CH_CD;
1947 ch->ch_flags &= ~CH_CD;
1950 /************************************************************************
1952 * TTY Entry points and helper functions
1954 ************************************************************************/
1960 static int dgap_tty_open(struct tty_struct *tty, struct file *file)
1962 struct board_t *brd;
1963 struct channel_t *ch;
1975 major = MAJOR(tty_devnum(tty));
1976 minor = MINOR(tty_devnum(tty));
1981 /* Get board pointer from our array of majors we have allocated */
1982 brd = dgap_BoardsByMajor[major];
1987 * If board is not yet up to a state of READY, go to
1988 * sleep waiting for it to happen or they cancel the open.
1990 rc = wait_event_interruptible(brd->state_wait,
1991 (brd->state & BOARD_READY));
1996 spin_lock_irqsave(&brd->bd_lock, lock_flags);
1998 /* The wait above should guarantee this cannot happen */
1999 if (brd->state != BOARD_READY) {
2000 spin_unlock_irqrestore(&brd->bd_lock, lock_flags);
2004 /* If opened device is greater than our number of ports, bail. */
2005 if (MINOR(tty_devnum(tty)) > brd->nasync) {
2006 spin_unlock_irqrestore(&brd->bd_lock, lock_flags);
2010 ch = brd->channels[minor];
2012 spin_unlock_irqrestore(&brd->bd_lock, lock_flags);
2016 /* Grab channel lock */
2017 spin_lock_irqsave(&ch->ch_lock, lock_flags2);
2019 /* Figure out our type */
2020 if (major == brd->dgap_Serial_Major) {
2021 un = &brd->channels[minor]->ch_tun;
2022 un->un_type = DGAP_SERIAL;
2023 } else if (major == brd->dgap_TransparentPrint_Major) {
2024 un = &brd->channels[minor]->ch_pun;
2025 un->un_type = DGAP_PRINT;
2027 spin_unlock_irqrestore(&ch->ch_lock, lock_flags2);
2028 spin_unlock_irqrestore(&brd->bd_lock, lock_flags);
2032 /* Store our unit into driver_data, so we always have it available. */
2033 tty->driver_data = un;
2036 * Error if channel info pointer is NULL.
2040 spin_unlock_irqrestore(&ch->ch_lock, lock_flags2);
2041 spin_unlock_irqrestore(&brd->bd_lock, lock_flags);
2048 if (!(un->un_flags & UN_ISOPEN)) {
2049 /* Store important variables. */
2052 /* Maybe do something here to the TTY struct as well? */
2056 * Initialize if neither terminal or printer is open.
2058 if (!((ch->ch_tun.un_flags | ch->ch_pun.un_flags) & UN_ISOPEN)) {
2064 * Flush input queue.
2066 head = readw(&(bs->rx_head));
2067 writew(head, &(bs->rx_tail));
2070 ch->pscan_state = 0;
2071 ch->pscan_savechar = 0;
2073 ch->ch_c_cflag = tty->termios.c_cflag;
2074 ch->ch_c_iflag = tty->termios.c_iflag;
2075 ch->ch_c_oflag = tty->termios.c_oflag;
2076 ch->ch_c_lflag = tty->termios.c_lflag;
2077 ch->ch_startc = tty->termios.c_cc[VSTART];
2078 ch->ch_stopc = tty->termios.c_cc[VSTOP];
2080 /* TODO: flush our TTY struct here? */
2085 * Run param in case we changed anything
2090 * follow protocol for opening port
2093 spin_unlock_irqrestore(&ch->ch_lock, lock_flags2);
2094 spin_unlock_irqrestore(&brd->bd_lock, lock_flags);
2096 rc = dgap_block_til_ready(tty, file, ch);
2101 /* No going back now, increment our unit and channel counters */
2102 spin_lock_irqsave(&ch->ch_lock, lock_flags);
2103 ch->ch_open_count++;
2104 un->un_open_count++;
2105 un->un_flags |= (UN_ISOPEN);
2106 spin_unlock_irqrestore(&ch->ch_lock, lock_flags);
2112 * dgap_block_til_ready()
2114 * Wait for DCD, if needed.
2116 static int dgap_block_til_ready(struct tty_struct *tty, struct file *file,
2117 struct channel_t *ch)
2120 struct un_t *un = NULL;
2123 int sleep_on_un_flags = 0;
2125 if (!tty || tty->magic != TTY_MAGIC || !file || !ch ||
2126 ch->magic != DGAP_CHANNEL_MAGIC)
2129 un = tty->driver_data;
2130 if (!un || un->magic != DGAP_UNIT_MAGIC)
2133 spin_lock_irqsave(&ch->ch_lock, lock_flags);
2140 sleep_on_un_flags = 0;
2143 * If board has failed somehow during our sleep,
2146 if (ch->ch_bd->state == BOARD_FAILED) {
2151 /* If tty was hung up, break out of loop and set error. */
2152 if (tty_hung_up_p(file)) {
2158 * If either unit is in the middle of the fragile part of close,
2159 * we just cannot touch the channel safely.
2160 * Go back to sleep, knowing that when the channel can be
2161 * touched safely, the close routine will signal the
2162 * ch_wait_flags to wake us back up.
2164 if (!((ch->ch_tun.un_flags | ch->ch_pun.un_flags) &
2168 * Our conditions to leave cleanly and happily:
2169 * 1) NONBLOCKING on the tty is set.
2171 * 3) DCD (fake or real) is active.
2174 if (file->f_flags & O_NONBLOCK)
2177 if (tty->flags & (1 << TTY_IO_ERROR))
2180 if (ch->ch_flags & CH_CD)
2183 if (ch->ch_flags & CH_FCAR)
2186 sleep_on_un_flags = 1;
2190 * If there is a signal pending, the user probably
2191 * interrupted (ctrl-c) us.
2192 * Leave loop with error set.
2194 if (signal_pending(current)) {
2195 retval = -ERESTARTSYS;
2200 * Store the flags before we let go of channel lock
2202 if (sleep_on_un_flags)
2203 old_flags = ch->ch_tun.un_flags | ch->ch_pun.un_flags;
2205 old_flags = ch->ch_flags;
2208 * Let go of channel lock before calling schedule.
2209 * Our poller will get any FEP events and wake us up when DCD
2210 * eventually goes active.
2213 spin_unlock_irqrestore(&ch->ch_lock, lock_flags);
2216 * Wait for something in the flags to change
2217 * from the current value.
2219 if (sleep_on_un_flags) {
2220 retval = wait_event_interruptible(un->un_flags_wait,
2221 (old_flags != (ch->ch_tun.un_flags |
2222 ch->ch_pun.un_flags)));
2224 retval = wait_event_interruptible(ch->ch_flags_wait,
2225 (old_flags != ch->ch_flags));
2229 * We got woken up for some reason.
2230 * Before looping around, grab our channel lock.
2232 spin_lock_irqsave(&ch->ch_lock, lock_flags);
2237 spin_unlock_irqrestore(&ch->ch_lock, lock_flags);
2248 * Hangup the port. Like a close, but don't wait for output to drain.
2250 static void dgap_tty_hangup(struct tty_struct *tty)
2253 struct channel_t *ch;
2256 if (!tty || tty->magic != TTY_MAGIC)
2259 un = tty->driver_data;
2260 if (!un || un->magic != DGAP_UNIT_MAGIC)
2264 if (!ch || ch->magic != DGAP_CHANNEL_MAGIC)
2268 if (!bd || bd->magic != DGAP_BOARD_MAGIC)
2271 /* flush the transmit queues */
2272 dgap_tty_flush_buffer(tty);
2280 static void dgap_tty_close(struct tty_struct *tty, struct file *file)
2282 struct ktermios *ts;
2284 struct channel_t *ch;
2289 if (!tty || tty->magic != TTY_MAGIC)
2292 un = tty->driver_data;
2293 if (!un || un->magic != DGAP_UNIT_MAGIC)
2297 if (!ch || ch->magic != DGAP_CHANNEL_MAGIC)
2301 if (!bd || bd->magic != DGAP_BOARD_MAGIC)
2306 spin_lock_irqsave(&ch->ch_lock, lock_flags);
2309 * Determine if this is the last close or not - and if we agree about
2310 * which type of close it is with the Line Discipline
2312 if ((tty->count == 1) && (un->un_open_count != 1)) {
2314 * Uh, oh. tty->count is 1, which means that the tty
2315 * structure will be freed. un_open_count should always
2316 * be one in these conditions. If it's greater than
2317 * one, we've got real problems, since it means the
2318 * serial port won't be shutdown.
2320 un->un_open_count = 1;
2323 if (--un->un_open_count < 0)
2324 un->un_open_count = 0;
2326 ch->ch_open_count--;
2328 if (ch->ch_open_count && un->un_open_count) {
2329 spin_unlock_irqrestore(&ch->ch_lock, lock_flags);
2333 /* OK, its the last close on the unit */
2335 un->un_flags |= UN_CLOSING;
2340 * Only officially close channel if count is 0 and
2341 * DIGI_PRINTER bit is not set.
2343 if ((ch->ch_open_count == 0) &&
2344 !(ch->ch_digi.digi_flags & DIGI_PRINTER)) {
2346 ch->ch_flags &= ~(CH_RXBLOCK);
2348 spin_unlock_irqrestore(&ch->ch_lock, lock_flags);
2350 /* wait for output to drain */
2351 /* This will also return if we take an interrupt */
2353 rc = dgap_wait_for_drain(tty);
2355 dgap_tty_flush_buffer(tty);
2356 tty_ldisc_flush(tty);
2358 spin_lock_irqsave(&ch->ch_lock, lock_flags);
2363 * If we have HUPCL set, lower DTR and RTS
2365 if (ch->ch_c_cflag & HUPCL) {
2366 ch->ch_mostat &= ~(D_RTS(ch)|D_DTR(ch));
2367 dgap_cmdb(ch, SMODEM, 0, D_DTR(ch)|D_RTS(ch), 0);
2370 * Go to sleep to ensure RTS/DTR
2371 * have been dropped for modems to see it.
2373 if (ch->ch_close_delay) {
2374 spin_unlock_irqrestore(&ch->ch_lock,
2376 dgap_ms_sleep(ch->ch_close_delay);
2377 spin_lock_irqsave(&ch->ch_lock, lock_flags);
2381 ch->pscan_state = 0;
2382 ch->pscan_savechar = 0;
2383 ch->ch_baud_info = 0;
2388 * turn off print device when closing print device.
2390 if ((un->un_type == DGAP_PRINT) && (ch->ch_flags & CH_PRON)) {
2391 dgap_wmove(ch, ch->ch_digi.digi_offstr,
2392 (int) ch->ch_digi.digi_offlen);
2393 ch->ch_flags &= ~CH_PRON;
2397 un->un_flags &= ~(UN_ISOPEN | UN_CLOSING);
2398 tty->driver_data = NULL;
2400 wake_up_interruptible(&ch->ch_flags_wait);
2401 wake_up_interruptible(&un->un_flags_wait);
2403 spin_unlock_irqrestore(&ch->ch_lock, lock_flags);
2407 * dgap_tty_chars_in_buffer()
2409 * Return number of characters that have not been transmitted yet.
2411 * This routine is used by the line discipline to determine if there
2412 * is data waiting to be transmitted/drained/flushed or not.
2414 static int dgap_tty_chars_in_buffer(struct tty_struct *tty)
2416 struct board_t *bd = NULL;
2417 struct channel_t *ch = NULL;
2418 struct un_t *un = NULL;
2419 struct bs_t *bs = NULL;
2422 u16 thead, ttail, tmask, chead, ctail;
2423 ulong lock_flags = 0;
2424 ulong lock_flags2 = 0;
2429 un = tty->driver_data;
2430 if (!un || un->magic != DGAP_UNIT_MAGIC)
2434 if (!ch || ch->magic != DGAP_CHANNEL_MAGIC)
2438 if (!bd || bd->magic != DGAP_BOARD_MAGIC)
2445 spin_lock_irqsave(&bd->bd_lock, lock_flags);
2446 spin_lock_irqsave(&ch->ch_lock, lock_flags2);
2448 tmask = (ch->ch_tsize - 1);
2450 /* Get Transmit queue pointers */
2451 thead = readw(&(bs->tx_head)) & tmask;
2452 ttail = readw(&(bs->tx_tail)) & tmask;
2454 /* Get tbusy flag */
2455 tbusy = readb(&(bs->tbusy));
2457 /* Get Command queue pointers */
2458 chead = readw(&(ch->ch_cm->cm_head));
2459 ctail = readw(&(ch->ch_cm->cm_tail));
2461 spin_unlock_irqrestore(&ch->ch_lock, lock_flags2);
2462 spin_unlock_irqrestore(&bd->bd_lock, lock_flags);
2465 * The only way we know for sure if there is no pending
2466 * data left to be transferred, is if:
2467 * 1) Transmit head and tail are equal (empty).
2468 * 2) Command queue head and tail are equal (empty).
2469 * 3) The "TBUSY" flag is 0. (Transmitter not busy).
2472 if ((ttail == thead) && (tbusy == 0) && (chead == ctail)) {
2476 chars = thead - ttail;
2478 chars = thead - ttail + ch->ch_tsize;
2480 * Fudge factor here.
2481 * If chars is zero, we know that the command queue had
2482 * something in it or tbusy was set. Because we cannot
2483 * be sure if there is still some data to be transmitted,
2484 * lets lie, and tell ld we have 1 byte left.
2488 * If TBUSY is still set, and our tx buffers are empty,
2489 * force the firmware to send me another wakeup after
2490 * TBUSY has been cleared.
2493 spin_lock_irqsave(&ch->ch_lock, lock_flags);
2494 un->un_flags |= UN_EMPTY;
2495 writeb(1, &(bs->iempty));
2496 spin_unlock_irqrestore(&ch->ch_lock,
2506 static int dgap_wait_for_drain(struct tty_struct *tty)
2508 struct channel_t *ch;
2513 ulong lock_flags = 0;
2515 if (!tty || tty->magic != TTY_MAGIC)
2518 un = tty->driver_data;
2519 if (!un || un->magic != DGAP_UNIT_MAGIC)
2523 if (!ch || ch->magic != DGAP_CHANNEL_MAGIC)
2532 /* Loop until data is drained */
2533 while (count != 0) {
2535 count = dgap_tty_chars_in_buffer(tty);
2540 /* Set flag waiting for drain */
2541 spin_lock_irqsave(&ch->ch_lock, lock_flags);
2542 un->un_flags |= UN_EMPTY;
2543 writeb(1, &(bs->iempty));
2544 spin_unlock_irqrestore(&ch->ch_lock, lock_flags);
2546 /* Go to sleep till we get woken up */
2547 ret = wait_event_interruptible(un->un_flags_wait,
2548 ((un->un_flags & UN_EMPTY) == 0));
2549 /* If ret is non-zero, user ctrl-c'ed us */
2554 spin_lock_irqsave(&ch->ch_lock, lock_flags);
2555 un->un_flags &= ~(UN_EMPTY);
2556 spin_unlock_irqrestore(&ch->ch_lock, lock_flags);
2564 * Reduces bytes_available to the max number of characters
2565 * that can be sent currently given the maxcps value, and
2566 * returns the new bytes_available. This only affects printer
2569 static int dgap_maxcps_room(struct tty_struct *tty, int bytes_available)
2571 struct channel_t *ch = NULL;
2572 struct un_t *un = NULL;
2575 return bytes_available;
2577 un = tty->driver_data;
2578 if (!un || un->magic != DGAP_UNIT_MAGIC)
2579 return bytes_available;
2582 if (!ch || ch->magic != DGAP_CHANNEL_MAGIC)
2583 return bytes_available;
2586 * If its not the Transparent print device, return
2587 * the full data amount.
2589 if (un->un_type != DGAP_PRINT)
2590 return bytes_available;
2592 if (ch->ch_digi.digi_maxcps > 0 && ch->ch_digi.digi_bufsize > 0) {
2594 unsigned long current_time = jiffies;
2595 unsigned long buffer_time = current_time +
2596 (HZ * ch->ch_digi.digi_bufsize) /
2597 ch->ch_digi.digi_maxcps;
2599 if (ch->ch_cpstime < current_time) {
2600 /* buffer is empty */
2601 ch->ch_cpstime = current_time; /* reset ch_cpstime */
2602 cps_limit = ch->ch_digi.digi_bufsize;
2603 } else if (ch->ch_cpstime < buffer_time) {
2604 /* still room in the buffer */
2605 cps_limit = ((buffer_time - ch->ch_cpstime) *
2606 ch->ch_digi.digi_maxcps) / HZ;
2608 /* no room in the buffer */
2612 bytes_available = min(cps_limit, bytes_available);
2615 return bytes_available;
2618 static inline void dgap_set_firmware_event(struct un_t *un, unsigned int event)
2620 struct channel_t *ch = NULL;
2621 struct bs_t *bs = NULL;
2623 if (!un || un->magic != DGAP_UNIT_MAGIC)
2626 if (!ch || ch->magic != DGAP_CHANNEL_MAGIC)
2632 if ((event & UN_LOW) != 0) {
2633 if ((un->un_flags & UN_LOW) == 0) {
2634 un->un_flags |= UN_LOW;
2635 writeb(1, &(bs->ilow));
2638 if ((event & UN_LOW) != 0) {
2639 if ((un->un_flags & UN_EMPTY) == 0) {
2640 un->un_flags |= UN_EMPTY;
2641 writeb(1, &(bs->iempty));
2647 * dgap_tty_write_room()
2649 * Return space available in Tx buffer
2651 static int dgap_tty_write_room(struct tty_struct *tty)
2653 struct channel_t *ch = NULL;
2654 struct un_t *un = NULL;
2655 struct bs_t *bs = NULL;
2656 u16 head, tail, tmask;
2658 ulong lock_flags = 0;
2663 un = tty->driver_data;
2664 if (!un || un->magic != DGAP_UNIT_MAGIC)
2668 if (!ch || ch->magic != DGAP_CHANNEL_MAGIC)
2675 spin_lock_irqsave(&ch->ch_lock, lock_flags);
2677 tmask = ch->ch_tsize - 1;
2678 head = readw(&(bs->tx_head)) & tmask;
2679 tail = readw(&(bs->tx_tail)) & tmask;
2681 ret = tail - head - 1;
2683 ret += ch->ch_tsize;
2685 /* Limit printer to maxcps */
2686 ret = dgap_maxcps_room(tty, ret);
2689 * If we are printer device, leave space for
2690 * possibly both the on and off strings.
2692 if (un->un_type == DGAP_PRINT) {
2693 if (!(ch->ch_flags & CH_PRON))
2694 ret -= ch->ch_digi.digi_onlen;
2695 ret -= ch->ch_digi.digi_offlen;
2697 if (ch->ch_flags & CH_PRON)
2698 ret -= ch->ch_digi.digi_offlen;
2705 * Schedule FEP to wake us up if needed.
2707 * TODO: This might be overkill...
2708 * Do we really need to schedule callbacks from the FEP
2709 * in every case? Can we get smarter based on ret?
2711 dgap_set_firmware_event(un, UN_LOW | UN_EMPTY);
2712 spin_unlock_irqrestore(&ch->ch_lock, lock_flags);
2718 * dgap_tty_put_char()
2720 * Put a character into ch->ch_buf
2722 * - used by the line discipline for OPOST processing
2724 static int dgap_tty_put_char(struct tty_struct *tty, unsigned char c)
2727 * Simply call tty_write.
2729 dgap_tty_write(tty, &c, 1);
2736 * Take data from the user or kernel and send it out to the FEP.
2737 * In here exists all the Transparent Print magic as well.
2739 static int dgap_tty_write(struct tty_struct *tty, const unsigned char *buf,
2742 struct channel_t *ch = NULL;
2743 struct un_t *un = NULL;
2744 struct bs_t *bs = NULL;
2746 u16 head, tail, tmask, remain;
2747 int bufcount = 0, n = 0;
2754 un = tty->driver_data;
2755 if (!un || un->magic != DGAP_UNIT_MAGIC)
2759 if (!ch || ch->magic != DGAP_CHANNEL_MAGIC)
2770 * Store original amount of characters passed in.
2771 * This helps to figure out if we should ask the FEP
2772 * to send us an event when it has more space available.
2776 spin_lock_irqsave(&ch->ch_lock, lock_flags);
2778 /* Get our space available for the channel from the board */
2779 tmask = ch->ch_tsize - 1;
2780 head = readw(&(bs->tx_head)) & tmask;
2781 tail = readw(&(bs->tx_tail)) & tmask;
2783 bufcount = tail - head - 1;
2785 bufcount += ch->ch_tsize;
2788 * Limit printer output to maxcps overall, with bursts allowed
2789 * up to bufsize characters.
2791 bufcount = dgap_maxcps_room(tty, bufcount);
2794 * Take minimum of what the user wants to send, and the
2795 * space available in the FEP buffer.
2797 count = min(count, bufcount);
2800 * Bail if no space left.
2803 dgap_set_firmware_event(un, UN_LOW | UN_EMPTY);
2804 spin_unlock_irqrestore(&ch->ch_lock, lock_flags);
2809 * Output the printer ON string, if we are in terminal mode, but
2810 * need to be in printer mode.
2812 if ((un->un_type == DGAP_PRINT) && !(ch->ch_flags & CH_PRON)) {
2813 dgap_wmove(ch, ch->ch_digi.digi_onstr,
2814 (int) ch->ch_digi.digi_onlen);
2815 head = readw(&(bs->tx_head)) & tmask;
2816 ch->ch_flags |= CH_PRON;
2820 * On the other hand, output the printer OFF string, if we are
2821 * currently in printer mode, but need to output to the terminal.
2823 if ((un->un_type != DGAP_PRINT) && (ch->ch_flags & CH_PRON)) {
2824 dgap_wmove(ch, ch->ch_digi.digi_offstr,
2825 (int) ch->ch_digi.digi_offlen);
2826 head = readw(&(bs->tx_head)) & tmask;
2827 ch->ch_flags &= ~CH_PRON;
2831 * If there is nothing left to copy, or
2832 * I can't handle any more data, leave.
2835 dgap_set_firmware_event(un, UN_LOW | UN_EMPTY);
2836 spin_unlock_irqrestore(&ch->ch_lock, lock_flags);
2843 * If the write wraps over the top of the circular buffer,
2844 * move the portion up to the wrap point, and reset the
2845 * pointers to the bottom.
2847 remain = ch->ch_tstart + ch->ch_tsize - head;
2851 vaddr = ch->ch_taddr + head;
2853 memcpy_toio(vaddr, (u8 *) buf, remain);
2854 dgap_sniff_nowait_nolock(ch, "USER WRITE", (u8 *) buf,
2857 head = ch->ch_tstart;
2864 * Move rest of data.
2866 vaddr = ch->ch_taddr + head;
2869 memcpy_toio(vaddr, (u8 *) buf, remain);
2870 dgap_sniff_nowait_nolock(ch, "USER WRITE", (u8 *)buf,
2878 ch->ch_txcount += count;
2880 writew(head, &(bs->tx_head));
2883 dgap_set_firmware_event(un, UN_LOW | UN_EMPTY);
2886 * If this is the print device, and the
2887 * printer is still on, we need to turn it
2888 * off before going idle. If the buffer is
2889 * non-empty, wait until it goes empty.
2890 * Otherwise turn it off right now.
2892 if ((un->un_type == DGAP_PRINT) && (ch->ch_flags & CH_PRON)) {
2893 tail = readw(&(bs->tx_tail)) & tmask;
2896 un->un_flags |= UN_EMPTY;
2897 writeb(1, &(bs->iempty));
2899 dgap_wmove(ch, ch->ch_digi.digi_offstr,
2900 (int) ch->ch_digi.digi_offlen);
2901 head = readw(&(bs->tx_head)) & tmask;
2902 ch->ch_flags &= ~CH_PRON;
2906 /* Update printer buffer empty time. */
2907 if ((un->un_type == DGAP_PRINT) && (ch->ch_digi.digi_maxcps > 0)
2908 && (ch->ch_digi.digi_bufsize > 0)) {
2909 ch->ch_cpstime += (HZ * count) / ch->ch_digi.digi_maxcps;
2912 spin_unlock_irqrestore(&ch->ch_lock, lock_flags);
2918 * Return modem signals to ld.
2920 static int dgap_tty_tiocmget(struct tty_struct *tty)
2922 struct channel_t *ch;
2928 if (!tty || tty->magic != TTY_MAGIC)
2931 un = tty->driver_data;
2932 if (!un || un->magic != DGAP_UNIT_MAGIC)
2936 if (!ch || ch->magic != DGAP_CHANNEL_MAGIC)
2939 spin_lock_irqsave(&ch->ch_lock, lock_flags);
2941 mstat = readb(&(ch->ch_bs->m_stat));
2942 /* Append any outbound signals that might be pending... */
2943 mstat |= ch->ch_mostat;
2945 spin_unlock_irqrestore(&ch->ch_lock, lock_flags);
2949 if (mstat & D_DTR(ch))
2950 result |= TIOCM_DTR;
2951 if (mstat & D_RTS(ch))
2952 result |= TIOCM_RTS;
2953 if (mstat & D_CTS(ch))
2954 result |= TIOCM_CTS;
2955 if (mstat & D_DSR(ch))
2956 result |= TIOCM_DSR;
2957 if (mstat & D_RI(ch))
2959 if (mstat & D_CD(ch))
2966 * dgap_tty_tiocmset()
2968 * Set modem signals, called by ld.
2970 static int dgap_tty_tiocmset(struct tty_struct *tty,
2971 unsigned int set, unsigned int clear)
2974 struct channel_t *ch;
2980 if (!tty || tty->magic != TTY_MAGIC)
2983 un = tty->driver_data;
2984 if (!un || un->magic != DGAP_UNIT_MAGIC)
2988 if (!ch || ch->magic != DGAP_CHANNEL_MAGIC)
2992 if (!bd || bd->magic != DGAP_BOARD_MAGIC)
2995 spin_lock_irqsave(&bd->bd_lock, lock_flags);
2996 spin_lock_irqsave(&ch->ch_lock, lock_flags2);
2998 if (set & TIOCM_RTS) {
2999 ch->ch_mforce |= D_RTS(ch);
3000 ch->ch_mval |= D_RTS(ch);
3003 if (set & TIOCM_DTR) {
3004 ch->ch_mforce |= D_DTR(ch);
3005 ch->ch_mval |= D_DTR(ch);
3008 if (clear & TIOCM_RTS) {
3009 ch->ch_mforce |= D_RTS(ch);
3010 ch->ch_mval &= ~(D_RTS(ch));
3013 if (clear & TIOCM_DTR) {
3014 ch->ch_mforce |= D_DTR(ch);
3015 ch->ch_mval &= ~(D_DTR(ch));
3020 spin_unlock_irqrestore(&ch->ch_lock, lock_flags2);
3021 spin_unlock_irqrestore(&bd->bd_lock, lock_flags);
3027 * dgap_tty_send_break()
3029 * Send a Break, called by ld.
3031 static int dgap_tty_send_break(struct tty_struct *tty, int msec)
3034 struct channel_t *ch;
3040 if (!tty || tty->magic != TTY_MAGIC)
3043 un = tty->driver_data;
3044 if (!un || un->magic != DGAP_UNIT_MAGIC)
3048 if (!ch || ch->magic != DGAP_CHANNEL_MAGIC)
3052 if (!bd || bd->magic != DGAP_BOARD_MAGIC)
3067 spin_lock_irqsave(&bd->bd_lock, lock_flags);
3068 spin_lock_irqsave(&ch->ch_lock, lock_flags2);
3070 dgap_cmdw(ch, SBREAK, (u16) SBREAK_TIME, 0);
3072 dgap_cmdw(ch, SBREAK, (u16) msec, 0);
3074 spin_unlock_irqrestore(&ch->ch_lock, lock_flags2);
3075 spin_unlock_irqrestore(&bd->bd_lock, lock_flags);
3081 * dgap_tty_wait_until_sent()
3083 * wait until data has been transmitted, called by ld.
3085 static void dgap_tty_wait_until_sent(struct tty_struct *tty, int timeout)
3087 dgap_wait_for_drain(tty);
3093 * send a high priority character, called by ld.
3095 static void dgap_tty_send_xchar(struct tty_struct *tty, char c)
3098 struct channel_t *ch;
3103 if (!tty || tty->magic != TTY_MAGIC)
3106 un = tty->driver_data;
3107 if (!un || un->magic != DGAP_UNIT_MAGIC)
3111 if (!ch || ch->magic != DGAP_CHANNEL_MAGIC)
3115 if (!bd || bd->magic != DGAP_BOARD_MAGIC)
3118 spin_lock_irqsave(&bd->bd_lock, lock_flags);
3119 spin_lock_irqsave(&ch->ch_lock, lock_flags2);
3122 * This is technically what we should do.
3123 * However, the NIST tests specifically want
3124 * to see each XON or XOFF character that it
3125 * sends, so lets just send each character
3129 if (c == STOP_CHAR(tty))
3130 dgap_cmdw(ch, RPAUSE, 0, 0);
3131 else if (c == START_CHAR(tty))
3132 dgap_cmdw(ch, RRESUME, 0, 0);
3134 dgap_wmove(ch, &c, 1);
3136 dgap_wmove(ch, &c, 1);
3139 spin_unlock_irqrestore(&ch->ch_lock, lock_flags2);
3140 spin_unlock_irqrestore(&bd->bd_lock, lock_flags);
3146 * Return modem signals to ld.
3148 static int dgap_get_modem_info(struct channel_t *ch, unsigned int __user *value)
3155 if (!ch || ch->magic != DGAP_CHANNEL_MAGIC)
3158 spin_lock_irqsave(&ch->ch_lock, lock_flags);
3160 mstat = readb(&(ch->ch_bs->m_stat));
3161 /* Append any outbound signals that might be pending... */
3162 mstat |= ch->ch_mostat;
3164 spin_unlock_irqrestore(&ch->ch_lock, lock_flags);
3168 if (mstat & D_DTR(ch))
3169 result |= TIOCM_DTR;
3170 if (mstat & D_RTS(ch))
3171 result |= TIOCM_RTS;
3172 if (mstat & D_CTS(ch))
3173 result |= TIOCM_CTS;
3174 if (mstat & D_DSR(ch))
3175 result |= TIOCM_DSR;
3176 if (mstat & D_RI(ch))
3178 if (mstat & D_CD(ch))
3181 rc = put_user(result, value);
3187 * dgap_set_modem_info()
3189 * Set modem signals, called by ld.
3191 static int dgap_set_modem_info(struct tty_struct *tty, unsigned int command,
3192 unsigned int __user *value)
3195 struct channel_t *ch;
3198 unsigned int arg = 0;
3202 if (!tty || tty->magic != TTY_MAGIC)
3205 un = tty->driver_data;
3206 if (!un || un->magic != DGAP_UNIT_MAGIC)
3210 if (!ch || ch->magic != DGAP_CHANNEL_MAGIC)
3214 if (!bd || bd->magic != DGAP_BOARD_MAGIC)
3217 ret = get_user(arg, value);
3223 if (arg & TIOCM_RTS) {
3224 ch->ch_mforce |= D_RTS(ch);
3225 ch->ch_mval |= D_RTS(ch);
3228 if (arg & TIOCM_DTR) {
3229 ch->ch_mforce |= D_DTR(ch);
3230 ch->ch_mval |= D_DTR(ch);
3236 if (arg & TIOCM_RTS) {
3237 ch->ch_mforce |= D_RTS(ch);
3238 ch->ch_mval &= ~(D_RTS(ch));
3241 if (arg & TIOCM_DTR) {
3242 ch->ch_mforce |= D_DTR(ch);
3243 ch->ch_mval &= ~(D_DTR(ch));
3249 ch->ch_mforce = D_DTR(ch)|D_RTS(ch);
3251 if (arg & TIOCM_RTS)
3252 ch->ch_mval |= D_RTS(ch);
3254 ch->ch_mval &= ~(D_RTS(ch));
3256 if (arg & TIOCM_DTR)
3257 ch->ch_mval |= (D_DTR(ch));
3259 ch->ch_mval &= ~(D_DTR(ch));
3267 spin_lock_irqsave(&bd->bd_lock, lock_flags);
3268 spin_lock_irqsave(&ch->ch_lock, lock_flags2);
3272 spin_unlock_irqrestore(&ch->ch_lock, lock_flags2);
3273 spin_unlock_irqrestore(&bd->bd_lock, lock_flags);
3279 * dgap_tty_digigeta()
3281 * Ioctl to get the information for ditty.
3286 static int dgap_tty_digigeta(struct tty_struct *tty,
3287 struct digi_t __user *retinfo)
3289 struct channel_t *ch;
3297 if (!tty || tty->magic != TTY_MAGIC)
3300 un = tty->driver_data;
3301 if (!un || un->magic != DGAP_UNIT_MAGIC)
3305 if (!ch || ch->magic != DGAP_CHANNEL_MAGIC)
3308 memset(&tmp, 0, sizeof(tmp));
3310 spin_lock_irqsave(&ch->ch_lock, lock_flags);
3311 memcpy(&tmp, &ch->ch_digi, sizeof(tmp));
3312 spin_unlock_irqrestore(&ch->ch_lock, lock_flags);
3314 if (copy_to_user(retinfo, &tmp, sizeof(*retinfo)))
3321 * dgap_tty_digiseta()
3323 * Ioctl to set the information for ditty.
3328 static int dgap_tty_digiseta(struct tty_struct *tty,
3329 struct digi_t __user *new_info)
3332 struct channel_t *ch;
3334 struct digi_t new_digi;
3335 ulong lock_flags = 0;
3336 unsigned long lock_flags2;
3338 if (!tty || tty->magic != TTY_MAGIC)
3341 un = tty->driver_data;
3342 if (!un || un->magic != DGAP_UNIT_MAGIC)
3346 if (!ch || ch->magic != DGAP_CHANNEL_MAGIC)
3350 if (!bd || bd->magic != DGAP_BOARD_MAGIC)
3353 if (copy_from_user(&new_digi, new_info, sizeof(struct digi_t)))
3356 spin_lock_irqsave(&bd->bd_lock, lock_flags);
3357 spin_lock_irqsave(&ch->ch_lock, lock_flags2);
3359 memcpy(&ch->ch_digi, &new_digi, sizeof(struct digi_t));
3361 if (ch->ch_digi.digi_maxcps < 1)
3362 ch->ch_digi.digi_maxcps = 1;
3364 if (ch->ch_digi.digi_maxcps > 10000)
3365 ch->ch_digi.digi_maxcps = 10000;
3367 if (ch->ch_digi.digi_bufsize < 10)
3368 ch->ch_digi.digi_bufsize = 10;
3370 if (ch->ch_digi.digi_maxchar < 1)
3371 ch->ch_digi.digi_maxchar = 1;
3373 if (ch->ch_digi.digi_maxchar > ch->ch_digi.digi_bufsize)
3374 ch->ch_digi.digi_maxchar = ch->ch_digi.digi_bufsize;
3376 if (ch->ch_digi.digi_onlen > DIGI_PLEN)
3377 ch->ch_digi.digi_onlen = DIGI_PLEN;
3379 if (ch->ch_digi.digi_offlen > DIGI_PLEN)
3380 ch->ch_digi.digi_offlen = DIGI_PLEN;
3384 spin_unlock_irqrestore(&ch->ch_lock, lock_flags2);
3385 spin_unlock_irqrestore(&bd->bd_lock, lock_flags);
3391 * dgap_tty_digigetedelay()
3393 * Ioctl to get the current edelay setting.
3398 static int dgap_tty_digigetedelay(struct tty_struct *tty, int __user *retinfo)
3400 struct channel_t *ch;
3408 if (!tty || tty->magic != TTY_MAGIC)
3411 un = tty->driver_data;
3412 if (!un || un->magic != DGAP_UNIT_MAGIC)
3416 if (!ch || ch->magic != DGAP_CHANNEL_MAGIC)
3419 memset(&tmp, 0, sizeof(tmp));
3421 spin_lock_irqsave(&ch->ch_lock, lock_flags);
3422 tmp = readw(&(ch->ch_bs->edelay));
3423 spin_unlock_irqrestore(&ch->ch_lock, lock_flags);
3425 if (copy_to_user(retinfo, &tmp, sizeof(*retinfo)))
3432 * dgap_tty_digisetedelay()
3434 * Ioctl to set the EDELAY setting
3437 static int dgap_tty_digisetedelay(struct tty_struct *tty, int __user *new_info)
3440 struct channel_t *ch;
3446 if (!tty || tty->magic != TTY_MAGIC)
3449 un = tty->driver_data;
3450 if (!un || un->magic != DGAP_UNIT_MAGIC)
3454 if (!ch || ch->magic != DGAP_CHANNEL_MAGIC)
3458 if (!bd || bd->magic != DGAP_BOARD_MAGIC)
3461 if (copy_from_user(&new_digi, new_info, sizeof(int)))
3464 spin_lock_irqsave(&bd->bd_lock, lock_flags);
3465 spin_lock_irqsave(&ch->ch_lock, lock_flags2);
3467 writew((u16) new_digi, &(ch->ch_bs->edelay));
3471 spin_unlock_irqrestore(&ch->ch_lock, lock_flags2);
3472 spin_unlock_irqrestore(&bd->bd_lock, lock_flags);
3478 * dgap_tty_digigetcustombaud()
3480 * Ioctl to get the current custom baud rate setting.
3482 static int dgap_tty_digigetcustombaud(struct tty_struct *tty,
3483 int __user *retinfo)
3485 struct channel_t *ch;
3493 if (!tty || tty->magic != TTY_MAGIC)
3496 un = tty->driver_data;
3497 if (!un || un->magic != DGAP_UNIT_MAGIC)
3501 if (!ch || ch->magic != DGAP_CHANNEL_MAGIC)
3504 memset(&tmp, 0, sizeof(tmp));
3506 spin_lock_irqsave(&ch->ch_lock, lock_flags);
3507 tmp = dgap_get_custom_baud(ch);
3508 spin_unlock_irqrestore(&ch->ch_lock, lock_flags);
3510 if (copy_to_user(retinfo, &tmp, sizeof(*retinfo)))
3517 * dgap_tty_digisetcustombaud()
3519 * Ioctl to set the custom baud rate setting
3521 static int dgap_tty_digisetcustombaud(struct tty_struct *tty,
3522 int __user *new_info)
3525 struct channel_t *ch;
3531 if (!tty || tty->magic != TTY_MAGIC)
3534 un = tty->driver_data;
3535 if (!un || un->magic != DGAP_UNIT_MAGIC)
3539 if (!ch || ch->magic != DGAP_CHANNEL_MAGIC)
3543 if (!bd || bd->magic != DGAP_BOARD_MAGIC)
3547 if (copy_from_user(&new_rate, new_info, sizeof(unsigned int)))
3550 if (bd->bd_flags & BD_FEP5PLUS) {
3552 spin_lock_irqsave(&bd->bd_lock, lock_flags);
3553 spin_lock_irqsave(&ch->ch_lock, lock_flags2);
3555 ch->ch_custom_speed = new_rate;
3559 spin_unlock_irqrestore(&ch->ch_lock, lock_flags2);
3560 spin_unlock_irqrestore(&bd->bd_lock, lock_flags);
3567 * dgap_set_termios()
3569 static void dgap_tty_set_termios(struct tty_struct *tty,
3570 struct ktermios *old_termios)
3573 struct channel_t *ch;
3575 unsigned long lock_flags;
3576 unsigned long lock_flags2;
3578 if (!tty || tty->magic != TTY_MAGIC)
3581 un = tty->driver_data;
3582 if (!un || un->magic != DGAP_UNIT_MAGIC)
3586 if (!ch || ch->magic != DGAP_CHANNEL_MAGIC)
3590 if (!bd || bd->magic != DGAP_BOARD_MAGIC)
3593 spin_lock_irqsave(&bd->bd_lock, lock_flags);
3594 spin_lock_irqsave(&ch->ch_lock, lock_flags2);
3596 ch->ch_c_cflag = tty->termios.c_cflag;
3597 ch->ch_c_iflag = tty->termios.c_iflag;
3598 ch->ch_c_oflag = tty->termios.c_oflag;
3599 ch->ch_c_lflag = tty->termios.c_lflag;
3600 ch->ch_startc = tty->termios.c_cc[VSTART];
3601 ch->ch_stopc = tty->termios.c_cc[VSTOP];
3606 spin_unlock_irqrestore(&ch->ch_lock, lock_flags2);
3607 spin_unlock_irqrestore(&bd->bd_lock, lock_flags);
3610 static void dgap_tty_throttle(struct tty_struct *tty)
3613 struct channel_t *ch;
3618 if (!tty || tty->magic != TTY_MAGIC)
3621 un = tty->driver_data;
3622 if (!un || un->magic != DGAP_UNIT_MAGIC)
3626 if (!ch || ch->magic != DGAP_CHANNEL_MAGIC)
3630 if (!bd || bd->magic != DGAP_BOARD_MAGIC)
3633 spin_lock_irqsave(&bd->bd_lock, lock_flags);
3634 spin_lock_irqsave(&ch->ch_lock, lock_flags2);
3636 ch->ch_flags |= (CH_RXBLOCK);
3638 dgap_cmdw(ch, RPAUSE, 0, 0);
3641 spin_unlock_irqrestore(&ch->ch_lock, lock_flags2);
3642 spin_unlock_irqrestore(&bd->bd_lock, lock_flags);
3646 static void dgap_tty_unthrottle(struct tty_struct *tty)
3649 struct channel_t *ch;
3654 if (!tty || tty->magic != TTY_MAGIC)
3657 un = tty->driver_data;
3658 if (!un || un->magic != DGAP_UNIT_MAGIC)
3662 if (!ch || ch->magic != DGAP_CHANNEL_MAGIC)
3666 if (!bd || bd->magic != DGAP_BOARD_MAGIC)
3669 spin_lock_irqsave(&bd->bd_lock, lock_flags);
3670 spin_lock_irqsave(&ch->ch_lock, lock_flags2);
3672 ch->ch_flags &= ~(CH_RXBLOCK);
3675 dgap_cmdw(ch, RRESUME, 0, 0);
3678 spin_unlock_irqrestore(&ch->ch_lock, lock_flags2);
3679 spin_unlock_irqrestore(&bd->bd_lock, lock_flags);
3682 static void dgap_tty_start(struct tty_struct *tty)
3685 struct channel_t *ch;
3690 if (!tty || tty->magic != TTY_MAGIC)
3693 un = tty->driver_data;
3694 if (!un || un->magic != DGAP_UNIT_MAGIC)
3698 if (!ch || ch->magic != DGAP_CHANNEL_MAGIC)
3702 if (!bd || bd->magic != DGAP_BOARD_MAGIC)
3705 spin_lock_irqsave(&bd->bd_lock, lock_flags);
3706 spin_lock_irqsave(&ch->ch_lock, lock_flags2);
3708 dgap_cmdw(ch, RESUMETX, 0, 0);
3710 spin_unlock_irqrestore(&ch->ch_lock, lock_flags2);
3711 spin_unlock_irqrestore(&bd->bd_lock, lock_flags);
3715 static void dgap_tty_stop(struct tty_struct *tty)
3718 struct channel_t *ch;
3723 if (!tty || tty->magic != TTY_MAGIC)
3726 un = tty->driver_data;
3727 if (!un || un->magic != DGAP_UNIT_MAGIC)
3731 if (!ch || ch->magic != DGAP_CHANNEL_MAGIC)
3735 if (!bd || bd->magic != DGAP_BOARD_MAGIC)
3738 spin_lock_irqsave(&bd->bd_lock, lock_flags);
3739 spin_lock_irqsave(&ch->ch_lock, lock_flags2);
3741 dgap_cmdw(ch, PAUSETX, 0, 0);
3743 spin_unlock_irqrestore(&ch->ch_lock, lock_flags2);
3744 spin_unlock_irqrestore(&bd->bd_lock, lock_flags);
3749 * dgap_tty_flush_chars()
3751 * Flush the cook buffer
3753 * Note to self, and any other poor souls who venture here:
3755 * flush in this case DOES NOT mean dispose of the data.
3756 * instead, it means "stop buffering and send it if you
3757 * haven't already." Just guess how I figured that out... SRW 2-Jun-98
3759 * It is also always called in interrupt context - JAR 8-Sept-99
3761 static void dgap_tty_flush_chars(struct tty_struct *tty)
3764 struct channel_t *ch;
3769 if (!tty || tty->magic != TTY_MAGIC)
3772 un = tty->driver_data;
3773 if (!un || un->magic != DGAP_UNIT_MAGIC)
3777 if (!ch || ch->magic != DGAP_CHANNEL_MAGIC)
3781 if (!bd || bd->magic != DGAP_BOARD_MAGIC)
3784 spin_lock_irqsave(&bd->bd_lock, lock_flags);
3785 spin_lock_irqsave(&ch->ch_lock, lock_flags2);
3787 /* TODO: Do something here */
3789 spin_unlock_irqrestore(&ch->ch_lock, lock_flags2);
3790 spin_unlock_irqrestore(&bd->bd_lock, lock_flags);
3794 * dgap_tty_flush_buffer()
3796 * Flush Tx buffer (make in == out)
3798 static void dgap_tty_flush_buffer(struct tty_struct *tty)
3801 struct channel_t *ch;
3807 if (!tty || tty->magic != TTY_MAGIC)
3810 un = tty->driver_data;
3811 if (!un || un->magic != DGAP_UNIT_MAGIC)
3815 if (!ch || ch->magic != DGAP_CHANNEL_MAGIC)
3819 if (!bd || bd->magic != DGAP_BOARD_MAGIC)
3822 spin_lock_irqsave(&bd->bd_lock, lock_flags);
3823 spin_lock_irqsave(&ch->ch_lock, lock_flags2);
3825 ch->ch_flags &= ~CH_STOP;
3826 head = readw(&(ch->ch_bs->tx_head));
3827 dgap_cmdw(ch, FLUSHTX, (u16) head, 0);
3828 dgap_cmdw(ch, RESUMETX, 0, 0);
3829 if (ch->ch_tun.un_flags & (UN_LOW|UN_EMPTY)) {
3830 ch->ch_tun.un_flags &= ~(UN_LOW|UN_EMPTY);
3831 wake_up_interruptible(&ch->ch_tun.un_flags_wait);
3833 if (ch->ch_pun.un_flags & (UN_LOW|UN_EMPTY)) {
3834 ch->ch_pun.un_flags &= ~(UN_LOW|UN_EMPTY);
3835 wake_up_interruptible(&ch->ch_pun.un_flags_wait);
3838 spin_unlock_irqrestore(&ch->ch_lock, lock_flags2);
3839 spin_unlock_irqrestore(&bd->bd_lock, lock_flags);
3840 if (waitqueue_active(&tty->write_wait))
3841 wake_up_interruptible(&tty->write_wait);
3845 /*****************************************************************************
3847 * The IOCTL function and all of its helpers
3849 *****************************************************************************/
3854 * The usual assortment of ioctl's
3856 static int dgap_tty_ioctl(struct tty_struct *tty, unsigned int cmd,
3860 struct channel_t *ch;
3864 ulong lock_flags = 0;
3865 ulong lock_flags2 = 0;
3866 void __user *uarg = (void __user *) arg;
3868 if (!tty || tty->magic != TTY_MAGIC)
3871 un = tty->driver_data;
3872 if (!un || un->magic != DGAP_UNIT_MAGIC)
3876 if (!ch || ch->magic != DGAP_CHANNEL_MAGIC)
3880 if (!bd || bd->magic != DGAP_BOARD_MAGIC)
3883 spin_lock_irqsave(&bd->bd_lock, lock_flags);
3884 spin_lock_irqsave(&ch->ch_lock, lock_flags2);
3886 if (un->un_open_count <= 0) {
3887 spin_unlock_irqrestore(&ch->ch_lock, lock_flags2);
3888 spin_unlock_irqrestore(&bd->bd_lock, lock_flags);
3894 /* Here are all the standard ioctl's that we MUST implement */
3898 * TCSBRK is SVID version: non-zero arg --> no break
3899 * this behaviour is exploited by tcdrain().
3901 * According to POSIX.1 spec (7.2.2.1.2) breaks should be
3902 * between 0.25 and 0.5 seconds so we'll ask for something
3903 * in the middle: 0.375 seconds.
3905 rc = tty_check_change(tty);
3906 spin_unlock_irqrestore(&ch->ch_lock, lock_flags2);
3907 spin_unlock_irqrestore(&bd->bd_lock, lock_flags);
3911 rc = dgap_wait_for_drain(tty);
3916 spin_lock_irqsave(&bd->bd_lock, lock_flags);
3917 spin_lock_irqsave(&ch->ch_lock, lock_flags2);
3919 if (((cmd == TCSBRK) && (!arg)) || (cmd == TCSBRKP))
3920 dgap_cmdw(ch, SBREAK, (u16) SBREAK_TIME, 0);
3922 spin_unlock_irqrestore(&ch->ch_lock, lock_flags2);
3923 spin_unlock_irqrestore(&bd->bd_lock, lock_flags);
3928 /* support for POSIX tcsendbreak()
3930 * According to POSIX.1 spec (7.2.2.1.2) breaks should be
3931 * between 0.25 and 0.5 seconds so we'll ask for something
3932 * in the middle: 0.375 seconds.
3934 rc = tty_check_change(tty);
3935 spin_unlock_irqrestore(&ch->ch_lock, lock_flags2);
3936 spin_unlock_irqrestore(&bd->bd_lock, lock_flags);
3940 rc = dgap_wait_for_drain(tty);
3944 spin_lock_irqsave(&bd->bd_lock, lock_flags);
3945 spin_lock_irqsave(&ch->ch_lock, lock_flags2);
3947 dgap_cmdw(ch, SBREAK, (u16) SBREAK_TIME, 0);
3949 spin_unlock_irqrestore(&ch->ch_lock, lock_flags2);
3950 spin_unlock_irqrestore(&bd->bd_lock, lock_flags);
3956 * FEP5 doesn't support turning on a break unconditionally.
3957 * The FEP5 device will stop sending a break automatically
3958 * after the specified time value that was sent when turning on
3961 rc = tty_check_change(tty);
3962 spin_unlock_irqrestore(&ch->ch_lock, lock_flags2);
3963 spin_unlock_irqrestore(&bd->bd_lock, lock_flags);
3967 rc = dgap_wait_for_drain(tty);
3971 spin_lock_irqsave(&bd->bd_lock, lock_flags);
3972 spin_lock_irqsave(&ch->ch_lock, lock_flags2);
3974 dgap_cmdw(ch, SBREAK, (u16) SBREAK_TIME, 0);
3976 spin_unlock_irqrestore(&ch->ch_lock, lock_flags2);
3977 spin_unlock_irqrestore(&bd->bd_lock, lock_flags);
3983 * FEP5 doesn't support turning off a break unconditionally.
3984 * The FEP5 device will stop sending a break automatically
3985 * after the specified time value that was sent when turning on
3988 spin_unlock_irqrestore(&ch->ch_lock, lock_flags2);
3989 spin_unlock_irqrestore(&bd->bd_lock, lock_flags);
3994 spin_unlock_irqrestore(&ch->ch_lock, lock_flags2);
3995 spin_unlock_irqrestore(&bd->bd_lock, lock_flags);
3997 rc = put_user(C_CLOCAL(tty) ? 1 : 0,
3998 (unsigned long __user *) arg);
4002 spin_unlock_irqrestore(&ch->ch_lock, lock_flags2);
4003 spin_unlock_irqrestore(&bd->bd_lock, lock_flags);
4005 rc = get_user(arg, (unsigned long __user *) arg);
4009 spin_lock_irqsave(&bd->bd_lock, lock_flags);
4010 spin_lock_irqsave(&ch->ch_lock, lock_flags2);
4011 tty->termios.c_cflag = ((tty->termios.c_cflag & ~CLOCAL) |
4012 (arg ? CLOCAL : 0));
4014 spin_unlock_irqrestore(&ch->ch_lock, lock_flags2);
4015 spin_unlock_irqrestore(&bd->bd_lock, lock_flags);
4020 spin_unlock_irqrestore(&ch->ch_lock, lock_flags2);
4021 spin_unlock_irqrestore(&bd->bd_lock, lock_flags);
4022 return dgap_get_modem_info(ch, uarg);
4027 spin_unlock_irqrestore(&ch->ch_lock, lock_flags2);
4028 spin_unlock_irqrestore(&bd->bd_lock, lock_flags);
4029 return dgap_set_modem_info(tty, cmd, uarg);
4032 * Here are any additional ioctl's that we want to implement
4037 * The linux tty driver doesn't have a flush
4038 * input routine for the driver, assuming all backed
4039 * up data is in the line disc. buffers. However,
4040 * we all know that's not the case. Here, we
4041 * act on the ioctl, but then lie and say we didn't
4042 * so the line discipline will process the flush
4045 rc = tty_check_change(tty);
4047 spin_unlock_irqrestore(&ch->ch_lock, lock_flags2);
4048 spin_unlock_irqrestore(&bd->bd_lock, lock_flags);
4052 if ((arg == TCIFLUSH) || (arg == TCIOFLUSH)) {
4053 if (!(un->un_type == DGAP_PRINT)) {
4054 head = readw(&(ch->ch_bs->rx_head));
4055 writew(head, &(ch->ch_bs->rx_tail));
4056 writeb(0, &(ch->ch_bs->orun));
4060 if ((arg != TCOFLUSH) && (arg != TCIOFLUSH)) {
4061 /* pretend we didn't recognize this IOCTL */
4062 spin_unlock_irqrestore(&ch->ch_lock, lock_flags2);
4063 spin_unlock_irqrestore(&bd->bd_lock, lock_flags);
4065 return -ENOIOCTLCMD;
4068 ch->ch_flags &= ~CH_STOP;
4069 head = readw(&(ch->ch_bs->tx_head));
4070 dgap_cmdw(ch, FLUSHTX, (u16) head, 0);
4071 dgap_cmdw(ch, RESUMETX, 0, 0);
4072 if (ch->ch_tun.un_flags & (UN_LOW|UN_EMPTY)) {
4073 ch->ch_tun.un_flags &= ~(UN_LOW|UN_EMPTY);
4074 wake_up_interruptible(&ch->ch_tun.un_flags_wait);
4076 if (ch->ch_pun.un_flags & (UN_LOW|UN_EMPTY)) {
4077 ch->ch_pun.un_flags &= ~(UN_LOW|UN_EMPTY);
4078 wake_up_interruptible(&ch->ch_pun.un_flags_wait);
4080 if (waitqueue_active(&tty->write_wait))
4081 wake_up_interruptible(&tty->write_wait);
4083 /* Can't hold any locks when calling tty_wakeup! */
4084 spin_unlock_irqrestore(&ch->ch_lock, lock_flags2);
4085 spin_unlock_irqrestore(&bd->bd_lock, lock_flags);
4088 /* pretend we didn't recognize this IOCTL */
4089 return -ENOIOCTLCMD;
4094 * The linux tty driver doesn't have a flush
4095 * input routine for the driver, assuming all backed
4096 * up data is in the line disc. buffers. However,
4097 * we all know that's not the case. Here, we
4098 * act on the ioctl, but then lie and say we didn't
4099 * so the line discipline will process the flush
4102 if (cmd == TCSETSF) {
4104 ch->ch_flags &= ~CH_STOP;
4105 head = readw(&(ch->ch_bs->rx_head));
4106 writew(head, &(ch->ch_bs->rx_tail));
4109 /* now wait for all the output to drain */
4110 spin_unlock_irqrestore(&ch->ch_lock, lock_flags2);
4111 spin_unlock_irqrestore(&bd->bd_lock, lock_flags);
4112 rc = dgap_wait_for_drain(tty);
4116 /* pretend we didn't recognize this */
4117 return -ENOIOCTLCMD;
4121 spin_unlock_irqrestore(&ch->ch_lock, lock_flags2);
4122 spin_unlock_irqrestore(&bd->bd_lock, lock_flags);
4123 rc = dgap_wait_for_drain(tty);
4127 /* pretend we didn't recognize this */
4128 return -ENOIOCTLCMD;
4132 * The Linux Line Discipline (LD) would do this for us if we
4133 * let it, but we have the special firmware options to do this
4134 * the "right way" regardless of hardware or software flow
4135 * control so we'll do it outselves instead of letting the LD
4138 rc = tty_check_change(tty);
4140 spin_unlock_irqrestore(&ch->ch_lock, lock_flags2);
4141 spin_unlock_irqrestore(&bd->bd_lock, lock_flags);
4148 spin_unlock_irqrestore(&ch->ch_lock, lock_flags2);
4149 spin_unlock_irqrestore(&bd->bd_lock, lock_flags);
4150 dgap_tty_start(tty);
4153 spin_unlock_irqrestore(&ch->ch_lock, lock_flags2);
4154 spin_unlock_irqrestore(&bd->bd_lock, lock_flags);
4158 spin_unlock_irqrestore(&ch->ch_lock, lock_flags2);
4159 spin_unlock_irqrestore(&bd->bd_lock, lock_flags);
4160 /* Make the ld do it */
4161 return -ENOIOCTLCMD;
4163 spin_unlock_irqrestore(&ch->ch_lock, lock_flags2);
4164 spin_unlock_irqrestore(&bd->bd_lock, lock_flags);
4165 /* Make the ld do it */
4166 return -ENOIOCTLCMD;
4168 spin_unlock_irqrestore(&ch->ch_lock, lock_flags2);
4169 spin_unlock_irqrestore(&bd->bd_lock, lock_flags);
4174 /* get information for ditty */
4175 spin_unlock_irqrestore(&ch->ch_lock, lock_flags2);
4176 spin_unlock_irqrestore(&bd->bd_lock, lock_flags);
4177 return dgap_tty_digigeta(tty, uarg);
4182 /* set information for ditty */
4183 if (cmd == (DIGI_SETAW)) {
4185 spin_unlock_irqrestore(&ch->ch_lock, lock_flags2);
4186 spin_unlock_irqrestore(&bd->bd_lock, lock_flags);
4187 rc = dgap_wait_for_drain(tty);
4190 spin_lock_irqsave(&bd->bd_lock, lock_flags);
4191 spin_lock_irqsave(&ch->ch_lock, lock_flags2);
4193 tty_ldisc_flush(tty);
4197 spin_unlock_irqrestore(&ch->ch_lock, lock_flags2);
4198 spin_unlock_irqrestore(&bd->bd_lock, lock_flags);
4199 return dgap_tty_digiseta(tty, uarg);
4202 spin_unlock_irqrestore(&ch->ch_lock, lock_flags2);
4203 spin_unlock_irqrestore(&bd->bd_lock, lock_flags);
4204 return dgap_tty_digigetedelay(tty, uarg);
4207 spin_unlock_irqrestore(&ch->ch_lock, lock_flags2);
4208 spin_unlock_irqrestore(&bd->bd_lock, lock_flags);
4209 return dgap_tty_digisetedelay(tty, uarg);
4211 case DIGI_GETCUSTOMBAUD:
4212 spin_unlock_irqrestore(&ch->ch_lock, lock_flags2);
4213 spin_unlock_irqrestore(&bd->bd_lock, lock_flags);
4214 return dgap_tty_digigetcustombaud(tty, uarg);
4216 case DIGI_SETCUSTOMBAUD:
4217 spin_unlock_irqrestore(&ch->ch_lock, lock_flags2);
4218 spin_unlock_irqrestore(&bd->bd_lock, lock_flags);
4219 return dgap_tty_digisetcustombaud(tty, uarg);
4221 case DIGI_RESET_PORT:
4222 dgap_firmware_reset_port(ch);
4224 spin_unlock_irqrestore(&ch->ch_lock, lock_flags2);
4225 spin_unlock_irqrestore(&bd->bd_lock, lock_flags);
4229 spin_unlock_irqrestore(&ch->ch_lock, lock_flags2);
4230 spin_unlock_irqrestore(&bd->bd_lock, lock_flags);
4232 return -ENOIOCTLCMD;
4236 static int dgap_after_config_loaded(int board)
4239 * Initialize KME waitqueues...
4241 init_waitqueue_head(&(dgap_Board[board]->kme_wait));
4244 * allocate flip buffer for board.
4246 dgap_Board[board]->flipbuf = kmalloc(MYFLIPLEN, GFP_ATOMIC);
4247 if (!dgap_Board[board]->flipbuf)
4250 dgap_Board[board]->flipflagbuf = kmalloc(MYFLIPLEN, GFP_ATOMIC);
4251 if (!dgap_Board[board]->flipflagbuf) {
4252 kfree(dgap_Board[board]->flipbuf);
4260 * Create pr and tty device entries
4262 static int dgap_tty_register_ports(struct board_t *brd)
4264 struct channel_t *ch;
4267 brd->SerialPorts = kcalloc(brd->nasync, sizeof(*brd->SerialPorts),
4269 if (brd->SerialPorts == NULL)
4271 for (i = 0; i < brd->nasync; i++)
4272 tty_port_init(&brd->SerialPorts[i]);
4274 brd->PrinterPorts = kcalloc(brd->nasync, sizeof(*brd->PrinterPorts),
4276 if (brd->PrinterPorts == NULL) {
4277 kfree(brd->SerialPorts);
4280 for (i = 0; i < brd->nasync; i++)
4281 tty_port_init(&brd->PrinterPorts[i]);
4283 ch = brd->channels[0];
4284 for (i = 0; i < brd->nasync; i++, ch = brd->channels[i]) {
4286 struct device *classp;
4288 classp = tty_port_register_device(&brd->SerialPorts[i],
4290 brd->firstminor + i, NULL);
4292 dgap_create_tty_sysfs(&ch->ch_tun, classp);
4293 ch->ch_tun.un_sysfs = classp;
4295 classp = tty_port_register_device(&brd->PrinterPorts[i],
4297 brd->firstminor + i, NULL);
4299 dgap_create_tty_sysfs(&ch->ch_pun, classp);
4300 ch->ch_pun.un_sysfs = classp;
4302 dgap_create_ports_sysfiles(brd);
4308 * Copies the BIOS code from the user to the board,
4309 * and starts the BIOS running.
4311 static void dgap_do_bios_load(struct board_t *brd, const u8 *ubios, int len)
4317 if (!brd || (brd->magic != DGAP_BOARD_MAGIC) || !brd->re_map_membase)
4320 addr = brd->re_map_membase;
4325 for (i = 0; i < 16; i++)
4326 writeb(0, addr + POSTAREA + i);
4332 memcpy_toio(addr + offset, ubios, len);
4334 writel(0x0bf00401, addr);
4335 writel(0, (addr + 4));
4337 /* Clear the reset, and change states. */
4338 writeb(FEPCLR, brd->re_map_port);
4342 * Checks to see if the BIOS completed running on the card.
4344 static int dgap_test_bios(struct board_t *brd)
4351 if (!brd || (brd->magic != DGAP_BOARD_MAGIC) || !brd->re_map_membase)
4354 addr = brd->re_map_membase;
4355 word = readw(addr + POSTAREA);
4358 * It can take 5-6 seconds for a board to
4359 * pass the bios self test and post results.
4360 * Give it 10 seconds.
4362 brd->wait_for_bios = 0;
4363 while (brd->wait_for_bios < 1000) {
4364 /* Check to see if BIOS thinks board is good. (GD). */
4365 if (word == *(u16 *) "GD")
4367 msleep_interruptible(10);
4368 brd->wait_for_bios++;
4369 word = readw(addr + POSTAREA);
4372 /* Gave up on board after too long of time taken */
4373 err1 = readw(addr + SEQUENCE);
4374 err2 = readw(addr + ERROR);
4375 pr_warn("dgap: %s failed diagnostics. Error #(%x,%x).\n",
4376 brd->name, err1, err2);
4377 brd->state = BOARD_FAILED;
4378 brd->dpastatus = BD_NOBIOS;
4384 * Copies the FEP code from the user to the board,
4385 * and starts the FEP running.
4387 static void dgap_do_fep_load(struct board_t *brd, const u8 *ufep, int len)
4392 if (!brd || (brd->magic != DGAP_BOARD_MAGIC) || !brd->re_map_membase)
4395 addr = brd->re_map_membase;
4401 memcpy_toio(addr + offset, ufep, len);
4404 * If board is a concentrator product, we need to give
4405 * it its config string describing how the concentrators look.
4407 if ((brd->type == PCX) || (brd->type == PEPC)) {
4409 u8 *config, *xconfig;
4412 xconfig = dgap_create_config_string(brd, string);
4414 /* Write string to board memory */
4415 config = addr + CONFIG;
4416 for (; i < CONFIGSIZE; i++, config++, xconfig++) {
4417 writeb(*xconfig, config);
4418 if ((*xconfig & 0xff) == 0xff)
4423 writel(0xbfc01004, (addr + 0xc34));
4424 writel(0x3, (addr + 0xc30));
4429 * Waits for the FEP to report thats its ready for us to use.
4431 static int dgap_test_fep(struct board_t *brd)
4438 if (!brd || (brd->magic != DGAP_BOARD_MAGIC) || !brd->re_map_membase)
4441 addr = brd->re_map_membase;
4442 word = readw(addr + FEPSTAT);
4445 * It can take 2-3 seconds for the FEP to
4446 * be up and running. Give it 5 secs.
4448 brd->wait_for_fep = 0;
4449 while (brd->wait_for_fep < 500) {
4450 /* Check to see if FEP is up and running now. */
4451 if (word == *(u16 *) "OS") {
4453 * Check to see if the board can support FEP5+ commands.
4455 word = readw(addr + FEP5_PLUS);
4456 if (word == *(u16 *) "5A")
4457 brd->bd_flags |= BD_FEP5PLUS;
4461 msleep_interruptible(10);
4462 brd->wait_for_fep++;
4463 word = readw(addr + FEPSTAT);
4466 /* Gave up on board after too long of time taken */
4467 err1 = readw(addr + SEQUENCE);
4468 err2 = readw(addr + ERROR);
4469 pr_warn("dgap: FEPOS for %s not functioning. Error #(%x,%x).\n",
4470 brd->name, err1, err2);
4471 brd->state = BOARD_FAILED;
4472 brd->dpastatus = BD_NOFEP;
4478 * Physically forces the FEP5 card to reset itself.
4480 static void dgap_do_reset_board(struct board_t *brd)
4487 if (!brd || (brd->magic != DGAP_BOARD_MAGIC) ||
4488 !brd->re_map_membase || !brd->re_map_port)
4491 /* FEPRST does not vary among supported boards */
4492 writeb(FEPRST, brd->re_map_port);
4494 for (i = 0; i <= 1000; i++) {
4495 check = readb(brd->re_map_port) & 0xe;
4496 if (check == FEPRST)
4502 pr_warn("dgap: Board not resetting... Failing board.\n");
4503 brd->state = BOARD_FAILED;
4504 brd->dpastatus = BD_NOFEP;
4509 * Make sure there really is memory out there.
4511 writel(0xa55a3cc3, (brd->re_map_membase + LOWMEM));
4512 writel(0x5aa5c33c, (brd->re_map_membase + HIGHMEM));
4513 check1 = readl(brd->re_map_membase + LOWMEM);
4514 check2 = readl(brd->re_map_membase + HIGHMEM);
4516 if ((check1 != 0xa55a3cc3) || (check2 != 0x5aa5c33c)) {
4517 pr_warn("dgap: No memory at %p for board.\n",
4518 brd->re_map_membase);
4519 brd->state = BOARD_FAILED;
4520 brd->dpastatus = BD_NOFEP;
4526 #ifdef DIGI_CONCENTRATORS_SUPPORTED
4528 * Sends a concentrator image into the FEP5 board.
4530 static void dgap_do_conc_load(struct board_t *brd, u8 *uaddr, int len)
4534 struct downld_t *to_dp;
4536 if (!brd || (brd->magic != DGAP_BOARD_MAGIC) || !brd->re_map_membase)
4539 vaddr = brd->re_map_membase;
4541 offset = readw((u16 *) (vaddr + DOWNREQ));
4542 to_dp = (struct downld_t *) (vaddr + (int) offset);
4543 memcpy_toio(to_dp, uaddr, len);
4545 /* Tell card we have data for it */
4546 writew(0, vaddr + (DOWNREQ));
4548 brd->conc_dl_status = NO_PENDING_CONCENTRATOR_REQUESTS;
4552 #define EXPANSION_ROM_SIZE (64 * 1024)
4553 #define FEP5_ROM_MAGIC (0xFEFFFFFF)
4555 static void dgap_get_vpd(struct board_t *brd)
4567 * Poke the magic number at the PCI Rom Address location.
4568 * If VPD is supported, the value read from that address
4571 magic = FEP5_ROM_MAGIC;
4572 pci_write_config_dword(brd->pdev, PCI_ROM_ADDRESS, magic);
4573 pci_read_config_dword(brd->pdev, PCI_ROM_ADDRESS, &magic);
4575 /* VPD not supported, bail */
4580 * To get to the OTPROM memory, we have to send the boards base
4581 * address or'ed with 1 into the PCI Rom Address location.
4583 magic = brd->membase | 0x01;
4584 pci_write_config_dword(brd->pdev, PCI_ROM_ADDRESS, magic);
4585 pci_read_config_dword(brd->pdev, PCI_ROM_ADDRESS, &magic);
4587 byte1 = readb(brd->re_map_membase);
4588 byte2 = readb(brd->re_map_membase + 1);
4591 * If the board correctly swapped to the OTPROM memory,
4592 * the first 2 bytes (header) should be 0x55, 0xAA
4594 if (byte1 == 0x55 && byte2 == 0xAA) {
4599 * We have to run through all the OTPROM memory looking
4600 * for the VPD offset.
4602 while (base_offset <= EXPANSION_ROM_SIZE) {
4605 * Lots of magic numbers here.
4607 * The VPD offset is located inside the ROM Data
4610 * We also have to remember the length of each
4611 * ROM Data Structure, so we can "hop" to the next
4612 * entry if the VPD isn't in the current
4613 * ROM Data Structure.
4615 rom_offset = readw(brd->re_map_membase +
4616 base_offset + 0x18);
4617 image_length = readw(brd->re_map_membase +
4618 rom_offset + 0x10) * 512;
4619 vpd_offset = readw(brd->re_map_membase +
4622 /* Found the VPD entry */
4626 /* We didn't find a VPD entry, go to next ROM entry. */
4627 base_offset += image_length;
4629 byte1 = readb(brd->re_map_membase + base_offset);
4630 byte2 = readb(brd->re_map_membase + base_offset + 1);
4633 * If the new ROM offset doesn't have 0x55, 0xAA
4634 * as its header, we have run out of ROM.
4636 if (byte1 != 0x55 || byte2 != 0xAA)
4641 * If we have a VPD offset, then mark the board
4642 * as having a valid VPD, and copy VPDSIZE (512) bytes of
4643 * that VPD to the buffer we have in our board structure.
4646 brd->bd_flags |= BD_HAS_VPD;
4647 for (i = 0; i < VPDSIZE; i++) {
4648 brd->vpd[i] = readb(brd->re_map_membase +
4655 * We MUST poke the magic number at the PCI Rom Address location again.
4656 * This makes the card report the regular board memory back to us,
4657 * rather than the OTPROM memory.
4659 magic = FEP5_ROM_MAGIC;
4660 pci_write_config_dword(brd->pdev, PCI_ROM_ADDRESS, magic);
4664 * Our board poller function.
4666 static void dgap_poll_tasklet(unsigned long data)
4668 struct board_t *bd = (struct board_t *) data;
4673 if (!bd || (bd->magic != DGAP_BOARD_MAGIC))
4676 if (bd->inhibit_poller)
4679 spin_lock_irqsave(&bd->bd_lock, lock_flags);
4681 vaddr = bd->re_map_membase;
4684 * If board is ready, parse deeper to see if there is anything to do.
4686 if (bd->state == BOARD_READY) {
4688 struct ev_t *eaddr = NULL;
4690 if (!bd->re_map_membase) {
4691 spin_unlock_irqrestore(&bd->bd_lock, lock_flags);
4694 if (!bd->re_map_port) {
4695 spin_unlock_irqrestore(&bd->bd_lock, lock_flags);
4702 eaddr = (struct ev_t *) (vaddr + EVBUF);
4704 /* Get our head and tail */
4705 head = readw(&(eaddr->ev_head));
4706 tail = readw(&(eaddr->ev_tail));
4709 * If there is an event pending. Go service it.
4712 spin_unlock_irqrestore(&bd->bd_lock, lock_flags);
4714 spin_lock_irqsave(&bd->bd_lock, lock_flags);
4719 * If board is doing interrupts, ACK the interrupt.
4721 if (bd && bd->intr_running)
4722 readb(bd->re_map_port + 2);
4724 spin_unlock_irqrestore(&bd->bd_lock, lock_flags);
4728 spin_unlock_irqrestore(&bd->bd_lock, lock_flags);
4731 /*=======================================================================
4733 * dgap_cmdb - Sends a 2 byte command to the FEP.
4735 * ch - Pointer to channel structure.
4736 * cmd - Command to be sent.
4737 * byte1 - Integer containing first byte to be sent.
4738 * byte2 - Integer containing second byte to be sent.
4739 * ncmds - Wait until ncmds or fewer cmds are left
4740 * in the cmd buffer before returning.
4742 *=======================================================================*/
4743 static void dgap_cmdb(struct channel_t *ch, u8 cmd, u8 byte1,
4744 u8 byte2, uint ncmds)
4747 struct cm_t *cm_addr = NULL;
4753 if (!ch || ch->magic != DGAP_CHANNEL_MAGIC)
4757 * Check if board is still alive.
4759 if (ch->ch_bd->state == BOARD_FAILED)
4763 * Make sure the pointers are in range before
4764 * writing to the FEP memory.
4766 vaddr = ch->ch_bd->re_map_membase;
4771 cm_addr = (struct cm_t *) (vaddr + CMDBUF);
4772 head = readw(&(cm_addr->cm_head));
4775 * Forget it if pointers out of range.
4777 if (head >= (CMDMAX - CMDSTART) || (head & 03)) {
4778 ch->ch_bd->state = BOARD_FAILED;
4783 * Put the data in the circular command buffer.
4785 writeb(cmd, (char *) (vaddr + head + CMDSTART + 0));
4786 writeb((u8) ch->ch_portnum, (char *) (vaddr + head + CMDSTART + 1));
4787 writeb(byte1, (char *) (vaddr + head + CMDSTART + 2));
4788 writeb(byte2, (char *) (vaddr + head + CMDSTART + 3));
4790 head = (head + 4) & (CMDMAX - CMDSTART - 4);
4792 writew(head, &(cm_addr->cm_head));
4795 * Wait if necessary before updating the head
4796 * pointer to limit the number of outstanding
4797 * commands to the FEP. If the time spent waiting
4798 * is outlandish, declare the FEP dead.
4800 for (count = dgap_count ;;) {
4802 head = readw(&(cm_addr->cm_head));
4803 tail = readw(&(cm_addr->cm_tail));
4805 n = (head - tail) & (CMDMAX - CMDSTART - 4);
4807 if (n <= ncmds * sizeof(struct cm_t))
4811 ch->ch_bd->state = BOARD_FAILED;
4818 /*=======================================================================
4820 * dgap_cmdw - Sends a 1 word command to the FEP.
4822 * ch - Pointer to channel structure.
4823 * cmd - Command to be sent.
4824 * word - Integer containing word to be sent.
4825 * ncmds - Wait until ncmds or fewer cmds are left
4826 * in the cmd buffer before returning.
4828 *=======================================================================*/
4829 static void dgap_cmdw(struct channel_t *ch, u8 cmd, u16 word, uint ncmds)
4832 struct cm_t *cm_addr = NULL;
4838 if (!ch || ch->magic != DGAP_CHANNEL_MAGIC)
4842 * Check if board is still alive.
4844 if (ch->ch_bd->state == BOARD_FAILED)
4848 * Make sure the pointers are in range before
4849 * writing to the FEP memory.
4851 vaddr = ch->ch_bd->re_map_membase;
4855 cm_addr = (struct cm_t *) (vaddr + CMDBUF);
4856 head = readw(&(cm_addr->cm_head));
4859 * Forget it if pointers out of range.
4861 if (head >= (CMDMAX - CMDSTART) || (head & 03)) {
4862 ch->ch_bd->state = BOARD_FAILED;
4867 * Put the data in the circular command buffer.
4869 writeb(cmd, (char *) (vaddr + head + CMDSTART + 0));
4870 writeb((u8) ch->ch_portnum, (char *) (vaddr + head + CMDSTART + 1));
4871 writew((u16) word, (char *) (vaddr + head + CMDSTART + 2));
4873 head = (head + 4) & (CMDMAX - CMDSTART - 4);
4875 writew(head, &(cm_addr->cm_head));
4878 * Wait if necessary before updating the head
4879 * pointer to limit the number of outstanding
4880 * commands to the FEP. If the time spent waiting
4881 * is outlandish, declare the FEP dead.
4883 for (count = dgap_count ;;) {
4885 head = readw(&(cm_addr->cm_head));
4886 tail = readw(&(cm_addr->cm_tail));
4888 n = (head - tail) & (CMDMAX - CMDSTART - 4);
4890 if (n <= ncmds * sizeof(struct cm_t))
4894 ch->ch_bd->state = BOARD_FAILED;
4901 /*=======================================================================
4903 * dgap_cmdw_ext - Sends a extended word command to the FEP.
4905 * ch - Pointer to channel structure.
4906 * cmd - Command to be sent.
4907 * word - Integer containing word to be sent.
4908 * ncmds - Wait until ncmds or fewer cmds are left
4909 * in the cmd buffer before returning.
4911 *=======================================================================*/
4912 static void dgap_cmdw_ext(struct channel_t *ch, u16 cmd, u16 word, uint ncmds)
4915 struct cm_t *cm_addr = NULL;
4921 if (!ch || ch->magic != DGAP_CHANNEL_MAGIC)
4925 * Check if board is still alive.
4927 if (ch->ch_bd->state == BOARD_FAILED)
4931 * Make sure the pointers are in range before
4932 * writing to the FEP memory.
4934 vaddr = ch->ch_bd->re_map_membase;
4938 cm_addr = (struct cm_t *) (vaddr + CMDBUF);
4939 head = readw(&(cm_addr->cm_head));
4942 * Forget it if pointers out of range.
4944 if (head >= (CMDMAX - CMDSTART) || (head & 03)) {
4945 ch->ch_bd->state = BOARD_FAILED;
4950 * Put the data in the circular command buffer.
4953 /* Write an FF to tell the FEP that we want an extended command */
4954 writeb((u8) 0xff, (char *) (vaddr + head + CMDSTART + 0));
4956 writeb((u8) ch->ch_portnum, (u8 *) (vaddr + head + CMDSTART + 1));
4957 writew((u16) cmd, (char *) (vaddr + head + CMDSTART + 2));
4960 * If the second part of the command won't fit,
4961 * put it at the beginning of the circular buffer.
4963 if (((head + 4) >= ((CMDMAX - CMDSTART)) || (head & 03)))
4964 writew((u16) word, (char *) (vaddr + CMDSTART));
4966 writew((u16) word, (char *) (vaddr + head + CMDSTART + 4));
4968 head = (head + 8) & (CMDMAX - CMDSTART - 4);
4970 writew(head, &(cm_addr->cm_head));
4973 * Wait if necessary before updating the head
4974 * pointer to limit the number of outstanding
4975 * commands to the FEP. If the time spent waiting
4976 * is outlandish, declare the FEP dead.
4978 for (count = dgap_count ;;) {
4980 head = readw(&(cm_addr->cm_head));
4981 tail = readw(&(cm_addr->cm_tail));
4983 n = (head - tail) & (CMDMAX - CMDSTART - 4);
4985 if (n <= ncmds * sizeof(struct cm_t))
4989 ch->ch_bd->state = BOARD_FAILED;
4996 /*=======================================================================
4998 * dgap_wmove - Write data to FEP buffer.
5000 * ch - Pointer to channel structure.
5001 * buf - Poiter to characters to be moved.
5002 * cnt - Number of characters to move.
5004 *=======================================================================*/
5005 static void dgap_wmove(struct channel_t *ch, char *buf, uint cnt)
5012 if (!ch || ch->magic != DGAP_CHANNEL_MAGIC)
5019 head = readw(&(bs->tx_head));
5022 * If pointers are out of range, just return.
5024 if ((cnt > ch->ch_tsize) ||
5025 (unsigned)(head - ch->ch_tstart) >= ch->ch_tsize)
5029 * If the write wraps over the top of the circular buffer,
5030 * move the portion up to the wrap point, and reset the
5031 * pointers to the bottom.
5033 n = ch->ch_tstart + ch->ch_tsize - head;
5037 taddr = ch->ch_taddr + head;
5038 memcpy_toio(taddr, buf, n);
5039 head = ch->ch_tstart;
5044 * Move rest of data.
5046 taddr = ch->ch_taddr + head;
5048 memcpy_toio(taddr, buf, n);
5051 writew(head, &(bs->tx_head));
5055 * Retrives the current custom baud rate from FEP memory,
5056 * and returns it back to the user.
5057 * Returns 0 on error.
5059 static uint dgap_get_custom_baud(struct channel_t *ch)
5065 if (!ch || ch->magic != DGAP_CHANNEL_MAGIC)
5068 if (!ch->ch_bd || ch->ch_bd->magic != DGAP_BOARD_MAGIC)
5071 if (!(ch->ch_bd->bd_flags & BD_FEP5PLUS))
5074 vaddr = ch->ch_bd->re_map_membase;
5080 * Go get from fep mem, what the fep
5081 * believes the custom baud rate is.
5083 offset = ((((*(unsigned short *)(vaddr + ECS_SEG)) << 4) +
5084 (ch->ch_portnum * 0x28) + LINE_SPEED));
5086 value = readw(vaddr + offset);
5091 * Calls the firmware to reset this channel.
5093 static void dgap_firmware_reset_port(struct channel_t *ch)
5095 dgap_cmdb(ch, CHRESET, 0, 0, 0);
5098 * Now that the channel is reset, we need to make sure
5099 * all the current settings get reapplied to the port
5102 * So we will set the driver's cache of firmware
5103 * settings all to 0, and then call param.
5105 ch->ch_fepiflag = 0;
5106 ch->ch_fepcflag = 0;
5107 ch->ch_fepoflag = 0;
5108 ch->ch_fepstartc = 0;
5109 ch->ch_fepstopc = 0;
5110 ch->ch_fepastartc = 0;
5111 ch->ch_fepastopc = 0;
5116 /*=======================================================================
5118 * dgap_param - Set Digi parameters.
5120 * struct tty_struct * - TTY for port.
5122 *=======================================================================*/
5123 static int dgap_param(struct tty_struct *tty)
5125 struct ktermios *ts;
5127 struct channel_t *ch;
5136 if (!tty || tty->magic != TTY_MAGIC)
5139 un = (struct un_t *) tty->driver_data;
5140 if (!un || un->magic != DGAP_UNIT_MAGIC)
5144 if (!ch || ch->magic != DGAP_CHANNEL_MAGIC)
5148 if (!bd || bd->magic != DGAP_BOARD_MAGIC)
5158 * If baud rate is zero, flush queues, and set mval to drop DTR.
5160 if ((ch->ch_c_cflag & (CBAUD)) == 0) {
5163 head = readw(&(ch->ch_bs->rx_head));
5164 writew(head, &(ch->ch_bs->rx_tail));
5167 head = readw(&(ch->ch_bs->tx_head));
5168 writew(head, &(ch->ch_bs->tx_tail));
5170 ch->ch_flags |= (CH_BAUD0);
5172 /* Drop RTS and DTR */
5173 ch->ch_mval &= ~(D_RTS(ch)|D_DTR(ch));
5174 mval = D_DTR(ch) | D_RTS(ch);
5175 ch->ch_baud_info = 0;
5177 } else if (ch->ch_custom_speed && (bd->bd_flags & BD_FEP5PLUS)) {
5179 * Tell the fep to do the command
5182 dgap_cmdw_ext(ch, 0xff01, ch->ch_custom_speed, 0);
5185 * Now go get from fep mem, what the fep
5186 * believes the custom baud rate is.
5188 ch->ch_custom_speed = dgap_get_custom_baud(ch);
5189 ch->ch_baud_info = ch->ch_custom_speed;
5191 /* Handle transition from B0 */
5192 if (ch->ch_flags & CH_BAUD0) {
5193 ch->ch_flags &= ~(CH_BAUD0);
5194 ch->ch_mval |= (D_RTS(ch)|D_DTR(ch));
5196 mval = D_DTR(ch) | D_RTS(ch);
5200 * Set baud rate, character size, and parity.
5208 ulong bauds[4][16] = {
5212 600, 1200, 1800, 2400,
5213 4800, 9600, 19200, 38400 },
5214 { /* slowbaud & CBAUDEX */
5215 0, 57600, 115200, 230400,
5216 460800, 150, 200, 921600,
5217 600, 1200, 1800, 2400,
5218 4800, 9600, 19200, 38400 },
5220 0, 57600, 76800, 115200,
5221 14400, 57600, 230400, 76800,
5222 115200, 230400, 28800, 460800,
5223 921600, 9600, 19200, 38400 },
5224 { /* fastbaud & CBAUDEX */
5225 0, 57600, 115200, 230400,
5226 460800, 150, 200, 921600,
5227 600, 1200, 1800, 2400,
5228 4800, 9600, 19200, 38400 }
5232 * Only use the TXPrint baud rate if the
5233 * terminal unit is NOT open
5235 if (!(ch->ch_tun.un_flags & UN_ISOPEN) &&
5236 (un->un_type == DGAP_PRINT))
5237 baud = C_BAUD(ch->ch_pun.un_tty) & 0xff;
5239 baud = C_BAUD(ch->ch_tun.un_tty) & 0xff;
5241 if (ch->ch_c_cflag & CBAUDEX)
5244 if (ch->ch_digi.digi_flags & DIGI_FAST)
5249 if ((iindex >= 0) && (iindex < 4) &&
5250 (jindex >= 0) && (jindex < 16))
5251 baud = bauds[iindex][jindex];
5258 ch->ch_baud_info = baud;
5261 * CBAUD has bit position 0x1000 set these days to
5262 * indicate Linux baud rate remap.
5263 * We use a different bit assignment for high speed.
5264 * Clear this bit out while grabbing the parts of
5267 cflag = ch->ch_c_cflag & ((CBAUD ^ CBAUDEX) | PARODD | PARENB |
5271 * HUPCL bit is used by FEP to indicate fast baud
5272 * table is to be used.
5274 if ((ch->ch_digi.digi_flags & DIGI_FAST) ||
5275 (ch->ch_c_cflag & CBAUDEX))
5278 if ((ch->ch_c_cflag & CBAUDEX) &&
5279 !(ch->ch_digi.digi_flags & DIGI_FAST)) {
5281 * The below code is trying to guarantee that only
5282 * baud rates 115200, 230400, 460800, 921600 are
5283 * remapped. We use exclusive or because the various
5284 * baud rates share common bit positions and therefore
5285 * can't be tested for easily.
5287 tcflag_t tcflag = (ch->ch_c_cflag & CBAUD) | CBAUDEX;
5291 * Map high speed requests to index
5292 * into FEP's baud table
5322 cflag = (cflag & ~(CBAUD | CBAUDEX)) | baudpart;
5327 if (cflag != ch->ch_fepcflag) {
5328 ch->ch_fepcflag = (u16) (cflag & 0xffff);
5331 * Okay to have channel and board
5332 * locks held calling this
5334 dgap_cmdw(ch, SCFLAG, (u16) cflag, 0);
5337 /* Handle transition from B0 */
5338 if (ch->ch_flags & CH_BAUD0) {
5339 ch->ch_flags &= ~(CH_BAUD0);
5340 ch->ch_mval |= (D_RTS(ch)|D_DTR(ch));
5342 mval = D_DTR(ch) | D_RTS(ch);
5348 iflag = ch->ch_c_iflag & (IGNBRK | BRKINT | IGNPAR | PARMRK |
5349 INPCK | ISTRIP | IXON | IXANY | IXOFF);
5351 if ((ch->ch_startc == _POSIX_VDISABLE) ||
5352 (ch->ch_stopc == _POSIX_VDISABLE)) {
5353 iflag &= ~(IXON | IXOFF);
5354 ch->ch_c_iflag &= ~(IXON | IXOFF);
5358 * Only the IBM Xr card can switch between
5359 * 232 and 422 modes on the fly
5361 if (bd->device == PCI_DEV_XR_IBM_DID) {
5362 if (ch->ch_digi.digi_flags & DIGI_422)
5363 dgap_cmdb(ch, SCOMMODE, MODE_422, 0, 0);
5365 dgap_cmdb(ch, SCOMMODE, MODE_232, 0, 0);
5368 if (ch->ch_digi.digi_flags & DIGI_ALTPIN)
5371 if (iflag != ch->ch_fepiflag) {
5372 ch->ch_fepiflag = iflag;
5374 /* Okay to have channel and board locks held calling this */
5375 dgap_cmdw(ch, SIFLAG, (u16) ch->ch_fepiflag, 0);
5379 * Select hardware handshaking.
5383 if (ch->ch_c_cflag & CRTSCTS)
5384 hflow |= (D_RTS(ch) | D_CTS(ch));
5385 if (ch->ch_digi.digi_flags & RTSPACE)
5387 if (ch->ch_digi.digi_flags & DTRPACE)
5389 if (ch->ch_digi.digi_flags & CTSPACE)
5391 if (ch->ch_digi.digi_flags & DSRPACE)
5393 if (ch->ch_digi.digi_flags & DCDPACE)
5396 if (hflow != ch->ch_hflow) {
5397 ch->ch_hflow = hflow;
5399 /* Okay to have channel and board locks held calling this */
5400 dgap_cmdb(ch, SHFLOW, (u8) hflow, 0xff, 0);
5405 * Set RTS and/or DTR Toggle if needed,
5406 * but only if product is FEP5+ based.
5408 if (bd->bd_flags & BD_FEP5PLUS) {
5410 if (ch->ch_digi.digi_flags & DIGI_RTS_TOGGLE)
5411 hflow2 |= (D_RTS(ch));
5412 if (ch->ch_digi.digi_flags & DIGI_DTR_TOGGLE)
5413 hflow2 |= (D_DTR(ch));
5415 dgap_cmdw_ext(ch, 0xff03, hflow2, 0);
5419 * Set modem control lines.
5422 mval ^= ch->ch_mforce & (mval ^ ch->ch_mval);
5424 if (ch->ch_mostat ^ mval) {
5425 ch->ch_mostat = mval;
5427 /* Okay to have channel and board locks held calling this */
5428 dgap_cmdb(ch, SMODEM, (u8) mval, D_RTS(ch)|D_DTR(ch), 0);
5432 * Read modem signals, and then call carrier function.
5434 ch->ch_mistat = readb(&(bs->m_stat));
5438 * Set the start and stop characters.
5440 if (ch->ch_startc != ch->ch_fepstartc ||
5441 ch->ch_stopc != ch->ch_fepstopc) {
5442 ch->ch_fepstartc = ch->ch_startc;
5443 ch->ch_fepstopc = ch->ch_stopc;
5445 /* Okay to have channel and board locks held calling this */
5446 dgap_cmdb(ch, SFLOWC, ch->ch_fepstartc, ch->ch_fepstopc, 0);
5450 * Set the Auxiliary start and stop characters.
5452 if (ch->ch_astartc != ch->ch_fepastartc ||
5453 ch->ch_astopc != ch->ch_fepastopc) {
5454 ch->ch_fepastartc = ch->ch_astartc;
5455 ch->ch_fepastopc = ch->ch_astopc;
5457 /* Okay to have channel and board locks held calling this */
5458 dgap_cmdb(ch, SAFLOWC, ch->ch_fepastartc, ch->ch_fepastopc, 0);
5465 * dgap_parity_scan()
5467 * Convert the FEP5 way of reporting parity errors and breaks into
5468 * the Linux line discipline way.
5470 static void dgap_parity_scan(struct channel_t *ch, unsigned char *cbuf,
5471 unsigned char *fbuf, int *len)
5475 unsigned char *in, *cout, *fout;
5482 if (!ch || ch->magic != DGAP_CHANNEL_MAGIC)
5487 switch (ch->pscan_state) {
5489 /* reset to sanity and fall through */
5490 ch->pscan_state = 0;
5493 /* No FF seen yet */
5494 if (c == (unsigned char) '\377')
5495 /* delete this character from stream */
5496 ch->pscan_state = 1;
5499 *fout++ = TTY_NORMAL;
5506 if (c == (unsigned char) '\377') {
5507 /* doubled ff, transform to single ff */
5509 *fout++ = TTY_NORMAL;
5511 ch->pscan_state = 0;
5513 /* save value examination in next state */
5514 ch->pscan_savechar = c;
5515 ch->pscan_state = 2;
5520 /* third character of ff sequence */
5524 if (ch->pscan_savechar == 0x0) {
5528 *fout++ = TTY_BREAK;
5530 ch->ch_err_parity++;
5531 *fout++ = TTY_PARITY;
5536 ch->pscan_state = 0;
5542 static void dgap_write_wakeup(struct board_t *bd, struct channel_t *ch,
5543 struct un_t *un, u32 mask,
5544 unsigned long *irq_flags1,
5545 unsigned long *irq_flags2)
5547 if (!(un->un_flags & mask))
5550 un->un_flags &= ~mask;
5552 if (!(un->un_flags & UN_ISOPEN))
5555 if ((un->un_tty->flags & (1 << TTY_DO_WRITE_WAKEUP)) &&
5556 un->un_tty->ldisc->ops->write_wakeup) {
5557 spin_unlock_irqrestore(&ch->ch_lock, *irq_flags2);
5558 spin_unlock_irqrestore(&bd->bd_lock, *irq_flags1);
5560 (un->un_tty->ldisc->ops->write_wakeup)(un->un_tty);
5562 spin_lock_irqsave(&bd->bd_lock, *irq_flags1);
5563 spin_lock_irqsave(&ch->ch_lock, *irq_flags2);
5565 wake_up_interruptible(&un->un_tty->write_wait);
5566 wake_up_interruptible(&un->un_flags_wait);
5569 /*=======================================================================
5571 * dgap_event - FEP to host event processing routine.
5573 * bd - Board of current event.
5575 *=======================================================================*/
5576 static int dgap_event(struct board_t *bd)
5578 struct channel_t *ch;
5584 struct ev_t *eaddr = NULL;
5592 if (!bd || bd->magic != DGAP_BOARD_MAGIC)
5595 spin_lock_irqsave(&bd->bd_lock, lock_flags);
5597 vaddr = bd->re_map_membase;
5600 spin_unlock_irqrestore(&bd->bd_lock, lock_flags);
5604 eaddr = (struct ev_t *) (vaddr + EVBUF);
5606 /* Get our head and tail */
5607 head = readw(&(eaddr->ev_head));
5608 tail = readw(&(eaddr->ev_tail));
5611 * Forget it if pointers out of range.
5614 if (head >= EVMAX - EVSTART || tail >= EVMAX - EVSTART ||
5615 (head | tail) & 03) {
5616 /* Let go of board lock */
5617 spin_unlock_irqrestore(&bd->bd_lock, lock_flags);
5622 * Loop to process all the events in the buffer.
5624 while (tail != head) {
5627 * Get interrupt information.
5630 event = bd->re_map_membase + tail + EVSTART;
5638 * Make sure the interrupt is valid.
5640 if (port >= bd->nasync)
5643 if (!(reason & (IFMODEM | IFBREAK | IFTLW | IFTEM | IFDATA)))
5646 ch = bd->channels[port];
5648 if (!ch || ch->magic != DGAP_CHANNEL_MAGIC)
5652 * If we have made it here, the event was valid.
5653 * Lock down the channel.
5655 spin_lock_irqsave(&ch->ch_lock, lock_flags2);
5660 spin_unlock_irqrestore(&ch->ch_lock, lock_flags2);
5665 * Process received data.
5667 if (reason & IFDATA) {
5670 * ALL LOCKS *MUST* BE DROPPED BEFORE CALLING INPUT!
5671 * input could send some data to ld, which in turn
5672 * could do a callback to one of our other functions.
5674 spin_unlock_irqrestore(&ch->ch_lock, lock_flags2);
5675 spin_unlock_irqrestore(&bd->bd_lock, lock_flags);
5679 spin_lock_irqsave(&bd->bd_lock, lock_flags);
5680 spin_lock_irqsave(&ch->ch_lock, lock_flags2);
5682 if (ch->ch_flags & CH_RACTIVE)
5683 ch->ch_flags |= CH_RENABLE;
5685 writeb(1, &(bs->idata));
5687 if (ch->ch_flags & CH_RWAIT) {
5688 ch->ch_flags &= ~CH_RWAIT;
5690 wake_up_interruptible
5691 (&ch->ch_tun.un_flags_wait);
5696 * Process Modem change signals.
5698 if (reason & IFMODEM) {
5699 ch->ch_mistat = modem;
5706 if (reason & IFBREAK) {
5708 if (ch->ch_tun.un_tty) {
5709 /* A break has been indicated */
5711 tty_buffer_request_room
5712 (ch->ch_tun.un_tty->port, 1);
5713 tty_insert_flip_char(ch->ch_tun.un_tty->port,
5715 tty_flip_buffer_push(ch->ch_tun.un_tty->port);
5720 * Process Transmit low.
5722 if (reason & IFTLW) {
5723 dgap_write_wakeup(bd, ch, &ch->ch_tun, UN_LOW,
5724 &lock_flags, &lock_flags2);
5725 dgap_write_wakeup(bd, ch, &ch->ch_pun, UN_LOW,
5726 &lock_flags, &lock_flags2);
5727 if (ch->ch_flags & CH_WLOW) {
5728 ch->ch_flags &= ~CH_WLOW;
5729 wake_up_interruptible(&ch->ch_flags_wait);
5734 * Process Transmit empty.
5736 if (reason & IFTEM) {
5737 dgap_write_wakeup(bd, ch, &ch->ch_tun, UN_EMPTY,
5738 &lock_flags, &lock_flags2);
5739 dgap_write_wakeup(bd, ch, &ch->ch_pun, UN_EMPTY,
5740 &lock_flags, &lock_flags2);
5741 if (ch->ch_flags & CH_WEMPTY) {
5742 ch->ch_flags &= ~CH_WEMPTY;
5743 wake_up_interruptible(&ch->ch_flags_wait);
5747 spin_unlock_irqrestore(&ch->ch_lock, lock_flags2);
5750 tail = (tail + 4) & (EVMAX - EVSTART - 4);
5753 writew(tail, &(eaddr->ev_tail));
5754 spin_unlock_irqrestore(&bd->bd_lock, lock_flags);
5759 static ssize_t dgap_driver_version_show(struct device_driver *ddp, char *buf)
5761 return snprintf(buf, PAGE_SIZE, "%s\n", DG_PART);
5763 static DRIVER_ATTR(version, S_IRUSR, dgap_driver_version_show, NULL);
5766 static ssize_t dgap_driver_boards_show(struct device_driver *ddp, char *buf)
5768 return snprintf(buf, PAGE_SIZE, "%d\n", dgap_NumBoards);
5770 static DRIVER_ATTR(boards, S_IRUSR, dgap_driver_boards_show, NULL);
5773 static ssize_t dgap_driver_maxboards_show(struct device_driver *ddp, char *buf)
5775 return snprintf(buf, PAGE_SIZE, "%d\n", MAXBOARDS);
5777 static DRIVER_ATTR(maxboards, S_IRUSR, dgap_driver_maxboards_show, NULL);
5780 static ssize_t dgap_driver_pollcounter_show(struct device_driver *ddp,
5783 return snprintf(buf, PAGE_SIZE, "%ld\n", dgap_poll_counter);
5785 static DRIVER_ATTR(pollcounter, S_IRUSR, dgap_driver_pollcounter_show, NULL);
5787 static ssize_t dgap_driver_pollrate_show(struct device_driver *ddp, char *buf)
5789 return snprintf(buf, PAGE_SIZE, "%dms\n", dgap_poll_tick);
5792 static ssize_t dgap_driver_pollrate_store(struct device_driver *ddp,
5793 const char *buf, size_t count)
5795 if (sscanf(buf, "%d\n", &dgap_poll_tick) != 1)
5799 static DRIVER_ATTR(pollrate, (S_IRUSR | S_IWUSR), dgap_driver_pollrate_show,
5800 dgap_driver_pollrate_store);
5802 static int dgap_create_driver_sysfiles(struct pci_driver *dgap_driver)
5805 struct device_driver *driverfs = &dgap_driver->driver;
5807 rc |= driver_create_file(driverfs, &driver_attr_version);
5808 rc |= driver_create_file(driverfs, &driver_attr_boards);
5809 rc |= driver_create_file(driverfs, &driver_attr_maxboards);
5810 rc |= driver_create_file(driverfs, &driver_attr_pollrate);
5811 rc |= driver_create_file(driverfs, &driver_attr_pollcounter);
5816 static void dgap_remove_driver_sysfiles(struct pci_driver *dgap_driver)
5818 struct device_driver *driverfs = &dgap_driver->driver;
5819 driver_remove_file(driverfs, &driver_attr_version);
5820 driver_remove_file(driverfs, &driver_attr_boards);
5821 driver_remove_file(driverfs, &driver_attr_maxboards);
5822 driver_remove_file(driverfs, &driver_attr_pollrate);
5823 driver_remove_file(driverfs, &driver_attr_pollcounter);
5826 static struct board_t *dgap_verify_board(struct device *p)
5833 bd = dev_get_drvdata(p);
5834 if (!bd || bd->magic != DGAP_BOARD_MAGIC || bd->state != BOARD_READY)
5840 static ssize_t dgap_ports_state_show(struct device *p,
5841 struct device_attribute *attr,
5848 bd = dgap_verify_board(p);
5852 for (i = 0; i < bd->nasync; i++) {
5853 count += snprintf(buf + count, PAGE_SIZE - count,
5854 "%d %s\n", bd->channels[i]->ch_portnum,
5855 bd->channels[i]->ch_open_count ? "Open" : "Closed");
5859 static DEVICE_ATTR(ports_state, S_IRUSR, dgap_ports_state_show, NULL);
5861 static ssize_t dgap_ports_baud_show(struct device *p,
5862 struct device_attribute *attr,
5869 bd = dgap_verify_board(p);
5873 for (i = 0; i < bd->nasync; i++) {
5874 count += snprintf(buf + count, PAGE_SIZE - count, "%d %d\n",
5875 bd->channels[i]->ch_portnum,
5876 bd->channels[i]->ch_baud_info);
5880 static DEVICE_ATTR(ports_baud, S_IRUSR, dgap_ports_baud_show, NULL);
5882 static ssize_t dgap_ports_msignals_show(struct device *p,
5883 struct device_attribute *attr,
5890 bd = dgap_verify_board(p);
5894 for (i = 0; i < bd->nasync; i++) {
5895 if (bd->channels[i]->ch_open_count)
5896 count += snprintf(buf + count, PAGE_SIZE - count,
5897 "%d %s %s %s %s %s %s\n",
5898 bd->channels[i]->ch_portnum,
5899 (bd->channels[i]->ch_mostat &
5900 UART_MCR_RTS) ? "RTS" : "",
5901 (bd->channels[i]->ch_mistat &
5902 UART_MSR_CTS) ? "CTS" : "",
5903 (bd->channels[i]->ch_mostat &
5904 UART_MCR_DTR) ? "DTR" : "",
5905 (bd->channels[i]->ch_mistat &
5906 UART_MSR_DSR) ? "DSR" : "",
5907 (bd->channels[i]->ch_mistat &
5908 UART_MSR_DCD) ? "DCD" : "",
5909 (bd->channels[i]->ch_mistat &
5910 UART_MSR_RI) ? "RI" : "");
5912 count += snprintf(buf + count, PAGE_SIZE - count,
5913 "%d\n", bd->channels[i]->ch_portnum);
5917 static DEVICE_ATTR(ports_msignals, S_IRUSR, dgap_ports_msignals_show, NULL);
5919 static ssize_t dgap_ports_iflag_show(struct device *p,
5920 struct device_attribute *attr,
5927 bd = dgap_verify_board(p);
5931 for (i = 0; i < bd->nasync; i++)
5932 count += snprintf(buf + count, PAGE_SIZE - count, "%d %x\n",
5933 bd->channels[i]->ch_portnum,
5934 bd->channels[i]->ch_c_iflag);
5937 static DEVICE_ATTR(ports_iflag, S_IRUSR, dgap_ports_iflag_show, NULL);
5939 static ssize_t dgap_ports_cflag_show(struct device *p,
5940 struct device_attribute *attr,
5947 bd = dgap_verify_board(p);
5951 for (i = 0; i < bd->nasync; i++)
5952 count += snprintf(buf + count, PAGE_SIZE - count, "%d %x\n",
5953 bd->channels[i]->ch_portnum,
5954 bd->channels[i]->ch_c_cflag);
5957 static DEVICE_ATTR(ports_cflag, S_IRUSR, dgap_ports_cflag_show, NULL);
5959 static ssize_t dgap_ports_oflag_show(struct device *p,
5960 struct device_attribute *attr,
5967 bd = dgap_verify_board(p);
5971 for (i = 0; i < bd->nasync; i++)
5972 count += snprintf(buf + count, PAGE_SIZE - count, "%d %x\n",
5973 bd->channels[i]->ch_portnum,
5974 bd->channels[i]->ch_c_oflag);
5977 static DEVICE_ATTR(ports_oflag, S_IRUSR, dgap_ports_oflag_show, NULL);
5979 static ssize_t dgap_ports_lflag_show(struct device *p,
5980 struct device_attribute *attr,
5987 bd = dgap_verify_board(p);
5991 for (i = 0; i < bd->nasync; i++)
5992 count += snprintf(buf + count, PAGE_SIZE - count, "%d %x\n",
5993 bd->channels[i]->ch_portnum,
5994 bd->channels[i]->ch_c_lflag);
5997 static DEVICE_ATTR(ports_lflag, S_IRUSR, dgap_ports_lflag_show, NULL);
5999 static ssize_t dgap_ports_digi_flag_show(struct device *p,
6000 struct device_attribute *attr,
6007 bd = dgap_verify_board(p);
6011 for (i = 0; i < bd->nasync; i++)
6012 count += snprintf(buf + count, PAGE_SIZE - count, "%d %x\n",
6013 bd->channels[i]->ch_portnum,
6014 bd->channels[i]->ch_digi.digi_flags);
6017 static DEVICE_ATTR(ports_digi_flag, S_IRUSR, dgap_ports_digi_flag_show, NULL);
6019 static ssize_t dgap_ports_rxcount_show(struct device *p,
6020 struct device_attribute *attr,
6027 bd = dgap_verify_board(p);
6031 for (i = 0; i < bd->nasync; i++)
6032 count += snprintf(buf + count, PAGE_SIZE - count, "%d %ld\n",
6033 bd->channels[i]->ch_portnum,
6034 bd->channels[i]->ch_rxcount);
6037 static DEVICE_ATTR(ports_rxcount, S_IRUSR, dgap_ports_rxcount_show, NULL);
6039 static ssize_t dgap_ports_txcount_show(struct device *p,
6040 struct device_attribute *attr,
6047 bd = dgap_verify_board(p);
6051 for (i = 0; i < bd->nasync; i++)
6052 count += snprintf(buf + count, PAGE_SIZE - count, "%d %ld\n",
6053 bd->channels[i]->ch_portnum,
6054 bd->channels[i]->ch_txcount);
6057 static DEVICE_ATTR(ports_txcount, S_IRUSR, dgap_ports_txcount_show, NULL);
6059 /* this function creates the sys files that will export each signal status
6060 * to sysfs each value will be put in a separate filename
6062 static void dgap_create_ports_sysfiles(struct board_t *bd)
6064 dev_set_drvdata(&bd->pdev->dev, bd);
6065 device_create_file(&(bd->pdev->dev), &dev_attr_ports_state);
6066 device_create_file(&(bd->pdev->dev), &dev_attr_ports_baud);
6067 device_create_file(&(bd->pdev->dev), &dev_attr_ports_msignals);
6068 device_create_file(&(bd->pdev->dev), &dev_attr_ports_iflag);
6069 device_create_file(&(bd->pdev->dev), &dev_attr_ports_cflag);
6070 device_create_file(&(bd->pdev->dev), &dev_attr_ports_oflag);
6071 device_create_file(&(bd->pdev->dev), &dev_attr_ports_lflag);
6072 device_create_file(&(bd->pdev->dev), &dev_attr_ports_digi_flag);
6073 device_create_file(&(bd->pdev->dev), &dev_attr_ports_rxcount);
6074 device_create_file(&(bd->pdev->dev), &dev_attr_ports_txcount);
6077 /* removes all the sys files created for that port */
6078 static void dgap_remove_ports_sysfiles(struct board_t *bd)
6080 device_remove_file(&(bd->pdev->dev), &dev_attr_ports_state);
6081 device_remove_file(&(bd->pdev->dev), &dev_attr_ports_baud);
6082 device_remove_file(&(bd->pdev->dev), &dev_attr_ports_msignals);
6083 device_remove_file(&(bd->pdev->dev), &dev_attr_ports_iflag);
6084 device_remove_file(&(bd->pdev->dev), &dev_attr_ports_cflag);
6085 device_remove_file(&(bd->pdev->dev), &dev_attr_ports_oflag);
6086 device_remove_file(&(bd->pdev->dev), &dev_attr_ports_lflag);
6087 device_remove_file(&(bd->pdev->dev), &dev_attr_ports_digi_flag);
6088 device_remove_file(&(bd->pdev->dev), &dev_attr_ports_rxcount);
6089 device_remove_file(&(bd->pdev->dev), &dev_attr_ports_txcount);
6092 static ssize_t dgap_tty_state_show(struct device *d,
6093 struct device_attribute *attr,
6097 struct channel_t *ch;
6102 un = dev_get_drvdata(d);
6103 if (!un || un->magic != DGAP_UNIT_MAGIC)
6106 if (!ch || ch->magic != DGAP_CHANNEL_MAGIC)
6109 if (!bd || bd->magic != DGAP_BOARD_MAGIC)
6111 if (bd->state != BOARD_READY)
6114 return snprintf(buf, PAGE_SIZE, "%s", un->un_open_count ?
6117 static DEVICE_ATTR(state, S_IRUSR, dgap_tty_state_show, NULL);
6119 static ssize_t dgap_tty_baud_show(struct device *d,
6120 struct device_attribute *attr,
6124 struct channel_t *ch;
6129 un = dev_get_drvdata(d);
6130 if (!un || un->magic != DGAP_UNIT_MAGIC)
6133 if (!ch || ch->magic != DGAP_CHANNEL_MAGIC)
6136 if (!bd || bd->magic != DGAP_BOARD_MAGIC)
6138 if (bd->state != BOARD_READY)
6141 return snprintf(buf, PAGE_SIZE, "%d\n", ch->ch_baud_info);
6143 static DEVICE_ATTR(baud, S_IRUSR, dgap_tty_baud_show, NULL);
6145 static ssize_t dgap_tty_msignals_show(struct device *d,
6146 struct device_attribute *attr,
6150 struct channel_t *ch;
6155 un = dev_get_drvdata(d);
6156 if (!un || un->magic != DGAP_UNIT_MAGIC)
6159 if (!ch || ch->magic != DGAP_CHANNEL_MAGIC)
6162 if (!bd || bd->magic != DGAP_BOARD_MAGIC)
6164 if (bd->state != BOARD_READY)
6167 if (ch->ch_open_count) {
6168 return snprintf(buf, PAGE_SIZE, "%s %s %s %s %s %s\n",
6169 (ch->ch_mostat & UART_MCR_RTS) ? "RTS" : "",
6170 (ch->ch_mistat & UART_MSR_CTS) ? "CTS" : "",
6171 (ch->ch_mostat & UART_MCR_DTR) ? "DTR" : "",
6172 (ch->ch_mistat & UART_MSR_DSR) ? "DSR" : "",
6173 (ch->ch_mistat & UART_MSR_DCD) ? "DCD" : "",
6174 (ch->ch_mistat & UART_MSR_RI) ? "RI" : "");
6178 static DEVICE_ATTR(msignals, S_IRUSR, dgap_tty_msignals_show, NULL);
6180 static ssize_t dgap_tty_iflag_show(struct device *d,
6181 struct device_attribute *attr,
6185 struct channel_t *ch;
6190 un = dev_get_drvdata(d);
6191 if (!un || un->magic != DGAP_UNIT_MAGIC)
6194 if (!ch || ch->magic != DGAP_CHANNEL_MAGIC)
6197 if (!bd || bd->magic != DGAP_BOARD_MAGIC)
6199 if (bd->state != BOARD_READY)
6202 return snprintf(buf, PAGE_SIZE, "%x\n", ch->ch_c_iflag);
6204 static DEVICE_ATTR(iflag, S_IRUSR, dgap_tty_iflag_show, NULL);
6206 static ssize_t dgap_tty_cflag_show(struct device *d,
6207 struct device_attribute *attr,
6211 struct channel_t *ch;
6216 un = dev_get_drvdata(d);
6217 if (!un || un->magic != DGAP_UNIT_MAGIC)
6220 if (!ch || ch->magic != DGAP_CHANNEL_MAGIC)
6223 if (!bd || bd->magic != DGAP_BOARD_MAGIC)
6225 if (bd->state != BOARD_READY)
6228 return snprintf(buf, PAGE_SIZE, "%x\n", ch->ch_c_cflag);
6230 static DEVICE_ATTR(cflag, S_IRUSR, dgap_tty_cflag_show, NULL);
6232 static ssize_t dgap_tty_oflag_show(struct device *d,
6233 struct device_attribute *attr,
6237 struct channel_t *ch;
6242 un = dev_get_drvdata(d);
6243 if (!un || un->magic != DGAP_UNIT_MAGIC)
6246 if (!ch || ch->magic != DGAP_CHANNEL_MAGIC)
6249 if (!bd || bd->magic != DGAP_BOARD_MAGIC)
6251 if (bd->state != BOARD_READY)
6254 return snprintf(buf, PAGE_SIZE, "%x\n", ch->ch_c_oflag);
6256 static DEVICE_ATTR(oflag, S_IRUSR, dgap_tty_oflag_show, NULL);
6258 static ssize_t dgap_tty_lflag_show(struct device *d,
6259 struct device_attribute *attr,
6263 struct channel_t *ch;
6268 un = dev_get_drvdata(d);
6269 if (!un || un->magic != DGAP_UNIT_MAGIC)
6272 if (!ch || ch->magic != DGAP_CHANNEL_MAGIC)
6275 if (!bd || bd->magic != DGAP_BOARD_MAGIC)
6277 if (bd->state != BOARD_READY)
6280 return snprintf(buf, PAGE_SIZE, "%x\n", ch->ch_c_lflag);
6282 static DEVICE_ATTR(lflag, S_IRUSR, dgap_tty_lflag_show, NULL);
6284 static ssize_t dgap_tty_digi_flag_show(struct device *d,
6285 struct device_attribute *attr,
6289 struct channel_t *ch;
6294 un = dev_get_drvdata(d);
6295 if (!un || un->magic != DGAP_UNIT_MAGIC)
6298 if (!ch || ch->magic != DGAP_CHANNEL_MAGIC)
6301 if (!bd || bd->magic != DGAP_BOARD_MAGIC)
6303 if (bd->state != BOARD_READY)
6306 return snprintf(buf, PAGE_SIZE, "%x\n", ch->ch_digi.digi_flags);
6308 static DEVICE_ATTR(digi_flag, S_IRUSR, dgap_tty_digi_flag_show, NULL);
6310 static ssize_t dgap_tty_rxcount_show(struct device *d,
6311 struct device_attribute *attr,
6315 struct channel_t *ch;
6320 un = dev_get_drvdata(d);
6321 if (!un || un->magic != DGAP_UNIT_MAGIC)
6324 if (!ch || ch->magic != DGAP_CHANNEL_MAGIC)
6327 if (!bd || bd->magic != DGAP_BOARD_MAGIC)
6329 if (bd->state != BOARD_READY)
6332 return snprintf(buf, PAGE_SIZE, "%ld\n", ch->ch_rxcount);
6334 static DEVICE_ATTR(rxcount, S_IRUSR, dgap_tty_rxcount_show, NULL);
6336 static ssize_t dgap_tty_txcount_show(struct device *d,
6337 struct device_attribute *attr,
6341 struct channel_t *ch;
6346 un = dev_get_drvdata(d);
6347 if (!un || un->magic != DGAP_UNIT_MAGIC)
6350 if (!ch || ch->magic != DGAP_CHANNEL_MAGIC)
6353 if (!bd || bd->magic != DGAP_BOARD_MAGIC)
6355 if (bd->state != BOARD_READY)
6358 return snprintf(buf, PAGE_SIZE, "%ld\n", ch->ch_txcount);
6360 static DEVICE_ATTR(txcount, S_IRUSR, dgap_tty_txcount_show, NULL);
6362 static ssize_t dgap_tty_name_show(struct device *d,
6363 struct device_attribute *attr,
6367 struct channel_t *ch;
6371 struct cnode *cptr = NULL;
6379 un = dev_get_drvdata(d);
6380 if (!un || un->magic != DGAP_UNIT_MAGIC)
6383 if (!ch || ch->magic != DGAP_CHANNEL_MAGIC)
6386 if (!bd || bd->magic != DGAP_BOARD_MAGIC)
6388 if (bd->state != BOARD_READY)
6392 cn = ch->ch_portnum;
6394 for (cptr = bd->bd_config; cptr; cptr = cptr->next) {
6396 if ((cptr->type == BNODE) &&
6397 ((cptr->u.board.type == APORT2_920P) ||
6398 (cptr->u.board.type == APORT4_920P) ||
6399 (cptr->u.board.type == APORT8_920P) ||
6400 (cptr->u.board.type == PAPORT4) ||
6401 (cptr->u.board.type == PAPORT8))) {
6404 if (cptr->u.board.v_start)
6405 starto = cptr->u.board.start;
6410 if (cptr->type == TNODE && found == TRUE) {
6412 if (strstr(cptr->u.ttyname, "tty")) {
6413 ptr1 = cptr->u.ttyname;
6416 ptr1 = cptr->u.ttyname;
6418 for (i = 0; i < dgap_config_get_num_prts(bd); i++) {
6422 return snprintf(buf, PAGE_SIZE, "%s%s%02d\n",
6423 (un->un_type == DGAP_PRINT) ?
6429 if (cptr->type == CNODE) {
6431 for (i = 0; i < cptr->u.conc.nport; i++) {
6432 if (cn != (i + ncount))
6435 return snprintf(buf, PAGE_SIZE, "%s%s%02ld\n",
6436 (un->un_type == DGAP_PRINT) ?
6439 i + (cptr->u.conc.v_start ?
6440 cptr->u.conc.start : 1));
6443 ncount += cptr->u.conc.nport;
6446 if (cptr->type == MNODE) {
6448 for (i = 0; i < cptr->u.module.nport; i++) {
6449 if (cn != (i + ncount))
6452 return snprintf(buf, PAGE_SIZE, "%s%s%02ld\n",
6453 (un->un_type == DGAP_PRINT) ?
6456 i + (cptr->u.module.v_start ?
6457 cptr->u.module.start : 1));
6460 ncount += cptr->u.module.nport;
6465 return snprintf(buf, PAGE_SIZE, "%s_dgap_%d_%d\n",
6466 (un->un_type == DGAP_PRINT) ? "pr" : "tty", bn, cn);
6469 static DEVICE_ATTR(custom_name, S_IRUSR, dgap_tty_name_show, NULL);
6471 static struct attribute *dgap_sysfs_tty_entries[] = {
6472 &dev_attr_state.attr,
6473 &dev_attr_baud.attr,
6474 &dev_attr_msignals.attr,
6475 &dev_attr_iflag.attr,
6476 &dev_attr_cflag.attr,
6477 &dev_attr_oflag.attr,
6478 &dev_attr_lflag.attr,
6479 &dev_attr_digi_flag.attr,
6480 &dev_attr_rxcount.attr,
6481 &dev_attr_txcount.attr,
6482 &dev_attr_custom_name.attr,
6486 static struct attribute_group dgap_tty_attribute_group = {
6488 .attrs = dgap_sysfs_tty_entries,
6491 static void dgap_create_tty_sysfs(struct un_t *un, struct device *c)
6495 ret = sysfs_create_group(&c->kobj, &dgap_tty_attribute_group);
6499 dev_set_drvdata(c, un);
6503 static void dgap_remove_tty_sysfs(struct device *c)
6505 sysfs_remove_group(&c->kobj, &dgap_tty_attribute_group);
6509 * Parse a configuration file read into memory as a string.
6511 static int dgap_parsefile(char **in, int Remove)
6513 struct cnode *p, *brd, *line, *conc;
6519 brd = line = conc = NULL;
6521 /* perhaps we are adding to an existing list? */
6522 while (p->next != NULL)
6525 /* file must start with a BEGIN */
6526 while ((rc = dgap_gettok(in, p)) != BEGIN) {
6528 dgap_err("unexpected EOF");
6534 rc = dgap_gettok(in, p);
6536 dgap_err("unexpected EOF");
6542 dgap_err("unexpected end of file");
6545 case BEGIN: /* should only be 1 begin */
6546 dgap_err("unexpected config_begin\n");
6552 case BOARD: /* board info */
6553 if (dgap_checknode(p))
6555 p->next = dgap_newnode(BNODE);
6557 dgap_err("out of memory");
6562 p->u.board.status = dgap_savestring("No");
6568 case APORT2_920P: /* AccelePort_4 */
6569 if (p->type != BNODE) {
6570 dgap_err("unexpected Digi_2r_920 string");
6573 p->u.board.type = APORT2_920P;
6574 p->u.board.v_type = 1;
6577 case APORT4_920P: /* AccelePort_4 */
6578 if (p->type != BNODE) {
6579 dgap_err("unexpected Digi_4r_920 string");
6582 p->u.board.type = APORT4_920P;
6583 p->u.board.v_type = 1;
6586 case APORT8_920P: /* AccelePort_8 */
6587 if (p->type != BNODE) {
6588 dgap_err("unexpected Digi_8r_920 string");
6591 p->u.board.type = APORT8_920P;
6592 p->u.board.v_type = 1;
6595 case PAPORT4: /* AccelePort_4 PCI */
6596 if (p->type != BNODE) {
6597 dgap_err("unexpected Digi_4r(PCI) string");
6600 p->u.board.type = PAPORT4;
6601 p->u.board.v_type = 1;
6604 case PAPORT8: /* AccelePort_8 PCI */
6605 if (p->type != BNODE) {
6606 dgap_err("unexpected Digi_8r string");
6609 p->u.board.type = PAPORT8;
6610 p->u.board.v_type = 1;
6613 case PCX: /* PCI C/X */
6614 if (p->type != BNODE) {
6615 dgap_err("unexpected Digi_C/X_(PCI) string");
6618 p->u.board.type = PCX;
6619 p->u.board.v_type = 1;
6620 p->u.board.conc1 = 0;
6621 p->u.board.conc2 = 0;
6622 p->u.board.module1 = 0;
6623 p->u.board.module2 = 0;
6626 case PEPC: /* PCI EPC/X */
6627 if (p->type != BNODE) {
6628 dgap_err("unexpected \"Digi_EPC/X_(PCI)\" string");
6631 p->u.board.type = PEPC;
6632 p->u.board.v_type = 1;
6633 p->u.board.conc1 = 0;
6634 p->u.board.conc2 = 0;
6635 p->u.board.module1 = 0;
6636 p->u.board.module2 = 0;
6639 case PPCM: /* PCI/Xem */
6640 if (p->type != BNODE) {
6641 dgap_err("unexpected PCI/Xem string");
6644 p->u.board.type = PPCM;
6645 p->u.board.v_type = 1;
6646 p->u.board.conc1 = 0;
6647 p->u.board.conc2 = 0;
6650 case IO: /* i/o port */
6651 if (p->type != BNODE) {
6652 dgap_err("IO port only vaild for boards");
6655 s = dgap_getword(in);
6657 dgap_err("unexpected end of file");
6660 p->u.board.portstr = dgap_savestring(s);
6661 if (kstrtol(s, 0, &p->u.board.port)) {
6662 dgap_err("bad number for IO port");
6665 p->u.board.v_port = 1;
6668 case MEM: /* memory address */
6669 if (p->type != BNODE) {
6670 dgap_err("memory address only vaild for boards");
6673 s = dgap_getword(in);
6675 dgap_err("unexpected end of file");
6678 p->u.board.addrstr = dgap_savestring(s);
6679 if (kstrtoul(s, 0, &p->u.board.addr)) {
6680 dgap_err("bad number for memory address");
6683 p->u.board.v_addr = 1;
6686 case PCIINFO: /* pci information */
6687 if (p->type != BNODE) {
6688 dgap_err("memory address only vaild for boards");
6691 s = dgap_getword(in);
6693 dgap_err("unexpected end of file");
6696 p->u.board.pcibusstr = dgap_savestring(s);
6697 if (kstrtoul(s, 0, &p->u.board.pcibus)) {
6698 dgap_err("bad number for pci bus");
6701 p->u.board.v_pcibus = 1;
6702 s = dgap_getword(in);
6704 dgap_err("unexpected end of file");
6707 p->u.board.pcislotstr = dgap_savestring(s);
6708 if (kstrtoul(s, 0, &p->u.board.pcislot)) {
6709 dgap_err("bad number for pci slot");
6712 p->u.board.v_pcislot = 1;
6716 if (p->type != BNODE) {
6717 dgap_err("install method only vaild for boards");
6720 s = dgap_getword(in);
6722 dgap_err("unexpected end of file");
6725 p->u.board.method = dgap_savestring(s);
6726 p->u.board.v_method = 1;
6730 if (p->type != BNODE) {
6731 dgap_err("config status only vaild for boards");
6734 s = dgap_getword(in);
6736 dgap_err("unexpected end of file");
6739 p->u.board.status = dgap_savestring(s);
6742 case NPORTS: /* number of ports */
6743 if (p->type == BNODE) {
6744 s = dgap_getword(in);
6746 dgap_err("unexpected end of file");
6749 if (kstrtol(s, 0, &p->u.board.nport)) {
6750 dgap_err("bad number for number of ports");
6753 p->u.board.v_nport = 1;
6754 } else if (p->type == CNODE) {
6755 s = dgap_getword(in);
6757 dgap_err("unexpected end of file");
6760 if (kstrtol(s, 0, &p->u.conc.nport)) {
6761 dgap_err("bad number for number of ports");
6764 p->u.conc.v_nport = 1;
6765 } else if (p->type == MNODE) {
6766 s = dgap_getword(in);
6768 dgap_err("unexpected end of file");
6771 if (kstrtol(s, 0, &p->u.module.nport)) {
6772 dgap_err("bad number for number of ports");
6775 p->u.module.v_nport = 1;
6777 dgap_err("nports only valid for concentrators or modules");
6782 case ID: /* letter ID used in tty name */
6783 s = dgap_getword(in);
6785 dgap_err("unexpected end of file");
6789 p->u.board.status = dgap_savestring(s);
6791 if (p->type == CNODE) {
6792 p->u.conc.id = dgap_savestring(s);
6794 } else if (p->type == MNODE) {
6795 p->u.module.id = dgap_savestring(s);
6796 p->u.module.v_id = 1;
6798 dgap_err("id only valid for concentrators or modules");
6803 case STARTO: /* start offset of ID */
6804 if (p->type == BNODE) {
6805 s = dgap_getword(in);
6807 dgap_err("unexpected end of file");
6810 if (kstrtol(s, 0, &p->u.board.start)) {
6811 dgap_err("bad number for start of tty count");
6814 p->u.board.v_start = 1;
6815 } else if (p->type == CNODE) {
6816 s = dgap_getword(in);
6818 dgap_err("unexpected end of file");
6821 if (kstrtol(s, 0, &p->u.conc.start)) {
6822 dgap_err("bad number for start of tty count");
6825 p->u.conc.v_start = 1;
6826 } else if (p->type == MNODE) {
6827 s = dgap_getword(in);
6829 dgap_err("unexpected end of file");
6832 if (kstrtol(s, 0, &p->u.module.start)) {
6833 dgap_err("bad number for start of tty count");
6836 p->u.module.v_start = 1;
6838 dgap_err("start only valid for concentrators or modules");
6843 case TTYN: /* tty name prefix */
6844 if (dgap_checknode(p))
6846 p->next = dgap_newnode(TNODE);
6848 dgap_err("out of memory");
6852 s = dgap_getword(in);
6854 dgap_err("unexpeced end of file");
6857 p->u.ttyname = dgap_savestring(s);
6858 if (!p->u.ttyname) {
6859 dgap_err("out of memory");
6864 case CU: /* cu name prefix */
6865 if (dgap_checknode(p))
6867 p->next = dgap_newnode(CUNODE);
6869 dgap_err("out of memory");
6873 s = dgap_getword(in);
6875 dgap_err("unexpeced end of file");
6878 p->u.cuname = dgap_savestring(s);
6880 dgap_err("out of memory");
6885 case LINE: /* line information */
6886 if (dgap_checknode(p))
6889 dgap_err("must specify board before line info");
6892 switch (brd->u.board.type) {
6894 dgap_err("line not vaild for PC/em");
6897 p->next = dgap_newnode(LNODE);
6899 dgap_err("out of memory");
6908 case CONC: /* concentrator information */
6909 if (dgap_checknode(p))
6912 dgap_err("must specify line info before concentrator");
6915 p->next = dgap_newnode(CNODE);
6917 dgap_err("out of memory");
6923 brd->u.board.conc2++;
6925 brd->u.board.conc1++;
6929 case CX: /* c/x type concentrator */
6930 if (p->type != CNODE) {
6931 dgap_err("cx only valid for concentrators");
6934 p->u.conc.type = CX;
6935 p->u.conc.v_type = 1;
6938 case EPC: /* epc type concentrator */
6939 if (p->type != CNODE) {
6940 dgap_err("cx only valid for concentrators");
6943 p->u.conc.type = EPC;
6944 p->u.conc.v_type = 1;
6947 case MOD: /* EBI module */
6948 if (dgap_checknode(p))
6951 dgap_err("must specify board info before EBI modules");
6954 switch (brd->u.board.type) {
6960 dgap_err("must specify concentrator info before EBI module");
6964 p->next = dgap_newnode(MNODE);
6966 dgap_err("out of memory");
6971 brd->u.board.module2++;
6973 brd->u.board.module1++;
6977 case PORTS: /* ports type EBI module */
6978 if (p->type != MNODE) {
6979 dgap_err("ports only valid for EBI modules");
6982 p->u.module.type = PORTS;
6983 p->u.module.v_type = 1;
6986 case MODEM: /* ports type EBI module */
6987 if (p->type != MNODE) {
6988 dgap_err("modem only valid for modem modules");
6991 p->u.module.type = MODEM;
6992 p->u.module.v_type = 1;
6996 if (p->type == LNODE) {
6997 s = dgap_getword(in);
6999 dgap_err("unexpected end of file");
7002 p->u.line.cable = dgap_savestring(s);
7003 p->u.line.v_cable = 1;
7007 case SPEED: /* sync line speed indication */
7008 if (p->type == LNODE) {
7009 s = dgap_getword(in);
7011 dgap_err("unexpected end of file");
7014 if (kstrtol(s, 0, &p->u.line.speed)) {
7015 dgap_err("bad number for line speed");
7018 p->u.line.v_speed = 1;
7019 } else if (p->type == CNODE) {
7020 s = dgap_getword(in);
7022 dgap_err("unexpected end of file");
7025 if (kstrtol(s, 0, &p->u.conc.speed)) {
7026 dgap_err("bad number for line speed");
7029 p->u.conc.v_speed = 1;
7031 dgap_err("speed valid only for lines or concentrators.");
7037 if (p->type == CNODE) {
7038 s = dgap_getword(in);
7040 dgap_err("unexpected end of file");
7043 p->u.conc.connect = dgap_savestring(s);
7044 p->u.conc.v_connect = 1;
7047 case PRINT: /* transparent print name prefix */
7048 if (dgap_checknode(p))
7050 p->next = dgap_newnode(PNODE);
7052 dgap_err("out of memory");
7056 s = dgap_getword(in);
7058 dgap_err("unexpeced end of file");
7061 p->u.printname = dgap_savestring(s);
7062 if (!p->u.printname) {
7063 dgap_err("out of memory");
7068 case CMAJOR: /* major number */
7069 if (dgap_checknode(p))
7071 p->next = dgap_newnode(JNODE);
7073 dgap_err("out of memory");
7077 s = dgap_getword(in);
7079 dgap_err("unexpected end of file");
7082 if (kstrtol(s, 0, &p->u.majornumber)) {
7083 dgap_err("bad number for major number");
7088 case ALTPIN: /* altpin setting */
7089 if (dgap_checknode(p))
7091 p->next = dgap_newnode(ANODE);
7093 dgap_err("out of memory");
7097 s = dgap_getword(in);
7099 dgap_err("unexpected end of file");
7102 if (kstrtol(s, 0, &p->u.altpin)) {
7103 dgap_err("bad number for altpin");
7108 case USEINTR: /* enable interrupt setting */
7109 if (dgap_checknode(p))
7111 p->next = dgap_newnode(INTRNODE);
7113 dgap_err("out of memory");
7117 s = dgap_getword(in);
7119 dgap_err("unexpected end of file");
7122 if (kstrtol(s, 0, &p->u.useintr)) {
7123 dgap_err("bad number for useintr");
7128 case TTSIZ: /* size of tty structure */
7129 if (dgap_checknode(p))
7131 p->next = dgap_newnode(TSNODE);
7133 dgap_err("out of memory");
7137 s = dgap_getword(in);
7139 dgap_err("unexpected end of file");
7142 if (kstrtol(s, 0, &p->u.ttysize)) {
7143 dgap_err("bad number for ttysize");
7148 case CHSIZ: /* channel structure size */
7149 if (dgap_checknode(p))
7151 p->next = dgap_newnode(CSNODE);
7153 dgap_err("out of memory");
7157 s = dgap_getword(in);
7159 dgap_err("unexpected end of file");
7162 if (kstrtol(s, 0, &p->u.chsize)) {
7163 dgap_err("bad number for chsize");
7168 case BSSIZ: /* board structure size */
7169 if (dgap_checknode(p))
7171 p->next = dgap_newnode(BSNODE);
7173 dgap_err("out of memory");
7177 s = dgap_getword(in);
7179 dgap_err("unexpected end of file");
7182 if (kstrtol(s, 0, &p->u.bssize)) {
7183 dgap_err("bad number for bssize");
7188 case UNTSIZ: /* sched structure size */
7189 if (dgap_checknode(p))
7191 p->next = dgap_newnode(USNODE);
7193 dgap_err("out of memory");
7197 s = dgap_getword(in);
7199 dgap_err("unexpected end of file");
7202 if (kstrtol(s, 0, &p->u.unsize)) {
7203 dgap_err("bad number for schedsize");
7208 case F2SIZ: /* f2200 structure size */
7209 if (dgap_checknode(p))
7211 p->next = dgap_newnode(FSNODE);
7213 dgap_err("out of memory");
7217 s = dgap_getword(in);
7219 dgap_err("unexpected end of file");
7222 if (kstrtol(s, 0, &p->u.f2size)) {
7223 dgap_err("bad number for f2200size");
7228 case VPSIZ: /* vpix structure size */
7229 if (dgap_checknode(p))
7231 p->next = dgap_newnode(VSNODE);
7233 dgap_err("out of memory");
7237 s = dgap_getword(in);
7239 dgap_err("unexpected end of file");
7242 if (kstrtol(s, 0, &p->u.vpixsize)) {
7243 dgap_err("bad number for vpixsize");
7252 * dgap_sindex: much like index(), but it looks for a match of any character in
7253 * the group, and returns that position. If the first character is a ^, then
7254 * this will match the first occurrence not in that group.
7256 static char *dgap_sindex(char *string, char *group)
7260 if (!string || !group)
7261 return (char *) NULL;
7263 if (*group == '^') {
7265 for (; *string; string++) {
7266 for (ptr = group; *ptr; ptr++) {
7267 if (*ptr == *string)
7274 for (; *string; string++) {
7275 for (ptr = group; *ptr; ptr++) {
7276 if (*ptr == *string)
7282 return (char *) NULL;
7286 * Get a token from the input file; return 0 if end of file is reached
7288 static int dgap_gettok(char **in, struct cnode *p)
7293 if (strstr(dgap_cword, "boar")) {
7294 w = dgap_getword(in);
7295 snprintf(dgap_cword, MAXCWORD, "%s", w);
7296 for (t = dgap_tlist; t->token != 0; t++) {
7297 if (!strcmp(w, t->string))
7300 dgap_err("board !!type not specified");
7303 while ((w = dgap_getword(in))) {
7304 snprintf(dgap_cword, MAXCWORD, "%s", w);
7305 for (t = dgap_tlist; t->token != 0; t++) {
7306 if (!strcmp(w, t->string))
7315 * get a word from the input stream, also keep track of current line number.
7316 * words are separated by whitespace.
7318 static char *dgap_getword(char **in)
7320 char *ret_ptr = *in;
7322 char *ptr = dgap_sindex(*in, " \t\n");
7324 /* If no word found, return null */
7328 /* Mark new location for our buffer */
7332 /* Eat any extra spaces/tabs/newlines that might be present */
7333 while (*in && **in && ((**in == ' ') ||
7344 * print an error message, giving the line number in the file where
7345 * the error occurred.
7347 static void dgap_err(char *s)
7349 pr_err("dgap: parse: %s\n", s);
7353 * allocate a new configuration node of type t
7355 static struct cnode *dgap_newnode(int t)
7359 n = kmalloc(sizeof(struct cnode), GFP_ATOMIC);
7361 memset((char *)n, 0, sizeof(struct cnode));
7368 * dgap_checknode: see if all the necessary info has been supplied for a node
7369 * before creating the next node.
7371 static int dgap_checknode(struct cnode *p)
7375 if (p->u.board.v_type == 0) {
7376 dgap_err("board type !not specified");
7383 if (p->u.line.v_speed == 0) {
7384 dgap_err("line speed not specified");
7390 if (p->u.conc.v_type == 0) {
7391 dgap_err("concentrator type not specified");
7394 if (p->u.conc.v_speed == 0) {
7395 dgap_err("concentrator line speed not specified");
7398 if (p->u.conc.v_nport == 0) {
7399 dgap_err("number of ports on concentrator not specified");
7402 if (p->u.conc.v_id == 0) {
7403 dgap_err("concentrator id letter not specified");
7409 if (p->u.module.v_type == 0) {
7410 dgap_err("EBI module type not specified");
7413 if (p->u.module.v_nport == 0) {
7414 dgap_err("number of ports on EBI module not specified");
7417 if (p->u.module.v_id == 0) {
7418 dgap_err("EBI module id letter not specified");
7427 * save a string somewhere
7429 static char *dgap_savestring(char *s)
7433 p = kmalloc(strlen(s) + 1, GFP_ATOMIC);
7440 * Given a board pointer, returns whether we should use interrupts or not.
7442 static uint dgap_config_get_useintr(struct board_t *bd)
7444 struct cnode *p = NULL;
7449 for (p = bd->bd_config; p; p = p->next) {
7453 * check for pcxr types.
7455 return p->u.useintr;
7461 /* If not found, then don't turn on interrupts. */
7466 * Given a board pointer, returns whether we turn on altpin or not.
7468 static uint dgap_config_get_altpin(struct board_t *bd)
7470 struct cnode *p = NULL;
7475 for (p = bd->bd_config; p; p = p->next) {
7479 * check for pcxr types.
7487 /* If not found, then don't turn on interrupts. */
7492 * Given a specific type of board, if found, detached link and
7493 * returns the first occurrence in the list.
7495 static struct cnode *dgap_find_config(int type, int bus, int slot)
7497 struct cnode *p, *prev = NULL, *prev2 = NULL, *found = NULL;
7501 while (p->next != NULL) {
7505 if (p->type == BNODE) {
7507 if (p->u.board.type == type) {
7509 if (p->u.board.v_pcibus &&
7510 p->u.board.pcibus != bus)
7512 if (p->u.board.v_pcislot &&
7513 p->u.board.pcislot != slot)
7518 * Keep walking thru the list till we
7519 * find the next board.
7521 while (p->next != NULL) {
7524 if (p->type == BNODE) {
7527 * Mark the end of our 1 board
7533 * Link the "next" board to the
7534 * previous board, effectively
7535 * "unlinking" our board from
7544 * It must be the last board in the list.
7555 * Given a board pointer, walks the config link, counting up
7556 * all ports user specified should be on the board.
7557 * (This does NOT mean they are all actually present right now tho)
7559 static uint dgap_config_get_num_prts(struct board_t *bd)
7562 struct cnode *p = NULL;
7567 for (p = bd->bd_config; p; p = p->next) {
7572 * check for pcxr types.
7574 if (p->u.board.type > EPCFE)
7575 count += p->u.board.nport;
7578 count += p->u.conc.nport;
7581 count += p->u.module.nport;
7588 static char *dgap_create_config_string(struct board_t *bd, char *string)
7591 struct cnode *p = NULL;
7592 struct cnode *q = NULL;
7600 for (p = bd->bd_config; p; p = p->next) {
7606 *ptr = p->u.line.speed;
7611 * Because the EPC/con concentrators can have EM modules
7612 * hanging off of them, we have to walk ahead in the
7613 * list and keep adding the number of ports on each EM
7614 * to the config. UGH!
7616 speed = p->u.conc.speed;
7618 if ((q != NULL) && (q->type == MNODE)) {
7619 *ptr = (p->u.conc.nport + 0x80);
7622 while ((q->next != NULL) &&
7623 (q->next->type) == MNODE) {
7625 *ptr = (q->u.module.nport + 0x80);
7630 *ptr = q->u.module.nport;
7633 *ptr = p->u.conc.nport;