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.
15 * You should have received a copy of the GNU General Public License
16 * along with this program; if not, write to the Free Software
17 * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
20 * NOTE TO LINUX KERNEL HACKERS: DO NOT REFORMAT THIS CODE!
22 * This is shared code between Digi's CVS archive and the
23 * Linux Kernel sources.
24 * Changing the source just for reformatting needlessly breaks
25 * our CVS diff history.
27 * Send any bug fixes/changes to: Eng.Linux at digi dot com.
33 * In the original out of kernel Digi dgap driver, firmware
34 * loading was done via user land to driver handshaking.
36 * For cards that support a concentrator (port expander),
37 * I believe the concentrator its self told the card which
38 * concentrator is actually attached and then that info
39 * was used to tell user land which concentrator firmware
40 * image was to be downloaded. I think even the BIOS or
41 * FEP images required could change with the connection
42 * of a particular concentrator.
44 * Since I have no access to any of these cards or
45 * concentrators, I cannot put the correct concentrator
46 * firmware file names into the firmware_info structure
47 * as is now done for the BIOS and FEP images.
49 * I think, but am not certain, that the cards supporting
50 * concentrators will function without them. So support
51 * of these cards has been left in this driver.
53 * In order to fully support those cards, they would
54 * either have to be acquired for dissection or maybe
55 * Digi International could provide some assistance.
57 #undef DIGI_CONCENTRATORS_SUPPORTED
59 #include <linux/kernel.h>
60 #include <linux/module.h>
61 #include <linux/pci.h>
62 #include <linux/delay.h> /* For udelay */
63 #include <linux/slab.h>
64 #include <linux/uaccess.h>
65 #include <linux/sched.h>
67 #include <linux/interrupt.h> /* For tasklet and interrupt structs/defines */
68 #include <linux/ctype.h>
69 #include <linux/tty.h>
70 #include <linux/tty_flip.h>
71 #include <linux/serial_reg.h>
72 #include <linux/io.h> /* For read[bwl]/write[bwl] */
74 #include <linux/string.h>
75 #include <linux/device.h>
76 #include <linux/kdev_t.h>
77 #include <linux/firmware.h>
81 #define init_MUTEX(sem) sema_init(sem, 1)
82 #define DECLARE_MUTEX(name) \
83 struct semaphore name = __SEMAPHORE_INITIALIZER(name, 1)
85 MODULE_LICENSE("GPL");
86 MODULE_AUTHOR("Digi International, http://www.digi.com");
87 MODULE_DESCRIPTION("Driver for the Digi International EPCA PCI based product line");
88 MODULE_SUPPORTED_DEVICE("dgap");
90 /**************************************************************************
92 * protos for this file
96 static int dgap_start(void);
97 static void dgap_init_globals(void);
98 static int dgap_found_board(struct pci_dev *pdev, int id);
99 static void dgap_cleanup_board(struct board_t *brd);
100 static void dgap_poll_handler(ulong dummy);
101 static int dgap_init_pci(void);
102 static int dgap_init_one(struct pci_dev *pdev, const struct pci_device_id *ent);
103 static void dgap_remove_one(struct pci_dev *dev);
104 static int dgap_probe1(struct pci_dev *pdev, int card_type);
105 static int dgap_do_remap(struct board_t *brd);
106 static irqreturn_t dgap_intr(int irq, void *voidbrd);
108 /* Our function prototypes */
109 static int dgap_tty_open(struct tty_struct *tty, struct file *file);
110 static void dgap_tty_close(struct tty_struct *tty, struct file *file);
111 static int dgap_block_til_ready(struct tty_struct *tty, struct file *file,
112 struct channel_t *ch);
113 static int dgap_tty_ioctl(struct tty_struct *tty, unsigned int cmd,
115 static int dgap_tty_digigeta(struct tty_struct *tty,
116 struct digi_t __user *retinfo);
117 static int dgap_tty_digiseta(struct tty_struct *tty,
118 struct digi_t __user *new_info);
119 static int dgap_tty_digigetedelay(struct tty_struct *tty, int __user *retinfo);
120 static int dgap_tty_digisetedelay(struct tty_struct *tty, int __user *new_info);
121 static int dgap_tty_write_room(struct tty_struct *tty);
122 static int dgap_tty_chars_in_buffer(struct tty_struct *tty);
123 static void dgap_tty_start(struct tty_struct *tty);
124 static void dgap_tty_stop(struct tty_struct *tty);
125 static void dgap_tty_throttle(struct tty_struct *tty);
126 static void dgap_tty_unthrottle(struct tty_struct *tty);
127 static void dgap_tty_flush_chars(struct tty_struct *tty);
128 static void dgap_tty_flush_buffer(struct tty_struct *tty);
129 static void dgap_tty_hangup(struct tty_struct *tty);
130 static int dgap_wait_for_drain(struct tty_struct *tty);
131 static int dgap_set_modem_info(struct tty_struct *tty, unsigned int command,
132 unsigned int __user *value);
133 static int dgap_get_modem_info(struct channel_t *ch,
134 unsigned int __user *value);
135 static int dgap_tty_digisetcustombaud(struct tty_struct *tty,
136 int __user *new_info);
137 static int dgap_tty_digigetcustombaud(struct tty_struct *tty,
138 int __user *retinfo);
139 static int dgap_tty_tiocmget(struct tty_struct *tty);
140 static int dgap_tty_tiocmset(struct tty_struct *tty, unsigned int set,
142 static int dgap_tty_send_break(struct tty_struct *tty, int msec);
143 static void dgap_tty_wait_until_sent(struct tty_struct *tty, int timeout);
144 static int dgap_tty_write(struct tty_struct *tty, const unsigned char *buf,
146 static void dgap_tty_set_termios(struct tty_struct *tty,
147 struct ktermios *old_termios);
148 static int dgap_tty_put_char(struct tty_struct *tty, unsigned char c);
149 static void dgap_tty_send_xchar(struct tty_struct *tty, char ch);
151 static int dgap_tty_register(struct board_t *brd);
152 static int dgap_tty_init(struct board_t *);
153 static void dgap_tty_uninit(struct board_t *);
154 static void dgap_carrier(struct channel_t *ch);
155 static void dgap_input(struct channel_t *ch);
158 * Our function prototypes from dgap_fep5
160 static void dgap_cmdw_ext(struct channel_t *ch, u16 cmd, u16 word, uint ncmds);
161 static int dgap_event(struct board_t *bd);
163 static void dgap_poll_tasklet(unsigned long data);
164 static void dgap_cmdb(struct channel_t *ch, uchar cmd, uchar byte1,
165 uchar byte2, uint ncmds);
166 static void dgap_cmdw(struct channel_t *ch, uchar cmd, u16 word, uint ncmds);
167 static void dgap_wmove(struct channel_t *ch, char *buf, uint cnt);
168 static int dgap_param(struct tty_struct *tty);
169 static void dgap_parity_scan(struct channel_t *ch, unsigned char *cbuf,
170 unsigned char *fbuf, int *len);
171 static uint dgap_get_custom_baud(struct channel_t *ch);
172 static void dgap_firmware_reset_port(struct channel_t *ch);
175 * Function prototypes from dgap_parse.c.
177 static int dgap_gettok(char **in, struct cnode *p);
178 static char *dgap_getword(char **in);
179 static char *dgap_savestring(char *s);
180 static struct cnode *dgap_newnode(int t);
181 static int dgap_checknode(struct cnode *p);
182 static void dgap_err(char *s);
185 * Function prototypes from dgap_sysfs.h
193 static void dgap_create_ports_sysfiles(struct board_t *bd);
194 static void dgap_remove_ports_sysfiles(struct board_t *bd);
196 static int dgap_create_driver_sysfiles(struct pci_driver *);
197 static void dgap_remove_driver_sysfiles(struct pci_driver *);
199 static void dgap_create_tty_sysfs(struct un_t *un, struct device *c);
200 static void dgap_remove_tty_sysfs(struct device *c);
203 * Function prototypes from dgap_parse.h
205 static int dgap_parsefile(char **in, int Remove);
206 static struct cnode *dgap_find_config(int type, int bus, int slot);
207 static uint dgap_config_get_num_prts(struct board_t *bd);
208 static char *dgap_create_config_string(struct board_t *bd, char *string);
209 static uint dgap_config_get_useintr(struct board_t *bd);
210 static uint dgap_config_get_altpin(struct board_t *bd);
212 static int dgap_ms_sleep(ulong ms);
213 static void dgap_do_bios_load(struct board_t *brd, const uchar *ubios, int len);
214 static void dgap_do_fep_load(struct board_t *brd, const uchar *ufep, int len);
215 #ifdef DIGI_CONCENTRATORS_SUPPORTED
216 static void dgap_do_conc_load(struct board_t *brd, uchar *uaddr, int len);
218 static int dgap_after_config_loaded(int board);
219 static int dgap_finalize_board_init(struct board_t *brd);
221 static void dgap_get_vpd(struct board_t *brd);
222 static void dgap_do_reset_board(struct board_t *brd);
223 static int dgap_do_wait_for_bios(struct board_t *brd);
224 static int dgap_do_wait_for_fep(struct board_t *brd);
225 static int dgap_tty_register_ports(struct board_t *brd);
226 static int dgap_firmware_load(struct pci_dev *pdev, int card_type);
228 /* Driver unload function */
229 static void dgap_cleanup_module(void);
231 module_exit(dgap_cleanup_module);
234 * File operations permitted on Control/Management major.
236 static const struct file_operations DgapBoardFops = {
237 .owner = THIS_MODULE,
243 static uint dgap_NumBoards;
244 static struct board_t *dgap_Board[MAXBOARDS];
245 static ulong dgap_poll_counter;
246 static char *dgap_config_buf;
247 static int dgap_driver_state = DRIVER_INITIALIZED;
248 DEFINE_SPINLOCK(dgap_dl_lock);
249 static wait_queue_head_t dgap_dl_wait;
250 static int dgap_dl_action;
251 static int dgap_poll_tick = 20; /* Poll interval - 20 ms */
256 static struct class *dgap_class;
258 static struct board_t *dgap_BoardsByMajor[256];
259 static uint dgap_count = 500;
264 DEFINE_SPINLOCK(dgap_poll_lock); /* Poll scheduling lock */
265 static ulong dgap_poll_time; /* Time of next poll */
266 static uint dgap_poll_stop; /* Used to tell poller to stop */
267 static struct timer_list dgap_poll_timer;
272 Card Model Number of Ports Interface
273 ----------------------------------------------------------------
274 Acceleport Xem 4 - 64 (EIA232 & EIA422)
275 Acceleport Xr 4 & 8 (EIA232)
276 Acceleport Xr 920 4 & 8 (EIA232)
277 Acceleport C/X 8 - 128 (EIA232)
278 Acceleport EPC/X 8 - 224 (EIA232)
279 Acceleport Xr/422 4 & 8 (EIA422)
280 Acceleport 2r/920 2 (EIA232)
281 Acceleport 4r/920 4 (EIA232)
282 Acceleport 8r/920 8 (EIA232)
284 IBM 8-Port Asynchronous PCI Adapter (EIA232)
285 IBM 128-Port Asynchronous PCI Adapter (EIA232 & EIA422)
288 static struct pci_device_id dgap_pci_tbl[] = {
289 { DIGI_VID, PCI_DEV_XEM_DID, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0 },
290 { DIGI_VID, PCI_DEV_CX_DID, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 1 },
291 { DIGI_VID, PCI_DEV_CX_IBM_DID, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 2 },
292 { DIGI_VID, PCI_DEV_EPCJ_DID, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 3 },
293 { DIGI_VID, PCI_DEV_920_2_DID, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 4 },
294 { DIGI_VID, PCI_DEV_920_4_DID, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 5 },
295 { DIGI_VID, PCI_DEV_920_8_DID, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 6 },
296 { DIGI_VID, PCI_DEV_XR_DID, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 7 },
297 { DIGI_VID, PCI_DEV_XRJ_DID, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 8 },
298 { DIGI_VID, PCI_DEV_XR_422_DID, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 9 },
299 { DIGI_VID, PCI_DEV_XR_IBM_DID, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 10 },
300 { DIGI_VID, PCI_DEV_XR_SAIP_DID, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 11 },
301 { DIGI_VID, PCI_DEV_XR_BULL_DID, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 12 },
302 { DIGI_VID, PCI_DEV_920_8_HP_DID, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 13 },
303 { DIGI_VID, PCI_DEV_XEM_HP_DID, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 14 },
304 {0,} /* 0 terminated list. */
306 MODULE_DEVICE_TABLE(pci, dgap_pci_tbl);
309 * A generic list of Product names, PCI Vendor ID, and PCI Device ID.
318 static struct board_id dgap_Ids[] = {
319 { PPCM, PCI_DEV_XEM_NAME, 64, (T_PCXM|T_PCLITE|T_PCIBUS) },
320 { PCX, PCI_DEV_CX_NAME, 128, (T_CX|T_PCIBUS) },
321 { PCX, PCI_DEV_CX_IBM_NAME, 128, (T_CX|T_PCIBUS) },
322 { PEPC, PCI_DEV_EPCJ_NAME, 224, (T_EPC|T_PCIBUS) },
323 { APORT2_920P, PCI_DEV_920_2_NAME, 2, (T_PCXR|T_PCLITE|T_PCIBUS) },
324 { APORT4_920P, PCI_DEV_920_4_NAME, 4, (T_PCXR|T_PCLITE|T_PCIBUS) },
325 { APORT8_920P, PCI_DEV_920_8_NAME, 8, (T_PCXR|T_PCLITE|T_PCIBUS) },
326 { PAPORT8, PCI_DEV_XR_NAME, 8, (T_PCXR|T_PCLITE|T_PCIBUS) },
327 { PAPORT8, PCI_DEV_XRJ_NAME, 8, (T_PCXR|T_PCLITE|T_PCIBUS) },
328 { PAPORT8, PCI_DEV_XR_422_NAME, 8, (T_PCXR|T_PCLITE|T_PCIBUS) },
329 { PAPORT8, PCI_DEV_XR_IBM_NAME, 8, (T_PCXR|T_PCLITE|T_PCIBUS) },
330 { PAPORT8, PCI_DEV_XR_SAIP_NAME, 8, (T_PCXR|T_PCLITE|T_PCIBUS) },
331 { PAPORT8, PCI_DEV_XR_BULL_NAME, 8, (T_PCXR|T_PCLITE|T_PCIBUS) },
332 { APORT8_920P, PCI_DEV_920_8_HP_NAME, 8, (T_PCXR|T_PCLITE|T_PCIBUS) },
333 { PPCM, PCI_DEV_XEM_HP_NAME, 64, (T_PCXM|T_PCLITE|T_PCIBUS) },
334 {0,} /* 0 terminated list. */
337 static struct pci_driver dgap_driver = {
339 .probe = dgap_init_one,
340 .id_table = dgap_pci_tbl,
341 .remove = dgap_remove_one,
344 struct firmware_info {
345 uchar *conf_name; /* dgap.conf */
346 uchar *bios_name; /* BIOS filename */
347 uchar *fep_name; /* FEP filename */
348 uchar *con_name; /* Concentrator filename FIXME*/
349 int num; /* sequence number */
353 * Firmware - BIOS, FEP, and CONC filenames
355 static struct firmware_info fw_info[] = {
356 { "dgap/dgap.conf", "dgap/sxbios.bin", "dgap/sxfep.bin", 0, 0 },
357 { "dgap/dgap.conf", "dgap/cxpbios.bin", "dgap/cxpfep.bin", 0, 1 },
358 { "dgap/dgap.conf", "dgap/cxpbios.bin", "dgap/cxpfep.bin", 0, 2 },
359 { "dgap/dgap.conf", "dgap/pcibios.bin", "dgap/pcifep.bin", 0, 3 },
360 { "dgap/dgap.conf", "dgap/xrbios.bin", "dgap/xrfep.bin", 0, 4 },
361 { "dgap/dgap.conf", "dgap/xrbios.bin", "dgap/xrfep.bin", 0, 5 },
362 { "dgap/dgap.conf", "dgap/xrbios.bin", "dgap/xrfep.bin", 0, 6 },
363 { "dgap/dgap.conf", "dgap/xrbios.bin", "dgap/xrfep.bin", 0, 7 },
364 { "dgap/dgap.conf", "dgap/xrbios.bin", "dgap/xrfep.bin", 0, 8 },
365 { "dgap/dgap.conf", "dgap/xrbios.bin", "dgap/xrfep.bin", 0, 9 },
366 { "dgap/dgap.conf", "dgap/xrbios.bin", "dgap/xrfep.bin", 0, 10 },
367 { "dgap/dgap.conf", "dgap/xrbios.bin", "dgap/xrfep.bin", 0, 11 },
368 { "dgap/dgap.conf", "dgap/xrbios.bin", "dgap/xrfep.bin", 0, 12 },
369 { "dgap/dgap.conf", "dgap/xrbios.bin", "dgap/xrfep.bin", 0, 13 },
370 { "dgap/dgap.conf", "dgap/sxbios.bin", "dgap/sxfep.bin", 0, 14 },
375 * Default transparent print information.
377 static struct digi_t dgap_digi_init = {
378 .digi_flags = DIGI_COOK, /* Flags */
379 .digi_maxcps = 100, /* Max CPS */
380 .digi_maxchar = 50, /* Max chars in print queue */
381 .digi_bufsize = 100, /* Printer buffer size */
382 .digi_onlen = 4, /* size of printer on string */
383 .digi_offlen = 4, /* size of printer off string */
384 .digi_onstr = "\033[5i", /* ANSI printer on string ] */
385 .digi_offstr = "\033[4i", /* ANSI printer off string ] */
386 .digi_term = "ansi" /* default terminal type */
390 * Define a local default termios struct. All ports will be created
391 * with this termios initially.
393 * This defines a raw port at 9600 baud, 8 data bits, no parity,
397 static struct ktermios DgapDefaultTermios = {
398 .c_iflag = (DEFAULT_IFLAGS), /* iflags */
399 .c_oflag = (DEFAULT_OFLAGS), /* oflags */
400 .c_cflag = (DEFAULT_CFLAGS), /* cflags */
401 .c_lflag = (DEFAULT_LFLAGS), /* lflags */
406 static const struct tty_operations dgap_tty_ops = {
407 .open = dgap_tty_open,
408 .close = dgap_tty_close,
409 .write = dgap_tty_write,
410 .write_room = dgap_tty_write_room,
411 .flush_buffer = dgap_tty_flush_buffer,
412 .chars_in_buffer = dgap_tty_chars_in_buffer,
413 .flush_chars = dgap_tty_flush_chars,
414 .ioctl = dgap_tty_ioctl,
415 .set_termios = dgap_tty_set_termios,
416 .stop = dgap_tty_stop,
417 .start = dgap_tty_start,
418 .throttle = dgap_tty_throttle,
419 .unthrottle = dgap_tty_unthrottle,
420 .hangup = dgap_tty_hangup,
421 .put_char = dgap_tty_put_char,
422 .tiocmget = dgap_tty_tiocmget,
423 .tiocmset = dgap_tty_tiocmset,
424 .break_ctl = dgap_tty_send_break,
425 .wait_until_sent = dgap_tty_wait_until_sent,
426 .send_xchar = dgap_tty_send_xchar
430 * Our needed internal static variables from dgap_parse.c
432 static struct cnode dgap_head;
434 static char dgap_cword[MAXCWORD];
441 static struct toklist dgap_tlist[] = {
442 { BEGIN, "config_begin" },
443 { END, "config_end" },
445 { PCX, "Digi_AccelePort_C/X_PCI" },
446 { PEPC, "Digi_AccelePort_EPC/X_PCI" },
447 { PPCM, "Digi_AccelePort_Xem_PCI" },
448 { APORT2_920P, "Digi_AccelePort_2r_920_PCI" },
449 { APORT4_920P, "Digi_AccelePort_4r_920_PCI" },
450 { APORT8_920P, "Digi_AccelePort_8r_920_PCI" },
451 { PAPORT4, "Digi_AccelePort_4r_PCI(EIA-232/RS-422)" },
452 { PAPORT8, "Digi_AccelePort_8r_PCI(EIA-232/RS-422)" },
454 { PCIINFO, "pciinfo" },
457 { CONC, "concentrator" },
467 { CONNECT, "connect" },
468 { METHOD, "method" },
469 { STATUS, "status" },
470 { CUSTOM, "Custom" },
476 { NPORTS, "nports" },
481 { ALTPIN, "altpin" },
482 { USEINTR, "useintr" },
483 { TTSIZ, "ttysize" },
485 { BSSIZ, "boardsize" },
486 { UNTSIZ, "schedsize" },
487 { F2SIZ, "f2200size" },
488 { VPSIZ, "vpixsize" },
492 /************************************************************************
494 * Driver load/unload functions
496 ************************************************************************/
501 * Module load. This is where it all starts.
503 static int dgap_init_module(void)
507 pr_info("%s, Digi International Part Number %s\n", DG_NAME, DG_PART);
513 rc = dgap_init_pci();
517 rc = dgap_create_driver_sysfiles(&dgap_driver);
521 dgap_driver_state = DRIVER_READY;
527 dgap_cleanup_module();
531 module_init(dgap_init_module);
536 static int dgap_start(void)
540 struct device *device;
543 * make sure that the globals are
544 * init'd before we do anything else
550 pr_info("For the tools package please visit http://www.digi.com\n");
553 * Register our base character device into the kernel.
557 * Register management/dpa devices
559 rc = register_chrdev(DIGI_DGAP_MAJOR, "dgap", &DgapBoardFops);
563 dgap_class = class_create(THIS_MODULE, "dgap_mgmt");
564 if (IS_ERR(dgap_class)) {
565 rc = PTR_ERR(dgap_class);
569 device = device_create(dgap_class, NULL,
570 MKDEV(DIGI_DGAP_MAJOR, 0),
572 if (IS_ERR(device)) {
573 rc = PTR_ERR(device);
577 /* Start the poller */
578 spin_lock_irqsave(&dgap_poll_lock, flags);
579 init_timer(&dgap_poll_timer);
580 dgap_poll_timer.function = dgap_poll_handler;
581 dgap_poll_timer.data = 0;
582 dgap_poll_time = jiffies + dgap_jiffies_from_ms(dgap_poll_tick);
583 dgap_poll_timer.expires = dgap_poll_time;
584 spin_unlock_irqrestore(&dgap_poll_lock, flags);
586 add_timer(&dgap_poll_timer);
591 class_destroy(dgap_class);
593 unregister_chrdev(DIGI_DGAP_MAJOR, "dgap");
598 * Register pci driver, and return how many boards we have.
600 static int dgap_init_pci(void)
602 return pci_register_driver(&dgap_driver);
605 /* returns count (>= 0), or negative on error */
606 static int dgap_init_one(struct pci_dev *pdev, const struct pci_device_id *ent)
610 /* wake up and enable device */
611 rc = pci_enable_device(pdev);
616 rc = dgap_probe1(pdev, ent->driver_data);
619 rc = dgap_firmware_load(pdev, ent->driver_data);
625 static int dgap_probe1(struct pci_dev *pdev, int card_type)
627 return dgap_found_board(pdev, card_type);
630 static void dgap_remove_one(struct pci_dev *dev)
636 * dgap_cleanup_module()
638 * Module unload. This is where it all ends.
640 static void dgap_cleanup_module(void)
645 spin_lock_irqsave(&dgap_poll_lock, lock_flags);
647 spin_unlock_irqrestore(&dgap_poll_lock, lock_flags);
649 /* Turn off poller right away. */
650 del_timer_sync(&dgap_poll_timer);
652 dgap_remove_driver_sysfiles(&dgap_driver);
654 device_destroy(dgap_class, MKDEV(DIGI_DGAP_MAJOR, 0));
655 class_destroy(dgap_class);
656 unregister_chrdev(DIGI_DGAP_MAJOR, "dgap");
658 kfree(dgap_config_buf);
660 for (i = 0; i < dgap_NumBoards; ++i) {
661 dgap_remove_ports_sysfiles(dgap_Board[i]);
662 dgap_tty_uninit(dgap_Board[i]);
663 dgap_cleanup_board(dgap_Board[i]);
667 pci_unregister_driver(&dgap_driver);
671 * dgap_cleanup_board()
673 * Free all the memory associated with a board
675 static void dgap_cleanup_board(struct board_t *brd)
679 if (!brd || brd->magic != DGAP_BOARD_MAGIC)
682 if (brd->intr_used && brd->irq)
683 free_irq(brd->irq, brd);
685 tasklet_kill(&brd->helper_tasklet);
687 if (brd->re_map_port) {
688 release_mem_region(brd->membase + 0x200000, 0x200000);
689 iounmap(brd->re_map_port);
690 brd->re_map_port = NULL;
693 if (brd->re_map_membase) {
694 release_mem_region(brd->membase, 0x200000);
695 iounmap(brd->re_map_membase);
696 brd->re_map_membase = NULL;
699 /* Free all allocated channels structs */
700 for (i = 0; i < MAXPORTS ; i++)
701 kfree(brd->channels[i]);
704 kfree(brd->flipflagbuf);
706 dgap_Board[brd->boardnum] = NULL;
714 * A board has been found, init it.
716 static int dgap_found_board(struct pci_dev *pdev, int id)
719 unsigned int pci_irq;
722 /* get the board structure and prep it */
723 brd = kzalloc(sizeof(struct board_t), GFP_KERNEL);
727 dgap_Board[dgap_NumBoards] = brd;
729 /* store the info for the board we've found */
730 brd->magic = DGAP_BOARD_MAGIC;
731 brd->boardnum = dgap_NumBoards;
733 brd->vendor = dgap_pci_tbl[id].vendor;
734 brd->device = dgap_pci_tbl[id].device;
736 brd->pci_bus = pdev->bus->number;
737 brd->pci_slot = PCI_SLOT(pdev->devfn);
738 brd->name = dgap_Ids[id].name;
739 brd->maxports = dgap_Ids[id].maxports;
740 brd->type = dgap_Ids[id].config_type;
741 brd->dpatype = dgap_Ids[id].dpatype;
742 brd->dpastatus = BD_NOFEP;
743 init_waitqueue_head(&brd->state_wait);
745 spin_lock_init(&brd->bd_lock);
748 brd->inhibit_poller = FALSE;
749 brd->wait_for_bios = 0;
750 brd->wait_for_fep = 0;
752 for (i = 0; i < MAXPORTS; i++)
753 brd->channels[i] = NULL;
755 /* store which card & revision we have */
756 pci_read_config_word(pdev, PCI_SUBSYSTEM_VENDOR_ID, &brd->subvendor);
757 pci_read_config_word(pdev, PCI_SUBSYSTEM_ID, &brd->subdevice);
758 pci_read_config_byte(pdev, PCI_REVISION_ID, &brd->rev);
763 /* get the PCI Base Address Registers */
765 /* Xr Jupiter and EPC use BAR 2 */
766 if (brd->device == PCI_DEV_XRJ_DID || brd->device == PCI_DEV_EPCJ_DID) {
767 brd->membase = pci_resource_start(pdev, 2);
768 brd->membase_end = pci_resource_end(pdev, 2);
770 /* Everyone else uses BAR 0 */
772 brd->membase = pci_resource_start(pdev, 0);
773 brd->membase_end = pci_resource_end(pdev, 0);
779 if (brd->membase & 1)
785 * On the PCI boards, there is no IO space allocated
786 * The I/O registers will be in the first 3 bytes of the
787 * upper 2MB of the 4MB memory space. The board memory
788 * will be mapped into the low 2MB of the 4MB memory space
790 brd->port = brd->membase + PCI_IO_OFFSET;
791 brd->port_end = brd->port + PCI_IO_SIZE;
794 * Special initialization for non-PLX boards
796 if (brd->device != PCI_DEV_XRJ_DID && brd->device != PCI_DEV_EPCJ_DID) {
799 pci_write_config_byte(pdev, 0x40, 0);
800 pci_write_config_byte(pdev, 0x46, 0);
802 /* Limit burst length to 2 doubleword transactions */
803 pci_write_config_byte(pdev, 0x42, 1);
806 * Enable IO and mem if not already done.
807 * This was needed for support on Itanium.
809 pci_read_config_word(pdev, PCI_COMMAND, &cmd);
810 cmd |= (PCI_COMMAND_IO | PCI_COMMAND_MEMORY);
811 pci_write_config_word(pdev, PCI_COMMAND, cmd);
814 /* init our poll helper tasklet */
815 tasklet_init(&brd->helper_tasklet, dgap_poll_tasklet,
816 (unsigned long) brd);
818 i = dgap_do_remap(brd);
820 brd->state = BOARD_FAILED;
822 pr_info("dgap: board %d: %s (rev %d), irq %ld, %s\n",
823 dgap_NumBoards, brd->name, brd->rev, brd->irq,
824 brd->state ? "NOT READY\0" : "READY\0");
830 static int dgap_finalize_board_init(struct board_t *brd)
834 if (!brd || brd->magic != DGAP_BOARD_MAGIC)
837 brd->use_interrupts = dgap_config_get_useintr(brd);
840 * Set up our interrupt handler if we are set to do interrupts.
842 if (brd->use_interrupts && brd->irq) {
844 rc = request_irq(brd->irq, dgap_intr, IRQF_SHARED, "DGAP", brd);
857 static int dgap_firmware_load(struct pci_dev *pdev, int card_type)
859 struct board_t *brd = dgap_Board[dgap_NumBoards - 1];
860 const struct firmware *fw;
864 dgap_do_reset_board(brd);
866 if (fw_info[card_type].conf_name) {
867 ret = request_firmware(&fw, fw_info[card_type].conf_name,
870 pr_err("dgap: config file %s not found\n",
871 fw_info[card_type].conf_name);
874 if (!dgap_config_buf) {
875 dgap_config_buf = kmalloc(fw->size + 1, GFP_ATOMIC);
876 if (!dgap_config_buf) {
877 release_firmware(fw);
882 memcpy(dgap_config_buf, fw->data, fw->size);
883 release_firmware(fw);
884 dgap_config_buf[fw->size + 1] = '\0';
886 if (dgap_parsefile(&dgap_config_buf, TRUE) != 0)
890 ret = dgap_after_config_loaded(brd->boardnum);
894 * Match this board to a config the user created for us.
897 dgap_find_config(brd->type, brd->pci_bus, brd->pci_slot);
900 * Because the 4 port Xr products share the same PCI ID
901 * as the 8 port Xr products, if we receive a NULL config
902 * back, and this is a PAPORT8 board, retry with a
903 * PAPORT4 attempt as well.
905 if (brd->type == PAPORT8 && !brd->bd_config)
907 dgap_find_config(PAPORT4, brd->pci_bus, brd->pci_slot);
909 if (!brd->bd_config) {
910 pr_err("dgap: No valid configuration found\n");
914 dgap_tty_register(brd);
915 dgap_finalize_board_init(brd);
917 if (fw_info[card_type].bios_name) {
918 ret = request_firmware(&fw, fw_info[card_type].bios_name,
921 pr_err("dgap: bios file %s not found\n",
922 fw_info[card_type].bios_name);
925 dgap_do_bios_load(brd, fw->data, fw->size);
926 release_firmware(fw);
928 /* Wait for BIOS to test board... */
929 if (!dgap_do_wait_for_bios(brd))
933 if (fw_info[card_type].fep_name) {
934 ret = request_firmware(&fw, fw_info[card_type].fep_name,
937 pr_err("dgap: fep file %s not found\n",
938 fw_info[card_type].fep_name);
941 dgap_do_fep_load(brd, fw->data, fw->size);
942 release_firmware(fw);
944 /* Wait for FEP to load on board... */
945 if (!dgap_do_wait_for_fep(brd))
949 #ifdef DIGI_CONCENTRATORS_SUPPORTED
951 * If this is a CX or EPCX, we need to see if the firmware
952 * is requesting a concentrator image from us.
954 if ((bd->type == PCX) || (bd->type == PEPC)) {
955 chk_addr = (u16 *) (vaddr + DOWNREQ);
956 /* Nonzero if FEP is requesting concentrator image. */
957 check = readw(chk_addr);
958 vaddr = brd->re_map_membase;
961 if (fw_info[card_type].con_name && check && vaddr) {
962 ret = request_firmware(&fw, fw_info[card_type].con_name,
965 pr_err("dgap: conc file %s not found\n",
966 fw_info[card_type].con_name);
969 /* Put concentrator firmware loading code here */
970 offset = readw((u16 *) (vaddr + DOWNREQ));
971 memcpy_toio(offset, fw->data, fw->size);
973 dgap_do_conc_load(brd, (char *)fw->data, fw->size)
974 release_firmware(fw);
978 * Do tty device initialization.
980 ret = dgap_tty_init(brd);
982 dgap_tty_uninit(brd);
986 ret = dgap_tty_register_ports(brd);
990 brd->state = BOARD_READY;
991 brd->dpastatus = BD_RUNNING;
999 static int dgap_do_remap(struct board_t *brd)
1001 if (!brd || brd->magic != DGAP_BOARD_MAGIC)
1004 if (!request_mem_region(brd->membase, 0x200000, "dgap"))
1007 if (!request_mem_region(brd->membase + PCI_IO_OFFSET, 0x200000,
1009 release_mem_region(brd->membase, 0x200000);
1013 brd->re_map_membase = ioremap(brd->membase, 0x200000);
1014 if (!brd->re_map_membase) {
1015 release_mem_region(brd->membase, 0x200000);
1016 release_mem_region(brd->membase + PCI_IO_OFFSET, 0x200000);
1020 brd->re_map_port = ioremap((brd->membase + PCI_IO_OFFSET), 0x200000);
1021 if (!brd->re_map_port) {
1022 release_mem_region(brd->membase, 0x200000);
1023 release_mem_region(brd->membase + PCI_IO_OFFSET, 0x200000);
1024 iounmap(brd->re_map_membase);
1031 /*****************************************************************************
1051 * As each timer expires, it determines (a) whether the "transmit"
1052 * waiter needs to be woken up, and (b) whether the poller needs to
1055 ******************************************************************************/
1057 static void dgap_poll_handler(ulong dummy)
1060 struct board_t *brd;
1061 unsigned long lock_flags;
1064 dgap_poll_counter++;
1067 * Do not start the board state machine until
1068 * driver tells us its up and running, and has
1069 * everything it needs.
1071 if (dgap_driver_state != DRIVER_READY)
1072 goto schedule_poller;
1075 * If we have just 1 board, or the system is not SMP,
1076 * then use the typical old style poller.
1077 * Otherwise, use our new tasklet based poller, which should
1078 * speed things up for multiple boards.
1080 if ((dgap_NumBoards == 1) || (num_online_cpus() <= 1)) {
1081 for (i = 0; i < dgap_NumBoards; i++) {
1083 brd = dgap_Board[i];
1085 if (brd->state == BOARD_FAILED)
1087 if (!brd->intr_running)
1088 /* Call the real board poller directly */
1089 dgap_poll_tasklet((unsigned long) brd);
1093 * Go thru each board, kicking off a
1094 * tasklet for each if needed
1096 for (i = 0; i < dgap_NumBoards; i++) {
1097 brd = dgap_Board[i];
1100 * Attempt to grab the board lock.
1102 * If we can't get it, no big deal, the next poll
1103 * will get it. Basically, I just really don't want
1104 * to spin in here, because I want to kick off my
1105 * tasklets as fast as I can, and then get out the
1108 if (!spin_trylock(&brd->bd_lock))
1112 * If board is in a failed state, don't bother
1113 * scheduling a tasklet
1115 if (brd->state == BOARD_FAILED) {
1116 spin_unlock(&brd->bd_lock);
1120 /* Schedule a poll helper task */
1121 if (!brd->intr_running)
1122 tasklet_schedule(&brd->helper_tasklet);
1125 * Can't do DGAP_UNLOCK here, as we don't have
1126 * lock_flags because we did a trylock above.
1128 spin_unlock(&brd->bd_lock);
1135 * Schedule ourself back at the nominal wakeup interval.
1137 spin_lock_irqsave(&dgap_poll_lock, lock_flags);
1138 dgap_poll_time += dgap_jiffies_from_ms(dgap_poll_tick);
1140 new_time = dgap_poll_time - jiffies;
1142 if ((ulong) new_time >= 2 * dgap_poll_tick) {
1144 jiffies + dgap_jiffies_from_ms(dgap_poll_tick);
1147 dgap_poll_timer.function = dgap_poll_handler;
1148 dgap_poll_timer.data = 0;
1149 dgap_poll_timer.expires = dgap_poll_time;
1150 spin_unlock_irqrestore(&dgap_poll_lock, lock_flags);
1152 if (!dgap_poll_stop)
1153 add_timer(&dgap_poll_timer);
1159 * Driver interrupt handler.
1161 static irqreturn_t dgap_intr(int irq, void *voidbrd)
1163 struct board_t *brd = (struct board_t *) voidbrd;
1169 * Check to make sure its for us.
1171 if (brd->magic != DGAP_BOARD_MAGIC)
1177 * Schedule tasklet to run at a better time.
1179 tasklet_schedule(&brd->helper_tasklet);
1184 * dgap_init_globals()
1186 * This is where we initialize the globals from the static insmod
1187 * configuration variables. These are declared near the head of
1190 static void dgap_init_globals(void)
1194 for (i = 0; i < MAXBOARDS; i++)
1195 dgap_Board[i] = NULL;
1197 init_timer(&dgap_poll_timer);
1199 init_waitqueue_head(&dgap_dl_wait);
1203 /************************************************************************
1207 ************************************************************************/
1212 * Put the driver to sleep for x ms's
1214 * Returns 0 if timed out, !0 (showing signal) if interrupted by a signal.
1216 static int dgap_ms_sleep(ulong ms)
1218 current->state = TASK_INTERRUPTIBLE;
1219 schedule_timeout((ms * HZ) / 1000);
1220 return signal_pending(current);
1223 /************************************************************************
1225 * TTY Initialization/Cleanup Functions
1227 ************************************************************************/
1230 * dgap_tty_register()
1232 * Init the tty subsystem for this board.
1234 static int dgap_tty_register(struct board_t *brd)
1238 brd->SerialDriver = alloc_tty_driver(MAXPORTS);
1240 snprintf(brd->SerialName, MAXTTYNAMELEN, "tty_dgap_%d_", brd->boardnum);
1241 brd->SerialDriver->name = brd->SerialName;
1242 brd->SerialDriver->name_base = 0;
1243 brd->SerialDriver->major = 0;
1244 brd->SerialDriver->minor_start = 0;
1245 brd->SerialDriver->type = TTY_DRIVER_TYPE_SERIAL;
1246 brd->SerialDriver->subtype = SERIAL_TYPE_NORMAL;
1247 brd->SerialDriver->init_termios = DgapDefaultTermios;
1248 brd->SerialDriver->driver_name = DRVSTR;
1249 brd->SerialDriver->flags = (TTY_DRIVER_REAL_RAW |
1250 TTY_DRIVER_DYNAMIC_DEV |
1251 TTY_DRIVER_HARDWARE_BREAK);
1253 /* The kernel wants space to store pointers to tty_structs */
1254 brd->SerialDriver->ttys =
1255 kzalloc(MAXPORTS * sizeof(struct tty_struct *), GFP_KERNEL);
1256 if (!brd->SerialDriver->ttys)
1260 * Entry points for driver. Called by the kernel from
1261 * tty_io.c and n_tty.c.
1263 tty_set_operations(brd->SerialDriver, &dgap_tty_ops);
1266 * If we're doing transparent print, we have to do all of the above
1267 * again, separately so we don't get the LD confused about what major
1268 * we are when we get into the dgap_tty_open() routine.
1270 brd->PrintDriver = alloc_tty_driver(MAXPORTS);
1272 snprintf(brd->PrintName, MAXTTYNAMELEN, "pr_dgap_%d_", brd->boardnum);
1273 brd->PrintDriver->name = brd->PrintName;
1274 brd->PrintDriver->name_base = 0;
1275 brd->PrintDriver->major = 0;
1276 brd->PrintDriver->minor_start = 0;
1277 brd->PrintDriver->type = TTY_DRIVER_TYPE_SERIAL;
1278 brd->PrintDriver->subtype = SERIAL_TYPE_NORMAL;
1279 brd->PrintDriver->init_termios = DgapDefaultTermios;
1280 brd->PrintDriver->driver_name = DRVSTR;
1281 brd->PrintDriver->flags = (TTY_DRIVER_REAL_RAW |
1282 TTY_DRIVER_DYNAMIC_DEV |
1283 TTY_DRIVER_HARDWARE_BREAK);
1285 /* The kernel wants space to store pointers to tty_structs */
1286 brd->PrintDriver->ttys =
1287 kzalloc(MAXPORTS * sizeof(struct tty_struct *), GFP_KERNEL);
1288 if (!brd->PrintDriver->ttys)
1292 * Entry points for driver. Called by the kernel from
1293 * tty_io.c and n_tty.c.
1295 tty_set_operations(brd->PrintDriver, &dgap_tty_ops);
1297 if (!brd->dgap_Major_Serial_Registered) {
1298 /* Register tty devices */
1299 rc = tty_register_driver(brd->SerialDriver);
1302 brd->dgap_Major_Serial_Registered = TRUE;
1303 dgap_BoardsByMajor[brd->SerialDriver->major] = brd;
1304 brd->dgap_Serial_Major = brd->SerialDriver->major;
1307 if (!brd->dgap_Major_TransparentPrint_Registered) {
1308 /* Register Transparent Print devices */
1309 rc = tty_register_driver(brd->PrintDriver);
1312 brd->dgap_Major_TransparentPrint_Registered = TRUE;
1313 dgap_BoardsByMajor[brd->PrintDriver->major] = brd;
1314 brd->dgap_TransparentPrint_Major = brd->PrintDriver->major;
1323 * Init the tty subsystem. Called once per board after board has been
1324 * downloaded and init'ed.
1326 static int dgap_tty_init(struct board_t *brd)
1330 uint true_count = 0;
1333 struct channel_t *ch;
1341 * Initialize board structure elements.
1344 vaddr = brd->re_map_membase;
1345 true_count = readw((vaddr + NCHAN));
1347 brd->nasync = dgap_config_get_num_prts(brd);
1350 brd->nasync = brd->maxports;
1352 if (brd->nasync > brd->maxports)
1353 brd->nasync = brd->maxports;
1355 if (true_count != brd->nasync) {
1356 if ((brd->type == PPCM) && (true_count == 64)) {
1357 pr_warn("dgap: %s configured for %d ports, has %d ports.\n",
1358 brd->name, brd->nasync, true_count);
1359 pr_warn("dgap: Please make SURE the EBI cable running from the card\n");
1360 pr_warn("dgap: to each EM module is plugged into EBI IN!\n");
1361 } else if ((brd->type == PPCM) && (true_count == 0)) {
1362 pr_warn("dgap: %s configured for %d ports, has %d ports.\n",
1363 brd->name, brd->nasync, true_count);
1364 pr_warn("dgap: Please make SURE the EBI cable running from the card\n");
1365 pr_warn("dgap: to each EM module is plugged into EBI IN!\n");
1367 pr_warn("dgap: %s configured for %d ports, has %d ports.\n",
1368 brd->name, brd->nasync, true_count);
1370 brd->nasync = true_count;
1372 /* If no ports, don't bother going any further */
1374 brd->state = BOARD_FAILED;
1375 brd->dpastatus = BD_NOFEP;
1381 * Allocate channel memory that might not have been allocated
1382 * when the driver was first loaded.
1384 for (i = 0; i < brd->nasync; i++) {
1385 if (!brd->channels[i]) {
1387 kzalloc(sizeof(struct channel_t), GFP_ATOMIC);
1388 if (!brd->channels[i])
1393 ch = brd->channels[0];
1394 vaddr = brd->re_map_membase;
1396 bs = (struct bs_t *) ((ulong) vaddr + CHANBUF);
1397 cm = (struct cm_t *) ((ulong) vaddr + CMDBUF);
1401 /* Set up channel variables */
1402 for (i = 0; i < brd->nasync; i++, ch = brd->channels[i], bs++) {
1404 if (!brd->channels[i])
1407 spin_lock_init(&ch->ch_lock);
1409 /* Store all our magic numbers */
1410 ch->magic = DGAP_CHANNEL_MAGIC;
1411 ch->ch_tun.magic = DGAP_UNIT_MAGIC;
1412 ch->ch_tun.un_type = DGAP_SERIAL;
1413 ch->ch_tun.un_ch = ch;
1414 ch->ch_tun.un_dev = i;
1416 ch->ch_pun.magic = DGAP_UNIT_MAGIC;
1417 ch->ch_pun.un_type = DGAP_PRINT;
1418 ch->ch_pun.un_ch = ch;
1419 ch->ch_pun.un_dev = i;
1421 ch->ch_vaddr = vaddr;
1426 ch->ch_digi = dgap_digi_init;
1429 * Set up digi dsr and dcd bits based on altpin flag.
1431 if (dgap_config_get_altpin(brd)) {
1434 ch->ch_digi.digi_flags |= DIGI_ALTPIN;
1437 ch->ch_dsr = DM_DSR;
1440 ch->ch_taddr = vaddr + ((ch->ch_bs->tx_seg) << 4);
1441 ch->ch_raddr = vaddr + ((ch->ch_bs->rx_seg) << 4);
1444 ch->ch_tsize = readw(&(ch->ch_bs->tx_max)) + 1;
1445 ch->ch_rsize = readw(&(ch->ch_bs->rx_max)) + 1;
1449 /* .25 second delay */
1450 ch->ch_close_delay = 250;
1453 * Set queue water marks, interrupt mask,
1454 * and general tty parameters.
1456 tlw = ch->ch_tsize >= 2000 ? ((ch->ch_tsize * 5) / 8) :
1460 dgap_cmdw(ch, STLOW, tlw, 0);
1462 dgap_cmdw(ch, SRLOW, ch->ch_rsize / 2, 0);
1464 dgap_cmdw(ch, SRHIGH, 7 * ch->ch_rsize / 8, 0);
1466 ch->ch_mistat = readb(&(ch->ch_bs->m_stat));
1468 init_waitqueue_head(&ch->ch_flags_wait);
1469 init_waitqueue_head(&ch->ch_tun.un_flags_wait);
1470 init_waitqueue_head(&ch->ch_pun.un_flags_wait);
1471 init_waitqueue_head(&ch->ch_sniff_wait);
1473 /* Turn on all modem interrupts for now */
1474 modem = (DM_CD | DM_DSR | DM_CTS | DM_RI);
1475 writeb(modem, &(ch->ch_bs->m_int));
1478 * Set edelay to 0 if interrupts are turned on,
1479 * otherwise set edelay to the usual 100.
1482 writew(0, &(ch->ch_bs->edelay));
1484 writew(100, &(ch->ch_bs->edelay));
1486 writeb(1, &(ch->ch_bs->idata));
1495 * Uninitialize the TTY portion of this driver. Free all memory and
1498 static void dgap_tty_uninit(struct board_t *brd)
1503 if (brd->dgap_Major_Serial_Registered) {
1504 dgap_BoardsByMajor[brd->SerialDriver->major] = NULL;
1505 brd->dgap_Serial_Major = 0;
1506 for (i = 0; i < brd->nasync; i++) {
1507 tty_port_destroy(&brd->SerialPorts[i]);
1508 dev = brd->channels[i]->ch_tun.un_sysfs;
1509 dgap_remove_tty_sysfs(dev);
1510 tty_unregister_device(brd->SerialDriver, i);
1512 tty_unregister_driver(brd->SerialDriver);
1513 kfree(brd->SerialDriver->ttys);
1514 brd->SerialDriver->ttys = NULL;
1515 put_tty_driver(brd->SerialDriver);
1516 kfree(brd->SerialPorts);
1517 brd->dgap_Major_Serial_Registered = FALSE;
1520 if (brd->dgap_Major_TransparentPrint_Registered) {
1521 dgap_BoardsByMajor[brd->PrintDriver->major] = NULL;
1522 brd->dgap_TransparentPrint_Major = 0;
1523 for (i = 0; i < brd->nasync; i++) {
1524 tty_port_destroy(&brd->PrinterPorts[i]);
1525 dev = brd->channels[i]->ch_pun.un_sysfs;
1526 dgap_remove_tty_sysfs(dev);
1527 tty_unregister_device(brd->PrintDriver, i);
1529 tty_unregister_driver(brd->PrintDriver);
1530 kfree(brd->PrintDriver->ttys);
1531 brd->PrintDriver->ttys = NULL;
1532 put_tty_driver(brd->PrintDriver);
1533 kfree(brd->PrinterPorts);
1534 brd->dgap_Major_TransparentPrint_Registered = FALSE;
1538 #define TMPBUFLEN (1024)
1540 * dgap_sniff - Dump data out to the "sniff" buffer if the
1541 * proc sniff file is opened...
1543 static void dgap_sniff_nowait_nolock(struct channel_t *ch, uchar *text,
1544 uchar *buf, int len)
1552 char tmpbuf[TMPBUFLEN];
1556 /* Leave if sniff not open */
1557 if (!(ch->ch_sniff_flags & SNIFF_OPEN))
1560 do_gettimeofday(&tv);
1562 /* Create our header for data dump */
1563 p += sprintf(p, "<%ld %ld><%s><", tv.tv_sec, tv.tv_usec, text);
1564 tmpbuflen = p - tmpbuf;
1569 for (i = 0; i < len && tmpbuflen < (TMPBUFLEN - 4); i++) {
1570 p += sprintf(p, "%02x ", *buf);
1572 tmpbuflen = p - tmpbuf;
1575 if (tmpbuflen < (TMPBUFLEN - 4)) {
1577 p += sprintf(p - 1, "%s\n", ">");
1579 p += sprintf(p, "%s\n", ">");
1585 nbuf = strlen(tmpbuf);
1589 * Loop while data remains.
1591 while (nbuf > 0 && ch->ch_sniff_buf) {
1593 * Determine the amount of available space left in the
1594 * buffer. If there's none, wait until some appears.
1596 n = (ch->ch_sniff_out - ch->ch_sniff_in - 1) &
1600 * If there is no space left to write to in our sniff
1601 * buffer, we have no choice but to drop the data.
1602 * We *cannot* sleep here waiting for space, because
1603 * this function was probably called by the
1604 * interrupt/timer routines!
1610 * Copy as much data as will fit.
1616 r = SNIFF_MAX - ch->ch_sniff_in;
1619 memcpy(ch->ch_sniff_buf +
1620 ch->ch_sniff_in, p, r);
1623 ch->ch_sniff_in = 0;
1628 memcpy(ch->ch_sniff_buf + ch->ch_sniff_in, p, n);
1630 ch->ch_sniff_in += n;
1635 * Wakeup any thread waiting for data
1637 if (ch->ch_sniff_flags & SNIFF_WAIT_DATA) {
1638 ch->ch_sniff_flags &= ~SNIFF_WAIT_DATA;
1639 wake_up_interruptible(&ch->ch_sniff_wait);
1644 * If the user sent us too much data to push into our tmpbuf,
1645 * we need to keep looping around on all the data.
1647 if (too_much_data) {
1652 } while (too_much_data);
1655 /*=======================================================================
1657 * dgap_input - Process received data.
1659 * ch - Pointer to channel structure.
1661 *=======================================================================*/
1663 static void dgap_input(struct channel_t *ch)
1667 struct tty_struct *tp;
1668 struct tty_ldisc *ld;
1682 if (!ch || ch->magic != DGAP_CHANNEL_MAGIC)
1685 tp = ch->ch_tun.un_tty;
1692 if (!bd || bd->magic != DGAP_BOARD_MAGIC)
1695 spin_lock_irqsave(&bd->bd_lock, lock_flags);
1696 spin_lock_irqsave(&ch->ch_lock, lock_flags2);
1699 * Figure the number of characters in the buffer.
1700 * Exit immediately if none.
1703 rmask = ch->ch_rsize - 1;
1705 head = readw(&(bs->rx_head));
1707 tail = readw(&(bs->rx_tail));
1710 data_len = (head - tail) & rmask;
1712 if (data_len == 0) {
1713 writeb(1, &(bs->idata));
1714 spin_unlock_irqrestore(&ch->ch_lock, lock_flags2);
1715 spin_unlock_irqrestore(&bd->bd_lock, lock_flags);
1720 * If the device is not open, or CREAD is off, flush
1721 * input data and return immediately.
1723 if ((bd->state != BOARD_READY) || !tp ||
1724 (tp->magic != TTY_MAGIC) ||
1725 !(ch->ch_tun.un_flags & UN_ISOPEN) ||
1726 !(tp->termios.c_cflag & CREAD) ||
1727 (ch->ch_tun.un_flags & UN_CLOSING)) {
1729 writew(head, &(bs->rx_tail));
1730 writeb(1, &(bs->idata));
1731 spin_unlock_irqrestore(&ch->ch_lock, lock_flags2);
1732 spin_unlock_irqrestore(&bd->bd_lock, lock_flags);
1737 * If we are throttled, simply don't read any data.
1739 if (ch->ch_flags & CH_RXBLOCK) {
1740 writeb(1, &(bs->idata));
1741 spin_unlock_irqrestore(&ch->ch_lock, lock_flags2);
1742 spin_unlock_irqrestore(&bd->bd_lock, lock_flags);
1749 tmpchar = readb(&(bs->orun));
1751 ch->ch_err_overrun++;
1752 writeb(0, &(bs->orun));
1755 /* Decide how much data we can send into the tty layer */
1756 flip_len = TTY_FLIPBUF_SIZE;
1758 /* Chop down the length, if needed */
1759 len = min(data_len, flip_len);
1760 len = min(len, (N_TTY_BUF_SIZE - 1));
1762 ld = tty_ldisc_ref(tp);
1764 #ifdef TTY_DONT_FLIP
1766 * If the DONT_FLIP flag is on, don't flush our buffer, and act
1767 * like the ld doesn't have any space to put the data right now.
1769 if (test_bit(TTY_DONT_FLIP, &tp->flags))
1774 * If we were unable to get a reference to the ld,
1775 * don't flush our buffer, and act like the ld doesn't
1776 * have any space to put the data right now.
1782 * If ld doesn't have a pointer to a receive_buf function,
1783 * flush the data, then act like the ld doesn't have any
1784 * space to put the data right now.
1786 if (!ld->ops->receive_buf) {
1787 writew(head, &(bs->rx_tail));
1793 writeb(1, &(bs->idata));
1794 spin_unlock_irqrestore(&ch->ch_lock, lock_flags2);
1795 spin_unlock_irqrestore(&bd->bd_lock, lock_flags);
1797 tty_ldisc_deref(ld);
1801 buf = ch->ch_bd->flipbuf;
1805 * n now contains the most amount of data we can copy,
1806 * bounded either by our buffer size or the amount
1807 * of data the card actually has pending...
1811 s = ((head >= tail) ? head : ch->ch_rsize) - tail;
1817 memcpy_fromio(buf, (char *) ch->ch_raddr + tail, s);
1818 dgap_sniff_nowait_nolock(ch, "USER READ", buf, s);
1824 /* Flip queue if needed */
1828 writew(tail, &(bs->rx_tail));
1829 writeb(1, &(bs->idata));
1830 ch->ch_rxcount += len;
1833 * If we are completely raw, we don't need to go through a lot
1834 * of the tty layers that exist.
1835 * In this case, we take the shortest and fastest route we
1836 * can to relay the data to the user.
1838 * On the other hand, if we are not raw, we need to go through
1839 * the tty layer, which has its API more well defined.
1841 if (I_PARMRK(tp) || I_BRKINT(tp) || I_INPCK(tp)) {
1842 dgap_parity_scan(ch, ch->ch_bd->flipbuf,
1843 ch->ch_bd->flipflagbuf, &len);
1845 len = tty_buffer_request_room(tp->port, len);
1846 tty_insert_flip_string_flags(tp->port, ch->ch_bd->flipbuf,
1847 ch->ch_bd->flipflagbuf, len);
1849 len = tty_buffer_request_room(tp->port, len);
1850 tty_insert_flip_string(tp->port, ch->ch_bd->flipbuf, len);
1853 spin_unlock_irqrestore(&ch->ch_lock, lock_flags2);
1854 spin_unlock_irqrestore(&bd->bd_lock, lock_flags);
1856 /* Tell the tty layer its okay to "eat" the data now */
1857 tty_flip_buffer_push(tp->port);
1860 tty_ldisc_deref(ld);
1864 /************************************************************************
1865 * Determines when CARRIER changes state and takes appropriate
1867 ************************************************************************/
1868 static void dgap_carrier(struct channel_t *ch)
1872 int virt_carrier = 0;
1873 int phys_carrier = 0;
1875 if (!ch || ch->magic != DGAP_CHANNEL_MAGIC)
1880 if (!bd || bd->magic != DGAP_BOARD_MAGIC)
1883 /* Make sure altpin is always set correctly */
1884 if (ch->ch_digi.digi_flags & DIGI_ALTPIN) {
1888 ch->ch_dsr = DM_DSR;
1892 if (ch->ch_mistat & D_CD(ch))
1895 if (ch->ch_digi.digi_flags & DIGI_FORCEDCD)
1898 if (ch->ch_c_cflag & CLOCAL)
1902 * Test for a VIRTUAL carrier transition to HIGH.
1904 if (((ch->ch_flags & CH_FCAR) == 0) && (virt_carrier == 1)) {
1907 * When carrier rises, wake any threads waiting
1908 * for carrier in the open routine.
1911 if (waitqueue_active(&(ch->ch_flags_wait)))
1912 wake_up_interruptible(&ch->ch_flags_wait);
1916 * Test for a PHYSICAL carrier transition to HIGH.
1918 if (((ch->ch_flags & CH_CD) == 0) && (phys_carrier == 1)) {
1921 * When carrier rises, wake any threads waiting
1922 * for carrier in the open routine.
1925 if (waitqueue_active(&(ch->ch_flags_wait)))
1926 wake_up_interruptible(&ch->ch_flags_wait);
1930 * Test for a PHYSICAL transition to low, so long as we aren't
1931 * currently ignoring physical transitions (which is what "virtual
1932 * carrier" indicates).
1934 * The transition of the virtual carrier to low really doesn't
1935 * matter... it really only means "ignore carrier state", not
1936 * "make pretend that carrier is there".
1938 if ((virt_carrier == 0) &&
1939 ((ch->ch_flags & CH_CD) != 0) &&
1940 (phys_carrier == 0)) {
1943 * When carrier drops:
1945 * Drop carrier on all open units.
1947 * Flush queues, waking up any task waiting in the
1950 * Send a hangup to the control terminal.
1952 * Enable all select calls.
1954 if (waitqueue_active(&(ch->ch_flags_wait)))
1955 wake_up_interruptible(&ch->ch_flags_wait);
1957 if (ch->ch_tun.un_open_count > 0)
1958 tty_hangup(ch->ch_tun.un_tty);
1960 if (ch->ch_pun.un_open_count > 0)
1961 tty_hangup(ch->ch_pun.un_tty);
1965 * Make sure that our cached values reflect the current reality.
1967 if (virt_carrier == 1)
1968 ch->ch_flags |= CH_FCAR;
1970 ch->ch_flags &= ~CH_FCAR;
1972 if (phys_carrier == 1)
1973 ch->ch_flags |= CH_CD;
1975 ch->ch_flags &= ~CH_CD;
1978 /************************************************************************
1980 * TTY Entry points and helper functions
1982 ************************************************************************/
1988 static int dgap_tty_open(struct tty_struct *tty, struct file *file)
1990 struct board_t *brd;
1991 struct channel_t *ch;
2003 major = MAJOR(tty_devnum(tty));
2004 minor = MINOR(tty_devnum(tty));
2009 /* Get board pointer from our array of majors we have allocated */
2010 brd = dgap_BoardsByMajor[major];
2015 * If board is not yet up to a state of READY, go to
2016 * sleep waiting for it to happen or they cancel the open.
2018 rc = wait_event_interruptible(brd->state_wait,
2019 (brd->state & BOARD_READY));
2024 spin_lock_irqsave(&brd->bd_lock, lock_flags);
2026 /* The wait above should guarantee this cannot happen */
2027 if (brd->state != BOARD_READY) {
2028 spin_unlock_irqrestore(&brd->bd_lock, lock_flags);
2032 /* If opened device is greater than our number of ports, bail. */
2033 if (MINOR(tty_devnum(tty)) > brd->nasync) {
2034 spin_unlock_irqrestore(&brd->bd_lock, lock_flags);
2038 ch = brd->channels[minor];
2040 spin_unlock_irqrestore(&brd->bd_lock, lock_flags);
2044 /* Grab channel lock */
2045 spin_lock_irqsave(&ch->ch_lock, lock_flags2);
2047 /* Figure out our type */
2048 if (major == brd->dgap_Serial_Major) {
2049 un = &brd->channels[minor]->ch_tun;
2050 un->un_type = DGAP_SERIAL;
2051 } else if (major == brd->dgap_TransparentPrint_Major) {
2052 un = &brd->channels[minor]->ch_pun;
2053 un->un_type = DGAP_PRINT;
2055 spin_unlock_irqrestore(&ch->ch_lock, lock_flags2);
2056 spin_unlock_irqrestore(&brd->bd_lock, lock_flags);
2060 /* Store our unit into driver_data, so we always have it available. */
2061 tty->driver_data = un;
2064 * Error if channel info pointer is NULL.
2068 spin_unlock_irqrestore(&ch->ch_lock, lock_flags2);
2069 spin_unlock_irqrestore(&brd->bd_lock, lock_flags);
2076 if (!(un->un_flags & UN_ISOPEN)) {
2077 /* Store important variables. */
2080 /* Maybe do something here to the TTY struct as well? */
2084 * Initialize if neither terminal or printer is open.
2086 if (!((ch->ch_tun.un_flags | ch->ch_pun.un_flags) & UN_ISOPEN)) {
2092 * Flush input queue.
2094 head = readw(&(bs->rx_head));
2095 writew(head, &(bs->rx_tail));
2098 ch->pscan_state = 0;
2099 ch->pscan_savechar = 0;
2101 ch->ch_c_cflag = tty->termios.c_cflag;
2102 ch->ch_c_iflag = tty->termios.c_iflag;
2103 ch->ch_c_oflag = tty->termios.c_oflag;
2104 ch->ch_c_lflag = tty->termios.c_lflag;
2105 ch->ch_startc = tty->termios.c_cc[VSTART];
2106 ch->ch_stopc = tty->termios.c_cc[VSTOP];
2108 /* TODO: flush our TTY struct here? */
2113 * Run param in case we changed anything
2118 * follow protocol for opening port
2121 spin_unlock_irqrestore(&ch->ch_lock, lock_flags2);
2122 spin_unlock_irqrestore(&brd->bd_lock, lock_flags);
2124 rc = dgap_block_til_ready(tty, file, ch);
2129 /* No going back now, increment our unit and channel counters */
2130 spin_lock_irqsave(&ch->ch_lock, lock_flags);
2131 ch->ch_open_count++;
2132 un->un_open_count++;
2133 un->un_flags |= (UN_ISOPEN);
2134 spin_unlock_irqrestore(&ch->ch_lock, lock_flags);
2140 * dgap_block_til_ready()
2142 * Wait for DCD, if needed.
2144 static int dgap_block_til_ready(struct tty_struct *tty, struct file *file,
2145 struct channel_t *ch)
2148 struct un_t *un = NULL;
2151 int sleep_on_un_flags = 0;
2153 if (!tty || tty->magic != TTY_MAGIC || !file || !ch ||
2154 ch->magic != DGAP_CHANNEL_MAGIC)
2157 un = tty->driver_data;
2158 if (!un || un->magic != DGAP_UNIT_MAGIC)
2161 spin_lock_irqsave(&ch->ch_lock, lock_flags);
2168 sleep_on_un_flags = 0;
2171 * If board has failed somehow during our sleep,
2174 if (ch->ch_bd->state == BOARD_FAILED) {
2179 /* If tty was hung up, break out of loop and set error. */
2180 if (tty_hung_up_p(file)) {
2186 * If either unit is in the middle of the fragile part of close,
2187 * we just cannot touch the channel safely.
2188 * Go back to sleep, knowing that when the channel can be
2189 * touched safely, the close routine will signal the
2190 * ch_wait_flags to wake us back up.
2192 if (!((ch->ch_tun.un_flags | ch->ch_pun.un_flags) &
2196 * Our conditions to leave cleanly and happily:
2197 * 1) NONBLOCKING on the tty is set.
2199 * 3) DCD (fake or real) is active.
2202 if (file->f_flags & O_NONBLOCK)
2205 if (tty->flags & (1 << TTY_IO_ERROR))
2208 if (ch->ch_flags & CH_CD)
2211 if (ch->ch_flags & CH_FCAR)
2214 sleep_on_un_flags = 1;
2218 * If there is a signal pending, the user probably
2219 * interrupted (ctrl-c) us.
2220 * Leave loop with error set.
2222 if (signal_pending(current)) {
2223 retval = -ERESTARTSYS;
2228 * Store the flags before we let go of channel lock
2230 if (sleep_on_un_flags)
2231 old_flags = ch->ch_tun.un_flags | ch->ch_pun.un_flags;
2233 old_flags = ch->ch_flags;
2236 * Let go of channel lock before calling schedule.
2237 * Our poller will get any FEP events and wake us up when DCD
2238 * eventually goes active.
2241 spin_unlock_irqrestore(&ch->ch_lock, lock_flags);
2244 * Wait for something in the flags to change
2245 * from the current value.
2247 if (sleep_on_un_flags) {
2248 retval = wait_event_interruptible(un->un_flags_wait,
2249 (old_flags != (ch->ch_tun.un_flags |
2250 ch->ch_pun.un_flags)));
2252 retval = wait_event_interruptible(ch->ch_flags_wait,
2253 (old_flags != ch->ch_flags));
2257 * We got woken up for some reason.
2258 * Before looping around, grab our channel lock.
2260 spin_lock_irqsave(&ch->ch_lock, lock_flags);
2265 spin_unlock_irqrestore(&ch->ch_lock, lock_flags);
2276 * Hangup the port. Like a close, but don't wait for output to drain.
2278 static void dgap_tty_hangup(struct tty_struct *tty)
2281 struct channel_t *ch;
2284 if (!tty || tty->magic != TTY_MAGIC)
2287 un = tty->driver_data;
2288 if (!un || un->magic != DGAP_UNIT_MAGIC)
2292 if (!ch || ch->magic != DGAP_CHANNEL_MAGIC)
2296 if (!bd || bd->magic != DGAP_BOARD_MAGIC)
2299 /* flush the transmit queues */
2300 dgap_tty_flush_buffer(tty);
2308 static void dgap_tty_close(struct tty_struct *tty, struct file *file)
2310 struct ktermios *ts;
2312 struct channel_t *ch;
2317 if (!tty || tty->magic != TTY_MAGIC)
2320 un = tty->driver_data;
2321 if (!un || un->magic != DGAP_UNIT_MAGIC)
2325 if (!ch || ch->magic != DGAP_CHANNEL_MAGIC)
2329 if (!bd || bd->magic != DGAP_BOARD_MAGIC)
2334 spin_lock_irqsave(&ch->ch_lock, lock_flags);
2337 * Determine if this is the last close or not - and if we agree about
2338 * which type of close it is with the Line Discipline
2340 if ((tty->count == 1) && (un->un_open_count != 1)) {
2342 * Uh, oh. tty->count is 1, which means that the tty
2343 * structure will be freed. un_open_count should always
2344 * be one in these conditions. If it's greater than
2345 * one, we've got real problems, since it means the
2346 * serial port won't be shutdown.
2348 un->un_open_count = 1;
2351 if (--un->un_open_count < 0)
2352 un->un_open_count = 0;
2354 ch->ch_open_count--;
2356 if (ch->ch_open_count && un->un_open_count) {
2357 spin_unlock_irqrestore(&ch->ch_lock, lock_flags);
2361 /* OK, its the last close on the unit */
2363 un->un_flags |= UN_CLOSING;
2368 * Only officially close channel if count is 0 and
2369 * DIGI_PRINTER bit is not set.
2371 if ((ch->ch_open_count == 0) &&
2372 !(ch->ch_digi.digi_flags & DIGI_PRINTER)) {
2374 ch->ch_flags &= ~(CH_RXBLOCK);
2376 spin_unlock_irqrestore(&ch->ch_lock, lock_flags);
2378 /* wait for output to drain */
2379 /* This will also return if we take an interrupt */
2381 rc = dgap_wait_for_drain(tty);
2383 dgap_tty_flush_buffer(tty);
2384 tty_ldisc_flush(tty);
2386 spin_lock_irqsave(&ch->ch_lock, lock_flags);
2391 * If we have HUPCL set, lower DTR and RTS
2393 if (ch->ch_c_cflag & HUPCL) {
2394 ch->ch_mostat &= ~(D_RTS(ch)|D_DTR(ch));
2395 dgap_cmdb(ch, SMODEM, 0, D_DTR(ch)|D_RTS(ch), 0);
2398 * Go to sleep to ensure RTS/DTR
2399 * have been dropped for modems to see it.
2401 if (ch->ch_close_delay) {
2402 spin_unlock_irqrestore(&ch->ch_lock,
2404 dgap_ms_sleep(ch->ch_close_delay);
2405 spin_lock_irqsave(&ch->ch_lock, lock_flags);
2409 ch->pscan_state = 0;
2410 ch->pscan_savechar = 0;
2411 ch->ch_baud_info = 0;
2416 * turn off print device when closing print device.
2418 if ((un->un_type == DGAP_PRINT) && (ch->ch_flags & CH_PRON)) {
2419 dgap_wmove(ch, ch->ch_digi.digi_offstr,
2420 (int) ch->ch_digi.digi_offlen);
2421 ch->ch_flags &= ~CH_PRON;
2425 un->un_flags &= ~(UN_ISOPEN | UN_CLOSING);
2426 tty->driver_data = NULL;
2428 wake_up_interruptible(&ch->ch_flags_wait);
2429 wake_up_interruptible(&un->un_flags_wait);
2431 spin_unlock_irqrestore(&ch->ch_lock, lock_flags);
2435 * dgap_tty_chars_in_buffer()
2437 * Return number of characters that have not been transmitted yet.
2439 * This routine is used by the line discipline to determine if there
2440 * is data waiting to be transmitted/drained/flushed or not.
2442 static int dgap_tty_chars_in_buffer(struct tty_struct *tty)
2444 struct board_t *bd = NULL;
2445 struct channel_t *ch = NULL;
2446 struct un_t *un = NULL;
2447 struct bs_t *bs = NULL;
2450 u16 thead, ttail, tmask, chead, ctail;
2451 ulong lock_flags = 0;
2452 ulong lock_flags2 = 0;
2457 un = tty->driver_data;
2458 if (!un || un->magic != DGAP_UNIT_MAGIC)
2462 if (!ch || ch->magic != DGAP_CHANNEL_MAGIC)
2466 if (!bd || bd->magic != DGAP_BOARD_MAGIC)
2473 spin_lock_irqsave(&bd->bd_lock, lock_flags);
2474 spin_lock_irqsave(&ch->ch_lock, lock_flags2);
2476 tmask = (ch->ch_tsize - 1);
2478 /* Get Transmit queue pointers */
2479 thead = readw(&(bs->tx_head)) & tmask;
2480 ttail = readw(&(bs->tx_tail)) & tmask;
2482 /* Get tbusy flag */
2483 tbusy = readb(&(bs->tbusy));
2485 /* Get Command queue pointers */
2486 chead = readw(&(ch->ch_cm->cm_head));
2487 ctail = readw(&(ch->ch_cm->cm_tail));
2489 spin_unlock_irqrestore(&ch->ch_lock, lock_flags2);
2490 spin_unlock_irqrestore(&bd->bd_lock, lock_flags);
2493 * The only way we know for sure if there is no pending
2494 * data left to be transferred, is if:
2495 * 1) Transmit head and tail are equal (empty).
2496 * 2) Command queue head and tail are equal (empty).
2497 * 3) The "TBUSY" flag is 0. (Transmitter not busy).
2500 if ((ttail == thead) && (tbusy == 0) && (chead == ctail)) {
2504 chars = thead - ttail;
2506 chars = thead - ttail + ch->ch_tsize;
2508 * Fudge factor here.
2509 * If chars is zero, we know that the command queue had
2510 * something in it or tbusy was set. Because we cannot
2511 * be sure if there is still some data to be transmitted,
2512 * lets lie, and tell ld we have 1 byte left.
2516 * If TBUSY is still set, and our tx buffers are empty,
2517 * force the firmware to send me another wakeup after
2518 * TBUSY has been cleared.
2521 spin_lock_irqsave(&ch->ch_lock, lock_flags);
2522 un->un_flags |= UN_EMPTY;
2523 writeb(1, &(bs->iempty));
2524 spin_unlock_irqrestore(&ch->ch_lock,
2534 static int dgap_wait_for_drain(struct tty_struct *tty)
2536 struct channel_t *ch;
2541 ulong lock_flags = 0;
2543 if (!tty || tty->magic != TTY_MAGIC)
2546 un = tty->driver_data;
2547 if (!un || un->magic != DGAP_UNIT_MAGIC)
2551 if (!ch || ch->magic != DGAP_CHANNEL_MAGIC)
2560 /* Loop until data is drained */
2561 while (count != 0) {
2563 count = dgap_tty_chars_in_buffer(tty);
2568 /* Set flag waiting for drain */
2569 spin_lock_irqsave(&ch->ch_lock, lock_flags);
2570 un->un_flags |= UN_EMPTY;
2571 writeb(1, &(bs->iempty));
2572 spin_unlock_irqrestore(&ch->ch_lock, lock_flags);
2574 /* Go to sleep till we get woken up */
2575 ret = wait_event_interruptible(un->un_flags_wait,
2576 ((un->un_flags & UN_EMPTY) == 0));
2577 /* If ret is non-zero, user ctrl-c'ed us */
2582 spin_lock_irqsave(&ch->ch_lock, lock_flags);
2583 un->un_flags &= ~(UN_EMPTY);
2584 spin_unlock_irqrestore(&ch->ch_lock, lock_flags);
2592 * Reduces bytes_available to the max number of characters
2593 * that can be sent currently given the maxcps value, and
2594 * returns the new bytes_available. This only affects printer
2597 static int dgap_maxcps_room(struct tty_struct *tty, int bytes_available)
2599 struct channel_t *ch = NULL;
2600 struct un_t *un = NULL;
2603 return bytes_available;
2605 un = tty->driver_data;
2606 if (!un || un->magic != DGAP_UNIT_MAGIC)
2607 return bytes_available;
2610 if (!ch || ch->magic != DGAP_CHANNEL_MAGIC)
2611 return bytes_available;
2614 * If its not the Transparent print device, return
2615 * the full data amount.
2617 if (un->un_type != DGAP_PRINT)
2618 return bytes_available;
2620 if (ch->ch_digi.digi_maxcps > 0 && ch->ch_digi.digi_bufsize > 0) {
2622 unsigned long current_time = jiffies;
2623 unsigned long buffer_time = current_time +
2624 (HZ * ch->ch_digi.digi_bufsize) /
2625 ch->ch_digi.digi_maxcps;
2627 if (ch->ch_cpstime < current_time) {
2628 /* buffer is empty */
2629 ch->ch_cpstime = current_time; /* reset ch_cpstime */
2630 cps_limit = ch->ch_digi.digi_bufsize;
2631 } else if (ch->ch_cpstime < buffer_time) {
2632 /* still room in the buffer */
2633 cps_limit = ((buffer_time - ch->ch_cpstime) *
2634 ch->ch_digi.digi_maxcps) / HZ;
2636 /* no room in the buffer */
2640 bytes_available = min(cps_limit, bytes_available);
2643 return bytes_available;
2646 static inline void dgap_set_firmware_event(struct un_t *un, unsigned int event)
2648 struct channel_t *ch = NULL;
2649 struct bs_t *bs = NULL;
2651 if (!un || un->magic != DGAP_UNIT_MAGIC)
2654 if (!ch || ch->magic != DGAP_CHANNEL_MAGIC)
2660 if ((event & UN_LOW) != 0) {
2661 if ((un->un_flags & UN_LOW) == 0) {
2662 un->un_flags |= UN_LOW;
2663 writeb(1, &(bs->ilow));
2666 if ((event & UN_LOW) != 0) {
2667 if ((un->un_flags & UN_EMPTY) == 0) {
2668 un->un_flags |= UN_EMPTY;
2669 writeb(1, &(bs->iempty));
2675 * dgap_tty_write_room()
2677 * Return space available in Tx buffer
2679 static int dgap_tty_write_room(struct tty_struct *tty)
2681 struct channel_t *ch = NULL;
2682 struct un_t *un = NULL;
2683 struct bs_t *bs = NULL;
2684 u16 head, tail, tmask;
2686 ulong lock_flags = 0;
2691 un = tty->driver_data;
2692 if (!un || un->magic != DGAP_UNIT_MAGIC)
2696 if (!ch || ch->magic != DGAP_CHANNEL_MAGIC)
2703 spin_lock_irqsave(&ch->ch_lock, lock_flags);
2705 tmask = ch->ch_tsize - 1;
2706 head = readw(&(bs->tx_head)) & tmask;
2707 tail = readw(&(bs->tx_tail)) & tmask;
2709 ret = tail - head - 1;
2711 ret += ch->ch_tsize;
2713 /* Limit printer to maxcps */
2714 ret = dgap_maxcps_room(tty, ret);
2717 * If we are printer device, leave space for
2718 * possibly both the on and off strings.
2720 if (un->un_type == DGAP_PRINT) {
2721 if (!(ch->ch_flags & CH_PRON))
2722 ret -= ch->ch_digi.digi_onlen;
2723 ret -= ch->ch_digi.digi_offlen;
2725 if (ch->ch_flags & CH_PRON)
2726 ret -= ch->ch_digi.digi_offlen;
2733 * Schedule FEP to wake us up if needed.
2735 * TODO: This might be overkill...
2736 * Do we really need to schedule callbacks from the FEP
2737 * in every case? Can we get smarter based on ret?
2739 dgap_set_firmware_event(un, UN_LOW | UN_EMPTY);
2740 spin_unlock_irqrestore(&ch->ch_lock, lock_flags);
2746 * dgap_tty_put_char()
2748 * Put a character into ch->ch_buf
2750 * - used by the line discipline for OPOST processing
2752 static int dgap_tty_put_char(struct tty_struct *tty, unsigned char c)
2755 * Simply call tty_write.
2757 dgap_tty_write(tty, &c, 1);
2764 * Take data from the user or kernel and send it out to the FEP.
2765 * In here exists all the Transparent Print magic as well.
2767 static int dgap_tty_write(struct tty_struct *tty, const unsigned char *buf,
2770 struct channel_t *ch = NULL;
2771 struct un_t *un = NULL;
2772 struct bs_t *bs = NULL;
2774 u16 head, tail, tmask, remain;
2775 int bufcount = 0, n = 0;
2782 un = tty->driver_data;
2783 if (!un || un->magic != DGAP_UNIT_MAGIC)
2787 if (!ch || ch->magic != DGAP_CHANNEL_MAGIC)
2798 * Store original amount of characters passed in.
2799 * This helps to figure out if we should ask the FEP
2800 * to send us an event when it has more space available.
2804 spin_lock_irqsave(&ch->ch_lock, lock_flags);
2806 /* Get our space available for the channel from the board */
2807 tmask = ch->ch_tsize - 1;
2808 head = readw(&(bs->tx_head)) & tmask;
2809 tail = readw(&(bs->tx_tail)) & tmask;
2811 bufcount = tail - head - 1;
2813 bufcount += ch->ch_tsize;
2816 * Limit printer output to maxcps overall, with bursts allowed
2817 * up to bufsize characters.
2819 bufcount = dgap_maxcps_room(tty, bufcount);
2822 * Take minimum of what the user wants to send, and the
2823 * space available in the FEP buffer.
2825 count = min(count, bufcount);
2828 * Bail if no space left.
2831 dgap_set_firmware_event(un, UN_LOW | UN_EMPTY);
2832 spin_unlock_irqrestore(&ch->ch_lock, lock_flags);
2837 * Output the printer ON string, if we are in terminal mode, but
2838 * need to be in printer mode.
2840 if ((un->un_type == DGAP_PRINT) && !(ch->ch_flags & CH_PRON)) {
2841 dgap_wmove(ch, ch->ch_digi.digi_onstr,
2842 (int) ch->ch_digi.digi_onlen);
2843 head = readw(&(bs->tx_head)) & tmask;
2844 ch->ch_flags |= CH_PRON;
2848 * On the other hand, output the printer OFF string, if we are
2849 * currently in printer mode, but need to output to the terminal.
2851 if ((un->un_type != DGAP_PRINT) && (ch->ch_flags & CH_PRON)) {
2852 dgap_wmove(ch, ch->ch_digi.digi_offstr,
2853 (int) ch->ch_digi.digi_offlen);
2854 head = readw(&(bs->tx_head)) & tmask;
2855 ch->ch_flags &= ~CH_PRON;
2859 * If there is nothing left to copy, or
2860 * I can't handle any more data, leave.
2863 dgap_set_firmware_event(un, UN_LOW | UN_EMPTY);
2864 spin_unlock_irqrestore(&ch->ch_lock, lock_flags);
2871 * If the write wraps over the top of the circular buffer,
2872 * move the portion up to the wrap point, and reset the
2873 * pointers to the bottom.
2875 remain = ch->ch_tstart + ch->ch_tsize - head;
2879 vaddr = ch->ch_taddr + head;
2881 memcpy_toio(vaddr, (uchar *) buf, remain);
2882 dgap_sniff_nowait_nolock(ch, "USER WRITE", (uchar *) buf,
2885 head = ch->ch_tstart;
2892 * Move rest of data.
2894 vaddr = ch->ch_taddr + head;
2897 memcpy_toio(vaddr, (uchar *) buf, remain);
2898 dgap_sniff_nowait_nolock(ch, "USER WRITE", (uchar *)buf,
2906 ch->ch_txcount += count;
2908 writew(head, &(bs->tx_head));
2911 dgap_set_firmware_event(un, UN_LOW | UN_EMPTY);
2914 * If this is the print device, and the
2915 * printer is still on, we need to turn it
2916 * off before going idle. If the buffer is
2917 * non-empty, wait until it goes empty.
2918 * Otherwise turn it off right now.
2920 if ((un->un_type == DGAP_PRINT) && (ch->ch_flags & CH_PRON)) {
2921 tail = readw(&(bs->tx_tail)) & tmask;
2924 un->un_flags |= UN_EMPTY;
2925 writeb(1, &(bs->iempty));
2927 dgap_wmove(ch, ch->ch_digi.digi_offstr,
2928 (int) ch->ch_digi.digi_offlen);
2929 head = readw(&(bs->tx_head)) & tmask;
2930 ch->ch_flags &= ~CH_PRON;
2934 /* Update printer buffer empty time. */
2935 if ((un->un_type == DGAP_PRINT) && (ch->ch_digi.digi_maxcps > 0)
2936 && (ch->ch_digi.digi_bufsize > 0)) {
2937 ch->ch_cpstime += (HZ * count) / ch->ch_digi.digi_maxcps;
2940 spin_unlock_irqrestore(&ch->ch_lock, lock_flags);
2946 * Return modem signals to ld.
2948 static int dgap_tty_tiocmget(struct tty_struct *tty)
2950 struct channel_t *ch;
2956 if (!tty || tty->magic != TTY_MAGIC)
2959 un = tty->driver_data;
2960 if (!un || un->magic != DGAP_UNIT_MAGIC)
2964 if (!ch || ch->magic != DGAP_CHANNEL_MAGIC)
2967 spin_lock_irqsave(&ch->ch_lock, lock_flags);
2969 mstat = readb(&(ch->ch_bs->m_stat));
2970 /* Append any outbound signals that might be pending... */
2971 mstat |= ch->ch_mostat;
2973 spin_unlock_irqrestore(&ch->ch_lock, lock_flags);
2977 if (mstat & D_DTR(ch))
2978 result |= TIOCM_DTR;
2979 if (mstat & D_RTS(ch))
2980 result |= TIOCM_RTS;
2981 if (mstat & D_CTS(ch))
2982 result |= TIOCM_CTS;
2983 if (mstat & D_DSR(ch))
2984 result |= TIOCM_DSR;
2985 if (mstat & D_RI(ch))
2987 if (mstat & D_CD(ch))
2994 * dgap_tty_tiocmset()
2996 * Set modem signals, called by ld.
2998 static int dgap_tty_tiocmset(struct tty_struct *tty,
2999 unsigned int set, unsigned int clear)
3002 struct channel_t *ch;
3008 if (!tty || tty->magic != TTY_MAGIC)
3011 un = tty->driver_data;
3012 if (!un || un->magic != DGAP_UNIT_MAGIC)
3016 if (!ch || ch->magic != DGAP_CHANNEL_MAGIC)
3020 if (!bd || bd->magic != DGAP_BOARD_MAGIC)
3023 spin_lock_irqsave(&bd->bd_lock, lock_flags);
3024 spin_lock_irqsave(&ch->ch_lock, lock_flags2);
3026 if (set & TIOCM_RTS) {
3027 ch->ch_mforce |= D_RTS(ch);
3028 ch->ch_mval |= D_RTS(ch);
3031 if (set & TIOCM_DTR) {
3032 ch->ch_mforce |= D_DTR(ch);
3033 ch->ch_mval |= D_DTR(ch);
3036 if (clear & TIOCM_RTS) {
3037 ch->ch_mforce |= D_RTS(ch);
3038 ch->ch_mval &= ~(D_RTS(ch));
3041 if (clear & TIOCM_DTR) {
3042 ch->ch_mforce |= D_DTR(ch);
3043 ch->ch_mval &= ~(D_DTR(ch));
3048 spin_unlock_irqrestore(&ch->ch_lock, lock_flags2);
3049 spin_unlock_irqrestore(&bd->bd_lock, lock_flags);
3055 * dgap_tty_send_break()
3057 * Send a Break, called by ld.
3059 static int dgap_tty_send_break(struct tty_struct *tty, int msec)
3062 struct channel_t *ch;
3068 if (!tty || tty->magic != TTY_MAGIC)
3071 un = tty->driver_data;
3072 if (!un || un->magic != DGAP_UNIT_MAGIC)
3076 if (!ch || ch->magic != DGAP_CHANNEL_MAGIC)
3080 if (!bd || bd->magic != DGAP_BOARD_MAGIC)
3095 spin_lock_irqsave(&bd->bd_lock, lock_flags);
3096 spin_lock_irqsave(&ch->ch_lock, lock_flags2);
3098 dgap_cmdw(ch, SBREAK, (u16) SBREAK_TIME, 0);
3100 dgap_cmdw(ch, SBREAK, (u16) msec, 0);
3102 spin_unlock_irqrestore(&ch->ch_lock, lock_flags2);
3103 spin_unlock_irqrestore(&bd->bd_lock, lock_flags);
3109 * dgap_tty_wait_until_sent()
3111 * wait until data has been transmitted, called by ld.
3113 static void dgap_tty_wait_until_sent(struct tty_struct *tty, int timeout)
3115 dgap_wait_for_drain(tty);
3121 * send a high priority character, called by ld.
3123 static void dgap_tty_send_xchar(struct tty_struct *tty, char c)
3126 struct channel_t *ch;
3131 if (!tty || tty->magic != TTY_MAGIC)
3134 un = tty->driver_data;
3135 if (!un || un->magic != DGAP_UNIT_MAGIC)
3139 if (!ch || ch->magic != DGAP_CHANNEL_MAGIC)
3143 if (!bd || bd->magic != DGAP_BOARD_MAGIC)
3146 spin_lock_irqsave(&bd->bd_lock, lock_flags);
3147 spin_lock_irqsave(&ch->ch_lock, lock_flags2);
3150 * This is technically what we should do.
3151 * However, the NIST tests specifically want
3152 * to see each XON or XOFF character that it
3153 * sends, so lets just send each character
3157 if (c == STOP_CHAR(tty))
3158 dgap_cmdw(ch, RPAUSE, 0, 0);
3159 else if (c == START_CHAR(tty))
3160 dgap_cmdw(ch, RRESUME, 0, 0);
3162 dgap_wmove(ch, &c, 1);
3164 dgap_wmove(ch, &c, 1);
3167 spin_unlock_irqrestore(&ch->ch_lock, lock_flags2);
3168 spin_unlock_irqrestore(&bd->bd_lock, lock_flags);
3174 * Return modem signals to ld.
3176 static int dgap_get_modem_info(struct channel_t *ch, unsigned int __user *value)
3183 if (!ch || ch->magic != DGAP_CHANNEL_MAGIC)
3186 spin_lock_irqsave(&ch->ch_lock, lock_flags);
3188 mstat = readb(&(ch->ch_bs->m_stat));
3189 /* Append any outbound signals that might be pending... */
3190 mstat |= ch->ch_mostat;
3192 spin_unlock_irqrestore(&ch->ch_lock, lock_flags);
3196 if (mstat & D_DTR(ch))
3197 result |= TIOCM_DTR;
3198 if (mstat & D_RTS(ch))
3199 result |= TIOCM_RTS;
3200 if (mstat & D_CTS(ch))
3201 result |= TIOCM_CTS;
3202 if (mstat & D_DSR(ch))
3203 result |= TIOCM_DSR;
3204 if (mstat & D_RI(ch))
3206 if (mstat & D_CD(ch))
3209 rc = put_user(result, value);
3215 * dgap_set_modem_info()
3217 * Set modem signals, called by ld.
3219 static int dgap_set_modem_info(struct tty_struct *tty, unsigned int command,
3220 unsigned int __user *value)
3223 struct channel_t *ch;
3226 unsigned int arg = 0;
3230 if (!tty || tty->magic != TTY_MAGIC)
3233 un = tty->driver_data;
3234 if (!un || un->magic != DGAP_UNIT_MAGIC)
3238 if (!ch || ch->magic != DGAP_CHANNEL_MAGIC)
3242 if (!bd || bd->magic != DGAP_BOARD_MAGIC)
3245 ret = get_user(arg, value);
3251 if (arg & TIOCM_RTS) {
3252 ch->ch_mforce |= D_RTS(ch);
3253 ch->ch_mval |= D_RTS(ch);
3256 if (arg & TIOCM_DTR) {
3257 ch->ch_mforce |= D_DTR(ch);
3258 ch->ch_mval |= D_DTR(ch);
3264 if (arg & TIOCM_RTS) {
3265 ch->ch_mforce |= D_RTS(ch);
3266 ch->ch_mval &= ~(D_RTS(ch));
3269 if (arg & TIOCM_DTR) {
3270 ch->ch_mforce |= D_DTR(ch);
3271 ch->ch_mval &= ~(D_DTR(ch));
3277 ch->ch_mforce = D_DTR(ch)|D_RTS(ch);
3279 if (arg & TIOCM_RTS)
3280 ch->ch_mval |= D_RTS(ch);
3282 ch->ch_mval &= ~(D_RTS(ch));
3284 if (arg & TIOCM_DTR)
3285 ch->ch_mval |= (D_DTR(ch));
3287 ch->ch_mval &= ~(D_DTR(ch));
3295 spin_lock_irqsave(&bd->bd_lock, lock_flags);
3296 spin_lock_irqsave(&ch->ch_lock, lock_flags2);
3300 spin_unlock_irqrestore(&ch->ch_lock, lock_flags2);
3301 spin_unlock_irqrestore(&bd->bd_lock, lock_flags);
3307 * dgap_tty_digigeta()
3309 * Ioctl to get the information for ditty.
3314 static int dgap_tty_digigeta(struct tty_struct *tty,
3315 struct digi_t __user *retinfo)
3317 struct channel_t *ch;
3325 if (!tty || tty->magic != TTY_MAGIC)
3328 un = tty->driver_data;
3329 if (!un || un->magic != DGAP_UNIT_MAGIC)
3333 if (!ch || ch->magic != DGAP_CHANNEL_MAGIC)
3336 memset(&tmp, 0, sizeof(tmp));
3338 spin_lock_irqsave(&ch->ch_lock, lock_flags);
3339 memcpy(&tmp, &ch->ch_digi, sizeof(tmp));
3340 spin_unlock_irqrestore(&ch->ch_lock, lock_flags);
3342 if (copy_to_user(retinfo, &tmp, sizeof(*retinfo)))
3349 * dgap_tty_digiseta()
3351 * Ioctl to set the information for ditty.
3356 static int dgap_tty_digiseta(struct tty_struct *tty,
3357 struct digi_t __user *new_info)
3360 struct channel_t *ch;
3362 struct digi_t new_digi;
3363 ulong lock_flags = 0;
3364 unsigned long lock_flags2;
3366 if (!tty || tty->magic != TTY_MAGIC)
3369 un = tty->driver_data;
3370 if (!un || un->magic != DGAP_UNIT_MAGIC)
3374 if (!ch || ch->magic != DGAP_CHANNEL_MAGIC)
3378 if (!bd || bd->magic != DGAP_BOARD_MAGIC)
3381 if (copy_from_user(&new_digi, new_info, sizeof(struct digi_t)))
3384 spin_lock_irqsave(&bd->bd_lock, lock_flags);
3385 spin_lock_irqsave(&ch->ch_lock, lock_flags2);
3387 memcpy(&ch->ch_digi, &new_digi, sizeof(struct digi_t));
3389 if (ch->ch_digi.digi_maxcps < 1)
3390 ch->ch_digi.digi_maxcps = 1;
3392 if (ch->ch_digi.digi_maxcps > 10000)
3393 ch->ch_digi.digi_maxcps = 10000;
3395 if (ch->ch_digi.digi_bufsize < 10)
3396 ch->ch_digi.digi_bufsize = 10;
3398 if (ch->ch_digi.digi_maxchar < 1)
3399 ch->ch_digi.digi_maxchar = 1;
3401 if (ch->ch_digi.digi_maxchar > ch->ch_digi.digi_bufsize)
3402 ch->ch_digi.digi_maxchar = ch->ch_digi.digi_bufsize;
3404 if (ch->ch_digi.digi_onlen > DIGI_PLEN)
3405 ch->ch_digi.digi_onlen = DIGI_PLEN;
3407 if (ch->ch_digi.digi_offlen > DIGI_PLEN)
3408 ch->ch_digi.digi_offlen = DIGI_PLEN;
3412 spin_unlock_irqrestore(&ch->ch_lock, lock_flags2);
3413 spin_unlock_irqrestore(&bd->bd_lock, lock_flags);
3419 * dgap_tty_digigetedelay()
3421 * Ioctl to get the current edelay setting.
3426 static int dgap_tty_digigetedelay(struct tty_struct *tty, int __user *retinfo)
3428 struct channel_t *ch;
3436 if (!tty || tty->magic != TTY_MAGIC)
3439 un = tty->driver_data;
3440 if (!un || un->magic != DGAP_UNIT_MAGIC)
3444 if (!ch || ch->magic != DGAP_CHANNEL_MAGIC)
3447 memset(&tmp, 0, sizeof(tmp));
3449 spin_lock_irqsave(&ch->ch_lock, lock_flags);
3450 tmp = readw(&(ch->ch_bs->edelay));
3451 spin_unlock_irqrestore(&ch->ch_lock, lock_flags);
3453 if (copy_to_user(retinfo, &tmp, sizeof(*retinfo)))
3460 * dgap_tty_digisetedelay()
3462 * Ioctl to set the EDELAY setting
3465 static int dgap_tty_digisetedelay(struct tty_struct *tty, int __user *new_info)
3468 struct channel_t *ch;
3474 if (!tty || tty->magic != TTY_MAGIC)
3477 un = tty->driver_data;
3478 if (!un || un->magic != DGAP_UNIT_MAGIC)
3482 if (!ch || ch->magic != DGAP_CHANNEL_MAGIC)
3486 if (!bd || bd->magic != DGAP_BOARD_MAGIC)
3489 if (copy_from_user(&new_digi, new_info, sizeof(int)))
3492 spin_lock_irqsave(&bd->bd_lock, lock_flags);
3493 spin_lock_irqsave(&ch->ch_lock, lock_flags2);
3495 writew((u16) new_digi, &(ch->ch_bs->edelay));
3499 spin_unlock_irqrestore(&ch->ch_lock, lock_flags2);
3500 spin_unlock_irqrestore(&bd->bd_lock, lock_flags);
3506 * dgap_tty_digigetcustombaud()
3508 * Ioctl to get the current custom baud rate setting.
3510 static int dgap_tty_digigetcustombaud(struct tty_struct *tty,
3511 int __user *retinfo)
3513 struct channel_t *ch;
3521 if (!tty || tty->magic != TTY_MAGIC)
3524 un = tty->driver_data;
3525 if (!un || un->magic != DGAP_UNIT_MAGIC)
3529 if (!ch || ch->magic != DGAP_CHANNEL_MAGIC)
3532 memset(&tmp, 0, sizeof(tmp));
3534 spin_lock_irqsave(&ch->ch_lock, lock_flags);
3535 tmp = dgap_get_custom_baud(ch);
3536 spin_unlock_irqrestore(&ch->ch_lock, lock_flags);
3538 if (copy_to_user(retinfo, &tmp, sizeof(*retinfo)))
3545 * dgap_tty_digisetcustombaud()
3547 * Ioctl to set the custom baud rate setting
3549 static int dgap_tty_digisetcustombaud(struct tty_struct *tty,
3550 int __user *new_info)
3553 struct channel_t *ch;
3559 if (!tty || tty->magic != TTY_MAGIC)
3562 un = tty->driver_data;
3563 if (!un || un->magic != DGAP_UNIT_MAGIC)
3567 if (!ch || ch->magic != DGAP_CHANNEL_MAGIC)
3571 if (!bd || bd->magic != DGAP_BOARD_MAGIC)
3575 if (copy_from_user(&new_rate, new_info, sizeof(unsigned int)))
3578 if (bd->bd_flags & BD_FEP5PLUS) {
3580 spin_lock_irqsave(&bd->bd_lock, lock_flags);
3581 spin_lock_irqsave(&ch->ch_lock, lock_flags2);
3583 ch->ch_custom_speed = new_rate;
3587 spin_unlock_irqrestore(&ch->ch_lock, lock_flags2);
3588 spin_unlock_irqrestore(&bd->bd_lock, lock_flags);
3595 * dgap_set_termios()
3597 static void dgap_tty_set_termios(struct tty_struct *tty,
3598 struct ktermios *old_termios)
3601 struct channel_t *ch;
3603 unsigned long lock_flags;
3604 unsigned long lock_flags2;
3606 if (!tty || tty->magic != TTY_MAGIC)
3609 un = tty->driver_data;
3610 if (!un || un->magic != DGAP_UNIT_MAGIC)
3614 if (!ch || ch->magic != DGAP_CHANNEL_MAGIC)
3618 if (!bd || bd->magic != DGAP_BOARD_MAGIC)
3621 spin_lock_irqsave(&bd->bd_lock, lock_flags);
3622 spin_lock_irqsave(&ch->ch_lock, lock_flags2);
3624 ch->ch_c_cflag = tty->termios.c_cflag;
3625 ch->ch_c_iflag = tty->termios.c_iflag;
3626 ch->ch_c_oflag = tty->termios.c_oflag;
3627 ch->ch_c_lflag = tty->termios.c_lflag;
3628 ch->ch_startc = tty->termios.c_cc[VSTART];
3629 ch->ch_stopc = tty->termios.c_cc[VSTOP];
3634 spin_unlock_irqrestore(&ch->ch_lock, lock_flags2);
3635 spin_unlock_irqrestore(&bd->bd_lock, lock_flags);
3638 static void dgap_tty_throttle(struct tty_struct *tty)
3641 struct channel_t *ch;
3646 if (!tty || tty->magic != TTY_MAGIC)
3649 un = tty->driver_data;
3650 if (!un || un->magic != DGAP_UNIT_MAGIC)
3654 if (!ch || ch->magic != DGAP_CHANNEL_MAGIC)
3658 if (!bd || bd->magic != DGAP_BOARD_MAGIC)
3661 spin_lock_irqsave(&bd->bd_lock, lock_flags);
3662 spin_lock_irqsave(&ch->ch_lock, lock_flags2);
3664 ch->ch_flags |= (CH_RXBLOCK);
3666 dgap_cmdw(ch, RPAUSE, 0, 0);
3669 spin_unlock_irqrestore(&ch->ch_lock, lock_flags2);
3670 spin_unlock_irqrestore(&bd->bd_lock, lock_flags);
3674 static void dgap_tty_unthrottle(struct tty_struct *tty)
3677 struct channel_t *ch;
3682 if (!tty || tty->magic != TTY_MAGIC)
3685 un = tty->driver_data;
3686 if (!un || un->magic != DGAP_UNIT_MAGIC)
3690 if (!ch || ch->magic != DGAP_CHANNEL_MAGIC)
3694 if (!bd || bd->magic != DGAP_BOARD_MAGIC)
3697 spin_lock_irqsave(&bd->bd_lock, lock_flags);
3698 spin_lock_irqsave(&ch->ch_lock, lock_flags2);
3700 ch->ch_flags &= ~(CH_RXBLOCK);
3703 dgap_cmdw(ch, RRESUME, 0, 0);
3706 spin_unlock_irqrestore(&ch->ch_lock, lock_flags2);
3707 spin_unlock_irqrestore(&bd->bd_lock, lock_flags);
3710 static void dgap_tty_start(struct tty_struct *tty)
3713 struct channel_t *ch;
3718 if (!tty || tty->magic != TTY_MAGIC)
3721 un = tty->driver_data;
3722 if (!un || un->magic != DGAP_UNIT_MAGIC)
3726 if (!ch || ch->magic != DGAP_CHANNEL_MAGIC)
3730 if (!bd || bd->magic != DGAP_BOARD_MAGIC)
3733 spin_lock_irqsave(&bd->bd_lock, lock_flags);
3734 spin_lock_irqsave(&ch->ch_lock, lock_flags2);
3736 dgap_cmdw(ch, RESUMETX, 0, 0);
3738 spin_unlock_irqrestore(&ch->ch_lock, lock_flags2);
3739 spin_unlock_irqrestore(&bd->bd_lock, lock_flags);
3743 static void dgap_tty_stop(struct tty_struct *tty)
3746 struct channel_t *ch;
3751 if (!tty || tty->magic != TTY_MAGIC)
3754 un = tty->driver_data;
3755 if (!un || un->magic != DGAP_UNIT_MAGIC)
3759 if (!ch || ch->magic != DGAP_CHANNEL_MAGIC)
3763 if (!bd || bd->magic != DGAP_BOARD_MAGIC)
3766 spin_lock_irqsave(&bd->bd_lock, lock_flags);
3767 spin_lock_irqsave(&ch->ch_lock, lock_flags2);
3769 dgap_cmdw(ch, PAUSETX, 0, 0);
3771 spin_unlock_irqrestore(&ch->ch_lock, lock_flags2);
3772 spin_unlock_irqrestore(&bd->bd_lock, lock_flags);
3777 * dgap_tty_flush_chars()
3779 * Flush the cook buffer
3781 * Note to self, and any other poor souls who venture here:
3783 * flush in this case DOES NOT mean dispose of the data.
3784 * instead, it means "stop buffering and send it if you
3785 * haven't already." Just guess how I figured that out... SRW 2-Jun-98
3787 * It is also always called in interrupt context - JAR 8-Sept-99
3789 static void dgap_tty_flush_chars(struct tty_struct *tty)
3792 struct channel_t *ch;
3797 if (!tty || tty->magic != TTY_MAGIC)
3800 un = tty->driver_data;
3801 if (!un || un->magic != DGAP_UNIT_MAGIC)
3805 if (!ch || ch->magic != DGAP_CHANNEL_MAGIC)
3809 if (!bd || bd->magic != DGAP_BOARD_MAGIC)
3812 spin_lock_irqsave(&bd->bd_lock, lock_flags);
3813 spin_lock_irqsave(&ch->ch_lock, lock_flags2);
3815 /* TODO: Do something here */
3817 spin_unlock_irqrestore(&ch->ch_lock, lock_flags2);
3818 spin_unlock_irqrestore(&bd->bd_lock, lock_flags);
3822 * dgap_tty_flush_buffer()
3824 * Flush Tx buffer (make in == out)
3826 static void dgap_tty_flush_buffer(struct tty_struct *tty)
3829 struct channel_t *ch;
3835 if (!tty || tty->magic != TTY_MAGIC)
3838 un = tty->driver_data;
3839 if (!un || un->magic != DGAP_UNIT_MAGIC)
3843 if (!ch || ch->magic != DGAP_CHANNEL_MAGIC)
3847 if (!bd || bd->magic != DGAP_BOARD_MAGIC)
3850 spin_lock_irqsave(&bd->bd_lock, lock_flags);
3851 spin_lock_irqsave(&ch->ch_lock, lock_flags2);
3853 ch->ch_flags &= ~CH_STOP;
3854 head = readw(&(ch->ch_bs->tx_head));
3855 dgap_cmdw(ch, FLUSHTX, (u16) head, 0);
3856 dgap_cmdw(ch, RESUMETX, 0, 0);
3857 if (ch->ch_tun.un_flags & (UN_LOW|UN_EMPTY)) {
3858 ch->ch_tun.un_flags &= ~(UN_LOW|UN_EMPTY);
3859 wake_up_interruptible(&ch->ch_tun.un_flags_wait);
3861 if (ch->ch_pun.un_flags & (UN_LOW|UN_EMPTY)) {
3862 ch->ch_pun.un_flags &= ~(UN_LOW|UN_EMPTY);
3863 wake_up_interruptible(&ch->ch_pun.un_flags_wait);
3866 spin_unlock_irqrestore(&ch->ch_lock, lock_flags2);
3867 spin_unlock_irqrestore(&bd->bd_lock, lock_flags);
3868 if (waitqueue_active(&tty->write_wait))
3869 wake_up_interruptible(&tty->write_wait);
3873 /*****************************************************************************
3875 * The IOCTL function and all of its helpers
3877 *****************************************************************************/
3882 * The usual assortment of ioctl's
3884 static int dgap_tty_ioctl(struct tty_struct *tty, unsigned int cmd,
3888 struct channel_t *ch;
3892 ulong lock_flags = 0;
3893 ulong lock_flags2 = 0;
3894 void __user *uarg = (void __user *) arg;
3896 if (!tty || tty->magic != TTY_MAGIC)
3899 un = tty->driver_data;
3900 if (!un || un->magic != DGAP_UNIT_MAGIC)
3904 if (!ch || ch->magic != DGAP_CHANNEL_MAGIC)
3908 if (!bd || bd->magic != DGAP_BOARD_MAGIC)
3911 spin_lock_irqsave(&bd->bd_lock, lock_flags);
3912 spin_lock_irqsave(&ch->ch_lock, lock_flags2);
3914 if (un->un_open_count <= 0) {
3915 spin_unlock_irqrestore(&ch->ch_lock, lock_flags2);
3916 spin_unlock_irqrestore(&bd->bd_lock, lock_flags);
3922 /* Here are all the standard ioctl's that we MUST implement */
3926 * TCSBRK is SVID version: non-zero arg --> no break
3927 * this behaviour is exploited by tcdrain().
3929 * According to POSIX.1 spec (7.2.2.1.2) breaks should be
3930 * between 0.25 and 0.5 seconds so we'll ask for something
3931 * in the middle: 0.375 seconds.
3933 rc = tty_check_change(tty);
3934 spin_unlock_irqrestore(&ch->ch_lock, lock_flags2);
3935 spin_unlock_irqrestore(&bd->bd_lock, lock_flags);
3939 rc = dgap_wait_for_drain(tty);
3944 spin_lock_irqsave(&bd->bd_lock, lock_flags);
3945 spin_lock_irqsave(&ch->ch_lock, lock_flags2);
3947 if (((cmd == TCSBRK) && (!arg)) || (cmd == TCSBRKP))
3948 dgap_cmdw(ch, SBREAK, (u16) SBREAK_TIME, 0);
3950 spin_unlock_irqrestore(&ch->ch_lock, lock_flags2);
3951 spin_unlock_irqrestore(&bd->bd_lock, lock_flags);
3956 /* support for POSIX tcsendbreak()
3958 * According to POSIX.1 spec (7.2.2.1.2) breaks should be
3959 * between 0.25 and 0.5 seconds so we'll ask for something
3960 * in the middle: 0.375 seconds.
3962 rc = tty_check_change(tty);
3963 spin_unlock_irqrestore(&ch->ch_lock, lock_flags2);
3964 spin_unlock_irqrestore(&bd->bd_lock, lock_flags);
3968 rc = dgap_wait_for_drain(tty);
3972 spin_lock_irqsave(&bd->bd_lock, lock_flags);
3973 spin_lock_irqsave(&ch->ch_lock, lock_flags2);
3975 dgap_cmdw(ch, SBREAK, (u16) SBREAK_TIME, 0);
3977 spin_unlock_irqrestore(&ch->ch_lock, lock_flags2);
3978 spin_unlock_irqrestore(&bd->bd_lock, lock_flags);
3984 * FEP5 doesn't support turning on a break unconditionally.
3985 * The FEP5 device will stop sending a break automatically
3986 * after the specified time value that was sent when turning on
3989 rc = tty_check_change(tty);
3990 spin_unlock_irqrestore(&ch->ch_lock, lock_flags2);
3991 spin_unlock_irqrestore(&bd->bd_lock, lock_flags);
3995 rc = dgap_wait_for_drain(tty);
3999 spin_lock_irqsave(&bd->bd_lock, lock_flags);
4000 spin_lock_irqsave(&ch->ch_lock, lock_flags2);
4002 dgap_cmdw(ch, SBREAK, (u16) SBREAK_TIME, 0);
4004 spin_unlock_irqrestore(&ch->ch_lock, lock_flags2);
4005 spin_unlock_irqrestore(&bd->bd_lock, lock_flags);
4011 * FEP5 doesn't support turning off a break unconditionally.
4012 * The FEP5 device will stop sending a break automatically
4013 * after the specified time value that was sent when turning on
4016 spin_unlock_irqrestore(&ch->ch_lock, lock_flags2);
4017 spin_unlock_irqrestore(&bd->bd_lock, lock_flags);
4022 spin_unlock_irqrestore(&ch->ch_lock, lock_flags2);
4023 spin_unlock_irqrestore(&bd->bd_lock, lock_flags);
4025 rc = put_user(C_CLOCAL(tty) ? 1 : 0,
4026 (unsigned long __user *) arg);
4030 spin_unlock_irqrestore(&ch->ch_lock, lock_flags2);
4031 spin_unlock_irqrestore(&bd->bd_lock, lock_flags);
4033 rc = get_user(arg, (unsigned long __user *) arg);
4037 spin_lock_irqsave(&bd->bd_lock, lock_flags);
4038 spin_lock_irqsave(&ch->ch_lock, lock_flags2);
4039 tty->termios.c_cflag = ((tty->termios.c_cflag & ~CLOCAL) |
4040 (arg ? CLOCAL : 0));
4042 spin_unlock_irqrestore(&ch->ch_lock, lock_flags2);
4043 spin_unlock_irqrestore(&bd->bd_lock, lock_flags);
4048 spin_unlock_irqrestore(&ch->ch_lock, lock_flags2);
4049 spin_unlock_irqrestore(&bd->bd_lock, lock_flags);
4050 return dgap_get_modem_info(ch, uarg);
4055 spin_unlock_irqrestore(&ch->ch_lock, lock_flags2);
4056 spin_unlock_irqrestore(&bd->bd_lock, lock_flags);
4057 return dgap_set_modem_info(tty, cmd, uarg);
4060 * Here are any additional ioctl's that we want to implement
4065 * The linux tty driver doesn't have a flush
4066 * input routine for the driver, assuming all backed
4067 * up data is in the line disc. buffers. However,
4068 * we all know that's not the case. Here, we
4069 * act on the ioctl, but then lie and say we didn't
4070 * so the line discipline will process the flush
4073 rc = tty_check_change(tty);
4075 spin_unlock_irqrestore(&ch->ch_lock, lock_flags2);
4076 spin_unlock_irqrestore(&bd->bd_lock, lock_flags);
4080 if ((arg == TCIFLUSH) || (arg == TCIOFLUSH)) {
4081 if (!(un->un_type == DGAP_PRINT)) {
4082 head = readw(&(ch->ch_bs->rx_head));
4083 writew(head, &(ch->ch_bs->rx_tail));
4084 writeb(0, &(ch->ch_bs->orun));
4088 if ((arg != TCOFLUSH) && (arg != TCIOFLUSH)) {
4089 /* pretend we didn't recognize this IOCTL */
4090 spin_unlock_irqrestore(&ch->ch_lock, lock_flags2);
4091 spin_unlock_irqrestore(&bd->bd_lock, lock_flags);
4093 return -ENOIOCTLCMD;
4096 ch->ch_flags &= ~CH_STOP;
4097 head = readw(&(ch->ch_bs->tx_head));
4098 dgap_cmdw(ch, FLUSHTX, (u16) head, 0);
4099 dgap_cmdw(ch, RESUMETX, 0, 0);
4100 if (ch->ch_tun.un_flags & (UN_LOW|UN_EMPTY)) {
4101 ch->ch_tun.un_flags &= ~(UN_LOW|UN_EMPTY);
4102 wake_up_interruptible(&ch->ch_tun.un_flags_wait);
4104 if (ch->ch_pun.un_flags & (UN_LOW|UN_EMPTY)) {
4105 ch->ch_pun.un_flags &= ~(UN_LOW|UN_EMPTY);
4106 wake_up_interruptible(&ch->ch_pun.un_flags_wait);
4108 if (waitqueue_active(&tty->write_wait))
4109 wake_up_interruptible(&tty->write_wait);
4111 /* Can't hold any locks when calling tty_wakeup! */
4112 spin_unlock_irqrestore(&ch->ch_lock, lock_flags2);
4113 spin_unlock_irqrestore(&bd->bd_lock, lock_flags);
4116 /* pretend we didn't recognize this IOCTL */
4117 return -ENOIOCTLCMD;
4122 * The linux tty driver doesn't have a flush
4123 * input routine for the driver, assuming all backed
4124 * up data is in the line disc. buffers. However,
4125 * we all know that's not the case. Here, we
4126 * act on the ioctl, but then lie and say we didn't
4127 * so the line discipline will process the flush
4130 if (cmd == TCSETSF) {
4132 ch->ch_flags &= ~CH_STOP;
4133 head = readw(&(ch->ch_bs->rx_head));
4134 writew(head, &(ch->ch_bs->rx_tail));
4137 /* now wait for all the output to drain */
4138 spin_unlock_irqrestore(&ch->ch_lock, lock_flags2);
4139 spin_unlock_irqrestore(&bd->bd_lock, lock_flags);
4140 rc = dgap_wait_for_drain(tty);
4144 /* pretend we didn't recognize this */
4145 return -ENOIOCTLCMD;
4149 spin_unlock_irqrestore(&ch->ch_lock, lock_flags2);
4150 spin_unlock_irqrestore(&bd->bd_lock, lock_flags);
4151 rc = dgap_wait_for_drain(tty);
4155 /* pretend we didn't recognize this */
4156 return -ENOIOCTLCMD;
4160 * The Linux Line Discipline (LD) would do this for us if we
4161 * let it, but we have the special firmware options to do this
4162 * the "right way" regardless of hardware or software flow
4163 * control so we'll do it outselves instead of letting the LD
4166 rc = tty_check_change(tty);
4168 spin_unlock_irqrestore(&ch->ch_lock, lock_flags2);
4169 spin_unlock_irqrestore(&bd->bd_lock, lock_flags);
4176 spin_unlock_irqrestore(&ch->ch_lock, lock_flags2);
4177 spin_unlock_irqrestore(&bd->bd_lock, lock_flags);
4178 dgap_tty_start(tty);
4181 spin_unlock_irqrestore(&ch->ch_lock, lock_flags2);
4182 spin_unlock_irqrestore(&bd->bd_lock, lock_flags);
4186 spin_unlock_irqrestore(&ch->ch_lock, lock_flags2);
4187 spin_unlock_irqrestore(&bd->bd_lock, lock_flags);
4188 /* Make the ld do it */
4189 return -ENOIOCTLCMD;
4191 spin_unlock_irqrestore(&ch->ch_lock, lock_flags2);
4192 spin_unlock_irqrestore(&bd->bd_lock, lock_flags);
4193 /* Make the ld do it */
4194 return -ENOIOCTLCMD;
4196 spin_unlock_irqrestore(&ch->ch_lock, lock_flags2);
4197 spin_unlock_irqrestore(&bd->bd_lock, lock_flags);
4202 /* get information for ditty */
4203 spin_unlock_irqrestore(&ch->ch_lock, lock_flags2);
4204 spin_unlock_irqrestore(&bd->bd_lock, lock_flags);
4205 return dgap_tty_digigeta(tty, uarg);
4210 /* set information for ditty */
4211 if (cmd == (DIGI_SETAW)) {
4213 spin_unlock_irqrestore(&ch->ch_lock, lock_flags2);
4214 spin_unlock_irqrestore(&bd->bd_lock, lock_flags);
4215 rc = dgap_wait_for_drain(tty);
4218 spin_lock_irqsave(&bd->bd_lock, lock_flags);
4219 spin_lock_irqsave(&ch->ch_lock, lock_flags2);
4221 tty_ldisc_flush(tty);
4225 spin_unlock_irqrestore(&ch->ch_lock, lock_flags2);
4226 spin_unlock_irqrestore(&bd->bd_lock, lock_flags);
4227 return dgap_tty_digiseta(tty, uarg);
4230 spin_unlock_irqrestore(&ch->ch_lock, lock_flags2);
4231 spin_unlock_irqrestore(&bd->bd_lock, lock_flags);
4232 return dgap_tty_digigetedelay(tty, uarg);
4235 spin_unlock_irqrestore(&ch->ch_lock, lock_flags2);
4236 spin_unlock_irqrestore(&bd->bd_lock, lock_flags);
4237 return dgap_tty_digisetedelay(tty, uarg);
4239 case DIGI_GETCUSTOMBAUD:
4240 spin_unlock_irqrestore(&ch->ch_lock, lock_flags2);
4241 spin_unlock_irqrestore(&bd->bd_lock, lock_flags);
4242 return dgap_tty_digigetcustombaud(tty, uarg);
4244 case DIGI_SETCUSTOMBAUD:
4245 spin_unlock_irqrestore(&ch->ch_lock, lock_flags2);
4246 spin_unlock_irqrestore(&bd->bd_lock, lock_flags);
4247 return dgap_tty_digisetcustombaud(tty, uarg);
4249 case DIGI_RESET_PORT:
4250 dgap_firmware_reset_port(ch);
4252 spin_unlock_irqrestore(&ch->ch_lock, lock_flags2);
4253 spin_unlock_irqrestore(&bd->bd_lock, lock_flags);
4257 spin_unlock_irqrestore(&ch->ch_lock, lock_flags2);
4258 spin_unlock_irqrestore(&bd->bd_lock, lock_flags);
4260 return -ENOIOCTLCMD;
4264 static int dgap_after_config_loaded(int board)
4267 * Initialize KME waitqueues...
4269 init_waitqueue_head(&(dgap_Board[board]->kme_wait));
4272 * allocate flip buffer for board.
4274 dgap_Board[board]->flipbuf = kmalloc(MYFLIPLEN, GFP_ATOMIC);
4275 if (!dgap_Board[board]->flipbuf)
4278 dgap_Board[board]->flipflagbuf = kmalloc(MYFLIPLEN, GFP_ATOMIC);
4279 if (!dgap_Board[board]->flipflagbuf) {
4280 kfree(dgap_Board[board]->flipbuf);
4288 * Create pr and tty device entries
4290 static int dgap_tty_register_ports(struct board_t *brd)
4292 struct channel_t *ch;
4295 brd->SerialPorts = kcalloc(brd->nasync, sizeof(*brd->SerialPorts),
4297 if (brd->SerialPorts == NULL)
4299 for (i = 0; i < brd->nasync; i++)
4300 tty_port_init(&brd->SerialPorts[i]);
4302 brd->PrinterPorts = kcalloc(brd->nasync, sizeof(*brd->PrinterPorts),
4304 if (brd->PrinterPorts == NULL) {
4305 kfree(brd->SerialPorts);
4308 for (i = 0; i < brd->nasync; i++)
4309 tty_port_init(&brd->PrinterPorts[i]);
4311 ch = brd->channels[0];
4312 for (i = 0; i < brd->nasync; i++, ch = brd->channels[i]) {
4314 struct device *classp;
4316 classp = tty_port_register_device(&brd->SerialPorts[i],
4318 brd->firstminor + i, NULL);
4320 dgap_create_tty_sysfs(&ch->ch_tun, classp);
4321 ch->ch_tun.un_sysfs = classp;
4323 classp = tty_port_register_device(&brd->PrinterPorts[i],
4325 brd->firstminor + i, NULL);
4327 dgap_create_tty_sysfs(&ch->ch_pun, classp);
4328 ch->ch_pun.un_sysfs = classp;
4330 dgap_create_ports_sysfiles(brd);
4336 * Copies the BIOS code from the user to the board,
4337 * and starts the BIOS running.
4339 static void dgap_do_bios_load(struct board_t *brd, const uchar *ubios, int len)
4345 if (!brd || (brd->magic != DGAP_BOARD_MAGIC) || !brd->re_map_membase)
4348 addr = brd->re_map_membase;
4353 for (i = 0; i < 16; i++)
4354 writeb(0, addr + POSTAREA + i);
4360 memcpy_toio(addr + offset, ubios, len);
4362 writel(0x0bf00401, addr);
4363 writel(0, (addr + 4));
4365 /* Clear the reset, and change states. */
4366 writeb(FEPCLR, brd->re_map_port);
4370 * Checks to see if the BIOS completed running on the card.
4372 static int dgap_do_wait_for_bios(struct board_t *brd)
4380 if (!brd || (brd->magic != DGAP_BOARD_MAGIC) || !brd->re_map_membase)
4383 addr = brd->re_map_membase;
4384 word = readw(addr + POSTAREA);
4387 * It can take 5-6 seconds for a board to
4388 * pass the bios self test and post results.
4389 * Give it 10 seconds.
4391 brd->wait_for_bios = 0;
4392 while (brd->wait_for_bios < 1000) {
4393 /* Check to see if BIOS thinks board is good. (GD). */
4394 if (word == *(u16 *) "GD")
4396 msleep_interruptible(10);
4397 brd->wait_for_bios++;
4398 word = readw(addr + POSTAREA);
4401 /* Gave up on board after too long of time taken */
4402 err1 = readw(addr + SEQUENCE);
4403 err2 = readw(addr + ERROR);
4404 pr_warn("dgap: %s failed diagnostics. Error #(%x,%x).\n",
4405 brd->name, err1, err2);
4406 brd->state = BOARD_FAILED;
4407 brd->dpastatus = BD_NOBIOS;
4413 * Copies the FEP code from the user to the board,
4414 * and starts the FEP running.
4416 static void dgap_do_fep_load(struct board_t *brd, const uchar *ufep, int len)
4421 if (!brd || (brd->magic != DGAP_BOARD_MAGIC) || !brd->re_map_membase)
4424 addr = brd->re_map_membase;
4430 memcpy_toio(addr + offset, ufep, len);
4433 * If board is a concentrator product, we need to give
4434 * it its config string describing how the concentrators look.
4436 if ((brd->type == PCX) || (brd->type == PEPC)) {
4438 uchar *config, *xconfig;
4441 xconfig = dgap_create_config_string(brd, string);
4443 /* Write string to board memory */
4444 config = addr + CONFIG;
4445 for (; i < CONFIGSIZE; i++, config++, xconfig++) {
4446 writeb(*xconfig, config);
4447 if ((*xconfig & 0xff) == 0xff)
4452 writel(0xbfc01004, (addr + 0xc34));
4453 writel(0x3, (addr + 0xc30));
4458 * Waits for the FEP to report thats its ready for us to use.
4460 static int dgap_do_wait_for_fep(struct board_t *brd)
4468 if (!brd || (brd->magic != DGAP_BOARD_MAGIC) || !brd->re_map_membase)
4471 addr = brd->re_map_membase;
4472 word = readw(addr + FEPSTAT);
4475 * It can take 2-3 seconds for the FEP to
4476 * be up and running. Give it 5 secs.
4478 brd->wait_for_fep = 0;
4479 while (brd->wait_for_fep < 500) {
4480 /* Check to see if FEP is up and running now. */
4481 if (word == *(u16 *) "OS") {
4483 * Check to see if the board can support FEP5+ commands.
4485 word = readw(addr + FEP5_PLUS);
4486 if (word == *(u16 *) "5A")
4487 brd->bd_flags |= BD_FEP5PLUS;
4491 msleep_interruptible(10);
4492 brd->wait_for_fep++;
4493 word = readw(addr + FEPSTAT);
4496 /* Gave up on board after too long of time taken */
4497 err1 = readw(addr + SEQUENCE);
4498 err2 = readw(addr + ERROR);
4499 pr_warn("dgap: FEPOS for %s not functioning. Error #(%x,%x).\n",
4500 brd->name, err1, err2);
4501 brd->state = BOARD_FAILED;
4502 brd->dpastatus = BD_NOFEP;
4508 * Physically forces the FEP5 card to reset itself.
4510 static void dgap_do_reset_board(struct board_t *brd)
4517 if (!brd || (brd->magic != DGAP_BOARD_MAGIC) ||
4518 !brd->re_map_membase || !brd->re_map_port)
4521 /* FEPRST does not vary among supported boards */
4522 writeb(FEPRST, brd->re_map_port);
4524 for (i = 0; i <= 1000; i++) {
4525 check = readb(brd->re_map_port) & 0xe;
4526 if (check == FEPRST)
4532 pr_warn("dgap: Board not resetting... Failing board.\n");
4533 brd->state = BOARD_FAILED;
4534 brd->dpastatus = BD_NOFEP;
4539 * Make sure there really is memory out there.
4541 writel(0xa55a3cc3, (brd->re_map_membase + LOWMEM));
4542 writel(0x5aa5c33c, (brd->re_map_membase + HIGHMEM));
4543 check1 = readl(brd->re_map_membase + LOWMEM);
4544 check2 = readl(brd->re_map_membase + HIGHMEM);
4546 if ((check1 != 0xa55a3cc3) || (check2 != 0x5aa5c33c)) {
4547 pr_warn("dgap: No memory at %p for board.\n",
4548 brd->re_map_membase);
4549 brd->state = BOARD_FAILED;
4550 brd->dpastatus = BD_NOFEP;
4556 #ifdef DIGI_CONCENTRATORS_SUPPORTED
4558 * Sends a concentrator image into the FEP5 board.
4560 static void dgap_do_conc_load(struct board_t *brd, uchar *uaddr, int len)
4564 struct downld_t *to_dp;
4566 if (!brd || (brd->magic != DGAP_BOARD_MAGIC) || !brd->re_map_membase)
4569 vaddr = brd->re_map_membase;
4571 offset = readw((u16 *) (vaddr + DOWNREQ));
4572 to_dp = (struct downld_t *) (vaddr + (int) offset);
4573 memcpy_toio(to_dp, uaddr, len);
4575 /* Tell card we have data for it */
4576 writew(0, vaddr + (DOWNREQ));
4578 brd->conc_dl_status = NO_PENDING_CONCENTRATOR_REQUESTS;
4582 #define EXPANSION_ROM_SIZE (64 * 1024)
4583 #define FEP5_ROM_MAGIC (0xFEFFFFFF)
4585 static void dgap_get_vpd(struct board_t *brd)
4597 * Poke the magic number at the PCI Rom Address location.
4598 * If VPD is supported, the value read from that address
4601 magic = FEP5_ROM_MAGIC;
4602 pci_write_config_dword(brd->pdev, PCI_ROM_ADDRESS, magic);
4603 pci_read_config_dword(brd->pdev, PCI_ROM_ADDRESS, &magic);
4605 /* VPD not supported, bail */
4610 * To get to the OTPROM memory, we have to send the boards base
4611 * address or'ed with 1 into the PCI Rom Address location.
4613 magic = brd->membase | 0x01;
4614 pci_write_config_dword(brd->pdev, PCI_ROM_ADDRESS, magic);
4615 pci_read_config_dword(brd->pdev, PCI_ROM_ADDRESS, &magic);
4617 byte1 = readb(brd->re_map_membase);
4618 byte2 = readb(brd->re_map_membase + 1);
4621 * If the board correctly swapped to the OTPROM memory,
4622 * the first 2 bytes (header) should be 0x55, 0xAA
4624 if (byte1 == 0x55 && byte2 == 0xAA) {
4629 * We have to run through all the OTPROM memory looking
4630 * for the VPD offset.
4632 while (base_offset <= EXPANSION_ROM_SIZE) {
4635 * Lots of magic numbers here.
4637 * The VPD offset is located inside the ROM Data
4640 * We also have to remember the length of each
4641 * ROM Data Structure, so we can "hop" to the next
4642 * entry if the VPD isn't in the current
4643 * ROM Data Structure.
4645 rom_offset = readw(brd->re_map_membase +
4646 base_offset + 0x18);
4647 image_length = readw(brd->re_map_membase +
4648 rom_offset + 0x10) * 512;
4649 vpd_offset = readw(brd->re_map_membase +
4652 /* Found the VPD entry */
4656 /* We didn't find a VPD entry, go to next ROM entry. */
4657 base_offset += image_length;
4659 byte1 = readb(brd->re_map_membase + base_offset);
4660 byte2 = readb(brd->re_map_membase + base_offset + 1);
4663 * If the new ROM offset doesn't have 0x55, 0xAA
4664 * as its header, we have run out of ROM.
4666 if (byte1 != 0x55 || byte2 != 0xAA)
4671 * If we have a VPD offset, then mark the board
4672 * as having a valid VPD, and copy VPDSIZE (512) bytes of
4673 * that VPD to the buffer we have in our board structure.
4676 brd->bd_flags |= BD_HAS_VPD;
4677 for (i = 0; i < VPDSIZE; i++) {
4678 brd->vpd[i] = readb(brd->re_map_membase +
4685 * We MUST poke the magic number at the PCI Rom Address location again.
4686 * This makes the card report the regular board memory back to us,
4687 * rather than the OTPROM memory.
4689 magic = FEP5_ROM_MAGIC;
4690 pci_write_config_dword(brd->pdev, PCI_ROM_ADDRESS, magic);
4694 * Our board poller function.
4696 static void dgap_poll_tasklet(unsigned long data)
4698 struct board_t *bd = (struct board_t *) data;
4703 if (!bd || (bd->magic != DGAP_BOARD_MAGIC))
4706 if (bd->inhibit_poller)
4709 spin_lock_irqsave(&bd->bd_lock, lock_flags);
4711 vaddr = bd->re_map_membase;
4714 * If board is ready, parse deeper to see if there is anything to do.
4716 if (bd->state == BOARD_READY) {
4718 struct ev_t *eaddr = NULL;
4720 if (!bd->re_map_membase) {
4721 spin_unlock_irqrestore(&bd->bd_lock, lock_flags);
4724 if (!bd->re_map_port) {
4725 spin_unlock_irqrestore(&bd->bd_lock, lock_flags);
4732 eaddr = (struct ev_t *) (vaddr + EVBUF);
4734 /* Get our head and tail */
4735 head = readw(&(eaddr->ev_head));
4736 tail = readw(&(eaddr->ev_tail));
4739 * If there is an event pending. Go service it.
4742 spin_unlock_irqrestore(&bd->bd_lock, lock_flags);
4744 spin_lock_irqsave(&bd->bd_lock, lock_flags);
4749 * If board is doing interrupts, ACK the interrupt.
4751 if (bd && bd->intr_running)
4752 readb(bd->re_map_port + 2);
4754 spin_unlock_irqrestore(&bd->bd_lock, lock_flags);
4758 spin_unlock_irqrestore(&bd->bd_lock, lock_flags);
4761 /*=======================================================================
4763 * dgap_cmdb - Sends a 2 byte command to the FEP.
4765 * ch - Pointer to channel structure.
4766 * cmd - Command to be sent.
4767 * byte1 - Integer containing first byte to be sent.
4768 * byte2 - Integer containing second byte to be sent.
4769 * ncmds - Wait until ncmds or fewer cmds are left
4770 * in the cmd buffer before returning.
4772 *=======================================================================*/
4773 static void dgap_cmdb(struct channel_t *ch, uchar cmd, uchar byte1,
4774 uchar byte2, uint ncmds)
4777 struct cm_t *cm_addr = NULL;
4783 if (!ch || ch->magic != DGAP_CHANNEL_MAGIC)
4787 * Check if board is still alive.
4789 if (ch->ch_bd->state == BOARD_FAILED)
4793 * Make sure the pointers are in range before
4794 * writing to the FEP memory.
4796 vaddr = ch->ch_bd->re_map_membase;
4801 cm_addr = (struct cm_t *) (vaddr + CMDBUF);
4802 head = readw(&(cm_addr->cm_head));
4805 * Forget it if pointers out of range.
4807 if (head >= (CMDMAX - CMDSTART) || (head & 03)) {
4808 ch->ch_bd->state = BOARD_FAILED;
4813 * Put the data in the circular command buffer.
4815 writeb(cmd, (char *) (vaddr + head + CMDSTART + 0));
4816 writeb((uchar) ch->ch_portnum, (char *) (vaddr + head + CMDSTART + 1));
4817 writeb(byte1, (char *) (vaddr + head + CMDSTART + 2));
4818 writeb(byte2, (char *) (vaddr + head + CMDSTART + 3));
4820 head = (head + 4) & (CMDMAX - CMDSTART - 4);
4822 writew(head, &(cm_addr->cm_head));
4825 * Wait if necessary before updating the head
4826 * pointer to limit the number of outstanding
4827 * commands to the FEP. If the time spent waiting
4828 * is outlandish, declare the FEP dead.
4830 for (count = dgap_count ;;) {
4832 head = readw(&(cm_addr->cm_head));
4833 tail = readw(&(cm_addr->cm_tail));
4835 n = (head - tail) & (CMDMAX - CMDSTART - 4);
4837 if (n <= ncmds * sizeof(struct cm_t))
4841 ch->ch_bd->state = BOARD_FAILED;
4848 /*=======================================================================
4850 * dgap_cmdw - Sends a 1 word command to the FEP.
4852 * ch - Pointer to channel structure.
4853 * cmd - Command to be sent.
4854 * word - Integer containing word to be sent.
4855 * ncmds - Wait until ncmds or fewer cmds are left
4856 * in the cmd buffer before returning.
4858 *=======================================================================*/
4859 static void dgap_cmdw(struct channel_t *ch, uchar cmd, u16 word, uint ncmds)
4862 struct cm_t *cm_addr = NULL;
4868 if (!ch || ch->magic != DGAP_CHANNEL_MAGIC)
4872 * Check if board is still alive.
4874 if (ch->ch_bd->state == BOARD_FAILED)
4878 * Make sure the pointers are in range before
4879 * writing to the FEP memory.
4881 vaddr = ch->ch_bd->re_map_membase;
4885 cm_addr = (struct cm_t *) (vaddr + CMDBUF);
4886 head = readw(&(cm_addr->cm_head));
4889 * Forget it if pointers out of range.
4891 if (head >= (CMDMAX - CMDSTART) || (head & 03)) {
4892 ch->ch_bd->state = BOARD_FAILED;
4897 * Put the data in the circular command buffer.
4899 writeb(cmd, (char *) (vaddr + head + CMDSTART + 0));
4900 writeb((uchar) ch->ch_portnum, (char *) (vaddr + head + CMDSTART + 1));
4901 writew((u16) word, (char *) (vaddr + head + CMDSTART + 2));
4903 head = (head + 4) & (CMDMAX - CMDSTART - 4);
4905 writew(head, &(cm_addr->cm_head));
4908 * Wait if necessary before updating the head
4909 * pointer to limit the number of outstanding
4910 * commands to the FEP. If the time spent waiting
4911 * is outlandish, declare the FEP dead.
4913 for (count = dgap_count ;;) {
4915 head = readw(&(cm_addr->cm_head));
4916 tail = readw(&(cm_addr->cm_tail));
4918 n = (head - tail) & (CMDMAX - CMDSTART - 4);
4920 if (n <= ncmds * sizeof(struct cm_t))
4924 ch->ch_bd->state = BOARD_FAILED;
4931 /*=======================================================================
4933 * dgap_cmdw_ext - Sends a extended word command to the FEP.
4935 * ch - Pointer to channel structure.
4936 * cmd - Command to be sent.
4937 * word - Integer containing word to be sent.
4938 * ncmds - Wait until ncmds or fewer cmds are left
4939 * in the cmd buffer before returning.
4941 *=======================================================================*/
4942 static void dgap_cmdw_ext(struct channel_t *ch, u16 cmd, u16 word, uint ncmds)
4945 struct cm_t *cm_addr = NULL;
4951 if (!ch || ch->magic != DGAP_CHANNEL_MAGIC)
4955 * Check if board is still alive.
4957 if (ch->ch_bd->state == BOARD_FAILED)
4961 * Make sure the pointers are in range before
4962 * writing to the FEP memory.
4964 vaddr = ch->ch_bd->re_map_membase;
4968 cm_addr = (struct cm_t *) (vaddr + CMDBUF);
4969 head = readw(&(cm_addr->cm_head));
4972 * Forget it if pointers out of range.
4974 if (head >= (CMDMAX - CMDSTART) || (head & 03)) {
4975 ch->ch_bd->state = BOARD_FAILED;
4980 * Put the data in the circular command buffer.
4983 /* Write an FF to tell the FEP that we want an extended command */
4984 writeb((uchar) 0xff, (char *) (vaddr + head + CMDSTART + 0));
4986 writeb((uchar) ch->ch_portnum, (uchar *) (vaddr + head + CMDSTART + 1));
4987 writew((u16) cmd, (char *) (vaddr + head + CMDSTART + 2));
4990 * If the second part of the command won't fit,
4991 * put it at the beginning of the circular buffer.
4993 if (((head + 4) >= ((CMDMAX - CMDSTART)) || (head & 03)))
4994 writew((u16) word, (char *) (vaddr + CMDSTART));
4996 writew((u16) word, (char *) (vaddr + head + CMDSTART + 4));
4998 head = (head + 8) & (CMDMAX - CMDSTART - 4);
5000 writew(head, &(cm_addr->cm_head));
5003 * Wait if necessary before updating the head
5004 * pointer to limit the number of outstanding
5005 * commands to the FEP. If the time spent waiting
5006 * is outlandish, declare the FEP dead.
5008 for (count = dgap_count ;;) {
5010 head = readw(&(cm_addr->cm_head));
5011 tail = readw(&(cm_addr->cm_tail));
5013 n = (head - tail) & (CMDMAX - CMDSTART - 4);
5015 if (n <= ncmds * sizeof(struct cm_t))
5019 ch->ch_bd->state = BOARD_FAILED;
5026 /*=======================================================================
5028 * dgap_wmove - Write data to FEP buffer.
5030 * ch - Pointer to channel structure.
5031 * buf - Poiter to characters to be moved.
5032 * cnt - Number of characters to move.
5034 *=======================================================================*/
5035 static void dgap_wmove(struct channel_t *ch, char *buf, uint cnt)
5042 if (!ch || ch->magic != DGAP_CHANNEL_MAGIC)
5049 head = readw(&(bs->tx_head));
5052 * If pointers are out of range, just return.
5054 if ((cnt > ch->ch_tsize) ||
5055 (unsigned)(head - ch->ch_tstart) >= ch->ch_tsize)
5059 * If the write wraps over the top of the circular buffer,
5060 * move the portion up to the wrap point, and reset the
5061 * pointers to the bottom.
5063 n = ch->ch_tstart + ch->ch_tsize - head;
5067 taddr = ch->ch_taddr + head;
5068 memcpy_toio(taddr, buf, n);
5069 head = ch->ch_tstart;
5074 * Move rest of data.
5076 taddr = ch->ch_taddr + head;
5078 memcpy_toio(taddr, buf, n);
5081 writew(head, &(bs->tx_head));
5085 * Retrives the current custom baud rate from FEP memory,
5086 * and returns it back to the user.
5087 * Returns 0 on error.
5089 static uint dgap_get_custom_baud(struct channel_t *ch)
5095 if (!ch || ch->magic != DGAP_CHANNEL_MAGIC)
5098 if (!ch->ch_bd || ch->ch_bd->magic != DGAP_BOARD_MAGIC)
5101 if (!(ch->ch_bd->bd_flags & BD_FEP5PLUS))
5104 vaddr = ch->ch_bd->re_map_membase;
5110 * Go get from fep mem, what the fep
5111 * believes the custom baud rate is.
5113 offset = ((((*(unsigned short *)(vaddr + ECS_SEG)) << 4) +
5114 (ch->ch_portnum * 0x28) + LINE_SPEED));
5116 value = readw(vaddr + offset);
5121 * Calls the firmware to reset this channel.
5123 static void dgap_firmware_reset_port(struct channel_t *ch)
5125 dgap_cmdb(ch, CHRESET, 0, 0, 0);
5128 * Now that the channel is reset, we need to make sure
5129 * all the current settings get reapplied to the port
5132 * So we will set the driver's cache of firmware
5133 * settings all to 0, and then call param.
5135 ch->ch_fepiflag = 0;
5136 ch->ch_fepcflag = 0;
5137 ch->ch_fepoflag = 0;
5138 ch->ch_fepstartc = 0;
5139 ch->ch_fepstopc = 0;
5140 ch->ch_fepastartc = 0;
5141 ch->ch_fepastopc = 0;
5146 /*=======================================================================
5148 * dgap_param - Set Digi parameters.
5150 * struct tty_struct * - TTY for port.
5152 *=======================================================================*/
5153 static int dgap_param(struct tty_struct *tty)
5155 struct ktermios *ts;
5157 struct channel_t *ch;
5166 if (!tty || tty->magic != TTY_MAGIC)
5169 un = (struct un_t *) tty->driver_data;
5170 if (!un || un->magic != DGAP_UNIT_MAGIC)
5174 if (!ch || ch->magic != DGAP_CHANNEL_MAGIC)
5178 if (!bd || bd->magic != DGAP_BOARD_MAGIC)
5188 * If baud rate is zero, flush queues, and set mval to drop DTR.
5190 if ((ch->ch_c_cflag & (CBAUD)) == 0) {
5193 head = readw(&(ch->ch_bs->rx_head));
5194 writew(head, &(ch->ch_bs->rx_tail));
5197 head = readw(&(ch->ch_bs->tx_head));
5198 writew(head, &(ch->ch_bs->tx_tail));
5200 ch->ch_flags |= (CH_BAUD0);
5202 /* Drop RTS and DTR */
5203 ch->ch_mval &= ~(D_RTS(ch)|D_DTR(ch));
5204 mval = D_DTR(ch) | D_RTS(ch);
5205 ch->ch_baud_info = 0;
5207 } else if (ch->ch_custom_speed && (bd->bd_flags & BD_FEP5PLUS)) {
5209 * Tell the fep to do the command
5212 dgap_cmdw_ext(ch, 0xff01, ch->ch_custom_speed, 0);
5215 * Now go get from fep mem, what the fep
5216 * believes the custom baud rate is.
5218 ch->ch_custom_speed = dgap_get_custom_baud(ch);
5219 ch->ch_baud_info = ch->ch_custom_speed;
5221 /* Handle transition from B0 */
5222 if (ch->ch_flags & CH_BAUD0) {
5223 ch->ch_flags &= ~(CH_BAUD0);
5224 ch->ch_mval |= (D_RTS(ch)|D_DTR(ch));
5226 mval = D_DTR(ch) | D_RTS(ch);
5230 * Set baud rate, character size, and parity.
5238 ulong bauds[4][16] = {
5242 600, 1200, 1800, 2400,
5243 4800, 9600, 19200, 38400 },
5244 { /* slowbaud & CBAUDEX */
5245 0, 57600, 115200, 230400,
5246 460800, 150, 200, 921600,
5247 600, 1200, 1800, 2400,
5248 4800, 9600, 19200, 38400 },
5250 0, 57600, 76800, 115200,
5251 14400, 57600, 230400, 76800,
5252 115200, 230400, 28800, 460800,
5253 921600, 9600, 19200, 38400 },
5254 { /* fastbaud & CBAUDEX */
5255 0, 57600, 115200, 230400,
5256 460800, 150, 200, 921600,
5257 600, 1200, 1800, 2400,
5258 4800, 9600, 19200, 38400 }
5262 * Only use the TXPrint baud rate if the
5263 * terminal unit is NOT open
5265 if (!(ch->ch_tun.un_flags & UN_ISOPEN) &&
5266 (un->un_type == DGAP_PRINT))
5267 baud = C_BAUD(ch->ch_pun.un_tty) & 0xff;
5269 baud = C_BAUD(ch->ch_tun.un_tty) & 0xff;
5271 if (ch->ch_c_cflag & CBAUDEX)
5274 if (ch->ch_digi.digi_flags & DIGI_FAST)
5279 if ((iindex >= 0) && (iindex < 4) &&
5280 (jindex >= 0) && (jindex < 16))
5281 baud = bauds[iindex][jindex];
5288 ch->ch_baud_info = baud;
5291 * CBAUD has bit position 0x1000 set these days to
5292 * indicate Linux baud rate remap.
5293 * We use a different bit assignment for high speed.
5294 * Clear this bit out while grabbing the parts of
5297 cflag = ch->ch_c_cflag & ((CBAUD ^ CBAUDEX) | PARODD | PARENB |
5301 * HUPCL bit is used by FEP to indicate fast baud
5302 * table is to be used.
5304 if ((ch->ch_digi.digi_flags & DIGI_FAST) ||
5305 (ch->ch_c_cflag & CBAUDEX))
5308 if ((ch->ch_c_cflag & CBAUDEX) &&
5309 !(ch->ch_digi.digi_flags & DIGI_FAST)) {
5311 * The below code is trying to guarantee that only
5312 * baud rates 115200, 230400, 460800, 921600 are
5313 * remapped. We use exclusive or because the various
5314 * baud rates share common bit positions and therefore
5315 * can't be tested for easily.
5317 tcflag_t tcflag = (ch->ch_c_cflag & CBAUD) | CBAUDEX;
5321 * Map high speed requests to index
5322 * into FEP's baud table
5352 cflag = (cflag & ~(CBAUD | CBAUDEX)) | baudpart;
5357 if (cflag != ch->ch_fepcflag) {
5358 ch->ch_fepcflag = (u16) (cflag & 0xffff);
5361 * Okay to have channel and board
5362 * locks held calling this
5364 dgap_cmdw(ch, SCFLAG, (u16) cflag, 0);
5367 /* Handle transition from B0 */
5368 if (ch->ch_flags & CH_BAUD0) {
5369 ch->ch_flags &= ~(CH_BAUD0);
5370 ch->ch_mval |= (D_RTS(ch)|D_DTR(ch));
5372 mval = D_DTR(ch) | D_RTS(ch);
5378 iflag = ch->ch_c_iflag & (IGNBRK | BRKINT | IGNPAR | PARMRK |
5379 INPCK | ISTRIP | IXON | IXANY | IXOFF);
5381 if ((ch->ch_startc == _POSIX_VDISABLE) ||
5382 (ch->ch_stopc == _POSIX_VDISABLE)) {
5383 iflag &= ~(IXON | IXOFF);
5384 ch->ch_c_iflag &= ~(IXON | IXOFF);
5388 * Only the IBM Xr card can switch between
5389 * 232 and 422 modes on the fly
5391 if (bd->device == PCI_DEV_XR_IBM_DID) {
5392 if (ch->ch_digi.digi_flags & DIGI_422)
5393 dgap_cmdb(ch, SCOMMODE, MODE_422, 0, 0);
5395 dgap_cmdb(ch, SCOMMODE, MODE_232, 0, 0);
5398 if (ch->ch_digi.digi_flags & DIGI_ALTPIN)
5401 if (iflag != ch->ch_fepiflag) {
5402 ch->ch_fepiflag = iflag;
5404 /* Okay to have channel and board locks held calling this */
5405 dgap_cmdw(ch, SIFLAG, (u16) ch->ch_fepiflag, 0);
5409 * Select hardware handshaking.
5413 if (ch->ch_c_cflag & CRTSCTS)
5414 hflow |= (D_RTS(ch) | D_CTS(ch));
5415 if (ch->ch_digi.digi_flags & RTSPACE)
5417 if (ch->ch_digi.digi_flags & DTRPACE)
5419 if (ch->ch_digi.digi_flags & CTSPACE)
5421 if (ch->ch_digi.digi_flags & DSRPACE)
5423 if (ch->ch_digi.digi_flags & DCDPACE)
5426 if (hflow != ch->ch_hflow) {
5427 ch->ch_hflow = hflow;
5429 /* Okay to have channel and board locks held calling this */
5430 dgap_cmdb(ch, SHFLOW, (uchar) hflow, 0xff, 0);
5435 * Set RTS and/or DTR Toggle if needed,
5436 * but only if product is FEP5+ based.
5438 if (bd->bd_flags & BD_FEP5PLUS) {
5440 if (ch->ch_digi.digi_flags & DIGI_RTS_TOGGLE)
5441 hflow2 |= (D_RTS(ch));
5442 if (ch->ch_digi.digi_flags & DIGI_DTR_TOGGLE)
5443 hflow2 |= (D_DTR(ch));
5445 dgap_cmdw_ext(ch, 0xff03, hflow2, 0);
5449 * Set modem control lines.
5452 mval ^= ch->ch_mforce & (mval ^ ch->ch_mval);
5454 if (ch->ch_mostat ^ mval) {
5455 ch->ch_mostat = mval;
5457 /* Okay to have channel and board locks held calling this */
5458 dgap_cmdb(ch, SMODEM, (uchar) mval, D_RTS(ch)|D_DTR(ch), 0);
5462 * Read modem signals, and then call carrier function.
5464 ch->ch_mistat = readb(&(bs->m_stat));
5468 * Set the start and stop characters.
5470 if (ch->ch_startc != ch->ch_fepstartc ||
5471 ch->ch_stopc != ch->ch_fepstopc) {
5472 ch->ch_fepstartc = ch->ch_startc;
5473 ch->ch_fepstopc = ch->ch_stopc;
5475 /* Okay to have channel and board locks held calling this */
5476 dgap_cmdb(ch, SFLOWC, ch->ch_fepstartc, ch->ch_fepstopc, 0);
5480 * Set the Auxiliary start and stop characters.
5482 if (ch->ch_astartc != ch->ch_fepastartc ||
5483 ch->ch_astopc != ch->ch_fepastopc) {
5484 ch->ch_fepastartc = ch->ch_astartc;
5485 ch->ch_fepastopc = ch->ch_astopc;
5487 /* Okay to have channel and board locks held calling this */
5488 dgap_cmdb(ch, SAFLOWC, ch->ch_fepastartc, ch->ch_fepastopc, 0);
5495 * dgap_parity_scan()
5497 * Convert the FEP5 way of reporting parity errors and breaks into
5498 * the Linux line discipline way.
5500 static void dgap_parity_scan(struct channel_t *ch, unsigned char *cbuf,
5501 unsigned char *fbuf, int *len)
5505 unsigned char *in, *cout, *fout;
5512 if (!ch || ch->magic != DGAP_CHANNEL_MAGIC)
5517 switch (ch->pscan_state) {
5519 /* reset to sanity and fall through */
5520 ch->pscan_state = 0;
5523 /* No FF seen yet */
5524 if (c == (unsigned char) '\377')
5525 /* delete this character from stream */
5526 ch->pscan_state = 1;
5529 *fout++ = TTY_NORMAL;
5536 if (c == (unsigned char) '\377') {
5537 /* doubled ff, transform to single ff */
5539 *fout++ = TTY_NORMAL;
5541 ch->pscan_state = 0;
5543 /* save value examination in next state */
5544 ch->pscan_savechar = c;
5545 ch->pscan_state = 2;
5550 /* third character of ff sequence */
5554 if (ch->pscan_savechar == 0x0) {
5558 *fout++ = TTY_BREAK;
5560 ch->ch_err_parity++;
5561 *fout++ = TTY_PARITY;
5566 ch->pscan_state = 0;
5572 static void dgap_write_wakeup(struct board_t *bd, struct channel_t *ch,
5573 struct un_t *un, u32 mask,
5574 unsigned long *irq_flags1,
5575 unsigned long *irq_flags2)
5577 if (!(un->un_flags & mask))
5580 un->un_flags &= ~mask;
5582 if (!(un->un_flags & UN_ISOPEN))
5585 if ((un->un_tty->flags & (1 << TTY_DO_WRITE_WAKEUP)) &&
5586 un->un_tty->ldisc->ops->write_wakeup) {
5587 spin_unlock_irqrestore(&ch->ch_lock, *irq_flags2);
5588 spin_unlock_irqrestore(&bd->bd_lock, *irq_flags1);
5590 (un->un_tty->ldisc->ops->write_wakeup)(un->un_tty);
5592 spin_lock_irqsave(&bd->bd_lock, *irq_flags1);
5593 spin_lock_irqsave(&ch->ch_lock, *irq_flags2);
5595 wake_up_interruptible(&un->un_tty->write_wait);
5596 wake_up_interruptible(&un->un_flags_wait);
5599 /*=======================================================================
5601 * dgap_event - FEP to host event processing routine.
5603 * bd - Board of current event.
5605 *=======================================================================*/
5606 static int dgap_event(struct board_t *bd)
5608 struct channel_t *ch;
5613 uchar *vaddr = NULL;
5614 struct ev_t *eaddr = NULL;
5622 if (!bd || bd->magic != DGAP_BOARD_MAGIC)
5625 spin_lock_irqsave(&bd->bd_lock, lock_flags);
5627 vaddr = bd->re_map_membase;
5630 spin_unlock_irqrestore(&bd->bd_lock, lock_flags);
5634 eaddr = (struct ev_t *) (vaddr + EVBUF);
5636 /* Get our head and tail */
5637 head = readw(&(eaddr->ev_head));
5638 tail = readw(&(eaddr->ev_tail));
5641 * Forget it if pointers out of range.
5644 if (head >= EVMAX - EVSTART || tail >= EVMAX - EVSTART ||
5645 (head | tail) & 03) {
5646 /* Let go of board lock */
5647 spin_unlock_irqrestore(&bd->bd_lock, lock_flags);
5652 * Loop to process all the events in the buffer.
5654 while (tail != head) {
5657 * Get interrupt information.
5660 event = bd->re_map_membase + tail + EVSTART;
5668 * Make sure the interrupt is valid.
5670 if (port >= bd->nasync)
5673 if (!(reason & (IFMODEM | IFBREAK | IFTLW | IFTEM | IFDATA)))
5676 ch = bd->channels[port];
5678 if (!ch || ch->magic != DGAP_CHANNEL_MAGIC)
5682 * If we have made it here, the event was valid.
5683 * Lock down the channel.
5685 spin_lock_irqsave(&ch->ch_lock, lock_flags2);
5690 spin_unlock_irqrestore(&ch->ch_lock, lock_flags2);
5695 * Process received data.
5697 if (reason & IFDATA) {
5700 * ALL LOCKS *MUST* BE DROPPED BEFORE CALLING INPUT!
5701 * input could send some data to ld, which in turn
5702 * could do a callback to one of our other functions.
5704 spin_unlock_irqrestore(&ch->ch_lock, lock_flags2);
5705 spin_unlock_irqrestore(&bd->bd_lock, lock_flags);
5709 spin_lock_irqsave(&bd->bd_lock, lock_flags);
5710 spin_lock_irqsave(&ch->ch_lock, lock_flags2);
5712 if (ch->ch_flags & CH_RACTIVE)
5713 ch->ch_flags |= CH_RENABLE;
5715 writeb(1, &(bs->idata));
5717 if (ch->ch_flags & CH_RWAIT) {
5718 ch->ch_flags &= ~CH_RWAIT;
5720 wake_up_interruptible
5721 (&ch->ch_tun.un_flags_wait);
5726 * Process Modem change signals.
5728 if (reason & IFMODEM) {
5729 ch->ch_mistat = modem;
5736 if (reason & IFBREAK) {
5738 if (ch->ch_tun.un_tty) {
5739 /* A break has been indicated */
5741 tty_buffer_request_room
5742 (ch->ch_tun.un_tty->port, 1);
5743 tty_insert_flip_char(ch->ch_tun.un_tty->port,
5745 tty_flip_buffer_push(ch->ch_tun.un_tty->port);
5750 * Process Transmit low.
5752 if (reason & IFTLW) {
5753 dgap_write_wakeup(bd, ch, &ch->ch_tun, UN_LOW,
5754 &lock_flags, &lock_flags2);
5755 dgap_write_wakeup(bd, ch, &ch->ch_pun, UN_LOW,
5756 &lock_flags, &lock_flags2);
5757 if (ch->ch_flags & CH_WLOW) {
5758 ch->ch_flags &= ~CH_WLOW;
5759 wake_up_interruptible(&ch->ch_flags_wait);
5764 * Process Transmit empty.
5766 if (reason & IFTEM) {
5767 dgap_write_wakeup(bd, ch, &ch->ch_tun, UN_EMPTY,
5768 &lock_flags, &lock_flags2);
5769 dgap_write_wakeup(bd, ch, &ch->ch_pun, UN_EMPTY,
5770 &lock_flags, &lock_flags2);
5771 if (ch->ch_flags & CH_WEMPTY) {
5772 ch->ch_flags &= ~CH_WEMPTY;
5773 wake_up_interruptible(&ch->ch_flags_wait);
5777 spin_unlock_irqrestore(&ch->ch_lock, lock_flags2);
5780 tail = (tail + 4) & (EVMAX - EVSTART - 4);
5783 writew(tail, &(eaddr->ev_tail));
5784 spin_unlock_irqrestore(&bd->bd_lock, lock_flags);
5789 static ssize_t dgap_driver_version_show(struct device_driver *ddp, char *buf)
5791 return snprintf(buf, PAGE_SIZE, "%s\n", DG_PART);
5793 static DRIVER_ATTR(version, S_IRUSR, dgap_driver_version_show, NULL);
5796 static ssize_t dgap_driver_boards_show(struct device_driver *ddp, char *buf)
5798 return snprintf(buf, PAGE_SIZE, "%d\n", dgap_NumBoards);
5800 static DRIVER_ATTR(boards, S_IRUSR, dgap_driver_boards_show, NULL);
5803 static ssize_t dgap_driver_maxboards_show(struct device_driver *ddp, char *buf)
5805 return snprintf(buf, PAGE_SIZE, "%d\n", MAXBOARDS);
5807 static DRIVER_ATTR(maxboards, S_IRUSR, dgap_driver_maxboards_show, NULL);
5810 static ssize_t dgap_driver_pollcounter_show(struct device_driver *ddp,
5813 return snprintf(buf, PAGE_SIZE, "%ld\n", dgap_poll_counter);
5815 static DRIVER_ATTR(pollcounter, S_IRUSR, dgap_driver_pollcounter_show, NULL);
5817 static ssize_t dgap_driver_pollrate_show(struct device_driver *ddp, char *buf)
5819 return snprintf(buf, PAGE_SIZE, "%dms\n", dgap_poll_tick);
5822 static ssize_t dgap_driver_pollrate_store(struct device_driver *ddp,
5823 const char *buf, size_t count)
5825 if (sscanf(buf, "%d\n", &dgap_poll_tick) != 1)
5829 static DRIVER_ATTR(pollrate, (S_IRUSR | S_IWUSR), dgap_driver_pollrate_show,
5830 dgap_driver_pollrate_store);
5832 static int dgap_create_driver_sysfiles(struct pci_driver *dgap_driver)
5835 struct device_driver *driverfs = &dgap_driver->driver;
5837 rc |= driver_create_file(driverfs, &driver_attr_version);
5838 rc |= driver_create_file(driverfs, &driver_attr_boards);
5839 rc |= driver_create_file(driverfs, &driver_attr_maxboards);
5840 rc |= driver_create_file(driverfs, &driver_attr_pollrate);
5841 rc |= driver_create_file(driverfs, &driver_attr_pollcounter);
5846 static void dgap_remove_driver_sysfiles(struct pci_driver *dgap_driver)
5848 struct device_driver *driverfs = &dgap_driver->driver;
5849 driver_remove_file(driverfs, &driver_attr_version);
5850 driver_remove_file(driverfs, &driver_attr_boards);
5851 driver_remove_file(driverfs, &driver_attr_maxboards);
5852 driver_remove_file(driverfs, &driver_attr_pollrate);
5853 driver_remove_file(driverfs, &driver_attr_pollcounter);
5856 static struct board_t *dgap_verify_board(struct device *p)
5863 bd = dev_get_drvdata(p);
5864 if (!bd || bd->magic != DGAP_BOARD_MAGIC || bd->state != BOARD_READY)
5870 static ssize_t dgap_ports_state_show(struct device *p,
5871 struct device_attribute *attr,
5878 bd = dgap_verify_board(p);
5882 for (i = 0; i < bd->nasync; i++) {
5883 count += snprintf(buf + count, PAGE_SIZE - count,
5884 "%d %s\n", bd->channels[i]->ch_portnum,
5885 bd->channels[i]->ch_open_count ? "Open" : "Closed");
5889 static DEVICE_ATTR(ports_state, S_IRUSR, dgap_ports_state_show, NULL);
5891 static ssize_t dgap_ports_baud_show(struct device *p,
5892 struct device_attribute *attr,
5899 bd = dgap_verify_board(p);
5903 for (i = 0; i < bd->nasync; i++) {
5904 count += snprintf(buf + count, PAGE_SIZE - count, "%d %d\n",
5905 bd->channels[i]->ch_portnum,
5906 bd->channels[i]->ch_baud_info);
5910 static DEVICE_ATTR(ports_baud, S_IRUSR, dgap_ports_baud_show, NULL);
5912 static ssize_t dgap_ports_msignals_show(struct device *p,
5913 struct device_attribute *attr,
5920 bd = dgap_verify_board(p);
5924 for (i = 0; i < bd->nasync; i++) {
5925 if (bd->channels[i]->ch_open_count)
5926 count += snprintf(buf + count, PAGE_SIZE - count,
5927 "%d %s %s %s %s %s %s\n",
5928 bd->channels[i]->ch_portnum,
5929 (bd->channels[i]->ch_mostat &
5930 UART_MCR_RTS) ? "RTS" : "",
5931 (bd->channels[i]->ch_mistat &
5932 UART_MSR_CTS) ? "CTS" : "",
5933 (bd->channels[i]->ch_mostat &
5934 UART_MCR_DTR) ? "DTR" : "",
5935 (bd->channels[i]->ch_mistat &
5936 UART_MSR_DSR) ? "DSR" : "",
5937 (bd->channels[i]->ch_mistat &
5938 UART_MSR_DCD) ? "DCD" : "",
5939 (bd->channels[i]->ch_mistat &
5940 UART_MSR_RI) ? "RI" : "");
5942 count += snprintf(buf + count, PAGE_SIZE - count,
5943 "%d\n", bd->channels[i]->ch_portnum);
5947 static DEVICE_ATTR(ports_msignals, S_IRUSR, dgap_ports_msignals_show, NULL);
5949 static ssize_t dgap_ports_iflag_show(struct device *p,
5950 struct device_attribute *attr,
5957 bd = dgap_verify_board(p);
5961 for (i = 0; i < bd->nasync; i++)
5962 count += snprintf(buf + count, PAGE_SIZE - count, "%d %x\n",
5963 bd->channels[i]->ch_portnum,
5964 bd->channels[i]->ch_c_iflag);
5967 static DEVICE_ATTR(ports_iflag, S_IRUSR, dgap_ports_iflag_show, NULL);
5969 static ssize_t dgap_ports_cflag_show(struct device *p,
5970 struct device_attribute *attr,
5977 bd = dgap_verify_board(p);
5981 for (i = 0; i < bd->nasync; i++)
5982 count += snprintf(buf + count, PAGE_SIZE - count, "%d %x\n",
5983 bd->channels[i]->ch_portnum,
5984 bd->channels[i]->ch_c_cflag);
5987 static DEVICE_ATTR(ports_cflag, S_IRUSR, dgap_ports_cflag_show, NULL);
5989 static ssize_t dgap_ports_oflag_show(struct device *p,
5990 struct device_attribute *attr,
5997 bd = dgap_verify_board(p);
6001 for (i = 0; i < bd->nasync; i++)
6002 count += snprintf(buf + count, PAGE_SIZE - count, "%d %x\n",
6003 bd->channels[i]->ch_portnum,
6004 bd->channels[i]->ch_c_oflag);
6007 static DEVICE_ATTR(ports_oflag, S_IRUSR, dgap_ports_oflag_show, NULL);
6009 static ssize_t dgap_ports_lflag_show(struct device *p,
6010 struct device_attribute *attr,
6017 bd = dgap_verify_board(p);
6021 for (i = 0; i < bd->nasync; i++)
6022 count += snprintf(buf + count, PAGE_SIZE - count, "%d %x\n",
6023 bd->channels[i]->ch_portnum,
6024 bd->channels[i]->ch_c_lflag);
6027 static DEVICE_ATTR(ports_lflag, S_IRUSR, dgap_ports_lflag_show, NULL);
6029 static ssize_t dgap_ports_digi_flag_show(struct device *p,
6030 struct device_attribute *attr,
6037 bd = dgap_verify_board(p);
6041 for (i = 0; i < bd->nasync; i++)
6042 count += snprintf(buf + count, PAGE_SIZE - count, "%d %x\n",
6043 bd->channels[i]->ch_portnum,
6044 bd->channels[i]->ch_digi.digi_flags);
6047 static DEVICE_ATTR(ports_digi_flag, S_IRUSR, dgap_ports_digi_flag_show, NULL);
6049 static ssize_t dgap_ports_rxcount_show(struct device *p,
6050 struct device_attribute *attr,
6057 bd = dgap_verify_board(p);
6061 for (i = 0; i < bd->nasync; i++)
6062 count += snprintf(buf + count, PAGE_SIZE - count, "%d %ld\n",
6063 bd->channels[i]->ch_portnum,
6064 bd->channels[i]->ch_rxcount);
6067 static DEVICE_ATTR(ports_rxcount, S_IRUSR, dgap_ports_rxcount_show, NULL);
6069 static ssize_t dgap_ports_txcount_show(struct device *p,
6070 struct device_attribute *attr,
6077 bd = dgap_verify_board(p);
6081 for (i = 0; i < bd->nasync; i++)
6082 count += snprintf(buf + count, PAGE_SIZE - count, "%d %ld\n",
6083 bd->channels[i]->ch_portnum,
6084 bd->channels[i]->ch_txcount);
6087 static DEVICE_ATTR(ports_txcount, S_IRUSR, dgap_ports_txcount_show, NULL);
6089 /* this function creates the sys files that will export each signal status
6090 * to sysfs each value will be put in a separate filename
6092 static void dgap_create_ports_sysfiles(struct board_t *bd)
6094 dev_set_drvdata(&bd->pdev->dev, bd);
6095 device_create_file(&(bd->pdev->dev), &dev_attr_ports_state);
6096 device_create_file(&(bd->pdev->dev), &dev_attr_ports_baud);
6097 device_create_file(&(bd->pdev->dev), &dev_attr_ports_msignals);
6098 device_create_file(&(bd->pdev->dev), &dev_attr_ports_iflag);
6099 device_create_file(&(bd->pdev->dev), &dev_attr_ports_cflag);
6100 device_create_file(&(bd->pdev->dev), &dev_attr_ports_oflag);
6101 device_create_file(&(bd->pdev->dev), &dev_attr_ports_lflag);
6102 device_create_file(&(bd->pdev->dev), &dev_attr_ports_digi_flag);
6103 device_create_file(&(bd->pdev->dev), &dev_attr_ports_rxcount);
6104 device_create_file(&(bd->pdev->dev), &dev_attr_ports_txcount);
6107 /* removes all the sys files created for that port */
6108 static void dgap_remove_ports_sysfiles(struct board_t *bd)
6110 device_remove_file(&(bd->pdev->dev), &dev_attr_ports_state);
6111 device_remove_file(&(bd->pdev->dev), &dev_attr_ports_baud);
6112 device_remove_file(&(bd->pdev->dev), &dev_attr_ports_msignals);
6113 device_remove_file(&(bd->pdev->dev), &dev_attr_ports_iflag);
6114 device_remove_file(&(bd->pdev->dev), &dev_attr_ports_cflag);
6115 device_remove_file(&(bd->pdev->dev), &dev_attr_ports_oflag);
6116 device_remove_file(&(bd->pdev->dev), &dev_attr_ports_lflag);
6117 device_remove_file(&(bd->pdev->dev), &dev_attr_ports_digi_flag);
6118 device_remove_file(&(bd->pdev->dev), &dev_attr_ports_rxcount);
6119 device_remove_file(&(bd->pdev->dev), &dev_attr_ports_txcount);
6122 static ssize_t dgap_tty_state_show(struct device *d,
6123 struct device_attribute *attr,
6127 struct channel_t *ch;
6132 un = dev_get_drvdata(d);
6133 if (!un || un->magic != DGAP_UNIT_MAGIC)
6136 if (!ch || ch->magic != DGAP_CHANNEL_MAGIC)
6139 if (!bd || bd->magic != DGAP_BOARD_MAGIC)
6141 if (bd->state != BOARD_READY)
6144 return snprintf(buf, PAGE_SIZE, "%s", un->un_open_count ?
6147 static DEVICE_ATTR(state, S_IRUSR, dgap_tty_state_show, NULL);
6149 static ssize_t dgap_tty_baud_show(struct device *d,
6150 struct device_attribute *attr,
6154 struct channel_t *ch;
6159 un = dev_get_drvdata(d);
6160 if (!un || un->magic != DGAP_UNIT_MAGIC)
6163 if (!ch || ch->magic != DGAP_CHANNEL_MAGIC)
6166 if (!bd || bd->magic != DGAP_BOARD_MAGIC)
6168 if (bd->state != BOARD_READY)
6171 return snprintf(buf, PAGE_SIZE, "%d\n", ch->ch_baud_info);
6173 static DEVICE_ATTR(baud, S_IRUSR, dgap_tty_baud_show, NULL);
6175 static ssize_t dgap_tty_msignals_show(struct device *d,
6176 struct device_attribute *attr,
6180 struct channel_t *ch;
6185 un = dev_get_drvdata(d);
6186 if (!un || un->magic != DGAP_UNIT_MAGIC)
6189 if (!ch || ch->magic != DGAP_CHANNEL_MAGIC)
6192 if (!bd || bd->magic != DGAP_BOARD_MAGIC)
6194 if (bd->state != BOARD_READY)
6197 if (ch->ch_open_count) {
6198 return snprintf(buf, PAGE_SIZE, "%s %s %s %s %s %s\n",
6199 (ch->ch_mostat & UART_MCR_RTS) ? "RTS" : "",
6200 (ch->ch_mistat & UART_MSR_CTS) ? "CTS" : "",
6201 (ch->ch_mostat & UART_MCR_DTR) ? "DTR" : "",
6202 (ch->ch_mistat & UART_MSR_DSR) ? "DSR" : "",
6203 (ch->ch_mistat & UART_MSR_DCD) ? "DCD" : "",
6204 (ch->ch_mistat & UART_MSR_RI) ? "RI" : "");
6208 static DEVICE_ATTR(msignals, S_IRUSR, dgap_tty_msignals_show, NULL);
6210 static ssize_t dgap_tty_iflag_show(struct device *d,
6211 struct device_attribute *attr,
6215 struct channel_t *ch;
6220 un = dev_get_drvdata(d);
6221 if (!un || un->magic != DGAP_UNIT_MAGIC)
6224 if (!ch || ch->magic != DGAP_CHANNEL_MAGIC)
6227 if (!bd || bd->magic != DGAP_BOARD_MAGIC)
6229 if (bd->state != BOARD_READY)
6232 return snprintf(buf, PAGE_SIZE, "%x\n", ch->ch_c_iflag);
6234 static DEVICE_ATTR(iflag, S_IRUSR, dgap_tty_iflag_show, NULL);
6236 static ssize_t dgap_tty_cflag_show(struct device *d,
6237 struct device_attribute *attr,
6241 struct channel_t *ch;
6246 un = dev_get_drvdata(d);
6247 if (!un || un->magic != DGAP_UNIT_MAGIC)
6250 if (!ch || ch->magic != DGAP_CHANNEL_MAGIC)
6253 if (!bd || bd->magic != DGAP_BOARD_MAGIC)
6255 if (bd->state != BOARD_READY)
6258 return snprintf(buf, PAGE_SIZE, "%x\n", ch->ch_c_cflag);
6260 static DEVICE_ATTR(cflag, S_IRUSR, dgap_tty_cflag_show, NULL);
6262 static ssize_t dgap_tty_oflag_show(struct device *d,
6263 struct device_attribute *attr,
6267 struct channel_t *ch;
6272 un = dev_get_drvdata(d);
6273 if (!un || un->magic != DGAP_UNIT_MAGIC)
6276 if (!ch || ch->magic != DGAP_CHANNEL_MAGIC)
6279 if (!bd || bd->magic != DGAP_BOARD_MAGIC)
6281 if (bd->state != BOARD_READY)
6284 return snprintf(buf, PAGE_SIZE, "%x\n", ch->ch_c_oflag);
6286 static DEVICE_ATTR(oflag, S_IRUSR, dgap_tty_oflag_show, NULL);
6288 static ssize_t dgap_tty_lflag_show(struct device *d,
6289 struct device_attribute *attr,
6293 struct channel_t *ch;
6298 un = dev_get_drvdata(d);
6299 if (!un || un->magic != DGAP_UNIT_MAGIC)
6302 if (!ch || ch->magic != DGAP_CHANNEL_MAGIC)
6305 if (!bd || bd->magic != DGAP_BOARD_MAGIC)
6307 if (bd->state != BOARD_READY)
6310 return snprintf(buf, PAGE_SIZE, "%x\n", ch->ch_c_lflag);
6312 static DEVICE_ATTR(lflag, S_IRUSR, dgap_tty_lflag_show, NULL);
6314 static ssize_t dgap_tty_digi_flag_show(struct device *d,
6315 struct device_attribute *attr,
6319 struct channel_t *ch;
6324 un = dev_get_drvdata(d);
6325 if (!un || un->magic != DGAP_UNIT_MAGIC)
6328 if (!ch || ch->magic != DGAP_CHANNEL_MAGIC)
6331 if (!bd || bd->magic != DGAP_BOARD_MAGIC)
6333 if (bd->state != BOARD_READY)
6336 return snprintf(buf, PAGE_SIZE, "%x\n", ch->ch_digi.digi_flags);
6338 static DEVICE_ATTR(digi_flag, S_IRUSR, dgap_tty_digi_flag_show, NULL);
6340 static ssize_t dgap_tty_rxcount_show(struct device *d,
6341 struct device_attribute *attr,
6345 struct channel_t *ch;
6350 un = dev_get_drvdata(d);
6351 if (!un || un->magic != DGAP_UNIT_MAGIC)
6354 if (!ch || ch->magic != DGAP_CHANNEL_MAGIC)
6357 if (!bd || bd->magic != DGAP_BOARD_MAGIC)
6359 if (bd->state != BOARD_READY)
6362 return snprintf(buf, PAGE_SIZE, "%ld\n", ch->ch_rxcount);
6364 static DEVICE_ATTR(rxcount, S_IRUSR, dgap_tty_rxcount_show, NULL);
6366 static ssize_t dgap_tty_txcount_show(struct device *d,
6367 struct device_attribute *attr,
6371 struct channel_t *ch;
6376 un = dev_get_drvdata(d);
6377 if (!un || un->magic != DGAP_UNIT_MAGIC)
6380 if (!ch || ch->magic != DGAP_CHANNEL_MAGIC)
6383 if (!bd || bd->magic != DGAP_BOARD_MAGIC)
6385 if (bd->state != BOARD_READY)
6388 return snprintf(buf, PAGE_SIZE, "%ld\n", ch->ch_txcount);
6390 static DEVICE_ATTR(txcount, S_IRUSR, dgap_tty_txcount_show, NULL);
6392 static ssize_t dgap_tty_name_show(struct device *d,
6393 struct device_attribute *attr,
6397 struct channel_t *ch;
6401 struct cnode *cptr = NULL;
6409 un = dev_get_drvdata(d);
6410 if (!un || un->magic != DGAP_UNIT_MAGIC)
6413 if (!ch || ch->magic != DGAP_CHANNEL_MAGIC)
6416 if (!bd || bd->magic != DGAP_BOARD_MAGIC)
6418 if (bd->state != BOARD_READY)
6422 cn = ch->ch_portnum;
6424 for (cptr = bd->bd_config; cptr; cptr = cptr->next) {
6426 if ((cptr->type == BNODE) &&
6427 ((cptr->u.board.type == APORT2_920P) ||
6428 (cptr->u.board.type == APORT4_920P) ||
6429 (cptr->u.board.type == APORT8_920P) ||
6430 (cptr->u.board.type == PAPORT4) ||
6431 (cptr->u.board.type == PAPORT8))) {
6434 if (cptr->u.board.v_start)
6435 starto = cptr->u.board.start;
6440 if (cptr->type == TNODE && found == TRUE) {
6442 if (strstr(cptr->u.ttyname, "tty")) {
6443 ptr1 = cptr->u.ttyname;
6446 ptr1 = cptr->u.ttyname;
6448 for (i = 0; i < dgap_config_get_num_prts(bd); i++) {
6452 return snprintf(buf, PAGE_SIZE, "%s%s%02d\n",
6453 (un->un_type == DGAP_PRINT) ?
6459 if (cptr->type == CNODE) {
6461 for (i = 0; i < cptr->u.conc.nport; i++) {
6462 if (cn != (i + ncount))
6465 return snprintf(buf, PAGE_SIZE, "%s%s%02ld\n",
6466 (un->un_type == DGAP_PRINT) ?
6469 i + (cptr->u.conc.v_start ?
6470 cptr->u.conc.start : 1));
6473 ncount += cptr->u.conc.nport;
6476 if (cptr->type == MNODE) {
6478 for (i = 0; i < cptr->u.module.nport; i++) {
6479 if (cn != (i + ncount))
6482 return snprintf(buf, PAGE_SIZE, "%s%s%02ld\n",
6483 (un->un_type == DGAP_PRINT) ?
6486 i + (cptr->u.module.v_start ?
6487 cptr->u.module.start : 1));
6490 ncount += cptr->u.module.nport;
6495 return snprintf(buf, PAGE_SIZE, "%s_dgap_%d_%d\n",
6496 (un->un_type == DGAP_PRINT) ? "pr" : "tty", bn, cn);
6499 static DEVICE_ATTR(custom_name, S_IRUSR, dgap_tty_name_show, NULL);
6501 static struct attribute *dgap_sysfs_tty_entries[] = {
6502 &dev_attr_state.attr,
6503 &dev_attr_baud.attr,
6504 &dev_attr_msignals.attr,
6505 &dev_attr_iflag.attr,
6506 &dev_attr_cflag.attr,
6507 &dev_attr_oflag.attr,
6508 &dev_attr_lflag.attr,
6509 &dev_attr_digi_flag.attr,
6510 &dev_attr_rxcount.attr,
6511 &dev_attr_txcount.attr,
6512 &dev_attr_custom_name.attr,
6516 static struct attribute_group dgap_tty_attribute_group = {
6518 .attrs = dgap_sysfs_tty_entries,
6521 static void dgap_create_tty_sysfs(struct un_t *un, struct device *c)
6525 ret = sysfs_create_group(&c->kobj, &dgap_tty_attribute_group);
6529 dev_set_drvdata(c, un);
6533 static void dgap_remove_tty_sysfs(struct device *c)
6535 sysfs_remove_group(&c->kobj, &dgap_tty_attribute_group);
6539 * Parse a configuration file read into memory as a string.
6541 static int dgap_parsefile(char **in, int Remove)
6543 struct cnode *p, *brd, *line, *conc;
6549 brd = line = conc = NULL;
6551 /* perhaps we are adding to an existing list? */
6552 while (p->next != NULL)
6555 /* file must start with a BEGIN */
6556 while ((rc = dgap_gettok(in, p)) != BEGIN) {
6558 dgap_err("unexpected EOF");
6564 rc = dgap_gettok(in, p);
6566 dgap_err("unexpected EOF");
6572 dgap_err("unexpected end of file");
6575 case BEGIN: /* should only be 1 begin */
6576 dgap_err("unexpected config_begin\n");
6582 case BOARD: /* board info */
6583 if (dgap_checknode(p))
6585 p->next = dgap_newnode(BNODE);
6587 dgap_err("out of memory");
6592 p->u.board.status = dgap_savestring("No");
6598 case APORT2_920P: /* AccelePort_4 */
6599 if (p->type != BNODE) {
6600 dgap_err("unexpected Digi_2r_920 string");
6603 p->u.board.type = APORT2_920P;
6604 p->u.board.v_type = 1;
6607 case APORT4_920P: /* AccelePort_4 */
6608 if (p->type != BNODE) {
6609 dgap_err("unexpected Digi_4r_920 string");
6612 p->u.board.type = APORT4_920P;
6613 p->u.board.v_type = 1;
6616 case APORT8_920P: /* AccelePort_8 */
6617 if (p->type != BNODE) {
6618 dgap_err("unexpected Digi_8r_920 string");
6621 p->u.board.type = APORT8_920P;
6622 p->u.board.v_type = 1;
6625 case PAPORT4: /* AccelePort_4 PCI */
6626 if (p->type != BNODE) {
6627 dgap_err("unexpected Digi_4r(PCI) string");
6630 p->u.board.type = PAPORT4;
6631 p->u.board.v_type = 1;
6634 case PAPORT8: /* AccelePort_8 PCI */
6635 if (p->type != BNODE) {
6636 dgap_err("unexpected Digi_8r string");
6639 p->u.board.type = PAPORT8;
6640 p->u.board.v_type = 1;
6643 case PCX: /* PCI C/X */
6644 if (p->type != BNODE) {
6645 dgap_err("unexpected Digi_C/X_(PCI) string");
6648 p->u.board.type = PCX;
6649 p->u.board.v_type = 1;
6650 p->u.board.conc1 = 0;
6651 p->u.board.conc2 = 0;
6652 p->u.board.module1 = 0;
6653 p->u.board.module2 = 0;
6656 case PEPC: /* PCI EPC/X */
6657 if (p->type != BNODE) {
6658 dgap_err("unexpected \"Digi_EPC/X_(PCI)\" string");
6661 p->u.board.type = PEPC;
6662 p->u.board.v_type = 1;
6663 p->u.board.conc1 = 0;
6664 p->u.board.conc2 = 0;
6665 p->u.board.module1 = 0;
6666 p->u.board.module2 = 0;
6669 case PPCM: /* PCI/Xem */
6670 if (p->type != BNODE) {
6671 dgap_err("unexpected PCI/Xem string");
6674 p->u.board.type = PPCM;
6675 p->u.board.v_type = 1;
6676 p->u.board.conc1 = 0;
6677 p->u.board.conc2 = 0;
6680 case IO: /* i/o port */
6681 if (p->type != BNODE) {
6682 dgap_err("IO port only vaild for boards");
6685 s = dgap_getword(in);
6687 dgap_err("unexpected end of file");
6690 p->u.board.portstr = dgap_savestring(s);
6691 if (kstrtol(s, 0, &p->u.board.port)) {
6692 dgap_err("bad number for IO port");
6695 p->u.board.v_port = 1;
6698 case MEM: /* memory address */
6699 if (p->type != BNODE) {
6700 dgap_err("memory address only vaild for boards");
6703 s = dgap_getword(in);
6705 dgap_err("unexpected end of file");
6708 p->u.board.addrstr = dgap_savestring(s);
6709 if (kstrtoul(s, 0, &p->u.board.addr)) {
6710 dgap_err("bad number for memory address");
6713 p->u.board.v_addr = 1;
6716 case PCIINFO: /* pci information */
6717 if (p->type != BNODE) {
6718 dgap_err("memory address only vaild for boards");
6721 s = dgap_getword(in);
6723 dgap_err("unexpected end of file");
6726 p->u.board.pcibusstr = dgap_savestring(s);
6727 if (kstrtoul(s, 0, &p->u.board.pcibus)) {
6728 dgap_err("bad number for pci bus");
6731 p->u.board.v_pcibus = 1;
6732 s = dgap_getword(in);
6734 dgap_err("unexpected end of file");
6737 p->u.board.pcislotstr = dgap_savestring(s);
6738 if (kstrtoul(s, 0, &p->u.board.pcislot)) {
6739 dgap_err("bad number for pci slot");
6742 p->u.board.v_pcislot = 1;
6746 if (p->type != BNODE) {
6747 dgap_err("install method only vaild for boards");
6750 s = dgap_getword(in);
6752 dgap_err("unexpected end of file");
6755 p->u.board.method = dgap_savestring(s);
6756 p->u.board.v_method = 1;
6760 if (p->type != BNODE) {
6761 dgap_err("config status only vaild for boards");
6764 s = dgap_getword(in);
6766 dgap_err("unexpected end of file");
6769 p->u.board.status = dgap_savestring(s);
6772 case NPORTS: /* number of ports */
6773 if (p->type == BNODE) {
6774 s = dgap_getword(in);
6776 dgap_err("unexpected end of file");
6779 if (kstrtol(s, 0, &p->u.board.nport)) {
6780 dgap_err("bad number for number of ports");
6783 p->u.board.v_nport = 1;
6784 } else if (p->type == CNODE) {
6785 s = dgap_getword(in);
6787 dgap_err("unexpected end of file");
6790 if (kstrtol(s, 0, &p->u.conc.nport)) {
6791 dgap_err("bad number for number of ports");
6794 p->u.conc.v_nport = 1;
6795 } else if (p->type == MNODE) {
6796 s = dgap_getword(in);
6798 dgap_err("unexpected end of file");
6801 if (kstrtol(s, 0, &p->u.module.nport)) {
6802 dgap_err("bad number for number of ports");
6805 p->u.module.v_nport = 1;
6807 dgap_err("nports only valid for concentrators or modules");
6812 case ID: /* letter ID used in tty name */
6813 s = dgap_getword(in);
6815 dgap_err("unexpected end of file");
6819 p->u.board.status = dgap_savestring(s);
6821 if (p->type == CNODE) {
6822 p->u.conc.id = dgap_savestring(s);
6824 } else if (p->type == MNODE) {
6825 p->u.module.id = dgap_savestring(s);
6826 p->u.module.v_id = 1;
6828 dgap_err("id only valid for concentrators or modules");
6833 case STARTO: /* start offset of ID */
6834 if (p->type == BNODE) {
6835 s = dgap_getword(in);
6837 dgap_err("unexpected end of file");
6840 if (kstrtol(s, 0, &p->u.board.start)) {
6841 dgap_err("bad number for start of tty count");
6844 p->u.board.v_start = 1;
6845 } else if (p->type == CNODE) {
6846 s = dgap_getword(in);
6848 dgap_err("unexpected end of file");
6851 if (kstrtol(s, 0, &p->u.conc.start)) {
6852 dgap_err("bad number for start of tty count");
6855 p->u.conc.v_start = 1;
6856 } else if (p->type == MNODE) {
6857 s = dgap_getword(in);
6859 dgap_err("unexpected end of file");
6862 if (kstrtol(s, 0, &p->u.module.start)) {
6863 dgap_err("bad number for start of tty count");
6866 p->u.module.v_start = 1;
6868 dgap_err("start only valid for concentrators or modules");
6873 case TTYN: /* tty name prefix */
6874 if (dgap_checknode(p))
6876 p->next = dgap_newnode(TNODE);
6878 dgap_err("out of memory");
6882 s = dgap_getword(in);
6884 dgap_err("unexpeced end of file");
6887 p->u.ttyname = dgap_savestring(s);
6888 if (!p->u.ttyname) {
6889 dgap_err("out of memory");
6894 case CU: /* cu name prefix */
6895 if (dgap_checknode(p))
6897 p->next = dgap_newnode(CUNODE);
6899 dgap_err("out of memory");
6903 s = dgap_getword(in);
6905 dgap_err("unexpeced end of file");
6908 p->u.cuname = dgap_savestring(s);
6910 dgap_err("out of memory");
6915 case LINE: /* line information */
6916 if (dgap_checknode(p))
6919 dgap_err("must specify board before line info");
6922 switch (brd->u.board.type) {
6924 dgap_err("line not vaild for PC/em");
6927 p->next = dgap_newnode(LNODE);
6929 dgap_err("out of memory");
6938 case CONC: /* concentrator information */
6939 if (dgap_checknode(p))
6942 dgap_err("must specify line info before concentrator");
6945 p->next = dgap_newnode(CNODE);
6947 dgap_err("out of memory");
6953 brd->u.board.conc2++;
6955 brd->u.board.conc1++;
6959 case CX: /* c/x type concentrator */
6960 if (p->type != CNODE) {
6961 dgap_err("cx only valid for concentrators");
6964 p->u.conc.type = CX;
6965 p->u.conc.v_type = 1;
6968 case EPC: /* epc type concentrator */
6969 if (p->type != CNODE) {
6970 dgap_err("cx only valid for concentrators");
6973 p->u.conc.type = EPC;
6974 p->u.conc.v_type = 1;
6977 case MOD: /* EBI module */
6978 if (dgap_checknode(p))
6981 dgap_err("must specify board info before EBI modules");
6984 switch (brd->u.board.type) {
6990 dgap_err("must specify concentrator info before EBI module");
6994 p->next = dgap_newnode(MNODE);
6996 dgap_err("out of memory");
7001 brd->u.board.module2++;
7003 brd->u.board.module1++;
7007 case PORTS: /* ports type EBI module */
7008 if (p->type != MNODE) {
7009 dgap_err("ports only valid for EBI modules");
7012 p->u.module.type = PORTS;
7013 p->u.module.v_type = 1;
7016 case MODEM: /* ports type EBI module */
7017 if (p->type != MNODE) {
7018 dgap_err("modem only valid for modem modules");
7021 p->u.module.type = MODEM;
7022 p->u.module.v_type = 1;
7026 if (p->type == LNODE) {
7027 s = dgap_getword(in);
7029 dgap_err("unexpected end of file");
7032 p->u.line.cable = dgap_savestring(s);
7033 p->u.line.v_cable = 1;
7037 case SPEED: /* sync line speed indication */
7038 if (p->type == LNODE) {
7039 s = dgap_getword(in);
7041 dgap_err("unexpected end of file");
7044 if (kstrtol(s, 0, &p->u.line.speed)) {
7045 dgap_err("bad number for line speed");
7048 p->u.line.v_speed = 1;
7049 } else if (p->type == CNODE) {
7050 s = dgap_getword(in);
7052 dgap_err("unexpected end of file");
7055 if (kstrtol(s, 0, &p->u.conc.speed)) {
7056 dgap_err("bad number for line speed");
7059 p->u.conc.v_speed = 1;
7061 dgap_err("speed valid only for lines or concentrators.");
7067 if (p->type == CNODE) {
7068 s = dgap_getword(in);
7070 dgap_err("unexpected end of file");
7073 p->u.conc.connect = dgap_savestring(s);
7074 p->u.conc.v_connect = 1;
7077 case PRINT: /* transparent print name prefix */
7078 if (dgap_checknode(p))
7080 p->next = dgap_newnode(PNODE);
7082 dgap_err("out of memory");
7086 s = dgap_getword(in);
7088 dgap_err("unexpeced end of file");
7091 p->u.printname = dgap_savestring(s);
7092 if (!p->u.printname) {
7093 dgap_err("out of memory");
7098 case CMAJOR: /* major number */
7099 if (dgap_checknode(p))
7101 p->next = dgap_newnode(JNODE);
7103 dgap_err("out of memory");
7107 s = dgap_getword(in);
7109 dgap_err("unexpected end of file");
7112 if (kstrtol(s, 0, &p->u.majornumber)) {
7113 dgap_err("bad number for major number");
7118 case ALTPIN: /* altpin setting */
7119 if (dgap_checknode(p))
7121 p->next = dgap_newnode(ANODE);
7123 dgap_err("out of memory");
7127 s = dgap_getword(in);
7129 dgap_err("unexpected end of file");
7132 if (kstrtol(s, 0, &p->u.altpin)) {
7133 dgap_err("bad number for altpin");
7138 case USEINTR: /* enable interrupt setting */
7139 if (dgap_checknode(p))
7141 p->next = dgap_newnode(INTRNODE);
7143 dgap_err("out of memory");
7147 s = dgap_getword(in);
7149 dgap_err("unexpected end of file");
7152 if (kstrtol(s, 0, &p->u.useintr)) {
7153 dgap_err("bad number for useintr");
7158 case TTSIZ: /* size of tty structure */
7159 if (dgap_checknode(p))
7161 p->next = dgap_newnode(TSNODE);
7163 dgap_err("out of memory");
7167 s = dgap_getword(in);
7169 dgap_err("unexpected end of file");
7172 if (kstrtol(s, 0, &p->u.ttysize)) {
7173 dgap_err("bad number for ttysize");
7178 case CHSIZ: /* channel structure size */
7179 if (dgap_checknode(p))
7181 p->next = dgap_newnode(CSNODE);
7183 dgap_err("out of memory");
7187 s = dgap_getword(in);
7189 dgap_err("unexpected end of file");
7192 if (kstrtol(s, 0, &p->u.chsize)) {
7193 dgap_err("bad number for chsize");
7198 case BSSIZ: /* board structure size */
7199 if (dgap_checknode(p))
7201 p->next = dgap_newnode(BSNODE);
7203 dgap_err("out of memory");
7207 s = dgap_getword(in);
7209 dgap_err("unexpected end of file");
7212 if (kstrtol(s, 0, &p->u.bssize)) {
7213 dgap_err("bad number for bssize");
7218 case UNTSIZ: /* sched structure size */
7219 if (dgap_checknode(p))
7221 p->next = dgap_newnode(USNODE);
7223 dgap_err("out of memory");
7227 s = dgap_getword(in);
7229 dgap_err("unexpected end of file");
7232 if (kstrtol(s, 0, &p->u.unsize)) {
7233 dgap_err("bad number for schedsize");
7238 case F2SIZ: /* f2200 structure size */
7239 if (dgap_checknode(p))
7241 p->next = dgap_newnode(FSNODE);
7243 dgap_err("out of memory");
7247 s = dgap_getword(in);
7249 dgap_err("unexpected end of file");
7252 if (kstrtol(s, 0, &p->u.f2size)) {
7253 dgap_err("bad number for f2200size");
7258 case VPSIZ: /* vpix structure size */
7259 if (dgap_checknode(p))
7261 p->next = dgap_newnode(VSNODE);
7263 dgap_err("out of memory");
7267 s = dgap_getword(in);
7269 dgap_err("unexpected end of file");
7272 if (kstrtol(s, 0, &p->u.vpixsize)) {
7273 dgap_err("bad number for vpixsize");
7282 * dgap_sindex: much like index(), but it looks for a match of any character in
7283 * the group, and returns that position. If the first character is a ^, then
7284 * this will match the first occurrence not in that group.
7286 static char *dgap_sindex(char *string, char *group)
7290 if (!string || !group)
7291 return (char *) NULL;
7293 if (*group == '^') {
7295 for (; *string; string++) {
7296 for (ptr = group; *ptr; ptr++) {
7297 if (*ptr == *string)
7304 for (; *string; string++) {
7305 for (ptr = group; *ptr; ptr++) {
7306 if (*ptr == *string)
7312 return (char *) NULL;
7316 * Get a token from the input file; return 0 if end of file is reached
7318 static int dgap_gettok(char **in, struct cnode *p)
7323 if (strstr(dgap_cword, "boar")) {
7324 w = dgap_getword(in);
7325 snprintf(dgap_cword, MAXCWORD, "%s", w);
7326 for (t = dgap_tlist; t->token != 0; t++) {
7327 if (!strcmp(w, t->string))
7330 dgap_err("board !!type not specified");
7333 while ((w = dgap_getword(in))) {
7334 snprintf(dgap_cword, MAXCWORD, "%s", w);
7335 for (t = dgap_tlist; t->token != 0; t++) {
7336 if (!strcmp(w, t->string))
7345 * get a word from the input stream, also keep track of current line number.
7346 * words are separated by whitespace.
7348 static char *dgap_getword(char **in)
7350 char *ret_ptr = *in;
7352 char *ptr = dgap_sindex(*in, " \t\n");
7354 /* If no word found, return null */
7358 /* Mark new location for our buffer */
7362 /* Eat any extra spaces/tabs/newlines that might be present */
7363 while (*in && **in && ((**in == ' ') ||
7374 * print an error message, giving the line number in the file where
7375 * the error occurred.
7377 static void dgap_err(char *s)
7379 pr_err("dgap: parse: %s\n", s);
7383 * allocate a new configuration node of type t
7385 static struct cnode *dgap_newnode(int t)
7389 n = kmalloc(sizeof(struct cnode), GFP_ATOMIC);
7391 memset((char *)n, 0, sizeof(struct cnode));
7398 * dgap_checknode: see if all the necessary info has been supplied for a node
7399 * before creating the next node.
7401 static int dgap_checknode(struct cnode *p)
7405 if (p->u.board.v_type == 0) {
7406 dgap_err("board type !not specified");
7413 if (p->u.line.v_speed == 0) {
7414 dgap_err("line speed not specified");
7420 if (p->u.conc.v_type == 0) {
7421 dgap_err("concentrator type not specified");
7424 if (p->u.conc.v_speed == 0) {
7425 dgap_err("concentrator line speed not specified");
7428 if (p->u.conc.v_nport == 0) {
7429 dgap_err("number of ports on concentrator not specified");
7432 if (p->u.conc.v_id == 0) {
7433 dgap_err("concentrator id letter not specified");
7439 if (p->u.module.v_type == 0) {
7440 dgap_err("EBI module type not specified");
7443 if (p->u.module.v_nport == 0) {
7444 dgap_err("number of ports on EBI module not specified");
7447 if (p->u.module.v_id == 0) {
7448 dgap_err("EBI module id letter not specified");
7457 * save a string somewhere
7459 static char *dgap_savestring(char *s)
7463 p = kmalloc(strlen(s) + 1, GFP_ATOMIC);
7470 * Given a board pointer, returns whether we should use interrupts or not.
7472 static uint dgap_config_get_useintr(struct board_t *bd)
7474 struct cnode *p = NULL;
7479 for (p = bd->bd_config; p; p = p->next) {
7483 * check for pcxr types.
7485 return p->u.useintr;
7491 /* If not found, then don't turn on interrupts. */
7496 * Given a board pointer, returns whether we turn on altpin or not.
7498 static uint dgap_config_get_altpin(struct board_t *bd)
7500 struct cnode *p = NULL;
7505 for (p = bd->bd_config; p; p = p->next) {
7509 * check for pcxr types.
7517 /* If not found, then don't turn on interrupts. */
7522 * Given a specific type of board, if found, detached link and
7523 * returns the first occurrence in the list.
7525 static struct cnode *dgap_find_config(int type, int bus, int slot)
7527 struct cnode *p, *prev = NULL, *prev2 = NULL, *found = NULL;
7531 while (p->next != NULL) {
7535 if (p->type == BNODE) {
7537 if (p->u.board.type == type) {
7539 if (p->u.board.v_pcibus &&
7540 p->u.board.pcibus != bus)
7542 if (p->u.board.v_pcislot &&
7543 p->u.board.pcislot != slot)
7548 * Keep walking thru the list till we
7549 * find the next board.
7551 while (p->next != NULL) {
7554 if (p->type == BNODE) {
7557 * Mark the end of our 1 board
7563 * Link the "next" board to the
7564 * previous board, effectively
7565 * "unlinking" our board from
7574 * It must be the last board in the list.
7585 * Given a board pointer, walks the config link, counting up
7586 * all ports user specified should be on the board.
7587 * (This does NOT mean they are all actually present right now tho)
7589 static uint dgap_config_get_num_prts(struct board_t *bd)
7592 struct cnode *p = NULL;
7597 for (p = bd->bd_config; p; p = p->next) {
7602 * check for pcxr types.
7604 if (p->u.board.type > EPCFE)
7605 count += p->u.board.nport;
7608 count += p->u.conc.nport;
7611 count += p->u.module.nport;
7618 static char *dgap_create_config_string(struct board_t *bd, char *string)
7621 struct cnode *p = NULL;
7622 struct cnode *q = NULL;
7630 for (p = bd->bd_config; p; p = p->next) {
7636 *ptr = p->u.line.speed;
7641 * Because the EPC/con concentrators can have EM modules
7642 * hanging off of them, we have to walk ahead in the
7643 * list and keep adding the number of ports on each EM
7644 * to the config. UGH!
7646 speed = p->u.conc.speed;
7648 if ((q != NULL) && (q->type == MNODE)) {
7649 *ptr = (p->u.conc.nport + 0x80);
7652 while ((q->next != NULL) &&
7653 (q->next->type) == MNODE) {
7655 *ptr = (q->u.module.nport + 0x80);
7660 *ptr = q->u.module.nport;
7663 *ptr = p->u.conc.nport;