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" },
252 { PCIINFO, "pciinfo" },
255 { CONC, "concentrator" },
265 { CONNECT, "connect" },
266 { METHOD, "method" },
267 { STATUS, "status" },
268 { CUSTOM, "Custom" },
274 { NPORTS, "nports" },
279 { ALTPIN, "altpin" },
280 { USEINTR, "useintr" },
281 { TTSIZ, "ttysize" },
283 { BSSIZ, "boardsize" },
284 { UNTSIZ, "schedsize" },
285 { F2SIZ, "f2200size" },
286 { VPSIZ, "vpixsize" },
292 * dgap_sindex: much like index(), but it looks for a match of any character in
293 * the group, and returns that position.
295 static char *dgap_sindex(char *string, char *group)
299 if (!string || !group)
302 for (; *string; string++) {
303 for (ptr = group; *ptr; ptr++) {
313 * get a word from the input stream, also keep track of current line number.
314 * words are separated by whitespace.
316 static char *dgap_getword(char **in)
320 char *ptr = dgap_sindex(*in, " \t\n");
322 /* If no word found, return null */
326 /* Mark new location for our buffer */
330 /* Eat any extra spaces/tabs/newlines that might be present */
331 while (*in && **in && ((**in == ' ') ||
343 * Get a token from the input file; return 0 if end of file is reached
345 static int dgap_gettok(char **in)
350 if (strstr(dgap_cword, "board")) {
351 w = dgap_getword(in);
352 snprintf(dgap_cword, MAXCWORD, "%s", w);
353 for (t = dgap_brdtype; t->token != 0; t++) {
354 if (!strcmp(w, t->string))
358 while ((w = dgap_getword(in))) {
359 snprintf(dgap_cword, MAXCWORD, "%s", w);
360 for (t = dgap_tlist; t->token != 0; t++) {
361 if (!strcmp(w, t->string))
371 * dgap_checknode: see if all the necessary info has been supplied for a node
372 * before creating the next node.
374 static int dgap_checknode(struct cnode *p)
378 if (p->u.line.v_speed == 0) {
379 pr_err("line speed not specified");
385 if (p->u.conc.v_speed == 0) {
386 pr_err("concentrator line speed not specified");
389 if (p->u.conc.v_nport == 0) {
390 pr_err("number of ports on concentrator not specified");
393 if (p->u.conc.v_id == 0) {
394 pr_err("concentrator id letter not specified");
400 if (p->u.module.v_nport == 0) {
401 pr_err("number of ports on EBI module not specified");
404 if (p->u.module.v_id == 0) {
405 pr_err("EBI module id letter not specified");
414 * Given a board pointer, returns whether we should use interrupts or not.
416 static uint dgap_config_get_useintr(struct board_t *bd)
423 for (p = bd->bd_config; p; p = p->next) {
424 if (p->type == INTRNODE) {
426 * check for pcxr types.
432 /* If not found, then don't turn on interrupts. */
437 * Given a board pointer, returns whether we turn on altpin or not.
439 static uint dgap_config_get_altpin(struct board_t *bd)
446 for (p = bd->bd_config; p; p = p->next) {
447 if (p->type == ANODE) {
449 * check for pcxr types.
455 /* If not found, then don't turn on interrupts. */
460 * Given a specific type of board, if found, detached link and
461 * returns the first occurrence in the list.
463 static struct cnode *dgap_find_config(int type, int bus, int slot)
465 struct cnode *p, *prev, *prev2, *found;
473 if (p->type != BNODE)
476 if (p->u.board.type != type)
479 if (p->u.board.v_pcibus &&
480 p->u.board.pcibus != bus)
483 if (p->u.board.v_pcislot &&
484 p->u.board.pcislot != slot)
489 * Keep walking thru the list till we
490 * find the next board.
496 if (p->type != BNODE)
500 * Mark the end of our 1 board
506 * Link the "next" board to the
507 * previous board, effectively
508 * "unlinking" our board from
516 * It must be the last board in the list.
525 * Given a board pointer, walks the config link, counting up
526 * all ports user specified should be on the board.
527 * (This does NOT mean they are all actually present right now tho)
529 static uint dgap_config_get_num_prts(struct board_t *bd)
537 for (p = bd->bd_config; p; p = p->next) {
542 * check for pcxr types.
544 if (p->u.board.type > EPCFE)
545 count += p->u.board.nport;
548 count += p->u.conc.nport;
551 count += p->u.module.nport;
558 static char *dgap_create_config_string(struct board_t *bd, char *string)
570 for (p = bd->bd_config; p; p = p->next) {
576 *ptr = p->u.line.speed;
581 * Because the EPC/con concentrators can have EM modules
582 * hanging off of them, we have to walk ahead in the
583 * list and keep adding the number of ports on each EM
584 * to the config. UGH!
586 speed = p->u.conc.speed;
588 if (q && (q->type == MNODE)) {
589 *ptr = (p->u.conc.nport + 0x80);
592 while (q->next && (q->next->type) == MNODE) {
593 *ptr = (q->u.module.nport + 0x80);
598 *ptr = q->u.module.nport;
601 *ptr = p->u.conc.nport;
616 * Parse a configuration file read into memory as a string.
618 static int dgap_parsefile(char **in)
620 struct cnode *p, *brd, *line, *conc;
626 brd = line = conc = NULL;
628 /* perhaps we are adding to an existing list? */
632 /* file must start with a BEGIN */
633 while ((rc = dgap_gettok(in)) != BEGIN) {
635 pr_err("unexpected EOF");
645 rc = dgap_gettok(in);
647 pr_err("unexpected EOF");
652 case BEGIN: /* should only be 1 begin */
653 pr_err("unexpected config_begin\n");
659 case BOARD: /* board info */
660 if (dgap_checknode(p))
663 p->next = kzalloc(sizeof(struct cnode), GFP_KERNEL);
670 p->u.board.status = kstrdup("No", GFP_KERNEL);
675 board_type = dgap_gettok(in);
676 if (board_type == 0) {
677 pr_err("board !!type not specified");
681 p->u.board.type = board_type;
685 case IO: /* i/o port */
686 if (p->type != BNODE) {
687 pr_err("IO port only valid for boards");
690 s = dgap_getword(in);
692 pr_err("unexpected end of file");
695 p->u.board.portstr = kstrdup(s, GFP_KERNEL);
696 if (kstrtol(s, 0, &p->u.board.port)) {
697 pr_err("bad number for IO port");
700 p->u.board.v_port = 1;
703 case MEM: /* memory address */
704 if (p->type != BNODE) {
705 pr_err("memory address only valid for boards");
708 s = dgap_getword(in);
710 pr_err("unexpected end of file");
713 p->u.board.addrstr = kstrdup(s, GFP_KERNEL);
714 if (kstrtoul(s, 0, &p->u.board.addr)) {
715 pr_err("bad number for memory address");
718 p->u.board.v_addr = 1;
721 case PCIINFO: /* pci information */
722 if (p->type != BNODE) {
723 pr_err("memory address only valid for boards");
726 s = dgap_getword(in);
728 pr_err("unexpected end of file");
731 p->u.board.pcibusstr = kstrdup(s, GFP_KERNEL);
732 if (kstrtoul(s, 0, &p->u.board.pcibus)) {
733 pr_err("bad number for pci bus");
736 p->u.board.v_pcibus = 1;
737 s = dgap_getword(in);
739 pr_err("unexpected end of file");
742 p->u.board.pcislotstr = kstrdup(s, GFP_KERNEL);
743 if (kstrtoul(s, 0, &p->u.board.pcislot)) {
744 pr_err("bad number for pci slot");
747 p->u.board.v_pcislot = 1;
751 if (p->type != BNODE) {
752 pr_err("install method only valid for boards");
755 s = dgap_getword(in);
757 pr_err("unexpected end of file");
760 p->u.board.method = kstrdup(s, GFP_KERNEL);
761 p->u.board.v_method = 1;
765 if (p->type != BNODE) {
766 pr_err("config status only valid for boards");
769 s = dgap_getword(in);
771 pr_err("unexpected end of file");
774 p->u.board.status = kstrdup(s, GFP_KERNEL);
777 case NPORTS: /* number of ports */
778 if (p->type == BNODE) {
779 s = dgap_getword(in);
781 pr_err("unexpected end of file");
784 if (kstrtol(s, 0, &p->u.board.nport)) {
785 pr_err("bad number for number of ports");
788 p->u.board.v_nport = 1;
789 } else if (p->type == CNODE) {
790 s = dgap_getword(in);
792 pr_err("unexpected end of file");
795 if (kstrtol(s, 0, &p->u.conc.nport)) {
796 pr_err("bad number for number of ports");
799 p->u.conc.v_nport = 1;
800 } else if (p->type == MNODE) {
801 s = dgap_getword(in);
803 pr_err("unexpected end of file");
806 if (kstrtol(s, 0, &p->u.module.nport)) {
807 pr_err("bad number for number of ports");
810 p->u.module.v_nport = 1;
812 pr_err("nports only valid for concentrators or modules");
817 case ID: /* letter ID used in tty name */
818 s = dgap_getword(in);
820 pr_err("unexpected end of file");
824 p->u.board.status = kstrdup(s, GFP_KERNEL);
826 if (p->type == CNODE) {
827 p->u.conc.id = kstrdup(s, GFP_KERNEL);
829 } else if (p->type == MNODE) {
830 p->u.module.id = kstrdup(s, GFP_KERNEL);
831 p->u.module.v_id = 1;
833 pr_err("id only valid for concentrators or modules");
838 case STARTO: /* start offset of ID */
839 if (p->type == BNODE) {
840 s = dgap_getword(in);
842 pr_err("unexpected end of file");
845 if (kstrtol(s, 0, &p->u.board.start)) {
846 pr_err("bad number for start of tty count");
849 p->u.board.v_start = 1;
850 } else if (p->type == CNODE) {
851 s = dgap_getword(in);
853 pr_err("unexpected end of file");
856 if (kstrtol(s, 0, &p->u.conc.start)) {
857 pr_err("bad number for start of tty count");
860 p->u.conc.v_start = 1;
861 } else if (p->type == MNODE) {
862 s = dgap_getword(in);
864 pr_err("unexpected end of file");
867 if (kstrtol(s, 0, &p->u.module.start)) {
868 pr_err("bad number for start of tty count");
871 p->u.module.v_start = 1;
873 pr_err("start only valid for concentrators or modules");
878 case TTYN: /* tty name prefix */
879 if (dgap_checknode(p))
882 p->next = kzalloc(sizeof(struct cnode), GFP_KERNEL);
889 s = dgap_getword(in);
891 pr_err("unexpeced end of file");
894 p->u.ttyname = kstrdup(s, GFP_KERNEL);
900 case CU: /* cu name prefix */
901 if (dgap_checknode(p))
904 p->next = kzalloc(sizeof(struct cnode), GFP_KERNEL);
911 s = dgap_getword(in);
913 pr_err("unexpeced end of file");
916 p->u.cuname = kstrdup(s, GFP_KERNEL);
922 case LINE: /* line information */
923 if (dgap_checknode(p))
926 pr_err("must specify board before line info");
929 switch (brd->u.board.type) {
931 pr_err("line not valid for PC/em");
935 p->next = kzalloc(sizeof(struct cnode), GFP_KERNEL);
946 case CONC: /* concentrator information */
947 if (dgap_checknode(p))
950 pr_err("must specify line info before concentrator");
954 p->next = kzalloc(sizeof(struct cnode), GFP_KERNEL);
963 brd->u.board.conc2++;
965 brd->u.board.conc1++;
967 conc_type = dgap_gettok(in);
968 if (conc_type == 0 || (conc_type != CX &&
970 pr_err("failed to set a type of concentratros");
974 p->u.conc.type = conc_type;
978 case MOD: /* EBI module */
979 if (dgap_checknode(p))
982 pr_err("must specify board info before EBI modules");
985 switch (brd->u.board.type) {
991 pr_err("must specify concentrator info before EBI module");
996 p->next = kzalloc(sizeof(struct cnode), GFP_KERNEL);
1004 brd->u.board.module2++;
1006 brd->u.board.module1++;
1008 module_type = dgap_gettok(in);
1009 if (module_type == 0 || (module_type != PORTS &&
1010 module_type != MODEM)) {
1011 pr_err("failed to set a type of module");
1015 p->u.module.type = module_type;
1020 if (p->type == LNODE) {
1021 s = dgap_getword(in);
1023 pr_err("unexpected end of file");
1026 p->u.line.cable = kstrdup(s, GFP_KERNEL);
1027 p->u.line.v_cable = 1;
1031 case SPEED: /* sync line speed indication */
1032 if (p->type == LNODE) {
1033 s = dgap_getword(in);
1035 pr_err("unexpected end of file");
1038 if (kstrtol(s, 0, &p->u.line.speed)) {
1039 pr_err("bad number for line speed");
1042 p->u.line.v_speed = 1;
1043 } else if (p->type == CNODE) {
1044 s = dgap_getword(in);
1046 pr_err("unexpected end of file");
1049 if (kstrtol(s, 0, &p->u.conc.speed)) {
1050 pr_err("bad number for line speed");
1053 p->u.conc.v_speed = 1;
1055 pr_err("speed valid only for lines or concentrators.");
1061 if (p->type == CNODE) {
1062 s = dgap_getword(in);
1064 pr_err("unexpected end of file");
1067 p->u.conc.connect = kstrdup(s, GFP_KERNEL);
1068 p->u.conc.v_connect = 1;
1071 case PRINT: /* transparent print name prefix */
1072 if (dgap_checknode(p))
1075 p->next = kzalloc(sizeof(struct cnode), GFP_KERNEL);
1082 s = dgap_getword(in);
1084 pr_err("unexpeced end of file");
1087 p->u.printname = kstrdup(s, GFP_KERNEL);
1088 if (!p->u.printname)
1093 case CMAJOR: /* major number */
1094 if (dgap_checknode(p))
1097 p->next = kzalloc(sizeof(struct cnode), GFP_KERNEL);
1104 s = dgap_getword(in);
1106 pr_err("unexpected end of file");
1109 if (kstrtol(s, 0, &p->u.majornumber)) {
1110 pr_err("bad number for major number");
1115 case ALTPIN: /* altpin setting */
1116 if (dgap_checknode(p))
1119 p->next = kzalloc(sizeof(struct cnode), GFP_KERNEL);
1126 s = dgap_getword(in);
1128 pr_err("unexpected end of file");
1131 if (kstrtol(s, 0, &p->u.altpin)) {
1132 pr_err("bad number for altpin");
1137 case USEINTR: /* enable interrupt setting */
1138 if (dgap_checknode(p))
1141 p->next = kzalloc(sizeof(struct cnode), GFP_KERNEL);
1147 s = dgap_getword(in);
1149 pr_err("unexpected end of file");
1152 if (kstrtol(s, 0, &p->u.useintr)) {
1153 pr_err("bad number for useintr");
1158 case TTSIZ: /* size of tty structure */
1159 if (dgap_checknode(p))
1162 p->next = kzalloc(sizeof(struct cnode), GFP_KERNEL);
1169 s = dgap_getword(in);
1171 pr_err("unexpected end of file");
1174 if (kstrtol(s, 0, &p->u.ttysize)) {
1175 pr_err("bad number for ttysize");
1180 case CHSIZ: /* channel structure size */
1181 if (dgap_checknode(p))
1184 p->next = kzalloc(sizeof(struct cnode), GFP_KERNEL);
1191 s = dgap_getword(in);
1193 pr_err("unexpected end of file");
1196 if (kstrtol(s, 0, &p->u.chsize)) {
1197 pr_err("bad number for chsize");
1202 case BSSIZ: /* board structure size */
1203 if (dgap_checknode(p))
1206 p->next = kzalloc(sizeof(struct cnode), GFP_KERNEL);
1213 s = dgap_getword(in);
1215 pr_err("unexpected end of file");
1218 if (kstrtol(s, 0, &p->u.bssize)) {
1219 pr_err("bad number for bssize");
1224 case UNTSIZ: /* sched structure size */
1225 if (dgap_checknode(p))
1228 p->next = kzalloc(sizeof(struct cnode), GFP_KERNEL);
1235 s = dgap_getword(in);
1237 pr_err("unexpected end of file");
1240 if (kstrtol(s, 0, &p->u.unsize)) {
1241 pr_err("bad number for schedsize");
1246 case F2SIZ: /* f2200 structure size */
1247 if (dgap_checknode(p))
1250 p->next = kzalloc(sizeof(struct cnode), GFP_KERNEL);
1257 s = dgap_getword(in);
1259 pr_err("unexpected end of file");
1262 if (kstrtol(s, 0, &p->u.f2size)) {
1263 pr_err("bad number for f2200size");
1268 case VPSIZ: /* vpix structure size */
1269 if (dgap_checknode(p))
1272 p->next = kzalloc(sizeof(struct cnode), GFP_KERNEL);
1279 s = dgap_getword(in);
1281 pr_err("unexpected end of file");
1284 if (kstrtol(s, 0, &p->u.vpixsize)) {
1285 pr_err("bad number for vpixsize");
1293 static void dgap_cleanup_nodes(void)
1300 struct cnode *tmp = p->next;
1302 if (p->type == NULLNODE) {
1309 kfree(p->u.board.portstr);
1310 kfree(p->u.board.addrstr);
1311 kfree(p->u.board.pcibusstr);
1312 kfree(p->u.board.pcislotstr);
1313 kfree(p->u.board.method);
1316 kfree(p->u.conc.id);
1317 kfree(p->u.conc.connect);
1320 kfree(p->u.module.id);
1323 kfree(p->u.ttyname);
1329 kfree(p->u.line.cable);
1332 kfree(p->u.printname);
1336 kfree(p->u.board.status);
1343 * Retrives the current custom baud rate from FEP memory,
1344 * and returns it back to the user.
1345 * Returns 0 on error.
1347 static uint dgap_get_custom_baud(struct channel_t *ch)
1352 if (!ch || ch->magic != DGAP_CHANNEL_MAGIC)
1355 if (!ch->ch_bd || ch->ch_bd->magic != DGAP_BOARD_MAGIC)
1358 if (!(ch->ch_bd->bd_flags & BD_FEP5PLUS))
1361 vaddr = ch->ch_bd->re_map_membase;
1367 * Go get from fep mem, what the fep
1368 * believes the custom baud rate is.
1370 offset = (ioread16(vaddr + ECS_SEG) << 4) + (ch->ch_portnum * 0x28)
1373 return readw(vaddr + offset);
1379 static int dgap_remap(struct board_t *brd)
1381 if (!brd || brd->magic != DGAP_BOARD_MAGIC)
1384 if (!request_mem_region(brd->membase, 0x200000, "dgap"))
1387 if (!request_mem_region(brd->membase + PCI_IO_OFFSET, 0x200000,
1391 brd->re_map_membase = ioremap(brd->membase, 0x200000);
1392 if (!brd->re_map_membase)
1395 brd->re_map_port = ioremap((brd->membase + PCI_IO_OFFSET), 0x200000);
1396 if (!brd->re_map_port)
1397 goto err_remap_port;
1402 iounmap(brd->re_map_membase);
1404 release_mem_region(brd->membase + PCI_IO_OFFSET, 0x200000);
1406 release_mem_region(brd->membase, 0x200000);
1411 static void dgap_unmap(struct board_t *brd)
1413 iounmap(brd->re_map_port);
1414 iounmap(brd->re_map_membase);
1415 release_mem_region(brd->membase + PCI_IO_OFFSET, 0x200000);
1416 release_mem_region(brd->membase, 0x200000);
1420 * dgap_parity_scan()
1422 * Convert the FEP5 way of reporting parity errors and breaks into
1423 * the Linux line discipline way.
1425 static void dgap_parity_scan(struct channel_t *ch, unsigned char *cbuf,
1426 unsigned char *fbuf, int *len)
1430 unsigned char *in, *cout, *fout;
1437 if (!ch || ch->magic != DGAP_CHANNEL_MAGIC)
1442 switch (ch->pscan_state) {
1444 /* reset to sanity and fall through */
1445 ch->pscan_state = 0;
1448 /* No FF seen yet */
1449 if (c == (unsigned char) '\377')
1450 /* delete this character from stream */
1451 ch->pscan_state = 1;
1454 *fout++ = TTY_NORMAL;
1461 if (c == (unsigned char) '\377') {
1462 /* doubled ff, transform to single ff */
1464 *fout++ = TTY_NORMAL;
1466 ch->pscan_state = 0;
1468 /* save value examination in next state */
1469 ch->pscan_savechar = c;
1470 ch->pscan_state = 2;
1475 /* third character of ff sequence */
1479 if (ch->pscan_savechar == 0x0) {
1483 *fout++ = TTY_BREAK;
1485 ch->ch_err_parity++;
1486 *fout++ = TTY_PARITY;
1491 ch->pscan_state = 0;
1497 /*=======================================================================
1499 * dgap_input - Process received data.
1501 * ch - Pointer to channel structure.
1503 *=======================================================================*/
1505 static void dgap_input(struct channel_t *ch)
1508 struct bs_t __iomem *bs;
1509 struct tty_struct *tp;
1510 struct tty_ldisc *ld;
1524 if (!ch || ch->magic != DGAP_CHANNEL_MAGIC)
1527 tp = ch->ch_tun.un_tty;
1534 if (!bd || bd->magic != DGAP_BOARD_MAGIC)
1537 spin_lock_irqsave(&bd->bd_lock, lock_flags);
1538 spin_lock_irqsave(&ch->ch_lock, lock_flags2);
1541 * Figure the number of characters in the buffer.
1542 * Exit immediately if none.
1545 rmask = ch->ch_rsize - 1;
1547 head = readw(&(bs->rx_head));
1549 tail = readw(&(bs->rx_tail));
1552 data_len = (head - tail) & rmask;
1554 if (data_len == 0) {
1555 writeb(1, &(bs->idata));
1556 spin_unlock_irqrestore(&ch->ch_lock, lock_flags2);
1557 spin_unlock_irqrestore(&bd->bd_lock, lock_flags);
1562 * If the device is not open, or CREAD is off, flush
1563 * input data and return immediately.
1565 if ((bd->state != BOARD_READY) || !tp ||
1566 (tp->magic != TTY_MAGIC) ||
1567 !(ch->ch_tun.un_flags & UN_ISOPEN) ||
1568 !(tp->termios.c_cflag & CREAD) ||
1569 (ch->ch_tun.un_flags & UN_CLOSING)) {
1571 writew(head, &(bs->rx_tail));
1572 writeb(1, &(bs->idata));
1573 spin_unlock_irqrestore(&ch->ch_lock, lock_flags2);
1574 spin_unlock_irqrestore(&bd->bd_lock, lock_flags);
1579 * If we are throttled, simply don't read any data.
1581 if (ch->ch_flags & CH_RXBLOCK) {
1582 writeb(1, &(bs->idata));
1583 spin_unlock_irqrestore(&ch->ch_lock, lock_flags2);
1584 spin_unlock_irqrestore(&bd->bd_lock, lock_flags);
1591 tmpchar = readb(&(bs->orun));
1593 ch->ch_err_overrun++;
1594 writeb(0, &(bs->orun));
1597 /* Decide how much data we can send into the tty layer */
1598 flip_len = TTY_FLIPBUF_SIZE;
1600 /* Chop down the length, if needed */
1601 len = min(data_len, flip_len);
1602 len = min(len, (N_TTY_BUF_SIZE - 1));
1604 ld = tty_ldisc_ref(tp);
1606 #ifdef TTY_DONT_FLIP
1608 * If the DONT_FLIP flag is on, don't flush our buffer, and act
1609 * like the ld doesn't have any space to put the data right now.
1611 if (test_bit(TTY_DONT_FLIP, &tp->flags))
1616 * If we were unable to get a reference to the ld,
1617 * don't flush our buffer, and act like the ld doesn't
1618 * have any space to put the data right now.
1624 * If ld doesn't have a pointer to a receive_buf function,
1625 * flush the data, then act like the ld doesn't have any
1626 * space to put the data right now.
1628 if (!ld->ops->receive_buf) {
1629 writew(head, &(bs->rx_tail));
1635 writeb(1, &(bs->idata));
1636 spin_unlock_irqrestore(&ch->ch_lock, lock_flags2);
1637 spin_unlock_irqrestore(&bd->bd_lock, lock_flags);
1639 tty_ldisc_deref(ld);
1643 buf = ch->ch_bd->flipbuf;
1647 * n now contains the most amount of data we can copy,
1648 * bounded either by our buffer size or the amount
1649 * of data the card actually has pending...
1653 s = ((head >= tail) ? head : ch->ch_rsize) - tail;
1659 memcpy_fromio(buf, ch->ch_raddr + tail, s);
1665 /* Flip queue if needed */
1669 writew(tail, &(bs->rx_tail));
1670 writeb(1, &(bs->idata));
1671 ch->ch_rxcount += len;
1674 * If we are completely raw, we don't need to go through a lot
1675 * of the tty layers that exist.
1676 * In this case, we take the shortest and fastest route we
1677 * can to relay the data to the user.
1679 * On the other hand, if we are not raw, we need to go through
1680 * the tty layer, which has its API more well defined.
1682 if (I_PARMRK(tp) || I_BRKINT(tp) || I_INPCK(tp)) {
1683 dgap_parity_scan(ch, ch->ch_bd->flipbuf,
1684 ch->ch_bd->flipflagbuf, &len);
1686 len = tty_buffer_request_room(tp->port, len);
1687 tty_insert_flip_string_flags(tp->port, ch->ch_bd->flipbuf,
1688 ch->ch_bd->flipflagbuf, len);
1690 len = tty_buffer_request_room(tp->port, len);
1691 tty_insert_flip_string(tp->port, ch->ch_bd->flipbuf, len);
1694 spin_unlock_irqrestore(&ch->ch_lock, lock_flags2);
1695 spin_unlock_irqrestore(&bd->bd_lock, lock_flags);
1697 /* Tell the tty layer its okay to "eat" the data now */
1698 tty_flip_buffer_push(tp->port);
1701 tty_ldisc_deref(ld);
1705 static void dgap_write_wakeup(struct board_t *bd, struct channel_t *ch,
1706 struct un_t *un, u32 mask,
1707 unsigned long *irq_flags1,
1708 unsigned long *irq_flags2)
1710 if (!(un->un_flags & mask))
1713 un->un_flags &= ~mask;
1715 if (!(un->un_flags & UN_ISOPEN))
1718 if ((un->un_tty->flags & (1 << TTY_DO_WRITE_WAKEUP)) &&
1719 un->un_tty->ldisc->ops->write_wakeup) {
1720 spin_unlock_irqrestore(&ch->ch_lock, *irq_flags2);
1721 spin_unlock_irqrestore(&bd->bd_lock, *irq_flags1);
1723 (un->un_tty->ldisc->ops->write_wakeup)(un->un_tty);
1725 spin_lock_irqsave(&bd->bd_lock, *irq_flags1);
1726 spin_lock_irqsave(&ch->ch_lock, *irq_flags2);
1728 wake_up_interruptible(&un->un_tty->write_wait);
1729 wake_up_interruptible(&un->un_flags_wait);
1732 /************************************************************************
1733 * Determines when CARRIER changes state and takes appropriate
1735 ************************************************************************/
1736 static void dgap_carrier(struct channel_t *ch)
1740 int virt_carrier = 0;
1741 int phys_carrier = 0;
1743 if (!ch || ch->magic != DGAP_CHANNEL_MAGIC)
1748 if (!bd || bd->magic != DGAP_BOARD_MAGIC)
1751 /* Make sure altpin is always set correctly */
1752 if (ch->ch_digi.digi_flags & DIGI_ALTPIN) {
1756 ch->ch_dsr = DM_DSR;
1760 if (ch->ch_mistat & D_CD(ch))
1763 if (ch->ch_digi.digi_flags & DIGI_FORCEDCD)
1766 if (ch->ch_c_cflag & CLOCAL)
1770 * Test for a VIRTUAL carrier transition to HIGH.
1772 if (((ch->ch_flags & CH_FCAR) == 0) && (virt_carrier == 1)) {
1775 * When carrier rises, wake any threads waiting
1776 * for carrier in the open routine.
1779 if (waitqueue_active(&(ch->ch_flags_wait)))
1780 wake_up_interruptible(&ch->ch_flags_wait);
1784 * Test for a PHYSICAL carrier transition to HIGH.
1786 if (((ch->ch_flags & CH_CD) == 0) && (phys_carrier == 1)) {
1789 * When carrier rises, wake any threads waiting
1790 * for carrier in the open routine.
1793 if (waitqueue_active(&(ch->ch_flags_wait)))
1794 wake_up_interruptible(&ch->ch_flags_wait);
1798 * Test for a PHYSICAL transition to low, so long as we aren't
1799 * currently ignoring physical transitions (which is what "virtual
1800 * carrier" indicates).
1802 * The transition of the virtual carrier to low really doesn't
1803 * matter... it really only means "ignore carrier state", not
1804 * "make pretend that carrier is there".
1806 if ((virt_carrier == 0) &&
1807 ((ch->ch_flags & CH_CD) != 0) &&
1808 (phys_carrier == 0)) {
1811 * When carrier drops:
1813 * Drop carrier on all open units.
1815 * Flush queues, waking up any task waiting in the
1818 * Send a hangup to the control terminal.
1820 * Enable all select calls.
1822 if (waitqueue_active(&(ch->ch_flags_wait)))
1823 wake_up_interruptible(&ch->ch_flags_wait);
1825 if (ch->ch_tun.un_open_count > 0)
1826 tty_hangup(ch->ch_tun.un_tty);
1828 if (ch->ch_pun.un_open_count > 0)
1829 tty_hangup(ch->ch_pun.un_tty);
1833 * Make sure that our cached values reflect the current reality.
1835 if (virt_carrier == 1)
1836 ch->ch_flags |= CH_FCAR;
1838 ch->ch_flags &= ~CH_FCAR;
1840 if (phys_carrier == 1)
1841 ch->ch_flags |= CH_CD;
1843 ch->ch_flags &= ~CH_CD;
1846 /*=======================================================================
1848 * dgap_event - FEP to host event processing routine.
1850 * bd - Board of current event.
1852 *=======================================================================*/
1853 static int dgap_event(struct board_t *bd)
1855 struct channel_t *ch;
1858 struct bs_t __iomem *bs;
1861 struct ev_t __iomem *eaddr;
1869 if (!bd || bd->magic != DGAP_BOARD_MAGIC)
1872 spin_lock_irqsave(&bd->bd_lock, lock_flags);
1874 vaddr = bd->re_map_membase;
1877 spin_unlock_irqrestore(&bd->bd_lock, lock_flags);
1881 eaddr = (struct ev_t __iomem *) (vaddr + EVBUF);
1883 /* Get our head and tail */
1884 head = readw(&(eaddr->ev_head));
1885 tail = readw(&(eaddr->ev_tail));
1888 * Forget it if pointers out of range.
1891 if (head >= EVMAX - EVSTART || tail >= EVMAX - EVSTART ||
1892 (head | tail) & 03) {
1893 /* Let go of board lock */
1894 spin_unlock_irqrestore(&bd->bd_lock, lock_flags);
1899 * Loop to process all the events in the buffer.
1901 while (tail != head) {
1904 * Get interrupt information.
1907 event = bd->re_map_membase + tail + EVSTART;
1909 port = ioread8(event);
1910 reason = ioread8(event + 1);
1911 modem = ioread8(event + 2);
1912 b1 = ioread8(event + 3);
1915 * Make sure the interrupt is valid.
1917 if (port >= bd->nasync)
1920 if (!(reason & (IFMODEM | IFBREAK | IFTLW | IFTEM | IFDATA)))
1923 ch = bd->channels[port];
1925 if (!ch || ch->magic != DGAP_CHANNEL_MAGIC)
1929 * If we have made it here, the event was valid.
1930 * Lock down the channel.
1932 spin_lock_irqsave(&ch->ch_lock, lock_flags2);
1937 spin_unlock_irqrestore(&ch->ch_lock, lock_flags2);
1942 * Process received data.
1944 if (reason & IFDATA) {
1947 * ALL LOCKS *MUST* BE DROPPED BEFORE CALLING INPUT!
1948 * input could send some data to ld, which in turn
1949 * could do a callback to one of our other functions.
1951 spin_unlock_irqrestore(&ch->ch_lock, lock_flags2);
1952 spin_unlock_irqrestore(&bd->bd_lock, lock_flags);
1956 spin_lock_irqsave(&bd->bd_lock, lock_flags);
1957 spin_lock_irqsave(&ch->ch_lock, lock_flags2);
1959 if (ch->ch_flags & CH_RACTIVE)
1960 ch->ch_flags |= CH_RENABLE;
1962 writeb(1, &(bs->idata));
1964 if (ch->ch_flags & CH_RWAIT) {
1965 ch->ch_flags &= ~CH_RWAIT;
1967 wake_up_interruptible
1968 (&ch->ch_tun.un_flags_wait);
1973 * Process Modem change signals.
1975 if (reason & IFMODEM) {
1976 ch->ch_mistat = modem;
1983 if (reason & IFBREAK) {
1985 if (ch->ch_tun.un_tty) {
1986 /* A break has been indicated */
1988 tty_buffer_request_room
1989 (ch->ch_tun.un_tty->port, 1);
1990 tty_insert_flip_char(ch->ch_tun.un_tty->port,
1992 tty_flip_buffer_push(ch->ch_tun.un_tty->port);
1997 * Process Transmit low.
1999 if (reason & IFTLW) {
2000 dgap_write_wakeup(bd, ch, &ch->ch_tun, UN_LOW,
2001 &lock_flags, &lock_flags2);
2002 dgap_write_wakeup(bd, ch, &ch->ch_pun, UN_LOW,
2003 &lock_flags, &lock_flags2);
2004 if (ch->ch_flags & CH_WLOW) {
2005 ch->ch_flags &= ~CH_WLOW;
2006 wake_up_interruptible(&ch->ch_flags_wait);
2011 * Process Transmit empty.
2013 if (reason & IFTEM) {
2014 dgap_write_wakeup(bd, ch, &ch->ch_tun, UN_EMPTY,
2015 &lock_flags, &lock_flags2);
2016 dgap_write_wakeup(bd, ch, &ch->ch_pun, UN_EMPTY,
2017 &lock_flags, &lock_flags2);
2018 if (ch->ch_flags & CH_WEMPTY) {
2019 ch->ch_flags &= ~CH_WEMPTY;
2020 wake_up_interruptible(&ch->ch_flags_wait);
2024 spin_unlock_irqrestore(&ch->ch_lock, lock_flags2);
2027 tail = (tail + 4) & (EVMAX - EVSTART - 4);
2030 writew(tail, &(eaddr->ev_tail));
2031 spin_unlock_irqrestore(&bd->bd_lock, lock_flags);
2037 * Our board poller function.
2039 static void dgap_poll_tasklet(unsigned long data)
2041 struct board_t *bd = (struct board_t *) data;
2043 char __iomem *vaddr;
2046 if (!bd || (bd->magic != DGAP_BOARD_MAGIC))
2049 if (bd->inhibit_poller)
2052 spin_lock_irqsave(&bd->bd_lock, lock_flags);
2054 vaddr = bd->re_map_membase;
2057 * If board is ready, parse deeper to see if there is anything to do.
2059 if (bd->state == BOARD_READY) {
2061 struct ev_t __iomem *eaddr;
2063 if (!bd->re_map_membase) {
2064 spin_unlock_irqrestore(&bd->bd_lock, lock_flags);
2067 if (!bd->re_map_port) {
2068 spin_unlock_irqrestore(&bd->bd_lock, lock_flags);
2075 eaddr = (struct ev_t __iomem *) (vaddr + EVBUF);
2077 /* Get our head and tail */
2078 head = readw(&(eaddr->ev_head));
2079 tail = readw(&(eaddr->ev_tail));
2082 * If there is an event pending. Go service it.
2085 spin_unlock_irqrestore(&bd->bd_lock, lock_flags);
2087 spin_lock_irqsave(&bd->bd_lock, lock_flags);
2092 * If board is doing interrupts, ACK the interrupt.
2094 if (bd && bd->intr_running)
2095 readb(bd->re_map_port + 2);
2097 spin_unlock_irqrestore(&bd->bd_lock, lock_flags);
2101 spin_unlock_irqrestore(&bd->bd_lock, lock_flags);
2105 * dgap_found_board()
2107 * A board has been found, init it.
2109 static struct board_t *dgap_found_board(struct pci_dev *pdev, int id,
2112 struct board_t *brd;
2113 unsigned int pci_irq;
2117 /* get the board structure and prep it */
2118 brd = kzalloc(sizeof(struct board_t), GFP_KERNEL);
2120 return ERR_PTR(-ENOMEM);
2122 /* store the info for the board we've found */
2123 brd->magic = DGAP_BOARD_MAGIC;
2124 brd->boardnum = boardnum;
2125 brd->vendor = dgap_pci_tbl[id].vendor;
2126 brd->device = dgap_pci_tbl[id].device;
2128 brd->pci_bus = pdev->bus->number;
2129 brd->pci_slot = PCI_SLOT(pdev->devfn);
2130 brd->name = dgap_ids[id].name;
2131 brd->maxports = dgap_ids[id].maxports;
2132 brd->type = dgap_ids[id].config_type;
2133 brd->dpatype = dgap_ids[id].dpatype;
2134 brd->dpastatus = BD_NOFEP;
2135 init_waitqueue_head(&brd->state_wait);
2137 spin_lock_init(&brd->bd_lock);
2139 brd->inhibit_poller = FALSE;
2140 brd->wait_for_bios = 0;
2141 brd->wait_for_fep = 0;
2143 for (i = 0; i < MAXPORTS; i++)
2144 brd->channels[i] = NULL;
2146 /* store which card & revision we have */
2147 pci_read_config_word(pdev, PCI_SUBSYSTEM_VENDOR_ID, &brd->subvendor);
2148 pci_read_config_word(pdev, PCI_SUBSYSTEM_ID, &brd->subdevice);
2149 pci_read_config_byte(pdev, PCI_REVISION_ID, &brd->rev);
2151 pci_irq = pdev->irq;
2154 /* get the PCI Base Address Registers */
2156 /* Xr Jupiter and EPC use BAR 2 */
2157 if (brd->device == PCI_DEV_XRJ_DID || brd->device == PCI_DEV_EPCJ_DID) {
2158 brd->membase = pci_resource_start(pdev, 2);
2159 brd->membase_end = pci_resource_end(pdev, 2);
2161 /* Everyone else uses BAR 0 */
2163 brd->membase = pci_resource_start(pdev, 0);
2164 brd->membase_end = pci_resource_end(pdev, 0);
2167 if (!brd->membase) {
2172 if (brd->membase & 1)
2175 brd->membase &= ~15;
2178 * On the PCI boards, there is no IO space allocated
2179 * The I/O registers will be in the first 3 bytes of the
2180 * upper 2MB of the 4MB memory space. The board memory
2181 * will be mapped into the low 2MB of the 4MB memory space
2183 brd->port = brd->membase + PCI_IO_OFFSET;
2184 brd->port_end = brd->port + PCI_IO_SIZE_DGAP;
2187 * Special initialization for non-PLX boards
2189 if (brd->device != PCI_DEV_XRJ_DID && brd->device != PCI_DEV_EPCJ_DID) {
2192 pci_write_config_byte(pdev, 0x40, 0);
2193 pci_write_config_byte(pdev, 0x46, 0);
2195 /* Limit burst length to 2 doubleword transactions */
2196 pci_write_config_byte(pdev, 0x42, 1);
2199 * Enable IO and mem if not already done.
2200 * This was needed for support on Itanium.
2202 pci_read_config_word(pdev, PCI_COMMAND, &cmd);
2203 cmd |= (PCI_COMMAND_IO | PCI_COMMAND_MEMORY);
2204 pci_write_config_word(pdev, PCI_COMMAND, cmd);
2207 /* init our poll helper tasklet */
2208 tasklet_init(&brd->helper_tasklet, dgap_poll_tasklet,
2209 (unsigned long) brd);
2211 ret = dgap_remap(brd);
2215 pr_info("dgap: board %d: %s (rev %d), irq %ld\n",
2216 boardnum, brd->name, brd->rev, brd->irq);
2223 return ERR_PTR(ret);
2229 * Driver interrupt handler.
2231 static irqreturn_t dgap_intr(int irq, void *voidbrd)
2233 struct board_t *brd = voidbrd;
2239 * Check to make sure its for us.
2241 if (brd->magic != DGAP_BOARD_MAGIC)
2247 * Schedule tasklet to run at a better time.
2249 tasklet_schedule(&brd->helper_tasklet);
2253 /*****************************************************************************
2273 * As each timer expires, it determines (a) whether the "transmit"
2274 * waiter needs to be woken up, and (b) whether the poller needs to
2277 ******************************************************************************/
2279 static void dgap_poll_handler(ulong dummy)
2282 struct board_t *brd;
2283 unsigned long lock_flags;
2286 dgap_poll_counter++;
2289 * Do not start the board state machine until
2290 * driver tells us its up and running, and has
2291 * everything it needs.
2293 if (dgap_driver_state != DRIVER_READY)
2294 goto schedule_poller;
2297 * If we have just 1 board, or the system is not SMP,
2298 * then use the typical old style poller.
2299 * Otherwise, use our new tasklet based poller, which should
2300 * speed things up for multiple boards.
2302 if ((dgap_numboards == 1) || (num_online_cpus() <= 1)) {
2303 for (i = 0; i < dgap_numboards; i++) {
2305 brd = dgap_board[i];
2307 if (brd->state == BOARD_FAILED)
2309 if (!brd->intr_running)
2310 /* Call the real board poller directly */
2311 dgap_poll_tasklet((unsigned long) brd);
2315 * Go thru each board, kicking off a
2316 * tasklet for each if needed
2318 for (i = 0; i < dgap_numboards; i++) {
2319 brd = dgap_board[i];
2322 * Attempt to grab the board lock.
2324 * If we can't get it, no big deal, the next poll
2325 * will get it. Basically, I just really don't want
2326 * to spin in here, because I want to kick off my
2327 * tasklets as fast as I can, and then get out the
2330 if (!spin_trylock(&brd->bd_lock))
2334 * If board is in a failed state, don't bother
2335 * scheduling a tasklet
2337 if (brd->state == BOARD_FAILED) {
2338 spin_unlock(&brd->bd_lock);
2342 /* Schedule a poll helper task */
2343 if (!brd->intr_running)
2344 tasklet_schedule(&brd->helper_tasklet);
2347 * Can't do DGAP_UNLOCK here, as we don't have
2348 * lock_flags because we did a trylock above.
2350 spin_unlock(&brd->bd_lock);
2357 * Schedule ourself back at the nominal wakeup interval.
2359 spin_lock_irqsave(&dgap_poll_lock, lock_flags);
2360 dgap_poll_time += dgap_jiffies_from_ms(dgap_poll_tick);
2362 new_time = dgap_poll_time - jiffies;
2364 if ((ulong) new_time >= 2 * dgap_poll_tick) {
2366 jiffies + dgap_jiffies_from_ms(dgap_poll_tick);
2369 dgap_poll_timer.function = dgap_poll_handler;
2370 dgap_poll_timer.data = 0;
2371 dgap_poll_timer.expires = dgap_poll_time;
2372 spin_unlock_irqrestore(&dgap_poll_lock, lock_flags);
2374 if (!dgap_poll_stop)
2375 add_timer(&dgap_poll_timer);
2378 /*=======================================================================
2380 * dgap_cmdb - Sends a 2 byte command to the FEP.
2382 * ch - Pointer to channel structure.
2383 * cmd - Command to be sent.
2384 * byte1 - Integer containing first byte to be sent.
2385 * byte2 - Integer containing second byte to be sent.
2386 * ncmds - Wait until ncmds or fewer cmds are left
2387 * in the cmd buffer before returning.
2389 *=======================================================================*/
2390 static void dgap_cmdb(struct channel_t *ch, u8 cmd, u8 byte1,
2391 u8 byte2, uint ncmds)
2393 char __iomem *vaddr;
2394 struct __iomem cm_t *cm_addr;
2400 if (!ch || ch->magic != DGAP_CHANNEL_MAGIC)
2404 * Check if board is still alive.
2406 if (ch->ch_bd->state == BOARD_FAILED)
2410 * Make sure the pointers are in range before
2411 * writing to the FEP memory.
2413 vaddr = ch->ch_bd->re_map_membase;
2418 cm_addr = (struct cm_t __iomem *) (vaddr + CMDBUF);
2419 head = readw(&(cm_addr->cm_head));
2422 * Forget it if pointers out of range.
2424 if (head >= (CMDMAX - CMDSTART) || (head & 03)) {
2425 ch->ch_bd->state = BOARD_FAILED;
2430 * Put the data in the circular command buffer.
2432 writeb(cmd, (vaddr + head + CMDSTART + 0));
2433 writeb((u8) ch->ch_portnum, (vaddr + head + CMDSTART + 1));
2434 writeb(byte1, (vaddr + head + CMDSTART + 2));
2435 writeb(byte2, (vaddr + head + CMDSTART + 3));
2437 head = (head + 4) & (CMDMAX - CMDSTART - 4);
2439 writew(head, &(cm_addr->cm_head));
2442 * Wait if necessary before updating the head
2443 * pointer to limit the number of outstanding
2444 * commands to the FEP. If the time spent waiting
2445 * is outlandish, declare the FEP dead.
2447 for (count = dgap_count ;;) {
2449 head = readw(&(cm_addr->cm_head));
2450 tail = readw(&(cm_addr->cm_tail));
2452 n = (head - tail) & (CMDMAX - CMDSTART - 4);
2454 if (n <= ncmds * sizeof(struct cm_t))
2458 ch->ch_bd->state = BOARD_FAILED;
2465 /*=======================================================================
2467 * dgap_cmdw - Sends a 1 word command to the FEP.
2469 * ch - Pointer to channel structure.
2470 * cmd - Command to be sent.
2471 * word - Integer containing word to be sent.
2472 * ncmds - Wait until ncmds or fewer cmds are left
2473 * in the cmd buffer before returning.
2475 *=======================================================================*/
2476 static void dgap_cmdw(struct channel_t *ch, u8 cmd, u16 word, uint ncmds)
2478 char __iomem *vaddr;
2479 struct __iomem cm_t *cm_addr;
2485 if (!ch || ch->magic != DGAP_CHANNEL_MAGIC)
2489 * Check if board is still alive.
2491 if (ch->ch_bd->state == BOARD_FAILED)
2495 * Make sure the pointers are in range before
2496 * writing to the FEP memory.
2498 vaddr = ch->ch_bd->re_map_membase;
2502 cm_addr = (struct cm_t __iomem *) (vaddr + CMDBUF);
2503 head = readw(&(cm_addr->cm_head));
2506 * Forget it if pointers out of range.
2508 if (head >= (CMDMAX - CMDSTART) || (head & 03)) {
2509 ch->ch_bd->state = BOARD_FAILED;
2514 * Put the data in the circular command buffer.
2516 writeb(cmd, (vaddr + head + CMDSTART + 0));
2517 writeb((u8) ch->ch_portnum, (vaddr + head + CMDSTART + 1));
2518 writew((u16) word, (vaddr + head + CMDSTART + 2));
2520 head = (head + 4) & (CMDMAX - CMDSTART - 4);
2522 writew(head, &(cm_addr->cm_head));
2525 * Wait if necessary before updating the head
2526 * pointer to limit the number of outstanding
2527 * commands to the FEP. If the time spent waiting
2528 * is outlandish, declare the FEP dead.
2530 for (count = dgap_count ;;) {
2532 head = readw(&(cm_addr->cm_head));
2533 tail = readw(&(cm_addr->cm_tail));
2535 n = (head - tail) & (CMDMAX - CMDSTART - 4);
2537 if (n <= ncmds * sizeof(struct cm_t))
2541 ch->ch_bd->state = BOARD_FAILED;
2548 /*=======================================================================
2550 * dgap_cmdw_ext - Sends a extended word command to the FEP.
2552 * ch - Pointer to channel structure.
2553 * cmd - Command to be sent.
2554 * word - Integer containing word to be sent.
2555 * ncmds - Wait until ncmds or fewer cmds are left
2556 * in the cmd buffer before returning.
2558 *=======================================================================*/
2559 static void dgap_cmdw_ext(struct channel_t *ch, u16 cmd, u16 word, uint ncmds)
2561 char __iomem *vaddr;
2562 struct __iomem cm_t *cm_addr;
2568 if (!ch || ch->magic != DGAP_CHANNEL_MAGIC)
2572 * Check if board is still alive.
2574 if (ch->ch_bd->state == BOARD_FAILED)
2578 * Make sure the pointers are in range before
2579 * writing to the FEP memory.
2581 vaddr = ch->ch_bd->re_map_membase;
2585 cm_addr = (struct cm_t __iomem *) (vaddr + CMDBUF);
2586 head = readw(&(cm_addr->cm_head));
2589 * Forget it if pointers out of range.
2591 if (head >= (CMDMAX - CMDSTART) || (head & 03)) {
2592 ch->ch_bd->state = BOARD_FAILED;
2597 * Put the data in the circular command buffer.
2600 /* Write an FF to tell the FEP that we want an extended command */
2601 writeb((u8) 0xff, (vaddr + head + CMDSTART + 0));
2603 writeb((u8) ch->ch_portnum, (vaddr + head + CMDSTART + 1));
2604 writew((u16) cmd, (vaddr + head + CMDSTART + 2));
2607 * If the second part of the command won't fit,
2608 * put it at the beginning of the circular buffer.
2610 if (((head + 4) >= ((CMDMAX - CMDSTART)) || (head & 03)))
2611 writew((u16) word, (vaddr + CMDSTART));
2613 writew((u16) word, (vaddr + head + CMDSTART + 4));
2615 head = (head + 8) & (CMDMAX - CMDSTART - 4);
2617 writew(head, &(cm_addr->cm_head));
2620 * Wait if necessary before updating the head
2621 * pointer to limit the number of outstanding
2622 * commands to the FEP. If the time spent waiting
2623 * is outlandish, declare the FEP dead.
2625 for (count = dgap_count ;;) {
2627 head = readw(&(cm_addr->cm_head));
2628 tail = readw(&(cm_addr->cm_tail));
2630 n = (head - tail) & (CMDMAX - CMDSTART - 4);
2632 if (n <= ncmds * sizeof(struct cm_t))
2636 ch->ch_bd->state = BOARD_FAILED;
2643 /*=======================================================================
2645 * dgap_wmove - Write data to FEP buffer.
2647 * ch - Pointer to channel structure.
2648 * buf - Pointer to characters to be moved.
2649 * cnt - Number of characters to move.
2651 *=======================================================================*/
2652 static void dgap_wmove(struct channel_t *ch, char *buf, uint cnt)
2655 char __iomem *taddr;
2656 struct bs_t __iomem *bs;
2659 if (!ch || ch->magic != DGAP_CHANNEL_MAGIC)
2666 head = readw(&(bs->tx_head));
2669 * If pointers are out of range, just return.
2671 if ((cnt > ch->ch_tsize) ||
2672 (unsigned)(head - ch->ch_tstart) >= ch->ch_tsize)
2676 * If the write wraps over the top of the circular buffer,
2677 * move the portion up to the wrap point, and reset the
2678 * pointers to the bottom.
2680 n = ch->ch_tstart + ch->ch_tsize - head;
2684 taddr = ch->ch_taddr + head;
2685 memcpy_toio(taddr, buf, n);
2686 head = ch->ch_tstart;
2691 * Move rest of data.
2693 taddr = ch->ch_taddr + head;
2695 memcpy_toio(taddr, buf, n);
2698 writew(head, &(bs->tx_head));
2702 * Calls the firmware to reset this channel.
2704 static void dgap_firmware_reset_port(struct channel_t *ch)
2706 dgap_cmdb(ch, CHRESET, 0, 0, 0);
2709 * Now that the channel is reset, we need to make sure
2710 * all the current settings get reapplied to the port
2713 * So we will set the driver's cache of firmware
2714 * settings all to 0, and then call param.
2716 ch->ch_fepiflag = 0;
2717 ch->ch_fepcflag = 0;
2718 ch->ch_fepoflag = 0;
2719 ch->ch_fepstartc = 0;
2720 ch->ch_fepstopc = 0;
2721 ch->ch_fepastartc = 0;
2722 ch->ch_fepastopc = 0;
2727 /*=======================================================================
2729 * dgap_param - Set Digi parameters.
2731 * struct tty_struct * - TTY for port.
2733 *=======================================================================*/
2734 static int dgap_param(struct channel_t *ch, struct board_t *bd, u32 un_type)
2743 * If baud rate is zero, flush queues, and set mval to drop DTR.
2745 if ((ch->ch_c_cflag & (CBAUD)) == 0) {
2748 head = readw(&(ch->ch_bs->rx_head));
2749 writew(head, &(ch->ch_bs->rx_tail));
2752 head = readw(&(ch->ch_bs->tx_head));
2753 writew(head, &(ch->ch_bs->tx_tail));
2755 ch->ch_flags |= (CH_BAUD0);
2757 /* Drop RTS and DTR */
2758 ch->ch_mval &= ~(D_RTS(ch)|D_DTR(ch));
2759 mval = D_DTR(ch) | D_RTS(ch);
2760 ch->ch_baud_info = 0;
2762 } else if (ch->ch_custom_speed && (bd->bd_flags & BD_FEP5PLUS)) {
2764 * Tell the fep to do the command
2767 dgap_cmdw_ext(ch, 0xff01, ch->ch_custom_speed, 0);
2770 * Now go get from fep mem, what the fep
2771 * believes the custom baud rate is.
2773 ch->ch_custom_speed = dgap_get_custom_baud(ch);
2774 ch->ch_baud_info = ch->ch_custom_speed;
2776 /* Handle transition from B0 */
2777 if (ch->ch_flags & CH_BAUD0) {
2778 ch->ch_flags &= ~(CH_BAUD0);
2779 ch->ch_mval |= (D_RTS(ch)|D_DTR(ch));
2781 mval = D_DTR(ch) | D_RTS(ch);
2785 * Set baud rate, character size, and parity.
2793 ulong bauds[4][16] = {
2797 600, 1200, 1800, 2400,
2798 4800, 9600, 19200, 38400 },
2799 { /* slowbaud & CBAUDEX */
2800 0, 57600, 115200, 230400,
2801 460800, 150, 200, 921600,
2802 600, 1200, 1800, 2400,
2803 4800, 9600, 19200, 38400 },
2805 0, 57600, 76800, 115200,
2806 14400, 57600, 230400, 76800,
2807 115200, 230400, 28800, 460800,
2808 921600, 9600, 19200, 38400 },
2809 { /* fastbaud & CBAUDEX */
2810 0, 57600, 115200, 230400,
2811 460800, 150, 200, 921600,
2812 600, 1200, 1800, 2400,
2813 4800, 9600, 19200, 38400 }
2817 * Only use the TXPrint baud rate if the
2818 * terminal unit is NOT open
2820 if (!(ch->ch_tun.un_flags & UN_ISOPEN) &&
2821 un_type == DGAP_PRINT)
2822 baud = C_BAUD(ch->ch_pun.un_tty) & 0xff;
2824 baud = C_BAUD(ch->ch_tun.un_tty) & 0xff;
2826 if (ch->ch_c_cflag & CBAUDEX)
2829 if (ch->ch_digi.digi_flags & DIGI_FAST)
2834 if ((iindex >= 0) && (iindex < 4) &&
2835 (jindex >= 0) && (jindex < 16))
2836 baud = bauds[iindex][jindex];
2843 ch->ch_baud_info = baud;
2846 * CBAUD has bit position 0x1000 set these days to
2847 * indicate Linux baud rate remap.
2848 * We use a different bit assignment for high speed.
2849 * Clear this bit out while grabbing the parts of
2852 cflag = ch->ch_c_cflag & ((CBAUD ^ CBAUDEX) | PARODD | PARENB |
2856 * HUPCL bit is used by FEP to indicate fast baud
2857 * table is to be used.
2859 if ((ch->ch_digi.digi_flags & DIGI_FAST) ||
2860 (ch->ch_c_cflag & CBAUDEX))
2863 if ((ch->ch_c_cflag & CBAUDEX) &&
2864 !(ch->ch_digi.digi_flags & DIGI_FAST)) {
2866 * The below code is trying to guarantee that only
2867 * baud rates 115200, 230400, 460800, 921600 are
2868 * remapped. We use exclusive or because the various
2869 * baud rates share common bit positions and therefore
2870 * can't be tested for easily.
2872 tcflag_t tcflag = (ch->ch_c_cflag & CBAUD) | CBAUDEX;
2876 * Map high speed requests to index
2877 * into FEP's baud table
2907 cflag = (cflag & ~(CBAUD | CBAUDEX)) | baudpart;
2912 if (cflag != ch->ch_fepcflag) {
2913 ch->ch_fepcflag = (u16) (cflag & 0xffff);
2916 * Okay to have channel and board
2917 * locks held calling this
2919 dgap_cmdw(ch, SCFLAG, (u16) cflag, 0);
2922 /* Handle transition from B0 */
2923 if (ch->ch_flags & CH_BAUD0) {
2924 ch->ch_flags &= ~(CH_BAUD0);
2925 ch->ch_mval |= (D_RTS(ch)|D_DTR(ch));
2927 mval = D_DTR(ch) | D_RTS(ch);
2933 iflag = ch->ch_c_iflag & (IGNBRK | BRKINT | IGNPAR | PARMRK |
2934 INPCK | ISTRIP | IXON | IXANY | IXOFF);
2936 if ((ch->ch_startc == _POSIX_VDISABLE) ||
2937 (ch->ch_stopc == _POSIX_VDISABLE)) {
2938 iflag &= ~(IXON | IXOFF);
2939 ch->ch_c_iflag &= ~(IXON | IXOFF);
2943 * Only the IBM Xr card can switch between
2944 * 232 and 422 modes on the fly
2946 if (bd->device == PCI_DEV_XR_IBM_DID) {
2947 if (ch->ch_digi.digi_flags & DIGI_422)
2948 dgap_cmdb(ch, SCOMMODE, MODE_422, 0, 0);
2950 dgap_cmdb(ch, SCOMMODE, MODE_232, 0, 0);
2953 if (ch->ch_digi.digi_flags & DIGI_ALTPIN)
2956 if (iflag != ch->ch_fepiflag) {
2957 ch->ch_fepiflag = iflag;
2959 /* Okay to have channel and board locks held calling this */
2960 dgap_cmdw(ch, SIFLAG, (u16) ch->ch_fepiflag, 0);
2964 * Select hardware handshaking.
2968 if (ch->ch_c_cflag & CRTSCTS)
2969 hflow |= (D_RTS(ch) | D_CTS(ch));
2970 if (ch->ch_digi.digi_flags & RTSPACE)
2972 if (ch->ch_digi.digi_flags & DTRPACE)
2974 if (ch->ch_digi.digi_flags & CTSPACE)
2976 if (ch->ch_digi.digi_flags & DSRPACE)
2978 if (ch->ch_digi.digi_flags & DCDPACE)
2981 if (hflow != ch->ch_hflow) {
2982 ch->ch_hflow = hflow;
2984 /* Okay to have channel and board locks held calling this */
2985 dgap_cmdb(ch, SHFLOW, (u8) hflow, 0xff, 0);
2989 * Set RTS and/or DTR Toggle if needed,
2990 * but only if product is FEP5+ based.
2992 if (bd->bd_flags & BD_FEP5PLUS) {
2995 if (ch->ch_digi.digi_flags & DIGI_RTS_TOGGLE)
2996 hflow2 |= (D_RTS(ch));
2997 if (ch->ch_digi.digi_flags & DIGI_DTR_TOGGLE)
2998 hflow2 |= (D_DTR(ch));
3000 dgap_cmdw_ext(ch, 0xff03, hflow2, 0);
3004 * Set modem control lines.
3007 mval ^= ch->ch_mforce & (mval ^ ch->ch_mval);
3009 if (ch->ch_mostat ^ mval) {
3010 ch->ch_mostat = mval;
3012 /* Okay to have channel and board locks held calling this */
3013 dgap_cmdb(ch, SMODEM, (u8) mval, D_RTS(ch)|D_DTR(ch), 0);
3017 * Read modem signals, and then call carrier function.
3019 ch->ch_mistat = readb(&(ch->ch_bs->m_stat));
3023 * Set the start and stop characters.
3025 if (ch->ch_startc != ch->ch_fepstartc ||
3026 ch->ch_stopc != ch->ch_fepstopc) {
3027 ch->ch_fepstartc = ch->ch_startc;
3028 ch->ch_fepstopc = ch->ch_stopc;
3030 /* Okay to have channel and board locks held calling this */
3031 dgap_cmdb(ch, SFLOWC, ch->ch_fepstartc, ch->ch_fepstopc, 0);
3035 * Set the Auxiliary start and stop characters.
3037 if (ch->ch_astartc != ch->ch_fepastartc ||
3038 ch->ch_astopc != ch->ch_fepastopc) {
3039 ch->ch_fepastartc = ch->ch_astartc;
3040 ch->ch_fepastopc = ch->ch_astopc;
3042 /* Okay to have channel and board locks held calling this */
3043 dgap_cmdb(ch, SAFLOWC, ch->ch_fepastartc, ch->ch_fepastopc, 0);
3050 * dgap_block_til_ready()
3052 * Wait for DCD, if needed.
3054 static int dgap_block_til_ready(struct tty_struct *tty, struct file *file,
3055 struct channel_t *ch)
3061 int sleep_on_un_flags;
3063 if (!tty || tty->magic != TTY_MAGIC || !file || !ch ||
3064 ch->magic != DGAP_CHANNEL_MAGIC)
3067 un = tty->driver_data;
3068 if (!un || un->magic != DGAP_UNIT_MAGIC)
3071 spin_lock_irqsave(&ch->ch_lock, lock_flags);
3078 sleep_on_un_flags = 0;
3081 * If board has failed somehow during our sleep,
3084 if (ch->ch_bd->state == BOARD_FAILED) {
3089 /* If tty was hung up, break out of loop and set error. */
3090 if (tty_hung_up_p(file)) {
3096 * If either unit is in the middle of the fragile part of close,
3097 * we just cannot touch the channel safely.
3098 * Go back to sleep, knowing that when the channel can be
3099 * touched safely, the close routine will signal the
3100 * ch_wait_flags to wake us back up.
3102 if (!((ch->ch_tun.un_flags | ch->ch_pun.un_flags) &
3106 * Our conditions to leave cleanly and happily:
3107 * 1) NONBLOCKING on the tty is set.
3109 * 3) DCD (fake or real) is active.
3112 if (file->f_flags & O_NONBLOCK)
3115 if (tty->flags & (1 << TTY_IO_ERROR))
3118 if (ch->ch_flags & CH_CD)
3121 if (ch->ch_flags & CH_FCAR)
3124 sleep_on_un_flags = 1;
3128 * If there is a signal pending, the user probably
3129 * interrupted (ctrl-c) us.
3130 * Leave loop with error set.
3132 if (signal_pending(current)) {
3133 retval = -ERESTARTSYS;
3138 * Store the flags before we let go of channel lock
3140 if (sleep_on_un_flags)
3141 old_flags = ch->ch_tun.un_flags | ch->ch_pun.un_flags;
3143 old_flags = ch->ch_flags;
3146 * Let go of channel lock before calling schedule.
3147 * Our poller will get any FEP events and wake us up when DCD
3148 * eventually goes active.
3151 spin_unlock_irqrestore(&ch->ch_lock, lock_flags);
3154 * Wait for something in the flags to change
3155 * from the current value.
3157 if (sleep_on_un_flags) {
3158 retval = wait_event_interruptible(un->un_flags_wait,
3159 (old_flags != (ch->ch_tun.un_flags |
3160 ch->ch_pun.un_flags)));
3162 retval = wait_event_interruptible(ch->ch_flags_wait,
3163 (old_flags != ch->ch_flags));
3167 * We got woken up for some reason.
3168 * Before looping around, grab our channel lock.
3170 spin_lock_irqsave(&ch->ch_lock, lock_flags);
3175 spin_unlock_irqrestore(&ch->ch_lock, lock_flags);
3181 * dgap_tty_flush_buffer()
3183 * Flush Tx buffer (make in == out)
3185 static void dgap_tty_flush_buffer(struct tty_struct *tty)
3188 struct channel_t *ch;
3194 if (!tty || tty->magic != TTY_MAGIC)
3197 un = tty->driver_data;
3198 if (!un || un->magic != DGAP_UNIT_MAGIC)
3202 if (!ch || ch->magic != DGAP_CHANNEL_MAGIC)
3206 if (!bd || bd->magic != DGAP_BOARD_MAGIC)
3209 spin_lock_irqsave(&bd->bd_lock, lock_flags);
3210 spin_lock_irqsave(&ch->ch_lock, lock_flags2);
3212 ch->ch_flags &= ~CH_STOP;
3213 head = readw(&(ch->ch_bs->tx_head));
3214 dgap_cmdw(ch, FLUSHTX, (u16) head, 0);
3215 dgap_cmdw(ch, RESUMETX, 0, 0);
3216 if (ch->ch_tun.un_flags & (UN_LOW|UN_EMPTY)) {
3217 ch->ch_tun.un_flags &= ~(UN_LOW|UN_EMPTY);
3218 wake_up_interruptible(&ch->ch_tun.un_flags_wait);
3220 if (ch->ch_pun.un_flags & (UN_LOW|UN_EMPTY)) {
3221 ch->ch_pun.un_flags &= ~(UN_LOW|UN_EMPTY);
3222 wake_up_interruptible(&ch->ch_pun.un_flags_wait);
3225 spin_unlock_irqrestore(&ch->ch_lock, lock_flags2);
3226 spin_unlock_irqrestore(&bd->bd_lock, lock_flags);
3227 if (waitqueue_active(&tty->write_wait))
3228 wake_up_interruptible(&tty->write_wait);
3235 * Hangup the port. Like a close, but don't wait for output to drain.
3237 static void dgap_tty_hangup(struct tty_struct *tty)
3240 struct channel_t *ch;
3243 if (!tty || tty->magic != TTY_MAGIC)
3246 un = tty->driver_data;
3247 if (!un || un->magic != DGAP_UNIT_MAGIC)
3251 if (!ch || ch->magic != DGAP_CHANNEL_MAGIC)
3255 if (!bd || bd->magic != DGAP_BOARD_MAGIC)
3258 /* flush the transmit queues */
3259 dgap_tty_flush_buffer(tty);
3263 * dgap_tty_chars_in_buffer()
3265 * Return number of characters that have not been transmitted yet.
3267 * This routine is used by the line discipline to determine if there
3268 * is data waiting to be transmitted/drained/flushed or not.
3270 static int dgap_tty_chars_in_buffer(struct tty_struct *tty)
3273 struct channel_t *ch;
3275 struct bs_t __iomem *bs;
3278 u16 thead, ttail, tmask, chead, ctail;
3279 ulong lock_flags = 0;
3280 ulong lock_flags2 = 0;
3285 un = tty->driver_data;
3286 if (!un || un->magic != DGAP_UNIT_MAGIC)
3290 if (!ch || ch->magic != DGAP_CHANNEL_MAGIC)
3294 if (!bd || bd->magic != DGAP_BOARD_MAGIC)
3301 spin_lock_irqsave(&bd->bd_lock, lock_flags);
3302 spin_lock_irqsave(&ch->ch_lock, lock_flags2);
3304 tmask = (ch->ch_tsize - 1);
3306 /* Get Transmit queue pointers */
3307 thead = readw(&(bs->tx_head)) & tmask;
3308 ttail = readw(&(bs->tx_tail)) & tmask;
3310 /* Get tbusy flag */
3311 tbusy = readb(&(bs->tbusy));
3313 /* Get Command queue pointers */
3314 chead = readw(&(ch->ch_cm->cm_head));
3315 ctail = readw(&(ch->ch_cm->cm_tail));
3317 spin_unlock_irqrestore(&ch->ch_lock, lock_flags2);
3318 spin_unlock_irqrestore(&bd->bd_lock, lock_flags);
3321 * The only way we know for sure if there is no pending
3322 * data left to be transferred, is if:
3323 * 1) Transmit head and tail are equal (empty).
3324 * 2) Command queue head and tail are equal (empty).
3325 * 3) The "TBUSY" flag is 0. (Transmitter not busy).
3328 if ((ttail == thead) && (tbusy == 0) && (chead == ctail)) {
3332 chars = thead - ttail;
3334 chars = thead - ttail + ch->ch_tsize;
3336 * Fudge factor here.
3337 * If chars is zero, we know that the command queue had
3338 * something in it or tbusy was set. Because we cannot
3339 * be sure if there is still some data to be transmitted,
3340 * lets lie, and tell ld we have 1 byte left.
3344 * If TBUSY is still set, and our tx buffers are empty,
3345 * force the firmware to send me another wakeup after
3346 * TBUSY has been cleared.
3349 spin_lock_irqsave(&ch->ch_lock, lock_flags);
3350 un->un_flags |= UN_EMPTY;
3351 writeb(1, &(bs->iempty));
3352 spin_unlock_irqrestore(&ch->ch_lock,
3362 static int dgap_wait_for_drain(struct tty_struct *tty)
3364 struct channel_t *ch;
3366 struct bs_t __iomem *bs;
3369 ulong lock_flags = 0;
3371 if (!tty || tty->magic != TTY_MAGIC)
3374 un = tty->driver_data;
3375 if (!un || un->magic != DGAP_UNIT_MAGIC)
3379 if (!ch || ch->magic != DGAP_CHANNEL_MAGIC)
3386 /* Loop until data is drained */
3387 while (count != 0) {
3389 count = dgap_tty_chars_in_buffer(tty);
3394 /* Set flag waiting for drain */
3395 spin_lock_irqsave(&ch->ch_lock, lock_flags);
3396 un->un_flags |= UN_EMPTY;
3397 writeb(1, &(bs->iempty));
3398 spin_unlock_irqrestore(&ch->ch_lock, lock_flags);
3400 /* Go to sleep till we get woken up */
3401 ret = wait_event_interruptible(un->un_flags_wait,
3402 ((un->un_flags & UN_EMPTY) == 0));
3403 /* If ret is non-zero, user ctrl-c'ed us */
3408 spin_lock_irqsave(&ch->ch_lock, lock_flags);
3409 un->un_flags &= ~(UN_EMPTY);
3410 spin_unlock_irqrestore(&ch->ch_lock, lock_flags);
3418 * Reduces bytes_available to the max number of characters
3419 * that can be sent currently given the maxcps value, and
3420 * returns the new bytes_available. This only affects printer
3423 static int dgap_maxcps_room(struct channel_t *ch, struct un_t *un,
3424 int bytes_available)
3427 * If its not the Transparent print device, return
3428 * the full data amount.
3430 if (un->un_type != DGAP_PRINT)
3431 return bytes_available;
3433 if (ch->ch_digi.digi_maxcps > 0 && ch->ch_digi.digi_bufsize > 0) {
3435 unsigned long current_time = jiffies;
3436 unsigned long buffer_time = current_time +
3437 (HZ * ch->ch_digi.digi_bufsize) /
3438 ch->ch_digi.digi_maxcps;
3440 if (ch->ch_cpstime < current_time) {
3441 /* buffer is empty */
3442 ch->ch_cpstime = current_time; /* reset ch_cpstime */
3443 cps_limit = ch->ch_digi.digi_bufsize;
3444 } else if (ch->ch_cpstime < buffer_time) {
3445 /* still room in the buffer */
3446 cps_limit = ((buffer_time - ch->ch_cpstime) *
3447 ch->ch_digi.digi_maxcps) / HZ;
3449 /* no room in the buffer */
3453 bytes_available = min(cps_limit, bytes_available);
3456 return bytes_available;
3459 static inline void dgap_set_firmware_event(struct un_t *un, unsigned int event)
3461 struct channel_t *ch;
3462 struct bs_t __iomem *bs;
3464 if (!un || un->magic != DGAP_UNIT_MAGIC)
3467 if (!ch || ch->magic != DGAP_CHANNEL_MAGIC)
3473 if ((event & UN_LOW) != 0) {
3474 if ((un->un_flags & UN_LOW) == 0) {
3475 un->un_flags |= UN_LOW;
3476 writeb(1, &(bs->ilow));
3479 if ((event & UN_LOW) != 0) {
3480 if ((un->un_flags & UN_EMPTY) == 0) {
3481 un->un_flags |= UN_EMPTY;
3482 writeb(1, &(bs->iempty));
3488 * dgap_tty_write_room()
3490 * Return space available in Tx buffer
3492 static int dgap_tty_write_room(struct tty_struct *tty)
3494 struct channel_t *ch;
3496 struct bs_t __iomem *bs;
3497 u16 head, tail, tmask;
3499 ulong lock_flags = 0;
3504 un = tty->driver_data;
3505 if (!un || un->magic != DGAP_UNIT_MAGIC)
3509 if (!ch || ch->magic != DGAP_CHANNEL_MAGIC)
3516 spin_lock_irqsave(&ch->ch_lock, lock_flags);
3518 tmask = ch->ch_tsize - 1;
3519 head = readw(&(bs->tx_head)) & tmask;
3520 tail = readw(&(bs->tx_tail)) & tmask;
3522 ret = tail - head - 1;
3524 ret += ch->ch_tsize;
3526 /* Limit printer to maxcps */
3527 ret = dgap_maxcps_room(ch, un, ret);
3530 * If we are printer device, leave space for
3531 * possibly both the on and off strings.
3533 if (un->un_type == DGAP_PRINT) {
3534 if (!(ch->ch_flags & CH_PRON))
3535 ret -= ch->ch_digi.digi_onlen;
3536 ret -= ch->ch_digi.digi_offlen;
3538 if (ch->ch_flags & CH_PRON)
3539 ret -= ch->ch_digi.digi_offlen;
3546 * Schedule FEP to wake us up if needed.
3548 * TODO: This might be overkill...
3549 * Do we really need to schedule callbacks from the FEP
3550 * in every case? Can we get smarter based on ret?
3552 dgap_set_firmware_event(un, UN_LOW | UN_EMPTY);
3553 spin_unlock_irqrestore(&ch->ch_lock, lock_flags);
3561 * Take data from the user or kernel and send it out to the FEP.
3562 * In here exists all the Transparent Print magic as well.
3564 static int dgap_tty_write(struct tty_struct *tty, const unsigned char *buf,
3567 struct channel_t *ch;
3569 struct bs_t __iomem *bs;
3570 char __iomem *vaddr;
3571 u16 head, tail, tmask, remain;
3578 un = tty->driver_data;
3579 if (!un || un->magic != DGAP_UNIT_MAGIC)
3583 if (!ch || ch->magic != DGAP_CHANNEL_MAGIC)
3593 spin_lock_irqsave(&ch->ch_lock, lock_flags);
3595 /* Get our space available for the channel from the board */
3596 tmask = ch->ch_tsize - 1;
3597 head = readw(&(bs->tx_head)) & tmask;
3598 tail = readw(&(bs->tx_tail)) & tmask;
3600 bufcount = tail - head - 1;
3602 bufcount += ch->ch_tsize;
3605 * Limit printer output to maxcps overall, with bursts allowed
3606 * up to bufsize characters.
3608 bufcount = dgap_maxcps_room(ch, un, bufcount);
3611 * Take minimum of what the user wants to send, and the
3612 * space available in the FEP buffer.
3614 count = min(count, bufcount);
3617 * Bail if no space left.
3620 dgap_set_firmware_event(un, UN_LOW | UN_EMPTY);
3621 spin_unlock_irqrestore(&ch->ch_lock, lock_flags);
3626 * Output the printer ON string, if we are in terminal mode, but
3627 * need to be in printer mode.
3629 if ((un->un_type == DGAP_PRINT) && !(ch->ch_flags & CH_PRON)) {
3630 dgap_wmove(ch, ch->ch_digi.digi_onstr,
3631 (int) ch->ch_digi.digi_onlen);
3632 head = readw(&(bs->tx_head)) & tmask;
3633 ch->ch_flags |= CH_PRON;
3637 * On the other hand, output the printer OFF string, if we are
3638 * currently in printer mode, but need to output to the terminal.
3640 if ((un->un_type != DGAP_PRINT) && (ch->ch_flags & CH_PRON)) {
3641 dgap_wmove(ch, ch->ch_digi.digi_offstr,
3642 (int) ch->ch_digi.digi_offlen);
3643 head = readw(&(bs->tx_head)) & tmask;
3644 ch->ch_flags &= ~CH_PRON;
3650 * If the write wraps over the top of the circular buffer,
3651 * move the portion up to the wrap point, and reset the
3652 * pointers to the bottom.
3654 remain = ch->ch_tstart + ch->ch_tsize - head;
3658 vaddr = ch->ch_taddr + head;
3660 memcpy_toio(vaddr, (u8 *) buf, remain);
3662 head = ch->ch_tstart;
3669 * Move rest of data.
3671 vaddr = ch->ch_taddr + head;
3674 memcpy_toio(vaddr, (u8 *) buf, remain);
3680 ch->ch_txcount += count;
3682 writew(head, &(bs->tx_head));
3685 dgap_set_firmware_event(un, UN_LOW | UN_EMPTY);
3688 * If this is the print device, and the
3689 * printer is still on, we need to turn it
3690 * off before going idle. If the buffer is
3691 * non-empty, wait until it goes empty.
3692 * Otherwise turn it off right now.
3694 if ((un->un_type == DGAP_PRINT) && (ch->ch_flags & CH_PRON)) {
3695 tail = readw(&(bs->tx_tail)) & tmask;
3698 un->un_flags |= UN_EMPTY;
3699 writeb(1, &(bs->iempty));
3701 dgap_wmove(ch, ch->ch_digi.digi_offstr,
3702 (int) ch->ch_digi.digi_offlen);
3703 head = readw(&(bs->tx_head)) & tmask;
3704 ch->ch_flags &= ~CH_PRON;
3708 /* Update printer buffer empty time. */
3709 if ((un->un_type == DGAP_PRINT) && (ch->ch_digi.digi_maxcps > 0)
3710 && (ch->ch_digi.digi_bufsize > 0)) {
3711 ch->ch_cpstime += (HZ * count) / ch->ch_digi.digi_maxcps;
3714 spin_unlock_irqrestore(&ch->ch_lock, lock_flags);
3720 * dgap_tty_put_char()
3722 * Put a character into ch->ch_buf
3724 * - used by the line discipline for OPOST processing
3726 static int dgap_tty_put_char(struct tty_struct *tty, unsigned char c)
3729 * Simply call tty_write.
3731 dgap_tty_write(tty, &c, 1);
3736 * Return modem signals to ld.
3738 static int dgap_tty_tiocmget(struct tty_struct *tty)
3740 struct channel_t *ch;
3746 if (!tty || tty->magic != TTY_MAGIC)
3749 un = tty->driver_data;
3750 if (!un || un->magic != DGAP_UNIT_MAGIC)
3754 if (!ch || ch->magic != DGAP_CHANNEL_MAGIC)
3757 spin_lock_irqsave(&ch->ch_lock, lock_flags);
3759 mstat = readb(&(ch->ch_bs->m_stat));
3760 /* Append any outbound signals that might be pending... */
3761 mstat |= ch->ch_mostat;
3763 spin_unlock_irqrestore(&ch->ch_lock, lock_flags);
3767 if (mstat & D_DTR(ch))
3768 result |= TIOCM_DTR;
3769 if (mstat & D_RTS(ch))
3770 result |= TIOCM_RTS;
3771 if (mstat & D_CTS(ch))
3772 result |= TIOCM_CTS;
3773 if (mstat & D_DSR(ch))
3774 result |= TIOCM_DSR;
3775 if (mstat & D_RI(ch))
3777 if (mstat & D_CD(ch))
3784 * dgap_tty_tiocmset()
3786 * Set modem signals, called by ld.
3788 static int dgap_tty_tiocmset(struct tty_struct *tty,
3789 unsigned int set, unsigned int clear)
3792 struct channel_t *ch;
3797 if (!tty || tty->magic != TTY_MAGIC)
3800 un = tty->driver_data;
3801 if (!un || un->magic != DGAP_UNIT_MAGIC)
3805 if (!ch || ch->magic != DGAP_CHANNEL_MAGIC)
3809 if (!bd || bd->magic != DGAP_BOARD_MAGIC)
3812 spin_lock_irqsave(&bd->bd_lock, lock_flags);
3813 spin_lock_irqsave(&ch->ch_lock, lock_flags2);
3815 if (set & TIOCM_RTS) {
3816 ch->ch_mforce |= D_RTS(ch);
3817 ch->ch_mval |= D_RTS(ch);
3820 if (set & TIOCM_DTR) {
3821 ch->ch_mforce |= D_DTR(ch);
3822 ch->ch_mval |= D_DTR(ch);
3825 if (clear & TIOCM_RTS) {
3826 ch->ch_mforce |= D_RTS(ch);
3827 ch->ch_mval &= ~(D_RTS(ch));
3830 if (clear & TIOCM_DTR) {
3831 ch->ch_mforce |= D_DTR(ch);
3832 ch->ch_mval &= ~(D_DTR(ch));
3835 dgap_param(ch, bd, un->un_type);
3837 spin_unlock_irqrestore(&ch->ch_lock, lock_flags2);
3838 spin_unlock_irqrestore(&bd->bd_lock, lock_flags);
3844 * dgap_tty_send_break()
3846 * Send a Break, called by ld.
3848 static int dgap_tty_send_break(struct tty_struct *tty, int msec)
3851 struct channel_t *ch;
3856 if (!tty || tty->magic != TTY_MAGIC)
3859 un = tty->driver_data;
3860 if (!un || un->magic != DGAP_UNIT_MAGIC)
3864 if (!ch || ch->magic != DGAP_CHANNEL_MAGIC)
3868 if (!bd || bd->magic != DGAP_BOARD_MAGIC)
3883 spin_lock_irqsave(&bd->bd_lock, lock_flags);
3884 spin_lock_irqsave(&ch->ch_lock, lock_flags2);
3886 dgap_cmdw(ch, SBREAK, (u16) SBREAK_TIME, 0);
3888 dgap_cmdw(ch, SBREAK, (u16) msec, 0);
3890 spin_unlock_irqrestore(&ch->ch_lock, lock_flags2);
3891 spin_unlock_irqrestore(&bd->bd_lock, lock_flags);
3897 * dgap_tty_wait_until_sent()
3899 * wait until data has been transmitted, called by ld.
3901 static void dgap_tty_wait_until_sent(struct tty_struct *tty, int timeout)
3903 dgap_wait_for_drain(tty);
3909 * send a high priority character, called by ld.
3911 static void dgap_tty_send_xchar(struct tty_struct *tty, char c)
3914 struct channel_t *ch;
3919 if (!tty || tty->magic != TTY_MAGIC)
3922 un = tty->driver_data;
3923 if (!un || un->magic != DGAP_UNIT_MAGIC)
3927 if (!ch || ch->magic != DGAP_CHANNEL_MAGIC)
3931 if (!bd || bd->magic != DGAP_BOARD_MAGIC)
3934 spin_lock_irqsave(&bd->bd_lock, lock_flags);
3935 spin_lock_irqsave(&ch->ch_lock, lock_flags2);
3938 * This is technically what we should do.
3939 * However, the NIST tests specifically want
3940 * to see each XON or XOFF character that it
3941 * sends, so lets just send each character
3945 if (c == STOP_CHAR(tty))
3946 dgap_cmdw(ch, RPAUSE, 0, 0);
3947 else if (c == START_CHAR(tty))
3948 dgap_cmdw(ch, RRESUME, 0, 0);
3950 dgap_wmove(ch, &c, 1);
3952 dgap_wmove(ch, &c, 1);
3955 spin_unlock_irqrestore(&ch->ch_lock, lock_flags2);
3956 spin_unlock_irqrestore(&bd->bd_lock, lock_flags);
3960 * Return modem signals to ld.
3962 static int dgap_get_modem_info(struct channel_t *ch, unsigned int __user *value)
3968 spin_lock_irqsave(&ch->ch_lock, lock_flags);
3970 mstat = readb(&(ch->ch_bs->m_stat));
3971 /* Append any outbound signals that might be pending... */
3972 mstat |= ch->ch_mostat;
3974 spin_unlock_irqrestore(&ch->ch_lock, lock_flags);
3978 if (mstat & D_DTR(ch))
3979 result |= TIOCM_DTR;
3980 if (mstat & D_RTS(ch))
3981 result |= TIOCM_RTS;
3982 if (mstat & D_CTS(ch))
3983 result |= TIOCM_CTS;
3984 if (mstat & D_DSR(ch))
3985 result |= TIOCM_DSR;
3986 if (mstat & D_RI(ch))
3988 if (mstat & D_CD(ch))
3991 return put_user(result, value);
3995 * dgap_set_modem_info()
3997 * Set modem signals, called by ld.
3999 static int dgap_set_modem_info(struct channel_t *ch, struct board_t *bd,
4000 struct un_t *un, unsigned int command,
4001 unsigned int __user *value)
4008 ret = get_user(arg, value);
4014 if (arg & TIOCM_RTS) {
4015 ch->ch_mforce |= D_RTS(ch);
4016 ch->ch_mval |= D_RTS(ch);
4019 if (arg & TIOCM_DTR) {
4020 ch->ch_mforce |= D_DTR(ch);
4021 ch->ch_mval |= D_DTR(ch);
4027 if (arg & TIOCM_RTS) {
4028 ch->ch_mforce |= D_RTS(ch);
4029 ch->ch_mval &= ~(D_RTS(ch));
4032 if (arg & TIOCM_DTR) {
4033 ch->ch_mforce |= D_DTR(ch);
4034 ch->ch_mval &= ~(D_DTR(ch));
4040 ch->ch_mforce = D_DTR(ch)|D_RTS(ch);
4042 if (arg & TIOCM_RTS)
4043 ch->ch_mval |= D_RTS(ch);
4045 ch->ch_mval &= ~(D_RTS(ch));
4047 if (arg & TIOCM_DTR)
4048 ch->ch_mval |= (D_DTR(ch));
4050 ch->ch_mval &= ~(D_DTR(ch));
4058 spin_lock_irqsave(&bd->bd_lock, lock_flags);
4059 spin_lock_irqsave(&ch->ch_lock, lock_flags2);
4061 dgap_param(ch, bd, un->un_type);
4063 spin_unlock_irqrestore(&ch->ch_lock, lock_flags2);
4064 spin_unlock_irqrestore(&bd->bd_lock, lock_flags);
4070 * dgap_tty_digigeta()
4072 * Ioctl to get the information for ditty.
4077 static int dgap_tty_digigeta(struct channel_t *ch,
4078 struct digi_t __user *retinfo)
4086 memset(&tmp, 0, sizeof(tmp));
4088 spin_lock_irqsave(&ch->ch_lock, lock_flags);
4089 memcpy(&tmp, &ch->ch_digi, sizeof(tmp));
4090 spin_unlock_irqrestore(&ch->ch_lock, lock_flags);
4092 if (copy_to_user(retinfo, &tmp, sizeof(*retinfo)))
4099 * dgap_tty_digiseta()
4101 * Ioctl to set the information for ditty.
4106 static int dgap_tty_digiseta(struct channel_t *ch, struct board_t *bd,
4107 struct un_t *un, struct digi_t __user *new_info)
4109 struct digi_t new_digi;
4110 ulong lock_flags = 0;
4111 unsigned long lock_flags2;
4113 if (copy_from_user(&new_digi, new_info, sizeof(struct digi_t)))
4116 spin_lock_irqsave(&bd->bd_lock, lock_flags);
4117 spin_lock_irqsave(&ch->ch_lock, lock_flags2);
4119 memcpy(&ch->ch_digi, &new_digi, sizeof(struct digi_t));
4121 if (ch->ch_digi.digi_maxcps < 1)
4122 ch->ch_digi.digi_maxcps = 1;
4124 if (ch->ch_digi.digi_maxcps > 10000)
4125 ch->ch_digi.digi_maxcps = 10000;
4127 if (ch->ch_digi.digi_bufsize < 10)
4128 ch->ch_digi.digi_bufsize = 10;
4130 if (ch->ch_digi.digi_maxchar < 1)
4131 ch->ch_digi.digi_maxchar = 1;
4133 if (ch->ch_digi.digi_maxchar > ch->ch_digi.digi_bufsize)
4134 ch->ch_digi.digi_maxchar = ch->ch_digi.digi_bufsize;
4136 if (ch->ch_digi.digi_onlen > DIGI_PLEN)
4137 ch->ch_digi.digi_onlen = DIGI_PLEN;
4139 if (ch->ch_digi.digi_offlen > DIGI_PLEN)
4140 ch->ch_digi.digi_offlen = DIGI_PLEN;
4142 dgap_param(ch, bd, un->un_type);
4144 spin_unlock_irqrestore(&ch->ch_lock, lock_flags2);
4145 spin_unlock_irqrestore(&bd->bd_lock, lock_flags);
4151 * dgap_tty_digigetedelay()
4153 * Ioctl to get the current edelay setting.
4158 static int dgap_tty_digigetedelay(struct tty_struct *tty, int __user *retinfo)
4160 struct channel_t *ch;
4168 if (!tty || tty->magic != TTY_MAGIC)
4171 un = tty->driver_data;
4172 if (!un || un->magic != DGAP_UNIT_MAGIC)
4176 if (!ch || ch->magic != DGAP_CHANNEL_MAGIC)
4179 memset(&tmp, 0, sizeof(tmp));
4181 spin_lock_irqsave(&ch->ch_lock, lock_flags);
4182 tmp = readw(&(ch->ch_bs->edelay));
4183 spin_unlock_irqrestore(&ch->ch_lock, lock_flags);
4185 if (copy_to_user(retinfo, &tmp, sizeof(*retinfo)))
4192 * dgap_tty_digisetedelay()
4194 * Ioctl to set the EDELAY setting
4197 static int dgap_tty_digisetedelay(struct channel_t *ch, struct board_t *bd,
4198 struct un_t *un, int __user *new_info)
4204 if (copy_from_user(&new_digi, new_info, sizeof(int)))
4207 spin_lock_irqsave(&bd->bd_lock, lock_flags);
4208 spin_lock_irqsave(&ch->ch_lock, lock_flags2);
4210 writew((u16) new_digi, &(ch->ch_bs->edelay));
4212 dgap_param(ch, bd, un->un_type);
4214 spin_unlock_irqrestore(&ch->ch_lock, lock_flags2);
4215 spin_unlock_irqrestore(&bd->bd_lock, lock_flags);
4221 * dgap_tty_digigetcustombaud()
4223 * Ioctl to get the current custom baud rate setting.
4225 static int dgap_tty_digigetcustombaud(struct channel_t *ch, struct un_t *un,
4226 int __user *retinfo)
4234 memset(&tmp, 0, sizeof(tmp));
4236 spin_lock_irqsave(&ch->ch_lock, lock_flags);
4237 tmp = dgap_get_custom_baud(ch);
4238 spin_unlock_irqrestore(&ch->ch_lock, lock_flags);
4240 if (copy_to_user(retinfo, &tmp, sizeof(*retinfo)))
4247 * dgap_tty_digisetcustombaud()
4249 * Ioctl to set the custom baud rate setting
4251 static int dgap_tty_digisetcustombaud(struct channel_t *ch, struct board_t *bd,
4252 struct un_t *un, int __user *new_info)
4258 if (copy_from_user(&new_rate, new_info, sizeof(unsigned int)))
4261 if (bd->bd_flags & BD_FEP5PLUS) {
4263 spin_lock_irqsave(&bd->bd_lock, lock_flags);
4264 spin_lock_irqsave(&ch->ch_lock, lock_flags2);
4266 ch->ch_custom_speed = new_rate;
4268 dgap_param(ch, bd, un->un_type);
4270 spin_unlock_irqrestore(&ch->ch_lock, lock_flags2);
4271 spin_unlock_irqrestore(&bd->bd_lock, lock_flags);
4278 * dgap_set_termios()
4280 static void dgap_tty_set_termios(struct tty_struct *tty,
4281 struct ktermios *old_termios)
4284 struct channel_t *ch;
4286 unsigned long lock_flags;
4287 unsigned long lock_flags2;
4289 if (!tty || tty->magic != TTY_MAGIC)
4292 un = tty->driver_data;
4293 if (!un || un->magic != DGAP_UNIT_MAGIC)
4297 if (!ch || ch->magic != DGAP_CHANNEL_MAGIC)
4301 if (!bd || bd->magic != DGAP_BOARD_MAGIC)
4304 spin_lock_irqsave(&bd->bd_lock, lock_flags);
4305 spin_lock_irqsave(&ch->ch_lock, lock_flags2);
4307 ch->ch_c_cflag = tty->termios.c_cflag;
4308 ch->ch_c_iflag = tty->termios.c_iflag;
4309 ch->ch_c_oflag = tty->termios.c_oflag;
4310 ch->ch_c_lflag = tty->termios.c_lflag;
4311 ch->ch_startc = tty->termios.c_cc[VSTART];
4312 ch->ch_stopc = tty->termios.c_cc[VSTOP];
4315 dgap_param(ch, bd, un->un_type);
4317 spin_unlock_irqrestore(&ch->ch_lock, lock_flags2);
4318 spin_unlock_irqrestore(&bd->bd_lock, lock_flags);
4321 static void dgap_tty_throttle(struct tty_struct *tty)
4324 struct channel_t *ch;
4329 if (!tty || tty->magic != TTY_MAGIC)
4332 un = tty->driver_data;
4333 if (!un || un->magic != DGAP_UNIT_MAGIC)
4337 if (!ch || ch->magic != DGAP_CHANNEL_MAGIC)
4341 if (!bd || bd->magic != DGAP_BOARD_MAGIC)
4344 spin_lock_irqsave(&bd->bd_lock, lock_flags);
4345 spin_lock_irqsave(&ch->ch_lock, lock_flags2);
4347 ch->ch_flags |= (CH_RXBLOCK);
4349 dgap_cmdw(ch, RPAUSE, 0, 0);
4352 spin_unlock_irqrestore(&ch->ch_lock, lock_flags2);
4353 spin_unlock_irqrestore(&bd->bd_lock, lock_flags);
4357 static void dgap_tty_unthrottle(struct tty_struct *tty)
4360 struct channel_t *ch;
4365 if (!tty || tty->magic != TTY_MAGIC)
4368 un = tty->driver_data;
4369 if (!un || un->magic != DGAP_UNIT_MAGIC)
4373 if (!ch || ch->magic != DGAP_CHANNEL_MAGIC)
4377 if (!bd || bd->magic != DGAP_BOARD_MAGIC)
4380 spin_lock_irqsave(&bd->bd_lock, lock_flags);
4381 spin_lock_irqsave(&ch->ch_lock, lock_flags2);
4383 ch->ch_flags &= ~(CH_RXBLOCK);
4386 dgap_cmdw(ch, RRESUME, 0, 0);
4389 spin_unlock_irqrestore(&ch->ch_lock, lock_flags2);
4390 spin_unlock_irqrestore(&bd->bd_lock, lock_flags);
4393 static struct board_t *find_board_by_major(unsigned int major)
4397 for (i = 0; i < MAXBOARDS; i++) {
4398 struct board_t *brd = dgap_board[i];
4402 if (major == brd->serial_driver->major ||
4403 major == brd->print_driver->major)
4410 /************************************************************************
4412 * TTY Entry points and helper functions
4414 ************************************************************************/
4420 static int dgap_tty_open(struct tty_struct *tty, struct file *file)
4422 struct board_t *brd;
4423 struct channel_t *ch;
4425 struct bs_t __iomem *bs;
4433 major = MAJOR(tty_devnum(tty));
4434 minor = MINOR(tty_devnum(tty));
4436 brd = find_board_by_major(major);
4441 * If board is not yet up to a state of READY, go to
4442 * sleep waiting for it to happen or they cancel the open.
4444 rc = wait_event_interruptible(brd->state_wait,
4445 (brd->state & BOARD_READY));
4450 spin_lock_irqsave(&brd->bd_lock, lock_flags);
4452 /* The wait above should guarantee this cannot happen */
4453 if (brd->state != BOARD_READY) {
4454 spin_unlock_irqrestore(&brd->bd_lock, lock_flags);
4458 /* If opened device is greater than our number of ports, bail. */
4459 if (MINOR(tty_devnum(tty)) > brd->nasync) {
4460 spin_unlock_irqrestore(&brd->bd_lock, lock_flags);
4464 ch = brd->channels[minor];
4466 spin_unlock_irqrestore(&brd->bd_lock, lock_flags);
4470 /* Grab channel lock */
4471 spin_lock_irqsave(&ch->ch_lock, lock_flags2);
4473 /* Figure out our type */
4474 if (major == brd->serial_driver->major) {
4475 un = &brd->channels[minor]->ch_tun;
4476 un->un_type = DGAP_SERIAL;
4477 } else if (major == brd->print_driver->major) {
4478 un = &brd->channels[minor]->ch_pun;
4479 un->un_type = DGAP_PRINT;
4481 spin_unlock_irqrestore(&ch->ch_lock, lock_flags2);
4482 spin_unlock_irqrestore(&brd->bd_lock, lock_flags);
4486 /* Store our unit into driver_data, so we always have it available. */
4487 tty->driver_data = un;
4490 * Error if channel info pointer is NULL.
4494 spin_unlock_irqrestore(&ch->ch_lock, lock_flags2);
4495 spin_unlock_irqrestore(&brd->bd_lock, lock_flags);
4502 if (!(un->un_flags & UN_ISOPEN)) {
4503 /* Store important variables. */
4506 /* Maybe do something here to the TTY struct as well? */
4510 * Initialize if neither terminal or printer is open.
4512 if (!((ch->ch_tun.un_flags | ch->ch_pun.un_flags) & UN_ISOPEN)) {
4518 * Flush input queue.
4520 head = readw(&(bs->rx_head));
4521 writew(head, &(bs->rx_tail));
4524 ch->pscan_state = 0;
4525 ch->pscan_savechar = 0;
4527 ch->ch_c_cflag = tty->termios.c_cflag;
4528 ch->ch_c_iflag = tty->termios.c_iflag;
4529 ch->ch_c_oflag = tty->termios.c_oflag;
4530 ch->ch_c_lflag = tty->termios.c_lflag;
4531 ch->ch_startc = tty->termios.c_cc[VSTART];
4532 ch->ch_stopc = tty->termios.c_cc[VSTOP];
4534 /* TODO: flush our TTY struct here? */
4539 * Run param in case we changed anything
4541 dgap_param(ch, brd, un->un_type);
4544 * follow protocol for opening port
4547 spin_unlock_irqrestore(&ch->ch_lock, lock_flags2);
4548 spin_unlock_irqrestore(&brd->bd_lock, lock_flags);
4550 rc = dgap_block_til_ready(tty, file, ch);
4555 /* No going back now, increment our unit and channel counters */
4556 spin_lock_irqsave(&ch->ch_lock, lock_flags);
4557 ch->ch_open_count++;
4558 un->un_open_count++;
4559 un->un_flags |= (UN_ISOPEN);
4560 spin_unlock_irqrestore(&ch->ch_lock, lock_flags);
4569 static void dgap_tty_close(struct tty_struct *tty, struct file *file)
4571 struct ktermios *ts;
4573 struct channel_t *ch;
4577 if (!tty || tty->magic != TTY_MAGIC)
4580 un = tty->driver_data;
4581 if (!un || un->magic != DGAP_UNIT_MAGIC)
4585 if (!ch || ch->magic != DGAP_CHANNEL_MAGIC)
4589 if (!bd || bd->magic != DGAP_BOARD_MAGIC)
4594 spin_lock_irqsave(&ch->ch_lock, lock_flags);
4597 * Determine if this is the last close or not - and if we agree about
4598 * which type of close it is with the Line Discipline
4600 if ((tty->count == 1) && (un->un_open_count != 1)) {
4602 * Uh, oh. tty->count is 1, which means that the tty
4603 * structure will be freed. un_open_count should always
4604 * be one in these conditions. If it's greater than
4605 * one, we've got real problems, since it means the
4606 * serial port won't be shutdown.
4608 un->un_open_count = 1;
4611 if (--un->un_open_count < 0)
4612 un->un_open_count = 0;
4614 ch->ch_open_count--;
4616 if (ch->ch_open_count && un->un_open_count) {
4617 spin_unlock_irqrestore(&ch->ch_lock, lock_flags);
4621 /* OK, its the last close on the unit */
4623 un->un_flags |= UN_CLOSING;
4628 * Only officially close channel if count is 0 and
4629 * DIGI_PRINTER bit is not set.
4631 if ((ch->ch_open_count == 0) &&
4632 !(ch->ch_digi.digi_flags & DIGI_PRINTER)) {
4634 ch->ch_flags &= ~(CH_RXBLOCK);
4636 spin_unlock_irqrestore(&ch->ch_lock, lock_flags);
4638 /* wait for output to drain */
4639 /* This will also return if we take an interrupt */
4641 dgap_wait_for_drain(tty);
4643 dgap_tty_flush_buffer(tty);
4644 tty_ldisc_flush(tty);
4646 spin_lock_irqsave(&ch->ch_lock, lock_flags);
4651 * If we have HUPCL set, lower DTR and RTS
4653 if (ch->ch_c_cflag & HUPCL) {
4654 ch->ch_mostat &= ~(D_RTS(ch)|D_DTR(ch));
4655 dgap_cmdb(ch, SMODEM, 0, D_DTR(ch)|D_RTS(ch), 0);
4658 * Go to sleep to ensure RTS/DTR
4659 * have been dropped for modems to see it.
4661 spin_unlock_irqrestore(&ch->ch_lock,
4664 /* .25 second delay for dropping RTS/DTR */
4665 schedule_timeout_interruptible(msecs_to_jiffies(250));
4667 spin_lock_irqsave(&ch->ch_lock, lock_flags);
4670 ch->pscan_state = 0;
4671 ch->pscan_savechar = 0;
4672 ch->ch_baud_info = 0;
4677 * turn off print device when closing print device.
4679 if ((un->un_type == DGAP_PRINT) && (ch->ch_flags & CH_PRON)) {
4680 dgap_wmove(ch, ch->ch_digi.digi_offstr,
4681 (int) ch->ch_digi.digi_offlen);
4682 ch->ch_flags &= ~CH_PRON;
4686 un->un_flags &= ~(UN_ISOPEN | UN_CLOSING);
4687 tty->driver_data = NULL;
4689 wake_up_interruptible(&ch->ch_flags_wait);
4690 wake_up_interruptible(&un->un_flags_wait);
4692 spin_unlock_irqrestore(&ch->ch_lock, lock_flags);
4695 static void dgap_tty_start(struct tty_struct *tty)
4698 struct channel_t *ch;
4703 if (!tty || tty->magic != TTY_MAGIC)
4706 un = tty->driver_data;
4707 if (!un || un->magic != DGAP_UNIT_MAGIC)
4711 if (!ch || ch->magic != DGAP_CHANNEL_MAGIC)
4715 if (!bd || bd->magic != DGAP_BOARD_MAGIC)
4718 spin_lock_irqsave(&bd->bd_lock, lock_flags);
4719 spin_lock_irqsave(&ch->ch_lock, lock_flags2);
4721 dgap_cmdw(ch, RESUMETX, 0, 0);
4723 spin_unlock_irqrestore(&ch->ch_lock, lock_flags2);
4724 spin_unlock_irqrestore(&bd->bd_lock, lock_flags);
4727 static void dgap_tty_stop(struct tty_struct *tty)
4730 struct channel_t *ch;
4735 if (!tty || tty->magic != TTY_MAGIC)
4738 un = tty->driver_data;
4739 if (!un || un->magic != DGAP_UNIT_MAGIC)
4743 if (!ch || ch->magic != DGAP_CHANNEL_MAGIC)
4747 if (!bd || bd->magic != DGAP_BOARD_MAGIC)
4750 spin_lock_irqsave(&bd->bd_lock, lock_flags);
4751 spin_lock_irqsave(&ch->ch_lock, lock_flags2);
4753 dgap_cmdw(ch, PAUSETX, 0, 0);
4755 spin_unlock_irqrestore(&ch->ch_lock, lock_flags2);
4756 spin_unlock_irqrestore(&bd->bd_lock, lock_flags);
4760 * dgap_tty_flush_chars()
4762 * Flush the cook buffer
4764 * Note to self, and any other poor souls who venture here:
4766 * flush in this case DOES NOT mean dispose of the data.
4767 * instead, it means "stop buffering and send it if you
4768 * haven't already." Just guess how I figured that out... SRW 2-Jun-98
4770 * It is also always called in interrupt context - JAR 8-Sept-99
4772 static void dgap_tty_flush_chars(struct tty_struct *tty)
4775 struct channel_t *ch;
4780 if (!tty || tty->magic != TTY_MAGIC)
4783 un = tty->driver_data;
4784 if (!un || un->magic != DGAP_UNIT_MAGIC)
4788 if (!ch || ch->magic != DGAP_CHANNEL_MAGIC)
4792 if (!bd || bd->magic != DGAP_BOARD_MAGIC)
4795 spin_lock_irqsave(&bd->bd_lock, lock_flags);
4796 spin_lock_irqsave(&ch->ch_lock, lock_flags2);
4798 /* TODO: Do something here */
4800 spin_unlock_irqrestore(&ch->ch_lock, lock_flags2);
4801 spin_unlock_irqrestore(&bd->bd_lock, lock_flags);
4804 /*****************************************************************************
4806 * The IOCTL function and all of its helpers
4808 *****************************************************************************/
4813 * The usual assortment of ioctl's
4815 static int dgap_tty_ioctl(struct tty_struct *tty, unsigned int cmd,
4819 struct channel_t *ch;
4823 ulong lock_flags = 0;
4824 ulong lock_flags2 = 0;
4825 void __user *uarg = (void __user *) arg;
4827 if (!tty || tty->magic != TTY_MAGIC)
4830 un = tty->driver_data;
4831 if (!un || un->magic != DGAP_UNIT_MAGIC)
4835 if (!ch || ch->magic != DGAP_CHANNEL_MAGIC)
4839 if (!bd || bd->magic != DGAP_BOARD_MAGIC)
4842 spin_lock_irqsave(&bd->bd_lock, lock_flags);
4843 spin_lock_irqsave(&ch->ch_lock, lock_flags2);
4845 if (un->un_open_count <= 0) {
4846 spin_unlock_irqrestore(&ch->ch_lock, lock_flags2);
4847 spin_unlock_irqrestore(&bd->bd_lock, lock_flags);
4853 /* Here are all the standard ioctl's that we MUST implement */
4857 * TCSBRK is SVID version: non-zero arg --> no break
4858 * this behaviour is exploited by tcdrain().
4860 * According to POSIX.1 spec (7.2.2.1.2) breaks should be
4861 * between 0.25 and 0.5 seconds so we'll ask for something
4862 * in the middle: 0.375 seconds.
4864 rc = tty_check_change(tty);
4865 spin_unlock_irqrestore(&ch->ch_lock, lock_flags2);
4866 spin_unlock_irqrestore(&bd->bd_lock, lock_flags);
4870 rc = dgap_wait_for_drain(tty);
4875 spin_lock_irqsave(&bd->bd_lock, lock_flags);
4876 spin_lock_irqsave(&ch->ch_lock, lock_flags2);
4878 if (((cmd == TCSBRK) && (!arg)) || (cmd == TCSBRKP))
4879 dgap_cmdw(ch, SBREAK, (u16) SBREAK_TIME, 0);
4881 spin_unlock_irqrestore(&ch->ch_lock, lock_flags2);
4882 spin_unlock_irqrestore(&bd->bd_lock, lock_flags);
4887 /* support for POSIX tcsendbreak()
4889 * According to POSIX.1 spec (7.2.2.1.2) breaks should be
4890 * between 0.25 and 0.5 seconds so we'll ask for something
4891 * in the middle: 0.375 seconds.
4893 rc = tty_check_change(tty);
4894 spin_unlock_irqrestore(&ch->ch_lock, lock_flags2);
4895 spin_unlock_irqrestore(&bd->bd_lock, lock_flags);
4899 rc = dgap_wait_for_drain(tty);
4903 spin_lock_irqsave(&bd->bd_lock, lock_flags);
4904 spin_lock_irqsave(&ch->ch_lock, lock_flags2);
4906 dgap_cmdw(ch, SBREAK, (u16) SBREAK_TIME, 0);
4908 spin_unlock_irqrestore(&ch->ch_lock, lock_flags2);
4909 spin_unlock_irqrestore(&bd->bd_lock, lock_flags);
4915 * FEP5 doesn't support turning on a break unconditionally.
4916 * The FEP5 device will stop sending a break automatically
4917 * after the specified time value that was sent when turning on
4920 rc = tty_check_change(tty);
4921 spin_unlock_irqrestore(&ch->ch_lock, lock_flags2);
4922 spin_unlock_irqrestore(&bd->bd_lock, lock_flags);
4926 rc = dgap_wait_for_drain(tty);
4930 spin_lock_irqsave(&bd->bd_lock, lock_flags);
4931 spin_lock_irqsave(&ch->ch_lock, lock_flags2);
4933 dgap_cmdw(ch, SBREAK, (u16) SBREAK_TIME, 0);
4935 spin_unlock_irqrestore(&ch->ch_lock, lock_flags2);
4936 spin_unlock_irqrestore(&bd->bd_lock, lock_flags);
4942 * FEP5 doesn't support turning off a break unconditionally.
4943 * The FEP5 device will stop sending a break automatically
4944 * after the specified time value that was sent when turning on
4947 spin_unlock_irqrestore(&ch->ch_lock, lock_flags2);
4948 spin_unlock_irqrestore(&bd->bd_lock, lock_flags);
4953 spin_unlock_irqrestore(&ch->ch_lock, lock_flags2);
4954 spin_unlock_irqrestore(&bd->bd_lock, lock_flags);
4956 return put_user(C_CLOCAL(tty) ? 1 : 0,
4957 (unsigned long __user *) arg);
4960 spin_unlock_irqrestore(&ch->ch_lock, lock_flags2);
4961 spin_unlock_irqrestore(&bd->bd_lock, lock_flags);
4963 rc = get_user(arg, (unsigned long __user *) arg);
4967 spin_lock_irqsave(&bd->bd_lock, lock_flags);
4968 spin_lock_irqsave(&ch->ch_lock, lock_flags2);
4969 tty->termios.c_cflag = ((tty->termios.c_cflag & ~CLOCAL) |
4970 (arg ? CLOCAL : 0));
4971 dgap_param(ch, bd, un->un_type);
4972 spin_unlock_irqrestore(&ch->ch_lock, lock_flags2);
4973 spin_unlock_irqrestore(&bd->bd_lock, lock_flags);
4978 spin_unlock_irqrestore(&ch->ch_lock, lock_flags2);
4979 spin_unlock_irqrestore(&bd->bd_lock, lock_flags);
4980 return dgap_get_modem_info(ch, uarg);
4985 spin_unlock_irqrestore(&ch->ch_lock, lock_flags2);
4986 spin_unlock_irqrestore(&bd->bd_lock, lock_flags);
4987 return dgap_set_modem_info(ch, bd, un, cmd, uarg);
4990 * Here are any additional ioctl's that we want to implement
4995 * The linux tty driver doesn't have a flush
4996 * input routine for the driver, assuming all backed
4997 * up data is in the line disc. buffers. However,
4998 * we all know that's not the case. Here, we
4999 * act on the ioctl, but then lie and say we didn't
5000 * so the line discipline will process the flush
5003 rc = tty_check_change(tty);
5005 spin_unlock_irqrestore(&ch->ch_lock, lock_flags2);
5006 spin_unlock_irqrestore(&bd->bd_lock, lock_flags);
5010 if ((arg == TCIFLUSH) || (arg == TCIOFLUSH)) {
5011 if (!(un->un_type == DGAP_PRINT)) {
5012 head = readw(&(ch->ch_bs->rx_head));
5013 writew(head, &(ch->ch_bs->rx_tail));
5014 writeb(0, &(ch->ch_bs->orun));
5018 if ((arg != TCOFLUSH) && (arg != TCIOFLUSH)) {
5019 /* pretend we didn't recognize this IOCTL */
5020 spin_unlock_irqrestore(&ch->ch_lock, lock_flags2);
5021 spin_unlock_irqrestore(&bd->bd_lock, lock_flags);
5023 return -ENOIOCTLCMD;
5026 ch->ch_flags &= ~CH_STOP;
5027 head = readw(&(ch->ch_bs->tx_head));
5028 dgap_cmdw(ch, FLUSHTX, (u16) head, 0);
5029 dgap_cmdw(ch, RESUMETX, 0, 0);
5030 if (ch->ch_tun.un_flags & (UN_LOW|UN_EMPTY)) {
5031 ch->ch_tun.un_flags &= ~(UN_LOW|UN_EMPTY);
5032 wake_up_interruptible(&ch->ch_tun.un_flags_wait);
5034 if (ch->ch_pun.un_flags & (UN_LOW|UN_EMPTY)) {
5035 ch->ch_pun.un_flags &= ~(UN_LOW|UN_EMPTY);
5036 wake_up_interruptible(&ch->ch_pun.un_flags_wait);
5038 if (waitqueue_active(&tty->write_wait))
5039 wake_up_interruptible(&tty->write_wait);
5041 /* Can't hold any locks when calling tty_wakeup! */
5042 spin_unlock_irqrestore(&ch->ch_lock, lock_flags2);
5043 spin_unlock_irqrestore(&bd->bd_lock, lock_flags);
5046 /* pretend we didn't recognize this IOCTL */
5047 return -ENOIOCTLCMD;
5052 * The linux tty driver doesn't have a flush
5053 * input routine for the driver, assuming all backed
5054 * up data is in the line disc. buffers. However,
5055 * we all know that's not the case. Here, we
5056 * act on the ioctl, but then lie and say we didn't
5057 * so the line discipline will process the flush
5060 if (cmd == TCSETSF) {
5062 ch->ch_flags &= ~CH_STOP;
5063 head = readw(&(ch->ch_bs->rx_head));
5064 writew(head, &(ch->ch_bs->rx_tail));
5067 /* now wait for all the output to drain */
5068 spin_unlock_irqrestore(&ch->ch_lock, lock_flags2);
5069 spin_unlock_irqrestore(&bd->bd_lock, lock_flags);
5070 rc = dgap_wait_for_drain(tty);
5074 /* pretend we didn't recognize this */
5075 return -ENOIOCTLCMD;
5079 spin_unlock_irqrestore(&ch->ch_lock, lock_flags2);
5080 spin_unlock_irqrestore(&bd->bd_lock, lock_flags);
5081 rc = dgap_wait_for_drain(tty);
5085 /* pretend we didn't recognize this */
5086 return -ENOIOCTLCMD;
5090 * The Linux Line Discipline (LD) would do this for us if we
5091 * let it, but we have the special firmware options to do this
5092 * the "right way" regardless of hardware or software flow
5093 * control so we'll do it outselves instead of letting the LD
5096 rc = tty_check_change(tty);
5098 spin_unlock_irqrestore(&ch->ch_lock, lock_flags2);
5099 spin_unlock_irqrestore(&bd->bd_lock, lock_flags);
5106 spin_unlock_irqrestore(&ch->ch_lock, lock_flags2);
5107 spin_unlock_irqrestore(&bd->bd_lock, lock_flags);
5108 dgap_tty_start(tty);
5111 spin_unlock_irqrestore(&ch->ch_lock, lock_flags2);
5112 spin_unlock_irqrestore(&bd->bd_lock, lock_flags);
5116 spin_unlock_irqrestore(&ch->ch_lock, lock_flags2);
5117 spin_unlock_irqrestore(&bd->bd_lock, lock_flags);
5118 /* Make the ld do it */
5119 return -ENOIOCTLCMD;
5121 spin_unlock_irqrestore(&ch->ch_lock, lock_flags2);
5122 spin_unlock_irqrestore(&bd->bd_lock, lock_flags);
5123 /* Make the ld do it */
5124 return -ENOIOCTLCMD;
5126 spin_unlock_irqrestore(&ch->ch_lock, lock_flags2);
5127 spin_unlock_irqrestore(&bd->bd_lock, lock_flags);
5132 /* get information for ditty */
5133 spin_unlock_irqrestore(&ch->ch_lock, lock_flags2);
5134 spin_unlock_irqrestore(&bd->bd_lock, lock_flags);
5135 return dgap_tty_digigeta(ch, uarg);
5140 /* set information for ditty */
5141 if (cmd == (DIGI_SETAW)) {
5143 spin_unlock_irqrestore(&ch->ch_lock, lock_flags2);
5144 spin_unlock_irqrestore(&bd->bd_lock, lock_flags);
5145 rc = dgap_wait_for_drain(tty);
5148 spin_lock_irqsave(&bd->bd_lock, lock_flags);
5149 spin_lock_irqsave(&ch->ch_lock, lock_flags2);
5151 tty_ldisc_flush(tty);
5155 spin_unlock_irqrestore(&ch->ch_lock, lock_flags2);
5156 spin_unlock_irqrestore(&bd->bd_lock, lock_flags);
5157 return dgap_tty_digiseta(ch, bd, un, uarg);
5160 spin_unlock_irqrestore(&ch->ch_lock, lock_flags2);
5161 spin_unlock_irqrestore(&bd->bd_lock, lock_flags);
5162 return dgap_tty_digigetedelay(tty, uarg);
5165 spin_unlock_irqrestore(&ch->ch_lock, lock_flags2);
5166 spin_unlock_irqrestore(&bd->bd_lock, lock_flags);
5167 return dgap_tty_digisetedelay(ch, bd, un, uarg);
5169 case DIGI_GETCUSTOMBAUD:
5170 spin_unlock_irqrestore(&ch->ch_lock, lock_flags2);
5171 spin_unlock_irqrestore(&bd->bd_lock, lock_flags);
5172 return dgap_tty_digigetcustombaud(ch, un, uarg);
5174 case DIGI_SETCUSTOMBAUD:
5175 spin_unlock_irqrestore(&ch->ch_lock, lock_flags2);
5176 spin_unlock_irqrestore(&bd->bd_lock, lock_flags);
5177 return dgap_tty_digisetcustombaud(ch, bd, un, uarg);
5179 case DIGI_RESET_PORT:
5180 dgap_firmware_reset_port(ch);
5181 dgap_param(ch, bd, un->un_type);
5182 spin_unlock_irqrestore(&ch->ch_lock, lock_flags2);
5183 spin_unlock_irqrestore(&bd->bd_lock, lock_flags);
5187 spin_unlock_irqrestore(&ch->ch_lock, lock_flags2);
5188 spin_unlock_irqrestore(&bd->bd_lock, lock_flags);
5190 return -ENOIOCTLCMD;
5194 static const struct tty_operations dgap_tty_ops = {
5195 .open = dgap_tty_open,
5196 .close = dgap_tty_close,
5197 .write = dgap_tty_write,
5198 .write_room = dgap_tty_write_room,
5199 .flush_buffer = dgap_tty_flush_buffer,
5200 .chars_in_buffer = dgap_tty_chars_in_buffer,
5201 .flush_chars = dgap_tty_flush_chars,
5202 .ioctl = dgap_tty_ioctl,
5203 .set_termios = dgap_tty_set_termios,
5204 .stop = dgap_tty_stop,
5205 .start = dgap_tty_start,
5206 .throttle = dgap_tty_throttle,
5207 .unthrottle = dgap_tty_unthrottle,
5208 .hangup = dgap_tty_hangup,
5209 .put_char = dgap_tty_put_char,
5210 .tiocmget = dgap_tty_tiocmget,
5211 .tiocmset = dgap_tty_tiocmset,
5212 .break_ctl = dgap_tty_send_break,
5213 .wait_until_sent = dgap_tty_wait_until_sent,
5214 .send_xchar = dgap_tty_send_xchar
5217 /************************************************************************
5219 * TTY Initialization/Cleanup Functions
5221 ************************************************************************/
5224 * dgap_tty_register()
5226 * Init the tty subsystem for this board.
5228 static int dgap_tty_register(struct board_t *brd)
5232 brd->serial_driver = tty_alloc_driver(MAXPORTS,
5233 TTY_DRIVER_REAL_RAW |
5234 TTY_DRIVER_DYNAMIC_DEV |
5235 TTY_DRIVER_HARDWARE_BREAK);
5236 if (IS_ERR(brd->serial_driver))
5237 return PTR_ERR(brd->serial_driver);
5239 snprintf(brd->serial_name, MAXTTYNAMELEN, "tty_dgap_%d_",
5241 brd->serial_driver->name = brd->serial_name;
5242 brd->serial_driver->name_base = 0;
5243 brd->serial_driver->major = 0;
5244 brd->serial_driver->minor_start = 0;
5245 brd->serial_driver->type = TTY_DRIVER_TYPE_SERIAL;
5246 brd->serial_driver->subtype = SERIAL_TYPE_NORMAL;
5247 brd->serial_driver->init_termios = dgap_default_termios;
5248 brd->serial_driver->driver_name = DRVSTR;
5251 * Entry points for driver. Called by the kernel from
5252 * tty_io.c and n_tty.c.
5254 tty_set_operations(brd->serial_driver, &dgap_tty_ops);
5257 * If we're doing transparent print, we have to do all of the above
5258 * again, separately so we don't get the LD confused about what major
5259 * we are when we get into the dgap_tty_open() routine.
5261 brd->print_driver = tty_alloc_driver(MAXPORTS,
5262 TTY_DRIVER_REAL_RAW |
5263 TTY_DRIVER_DYNAMIC_DEV |
5264 TTY_DRIVER_HARDWARE_BREAK);
5265 if (IS_ERR(brd->print_driver)) {
5266 rc = PTR_ERR(brd->print_driver);
5267 goto free_serial_drv;
5270 snprintf(brd->print_name, MAXTTYNAMELEN, "pr_dgap_%d_",
5272 brd->print_driver->name = brd->print_name;
5273 brd->print_driver->name_base = 0;
5274 brd->print_driver->major = 0;
5275 brd->print_driver->minor_start = 0;
5276 brd->print_driver->type = TTY_DRIVER_TYPE_SERIAL;
5277 brd->print_driver->subtype = SERIAL_TYPE_NORMAL;
5278 brd->print_driver->init_termios = dgap_default_termios;
5279 brd->print_driver->driver_name = DRVSTR;
5282 * Entry points for driver. Called by the kernel from
5283 * tty_io.c and n_tty.c.
5285 tty_set_operations(brd->print_driver, &dgap_tty_ops);
5287 /* Register tty devices */
5288 rc = tty_register_driver(brd->serial_driver);
5290 goto free_print_drv;
5292 /* Register Transparent Print devices */
5293 rc = tty_register_driver(brd->print_driver);
5295 goto unregister_serial_drv;
5299 unregister_serial_drv:
5300 tty_unregister_driver(brd->serial_driver);
5302 put_tty_driver(brd->print_driver);
5304 put_tty_driver(brd->serial_driver);
5309 static void dgap_tty_unregister(struct board_t *brd)
5311 tty_unregister_driver(brd->print_driver);
5312 tty_unregister_driver(brd->serial_driver);
5313 put_tty_driver(brd->print_driver);
5314 put_tty_driver(brd->serial_driver);
5317 static int dgap_alloc_flipbuf(struct board_t *brd)
5320 * allocate flip buffer for board.
5322 brd->flipbuf = kmalloc(MYFLIPLEN, GFP_KERNEL);
5326 brd->flipflagbuf = kmalloc(MYFLIPLEN, GFP_KERNEL);
5327 if (!brd->flipflagbuf) {
5328 kfree(brd->flipbuf);
5335 static void dgap_free_flipbuf(struct board_t *brd)
5337 kfree(brd->flipbuf);
5338 kfree(brd->flipflagbuf);
5341 static struct board_t *dgap_verify_board(struct device *p)
5348 bd = dev_get_drvdata(p);
5349 if (!bd || bd->magic != DGAP_BOARD_MAGIC || bd->state != BOARD_READY)
5355 static ssize_t dgap_ports_state_show(struct device *p,
5356 struct device_attribute *attr,
5363 bd = dgap_verify_board(p);
5367 for (i = 0; i < bd->nasync; i++) {
5368 count += snprintf(buf + count, PAGE_SIZE - count,
5369 "%d %s\n", bd->channels[i]->ch_portnum,
5370 bd->channels[i]->ch_open_count ? "Open" : "Closed");
5374 static DEVICE_ATTR(ports_state, S_IRUSR, dgap_ports_state_show, NULL);
5376 static ssize_t dgap_ports_baud_show(struct device *p,
5377 struct device_attribute *attr,
5384 bd = dgap_verify_board(p);
5388 for (i = 0; i < bd->nasync; i++) {
5389 count += snprintf(buf + count, PAGE_SIZE - count, "%d %d\n",
5390 bd->channels[i]->ch_portnum,
5391 bd->channels[i]->ch_baud_info);
5395 static DEVICE_ATTR(ports_baud, S_IRUSR, dgap_ports_baud_show, NULL);
5397 static ssize_t dgap_ports_msignals_show(struct device *p,
5398 struct device_attribute *attr,
5405 bd = dgap_verify_board(p);
5409 for (i = 0; i < bd->nasync; i++) {
5410 if (bd->channels[i]->ch_open_count)
5411 count += snprintf(buf + count, PAGE_SIZE - count,
5412 "%d %s %s %s %s %s %s\n",
5413 bd->channels[i]->ch_portnum,
5414 (bd->channels[i]->ch_mostat &
5415 UART_MCR_RTS) ? "RTS" : "",
5416 (bd->channels[i]->ch_mistat &
5417 UART_MSR_CTS) ? "CTS" : "",
5418 (bd->channels[i]->ch_mostat &
5419 UART_MCR_DTR) ? "DTR" : "",
5420 (bd->channels[i]->ch_mistat &
5421 UART_MSR_DSR) ? "DSR" : "",
5422 (bd->channels[i]->ch_mistat &
5423 UART_MSR_DCD) ? "DCD" : "",
5424 (bd->channels[i]->ch_mistat &
5425 UART_MSR_RI) ? "RI" : "");
5427 count += snprintf(buf + count, PAGE_SIZE - count,
5428 "%d\n", bd->channels[i]->ch_portnum);
5432 static DEVICE_ATTR(ports_msignals, S_IRUSR, dgap_ports_msignals_show, NULL);
5434 static ssize_t dgap_ports_iflag_show(struct device *p,
5435 struct device_attribute *attr,
5442 bd = dgap_verify_board(p);
5446 for (i = 0; i < bd->nasync; i++)
5447 count += snprintf(buf + count, PAGE_SIZE - count, "%d %x\n",
5448 bd->channels[i]->ch_portnum,
5449 bd->channels[i]->ch_c_iflag);
5452 static DEVICE_ATTR(ports_iflag, S_IRUSR, dgap_ports_iflag_show, NULL);
5454 static ssize_t dgap_ports_cflag_show(struct device *p,
5455 struct device_attribute *attr,
5462 bd = dgap_verify_board(p);
5466 for (i = 0; i < bd->nasync; i++)
5467 count += snprintf(buf + count, PAGE_SIZE - count, "%d %x\n",
5468 bd->channels[i]->ch_portnum,
5469 bd->channels[i]->ch_c_cflag);
5472 static DEVICE_ATTR(ports_cflag, S_IRUSR, dgap_ports_cflag_show, NULL);
5474 static ssize_t dgap_ports_oflag_show(struct device *p,
5475 struct device_attribute *attr,
5482 bd = dgap_verify_board(p);
5486 for (i = 0; i < bd->nasync; i++)
5487 count += snprintf(buf + count, PAGE_SIZE - count, "%d %x\n",
5488 bd->channels[i]->ch_portnum,
5489 bd->channels[i]->ch_c_oflag);
5492 static DEVICE_ATTR(ports_oflag, S_IRUSR, dgap_ports_oflag_show, NULL);
5494 static ssize_t dgap_ports_lflag_show(struct device *p,
5495 struct device_attribute *attr,
5502 bd = dgap_verify_board(p);
5506 for (i = 0; i < bd->nasync; i++)
5507 count += snprintf(buf + count, PAGE_SIZE - count, "%d %x\n",
5508 bd->channels[i]->ch_portnum,
5509 bd->channels[i]->ch_c_lflag);
5512 static DEVICE_ATTR(ports_lflag, S_IRUSR, dgap_ports_lflag_show, NULL);
5514 static ssize_t dgap_ports_digi_flag_show(struct device *p,
5515 struct device_attribute *attr,
5522 bd = dgap_verify_board(p);
5526 for (i = 0; i < bd->nasync; i++)
5527 count += snprintf(buf + count, PAGE_SIZE - count, "%d %x\n",
5528 bd->channels[i]->ch_portnum,
5529 bd->channels[i]->ch_digi.digi_flags);
5532 static DEVICE_ATTR(ports_digi_flag, S_IRUSR, dgap_ports_digi_flag_show, NULL);
5534 static ssize_t dgap_ports_rxcount_show(struct device *p,
5535 struct device_attribute *attr,
5542 bd = dgap_verify_board(p);
5546 for (i = 0; i < bd->nasync; i++)
5547 count += snprintf(buf + count, PAGE_SIZE - count, "%d %ld\n",
5548 bd->channels[i]->ch_portnum,
5549 bd->channels[i]->ch_rxcount);
5552 static DEVICE_ATTR(ports_rxcount, S_IRUSR, dgap_ports_rxcount_show, NULL);
5554 static ssize_t dgap_ports_txcount_show(struct device *p,
5555 struct device_attribute *attr,
5562 bd = dgap_verify_board(p);
5566 for (i = 0; i < bd->nasync; i++)
5567 count += snprintf(buf + count, PAGE_SIZE - count, "%d %ld\n",
5568 bd->channels[i]->ch_portnum,
5569 bd->channels[i]->ch_txcount);
5572 static DEVICE_ATTR(ports_txcount, S_IRUSR, dgap_ports_txcount_show, NULL);
5574 static ssize_t dgap_tty_state_show(struct device *d,
5575 struct device_attribute *attr,
5579 struct channel_t *ch;
5584 un = dev_get_drvdata(d);
5585 if (!un || un->magic != DGAP_UNIT_MAGIC)
5588 if (!ch || ch->magic != DGAP_CHANNEL_MAGIC)
5591 if (!bd || bd->magic != DGAP_BOARD_MAGIC)
5593 if (bd->state != BOARD_READY)
5596 return snprintf(buf, PAGE_SIZE, "%s", un->un_open_count ?
5599 static DEVICE_ATTR(state, S_IRUSR, dgap_tty_state_show, NULL);
5601 static ssize_t dgap_tty_baud_show(struct device *d,
5602 struct device_attribute *attr,
5606 struct channel_t *ch;
5611 un = dev_get_drvdata(d);
5612 if (!un || un->magic != DGAP_UNIT_MAGIC)
5615 if (!ch || ch->magic != DGAP_CHANNEL_MAGIC)
5618 if (!bd || bd->magic != DGAP_BOARD_MAGIC)
5620 if (bd->state != BOARD_READY)
5623 return snprintf(buf, PAGE_SIZE, "%d\n", ch->ch_baud_info);
5625 static DEVICE_ATTR(baud, S_IRUSR, dgap_tty_baud_show, NULL);
5627 static ssize_t dgap_tty_msignals_show(struct device *d,
5628 struct device_attribute *attr,
5632 struct channel_t *ch;
5637 un = dev_get_drvdata(d);
5638 if (!un || un->magic != DGAP_UNIT_MAGIC)
5641 if (!ch || ch->magic != DGAP_CHANNEL_MAGIC)
5644 if (!bd || bd->magic != DGAP_BOARD_MAGIC)
5646 if (bd->state != BOARD_READY)
5649 if (ch->ch_open_count) {
5650 return snprintf(buf, PAGE_SIZE, "%s %s %s %s %s %s\n",
5651 (ch->ch_mostat & UART_MCR_RTS) ? "RTS" : "",
5652 (ch->ch_mistat & UART_MSR_CTS) ? "CTS" : "",
5653 (ch->ch_mostat & UART_MCR_DTR) ? "DTR" : "",
5654 (ch->ch_mistat & UART_MSR_DSR) ? "DSR" : "",
5655 (ch->ch_mistat & UART_MSR_DCD) ? "DCD" : "",
5656 (ch->ch_mistat & UART_MSR_RI) ? "RI" : "");
5660 static DEVICE_ATTR(msignals, S_IRUSR, dgap_tty_msignals_show, NULL);
5662 static ssize_t dgap_tty_iflag_show(struct device *d,
5663 struct device_attribute *attr,
5667 struct channel_t *ch;
5672 un = dev_get_drvdata(d);
5673 if (!un || un->magic != DGAP_UNIT_MAGIC)
5676 if (!ch || ch->magic != DGAP_CHANNEL_MAGIC)
5679 if (!bd || bd->magic != DGAP_BOARD_MAGIC)
5681 if (bd->state != BOARD_READY)
5684 return snprintf(buf, PAGE_SIZE, "%x\n", ch->ch_c_iflag);
5686 static DEVICE_ATTR(iflag, S_IRUSR, dgap_tty_iflag_show, NULL);
5688 static ssize_t dgap_tty_cflag_show(struct device *d,
5689 struct device_attribute *attr,
5693 struct channel_t *ch;
5698 un = dev_get_drvdata(d);
5699 if (!un || un->magic != DGAP_UNIT_MAGIC)
5702 if (!ch || ch->magic != DGAP_CHANNEL_MAGIC)
5705 if (!bd || bd->magic != DGAP_BOARD_MAGIC)
5707 if (bd->state != BOARD_READY)
5710 return snprintf(buf, PAGE_SIZE, "%x\n", ch->ch_c_cflag);
5712 static DEVICE_ATTR(cflag, S_IRUSR, dgap_tty_cflag_show, NULL);
5714 static ssize_t dgap_tty_oflag_show(struct device *d,
5715 struct device_attribute *attr,
5719 struct channel_t *ch;
5724 un = dev_get_drvdata(d);
5725 if (!un || un->magic != DGAP_UNIT_MAGIC)
5728 if (!ch || ch->magic != DGAP_CHANNEL_MAGIC)
5731 if (!bd || bd->magic != DGAP_BOARD_MAGIC)
5733 if (bd->state != BOARD_READY)
5736 return snprintf(buf, PAGE_SIZE, "%x\n", ch->ch_c_oflag);
5738 static DEVICE_ATTR(oflag, S_IRUSR, dgap_tty_oflag_show, NULL);
5740 static ssize_t dgap_tty_lflag_show(struct device *d,
5741 struct device_attribute *attr,
5745 struct channel_t *ch;
5750 un = dev_get_drvdata(d);
5751 if (!un || un->magic != DGAP_UNIT_MAGIC)
5754 if (!ch || ch->magic != DGAP_CHANNEL_MAGIC)
5757 if (!bd || bd->magic != DGAP_BOARD_MAGIC)
5759 if (bd->state != BOARD_READY)
5762 return snprintf(buf, PAGE_SIZE, "%x\n", ch->ch_c_lflag);
5764 static DEVICE_ATTR(lflag, S_IRUSR, dgap_tty_lflag_show, NULL);
5766 static ssize_t dgap_tty_digi_flag_show(struct device *d,
5767 struct device_attribute *attr,
5771 struct channel_t *ch;
5776 un = dev_get_drvdata(d);
5777 if (!un || un->magic != DGAP_UNIT_MAGIC)
5780 if (!ch || ch->magic != DGAP_CHANNEL_MAGIC)
5783 if (!bd || bd->magic != DGAP_BOARD_MAGIC)
5785 if (bd->state != BOARD_READY)
5788 return snprintf(buf, PAGE_SIZE, "%x\n", ch->ch_digi.digi_flags);
5790 static DEVICE_ATTR(digi_flag, S_IRUSR, dgap_tty_digi_flag_show, NULL);
5792 static ssize_t dgap_tty_rxcount_show(struct device *d,
5793 struct device_attribute *attr,
5797 struct channel_t *ch;
5802 un = dev_get_drvdata(d);
5803 if (!un || un->magic != DGAP_UNIT_MAGIC)
5806 if (!ch || ch->magic != DGAP_CHANNEL_MAGIC)
5809 if (!bd || bd->magic != DGAP_BOARD_MAGIC)
5811 if (bd->state != BOARD_READY)
5814 return snprintf(buf, PAGE_SIZE, "%ld\n", ch->ch_rxcount);
5816 static DEVICE_ATTR(rxcount, S_IRUSR, dgap_tty_rxcount_show, NULL);
5818 static ssize_t dgap_tty_txcount_show(struct device *d,
5819 struct device_attribute *attr,
5823 struct channel_t *ch;
5828 un = dev_get_drvdata(d);
5829 if (!un || un->magic != DGAP_UNIT_MAGIC)
5832 if (!ch || ch->magic != DGAP_CHANNEL_MAGIC)
5835 if (!bd || bd->magic != DGAP_BOARD_MAGIC)
5837 if (bd->state != BOARD_READY)
5840 return snprintf(buf, PAGE_SIZE, "%ld\n", ch->ch_txcount);
5842 static DEVICE_ATTR(txcount, S_IRUSR, dgap_tty_txcount_show, NULL);
5844 static ssize_t dgap_tty_name_show(struct device *d,
5845 struct device_attribute *attr,
5849 struct channel_t *ch;
5861 un = dev_get_drvdata(d);
5862 if (!un || un->magic != DGAP_UNIT_MAGIC)
5865 if (!ch || ch->magic != DGAP_CHANNEL_MAGIC)
5868 if (!bd || bd->magic != DGAP_BOARD_MAGIC)
5870 if (bd->state != BOARD_READY)
5874 cn = ch->ch_portnum;
5876 for (cptr = bd->bd_config; cptr; cptr = cptr->next) {
5878 if ((cptr->type == BNODE) &&
5879 ((cptr->u.board.type == APORT2_920P) ||
5880 (cptr->u.board.type == APORT4_920P) ||
5881 (cptr->u.board.type == APORT8_920P) ||
5882 (cptr->u.board.type == PAPORT4) ||
5883 (cptr->u.board.type == PAPORT8))) {
5886 if (cptr->u.board.v_start)
5887 starto = cptr->u.board.start;
5892 if (cptr->type == TNODE && found == TRUE) {
5895 if (strstr(cptr->u.ttyname, "tty")) {
5896 ptr1 = cptr->u.ttyname;
5899 ptr1 = cptr->u.ttyname;
5901 for (i = 0; i < dgap_config_get_num_prts(bd); i++) {
5905 return snprintf(buf, PAGE_SIZE, "%s%s%02d\n",
5906 (un->un_type == DGAP_PRINT) ?
5912 if (cptr->type == CNODE) {
5914 for (i = 0; i < cptr->u.conc.nport; i++) {
5915 if (cn != (i + ncount))
5918 return snprintf(buf, PAGE_SIZE, "%s%s%02ld\n",
5919 (un->un_type == DGAP_PRINT) ?
5922 i + (cptr->u.conc.v_start ?
5923 cptr->u.conc.start : 1));
5926 ncount += cptr->u.conc.nport;
5929 if (cptr->type == MNODE) {
5931 for (i = 0; i < cptr->u.module.nport; i++) {
5932 if (cn != (i + ncount))
5935 return snprintf(buf, PAGE_SIZE, "%s%s%02ld\n",
5936 (un->un_type == DGAP_PRINT) ?
5939 i + (cptr->u.module.v_start ?
5940 cptr->u.module.start : 1));
5943 ncount += cptr->u.module.nport;
5947 return snprintf(buf, PAGE_SIZE, "%s_dgap_%d_%d\n",
5948 (un->un_type == DGAP_PRINT) ? "pr" : "tty", bn, cn);
5950 static DEVICE_ATTR(custom_name, S_IRUSR, dgap_tty_name_show, NULL);
5952 static struct attribute *dgap_sysfs_tty_entries[] = {
5953 &dev_attr_state.attr,
5954 &dev_attr_baud.attr,
5955 &dev_attr_msignals.attr,
5956 &dev_attr_iflag.attr,
5957 &dev_attr_cflag.attr,
5958 &dev_attr_oflag.attr,
5959 &dev_attr_lflag.attr,
5960 &dev_attr_digi_flag.attr,
5961 &dev_attr_rxcount.attr,
5962 &dev_attr_txcount.attr,
5963 &dev_attr_custom_name.attr,
5968 /* this function creates the sys files that will export each signal status
5969 * to sysfs each value will be put in a separate filename
5971 static void dgap_create_ports_sysfiles(struct board_t *bd)
5973 dev_set_drvdata(&bd->pdev->dev, bd);
5974 device_create_file(&(bd->pdev->dev), &dev_attr_ports_state);
5975 device_create_file(&(bd->pdev->dev), &dev_attr_ports_baud);
5976 device_create_file(&(bd->pdev->dev), &dev_attr_ports_msignals);
5977 device_create_file(&(bd->pdev->dev), &dev_attr_ports_iflag);
5978 device_create_file(&(bd->pdev->dev), &dev_attr_ports_cflag);
5979 device_create_file(&(bd->pdev->dev), &dev_attr_ports_oflag);
5980 device_create_file(&(bd->pdev->dev), &dev_attr_ports_lflag);
5981 device_create_file(&(bd->pdev->dev), &dev_attr_ports_digi_flag);
5982 device_create_file(&(bd->pdev->dev), &dev_attr_ports_rxcount);
5983 device_create_file(&(bd->pdev->dev), &dev_attr_ports_txcount);
5986 /* removes all the sys files created for that port */
5987 static void dgap_remove_ports_sysfiles(struct board_t *bd)
5989 device_remove_file(&(bd->pdev->dev), &dev_attr_ports_state);
5990 device_remove_file(&(bd->pdev->dev), &dev_attr_ports_baud);
5991 device_remove_file(&(bd->pdev->dev), &dev_attr_ports_msignals);
5992 device_remove_file(&(bd->pdev->dev), &dev_attr_ports_iflag);
5993 device_remove_file(&(bd->pdev->dev), &dev_attr_ports_cflag);
5994 device_remove_file(&(bd->pdev->dev), &dev_attr_ports_oflag);
5995 device_remove_file(&(bd->pdev->dev), &dev_attr_ports_lflag);
5996 device_remove_file(&(bd->pdev->dev), &dev_attr_ports_digi_flag);
5997 device_remove_file(&(bd->pdev->dev), &dev_attr_ports_rxcount);
5998 device_remove_file(&(bd->pdev->dev), &dev_attr_ports_txcount);
6002 * Copies the BIOS code from the user to the board,
6003 * and starts the BIOS running.
6005 static void dgap_do_bios_load(struct board_t *brd, const u8 *ubios, int len)
6011 if (!brd || (brd->magic != DGAP_BOARD_MAGIC) || !brd->re_map_membase)
6014 addr = brd->re_map_membase;
6019 for (i = 0; i < 16; i++)
6020 writeb(0, addr + POSTAREA + i);
6026 memcpy_toio(addr + offset, ubios, len);
6028 writel(0x0bf00401, addr);
6029 writel(0, (addr + 4));
6031 /* Clear the reset, and change states. */
6032 writeb(FEPCLR, brd->re_map_port);
6036 * Checks to see if the BIOS completed running on the card.
6038 static int dgap_test_bios(struct board_t *brd)
6045 if (!brd || (brd->magic != DGAP_BOARD_MAGIC) || !brd->re_map_membase)
6048 addr = brd->re_map_membase;
6049 word = readw(addr + POSTAREA);
6052 * It can take 5-6 seconds for a board to
6053 * pass the bios self test and post results.
6054 * Give it 10 seconds.
6056 brd->wait_for_bios = 0;
6057 while (brd->wait_for_bios < 1000) {
6058 /* Check to see if BIOS thinks board is good. (GD). */
6059 if (word == *(u16 *) "GD")
6061 msleep_interruptible(10);
6062 brd->wait_for_bios++;
6063 word = readw(addr + POSTAREA);
6066 /* Gave up on board after too long of time taken */
6067 err1 = readw(addr + SEQUENCE);
6068 err2 = readw(addr + ERROR);
6069 dev_warn(&brd->pdev->dev, "%s failed diagnostics. Error #(%x,%x).\n",
6070 brd->name, err1, err2);
6071 brd->state = BOARD_FAILED;
6072 brd->dpastatus = BD_NOBIOS;
6078 * Copies the FEP code from the user to the board,
6079 * and starts the FEP running.
6081 static void dgap_do_fep_load(struct board_t *brd, const u8 *ufep, int len)
6086 if (!brd || (brd->magic != DGAP_BOARD_MAGIC) || !brd->re_map_membase)
6089 addr = brd->re_map_membase;
6095 memcpy_toio(addr + offset, ufep, len);
6098 * If board is a concentrator product, we need to give
6099 * it its config string describing how the concentrators look.
6101 if ((brd->type == PCX) || (brd->type == PEPC)) {
6107 xconfig = dgap_create_config_string(brd, string);
6109 /* Write string to board memory */
6110 config = addr + CONFIG;
6111 for (; i < CONFIGSIZE; i++, config++, xconfig++) {
6112 writeb(*xconfig, config);
6113 if ((*xconfig & 0xff) == 0xff)
6118 writel(0xbfc01004, (addr + 0xc34));
6119 writel(0x3, (addr + 0xc30));
6124 * Waits for the FEP to report thats its ready for us to use.
6126 static int dgap_test_fep(struct board_t *brd)
6133 if (!brd || (brd->magic != DGAP_BOARD_MAGIC) || !brd->re_map_membase)
6136 addr = brd->re_map_membase;
6137 word = readw(addr + FEPSTAT);
6140 * It can take 2-3 seconds for the FEP to
6141 * be up and running. Give it 5 secs.
6143 brd->wait_for_fep = 0;
6144 while (brd->wait_for_fep < 500) {
6145 /* Check to see if FEP is up and running now. */
6146 if (word == *(u16 *) "OS") {
6148 * Check to see if the board can support FEP5+ commands.
6150 word = readw(addr + FEP5_PLUS);
6151 if (word == *(u16 *) "5A")
6152 brd->bd_flags |= BD_FEP5PLUS;
6156 msleep_interruptible(10);
6157 brd->wait_for_fep++;
6158 word = readw(addr + FEPSTAT);
6161 /* Gave up on board after too long of time taken */
6162 err1 = readw(addr + SEQUENCE);
6163 err2 = readw(addr + ERROR);
6164 dev_warn(&brd->pdev->dev,
6165 "FEPOS for %s not functioning. Error #(%x,%x).\n",
6166 brd->name, err1, err2);
6167 brd->state = BOARD_FAILED;
6168 brd->dpastatus = BD_NOFEP;
6174 * Physically forces the FEP5 card to reset itself.
6176 static void dgap_do_reset_board(struct board_t *brd)
6183 if (!brd || (brd->magic != DGAP_BOARD_MAGIC) ||
6184 !brd->re_map_membase || !brd->re_map_port)
6187 /* FEPRST does not vary among supported boards */
6188 writeb(FEPRST, brd->re_map_port);
6190 for (i = 0; i <= 1000; i++) {
6191 check = readb(brd->re_map_port) & 0xe;
6192 if (check == FEPRST)
6198 dev_warn(&brd->pdev->dev,
6199 "dgap: Board not resetting... Failing board.\n");
6200 brd->state = BOARD_FAILED;
6201 brd->dpastatus = BD_NOFEP;
6206 * Make sure there really is memory out there.
6208 writel(0xa55a3cc3, (brd->re_map_membase + LOWMEM));
6209 writel(0x5aa5c33c, (brd->re_map_membase + HIGHMEM));
6210 check1 = readl(brd->re_map_membase + LOWMEM);
6211 check2 = readl(brd->re_map_membase + HIGHMEM);
6213 if ((check1 != 0xa55a3cc3) || (check2 != 0x5aa5c33c)) {
6214 dev_warn(&brd->pdev->dev,
6215 "No memory at %p for board.\n",
6216 brd->re_map_membase);
6217 brd->state = BOARD_FAILED;
6218 brd->dpastatus = BD_NOFEP;
6223 #ifdef DIGI_CONCENTRATORS_SUPPORTED
6225 * Sends a concentrator image into the FEP5 board.
6227 static void dgap_do_conc_load(struct board_t *brd, u8 *uaddr, int len)
6229 char __iomem *vaddr;
6231 struct downld_t *to_dp;
6233 if (!brd || (brd->magic != DGAP_BOARD_MAGIC) || !brd->re_map_membase)
6236 vaddr = brd->re_map_membase;
6238 offset = readw((u16 *) (vaddr + DOWNREQ));
6239 to_dp = (struct downld_t *) (vaddr + (int) offset);
6240 memcpy_toio(to_dp, uaddr, len);
6242 /* Tell card we have data for it */
6243 writew(0, vaddr + (DOWNREQ));
6245 brd->conc_dl_status = NO_PENDING_CONCENTRATOR_REQUESTS;
6249 #define EXPANSION_ROM_SIZE (64 * 1024)
6250 #define FEP5_ROM_MAGIC (0xFEFFFFFF)
6252 static void dgap_get_vpd(struct board_t *brd)
6264 * Poke the magic number at the PCI Rom Address location.
6265 * If VPD is supported, the value read from that address
6268 magic = FEP5_ROM_MAGIC;
6269 pci_write_config_dword(brd->pdev, PCI_ROM_ADDRESS, magic);
6270 pci_read_config_dword(brd->pdev, PCI_ROM_ADDRESS, &magic);
6272 /* VPD not supported, bail */
6277 * To get to the OTPROM memory, we have to send the boards base
6278 * address or'ed with 1 into the PCI Rom Address location.
6280 magic = brd->membase | 0x01;
6281 pci_write_config_dword(brd->pdev, PCI_ROM_ADDRESS, magic);
6282 pci_read_config_dword(brd->pdev, PCI_ROM_ADDRESS, &magic);
6284 byte1 = readb(brd->re_map_membase);
6285 byte2 = readb(brd->re_map_membase + 1);
6288 * If the board correctly swapped to the OTPROM memory,
6289 * the first 2 bytes (header) should be 0x55, 0xAA
6291 if (byte1 == 0x55 && byte2 == 0xAA) {
6296 * We have to run through all the OTPROM memory looking
6297 * for the VPD offset.
6299 while (base_offset <= EXPANSION_ROM_SIZE) {
6302 * Lots of magic numbers here.
6304 * The VPD offset is located inside the ROM Data
6307 * We also have to remember the length of each
6308 * ROM Data Structure, so we can "hop" to the next
6309 * entry if the VPD isn't in the current
6310 * ROM Data Structure.
6312 rom_offset = readw(brd->re_map_membase +
6313 base_offset + 0x18);
6314 image_length = readw(brd->re_map_membase +
6315 rom_offset + 0x10) * 512;
6316 vpd_offset = readw(brd->re_map_membase +
6319 /* Found the VPD entry */
6323 /* We didn't find a VPD entry, go to next ROM entry. */
6324 base_offset += image_length;
6326 byte1 = readb(brd->re_map_membase + base_offset);
6327 byte2 = readb(brd->re_map_membase + base_offset + 1);
6330 * If the new ROM offset doesn't have 0x55, 0xAA
6331 * as its header, we have run out of ROM.
6333 if (byte1 != 0x55 || byte2 != 0xAA)
6338 * If we have a VPD offset, then mark the board
6339 * as having a valid VPD, and copy VPDSIZE (512) bytes of
6340 * that VPD to the buffer we have in our board structure.
6343 brd->bd_flags |= BD_HAS_VPD;
6344 for (i = 0; i < VPDSIZE; i++) {
6345 brd->vpd[i] = readb(brd->re_map_membase +
6352 * We MUST poke the magic number at the PCI Rom Address location again.
6353 * This makes the card report the regular board memory back to us,
6354 * rather than the OTPROM memory.
6356 magic = FEP5_ROM_MAGIC;
6357 pci_write_config_dword(brd->pdev, PCI_ROM_ADDRESS, magic);
6361 static ssize_t dgap_driver_version_show(struct device_driver *ddp, char *buf)
6363 return snprintf(buf, PAGE_SIZE, "%s\n", DG_PART);
6365 static DRIVER_ATTR(version, S_IRUSR, dgap_driver_version_show, NULL);
6368 static ssize_t dgap_driver_boards_show(struct device_driver *ddp, char *buf)
6370 return snprintf(buf, PAGE_SIZE, "%d\n", dgap_numboards);
6372 static DRIVER_ATTR(boards, S_IRUSR, dgap_driver_boards_show, NULL);
6375 static ssize_t dgap_driver_maxboards_show(struct device_driver *ddp, char *buf)
6377 return snprintf(buf, PAGE_SIZE, "%d\n", MAXBOARDS);
6379 static DRIVER_ATTR(maxboards, S_IRUSR, dgap_driver_maxboards_show, NULL);
6382 static ssize_t dgap_driver_pollcounter_show(struct device_driver *ddp,
6385 return snprintf(buf, PAGE_SIZE, "%ld\n", dgap_poll_counter);
6387 static DRIVER_ATTR(pollcounter, S_IRUSR, dgap_driver_pollcounter_show, NULL);
6389 static ssize_t dgap_driver_pollrate_show(struct device_driver *ddp, char *buf)
6391 return snprintf(buf, PAGE_SIZE, "%dms\n", dgap_poll_tick);
6394 static ssize_t dgap_driver_pollrate_store(struct device_driver *ddp,
6395 const char *buf, size_t count)
6397 if (sscanf(buf, "%d\n", &dgap_poll_tick) != 1)
6401 static DRIVER_ATTR(pollrate, (S_IRUSR | S_IWUSR), dgap_driver_pollrate_show,
6402 dgap_driver_pollrate_store);
6405 static int dgap_create_driver_sysfiles(struct pci_driver *dgap_driver)
6408 struct device_driver *driverfs = &dgap_driver->driver;
6410 rc |= driver_create_file(driverfs, &driver_attr_version);
6411 rc |= driver_create_file(driverfs, &driver_attr_boards);
6412 rc |= driver_create_file(driverfs, &driver_attr_maxboards);
6413 rc |= driver_create_file(driverfs, &driver_attr_pollrate);
6414 rc |= driver_create_file(driverfs, &driver_attr_pollcounter);
6419 static void dgap_remove_driver_sysfiles(struct pci_driver *dgap_driver)
6421 struct device_driver *driverfs = &dgap_driver->driver;
6423 driver_remove_file(driverfs, &driver_attr_version);
6424 driver_remove_file(driverfs, &driver_attr_boards);
6425 driver_remove_file(driverfs, &driver_attr_maxboards);
6426 driver_remove_file(driverfs, &driver_attr_pollrate);
6427 driver_remove_file(driverfs, &driver_attr_pollcounter);
6430 static struct attribute_group dgap_tty_attribute_group = {
6432 .attrs = dgap_sysfs_tty_entries,
6435 static void dgap_create_tty_sysfs(struct un_t *un, struct device *c)
6439 ret = sysfs_create_group(&c->kobj, &dgap_tty_attribute_group);
6443 dev_set_drvdata(c, un);
6447 static void dgap_remove_tty_sysfs(struct device *c)
6449 sysfs_remove_group(&c->kobj, &dgap_tty_attribute_group);
6453 * Create pr and tty device entries
6455 static int dgap_tty_register_ports(struct board_t *brd)
6457 struct channel_t *ch;
6461 brd->serial_ports = kcalloc(brd->nasync, sizeof(*brd->serial_ports),
6463 if (!brd->serial_ports)
6466 brd->printer_ports = kcalloc(brd->nasync, sizeof(*brd->printer_ports),
6468 if (!brd->printer_ports) {
6470 goto free_serial_ports;
6473 for (i = 0; i < brd->nasync; i++) {
6474 tty_port_init(&brd->serial_ports[i]);
6475 tty_port_init(&brd->printer_ports[i]);
6478 ch = brd->channels[0];
6479 for (i = 0; i < brd->nasync; i++, ch = brd->channels[i]) {
6481 struct device *classp;
6483 classp = tty_port_register_device(&brd->serial_ports[i],
6487 if (IS_ERR(classp)) {
6488 ret = PTR_ERR(classp);
6489 goto unregister_ttys;
6492 dgap_create_tty_sysfs(&ch->ch_tun, classp);
6493 ch->ch_tun.un_sysfs = classp;
6495 classp = tty_port_register_device(&brd->printer_ports[i],
6499 if (IS_ERR(classp)) {
6500 ret = PTR_ERR(classp);
6501 goto unregister_ttys;
6504 dgap_create_tty_sysfs(&ch->ch_pun, classp);
6505 ch->ch_pun.un_sysfs = classp;
6507 dgap_create_ports_sysfiles(brd);
6513 ch = brd->channels[i];
6514 if (ch->ch_tun.un_sysfs) {
6515 dgap_remove_tty_sysfs(ch->ch_tun.un_sysfs);
6516 tty_unregister_device(brd->serial_driver, i);
6519 if (ch->ch_pun.un_sysfs) {
6520 dgap_remove_tty_sysfs(ch->ch_pun.un_sysfs);
6521 tty_unregister_device(brd->print_driver, i);
6526 for (i = 0; i < brd->nasync; i++) {
6527 tty_port_destroy(&brd->serial_ports[i]);
6528 tty_port_destroy(&brd->printer_ports[i]);
6531 kfree(brd->printer_ports);
6532 brd->printer_ports = NULL;
6535 kfree(brd->serial_ports);
6536 brd->serial_ports = NULL;
6542 * dgap_cleanup_tty()
6544 * Uninitialize the TTY portion of this driver. Free all memory and
6547 static void dgap_cleanup_tty(struct board_t *brd)
6552 for (i = 0; i < brd->nasync; i++) {
6553 tty_port_destroy(&brd->serial_ports[i]);
6554 dev = brd->channels[i]->ch_tun.un_sysfs;
6555 dgap_remove_tty_sysfs(dev);
6556 tty_unregister_device(brd->serial_driver, i);
6558 tty_unregister_driver(brd->serial_driver);
6559 put_tty_driver(brd->serial_driver);
6560 kfree(brd->serial_ports);
6562 for (i = 0; i < brd->nasync; i++) {
6563 tty_port_destroy(&brd->printer_ports[i]);
6564 dev = brd->channels[i]->ch_pun.un_sysfs;
6565 dgap_remove_tty_sysfs(dev);
6566 tty_unregister_device(brd->print_driver, i);
6568 tty_unregister_driver(brd->print_driver);
6569 put_tty_driver(brd->print_driver);
6570 kfree(brd->printer_ports);
6573 static int dgap_request_irq(struct board_t *brd)
6577 if (!brd || brd->magic != DGAP_BOARD_MAGIC)
6581 * Set up our interrupt handler if we are set to do interrupts.
6583 if (dgap_config_get_useintr(brd) && brd->irq) {
6585 rc = request_irq(brd->irq, dgap_intr, IRQF_SHARED, "DGAP", brd);
6593 static void dgap_free_irq(struct board_t *brd)
6595 if (brd->intr_used && brd->irq)
6596 free_irq(brd->irq, brd);
6599 static int dgap_firmware_load(struct pci_dev *pdev, int card_type,
6600 struct board_t *brd)
6602 const struct firmware *fw;
6605 char *dgap_config_buf;
6608 dgap_do_reset_board(brd);
6610 if (fw_info[card_type].conf_name) {
6611 ret = request_firmware(&fw, fw_info[card_type].conf_name,
6614 dev_err(&pdev->dev, "config file %s not found\n",
6615 fw_info[card_type].conf_name);
6619 dgap_config_buf = kzalloc(fw->size + 1, GFP_KERNEL);
6620 if (!dgap_config_buf) {
6621 release_firmware(fw);
6625 memcpy(dgap_config_buf, fw->data, fw->size);
6626 release_firmware(fw);
6629 * preserve dgap_config_buf
6630 * as dgap_parsefile would
6631 * otherwise alter it.
6633 tmp_ptr = dgap_config_buf;
6635 if (dgap_parsefile(&tmp_ptr) != 0) {
6636 kfree(dgap_config_buf);
6639 kfree(dgap_config_buf);
6643 * Match this board to a config the user created for us.
6646 dgap_find_config(brd->type, brd->pci_bus, brd->pci_slot);
6649 * Because the 4 port Xr products share the same PCI ID
6650 * as the 8 port Xr products, if we receive a NULL config
6651 * back, and this is a PAPORT8 board, retry with a
6652 * PAPORT4 attempt as well.
6654 if (brd->type == PAPORT8 && !brd->bd_config)
6656 dgap_find_config(PAPORT4, brd->pci_bus, brd->pci_slot);
6658 if (!brd->bd_config) {
6659 dev_err(&pdev->dev, "No valid configuration found\n");
6663 if (fw_info[card_type].bios_name) {
6664 ret = request_firmware(&fw, fw_info[card_type].bios_name,
6667 dev_err(&pdev->dev, "bios file %s not found\n",
6668 fw_info[card_type].bios_name);
6671 dgap_do_bios_load(brd, fw->data, fw->size);
6672 release_firmware(fw);
6674 /* Wait for BIOS to test board... */
6675 ret = dgap_test_bios(brd);
6680 if (fw_info[card_type].fep_name) {
6681 ret = request_firmware(&fw, fw_info[card_type].fep_name,
6684 dev_err(&pdev->dev, "dgap: fep file %s not found\n",
6685 fw_info[card_type].fep_name);
6688 dgap_do_fep_load(brd, fw->data, fw->size);
6689 release_firmware(fw);
6691 /* Wait for FEP to load on board... */
6692 ret = dgap_test_fep(brd);
6697 #ifdef DIGI_CONCENTRATORS_SUPPORTED
6699 * If this is a CX or EPCX, we need to see if the firmware
6700 * is requesting a concentrator image from us.
6702 if ((bd->type == PCX) || (bd->type == PEPC)) {
6703 chk_addr = (u16 *) (vaddr + DOWNREQ);
6704 /* Nonzero if FEP is requesting concentrator image. */
6705 check = readw(chk_addr);
6706 vaddr = brd->re_map_membase;
6709 if (fw_info[card_type].con_name && check && vaddr) {
6710 ret = request_firmware(&fw, fw_info[card_type].con_name,
6713 dev_err(&pdev->dev, "conc file %s not found\n",
6714 fw_info[card_type].con_name);
6717 /* Put concentrator firmware loading code here */
6718 offset = readw((u16 *) (vaddr + DOWNREQ));
6719 memcpy_toio(offset, fw->data, fw->size);
6721 dgap_do_conc_load(brd, (char *)fw->data, fw->size)
6722 release_firmware(fw);
6732 * Init the tty subsystem. Called once per board after board has been
6733 * downloaded and init'ed.
6735 static int dgap_tty_init(struct board_t *brd)
6742 struct channel_t *ch;
6743 struct bs_t __iomem *bs;
6744 struct cm_t __iomem *cm;
6748 * Initialize board structure elements.
6751 vaddr = brd->re_map_membase;
6752 true_count = readw((vaddr + NCHAN));
6754 brd->nasync = dgap_config_get_num_prts(brd);
6757 brd->nasync = brd->maxports;
6759 if (brd->nasync > brd->maxports)
6760 brd->nasync = brd->maxports;
6762 if (true_count != brd->nasync) {
6763 dev_warn(&brd->pdev->dev,
6764 "%s configured for %d ports, has %d ports.\n",
6765 brd->name, brd->nasync, true_count);
6767 if ((brd->type == PPCM) &&
6768 (true_count == 64 || true_count == 0)) {
6769 dev_warn(&brd->pdev->dev,
6770 "Please make SURE the EBI cable running from the card\n");
6771 dev_warn(&brd->pdev->dev,
6772 "to each EM module is plugged into EBI IN!\n");
6775 brd->nasync = true_count;
6777 /* If no ports, don't bother going any further */
6779 brd->state = BOARD_FAILED;
6780 brd->dpastatus = BD_NOFEP;
6786 * Allocate channel memory that might not have been allocated
6787 * when the driver was first loaded.
6789 for (i = 0; i < brd->nasync; i++) {
6791 kzalloc(sizeof(struct channel_t), GFP_KERNEL);
6792 if (!brd->channels[i]) {
6798 ch = brd->channels[0];
6799 vaddr = brd->re_map_membase;
6801 bs = (struct bs_t __iomem *) ((ulong) vaddr + CHANBUF);
6802 cm = (struct cm_t __iomem *) ((ulong) vaddr + CMDBUF);
6806 /* Set up channel variables */
6807 for (i = 0; i < brd->nasync; i++, ch = brd->channels[i], bs++) {
6809 spin_lock_init(&ch->ch_lock);
6811 /* Store all our magic numbers */
6812 ch->magic = DGAP_CHANNEL_MAGIC;
6813 ch->ch_tun.magic = DGAP_UNIT_MAGIC;
6814 ch->ch_tun.un_type = DGAP_SERIAL;
6815 ch->ch_tun.un_ch = ch;
6816 ch->ch_tun.un_dev = i;
6818 ch->ch_pun.magic = DGAP_UNIT_MAGIC;
6819 ch->ch_pun.un_type = DGAP_PRINT;
6820 ch->ch_pun.un_ch = ch;
6821 ch->ch_pun.un_dev = i;
6823 ch->ch_vaddr = vaddr;
6828 ch->ch_digi = dgap_digi_init;
6831 * Set up digi dsr and dcd bits based on altpin flag.
6833 if (dgap_config_get_altpin(brd)) {
6836 ch->ch_digi.digi_flags |= DIGI_ALTPIN;
6839 ch->ch_dsr = DM_DSR;
6842 ch->ch_taddr = vaddr + (ioread16(&(ch->ch_bs->tx_seg)) << 4);
6843 ch->ch_raddr = vaddr + (ioread16(&(ch->ch_bs->rx_seg)) << 4);
6846 ch->ch_tsize = readw(&(ch->ch_bs->tx_max)) + 1;
6847 ch->ch_rsize = readw(&(ch->ch_bs->rx_max)) + 1;
6852 * Set queue water marks, interrupt mask,
6853 * and general tty parameters.
6855 tlw = ch->ch_tsize >= 2000 ? ((ch->ch_tsize * 5) / 8) :
6859 dgap_cmdw(ch, STLOW, tlw, 0);
6861 dgap_cmdw(ch, SRLOW, ch->ch_rsize / 2, 0);
6863 dgap_cmdw(ch, SRHIGH, 7 * ch->ch_rsize / 8, 0);
6865 ch->ch_mistat = readb(&(ch->ch_bs->m_stat));
6867 init_waitqueue_head(&ch->ch_flags_wait);
6868 init_waitqueue_head(&ch->ch_tun.un_flags_wait);
6869 init_waitqueue_head(&ch->ch_pun.un_flags_wait);
6871 /* Turn on all modem interrupts for now */
6872 modem = (DM_CD | DM_DSR | DM_CTS | DM_RI);
6873 writeb(modem, &(ch->ch_bs->m_int));
6876 * Set edelay to 0 if interrupts are turned on,
6877 * otherwise set edelay to the usual 100.
6880 writew(0, &(ch->ch_bs->edelay));
6882 writew(100, &(ch->ch_bs->edelay));
6884 writeb(1, &(ch->ch_bs->idata));
6891 kfree(brd->channels[i]);
6892 brd->channels[i] = NULL;
6900 * Free the channles which are allocated in dgap_tty_init().
6902 static void dgap_tty_free(struct board_t *brd)
6906 for (i = 0; i < brd->nasync; i++)
6907 kfree(brd->channels[i]);
6910 static int dgap_init_one(struct pci_dev *pdev, const struct pci_device_id *ent)
6913 struct board_t *brd;
6915 if (dgap_numboards >= MAXBOARDS)
6918 rc = pci_enable_device(pdev);
6922 brd = dgap_found_board(pdev, ent->driver_data, dgap_numboards);
6924 return PTR_ERR(brd);
6926 rc = dgap_firmware_load(pdev, ent->driver_data, brd);
6930 rc = dgap_alloc_flipbuf(brd);
6934 rc = dgap_tty_register(brd);
6938 rc = dgap_request_irq(brd);
6940 goto unregister_tty;
6943 * Do tty device initialization.
6945 rc = dgap_tty_init(brd);
6949 rc = dgap_tty_register_ports(brd);
6953 brd->state = BOARD_READY;
6954 brd->dpastatus = BD_RUNNING;
6956 dgap_board[dgap_numboards++] = brd;
6965 dgap_tty_unregister(brd);
6967 dgap_free_flipbuf(brd);
6969 dgap_cleanup_nodes();
6977 * dgap_cleanup_board()
6979 * Free all the memory associated with a board
6981 static void dgap_cleanup_board(struct board_t *brd)
6985 if (!brd || brd->magic != DGAP_BOARD_MAGIC)
6990 tasklet_kill(&brd->helper_tasklet);
6994 /* Free all allocated channels structs */
6995 for (i = 0; i < MAXPORTS ; i++)
6996 kfree(brd->channels[i]);
6998 kfree(brd->flipbuf);
6999 kfree(brd->flipflagbuf);
7001 dgap_board[brd->boardnum] = NULL;
7006 static void dgap_stop(bool removesys, struct pci_driver *drv)
7008 unsigned long lock_flags;
7010 spin_lock_irqsave(&dgap_poll_lock, lock_flags);
7012 spin_unlock_irqrestore(&dgap_poll_lock, lock_flags);
7014 del_timer_sync(&dgap_poll_timer);
7016 dgap_remove_driver_sysfiles(drv);
7018 device_destroy(dgap_class, MKDEV(DIGI_DGAP_MAJOR, 0));
7019 class_destroy(dgap_class);
7020 unregister_chrdev(DIGI_DGAP_MAJOR, "dgap");
7023 static void dgap_remove_one(struct pci_dev *dev)
7026 struct pci_driver *drv = to_pci_driver(dev->dev.driver);
7028 dgap_stop(true, drv);
7029 for (i = 0; i < dgap_numboards; ++i) {
7030 dgap_remove_ports_sysfiles(dgap_board[i]);
7031 dgap_cleanup_tty(dgap_board[i]);
7032 dgap_cleanup_board(dgap_board[i]);
7035 dgap_cleanup_nodes();
7038 static struct pci_driver dgap_driver = {
7040 .probe = dgap_init_one,
7041 .id_table = dgap_pci_tbl,
7042 .remove = dgap_remove_one,
7048 static int dgap_start(void)
7051 unsigned long flags;
7052 struct device *device;
7056 pr_info("For the tools package please visit http://www.digi.com\n");
7059 * Register our base character device into the kernel.
7063 * Register management/dpa devices
7065 rc = register_chrdev(DIGI_DGAP_MAJOR, "dgap", &dgap_board_fops);
7069 dgap_class = class_create(THIS_MODULE, "dgap_mgmt");
7070 if (IS_ERR(dgap_class)) {
7071 rc = PTR_ERR(dgap_class);
7075 device = device_create(dgap_class, NULL,
7076 MKDEV(DIGI_DGAP_MAJOR, 0),
7078 if (IS_ERR(device)) {
7079 rc = PTR_ERR(device);
7083 /* Start the poller */
7084 spin_lock_irqsave(&dgap_poll_lock, flags);
7085 setup_timer(&dgap_poll_timer, dgap_poll_handler, 0);
7086 dgap_poll_timer.data = 0;
7087 dgap_poll_time = jiffies + dgap_jiffies_from_ms(dgap_poll_tick);
7088 dgap_poll_timer.expires = dgap_poll_time;
7089 spin_unlock_irqrestore(&dgap_poll_lock, flags);
7091 add_timer(&dgap_poll_timer);
7096 class_destroy(dgap_class);
7098 unregister_chrdev(DIGI_DGAP_MAJOR, "dgap");
7102 /************************************************************************
7104 * Driver load/unload functions
7106 ************************************************************************/
7111 * Module load. This is where it all starts.
7113 static int dgap_init_module(void)
7117 pr_info("%s, Digi International Part Number %s\n", DG_NAME, DG_PART);
7123 rc = pci_register_driver(&dgap_driver);
7125 dgap_stop(false, NULL);
7129 rc = dgap_create_driver_sysfiles(&dgap_driver);
7131 goto err_unregister;
7133 dgap_driver_state = DRIVER_READY;
7138 pci_unregister_driver(&dgap_driver);
7143 * dgap_cleanup_module()
7145 * Module unload. This is where it all ends.
7147 static void dgap_cleanup_module(void)
7150 pci_unregister_driver(&dgap_driver);
7153 module_init(dgap_init_module);
7154 module_exit(dgap_cleanup_module);
7156 MODULE_LICENSE("GPL");
7157 MODULE_AUTHOR("Digi International, http://www.digi.com");
7158 MODULE_DESCRIPTION("Driver for the Digi International EPCA PCI based product line");
7159 MODULE_SUPPORTED_DEVICE("dgap");