2 * Copyright 2003 Digi International (www.digi.com)
3 * Scott H Kilau <Scott_Kilau at digi dot com>
5 * This program is free software; you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published by
7 * the Free Software Foundation; either version 2, or (at your option)
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY, EXPRESS OR IMPLIED; without even the
12 * implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
13 * PURPOSE. See the GNU General Public License for more details.
18 * In the original out of kernel Digi dgap driver, firmware
19 * loading was done via user land to driver handshaking.
21 * For cards that support a concentrator (port expander),
22 * I believe the concentrator its self told the card which
23 * concentrator is actually attached and then that info
24 * was used to tell user land which concentrator firmware
25 * image was to be downloaded. I think even the BIOS or
26 * FEP images required could change with the connection
27 * of a particular concentrator.
29 * Since I have no access to any of these cards or
30 * concentrators, I cannot put the correct concentrator
31 * firmware file names into the firmware_info structure
32 * as is now done for the BIOS and FEP images.
34 * I think, but am not certain, that the cards supporting
35 * concentrators will function without them. So support
36 * of these cards has been left in this driver.
38 * In order to fully support those cards, they would
39 * either have to be acquired for dissection or maybe
40 * Digi International could provide some assistance.
42 #undef DIGI_CONCENTRATORS_SUPPORTED
44 #define pr_fmt(fmt) "dgap: " fmt
46 #include <linux/kernel.h>
47 #include <linux/module.h>
48 #include <linux/pci.h>
49 #include <linux/delay.h> /* For udelay */
50 #include <linux/slab.h>
51 #include <linux/uaccess.h>
52 #include <linux/sched.h>
54 #include <linux/interrupt.h> /* For tasklet and interrupt structs/defines */
55 #include <linux/ctype.h>
56 #include <linux/tty.h>
57 #include <linux/tty_flip.h>
58 #include <linux/serial_reg.h>
59 #include <linux/io.h> /* For read[bwl]/write[bwl] */
61 #include <linux/string.h>
62 #include <linux/device.h>
63 #include <linux/kdev_t.h>
64 #include <linux/firmware.h>
69 * File operations permitted on Control/Management major.
71 static const struct file_operations dgap_board_fops = {
75 static uint dgap_numboards;
76 static struct board_t *dgap_board[MAXBOARDS];
77 static ulong dgap_poll_counter;
78 static int dgap_driver_state = DRIVER_INITIALIZED;
79 static int dgap_poll_tick = 20; /* Poll interval - 20 ms */
81 static struct class *dgap_class;
83 static uint dgap_count = 500;
88 static DEFINE_SPINLOCK(dgap_poll_lock); /* Poll scheduling lock */
89 static ulong dgap_poll_time; /* Time of next poll */
90 static uint dgap_poll_stop; /* Used to tell poller to stop */
91 static struct timer_list dgap_poll_timer;
96 Card Model Number of Ports Interface
97 ----------------------------------------------------------------
98 Acceleport Xem 4 - 64 (EIA232 & EIA422)
99 Acceleport Xr 4 & 8 (EIA232)
100 Acceleport Xr 920 4 & 8 (EIA232)
101 Acceleport C/X 8 - 128 (EIA232)
102 Acceleport EPC/X 8 - 224 (EIA232)
103 Acceleport Xr/422 4 & 8 (EIA422)
104 Acceleport 2r/920 2 (EIA232)
105 Acceleport 4r/920 4 (EIA232)
106 Acceleport 8r/920 8 (EIA232)
108 IBM 8-Port Asynchronous PCI Adapter (EIA232)
109 IBM 128-Port Asynchronous PCI Adapter (EIA232 & EIA422)
112 static struct pci_device_id dgap_pci_tbl[] = {
113 { DIGI_VID, PCI_DEV_XEM_DID, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0 },
114 { DIGI_VID, PCI_DEV_CX_DID, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 1 },
115 { DIGI_VID, PCI_DEV_CX_IBM_DID, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 2 },
116 { DIGI_VID, PCI_DEV_EPCJ_DID, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 3 },
117 { DIGI_VID, PCI_DEV_920_2_DID, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 4 },
118 { DIGI_VID, PCI_DEV_920_4_DID, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 5 },
119 { DIGI_VID, PCI_DEV_920_8_DID, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 6 },
120 { DIGI_VID, PCI_DEV_XR_DID, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 7 },
121 { DIGI_VID, PCI_DEV_XRJ_DID, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 8 },
122 { DIGI_VID, PCI_DEV_XR_422_DID, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 9 },
123 { DIGI_VID, PCI_DEV_XR_IBM_DID, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 10 },
124 { DIGI_VID, PCI_DEV_XR_SAIP_DID, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 11 },
125 { DIGI_VID, PCI_DEV_XR_BULL_DID, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 12 },
126 { DIGI_VID, PCI_DEV_920_8_HP_DID, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 13 },
127 { DIGI_VID, PCI_DEV_XEM_HP_DID, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 14 },
128 {0,} /* 0 terminated list. */
130 MODULE_DEVICE_TABLE(pci, dgap_pci_tbl);
133 * A generic list of Product names, PCI Vendor ID, and PCI Device ID.
142 static struct board_id dgap_ids[] = {
143 {PPCM, PCI_DEV_XEM_NAME, 64, (T_PCXM | T_PCLITE | T_PCIBUS)},
144 {PCX, PCI_DEV_CX_NAME, 128, (T_CX | T_PCIBUS) },
145 {PCX, PCI_DEV_CX_IBM_NAME, 128, (T_CX | T_PCIBUS) },
146 {PEPC, PCI_DEV_EPCJ_NAME, 224, (T_EPC | T_PCIBUS) },
147 {APORT2_920P, PCI_DEV_920_2_NAME, 2, (T_PCXR | T_PCLITE | T_PCIBUS)},
148 {APORT4_920P, PCI_DEV_920_4_NAME, 4, (T_PCXR | T_PCLITE | T_PCIBUS)},
149 {APORT8_920P, PCI_DEV_920_8_NAME, 8, (T_PCXR | T_PCLITE | T_PCIBUS)},
150 {PAPORT8, PCI_DEV_XR_NAME, 8, (T_PCXR | T_PCLITE | T_PCIBUS)},
151 {PAPORT8, PCI_DEV_XRJ_NAME, 8, (T_PCXR | T_PCLITE | T_PCIBUS)},
152 {PAPORT8, PCI_DEV_XR_422_NAME, 8, (T_PCXR | T_PCLITE | T_PCIBUS)},
153 {PAPORT8, PCI_DEV_XR_IBM_NAME, 8, (T_PCXR | T_PCLITE | T_PCIBUS)},
154 {PAPORT8, PCI_DEV_XR_SAIP_NAME, 8, (T_PCXR | T_PCLITE | T_PCIBUS)},
155 {PAPORT8, PCI_DEV_XR_BULL_NAME, 8, (T_PCXR | T_PCLITE | T_PCIBUS)},
156 {APORT8_920P, PCI_DEV_920_8_HP_NAME, 8, (T_PCXR | T_PCLITE | T_PCIBUS)},
157 {PPCM, PCI_DEV_XEM_HP_NAME, 64, (T_PCXM | T_PCLITE | T_PCIBUS)},
158 {0,} /* 0 terminated list. */
161 struct firmware_info {
162 u8 *conf_name; /* dgap.conf */
163 u8 *bios_name; /* BIOS filename */
164 u8 *fep_name; /* FEP filename */
165 u8 *con_name; /* Concentrator filename FIXME*/
166 int num; /* sequence number */
170 * Firmware - BIOS, FEP, and CONC filenames
172 static struct firmware_info fw_info[] = {
173 { "dgap/dgap.conf", "dgap/sxbios.bin", "dgap/sxfep.bin", NULL, 0 },
174 { "dgap/dgap.conf", "dgap/cxpbios.bin", "dgap/cxpfep.bin", NULL, 1 },
175 { "dgap/dgap.conf", "dgap/cxpbios.bin", "dgap/cxpfep.bin", NULL, 2 },
176 { "dgap/dgap.conf", "dgap/pcibios.bin", "dgap/pcifep.bin", NULL, 3 },
177 { "dgap/dgap.conf", "dgap/xrbios.bin", "dgap/xrfep.bin", NULL, 4 },
178 { "dgap/dgap.conf", "dgap/xrbios.bin", "dgap/xrfep.bin", NULL, 5 },
179 { "dgap/dgap.conf", "dgap/xrbios.bin", "dgap/xrfep.bin", NULL, 6 },
180 { "dgap/dgap.conf", "dgap/xrbios.bin", "dgap/xrfep.bin", NULL, 7 },
181 { "dgap/dgap.conf", "dgap/xrbios.bin", "dgap/xrfep.bin", NULL, 8 },
182 { "dgap/dgap.conf", "dgap/xrbios.bin", "dgap/xrfep.bin", NULL, 9 },
183 { "dgap/dgap.conf", "dgap/xrbios.bin", "dgap/xrfep.bin", NULL, 10 },
184 { "dgap/dgap.conf", "dgap/xrbios.bin", "dgap/xrfep.bin", NULL, 11 },
185 { "dgap/dgap.conf", "dgap/xrbios.bin", "dgap/xrfep.bin", NULL, 12 },
186 { "dgap/dgap.conf", "dgap/xrbios.bin", "dgap/xrfep.bin", NULL, 13 },
187 { "dgap/dgap.conf", "dgap/sxbios.bin", "dgap/sxfep.bin", NULL, 14 },
192 * Default transparent print information.
194 static struct digi_t dgap_digi_init = {
195 .digi_flags = DIGI_COOK, /* Flags */
196 .digi_maxcps = 100, /* Max CPS */
197 .digi_maxchar = 50, /* Max chars in print queue */
198 .digi_bufsize = 100, /* Printer buffer size */
199 .digi_onlen = 4, /* size of printer on string */
200 .digi_offlen = 4, /* size of printer off string */
201 .digi_onstr = "\033[5i", /* ANSI printer on string ] */
202 .digi_offstr = "\033[4i", /* ANSI printer off string ] */
203 .digi_term = "ansi" /* default terminal type */
207 * Define a local default termios struct. All ports will be created
208 * with this termios initially.
210 * This defines a raw port at 9600 baud, 8 data bits, no parity,
214 static struct ktermios dgap_default_termios = {
215 .c_iflag = (DEFAULT_IFLAGS), /* iflags */
216 .c_oflag = (DEFAULT_OFLAGS), /* oflags */
217 .c_cflag = (DEFAULT_CFLAGS), /* cflags */
218 .c_lflag = (DEFAULT_LFLAGS), /* lflags */
224 * Our needed internal static variables from dgap_parse.c
226 static struct cnode dgap_head;
228 static char dgap_cword[MAXCWORD];
235 static struct toklist dgap_brdtype[] = {
236 { PCX, "Digi_AccelePort_C/X_PCI" },
237 { PEPC, "Digi_AccelePort_EPC/X_PCI" },
238 { PPCM, "Digi_AccelePort_Xem_PCI" },
239 { APORT2_920P, "Digi_AccelePort_2r_920_PCI" },
240 { APORT4_920P, "Digi_AccelePort_4r_920_PCI" },
241 { APORT8_920P, "Digi_AccelePort_8r_920_PCI" },
242 { PAPORT4, "Digi_AccelePort_4r_PCI(EIA-232/RS-422)" },
243 { PAPORT8, "Digi_AccelePort_8r_PCI(EIA-232/RS-422)" },
247 static struct toklist dgap_tlist[] = {
248 { BEGIN, "config_begin" },
249 { END, "config_end" },
251 { PCIINFO, "pciinfo" },
254 { CONC, "concentrator" },
264 { CONNECT, "connect" },
265 { METHOD, "method" },
266 { STATUS, "status" },
267 { CUSTOM, "Custom" },
273 { NPORTS, "nports" },
278 { ALTPIN, "altpin" },
279 { USEINTR, "useintr" },
280 { TTSIZ, "ttysize" },
282 { BSSIZ, "boardsize" },
283 { UNTSIZ, "schedsize" },
284 { F2SIZ, "f2200size" },
285 { VPSIZ, "vpixsize" },
290 * get a word from the input stream, also keep track of current line number.
291 * words are separated by whitespace.
293 static char *dgap_getword(char **in)
297 char *ptr = strpbrk(*in, " \t\n");
299 /* If no word found, return null */
303 /* Mark new location for our buffer */
307 /* Eat any extra spaces/tabs/newlines that might be present */
308 while (*in && **in && ((**in == ' ') ||
320 * Get a token from the input file; return 0 if end of file is reached
322 static int dgap_gettok(char **in)
327 if (strstr(dgap_cword, "board")) {
328 w = dgap_getword(in);
331 snprintf(dgap_cword, MAXCWORD, "%s", w);
332 for (t = dgap_brdtype; t->token != 0; t++) {
333 if (!strcmp(w, t->string))
337 while ((w = dgap_getword(in))) {
338 snprintf(dgap_cword, MAXCWORD, "%s", w);
339 for (t = dgap_tlist; t->token != 0; t++) {
340 if (!strcmp(w, t->string))
350 * dgap_checknode: see if all the necessary info has been supplied for a node
351 * before creating the next node.
353 static int dgap_checknode(struct cnode *p)
357 if (p->u.line.v_speed == 0) {
358 pr_err("line speed not specified");
364 if (p->u.conc.v_speed == 0) {
365 pr_err("concentrator line speed not specified");
368 if (p->u.conc.v_nport == 0) {
369 pr_err("number of ports on concentrator not specified");
372 if (p->u.conc.v_id == 0) {
373 pr_err("concentrator id letter not specified");
379 if (p->u.module.v_nport == 0) {
380 pr_err("number of ports on EBI module not specified");
383 if (p->u.module.v_id == 0) {
384 pr_err("EBI module id letter not specified");
393 * Given a board pointer, returns whether we should use interrupts or not.
395 static uint dgap_config_get_useintr(struct board_t *bd)
402 for (p = bd->bd_config; p; p = p->next) {
403 if (p->type == INTRNODE) {
405 * check for pcxr types.
411 /* If not found, then don't turn on interrupts. */
416 * Given a board pointer, returns whether we turn on altpin or not.
418 static uint dgap_config_get_altpin(struct board_t *bd)
425 for (p = bd->bd_config; p; p = p->next) {
426 if (p->type == ANODE) {
428 * check for pcxr types.
434 /* If not found, then don't turn on interrupts. */
439 * Given a specific type of board, if found, detached link and
440 * returns the first occurrence in the list.
442 static struct cnode *dgap_find_config(int type, int bus, int slot)
444 struct cnode *p, *prev, *prev2, *found;
452 if (p->type != BNODE)
455 if (p->u.board.type != type)
458 if (p->u.board.v_pcibus &&
459 p->u.board.pcibus != bus)
462 if (p->u.board.v_pcislot &&
463 p->u.board.pcislot != slot)
468 * Keep walking thru the list till we
469 * find the next board.
475 if (p->type != BNODE)
479 * Mark the end of our 1 board
485 * Link the "next" board to the
486 * previous board, effectively
487 * "unlinking" our board from
495 * It must be the last board in the list.
504 * Given a board pointer, walks the config link, counting up
505 * all ports user specified should be on the board.
506 * (This does NOT mean they are all actually present right now tho)
508 static uint dgap_config_get_num_prts(struct board_t *bd)
516 for (p = bd->bd_config; p; p = p->next) {
520 * check for pcxr types.
522 if (p->u.board.type > EPCFE)
523 count += p->u.board.nport;
526 count += p->u.conc.nport;
529 count += p->u.module.nport;
536 static char *dgap_create_config_string(struct board_t *bd, char *string)
548 for (p = bd->bd_config; p; p = p->next) {
553 *ptr = p->u.line.speed;
558 * Because the EPC/con concentrators can have EM modules
559 * hanging off of them, we have to walk ahead in the
560 * list and keep adding the number of ports on each EM
561 * to the config. UGH!
563 speed = p->u.conc.speed;
565 if (q && (q->type == MNODE)) {
566 *ptr = (p->u.conc.nport + 0x80);
569 while (q->next && (q->next->type) == MNODE) {
570 *ptr = (q->u.module.nport + 0x80);
575 *ptr = q->u.module.nport;
578 *ptr = p->u.conc.nport;
593 * Parse a configuration file read into memory as a string.
595 static int dgap_parsefile(char **in)
597 struct cnode *p, *brd, *line, *conc;
603 brd = line = conc = NULL;
605 /* perhaps we are adding to an existing list? */
609 /* file must start with a BEGIN */
610 while ((rc = dgap_gettok(in)) != BEGIN) {
612 pr_err("unexpected EOF");
622 rc = dgap_gettok(in);
624 pr_err("unexpected EOF");
629 case BEGIN: /* should only be 1 begin */
630 pr_err("unexpected config_begin\n");
636 case BOARD: /* board info */
637 if (dgap_checknode(p))
640 p->next = kzalloc(sizeof(struct cnode), GFP_KERNEL);
647 p->u.board.status = kstrdup("No", GFP_KERNEL);
652 board_type = dgap_gettok(in);
653 if (board_type == 0) {
654 pr_err("board !!type not specified");
658 p->u.board.type = board_type;
662 case MEM: /* memory address */
663 if (p->type != BNODE) {
664 pr_err("memory address only valid for boards");
667 s = dgap_getword(in);
669 pr_err("unexpected end of file");
672 kfree(p->u.board.addrstr);
673 p->u.board.addrstr = kstrdup(s, GFP_KERNEL);
674 if (kstrtoul(s, 0, &p->u.board.addr)) {
675 pr_err("bad number for memory address");
678 p->u.board.v_addr = 1;
681 case PCIINFO: /* pci information */
682 if (p->type != BNODE) {
683 pr_err("memory address only valid for boards");
686 s = dgap_getword(in);
688 pr_err("unexpected end of file");
691 kfree(p->u.board.pcibusstr);
692 p->u.board.pcibusstr = kstrdup(s, GFP_KERNEL);
693 if (kstrtoul(s, 0, &p->u.board.pcibus)) {
694 pr_err("bad number for pci bus");
697 p->u.board.v_pcibus = 1;
698 s = dgap_getword(in);
700 pr_err("unexpected end of file");
703 kfree(p->u.board.pcislotstr);
704 p->u.board.pcislotstr = kstrdup(s, GFP_KERNEL);
705 if (kstrtoul(s, 0, &p->u.board.pcislot)) {
706 pr_err("bad number for pci slot");
709 p->u.board.v_pcislot = 1;
713 if (p->type != BNODE) {
714 pr_err("install method only valid for boards");
717 s = dgap_getword(in);
719 pr_err("unexpected end of file");
722 kfree(p->u.board.method);
723 p->u.board.method = kstrdup(s, GFP_KERNEL);
724 p->u.board.v_method = 1;
728 if (p->type != BNODE) {
729 pr_err("config status only valid for boards");
732 s = dgap_getword(in);
734 pr_err("unexpected end of file");
737 kfree(p->u.board.status);
738 p->u.board.status = kstrdup(s, GFP_KERNEL);
741 case NPORTS: /* number of ports */
742 if (p->type == BNODE) {
743 s = dgap_getword(in);
745 pr_err("unexpected end of file");
748 if (kstrtol(s, 0, &p->u.board.nport)) {
749 pr_err("bad number for number of ports");
752 p->u.board.v_nport = 1;
753 } else if (p->type == CNODE) {
754 s = dgap_getword(in);
756 pr_err("unexpected end of file");
759 if (kstrtol(s, 0, &p->u.conc.nport)) {
760 pr_err("bad number for number of ports");
763 p->u.conc.v_nport = 1;
764 } else if (p->type == MNODE) {
765 s = dgap_getword(in);
767 pr_err("unexpected end of file");
770 if (kstrtol(s, 0, &p->u.module.nport)) {
771 pr_err("bad number for number of ports");
774 p->u.module.v_nport = 1;
776 pr_err("nports only valid for concentrators or modules");
781 case ID: /* letter ID used in tty name */
782 s = dgap_getword(in);
784 pr_err("unexpected end of file");
787 kfree(p->u.board.status);
788 p->u.board.status = kstrdup(s, GFP_KERNEL);
790 if (p->type == CNODE) {
792 p->u.conc.id = kstrdup(s, GFP_KERNEL);
794 } else if (p->type == MNODE) {
795 kfree(p->u.module.id);
796 p->u.module.id = kstrdup(s, GFP_KERNEL);
797 p->u.module.v_id = 1;
799 pr_err("id only valid for concentrators or modules");
804 case STARTO: /* start offset of ID */
805 if (p->type == BNODE) {
806 s = dgap_getword(in);
808 pr_err("unexpected end of file");
811 if (kstrtol(s, 0, &p->u.board.start)) {
812 pr_err("bad number for start of tty count");
815 p->u.board.v_start = 1;
816 } else if (p->type == CNODE) {
817 s = dgap_getword(in);
819 pr_err("unexpected end of file");
822 if (kstrtol(s, 0, &p->u.conc.start)) {
823 pr_err("bad number for start of tty count");
826 p->u.conc.v_start = 1;
827 } else if (p->type == MNODE) {
828 s = dgap_getword(in);
830 pr_err("unexpected end of file");
833 if (kstrtol(s, 0, &p->u.module.start)) {
834 pr_err("bad number for start of tty count");
837 p->u.module.v_start = 1;
839 pr_err("start only valid for concentrators or modules");
844 case TTYN: /* tty name prefix */
845 if (dgap_checknode(p))
848 p->next = kzalloc(sizeof(struct cnode), GFP_KERNEL);
855 s = dgap_getword(in);
857 pr_err("unexpeced end of file");
860 p->u.ttyname = kstrdup(s, GFP_KERNEL);
866 case CU: /* cu name prefix */
867 if (dgap_checknode(p))
870 p->next = kzalloc(sizeof(struct cnode), GFP_KERNEL);
877 s = dgap_getword(in);
879 pr_err("unexpeced end of file");
882 p->u.cuname = kstrdup(s, GFP_KERNEL);
888 case LINE: /* line information */
889 if (dgap_checknode(p))
892 pr_err("must specify board before line info");
895 switch (brd->u.board.type) {
897 pr_err("line not valid for PC/em");
901 p->next = kzalloc(sizeof(struct cnode), GFP_KERNEL);
912 case CONC: /* concentrator information */
913 if (dgap_checknode(p))
916 pr_err("must specify line info before concentrator");
920 p->next = kzalloc(sizeof(struct cnode), GFP_KERNEL);
929 brd->u.board.conc2++;
931 brd->u.board.conc1++;
933 conc_type = dgap_gettok(in);
934 if (conc_type == 0 ||
935 (conc_type != CX && conc_type != EPC)) {
936 pr_err("failed to set a type of concentratros");
940 p->u.conc.type = conc_type;
944 case MOD: /* EBI module */
945 if (dgap_checknode(p))
948 pr_err("must specify board info before EBI modules");
951 switch (brd->u.board.type) {
957 pr_err("must specify concentrator info before EBI module");
962 p->next = kzalloc(sizeof(struct cnode), GFP_KERNEL);
970 brd->u.board.module2++;
972 brd->u.board.module1++;
974 module_type = dgap_gettok(in);
975 if (module_type == 0 ||
976 (module_type != PORTS && module_type != MODEM)) {
977 pr_err("failed to set a type of module");
981 p->u.module.type = module_type;
986 if (p->type == LNODE) {
987 s = dgap_getword(in);
989 pr_err("unexpected end of file");
992 kfree(p->u.line.cable);
993 p->u.line.cable = kstrdup(s, GFP_KERNEL);
994 p->u.line.v_cable = 1;
998 case SPEED: /* sync line speed indication */
999 if (p->type == LNODE) {
1000 s = dgap_getword(in);
1002 pr_err("unexpected end of file");
1005 if (kstrtol(s, 0, &p->u.line.speed)) {
1006 pr_err("bad number for line speed");
1009 p->u.line.v_speed = 1;
1010 } else if (p->type == CNODE) {
1011 s = dgap_getword(in);
1013 pr_err("unexpected end of file");
1016 if (kstrtol(s, 0, &p->u.conc.speed)) {
1017 pr_err("bad number for line speed");
1020 p->u.conc.v_speed = 1;
1022 pr_err("speed valid only for lines or concentrators.");
1028 if (p->type == CNODE) {
1029 s = dgap_getword(in);
1031 pr_err("unexpected end of file");
1034 kfree(p->u.conc.connect);
1035 p->u.conc.connect = kstrdup(s, GFP_KERNEL);
1036 p->u.conc.v_connect = 1;
1039 case PRINT: /* transparent print name prefix */
1040 if (dgap_checknode(p))
1043 p->next = kzalloc(sizeof(struct cnode), GFP_KERNEL);
1050 s = dgap_getword(in);
1052 pr_err("unexpeced end of file");
1055 p->u.printname = kstrdup(s, GFP_KERNEL);
1056 if (!p->u.printname)
1061 case CMAJOR: /* major number */
1062 if (dgap_checknode(p))
1065 p->next = kzalloc(sizeof(struct cnode), GFP_KERNEL);
1072 s = dgap_getword(in);
1074 pr_err("unexpected end of file");
1077 if (kstrtol(s, 0, &p->u.majornumber)) {
1078 pr_err("bad number for major number");
1083 case ALTPIN: /* altpin setting */
1084 if (dgap_checknode(p))
1087 p->next = kzalloc(sizeof(struct cnode), GFP_KERNEL);
1094 s = dgap_getword(in);
1096 pr_err("unexpected end of file");
1099 if (kstrtol(s, 0, &p->u.altpin)) {
1100 pr_err("bad number for altpin");
1105 case USEINTR: /* enable interrupt setting */
1106 if (dgap_checknode(p))
1109 p->next = kzalloc(sizeof(struct cnode), GFP_KERNEL);
1115 s = dgap_getword(in);
1117 pr_err("unexpected end of file");
1120 if (kstrtol(s, 0, &p->u.useintr)) {
1121 pr_err("bad number for useintr");
1126 case TTSIZ: /* size of tty structure */
1127 if (dgap_checknode(p))
1130 p->next = kzalloc(sizeof(struct cnode), GFP_KERNEL);
1137 s = dgap_getword(in);
1139 pr_err("unexpected end of file");
1142 if (kstrtol(s, 0, &p->u.ttysize)) {
1143 pr_err("bad number for ttysize");
1148 case CHSIZ: /* channel structure size */
1149 if (dgap_checknode(p))
1152 p->next = kzalloc(sizeof(struct cnode), GFP_KERNEL);
1159 s = dgap_getword(in);
1161 pr_err("unexpected end of file");
1164 if (kstrtol(s, 0, &p->u.chsize)) {
1165 pr_err("bad number for chsize");
1170 case BSSIZ: /* board structure size */
1171 if (dgap_checknode(p))
1174 p->next = kzalloc(sizeof(struct cnode), GFP_KERNEL);
1181 s = dgap_getword(in);
1183 pr_err("unexpected end of file");
1186 if (kstrtol(s, 0, &p->u.bssize)) {
1187 pr_err("bad number for bssize");
1192 case UNTSIZ: /* sched structure size */
1193 if (dgap_checknode(p))
1196 p->next = kzalloc(sizeof(struct cnode), GFP_KERNEL);
1203 s = dgap_getword(in);
1205 pr_err("unexpected end of file");
1208 if (kstrtol(s, 0, &p->u.unsize)) {
1209 pr_err("bad number for schedsize");
1214 case F2SIZ: /* f2200 structure size */
1215 if (dgap_checknode(p))
1218 p->next = kzalloc(sizeof(struct cnode), GFP_KERNEL);
1225 s = dgap_getword(in);
1227 pr_err("unexpected end of file");
1230 if (kstrtol(s, 0, &p->u.f2size)) {
1231 pr_err("bad number for f2200size");
1236 case VPSIZ: /* vpix structure size */
1237 if (dgap_checknode(p))
1240 p->next = kzalloc(sizeof(struct cnode), GFP_KERNEL);
1247 s = dgap_getword(in);
1249 pr_err("unexpected end of file");
1252 if (kstrtol(s, 0, &p->u.vpixsize)) {
1253 pr_err("bad number for vpixsize");
1261 static void dgap_cleanup_nodes(void)
1268 struct cnode *tmp = p->next;
1270 if (p->type == NULLNODE) {
1277 kfree(p->u.board.addrstr);
1278 kfree(p->u.board.pcibusstr);
1279 kfree(p->u.board.pcislotstr);
1280 kfree(p->u.board.method);
1283 kfree(p->u.conc.id);
1284 kfree(p->u.conc.connect);
1287 kfree(p->u.module.id);
1290 kfree(p->u.ttyname);
1296 kfree(p->u.line.cable);
1299 kfree(p->u.printname);
1303 kfree(p->u.board.status);
1310 * Retrives the current custom baud rate from FEP memory,
1311 * and returns it back to the user.
1312 * Returns 0 on error.
1314 static uint dgap_get_custom_baud(struct channel_t *ch)
1319 if (!ch || ch->magic != DGAP_CHANNEL_MAGIC)
1322 if (!ch->ch_bd || ch->ch_bd->magic != DGAP_BOARD_MAGIC)
1325 if (!(ch->ch_bd->bd_flags & BD_FEP5PLUS))
1328 vaddr = ch->ch_bd->re_map_membase;
1334 * Go get from fep mem, what the fep
1335 * believes the custom baud rate is.
1337 offset = (ioread16(vaddr + ECS_SEG) << 4) + (ch->ch_portnum * 0x28)
1340 return readw(vaddr + offset);
1346 static int dgap_remap(struct board_t *brd)
1348 if (!brd || brd->magic != DGAP_BOARD_MAGIC)
1351 if (!request_mem_region(brd->membase, 0x200000, "dgap"))
1354 if (!request_mem_region(brd->membase + PCI_IO_OFFSET, 0x200000, "dgap"))
1357 brd->re_map_membase = ioremap(brd->membase, 0x200000);
1358 if (!brd->re_map_membase)
1361 brd->re_map_port = ioremap((brd->membase + PCI_IO_OFFSET), 0x200000);
1362 if (!brd->re_map_port)
1363 goto err_remap_port;
1368 iounmap(brd->re_map_membase);
1370 release_mem_region(brd->membase + PCI_IO_OFFSET, 0x200000);
1372 release_mem_region(brd->membase, 0x200000);
1377 static void dgap_unmap(struct board_t *brd)
1379 iounmap(brd->re_map_port);
1380 iounmap(brd->re_map_membase);
1381 release_mem_region(brd->membase + PCI_IO_OFFSET, 0x200000);
1382 release_mem_region(brd->membase, 0x200000);
1386 * dgap_parity_scan()
1388 * Convert the FEP5 way of reporting parity errors and breaks into
1389 * the Linux line discipline way.
1391 static void dgap_parity_scan(struct channel_t *ch, unsigned char *cbuf,
1392 unsigned char *fbuf, int *len)
1396 unsigned char *in, *cout, *fout;
1403 if (!ch || ch->magic != DGAP_CHANNEL_MAGIC)
1408 switch (ch->pscan_state) {
1410 /* reset to sanity and fall through */
1411 ch->pscan_state = 0;
1414 /* No FF seen yet */
1415 if (c == (unsigned char)'\377')
1416 /* delete this character from stream */
1417 ch->pscan_state = 1;
1420 *fout++ = TTY_NORMAL;
1427 if (c == (unsigned char)'\377') {
1428 /* doubled ff, transform to single ff */
1430 *fout++ = TTY_NORMAL;
1432 ch->pscan_state = 0;
1434 /* save value examination in next state */
1435 ch->pscan_savechar = c;
1436 ch->pscan_state = 2;
1441 /* third character of ff sequence */
1445 if (ch->pscan_savechar == 0x0) {
1448 *fout++ = TTY_BREAK;
1450 ch->ch_err_parity++;
1451 *fout++ = TTY_PARITY;
1456 ch->pscan_state = 0;
1462 /*=======================================================================
1464 * dgap_input - Process received data.
1466 * ch - Pointer to channel structure.
1468 *=======================================================================*/
1470 static void dgap_input(struct channel_t *ch)
1473 struct bs_t __iomem *bs;
1474 struct tty_struct *tp;
1475 struct tty_ldisc *ld;
1489 if (!ch || ch->magic != DGAP_CHANNEL_MAGIC)
1492 tp = ch->ch_tun.un_tty;
1499 if (!bd || bd->magic != DGAP_BOARD_MAGIC)
1502 spin_lock_irqsave(&bd->bd_lock, lock_flags);
1503 spin_lock_irqsave(&ch->ch_lock, lock_flags2);
1506 * Figure the number of characters in the buffer.
1507 * Exit immediately if none.
1510 rmask = ch->ch_rsize - 1;
1512 head = readw(&bs->rx_head);
1514 tail = readw(&bs->rx_tail);
1517 data_len = (head - tail) & rmask;
1519 if (data_len == 0) {
1520 writeb(1, &bs->idata);
1521 spin_unlock_irqrestore(&ch->ch_lock, lock_flags2);
1522 spin_unlock_irqrestore(&bd->bd_lock, lock_flags);
1527 * If the device is not open, or CREAD is off, flush
1528 * input data and return immediately.
1530 if ((bd->state != BOARD_READY) || !tp ||
1531 (tp->magic != TTY_MAGIC) ||
1532 !(ch->ch_tun.un_flags & UN_ISOPEN) ||
1533 !(tp->termios.c_cflag & CREAD) ||
1534 (ch->ch_tun.un_flags & UN_CLOSING)) {
1535 writew(head, &bs->rx_tail);
1536 writeb(1, &bs->idata);
1537 spin_unlock_irqrestore(&ch->ch_lock, lock_flags2);
1538 spin_unlock_irqrestore(&bd->bd_lock, lock_flags);
1543 * If we are throttled, simply don't read any data.
1545 if (ch->ch_flags & CH_RXBLOCK) {
1546 writeb(1, &bs->idata);
1547 spin_unlock_irqrestore(&ch->ch_lock, lock_flags2);
1548 spin_unlock_irqrestore(&bd->bd_lock, lock_flags);
1555 tmpchar = readb(&bs->orun);
1557 ch->ch_err_overrun++;
1558 writeb(0, &bs->orun);
1561 /* Decide how much data we can send into the tty layer */
1562 flip_len = TTY_FLIPBUF_SIZE;
1564 /* Chop down the length, if needed */
1565 len = min(data_len, flip_len);
1566 len = min(len, (N_TTY_BUF_SIZE - 1));
1568 ld = tty_ldisc_ref(tp);
1570 #ifdef TTY_DONT_FLIP
1572 * If the DONT_FLIP flag is on, don't flush our buffer, and act
1573 * like the ld doesn't have any space to put the data right now.
1575 if (test_bit(TTY_DONT_FLIP, &tp->flags))
1580 * If we were unable to get a reference to the ld,
1581 * don't flush our buffer, and act like the ld doesn't
1582 * have any space to put the data right now.
1588 * If ld doesn't have a pointer to a receive_buf function,
1589 * flush the data, then act like the ld doesn't have any
1590 * space to put the data right now.
1592 if (!ld->ops->receive_buf) {
1593 writew(head, &bs->rx_tail);
1599 writeb(1, &bs->idata);
1600 spin_unlock_irqrestore(&ch->ch_lock, lock_flags2);
1601 spin_unlock_irqrestore(&bd->bd_lock, lock_flags);
1603 tty_ldisc_deref(ld);
1607 buf = ch->ch_bd->flipbuf;
1611 * n now contains the most amount of data we can copy,
1612 * bounded either by our buffer size or the amount
1613 * of data the card actually has pending...
1616 s = ((head >= tail) ? head : ch->ch_rsize) - tail;
1622 memcpy_fromio(buf, ch->ch_raddr + tail, s);
1628 /* Flip queue if needed */
1632 writew(tail, &bs->rx_tail);
1633 writeb(1, &bs->idata);
1634 ch->ch_rxcount += len;
1637 * If we are completely raw, we don't need to go through a lot
1638 * of the tty layers that exist.
1639 * In this case, we take the shortest and fastest route we
1640 * can to relay the data to the user.
1642 * On the other hand, if we are not raw, we need to go through
1643 * the tty layer, which has its API more well defined.
1645 if (I_PARMRK(tp) || I_BRKINT(tp) || I_INPCK(tp)) {
1646 dgap_parity_scan(ch, ch->ch_bd->flipbuf,
1647 ch->ch_bd->flipflagbuf, &len);
1649 len = tty_buffer_request_room(tp->port, len);
1650 tty_insert_flip_string_flags(tp->port, ch->ch_bd->flipbuf,
1651 ch->ch_bd->flipflagbuf, len);
1653 len = tty_buffer_request_room(tp->port, len);
1654 tty_insert_flip_string(tp->port, ch->ch_bd->flipbuf, len);
1657 spin_unlock_irqrestore(&ch->ch_lock, lock_flags2);
1658 spin_unlock_irqrestore(&bd->bd_lock, lock_flags);
1660 /* Tell the tty layer its okay to "eat" the data now */
1661 tty_flip_buffer_push(tp->port);
1664 tty_ldisc_deref(ld);
1667 static void dgap_write_wakeup(struct board_t *bd, struct channel_t *ch,
1668 struct un_t *un, u32 mask,
1669 unsigned long *irq_flags1,
1670 unsigned long *irq_flags2)
1672 if (!(un->un_flags & mask))
1675 un->un_flags &= ~mask;
1677 if (!(un->un_flags & UN_ISOPEN))
1680 if ((un->un_tty->flags & (1 << TTY_DO_WRITE_WAKEUP)) &&
1681 un->un_tty->ldisc->ops->write_wakeup) {
1682 spin_unlock_irqrestore(&ch->ch_lock, *irq_flags2);
1683 spin_unlock_irqrestore(&bd->bd_lock, *irq_flags1);
1685 (un->un_tty->ldisc->ops->write_wakeup)(un->un_tty);
1687 spin_lock_irqsave(&bd->bd_lock, *irq_flags1);
1688 spin_lock_irqsave(&ch->ch_lock, *irq_flags2);
1690 wake_up_interruptible(&un->un_tty->write_wait);
1691 wake_up_interruptible(&un->un_flags_wait);
1694 /************************************************************************
1695 * Determines when CARRIER changes state and takes appropriate
1697 ************************************************************************/
1698 static void dgap_carrier(struct channel_t *ch)
1702 int virt_carrier = 0;
1703 int phys_carrier = 0;
1705 if (!ch || ch->magic != DGAP_CHANNEL_MAGIC)
1710 if (!bd || bd->magic != DGAP_BOARD_MAGIC)
1713 /* Make sure altpin is always set correctly */
1714 if (ch->ch_digi.digi_flags & DIGI_ALTPIN) {
1718 ch->ch_dsr = DM_DSR;
1722 if (ch->ch_mistat & D_CD(ch))
1725 if (ch->ch_digi.digi_flags & DIGI_FORCEDCD)
1728 if (ch->ch_c_cflag & CLOCAL)
1732 * Test for a VIRTUAL carrier transition to HIGH.
1734 if (((ch->ch_flags & CH_FCAR) == 0) && (virt_carrier == 1)) {
1736 * When carrier rises, wake any threads waiting
1737 * for carrier in the open routine.
1740 if (waitqueue_active(&(ch->ch_flags_wait)))
1741 wake_up_interruptible(&ch->ch_flags_wait);
1745 * Test for a PHYSICAL carrier transition to HIGH.
1747 if (((ch->ch_flags & CH_CD) == 0) && (phys_carrier == 1)) {
1749 * When carrier rises, wake any threads waiting
1750 * for carrier in the open routine.
1753 if (waitqueue_active(&(ch->ch_flags_wait)))
1754 wake_up_interruptible(&ch->ch_flags_wait);
1758 * Test for a PHYSICAL transition to low, so long as we aren't
1759 * currently ignoring physical transitions (which is what "virtual
1760 * carrier" indicates).
1762 * The transition of the virtual carrier to low really doesn't
1763 * matter... it really only means "ignore carrier state", not
1764 * "make pretend that carrier is there".
1766 if ((virt_carrier == 0) &&
1767 ((ch->ch_flags & CH_CD) != 0) &&
1768 (phys_carrier == 0)) {
1770 * When carrier drops:
1772 * Drop carrier on all open units.
1774 * Flush queues, waking up any task waiting in the
1777 * Send a hangup to the control terminal.
1779 * Enable all select calls.
1781 if (waitqueue_active(&(ch->ch_flags_wait)))
1782 wake_up_interruptible(&ch->ch_flags_wait);
1784 if (ch->ch_tun.un_open_count > 0)
1785 tty_hangup(ch->ch_tun.un_tty);
1787 if (ch->ch_pun.un_open_count > 0)
1788 tty_hangup(ch->ch_pun.un_tty);
1792 * Make sure that our cached values reflect the current reality.
1794 if (virt_carrier == 1)
1795 ch->ch_flags |= CH_FCAR;
1797 ch->ch_flags &= ~CH_FCAR;
1799 if (phys_carrier == 1)
1800 ch->ch_flags |= CH_CD;
1802 ch->ch_flags &= ~CH_CD;
1805 /*=======================================================================
1807 * dgap_event - FEP to host event processing routine.
1809 * bd - Board of current event.
1811 *=======================================================================*/
1812 static int dgap_event(struct board_t *bd)
1814 struct channel_t *ch;
1817 struct bs_t __iomem *bs;
1820 struct ev_t __iomem *eaddr;
1827 if (!bd || bd->magic != DGAP_BOARD_MAGIC)
1830 spin_lock_irqsave(&bd->bd_lock, lock_flags);
1832 vaddr = bd->re_map_membase;
1835 spin_unlock_irqrestore(&bd->bd_lock, lock_flags);
1839 eaddr = (struct ev_t __iomem *)(vaddr + EVBUF);
1841 /* Get our head and tail */
1842 head = readw(&eaddr->ev_head);
1843 tail = readw(&eaddr->ev_tail);
1846 * Forget it if pointers out of range.
1849 if (head >= EVMAX - EVSTART || tail >= EVMAX - EVSTART ||
1850 (head | tail) & 03) {
1851 /* Let go of board lock */
1852 spin_unlock_irqrestore(&bd->bd_lock, lock_flags);
1857 * Loop to process all the events in the buffer.
1859 while (tail != head) {
1861 * Get interrupt information.
1864 event = bd->re_map_membase + tail + EVSTART;
1866 port = ioread8(event);
1867 reason = ioread8(event + 1);
1868 modem = ioread8(event + 2);
1872 * Make sure the interrupt is valid.
1874 if (port >= bd->nasync)
1877 if (!(reason & (IFMODEM | IFBREAK | IFTLW | IFTEM | IFDATA)))
1880 ch = bd->channels[port];
1882 if (!ch || ch->magic != DGAP_CHANNEL_MAGIC)
1886 * If we have made it here, the event was valid.
1887 * Lock down the channel.
1889 spin_lock_irqsave(&ch->ch_lock, lock_flags2);
1894 spin_unlock_irqrestore(&ch->ch_lock, lock_flags2);
1899 * Process received data.
1901 if (reason & IFDATA) {
1903 * ALL LOCKS *MUST* BE DROPPED BEFORE CALLING INPUT!
1904 * input could send some data to ld, which in turn
1905 * could do a callback to one of our other functions.
1907 spin_unlock_irqrestore(&ch->ch_lock, lock_flags2);
1908 spin_unlock_irqrestore(&bd->bd_lock, lock_flags);
1912 spin_lock_irqsave(&bd->bd_lock, lock_flags);
1913 spin_lock_irqsave(&ch->ch_lock, lock_flags2);
1915 if (ch->ch_flags & CH_RACTIVE)
1916 ch->ch_flags |= CH_RENABLE;
1918 writeb(1, &bs->idata);
1920 if (ch->ch_flags & CH_RWAIT) {
1921 ch->ch_flags &= ~CH_RWAIT;
1923 wake_up_interruptible
1924 (&ch->ch_tun.un_flags_wait);
1929 * Process Modem change signals.
1931 if (reason & IFMODEM) {
1932 ch->ch_mistat = modem;
1939 if (reason & IFBREAK) {
1940 if (ch->ch_tun.un_tty) {
1941 /* A break has been indicated */
1943 tty_buffer_request_room
1944 (ch->ch_tun.un_tty->port, 1);
1945 tty_insert_flip_char(ch->ch_tun.un_tty->port,
1947 tty_flip_buffer_push(ch->ch_tun.un_tty->port);
1952 * Process Transmit low.
1954 if (reason & IFTLW) {
1955 dgap_write_wakeup(bd, ch, &ch->ch_tun, UN_LOW,
1956 &lock_flags, &lock_flags2);
1957 dgap_write_wakeup(bd, ch, &ch->ch_pun, UN_LOW,
1958 &lock_flags, &lock_flags2);
1959 if (ch->ch_flags & CH_WLOW) {
1960 ch->ch_flags &= ~CH_WLOW;
1961 wake_up_interruptible(&ch->ch_flags_wait);
1966 * Process Transmit empty.
1968 if (reason & IFTEM) {
1969 dgap_write_wakeup(bd, ch, &ch->ch_tun, UN_EMPTY,
1970 &lock_flags, &lock_flags2);
1971 dgap_write_wakeup(bd, ch, &ch->ch_pun, UN_EMPTY,
1972 &lock_flags, &lock_flags2);
1973 if (ch->ch_flags & CH_WEMPTY) {
1974 ch->ch_flags &= ~CH_WEMPTY;
1975 wake_up_interruptible(&ch->ch_flags_wait);
1979 spin_unlock_irqrestore(&ch->ch_lock, lock_flags2);
1982 tail = (tail + 4) & (EVMAX - EVSTART - 4);
1985 writew(tail, &eaddr->ev_tail);
1986 spin_unlock_irqrestore(&bd->bd_lock, lock_flags);
1992 * Our board poller function.
1994 static void dgap_poll_tasklet(unsigned long data)
1996 struct board_t *bd = (struct board_t *)data;
1998 char __iomem *vaddr;
2001 if (!bd || (bd->magic != DGAP_BOARD_MAGIC))
2004 if (bd->inhibit_poller)
2007 spin_lock_irqsave(&bd->bd_lock, lock_flags);
2009 vaddr = bd->re_map_membase;
2012 * If board is ready, parse deeper to see if there is anything to do.
2014 if (bd->state == BOARD_READY) {
2015 struct ev_t __iomem *eaddr;
2017 if (!bd->re_map_membase) {
2018 spin_unlock_irqrestore(&bd->bd_lock, lock_flags);
2021 if (!bd->re_map_port) {
2022 spin_unlock_irqrestore(&bd->bd_lock, lock_flags);
2029 eaddr = (struct ev_t __iomem *)(vaddr + EVBUF);
2031 /* Get our head and tail */
2032 head = readw(&eaddr->ev_head);
2033 tail = readw(&eaddr->ev_tail);
2036 * If there is an event pending. Go service it.
2039 spin_unlock_irqrestore(&bd->bd_lock, lock_flags);
2041 spin_lock_irqsave(&bd->bd_lock, lock_flags);
2046 * If board is doing interrupts, ACK the interrupt.
2048 if (bd->intr_running)
2049 readb(bd->re_map_port + 2);
2051 spin_unlock_irqrestore(&bd->bd_lock, lock_flags);
2055 spin_unlock_irqrestore(&bd->bd_lock, lock_flags);
2059 * dgap_found_board()
2061 * A board has been found, init it.
2063 static struct board_t *dgap_found_board(struct pci_dev *pdev, int id,
2066 struct board_t *brd;
2067 unsigned int pci_irq;
2071 /* get the board structure and prep it */
2072 brd = kzalloc(sizeof(struct board_t), GFP_KERNEL);
2074 return ERR_PTR(-ENOMEM);
2076 /* store the info for the board we've found */
2077 brd->magic = DGAP_BOARD_MAGIC;
2078 brd->boardnum = boardnum;
2079 brd->vendor = dgap_pci_tbl[id].vendor;
2080 brd->device = dgap_pci_tbl[id].device;
2082 brd->pci_bus = pdev->bus->number;
2083 brd->pci_slot = PCI_SLOT(pdev->devfn);
2084 brd->name = dgap_ids[id].name;
2085 brd->maxports = dgap_ids[id].maxports;
2086 brd->type = dgap_ids[id].config_type;
2087 brd->dpatype = dgap_ids[id].dpatype;
2088 brd->dpastatus = BD_NOFEP;
2089 init_waitqueue_head(&brd->state_wait);
2091 spin_lock_init(&brd->bd_lock);
2093 brd->inhibit_poller = FALSE;
2094 brd->wait_for_bios = 0;
2095 brd->wait_for_fep = 0;
2097 for (i = 0; i < MAXPORTS; i++)
2098 brd->channels[i] = NULL;
2100 /* store which card & revision we have */
2101 pci_read_config_word(pdev, PCI_SUBSYSTEM_VENDOR_ID, &brd->subvendor);
2102 pci_read_config_word(pdev, PCI_SUBSYSTEM_ID, &brd->subdevice);
2103 pci_read_config_byte(pdev, PCI_REVISION_ID, &brd->rev);
2105 pci_irq = pdev->irq;
2108 /* get the PCI Base Address Registers */
2110 /* Xr Jupiter and EPC use BAR 2 */
2111 if (brd->device == PCI_DEV_XRJ_DID || brd->device == PCI_DEV_EPCJ_DID) {
2112 brd->membase = pci_resource_start(pdev, 2);
2113 brd->membase_end = pci_resource_end(pdev, 2);
2115 /* Everyone else uses BAR 0 */
2117 brd->membase = pci_resource_start(pdev, 0);
2118 brd->membase_end = pci_resource_end(pdev, 0);
2121 if (!brd->membase) {
2126 if (brd->membase & 1)
2129 brd->membase &= ~15;
2132 * On the PCI boards, there is no IO space allocated
2133 * The I/O registers will be in the first 3 bytes of the
2134 * upper 2MB of the 4MB memory space. The board memory
2135 * will be mapped into the low 2MB of the 4MB memory space
2137 brd->port = brd->membase + PCI_IO_OFFSET;
2138 brd->port_end = brd->port + PCI_IO_SIZE_DGAP;
2141 * Special initialization for non-PLX boards
2143 if (brd->device != PCI_DEV_XRJ_DID && brd->device != PCI_DEV_EPCJ_DID) {
2146 pci_write_config_byte(pdev, 0x40, 0);
2147 pci_write_config_byte(pdev, 0x46, 0);
2149 /* Limit burst length to 2 doubleword transactions */
2150 pci_write_config_byte(pdev, 0x42, 1);
2153 * Enable IO and mem if not already done.
2154 * This was needed for support on Itanium.
2156 pci_read_config_word(pdev, PCI_COMMAND, &cmd);
2157 cmd |= (PCI_COMMAND_IO | PCI_COMMAND_MEMORY);
2158 pci_write_config_word(pdev, PCI_COMMAND, cmd);
2161 /* init our poll helper tasklet */
2162 tasklet_init(&brd->helper_tasklet, dgap_poll_tasklet,
2163 (unsigned long)brd);
2165 ret = dgap_remap(brd);
2169 pr_info("dgap: board %d: %s (rev %d), irq %ld\n",
2170 boardnum, brd->name, brd->rev, brd->irq);
2177 return ERR_PTR(ret);
2183 * Driver interrupt handler.
2185 static irqreturn_t dgap_intr(int irq, void *voidbrd)
2187 struct board_t *brd = voidbrd;
2193 * Check to make sure its for us.
2195 if (brd->magic != DGAP_BOARD_MAGIC)
2201 * Schedule tasklet to run at a better time.
2203 tasklet_schedule(&brd->helper_tasklet);
2207 /*****************************************************************************
2227 * As each timer expires, it determines (a) whether the "transmit"
2228 * waiter needs to be woken up, and (b) whether the poller needs to
2231 ******************************************************************************/
2233 static void dgap_poll_handler(ulong dummy)
2236 struct board_t *brd;
2237 unsigned long lock_flags;
2240 dgap_poll_counter++;
2243 * Do not start the board state machine until
2244 * driver tells us its up and running, and has
2245 * everything it needs.
2247 if (dgap_driver_state != DRIVER_READY)
2248 goto schedule_poller;
2251 * If we have just 1 board, or the system is not SMP,
2252 * then use the typical old style poller.
2253 * Otherwise, use our new tasklet based poller, which should
2254 * speed things up for multiple boards.
2256 if ((dgap_numboards == 1) || (num_online_cpus() <= 1)) {
2257 for (i = 0; i < dgap_numboards; i++) {
2258 brd = dgap_board[i];
2260 if (brd->state == BOARD_FAILED)
2262 if (!brd->intr_running)
2263 /* Call the real board poller directly */
2264 dgap_poll_tasklet((unsigned long)brd);
2268 * Go thru each board, kicking off a
2269 * tasklet for each if needed
2271 for (i = 0; i < dgap_numboards; i++) {
2272 brd = dgap_board[i];
2275 * Attempt to grab the board lock.
2277 * If we can't get it, no big deal, the next poll
2278 * will get it. Basically, I just really don't want
2279 * to spin in here, because I want to kick off my
2280 * tasklets as fast as I can, and then get out the
2283 if (!spin_trylock(&brd->bd_lock))
2287 * If board is in a failed state, don't bother
2288 * scheduling a tasklet
2290 if (brd->state == BOARD_FAILED) {
2291 spin_unlock(&brd->bd_lock);
2295 /* Schedule a poll helper task */
2296 if (!brd->intr_running)
2297 tasklet_schedule(&brd->helper_tasklet);
2300 * Can't do DGAP_UNLOCK here, as we don't have
2301 * lock_flags because we did a trylock above.
2303 spin_unlock(&brd->bd_lock);
2310 * Schedule ourself back at the nominal wakeup interval.
2312 spin_lock_irqsave(&dgap_poll_lock, lock_flags);
2313 dgap_poll_time += dgap_jiffies_from_ms(dgap_poll_tick);
2315 new_time = dgap_poll_time - jiffies;
2317 if ((ulong)new_time >= 2 * dgap_poll_tick) {
2319 jiffies + dgap_jiffies_from_ms(dgap_poll_tick);
2322 dgap_poll_timer.function = dgap_poll_handler;
2323 dgap_poll_timer.data = 0;
2324 dgap_poll_timer.expires = dgap_poll_time;
2325 spin_unlock_irqrestore(&dgap_poll_lock, lock_flags);
2327 if (!dgap_poll_stop)
2328 add_timer(&dgap_poll_timer);
2331 /*=======================================================================
2333 * dgap_cmdb - Sends a 2 byte command to the FEP.
2335 * ch - Pointer to channel structure.
2336 * cmd - Command to be sent.
2337 * byte1 - Integer containing first byte to be sent.
2338 * byte2 - Integer containing second byte to be sent.
2339 * ncmds - Wait until ncmds or fewer cmds are left
2340 * in the cmd buffer before returning.
2342 *=======================================================================*/
2343 static void dgap_cmdb(struct channel_t *ch, u8 cmd, u8 byte1,
2344 u8 byte2, uint ncmds)
2346 char __iomem *vaddr;
2347 struct __iomem cm_t *cm_addr;
2353 if (!ch || ch->magic != DGAP_CHANNEL_MAGIC)
2357 * Check if board is still alive.
2359 if (ch->ch_bd->state == BOARD_FAILED)
2363 * Make sure the pointers are in range before
2364 * writing to the FEP memory.
2366 vaddr = ch->ch_bd->re_map_membase;
2371 cm_addr = (struct cm_t __iomem *)(vaddr + CMDBUF);
2372 head = readw(&cm_addr->cm_head);
2375 * Forget it if pointers out of range.
2377 if (head >= (CMDMAX - CMDSTART) || (head & 03)) {
2378 ch->ch_bd->state = BOARD_FAILED;
2383 * Put the data in the circular command buffer.
2385 writeb(cmd, (vaddr + head + CMDSTART + 0));
2386 writeb((u8)ch->ch_portnum, (vaddr + head + CMDSTART + 1));
2387 writeb(byte1, (vaddr + head + CMDSTART + 2));
2388 writeb(byte2, (vaddr + head + CMDSTART + 3));
2390 head = (head + 4) & (CMDMAX - CMDSTART - 4);
2392 writew(head, &cm_addr->cm_head);
2395 * Wait if necessary before updating the head
2396 * pointer to limit the number of outstanding
2397 * commands to the FEP. If the time spent waiting
2398 * is outlandish, declare the FEP dead.
2400 for (count = dgap_count ;;) {
2401 head = readw(&cm_addr->cm_head);
2402 tail = readw(&cm_addr->cm_tail);
2404 n = (head - tail) & (CMDMAX - CMDSTART - 4);
2406 if (n <= ncmds * sizeof(struct cm_t))
2410 ch->ch_bd->state = BOARD_FAILED;
2417 /*=======================================================================
2419 * dgap_cmdw - Sends a 1 word command to the FEP.
2421 * ch - Pointer to channel structure.
2422 * cmd - Command to be sent.
2423 * word - Integer containing word to be sent.
2424 * ncmds - Wait until ncmds or fewer cmds are left
2425 * in the cmd buffer before returning.
2427 *=======================================================================*/
2428 static void dgap_cmdw(struct channel_t *ch, u8 cmd, u16 word, uint ncmds)
2430 char __iomem *vaddr;
2431 struct __iomem cm_t *cm_addr;
2437 if (!ch || ch->magic != DGAP_CHANNEL_MAGIC)
2441 * Check if board is still alive.
2443 if (ch->ch_bd->state == BOARD_FAILED)
2447 * Make sure the pointers are in range before
2448 * writing to the FEP memory.
2450 vaddr = ch->ch_bd->re_map_membase;
2454 cm_addr = (struct cm_t __iomem *)(vaddr + CMDBUF);
2455 head = readw(&cm_addr->cm_head);
2458 * Forget it if pointers out of range.
2460 if (head >= (CMDMAX - CMDSTART) || (head & 03)) {
2461 ch->ch_bd->state = BOARD_FAILED;
2466 * Put the data in the circular command buffer.
2468 writeb(cmd, (vaddr + head + CMDSTART + 0));
2469 writeb((u8)ch->ch_portnum, (vaddr + head + CMDSTART + 1));
2470 writew((u16)word, (vaddr + head + CMDSTART + 2));
2472 head = (head + 4) & (CMDMAX - CMDSTART - 4);
2474 writew(head, &cm_addr->cm_head);
2477 * Wait if necessary before updating the head
2478 * pointer to limit the number of outstanding
2479 * commands to the FEP. If the time spent waiting
2480 * is outlandish, declare the FEP dead.
2482 for (count = dgap_count ;;) {
2483 head = readw(&cm_addr->cm_head);
2484 tail = readw(&cm_addr->cm_tail);
2486 n = (head - tail) & (CMDMAX - CMDSTART - 4);
2488 if (n <= ncmds * sizeof(struct cm_t))
2492 ch->ch_bd->state = BOARD_FAILED;
2499 /*=======================================================================
2501 * dgap_cmdw_ext - Sends a extended word command to the FEP.
2503 * ch - Pointer to channel structure.
2504 * cmd - Command to be sent.
2505 * word - Integer containing word to be sent.
2506 * ncmds - Wait until ncmds or fewer cmds are left
2507 * in the cmd buffer before returning.
2509 *=======================================================================*/
2510 static void dgap_cmdw_ext(struct channel_t *ch, u16 cmd, u16 word, uint ncmds)
2512 char __iomem *vaddr;
2513 struct __iomem cm_t *cm_addr;
2519 if (!ch || ch->magic != DGAP_CHANNEL_MAGIC)
2523 * Check if board is still alive.
2525 if (ch->ch_bd->state == BOARD_FAILED)
2529 * Make sure the pointers are in range before
2530 * writing to the FEP memory.
2532 vaddr = ch->ch_bd->re_map_membase;
2536 cm_addr = (struct cm_t __iomem *)(vaddr + CMDBUF);
2537 head = readw(&cm_addr->cm_head);
2540 * Forget it if pointers out of range.
2542 if (head >= (CMDMAX - CMDSTART) || (head & 03)) {
2543 ch->ch_bd->state = BOARD_FAILED;
2548 * Put the data in the circular command buffer.
2551 /* Write an FF to tell the FEP that we want an extended command */
2552 writeb((u8)0xff, (vaddr + head + CMDSTART + 0));
2554 writeb((u8)ch->ch_portnum, (vaddr + head + CMDSTART + 1));
2555 writew((u16)cmd, (vaddr + head + CMDSTART + 2));
2558 * If the second part of the command won't fit,
2559 * put it at the beginning of the circular buffer.
2561 if (((head + 4) >= ((CMDMAX - CMDSTART)) || (head & 03)))
2562 writew((u16)word, (vaddr + CMDSTART));
2564 writew((u16)word, (vaddr + head + CMDSTART + 4));
2566 head = (head + 8) & (CMDMAX - CMDSTART - 4);
2568 writew(head, &cm_addr->cm_head);
2571 * Wait if necessary before updating the head
2572 * pointer to limit the number of outstanding
2573 * commands to the FEP. If the time spent waiting
2574 * is outlandish, declare the FEP dead.
2576 for (count = dgap_count ;;) {
2577 head = readw(&cm_addr->cm_head);
2578 tail = readw(&cm_addr->cm_tail);
2580 n = (head - tail) & (CMDMAX - CMDSTART - 4);
2582 if (n <= ncmds * sizeof(struct cm_t))
2586 ch->ch_bd->state = BOARD_FAILED;
2593 /*=======================================================================
2595 * dgap_wmove - Write data to FEP buffer.
2597 * ch - Pointer to channel structure.
2598 * buf - Pointer to characters to be moved.
2599 * cnt - Number of characters to move.
2601 *=======================================================================*/
2602 static void dgap_wmove(struct channel_t *ch, char *buf, uint cnt)
2605 char __iomem *taddr;
2606 struct bs_t __iomem *bs;
2609 if (!ch || ch->magic != DGAP_CHANNEL_MAGIC)
2616 head = readw(&bs->tx_head);
2619 * If pointers are out of range, just return.
2621 if ((cnt > ch->ch_tsize) ||
2622 (unsigned)(head - ch->ch_tstart) >= ch->ch_tsize)
2626 * If the write wraps over the top of the circular buffer,
2627 * move the portion up to the wrap point, and reset the
2628 * pointers to the bottom.
2630 n = ch->ch_tstart + ch->ch_tsize - head;
2634 taddr = ch->ch_taddr + head;
2635 memcpy_toio(taddr, buf, n);
2636 head = ch->ch_tstart;
2641 * Move rest of data.
2643 taddr = ch->ch_taddr + head;
2645 memcpy_toio(taddr, buf, n);
2648 writew(head, &bs->tx_head);
2652 * Calls the firmware to reset this channel.
2654 static void dgap_firmware_reset_port(struct channel_t *ch)
2656 dgap_cmdb(ch, CHRESET, 0, 0, 0);
2659 * Now that the channel is reset, we need to make sure
2660 * all the current settings get reapplied to the port
2663 * So we will set the driver's cache of firmware
2664 * settings all to 0, and then call param.
2666 ch->ch_fepiflag = 0;
2667 ch->ch_fepcflag = 0;
2668 ch->ch_fepoflag = 0;
2669 ch->ch_fepstartc = 0;
2670 ch->ch_fepstopc = 0;
2671 ch->ch_fepastartc = 0;
2672 ch->ch_fepastopc = 0;
2677 /*=======================================================================
2679 * dgap_param - Set Digi parameters.
2681 * struct tty_struct * - TTY for port.
2683 *=======================================================================*/
2684 static int dgap_param(struct channel_t *ch, struct board_t *bd, u32 un_type)
2693 * If baud rate is zero, flush queues, and set mval to drop DTR.
2695 if ((ch->ch_c_cflag & (CBAUD)) == 0) {
2697 head = readw(&ch->ch_bs->rx_head);
2698 writew(head, &ch->ch_bs->rx_tail);
2701 head = readw(&ch->ch_bs->tx_head);
2702 writew(head, &ch->ch_bs->tx_tail);
2704 ch->ch_flags |= (CH_BAUD0);
2706 /* Drop RTS and DTR */
2707 ch->ch_mval &= ~(D_RTS(ch) | D_DTR(ch));
2708 mval = D_DTR(ch) | D_RTS(ch);
2709 ch->ch_baud_info = 0;
2711 } else if (ch->ch_custom_speed && (bd->bd_flags & BD_FEP5PLUS)) {
2713 * Tell the fep to do the command
2716 dgap_cmdw_ext(ch, 0xff01, ch->ch_custom_speed, 0);
2719 * Now go get from fep mem, what the fep
2720 * believes the custom baud rate is.
2722 ch->ch_custom_speed = dgap_get_custom_baud(ch);
2723 ch->ch_baud_info = ch->ch_custom_speed;
2725 /* Handle transition from B0 */
2726 if (ch->ch_flags & CH_BAUD0) {
2727 ch->ch_flags &= ~(CH_BAUD0);
2728 ch->ch_mval |= (D_RTS(ch) | D_DTR(ch));
2730 mval = D_DTR(ch) | D_RTS(ch);
2734 * Set baud rate, character size, and parity.
2742 ulong bauds[4][16] = {
2746 600, 1200, 1800, 2400,
2747 4800, 9600, 19200, 38400 },
2748 { /* slowbaud & CBAUDEX */
2749 0, 57600, 115200, 230400,
2750 460800, 150, 200, 921600,
2751 600, 1200, 1800, 2400,
2752 4800, 9600, 19200, 38400 },
2754 0, 57600, 76800, 115200,
2755 14400, 57600, 230400, 76800,
2756 115200, 230400, 28800, 460800,
2757 921600, 9600, 19200, 38400 },
2758 { /* fastbaud & CBAUDEX */
2759 0, 57600, 115200, 230400,
2760 460800, 150, 200, 921600,
2761 600, 1200, 1800, 2400,
2762 4800, 9600, 19200, 38400 }
2766 * Only use the TXPrint baud rate if the
2767 * terminal unit is NOT open
2769 if (!(ch->ch_tun.un_flags & UN_ISOPEN) &&
2770 un_type == DGAP_PRINT)
2771 baud = C_BAUD(ch->ch_pun.un_tty) & 0xff;
2773 baud = C_BAUD(ch->ch_tun.un_tty) & 0xff;
2775 if (ch->ch_c_cflag & CBAUDEX)
2778 if (ch->ch_digi.digi_flags & DIGI_FAST)
2783 if ((iindex >= 0) && (iindex < 4) &&
2784 (jindex >= 0) && (jindex < 16))
2785 baud = bauds[iindex][jindex];
2792 ch->ch_baud_info = baud;
2795 * CBAUD has bit position 0x1000 set these days to
2796 * indicate Linux baud rate remap.
2797 * We use a different bit assignment for high speed.
2798 * Clear this bit out while grabbing the parts of
2801 cflag = ch->ch_c_cflag & ((CBAUD ^ CBAUDEX) | PARODD | PARENB |
2805 * HUPCL bit is used by FEP to indicate fast baud
2806 * table is to be used.
2808 if ((ch->ch_digi.digi_flags & DIGI_FAST) ||
2809 (ch->ch_c_cflag & CBAUDEX))
2812 if ((ch->ch_c_cflag & CBAUDEX) &&
2813 !(ch->ch_digi.digi_flags & DIGI_FAST)) {
2815 * The below code is trying to guarantee that only
2816 * baud rates 115200, 230400, 460800, 921600 are
2817 * remapped. We use exclusive or because the various
2818 * baud rates share common bit positions and therefore
2819 * can't be tested for easily.
2821 tcflag_t tcflag = (ch->ch_c_cflag & CBAUD) | CBAUDEX;
2825 * Map high speed requests to index
2826 * into FEP's baud table
2856 cflag = (cflag & ~(CBAUD | CBAUDEX)) | baudpart;
2861 if (cflag != ch->ch_fepcflag) {
2862 ch->ch_fepcflag = (u16)(cflag & 0xffff);
2865 * Okay to have channel and board
2866 * locks held calling this
2868 dgap_cmdw(ch, SCFLAG, (u16)cflag, 0);
2871 /* Handle transition from B0 */
2872 if (ch->ch_flags & CH_BAUD0) {
2873 ch->ch_flags &= ~(CH_BAUD0);
2874 ch->ch_mval |= (D_RTS(ch) | D_DTR(ch));
2876 mval = D_DTR(ch) | D_RTS(ch);
2882 iflag = ch->ch_c_iflag & (IGNBRK | BRKINT | IGNPAR | PARMRK |
2883 INPCK | ISTRIP | IXON | IXANY | IXOFF);
2885 if ((ch->ch_startc == _POSIX_VDISABLE) ||
2886 (ch->ch_stopc == _POSIX_VDISABLE)) {
2887 iflag &= ~(IXON | IXOFF);
2888 ch->ch_c_iflag &= ~(IXON | IXOFF);
2892 * Only the IBM Xr card can switch between
2893 * 232 and 422 modes on the fly
2895 if (bd->device == PCI_DEV_XR_IBM_DID) {
2896 if (ch->ch_digi.digi_flags & DIGI_422)
2897 dgap_cmdb(ch, SCOMMODE, MODE_422, 0, 0);
2899 dgap_cmdb(ch, SCOMMODE, MODE_232, 0, 0);
2902 if (ch->ch_digi.digi_flags & DIGI_ALTPIN)
2905 if (iflag != ch->ch_fepiflag) {
2906 ch->ch_fepiflag = iflag;
2908 /* Okay to have channel and board locks held calling this */
2909 dgap_cmdw(ch, SIFLAG, (u16)ch->ch_fepiflag, 0);
2913 * Select hardware handshaking.
2917 if (ch->ch_c_cflag & CRTSCTS)
2918 hflow |= (D_RTS(ch) | D_CTS(ch));
2919 if (ch->ch_digi.digi_flags & RTSPACE)
2921 if (ch->ch_digi.digi_flags & DTRPACE)
2923 if (ch->ch_digi.digi_flags & CTSPACE)
2925 if (ch->ch_digi.digi_flags & DSRPACE)
2927 if (ch->ch_digi.digi_flags & DCDPACE)
2930 if (hflow != ch->ch_hflow) {
2931 ch->ch_hflow = hflow;
2933 /* Okay to have channel and board locks held calling this */
2934 dgap_cmdb(ch, SHFLOW, (u8)hflow, 0xff, 0);
2938 * Set RTS and/or DTR Toggle if needed,
2939 * but only if product is FEP5+ based.
2941 if (bd->bd_flags & BD_FEP5PLUS) {
2944 if (ch->ch_digi.digi_flags & DIGI_RTS_TOGGLE)
2945 hflow2 |= (D_RTS(ch));
2946 if (ch->ch_digi.digi_flags & DIGI_DTR_TOGGLE)
2947 hflow2 |= (D_DTR(ch));
2949 dgap_cmdw_ext(ch, 0xff03, hflow2, 0);
2953 * Set modem control lines.
2956 mval ^= ch->ch_mforce & (mval ^ ch->ch_mval);
2958 if (ch->ch_mostat ^ mval) {
2959 ch->ch_mostat = mval;
2961 /* Okay to have channel and board locks held calling this */
2962 dgap_cmdb(ch, SMODEM, (u8)mval, D_RTS(ch) | D_DTR(ch), 0);
2966 * Read modem signals, and then call carrier function.
2968 ch->ch_mistat = readb(&ch->ch_bs->m_stat);
2972 * Set the start and stop characters.
2974 if (ch->ch_startc != ch->ch_fepstartc ||
2975 ch->ch_stopc != ch->ch_fepstopc) {
2976 ch->ch_fepstartc = ch->ch_startc;
2977 ch->ch_fepstopc = ch->ch_stopc;
2979 /* Okay to have channel and board locks held calling this */
2980 dgap_cmdb(ch, SFLOWC, ch->ch_fepstartc, ch->ch_fepstopc, 0);
2984 * Set the Auxiliary start and stop characters.
2986 if (ch->ch_astartc != ch->ch_fepastartc ||
2987 ch->ch_astopc != ch->ch_fepastopc) {
2988 ch->ch_fepastartc = ch->ch_astartc;
2989 ch->ch_fepastopc = ch->ch_astopc;
2991 /* Okay to have channel and board locks held calling this */
2992 dgap_cmdb(ch, SAFLOWC, ch->ch_fepastartc, ch->ch_fepastopc, 0);
2999 * dgap_block_til_ready()
3001 * Wait for DCD, if needed.
3003 static int dgap_block_til_ready(struct tty_struct *tty, struct file *file,
3004 struct channel_t *ch)
3010 int sleep_on_un_flags;
3012 if (!tty || tty->magic != TTY_MAGIC || !file || !ch ||
3013 ch->magic != DGAP_CHANNEL_MAGIC)
3016 un = tty->driver_data;
3017 if (!un || un->magic != DGAP_UNIT_MAGIC)
3020 spin_lock_irqsave(&ch->ch_lock, lock_flags);
3026 sleep_on_un_flags = 0;
3029 * If board has failed somehow during our sleep,
3032 if (ch->ch_bd->state == BOARD_FAILED) {
3037 /* If tty was hung up, break out of loop and set error. */
3038 if (tty_hung_up_p(file)) {
3044 * If either unit is in the middle of the fragile part of close,
3045 * we just cannot touch the channel safely.
3046 * Go back to sleep, knowing that when the channel can be
3047 * touched safely, the close routine will signal the
3048 * ch_wait_flags to wake us back up.
3050 if (!((ch->ch_tun.un_flags | ch->ch_pun.un_flags) &
3053 * Our conditions to leave cleanly and happily:
3054 * 1) NONBLOCKING on the tty is set.
3056 * 3) DCD (fake or real) is active.
3059 if (file->f_flags & O_NONBLOCK)
3062 if (tty->flags & (1 << TTY_IO_ERROR))
3065 if (ch->ch_flags & CH_CD)
3068 if (ch->ch_flags & CH_FCAR)
3071 sleep_on_un_flags = 1;
3075 * If there is a signal pending, the user probably
3076 * interrupted (ctrl-c) us.
3077 * Leave loop with error set.
3079 if (signal_pending(current)) {
3080 retval = -ERESTARTSYS;
3085 * Store the flags before we let go of channel lock
3087 if (sleep_on_un_flags)
3088 old_flags = ch->ch_tun.un_flags | ch->ch_pun.un_flags;
3090 old_flags = ch->ch_flags;
3093 * Let go of channel lock before calling schedule.
3094 * Our poller will get any FEP events and wake us up when DCD
3095 * eventually goes active.
3098 spin_unlock_irqrestore(&ch->ch_lock, lock_flags);
3101 * Wait for something in the flags to change
3102 * from the current value.
3104 if (sleep_on_un_flags) {
3105 retval = wait_event_interruptible(un->un_flags_wait,
3106 (old_flags != (ch->ch_tun.un_flags |
3107 ch->ch_pun.un_flags)));
3109 retval = wait_event_interruptible(ch->ch_flags_wait,
3110 (old_flags != ch->ch_flags));
3114 * We got woken up for some reason.
3115 * Before looping around, grab our channel lock.
3117 spin_lock_irqsave(&ch->ch_lock, lock_flags);
3122 spin_unlock_irqrestore(&ch->ch_lock, lock_flags);
3128 * dgap_tty_flush_buffer()
3130 * Flush Tx buffer (make in == out)
3132 static void dgap_tty_flush_buffer(struct tty_struct *tty)
3135 struct channel_t *ch;
3141 if (!tty || tty->magic != TTY_MAGIC)
3144 un = tty->driver_data;
3145 if (!un || un->magic != DGAP_UNIT_MAGIC)
3149 if (!ch || ch->magic != DGAP_CHANNEL_MAGIC)
3153 if (!bd || bd->magic != DGAP_BOARD_MAGIC)
3156 spin_lock_irqsave(&bd->bd_lock, lock_flags);
3157 spin_lock_irqsave(&ch->ch_lock, lock_flags2);
3159 ch->ch_flags &= ~CH_STOP;
3160 head = readw(&ch->ch_bs->tx_head);
3161 dgap_cmdw(ch, FLUSHTX, (u16)head, 0);
3162 dgap_cmdw(ch, RESUMETX, 0, 0);
3163 if (ch->ch_tun.un_flags & (UN_LOW | UN_EMPTY)) {
3164 ch->ch_tun.un_flags &= ~(UN_LOW | UN_EMPTY);
3165 wake_up_interruptible(&ch->ch_tun.un_flags_wait);
3167 if (ch->ch_pun.un_flags & (UN_LOW | UN_EMPTY)) {
3168 ch->ch_pun.un_flags &= ~(UN_LOW | UN_EMPTY);
3169 wake_up_interruptible(&ch->ch_pun.un_flags_wait);
3172 spin_unlock_irqrestore(&ch->ch_lock, lock_flags2);
3173 spin_unlock_irqrestore(&bd->bd_lock, lock_flags);
3174 if (waitqueue_active(&tty->write_wait))
3175 wake_up_interruptible(&tty->write_wait);
3182 * Hangup the port. Like a close, but don't wait for output to drain.
3184 static void dgap_tty_hangup(struct tty_struct *tty)
3187 struct channel_t *ch;
3190 if (!tty || tty->magic != TTY_MAGIC)
3193 un = tty->driver_data;
3194 if (!un || un->magic != DGAP_UNIT_MAGIC)
3198 if (!ch || ch->magic != DGAP_CHANNEL_MAGIC)
3202 if (!bd || bd->magic != DGAP_BOARD_MAGIC)
3205 /* flush the transmit queues */
3206 dgap_tty_flush_buffer(tty);
3210 * dgap_tty_chars_in_buffer()
3212 * Return number of characters that have not been transmitted yet.
3214 * This routine is used by the line discipline to determine if there
3215 * is data waiting to be transmitted/drained/flushed or not.
3217 static int dgap_tty_chars_in_buffer(struct tty_struct *tty)
3220 struct channel_t *ch;
3222 struct bs_t __iomem *bs;
3225 u16 thead, ttail, tmask, chead, ctail;
3226 ulong lock_flags = 0;
3227 ulong lock_flags2 = 0;
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)
3248 spin_lock_irqsave(&bd->bd_lock, lock_flags);
3249 spin_lock_irqsave(&ch->ch_lock, lock_flags2);
3251 tmask = (ch->ch_tsize - 1);
3253 /* Get Transmit queue pointers */
3254 thead = readw(&bs->tx_head) & tmask;
3255 ttail = readw(&bs->tx_tail) & tmask;
3257 /* Get tbusy flag */
3258 tbusy = readb(&bs->tbusy);
3260 /* Get Command queue pointers */
3261 chead = readw(&ch->ch_cm->cm_head);
3262 ctail = readw(&ch->ch_cm->cm_tail);
3264 spin_unlock_irqrestore(&ch->ch_lock, lock_flags2);
3265 spin_unlock_irqrestore(&bd->bd_lock, lock_flags);
3268 * The only way we know for sure if there is no pending
3269 * data left to be transferred, is if:
3270 * 1) Transmit head and tail are equal (empty).
3271 * 2) Command queue head and tail are equal (empty).
3272 * 3) The "TBUSY" flag is 0. (Transmitter not busy).
3275 if ((ttail == thead) && (tbusy == 0) && (chead == ctail)) {
3279 chars = thead - ttail;
3281 chars = thead - ttail + ch->ch_tsize;
3283 * Fudge factor here.
3284 * If chars is zero, we know that the command queue had
3285 * something in it or tbusy was set. Because we cannot
3286 * be sure if there is still some data to be transmitted,
3287 * lets lie, and tell ld we have 1 byte left.
3291 * If TBUSY is still set, and our tx buffers are empty,
3292 * force the firmware to send me another wakeup after
3293 * TBUSY has been cleared.
3296 spin_lock_irqsave(&ch->ch_lock, lock_flags);
3297 un->un_flags |= UN_EMPTY;
3298 writeb(1, &bs->iempty);
3299 spin_unlock_irqrestore(&ch->ch_lock,
3309 static int dgap_wait_for_drain(struct tty_struct *tty)
3311 struct channel_t *ch;
3313 struct bs_t __iomem *bs;
3316 ulong lock_flags = 0;
3318 if (!tty || tty->magic != TTY_MAGIC)
3321 un = tty->driver_data;
3322 if (!un || un->magic != DGAP_UNIT_MAGIC)
3326 if (!ch || ch->magic != DGAP_CHANNEL_MAGIC)
3333 /* Loop until data is drained */
3334 while (count != 0) {
3335 count = dgap_tty_chars_in_buffer(tty);
3340 /* Set flag waiting for drain */
3341 spin_lock_irqsave(&ch->ch_lock, lock_flags);
3342 un->un_flags |= UN_EMPTY;
3343 writeb(1, &bs->iempty);
3344 spin_unlock_irqrestore(&ch->ch_lock, lock_flags);
3346 /* Go to sleep till we get woken up */
3347 ret = wait_event_interruptible(un->un_flags_wait,
3348 ((un->un_flags & UN_EMPTY) == 0));
3349 /* If ret is non-zero, user ctrl-c'ed us */
3354 spin_lock_irqsave(&ch->ch_lock, lock_flags);
3355 un->un_flags &= ~(UN_EMPTY);
3356 spin_unlock_irqrestore(&ch->ch_lock, lock_flags);
3364 * Reduces bytes_available to the max number of characters
3365 * that can be sent currently given the maxcps value, and
3366 * returns the new bytes_available. This only affects printer
3369 static int dgap_maxcps_room(struct channel_t *ch, struct un_t *un,
3370 int bytes_available)
3373 * If its not the Transparent print device, return
3374 * the full data amount.
3376 if (un->un_type != DGAP_PRINT)
3377 return bytes_available;
3379 if (ch->ch_digi.digi_maxcps > 0 && ch->ch_digi.digi_bufsize > 0) {
3381 unsigned long current_time = jiffies;
3382 unsigned long buffer_time = current_time +
3383 (HZ * ch->ch_digi.digi_bufsize) /
3384 ch->ch_digi.digi_maxcps;
3386 if (ch->ch_cpstime < current_time) {
3387 /* buffer is empty */
3388 ch->ch_cpstime = current_time; /* reset ch_cpstime */
3389 cps_limit = ch->ch_digi.digi_bufsize;
3390 } else if (ch->ch_cpstime < buffer_time) {
3391 /* still room in the buffer */
3392 cps_limit = ((buffer_time - ch->ch_cpstime) *
3393 ch->ch_digi.digi_maxcps) / HZ;
3395 /* no room in the buffer */
3399 bytes_available = min(cps_limit, bytes_available);
3402 return bytes_available;
3405 static inline void dgap_set_firmware_event(struct un_t *un, unsigned int event)
3407 struct channel_t *ch;
3408 struct bs_t __iomem *bs;
3410 if (!un || un->magic != DGAP_UNIT_MAGIC)
3413 if (!ch || ch->magic != DGAP_CHANNEL_MAGIC)
3419 if ((event & UN_LOW) != 0) {
3420 if ((un->un_flags & UN_LOW) == 0) {
3421 un->un_flags |= UN_LOW;
3422 writeb(1, &bs->ilow);
3425 if ((event & UN_LOW) != 0) {
3426 if ((un->un_flags & UN_EMPTY) == 0) {
3427 un->un_flags |= UN_EMPTY;
3428 writeb(1, &bs->iempty);
3434 * dgap_tty_write_room()
3436 * Return space available in Tx buffer
3438 static int dgap_tty_write_room(struct tty_struct *tty)
3440 struct channel_t *ch;
3442 struct bs_t __iomem *bs;
3443 u16 head, tail, tmask;
3445 ulong lock_flags = 0;
3450 un = tty->driver_data;
3451 if (!un || un->magic != DGAP_UNIT_MAGIC)
3455 if (!ch || ch->magic != DGAP_CHANNEL_MAGIC)
3462 spin_lock_irqsave(&ch->ch_lock, lock_flags);
3464 tmask = ch->ch_tsize - 1;
3465 head = readw(&bs->tx_head) & tmask;
3466 tail = readw(&bs->tx_tail) & tmask;
3468 ret = tail - head - 1;
3470 ret += ch->ch_tsize;
3472 /* Limit printer to maxcps */
3473 ret = dgap_maxcps_room(ch, un, ret);
3476 * If we are printer device, leave space for
3477 * possibly both the on and off strings.
3479 if (un->un_type == DGAP_PRINT) {
3480 if (!(ch->ch_flags & CH_PRON))
3481 ret -= ch->ch_digi.digi_onlen;
3482 ret -= ch->ch_digi.digi_offlen;
3484 if (ch->ch_flags & CH_PRON)
3485 ret -= ch->ch_digi.digi_offlen;
3492 * Schedule FEP to wake us up if needed.
3494 * TODO: This might be overkill...
3495 * Do we really need to schedule callbacks from the FEP
3496 * in every case? Can we get smarter based on ret?
3498 dgap_set_firmware_event(un, UN_LOW | UN_EMPTY);
3499 spin_unlock_irqrestore(&ch->ch_lock, lock_flags);
3507 * Take data from the user or kernel and send it out to the FEP.
3508 * In here exists all the Transparent Print magic as well.
3510 static int dgap_tty_write(struct tty_struct *tty, const unsigned char *buf,
3513 struct channel_t *ch;
3515 struct bs_t __iomem *bs;
3516 char __iomem *vaddr;
3517 u16 head, tail, tmask, remain;
3524 un = tty->driver_data;
3525 if (!un || un->magic != DGAP_UNIT_MAGIC)
3529 if (!ch || ch->magic != DGAP_CHANNEL_MAGIC)
3539 spin_lock_irqsave(&ch->ch_lock, lock_flags);
3541 /* Get our space available for the channel from the board */
3542 tmask = ch->ch_tsize - 1;
3543 head = readw(&(bs->tx_head)) & tmask;
3544 tail = readw(&(bs->tx_tail)) & tmask;
3546 bufcount = tail - head - 1;
3548 bufcount += ch->ch_tsize;
3551 * Limit printer output to maxcps overall, with bursts allowed
3552 * up to bufsize characters.
3554 bufcount = dgap_maxcps_room(ch, un, bufcount);
3557 * Take minimum of what the user wants to send, and the
3558 * space available in the FEP buffer.
3560 count = min(count, bufcount);
3563 * Bail if no space left.
3566 dgap_set_firmware_event(un, UN_LOW | UN_EMPTY);
3567 spin_unlock_irqrestore(&ch->ch_lock, lock_flags);
3572 * Output the printer ON string, if we are in terminal mode, but
3573 * need to be in printer mode.
3575 if ((un->un_type == DGAP_PRINT) && !(ch->ch_flags & CH_PRON)) {
3576 dgap_wmove(ch, ch->ch_digi.digi_onstr,
3577 (int)ch->ch_digi.digi_onlen);
3578 head = readw(&bs->tx_head) & tmask;
3579 ch->ch_flags |= CH_PRON;
3583 * On the other hand, output the printer OFF string, if we are
3584 * currently in printer mode, but need to output to the terminal.
3586 if ((un->un_type != DGAP_PRINT) && (ch->ch_flags & CH_PRON)) {
3587 dgap_wmove(ch, ch->ch_digi.digi_offstr,
3588 (int)ch->ch_digi.digi_offlen);
3589 head = readw(&bs->tx_head) & tmask;
3590 ch->ch_flags &= ~CH_PRON;
3596 * If the write wraps over the top of the circular buffer,
3597 * move the portion up to the wrap point, and reset the
3598 * pointers to the bottom.
3600 remain = ch->ch_tstart + ch->ch_tsize - head;
3604 vaddr = ch->ch_taddr + head;
3606 memcpy_toio(vaddr, (u8 *)buf, remain);
3608 head = ch->ch_tstart;
3614 * Move rest of data.
3616 vaddr = ch->ch_taddr + head;
3619 memcpy_toio(vaddr, (u8 *)buf, remain);
3624 ch->ch_txcount += count;
3626 writew(head, &bs->tx_head);
3629 dgap_set_firmware_event(un, UN_LOW | UN_EMPTY);
3632 * If this is the print device, and the
3633 * printer is still on, we need to turn it
3634 * off before going idle. If the buffer is
3635 * non-empty, wait until it goes empty.
3636 * Otherwise turn it off right now.
3638 if ((un->un_type == DGAP_PRINT) && (ch->ch_flags & CH_PRON)) {
3639 tail = readw(&bs->tx_tail) & tmask;
3642 un->un_flags |= UN_EMPTY;
3643 writeb(1, &bs->iempty);
3645 dgap_wmove(ch, ch->ch_digi.digi_offstr,
3646 (int)ch->ch_digi.digi_offlen);
3647 head = readw(&bs->tx_head) & tmask;
3648 ch->ch_flags &= ~CH_PRON;
3652 /* Update printer buffer empty time. */
3653 if ((un->un_type == DGAP_PRINT) && (ch->ch_digi.digi_maxcps > 0)
3654 && (ch->ch_digi.digi_bufsize > 0)) {
3655 ch->ch_cpstime += (HZ * count) / ch->ch_digi.digi_maxcps;
3658 spin_unlock_irqrestore(&ch->ch_lock, lock_flags);
3664 * dgap_tty_put_char()
3666 * Put a character into ch->ch_buf
3668 * - used by the line discipline for OPOST processing
3670 static int dgap_tty_put_char(struct tty_struct *tty, unsigned char c)
3673 * Simply call tty_write.
3675 dgap_tty_write(tty, &c, 1);
3680 * Return modem signals to ld.
3682 static int dgap_tty_tiocmget(struct tty_struct *tty)
3684 struct channel_t *ch;
3690 if (!tty || tty->magic != TTY_MAGIC)
3693 un = tty->driver_data;
3694 if (!un || un->magic != DGAP_UNIT_MAGIC)
3698 if (!ch || ch->magic != DGAP_CHANNEL_MAGIC)
3701 spin_lock_irqsave(&ch->ch_lock, lock_flags);
3703 mstat = readb(&ch->ch_bs->m_stat);
3704 /* Append any outbound signals that might be pending... */
3705 mstat |= ch->ch_mostat;
3707 spin_unlock_irqrestore(&ch->ch_lock, lock_flags);
3711 if (mstat & D_DTR(ch))
3712 result |= TIOCM_DTR;
3713 if (mstat & D_RTS(ch))
3714 result |= TIOCM_RTS;
3715 if (mstat & D_CTS(ch))
3716 result |= TIOCM_CTS;
3717 if (mstat & D_DSR(ch))
3718 result |= TIOCM_DSR;
3719 if (mstat & D_RI(ch))
3721 if (mstat & D_CD(ch))
3728 * dgap_tty_tiocmset()
3730 * Set modem signals, called by ld.
3732 static int dgap_tty_tiocmset(struct tty_struct *tty,
3733 unsigned int set, unsigned int clear)
3736 struct channel_t *ch;
3741 if (!tty || tty->magic != TTY_MAGIC)
3744 un = tty->driver_data;
3745 if (!un || un->magic != DGAP_UNIT_MAGIC)
3749 if (!ch || ch->magic != DGAP_CHANNEL_MAGIC)
3753 if (!bd || bd->magic != DGAP_BOARD_MAGIC)
3756 spin_lock_irqsave(&bd->bd_lock, lock_flags);
3757 spin_lock_irqsave(&ch->ch_lock, lock_flags2);
3759 if (set & TIOCM_RTS) {
3760 ch->ch_mforce |= D_RTS(ch);
3761 ch->ch_mval |= D_RTS(ch);
3764 if (set & TIOCM_DTR) {
3765 ch->ch_mforce |= D_DTR(ch);
3766 ch->ch_mval |= D_DTR(ch);
3769 if (clear & TIOCM_RTS) {
3770 ch->ch_mforce |= D_RTS(ch);
3771 ch->ch_mval &= ~(D_RTS(ch));
3774 if (clear & TIOCM_DTR) {
3775 ch->ch_mforce |= D_DTR(ch);
3776 ch->ch_mval &= ~(D_DTR(ch));
3779 dgap_param(ch, bd, un->un_type);
3781 spin_unlock_irqrestore(&ch->ch_lock, lock_flags2);
3782 spin_unlock_irqrestore(&bd->bd_lock, lock_flags);
3788 * dgap_tty_send_break()
3790 * Send a Break, called by ld.
3792 static int dgap_tty_send_break(struct tty_struct *tty, int msec)
3795 struct channel_t *ch;
3800 if (!tty || tty->magic != TTY_MAGIC)
3803 un = tty->driver_data;
3804 if (!un || un->magic != DGAP_UNIT_MAGIC)
3808 if (!ch || ch->magic != DGAP_CHANNEL_MAGIC)
3812 if (!bd || bd->magic != DGAP_BOARD_MAGIC)
3827 spin_lock_irqsave(&bd->bd_lock, lock_flags);
3828 spin_lock_irqsave(&ch->ch_lock, lock_flags2);
3830 dgap_cmdw(ch, SBREAK, (u16) SBREAK_TIME, 0);
3832 dgap_cmdw(ch, SBREAK, (u16)msec, 0);
3834 spin_unlock_irqrestore(&ch->ch_lock, lock_flags2);
3835 spin_unlock_irqrestore(&bd->bd_lock, lock_flags);
3841 * dgap_tty_wait_until_sent()
3843 * wait until data has been transmitted, called by ld.
3845 static void dgap_tty_wait_until_sent(struct tty_struct *tty, int timeout)
3847 dgap_wait_for_drain(tty);
3853 * send a high priority character, called by ld.
3855 static void dgap_tty_send_xchar(struct tty_struct *tty, char c)
3858 struct channel_t *ch;
3863 if (!tty || tty->magic != TTY_MAGIC)
3866 un = tty->driver_data;
3867 if (!un || un->magic != DGAP_UNIT_MAGIC)
3871 if (!ch || ch->magic != DGAP_CHANNEL_MAGIC)
3875 if (!bd || bd->magic != DGAP_BOARD_MAGIC)
3878 spin_lock_irqsave(&bd->bd_lock, lock_flags);
3879 spin_lock_irqsave(&ch->ch_lock, lock_flags2);
3882 * This is technically what we should do.
3883 * However, the NIST tests specifically want
3884 * to see each XON or XOFF character that it
3885 * sends, so lets just send each character
3889 if (c == STOP_CHAR(tty))
3890 dgap_cmdw(ch, RPAUSE, 0, 0);
3891 else if (c == START_CHAR(tty))
3892 dgap_cmdw(ch, RRESUME, 0, 0);
3894 dgap_wmove(ch, &c, 1);
3896 dgap_wmove(ch, &c, 1);
3899 spin_unlock_irqrestore(&ch->ch_lock, lock_flags2);
3900 spin_unlock_irqrestore(&bd->bd_lock, lock_flags);
3904 * Return modem signals to ld.
3906 static int dgap_get_modem_info(struct channel_t *ch, unsigned int __user *value)
3912 spin_lock_irqsave(&ch->ch_lock, lock_flags);
3914 mstat = readb(&ch->ch_bs->m_stat);
3915 /* Append any outbound signals that might be pending... */
3916 mstat |= ch->ch_mostat;
3918 spin_unlock_irqrestore(&ch->ch_lock, lock_flags);
3922 if (mstat & D_DTR(ch))
3923 result |= TIOCM_DTR;
3924 if (mstat & D_RTS(ch))
3925 result |= TIOCM_RTS;
3926 if (mstat & D_CTS(ch))
3927 result |= TIOCM_CTS;
3928 if (mstat & D_DSR(ch))
3929 result |= TIOCM_DSR;
3930 if (mstat & D_RI(ch))
3932 if (mstat & D_CD(ch))
3935 return put_user(result, value);
3939 * dgap_set_modem_info()
3941 * Set modem signals, called by ld.
3943 static int dgap_set_modem_info(struct channel_t *ch, struct board_t *bd,
3944 struct un_t *un, unsigned int command,
3945 unsigned int __user *value)
3952 ret = get_user(arg, value);
3958 if (arg & TIOCM_RTS) {
3959 ch->ch_mforce |= D_RTS(ch);
3960 ch->ch_mval |= D_RTS(ch);
3963 if (arg & TIOCM_DTR) {
3964 ch->ch_mforce |= D_DTR(ch);
3965 ch->ch_mval |= D_DTR(ch);
3971 if (arg & TIOCM_RTS) {
3972 ch->ch_mforce |= D_RTS(ch);
3973 ch->ch_mval &= ~(D_RTS(ch));
3976 if (arg & TIOCM_DTR) {
3977 ch->ch_mforce |= D_DTR(ch);
3978 ch->ch_mval &= ~(D_DTR(ch));
3984 ch->ch_mforce = D_DTR(ch) | D_RTS(ch);
3986 if (arg & TIOCM_RTS)
3987 ch->ch_mval |= D_RTS(ch);
3989 ch->ch_mval &= ~(D_RTS(ch));
3991 if (arg & TIOCM_DTR)
3992 ch->ch_mval |= (D_DTR(ch));
3994 ch->ch_mval &= ~(D_DTR(ch));
4002 spin_lock_irqsave(&bd->bd_lock, lock_flags);
4003 spin_lock_irqsave(&ch->ch_lock, lock_flags2);
4005 dgap_param(ch, bd, un->un_type);
4007 spin_unlock_irqrestore(&ch->ch_lock, lock_flags2);
4008 spin_unlock_irqrestore(&bd->bd_lock, lock_flags);
4014 * dgap_tty_digigeta()
4016 * Ioctl to get the information for ditty.
4021 static int dgap_tty_digigeta(struct channel_t *ch,
4022 struct digi_t __user *retinfo)
4030 memset(&tmp, 0, sizeof(tmp));
4032 spin_lock_irqsave(&ch->ch_lock, lock_flags);
4033 memcpy(&tmp, &ch->ch_digi, sizeof(tmp));
4034 spin_unlock_irqrestore(&ch->ch_lock, lock_flags);
4036 if (copy_to_user(retinfo, &tmp, sizeof(*retinfo)))
4043 * dgap_tty_digiseta()
4045 * Ioctl to set the information for ditty.
4050 static int dgap_tty_digiseta(struct channel_t *ch, struct board_t *bd,
4051 struct un_t *un, struct digi_t __user *new_info)
4053 struct digi_t new_digi;
4054 ulong lock_flags = 0;
4055 unsigned long lock_flags2;
4057 if (copy_from_user(&new_digi, new_info, sizeof(struct digi_t)))
4060 spin_lock_irqsave(&bd->bd_lock, lock_flags);
4061 spin_lock_irqsave(&ch->ch_lock, lock_flags2);
4063 memcpy(&ch->ch_digi, &new_digi, sizeof(struct digi_t));
4065 if (ch->ch_digi.digi_maxcps < 1)
4066 ch->ch_digi.digi_maxcps = 1;
4068 if (ch->ch_digi.digi_maxcps > 10000)
4069 ch->ch_digi.digi_maxcps = 10000;
4071 if (ch->ch_digi.digi_bufsize < 10)
4072 ch->ch_digi.digi_bufsize = 10;
4074 if (ch->ch_digi.digi_maxchar < 1)
4075 ch->ch_digi.digi_maxchar = 1;
4077 if (ch->ch_digi.digi_maxchar > ch->ch_digi.digi_bufsize)
4078 ch->ch_digi.digi_maxchar = ch->ch_digi.digi_bufsize;
4080 if (ch->ch_digi.digi_onlen > DIGI_PLEN)
4081 ch->ch_digi.digi_onlen = DIGI_PLEN;
4083 if (ch->ch_digi.digi_offlen > DIGI_PLEN)
4084 ch->ch_digi.digi_offlen = DIGI_PLEN;
4086 dgap_param(ch, bd, un->un_type);
4088 spin_unlock_irqrestore(&ch->ch_lock, lock_flags2);
4089 spin_unlock_irqrestore(&bd->bd_lock, lock_flags);
4095 * dgap_tty_digigetedelay()
4097 * Ioctl to get the current edelay setting.
4102 static int dgap_tty_digigetedelay(struct tty_struct *tty, int __user *retinfo)
4104 struct channel_t *ch;
4112 if (!tty || tty->magic != TTY_MAGIC)
4115 un = tty->driver_data;
4116 if (!un || un->magic != DGAP_UNIT_MAGIC)
4120 if (!ch || ch->magic != DGAP_CHANNEL_MAGIC)
4123 memset(&tmp, 0, sizeof(tmp));
4125 spin_lock_irqsave(&ch->ch_lock, lock_flags);
4126 tmp = readw(&ch->ch_bs->edelay);
4127 spin_unlock_irqrestore(&ch->ch_lock, lock_flags);
4129 if (copy_to_user(retinfo, &tmp, sizeof(*retinfo)))
4136 * dgap_tty_digisetedelay()
4138 * Ioctl to set the EDELAY setting
4141 static int dgap_tty_digisetedelay(struct channel_t *ch, struct board_t *bd,
4142 struct un_t *un, int __user *new_info)
4148 if (copy_from_user(&new_digi, new_info, sizeof(int)))
4151 spin_lock_irqsave(&bd->bd_lock, lock_flags);
4152 spin_lock_irqsave(&ch->ch_lock, lock_flags2);
4154 writew((u16)new_digi, &ch->ch_bs->edelay);
4156 dgap_param(ch, bd, un->un_type);
4158 spin_unlock_irqrestore(&ch->ch_lock, lock_flags2);
4159 spin_unlock_irqrestore(&bd->bd_lock, lock_flags);
4165 * dgap_tty_digigetcustombaud()
4167 * Ioctl to get the current custom baud rate setting.
4169 static int dgap_tty_digigetcustombaud(struct channel_t *ch, struct un_t *un,
4170 int __user *retinfo)
4178 memset(&tmp, 0, sizeof(tmp));
4180 spin_lock_irqsave(&ch->ch_lock, lock_flags);
4181 tmp = dgap_get_custom_baud(ch);
4182 spin_unlock_irqrestore(&ch->ch_lock, lock_flags);
4184 if (copy_to_user(retinfo, &tmp, sizeof(*retinfo)))
4191 * dgap_tty_digisetcustombaud()
4193 * Ioctl to set the custom baud rate setting
4195 static int dgap_tty_digisetcustombaud(struct channel_t *ch, struct board_t *bd,
4196 struct un_t *un, int __user *new_info)
4202 if (copy_from_user(&new_rate, new_info, sizeof(unsigned int)))
4205 if (bd->bd_flags & BD_FEP5PLUS) {
4206 spin_lock_irqsave(&bd->bd_lock, lock_flags);
4207 spin_lock_irqsave(&ch->ch_lock, lock_flags2);
4209 ch->ch_custom_speed = new_rate;
4211 dgap_param(ch, bd, un->un_type);
4213 spin_unlock_irqrestore(&ch->ch_lock, lock_flags2);
4214 spin_unlock_irqrestore(&bd->bd_lock, lock_flags);
4221 * dgap_set_termios()
4223 static void dgap_tty_set_termios(struct tty_struct *tty,
4224 struct ktermios *old_termios)
4227 struct channel_t *ch;
4229 unsigned long lock_flags;
4230 unsigned long lock_flags2;
4232 if (!tty || tty->magic != TTY_MAGIC)
4235 un = tty->driver_data;
4236 if (!un || un->magic != DGAP_UNIT_MAGIC)
4240 if (!ch || ch->magic != DGAP_CHANNEL_MAGIC)
4244 if (!bd || bd->magic != DGAP_BOARD_MAGIC)
4247 spin_lock_irqsave(&bd->bd_lock, lock_flags);
4248 spin_lock_irqsave(&ch->ch_lock, lock_flags2);
4250 ch->ch_c_cflag = tty->termios.c_cflag;
4251 ch->ch_c_iflag = tty->termios.c_iflag;
4252 ch->ch_c_oflag = tty->termios.c_oflag;
4253 ch->ch_c_lflag = tty->termios.c_lflag;
4254 ch->ch_startc = tty->termios.c_cc[VSTART];
4255 ch->ch_stopc = tty->termios.c_cc[VSTOP];
4258 dgap_param(ch, bd, un->un_type);
4260 spin_unlock_irqrestore(&ch->ch_lock, lock_flags2);
4261 spin_unlock_irqrestore(&bd->bd_lock, lock_flags);
4264 static void dgap_tty_throttle(struct tty_struct *tty)
4267 struct channel_t *ch;
4272 if (!tty || tty->magic != TTY_MAGIC)
4275 un = tty->driver_data;
4276 if (!un || un->magic != DGAP_UNIT_MAGIC)
4280 if (!ch || ch->magic != DGAP_CHANNEL_MAGIC)
4284 if (!bd || bd->magic != DGAP_BOARD_MAGIC)
4287 spin_lock_irqsave(&bd->bd_lock, lock_flags);
4288 spin_lock_irqsave(&ch->ch_lock, lock_flags2);
4290 ch->ch_flags |= (CH_RXBLOCK);
4292 dgap_cmdw(ch, RPAUSE, 0, 0);
4295 spin_unlock_irqrestore(&ch->ch_lock, lock_flags2);
4296 spin_unlock_irqrestore(&bd->bd_lock, lock_flags);
4299 static void dgap_tty_unthrottle(struct tty_struct *tty)
4302 struct channel_t *ch;
4307 if (!tty || tty->magic != TTY_MAGIC)
4310 un = tty->driver_data;
4311 if (!un || un->magic != DGAP_UNIT_MAGIC)
4315 if (!ch || ch->magic != DGAP_CHANNEL_MAGIC)
4319 if (!bd || bd->magic != DGAP_BOARD_MAGIC)
4322 spin_lock_irqsave(&bd->bd_lock, lock_flags);
4323 spin_lock_irqsave(&ch->ch_lock, lock_flags2);
4325 ch->ch_flags &= ~(CH_RXBLOCK);
4328 dgap_cmdw(ch, RRESUME, 0, 0);
4331 spin_unlock_irqrestore(&ch->ch_lock, lock_flags2);
4332 spin_unlock_irqrestore(&bd->bd_lock, lock_flags);
4335 static struct board_t *find_board_by_major(unsigned int major)
4339 for (i = 0; i < MAXBOARDS; i++) {
4340 struct board_t *brd = dgap_board[i];
4344 if (major == brd->serial_driver->major ||
4345 major == brd->print_driver->major)
4352 /************************************************************************
4354 * TTY Entry points and helper functions
4356 ************************************************************************/
4362 static int dgap_tty_open(struct tty_struct *tty, struct file *file)
4364 struct board_t *brd;
4365 struct channel_t *ch;
4367 struct bs_t __iomem *bs;
4375 major = MAJOR(tty_devnum(tty));
4376 minor = MINOR(tty_devnum(tty));
4378 brd = find_board_by_major(major);
4383 * If board is not yet up to a state of READY, go to
4384 * sleep waiting for it to happen or they cancel the open.
4386 rc = wait_event_interruptible(brd->state_wait,
4387 (brd->state & BOARD_READY));
4392 spin_lock_irqsave(&brd->bd_lock, lock_flags);
4394 /* The wait above should guarantee this cannot happen */
4395 if (brd->state != BOARD_READY) {
4396 spin_unlock_irqrestore(&brd->bd_lock, lock_flags);
4400 /* If opened device is greater than our number of ports, bail. */
4401 if (MINOR(tty_devnum(tty)) > brd->nasync) {
4402 spin_unlock_irqrestore(&brd->bd_lock, lock_flags);
4406 ch = brd->channels[minor];
4408 spin_unlock_irqrestore(&brd->bd_lock, lock_flags);
4412 /* Grab channel lock */
4413 spin_lock_irqsave(&ch->ch_lock, lock_flags2);
4415 /* Figure out our type */
4416 if (major == brd->serial_driver->major) {
4417 un = &brd->channels[minor]->ch_tun;
4418 un->un_type = DGAP_SERIAL;
4419 } else if (major == brd->print_driver->major) {
4420 un = &brd->channels[minor]->ch_pun;
4421 un->un_type = DGAP_PRINT;
4423 spin_unlock_irqrestore(&ch->ch_lock, lock_flags2);
4424 spin_unlock_irqrestore(&brd->bd_lock, lock_flags);
4428 /* Store our unit into driver_data, so we always have it available. */
4429 tty->driver_data = un;
4432 * Error if channel info pointer is NULL.
4436 spin_unlock_irqrestore(&ch->ch_lock, lock_flags2);
4437 spin_unlock_irqrestore(&brd->bd_lock, lock_flags);
4444 if (!(un->un_flags & UN_ISOPEN)) {
4445 /* Store important variables. */
4448 /* Maybe do something here to the TTY struct as well? */
4452 * Initialize if neither terminal or printer is open.
4454 if (!((ch->ch_tun.un_flags | ch->ch_pun.un_flags) & UN_ISOPEN)) {
4459 * Flush input queue.
4461 head = readw(&bs->rx_head);
4462 writew(head, &bs->rx_tail);
4465 ch->pscan_state = 0;
4466 ch->pscan_savechar = 0;
4468 ch->ch_c_cflag = tty->termios.c_cflag;
4469 ch->ch_c_iflag = tty->termios.c_iflag;
4470 ch->ch_c_oflag = tty->termios.c_oflag;
4471 ch->ch_c_lflag = tty->termios.c_lflag;
4472 ch->ch_startc = tty->termios.c_cc[VSTART];
4473 ch->ch_stopc = tty->termios.c_cc[VSTOP];
4475 /* TODO: flush our TTY struct here? */
4480 * Run param in case we changed anything
4482 dgap_param(ch, brd, un->un_type);
4485 * follow protocol for opening port
4488 spin_unlock_irqrestore(&ch->ch_lock, lock_flags2);
4489 spin_unlock_irqrestore(&brd->bd_lock, lock_flags);
4491 rc = dgap_block_til_ready(tty, file, ch);
4496 /* No going back now, increment our unit and channel counters */
4497 spin_lock_irqsave(&ch->ch_lock, lock_flags);
4498 ch->ch_open_count++;
4499 un->un_open_count++;
4500 un->un_flags |= (UN_ISOPEN);
4501 spin_unlock_irqrestore(&ch->ch_lock, lock_flags);
4510 static void dgap_tty_close(struct tty_struct *tty, struct file *file)
4513 struct channel_t *ch;
4517 if (!tty || tty->magic != TTY_MAGIC)
4520 un = tty->driver_data;
4521 if (!un || un->magic != DGAP_UNIT_MAGIC)
4525 if (!ch || ch->magic != DGAP_CHANNEL_MAGIC)
4529 if (!bd || bd->magic != DGAP_BOARD_MAGIC)
4532 spin_lock_irqsave(&ch->ch_lock, lock_flags);
4535 * Determine if this is the last close or not - and if we agree about
4536 * which type of close it is with the Line Discipline
4538 if ((tty->count == 1) && (un->un_open_count != 1)) {
4540 * Uh, oh. tty->count is 1, which means that the tty
4541 * structure will be freed. un_open_count should always
4542 * be one in these conditions. If it's greater than
4543 * one, we've got real problems, since it means the
4544 * serial port won't be shutdown.
4546 un->un_open_count = 1;
4549 if (--un->un_open_count < 0)
4550 un->un_open_count = 0;
4552 ch->ch_open_count--;
4554 if (ch->ch_open_count && un->un_open_count) {
4555 spin_unlock_irqrestore(&ch->ch_lock, lock_flags);
4559 /* OK, its the last close on the unit */
4561 un->un_flags |= UN_CLOSING;
4566 * Only officially close channel if count is 0 and
4567 * DIGI_PRINTER bit is not set.
4569 if ((ch->ch_open_count == 0) &&
4570 !(ch->ch_digi.digi_flags & DIGI_PRINTER)) {
4571 ch->ch_flags &= ~(CH_RXBLOCK);
4573 spin_unlock_irqrestore(&ch->ch_lock, lock_flags);
4575 /* wait for output to drain */
4576 /* This will also return if we take an interrupt */
4578 dgap_wait_for_drain(tty);
4580 dgap_tty_flush_buffer(tty);
4581 tty_ldisc_flush(tty);
4583 spin_lock_irqsave(&ch->ch_lock, lock_flags);
4588 * If we have HUPCL set, lower DTR and RTS
4590 if (ch->ch_c_cflag & HUPCL) {
4591 ch->ch_mostat &= ~(D_RTS(ch) | D_DTR(ch));
4592 dgap_cmdb(ch, SMODEM, 0, D_DTR(ch) | D_RTS(ch), 0);
4595 * Go to sleep to ensure RTS/DTR
4596 * have been dropped for modems to see it.
4598 spin_unlock_irqrestore(&ch->ch_lock,
4601 /* .25 second delay for dropping RTS/DTR */
4602 schedule_timeout_interruptible(msecs_to_jiffies(250));
4604 spin_lock_irqsave(&ch->ch_lock, lock_flags);
4607 ch->pscan_state = 0;
4608 ch->pscan_savechar = 0;
4609 ch->ch_baud_info = 0;
4613 * turn off print device when closing print device.
4615 if ((un->un_type == DGAP_PRINT) && (ch->ch_flags & CH_PRON)) {
4616 dgap_wmove(ch, ch->ch_digi.digi_offstr,
4617 (int)ch->ch_digi.digi_offlen);
4618 ch->ch_flags &= ~CH_PRON;
4622 un->un_flags &= ~(UN_ISOPEN | UN_CLOSING);
4623 tty->driver_data = NULL;
4625 wake_up_interruptible(&ch->ch_flags_wait);
4626 wake_up_interruptible(&un->un_flags_wait);
4628 spin_unlock_irqrestore(&ch->ch_lock, lock_flags);
4631 static void dgap_tty_start(struct tty_struct *tty)
4634 struct channel_t *ch;
4639 if (!tty || tty->magic != TTY_MAGIC)
4642 un = tty->driver_data;
4643 if (!un || un->magic != DGAP_UNIT_MAGIC)
4647 if (!ch || ch->magic != DGAP_CHANNEL_MAGIC)
4651 if (!bd || bd->magic != DGAP_BOARD_MAGIC)
4654 spin_lock_irqsave(&bd->bd_lock, lock_flags);
4655 spin_lock_irqsave(&ch->ch_lock, lock_flags2);
4657 dgap_cmdw(ch, RESUMETX, 0, 0);
4659 spin_unlock_irqrestore(&ch->ch_lock, lock_flags2);
4660 spin_unlock_irqrestore(&bd->bd_lock, lock_flags);
4663 static void dgap_tty_stop(struct tty_struct *tty)
4666 struct channel_t *ch;
4671 if (!tty || tty->magic != TTY_MAGIC)
4674 un = tty->driver_data;
4675 if (!un || un->magic != DGAP_UNIT_MAGIC)
4679 if (!ch || ch->magic != DGAP_CHANNEL_MAGIC)
4683 if (!bd || bd->magic != DGAP_BOARD_MAGIC)
4686 spin_lock_irqsave(&bd->bd_lock, lock_flags);
4687 spin_lock_irqsave(&ch->ch_lock, lock_flags2);
4689 dgap_cmdw(ch, PAUSETX, 0, 0);
4691 spin_unlock_irqrestore(&ch->ch_lock, lock_flags2);
4692 spin_unlock_irqrestore(&bd->bd_lock, lock_flags);
4696 * dgap_tty_flush_chars()
4698 * Flush the cook buffer
4700 * Note to self, and any other poor souls who venture here:
4702 * flush in this case DOES NOT mean dispose of the data.
4703 * instead, it means "stop buffering and send it if you
4704 * haven't already." Just guess how I figured that out... SRW 2-Jun-98
4706 * It is also always called in interrupt context - JAR 8-Sept-99
4708 static void dgap_tty_flush_chars(struct tty_struct *tty)
4711 struct channel_t *ch;
4716 if (!tty || tty->magic != TTY_MAGIC)
4719 un = tty->driver_data;
4720 if (!un || un->magic != DGAP_UNIT_MAGIC)
4724 if (!ch || ch->magic != DGAP_CHANNEL_MAGIC)
4728 if (!bd || bd->magic != DGAP_BOARD_MAGIC)
4731 spin_lock_irqsave(&bd->bd_lock, lock_flags);
4732 spin_lock_irqsave(&ch->ch_lock, lock_flags2);
4734 /* TODO: Do something here */
4736 spin_unlock_irqrestore(&ch->ch_lock, lock_flags2);
4737 spin_unlock_irqrestore(&bd->bd_lock, lock_flags);
4740 /*****************************************************************************
4742 * The IOCTL function and all of its helpers
4744 *****************************************************************************/
4749 * The usual assortment of ioctl's
4751 static int dgap_tty_ioctl(struct tty_struct *tty, unsigned int cmd,
4755 struct channel_t *ch;
4759 ulong lock_flags = 0;
4760 ulong lock_flags2 = 0;
4761 void __user *uarg = (void __user *)arg;
4763 if (!tty || tty->magic != TTY_MAGIC)
4766 un = tty->driver_data;
4767 if (!un || un->magic != DGAP_UNIT_MAGIC)
4771 if (!ch || ch->magic != DGAP_CHANNEL_MAGIC)
4775 if (!bd || bd->magic != DGAP_BOARD_MAGIC)
4778 spin_lock_irqsave(&bd->bd_lock, lock_flags);
4779 spin_lock_irqsave(&ch->ch_lock, lock_flags2);
4781 if (un->un_open_count <= 0) {
4782 spin_unlock_irqrestore(&ch->ch_lock, lock_flags2);
4783 spin_unlock_irqrestore(&bd->bd_lock, lock_flags);
4788 /* Here are all the standard ioctl's that we MUST implement */
4791 * TCSBRK is SVID version: non-zero arg --> no break
4792 * this behaviour is exploited by tcdrain().
4794 * According to POSIX.1 spec (7.2.2.1.2) breaks should be
4795 * between 0.25 and 0.5 seconds so we'll ask for something
4796 * in the middle: 0.375 seconds.
4798 rc = tty_check_change(tty);
4799 spin_unlock_irqrestore(&ch->ch_lock, lock_flags2);
4800 spin_unlock_irqrestore(&bd->bd_lock, lock_flags);
4804 rc = dgap_wait_for_drain(tty);
4809 spin_lock_irqsave(&bd->bd_lock, lock_flags);
4810 spin_lock_irqsave(&ch->ch_lock, lock_flags2);
4812 if (((cmd == TCSBRK) && (!arg)) || (cmd == TCSBRKP))
4813 dgap_cmdw(ch, SBREAK, (u16)SBREAK_TIME, 0);
4815 spin_unlock_irqrestore(&ch->ch_lock, lock_flags2);
4816 spin_unlock_irqrestore(&bd->bd_lock, lock_flags);
4821 /* support for POSIX tcsendbreak()
4823 * According to POSIX.1 spec (7.2.2.1.2) breaks should be
4824 * between 0.25 and 0.5 seconds so we'll ask for something
4825 * in the middle: 0.375 seconds.
4827 rc = tty_check_change(tty);
4828 spin_unlock_irqrestore(&ch->ch_lock, lock_flags2);
4829 spin_unlock_irqrestore(&bd->bd_lock, lock_flags);
4833 rc = dgap_wait_for_drain(tty);
4837 spin_lock_irqsave(&bd->bd_lock, lock_flags);
4838 spin_lock_irqsave(&ch->ch_lock, lock_flags2);
4840 dgap_cmdw(ch, SBREAK, (u16)SBREAK_TIME, 0);
4842 spin_unlock_irqrestore(&ch->ch_lock, lock_flags2);
4843 spin_unlock_irqrestore(&bd->bd_lock, lock_flags);
4849 * FEP5 doesn't support turning on a break unconditionally.
4850 * The FEP5 device will stop sending a break automatically
4851 * after the specified time value that was sent when turning on
4854 rc = tty_check_change(tty);
4855 spin_unlock_irqrestore(&ch->ch_lock, lock_flags2);
4856 spin_unlock_irqrestore(&bd->bd_lock, lock_flags);
4860 rc = dgap_wait_for_drain(tty);
4864 spin_lock_irqsave(&bd->bd_lock, lock_flags);
4865 spin_lock_irqsave(&ch->ch_lock, lock_flags2);
4867 dgap_cmdw(ch, SBREAK, (u16)SBREAK_TIME, 0);
4869 spin_unlock_irqrestore(&ch->ch_lock, lock_flags2);
4870 spin_unlock_irqrestore(&bd->bd_lock, lock_flags);
4876 * FEP5 doesn't support turning off a break unconditionally.
4877 * The FEP5 device will stop sending a break automatically
4878 * after the specified time value that was sent when turning on
4881 spin_unlock_irqrestore(&ch->ch_lock, lock_flags2);
4882 spin_unlock_irqrestore(&bd->bd_lock, lock_flags);
4887 spin_unlock_irqrestore(&ch->ch_lock, lock_flags2);
4888 spin_unlock_irqrestore(&bd->bd_lock, lock_flags);
4890 return put_user(C_CLOCAL(tty) ? 1 : 0,
4891 (unsigned long __user *)arg);
4894 spin_unlock_irqrestore(&ch->ch_lock, lock_flags2);
4895 spin_unlock_irqrestore(&bd->bd_lock, lock_flags);
4897 rc = get_user(arg, (unsigned long __user *)arg);
4901 spin_lock_irqsave(&bd->bd_lock, lock_flags);
4902 spin_lock_irqsave(&ch->ch_lock, lock_flags2);
4903 tty->termios.c_cflag = ((tty->termios.c_cflag & ~CLOCAL) |
4904 (arg ? CLOCAL : 0));
4905 dgap_param(ch, bd, un->un_type);
4906 spin_unlock_irqrestore(&ch->ch_lock, lock_flags2);
4907 spin_unlock_irqrestore(&bd->bd_lock, lock_flags);
4912 spin_unlock_irqrestore(&ch->ch_lock, lock_flags2);
4913 spin_unlock_irqrestore(&bd->bd_lock, lock_flags);
4914 return dgap_get_modem_info(ch, uarg);
4919 spin_unlock_irqrestore(&ch->ch_lock, lock_flags2);
4920 spin_unlock_irqrestore(&bd->bd_lock, lock_flags);
4921 return dgap_set_modem_info(ch, bd, un, cmd, uarg);
4924 * Here are any additional ioctl's that we want to implement
4929 * The linux tty driver doesn't have a flush
4930 * input routine for the driver, assuming all backed
4931 * up data is in the line disc. buffers. However,
4932 * we all know that's not the case. Here, we
4933 * act on the ioctl, but then lie and say we didn't
4934 * so the line discipline will process the flush
4937 rc = tty_check_change(tty);
4939 spin_unlock_irqrestore(&ch->ch_lock, lock_flags2);
4940 spin_unlock_irqrestore(&bd->bd_lock, lock_flags);
4944 if ((arg == TCIFLUSH) || (arg == TCIOFLUSH)) {
4945 if (!(un->un_type == DGAP_PRINT)) {
4946 head = readw(&ch->ch_bs->rx_head);
4947 writew(head, &ch->ch_bs->rx_tail);
4948 writeb(0, &ch->ch_bs->orun);
4952 if ((arg != TCOFLUSH) && (arg != TCIOFLUSH)) {
4953 /* pretend we didn't recognize this IOCTL */
4954 spin_unlock_irqrestore(&ch->ch_lock, lock_flags2);
4955 spin_unlock_irqrestore(&bd->bd_lock, lock_flags);
4957 return -ENOIOCTLCMD;
4960 ch->ch_flags &= ~CH_STOP;
4961 head = readw(&ch->ch_bs->tx_head);
4962 dgap_cmdw(ch, FLUSHTX, (u16)head, 0);
4963 dgap_cmdw(ch, RESUMETX, 0, 0);
4964 if (ch->ch_tun.un_flags & (UN_LOW | UN_EMPTY)) {
4965 ch->ch_tun.un_flags &= ~(UN_LOW | UN_EMPTY);
4966 wake_up_interruptible(&ch->ch_tun.un_flags_wait);
4968 if (ch->ch_pun.un_flags & (UN_LOW | UN_EMPTY)) {
4969 ch->ch_pun.un_flags &= ~(UN_LOW | UN_EMPTY);
4970 wake_up_interruptible(&ch->ch_pun.un_flags_wait);
4972 if (waitqueue_active(&tty->write_wait))
4973 wake_up_interruptible(&tty->write_wait);
4975 /* Can't hold any locks when calling tty_wakeup! */
4976 spin_unlock_irqrestore(&ch->ch_lock, lock_flags2);
4977 spin_unlock_irqrestore(&bd->bd_lock, lock_flags);
4980 /* pretend we didn't recognize this IOCTL */
4981 return -ENOIOCTLCMD;
4986 * The linux tty driver doesn't have a flush
4987 * input routine for the driver, assuming all backed
4988 * up data is in the line disc. buffers. However,
4989 * we all know that's not the case. Here, we
4990 * act on the ioctl, but then lie and say we didn't
4991 * so the line discipline will process the flush
4994 if (cmd == TCSETSF) {
4996 ch->ch_flags &= ~CH_STOP;
4997 head = readw(&ch->ch_bs->rx_head);
4998 writew(head, &ch->ch_bs->rx_tail);
5001 /* now wait for all the output to drain */
5002 spin_unlock_irqrestore(&ch->ch_lock, lock_flags2);
5003 spin_unlock_irqrestore(&bd->bd_lock, lock_flags);
5004 rc = dgap_wait_for_drain(tty);
5008 /* pretend we didn't recognize this */
5009 return -ENOIOCTLCMD;
5013 spin_unlock_irqrestore(&ch->ch_lock, lock_flags2);
5014 spin_unlock_irqrestore(&bd->bd_lock, lock_flags);
5015 rc = dgap_wait_for_drain(tty);
5019 /* pretend we didn't recognize this */
5020 return -ENOIOCTLCMD;
5024 * The Linux Line Discipline (LD) would do this for us if we
5025 * let it, but we have the special firmware options to do this
5026 * the "right way" regardless of hardware or software flow
5027 * control so we'll do it outselves instead of letting the LD
5030 rc = tty_check_change(tty);
5032 spin_unlock_irqrestore(&ch->ch_lock, lock_flags2);
5033 spin_unlock_irqrestore(&bd->bd_lock, lock_flags);
5039 spin_unlock_irqrestore(&ch->ch_lock, lock_flags2);
5040 spin_unlock_irqrestore(&bd->bd_lock, lock_flags);
5041 dgap_tty_start(tty);
5044 spin_unlock_irqrestore(&ch->ch_lock, lock_flags2);
5045 spin_unlock_irqrestore(&bd->bd_lock, lock_flags);
5049 spin_unlock_irqrestore(&ch->ch_lock, lock_flags2);
5050 spin_unlock_irqrestore(&bd->bd_lock, lock_flags);
5051 /* Make the ld do it */
5052 return -ENOIOCTLCMD;
5054 spin_unlock_irqrestore(&ch->ch_lock, lock_flags2);
5055 spin_unlock_irqrestore(&bd->bd_lock, lock_flags);
5056 /* Make the ld do it */
5057 return -ENOIOCTLCMD;
5059 spin_unlock_irqrestore(&ch->ch_lock, lock_flags2);
5060 spin_unlock_irqrestore(&bd->bd_lock, lock_flags);
5065 /* get information for ditty */
5066 spin_unlock_irqrestore(&ch->ch_lock, lock_flags2);
5067 spin_unlock_irqrestore(&bd->bd_lock, lock_flags);
5068 return dgap_tty_digigeta(ch, uarg);
5073 /* set information for ditty */
5074 if (cmd == (DIGI_SETAW)) {
5075 spin_unlock_irqrestore(&ch->ch_lock, lock_flags2);
5076 spin_unlock_irqrestore(&bd->bd_lock, lock_flags);
5077 rc = dgap_wait_for_drain(tty);
5080 spin_lock_irqsave(&bd->bd_lock, lock_flags);
5081 spin_lock_irqsave(&ch->ch_lock, lock_flags2);
5083 tty_ldisc_flush(tty);
5087 spin_unlock_irqrestore(&ch->ch_lock, lock_flags2);
5088 spin_unlock_irqrestore(&bd->bd_lock, lock_flags);
5089 return dgap_tty_digiseta(ch, bd, un, uarg);
5092 spin_unlock_irqrestore(&ch->ch_lock, lock_flags2);
5093 spin_unlock_irqrestore(&bd->bd_lock, lock_flags);
5094 return dgap_tty_digigetedelay(tty, uarg);
5097 spin_unlock_irqrestore(&ch->ch_lock, lock_flags2);
5098 spin_unlock_irqrestore(&bd->bd_lock, lock_flags);
5099 return dgap_tty_digisetedelay(ch, bd, un, uarg);
5101 case DIGI_GETCUSTOMBAUD:
5102 spin_unlock_irqrestore(&ch->ch_lock, lock_flags2);
5103 spin_unlock_irqrestore(&bd->bd_lock, lock_flags);
5104 return dgap_tty_digigetcustombaud(ch, un, uarg);
5106 case DIGI_SETCUSTOMBAUD:
5107 spin_unlock_irqrestore(&ch->ch_lock, lock_flags2);
5108 spin_unlock_irqrestore(&bd->bd_lock, lock_flags);
5109 return dgap_tty_digisetcustombaud(ch, bd, un, uarg);
5111 case DIGI_RESET_PORT:
5112 dgap_firmware_reset_port(ch);
5113 dgap_param(ch, bd, un->un_type);
5114 spin_unlock_irqrestore(&ch->ch_lock, lock_flags2);
5115 spin_unlock_irqrestore(&bd->bd_lock, lock_flags);
5119 spin_unlock_irqrestore(&ch->ch_lock, lock_flags2);
5120 spin_unlock_irqrestore(&bd->bd_lock, lock_flags);
5122 return -ENOIOCTLCMD;
5126 static const struct tty_operations dgap_tty_ops = {
5127 .open = dgap_tty_open,
5128 .close = dgap_tty_close,
5129 .write = dgap_tty_write,
5130 .write_room = dgap_tty_write_room,
5131 .flush_buffer = dgap_tty_flush_buffer,
5132 .chars_in_buffer = dgap_tty_chars_in_buffer,
5133 .flush_chars = dgap_tty_flush_chars,
5134 .ioctl = dgap_tty_ioctl,
5135 .set_termios = dgap_tty_set_termios,
5136 .stop = dgap_tty_stop,
5137 .start = dgap_tty_start,
5138 .throttle = dgap_tty_throttle,
5139 .unthrottle = dgap_tty_unthrottle,
5140 .hangup = dgap_tty_hangup,
5141 .put_char = dgap_tty_put_char,
5142 .tiocmget = dgap_tty_tiocmget,
5143 .tiocmset = dgap_tty_tiocmset,
5144 .break_ctl = dgap_tty_send_break,
5145 .wait_until_sent = dgap_tty_wait_until_sent,
5146 .send_xchar = dgap_tty_send_xchar
5149 /************************************************************************
5151 * TTY Initialization/Cleanup Functions
5153 ************************************************************************/
5156 * dgap_tty_register()
5158 * Init the tty subsystem for this board.
5160 static int dgap_tty_register(struct board_t *brd)
5164 brd->serial_driver = tty_alloc_driver(MAXPORTS,
5165 TTY_DRIVER_REAL_RAW |
5166 TTY_DRIVER_DYNAMIC_DEV |
5167 TTY_DRIVER_HARDWARE_BREAK);
5168 if (IS_ERR(brd->serial_driver))
5169 return PTR_ERR(brd->serial_driver);
5171 snprintf(brd->serial_name, MAXTTYNAMELEN, "tty_dgap_%d_",
5173 brd->serial_driver->name = brd->serial_name;
5174 brd->serial_driver->name_base = 0;
5175 brd->serial_driver->major = 0;
5176 brd->serial_driver->minor_start = 0;
5177 brd->serial_driver->type = TTY_DRIVER_TYPE_SERIAL;
5178 brd->serial_driver->subtype = SERIAL_TYPE_NORMAL;
5179 brd->serial_driver->init_termios = dgap_default_termios;
5180 brd->serial_driver->driver_name = DRVSTR;
5183 * Entry points for driver. Called by the kernel from
5184 * tty_io.c and n_tty.c.
5186 tty_set_operations(brd->serial_driver, &dgap_tty_ops);
5189 * If we're doing transparent print, we have to do all of the above
5190 * again, separately so we don't get the LD confused about what major
5191 * we are when we get into the dgap_tty_open() routine.
5193 brd->print_driver = tty_alloc_driver(MAXPORTS,
5194 TTY_DRIVER_REAL_RAW |
5195 TTY_DRIVER_DYNAMIC_DEV |
5196 TTY_DRIVER_HARDWARE_BREAK);
5197 if (IS_ERR(brd->print_driver)) {
5198 rc = PTR_ERR(brd->print_driver);
5199 goto free_serial_drv;
5202 snprintf(brd->print_name, MAXTTYNAMELEN, "pr_dgap_%d_",
5204 brd->print_driver->name = brd->print_name;
5205 brd->print_driver->name_base = 0;
5206 brd->print_driver->major = 0;
5207 brd->print_driver->minor_start = 0;
5208 brd->print_driver->type = TTY_DRIVER_TYPE_SERIAL;
5209 brd->print_driver->subtype = SERIAL_TYPE_NORMAL;
5210 brd->print_driver->init_termios = dgap_default_termios;
5211 brd->print_driver->driver_name = DRVSTR;
5214 * Entry points for driver. Called by the kernel from
5215 * tty_io.c and n_tty.c.
5217 tty_set_operations(brd->print_driver, &dgap_tty_ops);
5219 /* Register tty devices */
5220 rc = tty_register_driver(brd->serial_driver);
5222 goto free_print_drv;
5224 /* Register Transparent Print devices */
5225 rc = tty_register_driver(brd->print_driver);
5227 goto unregister_serial_drv;
5231 unregister_serial_drv:
5232 tty_unregister_driver(brd->serial_driver);
5234 put_tty_driver(brd->print_driver);
5236 put_tty_driver(brd->serial_driver);
5241 static void dgap_tty_unregister(struct board_t *brd)
5243 tty_unregister_driver(brd->print_driver);
5244 tty_unregister_driver(brd->serial_driver);
5245 put_tty_driver(brd->print_driver);
5246 put_tty_driver(brd->serial_driver);
5249 static int dgap_alloc_flipbuf(struct board_t *brd)
5252 * allocate flip buffer for board.
5254 brd->flipbuf = kmalloc(MYFLIPLEN, GFP_KERNEL);
5258 brd->flipflagbuf = kmalloc(MYFLIPLEN, GFP_KERNEL);
5259 if (!brd->flipflagbuf) {
5260 kfree(brd->flipbuf);
5267 static void dgap_free_flipbuf(struct board_t *brd)
5269 kfree(brd->flipbuf);
5270 kfree(brd->flipflagbuf);
5273 static struct board_t *dgap_verify_board(struct device *p)
5280 bd = dev_get_drvdata(p);
5281 if (!bd || bd->magic != DGAP_BOARD_MAGIC || bd->state != BOARD_READY)
5287 static ssize_t dgap_ports_state_show(struct device *p,
5288 struct device_attribute *attr,
5295 bd = dgap_verify_board(p);
5299 for (i = 0; i < bd->nasync; i++) {
5300 count += snprintf(buf + count, PAGE_SIZE - count,
5301 "%d %s\n", bd->channels[i]->ch_portnum,
5302 bd->channels[i]->ch_open_count ? "Open" : "Closed");
5306 static DEVICE_ATTR(ports_state, S_IRUSR, dgap_ports_state_show, NULL);
5308 static ssize_t dgap_ports_baud_show(struct device *p,
5309 struct device_attribute *attr,
5316 bd = dgap_verify_board(p);
5320 for (i = 0; i < bd->nasync; i++) {
5321 count += snprintf(buf + count, PAGE_SIZE - count, "%d %d\n",
5322 bd->channels[i]->ch_portnum,
5323 bd->channels[i]->ch_baud_info);
5327 static DEVICE_ATTR(ports_baud, S_IRUSR, dgap_ports_baud_show, NULL);
5329 static ssize_t dgap_ports_msignals_show(struct device *p,
5330 struct device_attribute *attr,
5337 bd = dgap_verify_board(p);
5341 for (i = 0; i < bd->nasync; i++) {
5342 if (bd->channels[i]->ch_open_count)
5343 count += snprintf(buf + count, PAGE_SIZE - count,
5344 "%d %s %s %s %s %s %s\n",
5345 bd->channels[i]->ch_portnum,
5346 (bd->channels[i]->ch_mostat &
5347 UART_MCR_RTS) ? "RTS" : "",
5348 (bd->channels[i]->ch_mistat &
5349 UART_MSR_CTS) ? "CTS" : "",
5350 (bd->channels[i]->ch_mostat &
5351 UART_MCR_DTR) ? "DTR" : "",
5352 (bd->channels[i]->ch_mistat &
5353 UART_MSR_DSR) ? "DSR" : "",
5354 (bd->channels[i]->ch_mistat &
5355 UART_MSR_DCD) ? "DCD" : "",
5356 (bd->channels[i]->ch_mistat &
5357 UART_MSR_RI) ? "RI" : "");
5359 count += snprintf(buf + count, PAGE_SIZE - count,
5360 "%d\n", bd->channels[i]->ch_portnum);
5364 static DEVICE_ATTR(ports_msignals, S_IRUSR, dgap_ports_msignals_show, NULL);
5366 static ssize_t dgap_ports_iflag_show(struct device *p,
5367 struct device_attribute *attr,
5374 bd = dgap_verify_board(p);
5378 for (i = 0; i < bd->nasync; i++)
5379 count += snprintf(buf + count, PAGE_SIZE - count, "%d %x\n",
5380 bd->channels[i]->ch_portnum,
5381 bd->channels[i]->ch_c_iflag);
5384 static DEVICE_ATTR(ports_iflag, S_IRUSR, dgap_ports_iflag_show, NULL);
5386 static ssize_t dgap_ports_cflag_show(struct device *p,
5387 struct device_attribute *attr,
5394 bd = dgap_verify_board(p);
5398 for (i = 0; i < bd->nasync; i++)
5399 count += snprintf(buf + count, PAGE_SIZE - count, "%d %x\n",
5400 bd->channels[i]->ch_portnum,
5401 bd->channels[i]->ch_c_cflag);
5404 static DEVICE_ATTR(ports_cflag, S_IRUSR, dgap_ports_cflag_show, NULL);
5406 static ssize_t dgap_ports_oflag_show(struct device *p,
5407 struct device_attribute *attr,
5414 bd = dgap_verify_board(p);
5418 for (i = 0; i < bd->nasync; i++)
5419 count += snprintf(buf + count, PAGE_SIZE - count, "%d %x\n",
5420 bd->channels[i]->ch_portnum,
5421 bd->channels[i]->ch_c_oflag);
5424 static DEVICE_ATTR(ports_oflag, S_IRUSR, dgap_ports_oflag_show, NULL);
5426 static ssize_t dgap_ports_lflag_show(struct device *p,
5427 struct device_attribute *attr,
5434 bd = dgap_verify_board(p);
5438 for (i = 0; i < bd->nasync; i++)
5439 count += snprintf(buf + count, PAGE_SIZE - count, "%d %x\n",
5440 bd->channels[i]->ch_portnum,
5441 bd->channels[i]->ch_c_lflag);
5444 static DEVICE_ATTR(ports_lflag, S_IRUSR, dgap_ports_lflag_show, NULL);
5446 static ssize_t dgap_ports_digi_flag_show(struct device *p,
5447 struct device_attribute *attr,
5454 bd = dgap_verify_board(p);
5458 for (i = 0; i < bd->nasync; i++)
5459 count += snprintf(buf + count, PAGE_SIZE - count, "%d %x\n",
5460 bd->channels[i]->ch_portnum,
5461 bd->channels[i]->ch_digi.digi_flags);
5464 static DEVICE_ATTR(ports_digi_flag, S_IRUSR, dgap_ports_digi_flag_show, NULL);
5466 static ssize_t dgap_ports_rxcount_show(struct device *p,
5467 struct device_attribute *attr,
5474 bd = dgap_verify_board(p);
5478 for (i = 0; i < bd->nasync; i++)
5479 count += snprintf(buf + count, PAGE_SIZE - count, "%d %ld\n",
5480 bd->channels[i]->ch_portnum,
5481 bd->channels[i]->ch_rxcount);
5484 static DEVICE_ATTR(ports_rxcount, S_IRUSR, dgap_ports_rxcount_show, NULL);
5486 static ssize_t dgap_ports_txcount_show(struct device *p,
5487 struct device_attribute *attr,
5494 bd = dgap_verify_board(p);
5498 for (i = 0; i < bd->nasync; i++)
5499 count += snprintf(buf + count, PAGE_SIZE - count, "%d %ld\n",
5500 bd->channels[i]->ch_portnum,
5501 bd->channels[i]->ch_txcount);
5504 static DEVICE_ATTR(ports_txcount, S_IRUSR, dgap_ports_txcount_show, NULL);
5506 static ssize_t dgap_tty_state_show(struct device *d,
5507 struct device_attribute *attr,
5511 struct channel_t *ch;
5516 un = dev_get_drvdata(d);
5517 if (!un || un->magic != DGAP_UNIT_MAGIC)
5520 if (!ch || ch->magic != DGAP_CHANNEL_MAGIC)
5523 if (!bd || bd->magic != DGAP_BOARD_MAGIC)
5525 if (bd->state != BOARD_READY)
5528 return snprintf(buf, PAGE_SIZE, "%s", un->un_open_count ?
5531 static DEVICE_ATTR(state, S_IRUSR, dgap_tty_state_show, NULL);
5533 static ssize_t dgap_tty_baud_show(struct device *d,
5534 struct device_attribute *attr,
5538 struct channel_t *ch;
5543 un = dev_get_drvdata(d);
5544 if (!un || un->magic != DGAP_UNIT_MAGIC)
5547 if (!ch || ch->magic != DGAP_CHANNEL_MAGIC)
5550 if (!bd || bd->magic != DGAP_BOARD_MAGIC)
5552 if (bd->state != BOARD_READY)
5555 return snprintf(buf, PAGE_SIZE, "%d\n", ch->ch_baud_info);
5557 static DEVICE_ATTR(baud, S_IRUSR, dgap_tty_baud_show, NULL);
5559 static ssize_t dgap_tty_msignals_show(struct device *d,
5560 struct device_attribute *attr,
5564 struct channel_t *ch;
5569 un = dev_get_drvdata(d);
5570 if (!un || un->magic != DGAP_UNIT_MAGIC)
5573 if (!ch || ch->magic != DGAP_CHANNEL_MAGIC)
5576 if (!bd || bd->magic != DGAP_BOARD_MAGIC)
5578 if (bd->state != BOARD_READY)
5581 if (ch->ch_open_count) {
5582 return snprintf(buf, PAGE_SIZE, "%s %s %s %s %s %s\n",
5583 (ch->ch_mostat & UART_MCR_RTS) ? "RTS" : "",
5584 (ch->ch_mistat & UART_MSR_CTS) ? "CTS" : "",
5585 (ch->ch_mostat & UART_MCR_DTR) ? "DTR" : "",
5586 (ch->ch_mistat & UART_MSR_DSR) ? "DSR" : "",
5587 (ch->ch_mistat & UART_MSR_DCD) ? "DCD" : "",
5588 (ch->ch_mistat & UART_MSR_RI) ? "RI" : "");
5592 static DEVICE_ATTR(msignals, S_IRUSR, dgap_tty_msignals_show, NULL);
5594 static ssize_t dgap_tty_iflag_show(struct device *d,
5595 struct device_attribute *attr,
5599 struct channel_t *ch;
5604 un = dev_get_drvdata(d);
5605 if (!un || un->magic != DGAP_UNIT_MAGIC)
5608 if (!ch || ch->magic != DGAP_CHANNEL_MAGIC)
5611 if (!bd || bd->magic != DGAP_BOARD_MAGIC)
5613 if (bd->state != BOARD_READY)
5616 return snprintf(buf, PAGE_SIZE, "%x\n", ch->ch_c_iflag);
5618 static DEVICE_ATTR(iflag, S_IRUSR, dgap_tty_iflag_show, NULL);
5620 static ssize_t dgap_tty_cflag_show(struct device *d,
5621 struct device_attribute *attr,
5625 struct channel_t *ch;
5630 un = dev_get_drvdata(d);
5631 if (!un || un->magic != DGAP_UNIT_MAGIC)
5634 if (!ch || ch->magic != DGAP_CHANNEL_MAGIC)
5637 if (!bd || bd->magic != DGAP_BOARD_MAGIC)
5639 if (bd->state != BOARD_READY)
5642 return snprintf(buf, PAGE_SIZE, "%x\n", ch->ch_c_cflag);
5644 static DEVICE_ATTR(cflag, S_IRUSR, dgap_tty_cflag_show, NULL);
5646 static ssize_t dgap_tty_oflag_show(struct device *d,
5647 struct device_attribute *attr,
5651 struct channel_t *ch;
5656 un = dev_get_drvdata(d);
5657 if (!un || un->magic != DGAP_UNIT_MAGIC)
5660 if (!ch || ch->magic != DGAP_CHANNEL_MAGIC)
5663 if (!bd || bd->magic != DGAP_BOARD_MAGIC)
5665 if (bd->state != BOARD_READY)
5668 return snprintf(buf, PAGE_SIZE, "%x\n", ch->ch_c_oflag);
5670 static DEVICE_ATTR(oflag, S_IRUSR, dgap_tty_oflag_show, NULL);
5672 static ssize_t dgap_tty_lflag_show(struct device *d,
5673 struct device_attribute *attr,
5677 struct channel_t *ch;
5682 un = dev_get_drvdata(d);
5683 if (!un || un->magic != DGAP_UNIT_MAGIC)
5686 if (!ch || ch->magic != DGAP_CHANNEL_MAGIC)
5689 if (!bd || bd->magic != DGAP_BOARD_MAGIC)
5691 if (bd->state != BOARD_READY)
5694 return snprintf(buf, PAGE_SIZE, "%x\n", ch->ch_c_lflag);
5696 static DEVICE_ATTR(lflag, S_IRUSR, dgap_tty_lflag_show, NULL);
5698 static ssize_t dgap_tty_digi_flag_show(struct device *d,
5699 struct device_attribute *attr,
5703 struct channel_t *ch;
5708 un = dev_get_drvdata(d);
5709 if (!un || un->magic != DGAP_UNIT_MAGIC)
5712 if (!ch || ch->magic != DGAP_CHANNEL_MAGIC)
5715 if (!bd || bd->magic != DGAP_BOARD_MAGIC)
5717 if (bd->state != BOARD_READY)
5720 return snprintf(buf, PAGE_SIZE, "%x\n", ch->ch_digi.digi_flags);
5722 static DEVICE_ATTR(digi_flag, S_IRUSR, dgap_tty_digi_flag_show, NULL);
5724 static ssize_t dgap_tty_rxcount_show(struct device *d,
5725 struct device_attribute *attr,
5729 struct channel_t *ch;
5734 un = dev_get_drvdata(d);
5735 if (!un || un->magic != DGAP_UNIT_MAGIC)
5738 if (!ch || ch->magic != DGAP_CHANNEL_MAGIC)
5741 if (!bd || bd->magic != DGAP_BOARD_MAGIC)
5743 if (bd->state != BOARD_READY)
5746 return snprintf(buf, PAGE_SIZE, "%ld\n", ch->ch_rxcount);
5748 static DEVICE_ATTR(rxcount, S_IRUSR, dgap_tty_rxcount_show, NULL);
5750 static ssize_t dgap_tty_txcount_show(struct device *d,
5751 struct device_attribute *attr,
5755 struct channel_t *ch;
5760 un = dev_get_drvdata(d);
5761 if (!un || un->magic != DGAP_UNIT_MAGIC)
5764 if (!ch || ch->magic != DGAP_CHANNEL_MAGIC)
5767 if (!bd || bd->magic != DGAP_BOARD_MAGIC)
5769 if (bd->state != BOARD_READY)
5772 return snprintf(buf, PAGE_SIZE, "%ld\n", ch->ch_txcount);
5774 static DEVICE_ATTR(txcount, S_IRUSR, dgap_tty_txcount_show, NULL);
5776 static ssize_t dgap_tty_name_show(struct device *d,
5777 struct device_attribute *attr,
5781 struct channel_t *ch;
5793 un = dev_get_drvdata(d);
5794 if (!un || un->magic != DGAP_UNIT_MAGIC)
5797 if (!ch || ch->magic != DGAP_CHANNEL_MAGIC)
5800 if (!bd || bd->magic != DGAP_BOARD_MAGIC)
5802 if (bd->state != BOARD_READY)
5806 cn = ch->ch_portnum;
5808 for (cptr = bd->bd_config; cptr; cptr = cptr->next) {
5809 if ((cptr->type == BNODE) &&
5810 ((cptr->u.board.type == APORT2_920P) ||
5811 (cptr->u.board.type == APORT4_920P) ||
5812 (cptr->u.board.type == APORT8_920P) ||
5813 (cptr->u.board.type == PAPORT4) ||
5814 (cptr->u.board.type == PAPORT8))) {
5816 if (cptr->u.board.v_start)
5817 starto = cptr->u.board.start;
5822 if (cptr->type == TNODE && found == TRUE) {
5825 if (strstr(cptr->u.ttyname, "tty")) {
5826 ptr1 = cptr->u.ttyname;
5829 ptr1 = cptr->u.ttyname;
5831 for (i = 0; i < dgap_config_get_num_prts(bd); i++) {
5835 return snprintf(buf, PAGE_SIZE, "%s%s%02d\n",
5836 (un->un_type == DGAP_PRINT) ?
5842 if (cptr->type == CNODE) {
5843 for (i = 0; i < cptr->u.conc.nport; i++) {
5844 if (cn != (i + ncount))
5847 return snprintf(buf, PAGE_SIZE, "%s%s%02ld\n",
5848 (un->un_type == DGAP_PRINT) ?
5851 i + (cptr->u.conc.v_start ?
5852 cptr->u.conc.start : 1));
5855 ncount += cptr->u.conc.nport;
5858 if (cptr->type == MNODE) {
5859 for (i = 0; i < cptr->u.module.nport; i++) {
5860 if (cn != (i + ncount))
5863 return snprintf(buf, PAGE_SIZE, "%s%s%02ld\n",
5864 (un->un_type == DGAP_PRINT) ?
5867 i + (cptr->u.module.v_start ?
5868 cptr->u.module.start : 1));
5871 ncount += cptr->u.module.nport;
5875 return snprintf(buf, PAGE_SIZE, "%s_dgap_%d_%d\n",
5876 (un->un_type == DGAP_PRINT) ? "pr" : "tty", bn, cn);
5878 static DEVICE_ATTR(custom_name, S_IRUSR, dgap_tty_name_show, NULL);
5880 static struct attribute *dgap_sysfs_tty_entries[] = {
5881 &dev_attr_state.attr,
5882 &dev_attr_baud.attr,
5883 &dev_attr_msignals.attr,
5884 &dev_attr_iflag.attr,
5885 &dev_attr_cflag.attr,
5886 &dev_attr_oflag.attr,
5887 &dev_attr_lflag.attr,
5888 &dev_attr_digi_flag.attr,
5889 &dev_attr_rxcount.attr,
5890 &dev_attr_txcount.attr,
5891 &dev_attr_custom_name.attr,
5896 /* this function creates the sys files that will export each signal status
5897 * to sysfs each value will be put in a separate filename
5899 static void dgap_create_ports_sysfiles(struct board_t *bd)
5901 dev_set_drvdata(&bd->pdev->dev, bd);
5902 device_create_file(&bd->pdev->dev, &dev_attr_ports_state);
5903 device_create_file(&bd->pdev->dev, &dev_attr_ports_baud);
5904 device_create_file(&bd->pdev->dev, &dev_attr_ports_msignals);
5905 device_create_file(&bd->pdev->dev, &dev_attr_ports_iflag);
5906 device_create_file(&bd->pdev->dev, &dev_attr_ports_cflag);
5907 device_create_file(&bd->pdev->dev, &dev_attr_ports_oflag);
5908 device_create_file(&bd->pdev->dev, &dev_attr_ports_lflag);
5909 device_create_file(&bd->pdev->dev, &dev_attr_ports_digi_flag);
5910 device_create_file(&bd->pdev->dev, &dev_attr_ports_rxcount);
5911 device_create_file(&bd->pdev->dev, &dev_attr_ports_txcount);
5914 /* removes all the sys files created for that port */
5915 static void dgap_remove_ports_sysfiles(struct board_t *bd)
5917 device_remove_file(&bd->pdev->dev, &dev_attr_ports_state);
5918 device_remove_file(&bd->pdev->dev, &dev_attr_ports_baud);
5919 device_remove_file(&bd->pdev->dev, &dev_attr_ports_msignals);
5920 device_remove_file(&bd->pdev->dev, &dev_attr_ports_iflag);
5921 device_remove_file(&bd->pdev->dev, &dev_attr_ports_cflag);
5922 device_remove_file(&bd->pdev->dev, &dev_attr_ports_oflag);
5923 device_remove_file(&bd->pdev->dev, &dev_attr_ports_lflag);
5924 device_remove_file(&bd->pdev->dev, &dev_attr_ports_digi_flag);
5925 device_remove_file(&bd->pdev->dev, &dev_attr_ports_rxcount);
5926 device_remove_file(&bd->pdev->dev, &dev_attr_ports_txcount);
5930 * Copies the BIOS code from the user to the board,
5931 * and starts the BIOS running.
5933 static void dgap_do_bios_load(struct board_t *brd, const u8 *ubios, int len)
5939 if (!brd || (brd->magic != DGAP_BOARD_MAGIC) || !brd->re_map_membase)
5942 addr = brd->re_map_membase;
5947 for (i = 0; i < 16; i++)
5948 writeb(0, addr + POSTAREA + i);
5954 memcpy_toio(addr + offset, ubios, len);
5956 writel(0x0bf00401, addr);
5957 writel(0, (addr + 4));
5959 /* Clear the reset, and change states. */
5960 writeb(FEPCLR, brd->re_map_port);
5964 * Checks to see if the BIOS completed running on the card.
5966 static int dgap_test_bios(struct board_t *brd)
5973 if (!brd || (brd->magic != DGAP_BOARD_MAGIC) || !brd->re_map_membase)
5976 addr = brd->re_map_membase;
5977 word = readw(addr + POSTAREA);
5980 * It can take 5-6 seconds for a board to
5981 * pass the bios self test and post results.
5982 * Give it 10 seconds.
5984 brd->wait_for_bios = 0;
5985 while (brd->wait_for_bios < 1000) {
5986 /* Check to see if BIOS thinks board is good. (GD). */
5987 if (word == *(u16 *)"GD")
5989 msleep_interruptible(10);
5990 brd->wait_for_bios++;
5991 word = readw(addr + POSTAREA);
5994 /* Gave up on board after too long of time taken */
5995 err1 = readw(addr + SEQUENCE);
5996 err2 = readw(addr + ERROR);
5997 dev_warn(&brd->pdev->dev, "%s failed diagnostics. Error #(%x,%x).\n",
5998 brd->name, err1, err2);
5999 brd->state = BOARD_FAILED;
6000 brd->dpastatus = BD_NOBIOS;
6006 * Copies the FEP code from the user to the board,
6007 * and starts the FEP running.
6009 static void dgap_do_fep_load(struct board_t *brd, const u8 *ufep, int len)
6014 if (!brd || (brd->magic != DGAP_BOARD_MAGIC) || !brd->re_map_membase)
6017 addr = brd->re_map_membase;
6023 memcpy_toio(addr + offset, ufep, len);
6026 * If board is a concentrator product, we need to give
6027 * it its config string describing how the concentrators look.
6029 if ((brd->type == PCX) || (brd->type == PEPC)) {
6035 xconfig = dgap_create_config_string(brd, string);
6037 /* Write string to board memory */
6038 config = addr + CONFIG;
6039 for (; i < CONFIGSIZE; i++, config++, xconfig++) {
6040 writeb(*xconfig, config);
6041 if ((*xconfig & 0xff) == 0xff)
6046 writel(0xbfc01004, (addr + 0xc34));
6047 writel(0x3, (addr + 0xc30));
6051 * Waits for the FEP to report thats its ready for us to use.
6053 static int dgap_test_fep(struct board_t *brd)
6060 if (!brd || (brd->magic != DGAP_BOARD_MAGIC) || !brd->re_map_membase)
6063 addr = brd->re_map_membase;
6064 word = readw(addr + FEPSTAT);
6067 * It can take 2-3 seconds for the FEP to
6068 * be up and running. Give it 5 secs.
6070 brd->wait_for_fep = 0;
6071 while (brd->wait_for_fep < 500) {
6072 /* Check to see if FEP is up and running now. */
6073 if (word == *(u16 *)"OS") {
6075 * Check to see if the board can support FEP5+ commands.
6077 word = readw(addr + FEP5_PLUS);
6078 if (word == *(u16 *)"5A")
6079 brd->bd_flags |= BD_FEP5PLUS;
6083 msleep_interruptible(10);
6084 brd->wait_for_fep++;
6085 word = readw(addr + FEPSTAT);
6088 /* Gave up on board after too long of time taken */
6089 err1 = readw(addr + SEQUENCE);
6090 err2 = readw(addr + ERROR);
6091 dev_warn(&brd->pdev->dev,
6092 "FEPOS for %s not functioning. Error #(%x,%x).\n",
6093 brd->name, err1, err2);
6094 brd->state = BOARD_FAILED;
6095 brd->dpastatus = BD_NOFEP;
6101 * Physically forces the FEP5 card to reset itself.
6103 static void dgap_do_reset_board(struct board_t *brd)
6110 if (!brd || (brd->magic != DGAP_BOARD_MAGIC) ||
6111 !brd->re_map_membase || !brd->re_map_port)
6114 /* FEPRST does not vary among supported boards */
6115 writeb(FEPRST, brd->re_map_port);
6117 for (i = 0; i <= 1000; i++) {
6118 check = readb(brd->re_map_port) & 0xe;
6119 if (check == FEPRST)
6124 dev_warn(&brd->pdev->dev,
6125 "dgap: Board not resetting... Failing board.\n");
6126 brd->state = BOARD_FAILED;
6127 brd->dpastatus = BD_NOFEP;
6132 * Make sure there really is memory out there.
6134 writel(0xa55a3cc3, (brd->re_map_membase + LOWMEM));
6135 writel(0x5aa5c33c, (brd->re_map_membase + HIGHMEM));
6136 check1 = readl(brd->re_map_membase + LOWMEM);
6137 check2 = readl(brd->re_map_membase + HIGHMEM);
6139 if ((check1 != 0xa55a3cc3) || (check2 != 0x5aa5c33c)) {
6140 dev_warn(&brd->pdev->dev,
6141 "No memory at %p for board.\n",
6142 brd->re_map_membase);
6143 brd->state = BOARD_FAILED;
6144 brd->dpastatus = BD_NOFEP;
6149 #ifdef DIGI_CONCENTRATORS_SUPPORTED
6151 * Sends a concentrator image into the FEP5 board.
6153 static void dgap_do_conc_load(struct board_t *brd, u8 *uaddr, int len)
6155 char __iomem *vaddr;
6157 struct downld_t *to_dp;
6159 if (!brd || (brd->magic != DGAP_BOARD_MAGIC) || !brd->re_map_membase)
6162 vaddr = brd->re_map_membase;
6164 offset = readw((u16 *)(vaddr + DOWNREQ));
6165 to_dp = (struct downld_t *)(vaddr + (int)offset);
6166 memcpy_toio(to_dp, uaddr, len);
6168 /* Tell card we have data for it */
6169 writew(0, vaddr + (DOWNREQ));
6171 brd->conc_dl_status = NO_PENDING_CONCENTRATOR_REQUESTS;
6175 #define EXPANSION_ROM_SIZE (64 * 1024)
6176 #define FEP5_ROM_MAGIC (0xFEFFFFFF)
6178 static void dgap_get_vpd(struct board_t *brd)
6190 * Poke the magic number at the PCI Rom Address location.
6191 * If VPD is supported, the value read from that address
6194 magic = FEP5_ROM_MAGIC;
6195 pci_write_config_dword(brd->pdev, PCI_ROM_ADDRESS, magic);
6196 pci_read_config_dword(brd->pdev, PCI_ROM_ADDRESS, &magic);
6198 /* VPD not supported, bail */
6203 * To get to the OTPROM memory, we have to send the boards base
6204 * address or'ed with 1 into the PCI Rom Address location.
6206 magic = brd->membase | 0x01;
6207 pci_write_config_dword(brd->pdev, PCI_ROM_ADDRESS, magic);
6208 pci_read_config_dword(brd->pdev, PCI_ROM_ADDRESS, &magic);
6210 byte1 = readb(brd->re_map_membase);
6211 byte2 = readb(brd->re_map_membase + 1);
6214 * If the board correctly swapped to the OTPROM memory,
6215 * the first 2 bytes (header) should be 0x55, 0xAA
6217 if (byte1 == 0x55 && byte2 == 0xAA) {
6221 * We have to run through all the OTPROM memory looking
6222 * for the VPD offset.
6224 while (base_offset <= EXPANSION_ROM_SIZE) {
6226 * Lots of magic numbers here.
6228 * The VPD offset is located inside the ROM Data
6231 * We also have to remember the length of each
6232 * ROM Data Structure, so we can "hop" to the next
6233 * entry if the VPD isn't in the current
6234 * ROM Data Structure.
6236 rom_offset = readw(brd->re_map_membase +
6237 base_offset + 0x18);
6238 image_length = readw(brd->re_map_membase +
6239 rom_offset + 0x10) * 512;
6240 vpd_offset = readw(brd->re_map_membase +
6243 /* Found the VPD entry */
6247 /* We didn't find a VPD entry, go to next ROM entry. */
6248 base_offset += image_length;
6250 byte1 = readb(brd->re_map_membase + base_offset);
6251 byte2 = readb(brd->re_map_membase + base_offset + 1);
6254 * If the new ROM offset doesn't have 0x55, 0xAA
6255 * as its header, we have run out of ROM.
6257 if (byte1 != 0x55 || byte2 != 0xAA)
6262 * If we have a VPD offset, then mark the board
6263 * as having a valid VPD, and copy VPDSIZE (512) bytes of
6264 * that VPD to the buffer we have in our board structure.
6267 brd->bd_flags |= BD_HAS_VPD;
6268 for (i = 0; i < VPDSIZE; i++) {
6269 brd->vpd[i] = readb(brd->re_map_membase +
6276 * We MUST poke the magic number at the PCI Rom Address location again.
6277 * This makes the card report the regular board memory back to us,
6278 * rather than the OTPROM memory.
6280 magic = FEP5_ROM_MAGIC;
6281 pci_write_config_dword(brd->pdev, PCI_ROM_ADDRESS, magic);
6285 static ssize_t dgap_driver_version_show(struct device_driver *ddp, char *buf)
6287 return snprintf(buf, PAGE_SIZE, "%s\n", DG_PART);
6289 static DRIVER_ATTR(version, S_IRUSR, dgap_driver_version_show, NULL);
6292 static ssize_t dgap_driver_boards_show(struct device_driver *ddp, char *buf)
6294 return snprintf(buf, PAGE_SIZE, "%d\n", dgap_numboards);
6296 static DRIVER_ATTR(boards, S_IRUSR, dgap_driver_boards_show, NULL);
6299 static ssize_t dgap_driver_maxboards_show(struct device_driver *ddp, char *buf)
6301 return snprintf(buf, PAGE_SIZE, "%d\n", MAXBOARDS);
6303 static DRIVER_ATTR(maxboards, S_IRUSR, dgap_driver_maxboards_show, NULL);
6306 static ssize_t dgap_driver_pollcounter_show(struct device_driver *ddp,
6309 return snprintf(buf, PAGE_SIZE, "%ld\n", dgap_poll_counter);
6311 static DRIVER_ATTR(pollcounter, S_IRUSR, dgap_driver_pollcounter_show, NULL);
6313 static ssize_t dgap_driver_pollrate_show(struct device_driver *ddp, char *buf)
6315 return snprintf(buf, PAGE_SIZE, "%dms\n", dgap_poll_tick);
6318 static ssize_t dgap_driver_pollrate_store(struct device_driver *ddp,
6319 const char *buf, size_t count)
6321 if (sscanf(buf, "%d\n", &dgap_poll_tick) != 1)
6325 static DRIVER_ATTR(pollrate, (S_IRUSR | S_IWUSR), dgap_driver_pollrate_show,
6326 dgap_driver_pollrate_store);
6329 static int dgap_create_driver_sysfiles(struct pci_driver *dgap_driver)
6332 struct device_driver *driverfs = &dgap_driver->driver;
6334 rc |= driver_create_file(driverfs, &driver_attr_version);
6335 rc |= driver_create_file(driverfs, &driver_attr_boards);
6336 rc |= driver_create_file(driverfs, &driver_attr_maxboards);
6337 rc |= driver_create_file(driverfs, &driver_attr_pollrate);
6338 rc |= driver_create_file(driverfs, &driver_attr_pollcounter);
6343 static void dgap_remove_driver_sysfiles(struct pci_driver *dgap_driver)
6345 struct device_driver *driverfs = &dgap_driver->driver;
6347 driver_remove_file(driverfs, &driver_attr_version);
6348 driver_remove_file(driverfs, &driver_attr_boards);
6349 driver_remove_file(driverfs, &driver_attr_maxboards);
6350 driver_remove_file(driverfs, &driver_attr_pollrate);
6351 driver_remove_file(driverfs, &driver_attr_pollcounter);
6354 static struct attribute_group dgap_tty_attribute_group = {
6356 .attrs = dgap_sysfs_tty_entries,
6359 static void dgap_create_tty_sysfs(struct un_t *un, struct device *c)
6363 ret = sysfs_create_group(&c->kobj, &dgap_tty_attribute_group);
6367 dev_set_drvdata(c, un);
6370 static void dgap_remove_tty_sysfs(struct device *c)
6372 sysfs_remove_group(&c->kobj, &dgap_tty_attribute_group);
6376 * Create pr and tty device entries
6378 static int dgap_tty_register_ports(struct board_t *brd)
6380 struct channel_t *ch;
6384 brd->serial_ports = kcalloc(brd->nasync, sizeof(*brd->serial_ports),
6386 if (!brd->serial_ports)
6389 brd->printer_ports = kcalloc(brd->nasync, sizeof(*brd->printer_ports),
6391 if (!brd->printer_ports) {
6393 goto free_serial_ports;
6396 for (i = 0; i < brd->nasync; i++) {
6397 tty_port_init(&brd->serial_ports[i]);
6398 tty_port_init(&brd->printer_ports[i]);
6401 ch = brd->channels[0];
6402 for (i = 0; i < brd->nasync; i++, ch = brd->channels[i]) {
6403 struct device *classp;
6405 classp = tty_port_register_device(&brd->serial_ports[i],
6409 if (IS_ERR(classp)) {
6410 ret = PTR_ERR(classp);
6411 goto unregister_ttys;
6414 dgap_create_tty_sysfs(&ch->ch_tun, classp);
6415 ch->ch_tun.un_sysfs = classp;
6417 classp = tty_port_register_device(&brd->printer_ports[i],
6421 if (IS_ERR(classp)) {
6422 ret = PTR_ERR(classp);
6423 goto unregister_ttys;
6426 dgap_create_tty_sysfs(&ch->ch_pun, classp);
6427 ch->ch_pun.un_sysfs = classp;
6429 dgap_create_ports_sysfiles(brd);
6435 ch = brd->channels[i];
6436 if (ch->ch_tun.un_sysfs) {
6437 dgap_remove_tty_sysfs(ch->ch_tun.un_sysfs);
6438 tty_unregister_device(brd->serial_driver, i);
6441 if (ch->ch_pun.un_sysfs) {
6442 dgap_remove_tty_sysfs(ch->ch_pun.un_sysfs);
6443 tty_unregister_device(brd->print_driver, i);
6448 for (i = 0; i < brd->nasync; i++) {
6449 tty_port_destroy(&brd->serial_ports[i]);
6450 tty_port_destroy(&brd->printer_ports[i]);
6453 kfree(brd->printer_ports);
6454 brd->printer_ports = NULL;
6457 kfree(brd->serial_ports);
6458 brd->serial_ports = NULL;
6464 * dgap_cleanup_tty()
6466 * Uninitialize the TTY portion of this driver. Free all memory and
6469 static void dgap_cleanup_tty(struct board_t *brd)
6474 for (i = 0; i < brd->nasync; i++) {
6475 tty_port_destroy(&brd->serial_ports[i]);
6476 dev = brd->channels[i]->ch_tun.un_sysfs;
6477 dgap_remove_tty_sysfs(dev);
6478 tty_unregister_device(brd->serial_driver, i);
6480 tty_unregister_driver(brd->serial_driver);
6481 put_tty_driver(brd->serial_driver);
6482 kfree(brd->serial_ports);
6484 for (i = 0; i < brd->nasync; i++) {
6485 tty_port_destroy(&brd->printer_ports[i]);
6486 dev = brd->channels[i]->ch_pun.un_sysfs;
6487 dgap_remove_tty_sysfs(dev);
6488 tty_unregister_device(brd->print_driver, i);
6490 tty_unregister_driver(brd->print_driver);
6491 put_tty_driver(brd->print_driver);
6492 kfree(brd->printer_ports);
6495 static int dgap_request_irq(struct board_t *brd)
6499 if (!brd || brd->magic != DGAP_BOARD_MAGIC)
6503 * Set up our interrupt handler if we are set to do interrupts.
6505 if (dgap_config_get_useintr(brd) && brd->irq) {
6506 rc = request_irq(brd->irq, dgap_intr, IRQF_SHARED, "DGAP", brd);
6514 static void dgap_free_irq(struct board_t *brd)
6516 if (brd->intr_used && brd->irq)
6517 free_irq(brd->irq, brd);
6520 static int dgap_firmware_load(struct pci_dev *pdev, int card_type,
6521 struct board_t *brd)
6523 const struct firmware *fw;
6526 char *dgap_config_buf;
6529 dgap_do_reset_board(brd);
6531 if (fw_info[card_type].conf_name) {
6532 ret = request_firmware(&fw, fw_info[card_type].conf_name,
6535 dev_err(&pdev->dev, "config file %s not found\n",
6536 fw_info[card_type].conf_name);
6540 dgap_config_buf = kzalloc(fw->size + 1, GFP_KERNEL);
6541 if (!dgap_config_buf) {
6542 release_firmware(fw);
6546 memcpy(dgap_config_buf, fw->data, fw->size);
6547 release_firmware(fw);
6550 * preserve dgap_config_buf
6551 * as dgap_parsefile would
6552 * otherwise alter it.
6554 tmp_ptr = dgap_config_buf;
6556 if (dgap_parsefile(&tmp_ptr) != 0) {
6557 kfree(dgap_config_buf);
6560 kfree(dgap_config_buf);
6564 * Match this board to a config the user created for us.
6567 dgap_find_config(brd->type, brd->pci_bus, brd->pci_slot);
6570 * Because the 4 port Xr products share the same PCI ID
6571 * as the 8 port Xr products, if we receive a NULL config
6572 * back, and this is a PAPORT8 board, retry with a
6573 * PAPORT4 attempt as well.
6575 if (brd->type == PAPORT8 && !brd->bd_config)
6577 dgap_find_config(PAPORT4, brd->pci_bus, brd->pci_slot);
6579 if (!brd->bd_config) {
6580 dev_err(&pdev->dev, "No valid configuration found\n");
6584 if (fw_info[card_type].bios_name) {
6585 ret = request_firmware(&fw, fw_info[card_type].bios_name,
6588 dev_err(&pdev->dev, "bios file %s not found\n",
6589 fw_info[card_type].bios_name);
6592 dgap_do_bios_load(brd, fw->data, fw->size);
6593 release_firmware(fw);
6595 /* Wait for BIOS to test board... */
6596 ret = dgap_test_bios(brd);
6601 if (fw_info[card_type].fep_name) {
6602 ret = request_firmware(&fw, fw_info[card_type].fep_name,
6605 dev_err(&pdev->dev, "dgap: fep file %s not found\n",
6606 fw_info[card_type].fep_name);
6609 dgap_do_fep_load(brd, fw->data, fw->size);
6610 release_firmware(fw);
6612 /* Wait for FEP to load on board... */
6613 ret = dgap_test_fep(brd);
6618 #ifdef DIGI_CONCENTRATORS_SUPPORTED
6620 * If this is a CX or EPCX, we need to see if the firmware
6621 * is requesting a concentrator image from us.
6623 if ((bd->type == PCX) || (bd->type == PEPC)) {
6624 chk_addr = (u16 *)(vaddr + DOWNREQ);
6625 /* Nonzero if FEP is requesting concentrator image. */
6626 check = readw(chk_addr);
6627 vaddr = brd->re_map_membase;
6630 if (fw_info[card_type].con_name && check && vaddr) {
6631 ret = request_firmware(&fw, fw_info[card_type].con_name,
6634 dev_err(&pdev->dev, "conc file %s not found\n",
6635 fw_info[card_type].con_name);
6638 /* Put concentrator firmware loading code here */
6639 offset = readw((u16 *)(vaddr + DOWNREQ));
6640 memcpy_toio(offset, fw->data, fw->size);
6642 dgap_do_conc_load(brd, (char *)fw->data, fw->size)
6643 release_firmware(fw);
6653 * Init the tty subsystem. Called once per board after board has been
6654 * downloaded and init'ed.
6656 static int dgap_tty_init(struct board_t *brd)
6663 struct channel_t *ch;
6664 struct bs_t __iomem *bs;
6665 struct cm_t __iomem *cm;
6669 * Initialize board structure elements.
6672 vaddr = brd->re_map_membase;
6673 true_count = readw((vaddr + NCHAN));
6675 brd->nasync = dgap_config_get_num_prts(brd);
6678 brd->nasync = brd->maxports;
6680 if (brd->nasync > brd->maxports)
6681 brd->nasync = brd->maxports;
6683 if (true_count != brd->nasync) {
6684 dev_warn(&brd->pdev->dev,
6685 "%s configured for %d ports, has %d ports.\n",
6686 brd->name, brd->nasync, true_count);
6688 if ((brd->type == PPCM) &&
6689 (true_count == 64 || true_count == 0)) {
6690 dev_warn(&brd->pdev->dev,
6691 "Please make SURE the EBI cable running from the card\n");
6692 dev_warn(&brd->pdev->dev,
6693 "to each EM module is plugged into EBI IN!\n");
6696 brd->nasync = true_count;
6698 /* If no ports, don't bother going any further */
6700 brd->state = BOARD_FAILED;
6701 brd->dpastatus = BD_NOFEP;
6707 * Allocate channel memory that might not have been allocated
6708 * when the driver was first loaded.
6710 for (i = 0; i < brd->nasync; i++) {
6712 kzalloc(sizeof(struct channel_t), GFP_KERNEL);
6713 if (!brd->channels[i]) {
6719 ch = brd->channels[0];
6720 vaddr = brd->re_map_membase;
6722 bs = (struct bs_t __iomem *)((ulong)vaddr + CHANBUF);
6723 cm = (struct cm_t __iomem *)((ulong)vaddr + CMDBUF);
6727 /* Set up channel variables */
6728 for (i = 0; i < brd->nasync; i++, ch = brd->channels[i], bs++) {
6729 spin_lock_init(&ch->ch_lock);
6731 /* Store all our magic numbers */
6732 ch->magic = DGAP_CHANNEL_MAGIC;
6733 ch->ch_tun.magic = DGAP_UNIT_MAGIC;
6734 ch->ch_tun.un_type = DGAP_SERIAL;
6735 ch->ch_tun.un_ch = ch;
6736 ch->ch_tun.un_dev = i;
6738 ch->ch_pun.magic = DGAP_UNIT_MAGIC;
6739 ch->ch_pun.un_type = DGAP_PRINT;
6740 ch->ch_pun.un_ch = ch;
6741 ch->ch_pun.un_dev = i;
6743 ch->ch_vaddr = vaddr;
6748 ch->ch_digi = dgap_digi_init;
6751 * Set up digi dsr and dcd bits based on altpin flag.
6753 if (dgap_config_get_altpin(brd)) {
6756 ch->ch_digi.digi_flags |= DIGI_ALTPIN;
6759 ch->ch_dsr = DM_DSR;
6762 ch->ch_taddr = vaddr + (ioread16(&ch->ch_bs->tx_seg) << 4);
6763 ch->ch_raddr = vaddr + (ioread16(&ch->ch_bs->rx_seg) << 4);
6766 ch->ch_tsize = readw(&ch->ch_bs->tx_max) + 1;
6767 ch->ch_rsize = readw(&ch->ch_bs->rx_max) + 1;
6772 * Set queue water marks, interrupt mask,
6773 * and general tty parameters.
6775 tlw = ch->ch_tsize >= 2000 ? ((ch->ch_tsize * 5) / 8) :
6779 dgap_cmdw(ch, STLOW, tlw, 0);
6781 dgap_cmdw(ch, SRLOW, ch->ch_rsize / 2, 0);
6783 dgap_cmdw(ch, SRHIGH, 7 * ch->ch_rsize / 8, 0);
6785 ch->ch_mistat = readb(&ch->ch_bs->m_stat);
6787 init_waitqueue_head(&ch->ch_flags_wait);
6788 init_waitqueue_head(&ch->ch_tun.un_flags_wait);
6789 init_waitqueue_head(&ch->ch_pun.un_flags_wait);
6791 /* Turn on all modem interrupts for now */
6792 modem = (DM_CD | DM_DSR | DM_CTS | DM_RI);
6793 writeb(modem, &ch->ch_bs->m_int);
6796 * Set edelay to 0 if interrupts are turned on,
6797 * otherwise set edelay to the usual 100.
6800 writew(0, &ch->ch_bs->edelay);
6802 writew(100, &ch->ch_bs->edelay);
6804 writeb(1, &ch->ch_bs->idata);
6811 kfree(brd->channels[i]);
6812 brd->channels[i] = NULL;
6820 * Free the channles which are allocated in dgap_tty_init().
6822 static void dgap_tty_free(struct board_t *brd)
6826 for (i = 0; i < brd->nasync; i++)
6827 kfree(brd->channels[i]);
6830 static int dgap_init_one(struct pci_dev *pdev, const struct pci_device_id *ent)
6833 struct board_t *brd;
6835 if (dgap_numboards >= MAXBOARDS)
6838 rc = pci_enable_device(pdev);
6842 brd = dgap_found_board(pdev, ent->driver_data, dgap_numboards);
6844 return PTR_ERR(brd);
6846 rc = dgap_firmware_load(pdev, ent->driver_data, brd);
6850 rc = dgap_alloc_flipbuf(brd);
6854 rc = dgap_tty_register(brd);
6858 rc = dgap_request_irq(brd);
6860 goto unregister_tty;
6863 * Do tty device initialization.
6865 rc = dgap_tty_init(brd);
6869 rc = dgap_tty_register_ports(brd);
6873 brd->state = BOARD_READY;
6874 brd->dpastatus = BD_RUNNING;
6876 dgap_board[dgap_numboards++] = brd;
6885 dgap_tty_unregister(brd);
6887 dgap_free_flipbuf(brd);
6889 dgap_cleanup_nodes();
6897 * dgap_cleanup_board()
6899 * Free all the memory associated with a board
6901 static void dgap_cleanup_board(struct board_t *brd)
6905 if (!brd || brd->magic != DGAP_BOARD_MAGIC)
6910 tasklet_kill(&brd->helper_tasklet);
6914 /* Free all allocated channels structs */
6915 for (i = 0; i < MAXPORTS ; i++)
6916 kfree(brd->channels[i]);
6918 kfree(brd->flipbuf);
6919 kfree(brd->flipflagbuf);
6921 dgap_board[brd->boardnum] = NULL;
6926 static void dgap_stop(bool removesys, struct pci_driver *drv)
6928 unsigned long lock_flags;
6930 spin_lock_irqsave(&dgap_poll_lock, lock_flags);
6932 spin_unlock_irqrestore(&dgap_poll_lock, lock_flags);
6934 del_timer_sync(&dgap_poll_timer);
6936 dgap_remove_driver_sysfiles(drv);
6938 device_destroy(dgap_class, MKDEV(DIGI_DGAP_MAJOR, 0));
6939 class_destroy(dgap_class);
6940 unregister_chrdev(DIGI_DGAP_MAJOR, "dgap");
6943 static void dgap_remove_one(struct pci_dev *dev)
6946 struct pci_driver *drv = to_pci_driver(dev->dev.driver);
6948 dgap_stop(true, drv);
6949 for (i = 0; i < dgap_numboards; ++i) {
6950 dgap_remove_ports_sysfiles(dgap_board[i]);
6951 dgap_cleanup_tty(dgap_board[i]);
6952 dgap_cleanup_board(dgap_board[i]);
6955 dgap_cleanup_nodes();
6958 static struct pci_driver dgap_driver = {
6960 .probe = dgap_init_one,
6961 .id_table = dgap_pci_tbl,
6962 .remove = dgap_remove_one,
6968 static int dgap_start(void)
6971 unsigned long flags;
6972 struct device *device;
6976 pr_info("For the tools package please visit http://www.digi.com\n");
6979 * Register our base character device into the kernel.
6983 * Register management/dpa devices
6985 rc = register_chrdev(DIGI_DGAP_MAJOR, "dgap", &dgap_board_fops);
6989 dgap_class = class_create(THIS_MODULE, "dgap_mgmt");
6990 if (IS_ERR(dgap_class)) {
6991 rc = PTR_ERR(dgap_class);
6995 device = device_create(dgap_class, NULL,
6996 MKDEV(DIGI_DGAP_MAJOR, 0),
6998 if (IS_ERR(device)) {
6999 rc = PTR_ERR(device);
7003 /* Start the poller */
7004 spin_lock_irqsave(&dgap_poll_lock, flags);
7005 setup_timer(&dgap_poll_timer, dgap_poll_handler, 0);
7006 dgap_poll_timer.data = 0;
7007 dgap_poll_time = jiffies + dgap_jiffies_from_ms(dgap_poll_tick);
7008 dgap_poll_timer.expires = dgap_poll_time;
7009 spin_unlock_irqrestore(&dgap_poll_lock, flags);
7011 add_timer(&dgap_poll_timer);
7016 class_destroy(dgap_class);
7018 unregister_chrdev(DIGI_DGAP_MAJOR, "dgap");
7022 /************************************************************************
7024 * Driver load/unload functions
7026 ************************************************************************/
7031 * Module load. This is where it all starts.
7033 static int dgap_init_module(void)
7037 pr_info("%s, Digi International Part Number %s\n", DG_NAME, DG_PART);
7043 rc = pci_register_driver(&dgap_driver);
7045 dgap_stop(false, NULL);
7049 rc = dgap_create_driver_sysfiles(&dgap_driver);
7051 goto err_unregister;
7053 dgap_driver_state = DRIVER_READY;
7058 pci_unregister_driver(&dgap_driver);
7063 * dgap_cleanup_module()
7065 * Module unload. This is where it all ends.
7067 static void dgap_cleanup_module(void)
7070 pci_unregister_driver(&dgap_driver);
7073 module_init(dgap_init_module);
7074 module_exit(dgap_cleanup_module);
7076 MODULE_LICENSE("GPL");
7077 MODULE_AUTHOR("Digi International, http://www.digi.com");
7078 MODULE_DESCRIPTION("Driver for the Digi International EPCA PCI based product line");
7079 MODULE_SUPPORTED_DEVICE("dgap");