2 * Copyright 2003 Digi International (www.digi.com)
3 * Scott H Kilau <Scott_Kilau at digi dot com>
5 * This program is free software; you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published by
7 * the Free Software Foundation; either version 2, or (at your option)
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY, EXPRESS OR IMPLIED; without even the
12 * implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
13 * PURPOSE. See the GNU General Public License for more details.
18 * In the original out of kernel Digi dgap driver, firmware
19 * loading was done via user land to driver handshaking.
21 * For cards that support a concentrator (port expander),
22 * I believe the concentrator its self told the card which
23 * concentrator is actually attached and then that info
24 * was used to tell user land which concentrator firmware
25 * image was to be downloaded. I think even the BIOS or
26 * FEP images required could change with the connection
27 * of a particular concentrator.
29 * Since I have no access to any of these cards or
30 * concentrators, I cannot put the correct concentrator
31 * firmware file names into the firmware_info structure
32 * as is now done for the BIOS and FEP images.
34 * I think, but am not certain, that the cards supporting
35 * concentrators will function without them. So support
36 * of these cards has been left in this driver.
38 * In order to fully support those cards, they would
39 * either have to be acquired for dissection or maybe
40 * Digi International could provide some assistance.
42 #undef DIGI_CONCENTRATORS_SUPPORTED
44 #include <linux/kernel.h>
45 #include <linux/module.h>
46 #include <linux/pci.h>
47 #include <linux/delay.h> /* For udelay */
48 #include <linux/slab.h>
49 #include <linux/uaccess.h>
50 #include <linux/sched.h>
52 #include <linux/interrupt.h> /* For tasklet and interrupt structs/defines */
53 #include <linux/ctype.h>
54 #include <linux/tty.h>
55 #include <linux/tty_flip.h>
56 #include <linux/serial_reg.h>
57 #include <linux/io.h> /* For read[bwl]/write[bwl] */
59 #include <linux/string.h>
60 #include <linux/device.h>
61 #include <linux/kdev_t.h>
62 #include <linux/firmware.h>
66 MODULE_LICENSE("GPL");
67 MODULE_AUTHOR("Digi International, http://www.digi.com");
68 MODULE_DESCRIPTION("Driver for the Digi International EPCA PCI based product line");
69 MODULE_SUPPORTED_DEVICE("dgap");
71 static int dgap_start(void);
72 static void dgap_init_globals(void);
73 static int dgap_found_board(struct pci_dev *pdev, int id);
74 static void dgap_cleanup_board(struct board_t *brd);
75 static void dgap_poll_handler(ulong dummy);
76 static int dgap_init_pci(void);
77 static int dgap_init_one(struct pci_dev *pdev, const struct pci_device_id *ent);
78 static void dgap_remove_one(struct pci_dev *dev);
79 static int dgap_probe1(struct pci_dev *pdev, int card_type);
80 static int dgap_do_remap(struct board_t *brd);
81 static irqreturn_t dgap_intr(int irq, void *voidbrd);
83 static int dgap_tty_open(struct tty_struct *tty, struct file *file);
84 static void dgap_tty_close(struct tty_struct *tty, struct file *file);
85 static int dgap_block_til_ready(struct tty_struct *tty, struct file *file,
86 struct channel_t *ch);
87 static int dgap_tty_ioctl(struct tty_struct *tty, unsigned int cmd,
89 static int dgap_tty_digigeta(struct tty_struct *tty,
90 struct digi_t __user *retinfo);
91 static int dgap_tty_digiseta(struct tty_struct *tty,
92 struct digi_t __user *new_info);
93 static int dgap_tty_digigetedelay(struct tty_struct *tty, int __user *retinfo);
94 static int dgap_tty_digisetedelay(struct tty_struct *tty, int __user *new_info);
95 static int dgap_tty_write_room(struct tty_struct *tty);
96 static int dgap_tty_chars_in_buffer(struct tty_struct *tty);
97 static void dgap_tty_start(struct tty_struct *tty);
98 static void dgap_tty_stop(struct tty_struct *tty);
99 static void dgap_tty_throttle(struct tty_struct *tty);
100 static void dgap_tty_unthrottle(struct tty_struct *tty);
101 static void dgap_tty_flush_chars(struct tty_struct *tty);
102 static void dgap_tty_flush_buffer(struct tty_struct *tty);
103 static void dgap_tty_hangup(struct tty_struct *tty);
104 static int dgap_wait_for_drain(struct tty_struct *tty);
105 static int dgap_set_modem_info(struct tty_struct *tty, unsigned int command,
106 unsigned int __user *value);
107 static int dgap_get_modem_info(struct channel_t *ch,
108 unsigned int __user *value);
109 static int dgap_tty_digisetcustombaud(struct tty_struct *tty,
110 int __user *new_info);
111 static int dgap_tty_digigetcustombaud(struct tty_struct *tty,
112 int __user *retinfo);
113 static int dgap_tty_tiocmget(struct tty_struct *tty);
114 static int dgap_tty_tiocmset(struct tty_struct *tty, unsigned int set,
116 static int dgap_tty_send_break(struct tty_struct *tty, int msec);
117 static void dgap_tty_wait_until_sent(struct tty_struct *tty, int timeout);
118 static int dgap_tty_write(struct tty_struct *tty, const unsigned char *buf,
120 static void dgap_tty_set_termios(struct tty_struct *tty,
121 struct ktermios *old_termios);
122 static int dgap_tty_put_char(struct tty_struct *tty, unsigned char c);
123 static void dgap_tty_send_xchar(struct tty_struct *tty, char ch);
125 static int dgap_tty_register(struct board_t *brd);
126 static int dgap_tty_init(struct board_t *);
127 static void dgap_tty_uninit(struct board_t *);
128 static void dgap_carrier(struct channel_t *ch);
129 static void dgap_input(struct channel_t *ch);
132 * Our function prototypes from dgap_fep5
134 static void dgap_cmdw_ext(struct channel_t *ch, u16 cmd, u16 word, uint ncmds);
135 static int dgap_event(struct board_t *bd);
137 static void dgap_poll_tasklet(unsigned long data);
138 static void dgap_cmdb(struct channel_t *ch, u8 cmd, u8 byte1,
139 u8 byte2, uint ncmds);
140 static void dgap_cmdw(struct channel_t *ch, u8 cmd, u16 word, uint ncmds);
141 static void dgap_wmove(struct channel_t *ch, char *buf, uint cnt);
142 static int dgap_param(struct tty_struct *tty);
143 static void dgap_parity_scan(struct channel_t *ch, unsigned char *cbuf,
144 unsigned char *fbuf, int *len);
145 static uint dgap_get_custom_baud(struct channel_t *ch);
146 static void dgap_firmware_reset_port(struct channel_t *ch);
149 * Function prototypes from dgap_parse.c.
151 static int dgap_gettok(char **in, struct cnode *p);
152 static char *dgap_getword(char **in);
153 static char *dgap_savestring(char *s);
154 static struct cnode *dgap_newnode(int t);
155 static int dgap_checknode(struct cnode *p);
156 static void dgap_err(char *s);
159 * Function prototypes from dgap_sysfs.h
167 static void dgap_create_ports_sysfiles(struct board_t *bd);
168 static void dgap_remove_ports_sysfiles(struct board_t *bd);
170 static int dgap_create_driver_sysfiles(struct pci_driver *);
171 static void dgap_remove_driver_sysfiles(struct pci_driver *);
173 static void dgap_create_tty_sysfs(struct un_t *un, struct device *c);
174 static void dgap_remove_tty_sysfs(struct device *c);
177 * Function prototypes from dgap_parse.h
179 static int dgap_parsefile(char **in, int Remove);
180 static struct cnode *dgap_find_config(int type, int bus, int slot);
181 static uint dgap_config_get_num_prts(struct board_t *bd);
182 static char *dgap_create_config_string(struct board_t *bd, char *string);
183 static uint dgap_config_get_useintr(struct board_t *bd);
184 static uint dgap_config_get_altpin(struct board_t *bd);
186 static int dgap_ms_sleep(ulong ms);
187 static void dgap_do_bios_load(struct board_t *brd, const u8 *ubios, int len);
188 static void dgap_do_fep_load(struct board_t *brd, const u8 *ufep, int len);
189 #ifdef DIGI_CONCENTRATORS_SUPPORTED
190 static void dgap_do_conc_load(struct board_t *brd, u8 *uaddr, int len);
192 static int dgap_after_config_loaded(int board);
193 static int dgap_finalize_board_init(struct board_t *brd);
195 static void dgap_get_vpd(struct board_t *brd);
196 static void dgap_do_reset_board(struct board_t *brd);
197 static int dgap_test_bios(struct board_t *brd);
198 static int dgap_test_fep(struct board_t *brd);
199 static int dgap_tty_register_ports(struct board_t *brd);
200 static int dgap_firmware_load(struct pci_dev *pdev, int card_type);
202 static void dgap_cleanup_module(void);
204 module_exit(dgap_cleanup_module);
207 * File operations permitted on Control/Management major.
209 static const struct file_operations DgapBoardFops = {
210 .owner = THIS_MODULE,
213 static uint dgap_NumBoards;
214 static struct board_t *dgap_Board[MAXBOARDS];
215 static ulong dgap_poll_counter;
216 static char *dgap_config_buf;
217 static int dgap_driver_state = DRIVER_INITIALIZED;
218 static wait_queue_head_t dgap_dl_wait;
219 static int dgap_poll_tick = 20; /* Poll interval - 20 ms */
221 static struct class *dgap_class;
223 static struct board_t *dgap_BoardsByMajor[256];
224 static uint dgap_count = 500;
229 DEFINE_SPINLOCK(dgap_poll_lock); /* Poll scheduling lock */
230 static ulong dgap_poll_time; /* Time of next poll */
231 static uint dgap_poll_stop; /* Used to tell poller to stop */
232 static struct timer_list dgap_poll_timer;
237 Card Model Number of Ports Interface
238 ----------------------------------------------------------------
239 Acceleport Xem 4 - 64 (EIA232 & EIA422)
240 Acceleport Xr 4 & 8 (EIA232)
241 Acceleport Xr 920 4 & 8 (EIA232)
242 Acceleport C/X 8 - 128 (EIA232)
243 Acceleport EPC/X 8 - 224 (EIA232)
244 Acceleport Xr/422 4 & 8 (EIA422)
245 Acceleport 2r/920 2 (EIA232)
246 Acceleport 4r/920 4 (EIA232)
247 Acceleport 8r/920 8 (EIA232)
249 IBM 8-Port Asynchronous PCI Adapter (EIA232)
250 IBM 128-Port Asynchronous PCI Adapter (EIA232 & EIA422)
253 static struct pci_device_id dgap_pci_tbl[] = {
254 { DIGI_VID, PCI_DEV_XEM_DID, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0 },
255 { DIGI_VID, PCI_DEV_CX_DID, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 1 },
256 { DIGI_VID, PCI_DEV_CX_IBM_DID, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 2 },
257 { DIGI_VID, PCI_DEV_EPCJ_DID, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 3 },
258 { DIGI_VID, PCI_DEV_920_2_DID, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 4 },
259 { DIGI_VID, PCI_DEV_920_4_DID, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 5 },
260 { DIGI_VID, PCI_DEV_920_8_DID, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 6 },
261 { DIGI_VID, PCI_DEV_XR_DID, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 7 },
262 { DIGI_VID, PCI_DEV_XRJ_DID, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 8 },
263 { DIGI_VID, PCI_DEV_XR_422_DID, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 9 },
264 { DIGI_VID, PCI_DEV_XR_IBM_DID, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 10 },
265 { DIGI_VID, PCI_DEV_XR_SAIP_DID, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 11 },
266 { DIGI_VID, PCI_DEV_XR_BULL_DID, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 12 },
267 { DIGI_VID, PCI_DEV_920_8_HP_DID, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 13 },
268 { DIGI_VID, PCI_DEV_XEM_HP_DID, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 14 },
269 {0,} /* 0 terminated list. */
271 MODULE_DEVICE_TABLE(pci, dgap_pci_tbl);
274 * A generic list of Product names, PCI Vendor ID, and PCI Device ID.
283 static struct board_id dgap_Ids[] = {
284 { PPCM, PCI_DEV_XEM_NAME, 64, (T_PCXM|T_PCLITE|T_PCIBUS) },
285 { PCX, PCI_DEV_CX_NAME, 128, (T_CX|T_PCIBUS) },
286 { PCX, PCI_DEV_CX_IBM_NAME, 128, (T_CX|T_PCIBUS) },
287 { PEPC, PCI_DEV_EPCJ_NAME, 224, (T_EPC|T_PCIBUS) },
288 { APORT2_920P, PCI_DEV_920_2_NAME, 2, (T_PCXR|T_PCLITE|T_PCIBUS) },
289 { APORT4_920P, PCI_DEV_920_4_NAME, 4, (T_PCXR|T_PCLITE|T_PCIBUS) },
290 { APORT8_920P, PCI_DEV_920_8_NAME, 8, (T_PCXR|T_PCLITE|T_PCIBUS) },
291 { PAPORT8, PCI_DEV_XR_NAME, 8, (T_PCXR|T_PCLITE|T_PCIBUS) },
292 { PAPORT8, PCI_DEV_XRJ_NAME, 8, (T_PCXR|T_PCLITE|T_PCIBUS) },
293 { PAPORT8, PCI_DEV_XR_422_NAME, 8, (T_PCXR|T_PCLITE|T_PCIBUS) },
294 { PAPORT8, PCI_DEV_XR_IBM_NAME, 8, (T_PCXR|T_PCLITE|T_PCIBUS) },
295 { PAPORT8, PCI_DEV_XR_SAIP_NAME, 8, (T_PCXR|T_PCLITE|T_PCIBUS) },
296 { PAPORT8, PCI_DEV_XR_BULL_NAME, 8, (T_PCXR|T_PCLITE|T_PCIBUS) },
297 { APORT8_920P, PCI_DEV_920_8_HP_NAME, 8, (T_PCXR|T_PCLITE|T_PCIBUS) },
298 { PPCM, PCI_DEV_XEM_HP_NAME, 64, (T_PCXM|T_PCLITE|T_PCIBUS) },
299 {0,} /* 0 terminated list. */
302 static struct pci_driver dgap_driver = {
304 .probe = dgap_init_one,
305 .id_table = dgap_pci_tbl,
306 .remove = dgap_remove_one,
309 struct firmware_info {
310 u8 *conf_name; /* dgap.conf */
311 u8 *bios_name; /* BIOS filename */
312 u8 *fep_name; /* FEP filename */
313 u8 *con_name; /* Concentrator filename FIXME*/
314 int num; /* sequence number */
318 * Firmware - BIOS, FEP, and CONC filenames
320 static struct firmware_info fw_info[] = {
321 { "dgap/dgap.conf", "dgap/sxbios.bin", "dgap/sxfep.bin", 0, 0 },
322 { "dgap/dgap.conf", "dgap/cxpbios.bin", "dgap/cxpfep.bin", 0, 1 },
323 { "dgap/dgap.conf", "dgap/cxpbios.bin", "dgap/cxpfep.bin", 0, 2 },
324 { "dgap/dgap.conf", "dgap/pcibios.bin", "dgap/pcifep.bin", 0, 3 },
325 { "dgap/dgap.conf", "dgap/xrbios.bin", "dgap/xrfep.bin", 0, 4 },
326 { "dgap/dgap.conf", "dgap/xrbios.bin", "dgap/xrfep.bin", 0, 5 },
327 { "dgap/dgap.conf", "dgap/xrbios.bin", "dgap/xrfep.bin", 0, 6 },
328 { "dgap/dgap.conf", "dgap/xrbios.bin", "dgap/xrfep.bin", 0, 7 },
329 { "dgap/dgap.conf", "dgap/xrbios.bin", "dgap/xrfep.bin", 0, 8 },
330 { "dgap/dgap.conf", "dgap/xrbios.bin", "dgap/xrfep.bin", 0, 9 },
331 { "dgap/dgap.conf", "dgap/xrbios.bin", "dgap/xrfep.bin", 0, 10 },
332 { "dgap/dgap.conf", "dgap/xrbios.bin", "dgap/xrfep.bin", 0, 11 },
333 { "dgap/dgap.conf", "dgap/xrbios.bin", "dgap/xrfep.bin", 0, 12 },
334 { "dgap/dgap.conf", "dgap/xrbios.bin", "dgap/xrfep.bin", 0, 13 },
335 { "dgap/dgap.conf", "dgap/sxbios.bin", "dgap/sxfep.bin", 0, 14 },
340 * Default transparent print information.
342 static struct digi_t dgap_digi_init = {
343 .digi_flags = DIGI_COOK, /* Flags */
344 .digi_maxcps = 100, /* Max CPS */
345 .digi_maxchar = 50, /* Max chars in print queue */
346 .digi_bufsize = 100, /* Printer buffer size */
347 .digi_onlen = 4, /* size of printer on string */
348 .digi_offlen = 4, /* size of printer off string */
349 .digi_onstr = "\033[5i", /* ANSI printer on string ] */
350 .digi_offstr = "\033[4i", /* ANSI printer off string ] */
351 .digi_term = "ansi" /* default terminal type */
355 * Define a local default termios struct. All ports will be created
356 * with this termios initially.
358 * This defines a raw port at 9600 baud, 8 data bits, no parity,
362 static struct ktermios DgapDefaultTermios = {
363 .c_iflag = (DEFAULT_IFLAGS), /* iflags */
364 .c_oflag = (DEFAULT_OFLAGS), /* oflags */
365 .c_cflag = (DEFAULT_CFLAGS), /* cflags */
366 .c_lflag = (DEFAULT_LFLAGS), /* lflags */
371 static const struct tty_operations dgap_tty_ops = {
372 .open = dgap_tty_open,
373 .close = dgap_tty_close,
374 .write = dgap_tty_write,
375 .write_room = dgap_tty_write_room,
376 .flush_buffer = dgap_tty_flush_buffer,
377 .chars_in_buffer = dgap_tty_chars_in_buffer,
378 .flush_chars = dgap_tty_flush_chars,
379 .ioctl = dgap_tty_ioctl,
380 .set_termios = dgap_tty_set_termios,
381 .stop = dgap_tty_stop,
382 .start = dgap_tty_start,
383 .throttle = dgap_tty_throttle,
384 .unthrottle = dgap_tty_unthrottle,
385 .hangup = dgap_tty_hangup,
386 .put_char = dgap_tty_put_char,
387 .tiocmget = dgap_tty_tiocmget,
388 .tiocmset = dgap_tty_tiocmset,
389 .break_ctl = dgap_tty_send_break,
390 .wait_until_sent = dgap_tty_wait_until_sent,
391 .send_xchar = dgap_tty_send_xchar
395 * Our needed internal static variables from dgap_parse.c
397 static struct cnode dgap_head;
399 static char dgap_cword[MAXCWORD];
406 static struct toklist dgap_tlist[] = {
407 { BEGIN, "config_begin" },
408 { END, "config_end" },
410 { PCX, "Digi_AccelePort_C/X_PCI" },
411 { PEPC, "Digi_AccelePort_EPC/X_PCI" },
412 { PPCM, "Digi_AccelePort_Xem_PCI" },
413 { APORT2_920P, "Digi_AccelePort_2r_920_PCI" },
414 { APORT4_920P, "Digi_AccelePort_4r_920_PCI" },
415 { APORT8_920P, "Digi_AccelePort_8r_920_PCI" },
416 { PAPORT4, "Digi_AccelePort_4r_PCI(EIA-232/RS-422)" },
417 { PAPORT8, "Digi_AccelePort_8r_PCI(EIA-232/RS-422)" },
419 { PCIINFO, "pciinfo" },
422 { CONC, "concentrator" },
432 { CONNECT, "connect" },
433 { METHOD, "method" },
434 { STATUS, "status" },
435 { CUSTOM, "Custom" },
441 { NPORTS, "nports" },
446 { ALTPIN, "altpin" },
447 { USEINTR, "useintr" },
448 { TTSIZ, "ttysize" },
450 { BSSIZ, "boardsize" },
451 { UNTSIZ, "schedsize" },
452 { F2SIZ, "f2200size" },
453 { VPSIZ, "vpixsize" },
457 /************************************************************************
459 * Driver load/unload functions
461 ************************************************************************/
466 * Module load. This is where it all starts.
468 static int dgap_init_module(void)
472 pr_info("%s, Digi International Part Number %s\n", DG_NAME, DG_PART);
478 rc = dgap_init_pci();
482 rc = dgap_create_driver_sysfiles(&dgap_driver);
486 dgap_driver_state = DRIVER_READY;
492 dgap_cleanup_module();
496 module_init(dgap_init_module);
501 static int dgap_start(void)
505 struct device *device;
508 * make sure that the globals are
509 * init'd before we do anything else
515 pr_info("For the tools package please visit http://www.digi.com\n");
518 * Register our base character device into the kernel.
522 * Register management/dpa devices
524 rc = register_chrdev(DIGI_DGAP_MAJOR, "dgap", &DgapBoardFops);
528 dgap_class = class_create(THIS_MODULE, "dgap_mgmt");
529 if (IS_ERR(dgap_class)) {
530 rc = PTR_ERR(dgap_class);
534 device = device_create(dgap_class, NULL,
535 MKDEV(DIGI_DGAP_MAJOR, 0),
537 if (IS_ERR(device)) {
538 rc = PTR_ERR(device);
542 /* Start the poller */
543 spin_lock_irqsave(&dgap_poll_lock, flags);
544 init_timer(&dgap_poll_timer);
545 dgap_poll_timer.function = dgap_poll_handler;
546 dgap_poll_timer.data = 0;
547 dgap_poll_time = jiffies + dgap_jiffies_from_ms(dgap_poll_tick);
548 dgap_poll_timer.expires = dgap_poll_time;
549 spin_unlock_irqrestore(&dgap_poll_lock, flags);
551 add_timer(&dgap_poll_timer);
556 class_destroy(dgap_class);
558 unregister_chrdev(DIGI_DGAP_MAJOR, "dgap");
563 * Register pci driver, and return how many boards we have.
565 static int dgap_init_pci(void)
567 return pci_register_driver(&dgap_driver);
570 /* returns count (>= 0), or negative on error */
571 static int dgap_init_one(struct pci_dev *pdev, const struct pci_device_id *ent)
575 /* wake up and enable device */
576 rc = pci_enable_device(pdev);
581 rc = dgap_probe1(pdev, ent->driver_data);
584 rc = dgap_firmware_load(pdev, ent->driver_data);
590 static int dgap_probe1(struct pci_dev *pdev, int card_type)
592 return dgap_found_board(pdev, card_type);
595 static void dgap_remove_one(struct pci_dev *dev)
601 * dgap_cleanup_module()
603 * Module unload. This is where it all ends.
605 static void dgap_cleanup_module(void)
610 spin_lock_irqsave(&dgap_poll_lock, lock_flags);
612 spin_unlock_irqrestore(&dgap_poll_lock, lock_flags);
614 /* Turn off poller right away. */
615 del_timer_sync(&dgap_poll_timer);
617 dgap_remove_driver_sysfiles(&dgap_driver);
619 device_destroy(dgap_class, MKDEV(DIGI_DGAP_MAJOR, 0));
620 class_destroy(dgap_class);
621 unregister_chrdev(DIGI_DGAP_MAJOR, "dgap");
623 for (i = 0; i < dgap_NumBoards; ++i) {
624 dgap_remove_ports_sysfiles(dgap_Board[i]);
625 dgap_tty_uninit(dgap_Board[i]);
626 dgap_cleanup_board(dgap_Board[i]);
630 pci_unregister_driver(&dgap_driver);
634 * dgap_cleanup_board()
636 * Free all the memory associated with a board
638 static void dgap_cleanup_board(struct board_t *brd)
642 if (!brd || brd->magic != DGAP_BOARD_MAGIC)
645 if (brd->intr_used && brd->irq)
646 free_irq(brd->irq, brd);
648 tasklet_kill(&brd->helper_tasklet);
650 if (brd->re_map_port) {
651 release_mem_region(brd->membase + 0x200000, 0x200000);
652 iounmap(brd->re_map_port);
653 brd->re_map_port = NULL;
656 if (brd->re_map_membase) {
657 release_mem_region(brd->membase, 0x200000);
658 iounmap(brd->re_map_membase);
659 brd->re_map_membase = NULL;
662 /* Free all allocated channels structs */
663 for (i = 0; i < MAXPORTS ; i++)
664 kfree(brd->channels[i]);
667 kfree(brd->flipflagbuf);
669 dgap_Board[brd->boardnum] = NULL;
677 * A board has been found, init it.
679 static int dgap_found_board(struct pci_dev *pdev, int id)
682 unsigned int pci_irq;
685 /* get the board structure and prep it */
686 brd = kzalloc(sizeof(struct board_t), GFP_KERNEL);
690 dgap_Board[dgap_NumBoards] = brd;
692 /* store the info for the board we've found */
693 brd->magic = DGAP_BOARD_MAGIC;
694 brd->boardnum = dgap_NumBoards;
696 brd->vendor = dgap_pci_tbl[id].vendor;
697 brd->device = dgap_pci_tbl[id].device;
699 brd->pci_bus = pdev->bus->number;
700 brd->pci_slot = PCI_SLOT(pdev->devfn);
701 brd->name = dgap_Ids[id].name;
702 brd->maxports = dgap_Ids[id].maxports;
703 brd->type = dgap_Ids[id].config_type;
704 brd->dpatype = dgap_Ids[id].dpatype;
705 brd->dpastatus = BD_NOFEP;
706 init_waitqueue_head(&brd->state_wait);
708 spin_lock_init(&brd->bd_lock);
711 brd->inhibit_poller = FALSE;
712 brd->wait_for_bios = 0;
713 brd->wait_for_fep = 0;
715 for (i = 0; i < MAXPORTS; i++)
716 brd->channels[i] = NULL;
718 /* store which card & revision we have */
719 pci_read_config_word(pdev, PCI_SUBSYSTEM_VENDOR_ID, &brd->subvendor);
720 pci_read_config_word(pdev, PCI_SUBSYSTEM_ID, &brd->subdevice);
721 pci_read_config_byte(pdev, PCI_REVISION_ID, &brd->rev);
726 /* get the PCI Base Address Registers */
728 /* Xr Jupiter and EPC use BAR 2 */
729 if (brd->device == PCI_DEV_XRJ_DID || brd->device == PCI_DEV_EPCJ_DID) {
730 brd->membase = pci_resource_start(pdev, 2);
731 brd->membase_end = pci_resource_end(pdev, 2);
733 /* Everyone else uses BAR 0 */
735 brd->membase = pci_resource_start(pdev, 0);
736 brd->membase_end = pci_resource_end(pdev, 0);
742 if (brd->membase & 1)
748 * On the PCI boards, there is no IO space allocated
749 * The I/O registers will be in the first 3 bytes of the
750 * upper 2MB of the 4MB memory space. The board memory
751 * will be mapped into the low 2MB of the 4MB memory space
753 brd->port = brd->membase + PCI_IO_OFFSET;
754 brd->port_end = brd->port + PCI_IO_SIZE;
757 * Special initialization for non-PLX boards
759 if (brd->device != PCI_DEV_XRJ_DID && brd->device != PCI_DEV_EPCJ_DID) {
762 pci_write_config_byte(pdev, 0x40, 0);
763 pci_write_config_byte(pdev, 0x46, 0);
765 /* Limit burst length to 2 doubleword transactions */
766 pci_write_config_byte(pdev, 0x42, 1);
769 * Enable IO and mem if not already done.
770 * This was needed for support on Itanium.
772 pci_read_config_word(pdev, PCI_COMMAND, &cmd);
773 cmd |= (PCI_COMMAND_IO | PCI_COMMAND_MEMORY);
774 pci_write_config_word(pdev, PCI_COMMAND, cmd);
777 /* init our poll helper tasklet */
778 tasklet_init(&brd->helper_tasklet, dgap_poll_tasklet,
779 (unsigned long) brd);
781 i = dgap_do_remap(brd);
783 brd->state = BOARD_FAILED;
785 pr_info("dgap: board %d: %s (rev %d), irq %ld\n",
786 dgap_NumBoards, brd->name, brd->rev, brd->irq);
792 static int dgap_finalize_board_init(struct board_t *brd)
796 if (!brd || brd->magic != DGAP_BOARD_MAGIC)
799 brd->use_interrupts = dgap_config_get_useintr(brd);
802 * Set up our interrupt handler if we are set to do interrupts.
804 if (brd->use_interrupts && brd->irq) {
806 rc = request_irq(brd->irq, dgap_intr, IRQF_SHARED, "DGAP", brd);
819 static int dgap_firmware_load(struct pci_dev *pdev, int card_type)
821 struct board_t *brd = dgap_Board[dgap_NumBoards - 1];
822 const struct firmware *fw;
826 dgap_do_reset_board(brd);
828 if ((fw_info[card_type].conf_name) && !dgap_config_buf) {
829 ret = request_firmware(&fw, fw_info[card_type].conf_name,
832 pr_err("dgap: config file %s not found\n",
833 fw_info[card_type].conf_name);
837 dgap_config_buf = kmalloc(fw->size + 1, GFP_KERNEL);
838 if (!dgap_config_buf) {
839 release_firmware(fw);
843 memcpy(dgap_config_buf, fw->data, fw->size);
844 release_firmware(fw);
845 dgap_config_buf[fw->size + 1] = '\0';
847 if (dgap_parsefile(&dgap_config_buf, TRUE) != 0) {
848 kfree(dgap_config_buf);
851 kfree(dgap_config_buf);
854 ret = dgap_after_config_loaded(brd->boardnum);
858 * Match this board to a config the user created for us.
861 dgap_find_config(brd->type, brd->pci_bus, brd->pci_slot);
864 * Because the 4 port Xr products share the same PCI ID
865 * as the 8 port Xr products, if we receive a NULL config
866 * back, and this is a PAPORT8 board, retry with a
867 * PAPORT4 attempt as well.
869 if (brd->type == PAPORT8 && !brd->bd_config)
871 dgap_find_config(PAPORT4, brd->pci_bus, brd->pci_slot);
873 if (!brd->bd_config) {
874 pr_err("dgap: No valid configuration found\n");
878 dgap_tty_register(brd);
879 dgap_finalize_board_init(brd);
881 if (fw_info[card_type].bios_name) {
882 ret = request_firmware(&fw, fw_info[card_type].bios_name,
885 pr_err("dgap: bios file %s not found\n",
886 fw_info[card_type].bios_name);
889 dgap_do_bios_load(brd, fw->data, fw->size);
890 release_firmware(fw);
892 /* Wait for BIOS to test board... */
893 ret = dgap_test_bios(brd);
898 if (fw_info[card_type].fep_name) {
899 ret = request_firmware(&fw, fw_info[card_type].fep_name,
902 pr_err("dgap: fep file %s not found\n",
903 fw_info[card_type].fep_name);
906 dgap_do_fep_load(brd, fw->data, fw->size);
907 release_firmware(fw);
909 /* Wait for FEP to load on board... */
910 ret = dgap_test_fep(brd);
915 #ifdef DIGI_CONCENTRATORS_SUPPORTED
917 * If this is a CX or EPCX, we need to see if the firmware
918 * is requesting a concentrator image from us.
920 if ((bd->type == PCX) || (bd->type == PEPC)) {
921 chk_addr = (u16 *) (vaddr + DOWNREQ);
922 /* Nonzero if FEP is requesting concentrator image. */
923 check = readw(chk_addr);
924 vaddr = brd->re_map_membase;
927 if (fw_info[card_type].con_name && check && vaddr) {
928 ret = request_firmware(&fw, fw_info[card_type].con_name,
931 pr_err("dgap: conc file %s not found\n",
932 fw_info[card_type].con_name);
935 /* Put concentrator firmware loading code here */
936 offset = readw((u16 *) (vaddr + DOWNREQ));
937 memcpy_toio(offset, fw->data, fw->size);
939 dgap_do_conc_load(brd, (char *)fw->data, fw->size)
940 release_firmware(fw);
944 * Do tty device initialization.
946 ret = dgap_tty_init(brd);
948 dgap_tty_uninit(brd);
952 ret = dgap_tty_register_ports(brd);
956 brd->state = BOARD_READY;
957 brd->dpastatus = BD_RUNNING;
965 static int dgap_do_remap(struct board_t *brd)
967 if (!brd || brd->magic != DGAP_BOARD_MAGIC)
970 if (!request_mem_region(brd->membase, 0x200000, "dgap"))
973 if (!request_mem_region(brd->membase + PCI_IO_OFFSET, 0x200000,
975 release_mem_region(brd->membase, 0x200000);
979 brd->re_map_membase = ioremap(brd->membase, 0x200000);
980 if (!brd->re_map_membase) {
981 release_mem_region(brd->membase, 0x200000);
982 release_mem_region(brd->membase + PCI_IO_OFFSET, 0x200000);
986 brd->re_map_port = ioremap((brd->membase + PCI_IO_OFFSET), 0x200000);
987 if (!brd->re_map_port) {
988 release_mem_region(brd->membase, 0x200000);
989 release_mem_region(brd->membase + PCI_IO_OFFSET, 0x200000);
990 iounmap(brd->re_map_membase);
997 /*****************************************************************************
1017 * As each timer expires, it determines (a) whether the "transmit"
1018 * waiter needs to be woken up, and (b) whether the poller needs to
1021 ******************************************************************************/
1023 static void dgap_poll_handler(ulong dummy)
1026 struct board_t *brd;
1027 unsigned long lock_flags;
1030 dgap_poll_counter++;
1033 * Do not start the board state machine until
1034 * driver tells us its up and running, and has
1035 * everything it needs.
1037 if (dgap_driver_state != DRIVER_READY)
1038 goto schedule_poller;
1041 * If we have just 1 board, or the system is not SMP,
1042 * then use the typical old style poller.
1043 * Otherwise, use our new tasklet based poller, which should
1044 * speed things up for multiple boards.
1046 if ((dgap_NumBoards == 1) || (num_online_cpus() <= 1)) {
1047 for (i = 0; i < dgap_NumBoards; i++) {
1049 brd = dgap_Board[i];
1051 if (brd->state == BOARD_FAILED)
1053 if (!brd->intr_running)
1054 /* Call the real board poller directly */
1055 dgap_poll_tasklet((unsigned long) brd);
1059 * Go thru each board, kicking off a
1060 * tasklet for each if needed
1062 for (i = 0; i < dgap_NumBoards; i++) {
1063 brd = dgap_Board[i];
1066 * Attempt to grab the board lock.
1068 * If we can't get it, no big deal, the next poll
1069 * will get it. Basically, I just really don't want
1070 * to spin in here, because I want to kick off my
1071 * tasklets as fast as I can, and then get out the
1074 if (!spin_trylock(&brd->bd_lock))
1078 * If board is in a failed state, don't bother
1079 * scheduling a tasklet
1081 if (brd->state == BOARD_FAILED) {
1082 spin_unlock(&brd->bd_lock);
1086 /* Schedule a poll helper task */
1087 if (!brd->intr_running)
1088 tasklet_schedule(&brd->helper_tasklet);
1091 * Can't do DGAP_UNLOCK here, as we don't have
1092 * lock_flags because we did a trylock above.
1094 spin_unlock(&brd->bd_lock);
1101 * Schedule ourself back at the nominal wakeup interval.
1103 spin_lock_irqsave(&dgap_poll_lock, lock_flags);
1104 dgap_poll_time += dgap_jiffies_from_ms(dgap_poll_tick);
1106 new_time = dgap_poll_time - jiffies;
1108 if ((ulong) new_time >= 2 * dgap_poll_tick) {
1110 jiffies + dgap_jiffies_from_ms(dgap_poll_tick);
1113 dgap_poll_timer.function = dgap_poll_handler;
1114 dgap_poll_timer.data = 0;
1115 dgap_poll_timer.expires = dgap_poll_time;
1116 spin_unlock_irqrestore(&dgap_poll_lock, lock_flags);
1118 if (!dgap_poll_stop)
1119 add_timer(&dgap_poll_timer);
1125 * Driver interrupt handler.
1127 static irqreturn_t dgap_intr(int irq, void *voidbrd)
1129 struct board_t *brd = (struct board_t *) voidbrd;
1135 * Check to make sure its for us.
1137 if (brd->magic != DGAP_BOARD_MAGIC)
1143 * Schedule tasklet to run at a better time.
1145 tasklet_schedule(&brd->helper_tasklet);
1150 * dgap_init_globals()
1152 * This is where we initialize the globals from the static insmod
1153 * configuration variables. These are declared near the head of
1156 static void dgap_init_globals(void)
1160 for (i = 0; i < MAXBOARDS; i++)
1161 dgap_Board[i] = NULL;
1163 init_timer(&dgap_poll_timer);
1165 init_waitqueue_head(&dgap_dl_wait);
1168 /************************************************************************
1172 ************************************************************************/
1177 * Put the driver to sleep for x ms's
1179 * Returns 0 if timed out, !0 (showing signal) if interrupted by a signal.
1181 static int dgap_ms_sleep(ulong ms)
1183 current->state = TASK_INTERRUPTIBLE;
1184 schedule_timeout((ms * HZ) / 1000);
1185 return signal_pending(current);
1188 /************************************************************************
1190 * TTY Initialization/Cleanup Functions
1192 ************************************************************************/
1195 * dgap_tty_register()
1197 * Init the tty subsystem for this board.
1199 static int dgap_tty_register(struct board_t *brd)
1203 brd->SerialDriver = alloc_tty_driver(MAXPORTS);
1205 snprintf(brd->SerialName, MAXTTYNAMELEN, "tty_dgap_%d_", brd->boardnum);
1206 brd->SerialDriver->name = brd->SerialName;
1207 brd->SerialDriver->name_base = 0;
1208 brd->SerialDriver->major = 0;
1209 brd->SerialDriver->minor_start = 0;
1210 brd->SerialDriver->type = TTY_DRIVER_TYPE_SERIAL;
1211 brd->SerialDriver->subtype = SERIAL_TYPE_NORMAL;
1212 brd->SerialDriver->init_termios = DgapDefaultTermios;
1213 brd->SerialDriver->driver_name = DRVSTR;
1214 brd->SerialDriver->flags = (TTY_DRIVER_REAL_RAW |
1215 TTY_DRIVER_DYNAMIC_DEV |
1216 TTY_DRIVER_HARDWARE_BREAK);
1218 /* The kernel wants space to store pointers to tty_structs */
1219 brd->SerialDriver->ttys =
1220 kzalloc(MAXPORTS * sizeof(struct tty_struct *), GFP_KERNEL);
1221 if (!brd->SerialDriver->ttys)
1225 * Entry points for driver. Called by the kernel from
1226 * tty_io.c and n_tty.c.
1228 tty_set_operations(brd->SerialDriver, &dgap_tty_ops);
1231 * If we're doing transparent print, we have to do all of the above
1232 * again, separately so we don't get the LD confused about what major
1233 * we are when we get into the dgap_tty_open() routine.
1235 brd->PrintDriver = alloc_tty_driver(MAXPORTS);
1237 snprintf(brd->PrintName, MAXTTYNAMELEN, "pr_dgap_%d_", brd->boardnum);
1238 brd->PrintDriver->name = brd->PrintName;
1239 brd->PrintDriver->name_base = 0;
1240 brd->PrintDriver->major = 0;
1241 brd->PrintDriver->minor_start = 0;
1242 brd->PrintDriver->type = TTY_DRIVER_TYPE_SERIAL;
1243 brd->PrintDriver->subtype = SERIAL_TYPE_NORMAL;
1244 brd->PrintDriver->init_termios = DgapDefaultTermios;
1245 brd->PrintDriver->driver_name = DRVSTR;
1246 brd->PrintDriver->flags = (TTY_DRIVER_REAL_RAW |
1247 TTY_DRIVER_DYNAMIC_DEV |
1248 TTY_DRIVER_HARDWARE_BREAK);
1250 /* The kernel wants space to store pointers to tty_structs */
1251 brd->PrintDriver->ttys =
1252 kzalloc(MAXPORTS * sizeof(struct tty_struct *), GFP_KERNEL);
1253 if (!brd->PrintDriver->ttys)
1257 * Entry points for driver. Called by the kernel from
1258 * tty_io.c and n_tty.c.
1260 tty_set_operations(brd->PrintDriver, &dgap_tty_ops);
1262 if (!brd->dgap_Major_Serial_Registered) {
1263 /* Register tty devices */
1264 rc = tty_register_driver(brd->SerialDriver);
1267 brd->dgap_Major_Serial_Registered = TRUE;
1268 dgap_BoardsByMajor[brd->SerialDriver->major] = brd;
1269 brd->dgap_Serial_Major = brd->SerialDriver->major;
1272 if (!brd->dgap_Major_TransparentPrint_Registered) {
1273 /* Register Transparent Print devices */
1274 rc = tty_register_driver(brd->PrintDriver);
1277 brd->dgap_Major_TransparentPrint_Registered = TRUE;
1278 dgap_BoardsByMajor[brd->PrintDriver->major] = brd;
1279 brd->dgap_TransparentPrint_Major = brd->PrintDriver->major;
1288 * Init the tty subsystem. Called once per board after board has been
1289 * downloaded and init'ed.
1291 static int dgap_tty_init(struct board_t *brd)
1295 uint true_count = 0;
1298 struct channel_t *ch;
1306 * Initialize board structure elements.
1309 vaddr = brd->re_map_membase;
1310 true_count = readw((vaddr + NCHAN));
1312 brd->nasync = dgap_config_get_num_prts(brd);
1315 brd->nasync = brd->maxports;
1317 if (brd->nasync > brd->maxports)
1318 brd->nasync = brd->maxports;
1320 if (true_count != brd->nasync) {
1321 if ((brd->type == PPCM) && (true_count == 64)) {
1322 pr_warn("dgap: %s configured for %d ports, has %d ports.\n",
1323 brd->name, brd->nasync, true_count);
1324 pr_warn("dgap: Please make SURE the EBI cable running from the card\n");
1325 pr_warn("dgap: to each EM module is plugged into EBI IN!\n");
1326 } else if ((brd->type == PPCM) && (true_count == 0)) {
1327 pr_warn("dgap: %s configured for %d ports, has %d ports.\n",
1328 brd->name, brd->nasync, true_count);
1329 pr_warn("dgap: Please make SURE the EBI cable running from the card\n");
1330 pr_warn("dgap: to each EM module is plugged into EBI IN!\n");
1332 pr_warn("dgap: %s configured for %d ports, has %d ports.\n",
1333 brd->name, brd->nasync, true_count);
1335 brd->nasync = true_count;
1337 /* If no ports, don't bother going any further */
1339 brd->state = BOARD_FAILED;
1340 brd->dpastatus = BD_NOFEP;
1346 * Allocate channel memory that might not have been allocated
1347 * when the driver was first loaded.
1349 for (i = 0; i < brd->nasync; i++) {
1350 if (!brd->channels[i]) {
1352 kzalloc(sizeof(struct channel_t), GFP_ATOMIC);
1353 if (!brd->channels[i])
1358 ch = brd->channels[0];
1359 vaddr = brd->re_map_membase;
1361 bs = (struct bs_t *) ((ulong) vaddr + CHANBUF);
1362 cm = (struct cm_t *) ((ulong) vaddr + CMDBUF);
1366 /* Set up channel variables */
1367 for (i = 0; i < brd->nasync; i++, ch = brd->channels[i], bs++) {
1369 if (!brd->channels[i])
1372 spin_lock_init(&ch->ch_lock);
1374 /* Store all our magic numbers */
1375 ch->magic = DGAP_CHANNEL_MAGIC;
1376 ch->ch_tun.magic = DGAP_UNIT_MAGIC;
1377 ch->ch_tun.un_type = DGAP_SERIAL;
1378 ch->ch_tun.un_ch = ch;
1379 ch->ch_tun.un_dev = i;
1381 ch->ch_pun.magic = DGAP_UNIT_MAGIC;
1382 ch->ch_pun.un_type = DGAP_PRINT;
1383 ch->ch_pun.un_ch = ch;
1384 ch->ch_pun.un_dev = i;
1386 ch->ch_vaddr = vaddr;
1391 ch->ch_digi = dgap_digi_init;
1394 * Set up digi dsr and dcd bits based on altpin flag.
1396 if (dgap_config_get_altpin(brd)) {
1399 ch->ch_digi.digi_flags |= DIGI_ALTPIN;
1402 ch->ch_dsr = DM_DSR;
1405 ch->ch_taddr = vaddr + ((ch->ch_bs->tx_seg) << 4);
1406 ch->ch_raddr = vaddr + ((ch->ch_bs->rx_seg) << 4);
1409 ch->ch_tsize = readw(&(ch->ch_bs->tx_max)) + 1;
1410 ch->ch_rsize = readw(&(ch->ch_bs->rx_max)) + 1;
1414 /* .25 second delay */
1415 ch->ch_close_delay = 250;
1418 * Set queue water marks, interrupt mask,
1419 * and general tty parameters.
1421 tlw = ch->ch_tsize >= 2000 ? ((ch->ch_tsize * 5) / 8) :
1425 dgap_cmdw(ch, STLOW, tlw, 0);
1427 dgap_cmdw(ch, SRLOW, ch->ch_rsize / 2, 0);
1429 dgap_cmdw(ch, SRHIGH, 7 * ch->ch_rsize / 8, 0);
1431 ch->ch_mistat = readb(&(ch->ch_bs->m_stat));
1433 init_waitqueue_head(&ch->ch_flags_wait);
1434 init_waitqueue_head(&ch->ch_tun.un_flags_wait);
1435 init_waitqueue_head(&ch->ch_pun.un_flags_wait);
1436 init_waitqueue_head(&ch->ch_sniff_wait);
1438 /* Turn on all modem interrupts for now */
1439 modem = (DM_CD | DM_DSR | DM_CTS | DM_RI);
1440 writeb(modem, &(ch->ch_bs->m_int));
1443 * Set edelay to 0 if interrupts are turned on,
1444 * otherwise set edelay to the usual 100.
1447 writew(0, &(ch->ch_bs->edelay));
1449 writew(100, &(ch->ch_bs->edelay));
1451 writeb(1, &(ch->ch_bs->idata));
1460 * Uninitialize the TTY portion of this driver. Free all memory and
1463 static void dgap_tty_uninit(struct board_t *brd)
1468 if (brd->dgap_Major_Serial_Registered) {
1469 dgap_BoardsByMajor[brd->SerialDriver->major] = NULL;
1470 brd->dgap_Serial_Major = 0;
1471 for (i = 0; i < brd->nasync; i++) {
1472 tty_port_destroy(&brd->SerialPorts[i]);
1473 dev = brd->channels[i]->ch_tun.un_sysfs;
1474 dgap_remove_tty_sysfs(dev);
1475 tty_unregister_device(brd->SerialDriver, i);
1477 tty_unregister_driver(brd->SerialDriver);
1478 kfree(brd->SerialDriver->ttys);
1479 brd->SerialDriver->ttys = NULL;
1480 put_tty_driver(brd->SerialDriver);
1481 kfree(brd->SerialPorts);
1482 brd->dgap_Major_Serial_Registered = FALSE;
1485 if (brd->dgap_Major_TransparentPrint_Registered) {
1486 dgap_BoardsByMajor[brd->PrintDriver->major] = NULL;
1487 brd->dgap_TransparentPrint_Major = 0;
1488 for (i = 0; i < brd->nasync; i++) {
1489 tty_port_destroy(&brd->PrinterPorts[i]);
1490 dev = brd->channels[i]->ch_pun.un_sysfs;
1491 dgap_remove_tty_sysfs(dev);
1492 tty_unregister_device(brd->PrintDriver, i);
1494 tty_unregister_driver(brd->PrintDriver);
1495 kfree(brd->PrintDriver->ttys);
1496 brd->PrintDriver->ttys = NULL;
1497 put_tty_driver(brd->PrintDriver);
1498 kfree(brd->PrinterPorts);
1499 brd->dgap_Major_TransparentPrint_Registered = FALSE;
1503 #define TMPBUFLEN (1024)
1505 * dgap_sniff - Dump data out to the "sniff" buffer if the
1506 * proc sniff file is opened...
1508 static void dgap_sniff_nowait_nolock(struct channel_t *ch, u8 *text,
1517 char tmpbuf[TMPBUFLEN];
1521 /* Leave if sniff not open */
1522 if (!(ch->ch_sniff_flags & SNIFF_OPEN))
1525 do_gettimeofday(&tv);
1527 /* Create our header for data dump */
1528 p += sprintf(p, "<%ld %ld><%s><", tv.tv_sec, tv.tv_usec, text);
1529 tmpbuflen = p - tmpbuf;
1534 for (i = 0; i < len && tmpbuflen < (TMPBUFLEN - 4); i++) {
1535 p += sprintf(p, "%02x ", *buf);
1537 tmpbuflen = p - tmpbuf;
1540 if (tmpbuflen < (TMPBUFLEN - 4)) {
1542 p += sprintf(p - 1, "%s\n", ">");
1544 p += sprintf(p, "%s\n", ">");
1550 nbuf = strlen(tmpbuf);
1554 * Loop while data remains.
1556 while (nbuf > 0 && ch->ch_sniff_buf) {
1558 * Determine the amount of available space left in the
1559 * buffer. If there's none, wait until some appears.
1561 n = (ch->ch_sniff_out - ch->ch_sniff_in - 1) &
1565 * If there is no space left to write to in our sniff
1566 * buffer, we have no choice but to drop the data.
1567 * We *cannot* sleep here waiting for space, because
1568 * this function was probably called by the
1569 * interrupt/timer routines!
1575 * Copy as much data as will fit.
1581 r = SNIFF_MAX - ch->ch_sniff_in;
1584 memcpy(ch->ch_sniff_buf +
1585 ch->ch_sniff_in, p, r);
1588 ch->ch_sniff_in = 0;
1593 memcpy(ch->ch_sniff_buf + ch->ch_sniff_in, p, n);
1595 ch->ch_sniff_in += n;
1600 * Wakeup any thread waiting for data
1602 if (ch->ch_sniff_flags & SNIFF_WAIT_DATA) {
1603 ch->ch_sniff_flags &= ~SNIFF_WAIT_DATA;
1604 wake_up_interruptible(&ch->ch_sniff_wait);
1609 * If the user sent us too much data to push into our tmpbuf,
1610 * we need to keep looping around on all the data.
1612 if (too_much_data) {
1617 } while (too_much_data);
1620 /*=======================================================================
1622 * dgap_input - Process received data.
1624 * ch - Pointer to channel structure.
1626 *=======================================================================*/
1628 static void dgap_input(struct channel_t *ch)
1632 struct tty_struct *tp;
1633 struct tty_ldisc *ld;
1647 if (!ch || ch->magic != DGAP_CHANNEL_MAGIC)
1650 tp = ch->ch_tun.un_tty;
1657 if (!bd || bd->magic != DGAP_BOARD_MAGIC)
1660 spin_lock_irqsave(&bd->bd_lock, lock_flags);
1661 spin_lock_irqsave(&ch->ch_lock, lock_flags2);
1664 * Figure the number of characters in the buffer.
1665 * Exit immediately if none.
1668 rmask = ch->ch_rsize - 1;
1670 head = readw(&(bs->rx_head));
1672 tail = readw(&(bs->rx_tail));
1675 data_len = (head - tail) & rmask;
1677 if (data_len == 0) {
1678 writeb(1, &(bs->idata));
1679 spin_unlock_irqrestore(&ch->ch_lock, lock_flags2);
1680 spin_unlock_irqrestore(&bd->bd_lock, lock_flags);
1685 * If the device is not open, or CREAD is off, flush
1686 * input data and return immediately.
1688 if ((bd->state != BOARD_READY) || !tp ||
1689 (tp->magic != TTY_MAGIC) ||
1690 !(ch->ch_tun.un_flags & UN_ISOPEN) ||
1691 !(tp->termios.c_cflag & CREAD) ||
1692 (ch->ch_tun.un_flags & UN_CLOSING)) {
1694 writew(head, &(bs->rx_tail));
1695 writeb(1, &(bs->idata));
1696 spin_unlock_irqrestore(&ch->ch_lock, lock_flags2);
1697 spin_unlock_irqrestore(&bd->bd_lock, lock_flags);
1702 * If we are throttled, simply don't read any data.
1704 if (ch->ch_flags & CH_RXBLOCK) {
1705 writeb(1, &(bs->idata));
1706 spin_unlock_irqrestore(&ch->ch_lock, lock_flags2);
1707 spin_unlock_irqrestore(&bd->bd_lock, lock_flags);
1714 tmpchar = readb(&(bs->orun));
1716 ch->ch_err_overrun++;
1717 writeb(0, &(bs->orun));
1720 /* Decide how much data we can send into the tty layer */
1721 flip_len = TTY_FLIPBUF_SIZE;
1723 /* Chop down the length, if needed */
1724 len = min(data_len, flip_len);
1725 len = min(len, (N_TTY_BUF_SIZE - 1));
1727 ld = tty_ldisc_ref(tp);
1729 #ifdef TTY_DONT_FLIP
1731 * If the DONT_FLIP flag is on, don't flush our buffer, and act
1732 * like the ld doesn't have any space to put the data right now.
1734 if (test_bit(TTY_DONT_FLIP, &tp->flags))
1739 * If we were unable to get a reference to the ld,
1740 * don't flush our buffer, and act like the ld doesn't
1741 * have any space to put the data right now.
1747 * If ld doesn't have a pointer to a receive_buf function,
1748 * flush the data, then act like the ld doesn't have any
1749 * space to put the data right now.
1751 if (!ld->ops->receive_buf) {
1752 writew(head, &(bs->rx_tail));
1758 writeb(1, &(bs->idata));
1759 spin_unlock_irqrestore(&ch->ch_lock, lock_flags2);
1760 spin_unlock_irqrestore(&bd->bd_lock, lock_flags);
1762 tty_ldisc_deref(ld);
1766 buf = ch->ch_bd->flipbuf;
1770 * n now contains the most amount of data we can copy,
1771 * bounded either by our buffer size or the amount
1772 * of data the card actually has pending...
1776 s = ((head >= tail) ? head : ch->ch_rsize) - tail;
1782 memcpy_fromio(buf, (char *) ch->ch_raddr + tail, s);
1783 dgap_sniff_nowait_nolock(ch, "USER READ", buf, s);
1789 /* Flip queue if needed */
1793 writew(tail, &(bs->rx_tail));
1794 writeb(1, &(bs->idata));
1795 ch->ch_rxcount += len;
1798 * If we are completely raw, we don't need to go through a lot
1799 * of the tty layers that exist.
1800 * In this case, we take the shortest and fastest route we
1801 * can to relay the data to the user.
1803 * On the other hand, if we are not raw, we need to go through
1804 * the tty layer, which has its API more well defined.
1806 if (I_PARMRK(tp) || I_BRKINT(tp) || I_INPCK(tp)) {
1807 dgap_parity_scan(ch, ch->ch_bd->flipbuf,
1808 ch->ch_bd->flipflagbuf, &len);
1810 len = tty_buffer_request_room(tp->port, len);
1811 tty_insert_flip_string_flags(tp->port, ch->ch_bd->flipbuf,
1812 ch->ch_bd->flipflagbuf, len);
1814 len = tty_buffer_request_room(tp->port, len);
1815 tty_insert_flip_string(tp->port, ch->ch_bd->flipbuf, len);
1818 spin_unlock_irqrestore(&ch->ch_lock, lock_flags2);
1819 spin_unlock_irqrestore(&bd->bd_lock, lock_flags);
1821 /* Tell the tty layer its okay to "eat" the data now */
1822 tty_flip_buffer_push(tp->port);
1825 tty_ldisc_deref(ld);
1829 /************************************************************************
1830 * Determines when CARRIER changes state and takes appropriate
1832 ************************************************************************/
1833 static void dgap_carrier(struct channel_t *ch)
1837 int virt_carrier = 0;
1838 int phys_carrier = 0;
1840 if (!ch || ch->magic != DGAP_CHANNEL_MAGIC)
1845 if (!bd || bd->magic != DGAP_BOARD_MAGIC)
1848 /* Make sure altpin is always set correctly */
1849 if (ch->ch_digi.digi_flags & DIGI_ALTPIN) {
1853 ch->ch_dsr = DM_DSR;
1857 if (ch->ch_mistat & D_CD(ch))
1860 if (ch->ch_digi.digi_flags & DIGI_FORCEDCD)
1863 if (ch->ch_c_cflag & CLOCAL)
1867 * Test for a VIRTUAL carrier transition to HIGH.
1869 if (((ch->ch_flags & CH_FCAR) == 0) && (virt_carrier == 1)) {
1872 * When carrier rises, wake any threads waiting
1873 * for carrier in the open routine.
1876 if (waitqueue_active(&(ch->ch_flags_wait)))
1877 wake_up_interruptible(&ch->ch_flags_wait);
1881 * Test for a PHYSICAL carrier transition to HIGH.
1883 if (((ch->ch_flags & CH_CD) == 0) && (phys_carrier == 1)) {
1886 * When carrier rises, wake any threads waiting
1887 * for carrier in the open routine.
1890 if (waitqueue_active(&(ch->ch_flags_wait)))
1891 wake_up_interruptible(&ch->ch_flags_wait);
1895 * Test for a PHYSICAL transition to low, so long as we aren't
1896 * currently ignoring physical transitions (which is what "virtual
1897 * carrier" indicates).
1899 * The transition of the virtual carrier to low really doesn't
1900 * matter... it really only means "ignore carrier state", not
1901 * "make pretend that carrier is there".
1903 if ((virt_carrier == 0) &&
1904 ((ch->ch_flags & CH_CD) != 0) &&
1905 (phys_carrier == 0)) {
1908 * When carrier drops:
1910 * Drop carrier on all open units.
1912 * Flush queues, waking up any task waiting in the
1915 * Send a hangup to the control terminal.
1917 * Enable all select calls.
1919 if (waitqueue_active(&(ch->ch_flags_wait)))
1920 wake_up_interruptible(&ch->ch_flags_wait);
1922 if (ch->ch_tun.un_open_count > 0)
1923 tty_hangup(ch->ch_tun.un_tty);
1925 if (ch->ch_pun.un_open_count > 0)
1926 tty_hangup(ch->ch_pun.un_tty);
1930 * Make sure that our cached values reflect the current reality.
1932 if (virt_carrier == 1)
1933 ch->ch_flags |= CH_FCAR;
1935 ch->ch_flags &= ~CH_FCAR;
1937 if (phys_carrier == 1)
1938 ch->ch_flags |= CH_CD;
1940 ch->ch_flags &= ~CH_CD;
1943 /************************************************************************
1945 * TTY Entry points and helper functions
1947 ************************************************************************/
1953 static int dgap_tty_open(struct tty_struct *tty, struct file *file)
1955 struct board_t *brd;
1956 struct channel_t *ch;
1968 major = MAJOR(tty_devnum(tty));
1969 minor = MINOR(tty_devnum(tty));
1974 /* Get board pointer from our array of majors we have allocated */
1975 brd = dgap_BoardsByMajor[major];
1980 * If board is not yet up to a state of READY, go to
1981 * sleep waiting for it to happen or they cancel the open.
1983 rc = wait_event_interruptible(brd->state_wait,
1984 (brd->state & BOARD_READY));
1989 spin_lock_irqsave(&brd->bd_lock, lock_flags);
1991 /* The wait above should guarantee this cannot happen */
1992 if (brd->state != BOARD_READY) {
1993 spin_unlock_irqrestore(&brd->bd_lock, lock_flags);
1997 /* If opened device is greater than our number of ports, bail. */
1998 if (MINOR(tty_devnum(tty)) > brd->nasync) {
1999 spin_unlock_irqrestore(&brd->bd_lock, lock_flags);
2003 ch = brd->channels[minor];
2005 spin_unlock_irqrestore(&brd->bd_lock, lock_flags);
2009 /* Grab channel lock */
2010 spin_lock_irqsave(&ch->ch_lock, lock_flags2);
2012 /* Figure out our type */
2013 if (major == brd->dgap_Serial_Major) {
2014 un = &brd->channels[minor]->ch_tun;
2015 un->un_type = DGAP_SERIAL;
2016 } else if (major == brd->dgap_TransparentPrint_Major) {
2017 un = &brd->channels[minor]->ch_pun;
2018 un->un_type = DGAP_PRINT;
2020 spin_unlock_irqrestore(&ch->ch_lock, lock_flags2);
2021 spin_unlock_irqrestore(&brd->bd_lock, lock_flags);
2025 /* Store our unit into driver_data, so we always have it available. */
2026 tty->driver_data = un;
2029 * Error if channel info pointer is NULL.
2033 spin_unlock_irqrestore(&ch->ch_lock, lock_flags2);
2034 spin_unlock_irqrestore(&brd->bd_lock, lock_flags);
2041 if (!(un->un_flags & UN_ISOPEN)) {
2042 /* Store important variables. */
2045 /* Maybe do something here to the TTY struct as well? */
2049 * Initialize if neither terminal or printer is open.
2051 if (!((ch->ch_tun.un_flags | ch->ch_pun.un_flags) & UN_ISOPEN)) {
2057 * Flush input queue.
2059 head = readw(&(bs->rx_head));
2060 writew(head, &(bs->rx_tail));
2063 ch->pscan_state = 0;
2064 ch->pscan_savechar = 0;
2066 ch->ch_c_cflag = tty->termios.c_cflag;
2067 ch->ch_c_iflag = tty->termios.c_iflag;
2068 ch->ch_c_oflag = tty->termios.c_oflag;
2069 ch->ch_c_lflag = tty->termios.c_lflag;
2070 ch->ch_startc = tty->termios.c_cc[VSTART];
2071 ch->ch_stopc = tty->termios.c_cc[VSTOP];
2073 /* TODO: flush our TTY struct here? */
2078 * Run param in case we changed anything
2083 * follow protocol for opening port
2086 spin_unlock_irqrestore(&ch->ch_lock, lock_flags2);
2087 spin_unlock_irqrestore(&brd->bd_lock, lock_flags);
2089 rc = dgap_block_til_ready(tty, file, ch);
2094 /* No going back now, increment our unit and channel counters */
2095 spin_lock_irqsave(&ch->ch_lock, lock_flags);
2096 ch->ch_open_count++;
2097 un->un_open_count++;
2098 un->un_flags |= (UN_ISOPEN);
2099 spin_unlock_irqrestore(&ch->ch_lock, lock_flags);
2105 * dgap_block_til_ready()
2107 * Wait for DCD, if needed.
2109 static int dgap_block_til_ready(struct tty_struct *tty, struct file *file,
2110 struct channel_t *ch)
2113 struct un_t *un = NULL;
2116 int sleep_on_un_flags = 0;
2118 if (!tty || tty->magic != TTY_MAGIC || !file || !ch ||
2119 ch->magic != DGAP_CHANNEL_MAGIC)
2122 un = tty->driver_data;
2123 if (!un || un->magic != DGAP_UNIT_MAGIC)
2126 spin_lock_irqsave(&ch->ch_lock, lock_flags);
2133 sleep_on_un_flags = 0;
2136 * If board has failed somehow during our sleep,
2139 if (ch->ch_bd->state == BOARD_FAILED) {
2144 /* If tty was hung up, break out of loop and set error. */
2145 if (tty_hung_up_p(file)) {
2151 * If either unit is in the middle of the fragile part of close,
2152 * we just cannot touch the channel safely.
2153 * Go back to sleep, knowing that when the channel can be
2154 * touched safely, the close routine will signal the
2155 * ch_wait_flags to wake us back up.
2157 if (!((ch->ch_tun.un_flags | ch->ch_pun.un_flags) &
2161 * Our conditions to leave cleanly and happily:
2162 * 1) NONBLOCKING on the tty is set.
2164 * 3) DCD (fake or real) is active.
2167 if (file->f_flags & O_NONBLOCK)
2170 if (tty->flags & (1 << TTY_IO_ERROR))
2173 if (ch->ch_flags & CH_CD)
2176 if (ch->ch_flags & CH_FCAR)
2179 sleep_on_un_flags = 1;
2183 * If there is a signal pending, the user probably
2184 * interrupted (ctrl-c) us.
2185 * Leave loop with error set.
2187 if (signal_pending(current)) {
2188 retval = -ERESTARTSYS;
2193 * Store the flags before we let go of channel lock
2195 if (sleep_on_un_flags)
2196 old_flags = ch->ch_tun.un_flags | ch->ch_pun.un_flags;
2198 old_flags = ch->ch_flags;
2201 * Let go of channel lock before calling schedule.
2202 * Our poller will get any FEP events and wake us up when DCD
2203 * eventually goes active.
2206 spin_unlock_irqrestore(&ch->ch_lock, lock_flags);
2209 * Wait for something in the flags to change
2210 * from the current value.
2212 if (sleep_on_un_flags) {
2213 retval = wait_event_interruptible(un->un_flags_wait,
2214 (old_flags != (ch->ch_tun.un_flags |
2215 ch->ch_pun.un_flags)));
2217 retval = wait_event_interruptible(ch->ch_flags_wait,
2218 (old_flags != ch->ch_flags));
2222 * We got woken up for some reason.
2223 * Before looping around, grab our channel lock.
2225 spin_lock_irqsave(&ch->ch_lock, lock_flags);
2230 spin_unlock_irqrestore(&ch->ch_lock, lock_flags);
2241 * Hangup the port. Like a close, but don't wait for output to drain.
2243 static void dgap_tty_hangup(struct tty_struct *tty)
2246 struct channel_t *ch;
2249 if (!tty || tty->magic != TTY_MAGIC)
2252 un = tty->driver_data;
2253 if (!un || un->magic != DGAP_UNIT_MAGIC)
2257 if (!ch || ch->magic != DGAP_CHANNEL_MAGIC)
2261 if (!bd || bd->magic != DGAP_BOARD_MAGIC)
2264 /* flush the transmit queues */
2265 dgap_tty_flush_buffer(tty);
2273 static void dgap_tty_close(struct tty_struct *tty, struct file *file)
2275 struct ktermios *ts;
2277 struct channel_t *ch;
2282 if (!tty || tty->magic != TTY_MAGIC)
2285 un = tty->driver_data;
2286 if (!un || un->magic != DGAP_UNIT_MAGIC)
2290 if (!ch || ch->magic != DGAP_CHANNEL_MAGIC)
2294 if (!bd || bd->magic != DGAP_BOARD_MAGIC)
2299 spin_lock_irqsave(&ch->ch_lock, lock_flags);
2302 * Determine if this is the last close or not - and if we agree about
2303 * which type of close it is with the Line Discipline
2305 if ((tty->count == 1) && (un->un_open_count != 1)) {
2307 * Uh, oh. tty->count is 1, which means that the tty
2308 * structure will be freed. un_open_count should always
2309 * be one in these conditions. If it's greater than
2310 * one, we've got real problems, since it means the
2311 * serial port won't be shutdown.
2313 un->un_open_count = 1;
2316 if (--un->un_open_count < 0)
2317 un->un_open_count = 0;
2319 ch->ch_open_count--;
2321 if (ch->ch_open_count && un->un_open_count) {
2322 spin_unlock_irqrestore(&ch->ch_lock, lock_flags);
2326 /* OK, its the last close on the unit */
2328 un->un_flags |= UN_CLOSING;
2333 * Only officially close channel if count is 0 and
2334 * DIGI_PRINTER bit is not set.
2336 if ((ch->ch_open_count == 0) &&
2337 !(ch->ch_digi.digi_flags & DIGI_PRINTER)) {
2339 ch->ch_flags &= ~(CH_RXBLOCK);
2341 spin_unlock_irqrestore(&ch->ch_lock, lock_flags);
2343 /* wait for output to drain */
2344 /* This will also return if we take an interrupt */
2346 rc = dgap_wait_for_drain(tty);
2348 dgap_tty_flush_buffer(tty);
2349 tty_ldisc_flush(tty);
2351 spin_lock_irqsave(&ch->ch_lock, lock_flags);
2356 * If we have HUPCL set, lower DTR and RTS
2358 if (ch->ch_c_cflag & HUPCL) {
2359 ch->ch_mostat &= ~(D_RTS(ch)|D_DTR(ch));
2360 dgap_cmdb(ch, SMODEM, 0, D_DTR(ch)|D_RTS(ch), 0);
2363 * Go to sleep to ensure RTS/DTR
2364 * have been dropped for modems to see it.
2366 if (ch->ch_close_delay) {
2367 spin_unlock_irqrestore(&ch->ch_lock,
2369 dgap_ms_sleep(ch->ch_close_delay);
2370 spin_lock_irqsave(&ch->ch_lock, lock_flags);
2374 ch->pscan_state = 0;
2375 ch->pscan_savechar = 0;
2376 ch->ch_baud_info = 0;
2381 * turn off print device when closing print device.
2383 if ((un->un_type == DGAP_PRINT) && (ch->ch_flags & CH_PRON)) {
2384 dgap_wmove(ch, ch->ch_digi.digi_offstr,
2385 (int) ch->ch_digi.digi_offlen);
2386 ch->ch_flags &= ~CH_PRON;
2390 un->un_flags &= ~(UN_ISOPEN | UN_CLOSING);
2391 tty->driver_data = NULL;
2393 wake_up_interruptible(&ch->ch_flags_wait);
2394 wake_up_interruptible(&un->un_flags_wait);
2396 spin_unlock_irqrestore(&ch->ch_lock, lock_flags);
2400 * dgap_tty_chars_in_buffer()
2402 * Return number of characters that have not been transmitted yet.
2404 * This routine is used by the line discipline to determine if there
2405 * is data waiting to be transmitted/drained/flushed or not.
2407 static int dgap_tty_chars_in_buffer(struct tty_struct *tty)
2409 struct board_t *bd = NULL;
2410 struct channel_t *ch = NULL;
2411 struct un_t *un = NULL;
2412 struct bs_t *bs = NULL;
2415 u16 thead, ttail, tmask, chead, ctail;
2416 ulong lock_flags = 0;
2417 ulong lock_flags2 = 0;
2422 un = tty->driver_data;
2423 if (!un || un->magic != DGAP_UNIT_MAGIC)
2427 if (!ch || ch->magic != DGAP_CHANNEL_MAGIC)
2431 if (!bd || bd->magic != DGAP_BOARD_MAGIC)
2438 spin_lock_irqsave(&bd->bd_lock, lock_flags);
2439 spin_lock_irqsave(&ch->ch_lock, lock_flags2);
2441 tmask = (ch->ch_tsize - 1);
2443 /* Get Transmit queue pointers */
2444 thead = readw(&(bs->tx_head)) & tmask;
2445 ttail = readw(&(bs->tx_tail)) & tmask;
2447 /* Get tbusy flag */
2448 tbusy = readb(&(bs->tbusy));
2450 /* Get Command queue pointers */
2451 chead = readw(&(ch->ch_cm->cm_head));
2452 ctail = readw(&(ch->ch_cm->cm_tail));
2454 spin_unlock_irqrestore(&ch->ch_lock, lock_flags2);
2455 spin_unlock_irqrestore(&bd->bd_lock, lock_flags);
2458 * The only way we know for sure if there is no pending
2459 * data left to be transferred, is if:
2460 * 1) Transmit head and tail are equal (empty).
2461 * 2) Command queue head and tail are equal (empty).
2462 * 3) The "TBUSY" flag is 0. (Transmitter not busy).
2465 if ((ttail == thead) && (tbusy == 0) && (chead == ctail)) {
2469 chars = thead - ttail;
2471 chars = thead - ttail + ch->ch_tsize;
2473 * Fudge factor here.
2474 * If chars is zero, we know that the command queue had
2475 * something in it or tbusy was set. Because we cannot
2476 * be sure if there is still some data to be transmitted,
2477 * lets lie, and tell ld we have 1 byte left.
2481 * If TBUSY is still set, and our tx buffers are empty,
2482 * force the firmware to send me another wakeup after
2483 * TBUSY has been cleared.
2486 spin_lock_irqsave(&ch->ch_lock, lock_flags);
2487 un->un_flags |= UN_EMPTY;
2488 writeb(1, &(bs->iempty));
2489 spin_unlock_irqrestore(&ch->ch_lock,
2499 static int dgap_wait_for_drain(struct tty_struct *tty)
2501 struct channel_t *ch;
2506 ulong lock_flags = 0;
2508 if (!tty || tty->magic != TTY_MAGIC)
2511 un = tty->driver_data;
2512 if (!un || un->magic != DGAP_UNIT_MAGIC)
2516 if (!ch || ch->magic != DGAP_CHANNEL_MAGIC)
2525 /* Loop until data is drained */
2526 while (count != 0) {
2528 count = dgap_tty_chars_in_buffer(tty);
2533 /* Set flag waiting for drain */
2534 spin_lock_irqsave(&ch->ch_lock, lock_flags);
2535 un->un_flags |= UN_EMPTY;
2536 writeb(1, &(bs->iempty));
2537 spin_unlock_irqrestore(&ch->ch_lock, lock_flags);
2539 /* Go to sleep till we get woken up */
2540 ret = wait_event_interruptible(un->un_flags_wait,
2541 ((un->un_flags & UN_EMPTY) == 0));
2542 /* If ret is non-zero, user ctrl-c'ed us */
2547 spin_lock_irqsave(&ch->ch_lock, lock_flags);
2548 un->un_flags &= ~(UN_EMPTY);
2549 spin_unlock_irqrestore(&ch->ch_lock, lock_flags);
2557 * Reduces bytes_available to the max number of characters
2558 * that can be sent currently given the maxcps value, and
2559 * returns the new bytes_available. This only affects printer
2562 static int dgap_maxcps_room(struct tty_struct *tty, int bytes_available)
2564 struct channel_t *ch = NULL;
2565 struct un_t *un = NULL;
2568 return bytes_available;
2570 un = tty->driver_data;
2571 if (!un || un->magic != DGAP_UNIT_MAGIC)
2572 return bytes_available;
2575 if (!ch || ch->magic != DGAP_CHANNEL_MAGIC)
2576 return bytes_available;
2579 * If its not the Transparent print device, return
2580 * the full data amount.
2582 if (un->un_type != DGAP_PRINT)
2583 return bytes_available;
2585 if (ch->ch_digi.digi_maxcps > 0 && ch->ch_digi.digi_bufsize > 0) {
2587 unsigned long current_time = jiffies;
2588 unsigned long buffer_time = current_time +
2589 (HZ * ch->ch_digi.digi_bufsize) /
2590 ch->ch_digi.digi_maxcps;
2592 if (ch->ch_cpstime < current_time) {
2593 /* buffer is empty */
2594 ch->ch_cpstime = current_time; /* reset ch_cpstime */
2595 cps_limit = ch->ch_digi.digi_bufsize;
2596 } else if (ch->ch_cpstime < buffer_time) {
2597 /* still room in the buffer */
2598 cps_limit = ((buffer_time - ch->ch_cpstime) *
2599 ch->ch_digi.digi_maxcps) / HZ;
2601 /* no room in the buffer */
2605 bytes_available = min(cps_limit, bytes_available);
2608 return bytes_available;
2611 static inline void dgap_set_firmware_event(struct un_t *un, unsigned int event)
2613 struct channel_t *ch = NULL;
2614 struct bs_t *bs = NULL;
2616 if (!un || un->magic != DGAP_UNIT_MAGIC)
2619 if (!ch || ch->magic != DGAP_CHANNEL_MAGIC)
2625 if ((event & UN_LOW) != 0) {
2626 if ((un->un_flags & UN_LOW) == 0) {
2627 un->un_flags |= UN_LOW;
2628 writeb(1, &(bs->ilow));
2631 if ((event & UN_LOW) != 0) {
2632 if ((un->un_flags & UN_EMPTY) == 0) {
2633 un->un_flags |= UN_EMPTY;
2634 writeb(1, &(bs->iempty));
2640 * dgap_tty_write_room()
2642 * Return space available in Tx buffer
2644 static int dgap_tty_write_room(struct tty_struct *tty)
2646 struct channel_t *ch = NULL;
2647 struct un_t *un = NULL;
2648 struct bs_t *bs = NULL;
2649 u16 head, tail, tmask;
2651 ulong lock_flags = 0;
2656 un = tty->driver_data;
2657 if (!un || un->magic != DGAP_UNIT_MAGIC)
2661 if (!ch || ch->magic != DGAP_CHANNEL_MAGIC)
2668 spin_lock_irqsave(&ch->ch_lock, lock_flags);
2670 tmask = ch->ch_tsize - 1;
2671 head = readw(&(bs->tx_head)) & tmask;
2672 tail = readw(&(bs->tx_tail)) & tmask;
2674 ret = tail - head - 1;
2676 ret += ch->ch_tsize;
2678 /* Limit printer to maxcps */
2679 ret = dgap_maxcps_room(tty, ret);
2682 * If we are printer device, leave space for
2683 * possibly both the on and off strings.
2685 if (un->un_type == DGAP_PRINT) {
2686 if (!(ch->ch_flags & CH_PRON))
2687 ret -= ch->ch_digi.digi_onlen;
2688 ret -= ch->ch_digi.digi_offlen;
2690 if (ch->ch_flags & CH_PRON)
2691 ret -= ch->ch_digi.digi_offlen;
2698 * Schedule FEP to wake us up if needed.
2700 * TODO: This might be overkill...
2701 * Do we really need to schedule callbacks from the FEP
2702 * in every case? Can we get smarter based on ret?
2704 dgap_set_firmware_event(un, UN_LOW | UN_EMPTY);
2705 spin_unlock_irqrestore(&ch->ch_lock, lock_flags);
2711 * dgap_tty_put_char()
2713 * Put a character into ch->ch_buf
2715 * - used by the line discipline for OPOST processing
2717 static int dgap_tty_put_char(struct tty_struct *tty, unsigned char c)
2720 * Simply call tty_write.
2722 dgap_tty_write(tty, &c, 1);
2729 * Take data from the user or kernel and send it out to the FEP.
2730 * In here exists all the Transparent Print magic as well.
2732 static int dgap_tty_write(struct tty_struct *tty, const unsigned char *buf,
2735 struct channel_t *ch = NULL;
2736 struct un_t *un = NULL;
2737 struct bs_t *bs = NULL;
2739 u16 head, tail, tmask, remain;
2740 int bufcount = 0, n = 0;
2747 un = tty->driver_data;
2748 if (!un || un->magic != DGAP_UNIT_MAGIC)
2752 if (!ch || ch->magic != DGAP_CHANNEL_MAGIC)
2763 * Store original amount of characters passed in.
2764 * This helps to figure out if we should ask the FEP
2765 * to send us an event when it has more space available.
2769 spin_lock_irqsave(&ch->ch_lock, lock_flags);
2771 /* Get our space available for the channel from the board */
2772 tmask = ch->ch_tsize - 1;
2773 head = readw(&(bs->tx_head)) & tmask;
2774 tail = readw(&(bs->tx_tail)) & tmask;
2776 bufcount = tail - head - 1;
2778 bufcount += ch->ch_tsize;
2781 * Limit printer output to maxcps overall, with bursts allowed
2782 * up to bufsize characters.
2784 bufcount = dgap_maxcps_room(tty, bufcount);
2787 * Take minimum of what the user wants to send, and the
2788 * space available in the FEP buffer.
2790 count = min(count, bufcount);
2793 * Bail if no space left.
2796 dgap_set_firmware_event(un, UN_LOW | UN_EMPTY);
2797 spin_unlock_irqrestore(&ch->ch_lock, lock_flags);
2802 * Output the printer ON string, if we are in terminal mode, but
2803 * need to be in printer mode.
2805 if ((un->un_type == DGAP_PRINT) && !(ch->ch_flags & CH_PRON)) {
2806 dgap_wmove(ch, ch->ch_digi.digi_onstr,
2807 (int) ch->ch_digi.digi_onlen);
2808 head = readw(&(bs->tx_head)) & tmask;
2809 ch->ch_flags |= CH_PRON;
2813 * On the other hand, output the printer OFF string, if we are
2814 * currently in printer mode, but need to output to the terminal.
2816 if ((un->un_type != DGAP_PRINT) && (ch->ch_flags & CH_PRON)) {
2817 dgap_wmove(ch, ch->ch_digi.digi_offstr,
2818 (int) ch->ch_digi.digi_offlen);
2819 head = readw(&(bs->tx_head)) & tmask;
2820 ch->ch_flags &= ~CH_PRON;
2824 * If there is nothing left to copy, or
2825 * I can't handle any more data, leave.
2828 dgap_set_firmware_event(un, UN_LOW | UN_EMPTY);
2829 spin_unlock_irqrestore(&ch->ch_lock, lock_flags);
2836 * If the write wraps over the top of the circular buffer,
2837 * move the portion up to the wrap point, and reset the
2838 * pointers to the bottom.
2840 remain = ch->ch_tstart + ch->ch_tsize - head;
2844 vaddr = ch->ch_taddr + head;
2846 memcpy_toio(vaddr, (u8 *) buf, remain);
2847 dgap_sniff_nowait_nolock(ch, "USER WRITE", (u8 *) buf,
2850 head = ch->ch_tstart;
2857 * Move rest of data.
2859 vaddr = ch->ch_taddr + head;
2862 memcpy_toio(vaddr, (u8 *) buf, remain);
2863 dgap_sniff_nowait_nolock(ch, "USER WRITE", (u8 *)buf,
2871 ch->ch_txcount += count;
2873 writew(head, &(bs->tx_head));
2876 dgap_set_firmware_event(un, UN_LOW | UN_EMPTY);
2879 * If this is the print device, and the
2880 * printer is still on, we need to turn it
2881 * off before going idle. If the buffer is
2882 * non-empty, wait until it goes empty.
2883 * Otherwise turn it off right now.
2885 if ((un->un_type == DGAP_PRINT) && (ch->ch_flags & CH_PRON)) {
2886 tail = readw(&(bs->tx_tail)) & tmask;
2889 un->un_flags |= UN_EMPTY;
2890 writeb(1, &(bs->iempty));
2892 dgap_wmove(ch, ch->ch_digi.digi_offstr,
2893 (int) ch->ch_digi.digi_offlen);
2894 head = readw(&(bs->tx_head)) & tmask;
2895 ch->ch_flags &= ~CH_PRON;
2899 /* Update printer buffer empty time. */
2900 if ((un->un_type == DGAP_PRINT) && (ch->ch_digi.digi_maxcps > 0)
2901 && (ch->ch_digi.digi_bufsize > 0)) {
2902 ch->ch_cpstime += (HZ * count) / ch->ch_digi.digi_maxcps;
2905 spin_unlock_irqrestore(&ch->ch_lock, lock_flags);
2911 * Return modem signals to ld.
2913 static int dgap_tty_tiocmget(struct tty_struct *tty)
2915 struct channel_t *ch;
2921 if (!tty || tty->magic != TTY_MAGIC)
2924 un = tty->driver_data;
2925 if (!un || un->magic != DGAP_UNIT_MAGIC)
2929 if (!ch || ch->magic != DGAP_CHANNEL_MAGIC)
2932 spin_lock_irqsave(&ch->ch_lock, lock_flags);
2934 mstat = readb(&(ch->ch_bs->m_stat));
2935 /* Append any outbound signals that might be pending... */
2936 mstat |= ch->ch_mostat;
2938 spin_unlock_irqrestore(&ch->ch_lock, lock_flags);
2942 if (mstat & D_DTR(ch))
2943 result |= TIOCM_DTR;
2944 if (mstat & D_RTS(ch))
2945 result |= TIOCM_RTS;
2946 if (mstat & D_CTS(ch))
2947 result |= TIOCM_CTS;
2948 if (mstat & D_DSR(ch))
2949 result |= TIOCM_DSR;
2950 if (mstat & D_RI(ch))
2952 if (mstat & D_CD(ch))
2959 * dgap_tty_tiocmset()
2961 * Set modem signals, called by ld.
2963 static int dgap_tty_tiocmset(struct tty_struct *tty,
2964 unsigned int set, unsigned int clear)
2967 struct channel_t *ch;
2973 if (!tty || tty->magic != TTY_MAGIC)
2976 un = tty->driver_data;
2977 if (!un || un->magic != DGAP_UNIT_MAGIC)
2981 if (!ch || ch->magic != DGAP_CHANNEL_MAGIC)
2985 if (!bd || bd->magic != DGAP_BOARD_MAGIC)
2988 spin_lock_irqsave(&bd->bd_lock, lock_flags);
2989 spin_lock_irqsave(&ch->ch_lock, lock_flags2);
2991 if (set & TIOCM_RTS) {
2992 ch->ch_mforce |= D_RTS(ch);
2993 ch->ch_mval |= D_RTS(ch);
2996 if (set & TIOCM_DTR) {
2997 ch->ch_mforce |= D_DTR(ch);
2998 ch->ch_mval |= D_DTR(ch);
3001 if (clear & TIOCM_RTS) {
3002 ch->ch_mforce |= D_RTS(ch);
3003 ch->ch_mval &= ~(D_RTS(ch));
3006 if (clear & TIOCM_DTR) {
3007 ch->ch_mforce |= D_DTR(ch);
3008 ch->ch_mval &= ~(D_DTR(ch));
3013 spin_unlock_irqrestore(&ch->ch_lock, lock_flags2);
3014 spin_unlock_irqrestore(&bd->bd_lock, lock_flags);
3020 * dgap_tty_send_break()
3022 * Send a Break, called by ld.
3024 static int dgap_tty_send_break(struct tty_struct *tty, int msec)
3027 struct channel_t *ch;
3033 if (!tty || tty->magic != TTY_MAGIC)
3036 un = tty->driver_data;
3037 if (!un || un->magic != DGAP_UNIT_MAGIC)
3041 if (!ch || ch->magic != DGAP_CHANNEL_MAGIC)
3045 if (!bd || bd->magic != DGAP_BOARD_MAGIC)
3060 spin_lock_irqsave(&bd->bd_lock, lock_flags);
3061 spin_lock_irqsave(&ch->ch_lock, lock_flags2);
3063 dgap_cmdw(ch, SBREAK, (u16) SBREAK_TIME, 0);
3065 dgap_cmdw(ch, SBREAK, (u16) msec, 0);
3067 spin_unlock_irqrestore(&ch->ch_lock, lock_flags2);
3068 spin_unlock_irqrestore(&bd->bd_lock, lock_flags);
3074 * dgap_tty_wait_until_sent()
3076 * wait until data has been transmitted, called by ld.
3078 static void dgap_tty_wait_until_sent(struct tty_struct *tty, int timeout)
3080 dgap_wait_for_drain(tty);
3086 * send a high priority character, called by ld.
3088 static void dgap_tty_send_xchar(struct tty_struct *tty, char c)
3091 struct channel_t *ch;
3096 if (!tty || tty->magic != TTY_MAGIC)
3099 un = tty->driver_data;
3100 if (!un || un->magic != DGAP_UNIT_MAGIC)
3104 if (!ch || ch->magic != DGAP_CHANNEL_MAGIC)
3108 if (!bd || bd->magic != DGAP_BOARD_MAGIC)
3111 spin_lock_irqsave(&bd->bd_lock, lock_flags);
3112 spin_lock_irqsave(&ch->ch_lock, lock_flags2);
3115 * This is technically what we should do.
3116 * However, the NIST tests specifically want
3117 * to see each XON or XOFF character that it
3118 * sends, so lets just send each character
3122 if (c == STOP_CHAR(tty))
3123 dgap_cmdw(ch, RPAUSE, 0, 0);
3124 else if (c == START_CHAR(tty))
3125 dgap_cmdw(ch, RRESUME, 0, 0);
3127 dgap_wmove(ch, &c, 1);
3129 dgap_wmove(ch, &c, 1);
3132 spin_unlock_irqrestore(&ch->ch_lock, lock_flags2);
3133 spin_unlock_irqrestore(&bd->bd_lock, lock_flags);
3139 * Return modem signals to ld.
3141 static int dgap_get_modem_info(struct channel_t *ch, unsigned int __user *value)
3148 if (!ch || ch->magic != DGAP_CHANNEL_MAGIC)
3151 spin_lock_irqsave(&ch->ch_lock, lock_flags);
3153 mstat = readb(&(ch->ch_bs->m_stat));
3154 /* Append any outbound signals that might be pending... */
3155 mstat |= ch->ch_mostat;
3157 spin_unlock_irqrestore(&ch->ch_lock, lock_flags);
3161 if (mstat & D_DTR(ch))
3162 result |= TIOCM_DTR;
3163 if (mstat & D_RTS(ch))
3164 result |= TIOCM_RTS;
3165 if (mstat & D_CTS(ch))
3166 result |= TIOCM_CTS;
3167 if (mstat & D_DSR(ch))
3168 result |= TIOCM_DSR;
3169 if (mstat & D_RI(ch))
3171 if (mstat & D_CD(ch))
3174 rc = put_user(result, value);
3180 * dgap_set_modem_info()
3182 * Set modem signals, called by ld.
3184 static int dgap_set_modem_info(struct tty_struct *tty, unsigned int command,
3185 unsigned int __user *value)
3188 struct channel_t *ch;
3191 unsigned int arg = 0;
3195 if (!tty || tty->magic != TTY_MAGIC)
3198 un = tty->driver_data;
3199 if (!un || un->magic != DGAP_UNIT_MAGIC)
3203 if (!ch || ch->magic != DGAP_CHANNEL_MAGIC)
3207 if (!bd || bd->magic != DGAP_BOARD_MAGIC)
3210 ret = get_user(arg, value);
3216 if (arg & TIOCM_RTS) {
3217 ch->ch_mforce |= D_RTS(ch);
3218 ch->ch_mval |= D_RTS(ch);
3221 if (arg & TIOCM_DTR) {
3222 ch->ch_mforce |= D_DTR(ch);
3223 ch->ch_mval |= D_DTR(ch);
3229 if (arg & TIOCM_RTS) {
3230 ch->ch_mforce |= D_RTS(ch);
3231 ch->ch_mval &= ~(D_RTS(ch));
3234 if (arg & TIOCM_DTR) {
3235 ch->ch_mforce |= D_DTR(ch);
3236 ch->ch_mval &= ~(D_DTR(ch));
3242 ch->ch_mforce = D_DTR(ch)|D_RTS(ch);
3244 if (arg & TIOCM_RTS)
3245 ch->ch_mval |= D_RTS(ch);
3247 ch->ch_mval &= ~(D_RTS(ch));
3249 if (arg & TIOCM_DTR)
3250 ch->ch_mval |= (D_DTR(ch));
3252 ch->ch_mval &= ~(D_DTR(ch));
3260 spin_lock_irqsave(&bd->bd_lock, lock_flags);
3261 spin_lock_irqsave(&ch->ch_lock, lock_flags2);
3265 spin_unlock_irqrestore(&ch->ch_lock, lock_flags2);
3266 spin_unlock_irqrestore(&bd->bd_lock, lock_flags);
3272 * dgap_tty_digigeta()
3274 * Ioctl to get the information for ditty.
3279 static int dgap_tty_digigeta(struct tty_struct *tty,
3280 struct digi_t __user *retinfo)
3282 struct channel_t *ch;
3290 if (!tty || tty->magic != TTY_MAGIC)
3293 un = tty->driver_data;
3294 if (!un || un->magic != DGAP_UNIT_MAGIC)
3298 if (!ch || ch->magic != DGAP_CHANNEL_MAGIC)
3301 memset(&tmp, 0, sizeof(tmp));
3303 spin_lock_irqsave(&ch->ch_lock, lock_flags);
3304 memcpy(&tmp, &ch->ch_digi, sizeof(tmp));
3305 spin_unlock_irqrestore(&ch->ch_lock, lock_flags);
3307 if (copy_to_user(retinfo, &tmp, sizeof(*retinfo)))
3314 * dgap_tty_digiseta()
3316 * Ioctl to set the information for ditty.
3321 static int dgap_tty_digiseta(struct tty_struct *tty,
3322 struct digi_t __user *new_info)
3325 struct channel_t *ch;
3327 struct digi_t new_digi;
3328 ulong lock_flags = 0;
3329 unsigned long lock_flags2;
3331 if (!tty || tty->magic != TTY_MAGIC)
3334 un = tty->driver_data;
3335 if (!un || un->magic != DGAP_UNIT_MAGIC)
3339 if (!ch || ch->magic != DGAP_CHANNEL_MAGIC)
3343 if (!bd || bd->magic != DGAP_BOARD_MAGIC)
3346 if (copy_from_user(&new_digi, new_info, sizeof(struct digi_t)))
3349 spin_lock_irqsave(&bd->bd_lock, lock_flags);
3350 spin_lock_irqsave(&ch->ch_lock, lock_flags2);
3352 memcpy(&ch->ch_digi, &new_digi, sizeof(struct digi_t));
3354 if (ch->ch_digi.digi_maxcps < 1)
3355 ch->ch_digi.digi_maxcps = 1;
3357 if (ch->ch_digi.digi_maxcps > 10000)
3358 ch->ch_digi.digi_maxcps = 10000;
3360 if (ch->ch_digi.digi_bufsize < 10)
3361 ch->ch_digi.digi_bufsize = 10;
3363 if (ch->ch_digi.digi_maxchar < 1)
3364 ch->ch_digi.digi_maxchar = 1;
3366 if (ch->ch_digi.digi_maxchar > ch->ch_digi.digi_bufsize)
3367 ch->ch_digi.digi_maxchar = ch->ch_digi.digi_bufsize;
3369 if (ch->ch_digi.digi_onlen > DIGI_PLEN)
3370 ch->ch_digi.digi_onlen = DIGI_PLEN;
3372 if (ch->ch_digi.digi_offlen > DIGI_PLEN)
3373 ch->ch_digi.digi_offlen = DIGI_PLEN;
3377 spin_unlock_irqrestore(&ch->ch_lock, lock_flags2);
3378 spin_unlock_irqrestore(&bd->bd_lock, lock_flags);
3384 * dgap_tty_digigetedelay()
3386 * Ioctl to get the current edelay setting.
3391 static int dgap_tty_digigetedelay(struct tty_struct *tty, int __user *retinfo)
3393 struct channel_t *ch;
3401 if (!tty || tty->magic != TTY_MAGIC)
3404 un = tty->driver_data;
3405 if (!un || un->magic != DGAP_UNIT_MAGIC)
3409 if (!ch || ch->magic != DGAP_CHANNEL_MAGIC)
3412 memset(&tmp, 0, sizeof(tmp));
3414 spin_lock_irqsave(&ch->ch_lock, lock_flags);
3415 tmp = readw(&(ch->ch_bs->edelay));
3416 spin_unlock_irqrestore(&ch->ch_lock, lock_flags);
3418 if (copy_to_user(retinfo, &tmp, sizeof(*retinfo)))
3425 * dgap_tty_digisetedelay()
3427 * Ioctl to set the EDELAY setting
3430 static int dgap_tty_digisetedelay(struct tty_struct *tty, int __user *new_info)
3433 struct channel_t *ch;
3439 if (!tty || tty->magic != TTY_MAGIC)
3442 un = tty->driver_data;
3443 if (!un || un->magic != DGAP_UNIT_MAGIC)
3447 if (!ch || ch->magic != DGAP_CHANNEL_MAGIC)
3451 if (!bd || bd->magic != DGAP_BOARD_MAGIC)
3454 if (copy_from_user(&new_digi, new_info, sizeof(int)))
3457 spin_lock_irqsave(&bd->bd_lock, lock_flags);
3458 spin_lock_irqsave(&ch->ch_lock, lock_flags2);
3460 writew((u16) new_digi, &(ch->ch_bs->edelay));
3464 spin_unlock_irqrestore(&ch->ch_lock, lock_flags2);
3465 spin_unlock_irqrestore(&bd->bd_lock, lock_flags);
3471 * dgap_tty_digigetcustombaud()
3473 * Ioctl to get the current custom baud rate setting.
3475 static int dgap_tty_digigetcustombaud(struct tty_struct *tty,
3476 int __user *retinfo)
3478 struct channel_t *ch;
3486 if (!tty || tty->magic != TTY_MAGIC)
3489 un = tty->driver_data;
3490 if (!un || un->magic != DGAP_UNIT_MAGIC)
3494 if (!ch || ch->magic != DGAP_CHANNEL_MAGIC)
3497 memset(&tmp, 0, sizeof(tmp));
3499 spin_lock_irqsave(&ch->ch_lock, lock_flags);
3500 tmp = dgap_get_custom_baud(ch);
3501 spin_unlock_irqrestore(&ch->ch_lock, lock_flags);
3503 if (copy_to_user(retinfo, &tmp, sizeof(*retinfo)))
3510 * dgap_tty_digisetcustombaud()
3512 * Ioctl to set the custom baud rate setting
3514 static int dgap_tty_digisetcustombaud(struct tty_struct *tty,
3515 int __user *new_info)
3518 struct channel_t *ch;
3524 if (!tty || tty->magic != TTY_MAGIC)
3527 un = tty->driver_data;
3528 if (!un || un->magic != DGAP_UNIT_MAGIC)
3532 if (!ch || ch->magic != DGAP_CHANNEL_MAGIC)
3536 if (!bd || bd->magic != DGAP_BOARD_MAGIC)
3540 if (copy_from_user(&new_rate, new_info, sizeof(unsigned int)))
3543 if (bd->bd_flags & BD_FEP5PLUS) {
3545 spin_lock_irqsave(&bd->bd_lock, lock_flags);
3546 spin_lock_irqsave(&ch->ch_lock, lock_flags2);
3548 ch->ch_custom_speed = new_rate;
3552 spin_unlock_irqrestore(&ch->ch_lock, lock_flags2);
3553 spin_unlock_irqrestore(&bd->bd_lock, lock_flags);
3560 * dgap_set_termios()
3562 static void dgap_tty_set_termios(struct tty_struct *tty,
3563 struct ktermios *old_termios)
3566 struct channel_t *ch;
3568 unsigned long lock_flags;
3569 unsigned long lock_flags2;
3571 if (!tty || tty->magic != TTY_MAGIC)
3574 un = tty->driver_data;
3575 if (!un || un->magic != DGAP_UNIT_MAGIC)
3579 if (!ch || ch->magic != DGAP_CHANNEL_MAGIC)
3583 if (!bd || bd->magic != DGAP_BOARD_MAGIC)
3586 spin_lock_irqsave(&bd->bd_lock, lock_flags);
3587 spin_lock_irqsave(&ch->ch_lock, lock_flags2);
3589 ch->ch_c_cflag = tty->termios.c_cflag;
3590 ch->ch_c_iflag = tty->termios.c_iflag;
3591 ch->ch_c_oflag = tty->termios.c_oflag;
3592 ch->ch_c_lflag = tty->termios.c_lflag;
3593 ch->ch_startc = tty->termios.c_cc[VSTART];
3594 ch->ch_stopc = tty->termios.c_cc[VSTOP];
3599 spin_unlock_irqrestore(&ch->ch_lock, lock_flags2);
3600 spin_unlock_irqrestore(&bd->bd_lock, lock_flags);
3603 static void dgap_tty_throttle(struct tty_struct *tty)
3606 struct channel_t *ch;
3611 if (!tty || tty->magic != TTY_MAGIC)
3614 un = tty->driver_data;
3615 if (!un || un->magic != DGAP_UNIT_MAGIC)
3619 if (!ch || ch->magic != DGAP_CHANNEL_MAGIC)
3623 if (!bd || bd->magic != DGAP_BOARD_MAGIC)
3626 spin_lock_irqsave(&bd->bd_lock, lock_flags);
3627 spin_lock_irqsave(&ch->ch_lock, lock_flags2);
3629 ch->ch_flags |= (CH_RXBLOCK);
3631 dgap_cmdw(ch, RPAUSE, 0, 0);
3634 spin_unlock_irqrestore(&ch->ch_lock, lock_flags2);
3635 spin_unlock_irqrestore(&bd->bd_lock, lock_flags);
3639 static void dgap_tty_unthrottle(struct tty_struct *tty)
3642 struct channel_t *ch;
3647 if (!tty || tty->magic != TTY_MAGIC)
3650 un = tty->driver_data;
3651 if (!un || un->magic != DGAP_UNIT_MAGIC)
3655 if (!ch || ch->magic != DGAP_CHANNEL_MAGIC)
3659 if (!bd || bd->magic != DGAP_BOARD_MAGIC)
3662 spin_lock_irqsave(&bd->bd_lock, lock_flags);
3663 spin_lock_irqsave(&ch->ch_lock, lock_flags2);
3665 ch->ch_flags &= ~(CH_RXBLOCK);
3668 dgap_cmdw(ch, RRESUME, 0, 0);
3671 spin_unlock_irqrestore(&ch->ch_lock, lock_flags2);
3672 spin_unlock_irqrestore(&bd->bd_lock, lock_flags);
3675 static void dgap_tty_start(struct tty_struct *tty)
3678 struct channel_t *ch;
3683 if (!tty || tty->magic != TTY_MAGIC)
3686 un = tty->driver_data;
3687 if (!un || un->magic != DGAP_UNIT_MAGIC)
3691 if (!ch || ch->magic != DGAP_CHANNEL_MAGIC)
3695 if (!bd || bd->magic != DGAP_BOARD_MAGIC)
3698 spin_lock_irqsave(&bd->bd_lock, lock_flags);
3699 spin_lock_irqsave(&ch->ch_lock, lock_flags2);
3701 dgap_cmdw(ch, RESUMETX, 0, 0);
3703 spin_unlock_irqrestore(&ch->ch_lock, lock_flags2);
3704 spin_unlock_irqrestore(&bd->bd_lock, lock_flags);
3708 static void dgap_tty_stop(struct tty_struct *tty)
3711 struct channel_t *ch;
3716 if (!tty || tty->magic != TTY_MAGIC)
3719 un = tty->driver_data;
3720 if (!un || un->magic != DGAP_UNIT_MAGIC)
3724 if (!ch || ch->magic != DGAP_CHANNEL_MAGIC)
3728 if (!bd || bd->magic != DGAP_BOARD_MAGIC)
3731 spin_lock_irqsave(&bd->bd_lock, lock_flags);
3732 spin_lock_irqsave(&ch->ch_lock, lock_flags2);
3734 dgap_cmdw(ch, PAUSETX, 0, 0);
3736 spin_unlock_irqrestore(&ch->ch_lock, lock_flags2);
3737 spin_unlock_irqrestore(&bd->bd_lock, lock_flags);
3742 * dgap_tty_flush_chars()
3744 * Flush the cook buffer
3746 * Note to self, and any other poor souls who venture here:
3748 * flush in this case DOES NOT mean dispose of the data.
3749 * instead, it means "stop buffering and send it if you
3750 * haven't already." Just guess how I figured that out... SRW 2-Jun-98
3752 * It is also always called in interrupt context - JAR 8-Sept-99
3754 static void dgap_tty_flush_chars(struct tty_struct *tty)
3757 struct channel_t *ch;
3762 if (!tty || tty->magic != TTY_MAGIC)
3765 un = tty->driver_data;
3766 if (!un || un->magic != DGAP_UNIT_MAGIC)
3770 if (!ch || ch->magic != DGAP_CHANNEL_MAGIC)
3774 if (!bd || bd->magic != DGAP_BOARD_MAGIC)
3777 spin_lock_irqsave(&bd->bd_lock, lock_flags);
3778 spin_lock_irqsave(&ch->ch_lock, lock_flags2);
3780 /* TODO: Do something here */
3782 spin_unlock_irqrestore(&ch->ch_lock, lock_flags2);
3783 spin_unlock_irqrestore(&bd->bd_lock, lock_flags);
3787 * dgap_tty_flush_buffer()
3789 * Flush Tx buffer (make in == out)
3791 static void dgap_tty_flush_buffer(struct tty_struct *tty)
3794 struct channel_t *ch;
3800 if (!tty || tty->magic != TTY_MAGIC)
3803 un = tty->driver_data;
3804 if (!un || un->magic != DGAP_UNIT_MAGIC)
3808 if (!ch || ch->magic != DGAP_CHANNEL_MAGIC)
3812 if (!bd || bd->magic != DGAP_BOARD_MAGIC)
3815 spin_lock_irqsave(&bd->bd_lock, lock_flags);
3816 spin_lock_irqsave(&ch->ch_lock, lock_flags2);
3818 ch->ch_flags &= ~CH_STOP;
3819 head = readw(&(ch->ch_bs->tx_head));
3820 dgap_cmdw(ch, FLUSHTX, (u16) head, 0);
3821 dgap_cmdw(ch, RESUMETX, 0, 0);
3822 if (ch->ch_tun.un_flags & (UN_LOW|UN_EMPTY)) {
3823 ch->ch_tun.un_flags &= ~(UN_LOW|UN_EMPTY);
3824 wake_up_interruptible(&ch->ch_tun.un_flags_wait);
3826 if (ch->ch_pun.un_flags & (UN_LOW|UN_EMPTY)) {
3827 ch->ch_pun.un_flags &= ~(UN_LOW|UN_EMPTY);
3828 wake_up_interruptible(&ch->ch_pun.un_flags_wait);
3831 spin_unlock_irqrestore(&ch->ch_lock, lock_flags2);
3832 spin_unlock_irqrestore(&bd->bd_lock, lock_flags);
3833 if (waitqueue_active(&tty->write_wait))
3834 wake_up_interruptible(&tty->write_wait);
3838 /*****************************************************************************
3840 * The IOCTL function and all of its helpers
3842 *****************************************************************************/
3847 * The usual assortment of ioctl's
3849 static int dgap_tty_ioctl(struct tty_struct *tty, unsigned int cmd,
3853 struct channel_t *ch;
3857 ulong lock_flags = 0;
3858 ulong lock_flags2 = 0;
3859 void __user *uarg = (void __user *) arg;
3861 if (!tty || tty->magic != TTY_MAGIC)
3864 un = tty->driver_data;
3865 if (!un || un->magic != DGAP_UNIT_MAGIC)
3869 if (!ch || ch->magic != DGAP_CHANNEL_MAGIC)
3873 if (!bd || bd->magic != DGAP_BOARD_MAGIC)
3876 spin_lock_irqsave(&bd->bd_lock, lock_flags);
3877 spin_lock_irqsave(&ch->ch_lock, lock_flags2);
3879 if (un->un_open_count <= 0) {
3880 spin_unlock_irqrestore(&ch->ch_lock, lock_flags2);
3881 spin_unlock_irqrestore(&bd->bd_lock, lock_flags);
3887 /* Here are all the standard ioctl's that we MUST implement */
3891 * TCSBRK is SVID version: non-zero arg --> no break
3892 * this behaviour is exploited by tcdrain().
3894 * According to POSIX.1 spec (7.2.2.1.2) breaks should be
3895 * between 0.25 and 0.5 seconds so we'll ask for something
3896 * in the middle: 0.375 seconds.
3898 rc = tty_check_change(tty);
3899 spin_unlock_irqrestore(&ch->ch_lock, lock_flags2);
3900 spin_unlock_irqrestore(&bd->bd_lock, lock_flags);
3904 rc = dgap_wait_for_drain(tty);
3909 spin_lock_irqsave(&bd->bd_lock, lock_flags);
3910 spin_lock_irqsave(&ch->ch_lock, lock_flags2);
3912 if (((cmd == TCSBRK) && (!arg)) || (cmd == TCSBRKP))
3913 dgap_cmdw(ch, SBREAK, (u16) SBREAK_TIME, 0);
3915 spin_unlock_irqrestore(&ch->ch_lock, lock_flags2);
3916 spin_unlock_irqrestore(&bd->bd_lock, lock_flags);
3921 /* support for POSIX tcsendbreak()
3923 * According to POSIX.1 spec (7.2.2.1.2) breaks should be
3924 * between 0.25 and 0.5 seconds so we'll ask for something
3925 * in the middle: 0.375 seconds.
3927 rc = tty_check_change(tty);
3928 spin_unlock_irqrestore(&ch->ch_lock, lock_flags2);
3929 spin_unlock_irqrestore(&bd->bd_lock, lock_flags);
3933 rc = dgap_wait_for_drain(tty);
3937 spin_lock_irqsave(&bd->bd_lock, lock_flags);
3938 spin_lock_irqsave(&ch->ch_lock, lock_flags2);
3940 dgap_cmdw(ch, SBREAK, (u16) SBREAK_TIME, 0);
3942 spin_unlock_irqrestore(&ch->ch_lock, lock_flags2);
3943 spin_unlock_irqrestore(&bd->bd_lock, lock_flags);
3949 * FEP5 doesn't support turning on a break unconditionally.
3950 * The FEP5 device will stop sending a break automatically
3951 * after the specified time value that was sent when turning on
3954 rc = tty_check_change(tty);
3955 spin_unlock_irqrestore(&ch->ch_lock, lock_flags2);
3956 spin_unlock_irqrestore(&bd->bd_lock, lock_flags);
3960 rc = dgap_wait_for_drain(tty);
3964 spin_lock_irqsave(&bd->bd_lock, lock_flags);
3965 spin_lock_irqsave(&ch->ch_lock, lock_flags2);
3967 dgap_cmdw(ch, SBREAK, (u16) SBREAK_TIME, 0);
3969 spin_unlock_irqrestore(&ch->ch_lock, lock_flags2);
3970 spin_unlock_irqrestore(&bd->bd_lock, lock_flags);
3976 * FEP5 doesn't support turning off a break unconditionally.
3977 * The FEP5 device will stop sending a break automatically
3978 * after the specified time value that was sent when turning on
3981 spin_unlock_irqrestore(&ch->ch_lock, lock_flags2);
3982 spin_unlock_irqrestore(&bd->bd_lock, lock_flags);
3987 spin_unlock_irqrestore(&ch->ch_lock, lock_flags2);
3988 spin_unlock_irqrestore(&bd->bd_lock, lock_flags);
3990 rc = put_user(C_CLOCAL(tty) ? 1 : 0,
3991 (unsigned long __user *) arg);
3995 spin_unlock_irqrestore(&ch->ch_lock, lock_flags2);
3996 spin_unlock_irqrestore(&bd->bd_lock, lock_flags);
3998 rc = get_user(arg, (unsigned long __user *) arg);
4002 spin_lock_irqsave(&bd->bd_lock, lock_flags);
4003 spin_lock_irqsave(&ch->ch_lock, lock_flags2);
4004 tty->termios.c_cflag = ((tty->termios.c_cflag & ~CLOCAL) |
4005 (arg ? CLOCAL : 0));
4007 spin_unlock_irqrestore(&ch->ch_lock, lock_flags2);
4008 spin_unlock_irqrestore(&bd->bd_lock, lock_flags);
4013 spin_unlock_irqrestore(&ch->ch_lock, lock_flags2);
4014 spin_unlock_irqrestore(&bd->bd_lock, lock_flags);
4015 return dgap_get_modem_info(ch, uarg);
4020 spin_unlock_irqrestore(&ch->ch_lock, lock_flags2);
4021 spin_unlock_irqrestore(&bd->bd_lock, lock_flags);
4022 return dgap_set_modem_info(tty, cmd, uarg);
4025 * Here are any additional ioctl's that we want to implement
4030 * The linux tty driver doesn't have a flush
4031 * input routine for the driver, assuming all backed
4032 * up data is in the line disc. buffers. However,
4033 * we all know that's not the case. Here, we
4034 * act on the ioctl, but then lie and say we didn't
4035 * so the line discipline will process the flush
4038 rc = tty_check_change(tty);
4040 spin_unlock_irqrestore(&ch->ch_lock, lock_flags2);
4041 spin_unlock_irqrestore(&bd->bd_lock, lock_flags);
4045 if ((arg == TCIFLUSH) || (arg == TCIOFLUSH)) {
4046 if (!(un->un_type == DGAP_PRINT)) {
4047 head = readw(&(ch->ch_bs->rx_head));
4048 writew(head, &(ch->ch_bs->rx_tail));
4049 writeb(0, &(ch->ch_bs->orun));
4053 if ((arg != TCOFLUSH) && (arg != TCIOFLUSH)) {
4054 /* pretend we didn't recognize this IOCTL */
4055 spin_unlock_irqrestore(&ch->ch_lock, lock_flags2);
4056 spin_unlock_irqrestore(&bd->bd_lock, lock_flags);
4058 return -ENOIOCTLCMD;
4061 ch->ch_flags &= ~CH_STOP;
4062 head = readw(&(ch->ch_bs->tx_head));
4063 dgap_cmdw(ch, FLUSHTX, (u16) head, 0);
4064 dgap_cmdw(ch, RESUMETX, 0, 0);
4065 if (ch->ch_tun.un_flags & (UN_LOW|UN_EMPTY)) {
4066 ch->ch_tun.un_flags &= ~(UN_LOW|UN_EMPTY);
4067 wake_up_interruptible(&ch->ch_tun.un_flags_wait);
4069 if (ch->ch_pun.un_flags & (UN_LOW|UN_EMPTY)) {
4070 ch->ch_pun.un_flags &= ~(UN_LOW|UN_EMPTY);
4071 wake_up_interruptible(&ch->ch_pun.un_flags_wait);
4073 if (waitqueue_active(&tty->write_wait))
4074 wake_up_interruptible(&tty->write_wait);
4076 /* Can't hold any locks when calling tty_wakeup! */
4077 spin_unlock_irqrestore(&ch->ch_lock, lock_flags2);
4078 spin_unlock_irqrestore(&bd->bd_lock, lock_flags);
4081 /* pretend we didn't recognize this IOCTL */
4082 return -ENOIOCTLCMD;
4087 * The linux tty driver doesn't have a flush
4088 * input routine for the driver, assuming all backed
4089 * up data is in the line disc. buffers. However,
4090 * we all know that's not the case. Here, we
4091 * act on the ioctl, but then lie and say we didn't
4092 * so the line discipline will process the flush
4095 if (cmd == TCSETSF) {
4097 ch->ch_flags &= ~CH_STOP;
4098 head = readw(&(ch->ch_bs->rx_head));
4099 writew(head, &(ch->ch_bs->rx_tail));
4102 /* now wait for all the output to drain */
4103 spin_unlock_irqrestore(&ch->ch_lock, lock_flags2);
4104 spin_unlock_irqrestore(&bd->bd_lock, lock_flags);
4105 rc = dgap_wait_for_drain(tty);
4109 /* pretend we didn't recognize this */
4110 return -ENOIOCTLCMD;
4114 spin_unlock_irqrestore(&ch->ch_lock, lock_flags2);
4115 spin_unlock_irqrestore(&bd->bd_lock, lock_flags);
4116 rc = dgap_wait_for_drain(tty);
4120 /* pretend we didn't recognize this */
4121 return -ENOIOCTLCMD;
4125 * The Linux Line Discipline (LD) would do this for us if we
4126 * let it, but we have the special firmware options to do this
4127 * the "right way" regardless of hardware or software flow
4128 * control so we'll do it outselves instead of letting the LD
4131 rc = tty_check_change(tty);
4133 spin_unlock_irqrestore(&ch->ch_lock, lock_flags2);
4134 spin_unlock_irqrestore(&bd->bd_lock, lock_flags);
4141 spin_unlock_irqrestore(&ch->ch_lock, lock_flags2);
4142 spin_unlock_irqrestore(&bd->bd_lock, lock_flags);
4143 dgap_tty_start(tty);
4146 spin_unlock_irqrestore(&ch->ch_lock, lock_flags2);
4147 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 /* Make the ld do it */
4154 return -ENOIOCTLCMD;
4156 spin_unlock_irqrestore(&ch->ch_lock, lock_flags2);
4157 spin_unlock_irqrestore(&bd->bd_lock, lock_flags);
4158 /* Make the ld do it */
4159 return -ENOIOCTLCMD;
4161 spin_unlock_irqrestore(&ch->ch_lock, lock_flags2);
4162 spin_unlock_irqrestore(&bd->bd_lock, lock_flags);
4167 /* get information for ditty */
4168 spin_unlock_irqrestore(&ch->ch_lock, lock_flags2);
4169 spin_unlock_irqrestore(&bd->bd_lock, lock_flags);
4170 return dgap_tty_digigeta(tty, uarg);
4175 /* set information for ditty */
4176 if (cmd == (DIGI_SETAW)) {
4178 spin_unlock_irqrestore(&ch->ch_lock, lock_flags2);
4179 spin_unlock_irqrestore(&bd->bd_lock, lock_flags);
4180 rc = dgap_wait_for_drain(tty);
4183 spin_lock_irqsave(&bd->bd_lock, lock_flags);
4184 spin_lock_irqsave(&ch->ch_lock, lock_flags2);
4186 tty_ldisc_flush(tty);
4190 spin_unlock_irqrestore(&ch->ch_lock, lock_flags2);
4191 spin_unlock_irqrestore(&bd->bd_lock, lock_flags);
4192 return dgap_tty_digiseta(tty, uarg);
4195 spin_unlock_irqrestore(&ch->ch_lock, lock_flags2);
4196 spin_unlock_irqrestore(&bd->bd_lock, lock_flags);
4197 return dgap_tty_digigetedelay(tty, uarg);
4200 spin_unlock_irqrestore(&ch->ch_lock, lock_flags2);
4201 spin_unlock_irqrestore(&bd->bd_lock, lock_flags);
4202 return dgap_tty_digisetedelay(tty, uarg);
4204 case DIGI_GETCUSTOMBAUD:
4205 spin_unlock_irqrestore(&ch->ch_lock, lock_flags2);
4206 spin_unlock_irqrestore(&bd->bd_lock, lock_flags);
4207 return dgap_tty_digigetcustombaud(tty, uarg);
4209 case DIGI_SETCUSTOMBAUD:
4210 spin_unlock_irqrestore(&ch->ch_lock, lock_flags2);
4211 spin_unlock_irqrestore(&bd->bd_lock, lock_flags);
4212 return dgap_tty_digisetcustombaud(tty, uarg);
4214 case DIGI_RESET_PORT:
4215 dgap_firmware_reset_port(ch);
4217 spin_unlock_irqrestore(&ch->ch_lock, lock_flags2);
4218 spin_unlock_irqrestore(&bd->bd_lock, lock_flags);
4222 spin_unlock_irqrestore(&ch->ch_lock, lock_flags2);
4223 spin_unlock_irqrestore(&bd->bd_lock, lock_flags);
4225 return -ENOIOCTLCMD;
4229 static int dgap_after_config_loaded(int board)
4232 * Initialize KME waitqueues...
4234 init_waitqueue_head(&(dgap_Board[board]->kme_wait));
4237 * allocate flip buffer for board.
4239 dgap_Board[board]->flipbuf = kmalloc(MYFLIPLEN, GFP_ATOMIC);
4240 if (!dgap_Board[board]->flipbuf)
4243 dgap_Board[board]->flipflagbuf = kmalloc(MYFLIPLEN, GFP_ATOMIC);
4244 if (!dgap_Board[board]->flipflagbuf) {
4245 kfree(dgap_Board[board]->flipbuf);
4253 * Create pr and tty device entries
4255 static int dgap_tty_register_ports(struct board_t *brd)
4257 struct channel_t *ch;
4260 brd->SerialPorts = kcalloc(brd->nasync, sizeof(*brd->SerialPorts),
4262 if (brd->SerialPorts == NULL)
4264 for (i = 0; i < brd->nasync; i++)
4265 tty_port_init(&brd->SerialPorts[i]);
4267 brd->PrinterPorts = kcalloc(brd->nasync, sizeof(*brd->PrinterPorts),
4269 if (brd->PrinterPorts == NULL) {
4270 kfree(brd->SerialPorts);
4273 for (i = 0; i < brd->nasync; i++)
4274 tty_port_init(&brd->PrinterPorts[i]);
4276 ch = brd->channels[0];
4277 for (i = 0; i < brd->nasync; i++, ch = brd->channels[i]) {
4279 struct device *classp;
4281 classp = tty_port_register_device(&brd->SerialPorts[i],
4283 brd->firstminor + i, NULL);
4285 dgap_create_tty_sysfs(&ch->ch_tun, classp);
4286 ch->ch_tun.un_sysfs = classp;
4288 classp = tty_port_register_device(&brd->PrinterPorts[i],
4290 brd->firstminor + i, NULL);
4292 dgap_create_tty_sysfs(&ch->ch_pun, classp);
4293 ch->ch_pun.un_sysfs = classp;
4295 dgap_create_ports_sysfiles(brd);
4301 * Copies the BIOS code from the user to the board,
4302 * and starts the BIOS running.
4304 static void dgap_do_bios_load(struct board_t *brd, const u8 *ubios, int len)
4310 if (!brd || (brd->magic != DGAP_BOARD_MAGIC) || !brd->re_map_membase)
4313 addr = brd->re_map_membase;
4318 for (i = 0; i < 16; i++)
4319 writeb(0, addr + POSTAREA + i);
4325 memcpy_toio(addr + offset, ubios, len);
4327 writel(0x0bf00401, addr);
4328 writel(0, (addr + 4));
4330 /* Clear the reset, and change states. */
4331 writeb(FEPCLR, brd->re_map_port);
4335 * Checks to see if the BIOS completed running on the card.
4337 static int dgap_test_bios(struct board_t *brd)
4344 if (!brd || (brd->magic != DGAP_BOARD_MAGIC) || !brd->re_map_membase)
4347 addr = brd->re_map_membase;
4348 word = readw(addr + POSTAREA);
4351 * It can take 5-6 seconds for a board to
4352 * pass the bios self test and post results.
4353 * Give it 10 seconds.
4355 brd->wait_for_bios = 0;
4356 while (brd->wait_for_bios < 1000) {
4357 /* Check to see if BIOS thinks board is good. (GD). */
4358 if (word == *(u16 *) "GD")
4360 msleep_interruptible(10);
4361 brd->wait_for_bios++;
4362 word = readw(addr + POSTAREA);
4365 /* Gave up on board after too long of time taken */
4366 err1 = readw(addr + SEQUENCE);
4367 err2 = readw(addr + ERROR);
4368 pr_warn("dgap: %s failed diagnostics. Error #(%x,%x).\n",
4369 brd->name, err1, err2);
4370 brd->state = BOARD_FAILED;
4371 brd->dpastatus = BD_NOBIOS;
4377 * Copies the FEP code from the user to the board,
4378 * and starts the FEP running.
4380 static void dgap_do_fep_load(struct board_t *brd, const u8 *ufep, int len)
4385 if (!brd || (brd->magic != DGAP_BOARD_MAGIC) || !brd->re_map_membase)
4388 addr = brd->re_map_membase;
4394 memcpy_toio(addr + offset, ufep, len);
4397 * If board is a concentrator product, we need to give
4398 * it its config string describing how the concentrators look.
4400 if ((brd->type == PCX) || (brd->type == PEPC)) {
4402 u8 *config, *xconfig;
4405 xconfig = dgap_create_config_string(brd, string);
4407 /* Write string to board memory */
4408 config = addr + CONFIG;
4409 for (; i < CONFIGSIZE; i++, config++, xconfig++) {
4410 writeb(*xconfig, config);
4411 if ((*xconfig & 0xff) == 0xff)
4416 writel(0xbfc01004, (addr + 0xc34));
4417 writel(0x3, (addr + 0xc30));
4422 * Waits for the FEP to report thats its ready for us to use.
4424 static int dgap_test_fep(struct board_t *brd)
4431 if (!brd || (brd->magic != DGAP_BOARD_MAGIC) || !brd->re_map_membase)
4434 addr = brd->re_map_membase;
4435 word = readw(addr + FEPSTAT);
4438 * It can take 2-3 seconds for the FEP to
4439 * be up and running. Give it 5 secs.
4441 brd->wait_for_fep = 0;
4442 while (brd->wait_for_fep < 500) {
4443 /* Check to see if FEP is up and running now. */
4444 if (word == *(u16 *) "OS") {
4446 * Check to see if the board can support FEP5+ commands.
4448 word = readw(addr + FEP5_PLUS);
4449 if (word == *(u16 *) "5A")
4450 brd->bd_flags |= BD_FEP5PLUS;
4454 msleep_interruptible(10);
4455 brd->wait_for_fep++;
4456 word = readw(addr + FEPSTAT);
4459 /* Gave up on board after too long of time taken */
4460 err1 = readw(addr + SEQUENCE);
4461 err2 = readw(addr + ERROR);
4462 pr_warn("dgap: FEPOS for %s not functioning. Error #(%x,%x).\n",
4463 brd->name, err1, err2);
4464 brd->state = BOARD_FAILED;
4465 brd->dpastatus = BD_NOFEP;
4471 * Physically forces the FEP5 card to reset itself.
4473 static void dgap_do_reset_board(struct board_t *brd)
4480 if (!brd || (brd->magic != DGAP_BOARD_MAGIC) ||
4481 !brd->re_map_membase || !brd->re_map_port)
4484 /* FEPRST does not vary among supported boards */
4485 writeb(FEPRST, brd->re_map_port);
4487 for (i = 0; i <= 1000; i++) {
4488 check = readb(brd->re_map_port) & 0xe;
4489 if (check == FEPRST)
4495 pr_warn("dgap: Board not resetting... Failing board.\n");
4496 brd->state = BOARD_FAILED;
4497 brd->dpastatus = BD_NOFEP;
4502 * Make sure there really is memory out there.
4504 writel(0xa55a3cc3, (brd->re_map_membase + LOWMEM));
4505 writel(0x5aa5c33c, (brd->re_map_membase + HIGHMEM));
4506 check1 = readl(brd->re_map_membase + LOWMEM);
4507 check2 = readl(brd->re_map_membase + HIGHMEM);
4509 if ((check1 != 0xa55a3cc3) || (check2 != 0x5aa5c33c)) {
4510 pr_warn("dgap: No memory at %p for board.\n",
4511 brd->re_map_membase);
4512 brd->state = BOARD_FAILED;
4513 brd->dpastatus = BD_NOFEP;
4519 #ifdef DIGI_CONCENTRATORS_SUPPORTED
4521 * Sends a concentrator image into the FEP5 board.
4523 static void dgap_do_conc_load(struct board_t *brd, u8 *uaddr, int len)
4527 struct downld_t *to_dp;
4529 if (!brd || (brd->magic != DGAP_BOARD_MAGIC) || !brd->re_map_membase)
4532 vaddr = brd->re_map_membase;
4534 offset = readw((u16 *) (vaddr + DOWNREQ));
4535 to_dp = (struct downld_t *) (vaddr + (int) offset);
4536 memcpy_toio(to_dp, uaddr, len);
4538 /* Tell card we have data for it */
4539 writew(0, vaddr + (DOWNREQ));
4541 brd->conc_dl_status = NO_PENDING_CONCENTRATOR_REQUESTS;
4545 #define EXPANSION_ROM_SIZE (64 * 1024)
4546 #define FEP5_ROM_MAGIC (0xFEFFFFFF)
4548 static void dgap_get_vpd(struct board_t *brd)
4560 * Poke the magic number at the PCI Rom Address location.
4561 * If VPD is supported, the value read from that address
4564 magic = FEP5_ROM_MAGIC;
4565 pci_write_config_dword(brd->pdev, PCI_ROM_ADDRESS, magic);
4566 pci_read_config_dword(brd->pdev, PCI_ROM_ADDRESS, &magic);
4568 /* VPD not supported, bail */
4573 * To get to the OTPROM memory, we have to send the boards base
4574 * address or'ed with 1 into the PCI Rom Address location.
4576 magic = brd->membase | 0x01;
4577 pci_write_config_dword(brd->pdev, PCI_ROM_ADDRESS, magic);
4578 pci_read_config_dword(brd->pdev, PCI_ROM_ADDRESS, &magic);
4580 byte1 = readb(brd->re_map_membase);
4581 byte2 = readb(brd->re_map_membase + 1);
4584 * If the board correctly swapped to the OTPROM memory,
4585 * the first 2 bytes (header) should be 0x55, 0xAA
4587 if (byte1 == 0x55 && byte2 == 0xAA) {
4592 * We have to run through all the OTPROM memory looking
4593 * for the VPD offset.
4595 while (base_offset <= EXPANSION_ROM_SIZE) {
4598 * Lots of magic numbers here.
4600 * The VPD offset is located inside the ROM Data
4603 * We also have to remember the length of each
4604 * ROM Data Structure, so we can "hop" to the next
4605 * entry if the VPD isn't in the current
4606 * ROM Data Structure.
4608 rom_offset = readw(brd->re_map_membase +
4609 base_offset + 0x18);
4610 image_length = readw(brd->re_map_membase +
4611 rom_offset + 0x10) * 512;
4612 vpd_offset = readw(brd->re_map_membase +
4615 /* Found the VPD entry */
4619 /* We didn't find a VPD entry, go to next ROM entry. */
4620 base_offset += image_length;
4622 byte1 = readb(brd->re_map_membase + base_offset);
4623 byte2 = readb(brd->re_map_membase + base_offset + 1);
4626 * If the new ROM offset doesn't have 0x55, 0xAA
4627 * as its header, we have run out of ROM.
4629 if (byte1 != 0x55 || byte2 != 0xAA)
4634 * If we have a VPD offset, then mark the board
4635 * as having a valid VPD, and copy VPDSIZE (512) bytes of
4636 * that VPD to the buffer we have in our board structure.
4639 brd->bd_flags |= BD_HAS_VPD;
4640 for (i = 0; i < VPDSIZE; i++) {
4641 brd->vpd[i] = readb(brd->re_map_membase +
4648 * We MUST poke the magic number at the PCI Rom Address location again.
4649 * This makes the card report the regular board memory back to us,
4650 * rather than the OTPROM memory.
4652 magic = FEP5_ROM_MAGIC;
4653 pci_write_config_dword(brd->pdev, PCI_ROM_ADDRESS, magic);
4657 * Our board poller function.
4659 static void dgap_poll_tasklet(unsigned long data)
4661 struct board_t *bd = (struct board_t *) data;
4666 if (!bd || (bd->magic != DGAP_BOARD_MAGIC))
4669 if (bd->inhibit_poller)
4672 spin_lock_irqsave(&bd->bd_lock, lock_flags);
4674 vaddr = bd->re_map_membase;
4677 * If board is ready, parse deeper to see if there is anything to do.
4679 if (bd->state == BOARD_READY) {
4681 struct ev_t *eaddr = NULL;
4683 if (!bd->re_map_membase) {
4684 spin_unlock_irqrestore(&bd->bd_lock, lock_flags);
4687 if (!bd->re_map_port) {
4688 spin_unlock_irqrestore(&bd->bd_lock, lock_flags);
4695 eaddr = (struct ev_t *) (vaddr + EVBUF);
4697 /* Get our head and tail */
4698 head = readw(&(eaddr->ev_head));
4699 tail = readw(&(eaddr->ev_tail));
4702 * If there is an event pending. Go service it.
4705 spin_unlock_irqrestore(&bd->bd_lock, lock_flags);
4707 spin_lock_irqsave(&bd->bd_lock, lock_flags);
4712 * If board is doing interrupts, ACK the interrupt.
4714 if (bd && bd->intr_running)
4715 readb(bd->re_map_port + 2);
4717 spin_unlock_irqrestore(&bd->bd_lock, lock_flags);
4721 spin_unlock_irqrestore(&bd->bd_lock, lock_flags);
4724 /*=======================================================================
4726 * dgap_cmdb - Sends a 2 byte command to the FEP.
4728 * ch - Pointer to channel structure.
4729 * cmd - Command to be sent.
4730 * byte1 - Integer containing first byte to be sent.
4731 * byte2 - Integer containing second byte to be sent.
4732 * ncmds - Wait until ncmds or fewer cmds are left
4733 * in the cmd buffer before returning.
4735 *=======================================================================*/
4736 static void dgap_cmdb(struct channel_t *ch, u8 cmd, u8 byte1,
4737 u8 byte2, uint ncmds)
4740 struct cm_t *cm_addr = NULL;
4746 if (!ch || ch->magic != DGAP_CHANNEL_MAGIC)
4750 * Check if board is still alive.
4752 if (ch->ch_bd->state == BOARD_FAILED)
4756 * Make sure the pointers are in range before
4757 * writing to the FEP memory.
4759 vaddr = ch->ch_bd->re_map_membase;
4764 cm_addr = (struct cm_t *) (vaddr + CMDBUF);
4765 head = readw(&(cm_addr->cm_head));
4768 * Forget it if pointers out of range.
4770 if (head >= (CMDMAX - CMDSTART) || (head & 03)) {
4771 ch->ch_bd->state = BOARD_FAILED;
4776 * Put the data in the circular command buffer.
4778 writeb(cmd, (char *) (vaddr + head + CMDSTART + 0));
4779 writeb((u8) ch->ch_portnum, (char *) (vaddr + head + CMDSTART + 1));
4780 writeb(byte1, (char *) (vaddr + head + CMDSTART + 2));
4781 writeb(byte2, (char *) (vaddr + head + CMDSTART + 3));
4783 head = (head + 4) & (CMDMAX - CMDSTART - 4);
4785 writew(head, &(cm_addr->cm_head));
4788 * Wait if necessary before updating the head
4789 * pointer to limit the number of outstanding
4790 * commands to the FEP. If the time spent waiting
4791 * is outlandish, declare the FEP dead.
4793 for (count = dgap_count ;;) {
4795 head = readw(&(cm_addr->cm_head));
4796 tail = readw(&(cm_addr->cm_tail));
4798 n = (head - tail) & (CMDMAX - CMDSTART - 4);
4800 if (n <= ncmds * sizeof(struct cm_t))
4804 ch->ch_bd->state = BOARD_FAILED;
4811 /*=======================================================================
4813 * dgap_cmdw - Sends a 1 word command to the FEP.
4815 * ch - Pointer to channel structure.
4816 * cmd - Command to be sent.
4817 * word - Integer containing word to be sent.
4818 * ncmds - Wait until ncmds or fewer cmds are left
4819 * in the cmd buffer before returning.
4821 *=======================================================================*/
4822 static void dgap_cmdw(struct channel_t *ch, u8 cmd, u16 word, uint ncmds)
4825 struct cm_t *cm_addr = NULL;
4831 if (!ch || ch->magic != DGAP_CHANNEL_MAGIC)
4835 * Check if board is still alive.
4837 if (ch->ch_bd->state == BOARD_FAILED)
4841 * Make sure the pointers are in range before
4842 * writing to the FEP memory.
4844 vaddr = ch->ch_bd->re_map_membase;
4848 cm_addr = (struct cm_t *) (vaddr + CMDBUF);
4849 head = readw(&(cm_addr->cm_head));
4852 * Forget it if pointers out of range.
4854 if (head >= (CMDMAX - CMDSTART) || (head & 03)) {
4855 ch->ch_bd->state = BOARD_FAILED;
4860 * Put the data in the circular command buffer.
4862 writeb(cmd, (char *) (vaddr + head + CMDSTART + 0));
4863 writeb((u8) ch->ch_portnum, (char *) (vaddr + head + CMDSTART + 1));
4864 writew((u16) word, (char *) (vaddr + head + CMDSTART + 2));
4866 head = (head + 4) & (CMDMAX - CMDSTART - 4);
4868 writew(head, &(cm_addr->cm_head));
4871 * Wait if necessary before updating the head
4872 * pointer to limit the number of outstanding
4873 * commands to the FEP. If the time spent waiting
4874 * is outlandish, declare the FEP dead.
4876 for (count = dgap_count ;;) {
4878 head = readw(&(cm_addr->cm_head));
4879 tail = readw(&(cm_addr->cm_tail));
4881 n = (head - tail) & (CMDMAX - CMDSTART - 4);
4883 if (n <= ncmds * sizeof(struct cm_t))
4887 ch->ch_bd->state = BOARD_FAILED;
4894 /*=======================================================================
4896 * dgap_cmdw_ext - Sends a extended word command to the FEP.
4898 * ch - Pointer to channel structure.
4899 * cmd - Command to be sent.
4900 * word - Integer containing word to be sent.
4901 * ncmds - Wait until ncmds or fewer cmds are left
4902 * in the cmd buffer before returning.
4904 *=======================================================================*/
4905 static void dgap_cmdw_ext(struct channel_t *ch, u16 cmd, u16 word, uint ncmds)
4908 struct cm_t *cm_addr = NULL;
4914 if (!ch || ch->magic != DGAP_CHANNEL_MAGIC)
4918 * Check if board is still alive.
4920 if (ch->ch_bd->state == BOARD_FAILED)
4924 * Make sure the pointers are in range before
4925 * writing to the FEP memory.
4927 vaddr = ch->ch_bd->re_map_membase;
4931 cm_addr = (struct cm_t *) (vaddr + CMDBUF);
4932 head = readw(&(cm_addr->cm_head));
4935 * Forget it if pointers out of range.
4937 if (head >= (CMDMAX - CMDSTART) || (head & 03)) {
4938 ch->ch_bd->state = BOARD_FAILED;
4943 * Put the data in the circular command buffer.
4946 /* Write an FF to tell the FEP that we want an extended command */
4947 writeb((u8) 0xff, (char *) (vaddr + head + CMDSTART + 0));
4949 writeb((u8) ch->ch_portnum, (u8 *) (vaddr + head + CMDSTART + 1));
4950 writew((u16) cmd, (char *) (vaddr + head + CMDSTART + 2));
4953 * If the second part of the command won't fit,
4954 * put it at the beginning of the circular buffer.
4956 if (((head + 4) >= ((CMDMAX - CMDSTART)) || (head & 03)))
4957 writew((u16) word, (char *) (vaddr + CMDSTART));
4959 writew((u16) word, (char *) (vaddr + head + CMDSTART + 4));
4961 head = (head + 8) & (CMDMAX - CMDSTART - 4);
4963 writew(head, &(cm_addr->cm_head));
4966 * Wait if necessary before updating the head
4967 * pointer to limit the number of outstanding
4968 * commands to the FEP. If the time spent waiting
4969 * is outlandish, declare the FEP dead.
4971 for (count = dgap_count ;;) {
4973 head = readw(&(cm_addr->cm_head));
4974 tail = readw(&(cm_addr->cm_tail));
4976 n = (head - tail) & (CMDMAX - CMDSTART - 4);
4978 if (n <= ncmds * sizeof(struct cm_t))
4982 ch->ch_bd->state = BOARD_FAILED;
4989 /*=======================================================================
4991 * dgap_wmove - Write data to FEP buffer.
4993 * ch - Pointer to channel structure.
4994 * buf - Poiter to characters to be moved.
4995 * cnt - Number of characters to move.
4997 *=======================================================================*/
4998 static void dgap_wmove(struct channel_t *ch, char *buf, uint cnt)
5005 if (!ch || ch->magic != DGAP_CHANNEL_MAGIC)
5012 head = readw(&(bs->tx_head));
5015 * If pointers are out of range, just return.
5017 if ((cnt > ch->ch_tsize) ||
5018 (unsigned)(head - ch->ch_tstart) >= ch->ch_tsize)
5022 * If the write wraps over the top of the circular buffer,
5023 * move the portion up to the wrap point, and reset the
5024 * pointers to the bottom.
5026 n = ch->ch_tstart + ch->ch_tsize - head;
5030 taddr = ch->ch_taddr + head;
5031 memcpy_toio(taddr, buf, n);
5032 head = ch->ch_tstart;
5037 * Move rest of data.
5039 taddr = ch->ch_taddr + head;
5041 memcpy_toio(taddr, buf, n);
5044 writew(head, &(bs->tx_head));
5048 * Retrives the current custom baud rate from FEP memory,
5049 * and returns it back to the user.
5050 * Returns 0 on error.
5052 static uint dgap_get_custom_baud(struct channel_t *ch)
5058 if (!ch || ch->magic != DGAP_CHANNEL_MAGIC)
5061 if (!ch->ch_bd || ch->ch_bd->magic != DGAP_BOARD_MAGIC)
5064 if (!(ch->ch_bd->bd_flags & BD_FEP5PLUS))
5067 vaddr = ch->ch_bd->re_map_membase;
5073 * Go get from fep mem, what the fep
5074 * believes the custom baud rate is.
5076 offset = ((((*(unsigned short *)(vaddr + ECS_SEG)) << 4) +
5077 (ch->ch_portnum * 0x28) + LINE_SPEED));
5079 value = readw(vaddr + offset);
5084 * Calls the firmware to reset this channel.
5086 static void dgap_firmware_reset_port(struct channel_t *ch)
5088 dgap_cmdb(ch, CHRESET, 0, 0, 0);
5091 * Now that the channel is reset, we need to make sure
5092 * all the current settings get reapplied to the port
5095 * So we will set the driver's cache of firmware
5096 * settings all to 0, and then call param.
5098 ch->ch_fepiflag = 0;
5099 ch->ch_fepcflag = 0;
5100 ch->ch_fepoflag = 0;
5101 ch->ch_fepstartc = 0;
5102 ch->ch_fepstopc = 0;
5103 ch->ch_fepastartc = 0;
5104 ch->ch_fepastopc = 0;
5109 /*=======================================================================
5111 * dgap_param - Set Digi parameters.
5113 * struct tty_struct * - TTY for port.
5115 *=======================================================================*/
5116 static int dgap_param(struct tty_struct *tty)
5118 struct ktermios *ts;
5120 struct channel_t *ch;
5129 if (!tty || tty->magic != TTY_MAGIC)
5132 un = (struct un_t *) tty->driver_data;
5133 if (!un || un->magic != DGAP_UNIT_MAGIC)
5137 if (!ch || ch->magic != DGAP_CHANNEL_MAGIC)
5141 if (!bd || bd->magic != DGAP_BOARD_MAGIC)
5151 * If baud rate is zero, flush queues, and set mval to drop DTR.
5153 if ((ch->ch_c_cflag & (CBAUD)) == 0) {
5156 head = readw(&(ch->ch_bs->rx_head));
5157 writew(head, &(ch->ch_bs->rx_tail));
5160 head = readw(&(ch->ch_bs->tx_head));
5161 writew(head, &(ch->ch_bs->tx_tail));
5163 ch->ch_flags |= (CH_BAUD0);
5165 /* Drop RTS and DTR */
5166 ch->ch_mval &= ~(D_RTS(ch)|D_DTR(ch));
5167 mval = D_DTR(ch) | D_RTS(ch);
5168 ch->ch_baud_info = 0;
5170 } else if (ch->ch_custom_speed && (bd->bd_flags & BD_FEP5PLUS)) {
5172 * Tell the fep to do the command
5175 dgap_cmdw_ext(ch, 0xff01, ch->ch_custom_speed, 0);
5178 * Now go get from fep mem, what the fep
5179 * believes the custom baud rate is.
5181 ch->ch_custom_speed = dgap_get_custom_baud(ch);
5182 ch->ch_baud_info = ch->ch_custom_speed;
5184 /* Handle transition from B0 */
5185 if (ch->ch_flags & CH_BAUD0) {
5186 ch->ch_flags &= ~(CH_BAUD0);
5187 ch->ch_mval |= (D_RTS(ch)|D_DTR(ch));
5189 mval = D_DTR(ch) | D_RTS(ch);
5193 * Set baud rate, character size, and parity.
5201 ulong bauds[4][16] = {
5205 600, 1200, 1800, 2400,
5206 4800, 9600, 19200, 38400 },
5207 { /* slowbaud & CBAUDEX */
5208 0, 57600, 115200, 230400,
5209 460800, 150, 200, 921600,
5210 600, 1200, 1800, 2400,
5211 4800, 9600, 19200, 38400 },
5213 0, 57600, 76800, 115200,
5214 14400, 57600, 230400, 76800,
5215 115200, 230400, 28800, 460800,
5216 921600, 9600, 19200, 38400 },
5217 { /* fastbaud & CBAUDEX */
5218 0, 57600, 115200, 230400,
5219 460800, 150, 200, 921600,
5220 600, 1200, 1800, 2400,
5221 4800, 9600, 19200, 38400 }
5225 * Only use the TXPrint baud rate if the
5226 * terminal unit is NOT open
5228 if (!(ch->ch_tun.un_flags & UN_ISOPEN) &&
5229 (un->un_type == DGAP_PRINT))
5230 baud = C_BAUD(ch->ch_pun.un_tty) & 0xff;
5232 baud = C_BAUD(ch->ch_tun.un_tty) & 0xff;
5234 if (ch->ch_c_cflag & CBAUDEX)
5237 if (ch->ch_digi.digi_flags & DIGI_FAST)
5242 if ((iindex >= 0) && (iindex < 4) &&
5243 (jindex >= 0) && (jindex < 16))
5244 baud = bauds[iindex][jindex];
5251 ch->ch_baud_info = baud;
5254 * CBAUD has bit position 0x1000 set these days to
5255 * indicate Linux baud rate remap.
5256 * We use a different bit assignment for high speed.
5257 * Clear this bit out while grabbing the parts of
5260 cflag = ch->ch_c_cflag & ((CBAUD ^ CBAUDEX) | PARODD | PARENB |
5264 * HUPCL bit is used by FEP to indicate fast baud
5265 * table is to be used.
5267 if ((ch->ch_digi.digi_flags & DIGI_FAST) ||
5268 (ch->ch_c_cflag & CBAUDEX))
5271 if ((ch->ch_c_cflag & CBAUDEX) &&
5272 !(ch->ch_digi.digi_flags & DIGI_FAST)) {
5274 * The below code is trying to guarantee that only
5275 * baud rates 115200, 230400, 460800, 921600 are
5276 * remapped. We use exclusive or because the various
5277 * baud rates share common bit positions and therefore
5278 * can't be tested for easily.
5280 tcflag_t tcflag = (ch->ch_c_cflag & CBAUD) | CBAUDEX;
5284 * Map high speed requests to index
5285 * into FEP's baud table
5315 cflag = (cflag & ~(CBAUD | CBAUDEX)) | baudpart;
5320 if (cflag != ch->ch_fepcflag) {
5321 ch->ch_fepcflag = (u16) (cflag & 0xffff);
5324 * Okay to have channel and board
5325 * locks held calling this
5327 dgap_cmdw(ch, SCFLAG, (u16) cflag, 0);
5330 /* Handle transition from B0 */
5331 if (ch->ch_flags & CH_BAUD0) {
5332 ch->ch_flags &= ~(CH_BAUD0);
5333 ch->ch_mval |= (D_RTS(ch)|D_DTR(ch));
5335 mval = D_DTR(ch) | D_RTS(ch);
5341 iflag = ch->ch_c_iflag & (IGNBRK | BRKINT | IGNPAR | PARMRK |
5342 INPCK | ISTRIP | IXON | IXANY | IXOFF);
5344 if ((ch->ch_startc == _POSIX_VDISABLE) ||
5345 (ch->ch_stopc == _POSIX_VDISABLE)) {
5346 iflag &= ~(IXON | IXOFF);
5347 ch->ch_c_iflag &= ~(IXON | IXOFF);
5351 * Only the IBM Xr card can switch between
5352 * 232 and 422 modes on the fly
5354 if (bd->device == PCI_DEV_XR_IBM_DID) {
5355 if (ch->ch_digi.digi_flags & DIGI_422)
5356 dgap_cmdb(ch, SCOMMODE, MODE_422, 0, 0);
5358 dgap_cmdb(ch, SCOMMODE, MODE_232, 0, 0);
5361 if (ch->ch_digi.digi_flags & DIGI_ALTPIN)
5364 if (iflag != ch->ch_fepiflag) {
5365 ch->ch_fepiflag = iflag;
5367 /* Okay to have channel and board locks held calling this */
5368 dgap_cmdw(ch, SIFLAG, (u16) ch->ch_fepiflag, 0);
5372 * Select hardware handshaking.
5376 if (ch->ch_c_cflag & CRTSCTS)
5377 hflow |= (D_RTS(ch) | D_CTS(ch));
5378 if (ch->ch_digi.digi_flags & RTSPACE)
5380 if (ch->ch_digi.digi_flags & DTRPACE)
5382 if (ch->ch_digi.digi_flags & CTSPACE)
5384 if (ch->ch_digi.digi_flags & DSRPACE)
5386 if (ch->ch_digi.digi_flags & DCDPACE)
5389 if (hflow != ch->ch_hflow) {
5390 ch->ch_hflow = hflow;
5392 /* Okay to have channel and board locks held calling this */
5393 dgap_cmdb(ch, SHFLOW, (u8) hflow, 0xff, 0);
5398 * Set RTS and/or DTR Toggle if needed,
5399 * but only if product is FEP5+ based.
5401 if (bd->bd_flags & BD_FEP5PLUS) {
5403 if (ch->ch_digi.digi_flags & DIGI_RTS_TOGGLE)
5404 hflow2 |= (D_RTS(ch));
5405 if (ch->ch_digi.digi_flags & DIGI_DTR_TOGGLE)
5406 hflow2 |= (D_DTR(ch));
5408 dgap_cmdw_ext(ch, 0xff03, hflow2, 0);
5412 * Set modem control lines.
5415 mval ^= ch->ch_mforce & (mval ^ ch->ch_mval);
5417 if (ch->ch_mostat ^ mval) {
5418 ch->ch_mostat = mval;
5420 /* Okay to have channel and board locks held calling this */
5421 dgap_cmdb(ch, SMODEM, (u8) mval, D_RTS(ch)|D_DTR(ch), 0);
5425 * Read modem signals, and then call carrier function.
5427 ch->ch_mistat = readb(&(bs->m_stat));
5431 * Set the start and stop characters.
5433 if (ch->ch_startc != ch->ch_fepstartc ||
5434 ch->ch_stopc != ch->ch_fepstopc) {
5435 ch->ch_fepstartc = ch->ch_startc;
5436 ch->ch_fepstopc = ch->ch_stopc;
5438 /* Okay to have channel and board locks held calling this */
5439 dgap_cmdb(ch, SFLOWC, ch->ch_fepstartc, ch->ch_fepstopc, 0);
5443 * Set the Auxiliary start and stop characters.
5445 if (ch->ch_astartc != ch->ch_fepastartc ||
5446 ch->ch_astopc != ch->ch_fepastopc) {
5447 ch->ch_fepastartc = ch->ch_astartc;
5448 ch->ch_fepastopc = ch->ch_astopc;
5450 /* Okay to have channel and board locks held calling this */
5451 dgap_cmdb(ch, SAFLOWC, ch->ch_fepastartc, ch->ch_fepastopc, 0);
5458 * dgap_parity_scan()
5460 * Convert the FEP5 way of reporting parity errors and breaks into
5461 * the Linux line discipline way.
5463 static void dgap_parity_scan(struct channel_t *ch, unsigned char *cbuf,
5464 unsigned char *fbuf, int *len)
5468 unsigned char *in, *cout, *fout;
5475 if (!ch || ch->magic != DGAP_CHANNEL_MAGIC)
5480 switch (ch->pscan_state) {
5482 /* reset to sanity and fall through */
5483 ch->pscan_state = 0;
5486 /* No FF seen yet */
5487 if (c == (unsigned char) '\377')
5488 /* delete this character from stream */
5489 ch->pscan_state = 1;
5492 *fout++ = TTY_NORMAL;
5499 if (c == (unsigned char) '\377') {
5500 /* doubled ff, transform to single ff */
5502 *fout++ = TTY_NORMAL;
5504 ch->pscan_state = 0;
5506 /* save value examination in next state */
5507 ch->pscan_savechar = c;
5508 ch->pscan_state = 2;
5513 /* third character of ff sequence */
5517 if (ch->pscan_savechar == 0x0) {
5521 *fout++ = TTY_BREAK;
5523 ch->ch_err_parity++;
5524 *fout++ = TTY_PARITY;
5529 ch->pscan_state = 0;
5535 static void dgap_write_wakeup(struct board_t *bd, struct channel_t *ch,
5536 struct un_t *un, u32 mask,
5537 unsigned long *irq_flags1,
5538 unsigned long *irq_flags2)
5540 if (!(un->un_flags & mask))
5543 un->un_flags &= ~mask;
5545 if (!(un->un_flags & UN_ISOPEN))
5548 if ((un->un_tty->flags & (1 << TTY_DO_WRITE_WAKEUP)) &&
5549 un->un_tty->ldisc->ops->write_wakeup) {
5550 spin_unlock_irqrestore(&ch->ch_lock, *irq_flags2);
5551 spin_unlock_irqrestore(&bd->bd_lock, *irq_flags1);
5553 (un->un_tty->ldisc->ops->write_wakeup)(un->un_tty);
5555 spin_lock_irqsave(&bd->bd_lock, *irq_flags1);
5556 spin_lock_irqsave(&ch->ch_lock, *irq_flags2);
5558 wake_up_interruptible(&un->un_tty->write_wait);
5559 wake_up_interruptible(&un->un_flags_wait);
5562 /*=======================================================================
5564 * dgap_event - FEP to host event processing routine.
5566 * bd - Board of current event.
5568 *=======================================================================*/
5569 static int dgap_event(struct board_t *bd)
5571 struct channel_t *ch;
5577 struct ev_t *eaddr = NULL;
5585 if (!bd || bd->magic != DGAP_BOARD_MAGIC)
5588 spin_lock_irqsave(&bd->bd_lock, lock_flags);
5590 vaddr = bd->re_map_membase;
5593 spin_unlock_irqrestore(&bd->bd_lock, lock_flags);
5597 eaddr = (struct ev_t *) (vaddr + EVBUF);
5599 /* Get our head and tail */
5600 head = readw(&(eaddr->ev_head));
5601 tail = readw(&(eaddr->ev_tail));
5604 * Forget it if pointers out of range.
5607 if (head >= EVMAX - EVSTART || tail >= EVMAX - EVSTART ||
5608 (head | tail) & 03) {
5609 /* Let go of board lock */
5610 spin_unlock_irqrestore(&bd->bd_lock, lock_flags);
5615 * Loop to process all the events in the buffer.
5617 while (tail != head) {
5620 * Get interrupt information.
5623 event = bd->re_map_membase + tail + EVSTART;
5631 * Make sure the interrupt is valid.
5633 if (port >= bd->nasync)
5636 if (!(reason & (IFMODEM | IFBREAK | IFTLW | IFTEM | IFDATA)))
5639 ch = bd->channels[port];
5641 if (!ch || ch->magic != DGAP_CHANNEL_MAGIC)
5645 * If we have made it here, the event was valid.
5646 * Lock down the channel.
5648 spin_lock_irqsave(&ch->ch_lock, lock_flags2);
5653 spin_unlock_irqrestore(&ch->ch_lock, lock_flags2);
5658 * Process received data.
5660 if (reason & IFDATA) {
5663 * ALL LOCKS *MUST* BE DROPPED BEFORE CALLING INPUT!
5664 * input could send some data to ld, which in turn
5665 * could do a callback to one of our other functions.
5667 spin_unlock_irqrestore(&ch->ch_lock, lock_flags2);
5668 spin_unlock_irqrestore(&bd->bd_lock, lock_flags);
5672 spin_lock_irqsave(&bd->bd_lock, lock_flags);
5673 spin_lock_irqsave(&ch->ch_lock, lock_flags2);
5675 if (ch->ch_flags & CH_RACTIVE)
5676 ch->ch_flags |= CH_RENABLE;
5678 writeb(1, &(bs->idata));
5680 if (ch->ch_flags & CH_RWAIT) {
5681 ch->ch_flags &= ~CH_RWAIT;
5683 wake_up_interruptible
5684 (&ch->ch_tun.un_flags_wait);
5689 * Process Modem change signals.
5691 if (reason & IFMODEM) {
5692 ch->ch_mistat = modem;
5699 if (reason & IFBREAK) {
5701 if (ch->ch_tun.un_tty) {
5702 /* A break has been indicated */
5704 tty_buffer_request_room
5705 (ch->ch_tun.un_tty->port, 1);
5706 tty_insert_flip_char(ch->ch_tun.un_tty->port,
5708 tty_flip_buffer_push(ch->ch_tun.un_tty->port);
5713 * Process Transmit low.
5715 if (reason & IFTLW) {
5716 dgap_write_wakeup(bd, ch, &ch->ch_tun, UN_LOW,
5717 &lock_flags, &lock_flags2);
5718 dgap_write_wakeup(bd, ch, &ch->ch_pun, UN_LOW,
5719 &lock_flags, &lock_flags2);
5720 if (ch->ch_flags & CH_WLOW) {
5721 ch->ch_flags &= ~CH_WLOW;
5722 wake_up_interruptible(&ch->ch_flags_wait);
5727 * Process Transmit empty.
5729 if (reason & IFTEM) {
5730 dgap_write_wakeup(bd, ch, &ch->ch_tun, UN_EMPTY,
5731 &lock_flags, &lock_flags2);
5732 dgap_write_wakeup(bd, ch, &ch->ch_pun, UN_EMPTY,
5733 &lock_flags, &lock_flags2);
5734 if (ch->ch_flags & CH_WEMPTY) {
5735 ch->ch_flags &= ~CH_WEMPTY;
5736 wake_up_interruptible(&ch->ch_flags_wait);
5740 spin_unlock_irqrestore(&ch->ch_lock, lock_flags2);
5743 tail = (tail + 4) & (EVMAX - EVSTART - 4);
5746 writew(tail, &(eaddr->ev_tail));
5747 spin_unlock_irqrestore(&bd->bd_lock, lock_flags);
5752 static ssize_t dgap_driver_version_show(struct device_driver *ddp, char *buf)
5754 return snprintf(buf, PAGE_SIZE, "%s\n", DG_PART);
5756 static DRIVER_ATTR(version, S_IRUSR, dgap_driver_version_show, NULL);
5759 static ssize_t dgap_driver_boards_show(struct device_driver *ddp, char *buf)
5761 return snprintf(buf, PAGE_SIZE, "%d\n", dgap_NumBoards);
5763 static DRIVER_ATTR(boards, S_IRUSR, dgap_driver_boards_show, NULL);
5766 static ssize_t dgap_driver_maxboards_show(struct device_driver *ddp, char *buf)
5768 return snprintf(buf, PAGE_SIZE, "%d\n", MAXBOARDS);
5770 static DRIVER_ATTR(maxboards, S_IRUSR, dgap_driver_maxboards_show, NULL);
5773 static ssize_t dgap_driver_pollcounter_show(struct device_driver *ddp,
5776 return snprintf(buf, PAGE_SIZE, "%ld\n", dgap_poll_counter);
5778 static DRIVER_ATTR(pollcounter, S_IRUSR, dgap_driver_pollcounter_show, NULL);
5780 static ssize_t dgap_driver_pollrate_show(struct device_driver *ddp, char *buf)
5782 return snprintf(buf, PAGE_SIZE, "%dms\n", dgap_poll_tick);
5785 static ssize_t dgap_driver_pollrate_store(struct device_driver *ddp,
5786 const char *buf, size_t count)
5788 if (sscanf(buf, "%d\n", &dgap_poll_tick) != 1)
5792 static DRIVER_ATTR(pollrate, (S_IRUSR | S_IWUSR), dgap_driver_pollrate_show,
5793 dgap_driver_pollrate_store);
5795 static int dgap_create_driver_sysfiles(struct pci_driver *dgap_driver)
5798 struct device_driver *driverfs = &dgap_driver->driver;
5800 rc |= driver_create_file(driverfs, &driver_attr_version);
5801 rc |= driver_create_file(driverfs, &driver_attr_boards);
5802 rc |= driver_create_file(driverfs, &driver_attr_maxboards);
5803 rc |= driver_create_file(driverfs, &driver_attr_pollrate);
5804 rc |= driver_create_file(driverfs, &driver_attr_pollcounter);
5809 static void dgap_remove_driver_sysfiles(struct pci_driver *dgap_driver)
5811 struct device_driver *driverfs = &dgap_driver->driver;
5812 driver_remove_file(driverfs, &driver_attr_version);
5813 driver_remove_file(driverfs, &driver_attr_boards);
5814 driver_remove_file(driverfs, &driver_attr_maxboards);
5815 driver_remove_file(driverfs, &driver_attr_pollrate);
5816 driver_remove_file(driverfs, &driver_attr_pollcounter);
5819 static struct board_t *dgap_verify_board(struct device *p)
5826 bd = dev_get_drvdata(p);
5827 if (!bd || bd->magic != DGAP_BOARD_MAGIC || bd->state != BOARD_READY)
5833 static ssize_t dgap_ports_state_show(struct device *p,
5834 struct device_attribute *attr,
5841 bd = dgap_verify_board(p);
5845 for (i = 0; i < bd->nasync; i++) {
5846 count += snprintf(buf + count, PAGE_SIZE - count,
5847 "%d %s\n", bd->channels[i]->ch_portnum,
5848 bd->channels[i]->ch_open_count ? "Open" : "Closed");
5852 static DEVICE_ATTR(ports_state, S_IRUSR, dgap_ports_state_show, NULL);
5854 static ssize_t dgap_ports_baud_show(struct device *p,
5855 struct device_attribute *attr,
5862 bd = dgap_verify_board(p);
5866 for (i = 0; i < bd->nasync; i++) {
5867 count += snprintf(buf + count, PAGE_SIZE - count, "%d %d\n",
5868 bd->channels[i]->ch_portnum,
5869 bd->channels[i]->ch_baud_info);
5873 static DEVICE_ATTR(ports_baud, S_IRUSR, dgap_ports_baud_show, NULL);
5875 static ssize_t dgap_ports_msignals_show(struct device *p,
5876 struct device_attribute *attr,
5883 bd = dgap_verify_board(p);
5887 for (i = 0; i < bd->nasync; i++) {
5888 if (bd->channels[i]->ch_open_count)
5889 count += snprintf(buf + count, PAGE_SIZE - count,
5890 "%d %s %s %s %s %s %s\n",
5891 bd->channels[i]->ch_portnum,
5892 (bd->channels[i]->ch_mostat &
5893 UART_MCR_RTS) ? "RTS" : "",
5894 (bd->channels[i]->ch_mistat &
5895 UART_MSR_CTS) ? "CTS" : "",
5896 (bd->channels[i]->ch_mostat &
5897 UART_MCR_DTR) ? "DTR" : "",
5898 (bd->channels[i]->ch_mistat &
5899 UART_MSR_DSR) ? "DSR" : "",
5900 (bd->channels[i]->ch_mistat &
5901 UART_MSR_DCD) ? "DCD" : "",
5902 (bd->channels[i]->ch_mistat &
5903 UART_MSR_RI) ? "RI" : "");
5905 count += snprintf(buf + count, PAGE_SIZE - count,
5906 "%d\n", bd->channels[i]->ch_portnum);
5910 static DEVICE_ATTR(ports_msignals, S_IRUSR, dgap_ports_msignals_show, NULL);
5912 static ssize_t dgap_ports_iflag_show(struct device *p,
5913 struct device_attribute *attr,
5920 bd = dgap_verify_board(p);
5924 for (i = 0; i < bd->nasync; i++)
5925 count += snprintf(buf + count, PAGE_SIZE - count, "%d %x\n",
5926 bd->channels[i]->ch_portnum,
5927 bd->channels[i]->ch_c_iflag);
5930 static DEVICE_ATTR(ports_iflag, S_IRUSR, dgap_ports_iflag_show, NULL);
5932 static ssize_t dgap_ports_cflag_show(struct device *p,
5933 struct device_attribute *attr,
5940 bd = dgap_verify_board(p);
5944 for (i = 0; i < bd->nasync; i++)
5945 count += snprintf(buf + count, PAGE_SIZE - count, "%d %x\n",
5946 bd->channels[i]->ch_portnum,
5947 bd->channels[i]->ch_c_cflag);
5950 static DEVICE_ATTR(ports_cflag, S_IRUSR, dgap_ports_cflag_show, NULL);
5952 static ssize_t dgap_ports_oflag_show(struct device *p,
5953 struct device_attribute *attr,
5960 bd = dgap_verify_board(p);
5964 for (i = 0; i < bd->nasync; i++)
5965 count += snprintf(buf + count, PAGE_SIZE - count, "%d %x\n",
5966 bd->channels[i]->ch_portnum,
5967 bd->channels[i]->ch_c_oflag);
5970 static DEVICE_ATTR(ports_oflag, S_IRUSR, dgap_ports_oflag_show, NULL);
5972 static ssize_t dgap_ports_lflag_show(struct device *p,
5973 struct device_attribute *attr,
5980 bd = dgap_verify_board(p);
5984 for (i = 0; i < bd->nasync; i++)
5985 count += snprintf(buf + count, PAGE_SIZE - count, "%d %x\n",
5986 bd->channels[i]->ch_portnum,
5987 bd->channels[i]->ch_c_lflag);
5990 static DEVICE_ATTR(ports_lflag, S_IRUSR, dgap_ports_lflag_show, NULL);
5992 static ssize_t dgap_ports_digi_flag_show(struct device *p,
5993 struct device_attribute *attr,
6000 bd = dgap_verify_board(p);
6004 for (i = 0; i < bd->nasync; i++)
6005 count += snprintf(buf + count, PAGE_SIZE - count, "%d %x\n",
6006 bd->channels[i]->ch_portnum,
6007 bd->channels[i]->ch_digi.digi_flags);
6010 static DEVICE_ATTR(ports_digi_flag, S_IRUSR, dgap_ports_digi_flag_show, NULL);
6012 static ssize_t dgap_ports_rxcount_show(struct device *p,
6013 struct device_attribute *attr,
6020 bd = dgap_verify_board(p);
6024 for (i = 0; i < bd->nasync; i++)
6025 count += snprintf(buf + count, PAGE_SIZE - count, "%d %ld\n",
6026 bd->channels[i]->ch_portnum,
6027 bd->channels[i]->ch_rxcount);
6030 static DEVICE_ATTR(ports_rxcount, S_IRUSR, dgap_ports_rxcount_show, NULL);
6032 static ssize_t dgap_ports_txcount_show(struct device *p,
6033 struct device_attribute *attr,
6040 bd = dgap_verify_board(p);
6044 for (i = 0; i < bd->nasync; i++)
6045 count += snprintf(buf + count, PAGE_SIZE - count, "%d %ld\n",
6046 bd->channels[i]->ch_portnum,
6047 bd->channels[i]->ch_txcount);
6050 static DEVICE_ATTR(ports_txcount, S_IRUSR, dgap_ports_txcount_show, NULL);
6052 /* this function creates the sys files that will export each signal status
6053 * to sysfs each value will be put in a separate filename
6055 static void dgap_create_ports_sysfiles(struct board_t *bd)
6057 dev_set_drvdata(&bd->pdev->dev, bd);
6058 device_create_file(&(bd->pdev->dev), &dev_attr_ports_state);
6059 device_create_file(&(bd->pdev->dev), &dev_attr_ports_baud);
6060 device_create_file(&(bd->pdev->dev), &dev_attr_ports_msignals);
6061 device_create_file(&(bd->pdev->dev), &dev_attr_ports_iflag);
6062 device_create_file(&(bd->pdev->dev), &dev_attr_ports_cflag);
6063 device_create_file(&(bd->pdev->dev), &dev_attr_ports_oflag);
6064 device_create_file(&(bd->pdev->dev), &dev_attr_ports_lflag);
6065 device_create_file(&(bd->pdev->dev), &dev_attr_ports_digi_flag);
6066 device_create_file(&(bd->pdev->dev), &dev_attr_ports_rxcount);
6067 device_create_file(&(bd->pdev->dev), &dev_attr_ports_txcount);
6070 /* removes all the sys files created for that port */
6071 static void dgap_remove_ports_sysfiles(struct board_t *bd)
6073 device_remove_file(&(bd->pdev->dev), &dev_attr_ports_state);
6074 device_remove_file(&(bd->pdev->dev), &dev_attr_ports_baud);
6075 device_remove_file(&(bd->pdev->dev), &dev_attr_ports_msignals);
6076 device_remove_file(&(bd->pdev->dev), &dev_attr_ports_iflag);
6077 device_remove_file(&(bd->pdev->dev), &dev_attr_ports_cflag);
6078 device_remove_file(&(bd->pdev->dev), &dev_attr_ports_oflag);
6079 device_remove_file(&(bd->pdev->dev), &dev_attr_ports_lflag);
6080 device_remove_file(&(bd->pdev->dev), &dev_attr_ports_digi_flag);
6081 device_remove_file(&(bd->pdev->dev), &dev_attr_ports_rxcount);
6082 device_remove_file(&(bd->pdev->dev), &dev_attr_ports_txcount);
6085 static ssize_t dgap_tty_state_show(struct device *d,
6086 struct device_attribute *attr,
6090 struct channel_t *ch;
6095 un = dev_get_drvdata(d);
6096 if (!un || un->magic != DGAP_UNIT_MAGIC)
6099 if (!ch || ch->magic != DGAP_CHANNEL_MAGIC)
6102 if (!bd || bd->magic != DGAP_BOARD_MAGIC)
6104 if (bd->state != BOARD_READY)
6107 return snprintf(buf, PAGE_SIZE, "%s", un->un_open_count ?
6110 static DEVICE_ATTR(state, S_IRUSR, dgap_tty_state_show, NULL);
6112 static ssize_t dgap_tty_baud_show(struct device *d,
6113 struct device_attribute *attr,
6117 struct channel_t *ch;
6122 un = dev_get_drvdata(d);
6123 if (!un || un->magic != DGAP_UNIT_MAGIC)
6126 if (!ch || ch->magic != DGAP_CHANNEL_MAGIC)
6129 if (!bd || bd->magic != DGAP_BOARD_MAGIC)
6131 if (bd->state != BOARD_READY)
6134 return snprintf(buf, PAGE_SIZE, "%d\n", ch->ch_baud_info);
6136 static DEVICE_ATTR(baud, S_IRUSR, dgap_tty_baud_show, NULL);
6138 static ssize_t dgap_tty_msignals_show(struct device *d,
6139 struct device_attribute *attr,
6143 struct channel_t *ch;
6148 un = dev_get_drvdata(d);
6149 if (!un || un->magic != DGAP_UNIT_MAGIC)
6152 if (!ch || ch->magic != DGAP_CHANNEL_MAGIC)
6155 if (!bd || bd->magic != DGAP_BOARD_MAGIC)
6157 if (bd->state != BOARD_READY)
6160 if (ch->ch_open_count) {
6161 return snprintf(buf, PAGE_SIZE, "%s %s %s %s %s %s\n",
6162 (ch->ch_mostat & UART_MCR_RTS) ? "RTS" : "",
6163 (ch->ch_mistat & UART_MSR_CTS) ? "CTS" : "",
6164 (ch->ch_mostat & UART_MCR_DTR) ? "DTR" : "",
6165 (ch->ch_mistat & UART_MSR_DSR) ? "DSR" : "",
6166 (ch->ch_mistat & UART_MSR_DCD) ? "DCD" : "",
6167 (ch->ch_mistat & UART_MSR_RI) ? "RI" : "");
6171 static DEVICE_ATTR(msignals, S_IRUSR, dgap_tty_msignals_show, NULL);
6173 static ssize_t dgap_tty_iflag_show(struct device *d,
6174 struct device_attribute *attr,
6178 struct channel_t *ch;
6183 un = dev_get_drvdata(d);
6184 if (!un || un->magic != DGAP_UNIT_MAGIC)
6187 if (!ch || ch->magic != DGAP_CHANNEL_MAGIC)
6190 if (!bd || bd->magic != DGAP_BOARD_MAGIC)
6192 if (bd->state != BOARD_READY)
6195 return snprintf(buf, PAGE_SIZE, "%x\n", ch->ch_c_iflag);
6197 static DEVICE_ATTR(iflag, S_IRUSR, dgap_tty_iflag_show, NULL);
6199 static ssize_t dgap_tty_cflag_show(struct device *d,
6200 struct device_attribute *attr,
6204 struct channel_t *ch;
6209 un = dev_get_drvdata(d);
6210 if (!un || un->magic != DGAP_UNIT_MAGIC)
6213 if (!ch || ch->magic != DGAP_CHANNEL_MAGIC)
6216 if (!bd || bd->magic != DGAP_BOARD_MAGIC)
6218 if (bd->state != BOARD_READY)
6221 return snprintf(buf, PAGE_SIZE, "%x\n", ch->ch_c_cflag);
6223 static DEVICE_ATTR(cflag, S_IRUSR, dgap_tty_cflag_show, NULL);
6225 static ssize_t dgap_tty_oflag_show(struct device *d,
6226 struct device_attribute *attr,
6230 struct channel_t *ch;
6235 un = dev_get_drvdata(d);
6236 if (!un || un->magic != DGAP_UNIT_MAGIC)
6239 if (!ch || ch->magic != DGAP_CHANNEL_MAGIC)
6242 if (!bd || bd->magic != DGAP_BOARD_MAGIC)
6244 if (bd->state != BOARD_READY)
6247 return snprintf(buf, PAGE_SIZE, "%x\n", ch->ch_c_oflag);
6249 static DEVICE_ATTR(oflag, S_IRUSR, dgap_tty_oflag_show, NULL);
6251 static ssize_t dgap_tty_lflag_show(struct device *d,
6252 struct device_attribute *attr,
6256 struct channel_t *ch;
6261 un = dev_get_drvdata(d);
6262 if (!un || un->magic != DGAP_UNIT_MAGIC)
6265 if (!ch || ch->magic != DGAP_CHANNEL_MAGIC)
6268 if (!bd || bd->magic != DGAP_BOARD_MAGIC)
6270 if (bd->state != BOARD_READY)
6273 return snprintf(buf, PAGE_SIZE, "%x\n", ch->ch_c_lflag);
6275 static DEVICE_ATTR(lflag, S_IRUSR, dgap_tty_lflag_show, NULL);
6277 static ssize_t dgap_tty_digi_flag_show(struct device *d,
6278 struct device_attribute *attr,
6282 struct channel_t *ch;
6287 un = dev_get_drvdata(d);
6288 if (!un || un->magic != DGAP_UNIT_MAGIC)
6291 if (!ch || ch->magic != DGAP_CHANNEL_MAGIC)
6294 if (!bd || bd->magic != DGAP_BOARD_MAGIC)
6296 if (bd->state != BOARD_READY)
6299 return snprintf(buf, PAGE_SIZE, "%x\n", ch->ch_digi.digi_flags);
6301 static DEVICE_ATTR(digi_flag, S_IRUSR, dgap_tty_digi_flag_show, NULL);
6303 static ssize_t dgap_tty_rxcount_show(struct device *d,
6304 struct device_attribute *attr,
6308 struct channel_t *ch;
6313 un = dev_get_drvdata(d);
6314 if (!un || un->magic != DGAP_UNIT_MAGIC)
6317 if (!ch || ch->magic != DGAP_CHANNEL_MAGIC)
6320 if (!bd || bd->magic != DGAP_BOARD_MAGIC)
6322 if (bd->state != BOARD_READY)
6325 return snprintf(buf, PAGE_SIZE, "%ld\n", ch->ch_rxcount);
6327 static DEVICE_ATTR(rxcount, S_IRUSR, dgap_tty_rxcount_show, NULL);
6329 static ssize_t dgap_tty_txcount_show(struct device *d,
6330 struct device_attribute *attr,
6334 struct channel_t *ch;
6339 un = dev_get_drvdata(d);
6340 if (!un || un->magic != DGAP_UNIT_MAGIC)
6343 if (!ch || ch->magic != DGAP_CHANNEL_MAGIC)
6346 if (!bd || bd->magic != DGAP_BOARD_MAGIC)
6348 if (bd->state != BOARD_READY)
6351 return snprintf(buf, PAGE_SIZE, "%ld\n", ch->ch_txcount);
6353 static DEVICE_ATTR(txcount, S_IRUSR, dgap_tty_txcount_show, NULL);
6355 static ssize_t dgap_tty_name_show(struct device *d,
6356 struct device_attribute *attr,
6360 struct channel_t *ch;
6364 struct cnode *cptr = NULL;
6372 un = dev_get_drvdata(d);
6373 if (!un || un->magic != DGAP_UNIT_MAGIC)
6376 if (!ch || ch->magic != DGAP_CHANNEL_MAGIC)
6379 if (!bd || bd->magic != DGAP_BOARD_MAGIC)
6381 if (bd->state != BOARD_READY)
6385 cn = ch->ch_portnum;
6387 for (cptr = bd->bd_config; cptr; cptr = cptr->next) {
6389 if ((cptr->type == BNODE) &&
6390 ((cptr->u.board.type == APORT2_920P) ||
6391 (cptr->u.board.type == APORT4_920P) ||
6392 (cptr->u.board.type == APORT8_920P) ||
6393 (cptr->u.board.type == PAPORT4) ||
6394 (cptr->u.board.type == PAPORT8))) {
6397 if (cptr->u.board.v_start)
6398 starto = cptr->u.board.start;
6403 if (cptr->type == TNODE && found == TRUE) {
6405 if (strstr(cptr->u.ttyname, "tty")) {
6406 ptr1 = cptr->u.ttyname;
6409 ptr1 = cptr->u.ttyname;
6411 for (i = 0; i < dgap_config_get_num_prts(bd); i++) {
6415 return snprintf(buf, PAGE_SIZE, "%s%s%02d\n",
6416 (un->un_type == DGAP_PRINT) ?
6422 if (cptr->type == CNODE) {
6424 for (i = 0; i < cptr->u.conc.nport; i++) {
6425 if (cn != (i + ncount))
6428 return snprintf(buf, PAGE_SIZE, "%s%s%02ld\n",
6429 (un->un_type == DGAP_PRINT) ?
6432 i + (cptr->u.conc.v_start ?
6433 cptr->u.conc.start : 1));
6436 ncount += cptr->u.conc.nport;
6439 if (cptr->type == MNODE) {
6441 for (i = 0; i < cptr->u.module.nport; i++) {
6442 if (cn != (i + ncount))
6445 return snprintf(buf, PAGE_SIZE, "%s%s%02ld\n",
6446 (un->un_type == DGAP_PRINT) ?
6449 i + (cptr->u.module.v_start ?
6450 cptr->u.module.start : 1));
6453 ncount += cptr->u.module.nport;
6458 return snprintf(buf, PAGE_SIZE, "%s_dgap_%d_%d\n",
6459 (un->un_type == DGAP_PRINT) ? "pr" : "tty", bn, cn);
6462 static DEVICE_ATTR(custom_name, S_IRUSR, dgap_tty_name_show, NULL);
6464 static struct attribute *dgap_sysfs_tty_entries[] = {
6465 &dev_attr_state.attr,
6466 &dev_attr_baud.attr,
6467 &dev_attr_msignals.attr,
6468 &dev_attr_iflag.attr,
6469 &dev_attr_cflag.attr,
6470 &dev_attr_oflag.attr,
6471 &dev_attr_lflag.attr,
6472 &dev_attr_digi_flag.attr,
6473 &dev_attr_rxcount.attr,
6474 &dev_attr_txcount.attr,
6475 &dev_attr_custom_name.attr,
6479 static struct attribute_group dgap_tty_attribute_group = {
6481 .attrs = dgap_sysfs_tty_entries,
6484 static void dgap_create_tty_sysfs(struct un_t *un, struct device *c)
6488 ret = sysfs_create_group(&c->kobj, &dgap_tty_attribute_group);
6492 dev_set_drvdata(c, un);
6496 static void dgap_remove_tty_sysfs(struct device *c)
6498 sysfs_remove_group(&c->kobj, &dgap_tty_attribute_group);
6502 * Parse a configuration file read into memory as a string.
6504 static int dgap_parsefile(char **in, int Remove)
6506 struct cnode *p, *brd, *line, *conc;
6512 brd = line = conc = NULL;
6514 /* perhaps we are adding to an existing list? */
6515 while (p->next != NULL)
6518 /* file must start with a BEGIN */
6519 while ((rc = dgap_gettok(in, p)) != BEGIN) {
6521 dgap_err("unexpected EOF");
6527 rc = dgap_gettok(in, p);
6529 dgap_err("unexpected EOF");
6535 dgap_err("unexpected end of file");
6538 case BEGIN: /* should only be 1 begin */
6539 dgap_err("unexpected config_begin\n");
6545 case BOARD: /* board info */
6546 if (dgap_checknode(p))
6548 p->next = dgap_newnode(BNODE);
6550 dgap_err("out of memory");
6555 p->u.board.status = dgap_savestring("No");
6561 case APORT2_920P: /* AccelePort_4 */
6562 if (p->type != BNODE) {
6563 dgap_err("unexpected Digi_2r_920 string");
6566 p->u.board.type = APORT2_920P;
6567 p->u.board.v_type = 1;
6570 case APORT4_920P: /* AccelePort_4 */
6571 if (p->type != BNODE) {
6572 dgap_err("unexpected Digi_4r_920 string");
6575 p->u.board.type = APORT4_920P;
6576 p->u.board.v_type = 1;
6579 case APORT8_920P: /* AccelePort_8 */
6580 if (p->type != BNODE) {
6581 dgap_err("unexpected Digi_8r_920 string");
6584 p->u.board.type = APORT8_920P;
6585 p->u.board.v_type = 1;
6588 case PAPORT4: /* AccelePort_4 PCI */
6589 if (p->type != BNODE) {
6590 dgap_err("unexpected Digi_4r(PCI) string");
6593 p->u.board.type = PAPORT4;
6594 p->u.board.v_type = 1;
6597 case PAPORT8: /* AccelePort_8 PCI */
6598 if (p->type != BNODE) {
6599 dgap_err("unexpected Digi_8r string");
6602 p->u.board.type = PAPORT8;
6603 p->u.board.v_type = 1;
6606 case PCX: /* PCI C/X */
6607 if (p->type != BNODE) {
6608 dgap_err("unexpected Digi_C/X_(PCI) string");
6611 p->u.board.type = PCX;
6612 p->u.board.v_type = 1;
6613 p->u.board.conc1 = 0;
6614 p->u.board.conc2 = 0;
6615 p->u.board.module1 = 0;
6616 p->u.board.module2 = 0;
6619 case PEPC: /* PCI EPC/X */
6620 if (p->type != BNODE) {
6621 dgap_err("unexpected \"Digi_EPC/X_(PCI)\" string");
6624 p->u.board.type = PEPC;
6625 p->u.board.v_type = 1;
6626 p->u.board.conc1 = 0;
6627 p->u.board.conc2 = 0;
6628 p->u.board.module1 = 0;
6629 p->u.board.module2 = 0;
6632 case PPCM: /* PCI/Xem */
6633 if (p->type != BNODE) {
6634 dgap_err("unexpected PCI/Xem string");
6637 p->u.board.type = PPCM;
6638 p->u.board.v_type = 1;
6639 p->u.board.conc1 = 0;
6640 p->u.board.conc2 = 0;
6643 case IO: /* i/o port */
6644 if (p->type != BNODE) {
6645 dgap_err("IO port only vaild for boards");
6648 s = dgap_getword(in);
6650 dgap_err("unexpected end of file");
6653 p->u.board.portstr = dgap_savestring(s);
6654 if (kstrtol(s, 0, &p->u.board.port)) {
6655 dgap_err("bad number for IO port");
6658 p->u.board.v_port = 1;
6661 case MEM: /* memory address */
6662 if (p->type != BNODE) {
6663 dgap_err("memory address only vaild for boards");
6666 s = dgap_getword(in);
6668 dgap_err("unexpected end of file");
6671 p->u.board.addrstr = dgap_savestring(s);
6672 if (kstrtoul(s, 0, &p->u.board.addr)) {
6673 dgap_err("bad number for memory address");
6676 p->u.board.v_addr = 1;
6679 case PCIINFO: /* pci information */
6680 if (p->type != BNODE) {
6681 dgap_err("memory address only vaild for boards");
6684 s = dgap_getword(in);
6686 dgap_err("unexpected end of file");
6689 p->u.board.pcibusstr = dgap_savestring(s);
6690 if (kstrtoul(s, 0, &p->u.board.pcibus)) {
6691 dgap_err("bad number for pci bus");
6694 p->u.board.v_pcibus = 1;
6695 s = dgap_getword(in);
6697 dgap_err("unexpected end of file");
6700 p->u.board.pcislotstr = dgap_savestring(s);
6701 if (kstrtoul(s, 0, &p->u.board.pcislot)) {
6702 dgap_err("bad number for pci slot");
6705 p->u.board.v_pcislot = 1;
6709 if (p->type != BNODE) {
6710 dgap_err("install method only vaild for boards");
6713 s = dgap_getword(in);
6715 dgap_err("unexpected end of file");
6718 p->u.board.method = dgap_savestring(s);
6719 p->u.board.v_method = 1;
6723 if (p->type != BNODE) {
6724 dgap_err("config status only vaild for boards");
6727 s = dgap_getword(in);
6729 dgap_err("unexpected end of file");
6732 p->u.board.status = dgap_savestring(s);
6735 case NPORTS: /* number of ports */
6736 if (p->type == BNODE) {
6737 s = dgap_getword(in);
6739 dgap_err("unexpected end of file");
6742 if (kstrtol(s, 0, &p->u.board.nport)) {
6743 dgap_err("bad number for number of ports");
6746 p->u.board.v_nport = 1;
6747 } else if (p->type == CNODE) {
6748 s = dgap_getword(in);
6750 dgap_err("unexpected end of file");
6753 if (kstrtol(s, 0, &p->u.conc.nport)) {
6754 dgap_err("bad number for number of ports");
6757 p->u.conc.v_nport = 1;
6758 } else if (p->type == MNODE) {
6759 s = dgap_getword(in);
6761 dgap_err("unexpected end of file");
6764 if (kstrtol(s, 0, &p->u.module.nport)) {
6765 dgap_err("bad number for number of ports");
6768 p->u.module.v_nport = 1;
6770 dgap_err("nports only valid for concentrators or modules");
6775 case ID: /* letter ID used in tty name */
6776 s = dgap_getword(in);
6778 dgap_err("unexpected end of file");
6782 p->u.board.status = dgap_savestring(s);
6784 if (p->type == CNODE) {
6785 p->u.conc.id = dgap_savestring(s);
6787 } else if (p->type == MNODE) {
6788 p->u.module.id = dgap_savestring(s);
6789 p->u.module.v_id = 1;
6791 dgap_err("id only valid for concentrators or modules");
6796 case STARTO: /* start offset of ID */
6797 if (p->type == BNODE) {
6798 s = dgap_getword(in);
6800 dgap_err("unexpected end of file");
6803 if (kstrtol(s, 0, &p->u.board.start)) {
6804 dgap_err("bad number for start of tty count");
6807 p->u.board.v_start = 1;
6808 } else if (p->type == CNODE) {
6809 s = dgap_getword(in);
6811 dgap_err("unexpected end of file");
6814 if (kstrtol(s, 0, &p->u.conc.start)) {
6815 dgap_err("bad number for start of tty count");
6818 p->u.conc.v_start = 1;
6819 } else if (p->type == MNODE) {
6820 s = dgap_getword(in);
6822 dgap_err("unexpected end of file");
6825 if (kstrtol(s, 0, &p->u.module.start)) {
6826 dgap_err("bad number for start of tty count");
6829 p->u.module.v_start = 1;
6831 dgap_err("start only valid for concentrators or modules");
6836 case TTYN: /* tty name prefix */
6837 if (dgap_checknode(p))
6839 p->next = dgap_newnode(TNODE);
6841 dgap_err("out of memory");
6845 s = dgap_getword(in);
6847 dgap_err("unexpeced end of file");
6850 p->u.ttyname = dgap_savestring(s);
6851 if (!p->u.ttyname) {
6852 dgap_err("out of memory");
6857 case CU: /* cu name prefix */
6858 if (dgap_checknode(p))
6860 p->next = dgap_newnode(CUNODE);
6862 dgap_err("out of memory");
6866 s = dgap_getword(in);
6868 dgap_err("unexpeced end of file");
6871 p->u.cuname = dgap_savestring(s);
6873 dgap_err("out of memory");
6878 case LINE: /* line information */
6879 if (dgap_checknode(p))
6882 dgap_err("must specify board before line info");
6885 switch (brd->u.board.type) {
6887 dgap_err("line not vaild for PC/em");
6890 p->next = dgap_newnode(LNODE);
6892 dgap_err("out of memory");
6901 case CONC: /* concentrator information */
6902 if (dgap_checknode(p))
6905 dgap_err("must specify line info before concentrator");
6908 p->next = dgap_newnode(CNODE);
6910 dgap_err("out of memory");
6916 brd->u.board.conc2++;
6918 brd->u.board.conc1++;
6922 case CX: /* c/x type concentrator */
6923 if (p->type != CNODE) {
6924 dgap_err("cx only valid for concentrators");
6927 p->u.conc.type = CX;
6928 p->u.conc.v_type = 1;
6931 case EPC: /* epc type concentrator */
6932 if (p->type != CNODE) {
6933 dgap_err("cx only valid for concentrators");
6936 p->u.conc.type = EPC;
6937 p->u.conc.v_type = 1;
6940 case MOD: /* EBI module */
6941 if (dgap_checknode(p))
6944 dgap_err("must specify board info before EBI modules");
6947 switch (brd->u.board.type) {
6953 dgap_err("must specify concentrator info before EBI module");
6957 p->next = dgap_newnode(MNODE);
6959 dgap_err("out of memory");
6964 brd->u.board.module2++;
6966 brd->u.board.module1++;
6970 case PORTS: /* ports type EBI module */
6971 if (p->type != MNODE) {
6972 dgap_err("ports only valid for EBI modules");
6975 p->u.module.type = PORTS;
6976 p->u.module.v_type = 1;
6979 case MODEM: /* ports type EBI module */
6980 if (p->type != MNODE) {
6981 dgap_err("modem only valid for modem modules");
6984 p->u.module.type = MODEM;
6985 p->u.module.v_type = 1;
6989 if (p->type == LNODE) {
6990 s = dgap_getword(in);
6992 dgap_err("unexpected end of file");
6995 p->u.line.cable = dgap_savestring(s);
6996 p->u.line.v_cable = 1;
7000 case SPEED: /* sync line speed indication */
7001 if (p->type == LNODE) {
7002 s = dgap_getword(in);
7004 dgap_err("unexpected end of file");
7007 if (kstrtol(s, 0, &p->u.line.speed)) {
7008 dgap_err("bad number for line speed");
7011 p->u.line.v_speed = 1;
7012 } else if (p->type == CNODE) {
7013 s = dgap_getword(in);
7015 dgap_err("unexpected end of file");
7018 if (kstrtol(s, 0, &p->u.conc.speed)) {
7019 dgap_err("bad number for line speed");
7022 p->u.conc.v_speed = 1;
7024 dgap_err("speed valid only for lines or concentrators.");
7030 if (p->type == CNODE) {
7031 s = dgap_getword(in);
7033 dgap_err("unexpected end of file");
7036 p->u.conc.connect = dgap_savestring(s);
7037 p->u.conc.v_connect = 1;
7040 case PRINT: /* transparent print name prefix */
7041 if (dgap_checknode(p))
7043 p->next = dgap_newnode(PNODE);
7045 dgap_err("out of memory");
7049 s = dgap_getword(in);
7051 dgap_err("unexpeced end of file");
7054 p->u.printname = dgap_savestring(s);
7055 if (!p->u.printname) {
7056 dgap_err("out of memory");
7061 case CMAJOR: /* major number */
7062 if (dgap_checknode(p))
7064 p->next = dgap_newnode(JNODE);
7066 dgap_err("out of memory");
7070 s = dgap_getword(in);
7072 dgap_err("unexpected end of file");
7075 if (kstrtol(s, 0, &p->u.majornumber)) {
7076 dgap_err("bad number for major number");
7081 case ALTPIN: /* altpin setting */
7082 if (dgap_checknode(p))
7084 p->next = dgap_newnode(ANODE);
7086 dgap_err("out of memory");
7090 s = dgap_getword(in);
7092 dgap_err("unexpected end of file");
7095 if (kstrtol(s, 0, &p->u.altpin)) {
7096 dgap_err("bad number for altpin");
7101 case USEINTR: /* enable interrupt setting */
7102 if (dgap_checknode(p))
7104 p->next = dgap_newnode(INTRNODE);
7106 dgap_err("out of memory");
7110 s = dgap_getword(in);
7112 dgap_err("unexpected end of file");
7115 if (kstrtol(s, 0, &p->u.useintr)) {
7116 dgap_err("bad number for useintr");
7121 case TTSIZ: /* size of tty structure */
7122 if (dgap_checknode(p))
7124 p->next = dgap_newnode(TSNODE);
7126 dgap_err("out of memory");
7130 s = dgap_getword(in);
7132 dgap_err("unexpected end of file");
7135 if (kstrtol(s, 0, &p->u.ttysize)) {
7136 dgap_err("bad number for ttysize");
7141 case CHSIZ: /* channel structure size */
7142 if (dgap_checknode(p))
7144 p->next = dgap_newnode(CSNODE);
7146 dgap_err("out of memory");
7150 s = dgap_getword(in);
7152 dgap_err("unexpected end of file");
7155 if (kstrtol(s, 0, &p->u.chsize)) {
7156 dgap_err("bad number for chsize");
7161 case BSSIZ: /* board structure size */
7162 if (dgap_checknode(p))
7164 p->next = dgap_newnode(BSNODE);
7166 dgap_err("out of memory");
7170 s = dgap_getword(in);
7172 dgap_err("unexpected end of file");
7175 if (kstrtol(s, 0, &p->u.bssize)) {
7176 dgap_err("bad number for bssize");
7181 case UNTSIZ: /* sched structure size */
7182 if (dgap_checknode(p))
7184 p->next = dgap_newnode(USNODE);
7186 dgap_err("out of memory");
7190 s = dgap_getword(in);
7192 dgap_err("unexpected end of file");
7195 if (kstrtol(s, 0, &p->u.unsize)) {
7196 dgap_err("bad number for schedsize");
7201 case F2SIZ: /* f2200 structure size */
7202 if (dgap_checknode(p))
7204 p->next = dgap_newnode(FSNODE);
7206 dgap_err("out of memory");
7210 s = dgap_getword(in);
7212 dgap_err("unexpected end of file");
7215 if (kstrtol(s, 0, &p->u.f2size)) {
7216 dgap_err("bad number for f2200size");
7221 case VPSIZ: /* vpix structure size */
7222 if (dgap_checknode(p))
7224 p->next = dgap_newnode(VSNODE);
7226 dgap_err("out of memory");
7230 s = dgap_getword(in);
7232 dgap_err("unexpected end of file");
7235 if (kstrtol(s, 0, &p->u.vpixsize)) {
7236 dgap_err("bad number for vpixsize");
7245 * dgap_sindex: much like index(), but it looks for a match of any character in
7246 * the group, and returns that position. If the first character is a ^, then
7247 * this will match the first occurrence not in that group.
7249 static char *dgap_sindex(char *string, char *group)
7253 if (!string || !group)
7254 return (char *) NULL;
7256 if (*group == '^') {
7258 for (; *string; string++) {
7259 for (ptr = group; *ptr; ptr++) {
7260 if (*ptr == *string)
7267 for (; *string; string++) {
7268 for (ptr = group; *ptr; ptr++) {
7269 if (*ptr == *string)
7275 return (char *) NULL;
7279 * Get a token from the input file; return 0 if end of file is reached
7281 static int dgap_gettok(char **in, struct cnode *p)
7286 if (strstr(dgap_cword, "boar")) {
7287 w = dgap_getword(in);
7288 snprintf(dgap_cword, MAXCWORD, "%s", w);
7289 for (t = dgap_tlist; t->token != 0; t++) {
7290 if (!strcmp(w, t->string))
7293 dgap_err("board !!type not specified");
7296 while ((w = dgap_getword(in))) {
7297 snprintf(dgap_cword, MAXCWORD, "%s", w);
7298 for (t = dgap_tlist; t->token != 0; t++) {
7299 if (!strcmp(w, t->string))
7308 * get a word from the input stream, also keep track of current line number.
7309 * words are separated by whitespace.
7311 static char *dgap_getword(char **in)
7313 char *ret_ptr = *in;
7315 char *ptr = dgap_sindex(*in, " \t\n");
7317 /* If no word found, return null */
7321 /* Mark new location for our buffer */
7325 /* Eat any extra spaces/tabs/newlines that might be present */
7326 while (*in && **in && ((**in == ' ') ||
7337 * print an error message, giving the line number in the file where
7338 * the error occurred.
7340 static void dgap_err(char *s)
7342 pr_err("dgap: parse: %s\n", s);
7346 * allocate a new configuration node of type t
7348 static struct cnode *dgap_newnode(int t)
7352 n = kmalloc(sizeof(struct cnode), GFP_ATOMIC);
7354 memset((char *)n, 0, sizeof(struct cnode));
7361 * dgap_checknode: see if all the necessary info has been supplied for a node
7362 * before creating the next node.
7364 static int dgap_checknode(struct cnode *p)
7368 if (p->u.board.v_type == 0) {
7369 dgap_err("board type !not specified");
7376 if (p->u.line.v_speed == 0) {
7377 dgap_err("line speed not specified");
7383 if (p->u.conc.v_type == 0) {
7384 dgap_err("concentrator type not specified");
7387 if (p->u.conc.v_speed == 0) {
7388 dgap_err("concentrator line speed not specified");
7391 if (p->u.conc.v_nport == 0) {
7392 dgap_err("number of ports on concentrator not specified");
7395 if (p->u.conc.v_id == 0) {
7396 dgap_err("concentrator id letter not specified");
7402 if (p->u.module.v_type == 0) {
7403 dgap_err("EBI module type not specified");
7406 if (p->u.module.v_nport == 0) {
7407 dgap_err("number of ports on EBI module not specified");
7410 if (p->u.module.v_id == 0) {
7411 dgap_err("EBI module id letter not specified");
7420 * save a string somewhere
7422 static char *dgap_savestring(char *s)
7426 p = kmalloc(strlen(s) + 1, GFP_ATOMIC);
7433 * Given a board pointer, returns whether we should use interrupts or not.
7435 static uint dgap_config_get_useintr(struct board_t *bd)
7437 struct cnode *p = NULL;
7442 for (p = bd->bd_config; p; p = p->next) {
7446 * check for pcxr types.
7448 return p->u.useintr;
7454 /* If not found, then don't turn on interrupts. */
7459 * Given a board pointer, returns whether we turn on altpin or not.
7461 static uint dgap_config_get_altpin(struct board_t *bd)
7463 struct cnode *p = NULL;
7468 for (p = bd->bd_config; p; p = p->next) {
7472 * check for pcxr types.
7480 /* If not found, then don't turn on interrupts. */
7485 * Given a specific type of board, if found, detached link and
7486 * returns the first occurrence in the list.
7488 static struct cnode *dgap_find_config(int type, int bus, int slot)
7490 struct cnode *p, *prev = NULL, *prev2 = NULL, *found = NULL;
7494 while (p->next != NULL) {
7498 if (p->type == BNODE) {
7500 if (p->u.board.type == type) {
7502 if (p->u.board.v_pcibus &&
7503 p->u.board.pcibus != bus)
7505 if (p->u.board.v_pcislot &&
7506 p->u.board.pcislot != slot)
7511 * Keep walking thru the list till we
7512 * find the next board.
7514 while (p->next != NULL) {
7517 if (p->type == BNODE) {
7520 * Mark the end of our 1 board
7526 * Link the "next" board to the
7527 * previous board, effectively
7528 * "unlinking" our board from
7537 * It must be the last board in the list.
7548 * Given a board pointer, walks the config link, counting up
7549 * all ports user specified should be on the board.
7550 * (This does NOT mean they are all actually present right now tho)
7552 static uint dgap_config_get_num_prts(struct board_t *bd)
7555 struct cnode *p = NULL;
7560 for (p = bd->bd_config; p; p = p->next) {
7565 * check for pcxr types.
7567 if (p->u.board.type > EPCFE)
7568 count += p->u.board.nport;
7571 count += p->u.conc.nport;
7574 count += p->u.module.nport;
7581 static char *dgap_create_config_string(struct board_t *bd, char *string)
7584 struct cnode *p = NULL;
7585 struct cnode *q = NULL;
7593 for (p = bd->bd_config; p; p = p->next) {
7599 *ptr = p->u.line.speed;
7604 * Because the EPC/con concentrators can have EM modules
7605 * hanging off of them, we have to walk ahead in the
7606 * list and keep adding the number of ports on each EM
7607 * to the config. UGH!
7609 speed = p->u.conc.speed;
7611 if ((q != NULL) && (q->type == MNODE)) {
7612 *ptr = (p->u.conc.nport + 0x80);
7615 while ((q->next != NULL) &&
7616 (q->next->type) == MNODE) {
7618 *ptr = (q->u.module.nport + 0x80);
7623 *ptr = q->u.module.nport;
7626 *ptr = p->u.conc.nport;