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 dgap_board_fops = {
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_boards_by_major[256];
224 static uint dgap_count = 500;
229 static 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", NULL, 0 },
322 { "dgap/dgap.conf", "dgap/cxpbios.bin", "dgap/cxpfep.bin", NULL, 1 },
323 { "dgap/dgap.conf", "dgap/cxpbios.bin", "dgap/cxpfep.bin", NULL, 2 },
324 { "dgap/dgap.conf", "dgap/pcibios.bin", "dgap/pcifep.bin", NULL, 3 },
325 { "dgap/dgap.conf", "dgap/xrbios.bin", "dgap/xrfep.bin", NULL, 4 },
326 { "dgap/dgap.conf", "dgap/xrbios.bin", "dgap/xrfep.bin", NULL, 5 },
327 { "dgap/dgap.conf", "dgap/xrbios.bin", "dgap/xrfep.bin", NULL, 6 },
328 { "dgap/dgap.conf", "dgap/xrbios.bin", "dgap/xrfep.bin", NULL, 7 },
329 { "dgap/dgap.conf", "dgap/xrbios.bin", "dgap/xrfep.bin", NULL, 8 },
330 { "dgap/dgap.conf", "dgap/xrbios.bin", "dgap/xrfep.bin", NULL, 9 },
331 { "dgap/dgap.conf", "dgap/xrbios.bin", "dgap/xrfep.bin", NULL, 10 },
332 { "dgap/dgap.conf", "dgap/xrbios.bin", "dgap/xrfep.bin", NULL, 11 },
333 { "dgap/dgap.conf", "dgap/xrbios.bin", "dgap/xrfep.bin", NULL, 12 },
334 { "dgap/dgap.conf", "dgap/xrbios.bin", "dgap/xrfep.bin", NULL, 13 },
335 { "dgap/dgap.conf", "dgap/sxbios.bin", "dgap/sxfep.bin", NULL, 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 dgap_default_termios = {
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", &dgap_board_fops);
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 if (dgap_numboards >= MAXBOARDS)
578 rc = pci_enable_device(pdev);
582 rc = dgap_probe1(pdev, ent->driver_data);
587 return 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 ret = dgap_tty_register(brd);
889 ret = dgap_finalize_board_init(brd);
893 if (fw_info[card_type].bios_name) {
894 ret = request_firmware(&fw, fw_info[card_type].bios_name,
897 pr_err("dgap: bios file %s not found\n",
898 fw_info[card_type].bios_name);
901 dgap_do_bios_load(brd, fw->data, fw->size);
902 release_firmware(fw);
904 /* Wait for BIOS to test board... */
905 ret = dgap_test_bios(brd);
910 if (fw_info[card_type].fep_name) {
911 ret = request_firmware(&fw, fw_info[card_type].fep_name,
914 pr_err("dgap: fep file %s not found\n",
915 fw_info[card_type].fep_name);
918 dgap_do_fep_load(brd, fw->data, fw->size);
919 release_firmware(fw);
921 /* Wait for FEP to load on board... */
922 ret = dgap_test_fep(brd);
927 #ifdef DIGI_CONCENTRATORS_SUPPORTED
929 * If this is a CX or EPCX, we need to see if the firmware
930 * is requesting a concentrator image from us.
932 if ((bd->type == PCX) || (bd->type == PEPC)) {
933 chk_addr = (u16 *) (vaddr + DOWNREQ);
934 /* Nonzero if FEP is requesting concentrator image. */
935 check = readw(chk_addr);
936 vaddr = brd->re_map_membase;
939 if (fw_info[card_type].con_name && check && vaddr) {
940 ret = request_firmware(&fw, fw_info[card_type].con_name,
943 pr_err("dgap: conc file %s not found\n",
944 fw_info[card_type].con_name);
947 /* Put concentrator firmware loading code here */
948 offset = readw((u16 *) (vaddr + DOWNREQ));
949 memcpy_toio(offset, fw->data, fw->size);
951 dgap_do_conc_load(brd, (char *)fw->data, fw->size)
952 release_firmware(fw);
956 * Do tty device initialization.
958 ret = dgap_tty_init(brd);
960 dgap_tty_uninit(brd);
964 ret = dgap_tty_register_ports(brd);
968 brd->state = BOARD_READY;
969 brd->dpastatus = BD_RUNNING;
977 static int dgap_do_remap(struct board_t *brd)
979 if (!brd || brd->magic != DGAP_BOARD_MAGIC)
982 if (!request_mem_region(brd->membase, 0x200000, "dgap"))
985 if (!request_mem_region(brd->membase + PCI_IO_OFFSET, 0x200000,
987 release_mem_region(brd->membase, 0x200000);
991 brd->re_map_membase = ioremap(brd->membase, 0x200000);
992 if (!brd->re_map_membase) {
993 release_mem_region(brd->membase, 0x200000);
994 release_mem_region(brd->membase + PCI_IO_OFFSET, 0x200000);
998 brd->re_map_port = ioremap((brd->membase + PCI_IO_OFFSET), 0x200000);
999 if (!brd->re_map_port) {
1000 release_mem_region(brd->membase, 0x200000);
1001 release_mem_region(brd->membase + PCI_IO_OFFSET, 0x200000);
1002 iounmap(brd->re_map_membase);
1009 /*****************************************************************************
1029 * As each timer expires, it determines (a) whether the "transmit"
1030 * waiter needs to be woken up, and (b) whether the poller needs to
1033 ******************************************************************************/
1035 static void dgap_poll_handler(ulong dummy)
1038 struct board_t *brd;
1039 unsigned long lock_flags;
1042 dgap_poll_counter++;
1045 * Do not start the board state machine until
1046 * driver tells us its up and running, and has
1047 * everything it needs.
1049 if (dgap_driver_state != DRIVER_READY)
1050 goto schedule_poller;
1053 * If we have just 1 board, or the system is not SMP,
1054 * then use the typical old style poller.
1055 * Otherwise, use our new tasklet based poller, which should
1056 * speed things up for multiple boards.
1058 if ((dgap_numboards == 1) || (num_online_cpus() <= 1)) {
1059 for (i = 0; i < dgap_numboards; i++) {
1061 brd = dgap_board[i];
1063 if (brd->state == BOARD_FAILED)
1065 if (!brd->intr_running)
1066 /* Call the real board poller directly */
1067 dgap_poll_tasklet((unsigned long) brd);
1071 * Go thru each board, kicking off a
1072 * tasklet for each if needed
1074 for (i = 0; i < dgap_numboards; i++) {
1075 brd = dgap_board[i];
1078 * Attempt to grab the board lock.
1080 * If we can't get it, no big deal, the next poll
1081 * will get it. Basically, I just really don't want
1082 * to spin in here, because I want to kick off my
1083 * tasklets as fast as I can, and then get out the
1086 if (!spin_trylock(&brd->bd_lock))
1090 * If board is in a failed state, don't bother
1091 * scheduling a tasklet
1093 if (brd->state == BOARD_FAILED) {
1094 spin_unlock(&brd->bd_lock);
1098 /* Schedule a poll helper task */
1099 if (!brd->intr_running)
1100 tasklet_schedule(&brd->helper_tasklet);
1103 * Can't do DGAP_UNLOCK here, as we don't have
1104 * lock_flags because we did a trylock above.
1106 spin_unlock(&brd->bd_lock);
1113 * Schedule ourself back at the nominal wakeup interval.
1115 spin_lock_irqsave(&dgap_poll_lock, lock_flags);
1116 dgap_poll_time += dgap_jiffies_from_ms(dgap_poll_tick);
1118 new_time = dgap_poll_time - jiffies;
1120 if ((ulong) new_time >= 2 * dgap_poll_tick) {
1122 jiffies + dgap_jiffies_from_ms(dgap_poll_tick);
1125 dgap_poll_timer.function = dgap_poll_handler;
1126 dgap_poll_timer.data = 0;
1127 dgap_poll_timer.expires = dgap_poll_time;
1128 spin_unlock_irqrestore(&dgap_poll_lock, lock_flags);
1130 if (!dgap_poll_stop)
1131 add_timer(&dgap_poll_timer);
1137 * Driver interrupt handler.
1139 static irqreturn_t dgap_intr(int irq, void *voidbrd)
1141 struct board_t *brd = (struct board_t *) voidbrd;
1147 * Check to make sure its for us.
1149 if (brd->magic != DGAP_BOARD_MAGIC)
1155 * Schedule tasklet to run at a better time.
1157 tasklet_schedule(&brd->helper_tasklet);
1162 * dgap_init_globals()
1164 * This is where we initialize the globals from the static insmod
1165 * configuration variables. These are declared near the head of
1168 static void dgap_init_globals(void)
1172 for (i = 0; i < MAXBOARDS; i++)
1173 dgap_board[i] = NULL;
1175 init_timer(&dgap_poll_timer);
1177 init_waitqueue_head(&dgap_dl_wait);
1180 /************************************************************************
1184 ************************************************************************/
1189 * Put the driver to sleep for x ms's
1191 * Returns 0 if timed out, !0 (showing signal) if interrupted by a signal.
1193 static int dgap_ms_sleep(ulong ms)
1195 current->state = TASK_INTERRUPTIBLE;
1196 schedule_timeout((ms * HZ) / 1000);
1197 return signal_pending(current);
1200 /************************************************************************
1202 * TTY Initialization/Cleanup Functions
1204 ************************************************************************/
1207 * dgap_tty_register()
1209 * Init the tty subsystem for this board.
1211 static int dgap_tty_register(struct board_t *brd)
1215 brd->serial_driver = alloc_tty_driver(MAXPORTS);
1217 snprintf(brd->serial_name, MAXTTYNAMELEN, "tty_dgap_%d_",
1219 brd->serial_driver->name = brd->serial_name;
1220 brd->serial_driver->name_base = 0;
1221 brd->serial_driver->major = 0;
1222 brd->serial_driver->minor_start = 0;
1223 brd->serial_driver->type = TTY_DRIVER_TYPE_SERIAL;
1224 brd->serial_driver->subtype = SERIAL_TYPE_NORMAL;
1225 brd->serial_driver->init_termios = dgap_default_termios;
1226 brd->serial_driver->driver_name = DRVSTR;
1227 brd->serial_driver->flags = (TTY_DRIVER_REAL_RAW |
1228 TTY_DRIVER_DYNAMIC_DEV |
1229 TTY_DRIVER_HARDWARE_BREAK);
1231 /* The kernel wants space to store pointers to tty_structs */
1232 brd->serial_driver->ttys =
1233 kzalloc(MAXPORTS * sizeof(struct tty_struct *), GFP_KERNEL);
1234 if (!brd->serial_driver->ttys)
1238 * Entry points for driver. Called by the kernel from
1239 * tty_io.c and n_tty.c.
1241 tty_set_operations(brd->serial_driver, &dgap_tty_ops);
1244 * If we're doing transparent print, we have to do all of the above
1245 * again, separately so we don't get the LD confused about what major
1246 * we are when we get into the dgap_tty_open() routine.
1248 brd->print_driver = alloc_tty_driver(MAXPORTS);
1250 snprintf(brd->print_name, MAXTTYNAMELEN, "pr_dgap_%d_",
1252 brd->print_driver->name = brd->print_name;
1253 brd->print_driver->name_base = 0;
1254 brd->print_driver->major = 0;
1255 brd->print_driver->minor_start = 0;
1256 brd->print_driver->type = TTY_DRIVER_TYPE_SERIAL;
1257 brd->print_driver->subtype = SERIAL_TYPE_NORMAL;
1258 brd->print_driver->init_termios = dgap_default_termios;
1259 brd->print_driver->driver_name = DRVSTR;
1260 brd->print_driver->flags = (TTY_DRIVER_REAL_RAW |
1261 TTY_DRIVER_DYNAMIC_DEV |
1262 TTY_DRIVER_HARDWARE_BREAK);
1264 /* The kernel wants space to store pointers to tty_structs */
1265 brd->print_driver->ttys =
1266 kzalloc(MAXPORTS * sizeof(struct tty_struct *), GFP_KERNEL);
1267 if (!brd->print_driver->ttys)
1271 * Entry points for driver. Called by the kernel from
1272 * tty_io.c and n_tty.c.
1274 tty_set_operations(brd->print_driver, &dgap_tty_ops);
1276 /* Register tty devices */
1277 rc = tty_register_driver(brd->serial_driver);
1280 brd->dgap_major_serial_registered = TRUE;
1281 dgap_boards_by_major[brd->serial_driver->major] = brd;
1282 brd->dgap_serial_major = brd->serial_driver->major;
1284 /* Register Transparent Print devices */
1285 rc = tty_register_driver(brd->print_driver);
1288 brd->dgap_major_transparent_print_registered = TRUE;
1289 dgap_boards_by_major[brd->print_driver->major] = brd;
1290 brd->dgap_transparent_print_major = brd->print_driver->major;
1298 * Init the tty subsystem. Called once per board after board has been
1299 * downloaded and init'ed.
1301 static int dgap_tty_init(struct board_t *brd)
1305 uint true_count = 0;
1308 struct channel_t *ch;
1309 struct bs_t __iomem *bs;
1310 struct cm_t __iomem *cm;
1316 * Initialize board structure elements.
1319 vaddr = brd->re_map_membase;
1320 true_count = readw((vaddr + NCHAN));
1322 brd->nasync = dgap_config_get_num_prts(brd);
1325 brd->nasync = brd->maxports;
1327 if (brd->nasync > brd->maxports)
1328 brd->nasync = brd->maxports;
1330 if (true_count != brd->nasync) {
1331 if ((brd->type == PPCM) && (true_count == 64)) {
1332 pr_warn("dgap: %s configured for %d ports, has %d ports.\n",
1333 brd->name, brd->nasync, true_count);
1334 pr_warn("dgap: Please make SURE the EBI cable running from the card\n");
1335 pr_warn("dgap: to each EM module is plugged into EBI IN!\n");
1336 } else if ((brd->type == PPCM) && (true_count == 0)) {
1337 pr_warn("dgap: %s configured for %d ports, has %d ports.\n",
1338 brd->name, brd->nasync, true_count);
1339 pr_warn("dgap: Please make SURE the EBI cable running from the card\n");
1340 pr_warn("dgap: to each EM module is plugged into EBI IN!\n");
1342 pr_warn("dgap: %s configured for %d ports, has %d ports.\n",
1343 brd->name, brd->nasync, true_count);
1345 brd->nasync = true_count;
1347 /* If no ports, don't bother going any further */
1349 brd->state = BOARD_FAILED;
1350 brd->dpastatus = BD_NOFEP;
1356 * Allocate channel memory that might not have been allocated
1357 * when the driver was first loaded.
1359 for (i = 0; i < brd->nasync; i++) {
1360 if (!brd->channels[i]) {
1362 kzalloc(sizeof(struct channel_t), GFP_ATOMIC);
1363 if (!brd->channels[i])
1368 ch = brd->channels[0];
1369 vaddr = brd->re_map_membase;
1371 bs = (struct bs_t __iomem *) ((ulong) vaddr + CHANBUF);
1372 cm = (struct cm_t __iomem *) ((ulong) vaddr + CMDBUF);
1376 /* Set up channel variables */
1377 for (i = 0; i < brd->nasync; i++, ch = brd->channels[i], bs++) {
1379 if (!brd->channels[i])
1382 spin_lock_init(&ch->ch_lock);
1384 /* Store all our magic numbers */
1385 ch->magic = DGAP_CHANNEL_MAGIC;
1386 ch->ch_tun.magic = DGAP_UNIT_MAGIC;
1387 ch->ch_tun.un_type = DGAP_SERIAL;
1388 ch->ch_tun.un_ch = ch;
1389 ch->ch_tun.un_dev = i;
1391 ch->ch_pun.magic = DGAP_UNIT_MAGIC;
1392 ch->ch_pun.un_type = DGAP_PRINT;
1393 ch->ch_pun.un_ch = ch;
1394 ch->ch_pun.un_dev = i;
1396 ch->ch_vaddr = vaddr;
1401 ch->ch_digi = dgap_digi_init;
1404 * Set up digi dsr and dcd bits based on altpin flag.
1406 if (dgap_config_get_altpin(brd)) {
1409 ch->ch_digi.digi_flags |= DIGI_ALTPIN;
1412 ch->ch_dsr = DM_DSR;
1415 ch->ch_taddr = vaddr + ((ch->ch_bs->tx_seg) << 4);
1416 ch->ch_raddr = vaddr + ((ch->ch_bs->rx_seg) << 4);
1419 ch->ch_tsize = readw(&(ch->ch_bs->tx_max)) + 1;
1420 ch->ch_rsize = readw(&(ch->ch_bs->rx_max)) + 1;
1424 /* .25 second delay */
1425 ch->ch_close_delay = 250;
1428 * Set queue water marks, interrupt mask,
1429 * and general tty parameters.
1431 tlw = ch->ch_tsize >= 2000 ? ((ch->ch_tsize * 5) / 8) :
1435 dgap_cmdw(ch, STLOW, tlw, 0);
1437 dgap_cmdw(ch, SRLOW, ch->ch_rsize / 2, 0);
1439 dgap_cmdw(ch, SRHIGH, 7 * ch->ch_rsize / 8, 0);
1441 ch->ch_mistat = readb(&(ch->ch_bs->m_stat));
1443 init_waitqueue_head(&ch->ch_flags_wait);
1444 init_waitqueue_head(&ch->ch_tun.un_flags_wait);
1445 init_waitqueue_head(&ch->ch_pun.un_flags_wait);
1446 init_waitqueue_head(&ch->ch_sniff_wait);
1448 /* Turn on all modem interrupts for now */
1449 modem = (DM_CD | DM_DSR | DM_CTS | DM_RI);
1450 writeb(modem, &(ch->ch_bs->m_int));
1453 * Set edelay to 0 if interrupts are turned on,
1454 * otherwise set edelay to the usual 100.
1457 writew(0, &(ch->ch_bs->edelay));
1459 writew(100, &(ch->ch_bs->edelay));
1461 writeb(1, &(ch->ch_bs->idata));
1470 * Uninitialize the TTY portion of this driver. Free all memory and
1473 static void dgap_tty_uninit(struct board_t *brd)
1478 if (brd->dgap_major_serial_registered) {
1479 dgap_boards_by_major[brd->serial_driver->major] = NULL;
1480 brd->dgap_serial_major = 0;
1481 for (i = 0; i < brd->nasync; i++) {
1482 tty_port_destroy(&brd->serial_ports[i]);
1483 dev = brd->channels[i]->ch_tun.un_sysfs;
1484 dgap_remove_tty_sysfs(dev);
1485 tty_unregister_device(brd->serial_driver, i);
1487 tty_unregister_driver(brd->serial_driver);
1488 kfree(brd->serial_driver->ttys);
1489 brd->serial_driver->ttys = NULL;
1490 put_tty_driver(brd->serial_driver);
1491 kfree(brd->serial_ports);
1492 brd->dgap_major_serial_registered = FALSE;
1495 if (brd->dgap_major_transparent_print_registered) {
1496 dgap_boards_by_major[brd->print_driver->major] = NULL;
1497 brd->dgap_transparent_print_major = 0;
1498 for (i = 0; i < brd->nasync; i++) {
1499 tty_port_destroy(&brd->printer_ports[i]);
1500 dev = brd->channels[i]->ch_pun.un_sysfs;
1501 dgap_remove_tty_sysfs(dev);
1502 tty_unregister_device(brd->print_driver, i);
1504 tty_unregister_driver(brd->print_driver);
1505 kfree(brd->print_driver->ttys);
1506 brd->print_driver->ttys = NULL;
1507 put_tty_driver(brd->print_driver);
1508 kfree(brd->printer_ports);
1509 brd->dgap_major_transparent_print_registered = FALSE;
1513 #define TMPBUFLEN (1024)
1515 * dgap_sniff - Dump data out to the "sniff" buffer if the
1516 * proc sniff file is opened...
1518 static void dgap_sniff_nowait_nolock(struct channel_t *ch, u8 *text,
1527 char tmpbuf[TMPBUFLEN];
1531 /* Leave if sniff not open */
1532 if (!(ch->ch_sniff_flags & SNIFF_OPEN))
1535 do_gettimeofday(&tv);
1537 /* Create our header for data dump */
1538 p += sprintf(p, "<%ld %ld><%s><", tv.tv_sec, tv.tv_usec, text);
1539 tmpbuflen = p - tmpbuf;
1544 for (i = 0; i < len && tmpbuflen < (TMPBUFLEN - 4); i++) {
1545 p += sprintf(p, "%02x ", *buf);
1547 tmpbuflen = p - tmpbuf;
1550 if (tmpbuflen < (TMPBUFLEN - 4)) {
1552 p += sprintf(p - 1, "%s\n", ">");
1554 p += sprintf(p, "%s\n", ">");
1560 nbuf = strlen(tmpbuf);
1564 * Loop while data remains.
1566 while (nbuf > 0 && ch->ch_sniff_buf) {
1568 * Determine the amount of available space left in the
1569 * buffer. If there's none, wait until some appears.
1571 n = (ch->ch_sniff_out - ch->ch_sniff_in - 1) &
1575 * If there is no space left to write to in our sniff
1576 * buffer, we have no choice but to drop the data.
1577 * We *cannot* sleep here waiting for space, because
1578 * this function was probably called by the
1579 * interrupt/timer routines!
1585 * Copy as much data as will fit.
1591 r = SNIFF_MAX - ch->ch_sniff_in;
1594 memcpy(ch->ch_sniff_buf +
1595 ch->ch_sniff_in, p, r);
1598 ch->ch_sniff_in = 0;
1603 memcpy(ch->ch_sniff_buf + ch->ch_sniff_in, p, n);
1605 ch->ch_sniff_in += n;
1610 * Wakeup any thread waiting for data
1612 if (ch->ch_sniff_flags & SNIFF_WAIT_DATA) {
1613 ch->ch_sniff_flags &= ~SNIFF_WAIT_DATA;
1614 wake_up_interruptible(&ch->ch_sniff_wait);
1619 * If the user sent us too much data to push into our tmpbuf,
1620 * we need to keep looping around on all the data.
1622 if (too_much_data) {
1627 } while (too_much_data);
1630 /*=======================================================================
1632 * dgap_input - Process received data.
1634 * ch - Pointer to channel structure.
1636 *=======================================================================*/
1638 static void dgap_input(struct channel_t *ch)
1641 struct bs_t __iomem *bs;
1642 struct tty_struct *tp;
1643 struct tty_ldisc *ld;
1657 if (!ch || ch->magic != DGAP_CHANNEL_MAGIC)
1660 tp = ch->ch_tun.un_tty;
1667 if (!bd || bd->magic != DGAP_BOARD_MAGIC)
1670 spin_lock_irqsave(&bd->bd_lock, lock_flags);
1671 spin_lock_irqsave(&ch->ch_lock, lock_flags2);
1674 * Figure the number of characters in the buffer.
1675 * Exit immediately if none.
1678 rmask = ch->ch_rsize - 1;
1680 head = readw(&(bs->rx_head));
1682 tail = readw(&(bs->rx_tail));
1685 data_len = (head - tail) & rmask;
1687 if (data_len == 0) {
1688 writeb(1, &(bs->idata));
1689 spin_unlock_irqrestore(&ch->ch_lock, lock_flags2);
1690 spin_unlock_irqrestore(&bd->bd_lock, lock_flags);
1695 * If the device is not open, or CREAD is off, flush
1696 * input data and return immediately.
1698 if ((bd->state != BOARD_READY) || !tp ||
1699 (tp->magic != TTY_MAGIC) ||
1700 !(ch->ch_tun.un_flags & UN_ISOPEN) ||
1701 !(tp->termios.c_cflag & CREAD) ||
1702 (ch->ch_tun.un_flags & UN_CLOSING)) {
1704 writew(head, &(bs->rx_tail));
1705 writeb(1, &(bs->idata));
1706 spin_unlock_irqrestore(&ch->ch_lock, lock_flags2);
1707 spin_unlock_irqrestore(&bd->bd_lock, lock_flags);
1712 * If we are throttled, simply don't read any data.
1714 if (ch->ch_flags & CH_RXBLOCK) {
1715 writeb(1, &(bs->idata));
1716 spin_unlock_irqrestore(&ch->ch_lock, lock_flags2);
1717 spin_unlock_irqrestore(&bd->bd_lock, lock_flags);
1724 tmpchar = readb(&(bs->orun));
1726 ch->ch_err_overrun++;
1727 writeb(0, &(bs->orun));
1730 /* Decide how much data we can send into the tty layer */
1731 flip_len = TTY_FLIPBUF_SIZE;
1733 /* Chop down the length, if needed */
1734 len = min(data_len, flip_len);
1735 len = min(len, (N_TTY_BUF_SIZE - 1));
1737 ld = tty_ldisc_ref(tp);
1739 #ifdef TTY_DONT_FLIP
1741 * If the DONT_FLIP flag is on, don't flush our buffer, and act
1742 * like the ld doesn't have any space to put the data right now.
1744 if (test_bit(TTY_DONT_FLIP, &tp->flags))
1749 * If we were unable to get a reference to the ld,
1750 * don't flush our buffer, and act like the ld doesn't
1751 * have any space to put the data right now.
1757 * If ld doesn't have a pointer to a receive_buf function,
1758 * flush the data, then act like the ld doesn't have any
1759 * space to put the data right now.
1761 if (!ld->ops->receive_buf) {
1762 writew(head, &(bs->rx_tail));
1768 writeb(1, &(bs->idata));
1769 spin_unlock_irqrestore(&ch->ch_lock, lock_flags2);
1770 spin_unlock_irqrestore(&bd->bd_lock, lock_flags);
1772 tty_ldisc_deref(ld);
1776 buf = ch->ch_bd->flipbuf;
1780 * n now contains the most amount of data we can copy,
1781 * bounded either by our buffer size or the amount
1782 * of data the card actually has pending...
1786 s = ((head >= tail) ? head : ch->ch_rsize) - tail;
1792 memcpy_fromio(buf, ch->ch_raddr + tail, s);
1793 dgap_sniff_nowait_nolock(ch, "USER READ", buf, s);
1799 /* Flip queue if needed */
1803 writew(tail, &(bs->rx_tail));
1804 writeb(1, &(bs->idata));
1805 ch->ch_rxcount += len;
1808 * If we are completely raw, we don't need to go through a lot
1809 * of the tty layers that exist.
1810 * In this case, we take the shortest and fastest route we
1811 * can to relay the data to the user.
1813 * On the other hand, if we are not raw, we need to go through
1814 * the tty layer, which has its API more well defined.
1816 if (I_PARMRK(tp) || I_BRKINT(tp) || I_INPCK(tp)) {
1817 dgap_parity_scan(ch, ch->ch_bd->flipbuf,
1818 ch->ch_bd->flipflagbuf, &len);
1820 len = tty_buffer_request_room(tp->port, len);
1821 tty_insert_flip_string_flags(tp->port, ch->ch_bd->flipbuf,
1822 ch->ch_bd->flipflagbuf, len);
1824 len = tty_buffer_request_room(tp->port, len);
1825 tty_insert_flip_string(tp->port, ch->ch_bd->flipbuf, len);
1828 spin_unlock_irqrestore(&ch->ch_lock, lock_flags2);
1829 spin_unlock_irqrestore(&bd->bd_lock, lock_flags);
1831 /* Tell the tty layer its okay to "eat" the data now */
1832 tty_flip_buffer_push(tp->port);
1835 tty_ldisc_deref(ld);
1839 /************************************************************************
1840 * Determines when CARRIER changes state and takes appropriate
1842 ************************************************************************/
1843 static void dgap_carrier(struct channel_t *ch)
1847 int virt_carrier = 0;
1848 int phys_carrier = 0;
1850 if (!ch || ch->magic != DGAP_CHANNEL_MAGIC)
1855 if (!bd || bd->magic != DGAP_BOARD_MAGIC)
1858 /* Make sure altpin is always set correctly */
1859 if (ch->ch_digi.digi_flags & DIGI_ALTPIN) {
1863 ch->ch_dsr = DM_DSR;
1867 if (ch->ch_mistat & D_CD(ch))
1870 if (ch->ch_digi.digi_flags & DIGI_FORCEDCD)
1873 if (ch->ch_c_cflag & CLOCAL)
1877 * Test for a VIRTUAL carrier transition to HIGH.
1879 if (((ch->ch_flags & CH_FCAR) == 0) && (virt_carrier == 1)) {
1882 * When carrier rises, wake any threads waiting
1883 * for carrier in the open routine.
1886 if (waitqueue_active(&(ch->ch_flags_wait)))
1887 wake_up_interruptible(&ch->ch_flags_wait);
1891 * Test for a PHYSICAL carrier transition to HIGH.
1893 if (((ch->ch_flags & CH_CD) == 0) && (phys_carrier == 1)) {
1896 * When carrier rises, wake any threads waiting
1897 * for carrier in the open routine.
1900 if (waitqueue_active(&(ch->ch_flags_wait)))
1901 wake_up_interruptible(&ch->ch_flags_wait);
1905 * Test for a PHYSICAL transition to low, so long as we aren't
1906 * currently ignoring physical transitions (which is what "virtual
1907 * carrier" indicates).
1909 * The transition of the virtual carrier to low really doesn't
1910 * matter... it really only means "ignore carrier state", not
1911 * "make pretend that carrier is there".
1913 if ((virt_carrier == 0) &&
1914 ((ch->ch_flags & CH_CD) != 0) &&
1915 (phys_carrier == 0)) {
1918 * When carrier drops:
1920 * Drop carrier on all open units.
1922 * Flush queues, waking up any task waiting in the
1925 * Send a hangup to the control terminal.
1927 * Enable all select calls.
1929 if (waitqueue_active(&(ch->ch_flags_wait)))
1930 wake_up_interruptible(&ch->ch_flags_wait);
1932 if (ch->ch_tun.un_open_count > 0)
1933 tty_hangup(ch->ch_tun.un_tty);
1935 if (ch->ch_pun.un_open_count > 0)
1936 tty_hangup(ch->ch_pun.un_tty);
1940 * Make sure that our cached values reflect the current reality.
1942 if (virt_carrier == 1)
1943 ch->ch_flags |= CH_FCAR;
1945 ch->ch_flags &= ~CH_FCAR;
1947 if (phys_carrier == 1)
1948 ch->ch_flags |= CH_CD;
1950 ch->ch_flags &= ~CH_CD;
1953 /************************************************************************
1955 * TTY Entry points and helper functions
1957 ************************************************************************/
1963 static int dgap_tty_open(struct tty_struct *tty, struct file *file)
1965 struct board_t *brd;
1966 struct channel_t *ch;
1968 struct bs_t __iomem *bs;
1978 major = MAJOR(tty_devnum(tty));
1979 minor = MINOR(tty_devnum(tty));
1984 /* Get board pointer from our array of majors we have allocated */
1985 brd = dgap_boards_by_major[major];
1990 * If board is not yet up to a state of READY, go to
1991 * sleep waiting for it to happen or they cancel the open.
1993 rc = wait_event_interruptible(brd->state_wait,
1994 (brd->state & BOARD_READY));
1999 spin_lock_irqsave(&brd->bd_lock, lock_flags);
2001 /* The wait above should guarantee this cannot happen */
2002 if (brd->state != BOARD_READY) {
2003 spin_unlock_irqrestore(&brd->bd_lock, lock_flags);
2007 /* If opened device is greater than our number of ports, bail. */
2008 if (MINOR(tty_devnum(tty)) > brd->nasync) {
2009 spin_unlock_irqrestore(&brd->bd_lock, lock_flags);
2013 ch = brd->channels[minor];
2015 spin_unlock_irqrestore(&brd->bd_lock, lock_flags);
2019 /* Grab channel lock */
2020 spin_lock_irqsave(&ch->ch_lock, lock_flags2);
2022 /* Figure out our type */
2023 if (major == brd->dgap_serial_major) {
2024 un = &brd->channels[minor]->ch_tun;
2025 un->un_type = DGAP_SERIAL;
2026 } else if (major == brd->dgap_transparent_print_major) {
2027 un = &brd->channels[minor]->ch_pun;
2028 un->un_type = DGAP_PRINT;
2030 spin_unlock_irqrestore(&ch->ch_lock, lock_flags2);
2031 spin_unlock_irqrestore(&brd->bd_lock, lock_flags);
2035 /* Store our unit into driver_data, so we always have it available. */
2036 tty->driver_data = un;
2039 * Error if channel info pointer is NULL.
2043 spin_unlock_irqrestore(&ch->ch_lock, lock_flags2);
2044 spin_unlock_irqrestore(&brd->bd_lock, lock_flags);
2051 if (!(un->un_flags & UN_ISOPEN)) {
2052 /* Store important variables. */
2055 /* Maybe do something here to the TTY struct as well? */
2059 * Initialize if neither terminal or printer is open.
2061 if (!((ch->ch_tun.un_flags | ch->ch_pun.un_flags) & UN_ISOPEN)) {
2067 * Flush input queue.
2069 head = readw(&(bs->rx_head));
2070 writew(head, &(bs->rx_tail));
2073 ch->pscan_state = 0;
2074 ch->pscan_savechar = 0;
2076 ch->ch_c_cflag = tty->termios.c_cflag;
2077 ch->ch_c_iflag = tty->termios.c_iflag;
2078 ch->ch_c_oflag = tty->termios.c_oflag;
2079 ch->ch_c_lflag = tty->termios.c_lflag;
2080 ch->ch_startc = tty->termios.c_cc[VSTART];
2081 ch->ch_stopc = tty->termios.c_cc[VSTOP];
2083 /* TODO: flush our TTY struct here? */
2088 * Run param in case we changed anything
2093 * follow protocol for opening port
2096 spin_unlock_irqrestore(&ch->ch_lock, lock_flags2);
2097 spin_unlock_irqrestore(&brd->bd_lock, lock_flags);
2099 rc = dgap_block_til_ready(tty, file, ch);
2104 /* No going back now, increment our unit and channel counters */
2105 spin_lock_irqsave(&ch->ch_lock, lock_flags);
2106 ch->ch_open_count++;
2107 un->un_open_count++;
2108 un->un_flags |= (UN_ISOPEN);
2109 spin_unlock_irqrestore(&ch->ch_lock, lock_flags);
2115 * dgap_block_til_ready()
2117 * Wait for DCD, if needed.
2119 static int dgap_block_til_ready(struct tty_struct *tty, struct file *file,
2120 struct channel_t *ch)
2123 struct un_t *un = NULL;
2126 int sleep_on_un_flags = 0;
2128 if (!tty || tty->magic != TTY_MAGIC || !file || !ch ||
2129 ch->magic != DGAP_CHANNEL_MAGIC)
2132 un = tty->driver_data;
2133 if (!un || un->magic != DGAP_UNIT_MAGIC)
2136 spin_lock_irqsave(&ch->ch_lock, lock_flags);
2143 sleep_on_un_flags = 0;
2146 * If board has failed somehow during our sleep,
2149 if (ch->ch_bd->state == BOARD_FAILED) {
2154 /* If tty was hung up, break out of loop and set error. */
2155 if (tty_hung_up_p(file)) {
2161 * If either unit is in the middle of the fragile part of close,
2162 * we just cannot touch the channel safely.
2163 * Go back to sleep, knowing that when the channel can be
2164 * touched safely, the close routine will signal the
2165 * ch_wait_flags to wake us back up.
2167 if (!((ch->ch_tun.un_flags | ch->ch_pun.un_flags) &
2171 * Our conditions to leave cleanly and happily:
2172 * 1) NONBLOCKING on the tty is set.
2174 * 3) DCD (fake or real) is active.
2177 if (file->f_flags & O_NONBLOCK)
2180 if (tty->flags & (1 << TTY_IO_ERROR))
2183 if (ch->ch_flags & CH_CD)
2186 if (ch->ch_flags & CH_FCAR)
2189 sleep_on_un_flags = 1;
2193 * If there is a signal pending, the user probably
2194 * interrupted (ctrl-c) us.
2195 * Leave loop with error set.
2197 if (signal_pending(current)) {
2198 retval = -ERESTARTSYS;
2203 * Store the flags before we let go of channel lock
2205 if (sleep_on_un_flags)
2206 old_flags = ch->ch_tun.un_flags | ch->ch_pun.un_flags;
2208 old_flags = ch->ch_flags;
2211 * Let go of channel lock before calling schedule.
2212 * Our poller will get any FEP events and wake us up when DCD
2213 * eventually goes active.
2216 spin_unlock_irqrestore(&ch->ch_lock, lock_flags);
2219 * Wait for something in the flags to change
2220 * from the current value.
2222 if (sleep_on_un_flags) {
2223 retval = wait_event_interruptible(un->un_flags_wait,
2224 (old_flags != (ch->ch_tun.un_flags |
2225 ch->ch_pun.un_flags)));
2227 retval = wait_event_interruptible(ch->ch_flags_wait,
2228 (old_flags != ch->ch_flags));
2232 * We got woken up for some reason.
2233 * Before looping around, grab our channel lock.
2235 spin_lock_irqsave(&ch->ch_lock, lock_flags);
2240 spin_unlock_irqrestore(&ch->ch_lock, lock_flags);
2251 * Hangup the port. Like a close, but don't wait for output to drain.
2253 static void dgap_tty_hangup(struct tty_struct *tty)
2256 struct channel_t *ch;
2259 if (!tty || tty->magic != TTY_MAGIC)
2262 un = tty->driver_data;
2263 if (!un || un->magic != DGAP_UNIT_MAGIC)
2267 if (!ch || ch->magic != DGAP_CHANNEL_MAGIC)
2271 if (!bd || bd->magic != DGAP_BOARD_MAGIC)
2274 /* flush the transmit queues */
2275 dgap_tty_flush_buffer(tty);
2283 static void dgap_tty_close(struct tty_struct *tty, struct file *file)
2285 struct ktermios *ts;
2287 struct channel_t *ch;
2292 if (!tty || tty->magic != TTY_MAGIC)
2295 un = tty->driver_data;
2296 if (!un || un->magic != DGAP_UNIT_MAGIC)
2300 if (!ch || ch->magic != DGAP_CHANNEL_MAGIC)
2304 if (!bd || bd->magic != DGAP_BOARD_MAGIC)
2309 spin_lock_irqsave(&ch->ch_lock, lock_flags);
2312 * Determine if this is the last close or not - and if we agree about
2313 * which type of close it is with the Line Discipline
2315 if ((tty->count == 1) && (un->un_open_count != 1)) {
2317 * Uh, oh. tty->count is 1, which means that the tty
2318 * structure will be freed. un_open_count should always
2319 * be one in these conditions. If it's greater than
2320 * one, we've got real problems, since it means the
2321 * serial port won't be shutdown.
2323 un->un_open_count = 1;
2326 if (--un->un_open_count < 0)
2327 un->un_open_count = 0;
2329 ch->ch_open_count--;
2331 if (ch->ch_open_count && un->un_open_count) {
2332 spin_unlock_irqrestore(&ch->ch_lock, lock_flags);
2336 /* OK, its the last close on the unit */
2338 un->un_flags |= UN_CLOSING;
2343 * Only officially close channel if count is 0 and
2344 * DIGI_PRINTER bit is not set.
2346 if ((ch->ch_open_count == 0) &&
2347 !(ch->ch_digi.digi_flags & DIGI_PRINTER)) {
2349 ch->ch_flags &= ~(CH_RXBLOCK);
2351 spin_unlock_irqrestore(&ch->ch_lock, lock_flags);
2353 /* wait for output to drain */
2354 /* This will also return if we take an interrupt */
2356 rc = dgap_wait_for_drain(tty);
2358 dgap_tty_flush_buffer(tty);
2359 tty_ldisc_flush(tty);
2361 spin_lock_irqsave(&ch->ch_lock, lock_flags);
2366 * If we have HUPCL set, lower DTR and RTS
2368 if (ch->ch_c_cflag & HUPCL) {
2369 ch->ch_mostat &= ~(D_RTS(ch)|D_DTR(ch));
2370 dgap_cmdb(ch, SMODEM, 0, D_DTR(ch)|D_RTS(ch), 0);
2373 * Go to sleep to ensure RTS/DTR
2374 * have been dropped for modems to see it.
2376 if (ch->ch_close_delay) {
2377 spin_unlock_irqrestore(&ch->ch_lock,
2379 dgap_ms_sleep(ch->ch_close_delay);
2380 spin_lock_irqsave(&ch->ch_lock, lock_flags);
2384 ch->pscan_state = 0;
2385 ch->pscan_savechar = 0;
2386 ch->ch_baud_info = 0;
2391 * turn off print device when closing print device.
2393 if ((un->un_type == DGAP_PRINT) && (ch->ch_flags & CH_PRON)) {
2394 dgap_wmove(ch, ch->ch_digi.digi_offstr,
2395 (int) ch->ch_digi.digi_offlen);
2396 ch->ch_flags &= ~CH_PRON;
2400 un->un_flags &= ~(UN_ISOPEN | UN_CLOSING);
2401 tty->driver_data = NULL;
2403 wake_up_interruptible(&ch->ch_flags_wait);
2404 wake_up_interruptible(&un->un_flags_wait);
2406 spin_unlock_irqrestore(&ch->ch_lock, lock_flags);
2410 * dgap_tty_chars_in_buffer()
2412 * Return number of characters that have not been transmitted yet.
2414 * This routine is used by the line discipline to determine if there
2415 * is data waiting to be transmitted/drained/flushed or not.
2417 static int dgap_tty_chars_in_buffer(struct tty_struct *tty)
2419 struct board_t *bd = NULL;
2420 struct channel_t *ch = NULL;
2421 struct un_t *un = NULL;
2422 struct bs_t __iomem *bs;
2425 u16 thead, ttail, tmask, chead, ctail;
2426 ulong lock_flags = 0;
2427 ulong lock_flags2 = 0;
2432 un = tty->driver_data;
2433 if (!un || un->magic != DGAP_UNIT_MAGIC)
2437 if (!ch || ch->magic != DGAP_CHANNEL_MAGIC)
2441 if (!bd || bd->magic != DGAP_BOARD_MAGIC)
2448 spin_lock_irqsave(&bd->bd_lock, lock_flags);
2449 spin_lock_irqsave(&ch->ch_lock, lock_flags2);
2451 tmask = (ch->ch_tsize - 1);
2453 /* Get Transmit queue pointers */
2454 thead = readw(&(bs->tx_head)) & tmask;
2455 ttail = readw(&(bs->tx_tail)) & tmask;
2457 /* Get tbusy flag */
2458 tbusy = readb(&(bs->tbusy));
2460 /* Get Command queue pointers */
2461 chead = readw(&(ch->ch_cm->cm_head));
2462 ctail = readw(&(ch->ch_cm->cm_tail));
2464 spin_unlock_irqrestore(&ch->ch_lock, lock_flags2);
2465 spin_unlock_irqrestore(&bd->bd_lock, lock_flags);
2468 * The only way we know for sure if there is no pending
2469 * data left to be transferred, is if:
2470 * 1) Transmit head and tail are equal (empty).
2471 * 2) Command queue head and tail are equal (empty).
2472 * 3) The "TBUSY" flag is 0. (Transmitter not busy).
2475 if ((ttail == thead) && (tbusy == 0) && (chead == ctail)) {
2479 chars = thead - ttail;
2481 chars = thead - ttail + ch->ch_tsize;
2483 * Fudge factor here.
2484 * If chars is zero, we know that the command queue had
2485 * something in it or tbusy was set. Because we cannot
2486 * be sure if there is still some data to be transmitted,
2487 * lets lie, and tell ld we have 1 byte left.
2491 * If TBUSY is still set, and our tx buffers are empty,
2492 * force the firmware to send me another wakeup after
2493 * TBUSY has been cleared.
2496 spin_lock_irqsave(&ch->ch_lock, lock_flags);
2497 un->un_flags |= UN_EMPTY;
2498 writeb(1, &(bs->iempty));
2499 spin_unlock_irqrestore(&ch->ch_lock,
2509 static int dgap_wait_for_drain(struct tty_struct *tty)
2511 struct channel_t *ch;
2513 struct bs_t __iomem *bs;
2516 ulong lock_flags = 0;
2518 if (!tty || tty->magic != TTY_MAGIC)
2521 un = tty->driver_data;
2522 if (!un || un->magic != DGAP_UNIT_MAGIC)
2526 if (!ch || ch->magic != DGAP_CHANNEL_MAGIC)
2535 /* Loop until data is drained */
2536 while (count != 0) {
2538 count = dgap_tty_chars_in_buffer(tty);
2543 /* Set flag waiting for drain */
2544 spin_lock_irqsave(&ch->ch_lock, lock_flags);
2545 un->un_flags |= UN_EMPTY;
2546 writeb(1, &(bs->iempty));
2547 spin_unlock_irqrestore(&ch->ch_lock, lock_flags);
2549 /* Go to sleep till we get woken up */
2550 ret = wait_event_interruptible(un->un_flags_wait,
2551 ((un->un_flags & UN_EMPTY) == 0));
2552 /* If ret is non-zero, user ctrl-c'ed us */
2557 spin_lock_irqsave(&ch->ch_lock, lock_flags);
2558 un->un_flags &= ~(UN_EMPTY);
2559 spin_unlock_irqrestore(&ch->ch_lock, lock_flags);
2567 * Reduces bytes_available to the max number of characters
2568 * that can be sent currently given the maxcps value, and
2569 * returns the new bytes_available. This only affects printer
2572 static int dgap_maxcps_room(struct tty_struct *tty, int bytes_available)
2574 struct channel_t *ch = NULL;
2575 struct un_t *un = NULL;
2578 return bytes_available;
2580 un = tty->driver_data;
2581 if (!un || un->magic != DGAP_UNIT_MAGIC)
2582 return bytes_available;
2585 if (!ch || ch->magic != DGAP_CHANNEL_MAGIC)
2586 return bytes_available;
2589 * If its not the Transparent print device, return
2590 * the full data amount.
2592 if (un->un_type != DGAP_PRINT)
2593 return bytes_available;
2595 if (ch->ch_digi.digi_maxcps > 0 && ch->ch_digi.digi_bufsize > 0) {
2597 unsigned long current_time = jiffies;
2598 unsigned long buffer_time = current_time +
2599 (HZ * ch->ch_digi.digi_bufsize) /
2600 ch->ch_digi.digi_maxcps;
2602 if (ch->ch_cpstime < current_time) {
2603 /* buffer is empty */
2604 ch->ch_cpstime = current_time; /* reset ch_cpstime */
2605 cps_limit = ch->ch_digi.digi_bufsize;
2606 } else if (ch->ch_cpstime < buffer_time) {
2607 /* still room in the buffer */
2608 cps_limit = ((buffer_time - ch->ch_cpstime) *
2609 ch->ch_digi.digi_maxcps) / HZ;
2611 /* no room in the buffer */
2615 bytes_available = min(cps_limit, bytes_available);
2618 return bytes_available;
2621 static inline void dgap_set_firmware_event(struct un_t *un, unsigned int event)
2623 struct channel_t *ch = NULL;
2624 struct bs_t __iomem *bs = NULL;
2626 if (!un || un->magic != DGAP_UNIT_MAGIC)
2629 if (!ch || ch->magic != DGAP_CHANNEL_MAGIC)
2635 if ((event & UN_LOW) != 0) {
2636 if ((un->un_flags & UN_LOW) == 0) {
2637 un->un_flags |= UN_LOW;
2638 writeb(1, &(bs->ilow));
2641 if ((event & UN_LOW) != 0) {
2642 if ((un->un_flags & UN_EMPTY) == 0) {
2643 un->un_flags |= UN_EMPTY;
2644 writeb(1, &(bs->iempty));
2650 * dgap_tty_write_room()
2652 * Return space available in Tx buffer
2654 static int dgap_tty_write_room(struct tty_struct *tty)
2656 struct channel_t *ch = NULL;
2657 struct un_t *un = NULL;
2658 struct bs_t __iomem *bs;
2659 u16 head, tail, tmask;
2661 ulong lock_flags = 0;
2666 un = tty->driver_data;
2667 if (!un || un->magic != DGAP_UNIT_MAGIC)
2671 if (!ch || ch->magic != DGAP_CHANNEL_MAGIC)
2678 spin_lock_irqsave(&ch->ch_lock, lock_flags);
2680 tmask = ch->ch_tsize - 1;
2681 head = readw(&(bs->tx_head)) & tmask;
2682 tail = readw(&(bs->tx_tail)) & tmask;
2684 ret = tail - head - 1;
2686 ret += ch->ch_tsize;
2688 /* Limit printer to maxcps */
2689 ret = dgap_maxcps_room(tty, ret);
2692 * If we are printer device, leave space for
2693 * possibly both the on and off strings.
2695 if (un->un_type == DGAP_PRINT) {
2696 if (!(ch->ch_flags & CH_PRON))
2697 ret -= ch->ch_digi.digi_onlen;
2698 ret -= ch->ch_digi.digi_offlen;
2700 if (ch->ch_flags & CH_PRON)
2701 ret -= ch->ch_digi.digi_offlen;
2708 * Schedule FEP to wake us up if needed.
2710 * TODO: This might be overkill...
2711 * Do we really need to schedule callbacks from the FEP
2712 * in every case? Can we get smarter based on ret?
2714 dgap_set_firmware_event(un, UN_LOW | UN_EMPTY);
2715 spin_unlock_irqrestore(&ch->ch_lock, lock_flags);
2721 * dgap_tty_put_char()
2723 * Put a character into ch->ch_buf
2725 * - used by the line discipline for OPOST processing
2727 static int dgap_tty_put_char(struct tty_struct *tty, unsigned char c)
2730 * Simply call tty_write.
2732 dgap_tty_write(tty, &c, 1);
2739 * Take data from the user or kernel and send it out to the FEP.
2740 * In here exists all the Transparent Print magic as well.
2742 static int dgap_tty_write(struct tty_struct *tty, const unsigned char *buf,
2745 struct channel_t *ch = NULL;
2746 struct un_t *un = NULL;
2747 struct bs_t __iomem *bs;
2748 char __iomem *vaddr;
2749 u16 head, tail, tmask, remain;
2750 int bufcount = 0, n = 0;
2757 un = tty->driver_data;
2758 if (!un || un->magic != DGAP_UNIT_MAGIC)
2762 if (!ch || ch->magic != DGAP_CHANNEL_MAGIC)
2773 * Store original amount of characters passed in.
2774 * This helps to figure out if we should ask the FEP
2775 * to send us an event when it has more space available.
2779 spin_lock_irqsave(&ch->ch_lock, lock_flags);
2781 /* Get our space available for the channel from the board */
2782 tmask = ch->ch_tsize - 1;
2783 head = readw(&(bs->tx_head)) & tmask;
2784 tail = readw(&(bs->tx_tail)) & tmask;
2786 bufcount = tail - head - 1;
2788 bufcount += ch->ch_tsize;
2791 * Limit printer output to maxcps overall, with bursts allowed
2792 * up to bufsize characters.
2794 bufcount = dgap_maxcps_room(tty, bufcount);
2797 * Take minimum of what the user wants to send, and the
2798 * space available in the FEP buffer.
2800 count = min(count, bufcount);
2803 * Bail if no space left.
2806 dgap_set_firmware_event(un, UN_LOW | UN_EMPTY);
2807 spin_unlock_irqrestore(&ch->ch_lock, lock_flags);
2812 * Output the printer ON string, if we are in terminal mode, but
2813 * need to be in printer mode.
2815 if ((un->un_type == DGAP_PRINT) && !(ch->ch_flags & CH_PRON)) {
2816 dgap_wmove(ch, ch->ch_digi.digi_onstr,
2817 (int) ch->ch_digi.digi_onlen);
2818 head = readw(&(bs->tx_head)) & tmask;
2819 ch->ch_flags |= CH_PRON;
2823 * On the other hand, output the printer OFF string, if we are
2824 * currently in printer mode, but need to output to the terminal.
2826 if ((un->un_type != DGAP_PRINT) && (ch->ch_flags & CH_PRON)) {
2827 dgap_wmove(ch, ch->ch_digi.digi_offstr,
2828 (int) ch->ch_digi.digi_offlen);
2829 head = readw(&(bs->tx_head)) & tmask;
2830 ch->ch_flags &= ~CH_PRON;
2834 * If there is nothing left to copy, or
2835 * I can't handle any more data, leave.
2838 dgap_set_firmware_event(un, UN_LOW | UN_EMPTY);
2839 spin_unlock_irqrestore(&ch->ch_lock, lock_flags);
2846 * If the write wraps over the top of the circular buffer,
2847 * move the portion up to the wrap point, and reset the
2848 * pointers to the bottom.
2850 remain = ch->ch_tstart + ch->ch_tsize - head;
2854 vaddr = ch->ch_taddr + head;
2856 memcpy_toio(vaddr, (u8 *) buf, remain);
2857 dgap_sniff_nowait_nolock(ch, "USER WRITE", (u8 *) buf,
2860 head = ch->ch_tstart;
2867 * Move rest of data.
2869 vaddr = ch->ch_taddr + head;
2872 memcpy_toio(vaddr, (u8 *) buf, remain);
2873 dgap_sniff_nowait_nolock(ch, "USER WRITE", (u8 *)buf,
2881 ch->ch_txcount += count;
2883 writew(head, &(bs->tx_head));
2886 dgap_set_firmware_event(un, UN_LOW | UN_EMPTY);
2889 * If this is the print device, and the
2890 * printer is still on, we need to turn it
2891 * off before going idle. If the buffer is
2892 * non-empty, wait until it goes empty.
2893 * Otherwise turn it off right now.
2895 if ((un->un_type == DGAP_PRINT) && (ch->ch_flags & CH_PRON)) {
2896 tail = readw(&(bs->tx_tail)) & tmask;
2899 un->un_flags |= UN_EMPTY;
2900 writeb(1, &(bs->iempty));
2902 dgap_wmove(ch, ch->ch_digi.digi_offstr,
2903 (int) ch->ch_digi.digi_offlen);
2904 head = readw(&(bs->tx_head)) & tmask;
2905 ch->ch_flags &= ~CH_PRON;
2909 /* Update printer buffer empty time. */
2910 if ((un->un_type == DGAP_PRINT) && (ch->ch_digi.digi_maxcps > 0)
2911 && (ch->ch_digi.digi_bufsize > 0)) {
2912 ch->ch_cpstime += (HZ * count) / ch->ch_digi.digi_maxcps;
2915 spin_unlock_irqrestore(&ch->ch_lock, lock_flags);
2921 * Return modem signals to ld.
2923 static int dgap_tty_tiocmget(struct tty_struct *tty)
2925 struct channel_t *ch;
2931 if (!tty || tty->magic != TTY_MAGIC)
2934 un = tty->driver_data;
2935 if (!un || un->magic != DGAP_UNIT_MAGIC)
2939 if (!ch || ch->magic != DGAP_CHANNEL_MAGIC)
2942 spin_lock_irqsave(&ch->ch_lock, lock_flags);
2944 mstat = readb(&(ch->ch_bs->m_stat));
2945 /* Append any outbound signals that might be pending... */
2946 mstat |= ch->ch_mostat;
2948 spin_unlock_irqrestore(&ch->ch_lock, lock_flags);
2952 if (mstat & D_DTR(ch))
2953 result |= TIOCM_DTR;
2954 if (mstat & D_RTS(ch))
2955 result |= TIOCM_RTS;
2956 if (mstat & D_CTS(ch))
2957 result |= TIOCM_CTS;
2958 if (mstat & D_DSR(ch))
2959 result |= TIOCM_DSR;
2960 if (mstat & D_RI(ch))
2962 if (mstat & D_CD(ch))
2969 * dgap_tty_tiocmset()
2971 * Set modem signals, called by ld.
2973 static int dgap_tty_tiocmset(struct tty_struct *tty,
2974 unsigned int set, unsigned int clear)
2977 struct channel_t *ch;
2983 if (!tty || tty->magic != TTY_MAGIC)
2986 un = tty->driver_data;
2987 if (!un || un->magic != DGAP_UNIT_MAGIC)
2991 if (!ch || ch->magic != DGAP_CHANNEL_MAGIC)
2995 if (!bd || bd->magic != DGAP_BOARD_MAGIC)
2998 spin_lock_irqsave(&bd->bd_lock, lock_flags);
2999 spin_lock_irqsave(&ch->ch_lock, lock_flags2);
3001 if (set & TIOCM_RTS) {
3002 ch->ch_mforce |= D_RTS(ch);
3003 ch->ch_mval |= D_RTS(ch);
3006 if (set & TIOCM_DTR) {
3007 ch->ch_mforce |= D_DTR(ch);
3008 ch->ch_mval |= D_DTR(ch);
3011 if (clear & TIOCM_RTS) {
3012 ch->ch_mforce |= D_RTS(ch);
3013 ch->ch_mval &= ~(D_RTS(ch));
3016 if (clear & TIOCM_DTR) {
3017 ch->ch_mforce |= D_DTR(ch);
3018 ch->ch_mval &= ~(D_DTR(ch));
3023 spin_unlock_irqrestore(&ch->ch_lock, lock_flags2);
3024 spin_unlock_irqrestore(&bd->bd_lock, lock_flags);
3030 * dgap_tty_send_break()
3032 * Send a Break, called by ld.
3034 static int dgap_tty_send_break(struct tty_struct *tty, int msec)
3037 struct channel_t *ch;
3043 if (!tty || tty->magic != TTY_MAGIC)
3046 un = tty->driver_data;
3047 if (!un || un->magic != DGAP_UNIT_MAGIC)
3051 if (!ch || ch->magic != DGAP_CHANNEL_MAGIC)
3055 if (!bd || bd->magic != DGAP_BOARD_MAGIC)
3070 spin_lock_irqsave(&bd->bd_lock, lock_flags);
3071 spin_lock_irqsave(&ch->ch_lock, lock_flags2);
3073 dgap_cmdw(ch, SBREAK, (u16) SBREAK_TIME, 0);
3075 dgap_cmdw(ch, SBREAK, (u16) msec, 0);
3077 spin_unlock_irqrestore(&ch->ch_lock, lock_flags2);
3078 spin_unlock_irqrestore(&bd->bd_lock, lock_flags);
3084 * dgap_tty_wait_until_sent()
3086 * wait until data has been transmitted, called by ld.
3088 static void dgap_tty_wait_until_sent(struct tty_struct *tty, int timeout)
3090 dgap_wait_for_drain(tty);
3096 * send a high priority character, called by ld.
3098 static void dgap_tty_send_xchar(struct tty_struct *tty, char c)
3101 struct channel_t *ch;
3106 if (!tty || tty->magic != TTY_MAGIC)
3109 un = tty->driver_data;
3110 if (!un || un->magic != DGAP_UNIT_MAGIC)
3114 if (!ch || ch->magic != DGAP_CHANNEL_MAGIC)
3118 if (!bd || bd->magic != DGAP_BOARD_MAGIC)
3121 spin_lock_irqsave(&bd->bd_lock, lock_flags);
3122 spin_lock_irqsave(&ch->ch_lock, lock_flags2);
3125 * This is technically what we should do.
3126 * However, the NIST tests specifically want
3127 * to see each XON or XOFF character that it
3128 * sends, so lets just send each character
3132 if (c == STOP_CHAR(tty))
3133 dgap_cmdw(ch, RPAUSE, 0, 0);
3134 else if (c == START_CHAR(tty))
3135 dgap_cmdw(ch, RRESUME, 0, 0);
3137 dgap_wmove(ch, &c, 1);
3139 dgap_wmove(ch, &c, 1);
3142 spin_unlock_irqrestore(&ch->ch_lock, lock_flags2);
3143 spin_unlock_irqrestore(&bd->bd_lock, lock_flags);
3149 * Return modem signals to ld.
3151 static int dgap_get_modem_info(struct channel_t *ch, unsigned int __user *value)
3158 if (!ch || ch->magic != DGAP_CHANNEL_MAGIC)
3161 spin_lock_irqsave(&ch->ch_lock, lock_flags);
3163 mstat = readb(&(ch->ch_bs->m_stat));
3164 /* Append any outbound signals that might be pending... */
3165 mstat |= ch->ch_mostat;
3167 spin_unlock_irqrestore(&ch->ch_lock, lock_flags);
3171 if (mstat & D_DTR(ch))
3172 result |= TIOCM_DTR;
3173 if (mstat & D_RTS(ch))
3174 result |= TIOCM_RTS;
3175 if (mstat & D_CTS(ch))
3176 result |= TIOCM_CTS;
3177 if (mstat & D_DSR(ch))
3178 result |= TIOCM_DSR;
3179 if (mstat & D_RI(ch))
3181 if (mstat & D_CD(ch))
3184 rc = put_user(result, value);
3190 * dgap_set_modem_info()
3192 * Set modem signals, called by ld.
3194 static int dgap_set_modem_info(struct tty_struct *tty, unsigned int command,
3195 unsigned int __user *value)
3198 struct channel_t *ch;
3201 unsigned int arg = 0;
3205 if (!tty || tty->magic != TTY_MAGIC)
3208 un = tty->driver_data;
3209 if (!un || un->magic != DGAP_UNIT_MAGIC)
3213 if (!ch || ch->magic != DGAP_CHANNEL_MAGIC)
3217 if (!bd || bd->magic != DGAP_BOARD_MAGIC)
3220 ret = get_user(arg, value);
3226 if (arg & TIOCM_RTS) {
3227 ch->ch_mforce |= D_RTS(ch);
3228 ch->ch_mval |= D_RTS(ch);
3231 if (arg & TIOCM_DTR) {
3232 ch->ch_mforce |= D_DTR(ch);
3233 ch->ch_mval |= D_DTR(ch);
3239 if (arg & TIOCM_RTS) {
3240 ch->ch_mforce |= D_RTS(ch);
3241 ch->ch_mval &= ~(D_RTS(ch));
3244 if (arg & TIOCM_DTR) {
3245 ch->ch_mforce |= D_DTR(ch);
3246 ch->ch_mval &= ~(D_DTR(ch));
3252 ch->ch_mforce = D_DTR(ch)|D_RTS(ch);
3254 if (arg & TIOCM_RTS)
3255 ch->ch_mval |= D_RTS(ch);
3257 ch->ch_mval &= ~(D_RTS(ch));
3259 if (arg & TIOCM_DTR)
3260 ch->ch_mval |= (D_DTR(ch));
3262 ch->ch_mval &= ~(D_DTR(ch));
3270 spin_lock_irqsave(&bd->bd_lock, lock_flags);
3271 spin_lock_irqsave(&ch->ch_lock, lock_flags2);
3275 spin_unlock_irqrestore(&ch->ch_lock, lock_flags2);
3276 spin_unlock_irqrestore(&bd->bd_lock, lock_flags);
3282 * dgap_tty_digigeta()
3284 * Ioctl to get the information for ditty.
3289 static int dgap_tty_digigeta(struct tty_struct *tty,
3290 struct digi_t __user *retinfo)
3292 struct channel_t *ch;
3300 if (!tty || tty->magic != TTY_MAGIC)
3303 un = tty->driver_data;
3304 if (!un || un->magic != DGAP_UNIT_MAGIC)
3308 if (!ch || ch->magic != DGAP_CHANNEL_MAGIC)
3311 memset(&tmp, 0, sizeof(tmp));
3313 spin_lock_irqsave(&ch->ch_lock, lock_flags);
3314 memcpy(&tmp, &ch->ch_digi, sizeof(tmp));
3315 spin_unlock_irqrestore(&ch->ch_lock, lock_flags);
3317 if (copy_to_user(retinfo, &tmp, sizeof(*retinfo)))
3324 * dgap_tty_digiseta()
3326 * Ioctl to set the information for ditty.
3331 static int dgap_tty_digiseta(struct tty_struct *tty,
3332 struct digi_t __user *new_info)
3335 struct channel_t *ch;
3337 struct digi_t new_digi;
3338 ulong lock_flags = 0;
3339 unsigned long lock_flags2;
3341 if (!tty || tty->magic != TTY_MAGIC)
3344 un = tty->driver_data;
3345 if (!un || un->magic != DGAP_UNIT_MAGIC)
3349 if (!ch || ch->magic != DGAP_CHANNEL_MAGIC)
3353 if (!bd || bd->magic != DGAP_BOARD_MAGIC)
3356 if (copy_from_user(&new_digi, new_info, sizeof(struct digi_t)))
3359 spin_lock_irqsave(&bd->bd_lock, lock_flags);
3360 spin_lock_irqsave(&ch->ch_lock, lock_flags2);
3362 memcpy(&ch->ch_digi, &new_digi, sizeof(struct digi_t));
3364 if (ch->ch_digi.digi_maxcps < 1)
3365 ch->ch_digi.digi_maxcps = 1;
3367 if (ch->ch_digi.digi_maxcps > 10000)
3368 ch->ch_digi.digi_maxcps = 10000;
3370 if (ch->ch_digi.digi_bufsize < 10)
3371 ch->ch_digi.digi_bufsize = 10;
3373 if (ch->ch_digi.digi_maxchar < 1)
3374 ch->ch_digi.digi_maxchar = 1;
3376 if (ch->ch_digi.digi_maxchar > ch->ch_digi.digi_bufsize)
3377 ch->ch_digi.digi_maxchar = ch->ch_digi.digi_bufsize;
3379 if (ch->ch_digi.digi_onlen > DIGI_PLEN)
3380 ch->ch_digi.digi_onlen = DIGI_PLEN;
3382 if (ch->ch_digi.digi_offlen > DIGI_PLEN)
3383 ch->ch_digi.digi_offlen = DIGI_PLEN;
3387 spin_unlock_irqrestore(&ch->ch_lock, lock_flags2);
3388 spin_unlock_irqrestore(&bd->bd_lock, lock_flags);
3394 * dgap_tty_digigetedelay()
3396 * Ioctl to get the current edelay setting.
3401 static int dgap_tty_digigetedelay(struct tty_struct *tty, int __user *retinfo)
3403 struct channel_t *ch;
3411 if (!tty || tty->magic != TTY_MAGIC)
3414 un = tty->driver_data;
3415 if (!un || un->magic != DGAP_UNIT_MAGIC)
3419 if (!ch || ch->magic != DGAP_CHANNEL_MAGIC)
3422 memset(&tmp, 0, sizeof(tmp));
3424 spin_lock_irqsave(&ch->ch_lock, lock_flags);
3425 tmp = readw(&(ch->ch_bs->edelay));
3426 spin_unlock_irqrestore(&ch->ch_lock, lock_flags);
3428 if (copy_to_user(retinfo, &tmp, sizeof(*retinfo)))
3435 * dgap_tty_digisetedelay()
3437 * Ioctl to set the EDELAY setting
3440 static int dgap_tty_digisetedelay(struct tty_struct *tty, int __user *new_info)
3443 struct channel_t *ch;
3449 if (!tty || tty->magic != TTY_MAGIC)
3452 un = tty->driver_data;
3453 if (!un || un->magic != DGAP_UNIT_MAGIC)
3457 if (!ch || ch->magic != DGAP_CHANNEL_MAGIC)
3461 if (!bd || bd->magic != DGAP_BOARD_MAGIC)
3464 if (copy_from_user(&new_digi, new_info, sizeof(int)))
3467 spin_lock_irqsave(&bd->bd_lock, lock_flags);
3468 spin_lock_irqsave(&ch->ch_lock, lock_flags2);
3470 writew((u16) new_digi, &(ch->ch_bs->edelay));
3474 spin_unlock_irqrestore(&ch->ch_lock, lock_flags2);
3475 spin_unlock_irqrestore(&bd->bd_lock, lock_flags);
3481 * dgap_tty_digigetcustombaud()
3483 * Ioctl to get the current custom baud rate setting.
3485 static int dgap_tty_digigetcustombaud(struct tty_struct *tty,
3486 int __user *retinfo)
3488 struct channel_t *ch;
3496 if (!tty || tty->magic != TTY_MAGIC)
3499 un = tty->driver_data;
3500 if (!un || un->magic != DGAP_UNIT_MAGIC)
3504 if (!ch || ch->magic != DGAP_CHANNEL_MAGIC)
3507 memset(&tmp, 0, sizeof(tmp));
3509 spin_lock_irqsave(&ch->ch_lock, lock_flags);
3510 tmp = dgap_get_custom_baud(ch);
3511 spin_unlock_irqrestore(&ch->ch_lock, lock_flags);
3513 if (copy_to_user(retinfo, &tmp, sizeof(*retinfo)))
3520 * dgap_tty_digisetcustombaud()
3522 * Ioctl to set the custom baud rate setting
3524 static int dgap_tty_digisetcustombaud(struct tty_struct *tty,
3525 int __user *new_info)
3528 struct channel_t *ch;
3534 if (!tty || tty->magic != TTY_MAGIC)
3537 un = tty->driver_data;
3538 if (!un || un->magic != DGAP_UNIT_MAGIC)
3542 if (!ch || ch->magic != DGAP_CHANNEL_MAGIC)
3546 if (!bd || bd->magic != DGAP_BOARD_MAGIC)
3550 if (copy_from_user(&new_rate, new_info, sizeof(unsigned int)))
3553 if (bd->bd_flags & BD_FEP5PLUS) {
3555 spin_lock_irqsave(&bd->bd_lock, lock_flags);
3556 spin_lock_irqsave(&ch->ch_lock, lock_flags2);
3558 ch->ch_custom_speed = new_rate;
3562 spin_unlock_irqrestore(&ch->ch_lock, lock_flags2);
3563 spin_unlock_irqrestore(&bd->bd_lock, lock_flags);
3570 * dgap_set_termios()
3572 static void dgap_tty_set_termios(struct tty_struct *tty,
3573 struct ktermios *old_termios)
3576 struct channel_t *ch;
3578 unsigned long lock_flags;
3579 unsigned long lock_flags2;
3581 if (!tty || tty->magic != TTY_MAGIC)
3584 un = tty->driver_data;
3585 if (!un || un->magic != DGAP_UNIT_MAGIC)
3589 if (!ch || ch->magic != DGAP_CHANNEL_MAGIC)
3593 if (!bd || bd->magic != DGAP_BOARD_MAGIC)
3596 spin_lock_irqsave(&bd->bd_lock, lock_flags);
3597 spin_lock_irqsave(&ch->ch_lock, lock_flags2);
3599 ch->ch_c_cflag = tty->termios.c_cflag;
3600 ch->ch_c_iflag = tty->termios.c_iflag;
3601 ch->ch_c_oflag = tty->termios.c_oflag;
3602 ch->ch_c_lflag = tty->termios.c_lflag;
3603 ch->ch_startc = tty->termios.c_cc[VSTART];
3604 ch->ch_stopc = tty->termios.c_cc[VSTOP];
3609 spin_unlock_irqrestore(&ch->ch_lock, lock_flags2);
3610 spin_unlock_irqrestore(&bd->bd_lock, lock_flags);
3613 static void dgap_tty_throttle(struct tty_struct *tty)
3616 struct channel_t *ch;
3621 if (!tty || tty->magic != TTY_MAGIC)
3624 un = tty->driver_data;
3625 if (!un || un->magic != DGAP_UNIT_MAGIC)
3629 if (!ch || ch->magic != DGAP_CHANNEL_MAGIC)
3633 if (!bd || bd->magic != DGAP_BOARD_MAGIC)
3636 spin_lock_irqsave(&bd->bd_lock, lock_flags);
3637 spin_lock_irqsave(&ch->ch_lock, lock_flags2);
3639 ch->ch_flags |= (CH_RXBLOCK);
3641 dgap_cmdw(ch, RPAUSE, 0, 0);
3644 spin_unlock_irqrestore(&ch->ch_lock, lock_flags2);
3645 spin_unlock_irqrestore(&bd->bd_lock, lock_flags);
3649 static void dgap_tty_unthrottle(struct tty_struct *tty)
3652 struct channel_t *ch;
3657 if (!tty || tty->magic != TTY_MAGIC)
3660 un = tty->driver_data;
3661 if (!un || un->magic != DGAP_UNIT_MAGIC)
3665 if (!ch || ch->magic != DGAP_CHANNEL_MAGIC)
3669 if (!bd || bd->magic != DGAP_BOARD_MAGIC)
3672 spin_lock_irqsave(&bd->bd_lock, lock_flags);
3673 spin_lock_irqsave(&ch->ch_lock, lock_flags2);
3675 ch->ch_flags &= ~(CH_RXBLOCK);
3678 dgap_cmdw(ch, RRESUME, 0, 0);
3681 spin_unlock_irqrestore(&ch->ch_lock, lock_flags2);
3682 spin_unlock_irqrestore(&bd->bd_lock, lock_flags);
3685 static void dgap_tty_start(struct tty_struct *tty)
3688 struct channel_t *ch;
3693 if (!tty || tty->magic != TTY_MAGIC)
3696 un = tty->driver_data;
3697 if (!un || un->magic != DGAP_UNIT_MAGIC)
3701 if (!ch || ch->magic != DGAP_CHANNEL_MAGIC)
3705 if (!bd || bd->magic != DGAP_BOARD_MAGIC)
3708 spin_lock_irqsave(&bd->bd_lock, lock_flags);
3709 spin_lock_irqsave(&ch->ch_lock, lock_flags2);
3711 dgap_cmdw(ch, RESUMETX, 0, 0);
3713 spin_unlock_irqrestore(&ch->ch_lock, lock_flags2);
3714 spin_unlock_irqrestore(&bd->bd_lock, lock_flags);
3718 static void dgap_tty_stop(struct tty_struct *tty)
3721 struct channel_t *ch;
3726 if (!tty || tty->magic != TTY_MAGIC)
3729 un = tty->driver_data;
3730 if (!un || un->magic != DGAP_UNIT_MAGIC)
3734 if (!ch || ch->magic != DGAP_CHANNEL_MAGIC)
3738 if (!bd || bd->magic != DGAP_BOARD_MAGIC)
3741 spin_lock_irqsave(&bd->bd_lock, lock_flags);
3742 spin_lock_irqsave(&ch->ch_lock, lock_flags2);
3744 dgap_cmdw(ch, PAUSETX, 0, 0);
3746 spin_unlock_irqrestore(&ch->ch_lock, lock_flags2);
3747 spin_unlock_irqrestore(&bd->bd_lock, lock_flags);
3752 * dgap_tty_flush_chars()
3754 * Flush the cook buffer
3756 * Note to self, and any other poor souls who venture here:
3758 * flush in this case DOES NOT mean dispose of the data.
3759 * instead, it means "stop buffering and send it if you
3760 * haven't already." Just guess how I figured that out... SRW 2-Jun-98
3762 * It is also always called in interrupt context - JAR 8-Sept-99
3764 static void dgap_tty_flush_chars(struct tty_struct *tty)
3767 struct channel_t *ch;
3772 if (!tty || tty->magic != TTY_MAGIC)
3775 un = tty->driver_data;
3776 if (!un || un->magic != DGAP_UNIT_MAGIC)
3780 if (!ch || ch->magic != DGAP_CHANNEL_MAGIC)
3784 if (!bd || bd->magic != DGAP_BOARD_MAGIC)
3787 spin_lock_irqsave(&bd->bd_lock, lock_flags);
3788 spin_lock_irqsave(&ch->ch_lock, lock_flags2);
3790 /* TODO: Do something here */
3792 spin_unlock_irqrestore(&ch->ch_lock, lock_flags2);
3793 spin_unlock_irqrestore(&bd->bd_lock, lock_flags);
3797 * dgap_tty_flush_buffer()
3799 * Flush Tx buffer (make in == out)
3801 static void dgap_tty_flush_buffer(struct tty_struct *tty)
3804 struct channel_t *ch;
3810 if (!tty || tty->magic != TTY_MAGIC)
3813 un = tty->driver_data;
3814 if (!un || un->magic != DGAP_UNIT_MAGIC)
3818 if (!ch || ch->magic != DGAP_CHANNEL_MAGIC)
3822 if (!bd || bd->magic != DGAP_BOARD_MAGIC)
3825 spin_lock_irqsave(&bd->bd_lock, lock_flags);
3826 spin_lock_irqsave(&ch->ch_lock, lock_flags2);
3828 ch->ch_flags &= ~CH_STOP;
3829 head = readw(&(ch->ch_bs->tx_head));
3830 dgap_cmdw(ch, FLUSHTX, (u16) head, 0);
3831 dgap_cmdw(ch, RESUMETX, 0, 0);
3832 if (ch->ch_tun.un_flags & (UN_LOW|UN_EMPTY)) {
3833 ch->ch_tun.un_flags &= ~(UN_LOW|UN_EMPTY);
3834 wake_up_interruptible(&ch->ch_tun.un_flags_wait);
3836 if (ch->ch_pun.un_flags & (UN_LOW|UN_EMPTY)) {
3837 ch->ch_pun.un_flags &= ~(UN_LOW|UN_EMPTY);
3838 wake_up_interruptible(&ch->ch_pun.un_flags_wait);
3841 spin_unlock_irqrestore(&ch->ch_lock, lock_flags2);
3842 spin_unlock_irqrestore(&bd->bd_lock, lock_flags);
3843 if (waitqueue_active(&tty->write_wait))
3844 wake_up_interruptible(&tty->write_wait);
3848 /*****************************************************************************
3850 * The IOCTL function and all of its helpers
3852 *****************************************************************************/
3857 * The usual assortment of ioctl's
3859 static int dgap_tty_ioctl(struct tty_struct *tty, unsigned int cmd,
3863 struct channel_t *ch;
3867 ulong lock_flags = 0;
3868 ulong lock_flags2 = 0;
3869 void __user *uarg = (void __user *) arg;
3871 if (!tty || tty->magic != TTY_MAGIC)
3874 un = tty->driver_data;
3875 if (!un || un->magic != DGAP_UNIT_MAGIC)
3879 if (!ch || ch->magic != DGAP_CHANNEL_MAGIC)
3883 if (!bd || bd->magic != DGAP_BOARD_MAGIC)
3886 spin_lock_irqsave(&bd->bd_lock, lock_flags);
3887 spin_lock_irqsave(&ch->ch_lock, lock_flags2);
3889 if (un->un_open_count <= 0) {
3890 spin_unlock_irqrestore(&ch->ch_lock, lock_flags2);
3891 spin_unlock_irqrestore(&bd->bd_lock, lock_flags);
3897 /* Here are all the standard ioctl's that we MUST implement */
3901 * TCSBRK is SVID version: non-zero arg --> no break
3902 * this behaviour is exploited by tcdrain().
3904 * According to POSIX.1 spec (7.2.2.1.2) breaks should be
3905 * between 0.25 and 0.5 seconds so we'll ask for something
3906 * in the middle: 0.375 seconds.
3908 rc = tty_check_change(tty);
3909 spin_unlock_irqrestore(&ch->ch_lock, lock_flags2);
3910 spin_unlock_irqrestore(&bd->bd_lock, lock_flags);
3914 rc = dgap_wait_for_drain(tty);
3919 spin_lock_irqsave(&bd->bd_lock, lock_flags);
3920 spin_lock_irqsave(&ch->ch_lock, lock_flags2);
3922 if (((cmd == TCSBRK) && (!arg)) || (cmd == TCSBRKP))
3923 dgap_cmdw(ch, SBREAK, (u16) SBREAK_TIME, 0);
3925 spin_unlock_irqrestore(&ch->ch_lock, lock_flags2);
3926 spin_unlock_irqrestore(&bd->bd_lock, lock_flags);
3931 /* support for POSIX tcsendbreak()
3933 * According to POSIX.1 spec (7.2.2.1.2) breaks should be
3934 * between 0.25 and 0.5 seconds so we'll ask for something
3935 * in the middle: 0.375 seconds.
3937 rc = tty_check_change(tty);
3938 spin_unlock_irqrestore(&ch->ch_lock, lock_flags2);
3939 spin_unlock_irqrestore(&bd->bd_lock, lock_flags);
3943 rc = dgap_wait_for_drain(tty);
3947 spin_lock_irqsave(&bd->bd_lock, lock_flags);
3948 spin_lock_irqsave(&ch->ch_lock, lock_flags2);
3950 dgap_cmdw(ch, SBREAK, (u16) SBREAK_TIME, 0);
3952 spin_unlock_irqrestore(&ch->ch_lock, lock_flags2);
3953 spin_unlock_irqrestore(&bd->bd_lock, lock_flags);
3959 * FEP5 doesn't support turning on a break unconditionally.
3960 * The FEP5 device will stop sending a break automatically
3961 * after the specified time value that was sent when turning on
3964 rc = tty_check_change(tty);
3965 spin_unlock_irqrestore(&ch->ch_lock, lock_flags2);
3966 spin_unlock_irqrestore(&bd->bd_lock, lock_flags);
3970 rc = dgap_wait_for_drain(tty);
3974 spin_lock_irqsave(&bd->bd_lock, lock_flags);
3975 spin_lock_irqsave(&ch->ch_lock, lock_flags2);
3977 dgap_cmdw(ch, SBREAK, (u16) SBREAK_TIME, 0);
3979 spin_unlock_irqrestore(&ch->ch_lock, lock_flags2);
3980 spin_unlock_irqrestore(&bd->bd_lock, lock_flags);
3986 * FEP5 doesn't support turning off a break unconditionally.
3987 * The FEP5 device will stop sending a break automatically
3988 * after the specified time value that was sent when turning on
3991 spin_unlock_irqrestore(&ch->ch_lock, lock_flags2);
3992 spin_unlock_irqrestore(&bd->bd_lock, lock_flags);
3997 spin_unlock_irqrestore(&ch->ch_lock, lock_flags2);
3998 spin_unlock_irqrestore(&bd->bd_lock, lock_flags);
4000 rc = put_user(C_CLOCAL(tty) ? 1 : 0,
4001 (unsigned long __user *) arg);
4005 spin_unlock_irqrestore(&ch->ch_lock, lock_flags2);
4006 spin_unlock_irqrestore(&bd->bd_lock, lock_flags);
4008 rc = get_user(arg, (unsigned long __user *) arg);
4012 spin_lock_irqsave(&bd->bd_lock, lock_flags);
4013 spin_lock_irqsave(&ch->ch_lock, lock_flags2);
4014 tty->termios.c_cflag = ((tty->termios.c_cflag & ~CLOCAL) |
4015 (arg ? CLOCAL : 0));
4017 spin_unlock_irqrestore(&ch->ch_lock, lock_flags2);
4018 spin_unlock_irqrestore(&bd->bd_lock, lock_flags);
4023 spin_unlock_irqrestore(&ch->ch_lock, lock_flags2);
4024 spin_unlock_irqrestore(&bd->bd_lock, lock_flags);
4025 return dgap_get_modem_info(ch, uarg);
4030 spin_unlock_irqrestore(&ch->ch_lock, lock_flags2);
4031 spin_unlock_irqrestore(&bd->bd_lock, lock_flags);
4032 return dgap_set_modem_info(tty, cmd, uarg);
4035 * Here are any additional ioctl's that we want to implement
4040 * The linux tty driver doesn't have a flush
4041 * input routine for the driver, assuming all backed
4042 * up data is in the line disc. buffers. However,
4043 * we all know that's not the case. Here, we
4044 * act on the ioctl, but then lie and say we didn't
4045 * so the line discipline will process the flush
4048 rc = tty_check_change(tty);
4050 spin_unlock_irqrestore(&ch->ch_lock, lock_flags2);
4051 spin_unlock_irqrestore(&bd->bd_lock, lock_flags);
4055 if ((arg == TCIFLUSH) || (arg == TCIOFLUSH)) {
4056 if (!(un->un_type == DGAP_PRINT)) {
4057 head = readw(&(ch->ch_bs->rx_head));
4058 writew(head, &(ch->ch_bs->rx_tail));
4059 writeb(0, &(ch->ch_bs->orun));
4063 if ((arg != TCOFLUSH) && (arg != TCIOFLUSH)) {
4064 /* pretend we didn't recognize this IOCTL */
4065 spin_unlock_irqrestore(&ch->ch_lock, lock_flags2);
4066 spin_unlock_irqrestore(&bd->bd_lock, lock_flags);
4068 return -ENOIOCTLCMD;
4071 ch->ch_flags &= ~CH_STOP;
4072 head = readw(&(ch->ch_bs->tx_head));
4073 dgap_cmdw(ch, FLUSHTX, (u16) head, 0);
4074 dgap_cmdw(ch, RESUMETX, 0, 0);
4075 if (ch->ch_tun.un_flags & (UN_LOW|UN_EMPTY)) {
4076 ch->ch_tun.un_flags &= ~(UN_LOW|UN_EMPTY);
4077 wake_up_interruptible(&ch->ch_tun.un_flags_wait);
4079 if (ch->ch_pun.un_flags & (UN_LOW|UN_EMPTY)) {
4080 ch->ch_pun.un_flags &= ~(UN_LOW|UN_EMPTY);
4081 wake_up_interruptible(&ch->ch_pun.un_flags_wait);
4083 if (waitqueue_active(&tty->write_wait))
4084 wake_up_interruptible(&tty->write_wait);
4086 /* Can't hold any locks when calling tty_wakeup! */
4087 spin_unlock_irqrestore(&ch->ch_lock, lock_flags2);
4088 spin_unlock_irqrestore(&bd->bd_lock, lock_flags);
4091 /* pretend we didn't recognize this IOCTL */
4092 return -ENOIOCTLCMD;
4097 * The linux tty driver doesn't have a flush
4098 * input routine for the driver, assuming all backed
4099 * up data is in the line disc. buffers. However,
4100 * we all know that's not the case. Here, we
4101 * act on the ioctl, but then lie and say we didn't
4102 * so the line discipline will process the flush
4105 if (cmd == TCSETSF) {
4107 ch->ch_flags &= ~CH_STOP;
4108 head = readw(&(ch->ch_bs->rx_head));
4109 writew(head, &(ch->ch_bs->rx_tail));
4112 /* now wait for all the output to drain */
4113 spin_unlock_irqrestore(&ch->ch_lock, lock_flags2);
4114 spin_unlock_irqrestore(&bd->bd_lock, lock_flags);
4115 rc = dgap_wait_for_drain(tty);
4119 /* pretend we didn't recognize this */
4120 return -ENOIOCTLCMD;
4124 spin_unlock_irqrestore(&ch->ch_lock, lock_flags2);
4125 spin_unlock_irqrestore(&bd->bd_lock, lock_flags);
4126 rc = dgap_wait_for_drain(tty);
4130 /* pretend we didn't recognize this */
4131 return -ENOIOCTLCMD;
4135 * The Linux Line Discipline (LD) would do this for us if we
4136 * let it, but we have the special firmware options to do this
4137 * the "right way" regardless of hardware or software flow
4138 * control so we'll do it outselves instead of letting the LD
4141 rc = tty_check_change(tty);
4143 spin_unlock_irqrestore(&ch->ch_lock, lock_flags2);
4144 spin_unlock_irqrestore(&bd->bd_lock, lock_flags);
4151 spin_unlock_irqrestore(&ch->ch_lock, lock_flags2);
4152 spin_unlock_irqrestore(&bd->bd_lock, lock_flags);
4153 dgap_tty_start(tty);
4156 spin_unlock_irqrestore(&ch->ch_lock, lock_flags2);
4157 spin_unlock_irqrestore(&bd->bd_lock, lock_flags);
4161 spin_unlock_irqrestore(&ch->ch_lock, lock_flags2);
4162 spin_unlock_irqrestore(&bd->bd_lock, lock_flags);
4163 /* Make the ld do it */
4164 return -ENOIOCTLCMD;
4166 spin_unlock_irqrestore(&ch->ch_lock, lock_flags2);
4167 spin_unlock_irqrestore(&bd->bd_lock, lock_flags);
4168 /* Make the ld do it */
4169 return -ENOIOCTLCMD;
4171 spin_unlock_irqrestore(&ch->ch_lock, lock_flags2);
4172 spin_unlock_irqrestore(&bd->bd_lock, lock_flags);
4177 /* get information for ditty */
4178 spin_unlock_irqrestore(&ch->ch_lock, lock_flags2);
4179 spin_unlock_irqrestore(&bd->bd_lock, lock_flags);
4180 return dgap_tty_digigeta(tty, uarg);
4185 /* set information for ditty */
4186 if (cmd == (DIGI_SETAW)) {
4188 spin_unlock_irqrestore(&ch->ch_lock, lock_flags2);
4189 spin_unlock_irqrestore(&bd->bd_lock, lock_flags);
4190 rc = dgap_wait_for_drain(tty);
4193 spin_lock_irqsave(&bd->bd_lock, lock_flags);
4194 spin_lock_irqsave(&ch->ch_lock, lock_flags2);
4196 tty_ldisc_flush(tty);
4200 spin_unlock_irqrestore(&ch->ch_lock, lock_flags2);
4201 spin_unlock_irqrestore(&bd->bd_lock, lock_flags);
4202 return dgap_tty_digiseta(tty, uarg);
4205 spin_unlock_irqrestore(&ch->ch_lock, lock_flags2);
4206 spin_unlock_irqrestore(&bd->bd_lock, lock_flags);
4207 return dgap_tty_digigetedelay(tty, uarg);
4210 spin_unlock_irqrestore(&ch->ch_lock, lock_flags2);
4211 spin_unlock_irqrestore(&bd->bd_lock, lock_flags);
4212 return dgap_tty_digisetedelay(tty, uarg);
4214 case DIGI_GETCUSTOMBAUD:
4215 spin_unlock_irqrestore(&ch->ch_lock, lock_flags2);
4216 spin_unlock_irqrestore(&bd->bd_lock, lock_flags);
4217 return dgap_tty_digigetcustombaud(tty, uarg);
4219 case DIGI_SETCUSTOMBAUD:
4220 spin_unlock_irqrestore(&ch->ch_lock, lock_flags2);
4221 spin_unlock_irqrestore(&bd->bd_lock, lock_flags);
4222 return dgap_tty_digisetcustombaud(tty, uarg);
4224 case DIGI_RESET_PORT:
4225 dgap_firmware_reset_port(ch);
4227 spin_unlock_irqrestore(&ch->ch_lock, lock_flags2);
4228 spin_unlock_irqrestore(&bd->bd_lock, lock_flags);
4232 spin_unlock_irqrestore(&ch->ch_lock, lock_flags2);
4233 spin_unlock_irqrestore(&bd->bd_lock, lock_flags);
4235 return -ENOIOCTLCMD;
4239 static int dgap_after_config_loaded(int board)
4242 * Initialize KME waitqueues...
4244 init_waitqueue_head(&(dgap_board[board]->kme_wait));
4247 * allocate flip buffer for board.
4249 dgap_board[board]->flipbuf = kmalloc(MYFLIPLEN, GFP_ATOMIC);
4250 if (!dgap_board[board]->flipbuf)
4253 dgap_board[board]->flipflagbuf = kmalloc(MYFLIPLEN, GFP_ATOMIC);
4254 if (!dgap_board[board]->flipflagbuf) {
4255 kfree(dgap_board[board]->flipbuf);
4263 * Create pr and tty device entries
4265 static int dgap_tty_register_ports(struct board_t *brd)
4267 struct channel_t *ch;
4270 brd->serial_ports = kcalloc(brd->nasync, sizeof(*brd->serial_ports),
4272 if (brd->serial_ports == NULL)
4274 for (i = 0; i < brd->nasync; i++)
4275 tty_port_init(&brd->serial_ports[i]);
4277 brd->printer_ports = kcalloc(brd->nasync, sizeof(*brd->printer_ports),
4279 if (brd->printer_ports == NULL) {
4280 kfree(brd->serial_ports);
4283 for (i = 0; i < brd->nasync; i++)
4284 tty_port_init(&brd->printer_ports[i]);
4286 ch = brd->channels[0];
4287 for (i = 0; i < brd->nasync; i++, ch = brd->channels[i]) {
4289 struct device *classp;
4291 classp = tty_port_register_device(&brd->serial_ports[i],
4293 brd->firstminor + i, NULL);
4295 dgap_create_tty_sysfs(&ch->ch_tun, classp);
4296 ch->ch_tun.un_sysfs = classp;
4298 classp = tty_port_register_device(&brd->printer_ports[i],
4300 brd->firstminor + i, NULL);
4302 dgap_create_tty_sysfs(&ch->ch_pun, classp);
4303 ch->ch_pun.un_sysfs = classp;
4305 dgap_create_ports_sysfiles(brd);
4311 * Copies the BIOS code from the user to the board,
4312 * and starts the BIOS running.
4314 static void dgap_do_bios_load(struct board_t *brd, const u8 *ubios, int len)
4320 if (!brd || (brd->magic != DGAP_BOARD_MAGIC) || !brd->re_map_membase)
4323 addr = brd->re_map_membase;
4328 for (i = 0; i < 16; i++)
4329 writeb(0, addr + POSTAREA + i);
4335 memcpy_toio(addr + offset, ubios, len);
4337 writel(0x0bf00401, addr);
4338 writel(0, (addr + 4));
4340 /* Clear the reset, and change states. */
4341 writeb(FEPCLR, brd->re_map_port);
4345 * Checks to see if the BIOS completed running on the card.
4347 static int dgap_test_bios(struct board_t *brd)
4354 if (!brd || (brd->magic != DGAP_BOARD_MAGIC) || !brd->re_map_membase)
4357 addr = brd->re_map_membase;
4358 word = readw(addr + POSTAREA);
4361 * It can take 5-6 seconds for a board to
4362 * pass the bios self test and post results.
4363 * Give it 10 seconds.
4365 brd->wait_for_bios = 0;
4366 while (brd->wait_for_bios < 1000) {
4367 /* Check to see if BIOS thinks board is good. (GD). */
4368 if (word == *(u16 *) "GD")
4370 msleep_interruptible(10);
4371 brd->wait_for_bios++;
4372 word = readw(addr + POSTAREA);
4375 /* Gave up on board after too long of time taken */
4376 err1 = readw(addr + SEQUENCE);
4377 err2 = readw(addr + ERROR);
4378 pr_warn("dgap: %s failed diagnostics. Error #(%x,%x).\n",
4379 brd->name, err1, err2);
4380 brd->state = BOARD_FAILED;
4381 brd->dpastatus = BD_NOBIOS;
4387 * Copies the FEP code from the user to the board,
4388 * and starts the FEP running.
4390 static void dgap_do_fep_load(struct board_t *brd, const u8 *ufep, int len)
4395 if (!brd || (brd->magic != DGAP_BOARD_MAGIC) || !brd->re_map_membase)
4398 addr = brd->re_map_membase;
4404 memcpy_toio(addr + offset, ufep, len);
4407 * If board is a concentrator product, we need to give
4408 * it its config string describing how the concentrators look.
4410 if ((brd->type == PCX) || (brd->type == PEPC)) {
4416 xconfig = dgap_create_config_string(brd, string);
4418 /* Write string to board memory */
4419 config = addr + CONFIG;
4420 for (; i < CONFIGSIZE; i++, config++, xconfig++) {
4421 writeb(*xconfig, config);
4422 if ((*xconfig & 0xff) == 0xff)
4427 writel(0xbfc01004, (addr + 0xc34));
4428 writel(0x3, (addr + 0xc30));
4433 * Waits for the FEP to report thats its ready for us to use.
4435 static int dgap_test_fep(struct board_t *brd)
4442 if (!brd || (brd->magic != DGAP_BOARD_MAGIC) || !brd->re_map_membase)
4445 addr = brd->re_map_membase;
4446 word = readw(addr + FEPSTAT);
4449 * It can take 2-3 seconds for the FEP to
4450 * be up and running. Give it 5 secs.
4452 brd->wait_for_fep = 0;
4453 while (brd->wait_for_fep < 500) {
4454 /* Check to see if FEP is up and running now. */
4455 if (word == *(u16 *) "OS") {
4457 * Check to see if the board can support FEP5+ commands.
4459 word = readw(addr + FEP5_PLUS);
4460 if (word == *(u16 *) "5A")
4461 brd->bd_flags |= BD_FEP5PLUS;
4465 msleep_interruptible(10);
4466 brd->wait_for_fep++;
4467 word = readw(addr + FEPSTAT);
4470 /* Gave up on board after too long of time taken */
4471 err1 = readw(addr + SEQUENCE);
4472 err2 = readw(addr + ERROR);
4473 pr_warn("dgap: FEPOS for %s not functioning. Error #(%x,%x).\n",
4474 brd->name, err1, err2);
4475 brd->state = BOARD_FAILED;
4476 brd->dpastatus = BD_NOFEP;
4482 * Physically forces the FEP5 card to reset itself.
4484 static void dgap_do_reset_board(struct board_t *brd)
4491 if (!brd || (brd->magic != DGAP_BOARD_MAGIC) ||
4492 !brd->re_map_membase || !brd->re_map_port)
4495 /* FEPRST does not vary among supported boards */
4496 writeb(FEPRST, brd->re_map_port);
4498 for (i = 0; i <= 1000; i++) {
4499 check = readb(brd->re_map_port) & 0xe;
4500 if (check == FEPRST)
4506 pr_warn("dgap: Board not resetting... Failing board.\n");
4507 brd->state = BOARD_FAILED;
4508 brd->dpastatus = BD_NOFEP;
4513 * Make sure there really is memory out there.
4515 writel(0xa55a3cc3, (brd->re_map_membase + LOWMEM));
4516 writel(0x5aa5c33c, (brd->re_map_membase + HIGHMEM));
4517 check1 = readl(brd->re_map_membase + LOWMEM);
4518 check2 = readl(brd->re_map_membase + HIGHMEM);
4520 if ((check1 != 0xa55a3cc3) || (check2 != 0x5aa5c33c)) {
4521 pr_warn("dgap: No memory at %p for board.\n",
4522 brd->re_map_membase);
4523 brd->state = BOARD_FAILED;
4524 brd->dpastatus = BD_NOFEP;
4530 #ifdef DIGI_CONCENTRATORS_SUPPORTED
4532 * Sends a concentrator image into the FEP5 board.
4534 static void dgap_do_conc_load(struct board_t *brd, u8 *uaddr, int len)
4536 char __iomem *vaddr;
4538 struct downld_t *to_dp;
4540 if (!brd || (brd->magic != DGAP_BOARD_MAGIC) || !brd->re_map_membase)
4543 vaddr = brd->re_map_membase;
4545 offset = readw((u16 *) (vaddr + DOWNREQ));
4546 to_dp = (struct downld_t *) (vaddr + (int) offset);
4547 memcpy_toio(to_dp, uaddr, len);
4549 /* Tell card we have data for it */
4550 writew(0, vaddr + (DOWNREQ));
4552 brd->conc_dl_status = NO_PENDING_CONCENTRATOR_REQUESTS;
4556 #define EXPANSION_ROM_SIZE (64 * 1024)
4557 #define FEP5_ROM_MAGIC (0xFEFFFFFF)
4559 static void dgap_get_vpd(struct board_t *brd)
4571 * Poke the magic number at the PCI Rom Address location.
4572 * If VPD is supported, the value read from that address
4575 magic = FEP5_ROM_MAGIC;
4576 pci_write_config_dword(brd->pdev, PCI_ROM_ADDRESS, magic);
4577 pci_read_config_dword(brd->pdev, PCI_ROM_ADDRESS, &magic);
4579 /* VPD not supported, bail */
4584 * To get to the OTPROM memory, we have to send the boards base
4585 * address or'ed with 1 into the PCI Rom Address location.
4587 magic = brd->membase | 0x01;
4588 pci_write_config_dword(brd->pdev, PCI_ROM_ADDRESS, magic);
4589 pci_read_config_dword(brd->pdev, PCI_ROM_ADDRESS, &magic);
4591 byte1 = readb(brd->re_map_membase);
4592 byte2 = readb(brd->re_map_membase + 1);
4595 * If the board correctly swapped to the OTPROM memory,
4596 * the first 2 bytes (header) should be 0x55, 0xAA
4598 if (byte1 == 0x55 && byte2 == 0xAA) {
4603 * We have to run through all the OTPROM memory looking
4604 * for the VPD offset.
4606 while (base_offset <= EXPANSION_ROM_SIZE) {
4609 * Lots of magic numbers here.
4611 * The VPD offset is located inside the ROM Data
4614 * We also have to remember the length of each
4615 * ROM Data Structure, so we can "hop" to the next
4616 * entry if the VPD isn't in the current
4617 * ROM Data Structure.
4619 rom_offset = readw(brd->re_map_membase +
4620 base_offset + 0x18);
4621 image_length = readw(brd->re_map_membase +
4622 rom_offset + 0x10) * 512;
4623 vpd_offset = readw(brd->re_map_membase +
4626 /* Found the VPD entry */
4630 /* We didn't find a VPD entry, go to next ROM entry. */
4631 base_offset += image_length;
4633 byte1 = readb(brd->re_map_membase + base_offset);
4634 byte2 = readb(brd->re_map_membase + base_offset + 1);
4637 * If the new ROM offset doesn't have 0x55, 0xAA
4638 * as its header, we have run out of ROM.
4640 if (byte1 != 0x55 || byte2 != 0xAA)
4645 * If we have a VPD offset, then mark the board
4646 * as having a valid VPD, and copy VPDSIZE (512) bytes of
4647 * that VPD to the buffer we have in our board structure.
4650 brd->bd_flags |= BD_HAS_VPD;
4651 for (i = 0; i < VPDSIZE; i++) {
4652 brd->vpd[i] = readb(brd->re_map_membase +
4659 * We MUST poke the magic number at the PCI Rom Address location again.
4660 * This makes the card report the regular board memory back to us,
4661 * rather than the OTPROM memory.
4663 magic = FEP5_ROM_MAGIC;
4664 pci_write_config_dword(brd->pdev, PCI_ROM_ADDRESS, magic);
4668 * Our board poller function.
4670 static void dgap_poll_tasklet(unsigned long data)
4672 struct board_t *bd = (struct board_t *) data;
4674 char __iomem *vaddr;
4677 if (!bd || (bd->magic != DGAP_BOARD_MAGIC))
4680 if (bd->inhibit_poller)
4683 spin_lock_irqsave(&bd->bd_lock, lock_flags);
4685 vaddr = bd->re_map_membase;
4688 * If board is ready, parse deeper to see if there is anything to do.
4690 if (bd->state == BOARD_READY) {
4692 struct ev_t __iomem *eaddr;
4694 if (!bd->re_map_membase) {
4695 spin_unlock_irqrestore(&bd->bd_lock, lock_flags);
4698 if (!bd->re_map_port) {
4699 spin_unlock_irqrestore(&bd->bd_lock, lock_flags);
4706 eaddr = (struct ev_t __iomem *) (vaddr + EVBUF);
4708 /* Get our head and tail */
4709 head = readw(&(eaddr->ev_head));
4710 tail = readw(&(eaddr->ev_tail));
4713 * If there is an event pending. Go service it.
4716 spin_unlock_irqrestore(&bd->bd_lock, lock_flags);
4718 spin_lock_irqsave(&bd->bd_lock, lock_flags);
4723 * If board is doing interrupts, ACK the interrupt.
4725 if (bd && bd->intr_running)
4726 readb(bd->re_map_port + 2);
4728 spin_unlock_irqrestore(&bd->bd_lock, lock_flags);
4732 spin_unlock_irqrestore(&bd->bd_lock, lock_flags);
4735 /*=======================================================================
4737 * dgap_cmdb - Sends a 2 byte command to the FEP.
4739 * ch - Pointer to channel structure.
4740 * cmd - Command to be sent.
4741 * byte1 - Integer containing first byte to be sent.
4742 * byte2 - Integer containing second byte to be sent.
4743 * ncmds - Wait until ncmds or fewer cmds are left
4744 * in the cmd buffer before returning.
4746 *=======================================================================*/
4747 static void dgap_cmdb(struct channel_t *ch, u8 cmd, u8 byte1,
4748 u8 byte2, uint ncmds)
4750 char __iomem *vaddr;
4751 struct __iomem cm_t *cm_addr;
4757 if (!ch || ch->magic != DGAP_CHANNEL_MAGIC)
4761 * Check if board is still alive.
4763 if (ch->ch_bd->state == BOARD_FAILED)
4767 * Make sure the pointers are in range before
4768 * writing to the FEP memory.
4770 vaddr = ch->ch_bd->re_map_membase;
4775 cm_addr = (struct cm_t __iomem *) (vaddr + CMDBUF);
4776 head = readw(&(cm_addr->cm_head));
4779 * Forget it if pointers out of range.
4781 if (head >= (CMDMAX - CMDSTART) || (head & 03)) {
4782 ch->ch_bd->state = BOARD_FAILED;
4787 * Put the data in the circular command buffer.
4789 writeb(cmd, (vaddr + head + CMDSTART + 0));
4790 writeb((u8) ch->ch_portnum, (vaddr + head + CMDSTART + 1));
4791 writeb(byte1, (vaddr + head + CMDSTART + 2));
4792 writeb(byte2, (vaddr + head + CMDSTART + 3));
4794 head = (head + 4) & (CMDMAX - CMDSTART - 4);
4796 writew(head, &(cm_addr->cm_head));
4799 * Wait if necessary before updating the head
4800 * pointer to limit the number of outstanding
4801 * commands to the FEP. If the time spent waiting
4802 * is outlandish, declare the FEP dead.
4804 for (count = dgap_count ;;) {
4806 head = readw(&(cm_addr->cm_head));
4807 tail = readw(&(cm_addr->cm_tail));
4809 n = (head - tail) & (CMDMAX - CMDSTART - 4);
4811 if (n <= ncmds * sizeof(struct cm_t))
4815 ch->ch_bd->state = BOARD_FAILED;
4822 /*=======================================================================
4824 * dgap_cmdw - Sends a 1 word command to the FEP.
4826 * ch - Pointer to channel structure.
4827 * cmd - Command to be sent.
4828 * word - Integer containing word to be sent.
4829 * ncmds - Wait until ncmds or fewer cmds are left
4830 * in the cmd buffer before returning.
4832 *=======================================================================*/
4833 static void dgap_cmdw(struct channel_t *ch, u8 cmd, u16 word, uint ncmds)
4835 char __iomem *vaddr;
4836 struct __iomem cm_t *cm_addr;
4842 if (!ch || ch->magic != DGAP_CHANNEL_MAGIC)
4846 * Check if board is still alive.
4848 if (ch->ch_bd->state == BOARD_FAILED)
4852 * Make sure the pointers are in range before
4853 * writing to the FEP memory.
4855 vaddr = ch->ch_bd->re_map_membase;
4859 cm_addr = (struct cm_t __iomem *) (vaddr + CMDBUF);
4860 head = readw(&(cm_addr->cm_head));
4863 * Forget it if pointers out of range.
4865 if (head >= (CMDMAX - CMDSTART) || (head & 03)) {
4866 ch->ch_bd->state = BOARD_FAILED;
4871 * Put the data in the circular command buffer.
4873 writeb(cmd, (vaddr + head + CMDSTART + 0));
4874 writeb((u8) ch->ch_portnum, (vaddr + head + CMDSTART + 1));
4875 writew((u16) word, (vaddr + head + CMDSTART + 2));
4877 head = (head + 4) & (CMDMAX - CMDSTART - 4);
4879 writew(head, &(cm_addr->cm_head));
4882 * Wait if necessary before updating the head
4883 * pointer to limit the number of outstanding
4884 * commands to the FEP. If the time spent waiting
4885 * is outlandish, declare the FEP dead.
4887 for (count = dgap_count ;;) {
4889 head = readw(&(cm_addr->cm_head));
4890 tail = readw(&(cm_addr->cm_tail));
4892 n = (head - tail) & (CMDMAX - CMDSTART - 4);
4894 if (n <= ncmds * sizeof(struct cm_t))
4898 ch->ch_bd->state = BOARD_FAILED;
4905 /*=======================================================================
4907 * dgap_cmdw_ext - Sends a extended word command to the FEP.
4909 * ch - Pointer to channel structure.
4910 * cmd - Command to be sent.
4911 * word - Integer containing word to be sent.
4912 * ncmds - Wait until ncmds or fewer cmds are left
4913 * in the cmd buffer before returning.
4915 *=======================================================================*/
4916 static void dgap_cmdw_ext(struct channel_t *ch, u16 cmd, u16 word, uint ncmds)
4918 char __iomem *vaddr;
4919 struct __iomem cm_t *cm_addr;
4925 if (!ch || ch->magic != DGAP_CHANNEL_MAGIC)
4929 * Check if board is still alive.
4931 if (ch->ch_bd->state == BOARD_FAILED)
4935 * Make sure the pointers are in range before
4936 * writing to the FEP memory.
4938 vaddr = ch->ch_bd->re_map_membase;
4942 cm_addr = (struct cm_t __iomem *) (vaddr + CMDBUF);
4943 head = readw(&(cm_addr->cm_head));
4946 * Forget it if pointers out of range.
4948 if (head >= (CMDMAX - CMDSTART) || (head & 03)) {
4949 ch->ch_bd->state = BOARD_FAILED;
4954 * Put the data in the circular command buffer.
4957 /* Write an FF to tell the FEP that we want an extended command */
4958 writeb((u8) 0xff, (vaddr + head + CMDSTART + 0));
4960 writeb((u8) ch->ch_portnum, (vaddr + head + CMDSTART + 1));
4961 writew((u16) cmd, (vaddr + head + CMDSTART + 2));
4964 * If the second part of the command won't fit,
4965 * put it at the beginning of the circular buffer.
4967 if (((head + 4) >= ((CMDMAX - CMDSTART)) || (head & 03)))
4968 writew((u16) word, (vaddr + CMDSTART));
4970 writew((u16) word, (vaddr + head + CMDSTART + 4));
4972 head = (head + 8) & (CMDMAX - CMDSTART - 4);
4974 writew(head, &(cm_addr->cm_head));
4977 * Wait if necessary before updating the head
4978 * pointer to limit the number of outstanding
4979 * commands to the FEP. If the time spent waiting
4980 * is outlandish, declare the FEP dead.
4982 for (count = dgap_count ;;) {
4984 head = readw(&(cm_addr->cm_head));
4985 tail = readw(&(cm_addr->cm_tail));
4987 n = (head - tail) & (CMDMAX - CMDSTART - 4);
4989 if (n <= ncmds * sizeof(struct cm_t))
4993 ch->ch_bd->state = BOARD_FAILED;
5000 /*=======================================================================
5002 * dgap_wmove - Write data to FEP buffer.
5004 * ch - Pointer to channel structure.
5005 * buf - Poiter to characters to be moved.
5006 * cnt - Number of characters to move.
5008 *=======================================================================*/
5009 static void dgap_wmove(struct channel_t *ch, char *buf, uint cnt)
5012 char __iomem *taddr;
5013 struct bs_t __iomem *bs;
5016 if (!ch || ch->magic != DGAP_CHANNEL_MAGIC)
5023 head = readw(&(bs->tx_head));
5026 * If pointers are out of range, just return.
5028 if ((cnt > ch->ch_tsize) ||
5029 (unsigned)(head - ch->ch_tstart) >= ch->ch_tsize)
5033 * If the write wraps over the top of the circular buffer,
5034 * move the portion up to the wrap point, and reset the
5035 * pointers to the bottom.
5037 n = ch->ch_tstart + ch->ch_tsize - head;
5041 taddr = ch->ch_taddr + head;
5042 memcpy_toio(taddr, buf, n);
5043 head = ch->ch_tstart;
5048 * Move rest of data.
5050 taddr = ch->ch_taddr + head;
5052 memcpy_toio(taddr, buf, n);
5055 writew(head, &(bs->tx_head));
5059 * Retrives the current custom baud rate from FEP memory,
5060 * and returns it back to the user.
5061 * Returns 0 on error.
5063 static uint dgap_get_custom_baud(struct channel_t *ch)
5069 if (!ch || ch->magic != DGAP_CHANNEL_MAGIC)
5072 if (!ch->ch_bd || ch->ch_bd->magic != DGAP_BOARD_MAGIC)
5075 if (!(ch->ch_bd->bd_flags & BD_FEP5PLUS))
5078 vaddr = ch->ch_bd->re_map_membase;
5084 * Go get from fep mem, what the fep
5085 * believes the custom baud rate is.
5087 offset = ((((*(unsigned short __iomem *)(vaddr + ECS_SEG)) << 4) +
5088 (ch->ch_portnum * 0x28) + LINE_SPEED));
5090 value = readw(vaddr + offset);
5095 * Calls the firmware to reset this channel.
5097 static void dgap_firmware_reset_port(struct channel_t *ch)
5099 dgap_cmdb(ch, CHRESET, 0, 0, 0);
5102 * Now that the channel is reset, we need to make sure
5103 * all the current settings get reapplied to the port
5106 * So we will set the driver's cache of firmware
5107 * settings all to 0, and then call param.
5109 ch->ch_fepiflag = 0;
5110 ch->ch_fepcflag = 0;
5111 ch->ch_fepoflag = 0;
5112 ch->ch_fepstartc = 0;
5113 ch->ch_fepstopc = 0;
5114 ch->ch_fepastartc = 0;
5115 ch->ch_fepastopc = 0;
5120 /*=======================================================================
5122 * dgap_param - Set Digi parameters.
5124 * struct tty_struct * - TTY for port.
5126 *=======================================================================*/
5127 static int dgap_param(struct tty_struct *tty)
5129 struct ktermios *ts;
5131 struct channel_t *ch;
5132 struct bs_t __iomem *bs;
5140 if (!tty || tty->magic != TTY_MAGIC)
5143 un = (struct un_t *) tty->driver_data;
5144 if (!un || un->magic != DGAP_UNIT_MAGIC)
5148 if (!ch || ch->magic != DGAP_CHANNEL_MAGIC)
5152 if (!bd || bd->magic != DGAP_BOARD_MAGIC)
5162 * If baud rate is zero, flush queues, and set mval to drop DTR.
5164 if ((ch->ch_c_cflag & (CBAUD)) == 0) {
5167 head = readw(&(ch->ch_bs->rx_head));
5168 writew(head, &(ch->ch_bs->rx_tail));
5171 head = readw(&(ch->ch_bs->tx_head));
5172 writew(head, &(ch->ch_bs->tx_tail));
5174 ch->ch_flags |= (CH_BAUD0);
5176 /* Drop RTS and DTR */
5177 ch->ch_mval &= ~(D_RTS(ch)|D_DTR(ch));
5178 mval = D_DTR(ch) | D_RTS(ch);
5179 ch->ch_baud_info = 0;
5181 } else if (ch->ch_custom_speed && (bd->bd_flags & BD_FEP5PLUS)) {
5183 * Tell the fep to do the command
5186 dgap_cmdw_ext(ch, 0xff01, ch->ch_custom_speed, 0);
5189 * Now go get from fep mem, what the fep
5190 * believes the custom baud rate is.
5192 ch->ch_custom_speed = dgap_get_custom_baud(ch);
5193 ch->ch_baud_info = ch->ch_custom_speed;
5195 /* Handle transition from B0 */
5196 if (ch->ch_flags & CH_BAUD0) {
5197 ch->ch_flags &= ~(CH_BAUD0);
5198 ch->ch_mval |= (D_RTS(ch)|D_DTR(ch));
5200 mval = D_DTR(ch) | D_RTS(ch);
5204 * Set baud rate, character size, and parity.
5212 ulong bauds[4][16] = {
5216 600, 1200, 1800, 2400,
5217 4800, 9600, 19200, 38400 },
5218 { /* slowbaud & CBAUDEX */
5219 0, 57600, 115200, 230400,
5220 460800, 150, 200, 921600,
5221 600, 1200, 1800, 2400,
5222 4800, 9600, 19200, 38400 },
5224 0, 57600, 76800, 115200,
5225 14400, 57600, 230400, 76800,
5226 115200, 230400, 28800, 460800,
5227 921600, 9600, 19200, 38400 },
5228 { /* fastbaud & CBAUDEX */
5229 0, 57600, 115200, 230400,
5230 460800, 150, 200, 921600,
5231 600, 1200, 1800, 2400,
5232 4800, 9600, 19200, 38400 }
5236 * Only use the TXPrint baud rate if the
5237 * terminal unit is NOT open
5239 if (!(ch->ch_tun.un_flags & UN_ISOPEN) &&
5240 (un->un_type == DGAP_PRINT))
5241 baud = C_BAUD(ch->ch_pun.un_tty) & 0xff;
5243 baud = C_BAUD(ch->ch_tun.un_tty) & 0xff;
5245 if (ch->ch_c_cflag & CBAUDEX)
5248 if (ch->ch_digi.digi_flags & DIGI_FAST)
5253 if ((iindex >= 0) && (iindex < 4) &&
5254 (jindex >= 0) && (jindex < 16))
5255 baud = bauds[iindex][jindex];
5262 ch->ch_baud_info = baud;
5265 * CBAUD has bit position 0x1000 set these days to
5266 * indicate Linux baud rate remap.
5267 * We use a different bit assignment for high speed.
5268 * Clear this bit out while grabbing the parts of
5271 cflag = ch->ch_c_cflag & ((CBAUD ^ CBAUDEX) | PARODD | PARENB |
5275 * HUPCL bit is used by FEP to indicate fast baud
5276 * table is to be used.
5278 if ((ch->ch_digi.digi_flags & DIGI_FAST) ||
5279 (ch->ch_c_cflag & CBAUDEX))
5282 if ((ch->ch_c_cflag & CBAUDEX) &&
5283 !(ch->ch_digi.digi_flags & DIGI_FAST)) {
5285 * The below code is trying to guarantee that only
5286 * baud rates 115200, 230400, 460800, 921600 are
5287 * remapped. We use exclusive or because the various
5288 * baud rates share common bit positions and therefore
5289 * can't be tested for easily.
5291 tcflag_t tcflag = (ch->ch_c_cflag & CBAUD) | CBAUDEX;
5295 * Map high speed requests to index
5296 * into FEP's baud table
5326 cflag = (cflag & ~(CBAUD | CBAUDEX)) | baudpart;
5331 if (cflag != ch->ch_fepcflag) {
5332 ch->ch_fepcflag = (u16) (cflag & 0xffff);
5335 * Okay to have channel and board
5336 * locks held calling this
5338 dgap_cmdw(ch, SCFLAG, (u16) cflag, 0);
5341 /* Handle transition from B0 */
5342 if (ch->ch_flags & CH_BAUD0) {
5343 ch->ch_flags &= ~(CH_BAUD0);
5344 ch->ch_mval |= (D_RTS(ch)|D_DTR(ch));
5346 mval = D_DTR(ch) | D_RTS(ch);
5352 iflag = ch->ch_c_iflag & (IGNBRK | BRKINT | IGNPAR | PARMRK |
5353 INPCK | ISTRIP | IXON | IXANY | IXOFF);
5355 if ((ch->ch_startc == _POSIX_VDISABLE) ||
5356 (ch->ch_stopc == _POSIX_VDISABLE)) {
5357 iflag &= ~(IXON | IXOFF);
5358 ch->ch_c_iflag &= ~(IXON | IXOFF);
5362 * Only the IBM Xr card can switch between
5363 * 232 and 422 modes on the fly
5365 if (bd->device == PCI_DEV_XR_IBM_DID) {
5366 if (ch->ch_digi.digi_flags & DIGI_422)
5367 dgap_cmdb(ch, SCOMMODE, MODE_422, 0, 0);
5369 dgap_cmdb(ch, SCOMMODE, MODE_232, 0, 0);
5372 if (ch->ch_digi.digi_flags & DIGI_ALTPIN)
5375 if (iflag != ch->ch_fepiflag) {
5376 ch->ch_fepiflag = iflag;
5378 /* Okay to have channel and board locks held calling this */
5379 dgap_cmdw(ch, SIFLAG, (u16) ch->ch_fepiflag, 0);
5383 * Select hardware handshaking.
5387 if (ch->ch_c_cflag & CRTSCTS)
5388 hflow |= (D_RTS(ch) | D_CTS(ch));
5389 if (ch->ch_digi.digi_flags & RTSPACE)
5391 if (ch->ch_digi.digi_flags & DTRPACE)
5393 if (ch->ch_digi.digi_flags & CTSPACE)
5395 if (ch->ch_digi.digi_flags & DSRPACE)
5397 if (ch->ch_digi.digi_flags & DCDPACE)
5400 if (hflow != ch->ch_hflow) {
5401 ch->ch_hflow = hflow;
5403 /* Okay to have channel and board locks held calling this */
5404 dgap_cmdb(ch, SHFLOW, (u8) hflow, 0xff, 0);
5409 * Set RTS and/or DTR Toggle if needed,
5410 * but only if product is FEP5+ based.
5412 if (bd->bd_flags & BD_FEP5PLUS) {
5414 if (ch->ch_digi.digi_flags & DIGI_RTS_TOGGLE)
5415 hflow2 |= (D_RTS(ch));
5416 if (ch->ch_digi.digi_flags & DIGI_DTR_TOGGLE)
5417 hflow2 |= (D_DTR(ch));
5419 dgap_cmdw_ext(ch, 0xff03, hflow2, 0);
5423 * Set modem control lines.
5426 mval ^= ch->ch_mforce & (mval ^ ch->ch_mval);
5428 if (ch->ch_mostat ^ mval) {
5429 ch->ch_mostat = mval;
5431 /* Okay to have channel and board locks held calling this */
5432 dgap_cmdb(ch, SMODEM, (u8) mval, D_RTS(ch)|D_DTR(ch), 0);
5436 * Read modem signals, and then call carrier function.
5438 ch->ch_mistat = readb(&(bs->m_stat));
5442 * Set the start and stop characters.
5444 if (ch->ch_startc != ch->ch_fepstartc ||
5445 ch->ch_stopc != ch->ch_fepstopc) {
5446 ch->ch_fepstartc = ch->ch_startc;
5447 ch->ch_fepstopc = ch->ch_stopc;
5449 /* Okay to have channel and board locks held calling this */
5450 dgap_cmdb(ch, SFLOWC, ch->ch_fepstartc, ch->ch_fepstopc, 0);
5454 * Set the Auxiliary start and stop characters.
5456 if (ch->ch_astartc != ch->ch_fepastartc ||
5457 ch->ch_astopc != ch->ch_fepastopc) {
5458 ch->ch_fepastartc = ch->ch_astartc;
5459 ch->ch_fepastopc = ch->ch_astopc;
5461 /* Okay to have channel and board locks held calling this */
5462 dgap_cmdb(ch, SAFLOWC, ch->ch_fepastartc, ch->ch_fepastopc, 0);
5469 * dgap_parity_scan()
5471 * Convert the FEP5 way of reporting parity errors and breaks into
5472 * the Linux line discipline way.
5474 static void dgap_parity_scan(struct channel_t *ch, unsigned char *cbuf,
5475 unsigned char *fbuf, int *len)
5479 unsigned char *in, *cout, *fout;
5486 if (!ch || ch->magic != DGAP_CHANNEL_MAGIC)
5491 switch (ch->pscan_state) {
5493 /* reset to sanity and fall through */
5494 ch->pscan_state = 0;
5497 /* No FF seen yet */
5498 if (c == (unsigned char) '\377')
5499 /* delete this character from stream */
5500 ch->pscan_state = 1;
5503 *fout++ = TTY_NORMAL;
5510 if (c == (unsigned char) '\377') {
5511 /* doubled ff, transform to single ff */
5513 *fout++ = TTY_NORMAL;
5515 ch->pscan_state = 0;
5517 /* save value examination in next state */
5518 ch->pscan_savechar = c;
5519 ch->pscan_state = 2;
5524 /* third character of ff sequence */
5528 if (ch->pscan_savechar == 0x0) {
5532 *fout++ = TTY_BREAK;
5534 ch->ch_err_parity++;
5535 *fout++ = TTY_PARITY;
5540 ch->pscan_state = 0;
5546 static void dgap_write_wakeup(struct board_t *bd, struct channel_t *ch,
5547 struct un_t *un, u32 mask,
5548 unsigned long *irq_flags1,
5549 unsigned long *irq_flags2)
5551 if (!(un->un_flags & mask))
5554 un->un_flags &= ~mask;
5556 if (!(un->un_flags & UN_ISOPEN))
5559 if ((un->un_tty->flags & (1 << TTY_DO_WRITE_WAKEUP)) &&
5560 un->un_tty->ldisc->ops->write_wakeup) {
5561 spin_unlock_irqrestore(&ch->ch_lock, *irq_flags2);
5562 spin_unlock_irqrestore(&bd->bd_lock, *irq_flags1);
5564 (un->un_tty->ldisc->ops->write_wakeup)(un->un_tty);
5566 spin_lock_irqsave(&bd->bd_lock, *irq_flags1);
5567 spin_lock_irqsave(&ch->ch_lock, *irq_flags2);
5569 wake_up_interruptible(&un->un_tty->write_wait);
5570 wake_up_interruptible(&un->un_flags_wait);
5573 /*=======================================================================
5575 * dgap_event - FEP to host event processing routine.
5577 * bd - Board of current event.
5579 *=======================================================================*/
5580 static int dgap_event(struct board_t *bd)
5582 struct channel_t *ch;
5585 struct bs_t __iomem *bs;
5588 struct ev_t __iomem *eaddr;
5596 if (!bd || bd->magic != DGAP_BOARD_MAGIC)
5599 spin_lock_irqsave(&bd->bd_lock, lock_flags);
5601 vaddr = bd->re_map_membase;
5604 spin_unlock_irqrestore(&bd->bd_lock, lock_flags);
5608 eaddr = (struct ev_t __iomem *) (vaddr + EVBUF);
5610 /* Get our head and tail */
5611 head = readw(&(eaddr->ev_head));
5612 tail = readw(&(eaddr->ev_tail));
5615 * Forget it if pointers out of range.
5618 if (head >= EVMAX - EVSTART || tail >= EVMAX - EVSTART ||
5619 (head | tail) & 03) {
5620 /* Let go of board lock */
5621 spin_unlock_irqrestore(&bd->bd_lock, lock_flags);
5626 * Loop to process all the events in the buffer.
5628 while (tail != head) {
5631 * Get interrupt information.
5634 event = bd->re_map_membase + tail + EVSTART;
5642 * Make sure the interrupt is valid.
5644 if (port >= bd->nasync)
5647 if (!(reason & (IFMODEM | IFBREAK | IFTLW | IFTEM | IFDATA)))
5650 ch = bd->channels[port];
5652 if (!ch || ch->magic != DGAP_CHANNEL_MAGIC)
5656 * If we have made it here, the event was valid.
5657 * Lock down the channel.
5659 spin_lock_irqsave(&ch->ch_lock, lock_flags2);
5664 spin_unlock_irqrestore(&ch->ch_lock, lock_flags2);
5669 * Process received data.
5671 if (reason & IFDATA) {
5674 * ALL LOCKS *MUST* BE DROPPED BEFORE CALLING INPUT!
5675 * input could send some data to ld, which in turn
5676 * could do a callback to one of our other functions.
5678 spin_unlock_irqrestore(&ch->ch_lock, lock_flags2);
5679 spin_unlock_irqrestore(&bd->bd_lock, lock_flags);
5683 spin_lock_irqsave(&bd->bd_lock, lock_flags);
5684 spin_lock_irqsave(&ch->ch_lock, lock_flags2);
5686 if (ch->ch_flags & CH_RACTIVE)
5687 ch->ch_flags |= CH_RENABLE;
5689 writeb(1, &(bs->idata));
5691 if (ch->ch_flags & CH_RWAIT) {
5692 ch->ch_flags &= ~CH_RWAIT;
5694 wake_up_interruptible
5695 (&ch->ch_tun.un_flags_wait);
5700 * Process Modem change signals.
5702 if (reason & IFMODEM) {
5703 ch->ch_mistat = modem;
5710 if (reason & IFBREAK) {
5712 if (ch->ch_tun.un_tty) {
5713 /* A break has been indicated */
5715 tty_buffer_request_room
5716 (ch->ch_tun.un_tty->port, 1);
5717 tty_insert_flip_char(ch->ch_tun.un_tty->port,
5719 tty_flip_buffer_push(ch->ch_tun.un_tty->port);
5724 * Process Transmit low.
5726 if (reason & IFTLW) {
5727 dgap_write_wakeup(bd, ch, &ch->ch_tun, UN_LOW,
5728 &lock_flags, &lock_flags2);
5729 dgap_write_wakeup(bd, ch, &ch->ch_pun, UN_LOW,
5730 &lock_flags, &lock_flags2);
5731 if (ch->ch_flags & CH_WLOW) {
5732 ch->ch_flags &= ~CH_WLOW;
5733 wake_up_interruptible(&ch->ch_flags_wait);
5738 * Process Transmit empty.
5740 if (reason & IFTEM) {
5741 dgap_write_wakeup(bd, ch, &ch->ch_tun, UN_EMPTY,
5742 &lock_flags, &lock_flags2);
5743 dgap_write_wakeup(bd, ch, &ch->ch_pun, UN_EMPTY,
5744 &lock_flags, &lock_flags2);
5745 if (ch->ch_flags & CH_WEMPTY) {
5746 ch->ch_flags &= ~CH_WEMPTY;
5747 wake_up_interruptible(&ch->ch_flags_wait);
5751 spin_unlock_irqrestore(&ch->ch_lock, lock_flags2);
5754 tail = (tail + 4) & (EVMAX - EVSTART - 4);
5757 writew(tail, &(eaddr->ev_tail));
5758 spin_unlock_irqrestore(&bd->bd_lock, lock_flags);
5763 static ssize_t dgap_driver_version_show(struct device_driver *ddp, char *buf)
5765 return snprintf(buf, PAGE_SIZE, "%s\n", DG_PART);
5767 static DRIVER_ATTR(version, S_IRUSR, dgap_driver_version_show, NULL);
5770 static ssize_t dgap_driver_boards_show(struct device_driver *ddp, char *buf)
5772 return snprintf(buf, PAGE_SIZE, "%d\n", dgap_numboards);
5774 static DRIVER_ATTR(boards, S_IRUSR, dgap_driver_boards_show, NULL);
5777 static ssize_t dgap_driver_maxboards_show(struct device_driver *ddp, char *buf)
5779 return snprintf(buf, PAGE_SIZE, "%d\n", MAXBOARDS);
5781 static DRIVER_ATTR(maxboards, S_IRUSR, dgap_driver_maxboards_show, NULL);
5784 static ssize_t dgap_driver_pollcounter_show(struct device_driver *ddp,
5787 return snprintf(buf, PAGE_SIZE, "%ld\n", dgap_poll_counter);
5789 static DRIVER_ATTR(pollcounter, S_IRUSR, dgap_driver_pollcounter_show, NULL);
5791 static ssize_t dgap_driver_pollrate_show(struct device_driver *ddp, char *buf)
5793 return snprintf(buf, PAGE_SIZE, "%dms\n", dgap_poll_tick);
5796 static ssize_t dgap_driver_pollrate_store(struct device_driver *ddp,
5797 const char *buf, size_t count)
5799 if (sscanf(buf, "%d\n", &dgap_poll_tick) != 1)
5803 static DRIVER_ATTR(pollrate, (S_IRUSR | S_IWUSR), dgap_driver_pollrate_show,
5804 dgap_driver_pollrate_store);
5806 static int dgap_create_driver_sysfiles(struct pci_driver *dgap_driver)
5809 struct device_driver *driverfs = &dgap_driver->driver;
5811 rc |= driver_create_file(driverfs, &driver_attr_version);
5812 rc |= driver_create_file(driverfs, &driver_attr_boards);
5813 rc |= driver_create_file(driverfs, &driver_attr_maxboards);
5814 rc |= driver_create_file(driverfs, &driver_attr_pollrate);
5815 rc |= driver_create_file(driverfs, &driver_attr_pollcounter);
5820 static void dgap_remove_driver_sysfiles(struct pci_driver *dgap_driver)
5822 struct device_driver *driverfs = &dgap_driver->driver;
5823 driver_remove_file(driverfs, &driver_attr_version);
5824 driver_remove_file(driverfs, &driver_attr_boards);
5825 driver_remove_file(driverfs, &driver_attr_maxboards);
5826 driver_remove_file(driverfs, &driver_attr_pollrate);
5827 driver_remove_file(driverfs, &driver_attr_pollcounter);
5830 static struct board_t *dgap_verify_board(struct device *p)
5837 bd = dev_get_drvdata(p);
5838 if (!bd || bd->magic != DGAP_BOARD_MAGIC || bd->state != BOARD_READY)
5844 static ssize_t dgap_ports_state_show(struct device *p,
5845 struct device_attribute *attr,
5852 bd = dgap_verify_board(p);
5856 for (i = 0; i < bd->nasync; i++) {
5857 count += snprintf(buf + count, PAGE_SIZE - count,
5858 "%d %s\n", bd->channels[i]->ch_portnum,
5859 bd->channels[i]->ch_open_count ? "Open" : "Closed");
5863 static DEVICE_ATTR(ports_state, S_IRUSR, dgap_ports_state_show, NULL);
5865 static ssize_t dgap_ports_baud_show(struct device *p,
5866 struct device_attribute *attr,
5873 bd = dgap_verify_board(p);
5877 for (i = 0; i < bd->nasync; i++) {
5878 count += snprintf(buf + count, PAGE_SIZE - count, "%d %d\n",
5879 bd->channels[i]->ch_portnum,
5880 bd->channels[i]->ch_baud_info);
5884 static DEVICE_ATTR(ports_baud, S_IRUSR, dgap_ports_baud_show, NULL);
5886 static ssize_t dgap_ports_msignals_show(struct device *p,
5887 struct device_attribute *attr,
5894 bd = dgap_verify_board(p);
5898 for (i = 0; i < bd->nasync; i++) {
5899 if (bd->channels[i]->ch_open_count)
5900 count += snprintf(buf + count, PAGE_SIZE - count,
5901 "%d %s %s %s %s %s %s\n",
5902 bd->channels[i]->ch_portnum,
5903 (bd->channels[i]->ch_mostat &
5904 UART_MCR_RTS) ? "RTS" : "",
5905 (bd->channels[i]->ch_mistat &
5906 UART_MSR_CTS) ? "CTS" : "",
5907 (bd->channels[i]->ch_mostat &
5908 UART_MCR_DTR) ? "DTR" : "",
5909 (bd->channels[i]->ch_mistat &
5910 UART_MSR_DSR) ? "DSR" : "",
5911 (bd->channels[i]->ch_mistat &
5912 UART_MSR_DCD) ? "DCD" : "",
5913 (bd->channels[i]->ch_mistat &
5914 UART_MSR_RI) ? "RI" : "");
5916 count += snprintf(buf + count, PAGE_SIZE - count,
5917 "%d\n", bd->channels[i]->ch_portnum);
5921 static DEVICE_ATTR(ports_msignals, S_IRUSR, dgap_ports_msignals_show, NULL);
5923 static ssize_t dgap_ports_iflag_show(struct device *p,
5924 struct device_attribute *attr,
5931 bd = dgap_verify_board(p);
5935 for (i = 0; i < bd->nasync; i++)
5936 count += snprintf(buf + count, PAGE_SIZE - count, "%d %x\n",
5937 bd->channels[i]->ch_portnum,
5938 bd->channels[i]->ch_c_iflag);
5941 static DEVICE_ATTR(ports_iflag, S_IRUSR, dgap_ports_iflag_show, NULL);
5943 static ssize_t dgap_ports_cflag_show(struct device *p,
5944 struct device_attribute *attr,
5951 bd = dgap_verify_board(p);
5955 for (i = 0; i < bd->nasync; i++)
5956 count += snprintf(buf + count, PAGE_SIZE - count, "%d %x\n",
5957 bd->channels[i]->ch_portnum,
5958 bd->channels[i]->ch_c_cflag);
5961 static DEVICE_ATTR(ports_cflag, S_IRUSR, dgap_ports_cflag_show, NULL);
5963 static ssize_t dgap_ports_oflag_show(struct device *p,
5964 struct device_attribute *attr,
5971 bd = dgap_verify_board(p);
5975 for (i = 0; i < bd->nasync; i++)
5976 count += snprintf(buf + count, PAGE_SIZE - count, "%d %x\n",
5977 bd->channels[i]->ch_portnum,
5978 bd->channels[i]->ch_c_oflag);
5981 static DEVICE_ATTR(ports_oflag, S_IRUSR, dgap_ports_oflag_show, NULL);
5983 static ssize_t dgap_ports_lflag_show(struct device *p,
5984 struct device_attribute *attr,
5991 bd = dgap_verify_board(p);
5995 for (i = 0; i < bd->nasync; i++)
5996 count += snprintf(buf + count, PAGE_SIZE - count, "%d %x\n",
5997 bd->channels[i]->ch_portnum,
5998 bd->channels[i]->ch_c_lflag);
6001 static DEVICE_ATTR(ports_lflag, S_IRUSR, dgap_ports_lflag_show, NULL);
6003 static ssize_t dgap_ports_digi_flag_show(struct device *p,
6004 struct device_attribute *attr,
6011 bd = dgap_verify_board(p);
6015 for (i = 0; i < bd->nasync; i++)
6016 count += snprintf(buf + count, PAGE_SIZE - count, "%d %x\n",
6017 bd->channels[i]->ch_portnum,
6018 bd->channels[i]->ch_digi.digi_flags);
6021 static DEVICE_ATTR(ports_digi_flag, S_IRUSR, dgap_ports_digi_flag_show, NULL);
6023 static ssize_t dgap_ports_rxcount_show(struct device *p,
6024 struct device_attribute *attr,
6031 bd = dgap_verify_board(p);
6035 for (i = 0; i < bd->nasync; i++)
6036 count += snprintf(buf + count, PAGE_SIZE - count, "%d %ld\n",
6037 bd->channels[i]->ch_portnum,
6038 bd->channels[i]->ch_rxcount);
6041 static DEVICE_ATTR(ports_rxcount, S_IRUSR, dgap_ports_rxcount_show, NULL);
6043 static ssize_t dgap_ports_txcount_show(struct device *p,
6044 struct device_attribute *attr,
6051 bd = dgap_verify_board(p);
6055 for (i = 0; i < bd->nasync; i++)
6056 count += snprintf(buf + count, PAGE_SIZE - count, "%d %ld\n",
6057 bd->channels[i]->ch_portnum,
6058 bd->channels[i]->ch_txcount);
6061 static DEVICE_ATTR(ports_txcount, S_IRUSR, dgap_ports_txcount_show, NULL);
6063 /* this function creates the sys files that will export each signal status
6064 * to sysfs each value will be put in a separate filename
6066 static void dgap_create_ports_sysfiles(struct board_t *bd)
6068 dev_set_drvdata(&bd->pdev->dev, bd);
6069 device_create_file(&(bd->pdev->dev), &dev_attr_ports_state);
6070 device_create_file(&(bd->pdev->dev), &dev_attr_ports_baud);
6071 device_create_file(&(bd->pdev->dev), &dev_attr_ports_msignals);
6072 device_create_file(&(bd->pdev->dev), &dev_attr_ports_iflag);
6073 device_create_file(&(bd->pdev->dev), &dev_attr_ports_cflag);
6074 device_create_file(&(bd->pdev->dev), &dev_attr_ports_oflag);
6075 device_create_file(&(bd->pdev->dev), &dev_attr_ports_lflag);
6076 device_create_file(&(bd->pdev->dev), &dev_attr_ports_digi_flag);
6077 device_create_file(&(bd->pdev->dev), &dev_attr_ports_rxcount);
6078 device_create_file(&(bd->pdev->dev), &dev_attr_ports_txcount);
6081 /* removes all the sys files created for that port */
6082 static void dgap_remove_ports_sysfiles(struct board_t *bd)
6084 device_remove_file(&(bd->pdev->dev), &dev_attr_ports_state);
6085 device_remove_file(&(bd->pdev->dev), &dev_attr_ports_baud);
6086 device_remove_file(&(bd->pdev->dev), &dev_attr_ports_msignals);
6087 device_remove_file(&(bd->pdev->dev), &dev_attr_ports_iflag);
6088 device_remove_file(&(bd->pdev->dev), &dev_attr_ports_cflag);
6089 device_remove_file(&(bd->pdev->dev), &dev_attr_ports_oflag);
6090 device_remove_file(&(bd->pdev->dev), &dev_attr_ports_lflag);
6091 device_remove_file(&(bd->pdev->dev), &dev_attr_ports_digi_flag);
6092 device_remove_file(&(bd->pdev->dev), &dev_attr_ports_rxcount);
6093 device_remove_file(&(bd->pdev->dev), &dev_attr_ports_txcount);
6096 static ssize_t dgap_tty_state_show(struct device *d,
6097 struct device_attribute *attr,
6101 struct channel_t *ch;
6106 un = dev_get_drvdata(d);
6107 if (!un || un->magic != DGAP_UNIT_MAGIC)
6110 if (!ch || ch->magic != DGAP_CHANNEL_MAGIC)
6113 if (!bd || bd->magic != DGAP_BOARD_MAGIC)
6115 if (bd->state != BOARD_READY)
6118 return snprintf(buf, PAGE_SIZE, "%s", un->un_open_count ?
6121 static DEVICE_ATTR(state, S_IRUSR, dgap_tty_state_show, NULL);
6123 static ssize_t dgap_tty_baud_show(struct device *d,
6124 struct device_attribute *attr,
6128 struct channel_t *ch;
6133 un = dev_get_drvdata(d);
6134 if (!un || un->magic != DGAP_UNIT_MAGIC)
6137 if (!ch || ch->magic != DGAP_CHANNEL_MAGIC)
6140 if (!bd || bd->magic != DGAP_BOARD_MAGIC)
6142 if (bd->state != BOARD_READY)
6145 return snprintf(buf, PAGE_SIZE, "%d\n", ch->ch_baud_info);
6147 static DEVICE_ATTR(baud, S_IRUSR, dgap_tty_baud_show, NULL);
6149 static ssize_t dgap_tty_msignals_show(struct device *d,
6150 struct device_attribute *attr,
6154 struct channel_t *ch;
6159 un = dev_get_drvdata(d);
6160 if (!un || un->magic != DGAP_UNIT_MAGIC)
6163 if (!ch || ch->magic != DGAP_CHANNEL_MAGIC)
6166 if (!bd || bd->magic != DGAP_BOARD_MAGIC)
6168 if (bd->state != BOARD_READY)
6171 if (ch->ch_open_count) {
6172 return snprintf(buf, PAGE_SIZE, "%s %s %s %s %s %s\n",
6173 (ch->ch_mostat & UART_MCR_RTS) ? "RTS" : "",
6174 (ch->ch_mistat & UART_MSR_CTS) ? "CTS" : "",
6175 (ch->ch_mostat & UART_MCR_DTR) ? "DTR" : "",
6176 (ch->ch_mistat & UART_MSR_DSR) ? "DSR" : "",
6177 (ch->ch_mistat & UART_MSR_DCD) ? "DCD" : "",
6178 (ch->ch_mistat & UART_MSR_RI) ? "RI" : "");
6182 static DEVICE_ATTR(msignals, S_IRUSR, dgap_tty_msignals_show, NULL);
6184 static ssize_t dgap_tty_iflag_show(struct device *d,
6185 struct device_attribute *attr,
6189 struct channel_t *ch;
6194 un = dev_get_drvdata(d);
6195 if (!un || un->magic != DGAP_UNIT_MAGIC)
6198 if (!ch || ch->magic != DGAP_CHANNEL_MAGIC)
6201 if (!bd || bd->magic != DGAP_BOARD_MAGIC)
6203 if (bd->state != BOARD_READY)
6206 return snprintf(buf, PAGE_SIZE, "%x\n", ch->ch_c_iflag);
6208 static DEVICE_ATTR(iflag, S_IRUSR, dgap_tty_iflag_show, NULL);
6210 static ssize_t dgap_tty_cflag_show(struct device *d,
6211 struct device_attribute *attr,
6215 struct channel_t *ch;
6220 un = dev_get_drvdata(d);
6221 if (!un || un->magic != DGAP_UNIT_MAGIC)
6224 if (!ch || ch->magic != DGAP_CHANNEL_MAGIC)
6227 if (!bd || bd->magic != DGAP_BOARD_MAGIC)
6229 if (bd->state != BOARD_READY)
6232 return snprintf(buf, PAGE_SIZE, "%x\n", ch->ch_c_cflag);
6234 static DEVICE_ATTR(cflag, S_IRUSR, dgap_tty_cflag_show, NULL);
6236 static ssize_t dgap_tty_oflag_show(struct device *d,
6237 struct device_attribute *attr,
6241 struct channel_t *ch;
6246 un = dev_get_drvdata(d);
6247 if (!un || un->magic != DGAP_UNIT_MAGIC)
6250 if (!ch || ch->magic != DGAP_CHANNEL_MAGIC)
6253 if (!bd || bd->magic != DGAP_BOARD_MAGIC)
6255 if (bd->state != BOARD_READY)
6258 return snprintf(buf, PAGE_SIZE, "%x\n", ch->ch_c_oflag);
6260 static DEVICE_ATTR(oflag, S_IRUSR, dgap_tty_oflag_show, NULL);
6262 static ssize_t dgap_tty_lflag_show(struct device *d,
6263 struct device_attribute *attr,
6267 struct channel_t *ch;
6272 un = dev_get_drvdata(d);
6273 if (!un || un->magic != DGAP_UNIT_MAGIC)
6276 if (!ch || ch->magic != DGAP_CHANNEL_MAGIC)
6279 if (!bd || bd->magic != DGAP_BOARD_MAGIC)
6281 if (bd->state != BOARD_READY)
6284 return snprintf(buf, PAGE_SIZE, "%x\n", ch->ch_c_lflag);
6286 static DEVICE_ATTR(lflag, S_IRUSR, dgap_tty_lflag_show, NULL);
6288 static ssize_t dgap_tty_digi_flag_show(struct device *d,
6289 struct device_attribute *attr,
6293 struct channel_t *ch;
6298 un = dev_get_drvdata(d);
6299 if (!un || un->magic != DGAP_UNIT_MAGIC)
6302 if (!ch || ch->magic != DGAP_CHANNEL_MAGIC)
6305 if (!bd || bd->magic != DGAP_BOARD_MAGIC)
6307 if (bd->state != BOARD_READY)
6310 return snprintf(buf, PAGE_SIZE, "%x\n", ch->ch_digi.digi_flags);
6312 static DEVICE_ATTR(digi_flag, S_IRUSR, dgap_tty_digi_flag_show, NULL);
6314 static ssize_t dgap_tty_rxcount_show(struct device *d,
6315 struct device_attribute *attr,
6319 struct channel_t *ch;
6324 un = dev_get_drvdata(d);
6325 if (!un || un->magic != DGAP_UNIT_MAGIC)
6328 if (!ch || ch->magic != DGAP_CHANNEL_MAGIC)
6331 if (!bd || bd->magic != DGAP_BOARD_MAGIC)
6333 if (bd->state != BOARD_READY)
6336 return snprintf(buf, PAGE_SIZE, "%ld\n", ch->ch_rxcount);
6338 static DEVICE_ATTR(rxcount, S_IRUSR, dgap_tty_rxcount_show, NULL);
6340 static ssize_t dgap_tty_txcount_show(struct device *d,
6341 struct device_attribute *attr,
6345 struct channel_t *ch;
6350 un = dev_get_drvdata(d);
6351 if (!un || un->magic != DGAP_UNIT_MAGIC)
6354 if (!ch || ch->magic != DGAP_CHANNEL_MAGIC)
6357 if (!bd || bd->magic != DGAP_BOARD_MAGIC)
6359 if (bd->state != BOARD_READY)
6362 return snprintf(buf, PAGE_SIZE, "%ld\n", ch->ch_txcount);
6364 static DEVICE_ATTR(txcount, S_IRUSR, dgap_tty_txcount_show, NULL);
6366 static ssize_t dgap_tty_name_show(struct device *d,
6367 struct device_attribute *attr,
6371 struct channel_t *ch;
6375 struct cnode *cptr = NULL;
6383 un = dev_get_drvdata(d);
6384 if (!un || un->magic != DGAP_UNIT_MAGIC)
6387 if (!ch || ch->magic != DGAP_CHANNEL_MAGIC)
6390 if (!bd || bd->magic != DGAP_BOARD_MAGIC)
6392 if (bd->state != BOARD_READY)
6396 cn = ch->ch_portnum;
6398 for (cptr = bd->bd_config; cptr; cptr = cptr->next) {
6400 if ((cptr->type == BNODE) &&
6401 ((cptr->u.board.type == APORT2_920P) ||
6402 (cptr->u.board.type == APORT4_920P) ||
6403 (cptr->u.board.type == APORT8_920P) ||
6404 (cptr->u.board.type == PAPORT4) ||
6405 (cptr->u.board.type == PAPORT8))) {
6408 if (cptr->u.board.v_start)
6409 starto = cptr->u.board.start;
6414 if (cptr->type == TNODE && found == TRUE) {
6416 if (strstr(cptr->u.ttyname, "tty")) {
6417 ptr1 = cptr->u.ttyname;
6420 ptr1 = cptr->u.ttyname;
6422 for (i = 0; i < dgap_config_get_num_prts(bd); i++) {
6426 return snprintf(buf, PAGE_SIZE, "%s%s%02d\n",
6427 (un->un_type == DGAP_PRINT) ?
6433 if (cptr->type == CNODE) {
6435 for (i = 0; i < cptr->u.conc.nport; i++) {
6436 if (cn != (i + ncount))
6439 return snprintf(buf, PAGE_SIZE, "%s%s%02ld\n",
6440 (un->un_type == DGAP_PRINT) ?
6443 i + (cptr->u.conc.v_start ?
6444 cptr->u.conc.start : 1));
6447 ncount += cptr->u.conc.nport;
6450 if (cptr->type == MNODE) {
6452 for (i = 0; i < cptr->u.module.nport; i++) {
6453 if (cn != (i + ncount))
6456 return snprintf(buf, PAGE_SIZE, "%s%s%02ld\n",
6457 (un->un_type == DGAP_PRINT) ?
6460 i + (cptr->u.module.v_start ?
6461 cptr->u.module.start : 1));
6464 ncount += cptr->u.module.nport;
6469 return snprintf(buf, PAGE_SIZE, "%s_dgap_%d_%d\n",
6470 (un->un_type == DGAP_PRINT) ? "pr" : "tty", bn, cn);
6473 static DEVICE_ATTR(custom_name, S_IRUSR, dgap_tty_name_show, NULL);
6475 static struct attribute *dgap_sysfs_tty_entries[] = {
6476 &dev_attr_state.attr,
6477 &dev_attr_baud.attr,
6478 &dev_attr_msignals.attr,
6479 &dev_attr_iflag.attr,
6480 &dev_attr_cflag.attr,
6481 &dev_attr_oflag.attr,
6482 &dev_attr_lflag.attr,
6483 &dev_attr_digi_flag.attr,
6484 &dev_attr_rxcount.attr,
6485 &dev_attr_txcount.attr,
6486 &dev_attr_custom_name.attr,
6490 static struct attribute_group dgap_tty_attribute_group = {
6492 .attrs = dgap_sysfs_tty_entries,
6495 static void dgap_create_tty_sysfs(struct un_t *un, struct device *c)
6499 ret = sysfs_create_group(&c->kobj, &dgap_tty_attribute_group);
6503 dev_set_drvdata(c, un);
6507 static void dgap_remove_tty_sysfs(struct device *c)
6509 sysfs_remove_group(&c->kobj, &dgap_tty_attribute_group);
6513 * Parse a configuration file read into memory as a string.
6515 static int dgap_parsefile(char **in, int remove)
6517 struct cnode *p, *brd, *line, *conc;
6523 brd = line = conc = NULL;
6525 /* perhaps we are adding to an existing list? */
6526 while (p->next != NULL)
6529 /* file must start with a BEGIN */
6530 while ((rc = dgap_gettok(in, p)) != BEGIN) {
6532 dgap_err("unexpected EOF");
6538 rc = dgap_gettok(in, p);
6540 dgap_err("unexpected EOF");
6546 dgap_err("unexpected end of file");
6549 case BEGIN: /* should only be 1 begin */
6550 dgap_err("unexpected config_begin\n");
6556 case BOARD: /* board info */
6557 if (dgap_checknode(p))
6559 p->next = dgap_newnode(BNODE);
6561 dgap_err("out of memory");
6566 p->u.board.status = dgap_savestring("No");
6572 case APORT2_920P: /* AccelePort_4 */
6573 if (p->type != BNODE) {
6574 dgap_err("unexpected Digi_2r_920 string");
6577 p->u.board.type = APORT2_920P;
6578 p->u.board.v_type = 1;
6581 case APORT4_920P: /* AccelePort_4 */
6582 if (p->type != BNODE) {
6583 dgap_err("unexpected Digi_4r_920 string");
6586 p->u.board.type = APORT4_920P;
6587 p->u.board.v_type = 1;
6590 case APORT8_920P: /* AccelePort_8 */
6591 if (p->type != BNODE) {
6592 dgap_err("unexpected Digi_8r_920 string");
6595 p->u.board.type = APORT8_920P;
6596 p->u.board.v_type = 1;
6599 case PAPORT4: /* AccelePort_4 PCI */
6600 if (p->type != BNODE) {
6601 dgap_err("unexpected Digi_4r(PCI) string");
6604 p->u.board.type = PAPORT4;
6605 p->u.board.v_type = 1;
6608 case PAPORT8: /* AccelePort_8 PCI */
6609 if (p->type != BNODE) {
6610 dgap_err("unexpected Digi_8r string");
6613 p->u.board.type = PAPORT8;
6614 p->u.board.v_type = 1;
6617 case PCX: /* PCI C/X */
6618 if (p->type != BNODE) {
6619 dgap_err("unexpected Digi_C/X_(PCI) string");
6622 p->u.board.type = PCX;
6623 p->u.board.v_type = 1;
6624 p->u.board.conc1 = 0;
6625 p->u.board.conc2 = 0;
6626 p->u.board.module1 = 0;
6627 p->u.board.module2 = 0;
6630 case PEPC: /* PCI EPC/X */
6631 if (p->type != BNODE) {
6632 dgap_err("unexpected \"Digi_EPC/X_(PCI)\" string");
6635 p->u.board.type = PEPC;
6636 p->u.board.v_type = 1;
6637 p->u.board.conc1 = 0;
6638 p->u.board.conc2 = 0;
6639 p->u.board.module1 = 0;
6640 p->u.board.module2 = 0;
6643 case PPCM: /* PCI/Xem */
6644 if (p->type != BNODE) {
6645 dgap_err("unexpected PCI/Xem string");
6648 p->u.board.type = PPCM;
6649 p->u.board.v_type = 1;
6650 p->u.board.conc1 = 0;
6651 p->u.board.conc2 = 0;
6654 case IO: /* i/o port */
6655 if (p->type != BNODE) {
6656 dgap_err("IO port only vaild for boards");
6659 s = dgap_getword(in);
6661 dgap_err("unexpected end of file");
6664 p->u.board.portstr = dgap_savestring(s);
6665 if (kstrtol(s, 0, &p->u.board.port)) {
6666 dgap_err("bad number for IO port");
6669 p->u.board.v_port = 1;
6672 case MEM: /* memory address */
6673 if (p->type != BNODE) {
6674 dgap_err("memory address only vaild for boards");
6677 s = dgap_getword(in);
6679 dgap_err("unexpected end of file");
6682 p->u.board.addrstr = dgap_savestring(s);
6683 if (kstrtoul(s, 0, &p->u.board.addr)) {
6684 dgap_err("bad number for memory address");
6687 p->u.board.v_addr = 1;
6690 case PCIINFO: /* pci information */
6691 if (p->type != BNODE) {
6692 dgap_err("memory address only vaild for boards");
6695 s = dgap_getword(in);
6697 dgap_err("unexpected end of file");
6700 p->u.board.pcibusstr = dgap_savestring(s);
6701 if (kstrtoul(s, 0, &p->u.board.pcibus)) {
6702 dgap_err("bad number for pci bus");
6705 p->u.board.v_pcibus = 1;
6706 s = dgap_getword(in);
6708 dgap_err("unexpected end of file");
6711 p->u.board.pcislotstr = dgap_savestring(s);
6712 if (kstrtoul(s, 0, &p->u.board.pcislot)) {
6713 dgap_err("bad number for pci slot");
6716 p->u.board.v_pcislot = 1;
6720 if (p->type != BNODE) {
6721 dgap_err("install method only vaild for boards");
6724 s = dgap_getword(in);
6726 dgap_err("unexpected end of file");
6729 p->u.board.method = dgap_savestring(s);
6730 p->u.board.v_method = 1;
6734 if (p->type != BNODE) {
6735 dgap_err("config status only vaild for boards");
6738 s = dgap_getword(in);
6740 dgap_err("unexpected end of file");
6743 p->u.board.status = dgap_savestring(s);
6746 case NPORTS: /* number of ports */
6747 if (p->type == BNODE) {
6748 s = dgap_getword(in);
6750 dgap_err("unexpected end of file");
6753 if (kstrtol(s, 0, &p->u.board.nport)) {
6754 dgap_err("bad number for number of ports");
6757 p->u.board.v_nport = 1;
6758 } else if (p->type == CNODE) {
6759 s = dgap_getword(in);
6761 dgap_err("unexpected end of file");
6764 if (kstrtol(s, 0, &p->u.conc.nport)) {
6765 dgap_err("bad number for number of ports");
6768 p->u.conc.v_nport = 1;
6769 } else if (p->type == MNODE) {
6770 s = dgap_getword(in);
6772 dgap_err("unexpected end of file");
6775 if (kstrtol(s, 0, &p->u.module.nport)) {
6776 dgap_err("bad number for number of ports");
6779 p->u.module.v_nport = 1;
6781 dgap_err("nports only valid for concentrators or modules");
6786 case ID: /* letter ID used in tty name */
6787 s = dgap_getword(in);
6789 dgap_err("unexpected end of file");
6793 p->u.board.status = dgap_savestring(s);
6795 if (p->type == CNODE) {
6796 p->u.conc.id = dgap_savestring(s);
6798 } else if (p->type == MNODE) {
6799 p->u.module.id = dgap_savestring(s);
6800 p->u.module.v_id = 1;
6802 dgap_err("id only valid for concentrators or modules");
6807 case STARTO: /* start offset of ID */
6808 if (p->type == BNODE) {
6809 s = dgap_getword(in);
6811 dgap_err("unexpected end of file");
6814 if (kstrtol(s, 0, &p->u.board.start)) {
6815 dgap_err("bad number for start of tty count");
6818 p->u.board.v_start = 1;
6819 } else if (p->type == CNODE) {
6820 s = dgap_getword(in);
6822 dgap_err("unexpected end of file");
6825 if (kstrtol(s, 0, &p->u.conc.start)) {
6826 dgap_err("bad number for start of tty count");
6829 p->u.conc.v_start = 1;
6830 } else if (p->type == MNODE) {
6831 s = dgap_getword(in);
6833 dgap_err("unexpected end of file");
6836 if (kstrtol(s, 0, &p->u.module.start)) {
6837 dgap_err("bad number for start of tty count");
6840 p->u.module.v_start = 1;
6842 dgap_err("start only valid for concentrators or modules");
6847 case TTYN: /* tty name prefix */
6848 if (dgap_checknode(p))
6850 p->next = dgap_newnode(TNODE);
6852 dgap_err("out of memory");
6856 s = dgap_getword(in);
6858 dgap_err("unexpeced end of file");
6861 p->u.ttyname = dgap_savestring(s);
6862 if (!p->u.ttyname) {
6863 dgap_err("out of memory");
6868 case CU: /* cu name prefix */
6869 if (dgap_checknode(p))
6871 p->next = dgap_newnode(CUNODE);
6873 dgap_err("out of memory");
6877 s = dgap_getword(in);
6879 dgap_err("unexpeced end of file");
6882 p->u.cuname = dgap_savestring(s);
6884 dgap_err("out of memory");
6889 case LINE: /* line information */
6890 if (dgap_checknode(p))
6893 dgap_err("must specify board before line info");
6896 switch (brd->u.board.type) {
6898 dgap_err("line not vaild for PC/em");
6901 p->next = dgap_newnode(LNODE);
6903 dgap_err("out of memory");
6912 case CONC: /* concentrator information */
6913 if (dgap_checknode(p))
6916 dgap_err("must specify line info before concentrator");
6919 p->next = dgap_newnode(CNODE);
6921 dgap_err("out of memory");
6927 brd->u.board.conc2++;
6929 brd->u.board.conc1++;
6933 case CX: /* c/x type concentrator */
6934 if (p->type != CNODE) {
6935 dgap_err("cx only valid for concentrators");
6938 p->u.conc.type = CX;
6939 p->u.conc.v_type = 1;
6942 case EPC: /* epc type concentrator */
6943 if (p->type != CNODE) {
6944 dgap_err("cx only valid for concentrators");
6947 p->u.conc.type = EPC;
6948 p->u.conc.v_type = 1;
6951 case MOD: /* EBI module */
6952 if (dgap_checknode(p))
6955 dgap_err("must specify board info before EBI modules");
6958 switch (brd->u.board.type) {
6964 dgap_err("must specify concentrator info before EBI module");
6968 p->next = dgap_newnode(MNODE);
6970 dgap_err("out of memory");
6975 brd->u.board.module2++;
6977 brd->u.board.module1++;
6981 case PORTS: /* ports type EBI module */
6982 if (p->type != MNODE) {
6983 dgap_err("ports only valid for EBI modules");
6986 p->u.module.type = PORTS;
6987 p->u.module.v_type = 1;
6990 case MODEM: /* ports type EBI module */
6991 if (p->type != MNODE) {
6992 dgap_err("modem only valid for modem modules");
6995 p->u.module.type = MODEM;
6996 p->u.module.v_type = 1;
7000 if (p->type == LNODE) {
7001 s = dgap_getword(in);
7003 dgap_err("unexpected end of file");
7006 p->u.line.cable = dgap_savestring(s);
7007 p->u.line.v_cable = 1;
7011 case SPEED: /* sync line speed indication */
7012 if (p->type == LNODE) {
7013 s = dgap_getword(in);
7015 dgap_err("unexpected end of file");
7018 if (kstrtol(s, 0, &p->u.line.speed)) {
7019 dgap_err("bad number for line speed");
7022 p->u.line.v_speed = 1;
7023 } else if (p->type == CNODE) {
7024 s = dgap_getword(in);
7026 dgap_err("unexpected end of file");
7029 if (kstrtol(s, 0, &p->u.conc.speed)) {
7030 dgap_err("bad number for line speed");
7033 p->u.conc.v_speed = 1;
7035 dgap_err("speed valid only for lines or concentrators.");
7041 if (p->type == CNODE) {
7042 s = dgap_getword(in);
7044 dgap_err("unexpected end of file");
7047 p->u.conc.connect = dgap_savestring(s);
7048 p->u.conc.v_connect = 1;
7051 case PRINT: /* transparent print name prefix */
7052 if (dgap_checknode(p))
7054 p->next = dgap_newnode(PNODE);
7056 dgap_err("out of memory");
7060 s = dgap_getword(in);
7062 dgap_err("unexpeced end of file");
7065 p->u.printname = dgap_savestring(s);
7066 if (!p->u.printname) {
7067 dgap_err("out of memory");
7072 case CMAJOR: /* major number */
7073 if (dgap_checknode(p))
7075 p->next = dgap_newnode(JNODE);
7077 dgap_err("out of memory");
7081 s = dgap_getword(in);
7083 dgap_err("unexpected end of file");
7086 if (kstrtol(s, 0, &p->u.majornumber)) {
7087 dgap_err("bad number for major number");
7092 case ALTPIN: /* altpin setting */
7093 if (dgap_checknode(p))
7095 p->next = dgap_newnode(ANODE);
7097 dgap_err("out of memory");
7101 s = dgap_getword(in);
7103 dgap_err("unexpected end of file");
7106 if (kstrtol(s, 0, &p->u.altpin)) {
7107 dgap_err("bad number for altpin");
7112 case USEINTR: /* enable interrupt setting */
7113 if (dgap_checknode(p))
7115 p->next = dgap_newnode(INTRNODE);
7117 dgap_err("out of memory");
7121 s = dgap_getword(in);
7123 dgap_err("unexpected end of file");
7126 if (kstrtol(s, 0, &p->u.useintr)) {
7127 dgap_err("bad number for useintr");
7132 case TTSIZ: /* size of tty structure */
7133 if (dgap_checknode(p))
7135 p->next = dgap_newnode(TSNODE);
7137 dgap_err("out of memory");
7141 s = dgap_getword(in);
7143 dgap_err("unexpected end of file");
7146 if (kstrtol(s, 0, &p->u.ttysize)) {
7147 dgap_err("bad number for ttysize");
7152 case CHSIZ: /* channel structure size */
7153 if (dgap_checknode(p))
7155 p->next = dgap_newnode(CSNODE);
7157 dgap_err("out of memory");
7161 s = dgap_getword(in);
7163 dgap_err("unexpected end of file");
7166 if (kstrtol(s, 0, &p->u.chsize)) {
7167 dgap_err("bad number for chsize");
7172 case BSSIZ: /* board structure size */
7173 if (dgap_checknode(p))
7175 p->next = dgap_newnode(BSNODE);
7177 dgap_err("out of memory");
7181 s = dgap_getword(in);
7183 dgap_err("unexpected end of file");
7186 if (kstrtol(s, 0, &p->u.bssize)) {
7187 dgap_err("bad number for bssize");
7192 case UNTSIZ: /* sched structure size */
7193 if (dgap_checknode(p))
7195 p->next = dgap_newnode(USNODE);
7197 dgap_err("out of memory");
7201 s = dgap_getword(in);
7203 dgap_err("unexpected end of file");
7206 if (kstrtol(s, 0, &p->u.unsize)) {
7207 dgap_err("bad number for schedsize");
7212 case F2SIZ: /* f2200 structure size */
7213 if (dgap_checknode(p))
7215 p->next = dgap_newnode(FSNODE);
7217 dgap_err("out of memory");
7221 s = dgap_getword(in);
7223 dgap_err("unexpected end of file");
7226 if (kstrtol(s, 0, &p->u.f2size)) {
7227 dgap_err("bad number for f2200size");
7232 case VPSIZ: /* vpix structure size */
7233 if (dgap_checknode(p))
7235 p->next = dgap_newnode(VSNODE);
7237 dgap_err("out of memory");
7241 s = dgap_getword(in);
7243 dgap_err("unexpected end of file");
7246 if (kstrtol(s, 0, &p->u.vpixsize)) {
7247 dgap_err("bad number for vpixsize");
7256 * dgap_sindex: much like index(), but it looks for a match of any character in
7257 * the group, and returns that position. If the first character is a ^, then
7258 * this will match the first occurrence not in that group.
7260 static char *dgap_sindex(char *string, char *group)
7264 if (!string || !group)
7265 return (char *) NULL;
7267 if (*group == '^') {
7269 for (; *string; string++) {
7270 for (ptr = group; *ptr; ptr++) {
7271 if (*ptr == *string)
7278 for (; *string; string++) {
7279 for (ptr = group; *ptr; ptr++) {
7280 if (*ptr == *string)
7286 return (char *) NULL;
7290 * Get a token from the input file; return 0 if end of file is reached
7292 static int dgap_gettok(char **in, struct cnode *p)
7297 if (strstr(dgap_cword, "boar")) {
7298 w = dgap_getword(in);
7299 snprintf(dgap_cword, MAXCWORD, "%s", w);
7300 for (t = dgap_tlist; t->token != 0; t++) {
7301 if (!strcmp(w, t->string))
7304 dgap_err("board !!type not specified");
7307 while ((w = dgap_getword(in))) {
7308 snprintf(dgap_cword, MAXCWORD, "%s", w);
7309 for (t = dgap_tlist; t->token != 0; t++) {
7310 if (!strcmp(w, t->string))
7319 * get a word from the input stream, also keep track of current line number.
7320 * words are separated by whitespace.
7322 static char *dgap_getword(char **in)
7324 char *ret_ptr = *in;
7326 char *ptr = dgap_sindex(*in, " \t\n");
7328 /* If no word found, return null */
7332 /* Mark new location for our buffer */
7336 /* Eat any extra spaces/tabs/newlines that might be present */
7337 while (*in && **in && ((**in == ' ') ||
7348 * print an error message, giving the line number in the file where
7349 * the error occurred.
7351 static void dgap_err(char *s)
7353 pr_err("dgap: parse: %s\n", s);
7357 * allocate a new configuration node of type t
7359 static struct cnode *dgap_newnode(int t)
7363 n = kmalloc(sizeof(struct cnode), GFP_ATOMIC);
7365 memset((char *)n, 0, sizeof(struct cnode));
7372 * dgap_checknode: see if all the necessary info has been supplied for a node
7373 * before creating the next node.
7375 static int dgap_checknode(struct cnode *p)
7379 if (p->u.board.v_type == 0) {
7380 dgap_err("board type !not specified");
7387 if (p->u.line.v_speed == 0) {
7388 dgap_err("line speed not specified");
7394 if (p->u.conc.v_type == 0) {
7395 dgap_err("concentrator type not specified");
7398 if (p->u.conc.v_speed == 0) {
7399 dgap_err("concentrator line speed not specified");
7402 if (p->u.conc.v_nport == 0) {
7403 dgap_err("number of ports on concentrator not specified");
7406 if (p->u.conc.v_id == 0) {
7407 dgap_err("concentrator id letter not specified");
7413 if (p->u.module.v_type == 0) {
7414 dgap_err("EBI module type not specified");
7417 if (p->u.module.v_nport == 0) {
7418 dgap_err("number of ports on EBI module not specified");
7421 if (p->u.module.v_id == 0) {
7422 dgap_err("EBI module id letter not specified");
7431 * save a string somewhere
7433 static char *dgap_savestring(char *s)
7437 p = kmalloc(strlen(s) + 1, GFP_ATOMIC);
7444 * Given a board pointer, returns whether we should use interrupts or not.
7446 static uint dgap_config_get_useintr(struct board_t *bd)
7448 struct cnode *p = NULL;
7453 for (p = bd->bd_config; p; p = p->next) {
7457 * check for pcxr types.
7459 return p->u.useintr;
7465 /* If not found, then don't turn on interrupts. */
7470 * Given a board pointer, returns whether we turn on altpin or not.
7472 static uint dgap_config_get_altpin(struct board_t *bd)
7474 struct cnode *p = NULL;
7479 for (p = bd->bd_config; p; p = p->next) {
7483 * check for pcxr types.
7491 /* If not found, then don't turn on interrupts. */
7496 * Given a specific type of board, if found, detached link and
7497 * returns the first occurrence in the list.
7499 static struct cnode *dgap_find_config(int type, int bus, int slot)
7501 struct cnode *p, *prev = NULL, *prev2 = NULL, *found = NULL;
7505 while (p->next != NULL) {
7509 if (p->type == BNODE) {
7511 if (p->u.board.type == type) {
7513 if (p->u.board.v_pcibus &&
7514 p->u.board.pcibus != bus)
7516 if (p->u.board.v_pcislot &&
7517 p->u.board.pcislot != slot)
7522 * Keep walking thru the list till we
7523 * find the next board.
7525 while (p->next != NULL) {
7528 if (p->type == BNODE) {
7531 * Mark the end of our 1 board
7537 * Link the "next" board to the
7538 * previous board, effectively
7539 * "unlinking" our board from
7548 * It must be the last board in the list.
7559 * Given a board pointer, walks the config link, counting up
7560 * all ports user specified should be on the board.
7561 * (This does NOT mean they are all actually present right now tho)
7563 static uint dgap_config_get_num_prts(struct board_t *bd)
7566 struct cnode *p = NULL;
7571 for (p = bd->bd_config; p; p = p->next) {
7576 * check for pcxr types.
7578 if (p->u.board.type > EPCFE)
7579 count += p->u.board.nport;
7582 count += p->u.conc.nport;
7585 count += p->u.module.nport;
7592 static char *dgap_create_config_string(struct board_t *bd, char *string)
7595 struct cnode *p = NULL;
7596 struct cnode *q = NULL;
7604 for (p = bd->bd_config; p; p = p->next) {
7610 *ptr = p->u.line.speed;
7615 * Because the EPC/con concentrators can have EM modules
7616 * hanging off of them, we have to walk ahead in the
7617 * list and keep adding the number of ports on each EM
7618 * to the config. UGH!
7620 speed = p->u.conc.speed;
7622 if ((q != NULL) && (q->type == MNODE)) {
7623 *ptr = (p->u.conc.nport + 0x80);
7626 while ((q->next != NULL) &&
7627 (q->next->type) == MNODE) {
7629 *ptr = (q->u.module.nport + 0x80);
7634 *ptr = q->u.module.nport;
7637 *ptr = p->u.conc.nport;