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. If the first character is a ^, then
294 * this will match the first occurrence not in that group.
296 static char *dgap_sindex(char *string, char *group)
300 if (!string || !group)
305 for (; *string; string++) {
306 for (ptr = group; *ptr; ptr++) {
314 for (; *string; string++) {
315 for (ptr = group; *ptr; ptr++) {
326 * get a word from the input stream, also keep track of current line number.
327 * words are separated by whitespace.
329 static char *dgap_getword(char **in)
333 char *ptr = dgap_sindex(*in, " \t\n");
335 /* If no word found, return null */
339 /* Mark new location for our buffer */
343 /* Eat any extra spaces/tabs/newlines that might be present */
344 while (*in && **in && ((**in == ' ') ||
356 * Get a token from the input file; return 0 if end of file is reached
358 static int dgap_gettok(char **in)
363 if (strstr(dgap_cword, "board")) {
364 w = dgap_getword(in);
365 snprintf(dgap_cword, MAXCWORD, "%s", w);
366 for (t = dgap_brdtype; t->token != 0; t++) {
367 if (!strcmp(w, t->string))
371 while ((w = dgap_getword(in))) {
372 snprintf(dgap_cword, MAXCWORD, "%s", w);
373 for (t = dgap_tlist; t->token != 0; t++) {
374 if (!strcmp(w, t->string))
384 * dgap_checknode: see if all the necessary info has been supplied for a node
385 * before creating the next node.
387 static int dgap_checknode(struct cnode *p)
391 if (p->u.line.v_speed == 0) {
392 pr_err("line speed not specified");
398 if (p->u.conc.v_speed == 0) {
399 pr_err("concentrator line speed not specified");
402 if (p->u.conc.v_nport == 0) {
403 pr_err("number of ports on concentrator not specified");
406 if (p->u.conc.v_id == 0) {
407 pr_err("concentrator id letter not specified");
413 if (p->u.module.v_nport == 0) {
414 pr_err("number of ports on EBI module not specified");
417 if (p->u.module.v_id == 0) {
418 pr_err("EBI module id letter not specified");
427 * Given a board pointer, returns whether we should use interrupts or not.
429 static uint dgap_config_get_useintr(struct board_t *bd)
436 for (p = bd->bd_config; p; p = p->next) {
437 if (p->type == INTRNODE) {
439 * check for pcxr types.
445 /* If not found, then don't turn on interrupts. */
450 * Given a board pointer, returns whether we turn on altpin or not.
452 static uint dgap_config_get_altpin(struct board_t *bd)
459 for (p = bd->bd_config; p; p = p->next) {
460 if (p->type == ANODE) {
462 * check for pcxr types.
468 /* If not found, then don't turn on interrupts. */
473 * Given a specific type of board, if found, detached link and
474 * returns the first occurrence in the list.
476 static struct cnode *dgap_find_config(int type, int bus, int slot)
478 struct cnode *p, *prev, *prev2, *found;
486 if (p->type != BNODE)
489 if (p->u.board.type != type)
492 if (p->u.board.v_pcibus &&
493 p->u.board.pcibus != bus)
496 if (p->u.board.v_pcislot &&
497 p->u.board.pcislot != slot)
502 * Keep walking thru the list till we
503 * find the next board.
509 if (p->type != BNODE)
513 * Mark the end of our 1 board
519 * Link the "next" board to the
520 * previous board, effectively
521 * "unlinking" our board from
529 * It must be the last board in the list.
538 * Given a board pointer, walks the config link, counting up
539 * all ports user specified should be on the board.
540 * (This does NOT mean they are all actually present right now tho)
542 static uint dgap_config_get_num_prts(struct board_t *bd)
550 for (p = bd->bd_config; p; p = p->next) {
555 * check for pcxr types.
557 if (p->u.board.type > EPCFE)
558 count += p->u.board.nport;
561 count += p->u.conc.nport;
564 count += p->u.module.nport;
571 static char *dgap_create_config_string(struct board_t *bd, char *string)
583 for (p = bd->bd_config; p; p = p->next) {
589 *ptr = p->u.line.speed;
594 * Because the EPC/con concentrators can have EM modules
595 * hanging off of them, we have to walk ahead in the
596 * list and keep adding the number of ports on each EM
597 * to the config. UGH!
599 speed = p->u.conc.speed;
601 if (q && (q->type == MNODE)) {
602 *ptr = (p->u.conc.nport + 0x80);
605 while (q->next && (q->next->type) == MNODE) {
606 *ptr = (q->u.module.nport + 0x80);
611 *ptr = q->u.module.nport;
614 *ptr = p->u.conc.nport;
629 * Parse a configuration file read into memory as a string.
631 static int dgap_parsefile(char **in)
633 struct cnode *p, *brd, *line, *conc;
639 brd = line = conc = NULL;
641 /* perhaps we are adding to an existing list? */
645 /* file must start with a BEGIN */
646 while ((rc = dgap_gettok(in)) != BEGIN) {
648 pr_err("unexpected EOF");
658 rc = dgap_gettok(in);
660 pr_err("unexpected EOF");
665 case BEGIN: /* should only be 1 begin */
666 pr_err("unexpected config_begin\n");
672 case BOARD: /* board info */
673 if (dgap_checknode(p))
676 p->next = kzalloc(sizeof(struct cnode), GFP_KERNEL);
683 p->u.board.status = kstrdup("No", GFP_KERNEL);
688 board_type = dgap_gettok(in);
689 if (board_type == 0) {
690 pr_err("board !!type not specified");
694 p->u.board.type = board_type;
698 case IO: /* i/o port */
699 if (p->type != BNODE) {
700 pr_err("IO port only valid for boards");
703 s = dgap_getword(in);
705 pr_err("unexpected end of file");
708 p->u.board.portstr = kstrdup(s, GFP_KERNEL);
709 if (kstrtol(s, 0, &p->u.board.port)) {
710 pr_err("bad number for IO port");
713 p->u.board.v_port = 1;
716 case MEM: /* memory address */
717 if (p->type != BNODE) {
718 pr_err("memory address only valid for boards");
721 s = dgap_getword(in);
723 pr_err("unexpected end of file");
726 p->u.board.addrstr = kstrdup(s, GFP_KERNEL);
727 if (kstrtoul(s, 0, &p->u.board.addr)) {
728 pr_err("bad number for memory address");
731 p->u.board.v_addr = 1;
734 case PCIINFO: /* pci information */
735 if (p->type != BNODE) {
736 pr_err("memory address only valid for boards");
739 s = dgap_getword(in);
741 pr_err("unexpected end of file");
744 p->u.board.pcibusstr = kstrdup(s, GFP_KERNEL);
745 if (kstrtoul(s, 0, &p->u.board.pcibus)) {
746 pr_err("bad number for pci bus");
749 p->u.board.v_pcibus = 1;
750 s = dgap_getword(in);
752 pr_err("unexpected end of file");
755 p->u.board.pcislotstr = kstrdup(s, GFP_KERNEL);
756 if (kstrtoul(s, 0, &p->u.board.pcislot)) {
757 pr_err("bad number for pci slot");
760 p->u.board.v_pcislot = 1;
764 if (p->type != BNODE) {
765 pr_err("install method only valid for boards");
768 s = dgap_getword(in);
770 pr_err("unexpected end of file");
773 p->u.board.method = kstrdup(s, GFP_KERNEL);
774 p->u.board.v_method = 1;
778 if (p->type != BNODE) {
779 pr_err("config status only valid for boards");
782 s = dgap_getword(in);
784 pr_err("unexpected end of file");
787 p->u.board.status = kstrdup(s, GFP_KERNEL);
790 case NPORTS: /* number of ports */
791 if (p->type == BNODE) {
792 s = dgap_getword(in);
794 pr_err("unexpected end of file");
797 if (kstrtol(s, 0, &p->u.board.nport)) {
798 pr_err("bad number for number of ports");
801 p->u.board.v_nport = 1;
802 } else if (p->type == CNODE) {
803 s = dgap_getword(in);
805 pr_err("unexpected end of file");
808 if (kstrtol(s, 0, &p->u.conc.nport)) {
809 pr_err("bad number for number of ports");
812 p->u.conc.v_nport = 1;
813 } else if (p->type == MNODE) {
814 s = dgap_getword(in);
816 pr_err("unexpected end of file");
819 if (kstrtol(s, 0, &p->u.module.nport)) {
820 pr_err("bad number for number of ports");
823 p->u.module.v_nport = 1;
825 pr_err("nports only valid for concentrators or modules");
830 case ID: /* letter ID used in tty name */
831 s = dgap_getword(in);
833 pr_err("unexpected end of file");
837 p->u.board.status = kstrdup(s, GFP_KERNEL);
839 if (p->type == CNODE) {
840 p->u.conc.id = kstrdup(s, GFP_KERNEL);
842 } else if (p->type == MNODE) {
843 p->u.module.id = kstrdup(s, GFP_KERNEL);
844 p->u.module.v_id = 1;
846 pr_err("id only valid for concentrators or modules");
851 case STARTO: /* start offset of ID */
852 if (p->type == BNODE) {
853 s = dgap_getword(in);
855 pr_err("unexpected end of file");
858 if (kstrtol(s, 0, &p->u.board.start)) {
859 pr_err("bad number for start of tty count");
862 p->u.board.v_start = 1;
863 } else if (p->type == CNODE) {
864 s = dgap_getword(in);
866 pr_err("unexpected end of file");
869 if (kstrtol(s, 0, &p->u.conc.start)) {
870 pr_err("bad number for start of tty count");
873 p->u.conc.v_start = 1;
874 } else if (p->type == MNODE) {
875 s = dgap_getword(in);
877 pr_err("unexpected end of file");
880 if (kstrtol(s, 0, &p->u.module.start)) {
881 pr_err("bad number for start of tty count");
884 p->u.module.v_start = 1;
886 pr_err("start only valid for concentrators or modules");
891 case TTYN: /* tty name prefix */
892 if (dgap_checknode(p))
895 p->next = kzalloc(sizeof(struct cnode), GFP_KERNEL);
902 s = dgap_getword(in);
904 pr_err("unexpeced end of file");
907 p->u.ttyname = kstrdup(s, GFP_KERNEL);
913 case CU: /* cu name prefix */
914 if (dgap_checknode(p))
917 p->next = kzalloc(sizeof(struct cnode), GFP_KERNEL);
924 s = dgap_getword(in);
926 pr_err("unexpeced end of file");
929 p->u.cuname = kstrdup(s, GFP_KERNEL);
935 case LINE: /* line information */
936 if (dgap_checknode(p))
939 pr_err("must specify board before line info");
942 switch (brd->u.board.type) {
944 pr_err("line not valid for PC/em");
948 p->next = kzalloc(sizeof(struct cnode), GFP_KERNEL);
959 case CONC: /* concentrator information */
960 if (dgap_checknode(p))
963 pr_err("must specify line info before concentrator");
967 p->next = kzalloc(sizeof(struct cnode), GFP_KERNEL);
976 brd->u.board.conc2++;
978 brd->u.board.conc1++;
980 conc_type = dgap_gettok(in);
981 if (conc_type == 0 || (conc_type != CX &&
983 pr_err("failed to set a type of concentratros");
987 p->u.conc.type = conc_type;
991 case MOD: /* EBI module */
992 if (dgap_checknode(p))
995 pr_err("must specify board info before EBI modules");
998 switch (brd->u.board.type) {
1004 pr_err("must specify concentrator info before EBI module");
1009 p->next = kzalloc(sizeof(struct cnode), GFP_KERNEL);
1017 brd->u.board.module2++;
1019 brd->u.board.module1++;
1021 module_type = dgap_gettok(in);
1022 if (module_type == 0 || (module_type != PORTS &&
1023 module_type != MODEM)) {
1024 pr_err("failed to set a type of module");
1028 p->u.module.type = module_type;
1033 if (p->type == LNODE) {
1034 s = dgap_getword(in);
1036 pr_err("unexpected end of file");
1039 p->u.line.cable = kstrdup(s, GFP_KERNEL);
1040 p->u.line.v_cable = 1;
1044 case SPEED: /* sync line speed indication */
1045 if (p->type == LNODE) {
1046 s = dgap_getword(in);
1048 pr_err("unexpected end of file");
1051 if (kstrtol(s, 0, &p->u.line.speed)) {
1052 pr_err("bad number for line speed");
1055 p->u.line.v_speed = 1;
1056 } else if (p->type == CNODE) {
1057 s = dgap_getword(in);
1059 pr_err("unexpected end of file");
1062 if (kstrtol(s, 0, &p->u.conc.speed)) {
1063 pr_err("bad number for line speed");
1066 p->u.conc.v_speed = 1;
1068 pr_err("speed valid only for lines or concentrators.");
1074 if (p->type == CNODE) {
1075 s = dgap_getword(in);
1077 pr_err("unexpected end of file");
1080 p->u.conc.connect = kstrdup(s, GFP_KERNEL);
1081 p->u.conc.v_connect = 1;
1084 case PRINT: /* transparent print name prefix */
1085 if (dgap_checknode(p))
1088 p->next = kzalloc(sizeof(struct cnode), GFP_KERNEL);
1095 s = dgap_getword(in);
1097 pr_err("unexpeced end of file");
1100 p->u.printname = kstrdup(s, GFP_KERNEL);
1101 if (!p->u.printname)
1106 case CMAJOR: /* major number */
1107 if (dgap_checknode(p))
1110 p->next = kzalloc(sizeof(struct cnode), GFP_KERNEL);
1117 s = dgap_getword(in);
1119 pr_err("unexpected end of file");
1122 if (kstrtol(s, 0, &p->u.majornumber)) {
1123 pr_err("bad number for major number");
1128 case ALTPIN: /* altpin setting */
1129 if (dgap_checknode(p))
1132 p->next = kzalloc(sizeof(struct cnode), GFP_KERNEL);
1139 s = dgap_getword(in);
1141 pr_err("unexpected end of file");
1144 if (kstrtol(s, 0, &p->u.altpin)) {
1145 pr_err("bad number for altpin");
1150 case USEINTR: /* enable interrupt setting */
1151 if (dgap_checknode(p))
1154 p->next = kzalloc(sizeof(struct cnode), GFP_KERNEL);
1160 s = dgap_getword(in);
1162 pr_err("unexpected end of file");
1165 if (kstrtol(s, 0, &p->u.useintr)) {
1166 pr_err("bad number for useintr");
1171 case TTSIZ: /* size of tty structure */
1172 if (dgap_checknode(p))
1175 p->next = kzalloc(sizeof(struct cnode), GFP_KERNEL);
1182 s = dgap_getword(in);
1184 pr_err("unexpected end of file");
1187 if (kstrtol(s, 0, &p->u.ttysize)) {
1188 pr_err("bad number for ttysize");
1193 case CHSIZ: /* channel structure size */
1194 if (dgap_checknode(p))
1197 p->next = kzalloc(sizeof(struct cnode), GFP_KERNEL);
1204 s = dgap_getword(in);
1206 pr_err("unexpected end of file");
1209 if (kstrtol(s, 0, &p->u.chsize)) {
1210 pr_err("bad number for chsize");
1215 case BSSIZ: /* board structure size */
1216 if (dgap_checknode(p))
1219 p->next = kzalloc(sizeof(struct cnode), GFP_KERNEL);
1226 s = dgap_getword(in);
1228 pr_err("unexpected end of file");
1231 if (kstrtol(s, 0, &p->u.bssize)) {
1232 pr_err("bad number for bssize");
1237 case UNTSIZ: /* sched structure size */
1238 if (dgap_checknode(p))
1241 p->next = kzalloc(sizeof(struct cnode), GFP_KERNEL);
1248 s = dgap_getword(in);
1250 pr_err("unexpected end of file");
1253 if (kstrtol(s, 0, &p->u.unsize)) {
1254 pr_err("bad number for schedsize");
1259 case F2SIZ: /* f2200 structure size */
1260 if (dgap_checknode(p))
1263 p->next = kzalloc(sizeof(struct cnode), GFP_KERNEL);
1270 s = dgap_getword(in);
1272 pr_err("unexpected end of file");
1275 if (kstrtol(s, 0, &p->u.f2size)) {
1276 pr_err("bad number for f2200size");
1281 case VPSIZ: /* vpix structure size */
1282 if (dgap_checknode(p))
1285 p->next = kzalloc(sizeof(struct cnode), GFP_KERNEL);
1292 s = dgap_getword(in);
1294 pr_err("unexpected end of file");
1297 if (kstrtol(s, 0, &p->u.vpixsize)) {
1298 pr_err("bad number for vpixsize");
1306 static void dgap_cleanup_nodes(void)
1313 struct cnode *tmp = p->next;
1315 if (p->type == NULLNODE) {
1322 kfree(p->u.board.portstr);
1323 kfree(p->u.board.addrstr);
1324 kfree(p->u.board.pcibusstr);
1325 kfree(p->u.board.pcislotstr);
1326 kfree(p->u.board.method);
1329 kfree(p->u.conc.id);
1330 kfree(p->u.conc.connect);
1333 kfree(p->u.module.id);
1336 kfree(p->u.ttyname);
1342 kfree(p->u.line.cable);
1345 kfree(p->u.printname);
1349 kfree(p->u.board.status);
1356 * Retrives the current custom baud rate from FEP memory,
1357 * and returns it back to the user.
1358 * Returns 0 on error.
1360 static uint dgap_get_custom_baud(struct channel_t *ch)
1366 if (!ch || ch->magic != DGAP_CHANNEL_MAGIC)
1369 if (!ch->ch_bd || ch->ch_bd->magic != DGAP_BOARD_MAGIC)
1372 if (!(ch->ch_bd->bd_flags & BD_FEP5PLUS))
1375 vaddr = ch->ch_bd->re_map_membase;
1381 * Go get from fep mem, what the fep
1382 * believes the custom baud rate is.
1384 offset = (ioread16(vaddr + ECS_SEG) << 4) + (ch->ch_portnum * 0x28)
1387 value = readw(vaddr + offset);
1394 static int dgap_remap(struct board_t *brd)
1396 if (!brd || brd->magic != DGAP_BOARD_MAGIC)
1399 if (!request_mem_region(brd->membase, 0x200000, "dgap"))
1402 if (!request_mem_region(brd->membase + PCI_IO_OFFSET, 0x200000,
1406 brd->re_map_membase = ioremap(brd->membase, 0x200000);
1407 if (!brd->re_map_membase)
1410 brd->re_map_port = ioremap((brd->membase + PCI_IO_OFFSET), 0x200000);
1411 if (!brd->re_map_port)
1412 goto err_remap_port;
1417 iounmap(brd->re_map_membase);
1419 release_mem_region(brd->membase + PCI_IO_OFFSET, 0x200000);
1421 release_mem_region(brd->membase, 0x200000);
1426 static void dgap_unmap(struct board_t *brd)
1428 iounmap(brd->re_map_port);
1429 iounmap(brd->re_map_membase);
1430 release_mem_region(brd->membase + PCI_IO_OFFSET, 0x200000);
1431 release_mem_region(brd->membase, 0x200000);
1435 * dgap_parity_scan()
1437 * Convert the FEP5 way of reporting parity errors and breaks into
1438 * the Linux line discipline way.
1440 static void dgap_parity_scan(struct channel_t *ch, unsigned char *cbuf,
1441 unsigned char *fbuf, int *len)
1445 unsigned char *in, *cout, *fout;
1452 if (!ch || ch->magic != DGAP_CHANNEL_MAGIC)
1457 switch (ch->pscan_state) {
1459 /* reset to sanity and fall through */
1460 ch->pscan_state = 0;
1463 /* No FF seen yet */
1464 if (c == (unsigned char) '\377')
1465 /* delete this character from stream */
1466 ch->pscan_state = 1;
1469 *fout++ = TTY_NORMAL;
1476 if (c == (unsigned char) '\377') {
1477 /* doubled ff, transform to single ff */
1479 *fout++ = TTY_NORMAL;
1481 ch->pscan_state = 0;
1483 /* save value examination in next state */
1484 ch->pscan_savechar = c;
1485 ch->pscan_state = 2;
1490 /* third character of ff sequence */
1494 if (ch->pscan_savechar == 0x0) {
1498 *fout++ = TTY_BREAK;
1500 ch->ch_err_parity++;
1501 *fout++ = TTY_PARITY;
1506 ch->pscan_state = 0;
1512 /*=======================================================================
1514 * dgap_input - Process received data.
1516 * ch - Pointer to channel structure.
1518 *=======================================================================*/
1520 static void dgap_input(struct channel_t *ch)
1523 struct bs_t __iomem *bs;
1524 struct tty_struct *tp;
1525 struct tty_ldisc *ld;
1539 if (!ch || ch->magic != DGAP_CHANNEL_MAGIC)
1542 tp = ch->ch_tun.un_tty;
1549 if (!bd || bd->magic != DGAP_BOARD_MAGIC)
1552 spin_lock_irqsave(&bd->bd_lock, lock_flags);
1553 spin_lock_irqsave(&ch->ch_lock, lock_flags2);
1556 * Figure the number of characters in the buffer.
1557 * Exit immediately if none.
1560 rmask = ch->ch_rsize - 1;
1562 head = readw(&(bs->rx_head));
1564 tail = readw(&(bs->rx_tail));
1567 data_len = (head - tail) & rmask;
1569 if (data_len == 0) {
1570 writeb(1, &(bs->idata));
1571 spin_unlock_irqrestore(&ch->ch_lock, lock_flags2);
1572 spin_unlock_irqrestore(&bd->bd_lock, lock_flags);
1577 * If the device is not open, or CREAD is off, flush
1578 * input data and return immediately.
1580 if ((bd->state != BOARD_READY) || !tp ||
1581 (tp->magic != TTY_MAGIC) ||
1582 !(ch->ch_tun.un_flags & UN_ISOPEN) ||
1583 !(tp->termios.c_cflag & CREAD) ||
1584 (ch->ch_tun.un_flags & UN_CLOSING)) {
1586 writew(head, &(bs->rx_tail));
1587 writeb(1, &(bs->idata));
1588 spin_unlock_irqrestore(&ch->ch_lock, lock_flags2);
1589 spin_unlock_irqrestore(&bd->bd_lock, lock_flags);
1594 * If we are throttled, simply don't read any data.
1596 if (ch->ch_flags & CH_RXBLOCK) {
1597 writeb(1, &(bs->idata));
1598 spin_unlock_irqrestore(&ch->ch_lock, lock_flags2);
1599 spin_unlock_irqrestore(&bd->bd_lock, lock_flags);
1606 tmpchar = readb(&(bs->orun));
1608 ch->ch_err_overrun++;
1609 writeb(0, &(bs->orun));
1612 /* Decide how much data we can send into the tty layer */
1613 flip_len = TTY_FLIPBUF_SIZE;
1615 /* Chop down the length, if needed */
1616 len = min(data_len, flip_len);
1617 len = min(len, (N_TTY_BUF_SIZE - 1));
1619 ld = tty_ldisc_ref(tp);
1621 #ifdef TTY_DONT_FLIP
1623 * If the DONT_FLIP flag is on, don't flush our buffer, and act
1624 * like the ld doesn't have any space to put the data right now.
1626 if (test_bit(TTY_DONT_FLIP, &tp->flags))
1631 * If we were unable to get a reference to the ld,
1632 * don't flush our buffer, and act like the ld doesn't
1633 * have any space to put the data right now.
1639 * If ld doesn't have a pointer to a receive_buf function,
1640 * flush the data, then act like the ld doesn't have any
1641 * space to put the data right now.
1643 if (!ld->ops->receive_buf) {
1644 writew(head, &(bs->rx_tail));
1650 writeb(1, &(bs->idata));
1651 spin_unlock_irqrestore(&ch->ch_lock, lock_flags2);
1652 spin_unlock_irqrestore(&bd->bd_lock, lock_flags);
1654 tty_ldisc_deref(ld);
1658 buf = ch->ch_bd->flipbuf;
1662 * n now contains the most amount of data we can copy,
1663 * bounded either by our buffer size or the amount
1664 * of data the card actually has pending...
1668 s = ((head >= tail) ? head : ch->ch_rsize) - tail;
1674 memcpy_fromio(buf, ch->ch_raddr + tail, s);
1680 /* Flip queue if needed */
1684 writew(tail, &(bs->rx_tail));
1685 writeb(1, &(bs->idata));
1686 ch->ch_rxcount += len;
1689 * If we are completely raw, we don't need to go through a lot
1690 * of the tty layers that exist.
1691 * In this case, we take the shortest and fastest route we
1692 * can to relay the data to the user.
1694 * On the other hand, if we are not raw, we need to go through
1695 * the tty layer, which has its API more well defined.
1697 if (I_PARMRK(tp) || I_BRKINT(tp) || I_INPCK(tp)) {
1698 dgap_parity_scan(ch, ch->ch_bd->flipbuf,
1699 ch->ch_bd->flipflagbuf, &len);
1701 len = tty_buffer_request_room(tp->port, len);
1702 tty_insert_flip_string_flags(tp->port, ch->ch_bd->flipbuf,
1703 ch->ch_bd->flipflagbuf, len);
1705 len = tty_buffer_request_room(tp->port, len);
1706 tty_insert_flip_string(tp->port, ch->ch_bd->flipbuf, len);
1709 spin_unlock_irqrestore(&ch->ch_lock, lock_flags2);
1710 spin_unlock_irqrestore(&bd->bd_lock, lock_flags);
1712 /* Tell the tty layer its okay to "eat" the data now */
1713 tty_flip_buffer_push(tp->port);
1716 tty_ldisc_deref(ld);
1720 static void dgap_write_wakeup(struct board_t *bd, struct channel_t *ch,
1721 struct un_t *un, u32 mask,
1722 unsigned long *irq_flags1,
1723 unsigned long *irq_flags2)
1725 if (!(un->un_flags & mask))
1728 un->un_flags &= ~mask;
1730 if (!(un->un_flags & UN_ISOPEN))
1733 if ((un->un_tty->flags & (1 << TTY_DO_WRITE_WAKEUP)) &&
1734 un->un_tty->ldisc->ops->write_wakeup) {
1735 spin_unlock_irqrestore(&ch->ch_lock, *irq_flags2);
1736 spin_unlock_irqrestore(&bd->bd_lock, *irq_flags1);
1738 (un->un_tty->ldisc->ops->write_wakeup)(un->un_tty);
1740 spin_lock_irqsave(&bd->bd_lock, *irq_flags1);
1741 spin_lock_irqsave(&ch->ch_lock, *irq_flags2);
1743 wake_up_interruptible(&un->un_tty->write_wait);
1744 wake_up_interruptible(&un->un_flags_wait);
1747 /************************************************************************
1748 * Determines when CARRIER changes state and takes appropriate
1750 ************************************************************************/
1751 static void dgap_carrier(struct channel_t *ch)
1755 int virt_carrier = 0;
1756 int phys_carrier = 0;
1758 if (!ch || ch->magic != DGAP_CHANNEL_MAGIC)
1763 if (!bd || bd->magic != DGAP_BOARD_MAGIC)
1766 /* Make sure altpin is always set correctly */
1767 if (ch->ch_digi.digi_flags & DIGI_ALTPIN) {
1771 ch->ch_dsr = DM_DSR;
1775 if (ch->ch_mistat & D_CD(ch))
1778 if (ch->ch_digi.digi_flags & DIGI_FORCEDCD)
1781 if (ch->ch_c_cflag & CLOCAL)
1785 * Test for a VIRTUAL carrier transition to HIGH.
1787 if (((ch->ch_flags & CH_FCAR) == 0) && (virt_carrier == 1)) {
1790 * When carrier rises, wake any threads waiting
1791 * for carrier in the open routine.
1794 if (waitqueue_active(&(ch->ch_flags_wait)))
1795 wake_up_interruptible(&ch->ch_flags_wait);
1799 * Test for a PHYSICAL carrier transition to HIGH.
1801 if (((ch->ch_flags & CH_CD) == 0) && (phys_carrier == 1)) {
1804 * When carrier rises, wake any threads waiting
1805 * for carrier in the open routine.
1808 if (waitqueue_active(&(ch->ch_flags_wait)))
1809 wake_up_interruptible(&ch->ch_flags_wait);
1813 * Test for a PHYSICAL transition to low, so long as we aren't
1814 * currently ignoring physical transitions (which is what "virtual
1815 * carrier" indicates).
1817 * The transition of the virtual carrier to low really doesn't
1818 * matter... it really only means "ignore carrier state", not
1819 * "make pretend that carrier is there".
1821 if ((virt_carrier == 0) &&
1822 ((ch->ch_flags & CH_CD) != 0) &&
1823 (phys_carrier == 0)) {
1826 * When carrier drops:
1828 * Drop carrier on all open units.
1830 * Flush queues, waking up any task waiting in the
1833 * Send a hangup to the control terminal.
1835 * Enable all select calls.
1837 if (waitqueue_active(&(ch->ch_flags_wait)))
1838 wake_up_interruptible(&ch->ch_flags_wait);
1840 if (ch->ch_tun.un_open_count > 0)
1841 tty_hangup(ch->ch_tun.un_tty);
1843 if (ch->ch_pun.un_open_count > 0)
1844 tty_hangup(ch->ch_pun.un_tty);
1848 * Make sure that our cached values reflect the current reality.
1850 if (virt_carrier == 1)
1851 ch->ch_flags |= CH_FCAR;
1853 ch->ch_flags &= ~CH_FCAR;
1855 if (phys_carrier == 1)
1856 ch->ch_flags |= CH_CD;
1858 ch->ch_flags &= ~CH_CD;
1861 /*=======================================================================
1863 * dgap_event - FEP to host event processing routine.
1865 * bd - Board of current event.
1867 *=======================================================================*/
1868 static int dgap_event(struct board_t *bd)
1870 struct channel_t *ch;
1873 struct bs_t __iomem *bs;
1876 struct ev_t __iomem *eaddr;
1884 if (!bd || bd->magic != DGAP_BOARD_MAGIC)
1887 spin_lock_irqsave(&bd->bd_lock, lock_flags);
1889 vaddr = bd->re_map_membase;
1892 spin_unlock_irqrestore(&bd->bd_lock, lock_flags);
1896 eaddr = (struct ev_t __iomem *) (vaddr + EVBUF);
1898 /* Get our head and tail */
1899 head = readw(&(eaddr->ev_head));
1900 tail = readw(&(eaddr->ev_tail));
1903 * Forget it if pointers out of range.
1906 if (head >= EVMAX - EVSTART || tail >= EVMAX - EVSTART ||
1907 (head | tail) & 03) {
1908 /* Let go of board lock */
1909 spin_unlock_irqrestore(&bd->bd_lock, lock_flags);
1914 * Loop to process all the events in the buffer.
1916 while (tail != head) {
1919 * Get interrupt information.
1922 event = bd->re_map_membase + tail + EVSTART;
1924 port = ioread8(event);
1925 reason = ioread8(event + 1);
1926 modem = ioread8(event + 2);
1927 b1 = ioread8(event + 3);
1930 * Make sure the interrupt is valid.
1932 if (port >= bd->nasync)
1935 if (!(reason & (IFMODEM | IFBREAK | IFTLW | IFTEM | IFDATA)))
1938 ch = bd->channels[port];
1940 if (!ch || ch->magic != DGAP_CHANNEL_MAGIC)
1944 * If we have made it here, the event was valid.
1945 * Lock down the channel.
1947 spin_lock_irqsave(&ch->ch_lock, lock_flags2);
1952 spin_unlock_irqrestore(&ch->ch_lock, lock_flags2);
1957 * Process received data.
1959 if (reason & IFDATA) {
1962 * ALL LOCKS *MUST* BE DROPPED BEFORE CALLING INPUT!
1963 * input could send some data to ld, which in turn
1964 * could do a callback to one of our other functions.
1966 spin_unlock_irqrestore(&ch->ch_lock, lock_flags2);
1967 spin_unlock_irqrestore(&bd->bd_lock, lock_flags);
1971 spin_lock_irqsave(&bd->bd_lock, lock_flags);
1972 spin_lock_irqsave(&ch->ch_lock, lock_flags2);
1974 if (ch->ch_flags & CH_RACTIVE)
1975 ch->ch_flags |= CH_RENABLE;
1977 writeb(1, &(bs->idata));
1979 if (ch->ch_flags & CH_RWAIT) {
1980 ch->ch_flags &= ~CH_RWAIT;
1982 wake_up_interruptible
1983 (&ch->ch_tun.un_flags_wait);
1988 * Process Modem change signals.
1990 if (reason & IFMODEM) {
1991 ch->ch_mistat = modem;
1998 if (reason & IFBREAK) {
2000 if (ch->ch_tun.un_tty) {
2001 /* A break has been indicated */
2003 tty_buffer_request_room
2004 (ch->ch_tun.un_tty->port, 1);
2005 tty_insert_flip_char(ch->ch_tun.un_tty->port,
2007 tty_flip_buffer_push(ch->ch_tun.un_tty->port);
2012 * Process Transmit low.
2014 if (reason & IFTLW) {
2015 dgap_write_wakeup(bd, ch, &ch->ch_tun, UN_LOW,
2016 &lock_flags, &lock_flags2);
2017 dgap_write_wakeup(bd, ch, &ch->ch_pun, UN_LOW,
2018 &lock_flags, &lock_flags2);
2019 if (ch->ch_flags & CH_WLOW) {
2020 ch->ch_flags &= ~CH_WLOW;
2021 wake_up_interruptible(&ch->ch_flags_wait);
2026 * Process Transmit empty.
2028 if (reason & IFTEM) {
2029 dgap_write_wakeup(bd, ch, &ch->ch_tun, UN_EMPTY,
2030 &lock_flags, &lock_flags2);
2031 dgap_write_wakeup(bd, ch, &ch->ch_pun, UN_EMPTY,
2032 &lock_flags, &lock_flags2);
2033 if (ch->ch_flags & CH_WEMPTY) {
2034 ch->ch_flags &= ~CH_WEMPTY;
2035 wake_up_interruptible(&ch->ch_flags_wait);
2039 spin_unlock_irqrestore(&ch->ch_lock, lock_flags2);
2042 tail = (tail + 4) & (EVMAX - EVSTART - 4);
2045 writew(tail, &(eaddr->ev_tail));
2046 spin_unlock_irqrestore(&bd->bd_lock, lock_flags);
2052 * Our board poller function.
2054 static void dgap_poll_tasklet(unsigned long data)
2056 struct board_t *bd = (struct board_t *) data;
2058 char __iomem *vaddr;
2061 if (!bd || (bd->magic != DGAP_BOARD_MAGIC))
2064 if (bd->inhibit_poller)
2067 spin_lock_irqsave(&bd->bd_lock, lock_flags);
2069 vaddr = bd->re_map_membase;
2072 * If board is ready, parse deeper to see if there is anything to do.
2074 if (bd->state == BOARD_READY) {
2076 struct ev_t __iomem *eaddr;
2078 if (!bd->re_map_membase) {
2079 spin_unlock_irqrestore(&bd->bd_lock, lock_flags);
2082 if (!bd->re_map_port) {
2083 spin_unlock_irqrestore(&bd->bd_lock, lock_flags);
2090 eaddr = (struct ev_t __iomem *) (vaddr + EVBUF);
2092 /* Get our head and tail */
2093 head = readw(&(eaddr->ev_head));
2094 tail = readw(&(eaddr->ev_tail));
2097 * If there is an event pending. Go service it.
2100 spin_unlock_irqrestore(&bd->bd_lock, lock_flags);
2102 spin_lock_irqsave(&bd->bd_lock, lock_flags);
2107 * If board is doing interrupts, ACK the interrupt.
2109 if (bd && bd->intr_running)
2110 readb(bd->re_map_port + 2);
2112 spin_unlock_irqrestore(&bd->bd_lock, lock_flags);
2116 spin_unlock_irqrestore(&bd->bd_lock, lock_flags);
2120 * dgap_found_board()
2122 * A board has been found, init it.
2124 static struct board_t *dgap_found_board(struct pci_dev *pdev, int id,
2127 struct board_t *brd;
2128 unsigned int pci_irq;
2132 /* get the board structure and prep it */
2133 brd = kzalloc(sizeof(struct board_t), GFP_KERNEL);
2135 return ERR_PTR(-ENOMEM);
2137 /* store the info for the board we've found */
2138 brd->magic = DGAP_BOARD_MAGIC;
2139 brd->boardnum = boardnum;
2140 brd->vendor = dgap_pci_tbl[id].vendor;
2141 brd->device = dgap_pci_tbl[id].device;
2143 brd->pci_bus = pdev->bus->number;
2144 brd->pci_slot = PCI_SLOT(pdev->devfn);
2145 brd->name = dgap_ids[id].name;
2146 brd->maxports = dgap_ids[id].maxports;
2147 brd->type = dgap_ids[id].config_type;
2148 brd->dpatype = dgap_ids[id].dpatype;
2149 brd->dpastatus = BD_NOFEP;
2150 init_waitqueue_head(&brd->state_wait);
2152 spin_lock_init(&brd->bd_lock);
2154 brd->inhibit_poller = FALSE;
2155 brd->wait_for_bios = 0;
2156 brd->wait_for_fep = 0;
2158 for (i = 0; i < MAXPORTS; i++)
2159 brd->channels[i] = NULL;
2161 /* store which card & revision we have */
2162 pci_read_config_word(pdev, PCI_SUBSYSTEM_VENDOR_ID, &brd->subvendor);
2163 pci_read_config_word(pdev, PCI_SUBSYSTEM_ID, &brd->subdevice);
2164 pci_read_config_byte(pdev, PCI_REVISION_ID, &brd->rev);
2166 pci_irq = pdev->irq;
2169 /* get the PCI Base Address Registers */
2171 /* Xr Jupiter and EPC use BAR 2 */
2172 if (brd->device == PCI_DEV_XRJ_DID || brd->device == PCI_DEV_EPCJ_DID) {
2173 brd->membase = pci_resource_start(pdev, 2);
2174 brd->membase_end = pci_resource_end(pdev, 2);
2176 /* Everyone else uses BAR 0 */
2178 brd->membase = pci_resource_start(pdev, 0);
2179 brd->membase_end = pci_resource_end(pdev, 0);
2182 if (!brd->membase) {
2187 if (brd->membase & 1)
2190 brd->membase &= ~15;
2193 * On the PCI boards, there is no IO space allocated
2194 * The I/O registers will be in the first 3 bytes of the
2195 * upper 2MB of the 4MB memory space. The board memory
2196 * will be mapped into the low 2MB of the 4MB memory space
2198 brd->port = brd->membase + PCI_IO_OFFSET;
2199 brd->port_end = brd->port + PCI_IO_SIZE;
2202 * Special initialization for non-PLX boards
2204 if (brd->device != PCI_DEV_XRJ_DID && brd->device != PCI_DEV_EPCJ_DID) {
2207 pci_write_config_byte(pdev, 0x40, 0);
2208 pci_write_config_byte(pdev, 0x46, 0);
2210 /* Limit burst length to 2 doubleword transactions */
2211 pci_write_config_byte(pdev, 0x42, 1);
2214 * Enable IO and mem if not already done.
2215 * This was needed for support on Itanium.
2217 pci_read_config_word(pdev, PCI_COMMAND, &cmd);
2218 cmd |= (PCI_COMMAND_IO | PCI_COMMAND_MEMORY);
2219 pci_write_config_word(pdev, PCI_COMMAND, cmd);
2222 /* init our poll helper tasklet */
2223 tasklet_init(&brd->helper_tasklet, dgap_poll_tasklet,
2224 (unsigned long) brd);
2226 ret = dgap_remap(brd);
2230 pr_info("dgap: board %d: %s (rev %d), irq %ld\n",
2231 boardnum, brd->name, brd->rev, brd->irq);
2238 return ERR_PTR(ret);
2244 * Driver interrupt handler.
2246 static irqreturn_t dgap_intr(int irq, void *voidbrd)
2248 struct board_t *brd = voidbrd;
2254 * Check to make sure its for us.
2256 if (brd->magic != DGAP_BOARD_MAGIC)
2262 * Schedule tasklet to run at a better time.
2264 tasklet_schedule(&brd->helper_tasklet);
2268 /*****************************************************************************
2288 * As each timer expires, it determines (a) whether the "transmit"
2289 * waiter needs to be woken up, and (b) whether the poller needs to
2292 ******************************************************************************/
2294 static void dgap_poll_handler(ulong dummy)
2297 struct board_t *brd;
2298 unsigned long lock_flags;
2301 dgap_poll_counter++;
2304 * Do not start the board state machine until
2305 * driver tells us its up and running, and has
2306 * everything it needs.
2308 if (dgap_driver_state != DRIVER_READY)
2309 goto schedule_poller;
2312 * If we have just 1 board, or the system is not SMP,
2313 * then use the typical old style poller.
2314 * Otherwise, use our new tasklet based poller, which should
2315 * speed things up for multiple boards.
2317 if ((dgap_numboards == 1) || (num_online_cpus() <= 1)) {
2318 for (i = 0; i < dgap_numboards; i++) {
2320 brd = dgap_board[i];
2322 if (brd->state == BOARD_FAILED)
2324 if (!brd->intr_running)
2325 /* Call the real board poller directly */
2326 dgap_poll_tasklet((unsigned long) brd);
2330 * Go thru each board, kicking off a
2331 * tasklet for each if needed
2333 for (i = 0; i < dgap_numboards; i++) {
2334 brd = dgap_board[i];
2337 * Attempt to grab the board lock.
2339 * If we can't get it, no big deal, the next poll
2340 * will get it. Basically, I just really don't want
2341 * to spin in here, because I want to kick off my
2342 * tasklets as fast as I can, and then get out the
2345 if (!spin_trylock(&brd->bd_lock))
2349 * If board is in a failed state, don't bother
2350 * scheduling a tasklet
2352 if (brd->state == BOARD_FAILED) {
2353 spin_unlock(&brd->bd_lock);
2357 /* Schedule a poll helper task */
2358 if (!brd->intr_running)
2359 tasklet_schedule(&brd->helper_tasklet);
2362 * Can't do DGAP_UNLOCK here, as we don't have
2363 * lock_flags because we did a trylock above.
2365 spin_unlock(&brd->bd_lock);
2372 * Schedule ourself back at the nominal wakeup interval.
2374 spin_lock_irqsave(&dgap_poll_lock, lock_flags);
2375 dgap_poll_time += dgap_jiffies_from_ms(dgap_poll_tick);
2377 new_time = dgap_poll_time - jiffies;
2379 if ((ulong) new_time >= 2 * dgap_poll_tick) {
2381 jiffies + dgap_jiffies_from_ms(dgap_poll_tick);
2384 dgap_poll_timer.function = dgap_poll_handler;
2385 dgap_poll_timer.data = 0;
2386 dgap_poll_timer.expires = dgap_poll_time;
2387 spin_unlock_irqrestore(&dgap_poll_lock, lock_flags);
2389 if (!dgap_poll_stop)
2390 add_timer(&dgap_poll_timer);
2393 /*=======================================================================
2395 * dgap_cmdb - Sends a 2 byte command to the FEP.
2397 * ch - Pointer to channel structure.
2398 * cmd - Command to be sent.
2399 * byte1 - Integer containing first byte to be sent.
2400 * byte2 - Integer containing second byte to be sent.
2401 * ncmds - Wait until ncmds or fewer cmds are left
2402 * in the cmd buffer before returning.
2404 *=======================================================================*/
2405 static void dgap_cmdb(struct channel_t *ch, u8 cmd, u8 byte1,
2406 u8 byte2, uint ncmds)
2408 char __iomem *vaddr;
2409 struct __iomem cm_t *cm_addr;
2415 if (!ch || ch->magic != DGAP_CHANNEL_MAGIC)
2419 * Check if board is still alive.
2421 if (ch->ch_bd->state == BOARD_FAILED)
2425 * Make sure the pointers are in range before
2426 * writing to the FEP memory.
2428 vaddr = ch->ch_bd->re_map_membase;
2433 cm_addr = (struct cm_t __iomem *) (vaddr + CMDBUF);
2434 head = readw(&(cm_addr->cm_head));
2437 * Forget it if pointers out of range.
2439 if (head >= (CMDMAX - CMDSTART) || (head & 03)) {
2440 ch->ch_bd->state = BOARD_FAILED;
2445 * Put the data in the circular command buffer.
2447 writeb(cmd, (vaddr + head + CMDSTART + 0));
2448 writeb((u8) ch->ch_portnum, (vaddr + head + CMDSTART + 1));
2449 writeb(byte1, (vaddr + head + CMDSTART + 2));
2450 writeb(byte2, (vaddr + head + CMDSTART + 3));
2452 head = (head + 4) & (CMDMAX - CMDSTART - 4);
2454 writew(head, &(cm_addr->cm_head));
2457 * Wait if necessary before updating the head
2458 * pointer to limit the number of outstanding
2459 * commands to the FEP. If the time spent waiting
2460 * is outlandish, declare the FEP dead.
2462 for (count = dgap_count ;;) {
2464 head = readw(&(cm_addr->cm_head));
2465 tail = readw(&(cm_addr->cm_tail));
2467 n = (head - tail) & (CMDMAX - CMDSTART - 4);
2469 if (n <= ncmds * sizeof(struct cm_t))
2473 ch->ch_bd->state = BOARD_FAILED;
2480 /*=======================================================================
2482 * dgap_cmdw - Sends a 1 word command to the FEP.
2484 * ch - Pointer to channel structure.
2485 * cmd - Command to be sent.
2486 * word - Integer containing word to be sent.
2487 * ncmds - Wait until ncmds or fewer cmds are left
2488 * in the cmd buffer before returning.
2490 *=======================================================================*/
2491 static void dgap_cmdw(struct channel_t *ch, u8 cmd, u16 word, uint ncmds)
2493 char __iomem *vaddr;
2494 struct __iomem cm_t *cm_addr;
2500 if (!ch || ch->magic != DGAP_CHANNEL_MAGIC)
2504 * Check if board is still alive.
2506 if (ch->ch_bd->state == BOARD_FAILED)
2510 * Make sure the pointers are in range before
2511 * writing to the FEP memory.
2513 vaddr = ch->ch_bd->re_map_membase;
2517 cm_addr = (struct cm_t __iomem *) (vaddr + CMDBUF);
2518 head = readw(&(cm_addr->cm_head));
2521 * Forget it if pointers out of range.
2523 if (head >= (CMDMAX - CMDSTART) || (head & 03)) {
2524 ch->ch_bd->state = BOARD_FAILED;
2529 * Put the data in the circular command buffer.
2531 writeb(cmd, (vaddr + head + CMDSTART + 0));
2532 writeb((u8) ch->ch_portnum, (vaddr + head + CMDSTART + 1));
2533 writew((u16) word, (vaddr + head + CMDSTART + 2));
2535 head = (head + 4) & (CMDMAX - CMDSTART - 4);
2537 writew(head, &(cm_addr->cm_head));
2540 * Wait if necessary before updating the head
2541 * pointer to limit the number of outstanding
2542 * commands to the FEP. If the time spent waiting
2543 * is outlandish, declare the FEP dead.
2545 for (count = dgap_count ;;) {
2547 head = readw(&(cm_addr->cm_head));
2548 tail = readw(&(cm_addr->cm_tail));
2550 n = (head - tail) & (CMDMAX - CMDSTART - 4);
2552 if (n <= ncmds * sizeof(struct cm_t))
2556 ch->ch_bd->state = BOARD_FAILED;
2563 /*=======================================================================
2565 * dgap_cmdw_ext - Sends a extended word command to the FEP.
2567 * ch - Pointer to channel structure.
2568 * cmd - Command to be sent.
2569 * word - Integer containing word to be sent.
2570 * ncmds - Wait until ncmds or fewer cmds are left
2571 * in the cmd buffer before returning.
2573 *=======================================================================*/
2574 static void dgap_cmdw_ext(struct channel_t *ch, u16 cmd, u16 word, uint ncmds)
2576 char __iomem *vaddr;
2577 struct __iomem cm_t *cm_addr;
2583 if (!ch || ch->magic != DGAP_CHANNEL_MAGIC)
2587 * Check if board is still alive.
2589 if (ch->ch_bd->state == BOARD_FAILED)
2593 * Make sure the pointers are in range before
2594 * writing to the FEP memory.
2596 vaddr = ch->ch_bd->re_map_membase;
2600 cm_addr = (struct cm_t __iomem *) (vaddr + CMDBUF);
2601 head = readw(&(cm_addr->cm_head));
2604 * Forget it if pointers out of range.
2606 if (head >= (CMDMAX - CMDSTART) || (head & 03)) {
2607 ch->ch_bd->state = BOARD_FAILED;
2612 * Put the data in the circular command buffer.
2615 /* Write an FF to tell the FEP that we want an extended command */
2616 writeb((u8) 0xff, (vaddr + head + CMDSTART + 0));
2618 writeb((u8) ch->ch_portnum, (vaddr + head + CMDSTART + 1));
2619 writew((u16) cmd, (vaddr + head + CMDSTART + 2));
2622 * If the second part of the command won't fit,
2623 * put it at the beginning of the circular buffer.
2625 if (((head + 4) >= ((CMDMAX - CMDSTART)) || (head & 03)))
2626 writew((u16) word, (vaddr + CMDSTART));
2628 writew((u16) word, (vaddr + head + CMDSTART + 4));
2630 head = (head + 8) & (CMDMAX - CMDSTART - 4);
2632 writew(head, &(cm_addr->cm_head));
2635 * Wait if necessary before updating the head
2636 * pointer to limit the number of outstanding
2637 * commands to the FEP. If the time spent waiting
2638 * is outlandish, declare the FEP dead.
2640 for (count = dgap_count ;;) {
2642 head = readw(&(cm_addr->cm_head));
2643 tail = readw(&(cm_addr->cm_tail));
2645 n = (head - tail) & (CMDMAX - CMDSTART - 4);
2647 if (n <= ncmds * sizeof(struct cm_t))
2651 ch->ch_bd->state = BOARD_FAILED;
2658 /*=======================================================================
2660 * dgap_wmove - Write data to FEP buffer.
2662 * ch - Pointer to channel structure.
2663 * buf - Poiter to characters to be moved.
2664 * cnt - Number of characters to move.
2666 *=======================================================================*/
2667 static void dgap_wmove(struct channel_t *ch, char *buf, uint cnt)
2670 char __iomem *taddr;
2671 struct bs_t __iomem *bs;
2674 if (!ch || ch->magic != DGAP_CHANNEL_MAGIC)
2681 head = readw(&(bs->tx_head));
2684 * If pointers are out of range, just return.
2686 if ((cnt > ch->ch_tsize) ||
2687 (unsigned)(head - ch->ch_tstart) >= ch->ch_tsize)
2691 * If the write wraps over the top of the circular buffer,
2692 * move the portion up to the wrap point, and reset the
2693 * pointers to the bottom.
2695 n = ch->ch_tstart + ch->ch_tsize - head;
2699 taddr = ch->ch_taddr + head;
2700 memcpy_toio(taddr, buf, n);
2701 head = ch->ch_tstart;
2706 * Move rest of data.
2708 taddr = ch->ch_taddr + head;
2710 memcpy_toio(taddr, buf, n);
2713 writew(head, &(bs->tx_head));
2717 * Calls the firmware to reset this channel.
2719 static void dgap_firmware_reset_port(struct channel_t *ch)
2721 dgap_cmdb(ch, CHRESET, 0, 0, 0);
2724 * Now that the channel is reset, we need to make sure
2725 * all the current settings get reapplied to the port
2728 * So we will set the driver's cache of firmware
2729 * settings all to 0, and then call param.
2731 ch->ch_fepiflag = 0;
2732 ch->ch_fepcflag = 0;
2733 ch->ch_fepoflag = 0;
2734 ch->ch_fepstartc = 0;
2735 ch->ch_fepstopc = 0;
2736 ch->ch_fepastartc = 0;
2737 ch->ch_fepastopc = 0;
2742 /*=======================================================================
2744 * dgap_param - Set Digi parameters.
2746 * struct tty_struct * - TTY for port.
2748 *=======================================================================*/
2749 static int dgap_param(struct channel_t *ch, struct board_t *bd, u32 un_type)
2758 * If baud rate is zero, flush queues, and set mval to drop DTR.
2760 if ((ch->ch_c_cflag & (CBAUD)) == 0) {
2763 head = readw(&(ch->ch_bs->rx_head));
2764 writew(head, &(ch->ch_bs->rx_tail));
2767 head = readw(&(ch->ch_bs->tx_head));
2768 writew(head, &(ch->ch_bs->tx_tail));
2770 ch->ch_flags |= (CH_BAUD0);
2772 /* Drop RTS and DTR */
2773 ch->ch_mval &= ~(D_RTS(ch)|D_DTR(ch));
2774 mval = D_DTR(ch) | D_RTS(ch);
2775 ch->ch_baud_info = 0;
2777 } else if (ch->ch_custom_speed && (bd->bd_flags & BD_FEP5PLUS)) {
2779 * Tell the fep to do the command
2782 dgap_cmdw_ext(ch, 0xff01, ch->ch_custom_speed, 0);
2785 * Now go get from fep mem, what the fep
2786 * believes the custom baud rate is.
2788 ch->ch_custom_speed = dgap_get_custom_baud(ch);
2789 ch->ch_baud_info = ch->ch_custom_speed;
2791 /* Handle transition from B0 */
2792 if (ch->ch_flags & CH_BAUD0) {
2793 ch->ch_flags &= ~(CH_BAUD0);
2794 ch->ch_mval |= (D_RTS(ch)|D_DTR(ch));
2796 mval = D_DTR(ch) | D_RTS(ch);
2800 * Set baud rate, character size, and parity.
2808 ulong bauds[4][16] = {
2812 600, 1200, 1800, 2400,
2813 4800, 9600, 19200, 38400 },
2814 { /* slowbaud & CBAUDEX */
2815 0, 57600, 115200, 230400,
2816 460800, 150, 200, 921600,
2817 600, 1200, 1800, 2400,
2818 4800, 9600, 19200, 38400 },
2820 0, 57600, 76800, 115200,
2821 14400, 57600, 230400, 76800,
2822 115200, 230400, 28800, 460800,
2823 921600, 9600, 19200, 38400 },
2824 { /* fastbaud & CBAUDEX */
2825 0, 57600, 115200, 230400,
2826 460800, 150, 200, 921600,
2827 600, 1200, 1800, 2400,
2828 4800, 9600, 19200, 38400 }
2832 * Only use the TXPrint baud rate if the
2833 * terminal unit is NOT open
2835 if (!(ch->ch_tun.un_flags & UN_ISOPEN) &&
2836 un_type == DGAP_PRINT)
2837 baud = C_BAUD(ch->ch_pun.un_tty) & 0xff;
2839 baud = C_BAUD(ch->ch_tun.un_tty) & 0xff;
2841 if (ch->ch_c_cflag & CBAUDEX)
2844 if (ch->ch_digi.digi_flags & DIGI_FAST)
2849 if ((iindex >= 0) && (iindex < 4) &&
2850 (jindex >= 0) && (jindex < 16))
2851 baud = bauds[iindex][jindex];
2858 ch->ch_baud_info = baud;
2861 * CBAUD has bit position 0x1000 set these days to
2862 * indicate Linux baud rate remap.
2863 * We use a different bit assignment for high speed.
2864 * Clear this bit out while grabbing the parts of
2867 cflag = ch->ch_c_cflag & ((CBAUD ^ CBAUDEX) | PARODD | PARENB |
2871 * HUPCL bit is used by FEP to indicate fast baud
2872 * table is to be used.
2874 if ((ch->ch_digi.digi_flags & DIGI_FAST) ||
2875 (ch->ch_c_cflag & CBAUDEX))
2878 if ((ch->ch_c_cflag & CBAUDEX) &&
2879 !(ch->ch_digi.digi_flags & DIGI_FAST)) {
2881 * The below code is trying to guarantee that only
2882 * baud rates 115200, 230400, 460800, 921600 are
2883 * remapped. We use exclusive or because the various
2884 * baud rates share common bit positions and therefore
2885 * can't be tested for easily.
2887 tcflag_t tcflag = (ch->ch_c_cflag & CBAUD) | CBAUDEX;
2891 * Map high speed requests to index
2892 * into FEP's baud table
2922 cflag = (cflag & ~(CBAUD | CBAUDEX)) | baudpart;
2927 if (cflag != ch->ch_fepcflag) {
2928 ch->ch_fepcflag = (u16) (cflag & 0xffff);
2931 * Okay to have channel and board
2932 * locks held calling this
2934 dgap_cmdw(ch, SCFLAG, (u16) cflag, 0);
2937 /* Handle transition from B0 */
2938 if (ch->ch_flags & CH_BAUD0) {
2939 ch->ch_flags &= ~(CH_BAUD0);
2940 ch->ch_mval |= (D_RTS(ch)|D_DTR(ch));
2942 mval = D_DTR(ch) | D_RTS(ch);
2948 iflag = ch->ch_c_iflag & (IGNBRK | BRKINT | IGNPAR | PARMRK |
2949 INPCK | ISTRIP | IXON | IXANY | IXOFF);
2951 if ((ch->ch_startc == _POSIX_VDISABLE) ||
2952 (ch->ch_stopc == _POSIX_VDISABLE)) {
2953 iflag &= ~(IXON | IXOFF);
2954 ch->ch_c_iflag &= ~(IXON | IXOFF);
2958 * Only the IBM Xr card can switch between
2959 * 232 and 422 modes on the fly
2961 if (bd->device == PCI_DEV_XR_IBM_DID) {
2962 if (ch->ch_digi.digi_flags & DIGI_422)
2963 dgap_cmdb(ch, SCOMMODE, MODE_422, 0, 0);
2965 dgap_cmdb(ch, SCOMMODE, MODE_232, 0, 0);
2968 if (ch->ch_digi.digi_flags & DIGI_ALTPIN)
2971 if (iflag != ch->ch_fepiflag) {
2972 ch->ch_fepiflag = iflag;
2974 /* Okay to have channel and board locks held calling this */
2975 dgap_cmdw(ch, SIFLAG, (u16) ch->ch_fepiflag, 0);
2979 * Select hardware handshaking.
2983 if (ch->ch_c_cflag & CRTSCTS)
2984 hflow |= (D_RTS(ch) | D_CTS(ch));
2985 if (ch->ch_digi.digi_flags & RTSPACE)
2987 if (ch->ch_digi.digi_flags & DTRPACE)
2989 if (ch->ch_digi.digi_flags & CTSPACE)
2991 if (ch->ch_digi.digi_flags & DSRPACE)
2993 if (ch->ch_digi.digi_flags & DCDPACE)
2996 if (hflow != ch->ch_hflow) {
2997 ch->ch_hflow = hflow;
2999 /* Okay to have channel and board locks held calling this */
3000 dgap_cmdb(ch, SHFLOW, (u8) hflow, 0xff, 0);
3004 * Set RTS and/or DTR Toggle if needed,
3005 * but only if product is FEP5+ based.
3007 if (bd->bd_flags & BD_FEP5PLUS) {
3010 if (ch->ch_digi.digi_flags & DIGI_RTS_TOGGLE)
3011 hflow2 |= (D_RTS(ch));
3012 if (ch->ch_digi.digi_flags & DIGI_DTR_TOGGLE)
3013 hflow2 |= (D_DTR(ch));
3015 dgap_cmdw_ext(ch, 0xff03, hflow2, 0);
3019 * Set modem control lines.
3022 mval ^= ch->ch_mforce & (mval ^ ch->ch_mval);
3024 if (ch->ch_mostat ^ mval) {
3025 ch->ch_mostat = mval;
3027 /* Okay to have channel and board locks held calling this */
3028 dgap_cmdb(ch, SMODEM, (u8) mval, D_RTS(ch)|D_DTR(ch), 0);
3032 * Read modem signals, and then call carrier function.
3034 ch->ch_mistat = readb(&(ch->ch_bs->m_stat));
3038 * Set the start and stop characters.
3040 if (ch->ch_startc != ch->ch_fepstartc ||
3041 ch->ch_stopc != ch->ch_fepstopc) {
3042 ch->ch_fepstartc = ch->ch_startc;
3043 ch->ch_fepstopc = ch->ch_stopc;
3045 /* Okay to have channel and board locks held calling this */
3046 dgap_cmdb(ch, SFLOWC, ch->ch_fepstartc, ch->ch_fepstopc, 0);
3050 * Set the Auxiliary start and stop characters.
3052 if (ch->ch_astartc != ch->ch_fepastartc ||
3053 ch->ch_astopc != ch->ch_fepastopc) {
3054 ch->ch_fepastartc = ch->ch_astartc;
3055 ch->ch_fepastopc = ch->ch_astopc;
3057 /* Okay to have channel and board locks held calling this */
3058 dgap_cmdb(ch, SAFLOWC, ch->ch_fepastartc, ch->ch_fepastopc, 0);
3065 * dgap_block_til_ready()
3067 * Wait for DCD, if needed.
3069 static int dgap_block_til_ready(struct tty_struct *tty, struct file *file,
3070 struct channel_t *ch)
3076 int sleep_on_un_flags;
3078 if (!tty || tty->magic != TTY_MAGIC || !file || !ch ||
3079 ch->magic != DGAP_CHANNEL_MAGIC)
3082 un = tty->driver_data;
3083 if (!un || un->magic != DGAP_UNIT_MAGIC)
3086 spin_lock_irqsave(&ch->ch_lock, lock_flags);
3093 sleep_on_un_flags = 0;
3096 * If board has failed somehow during our sleep,
3099 if (ch->ch_bd->state == BOARD_FAILED) {
3104 /* If tty was hung up, break out of loop and set error. */
3105 if (tty_hung_up_p(file)) {
3111 * If either unit is in the middle of the fragile part of close,
3112 * we just cannot touch the channel safely.
3113 * Go back to sleep, knowing that when the channel can be
3114 * touched safely, the close routine will signal the
3115 * ch_wait_flags to wake us back up.
3117 if (!((ch->ch_tun.un_flags | ch->ch_pun.un_flags) &
3121 * Our conditions to leave cleanly and happily:
3122 * 1) NONBLOCKING on the tty is set.
3124 * 3) DCD (fake or real) is active.
3127 if (file->f_flags & O_NONBLOCK)
3130 if (tty->flags & (1 << TTY_IO_ERROR))
3133 if (ch->ch_flags & CH_CD)
3136 if (ch->ch_flags & CH_FCAR)
3139 sleep_on_un_flags = 1;
3143 * If there is a signal pending, the user probably
3144 * interrupted (ctrl-c) us.
3145 * Leave loop with error set.
3147 if (signal_pending(current)) {
3148 retval = -ERESTARTSYS;
3153 * Store the flags before we let go of channel lock
3155 if (sleep_on_un_flags)
3156 old_flags = ch->ch_tun.un_flags | ch->ch_pun.un_flags;
3158 old_flags = ch->ch_flags;
3161 * Let go of channel lock before calling schedule.
3162 * Our poller will get any FEP events and wake us up when DCD
3163 * eventually goes active.
3166 spin_unlock_irqrestore(&ch->ch_lock, lock_flags);
3169 * Wait for something in the flags to change
3170 * from the current value.
3172 if (sleep_on_un_flags) {
3173 retval = wait_event_interruptible(un->un_flags_wait,
3174 (old_flags != (ch->ch_tun.un_flags |
3175 ch->ch_pun.un_flags)));
3177 retval = wait_event_interruptible(ch->ch_flags_wait,
3178 (old_flags != ch->ch_flags));
3182 * We got woken up for some reason.
3183 * Before looping around, grab our channel lock.
3185 spin_lock_irqsave(&ch->ch_lock, lock_flags);
3190 spin_unlock_irqrestore(&ch->ch_lock, lock_flags);
3196 * dgap_tty_flush_buffer()
3198 * Flush Tx buffer (make in == out)
3200 static void dgap_tty_flush_buffer(struct tty_struct *tty)
3203 struct channel_t *ch;
3209 if (!tty || tty->magic != TTY_MAGIC)
3212 un = tty->driver_data;
3213 if (!un || un->magic != DGAP_UNIT_MAGIC)
3217 if (!ch || ch->magic != DGAP_CHANNEL_MAGIC)
3221 if (!bd || bd->magic != DGAP_BOARD_MAGIC)
3224 spin_lock_irqsave(&bd->bd_lock, lock_flags);
3225 spin_lock_irqsave(&ch->ch_lock, lock_flags2);
3227 ch->ch_flags &= ~CH_STOP;
3228 head = readw(&(ch->ch_bs->tx_head));
3229 dgap_cmdw(ch, FLUSHTX, (u16) head, 0);
3230 dgap_cmdw(ch, RESUMETX, 0, 0);
3231 if (ch->ch_tun.un_flags & (UN_LOW|UN_EMPTY)) {
3232 ch->ch_tun.un_flags &= ~(UN_LOW|UN_EMPTY);
3233 wake_up_interruptible(&ch->ch_tun.un_flags_wait);
3235 if (ch->ch_pun.un_flags & (UN_LOW|UN_EMPTY)) {
3236 ch->ch_pun.un_flags &= ~(UN_LOW|UN_EMPTY);
3237 wake_up_interruptible(&ch->ch_pun.un_flags_wait);
3240 spin_unlock_irqrestore(&ch->ch_lock, lock_flags2);
3241 spin_unlock_irqrestore(&bd->bd_lock, lock_flags);
3242 if (waitqueue_active(&tty->write_wait))
3243 wake_up_interruptible(&tty->write_wait);
3250 * Hangup the port. Like a close, but don't wait for output to drain.
3252 static void dgap_tty_hangup(struct tty_struct *tty)
3255 struct channel_t *ch;
3258 if (!tty || tty->magic != TTY_MAGIC)
3261 un = tty->driver_data;
3262 if (!un || un->magic != DGAP_UNIT_MAGIC)
3266 if (!ch || ch->magic != DGAP_CHANNEL_MAGIC)
3270 if (!bd || bd->magic != DGAP_BOARD_MAGIC)
3273 /* flush the transmit queues */
3274 dgap_tty_flush_buffer(tty);
3278 * dgap_tty_chars_in_buffer()
3280 * Return number of characters that have not been transmitted yet.
3282 * This routine is used by the line discipline to determine if there
3283 * is data waiting to be transmitted/drained/flushed or not.
3285 static int dgap_tty_chars_in_buffer(struct tty_struct *tty)
3288 struct channel_t *ch;
3290 struct bs_t __iomem *bs;
3293 u16 thead, ttail, tmask, chead, ctail;
3294 ulong lock_flags = 0;
3295 ulong lock_flags2 = 0;
3300 un = tty->driver_data;
3301 if (!un || un->magic != DGAP_UNIT_MAGIC)
3305 if (!ch || ch->magic != DGAP_CHANNEL_MAGIC)
3309 if (!bd || bd->magic != DGAP_BOARD_MAGIC)
3316 spin_lock_irqsave(&bd->bd_lock, lock_flags);
3317 spin_lock_irqsave(&ch->ch_lock, lock_flags2);
3319 tmask = (ch->ch_tsize - 1);
3321 /* Get Transmit queue pointers */
3322 thead = readw(&(bs->tx_head)) & tmask;
3323 ttail = readw(&(bs->tx_tail)) & tmask;
3325 /* Get tbusy flag */
3326 tbusy = readb(&(bs->tbusy));
3328 /* Get Command queue pointers */
3329 chead = readw(&(ch->ch_cm->cm_head));
3330 ctail = readw(&(ch->ch_cm->cm_tail));
3332 spin_unlock_irqrestore(&ch->ch_lock, lock_flags2);
3333 spin_unlock_irqrestore(&bd->bd_lock, lock_flags);
3336 * The only way we know for sure if there is no pending
3337 * data left to be transferred, is if:
3338 * 1) Transmit head and tail are equal (empty).
3339 * 2) Command queue head and tail are equal (empty).
3340 * 3) The "TBUSY" flag is 0. (Transmitter not busy).
3343 if ((ttail == thead) && (tbusy == 0) && (chead == ctail)) {
3347 chars = thead - ttail;
3349 chars = thead - ttail + ch->ch_tsize;
3351 * Fudge factor here.
3352 * If chars is zero, we know that the command queue had
3353 * something in it or tbusy was set. Because we cannot
3354 * be sure if there is still some data to be transmitted,
3355 * lets lie, and tell ld we have 1 byte left.
3359 * If TBUSY is still set, and our tx buffers are empty,
3360 * force the firmware to send me another wakeup after
3361 * TBUSY has been cleared.
3364 spin_lock_irqsave(&ch->ch_lock, lock_flags);
3365 un->un_flags |= UN_EMPTY;
3366 writeb(1, &(bs->iempty));
3367 spin_unlock_irqrestore(&ch->ch_lock,
3377 static int dgap_wait_for_drain(struct tty_struct *tty)
3379 struct channel_t *ch;
3381 struct bs_t __iomem *bs;
3384 ulong lock_flags = 0;
3386 if (!tty || tty->magic != TTY_MAGIC)
3389 un = tty->driver_data;
3390 if (!un || un->magic != DGAP_UNIT_MAGIC)
3394 if (!ch || ch->magic != DGAP_CHANNEL_MAGIC)
3401 /* Loop until data is drained */
3402 while (count != 0) {
3404 count = dgap_tty_chars_in_buffer(tty);
3409 /* Set flag waiting for drain */
3410 spin_lock_irqsave(&ch->ch_lock, lock_flags);
3411 un->un_flags |= UN_EMPTY;
3412 writeb(1, &(bs->iempty));
3413 spin_unlock_irqrestore(&ch->ch_lock, lock_flags);
3415 /* Go to sleep till we get woken up */
3416 ret = wait_event_interruptible(un->un_flags_wait,
3417 ((un->un_flags & UN_EMPTY) == 0));
3418 /* If ret is non-zero, user ctrl-c'ed us */
3423 spin_lock_irqsave(&ch->ch_lock, lock_flags);
3424 un->un_flags &= ~(UN_EMPTY);
3425 spin_unlock_irqrestore(&ch->ch_lock, lock_flags);
3433 * Reduces bytes_available to the max number of characters
3434 * that can be sent currently given the maxcps value, and
3435 * returns the new bytes_available. This only affects printer
3438 static int dgap_maxcps_room(struct channel_t *ch, struct un_t *un,
3439 int bytes_available)
3442 * If its not the Transparent print device, return
3443 * the full data amount.
3445 if (un->un_type != DGAP_PRINT)
3446 return bytes_available;
3448 if (ch->ch_digi.digi_maxcps > 0 && ch->ch_digi.digi_bufsize > 0) {
3450 unsigned long current_time = jiffies;
3451 unsigned long buffer_time = current_time +
3452 (HZ * ch->ch_digi.digi_bufsize) /
3453 ch->ch_digi.digi_maxcps;
3455 if (ch->ch_cpstime < current_time) {
3456 /* buffer is empty */
3457 ch->ch_cpstime = current_time; /* reset ch_cpstime */
3458 cps_limit = ch->ch_digi.digi_bufsize;
3459 } else if (ch->ch_cpstime < buffer_time) {
3460 /* still room in the buffer */
3461 cps_limit = ((buffer_time - ch->ch_cpstime) *
3462 ch->ch_digi.digi_maxcps) / HZ;
3464 /* no room in the buffer */
3468 bytes_available = min(cps_limit, bytes_available);
3471 return bytes_available;
3474 static inline void dgap_set_firmware_event(struct un_t *un, unsigned int event)
3476 struct channel_t *ch;
3477 struct bs_t __iomem *bs;
3479 if (!un || un->magic != DGAP_UNIT_MAGIC)
3482 if (!ch || ch->magic != DGAP_CHANNEL_MAGIC)
3488 if ((event & UN_LOW) != 0) {
3489 if ((un->un_flags & UN_LOW) == 0) {
3490 un->un_flags |= UN_LOW;
3491 writeb(1, &(bs->ilow));
3494 if ((event & UN_LOW) != 0) {
3495 if ((un->un_flags & UN_EMPTY) == 0) {
3496 un->un_flags |= UN_EMPTY;
3497 writeb(1, &(bs->iempty));
3503 * dgap_tty_write_room()
3505 * Return space available in Tx buffer
3507 static int dgap_tty_write_room(struct tty_struct *tty)
3509 struct channel_t *ch;
3511 struct bs_t __iomem *bs;
3512 u16 head, tail, tmask;
3514 ulong lock_flags = 0;
3519 un = tty->driver_data;
3520 if (!un || un->magic != DGAP_UNIT_MAGIC)
3524 if (!ch || ch->magic != DGAP_CHANNEL_MAGIC)
3531 spin_lock_irqsave(&ch->ch_lock, lock_flags);
3533 tmask = ch->ch_tsize - 1;
3534 head = readw(&(bs->tx_head)) & tmask;
3535 tail = readw(&(bs->tx_tail)) & tmask;
3537 ret = tail - head - 1;
3539 ret += ch->ch_tsize;
3541 /* Limit printer to maxcps */
3542 ret = dgap_maxcps_room(ch, un, ret);
3545 * If we are printer device, leave space for
3546 * possibly both the on and off strings.
3548 if (un->un_type == DGAP_PRINT) {
3549 if (!(ch->ch_flags & CH_PRON))
3550 ret -= ch->ch_digi.digi_onlen;
3551 ret -= ch->ch_digi.digi_offlen;
3553 if (ch->ch_flags & CH_PRON)
3554 ret -= ch->ch_digi.digi_offlen;
3561 * Schedule FEP to wake us up if needed.
3563 * TODO: This might be overkill...
3564 * Do we really need to schedule callbacks from the FEP
3565 * in every case? Can we get smarter based on ret?
3567 dgap_set_firmware_event(un, UN_LOW | UN_EMPTY);
3568 spin_unlock_irqrestore(&ch->ch_lock, lock_flags);
3576 * Take data from the user or kernel and send it out to the FEP.
3577 * In here exists all the Transparent Print magic as well.
3579 static int dgap_tty_write(struct tty_struct *tty, const unsigned char *buf,
3582 struct channel_t *ch;
3584 struct bs_t __iomem *bs;
3585 char __iomem *vaddr;
3586 u16 head, tail, tmask, remain;
3593 un = tty->driver_data;
3594 if (!un || un->magic != DGAP_UNIT_MAGIC)
3598 if (!ch || ch->magic != DGAP_CHANNEL_MAGIC)
3608 spin_lock_irqsave(&ch->ch_lock, lock_flags);
3610 /* Get our space available for the channel from the board */
3611 tmask = ch->ch_tsize - 1;
3612 head = readw(&(bs->tx_head)) & tmask;
3613 tail = readw(&(bs->tx_tail)) & tmask;
3615 bufcount = tail - head - 1;
3617 bufcount += ch->ch_tsize;
3620 * Limit printer output to maxcps overall, with bursts allowed
3621 * up to bufsize characters.
3623 bufcount = dgap_maxcps_room(ch, un, bufcount);
3626 * Take minimum of what the user wants to send, and the
3627 * space available in the FEP buffer.
3629 count = min(count, bufcount);
3632 * Bail if no space left.
3635 dgap_set_firmware_event(un, UN_LOW | UN_EMPTY);
3636 spin_unlock_irqrestore(&ch->ch_lock, lock_flags);
3641 * Output the printer ON string, if we are in terminal mode, but
3642 * need to be in printer mode.
3644 if ((un->un_type == DGAP_PRINT) && !(ch->ch_flags & CH_PRON)) {
3645 dgap_wmove(ch, ch->ch_digi.digi_onstr,
3646 (int) ch->ch_digi.digi_onlen);
3647 head = readw(&(bs->tx_head)) & tmask;
3648 ch->ch_flags |= CH_PRON;
3652 * On the other hand, output the printer OFF string, if we are
3653 * currently in printer mode, but need to output to the terminal.
3655 if ((un->un_type != DGAP_PRINT) && (ch->ch_flags & CH_PRON)) {
3656 dgap_wmove(ch, ch->ch_digi.digi_offstr,
3657 (int) ch->ch_digi.digi_offlen);
3658 head = readw(&(bs->tx_head)) & tmask;
3659 ch->ch_flags &= ~CH_PRON;
3665 * If the write wraps over the top of the circular buffer,
3666 * move the portion up to the wrap point, and reset the
3667 * pointers to the bottom.
3669 remain = ch->ch_tstart + ch->ch_tsize - head;
3673 vaddr = ch->ch_taddr + head;
3675 memcpy_toio(vaddr, (u8 *) buf, remain);
3677 head = ch->ch_tstart;
3684 * Move rest of data.
3686 vaddr = ch->ch_taddr + head;
3689 memcpy_toio(vaddr, (u8 *) buf, remain);
3695 ch->ch_txcount += count;
3697 writew(head, &(bs->tx_head));
3700 dgap_set_firmware_event(un, UN_LOW | UN_EMPTY);
3703 * If this is the print device, and the
3704 * printer is still on, we need to turn it
3705 * off before going idle. If the buffer is
3706 * non-empty, wait until it goes empty.
3707 * Otherwise turn it off right now.
3709 if ((un->un_type == DGAP_PRINT) && (ch->ch_flags & CH_PRON)) {
3710 tail = readw(&(bs->tx_tail)) & tmask;
3713 un->un_flags |= UN_EMPTY;
3714 writeb(1, &(bs->iempty));
3716 dgap_wmove(ch, ch->ch_digi.digi_offstr,
3717 (int) ch->ch_digi.digi_offlen);
3718 head = readw(&(bs->tx_head)) & tmask;
3719 ch->ch_flags &= ~CH_PRON;
3723 /* Update printer buffer empty time. */
3724 if ((un->un_type == DGAP_PRINT) && (ch->ch_digi.digi_maxcps > 0)
3725 && (ch->ch_digi.digi_bufsize > 0)) {
3726 ch->ch_cpstime += (HZ * count) / ch->ch_digi.digi_maxcps;
3729 spin_unlock_irqrestore(&ch->ch_lock, lock_flags);
3735 * dgap_tty_put_char()
3737 * Put a character into ch->ch_buf
3739 * - used by the line discipline for OPOST processing
3741 static int dgap_tty_put_char(struct tty_struct *tty, unsigned char c)
3744 * Simply call tty_write.
3746 dgap_tty_write(tty, &c, 1);
3751 * Return modem signals to ld.
3753 static int dgap_tty_tiocmget(struct tty_struct *tty)
3755 struct channel_t *ch;
3761 if (!tty || tty->magic != TTY_MAGIC)
3764 un = tty->driver_data;
3765 if (!un || un->magic != DGAP_UNIT_MAGIC)
3769 if (!ch || ch->magic != DGAP_CHANNEL_MAGIC)
3772 spin_lock_irqsave(&ch->ch_lock, lock_flags);
3774 mstat = readb(&(ch->ch_bs->m_stat));
3775 /* Append any outbound signals that might be pending... */
3776 mstat |= ch->ch_mostat;
3778 spin_unlock_irqrestore(&ch->ch_lock, lock_flags);
3782 if (mstat & D_DTR(ch))
3783 result |= TIOCM_DTR;
3784 if (mstat & D_RTS(ch))
3785 result |= TIOCM_RTS;
3786 if (mstat & D_CTS(ch))
3787 result |= TIOCM_CTS;
3788 if (mstat & D_DSR(ch))
3789 result |= TIOCM_DSR;
3790 if (mstat & D_RI(ch))
3792 if (mstat & D_CD(ch))
3799 * dgap_tty_tiocmset()
3801 * Set modem signals, called by ld.
3803 static int dgap_tty_tiocmset(struct tty_struct *tty,
3804 unsigned int set, unsigned int clear)
3807 struct channel_t *ch;
3812 if (!tty || tty->magic != TTY_MAGIC)
3815 un = tty->driver_data;
3816 if (!un || un->magic != DGAP_UNIT_MAGIC)
3820 if (!ch || ch->magic != DGAP_CHANNEL_MAGIC)
3824 if (!bd || bd->magic != DGAP_BOARD_MAGIC)
3827 spin_lock_irqsave(&bd->bd_lock, lock_flags);
3828 spin_lock_irqsave(&ch->ch_lock, lock_flags2);
3830 if (set & TIOCM_RTS) {
3831 ch->ch_mforce |= D_RTS(ch);
3832 ch->ch_mval |= D_RTS(ch);
3835 if (set & TIOCM_DTR) {
3836 ch->ch_mforce |= D_DTR(ch);
3837 ch->ch_mval |= D_DTR(ch);
3840 if (clear & TIOCM_RTS) {
3841 ch->ch_mforce |= D_RTS(ch);
3842 ch->ch_mval &= ~(D_RTS(ch));
3845 if (clear & TIOCM_DTR) {
3846 ch->ch_mforce |= D_DTR(ch);
3847 ch->ch_mval &= ~(D_DTR(ch));
3850 dgap_param(ch, bd, un->un_type);
3852 spin_unlock_irqrestore(&ch->ch_lock, lock_flags2);
3853 spin_unlock_irqrestore(&bd->bd_lock, lock_flags);
3859 * dgap_tty_send_break()
3861 * Send a Break, called by ld.
3863 static int dgap_tty_send_break(struct tty_struct *tty, int msec)
3866 struct channel_t *ch;
3871 if (!tty || tty->magic != TTY_MAGIC)
3874 un = tty->driver_data;
3875 if (!un || un->magic != DGAP_UNIT_MAGIC)
3879 if (!ch || ch->magic != DGAP_CHANNEL_MAGIC)
3883 if (!bd || bd->magic != DGAP_BOARD_MAGIC)
3898 spin_lock_irqsave(&bd->bd_lock, lock_flags);
3899 spin_lock_irqsave(&ch->ch_lock, lock_flags2);
3901 dgap_cmdw(ch, SBREAK, (u16) SBREAK_TIME, 0);
3903 dgap_cmdw(ch, SBREAK, (u16) msec, 0);
3905 spin_unlock_irqrestore(&ch->ch_lock, lock_flags2);
3906 spin_unlock_irqrestore(&bd->bd_lock, lock_flags);
3912 * dgap_tty_wait_until_sent()
3914 * wait until data has been transmitted, called by ld.
3916 static void dgap_tty_wait_until_sent(struct tty_struct *tty, int timeout)
3918 dgap_wait_for_drain(tty);
3924 * send a high priority character, called by ld.
3926 static void dgap_tty_send_xchar(struct tty_struct *tty, char c)
3929 struct channel_t *ch;
3934 if (!tty || tty->magic != TTY_MAGIC)
3937 un = tty->driver_data;
3938 if (!un || un->magic != DGAP_UNIT_MAGIC)
3942 if (!ch || ch->magic != DGAP_CHANNEL_MAGIC)
3946 if (!bd || bd->magic != DGAP_BOARD_MAGIC)
3949 spin_lock_irqsave(&bd->bd_lock, lock_flags);
3950 spin_lock_irqsave(&ch->ch_lock, lock_flags2);
3953 * This is technically what we should do.
3954 * However, the NIST tests specifically want
3955 * to see each XON or XOFF character that it
3956 * sends, so lets just send each character
3960 if (c == STOP_CHAR(tty))
3961 dgap_cmdw(ch, RPAUSE, 0, 0);
3962 else if (c == START_CHAR(tty))
3963 dgap_cmdw(ch, RRESUME, 0, 0);
3965 dgap_wmove(ch, &c, 1);
3967 dgap_wmove(ch, &c, 1);
3970 spin_unlock_irqrestore(&ch->ch_lock, lock_flags2);
3971 spin_unlock_irqrestore(&bd->bd_lock, lock_flags);
3975 * Return modem signals to ld.
3977 static int dgap_get_modem_info(struct channel_t *ch, unsigned int __user *value)
3984 spin_lock_irqsave(&ch->ch_lock, lock_flags);
3986 mstat = readb(&(ch->ch_bs->m_stat));
3987 /* Append any outbound signals that might be pending... */
3988 mstat |= ch->ch_mostat;
3990 spin_unlock_irqrestore(&ch->ch_lock, lock_flags);
3994 if (mstat & D_DTR(ch))
3995 result |= TIOCM_DTR;
3996 if (mstat & D_RTS(ch))
3997 result |= TIOCM_RTS;
3998 if (mstat & D_CTS(ch))
3999 result |= TIOCM_CTS;
4000 if (mstat & D_DSR(ch))
4001 result |= TIOCM_DSR;
4002 if (mstat & D_RI(ch))
4004 if (mstat & D_CD(ch))
4007 rc = put_user(result, value);
4013 * dgap_set_modem_info()
4015 * Set modem signals, called by ld.
4017 static int dgap_set_modem_info(struct channel_t *ch, struct board_t *bd,
4018 struct un_t *un, unsigned int command,
4019 unsigned int __user *value)
4026 ret = get_user(arg, value);
4032 if (arg & TIOCM_RTS) {
4033 ch->ch_mforce |= D_RTS(ch);
4034 ch->ch_mval |= D_RTS(ch);
4037 if (arg & TIOCM_DTR) {
4038 ch->ch_mforce |= D_DTR(ch);
4039 ch->ch_mval |= D_DTR(ch);
4045 if (arg & TIOCM_RTS) {
4046 ch->ch_mforce |= D_RTS(ch);
4047 ch->ch_mval &= ~(D_RTS(ch));
4050 if (arg & TIOCM_DTR) {
4051 ch->ch_mforce |= D_DTR(ch);
4052 ch->ch_mval &= ~(D_DTR(ch));
4058 ch->ch_mforce = D_DTR(ch)|D_RTS(ch);
4060 if (arg & TIOCM_RTS)
4061 ch->ch_mval |= D_RTS(ch);
4063 ch->ch_mval &= ~(D_RTS(ch));
4065 if (arg & TIOCM_DTR)
4066 ch->ch_mval |= (D_DTR(ch));
4068 ch->ch_mval &= ~(D_DTR(ch));
4076 spin_lock_irqsave(&bd->bd_lock, lock_flags);
4077 spin_lock_irqsave(&ch->ch_lock, lock_flags2);
4079 dgap_param(ch, bd, un->un_type);
4081 spin_unlock_irqrestore(&ch->ch_lock, lock_flags2);
4082 spin_unlock_irqrestore(&bd->bd_lock, lock_flags);
4088 * dgap_tty_digigeta()
4090 * Ioctl to get the information for ditty.
4095 static int dgap_tty_digigeta(struct channel_t *ch,
4096 struct digi_t __user *retinfo)
4104 memset(&tmp, 0, sizeof(tmp));
4106 spin_lock_irqsave(&ch->ch_lock, lock_flags);
4107 memcpy(&tmp, &ch->ch_digi, sizeof(tmp));
4108 spin_unlock_irqrestore(&ch->ch_lock, lock_flags);
4110 if (copy_to_user(retinfo, &tmp, sizeof(*retinfo)))
4117 * dgap_tty_digiseta()
4119 * Ioctl to set the information for ditty.
4124 static int dgap_tty_digiseta(struct channel_t *ch, struct board_t *bd,
4125 struct un_t *un, struct digi_t __user *new_info)
4127 struct digi_t new_digi;
4128 ulong lock_flags = 0;
4129 unsigned long lock_flags2;
4131 if (copy_from_user(&new_digi, new_info, sizeof(struct digi_t)))
4134 spin_lock_irqsave(&bd->bd_lock, lock_flags);
4135 spin_lock_irqsave(&ch->ch_lock, lock_flags2);
4137 memcpy(&ch->ch_digi, &new_digi, sizeof(struct digi_t));
4139 if (ch->ch_digi.digi_maxcps < 1)
4140 ch->ch_digi.digi_maxcps = 1;
4142 if (ch->ch_digi.digi_maxcps > 10000)
4143 ch->ch_digi.digi_maxcps = 10000;
4145 if (ch->ch_digi.digi_bufsize < 10)
4146 ch->ch_digi.digi_bufsize = 10;
4148 if (ch->ch_digi.digi_maxchar < 1)
4149 ch->ch_digi.digi_maxchar = 1;
4151 if (ch->ch_digi.digi_maxchar > ch->ch_digi.digi_bufsize)
4152 ch->ch_digi.digi_maxchar = ch->ch_digi.digi_bufsize;
4154 if (ch->ch_digi.digi_onlen > DIGI_PLEN)
4155 ch->ch_digi.digi_onlen = DIGI_PLEN;
4157 if (ch->ch_digi.digi_offlen > DIGI_PLEN)
4158 ch->ch_digi.digi_offlen = DIGI_PLEN;
4160 dgap_param(ch, bd, un->un_type);
4162 spin_unlock_irqrestore(&ch->ch_lock, lock_flags2);
4163 spin_unlock_irqrestore(&bd->bd_lock, lock_flags);
4169 * dgap_tty_digigetedelay()
4171 * Ioctl to get the current edelay setting.
4176 static int dgap_tty_digigetedelay(struct tty_struct *tty, int __user *retinfo)
4178 struct channel_t *ch;
4186 if (!tty || tty->magic != TTY_MAGIC)
4189 un = tty->driver_data;
4190 if (!un || un->magic != DGAP_UNIT_MAGIC)
4194 if (!ch || ch->magic != DGAP_CHANNEL_MAGIC)
4197 memset(&tmp, 0, sizeof(tmp));
4199 spin_lock_irqsave(&ch->ch_lock, lock_flags);
4200 tmp = readw(&(ch->ch_bs->edelay));
4201 spin_unlock_irqrestore(&ch->ch_lock, lock_flags);
4203 if (copy_to_user(retinfo, &tmp, sizeof(*retinfo)))
4210 * dgap_tty_digisetedelay()
4212 * Ioctl to set the EDELAY setting
4215 static int dgap_tty_digisetedelay(struct channel_t *ch, struct board_t *bd,
4216 struct un_t *un, int __user *new_info)
4222 if (copy_from_user(&new_digi, new_info, sizeof(int)))
4225 spin_lock_irqsave(&bd->bd_lock, lock_flags);
4226 spin_lock_irqsave(&ch->ch_lock, lock_flags2);
4228 writew((u16) new_digi, &(ch->ch_bs->edelay));
4230 dgap_param(ch, bd, un->un_type);
4232 spin_unlock_irqrestore(&ch->ch_lock, lock_flags2);
4233 spin_unlock_irqrestore(&bd->bd_lock, lock_flags);
4239 * dgap_tty_digigetcustombaud()
4241 * Ioctl to get the current custom baud rate setting.
4243 static int dgap_tty_digigetcustombaud(struct channel_t *ch, struct un_t *un,
4244 int __user *retinfo)
4252 memset(&tmp, 0, sizeof(tmp));
4254 spin_lock_irqsave(&ch->ch_lock, lock_flags);
4255 tmp = dgap_get_custom_baud(ch);
4256 spin_unlock_irqrestore(&ch->ch_lock, lock_flags);
4258 if (copy_to_user(retinfo, &tmp, sizeof(*retinfo)))
4265 * dgap_tty_digisetcustombaud()
4267 * Ioctl to set the custom baud rate setting
4269 static int dgap_tty_digisetcustombaud(struct channel_t *ch, struct board_t *bd,
4270 struct un_t *un, int __user *new_info)
4276 if (copy_from_user(&new_rate, new_info, sizeof(unsigned int)))
4279 if (bd->bd_flags & BD_FEP5PLUS) {
4281 spin_lock_irqsave(&bd->bd_lock, lock_flags);
4282 spin_lock_irqsave(&ch->ch_lock, lock_flags2);
4284 ch->ch_custom_speed = new_rate;
4286 dgap_param(ch, bd, un->un_type);
4288 spin_unlock_irqrestore(&ch->ch_lock, lock_flags2);
4289 spin_unlock_irqrestore(&bd->bd_lock, lock_flags);
4296 * dgap_set_termios()
4298 static void dgap_tty_set_termios(struct tty_struct *tty,
4299 struct ktermios *old_termios)
4302 struct channel_t *ch;
4304 unsigned long lock_flags;
4305 unsigned long lock_flags2;
4307 if (!tty || tty->magic != TTY_MAGIC)
4310 un = tty->driver_data;
4311 if (!un || un->magic != DGAP_UNIT_MAGIC)
4315 if (!ch || ch->magic != DGAP_CHANNEL_MAGIC)
4319 if (!bd || bd->magic != DGAP_BOARD_MAGIC)
4322 spin_lock_irqsave(&bd->bd_lock, lock_flags);
4323 spin_lock_irqsave(&ch->ch_lock, lock_flags2);
4325 ch->ch_c_cflag = tty->termios.c_cflag;
4326 ch->ch_c_iflag = tty->termios.c_iflag;
4327 ch->ch_c_oflag = tty->termios.c_oflag;
4328 ch->ch_c_lflag = tty->termios.c_lflag;
4329 ch->ch_startc = tty->termios.c_cc[VSTART];
4330 ch->ch_stopc = tty->termios.c_cc[VSTOP];
4333 dgap_param(ch, bd, un->un_type);
4335 spin_unlock_irqrestore(&ch->ch_lock, lock_flags2);
4336 spin_unlock_irqrestore(&bd->bd_lock, lock_flags);
4339 static void dgap_tty_throttle(struct tty_struct *tty)
4342 struct channel_t *ch;
4347 if (!tty || tty->magic != TTY_MAGIC)
4350 un = tty->driver_data;
4351 if (!un || un->magic != DGAP_UNIT_MAGIC)
4355 if (!ch || ch->magic != DGAP_CHANNEL_MAGIC)
4359 if (!bd || bd->magic != DGAP_BOARD_MAGIC)
4362 spin_lock_irqsave(&bd->bd_lock, lock_flags);
4363 spin_lock_irqsave(&ch->ch_lock, lock_flags2);
4365 ch->ch_flags |= (CH_RXBLOCK);
4367 dgap_cmdw(ch, RPAUSE, 0, 0);
4370 spin_unlock_irqrestore(&ch->ch_lock, lock_flags2);
4371 spin_unlock_irqrestore(&bd->bd_lock, lock_flags);
4375 static void dgap_tty_unthrottle(struct tty_struct *tty)
4378 struct channel_t *ch;
4383 if (!tty || tty->magic != TTY_MAGIC)
4386 un = tty->driver_data;
4387 if (!un || un->magic != DGAP_UNIT_MAGIC)
4391 if (!ch || ch->magic != DGAP_CHANNEL_MAGIC)
4395 if (!bd || bd->magic != DGAP_BOARD_MAGIC)
4398 spin_lock_irqsave(&bd->bd_lock, lock_flags);
4399 spin_lock_irqsave(&ch->ch_lock, lock_flags2);
4401 ch->ch_flags &= ~(CH_RXBLOCK);
4404 dgap_cmdw(ch, RRESUME, 0, 0);
4407 spin_unlock_irqrestore(&ch->ch_lock, lock_flags2);
4408 spin_unlock_irqrestore(&bd->bd_lock, lock_flags);
4411 static struct board_t *find_board_by_major(unsigned int major)
4415 for (i = 0; i < MAXBOARDS; i++) {
4416 struct board_t *brd = dgap_board[i];
4420 if (major == brd->serial_driver->major ||
4421 major == brd->print_driver->major)
4428 /************************************************************************
4430 * TTY Entry points and helper functions
4432 ************************************************************************/
4438 static int dgap_tty_open(struct tty_struct *tty, struct file *file)
4440 struct board_t *brd;
4441 struct channel_t *ch;
4443 struct bs_t __iomem *bs;
4451 major = MAJOR(tty_devnum(tty));
4452 minor = MINOR(tty_devnum(tty));
4454 brd = find_board_by_major(major);
4459 * If board is not yet up to a state of READY, go to
4460 * sleep waiting for it to happen or they cancel the open.
4462 rc = wait_event_interruptible(brd->state_wait,
4463 (brd->state & BOARD_READY));
4468 spin_lock_irqsave(&brd->bd_lock, lock_flags);
4470 /* The wait above should guarantee this cannot happen */
4471 if (brd->state != BOARD_READY) {
4472 spin_unlock_irqrestore(&brd->bd_lock, lock_flags);
4476 /* If opened device is greater than our number of ports, bail. */
4477 if (MINOR(tty_devnum(tty)) > brd->nasync) {
4478 spin_unlock_irqrestore(&brd->bd_lock, lock_flags);
4482 ch = brd->channels[minor];
4484 spin_unlock_irqrestore(&brd->bd_lock, lock_flags);
4488 /* Grab channel lock */
4489 spin_lock_irqsave(&ch->ch_lock, lock_flags2);
4491 /* Figure out our type */
4492 if (major == brd->serial_driver->major) {
4493 un = &brd->channels[minor]->ch_tun;
4494 un->un_type = DGAP_SERIAL;
4495 } else if (major == brd->print_driver->major) {
4496 un = &brd->channels[minor]->ch_pun;
4497 un->un_type = DGAP_PRINT;
4499 spin_unlock_irqrestore(&ch->ch_lock, lock_flags2);
4500 spin_unlock_irqrestore(&brd->bd_lock, lock_flags);
4504 /* Store our unit into driver_data, so we always have it available. */
4505 tty->driver_data = un;
4508 * Error if channel info pointer is NULL.
4512 spin_unlock_irqrestore(&ch->ch_lock, lock_flags2);
4513 spin_unlock_irqrestore(&brd->bd_lock, lock_flags);
4520 if (!(un->un_flags & UN_ISOPEN)) {
4521 /* Store important variables. */
4524 /* Maybe do something here to the TTY struct as well? */
4528 * Initialize if neither terminal or printer is open.
4530 if (!((ch->ch_tun.un_flags | ch->ch_pun.un_flags) & UN_ISOPEN)) {
4536 * Flush input queue.
4538 head = readw(&(bs->rx_head));
4539 writew(head, &(bs->rx_tail));
4542 ch->pscan_state = 0;
4543 ch->pscan_savechar = 0;
4545 ch->ch_c_cflag = tty->termios.c_cflag;
4546 ch->ch_c_iflag = tty->termios.c_iflag;
4547 ch->ch_c_oflag = tty->termios.c_oflag;
4548 ch->ch_c_lflag = tty->termios.c_lflag;
4549 ch->ch_startc = tty->termios.c_cc[VSTART];
4550 ch->ch_stopc = tty->termios.c_cc[VSTOP];
4552 /* TODO: flush our TTY struct here? */
4557 * Run param in case we changed anything
4559 dgap_param(ch, brd, un->un_type);
4562 * follow protocol for opening port
4565 spin_unlock_irqrestore(&ch->ch_lock, lock_flags2);
4566 spin_unlock_irqrestore(&brd->bd_lock, lock_flags);
4568 rc = dgap_block_til_ready(tty, file, ch);
4573 /* No going back now, increment our unit and channel counters */
4574 spin_lock_irqsave(&ch->ch_lock, lock_flags);
4575 ch->ch_open_count++;
4576 un->un_open_count++;
4577 un->un_flags |= (UN_ISOPEN);
4578 spin_unlock_irqrestore(&ch->ch_lock, lock_flags);
4587 static void dgap_tty_close(struct tty_struct *tty, struct file *file)
4589 struct ktermios *ts;
4591 struct channel_t *ch;
4595 if (!tty || tty->magic != TTY_MAGIC)
4598 un = tty->driver_data;
4599 if (!un || un->magic != DGAP_UNIT_MAGIC)
4603 if (!ch || ch->magic != DGAP_CHANNEL_MAGIC)
4607 if (!bd || bd->magic != DGAP_BOARD_MAGIC)
4612 spin_lock_irqsave(&ch->ch_lock, lock_flags);
4615 * Determine if this is the last close or not - and if we agree about
4616 * which type of close it is with the Line Discipline
4618 if ((tty->count == 1) && (un->un_open_count != 1)) {
4620 * Uh, oh. tty->count is 1, which means that the tty
4621 * structure will be freed. un_open_count should always
4622 * be one in these conditions. If it's greater than
4623 * one, we've got real problems, since it means the
4624 * serial port won't be shutdown.
4626 un->un_open_count = 1;
4629 if (--un->un_open_count < 0)
4630 un->un_open_count = 0;
4632 ch->ch_open_count--;
4634 if (ch->ch_open_count && un->un_open_count) {
4635 spin_unlock_irqrestore(&ch->ch_lock, lock_flags);
4639 /* OK, its the last close on the unit */
4641 un->un_flags |= UN_CLOSING;
4646 * Only officially close channel if count is 0 and
4647 * DIGI_PRINTER bit is not set.
4649 if ((ch->ch_open_count == 0) &&
4650 !(ch->ch_digi.digi_flags & DIGI_PRINTER)) {
4652 ch->ch_flags &= ~(CH_RXBLOCK);
4654 spin_unlock_irqrestore(&ch->ch_lock, lock_flags);
4656 /* wait for output to drain */
4657 /* This will also return if we take an interrupt */
4659 dgap_wait_for_drain(tty);
4661 dgap_tty_flush_buffer(tty);
4662 tty_ldisc_flush(tty);
4664 spin_lock_irqsave(&ch->ch_lock, lock_flags);
4669 * If we have HUPCL set, lower DTR and RTS
4671 if (ch->ch_c_cflag & HUPCL) {
4672 ch->ch_mostat &= ~(D_RTS(ch)|D_DTR(ch));
4673 dgap_cmdb(ch, SMODEM, 0, D_DTR(ch)|D_RTS(ch), 0);
4676 * Go to sleep to ensure RTS/DTR
4677 * have been dropped for modems to see it.
4679 spin_unlock_irqrestore(&ch->ch_lock,
4682 /* .25 second delay for dropping RTS/DTR */
4683 schedule_timeout_interruptible(msecs_to_jiffies(250));
4685 spin_lock_irqsave(&ch->ch_lock, lock_flags);
4688 ch->pscan_state = 0;
4689 ch->pscan_savechar = 0;
4690 ch->ch_baud_info = 0;
4695 * turn off print device when closing print device.
4697 if ((un->un_type == DGAP_PRINT) && (ch->ch_flags & CH_PRON)) {
4698 dgap_wmove(ch, ch->ch_digi.digi_offstr,
4699 (int) ch->ch_digi.digi_offlen);
4700 ch->ch_flags &= ~CH_PRON;
4704 un->un_flags &= ~(UN_ISOPEN | UN_CLOSING);
4705 tty->driver_data = NULL;
4707 wake_up_interruptible(&ch->ch_flags_wait);
4708 wake_up_interruptible(&un->un_flags_wait);
4710 spin_unlock_irqrestore(&ch->ch_lock, lock_flags);
4713 static void dgap_tty_start(struct tty_struct *tty)
4716 struct channel_t *ch;
4721 if (!tty || tty->magic != TTY_MAGIC)
4724 un = tty->driver_data;
4725 if (!un || un->magic != DGAP_UNIT_MAGIC)
4729 if (!ch || ch->magic != DGAP_CHANNEL_MAGIC)
4733 if (!bd || bd->magic != DGAP_BOARD_MAGIC)
4736 spin_lock_irqsave(&bd->bd_lock, lock_flags);
4737 spin_lock_irqsave(&ch->ch_lock, lock_flags2);
4739 dgap_cmdw(ch, RESUMETX, 0, 0);
4741 spin_unlock_irqrestore(&ch->ch_lock, lock_flags2);
4742 spin_unlock_irqrestore(&bd->bd_lock, lock_flags);
4745 static void dgap_tty_stop(struct tty_struct *tty)
4748 struct channel_t *ch;
4753 if (!tty || tty->magic != TTY_MAGIC)
4756 un = tty->driver_data;
4757 if (!un || un->magic != DGAP_UNIT_MAGIC)
4761 if (!ch || ch->magic != DGAP_CHANNEL_MAGIC)
4765 if (!bd || bd->magic != DGAP_BOARD_MAGIC)
4768 spin_lock_irqsave(&bd->bd_lock, lock_flags);
4769 spin_lock_irqsave(&ch->ch_lock, lock_flags2);
4771 dgap_cmdw(ch, PAUSETX, 0, 0);
4773 spin_unlock_irqrestore(&ch->ch_lock, lock_flags2);
4774 spin_unlock_irqrestore(&bd->bd_lock, lock_flags);
4778 * dgap_tty_flush_chars()
4780 * Flush the cook buffer
4782 * Note to self, and any other poor souls who venture here:
4784 * flush in this case DOES NOT mean dispose of the data.
4785 * instead, it means "stop buffering and send it if you
4786 * haven't already." Just guess how I figured that out... SRW 2-Jun-98
4788 * It is also always called in interrupt context - JAR 8-Sept-99
4790 static void dgap_tty_flush_chars(struct tty_struct *tty)
4793 struct channel_t *ch;
4798 if (!tty || tty->magic != TTY_MAGIC)
4801 un = tty->driver_data;
4802 if (!un || un->magic != DGAP_UNIT_MAGIC)
4806 if (!ch || ch->magic != DGAP_CHANNEL_MAGIC)
4810 if (!bd || bd->magic != DGAP_BOARD_MAGIC)
4813 spin_lock_irqsave(&bd->bd_lock, lock_flags);
4814 spin_lock_irqsave(&ch->ch_lock, lock_flags2);
4816 /* TODO: Do something here */
4818 spin_unlock_irqrestore(&ch->ch_lock, lock_flags2);
4819 spin_unlock_irqrestore(&bd->bd_lock, lock_flags);
4822 /*****************************************************************************
4824 * The IOCTL function and all of its helpers
4826 *****************************************************************************/
4831 * The usual assortment of ioctl's
4833 static int dgap_tty_ioctl(struct tty_struct *tty, unsigned int cmd,
4837 struct channel_t *ch;
4841 ulong lock_flags = 0;
4842 ulong lock_flags2 = 0;
4843 void __user *uarg = (void __user *) arg;
4845 if (!tty || tty->magic != TTY_MAGIC)
4848 un = tty->driver_data;
4849 if (!un || un->magic != DGAP_UNIT_MAGIC)
4853 if (!ch || ch->magic != DGAP_CHANNEL_MAGIC)
4857 if (!bd || bd->magic != DGAP_BOARD_MAGIC)
4860 spin_lock_irqsave(&bd->bd_lock, lock_flags);
4861 spin_lock_irqsave(&ch->ch_lock, lock_flags2);
4863 if (un->un_open_count <= 0) {
4864 spin_unlock_irqrestore(&ch->ch_lock, lock_flags2);
4865 spin_unlock_irqrestore(&bd->bd_lock, lock_flags);
4871 /* Here are all the standard ioctl's that we MUST implement */
4875 * TCSBRK is SVID version: non-zero arg --> no break
4876 * this behaviour is exploited by tcdrain().
4878 * According to POSIX.1 spec (7.2.2.1.2) breaks should be
4879 * between 0.25 and 0.5 seconds so we'll ask for something
4880 * in the middle: 0.375 seconds.
4882 rc = tty_check_change(tty);
4883 spin_unlock_irqrestore(&ch->ch_lock, lock_flags2);
4884 spin_unlock_irqrestore(&bd->bd_lock, lock_flags);
4888 rc = dgap_wait_for_drain(tty);
4893 spin_lock_irqsave(&bd->bd_lock, lock_flags);
4894 spin_lock_irqsave(&ch->ch_lock, lock_flags2);
4896 if (((cmd == TCSBRK) && (!arg)) || (cmd == TCSBRKP))
4897 dgap_cmdw(ch, SBREAK, (u16) SBREAK_TIME, 0);
4899 spin_unlock_irqrestore(&ch->ch_lock, lock_flags2);
4900 spin_unlock_irqrestore(&bd->bd_lock, lock_flags);
4905 /* support for POSIX tcsendbreak()
4907 * According to POSIX.1 spec (7.2.2.1.2) breaks should be
4908 * between 0.25 and 0.5 seconds so we'll ask for something
4909 * in the middle: 0.375 seconds.
4911 rc = tty_check_change(tty);
4912 spin_unlock_irqrestore(&ch->ch_lock, lock_flags2);
4913 spin_unlock_irqrestore(&bd->bd_lock, lock_flags);
4917 rc = dgap_wait_for_drain(tty);
4921 spin_lock_irqsave(&bd->bd_lock, lock_flags);
4922 spin_lock_irqsave(&ch->ch_lock, lock_flags2);
4924 dgap_cmdw(ch, SBREAK, (u16) SBREAK_TIME, 0);
4926 spin_unlock_irqrestore(&ch->ch_lock, lock_flags2);
4927 spin_unlock_irqrestore(&bd->bd_lock, lock_flags);
4933 * FEP5 doesn't support turning on a break unconditionally.
4934 * The FEP5 device will stop sending a break automatically
4935 * after the specified time value that was sent when turning on
4938 rc = tty_check_change(tty);
4939 spin_unlock_irqrestore(&ch->ch_lock, lock_flags2);
4940 spin_unlock_irqrestore(&bd->bd_lock, lock_flags);
4944 rc = dgap_wait_for_drain(tty);
4948 spin_lock_irqsave(&bd->bd_lock, lock_flags);
4949 spin_lock_irqsave(&ch->ch_lock, lock_flags2);
4951 dgap_cmdw(ch, SBREAK, (u16) SBREAK_TIME, 0);
4953 spin_unlock_irqrestore(&ch->ch_lock, lock_flags2);
4954 spin_unlock_irqrestore(&bd->bd_lock, lock_flags);
4960 * FEP5 doesn't support turning off a break unconditionally.
4961 * The FEP5 device will stop sending a break automatically
4962 * after the specified time value that was sent when turning on
4965 spin_unlock_irqrestore(&ch->ch_lock, lock_flags2);
4966 spin_unlock_irqrestore(&bd->bd_lock, lock_flags);
4971 spin_unlock_irqrestore(&ch->ch_lock, lock_flags2);
4972 spin_unlock_irqrestore(&bd->bd_lock, lock_flags);
4974 rc = put_user(C_CLOCAL(tty) ? 1 : 0,
4975 (unsigned long __user *) arg);
4979 spin_unlock_irqrestore(&ch->ch_lock, lock_flags2);
4980 spin_unlock_irqrestore(&bd->bd_lock, lock_flags);
4982 rc = get_user(arg, (unsigned long __user *) arg);
4986 spin_lock_irqsave(&bd->bd_lock, lock_flags);
4987 spin_lock_irqsave(&ch->ch_lock, lock_flags2);
4988 tty->termios.c_cflag = ((tty->termios.c_cflag & ~CLOCAL) |
4989 (arg ? CLOCAL : 0));
4990 dgap_param(ch, bd, un->un_type);
4991 spin_unlock_irqrestore(&ch->ch_lock, lock_flags2);
4992 spin_unlock_irqrestore(&bd->bd_lock, lock_flags);
4997 spin_unlock_irqrestore(&ch->ch_lock, lock_flags2);
4998 spin_unlock_irqrestore(&bd->bd_lock, lock_flags);
4999 return dgap_get_modem_info(ch, uarg);
5004 spin_unlock_irqrestore(&ch->ch_lock, lock_flags2);
5005 spin_unlock_irqrestore(&bd->bd_lock, lock_flags);
5006 return dgap_set_modem_info(ch, bd, un, cmd, uarg);
5009 * Here are any additional ioctl's that we want to implement
5014 * The linux tty driver doesn't have a flush
5015 * input routine for the driver, assuming all backed
5016 * up data is in the line disc. buffers. However,
5017 * we all know that's not the case. Here, we
5018 * act on the ioctl, but then lie and say we didn't
5019 * so the line discipline will process the flush
5022 rc = tty_check_change(tty);
5024 spin_unlock_irqrestore(&ch->ch_lock, lock_flags2);
5025 spin_unlock_irqrestore(&bd->bd_lock, lock_flags);
5029 if ((arg == TCIFLUSH) || (arg == TCIOFLUSH)) {
5030 if (!(un->un_type == DGAP_PRINT)) {
5031 head = readw(&(ch->ch_bs->rx_head));
5032 writew(head, &(ch->ch_bs->rx_tail));
5033 writeb(0, &(ch->ch_bs->orun));
5037 if ((arg != TCOFLUSH) && (arg != TCIOFLUSH)) {
5038 /* pretend we didn't recognize this IOCTL */
5039 spin_unlock_irqrestore(&ch->ch_lock, lock_flags2);
5040 spin_unlock_irqrestore(&bd->bd_lock, lock_flags);
5042 return -ENOIOCTLCMD;
5045 ch->ch_flags &= ~CH_STOP;
5046 head = readw(&(ch->ch_bs->tx_head));
5047 dgap_cmdw(ch, FLUSHTX, (u16) head, 0);
5048 dgap_cmdw(ch, RESUMETX, 0, 0);
5049 if (ch->ch_tun.un_flags & (UN_LOW|UN_EMPTY)) {
5050 ch->ch_tun.un_flags &= ~(UN_LOW|UN_EMPTY);
5051 wake_up_interruptible(&ch->ch_tun.un_flags_wait);
5053 if (ch->ch_pun.un_flags & (UN_LOW|UN_EMPTY)) {
5054 ch->ch_pun.un_flags &= ~(UN_LOW|UN_EMPTY);
5055 wake_up_interruptible(&ch->ch_pun.un_flags_wait);
5057 if (waitqueue_active(&tty->write_wait))
5058 wake_up_interruptible(&tty->write_wait);
5060 /* Can't hold any locks when calling tty_wakeup! */
5061 spin_unlock_irqrestore(&ch->ch_lock, lock_flags2);
5062 spin_unlock_irqrestore(&bd->bd_lock, lock_flags);
5065 /* pretend we didn't recognize this IOCTL */
5066 return -ENOIOCTLCMD;
5071 * The linux tty driver doesn't have a flush
5072 * input routine for the driver, assuming all backed
5073 * up data is in the line disc. buffers. However,
5074 * we all know that's not the case. Here, we
5075 * act on the ioctl, but then lie and say we didn't
5076 * so the line discipline will process the flush
5079 if (cmd == TCSETSF) {
5081 ch->ch_flags &= ~CH_STOP;
5082 head = readw(&(ch->ch_bs->rx_head));
5083 writew(head, &(ch->ch_bs->rx_tail));
5086 /* now wait for all the output to drain */
5087 spin_unlock_irqrestore(&ch->ch_lock, lock_flags2);
5088 spin_unlock_irqrestore(&bd->bd_lock, lock_flags);
5089 rc = dgap_wait_for_drain(tty);
5093 /* pretend we didn't recognize this */
5094 return -ENOIOCTLCMD;
5098 spin_unlock_irqrestore(&ch->ch_lock, lock_flags2);
5099 spin_unlock_irqrestore(&bd->bd_lock, lock_flags);
5100 rc = dgap_wait_for_drain(tty);
5104 /* pretend we didn't recognize this */
5105 return -ENOIOCTLCMD;
5109 * The Linux Line Discipline (LD) would do this for us if we
5110 * let it, but we have the special firmware options to do this
5111 * the "right way" regardless of hardware or software flow
5112 * control so we'll do it outselves instead of letting the LD
5115 rc = tty_check_change(tty);
5117 spin_unlock_irqrestore(&ch->ch_lock, lock_flags2);
5118 spin_unlock_irqrestore(&bd->bd_lock, lock_flags);
5125 spin_unlock_irqrestore(&ch->ch_lock, lock_flags2);
5126 spin_unlock_irqrestore(&bd->bd_lock, lock_flags);
5127 dgap_tty_start(tty);
5130 spin_unlock_irqrestore(&ch->ch_lock, lock_flags2);
5131 spin_unlock_irqrestore(&bd->bd_lock, lock_flags);
5135 spin_unlock_irqrestore(&ch->ch_lock, lock_flags2);
5136 spin_unlock_irqrestore(&bd->bd_lock, lock_flags);
5137 /* Make the ld do it */
5138 return -ENOIOCTLCMD;
5140 spin_unlock_irqrestore(&ch->ch_lock, lock_flags2);
5141 spin_unlock_irqrestore(&bd->bd_lock, lock_flags);
5142 /* Make the ld do it */
5143 return -ENOIOCTLCMD;
5145 spin_unlock_irqrestore(&ch->ch_lock, lock_flags2);
5146 spin_unlock_irqrestore(&bd->bd_lock, lock_flags);
5151 /* get information for ditty */
5152 spin_unlock_irqrestore(&ch->ch_lock, lock_flags2);
5153 spin_unlock_irqrestore(&bd->bd_lock, lock_flags);
5154 return dgap_tty_digigeta(ch, uarg);
5159 /* set information for ditty */
5160 if (cmd == (DIGI_SETAW)) {
5162 spin_unlock_irqrestore(&ch->ch_lock, lock_flags2);
5163 spin_unlock_irqrestore(&bd->bd_lock, lock_flags);
5164 rc = dgap_wait_for_drain(tty);
5167 spin_lock_irqsave(&bd->bd_lock, lock_flags);
5168 spin_lock_irqsave(&ch->ch_lock, lock_flags2);
5170 tty_ldisc_flush(tty);
5174 spin_unlock_irqrestore(&ch->ch_lock, lock_flags2);
5175 spin_unlock_irqrestore(&bd->bd_lock, lock_flags);
5176 return dgap_tty_digiseta(ch, bd, un, uarg);
5179 spin_unlock_irqrestore(&ch->ch_lock, lock_flags2);
5180 spin_unlock_irqrestore(&bd->bd_lock, lock_flags);
5181 return dgap_tty_digigetedelay(tty, uarg);
5184 spin_unlock_irqrestore(&ch->ch_lock, lock_flags2);
5185 spin_unlock_irqrestore(&bd->bd_lock, lock_flags);
5186 return dgap_tty_digisetedelay(ch, bd, un, uarg);
5188 case DIGI_GETCUSTOMBAUD:
5189 spin_unlock_irqrestore(&ch->ch_lock, lock_flags2);
5190 spin_unlock_irqrestore(&bd->bd_lock, lock_flags);
5191 return dgap_tty_digigetcustombaud(ch, un, uarg);
5193 case DIGI_SETCUSTOMBAUD:
5194 spin_unlock_irqrestore(&ch->ch_lock, lock_flags2);
5195 spin_unlock_irqrestore(&bd->bd_lock, lock_flags);
5196 return dgap_tty_digisetcustombaud(ch, bd, un, uarg);
5198 case DIGI_RESET_PORT:
5199 dgap_firmware_reset_port(ch);
5200 dgap_param(ch, bd, un->un_type);
5201 spin_unlock_irqrestore(&ch->ch_lock, lock_flags2);
5202 spin_unlock_irqrestore(&bd->bd_lock, lock_flags);
5206 spin_unlock_irqrestore(&ch->ch_lock, lock_flags2);
5207 spin_unlock_irqrestore(&bd->bd_lock, lock_flags);
5209 return -ENOIOCTLCMD;
5213 static const struct tty_operations dgap_tty_ops = {
5214 .open = dgap_tty_open,
5215 .close = dgap_tty_close,
5216 .write = dgap_tty_write,
5217 .write_room = dgap_tty_write_room,
5218 .flush_buffer = dgap_tty_flush_buffer,
5219 .chars_in_buffer = dgap_tty_chars_in_buffer,
5220 .flush_chars = dgap_tty_flush_chars,
5221 .ioctl = dgap_tty_ioctl,
5222 .set_termios = dgap_tty_set_termios,
5223 .stop = dgap_tty_stop,
5224 .start = dgap_tty_start,
5225 .throttle = dgap_tty_throttle,
5226 .unthrottle = dgap_tty_unthrottle,
5227 .hangup = dgap_tty_hangup,
5228 .put_char = dgap_tty_put_char,
5229 .tiocmget = dgap_tty_tiocmget,
5230 .tiocmset = dgap_tty_tiocmset,
5231 .break_ctl = dgap_tty_send_break,
5232 .wait_until_sent = dgap_tty_wait_until_sent,
5233 .send_xchar = dgap_tty_send_xchar
5236 /************************************************************************
5238 * TTY Initialization/Cleanup Functions
5240 ************************************************************************/
5243 * dgap_tty_register()
5245 * Init the tty subsystem for this board.
5247 static int dgap_tty_register(struct board_t *brd)
5251 brd->serial_driver = tty_alloc_driver(MAXPORTS,
5252 TTY_DRIVER_REAL_RAW |
5253 TTY_DRIVER_DYNAMIC_DEV |
5254 TTY_DRIVER_HARDWARE_BREAK);
5255 if (IS_ERR(brd->serial_driver))
5256 return PTR_ERR(brd->serial_driver);
5258 snprintf(brd->serial_name, MAXTTYNAMELEN, "tty_dgap_%d_",
5260 brd->serial_driver->name = brd->serial_name;
5261 brd->serial_driver->name_base = 0;
5262 brd->serial_driver->major = 0;
5263 brd->serial_driver->minor_start = 0;
5264 brd->serial_driver->type = TTY_DRIVER_TYPE_SERIAL;
5265 brd->serial_driver->subtype = SERIAL_TYPE_NORMAL;
5266 brd->serial_driver->init_termios = dgap_default_termios;
5267 brd->serial_driver->driver_name = DRVSTR;
5270 * Entry points for driver. Called by the kernel from
5271 * tty_io.c and n_tty.c.
5273 tty_set_operations(brd->serial_driver, &dgap_tty_ops);
5276 * If we're doing transparent print, we have to do all of the above
5277 * again, separately so we don't get the LD confused about what major
5278 * we are when we get into the dgap_tty_open() routine.
5280 brd->print_driver = tty_alloc_driver(MAXPORTS,
5281 TTY_DRIVER_REAL_RAW |
5282 TTY_DRIVER_DYNAMIC_DEV |
5283 TTY_DRIVER_HARDWARE_BREAK);
5284 if (IS_ERR(brd->print_driver)) {
5285 rc = PTR_ERR(brd->print_driver);
5286 goto free_serial_drv;
5289 snprintf(brd->print_name, MAXTTYNAMELEN, "pr_dgap_%d_",
5291 brd->print_driver->name = brd->print_name;
5292 brd->print_driver->name_base = 0;
5293 brd->print_driver->major = 0;
5294 brd->print_driver->minor_start = 0;
5295 brd->print_driver->type = TTY_DRIVER_TYPE_SERIAL;
5296 brd->print_driver->subtype = SERIAL_TYPE_NORMAL;
5297 brd->print_driver->init_termios = dgap_default_termios;
5298 brd->print_driver->driver_name = DRVSTR;
5301 * Entry points for driver. Called by the kernel from
5302 * tty_io.c and n_tty.c.
5304 tty_set_operations(brd->print_driver, &dgap_tty_ops);
5306 /* Register tty devices */
5307 rc = tty_register_driver(brd->serial_driver);
5309 goto free_print_drv;
5311 /* Register Transparent Print devices */
5312 rc = tty_register_driver(brd->print_driver);
5314 goto unregister_serial_drv;
5318 unregister_serial_drv:
5319 tty_unregister_driver(brd->serial_driver);
5321 put_tty_driver(brd->print_driver);
5323 put_tty_driver(brd->serial_driver);
5328 static void dgap_tty_unregister(struct board_t *brd)
5330 tty_unregister_driver(brd->print_driver);
5331 tty_unregister_driver(brd->serial_driver);
5332 put_tty_driver(brd->print_driver);
5333 put_tty_driver(brd->serial_driver);
5336 static int dgap_alloc_flipbuf(struct board_t *brd)
5339 * allocate flip buffer for board.
5341 brd->flipbuf = kmalloc(MYFLIPLEN, GFP_KERNEL);
5345 brd->flipflagbuf = kmalloc(MYFLIPLEN, GFP_KERNEL);
5346 if (!brd->flipflagbuf) {
5347 kfree(brd->flipbuf);
5354 static void dgap_free_flipbuf(struct board_t *brd)
5356 kfree(brd->flipbuf);
5357 kfree(brd->flipflagbuf);
5360 static struct board_t *dgap_verify_board(struct device *p)
5367 bd = dev_get_drvdata(p);
5368 if (!bd || bd->magic != DGAP_BOARD_MAGIC || bd->state != BOARD_READY)
5374 static ssize_t dgap_ports_state_show(struct device *p,
5375 struct device_attribute *attr,
5382 bd = dgap_verify_board(p);
5386 for (i = 0; i < bd->nasync; i++) {
5387 count += snprintf(buf + count, PAGE_SIZE - count,
5388 "%d %s\n", bd->channels[i]->ch_portnum,
5389 bd->channels[i]->ch_open_count ? "Open" : "Closed");
5393 static DEVICE_ATTR(ports_state, S_IRUSR, dgap_ports_state_show, NULL);
5395 static ssize_t dgap_ports_baud_show(struct device *p,
5396 struct device_attribute *attr,
5403 bd = dgap_verify_board(p);
5407 for (i = 0; i < bd->nasync; i++) {
5408 count += snprintf(buf + count, PAGE_SIZE - count, "%d %d\n",
5409 bd->channels[i]->ch_portnum,
5410 bd->channels[i]->ch_baud_info);
5414 static DEVICE_ATTR(ports_baud, S_IRUSR, dgap_ports_baud_show, NULL);
5416 static ssize_t dgap_ports_msignals_show(struct device *p,
5417 struct device_attribute *attr,
5424 bd = dgap_verify_board(p);
5428 for (i = 0; i < bd->nasync; i++) {
5429 if (bd->channels[i]->ch_open_count)
5430 count += snprintf(buf + count, PAGE_SIZE - count,
5431 "%d %s %s %s %s %s %s\n",
5432 bd->channels[i]->ch_portnum,
5433 (bd->channels[i]->ch_mostat &
5434 UART_MCR_RTS) ? "RTS" : "",
5435 (bd->channels[i]->ch_mistat &
5436 UART_MSR_CTS) ? "CTS" : "",
5437 (bd->channels[i]->ch_mostat &
5438 UART_MCR_DTR) ? "DTR" : "",
5439 (bd->channels[i]->ch_mistat &
5440 UART_MSR_DSR) ? "DSR" : "",
5441 (bd->channels[i]->ch_mistat &
5442 UART_MSR_DCD) ? "DCD" : "",
5443 (bd->channels[i]->ch_mistat &
5444 UART_MSR_RI) ? "RI" : "");
5446 count += snprintf(buf + count, PAGE_SIZE - count,
5447 "%d\n", bd->channels[i]->ch_portnum);
5451 static DEVICE_ATTR(ports_msignals, S_IRUSR, dgap_ports_msignals_show, NULL);
5453 static ssize_t dgap_ports_iflag_show(struct device *p,
5454 struct device_attribute *attr,
5461 bd = dgap_verify_board(p);
5465 for (i = 0; i < bd->nasync; i++)
5466 count += snprintf(buf + count, PAGE_SIZE - count, "%d %x\n",
5467 bd->channels[i]->ch_portnum,
5468 bd->channels[i]->ch_c_iflag);
5471 static DEVICE_ATTR(ports_iflag, S_IRUSR, dgap_ports_iflag_show, NULL);
5473 static ssize_t dgap_ports_cflag_show(struct device *p,
5474 struct device_attribute *attr,
5481 bd = dgap_verify_board(p);
5485 for (i = 0; i < bd->nasync; i++)
5486 count += snprintf(buf + count, PAGE_SIZE - count, "%d %x\n",
5487 bd->channels[i]->ch_portnum,
5488 bd->channels[i]->ch_c_cflag);
5491 static DEVICE_ATTR(ports_cflag, S_IRUSR, dgap_ports_cflag_show, NULL);
5493 static ssize_t dgap_ports_oflag_show(struct device *p,
5494 struct device_attribute *attr,
5501 bd = dgap_verify_board(p);
5505 for (i = 0; i < bd->nasync; i++)
5506 count += snprintf(buf + count, PAGE_SIZE - count, "%d %x\n",
5507 bd->channels[i]->ch_portnum,
5508 bd->channels[i]->ch_c_oflag);
5511 static DEVICE_ATTR(ports_oflag, S_IRUSR, dgap_ports_oflag_show, NULL);
5513 static ssize_t dgap_ports_lflag_show(struct device *p,
5514 struct device_attribute *attr,
5521 bd = dgap_verify_board(p);
5525 for (i = 0; i < bd->nasync; i++)
5526 count += snprintf(buf + count, PAGE_SIZE - count, "%d %x\n",
5527 bd->channels[i]->ch_portnum,
5528 bd->channels[i]->ch_c_lflag);
5531 static DEVICE_ATTR(ports_lflag, S_IRUSR, dgap_ports_lflag_show, NULL);
5533 static ssize_t dgap_ports_digi_flag_show(struct device *p,
5534 struct device_attribute *attr,
5541 bd = dgap_verify_board(p);
5545 for (i = 0; i < bd->nasync; i++)
5546 count += snprintf(buf + count, PAGE_SIZE - count, "%d %x\n",
5547 bd->channels[i]->ch_portnum,
5548 bd->channels[i]->ch_digi.digi_flags);
5551 static DEVICE_ATTR(ports_digi_flag, S_IRUSR, dgap_ports_digi_flag_show, NULL);
5553 static ssize_t dgap_ports_rxcount_show(struct device *p,
5554 struct device_attribute *attr,
5561 bd = dgap_verify_board(p);
5565 for (i = 0; i < bd->nasync; i++)
5566 count += snprintf(buf + count, PAGE_SIZE - count, "%d %ld\n",
5567 bd->channels[i]->ch_portnum,
5568 bd->channels[i]->ch_rxcount);
5571 static DEVICE_ATTR(ports_rxcount, S_IRUSR, dgap_ports_rxcount_show, NULL);
5573 static ssize_t dgap_ports_txcount_show(struct device *p,
5574 struct device_attribute *attr,
5581 bd = dgap_verify_board(p);
5585 for (i = 0; i < bd->nasync; i++)
5586 count += snprintf(buf + count, PAGE_SIZE - count, "%d %ld\n",
5587 bd->channels[i]->ch_portnum,
5588 bd->channels[i]->ch_txcount);
5591 static DEVICE_ATTR(ports_txcount, S_IRUSR, dgap_ports_txcount_show, NULL);
5593 static ssize_t dgap_tty_state_show(struct device *d,
5594 struct device_attribute *attr,
5598 struct channel_t *ch;
5603 un = dev_get_drvdata(d);
5604 if (!un || un->magic != DGAP_UNIT_MAGIC)
5607 if (!ch || ch->magic != DGAP_CHANNEL_MAGIC)
5610 if (!bd || bd->magic != DGAP_BOARD_MAGIC)
5612 if (bd->state != BOARD_READY)
5615 return snprintf(buf, PAGE_SIZE, "%s", un->un_open_count ?
5618 static DEVICE_ATTR(state, S_IRUSR, dgap_tty_state_show, NULL);
5620 static ssize_t dgap_tty_baud_show(struct device *d,
5621 struct device_attribute *attr,
5625 struct channel_t *ch;
5630 un = dev_get_drvdata(d);
5631 if (!un || un->magic != DGAP_UNIT_MAGIC)
5634 if (!ch || ch->magic != DGAP_CHANNEL_MAGIC)
5637 if (!bd || bd->magic != DGAP_BOARD_MAGIC)
5639 if (bd->state != BOARD_READY)
5642 return snprintf(buf, PAGE_SIZE, "%d\n", ch->ch_baud_info);
5644 static DEVICE_ATTR(baud, S_IRUSR, dgap_tty_baud_show, NULL);
5646 static ssize_t dgap_tty_msignals_show(struct device *d,
5647 struct device_attribute *attr,
5651 struct channel_t *ch;
5656 un = dev_get_drvdata(d);
5657 if (!un || un->magic != DGAP_UNIT_MAGIC)
5660 if (!ch || ch->magic != DGAP_CHANNEL_MAGIC)
5663 if (!bd || bd->magic != DGAP_BOARD_MAGIC)
5665 if (bd->state != BOARD_READY)
5668 if (ch->ch_open_count) {
5669 return snprintf(buf, PAGE_SIZE, "%s %s %s %s %s %s\n",
5670 (ch->ch_mostat & UART_MCR_RTS) ? "RTS" : "",
5671 (ch->ch_mistat & UART_MSR_CTS) ? "CTS" : "",
5672 (ch->ch_mostat & UART_MCR_DTR) ? "DTR" : "",
5673 (ch->ch_mistat & UART_MSR_DSR) ? "DSR" : "",
5674 (ch->ch_mistat & UART_MSR_DCD) ? "DCD" : "",
5675 (ch->ch_mistat & UART_MSR_RI) ? "RI" : "");
5679 static DEVICE_ATTR(msignals, S_IRUSR, dgap_tty_msignals_show, NULL);
5681 static ssize_t dgap_tty_iflag_show(struct device *d,
5682 struct device_attribute *attr,
5686 struct channel_t *ch;
5691 un = dev_get_drvdata(d);
5692 if (!un || un->magic != DGAP_UNIT_MAGIC)
5695 if (!ch || ch->magic != DGAP_CHANNEL_MAGIC)
5698 if (!bd || bd->magic != DGAP_BOARD_MAGIC)
5700 if (bd->state != BOARD_READY)
5703 return snprintf(buf, PAGE_SIZE, "%x\n", ch->ch_c_iflag);
5705 static DEVICE_ATTR(iflag, S_IRUSR, dgap_tty_iflag_show, NULL);
5707 static ssize_t dgap_tty_cflag_show(struct device *d,
5708 struct device_attribute *attr,
5712 struct channel_t *ch;
5717 un = dev_get_drvdata(d);
5718 if (!un || un->magic != DGAP_UNIT_MAGIC)
5721 if (!ch || ch->magic != DGAP_CHANNEL_MAGIC)
5724 if (!bd || bd->magic != DGAP_BOARD_MAGIC)
5726 if (bd->state != BOARD_READY)
5729 return snprintf(buf, PAGE_SIZE, "%x\n", ch->ch_c_cflag);
5731 static DEVICE_ATTR(cflag, S_IRUSR, dgap_tty_cflag_show, NULL);
5733 static ssize_t dgap_tty_oflag_show(struct device *d,
5734 struct device_attribute *attr,
5738 struct channel_t *ch;
5743 un = dev_get_drvdata(d);
5744 if (!un || un->magic != DGAP_UNIT_MAGIC)
5747 if (!ch || ch->magic != DGAP_CHANNEL_MAGIC)
5750 if (!bd || bd->magic != DGAP_BOARD_MAGIC)
5752 if (bd->state != BOARD_READY)
5755 return snprintf(buf, PAGE_SIZE, "%x\n", ch->ch_c_oflag);
5757 static DEVICE_ATTR(oflag, S_IRUSR, dgap_tty_oflag_show, NULL);
5759 static ssize_t dgap_tty_lflag_show(struct device *d,
5760 struct device_attribute *attr,
5764 struct channel_t *ch;
5769 un = dev_get_drvdata(d);
5770 if (!un || un->magic != DGAP_UNIT_MAGIC)
5773 if (!ch || ch->magic != DGAP_CHANNEL_MAGIC)
5776 if (!bd || bd->magic != DGAP_BOARD_MAGIC)
5778 if (bd->state != BOARD_READY)
5781 return snprintf(buf, PAGE_SIZE, "%x\n", ch->ch_c_lflag);
5783 static DEVICE_ATTR(lflag, S_IRUSR, dgap_tty_lflag_show, NULL);
5785 static ssize_t dgap_tty_digi_flag_show(struct device *d,
5786 struct device_attribute *attr,
5790 struct channel_t *ch;
5795 un = dev_get_drvdata(d);
5796 if (!un || un->magic != DGAP_UNIT_MAGIC)
5799 if (!ch || ch->magic != DGAP_CHANNEL_MAGIC)
5802 if (!bd || bd->magic != DGAP_BOARD_MAGIC)
5804 if (bd->state != BOARD_READY)
5807 return snprintf(buf, PAGE_SIZE, "%x\n", ch->ch_digi.digi_flags);
5809 static DEVICE_ATTR(digi_flag, S_IRUSR, dgap_tty_digi_flag_show, NULL);
5811 static ssize_t dgap_tty_rxcount_show(struct device *d,
5812 struct device_attribute *attr,
5816 struct channel_t *ch;
5821 un = dev_get_drvdata(d);
5822 if (!un || un->magic != DGAP_UNIT_MAGIC)
5825 if (!ch || ch->magic != DGAP_CHANNEL_MAGIC)
5828 if (!bd || bd->magic != DGAP_BOARD_MAGIC)
5830 if (bd->state != BOARD_READY)
5833 return snprintf(buf, PAGE_SIZE, "%ld\n", ch->ch_rxcount);
5835 static DEVICE_ATTR(rxcount, S_IRUSR, dgap_tty_rxcount_show, NULL);
5837 static ssize_t dgap_tty_txcount_show(struct device *d,
5838 struct device_attribute *attr,
5842 struct channel_t *ch;
5847 un = dev_get_drvdata(d);
5848 if (!un || un->magic != DGAP_UNIT_MAGIC)
5851 if (!ch || ch->magic != DGAP_CHANNEL_MAGIC)
5854 if (!bd || bd->magic != DGAP_BOARD_MAGIC)
5856 if (bd->state != BOARD_READY)
5859 return snprintf(buf, PAGE_SIZE, "%ld\n", ch->ch_txcount);
5861 static DEVICE_ATTR(txcount, S_IRUSR, dgap_tty_txcount_show, NULL);
5863 static ssize_t dgap_tty_name_show(struct device *d,
5864 struct device_attribute *attr,
5868 struct channel_t *ch;
5880 un = dev_get_drvdata(d);
5881 if (!un || un->magic != DGAP_UNIT_MAGIC)
5884 if (!ch || ch->magic != DGAP_CHANNEL_MAGIC)
5887 if (!bd || bd->magic != DGAP_BOARD_MAGIC)
5889 if (bd->state != BOARD_READY)
5893 cn = ch->ch_portnum;
5895 for (cptr = bd->bd_config; cptr; cptr = cptr->next) {
5897 if ((cptr->type == BNODE) &&
5898 ((cptr->u.board.type == APORT2_920P) ||
5899 (cptr->u.board.type == APORT4_920P) ||
5900 (cptr->u.board.type == APORT8_920P) ||
5901 (cptr->u.board.type == PAPORT4) ||
5902 (cptr->u.board.type == PAPORT8))) {
5905 if (cptr->u.board.v_start)
5906 starto = cptr->u.board.start;
5911 if (cptr->type == TNODE && found == TRUE) {
5914 if (strstr(cptr->u.ttyname, "tty")) {
5915 ptr1 = cptr->u.ttyname;
5918 ptr1 = cptr->u.ttyname;
5920 for (i = 0; i < dgap_config_get_num_prts(bd); i++) {
5924 return snprintf(buf, PAGE_SIZE, "%s%s%02d\n",
5925 (un->un_type == DGAP_PRINT) ?
5931 if (cptr->type == CNODE) {
5933 for (i = 0; i < cptr->u.conc.nport; i++) {
5934 if (cn != (i + ncount))
5937 return snprintf(buf, PAGE_SIZE, "%s%s%02ld\n",
5938 (un->un_type == DGAP_PRINT) ?
5941 i + (cptr->u.conc.v_start ?
5942 cptr->u.conc.start : 1));
5945 ncount += cptr->u.conc.nport;
5948 if (cptr->type == MNODE) {
5950 for (i = 0; i < cptr->u.module.nport; i++) {
5951 if (cn != (i + ncount))
5954 return snprintf(buf, PAGE_SIZE, "%s%s%02ld\n",
5955 (un->un_type == DGAP_PRINT) ?
5958 i + (cptr->u.module.v_start ?
5959 cptr->u.module.start : 1));
5962 ncount += cptr->u.module.nport;
5966 return snprintf(buf, PAGE_SIZE, "%s_dgap_%d_%d\n",
5967 (un->un_type == DGAP_PRINT) ? "pr" : "tty", bn, cn);
5969 static DEVICE_ATTR(custom_name, S_IRUSR, dgap_tty_name_show, NULL);
5971 static struct attribute *dgap_sysfs_tty_entries[] = {
5972 &dev_attr_state.attr,
5973 &dev_attr_baud.attr,
5974 &dev_attr_msignals.attr,
5975 &dev_attr_iflag.attr,
5976 &dev_attr_cflag.attr,
5977 &dev_attr_oflag.attr,
5978 &dev_attr_lflag.attr,
5979 &dev_attr_digi_flag.attr,
5980 &dev_attr_rxcount.attr,
5981 &dev_attr_txcount.attr,
5982 &dev_attr_custom_name.attr,
5987 /* this function creates the sys files that will export each signal status
5988 * to sysfs each value will be put in a separate filename
5990 static void dgap_create_ports_sysfiles(struct board_t *bd)
5992 dev_set_drvdata(&bd->pdev->dev, bd);
5993 device_create_file(&(bd->pdev->dev), &dev_attr_ports_state);
5994 device_create_file(&(bd->pdev->dev), &dev_attr_ports_baud);
5995 device_create_file(&(bd->pdev->dev), &dev_attr_ports_msignals);
5996 device_create_file(&(bd->pdev->dev), &dev_attr_ports_iflag);
5997 device_create_file(&(bd->pdev->dev), &dev_attr_ports_cflag);
5998 device_create_file(&(bd->pdev->dev), &dev_attr_ports_oflag);
5999 device_create_file(&(bd->pdev->dev), &dev_attr_ports_lflag);
6000 device_create_file(&(bd->pdev->dev), &dev_attr_ports_digi_flag);
6001 device_create_file(&(bd->pdev->dev), &dev_attr_ports_rxcount);
6002 device_create_file(&(bd->pdev->dev), &dev_attr_ports_txcount);
6005 /* removes all the sys files created for that port */
6006 static void dgap_remove_ports_sysfiles(struct board_t *bd)
6008 device_remove_file(&(bd->pdev->dev), &dev_attr_ports_state);
6009 device_remove_file(&(bd->pdev->dev), &dev_attr_ports_baud);
6010 device_remove_file(&(bd->pdev->dev), &dev_attr_ports_msignals);
6011 device_remove_file(&(bd->pdev->dev), &dev_attr_ports_iflag);
6012 device_remove_file(&(bd->pdev->dev), &dev_attr_ports_cflag);
6013 device_remove_file(&(bd->pdev->dev), &dev_attr_ports_oflag);
6014 device_remove_file(&(bd->pdev->dev), &dev_attr_ports_lflag);
6015 device_remove_file(&(bd->pdev->dev), &dev_attr_ports_digi_flag);
6016 device_remove_file(&(bd->pdev->dev), &dev_attr_ports_rxcount);
6017 device_remove_file(&(bd->pdev->dev), &dev_attr_ports_txcount);
6021 * Copies the BIOS code from the user to the board,
6022 * and starts the BIOS running.
6024 static void dgap_do_bios_load(struct board_t *brd, const u8 *ubios, int len)
6030 if (!brd || (brd->magic != DGAP_BOARD_MAGIC) || !brd->re_map_membase)
6033 addr = brd->re_map_membase;
6038 for (i = 0; i < 16; i++)
6039 writeb(0, addr + POSTAREA + i);
6045 memcpy_toio(addr + offset, ubios, len);
6047 writel(0x0bf00401, addr);
6048 writel(0, (addr + 4));
6050 /* Clear the reset, and change states. */
6051 writeb(FEPCLR, brd->re_map_port);
6055 * Checks to see if the BIOS completed running on the card.
6057 static int dgap_test_bios(struct board_t *brd)
6064 if (!brd || (brd->magic != DGAP_BOARD_MAGIC) || !brd->re_map_membase)
6067 addr = brd->re_map_membase;
6068 word = readw(addr + POSTAREA);
6071 * It can take 5-6 seconds for a board to
6072 * pass the bios self test and post results.
6073 * Give it 10 seconds.
6075 brd->wait_for_bios = 0;
6076 while (brd->wait_for_bios < 1000) {
6077 /* Check to see if BIOS thinks board is good. (GD). */
6078 if (word == *(u16 *) "GD")
6080 msleep_interruptible(10);
6081 brd->wait_for_bios++;
6082 word = readw(addr + POSTAREA);
6085 /* Gave up on board after too long of time taken */
6086 err1 = readw(addr + SEQUENCE);
6087 err2 = readw(addr + ERROR);
6088 dev_warn(&brd->pdev->dev, "%s failed diagnostics. Error #(%x,%x).\n",
6089 brd->name, err1, err2);
6090 brd->state = BOARD_FAILED;
6091 brd->dpastatus = BD_NOBIOS;
6097 * Copies the FEP code from the user to the board,
6098 * and starts the FEP running.
6100 static void dgap_do_fep_load(struct board_t *brd, const u8 *ufep, int len)
6105 if (!brd || (brd->magic != DGAP_BOARD_MAGIC) || !brd->re_map_membase)
6108 addr = brd->re_map_membase;
6114 memcpy_toio(addr + offset, ufep, len);
6117 * If board is a concentrator product, we need to give
6118 * it its config string describing how the concentrators look.
6120 if ((brd->type == PCX) || (brd->type == PEPC)) {
6126 xconfig = dgap_create_config_string(brd, string);
6128 /* Write string to board memory */
6129 config = addr + CONFIG;
6130 for (; i < CONFIGSIZE; i++, config++, xconfig++) {
6131 writeb(*xconfig, config);
6132 if ((*xconfig & 0xff) == 0xff)
6137 writel(0xbfc01004, (addr + 0xc34));
6138 writel(0x3, (addr + 0xc30));
6143 * Waits for the FEP to report thats its ready for us to use.
6145 static int dgap_test_fep(struct board_t *brd)
6152 if (!brd || (brd->magic != DGAP_BOARD_MAGIC) || !brd->re_map_membase)
6155 addr = brd->re_map_membase;
6156 word = readw(addr + FEPSTAT);
6159 * It can take 2-3 seconds for the FEP to
6160 * be up and running. Give it 5 secs.
6162 brd->wait_for_fep = 0;
6163 while (brd->wait_for_fep < 500) {
6164 /* Check to see if FEP is up and running now. */
6165 if (word == *(u16 *) "OS") {
6167 * Check to see if the board can support FEP5+ commands.
6169 word = readw(addr + FEP5_PLUS);
6170 if (word == *(u16 *) "5A")
6171 brd->bd_flags |= BD_FEP5PLUS;
6175 msleep_interruptible(10);
6176 brd->wait_for_fep++;
6177 word = readw(addr + FEPSTAT);
6180 /* Gave up on board after too long of time taken */
6181 err1 = readw(addr + SEQUENCE);
6182 err2 = readw(addr + ERROR);
6183 dev_warn(&brd->pdev->dev,
6184 "FEPOS for %s not functioning. Error #(%x,%x).\n",
6185 brd->name, err1, err2);
6186 brd->state = BOARD_FAILED;
6187 brd->dpastatus = BD_NOFEP;
6193 * Physically forces the FEP5 card to reset itself.
6195 static void dgap_do_reset_board(struct board_t *brd)
6202 if (!brd || (brd->magic != DGAP_BOARD_MAGIC) ||
6203 !brd->re_map_membase || !brd->re_map_port)
6206 /* FEPRST does not vary among supported boards */
6207 writeb(FEPRST, brd->re_map_port);
6209 for (i = 0; i <= 1000; i++) {
6210 check = readb(brd->re_map_port) & 0xe;
6211 if (check == FEPRST)
6217 dev_warn(&brd->pdev->dev,
6218 "dgap: Board not resetting... Failing board.\n");
6219 brd->state = BOARD_FAILED;
6220 brd->dpastatus = BD_NOFEP;
6225 * Make sure there really is memory out there.
6227 writel(0xa55a3cc3, (brd->re_map_membase + LOWMEM));
6228 writel(0x5aa5c33c, (brd->re_map_membase + HIGHMEM));
6229 check1 = readl(brd->re_map_membase + LOWMEM);
6230 check2 = readl(brd->re_map_membase + HIGHMEM);
6232 if ((check1 != 0xa55a3cc3) || (check2 != 0x5aa5c33c)) {
6233 dev_warn(&brd->pdev->dev,
6234 "No memory at %p for board.\n",
6235 brd->re_map_membase);
6236 brd->state = BOARD_FAILED;
6237 brd->dpastatus = BD_NOFEP;
6242 #ifdef DIGI_CONCENTRATORS_SUPPORTED
6244 * Sends a concentrator image into the FEP5 board.
6246 static void dgap_do_conc_load(struct board_t *brd, u8 *uaddr, int len)
6248 char __iomem *vaddr;
6250 struct downld_t *to_dp;
6252 if (!brd || (brd->magic != DGAP_BOARD_MAGIC) || !brd->re_map_membase)
6255 vaddr = brd->re_map_membase;
6257 offset = readw((u16 *) (vaddr + DOWNREQ));
6258 to_dp = (struct downld_t *) (vaddr + (int) offset);
6259 memcpy_toio(to_dp, uaddr, len);
6261 /* Tell card we have data for it */
6262 writew(0, vaddr + (DOWNREQ));
6264 brd->conc_dl_status = NO_PENDING_CONCENTRATOR_REQUESTS;
6268 #define EXPANSION_ROM_SIZE (64 * 1024)
6269 #define FEP5_ROM_MAGIC (0xFEFFFFFF)
6271 static void dgap_get_vpd(struct board_t *brd)
6283 * Poke the magic number at the PCI Rom Address location.
6284 * If VPD is supported, the value read from that address
6287 magic = FEP5_ROM_MAGIC;
6288 pci_write_config_dword(brd->pdev, PCI_ROM_ADDRESS, magic);
6289 pci_read_config_dword(brd->pdev, PCI_ROM_ADDRESS, &magic);
6291 /* VPD not supported, bail */
6296 * To get to the OTPROM memory, we have to send the boards base
6297 * address or'ed with 1 into the PCI Rom Address location.
6299 magic = brd->membase | 0x01;
6300 pci_write_config_dword(brd->pdev, PCI_ROM_ADDRESS, magic);
6301 pci_read_config_dword(brd->pdev, PCI_ROM_ADDRESS, &magic);
6303 byte1 = readb(brd->re_map_membase);
6304 byte2 = readb(brd->re_map_membase + 1);
6307 * If the board correctly swapped to the OTPROM memory,
6308 * the first 2 bytes (header) should be 0x55, 0xAA
6310 if (byte1 == 0x55 && byte2 == 0xAA) {
6315 * We have to run through all the OTPROM memory looking
6316 * for the VPD offset.
6318 while (base_offset <= EXPANSION_ROM_SIZE) {
6321 * Lots of magic numbers here.
6323 * The VPD offset is located inside the ROM Data
6326 * We also have to remember the length of each
6327 * ROM Data Structure, so we can "hop" to the next
6328 * entry if the VPD isn't in the current
6329 * ROM Data Structure.
6331 rom_offset = readw(brd->re_map_membase +
6332 base_offset + 0x18);
6333 image_length = readw(brd->re_map_membase +
6334 rom_offset + 0x10) * 512;
6335 vpd_offset = readw(brd->re_map_membase +
6338 /* Found the VPD entry */
6342 /* We didn't find a VPD entry, go to next ROM entry. */
6343 base_offset += image_length;
6345 byte1 = readb(brd->re_map_membase + base_offset);
6346 byte2 = readb(brd->re_map_membase + base_offset + 1);
6349 * If the new ROM offset doesn't have 0x55, 0xAA
6350 * as its header, we have run out of ROM.
6352 if (byte1 != 0x55 || byte2 != 0xAA)
6357 * If we have a VPD offset, then mark the board
6358 * as having a valid VPD, and copy VPDSIZE (512) bytes of
6359 * that VPD to the buffer we have in our board structure.
6362 brd->bd_flags |= BD_HAS_VPD;
6363 for (i = 0; i < VPDSIZE; i++) {
6364 brd->vpd[i] = readb(brd->re_map_membase +
6371 * We MUST poke the magic number at the PCI Rom Address location again.
6372 * This makes the card report the regular board memory back to us,
6373 * rather than the OTPROM memory.
6375 magic = FEP5_ROM_MAGIC;
6376 pci_write_config_dword(brd->pdev, PCI_ROM_ADDRESS, magic);
6380 static ssize_t dgap_driver_version_show(struct device_driver *ddp, char *buf)
6382 return snprintf(buf, PAGE_SIZE, "%s\n", DG_PART);
6384 static DRIVER_ATTR(version, S_IRUSR, dgap_driver_version_show, NULL);
6387 static ssize_t dgap_driver_boards_show(struct device_driver *ddp, char *buf)
6389 return snprintf(buf, PAGE_SIZE, "%d\n", dgap_numboards);
6391 static DRIVER_ATTR(boards, S_IRUSR, dgap_driver_boards_show, NULL);
6394 static ssize_t dgap_driver_maxboards_show(struct device_driver *ddp, char *buf)
6396 return snprintf(buf, PAGE_SIZE, "%d\n", MAXBOARDS);
6398 static DRIVER_ATTR(maxboards, S_IRUSR, dgap_driver_maxboards_show, NULL);
6401 static ssize_t dgap_driver_pollcounter_show(struct device_driver *ddp,
6404 return snprintf(buf, PAGE_SIZE, "%ld\n", dgap_poll_counter);
6406 static DRIVER_ATTR(pollcounter, S_IRUSR, dgap_driver_pollcounter_show, NULL);
6408 static ssize_t dgap_driver_pollrate_show(struct device_driver *ddp, char *buf)
6410 return snprintf(buf, PAGE_SIZE, "%dms\n", dgap_poll_tick);
6413 static ssize_t dgap_driver_pollrate_store(struct device_driver *ddp,
6414 const char *buf, size_t count)
6416 if (sscanf(buf, "%d\n", &dgap_poll_tick) != 1)
6420 static DRIVER_ATTR(pollrate, (S_IRUSR | S_IWUSR), dgap_driver_pollrate_show,
6421 dgap_driver_pollrate_store);
6424 static int dgap_create_driver_sysfiles(struct pci_driver *dgap_driver)
6427 struct device_driver *driverfs = &dgap_driver->driver;
6429 rc |= driver_create_file(driverfs, &driver_attr_version);
6430 rc |= driver_create_file(driverfs, &driver_attr_boards);
6431 rc |= driver_create_file(driverfs, &driver_attr_maxboards);
6432 rc |= driver_create_file(driverfs, &driver_attr_pollrate);
6433 rc |= driver_create_file(driverfs, &driver_attr_pollcounter);
6438 static void dgap_remove_driver_sysfiles(struct pci_driver *dgap_driver)
6440 struct device_driver *driverfs = &dgap_driver->driver;
6442 driver_remove_file(driverfs, &driver_attr_version);
6443 driver_remove_file(driverfs, &driver_attr_boards);
6444 driver_remove_file(driverfs, &driver_attr_maxboards);
6445 driver_remove_file(driverfs, &driver_attr_pollrate);
6446 driver_remove_file(driverfs, &driver_attr_pollcounter);
6449 static struct attribute_group dgap_tty_attribute_group = {
6451 .attrs = dgap_sysfs_tty_entries,
6454 static void dgap_create_tty_sysfs(struct un_t *un, struct device *c)
6458 ret = sysfs_create_group(&c->kobj, &dgap_tty_attribute_group);
6462 dev_set_drvdata(c, un);
6466 static void dgap_remove_tty_sysfs(struct device *c)
6468 sysfs_remove_group(&c->kobj, &dgap_tty_attribute_group);
6472 * Create pr and tty device entries
6474 static int dgap_tty_register_ports(struct board_t *brd)
6476 struct channel_t *ch;
6480 brd->serial_ports = kcalloc(brd->nasync, sizeof(*brd->serial_ports),
6482 if (!brd->serial_ports)
6485 brd->printer_ports = kcalloc(brd->nasync, sizeof(*brd->printer_ports),
6487 if (!brd->printer_ports) {
6489 goto free_serial_ports;
6492 for (i = 0; i < brd->nasync; i++) {
6493 tty_port_init(&brd->serial_ports[i]);
6494 tty_port_init(&brd->printer_ports[i]);
6497 ch = brd->channels[0];
6498 for (i = 0; i < brd->nasync; i++, ch = brd->channels[i]) {
6500 struct device *classp;
6502 classp = tty_port_register_device(&brd->serial_ports[i],
6506 if (IS_ERR(classp)) {
6507 ret = PTR_ERR(classp);
6508 goto unregister_ttys;
6511 dgap_create_tty_sysfs(&ch->ch_tun, classp);
6512 ch->ch_tun.un_sysfs = classp;
6514 classp = tty_port_register_device(&brd->printer_ports[i],
6518 if (IS_ERR(classp)) {
6519 ret = PTR_ERR(classp);
6520 goto unregister_ttys;
6523 dgap_create_tty_sysfs(&ch->ch_pun, classp);
6524 ch->ch_pun.un_sysfs = classp;
6526 dgap_create_ports_sysfiles(brd);
6532 ch = brd->channels[i];
6533 if (ch->ch_tun.un_sysfs) {
6534 dgap_remove_tty_sysfs(ch->ch_tun.un_sysfs);
6535 tty_unregister_device(brd->serial_driver, i);
6538 if (ch->ch_pun.un_sysfs) {
6539 dgap_remove_tty_sysfs(ch->ch_pun.un_sysfs);
6540 tty_unregister_device(brd->print_driver, i);
6545 for (i = 0; i < brd->nasync; i++) {
6546 tty_port_destroy(&brd->serial_ports[i]);
6547 tty_port_destroy(&brd->printer_ports[i]);
6550 kfree(brd->printer_ports);
6551 brd->printer_ports = NULL;
6554 kfree(brd->serial_ports);
6555 brd->serial_ports = NULL;
6561 * dgap_cleanup_tty()
6563 * Uninitialize the TTY portion of this driver. Free all memory and
6566 static void dgap_cleanup_tty(struct board_t *brd)
6571 for (i = 0; i < brd->nasync; i++) {
6572 tty_port_destroy(&brd->serial_ports[i]);
6573 dev = brd->channels[i]->ch_tun.un_sysfs;
6574 dgap_remove_tty_sysfs(dev);
6575 tty_unregister_device(brd->serial_driver, i);
6577 tty_unregister_driver(brd->serial_driver);
6578 put_tty_driver(brd->serial_driver);
6579 kfree(brd->serial_ports);
6581 for (i = 0; i < brd->nasync; i++) {
6582 tty_port_destroy(&brd->printer_ports[i]);
6583 dev = brd->channels[i]->ch_pun.un_sysfs;
6584 dgap_remove_tty_sysfs(dev);
6585 tty_unregister_device(brd->print_driver, i);
6587 tty_unregister_driver(brd->print_driver);
6588 put_tty_driver(brd->print_driver);
6589 kfree(brd->printer_ports);
6592 static int dgap_request_irq(struct board_t *brd)
6596 if (!brd || brd->magic != DGAP_BOARD_MAGIC)
6600 * Set up our interrupt handler if we are set to do interrupts.
6602 if (dgap_config_get_useintr(brd) && brd->irq) {
6604 rc = request_irq(brd->irq, dgap_intr, IRQF_SHARED, "DGAP", brd);
6612 static void dgap_free_irq(struct board_t *brd)
6614 if (brd->intr_used && brd->irq)
6615 free_irq(brd->irq, brd);
6618 static int dgap_firmware_load(struct pci_dev *pdev, int card_type,
6619 struct board_t *brd)
6621 const struct firmware *fw;
6624 char *dgap_config_buf;
6627 dgap_do_reset_board(brd);
6629 if (fw_info[card_type].conf_name) {
6630 ret = request_firmware(&fw, fw_info[card_type].conf_name,
6633 dev_err(&pdev->dev, "config file %s not found\n",
6634 fw_info[card_type].conf_name);
6638 dgap_config_buf = kzalloc(fw->size + 1, GFP_KERNEL);
6639 if (!dgap_config_buf) {
6640 release_firmware(fw);
6644 memcpy(dgap_config_buf, fw->data, fw->size);
6645 release_firmware(fw);
6648 * preserve dgap_config_buf
6649 * as dgap_parsefile would
6650 * otherwise alter it.
6652 tmp_ptr = dgap_config_buf;
6654 if (dgap_parsefile(&tmp_ptr) != 0) {
6655 kfree(dgap_config_buf);
6658 kfree(dgap_config_buf);
6662 * Match this board to a config the user created for us.
6665 dgap_find_config(brd->type, brd->pci_bus, brd->pci_slot);
6668 * Because the 4 port Xr products share the same PCI ID
6669 * as the 8 port Xr products, if we receive a NULL config
6670 * back, and this is a PAPORT8 board, retry with a
6671 * PAPORT4 attempt as well.
6673 if (brd->type == PAPORT8 && !brd->bd_config)
6675 dgap_find_config(PAPORT4, brd->pci_bus, brd->pci_slot);
6677 if (!brd->bd_config) {
6678 dev_err(&pdev->dev, "No valid configuration found\n");
6682 if (fw_info[card_type].bios_name) {
6683 ret = request_firmware(&fw, fw_info[card_type].bios_name,
6686 dev_err(&pdev->dev, "bios file %s not found\n",
6687 fw_info[card_type].bios_name);
6690 dgap_do_bios_load(brd, fw->data, fw->size);
6691 release_firmware(fw);
6693 /* Wait for BIOS to test board... */
6694 ret = dgap_test_bios(brd);
6699 if (fw_info[card_type].fep_name) {
6700 ret = request_firmware(&fw, fw_info[card_type].fep_name,
6703 dev_err(&pdev->dev, "dgap: fep file %s not found\n",
6704 fw_info[card_type].fep_name);
6707 dgap_do_fep_load(brd, fw->data, fw->size);
6708 release_firmware(fw);
6710 /* Wait for FEP to load on board... */
6711 ret = dgap_test_fep(brd);
6716 #ifdef DIGI_CONCENTRATORS_SUPPORTED
6718 * If this is a CX or EPCX, we need to see if the firmware
6719 * is requesting a concentrator image from us.
6721 if ((bd->type == PCX) || (bd->type == PEPC)) {
6722 chk_addr = (u16 *) (vaddr + DOWNREQ);
6723 /* Nonzero if FEP is requesting concentrator image. */
6724 check = readw(chk_addr);
6725 vaddr = brd->re_map_membase;
6728 if (fw_info[card_type].con_name && check && vaddr) {
6729 ret = request_firmware(&fw, fw_info[card_type].con_name,
6732 dev_err(&pdev->dev, "conc file %s not found\n",
6733 fw_info[card_type].con_name);
6736 /* Put concentrator firmware loading code here */
6737 offset = readw((u16 *) (vaddr + DOWNREQ));
6738 memcpy_toio(offset, fw->data, fw->size);
6740 dgap_do_conc_load(brd, (char *)fw->data, fw->size)
6741 release_firmware(fw);
6751 * Init the tty subsystem. Called once per board after board has been
6752 * downloaded and init'ed.
6754 static int dgap_tty_init(struct board_t *brd)
6761 struct channel_t *ch;
6762 struct bs_t __iomem *bs;
6763 struct cm_t __iomem *cm;
6767 * Initialize board structure elements.
6770 vaddr = brd->re_map_membase;
6771 true_count = readw((vaddr + NCHAN));
6773 brd->nasync = dgap_config_get_num_prts(brd);
6776 brd->nasync = brd->maxports;
6778 if (brd->nasync > brd->maxports)
6779 brd->nasync = brd->maxports;
6781 if (true_count != brd->nasync) {
6782 dev_warn(&brd->pdev->dev,
6783 "%s configured for %d ports, has %d ports.\n",
6784 brd->name, brd->nasync, true_count);
6786 if ((brd->type == PPCM) &&
6787 (true_count == 64 || true_count == 0)) {
6788 dev_warn(&brd->pdev->dev,
6789 "Please make SURE the EBI cable running from the card\n");
6790 dev_warn(&brd->pdev->dev,
6791 "to each EM module is plugged into EBI IN!\n");
6794 brd->nasync = true_count;
6796 /* If no ports, don't bother going any further */
6798 brd->state = BOARD_FAILED;
6799 brd->dpastatus = BD_NOFEP;
6805 * Allocate channel memory that might not have been allocated
6806 * when the driver was first loaded.
6808 for (i = 0; i < brd->nasync; i++) {
6810 kzalloc(sizeof(struct channel_t), GFP_KERNEL);
6811 if (!brd->channels[i]) {
6817 ch = brd->channels[0];
6818 vaddr = brd->re_map_membase;
6820 bs = (struct bs_t __iomem *) ((ulong) vaddr + CHANBUF);
6821 cm = (struct cm_t __iomem *) ((ulong) vaddr + CMDBUF);
6825 /* Set up channel variables */
6826 for (i = 0; i < brd->nasync; i++, ch = brd->channels[i], bs++) {
6828 spin_lock_init(&ch->ch_lock);
6830 /* Store all our magic numbers */
6831 ch->magic = DGAP_CHANNEL_MAGIC;
6832 ch->ch_tun.magic = DGAP_UNIT_MAGIC;
6833 ch->ch_tun.un_type = DGAP_SERIAL;
6834 ch->ch_tun.un_ch = ch;
6835 ch->ch_tun.un_dev = i;
6837 ch->ch_pun.magic = DGAP_UNIT_MAGIC;
6838 ch->ch_pun.un_type = DGAP_PRINT;
6839 ch->ch_pun.un_ch = ch;
6840 ch->ch_pun.un_dev = i;
6842 ch->ch_vaddr = vaddr;
6847 ch->ch_digi = dgap_digi_init;
6850 * Set up digi dsr and dcd bits based on altpin flag.
6852 if (dgap_config_get_altpin(brd)) {
6855 ch->ch_digi.digi_flags |= DIGI_ALTPIN;
6858 ch->ch_dsr = DM_DSR;
6861 ch->ch_taddr = vaddr + (ioread16(&(ch->ch_bs->tx_seg)) << 4);
6862 ch->ch_raddr = vaddr + (ioread16(&(ch->ch_bs->rx_seg)) << 4);
6865 ch->ch_tsize = readw(&(ch->ch_bs->tx_max)) + 1;
6866 ch->ch_rsize = readw(&(ch->ch_bs->rx_max)) + 1;
6871 * Set queue water marks, interrupt mask,
6872 * and general tty parameters.
6874 tlw = ch->ch_tsize >= 2000 ? ((ch->ch_tsize * 5) / 8) :
6878 dgap_cmdw(ch, STLOW, tlw, 0);
6880 dgap_cmdw(ch, SRLOW, ch->ch_rsize / 2, 0);
6882 dgap_cmdw(ch, SRHIGH, 7 * ch->ch_rsize / 8, 0);
6884 ch->ch_mistat = readb(&(ch->ch_bs->m_stat));
6886 init_waitqueue_head(&ch->ch_flags_wait);
6887 init_waitqueue_head(&ch->ch_tun.un_flags_wait);
6888 init_waitqueue_head(&ch->ch_pun.un_flags_wait);
6890 /* Turn on all modem interrupts for now */
6891 modem = (DM_CD | DM_DSR | DM_CTS | DM_RI);
6892 writeb(modem, &(ch->ch_bs->m_int));
6895 * Set edelay to 0 if interrupts are turned on,
6896 * otherwise set edelay to the usual 100.
6899 writew(0, &(ch->ch_bs->edelay));
6901 writew(100, &(ch->ch_bs->edelay));
6903 writeb(1, &(ch->ch_bs->idata));
6910 kfree(brd->channels[i]);
6911 brd->channels[i] = NULL;
6919 * Free the channles which are allocated in dgap_tty_init().
6921 static void dgap_tty_free(struct board_t *brd)
6925 for (i = 0; i < brd->nasync; i++)
6926 kfree(brd->channels[i]);
6929 static int dgap_init_one(struct pci_dev *pdev, const struct pci_device_id *ent)
6932 struct board_t *brd;
6934 if (dgap_numboards >= MAXBOARDS)
6937 rc = pci_enable_device(pdev);
6941 brd = dgap_found_board(pdev, ent->driver_data, dgap_numboards);
6943 return PTR_ERR(brd);
6945 rc = dgap_firmware_load(pdev, ent->driver_data, brd);
6949 rc = dgap_alloc_flipbuf(brd);
6953 rc = dgap_tty_register(brd);
6957 rc = dgap_request_irq(brd);
6959 goto unregister_tty;
6962 * Do tty device initialization.
6964 rc = dgap_tty_init(brd);
6968 rc = dgap_tty_register_ports(brd);
6972 brd->state = BOARD_READY;
6973 brd->dpastatus = BD_RUNNING;
6975 dgap_board[dgap_numboards++] = brd;
6984 dgap_tty_unregister(brd);
6986 dgap_free_flipbuf(brd);
6988 dgap_cleanup_nodes();
6995 static void dgap_remove_one(struct pci_dev *dev)
7000 static struct pci_driver dgap_driver = {
7002 .probe = dgap_init_one,
7003 .id_table = dgap_pci_tbl,
7004 .remove = dgap_remove_one,
7010 static int dgap_start(void)
7013 unsigned long flags;
7014 struct device *device;
7018 pr_info("For the tools package please visit http://www.digi.com\n");
7021 * Register our base character device into the kernel.
7025 * Register management/dpa devices
7027 rc = register_chrdev(DIGI_DGAP_MAJOR, "dgap", &dgap_board_fops);
7031 dgap_class = class_create(THIS_MODULE, "dgap_mgmt");
7032 if (IS_ERR(dgap_class)) {
7033 rc = PTR_ERR(dgap_class);
7037 device = device_create(dgap_class, NULL,
7038 MKDEV(DIGI_DGAP_MAJOR, 0),
7040 if (IS_ERR(device)) {
7041 rc = PTR_ERR(device);
7045 /* Start the poller */
7046 spin_lock_irqsave(&dgap_poll_lock, flags);
7047 init_timer(&dgap_poll_timer);
7048 dgap_poll_timer.function = dgap_poll_handler;
7049 dgap_poll_timer.data = 0;
7050 dgap_poll_time = jiffies + dgap_jiffies_from_ms(dgap_poll_tick);
7051 dgap_poll_timer.expires = dgap_poll_time;
7052 spin_unlock_irqrestore(&dgap_poll_lock, flags);
7054 add_timer(&dgap_poll_timer);
7059 class_destroy(dgap_class);
7061 unregister_chrdev(DIGI_DGAP_MAJOR, "dgap");
7065 static void dgap_stop(void)
7067 unsigned long lock_flags;
7069 spin_lock_irqsave(&dgap_poll_lock, lock_flags);
7071 spin_unlock_irqrestore(&dgap_poll_lock, lock_flags);
7073 del_timer_sync(&dgap_poll_timer);
7075 device_destroy(dgap_class, MKDEV(DIGI_DGAP_MAJOR, 0));
7076 class_destroy(dgap_class);
7077 unregister_chrdev(DIGI_DGAP_MAJOR, "dgap");
7081 * dgap_cleanup_board()
7083 * Free all the memory associated with a board
7085 static void dgap_cleanup_board(struct board_t *brd)
7089 if (!brd || brd->magic != DGAP_BOARD_MAGIC)
7094 tasklet_kill(&brd->helper_tasklet);
7098 /* Free all allocated channels structs */
7099 for (i = 0; i < MAXPORTS ; i++)
7100 kfree(brd->channels[i]);
7102 kfree(brd->flipbuf);
7103 kfree(brd->flipflagbuf);
7105 dgap_board[brd->boardnum] = NULL;
7111 /************************************************************************
7113 * Driver load/unload functions
7115 ************************************************************************/
7120 * Module load. This is where it all starts.
7122 static int dgap_init_module(void)
7126 pr_info("%s, Digi International Part Number %s\n", DG_NAME, DG_PART);
7132 rc = pci_register_driver(&dgap_driver);
7136 rc = dgap_create_driver_sysfiles(&dgap_driver);
7138 goto err_unregister;
7140 dgap_driver_state = DRIVER_READY;
7145 pci_unregister_driver(&dgap_driver);
7153 * dgap_cleanup_module()
7155 * Module unload. This is where it all ends.
7157 static void dgap_cleanup_module(void)
7162 spin_lock_irqsave(&dgap_poll_lock, lock_flags);
7164 spin_unlock_irqrestore(&dgap_poll_lock, lock_flags);
7166 /* Turn off poller right away. */
7167 del_timer_sync(&dgap_poll_timer);
7169 dgap_remove_driver_sysfiles(&dgap_driver);
7171 device_destroy(dgap_class, MKDEV(DIGI_DGAP_MAJOR, 0));
7172 class_destroy(dgap_class);
7173 unregister_chrdev(DIGI_DGAP_MAJOR, "dgap");
7175 for (i = 0; i < dgap_numboards; ++i) {
7176 dgap_remove_ports_sysfiles(dgap_board[i]);
7177 dgap_cleanup_tty(dgap_board[i]);
7178 dgap_cleanup_board(dgap_board[i]);
7181 dgap_cleanup_nodes();
7184 pci_unregister_driver(&dgap_driver);
7187 module_init(dgap_init_module);
7188 module_exit(dgap_cleanup_module);
7190 MODULE_LICENSE("GPL");
7191 MODULE_AUTHOR("Digi International, http://www.digi.com");
7192 MODULE_DESCRIPTION("Driver for the Digi International EPCA PCI based product line");
7193 MODULE_SUPPORTED_DEVICE("dgap");