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 static DEFINE_SPINLOCK(dgap_poll_lock); /* Poll scheduling lock */
230 static ulong dgap_poll_time; /* Time of next poll */
231 static uint dgap_poll_stop; /* Used to tell poller to stop */
232 static struct timer_list dgap_poll_timer;
237 Card Model Number of Ports Interface
238 ----------------------------------------------------------------
239 Acceleport Xem 4 - 64 (EIA232 & EIA422)
240 Acceleport Xr 4 & 8 (EIA232)
241 Acceleport Xr 920 4 & 8 (EIA232)
242 Acceleport C/X 8 - 128 (EIA232)
243 Acceleport EPC/X 8 - 224 (EIA232)
244 Acceleport Xr/422 4 & 8 (EIA422)
245 Acceleport 2r/920 2 (EIA232)
246 Acceleport 4r/920 4 (EIA232)
247 Acceleport 8r/920 8 (EIA232)
249 IBM 8-Port Asynchronous PCI Adapter (EIA232)
250 IBM 128-Port Asynchronous PCI Adapter (EIA232 & EIA422)
253 static struct pci_device_id dgap_pci_tbl[] = {
254 { DIGI_VID, PCI_DEV_XEM_DID, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0 },
255 { DIGI_VID, PCI_DEV_CX_DID, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 1 },
256 { DIGI_VID, PCI_DEV_CX_IBM_DID, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 2 },
257 { DIGI_VID, PCI_DEV_EPCJ_DID, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 3 },
258 { DIGI_VID, PCI_DEV_920_2_DID, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 4 },
259 { DIGI_VID, PCI_DEV_920_4_DID, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 5 },
260 { DIGI_VID, PCI_DEV_920_8_DID, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 6 },
261 { DIGI_VID, PCI_DEV_XR_DID, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 7 },
262 { DIGI_VID, PCI_DEV_XRJ_DID, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 8 },
263 { DIGI_VID, PCI_DEV_XR_422_DID, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 9 },
264 { DIGI_VID, PCI_DEV_XR_IBM_DID, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 10 },
265 { DIGI_VID, PCI_DEV_XR_SAIP_DID, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 11 },
266 { DIGI_VID, PCI_DEV_XR_BULL_DID, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 12 },
267 { DIGI_VID, PCI_DEV_920_8_HP_DID, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 13 },
268 { DIGI_VID, PCI_DEV_XEM_HP_DID, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 14 },
269 {0,} /* 0 terminated list. */
271 MODULE_DEVICE_TABLE(pci, dgap_pci_tbl);
274 * A generic list of Product names, PCI Vendor ID, and PCI Device ID.
283 static struct board_id dgap_Ids[] = {
284 { PPCM, PCI_DEV_XEM_NAME, 64, (T_PCXM|T_PCLITE|T_PCIBUS) },
285 { PCX, PCI_DEV_CX_NAME, 128, (T_CX|T_PCIBUS) },
286 { PCX, PCI_DEV_CX_IBM_NAME, 128, (T_CX|T_PCIBUS) },
287 { PEPC, PCI_DEV_EPCJ_NAME, 224, (T_EPC|T_PCIBUS) },
288 { APORT2_920P, PCI_DEV_920_2_NAME, 2, (T_PCXR|T_PCLITE|T_PCIBUS) },
289 { APORT4_920P, PCI_DEV_920_4_NAME, 4, (T_PCXR|T_PCLITE|T_PCIBUS) },
290 { APORT8_920P, PCI_DEV_920_8_NAME, 8, (T_PCXR|T_PCLITE|T_PCIBUS) },
291 { PAPORT8, PCI_DEV_XR_NAME, 8, (T_PCXR|T_PCLITE|T_PCIBUS) },
292 { PAPORT8, PCI_DEV_XRJ_NAME, 8, (T_PCXR|T_PCLITE|T_PCIBUS) },
293 { PAPORT8, PCI_DEV_XR_422_NAME, 8, (T_PCXR|T_PCLITE|T_PCIBUS) },
294 { PAPORT8, PCI_DEV_XR_IBM_NAME, 8, (T_PCXR|T_PCLITE|T_PCIBUS) },
295 { PAPORT8, PCI_DEV_XR_SAIP_NAME, 8, (T_PCXR|T_PCLITE|T_PCIBUS) },
296 { PAPORT8, PCI_DEV_XR_BULL_NAME, 8, (T_PCXR|T_PCLITE|T_PCIBUS) },
297 { APORT8_920P, PCI_DEV_920_8_HP_NAME, 8, (T_PCXR|T_PCLITE|T_PCIBUS) },
298 { PPCM, PCI_DEV_XEM_HP_NAME, 64, (T_PCXM|T_PCLITE|T_PCIBUS) },
299 {0,} /* 0 terminated list. */
302 static struct pci_driver dgap_driver = {
304 .probe = dgap_init_one,
305 .id_table = dgap_pci_tbl,
306 .remove = dgap_remove_one,
309 struct firmware_info {
310 u8 *conf_name; /* dgap.conf */
311 u8 *bios_name; /* BIOS filename */
312 u8 *fep_name; /* FEP filename */
313 u8 *con_name; /* Concentrator filename FIXME*/
314 int num; /* sequence number */
318 * Firmware - BIOS, FEP, and CONC filenames
320 static struct firmware_info fw_info[] = {
321 { "dgap/dgap.conf", "dgap/sxbios.bin", "dgap/sxfep.bin", NULL, 0 },
322 { "dgap/dgap.conf", "dgap/cxpbios.bin", "dgap/cxpfep.bin", NULL, 1 },
323 { "dgap/dgap.conf", "dgap/cxpbios.bin", "dgap/cxpfep.bin", NULL, 2 },
324 { "dgap/dgap.conf", "dgap/pcibios.bin", "dgap/pcifep.bin", NULL, 3 },
325 { "dgap/dgap.conf", "dgap/xrbios.bin", "dgap/xrfep.bin", NULL, 4 },
326 { "dgap/dgap.conf", "dgap/xrbios.bin", "dgap/xrfep.bin", NULL, 5 },
327 { "dgap/dgap.conf", "dgap/xrbios.bin", "dgap/xrfep.bin", NULL, 6 },
328 { "dgap/dgap.conf", "dgap/xrbios.bin", "dgap/xrfep.bin", NULL, 7 },
329 { "dgap/dgap.conf", "dgap/xrbios.bin", "dgap/xrfep.bin", NULL, 8 },
330 { "dgap/dgap.conf", "dgap/xrbios.bin", "dgap/xrfep.bin", NULL, 9 },
331 { "dgap/dgap.conf", "dgap/xrbios.bin", "dgap/xrfep.bin", NULL, 10 },
332 { "dgap/dgap.conf", "dgap/xrbios.bin", "dgap/xrfep.bin", NULL, 11 },
333 { "dgap/dgap.conf", "dgap/xrbios.bin", "dgap/xrfep.bin", NULL, 12 },
334 { "dgap/dgap.conf", "dgap/xrbios.bin", "dgap/xrfep.bin", NULL, 13 },
335 { "dgap/dgap.conf", "dgap/sxbios.bin", "dgap/sxfep.bin", NULL, 14 },
340 * Default transparent print information.
342 static struct digi_t dgap_digi_init = {
343 .digi_flags = DIGI_COOK, /* Flags */
344 .digi_maxcps = 100, /* Max CPS */
345 .digi_maxchar = 50, /* Max chars in print queue */
346 .digi_bufsize = 100, /* Printer buffer size */
347 .digi_onlen = 4, /* size of printer on string */
348 .digi_offlen = 4, /* size of printer off string */
349 .digi_onstr = "\033[5i", /* ANSI printer on string ] */
350 .digi_offstr = "\033[4i", /* ANSI printer off string ] */
351 .digi_term = "ansi" /* default terminal type */
355 * Define a local default termios struct. All ports will be created
356 * with this termios initially.
358 * This defines a raw port at 9600 baud, 8 data bits, no parity,
362 static struct ktermios DgapDefaultTermios = {
363 .c_iflag = (DEFAULT_IFLAGS), /* iflags */
364 .c_oflag = (DEFAULT_OFLAGS), /* oflags */
365 .c_cflag = (DEFAULT_CFLAGS), /* cflags */
366 .c_lflag = (DEFAULT_LFLAGS), /* lflags */
371 static const struct tty_operations dgap_tty_ops = {
372 .open = dgap_tty_open,
373 .close = dgap_tty_close,
374 .write = dgap_tty_write,
375 .write_room = dgap_tty_write_room,
376 .flush_buffer = dgap_tty_flush_buffer,
377 .chars_in_buffer = dgap_tty_chars_in_buffer,
378 .flush_chars = dgap_tty_flush_chars,
379 .ioctl = dgap_tty_ioctl,
380 .set_termios = dgap_tty_set_termios,
381 .stop = dgap_tty_stop,
382 .start = dgap_tty_start,
383 .throttle = dgap_tty_throttle,
384 .unthrottle = dgap_tty_unthrottle,
385 .hangup = dgap_tty_hangup,
386 .put_char = dgap_tty_put_char,
387 .tiocmget = dgap_tty_tiocmget,
388 .tiocmset = dgap_tty_tiocmset,
389 .break_ctl = dgap_tty_send_break,
390 .wait_until_sent = dgap_tty_wait_until_sent,
391 .send_xchar = dgap_tty_send_xchar
395 * Our needed internal static variables from dgap_parse.c
397 static struct cnode dgap_head;
399 static char dgap_cword[MAXCWORD];
406 static struct toklist dgap_tlist[] = {
407 { BEGIN, "config_begin" },
408 { END, "config_end" },
410 { PCX, "Digi_AccelePort_C/X_PCI" },
411 { PEPC, "Digi_AccelePort_EPC/X_PCI" },
412 { PPCM, "Digi_AccelePort_Xem_PCI" },
413 { APORT2_920P, "Digi_AccelePort_2r_920_PCI" },
414 { APORT4_920P, "Digi_AccelePort_4r_920_PCI" },
415 { APORT8_920P, "Digi_AccelePort_8r_920_PCI" },
416 { PAPORT4, "Digi_AccelePort_4r_PCI(EIA-232/RS-422)" },
417 { PAPORT8, "Digi_AccelePort_8r_PCI(EIA-232/RS-422)" },
419 { PCIINFO, "pciinfo" },
422 { CONC, "concentrator" },
432 { CONNECT, "connect" },
433 { METHOD, "method" },
434 { STATUS, "status" },
435 { CUSTOM, "Custom" },
441 { NPORTS, "nports" },
446 { ALTPIN, "altpin" },
447 { USEINTR, "useintr" },
448 { TTSIZ, "ttysize" },
450 { BSSIZ, "boardsize" },
451 { UNTSIZ, "schedsize" },
452 { F2SIZ, "f2200size" },
453 { VPSIZ, "vpixsize" },
457 /************************************************************************
459 * Driver load/unload functions
461 ************************************************************************/
466 * Module load. This is where it all starts.
468 static int dgap_init_module(void)
472 pr_info("%s, Digi International Part Number %s\n", DG_NAME, DG_PART);
478 rc = dgap_init_pci();
482 rc = dgap_create_driver_sysfiles(&dgap_driver);
486 dgap_driver_state = DRIVER_READY;
492 dgap_cleanup_module();
496 module_init(dgap_init_module);
501 static int dgap_start(void)
505 struct device *device;
508 * make sure that the globals are
509 * init'd before we do anything else
515 pr_info("For the tools package please visit http://www.digi.com\n");
518 * Register our base character device into the kernel.
522 * Register management/dpa devices
524 rc = register_chrdev(DIGI_DGAP_MAJOR, "dgap", &DgapBoardFops);
528 dgap_class = class_create(THIS_MODULE, "dgap_mgmt");
529 if (IS_ERR(dgap_class)) {
530 rc = PTR_ERR(dgap_class);
534 device = device_create(dgap_class, NULL,
535 MKDEV(DIGI_DGAP_MAJOR, 0),
537 if (IS_ERR(device)) {
538 rc = PTR_ERR(device);
542 /* Start the poller */
543 spin_lock_irqsave(&dgap_poll_lock, flags);
544 init_timer(&dgap_poll_timer);
545 dgap_poll_timer.function = dgap_poll_handler;
546 dgap_poll_timer.data = 0;
547 dgap_poll_time = jiffies + dgap_jiffies_from_ms(dgap_poll_tick);
548 dgap_poll_timer.expires = dgap_poll_time;
549 spin_unlock_irqrestore(&dgap_poll_lock, flags);
551 add_timer(&dgap_poll_timer);
556 class_destroy(dgap_class);
558 unregister_chrdev(DIGI_DGAP_MAJOR, "dgap");
563 * Register pci driver, and return how many boards we have.
565 static int dgap_init_pci(void)
567 return pci_register_driver(&dgap_driver);
570 /* returns count (>= 0), or negative on error */
571 static int dgap_init_one(struct pci_dev *pdev, const struct pci_device_id *ent)
575 /* wake up and enable device */
576 rc = pci_enable_device(pdev);
581 rc = dgap_probe1(pdev, ent->driver_data);
584 rc = dgap_firmware_load(pdev, ent->driver_data);
590 static int dgap_probe1(struct pci_dev *pdev, int card_type)
592 return dgap_found_board(pdev, card_type);
595 static void dgap_remove_one(struct pci_dev *dev)
601 * dgap_cleanup_module()
603 * Module unload. This is where it all ends.
605 static void dgap_cleanup_module(void)
610 spin_lock_irqsave(&dgap_poll_lock, lock_flags);
612 spin_unlock_irqrestore(&dgap_poll_lock, lock_flags);
614 /* Turn off poller right away. */
615 del_timer_sync(&dgap_poll_timer);
617 dgap_remove_driver_sysfiles(&dgap_driver);
619 device_destroy(dgap_class, MKDEV(DIGI_DGAP_MAJOR, 0));
620 class_destroy(dgap_class);
621 unregister_chrdev(DIGI_DGAP_MAJOR, "dgap");
623 for (i = 0; i < dgap_NumBoards; ++i) {
624 dgap_remove_ports_sysfiles(dgap_Board[i]);
625 dgap_tty_uninit(dgap_Board[i]);
626 dgap_cleanup_board(dgap_Board[i]);
630 pci_unregister_driver(&dgap_driver);
634 * dgap_cleanup_board()
636 * Free all the memory associated with a board
638 static void dgap_cleanup_board(struct board_t *brd)
642 if (!brd || brd->magic != DGAP_BOARD_MAGIC)
645 if (brd->intr_used && brd->irq)
646 free_irq(brd->irq, brd);
648 tasklet_kill(&brd->helper_tasklet);
650 if (brd->re_map_port) {
651 release_mem_region(brd->membase + 0x200000, 0x200000);
652 iounmap(brd->re_map_port);
653 brd->re_map_port = NULL;
656 if (brd->re_map_membase) {
657 release_mem_region(brd->membase, 0x200000);
658 iounmap(brd->re_map_membase);
659 brd->re_map_membase = NULL;
662 /* Free all allocated channels structs */
663 for (i = 0; i < MAXPORTS ; i++)
664 kfree(brd->channels[i]);
667 kfree(brd->flipflagbuf);
669 dgap_Board[brd->boardnum] = NULL;
677 * A board has been found, init it.
679 static int dgap_found_board(struct pci_dev *pdev, int id)
682 unsigned int pci_irq;
685 /* get the board structure and prep it */
686 brd = kzalloc(sizeof(struct board_t), GFP_KERNEL);
690 dgap_Board[dgap_NumBoards] = brd;
692 /* store the info for the board we've found */
693 brd->magic = DGAP_BOARD_MAGIC;
694 brd->boardnum = dgap_NumBoards;
696 brd->vendor = dgap_pci_tbl[id].vendor;
697 brd->device = dgap_pci_tbl[id].device;
699 brd->pci_bus = pdev->bus->number;
700 brd->pci_slot = PCI_SLOT(pdev->devfn);
701 brd->name = dgap_Ids[id].name;
702 brd->maxports = dgap_Ids[id].maxports;
703 brd->type = dgap_Ids[id].config_type;
704 brd->dpatype = dgap_Ids[id].dpatype;
705 brd->dpastatus = BD_NOFEP;
706 init_waitqueue_head(&brd->state_wait);
708 spin_lock_init(&brd->bd_lock);
711 brd->inhibit_poller = FALSE;
712 brd->wait_for_bios = 0;
713 brd->wait_for_fep = 0;
715 for (i = 0; i < MAXPORTS; i++)
716 brd->channels[i] = NULL;
718 /* store which card & revision we have */
719 pci_read_config_word(pdev, PCI_SUBSYSTEM_VENDOR_ID, &brd->subvendor);
720 pci_read_config_word(pdev, PCI_SUBSYSTEM_ID, &brd->subdevice);
721 pci_read_config_byte(pdev, PCI_REVISION_ID, &brd->rev);
726 /* get the PCI Base Address Registers */
728 /* Xr Jupiter and EPC use BAR 2 */
729 if (brd->device == PCI_DEV_XRJ_DID || brd->device == PCI_DEV_EPCJ_DID) {
730 brd->membase = pci_resource_start(pdev, 2);
731 brd->membase_end = pci_resource_end(pdev, 2);
733 /* Everyone else uses BAR 0 */
735 brd->membase = pci_resource_start(pdev, 0);
736 brd->membase_end = pci_resource_end(pdev, 0);
742 if (brd->membase & 1)
748 * On the PCI boards, there is no IO space allocated
749 * The I/O registers will be in the first 3 bytes of the
750 * upper 2MB of the 4MB memory space. The board memory
751 * will be mapped into the low 2MB of the 4MB memory space
753 brd->port = brd->membase + PCI_IO_OFFSET;
754 brd->port_end = brd->port + PCI_IO_SIZE;
757 * Special initialization for non-PLX boards
759 if (brd->device != PCI_DEV_XRJ_DID && brd->device != PCI_DEV_EPCJ_DID) {
762 pci_write_config_byte(pdev, 0x40, 0);
763 pci_write_config_byte(pdev, 0x46, 0);
765 /* Limit burst length to 2 doubleword transactions */
766 pci_write_config_byte(pdev, 0x42, 1);
769 * Enable IO and mem if not already done.
770 * This was needed for support on Itanium.
772 pci_read_config_word(pdev, PCI_COMMAND, &cmd);
773 cmd |= (PCI_COMMAND_IO | PCI_COMMAND_MEMORY);
774 pci_write_config_word(pdev, PCI_COMMAND, cmd);
777 /* init our poll helper tasklet */
778 tasklet_init(&brd->helper_tasklet, dgap_poll_tasklet,
779 (unsigned long) brd);
781 i = dgap_do_remap(brd);
783 brd->state = BOARD_FAILED;
785 pr_info("dgap: board %d: %s (rev %d), irq %ld\n",
786 dgap_NumBoards, brd->name, brd->rev, brd->irq);
792 static int dgap_finalize_board_init(struct board_t *brd)
796 if (!brd || brd->magic != DGAP_BOARD_MAGIC)
799 brd->use_interrupts = dgap_config_get_useintr(brd);
802 * Set up our interrupt handler if we are set to do interrupts.
804 if (brd->use_interrupts && brd->irq) {
806 rc = request_irq(brd->irq, dgap_intr, IRQF_SHARED, "DGAP", brd);
819 static int dgap_firmware_load(struct pci_dev *pdev, int card_type)
821 struct board_t *brd = dgap_Board[dgap_NumBoards - 1];
822 const struct firmware *fw;
827 dgap_do_reset_board(brd);
829 if ((fw_info[card_type].conf_name) && !dgap_config_buf) {
830 ret = request_firmware(&fw, fw_info[card_type].conf_name,
833 pr_err("dgap: config file %s not found\n",
834 fw_info[card_type].conf_name);
838 dgap_config_buf = kzalloc(fw->size + 1, GFP_KERNEL);
839 if (!dgap_config_buf) {
840 release_firmware(fw);
844 memcpy(dgap_config_buf, fw->data, fw->size);
845 release_firmware(fw);
848 * preserve dgap_config_buf
849 * as dgap_parsefile would
850 * otherwise alter it.
852 tmp_ptr = dgap_config_buf;
854 if (dgap_parsefile(&tmp_ptr, TRUE) != 0) {
855 kfree(dgap_config_buf);
858 kfree(dgap_config_buf);
861 ret = dgap_after_config_loaded(brd->boardnum);
865 * Match this board to a config the user created for us.
868 dgap_find_config(brd->type, brd->pci_bus, brd->pci_slot);
871 * Because the 4 port Xr products share the same PCI ID
872 * as the 8 port Xr products, if we receive a NULL config
873 * back, and this is a PAPORT8 board, retry with a
874 * PAPORT4 attempt as well.
876 if (brd->type == PAPORT8 && !brd->bd_config)
878 dgap_find_config(PAPORT4, brd->pci_bus, brd->pci_slot);
880 if (!brd->bd_config) {
881 pr_err("dgap: No valid configuration found\n");
885 dgap_tty_register(brd);
886 dgap_finalize_board_init(brd);
888 if (fw_info[card_type].bios_name) {
889 ret = request_firmware(&fw, fw_info[card_type].bios_name,
892 pr_err("dgap: bios file %s not found\n",
893 fw_info[card_type].bios_name);
896 dgap_do_bios_load(brd, fw->data, fw->size);
897 release_firmware(fw);
899 /* Wait for BIOS to test board... */
900 ret = dgap_test_bios(brd);
905 if (fw_info[card_type].fep_name) {
906 ret = request_firmware(&fw, fw_info[card_type].fep_name,
909 pr_err("dgap: fep file %s not found\n",
910 fw_info[card_type].fep_name);
913 dgap_do_fep_load(brd, fw->data, fw->size);
914 release_firmware(fw);
916 /* Wait for FEP to load on board... */
917 ret = dgap_test_fep(brd);
922 #ifdef DIGI_CONCENTRATORS_SUPPORTED
924 * If this is a CX or EPCX, we need to see if the firmware
925 * is requesting a concentrator image from us.
927 if ((bd->type == PCX) || (bd->type == PEPC)) {
928 chk_addr = (u16 *) (vaddr + DOWNREQ);
929 /* Nonzero if FEP is requesting concentrator image. */
930 check = readw(chk_addr);
931 vaddr = brd->re_map_membase;
934 if (fw_info[card_type].con_name && check && vaddr) {
935 ret = request_firmware(&fw, fw_info[card_type].con_name,
938 pr_err("dgap: conc file %s not found\n",
939 fw_info[card_type].con_name);
942 /* Put concentrator firmware loading code here */
943 offset = readw((u16 *) (vaddr + DOWNREQ));
944 memcpy_toio(offset, fw->data, fw->size);
946 dgap_do_conc_load(brd, (char *)fw->data, fw->size)
947 release_firmware(fw);
951 * Do tty device initialization.
953 ret = dgap_tty_init(brd);
955 dgap_tty_uninit(brd);
959 ret = dgap_tty_register_ports(brd);
963 brd->state = BOARD_READY;
964 brd->dpastatus = BD_RUNNING;
972 static int dgap_do_remap(struct board_t *brd)
974 if (!brd || brd->magic != DGAP_BOARD_MAGIC)
977 if (!request_mem_region(brd->membase, 0x200000, "dgap"))
980 if (!request_mem_region(brd->membase + PCI_IO_OFFSET, 0x200000,
982 release_mem_region(brd->membase, 0x200000);
986 brd->re_map_membase = ioremap(brd->membase, 0x200000);
987 if (!brd->re_map_membase) {
988 release_mem_region(brd->membase, 0x200000);
989 release_mem_region(brd->membase + PCI_IO_OFFSET, 0x200000);
993 brd->re_map_port = ioremap((brd->membase + PCI_IO_OFFSET), 0x200000);
994 if (!brd->re_map_port) {
995 release_mem_region(brd->membase, 0x200000);
996 release_mem_region(brd->membase + PCI_IO_OFFSET, 0x200000);
997 iounmap(brd->re_map_membase);
1004 /*****************************************************************************
1024 * As each timer expires, it determines (a) whether the "transmit"
1025 * waiter needs to be woken up, and (b) whether the poller needs to
1028 ******************************************************************************/
1030 static void dgap_poll_handler(ulong dummy)
1033 struct board_t *brd;
1034 unsigned long lock_flags;
1037 dgap_poll_counter++;
1040 * Do not start the board state machine until
1041 * driver tells us its up and running, and has
1042 * everything it needs.
1044 if (dgap_driver_state != DRIVER_READY)
1045 goto schedule_poller;
1048 * If we have just 1 board, or the system is not SMP,
1049 * then use the typical old style poller.
1050 * Otherwise, use our new tasklet based poller, which should
1051 * speed things up for multiple boards.
1053 if ((dgap_NumBoards == 1) || (num_online_cpus() <= 1)) {
1054 for (i = 0; i < dgap_NumBoards; i++) {
1056 brd = dgap_Board[i];
1058 if (brd->state == BOARD_FAILED)
1060 if (!brd->intr_running)
1061 /* Call the real board poller directly */
1062 dgap_poll_tasklet((unsigned long) brd);
1066 * Go thru each board, kicking off a
1067 * tasklet for each if needed
1069 for (i = 0; i < dgap_NumBoards; i++) {
1070 brd = dgap_Board[i];
1073 * Attempt to grab the board lock.
1075 * If we can't get it, no big deal, the next poll
1076 * will get it. Basically, I just really don't want
1077 * to spin in here, because I want to kick off my
1078 * tasklets as fast as I can, and then get out the
1081 if (!spin_trylock(&brd->bd_lock))
1085 * If board is in a failed state, don't bother
1086 * scheduling a tasklet
1088 if (brd->state == BOARD_FAILED) {
1089 spin_unlock(&brd->bd_lock);
1093 /* Schedule a poll helper task */
1094 if (!brd->intr_running)
1095 tasklet_schedule(&brd->helper_tasklet);
1098 * Can't do DGAP_UNLOCK here, as we don't have
1099 * lock_flags because we did a trylock above.
1101 spin_unlock(&brd->bd_lock);
1108 * Schedule ourself back at the nominal wakeup interval.
1110 spin_lock_irqsave(&dgap_poll_lock, lock_flags);
1111 dgap_poll_time += dgap_jiffies_from_ms(dgap_poll_tick);
1113 new_time = dgap_poll_time - jiffies;
1115 if ((ulong) new_time >= 2 * dgap_poll_tick) {
1117 jiffies + dgap_jiffies_from_ms(dgap_poll_tick);
1120 dgap_poll_timer.function = dgap_poll_handler;
1121 dgap_poll_timer.data = 0;
1122 dgap_poll_timer.expires = dgap_poll_time;
1123 spin_unlock_irqrestore(&dgap_poll_lock, lock_flags);
1125 if (!dgap_poll_stop)
1126 add_timer(&dgap_poll_timer);
1132 * Driver interrupt handler.
1134 static irqreturn_t dgap_intr(int irq, void *voidbrd)
1136 struct board_t *brd = (struct board_t *) voidbrd;
1142 * Check to make sure its for us.
1144 if (brd->magic != DGAP_BOARD_MAGIC)
1150 * Schedule tasklet to run at a better time.
1152 tasklet_schedule(&brd->helper_tasklet);
1157 * dgap_init_globals()
1159 * This is where we initialize the globals from the static insmod
1160 * configuration variables. These are declared near the head of
1163 static void dgap_init_globals(void)
1167 for (i = 0; i < MAXBOARDS; i++)
1168 dgap_Board[i] = NULL;
1170 init_timer(&dgap_poll_timer);
1172 init_waitqueue_head(&dgap_dl_wait);
1175 /************************************************************************
1179 ************************************************************************/
1184 * Put the driver to sleep for x ms's
1186 * Returns 0 if timed out, !0 (showing signal) if interrupted by a signal.
1188 static int dgap_ms_sleep(ulong ms)
1190 current->state = TASK_INTERRUPTIBLE;
1191 schedule_timeout((ms * HZ) / 1000);
1192 return signal_pending(current);
1195 /************************************************************************
1197 * TTY Initialization/Cleanup Functions
1199 ************************************************************************/
1202 * dgap_tty_register()
1204 * Init the tty subsystem for this board.
1206 static int dgap_tty_register(struct board_t *brd)
1210 brd->SerialDriver = alloc_tty_driver(MAXPORTS);
1212 snprintf(brd->SerialName, MAXTTYNAMELEN, "tty_dgap_%d_", brd->boardnum);
1213 brd->SerialDriver->name = brd->SerialName;
1214 brd->SerialDriver->name_base = 0;
1215 brd->SerialDriver->major = 0;
1216 brd->SerialDriver->minor_start = 0;
1217 brd->SerialDriver->type = TTY_DRIVER_TYPE_SERIAL;
1218 brd->SerialDriver->subtype = SERIAL_TYPE_NORMAL;
1219 brd->SerialDriver->init_termios = DgapDefaultTermios;
1220 brd->SerialDriver->driver_name = DRVSTR;
1221 brd->SerialDriver->flags = (TTY_DRIVER_REAL_RAW |
1222 TTY_DRIVER_DYNAMIC_DEV |
1223 TTY_DRIVER_HARDWARE_BREAK);
1225 /* The kernel wants space to store pointers to tty_structs */
1226 brd->SerialDriver->ttys =
1227 kzalloc(MAXPORTS * sizeof(struct tty_struct *), GFP_KERNEL);
1228 if (!brd->SerialDriver->ttys)
1232 * Entry points for driver. Called by the kernel from
1233 * tty_io.c and n_tty.c.
1235 tty_set_operations(brd->SerialDriver, &dgap_tty_ops);
1238 * If we're doing transparent print, we have to do all of the above
1239 * again, separately so we don't get the LD confused about what major
1240 * we are when we get into the dgap_tty_open() routine.
1242 brd->PrintDriver = alloc_tty_driver(MAXPORTS);
1244 snprintf(brd->PrintName, MAXTTYNAMELEN, "pr_dgap_%d_", brd->boardnum);
1245 brd->PrintDriver->name = brd->PrintName;
1246 brd->PrintDriver->name_base = 0;
1247 brd->PrintDriver->major = 0;
1248 brd->PrintDriver->minor_start = 0;
1249 brd->PrintDriver->type = TTY_DRIVER_TYPE_SERIAL;
1250 brd->PrintDriver->subtype = SERIAL_TYPE_NORMAL;
1251 brd->PrintDriver->init_termios = DgapDefaultTermios;
1252 brd->PrintDriver->driver_name = DRVSTR;
1253 brd->PrintDriver->flags = (TTY_DRIVER_REAL_RAW |
1254 TTY_DRIVER_DYNAMIC_DEV |
1255 TTY_DRIVER_HARDWARE_BREAK);
1257 /* The kernel wants space to store pointers to tty_structs */
1258 brd->PrintDriver->ttys =
1259 kzalloc(MAXPORTS * sizeof(struct tty_struct *), GFP_KERNEL);
1260 if (!brd->PrintDriver->ttys)
1264 * Entry points for driver. Called by the kernel from
1265 * tty_io.c and n_tty.c.
1267 tty_set_operations(brd->PrintDriver, &dgap_tty_ops);
1269 if (!brd->dgap_Major_Serial_Registered) {
1270 /* Register tty devices */
1271 rc = tty_register_driver(brd->SerialDriver);
1274 brd->dgap_Major_Serial_Registered = TRUE;
1275 dgap_BoardsByMajor[brd->SerialDriver->major] = brd;
1276 brd->dgap_Serial_Major = brd->SerialDriver->major;
1279 if (!brd->dgap_Major_TransparentPrint_Registered) {
1280 /* Register Transparent Print devices */
1281 rc = tty_register_driver(brd->PrintDriver);
1284 brd->dgap_Major_TransparentPrint_Registered = TRUE;
1285 dgap_BoardsByMajor[brd->PrintDriver->major] = brd;
1286 brd->dgap_TransparentPrint_Major = brd->PrintDriver->major;
1295 * Init the tty subsystem. Called once per board after board has been
1296 * downloaded and init'ed.
1298 static int dgap_tty_init(struct board_t *brd)
1302 uint true_count = 0;
1305 struct channel_t *ch;
1306 struct bs_t __iomem *bs;
1307 struct cm_t __iomem *cm;
1313 * Initialize board structure elements.
1316 vaddr = brd->re_map_membase;
1317 true_count = readw((vaddr + NCHAN));
1319 brd->nasync = dgap_config_get_num_prts(brd);
1322 brd->nasync = brd->maxports;
1324 if (brd->nasync > brd->maxports)
1325 brd->nasync = brd->maxports;
1327 if (true_count != brd->nasync) {
1328 if ((brd->type == PPCM) && (true_count == 64)) {
1329 pr_warn("dgap: %s configured for %d ports, has %d ports.\n",
1330 brd->name, brd->nasync, true_count);
1331 pr_warn("dgap: Please make SURE the EBI cable running from the card\n");
1332 pr_warn("dgap: to each EM module is plugged into EBI IN!\n");
1333 } else if ((brd->type == PPCM) && (true_count == 0)) {
1334 pr_warn("dgap: %s configured for %d ports, has %d ports.\n",
1335 brd->name, brd->nasync, true_count);
1336 pr_warn("dgap: Please make SURE the EBI cable running from the card\n");
1337 pr_warn("dgap: to each EM module is plugged into EBI IN!\n");
1339 pr_warn("dgap: %s configured for %d ports, has %d ports.\n",
1340 brd->name, brd->nasync, true_count);
1342 brd->nasync = true_count;
1344 /* If no ports, don't bother going any further */
1346 brd->state = BOARD_FAILED;
1347 brd->dpastatus = BD_NOFEP;
1353 * Allocate channel memory that might not have been allocated
1354 * when the driver was first loaded.
1356 for (i = 0; i < brd->nasync; i++) {
1357 if (!brd->channels[i]) {
1359 kzalloc(sizeof(struct channel_t), GFP_ATOMIC);
1360 if (!brd->channels[i])
1365 ch = brd->channels[0];
1366 vaddr = brd->re_map_membase;
1368 bs = (struct bs_t __iomem *) ((ulong) vaddr + CHANBUF);
1369 cm = (struct cm_t __iomem *) ((ulong) vaddr + CMDBUF);
1373 /* Set up channel variables */
1374 for (i = 0; i < brd->nasync; i++, ch = brd->channels[i], bs++) {
1376 if (!brd->channels[i])
1379 spin_lock_init(&ch->ch_lock);
1381 /* Store all our magic numbers */
1382 ch->magic = DGAP_CHANNEL_MAGIC;
1383 ch->ch_tun.magic = DGAP_UNIT_MAGIC;
1384 ch->ch_tun.un_type = DGAP_SERIAL;
1385 ch->ch_tun.un_ch = ch;
1386 ch->ch_tun.un_dev = i;
1388 ch->ch_pun.magic = DGAP_UNIT_MAGIC;
1389 ch->ch_pun.un_type = DGAP_PRINT;
1390 ch->ch_pun.un_ch = ch;
1391 ch->ch_pun.un_dev = i;
1393 ch->ch_vaddr = vaddr;
1398 ch->ch_digi = dgap_digi_init;
1401 * Set up digi dsr and dcd bits based on altpin flag.
1403 if (dgap_config_get_altpin(brd)) {
1406 ch->ch_digi.digi_flags |= DIGI_ALTPIN;
1409 ch->ch_dsr = DM_DSR;
1412 ch->ch_taddr = vaddr + ((ch->ch_bs->tx_seg) << 4);
1413 ch->ch_raddr = vaddr + ((ch->ch_bs->rx_seg) << 4);
1416 ch->ch_tsize = readw(&(ch->ch_bs->tx_max)) + 1;
1417 ch->ch_rsize = readw(&(ch->ch_bs->rx_max)) + 1;
1421 /* .25 second delay */
1422 ch->ch_close_delay = 250;
1425 * Set queue water marks, interrupt mask,
1426 * and general tty parameters.
1428 tlw = ch->ch_tsize >= 2000 ? ((ch->ch_tsize * 5) / 8) :
1432 dgap_cmdw(ch, STLOW, tlw, 0);
1434 dgap_cmdw(ch, SRLOW, ch->ch_rsize / 2, 0);
1436 dgap_cmdw(ch, SRHIGH, 7 * ch->ch_rsize / 8, 0);
1438 ch->ch_mistat = readb(&(ch->ch_bs->m_stat));
1440 init_waitqueue_head(&ch->ch_flags_wait);
1441 init_waitqueue_head(&ch->ch_tun.un_flags_wait);
1442 init_waitqueue_head(&ch->ch_pun.un_flags_wait);
1443 init_waitqueue_head(&ch->ch_sniff_wait);
1445 /* Turn on all modem interrupts for now */
1446 modem = (DM_CD | DM_DSR | DM_CTS | DM_RI);
1447 writeb(modem, &(ch->ch_bs->m_int));
1450 * Set edelay to 0 if interrupts are turned on,
1451 * otherwise set edelay to the usual 100.
1454 writew(0, &(ch->ch_bs->edelay));
1456 writew(100, &(ch->ch_bs->edelay));
1458 writeb(1, &(ch->ch_bs->idata));
1467 * Uninitialize the TTY portion of this driver. Free all memory and
1470 static void dgap_tty_uninit(struct board_t *brd)
1475 if (brd->dgap_Major_Serial_Registered) {
1476 dgap_BoardsByMajor[brd->SerialDriver->major] = NULL;
1477 brd->dgap_Serial_Major = 0;
1478 for (i = 0; i < brd->nasync; i++) {
1479 tty_port_destroy(&brd->SerialPorts[i]);
1480 dev = brd->channels[i]->ch_tun.un_sysfs;
1481 dgap_remove_tty_sysfs(dev);
1482 tty_unregister_device(brd->SerialDriver, i);
1484 tty_unregister_driver(brd->SerialDriver);
1485 kfree(brd->SerialDriver->ttys);
1486 brd->SerialDriver->ttys = NULL;
1487 put_tty_driver(brd->SerialDriver);
1488 kfree(brd->SerialPorts);
1489 brd->dgap_Major_Serial_Registered = FALSE;
1492 if (brd->dgap_Major_TransparentPrint_Registered) {
1493 dgap_BoardsByMajor[brd->PrintDriver->major] = NULL;
1494 brd->dgap_TransparentPrint_Major = 0;
1495 for (i = 0; i < brd->nasync; i++) {
1496 tty_port_destroy(&brd->PrinterPorts[i]);
1497 dev = brd->channels[i]->ch_pun.un_sysfs;
1498 dgap_remove_tty_sysfs(dev);
1499 tty_unregister_device(brd->PrintDriver, i);
1501 tty_unregister_driver(brd->PrintDriver);
1502 kfree(brd->PrintDriver->ttys);
1503 brd->PrintDriver->ttys = NULL;
1504 put_tty_driver(brd->PrintDriver);
1505 kfree(brd->PrinterPorts);
1506 brd->dgap_Major_TransparentPrint_Registered = FALSE;
1510 #define TMPBUFLEN (1024)
1512 * dgap_sniff - Dump data out to the "sniff" buffer if the
1513 * proc sniff file is opened...
1515 static void dgap_sniff_nowait_nolock(struct channel_t *ch, u8 *text,
1524 char tmpbuf[TMPBUFLEN];
1528 /* Leave if sniff not open */
1529 if (!(ch->ch_sniff_flags & SNIFF_OPEN))
1532 do_gettimeofday(&tv);
1534 /* Create our header for data dump */
1535 p += sprintf(p, "<%ld %ld><%s><", tv.tv_sec, tv.tv_usec, text);
1536 tmpbuflen = p - tmpbuf;
1541 for (i = 0; i < len && tmpbuflen < (TMPBUFLEN - 4); i++) {
1542 p += sprintf(p, "%02x ", *buf);
1544 tmpbuflen = p - tmpbuf;
1547 if (tmpbuflen < (TMPBUFLEN - 4)) {
1549 p += sprintf(p - 1, "%s\n", ">");
1551 p += sprintf(p, "%s\n", ">");
1557 nbuf = strlen(tmpbuf);
1561 * Loop while data remains.
1563 while (nbuf > 0 && ch->ch_sniff_buf) {
1565 * Determine the amount of available space left in the
1566 * buffer. If there's none, wait until some appears.
1568 n = (ch->ch_sniff_out - ch->ch_sniff_in - 1) &
1572 * If there is no space left to write to in our sniff
1573 * buffer, we have no choice but to drop the data.
1574 * We *cannot* sleep here waiting for space, because
1575 * this function was probably called by the
1576 * interrupt/timer routines!
1582 * Copy as much data as will fit.
1588 r = SNIFF_MAX - ch->ch_sniff_in;
1591 memcpy(ch->ch_sniff_buf +
1592 ch->ch_sniff_in, p, r);
1595 ch->ch_sniff_in = 0;
1600 memcpy(ch->ch_sniff_buf + ch->ch_sniff_in, p, n);
1602 ch->ch_sniff_in += n;
1607 * Wakeup any thread waiting for data
1609 if (ch->ch_sniff_flags & SNIFF_WAIT_DATA) {
1610 ch->ch_sniff_flags &= ~SNIFF_WAIT_DATA;
1611 wake_up_interruptible(&ch->ch_sniff_wait);
1616 * If the user sent us too much data to push into our tmpbuf,
1617 * we need to keep looping around on all the data.
1619 if (too_much_data) {
1624 } while (too_much_data);
1627 /*=======================================================================
1629 * dgap_input - Process received data.
1631 * ch - Pointer to channel structure.
1633 *=======================================================================*/
1635 static void dgap_input(struct channel_t *ch)
1638 struct bs_t __iomem *bs;
1639 struct tty_struct *tp;
1640 struct tty_ldisc *ld;
1654 if (!ch || ch->magic != DGAP_CHANNEL_MAGIC)
1657 tp = ch->ch_tun.un_tty;
1664 if (!bd || bd->magic != DGAP_BOARD_MAGIC)
1667 spin_lock_irqsave(&bd->bd_lock, lock_flags);
1668 spin_lock_irqsave(&ch->ch_lock, lock_flags2);
1671 * Figure the number of characters in the buffer.
1672 * Exit immediately if none.
1675 rmask = ch->ch_rsize - 1;
1677 head = readw(&(bs->rx_head));
1679 tail = readw(&(bs->rx_tail));
1682 data_len = (head - tail) & rmask;
1684 if (data_len == 0) {
1685 writeb(1, &(bs->idata));
1686 spin_unlock_irqrestore(&ch->ch_lock, lock_flags2);
1687 spin_unlock_irqrestore(&bd->bd_lock, lock_flags);
1692 * If the device is not open, or CREAD is off, flush
1693 * input data and return immediately.
1695 if ((bd->state != BOARD_READY) || !tp ||
1696 (tp->magic != TTY_MAGIC) ||
1697 !(ch->ch_tun.un_flags & UN_ISOPEN) ||
1698 !(tp->termios.c_cflag & CREAD) ||
1699 (ch->ch_tun.un_flags & UN_CLOSING)) {
1701 writew(head, &(bs->rx_tail));
1702 writeb(1, &(bs->idata));
1703 spin_unlock_irqrestore(&ch->ch_lock, lock_flags2);
1704 spin_unlock_irqrestore(&bd->bd_lock, lock_flags);
1709 * If we are throttled, simply don't read any data.
1711 if (ch->ch_flags & CH_RXBLOCK) {
1712 writeb(1, &(bs->idata));
1713 spin_unlock_irqrestore(&ch->ch_lock, lock_flags2);
1714 spin_unlock_irqrestore(&bd->bd_lock, lock_flags);
1721 tmpchar = readb(&(bs->orun));
1723 ch->ch_err_overrun++;
1724 writeb(0, &(bs->orun));
1727 /* Decide how much data we can send into the tty layer */
1728 flip_len = TTY_FLIPBUF_SIZE;
1730 /* Chop down the length, if needed */
1731 len = min(data_len, flip_len);
1732 len = min(len, (N_TTY_BUF_SIZE - 1));
1734 ld = tty_ldisc_ref(tp);
1736 #ifdef TTY_DONT_FLIP
1738 * If the DONT_FLIP flag is on, don't flush our buffer, and act
1739 * like the ld doesn't have any space to put the data right now.
1741 if (test_bit(TTY_DONT_FLIP, &tp->flags))
1746 * If we were unable to get a reference to the ld,
1747 * don't flush our buffer, and act like the ld doesn't
1748 * have any space to put the data right now.
1754 * If ld doesn't have a pointer to a receive_buf function,
1755 * flush the data, then act like the ld doesn't have any
1756 * space to put the data right now.
1758 if (!ld->ops->receive_buf) {
1759 writew(head, &(bs->rx_tail));
1765 writeb(1, &(bs->idata));
1766 spin_unlock_irqrestore(&ch->ch_lock, lock_flags2);
1767 spin_unlock_irqrestore(&bd->bd_lock, lock_flags);
1769 tty_ldisc_deref(ld);
1773 buf = ch->ch_bd->flipbuf;
1777 * n now contains the most amount of data we can copy,
1778 * bounded either by our buffer size or the amount
1779 * of data the card actually has pending...
1783 s = ((head >= tail) ? head : ch->ch_rsize) - tail;
1789 memcpy_fromio(buf, ch->ch_raddr + tail, s);
1790 dgap_sniff_nowait_nolock(ch, "USER READ", buf, s);
1796 /* Flip queue if needed */
1800 writew(tail, &(bs->rx_tail));
1801 writeb(1, &(bs->idata));
1802 ch->ch_rxcount += len;
1805 * If we are completely raw, we don't need to go through a lot
1806 * of the tty layers that exist.
1807 * In this case, we take the shortest and fastest route we
1808 * can to relay the data to the user.
1810 * On the other hand, if we are not raw, we need to go through
1811 * the tty layer, which has its API more well defined.
1813 if (I_PARMRK(tp) || I_BRKINT(tp) || I_INPCK(tp)) {
1814 dgap_parity_scan(ch, ch->ch_bd->flipbuf,
1815 ch->ch_bd->flipflagbuf, &len);
1817 len = tty_buffer_request_room(tp->port, len);
1818 tty_insert_flip_string_flags(tp->port, ch->ch_bd->flipbuf,
1819 ch->ch_bd->flipflagbuf, len);
1821 len = tty_buffer_request_room(tp->port, len);
1822 tty_insert_flip_string(tp->port, ch->ch_bd->flipbuf, len);
1825 spin_unlock_irqrestore(&ch->ch_lock, lock_flags2);
1826 spin_unlock_irqrestore(&bd->bd_lock, lock_flags);
1828 /* Tell the tty layer its okay to "eat" the data now */
1829 tty_flip_buffer_push(tp->port);
1832 tty_ldisc_deref(ld);
1836 /************************************************************************
1837 * Determines when CARRIER changes state and takes appropriate
1839 ************************************************************************/
1840 static void dgap_carrier(struct channel_t *ch)
1844 int virt_carrier = 0;
1845 int phys_carrier = 0;
1847 if (!ch || ch->magic != DGAP_CHANNEL_MAGIC)
1852 if (!bd || bd->magic != DGAP_BOARD_MAGIC)
1855 /* Make sure altpin is always set correctly */
1856 if (ch->ch_digi.digi_flags & DIGI_ALTPIN) {
1860 ch->ch_dsr = DM_DSR;
1864 if (ch->ch_mistat & D_CD(ch))
1867 if (ch->ch_digi.digi_flags & DIGI_FORCEDCD)
1870 if (ch->ch_c_cflag & CLOCAL)
1874 * Test for a VIRTUAL carrier transition to HIGH.
1876 if (((ch->ch_flags & CH_FCAR) == 0) && (virt_carrier == 1)) {
1879 * When carrier rises, wake any threads waiting
1880 * for carrier in the open routine.
1883 if (waitqueue_active(&(ch->ch_flags_wait)))
1884 wake_up_interruptible(&ch->ch_flags_wait);
1888 * Test for a PHYSICAL carrier transition to HIGH.
1890 if (((ch->ch_flags & CH_CD) == 0) && (phys_carrier == 1)) {
1893 * When carrier rises, wake any threads waiting
1894 * for carrier in the open routine.
1897 if (waitqueue_active(&(ch->ch_flags_wait)))
1898 wake_up_interruptible(&ch->ch_flags_wait);
1902 * Test for a PHYSICAL transition to low, so long as we aren't
1903 * currently ignoring physical transitions (which is what "virtual
1904 * carrier" indicates).
1906 * The transition of the virtual carrier to low really doesn't
1907 * matter... it really only means "ignore carrier state", not
1908 * "make pretend that carrier is there".
1910 if ((virt_carrier == 0) &&
1911 ((ch->ch_flags & CH_CD) != 0) &&
1912 (phys_carrier == 0)) {
1915 * When carrier drops:
1917 * Drop carrier on all open units.
1919 * Flush queues, waking up any task waiting in the
1922 * Send a hangup to the control terminal.
1924 * Enable all select calls.
1926 if (waitqueue_active(&(ch->ch_flags_wait)))
1927 wake_up_interruptible(&ch->ch_flags_wait);
1929 if (ch->ch_tun.un_open_count > 0)
1930 tty_hangup(ch->ch_tun.un_tty);
1932 if (ch->ch_pun.un_open_count > 0)
1933 tty_hangup(ch->ch_pun.un_tty);
1937 * Make sure that our cached values reflect the current reality.
1939 if (virt_carrier == 1)
1940 ch->ch_flags |= CH_FCAR;
1942 ch->ch_flags &= ~CH_FCAR;
1944 if (phys_carrier == 1)
1945 ch->ch_flags |= CH_CD;
1947 ch->ch_flags &= ~CH_CD;
1950 /************************************************************************
1952 * TTY Entry points and helper functions
1954 ************************************************************************/
1960 static int dgap_tty_open(struct tty_struct *tty, struct file *file)
1962 struct board_t *brd;
1963 struct channel_t *ch;
1965 struct bs_t __iomem *bs;
1975 major = MAJOR(tty_devnum(tty));
1976 minor = MINOR(tty_devnum(tty));
1981 /* Get board pointer from our array of majors we have allocated */
1982 brd = dgap_BoardsByMajor[major];
1987 * If board is not yet up to a state of READY, go to
1988 * sleep waiting for it to happen or they cancel the open.
1990 rc = wait_event_interruptible(brd->state_wait,
1991 (brd->state & BOARD_READY));
1996 spin_lock_irqsave(&brd->bd_lock, lock_flags);
1998 /* The wait above should guarantee this cannot happen */
1999 if (brd->state != BOARD_READY) {
2000 spin_unlock_irqrestore(&brd->bd_lock, lock_flags);
2004 /* If opened device is greater than our number of ports, bail. */
2005 if (MINOR(tty_devnum(tty)) > brd->nasync) {
2006 spin_unlock_irqrestore(&brd->bd_lock, lock_flags);
2010 ch = brd->channels[minor];
2012 spin_unlock_irqrestore(&brd->bd_lock, lock_flags);
2016 /* Grab channel lock */
2017 spin_lock_irqsave(&ch->ch_lock, lock_flags2);
2019 /* Figure out our type */
2020 if (major == brd->dgap_Serial_Major) {
2021 un = &brd->channels[minor]->ch_tun;
2022 un->un_type = DGAP_SERIAL;
2023 } else if (major == brd->dgap_TransparentPrint_Major) {
2024 un = &brd->channels[minor]->ch_pun;
2025 un->un_type = DGAP_PRINT;
2027 spin_unlock_irqrestore(&ch->ch_lock, lock_flags2);
2028 spin_unlock_irqrestore(&brd->bd_lock, lock_flags);
2032 /* Store our unit into driver_data, so we always have it available. */
2033 tty->driver_data = un;
2036 * Error if channel info pointer is NULL.
2040 spin_unlock_irqrestore(&ch->ch_lock, lock_flags2);
2041 spin_unlock_irqrestore(&brd->bd_lock, lock_flags);
2048 if (!(un->un_flags & UN_ISOPEN)) {
2049 /* Store important variables. */
2052 /* Maybe do something here to the TTY struct as well? */
2056 * Initialize if neither terminal or printer is open.
2058 if (!((ch->ch_tun.un_flags | ch->ch_pun.un_flags) & UN_ISOPEN)) {
2064 * Flush input queue.
2066 head = readw(&(bs->rx_head));
2067 writew(head, &(bs->rx_tail));
2070 ch->pscan_state = 0;
2071 ch->pscan_savechar = 0;
2073 ch->ch_c_cflag = tty->termios.c_cflag;
2074 ch->ch_c_iflag = tty->termios.c_iflag;
2075 ch->ch_c_oflag = tty->termios.c_oflag;
2076 ch->ch_c_lflag = tty->termios.c_lflag;
2077 ch->ch_startc = tty->termios.c_cc[VSTART];
2078 ch->ch_stopc = tty->termios.c_cc[VSTOP];
2080 /* TODO: flush our TTY struct here? */
2085 * Run param in case we changed anything
2090 * follow protocol for opening port
2093 spin_unlock_irqrestore(&ch->ch_lock, lock_flags2);
2094 spin_unlock_irqrestore(&brd->bd_lock, lock_flags);
2096 rc = dgap_block_til_ready(tty, file, ch);
2101 /* No going back now, increment our unit and channel counters */
2102 spin_lock_irqsave(&ch->ch_lock, lock_flags);
2103 ch->ch_open_count++;
2104 un->un_open_count++;
2105 un->un_flags |= (UN_ISOPEN);
2106 spin_unlock_irqrestore(&ch->ch_lock, lock_flags);
2112 * dgap_block_til_ready()
2114 * Wait for DCD, if needed.
2116 static int dgap_block_til_ready(struct tty_struct *tty, struct file *file,
2117 struct channel_t *ch)
2120 struct un_t *un = NULL;
2123 int sleep_on_un_flags = 0;
2125 if (!tty || tty->magic != TTY_MAGIC || !file || !ch ||
2126 ch->magic != DGAP_CHANNEL_MAGIC)
2129 un = tty->driver_data;
2130 if (!un || un->magic != DGAP_UNIT_MAGIC)
2133 spin_lock_irqsave(&ch->ch_lock, lock_flags);
2140 sleep_on_un_flags = 0;
2143 * If board has failed somehow during our sleep,
2146 if (ch->ch_bd->state == BOARD_FAILED) {
2151 /* If tty was hung up, break out of loop and set error. */
2152 if (tty_hung_up_p(file)) {
2158 * If either unit is in the middle of the fragile part of close,
2159 * we just cannot touch the channel safely.
2160 * Go back to sleep, knowing that when the channel can be
2161 * touched safely, the close routine will signal the
2162 * ch_wait_flags to wake us back up.
2164 if (!((ch->ch_tun.un_flags | ch->ch_pun.un_flags) &
2168 * Our conditions to leave cleanly and happily:
2169 * 1) NONBLOCKING on the tty is set.
2171 * 3) DCD (fake or real) is active.
2174 if (file->f_flags & O_NONBLOCK)
2177 if (tty->flags & (1 << TTY_IO_ERROR))
2180 if (ch->ch_flags & CH_CD)
2183 if (ch->ch_flags & CH_FCAR)
2186 sleep_on_un_flags = 1;
2190 * If there is a signal pending, the user probably
2191 * interrupted (ctrl-c) us.
2192 * Leave loop with error set.
2194 if (signal_pending(current)) {
2195 retval = -ERESTARTSYS;
2200 * Store the flags before we let go of channel lock
2202 if (sleep_on_un_flags)
2203 old_flags = ch->ch_tun.un_flags | ch->ch_pun.un_flags;
2205 old_flags = ch->ch_flags;
2208 * Let go of channel lock before calling schedule.
2209 * Our poller will get any FEP events and wake us up when DCD
2210 * eventually goes active.
2213 spin_unlock_irqrestore(&ch->ch_lock, lock_flags);
2216 * Wait for something in the flags to change
2217 * from the current value.
2219 if (sleep_on_un_flags) {
2220 retval = wait_event_interruptible(un->un_flags_wait,
2221 (old_flags != (ch->ch_tun.un_flags |
2222 ch->ch_pun.un_flags)));
2224 retval = wait_event_interruptible(ch->ch_flags_wait,
2225 (old_flags != ch->ch_flags));
2229 * We got woken up for some reason.
2230 * Before looping around, grab our channel lock.
2232 spin_lock_irqsave(&ch->ch_lock, lock_flags);
2237 spin_unlock_irqrestore(&ch->ch_lock, lock_flags);
2248 * Hangup the port. Like a close, but don't wait for output to drain.
2250 static void dgap_tty_hangup(struct tty_struct *tty)
2253 struct channel_t *ch;
2256 if (!tty || tty->magic != TTY_MAGIC)
2259 un = tty->driver_data;
2260 if (!un || un->magic != DGAP_UNIT_MAGIC)
2264 if (!ch || ch->magic != DGAP_CHANNEL_MAGIC)
2268 if (!bd || bd->magic != DGAP_BOARD_MAGIC)
2271 /* flush the transmit queues */
2272 dgap_tty_flush_buffer(tty);
2280 static void dgap_tty_close(struct tty_struct *tty, struct file *file)
2282 struct ktermios *ts;
2284 struct channel_t *ch;
2289 if (!tty || tty->magic != TTY_MAGIC)
2292 un = tty->driver_data;
2293 if (!un || un->magic != DGAP_UNIT_MAGIC)
2297 if (!ch || ch->magic != DGAP_CHANNEL_MAGIC)
2301 if (!bd || bd->magic != DGAP_BOARD_MAGIC)
2306 spin_lock_irqsave(&ch->ch_lock, lock_flags);
2309 * Determine if this is the last close or not - and if we agree about
2310 * which type of close it is with the Line Discipline
2312 if ((tty->count == 1) && (un->un_open_count != 1)) {
2314 * Uh, oh. tty->count is 1, which means that the tty
2315 * structure will be freed. un_open_count should always
2316 * be one in these conditions. If it's greater than
2317 * one, we've got real problems, since it means the
2318 * serial port won't be shutdown.
2320 un->un_open_count = 1;
2323 if (--un->un_open_count < 0)
2324 un->un_open_count = 0;
2326 ch->ch_open_count--;
2328 if (ch->ch_open_count && un->un_open_count) {
2329 spin_unlock_irqrestore(&ch->ch_lock, lock_flags);
2333 /* OK, its the last close on the unit */
2335 un->un_flags |= UN_CLOSING;
2340 * Only officially close channel if count is 0 and
2341 * DIGI_PRINTER bit is not set.
2343 if ((ch->ch_open_count == 0) &&
2344 !(ch->ch_digi.digi_flags & DIGI_PRINTER)) {
2346 ch->ch_flags &= ~(CH_RXBLOCK);
2348 spin_unlock_irqrestore(&ch->ch_lock, lock_flags);
2350 /* wait for output to drain */
2351 /* This will also return if we take an interrupt */
2353 rc = dgap_wait_for_drain(tty);
2355 dgap_tty_flush_buffer(tty);
2356 tty_ldisc_flush(tty);
2358 spin_lock_irqsave(&ch->ch_lock, lock_flags);
2363 * If we have HUPCL set, lower DTR and RTS
2365 if (ch->ch_c_cflag & HUPCL) {
2366 ch->ch_mostat &= ~(D_RTS(ch)|D_DTR(ch));
2367 dgap_cmdb(ch, SMODEM, 0, D_DTR(ch)|D_RTS(ch), 0);
2370 * Go to sleep to ensure RTS/DTR
2371 * have been dropped for modems to see it.
2373 if (ch->ch_close_delay) {
2374 spin_unlock_irqrestore(&ch->ch_lock,
2376 dgap_ms_sleep(ch->ch_close_delay);
2377 spin_lock_irqsave(&ch->ch_lock, lock_flags);
2381 ch->pscan_state = 0;
2382 ch->pscan_savechar = 0;
2383 ch->ch_baud_info = 0;
2388 * turn off print device when closing print device.
2390 if ((un->un_type == DGAP_PRINT) && (ch->ch_flags & CH_PRON)) {
2391 dgap_wmove(ch, ch->ch_digi.digi_offstr,
2392 (int) ch->ch_digi.digi_offlen);
2393 ch->ch_flags &= ~CH_PRON;
2397 un->un_flags &= ~(UN_ISOPEN | UN_CLOSING);
2398 tty->driver_data = NULL;
2400 wake_up_interruptible(&ch->ch_flags_wait);
2401 wake_up_interruptible(&un->un_flags_wait);
2403 spin_unlock_irqrestore(&ch->ch_lock, lock_flags);
2407 * dgap_tty_chars_in_buffer()
2409 * Return number of characters that have not been transmitted yet.
2411 * This routine is used by the line discipline to determine if there
2412 * is data waiting to be transmitted/drained/flushed or not.
2414 static int dgap_tty_chars_in_buffer(struct tty_struct *tty)
2416 struct board_t *bd = NULL;
2417 struct channel_t *ch = NULL;
2418 struct un_t *un = NULL;
2419 struct bs_t __iomem *bs;
2422 u16 thead, ttail, tmask, chead, ctail;
2423 ulong lock_flags = 0;
2424 ulong lock_flags2 = 0;
2429 un = tty->driver_data;
2430 if (!un || un->magic != DGAP_UNIT_MAGIC)
2434 if (!ch || ch->magic != DGAP_CHANNEL_MAGIC)
2438 if (!bd || bd->magic != DGAP_BOARD_MAGIC)
2445 spin_lock_irqsave(&bd->bd_lock, lock_flags);
2446 spin_lock_irqsave(&ch->ch_lock, lock_flags2);
2448 tmask = (ch->ch_tsize - 1);
2450 /* Get Transmit queue pointers */
2451 thead = readw(&(bs->tx_head)) & tmask;
2452 ttail = readw(&(bs->tx_tail)) & tmask;
2454 /* Get tbusy flag */
2455 tbusy = readb(&(bs->tbusy));
2457 /* Get Command queue pointers */
2458 chead = readw(&(ch->ch_cm->cm_head));
2459 ctail = readw(&(ch->ch_cm->cm_tail));
2461 spin_unlock_irqrestore(&ch->ch_lock, lock_flags2);
2462 spin_unlock_irqrestore(&bd->bd_lock, lock_flags);
2465 * The only way we know for sure if there is no pending
2466 * data left to be transferred, is if:
2467 * 1) Transmit head and tail are equal (empty).
2468 * 2) Command queue head and tail are equal (empty).
2469 * 3) The "TBUSY" flag is 0. (Transmitter not busy).
2472 if ((ttail == thead) && (tbusy == 0) && (chead == ctail)) {
2476 chars = thead - ttail;
2478 chars = thead - ttail + ch->ch_tsize;
2480 * Fudge factor here.
2481 * If chars is zero, we know that the command queue had
2482 * something in it or tbusy was set. Because we cannot
2483 * be sure if there is still some data to be transmitted,
2484 * lets lie, and tell ld we have 1 byte left.
2488 * If TBUSY is still set, and our tx buffers are empty,
2489 * force the firmware to send me another wakeup after
2490 * TBUSY has been cleared.
2493 spin_lock_irqsave(&ch->ch_lock, lock_flags);
2494 un->un_flags |= UN_EMPTY;
2495 writeb(1, &(bs->iempty));
2496 spin_unlock_irqrestore(&ch->ch_lock,
2506 static int dgap_wait_for_drain(struct tty_struct *tty)
2508 struct channel_t *ch;
2510 struct bs_t __iomem *bs;
2513 ulong lock_flags = 0;
2515 if (!tty || tty->magic != TTY_MAGIC)
2518 un = tty->driver_data;
2519 if (!un || un->magic != DGAP_UNIT_MAGIC)
2523 if (!ch || ch->magic != DGAP_CHANNEL_MAGIC)
2532 /* Loop until data is drained */
2533 while (count != 0) {
2535 count = dgap_tty_chars_in_buffer(tty);
2540 /* Set flag waiting for drain */
2541 spin_lock_irqsave(&ch->ch_lock, lock_flags);
2542 un->un_flags |= UN_EMPTY;
2543 writeb(1, &(bs->iempty));
2544 spin_unlock_irqrestore(&ch->ch_lock, lock_flags);
2546 /* Go to sleep till we get woken up */
2547 ret = wait_event_interruptible(un->un_flags_wait,
2548 ((un->un_flags & UN_EMPTY) == 0));
2549 /* If ret is non-zero, user ctrl-c'ed us */
2554 spin_lock_irqsave(&ch->ch_lock, lock_flags);
2555 un->un_flags &= ~(UN_EMPTY);
2556 spin_unlock_irqrestore(&ch->ch_lock, lock_flags);
2564 * Reduces bytes_available to the max number of characters
2565 * that can be sent currently given the maxcps value, and
2566 * returns the new bytes_available. This only affects printer
2569 static int dgap_maxcps_room(struct tty_struct *tty, int bytes_available)
2571 struct channel_t *ch = NULL;
2572 struct un_t *un = NULL;
2575 return bytes_available;
2577 un = tty->driver_data;
2578 if (!un || un->magic != DGAP_UNIT_MAGIC)
2579 return bytes_available;
2582 if (!ch || ch->magic != DGAP_CHANNEL_MAGIC)
2583 return bytes_available;
2586 * If its not the Transparent print device, return
2587 * the full data amount.
2589 if (un->un_type != DGAP_PRINT)
2590 return bytes_available;
2592 if (ch->ch_digi.digi_maxcps > 0 && ch->ch_digi.digi_bufsize > 0) {
2594 unsigned long current_time = jiffies;
2595 unsigned long buffer_time = current_time +
2596 (HZ * ch->ch_digi.digi_bufsize) /
2597 ch->ch_digi.digi_maxcps;
2599 if (ch->ch_cpstime < current_time) {
2600 /* buffer is empty */
2601 ch->ch_cpstime = current_time; /* reset ch_cpstime */
2602 cps_limit = ch->ch_digi.digi_bufsize;
2603 } else if (ch->ch_cpstime < buffer_time) {
2604 /* still room in the buffer */
2605 cps_limit = ((buffer_time - ch->ch_cpstime) *
2606 ch->ch_digi.digi_maxcps) / HZ;
2608 /* no room in the buffer */
2612 bytes_available = min(cps_limit, bytes_available);
2615 return bytes_available;
2618 static inline void dgap_set_firmware_event(struct un_t *un, unsigned int event)
2620 struct channel_t *ch = NULL;
2621 struct bs_t __iomem *bs = NULL;
2623 if (!un || un->magic != DGAP_UNIT_MAGIC)
2626 if (!ch || ch->magic != DGAP_CHANNEL_MAGIC)
2632 if ((event & UN_LOW) != 0) {
2633 if ((un->un_flags & UN_LOW) == 0) {
2634 un->un_flags |= UN_LOW;
2635 writeb(1, &(bs->ilow));
2638 if ((event & UN_LOW) != 0) {
2639 if ((un->un_flags & UN_EMPTY) == 0) {
2640 un->un_flags |= UN_EMPTY;
2641 writeb(1, &(bs->iempty));
2647 * dgap_tty_write_room()
2649 * Return space available in Tx buffer
2651 static int dgap_tty_write_room(struct tty_struct *tty)
2653 struct channel_t *ch = NULL;
2654 struct un_t *un = NULL;
2655 struct bs_t __iomem *bs;
2656 u16 head, tail, tmask;
2658 ulong lock_flags = 0;
2663 un = tty->driver_data;
2664 if (!un || un->magic != DGAP_UNIT_MAGIC)
2668 if (!ch || ch->magic != DGAP_CHANNEL_MAGIC)
2675 spin_lock_irqsave(&ch->ch_lock, lock_flags);
2677 tmask = ch->ch_tsize - 1;
2678 head = readw(&(bs->tx_head)) & tmask;
2679 tail = readw(&(bs->tx_tail)) & tmask;
2681 ret = tail - head - 1;
2683 ret += ch->ch_tsize;
2685 /* Limit printer to maxcps */
2686 ret = dgap_maxcps_room(tty, ret);
2689 * If we are printer device, leave space for
2690 * possibly both the on and off strings.
2692 if (un->un_type == DGAP_PRINT) {
2693 if (!(ch->ch_flags & CH_PRON))
2694 ret -= ch->ch_digi.digi_onlen;
2695 ret -= ch->ch_digi.digi_offlen;
2697 if (ch->ch_flags & CH_PRON)
2698 ret -= ch->ch_digi.digi_offlen;
2705 * Schedule FEP to wake us up if needed.
2707 * TODO: This might be overkill...
2708 * Do we really need to schedule callbacks from the FEP
2709 * in every case? Can we get smarter based on ret?
2711 dgap_set_firmware_event(un, UN_LOW | UN_EMPTY);
2712 spin_unlock_irqrestore(&ch->ch_lock, lock_flags);
2718 * dgap_tty_put_char()
2720 * Put a character into ch->ch_buf
2722 * - used by the line discipline for OPOST processing
2724 static int dgap_tty_put_char(struct tty_struct *tty, unsigned char c)
2727 * Simply call tty_write.
2729 dgap_tty_write(tty, &c, 1);
2736 * Take data from the user or kernel and send it out to the FEP.
2737 * In here exists all the Transparent Print magic as well.
2739 static int dgap_tty_write(struct tty_struct *tty, const unsigned char *buf,
2742 struct channel_t *ch = NULL;
2743 struct un_t *un = NULL;
2744 struct bs_t __iomem *bs;
2745 char __iomem *vaddr;
2746 u16 head, tail, tmask, remain;
2747 int bufcount = 0, n = 0;
2754 un = tty->driver_data;
2755 if (!un || un->magic != DGAP_UNIT_MAGIC)
2759 if (!ch || ch->magic != DGAP_CHANNEL_MAGIC)
2770 * Store original amount of characters passed in.
2771 * This helps to figure out if we should ask the FEP
2772 * to send us an event when it has more space available.
2776 spin_lock_irqsave(&ch->ch_lock, lock_flags);
2778 /* Get our space available for the channel from the board */
2779 tmask = ch->ch_tsize - 1;
2780 head = readw(&(bs->tx_head)) & tmask;
2781 tail = readw(&(bs->tx_tail)) & tmask;
2783 bufcount = tail - head - 1;
2785 bufcount += ch->ch_tsize;
2788 * Limit printer output to maxcps overall, with bursts allowed
2789 * up to bufsize characters.
2791 bufcount = dgap_maxcps_room(tty, bufcount);
2794 * Take minimum of what the user wants to send, and the
2795 * space available in the FEP buffer.
2797 count = min(count, bufcount);
2800 * Bail if no space left.
2803 dgap_set_firmware_event(un, UN_LOW | UN_EMPTY);
2804 spin_unlock_irqrestore(&ch->ch_lock, lock_flags);
2809 * Output the printer ON string, if we are in terminal mode, but
2810 * need to be in printer mode.
2812 if ((un->un_type == DGAP_PRINT) && !(ch->ch_flags & CH_PRON)) {
2813 dgap_wmove(ch, ch->ch_digi.digi_onstr,
2814 (int) ch->ch_digi.digi_onlen);
2815 head = readw(&(bs->tx_head)) & tmask;
2816 ch->ch_flags |= CH_PRON;
2820 * On the other hand, output the printer OFF string, if we are
2821 * currently in printer mode, but need to output to the terminal.
2823 if ((un->un_type != DGAP_PRINT) && (ch->ch_flags & CH_PRON)) {
2824 dgap_wmove(ch, ch->ch_digi.digi_offstr,
2825 (int) ch->ch_digi.digi_offlen);
2826 head = readw(&(bs->tx_head)) & tmask;
2827 ch->ch_flags &= ~CH_PRON;
2831 * If there is nothing left to copy, or
2832 * I can't handle any more data, leave.
2835 dgap_set_firmware_event(un, UN_LOW | UN_EMPTY);
2836 spin_unlock_irqrestore(&ch->ch_lock, lock_flags);
2843 * If the write wraps over the top of the circular buffer,
2844 * move the portion up to the wrap point, and reset the
2845 * pointers to the bottom.
2847 remain = ch->ch_tstart + ch->ch_tsize - head;
2851 vaddr = ch->ch_taddr + head;
2853 memcpy_toio(vaddr, (u8 *) buf, remain);
2854 dgap_sniff_nowait_nolock(ch, "USER WRITE", (u8 *) buf,
2857 head = ch->ch_tstart;
2864 * Move rest of data.
2866 vaddr = ch->ch_taddr + head;
2869 memcpy_toio(vaddr, (u8 *) buf, remain);
2870 dgap_sniff_nowait_nolock(ch, "USER WRITE", (u8 *)buf,
2878 ch->ch_txcount += count;
2880 writew(head, &(bs->tx_head));
2883 dgap_set_firmware_event(un, UN_LOW | UN_EMPTY);
2886 * If this is the print device, and the
2887 * printer is still on, we need to turn it
2888 * off before going idle. If the buffer is
2889 * non-empty, wait until it goes empty.
2890 * Otherwise turn it off right now.
2892 if ((un->un_type == DGAP_PRINT) && (ch->ch_flags & CH_PRON)) {
2893 tail = readw(&(bs->tx_tail)) & tmask;
2896 un->un_flags |= UN_EMPTY;
2897 writeb(1, &(bs->iempty));
2899 dgap_wmove(ch, ch->ch_digi.digi_offstr,
2900 (int) ch->ch_digi.digi_offlen);
2901 head = readw(&(bs->tx_head)) & tmask;
2902 ch->ch_flags &= ~CH_PRON;
2906 /* Update printer buffer empty time. */
2907 if ((un->un_type == DGAP_PRINT) && (ch->ch_digi.digi_maxcps > 0)
2908 && (ch->ch_digi.digi_bufsize > 0)) {
2909 ch->ch_cpstime += (HZ * count) / ch->ch_digi.digi_maxcps;
2912 spin_unlock_irqrestore(&ch->ch_lock, lock_flags);
2918 * Return modem signals to ld.
2920 static int dgap_tty_tiocmget(struct tty_struct *tty)
2922 struct channel_t *ch;
2928 if (!tty || tty->magic != TTY_MAGIC)
2931 un = tty->driver_data;
2932 if (!un || un->magic != DGAP_UNIT_MAGIC)
2936 if (!ch || ch->magic != DGAP_CHANNEL_MAGIC)
2939 spin_lock_irqsave(&ch->ch_lock, lock_flags);
2941 mstat = readb(&(ch->ch_bs->m_stat));
2942 /* Append any outbound signals that might be pending... */
2943 mstat |= ch->ch_mostat;
2945 spin_unlock_irqrestore(&ch->ch_lock, lock_flags);
2949 if (mstat & D_DTR(ch))
2950 result |= TIOCM_DTR;
2951 if (mstat & D_RTS(ch))
2952 result |= TIOCM_RTS;
2953 if (mstat & D_CTS(ch))
2954 result |= TIOCM_CTS;
2955 if (mstat & D_DSR(ch))
2956 result |= TIOCM_DSR;
2957 if (mstat & D_RI(ch))
2959 if (mstat & D_CD(ch))
2966 * dgap_tty_tiocmset()
2968 * Set modem signals, called by ld.
2970 static int dgap_tty_tiocmset(struct tty_struct *tty,
2971 unsigned int set, unsigned int clear)
2974 struct channel_t *ch;
2980 if (!tty || tty->magic != TTY_MAGIC)
2983 un = tty->driver_data;
2984 if (!un || un->magic != DGAP_UNIT_MAGIC)
2988 if (!ch || ch->magic != DGAP_CHANNEL_MAGIC)
2992 if (!bd || bd->magic != DGAP_BOARD_MAGIC)
2995 spin_lock_irqsave(&bd->bd_lock, lock_flags);
2996 spin_lock_irqsave(&ch->ch_lock, lock_flags2);
2998 if (set & TIOCM_RTS) {
2999 ch->ch_mforce |= D_RTS(ch);
3000 ch->ch_mval |= D_RTS(ch);
3003 if (set & TIOCM_DTR) {
3004 ch->ch_mforce |= D_DTR(ch);
3005 ch->ch_mval |= D_DTR(ch);
3008 if (clear & TIOCM_RTS) {
3009 ch->ch_mforce |= D_RTS(ch);
3010 ch->ch_mval &= ~(D_RTS(ch));
3013 if (clear & TIOCM_DTR) {
3014 ch->ch_mforce |= D_DTR(ch);
3015 ch->ch_mval &= ~(D_DTR(ch));
3020 spin_unlock_irqrestore(&ch->ch_lock, lock_flags2);
3021 spin_unlock_irqrestore(&bd->bd_lock, lock_flags);
3027 * dgap_tty_send_break()
3029 * Send a Break, called by ld.
3031 static int dgap_tty_send_break(struct tty_struct *tty, int msec)
3034 struct channel_t *ch;
3040 if (!tty || tty->magic != TTY_MAGIC)
3043 un = tty->driver_data;
3044 if (!un || un->magic != DGAP_UNIT_MAGIC)
3048 if (!ch || ch->magic != DGAP_CHANNEL_MAGIC)
3052 if (!bd || bd->magic != DGAP_BOARD_MAGIC)
3067 spin_lock_irqsave(&bd->bd_lock, lock_flags);
3068 spin_lock_irqsave(&ch->ch_lock, lock_flags2);
3070 dgap_cmdw(ch, SBREAK, (u16) SBREAK_TIME, 0);
3072 dgap_cmdw(ch, SBREAK, (u16) msec, 0);
3074 spin_unlock_irqrestore(&ch->ch_lock, lock_flags2);
3075 spin_unlock_irqrestore(&bd->bd_lock, lock_flags);
3081 * dgap_tty_wait_until_sent()
3083 * wait until data has been transmitted, called by ld.
3085 static void dgap_tty_wait_until_sent(struct tty_struct *tty, int timeout)
3087 dgap_wait_for_drain(tty);
3093 * send a high priority character, called by ld.
3095 static void dgap_tty_send_xchar(struct tty_struct *tty, char c)
3098 struct channel_t *ch;
3103 if (!tty || tty->magic != TTY_MAGIC)
3106 un = tty->driver_data;
3107 if (!un || un->magic != DGAP_UNIT_MAGIC)
3111 if (!ch || ch->magic != DGAP_CHANNEL_MAGIC)
3115 if (!bd || bd->magic != DGAP_BOARD_MAGIC)
3118 spin_lock_irqsave(&bd->bd_lock, lock_flags);
3119 spin_lock_irqsave(&ch->ch_lock, lock_flags2);
3122 * This is technically what we should do.
3123 * However, the NIST tests specifically want
3124 * to see each XON or XOFF character that it
3125 * sends, so lets just send each character
3129 if (c == STOP_CHAR(tty))
3130 dgap_cmdw(ch, RPAUSE, 0, 0);
3131 else if (c == START_CHAR(tty))
3132 dgap_cmdw(ch, RRESUME, 0, 0);
3134 dgap_wmove(ch, &c, 1);
3136 dgap_wmove(ch, &c, 1);
3139 spin_unlock_irqrestore(&ch->ch_lock, lock_flags2);
3140 spin_unlock_irqrestore(&bd->bd_lock, lock_flags);
3146 * Return modem signals to ld.
3148 static int dgap_get_modem_info(struct channel_t *ch, unsigned int __user *value)
3155 if (!ch || ch->magic != DGAP_CHANNEL_MAGIC)
3158 spin_lock_irqsave(&ch->ch_lock, lock_flags);
3160 mstat = readb(&(ch->ch_bs->m_stat));
3161 /* Append any outbound signals that might be pending... */
3162 mstat |= ch->ch_mostat;
3164 spin_unlock_irqrestore(&ch->ch_lock, lock_flags);
3168 if (mstat & D_DTR(ch))
3169 result |= TIOCM_DTR;
3170 if (mstat & D_RTS(ch))
3171 result |= TIOCM_RTS;
3172 if (mstat & D_CTS(ch))
3173 result |= TIOCM_CTS;
3174 if (mstat & D_DSR(ch))
3175 result |= TIOCM_DSR;
3176 if (mstat & D_RI(ch))
3178 if (mstat & D_CD(ch))
3181 rc = put_user(result, value);
3187 * dgap_set_modem_info()
3189 * Set modem signals, called by ld.
3191 static int dgap_set_modem_info(struct tty_struct *tty, unsigned int command,
3192 unsigned int __user *value)
3195 struct channel_t *ch;
3198 unsigned int arg = 0;
3202 if (!tty || tty->magic != TTY_MAGIC)
3205 un = tty->driver_data;
3206 if (!un || un->magic != DGAP_UNIT_MAGIC)
3210 if (!ch || ch->magic != DGAP_CHANNEL_MAGIC)
3214 if (!bd || bd->magic != DGAP_BOARD_MAGIC)
3217 ret = get_user(arg, value);
3223 if (arg & TIOCM_RTS) {
3224 ch->ch_mforce |= D_RTS(ch);
3225 ch->ch_mval |= D_RTS(ch);
3228 if (arg & TIOCM_DTR) {
3229 ch->ch_mforce |= D_DTR(ch);
3230 ch->ch_mval |= D_DTR(ch);
3236 if (arg & TIOCM_RTS) {
3237 ch->ch_mforce |= D_RTS(ch);
3238 ch->ch_mval &= ~(D_RTS(ch));
3241 if (arg & TIOCM_DTR) {
3242 ch->ch_mforce |= D_DTR(ch);
3243 ch->ch_mval &= ~(D_DTR(ch));
3249 ch->ch_mforce = D_DTR(ch)|D_RTS(ch);
3251 if (arg & TIOCM_RTS)
3252 ch->ch_mval |= D_RTS(ch);
3254 ch->ch_mval &= ~(D_RTS(ch));
3256 if (arg & TIOCM_DTR)
3257 ch->ch_mval |= (D_DTR(ch));
3259 ch->ch_mval &= ~(D_DTR(ch));
3267 spin_lock_irqsave(&bd->bd_lock, lock_flags);
3268 spin_lock_irqsave(&ch->ch_lock, lock_flags2);
3272 spin_unlock_irqrestore(&ch->ch_lock, lock_flags2);
3273 spin_unlock_irqrestore(&bd->bd_lock, lock_flags);
3279 * dgap_tty_digigeta()
3281 * Ioctl to get the information for ditty.
3286 static int dgap_tty_digigeta(struct tty_struct *tty,
3287 struct digi_t __user *retinfo)
3289 struct channel_t *ch;
3297 if (!tty || tty->magic != TTY_MAGIC)
3300 un = tty->driver_data;
3301 if (!un || un->magic != DGAP_UNIT_MAGIC)
3305 if (!ch || ch->magic != DGAP_CHANNEL_MAGIC)
3308 memset(&tmp, 0, sizeof(tmp));
3310 spin_lock_irqsave(&ch->ch_lock, lock_flags);
3311 memcpy(&tmp, &ch->ch_digi, sizeof(tmp));
3312 spin_unlock_irqrestore(&ch->ch_lock, lock_flags);
3314 if (copy_to_user(retinfo, &tmp, sizeof(*retinfo)))
3321 * dgap_tty_digiseta()
3323 * Ioctl to set the information for ditty.
3328 static int dgap_tty_digiseta(struct tty_struct *tty,
3329 struct digi_t __user *new_info)
3332 struct channel_t *ch;
3334 struct digi_t new_digi;
3335 ulong lock_flags = 0;
3336 unsigned long lock_flags2;
3338 if (!tty || tty->magic != TTY_MAGIC)
3341 un = tty->driver_data;
3342 if (!un || un->magic != DGAP_UNIT_MAGIC)
3346 if (!ch || ch->magic != DGAP_CHANNEL_MAGIC)
3350 if (!bd || bd->magic != DGAP_BOARD_MAGIC)
3353 if (copy_from_user(&new_digi, new_info, sizeof(struct digi_t)))
3356 spin_lock_irqsave(&bd->bd_lock, lock_flags);
3357 spin_lock_irqsave(&ch->ch_lock, lock_flags2);
3359 memcpy(&ch->ch_digi, &new_digi, sizeof(struct digi_t));
3361 if (ch->ch_digi.digi_maxcps < 1)
3362 ch->ch_digi.digi_maxcps = 1;
3364 if (ch->ch_digi.digi_maxcps > 10000)
3365 ch->ch_digi.digi_maxcps = 10000;
3367 if (ch->ch_digi.digi_bufsize < 10)
3368 ch->ch_digi.digi_bufsize = 10;
3370 if (ch->ch_digi.digi_maxchar < 1)
3371 ch->ch_digi.digi_maxchar = 1;
3373 if (ch->ch_digi.digi_maxchar > ch->ch_digi.digi_bufsize)
3374 ch->ch_digi.digi_maxchar = ch->ch_digi.digi_bufsize;
3376 if (ch->ch_digi.digi_onlen > DIGI_PLEN)
3377 ch->ch_digi.digi_onlen = DIGI_PLEN;
3379 if (ch->ch_digi.digi_offlen > DIGI_PLEN)
3380 ch->ch_digi.digi_offlen = DIGI_PLEN;
3384 spin_unlock_irqrestore(&ch->ch_lock, lock_flags2);
3385 spin_unlock_irqrestore(&bd->bd_lock, lock_flags);
3391 * dgap_tty_digigetedelay()
3393 * Ioctl to get the current edelay setting.
3398 static int dgap_tty_digigetedelay(struct tty_struct *tty, int __user *retinfo)
3400 struct channel_t *ch;
3408 if (!tty || tty->magic != TTY_MAGIC)
3411 un = tty->driver_data;
3412 if (!un || un->magic != DGAP_UNIT_MAGIC)
3416 if (!ch || ch->magic != DGAP_CHANNEL_MAGIC)
3419 memset(&tmp, 0, sizeof(tmp));
3421 spin_lock_irqsave(&ch->ch_lock, lock_flags);
3422 tmp = readw(&(ch->ch_bs->edelay));
3423 spin_unlock_irqrestore(&ch->ch_lock, lock_flags);
3425 if (copy_to_user(retinfo, &tmp, sizeof(*retinfo)))
3432 * dgap_tty_digisetedelay()
3434 * Ioctl to set the EDELAY setting
3437 static int dgap_tty_digisetedelay(struct tty_struct *tty, int __user *new_info)
3440 struct channel_t *ch;
3446 if (!tty || tty->magic != TTY_MAGIC)
3449 un = tty->driver_data;
3450 if (!un || un->magic != DGAP_UNIT_MAGIC)
3454 if (!ch || ch->magic != DGAP_CHANNEL_MAGIC)
3458 if (!bd || bd->magic != DGAP_BOARD_MAGIC)
3461 if (copy_from_user(&new_digi, new_info, sizeof(int)))
3464 spin_lock_irqsave(&bd->bd_lock, lock_flags);
3465 spin_lock_irqsave(&ch->ch_lock, lock_flags2);
3467 writew((u16) new_digi, &(ch->ch_bs->edelay));
3471 spin_unlock_irqrestore(&ch->ch_lock, lock_flags2);
3472 spin_unlock_irqrestore(&bd->bd_lock, lock_flags);
3478 * dgap_tty_digigetcustombaud()
3480 * Ioctl to get the current custom baud rate setting.
3482 static int dgap_tty_digigetcustombaud(struct tty_struct *tty,
3483 int __user *retinfo)
3485 struct channel_t *ch;
3493 if (!tty || tty->magic != TTY_MAGIC)
3496 un = tty->driver_data;
3497 if (!un || un->magic != DGAP_UNIT_MAGIC)
3501 if (!ch || ch->magic != DGAP_CHANNEL_MAGIC)
3504 memset(&tmp, 0, sizeof(tmp));
3506 spin_lock_irqsave(&ch->ch_lock, lock_flags);
3507 tmp = dgap_get_custom_baud(ch);
3508 spin_unlock_irqrestore(&ch->ch_lock, lock_flags);
3510 if (copy_to_user(retinfo, &tmp, sizeof(*retinfo)))
3517 * dgap_tty_digisetcustombaud()
3519 * Ioctl to set the custom baud rate setting
3521 static int dgap_tty_digisetcustombaud(struct tty_struct *tty,
3522 int __user *new_info)
3525 struct channel_t *ch;
3531 if (!tty || tty->magic != TTY_MAGIC)
3534 un = tty->driver_data;
3535 if (!un || un->magic != DGAP_UNIT_MAGIC)
3539 if (!ch || ch->magic != DGAP_CHANNEL_MAGIC)
3543 if (!bd || bd->magic != DGAP_BOARD_MAGIC)
3547 if (copy_from_user(&new_rate, new_info, sizeof(unsigned int)))
3550 if (bd->bd_flags & BD_FEP5PLUS) {
3552 spin_lock_irqsave(&bd->bd_lock, lock_flags);
3553 spin_lock_irqsave(&ch->ch_lock, lock_flags2);
3555 ch->ch_custom_speed = new_rate;
3559 spin_unlock_irqrestore(&ch->ch_lock, lock_flags2);
3560 spin_unlock_irqrestore(&bd->bd_lock, lock_flags);
3567 * dgap_set_termios()
3569 static void dgap_tty_set_termios(struct tty_struct *tty,
3570 struct ktermios *old_termios)
3573 struct channel_t *ch;
3575 unsigned long lock_flags;
3576 unsigned long lock_flags2;
3578 if (!tty || tty->magic != TTY_MAGIC)
3581 un = tty->driver_data;
3582 if (!un || un->magic != DGAP_UNIT_MAGIC)
3586 if (!ch || ch->magic != DGAP_CHANNEL_MAGIC)
3590 if (!bd || bd->magic != DGAP_BOARD_MAGIC)
3593 spin_lock_irqsave(&bd->bd_lock, lock_flags);
3594 spin_lock_irqsave(&ch->ch_lock, lock_flags2);
3596 ch->ch_c_cflag = tty->termios.c_cflag;
3597 ch->ch_c_iflag = tty->termios.c_iflag;
3598 ch->ch_c_oflag = tty->termios.c_oflag;
3599 ch->ch_c_lflag = tty->termios.c_lflag;
3600 ch->ch_startc = tty->termios.c_cc[VSTART];
3601 ch->ch_stopc = tty->termios.c_cc[VSTOP];
3606 spin_unlock_irqrestore(&ch->ch_lock, lock_flags2);
3607 spin_unlock_irqrestore(&bd->bd_lock, lock_flags);
3610 static void dgap_tty_throttle(struct tty_struct *tty)
3613 struct channel_t *ch;
3618 if (!tty || tty->magic != TTY_MAGIC)
3621 un = tty->driver_data;
3622 if (!un || un->magic != DGAP_UNIT_MAGIC)
3626 if (!ch || ch->magic != DGAP_CHANNEL_MAGIC)
3630 if (!bd || bd->magic != DGAP_BOARD_MAGIC)
3633 spin_lock_irqsave(&bd->bd_lock, lock_flags);
3634 spin_lock_irqsave(&ch->ch_lock, lock_flags2);
3636 ch->ch_flags |= (CH_RXBLOCK);
3638 dgap_cmdw(ch, RPAUSE, 0, 0);
3641 spin_unlock_irqrestore(&ch->ch_lock, lock_flags2);
3642 spin_unlock_irqrestore(&bd->bd_lock, lock_flags);
3646 static void dgap_tty_unthrottle(struct tty_struct *tty)
3649 struct channel_t *ch;
3654 if (!tty || tty->magic != TTY_MAGIC)
3657 un = tty->driver_data;
3658 if (!un || un->magic != DGAP_UNIT_MAGIC)
3662 if (!ch || ch->magic != DGAP_CHANNEL_MAGIC)
3666 if (!bd || bd->magic != DGAP_BOARD_MAGIC)
3669 spin_lock_irqsave(&bd->bd_lock, lock_flags);
3670 spin_lock_irqsave(&ch->ch_lock, lock_flags2);
3672 ch->ch_flags &= ~(CH_RXBLOCK);
3675 dgap_cmdw(ch, RRESUME, 0, 0);
3678 spin_unlock_irqrestore(&ch->ch_lock, lock_flags2);
3679 spin_unlock_irqrestore(&bd->bd_lock, lock_flags);
3682 static void dgap_tty_start(struct tty_struct *tty)
3685 struct channel_t *ch;
3690 if (!tty || tty->magic != TTY_MAGIC)
3693 un = tty->driver_data;
3694 if (!un || un->magic != DGAP_UNIT_MAGIC)
3698 if (!ch || ch->magic != DGAP_CHANNEL_MAGIC)
3702 if (!bd || bd->magic != DGAP_BOARD_MAGIC)
3705 spin_lock_irqsave(&bd->bd_lock, lock_flags);
3706 spin_lock_irqsave(&ch->ch_lock, lock_flags2);
3708 dgap_cmdw(ch, RESUMETX, 0, 0);
3710 spin_unlock_irqrestore(&ch->ch_lock, lock_flags2);
3711 spin_unlock_irqrestore(&bd->bd_lock, lock_flags);
3715 static void dgap_tty_stop(struct tty_struct *tty)
3718 struct channel_t *ch;
3723 if (!tty || tty->magic != TTY_MAGIC)
3726 un = tty->driver_data;
3727 if (!un || un->magic != DGAP_UNIT_MAGIC)
3731 if (!ch || ch->magic != DGAP_CHANNEL_MAGIC)
3735 if (!bd || bd->magic != DGAP_BOARD_MAGIC)
3738 spin_lock_irqsave(&bd->bd_lock, lock_flags);
3739 spin_lock_irqsave(&ch->ch_lock, lock_flags2);
3741 dgap_cmdw(ch, PAUSETX, 0, 0);
3743 spin_unlock_irqrestore(&ch->ch_lock, lock_flags2);
3744 spin_unlock_irqrestore(&bd->bd_lock, lock_flags);
3749 * dgap_tty_flush_chars()
3751 * Flush the cook buffer
3753 * Note to self, and any other poor souls who venture here:
3755 * flush in this case DOES NOT mean dispose of the data.
3756 * instead, it means "stop buffering and send it if you
3757 * haven't already." Just guess how I figured that out... SRW 2-Jun-98
3759 * It is also always called in interrupt context - JAR 8-Sept-99
3761 static void dgap_tty_flush_chars(struct tty_struct *tty)
3764 struct channel_t *ch;
3769 if (!tty || tty->magic != TTY_MAGIC)
3772 un = tty->driver_data;
3773 if (!un || un->magic != DGAP_UNIT_MAGIC)
3777 if (!ch || ch->magic != DGAP_CHANNEL_MAGIC)
3781 if (!bd || bd->magic != DGAP_BOARD_MAGIC)
3784 spin_lock_irqsave(&bd->bd_lock, lock_flags);
3785 spin_lock_irqsave(&ch->ch_lock, lock_flags2);
3787 /* TODO: Do something here */
3789 spin_unlock_irqrestore(&ch->ch_lock, lock_flags2);
3790 spin_unlock_irqrestore(&bd->bd_lock, lock_flags);
3794 * dgap_tty_flush_buffer()
3796 * Flush Tx buffer (make in == out)
3798 static void dgap_tty_flush_buffer(struct tty_struct *tty)
3801 struct channel_t *ch;
3807 if (!tty || tty->magic != TTY_MAGIC)
3810 un = tty->driver_data;
3811 if (!un || un->magic != DGAP_UNIT_MAGIC)
3815 if (!ch || ch->magic != DGAP_CHANNEL_MAGIC)
3819 if (!bd || bd->magic != DGAP_BOARD_MAGIC)
3822 spin_lock_irqsave(&bd->bd_lock, lock_flags);
3823 spin_lock_irqsave(&ch->ch_lock, lock_flags2);
3825 ch->ch_flags &= ~CH_STOP;
3826 head = readw(&(ch->ch_bs->tx_head));
3827 dgap_cmdw(ch, FLUSHTX, (u16) head, 0);
3828 dgap_cmdw(ch, RESUMETX, 0, 0);
3829 if (ch->ch_tun.un_flags & (UN_LOW|UN_EMPTY)) {
3830 ch->ch_tun.un_flags &= ~(UN_LOW|UN_EMPTY);
3831 wake_up_interruptible(&ch->ch_tun.un_flags_wait);
3833 if (ch->ch_pun.un_flags & (UN_LOW|UN_EMPTY)) {
3834 ch->ch_pun.un_flags &= ~(UN_LOW|UN_EMPTY);
3835 wake_up_interruptible(&ch->ch_pun.un_flags_wait);
3838 spin_unlock_irqrestore(&ch->ch_lock, lock_flags2);
3839 spin_unlock_irqrestore(&bd->bd_lock, lock_flags);
3840 if (waitqueue_active(&tty->write_wait))
3841 wake_up_interruptible(&tty->write_wait);
3845 /*****************************************************************************
3847 * The IOCTL function and all of its helpers
3849 *****************************************************************************/
3854 * The usual assortment of ioctl's
3856 static int dgap_tty_ioctl(struct tty_struct *tty, unsigned int cmd,
3860 struct channel_t *ch;
3864 ulong lock_flags = 0;
3865 ulong lock_flags2 = 0;
3866 void __user *uarg = (void __user *) arg;
3868 if (!tty || tty->magic != TTY_MAGIC)
3871 un = tty->driver_data;
3872 if (!un || un->magic != DGAP_UNIT_MAGIC)
3876 if (!ch || ch->magic != DGAP_CHANNEL_MAGIC)
3880 if (!bd || bd->magic != DGAP_BOARD_MAGIC)
3883 spin_lock_irqsave(&bd->bd_lock, lock_flags);
3884 spin_lock_irqsave(&ch->ch_lock, lock_flags2);
3886 if (un->un_open_count <= 0) {
3887 spin_unlock_irqrestore(&ch->ch_lock, lock_flags2);
3888 spin_unlock_irqrestore(&bd->bd_lock, lock_flags);
3894 /* Here are all the standard ioctl's that we MUST implement */
3898 * TCSBRK is SVID version: non-zero arg --> no break
3899 * this behaviour is exploited by tcdrain().
3901 * According to POSIX.1 spec (7.2.2.1.2) breaks should be
3902 * between 0.25 and 0.5 seconds so we'll ask for something
3903 * in the middle: 0.375 seconds.
3905 rc = tty_check_change(tty);
3906 spin_unlock_irqrestore(&ch->ch_lock, lock_flags2);
3907 spin_unlock_irqrestore(&bd->bd_lock, lock_flags);
3911 rc = dgap_wait_for_drain(tty);
3916 spin_lock_irqsave(&bd->bd_lock, lock_flags);
3917 spin_lock_irqsave(&ch->ch_lock, lock_flags2);
3919 if (((cmd == TCSBRK) && (!arg)) || (cmd == TCSBRKP))
3920 dgap_cmdw(ch, SBREAK, (u16) SBREAK_TIME, 0);
3922 spin_unlock_irqrestore(&ch->ch_lock, lock_flags2);
3923 spin_unlock_irqrestore(&bd->bd_lock, lock_flags);
3928 /* support for POSIX tcsendbreak()
3930 * According to POSIX.1 spec (7.2.2.1.2) breaks should be
3931 * between 0.25 and 0.5 seconds so we'll ask for something
3932 * in the middle: 0.375 seconds.
3934 rc = tty_check_change(tty);
3935 spin_unlock_irqrestore(&ch->ch_lock, lock_flags2);
3936 spin_unlock_irqrestore(&bd->bd_lock, lock_flags);
3940 rc = dgap_wait_for_drain(tty);
3944 spin_lock_irqsave(&bd->bd_lock, lock_flags);
3945 spin_lock_irqsave(&ch->ch_lock, lock_flags2);
3947 dgap_cmdw(ch, SBREAK, (u16) SBREAK_TIME, 0);
3949 spin_unlock_irqrestore(&ch->ch_lock, lock_flags2);
3950 spin_unlock_irqrestore(&bd->bd_lock, lock_flags);
3956 * FEP5 doesn't support turning on a break unconditionally.
3957 * The FEP5 device will stop sending a break automatically
3958 * after the specified time value that was sent when turning on
3961 rc = tty_check_change(tty);
3962 spin_unlock_irqrestore(&ch->ch_lock, lock_flags2);
3963 spin_unlock_irqrestore(&bd->bd_lock, lock_flags);
3967 rc = dgap_wait_for_drain(tty);
3971 spin_lock_irqsave(&bd->bd_lock, lock_flags);
3972 spin_lock_irqsave(&ch->ch_lock, lock_flags2);
3974 dgap_cmdw(ch, SBREAK, (u16) SBREAK_TIME, 0);
3976 spin_unlock_irqrestore(&ch->ch_lock, lock_flags2);
3977 spin_unlock_irqrestore(&bd->bd_lock, lock_flags);
3983 * FEP5 doesn't support turning off a break unconditionally.
3984 * The FEP5 device will stop sending a break automatically
3985 * after the specified time value that was sent when turning on
3988 spin_unlock_irqrestore(&ch->ch_lock, lock_flags2);
3989 spin_unlock_irqrestore(&bd->bd_lock, lock_flags);
3994 spin_unlock_irqrestore(&ch->ch_lock, lock_flags2);
3995 spin_unlock_irqrestore(&bd->bd_lock, lock_flags);
3997 rc = put_user(C_CLOCAL(tty) ? 1 : 0,
3998 (unsigned long __user *) arg);
4002 spin_unlock_irqrestore(&ch->ch_lock, lock_flags2);
4003 spin_unlock_irqrestore(&bd->bd_lock, lock_flags);
4005 rc = get_user(arg, (unsigned long __user *) arg);
4009 spin_lock_irqsave(&bd->bd_lock, lock_flags);
4010 spin_lock_irqsave(&ch->ch_lock, lock_flags2);
4011 tty->termios.c_cflag = ((tty->termios.c_cflag & ~CLOCAL) |
4012 (arg ? CLOCAL : 0));
4014 spin_unlock_irqrestore(&ch->ch_lock, lock_flags2);
4015 spin_unlock_irqrestore(&bd->bd_lock, lock_flags);
4020 spin_unlock_irqrestore(&ch->ch_lock, lock_flags2);
4021 spin_unlock_irqrestore(&bd->bd_lock, lock_flags);
4022 return dgap_get_modem_info(ch, uarg);
4027 spin_unlock_irqrestore(&ch->ch_lock, lock_flags2);
4028 spin_unlock_irqrestore(&bd->bd_lock, lock_flags);
4029 return dgap_set_modem_info(tty, cmd, uarg);
4032 * Here are any additional ioctl's that we want to implement
4037 * The linux tty driver doesn't have a flush
4038 * input routine for the driver, assuming all backed
4039 * up data is in the line disc. buffers. However,
4040 * we all know that's not the case. Here, we
4041 * act on the ioctl, but then lie and say we didn't
4042 * so the line discipline will process the flush
4045 rc = tty_check_change(tty);
4047 spin_unlock_irqrestore(&ch->ch_lock, lock_flags2);
4048 spin_unlock_irqrestore(&bd->bd_lock, lock_flags);
4052 if ((arg == TCIFLUSH) || (arg == TCIOFLUSH)) {
4053 if (!(un->un_type == DGAP_PRINT)) {
4054 head = readw(&(ch->ch_bs->rx_head));
4055 writew(head, &(ch->ch_bs->rx_tail));
4056 writeb(0, &(ch->ch_bs->orun));
4060 if ((arg != TCOFLUSH) && (arg != TCIOFLUSH)) {
4061 /* pretend we didn't recognize this IOCTL */
4062 spin_unlock_irqrestore(&ch->ch_lock, lock_flags2);
4063 spin_unlock_irqrestore(&bd->bd_lock, lock_flags);
4065 return -ENOIOCTLCMD;
4068 ch->ch_flags &= ~CH_STOP;
4069 head = readw(&(ch->ch_bs->tx_head));
4070 dgap_cmdw(ch, FLUSHTX, (u16) head, 0);
4071 dgap_cmdw(ch, RESUMETX, 0, 0);
4072 if (ch->ch_tun.un_flags & (UN_LOW|UN_EMPTY)) {
4073 ch->ch_tun.un_flags &= ~(UN_LOW|UN_EMPTY);
4074 wake_up_interruptible(&ch->ch_tun.un_flags_wait);
4076 if (ch->ch_pun.un_flags & (UN_LOW|UN_EMPTY)) {
4077 ch->ch_pun.un_flags &= ~(UN_LOW|UN_EMPTY);
4078 wake_up_interruptible(&ch->ch_pun.un_flags_wait);
4080 if (waitqueue_active(&tty->write_wait))
4081 wake_up_interruptible(&tty->write_wait);
4083 /* Can't hold any locks when calling tty_wakeup! */
4084 spin_unlock_irqrestore(&ch->ch_lock, lock_flags2);
4085 spin_unlock_irqrestore(&bd->bd_lock, lock_flags);
4088 /* pretend we didn't recognize this IOCTL */
4089 return -ENOIOCTLCMD;
4094 * The linux tty driver doesn't have a flush
4095 * input routine for the driver, assuming all backed
4096 * up data is in the line disc. buffers. However,
4097 * we all know that's not the case. Here, we
4098 * act on the ioctl, but then lie and say we didn't
4099 * so the line discipline will process the flush
4102 if (cmd == TCSETSF) {
4104 ch->ch_flags &= ~CH_STOP;
4105 head = readw(&(ch->ch_bs->rx_head));
4106 writew(head, &(ch->ch_bs->rx_tail));
4109 /* now wait for all the output to drain */
4110 spin_unlock_irqrestore(&ch->ch_lock, lock_flags2);
4111 spin_unlock_irqrestore(&bd->bd_lock, lock_flags);
4112 rc = dgap_wait_for_drain(tty);
4116 /* pretend we didn't recognize this */
4117 return -ENOIOCTLCMD;
4121 spin_unlock_irqrestore(&ch->ch_lock, lock_flags2);
4122 spin_unlock_irqrestore(&bd->bd_lock, lock_flags);
4123 rc = dgap_wait_for_drain(tty);
4127 /* pretend we didn't recognize this */
4128 return -ENOIOCTLCMD;
4132 * The Linux Line Discipline (LD) would do this for us if we
4133 * let it, but we have the special firmware options to do this
4134 * the "right way" regardless of hardware or software flow
4135 * control so we'll do it outselves instead of letting the LD
4138 rc = tty_check_change(tty);
4140 spin_unlock_irqrestore(&ch->ch_lock, lock_flags2);
4141 spin_unlock_irqrestore(&bd->bd_lock, lock_flags);
4148 spin_unlock_irqrestore(&ch->ch_lock, lock_flags2);
4149 spin_unlock_irqrestore(&bd->bd_lock, lock_flags);
4150 dgap_tty_start(tty);
4153 spin_unlock_irqrestore(&ch->ch_lock, lock_flags2);
4154 spin_unlock_irqrestore(&bd->bd_lock, lock_flags);
4158 spin_unlock_irqrestore(&ch->ch_lock, lock_flags2);
4159 spin_unlock_irqrestore(&bd->bd_lock, lock_flags);
4160 /* Make the ld do it */
4161 return -ENOIOCTLCMD;
4163 spin_unlock_irqrestore(&ch->ch_lock, lock_flags2);
4164 spin_unlock_irqrestore(&bd->bd_lock, lock_flags);
4165 /* Make the ld do it */
4166 return -ENOIOCTLCMD;
4168 spin_unlock_irqrestore(&ch->ch_lock, lock_flags2);
4169 spin_unlock_irqrestore(&bd->bd_lock, lock_flags);
4174 /* get information for ditty */
4175 spin_unlock_irqrestore(&ch->ch_lock, lock_flags2);
4176 spin_unlock_irqrestore(&bd->bd_lock, lock_flags);
4177 return dgap_tty_digigeta(tty, uarg);
4182 /* set information for ditty */
4183 if (cmd == (DIGI_SETAW)) {
4185 spin_unlock_irqrestore(&ch->ch_lock, lock_flags2);
4186 spin_unlock_irqrestore(&bd->bd_lock, lock_flags);
4187 rc = dgap_wait_for_drain(tty);
4190 spin_lock_irqsave(&bd->bd_lock, lock_flags);
4191 spin_lock_irqsave(&ch->ch_lock, lock_flags2);
4193 tty_ldisc_flush(tty);
4197 spin_unlock_irqrestore(&ch->ch_lock, lock_flags2);
4198 spin_unlock_irqrestore(&bd->bd_lock, lock_flags);
4199 return dgap_tty_digiseta(tty, uarg);
4202 spin_unlock_irqrestore(&ch->ch_lock, lock_flags2);
4203 spin_unlock_irqrestore(&bd->bd_lock, lock_flags);
4204 return dgap_tty_digigetedelay(tty, uarg);
4207 spin_unlock_irqrestore(&ch->ch_lock, lock_flags2);
4208 spin_unlock_irqrestore(&bd->bd_lock, lock_flags);
4209 return dgap_tty_digisetedelay(tty, uarg);
4211 case DIGI_GETCUSTOMBAUD:
4212 spin_unlock_irqrestore(&ch->ch_lock, lock_flags2);
4213 spin_unlock_irqrestore(&bd->bd_lock, lock_flags);
4214 return dgap_tty_digigetcustombaud(tty, uarg);
4216 case DIGI_SETCUSTOMBAUD:
4217 spin_unlock_irqrestore(&ch->ch_lock, lock_flags2);
4218 spin_unlock_irqrestore(&bd->bd_lock, lock_flags);
4219 return dgap_tty_digisetcustombaud(tty, uarg);
4221 case DIGI_RESET_PORT:
4222 dgap_firmware_reset_port(ch);
4224 spin_unlock_irqrestore(&ch->ch_lock, lock_flags2);
4225 spin_unlock_irqrestore(&bd->bd_lock, lock_flags);
4229 spin_unlock_irqrestore(&ch->ch_lock, lock_flags2);
4230 spin_unlock_irqrestore(&bd->bd_lock, lock_flags);
4232 return -ENOIOCTLCMD;
4236 static int dgap_after_config_loaded(int board)
4239 * Initialize KME waitqueues...
4241 init_waitqueue_head(&(dgap_Board[board]->kme_wait));
4244 * allocate flip buffer for board.
4246 dgap_Board[board]->flipbuf = kmalloc(MYFLIPLEN, GFP_ATOMIC);
4247 if (!dgap_Board[board]->flipbuf)
4250 dgap_Board[board]->flipflagbuf = kmalloc(MYFLIPLEN, GFP_ATOMIC);
4251 if (!dgap_Board[board]->flipflagbuf) {
4252 kfree(dgap_Board[board]->flipbuf);
4260 * Create pr and tty device entries
4262 static int dgap_tty_register_ports(struct board_t *brd)
4264 struct channel_t *ch;
4267 brd->SerialPorts = kcalloc(brd->nasync, sizeof(*brd->SerialPorts),
4269 if (brd->SerialPorts == NULL)
4271 for (i = 0; i < brd->nasync; i++)
4272 tty_port_init(&brd->SerialPorts[i]);
4274 brd->PrinterPorts = kcalloc(brd->nasync, sizeof(*brd->PrinterPorts),
4276 if (brd->PrinterPorts == NULL) {
4277 kfree(brd->SerialPorts);
4280 for (i = 0; i < brd->nasync; i++)
4281 tty_port_init(&brd->PrinterPorts[i]);
4283 ch = brd->channels[0];
4284 for (i = 0; i < brd->nasync; i++, ch = brd->channels[i]) {
4286 struct device *classp;
4288 classp = tty_port_register_device(&brd->SerialPorts[i],
4290 brd->firstminor + i, NULL);
4292 dgap_create_tty_sysfs(&ch->ch_tun, classp);
4293 ch->ch_tun.un_sysfs = classp;
4295 classp = tty_port_register_device(&brd->PrinterPorts[i],
4297 brd->firstminor + i, NULL);
4299 dgap_create_tty_sysfs(&ch->ch_pun, classp);
4300 ch->ch_pun.un_sysfs = classp;
4302 dgap_create_ports_sysfiles(brd);
4308 * Copies the BIOS code from the user to the board,
4309 * and starts the BIOS running.
4311 static void dgap_do_bios_load(struct board_t *brd, const u8 *ubios, int len)
4317 if (!brd || (brd->magic != DGAP_BOARD_MAGIC) || !brd->re_map_membase)
4320 addr = brd->re_map_membase;
4325 for (i = 0; i < 16; i++)
4326 writeb(0, addr + POSTAREA + i);
4332 memcpy_toio(addr + offset, ubios, len);
4334 writel(0x0bf00401, addr);
4335 writel(0, (addr + 4));
4337 /* Clear the reset, and change states. */
4338 writeb(FEPCLR, brd->re_map_port);
4342 * Checks to see if the BIOS completed running on the card.
4344 static int dgap_test_bios(struct board_t *brd)
4351 if (!brd || (brd->magic != DGAP_BOARD_MAGIC) || !brd->re_map_membase)
4354 addr = brd->re_map_membase;
4355 word = readw(addr + POSTAREA);
4358 * It can take 5-6 seconds for a board to
4359 * pass the bios self test and post results.
4360 * Give it 10 seconds.
4362 brd->wait_for_bios = 0;
4363 while (brd->wait_for_bios < 1000) {
4364 /* Check to see if BIOS thinks board is good. (GD). */
4365 if (word == *(u16 *) "GD")
4367 msleep_interruptible(10);
4368 brd->wait_for_bios++;
4369 word = readw(addr + POSTAREA);
4372 /* Gave up on board after too long of time taken */
4373 err1 = readw(addr + SEQUENCE);
4374 err2 = readw(addr + ERROR);
4375 pr_warn("dgap: %s failed diagnostics. Error #(%x,%x).\n",
4376 brd->name, err1, err2);
4377 brd->state = BOARD_FAILED;
4378 brd->dpastatus = BD_NOBIOS;
4384 * Copies the FEP code from the user to the board,
4385 * and starts the FEP running.
4387 static void dgap_do_fep_load(struct board_t *brd, const u8 *ufep, int len)
4392 if (!brd || (brd->magic != DGAP_BOARD_MAGIC) || !brd->re_map_membase)
4395 addr = brd->re_map_membase;
4401 memcpy_toio(addr + offset, ufep, len);
4404 * If board is a concentrator product, we need to give
4405 * it its config string describing how the concentrators look.
4407 if ((brd->type == PCX) || (brd->type == PEPC)) {
4413 xconfig = dgap_create_config_string(brd, string);
4415 /* Write string to board memory */
4416 config = addr + CONFIG;
4417 for (; i < CONFIGSIZE; i++, config++, xconfig++) {
4418 writeb(*xconfig, config);
4419 if ((*xconfig & 0xff) == 0xff)
4424 writel(0xbfc01004, (addr + 0xc34));
4425 writel(0x3, (addr + 0xc30));
4430 * Waits for the FEP to report thats its ready for us to use.
4432 static int dgap_test_fep(struct board_t *brd)
4439 if (!brd || (brd->magic != DGAP_BOARD_MAGIC) || !brd->re_map_membase)
4442 addr = brd->re_map_membase;
4443 word = readw(addr + FEPSTAT);
4446 * It can take 2-3 seconds for the FEP to
4447 * be up and running. Give it 5 secs.
4449 brd->wait_for_fep = 0;
4450 while (brd->wait_for_fep < 500) {
4451 /* Check to see if FEP is up and running now. */
4452 if (word == *(u16 *) "OS") {
4454 * Check to see if the board can support FEP5+ commands.
4456 word = readw(addr + FEP5_PLUS);
4457 if (word == *(u16 *) "5A")
4458 brd->bd_flags |= BD_FEP5PLUS;
4462 msleep_interruptible(10);
4463 brd->wait_for_fep++;
4464 word = readw(addr + FEPSTAT);
4467 /* Gave up on board after too long of time taken */
4468 err1 = readw(addr + SEQUENCE);
4469 err2 = readw(addr + ERROR);
4470 pr_warn("dgap: FEPOS for %s not functioning. Error #(%x,%x).\n",
4471 brd->name, err1, err2);
4472 brd->state = BOARD_FAILED;
4473 brd->dpastatus = BD_NOFEP;
4479 * Physically forces the FEP5 card to reset itself.
4481 static void dgap_do_reset_board(struct board_t *brd)
4488 if (!brd || (brd->magic != DGAP_BOARD_MAGIC) ||
4489 !brd->re_map_membase || !brd->re_map_port)
4492 /* FEPRST does not vary among supported boards */
4493 writeb(FEPRST, brd->re_map_port);
4495 for (i = 0; i <= 1000; i++) {
4496 check = readb(brd->re_map_port) & 0xe;
4497 if (check == FEPRST)
4503 pr_warn("dgap: Board not resetting... Failing board.\n");
4504 brd->state = BOARD_FAILED;
4505 brd->dpastatus = BD_NOFEP;
4510 * Make sure there really is memory out there.
4512 writel(0xa55a3cc3, (brd->re_map_membase + LOWMEM));
4513 writel(0x5aa5c33c, (brd->re_map_membase + HIGHMEM));
4514 check1 = readl(brd->re_map_membase + LOWMEM);
4515 check2 = readl(brd->re_map_membase + HIGHMEM);
4517 if ((check1 != 0xa55a3cc3) || (check2 != 0x5aa5c33c)) {
4518 pr_warn("dgap: No memory at %p for board.\n",
4519 brd->re_map_membase);
4520 brd->state = BOARD_FAILED;
4521 brd->dpastatus = BD_NOFEP;
4527 #ifdef DIGI_CONCENTRATORS_SUPPORTED
4529 * Sends a concentrator image into the FEP5 board.
4531 static void dgap_do_conc_load(struct board_t *brd, u8 *uaddr, int len)
4533 char __iomem *vaddr;
4535 struct downld_t *to_dp;
4537 if (!brd || (brd->magic != DGAP_BOARD_MAGIC) || !brd->re_map_membase)
4540 vaddr = brd->re_map_membase;
4542 offset = readw((u16 *) (vaddr + DOWNREQ));
4543 to_dp = (struct downld_t *) (vaddr + (int) offset);
4544 memcpy_toio(to_dp, uaddr, len);
4546 /* Tell card we have data for it */
4547 writew(0, vaddr + (DOWNREQ));
4549 brd->conc_dl_status = NO_PENDING_CONCENTRATOR_REQUESTS;
4553 #define EXPANSION_ROM_SIZE (64 * 1024)
4554 #define FEP5_ROM_MAGIC (0xFEFFFFFF)
4556 static void dgap_get_vpd(struct board_t *brd)
4568 * Poke the magic number at the PCI Rom Address location.
4569 * If VPD is supported, the value read from that address
4572 magic = FEP5_ROM_MAGIC;
4573 pci_write_config_dword(brd->pdev, PCI_ROM_ADDRESS, magic);
4574 pci_read_config_dword(brd->pdev, PCI_ROM_ADDRESS, &magic);
4576 /* VPD not supported, bail */
4581 * To get to the OTPROM memory, we have to send the boards base
4582 * address or'ed with 1 into the PCI Rom Address location.
4584 magic = brd->membase | 0x01;
4585 pci_write_config_dword(brd->pdev, PCI_ROM_ADDRESS, magic);
4586 pci_read_config_dword(brd->pdev, PCI_ROM_ADDRESS, &magic);
4588 byte1 = readb(brd->re_map_membase);
4589 byte2 = readb(brd->re_map_membase + 1);
4592 * If the board correctly swapped to the OTPROM memory,
4593 * the first 2 bytes (header) should be 0x55, 0xAA
4595 if (byte1 == 0x55 && byte2 == 0xAA) {
4600 * We have to run through all the OTPROM memory looking
4601 * for the VPD offset.
4603 while (base_offset <= EXPANSION_ROM_SIZE) {
4606 * Lots of magic numbers here.
4608 * The VPD offset is located inside the ROM Data
4611 * We also have to remember the length of each
4612 * ROM Data Structure, so we can "hop" to the next
4613 * entry if the VPD isn't in the current
4614 * ROM Data Structure.
4616 rom_offset = readw(brd->re_map_membase +
4617 base_offset + 0x18);
4618 image_length = readw(brd->re_map_membase +
4619 rom_offset + 0x10) * 512;
4620 vpd_offset = readw(brd->re_map_membase +
4623 /* Found the VPD entry */
4627 /* We didn't find a VPD entry, go to next ROM entry. */
4628 base_offset += image_length;
4630 byte1 = readb(brd->re_map_membase + base_offset);
4631 byte2 = readb(brd->re_map_membase + base_offset + 1);
4634 * If the new ROM offset doesn't have 0x55, 0xAA
4635 * as its header, we have run out of ROM.
4637 if (byte1 != 0x55 || byte2 != 0xAA)
4642 * If we have a VPD offset, then mark the board
4643 * as having a valid VPD, and copy VPDSIZE (512) bytes of
4644 * that VPD to the buffer we have in our board structure.
4647 brd->bd_flags |= BD_HAS_VPD;
4648 for (i = 0; i < VPDSIZE; i++) {
4649 brd->vpd[i] = readb(brd->re_map_membase +
4656 * We MUST poke the magic number at the PCI Rom Address location again.
4657 * This makes the card report the regular board memory back to us,
4658 * rather than the OTPROM memory.
4660 magic = FEP5_ROM_MAGIC;
4661 pci_write_config_dword(brd->pdev, PCI_ROM_ADDRESS, magic);
4665 * Our board poller function.
4667 static void dgap_poll_tasklet(unsigned long data)
4669 struct board_t *bd = (struct board_t *) data;
4671 char __iomem *vaddr;
4674 if (!bd || (bd->magic != DGAP_BOARD_MAGIC))
4677 if (bd->inhibit_poller)
4680 spin_lock_irqsave(&bd->bd_lock, lock_flags);
4682 vaddr = bd->re_map_membase;
4685 * If board is ready, parse deeper to see if there is anything to do.
4687 if (bd->state == BOARD_READY) {
4689 struct ev_t __iomem *eaddr;
4691 if (!bd->re_map_membase) {
4692 spin_unlock_irqrestore(&bd->bd_lock, lock_flags);
4695 if (!bd->re_map_port) {
4696 spin_unlock_irqrestore(&bd->bd_lock, lock_flags);
4703 eaddr = (struct ev_t __iomem *) (vaddr + EVBUF);
4705 /* Get our head and tail */
4706 head = readw(&(eaddr->ev_head));
4707 tail = readw(&(eaddr->ev_tail));
4710 * If there is an event pending. Go service it.
4713 spin_unlock_irqrestore(&bd->bd_lock, lock_flags);
4715 spin_lock_irqsave(&bd->bd_lock, lock_flags);
4720 * If board is doing interrupts, ACK the interrupt.
4722 if (bd && bd->intr_running)
4723 readb(bd->re_map_port + 2);
4725 spin_unlock_irqrestore(&bd->bd_lock, lock_flags);
4729 spin_unlock_irqrestore(&bd->bd_lock, lock_flags);
4732 /*=======================================================================
4734 * dgap_cmdb - Sends a 2 byte command to the FEP.
4736 * ch - Pointer to channel structure.
4737 * cmd - Command to be sent.
4738 * byte1 - Integer containing first byte to be sent.
4739 * byte2 - Integer containing second byte to be sent.
4740 * ncmds - Wait until ncmds or fewer cmds are left
4741 * in the cmd buffer before returning.
4743 *=======================================================================*/
4744 static void dgap_cmdb(struct channel_t *ch, u8 cmd, u8 byte1,
4745 u8 byte2, uint ncmds)
4747 char __iomem *vaddr;
4748 struct __iomem cm_t *cm_addr;
4754 if (!ch || ch->magic != DGAP_CHANNEL_MAGIC)
4758 * Check if board is still alive.
4760 if (ch->ch_bd->state == BOARD_FAILED)
4764 * Make sure the pointers are in range before
4765 * writing to the FEP memory.
4767 vaddr = ch->ch_bd->re_map_membase;
4772 cm_addr = (struct cm_t __iomem *) (vaddr + CMDBUF);
4773 head = readw(&(cm_addr->cm_head));
4776 * Forget it if pointers out of range.
4778 if (head >= (CMDMAX - CMDSTART) || (head & 03)) {
4779 ch->ch_bd->state = BOARD_FAILED;
4784 * Put the data in the circular command buffer.
4786 writeb(cmd, (vaddr + head + CMDSTART + 0));
4787 writeb((u8) ch->ch_portnum, (vaddr + head + CMDSTART + 1));
4788 writeb(byte1, (vaddr + head + CMDSTART + 2));
4789 writeb(byte2, (vaddr + head + CMDSTART + 3));
4791 head = (head + 4) & (CMDMAX - CMDSTART - 4);
4793 writew(head, &(cm_addr->cm_head));
4796 * Wait if necessary before updating the head
4797 * pointer to limit the number of outstanding
4798 * commands to the FEP. If the time spent waiting
4799 * is outlandish, declare the FEP dead.
4801 for (count = dgap_count ;;) {
4803 head = readw(&(cm_addr->cm_head));
4804 tail = readw(&(cm_addr->cm_tail));
4806 n = (head - tail) & (CMDMAX - CMDSTART - 4);
4808 if (n <= ncmds * sizeof(struct cm_t))
4812 ch->ch_bd->state = BOARD_FAILED;
4819 /*=======================================================================
4821 * dgap_cmdw - Sends a 1 word command to the FEP.
4823 * ch - Pointer to channel structure.
4824 * cmd - Command to be sent.
4825 * word - Integer containing word to be sent.
4826 * ncmds - Wait until ncmds or fewer cmds are left
4827 * in the cmd buffer before returning.
4829 *=======================================================================*/
4830 static void dgap_cmdw(struct channel_t *ch, u8 cmd, u16 word, uint ncmds)
4832 char __iomem *vaddr;
4833 struct __iomem cm_t *cm_addr;
4839 if (!ch || ch->magic != DGAP_CHANNEL_MAGIC)
4843 * Check if board is still alive.
4845 if (ch->ch_bd->state == BOARD_FAILED)
4849 * Make sure the pointers are in range before
4850 * writing to the FEP memory.
4852 vaddr = ch->ch_bd->re_map_membase;
4856 cm_addr = (struct cm_t __iomem *) (vaddr + CMDBUF);
4857 head = readw(&(cm_addr->cm_head));
4860 * Forget it if pointers out of range.
4862 if (head >= (CMDMAX - CMDSTART) || (head & 03)) {
4863 ch->ch_bd->state = BOARD_FAILED;
4868 * Put the data in the circular command buffer.
4870 writeb(cmd, (vaddr + head + CMDSTART + 0));
4871 writeb((u8) ch->ch_portnum, (vaddr + head + CMDSTART + 1));
4872 writew((u16) word, (vaddr + head + CMDSTART + 2));
4874 head = (head + 4) & (CMDMAX - CMDSTART - 4);
4876 writew(head, &(cm_addr->cm_head));
4879 * Wait if necessary before updating the head
4880 * pointer to limit the number of outstanding
4881 * commands to the FEP. If the time spent waiting
4882 * is outlandish, declare the FEP dead.
4884 for (count = dgap_count ;;) {
4886 head = readw(&(cm_addr->cm_head));
4887 tail = readw(&(cm_addr->cm_tail));
4889 n = (head - tail) & (CMDMAX - CMDSTART - 4);
4891 if (n <= ncmds * sizeof(struct cm_t))
4895 ch->ch_bd->state = BOARD_FAILED;
4902 /*=======================================================================
4904 * dgap_cmdw_ext - Sends a extended word command to the FEP.
4906 * ch - Pointer to channel structure.
4907 * cmd - Command to be sent.
4908 * word - Integer containing word to be sent.
4909 * ncmds - Wait until ncmds or fewer cmds are left
4910 * in the cmd buffer before returning.
4912 *=======================================================================*/
4913 static void dgap_cmdw_ext(struct channel_t *ch, u16 cmd, u16 word, uint ncmds)
4915 char __iomem *vaddr;
4916 struct __iomem cm_t *cm_addr;
4922 if (!ch || ch->magic != DGAP_CHANNEL_MAGIC)
4926 * Check if board is still alive.
4928 if (ch->ch_bd->state == BOARD_FAILED)
4932 * Make sure the pointers are in range before
4933 * writing to the FEP memory.
4935 vaddr = ch->ch_bd->re_map_membase;
4939 cm_addr = (struct cm_t __iomem *) (vaddr + CMDBUF);
4940 head = readw(&(cm_addr->cm_head));
4943 * Forget it if pointers out of range.
4945 if (head >= (CMDMAX - CMDSTART) || (head & 03)) {
4946 ch->ch_bd->state = BOARD_FAILED;
4951 * Put the data in the circular command buffer.
4954 /* Write an FF to tell the FEP that we want an extended command */
4955 writeb((u8) 0xff, (vaddr + head + CMDSTART + 0));
4957 writeb((u8) ch->ch_portnum, (vaddr + head + CMDSTART + 1));
4958 writew((u16) cmd, (vaddr + head + CMDSTART + 2));
4961 * If the second part of the command won't fit,
4962 * put it at the beginning of the circular buffer.
4964 if (((head + 4) >= ((CMDMAX - CMDSTART)) || (head & 03)))
4965 writew((u16) word, (vaddr + CMDSTART));
4967 writew((u16) word, (vaddr + head + CMDSTART + 4));
4969 head = (head + 8) & (CMDMAX - CMDSTART - 4);
4971 writew(head, &(cm_addr->cm_head));
4974 * Wait if necessary before updating the head
4975 * pointer to limit the number of outstanding
4976 * commands to the FEP. If the time spent waiting
4977 * is outlandish, declare the FEP dead.
4979 for (count = dgap_count ;;) {
4981 head = readw(&(cm_addr->cm_head));
4982 tail = readw(&(cm_addr->cm_tail));
4984 n = (head - tail) & (CMDMAX - CMDSTART - 4);
4986 if (n <= ncmds * sizeof(struct cm_t))
4990 ch->ch_bd->state = BOARD_FAILED;
4997 /*=======================================================================
4999 * dgap_wmove - Write data to FEP buffer.
5001 * ch - Pointer to channel structure.
5002 * buf - Poiter to characters to be moved.
5003 * cnt - Number of characters to move.
5005 *=======================================================================*/
5006 static void dgap_wmove(struct channel_t *ch, char *buf, uint cnt)
5009 char __iomem *taddr;
5010 struct bs_t __iomem *bs;
5013 if (!ch || ch->magic != DGAP_CHANNEL_MAGIC)
5020 head = readw(&(bs->tx_head));
5023 * If pointers are out of range, just return.
5025 if ((cnt > ch->ch_tsize) ||
5026 (unsigned)(head - ch->ch_tstart) >= ch->ch_tsize)
5030 * If the write wraps over the top of the circular buffer,
5031 * move the portion up to the wrap point, and reset the
5032 * pointers to the bottom.
5034 n = ch->ch_tstart + ch->ch_tsize - head;
5038 taddr = ch->ch_taddr + head;
5039 memcpy_toio(taddr, buf, n);
5040 head = ch->ch_tstart;
5045 * Move rest of data.
5047 taddr = ch->ch_taddr + head;
5049 memcpy_toio(taddr, buf, n);
5052 writew(head, &(bs->tx_head));
5056 * Retrives the current custom baud rate from FEP memory,
5057 * and returns it back to the user.
5058 * Returns 0 on error.
5060 static uint dgap_get_custom_baud(struct channel_t *ch)
5066 if (!ch || ch->magic != DGAP_CHANNEL_MAGIC)
5069 if (!ch->ch_bd || ch->ch_bd->magic != DGAP_BOARD_MAGIC)
5072 if (!(ch->ch_bd->bd_flags & BD_FEP5PLUS))
5075 vaddr = ch->ch_bd->re_map_membase;
5081 * Go get from fep mem, what the fep
5082 * believes the custom baud rate is.
5084 offset = ((((*(unsigned short __iomem *)(vaddr + ECS_SEG)) << 4) +
5085 (ch->ch_portnum * 0x28) + LINE_SPEED));
5087 value = readw(vaddr + offset);
5092 * Calls the firmware to reset this channel.
5094 static void dgap_firmware_reset_port(struct channel_t *ch)
5096 dgap_cmdb(ch, CHRESET, 0, 0, 0);
5099 * Now that the channel is reset, we need to make sure
5100 * all the current settings get reapplied to the port
5103 * So we will set the driver's cache of firmware
5104 * settings all to 0, and then call param.
5106 ch->ch_fepiflag = 0;
5107 ch->ch_fepcflag = 0;
5108 ch->ch_fepoflag = 0;
5109 ch->ch_fepstartc = 0;
5110 ch->ch_fepstopc = 0;
5111 ch->ch_fepastartc = 0;
5112 ch->ch_fepastopc = 0;
5117 /*=======================================================================
5119 * dgap_param - Set Digi parameters.
5121 * struct tty_struct * - TTY for port.
5123 *=======================================================================*/
5124 static int dgap_param(struct tty_struct *tty)
5126 struct ktermios *ts;
5128 struct channel_t *ch;
5129 struct bs_t __iomem *bs;
5137 if (!tty || tty->magic != TTY_MAGIC)
5140 un = (struct un_t *) tty->driver_data;
5141 if (!un || un->magic != DGAP_UNIT_MAGIC)
5145 if (!ch || ch->magic != DGAP_CHANNEL_MAGIC)
5149 if (!bd || bd->magic != DGAP_BOARD_MAGIC)
5159 * If baud rate is zero, flush queues, and set mval to drop DTR.
5161 if ((ch->ch_c_cflag & (CBAUD)) == 0) {
5164 head = readw(&(ch->ch_bs->rx_head));
5165 writew(head, &(ch->ch_bs->rx_tail));
5168 head = readw(&(ch->ch_bs->tx_head));
5169 writew(head, &(ch->ch_bs->tx_tail));
5171 ch->ch_flags |= (CH_BAUD0);
5173 /* Drop RTS and DTR */
5174 ch->ch_mval &= ~(D_RTS(ch)|D_DTR(ch));
5175 mval = D_DTR(ch) | D_RTS(ch);
5176 ch->ch_baud_info = 0;
5178 } else if (ch->ch_custom_speed && (bd->bd_flags & BD_FEP5PLUS)) {
5180 * Tell the fep to do the command
5183 dgap_cmdw_ext(ch, 0xff01, ch->ch_custom_speed, 0);
5186 * Now go get from fep mem, what the fep
5187 * believes the custom baud rate is.
5189 ch->ch_custom_speed = dgap_get_custom_baud(ch);
5190 ch->ch_baud_info = ch->ch_custom_speed;
5192 /* Handle transition from B0 */
5193 if (ch->ch_flags & CH_BAUD0) {
5194 ch->ch_flags &= ~(CH_BAUD0);
5195 ch->ch_mval |= (D_RTS(ch)|D_DTR(ch));
5197 mval = D_DTR(ch) | D_RTS(ch);
5201 * Set baud rate, character size, and parity.
5209 ulong bauds[4][16] = {
5213 600, 1200, 1800, 2400,
5214 4800, 9600, 19200, 38400 },
5215 { /* slowbaud & CBAUDEX */
5216 0, 57600, 115200, 230400,
5217 460800, 150, 200, 921600,
5218 600, 1200, 1800, 2400,
5219 4800, 9600, 19200, 38400 },
5221 0, 57600, 76800, 115200,
5222 14400, 57600, 230400, 76800,
5223 115200, 230400, 28800, 460800,
5224 921600, 9600, 19200, 38400 },
5225 { /* fastbaud & CBAUDEX */
5226 0, 57600, 115200, 230400,
5227 460800, 150, 200, 921600,
5228 600, 1200, 1800, 2400,
5229 4800, 9600, 19200, 38400 }
5233 * Only use the TXPrint baud rate if the
5234 * terminal unit is NOT open
5236 if (!(ch->ch_tun.un_flags & UN_ISOPEN) &&
5237 (un->un_type == DGAP_PRINT))
5238 baud = C_BAUD(ch->ch_pun.un_tty) & 0xff;
5240 baud = C_BAUD(ch->ch_tun.un_tty) & 0xff;
5242 if (ch->ch_c_cflag & CBAUDEX)
5245 if (ch->ch_digi.digi_flags & DIGI_FAST)
5250 if ((iindex >= 0) && (iindex < 4) &&
5251 (jindex >= 0) && (jindex < 16))
5252 baud = bauds[iindex][jindex];
5259 ch->ch_baud_info = baud;
5262 * CBAUD has bit position 0x1000 set these days to
5263 * indicate Linux baud rate remap.
5264 * We use a different bit assignment for high speed.
5265 * Clear this bit out while grabbing the parts of
5268 cflag = ch->ch_c_cflag & ((CBAUD ^ CBAUDEX) | PARODD | PARENB |
5272 * HUPCL bit is used by FEP to indicate fast baud
5273 * table is to be used.
5275 if ((ch->ch_digi.digi_flags & DIGI_FAST) ||
5276 (ch->ch_c_cflag & CBAUDEX))
5279 if ((ch->ch_c_cflag & CBAUDEX) &&
5280 !(ch->ch_digi.digi_flags & DIGI_FAST)) {
5282 * The below code is trying to guarantee that only
5283 * baud rates 115200, 230400, 460800, 921600 are
5284 * remapped. We use exclusive or because the various
5285 * baud rates share common bit positions and therefore
5286 * can't be tested for easily.
5288 tcflag_t tcflag = (ch->ch_c_cflag & CBAUD) | CBAUDEX;
5292 * Map high speed requests to index
5293 * into FEP's baud table
5323 cflag = (cflag & ~(CBAUD | CBAUDEX)) | baudpart;
5328 if (cflag != ch->ch_fepcflag) {
5329 ch->ch_fepcflag = (u16) (cflag & 0xffff);
5332 * Okay to have channel and board
5333 * locks held calling this
5335 dgap_cmdw(ch, SCFLAG, (u16) cflag, 0);
5338 /* Handle transition from B0 */
5339 if (ch->ch_flags & CH_BAUD0) {
5340 ch->ch_flags &= ~(CH_BAUD0);
5341 ch->ch_mval |= (D_RTS(ch)|D_DTR(ch));
5343 mval = D_DTR(ch) | D_RTS(ch);
5349 iflag = ch->ch_c_iflag & (IGNBRK | BRKINT | IGNPAR | PARMRK |
5350 INPCK | ISTRIP | IXON | IXANY | IXOFF);
5352 if ((ch->ch_startc == _POSIX_VDISABLE) ||
5353 (ch->ch_stopc == _POSIX_VDISABLE)) {
5354 iflag &= ~(IXON | IXOFF);
5355 ch->ch_c_iflag &= ~(IXON | IXOFF);
5359 * Only the IBM Xr card can switch between
5360 * 232 and 422 modes on the fly
5362 if (bd->device == PCI_DEV_XR_IBM_DID) {
5363 if (ch->ch_digi.digi_flags & DIGI_422)
5364 dgap_cmdb(ch, SCOMMODE, MODE_422, 0, 0);
5366 dgap_cmdb(ch, SCOMMODE, MODE_232, 0, 0);
5369 if (ch->ch_digi.digi_flags & DIGI_ALTPIN)
5372 if (iflag != ch->ch_fepiflag) {
5373 ch->ch_fepiflag = iflag;
5375 /* Okay to have channel and board locks held calling this */
5376 dgap_cmdw(ch, SIFLAG, (u16) ch->ch_fepiflag, 0);
5380 * Select hardware handshaking.
5384 if (ch->ch_c_cflag & CRTSCTS)
5385 hflow |= (D_RTS(ch) | D_CTS(ch));
5386 if (ch->ch_digi.digi_flags & RTSPACE)
5388 if (ch->ch_digi.digi_flags & DTRPACE)
5390 if (ch->ch_digi.digi_flags & CTSPACE)
5392 if (ch->ch_digi.digi_flags & DSRPACE)
5394 if (ch->ch_digi.digi_flags & DCDPACE)
5397 if (hflow != ch->ch_hflow) {
5398 ch->ch_hflow = hflow;
5400 /* Okay to have channel and board locks held calling this */
5401 dgap_cmdb(ch, SHFLOW, (u8) hflow, 0xff, 0);
5406 * Set RTS and/or DTR Toggle if needed,
5407 * but only if product is FEP5+ based.
5409 if (bd->bd_flags & BD_FEP5PLUS) {
5411 if (ch->ch_digi.digi_flags & DIGI_RTS_TOGGLE)
5412 hflow2 |= (D_RTS(ch));
5413 if (ch->ch_digi.digi_flags & DIGI_DTR_TOGGLE)
5414 hflow2 |= (D_DTR(ch));
5416 dgap_cmdw_ext(ch, 0xff03, hflow2, 0);
5420 * Set modem control lines.
5423 mval ^= ch->ch_mforce & (mval ^ ch->ch_mval);
5425 if (ch->ch_mostat ^ mval) {
5426 ch->ch_mostat = mval;
5428 /* Okay to have channel and board locks held calling this */
5429 dgap_cmdb(ch, SMODEM, (u8) mval, D_RTS(ch)|D_DTR(ch), 0);
5433 * Read modem signals, and then call carrier function.
5435 ch->ch_mistat = readb(&(bs->m_stat));
5439 * Set the start and stop characters.
5441 if (ch->ch_startc != ch->ch_fepstartc ||
5442 ch->ch_stopc != ch->ch_fepstopc) {
5443 ch->ch_fepstartc = ch->ch_startc;
5444 ch->ch_fepstopc = ch->ch_stopc;
5446 /* Okay to have channel and board locks held calling this */
5447 dgap_cmdb(ch, SFLOWC, ch->ch_fepstartc, ch->ch_fepstopc, 0);
5451 * Set the Auxiliary start and stop characters.
5453 if (ch->ch_astartc != ch->ch_fepastartc ||
5454 ch->ch_astopc != ch->ch_fepastopc) {
5455 ch->ch_fepastartc = ch->ch_astartc;
5456 ch->ch_fepastopc = ch->ch_astopc;
5458 /* Okay to have channel and board locks held calling this */
5459 dgap_cmdb(ch, SAFLOWC, ch->ch_fepastartc, ch->ch_fepastopc, 0);
5466 * dgap_parity_scan()
5468 * Convert the FEP5 way of reporting parity errors and breaks into
5469 * the Linux line discipline way.
5471 static void dgap_parity_scan(struct channel_t *ch, unsigned char *cbuf,
5472 unsigned char *fbuf, int *len)
5476 unsigned char *in, *cout, *fout;
5483 if (!ch || ch->magic != DGAP_CHANNEL_MAGIC)
5488 switch (ch->pscan_state) {
5490 /* reset to sanity and fall through */
5491 ch->pscan_state = 0;
5494 /* No FF seen yet */
5495 if (c == (unsigned char) '\377')
5496 /* delete this character from stream */
5497 ch->pscan_state = 1;
5500 *fout++ = TTY_NORMAL;
5507 if (c == (unsigned char) '\377') {
5508 /* doubled ff, transform to single ff */
5510 *fout++ = TTY_NORMAL;
5512 ch->pscan_state = 0;
5514 /* save value examination in next state */
5515 ch->pscan_savechar = c;
5516 ch->pscan_state = 2;
5521 /* third character of ff sequence */
5525 if (ch->pscan_savechar == 0x0) {
5529 *fout++ = TTY_BREAK;
5531 ch->ch_err_parity++;
5532 *fout++ = TTY_PARITY;
5537 ch->pscan_state = 0;
5543 static void dgap_write_wakeup(struct board_t *bd, struct channel_t *ch,
5544 struct un_t *un, u32 mask,
5545 unsigned long *irq_flags1,
5546 unsigned long *irq_flags2)
5548 if (!(un->un_flags & mask))
5551 un->un_flags &= ~mask;
5553 if (!(un->un_flags & UN_ISOPEN))
5556 if ((un->un_tty->flags & (1 << TTY_DO_WRITE_WAKEUP)) &&
5557 un->un_tty->ldisc->ops->write_wakeup) {
5558 spin_unlock_irqrestore(&ch->ch_lock, *irq_flags2);
5559 spin_unlock_irqrestore(&bd->bd_lock, *irq_flags1);
5561 (un->un_tty->ldisc->ops->write_wakeup)(un->un_tty);
5563 spin_lock_irqsave(&bd->bd_lock, *irq_flags1);
5564 spin_lock_irqsave(&ch->ch_lock, *irq_flags2);
5566 wake_up_interruptible(&un->un_tty->write_wait);
5567 wake_up_interruptible(&un->un_flags_wait);
5570 /*=======================================================================
5572 * dgap_event - FEP to host event processing routine.
5574 * bd - Board of current event.
5576 *=======================================================================*/
5577 static int dgap_event(struct board_t *bd)
5579 struct channel_t *ch;
5582 struct bs_t __iomem *bs;
5585 struct ev_t __iomem *eaddr;
5593 if (!bd || bd->magic != DGAP_BOARD_MAGIC)
5596 spin_lock_irqsave(&bd->bd_lock, lock_flags);
5598 vaddr = bd->re_map_membase;
5601 spin_unlock_irqrestore(&bd->bd_lock, lock_flags);
5605 eaddr = (struct ev_t __iomem *) (vaddr + EVBUF);
5607 /* Get our head and tail */
5608 head = readw(&(eaddr->ev_head));
5609 tail = readw(&(eaddr->ev_tail));
5612 * Forget it if pointers out of range.
5615 if (head >= EVMAX - EVSTART || tail >= EVMAX - EVSTART ||
5616 (head | tail) & 03) {
5617 /* Let go of board lock */
5618 spin_unlock_irqrestore(&bd->bd_lock, lock_flags);
5623 * Loop to process all the events in the buffer.
5625 while (tail != head) {
5628 * Get interrupt information.
5631 event = bd->re_map_membase + tail + EVSTART;
5639 * Make sure the interrupt is valid.
5641 if (port >= bd->nasync)
5644 if (!(reason & (IFMODEM | IFBREAK | IFTLW | IFTEM | IFDATA)))
5647 ch = bd->channels[port];
5649 if (!ch || ch->magic != DGAP_CHANNEL_MAGIC)
5653 * If we have made it here, the event was valid.
5654 * Lock down the channel.
5656 spin_lock_irqsave(&ch->ch_lock, lock_flags2);
5661 spin_unlock_irqrestore(&ch->ch_lock, lock_flags2);
5666 * Process received data.
5668 if (reason & IFDATA) {
5671 * ALL LOCKS *MUST* BE DROPPED BEFORE CALLING INPUT!
5672 * input could send some data to ld, which in turn
5673 * could do a callback to one of our other functions.
5675 spin_unlock_irqrestore(&ch->ch_lock, lock_flags2);
5676 spin_unlock_irqrestore(&bd->bd_lock, lock_flags);
5680 spin_lock_irqsave(&bd->bd_lock, lock_flags);
5681 spin_lock_irqsave(&ch->ch_lock, lock_flags2);
5683 if (ch->ch_flags & CH_RACTIVE)
5684 ch->ch_flags |= CH_RENABLE;
5686 writeb(1, &(bs->idata));
5688 if (ch->ch_flags & CH_RWAIT) {
5689 ch->ch_flags &= ~CH_RWAIT;
5691 wake_up_interruptible
5692 (&ch->ch_tun.un_flags_wait);
5697 * Process Modem change signals.
5699 if (reason & IFMODEM) {
5700 ch->ch_mistat = modem;
5707 if (reason & IFBREAK) {
5709 if (ch->ch_tun.un_tty) {
5710 /* A break has been indicated */
5712 tty_buffer_request_room
5713 (ch->ch_tun.un_tty->port, 1);
5714 tty_insert_flip_char(ch->ch_tun.un_tty->port,
5716 tty_flip_buffer_push(ch->ch_tun.un_tty->port);
5721 * Process Transmit low.
5723 if (reason & IFTLW) {
5724 dgap_write_wakeup(bd, ch, &ch->ch_tun, UN_LOW,
5725 &lock_flags, &lock_flags2);
5726 dgap_write_wakeup(bd, ch, &ch->ch_pun, UN_LOW,
5727 &lock_flags, &lock_flags2);
5728 if (ch->ch_flags & CH_WLOW) {
5729 ch->ch_flags &= ~CH_WLOW;
5730 wake_up_interruptible(&ch->ch_flags_wait);
5735 * Process Transmit empty.
5737 if (reason & IFTEM) {
5738 dgap_write_wakeup(bd, ch, &ch->ch_tun, UN_EMPTY,
5739 &lock_flags, &lock_flags2);
5740 dgap_write_wakeup(bd, ch, &ch->ch_pun, UN_EMPTY,
5741 &lock_flags, &lock_flags2);
5742 if (ch->ch_flags & CH_WEMPTY) {
5743 ch->ch_flags &= ~CH_WEMPTY;
5744 wake_up_interruptible(&ch->ch_flags_wait);
5748 spin_unlock_irqrestore(&ch->ch_lock, lock_flags2);
5751 tail = (tail + 4) & (EVMAX - EVSTART - 4);
5754 writew(tail, &(eaddr->ev_tail));
5755 spin_unlock_irqrestore(&bd->bd_lock, lock_flags);
5760 static ssize_t dgap_driver_version_show(struct device_driver *ddp, char *buf)
5762 return snprintf(buf, PAGE_SIZE, "%s\n", DG_PART);
5764 static DRIVER_ATTR(version, S_IRUSR, dgap_driver_version_show, NULL);
5767 static ssize_t dgap_driver_boards_show(struct device_driver *ddp, char *buf)
5769 return snprintf(buf, PAGE_SIZE, "%d\n", dgap_NumBoards);
5771 static DRIVER_ATTR(boards, S_IRUSR, dgap_driver_boards_show, NULL);
5774 static ssize_t dgap_driver_maxboards_show(struct device_driver *ddp, char *buf)
5776 return snprintf(buf, PAGE_SIZE, "%d\n", MAXBOARDS);
5778 static DRIVER_ATTR(maxboards, S_IRUSR, dgap_driver_maxboards_show, NULL);
5781 static ssize_t dgap_driver_pollcounter_show(struct device_driver *ddp,
5784 return snprintf(buf, PAGE_SIZE, "%ld\n", dgap_poll_counter);
5786 static DRIVER_ATTR(pollcounter, S_IRUSR, dgap_driver_pollcounter_show, NULL);
5788 static ssize_t dgap_driver_pollrate_show(struct device_driver *ddp, char *buf)
5790 return snprintf(buf, PAGE_SIZE, "%dms\n", dgap_poll_tick);
5793 static ssize_t dgap_driver_pollrate_store(struct device_driver *ddp,
5794 const char *buf, size_t count)
5796 if (sscanf(buf, "%d\n", &dgap_poll_tick) != 1)
5800 static DRIVER_ATTR(pollrate, (S_IRUSR | S_IWUSR), dgap_driver_pollrate_show,
5801 dgap_driver_pollrate_store);
5803 static int dgap_create_driver_sysfiles(struct pci_driver *dgap_driver)
5806 struct device_driver *driverfs = &dgap_driver->driver;
5808 rc |= driver_create_file(driverfs, &driver_attr_version);
5809 rc |= driver_create_file(driverfs, &driver_attr_boards);
5810 rc |= driver_create_file(driverfs, &driver_attr_maxboards);
5811 rc |= driver_create_file(driverfs, &driver_attr_pollrate);
5812 rc |= driver_create_file(driverfs, &driver_attr_pollcounter);
5817 static void dgap_remove_driver_sysfiles(struct pci_driver *dgap_driver)
5819 struct device_driver *driverfs = &dgap_driver->driver;
5820 driver_remove_file(driverfs, &driver_attr_version);
5821 driver_remove_file(driverfs, &driver_attr_boards);
5822 driver_remove_file(driverfs, &driver_attr_maxboards);
5823 driver_remove_file(driverfs, &driver_attr_pollrate);
5824 driver_remove_file(driverfs, &driver_attr_pollcounter);
5827 static struct board_t *dgap_verify_board(struct device *p)
5834 bd = dev_get_drvdata(p);
5835 if (!bd || bd->magic != DGAP_BOARD_MAGIC || bd->state != BOARD_READY)
5841 static ssize_t dgap_ports_state_show(struct device *p,
5842 struct device_attribute *attr,
5849 bd = dgap_verify_board(p);
5853 for (i = 0; i < bd->nasync; i++) {
5854 count += snprintf(buf + count, PAGE_SIZE - count,
5855 "%d %s\n", bd->channels[i]->ch_portnum,
5856 bd->channels[i]->ch_open_count ? "Open" : "Closed");
5860 static DEVICE_ATTR(ports_state, S_IRUSR, dgap_ports_state_show, NULL);
5862 static ssize_t dgap_ports_baud_show(struct device *p,
5863 struct device_attribute *attr,
5870 bd = dgap_verify_board(p);
5874 for (i = 0; i < bd->nasync; i++) {
5875 count += snprintf(buf + count, PAGE_SIZE - count, "%d %d\n",
5876 bd->channels[i]->ch_portnum,
5877 bd->channels[i]->ch_baud_info);
5881 static DEVICE_ATTR(ports_baud, S_IRUSR, dgap_ports_baud_show, NULL);
5883 static ssize_t dgap_ports_msignals_show(struct device *p,
5884 struct device_attribute *attr,
5891 bd = dgap_verify_board(p);
5895 for (i = 0; i < bd->nasync; i++) {
5896 if (bd->channels[i]->ch_open_count)
5897 count += snprintf(buf + count, PAGE_SIZE - count,
5898 "%d %s %s %s %s %s %s\n",
5899 bd->channels[i]->ch_portnum,
5900 (bd->channels[i]->ch_mostat &
5901 UART_MCR_RTS) ? "RTS" : "",
5902 (bd->channels[i]->ch_mistat &
5903 UART_MSR_CTS) ? "CTS" : "",
5904 (bd->channels[i]->ch_mostat &
5905 UART_MCR_DTR) ? "DTR" : "",
5906 (bd->channels[i]->ch_mistat &
5907 UART_MSR_DSR) ? "DSR" : "",
5908 (bd->channels[i]->ch_mistat &
5909 UART_MSR_DCD) ? "DCD" : "",
5910 (bd->channels[i]->ch_mistat &
5911 UART_MSR_RI) ? "RI" : "");
5913 count += snprintf(buf + count, PAGE_SIZE - count,
5914 "%d\n", bd->channels[i]->ch_portnum);
5918 static DEVICE_ATTR(ports_msignals, S_IRUSR, dgap_ports_msignals_show, NULL);
5920 static ssize_t dgap_ports_iflag_show(struct device *p,
5921 struct device_attribute *attr,
5928 bd = dgap_verify_board(p);
5932 for (i = 0; i < bd->nasync; i++)
5933 count += snprintf(buf + count, PAGE_SIZE - count, "%d %x\n",
5934 bd->channels[i]->ch_portnum,
5935 bd->channels[i]->ch_c_iflag);
5938 static DEVICE_ATTR(ports_iflag, S_IRUSR, dgap_ports_iflag_show, NULL);
5940 static ssize_t dgap_ports_cflag_show(struct device *p,
5941 struct device_attribute *attr,
5948 bd = dgap_verify_board(p);
5952 for (i = 0; i < bd->nasync; i++)
5953 count += snprintf(buf + count, PAGE_SIZE - count, "%d %x\n",
5954 bd->channels[i]->ch_portnum,
5955 bd->channels[i]->ch_c_cflag);
5958 static DEVICE_ATTR(ports_cflag, S_IRUSR, dgap_ports_cflag_show, NULL);
5960 static ssize_t dgap_ports_oflag_show(struct device *p,
5961 struct device_attribute *attr,
5968 bd = dgap_verify_board(p);
5972 for (i = 0; i < bd->nasync; i++)
5973 count += snprintf(buf + count, PAGE_SIZE - count, "%d %x\n",
5974 bd->channels[i]->ch_portnum,
5975 bd->channels[i]->ch_c_oflag);
5978 static DEVICE_ATTR(ports_oflag, S_IRUSR, dgap_ports_oflag_show, NULL);
5980 static ssize_t dgap_ports_lflag_show(struct device *p,
5981 struct device_attribute *attr,
5988 bd = dgap_verify_board(p);
5992 for (i = 0; i < bd->nasync; i++)
5993 count += snprintf(buf + count, PAGE_SIZE - count, "%d %x\n",
5994 bd->channels[i]->ch_portnum,
5995 bd->channels[i]->ch_c_lflag);
5998 static DEVICE_ATTR(ports_lflag, S_IRUSR, dgap_ports_lflag_show, NULL);
6000 static ssize_t dgap_ports_digi_flag_show(struct device *p,
6001 struct device_attribute *attr,
6008 bd = dgap_verify_board(p);
6012 for (i = 0; i < bd->nasync; i++)
6013 count += snprintf(buf + count, PAGE_SIZE - count, "%d %x\n",
6014 bd->channels[i]->ch_portnum,
6015 bd->channels[i]->ch_digi.digi_flags);
6018 static DEVICE_ATTR(ports_digi_flag, S_IRUSR, dgap_ports_digi_flag_show, NULL);
6020 static ssize_t dgap_ports_rxcount_show(struct device *p,
6021 struct device_attribute *attr,
6028 bd = dgap_verify_board(p);
6032 for (i = 0; i < bd->nasync; i++)
6033 count += snprintf(buf + count, PAGE_SIZE - count, "%d %ld\n",
6034 bd->channels[i]->ch_portnum,
6035 bd->channels[i]->ch_rxcount);
6038 static DEVICE_ATTR(ports_rxcount, S_IRUSR, dgap_ports_rxcount_show, NULL);
6040 static ssize_t dgap_ports_txcount_show(struct device *p,
6041 struct device_attribute *attr,
6048 bd = dgap_verify_board(p);
6052 for (i = 0; i < bd->nasync; i++)
6053 count += snprintf(buf + count, PAGE_SIZE - count, "%d %ld\n",
6054 bd->channels[i]->ch_portnum,
6055 bd->channels[i]->ch_txcount);
6058 static DEVICE_ATTR(ports_txcount, S_IRUSR, dgap_ports_txcount_show, NULL);
6060 /* this function creates the sys files that will export each signal status
6061 * to sysfs each value will be put in a separate filename
6063 static void dgap_create_ports_sysfiles(struct board_t *bd)
6065 dev_set_drvdata(&bd->pdev->dev, bd);
6066 device_create_file(&(bd->pdev->dev), &dev_attr_ports_state);
6067 device_create_file(&(bd->pdev->dev), &dev_attr_ports_baud);
6068 device_create_file(&(bd->pdev->dev), &dev_attr_ports_msignals);
6069 device_create_file(&(bd->pdev->dev), &dev_attr_ports_iflag);
6070 device_create_file(&(bd->pdev->dev), &dev_attr_ports_cflag);
6071 device_create_file(&(bd->pdev->dev), &dev_attr_ports_oflag);
6072 device_create_file(&(bd->pdev->dev), &dev_attr_ports_lflag);
6073 device_create_file(&(bd->pdev->dev), &dev_attr_ports_digi_flag);
6074 device_create_file(&(bd->pdev->dev), &dev_attr_ports_rxcount);
6075 device_create_file(&(bd->pdev->dev), &dev_attr_ports_txcount);
6078 /* removes all the sys files created for that port */
6079 static void dgap_remove_ports_sysfiles(struct board_t *bd)
6081 device_remove_file(&(bd->pdev->dev), &dev_attr_ports_state);
6082 device_remove_file(&(bd->pdev->dev), &dev_attr_ports_baud);
6083 device_remove_file(&(bd->pdev->dev), &dev_attr_ports_msignals);
6084 device_remove_file(&(bd->pdev->dev), &dev_attr_ports_iflag);
6085 device_remove_file(&(bd->pdev->dev), &dev_attr_ports_cflag);
6086 device_remove_file(&(bd->pdev->dev), &dev_attr_ports_oflag);
6087 device_remove_file(&(bd->pdev->dev), &dev_attr_ports_lflag);
6088 device_remove_file(&(bd->pdev->dev), &dev_attr_ports_digi_flag);
6089 device_remove_file(&(bd->pdev->dev), &dev_attr_ports_rxcount);
6090 device_remove_file(&(bd->pdev->dev), &dev_attr_ports_txcount);
6093 static ssize_t dgap_tty_state_show(struct device *d,
6094 struct device_attribute *attr,
6098 struct channel_t *ch;
6103 un = dev_get_drvdata(d);
6104 if (!un || un->magic != DGAP_UNIT_MAGIC)
6107 if (!ch || ch->magic != DGAP_CHANNEL_MAGIC)
6110 if (!bd || bd->magic != DGAP_BOARD_MAGIC)
6112 if (bd->state != BOARD_READY)
6115 return snprintf(buf, PAGE_SIZE, "%s", un->un_open_count ?
6118 static DEVICE_ATTR(state, S_IRUSR, dgap_tty_state_show, NULL);
6120 static ssize_t dgap_tty_baud_show(struct device *d,
6121 struct device_attribute *attr,
6125 struct channel_t *ch;
6130 un = dev_get_drvdata(d);
6131 if (!un || un->magic != DGAP_UNIT_MAGIC)
6134 if (!ch || ch->magic != DGAP_CHANNEL_MAGIC)
6137 if (!bd || bd->magic != DGAP_BOARD_MAGIC)
6139 if (bd->state != BOARD_READY)
6142 return snprintf(buf, PAGE_SIZE, "%d\n", ch->ch_baud_info);
6144 static DEVICE_ATTR(baud, S_IRUSR, dgap_tty_baud_show, NULL);
6146 static ssize_t dgap_tty_msignals_show(struct device *d,
6147 struct device_attribute *attr,
6151 struct channel_t *ch;
6156 un = dev_get_drvdata(d);
6157 if (!un || un->magic != DGAP_UNIT_MAGIC)
6160 if (!ch || ch->magic != DGAP_CHANNEL_MAGIC)
6163 if (!bd || bd->magic != DGAP_BOARD_MAGIC)
6165 if (bd->state != BOARD_READY)
6168 if (ch->ch_open_count) {
6169 return snprintf(buf, PAGE_SIZE, "%s %s %s %s %s %s\n",
6170 (ch->ch_mostat & UART_MCR_RTS) ? "RTS" : "",
6171 (ch->ch_mistat & UART_MSR_CTS) ? "CTS" : "",
6172 (ch->ch_mostat & UART_MCR_DTR) ? "DTR" : "",
6173 (ch->ch_mistat & UART_MSR_DSR) ? "DSR" : "",
6174 (ch->ch_mistat & UART_MSR_DCD) ? "DCD" : "",
6175 (ch->ch_mistat & UART_MSR_RI) ? "RI" : "");
6179 static DEVICE_ATTR(msignals, S_IRUSR, dgap_tty_msignals_show, NULL);
6181 static ssize_t dgap_tty_iflag_show(struct device *d,
6182 struct device_attribute *attr,
6186 struct channel_t *ch;
6191 un = dev_get_drvdata(d);
6192 if (!un || un->magic != DGAP_UNIT_MAGIC)
6195 if (!ch || ch->magic != DGAP_CHANNEL_MAGIC)
6198 if (!bd || bd->magic != DGAP_BOARD_MAGIC)
6200 if (bd->state != BOARD_READY)
6203 return snprintf(buf, PAGE_SIZE, "%x\n", ch->ch_c_iflag);
6205 static DEVICE_ATTR(iflag, S_IRUSR, dgap_tty_iflag_show, NULL);
6207 static ssize_t dgap_tty_cflag_show(struct device *d,
6208 struct device_attribute *attr,
6212 struct channel_t *ch;
6217 un = dev_get_drvdata(d);
6218 if (!un || un->magic != DGAP_UNIT_MAGIC)
6221 if (!ch || ch->magic != DGAP_CHANNEL_MAGIC)
6224 if (!bd || bd->magic != DGAP_BOARD_MAGIC)
6226 if (bd->state != BOARD_READY)
6229 return snprintf(buf, PAGE_SIZE, "%x\n", ch->ch_c_cflag);
6231 static DEVICE_ATTR(cflag, S_IRUSR, dgap_tty_cflag_show, NULL);
6233 static ssize_t dgap_tty_oflag_show(struct device *d,
6234 struct device_attribute *attr,
6238 struct channel_t *ch;
6243 un = dev_get_drvdata(d);
6244 if (!un || un->magic != DGAP_UNIT_MAGIC)
6247 if (!ch || ch->magic != DGAP_CHANNEL_MAGIC)
6250 if (!bd || bd->magic != DGAP_BOARD_MAGIC)
6252 if (bd->state != BOARD_READY)
6255 return snprintf(buf, PAGE_SIZE, "%x\n", ch->ch_c_oflag);
6257 static DEVICE_ATTR(oflag, S_IRUSR, dgap_tty_oflag_show, NULL);
6259 static ssize_t dgap_tty_lflag_show(struct device *d,
6260 struct device_attribute *attr,
6264 struct channel_t *ch;
6269 un = dev_get_drvdata(d);
6270 if (!un || un->magic != DGAP_UNIT_MAGIC)
6273 if (!ch || ch->magic != DGAP_CHANNEL_MAGIC)
6276 if (!bd || bd->magic != DGAP_BOARD_MAGIC)
6278 if (bd->state != BOARD_READY)
6281 return snprintf(buf, PAGE_SIZE, "%x\n", ch->ch_c_lflag);
6283 static DEVICE_ATTR(lflag, S_IRUSR, dgap_tty_lflag_show, NULL);
6285 static ssize_t dgap_tty_digi_flag_show(struct device *d,
6286 struct device_attribute *attr,
6290 struct channel_t *ch;
6295 un = dev_get_drvdata(d);
6296 if (!un || un->magic != DGAP_UNIT_MAGIC)
6299 if (!ch || ch->magic != DGAP_CHANNEL_MAGIC)
6302 if (!bd || bd->magic != DGAP_BOARD_MAGIC)
6304 if (bd->state != BOARD_READY)
6307 return snprintf(buf, PAGE_SIZE, "%x\n", ch->ch_digi.digi_flags);
6309 static DEVICE_ATTR(digi_flag, S_IRUSR, dgap_tty_digi_flag_show, NULL);
6311 static ssize_t dgap_tty_rxcount_show(struct device *d,
6312 struct device_attribute *attr,
6316 struct channel_t *ch;
6321 un = dev_get_drvdata(d);
6322 if (!un || un->magic != DGAP_UNIT_MAGIC)
6325 if (!ch || ch->magic != DGAP_CHANNEL_MAGIC)
6328 if (!bd || bd->magic != DGAP_BOARD_MAGIC)
6330 if (bd->state != BOARD_READY)
6333 return snprintf(buf, PAGE_SIZE, "%ld\n", ch->ch_rxcount);
6335 static DEVICE_ATTR(rxcount, S_IRUSR, dgap_tty_rxcount_show, NULL);
6337 static ssize_t dgap_tty_txcount_show(struct device *d,
6338 struct device_attribute *attr,
6342 struct channel_t *ch;
6347 un = dev_get_drvdata(d);
6348 if (!un || un->magic != DGAP_UNIT_MAGIC)
6351 if (!ch || ch->magic != DGAP_CHANNEL_MAGIC)
6354 if (!bd || bd->magic != DGAP_BOARD_MAGIC)
6356 if (bd->state != BOARD_READY)
6359 return snprintf(buf, PAGE_SIZE, "%ld\n", ch->ch_txcount);
6361 static DEVICE_ATTR(txcount, S_IRUSR, dgap_tty_txcount_show, NULL);
6363 static ssize_t dgap_tty_name_show(struct device *d,
6364 struct device_attribute *attr,
6368 struct channel_t *ch;
6372 struct cnode *cptr = NULL;
6380 un = dev_get_drvdata(d);
6381 if (!un || un->magic != DGAP_UNIT_MAGIC)
6384 if (!ch || ch->magic != DGAP_CHANNEL_MAGIC)
6387 if (!bd || bd->magic != DGAP_BOARD_MAGIC)
6389 if (bd->state != BOARD_READY)
6393 cn = ch->ch_portnum;
6395 for (cptr = bd->bd_config; cptr; cptr = cptr->next) {
6397 if ((cptr->type == BNODE) &&
6398 ((cptr->u.board.type == APORT2_920P) ||
6399 (cptr->u.board.type == APORT4_920P) ||
6400 (cptr->u.board.type == APORT8_920P) ||
6401 (cptr->u.board.type == PAPORT4) ||
6402 (cptr->u.board.type == PAPORT8))) {
6405 if (cptr->u.board.v_start)
6406 starto = cptr->u.board.start;
6411 if (cptr->type == TNODE && found == TRUE) {
6413 if (strstr(cptr->u.ttyname, "tty")) {
6414 ptr1 = cptr->u.ttyname;
6417 ptr1 = cptr->u.ttyname;
6419 for (i = 0; i < dgap_config_get_num_prts(bd); i++) {
6423 return snprintf(buf, PAGE_SIZE, "%s%s%02d\n",
6424 (un->un_type == DGAP_PRINT) ?
6430 if (cptr->type == CNODE) {
6432 for (i = 0; i < cptr->u.conc.nport; i++) {
6433 if (cn != (i + ncount))
6436 return snprintf(buf, PAGE_SIZE, "%s%s%02ld\n",
6437 (un->un_type == DGAP_PRINT) ?
6440 i + (cptr->u.conc.v_start ?
6441 cptr->u.conc.start : 1));
6444 ncount += cptr->u.conc.nport;
6447 if (cptr->type == MNODE) {
6449 for (i = 0; i < cptr->u.module.nport; i++) {
6450 if (cn != (i + ncount))
6453 return snprintf(buf, PAGE_SIZE, "%s%s%02ld\n",
6454 (un->un_type == DGAP_PRINT) ?
6457 i + (cptr->u.module.v_start ?
6458 cptr->u.module.start : 1));
6461 ncount += cptr->u.module.nport;
6466 return snprintf(buf, PAGE_SIZE, "%s_dgap_%d_%d\n",
6467 (un->un_type == DGAP_PRINT) ? "pr" : "tty", bn, cn);
6470 static DEVICE_ATTR(custom_name, S_IRUSR, dgap_tty_name_show, NULL);
6472 static struct attribute *dgap_sysfs_tty_entries[] = {
6473 &dev_attr_state.attr,
6474 &dev_attr_baud.attr,
6475 &dev_attr_msignals.attr,
6476 &dev_attr_iflag.attr,
6477 &dev_attr_cflag.attr,
6478 &dev_attr_oflag.attr,
6479 &dev_attr_lflag.attr,
6480 &dev_attr_digi_flag.attr,
6481 &dev_attr_rxcount.attr,
6482 &dev_attr_txcount.attr,
6483 &dev_attr_custom_name.attr,
6487 static struct attribute_group dgap_tty_attribute_group = {
6489 .attrs = dgap_sysfs_tty_entries,
6492 static void dgap_create_tty_sysfs(struct un_t *un, struct device *c)
6496 ret = sysfs_create_group(&c->kobj, &dgap_tty_attribute_group);
6500 dev_set_drvdata(c, un);
6504 static void dgap_remove_tty_sysfs(struct device *c)
6506 sysfs_remove_group(&c->kobj, &dgap_tty_attribute_group);
6510 * Parse a configuration file read into memory as a string.
6512 static int dgap_parsefile(char **in, int Remove)
6514 struct cnode *p, *brd, *line, *conc;
6520 brd = line = conc = NULL;
6522 /* perhaps we are adding to an existing list? */
6523 while (p->next != NULL)
6526 /* file must start with a BEGIN */
6527 while ((rc = dgap_gettok(in, p)) != BEGIN) {
6529 dgap_err("unexpected EOF");
6535 rc = dgap_gettok(in, p);
6537 dgap_err("unexpected EOF");
6543 dgap_err("unexpected end of file");
6546 case BEGIN: /* should only be 1 begin */
6547 dgap_err("unexpected config_begin\n");
6553 case BOARD: /* board info */
6554 if (dgap_checknode(p))
6556 p->next = dgap_newnode(BNODE);
6558 dgap_err("out of memory");
6563 p->u.board.status = dgap_savestring("No");
6569 case APORT2_920P: /* AccelePort_4 */
6570 if (p->type != BNODE) {
6571 dgap_err("unexpected Digi_2r_920 string");
6574 p->u.board.type = APORT2_920P;
6575 p->u.board.v_type = 1;
6578 case APORT4_920P: /* AccelePort_4 */
6579 if (p->type != BNODE) {
6580 dgap_err("unexpected Digi_4r_920 string");
6583 p->u.board.type = APORT4_920P;
6584 p->u.board.v_type = 1;
6587 case APORT8_920P: /* AccelePort_8 */
6588 if (p->type != BNODE) {
6589 dgap_err("unexpected Digi_8r_920 string");
6592 p->u.board.type = APORT8_920P;
6593 p->u.board.v_type = 1;
6596 case PAPORT4: /* AccelePort_4 PCI */
6597 if (p->type != BNODE) {
6598 dgap_err("unexpected Digi_4r(PCI) string");
6601 p->u.board.type = PAPORT4;
6602 p->u.board.v_type = 1;
6605 case PAPORT8: /* AccelePort_8 PCI */
6606 if (p->type != BNODE) {
6607 dgap_err("unexpected Digi_8r string");
6610 p->u.board.type = PAPORT8;
6611 p->u.board.v_type = 1;
6614 case PCX: /* PCI C/X */
6615 if (p->type != BNODE) {
6616 dgap_err("unexpected Digi_C/X_(PCI) string");
6619 p->u.board.type = PCX;
6620 p->u.board.v_type = 1;
6621 p->u.board.conc1 = 0;
6622 p->u.board.conc2 = 0;
6623 p->u.board.module1 = 0;
6624 p->u.board.module2 = 0;
6627 case PEPC: /* PCI EPC/X */
6628 if (p->type != BNODE) {
6629 dgap_err("unexpected \"Digi_EPC/X_(PCI)\" string");
6632 p->u.board.type = PEPC;
6633 p->u.board.v_type = 1;
6634 p->u.board.conc1 = 0;
6635 p->u.board.conc2 = 0;
6636 p->u.board.module1 = 0;
6637 p->u.board.module2 = 0;
6640 case PPCM: /* PCI/Xem */
6641 if (p->type != BNODE) {
6642 dgap_err("unexpected PCI/Xem string");
6645 p->u.board.type = PPCM;
6646 p->u.board.v_type = 1;
6647 p->u.board.conc1 = 0;
6648 p->u.board.conc2 = 0;
6651 case IO: /* i/o port */
6652 if (p->type != BNODE) {
6653 dgap_err("IO port only vaild for boards");
6656 s = dgap_getword(in);
6658 dgap_err("unexpected end of file");
6661 p->u.board.portstr = dgap_savestring(s);
6662 if (kstrtol(s, 0, &p->u.board.port)) {
6663 dgap_err("bad number for IO port");
6666 p->u.board.v_port = 1;
6669 case MEM: /* memory address */
6670 if (p->type != BNODE) {
6671 dgap_err("memory address only vaild for boards");
6674 s = dgap_getword(in);
6676 dgap_err("unexpected end of file");
6679 p->u.board.addrstr = dgap_savestring(s);
6680 if (kstrtoul(s, 0, &p->u.board.addr)) {
6681 dgap_err("bad number for memory address");
6684 p->u.board.v_addr = 1;
6687 case PCIINFO: /* pci information */
6688 if (p->type != BNODE) {
6689 dgap_err("memory address only vaild for boards");
6692 s = dgap_getword(in);
6694 dgap_err("unexpected end of file");
6697 p->u.board.pcibusstr = dgap_savestring(s);
6698 if (kstrtoul(s, 0, &p->u.board.pcibus)) {
6699 dgap_err("bad number for pci bus");
6702 p->u.board.v_pcibus = 1;
6703 s = dgap_getword(in);
6705 dgap_err("unexpected end of file");
6708 p->u.board.pcislotstr = dgap_savestring(s);
6709 if (kstrtoul(s, 0, &p->u.board.pcislot)) {
6710 dgap_err("bad number for pci slot");
6713 p->u.board.v_pcislot = 1;
6717 if (p->type != BNODE) {
6718 dgap_err("install method only vaild for boards");
6721 s = dgap_getword(in);
6723 dgap_err("unexpected end of file");
6726 p->u.board.method = dgap_savestring(s);
6727 p->u.board.v_method = 1;
6731 if (p->type != BNODE) {
6732 dgap_err("config status only vaild for boards");
6735 s = dgap_getword(in);
6737 dgap_err("unexpected end of file");
6740 p->u.board.status = dgap_savestring(s);
6743 case NPORTS: /* number of ports */
6744 if (p->type == BNODE) {
6745 s = dgap_getword(in);
6747 dgap_err("unexpected end of file");
6750 if (kstrtol(s, 0, &p->u.board.nport)) {
6751 dgap_err("bad number for number of ports");
6754 p->u.board.v_nport = 1;
6755 } else if (p->type == CNODE) {
6756 s = dgap_getword(in);
6758 dgap_err("unexpected end of file");
6761 if (kstrtol(s, 0, &p->u.conc.nport)) {
6762 dgap_err("bad number for number of ports");
6765 p->u.conc.v_nport = 1;
6766 } else if (p->type == MNODE) {
6767 s = dgap_getword(in);
6769 dgap_err("unexpected end of file");
6772 if (kstrtol(s, 0, &p->u.module.nport)) {
6773 dgap_err("bad number for number of ports");
6776 p->u.module.v_nport = 1;
6778 dgap_err("nports only valid for concentrators or modules");
6783 case ID: /* letter ID used in tty name */
6784 s = dgap_getword(in);
6786 dgap_err("unexpected end of file");
6790 p->u.board.status = dgap_savestring(s);
6792 if (p->type == CNODE) {
6793 p->u.conc.id = dgap_savestring(s);
6795 } else if (p->type == MNODE) {
6796 p->u.module.id = dgap_savestring(s);
6797 p->u.module.v_id = 1;
6799 dgap_err("id only valid for concentrators or modules");
6804 case STARTO: /* start offset of ID */
6805 if (p->type == BNODE) {
6806 s = dgap_getword(in);
6808 dgap_err("unexpected end of file");
6811 if (kstrtol(s, 0, &p->u.board.start)) {
6812 dgap_err("bad number for start of tty count");
6815 p->u.board.v_start = 1;
6816 } else if (p->type == CNODE) {
6817 s = dgap_getword(in);
6819 dgap_err("unexpected end of file");
6822 if (kstrtol(s, 0, &p->u.conc.start)) {
6823 dgap_err("bad number for start of tty count");
6826 p->u.conc.v_start = 1;
6827 } else if (p->type == MNODE) {
6828 s = dgap_getword(in);
6830 dgap_err("unexpected end of file");
6833 if (kstrtol(s, 0, &p->u.module.start)) {
6834 dgap_err("bad number for start of tty count");
6837 p->u.module.v_start = 1;
6839 dgap_err("start only valid for concentrators or modules");
6844 case TTYN: /* tty name prefix */
6845 if (dgap_checknode(p))
6847 p->next = dgap_newnode(TNODE);
6849 dgap_err("out of memory");
6853 s = dgap_getword(in);
6855 dgap_err("unexpeced end of file");
6858 p->u.ttyname = dgap_savestring(s);
6859 if (!p->u.ttyname) {
6860 dgap_err("out of memory");
6865 case CU: /* cu name prefix */
6866 if (dgap_checknode(p))
6868 p->next = dgap_newnode(CUNODE);
6870 dgap_err("out of memory");
6874 s = dgap_getword(in);
6876 dgap_err("unexpeced end of file");
6879 p->u.cuname = dgap_savestring(s);
6881 dgap_err("out of memory");
6886 case LINE: /* line information */
6887 if (dgap_checknode(p))
6890 dgap_err("must specify board before line info");
6893 switch (brd->u.board.type) {
6895 dgap_err("line not vaild for PC/em");
6898 p->next = dgap_newnode(LNODE);
6900 dgap_err("out of memory");
6909 case CONC: /* concentrator information */
6910 if (dgap_checknode(p))
6913 dgap_err("must specify line info before concentrator");
6916 p->next = dgap_newnode(CNODE);
6918 dgap_err("out of memory");
6924 brd->u.board.conc2++;
6926 brd->u.board.conc1++;
6930 case CX: /* c/x type concentrator */
6931 if (p->type != CNODE) {
6932 dgap_err("cx only valid for concentrators");
6935 p->u.conc.type = CX;
6936 p->u.conc.v_type = 1;
6939 case EPC: /* epc type concentrator */
6940 if (p->type != CNODE) {
6941 dgap_err("cx only valid for concentrators");
6944 p->u.conc.type = EPC;
6945 p->u.conc.v_type = 1;
6948 case MOD: /* EBI module */
6949 if (dgap_checknode(p))
6952 dgap_err("must specify board info before EBI modules");
6955 switch (brd->u.board.type) {
6961 dgap_err("must specify concentrator info before EBI module");
6965 p->next = dgap_newnode(MNODE);
6967 dgap_err("out of memory");
6972 brd->u.board.module2++;
6974 brd->u.board.module1++;
6978 case PORTS: /* ports type EBI module */
6979 if (p->type != MNODE) {
6980 dgap_err("ports only valid for EBI modules");
6983 p->u.module.type = PORTS;
6984 p->u.module.v_type = 1;
6987 case MODEM: /* ports type EBI module */
6988 if (p->type != MNODE) {
6989 dgap_err("modem only valid for modem modules");
6992 p->u.module.type = MODEM;
6993 p->u.module.v_type = 1;
6997 if (p->type == LNODE) {
6998 s = dgap_getword(in);
7000 dgap_err("unexpected end of file");
7003 p->u.line.cable = dgap_savestring(s);
7004 p->u.line.v_cable = 1;
7008 case SPEED: /* sync line speed indication */
7009 if (p->type == LNODE) {
7010 s = dgap_getword(in);
7012 dgap_err("unexpected end of file");
7015 if (kstrtol(s, 0, &p->u.line.speed)) {
7016 dgap_err("bad number for line speed");
7019 p->u.line.v_speed = 1;
7020 } else if (p->type == CNODE) {
7021 s = dgap_getword(in);
7023 dgap_err("unexpected end of file");
7026 if (kstrtol(s, 0, &p->u.conc.speed)) {
7027 dgap_err("bad number for line speed");
7030 p->u.conc.v_speed = 1;
7032 dgap_err("speed valid only for lines or concentrators.");
7038 if (p->type == CNODE) {
7039 s = dgap_getword(in);
7041 dgap_err("unexpected end of file");
7044 p->u.conc.connect = dgap_savestring(s);
7045 p->u.conc.v_connect = 1;
7048 case PRINT: /* transparent print name prefix */
7049 if (dgap_checknode(p))
7051 p->next = dgap_newnode(PNODE);
7053 dgap_err("out of memory");
7057 s = dgap_getword(in);
7059 dgap_err("unexpeced end of file");
7062 p->u.printname = dgap_savestring(s);
7063 if (!p->u.printname) {
7064 dgap_err("out of memory");
7069 case CMAJOR: /* major number */
7070 if (dgap_checknode(p))
7072 p->next = dgap_newnode(JNODE);
7074 dgap_err("out of memory");
7078 s = dgap_getword(in);
7080 dgap_err("unexpected end of file");
7083 if (kstrtol(s, 0, &p->u.majornumber)) {
7084 dgap_err("bad number for major number");
7089 case ALTPIN: /* altpin setting */
7090 if (dgap_checknode(p))
7092 p->next = dgap_newnode(ANODE);
7094 dgap_err("out of memory");
7098 s = dgap_getword(in);
7100 dgap_err("unexpected end of file");
7103 if (kstrtol(s, 0, &p->u.altpin)) {
7104 dgap_err("bad number for altpin");
7109 case USEINTR: /* enable interrupt setting */
7110 if (dgap_checknode(p))
7112 p->next = dgap_newnode(INTRNODE);
7114 dgap_err("out of memory");
7118 s = dgap_getword(in);
7120 dgap_err("unexpected end of file");
7123 if (kstrtol(s, 0, &p->u.useintr)) {
7124 dgap_err("bad number for useintr");
7129 case TTSIZ: /* size of tty structure */
7130 if (dgap_checknode(p))
7132 p->next = dgap_newnode(TSNODE);
7134 dgap_err("out of memory");
7138 s = dgap_getword(in);
7140 dgap_err("unexpected end of file");
7143 if (kstrtol(s, 0, &p->u.ttysize)) {
7144 dgap_err("bad number for ttysize");
7149 case CHSIZ: /* channel structure size */
7150 if (dgap_checknode(p))
7152 p->next = dgap_newnode(CSNODE);
7154 dgap_err("out of memory");
7158 s = dgap_getword(in);
7160 dgap_err("unexpected end of file");
7163 if (kstrtol(s, 0, &p->u.chsize)) {
7164 dgap_err("bad number for chsize");
7169 case BSSIZ: /* board structure size */
7170 if (dgap_checknode(p))
7172 p->next = dgap_newnode(BSNODE);
7174 dgap_err("out of memory");
7178 s = dgap_getword(in);
7180 dgap_err("unexpected end of file");
7183 if (kstrtol(s, 0, &p->u.bssize)) {
7184 dgap_err("bad number for bssize");
7189 case UNTSIZ: /* sched structure size */
7190 if (dgap_checknode(p))
7192 p->next = dgap_newnode(USNODE);
7194 dgap_err("out of memory");
7198 s = dgap_getword(in);
7200 dgap_err("unexpected end of file");
7203 if (kstrtol(s, 0, &p->u.unsize)) {
7204 dgap_err("bad number for schedsize");
7209 case F2SIZ: /* f2200 structure size */
7210 if (dgap_checknode(p))
7212 p->next = dgap_newnode(FSNODE);
7214 dgap_err("out of memory");
7218 s = dgap_getword(in);
7220 dgap_err("unexpected end of file");
7223 if (kstrtol(s, 0, &p->u.f2size)) {
7224 dgap_err("bad number for f2200size");
7229 case VPSIZ: /* vpix structure size */
7230 if (dgap_checknode(p))
7232 p->next = dgap_newnode(VSNODE);
7234 dgap_err("out of memory");
7238 s = dgap_getword(in);
7240 dgap_err("unexpected end of file");
7243 if (kstrtol(s, 0, &p->u.vpixsize)) {
7244 dgap_err("bad number for vpixsize");
7253 * dgap_sindex: much like index(), but it looks for a match of any character in
7254 * the group, and returns that position. If the first character is a ^, then
7255 * this will match the first occurrence not in that group.
7257 static char *dgap_sindex(char *string, char *group)
7261 if (!string || !group)
7262 return (char *) NULL;
7264 if (*group == '^') {
7266 for (; *string; string++) {
7267 for (ptr = group; *ptr; ptr++) {
7268 if (*ptr == *string)
7275 for (; *string; string++) {
7276 for (ptr = group; *ptr; ptr++) {
7277 if (*ptr == *string)
7283 return (char *) NULL;
7287 * Get a token from the input file; return 0 if end of file is reached
7289 static int dgap_gettok(char **in, struct cnode *p)
7294 if (strstr(dgap_cword, "boar")) {
7295 w = dgap_getword(in);
7296 snprintf(dgap_cword, MAXCWORD, "%s", w);
7297 for (t = dgap_tlist; t->token != 0; t++) {
7298 if (!strcmp(w, t->string))
7301 dgap_err("board !!type not specified");
7304 while ((w = dgap_getword(in))) {
7305 snprintf(dgap_cword, MAXCWORD, "%s", w);
7306 for (t = dgap_tlist; t->token != 0; t++) {
7307 if (!strcmp(w, t->string))
7316 * get a word from the input stream, also keep track of current line number.
7317 * words are separated by whitespace.
7319 static char *dgap_getword(char **in)
7321 char *ret_ptr = *in;
7323 char *ptr = dgap_sindex(*in, " \t\n");
7325 /* If no word found, return null */
7329 /* Mark new location for our buffer */
7333 /* Eat any extra spaces/tabs/newlines that might be present */
7334 while (*in && **in && ((**in == ' ') ||
7345 * print an error message, giving the line number in the file where
7346 * the error occurred.
7348 static void dgap_err(char *s)
7350 pr_err("dgap: parse: %s\n", s);
7354 * allocate a new configuration node of type t
7356 static struct cnode *dgap_newnode(int t)
7360 n = kmalloc(sizeof(struct cnode), GFP_ATOMIC);
7362 memset((char *)n, 0, sizeof(struct cnode));
7369 * dgap_checknode: see if all the necessary info has been supplied for a node
7370 * before creating the next node.
7372 static int dgap_checknode(struct cnode *p)
7376 if (p->u.board.v_type == 0) {
7377 dgap_err("board type !not specified");
7384 if (p->u.line.v_speed == 0) {
7385 dgap_err("line speed not specified");
7391 if (p->u.conc.v_type == 0) {
7392 dgap_err("concentrator type not specified");
7395 if (p->u.conc.v_speed == 0) {
7396 dgap_err("concentrator line speed not specified");
7399 if (p->u.conc.v_nport == 0) {
7400 dgap_err("number of ports on concentrator not specified");
7403 if (p->u.conc.v_id == 0) {
7404 dgap_err("concentrator id letter not specified");
7410 if (p->u.module.v_type == 0) {
7411 dgap_err("EBI module type not specified");
7414 if (p->u.module.v_nport == 0) {
7415 dgap_err("number of ports on EBI module not specified");
7418 if (p->u.module.v_id == 0) {
7419 dgap_err("EBI module id letter not specified");
7428 * save a string somewhere
7430 static char *dgap_savestring(char *s)
7434 p = kmalloc(strlen(s) + 1, GFP_ATOMIC);
7441 * Given a board pointer, returns whether we should use interrupts or not.
7443 static uint dgap_config_get_useintr(struct board_t *bd)
7445 struct cnode *p = NULL;
7450 for (p = bd->bd_config; p; p = p->next) {
7454 * check for pcxr types.
7456 return p->u.useintr;
7462 /* If not found, then don't turn on interrupts. */
7467 * Given a board pointer, returns whether we turn on altpin or not.
7469 static uint dgap_config_get_altpin(struct board_t *bd)
7471 struct cnode *p = NULL;
7476 for (p = bd->bd_config; p; p = p->next) {
7480 * check for pcxr types.
7488 /* If not found, then don't turn on interrupts. */
7493 * Given a specific type of board, if found, detached link and
7494 * returns the first occurrence in the list.
7496 static struct cnode *dgap_find_config(int type, int bus, int slot)
7498 struct cnode *p, *prev = NULL, *prev2 = NULL, *found = NULL;
7502 while (p->next != NULL) {
7506 if (p->type == BNODE) {
7508 if (p->u.board.type == type) {
7510 if (p->u.board.v_pcibus &&
7511 p->u.board.pcibus != bus)
7513 if (p->u.board.v_pcislot &&
7514 p->u.board.pcislot != slot)
7519 * Keep walking thru the list till we
7520 * find the next board.
7522 while (p->next != NULL) {
7525 if (p->type == BNODE) {
7528 * Mark the end of our 1 board
7534 * Link the "next" board to the
7535 * previous board, effectively
7536 * "unlinking" our board from
7545 * It must be the last board in the list.
7556 * Given a board pointer, walks the config link, counting up
7557 * all ports user specified should be on the board.
7558 * (This does NOT mean they are all actually present right now tho)
7560 static uint dgap_config_get_num_prts(struct board_t *bd)
7563 struct cnode *p = NULL;
7568 for (p = bd->bd_config; p; p = p->next) {
7573 * check for pcxr types.
7575 if (p->u.board.type > EPCFE)
7576 count += p->u.board.nport;
7579 count += p->u.conc.nport;
7582 count += p->u.module.nport;
7589 static char *dgap_create_config_string(struct board_t *bd, char *string)
7592 struct cnode *p = NULL;
7593 struct cnode *q = NULL;
7601 for (p = bd->bd_config; p; p = p->next) {
7607 *ptr = p->u.line.speed;
7612 * Because the EPC/con concentrators can have EM modules
7613 * hanging off of them, we have to walk ahead in the
7614 * list and keep adding the number of ports on each EM
7615 * to the config. UGH!
7617 speed = p->u.conc.speed;
7619 if ((q != NULL) && (q->type == MNODE)) {
7620 *ptr = (p->u.conc.nport + 0x80);
7623 while ((q->next != NULL) &&
7624 (q->next->type) == MNODE) {
7626 *ptr = (q->u.module.nport + 0x80);
7631 *ptr = q->u.module.nport;
7634 *ptr = p->u.conc.nport;