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 if (dgap_NumBoards >= MAXBOARDS)
578 /* wake up and enable device */
579 rc = pci_enable_device(pdev);
584 rc = dgap_probe1(pdev, ent->driver_data);
587 rc = dgap_firmware_load(pdev, ent->driver_data);
593 static int dgap_probe1(struct pci_dev *pdev, int card_type)
595 return dgap_found_board(pdev, card_type);
598 static void dgap_remove_one(struct pci_dev *dev)
604 * dgap_cleanup_module()
606 * Module unload. This is where it all ends.
608 static void dgap_cleanup_module(void)
613 spin_lock_irqsave(&dgap_poll_lock, lock_flags);
615 spin_unlock_irqrestore(&dgap_poll_lock, lock_flags);
617 /* Turn off poller right away. */
618 del_timer_sync(&dgap_poll_timer);
620 dgap_remove_driver_sysfiles(&dgap_driver);
622 device_destroy(dgap_class, MKDEV(DIGI_DGAP_MAJOR, 0));
623 class_destroy(dgap_class);
624 unregister_chrdev(DIGI_DGAP_MAJOR, "dgap");
626 for (i = 0; i < dgap_NumBoards; ++i) {
627 dgap_remove_ports_sysfiles(dgap_Board[i]);
628 dgap_tty_uninit(dgap_Board[i]);
629 dgap_cleanup_board(dgap_Board[i]);
633 pci_unregister_driver(&dgap_driver);
637 * dgap_cleanup_board()
639 * Free all the memory associated with a board
641 static void dgap_cleanup_board(struct board_t *brd)
645 if (!brd || brd->magic != DGAP_BOARD_MAGIC)
648 if (brd->intr_used && brd->irq)
649 free_irq(brd->irq, brd);
651 tasklet_kill(&brd->helper_tasklet);
653 if (brd->re_map_port) {
654 release_mem_region(brd->membase + 0x200000, 0x200000);
655 iounmap(brd->re_map_port);
656 brd->re_map_port = NULL;
659 if (brd->re_map_membase) {
660 release_mem_region(brd->membase, 0x200000);
661 iounmap(brd->re_map_membase);
662 brd->re_map_membase = NULL;
665 /* Free all allocated channels structs */
666 for (i = 0; i < MAXPORTS ; i++)
667 kfree(brd->channels[i]);
670 kfree(brd->flipflagbuf);
672 dgap_Board[brd->boardnum] = NULL;
680 * A board has been found, init it.
682 static int dgap_found_board(struct pci_dev *pdev, int id)
685 unsigned int pci_irq;
688 /* get the board structure and prep it */
689 brd = kzalloc(sizeof(struct board_t), GFP_KERNEL);
693 dgap_Board[dgap_NumBoards] = brd;
695 /* store the info for the board we've found */
696 brd->magic = DGAP_BOARD_MAGIC;
697 brd->boardnum = dgap_NumBoards;
699 brd->vendor = dgap_pci_tbl[id].vendor;
700 brd->device = dgap_pci_tbl[id].device;
702 brd->pci_bus = pdev->bus->number;
703 brd->pci_slot = PCI_SLOT(pdev->devfn);
704 brd->name = dgap_Ids[id].name;
705 brd->maxports = dgap_Ids[id].maxports;
706 brd->type = dgap_Ids[id].config_type;
707 brd->dpatype = dgap_Ids[id].dpatype;
708 brd->dpastatus = BD_NOFEP;
709 init_waitqueue_head(&brd->state_wait);
711 spin_lock_init(&brd->bd_lock);
714 brd->inhibit_poller = FALSE;
715 brd->wait_for_bios = 0;
716 brd->wait_for_fep = 0;
718 for (i = 0; i < MAXPORTS; i++)
719 brd->channels[i] = NULL;
721 /* store which card & revision we have */
722 pci_read_config_word(pdev, PCI_SUBSYSTEM_VENDOR_ID, &brd->subvendor);
723 pci_read_config_word(pdev, PCI_SUBSYSTEM_ID, &brd->subdevice);
724 pci_read_config_byte(pdev, PCI_REVISION_ID, &brd->rev);
729 /* get the PCI Base Address Registers */
731 /* Xr Jupiter and EPC use BAR 2 */
732 if (brd->device == PCI_DEV_XRJ_DID || brd->device == PCI_DEV_EPCJ_DID) {
733 brd->membase = pci_resource_start(pdev, 2);
734 brd->membase_end = pci_resource_end(pdev, 2);
736 /* Everyone else uses BAR 0 */
738 brd->membase = pci_resource_start(pdev, 0);
739 brd->membase_end = pci_resource_end(pdev, 0);
745 if (brd->membase & 1)
751 * On the PCI boards, there is no IO space allocated
752 * The I/O registers will be in the first 3 bytes of the
753 * upper 2MB of the 4MB memory space. The board memory
754 * will be mapped into the low 2MB of the 4MB memory space
756 brd->port = brd->membase + PCI_IO_OFFSET;
757 brd->port_end = brd->port + PCI_IO_SIZE;
760 * Special initialization for non-PLX boards
762 if (brd->device != PCI_DEV_XRJ_DID && brd->device != PCI_DEV_EPCJ_DID) {
765 pci_write_config_byte(pdev, 0x40, 0);
766 pci_write_config_byte(pdev, 0x46, 0);
768 /* Limit burst length to 2 doubleword transactions */
769 pci_write_config_byte(pdev, 0x42, 1);
772 * Enable IO and mem if not already done.
773 * This was needed for support on Itanium.
775 pci_read_config_word(pdev, PCI_COMMAND, &cmd);
776 cmd |= (PCI_COMMAND_IO | PCI_COMMAND_MEMORY);
777 pci_write_config_word(pdev, PCI_COMMAND, cmd);
780 /* init our poll helper tasklet */
781 tasklet_init(&brd->helper_tasklet, dgap_poll_tasklet,
782 (unsigned long) brd);
784 i = dgap_do_remap(brd);
786 brd->state = BOARD_FAILED;
788 pr_info("dgap: board %d: %s (rev %d), irq %ld\n",
789 dgap_NumBoards, brd->name, brd->rev, brd->irq);
795 static int dgap_finalize_board_init(struct board_t *brd)
799 if (!brd || brd->magic != DGAP_BOARD_MAGIC)
802 brd->use_interrupts = dgap_config_get_useintr(brd);
805 * Set up our interrupt handler if we are set to do interrupts.
807 if (brd->use_interrupts && brd->irq) {
809 rc = request_irq(brd->irq, dgap_intr, IRQF_SHARED, "DGAP", brd);
822 static int dgap_firmware_load(struct pci_dev *pdev, int card_type)
824 struct board_t *brd = dgap_Board[dgap_NumBoards - 1];
825 const struct firmware *fw;
830 dgap_do_reset_board(brd);
832 if ((fw_info[card_type].conf_name) && !dgap_config_buf) {
833 ret = request_firmware(&fw, fw_info[card_type].conf_name,
836 pr_err("dgap: config file %s not found\n",
837 fw_info[card_type].conf_name);
841 dgap_config_buf = kzalloc(fw->size + 1, GFP_KERNEL);
842 if (!dgap_config_buf) {
843 release_firmware(fw);
847 memcpy(dgap_config_buf, fw->data, fw->size);
848 release_firmware(fw);
851 * preserve dgap_config_buf
852 * as dgap_parsefile would
853 * otherwise alter it.
855 tmp_ptr = dgap_config_buf;
857 if (dgap_parsefile(&tmp_ptr, TRUE) != 0) {
858 kfree(dgap_config_buf);
861 kfree(dgap_config_buf);
864 ret = dgap_after_config_loaded(brd->boardnum);
868 * Match this board to a config the user created for us.
871 dgap_find_config(brd->type, brd->pci_bus, brd->pci_slot);
874 * Because the 4 port Xr products share the same PCI ID
875 * as the 8 port Xr products, if we receive a NULL config
876 * back, and this is a PAPORT8 board, retry with a
877 * PAPORT4 attempt as well.
879 if (brd->type == PAPORT8 && !brd->bd_config)
881 dgap_find_config(PAPORT4, brd->pci_bus, brd->pci_slot);
883 if (!brd->bd_config) {
884 pr_err("dgap: No valid configuration found\n");
888 ret = dgap_tty_register(brd);
892 ret = dgap_finalize_board_init(brd);
896 if (fw_info[card_type].bios_name) {
897 ret = request_firmware(&fw, fw_info[card_type].bios_name,
900 pr_err("dgap: bios file %s not found\n",
901 fw_info[card_type].bios_name);
904 dgap_do_bios_load(brd, fw->data, fw->size);
905 release_firmware(fw);
907 /* Wait for BIOS to test board... */
908 ret = dgap_test_bios(brd);
913 if (fw_info[card_type].fep_name) {
914 ret = request_firmware(&fw, fw_info[card_type].fep_name,
917 pr_err("dgap: fep file %s not found\n",
918 fw_info[card_type].fep_name);
921 dgap_do_fep_load(brd, fw->data, fw->size);
922 release_firmware(fw);
924 /* Wait for FEP to load on board... */
925 ret = dgap_test_fep(brd);
930 #ifdef DIGI_CONCENTRATORS_SUPPORTED
932 * If this is a CX or EPCX, we need to see if the firmware
933 * is requesting a concentrator image from us.
935 if ((bd->type == PCX) || (bd->type == PEPC)) {
936 chk_addr = (u16 *) (vaddr + DOWNREQ);
937 /* Nonzero if FEP is requesting concentrator image. */
938 check = readw(chk_addr);
939 vaddr = brd->re_map_membase;
942 if (fw_info[card_type].con_name && check && vaddr) {
943 ret = request_firmware(&fw, fw_info[card_type].con_name,
946 pr_err("dgap: conc file %s not found\n",
947 fw_info[card_type].con_name);
950 /* Put concentrator firmware loading code here */
951 offset = readw((u16 *) (vaddr + DOWNREQ));
952 memcpy_toio(offset, fw->data, fw->size);
954 dgap_do_conc_load(brd, (char *)fw->data, fw->size)
955 release_firmware(fw);
959 * Do tty device initialization.
961 ret = dgap_tty_init(brd);
963 dgap_tty_uninit(brd);
967 ret = dgap_tty_register_ports(brd);
971 brd->state = BOARD_READY;
972 brd->dpastatus = BD_RUNNING;
980 static int dgap_do_remap(struct board_t *brd)
982 if (!brd || brd->magic != DGAP_BOARD_MAGIC)
985 if (!request_mem_region(brd->membase, 0x200000, "dgap"))
988 if (!request_mem_region(brd->membase + PCI_IO_OFFSET, 0x200000,
990 release_mem_region(brd->membase, 0x200000);
994 brd->re_map_membase = ioremap(brd->membase, 0x200000);
995 if (!brd->re_map_membase) {
996 release_mem_region(brd->membase, 0x200000);
997 release_mem_region(brd->membase + PCI_IO_OFFSET, 0x200000);
1001 brd->re_map_port = ioremap((brd->membase + PCI_IO_OFFSET), 0x200000);
1002 if (!brd->re_map_port) {
1003 release_mem_region(brd->membase, 0x200000);
1004 release_mem_region(brd->membase + PCI_IO_OFFSET, 0x200000);
1005 iounmap(brd->re_map_membase);
1012 /*****************************************************************************
1032 * As each timer expires, it determines (a) whether the "transmit"
1033 * waiter needs to be woken up, and (b) whether the poller needs to
1036 ******************************************************************************/
1038 static void dgap_poll_handler(ulong dummy)
1041 struct board_t *brd;
1042 unsigned long lock_flags;
1045 dgap_poll_counter++;
1048 * Do not start the board state machine until
1049 * driver tells us its up and running, and has
1050 * everything it needs.
1052 if (dgap_driver_state != DRIVER_READY)
1053 goto schedule_poller;
1056 * If we have just 1 board, or the system is not SMP,
1057 * then use the typical old style poller.
1058 * Otherwise, use our new tasklet based poller, which should
1059 * speed things up for multiple boards.
1061 if ((dgap_NumBoards == 1) || (num_online_cpus() <= 1)) {
1062 for (i = 0; i < dgap_NumBoards; i++) {
1064 brd = dgap_Board[i];
1066 if (brd->state == BOARD_FAILED)
1068 if (!brd->intr_running)
1069 /* Call the real board poller directly */
1070 dgap_poll_tasklet((unsigned long) brd);
1074 * Go thru each board, kicking off a
1075 * tasklet for each if needed
1077 for (i = 0; i < dgap_NumBoards; i++) {
1078 brd = dgap_Board[i];
1081 * Attempt to grab the board lock.
1083 * If we can't get it, no big deal, the next poll
1084 * will get it. Basically, I just really don't want
1085 * to spin in here, because I want to kick off my
1086 * tasklets as fast as I can, and then get out the
1089 if (!spin_trylock(&brd->bd_lock))
1093 * If board is in a failed state, don't bother
1094 * scheduling a tasklet
1096 if (brd->state == BOARD_FAILED) {
1097 spin_unlock(&brd->bd_lock);
1101 /* Schedule a poll helper task */
1102 if (!brd->intr_running)
1103 tasklet_schedule(&brd->helper_tasklet);
1106 * Can't do DGAP_UNLOCK here, as we don't have
1107 * lock_flags because we did a trylock above.
1109 spin_unlock(&brd->bd_lock);
1116 * Schedule ourself back at the nominal wakeup interval.
1118 spin_lock_irqsave(&dgap_poll_lock, lock_flags);
1119 dgap_poll_time += dgap_jiffies_from_ms(dgap_poll_tick);
1121 new_time = dgap_poll_time - jiffies;
1123 if ((ulong) new_time >= 2 * dgap_poll_tick) {
1125 jiffies + dgap_jiffies_from_ms(dgap_poll_tick);
1128 dgap_poll_timer.function = dgap_poll_handler;
1129 dgap_poll_timer.data = 0;
1130 dgap_poll_timer.expires = dgap_poll_time;
1131 spin_unlock_irqrestore(&dgap_poll_lock, lock_flags);
1133 if (!dgap_poll_stop)
1134 add_timer(&dgap_poll_timer);
1140 * Driver interrupt handler.
1142 static irqreturn_t dgap_intr(int irq, void *voidbrd)
1144 struct board_t *brd = (struct board_t *) voidbrd;
1150 * Check to make sure its for us.
1152 if (brd->magic != DGAP_BOARD_MAGIC)
1158 * Schedule tasklet to run at a better time.
1160 tasklet_schedule(&brd->helper_tasklet);
1165 * dgap_init_globals()
1167 * This is where we initialize the globals from the static insmod
1168 * configuration variables. These are declared near the head of
1171 static void dgap_init_globals(void)
1175 for (i = 0; i < MAXBOARDS; i++)
1176 dgap_Board[i] = NULL;
1178 init_timer(&dgap_poll_timer);
1180 init_waitqueue_head(&dgap_dl_wait);
1183 /************************************************************************
1187 ************************************************************************/
1192 * Put the driver to sleep for x ms's
1194 * Returns 0 if timed out, !0 (showing signal) if interrupted by a signal.
1196 static int dgap_ms_sleep(ulong ms)
1198 current->state = TASK_INTERRUPTIBLE;
1199 schedule_timeout((ms * HZ) / 1000);
1200 return signal_pending(current);
1203 /************************************************************************
1205 * TTY Initialization/Cleanup Functions
1207 ************************************************************************/
1210 * dgap_tty_register()
1212 * Init the tty subsystem for this board.
1214 static int dgap_tty_register(struct board_t *brd)
1218 brd->SerialDriver = alloc_tty_driver(MAXPORTS);
1220 snprintf(brd->SerialName, MAXTTYNAMELEN, "tty_dgap_%d_", brd->boardnum);
1221 brd->SerialDriver->name = brd->SerialName;
1222 brd->SerialDriver->name_base = 0;
1223 brd->SerialDriver->major = 0;
1224 brd->SerialDriver->minor_start = 0;
1225 brd->SerialDriver->type = TTY_DRIVER_TYPE_SERIAL;
1226 brd->SerialDriver->subtype = SERIAL_TYPE_NORMAL;
1227 brd->SerialDriver->init_termios = DgapDefaultTermios;
1228 brd->SerialDriver->driver_name = DRVSTR;
1229 brd->SerialDriver->flags = (TTY_DRIVER_REAL_RAW |
1230 TTY_DRIVER_DYNAMIC_DEV |
1231 TTY_DRIVER_HARDWARE_BREAK);
1233 /* The kernel wants space to store pointers to tty_structs */
1234 brd->SerialDriver->ttys =
1235 kzalloc(MAXPORTS * sizeof(struct tty_struct *), GFP_KERNEL);
1236 if (!brd->SerialDriver->ttys)
1240 * Entry points for driver. Called by the kernel from
1241 * tty_io.c and n_tty.c.
1243 tty_set_operations(brd->SerialDriver, &dgap_tty_ops);
1246 * If we're doing transparent print, we have to do all of the above
1247 * again, separately so we don't get the LD confused about what major
1248 * we are when we get into the dgap_tty_open() routine.
1250 brd->PrintDriver = alloc_tty_driver(MAXPORTS);
1252 snprintf(brd->PrintName, MAXTTYNAMELEN, "pr_dgap_%d_", brd->boardnum);
1253 brd->PrintDriver->name = brd->PrintName;
1254 brd->PrintDriver->name_base = 0;
1255 brd->PrintDriver->major = 0;
1256 brd->PrintDriver->minor_start = 0;
1257 brd->PrintDriver->type = TTY_DRIVER_TYPE_SERIAL;
1258 brd->PrintDriver->subtype = SERIAL_TYPE_NORMAL;
1259 brd->PrintDriver->init_termios = DgapDefaultTermios;
1260 brd->PrintDriver->driver_name = DRVSTR;
1261 brd->PrintDriver->flags = (TTY_DRIVER_REAL_RAW |
1262 TTY_DRIVER_DYNAMIC_DEV |
1263 TTY_DRIVER_HARDWARE_BREAK);
1265 /* The kernel wants space to store pointers to tty_structs */
1266 brd->PrintDriver->ttys =
1267 kzalloc(MAXPORTS * sizeof(struct tty_struct *), GFP_KERNEL);
1268 if (!brd->PrintDriver->ttys)
1272 * Entry points for driver. Called by the kernel from
1273 * tty_io.c and n_tty.c.
1275 tty_set_operations(brd->PrintDriver, &dgap_tty_ops);
1277 /* Register tty devices */
1278 rc = tty_register_driver(brd->SerialDriver);
1281 brd->dgap_Major_Serial_Registered = TRUE;
1282 dgap_BoardsByMajor[brd->SerialDriver->major] = brd;
1283 brd->dgap_Serial_Major = brd->SerialDriver->major;
1285 /* Register Transparent Print devices */
1286 rc = tty_register_driver(brd->PrintDriver);
1289 brd->dgap_Major_TransparentPrint_Registered = TRUE;
1290 dgap_BoardsByMajor[brd->PrintDriver->major] = brd;
1291 brd->dgap_TransparentPrint_Major = brd->PrintDriver->major;
1299 * Init the tty subsystem. Called once per board after board has been
1300 * downloaded and init'ed.
1302 static int dgap_tty_init(struct board_t *brd)
1306 uint true_count = 0;
1309 struct channel_t *ch;
1310 struct bs_t __iomem *bs;
1311 struct cm_t __iomem *cm;
1317 * Initialize board structure elements.
1320 vaddr = brd->re_map_membase;
1321 true_count = readw((vaddr + NCHAN));
1323 brd->nasync = dgap_config_get_num_prts(brd);
1326 brd->nasync = brd->maxports;
1328 if (brd->nasync > brd->maxports)
1329 brd->nasync = brd->maxports;
1331 if (true_count != brd->nasync) {
1332 if ((brd->type == PPCM) && (true_count == 64)) {
1333 pr_warn("dgap: %s configured for %d ports, has %d ports.\n",
1334 brd->name, brd->nasync, true_count);
1335 pr_warn("dgap: Please make SURE the EBI cable running from the card\n");
1336 pr_warn("dgap: to each EM module is plugged into EBI IN!\n");
1337 } else if ((brd->type == PPCM) && (true_count == 0)) {
1338 pr_warn("dgap: %s configured for %d ports, has %d ports.\n",
1339 brd->name, brd->nasync, true_count);
1340 pr_warn("dgap: Please make SURE the EBI cable running from the card\n");
1341 pr_warn("dgap: to each EM module is plugged into EBI IN!\n");
1343 pr_warn("dgap: %s configured for %d ports, has %d ports.\n",
1344 brd->name, brd->nasync, true_count);
1346 brd->nasync = true_count;
1348 /* If no ports, don't bother going any further */
1350 brd->state = BOARD_FAILED;
1351 brd->dpastatus = BD_NOFEP;
1357 * Allocate channel memory that might not have been allocated
1358 * when the driver was first loaded.
1360 for (i = 0; i < brd->nasync; i++) {
1361 if (!brd->channels[i]) {
1363 kzalloc(sizeof(struct channel_t), GFP_ATOMIC);
1364 if (!brd->channels[i])
1369 ch = brd->channels[0];
1370 vaddr = brd->re_map_membase;
1372 bs = (struct bs_t __iomem *) ((ulong) vaddr + CHANBUF);
1373 cm = (struct cm_t __iomem *) ((ulong) vaddr + CMDBUF);
1377 /* Set up channel variables */
1378 for (i = 0; i < brd->nasync; i++, ch = brd->channels[i], bs++) {
1380 if (!brd->channels[i])
1383 spin_lock_init(&ch->ch_lock);
1385 /* Store all our magic numbers */
1386 ch->magic = DGAP_CHANNEL_MAGIC;
1387 ch->ch_tun.magic = DGAP_UNIT_MAGIC;
1388 ch->ch_tun.un_type = DGAP_SERIAL;
1389 ch->ch_tun.un_ch = ch;
1390 ch->ch_tun.un_dev = i;
1392 ch->ch_pun.magic = DGAP_UNIT_MAGIC;
1393 ch->ch_pun.un_type = DGAP_PRINT;
1394 ch->ch_pun.un_ch = ch;
1395 ch->ch_pun.un_dev = i;
1397 ch->ch_vaddr = vaddr;
1402 ch->ch_digi = dgap_digi_init;
1405 * Set up digi dsr and dcd bits based on altpin flag.
1407 if (dgap_config_get_altpin(brd)) {
1410 ch->ch_digi.digi_flags |= DIGI_ALTPIN;
1413 ch->ch_dsr = DM_DSR;
1416 ch->ch_taddr = vaddr + ((ch->ch_bs->tx_seg) << 4);
1417 ch->ch_raddr = vaddr + ((ch->ch_bs->rx_seg) << 4);
1420 ch->ch_tsize = readw(&(ch->ch_bs->tx_max)) + 1;
1421 ch->ch_rsize = readw(&(ch->ch_bs->rx_max)) + 1;
1425 /* .25 second delay */
1426 ch->ch_close_delay = 250;
1429 * Set queue water marks, interrupt mask,
1430 * and general tty parameters.
1432 tlw = ch->ch_tsize >= 2000 ? ((ch->ch_tsize * 5) / 8) :
1436 dgap_cmdw(ch, STLOW, tlw, 0);
1438 dgap_cmdw(ch, SRLOW, ch->ch_rsize / 2, 0);
1440 dgap_cmdw(ch, SRHIGH, 7 * ch->ch_rsize / 8, 0);
1442 ch->ch_mistat = readb(&(ch->ch_bs->m_stat));
1444 init_waitqueue_head(&ch->ch_flags_wait);
1445 init_waitqueue_head(&ch->ch_tun.un_flags_wait);
1446 init_waitqueue_head(&ch->ch_pun.un_flags_wait);
1447 init_waitqueue_head(&ch->ch_sniff_wait);
1449 /* Turn on all modem interrupts for now */
1450 modem = (DM_CD | DM_DSR | DM_CTS | DM_RI);
1451 writeb(modem, &(ch->ch_bs->m_int));
1454 * Set edelay to 0 if interrupts are turned on,
1455 * otherwise set edelay to the usual 100.
1458 writew(0, &(ch->ch_bs->edelay));
1460 writew(100, &(ch->ch_bs->edelay));
1462 writeb(1, &(ch->ch_bs->idata));
1471 * Uninitialize the TTY portion of this driver. Free all memory and
1474 static void dgap_tty_uninit(struct board_t *brd)
1479 if (brd->dgap_Major_Serial_Registered) {
1480 dgap_BoardsByMajor[brd->SerialDriver->major] = NULL;
1481 brd->dgap_Serial_Major = 0;
1482 for (i = 0; i < brd->nasync; i++) {
1483 tty_port_destroy(&brd->SerialPorts[i]);
1484 dev = brd->channels[i]->ch_tun.un_sysfs;
1485 dgap_remove_tty_sysfs(dev);
1486 tty_unregister_device(brd->SerialDriver, i);
1488 tty_unregister_driver(brd->SerialDriver);
1489 kfree(brd->SerialDriver->ttys);
1490 brd->SerialDriver->ttys = NULL;
1491 put_tty_driver(brd->SerialDriver);
1492 kfree(brd->SerialPorts);
1493 brd->dgap_Major_Serial_Registered = FALSE;
1496 if (brd->dgap_Major_TransparentPrint_Registered) {
1497 dgap_BoardsByMajor[brd->PrintDriver->major] = NULL;
1498 brd->dgap_TransparentPrint_Major = 0;
1499 for (i = 0; i < brd->nasync; i++) {
1500 tty_port_destroy(&brd->PrinterPorts[i]);
1501 dev = brd->channels[i]->ch_pun.un_sysfs;
1502 dgap_remove_tty_sysfs(dev);
1503 tty_unregister_device(brd->PrintDriver, i);
1505 tty_unregister_driver(brd->PrintDriver);
1506 kfree(brd->PrintDriver->ttys);
1507 brd->PrintDriver->ttys = NULL;
1508 put_tty_driver(brd->PrintDriver);
1509 kfree(brd->PrinterPorts);
1510 brd->dgap_Major_TransparentPrint_Registered = FALSE;
1514 #define TMPBUFLEN (1024)
1516 * dgap_sniff - Dump data out to the "sniff" buffer if the
1517 * proc sniff file is opened...
1519 static void dgap_sniff_nowait_nolock(struct channel_t *ch, u8 *text,
1528 char tmpbuf[TMPBUFLEN];
1532 /* Leave if sniff not open */
1533 if (!(ch->ch_sniff_flags & SNIFF_OPEN))
1536 do_gettimeofday(&tv);
1538 /* Create our header for data dump */
1539 p += sprintf(p, "<%ld %ld><%s><", tv.tv_sec, tv.tv_usec, text);
1540 tmpbuflen = p - tmpbuf;
1545 for (i = 0; i < len && tmpbuflen < (TMPBUFLEN - 4); i++) {
1546 p += sprintf(p, "%02x ", *buf);
1548 tmpbuflen = p - tmpbuf;
1551 if (tmpbuflen < (TMPBUFLEN - 4)) {
1553 p += sprintf(p - 1, "%s\n", ">");
1555 p += sprintf(p, "%s\n", ">");
1561 nbuf = strlen(tmpbuf);
1565 * Loop while data remains.
1567 while (nbuf > 0 && ch->ch_sniff_buf) {
1569 * Determine the amount of available space left in the
1570 * buffer. If there's none, wait until some appears.
1572 n = (ch->ch_sniff_out - ch->ch_sniff_in - 1) &
1576 * If there is no space left to write to in our sniff
1577 * buffer, we have no choice but to drop the data.
1578 * We *cannot* sleep here waiting for space, because
1579 * this function was probably called by the
1580 * interrupt/timer routines!
1586 * Copy as much data as will fit.
1592 r = SNIFF_MAX - ch->ch_sniff_in;
1595 memcpy(ch->ch_sniff_buf +
1596 ch->ch_sniff_in, p, r);
1599 ch->ch_sniff_in = 0;
1604 memcpy(ch->ch_sniff_buf + ch->ch_sniff_in, p, n);
1606 ch->ch_sniff_in += n;
1611 * Wakeup any thread waiting for data
1613 if (ch->ch_sniff_flags & SNIFF_WAIT_DATA) {
1614 ch->ch_sniff_flags &= ~SNIFF_WAIT_DATA;
1615 wake_up_interruptible(&ch->ch_sniff_wait);
1620 * If the user sent us too much data to push into our tmpbuf,
1621 * we need to keep looping around on all the data.
1623 if (too_much_data) {
1628 } while (too_much_data);
1631 /*=======================================================================
1633 * dgap_input - Process received data.
1635 * ch - Pointer to channel structure.
1637 *=======================================================================*/
1639 static void dgap_input(struct channel_t *ch)
1642 struct bs_t __iomem *bs;
1643 struct tty_struct *tp;
1644 struct tty_ldisc *ld;
1658 if (!ch || ch->magic != DGAP_CHANNEL_MAGIC)
1661 tp = ch->ch_tun.un_tty;
1668 if (!bd || bd->magic != DGAP_BOARD_MAGIC)
1671 spin_lock_irqsave(&bd->bd_lock, lock_flags);
1672 spin_lock_irqsave(&ch->ch_lock, lock_flags2);
1675 * Figure the number of characters in the buffer.
1676 * Exit immediately if none.
1679 rmask = ch->ch_rsize - 1;
1681 head = readw(&(bs->rx_head));
1683 tail = readw(&(bs->rx_tail));
1686 data_len = (head - tail) & rmask;
1688 if (data_len == 0) {
1689 writeb(1, &(bs->idata));
1690 spin_unlock_irqrestore(&ch->ch_lock, lock_flags2);
1691 spin_unlock_irqrestore(&bd->bd_lock, lock_flags);
1696 * If the device is not open, or CREAD is off, flush
1697 * input data and return immediately.
1699 if ((bd->state != BOARD_READY) || !tp ||
1700 (tp->magic != TTY_MAGIC) ||
1701 !(ch->ch_tun.un_flags & UN_ISOPEN) ||
1702 !(tp->termios.c_cflag & CREAD) ||
1703 (ch->ch_tun.un_flags & UN_CLOSING)) {
1705 writew(head, &(bs->rx_tail));
1706 writeb(1, &(bs->idata));
1707 spin_unlock_irqrestore(&ch->ch_lock, lock_flags2);
1708 spin_unlock_irqrestore(&bd->bd_lock, lock_flags);
1713 * If we are throttled, simply don't read any data.
1715 if (ch->ch_flags & CH_RXBLOCK) {
1716 writeb(1, &(bs->idata));
1717 spin_unlock_irqrestore(&ch->ch_lock, lock_flags2);
1718 spin_unlock_irqrestore(&bd->bd_lock, lock_flags);
1725 tmpchar = readb(&(bs->orun));
1727 ch->ch_err_overrun++;
1728 writeb(0, &(bs->orun));
1731 /* Decide how much data we can send into the tty layer */
1732 flip_len = TTY_FLIPBUF_SIZE;
1734 /* Chop down the length, if needed */
1735 len = min(data_len, flip_len);
1736 len = min(len, (N_TTY_BUF_SIZE - 1));
1738 ld = tty_ldisc_ref(tp);
1740 #ifdef TTY_DONT_FLIP
1742 * If the DONT_FLIP flag is on, don't flush our buffer, and act
1743 * like the ld doesn't have any space to put the data right now.
1745 if (test_bit(TTY_DONT_FLIP, &tp->flags))
1750 * If we were unable to get a reference to the ld,
1751 * don't flush our buffer, and act like the ld doesn't
1752 * have any space to put the data right now.
1758 * If ld doesn't have a pointer to a receive_buf function,
1759 * flush the data, then act like the ld doesn't have any
1760 * space to put the data right now.
1762 if (!ld->ops->receive_buf) {
1763 writew(head, &(bs->rx_tail));
1769 writeb(1, &(bs->idata));
1770 spin_unlock_irqrestore(&ch->ch_lock, lock_flags2);
1771 spin_unlock_irqrestore(&bd->bd_lock, lock_flags);
1773 tty_ldisc_deref(ld);
1777 buf = ch->ch_bd->flipbuf;
1781 * n now contains the most amount of data we can copy,
1782 * bounded either by our buffer size or the amount
1783 * of data the card actually has pending...
1787 s = ((head >= tail) ? head : ch->ch_rsize) - tail;
1793 memcpy_fromio(buf, ch->ch_raddr + tail, s);
1794 dgap_sniff_nowait_nolock(ch, "USER READ", buf, s);
1800 /* Flip queue if needed */
1804 writew(tail, &(bs->rx_tail));
1805 writeb(1, &(bs->idata));
1806 ch->ch_rxcount += len;
1809 * If we are completely raw, we don't need to go through a lot
1810 * of the tty layers that exist.
1811 * In this case, we take the shortest and fastest route we
1812 * can to relay the data to the user.
1814 * On the other hand, if we are not raw, we need to go through
1815 * the tty layer, which has its API more well defined.
1817 if (I_PARMRK(tp) || I_BRKINT(tp) || I_INPCK(tp)) {
1818 dgap_parity_scan(ch, ch->ch_bd->flipbuf,
1819 ch->ch_bd->flipflagbuf, &len);
1821 len = tty_buffer_request_room(tp->port, len);
1822 tty_insert_flip_string_flags(tp->port, ch->ch_bd->flipbuf,
1823 ch->ch_bd->flipflagbuf, len);
1825 len = tty_buffer_request_room(tp->port, len);
1826 tty_insert_flip_string(tp->port, ch->ch_bd->flipbuf, len);
1829 spin_unlock_irqrestore(&ch->ch_lock, lock_flags2);
1830 spin_unlock_irqrestore(&bd->bd_lock, lock_flags);
1832 /* Tell the tty layer its okay to "eat" the data now */
1833 tty_flip_buffer_push(tp->port);
1836 tty_ldisc_deref(ld);
1840 /************************************************************************
1841 * Determines when CARRIER changes state and takes appropriate
1843 ************************************************************************/
1844 static void dgap_carrier(struct channel_t *ch)
1848 int virt_carrier = 0;
1849 int phys_carrier = 0;
1851 if (!ch || ch->magic != DGAP_CHANNEL_MAGIC)
1856 if (!bd || bd->magic != DGAP_BOARD_MAGIC)
1859 /* Make sure altpin is always set correctly */
1860 if (ch->ch_digi.digi_flags & DIGI_ALTPIN) {
1864 ch->ch_dsr = DM_DSR;
1868 if (ch->ch_mistat & D_CD(ch))
1871 if (ch->ch_digi.digi_flags & DIGI_FORCEDCD)
1874 if (ch->ch_c_cflag & CLOCAL)
1878 * Test for a VIRTUAL carrier transition to HIGH.
1880 if (((ch->ch_flags & CH_FCAR) == 0) && (virt_carrier == 1)) {
1883 * When carrier rises, wake any threads waiting
1884 * for carrier in the open routine.
1887 if (waitqueue_active(&(ch->ch_flags_wait)))
1888 wake_up_interruptible(&ch->ch_flags_wait);
1892 * Test for a PHYSICAL carrier transition to HIGH.
1894 if (((ch->ch_flags & CH_CD) == 0) && (phys_carrier == 1)) {
1897 * When carrier rises, wake any threads waiting
1898 * for carrier in the open routine.
1901 if (waitqueue_active(&(ch->ch_flags_wait)))
1902 wake_up_interruptible(&ch->ch_flags_wait);
1906 * Test for a PHYSICAL transition to low, so long as we aren't
1907 * currently ignoring physical transitions (which is what "virtual
1908 * carrier" indicates).
1910 * The transition of the virtual carrier to low really doesn't
1911 * matter... it really only means "ignore carrier state", not
1912 * "make pretend that carrier is there".
1914 if ((virt_carrier == 0) &&
1915 ((ch->ch_flags & CH_CD) != 0) &&
1916 (phys_carrier == 0)) {
1919 * When carrier drops:
1921 * Drop carrier on all open units.
1923 * Flush queues, waking up any task waiting in the
1926 * Send a hangup to the control terminal.
1928 * Enable all select calls.
1930 if (waitqueue_active(&(ch->ch_flags_wait)))
1931 wake_up_interruptible(&ch->ch_flags_wait);
1933 if (ch->ch_tun.un_open_count > 0)
1934 tty_hangup(ch->ch_tun.un_tty);
1936 if (ch->ch_pun.un_open_count > 0)
1937 tty_hangup(ch->ch_pun.un_tty);
1941 * Make sure that our cached values reflect the current reality.
1943 if (virt_carrier == 1)
1944 ch->ch_flags |= CH_FCAR;
1946 ch->ch_flags &= ~CH_FCAR;
1948 if (phys_carrier == 1)
1949 ch->ch_flags |= CH_CD;
1951 ch->ch_flags &= ~CH_CD;
1954 /************************************************************************
1956 * TTY Entry points and helper functions
1958 ************************************************************************/
1964 static int dgap_tty_open(struct tty_struct *tty, struct file *file)
1966 struct board_t *brd;
1967 struct channel_t *ch;
1969 struct bs_t __iomem *bs;
1979 major = MAJOR(tty_devnum(tty));
1980 minor = MINOR(tty_devnum(tty));
1985 /* Get board pointer from our array of majors we have allocated */
1986 brd = dgap_BoardsByMajor[major];
1991 * If board is not yet up to a state of READY, go to
1992 * sleep waiting for it to happen or they cancel the open.
1994 rc = wait_event_interruptible(brd->state_wait,
1995 (brd->state & BOARD_READY));
2000 spin_lock_irqsave(&brd->bd_lock, lock_flags);
2002 /* The wait above should guarantee this cannot happen */
2003 if (brd->state != BOARD_READY) {
2004 spin_unlock_irqrestore(&brd->bd_lock, lock_flags);
2008 /* If opened device is greater than our number of ports, bail. */
2009 if (MINOR(tty_devnum(tty)) > brd->nasync) {
2010 spin_unlock_irqrestore(&brd->bd_lock, lock_flags);
2014 ch = brd->channels[minor];
2016 spin_unlock_irqrestore(&brd->bd_lock, lock_flags);
2020 /* Grab channel lock */
2021 spin_lock_irqsave(&ch->ch_lock, lock_flags2);
2023 /* Figure out our type */
2024 if (major == brd->dgap_Serial_Major) {
2025 un = &brd->channels[minor]->ch_tun;
2026 un->un_type = DGAP_SERIAL;
2027 } else if (major == brd->dgap_TransparentPrint_Major) {
2028 un = &brd->channels[minor]->ch_pun;
2029 un->un_type = DGAP_PRINT;
2031 spin_unlock_irqrestore(&ch->ch_lock, lock_flags2);
2032 spin_unlock_irqrestore(&brd->bd_lock, lock_flags);
2036 /* Store our unit into driver_data, so we always have it available. */
2037 tty->driver_data = un;
2040 * Error if channel info pointer is NULL.
2044 spin_unlock_irqrestore(&ch->ch_lock, lock_flags2);
2045 spin_unlock_irqrestore(&brd->bd_lock, lock_flags);
2052 if (!(un->un_flags & UN_ISOPEN)) {
2053 /* Store important variables. */
2056 /* Maybe do something here to the TTY struct as well? */
2060 * Initialize if neither terminal or printer is open.
2062 if (!((ch->ch_tun.un_flags | ch->ch_pun.un_flags) & UN_ISOPEN)) {
2068 * Flush input queue.
2070 head = readw(&(bs->rx_head));
2071 writew(head, &(bs->rx_tail));
2074 ch->pscan_state = 0;
2075 ch->pscan_savechar = 0;
2077 ch->ch_c_cflag = tty->termios.c_cflag;
2078 ch->ch_c_iflag = tty->termios.c_iflag;
2079 ch->ch_c_oflag = tty->termios.c_oflag;
2080 ch->ch_c_lflag = tty->termios.c_lflag;
2081 ch->ch_startc = tty->termios.c_cc[VSTART];
2082 ch->ch_stopc = tty->termios.c_cc[VSTOP];
2084 /* TODO: flush our TTY struct here? */
2089 * Run param in case we changed anything
2094 * follow protocol for opening port
2097 spin_unlock_irqrestore(&ch->ch_lock, lock_flags2);
2098 spin_unlock_irqrestore(&brd->bd_lock, lock_flags);
2100 rc = dgap_block_til_ready(tty, file, ch);
2105 /* No going back now, increment our unit and channel counters */
2106 spin_lock_irqsave(&ch->ch_lock, lock_flags);
2107 ch->ch_open_count++;
2108 un->un_open_count++;
2109 un->un_flags |= (UN_ISOPEN);
2110 spin_unlock_irqrestore(&ch->ch_lock, lock_flags);
2116 * dgap_block_til_ready()
2118 * Wait for DCD, if needed.
2120 static int dgap_block_til_ready(struct tty_struct *tty, struct file *file,
2121 struct channel_t *ch)
2124 struct un_t *un = NULL;
2127 int sleep_on_un_flags = 0;
2129 if (!tty || tty->magic != TTY_MAGIC || !file || !ch ||
2130 ch->magic != DGAP_CHANNEL_MAGIC)
2133 un = tty->driver_data;
2134 if (!un || un->magic != DGAP_UNIT_MAGIC)
2137 spin_lock_irqsave(&ch->ch_lock, lock_flags);
2144 sleep_on_un_flags = 0;
2147 * If board has failed somehow during our sleep,
2150 if (ch->ch_bd->state == BOARD_FAILED) {
2155 /* If tty was hung up, break out of loop and set error. */
2156 if (tty_hung_up_p(file)) {
2162 * If either unit is in the middle of the fragile part of close,
2163 * we just cannot touch the channel safely.
2164 * Go back to sleep, knowing that when the channel can be
2165 * touched safely, the close routine will signal the
2166 * ch_wait_flags to wake us back up.
2168 if (!((ch->ch_tun.un_flags | ch->ch_pun.un_flags) &
2172 * Our conditions to leave cleanly and happily:
2173 * 1) NONBLOCKING on the tty is set.
2175 * 3) DCD (fake or real) is active.
2178 if (file->f_flags & O_NONBLOCK)
2181 if (tty->flags & (1 << TTY_IO_ERROR))
2184 if (ch->ch_flags & CH_CD)
2187 if (ch->ch_flags & CH_FCAR)
2190 sleep_on_un_flags = 1;
2194 * If there is a signal pending, the user probably
2195 * interrupted (ctrl-c) us.
2196 * Leave loop with error set.
2198 if (signal_pending(current)) {
2199 retval = -ERESTARTSYS;
2204 * Store the flags before we let go of channel lock
2206 if (sleep_on_un_flags)
2207 old_flags = ch->ch_tun.un_flags | ch->ch_pun.un_flags;
2209 old_flags = ch->ch_flags;
2212 * Let go of channel lock before calling schedule.
2213 * Our poller will get any FEP events and wake us up when DCD
2214 * eventually goes active.
2217 spin_unlock_irqrestore(&ch->ch_lock, lock_flags);
2220 * Wait for something in the flags to change
2221 * from the current value.
2223 if (sleep_on_un_flags) {
2224 retval = wait_event_interruptible(un->un_flags_wait,
2225 (old_flags != (ch->ch_tun.un_flags |
2226 ch->ch_pun.un_flags)));
2228 retval = wait_event_interruptible(ch->ch_flags_wait,
2229 (old_flags != ch->ch_flags));
2233 * We got woken up for some reason.
2234 * Before looping around, grab our channel lock.
2236 spin_lock_irqsave(&ch->ch_lock, lock_flags);
2241 spin_unlock_irqrestore(&ch->ch_lock, lock_flags);
2252 * Hangup the port. Like a close, but don't wait for output to drain.
2254 static void dgap_tty_hangup(struct tty_struct *tty)
2257 struct channel_t *ch;
2260 if (!tty || tty->magic != TTY_MAGIC)
2263 un = tty->driver_data;
2264 if (!un || un->magic != DGAP_UNIT_MAGIC)
2268 if (!ch || ch->magic != DGAP_CHANNEL_MAGIC)
2272 if (!bd || bd->magic != DGAP_BOARD_MAGIC)
2275 /* flush the transmit queues */
2276 dgap_tty_flush_buffer(tty);
2284 static void dgap_tty_close(struct tty_struct *tty, struct file *file)
2286 struct ktermios *ts;
2288 struct channel_t *ch;
2293 if (!tty || tty->magic != TTY_MAGIC)
2296 un = tty->driver_data;
2297 if (!un || un->magic != DGAP_UNIT_MAGIC)
2301 if (!ch || ch->magic != DGAP_CHANNEL_MAGIC)
2305 if (!bd || bd->magic != DGAP_BOARD_MAGIC)
2310 spin_lock_irqsave(&ch->ch_lock, lock_flags);
2313 * Determine if this is the last close or not - and if we agree about
2314 * which type of close it is with the Line Discipline
2316 if ((tty->count == 1) && (un->un_open_count != 1)) {
2318 * Uh, oh. tty->count is 1, which means that the tty
2319 * structure will be freed. un_open_count should always
2320 * be one in these conditions. If it's greater than
2321 * one, we've got real problems, since it means the
2322 * serial port won't be shutdown.
2324 un->un_open_count = 1;
2327 if (--un->un_open_count < 0)
2328 un->un_open_count = 0;
2330 ch->ch_open_count--;
2332 if (ch->ch_open_count && un->un_open_count) {
2333 spin_unlock_irqrestore(&ch->ch_lock, lock_flags);
2337 /* OK, its the last close on the unit */
2339 un->un_flags |= UN_CLOSING;
2344 * Only officially close channel if count is 0 and
2345 * DIGI_PRINTER bit is not set.
2347 if ((ch->ch_open_count == 0) &&
2348 !(ch->ch_digi.digi_flags & DIGI_PRINTER)) {
2350 ch->ch_flags &= ~(CH_RXBLOCK);
2352 spin_unlock_irqrestore(&ch->ch_lock, lock_flags);
2354 /* wait for output to drain */
2355 /* This will also return if we take an interrupt */
2357 rc = dgap_wait_for_drain(tty);
2359 dgap_tty_flush_buffer(tty);
2360 tty_ldisc_flush(tty);
2362 spin_lock_irqsave(&ch->ch_lock, lock_flags);
2367 * If we have HUPCL set, lower DTR and RTS
2369 if (ch->ch_c_cflag & HUPCL) {
2370 ch->ch_mostat &= ~(D_RTS(ch)|D_DTR(ch));
2371 dgap_cmdb(ch, SMODEM, 0, D_DTR(ch)|D_RTS(ch), 0);
2374 * Go to sleep to ensure RTS/DTR
2375 * have been dropped for modems to see it.
2377 if (ch->ch_close_delay) {
2378 spin_unlock_irqrestore(&ch->ch_lock,
2380 dgap_ms_sleep(ch->ch_close_delay);
2381 spin_lock_irqsave(&ch->ch_lock, lock_flags);
2385 ch->pscan_state = 0;
2386 ch->pscan_savechar = 0;
2387 ch->ch_baud_info = 0;
2392 * turn off print device when closing print device.
2394 if ((un->un_type == DGAP_PRINT) && (ch->ch_flags & CH_PRON)) {
2395 dgap_wmove(ch, ch->ch_digi.digi_offstr,
2396 (int) ch->ch_digi.digi_offlen);
2397 ch->ch_flags &= ~CH_PRON;
2401 un->un_flags &= ~(UN_ISOPEN | UN_CLOSING);
2402 tty->driver_data = NULL;
2404 wake_up_interruptible(&ch->ch_flags_wait);
2405 wake_up_interruptible(&un->un_flags_wait);
2407 spin_unlock_irqrestore(&ch->ch_lock, lock_flags);
2411 * dgap_tty_chars_in_buffer()
2413 * Return number of characters that have not been transmitted yet.
2415 * This routine is used by the line discipline to determine if there
2416 * is data waiting to be transmitted/drained/flushed or not.
2418 static int dgap_tty_chars_in_buffer(struct tty_struct *tty)
2420 struct board_t *bd = NULL;
2421 struct channel_t *ch = NULL;
2422 struct un_t *un = NULL;
2423 struct bs_t __iomem *bs;
2426 u16 thead, ttail, tmask, chead, ctail;
2427 ulong lock_flags = 0;
2428 ulong lock_flags2 = 0;
2433 un = tty->driver_data;
2434 if (!un || un->magic != DGAP_UNIT_MAGIC)
2438 if (!ch || ch->magic != DGAP_CHANNEL_MAGIC)
2442 if (!bd || bd->magic != DGAP_BOARD_MAGIC)
2449 spin_lock_irqsave(&bd->bd_lock, lock_flags);
2450 spin_lock_irqsave(&ch->ch_lock, lock_flags2);
2452 tmask = (ch->ch_tsize - 1);
2454 /* Get Transmit queue pointers */
2455 thead = readw(&(bs->tx_head)) & tmask;
2456 ttail = readw(&(bs->tx_tail)) & tmask;
2458 /* Get tbusy flag */
2459 tbusy = readb(&(bs->tbusy));
2461 /* Get Command queue pointers */
2462 chead = readw(&(ch->ch_cm->cm_head));
2463 ctail = readw(&(ch->ch_cm->cm_tail));
2465 spin_unlock_irqrestore(&ch->ch_lock, lock_flags2);
2466 spin_unlock_irqrestore(&bd->bd_lock, lock_flags);
2469 * The only way we know for sure if there is no pending
2470 * data left to be transferred, is if:
2471 * 1) Transmit head and tail are equal (empty).
2472 * 2) Command queue head and tail are equal (empty).
2473 * 3) The "TBUSY" flag is 0. (Transmitter not busy).
2476 if ((ttail == thead) && (tbusy == 0) && (chead == ctail)) {
2480 chars = thead - ttail;
2482 chars = thead - ttail + ch->ch_tsize;
2484 * Fudge factor here.
2485 * If chars is zero, we know that the command queue had
2486 * something in it or tbusy was set. Because we cannot
2487 * be sure if there is still some data to be transmitted,
2488 * lets lie, and tell ld we have 1 byte left.
2492 * If TBUSY is still set, and our tx buffers are empty,
2493 * force the firmware to send me another wakeup after
2494 * TBUSY has been cleared.
2497 spin_lock_irqsave(&ch->ch_lock, lock_flags);
2498 un->un_flags |= UN_EMPTY;
2499 writeb(1, &(bs->iempty));
2500 spin_unlock_irqrestore(&ch->ch_lock,
2510 static int dgap_wait_for_drain(struct tty_struct *tty)
2512 struct channel_t *ch;
2514 struct bs_t __iomem *bs;
2517 ulong lock_flags = 0;
2519 if (!tty || tty->magic != TTY_MAGIC)
2522 un = tty->driver_data;
2523 if (!un || un->magic != DGAP_UNIT_MAGIC)
2527 if (!ch || ch->magic != DGAP_CHANNEL_MAGIC)
2536 /* Loop until data is drained */
2537 while (count != 0) {
2539 count = dgap_tty_chars_in_buffer(tty);
2544 /* Set flag waiting for drain */
2545 spin_lock_irqsave(&ch->ch_lock, lock_flags);
2546 un->un_flags |= UN_EMPTY;
2547 writeb(1, &(bs->iempty));
2548 spin_unlock_irqrestore(&ch->ch_lock, lock_flags);
2550 /* Go to sleep till we get woken up */
2551 ret = wait_event_interruptible(un->un_flags_wait,
2552 ((un->un_flags & UN_EMPTY) == 0));
2553 /* If ret is non-zero, user ctrl-c'ed us */
2558 spin_lock_irqsave(&ch->ch_lock, lock_flags);
2559 un->un_flags &= ~(UN_EMPTY);
2560 spin_unlock_irqrestore(&ch->ch_lock, lock_flags);
2568 * Reduces bytes_available to the max number of characters
2569 * that can be sent currently given the maxcps value, and
2570 * returns the new bytes_available. This only affects printer
2573 static int dgap_maxcps_room(struct tty_struct *tty, int bytes_available)
2575 struct channel_t *ch = NULL;
2576 struct un_t *un = NULL;
2579 return bytes_available;
2581 un = tty->driver_data;
2582 if (!un || un->magic != DGAP_UNIT_MAGIC)
2583 return bytes_available;
2586 if (!ch || ch->magic != DGAP_CHANNEL_MAGIC)
2587 return bytes_available;
2590 * If its not the Transparent print device, return
2591 * the full data amount.
2593 if (un->un_type != DGAP_PRINT)
2594 return bytes_available;
2596 if (ch->ch_digi.digi_maxcps > 0 && ch->ch_digi.digi_bufsize > 0) {
2598 unsigned long current_time = jiffies;
2599 unsigned long buffer_time = current_time +
2600 (HZ * ch->ch_digi.digi_bufsize) /
2601 ch->ch_digi.digi_maxcps;
2603 if (ch->ch_cpstime < current_time) {
2604 /* buffer is empty */
2605 ch->ch_cpstime = current_time; /* reset ch_cpstime */
2606 cps_limit = ch->ch_digi.digi_bufsize;
2607 } else if (ch->ch_cpstime < buffer_time) {
2608 /* still room in the buffer */
2609 cps_limit = ((buffer_time - ch->ch_cpstime) *
2610 ch->ch_digi.digi_maxcps) / HZ;
2612 /* no room in the buffer */
2616 bytes_available = min(cps_limit, bytes_available);
2619 return bytes_available;
2622 static inline void dgap_set_firmware_event(struct un_t *un, unsigned int event)
2624 struct channel_t *ch = NULL;
2625 struct bs_t __iomem *bs = NULL;
2627 if (!un || un->magic != DGAP_UNIT_MAGIC)
2630 if (!ch || ch->magic != DGAP_CHANNEL_MAGIC)
2636 if ((event & UN_LOW) != 0) {
2637 if ((un->un_flags & UN_LOW) == 0) {
2638 un->un_flags |= UN_LOW;
2639 writeb(1, &(bs->ilow));
2642 if ((event & UN_LOW) != 0) {
2643 if ((un->un_flags & UN_EMPTY) == 0) {
2644 un->un_flags |= UN_EMPTY;
2645 writeb(1, &(bs->iempty));
2651 * dgap_tty_write_room()
2653 * Return space available in Tx buffer
2655 static int dgap_tty_write_room(struct tty_struct *tty)
2657 struct channel_t *ch = NULL;
2658 struct un_t *un = NULL;
2659 struct bs_t __iomem *bs;
2660 u16 head, tail, tmask;
2662 ulong lock_flags = 0;
2667 un = tty->driver_data;
2668 if (!un || un->magic != DGAP_UNIT_MAGIC)
2672 if (!ch || ch->magic != DGAP_CHANNEL_MAGIC)
2679 spin_lock_irqsave(&ch->ch_lock, lock_flags);
2681 tmask = ch->ch_tsize - 1;
2682 head = readw(&(bs->tx_head)) & tmask;
2683 tail = readw(&(bs->tx_tail)) & tmask;
2685 ret = tail - head - 1;
2687 ret += ch->ch_tsize;
2689 /* Limit printer to maxcps */
2690 ret = dgap_maxcps_room(tty, ret);
2693 * If we are printer device, leave space for
2694 * possibly both the on and off strings.
2696 if (un->un_type == DGAP_PRINT) {
2697 if (!(ch->ch_flags & CH_PRON))
2698 ret -= ch->ch_digi.digi_onlen;
2699 ret -= ch->ch_digi.digi_offlen;
2701 if (ch->ch_flags & CH_PRON)
2702 ret -= ch->ch_digi.digi_offlen;
2709 * Schedule FEP to wake us up if needed.
2711 * TODO: This might be overkill...
2712 * Do we really need to schedule callbacks from the FEP
2713 * in every case? Can we get smarter based on ret?
2715 dgap_set_firmware_event(un, UN_LOW | UN_EMPTY);
2716 spin_unlock_irqrestore(&ch->ch_lock, lock_flags);
2722 * dgap_tty_put_char()
2724 * Put a character into ch->ch_buf
2726 * - used by the line discipline for OPOST processing
2728 static int dgap_tty_put_char(struct tty_struct *tty, unsigned char c)
2731 * Simply call tty_write.
2733 dgap_tty_write(tty, &c, 1);
2740 * Take data from the user or kernel and send it out to the FEP.
2741 * In here exists all the Transparent Print magic as well.
2743 static int dgap_tty_write(struct tty_struct *tty, const unsigned char *buf,
2746 struct channel_t *ch = NULL;
2747 struct un_t *un = NULL;
2748 struct bs_t __iomem *bs;
2749 char __iomem *vaddr;
2750 u16 head, tail, tmask, remain;
2751 int bufcount = 0, n = 0;
2758 un = tty->driver_data;
2759 if (!un || un->magic != DGAP_UNIT_MAGIC)
2763 if (!ch || ch->magic != DGAP_CHANNEL_MAGIC)
2774 * Store original amount of characters passed in.
2775 * This helps to figure out if we should ask the FEP
2776 * to send us an event when it has more space available.
2780 spin_lock_irqsave(&ch->ch_lock, lock_flags);
2782 /* Get our space available for the channel from the board */
2783 tmask = ch->ch_tsize - 1;
2784 head = readw(&(bs->tx_head)) & tmask;
2785 tail = readw(&(bs->tx_tail)) & tmask;
2787 bufcount = tail - head - 1;
2789 bufcount += ch->ch_tsize;
2792 * Limit printer output to maxcps overall, with bursts allowed
2793 * up to bufsize characters.
2795 bufcount = dgap_maxcps_room(tty, bufcount);
2798 * Take minimum of what the user wants to send, and the
2799 * space available in the FEP buffer.
2801 count = min(count, bufcount);
2804 * Bail if no space left.
2807 dgap_set_firmware_event(un, UN_LOW | UN_EMPTY);
2808 spin_unlock_irqrestore(&ch->ch_lock, lock_flags);
2813 * Output the printer ON string, if we are in terminal mode, but
2814 * need to be in printer mode.
2816 if ((un->un_type == DGAP_PRINT) && !(ch->ch_flags & CH_PRON)) {
2817 dgap_wmove(ch, ch->ch_digi.digi_onstr,
2818 (int) ch->ch_digi.digi_onlen);
2819 head = readw(&(bs->tx_head)) & tmask;
2820 ch->ch_flags |= CH_PRON;
2824 * On the other hand, output the printer OFF string, if we are
2825 * currently in printer mode, but need to output to the terminal.
2827 if ((un->un_type != DGAP_PRINT) && (ch->ch_flags & CH_PRON)) {
2828 dgap_wmove(ch, ch->ch_digi.digi_offstr,
2829 (int) ch->ch_digi.digi_offlen);
2830 head = readw(&(bs->tx_head)) & tmask;
2831 ch->ch_flags &= ~CH_PRON;
2835 * If there is nothing left to copy, or
2836 * I can't handle any more data, leave.
2839 dgap_set_firmware_event(un, UN_LOW | UN_EMPTY);
2840 spin_unlock_irqrestore(&ch->ch_lock, lock_flags);
2847 * If the write wraps over the top of the circular buffer,
2848 * move the portion up to the wrap point, and reset the
2849 * pointers to the bottom.
2851 remain = ch->ch_tstart + ch->ch_tsize - head;
2855 vaddr = ch->ch_taddr + head;
2857 memcpy_toio(vaddr, (u8 *) buf, remain);
2858 dgap_sniff_nowait_nolock(ch, "USER WRITE", (u8 *) buf,
2861 head = ch->ch_tstart;
2868 * Move rest of data.
2870 vaddr = ch->ch_taddr + head;
2873 memcpy_toio(vaddr, (u8 *) buf, remain);
2874 dgap_sniff_nowait_nolock(ch, "USER WRITE", (u8 *)buf,
2882 ch->ch_txcount += count;
2884 writew(head, &(bs->tx_head));
2887 dgap_set_firmware_event(un, UN_LOW | UN_EMPTY);
2890 * If this is the print device, and the
2891 * printer is still on, we need to turn it
2892 * off before going idle. If the buffer is
2893 * non-empty, wait until it goes empty.
2894 * Otherwise turn it off right now.
2896 if ((un->un_type == DGAP_PRINT) && (ch->ch_flags & CH_PRON)) {
2897 tail = readw(&(bs->tx_tail)) & tmask;
2900 un->un_flags |= UN_EMPTY;
2901 writeb(1, &(bs->iempty));
2903 dgap_wmove(ch, ch->ch_digi.digi_offstr,
2904 (int) ch->ch_digi.digi_offlen);
2905 head = readw(&(bs->tx_head)) & tmask;
2906 ch->ch_flags &= ~CH_PRON;
2910 /* Update printer buffer empty time. */
2911 if ((un->un_type == DGAP_PRINT) && (ch->ch_digi.digi_maxcps > 0)
2912 && (ch->ch_digi.digi_bufsize > 0)) {
2913 ch->ch_cpstime += (HZ * count) / ch->ch_digi.digi_maxcps;
2916 spin_unlock_irqrestore(&ch->ch_lock, lock_flags);
2922 * Return modem signals to ld.
2924 static int dgap_tty_tiocmget(struct tty_struct *tty)
2926 struct channel_t *ch;
2932 if (!tty || tty->magic != TTY_MAGIC)
2935 un = tty->driver_data;
2936 if (!un || un->magic != DGAP_UNIT_MAGIC)
2940 if (!ch || ch->magic != DGAP_CHANNEL_MAGIC)
2943 spin_lock_irqsave(&ch->ch_lock, lock_flags);
2945 mstat = readb(&(ch->ch_bs->m_stat));
2946 /* Append any outbound signals that might be pending... */
2947 mstat |= ch->ch_mostat;
2949 spin_unlock_irqrestore(&ch->ch_lock, lock_flags);
2953 if (mstat & D_DTR(ch))
2954 result |= TIOCM_DTR;
2955 if (mstat & D_RTS(ch))
2956 result |= TIOCM_RTS;
2957 if (mstat & D_CTS(ch))
2958 result |= TIOCM_CTS;
2959 if (mstat & D_DSR(ch))
2960 result |= TIOCM_DSR;
2961 if (mstat & D_RI(ch))
2963 if (mstat & D_CD(ch))
2970 * dgap_tty_tiocmset()
2972 * Set modem signals, called by ld.
2974 static int dgap_tty_tiocmset(struct tty_struct *tty,
2975 unsigned int set, unsigned int clear)
2978 struct channel_t *ch;
2984 if (!tty || tty->magic != TTY_MAGIC)
2987 un = tty->driver_data;
2988 if (!un || un->magic != DGAP_UNIT_MAGIC)
2992 if (!ch || ch->magic != DGAP_CHANNEL_MAGIC)
2996 if (!bd || bd->magic != DGAP_BOARD_MAGIC)
2999 spin_lock_irqsave(&bd->bd_lock, lock_flags);
3000 spin_lock_irqsave(&ch->ch_lock, lock_flags2);
3002 if (set & TIOCM_RTS) {
3003 ch->ch_mforce |= D_RTS(ch);
3004 ch->ch_mval |= D_RTS(ch);
3007 if (set & TIOCM_DTR) {
3008 ch->ch_mforce |= D_DTR(ch);
3009 ch->ch_mval |= D_DTR(ch);
3012 if (clear & TIOCM_RTS) {
3013 ch->ch_mforce |= D_RTS(ch);
3014 ch->ch_mval &= ~(D_RTS(ch));
3017 if (clear & TIOCM_DTR) {
3018 ch->ch_mforce |= D_DTR(ch);
3019 ch->ch_mval &= ~(D_DTR(ch));
3024 spin_unlock_irqrestore(&ch->ch_lock, lock_flags2);
3025 spin_unlock_irqrestore(&bd->bd_lock, lock_flags);
3031 * dgap_tty_send_break()
3033 * Send a Break, called by ld.
3035 static int dgap_tty_send_break(struct tty_struct *tty, int msec)
3038 struct channel_t *ch;
3044 if (!tty || tty->magic != TTY_MAGIC)
3047 un = tty->driver_data;
3048 if (!un || un->magic != DGAP_UNIT_MAGIC)
3052 if (!ch || ch->magic != DGAP_CHANNEL_MAGIC)
3056 if (!bd || bd->magic != DGAP_BOARD_MAGIC)
3071 spin_lock_irqsave(&bd->bd_lock, lock_flags);
3072 spin_lock_irqsave(&ch->ch_lock, lock_flags2);
3074 dgap_cmdw(ch, SBREAK, (u16) SBREAK_TIME, 0);
3076 dgap_cmdw(ch, SBREAK, (u16) msec, 0);
3078 spin_unlock_irqrestore(&ch->ch_lock, lock_flags2);
3079 spin_unlock_irqrestore(&bd->bd_lock, lock_flags);
3085 * dgap_tty_wait_until_sent()
3087 * wait until data has been transmitted, called by ld.
3089 static void dgap_tty_wait_until_sent(struct tty_struct *tty, int timeout)
3091 dgap_wait_for_drain(tty);
3097 * send a high priority character, called by ld.
3099 static void dgap_tty_send_xchar(struct tty_struct *tty, char c)
3102 struct channel_t *ch;
3107 if (!tty || tty->magic != TTY_MAGIC)
3110 un = tty->driver_data;
3111 if (!un || un->magic != DGAP_UNIT_MAGIC)
3115 if (!ch || ch->magic != DGAP_CHANNEL_MAGIC)
3119 if (!bd || bd->magic != DGAP_BOARD_MAGIC)
3122 spin_lock_irqsave(&bd->bd_lock, lock_flags);
3123 spin_lock_irqsave(&ch->ch_lock, lock_flags2);
3126 * This is technically what we should do.
3127 * However, the NIST tests specifically want
3128 * to see each XON or XOFF character that it
3129 * sends, so lets just send each character
3133 if (c == STOP_CHAR(tty))
3134 dgap_cmdw(ch, RPAUSE, 0, 0);
3135 else if (c == START_CHAR(tty))
3136 dgap_cmdw(ch, RRESUME, 0, 0);
3138 dgap_wmove(ch, &c, 1);
3140 dgap_wmove(ch, &c, 1);
3143 spin_unlock_irqrestore(&ch->ch_lock, lock_flags2);
3144 spin_unlock_irqrestore(&bd->bd_lock, lock_flags);
3150 * Return modem signals to ld.
3152 static int dgap_get_modem_info(struct channel_t *ch, unsigned int __user *value)
3159 if (!ch || ch->magic != DGAP_CHANNEL_MAGIC)
3162 spin_lock_irqsave(&ch->ch_lock, lock_flags);
3164 mstat = readb(&(ch->ch_bs->m_stat));
3165 /* Append any outbound signals that might be pending... */
3166 mstat |= ch->ch_mostat;
3168 spin_unlock_irqrestore(&ch->ch_lock, lock_flags);
3172 if (mstat & D_DTR(ch))
3173 result |= TIOCM_DTR;
3174 if (mstat & D_RTS(ch))
3175 result |= TIOCM_RTS;
3176 if (mstat & D_CTS(ch))
3177 result |= TIOCM_CTS;
3178 if (mstat & D_DSR(ch))
3179 result |= TIOCM_DSR;
3180 if (mstat & D_RI(ch))
3182 if (mstat & D_CD(ch))
3185 rc = put_user(result, value);
3191 * dgap_set_modem_info()
3193 * Set modem signals, called by ld.
3195 static int dgap_set_modem_info(struct tty_struct *tty, unsigned int command,
3196 unsigned int __user *value)
3199 struct channel_t *ch;
3202 unsigned int arg = 0;
3206 if (!tty || tty->magic != TTY_MAGIC)
3209 un = tty->driver_data;
3210 if (!un || un->magic != DGAP_UNIT_MAGIC)
3214 if (!ch || ch->magic != DGAP_CHANNEL_MAGIC)
3218 if (!bd || bd->magic != DGAP_BOARD_MAGIC)
3221 ret = get_user(arg, value);
3227 if (arg & TIOCM_RTS) {
3228 ch->ch_mforce |= D_RTS(ch);
3229 ch->ch_mval |= D_RTS(ch);
3232 if (arg & TIOCM_DTR) {
3233 ch->ch_mforce |= D_DTR(ch);
3234 ch->ch_mval |= D_DTR(ch);
3240 if (arg & TIOCM_RTS) {
3241 ch->ch_mforce |= D_RTS(ch);
3242 ch->ch_mval &= ~(D_RTS(ch));
3245 if (arg & TIOCM_DTR) {
3246 ch->ch_mforce |= D_DTR(ch);
3247 ch->ch_mval &= ~(D_DTR(ch));
3253 ch->ch_mforce = D_DTR(ch)|D_RTS(ch);
3255 if (arg & TIOCM_RTS)
3256 ch->ch_mval |= D_RTS(ch);
3258 ch->ch_mval &= ~(D_RTS(ch));
3260 if (arg & TIOCM_DTR)
3261 ch->ch_mval |= (D_DTR(ch));
3263 ch->ch_mval &= ~(D_DTR(ch));
3271 spin_lock_irqsave(&bd->bd_lock, lock_flags);
3272 spin_lock_irqsave(&ch->ch_lock, lock_flags2);
3276 spin_unlock_irqrestore(&ch->ch_lock, lock_flags2);
3277 spin_unlock_irqrestore(&bd->bd_lock, lock_flags);
3283 * dgap_tty_digigeta()
3285 * Ioctl to get the information for ditty.
3290 static int dgap_tty_digigeta(struct tty_struct *tty,
3291 struct digi_t __user *retinfo)
3293 struct channel_t *ch;
3301 if (!tty || tty->magic != TTY_MAGIC)
3304 un = tty->driver_data;
3305 if (!un || un->magic != DGAP_UNIT_MAGIC)
3309 if (!ch || ch->magic != DGAP_CHANNEL_MAGIC)
3312 memset(&tmp, 0, sizeof(tmp));
3314 spin_lock_irqsave(&ch->ch_lock, lock_flags);
3315 memcpy(&tmp, &ch->ch_digi, sizeof(tmp));
3316 spin_unlock_irqrestore(&ch->ch_lock, lock_flags);
3318 if (copy_to_user(retinfo, &tmp, sizeof(*retinfo)))
3325 * dgap_tty_digiseta()
3327 * Ioctl to set the information for ditty.
3332 static int dgap_tty_digiseta(struct tty_struct *tty,
3333 struct digi_t __user *new_info)
3336 struct channel_t *ch;
3338 struct digi_t new_digi;
3339 ulong lock_flags = 0;
3340 unsigned long lock_flags2;
3342 if (!tty || tty->magic != TTY_MAGIC)
3345 un = tty->driver_data;
3346 if (!un || un->magic != DGAP_UNIT_MAGIC)
3350 if (!ch || ch->magic != DGAP_CHANNEL_MAGIC)
3354 if (!bd || bd->magic != DGAP_BOARD_MAGIC)
3357 if (copy_from_user(&new_digi, new_info, sizeof(struct digi_t)))
3360 spin_lock_irqsave(&bd->bd_lock, lock_flags);
3361 spin_lock_irqsave(&ch->ch_lock, lock_flags2);
3363 memcpy(&ch->ch_digi, &new_digi, sizeof(struct digi_t));
3365 if (ch->ch_digi.digi_maxcps < 1)
3366 ch->ch_digi.digi_maxcps = 1;
3368 if (ch->ch_digi.digi_maxcps > 10000)
3369 ch->ch_digi.digi_maxcps = 10000;
3371 if (ch->ch_digi.digi_bufsize < 10)
3372 ch->ch_digi.digi_bufsize = 10;
3374 if (ch->ch_digi.digi_maxchar < 1)
3375 ch->ch_digi.digi_maxchar = 1;
3377 if (ch->ch_digi.digi_maxchar > ch->ch_digi.digi_bufsize)
3378 ch->ch_digi.digi_maxchar = ch->ch_digi.digi_bufsize;
3380 if (ch->ch_digi.digi_onlen > DIGI_PLEN)
3381 ch->ch_digi.digi_onlen = DIGI_PLEN;
3383 if (ch->ch_digi.digi_offlen > DIGI_PLEN)
3384 ch->ch_digi.digi_offlen = DIGI_PLEN;
3388 spin_unlock_irqrestore(&ch->ch_lock, lock_flags2);
3389 spin_unlock_irqrestore(&bd->bd_lock, lock_flags);
3395 * dgap_tty_digigetedelay()
3397 * Ioctl to get the current edelay setting.
3402 static int dgap_tty_digigetedelay(struct tty_struct *tty, int __user *retinfo)
3404 struct channel_t *ch;
3412 if (!tty || tty->magic != TTY_MAGIC)
3415 un = tty->driver_data;
3416 if (!un || un->magic != DGAP_UNIT_MAGIC)
3420 if (!ch || ch->magic != DGAP_CHANNEL_MAGIC)
3423 memset(&tmp, 0, sizeof(tmp));
3425 spin_lock_irqsave(&ch->ch_lock, lock_flags);
3426 tmp = readw(&(ch->ch_bs->edelay));
3427 spin_unlock_irqrestore(&ch->ch_lock, lock_flags);
3429 if (copy_to_user(retinfo, &tmp, sizeof(*retinfo)))
3436 * dgap_tty_digisetedelay()
3438 * Ioctl to set the EDELAY setting
3441 static int dgap_tty_digisetedelay(struct tty_struct *tty, int __user *new_info)
3444 struct channel_t *ch;
3450 if (!tty || tty->magic != TTY_MAGIC)
3453 un = tty->driver_data;
3454 if (!un || un->magic != DGAP_UNIT_MAGIC)
3458 if (!ch || ch->magic != DGAP_CHANNEL_MAGIC)
3462 if (!bd || bd->magic != DGAP_BOARD_MAGIC)
3465 if (copy_from_user(&new_digi, new_info, sizeof(int)))
3468 spin_lock_irqsave(&bd->bd_lock, lock_flags);
3469 spin_lock_irqsave(&ch->ch_lock, lock_flags2);
3471 writew((u16) new_digi, &(ch->ch_bs->edelay));
3475 spin_unlock_irqrestore(&ch->ch_lock, lock_flags2);
3476 spin_unlock_irqrestore(&bd->bd_lock, lock_flags);
3482 * dgap_tty_digigetcustombaud()
3484 * Ioctl to get the current custom baud rate setting.
3486 static int dgap_tty_digigetcustombaud(struct tty_struct *tty,
3487 int __user *retinfo)
3489 struct channel_t *ch;
3497 if (!tty || tty->magic != TTY_MAGIC)
3500 un = tty->driver_data;
3501 if (!un || un->magic != DGAP_UNIT_MAGIC)
3505 if (!ch || ch->magic != DGAP_CHANNEL_MAGIC)
3508 memset(&tmp, 0, sizeof(tmp));
3510 spin_lock_irqsave(&ch->ch_lock, lock_flags);
3511 tmp = dgap_get_custom_baud(ch);
3512 spin_unlock_irqrestore(&ch->ch_lock, lock_flags);
3514 if (copy_to_user(retinfo, &tmp, sizeof(*retinfo)))
3521 * dgap_tty_digisetcustombaud()
3523 * Ioctl to set the custom baud rate setting
3525 static int dgap_tty_digisetcustombaud(struct tty_struct *tty,
3526 int __user *new_info)
3529 struct channel_t *ch;
3535 if (!tty || tty->magic != TTY_MAGIC)
3538 un = tty->driver_data;
3539 if (!un || un->magic != DGAP_UNIT_MAGIC)
3543 if (!ch || ch->magic != DGAP_CHANNEL_MAGIC)
3547 if (!bd || bd->magic != DGAP_BOARD_MAGIC)
3551 if (copy_from_user(&new_rate, new_info, sizeof(unsigned int)))
3554 if (bd->bd_flags & BD_FEP5PLUS) {
3556 spin_lock_irqsave(&bd->bd_lock, lock_flags);
3557 spin_lock_irqsave(&ch->ch_lock, lock_flags2);
3559 ch->ch_custom_speed = new_rate;
3563 spin_unlock_irqrestore(&ch->ch_lock, lock_flags2);
3564 spin_unlock_irqrestore(&bd->bd_lock, lock_flags);
3571 * dgap_set_termios()
3573 static void dgap_tty_set_termios(struct tty_struct *tty,
3574 struct ktermios *old_termios)
3577 struct channel_t *ch;
3579 unsigned long lock_flags;
3580 unsigned long lock_flags2;
3582 if (!tty || tty->magic != TTY_MAGIC)
3585 un = tty->driver_data;
3586 if (!un || un->magic != DGAP_UNIT_MAGIC)
3590 if (!ch || ch->magic != DGAP_CHANNEL_MAGIC)
3594 if (!bd || bd->magic != DGAP_BOARD_MAGIC)
3597 spin_lock_irqsave(&bd->bd_lock, lock_flags);
3598 spin_lock_irqsave(&ch->ch_lock, lock_flags2);
3600 ch->ch_c_cflag = tty->termios.c_cflag;
3601 ch->ch_c_iflag = tty->termios.c_iflag;
3602 ch->ch_c_oflag = tty->termios.c_oflag;
3603 ch->ch_c_lflag = tty->termios.c_lflag;
3604 ch->ch_startc = tty->termios.c_cc[VSTART];
3605 ch->ch_stopc = tty->termios.c_cc[VSTOP];
3610 spin_unlock_irqrestore(&ch->ch_lock, lock_flags2);
3611 spin_unlock_irqrestore(&bd->bd_lock, lock_flags);
3614 static void dgap_tty_throttle(struct tty_struct *tty)
3617 struct channel_t *ch;
3622 if (!tty || tty->magic != TTY_MAGIC)
3625 un = tty->driver_data;
3626 if (!un || un->magic != DGAP_UNIT_MAGIC)
3630 if (!ch || ch->magic != DGAP_CHANNEL_MAGIC)
3634 if (!bd || bd->magic != DGAP_BOARD_MAGIC)
3637 spin_lock_irqsave(&bd->bd_lock, lock_flags);
3638 spin_lock_irqsave(&ch->ch_lock, lock_flags2);
3640 ch->ch_flags |= (CH_RXBLOCK);
3642 dgap_cmdw(ch, RPAUSE, 0, 0);
3645 spin_unlock_irqrestore(&ch->ch_lock, lock_flags2);
3646 spin_unlock_irqrestore(&bd->bd_lock, lock_flags);
3650 static void dgap_tty_unthrottle(struct tty_struct *tty)
3653 struct channel_t *ch;
3658 if (!tty || tty->magic != TTY_MAGIC)
3661 un = tty->driver_data;
3662 if (!un || un->magic != DGAP_UNIT_MAGIC)
3666 if (!ch || ch->magic != DGAP_CHANNEL_MAGIC)
3670 if (!bd || bd->magic != DGAP_BOARD_MAGIC)
3673 spin_lock_irqsave(&bd->bd_lock, lock_flags);
3674 spin_lock_irqsave(&ch->ch_lock, lock_flags2);
3676 ch->ch_flags &= ~(CH_RXBLOCK);
3679 dgap_cmdw(ch, RRESUME, 0, 0);
3682 spin_unlock_irqrestore(&ch->ch_lock, lock_flags2);
3683 spin_unlock_irqrestore(&bd->bd_lock, lock_flags);
3686 static void dgap_tty_start(struct tty_struct *tty)
3689 struct channel_t *ch;
3694 if (!tty || tty->magic != TTY_MAGIC)
3697 un = tty->driver_data;
3698 if (!un || un->magic != DGAP_UNIT_MAGIC)
3702 if (!ch || ch->magic != DGAP_CHANNEL_MAGIC)
3706 if (!bd || bd->magic != DGAP_BOARD_MAGIC)
3709 spin_lock_irqsave(&bd->bd_lock, lock_flags);
3710 spin_lock_irqsave(&ch->ch_lock, lock_flags2);
3712 dgap_cmdw(ch, RESUMETX, 0, 0);
3714 spin_unlock_irqrestore(&ch->ch_lock, lock_flags2);
3715 spin_unlock_irqrestore(&bd->bd_lock, lock_flags);
3719 static void dgap_tty_stop(struct tty_struct *tty)
3722 struct channel_t *ch;
3727 if (!tty || tty->magic != TTY_MAGIC)
3730 un = tty->driver_data;
3731 if (!un || un->magic != DGAP_UNIT_MAGIC)
3735 if (!ch || ch->magic != DGAP_CHANNEL_MAGIC)
3739 if (!bd || bd->magic != DGAP_BOARD_MAGIC)
3742 spin_lock_irqsave(&bd->bd_lock, lock_flags);
3743 spin_lock_irqsave(&ch->ch_lock, lock_flags2);
3745 dgap_cmdw(ch, PAUSETX, 0, 0);
3747 spin_unlock_irqrestore(&ch->ch_lock, lock_flags2);
3748 spin_unlock_irqrestore(&bd->bd_lock, lock_flags);
3753 * dgap_tty_flush_chars()
3755 * Flush the cook buffer
3757 * Note to self, and any other poor souls who venture here:
3759 * flush in this case DOES NOT mean dispose of the data.
3760 * instead, it means "stop buffering and send it if you
3761 * haven't already." Just guess how I figured that out... SRW 2-Jun-98
3763 * It is also always called in interrupt context - JAR 8-Sept-99
3765 static void dgap_tty_flush_chars(struct tty_struct *tty)
3768 struct channel_t *ch;
3773 if (!tty || tty->magic != TTY_MAGIC)
3776 un = tty->driver_data;
3777 if (!un || un->magic != DGAP_UNIT_MAGIC)
3781 if (!ch || ch->magic != DGAP_CHANNEL_MAGIC)
3785 if (!bd || bd->magic != DGAP_BOARD_MAGIC)
3788 spin_lock_irqsave(&bd->bd_lock, lock_flags);
3789 spin_lock_irqsave(&ch->ch_lock, lock_flags2);
3791 /* TODO: Do something here */
3793 spin_unlock_irqrestore(&ch->ch_lock, lock_flags2);
3794 spin_unlock_irqrestore(&bd->bd_lock, lock_flags);
3798 * dgap_tty_flush_buffer()
3800 * Flush Tx buffer (make in == out)
3802 static void dgap_tty_flush_buffer(struct tty_struct *tty)
3805 struct channel_t *ch;
3811 if (!tty || tty->magic != TTY_MAGIC)
3814 un = tty->driver_data;
3815 if (!un || un->magic != DGAP_UNIT_MAGIC)
3819 if (!ch || ch->magic != DGAP_CHANNEL_MAGIC)
3823 if (!bd || bd->magic != DGAP_BOARD_MAGIC)
3826 spin_lock_irqsave(&bd->bd_lock, lock_flags);
3827 spin_lock_irqsave(&ch->ch_lock, lock_flags2);
3829 ch->ch_flags &= ~CH_STOP;
3830 head = readw(&(ch->ch_bs->tx_head));
3831 dgap_cmdw(ch, FLUSHTX, (u16) head, 0);
3832 dgap_cmdw(ch, RESUMETX, 0, 0);
3833 if (ch->ch_tun.un_flags & (UN_LOW|UN_EMPTY)) {
3834 ch->ch_tun.un_flags &= ~(UN_LOW|UN_EMPTY);
3835 wake_up_interruptible(&ch->ch_tun.un_flags_wait);
3837 if (ch->ch_pun.un_flags & (UN_LOW|UN_EMPTY)) {
3838 ch->ch_pun.un_flags &= ~(UN_LOW|UN_EMPTY);
3839 wake_up_interruptible(&ch->ch_pun.un_flags_wait);
3842 spin_unlock_irqrestore(&ch->ch_lock, lock_flags2);
3843 spin_unlock_irqrestore(&bd->bd_lock, lock_flags);
3844 if (waitqueue_active(&tty->write_wait))
3845 wake_up_interruptible(&tty->write_wait);
3849 /*****************************************************************************
3851 * The IOCTL function and all of its helpers
3853 *****************************************************************************/
3858 * The usual assortment of ioctl's
3860 static int dgap_tty_ioctl(struct tty_struct *tty, unsigned int cmd,
3864 struct channel_t *ch;
3868 ulong lock_flags = 0;
3869 ulong lock_flags2 = 0;
3870 void __user *uarg = (void __user *) arg;
3872 if (!tty || tty->magic != TTY_MAGIC)
3875 un = tty->driver_data;
3876 if (!un || un->magic != DGAP_UNIT_MAGIC)
3880 if (!ch || ch->magic != DGAP_CHANNEL_MAGIC)
3884 if (!bd || bd->magic != DGAP_BOARD_MAGIC)
3887 spin_lock_irqsave(&bd->bd_lock, lock_flags);
3888 spin_lock_irqsave(&ch->ch_lock, lock_flags2);
3890 if (un->un_open_count <= 0) {
3891 spin_unlock_irqrestore(&ch->ch_lock, lock_flags2);
3892 spin_unlock_irqrestore(&bd->bd_lock, lock_flags);
3898 /* Here are all the standard ioctl's that we MUST implement */
3902 * TCSBRK is SVID version: non-zero arg --> no break
3903 * this behaviour is exploited by tcdrain().
3905 * According to POSIX.1 spec (7.2.2.1.2) breaks should be
3906 * between 0.25 and 0.5 seconds so we'll ask for something
3907 * in the middle: 0.375 seconds.
3909 rc = tty_check_change(tty);
3910 spin_unlock_irqrestore(&ch->ch_lock, lock_flags2);
3911 spin_unlock_irqrestore(&bd->bd_lock, lock_flags);
3915 rc = dgap_wait_for_drain(tty);
3920 spin_lock_irqsave(&bd->bd_lock, lock_flags);
3921 spin_lock_irqsave(&ch->ch_lock, lock_flags2);
3923 if (((cmd == TCSBRK) && (!arg)) || (cmd == TCSBRKP))
3924 dgap_cmdw(ch, SBREAK, (u16) SBREAK_TIME, 0);
3926 spin_unlock_irqrestore(&ch->ch_lock, lock_flags2);
3927 spin_unlock_irqrestore(&bd->bd_lock, lock_flags);
3932 /* support for POSIX tcsendbreak()
3934 * According to POSIX.1 spec (7.2.2.1.2) breaks should be
3935 * between 0.25 and 0.5 seconds so we'll ask for something
3936 * in the middle: 0.375 seconds.
3938 rc = tty_check_change(tty);
3939 spin_unlock_irqrestore(&ch->ch_lock, lock_flags2);
3940 spin_unlock_irqrestore(&bd->bd_lock, lock_flags);
3944 rc = dgap_wait_for_drain(tty);
3948 spin_lock_irqsave(&bd->bd_lock, lock_flags);
3949 spin_lock_irqsave(&ch->ch_lock, lock_flags2);
3951 dgap_cmdw(ch, SBREAK, (u16) SBREAK_TIME, 0);
3953 spin_unlock_irqrestore(&ch->ch_lock, lock_flags2);
3954 spin_unlock_irqrestore(&bd->bd_lock, lock_flags);
3960 * FEP5 doesn't support turning on a break unconditionally.
3961 * The FEP5 device will stop sending a break automatically
3962 * after the specified time value that was sent when turning on
3965 rc = tty_check_change(tty);
3966 spin_unlock_irqrestore(&ch->ch_lock, lock_flags2);
3967 spin_unlock_irqrestore(&bd->bd_lock, lock_flags);
3971 rc = dgap_wait_for_drain(tty);
3975 spin_lock_irqsave(&bd->bd_lock, lock_flags);
3976 spin_lock_irqsave(&ch->ch_lock, lock_flags2);
3978 dgap_cmdw(ch, SBREAK, (u16) SBREAK_TIME, 0);
3980 spin_unlock_irqrestore(&ch->ch_lock, lock_flags2);
3981 spin_unlock_irqrestore(&bd->bd_lock, lock_flags);
3987 * FEP5 doesn't support turning off a break unconditionally.
3988 * The FEP5 device will stop sending a break automatically
3989 * after the specified time value that was sent when turning on
3992 spin_unlock_irqrestore(&ch->ch_lock, lock_flags2);
3993 spin_unlock_irqrestore(&bd->bd_lock, lock_flags);
3998 spin_unlock_irqrestore(&ch->ch_lock, lock_flags2);
3999 spin_unlock_irqrestore(&bd->bd_lock, lock_flags);
4001 rc = put_user(C_CLOCAL(tty) ? 1 : 0,
4002 (unsigned long __user *) arg);
4006 spin_unlock_irqrestore(&ch->ch_lock, lock_flags2);
4007 spin_unlock_irqrestore(&bd->bd_lock, lock_flags);
4009 rc = get_user(arg, (unsigned long __user *) arg);
4013 spin_lock_irqsave(&bd->bd_lock, lock_flags);
4014 spin_lock_irqsave(&ch->ch_lock, lock_flags2);
4015 tty->termios.c_cflag = ((tty->termios.c_cflag & ~CLOCAL) |
4016 (arg ? CLOCAL : 0));
4018 spin_unlock_irqrestore(&ch->ch_lock, lock_flags2);
4019 spin_unlock_irqrestore(&bd->bd_lock, lock_flags);
4024 spin_unlock_irqrestore(&ch->ch_lock, lock_flags2);
4025 spin_unlock_irqrestore(&bd->bd_lock, lock_flags);
4026 return dgap_get_modem_info(ch, uarg);
4031 spin_unlock_irqrestore(&ch->ch_lock, lock_flags2);
4032 spin_unlock_irqrestore(&bd->bd_lock, lock_flags);
4033 return dgap_set_modem_info(tty, cmd, uarg);
4036 * Here are any additional ioctl's that we want to implement
4041 * The linux tty driver doesn't have a flush
4042 * input routine for the driver, assuming all backed
4043 * up data is in the line disc. buffers. However,
4044 * we all know that's not the case. Here, we
4045 * act on the ioctl, but then lie and say we didn't
4046 * so the line discipline will process the flush
4049 rc = tty_check_change(tty);
4051 spin_unlock_irqrestore(&ch->ch_lock, lock_flags2);
4052 spin_unlock_irqrestore(&bd->bd_lock, lock_flags);
4056 if ((arg == TCIFLUSH) || (arg == TCIOFLUSH)) {
4057 if (!(un->un_type == DGAP_PRINT)) {
4058 head = readw(&(ch->ch_bs->rx_head));
4059 writew(head, &(ch->ch_bs->rx_tail));
4060 writeb(0, &(ch->ch_bs->orun));
4064 if ((arg != TCOFLUSH) && (arg != TCIOFLUSH)) {
4065 /* pretend we didn't recognize this IOCTL */
4066 spin_unlock_irqrestore(&ch->ch_lock, lock_flags2);
4067 spin_unlock_irqrestore(&bd->bd_lock, lock_flags);
4069 return -ENOIOCTLCMD;
4072 ch->ch_flags &= ~CH_STOP;
4073 head = readw(&(ch->ch_bs->tx_head));
4074 dgap_cmdw(ch, FLUSHTX, (u16) head, 0);
4075 dgap_cmdw(ch, RESUMETX, 0, 0);
4076 if (ch->ch_tun.un_flags & (UN_LOW|UN_EMPTY)) {
4077 ch->ch_tun.un_flags &= ~(UN_LOW|UN_EMPTY);
4078 wake_up_interruptible(&ch->ch_tun.un_flags_wait);
4080 if (ch->ch_pun.un_flags & (UN_LOW|UN_EMPTY)) {
4081 ch->ch_pun.un_flags &= ~(UN_LOW|UN_EMPTY);
4082 wake_up_interruptible(&ch->ch_pun.un_flags_wait);
4084 if (waitqueue_active(&tty->write_wait))
4085 wake_up_interruptible(&tty->write_wait);
4087 /* Can't hold any locks when calling tty_wakeup! */
4088 spin_unlock_irqrestore(&ch->ch_lock, lock_flags2);
4089 spin_unlock_irqrestore(&bd->bd_lock, lock_flags);
4092 /* pretend we didn't recognize this IOCTL */
4093 return -ENOIOCTLCMD;
4098 * The linux tty driver doesn't have a flush
4099 * input routine for the driver, assuming all backed
4100 * up data is in the line disc. buffers. However,
4101 * we all know that's not the case. Here, we
4102 * act on the ioctl, but then lie and say we didn't
4103 * so the line discipline will process the flush
4106 if (cmd == TCSETSF) {
4108 ch->ch_flags &= ~CH_STOP;
4109 head = readw(&(ch->ch_bs->rx_head));
4110 writew(head, &(ch->ch_bs->rx_tail));
4113 /* now wait for all the output to drain */
4114 spin_unlock_irqrestore(&ch->ch_lock, lock_flags2);
4115 spin_unlock_irqrestore(&bd->bd_lock, lock_flags);
4116 rc = dgap_wait_for_drain(tty);
4120 /* pretend we didn't recognize this */
4121 return -ENOIOCTLCMD;
4125 spin_unlock_irqrestore(&ch->ch_lock, lock_flags2);
4126 spin_unlock_irqrestore(&bd->bd_lock, lock_flags);
4127 rc = dgap_wait_for_drain(tty);
4131 /* pretend we didn't recognize this */
4132 return -ENOIOCTLCMD;
4136 * The Linux Line Discipline (LD) would do this for us if we
4137 * let it, but we have the special firmware options to do this
4138 * the "right way" regardless of hardware or software flow
4139 * control so we'll do it outselves instead of letting the LD
4142 rc = tty_check_change(tty);
4144 spin_unlock_irqrestore(&ch->ch_lock, lock_flags2);
4145 spin_unlock_irqrestore(&bd->bd_lock, lock_flags);
4152 spin_unlock_irqrestore(&ch->ch_lock, lock_flags2);
4153 spin_unlock_irqrestore(&bd->bd_lock, lock_flags);
4154 dgap_tty_start(tty);
4157 spin_unlock_irqrestore(&ch->ch_lock, lock_flags2);
4158 spin_unlock_irqrestore(&bd->bd_lock, lock_flags);
4162 spin_unlock_irqrestore(&ch->ch_lock, lock_flags2);
4163 spin_unlock_irqrestore(&bd->bd_lock, lock_flags);
4164 /* Make the ld do it */
4165 return -ENOIOCTLCMD;
4167 spin_unlock_irqrestore(&ch->ch_lock, lock_flags2);
4168 spin_unlock_irqrestore(&bd->bd_lock, lock_flags);
4169 /* Make the ld do it */
4170 return -ENOIOCTLCMD;
4172 spin_unlock_irqrestore(&ch->ch_lock, lock_flags2);
4173 spin_unlock_irqrestore(&bd->bd_lock, lock_flags);
4178 /* get information for ditty */
4179 spin_unlock_irqrestore(&ch->ch_lock, lock_flags2);
4180 spin_unlock_irqrestore(&bd->bd_lock, lock_flags);
4181 return dgap_tty_digigeta(tty, uarg);
4186 /* set information for ditty */
4187 if (cmd == (DIGI_SETAW)) {
4189 spin_unlock_irqrestore(&ch->ch_lock, lock_flags2);
4190 spin_unlock_irqrestore(&bd->bd_lock, lock_flags);
4191 rc = dgap_wait_for_drain(tty);
4194 spin_lock_irqsave(&bd->bd_lock, lock_flags);
4195 spin_lock_irqsave(&ch->ch_lock, lock_flags2);
4197 tty_ldisc_flush(tty);
4201 spin_unlock_irqrestore(&ch->ch_lock, lock_flags2);
4202 spin_unlock_irqrestore(&bd->bd_lock, lock_flags);
4203 return dgap_tty_digiseta(tty, uarg);
4206 spin_unlock_irqrestore(&ch->ch_lock, lock_flags2);
4207 spin_unlock_irqrestore(&bd->bd_lock, lock_flags);
4208 return dgap_tty_digigetedelay(tty, uarg);
4211 spin_unlock_irqrestore(&ch->ch_lock, lock_flags2);
4212 spin_unlock_irqrestore(&bd->bd_lock, lock_flags);
4213 return dgap_tty_digisetedelay(tty, uarg);
4215 case DIGI_GETCUSTOMBAUD:
4216 spin_unlock_irqrestore(&ch->ch_lock, lock_flags2);
4217 spin_unlock_irqrestore(&bd->bd_lock, lock_flags);
4218 return dgap_tty_digigetcustombaud(tty, uarg);
4220 case DIGI_SETCUSTOMBAUD:
4221 spin_unlock_irqrestore(&ch->ch_lock, lock_flags2);
4222 spin_unlock_irqrestore(&bd->bd_lock, lock_flags);
4223 return dgap_tty_digisetcustombaud(tty, uarg);
4225 case DIGI_RESET_PORT:
4226 dgap_firmware_reset_port(ch);
4228 spin_unlock_irqrestore(&ch->ch_lock, lock_flags2);
4229 spin_unlock_irqrestore(&bd->bd_lock, lock_flags);
4233 spin_unlock_irqrestore(&ch->ch_lock, lock_flags2);
4234 spin_unlock_irqrestore(&bd->bd_lock, lock_flags);
4236 return -ENOIOCTLCMD;
4240 static int dgap_after_config_loaded(int board)
4243 * Initialize KME waitqueues...
4245 init_waitqueue_head(&(dgap_Board[board]->kme_wait));
4248 * allocate flip buffer for board.
4250 dgap_Board[board]->flipbuf = kmalloc(MYFLIPLEN, GFP_ATOMIC);
4251 if (!dgap_Board[board]->flipbuf)
4254 dgap_Board[board]->flipflagbuf = kmalloc(MYFLIPLEN, GFP_ATOMIC);
4255 if (!dgap_Board[board]->flipflagbuf) {
4256 kfree(dgap_Board[board]->flipbuf);
4264 * Create pr and tty device entries
4266 static int dgap_tty_register_ports(struct board_t *brd)
4268 struct channel_t *ch;
4271 brd->SerialPorts = kcalloc(brd->nasync, sizeof(*brd->SerialPorts),
4273 if (brd->SerialPorts == NULL)
4275 for (i = 0; i < brd->nasync; i++)
4276 tty_port_init(&brd->SerialPorts[i]);
4278 brd->PrinterPorts = kcalloc(brd->nasync, sizeof(*brd->PrinterPorts),
4280 if (brd->PrinterPorts == NULL) {
4281 kfree(brd->SerialPorts);
4284 for (i = 0; i < brd->nasync; i++)
4285 tty_port_init(&brd->PrinterPorts[i]);
4287 ch = brd->channels[0];
4288 for (i = 0; i < brd->nasync; i++, ch = brd->channels[i]) {
4290 struct device *classp;
4292 classp = tty_port_register_device(&brd->SerialPorts[i],
4294 brd->firstminor + i, NULL);
4296 dgap_create_tty_sysfs(&ch->ch_tun, classp);
4297 ch->ch_tun.un_sysfs = classp;
4299 classp = tty_port_register_device(&brd->PrinterPorts[i],
4301 brd->firstminor + i, NULL);
4303 dgap_create_tty_sysfs(&ch->ch_pun, classp);
4304 ch->ch_pun.un_sysfs = classp;
4306 dgap_create_ports_sysfiles(brd);
4312 * Copies the BIOS code from the user to the board,
4313 * and starts the BIOS running.
4315 static void dgap_do_bios_load(struct board_t *brd, const u8 *ubios, int len)
4321 if (!brd || (brd->magic != DGAP_BOARD_MAGIC) || !brd->re_map_membase)
4324 addr = brd->re_map_membase;
4329 for (i = 0; i < 16; i++)
4330 writeb(0, addr + POSTAREA + i);
4336 memcpy_toio(addr + offset, ubios, len);
4338 writel(0x0bf00401, addr);
4339 writel(0, (addr + 4));
4341 /* Clear the reset, and change states. */
4342 writeb(FEPCLR, brd->re_map_port);
4346 * Checks to see if the BIOS completed running on the card.
4348 static int dgap_test_bios(struct board_t *brd)
4355 if (!brd || (brd->magic != DGAP_BOARD_MAGIC) || !brd->re_map_membase)
4358 addr = brd->re_map_membase;
4359 word = readw(addr + POSTAREA);
4362 * It can take 5-6 seconds for a board to
4363 * pass the bios self test and post results.
4364 * Give it 10 seconds.
4366 brd->wait_for_bios = 0;
4367 while (brd->wait_for_bios < 1000) {
4368 /* Check to see if BIOS thinks board is good. (GD). */
4369 if (word == *(u16 *) "GD")
4371 msleep_interruptible(10);
4372 brd->wait_for_bios++;
4373 word = readw(addr + POSTAREA);
4376 /* Gave up on board after too long of time taken */
4377 err1 = readw(addr + SEQUENCE);
4378 err2 = readw(addr + ERROR);
4379 pr_warn("dgap: %s failed diagnostics. Error #(%x,%x).\n",
4380 brd->name, err1, err2);
4381 brd->state = BOARD_FAILED;
4382 brd->dpastatus = BD_NOBIOS;
4388 * Copies the FEP code from the user to the board,
4389 * and starts the FEP running.
4391 static void dgap_do_fep_load(struct board_t *brd, const u8 *ufep, int len)
4396 if (!brd || (brd->magic != DGAP_BOARD_MAGIC) || !brd->re_map_membase)
4399 addr = brd->re_map_membase;
4405 memcpy_toio(addr + offset, ufep, len);
4408 * If board is a concentrator product, we need to give
4409 * it its config string describing how the concentrators look.
4411 if ((brd->type == PCX) || (brd->type == PEPC)) {
4417 xconfig = dgap_create_config_string(brd, string);
4419 /* Write string to board memory */
4420 config = addr + CONFIG;
4421 for (; i < CONFIGSIZE; i++, config++, xconfig++) {
4422 writeb(*xconfig, config);
4423 if ((*xconfig & 0xff) == 0xff)
4428 writel(0xbfc01004, (addr + 0xc34));
4429 writel(0x3, (addr + 0xc30));
4434 * Waits for the FEP to report thats its ready for us to use.
4436 static int dgap_test_fep(struct board_t *brd)
4443 if (!brd || (brd->magic != DGAP_BOARD_MAGIC) || !brd->re_map_membase)
4446 addr = brd->re_map_membase;
4447 word = readw(addr + FEPSTAT);
4450 * It can take 2-3 seconds for the FEP to
4451 * be up and running. Give it 5 secs.
4453 brd->wait_for_fep = 0;
4454 while (brd->wait_for_fep < 500) {
4455 /* Check to see if FEP is up and running now. */
4456 if (word == *(u16 *) "OS") {
4458 * Check to see if the board can support FEP5+ commands.
4460 word = readw(addr + FEP5_PLUS);
4461 if (word == *(u16 *) "5A")
4462 brd->bd_flags |= BD_FEP5PLUS;
4466 msleep_interruptible(10);
4467 brd->wait_for_fep++;
4468 word = readw(addr + FEPSTAT);
4471 /* Gave up on board after too long of time taken */
4472 err1 = readw(addr + SEQUENCE);
4473 err2 = readw(addr + ERROR);
4474 pr_warn("dgap: FEPOS for %s not functioning. Error #(%x,%x).\n",
4475 brd->name, err1, err2);
4476 brd->state = BOARD_FAILED;
4477 brd->dpastatus = BD_NOFEP;
4483 * Physically forces the FEP5 card to reset itself.
4485 static void dgap_do_reset_board(struct board_t *brd)
4492 if (!brd || (brd->magic != DGAP_BOARD_MAGIC) ||
4493 !brd->re_map_membase || !brd->re_map_port)
4496 /* FEPRST does not vary among supported boards */
4497 writeb(FEPRST, brd->re_map_port);
4499 for (i = 0; i <= 1000; i++) {
4500 check = readb(brd->re_map_port) & 0xe;
4501 if (check == FEPRST)
4507 pr_warn("dgap: Board not resetting... Failing board.\n");
4508 brd->state = BOARD_FAILED;
4509 brd->dpastatus = BD_NOFEP;
4514 * Make sure there really is memory out there.
4516 writel(0xa55a3cc3, (brd->re_map_membase + LOWMEM));
4517 writel(0x5aa5c33c, (brd->re_map_membase + HIGHMEM));
4518 check1 = readl(brd->re_map_membase + LOWMEM);
4519 check2 = readl(brd->re_map_membase + HIGHMEM);
4521 if ((check1 != 0xa55a3cc3) || (check2 != 0x5aa5c33c)) {
4522 pr_warn("dgap: No memory at %p for board.\n",
4523 brd->re_map_membase);
4524 brd->state = BOARD_FAILED;
4525 brd->dpastatus = BD_NOFEP;
4531 #ifdef DIGI_CONCENTRATORS_SUPPORTED
4533 * Sends a concentrator image into the FEP5 board.
4535 static void dgap_do_conc_load(struct board_t *brd, u8 *uaddr, int len)
4537 char __iomem *vaddr;
4539 struct downld_t *to_dp;
4541 if (!brd || (brd->magic != DGAP_BOARD_MAGIC) || !brd->re_map_membase)
4544 vaddr = brd->re_map_membase;
4546 offset = readw((u16 *) (vaddr + DOWNREQ));
4547 to_dp = (struct downld_t *) (vaddr + (int) offset);
4548 memcpy_toio(to_dp, uaddr, len);
4550 /* Tell card we have data for it */
4551 writew(0, vaddr + (DOWNREQ));
4553 brd->conc_dl_status = NO_PENDING_CONCENTRATOR_REQUESTS;
4557 #define EXPANSION_ROM_SIZE (64 * 1024)
4558 #define FEP5_ROM_MAGIC (0xFEFFFFFF)
4560 static void dgap_get_vpd(struct board_t *brd)
4572 * Poke the magic number at the PCI Rom Address location.
4573 * If VPD is supported, the value read from that address
4576 magic = FEP5_ROM_MAGIC;
4577 pci_write_config_dword(brd->pdev, PCI_ROM_ADDRESS, magic);
4578 pci_read_config_dword(brd->pdev, PCI_ROM_ADDRESS, &magic);
4580 /* VPD not supported, bail */
4585 * To get to the OTPROM memory, we have to send the boards base
4586 * address or'ed with 1 into the PCI Rom Address location.
4588 magic = brd->membase | 0x01;
4589 pci_write_config_dword(brd->pdev, PCI_ROM_ADDRESS, magic);
4590 pci_read_config_dword(brd->pdev, PCI_ROM_ADDRESS, &magic);
4592 byte1 = readb(brd->re_map_membase);
4593 byte2 = readb(brd->re_map_membase + 1);
4596 * If the board correctly swapped to the OTPROM memory,
4597 * the first 2 bytes (header) should be 0x55, 0xAA
4599 if (byte1 == 0x55 && byte2 == 0xAA) {
4604 * We have to run through all the OTPROM memory looking
4605 * for the VPD offset.
4607 while (base_offset <= EXPANSION_ROM_SIZE) {
4610 * Lots of magic numbers here.
4612 * The VPD offset is located inside the ROM Data
4615 * We also have to remember the length of each
4616 * ROM Data Structure, so we can "hop" to the next
4617 * entry if the VPD isn't in the current
4618 * ROM Data Structure.
4620 rom_offset = readw(brd->re_map_membase +
4621 base_offset + 0x18);
4622 image_length = readw(brd->re_map_membase +
4623 rom_offset + 0x10) * 512;
4624 vpd_offset = readw(brd->re_map_membase +
4627 /* Found the VPD entry */
4631 /* We didn't find a VPD entry, go to next ROM entry. */
4632 base_offset += image_length;
4634 byte1 = readb(brd->re_map_membase + base_offset);
4635 byte2 = readb(brd->re_map_membase + base_offset + 1);
4638 * If the new ROM offset doesn't have 0x55, 0xAA
4639 * as its header, we have run out of ROM.
4641 if (byte1 != 0x55 || byte2 != 0xAA)
4646 * If we have a VPD offset, then mark the board
4647 * as having a valid VPD, and copy VPDSIZE (512) bytes of
4648 * that VPD to the buffer we have in our board structure.
4651 brd->bd_flags |= BD_HAS_VPD;
4652 for (i = 0; i < VPDSIZE; i++) {
4653 brd->vpd[i] = readb(brd->re_map_membase +
4660 * We MUST poke the magic number at the PCI Rom Address location again.
4661 * This makes the card report the regular board memory back to us,
4662 * rather than the OTPROM memory.
4664 magic = FEP5_ROM_MAGIC;
4665 pci_write_config_dword(brd->pdev, PCI_ROM_ADDRESS, magic);
4669 * Our board poller function.
4671 static void dgap_poll_tasklet(unsigned long data)
4673 struct board_t *bd = (struct board_t *) data;
4675 char __iomem *vaddr;
4678 if (!bd || (bd->magic != DGAP_BOARD_MAGIC))
4681 if (bd->inhibit_poller)
4684 spin_lock_irqsave(&bd->bd_lock, lock_flags);
4686 vaddr = bd->re_map_membase;
4689 * If board is ready, parse deeper to see if there is anything to do.
4691 if (bd->state == BOARD_READY) {
4693 struct ev_t __iomem *eaddr;
4695 if (!bd->re_map_membase) {
4696 spin_unlock_irqrestore(&bd->bd_lock, lock_flags);
4699 if (!bd->re_map_port) {
4700 spin_unlock_irqrestore(&bd->bd_lock, lock_flags);
4707 eaddr = (struct ev_t __iomem *) (vaddr + EVBUF);
4709 /* Get our head and tail */
4710 head = readw(&(eaddr->ev_head));
4711 tail = readw(&(eaddr->ev_tail));
4714 * If there is an event pending. Go service it.
4717 spin_unlock_irqrestore(&bd->bd_lock, lock_flags);
4719 spin_lock_irqsave(&bd->bd_lock, lock_flags);
4724 * If board is doing interrupts, ACK the interrupt.
4726 if (bd && bd->intr_running)
4727 readb(bd->re_map_port + 2);
4729 spin_unlock_irqrestore(&bd->bd_lock, lock_flags);
4733 spin_unlock_irqrestore(&bd->bd_lock, lock_flags);
4736 /*=======================================================================
4738 * dgap_cmdb - Sends a 2 byte command to the FEP.
4740 * ch - Pointer to channel structure.
4741 * cmd - Command to be sent.
4742 * byte1 - Integer containing first byte to be sent.
4743 * byte2 - Integer containing second byte to be sent.
4744 * ncmds - Wait until ncmds or fewer cmds are left
4745 * in the cmd buffer before returning.
4747 *=======================================================================*/
4748 static void dgap_cmdb(struct channel_t *ch, u8 cmd, u8 byte1,
4749 u8 byte2, uint ncmds)
4751 char __iomem *vaddr;
4752 struct __iomem cm_t *cm_addr;
4758 if (!ch || ch->magic != DGAP_CHANNEL_MAGIC)
4762 * Check if board is still alive.
4764 if (ch->ch_bd->state == BOARD_FAILED)
4768 * Make sure the pointers are in range before
4769 * writing to the FEP memory.
4771 vaddr = ch->ch_bd->re_map_membase;
4776 cm_addr = (struct cm_t __iomem *) (vaddr + CMDBUF);
4777 head = readw(&(cm_addr->cm_head));
4780 * Forget it if pointers out of range.
4782 if (head >= (CMDMAX - CMDSTART) || (head & 03)) {
4783 ch->ch_bd->state = BOARD_FAILED;
4788 * Put the data in the circular command buffer.
4790 writeb(cmd, (vaddr + head + CMDSTART + 0));
4791 writeb((u8) ch->ch_portnum, (vaddr + head + CMDSTART + 1));
4792 writeb(byte1, (vaddr + head + CMDSTART + 2));
4793 writeb(byte2, (vaddr + head + CMDSTART + 3));
4795 head = (head + 4) & (CMDMAX - CMDSTART - 4);
4797 writew(head, &(cm_addr->cm_head));
4800 * Wait if necessary before updating the head
4801 * pointer to limit the number of outstanding
4802 * commands to the FEP. If the time spent waiting
4803 * is outlandish, declare the FEP dead.
4805 for (count = dgap_count ;;) {
4807 head = readw(&(cm_addr->cm_head));
4808 tail = readw(&(cm_addr->cm_tail));
4810 n = (head - tail) & (CMDMAX - CMDSTART - 4);
4812 if (n <= ncmds * sizeof(struct cm_t))
4816 ch->ch_bd->state = BOARD_FAILED;
4823 /*=======================================================================
4825 * dgap_cmdw - Sends a 1 word command to the FEP.
4827 * ch - Pointer to channel structure.
4828 * cmd - Command to be sent.
4829 * word - Integer containing word to be sent.
4830 * ncmds - Wait until ncmds or fewer cmds are left
4831 * in the cmd buffer before returning.
4833 *=======================================================================*/
4834 static void dgap_cmdw(struct channel_t *ch, u8 cmd, u16 word, uint ncmds)
4836 char __iomem *vaddr;
4837 struct __iomem cm_t *cm_addr;
4843 if (!ch || ch->magic != DGAP_CHANNEL_MAGIC)
4847 * Check if board is still alive.
4849 if (ch->ch_bd->state == BOARD_FAILED)
4853 * Make sure the pointers are in range before
4854 * writing to the FEP memory.
4856 vaddr = ch->ch_bd->re_map_membase;
4860 cm_addr = (struct cm_t __iomem *) (vaddr + CMDBUF);
4861 head = readw(&(cm_addr->cm_head));
4864 * Forget it if pointers out of range.
4866 if (head >= (CMDMAX - CMDSTART) || (head & 03)) {
4867 ch->ch_bd->state = BOARD_FAILED;
4872 * Put the data in the circular command buffer.
4874 writeb(cmd, (vaddr + head + CMDSTART + 0));
4875 writeb((u8) ch->ch_portnum, (vaddr + head + CMDSTART + 1));
4876 writew((u16) word, (vaddr + head + CMDSTART + 2));
4878 head = (head + 4) & (CMDMAX - CMDSTART - 4);
4880 writew(head, &(cm_addr->cm_head));
4883 * Wait if necessary before updating the head
4884 * pointer to limit the number of outstanding
4885 * commands to the FEP. If the time spent waiting
4886 * is outlandish, declare the FEP dead.
4888 for (count = dgap_count ;;) {
4890 head = readw(&(cm_addr->cm_head));
4891 tail = readw(&(cm_addr->cm_tail));
4893 n = (head - tail) & (CMDMAX - CMDSTART - 4);
4895 if (n <= ncmds * sizeof(struct cm_t))
4899 ch->ch_bd->state = BOARD_FAILED;
4906 /*=======================================================================
4908 * dgap_cmdw_ext - Sends a extended word command to the FEP.
4910 * ch - Pointer to channel structure.
4911 * cmd - Command to be sent.
4912 * word - Integer containing word to be sent.
4913 * ncmds - Wait until ncmds or fewer cmds are left
4914 * in the cmd buffer before returning.
4916 *=======================================================================*/
4917 static void dgap_cmdw_ext(struct channel_t *ch, u16 cmd, u16 word, uint ncmds)
4919 char __iomem *vaddr;
4920 struct __iomem cm_t *cm_addr;
4926 if (!ch || ch->magic != DGAP_CHANNEL_MAGIC)
4930 * Check if board is still alive.
4932 if (ch->ch_bd->state == BOARD_FAILED)
4936 * Make sure the pointers are in range before
4937 * writing to the FEP memory.
4939 vaddr = ch->ch_bd->re_map_membase;
4943 cm_addr = (struct cm_t __iomem *) (vaddr + CMDBUF);
4944 head = readw(&(cm_addr->cm_head));
4947 * Forget it if pointers out of range.
4949 if (head >= (CMDMAX - CMDSTART) || (head & 03)) {
4950 ch->ch_bd->state = BOARD_FAILED;
4955 * Put the data in the circular command buffer.
4958 /* Write an FF to tell the FEP that we want an extended command */
4959 writeb((u8) 0xff, (vaddr + head + CMDSTART + 0));
4961 writeb((u8) ch->ch_portnum, (vaddr + head + CMDSTART + 1));
4962 writew((u16) cmd, (vaddr + head + CMDSTART + 2));
4965 * If the second part of the command won't fit,
4966 * put it at the beginning of the circular buffer.
4968 if (((head + 4) >= ((CMDMAX - CMDSTART)) || (head & 03)))
4969 writew((u16) word, (vaddr + CMDSTART));
4971 writew((u16) word, (vaddr + head + CMDSTART + 4));
4973 head = (head + 8) & (CMDMAX - CMDSTART - 4);
4975 writew(head, &(cm_addr->cm_head));
4978 * Wait if necessary before updating the head
4979 * pointer to limit the number of outstanding
4980 * commands to the FEP. If the time spent waiting
4981 * is outlandish, declare the FEP dead.
4983 for (count = dgap_count ;;) {
4985 head = readw(&(cm_addr->cm_head));
4986 tail = readw(&(cm_addr->cm_tail));
4988 n = (head - tail) & (CMDMAX - CMDSTART - 4);
4990 if (n <= ncmds * sizeof(struct cm_t))
4994 ch->ch_bd->state = BOARD_FAILED;
5001 /*=======================================================================
5003 * dgap_wmove - Write data to FEP buffer.
5005 * ch - Pointer to channel structure.
5006 * buf - Poiter to characters to be moved.
5007 * cnt - Number of characters to move.
5009 *=======================================================================*/
5010 static void dgap_wmove(struct channel_t *ch, char *buf, uint cnt)
5013 char __iomem *taddr;
5014 struct bs_t __iomem *bs;
5017 if (!ch || ch->magic != DGAP_CHANNEL_MAGIC)
5024 head = readw(&(bs->tx_head));
5027 * If pointers are out of range, just return.
5029 if ((cnt > ch->ch_tsize) ||
5030 (unsigned)(head - ch->ch_tstart) >= ch->ch_tsize)
5034 * If the write wraps over the top of the circular buffer,
5035 * move the portion up to the wrap point, and reset the
5036 * pointers to the bottom.
5038 n = ch->ch_tstart + ch->ch_tsize - head;
5042 taddr = ch->ch_taddr + head;
5043 memcpy_toio(taddr, buf, n);
5044 head = ch->ch_tstart;
5049 * Move rest of data.
5051 taddr = ch->ch_taddr + head;
5053 memcpy_toio(taddr, buf, n);
5056 writew(head, &(bs->tx_head));
5060 * Retrives the current custom baud rate from FEP memory,
5061 * and returns it back to the user.
5062 * Returns 0 on error.
5064 static uint dgap_get_custom_baud(struct channel_t *ch)
5070 if (!ch || ch->magic != DGAP_CHANNEL_MAGIC)
5073 if (!ch->ch_bd || ch->ch_bd->magic != DGAP_BOARD_MAGIC)
5076 if (!(ch->ch_bd->bd_flags & BD_FEP5PLUS))
5079 vaddr = ch->ch_bd->re_map_membase;
5085 * Go get from fep mem, what the fep
5086 * believes the custom baud rate is.
5088 offset = ((((*(unsigned short __iomem *)(vaddr + ECS_SEG)) << 4) +
5089 (ch->ch_portnum * 0x28) + LINE_SPEED));
5091 value = readw(vaddr + offset);
5096 * Calls the firmware to reset this channel.
5098 static void dgap_firmware_reset_port(struct channel_t *ch)
5100 dgap_cmdb(ch, CHRESET, 0, 0, 0);
5103 * Now that the channel is reset, we need to make sure
5104 * all the current settings get reapplied to the port
5107 * So we will set the driver's cache of firmware
5108 * settings all to 0, and then call param.
5110 ch->ch_fepiflag = 0;
5111 ch->ch_fepcflag = 0;
5112 ch->ch_fepoflag = 0;
5113 ch->ch_fepstartc = 0;
5114 ch->ch_fepstopc = 0;
5115 ch->ch_fepastartc = 0;
5116 ch->ch_fepastopc = 0;
5121 /*=======================================================================
5123 * dgap_param - Set Digi parameters.
5125 * struct tty_struct * - TTY for port.
5127 *=======================================================================*/
5128 static int dgap_param(struct tty_struct *tty)
5130 struct ktermios *ts;
5132 struct channel_t *ch;
5133 struct bs_t __iomem *bs;
5141 if (!tty || tty->magic != TTY_MAGIC)
5144 un = (struct un_t *) tty->driver_data;
5145 if (!un || un->magic != DGAP_UNIT_MAGIC)
5149 if (!ch || ch->magic != DGAP_CHANNEL_MAGIC)
5153 if (!bd || bd->magic != DGAP_BOARD_MAGIC)
5163 * If baud rate is zero, flush queues, and set mval to drop DTR.
5165 if ((ch->ch_c_cflag & (CBAUD)) == 0) {
5168 head = readw(&(ch->ch_bs->rx_head));
5169 writew(head, &(ch->ch_bs->rx_tail));
5172 head = readw(&(ch->ch_bs->tx_head));
5173 writew(head, &(ch->ch_bs->tx_tail));
5175 ch->ch_flags |= (CH_BAUD0);
5177 /* Drop RTS and DTR */
5178 ch->ch_mval &= ~(D_RTS(ch)|D_DTR(ch));
5179 mval = D_DTR(ch) | D_RTS(ch);
5180 ch->ch_baud_info = 0;
5182 } else if (ch->ch_custom_speed && (bd->bd_flags & BD_FEP5PLUS)) {
5184 * Tell the fep to do the command
5187 dgap_cmdw_ext(ch, 0xff01, ch->ch_custom_speed, 0);
5190 * Now go get from fep mem, what the fep
5191 * believes the custom baud rate is.
5193 ch->ch_custom_speed = dgap_get_custom_baud(ch);
5194 ch->ch_baud_info = ch->ch_custom_speed;
5196 /* Handle transition from B0 */
5197 if (ch->ch_flags & CH_BAUD0) {
5198 ch->ch_flags &= ~(CH_BAUD0);
5199 ch->ch_mval |= (D_RTS(ch)|D_DTR(ch));
5201 mval = D_DTR(ch) | D_RTS(ch);
5205 * Set baud rate, character size, and parity.
5213 ulong bauds[4][16] = {
5217 600, 1200, 1800, 2400,
5218 4800, 9600, 19200, 38400 },
5219 { /* slowbaud & CBAUDEX */
5220 0, 57600, 115200, 230400,
5221 460800, 150, 200, 921600,
5222 600, 1200, 1800, 2400,
5223 4800, 9600, 19200, 38400 },
5225 0, 57600, 76800, 115200,
5226 14400, 57600, 230400, 76800,
5227 115200, 230400, 28800, 460800,
5228 921600, 9600, 19200, 38400 },
5229 { /* fastbaud & CBAUDEX */
5230 0, 57600, 115200, 230400,
5231 460800, 150, 200, 921600,
5232 600, 1200, 1800, 2400,
5233 4800, 9600, 19200, 38400 }
5237 * Only use the TXPrint baud rate if the
5238 * terminal unit is NOT open
5240 if (!(ch->ch_tun.un_flags & UN_ISOPEN) &&
5241 (un->un_type == DGAP_PRINT))
5242 baud = C_BAUD(ch->ch_pun.un_tty) & 0xff;
5244 baud = C_BAUD(ch->ch_tun.un_tty) & 0xff;
5246 if (ch->ch_c_cflag & CBAUDEX)
5249 if (ch->ch_digi.digi_flags & DIGI_FAST)
5254 if ((iindex >= 0) && (iindex < 4) &&
5255 (jindex >= 0) && (jindex < 16))
5256 baud = bauds[iindex][jindex];
5263 ch->ch_baud_info = baud;
5266 * CBAUD has bit position 0x1000 set these days to
5267 * indicate Linux baud rate remap.
5268 * We use a different bit assignment for high speed.
5269 * Clear this bit out while grabbing the parts of
5272 cflag = ch->ch_c_cflag & ((CBAUD ^ CBAUDEX) | PARODD | PARENB |
5276 * HUPCL bit is used by FEP to indicate fast baud
5277 * table is to be used.
5279 if ((ch->ch_digi.digi_flags & DIGI_FAST) ||
5280 (ch->ch_c_cflag & CBAUDEX))
5283 if ((ch->ch_c_cflag & CBAUDEX) &&
5284 !(ch->ch_digi.digi_flags & DIGI_FAST)) {
5286 * The below code is trying to guarantee that only
5287 * baud rates 115200, 230400, 460800, 921600 are
5288 * remapped. We use exclusive or because the various
5289 * baud rates share common bit positions and therefore
5290 * can't be tested for easily.
5292 tcflag_t tcflag = (ch->ch_c_cflag & CBAUD) | CBAUDEX;
5296 * Map high speed requests to index
5297 * into FEP's baud table
5327 cflag = (cflag & ~(CBAUD | CBAUDEX)) | baudpart;
5332 if (cflag != ch->ch_fepcflag) {
5333 ch->ch_fepcflag = (u16) (cflag & 0xffff);
5336 * Okay to have channel and board
5337 * locks held calling this
5339 dgap_cmdw(ch, SCFLAG, (u16) cflag, 0);
5342 /* Handle transition from B0 */
5343 if (ch->ch_flags & CH_BAUD0) {
5344 ch->ch_flags &= ~(CH_BAUD0);
5345 ch->ch_mval |= (D_RTS(ch)|D_DTR(ch));
5347 mval = D_DTR(ch) | D_RTS(ch);
5353 iflag = ch->ch_c_iflag & (IGNBRK | BRKINT | IGNPAR | PARMRK |
5354 INPCK | ISTRIP | IXON | IXANY | IXOFF);
5356 if ((ch->ch_startc == _POSIX_VDISABLE) ||
5357 (ch->ch_stopc == _POSIX_VDISABLE)) {
5358 iflag &= ~(IXON | IXOFF);
5359 ch->ch_c_iflag &= ~(IXON | IXOFF);
5363 * Only the IBM Xr card can switch between
5364 * 232 and 422 modes on the fly
5366 if (bd->device == PCI_DEV_XR_IBM_DID) {
5367 if (ch->ch_digi.digi_flags & DIGI_422)
5368 dgap_cmdb(ch, SCOMMODE, MODE_422, 0, 0);
5370 dgap_cmdb(ch, SCOMMODE, MODE_232, 0, 0);
5373 if (ch->ch_digi.digi_flags & DIGI_ALTPIN)
5376 if (iflag != ch->ch_fepiflag) {
5377 ch->ch_fepiflag = iflag;
5379 /* Okay to have channel and board locks held calling this */
5380 dgap_cmdw(ch, SIFLAG, (u16) ch->ch_fepiflag, 0);
5384 * Select hardware handshaking.
5388 if (ch->ch_c_cflag & CRTSCTS)
5389 hflow |= (D_RTS(ch) | D_CTS(ch));
5390 if (ch->ch_digi.digi_flags & RTSPACE)
5392 if (ch->ch_digi.digi_flags & DTRPACE)
5394 if (ch->ch_digi.digi_flags & CTSPACE)
5396 if (ch->ch_digi.digi_flags & DSRPACE)
5398 if (ch->ch_digi.digi_flags & DCDPACE)
5401 if (hflow != ch->ch_hflow) {
5402 ch->ch_hflow = hflow;
5404 /* Okay to have channel and board locks held calling this */
5405 dgap_cmdb(ch, SHFLOW, (u8) hflow, 0xff, 0);
5410 * Set RTS and/or DTR Toggle if needed,
5411 * but only if product is FEP5+ based.
5413 if (bd->bd_flags & BD_FEP5PLUS) {
5415 if (ch->ch_digi.digi_flags & DIGI_RTS_TOGGLE)
5416 hflow2 |= (D_RTS(ch));
5417 if (ch->ch_digi.digi_flags & DIGI_DTR_TOGGLE)
5418 hflow2 |= (D_DTR(ch));
5420 dgap_cmdw_ext(ch, 0xff03, hflow2, 0);
5424 * Set modem control lines.
5427 mval ^= ch->ch_mforce & (mval ^ ch->ch_mval);
5429 if (ch->ch_mostat ^ mval) {
5430 ch->ch_mostat = mval;
5432 /* Okay to have channel and board locks held calling this */
5433 dgap_cmdb(ch, SMODEM, (u8) mval, D_RTS(ch)|D_DTR(ch), 0);
5437 * Read modem signals, and then call carrier function.
5439 ch->ch_mistat = readb(&(bs->m_stat));
5443 * Set the start and stop characters.
5445 if (ch->ch_startc != ch->ch_fepstartc ||
5446 ch->ch_stopc != ch->ch_fepstopc) {
5447 ch->ch_fepstartc = ch->ch_startc;
5448 ch->ch_fepstopc = ch->ch_stopc;
5450 /* Okay to have channel and board locks held calling this */
5451 dgap_cmdb(ch, SFLOWC, ch->ch_fepstartc, ch->ch_fepstopc, 0);
5455 * Set the Auxiliary start and stop characters.
5457 if (ch->ch_astartc != ch->ch_fepastartc ||
5458 ch->ch_astopc != ch->ch_fepastopc) {
5459 ch->ch_fepastartc = ch->ch_astartc;
5460 ch->ch_fepastopc = ch->ch_astopc;
5462 /* Okay to have channel and board locks held calling this */
5463 dgap_cmdb(ch, SAFLOWC, ch->ch_fepastartc, ch->ch_fepastopc, 0);
5470 * dgap_parity_scan()
5472 * Convert the FEP5 way of reporting parity errors and breaks into
5473 * the Linux line discipline way.
5475 static void dgap_parity_scan(struct channel_t *ch, unsigned char *cbuf,
5476 unsigned char *fbuf, int *len)
5480 unsigned char *in, *cout, *fout;
5487 if (!ch || ch->magic != DGAP_CHANNEL_MAGIC)
5492 switch (ch->pscan_state) {
5494 /* reset to sanity and fall through */
5495 ch->pscan_state = 0;
5498 /* No FF seen yet */
5499 if (c == (unsigned char) '\377')
5500 /* delete this character from stream */
5501 ch->pscan_state = 1;
5504 *fout++ = TTY_NORMAL;
5511 if (c == (unsigned char) '\377') {
5512 /* doubled ff, transform to single ff */
5514 *fout++ = TTY_NORMAL;
5516 ch->pscan_state = 0;
5518 /* save value examination in next state */
5519 ch->pscan_savechar = c;
5520 ch->pscan_state = 2;
5525 /* third character of ff sequence */
5529 if (ch->pscan_savechar == 0x0) {
5533 *fout++ = TTY_BREAK;
5535 ch->ch_err_parity++;
5536 *fout++ = TTY_PARITY;
5541 ch->pscan_state = 0;
5547 static void dgap_write_wakeup(struct board_t *bd, struct channel_t *ch,
5548 struct un_t *un, u32 mask,
5549 unsigned long *irq_flags1,
5550 unsigned long *irq_flags2)
5552 if (!(un->un_flags & mask))
5555 un->un_flags &= ~mask;
5557 if (!(un->un_flags & UN_ISOPEN))
5560 if ((un->un_tty->flags & (1 << TTY_DO_WRITE_WAKEUP)) &&
5561 un->un_tty->ldisc->ops->write_wakeup) {
5562 spin_unlock_irqrestore(&ch->ch_lock, *irq_flags2);
5563 spin_unlock_irqrestore(&bd->bd_lock, *irq_flags1);
5565 (un->un_tty->ldisc->ops->write_wakeup)(un->un_tty);
5567 spin_lock_irqsave(&bd->bd_lock, *irq_flags1);
5568 spin_lock_irqsave(&ch->ch_lock, *irq_flags2);
5570 wake_up_interruptible(&un->un_tty->write_wait);
5571 wake_up_interruptible(&un->un_flags_wait);
5574 /*=======================================================================
5576 * dgap_event - FEP to host event processing routine.
5578 * bd - Board of current event.
5580 *=======================================================================*/
5581 static int dgap_event(struct board_t *bd)
5583 struct channel_t *ch;
5586 struct bs_t __iomem *bs;
5589 struct ev_t __iomem *eaddr;
5597 if (!bd || bd->magic != DGAP_BOARD_MAGIC)
5600 spin_lock_irqsave(&bd->bd_lock, lock_flags);
5602 vaddr = bd->re_map_membase;
5605 spin_unlock_irqrestore(&bd->bd_lock, lock_flags);
5609 eaddr = (struct ev_t __iomem *) (vaddr + EVBUF);
5611 /* Get our head and tail */
5612 head = readw(&(eaddr->ev_head));
5613 tail = readw(&(eaddr->ev_tail));
5616 * Forget it if pointers out of range.
5619 if (head >= EVMAX - EVSTART || tail >= EVMAX - EVSTART ||
5620 (head | tail) & 03) {
5621 /* Let go of board lock */
5622 spin_unlock_irqrestore(&bd->bd_lock, lock_flags);
5627 * Loop to process all the events in the buffer.
5629 while (tail != head) {
5632 * Get interrupt information.
5635 event = bd->re_map_membase + tail + EVSTART;
5643 * Make sure the interrupt is valid.
5645 if (port >= bd->nasync)
5648 if (!(reason & (IFMODEM | IFBREAK | IFTLW | IFTEM | IFDATA)))
5651 ch = bd->channels[port];
5653 if (!ch || ch->magic != DGAP_CHANNEL_MAGIC)
5657 * If we have made it here, the event was valid.
5658 * Lock down the channel.
5660 spin_lock_irqsave(&ch->ch_lock, lock_flags2);
5665 spin_unlock_irqrestore(&ch->ch_lock, lock_flags2);
5670 * Process received data.
5672 if (reason & IFDATA) {
5675 * ALL LOCKS *MUST* BE DROPPED BEFORE CALLING INPUT!
5676 * input could send some data to ld, which in turn
5677 * could do a callback to one of our other functions.
5679 spin_unlock_irqrestore(&ch->ch_lock, lock_flags2);
5680 spin_unlock_irqrestore(&bd->bd_lock, lock_flags);
5684 spin_lock_irqsave(&bd->bd_lock, lock_flags);
5685 spin_lock_irqsave(&ch->ch_lock, lock_flags2);
5687 if (ch->ch_flags & CH_RACTIVE)
5688 ch->ch_flags |= CH_RENABLE;
5690 writeb(1, &(bs->idata));
5692 if (ch->ch_flags & CH_RWAIT) {
5693 ch->ch_flags &= ~CH_RWAIT;
5695 wake_up_interruptible
5696 (&ch->ch_tun.un_flags_wait);
5701 * Process Modem change signals.
5703 if (reason & IFMODEM) {
5704 ch->ch_mistat = modem;
5711 if (reason & IFBREAK) {
5713 if (ch->ch_tun.un_tty) {
5714 /* A break has been indicated */
5716 tty_buffer_request_room
5717 (ch->ch_tun.un_tty->port, 1);
5718 tty_insert_flip_char(ch->ch_tun.un_tty->port,
5720 tty_flip_buffer_push(ch->ch_tun.un_tty->port);
5725 * Process Transmit low.
5727 if (reason & IFTLW) {
5728 dgap_write_wakeup(bd, ch, &ch->ch_tun, UN_LOW,
5729 &lock_flags, &lock_flags2);
5730 dgap_write_wakeup(bd, ch, &ch->ch_pun, UN_LOW,
5731 &lock_flags, &lock_flags2);
5732 if (ch->ch_flags & CH_WLOW) {
5733 ch->ch_flags &= ~CH_WLOW;
5734 wake_up_interruptible(&ch->ch_flags_wait);
5739 * Process Transmit empty.
5741 if (reason & IFTEM) {
5742 dgap_write_wakeup(bd, ch, &ch->ch_tun, UN_EMPTY,
5743 &lock_flags, &lock_flags2);
5744 dgap_write_wakeup(bd, ch, &ch->ch_pun, UN_EMPTY,
5745 &lock_flags, &lock_flags2);
5746 if (ch->ch_flags & CH_WEMPTY) {
5747 ch->ch_flags &= ~CH_WEMPTY;
5748 wake_up_interruptible(&ch->ch_flags_wait);
5752 spin_unlock_irqrestore(&ch->ch_lock, lock_flags2);
5755 tail = (tail + 4) & (EVMAX - EVSTART - 4);
5758 writew(tail, &(eaddr->ev_tail));
5759 spin_unlock_irqrestore(&bd->bd_lock, lock_flags);
5764 static ssize_t dgap_driver_version_show(struct device_driver *ddp, char *buf)
5766 return snprintf(buf, PAGE_SIZE, "%s\n", DG_PART);
5768 static DRIVER_ATTR(version, S_IRUSR, dgap_driver_version_show, NULL);
5771 static ssize_t dgap_driver_boards_show(struct device_driver *ddp, char *buf)
5773 return snprintf(buf, PAGE_SIZE, "%d\n", dgap_NumBoards);
5775 static DRIVER_ATTR(boards, S_IRUSR, dgap_driver_boards_show, NULL);
5778 static ssize_t dgap_driver_maxboards_show(struct device_driver *ddp, char *buf)
5780 return snprintf(buf, PAGE_SIZE, "%d\n", MAXBOARDS);
5782 static DRIVER_ATTR(maxboards, S_IRUSR, dgap_driver_maxboards_show, NULL);
5785 static ssize_t dgap_driver_pollcounter_show(struct device_driver *ddp,
5788 return snprintf(buf, PAGE_SIZE, "%ld\n", dgap_poll_counter);
5790 static DRIVER_ATTR(pollcounter, S_IRUSR, dgap_driver_pollcounter_show, NULL);
5792 static ssize_t dgap_driver_pollrate_show(struct device_driver *ddp, char *buf)
5794 return snprintf(buf, PAGE_SIZE, "%dms\n", dgap_poll_tick);
5797 static ssize_t dgap_driver_pollrate_store(struct device_driver *ddp,
5798 const char *buf, size_t count)
5800 if (sscanf(buf, "%d\n", &dgap_poll_tick) != 1)
5804 static DRIVER_ATTR(pollrate, (S_IRUSR | S_IWUSR), dgap_driver_pollrate_show,
5805 dgap_driver_pollrate_store);
5807 static int dgap_create_driver_sysfiles(struct pci_driver *dgap_driver)
5810 struct device_driver *driverfs = &dgap_driver->driver;
5812 rc |= driver_create_file(driverfs, &driver_attr_version);
5813 rc |= driver_create_file(driverfs, &driver_attr_boards);
5814 rc |= driver_create_file(driverfs, &driver_attr_maxboards);
5815 rc |= driver_create_file(driverfs, &driver_attr_pollrate);
5816 rc |= driver_create_file(driverfs, &driver_attr_pollcounter);
5821 static void dgap_remove_driver_sysfiles(struct pci_driver *dgap_driver)
5823 struct device_driver *driverfs = &dgap_driver->driver;
5824 driver_remove_file(driverfs, &driver_attr_version);
5825 driver_remove_file(driverfs, &driver_attr_boards);
5826 driver_remove_file(driverfs, &driver_attr_maxboards);
5827 driver_remove_file(driverfs, &driver_attr_pollrate);
5828 driver_remove_file(driverfs, &driver_attr_pollcounter);
5831 static struct board_t *dgap_verify_board(struct device *p)
5838 bd = dev_get_drvdata(p);
5839 if (!bd || bd->magic != DGAP_BOARD_MAGIC || bd->state != BOARD_READY)
5845 static ssize_t dgap_ports_state_show(struct device *p,
5846 struct device_attribute *attr,
5853 bd = dgap_verify_board(p);
5857 for (i = 0; i < bd->nasync; i++) {
5858 count += snprintf(buf + count, PAGE_SIZE - count,
5859 "%d %s\n", bd->channels[i]->ch_portnum,
5860 bd->channels[i]->ch_open_count ? "Open" : "Closed");
5864 static DEVICE_ATTR(ports_state, S_IRUSR, dgap_ports_state_show, NULL);
5866 static ssize_t dgap_ports_baud_show(struct device *p,
5867 struct device_attribute *attr,
5874 bd = dgap_verify_board(p);
5878 for (i = 0; i < bd->nasync; i++) {
5879 count += snprintf(buf + count, PAGE_SIZE - count, "%d %d\n",
5880 bd->channels[i]->ch_portnum,
5881 bd->channels[i]->ch_baud_info);
5885 static DEVICE_ATTR(ports_baud, S_IRUSR, dgap_ports_baud_show, NULL);
5887 static ssize_t dgap_ports_msignals_show(struct device *p,
5888 struct device_attribute *attr,
5895 bd = dgap_verify_board(p);
5899 for (i = 0; i < bd->nasync; i++) {
5900 if (bd->channels[i]->ch_open_count)
5901 count += snprintf(buf + count, PAGE_SIZE - count,
5902 "%d %s %s %s %s %s %s\n",
5903 bd->channels[i]->ch_portnum,
5904 (bd->channels[i]->ch_mostat &
5905 UART_MCR_RTS) ? "RTS" : "",
5906 (bd->channels[i]->ch_mistat &
5907 UART_MSR_CTS) ? "CTS" : "",
5908 (bd->channels[i]->ch_mostat &
5909 UART_MCR_DTR) ? "DTR" : "",
5910 (bd->channels[i]->ch_mistat &
5911 UART_MSR_DSR) ? "DSR" : "",
5912 (bd->channels[i]->ch_mistat &
5913 UART_MSR_DCD) ? "DCD" : "",
5914 (bd->channels[i]->ch_mistat &
5915 UART_MSR_RI) ? "RI" : "");
5917 count += snprintf(buf + count, PAGE_SIZE - count,
5918 "%d\n", bd->channels[i]->ch_portnum);
5922 static DEVICE_ATTR(ports_msignals, S_IRUSR, dgap_ports_msignals_show, NULL);
5924 static ssize_t dgap_ports_iflag_show(struct device *p,
5925 struct device_attribute *attr,
5932 bd = dgap_verify_board(p);
5936 for (i = 0; i < bd->nasync; i++)
5937 count += snprintf(buf + count, PAGE_SIZE - count, "%d %x\n",
5938 bd->channels[i]->ch_portnum,
5939 bd->channels[i]->ch_c_iflag);
5942 static DEVICE_ATTR(ports_iflag, S_IRUSR, dgap_ports_iflag_show, NULL);
5944 static ssize_t dgap_ports_cflag_show(struct device *p,
5945 struct device_attribute *attr,
5952 bd = dgap_verify_board(p);
5956 for (i = 0; i < bd->nasync; i++)
5957 count += snprintf(buf + count, PAGE_SIZE - count, "%d %x\n",
5958 bd->channels[i]->ch_portnum,
5959 bd->channels[i]->ch_c_cflag);
5962 static DEVICE_ATTR(ports_cflag, S_IRUSR, dgap_ports_cflag_show, NULL);
5964 static ssize_t dgap_ports_oflag_show(struct device *p,
5965 struct device_attribute *attr,
5972 bd = dgap_verify_board(p);
5976 for (i = 0; i < bd->nasync; i++)
5977 count += snprintf(buf + count, PAGE_SIZE - count, "%d %x\n",
5978 bd->channels[i]->ch_portnum,
5979 bd->channels[i]->ch_c_oflag);
5982 static DEVICE_ATTR(ports_oflag, S_IRUSR, dgap_ports_oflag_show, NULL);
5984 static ssize_t dgap_ports_lflag_show(struct device *p,
5985 struct device_attribute *attr,
5992 bd = dgap_verify_board(p);
5996 for (i = 0; i < bd->nasync; i++)
5997 count += snprintf(buf + count, PAGE_SIZE - count, "%d %x\n",
5998 bd->channels[i]->ch_portnum,
5999 bd->channels[i]->ch_c_lflag);
6002 static DEVICE_ATTR(ports_lflag, S_IRUSR, dgap_ports_lflag_show, NULL);
6004 static ssize_t dgap_ports_digi_flag_show(struct device *p,
6005 struct device_attribute *attr,
6012 bd = dgap_verify_board(p);
6016 for (i = 0; i < bd->nasync; i++)
6017 count += snprintf(buf + count, PAGE_SIZE - count, "%d %x\n",
6018 bd->channels[i]->ch_portnum,
6019 bd->channels[i]->ch_digi.digi_flags);
6022 static DEVICE_ATTR(ports_digi_flag, S_IRUSR, dgap_ports_digi_flag_show, NULL);
6024 static ssize_t dgap_ports_rxcount_show(struct device *p,
6025 struct device_attribute *attr,
6032 bd = dgap_verify_board(p);
6036 for (i = 0; i < bd->nasync; i++)
6037 count += snprintf(buf + count, PAGE_SIZE - count, "%d %ld\n",
6038 bd->channels[i]->ch_portnum,
6039 bd->channels[i]->ch_rxcount);
6042 static DEVICE_ATTR(ports_rxcount, S_IRUSR, dgap_ports_rxcount_show, NULL);
6044 static ssize_t dgap_ports_txcount_show(struct device *p,
6045 struct device_attribute *attr,
6052 bd = dgap_verify_board(p);
6056 for (i = 0; i < bd->nasync; i++)
6057 count += snprintf(buf + count, PAGE_SIZE - count, "%d %ld\n",
6058 bd->channels[i]->ch_portnum,
6059 bd->channels[i]->ch_txcount);
6062 static DEVICE_ATTR(ports_txcount, S_IRUSR, dgap_ports_txcount_show, NULL);
6064 /* this function creates the sys files that will export each signal status
6065 * to sysfs each value will be put in a separate filename
6067 static void dgap_create_ports_sysfiles(struct board_t *bd)
6069 dev_set_drvdata(&bd->pdev->dev, bd);
6070 device_create_file(&(bd->pdev->dev), &dev_attr_ports_state);
6071 device_create_file(&(bd->pdev->dev), &dev_attr_ports_baud);
6072 device_create_file(&(bd->pdev->dev), &dev_attr_ports_msignals);
6073 device_create_file(&(bd->pdev->dev), &dev_attr_ports_iflag);
6074 device_create_file(&(bd->pdev->dev), &dev_attr_ports_cflag);
6075 device_create_file(&(bd->pdev->dev), &dev_attr_ports_oflag);
6076 device_create_file(&(bd->pdev->dev), &dev_attr_ports_lflag);
6077 device_create_file(&(bd->pdev->dev), &dev_attr_ports_digi_flag);
6078 device_create_file(&(bd->pdev->dev), &dev_attr_ports_rxcount);
6079 device_create_file(&(bd->pdev->dev), &dev_attr_ports_txcount);
6082 /* removes all the sys files created for that port */
6083 static void dgap_remove_ports_sysfiles(struct board_t *bd)
6085 device_remove_file(&(bd->pdev->dev), &dev_attr_ports_state);
6086 device_remove_file(&(bd->pdev->dev), &dev_attr_ports_baud);
6087 device_remove_file(&(bd->pdev->dev), &dev_attr_ports_msignals);
6088 device_remove_file(&(bd->pdev->dev), &dev_attr_ports_iflag);
6089 device_remove_file(&(bd->pdev->dev), &dev_attr_ports_cflag);
6090 device_remove_file(&(bd->pdev->dev), &dev_attr_ports_oflag);
6091 device_remove_file(&(bd->pdev->dev), &dev_attr_ports_lflag);
6092 device_remove_file(&(bd->pdev->dev), &dev_attr_ports_digi_flag);
6093 device_remove_file(&(bd->pdev->dev), &dev_attr_ports_rxcount);
6094 device_remove_file(&(bd->pdev->dev), &dev_attr_ports_txcount);
6097 static ssize_t dgap_tty_state_show(struct device *d,
6098 struct device_attribute *attr,
6102 struct channel_t *ch;
6107 un = dev_get_drvdata(d);
6108 if (!un || un->magic != DGAP_UNIT_MAGIC)
6111 if (!ch || ch->magic != DGAP_CHANNEL_MAGIC)
6114 if (!bd || bd->magic != DGAP_BOARD_MAGIC)
6116 if (bd->state != BOARD_READY)
6119 return snprintf(buf, PAGE_SIZE, "%s", un->un_open_count ?
6122 static DEVICE_ATTR(state, S_IRUSR, dgap_tty_state_show, NULL);
6124 static ssize_t dgap_tty_baud_show(struct device *d,
6125 struct device_attribute *attr,
6129 struct channel_t *ch;
6134 un = dev_get_drvdata(d);
6135 if (!un || un->magic != DGAP_UNIT_MAGIC)
6138 if (!ch || ch->magic != DGAP_CHANNEL_MAGIC)
6141 if (!bd || bd->magic != DGAP_BOARD_MAGIC)
6143 if (bd->state != BOARD_READY)
6146 return snprintf(buf, PAGE_SIZE, "%d\n", ch->ch_baud_info);
6148 static DEVICE_ATTR(baud, S_IRUSR, dgap_tty_baud_show, NULL);
6150 static ssize_t dgap_tty_msignals_show(struct device *d,
6151 struct device_attribute *attr,
6155 struct channel_t *ch;
6160 un = dev_get_drvdata(d);
6161 if (!un || un->magic != DGAP_UNIT_MAGIC)
6164 if (!ch || ch->magic != DGAP_CHANNEL_MAGIC)
6167 if (!bd || bd->magic != DGAP_BOARD_MAGIC)
6169 if (bd->state != BOARD_READY)
6172 if (ch->ch_open_count) {
6173 return snprintf(buf, PAGE_SIZE, "%s %s %s %s %s %s\n",
6174 (ch->ch_mostat & UART_MCR_RTS) ? "RTS" : "",
6175 (ch->ch_mistat & UART_MSR_CTS) ? "CTS" : "",
6176 (ch->ch_mostat & UART_MCR_DTR) ? "DTR" : "",
6177 (ch->ch_mistat & UART_MSR_DSR) ? "DSR" : "",
6178 (ch->ch_mistat & UART_MSR_DCD) ? "DCD" : "",
6179 (ch->ch_mistat & UART_MSR_RI) ? "RI" : "");
6183 static DEVICE_ATTR(msignals, S_IRUSR, dgap_tty_msignals_show, NULL);
6185 static ssize_t dgap_tty_iflag_show(struct device *d,
6186 struct device_attribute *attr,
6190 struct channel_t *ch;
6195 un = dev_get_drvdata(d);
6196 if (!un || un->magic != DGAP_UNIT_MAGIC)
6199 if (!ch || ch->magic != DGAP_CHANNEL_MAGIC)
6202 if (!bd || bd->magic != DGAP_BOARD_MAGIC)
6204 if (bd->state != BOARD_READY)
6207 return snprintf(buf, PAGE_SIZE, "%x\n", ch->ch_c_iflag);
6209 static DEVICE_ATTR(iflag, S_IRUSR, dgap_tty_iflag_show, NULL);
6211 static ssize_t dgap_tty_cflag_show(struct device *d,
6212 struct device_attribute *attr,
6216 struct channel_t *ch;
6221 un = dev_get_drvdata(d);
6222 if (!un || un->magic != DGAP_UNIT_MAGIC)
6225 if (!ch || ch->magic != DGAP_CHANNEL_MAGIC)
6228 if (!bd || bd->magic != DGAP_BOARD_MAGIC)
6230 if (bd->state != BOARD_READY)
6233 return snprintf(buf, PAGE_SIZE, "%x\n", ch->ch_c_cflag);
6235 static DEVICE_ATTR(cflag, S_IRUSR, dgap_tty_cflag_show, NULL);
6237 static ssize_t dgap_tty_oflag_show(struct device *d,
6238 struct device_attribute *attr,
6242 struct channel_t *ch;
6247 un = dev_get_drvdata(d);
6248 if (!un || un->magic != DGAP_UNIT_MAGIC)
6251 if (!ch || ch->magic != DGAP_CHANNEL_MAGIC)
6254 if (!bd || bd->magic != DGAP_BOARD_MAGIC)
6256 if (bd->state != BOARD_READY)
6259 return snprintf(buf, PAGE_SIZE, "%x\n", ch->ch_c_oflag);
6261 static DEVICE_ATTR(oflag, S_IRUSR, dgap_tty_oflag_show, NULL);
6263 static ssize_t dgap_tty_lflag_show(struct device *d,
6264 struct device_attribute *attr,
6268 struct channel_t *ch;
6273 un = dev_get_drvdata(d);
6274 if (!un || un->magic != DGAP_UNIT_MAGIC)
6277 if (!ch || ch->magic != DGAP_CHANNEL_MAGIC)
6280 if (!bd || bd->magic != DGAP_BOARD_MAGIC)
6282 if (bd->state != BOARD_READY)
6285 return snprintf(buf, PAGE_SIZE, "%x\n", ch->ch_c_lflag);
6287 static DEVICE_ATTR(lflag, S_IRUSR, dgap_tty_lflag_show, NULL);
6289 static ssize_t dgap_tty_digi_flag_show(struct device *d,
6290 struct device_attribute *attr,
6294 struct channel_t *ch;
6299 un = dev_get_drvdata(d);
6300 if (!un || un->magic != DGAP_UNIT_MAGIC)
6303 if (!ch || ch->magic != DGAP_CHANNEL_MAGIC)
6306 if (!bd || bd->magic != DGAP_BOARD_MAGIC)
6308 if (bd->state != BOARD_READY)
6311 return snprintf(buf, PAGE_SIZE, "%x\n", ch->ch_digi.digi_flags);
6313 static DEVICE_ATTR(digi_flag, S_IRUSR, dgap_tty_digi_flag_show, NULL);
6315 static ssize_t dgap_tty_rxcount_show(struct device *d,
6316 struct device_attribute *attr,
6320 struct channel_t *ch;
6325 un = dev_get_drvdata(d);
6326 if (!un || un->magic != DGAP_UNIT_MAGIC)
6329 if (!ch || ch->magic != DGAP_CHANNEL_MAGIC)
6332 if (!bd || bd->magic != DGAP_BOARD_MAGIC)
6334 if (bd->state != BOARD_READY)
6337 return snprintf(buf, PAGE_SIZE, "%ld\n", ch->ch_rxcount);
6339 static DEVICE_ATTR(rxcount, S_IRUSR, dgap_tty_rxcount_show, NULL);
6341 static ssize_t dgap_tty_txcount_show(struct device *d,
6342 struct device_attribute *attr,
6346 struct channel_t *ch;
6351 un = dev_get_drvdata(d);
6352 if (!un || un->magic != DGAP_UNIT_MAGIC)
6355 if (!ch || ch->magic != DGAP_CHANNEL_MAGIC)
6358 if (!bd || bd->magic != DGAP_BOARD_MAGIC)
6360 if (bd->state != BOARD_READY)
6363 return snprintf(buf, PAGE_SIZE, "%ld\n", ch->ch_txcount);
6365 static DEVICE_ATTR(txcount, S_IRUSR, dgap_tty_txcount_show, NULL);
6367 static ssize_t dgap_tty_name_show(struct device *d,
6368 struct device_attribute *attr,
6372 struct channel_t *ch;
6376 struct cnode *cptr = NULL;
6384 un = dev_get_drvdata(d);
6385 if (!un || un->magic != DGAP_UNIT_MAGIC)
6388 if (!ch || ch->magic != DGAP_CHANNEL_MAGIC)
6391 if (!bd || bd->magic != DGAP_BOARD_MAGIC)
6393 if (bd->state != BOARD_READY)
6397 cn = ch->ch_portnum;
6399 for (cptr = bd->bd_config; cptr; cptr = cptr->next) {
6401 if ((cptr->type == BNODE) &&
6402 ((cptr->u.board.type == APORT2_920P) ||
6403 (cptr->u.board.type == APORT4_920P) ||
6404 (cptr->u.board.type == APORT8_920P) ||
6405 (cptr->u.board.type == PAPORT4) ||
6406 (cptr->u.board.type == PAPORT8))) {
6409 if (cptr->u.board.v_start)
6410 starto = cptr->u.board.start;
6415 if (cptr->type == TNODE && found == TRUE) {
6417 if (strstr(cptr->u.ttyname, "tty")) {
6418 ptr1 = cptr->u.ttyname;
6421 ptr1 = cptr->u.ttyname;
6423 for (i = 0; i < dgap_config_get_num_prts(bd); i++) {
6427 return snprintf(buf, PAGE_SIZE, "%s%s%02d\n",
6428 (un->un_type == DGAP_PRINT) ?
6434 if (cptr->type == CNODE) {
6436 for (i = 0; i < cptr->u.conc.nport; i++) {
6437 if (cn != (i + ncount))
6440 return snprintf(buf, PAGE_SIZE, "%s%s%02ld\n",
6441 (un->un_type == DGAP_PRINT) ?
6444 i + (cptr->u.conc.v_start ?
6445 cptr->u.conc.start : 1));
6448 ncount += cptr->u.conc.nport;
6451 if (cptr->type == MNODE) {
6453 for (i = 0; i < cptr->u.module.nport; i++) {
6454 if (cn != (i + ncount))
6457 return snprintf(buf, PAGE_SIZE, "%s%s%02ld\n",
6458 (un->un_type == DGAP_PRINT) ?
6461 i + (cptr->u.module.v_start ?
6462 cptr->u.module.start : 1));
6465 ncount += cptr->u.module.nport;
6470 return snprintf(buf, PAGE_SIZE, "%s_dgap_%d_%d\n",
6471 (un->un_type == DGAP_PRINT) ? "pr" : "tty", bn, cn);
6474 static DEVICE_ATTR(custom_name, S_IRUSR, dgap_tty_name_show, NULL);
6476 static struct attribute *dgap_sysfs_tty_entries[] = {
6477 &dev_attr_state.attr,
6478 &dev_attr_baud.attr,
6479 &dev_attr_msignals.attr,
6480 &dev_attr_iflag.attr,
6481 &dev_attr_cflag.attr,
6482 &dev_attr_oflag.attr,
6483 &dev_attr_lflag.attr,
6484 &dev_attr_digi_flag.attr,
6485 &dev_attr_rxcount.attr,
6486 &dev_attr_txcount.attr,
6487 &dev_attr_custom_name.attr,
6491 static struct attribute_group dgap_tty_attribute_group = {
6493 .attrs = dgap_sysfs_tty_entries,
6496 static void dgap_create_tty_sysfs(struct un_t *un, struct device *c)
6500 ret = sysfs_create_group(&c->kobj, &dgap_tty_attribute_group);
6504 dev_set_drvdata(c, un);
6508 static void dgap_remove_tty_sysfs(struct device *c)
6510 sysfs_remove_group(&c->kobj, &dgap_tty_attribute_group);
6514 * Parse a configuration file read into memory as a string.
6516 static int dgap_parsefile(char **in, int Remove)
6518 struct cnode *p, *brd, *line, *conc;
6524 brd = line = conc = NULL;
6526 /* perhaps we are adding to an existing list? */
6527 while (p->next != NULL)
6530 /* file must start with a BEGIN */
6531 while ((rc = dgap_gettok(in, p)) != BEGIN) {
6533 dgap_err("unexpected EOF");
6539 rc = dgap_gettok(in, p);
6541 dgap_err("unexpected EOF");
6547 dgap_err("unexpected end of file");
6550 case BEGIN: /* should only be 1 begin */
6551 dgap_err("unexpected config_begin\n");
6557 case BOARD: /* board info */
6558 if (dgap_checknode(p))
6560 p->next = dgap_newnode(BNODE);
6562 dgap_err("out of memory");
6567 p->u.board.status = dgap_savestring("No");
6573 case APORT2_920P: /* AccelePort_4 */
6574 if (p->type != BNODE) {
6575 dgap_err("unexpected Digi_2r_920 string");
6578 p->u.board.type = APORT2_920P;
6579 p->u.board.v_type = 1;
6582 case APORT4_920P: /* AccelePort_4 */
6583 if (p->type != BNODE) {
6584 dgap_err("unexpected Digi_4r_920 string");
6587 p->u.board.type = APORT4_920P;
6588 p->u.board.v_type = 1;
6591 case APORT8_920P: /* AccelePort_8 */
6592 if (p->type != BNODE) {
6593 dgap_err("unexpected Digi_8r_920 string");
6596 p->u.board.type = APORT8_920P;
6597 p->u.board.v_type = 1;
6600 case PAPORT4: /* AccelePort_4 PCI */
6601 if (p->type != BNODE) {
6602 dgap_err("unexpected Digi_4r(PCI) string");
6605 p->u.board.type = PAPORT4;
6606 p->u.board.v_type = 1;
6609 case PAPORT8: /* AccelePort_8 PCI */
6610 if (p->type != BNODE) {
6611 dgap_err("unexpected Digi_8r string");
6614 p->u.board.type = PAPORT8;
6615 p->u.board.v_type = 1;
6618 case PCX: /* PCI C/X */
6619 if (p->type != BNODE) {
6620 dgap_err("unexpected Digi_C/X_(PCI) string");
6623 p->u.board.type = PCX;
6624 p->u.board.v_type = 1;
6625 p->u.board.conc1 = 0;
6626 p->u.board.conc2 = 0;
6627 p->u.board.module1 = 0;
6628 p->u.board.module2 = 0;
6631 case PEPC: /* PCI EPC/X */
6632 if (p->type != BNODE) {
6633 dgap_err("unexpected \"Digi_EPC/X_(PCI)\" string");
6636 p->u.board.type = PEPC;
6637 p->u.board.v_type = 1;
6638 p->u.board.conc1 = 0;
6639 p->u.board.conc2 = 0;
6640 p->u.board.module1 = 0;
6641 p->u.board.module2 = 0;
6644 case PPCM: /* PCI/Xem */
6645 if (p->type != BNODE) {
6646 dgap_err("unexpected PCI/Xem string");
6649 p->u.board.type = PPCM;
6650 p->u.board.v_type = 1;
6651 p->u.board.conc1 = 0;
6652 p->u.board.conc2 = 0;
6655 case IO: /* i/o port */
6656 if (p->type != BNODE) {
6657 dgap_err("IO port only vaild for boards");
6660 s = dgap_getword(in);
6662 dgap_err("unexpected end of file");
6665 p->u.board.portstr = dgap_savestring(s);
6666 if (kstrtol(s, 0, &p->u.board.port)) {
6667 dgap_err("bad number for IO port");
6670 p->u.board.v_port = 1;
6673 case MEM: /* memory address */
6674 if (p->type != BNODE) {
6675 dgap_err("memory address only vaild for boards");
6678 s = dgap_getword(in);
6680 dgap_err("unexpected end of file");
6683 p->u.board.addrstr = dgap_savestring(s);
6684 if (kstrtoul(s, 0, &p->u.board.addr)) {
6685 dgap_err("bad number for memory address");
6688 p->u.board.v_addr = 1;
6691 case PCIINFO: /* pci information */
6692 if (p->type != BNODE) {
6693 dgap_err("memory address only vaild for boards");
6696 s = dgap_getword(in);
6698 dgap_err("unexpected end of file");
6701 p->u.board.pcibusstr = dgap_savestring(s);
6702 if (kstrtoul(s, 0, &p->u.board.pcibus)) {
6703 dgap_err("bad number for pci bus");
6706 p->u.board.v_pcibus = 1;
6707 s = dgap_getword(in);
6709 dgap_err("unexpected end of file");
6712 p->u.board.pcislotstr = dgap_savestring(s);
6713 if (kstrtoul(s, 0, &p->u.board.pcislot)) {
6714 dgap_err("bad number for pci slot");
6717 p->u.board.v_pcislot = 1;
6721 if (p->type != BNODE) {
6722 dgap_err("install method only vaild for boards");
6725 s = dgap_getword(in);
6727 dgap_err("unexpected end of file");
6730 p->u.board.method = dgap_savestring(s);
6731 p->u.board.v_method = 1;
6735 if (p->type != BNODE) {
6736 dgap_err("config status only vaild for boards");
6739 s = dgap_getword(in);
6741 dgap_err("unexpected end of file");
6744 p->u.board.status = dgap_savestring(s);
6747 case NPORTS: /* number of ports */
6748 if (p->type == BNODE) {
6749 s = dgap_getword(in);
6751 dgap_err("unexpected end of file");
6754 if (kstrtol(s, 0, &p->u.board.nport)) {
6755 dgap_err("bad number for number of ports");
6758 p->u.board.v_nport = 1;
6759 } else if (p->type == CNODE) {
6760 s = dgap_getword(in);
6762 dgap_err("unexpected end of file");
6765 if (kstrtol(s, 0, &p->u.conc.nport)) {
6766 dgap_err("bad number for number of ports");
6769 p->u.conc.v_nport = 1;
6770 } else if (p->type == MNODE) {
6771 s = dgap_getword(in);
6773 dgap_err("unexpected end of file");
6776 if (kstrtol(s, 0, &p->u.module.nport)) {
6777 dgap_err("bad number for number of ports");
6780 p->u.module.v_nport = 1;
6782 dgap_err("nports only valid for concentrators or modules");
6787 case ID: /* letter ID used in tty name */
6788 s = dgap_getword(in);
6790 dgap_err("unexpected end of file");
6794 p->u.board.status = dgap_savestring(s);
6796 if (p->type == CNODE) {
6797 p->u.conc.id = dgap_savestring(s);
6799 } else if (p->type == MNODE) {
6800 p->u.module.id = dgap_savestring(s);
6801 p->u.module.v_id = 1;
6803 dgap_err("id only valid for concentrators or modules");
6808 case STARTO: /* start offset of ID */
6809 if (p->type == BNODE) {
6810 s = dgap_getword(in);
6812 dgap_err("unexpected end of file");
6815 if (kstrtol(s, 0, &p->u.board.start)) {
6816 dgap_err("bad number for start of tty count");
6819 p->u.board.v_start = 1;
6820 } else if (p->type == CNODE) {
6821 s = dgap_getword(in);
6823 dgap_err("unexpected end of file");
6826 if (kstrtol(s, 0, &p->u.conc.start)) {
6827 dgap_err("bad number for start of tty count");
6830 p->u.conc.v_start = 1;
6831 } else if (p->type == MNODE) {
6832 s = dgap_getword(in);
6834 dgap_err("unexpected end of file");
6837 if (kstrtol(s, 0, &p->u.module.start)) {
6838 dgap_err("bad number for start of tty count");
6841 p->u.module.v_start = 1;
6843 dgap_err("start only valid for concentrators or modules");
6848 case TTYN: /* tty name prefix */
6849 if (dgap_checknode(p))
6851 p->next = dgap_newnode(TNODE);
6853 dgap_err("out of memory");
6857 s = dgap_getword(in);
6859 dgap_err("unexpeced end of file");
6862 p->u.ttyname = dgap_savestring(s);
6863 if (!p->u.ttyname) {
6864 dgap_err("out of memory");
6869 case CU: /* cu name prefix */
6870 if (dgap_checknode(p))
6872 p->next = dgap_newnode(CUNODE);
6874 dgap_err("out of memory");
6878 s = dgap_getword(in);
6880 dgap_err("unexpeced end of file");
6883 p->u.cuname = dgap_savestring(s);
6885 dgap_err("out of memory");
6890 case LINE: /* line information */
6891 if (dgap_checknode(p))
6894 dgap_err("must specify board before line info");
6897 switch (brd->u.board.type) {
6899 dgap_err("line not vaild for PC/em");
6902 p->next = dgap_newnode(LNODE);
6904 dgap_err("out of memory");
6913 case CONC: /* concentrator information */
6914 if (dgap_checknode(p))
6917 dgap_err("must specify line info before concentrator");
6920 p->next = dgap_newnode(CNODE);
6922 dgap_err("out of memory");
6928 brd->u.board.conc2++;
6930 brd->u.board.conc1++;
6934 case CX: /* c/x type concentrator */
6935 if (p->type != CNODE) {
6936 dgap_err("cx only valid for concentrators");
6939 p->u.conc.type = CX;
6940 p->u.conc.v_type = 1;
6943 case EPC: /* epc type concentrator */
6944 if (p->type != CNODE) {
6945 dgap_err("cx only valid for concentrators");
6948 p->u.conc.type = EPC;
6949 p->u.conc.v_type = 1;
6952 case MOD: /* EBI module */
6953 if (dgap_checknode(p))
6956 dgap_err("must specify board info before EBI modules");
6959 switch (brd->u.board.type) {
6965 dgap_err("must specify concentrator info before EBI module");
6969 p->next = dgap_newnode(MNODE);
6971 dgap_err("out of memory");
6976 brd->u.board.module2++;
6978 brd->u.board.module1++;
6982 case PORTS: /* ports type EBI module */
6983 if (p->type != MNODE) {
6984 dgap_err("ports only valid for EBI modules");
6987 p->u.module.type = PORTS;
6988 p->u.module.v_type = 1;
6991 case MODEM: /* ports type EBI module */
6992 if (p->type != MNODE) {
6993 dgap_err("modem only valid for modem modules");
6996 p->u.module.type = MODEM;
6997 p->u.module.v_type = 1;
7001 if (p->type == LNODE) {
7002 s = dgap_getword(in);
7004 dgap_err("unexpected end of file");
7007 p->u.line.cable = dgap_savestring(s);
7008 p->u.line.v_cable = 1;
7012 case SPEED: /* sync line speed indication */
7013 if (p->type == LNODE) {
7014 s = dgap_getword(in);
7016 dgap_err("unexpected end of file");
7019 if (kstrtol(s, 0, &p->u.line.speed)) {
7020 dgap_err("bad number for line speed");
7023 p->u.line.v_speed = 1;
7024 } else if (p->type == CNODE) {
7025 s = dgap_getword(in);
7027 dgap_err("unexpected end of file");
7030 if (kstrtol(s, 0, &p->u.conc.speed)) {
7031 dgap_err("bad number for line speed");
7034 p->u.conc.v_speed = 1;
7036 dgap_err("speed valid only for lines or concentrators.");
7042 if (p->type == CNODE) {
7043 s = dgap_getword(in);
7045 dgap_err("unexpected end of file");
7048 p->u.conc.connect = dgap_savestring(s);
7049 p->u.conc.v_connect = 1;
7052 case PRINT: /* transparent print name prefix */
7053 if (dgap_checknode(p))
7055 p->next = dgap_newnode(PNODE);
7057 dgap_err("out of memory");
7061 s = dgap_getword(in);
7063 dgap_err("unexpeced end of file");
7066 p->u.printname = dgap_savestring(s);
7067 if (!p->u.printname) {
7068 dgap_err("out of memory");
7073 case CMAJOR: /* major number */
7074 if (dgap_checknode(p))
7076 p->next = dgap_newnode(JNODE);
7078 dgap_err("out of memory");
7082 s = dgap_getword(in);
7084 dgap_err("unexpected end of file");
7087 if (kstrtol(s, 0, &p->u.majornumber)) {
7088 dgap_err("bad number for major number");
7093 case ALTPIN: /* altpin setting */
7094 if (dgap_checknode(p))
7096 p->next = dgap_newnode(ANODE);
7098 dgap_err("out of memory");
7102 s = dgap_getword(in);
7104 dgap_err("unexpected end of file");
7107 if (kstrtol(s, 0, &p->u.altpin)) {
7108 dgap_err("bad number for altpin");
7113 case USEINTR: /* enable interrupt setting */
7114 if (dgap_checknode(p))
7116 p->next = dgap_newnode(INTRNODE);
7118 dgap_err("out of memory");
7122 s = dgap_getword(in);
7124 dgap_err("unexpected end of file");
7127 if (kstrtol(s, 0, &p->u.useintr)) {
7128 dgap_err("bad number for useintr");
7133 case TTSIZ: /* size of tty structure */
7134 if (dgap_checknode(p))
7136 p->next = dgap_newnode(TSNODE);
7138 dgap_err("out of memory");
7142 s = dgap_getword(in);
7144 dgap_err("unexpected end of file");
7147 if (kstrtol(s, 0, &p->u.ttysize)) {
7148 dgap_err("bad number for ttysize");
7153 case CHSIZ: /* channel structure size */
7154 if (dgap_checknode(p))
7156 p->next = dgap_newnode(CSNODE);
7158 dgap_err("out of memory");
7162 s = dgap_getword(in);
7164 dgap_err("unexpected end of file");
7167 if (kstrtol(s, 0, &p->u.chsize)) {
7168 dgap_err("bad number for chsize");
7173 case BSSIZ: /* board structure size */
7174 if (dgap_checknode(p))
7176 p->next = dgap_newnode(BSNODE);
7178 dgap_err("out of memory");
7182 s = dgap_getword(in);
7184 dgap_err("unexpected end of file");
7187 if (kstrtol(s, 0, &p->u.bssize)) {
7188 dgap_err("bad number for bssize");
7193 case UNTSIZ: /* sched structure size */
7194 if (dgap_checknode(p))
7196 p->next = dgap_newnode(USNODE);
7198 dgap_err("out of memory");
7202 s = dgap_getword(in);
7204 dgap_err("unexpected end of file");
7207 if (kstrtol(s, 0, &p->u.unsize)) {
7208 dgap_err("bad number for schedsize");
7213 case F2SIZ: /* f2200 structure size */
7214 if (dgap_checknode(p))
7216 p->next = dgap_newnode(FSNODE);
7218 dgap_err("out of memory");
7222 s = dgap_getword(in);
7224 dgap_err("unexpected end of file");
7227 if (kstrtol(s, 0, &p->u.f2size)) {
7228 dgap_err("bad number for f2200size");
7233 case VPSIZ: /* vpix structure size */
7234 if (dgap_checknode(p))
7236 p->next = dgap_newnode(VSNODE);
7238 dgap_err("out of memory");
7242 s = dgap_getword(in);
7244 dgap_err("unexpected end of file");
7247 if (kstrtol(s, 0, &p->u.vpixsize)) {
7248 dgap_err("bad number for vpixsize");
7257 * dgap_sindex: much like index(), but it looks for a match of any character in
7258 * the group, and returns that position. If the first character is a ^, then
7259 * this will match the first occurrence not in that group.
7261 static char *dgap_sindex(char *string, char *group)
7265 if (!string || !group)
7266 return (char *) NULL;
7268 if (*group == '^') {
7270 for (; *string; string++) {
7271 for (ptr = group; *ptr; ptr++) {
7272 if (*ptr == *string)
7279 for (; *string; string++) {
7280 for (ptr = group; *ptr; ptr++) {
7281 if (*ptr == *string)
7287 return (char *) NULL;
7291 * Get a token from the input file; return 0 if end of file is reached
7293 static int dgap_gettok(char **in, struct cnode *p)
7298 if (strstr(dgap_cword, "boar")) {
7299 w = dgap_getword(in);
7300 snprintf(dgap_cword, MAXCWORD, "%s", w);
7301 for (t = dgap_tlist; t->token != 0; t++) {
7302 if (!strcmp(w, t->string))
7305 dgap_err("board !!type not specified");
7308 while ((w = dgap_getword(in))) {
7309 snprintf(dgap_cword, MAXCWORD, "%s", w);
7310 for (t = dgap_tlist; t->token != 0; t++) {
7311 if (!strcmp(w, t->string))
7320 * get a word from the input stream, also keep track of current line number.
7321 * words are separated by whitespace.
7323 static char *dgap_getword(char **in)
7325 char *ret_ptr = *in;
7327 char *ptr = dgap_sindex(*in, " \t\n");
7329 /* If no word found, return null */
7333 /* Mark new location for our buffer */
7337 /* Eat any extra spaces/tabs/newlines that might be present */
7338 while (*in && **in && ((**in == ' ') ||
7349 * print an error message, giving the line number in the file where
7350 * the error occurred.
7352 static void dgap_err(char *s)
7354 pr_err("dgap: parse: %s\n", s);
7358 * allocate a new configuration node of type t
7360 static struct cnode *dgap_newnode(int t)
7364 n = kmalloc(sizeof(struct cnode), GFP_ATOMIC);
7366 memset((char *)n, 0, sizeof(struct cnode));
7373 * dgap_checknode: see if all the necessary info has been supplied for a node
7374 * before creating the next node.
7376 static int dgap_checknode(struct cnode *p)
7380 if (p->u.board.v_type == 0) {
7381 dgap_err("board type !not specified");
7388 if (p->u.line.v_speed == 0) {
7389 dgap_err("line speed not specified");
7395 if (p->u.conc.v_type == 0) {
7396 dgap_err("concentrator type not specified");
7399 if (p->u.conc.v_speed == 0) {
7400 dgap_err("concentrator line speed not specified");
7403 if (p->u.conc.v_nport == 0) {
7404 dgap_err("number of ports on concentrator not specified");
7407 if (p->u.conc.v_id == 0) {
7408 dgap_err("concentrator id letter not specified");
7414 if (p->u.module.v_type == 0) {
7415 dgap_err("EBI module type not specified");
7418 if (p->u.module.v_nport == 0) {
7419 dgap_err("number of ports on EBI module not specified");
7422 if (p->u.module.v_id == 0) {
7423 dgap_err("EBI module id letter not specified");
7432 * save a string somewhere
7434 static char *dgap_savestring(char *s)
7438 p = kmalloc(strlen(s) + 1, GFP_ATOMIC);
7445 * Given a board pointer, returns whether we should use interrupts or not.
7447 static uint dgap_config_get_useintr(struct board_t *bd)
7449 struct cnode *p = NULL;
7454 for (p = bd->bd_config; p; p = p->next) {
7458 * check for pcxr types.
7460 return p->u.useintr;
7466 /* If not found, then don't turn on interrupts. */
7471 * Given a board pointer, returns whether we turn on altpin or not.
7473 static uint dgap_config_get_altpin(struct board_t *bd)
7475 struct cnode *p = NULL;
7480 for (p = bd->bd_config; p; p = p->next) {
7484 * check for pcxr types.
7492 /* If not found, then don't turn on interrupts. */
7497 * Given a specific type of board, if found, detached link and
7498 * returns the first occurrence in the list.
7500 static struct cnode *dgap_find_config(int type, int bus, int slot)
7502 struct cnode *p, *prev = NULL, *prev2 = NULL, *found = NULL;
7506 while (p->next != NULL) {
7510 if (p->type == BNODE) {
7512 if (p->u.board.type == type) {
7514 if (p->u.board.v_pcibus &&
7515 p->u.board.pcibus != bus)
7517 if (p->u.board.v_pcislot &&
7518 p->u.board.pcislot != slot)
7523 * Keep walking thru the list till we
7524 * find the next board.
7526 while (p->next != NULL) {
7529 if (p->type == BNODE) {
7532 * Mark the end of our 1 board
7538 * Link the "next" board to the
7539 * previous board, effectively
7540 * "unlinking" our board from
7549 * It must be the last board in the list.
7560 * Given a board pointer, walks the config link, counting up
7561 * all ports user specified should be on the board.
7562 * (This does NOT mean they are all actually present right now tho)
7564 static uint dgap_config_get_num_prts(struct board_t *bd)
7567 struct cnode *p = NULL;
7572 for (p = bd->bd_config; p; p = p->next) {
7577 * check for pcxr types.
7579 if (p->u.board.type > EPCFE)
7580 count += p->u.board.nport;
7583 count += p->u.conc.nport;
7586 count += p->u.module.nport;
7593 static char *dgap_create_config_string(struct board_t *bd, char *string)
7596 struct cnode *p = NULL;
7597 struct cnode *q = NULL;
7605 for (p = bd->bd_config; p; p = p->next) {
7611 *ptr = p->u.line.speed;
7616 * Because the EPC/con concentrators can have EM modules
7617 * hanging off of them, we have to walk ahead in the
7618 * list and keep adding the number of ports on each EM
7619 * to the config. UGH!
7621 speed = p->u.conc.speed;
7623 if ((q != NULL) && (q->type == MNODE)) {
7624 *ptr = (p->u.conc.nport + 0x80);
7627 while ((q->next != NULL) &&
7628 (q->next->type) == MNODE) {
7630 *ptr = (q->u.module.nport + 0x80);
7635 *ptr = q->u.module.nport;
7638 *ptr = p->u.conc.nport;