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_number_of_ports(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
, uchar __user
*ubios
,
215 static void dgap_do_fep_load(struct board_t
*brd
, uchar __user
*ufep
, int len
);
216 #ifdef DIGI_CONCENTRATORS_SUPPORTED
217 static void dgap_do_conc_load(struct board_t
*brd
, uchar
*uaddr
, int len
);
219 static int dgap_after_config_loaded(int board
);
220 static int dgap_finalize_board_init(struct board_t
*brd
);
222 static void dgap_get_vpd(struct board_t
*brd
);
223 static void dgap_do_reset_board(struct board_t
*brd
);
224 static void dgap_do_wait_for_bios(struct board_t
*brd
);
225 static void dgap_do_wait_for_fep(struct board_t
*brd
);
226 static int dgap_tty_register_ports(struct board_t
*brd
);
227 static int dgap_firmware_load(struct pci_dev
*pdev
, int card_type
);
229 /* Driver unload function */
230 static void dgap_cleanup_module(void);
232 module_exit(dgap_cleanup_module
);
235 * File operations permitted on Control/Management major.
237 static const struct file_operations DgapBoardFops
= {
238 .owner
= THIS_MODULE
,
244 static uint dgap_NumBoards
;
245 static struct board_t
*dgap_Board
[MAXBOARDS
];
246 static ulong dgap_poll_counter
;
247 static char *dgap_config_buf
;
248 static int dgap_driver_state
= DRIVER_INITIALIZED
;
249 DEFINE_SPINLOCK(dgap_dl_lock
);
250 static wait_queue_head_t dgap_dl_wait
;
251 static int dgap_dl_action
;
252 static int dgap_poll_tick
= 20; /* Poll interval - 20 ms */
257 static struct class *dgap_class
;
259 static struct board_t
*dgap_BoardsByMajor
[256];
260 static uint dgap_count
= 500;
265 DEFINE_SPINLOCK(dgap_poll_lock
); /* Poll scheduling lock */
266 static ulong dgap_poll_time
; /* Time of next poll */
267 static uint dgap_poll_stop
; /* Used to tell poller to stop */
268 static struct timer_list dgap_poll_timer
;
273 Card Model Number of Ports Interface
274 ----------------------------------------------------------------
275 Acceleport Xem 4 - 64 (EIA232 & EIA422)
276 Acceleport Xr 4 & 8 (EIA232)
277 Acceleport Xr 920 4 & 8 (EIA232)
278 Acceleport C/X 8 - 128 (EIA232)
279 Acceleport EPC/X 8 - 224 (EIA232)
280 Acceleport Xr/422 4 & 8 (EIA422)
281 Acceleport 2r/920 2 (EIA232)
282 Acceleport 4r/920 4 (EIA232)
283 Acceleport 8r/920 8 (EIA232)
285 IBM 8-Port Asynchronous PCI Adapter (EIA232)
286 IBM 128-Port Asynchronous PCI Adapter (EIA232 & EIA422)
289 static struct pci_device_id dgap_pci_tbl
[] = {
290 { DIGI_VID
, PCI_DEV_XEM_DID
, PCI_ANY_ID
, PCI_ANY_ID
, 0, 0, 0 },
291 { DIGI_VID
, PCI_DEV_CX_DID
, PCI_ANY_ID
, PCI_ANY_ID
, 0, 0, 1 },
292 { DIGI_VID
, PCI_DEV_CX_IBM_DID
, PCI_ANY_ID
, PCI_ANY_ID
, 0, 0, 2 },
293 { DIGI_VID
, PCI_DEV_EPCJ_DID
, PCI_ANY_ID
, PCI_ANY_ID
, 0, 0, 3 },
294 { DIGI_VID
, PCI_DEV_920_2_DID
, PCI_ANY_ID
, PCI_ANY_ID
, 0, 0, 4 },
295 { DIGI_VID
, PCI_DEV_920_4_DID
, PCI_ANY_ID
, PCI_ANY_ID
, 0, 0, 5 },
296 { DIGI_VID
, PCI_DEV_920_8_DID
, PCI_ANY_ID
, PCI_ANY_ID
, 0, 0, 6 },
297 { DIGI_VID
, PCI_DEV_XR_DID
, PCI_ANY_ID
, PCI_ANY_ID
, 0, 0, 7 },
298 { DIGI_VID
, PCI_DEV_XRJ_DID
, PCI_ANY_ID
, PCI_ANY_ID
, 0, 0, 8 },
299 { DIGI_VID
, PCI_DEV_XR_422_DID
, PCI_ANY_ID
, PCI_ANY_ID
, 0, 0, 9 },
300 { DIGI_VID
, PCI_DEV_XR_IBM_DID
, PCI_ANY_ID
, PCI_ANY_ID
, 0, 0, 10 },
301 { DIGI_VID
, PCI_DEV_XR_SAIP_DID
, PCI_ANY_ID
, PCI_ANY_ID
, 0, 0, 11 },
302 { DIGI_VID
, PCI_DEV_XR_BULL_DID
, PCI_ANY_ID
, PCI_ANY_ID
, 0, 0, 12 },
303 { DIGI_VID
, PCI_DEV_920_8_HP_DID
, PCI_ANY_ID
, PCI_ANY_ID
, 0, 0, 13 },
304 { DIGI_VID
, PCI_DEV_XEM_HP_DID
, PCI_ANY_ID
, PCI_ANY_ID
, 0, 0, 14 },
305 {0,} /* 0 terminated list. */
307 MODULE_DEVICE_TABLE(pci
, dgap_pci_tbl
);
310 * A generic list of Product names, PCI Vendor ID, and PCI Device ID.
319 static struct board_id dgap_Ids
[] = {
320 { PPCM
, PCI_DEV_XEM_NAME
, 64, (T_PCXM
|T_PCLITE
|T_PCIBUS
) },
321 { PCX
, PCI_DEV_CX_NAME
, 128, (T_CX
|T_PCIBUS
) },
322 { PCX
, PCI_DEV_CX_IBM_NAME
, 128, (T_CX
|T_PCIBUS
) },
323 { PEPC
, PCI_DEV_EPCJ_NAME
, 224, (T_EPC
|T_PCIBUS
) },
324 { APORT2_920P
, PCI_DEV_920_2_NAME
, 2, (T_PCXR
|T_PCLITE
|T_PCIBUS
) },
325 { APORT4_920P
, PCI_DEV_920_4_NAME
, 4, (T_PCXR
|T_PCLITE
|T_PCIBUS
) },
326 { APORT8_920P
, PCI_DEV_920_8_NAME
, 8, (T_PCXR
|T_PCLITE
|T_PCIBUS
) },
327 { PAPORT8
, PCI_DEV_XR_NAME
, 8, (T_PCXR
|T_PCLITE
|T_PCIBUS
) },
328 { PAPORT8
, PCI_DEV_XRJ_NAME
, 8, (T_PCXR
|T_PCLITE
|T_PCIBUS
) },
329 { PAPORT8
, PCI_DEV_XR_422_NAME
, 8, (T_PCXR
|T_PCLITE
|T_PCIBUS
) },
330 { PAPORT8
, PCI_DEV_XR_IBM_NAME
, 8, (T_PCXR
|T_PCLITE
|T_PCIBUS
) },
331 { PAPORT8
, PCI_DEV_XR_SAIP_NAME
, 8, (T_PCXR
|T_PCLITE
|T_PCIBUS
) },
332 { PAPORT8
, PCI_DEV_XR_BULL_NAME
, 8, (T_PCXR
|T_PCLITE
|T_PCIBUS
) },
333 { APORT8_920P
, PCI_DEV_920_8_HP_NAME
, 8, (T_PCXR
|T_PCLITE
|T_PCIBUS
) },
334 { PPCM
, PCI_DEV_XEM_HP_NAME
, 64, (T_PCXM
|T_PCLITE
|T_PCIBUS
) },
335 {0,} /* 0 terminated list. */
338 static struct pci_driver dgap_driver
= {
340 .probe
= dgap_init_one
,
341 .id_table
= dgap_pci_tbl
,
342 .remove
= dgap_remove_one
,
345 struct firmware_info
{
346 uchar
*conf_name
; /* dgap.conf */
347 uchar
*bios_name
; /* BIOS filename */
348 uchar
*fep_name
; /* FEP filename */
349 uchar
*con_name
; /* Concentrator filename FIXME*/
350 int num
; /* sequence number */
354 * Firmware - BIOS, FEP, and CONC filenames
356 static struct firmware_info fw_info
[] = {
357 { "dgap/dgap.conf", "dgap/sxbios.bin", "dgap/sxfep.bin", 0, 0 },
358 { "dgap/dgap.conf", "dgap/cxpbios.bin", "dgap/cxpfep.bin", 0, 1 },
359 { "dgap/dgap.conf", "dgap/cxpbios.bin", "dgap/cxpfep.bin", 0, 2 },
360 { "dgap/dgap.conf", "dgap/pcibios.bin", "dgap/pcifep.bin", 0, 3 },
361 { "dgap/dgap.conf", "dgap/xrbios.bin", "dgap/xrfep.bin", 0, 4 },
362 { "dgap/dgap.conf", "dgap/xrbios.bin", "dgap/xrfep.bin", 0, 5 },
363 { "dgap/dgap.conf", "dgap/xrbios.bin", "dgap/xrfep.bin", 0, 6 },
364 { "dgap/dgap.conf", "dgap/xrbios.bin", "dgap/xrfep.bin", 0, 7 },
365 { "dgap/dgap.conf", "dgap/xrbios.bin", "dgap/xrfep.bin", 0, 8 },
366 { "dgap/dgap.conf", "dgap/xrbios.bin", "dgap/xrfep.bin", 0, 9 },
367 { "dgap/dgap.conf", "dgap/xrbios.bin", "dgap/xrfep.bin", 0, 10 },
368 { "dgap/dgap.conf", "dgap/xrbios.bin", "dgap/xrfep.bin", 0, 11 },
369 { "dgap/dgap.conf", "dgap/xrbios.bin", "dgap/xrfep.bin", 0, 12 },
370 { "dgap/dgap.conf", "dgap/xrbios.bin", "dgap/xrfep.bin", 0, 13 },
371 { "dgap/dgap.conf", "dgap/sxbios.bin", "dgap/sxfep.bin", 0, 14 },
375 static char *dgap_driver_state_text
[] = {
376 "Driver Initialized",
377 "Driver needs configuration load.",
378 "Driver requested configuration from download daemon.",
383 * Default transparent print information.
385 static struct digi_t dgap_digi_init
= {
386 .digi_flags
= DIGI_COOK
, /* Flags */
387 .digi_maxcps
= 100, /* Max CPS */
388 .digi_maxchar
= 50, /* Max chars in print queue */
389 .digi_bufsize
= 100, /* Printer buffer size */
390 .digi_onlen
= 4, /* size of printer on string */
391 .digi_offlen
= 4, /* size of printer off string */
392 .digi_onstr
= "\033[5i", /* ANSI printer on string ] */
393 .digi_offstr
= "\033[4i", /* ANSI printer off string ] */
394 .digi_term
= "ansi" /* default terminal type */
398 * Define a local default termios struct. All ports will be created
399 * with this termios initially.
401 * This defines a raw port at 9600 baud, 8 data bits, no parity,
405 static struct ktermios DgapDefaultTermios
= {
406 .c_iflag
= (DEFAULT_IFLAGS
), /* iflags */
407 .c_oflag
= (DEFAULT_OFLAGS
), /* oflags */
408 .c_cflag
= (DEFAULT_CFLAGS
), /* cflags */
409 .c_lflag
= (DEFAULT_LFLAGS
), /* lflags */
414 static const struct tty_operations dgap_tty_ops
= {
415 .open
= dgap_tty_open
,
416 .close
= dgap_tty_close
,
417 .write
= dgap_tty_write
,
418 .write_room
= dgap_tty_write_room
,
419 .flush_buffer
= dgap_tty_flush_buffer
,
420 .chars_in_buffer
= dgap_tty_chars_in_buffer
,
421 .flush_chars
= dgap_tty_flush_chars
,
422 .ioctl
= dgap_tty_ioctl
,
423 .set_termios
= dgap_tty_set_termios
,
424 .stop
= dgap_tty_stop
,
425 .start
= dgap_tty_start
,
426 .throttle
= dgap_tty_throttle
,
427 .unthrottle
= dgap_tty_unthrottle
,
428 .hangup
= dgap_tty_hangup
,
429 .put_char
= dgap_tty_put_char
,
430 .tiocmget
= dgap_tty_tiocmget
,
431 .tiocmset
= dgap_tty_tiocmset
,
432 .break_ctl
= dgap_tty_send_break
,
433 .wait_until_sent
= dgap_tty_wait_until_sent
,
434 .send_xchar
= dgap_tty_send_xchar
438 * Our needed internal static variables from dgap_parse.c
440 static struct cnode dgap_head
;
442 static char dgap_cword
[MAXCWORD
];
449 static struct toklist dgap_tlist
[] = {
450 { BEGIN
, "config_begin" },
451 { END
, "config_end" },
453 { PCX
, "Digi_AccelePort_C/X_PCI" },
454 { PEPC
, "Digi_AccelePort_EPC/X_PCI" },
455 { PPCM
, "Digi_AccelePort_Xem_PCI" },
456 { APORT2_920P
, "Digi_AccelePort_2r_920_PCI" },
457 { APORT4_920P
, "Digi_AccelePort_4r_920_PCI" },
458 { APORT8_920P
, "Digi_AccelePort_8r_920_PCI" },
459 { PAPORT4
, "Digi_AccelePort_4r_PCI(EIA-232/RS-422)" },
460 { PAPORT8
, "Digi_AccelePort_8r_PCI(EIA-232/RS-422)" },
462 { PCIINFO
, "pciinfo" },
465 { CONC
, "concentrator" },
475 { CONNECT
, "connect" },
476 { METHOD
, "method" },
477 { STATUS
, "status" },
478 { CUSTOM
, "Custom" },
484 { NPORTS
, "nports" },
489 { ALTPIN
, "altpin" },
490 { USEINTR
, "useintr" },
491 { TTSIZ
, "ttysize" },
493 { BSSIZ
, "boardsize" },
494 { UNTSIZ
, "schedsize" },
495 { F2SIZ
, "f2200size" },
496 { VPSIZ
, "vpixsize" },
500 /************************************************************************
502 * Driver load/unload functions
504 ************************************************************************/
509 * Module load. This is where it all starts.
511 static int dgap_init_module(void)
515 pr_info("%s, Digi International Part Number %s\n", DG_NAME
, DG_PART
);
517 dgap_driver_state
= DRIVER_NEED_CONFIG_LOAD
;
523 rc
= dgap_init_pci();
527 rc
= dgap_create_driver_sysfiles(&dgap_driver
);
531 dgap_driver_state
= DRIVER_READY
;
537 dgap_cleanup_module();
541 module_init(dgap_init_module
);
546 static int dgap_start(void)
552 * make sure that the globals are
553 * init'd before we do anything else
559 pr_info("For the tools package please visit http://www.digi.com\n");
562 * Register our base character device into the kernel.
566 * Register management/dpa devices
568 rc
= register_chrdev(DIGI_DGAP_MAJOR
, "dgap", &DgapBoardFops
);
572 dgap_class
= class_create(THIS_MODULE
, "dgap_mgmt");
573 device_create(dgap_class
, NULL
,
574 MKDEV(DIGI_DGAP_MAJOR
, 0),
577 /* Start the poller */
578 DGAP_LOCK(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 DGAP_UNLOCK(dgap_poll_lock
, flags
);
586 add_timer(&dgap_poll_timer
);
588 dgap_driver_state
= DRIVER_NEED_CONFIG_LOAD
;
594 * Register pci driver, and return how many boards we have.
596 static int dgap_init_pci(void)
598 return pci_register_driver(&dgap_driver
);
601 /* returns count (>= 0), or negative on error */
602 static int dgap_init_one(struct pci_dev
*pdev
, const struct pci_device_id
*ent
)
606 /* wake up and enable device */
607 rc
= pci_enable_device(pdev
);
612 rc
= dgap_probe1(pdev
, ent
->driver_data
);
615 rc
= dgap_firmware_load(pdev
, ent
->driver_data
);
621 static int dgap_probe1(struct pci_dev
*pdev
, int card_type
)
623 return dgap_found_board(pdev
, card_type
);
626 static void dgap_remove_one(struct pci_dev
*dev
)
632 * dgap_cleanup_module()
634 * Module unload. This is where it all ends.
636 static void dgap_cleanup_module(void)
641 DGAP_LOCK(dgap_poll_lock
, lock_flags
);
643 DGAP_UNLOCK(dgap_poll_lock
, lock_flags
);
645 /* Turn off poller right away. */
646 del_timer_sync(&dgap_poll_timer
);
648 dgap_remove_driver_sysfiles(&dgap_driver
);
650 device_destroy(dgap_class
, MKDEV(DIGI_DGAP_MAJOR
, 0));
651 class_destroy(dgap_class
);
652 unregister_chrdev(DIGI_DGAP_MAJOR
, "dgap");
654 kfree(dgap_config_buf
);
656 for (i
= 0; i
< dgap_NumBoards
; ++i
) {
657 dgap_remove_ports_sysfiles(dgap_Board
[i
]);
658 dgap_tty_uninit(dgap_Board
[i
]);
659 dgap_cleanup_board(dgap_Board
[i
]);
663 pci_unregister_driver(&dgap_driver
);
667 * dgap_cleanup_board()
669 * Free all the memory associated with a board
671 static void dgap_cleanup_board(struct board_t
*brd
)
675 if (!brd
|| brd
->magic
!= DGAP_BOARD_MAGIC
)
678 if (brd
->intr_used
&& brd
->irq
)
679 free_irq(brd
->irq
, brd
);
681 tasklet_kill(&brd
->helper_tasklet
);
683 if (brd
->re_map_port
) {
684 release_mem_region(brd
->membase
+ 0x200000, 0x200000);
685 iounmap(brd
->re_map_port
);
686 brd
->re_map_port
= NULL
;
689 if (brd
->re_map_membase
) {
690 release_mem_region(brd
->membase
, 0x200000);
691 iounmap(brd
->re_map_membase
);
692 brd
->re_map_membase
= NULL
;
695 /* Free all allocated channels structs */
696 for (i
= 0; i
< MAXPORTS
; i
++)
697 kfree(brd
->channels
[i
]);
700 kfree(brd
->flipflagbuf
);
702 dgap_Board
[brd
->boardnum
] = NULL
;
710 * A board has been found, init it.
712 static int dgap_found_board(struct pci_dev
*pdev
, int id
)
715 unsigned int pci_irq
;
718 /* get the board structure and prep it */
719 brd
= kzalloc(sizeof(struct board_t
), GFP_KERNEL
);
723 dgap_Board
[dgap_NumBoards
] = brd
;
725 /* store the info for the board we've found */
726 brd
->magic
= DGAP_BOARD_MAGIC
;
727 brd
->boardnum
= dgap_NumBoards
;
729 brd
->vendor
= dgap_pci_tbl
[id
].vendor
;
730 brd
->device
= dgap_pci_tbl
[id
].device
;
732 brd
->pci_bus
= pdev
->bus
->number
;
733 brd
->pci_slot
= PCI_SLOT(pdev
->devfn
);
734 brd
->name
= dgap_Ids
[id
].name
;
735 brd
->maxports
= dgap_Ids
[id
].maxports
;
736 brd
->type
= dgap_Ids
[id
].config_type
;
737 brd
->dpatype
= dgap_Ids
[id
].dpatype
;
738 brd
->dpastatus
= BD_NOFEP
;
739 init_waitqueue_head(&brd
->state_wait
);
741 DGAP_SPINLOCK_INIT(brd
->bd_lock
);
743 brd
->state
= BOARD_FOUND
;
745 brd
->inhibit_poller
= FALSE
;
746 brd
->wait_for_bios
= 0;
747 brd
->wait_for_fep
= 0;
749 for (i
= 0; i
< MAXPORTS
; i
++)
750 brd
->channels
[i
] = NULL
;
752 /* store which card & revision we have */
753 pci_read_config_word(pdev
, PCI_SUBSYSTEM_VENDOR_ID
, &brd
->subvendor
);
754 pci_read_config_word(pdev
, PCI_SUBSYSTEM_ID
, &brd
->subdevice
);
755 pci_read_config_byte(pdev
, PCI_REVISION_ID
, &brd
->rev
);
760 /* get the PCI Base Address Registers */
762 /* Xr Jupiter and EPC use BAR 2 */
763 if (brd
->device
== PCI_DEV_XRJ_DID
|| brd
->device
== PCI_DEV_EPCJ_DID
) {
764 brd
->membase
= pci_resource_start(pdev
, 2);
765 brd
->membase_end
= pci_resource_end(pdev
, 2);
767 /* Everyone else uses BAR 0 */
769 brd
->membase
= pci_resource_start(pdev
, 0);
770 brd
->membase_end
= pci_resource_end(pdev
, 0);
776 if (brd
->membase
& 1)
782 * On the PCI boards, there is no IO space allocated
783 * The I/O registers will be in the first 3 bytes of the
784 * upper 2MB of the 4MB memory space. The board memory
785 * will be mapped into the low 2MB of the 4MB memory space
787 brd
->port
= brd
->membase
+ PCI_IO_OFFSET
;
788 brd
->port_end
= brd
->port
+ PCI_IO_SIZE
;
791 * Special initialization for non-PLX boards
793 if (brd
->device
!= PCI_DEV_XRJ_DID
&& brd
->device
!= PCI_DEV_EPCJ_DID
) {
796 pci_write_config_byte(pdev
, 0x40, 0);
797 pci_write_config_byte(pdev
, 0x46, 0);
799 /* Limit burst length to 2 doubleword transactions */
800 pci_write_config_byte(pdev
, 0x42, 1);
803 * Enable IO and mem if not already done.
804 * This was needed for support on Itanium.
806 pci_read_config_word(pdev
, PCI_COMMAND
, &cmd
);
807 cmd
|= (PCI_COMMAND_IO
| PCI_COMMAND_MEMORY
);
808 pci_write_config_word(pdev
, PCI_COMMAND
, cmd
);
811 /* init our poll helper tasklet */
812 tasklet_init(&brd
->helper_tasklet
, dgap_poll_tasklet
,
813 (unsigned long) brd
);
815 i
= dgap_do_remap(brd
);
817 brd
->state
= BOARD_FAILED
;
819 brd
->state
= NEED_RESET
;
825 static int dgap_finalize_board_init(struct board_t
*brd
)
829 if (!brd
|| brd
->magic
!= DGAP_BOARD_MAGIC
)
832 brd
->use_interrupts
= dgap_config_get_useintr(brd
);
835 * Set up our interrupt handler if we are set to do interrupts.
837 if (brd
->use_interrupts
&& brd
->irq
) {
839 rc
= request_irq(brd
->irq
, dgap_intr
, IRQF_SHARED
, "DGAP", brd
);
852 static int dgap_firmware_load(struct pci_dev
*pdev
, int card_type
)
854 struct board_t
*brd
= dgap_Board
[dgap_NumBoards
- 1];
855 const struct firmware
*fw
;
859 dgap_do_reset_board(brd
);
861 if ((fw_info
[card_type
].conf_name
) &&
862 (dgap_driver_state
== DRIVER_NEED_CONFIG_LOAD
)) {
863 ret
= request_firmware(&fw
, fw_info
[card_type
].conf_name
,
866 pr_err("dgap: config file %s not found\n",
867 fw_info
[card_type
].conf_name
);
870 if (!dgap_config_buf
) {
871 dgap_config_buf
= kmalloc(fw
->size
+ 1, GFP_ATOMIC
);
872 if (!dgap_config_buf
) {
873 release_firmware(fw
);
878 memcpy(dgap_config_buf
, fw
->data
, fw
->size
);
879 release_firmware(fw
);
880 dgap_config_buf
[fw
->size
+ 1] = '\0';
882 if (dgap_parsefile(&dgap_config_buf
, TRUE
) != 0)
885 dgap_driver_state
= -1;
888 ret
= dgap_after_config_loaded(brd
->boardnum
);
892 * Match this board to a config the user created for us.
895 dgap_find_config(brd
->type
, brd
->pci_bus
, brd
->pci_slot
);
898 * Because the 4 port Xr products share the same PCI ID
899 * as the 8 port Xr products, if we receive a NULL config
900 * back, and this is a PAPORT8 board, retry with a
901 * PAPORT4 attempt as well.
903 if (brd
->type
== PAPORT8
&& !brd
->bd_config
)
905 dgap_find_config(PAPORT4
, brd
->pci_bus
, brd
->pci_slot
);
907 if (!brd
->bd_config
) {
908 pr_err("dgap: No valid configuration found\n");
912 dgap_tty_register(brd
);
913 dgap_finalize_board_init(brd
);
915 if (fw_info
[card_type
].bios_name
) {
916 ret
= request_firmware(&fw
, fw_info
[card_type
].bios_name
,
919 pr_err("dgap: bios file %s not found\n",
920 fw_info
[card_type
].bios_name
);
923 dgap_do_bios_load(brd
, (char *)fw
->data
, fw
->size
);
924 release_firmware(fw
);
926 /* Wait for BIOS to test board... */
927 dgap_do_wait_for_bios(brd
);
929 if (brd
->state
!= FINISHED_BIOS_LOAD
)
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
, (char *)fw
->data
, fw
->size
);
942 release_firmware(fw
);
944 /* Wait for FEP to load on board... */
945 dgap_do_wait_for_fep(brd
);
947 if (brd
->state
!= FINISHED_FEP_LOAD
)
951 #ifdef DIGI_CONCENTRATORS_SUPPORTED
953 * If this is a CX or EPCX, we need to see if the firmware
954 * is requesting a concentrator image from us.
956 if ((bd
->type
== PCX
) || (bd
->type
== PEPC
)) {
957 chk_addr
= (u16
*) (vaddr
+ DOWNREQ
);
958 /* Nonzero if FEP is requesting concentrator image. */
959 check
= readw(chk_addr
);
960 vaddr
= brd
->re_map_membase
;
963 if (fw_info
[card_type
].con_name
&& check
&& vaddr
) {
964 ret
= request_firmware(&fw
, fw_info
[card_type
].con_name
,
967 pr_err("dgap: conc file %s not found\n",
968 fw_info
[card_type
].con_name
);
971 /* Put concentrator firmware loading code here */
972 offset
= readw((u16
*) (vaddr
+ DOWNREQ
));
973 memcpy_toio(offset
, fw
->data
, fw
->size
);
975 dgap_do_conc_load(brd
, (char *)fw
->data
, fw
->size
)
976 release_firmware(fw
);
980 * Do tty device initialization.
982 ret
= dgap_tty_init(brd
);
984 dgap_tty_uninit(brd
);
988 ret
= dgap_tty_register_ports(brd
);
992 brd
->state
= BOARD_READY
;
993 brd
->dpastatus
= BD_RUNNING
;
1001 static int dgap_do_remap(struct board_t
*brd
)
1003 if (!brd
|| brd
->magic
!= DGAP_BOARD_MAGIC
)
1006 if (!request_mem_region(brd
->membase
, 0x200000, "dgap"))
1009 if (!request_mem_region(brd
->membase
+ PCI_IO_OFFSET
, 0x200000,
1011 release_mem_region(brd
->membase
, 0x200000);
1015 brd
->re_map_membase
= ioremap(brd
->membase
, 0x200000);
1016 if (!brd
->re_map_membase
) {
1017 release_mem_region(brd
->membase
, 0x200000);
1018 release_mem_region(brd
->membase
+ PCI_IO_OFFSET
, 0x200000);
1022 brd
->re_map_port
= ioremap((brd
->membase
+ PCI_IO_OFFSET
), 0x200000);
1023 if (!brd
->re_map_port
) {
1024 release_mem_region(brd
->membase
, 0x200000);
1025 release_mem_region(brd
->membase
+ PCI_IO_OFFSET
, 0x200000);
1026 iounmap(brd
->re_map_membase
);
1033 /*****************************************************************************
1053 * As each timer expires, it determines (a) whether the "transmit"
1054 * waiter needs to be woken up, and (b) whether the poller needs to
1057 ******************************************************************************/
1059 static void dgap_poll_handler(ulong dummy
)
1062 struct board_t
*brd
;
1063 unsigned long lock_flags
;
1066 dgap_poll_counter
++;
1069 * Do not start the board state machine until
1070 * driver tells us its up and running, and has
1071 * everything it needs.
1073 if (dgap_driver_state
!= DRIVER_READY
)
1074 goto schedule_poller
;
1077 * If we have just 1 board, or the system is not SMP,
1078 * then use the typical old style poller.
1079 * Otherwise, use our new tasklet based poller, which should
1080 * speed things up for multiple boards.
1082 if ((dgap_NumBoards
== 1) || (num_online_cpus() <= 1)) {
1083 for (i
= 0; i
< dgap_NumBoards
; i
++) {
1085 brd
= dgap_Board
[i
];
1087 if (brd
->state
== BOARD_FAILED
)
1089 if (!brd
->intr_running
)
1090 /* Call the real board poller directly */
1091 dgap_poll_tasklet((unsigned long) brd
);
1095 * Go thru each board, kicking off a
1096 * tasklet for each if needed
1098 for (i
= 0; i
< dgap_NumBoards
; i
++) {
1099 brd
= dgap_Board
[i
];
1102 * Attempt to grab the board lock.
1104 * If we can't get it, no big deal, the next poll
1105 * will get it. Basically, I just really don't want
1106 * to spin in here, because I want to kick off my
1107 * tasklets as fast as I can, and then get out the
1110 if (!spin_trylock(&brd
->bd_lock
))
1114 * If board is in a failed state, don't bother
1115 * scheduling a tasklet
1117 if (brd
->state
== BOARD_FAILED
) {
1118 spin_unlock(&brd
->bd_lock
);
1122 /* Schedule a poll helper task */
1123 if (!brd
->intr_running
)
1124 tasklet_schedule(&brd
->helper_tasklet
);
1127 * Can't do DGAP_UNLOCK here, as we don't have
1128 * lock_flags because we did a trylock above.
1130 spin_unlock(&brd
->bd_lock
);
1137 * Schedule ourself back at the nominal wakeup interval.
1139 DGAP_LOCK(dgap_poll_lock
, lock_flags
);
1140 dgap_poll_time
+= dgap_jiffies_from_ms(dgap_poll_tick
);
1142 new_time
= dgap_poll_time
- jiffies
;
1144 if ((ulong
) new_time
>= 2 * dgap_poll_tick
) {
1146 jiffies
+ dgap_jiffies_from_ms(dgap_poll_tick
);
1149 dgap_poll_timer
.function
= dgap_poll_handler
;
1150 dgap_poll_timer
.data
= 0;
1151 dgap_poll_timer
.expires
= dgap_poll_time
;
1152 DGAP_UNLOCK(dgap_poll_lock
, lock_flags
);
1154 if (!dgap_poll_stop
)
1155 add_timer(&dgap_poll_timer
);
1161 * Driver interrupt handler.
1163 static irqreturn_t
dgap_intr(int irq
, void *voidbrd
)
1165 struct board_t
*brd
= (struct board_t
*) voidbrd
;
1171 * Check to make sure its for us.
1173 if (brd
->magic
!= DGAP_BOARD_MAGIC
)
1179 * Schedule tasklet to run at a better time.
1181 tasklet_schedule(&brd
->helper_tasklet
);
1186 * dgap_init_globals()
1188 * This is where we initialize the globals from the static insmod
1189 * configuration variables. These are declared near the head of
1192 static void dgap_init_globals(void)
1196 for (i
= 0; i
< MAXBOARDS
; i
++)
1197 dgap_Board
[i
] = NULL
;
1199 init_timer(&dgap_poll_timer
);
1201 init_waitqueue_head(&dgap_dl_wait
);
1205 /************************************************************************
1209 ************************************************************************/
1214 * Put the driver to sleep for x ms's
1216 * Returns 0 if timed out, !0 (showing signal) if interrupted by a signal.
1218 static int dgap_ms_sleep(ulong ms
)
1220 current
->state
= TASK_INTERRUPTIBLE
;
1221 schedule_timeout((ms
* HZ
) / 1000);
1222 return signal_pending(current
);
1225 /************************************************************************
1227 * TTY Initialization/Cleanup Functions
1229 ************************************************************************/
1232 * dgap_tty_register()
1234 * Init the tty subsystem for this board.
1236 static int dgap_tty_register(struct board_t
*brd
)
1240 brd
->SerialDriver
= alloc_tty_driver(MAXPORTS
);
1242 snprintf(brd
->SerialName
, MAXTTYNAMELEN
, "tty_dgap_%d_", brd
->boardnum
);
1243 brd
->SerialDriver
->name
= brd
->SerialName
;
1244 brd
->SerialDriver
->name_base
= 0;
1245 brd
->SerialDriver
->major
= 0;
1246 brd
->SerialDriver
->minor_start
= 0;
1247 brd
->SerialDriver
->type
= TTY_DRIVER_TYPE_SERIAL
;
1248 brd
->SerialDriver
->subtype
= SERIAL_TYPE_NORMAL
;
1249 brd
->SerialDriver
->init_termios
= DgapDefaultTermios
;
1250 brd
->SerialDriver
->driver_name
= DRVSTR
;
1251 brd
->SerialDriver
->flags
= (TTY_DRIVER_REAL_RAW
|
1252 TTY_DRIVER_DYNAMIC_DEV
|
1253 TTY_DRIVER_HARDWARE_BREAK
);
1255 /* The kernel wants space to store pointers to tty_structs */
1256 brd
->SerialDriver
->ttys
=
1257 kzalloc(MAXPORTS
* sizeof(struct tty_struct
*), GFP_KERNEL
);
1258 if (!brd
->SerialDriver
->ttys
)
1262 * Entry points for driver. Called by the kernel from
1263 * tty_io.c and n_tty.c.
1265 tty_set_operations(brd
->SerialDriver
, &dgap_tty_ops
);
1268 * If we're doing transparent print, we have to do all of the above
1269 * again, separately so we don't get the LD confused about what major
1270 * we are when we get into the dgap_tty_open() routine.
1272 brd
->PrintDriver
= alloc_tty_driver(MAXPORTS
);
1274 snprintf(brd
->PrintName
, MAXTTYNAMELEN
, "pr_dgap_%d_", brd
->boardnum
);
1275 brd
->PrintDriver
->name
= brd
->PrintName
;
1276 brd
->PrintDriver
->name_base
= 0;
1277 brd
->PrintDriver
->major
= 0;
1278 brd
->PrintDriver
->minor_start
= 0;
1279 brd
->PrintDriver
->type
= TTY_DRIVER_TYPE_SERIAL
;
1280 brd
->PrintDriver
->subtype
= SERIAL_TYPE_NORMAL
;
1281 brd
->PrintDriver
->init_termios
= DgapDefaultTermios
;
1282 brd
->PrintDriver
->driver_name
= DRVSTR
;
1283 brd
->PrintDriver
->flags
= (TTY_DRIVER_REAL_RAW
|
1284 TTY_DRIVER_DYNAMIC_DEV
|
1285 TTY_DRIVER_HARDWARE_BREAK
);
1287 /* The kernel wants space to store pointers to tty_structs */
1288 brd
->PrintDriver
->ttys
=
1289 kzalloc(MAXPORTS
* sizeof(struct tty_struct
*), GFP_KERNEL
);
1290 if (!brd
->PrintDriver
->ttys
)
1294 * Entry points for driver. Called by the kernel from
1295 * tty_io.c and n_tty.c.
1297 tty_set_operations(brd
->PrintDriver
, &dgap_tty_ops
);
1299 if (!brd
->dgap_Major_Serial_Registered
) {
1300 /* Register tty devices */
1301 rc
= tty_register_driver(brd
->SerialDriver
);
1304 brd
->dgap_Major_Serial_Registered
= TRUE
;
1305 dgap_BoardsByMajor
[brd
->SerialDriver
->major
] = brd
;
1306 brd
->dgap_Serial_Major
= brd
->SerialDriver
->major
;
1309 if (!brd
->dgap_Major_TransparentPrint_Registered
) {
1310 /* Register Transparent Print devices */
1311 rc
= tty_register_driver(brd
->PrintDriver
);
1314 brd
->dgap_Major_TransparentPrint_Registered
= TRUE
;
1315 dgap_BoardsByMajor
[brd
->PrintDriver
->major
] = brd
;
1316 brd
->dgap_TransparentPrint_Major
= brd
->PrintDriver
->major
;
1325 * Init the tty subsystem. Called once per board after board has been
1326 * downloaded and init'ed.
1328 static int dgap_tty_init(struct board_t
*brd
)
1332 uint true_count
= 0;
1335 struct channel_t
*ch
;
1343 * Initialize board structure elements.
1346 vaddr
= brd
->re_map_membase
;
1347 true_count
= readw((vaddr
+ NCHAN
));
1349 brd
->nasync
= dgap_config_get_number_of_ports(brd
);
1352 brd
->nasync
= brd
->maxports
;
1354 if (brd
->nasync
> brd
->maxports
)
1355 brd
->nasync
= brd
->maxports
;
1357 if (true_count
!= brd
->nasync
) {
1358 if ((brd
->type
== PPCM
) && (true_count
== 64)) {
1359 pr_warn("dgap: %s configured for %d ports, has %d ports.\n",
1360 brd
->name
, brd
->nasync
, true_count
);
1361 pr_warn("dgap: Please make SURE the EBI cable running from the card\n");
1362 pr_warn("dgap: to each EM module is plugged into EBI IN!\n");
1363 } else if ((brd
->type
== PPCM
) && (true_count
== 0)) {
1364 pr_warn("dgap: %s configured for %d ports, has %d ports.\n",
1365 brd
->name
, brd
->nasync
, true_count
);
1366 pr_warn("dgap: Please make SURE the EBI cable running from the card\n");
1367 pr_warn("dgap: to each EM module is plugged into EBI IN!\n");
1369 pr_warn("dgap: %s configured for %d ports, has %d ports.\n",
1370 brd
->name
, brd
->nasync
, true_count
);
1372 brd
->nasync
= true_count
;
1374 /* If no ports, don't bother going any further */
1376 brd
->state
= BOARD_FAILED
;
1377 brd
->dpastatus
= BD_NOFEP
;
1383 * Allocate channel memory that might not have been allocated
1384 * when the driver was first loaded.
1386 for (i
= 0; i
< brd
->nasync
; i
++) {
1387 if (!brd
->channels
[i
]) {
1389 kzalloc(sizeof(struct channel_t
), GFP_ATOMIC
);
1390 if (!brd
->channels
[i
])
1395 ch
= brd
->channels
[0];
1396 vaddr
= brd
->re_map_membase
;
1398 bs
= (struct bs_t
*) ((ulong
) vaddr
+ CHANBUF
);
1399 cm
= (struct cm_t
*) ((ulong
) vaddr
+ CMDBUF
);
1403 /* Set up channel variables */
1404 for (i
= 0; i
< brd
->nasync
; i
++, ch
= brd
->channels
[i
], bs
++) {
1406 if (!brd
->channels
[i
])
1409 DGAP_SPINLOCK_INIT(ch
->ch_lock
);
1411 /* Store all our magic numbers */
1412 ch
->magic
= DGAP_CHANNEL_MAGIC
;
1413 ch
->ch_tun
.magic
= DGAP_UNIT_MAGIC
;
1414 ch
->ch_tun
.un_type
= DGAP_SERIAL
;
1415 ch
->ch_tun
.un_ch
= ch
;
1416 ch
->ch_tun
.un_dev
= i
;
1418 ch
->ch_pun
.magic
= DGAP_UNIT_MAGIC
;
1419 ch
->ch_pun
.un_type
= DGAP_PRINT
;
1420 ch
->ch_pun
.un_ch
= ch
;
1421 ch
->ch_pun
.un_dev
= i
;
1423 ch
->ch_vaddr
= vaddr
;
1428 ch
->ch_digi
= dgap_digi_init
;
1431 * Set up digi dsr and dcd bits based on altpin flag.
1433 if (dgap_config_get_altpin(brd
)) {
1436 ch
->ch_digi
.digi_flags
|= DIGI_ALTPIN
;
1439 ch
->ch_dsr
= DM_DSR
;
1442 ch
->ch_taddr
= vaddr
+ ((ch
->ch_bs
->tx_seg
) << 4);
1443 ch
->ch_raddr
= vaddr
+ ((ch
->ch_bs
->rx_seg
) << 4);
1446 ch
->ch_tsize
= readw(&(ch
->ch_bs
->tx_max
)) + 1;
1447 ch
->ch_rsize
= readw(&(ch
->ch_bs
->rx_max
)) + 1;
1451 /* .25 second delay */
1452 ch
->ch_close_delay
= 250;
1455 * Set queue water marks, interrupt mask,
1456 * and general tty parameters.
1458 tlw
= ch
->ch_tsize
>= 2000 ? ((ch
->ch_tsize
* 5) / 8) :
1462 dgap_cmdw(ch
, STLOW
, tlw
, 0);
1464 dgap_cmdw(ch
, SRLOW
, ch
->ch_rsize
/ 2, 0);
1466 dgap_cmdw(ch
, SRHIGH
, 7 * ch
->ch_rsize
/ 8, 0);
1468 ch
->ch_mistat
= readb(&(ch
->ch_bs
->m_stat
));
1470 init_waitqueue_head(&ch
->ch_flags_wait
);
1471 init_waitqueue_head(&ch
->ch_tun
.un_flags_wait
);
1472 init_waitqueue_head(&ch
->ch_pun
.un_flags_wait
);
1473 init_waitqueue_head(&ch
->ch_sniff_wait
);
1475 /* Turn on all modem interrupts for now */
1476 modem
= (DM_CD
| DM_DSR
| DM_CTS
| DM_RI
);
1477 writeb(modem
, &(ch
->ch_bs
->m_int
));
1480 * Set edelay to 0 if interrupts are turned on,
1481 * otherwise set edelay to the usual 100.
1484 writew(0, &(ch
->ch_bs
->edelay
));
1486 writew(100, &(ch
->ch_bs
->edelay
));
1488 writeb(1, &(ch
->ch_bs
->idata
));
1497 * Uninitialize the TTY portion of this driver. Free all memory and
1500 static void dgap_tty_uninit(struct board_t
*brd
)
1505 if (brd
->dgap_Major_Serial_Registered
) {
1506 dgap_BoardsByMajor
[brd
->SerialDriver
->major
] = NULL
;
1507 brd
->dgap_Serial_Major
= 0;
1508 for (i
= 0; i
< brd
->nasync
; i
++) {
1509 tty_port_destroy(&brd
->SerialPorts
[i
]);
1510 dev
= brd
->channels
[i
]->ch_tun
.un_sysfs
;
1511 dgap_remove_tty_sysfs(dev
);
1512 tty_unregister_device(brd
->SerialDriver
, i
);
1514 tty_unregister_driver(brd
->SerialDriver
);
1515 kfree(brd
->SerialDriver
->ttys
);
1516 brd
->SerialDriver
->ttys
= NULL
;
1517 put_tty_driver(brd
->SerialDriver
);
1518 kfree(brd
->SerialPorts
);
1519 brd
->dgap_Major_Serial_Registered
= FALSE
;
1522 if (brd
->dgap_Major_TransparentPrint_Registered
) {
1523 dgap_BoardsByMajor
[brd
->PrintDriver
->major
] = NULL
;
1524 brd
->dgap_TransparentPrint_Major
= 0;
1525 for (i
= 0; i
< brd
->nasync
; i
++) {
1526 tty_port_destroy(&brd
->PrinterPorts
[i
]);
1527 dev
= brd
->channels
[i
]->ch_pun
.un_sysfs
;
1528 dgap_remove_tty_sysfs(dev
);
1529 tty_unregister_device(brd
->PrintDriver
, i
);
1531 tty_unregister_driver(brd
->PrintDriver
);
1532 kfree(brd
->PrintDriver
->ttys
);
1533 brd
->PrintDriver
->ttys
= NULL
;
1534 put_tty_driver(brd
->PrintDriver
);
1535 kfree(brd
->PrinterPorts
);
1536 brd
->dgap_Major_TransparentPrint_Registered
= FALSE
;
1540 #define TMPBUFLEN (1024)
1542 * dgap_sniff - Dump data out to the "sniff" buffer if the
1543 * proc sniff file is opened...
1545 static void dgap_sniff_nowait_nolock(struct channel_t
*ch
, uchar
*text
,
1546 uchar
*buf
, int len
)
1554 char tmpbuf
[TMPBUFLEN
];
1558 /* Leave if sniff not open */
1559 if (!(ch
->ch_sniff_flags
& SNIFF_OPEN
))
1562 do_gettimeofday(&tv
);
1564 /* Create our header for data dump */
1565 p
+= sprintf(p
, "<%ld %ld><%s><", tv
.tv_sec
, tv
.tv_usec
, text
);
1566 tmpbuflen
= p
- tmpbuf
;
1571 for (i
= 0; i
< len
&& tmpbuflen
< (TMPBUFLEN
- 4); i
++) {
1572 p
+= sprintf(p
, "%02x ", *buf
);
1574 tmpbuflen
= p
- tmpbuf
;
1577 if (tmpbuflen
< (TMPBUFLEN
- 4)) {
1579 p
+= sprintf(p
- 1, "%s\n", ">");
1581 p
+= sprintf(p
, "%s\n", ">");
1587 nbuf
= strlen(tmpbuf
);
1591 * Loop while data remains.
1593 while (nbuf
> 0 && ch
->ch_sniff_buf
) {
1595 * Determine the amount of available space left in the
1596 * buffer. If there's none, wait until some appears.
1598 n
= (ch
->ch_sniff_out
- ch
->ch_sniff_in
- 1) &
1602 * If there is no space left to write to in our sniff
1603 * buffer, we have no choice but to drop the data.
1604 * We *cannot* sleep here waiting for space, because
1605 * this function was probably called by the
1606 * interrupt/timer routines!
1612 * Copy as much data as will fit.
1618 r
= SNIFF_MAX
- ch
->ch_sniff_in
;
1621 memcpy(ch
->ch_sniff_buf
+ ch
->ch_sniff_in
, p
, r
);
1624 ch
->ch_sniff_in
= 0;
1629 memcpy(ch
->ch_sniff_buf
+ ch
->ch_sniff_in
, p
, n
);
1631 ch
->ch_sniff_in
+= n
;
1636 * Wakeup any thread waiting for data
1638 if (ch
->ch_sniff_flags
& SNIFF_WAIT_DATA
) {
1639 ch
->ch_sniff_flags
&= ~SNIFF_WAIT_DATA
;
1640 wake_up_interruptible(&ch
->ch_sniff_wait
);
1645 * If the user sent us too much data to push into our tmpbuf,
1646 * we need to keep looping around on all the data.
1648 if (too_much_data
) {
1653 } while (too_much_data
);
1656 /*=======================================================================
1658 * dgap_input - Process received data.
1660 * ch - Pointer to channel structure.
1662 *=======================================================================*/
1664 static void dgap_input(struct channel_t
*ch
)
1668 struct tty_struct
*tp
;
1669 struct tty_ldisc
*ld
;
1683 if (!ch
|| ch
->magic
!= DGAP_CHANNEL_MAGIC
)
1686 tp
= ch
->ch_tun
.un_tty
;
1693 if (!bd
|| bd
->magic
!= DGAP_BOARD_MAGIC
)
1696 DGAP_LOCK(bd
->bd_lock
, lock_flags
);
1697 DGAP_LOCK(ch
->ch_lock
, lock_flags2
);
1700 * Figure the number of characters in the buffer.
1701 * Exit immediately if none.
1704 rmask
= ch
->ch_rsize
- 1;
1706 head
= readw(&(bs
->rx_head
));
1708 tail
= readw(&(bs
->rx_tail
));
1711 data_len
= (head
- tail
) & rmask
;
1713 if (data_len
== 0) {
1714 writeb(1, &(bs
->idata
));
1715 DGAP_UNLOCK(ch
->ch_lock
, lock_flags2
);
1716 DGAP_UNLOCK(bd
->bd_lock
, lock_flags
);
1721 * If the device is not open, or CREAD is off, flush
1722 * input data and return immediately.
1724 if ((bd
->state
!= BOARD_READY
) || !tp
||
1725 (tp
->magic
!= TTY_MAGIC
) ||
1726 !(ch
->ch_tun
.un_flags
& UN_ISOPEN
) ||
1727 !(tp
->termios
.c_cflag
& CREAD
) ||
1728 (ch
->ch_tun
.un_flags
& UN_CLOSING
)) {
1730 writew(head
, &(bs
->rx_tail
));
1731 writeb(1, &(bs
->idata
));
1732 DGAP_UNLOCK(ch
->ch_lock
, lock_flags2
);
1733 DGAP_UNLOCK(bd
->bd_lock
, lock_flags
);
1738 * If we are throttled, simply don't read any data.
1740 if (ch
->ch_flags
& CH_RXBLOCK
) {
1741 writeb(1, &(bs
->idata
));
1742 DGAP_UNLOCK(ch
->ch_lock
, lock_flags2
);
1743 DGAP_UNLOCK(bd
->bd_lock
, lock_flags
);
1750 tmpchar
= readb(&(bs
->orun
));
1752 ch
->ch_err_overrun
++;
1753 writeb(0, &(bs
->orun
));
1756 /* Decide how much data we can send into the tty layer */
1757 flip_len
= TTY_FLIPBUF_SIZE
;
1759 /* Chop down the length, if needed */
1760 len
= min(data_len
, flip_len
);
1761 len
= min(len
, (N_TTY_BUF_SIZE
- 1));
1763 ld
= tty_ldisc_ref(tp
);
1765 #ifdef TTY_DONT_FLIP
1767 * If the DONT_FLIP flag is on, don't flush our buffer, and act
1768 * like the ld doesn't have any space to put the data right now.
1770 if (test_bit(TTY_DONT_FLIP
, &tp
->flags
))
1775 * If we were unable to get a reference to the ld,
1776 * don't flush our buffer, and act like the ld doesn't
1777 * have any space to put the data right now.
1783 * If ld doesn't have a pointer to a receive_buf function,
1784 * flush the data, then act like the ld doesn't have any
1785 * space to put the data right now.
1787 if (!ld
->ops
->receive_buf
) {
1788 writew(head
, &(bs
->rx_tail
));
1794 writeb(1, &(bs
->idata
));
1795 DGAP_UNLOCK(ch
->ch_lock
, lock_flags2
);
1796 DGAP_UNLOCK(bd
->bd_lock
, lock_flags
);
1798 tty_ldisc_deref(ld
);
1802 buf
= ch
->ch_bd
->flipbuf
;
1806 * n now contains the most amount of data we can copy,
1807 * bounded either by our buffer size or the amount
1808 * of data the card actually has pending...
1812 s
= ((head
>= tail
) ? head
: ch
->ch_rsize
) - tail
;
1818 memcpy_fromio(buf
, (char *) ch
->ch_raddr
+ tail
, s
);
1819 dgap_sniff_nowait_nolock(ch
, "USER READ", buf
, s
);
1825 /* Flip queue if needed */
1829 writew(tail
, &(bs
->rx_tail
));
1830 writeb(1, &(bs
->idata
));
1831 ch
->ch_rxcount
+= len
;
1834 * If we are completely raw, we don't need to go through a lot
1835 * of the tty layers that exist.
1836 * In this case, we take the shortest and fastest route we
1837 * can to relay the data to the user.
1839 * On the other hand, if we are not raw, we need to go through
1840 * the tty layer, which has its API more well defined.
1842 if (I_PARMRK(tp
) || I_BRKINT(tp
) || I_INPCK(tp
)) {
1843 dgap_parity_scan(ch
, ch
->ch_bd
->flipbuf
,
1844 ch
->ch_bd
->flipflagbuf
, &len
);
1846 len
= tty_buffer_request_room(tp
->port
, len
);
1847 tty_insert_flip_string_flags(tp
->port
, ch
->ch_bd
->flipbuf
,
1848 ch
->ch_bd
->flipflagbuf
, len
);
1850 len
= tty_buffer_request_room(tp
->port
, len
);
1851 tty_insert_flip_string(tp
->port
, ch
->ch_bd
->flipbuf
, len
);
1854 DGAP_UNLOCK(ch
->ch_lock
, lock_flags2
);
1855 DGAP_UNLOCK(bd
->bd_lock
, lock_flags
);
1857 /* Tell the tty layer its okay to "eat" the data now */
1858 tty_flip_buffer_push(tp
->port
);
1861 tty_ldisc_deref(ld
);
1865 /************************************************************************
1866 * Determines when CARRIER changes state and takes appropriate
1868 ************************************************************************/
1869 static void dgap_carrier(struct channel_t
*ch
)
1873 int virt_carrier
= 0;
1874 int phys_carrier
= 0;
1876 if (!ch
|| ch
->magic
!= DGAP_CHANNEL_MAGIC
)
1881 if (!bd
|| bd
->magic
!= DGAP_BOARD_MAGIC
)
1884 /* Make sure altpin is always set correctly */
1885 if (ch
->ch_digi
.digi_flags
& DIGI_ALTPIN
) {
1889 ch
->ch_dsr
= DM_DSR
;
1893 if (ch
->ch_mistat
& D_CD(ch
))
1896 if (ch
->ch_digi
.digi_flags
& DIGI_FORCEDCD
)
1899 if (ch
->ch_c_cflag
& CLOCAL
)
1903 * Test for a VIRTUAL carrier transition to HIGH.
1905 if (((ch
->ch_flags
& CH_FCAR
) == 0) && (virt_carrier
== 1)) {
1908 * When carrier rises, wake any threads waiting
1909 * for carrier in the open routine.
1912 if (waitqueue_active(&(ch
->ch_flags_wait
)))
1913 wake_up_interruptible(&ch
->ch_flags_wait
);
1917 * Test for a PHYSICAL carrier transition to HIGH.
1919 if (((ch
->ch_flags
& CH_CD
) == 0) && (phys_carrier
== 1)) {
1922 * When carrier rises, wake any threads waiting
1923 * for carrier in the open routine.
1926 if (waitqueue_active(&(ch
->ch_flags_wait
)))
1927 wake_up_interruptible(&ch
->ch_flags_wait
);
1931 * Test for a PHYSICAL transition to low, so long as we aren't
1932 * currently ignoring physical transitions (which is what "virtual
1933 * carrier" indicates).
1935 * The transition of the virtual carrier to low really doesn't
1936 * matter... it really only means "ignore carrier state", not
1937 * "make pretend that carrier is there".
1939 if ((virt_carrier
== 0) &&
1940 ((ch
->ch_flags
& CH_CD
) != 0) &&
1941 (phys_carrier
== 0)) {
1944 * When carrier drops:
1946 * Drop carrier on all open units.
1948 * Flush queues, waking up any task waiting in the
1951 * Send a hangup to the control terminal.
1953 * Enable all select calls.
1955 if (waitqueue_active(&(ch
->ch_flags_wait
)))
1956 wake_up_interruptible(&ch
->ch_flags_wait
);
1958 if (ch
->ch_tun
.un_open_count
> 0)
1959 tty_hangup(ch
->ch_tun
.un_tty
);
1961 if (ch
->ch_pun
.un_open_count
> 0)
1962 tty_hangup(ch
->ch_pun
.un_tty
);
1966 * Make sure that our cached values reflect the current reality.
1968 if (virt_carrier
== 1)
1969 ch
->ch_flags
|= CH_FCAR
;
1971 ch
->ch_flags
&= ~CH_FCAR
;
1973 if (phys_carrier
== 1)
1974 ch
->ch_flags
|= CH_CD
;
1976 ch
->ch_flags
&= ~CH_CD
;
1979 /************************************************************************
1981 * TTY Entry points and helper functions
1983 ************************************************************************/
1989 static int dgap_tty_open(struct tty_struct
*tty
, struct file
*file
)
1991 struct board_t
*brd
;
1992 struct channel_t
*ch
;
2004 major
= MAJOR(tty_devnum(tty
));
2005 minor
= MINOR(tty_devnum(tty
));
2010 /* Get board pointer from our array of majors we have allocated */
2011 brd
= dgap_BoardsByMajor
[major
];
2016 * If board is not yet up to a state of READY, go to
2017 * sleep waiting for it to happen or they cancel the open.
2019 rc
= wait_event_interruptible(brd
->state_wait
,
2020 (brd
->state
& BOARD_READY
));
2025 DGAP_LOCK(brd
->bd_lock
, lock_flags
);
2027 /* The wait above should guarantee this cannot happen */
2028 if (brd
->state
!= BOARD_READY
) {
2029 DGAP_UNLOCK(brd
->bd_lock
, lock_flags
);
2033 /* If opened device is greater than our number of ports, bail. */
2034 if (MINOR(tty_devnum(tty
)) > brd
->nasync
) {
2035 DGAP_UNLOCK(brd
->bd_lock
, lock_flags
);
2039 ch
= brd
->channels
[minor
];
2041 DGAP_UNLOCK(brd
->bd_lock
, lock_flags
);
2045 /* Grab channel lock */
2046 DGAP_LOCK(ch
->ch_lock
, lock_flags2
);
2048 /* Figure out our type */
2049 if (major
== brd
->dgap_Serial_Major
) {
2050 un
= &brd
->channels
[minor
]->ch_tun
;
2051 un
->un_type
= DGAP_SERIAL
;
2052 } else if (major
== brd
->dgap_TransparentPrint_Major
) {
2053 un
= &brd
->channels
[minor
]->ch_pun
;
2054 un
->un_type
= DGAP_PRINT
;
2056 DGAP_UNLOCK(ch
->ch_lock
, lock_flags2
);
2057 DGAP_UNLOCK(brd
->bd_lock
, lock_flags
);
2061 /* Store our unit into driver_data, so we always have it available. */
2062 tty
->driver_data
= un
;
2065 * Error if channel info pointer is NULL.
2069 DGAP_UNLOCK(ch
->ch_lock
, lock_flags2
);
2070 DGAP_UNLOCK(brd
->bd_lock
, lock_flags
);
2077 if (!(un
->un_flags
& UN_ISOPEN
)) {
2078 /* Store important variables. */
2081 /* Maybe do something here to the TTY struct as well? */
2085 * Initialize if neither terminal or printer is open.
2087 if (!((ch
->ch_tun
.un_flags
| ch
->ch_pun
.un_flags
) & UN_ISOPEN
)) {
2093 * Flush input queue.
2095 head
= readw(&(bs
->rx_head
));
2096 writew(head
, &(bs
->rx_tail
));
2099 ch
->pscan_state
= 0;
2100 ch
->pscan_savechar
= 0;
2102 ch
->ch_c_cflag
= tty
->termios
.c_cflag
;
2103 ch
->ch_c_iflag
= tty
->termios
.c_iflag
;
2104 ch
->ch_c_oflag
= tty
->termios
.c_oflag
;
2105 ch
->ch_c_lflag
= tty
->termios
.c_lflag
;
2106 ch
->ch_startc
= tty
->termios
.c_cc
[VSTART
];
2107 ch
->ch_stopc
= tty
->termios
.c_cc
[VSTOP
];
2109 /* TODO: flush our TTY struct here? */
2114 * Run param in case we changed anything
2119 * follow protocol for opening port
2122 DGAP_UNLOCK(ch
->ch_lock
, lock_flags2
);
2123 DGAP_UNLOCK(brd
->bd_lock
, lock_flags
);
2125 rc
= dgap_block_til_ready(tty
, file
, ch
);
2130 /* No going back now, increment our unit and channel counters */
2131 DGAP_LOCK(ch
->ch_lock
, lock_flags
);
2132 ch
->ch_open_count
++;
2133 un
->un_open_count
++;
2134 un
->un_flags
|= (UN_ISOPEN
);
2135 DGAP_UNLOCK(ch
->ch_lock
, lock_flags
);
2141 * dgap_block_til_ready()
2143 * Wait for DCD, if needed.
2145 static int dgap_block_til_ready(struct tty_struct
*tty
, struct file
*file
,
2146 struct channel_t
*ch
)
2149 struct un_t
*un
= NULL
;
2152 int sleep_on_un_flags
= 0;
2154 if (!tty
|| tty
->magic
!= TTY_MAGIC
|| !file
|| !ch
||
2155 ch
->magic
!= DGAP_CHANNEL_MAGIC
)
2158 un
= tty
->driver_data
;
2159 if (!un
|| un
->magic
!= DGAP_UNIT_MAGIC
)
2162 DGAP_LOCK(ch
->ch_lock
, lock_flags
);
2169 sleep_on_un_flags
= 0;
2172 * If board has failed somehow during our sleep,
2175 if (ch
->ch_bd
->state
== BOARD_FAILED
) {
2180 /* If tty was hung up, break out of loop and set error. */
2181 if (tty_hung_up_p(file
)) {
2187 * If either unit is in the middle of the fragile part of close,
2188 * we just cannot touch the channel safely.
2189 * Go back to sleep, knowing that when the channel can be
2190 * touched safely, the close routine will signal the
2191 * ch_wait_flags to wake us back up.
2193 if (!((ch
->ch_tun
.un_flags
| ch
->ch_pun
.un_flags
) &
2197 * Our conditions to leave cleanly and happily:
2198 * 1) NONBLOCKING on the tty is set.
2200 * 3) DCD (fake or real) is active.
2203 if (file
->f_flags
& O_NONBLOCK
)
2206 if (tty
->flags
& (1 << TTY_IO_ERROR
))
2209 if (ch
->ch_flags
& CH_CD
)
2212 if (ch
->ch_flags
& CH_FCAR
)
2215 sleep_on_un_flags
= 1;
2219 * If there is a signal pending, the user probably
2220 * interrupted (ctrl-c) us.
2221 * Leave loop with error set.
2223 if (signal_pending(current
)) {
2224 retval
= -ERESTARTSYS
;
2229 * Store the flags before we let go of channel lock
2231 if (sleep_on_un_flags
)
2232 old_flags
= ch
->ch_tun
.un_flags
| ch
->ch_pun
.un_flags
;
2234 old_flags
= ch
->ch_flags
;
2237 * Let go of channel lock before calling schedule.
2238 * Our poller will get any FEP events and wake us up when DCD
2239 * eventually goes active.
2242 DGAP_UNLOCK(ch
->ch_lock
, lock_flags
);
2245 * Wait for something in the flags to change
2246 * from the current value.
2248 if (sleep_on_un_flags
) {
2249 retval
= wait_event_interruptible(un
->un_flags_wait
,
2250 (old_flags
!= (ch
->ch_tun
.un_flags
|
2251 ch
->ch_pun
.un_flags
)));
2253 retval
= wait_event_interruptible(ch
->ch_flags_wait
,
2254 (old_flags
!= ch
->ch_flags
));
2258 * We got woken up for some reason.
2259 * Before looping around, grab our channel lock.
2261 DGAP_LOCK(ch
->ch_lock
, lock_flags
);
2266 DGAP_UNLOCK(ch
->ch_lock
, lock_flags
);
2277 * Hangup the port. Like a close, but don't wait for output to drain.
2279 static void dgap_tty_hangup(struct tty_struct
*tty
)
2282 struct channel_t
*ch
;
2285 if (!tty
|| tty
->magic
!= TTY_MAGIC
)
2288 un
= tty
->driver_data
;
2289 if (!un
|| un
->magic
!= DGAP_UNIT_MAGIC
)
2293 if (!ch
|| ch
->magic
!= DGAP_CHANNEL_MAGIC
)
2297 if (!bd
|| bd
->magic
!= DGAP_BOARD_MAGIC
)
2300 /* flush the transmit queues */
2301 dgap_tty_flush_buffer(tty
);
2309 static void dgap_tty_close(struct tty_struct
*tty
, struct file
*file
)
2311 struct ktermios
*ts
;
2313 struct channel_t
*ch
;
2318 if (!tty
|| tty
->magic
!= TTY_MAGIC
)
2321 un
= tty
->driver_data
;
2322 if (!un
|| un
->magic
!= DGAP_UNIT_MAGIC
)
2326 if (!ch
|| ch
->magic
!= DGAP_CHANNEL_MAGIC
)
2330 if (!bd
|| bd
->magic
!= DGAP_BOARD_MAGIC
)
2335 DGAP_LOCK(ch
->ch_lock
, lock_flags
);
2338 * Determine if this is the last close or not - and if we agree about
2339 * which type of close it is with the Line Discipline
2341 if ((tty
->count
== 1) && (un
->un_open_count
!= 1)) {
2343 * Uh, oh. tty->count is 1, which means that the tty
2344 * structure will be freed. un_open_count should always
2345 * be one in these conditions. If it's greater than
2346 * one, we've got real problems, since it means the
2347 * serial port won't be shutdown.
2349 un
->un_open_count
= 1;
2352 if (--un
->un_open_count
< 0)
2353 un
->un_open_count
= 0;
2355 ch
->ch_open_count
--;
2357 if (ch
->ch_open_count
&& un
->un_open_count
) {
2358 DGAP_UNLOCK(ch
->ch_lock
, lock_flags
);
2362 /* OK, its the last close on the unit */
2364 un
->un_flags
|= UN_CLOSING
;
2369 * Only officially close channel if count is 0 and
2370 * DIGI_PRINTER bit is not set.
2372 if ((ch
->ch_open_count
== 0) &&
2373 !(ch
->ch_digi
.digi_flags
& DIGI_PRINTER
)) {
2375 ch
->ch_flags
&= ~(CH_RXBLOCK
);
2377 DGAP_UNLOCK(ch
->ch_lock
, lock_flags
);
2379 /* wait for output to drain */
2380 /* This will also return if we take an interrupt */
2382 rc
= dgap_wait_for_drain(tty
);
2384 dgap_tty_flush_buffer(tty
);
2385 tty_ldisc_flush(tty
);
2387 DGAP_LOCK(ch
->ch_lock
, lock_flags
);
2392 * If we have HUPCL set, lower DTR and RTS
2394 if (ch
->ch_c_cflag
& HUPCL
) {
2395 ch
->ch_mostat
&= ~(D_RTS(ch
)|D_DTR(ch
));
2396 dgap_cmdb(ch
, SMODEM
, 0, D_DTR(ch
)|D_RTS(ch
), 0);
2399 * Go to sleep to ensure RTS/DTR
2400 * have been dropped for modems to see it.
2402 if (ch
->ch_close_delay
) {
2403 DGAP_UNLOCK(ch
->ch_lock
, lock_flags
);
2404 dgap_ms_sleep(ch
->ch_close_delay
);
2405 DGAP_LOCK(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 DGAP_UNLOCK(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 DGAP_LOCK(bd
->bd_lock
, lock_flags
);
2474 DGAP_LOCK(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 DGAP_UNLOCK(ch
->ch_lock
, lock_flags2
);
2490 DGAP_UNLOCK(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 DGAP_LOCK(ch
->ch_lock
, lock_flags
);
2522 un
->un_flags
|= UN_EMPTY
;
2523 writeb(1, &(bs
->iempty
));
2524 DGAP_UNLOCK(ch
->ch_lock
, lock_flags
);
2533 static int dgap_wait_for_drain(struct tty_struct
*tty
)
2535 struct channel_t
*ch
;
2540 ulong lock_flags
= 0;
2542 if (!tty
|| tty
->magic
!= TTY_MAGIC
)
2545 un
= tty
->driver_data
;
2546 if (!un
|| un
->magic
!= DGAP_UNIT_MAGIC
)
2550 if (!ch
|| ch
->magic
!= DGAP_CHANNEL_MAGIC
)
2559 /* Loop until data is drained */
2560 while (count
!= 0) {
2562 count
= dgap_tty_chars_in_buffer(tty
);
2567 /* Set flag waiting for drain */
2568 DGAP_LOCK(ch
->ch_lock
, lock_flags
);
2569 un
->un_flags
|= UN_EMPTY
;
2570 writeb(1, &(bs
->iempty
));
2571 DGAP_UNLOCK(ch
->ch_lock
, lock_flags
);
2573 /* Go to sleep till we get woken up */
2574 ret
= wait_event_interruptible(un
->un_flags_wait
,
2575 ((un
->un_flags
& UN_EMPTY
) == 0));
2576 /* If ret is non-zero, user ctrl-c'ed us */
2581 DGAP_LOCK(ch
->ch_lock
, lock_flags
);
2582 un
->un_flags
&= ~(UN_EMPTY
);
2583 DGAP_UNLOCK(ch
->ch_lock
, lock_flags
);
2591 * Reduces bytes_available to the max number of characters
2592 * that can be sent currently given the maxcps value, and
2593 * returns the new bytes_available. This only affects printer
2596 static int dgap_maxcps_room(struct tty_struct
*tty
, int bytes_available
)
2598 struct channel_t
*ch
= NULL
;
2599 struct un_t
*un
= NULL
;
2602 return bytes_available
;
2604 un
= tty
->driver_data
;
2605 if (!un
|| un
->magic
!= DGAP_UNIT_MAGIC
)
2606 return bytes_available
;
2609 if (!ch
|| ch
->magic
!= DGAP_CHANNEL_MAGIC
)
2610 return bytes_available
;
2613 * If its not the Transparent print device, return
2614 * the full data amount.
2616 if (un
->un_type
!= DGAP_PRINT
)
2617 return bytes_available
;
2619 if (ch
->ch_digi
.digi_maxcps
> 0 && ch
->ch_digi
.digi_bufsize
> 0) {
2621 unsigned long current_time
= jiffies
;
2622 unsigned long buffer_time
= current_time
+
2623 (HZ
* ch
->ch_digi
.digi_bufsize
) /
2624 ch
->ch_digi
.digi_maxcps
;
2626 if (ch
->ch_cpstime
< current_time
) {
2627 /* buffer is empty */
2628 ch
->ch_cpstime
= current_time
; /* reset ch_cpstime */
2629 cps_limit
= ch
->ch_digi
.digi_bufsize
;
2630 } else if (ch
->ch_cpstime
< buffer_time
) {
2631 /* still room in the buffer */
2632 cps_limit
= ((buffer_time
- ch
->ch_cpstime
) *
2633 ch
->ch_digi
.digi_maxcps
) / HZ
;
2635 /* no room in the buffer */
2639 bytes_available
= min(cps_limit
, bytes_available
);
2642 return bytes_available
;
2645 static inline void dgap_set_firmware_event(struct un_t
*un
, unsigned int event
)
2647 struct channel_t
*ch
= NULL
;
2648 struct bs_t
*bs
= NULL
;
2650 if (!un
|| un
->magic
!= DGAP_UNIT_MAGIC
)
2653 if (!ch
|| ch
->magic
!= DGAP_CHANNEL_MAGIC
)
2659 if ((event
& UN_LOW
) != 0) {
2660 if ((un
->un_flags
& UN_LOW
) == 0) {
2661 un
->un_flags
|= UN_LOW
;
2662 writeb(1, &(bs
->ilow
));
2665 if ((event
& UN_LOW
) != 0) {
2666 if ((un
->un_flags
& UN_EMPTY
) == 0) {
2667 un
->un_flags
|= UN_EMPTY
;
2668 writeb(1, &(bs
->iempty
));
2674 * dgap_tty_write_room()
2676 * Return space available in Tx buffer
2678 static int dgap_tty_write_room(struct tty_struct
*tty
)
2680 struct channel_t
*ch
= NULL
;
2681 struct un_t
*un
= NULL
;
2682 struct bs_t
*bs
= NULL
;
2683 u16 head
, tail
, tmask
;
2685 ulong lock_flags
= 0;
2690 un
= tty
->driver_data
;
2691 if (!un
|| un
->magic
!= DGAP_UNIT_MAGIC
)
2695 if (!ch
|| ch
->magic
!= DGAP_CHANNEL_MAGIC
)
2702 DGAP_LOCK(ch
->ch_lock
, lock_flags
);
2704 tmask
= ch
->ch_tsize
- 1;
2705 head
= readw(&(bs
->tx_head
)) & tmask
;
2706 tail
= readw(&(bs
->tx_tail
)) & tmask
;
2708 ret
= tail
- head
- 1;
2710 ret
+= ch
->ch_tsize
;
2712 /* Limit printer to maxcps */
2713 ret
= dgap_maxcps_room(tty
, ret
);
2716 * If we are printer device, leave space for
2717 * possibly both the on and off strings.
2719 if (un
->un_type
== DGAP_PRINT
) {
2720 if (!(ch
->ch_flags
& CH_PRON
))
2721 ret
-= ch
->ch_digi
.digi_onlen
;
2722 ret
-= ch
->ch_digi
.digi_offlen
;
2724 if (ch
->ch_flags
& CH_PRON
)
2725 ret
-= ch
->ch_digi
.digi_offlen
;
2732 * Schedule FEP to wake us up if needed.
2734 * TODO: This might be overkill...
2735 * Do we really need to schedule callbacks from the FEP
2736 * in every case? Can we get smarter based on ret?
2738 dgap_set_firmware_event(un
, UN_LOW
| UN_EMPTY
);
2739 DGAP_UNLOCK(ch
->ch_lock
, lock_flags
);
2745 * dgap_tty_put_char()
2747 * Put a character into ch->ch_buf
2749 * - used by the line discipline for OPOST processing
2751 static int dgap_tty_put_char(struct tty_struct
*tty
, unsigned char c
)
2754 * Simply call tty_write.
2756 dgap_tty_write(tty
, &c
, 1);
2763 * Take data from the user or kernel and send it out to the FEP.
2764 * In here exists all the Transparent Print magic as well.
2766 static int dgap_tty_write(struct tty_struct
*tty
, const unsigned char *buf
,
2769 struct channel_t
*ch
= NULL
;
2770 struct un_t
*un
= NULL
;
2771 struct bs_t
*bs
= NULL
;
2773 u16 head
, tail
, tmask
, remain
;
2774 int bufcount
= 0, n
= 0;
2781 un
= tty
->driver_data
;
2782 if (!un
|| un
->magic
!= DGAP_UNIT_MAGIC
)
2786 if (!ch
|| ch
->magic
!= DGAP_CHANNEL_MAGIC
)
2797 * Store original amount of characters passed in.
2798 * This helps to figure out if we should ask the FEP
2799 * to send us an event when it has more space available.
2803 DGAP_LOCK(ch
->ch_lock
, lock_flags
);
2805 /* Get our space available for the channel from the board */
2806 tmask
= ch
->ch_tsize
- 1;
2807 head
= readw(&(bs
->tx_head
)) & tmask
;
2808 tail
= readw(&(bs
->tx_tail
)) & tmask
;
2810 bufcount
= tail
- head
- 1;
2812 bufcount
+= ch
->ch_tsize
;
2815 * Limit printer output to maxcps overall, with bursts allowed
2816 * up to bufsize characters.
2818 bufcount
= dgap_maxcps_room(tty
, bufcount
);
2821 * Take minimum of what the user wants to send, and the
2822 * space available in the FEP buffer.
2824 count
= min(count
, bufcount
);
2827 * Bail if no space left.
2830 dgap_set_firmware_event(un
, UN_LOW
| UN_EMPTY
);
2831 DGAP_UNLOCK(ch
->ch_lock
, lock_flags
);
2836 * Output the printer ON string, if we are in terminal mode, but
2837 * need to be in printer mode.
2839 if ((un
->un_type
== DGAP_PRINT
) && !(ch
->ch_flags
& CH_PRON
)) {
2840 dgap_wmove(ch
, ch
->ch_digi
.digi_onstr
,
2841 (int) ch
->ch_digi
.digi_onlen
);
2842 head
= readw(&(bs
->tx_head
)) & tmask
;
2843 ch
->ch_flags
|= CH_PRON
;
2847 * On the other hand, output the printer OFF string, if we are
2848 * currently in printer mode, but need to output to the terminal.
2850 if ((un
->un_type
!= DGAP_PRINT
) && (ch
->ch_flags
& CH_PRON
)) {
2851 dgap_wmove(ch
, ch
->ch_digi
.digi_offstr
,
2852 (int) ch
->ch_digi
.digi_offlen
);
2853 head
= readw(&(bs
->tx_head
)) & tmask
;
2854 ch
->ch_flags
&= ~CH_PRON
;
2858 * If there is nothing left to copy, or
2859 * I can't handle any more data, leave.
2862 dgap_set_firmware_event(un
, UN_LOW
| UN_EMPTY
);
2863 DGAP_UNLOCK(ch
->ch_lock
, lock_flags
);
2870 * If the write wraps over the top of the circular buffer,
2871 * move the portion up to the wrap point, and reset the
2872 * pointers to the bottom.
2874 remain
= ch
->ch_tstart
+ ch
->ch_tsize
- head
;
2878 vaddr
= ch
->ch_taddr
+ head
;
2880 memcpy_toio(vaddr
, (uchar
*) buf
, remain
);
2881 dgap_sniff_nowait_nolock(ch
, "USER WRITE", (uchar
*) buf
,
2884 head
= ch
->ch_tstart
;
2891 * Move rest of data.
2893 vaddr
= ch
->ch_taddr
+ head
;
2896 memcpy_toio(vaddr
, (uchar
*) buf
, remain
);
2897 dgap_sniff_nowait_nolock(ch
, "USER WRITE", (uchar
*)buf
,
2905 ch
->ch_txcount
+= count
;
2907 writew(head
, &(bs
->tx_head
));
2910 dgap_set_firmware_event(un
, UN_LOW
| UN_EMPTY
);
2913 * If this is the print device, and the
2914 * printer is still on, we need to turn it
2915 * off before going idle. If the buffer is
2916 * non-empty, wait until it goes empty.
2917 * Otherwise turn it off right now.
2919 if ((un
->un_type
== DGAP_PRINT
) && (ch
->ch_flags
& CH_PRON
)) {
2920 tail
= readw(&(bs
->tx_tail
)) & tmask
;
2923 un
->un_flags
|= UN_EMPTY
;
2924 writeb(1, &(bs
->iempty
));
2926 dgap_wmove(ch
, ch
->ch_digi
.digi_offstr
,
2927 (int) ch
->ch_digi
.digi_offlen
);
2928 head
= readw(&(bs
->tx_head
)) & tmask
;
2929 ch
->ch_flags
&= ~CH_PRON
;
2933 /* Update printer buffer empty time. */
2934 if ((un
->un_type
== DGAP_PRINT
) && (ch
->ch_digi
.digi_maxcps
> 0)
2935 && (ch
->ch_digi
.digi_bufsize
> 0)) {
2936 ch
->ch_cpstime
+= (HZ
* count
) / ch
->ch_digi
.digi_maxcps
;
2939 DGAP_UNLOCK(ch
->ch_lock
, lock_flags
);
2945 * Return modem signals to ld.
2947 static int dgap_tty_tiocmget(struct tty_struct
*tty
)
2949 struct channel_t
*ch
;
2955 if (!tty
|| tty
->magic
!= TTY_MAGIC
)
2958 un
= tty
->driver_data
;
2959 if (!un
|| un
->magic
!= DGAP_UNIT_MAGIC
)
2963 if (!ch
|| ch
->magic
!= DGAP_CHANNEL_MAGIC
)
2966 DGAP_LOCK(ch
->ch_lock
, lock_flags
);
2968 mstat
= readb(&(ch
->ch_bs
->m_stat
));
2969 /* Append any outbound signals that might be pending... */
2970 mstat
|= ch
->ch_mostat
;
2972 DGAP_UNLOCK(ch
->ch_lock
, lock_flags
);
2976 if (mstat
& D_DTR(ch
))
2977 result
|= TIOCM_DTR
;
2978 if (mstat
& D_RTS(ch
))
2979 result
|= TIOCM_RTS
;
2980 if (mstat
& D_CTS(ch
))
2981 result
|= TIOCM_CTS
;
2982 if (mstat
& D_DSR(ch
))
2983 result
|= TIOCM_DSR
;
2984 if (mstat
& D_RI(ch
))
2986 if (mstat
& D_CD(ch
))
2993 * dgap_tty_tiocmset()
2995 * Set modem signals, called by ld.
2997 static int dgap_tty_tiocmset(struct tty_struct
*tty
,
2998 unsigned int set
, unsigned int clear
)
3001 struct channel_t
*ch
;
3007 if (!tty
|| tty
->magic
!= TTY_MAGIC
)
3010 un
= tty
->driver_data
;
3011 if (!un
|| un
->magic
!= DGAP_UNIT_MAGIC
)
3015 if (!ch
|| ch
->magic
!= DGAP_CHANNEL_MAGIC
)
3019 if (!bd
|| bd
->magic
!= DGAP_BOARD_MAGIC
)
3022 DGAP_LOCK(bd
->bd_lock
, lock_flags
);
3023 DGAP_LOCK(ch
->ch_lock
, lock_flags2
);
3025 if (set
& TIOCM_RTS
) {
3026 ch
->ch_mforce
|= D_RTS(ch
);
3027 ch
->ch_mval
|= D_RTS(ch
);
3030 if (set
& TIOCM_DTR
) {
3031 ch
->ch_mforce
|= D_DTR(ch
);
3032 ch
->ch_mval
|= D_DTR(ch
);
3035 if (clear
& TIOCM_RTS
) {
3036 ch
->ch_mforce
|= D_RTS(ch
);
3037 ch
->ch_mval
&= ~(D_RTS(ch
));
3040 if (clear
& TIOCM_DTR
) {
3041 ch
->ch_mforce
|= D_DTR(ch
);
3042 ch
->ch_mval
&= ~(D_DTR(ch
));
3047 DGAP_UNLOCK(ch
->ch_lock
, lock_flags2
);
3048 DGAP_UNLOCK(bd
->bd_lock
, lock_flags
);
3054 * dgap_tty_send_break()
3056 * Send a Break, called by ld.
3058 static int dgap_tty_send_break(struct tty_struct
*tty
, int msec
)
3061 struct channel_t
*ch
;
3067 if (!tty
|| tty
->magic
!= TTY_MAGIC
)
3070 un
= tty
->driver_data
;
3071 if (!un
|| un
->magic
!= DGAP_UNIT_MAGIC
)
3075 if (!ch
|| ch
->magic
!= DGAP_CHANNEL_MAGIC
)
3079 if (!bd
|| bd
->magic
!= DGAP_BOARD_MAGIC
)
3094 DGAP_LOCK(bd
->bd_lock
, lock_flags
);
3095 DGAP_LOCK(ch
->ch_lock
, lock_flags2
);
3097 dgap_cmdw(ch
, SBREAK
, (u16
) SBREAK_TIME
, 0);
3099 dgap_cmdw(ch
, SBREAK
, (u16
) msec
, 0);
3101 DGAP_UNLOCK(ch
->ch_lock
, lock_flags2
);
3102 DGAP_UNLOCK(bd
->bd_lock
, lock_flags
);
3108 * dgap_tty_wait_until_sent()
3110 * wait until data has been transmitted, called by ld.
3112 static void dgap_tty_wait_until_sent(struct tty_struct
*tty
, int timeout
)
3114 dgap_wait_for_drain(tty
);
3120 * send a high priority character, called by ld.
3122 static void dgap_tty_send_xchar(struct tty_struct
*tty
, char c
)
3125 struct channel_t
*ch
;
3130 if (!tty
|| tty
->magic
!= TTY_MAGIC
)
3133 un
= tty
->driver_data
;
3134 if (!un
|| un
->magic
!= DGAP_UNIT_MAGIC
)
3138 if (!ch
|| ch
->magic
!= DGAP_CHANNEL_MAGIC
)
3142 if (!bd
|| bd
->magic
!= DGAP_BOARD_MAGIC
)
3145 DGAP_LOCK(bd
->bd_lock
, lock_flags
);
3146 DGAP_LOCK(ch
->ch_lock
, lock_flags2
);
3149 * This is technically what we should do.
3150 * However, the NIST tests specifically want
3151 * to see each XON or XOFF character that it
3152 * sends, so lets just send each character
3156 if (c
== STOP_CHAR(tty
))
3157 dgap_cmdw(ch
, RPAUSE
, 0, 0);
3158 else if (c
== START_CHAR(tty
))
3159 dgap_cmdw(ch
, RRESUME
, 0, 0);
3161 dgap_wmove(ch
, &c
, 1);
3163 dgap_wmove(ch
, &c
, 1);
3166 DGAP_UNLOCK(ch
->ch_lock
, lock_flags2
);
3167 DGAP_UNLOCK(bd
->bd_lock
, lock_flags
);
3173 * Return modem signals to ld.
3175 static int dgap_get_modem_info(struct channel_t
*ch
, unsigned int __user
*value
)
3182 if (!ch
|| ch
->magic
!= DGAP_CHANNEL_MAGIC
)
3185 DGAP_LOCK(ch
->ch_lock
, lock_flags
);
3187 mstat
= readb(&(ch
->ch_bs
->m_stat
));
3188 /* Append any outbound signals that might be pending... */
3189 mstat
|= ch
->ch_mostat
;
3191 DGAP_UNLOCK(ch
->ch_lock
, lock_flags
);
3195 if (mstat
& D_DTR(ch
))
3196 result
|= TIOCM_DTR
;
3197 if (mstat
& D_RTS(ch
))
3198 result
|= TIOCM_RTS
;
3199 if (mstat
& D_CTS(ch
))
3200 result
|= TIOCM_CTS
;
3201 if (mstat
& D_DSR(ch
))
3202 result
|= TIOCM_DSR
;
3203 if (mstat
& D_RI(ch
))
3205 if (mstat
& D_CD(ch
))
3208 rc
= put_user(result
, value
);
3214 * dgap_set_modem_info()
3216 * Set modem signals, called by ld.
3218 static int dgap_set_modem_info(struct tty_struct
*tty
, unsigned int command
,
3219 unsigned int __user
*value
)
3222 struct channel_t
*ch
;
3225 unsigned int arg
= 0;
3229 if (!tty
|| tty
->magic
!= TTY_MAGIC
)
3232 un
= tty
->driver_data
;
3233 if (!un
|| un
->magic
!= DGAP_UNIT_MAGIC
)
3237 if (!ch
|| ch
->magic
!= DGAP_CHANNEL_MAGIC
)
3241 if (!bd
|| bd
->magic
!= DGAP_BOARD_MAGIC
)
3244 ret
= get_user(arg
, value
);
3250 if (arg
& TIOCM_RTS
) {
3251 ch
->ch_mforce
|= D_RTS(ch
);
3252 ch
->ch_mval
|= D_RTS(ch
);
3255 if (arg
& TIOCM_DTR
) {
3256 ch
->ch_mforce
|= D_DTR(ch
);
3257 ch
->ch_mval
|= D_DTR(ch
);
3263 if (arg
& TIOCM_RTS
) {
3264 ch
->ch_mforce
|= D_RTS(ch
);
3265 ch
->ch_mval
&= ~(D_RTS(ch
));
3268 if (arg
& TIOCM_DTR
) {
3269 ch
->ch_mforce
|= D_DTR(ch
);
3270 ch
->ch_mval
&= ~(D_DTR(ch
));
3276 ch
->ch_mforce
= D_DTR(ch
)|D_RTS(ch
);
3278 if (arg
& TIOCM_RTS
)
3279 ch
->ch_mval
|= D_RTS(ch
);
3281 ch
->ch_mval
&= ~(D_RTS(ch
));
3283 if (arg
& TIOCM_DTR
)
3284 ch
->ch_mval
|= (D_DTR(ch
));
3286 ch
->ch_mval
&= ~(D_DTR(ch
));
3294 DGAP_LOCK(bd
->bd_lock
, lock_flags
);
3295 DGAP_LOCK(ch
->ch_lock
, lock_flags2
);
3299 DGAP_UNLOCK(ch
->ch_lock
, lock_flags2
);
3300 DGAP_UNLOCK(bd
->bd_lock
, lock_flags
);
3306 * dgap_tty_digigeta()
3308 * Ioctl to get the information for ditty.
3313 static int dgap_tty_digigeta(struct tty_struct
*tty
,
3314 struct digi_t __user
*retinfo
)
3316 struct channel_t
*ch
;
3324 if (!tty
|| tty
->magic
!= TTY_MAGIC
)
3327 un
= tty
->driver_data
;
3328 if (!un
|| un
->magic
!= DGAP_UNIT_MAGIC
)
3332 if (!ch
|| ch
->magic
!= DGAP_CHANNEL_MAGIC
)
3335 memset(&tmp
, 0, sizeof(tmp
));
3337 DGAP_LOCK(ch
->ch_lock
, lock_flags
);
3338 memcpy(&tmp
, &ch
->ch_digi
, sizeof(tmp
));
3339 DGAP_UNLOCK(ch
->ch_lock
, lock_flags
);
3341 if (copy_to_user(retinfo
, &tmp
, sizeof(*retinfo
)))
3348 * dgap_tty_digiseta()
3350 * Ioctl to set the information for ditty.
3355 static int dgap_tty_digiseta(struct tty_struct
*tty
,
3356 struct digi_t __user
*new_info
)
3359 struct channel_t
*ch
;
3361 struct digi_t new_digi
;
3362 ulong lock_flags
= 0;
3363 unsigned long lock_flags2
;
3365 if (!tty
|| tty
->magic
!= TTY_MAGIC
)
3368 un
= tty
->driver_data
;
3369 if (!un
|| un
->magic
!= DGAP_UNIT_MAGIC
)
3373 if (!ch
|| ch
->magic
!= DGAP_CHANNEL_MAGIC
)
3377 if (!bd
|| bd
->magic
!= DGAP_BOARD_MAGIC
)
3380 if (copy_from_user(&new_digi
, new_info
, sizeof(struct digi_t
)))
3383 DGAP_LOCK(bd
->bd_lock
, lock_flags
);
3384 DGAP_LOCK(ch
->ch_lock
, lock_flags2
);
3386 memcpy(&ch
->ch_digi
, &new_digi
, sizeof(struct digi_t
));
3388 if (ch
->ch_digi
.digi_maxcps
< 1)
3389 ch
->ch_digi
.digi_maxcps
= 1;
3391 if (ch
->ch_digi
.digi_maxcps
> 10000)
3392 ch
->ch_digi
.digi_maxcps
= 10000;
3394 if (ch
->ch_digi
.digi_bufsize
< 10)
3395 ch
->ch_digi
.digi_bufsize
= 10;
3397 if (ch
->ch_digi
.digi_maxchar
< 1)
3398 ch
->ch_digi
.digi_maxchar
= 1;
3400 if (ch
->ch_digi
.digi_maxchar
> ch
->ch_digi
.digi_bufsize
)
3401 ch
->ch_digi
.digi_maxchar
= ch
->ch_digi
.digi_bufsize
;
3403 if (ch
->ch_digi
.digi_onlen
> DIGI_PLEN
)
3404 ch
->ch_digi
.digi_onlen
= DIGI_PLEN
;
3406 if (ch
->ch_digi
.digi_offlen
> DIGI_PLEN
)
3407 ch
->ch_digi
.digi_offlen
= DIGI_PLEN
;
3411 DGAP_UNLOCK(ch
->ch_lock
, lock_flags2
);
3412 DGAP_UNLOCK(bd
->bd_lock
, lock_flags
);
3418 * dgap_tty_digigetedelay()
3420 * Ioctl to get the current edelay setting.
3425 static int dgap_tty_digigetedelay(struct tty_struct
*tty
, int __user
*retinfo
)
3427 struct channel_t
*ch
;
3435 if (!tty
|| tty
->magic
!= TTY_MAGIC
)
3438 un
= tty
->driver_data
;
3439 if (!un
|| un
->magic
!= DGAP_UNIT_MAGIC
)
3443 if (!ch
|| ch
->magic
!= DGAP_CHANNEL_MAGIC
)
3446 memset(&tmp
, 0, sizeof(tmp
));
3448 DGAP_LOCK(ch
->ch_lock
, lock_flags
);
3449 tmp
= readw(&(ch
->ch_bs
->edelay
));
3450 DGAP_UNLOCK(ch
->ch_lock
, lock_flags
);
3452 if (copy_to_user(retinfo
, &tmp
, sizeof(*retinfo
)))
3459 * dgap_tty_digisetedelay()
3461 * Ioctl to set the EDELAY setting
3464 static int dgap_tty_digisetedelay(struct tty_struct
*tty
, int __user
*new_info
)
3467 struct channel_t
*ch
;
3473 if (!tty
|| tty
->magic
!= TTY_MAGIC
)
3476 un
= tty
->driver_data
;
3477 if (!un
|| un
->magic
!= DGAP_UNIT_MAGIC
)
3481 if (!ch
|| ch
->magic
!= DGAP_CHANNEL_MAGIC
)
3485 if (!bd
|| bd
->magic
!= DGAP_BOARD_MAGIC
)
3488 if (copy_from_user(&new_digi
, new_info
, sizeof(int)))
3491 DGAP_LOCK(bd
->bd_lock
, lock_flags
);
3492 DGAP_LOCK(ch
->ch_lock
, lock_flags2
);
3494 writew((u16
) new_digi
, &(ch
->ch_bs
->edelay
));
3498 DGAP_UNLOCK(ch
->ch_lock
, lock_flags2
);
3499 DGAP_UNLOCK(bd
->bd_lock
, lock_flags
);
3505 * dgap_tty_digigetcustombaud()
3507 * Ioctl to get the current custom baud rate setting.
3509 static int dgap_tty_digigetcustombaud(struct tty_struct
*tty
,
3510 int __user
*retinfo
)
3512 struct channel_t
*ch
;
3520 if (!tty
|| tty
->magic
!= TTY_MAGIC
)
3523 un
= tty
->driver_data
;
3524 if (!un
|| un
->magic
!= DGAP_UNIT_MAGIC
)
3528 if (!ch
|| ch
->magic
!= DGAP_CHANNEL_MAGIC
)
3531 memset(&tmp
, 0, sizeof(tmp
));
3533 DGAP_LOCK(ch
->ch_lock
, lock_flags
);
3534 tmp
= dgap_get_custom_baud(ch
);
3535 DGAP_UNLOCK(ch
->ch_lock
, lock_flags
);
3537 if (copy_to_user(retinfo
, &tmp
, sizeof(*retinfo
)))
3544 * dgap_tty_digisetcustombaud()
3546 * Ioctl to set the custom baud rate setting
3548 static int dgap_tty_digisetcustombaud(struct tty_struct
*tty
,
3549 int __user
*new_info
)
3552 struct channel_t
*ch
;
3558 if (!tty
|| tty
->magic
!= TTY_MAGIC
)
3561 un
= tty
->driver_data
;
3562 if (!un
|| un
->magic
!= DGAP_UNIT_MAGIC
)
3566 if (!ch
|| ch
->magic
!= DGAP_CHANNEL_MAGIC
)
3570 if (!bd
|| bd
->magic
!= DGAP_BOARD_MAGIC
)
3574 if (copy_from_user(&new_rate
, new_info
, sizeof(unsigned int)))
3577 if (bd
->bd_flags
& BD_FEP5PLUS
) {
3579 DGAP_LOCK(bd
->bd_lock
, lock_flags
);
3580 DGAP_LOCK(ch
->ch_lock
, lock_flags2
);
3582 ch
->ch_custom_speed
= new_rate
;
3586 DGAP_UNLOCK(ch
->ch_lock
, lock_flags2
);
3587 DGAP_UNLOCK(bd
->bd_lock
, lock_flags
);
3594 * dgap_set_termios()
3596 static void dgap_tty_set_termios(struct tty_struct
*tty
,
3597 struct ktermios
*old_termios
)
3600 struct channel_t
*ch
;
3602 unsigned long lock_flags
;
3603 unsigned long lock_flags2
;
3605 if (!tty
|| tty
->magic
!= TTY_MAGIC
)
3608 un
= tty
->driver_data
;
3609 if (!un
|| un
->magic
!= DGAP_UNIT_MAGIC
)
3613 if (!ch
|| ch
->magic
!= DGAP_CHANNEL_MAGIC
)
3617 if (!bd
|| bd
->magic
!= DGAP_BOARD_MAGIC
)
3620 DGAP_LOCK(bd
->bd_lock
, lock_flags
);
3621 DGAP_LOCK(ch
->ch_lock
, lock_flags2
);
3623 ch
->ch_c_cflag
= tty
->termios
.c_cflag
;
3624 ch
->ch_c_iflag
= tty
->termios
.c_iflag
;
3625 ch
->ch_c_oflag
= tty
->termios
.c_oflag
;
3626 ch
->ch_c_lflag
= tty
->termios
.c_lflag
;
3627 ch
->ch_startc
= tty
->termios
.c_cc
[VSTART
];
3628 ch
->ch_stopc
= tty
->termios
.c_cc
[VSTOP
];
3633 DGAP_UNLOCK(ch
->ch_lock
, lock_flags2
);
3634 DGAP_UNLOCK(bd
->bd_lock
, lock_flags
);
3637 static void dgap_tty_throttle(struct tty_struct
*tty
)
3640 struct channel_t
*ch
;
3645 if (!tty
|| tty
->magic
!= TTY_MAGIC
)
3648 un
= tty
->driver_data
;
3649 if (!un
|| un
->magic
!= DGAP_UNIT_MAGIC
)
3653 if (!ch
|| ch
->magic
!= DGAP_CHANNEL_MAGIC
)
3657 if (!bd
|| bd
->magic
!= DGAP_BOARD_MAGIC
)
3660 DGAP_LOCK(bd
->bd_lock
, lock_flags
);
3661 DGAP_LOCK(ch
->ch_lock
, lock_flags2
);
3663 ch
->ch_flags
|= (CH_RXBLOCK
);
3665 dgap_cmdw(ch
, RPAUSE
, 0, 0);
3668 DGAP_UNLOCK(ch
->ch_lock
, lock_flags2
);
3669 DGAP_UNLOCK(bd
->bd_lock
, lock_flags
);
3673 static void dgap_tty_unthrottle(struct tty_struct
*tty
)
3676 struct channel_t
*ch
;
3681 if (!tty
|| tty
->magic
!= TTY_MAGIC
)
3684 un
= tty
->driver_data
;
3685 if (!un
|| un
->magic
!= DGAP_UNIT_MAGIC
)
3689 if (!ch
|| ch
->magic
!= DGAP_CHANNEL_MAGIC
)
3693 if (!bd
|| bd
->magic
!= DGAP_BOARD_MAGIC
)
3696 DGAP_LOCK(bd
->bd_lock
, lock_flags
);
3697 DGAP_LOCK(ch
->ch_lock
, lock_flags2
);
3699 ch
->ch_flags
&= ~(CH_RXBLOCK
);
3702 dgap_cmdw(ch
, RRESUME
, 0, 0);
3705 DGAP_UNLOCK(ch
->ch_lock
, lock_flags2
);
3706 DGAP_UNLOCK(bd
->bd_lock
, lock_flags
);
3709 static void dgap_tty_start(struct tty_struct
*tty
)
3712 struct channel_t
*ch
;
3717 if (!tty
|| tty
->magic
!= TTY_MAGIC
)
3720 un
= tty
->driver_data
;
3721 if (!un
|| un
->magic
!= DGAP_UNIT_MAGIC
)
3725 if (!ch
|| ch
->magic
!= DGAP_CHANNEL_MAGIC
)
3729 if (!bd
|| bd
->magic
!= DGAP_BOARD_MAGIC
)
3732 DGAP_LOCK(bd
->bd_lock
, lock_flags
);
3733 DGAP_LOCK(ch
->ch_lock
, lock_flags2
);
3735 dgap_cmdw(ch
, RESUMETX
, 0, 0);
3737 DGAP_UNLOCK(ch
->ch_lock
, lock_flags2
);
3738 DGAP_UNLOCK(bd
->bd_lock
, lock_flags
);
3742 static void dgap_tty_stop(struct tty_struct
*tty
)
3745 struct channel_t
*ch
;
3750 if (!tty
|| tty
->magic
!= TTY_MAGIC
)
3753 un
= tty
->driver_data
;
3754 if (!un
|| un
->magic
!= DGAP_UNIT_MAGIC
)
3758 if (!ch
|| ch
->magic
!= DGAP_CHANNEL_MAGIC
)
3762 if (!bd
|| bd
->magic
!= DGAP_BOARD_MAGIC
)
3765 DGAP_LOCK(bd
->bd_lock
, lock_flags
);
3766 DGAP_LOCK(ch
->ch_lock
, lock_flags2
);
3768 dgap_cmdw(ch
, PAUSETX
, 0, 0);
3770 DGAP_UNLOCK(ch
->ch_lock
, lock_flags2
);
3771 DGAP_UNLOCK(bd
->bd_lock
, lock_flags
);
3776 * dgap_tty_flush_chars()
3778 * Flush the cook buffer
3780 * Note to self, and any other poor souls who venture here:
3782 * flush in this case DOES NOT mean dispose of the data.
3783 * instead, it means "stop buffering and send it if you
3784 * haven't already." Just guess how I figured that out... SRW 2-Jun-98
3786 * It is also always called in interrupt context - JAR 8-Sept-99
3788 static void dgap_tty_flush_chars(struct tty_struct
*tty
)
3791 struct channel_t
*ch
;
3796 if (!tty
|| tty
->magic
!= TTY_MAGIC
)
3799 un
= tty
->driver_data
;
3800 if (!un
|| un
->magic
!= DGAP_UNIT_MAGIC
)
3804 if (!ch
|| ch
->magic
!= DGAP_CHANNEL_MAGIC
)
3808 if (!bd
|| bd
->magic
!= DGAP_BOARD_MAGIC
)
3811 DGAP_LOCK(bd
->bd_lock
, lock_flags
);
3812 DGAP_LOCK(ch
->ch_lock
, lock_flags2
);
3814 /* TODO: Do something here */
3816 DGAP_UNLOCK(ch
->ch_lock
, lock_flags2
);
3817 DGAP_UNLOCK(bd
->bd_lock
, lock_flags
);
3821 * dgap_tty_flush_buffer()
3823 * Flush Tx buffer (make in == out)
3825 static void dgap_tty_flush_buffer(struct tty_struct
*tty
)
3828 struct channel_t
*ch
;
3834 if (!tty
|| tty
->magic
!= TTY_MAGIC
)
3837 un
= tty
->driver_data
;
3838 if (!un
|| un
->magic
!= DGAP_UNIT_MAGIC
)
3842 if (!ch
|| ch
->magic
!= DGAP_CHANNEL_MAGIC
)
3846 if (!bd
|| bd
->magic
!= DGAP_BOARD_MAGIC
)
3849 DGAP_LOCK(bd
->bd_lock
, lock_flags
);
3850 DGAP_LOCK(ch
->ch_lock
, lock_flags2
);
3852 ch
->ch_flags
&= ~CH_STOP
;
3853 head
= readw(&(ch
->ch_bs
->tx_head
));
3854 dgap_cmdw(ch
, FLUSHTX
, (u16
) head
, 0);
3855 dgap_cmdw(ch
, RESUMETX
, 0, 0);
3856 if (ch
->ch_tun
.un_flags
& (UN_LOW
|UN_EMPTY
)) {
3857 ch
->ch_tun
.un_flags
&= ~(UN_LOW
|UN_EMPTY
);
3858 wake_up_interruptible(&ch
->ch_tun
.un_flags_wait
);
3860 if (ch
->ch_pun
.un_flags
& (UN_LOW
|UN_EMPTY
)) {
3861 ch
->ch_pun
.un_flags
&= ~(UN_LOW
|UN_EMPTY
);
3862 wake_up_interruptible(&ch
->ch_pun
.un_flags_wait
);
3865 DGAP_UNLOCK(ch
->ch_lock
, lock_flags2
);
3866 DGAP_UNLOCK(bd
->bd_lock
, lock_flags
);
3867 if (waitqueue_active(&tty
->write_wait
))
3868 wake_up_interruptible(&tty
->write_wait
);
3872 /*****************************************************************************
3874 * The IOCTL function and all of its helpers
3876 *****************************************************************************/
3881 * The usual assortment of ioctl's
3883 static int dgap_tty_ioctl(struct tty_struct
*tty
, unsigned int cmd
,
3887 struct channel_t
*ch
;
3891 ulong lock_flags
= 0;
3892 ulong lock_flags2
= 0;
3893 void __user
*uarg
= (void __user
*) arg
;
3895 if (!tty
|| tty
->magic
!= TTY_MAGIC
)
3898 un
= tty
->driver_data
;
3899 if (!un
|| un
->magic
!= DGAP_UNIT_MAGIC
)
3903 if (!ch
|| ch
->magic
!= DGAP_CHANNEL_MAGIC
)
3907 if (!bd
|| bd
->magic
!= DGAP_BOARD_MAGIC
)
3910 DGAP_LOCK(bd
->bd_lock
, lock_flags
);
3911 DGAP_LOCK(ch
->ch_lock
, lock_flags2
);
3913 if (un
->un_open_count
<= 0) {
3914 DGAP_UNLOCK(ch
->ch_lock
, lock_flags2
);
3915 DGAP_UNLOCK(bd
->bd_lock
, lock_flags
);
3921 /* Here are all the standard ioctl's that we MUST implement */
3925 * TCSBRK is SVID version: non-zero arg --> no break
3926 * this behaviour is exploited by tcdrain().
3928 * According to POSIX.1 spec (7.2.2.1.2) breaks should be
3929 * between 0.25 and 0.5 seconds so we'll ask for something
3930 * in the middle: 0.375 seconds.
3932 rc
= tty_check_change(tty
);
3933 DGAP_UNLOCK(ch
->ch_lock
, lock_flags2
);
3934 DGAP_UNLOCK(bd
->bd_lock
, lock_flags
);
3938 rc
= dgap_wait_for_drain(tty
);
3943 DGAP_LOCK(bd
->bd_lock
, lock_flags
);
3944 DGAP_LOCK(ch
->ch_lock
, lock_flags2
);
3946 if (((cmd
== TCSBRK
) && (!arg
)) || (cmd
== TCSBRKP
))
3947 dgap_cmdw(ch
, SBREAK
, (u16
) SBREAK_TIME
, 0);
3949 DGAP_UNLOCK(ch
->ch_lock
, lock_flags2
);
3950 DGAP_UNLOCK(bd
->bd_lock
, lock_flags
);
3955 /* support for POSIX tcsendbreak()
3957 * According to POSIX.1 spec (7.2.2.1.2) breaks should be
3958 * between 0.25 and 0.5 seconds so we'll ask for something
3959 * in the middle: 0.375 seconds.
3961 rc
= tty_check_change(tty
);
3962 DGAP_UNLOCK(ch
->ch_lock
, lock_flags2
);
3963 DGAP_UNLOCK(bd
->bd_lock
, lock_flags
);
3967 rc
= dgap_wait_for_drain(tty
);
3971 DGAP_LOCK(bd
->bd_lock
, lock_flags
);
3972 DGAP_LOCK(ch
->ch_lock
, lock_flags2
);
3974 dgap_cmdw(ch
, SBREAK
, (u16
) SBREAK_TIME
, 0);
3976 DGAP_UNLOCK(ch
->ch_lock
, lock_flags2
);
3977 DGAP_UNLOCK(bd
->bd_lock
, lock_flags
);
3983 * FEP5 doesn't support turning on a break unconditionally.
3984 * The FEP5 device will stop sending a break automatically
3985 * after the specified time value that was sent when turning on
3988 rc
= tty_check_change(tty
);
3989 DGAP_UNLOCK(ch
->ch_lock
, lock_flags2
);
3990 DGAP_UNLOCK(bd
->bd_lock
, lock_flags
);
3994 rc
= dgap_wait_for_drain(tty
);
3998 DGAP_LOCK(bd
->bd_lock
, lock_flags
);
3999 DGAP_LOCK(ch
->ch_lock
, lock_flags2
);
4001 dgap_cmdw(ch
, SBREAK
, (u16
) SBREAK_TIME
, 0);
4003 DGAP_UNLOCK(ch
->ch_lock
, lock_flags2
);
4004 DGAP_UNLOCK(bd
->bd_lock
, lock_flags
);
4010 * FEP5 doesn't support turning off a break unconditionally.
4011 * The FEP5 device will stop sending a break automatically
4012 * after the specified time value that was sent when turning on
4015 DGAP_UNLOCK(ch
->ch_lock
, lock_flags2
);
4016 DGAP_UNLOCK(bd
->bd_lock
, lock_flags
);
4021 DGAP_UNLOCK(ch
->ch_lock
, lock_flags2
);
4022 DGAP_UNLOCK(bd
->bd_lock
, lock_flags
);
4024 rc
= put_user(C_CLOCAL(tty
) ? 1 : 0,
4025 (unsigned long __user
*) arg
);
4029 DGAP_UNLOCK(ch
->ch_lock
, lock_flags2
);
4030 DGAP_UNLOCK(bd
->bd_lock
, lock_flags
);
4032 rc
= get_user(arg
, (unsigned long __user
*) arg
);
4036 DGAP_LOCK(bd
->bd_lock
, lock_flags
);
4037 DGAP_LOCK(ch
->ch_lock
, lock_flags2
);
4038 tty
->termios
.c_cflag
= ((tty
->termios
.c_cflag
& ~CLOCAL
) |
4039 (arg
? CLOCAL
: 0));
4041 DGAP_UNLOCK(ch
->ch_lock
, lock_flags2
);
4042 DGAP_UNLOCK(bd
->bd_lock
, lock_flags
);
4047 DGAP_UNLOCK(ch
->ch_lock
, lock_flags2
);
4048 DGAP_UNLOCK(bd
->bd_lock
, lock_flags
);
4049 return dgap_get_modem_info(ch
, uarg
);
4054 DGAP_UNLOCK(ch
->ch_lock
, lock_flags2
);
4055 DGAP_UNLOCK(bd
->bd_lock
, lock_flags
);
4056 return dgap_set_modem_info(tty
, cmd
, uarg
);
4059 * Here are any additional ioctl's that we want to implement
4064 * The linux tty driver doesn't have a flush
4065 * input routine for the driver, assuming all backed
4066 * up data is in the line disc. buffers. However,
4067 * we all know that's not the case. Here, we
4068 * act on the ioctl, but then lie and say we didn't
4069 * so the line discipline will process the flush
4072 rc
= tty_check_change(tty
);
4074 DGAP_UNLOCK(ch
->ch_lock
, lock_flags2
);
4075 DGAP_UNLOCK(bd
->bd_lock
, lock_flags
);
4079 if ((arg
== TCIFLUSH
) || (arg
== TCIOFLUSH
)) {
4080 if (!(un
->un_type
== DGAP_PRINT
)) {
4081 head
= readw(&(ch
->ch_bs
->rx_head
));
4082 writew(head
, &(ch
->ch_bs
->rx_tail
));
4083 writeb(0, &(ch
->ch_bs
->orun
));
4087 if ((arg
== TCOFLUSH
) || (arg
== TCIOFLUSH
)) {
4088 ch
->ch_flags
&= ~CH_STOP
;
4089 head
= readw(&(ch
->ch_bs
->tx_head
));
4090 dgap_cmdw(ch
, FLUSHTX
, (u16
) head
, 0);
4091 dgap_cmdw(ch
, RESUMETX
, 0, 0);
4092 if (ch
->ch_tun
.un_flags
& (UN_LOW
|UN_EMPTY
)) {
4093 ch
->ch_tun
.un_flags
&= ~(UN_LOW
|UN_EMPTY
);
4094 wake_up_interruptible(&ch
->ch_tun
.un_flags_wait
);
4096 if (ch
->ch_pun
.un_flags
& (UN_LOW
|UN_EMPTY
)) {
4097 ch
->ch_pun
.un_flags
&= ~(UN_LOW
|UN_EMPTY
);
4098 wake_up_interruptible(&ch
->ch_pun
.un_flags_wait
);
4100 if (waitqueue_active(&tty
->write_wait
))
4101 wake_up_interruptible(&tty
->write_wait
);
4103 /* Can't hold any locks when calling tty_wakeup! */
4104 DGAP_UNLOCK(ch
->ch_lock
, lock_flags2
);
4105 DGAP_UNLOCK(bd
->bd_lock
, lock_flags
);
4107 DGAP_LOCK(bd
->bd_lock
, lock_flags
);
4108 DGAP_LOCK(ch
->ch_lock
, lock_flags2
);
4111 /* pretend we didn't recognize this IOCTL */
4112 DGAP_UNLOCK(ch
->ch_lock
, lock_flags2
);
4113 DGAP_UNLOCK(bd
->bd_lock
, lock_flags
);
4115 return -ENOIOCTLCMD
;
4120 * The linux tty driver doesn't have a flush
4121 * input routine for the driver, assuming all backed
4122 * up data is in the line disc. buffers. However,
4123 * we all know that's not the case. Here, we
4124 * act on the ioctl, but then lie and say we didn't
4125 * so the line discipline will process the flush
4128 if (cmd
== TCSETSF
) {
4130 ch
->ch_flags
&= ~CH_STOP
;
4131 head
= readw(&(ch
->ch_bs
->rx_head
));
4132 writew(head
, &(ch
->ch_bs
->rx_tail
));
4135 /* now wait for all the output to drain */
4136 DGAP_UNLOCK(ch
->ch_lock
, lock_flags2
);
4137 DGAP_UNLOCK(bd
->bd_lock
, lock_flags
);
4138 rc
= dgap_wait_for_drain(tty
);
4142 /* pretend we didn't recognize this */
4143 return -ENOIOCTLCMD
;
4147 DGAP_UNLOCK(ch
->ch_lock
, lock_flags2
);
4148 DGAP_UNLOCK(bd
->bd_lock
, lock_flags
);
4149 rc
= dgap_wait_for_drain(tty
);
4153 /* pretend we didn't recognize this */
4154 return -ENOIOCTLCMD
;
4158 * The Linux Line Discipline (LD) would do this for us if we
4159 * let it, but we have the special firmware options to do this
4160 * the "right way" regardless of hardware or software flow
4161 * control so we'll do it outselves instead of letting the LD
4164 rc
= tty_check_change(tty
);
4166 DGAP_UNLOCK(ch
->ch_lock
, lock_flags2
);
4167 DGAP_UNLOCK(bd
->bd_lock
, lock_flags
);
4174 DGAP_UNLOCK(ch
->ch_lock
, lock_flags2
);
4175 DGAP_UNLOCK(bd
->bd_lock
, lock_flags
);
4176 dgap_tty_start(tty
);
4179 DGAP_UNLOCK(ch
->ch_lock
, lock_flags2
);
4180 DGAP_UNLOCK(bd
->bd_lock
, lock_flags
);
4184 DGAP_UNLOCK(ch
->ch_lock
, lock_flags2
);
4185 DGAP_UNLOCK(bd
->bd_lock
, lock_flags
);
4186 /* Make the ld do it */
4187 return -ENOIOCTLCMD
;
4189 DGAP_UNLOCK(ch
->ch_lock
, lock_flags2
);
4190 DGAP_UNLOCK(bd
->bd_lock
, lock_flags
);
4191 /* Make the ld do it */
4192 return -ENOIOCTLCMD
;
4194 DGAP_UNLOCK(ch
->ch_lock
, lock_flags2
);
4195 DGAP_UNLOCK(bd
->bd_lock
, lock_flags
);
4200 /* get information for ditty */
4201 DGAP_UNLOCK(ch
->ch_lock
, lock_flags2
);
4202 DGAP_UNLOCK(bd
->bd_lock
, lock_flags
);
4203 return dgap_tty_digigeta(tty
, uarg
);
4208 /* set information for ditty */
4209 if (cmd
== (DIGI_SETAW
)) {
4211 DGAP_UNLOCK(ch
->ch_lock
, lock_flags2
);
4212 DGAP_UNLOCK(bd
->bd_lock
, lock_flags
);
4213 rc
= dgap_wait_for_drain(tty
);
4216 DGAP_LOCK(bd
->bd_lock
, lock_flags
);
4217 DGAP_LOCK(ch
->ch_lock
, lock_flags2
);
4219 tty_ldisc_flush(tty
);
4223 DGAP_UNLOCK(ch
->ch_lock
, lock_flags2
);
4224 DGAP_UNLOCK(bd
->bd_lock
, lock_flags
);
4225 return dgap_tty_digiseta(tty
, uarg
);
4228 DGAP_UNLOCK(ch
->ch_lock
, lock_flags2
);
4229 DGAP_UNLOCK(bd
->bd_lock
, lock_flags
);
4230 return dgap_tty_digigetedelay(tty
, uarg
);
4233 DGAP_UNLOCK(ch
->ch_lock
, lock_flags2
);
4234 DGAP_UNLOCK(bd
->bd_lock
, lock_flags
);
4235 return dgap_tty_digisetedelay(tty
, uarg
);
4237 case DIGI_GETCUSTOMBAUD
:
4238 DGAP_UNLOCK(ch
->ch_lock
, lock_flags2
);
4239 DGAP_UNLOCK(bd
->bd_lock
, lock_flags
);
4240 return dgap_tty_digigetcustombaud(tty
, uarg
);
4242 case DIGI_SETCUSTOMBAUD
:
4243 DGAP_UNLOCK(ch
->ch_lock
, lock_flags2
);
4244 DGAP_UNLOCK(bd
->bd_lock
, lock_flags
);
4245 return dgap_tty_digisetcustombaud(tty
, uarg
);
4247 case DIGI_RESET_PORT
:
4248 dgap_firmware_reset_port(ch
);
4250 DGAP_UNLOCK(ch
->ch_lock
, lock_flags2
);
4251 DGAP_UNLOCK(bd
->bd_lock
, lock_flags
);
4255 DGAP_UNLOCK(ch
->ch_lock
, lock_flags2
);
4256 DGAP_UNLOCK(bd
->bd_lock
, lock_flags
);
4258 return -ENOIOCTLCMD
;
4262 static int dgap_after_config_loaded(int board
)
4265 * Initialize KME waitqueues...
4267 init_waitqueue_head(&(dgap_Board
[board
]->kme_wait
));
4270 * allocate flip buffer for board.
4272 dgap_Board
[board
]->flipbuf
= kmalloc(MYFLIPLEN
, GFP_ATOMIC
);
4273 if (!dgap_Board
[board
]->flipbuf
)
4276 dgap_Board
[board
]->flipflagbuf
= kmalloc(MYFLIPLEN
, GFP_ATOMIC
);
4277 if (!dgap_Board
[board
]->flipflagbuf
) {
4278 kfree(dgap_Board
[board
]->flipbuf
);
4286 * Create pr and tty device entries
4288 static int dgap_tty_register_ports(struct board_t
*brd
)
4290 struct channel_t
*ch
;
4293 brd
->SerialPorts
= kcalloc(brd
->nasync
, sizeof(*brd
->SerialPorts
),
4295 if (brd
->SerialPorts
== NULL
)
4297 for (i
= 0; i
< brd
->nasync
; i
++)
4298 tty_port_init(&brd
->SerialPorts
[i
]);
4300 brd
->PrinterPorts
= kcalloc(brd
->nasync
, sizeof(*brd
->PrinterPorts
),
4302 if (brd
->PrinterPorts
== NULL
) {
4303 kfree(brd
->SerialPorts
);
4306 for (i
= 0; i
< brd
->nasync
; i
++)
4307 tty_port_init(&brd
->PrinterPorts
[i
]);
4309 ch
= brd
->channels
[0];
4310 for (i
= 0; i
< brd
->nasync
; i
++, ch
= brd
->channels
[i
]) {
4312 struct device
*classp
;
4314 classp
= tty_port_register_device(&brd
->SerialPorts
[i
],
4316 brd
->firstminor
+ i
, NULL
);
4318 dgap_create_tty_sysfs(&ch
->ch_tun
, classp
);
4319 ch
->ch_tun
.un_sysfs
= classp
;
4321 classp
= tty_port_register_device(&brd
->PrinterPorts
[i
],
4323 brd
->firstminor
+ i
, NULL
);
4325 dgap_create_tty_sysfs(&ch
->ch_pun
, classp
);
4326 ch
->ch_pun
.un_sysfs
= classp
;
4328 dgap_create_ports_sysfiles(brd
);
4334 * Copies the BIOS code from the user to the board,
4335 * and starts the BIOS running.
4337 static void dgap_do_bios_load(struct board_t
*brd
, uchar __user
*ubios
, int len
)
4343 if (!brd
|| (brd
->magic
!= DGAP_BOARD_MAGIC
) || !brd
->re_map_membase
)
4346 addr
= brd
->re_map_membase
;
4351 for (i
= 0; i
< 16; i
++)
4352 writeb(0, addr
+ POSTAREA
+ i
);
4358 memcpy_toio(addr
+ offset
, ubios
, len
);
4360 writel(0x0bf00401, addr
);
4361 writel(0, (addr
+ 4));
4363 /* Clear the reset, and change states. */
4364 writeb(FEPCLR
, brd
->re_map_port
);
4368 * Checks to see if the BIOS completed running on the card.
4370 static void dgap_do_wait_for_bios(struct board_t
*brd
)
4377 if (!brd
|| (brd
->magic
!= DGAP_BOARD_MAGIC
) || !brd
->re_map_membase
)
4380 addr
= brd
->re_map_membase
;
4381 word
= readw(addr
+ POSTAREA
);
4384 * It can take 5-6 seconds for a board to
4385 * pass the bios self test and post results.
4386 * Give it 10 seconds.
4388 brd
->wait_for_bios
= 0;
4389 while (brd
->wait_for_bios
< 1000) {
4390 /* Check to see if BIOS thinks board is good. (GD). */
4391 if (word
== *(u16
*) "GD") {
4392 brd
->state
= FINISHED_BIOS_LOAD
;
4395 msleep_interruptible(10);
4396 brd
->wait_for_bios
++;
4397 word
= readw(addr
+ POSTAREA
);
4400 /* Gave up on board after too long of time taken */
4401 err1
= readw(addr
+ SEQUENCE
);
4402 err2
= readw(addr
+ ERROR
);
4403 pr_warn("dgap: %s failed diagnostics. Error #(%x,%x).\n",
4404 brd
->name
, err1
, err2
);
4405 brd
->state
= BOARD_FAILED
;
4406 brd
->dpastatus
= BD_NOBIOS
;
4410 * Copies the FEP code from the user to the board,
4411 * and starts the FEP running.
4413 static void dgap_do_fep_load(struct board_t
*brd
, uchar
*ufep
, int len
)
4418 if (!brd
|| (brd
->magic
!= DGAP_BOARD_MAGIC
) || !brd
->re_map_membase
)
4421 addr
= brd
->re_map_membase
;
4427 memcpy_toio(addr
+ offset
, ufep
, len
);
4430 * If board is a concentrator product, we need to give
4431 * it its config string describing how the concentrators look.
4433 if ((brd
->type
== PCX
) || (brd
->type
== PEPC
)) {
4435 uchar
*config
, *xconfig
;
4438 xconfig
= dgap_create_config_string(brd
, string
);
4440 /* Write string to board memory */
4441 config
= addr
+ CONFIG
;
4442 for (; i
< CONFIGSIZE
; i
++, config
++, xconfig
++) {
4443 writeb(*xconfig
, config
);
4444 if ((*xconfig
& 0xff) == 0xff)
4449 writel(0xbfc01004, (addr
+ 0xc34));
4450 writel(0x3, (addr
+ 0xc30));
4455 * Waits for the FEP to report thats its ready for us to use.
4457 static void dgap_do_wait_for_fep(struct board_t
*brd
)
4464 if (!brd
|| (brd
->magic
!= DGAP_BOARD_MAGIC
) || !brd
->re_map_membase
)
4467 addr
= brd
->re_map_membase
;
4468 word
= readw(addr
+ FEPSTAT
);
4471 * It can take 2-3 seconds for the FEP to
4472 * be up and running. Give it 5 secs.
4474 brd
->wait_for_fep
= 0;
4475 while (brd
->wait_for_fep
< 500) {
4476 /* Check to see if FEP is up and running now. */
4477 if (word
== *(u16
*) "OS") {
4478 brd
->state
= FINISHED_FEP_LOAD
;
4480 * Check to see if the board can support FEP5+ commands.
4482 word
= readw(addr
+ FEP5_PLUS
);
4483 if (word
== *(u16
*) "5A")
4484 brd
->bd_flags
|= BD_FEP5PLUS
;
4488 msleep_interruptible(10);
4489 brd
->wait_for_fep
++;
4490 word
= readw(addr
+ FEPSTAT
);
4493 /* Gave up on board after too long of time taken */
4494 err1
= readw(addr
+ SEQUENCE
);
4495 err2
= readw(addr
+ ERROR
);
4496 pr_warn("dgap: FEPOS for %s not functioning. Error #(%x,%x).\n",
4497 brd
->name
, err1
, err2
);
4498 brd
->state
= BOARD_FAILED
;
4499 brd
->dpastatus
= BD_NOFEP
;
4503 * Physically forces the FEP5 card to reset itself.
4505 static void dgap_do_reset_board(struct board_t
*brd
)
4512 if (!brd
|| (brd
->magic
!= DGAP_BOARD_MAGIC
) ||
4513 !brd
->re_map_membase
|| !brd
->re_map_port
)
4516 /* FEPRST does not vary among supported boards */
4517 writeb(FEPRST
, brd
->re_map_port
);
4519 for (i
= 0; i
<= 1000; i
++) {
4520 check
= readb(brd
->re_map_port
) & 0xe;
4521 if (check
== FEPRST
)
4527 pr_warn("dgap: Board not resetting... Failing board.\n");
4528 brd
->state
= BOARD_FAILED
;
4529 brd
->dpastatus
= BD_NOFEP
;
4534 * Make sure there really is memory out there.
4536 writel(0xa55a3cc3, (brd
->re_map_membase
+ LOWMEM
));
4537 writel(0x5aa5c33c, (brd
->re_map_membase
+ HIGHMEM
));
4538 check1
= readl(brd
->re_map_membase
+ LOWMEM
);
4539 check2
= readl(brd
->re_map_membase
+ HIGHMEM
);
4541 if ((check1
!= 0xa55a3cc3) || (check2
!= 0x5aa5c33c)) {
4542 pr_warn("dgap: No memory at %p for board.\n",
4543 brd
->re_map_membase
);
4544 brd
->state
= BOARD_FAILED
;
4545 brd
->dpastatus
= BD_NOFEP
;
4549 if (brd
->state
!= BOARD_FAILED
)
4550 brd
->state
= FINISHED_RESET
;
4553 #ifdef DIGI_CONCENTRATORS_SUPPORTED
4555 * Sends a concentrator image into the FEP5 board.
4557 static void dgap_do_conc_load(struct board_t
*brd
, uchar
*uaddr
, int len
)
4561 struct downld_t
*to_dp
;
4563 if (!brd
|| (brd
->magic
!= DGAP_BOARD_MAGIC
) || !brd
->re_map_membase
)
4566 vaddr
= brd
->re_map_membase
;
4568 offset
= readw((u16
*) (vaddr
+ DOWNREQ
));
4569 to_dp
= (struct downld_t
*) (vaddr
+ (int) offset
);
4570 memcpy_toio(to_dp
, uaddr
, len
);
4572 /* Tell card we have data for it */
4573 writew(0, vaddr
+ (DOWNREQ
));
4575 brd
->conc_dl_status
= NO_PENDING_CONCENTRATOR_REQUESTS
;
4579 #define EXPANSION_ROM_SIZE (64 * 1024)
4580 #define FEP5_ROM_MAGIC (0xFEFFFFFF)
4582 static void dgap_get_vpd(struct board_t
*brd
)
4594 * Poke the magic number at the PCI Rom Address location.
4595 * If VPD is supported, the value read from that address
4598 magic
= FEP5_ROM_MAGIC
;
4599 pci_write_config_dword(brd
->pdev
, PCI_ROM_ADDRESS
, magic
);
4600 pci_read_config_dword(brd
->pdev
, PCI_ROM_ADDRESS
, &magic
);
4602 /* VPD not supported, bail */
4607 * To get to the OTPROM memory, we have to send the boards base
4608 * address or'ed with 1 into the PCI Rom Address location.
4610 magic
= brd
->membase
| 0x01;
4611 pci_write_config_dword(brd
->pdev
, PCI_ROM_ADDRESS
, magic
);
4612 pci_read_config_dword(brd
->pdev
, PCI_ROM_ADDRESS
, &magic
);
4614 byte1
= readb(brd
->re_map_membase
);
4615 byte2
= readb(brd
->re_map_membase
+ 1);
4618 * If the board correctly swapped to the OTPROM memory,
4619 * the first 2 bytes (header) should be 0x55, 0xAA
4621 if (byte1
== 0x55 && byte2
== 0xAA) {
4626 * We have to run through all the OTPROM memory looking
4627 * for the VPD offset.
4629 while (base_offset
<= EXPANSION_ROM_SIZE
) {
4632 * Lots of magic numbers here.
4634 * The VPD offset is located inside the ROM Data
4637 * We also have to remember the length of each
4638 * ROM Data Structure, so we can "hop" to the next
4639 * entry if the VPD isn't in the current
4640 * ROM Data Structure.
4642 rom_offset
= readw(brd
->re_map_membase
+
4643 base_offset
+ 0x18);
4644 image_length
= readw(brd
->re_map_membase
+
4645 rom_offset
+ 0x10) * 512;
4646 vpd_offset
= readw(brd
->re_map_membase
+
4649 /* Found the VPD entry */
4653 /* We didn't find a VPD entry, go to next ROM entry. */
4654 base_offset
+= image_length
;
4656 byte1
= readb(brd
->re_map_membase
+ base_offset
);
4657 byte2
= readb(brd
->re_map_membase
+ base_offset
+ 1);
4660 * If the new ROM offset doesn't have 0x55, 0xAA
4661 * as its header, we have run out of ROM.
4663 if (byte1
!= 0x55 || byte2
!= 0xAA)
4668 * If we have a VPD offset, then mark the board
4669 * as having a valid VPD, and copy VPDSIZE (512) bytes of
4670 * that VPD to the buffer we have in our board structure.
4673 brd
->bd_flags
|= BD_HAS_VPD
;
4674 for (i
= 0; i
< VPDSIZE
; i
++) {
4675 brd
->vpd
[i
] = readb(brd
->re_map_membase
+
4682 * We MUST poke the magic number at the PCI Rom Address location again.
4683 * This makes the card report the regular board memory back to us,
4684 * rather than the OTPROM memory.
4686 magic
= FEP5_ROM_MAGIC
;
4687 pci_write_config_dword(brd
->pdev
, PCI_ROM_ADDRESS
, magic
);
4691 * Our board poller function.
4693 static void dgap_poll_tasklet(unsigned long data
)
4695 struct board_t
*bd
= (struct board_t
*) data
;
4701 if (!bd
|| (bd
->magic
!= DGAP_BOARD_MAGIC
))
4704 if (bd
->inhibit_poller
)
4707 DGAP_LOCK(bd
->bd_lock
, lock_flags
);
4709 vaddr
= bd
->re_map_membase
;
4712 * If board is ready, parse deeper to see if there is anything to do.
4714 if (bd
->state
== BOARD_READY
) {
4716 struct ev_t
*eaddr
= NULL
;
4718 if (!bd
->re_map_membase
) {
4719 DGAP_UNLOCK(bd
->bd_lock
, lock_flags
);
4722 if (!bd
->re_map_port
) {
4723 DGAP_UNLOCK(bd
->bd_lock
, lock_flags
);
4730 eaddr
= (struct ev_t
*) (vaddr
+ EVBUF
);
4732 /* Get our head and tail */
4733 head
= readw(&(eaddr
->ev_head
));
4734 tail
= readw(&(eaddr
->ev_tail
));
4737 * If there is an event pending. Go service it.
4740 DGAP_UNLOCK(bd
->bd_lock
, lock_flags
);
4742 DGAP_LOCK(bd
->bd_lock
, lock_flags
);
4747 * If board is doing interrupts, ACK the interrupt.
4749 if (bd
&& bd
->intr_running
)
4750 readb(bd
->re_map_port
+ 2);
4752 DGAP_UNLOCK(bd
->bd_lock
, lock_flags
);
4756 /* Our state machine to get the board up and running */
4759 if (bd
->state
== NEED_RESET
) {
4764 dgap_do_reset_board(bd
);
4767 /* Move to next state */
4768 if (bd
->state
== FINISHED_RESET
)
4769 bd
->state
= NEED_CONFIG
;
4771 if (bd
->state
== NEED_CONFIG
) {
4773 * Match this board to a config the user created for us.
4775 bd
->bd_config
= dgap_find_config(bd
->type
, bd
->pci_bus
,
4779 * Because the 4 port Xr products share the same PCI ID
4780 * as the 8 port Xr products, if we receive a NULL config
4781 * back, and this is a PAPORT8 board, retry with a
4782 * PAPORT4 attempt as well.
4784 if (bd
->type
== PAPORT8
&& !bd
->bd_config
)
4785 bd
->bd_config
= dgap_find_config(PAPORT4
, bd
->pci_bus
,
4789 * Register the ttys (if any) into the kernel.
4792 bd
->state
= FINISHED_CONFIG
;
4794 bd
->state
= CONFIG_NOT_FOUND
;
4797 /* Move to next state */
4798 if (bd
->state
== FINISHED_CONFIG
)
4799 bd
->state
= NEED_DEVICE_CREATION
;
4801 /* Move to next state */
4802 if (bd
->state
== NEED_DEVICE_CREATION
) {
4804 * Signal downloader, its got some work to do.
4806 DGAP_LOCK(dgap_dl_lock
, lock_flags2
);
4807 if (dgap_dl_action
!= 1) {
4809 wake_up_interruptible(&dgap_dl_wait
);
4811 DGAP_UNLOCK(dgap_dl_lock
, lock_flags2
);
4814 /* Move to next state */
4815 if (bd
->state
== FINISHED_DEVICE_CREATION
)
4816 bd
->state
= NEED_BIOS_LOAD
;
4818 /* Move to next state */
4819 if (bd
->state
== NEED_BIOS_LOAD
) {
4821 * Signal downloader, its got some work to do.
4823 DGAP_LOCK(dgap_dl_lock
, lock_flags2
);
4824 if (dgap_dl_action
!= 1) {
4826 wake_up_interruptible(&dgap_dl_wait
);
4828 DGAP_UNLOCK(dgap_dl_lock
, lock_flags2
);
4831 /* Wait for BIOS to test board... */
4832 if (bd
->state
== WAIT_BIOS_LOAD
)
4833 dgap_do_wait_for_bios(bd
);
4835 /* Move to next state */
4836 if (bd
->state
== FINISHED_BIOS_LOAD
) {
4837 bd
->state
= NEED_FEP_LOAD
;
4840 * Signal downloader, its got some work to do.
4842 DGAP_LOCK(dgap_dl_lock
, lock_flags2
);
4843 if (dgap_dl_action
!= 1) {
4845 wake_up_interruptible(&dgap_dl_wait
);
4847 DGAP_UNLOCK(dgap_dl_lock
, lock_flags2
);
4850 /* Wait for FEP to load on board... */
4851 if (bd
->state
== WAIT_FEP_LOAD
)
4852 dgap_do_wait_for_fep(bd
);
4854 /* Move to next state */
4855 if (bd
->state
== FINISHED_FEP_LOAD
) {
4858 * Do tty device initialization.
4860 int rc
= dgap_tty_init(bd
);
4863 dgap_tty_uninit(bd
);
4864 bd
->state
= BOARD_FAILED
;
4865 bd
->dpastatus
= BD_NOFEP
;
4867 bd
->state
= NEED_PROC_CREATION
;
4870 * Signal downloader, its got some work to do.
4872 DGAP_LOCK(dgap_dl_lock
, lock_flags2
);
4873 if (dgap_dl_action
!= 1) {
4875 wake_up_interruptible(&dgap_dl_wait
);
4877 DGAP_UNLOCK(dgap_dl_lock
, lock_flags2
);
4881 /* Move to next state */
4882 if (bd
->state
== FINISHED_PROC_CREATION
) {
4884 bd
->state
= BOARD_READY
;
4885 bd
->dpastatus
= BD_RUNNING
;
4888 * If user requested the board to run in interrupt mode,
4889 * go and set it up on the board.
4891 if (bd
->intr_used
) {
4892 writew(1, (bd
->re_map_membase
+ ENABLE_INTR
));
4894 * Tell the board to poll the UARTS as fast as possible.
4896 writew(FEPPOLL_MIN
, (bd
->re_map_membase
+ FEPPOLL
));
4897 bd
->intr_running
= 1;
4900 /* Wake up anyone waiting for board state to change to ready */
4901 wake_up_interruptible(&bd
->state_wait
);
4904 DGAP_UNLOCK(bd
->bd_lock
, lock_flags
);
4907 /*=======================================================================
4909 * dgap_cmdb - Sends a 2 byte command to the FEP.
4911 * ch - Pointer to channel structure.
4912 * cmd - Command to be sent.
4913 * byte1 - Integer containing first byte to be sent.
4914 * byte2 - Integer containing second byte to be sent.
4915 * ncmds - Wait until ncmds or fewer cmds are left
4916 * in the cmd buffer before returning.
4918 *=======================================================================*/
4919 static void dgap_cmdb(struct channel_t
*ch
, uchar cmd
, uchar byte1
,
4920 uchar byte2
, uint ncmds
)
4923 struct cm_t
*cm_addr
= NULL
;
4929 if (!ch
|| ch
->magic
!= DGAP_CHANNEL_MAGIC
)
4933 * Check if board is still alive.
4935 if (ch
->ch_bd
->state
== BOARD_FAILED
)
4939 * Make sure the pointers are in range before
4940 * writing to the FEP memory.
4942 vaddr
= ch
->ch_bd
->re_map_membase
;
4947 cm_addr
= (struct cm_t
*) (vaddr
+ CMDBUF
);
4948 head
= readw(&(cm_addr
->cm_head
));
4951 * Forget it if pointers out of range.
4953 if (head
>= (CMDMAX
- CMDSTART
) || (head
& 03)) {
4954 ch
->ch_bd
->state
= BOARD_FAILED
;
4959 * Put the data in the circular command buffer.
4961 writeb(cmd
, (char *) (vaddr
+ head
+ CMDSTART
+ 0));
4962 writeb((uchar
) ch
->ch_portnum
, (char *) (vaddr
+ head
+ CMDSTART
+ 1));
4963 writeb(byte1
, (char *) (vaddr
+ head
+ CMDSTART
+ 2));
4964 writeb(byte2
, (char *) (vaddr
+ head
+ CMDSTART
+ 3));
4966 head
= (head
+ 4) & (CMDMAX
- CMDSTART
- 4);
4968 writew(head
, &(cm_addr
->cm_head
));
4971 * Wait if necessary before updating the head
4972 * pointer to limit the number of outstanding
4973 * commands to the FEP. If the time spent waiting
4974 * is outlandish, declare the FEP dead.
4976 for (count
= dgap_count
;;) {
4978 head
= readw(&(cm_addr
->cm_head
));
4979 tail
= readw(&(cm_addr
->cm_tail
));
4981 n
= (head
- tail
) & (CMDMAX
- CMDSTART
- 4);
4983 if (n
<= ncmds
* sizeof(struct cm_t
))
4987 ch
->ch_bd
->state
= BOARD_FAILED
;
4994 /*=======================================================================
4996 * dgap_cmdw - Sends a 1 word command to the FEP.
4998 * ch - Pointer to channel structure.
4999 * cmd - Command to be sent.
5000 * word - Integer containing word to be sent.
5001 * ncmds - Wait until ncmds or fewer cmds are left
5002 * in the cmd buffer before returning.
5004 *=======================================================================*/
5005 static void dgap_cmdw(struct channel_t
*ch
, uchar cmd
, u16 word
, uint ncmds
)
5008 struct cm_t
*cm_addr
= NULL
;
5014 if (!ch
|| ch
->magic
!= DGAP_CHANNEL_MAGIC
)
5018 * Check if board is still alive.
5020 if (ch
->ch_bd
->state
== BOARD_FAILED
)
5024 * Make sure the pointers are in range before
5025 * writing to the FEP memory.
5027 vaddr
= ch
->ch_bd
->re_map_membase
;
5031 cm_addr
= (struct cm_t
*) (vaddr
+ CMDBUF
);
5032 head
= readw(&(cm_addr
->cm_head
));
5035 * Forget it if pointers out of range.
5037 if (head
>= (CMDMAX
- CMDSTART
) || (head
& 03)) {
5038 ch
->ch_bd
->state
= BOARD_FAILED
;
5043 * Put the data in the circular command buffer.
5045 writeb(cmd
, (char *) (vaddr
+ head
+ CMDSTART
+ 0));
5046 writeb((uchar
) ch
->ch_portnum
, (char *) (vaddr
+ head
+ CMDSTART
+ 1));
5047 writew((u16
) word
, (char *) (vaddr
+ head
+ CMDSTART
+ 2));
5049 head
= (head
+ 4) & (CMDMAX
- CMDSTART
- 4);
5051 writew(head
, &(cm_addr
->cm_head
));
5054 * Wait if necessary before updating the head
5055 * pointer to limit the number of outstanding
5056 * commands to the FEP. If the time spent waiting
5057 * is outlandish, declare the FEP dead.
5059 for (count
= dgap_count
;;) {
5061 head
= readw(&(cm_addr
->cm_head
));
5062 tail
= readw(&(cm_addr
->cm_tail
));
5064 n
= (head
- tail
) & (CMDMAX
- CMDSTART
- 4);
5066 if (n
<= ncmds
* sizeof(struct cm_t
))
5070 ch
->ch_bd
->state
= BOARD_FAILED
;
5077 /*=======================================================================
5079 * dgap_cmdw_ext - Sends a extended word command to the FEP.
5081 * ch - Pointer to channel structure.
5082 * cmd - Command to be sent.
5083 * word - Integer containing word to be sent.
5084 * ncmds - Wait until ncmds or fewer cmds are left
5085 * in the cmd buffer before returning.
5087 *=======================================================================*/
5088 static void dgap_cmdw_ext(struct channel_t
*ch
, u16 cmd
, u16 word
, uint ncmds
)
5091 struct cm_t
*cm_addr
= NULL
;
5097 if (!ch
|| ch
->magic
!= DGAP_CHANNEL_MAGIC
)
5101 * Check if board is still alive.
5103 if (ch
->ch_bd
->state
== BOARD_FAILED
)
5107 * Make sure the pointers are in range before
5108 * writing to the FEP memory.
5110 vaddr
= ch
->ch_bd
->re_map_membase
;
5114 cm_addr
= (struct cm_t
*) (vaddr
+ CMDBUF
);
5115 head
= readw(&(cm_addr
->cm_head
));
5118 * Forget it if pointers out of range.
5120 if (head
>= (CMDMAX
- CMDSTART
) || (head
& 03)) {
5121 ch
->ch_bd
->state
= BOARD_FAILED
;
5126 * Put the data in the circular command buffer.
5129 /* Write an FF to tell the FEP that we want an extended command */
5130 writeb((uchar
) 0xff, (char *) (vaddr
+ head
+ CMDSTART
+ 0));
5132 writeb((uchar
) ch
->ch_portnum
, (uchar
*) (vaddr
+ head
+ CMDSTART
+ 1));
5133 writew((u16
) cmd
, (char *) (vaddr
+ head
+ CMDSTART
+ 2));
5136 * If the second part of the command won't fit,
5137 * put it at the beginning of the circular buffer.
5139 if (((head
+ 4) >= ((CMDMAX
- CMDSTART
)) || (head
& 03)))
5140 writew((u16
) word
, (char *) (vaddr
+ CMDSTART
));
5142 writew((u16
) word
, (char *) (vaddr
+ head
+ CMDSTART
+ 4));
5144 head
= (head
+ 8) & (CMDMAX
- CMDSTART
- 4);
5146 writew(head
, &(cm_addr
->cm_head
));
5149 * Wait if necessary before updating the head
5150 * pointer to limit the number of outstanding
5151 * commands to the FEP. If the time spent waiting
5152 * is outlandish, declare the FEP dead.
5154 for (count
= dgap_count
;;) {
5156 head
= readw(&(cm_addr
->cm_head
));
5157 tail
= readw(&(cm_addr
->cm_tail
));
5159 n
= (head
- tail
) & (CMDMAX
- CMDSTART
- 4);
5161 if (n
<= ncmds
* sizeof(struct cm_t
))
5165 ch
->ch_bd
->state
= BOARD_FAILED
;
5172 /*=======================================================================
5174 * dgap_wmove - Write data to FEP buffer.
5176 * ch - Pointer to channel structure.
5177 * buf - Poiter to characters to be moved.
5178 * cnt - Number of characters to move.
5180 *=======================================================================*/
5181 static void dgap_wmove(struct channel_t
*ch
, char *buf
, uint cnt
)
5188 if (!ch
|| ch
->magic
!= DGAP_CHANNEL_MAGIC
)
5195 head
= readw(&(bs
->tx_head
));
5198 * If pointers are out of range, just return.
5200 if ((cnt
> ch
->ch_tsize
) ||
5201 (unsigned)(head
- ch
->ch_tstart
) >= ch
->ch_tsize
)
5205 * If the write wraps over the top of the circular buffer,
5206 * move the portion up to the wrap point, and reset the
5207 * pointers to the bottom.
5209 n
= ch
->ch_tstart
+ ch
->ch_tsize
- head
;
5213 taddr
= ch
->ch_taddr
+ head
;
5214 memcpy_toio(taddr
, buf
, n
);
5215 head
= ch
->ch_tstart
;
5220 * Move rest of data.
5222 taddr
= ch
->ch_taddr
+ head
;
5224 memcpy_toio(taddr
, buf
, n
);
5227 writew(head
, &(bs
->tx_head
));
5231 * Retrives the current custom baud rate from FEP memory,
5232 * and returns it back to the user.
5233 * Returns 0 on error.
5235 static uint
dgap_get_custom_baud(struct channel_t
*ch
)
5241 if (!ch
|| ch
->magic
!= DGAP_CHANNEL_MAGIC
)
5244 if (!ch
->ch_bd
|| ch
->ch_bd
->magic
!= DGAP_BOARD_MAGIC
)
5247 if (!(ch
->ch_bd
->bd_flags
& BD_FEP5PLUS
))
5250 vaddr
= ch
->ch_bd
->re_map_membase
;
5256 * Go get from fep mem, what the fep
5257 * believes the custom baud rate is.
5259 offset
= ((((*(unsigned short *)(vaddr
+ ECS_SEG
)) << 4) +
5260 (ch
->ch_portnum
* 0x28) + LINE_SPEED
));
5262 value
= readw(vaddr
+ offset
);
5267 * Calls the firmware to reset this channel.
5269 static void dgap_firmware_reset_port(struct channel_t
*ch
)
5271 dgap_cmdb(ch
, CHRESET
, 0, 0, 0);
5274 * Now that the channel is reset, we need to make sure
5275 * all the current settings get reapplied to the port
5278 * So we will set the driver's cache of firmware
5279 * settings all to 0, and then call param.
5281 ch
->ch_fepiflag
= 0;
5282 ch
->ch_fepcflag
= 0;
5283 ch
->ch_fepoflag
= 0;
5284 ch
->ch_fepstartc
= 0;
5285 ch
->ch_fepstopc
= 0;
5286 ch
->ch_fepastartc
= 0;
5287 ch
->ch_fepastopc
= 0;
5292 /*=======================================================================
5294 * dgap_param - Set Digi parameters.
5296 * struct tty_struct * - TTY for port.
5298 *=======================================================================*/
5299 static int dgap_param(struct tty_struct
*tty
)
5301 struct ktermios
*ts
;
5303 struct channel_t
*ch
;
5312 if (!tty
|| tty
->magic
!= TTY_MAGIC
)
5315 un
= (struct un_t
*) tty
->driver_data
;
5316 if (!un
|| un
->magic
!= DGAP_UNIT_MAGIC
)
5320 if (!ch
|| ch
->magic
!= DGAP_CHANNEL_MAGIC
)
5324 if (!bd
|| bd
->magic
!= DGAP_BOARD_MAGIC
)
5334 * If baud rate is zero, flush queues, and set mval to drop DTR.
5336 if ((ch
->ch_c_cflag
& (CBAUD
)) == 0) {
5339 head
= readw(&(ch
->ch_bs
->rx_head
));
5340 writew(head
, &(ch
->ch_bs
->rx_tail
));
5343 head
= readw(&(ch
->ch_bs
->tx_head
));
5344 writew(head
, &(ch
->ch_bs
->tx_tail
));
5346 ch
->ch_flags
|= (CH_BAUD0
);
5348 /* Drop RTS and DTR */
5349 ch
->ch_mval
&= ~(D_RTS(ch
)|D_DTR(ch
));
5350 mval
= D_DTR(ch
) | D_RTS(ch
);
5351 ch
->ch_baud_info
= 0;
5353 } else if (ch
->ch_custom_speed
&& (bd
->bd_flags
& BD_FEP5PLUS
)) {
5355 * Tell the fep to do the command
5358 dgap_cmdw_ext(ch
, 0xff01, ch
->ch_custom_speed
, 0);
5361 * Now go get from fep mem, what the fep
5362 * believes the custom baud rate is.
5364 ch
->ch_custom_speed
= dgap_get_custom_baud(ch
);
5365 ch
->ch_baud_info
= ch
->ch_custom_speed
;
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
);
5376 * Set baud rate, character size, and parity.
5384 ulong bauds
[4][16] = {
5388 600, 1200, 1800, 2400,
5389 4800, 9600, 19200, 38400 },
5390 { /* slowbaud & CBAUDEX */
5391 0, 57600, 115200, 230400,
5392 460800, 150, 200, 921600,
5393 600, 1200, 1800, 2400,
5394 4800, 9600, 19200, 38400 },
5396 0, 57600, 76800, 115200,
5397 14400, 57600, 230400, 76800,
5398 115200, 230400, 28800, 460800,
5399 921600, 9600, 19200, 38400 },
5400 { /* fastbaud & CBAUDEX */
5401 0, 57600, 115200, 230400,
5402 460800, 150, 200, 921600,
5403 600, 1200, 1800, 2400,
5404 4800, 9600, 19200, 38400 }
5408 * Only use the TXPrint baud rate if the
5409 * terminal unit is NOT open
5411 if (!(ch
->ch_tun
.un_flags
& UN_ISOPEN
) &&
5412 (un
->un_type
== DGAP_PRINT
))
5413 baud
= C_BAUD(ch
->ch_pun
.un_tty
) & 0xff;
5415 baud
= C_BAUD(ch
->ch_tun
.un_tty
) & 0xff;
5417 if (ch
->ch_c_cflag
& CBAUDEX
)
5420 if (ch
->ch_digi
.digi_flags
& DIGI_FAST
)
5425 if ((iindex
>= 0) && (iindex
< 4) &&
5426 (jindex
>= 0) && (jindex
< 16))
5427 baud
= bauds
[iindex
][jindex
];
5434 ch
->ch_baud_info
= baud
;
5437 * CBAUD has bit position 0x1000 set these days to
5438 * indicate Linux baud rate remap.
5439 * We use a different bit assignment for high speed.
5440 * Clear this bit out while grabbing the parts of
5443 cflag
= ch
->ch_c_cflag
& ((CBAUD
^ CBAUDEX
) | PARODD
| PARENB
|
5447 * HUPCL bit is used by FEP to indicate fast baud
5448 * table is to be used.
5450 if ((ch
->ch_digi
.digi_flags
& DIGI_FAST
) ||
5451 (ch
->ch_c_cflag
& CBAUDEX
))
5454 if ((ch
->ch_c_cflag
& CBAUDEX
) &&
5455 !(ch
->ch_digi
.digi_flags
& DIGI_FAST
)) {
5457 * The below code is trying to guarantee that only
5458 * baud rates 115200, 230400, 460800, 921600 are
5459 * remapped. We use exclusive or because the various
5460 * baud rates share common bit positions and therefore
5461 * can't be tested for easily.
5463 tcflag_t tcflag
= (ch
->ch_c_cflag
& CBAUD
) | CBAUDEX
;
5467 * Map high speed requests to index
5468 * into FEP's baud table
5498 cflag
= (cflag
& ~(CBAUD
| CBAUDEX
)) | baudpart
;
5503 if (cflag
!= ch
->ch_fepcflag
) {
5504 ch
->ch_fepcflag
= (u16
) (cflag
& 0xffff);
5507 * Okay to have channel and board
5508 * locks held calling this
5510 dgap_cmdw(ch
, SCFLAG
, (u16
) cflag
, 0);
5513 /* Handle transition from B0 */
5514 if (ch
->ch_flags
& CH_BAUD0
) {
5515 ch
->ch_flags
&= ~(CH_BAUD0
);
5516 ch
->ch_mval
|= (D_RTS(ch
)|D_DTR(ch
));
5518 mval
= D_DTR(ch
) | D_RTS(ch
);
5524 iflag
= ch
->ch_c_iflag
& (IGNBRK
| BRKINT
| IGNPAR
| PARMRK
|
5525 INPCK
| ISTRIP
| IXON
| IXANY
| IXOFF
);
5527 if ((ch
->ch_startc
== _POSIX_VDISABLE
) ||
5528 (ch
->ch_stopc
== _POSIX_VDISABLE
)) {
5529 iflag
&= ~(IXON
| IXOFF
);
5530 ch
->ch_c_iflag
&= ~(IXON
| IXOFF
);
5534 * Only the IBM Xr card can switch between
5535 * 232 and 422 modes on the fly
5537 if (bd
->device
== PCI_DEV_XR_IBM_DID
) {
5538 if (ch
->ch_digi
.digi_flags
& DIGI_422
)
5539 dgap_cmdb(ch
, SCOMMODE
, MODE_422
, 0, 0);
5541 dgap_cmdb(ch
, SCOMMODE
, MODE_232
, 0, 0);
5544 if (ch
->ch_digi
.digi_flags
& DIGI_ALTPIN
)
5547 if (iflag
!= ch
->ch_fepiflag
) {
5548 ch
->ch_fepiflag
= iflag
;
5550 /* Okay to have channel and board locks held calling this */
5551 dgap_cmdw(ch
, SIFLAG
, (u16
) ch
->ch_fepiflag
, 0);
5555 * Select hardware handshaking.
5559 if (ch
->ch_c_cflag
& CRTSCTS
)
5560 hflow
|= (D_RTS(ch
) | D_CTS(ch
));
5561 if (ch
->ch_digi
.digi_flags
& RTSPACE
)
5563 if (ch
->ch_digi
.digi_flags
& DTRPACE
)
5565 if (ch
->ch_digi
.digi_flags
& CTSPACE
)
5567 if (ch
->ch_digi
.digi_flags
& DSRPACE
)
5569 if (ch
->ch_digi
.digi_flags
& DCDPACE
)
5572 if (hflow
!= ch
->ch_hflow
) {
5573 ch
->ch_hflow
= hflow
;
5575 /* Okay to have channel and board locks held calling this */
5576 dgap_cmdb(ch
, SHFLOW
, (uchar
) hflow
, 0xff, 0);
5581 * Set RTS and/or DTR Toggle if needed,
5582 * but only if product is FEP5+ based.
5584 if (bd
->bd_flags
& BD_FEP5PLUS
) {
5586 if (ch
->ch_digi
.digi_flags
& DIGI_RTS_TOGGLE
)
5587 hflow2
|= (D_RTS(ch
));
5588 if (ch
->ch_digi
.digi_flags
& DIGI_DTR_TOGGLE
)
5589 hflow2
|= (D_DTR(ch
));
5591 dgap_cmdw_ext(ch
, 0xff03, hflow2
, 0);
5595 * Set modem control lines.
5598 mval
^= ch
->ch_mforce
& (mval
^ ch
->ch_mval
);
5600 if (ch
->ch_mostat
^ mval
) {
5601 ch
->ch_mostat
= mval
;
5603 /* Okay to have channel and board locks held calling this */
5604 dgap_cmdb(ch
, SMODEM
, (uchar
) mval
, D_RTS(ch
)|D_DTR(ch
), 0);
5608 * Read modem signals, and then call carrier function.
5610 ch
->ch_mistat
= readb(&(bs
->m_stat
));
5614 * Set the start and stop characters.
5616 if (ch
->ch_startc
!= ch
->ch_fepstartc
||
5617 ch
->ch_stopc
!= ch
->ch_fepstopc
) {
5618 ch
->ch_fepstartc
= ch
->ch_startc
;
5619 ch
->ch_fepstopc
= ch
->ch_stopc
;
5621 /* Okay to have channel and board locks held calling this */
5622 dgap_cmdb(ch
, SFLOWC
, ch
->ch_fepstartc
, ch
->ch_fepstopc
, 0);
5626 * Set the Auxiliary start and stop characters.
5628 if (ch
->ch_astartc
!= ch
->ch_fepastartc
||
5629 ch
->ch_astopc
!= ch
->ch_fepastopc
) {
5630 ch
->ch_fepastartc
= ch
->ch_astartc
;
5631 ch
->ch_fepastopc
= ch
->ch_astopc
;
5633 /* Okay to have channel and board locks held calling this */
5634 dgap_cmdb(ch
, SAFLOWC
, ch
->ch_fepastartc
, ch
->ch_fepastopc
, 0);
5641 * dgap_parity_scan()
5643 * Convert the FEP5 way of reporting parity errors and breaks into
5644 * the Linux line discipline way.
5646 static void dgap_parity_scan(struct channel_t
*ch
, unsigned char *cbuf
,
5647 unsigned char *fbuf
, int *len
)
5651 unsigned char *in
, *cout
, *fout
;
5658 if (!ch
|| ch
->magic
!= DGAP_CHANNEL_MAGIC
)
5663 switch (ch
->pscan_state
) {
5665 /* reset to sanity and fall through */
5666 ch
->pscan_state
= 0;
5669 /* No FF seen yet */
5670 if (c
== (unsigned char) '\377')
5671 /* delete this character from stream */
5672 ch
->pscan_state
= 1;
5675 *fout
++ = TTY_NORMAL
;
5682 if (c
== (unsigned char) '\377') {
5683 /* doubled ff, transform to single ff */
5685 *fout
++ = TTY_NORMAL
;
5687 ch
->pscan_state
= 0;
5689 /* save value examination in next state */
5690 ch
->pscan_savechar
= c
;
5691 ch
->pscan_state
= 2;
5696 /* third character of ff sequence */
5700 if (ch
->pscan_savechar
== 0x0) {
5704 *fout
++ = TTY_BREAK
;
5706 ch
->ch_err_parity
++;
5707 *fout
++ = TTY_PARITY
;
5712 ch
->pscan_state
= 0;
5718 /*=======================================================================
5720 * dgap_event - FEP to host event processing routine.
5722 * bd - Board of current event.
5724 *=======================================================================*/
5725 static int dgap_event(struct board_t
*bd
)
5727 struct channel_t
*ch
;
5732 uchar
*vaddr
= NULL
;
5733 struct ev_t
*eaddr
= NULL
;
5741 if (!bd
|| bd
->magic
!= DGAP_BOARD_MAGIC
)
5744 DGAP_LOCK(bd
->bd_lock
, lock_flags
);
5746 vaddr
= bd
->re_map_membase
;
5749 DGAP_UNLOCK(bd
->bd_lock
, lock_flags
);
5753 eaddr
= (struct ev_t
*) (vaddr
+ EVBUF
);
5755 /* Get our head and tail */
5756 head
= readw(&(eaddr
->ev_head
));
5757 tail
= readw(&(eaddr
->ev_tail
));
5760 * Forget it if pointers out of range.
5763 if (head
>= EVMAX
- EVSTART
|| tail
>= EVMAX
- EVSTART
||
5764 (head
| tail
) & 03) {
5765 /* Let go of board lock */
5766 DGAP_UNLOCK(bd
->bd_lock
, lock_flags
);
5771 * Loop to process all the events in the buffer.
5773 while (tail
!= head
) {
5776 * Get interrupt information.
5779 event
= bd
->re_map_membase
+ tail
+ EVSTART
;
5787 * Make sure the interrupt is valid.
5789 if (port
>= bd
->nasync
)
5792 if (!(reason
& (IFMODEM
| IFBREAK
| IFTLW
| IFTEM
| IFDATA
)))
5795 ch
= bd
->channels
[port
];
5797 if (!ch
|| ch
->magic
!= DGAP_CHANNEL_MAGIC
)
5801 * If we have made it here, the event was valid.
5802 * Lock down the channel.
5804 DGAP_LOCK(ch
->ch_lock
, lock_flags2
);
5809 DGAP_UNLOCK(ch
->ch_lock
, lock_flags2
);
5814 * Process received data.
5816 if (reason
& IFDATA
) {
5819 * ALL LOCKS *MUST* BE DROPPED BEFORE CALLING INPUT!
5820 * input could send some data to ld, which in turn
5821 * could do a callback to one of our other functions.
5823 DGAP_UNLOCK(ch
->ch_lock
, lock_flags2
);
5824 DGAP_UNLOCK(bd
->bd_lock
, lock_flags
);
5828 DGAP_LOCK(bd
->bd_lock
, lock_flags
);
5829 DGAP_LOCK(ch
->ch_lock
, lock_flags2
);
5831 if (ch
->ch_flags
& CH_RACTIVE
)
5832 ch
->ch_flags
|= CH_RENABLE
;
5834 writeb(1, &(bs
->idata
));
5836 if (ch
->ch_flags
& CH_RWAIT
) {
5837 ch
->ch_flags
&= ~CH_RWAIT
;
5839 wake_up_interruptible(&ch
->ch_tun
.un_flags_wait
);
5844 * Process Modem change signals.
5846 if (reason
& IFMODEM
) {
5847 ch
->ch_mistat
= modem
;
5854 if (reason
& IFBREAK
) {
5856 if (ch
->ch_tun
.un_tty
) {
5857 /* A break has been indicated */
5859 tty_buffer_request_room(ch
->ch_tun
.un_tty
->port
, 1);
5860 tty_insert_flip_char(ch
->ch_tun
.un_tty
->port
, 0, TTY_BREAK
);
5861 tty_flip_buffer_push(ch
->ch_tun
.un_tty
->port
);
5866 * Process Transmit low.
5868 if (reason
& IFTLW
) {
5870 if (ch
->ch_tun
.un_flags
& UN_LOW
) {
5871 ch
->ch_tun
.un_flags
&= ~UN_LOW
;
5873 if (ch
->ch_tun
.un_flags
& UN_ISOPEN
) {
5874 if ((ch
->ch_tun
.un_tty
->flags
&
5875 (1 << TTY_DO_WRITE_WAKEUP
)) &&
5876 ch
->ch_tun
.un_tty
->ldisc
->ops
->write_wakeup
) {
5877 DGAP_UNLOCK(ch
->ch_lock
, lock_flags2
);
5878 DGAP_UNLOCK(bd
->bd_lock
, lock_flags
);
5879 (ch
->ch_tun
.un_tty
->ldisc
->ops
->write_wakeup
)(ch
->ch_tun
.un_tty
);
5880 DGAP_LOCK(bd
->bd_lock
, lock_flags
);
5881 DGAP_LOCK(ch
->ch_lock
, lock_flags2
);
5883 wake_up_interruptible(&ch
->ch_tun
.un_tty
->write_wait
);
5884 wake_up_interruptible(&ch
->ch_tun
.un_flags_wait
);
5888 if (ch
->ch_pun
.un_flags
& UN_LOW
) {
5889 ch
->ch_pun
.un_flags
&= ~UN_LOW
;
5890 if (ch
->ch_pun
.un_flags
& UN_ISOPEN
) {
5891 if ((ch
->ch_pun
.un_tty
->flags
&
5892 (1 << TTY_DO_WRITE_WAKEUP
)) &&
5893 ch
->ch_pun
.un_tty
->ldisc
->ops
->write_wakeup
) {
5894 DGAP_UNLOCK(ch
->ch_lock
, lock_flags2
);
5895 DGAP_UNLOCK(bd
->bd_lock
, lock_flags
);
5896 (ch
->ch_pun
.un_tty
->ldisc
->ops
->write_wakeup
)(ch
->ch_pun
.un_tty
);
5897 DGAP_LOCK(bd
->bd_lock
, lock_flags
);
5898 DGAP_LOCK(ch
->ch_lock
, lock_flags2
);
5900 wake_up_interruptible(&ch
->ch_pun
.un_tty
->write_wait
);
5901 wake_up_interruptible(&ch
->ch_pun
.un_flags_wait
);
5905 if (ch
->ch_flags
& CH_WLOW
) {
5906 ch
->ch_flags
&= ~CH_WLOW
;
5907 wake_up_interruptible(&ch
->ch_flags_wait
);
5912 * Process Transmit empty.
5914 if (reason
& IFTEM
) {
5915 if (ch
->ch_tun
.un_flags
& UN_EMPTY
) {
5916 ch
->ch_tun
.un_flags
&= ~UN_EMPTY
;
5917 if (ch
->ch_tun
.un_flags
& UN_ISOPEN
) {
5918 if ((ch
->ch_tun
.un_tty
->flags
&
5919 (1 << TTY_DO_WRITE_WAKEUP
)) &&
5920 ch
->ch_tun
.un_tty
->ldisc
->ops
->write_wakeup
) {
5921 DGAP_UNLOCK(ch
->ch_lock
, lock_flags2
);
5922 DGAP_UNLOCK(bd
->bd_lock
, lock_flags
);
5924 (ch
->ch_tun
.un_tty
->ldisc
->ops
->write_wakeup
)(ch
->ch_tun
.un_tty
);
5925 DGAP_LOCK(bd
->bd_lock
, lock_flags
);
5926 DGAP_LOCK(ch
->ch_lock
, lock_flags2
);
5928 wake_up_interruptible(&ch
->ch_tun
.un_tty
->write_wait
);
5929 wake_up_interruptible(&ch
->ch_tun
.un_flags_wait
);
5933 if (ch
->ch_pun
.un_flags
& UN_EMPTY
) {
5934 ch
->ch_pun
.un_flags
&= ~UN_EMPTY
;
5935 if (ch
->ch_pun
.un_flags
& UN_ISOPEN
) {
5936 if ((ch
->ch_pun
.un_tty
->flags
&
5937 (1 << TTY_DO_WRITE_WAKEUP
)) &&
5938 ch
->ch_pun
.un_tty
->ldisc
->ops
->write_wakeup
) {
5939 DGAP_UNLOCK(ch
->ch_lock
, lock_flags2
);
5940 DGAP_UNLOCK(bd
->bd_lock
, lock_flags
);
5941 (ch
->ch_pun
.un_tty
->ldisc
->ops
->write_wakeup
)(ch
->ch_pun
.un_tty
);
5942 DGAP_LOCK(bd
->bd_lock
, lock_flags
);
5943 DGAP_LOCK(ch
->ch_lock
, lock_flags2
);
5945 wake_up_interruptible(&ch
->ch_pun
.un_tty
->write_wait
);
5946 wake_up_interruptible(&ch
->ch_pun
.un_flags_wait
);
5951 if (ch
->ch_flags
& CH_WEMPTY
) {
5952 ch
->ch_flags
&= ~CH_WEMPTY
;
5953 wake_up_interruptible(&ch
->ch_flags_wait
);
5957 DGAP_UNLOCK(ch
->ch_lock
, lock_flags2
);
5960 tail
= (tail
+ 4) & (EVMAX
- EVSTART
- 4);
5963 writew(tail
, &(eaddr
->ev_tail
));
5964 DGAP_UNLOCK(bd
->bd_lock
, lock_flags
);
5969 static ssize_t
dgap_driver_version_show(struct device_driver
*ddp
, char *buf
)
5971 return snprintf(buf
, PAGE_SIZE
, "%s\n", DG_PART
);
5973 static DRIVER_ATTR(version
, S_IRUSR
, dgap_driver_version_show
, NULL
);
5976 static ssize_t
dgap_driver_boards_show(struct device_driver
*ddp
, char *buf
)
5978 return snprintf(buf
, PAGE_SIZE
, "%d\n", dgap_NumBoards
);
5980 static DRIVER_ATTR(boards
, S_IRUSR
, dgap_driver_boards_show
, NULL
);
5983 static ssize_t
dgap_driver_maxboards_show(struct device_driver
*ddp
, char *buf
)
5985 return snprintf(buf
, PAGE_SIZE
, "%d\n", MAXBOARDS
);
5987 static DRIVER_ATTR(maxboards
, S_IRUSR
, dgap_driver_maxboards_show
, NULL
);
5990 static ssize_t
dgap_driver_pollcounter_show(struct device_driver
*ddp
, char *buf
)
5992 return snprintf(buf
, PAGE_SIZE
, "%ld\n", dgap_poll_counter
);
5994 static DRIVER_ATTR(pollcounter
, S_IRUSR
, dgap_driver_pollcounter_show
, NULL
);
5997 static ssize_t
dgap_driver_state_show(struct device_driver
*ddp
, char *buf
)
5999 return snprintf(buf
, PAGE_SIZE
, "%s\n", dgap_driver_state_text
[dgap_driver_state
]);
6001 static DRIVER_ATTR(state
, S_IRUSR
, dgap_driver_state_show
, NULL
);
6003 static ssize_t
dgap_driver_pollrate_show(struct device_driver
*ddp
, char *buf
)
6005 return snprintf(buf
, PAGE_SIZE
, "%dms\n", dgap_poll_tick
);
6008 static ssize_t
dgap_driver_pollrate_store(struct device_driver
*ddp
, const char *buf
, size_t count
)
6010 if (sscanf(buf
, "%d\n", &dgap_poll_tick
) != 1)
6014 static DRIVER_ATTR(pollrate
, (S_IRUSR
| S_IWUSR
), dgap_driver_pollrate_show
, dgap_driver_pollrate_store
);
6016 static int dgap_create_driver_sysfiles(struct pci_driver
*dgap_driver
)
6019 struct device_driver
*driverfs
= &dgap_driver
->driver
;
6021 rc
|= driver_create_file(driverfs
, &driver_attr_version
);
6022 rc
|= driver_create_file(driverfs
, &driver_attr_boards
);
6023 rc
|= driver_create_file(driverfs
, &driver_attr_maxboards
);
6024 rc
|= driver_create_file(driverfs
, &driver_attr_pollrate
);
6025 rc
|= driver_create_file(driverfs
, &driver_attr_pollcounter
);
6026 rc
|= driver_create_file(driverfs
, &driver_attr_state
);
6031 static void dgap_remove_driver_sysfiles(struct pci_driver
*dgap_driver
)
6033 struct device_driver
*driverfs
= &dgap_driver
->driver
;
6034 driver_remove_file(driverfs
, &driver_attr_version
);
6035 driver_remove_file(driverfs
, &driver_attr_boards
);
6036 driver_remove_file(driverfs
, &driver_attr_maxboards
);
6037 driver_remove_file(driverfs
, &driver_attr_pollrate
);
6038 driver_remove_file(driverfs
, &driver_attr_pollcounter
);
6039 driver_remove_file(driverfs
, &driver_attr_state
);
6042 static struct board_t
*dgap_verify_board(struct device
*p
)
6049 bd
= dev_get_drvdata(p
);
6050 if (!bd
|| bd
->magic
!= DGAP_BOARD_MAGIC
|| bd
->state
!= BOARD_READY
)
6056 static ssize_t
dgap_ports_state_show(struct device
*p
, struct device_attribute
*attr
, char *buf
)
6062 bd
= dgap_verify_board(p
);
6066 for (i
= 0; i
< bd
->nasync
; i
++) {
6067 count
+= snprintf(buf
+ count
, PAGE_SIZE
- count
,
6068 "%d %s\n", bd
->channels
[i
]->ch_portnum
,
6069 bd
->channels
[i
]->ch_open_count
? "Open" : "Closed");
6073 static DEVICE_ATTR(ports_state
, S_IRUSR
, dgap_ports_state_show
, NULL
);
6075 static ssize_t
dgap_ports_baud_show(struct device
*p
, struct device_attribute
*attr
, char *buf
)
6081 bd
= dgap_verify_board(p
);
6085 for (i
= 0; i
< bd
->nasync
; i
++) {
6086 count
+= snprintf(buf
+ count
, PAGE_SIZE
- count
,
6087 "%d %d\n", bd
->channels
[i
]->ch_portnum
, bd
->channels
[i
]->ch_baud_info
);
6091 static DEVICE_ATTR(ports_baud
, S_IRUSR
, dgap_ports_baud_show
, NULL
);
6093 static ssize_t
dgap_ports_msignals_show(struct device
*p
, struct device_attribute
*attr
, char *buf
)
6099 bd
= dgap_verify_board(p
);
6103 for (i
= 0; i
< bd
->nasync
; i
++) {
6104 if (bd
->channels
[i
]->ch_open_count
)
6105 count
+= snprintf(buf
+ count
, PAGE_SIZE
- count
,
6106 "%d %s %s %s %s %s %s\n", bd
->channels
[i
]->ch_portnum
,
6107 (bd
->channels
[i
]->ch_mostat
& UART_MCR_RTS
) ? "RTS" : "",
6108 (bd
->channels
[i
]->ch_mistat
& UART_MSR_CTS
) ? "CTS" : "",
6109 (bd
->channels
[i
]->ch_mostat
& UART_MCR_DTR
) ? "DTR" : "",
6110 (bd
->channels
[i
]->ch_mistat
& UART_MSR_DSR
) ? "DSR" : "",
6111 (bd
->channels
[i
]->ch_mistat
& UART_MSR_DCD
) ? "DCD" : "",
6112 (bd
->channels
[i
]->ch_mistat
& UART_MSR_RI
) ? "RI" : "");
6114 count
+= snprintf(buf
+ count
, PAGE_SIZE
- count
,
6115 "%d\n", bd
->channels
[i
]->ch_portnum
);
6119 static DEVICE_ATTR(ports_msignals
, S_IRUSR
, dgap_ports_msignals_show
, NULL
);
6121 static ssize_t
dgap_ports_iflag_show(struct device
*p
, struct device_attribute
*attr
, char *buf
)
6127 bd
= dgap_verify_board(p
);
6131 for (i
= 0; i
< bd
->nasync
; i
++)
6132 count
+= snprintf(buf
+ count
, PAGE_SIZE
- count
, "%d %x\n",
6133 bd
->channels
[i
]->ch_portnum
, bd
->channels
[i
]->ch_c_iflag
);
6136 static DEVICE_ATTR(ports_iflag
, S_IRUSR
, dgap_ports_iflag_show
, NULL
);
6138 static ssize_t
dgap_ports_cflag_show(struct device
*p
, struct device_attribute
*attr
, char *buf
)
6144 bd
= dgap_verify_board(p
);
6148 for (i
= 0; i
< bd
->nasync
; i
++)
6149 count
+= snprintf(buf
+ count
, PAGE_SIZE
- count
, "%d %x\n",
6150 bd
->channels
[i
]->ch_portnum
, bd
->channels
[i
]->ch_c_cflag
);
6153 static DEVICE_ATTR(ports_cflag
, S_IRUSR
, dgap_ports_cflag_show
, NULL
);
6155 static ssize_t
dgap_ports_oflag_show(struct device
*p
, struct device_attribute
*attr
, char *buf
)
6161 bd
= dgap_verify_board(p
);
6165 for (i
= 0; i
< bd
->nasync
; i
++)
6166 count
+= snprintf(buf
+ count
, PAGE_SIZE
- count
, "%d %x\n",
6167 bd
->channels
[i
]->ch_portnum
, bd
->channels
[i
]->ch_c_oflag
);
6170 static DEVICE_ATTR(ports_oflag
, S_IRUSR
, dgap_ports_oflag_show
, NULL
);
6172 static ssize_t
dgap_ports_lflag_show(struct device
*p
, struct device_attribute
*attr
, char *buf
)
6178 bd
= dgap_verify_board(p
);
6182 for (i
= 0; i
< bd
->nasync
; i
++)
6183 count
+= snprintf(buf
+ count
, PAGE_SIZE
- count
, "%d %x\n",
6184 bd
->channels
[i
]->ch_portnum
, bd
->channels
[i
]->ch_c_lflag
);
6187 static DEVICE_ATTR(ports_lflag
, S_IRUSR
, dgap_ports_lflag_show
, NULL
);
6189 static ssize_t
dgap_ports_digi_flag_show(struct device
*p
, struct device_attribute
*attr
, char *buf
)
6195 bd
= dgap_verify_board(p
);
6199 for (i
= 0; i
< bd
->nasync
; i
++)
6200 count
+= snprintf(buf
+ count
, PAGE_SIZE
- count
, "%d %x\n",
6201 bd
->channels
[i
]->ch_portnum
, bd
->channels
[i
]->ch_digi
.digi_flags
);
6204 static DEVICE_ATTR(ports_digi_flag
, S_IRUSR
, dgap_ports_digi_flag_show
, NULL
);
6206 static ssize_t
dgap_ports_rxcount_show(struct device
*p
, struct device_attribute
*attr
, char *buf
)
6212 bd
= dgap_verify_board(p
);
6216 for (i
= 0; i
< bd
->nasync
; i
++)
6217 count
+= snprintf(buf
+ count
, PAGE_SIZE
- count
, "%d %ld\n",
6218 bd
->channels
[i
]->ch_portnum
, bd
->channels
[i
]->ch_rxcount
);
6221 static DEVICE_ATTR(ports_rxcount
, S_IRUSR
, dgap_ports_rxcount_show
, NULL
);
6223 static ssize_t
dgap_ports_txcount_show(struct device
*p
, struct device_attribute
*attr
, char *buf
)
6229 bd
= dgap_verify_board(p
);
6233 for (i
= 0; i
< bd
->nasync
; i
++)
6234 count
+= snprintf(buf
+ count
, PAGE_SIZE
- count
, "%d %ld\n",
6235 bd
->channels
[i
]->ch_portnum
, bd
->channels
[i
]->ch_txcount
);
6238 static DEVICE_ATTR(ports_txcount
, S_IRUSR
, dgap_ports_txcount_show
, NULL
);
6240 /* this function creates the sys files that will export each signal status
6241 * to sysfs each value will be put in a separate filename
6243 static void dgap_create_ports_sysfiles(struct board_t
*bd
)
6245 dev_set_drvdata(&bd
->pdev
->dev
, bd
);
6246 device_create_file(&(bd
->pdev
->dev
), &dev_attr_ports_state
);
6247 device_create_file(&(bd
->pdev
->dev
), &dev_attr_ports_baud
);
6248 device_create_file(&(bd
->pdev
->dev
), &dev_attr_ports_msignals
);
6249 device_create_file(&(bd
->pdev
->dev
), &dev_attr_ports_iflag
);
6250 device_create_file(&(bd
->pdev
->dev
), &dev_attr_ports_cflag
);
6251 device_create_file(&(bd
->pdev
->dev
), &dev_attr_ports_oflag
);
6252 device_create_file(&(bd
->pdev
->dev
), &dev_attr_ports_lflag
);
6253 device_create_file(&(bd
->pdev
->dev
), &dev_attr_ports_digi_flag
);
6254 device_create_file(&(bd
->pdev
->dev
), &dev_attr_ports_rxcount
);
6255 device_create_file(&(bd
->pdev
->dev
), &dev_attr_ports_txcount
);
6258 /* removes all the sys files created for that port */
6259 static void dgap_remove_ports_sysfiles(struct board_t
*bd
)
6261 device_remove_file(&(bd
->pdev
->dev
), &dev_attr_ports_state
);
6262 device_remove_file(&(bd
->pdev
->dev
), &dev_attr_ports_baud
);
6263 device_remove_file(&(bd
->pdev
->dev
), &dev_attr_ports_msignals
);
6264 device_remove_file(&(bd
->pdev
->dev
), &dev_attr_ports_iflag
);
6265 device_remove_file(&(bd
->pdev
->dev
), &dev_attr_ports_cflag
);
6266 device_remove_file(&(bd
->pdev
->dev
), &dev_attr_ports_oflag
);
6267 device_remove_file(&(bd
->pdev
->dev
), &dev_attr_ports_lflag
);
6268 device_remove_file(&(bd
->pdev
->dev
), &dev_attr_ports_digi_flag
);
6269 device_remove_file(&(bd
->pdev
->dev
), &dev_attr_ports_rxcount
);
6270 device_remove_file(&(bd
->pdev
->dev
), &dev_attr_ports_txcount
);
6273 static ssize_t
dgap_tty_state_show(struct device
*d
, struct device_attribute
*attr
, char *buf
)
6276 struct channel_t
*ch
;
6281 un
= dev_get_drvdata(d
);
6282 if (!un
|| un
->magic
!= DGAP_UNIT_MAGIC
)
6285 if (!ch
|| ch
->magic
!= DGAP_CHANNEL_MAGIC
)
6288 if (!bd
|| bd
->magic
!= DGAP_BOARD_MAGIC
)
6290 if (bd
->state
!= BOARD_READY
)
6293 return snprintf(buf
, PAGE_SIZE
, "%s", un
->un_open_count
? "Open" : "Closed");
6295 static DEVICE_ATTR(state
, S_IRUSR
, dgap_tty_state_show
, NULL
);
6297 static ssize_t
dgap_tty_baud_show(struct device
*d
, struct device_attribute
*attr
, char *buf
)
6300 struct channel_t
*ch
;
6305 un
= dev_get_drvdata(d
);
6306 if (!un
|| un
->magic
!= DGAP_UNIT_MAGIC
)
6309 if (!ch
|| ch
->magic
!= DGAP_CHANNEL_MAGIC
)
6312 if (!bd
|| bd
->magic
!= DGAP_BOARD_MAGIC
)
6314 if (bd
->state
!= BOARD_READY
)
6317 return snprintf(buf
, PAGE_SIZE
, "%d\n", ch
->ch_baud_info
);
6319 static DEVICE_ATTR(baud
, S_IRUSR
, dgap_tty_baud_show
, NULL
);
6321 static ssize_t
dgap_tty_msignals_show(struct device
*d
, struct device_attribute
*attr
, char *buf
)
6324 struct channel_t
*ch
;
6329 un
= dev_get_drvdata(d
);
6330 if (!un
|| un
->magic
!= DGAP_UNIT_MAGIC
)
6333 if (!ch
|| ch
->magic
!= DGAP_CHANNEL_MAGIC
)
6336 if (!bd
|| bd
->magic
!= DGAP_BOARD_MAGIC
)
6338 if (bd
->state
!= BOARD_READY
)
6341 if (ch
->ch_open_count
) {
6342 return snprintf(buf
, PAGE_SIZE
, "%s %s %s %s %s %s\n",
6343 (ch
->ch_mostat
& UART_MCR_RTS
) ? "RTS" : "",
6344 (ch
->ch_mistat
& UART_MSR_CTS
) ? "CTS" : "",
6345 (ch
->ch_mostat
& UART_MCR_DTR
) ? "DTR" : "",
6346 (ch
->ch_mistat
& UART_MSR_DSR
) ? "DSR" : "",
6347 (ch
->ch_mistat
& UART_MSR_DCD
) ? "DCD" : "",
6348 (ch
->ch_mistat
& UART_MSR_RI
) ? "RI" : "");
6352 static DEVICE_ATTR(msignals
, S_IRUSR
, dgap_tty_msignals_show
, NULL
);
6354 static ssize_t
dgap_tty_iflag_show(struct device
*d
, struct device_attribute
*attr
, char *buf
)
6357 struct channel_t
*ch
;
6362 un
= dev_get_drvdata(d
);
6363 if (!un
|| un
->magic
!= DGAP_UNIT_MAGIC
)
6366 if (!ch
|| ch
->magic
!= DGAP_CHANNEL_MAGIC
)
6369 if (!bd
|| bd
->magic
!= DGAP_BOARD_MAGIC
)
6371 if (bd
->state
!= BOARD_READY
)
6374 return snprintf(buf
, PAGE_SIZE
, "%x\n", ch
->ch_c_iflag
);
6376 static DEVICE_ATTR(iflag
, S_IRUSR
, dgap_tty_iflag_show
, NULL
);
6378 static ssize_t
dgap_tty_cflag_show(struct device
*d
, struct device_attribute
*attr
, char *buf
)
6381 struct channel_t
*ch
;
6386 un
= dev_get_drvdata(d
);
6387 if (!un
|| un
->magic
!= DGAP_UNIT_MAGIC
)
6390 if (!ch
|| ch
->magic
!= DGAP_CHANNEL_MAGIC
)
6393 if (!bd
|| bd
->magic
!= DGAP_BOARD_MAGIC
)
6395 if (bd
->state
!= BOARD_READY
)
6398 return snprintf(buf
, PAGE_SIZE
, "%x\n", ch
->ch_c_cflag
);
6400 static DEVICE_ATTR(cflag
, S_IRUSR
, dgap_tty_cflag_show
, NULL
);
6402 static ssize_t
dgap_tty_oflag_show(struct device
*d
, struct device_attribute
*attr
, char *buf
)
6405 struct channel_t
*ch
;
6410 un
= dev_get_drvdata(d
);
6411 if (!un
|| un
->magic
!= DGAP_UNIT_MAGIC
)
6414 if (!ch
|| ch
->magic
!= DGAP_CHANNEL_MAGIC
)
6417 if (!bd
|| bd
->magic
!= DGAP_BOARD_MAGIC
)
6419 if (bd
->state
!= BOARD_READY
)
6422 return snprintf(buf
, PAGE_SIZE
, "%x\n", ch
->ch_c_oflag
);
6424 static DEVICE_ATTR(oflag
, S_IRUSR
, dgap_tty_oflag_show
, NULL
);
6426 static ssize_t
dgap_tty_lflag_show(struct device
*d
, struct device_attribute
*attr
, char *buf
)
6429 struct channel_t
*ch
;
6434 un
= dev_get_drvdata(d
);
6435 if (!un
|| un
->magic
!= DGAP_UNIT_MAGIC
)
6438 if (!ch
|| ch
->magic
!= DGAP_CHANNEL_MAGIC
)
6441 if (!bd
|| bd
->magic
!= DGAP_BOARD_MAGIC
)
6443 if (bd
->state
!= BOARD_READY
)
6446 return snprintf(buf
, PAGE_SIZE
, "%x\n", ch
->ch_c_lflag
);
6448 static DEVICE_ATTR(lflag
, S_IRUSR
, dgap_tty_lflag_show
, NULL
);
6450 static ssize_t
dgap_tty_digi_flag_show(struct device
*d
, struct device_attribute
*attr
, char *buf
)
6453 struct channel_t
*ch
;
6458 un
= dev_get_drvdata(d
);
6459 if (!un
|| un
->magic
!= DGAP_UNIT_MAGIC
)
6462 if (!ch
|| ch
->magic
!= DGAP_CHANNEL_MAGIC
)
6465 if (!bd
|| bd
->magic
!= DGAP_BOARD_MAGIC
)
6467 if (bd
->state
!= BOARD_READY
)
6470 return snprintf(buf
, PAGE_SIZE
, "%x\n", ch
->ch_digi
.digi_flags
);
6472 static DEVICE_ATTR(digi_flag
, S_IRUSR
, dgap_tty_digi_flag_show
, NULL
);
6474 static ssize_t
dgap_tty_rxcount_show(struct device
*d
, struct device_attribute
*attr
, char *buf
)
6477 struct channel_t
*ch
;
6482 un
= dev_get_drvdata(d
);
6483 if (!un
|| un
->magic
!= DGAP_UNIT_MAGIC
)
6486 if (!ch
|| ch
->magic
!= DGAP_CHANNEL_MAGIC
)
6489 if (!bd
|| bd
->magic
!= DGAP_BOARD_MAGIC
)
6491 if (bd
->state
!= BOARD_READY
)
6494 return snprintf(buf
, PAGE_SIZE
, "%ld\n", ch
->ch_rxcount
);
6496 static DEVICE_ATTR(rxcount
, S_IRUSR
, dgap_tty_rxcount_show
, NULL
);
6498 static ssize_t
dgap_tty_txcount_show(struct device
*d
, struct device_attribute
*attr
, char *buf
)
6501 struct channel_t
*ch
;
6506 un
= dev_get_drvdata(d
);
6507 if (!un
|| un
->magic
!= DGAP_UNIT_MAGIC
)
6510 if (!ch
|| ch
->magic
!= DGAP_CHANNEL_MAGIC
)
6513 if (!bd
|| bd
->magic
!= DGAP_BOARD_MAGIC
)
6515 if (bd
->state
!= BOARD_READY
)
6518 return snprintf(buf
, PAGE_SIZE
, "%ld\n", ch
->ch_txcount
);
6520 static DEVICE_ATTR(txcount
, S_IRUSR
, dgap_tty_txcount_show
, NULL
);
6522 static ssize_t
dgap_tty_name_show(struct device
*d
, struct device_attribute
*attr
, char *buf
)
6525 struct channel_t
*ch
;
6529 struct cnode
*cptr
= NULL
;
6537 un
= dev_get_drvdata(d
);
6538 if (!un
|| un
->magic
!= DGAP_UNIT_MAGIC
)
6541 if (!ch
|| ch
->magic
!= DGAP_CHANNEL_MAGIC
)
6544 if (!bd
|| bd
->magic
!= DGAP_BOARD_MAGIC
)
6546 if (bd
->state
!= BOARD_READY
)
6550 cn
= ch
->ch_portnum
;
6552 for (cptr
= bd
->bd_config
; cptr
; cptr
= cptr
->next
) {
6554 if ((cptr
->type
== BNODE
) &&
6555 ((cptr
->u
.board
.type
== APORT2_920P
) || (cptr
->u
.board
.type
== APORT4_920P
) ||
6556 (cptr
->u
.board
.type
== APORT8_920P
) || (cptr
->u
.board
.type
== PAPORT4
) ||
6557 (cptr
->u
.board
.type
== PAPORT8
))) {
6560 if (cptr
->u
.board
.v_start
)
6561 starto
= cptr
->u
.board
.start
;
6566 if (cptr
->type
== TNODE
&& found
== TRUE
) {
6568 if (strstr(cptr
->u
.ttyname
, "tty")) {
6569 ptr1
= cptr
->u
.ttyname
;
6572 ptr1
= cptr
->u
.ttyname
;
6574 for (i
= 0; i
< dgap_config_get_number_of_ports(bd
); i
++) {
6576 return snprintf(buf
, PAGE_SIZE
, "%s%s%02d\n",
6577 (un
->un_type
== DGAP_PRINT
) ? "pr" : "tty",
6582 if (cptr
->type
== CNODE
) {
6584 for (i
= 0; i
< cptr
->u
.conc
.nport
; i
++) {
6585 if (cn
== (i
+ ncount
))
6587 return snprintf(buf
, PAGE_SIZE
, "%s%s%02d\n",
6588 (un
->un_type
== DGAP_PRINT
) ? "pr" : "tty",
6590 i
+ (cptr
->u
.conc
.v_start
? cptr
->u
.conc
.start
: 1));
6593 ncount
+= cptr
->u
.conc
.nport
;
6596 if (cptr
->type
== MNODE
) {
6598 for (i
= 0; i
< cptr
->u
.module
.nport
; i
++) {
6599 if (cn
== (i
+ ncount
))
6600 return snprintf(buf
, PAGE_SIZE
, "%s%s%02d\n",
6601 (un
->un_type
== DGAP_PRINT
) ? "pr" : "tty",
6603 i
+ (cptr
->u
.module
.v_start
? cptr
->u
.module
.start
: 1));
6606 ncount
+= cptr
->u
.module
.nport
;
6611 return snprintf(buf
, PAGE_SIZE
, "%s_dgap_%d_%d\n",
6612 (un
->un_type
== DGAP_PRINT
) ? "pr" : "tty", bn
, cn
);
6615 static DEVICE_ATTR(custom_name
, S_IRUSR
, dgap_tty_name_show
, NULL
);
6617 static struct attribute
*dgap_sysfs_tty_entries
[] = {
6618 &dev_attr_state
.attr
,
6619 &dev_attr_baud
.attr
,
6620 &dev_attr_msignals
.attr
,
6621 &dev_attr_iflag
.attr
,
6622 &dev_attr_cflag
.attr
,
6623 &dev_attr_oflag
.attr
,
6624 &dev_attr_lflag
.attr
,
6625 &dev_attr_digi_flag
.attr
,
6626 &dev_attr_rxcount
.attr
,
6627 &dev_attr_txcount
.attr
,
6628 &dev_attr_custom_name
.attr
,
6632 static struct attribute_group dgap_tty_attribute_group
= {
6634 .attrs
= dgap_sysfs_tty_entries
,
6637 static void dgap_create_tty_sysfs(struct un_t
*un
, struct device
*c
)
6641 ret
= sysfs_create_group(&c
->kobj
, &dgap_tty_attribute_group
);
6645 dev_set_drvdata(c
, un
);
6649 static void dgap_remove_tty_sysfs(struct device
*c
)
6651 sysfs_remove_group(&c
->kobj
, &dgap_tty_attribute_group
);
6655 * Parse a configuration file read into memory as a string.
6657 static int dgap_parsefile(char **in
, int Remove
)
6659 struct cnode
*p
, *brd
, *line
, *conc
;
6661 char *s
= NULL
, *s2
= NULL
;
6665 brd
= line
= conc
= NULL
;
6667 /* perhaps we are adding to an existing list? */
6668 while (p
->next
!= NULL
)
6671 /* file must start with a BEGIN */
6672 while ((rc
= dgap_gettok(in
, p
)) != BEGIN
) {
6674 dgap_err("unexpected EOF");
6680 rc
= dgap_gettok(in
, p
);
6682 dgap_err("unexpected EOF");
6688 dgap_err("unexpected end of file");
6691 case BEGIN
: /* should only be 1 begin */
6692 dgap_err("unexpected config_begin\n");
6698 case BOARD
: /* board info */
6699 if (dgap_checknode(p
))
6701 p
->next
= dgap_newnode(BNODE
);
6703 dgap_err("out of memory");
6708 p
->u
.board
.status
= dgap_savestring("No");
6714 case APORT2_920P
: /* AccelePort_4 */
6715 if (p
->type
!= BNODE
) {
6716 dgap_err("unexpected Digi_2r_920 string");
6719 p
->u
.board
.type
= APORT2_920P
;
6720 p
->u
.board
.v_type
= 1;
6723 case APORT4_920P
: /* AccelePort_4 */
6724 if (p
->type
!= BNODE
) {
6725 dgap_err("unexpected Digi_4r_920 string");
6728 p
->u
.board
.type
= APORT4_920P
;
6729 p
->u
.board
.v_type
= 1;
6732 case APORT8_920P
: /* AccelePort_8 */
6733 if (p
->type
!= BNODE
) {
6734 dgap_err("unexpected Digi_8r_920 string");
6737 p
->u
.board
.type
= APORT8_920P
;
6738 p
->u
.board
.v_type
= 1;
6741 case PAPORT4
: /* AccelePort_4 PCI */
6742 if (p
->type
!= BNODE
) {
6743 dgap_err("unexpected Digi_4r(PCI) string");
6746 p
->u
.board
.type
= PAPORT4
;
6747 p
->u
.board
.v_type
= 1;
6750 case PAPORT8
: /* AccelePort_8 PCI */
6751 if (p
->type
!= BNODE
) {
6752 dgap_err("unexpected Digi_8r string");
6755 p
->u
.board
.type
= PAPORT8
;
6756 p
->u
.board
.v_type
= 1;
6759 case PCX
: /* PCI C/X */
6760 if (p
->type
!= BNODE
) {
6761 dgap_err("unexpected Digi_C/X_(PCI) string");
6764 p
->u
.board
.type
= PCX
;
6765 p
->u
.board
.v_type
= 1;
6766 p
->u
.board
.conc1
= 0;
6767 p
->u
.board
.conc2
= 0;
6768 p
->u
.board
.module1
= 0;
6769 p
->u
.board
.module2
= 0;
6772 case PEPC
: /* PCI EPC/X */
6773 if (p
->type
!= BNODE
) {
6774 dgap_err("unexpected \"Digi_EPC/X_(PCI)\" string");
6777 p
->u
.board
.type
= PEPC
;
6778 p
->u
.board
.v_type
= 1;
6779 p
->u
.board
.conc1
= 0;
6780 p
->u
.board
.conc2
= 0;
6781 p
->u
.board
.module1
= 0;
6782 p
->u
.board
.module2
= 0;
6785 case PPCM
: /* PCI/Xem */
6786 if (p
->type
!= BNODE
) {
6787 dgap_err("unexpected PCI/Xem string");
6790 p
->u
.board
.type
= PPCM
;
6791 p
->u
.board
.v_type
= 1;
6792 p
->u
.board
.conc1
= 0;
6793 p
->u
.board
.conc2
= 0;
6796 case IO
: /* i/o port */
6797 if (p
->type
!= BNODE
) {
6798 dgap_err("IO port only vaild for boards");
6801 s
= dgap_getword(in
);
6803 dgap_err("unexpected end of file");
6806 p
->u
.board
.portstr
= dgap_savestring(s
);
6807 p
->u
.board
.port
= (short)simple_strtol(s
, &s2
, 0);
6808 if ((short)strlen(s
) > (short)(s2
- s
)) {
6809 dgap_err("bad number for IO port");
6812 p
->u
.board
.v_port
= 1;
6815 case MEM
: /* memory address */
6816 if (p
->type
!= BNODE
) {
6817 dgap_err("memory address only vaild for boards");
6820 s
= dgap_getword(in
);
6822 dgap_err("unexpected end of file");
6825 p
->u
.board
.addrstr
= dgap_savestring(s
);
6826 p
->u
.board
.addr
= simple_strtoul(s
, &s2
, 0);
6827 if ((int)strlen(s
) > (int)(s2
- s
)) {
6828 dgap_err("bad number for memory address");
6831 p
->u
.board
.v_addr
= 1;
6834 case PCIINFO
: /* pci information */
6835 if (p
->type
!= BNODE
) {
6836 dgap_err("memory address only vaild for boards");
6839 s
= dgap_getword(in
);
6841 dgap_err("unexpected end of file");
6844 p
->u
.board
.pcibusstr
= dgap_savestring(s
);
6845 p
->u
.board
.pcibus
= simple_strtoul(s
, &s2
, 0);
6846 if ((int)strlen(s
) > (int)(s2
- s
)) {
6847 dgap_err("bad number for pci bus");
6850 p
->u
.board
.v_pcibus
= 1;
6851 s
= dgap_getword(in
);
6853 dgap_err("unexpected end of file");
6856 p
->u
.board
.pcislotstr
= dgap_savestring(s
);
6857 p
->u
.board
.pcislot
= simple_strtoul(s
, &s2
, 0);
6858 if ((int)strlen(s
) > (int)(s2
- s
)) {
6859 dgap_err("bad number for pci slot");
6862 p
->u
.board
.v_pcislot
= 1;
6866 if (p
->type
!= BNODE
) {
6867 dgap_err("install method only vaild for boards");
6870 s
= dgap_getword(in
);
6872 dgap_err("unexpected end of file");
6875 p
->u
.board
.method
= dgap_savestring(s
);
6876 p
->u
.board
.v_method
= 1;
6880 if (p
->type
!= BNODE
) {
6881 dgap_err("config status only vaild for boards");
6884 s
= dgap_getword(in
);
6886 dgap_err("unexpected end of file");
6889 p
->u
.board
.status
= dgap_savestring(s
);
6892 case NPORTS
: /* number of ports */
6893 if (p
->type
== BNODE
) {
6894 s
= dgap_getword(in
);
6896 dgap_err("unexpected end of file");
6899 p
->u
.board
.nport
= (char)simple_strtol(s
, &s2
, 0);
6900 if ((int)strlen(s
) > (int)(s2
- s
)) {
6901 dgap_err("bad number for number of ports");
6904 p
->u
.board
.v_nport
= 1;
6905 } else if (p
->type
== CNODE
) {
6906 s
= dgap_getword(in
);
6908 dgap_err("unexpected end of file");
6911 p
->u
.conc
.nport
= (char)simple_strtol(s
, &s2
, 0);
6912 if ((int)strlen(s
) > (int)(s2
- s
)) {
6913 dgap_err("bad number for number of ports");
6916 p
->u
.conc
.v_nport
= 1;
6917 } else if (p
->type
== MNODE
) {
6918 s
= dgap_getword(in
);
6920 dgap_err("unexpected end of file");
6923 p
->u
.module
.nport
= (char)simple_strtol(s
, &s2
, 0);
6924 if ((int)strlen(s
) > (int)(s2
- s
)) {
6925 dgap_err("bad number for number of ports");
6928 p
->u
.module
.v_nport
= 1;
6930 dgap_err("nports only valid for concentrators or modules");
6935 case ID
: /* letter ID used in tty name */
6936 s
= dgap_getword(in
);
6938 dgap_err("unexpected end of file");
6942 p
->u
.board
.status
= dgap_savestring(s
);
6944 if (p
->type
== CNODE
) {
6945 p
->u
.conc
.id
= dgap_savestring(s
);
6947 } else if (p
->type
== MNODE
) {
6948 p
->u
.module
.id
= dgap_savestring(s
);
6949 p
->u
.module
.v_id
= 1;
6951 dgap_err("id only valid for concentrators or modules");
6956 case STARTO
: /* start offset of ID */
6957 if (p
->type
== BNODE
) {
6958 s
= dgap_getword(in
);
6960 dgap_err("unexpected end of file");
6963 p
->u
.board
.start
= simple_strtol(s
, &s2
, 0);
6964 if ((int)strlen(s
) > (int)(s2
- s
)) {
6965 dgap_err("bad number for start of tty count");
6968 p
->u
.board
.v_start
= 1;
6969 } else if (p
->type
== CNODE
) {
6970 s
= dgap_getword(in
);
6972 dgap_err("unexpected end of file");
6975 p
->u
.conc
.start
= simple_strtol(s
, &s2
, 0);
6976 if ((int)strlen(s
) > (int)(s2
- s
)) {
6977 dgap_err("bad number for start of tty count");
6980 p
->u
.conc
.v_start
= 1;
6981 } else if (p
->type
== MNODE
) {
6982 s
= dgap_getword(in
);
6984 dgap_err("unexpected end of file");
6987 p
->u
.module
.start
= simple_strtol(s
, &s2
, 0);
6988 if ((int)strlen(s
) > (int)(s2
- s
)) {
6989 dgap_err("bad number for start of tty count");
6992 p
->u
.module
.v_start
= 1;
6994 dgap_err("start only valid for concentrators or modules");
6999 case TTYN
: /* tty name prefix */
7000 if (dgap_checknode(p
))
7002 p
->next
= dgap_newnode(TNODE
);
7004 dgap_err("out of memory");
7008 s
= dgap_getword(in
);
7010 dgap_err("unexpeced end of file");
7013 p
->u
.ttyname
= dgap_savestring(s
);
7014 if (!p
->u
.ttyname
) {
7015 dgap_err("out of memory");
7020 case CU
: /* cu name prefix */
7021 if (dgap_checknode(p
))
7023 p
->next
= dgap_newnode(CUNODE
);
7025 dgap_err("out of memory");
7029 s
= dgap_getword(in
);
7031 dgap_err("unexpeced end of file");
7034 p
->u
.cuname
= dgap_savestring(s
);
7036 dgap_err("out of memory");
7041 case LINE
: /* line information */
7042 if (dgap_checknode(p
))
7045 dgap_err("must specify board before line info");
7048 switch (brd
->u
.board
.type
) {
7050 dgap_err("line not vaild for PC/em");
7053 p
->next
= dgap_newnode(LNODE
);
7055 dgap_err("out of memory");
7064 case CONC
: /* concentrator information */
7065 if (dgap_checknode(p
))
7068 dgap_err("must specify line info before concentrator");
7071 p
->next
= dgap_newnode(CNODE
);
7073 dgap_err("out of memory");
7079 brd
->u
.board
.conc2
++;
7081 brd
->u
.board
.conc1
++;
7085 case CX
: /* c/x type concentrator */
7086 if (p
->type
!= CNODE
) {
7087 dgap_err("cx only valid for concentrators");
7090 p
->u
.conc
.type
= CX
;
7091 p
->u
.conc
.v_type
= 1;
7094 case EPC
: /* epc type concentrator */
7095 if (p
->type
!= CNODE
) {
7096 dgap_err("cx only valid for concentrators");
7099 p
->u
.conc
.type
= EPC
;
7100 p
->u
.conc
.v_type
= 1;
7103 case MOD
: /* EBI module */
7104 if (dgap_checknode(p
))
7107 dgap_err("must specify board info before EBI modules");
7110 switch (brd
->u
.board
.type
) {
7116 dgap_err("must specify concentrator info before EBI module");
7120 p
->next
= dgap_newnode(MNODE
);
7122 dgap_err("out of memory");
7127 brd
->u
.board
.module2
++;
7129 brd
->u
.board
.module1
++;
7133 case PORTS
: /* ports type EBI module */
7134 if (p
->type
!= MNODE
) {
7135 dgap_err("ports only valid for EBI modules");
7138 p
->u
.module
.type
= PORTS
;
7139 p
->u
.module
.v_type
= 1;
7142 case MODEM
: /* ports type EBI module */
7143 if (p
->type
!= MNODE
) {
7144 dgap_err("modem only valid for modem modules");
7147 p
->u
.module
.type
= MODEM
;
7148 p
->u
.module
.v_type
= 1;
7152 if (p
->type
== LNODE
) {
7153 s
= dgap_getword(in
);
7155 dgap_err("unexpected end of file");
7158 p
->u
.line
.cable
= dgap_savestring(s
);
7159 p
->u
.line
.v_cable
= 1;
7163 case SPEED
: /* sync line speed indication */
7164 if (p
->type
== LNODE
) {
7165 s
= dgap_getword(in
);
7167 dgap_err("unexpected end of file");
7170 p
->u
.line
.speed
= (char)simple_strtol(s
, &s2
, 0);
7171 if ((short)strlen(s
) > (short)(s2
- s
)) {
7172 dgap_err("bad number for line speed");
7175 p
->u
.line
.v_speed
= 1;
7176 } else if (p
->type
== CNODE
) {
7177 s
= dgap_getword(in
);
7179 dgap_err("unexpected end of file");
7182 p
->u
.conc
.speed
= (char)simple_strtol(s
, &s2
, 0);
7183 if ((short)strlen(s
) > (short)(s2
- s
)) {
7184 dgap_err("bad number for line speed");
7187 p
->u
.conc
.v_speed
= 1;
7189 dgap_err("speed valid only for lines or concentrators.");
7195 if (p
->type
== CNODE
) {
7196 s
= dgap_getword(in
);
7198 dgap_err("unexpected end of file");
7201 p
->u
.conc
.connect
= dgap_savestring(s
);
7202 p
->u
.conc
.v_connect
= 1;
7205 case PRINT
: /* transparent print name prefix */
7206 if (dgap_checknode(p
))
7208 p
->next
= dgap_newnode(PNODE
);
7210 dgap_err("out of memory");
7214 s
= dgap_getword(in
);
7216 dgap_err("unexpeced end of file");
7219 p
->u
.printname
= dgap_savestring(s
);
7220 if (!p
->u
.printname
) {
7221 dgap_err("out of memory");
7226 case CMAJOR
: /* major number */
7227 if (dgap_checknode(p
))
7229 p
->next
= dgap_newnode(JNODE
);
7231 dgap_err("out of memory");
7235 s
= dgap_getword(in
);
7237 dgap_err("unexpected end of file");
7240 p
->u
.majornumber
= simple_strtol(s
, &s2
, 0);
7241 if ((int)strlen(s
) > (int)(s2
- s
)) {
7242 dgap_err("bad number for major number");
7247 case ALTPIN
: /* altpin setting */
7248 if (dgap_checknode(p
))
7250 p
->next
= dgap_newnode(ANODE
);
7252 dgap_err("out of memory");
7256 s
= dgap_getword(in
);
7258 dgap_err("unexpected end of file");
7261 p
->u
.altpin
= simple_strtol(s
, &s2
, 0);
7262 if ((int)strlen(s
) > (int)(s2
- s
)) {
7263 dgap_err("bad number for altpin");
7268 case USEINTR
: /* enable interrupt setting */
7269 if (dgap_checknode(p
))
7271 p
->next
= dgap_newnode(INTRNODE
);
7273 dgap_err("out of memory");
7277 s
= dgap_getword(in
);
7279 dgap_err("unexpected end of file");
7282 p
->u
.useintr
= simple_strtol(s
, &s2
, 0);
7283 if ((int)strlen(s
) > (int)(s2
- s
)) {
7284 dgap_err("bad number for useintr");
7289 case TTSIZ
: /* size of tty structure */
7290 if (dgap_checknode(p
))
7292 p
->next
= dgap_newnode(TSNODE
);
7294 dgap_err("out of memory");
7298 s
= dgap_getword(in
);
7300 dgap_err("unexpected end of file");
7303 p
->u
.ttysize
= simple_strtol(s
, &s2
, 0);
7304 if ((int)strlen(s
) > (int)(s2
- s
)) {
7305 dgap_err("bad number for ttysize");
7310 case CHSIZ
: /* channel structure size */
7311 if (dgap_checknode(p
))
7313 p
->next
= dgap_newnode(CSNODE
);
7315 dgap_err("out of memory");
7319 s
= dgap_getword(in
);
7321 dgap_err("unexpected end of file");
7324 p
->u
.chsize
= simple_strtol(s
, &s2
, 0);
7325 if ((int)strlen(s
) > (int)(s2
- s
)) {
7326 dgap_err("bad number for chsize");
7331 case BSSIZ
: /* board structure size */
7332 if (dgap_checknode(p
))
7334 p
->next
= dgap_newnode(BSNODE
);
7336 dgap_err("out of memory");
7340 s
= dgap_getword(in
);
7342 dgap_err("unexpected end of file");
7345 p
->u
.bssize
= simple_strtol(s
, &s2
, 0);
7346 if ((int)strlen(s
) > (int)(s2
- s
)) {
7347 dgap_err("bad number for bssize");
7352 case UNTSIZ
: /* sched structure size */
7353 if (dgap_checknode(p
))
7355 p
->next
= dgap_newnode(USNODE
);
7357 dgap_err("out of memory");
7361 s
= dgap_getword(in
);
7363 dgap_err("unexpected end of file");
7366 p
->u
.unsize
= simple_strtol(s
, &s2
, 0);
7367 if ((int)strlen(s
) > (int)(s2
- s
)) {
7368 dgap_err("bad number for schedsize");
7373 case F2SIZ
: /* f2200 structure size */
7374 if (dgap_checknode(p
))
7376 p
->next
= dgap_newnode(FSNODE
);
7378 dgap_err("out of memory");
7382 s
= dgap_getword(in
);
7384 dgap_err("unexpected end of file");
7387 p
->u
.f2size
= simple_strtol(s
, &s2
, 0);
7388 if ((int)strlen(s
) > (int)(s2
- s
)) {
7389 dgap_err("bad number for f2200size");
7394 case VPSIZ
: /* vpix structure size */
7395 if (dgap_checknode(p
))
7397 p
->next
= dgap_newnode(VSNODE
);
7399 dgap_err("out of memory");
7403 s
= dgap_getword(in
);
7405 dgap_err("unexpected end of file");
7408 p
->u
.vpixsize
= simple_strtol(s
, &s2
, 0);
7409 if ((int)strlen(s
) > (int)(s2
- s
)) {
7410 dgap_err("bad number for vpixsize");
7419 * dgap_sindex: much like index(), but it looks for a match of any character in
7420 * the group, and returns that position. If the first character is a ^, then
7421 * this will match the first occurrence not in that group.
7423 static char *dgap_sindex(char *string
, char *group
)
7427 if (!string
|| !group
)
7428 return (char *) NULL
;
7430 if (*group
== '^') {
7432 for (; *string
; string
++) {
7433 for (ptr
= group
; *ptr
; ptr
++) {
7434 if (*ptr
== *string
)
7441 for (; *string
; string
++) {
7442 for (ptr
= group
; *ptr
; ptr
++) {
7443 if (*ptr
== *string
)
7449 return (char *) NULL
;
7453 * Get a token from the input file; return 0 if end of file is reached
7455 static int dgap_gettok(char **in
, struct cnode
*p
)
7460 if (strstr(dgap_cword
, "boar")) {
7461 w
= dgap_getword(in
);
7462 snprintf(dgap_cword
, MAXCWORD
, "%s", w
);
7463 for (t
= dgap_tlist
; t
->token
!= 0; t
++) {
7464 if (!strcmp(w
, t
->string
))
7467 dgap_err("board !!type not specified");
7470 while ((w
= dgap_getword(in
))) {
7471 snprintf(dgap_cword
, MAXCWORD
, "%s", w
);
7472 for (t
= dgap_tlist
; t
->token
!= 0; t
++) {
7473 if (!strcmp(w
, t
->string
))
7482 * get a word from the input stream, also keep track of current line number.
7483 * words are separated by whitespace.
7485 static char *dgap_getword(char **in
)
7487 char *ret_ptr
= *in
;
7489 char *ptr
= dgap_sindex(*in
, " \t\n");
7491 /* If no word found, return null */
7495 /* Mark new location for our buffer */
7499 /* Eat any extra spaces/tabs/newlines that might be present */
7500 while (*in
&& **in
&& ((**in
== ' ') || (**in
== '\t') || (**in
== '\n'))) {
7509 * print an error message, giving the line number in the file where
7510 * the error occurred.
7512 static void dgap_err(char *s
)
7514 pr_err("dgap: parse: %s\n", s
);
7518 * allocate a new configuration node of type t
7520 static struct cnode
*dgap_newnode(int t
)
7524 n
= kmalloc(sizeof(struct cnode
), GFP_ATOMIC
);
7526 memset((char *)n
, 0, sizeof(struct cnode
));
7533 * dgap_checknode: see if all the necessary info has been supplied for a node
7534 * before creating the next node.
7536 static int dgap_checknode(struct cnode
*p
)
7540 if (p
->u
.board
.v_type
== 0) {
7541 dgap_err("board type !not specified");
7548 if (p
->u
.line
.v_speed
== 0) {
7549 dgap_err("line speed not specified");
7555 if (p
->u
.conc
.v_type
== 0) {
7556 dgap_err("concentrator type not specified");
7559 if (p
->u
.conc
.v_speed
== 0) {
7560 dgap_err("concentrator line speed not specified");
7563 if (p
->u
.conc
.v_nport
== 0) {
7564 dgap_err("number of ports on concentrator not specified");
7567 if (p
->u
.conc
.v_id
== 0) {
7568 dgap_err("concentrator id letter not specified");
7574 if (p
->u
.module
.v_type
== 0) {
7575 dgap_err("EBI module type not specified");
7578 if (p
->u
.module
.v_nport
== 0) {
7579 dgap_err("number of ports on EBI module not specified");
7582 if (p
->u
.module
.v_id
== 0) {
7583 dgap_err("EBI module id letter not specified");
7592 * save a string somewhere
7594 static char *dgap_savestring(char *s
)
7598 p
= kmalloc(strlen(s
) + 1, GFP_ATOMIC
);
7605 * Given a board pointer, returns whether we should use interrupts or not.
7607 static uint
dgap_config_get_useintr(struct board_t
*bd
)
7609 struct cnode
*p
= NULL
;
7614 for (p
= bd
->bd_config
; p
; p
= p
->next
) {
7618 * check for pcxr types.
7620 return p
->u
.useintr
;
7626 /* If not found, then don't turn on interrupts. */
7631 * Given a board pointer, returns whether we turn on altpin or not.
7633 static uint
dgap_config_get_altpin(struct board_t
*bd
)
7635 struct cnode
*p
= NULL
;
7640 for (p
= bd
->bd_config
; p
; p
= p
->next
) {
7644 * check for pcxr types.
7652 /* If not found, then don't turn on interrupts. */
7657 * Given a specific type of board, if found, detached link and
7658 * returns the first occurrence in the list.
7660 static struct cnode
*dgap_find_config(int type
, int bus
, int slot
)
7662 struct cnode
*p
, *prev
= NULL
, *prev2
= NULL
, *found
= NULL
;
7666 while (p
->next
!= NULL
) {
7670 if (p
->type
== BNODE
) {
7672 if (p
->u
.board
.type
== type
) {
7674 if (p
->u
.board
.v_pcibus
&&
7675 p
->u
.board
.pcibus
!= bus
)
7677 if (p
->u
.board
.v_pcislot
&&
7678 p
->u
.board
.pcislot
!= slot
)
7683 * Keep walking thru the list till we find the next board.
7685 while (p
->next
!= NULL
) {
7688 if (p
->type
== BNODE
) {
7691 * Mark the end of our 1 board chain of configs.
7696 * Link the "next" board to the previous board,
7697 * effectively "unlinking" our board from the main config.
7705 * It must be the last board in the list.
7716 * Given a board pointer, walks the config link, counting up
7717 * all ports user specified should be on the board.
7718 * (This does NOT mean they are all actually present right now tho)
7720 static uint
dgap_config_get_number_of_ports(struct board_t
*bd
)
7723 struct cnode
*p
= NULL
;
7728 for (p
= bd
->bd_config
; p
; p
= p
->next
) {
7733 * check for pcxr types.
7735 if (p
->u
.board
.type
> EPCFE
)
7736 count
+= p
->u
.board
.nport
;
7739 count
+= p
->u
.conc
.nport
;
7742 count
+= p
->u
.module
.nport
;
7749 static char *dgap_create_config_string(struct board_t
*bd
, char *string
)
7752 struct cnode
*p
= NULL
;
7753 struct cnode
*q
= NULL
;
7761 for (p
= bd
->bd_config
; p
; p
= p
->next
) {
7767 *ptr
= p
->u
.line
.speed
;
7772 * Because the EPC/con concentrators can have EM modules
7773 * hanging off of them, we have to walk ahead in the list
7774 * and keep adding the number of ports on each EM to the config.
7777 speed
= p
->u
.conc
.speed
;
7779 if ((q
!= NULL
) && (q
->type
== MNODE
)) {
7780 *ptr
= (p
->u
.conc
.nport
+ 0x80);
7783 while ((q
->next
!= NULL
) && (q
->next
->type
) == MNODE
) {
7784 *ptr
= (q
->u
.module
.nport
+ 0x80);
7789 *ptr
= q
->u
.module
.nport
;
7792 *ptr
= p
->u
.conc
.nport
;