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)
1365 if (!ch || ch->magic != DGAP_CHANNEL_MAGIC)
1368 if (!ch->ch_bd || ch->ch_bd->magic != DGAP_BOARD_MAGIC)
1371 if (!(ch->ch_bd->bd_flags & BD_FEP5PLUS))
1374 vaddr = ch->ch_bd->re_map_membase;
1380 * Go get from fep mem, what the fep
1381 * believes the custom baud rate is.
1383 offset = (ioread16(vaddr + ECS_SEG) << 4) + (ch->ch_portnum * 0x28)
1386 return readw(vaddr + offset);
1392 static int dgap_remap(struct board_t *brd)
1394 if (!brd || brd->magic != DGAP_BOARD_MAGIC)
1397 if (!request_mem_region(brd->membase, 0x200000, "dgap"))
1400 if (!request_mem_region(brd->membase + PCI_IO_OFFSET, 0x200000,
1404 brd->re_map_membase = ioremap(brd->membase, 0x200000);
1405 if (!brd->re_map_membase)
1408 brd->re_map_port = ioremap((brd->membase + PCI_IO_OFFSET), 0x200000);
1409 if (!brd->re_map_port)
1410 goto err_remap_port;
1415 iounmap(brd->re_map_membase);
1417 release_mem_region(brd->membase + PCI_IO_OFFSET, 0x200000);
1419 release_mem_region(brd->membase, 0x200000);
1424 static void dgap_unmap(struct board_t *brd)
1426 iounmap(brd->re_map_port);
1427 iounmap(brd->re_map_membase);
1428 release_mem_region(brd->membase + PCI_IO_OFFSET, 0x200000);
1429 release_mem_region(brd->membase, 0x200000);
1433 * dgap_parity_scan()
1435 * Convert the FEP5 way of reporting parity errors and breaks into
1436 * the Linux line discipline way.
1438 static void dgap_parity_scan(struct channel_t *ch, unsigned char *cbuf,
1439 unsigned char *fbuf, int *len)
1443 unsigned char *in, *cout, *fout;
1450 if (!ch || ch->magic != DGAP_CHANNEL_MAGIC)
1455 switch (ch->pscan_state) {
1457 /* reset to sanity and fall through */
1458 ch->pscan_state = 0;
1461 /* No FF seen yet */
1462 if (c == (unsigned char) '\377')
1463 /* delete this character from stream */
1464 ch->pscan_state = 1;
1467 *fout++ = TTY_NORMAL;
1474 if (c == (unsigned char) '\377') {
1475 /* doubled ff, transform to single ff */
1477 *fout++ = TTY_NORMAL;
1479 ch->pscan_state = 0;
1481 /* save value examination in next state */
1482 ch->pscan_savechar = c;
1483 ch->pscan_state = 2;
1488 /* third character of ff sequence */
1492 if (ch->pscan_savechar == 0x0) {
1496 *fout++ = TTY_BREAK;
1498 ch->ch_err_parity++;
1499 *fout++ = TTY_PARITY;
1504 ch->pscan_state = 0;
1510 /*=======================================================================
1512 * dgap_input - Process received data.
1514 * ch - Pointer to channel structure.
1516 *=======================================================================*/
1518 static void dgap_input(struct channel_t *ch)
1521 struct bs_t __iomem *bs;
1522 struct tty_struct *tp;
1523 struct tty_ldisc *ld;
1537 if (!ch || ch->magic != DGAP_CHANNEL_MAGIC)
1540 tp = ch->ch_tun.un_tty;
1547 if (!bd || bd->magic != DGAP_BOARD_MAGIC)
1550 spin_lock_irqsave(&bd->bd_lock, lock_flags);
1551 spin_lock_irqsave(&ch->ch_lock, lock_flags2);
1554 * Figure the number of characters in the buffer.
1555 * Exit immediately if none.
1558 rmask = ch->ch_rsize - 1;
1560 head = readw(&(bs->rx_head));
1562 tail = readw(&(bs->rx_tail));
1565 data_len = (head - tail) & rmask;
1567 if (data_len == 0) {
1568 writeb(1, &(bs->idata));
1569 spin_unlock_irqrestore(&ch->ch_lock, lock_flags2);
1570 spin_unlock_irqrestore(&bd->bd_lock, lock_flags);
1575 * If the device is not open, or CREAD is off, flush
1576 * input data and return immediately.
1578 if ((bd->state != BOARD_READY) || !tp ||
1579 (tp->magic != TTY_MAGIC) ||
1580 !(ch->ch_tun.un_flags & UN_ISOPEN) ||
1581 !(tp->termios.c_cflag & CREAD) ||
1582 (ch->ch_tun.un_flags & UN_CLOSING)) {
1584 writew(head, &(bs->rx_tail));
1585 writeb(1, &(bs->idata));
1586 spin_unlock_irqrestore(&ch->ch_lock, lock_flags2);
1587 spin_unlock_irqrestore(&bd->bd_lock, lock_flags);
1592 * If we are throttled, simply don't read any data.
1594 if (ch->ch_flags & CH_RXBLOCK) {
1595 writeb(1, &(bs->idata));
1596 spin_unlock_irqrestore(&ch->ch_lock, lock_flags2);
1597 spin_unlock_irqrestore(&bd->bd_lock, lock_flags);
1604 tmpchar = readb(&(bs->orun));
1606 ch->ch_err_overrun++;
1607 writeb(0, &(bs->orun));
1610 /* Decide how much data we can send into the tty layer */
1611 flip_len = TTY_FLIPBUF_SIZE;
1613 /* Chop down the length, if needed */
1614 len = min(data_len, flip_len);
1615 len = min(len, (N_TTY_BUF_SIZE - 1));
1617 ld = tty_ldisc_ref(tp);
1619 #ifdef TTY_DONT_FLIP
1621 * If the DONT_FLIP flag is on, don't flush our buffer, and act
1622 * like the ld doesn't have any space to put the data right now.
1624 if (test_bit(TTY_DONT_FLIP, &tp->flags))
1629 * If we were unable to get a reference to the ld,
1630 * don't flush our buffer, and act like the ld doesn't
1631 * have any space to put the data right now.
1637 * If ld doesn't have a pointer to a receive_buf function,
1638 * flush the data, then act like the ld doesn't have any
1639 * space to put the data right now.
1641 if (!ld->ops->receive_buf) {
1642 writew(head, &(bs->rx_tail));
1648 writeb(1, &(bs->idata));
1649 spin_unlock_irqrestore(&ch->ch_lock, lock_flags2);
1650 spin_unlock_irqrestore(&bd->bd_lock, lock_flags);
1652 tty_ldisc_deref(ld);
1656 buf = ch->ch_bd->flipbuf;
1660 * n now contains the most amount of data we can copy,
1661 * bounded either by our buffer size or the amount
1662 * of data the card actually has pending...
1666 s = ((head >= tail) ? head : ch->ch_rsize) - tail;
1672 memcpy_fromio(buf, ch->ch_raddr + tail, s);
1678 /* Flip queue if needed */
1682 writew(tail, &(bs->rx_tail));
1683 writeb(1, &(bs->idata));
1684 ch->ch_rxcount += len;
1687 * If we are completely raw, we don't need to go through a lot
1688 * of the tty layers that exist.
1689 * In this case, we take the shortest and fastest route we
1690 * can to relay the data to the user.
1692 * On the other hand, if we are not raw, we need to go through
1693 * the tty layer, which has its API more well defined.
1695 if (I_PARMRK(tp) || I_BRKINT(tp) || I_INPCK(tp)) {
1696 dgap_parity_scan(ch, ch->ch_bd->flipbuf,
1697 ch->ch_bd->flipflagbuf, &len);
1699 len = tty_buffer_request_room(tp->port, len);
1700 tty_insert_flip_string_flags(tp->port, ch->ch_bd->flipbuf,
1701 ch->ch_bd->flipflagbuf, len);
1703 len = tty_buffer_request_room(tp->port, len);
1704 tty_insert_flip_string(tp->port, ch->ch_bd->flipbuf, len);
1707 spin_unlock_irqrestore(&ch->ch_lock, lock_flags2);
1708 spin_unlock_irqrestore(&bd->bd_lock, lock_flags);
1710 /* Tell the tty layer its okay to "eat" the data now */
1711 tty_flip_buffer_push(tp->port);
1714 tty_ldisc_deref(ld);
1718 static void dgap_write_wakeup(struct board_t *bd, struct channel_t *ch,
1719 struct un_t *un, u32 mask,
1720 unsigned long *irq_flags1,
1721 unsigned long *irq_flags2)
1723 if (!(un->un_flags & mask))
1726 un->un_flags &= ~mask;
1728 if (!(un->un_flags & UN_ISOPEN))
1731 if ((un->un_tty->flags & (1 << TTY_DO_WRITE_WAKEUP)) &&
1732 un->un_tty->ldisc->ops->write_wakeup) {
1733 spin_unlock_irqrestore(&ch->ch_lock, *irq_flags2);
1734 spin_unlock_irqrestore(&bd->bd_lock, *irq_flags1);
1736 (un->un_tty->ldisc->ops->write_wakeup)(un->un_tty);
1738 spin_lock_irqsave(&bd->bd_lock, *irq_flags1);
1739 spin_lock_irqsave(&ch->ch_lock, *irq_flags2);
1741 wake_up_interruptible(&un->un_tty->write_wait);
1742 wake_up_interruptible(&un->un_flags_wait);
1745 /************************************************************************
1746 * Determines when CARRIER changes state and takes appropriate
1748 ************************************************************************/
1749 static void dgap_carrier(struct channel_t *ch)
1753 int virt_carrier = 0;
1754 int phys_carrier = 0;
1756 if (!ch || ch->magic != DGAP_CHANNEL_MAGIC)
1761 if (!bd || bd->magic != DGAP_BOARD_MAGIC)
1764 /* Make sure altpin is always set correctly */
1765 if (ch->ch_digi.digi_flags & DIGI_ALTPIN) {
1769 ch->ch_dsr = DM_DSR;
1773 if (ch->ch_mistat & D_CD(ch))
1776 if (ch->ch_digi.digi_flags & DIGI_FORCEDCD)
1779 if (ch->ch_c_cflag & CLOCAL)
1783 * Test for a VIRTUAL carrier transition to HIGH.
1785 if (((ch->ch_flags & CH_FCAR) == 0) && (virt_carrier == 1)) {
1788 * When carrier rises, wake any threads waiting
1789 * for carrier in the open routine.
1792 if (waitqueue_active(&(ch->ch_flags_wait)))
1793 wake_up_interruptible(&ch->ch_flags_wait);
1797 * Test for a PHYSICAL carrier transition to HIGH.
1799 if (((ch->ch_flags & CH_CD) == 0) && (phys_carrier == 1)) {
1802 * When carrier rises, wake any threads waiting
1803 * for carrier in the open routine.
1806 if (waitqueue_active(&(ch->ch_flags_wait)))
1807 wake_up_interruptible(&ch->ch_flags_wait);
1811 * Test for a PHYSICAL transition to low, so long as we aren't
1812 * currently ignoring physical transitions (which is what "virtual
1813 * carrier" indicates).
1815 * The transition of the virtual carrier to low really doesn't
1816 * matter... it really only means "ignore carrier state", not
1817 * "make pretend that carrier is there".
1819 if ((virt_carrier == 0) &&
1820 ((ch->ch_flags & CH_CD) != 0) &&
1821 (phys_carrier == 0)) {
1824 * When carrier drops:
1826 * Drop carrier on all open units.
1828 * Flush queues, waking up any task waiting in the
1831 * Send a hangup to the control terminal.
1833 * Enable all select calls.
1835 if (waitqueue_active(&(ch->ch_flags_wait)))
1836 wake_up_interruptible(&ch->ch_flags_wait);
1838 if (ch->ch_tun.un_open_count > 0)
1839 tty_hangup(ch->ch_tun.un_tty);
1841 if (ch->ch_pun.un_open_count > 0)
1842 tty_hangup(ch->ch_pun.un_tty);
1846 * Make sure that our cached values reflect the current reality.
1848 if (virt_carrier == 1)
1849 ch->ch_flags |= CH_FCAR;
1851 ch->ch_flags &= ~CH_FCAR;
1853 if (phys_carrier == 1)
1854 ch->ch_flags |= CH_CD;
1856 ch->ch_flags &= ~CH_CD;
1859 /*=======================================================================
1861 * dgap_event - FEP to host event processing routine.
1863 * bd - Board of current event.
1865 *=======================================================================*/
1866 static int dgap_event(struct board_t *bd)
1868 struct channel_t *ch;
1871 struct bs_t __iomem *bs;
1874 struct ev_t __iomem *eaddr;
1882 if (!bd || bd->magic != DGAP_BOARD_MAGIC)
1885 spin_lock_irqsave(&bd->bd_lock, lock_flags);
1887 vaddr = bd->re_map_membase;
1890 spin_unlock_irqrestore(&bd->bd_lock, lock_flags);
1894 eaddr = (struct ev_t __iomem *) (vaddr + EVBUF);
1896 /* Get our head and tail */
1897 head = readw(&(eaddr->ev_head));
1898 tail = readw(&(eaddr->ev_tail));
1901 * Forget it if pointers out of range.
1904 if (head >= EVMAX - EVSTART || tail >= EVMAX - EVSTART ||
1905 (head | tail) & 03) {
1906 /* Let go of board lock */
1907 spin_unlock_irqrestore(&bd->bd_lock, lock_flags);
1912 * Loop to process all the events in the buffer.
1914 while (tail != head) {
1917 * Get interrupt information.
1920 event = bd->re_map_membase + tail + EVSTART;
1922 port = ioread8(event);
1923 reason = ioread8(event + 1);
1924 modem = ioread8(event + 2);
1925 b1 = ioread8(event + 3);
1928 * Make sure the interrupt is valid.
1930 if (port >= bd->nasync)
1933 if (!(reason & (IFMODEM | IFBREAK | IFTLW | IFTEM | IFDATA)))
1936 ch = bd->channels[port];
1938 if (!ch || ch->magic != DGAP_CHANNEL_MAGIC)
1942 * If we have made it here, the event was valid.
1943 * Lock down the channel.
1945 spin_lock_irqsave(&ch->ch_lock, lock_flags2);
1950 spin_unlock_irqrestore(&ch->ch_lock, lock_flags2);
1955 * Process received data.
1957 if (reason & IFDATA) {
1960 * ALL LOCKS *MUST* BE DROPPED BEFORE CALLING INPUT!
1961 * input could send some data to ld, which in turn
1962 * could do a callback to one of our other functions.
1964 spin_unlock_irqrestore(&ch->ch_lock, lock_flags2);
1965 spin_unlock_irqrestore(&bd->bd_lock, lock_flags);
1969 spin_lock_irqsave(&bd->bd_lock, lock_flags);
1970 spin_lock_irqsave(&ch->ch_lock, lock_flags2);
1972 if (ch->ch_flags & CH_RACTIVE)
1973 ch->ch_flags |= CH_RENABLE;
1975 writeb(1, &(bs->idata));
1977 if (ch->ch_flags & CH_RWAIT) {
1978 ch->ch_flags &= ~CH_RWAIT;
1980 wake_up_interruptible
1981 (&ch->ch_tun.un_flags_wait);
1986 * Process Modem change signals.
1988 if (reason & IFMODEM) {
1989 ch->ch_mistat = modem;
1996 if (reason & IFBREAK) {
1998 if (ch->ch_tun.un_tty) {
1999 /* A break has been indicated */
2001 tty_buffer_request_room
2002 (ch->ch_tun.un_tty->port, 1);
2003 tty_insert_flip_char(ch->ch_tun.un_tty->port,
2005 tty_flip_buffer_push(ch->ch_tun.un_tty->port);
2010 * Process Transmit low.
2012 if (reason & IFTLW) {
2013 dgap_write_wakeup(bd, ch, &ch->ch_tun, UN_LOW,
2014 &lock_flags, &lock_flags2);
2015 dgap_write_wakeup(bd, ch, &ch->ch_pun, UN_LOW,
2016 &lock_flags, &lock_flags2);
2017 if (ch->ch_flags & CH_WLOW) {
2018 ch->ch_flags &= ~CH_WLOW;
2019 wake_up_interruptible(&ch->ch_flags_wait);
2024 * Process Transmit empty.
2026 if (reason & IFTEM) {
2027 dgap_write_wakeup(bd, ch, &ch->ch_tun, UN_EMPTY,
2028 &lock_flags, &lock_flags2);
2029 dgap_write_wakeup(bd, ch, &ch->ch_pun, UN_EMPTY,
2030 &lock_flags, &lock_flags2);
2031 if (ch->ch_flags & CH_WEMPTY) {
2032 ch->ch_flags &= ~CH_WEMPTY;
2033 wake_up_interruptible(&ch->ch_flags_wait);
2037 spin_unlock_irqrestore(&ch->ch_lock, lock_flags2);
2040 tail = (tail + 4) & (EVMAX - EVSTART - 4);
2043 writew(tail, &(eaddr->ev_tail));
2044 spin_unlock_irqrestore(&bd->bd_lock, lock_flags);
2050 * Our board poller function.
2052 static void dgap_poll_tasklet(unsigned long data)
2054 struct board_t *bd = (struct board_t *) data;
2056 char __iomem *vaddr;
2059 if (!bd || (bd->magic != DGAP_BOARD_MAGIC))
2062 if (bd->inhibit_poller)
2065 spin_lock_irqsave(&bd->bd_lock, lock_flags);
2067 vaddr = bd->re_map_membase;
2070 * If board is ready, parse deeper to see if there is anything to do.
2072 if (bd->state == BOARD_READY) {
2074 struct ev_t __iomem *eaddr;
2076 if (!bd->re_map_membase) {
2077 spin_unlock_irqrestore(&bd->bd_lock, lock_flags);
2080 if (!bd->re_map_port) {
2081 spin_unlock_irqrestore(&bd->bd_lock, lock_flags);
2088 eaddr = (struct ev_t __iomem *) (vaddr + EVBUF);
2090 /* Get our head and tail */
2091 head = readw(&(eaddr->ev_head));
2092 tail = readw(&(eaddr->ev_tail));
2095 * If there is an event pending. Go service it.
2098 spin_unlock_irqrestore(&bd->bd_lock, lock_flags);
2100 spin_lock_irqsave(&bd->bd_lock, lock_flags);
2105 * If board is doing interrupts, ACK the interrupt.
2107 if (bd && bd->intr_running)
2108 readb(bd->re_map_port + 2);
2110 spin_unlock_irqrestore(&bd->bd_lock, lock_flags);
2114 spin_unlock_irqrestore(&bd->bd_lock, lock_flags);
2118 * dgap_found_board()
2120 * A board has been found, init it.
2122 static struct board_t *dgap_found_board(struct pci_dev *pdev, int id,
2125 struct board_t *brd;
2126 unsigned int pci_irq;
2130 /* get the board structure and prep it */
2131 brd = kzalloc(sizeof(struct board_t), GFP_KERNEL);
2133 return ERR_PTR(-ENOMEM);
2135 /* store the info for the board we've found */
2136 brd->magic = DGAP_BOARD_MAGIC;
2137 brd->boardnum = boardnum;
2138 brd->vendor = dgap_pci_tbl[id].vendor;
2139 brd->device = dgap_pci_tbl[id].device;
2141 brd->pci_bus = pdev->bus->number;
2142 brd->pci_slot = PCI_SLOT(pdev->devfn);
2143 brd->name = dgap_ids[id].name;
2144 brd->maxports = dgap_ids[id].maxports;
2145 brd->type = dgap_ids[id].config_type;
2146 brd->dpatype = dgap_ids[id].dpatype;
2147 brd->dpastatus = BD_NOFEP;
2148 init_waitqueue_head(&brd->state_wait);
2150 spin_lock_init(&brd->bd_lock);
2152 brd->inhibit_poller = FALSE;
2153 brd->wait_for_bios = 0;
2154 brd->wait_for_fep = 0;
2156 for (i = 0; i < MAXPORTS; i++)
2157 brd->channels[i] = NULL;
2159 /* store which card & revision we have */
2160 pci_read_config_word(pdev, PCI_SUBSYSTEM_VENDOR_ID, &brd->subvendor);
2161 pci_read_config_word(pdev, PCI_SUBSYSTEM_ID, &brd->subdevice);
2162 pci_read_config_byte(pdev, PCI_REVISION_ID, &brd->rev);
2164 pci_irq = pdev->irq;
2167 /* get the PCI Base Address Registers */
2169 /* Xr Jupiter and EPC use BAR 2 */
2170 if (brd->device == PCI_DEV_XRJ_DID || brd->device == PCI_DEV_EPCJ_DID) {
2171 brd->membase = pci_resource_start(pdev, 2);
2172 brd->membase_end = pci_resource_end(pdev, 2);
2174 /* Everyone else uses BAR 0 */
2176 brd->membase = pci_resource_start(pdev, 0);
2177 brd->membase_end = pci_resource_end(pdev, 0);
2180 if (!brd->membase) {
2185 if (brd->membase & 1)
2188 brd->membase &= ~15;
2191 * On the PCI boards, there is no IO space allocated
2192 * The I/O registers will be in the first 3 bytes of the
2193 * upper 2MB of the 4MB memory space. The board memory
2194 * will be mapped into the low 2MB of the 4MB memory space
2196 brd->port = brd->membase + PCI_IO_OFFSET;
2197 brd->port_end = brd->port + PCI_IO_SIZE_DGAP;
2200 * Special initialization for non-PLX boards
2202 if (brd->device != PCI_DEV_XRJ_DID && brd->device != PCI_DEV_EPCJ_DID) {
2205 pci_write_config_byte(pdev, 0x40, 0);
2206 pci_write_config_byte(pdev, 0x46, 0);
2208 /* Limit burst length to 2 doubleword transactions */
2209 pci_write_config_byte(pdev, 0x42, 1);
2212 * Enable IO and mem if not already done.
2213 * This was needed for support on Itanium.
2215 pci_read_config_word(pdev, PCI_COMMAND, &cmd);
2216 cmd |= (PCI_COMMAND_IO | PCI_COMMAND_MEMORY);
2217 pci_write_config_word(pdev, PCI_COMMAND, cmd);
2220 /* init our poll helper tasklet */
2221 tasklet_init(&brd->helper_tasklet, dgap_poll_tasklet,
2222 (unsigned long) brd);
2224 ret = dgap_remap(brd);
2228 pr_info("dgap: board %d: %s (rev %d), irq %ld\n",
2229 boardnum, brd->name, brd->rev, brd->irq);
2236 return ERR_PTR(ret);
2242 * Driver interrupt handler.
2244 static irqreturn_t dgap_intr(int irq, void *voidbrd)
2246 struct board_t *brd = voidbrd;
2252 * Check to make sure its for us.
2254 if (brd->magic != DGAP_BOARD_MAGIC)
2260 * Schedule tasklet to run at a better time.
2262 tasklet_schedule(&brd->helper_tasklet);
2266 /*****************************************************************************
2286 * As each timer expires, it determines (a) whether the "transmit"
2287 * waiter needs to be woken up, and (b) whether the poller needs to
2290 ******************************************************************************/
2292 static void dgap_poll_handler(ulong dummy)
2295 struct board_t *brd;
2296 unsigned long lock_flags;
2299 dgap_poll_counter++;
2302 * Do not start the board state machine until
2303 * driver tells us its up and running, and has
2304 * everything it needs.
2306 if (dgap_driver_state != DRIVER_READY)
2307 goto schedule_poller;
2310 * If we have just 1 board, or the system is not SMP,
2311 * then use the typical old style poller.
2312 * Otherwise, use our new tasklet based poller, which should
2313 * speed things up for multiple boards.
2315 if ((dgap_numboards == 1) || (num_online_cpus() <= 1)) {
2316 for (i = 0; i < dgap_numboards; i++) {
2318 brd = dgap_board[i];
2320 if (brd->state == BOARD_FAILED)
2322 if (!brd->intr_running)
2323 /* Call the real board poller directly */
2324 dgap_poll_tasklet((unsigned long) brd);
2328 * Go thru each board, kicking off a
2329 * tasklet for each if needed
2331 for (i = 0; i < dgap_numboards; i++) {
2332 brd = dgap_board[i];
2335 * Attempt to grab the board lock.
2337 * If we can't get it, no big deal, the next poll
2338 * will get it. Basically, I just really don't want
2339 * to spin in here, because I want to kick off my
2340 * tasklets as fast as I can, and then get out the
2343 if (!spin_trylock(&brd->bd_lock))
2347 * If board is in a failed state, don't bother
2348 * scheduling a tasklet
2350 if (brd->state == BOARD_FAILED) {
2351 spin_unlock(&brd->bd_lock);
2355 /* Schedule a poll helper task */
2356 if (!brd->intr_running)
2357 tasklet_schedule(&brd->helper_tasklet);
2360 * Can't do DGAP_UNLOCK here, as we don't have
2361 * lock_flags because we did a trylock above.
2363 spin_unlock(&brd->bd_lock);
2370 * Schedule ourself back at the nominal wakeup interval.
2372 spin_lock_irqsave(&dgap_poll_lock, lock_flags);
2373 dgap_poll_time += dgap_jiffies_from_ms(dgap_poll_tick);
2375 new_time = dgap_poll_time - jiffies;
2377 if ((ulong) new_time >= 2 * dgap_poll_tick) {
2379 jiffies + dgap_jiffies_from_ms(dgap_poll_tick);
2382 dgap_poll_timer.function = dgap_poll_handler;
2383 dgap_poll_timer.data = 0;
2384 dgap_poll_timer.expires = dgap_poll_time;
2385 spin_unlock_irqrestore(&dgap_poll_lock, lock_flags);
2387 if (!dgap_poll_stop)
2388 add_timer(&dgap_poll_timer);
2391 /*=======================================================================
2393 * dgap_cmdb - Sends a 2 byte command to the FEP.
2395 * ch - Pointer to channel structure.
2396 * cmd - Command to be sent.
2397 * byte1 - Integer containing first byte to be sent.
2398 * byte2 - Integer containing second byte to be sent.
2399 * ncmds - Wait until ncmds or fewer cmds are left
2400 * in the cmd buffer before returning.
2402 *=======================================================================*/
2403 static void dgap_cmdb(struct channel_t *ch, u8 cmd, u8 byte1,
2404 u8 byte2, uint ncmds)
2406 char __iomem *vaddr;
2407 struct __iomem cm_t *cm_addr;
2413 if (!ch || ch->magic != DGAP_CHANNEL_MAGIC)
2417 * Check if board is still alive.
2419 if (ch->ch_bd->state == BOARD_FAILED)
2423 * Make sure the pointers are in range before
2424 * writing to the FEP memory.
2426 vaddr = ch->ch_bd->re_map_membase;
2431 cm_addr = (struct cm_t __iomem *) (vaddr + CMDBUF);
2432 head = readw(&(cm_addr->cm_head));
2435 * Forget it if pointers out of range.
2437 if (head >= (CMDMAX - CMDSTART) || (head & 03)) {
2438 ch->ch_bd->state = BOARD_FAILED;
2443 * Put the data in the circular command buffer.
2445 writeb(cmd, (vaddr + head + CMDSTART + 0));
2446 writeb((u8) ch->ch_portnum, (vaddr + head + CMDSTART + 1));
2447 writeb(byte1, (vaddr + head + CMDSTART + 2));
2448 writeb(byte2, (vaddr + head + CMDSTART + 3));
2450 head = (head + 4) & (CMDMAX - CMDSTART - 4);
2452 writew(head, &(cm_addr->cm_head));
2455 * Wait if necessary before updating the head
2456 * pointer to limit the number of outstanding
2457 * commands to the FEP. If the time spent waiting
2458 * is outlandish, declare the FEP dead.
2460 for (count = dgap_count ;;) {
2462 head = readw(&(cm_addr->cm_head));
2463 tail = readw(&(cm_addr->cm_tail));
2465 n = (head - tail) & (CMDMAX - CMDSTART - 4);
2467 if (n <= ncmds * sizeof(struct cm_t))
2471 ch->ch_bd->state = BOARD_FAILED;
2478 /*=======================================================================
2480 * dgap_cmdw - Sends a 1 word command to the FEP.
2482 * ch - Pointer to channel structure.
2483 * cmd - Command to be sent.
2484 * word - Integer containing word to be sent.
2485 * ncmds - Wait until ncmds or fewer cmds are left
2486 * in the cmd buffer before returning.
2488 *=======================================================================*/
2489 static void dgap_cmdw(struct channel_t *ch, u8 cmd, u16 word, uint ncmds)
2491 char __iomem *vaddr;
2492 struct __iomem cm_t *cm_addr;
2498 if (!ch || ch->magic != DGAP_CHANNEL_MAGIC)
2502 * Check if board is still alive.
2504 if (ch->ch_bd->state == BOARD_FAILED)
2508 * Make sure the pointers are in range before
2509 * writing to the FEP memory.
2511 vaddr = ch->ch_bd->re_map_membase;
2515 cm_addr = (struct cm_t __iomem *) (vaddr + CMDBUF);
2516 head = readw(&(cm_addr->cm_head));
2519 * Forget it if pointers out of range.
2521 if (head >= (CMDMAX - CMDSTART) || (head & 03)) {
2522 ch->ch_bd->state = BOARD_FAILED;
2527 * Put the data in the circular command buffer.
2529 writeb(cmd, (vaddr + head + CMDSTART + 0));
2530 writeb((u8) ch->ch_portnum, (vaddr + head + CMDSTART + 1));
2531 writew((u16) word, (vaddr + head + CMDSTART + 2));
2533 head = (head + 4) & (CMDMAX - CMDSTART - 4);
2535 writew(head, &(cm_addr->cm_head));
2538 * Wait if necessary before updating the head
2539 * pointer to limit the number of outstanding
2540 * commands to the FEP. If the time spent waiting
2541 * is outlandish, declare the FEP dead.
2543 for (count = dgap_count ;;) {
2545 head = readw(&(cm_addr->cm_head));
2546 tail = readw(&(cm_addr->cm_tail));
2548 n = (head - tail) & (CMDMAX - CMDSTART - 4);
2550 if (n <= ncmds * sizeof(struct cm_t))
2554 ch->ch_bd->state = BOARD_FAILED;
2561 /*=======================================================================
2563 * dgap_cmdw_ext - Sends a extended word command to the FEP.
2565 * ch - Pointer to channel structure.
2566 * cmd - Command to be sent.
2567 * word - Integer containing word to be sent.
2568 * ncmds - Wait until ncmds or fewer cmds are left
2569 * in the cmd buffer before returning.
2571 *=======================================================================*/
2572 static void dgap_cmdw_ext(struct channel_t *ch, u16 cmd, u16 word, uint ncmds)
2574 char __iomem *vaddr;
2575 struct __iomem cm_t *cm_addr;
2581 if (!ch || ch->magic != DGAP_CHANNEL_MAGIC)
2585 * Check if board is still alive.
2587 if (ch->ch_bd->state == BOARD_FAILED)
2591 * Make sure the pointers are in range before
2592 * writing to the FEP memory.
2594 vaddr = ch->ch_bd->re_map_membase;
2598 cm_addr = (struct cm_t __iomem *) (vaddr + CMDBUF);
2599 head = readw(&(cm_addr->cm_head));
2602 * Forget it if pointers out of range.
2604 if (head >= (CMDMAX - CMDSTART) || (head & 03)) {
2605 ch->ch_bd->state = BOARD_FAILED;
2610 * Put the data in the circular command buffer.
2613 /* Write an FF to tell the FEP that we want an extended command */
2614 writeb((u8) 0xff, (vaddr + head + CMDSTART + 0));
2616 writeb((u8) ch->ch_portnum, (vaddr + head + CMDSTART + 1));
2617 writew((u16) cmd, (vaddr + head + CMDSTART + 2));
2620 * If the second part of the command won't fit,
2621 * put it at the beginning of the circular buffer.
2623 if (((head + 4) >= ((CMDMAX - CMDSTART)) || (head & 03)))
2624 writew((u16) word, (vaddr + CMDSTART));
2626 writew((u16) word, (vaddr + head + CMDSTART + 4));
2628 head = (head + 8) & (CMDMAX - CMDSTART - 4);
2630 writew(head, &(cm_addr->cm_head));
2633 * Wait if necessary before updating the head
2634 * pointer to limit the number of outstanding
2635 * commands to the FEP. If the time spent waiting
2636 * is outlandish, declare the FEP dead.
2638 for (count = dgap_count ;;) {
2640 head = readw(&(cm_addr->cm_head));
2641 tail = readw(&(cm_addr->cm_tail));
2643 n = (head - tail) & (CMDMAX - CMDSTART - 4);
2645 if (n <= ncmds * sizeof(struct cm_t))
2649 ch->ch_bd->state = BOARD_FAILED;
2656 /*=======================================================================
2658 * dgap_wmove - Write data to FEP buffer.
2660 * ch - Pointer to channel structure.
2661 * buf - Poiter to characters to be moved.
2662 * cnt - Number of characters to move.
2664 *=======================================================================*/
2665 static void dgap_wmove(struct channel_t *ch, char *buf, uint cnt)
2668 char __iomem *taddr;
2669 struct bs_t __iomem *bs;
2672 if (!ch || ch->magic != DGAP_CHANNEL_MAGIC)
2679 head = readw(&(bs->tx_head));
2682 * If pointers are out of range, just return.
2684 if ((cnt > ch->ch_tsize) ||
2685 (unsigned)(head - ch->ch_tstart) >= ch->ch_tsize)
2689 * If the write wraps over the top of the circular buffer,
2690 * move the portion up to the wrap point, and reset the
2691 * pointers to the bottom.
2693 n = ch->ch_tstart + ch->ch_tsize - head;
2697 taddr = ch->ch_taddr + head;
2698 memcpy_toio(taddr, buf, n);
2699 head = ch->ch_tstart;
2704 * Move rest of data.
2706 taddr = ch->ch_taddr + head;
2708 memcpy_toio(taddr, buf, n);
2711 writew(head, &(bs->tx_head));
2715 * Calls the firmware to reset this channel.
2717 static void dgap_firmware_reset_port(struct channel_t *ch)
2719 dgap_cmdb(ch, CHRESET, 0, 0, 0);
2722 * Now that the channel is reset, we need to make sure
2723 * all the current settings get reapplied to the port
2726 * So we will set the driver's cache of firmware
2727 * settings all to 0, and then call param.
2729 ch->ch_fepiflag = 0;
2730 ch->ch_fepcflag = 0;
2731 ch->ch_fepoflag = 0;
2732 ch->ch_fepstartc = 0;
2733 ch->ch_fepstopc = 0;
2734 ch->ch_fepastartc = 0;
2735 ch->ch_fepastopc = 0;
2740 /*=======================================================================
2742 * dgap_param - Set Digi parameters.
2744 * struct tty_struct * - TTY for port.
2746 *=======================================================================*/
2747 static int dgap_param(struct channel_t *ch, struct board_t *bd, u32 un_type)
2756 * If baud rate is zero, flush queues, and set mval to drop DTR.
2758 if ((ch->ch_c_cflag & (CBAUD)) == 0) {
2761 head = readw(&(ch->ch_bs->rx_head));
2762 writew(head, &(ch->ch_bs->rx_tail));
2765 head = readw(&(ch->ch_bs->tx_head));
2766 writew(head, &(ch->ch_bs->tx_tail));
2768 ch->ch_flags |= (CH_BAUD0);
2770 /* Drop RTS and DTR */
2771 ch->ch_mval &= ~(D_RTS(ch)|D_DTR(ch));
2772 mval = D_DTR(ch) | D_RTS(ch);
2773 ch->ch_baud_info = 0;
2775 } else if (ch->ch_custom_speed && (bd->bd_flags & BD_FEP5PLUS)) {
2777 * Tell the fep to do the command
2780 dgap_cmdw_ext(ch, 0xff01, ch->ch_custom_speed, 0);
2783 * Now go get from fep mem, what the fep
2784 * believes the custom baud rate is.
2786 ch->ch_custom_speed = dgap_get_custom_baud(ch);
2787 ch->ch_baud_info = ch->ch_custom_speed;
2789 /* Handle transition from B0 */
2790 if (ch->ch_flags & CH_BAUD0) {
2791 ch->ch_flags &= ~(CH_BAUD0);
2792 ch->ch_mval |= (D_RTS(ch)|D_DTR(ch));
2794 mval = D_DTR(ch) | D_RTS(ch);
2798 * Set baud rate, character size, and parity.
2806 ulong bauds[4][16] = {
2810 600, 1200, 1800, 2400,
2811 4800, 9600, 19200, 38400 },
2812 { /* slowbaud & CBAUDEX */
2813 0, 57600, 115200, 230400,
2814 460800, 150, 200, 921600,
2815 600, 1200, 1800, 2400,
2816 4800, 9600, 19200, 38400 },
2818 0, 57600, 76800, 115200,
2819 14400, 57600, 230400, 76800,
2820 115200, 230400, 28800, 460800,
2821 921600, 9600, 19200, 38400 },
2822 { /* fastbaud & CBAUDEX */
2823 0, 57600, 115200, 230400,
2824 460800, 150, 200, 921600,
2825 600, 1200, 1800, 2400,
2826 4800, 9600, 19200, 38400 }
2830 * Only use the TXPrint baud rate if the
2831 * terminal unit is NOT open
2833 if (!(ch->ch_tun.un_flags & UN_ISOPEN) &&
2834 un_type == DGAP_PRINT)
2835 baud = C_BAUD(ch->ch_pun.un_tty) & 0xff;
2837 baud = C_BAUD(ch->ch_tun.un_tty) & 0xff;
2839 if (ch->ch_c_cflag & CBAUDEX)
2842 if (ch->ch_digi.digi_flags & DIGI_FAST)
2847 if ((iindex >= 0) && (iindex < 4) &&
2848 (jindex >= 0) && (jindex < 16))
2849 baud = bauds[iindex][jindex];
2856 ch->ch_baud_info = baud;
2859 * CBAUD has bit position 0x1000 set these days to
2860 * indicate Linux baud rate remap.
2861 * We use a different bit assignment for high speed.
2862 * Clear this bit out while grabbing the parts of
2865 cflag = ch->ch_c_cflag & ((CBAUD ^ CBAUDEX) | PARODD | PARENB |
2869 * HUPCL bit is used by FEP to indicate fast baud
2870 * table is to be used.
2872 if ((ch->ch_digi.digi_flags & DIGI_FAST) ||
2873 (ch->ch_c_cflag & CBAUDEX))
2876 if ((ch->ch_c_cflag & CBAUDEX) &&
2877 !(ch->ch_digi.digi_flags & DIGI_FAST)) {
2879 * The below code is trying to guarantee that only
2880 * baud rates 115200, 230400, 460800, 921600 are
2881 * remapped. We use exclusive or because the various
2882 * baud rates share common bit positions and therefore
2883 * can't be tested for easily.
2885 tcflag_t tcflag = (ch->ch_c_cflag & CBAUD) | CBAUDEX;
2889 * Map high speed requests to index
2890 * into FEP's baud table
2920 cflag = (cflag & ~(CBAUD | CBAUDEX)) | baudpart;
2925 if (cflag != ch->ch_fepcflag) {
2926 ch->ch_fepcflag = (u16) (cflag & 0xffff);
2929 * Okay to have channel and board
2930 * locks held calling this
2932 dgap_cmdw(ch, SCFLAG, (u16) cflag, 0);
2935 /* Handle transition from B0 */
2936 if (ch->ch_flags & CH_BAUD0) {
2937 ch->ch_flags &= ~(CH_BAUD0);
2938 ch->ch_mval |= (D_RTS(ch)|D_DTR(ch));
2940 mval = D_DTR(ch) | D_RTS(ch);
2946 iflag = ch->ch_c_iflag & (IGNBRK | BRKINT | IGNPAR | PARMRK |
2947 INPCK | ISTRIP | IXON | IXANY | IXOFF);
2949 if ((ch->ch_startc == _POSIX_VDISABLE) ||
2950 (ch->ch_stopc == _POSIX_VDISABLE)) {
2951 iflag &= ~(IXON | IXOFF);
2952 ch->ch_c_iflag &= ~(IXON | IXOFF);
2956 * Only the IBM Xr card can switch between
2957 * 232 and 422 modes on the fly
2959 if (bd->device == PCI_DEV_XR_IBM_DID) {
2960 if (ch->ch_digi.digi_flags & DIGI_422)
2961 dgap_cmdb(ch, SCOMMODE, MODE_422, 0, 0);
2963 dgap_cmdb(ch, SCOMMODE, MODE_232, 0, 0);
2966 if (ch->ch_digi.digi_flags & DIGI_ALTPIN)
2969 if (iflag != ch->ch_fepiflag) {
2970 ch->ch_fepiflag = iflag;
2972 /* Okay to have channel and board locks held calling this */
2973 dgap_cmdw(ch, SIFLAG, (u16) ch->ch_fepiflag, 0);
2977 * Select hardware handshaking.
2981 if (ch->ch_c_cflag & CRTSCTS)
2982 hflow |= (D_RTS(ch) | D_CTS(ch));
2983 if (ch->ch_digi.digi_flags & RTSPACE)
2985 if (ch->ch_digi.digi_flags & DTRPACE)
2987 if (ch->ch_digi.digi_flags & CTSPACE)
2989 if (ch->ch_digi.digi_flags & DSRPACE)
2991 if (ch->ch_digi.digi_flags & DCDPACE)
2994 if (hflow != ch->ch_hflow) {
2995 ch->ch_hflow = hflow;
2997 /* Okay to have channel and board locks held calling this */
2998 dgap_cmdb(ch, SHFLOW, (u8) hflow, 0xff, 0);
3002 * Set RTS and/or DTR Toggle if needed,
3003 * but only if product is FEP5+ based.
3005 if (bd->bd_flags & BD_FEP5PLUS) {
3008 if (ch->ch_digi.digi_flags & DIGI_RTS_TOGGLE)
3009 hflow2 |= (D_RTS(ch));
3010 if (ch->ch_digi.digi_flags & DIGI_DTR_TOGGLE)
3011 hflow2 |= (D_DTR(ch));
3013 dgap_cmdw_ext(ch, 0xff03, hflow2, 0);
3017 * Set modem control lines.
3020 mval ^= ch->ch_mforce & (mval ^ ch->ch_mval);
3022 if (ch->ch_mostat ^ mval) {
3023 ch->ch_mostat = mval;
3025 /* Okay to have channel and board locks held calling this */
3026 dgap_cmdb(ch, SMODEM, (u8) mval, D_RTS(ch)|D_DTR(ch), 0);
3030 * Read modem signals, and then call carrier function.
3032 ch->ch_mistat = readb(&(ch->ch_bs->m_stat));
3036 * Set the start and stop characters.
3038 if (ch->ch_startc != ch->ch_fepstartc ||
3039 ch->ch_stopc != ch->ch_fepstopc) {
3040 ch->ch_fepstartc = ch->ch_startc;
3041 ch->ch_fepstopc = ch->ch_stopc;
3043 /* Okay to have channel and board locks held calling this */
3044 dgap_cmdb(ch, SFLOWC, ch->ch_fepstartc, ch->ch_fepstopc, 0);
3048 * Set the Auxiliary start and stop characters.
3050 if (ch->ch_astartc != ch->ch_fepastartc ||
3051 ch->ch_astopc != ch->ch_fepastopc) {
3052 ch->ch_fepastartc = ch->ch_astartc;
3053 ch->ch_fepastopc = ch->ch_astopc;
3055 /* Okay to have channel and board locks held calling this */
3056 dgap_cmdb(ch, SAFLOWC, ch->ch_fepastartc, ch->ch_fepastopc, 0);
3063 * dgap_block_til_ready()
3065 * Wait for DCD, if needed.
3067 static int dgap_block_til_ready(struct tty_struct *tty, struct file *file,
3068 struct channel_t *ch)
3074 int sleep_on_un_flags;
3076 if (!tty || tty->magic != TTY_MAGIC || !file || !ch ||
3077 ch->magic != DGAP_CHANNEL_MAGIC)
3080 un = tty->driver_data;
3081 if (!un || un->magic != DGAP_UNIT_MAGIC)
3084 spin_lock_irqsave(&ch->ch_lock, lock_flags);
3091 sleep_on_un_flags = 0;
3094 * If board has failed somehow during our sleep,
3097 if (ch->ch_bd->state == BOARD_FAILED) {
3102 /* If tty was hung up, break out of loop and set error. */
3103 if (tty_hung_up_p(file)) {
3109 * If either unit is in the middle of the fragile part of close,
3110 * we just cannot touch the channel safely.
3111 * Go back to sleep, knowing that when the channel can be
3112 * touched safely, the close routine will signal the
3113 * ch_wait_flags to wake us back up.
3115 if (!((ch->ch_tun.un_flags | ch->ch_pun.un_flags) &
3119 * Our conditions to leave cleanly and happily:
3120 * 1) NONBLOCKING on the tty is set.
3122 * 3) DCD (fake or real) is active.
3125 if (file->f_flags & O_NONBLOCK)
3128 if (tty->flags & (1 << TTY_IO_ERROR))
3131 if (ch->ch_flags & CH_CD)
3134 if (ch->ch_flags & CH_FCAR)
3137 sleep_on_un_flags = 1;
3141 * If there is a signal pending, the user probably
3142 * interrupted (ctrl-c) us.
3143 * Leave loop with error set.
3145 if (signal_pending(current)) {
3146 retval = -ERESTARTSYS;
3151 * Store the flags before we let go of channel lock
3153 if (sleep_on_un_flags)
3154 old_flags = ch->ch_tun.un_flags | ch->ch_pun.un_flags;
3156 old_flags = ch->ch_flags;
3159 * Let go of channel lock before calling schedule.
3160 * Our poller will get any FEP events and wake us up when DCD
3161 * eventually goes active.
3164 spin_unlock_irqrestore(&ch->ch_lock, lock_flags);
3167 * Wait for something in the flags to change
3168 * from the current value.
3170 if (sleep_on_un_flags) {
3171 retval = wait_event_interruptible(un->un_flags_wait,
3172 (old_flags != (ch->ch_tun.un_flags |
3173 ch->ch_pun.un_flags)));
3175 retval = wait_event_interruptible(ch->ch_flags_wait,
3176 (old_flags != ch->ch_flags));
3180 * We got woken up for some reason.
3181 * Before looping around, grab our channel lock.
3183 spin_lock_irqsave(&ch->ch_lock, lock_flags);
3188 spin_unlock_irqrestore(&ch->ch_lock, lock_flags);
3194 * dgap_tty_flush_buffer()
3196 * Flush Tx buffer (make in == out)
3198 static void dgap_tty_flush_buffer(struct tty_struct *tty)
3201 struct channel_t *ch;
3207 if (!tty || tty->magic != TTY_MAGIC)
3210 un = tty->driver_data;
3211 if (!un || un->magic != DGAP_UNIT_MAGIC)
3215 if (!ch || ch->magic != DGAP_CHANNEL_MAGIC)
3219 if (!bd || bd->magic != DGAP_BOARD_MAGIC)
3222 spin_lock_irqsave(&bd->bd_lock, lock_flags);
3223 spin_lock_irqsave(&ch->ch_lock, lock_flags2);
3225 ch->ch_flags &= ~CH_STOP;
3226 head = readw(&(ch->ch_bs->tx_head));
3227 dgap_cmdw(ch, FLUSHTX, (u16) head, 0);
3228 dgap_cmdw(ch, RESUMETX, 0, 0);
3229 if (ch->ch_tun.un_flags & (UN_LOW|UN_EMPTY)) {
3230 ch->ch_tun.un_flags &= ~(UN_LOW|UN_EMPTY);
3231 wake_up_interruptible(&ch->ch_tun.un_flags_wait);
3233 if (ch->ch_pun.un_flags & (UN_LOW|UN_EMPTY)) {
3234 ch->ch_pun.un_flags &= ~(UN_LOW|UN_EMPTY);
3235 wake_up_interruptible(&ch->ch_pun.un_flags_wait);
3238 spin_unlock_irqrestore(&ch->ch_lock, lock_flags2);
3239 spin_unlock_irqrestore(&bd->bd_lock, lock_flags);
3240 if (waitqueue_active(&tty->write_wait))
3241 wake_up_interruptible(&tty->write_wait);
3248 * Hangup the port. Like a close, but don't wait for output to drain.
3250 static void dgap_tty_hangup(struct tty_struct *tty)
3253 struct channel_t *ch;
3256 if (!tty || tty->magic != TTY_MAGIC)
3259 un = tty->driver_data;
3260 if (!un || un->magic != DGAP_UNIT_MAGIC)
3264 if (!ch || ch->magic != DGAP_CHANNEL_MAGIC)
3268 if (!bd || bd->magic != DGAP_BOARD_MAGIC)
3271 /* flush the transmit queues */
3272 dgap_tty_flush_buffer(tty);
3276 * dgap_tty_chars_in_buffer()
3278 * Return number of characters that have not been transmitted yet.
3280 * This routine is used by the line discipline to determine if there
3281 * is data waiting to be transmitted/drained/flushed or not.
3283 static int dgap_tty_chars_in_buffer(struct tty_struct *tty)
3286 struct channel_t *ch;
3288 struct bs_t __iomem *bs;
3291 u16 thead, ttail, tmask, chead, ctail;
3292 ulong lock_flags = 0;
3293 ulong lock_flags2 = 0;
3298 un = tty->driver_data;
3299 if (!un || un->magic != DGAP_UNIT_MAGIC)
3303 if (!ch || ch->magic != DGAP_CHANNEL_MAGIC)
3307 if (!bd || bd->magic != DGAP_BOARD_MAGIC)
3314 spin_lock_irqsave(&bd->bd_lock, lock_flags);
3315 spin_lock_irqsave(&ch->ch_lock, lock_flags2);
3317 tmask = (ch->ch_tsize - 1);
3319 /* Get Transmit queue pointers */
3320 thead = readw(&(bs->tx_head)) & tmask;
3321 ttail = readw(&(bs->tx_tail)) & tmask;
3323 /* Get tbusy flag */
3324 tbusy = readb(&(bs->tbusy));
3326 /* Get Command queue pointers */
3327 chead = readw(&(ch->ch_cm->cm_head));
3328 ctail = readw(&(ch->ch_cm->cm_tail));
3330 spin_unlock_irqrestore(&ch->ch_lock, lock_flags2);
3331 spin_unlock_irqrestore(&bd->bd_lock, lock_flags);
3334 * The only way we know for sure if there is no pending
3335 * data left to be transferred, is if:
3336 * 1) Transmit head and tail are equal (empty).
3337 * 2) Command queue head and tail are equal (empty).
3338 * 3) The "TBUSY" flag is 0. (Transmitter not busy).
3341 if ((ttail == thead) && (tbusy == 0) && (chead == ctail)) {
3345 chars = thead - ttail;
3347 chars = thead - ttail + ch->ch_tsize;
3349 * Fudge factor here.
3350 * If chars is zero, we know that the command queue had
3351 * something in it or tbusy was set. Because we cannot
3352 * be sure if there is still some data to be transmitted,
3353 * lets lie, and tell ld we have 1 byte left.
3357 * If TBUSY is still set, and our tx buffers are empty,
3358 * force the firmware to send me another wakeup after
3359 * TBUSY has been cleared.
3362 spin_lock_irqsave(&ch->ch_lock, lock_flags);
3363 un->un_flags |= UN_EMPTY;
3364 writeb(1, &(bs->iempty));
3365 spin_unlock_irqrestore(&ch->ch_lock,
3375 static int dgap_wait_for_drain(struct tty_struct *tty)
3377 struct channel_t *ch;
3379 struct bs_t __iomem *bs;
3382 ulong lock_flags = 0;
3384 if (!tty || tty->magic != TTY_MAGIC)
3387 un = tty->driver_data;
3388 if (!un || un->magic != DGAP_UNIT_MAGIC)
3392 if (!ch || ch->magic != DGAP_CHANNEL_MAGIC)
3399 /* Loop until data is drained */
3400 while (count != 0) {
3402 count = dgap_tty_chars_in_buffer(tty);
3407 /* Set flag waiting for drain */
3408 spin_lock_irqsave(&ch->ch_lock, lock_flags);
3409 un->un_flags |= UN_EMPTY;
3410 writeb(1, &(bs->iempty));
3411 spin_unlock_irqrestore(&ch->ch_lock, lock_flags);
3413 /* Go to sleep till we get woken up */
3414 ret = wait_event_interruptible(un->un_flags_wait,
3415 ((un->un_flags & UN_EMPTY) == 0));
3416 /* If ret is non-zero, user ctrl-c'ed us */
3421 spin_lock_irqsave(&ch->ch_lock, lock_flags);
3422 un->un_flags &= ~(UN_EMPTY);
3423 spin_unlock_irqrestore(&ch->ch_lock, lock_flags);
3431 * Reduces bytes_available to the max number of characters
3432 * that can be sent currently given the maxcps value, and
3433 * returns the new bytes_available. This only affects printer
3436 static int dgap_maxcps_room(struct channel_t *ch, struct un_t *un,
3437 int bytes_available)
3440 * If its not the Transparent print device, return
3441 * the full data amount.
3443 if (un->un_type != DGAP_PRINT)
3444 return bytes_available;
3446 if (ch->ch_digi.digi_maxcps > 0 && ch->ch_digi.digi_bufsize > 0) {
3448 unsigned long current_time = jiffies;
3449 unsigned long buffer_time = current_time +
3450 (HZ * ch->ch_digi.digi_bufsize) /
3451 ch->ch_digi.digi_maxcps;
3453 if (ch->ch_cpstime < current_time) {
3454 /* buffer is empty */
3455 ch->ch_cpstime = current_time; /* reset ch_cpstime */
3456 cps_limit = ch->ch_digi.digi_bufsize;
3457 } else if (ch->ch_cpstime < buffer_time) {
3458 /* still room in the buffer */
3459 cps_limit = ((buffer_time - ch->ch_cpstime) *
3460 ch->ch_digi.digi_maxcps) / HZ;
3462 /* no room in the buffer */
3466 bytes_available = min(cps_limit, bytes_available);
3469 return bytes_available;
3472 static inline void dgap_set_firmware_event(struct un_t *un, unsigned int event)
3474 struct channel_t *ch;
3475 struct bs_t __iomem *bs;
3477 if (!un || un->magic != DGAP_UNIT_MAGIC)
3480 if (!ch || ch->magic != DGAP_CHANNEL_MAGIC)
3486 if ((event & UN_LOW) != 0) {
3487 if ((un->un_flags & UN_LOW) == 0) {
3488 un->un_flags |= UN_LOW;
3489 writeb(1, &(bs->ilow));
3492 if ((event & UN_LOW) != 0) {
3493 if ((un->un_flags & UN_EMPTY) == 0) {
3494 un->un_flags |= UN_EMPTY;
3495 writeb(1, &(bs->iempty));
3501 * dgap_tty_write_room()
3503 * Return space available in Tx buffer
3505 static int dgap_tty_write_room(struct tty_struct *tty)
3507 struct channel_t *ch;
3509 struct bs_t __iomem *bs;
3510 u16 head, tail, tmask;
3512 ulong lock_flags = 0;
3517 un = tty->driver_data;
3518 if (!un || un->magic != DGAP_UNIT_MAGIC)
3522 if (!ch || ch->magic != DGAP_CHANNEL_MAGIC)
3529 spin_lock_irqsave(&ch->ch_lock, lock_flags);
3531 tmask = ch->ch_tsize - 1;
3532 head = readw(&(bs->tx_head)) & tmask;
3533 tail = readw(&(bs->tx_tail)) & tmask;
3535 ret = tail - head - 1;
3537 ret += ch->ch_tsize;
3539 /* Limit printer to maxcps */
3540 ret = dgap_maxcps_room(ch, un, ret);
3543 * If we are printer device, leave space for
3544 * possibly both the on and off strings.
3546 if (un->un_type == DGAP_PRINT) {
3547 if (!(ch->ch_flags & CH_PRON))
3548 ret -= ch->ch_digi.digi_onlen;
3549 ret -= ch->ch_digi.digi_offlen;
3551 if (ch->ch_flags & CH_PRON)
3552 ret -= ch->ch_digi.digi_offlen;
3559 * Schedule FEP to wake us up if needed.
3561 * TODO: This might be overkill...
3562 * Do we really need to schedule callbacks from the FEP
3563 * in every case? Can we get smarter based on ret?
3565 dgap_set_firmware_event(un, UN_LOW | UN_EMPTY);
3566 spin_unlock_irqrestore(&ch->ch_lock, lock_flags);
3574 * Take data from the user or kernel and send it out to the FEP.
3575 * In here exists all the Transparent Print magic as well.
3577 static int dgap_tty_write(struct tty_struct *tty, const unsigned char *buf,
3580 struct channel_t *ch;
3582 struct bs_t __iomem *bs;
3583 char __iomem *vaddr;
3584 u16 head, tail, tmask, remain;
3591 un = tty->driver_data;
3592 if (!un || un->magic != DGAP_UNIT_MAGIC)
3596 if (!ch || ch->magic != DGAP_CHANNEL_MAGIC)
3606 spin_lock_irqsave(&ch->ch_lock, lock_flags);
3608 /* Get our space available for the channel from the board */
3609 tmask = ch->ch_tsize - 1;
3610 head = readw(&(bs->tx_head)) & tmask;
3611 tail = readw(&(bs->tx_tail)) & tmask;
3613 bufcount = tail - head - 1;
3615 bufcount += ch->ch_tsize;
3618 * Limit printer output to maxcps overall, with bursts allowed
3619 * up to bufsize characters.
3621 bufcount = dgap_maxcps_room(ch, un, bufcount);
3624 * Take minimum of what the user wants to send, and the
3625 * space available in the FEP buffer.
3627 count = min(count, bufcount);
3630 * Bail if no space left.
3633 dgap_set_firmware_event(un, UN_LOW | UN_EMPTY);
3634 spin_unlock_irqrestore(&ch->ch_lock, lock_flags);
3639 * Output the printer ON string, if we are in terminal mode, but
3640 * need to be in printer mode.
3642 if ((un->un_type == DGAP_PRINT) && !(ch->ch_flags & CH_PRON)) {
3643 dgap_wmove(ch, ch->ch_digi.digi_onstr,
3644 (int) ch->ch_digi.digi_onlen);
3645 head = readw(&(bs->tx_head)) & tmask;
3646 ch->ch_flags |= CH_PRON;
3650 * On the other hand, output the printer OFF string, if we are
3651 * currently in printer mode, but need to output to the terminal.
3653 if ((un->un_type != DGAP_PRINT) && (ch->ch_flags & CH_PRON)) {
3654 dgap_wmove(ch, ch->ch_digi.digi_offstr,
3655 (int) ch->ch_digi.digi_offlen);
3656 head = readw(&(bs->tx_head)) & tmask;
3657 ch->ch_flags &= ~CH_PRON;
3663 * If the write wraps over the top of the circular buffer,
3664 * move the portion up to the wrap point, and reset the
3665 * pointers to the bottom.
3667 remain = ch->ch_tstart + ch->ch_tsize - head;
3671 vaddr = ch->ch_taddr + head;
3673 memcpy_toio(vaddr, (u8 *) buf, remain);
3675 head = ch->ch_tstart;
3682 * Move rest of data.
3684 vaddr = ch->ch_taddr + head;
3687 memcpy_toio(vaddr, (u8 *) buf, remain);
3693 ch->ch_txcount += count;
3695 writew(head, &(bs->tx_head));
3698 dgap_set_firmware_event(un, UN_LOW | UN_EMPTY);
3701 * If this is the print device, and the
3702 * printer is still on, we need to turn it
3703 * off before going idle. If the buffer is
3704 * non-empty, wait until it goes empty.
3705 * Otherwise turn it off right now.
3707 if ((un->un_type == DGAP_PRINT) && (ch->ch_flags & CH_PRON)) {
3708 tail = readw(&(bs->tx_tail)) & tmask;
3711 un->un_flags |= UN_EMPTY;
3712 writeb(1, &(bs->iempty));
3714 dgap_wmove(ch, ch->ch_digi.digi_offstr,
3715 (int) ch->ch_digi.digi_offlen);
3716 head = readw(&(bs->tx_head)) & tmask;
3717 ch->ch_flags &= ~CH_PRON;
3721 /* Update printer buffer empty time. */
3722 if ((un->un_type == DGAP_PRINT) && (ch->ch_digi.digi_maxcps > 0)
3723 && (ch->ch_digi.digi_bufsize > 0)) {
3724 ch->ch_cpstime += (HZ * count) / ch->ch_digi.digi_maxcps;
3727 spin_unlock_irqrestore(&ch->ch_lock, lock_flags);
3733 * dgap_tty_put_char()
3735 * Put a character into ch->ch_buf
3737 * - used by the line discipline for OPOST processing
3739 static int dgap_tty_put_char(struct tty_struct *tty, unsigned char c)
3742 * Simply call tty_write.
3744 dgap_tty_write(tty, &c, 1);
3749 * Return modem signals to ld.
3751 static int dgap_tty_tiocmget(struct tty_struct *tty)
3753 struct channel_t *ch;
3759 if (!tty || tty->magic != TTY_MAGIC)
3762 un = tty->driver_data;
3763 if (!un || un->magic != DGAP_UNIT_MAGIC)
3767 if (!ch || ch->magic != DGAP_CHANNEL_MAGIC)
3770 spin_lock_irqsave(&ch->ch_lock, lock_flags);
3772 mstat = readb(&(ch->ch_bs->m_stat));
3773 /* Append any outbound signals that might be pending... */
3774 mstat |= ch->ch_mostat;
3776 spin_unlock_irqrestore(&ch->ch_lock, lock_flags);
3780 if (mstat & D_DTR(ch))
3781 result |= TIOCM_DTR;
3782 if (mstat & D_RTS(ch))
3783 result |= TIOCM_RTS;
3784 if (mstat & D_CTS(ch))
3785 result |= TIOCM_CTS;
3786 if (mstat & D_DSR(ch))
3787 result |= TIOCM_DSR;
3788 if (mstat & D_RI(ch))
3790 if (mstat & D_CD(ch))
3797 * dgap_tty_tiocmset()
3799 * Set modem signals, called by ld.
3801 static int dgap_tty_tiocmset(struct tty_struct *tty,
3802 unsigned int set, unsigned int clear)
3805 struct channel_t *ch;
3810 if (!tty || tty->magic != TTY_MAGIC)
3813 un = tty->driver_data;
3814 if (!un || un->magic != DGAP_UNIT_MAGIC)
3818 if (!ch || ch->magic != DGAP_CHANNEL_MAGIC)
3822 if (!bd || bd->magic != DGAP_BOARD_MAGIC)
3825 spin_lock_irqsave(&bd->bd_lock, lock_flags);
3826 spin_lock_irqsave(&ch->ch_lock, lock_flags2);
3828 if (set & TIOCM_RTS) {
3829 ch->ch_mforce |= D_RTS(ch);
3830 ch->ch_mval |= D_RTS(ch);
3833 if (set & TIOCM_DTR) {
3834 ch->ch_mforce |= D_DTR(ch);
3835 ch->ch_mval |= D_DTR(ch);
3838 if (clear & TIOCM_RTS) {
3839 ch->ch_mforce |= D_RTS(ch);
3840 ch->ch_mval &= ~(D_RTS(ch));
3843 if (clear & TIOCM_DTR) {
3844 ch->ch_mforce |= D_DTR(ch);
3845 ch->ch_mval &= ~(D_DTR(ch));
3848 dgap_param(ch, bd, un->un_type);
3850 spin_unlock_irqrestore(&ch->ch_lock, lock_flags2);
3851 spin_unlock_irqrestore(&bd->bd_lock, lock_flags);
3857 * dgap_tty_send_break()
3859 * Send a Break, called by ld.
3861 static int dgap_tty_send_break(struct tty_struct *tty, int msec)
3864 struct channel_t *ch;
3869 if (!tty || tty->magic != TTY_MAGIC)
3872 un = tty->driver_data;
3873 if (!un || un->magic != DGAP_UNIT_MAGIC)
3877 if (!ch || ch->magic != DGAP_CHANNEL_MAGIC)
3881 if (!bd || bd->magic != DGAP_BOARD_MAGIC)
3896 spin_lock_irqsave(&bd->bd_lock, lock_flags);
3897 spin_lock_irqsave(&ch->ch_lock, lock_flags2);
3899 dgap_cmdw(ch, SBREAK, (u16) SBREAK_TIME, 0);
3901 dgap_cmdw(ch, SBREAK, (u16) msec, 0);
3903 spin_unlock_irqrestore(&ch->ch_lock, lock_flags2);
3904 spin_unlock_irqrestore(&bd->bd_lock, lock_flags);
3910 * dgap_tty_wait_until_sent()
3912 * wait until data has been transmitted, called by ld.
3914 static void dgap_tty_wait_until_sent(struct tty_struct *tty, int timeout)
3916 dgap_wait_for_drain(tty);
3922 * send a high priority character, called by ld.
3924 static void dgap_tty_send_xchar(struct tty_struct *tty, char c)
3927 struct channel_t *ch;
3932 if (!tty || tty->magic != TTY_MAGIC)
3935 un = tty->driver_data;
3936 if (!un || un->magic != DGAP_UNIT_MAGIC)
3940 if (!ch || ch->magic != DGAP_CHANNEL_MAGIC)
3944 if (!bd || bd->magic != DGAP_BOARD_MAGIC)
3947 spin_lock_irqsave(&bd->bd_lock, lock_flags);
3948 spin_lock_irqsave(&ch->ch_lock, lock_flags2);
3951 * This is technically what we should do.
3952 * However, the NIST tests specifically want
3953 * to see each XON or XOFF character that it
3954 * sends, so lets just send each character
3958 if (c == STOP_CHAR(tty))
3959 dgap_cmdw(ch, RPAUSE, 0, 0);
3960 else if (c == START_CHAR(tty))
3961 dgap_cmdw(ch, RRESUME, 0, 0);
3963 dgap_wmove(ch, &c, 1);
3965 dgap_wmove(ch, &c, 1);
3968 spin_unlock_irqrestore(&ch->ch_lock, lock_flags2);
3969 spin_unlock_irqrestore(&bd->bd_lock, lock_flags);
3973 * Return modem signals to ld.
3975 static int dgap_get_modem_info(struct channel_t *ch, unsigned int __user *value)
3981 spin_lock_irqsave(&ch->ch_lock, lock_flags);
3983 mstat = readb(&(ch->ch_bs->m_stat));
3984 /* Append any outbound signals that might be pending... */
3985 mstat |= ch->ch_mostat;
3987 spin_unlock_irqrestore(&ch->ch_lock, lock_flags);
3991 if (mstat & D_DTR(ch))
3992 result |= TIOCM_DTR;
3993 if (mstat & D_RTS(ch))
3994 result |= TIOCM_RTS;
3995 if (mstat & D_CTS(ch))
3996 result |= TIOCM_CTS;
3997 if (mstat & D_DSR(ch))
3998 result |= TIOCM_DSR;
3999 if (mstat & D_RI(ch))
4001 if (mstat & D_CD(ch))
4004 return put_user(result, value);
4008 * dgap_set_modem_info()
4010 * Set modem signals, called by ld.
4012 static int dgap_set_modem_info(struct channel_t *ch, struct board_t *bd,
4013 struct un_t *un, unsigned int command,
4014 unsigned int __user *value)
4021 ret = get_user(arg, value);
4027 if (arg & TIOCM_RTS) {
4028 ch->ch_mforce |= D_RTS(ch);
4029 ch->ch_mval |= D_RTS(ch);
4032 if (arg & TIOCM_DTR) {
4033 ch->ch_mforce |= D_DTR(ch);
4034 ch->ch_mval |= D_DTR(ch);
4040 if (arg & TIOCM_RTS) {
4041 ch->ch_mforce |= D_RTS(ch);
4042 ch->ch_mval &= ~(D_RTS(ch));
4045 if (arg & TIOCM_DTR) {
4046 ch->ch_mforce |= D_DTR(ch);
4047 ch->ch_mval &= ~(D_DTR(ch));
4053 ch->ch_mforce = D_DTR(ch)|D_RTS(ch);
4055 if (arg & TIOCM_RTS)
4056 ch->ch_mval |= D_RTS(ch);
4058 ch->ch_mval &= ~(D_RTS(ch));
4060 if (arg & TIOCM_DTR)
4061 ch->ch_mval |= (D_DTR(ch));
4063 ch->ch_mval &= ~(D_DTR(ch));
4071 spin_lock_irqsave(&bd->bd_lock, lock_flags);
4072 spin_lock_irqsave(&ch->ch_lock, lock_flags2);
4074 dgap_param(ch, bd, un->un_type);
4076 spin_unlock_irqrestore(&ch->ch_lock, lock_flags2);
4077 spin_unlock_irqrestore(&bd->bd_lock, lock_flags);
4083 * dgap_tty_digigeta()
4085 * Ioctl to get the information for ditty.
4090 static int dgap_tty_digigeta(struct channel_t *ch,
4091 struct digi_t __user *retinfo)
4099 memset(&tmp, 0, sizeof(tmp));
4101 spin_lock_irqsave(&ch->ch_lock, lock_flags);
4102 memcpy(&tmp, &ch->ch_digi, sizeof(tmp));
4103 spin_unlock_irqrestore(&ch->ch_lock, lock_flags);
4105 if (copy_to_user(retinfo, &tmp, sizeof(*retinfo)))
4112 * dgap_tty_digiseta()
4114 * Ioctl to set the information for ditty.
4119 static int dgap_tty_digiseta(struct channel_t *ch, struct board_t *bd,
4120 struct un_t *un, struct digi_t __user *new_info)
4122 struct digi_t new_digi;
4123 ulong lock_flags = 0;
4124 unsigned long lock_flags2;
4126 if (copy_from_user(&new_digi, new_info, sizeof(struct digi_t)))
4129 spin_lock_irqsave(&bd->bd_lock, lock_flags);
4130 spin_lock_irqsave(&ch->ch_lock, lock_flags2);
4132 memcpy(&ch->ch_digi, &new_digi, sizeof(struct digi_t));
4134 if (ch->ch_digi.digi_maxcps < 1)
4135 ch->ch_digi.digi_maxcps = 1;
4137 if (ch->ch_digi.digi_maxcps > 10000)
4138 ch->ch_digi.digi_maxcps = 10000;
4140 if (ch->ch_digi.digi_bufsize < 10)
4141 ch->ch_digi.digi_bufsize = 10;
4143 if (ch->ch_digi.digi_maxchar < 1)
4144 ch->ch_digi.digi_maxchar = 1;
4146 if (ch->ch_digi.digi_maxchar > ch->ch_digi.digi_bufsize)
4147 ch->ch_digi.digi_maxchar = ch->ch_digi.digi_bufsize;
4149 if (ch->ch_digi.digi_onlen > DIGI_PLEN)
4150 ch->ch_digi.digi_onlen = DIGI_PLEN;
4152 if (ch->ch_digi.digi_offlen > DIGI_PLEN)
4153 ch->ch_digi.digi_offlen = DIGI_PLEN;
4155 dgap_param(ch, bd, un->un_type);
4157 spin_unlock_irqrestore(&ch->ch_lock, lock_flags2);
4158 spin_unlock_irqrestore(&bd->bd_lock, lock_flags);
4164 * dgap_tty_digigetedelay()
4166 * Ioctl to get the current edelay setting.
4171 static int dgap_tty_digigetedelay(struct tty_struct *tty, int __user *retinfo)
4173 struct channel_t *ch;
4181 if (!tty || tty->magic != TTY_MAGIC)
4184 un = tty->driver_data;
4185 if (!un || un->magic != DGAP_UNIT_MAGIC)
4189 if (!ch || ch->magic != DGAP_CHANNEL_MAGIC)
4192 memset(&tmp, 0, sizeof(tmp));
4194 spin_lock_irqsave(&ch->ch_lock, lock_flags);
4195 tmp = readw(&(ch->ch_bs->edelay));
4196 spin_unlock_irqrestore(&ch->ch_lock, lock_flags);
4198 if (copy_to_user(retinfo, &tmp, sizeof(*retinfo)))
4205 * dgap_tty_digisetedelay()
4207 * Ioctl to set the EDELAY setting
4210 static int dgap_tty_digisetedelay(struct channel_t *ch, struct board_t *bd,
4211 struct un_t *un, int __user *new_info)
4217 if (copy_from_user(&new_digi, new_info, sizeof(int)))
4220 spin_lock_irqsave(&bd->bd_lock, lock_flags);
4221 spin_lock_irqsave(&ch->ch_lock, lock_flags2);
4223 writew((u16) new_digi, &(ch->ch_bs->edelay));
4225 dgap_param(ch, bd, un->un_type);
4227 spin_unlock_irqrestore(&ch->ch_lock, lock_flags2);
4228 spin_unlock_irqrestore(&bd->bd_lock, lock_flags);
4234 * dgap_tty_digigetcustombaud()
4236 * Ioctl to get the current custom baud rate setting.
4238 static int dgap_tty_digigetcustombaud(struct channel_t *ch, struct un_t *un,
4239 int __user *retinfo)
4247 memset(&tmp, 0, sizeof(tmp));
4249 spin_lock_irqsave(&ch->ch_lock, lock_flags);
4250 tmp = dgap_get_custom_baud(ch);
4251 spin_unlock_irqrestore(&ch->ch_lock, lock_flags);
4253 if (copy_to_user(retinfo, &tmp, sizeof(*retinfo)))
4260 * dgap_tty_digisetcustombaud()
4262 * Ioctl to set the custom baud rate setting
4264 static int dgap_tty_digisetcustombaud(struct channel_t *ch, struct board_t *bd,
4265 struct un_t *un, int __user *new_info)
4271 if (copy_from_user(&new_rate, new_info, sizeof(unsigned int)))
4274 if (bd->bd_flags & BD_FEP5PLUS) {
4276 spin_lock_irqsave(&bd->bd_lock, lock_flags);
4277 spin_lock_irqsave(&ch->ch_lock, lock_flags2);
4279 ch->ch_custom_speed = new_rate;
4281 dgap_param(ch, bd, un->un_type);
4283 spin_unlock_irqrestore(&ch->ch_lock, lock_flags2);
4284 spin_unlock_irqrestore(&bd->bd_lock, lock_flags);
4291 * dgap_set_termios()
4293 static void dgap_tty_set_termios(struct tty_struct *tty,
4294 struct ktermios *old_termios)
4297 struct channel_t *ch;
4299 unsigned long lock_flags;
4300 unsigned long lock_flags2;
4302 if (!tty || tty->magic != TTY_MAGIC)
4305 un = tty->driver_data;
4306 if (!un || un->magic != DGAP_UNIT_MAGIC)
4310 if (!ch || ch->magic != DGAP_CHANNEL_MAGIC)
4314 if (!bd || bd->magic != DGAP_BOARD_MAGIC)
4317 spin_lock_irqsave(&bd->bd_lock, lock_flags);
4318 spin_lock_irqsave(&ch->ch_lock, lock_flags2);
4320 ch->ch_c_cflag = tty->termios.c_cflag;
4321 ch->ch_c_iflag = tty->termios.c_iflag;
4322 ch->ch_c_oflag = tty->termios.c_oflag;
4323 ch->ch_c_lflag = tty->termios.c_lflag;
4324 ch->ch_startc = tty->termios.c_cc[VSTART];
4325 ch->ch_stopc = tty->termios.c_cc[VSTOP];
4328 dgap_param(ch, bd, un->un_type);
4330 spin_unlock_irqrestore(&ch->ch_lock, lock_flags2);
4331 spin_unlock_irqrestore(&bd->bd_lock, lock_flags);
4334 static void dgap_tty_throttle(struct tty_struct *tty)
4337 struct channel_t *ch;
4342 if (!tty || tty->magic != TTY_MAGIC)
4345 un = tty->driver_data;
4346 if (!un || un->magic != DGAP_UNIT_MAGIC)
4350 if (!ch || ch->magic != DGAP_CHANNEL_MAGIC)
4354 if (!bd || bd->magic != DGAP_BOARD_MAGIC)
4357 spin_lock_irqsave(&bd->bd_lock, lock_flags);
4358 spin_lock_irqsave(&ch->ch_lock, lock_flags2);
4360 ch->ch_flags |= (CH_RXBLOCK);
4362 dgap_cmdw(ch, RPAUSE, 0, 0);
4365 spin_unlock_irqrestore(&ch->ch_lock, lock_flags2);
4366 spin_unlock_irqrestore(&bd->bd_lock, lock_flags);
4370 static void dgap_tty_unthrottle(struct tty_struct *tty)
4373 struct channel_t *ch;
4378 if (!tty || tty->magic != TTY_MAGIC)
4381 un = tty->driver_data;
4382 if (!un || un->magic != DGAP_UNIT_MAGIC)
4386 if (!ch || ch->magic != DGAP_CHANNEL_MAGIC)
4390 if (!bd || bd->magic != DGAP_BOARD_MAGIC)
4393 spin_lock_irqsave(&bd->bd_lock, lock_flags);
4394 spin_lock_irqsave(&ch->ch_lock, lock_flags2);
4396 ch->ch_flags &= ~(CH_RXBLOCK);
4399 dgap_cmdw(ch, RRESUME, 0, 0);
4402 spin_unlock_irqrestore(&ch->ch_lock, lock_flags2);
4403 spin_unlock_irqrestore(&bd->bd_lock, lock_flags);
4406 static struct board_t *find_board_by_major(unsigned int major)
4410 for (i = 0; i < MAXBOARDS; i++) {
4411 struct board_t *brd = dgap_board[i];
4415 if (major == brd->serial_driver->major ||
4416 major == brd->print_driver->major)
4423 /************************************************************************
4425 * TTY Entry points and helper functions
4427 ************************************************************************/
4433 static int dgap_tty_open(struct tty_struct *tty, struct file *file)
4435 struct board_t *brd;
4436 struct channel_t *ch;
4438 struct bs_t __iomem *bs;
4446 major = MAJOR(tty_devnum(tty));
4447 minor = MINOR(tty_devnum(tty));
4449 brd = find_board_by_major(major);
4454 * If board is not yet up to a state of READY, go to
4455 * sleep waiting for it to happen or they cancel the open.
4457 rc = wait_event_interruptible(brd->state_wait,
4458 (brd->state & BOARD_READY));
4463 spin_lock_irqsave(&brd->bd_lock, lock_flags);
4465 /* The wait above should guarantee this cannot happen */
4466 if (brd->state != BOARD_READY) {
4467 spin_unlock_irqrestore(&brd->bd_lock, lock_flags);
4471 /* If opened device is greater than our number of ports, bail. */
4472 if (MINOR(tty_devnum(tty)) > brd->nasync) {
4473 spin_unlock_irqrestore(&brd->bd_lock, lock_flags);
4477 ch = brd->channels[minor];
4479 spin_unlock_irqrestore(&brd->bd_lock, lock_flags);
4483 /* Grab channel lock */
4484 spin_lock_irqsave(&ch->ch_lock, lock_flags2);
4486 /* Figure out our type */
4487 if (major == brd->serial_driver->major) {
4488 un = &brd->channels[minor]->ch_tun;
4489 un->un_type = DGAP_SERIAL;
4490 } else if (major == brd->print_driver->major) {
4491 un = &brd->channels[minor]->ch_pun;
4492 un->un_type = DGAP_PRINT;
4494 spin_unlock_irqrestore(&ch->ch_lock, lock_flags2);
4495 spin_unlock_irqrestore(&brd->bd_lock, lock_flags);
4499 /* Store our unit into driver_data, so we always have it available. */
4500 tty->driver_data = un;
4503 * Error if channel info pointer is NULL.
4507 spin_unlock_irqrestore(&ch->ch_lock, lock_flags2);
4508 spin_unlock_irqrestore(&brd->bd_lock, lock_flags);
4515 if (!(un->un_flags & UN_ISOPEN)) {
4516 /* Store important variables. */
4519 /* Maybe do something here to the TTY struct as well? */
4523 * Initialize if neither terminal or printer is open.
4525 if (!((ch->ch_tun.un_flags | ch->ch_pun.un_flags) & UN_ISOPEN)) {
4531 * Flush input queue.
4533 head = readw(&(bs->rx_head));
4534 writew(head, &(bs->rx_tail));
4537 ch->pscan_state = 0;
4538 ch->pscan_savechar = 0;
4540 ch->ch_c_cflag = tty->termios.c_cflag;
4541 ch->ch_c_iflag = tty->termios.c_iflag;
4542 ch->ch_c_oflag = tty->termios.c_oflag;
4543 ch->ch_c_lflag = tty->termios.c_lflag;
4544 ch->ch_startc = tty->termios.c_cc[VSTART];
4545 ch->ch_stopc = tty->termios.c_cc[VSTOP];
4547 /* TODO: flush our TTY struct here? */
4552 * Run param in case we changed anything
4554 dgap_param(ch, brd, un->un_type);
4557 * follow protocol for opening port
4560 spin_unlock_irqrestore(&ch->ch_lock, lock_flags2);
4561 spin_unlock_irqrestore(&brd->bd_lock, lock_flags);
4563 rc = dgap_block_til_ready(tty, file, ch);
4568 /* No going back now, increment our unit and channel counters */
4569 spin_lock_irqsave(&ch->ch_lock, lock_flags);
4570 ch->ch_open_count++;
4571 un->un_open_count++;
4572 un->un_flags |= (UN_ISOPEN);
4573 spin_unlock_irqrestore(&ch->ch_lock, lock_flags);
4582 static void dgap_tty_close(struct tty_struct *tty, struct file *file)
4584 struct ktermios *ts;
4586 struct channel_t *ch;
4590 if (!tty || tty->magic != TTY_MAGIC)
4593 un = tty->driver_data;
4594 if (!un || un->magic != DGAP_UNIT_MAGIC)
4598 if (!ch || ch->magic != DGAP_CHANNEL_MAGIC)
4602 if (!bd || bd->magic != DGAP_BOARD_MAGIC)
4607 spin_lock_irqsave(&ch->ch_lock, lock_flags);
4610 * Determine if this is the last close or not - and if we agree about
4611 * which type of close it is with the Line Discipline
4613 if ((tty->count == 1) && (un->un_open_count != 1)) {
4615 * Uh, oh. tty->count is 1, which means that the tty
4616 * structure will be freed. un_open_count should always
4617 * be one in these conditions. If it's greater than
4618 * one, we've got real problems, since it means the
4619 * serial port won't be shutdown.
4621 un->un_open_count = 1;
4624 if (--un->un_open_count < 0)
4625 un->un_open_count = 0;
4627 ch->ch_open_count--;
4629 if (ch->ch_open_count && un->un_open_count) {
4630 spin_unlock_irqrestore(&ch->ch_lock, lock_flags);
4634 /* OK, its the last close on the unit */
4636 un->un_flags |= UN_CLOSING;
4641 * Only officially close channel if count is 0 and
4642 * DIGI_PRINTER bit is not set.
4644 if ((ch->ch_open_count == 0) &&
4645 !(ch->ch_digi.digi_flags & DIGI_PRINTER)) {
4647 ch->ch_flags &= ~(CH_RXBLOCK);
4649 spin_unlock_irqrestore(&ch->ch_lock, lock_flags);
4651 /* wait for output to drain */
4652 /* This will also return if we take an interrupt */
4654 dgap_wait_for_drain(tty);
4656 dgap_tty_flush_buffer(tty);
4657 tty_ldisc_flush(tty);
4659 spin_lock_irqsave(&ch->ch_lock, lock_flags);
4664 * If we have HUPCL set, lower DTR and RTS
4666 if (ch->ch_c_cflag & HUPCL) {
4667 ch->ch_mostat &= ~(D_RTS(ch)|D_DTR(ch));
4668 dgap_cmdb(ch, SMODEM, 0, D_DTR(ch)|D_RTS(ch), 0);
4671 * Go to sleep to ensure RTS/DTR
4672 * have been dropped for modems to see it.
4674 spin_unlock_irqrestore(&ch->ch_lock,
4677 /* .25 second delay for dropping RTS/DTR */
4678 schedule_timeout_interruptible(msecs_to_jiffies(250));
4680 spin_lock_irqsave(&ch->ch_lock, lock_flags);
4683 ch->pscan_state = 0;
4684 ch->pscan_savechar = 0;
4685 ch->ch_baud_info = 0;
4690 * turn off print device when closing print device.
4692 if ((un->un_type == DGAP_PRINT) && (ch->ch_flags & CH_PRON)) {
4693 dgap_wmove(ch, ch->ch_digi.digi_offstr,
4694 (int) ch->ch_digi.digi_offlen);
4695 ch->ch_flags &= ~CH_PRON;
4699 un->un_flags &= ~(UN_ISOPEN | UN_CLOSING);
4700 tty->driver_data = NULL;
4702 wake_up_interruptible(&ch->ch_flags_wait);
4703 wake_up_interruptible(&un->un_flags_wait);
4705 spin_unlock_irqrestore(&ch->ch_lock, lock_flags);
4708 static void dgap_tty_start(struct tty_struct *tty)
4711 struct channel_t *ch;
4716 if (!tty || tty->magic != TTY_MAGIC)
4719 un = tty->driver_data;
4720 if (!un || un->magic != DGAP_UNIT_MAGIC)
4724 if (!ch || ch->magic != DGAP_CHANNEL_MAGIC)
4728 if (!bd || bd->magic != DGAP_BOARD_MAGIC)
4731 spin_lock_irqsave(&bd->bd_lock, lock_flags);
4732 spin_lock_irqsave(&ch->ch_lock, lock_flags2);
4734 dgap_cmdw(ch, RESUMETX, 0, 0);
4736 spin_unlock_irqrestore(&ch->ch_lock, lock_flags2);
4737 spin_unlock_irqrestore(&bd->bd_lock, lock_flags);
4740 static void dgap_tty_stop(struct tty_struct *tty)
4743 struct channel_t *ch;
4748 if (!tty || tty->magic != TTY_MAGIC)
4751 un = tty->driver_data;
4752 if (!un || un->magic != DGAP_UNIT_MAGIC)
4756 if (!ch || ch->magic != DGAP_CHANNEL_MAGIC)
4760 if (!bd || bd->magic != DGAP_BOARD_MAGIC)
4763 spin_lock_irqsave(&bd->bd_lock, lock_flags);
4764 spin_lock_irqsave(&ch->ch_lock, lock_flags2);
4766 dgap_cmdw(ch, PAUSETX, 0, 0);
4768 spin_unlock_irqrestore(&ch->ch_lock, lock_flags2);
4769 spin_unlock_irqrestore(&bd->bd_lock, lock_flags);
4773 * dgap_tty_flush_chars()
4775 * Flush the cook buffer
4777 * Note to self, and any other poor souls who venture here:
4779 * flush in this case DOES NOT mean dispose of the data.
4780 * instead, it means "stop buffering and send it if you
4781 * haven't already." Just guess how I figured that out... SRW 2-Jun-98
4783 * It is also always called in interrupt context - JAR 8-Sept-99
4785 static void dgap_tty_flush_chars(struct tty_struct *tty)
4788 struct channel_t *ch;
4793 if (!tty || tty->magic != TTY_MAGIC)
4796 un = tty->driver_data;
4797 if (!un || un->magic != DGAP_UNIT_MAGIC)
4801 if (!ch || ch->magic != DGAP_CHANNEL_MAGIC)
4805 if (!bd || bd->magic != DGAP_BOARD_MAGIC)
4808 spin_lock_irqsave(&bd->bd_lock, lock_flags);
4809 spin_lock_irqsave(&ch->ch_lock, lock_flags2);
4811 /* TODO: Do something here */
4813 spin_unlock_irqrestore(&ch->ch_lock, lock_flags2);
4814 spin_unlock_irqrestore(&bd->bd_lock, lock_flags);
4817 /*****************************************************************************
4819 * The IOCTL function and all of its helpers
4821 *****************************************************************************/
4826 * The usual assortment of ioctl's
4828 static int dgap_tty_ioctl(struct tty_struct *tty, unsigned int cmd,
4832 struct channel_t *ch;
4836 ulong lock_flags = 0;
4837 ulong lock_flags2 = 0;
4838 void __user *uarg = (void __user *) arg;
4840 if (!tty || tty->magic != TTY_MAGIC)
4843 un = tty->driver_data;
4844 if (!un || un->magic != DGAP_UNIT_MAGIC)
4848 if (!ch || ch->magic != DGAP_CHANNEL_MAGIC)
4852 if (!bd || bd->magic != DGAP_BOARD_MAGIC)
4855 spin_lock_irqsave(&bd->bd_lock, lock_flags);
4856 spin_lock_irqsave(&ch->ch_lock, lock_flags2);
4858 if (un->un_open_count <= 0) {
4859 spin_unlock_irqrestore(&ch->ch_lock, lock_flags2);
4860 spin_unlock_irqrestore(&bd->bd_lock, lock_flags);
4866 /* Here are all the standard ioctl's that we MUST implement */
4870 * TCSBRK is SVID version: non-zero arg --> no break
4871 * this behaviour is exploited by tcdrain().
4873 * According to POSIX.1 spec (7.2.2.1.2) breaks should be
4874 * between 0.25 and 0.5 seconds so we'll ask for something
4875 * in the middle: 0.375 seconds.
4877 rc = tty_check_change(tty);
4878 spin_unlock_irqrestore(&ch->ch_lock, lock_flags2);
4879 spin_unlock_irqrestore(&bd->bd_lock, lock_flags);
4883 rc = dgap_wait_for_drain(tty);
4888 spin_lock_irqsave(&bd->bd_lock, lock_flags);
4889 spin_lock_irqsave(&ch->ch_lock, lock_flags2);
4891 if (((cmd == TCSBRK) && (!arg)) || (cmd == TCSBRKP))
4892 dgap_cmdw(ch, SBREAK, (u16) SBREAK_TIME, 0);
4894 spin_unlock_irqrestore(&ch->ch_lock, lock_flags2);
4895 spin_unlock_irqrestore(&bd->bd_lock, lock_flags);
4900 /* support for POSIX tcsendbreak()
4902 * According to POSIX.1 spec (7.2.2.1.2) breaks should be
4903 * between 0.25 and 0.5 seconds so we'll ask for something
4904 * in the middle: 0.375 seconds.
4906 rc = tty_check_change(tty);
4907 spin_unlock_irqrestore(&ch->ch_lock, lock_flags2);
4908 spin_unlock_irqrestore(&bd->bd_lock, lock_flags);
4912 rc = dgap_wait_for_drain(tty);
4916 spin_lock_irqsave(&bd->bd_lock, lock_flags);
4917 spin_lock_irqsave(&ch->ch_lock, lock_flags2);
4919 dgap_cmdw(ch, SBREAK, (u16) SBREAK_TIME, 0);
4921 spin_unlock_irqrestore(&ch->ch_lock, lock_flags2);
4922 spin_unlock_irqrestore(&bd->bd_lock, lock_flags);
4928 * FEP5 doesn't support turning on a break unconditionally.
4929 * The FEP5 device will stop sending a break automatically
4930 * after the specified time value that was sent when turning on
4933 rc = tty_check_change(tty);
4934 spin_unlock_irqrestore(&ch->ch_lock, lock_flags2);
4935 spin_unlock_irqrestore(&bd->bd_lock, lock_flags);
4939 rc = dgap_wait_for_drain(tty);
4943 spin_lock_irqsave(&bd->bd_lock, lock_flags);
4944 spin_lock_irqsave(&ch->ch_lock, lock_flags2);
4946 dgap_cmdw(ch, SBREAK, (u16) SBREAK_TIME, 0);
4948 spin_unlock_irqrestore(&ch->ch_lock, lock_flags2);
4949 spin_unlock_irqrestore(&bd->bd_lock, lock_flags);
4955 * FEP5 doesn't support turning off a break unconditionally.
4956 * The FEP5 device will stop sending a break automatically
4957 * after the specified time value that was sent when turning on
4960 spin_unlock_irqrestore(&ch->ch_lock, lock_flags2);
4961 spin_unlock_irqrestore(&bd->bd_lock, lock_flags);
4966 spin_unlock_irqrestore(&ch->ch_lock, lock_flags2);
4967 spin_unlock_irqrestore(&bd->bd_lock, lock_flags);
4969 rc = put_user(C_CLOCAL(tty) ? 1 : 0,
4970 (unsigned long __user *) arg);
4974 spin_unlock_irqrestore(&ch->ch_lock, lock_flags2);
4975 spin_unlock_irqrestore(&bd->bd_lock, lock_flags);
4977 rc = get_user(arg, (unsigned long __user *) arg);
4981 spin_lock_irqsave(&bd->bd_lock, lock_flags);
4982 spin_lock_irqsave(&ch->ch_lock, lock_flags2);
4983 tty->termios.c_cflag = ((tty->termios.c_cflag & ~CLOCAL) |
4984 (arg ? CLOCAL : 0));
4985 dgap_param(ch, bd, un->un_type);
4986 spin_unlock_irqrestore(&ch->ch_lock, lock_flags2);
4987 spin_unlock_irqrestore(&bd->bd_lock, lock_flags);
4992 spin_unlock_irqrestore(&ch->ch_lock, lock_flags2);
4993 spin_unlock_irqrestore(&bd->bd_lock, lock_flags);
4994 return dgap_get_modem_info(ch, uarg);
4999 spin_unlock_irqrestore(&ch->ch_lock, lock_flags2);
5000 spin_unlock_irqrestore(&bd->bd_lock, lock_flags);
5001 return dgap_set_modem_info(ch, bd, un, cmd, uarg);
5004 * Here are any additional ioctl's that we want to implement
5009 * The linux tty driver doesn't have a flush
5010 * input routine for the driver, assuming all backed
5011 * up data is in the line disc. buffers. However,
5012 * we all know that's not the case. Here, we
5013 * act on the ioctl, but then lie and say we didn't
5014 * so the line discipline will process the flush
5017 rc = tty_check_change(tty);
5019 spin_unlock_irqrestore(&ch->ch_lock, lock_flags2);
5020 spin_unlock_irqrestore(&bd->bd_lock, lock_flags);
5024 if ((arg == TCIFLUSH) || (arg == TCIOFLUSH)) {
5025 if (!(un->un_type == DGAP_PRINT)) {
5026 head = readw(&(ch->ch_bs->rx_head));
5027 writew(head, &(ch->ch_bs->rx_tail));
5028 writeb(0, &(ch->ch_bs->orun));
5032 if ((arg != TCOFLUSH) && (arg != TCIOFLUSH)) {
5033 /* pretend we didn't recognize this IOCTL */
5034 spin_unlock_irqrestore(&ch->ch_lock, lock_flags2);
5035 spin_unlock_irqrestore(&bd->bd_lock, lock_flags);
5037 return -ENOIOCTLCMD;
5040 ch->ch_flags &= ~CH_STOP;
5041 head = readw(&(ch->ch_bs->tx_head));
5042 dgap_cmdw(ch, FLUSHTX, (u16) head, 0);
5043 dgap_cmdw(ch, RESUMETX, 0, 0);
5044 if (ch->ch_tun.un_flags & (UN_LOW|UN_EMPTY)) {
5045 ch->ch_tun.un_flags &= ~(UN_LOW|UN_EMPTY);
5046 wake_up_interruptible(&ch->ch_tun.un_flags_wait);
5048 if (ch->ch_pun.un_flags & (UN_LOW|UN_EMPTY)) {
5049 ch->ch_pun.un_flags &= ~(UN_LOW|UN_EMPTY);
5050 wake_up_interruptible(&ch->ch_pun.un_flags_wait);
5052 if (waitqueue_active(&tty->write_wait))
5053 wake_up_interruptible(&tty->write_wait);
5055 /* Can't hold any locks when calling tty_wakeup! */
5056 spin_unlock_irqrestore(&ch->ch_lock, lock_flags2);
5057 spin_unlock_irqrestore(&bd->bd_lock, lock_flags);
5060 /* pretend we didn't recognize this IOCTL */
5061 return -ENOIOCTLCMD;
5066 * The linux tty driver doesn't have a flush
5067 * input routine for the driver, assuming all backed
5068 * up data is in the line disc. buffers. However,
5069 * we all know that's not the case. Here, we
5070 * act on the ioctl, but then lie and say we didn't
5071 * so the line discipline will process the flush
5074 if (cmd == TCSETSF) {
5076 ch->ch_flags &= ~CH_STOP;
5077 head = readw(&(ch->ch_bs->rx_head));
5078 writew(head, &(ch->ch_bs->rx_tail));
5081 /* now wait for all the output to drain */
5082 spin_unlock_irqrestore(&ch->ch_lock, lock_flags2);
5083 spin_unlock_irqrestore(&bd->bd_lock, lock_flags);
5084 rc = dgap_wait_for_drain(tty);
5088 /* pretend we didn't recognize this */
5089 return -ENOIOCTLCMD;
5093 spin_unlock_irqrestore(&ch->ch_lock, lock_flags2);
5094 spin_unlock_irqrestore(&bd->bd_lock, lock_flags);
5095 rc = dgap_wait_for_drain(tty);
5099 /* pretend we didn't recognize this */
5100 return -ENOIOCTLCMD;
5104 * The Linux Line Discipline (LD) would do this for us if we
5105 * let it, but we have the special firmware options to do this
5106 * the "right way" regardless of hardware or software flow
5107 * control so we'll do it outselves instead of letting the LD
5110 rc = tty_check_change(tty);
5112 spin_unlock_irqrestore(&ch->ch_lock, lock_flags2);
5113 spin_unlock_irqrestore(&bd->bd_lock, lock_flags);
5120 spin_unlock_irqrestore(&ch->ch_lock, lock_flags2);
5121 spin_unlock_irqrestore(&bd->bd_lock, lock_flags);
5122 dgap_tty_start(tty);
5125 spin_unlock_irqrestore(&ch->ch_lock, lock_flags2);
5126 spin_unlock_irqrestore(&bd->bd_lock, lock_flags);
5130 spin_unlock_irqrestore(&ch->ch_lock, lock_flags2);
5131 spin_unlock_irqrestore(&bd->bd_lock, lock_flags);
5132 /* Make the ld do it */
5133 return -ENOIOCTLCMD;
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);
5146 /* get information for ditty */
5147 spin_unlock_irqrestore(&ch->ch_lock, lock_flags2);
5148 spin_unlock_irqrestore(&bd->bd_lock, lock_flags);
5149 return dgap_tty_digigeta(ch, uarg);
5154 /* set information for ditty */
5155 if (cmd == (DIGI_SETAW)) {
5157 spin_unlock_irqrestore(&ch->ch_lock, lock_flags2);
5158 spin_unlock_irqrestore(&bd->bd_lock, lock_flags);
5159 rc = dgap_wait_for_drain(tty);
5162 spin_lock_irqsave(&bd->bd_lock, lock_flags);
5163 spin_lock_irqsave(&ch->ch_lock, lock_flags2);
5165 tty_ldisc_flush(tty);
5169 spin_unlock_irqrestore(&ch->ch_lock, lock_flags2);
5170 spin_unlock_irqrestore(&bd->bd_lock, lock_flags);
5171 return dgap_tty_digiseta(ch, bd, un, uarg);
5174 spin_unlock_irqrestore(&ch->ch_lock, lock_flags2);
5175 spin_unlock_irqrestore(&bd->bd_lock, lock_flags);
5176 return dgap_tty_digigetedelay(tty, uarg);
5179 spin_unlock_irqrestore(&ch->ch_lock, lock_flags2);
5180 spin_unlock_irqrestore(&bd->bd_lock, lock_flags);
5181 return dgap_tty_digisetedelay(ch, bd, un, uarg);
5183 case DIGI_GETCUSTOMBAUD:
5184 spin_unlock_irqrestore(&ch->ch_lock, lock_flags2);
5185 spin_unlock_irqrestore(&bd->bd_lock, lock_flags);
5186 return dgap_tty_digigetcustombaud(ch, un, uarg);
5188 case DIGI_SETCUSTOMBAUD:
5189 spin_unlock_irqrestore(&ch->ch_lock, lock_flags2);
5190 spin_unlock_irqrestore(&bd->bd_lock, lock_flags);
5191 return dgap_tty_digisetcustombaud(ch, bd, un, uarg);
5193 case DIGI_RESET_PORT:
5194 dgap_firmware_reset_port(ch);
5195 dgap_param(ch, bd, un->un_type);
5196 spin_unlock_irqrestore(&ch->ch_lock, lock_flags2);
5197 spin_unlock_irqrestore(&bd->bd_lock, lock_flags);
5201 spin_unlock_irqrestore(&ch->ch_lock, lock_flags2);
5202 spin_unlock_irqrestore(&bd->bd_lock, lock_flags);
5204 return -ENOIOCTLCMD;
5208 static const struct tty_operations dgap_tty_ops = {
5209 .open = dgap_tty_open,
5210 .close = dgap_tty_close,
5211 .write = dgap_tty_write,
5212 .write_room = dgap_tty_write_room,
5213 .flush_buffer = dgap_tty_flush_buffer,
5214 .chars_in_buffer = dgap_tty_chars_in_buffer,
5215 .flush_chars = dgap_tty_flush_chars,
5216 .ioctl = dgap_tty_ioctl,
5217 .set_termios = dgap_tty_set_termios,
5218 .stop = dgap_tty_stop,
5219 .start = dgap_tty_start,
5220 .throttle = dgap_tty_throttle,
5221 .unthrottle = dgap_tty_unthrottle,
5222 .hangup = dgap_tty_hangup,
5223 .put_char = dgap_tty_put_char,
5224 .tiocmget = dgap_tty_tiocmget,
5225 .tiocmset = dgap_tty_tiocmset,
5226 .break_ctl = dgap_tty_send_break,
5227 .wait_until_sent = dgap_tty_wait_until_sent,
5228 .send_xchar = dgap_tty_send_xchar
5231 /************************************************************************
5233 * TTY Initialization/Cleanup Functions
5235 ************************************************************************/
5238 * dgap_tty_register()
5240 * Init the tty subsystem for this board.
5242 static int dgap_tty_register(struct board_t *brd)
5246 brd->serial_driver = tty_alloc_driver(MAXPORTS,
5247 TTY_DRIVER_REAL_RAW |
5248 TTY_DRIVER_DYNAMIC_DEV |
5249 TTY_DRIVER_HARDWARE_BREAK);
5250 if (IS_ERR(brd->serial_driver))
5251 return PTR_ERR(brd->serial_driver);
5253 snprintf(brd->serial_name, MAXTTYNAMELEN, "tty_dgap_%d_",
5255 brd->serial_driver->name = brd->serial_name;
5256 brd->serial_driver->name_base = 0;
5257 brd->serial_driver->major = 0;
5258 brd->serial_driver->minor_start = 0;
5259 brd->serial_driver->type = TTY_DRIVER_TYPE_SERIAL;
5260 brd->serial_driver->subtype = SERIAL_TYPE_NORMAL;
5261 brd->serial_driver->init_termios = dgap_default_termios;
5262 brd->serial_driver->driver_name = DRVSTR;
5265 * Entry points for driver. Called by the kernel from
5266 * tty_io.c and n_tty.c.
5268 tty_set_operations(brd->serial_driver, &dgap_tty_ops);
5271 * If we're doing transparent print, we have to do all of the above
5272 * again, separately so we don't get the LD confused about what major
5273 * we are when we get into the dgap_tty_open() routine.
5275 brd->print_driver = tty_alloc_driver(MAXPORTS,
5276 TTY_DRIVER_REAL_RAW |
5277 TTY_DRIVER_DYNAMIC_DEV |
5278 TTY_DRIVER_HARDWARE_BREAK);
5279 if (IS_ERR(brd->print_driver)) {
5280 rc = PTR_ERR(brd->print_driver);
5281 goto free_serial_drv;
5284 snprintf(brd->print_name, MAXTTYNAMELEN, "pr_dgap_%d_",
5286 brd->print_driver->name = brd->print_name;
5287 brd->print_driver->name_base = 0;
5288 brd->print_driver->major = 0;
5289 brd->print_driver->minor_start = 0;
5290 brd->print_driver->type = TTY_DRIVER_TYPE_SERIAL;
5291 brd->print_driver->subtype = SERIAL_TYPE_NORMAL;
5292 brd->print_driver->init_termios = dgap_default_termios;
5293 brd->print_driver->driver_name = DRVSTR;
5296 * Entry points for driver. Called by the kernel from
5297 * tty_io.c and n_tty.c.
5299 tty_set_operations(brd->print_driver, &dgap_tty_ops);
5301 /* Register tty devices */
5302 rc = tty_register_driver(brd->serial_driver);
5304 goto free_print_drv;
5306 /* Register Transparent Print devices */
5307 rc = tty_register_driver(brd->print_driver);
5309 goto unregister_serial_drv;
5313 unregister_serial_drv:
5314 tty_unregister_driver(brd->serial_driver);
5316 put_tty_driver(brd->print_driver);
5318 put_tty_driver(brd->serial_driver);
5323 static void dgap_tty_unregister(struct board_t *brd)
5325 tty_unregister_driver(brd->print_driver);
5326 tty_unregister_driver(brd->serial_driver);
5327 put_tty_driver(brd->print_driver);
5328 put_tty_driver(brd->serial_driver);
5331 static int dgap_alloc_flipbuf(struct board_t *brd)
5334 * allocate flip buffer for board.
5336 brd->flipbuf = kmalloc(MYFLIPLEN, GFP_KERNEL);
5340 brd->flipflagbuf = kmalloc(MYFLIPLEN, GFP_KERNEL);
5341 if (!brd->flipflagbuf) {
5342 kfree(brd->flipbuf);
5349 static void dgap_free_flipbuf(struct board_t *brd)
5351 kfree(brd->flipbuf);
5352 kfree(brd->flipflagbuf);
5355 static struct board_t *dgap_verify_board(struct device *p)
5362 bd = dev_get_drvdata(p);
5363 if (!bd || bd->magic != DGAP_BOARD_MAGIC || bd->state != BOARD_READY)
5369 static ssize_t dgap_ports_state_show(struct device *p,
5370 struct device_attribute *attr,
5377 bd = dgap_verify_board(p);
5381 for (i = 0; i < bd->nasync; i++) {
5382 count += snprintf(buf + count, PAGE_SIZE - count,
5383 "%d %s\n", bd->channels[i]->ch_portnum,
5384 bd->channels[i]->ch_open_count ? "Open" : "Closed");
5388 static DEVICE_ATTR(ports_state, S_IRUSR, dgap_ports_state_show, NULL);
5390 static ssize_t dgap_ports_baud_show(struct device *p,
5391 struct device_attribute *attr,
5398 bd = dgap_verify_board(p);
5402 for (i = 0; i < bd->nasync; i++) {
5403 count += snprintf(buf + count, PAGE_SIZE - count, "%d %d\n",
5404 bd->channels[i]->ch_portnum,
5405 bd->channels[i]->ch_baud_info);
5409 static DEVICE_ATTR(ports_baud, S_IRUSR, dgap_ports_baud_show, NULL);
5411 static ssize_t dgap_ports_msignals_show(struct device *p,
5412 struct device_attribute *attr,
5419 bd = dgap_verify_board(p);
5423 for (i = 0; i < bd->nasync; i++) {
5424 if (bd->channels[i]->ch_open_count)
5425 count += snprintf(buf + count, PAGE_SIZE - count,
5426 "%d %s %s %s %s %s %s\n",
5427 bd->channels[i]->ch_portnum,
5428 (bd->channels[i]->ch_mostat &
5429 UART_MCR_RTS) ? "RTS" : "",
5430 (bd->channels[i]->ch_mistat &
5431 UART_MSR_CTS) ? "CTS" : "",
5432 (bd->channels[i]->ch_mostat &
5433 UART_MCR_DTR) ? "DTR" : "",
5434 (bd->channels[i]->ch_mistat &
5435 UART_MSR_DSR) ? "DSR" : "",
5436 (bd->channels[i]->ch_mistat &
5437 UART_MSR_DCD) ? "DCD" : "",
5438 (bd->channels[i]->ch_mistat &
5439 UART_MSR_RI) ? "RI" : "");
5441 count += snprintf(buf + count, PAGE_SIZE - count,
5442 "%d\n", bd->channels[i]->ch_portnum);
5446 static DEVICE_ATTR(ports_msignals, S_IRUSR, dgap_ports_msignals_show, NULL);
5448 static ssize_t dgap_ports_iflag_show(struct device *p,
5449 struct device_attribute *attr,
5456 bd = dgap_verify_board(p);
5460 for (i = 0; i < bd->nasync; i++)
5461 count += snprintf(buf + count, PAGE_SIZE - count, "%d %x\n",
5462 bd->channels[i]->ch_portnum,
5463 bd->channels[i]->ch_c_iflag);
5466 static DEVICE_ATTR(ports_iflag, S_IRUSR, dgap_ports_iflag_show, NULL);
5468 static ssize_t dgap_ports_cflag_show(struct device *p,
5469 struct device_attribute *attr,
5476 bd = dgap_verify_board(p);
5480 for (i = 0; i < bd->nasync; i++)
5481 count += snprintf(buf + count, PAGE_SIZE - count, "%d %x\n",
5482 bd->channels[i]->ch_portnum,
5483 bd->channels[i]->ch_c_cflag);
5486 static DEVICE_ATTR(ports_cflag, S_IRUSR, dgap_ports_cflag_show, NULL);
5488 static ssize_t dgap_ports_oflag_show(struct device *p,
5489 struct device_attribute *attr,
5496 bd = dgap_verify_board(p);
5500 for (i = 0; i < bd->nasync; i++)
5501 count += snprintf(buf + count, PAGE_SIZE - count, "%d %x\n",
5502 bd->channels[i]->ch_portnum,
5503 bd->channels[i]->ch_c_oflag);
5506 static DEVICE_ATTR(ports_oflag, S_IRUSR, dgap_ports_oflag_show, NULL);
5508 static ssize_t dgap_ports_lflag_show(struct device *p,
5509 struct device_attribute *attr,
5516 bd = dgap_verify_board(p);
5520 for (i = 0; i < bd->nasync; i++)
5521 count += snprintf(buf + count, PAGE_SIZE - count, "%d %x\n",
5522 bd->channels[i]->ch_portnum,
5523 bd->channels[i]->ch_c_lflag);
5526 static DEVICE_ATTR(ports_lflag, S_IRUSR, dgap_ports_lflag_show, NULL);
5528 static ssize_t dgap_ports_digi_flag_show(struct device *p,
5529 struct device_attribute *attr,
5536 bd = dgap_verify_board(p);
5540 for (i = 0; i < bd->nasync; i++)
5541 count += snprintf(buf + count, PAGE_SIZE - count, "%d %x\n",
5542 bd->channels[i]->ch_portnum,
5543 bd->channels[i]->ch_digi.digi_flags);
5546 static DEVICE_ATTR(ports_digi_flag, S_IRUSR, dgap_ports_digi_flag_show, NULL);
5548 static ssize_t dgap_ports_rxcount_show(struct device *p,
5549 struct device_attribute *attr,
5556 bd = dgap_verify_board(p);
5560 for (i = 0; i < bd->nasync; i++)
5561 count += snprintf(buf + count, PAGE_SIZE - count, "%d %ld\n",
5562 bd->channels[i]->ch_portnum,
5563 bd->channels[i]->ch_rxcount);
5566 static DEVICE_ATTR(ports_rxcount, S_IRUSR, dgap_ports_rxcount_show, NULL);
5568 static ssize_t dgap_ports_txcount_show(struct device *p,
5569 struct device_attribute *attr,
5576 bd = dgap_verify_board(p);
5580 for (i = 0; i < bd->nasync; i++)
5581 count += snprintf(buf + count, PAGE_SIZE - count, "%d %ld\n",
5582 bd->channels[i]->ch_portnum,
5583 bd->channels[i]->ch_txcount);
5586 static DEVICE_ATTR(ports_txcount, S_IRUSR, dgap_ports_txcount_show, NULL);
5588 static ssize_t dgap_tty_state_show(struct device *d,
5589 struct device_attribute *attr,
5593 struct channel_t *ch;
5598 un = dev_get_drvdata(d);
5599 if (!un || un->magic != DGAP_UNIT_MAGIC)
5602 if (!ch || ch->magic != DGAP_CHANNEL_MAGIC)
5605 if (!bd || bd->magic != DGAP_BOARD_MAGIC)
5607 if (bd->state != BOARD_READY)
5610 return snprintf(buf, PAGE_SIZE, "%s", un->un_open_count ?
5613 static DEVICE_ATTR(state, S_IRUSR, dgap_tty_state_show, NULL);
5615 static ssize_t dgap_tty_baud_show(struct device *d,
5616 struct device_attribute *attr,
5620 struct channel_t *ch;
5625 un = dev_get_drvdata(d);
5626 if (!un || un->magic != DGAP_UNIT_MAGIC)
5629 if (!ch || ch->magic != DGAP_CHANNEL_MAGIC)
5632 if (!bd || bd->magic != DGAP_BOARD_MAGIC)
5634 if (bd->state != BOARD_READY)
5637 return snprintf(buf, PAGE_SIZE, "%d\n", ch->ch_baud_info);
5639 static DEVICE_ATTR(baud, S_IRUSR, dgap_tty_baud_show, NULL);
5641 static ssize_t dgap_tty_msignals_show(struct device *d,
5642 struct device_attribute *attr,
5646 struct channel_t *ch;
5651 un = dev_get_drvdata(d);
5652 if (!un || un->magic != DGAP_UNIT_MAGIC)
5655 if (!ch || ch->magic != DGAP_CHANNEL_MAGIC)
5658 if (!bd || bd->magic != DGAP_BOARD_MAGIC)
5660 if (bd->state != BOARD_READY)
5663 if (ch->ch_open_count) {
5664 return snprintf(buf, PAGE_SIZE, "%s %s %s %s %s %s\n",
5665 (ch->ch_mostat & UART_MCR_RTS) ? "RTS" : "",
5666 (ch->ch_mistat & UART_MSR_CTS) ? "CTS" : "",
5667 (ch->ch_mostat & UART_MCR_DTR) ? "DTR" : "",
5668 (ch->ch_mistat & UART_MSR_DSR) ? "DSR" : "",
5669 (ch->ch_mistat & UART_MSR_DCD) ? "DCD" : "",
5670 (ch->ch_mistat & UART_MSR_RI) ? "RI" : "");
5674 static DEVICE_ATTR(msignals, S_IRUSR, dgap_tty_msignals_show, NULL);
5676 static ssize_t dgap_tty_iflag_show(struct device *d,
5677 struct device_attribute *attr,
5681 struct channel_t *ch;
5686 un = dev_get_drvdata(d);
5687 if (!un || un->magic != DGAP_UNIT_MAGIC)
5690 if (!ch || ch->magic != DGAP_CHANNEL_MAGIC)
5693 if (!bd || bd->magic != DGAP_BOARD_MAGIC)
5695 if (bd->state != BOARD_READY)
5698 return snprintf(buf, PAGE_SIZE, "%x\n", ch->ch_c_iflag);
5700 static DEVICE_ATTR(iflag, S_IRUSR, dgap_tty_iflag_show, NULL);
5702 static ssize_t dgap_tty_cflag_show(struct device *d,
5703 struct device_attribute *attr,
5707 struct channel_t *ch;
5712 un = dev_get_drvdata(d);
5713 if (!un || un->magic != DGAP_UNIT_MAGIC)
5716 if (!ch || ch->magic != DGAP_CHANNEL_MAGIC)
5719 if (!bd || bd->magic != DGAP_BOARD_MAGIC)
5721 if (bd->state != BOARD_READY)
5724 return snprintf(buf, PAGE_SIZE, "%x\n", ch->ch_c_cflag);
5726 static DEVICE_ATTR(cflag, S_IRUSR, dgap_tty_cflag_show, NULL);
5728 static ssize_t dgap_tty_oflag_show(struct device *d,
5729 struct device_attribute *attr,
5733 struct channel_t *ch;
5738 un = dev_get_drvdata(d);
5739 if (!un || un->magic != DGAP_UNIT_MAGIC)
5742 if (!ch || ch->magic != DGAP_CHANNEL_MAGIC)
5745 if (!bd || bd->magic != DGAP_BOARD_MAGIC)
5747 if (bd->state != BOARD_READY)
5750 return snprintf(buf, PAGE_SIZE, "%x\n", ch->ch_c_oflag);
5752 static DEVICE_ATTR(oflag, S_IRUSR, dgap_tty_oflag_show, NULL);
5754 static ssize_t dgap_tty_lflag_show(struct device *d,
5755 struct device_attribute *attr,
5759 struct channel_t *ch;
5764 un = dev_get_drvdata(d);
5765 if (!un || un->magic != DGAP_UNIT_MAGIC)
5768 if (!ch || ch->magic != DGAP_CHANNEL_MAGIC)
5771 if (!bd || bd->magic != DGAP_BOARD_MAGIC)
5773 if (bd->state != BOARD_READY)
5776 return snprintf(buf, PAGE_SIZE, "%x\n", ch->ch_c_lflag);
5778 static DEVICE_ATTR(lflag, S_IRUSR, dgap_tty_lflag_show, NULL);
5780 static ssize_t dgap_tty_digi_flag_show(struct device *d,
5781 struct device_attribute *attr,
5785 struct channel_t *ch;
5790 un = dev_get_drvdata(d);
5791 if (!un || un->magic != DGAP_UNIT_MAGIC)
5794 if (!ch || ch->magic != DGAP_CHANNEL_MAGIC)
5797 if (!bd || bd->magic != DGAP_BOARD_MAGIC)
5799 if (bd->state != BOARD_READY)
5802 return snprintf(buf, PAGE_SIZE, "%x\n", ch->ch_digi.digi_flags);
5804 static DEVICE_ATTR(digi_flag, S_IRUSR, dgap_tty_digi_flag_show, NULL);
5806 static ssize_t dgap_tty_rxcount_show(struct device *d,
5807 struct device_attribute *attr,
5811 struct channel_t *ch;
5816 un = dev_get_drvdata(d);
5817 if (!un || un->magic != DGAP_UNIT_MAGIC)
5820 if (!ch || ch->magic != DGAP_CHANNEL_MAGIC)
5823 if (!bd || bd->magic != DGAP_BOARD_MAGIC)
5825 if (bd->state != BOARD_READY)
5828 return snprintf(buf, PAGE_SIZE, "%ld\n", ch->ch_rxcount);
5830 static DEVICE_ATTR(rxcount, S_IRUSR, dgap_tty_rxcount_show, NULL);
5832 static ssize_t dgap_tty_txcount_show(struct device *d,
5833 struct device_attribute *attr,
5837 struct channel_t *ch;
5842 un = dev_get_drvdata(d);
5843 if (!un || un->magic != DGAP_UNIT_MAGIC)
5846 if (!ch || ch->magic != DGAP_CHANNEL_MAGIC)
5849 if (!bd || bd->magic != DGAP_BOARD_MAGIC)
5851 if (bd->state != BOARD_READY)
5854 return snprintf(buf, PAGE_SIZE, "%ld\n", ch->ch_txcount);
5856 static DEVICE_ATTR(txcount, S_IRUSR, dgap_tty_txcount_show, NULL);
5858 static ssize_t dgap_tty_name_show(struct device *d,
5859 struct device_attribute *attr,
5863 struct channel_t *ch;
5875 un = dev_get_drvdata(d);
5876 if (!un || un->magic != DGAP_UNIT_MAGIC)
5879 if (!ch || ch->magic != DGAP_CHANNEL_MAGIC)
5882 if (!bd || bd->magic != DGAP_BOARD_MAGIC)
5884 if (bd->state != BOARD_READY)
5888 cn = ch->ch_portnum;
5890 for (cptr = bd->bd_config; cptr; cptr = cptr->next) {
5892 if ((cptr->type == BNODE) &&
5893 ((cptr->u.board.type == APORT2_920P) ||
5894 (cptr->u.board.type == APORT4_920P) ||
5895 (cptr->u.board.type == APORT8_920P) ||
5896 (cptr->u.board.type == PAPORT4) ||
5897 (cptr->u.board.type == PAPORT8))) {
5900 if (cptr->u.board.v_start)
5901 starto = cptr->u.board.start;
5906 if (cptr->type == TNODE && found == TRUE) {
5909 if (strstr(cptr->u.ttyname, "tty")) {
5910 ptr1 = cptr->u.ttyname;
5913 ptr1 = cptr->u.ttyname;
5915 for (i = 0; i < dgap_config_get_num_prts(bd); i++) {
5919 return snprintf(buf, PAGE_SIZE, "%s%s%02d\n",
5920 (un->un_type == DGAP_PRINT) ?
5926 if (cptr->type == CNODE) {
5928 for (i = 0; i < cptr->u.conc.nport; i++) {
5929 if (cn != (i + ncount))
5932 return snprintf(buf, PAGE_SIZE, "%s%s%02ld\n",
5933 (un->un_type == DGAP_PRINT) ?
5936 i + (cptr->u.conc.v_start ?
5937 cptr->u.conc.start : 1));
5940 ncount += cptr->u.conc.nport;
5943 if (cptr->type == MNODE) {
5945 for (i = 0; i < cptr->u.module.nport; i++) {
5946 if (cn != (i + ncount))
5949 return snprintf(buf, PAGE_SIZE, "%s%s%02ld\n",
5950 (un->un_type == DGAP_PRINT) ?
5953 i + (cptr->u.module.v_start ?
5954 cptr->u.module.start : 1));
5957 ncount += cptr->u.module.nport;
5961 return snprintf(buf, PAGE_SIZE, "%s_dgap_%d_%d\n",
5962 (un->un_type == DGAP_PRINT) ? "pr" : "tty", bn, cn);
5964 static DEVICE_ATTR(custom_name, S_IRUSR, dgap_tty_name_show, NULL);
5966 static struct attribute *dgap_sysfs_tty_entries[] = {
5967 &dev_attr_state.attr,
5968 &dev_attr_baud.attr,
5969 &dev_attr_msignals.attr,
5970 &dev_attr_iflag.attr,
5971 &dev_attr_cflag.attr,
5972 &dev_attr_oflag.attr,
5973 &dev_attr_lflag.attr,
5974 &dev_attr_digi_flag.attr,
5975 &dev_attr_rxcount.attr,
5976 &dev_attr_txcount.attr,
5977 &dev_attr_custom_name.attr,
5982 /* this function creates the sys files that will export each signal status
5983 * to sysfs each value will be put in a separate filename
5985 static void dgap_create_ports_sysfiles(struct board_t *bd)
5987 dev_set_drvdata(&bd->pdev->dev, bd);
5988 device_create_file(&(bd->pdev->dev), &dev_attr_ports_state);
5989 device_create_file(&(bd->pdev->dev), &dev_attr_ports_baud);
5990 device_create_file(&(bd->pdev->dev), &dev_attr_ports_msignals);
5991 device_create_file(&(bd->pdev->dev), &dev_attr_ports_iflag);
5992 device_create_file(&(bd->pdev->dev), &dev_attr_ports_cflag);
5993 device_create_file(&(bd->pdev->dev), &dev_attr_ports_oflag);
5994 device_create_file(&(bd->pdev->dev), &dev_attr_ports_lflag);
5995 device_create_file(&(bd->pdev->dev), &dev_attr_ports_digi_flag);
5996 device_create_file(&(bd->pdev->dev), &dev_attr_ports_rxcount);
5997 device_create_file(&(bd->pdev->dev), &dev_attr_ports_txcount);
6000 /* removes all the sys files created for that port */
6001 static void dgap_remove_ports_sysfiles(struct board_t *bd)
6003 device_remove_file(&(bd->pdev->dev), &dev_attr_ports_state);
6004 device_remove_file(&(bd->pdev->dev), &dev_attr_ports_baud);
6005 device_remove_file(&(bd->pdev->dev), &dev_attr_ports_msignals);
6006 device_remove_file(&(bd->pdev->dev), &dev_attr_ports_iflag);
6007 device_remove_file(&(bd->pdev->dev), &dev_attr_ports_cflag);
6008 device_remove_file(&(bd->pdev->dev), &dev_attr_ports_oflag);
6009 device_remove_file(&(bd->pdev->dev), &dev_attr_ports_lflag);
6010 device_remove_file(&(bd->pdev->dev), &dev_attr_ports_digi_flag);
6011 device_remove_file(&(bd->pdev->dev), &dev_attr_ports_rxcount);
6012 device_remove_file(&(bd->pdev->dev), &dev_attr_ports_txcount);
6016 * Copies the BIOS code from the user to the board,
6017 * and starts the BIOS running.
6019 static void dgap_do_bios_load(struct board_t *brd, const u8 *ubios, int len)
6025 if (!brd || (brd->magic != DGAP_BOARD_MAGIC) || !brd->re_map_membase)
6028 addr = brd->re_map_membase;
6033 for (i = 0; i < 16; i++)
6034 writeb(0, addr + POSTAREA + i);
6040 memcpy_toio(addr + offset, ubios, len);
6042 writel(0x0bf00401, addr);
6043 writel(0, (addr + 4));
6045 /* Clear the reset, and change states. */
6046 writeb(FEPCLR, brd->re_map_port);
6050 * Checks to see if the BIOS completed running on the card.
6052 static int dgap_test_bios(struct board_t *brd)
6059 if (!brd || (brd->magic != DGAP_BOARD_MAGIC) || !brd->re_map_membase)
6062 addr = brd->re_map_membase;
6063 word = readw(addr + POSTAREA);
6066 * It can take 5-6 seconds for a board to
6067 * pass the bios self test and post results.
6068 * Give it 10 seconds.
6070 brd->wait_for_bios = 0;
6071 while (brd->wait_for_bios < 1000) {
6072 /* Check to see if BIOS thinks board is good. (GD). */
6073 if (word == *(u16 *) "GD")
6075 msleep_interruptible(10);
6076 brd->wait_for_bios++;
6077 word = readw(addr + POSTAREA);
6080 /* Gave up on board after too long of time taken */
6081 err1 = readw(addr + SEQUENCE);
6082 err2 = readw(addr + ERROR);
6083 dev_warn(&brd->pdev->dev, "%s failed diagnostics. Error #(%x,%x).\n",
6084 brd->name, err1, err2);
6085 brd->state = BOARD_FAILED;
6086 brd->dpastatus = BD_NOBIOS;
6092 * Copies the FEP code from the user to the board,
6093 * and starts the FEP running.
6095 static void dgap_do_fep_load(struct board_t *brd, const u8 *ufep, int len)
6100 if (!brd || (brd->magic != DGAP_BOARD_MAGIC) || !brd->re_map_membase)
6103 addr = brd->re_map_membase;
6109 memcpy_toio(addr + offset, ufep, len);
6112 * If board is a concentrator product, we need to give
6113 * it its config string describing how the concentrators look.
6115 if ((brd->type == PCX) || (brd->type == PEPC)) {
6121 xconfig = dgap_create_config_string(brd, string);
6123 /* Write string to board memory */
6124 config = addr + CONFIG;
6125 for (; i < CONFIGSIZE; i++, config++, xconfig++) {
6126 writeb(*xconfig, config);
6127 if ((*xconfig & 0xff) == 0xff)
6132 writel(0xbfc01004, (addr + 0xc34));
6133 writel(0x3, (addr + 0xc30));
6138 * Waits for the FEP to report thats its ready for us to use.
6140 static int dgap_test_fep(struct board_t *brd)
6147 if (!brd || (brd->magic != DGAP_BOARD_MAGIC) || !brd->re_map_membase)
6150 addr = brd->re_map_membase;
6151 word = readw(addr + FEPSTAT);
6154 * It can take 2-3 seconds for the FEP to
6155 * be up and running. Give it 5 secs.
6157 brd->wait_for_fep = 0;
6158 while (brd->wait_for_fep < 500) {
6159 /* Check to see if FEP is up and running now. */
6160 if (word == *(u16 *) "OS") {
6162 * Check to see if the board can support FEP5+ commands.
6164 word = readw(addr + FEP5_PLUS);
6165 if (word == *(u16 *) "5A")
6166 brd->bd_flags |= BD_FEP5PLUS;
6170 msleep_interruptible(10);
6171 brd->wait_for_fep++;
6172 word = readw(addr + FEPSTAT);
6175 /* Gave up on board after too long of time taken */
6176 err1 = readw(addr + SEQUENCE);
6177 err2 = readw(addr + ERROR);
6178 dev_warn(&brd->pdev->dev,
6179 "FEPOS for %s not functioning. Error #(%x,%x).\n",
6180 brd->name, err1, err2);
6181 brd->state = BOARD_FAILED;
6182 brd->dpastatus = BD_NOFEP;
6188 * Physically forces the FEP5 card to reset itself.
6190 static void dgap_do_reset_board(struct board_t *brd)
6197 if (!brd || (brd->magic != DGAP_BOARD_MAGIC) ||
6198 !brd->re_map_membase || !brd->re_map_port)
6201 /* FEPRST does not vary among supported boards */
6202 writeb(FEPRST, brd->re_map_port);
6204 for (i = 0; i <= 1000; i++) {
6205 check = readb(brd->re_map_port) & 0xe;
6206 if (check == FEPRST)
6212 dev_warn(&brd->pdev->dev,
6213 "dgap: Board not resetting... Failing board.\n");
6214 brd->state = BOARD_FAILED;
6215 brd->dpastatus = BD_NOFEP;
6220 * Make sure there really is memory out there.
6222 writel(0xa55a3cc3, (brd->re_map_membase + LOWMEM));
6223 writel(0x5aa5c33c, (brd->re_map_membase + HIGHMEM));
6224 check1 = readl(brd->re_map_membase + LOWMEM);
6225 check2 = readl(brd->re_map_membase + HIGHMEM);
6227 if ((check1 != 0xa55a3cc3) || (check2 != 0x5aa5c33c)) {
6228 dev_warn(&brd->pdev->dev,
6229 "No memory at %p for board.\n",
6230 brd->re_map_membase);
6231 brd->state = BOARD_FAILED;
6232 brd->dpastatus = BD_NOFEP;
6237 #ifdef DIGI_CONCENTRATORS_SUPPORTED
6239 * Sends a concentrator image into the FEP5 board.
6241 static void dgap_do_conc_load(struct board_t *brd, u8 *uaddr, int len)
6243 char __iomem *vaddr;
6245 struct downld_t *to_dp;
6247 if (!brd || (brd->magic != DGAP_BOARD_MAGIC) || !brd->re_map_membase)
6250 vaddr = brd->re_map_membase;
6252 offset = readw((u16 *) (vaddr + DOWNREQ));
6253 to_dp = (struct downld_t *) (vaddr + (int) offset);
6254 memcpy_toio(to_dp, uaddr, len);
6256 /* Tell card we have data for it */
6257 writew(0, vaddr + (DOWNREQ));
6259 brd->conc_dl_status = NO_PENDING_CONCENTRATOR_REQUESTS;
6263 #define EXPANSION_ROM_SIZE (64 * 1024)
6264 #define FEP5_ROM_MAGIC (0xFEFFFFFF)
6266 static void dgap_get_vpd(struct board_t *brd)
6278 * Poke the magic number at the PCI Rom Address location.
6279 * If VPD is supported, the value read from that address
6282 magic = FEP5_ROM_MAGIC;
6283 pci_write_config_dword(brd->pdev, PCI_ROM_ADDRESS, magic);
6284 pci_read_config_dword(brd->pdev, PCI_ROM_ADDRESS, &magic);
6286 /* VPD not supported, bail */
6291 * To get to the OTPROM memory, we have to send the boards base
6292 * address or'ed with 1 into the PCI Rom Address location.
6294 magic = brd->membase | 0x01;
6295 pci_write_config_dword(brd->pdev, PCI_ROM_ADDRESS, magic);
6296 pci_read_config_dword(brd->pdev, PCI_ROM_ADDRESS, &magic);
6298 byte1 = readb(brd->re_map_membase);
6299 byte2 = readb(brd->re_map_membase + 1);
6302 * If the board correctly swapped to the OTPROM memory,
6303 * the first 2 bytes (header) should be 0x55, 0xAA
6305 if (byte1 == 0x55 && byte2 == 0xAA) {
6310 * We have to run through all the OTPROM memory looking
6311 * for the VPD offset.
6313 while (base_offset <= EXPANSION_ROM_SIZE) {
6316 * Lots of magic numbers here.
6318 * The VPD offset is located inside the ROM Data
6321 * We also have to remember the length of each
6322 * ROM Data Structure, so we can "hop" to the next
6323 * entry if the VPD isn't in the current
6324 * ROM Data Structure.
6326 rom_offset = readw(brd->re_map_membase +
6327 base_offset + 0x18);
6328 image_length = readw(brd->re_map_membase +
6329 rom_offset + 0x10) * 512;
6330 vpd_offset = readw(brd->re_map_membase +
6333 /* Found the VPD entry */
6337 /* We didn't find a VPD entry, go to next ROM entry. */
6338 base_offset += image_length;
6340 byte1 = readb(brd->re_map_membase + base_offset);
6341 byte2 = readb(brd->re_map_membase + base_offset + 1);
6344 * If the new ROM offset doesn't have 0x55, 0xAA
6345 * as its header, we have run out of ROM.
6347 if (byte1 != 0x55 || byte2 != 0xAA)
6352 * If we have a VPD offset, then mark the board
6353 * as having a valid VPD, and copy VPDSIZE (512) bytes of
6354 * that VPD to the buffer we have in our board structure.
6357 brd->bd_flags |= BD_HAS_VPD;
6358 for (i = 0; i < VPDSIZE; i++) {
6359 brd->vpd[i] = readb(brd->re_map_membase +
6366 * We MUST poke the magic number at the PCI Rom Address location again.
6367 * This makes the card report the regular board memory back to us,
6368 * rather than the OTPROM memory.
6370 magic = FEP5_ROM_MAGIC;
6371 pci_write_config_dword(brd->pdev, PCI_ROM_ADDRESS, magic);
6375 static ssize_t dgap_driver_version_show(struct device_driver *ddp, char *buf)
6377 return snprintf(buf, PAGE_SIZE, "%s\n", DG_PART);
6379 static DRIVER_ATTR(version, S_IRUSR, dgap_driver_version_show, NULL);
6382 static ssize_t dgap_driver_boards_show(struct device_driver *ddp, char *buf)
6384 return snprintf(buf, PAGE_SIZE, "%d\n", dgap_numboards);
6386 static DRIVER_ATTR(boards, S_IRUSR, dgap_driver_boards_show, NULL);
6389 static ssize_t dgap_driver_maxboards_show(struct device_driver *ddp, char *buf)
6391 return snprintf(buf, PAGE_SIZE, "%d\n", MAXBOARDS);
6393 static DRIVER_ATTR(maxboards, S_IRUSR, dgap_driver_maxboards_show, NULL);
6396 static ssize_t dgap_driver_pollcounter_show(struct device_driver *ddp,
6399 return snprintf(buf, PAGE_SIZE, "%ld\n", dgap_poll_counter);
6401 static DRIVER_ATTR(pollcounter, S_IRUSR, dgap_driver_pollcounter_show, NULL);
6403 static ssize_t dgap_driver_pollrate_show(struct device_driver *ddp, char *buf)
6405 return snprintf(buf, PAGE_SIZE, "%dms\n", dgap_poll_tick);
6408 static ssize_t dgap_driver_pollrate_store(struct device_driver *ddp,
6409 const char *buf, size_t count)
6411 if (sscanf(buf, "%d\n", &dgap_poll_tick) != 1)
6415 static DRIVER_ATTR(pollrate, (S_IRUSR | S_IWUSR), dgap_driver_pollrate_show,
6416 dgap_driver_pollrate_store);
6419 static int dgap_create_driver_sysfiles(struct pci_driver *dgap_driver)
6422 struct device_driver *driverfs = &dgap_driver->driver;
6424 rc |= driver_create_file(driverfs, &driver_attr_version);
6425 rc |= driver_create_file(driverfs, &driver_attr_boards);
6426 rc |= driver_create_file(driverfs, &driver_attr_maxboards);
6427 rc |= driver_create_file(driverfs, &driver_attr_pollrate);
6428 rc |= driver_create_file(driverfs, &driver_attr_pollcounter);
6433 static void dgap_remove_driver_sysfiles(struct pci_driver *dgap_driver)
6435 struct device_driver *driverfs = &dgap_driver->driver;
6437 driver_remove_file(driverfs, &driver_attr_version);
6438 driver_remove_file(driverfs, &driver_attr_boards);
6439 driver_remove_file(driverfs, &driver_attr_maxboards);
6440 driver_remove_file(driverfs, &driver_attr_pollrate);
6441 driver_remove_file(driverfs, &driver_attr_pollcounter);
6444 static struct attribute_group dgap_tty_attribute_group = {
6446 .attrs = dgap_sysfs_tty_entries,
6449 static void dgap_create_tty_sysfs(struct un_t *un, struct device *c)
6453 ret = sysfs_create_group(&c->kobj, &dgap_tty_attribute_group);
6457 dev_set_drvdata(c, un);
6461 static void dgap_remove_tty_sysfs(struct device *c)
6463 sysfs_remove_group(&c->kobj, &dgap_tty_attribute_group);
6467 * Create pr and tty device entries
6469 static int dgap_tty_register_ports(struct board_t *brd)
6471 struct channel_t *ch;
6475 brd->serial_ports = kcalloc(brd->nasync, sizeof(*brd->serial_ports),
6477 if (!brd->serial_ports)
6480 brd->printer_ports = kcalloc(brd->nasync, sizeof(*brd->printer_ports),
6482 if (!brd->printer_ports) {
6484 goto free_serial_ports;
6487 for (i = 0; i < brd->nasync; i++) {
6488 tty_port_init(&brd->serial_ports[i]);
6489 tty_port_init(&brd->printer_ports[i]);
6492 ch = brd->channels[0];
6493 for (i = 0; i < brd->nasync; i++, ch = brd->channels[i]) {
6495 struct device *classp;
6497 classp = tty_port_register_device(&brd->serial_ports[i],
6501 if (IS_ERR(classp)) {
6502 ret = PTR_ERR(classp);
6503 goto unregister_ttys;
6506 dgap_create_tty_sysfs(&ch->ch_tun, classp);
6507 ch->ch_tun.un_sysfs = classp;
6509 classp = tty_port_register_device(&brd->printer_ports[i],
6513 if (IS_ERR(classp)) {
6514 ret = PTR_ERR(classp);
6515 goto unregister_ttys;
6518 dgap_create_tty_sysfs(&ch->ch_pun, classp);
6519 ch->ch_pun.un_sysfs = classp;
6521 dgap_create_ports_sysfiles(brd);
6527 ch = brd->channels[i];
6528 if (ch->ch_tun.un_sysfs) {
6529 dgap_remove_tty_sysfs(ch->ch_tun.un_sysfs);
6530 tty_unregister_device(brd->serial_driver, i);
6533 if (ch->ch_pun.un_sysfs) {
6534 dgap_remove_tty_sysfs(ch->ch_pun.un_sysfs);
6535 tty_unregister_device(brd->print_driver, i);
6540 for (i = 0; i < brd->nasync; i++) {
6541 tty_port_destroy(&brd->serial_ports[i]);
6542 tty_port_destroy(&brd->printer_ports[i]);
6545 kfree(brd->printer_ports);
6546 brd->printer_ports = NULL;
6549 kfree(brd->serial_ports);
6550 brd->serial_ports = NULL;
6556 * dgap_cleanup_tty()
6558 * Uninitialize the TTY portion of this driver. Free all memory and
6561 static void dgap_cleanup_tty(struct board_t *brd)
6566 for (i = 0; i < brd->nasync; i++) {
6567 tty_port_destroy(&brd->serial_ports[i]);
6568 dev = brd->channels[i]->ch_tun.un_sysfs;
6569 dgap_remove_tty_sysfs(dev);
6570 tty_unregister_device(brd->serial_driver, i);
6572 tty_unregister_driver(brd->serial_driver);
6573 put_tty_driver(brd->serial_driver);
6574 kfree(brd->serial_ports);
6576 for (i = 0; i < brd->nasync; i++) {
6577 tty_port_destroy(&brd->printer_ports[i]);
6578 dev = brd->channels[i]->ch_pun.un_sysfs;
6579 dgap_remove_tty_sysfs(dev);
6580 tty_unregister_device(brd->print_driver, i);
6582 tty_unregister_driver(brd->print_driver);
6583 put_tty_driver(brd->print_driver);
6584 kfree(brd->printer_ports);
6587 static int dgap_request_irq(struct board_t *brd)
6591 if (!brd || brd->magic != DGAP_BOARD_MAGIC)
6595 * Set up our interrupt handler if we are set to do interrupts.
6597 if (dgap_config_get_useintr(brd) && brd->irq) {
6599 rc = request_irq(brd->irq, dgap_intr, IRQF_SHARED, "DGAP", brd);
6607 static void dgap_free_irq(struct board_t *brd)
6609 if (brd->intr_used && brd->irq)
6610 free_irq(brd->irq, brd);
6613 static int dgap_firmware_load(struct pci_dev *pdev, int card_type,
6614 struct board_t *brd)
6616 const struct firmware *fw;
6619 char *dgap_config_buf;
6622 dgap_do_reset_board(brd);
6624 if (fw_info[card_type].conf_name) {
6625 ret = request_firmware(&fw, fw_info[card_type].conf_name,
6628 dev_err(&pdev->dev, "config file %s not found\n",
6629 fw_info[card_type].conf_name);
6633 dgap_config_buf = kzalloc(fw->size + 1, GFP_KERNEL);
6634 if (!dgap_config_buf) {
6635 release_firmware(fw);
6639 memcpy(dgap_config_buf, fw->data, fw->size);
6640 release_firmware(fw);
6643 * preserve dgap_config_buf
6644 * as dgap_parsefile would
6645 * otherwise alter it.
6647 tmp_ptr = dgap_config_buf;
6649 if (dgap_parsefile(&tmp_ptr) != 0) {
6650 kfree(dgap_config_buf);
6653 kfree(dgap_config_buf);
6657 * Match this board to a config the user created for us.
6660 dgap_find_config(brd->type, brd->pci_bus, brd->pci_slot);
6663 * Because the 4 port Xr products share the same PCI ID
6664 * as the 8 port Xr products, if we receive a NULL config
6665 * back, and this is a PAPORT8 board, retry with a
6666 * PAPORT4 attempt as well.
6668 if (brd->type == PAPORT8 && !brd->bd_config)
6670 dgap_find_config(PAPORT4, brd->pci_bus, brd->pci_slot);
6672 if (!brd->bd_config) {
6673 dev_err(&pdev->dev, "No valid configuration found\n");
6677 if (fw_info[card_type].bios_name) {
6678 ret = request_firmware(&fw, fw_info[card_type].bios_name,
6681 dev_err(&pdev->dev, "bios file %s not found\n",
6682 fw_info[card_type].bios_name);
6685 dgap_do_bios_load(brd, fw->data, fw->size);
6686 release_firmware(fw);
6688 /* Wait for BIOS to test board... */
6689 ret = dgap_test_bios(brd);
6694 if (fw_info[card_type].fep_name) {
6695 ret = request_firmware(&fw, fw_info[card_type].fep_name,
6698 dev_err(&pdev->dev, "dgap: fep file %s not found\n",
6699 fw_info[card_type].fep_name);
6702 dgap_do_fep_load(brd, fw->data, fw->size);
6703 release_firmware(fw);
6705 /* Wait for FEP to load on board... */
6706 ret = dgap_test_fep(brd);
6711 #ifdef DIGI_CONCENTRATORS_SUPPORTED
6713 * If this is a CX or EPCX, we need to see if the firmware
6714 * is requesting a concentrator image from us.
6716 if ((bd->type == PCX) || (bd->type == PEPC)) {
6717 chk_addr = (u16 *) (vaddr + DOWNREQ);
6718 /* Nonzero if FEP is requesting concentrator image. */
6719 check = readw(chk_addr);
6720 vaddr = brd->re_map_membase;
6723 if (fw_info[card_type].con_name && check && vaddr) {
6724 ret = request_firmware(&fw, fw_info[card_type].con_name,
6727 dev_err(&pdev->dev, "conc file %s not found\n",
6728 fw_info[card_type].con_name);
6731 /* Put concentrator firmware loading code here */
6732 offset = readw((u16 *) (vaddr + DOWNREQ));
6733 memcpy_toio(offset, fw->data, fw->size);
6735 dgap_do_conc_load(brd, (char *)fw->data, fw->size)
6736 release_firmware(fw);
6746 * Init the tty subsystem. Called once per board after board has been
6747 * downloaded and init'ed.
6749 static int dgap_tty_init(struct board_t *brd)
6756 struct channel_t *ch;
6757 struct bs_t __iomem *bs;
6758 struct cm_t __iomem *cm;
6762 * Initialize board structure elements.
6765 vaddr = brd->re_map_membase;
6766 true_count = readw((vaddr + NCHAN));
6768 brd->nasync = dgap_config_get_num_prts(brd);
6771 brd->nasync = brd->maxports;
6773 if (brd->nasync > brd->maxports)
6774 brd->nasync = brd->maxports;
6776 if (true_count != brd->nasync) {
6777 dev_warn(&brd->pdev->dev,
6778 "%s configured for %d ports, has %d ports.\n",
6779 brd->name, brd->nasync, true_count);
6781 if ((brd->type == PPCM) &&
6782 (true_count == 64 || true_count == 0)) {
6783 dev_warn(&brd->pdev->dev,
6784 "Please make SURE the EBI cable running from the card\n");
6785 dev_warn(&brd->pdev->dev,
6786 "to each EM module is plugged into EBI IN!\n");
6789 brd->nasync = true_count;
6791 /* If no ports, don't bother going any further */
6793 brd->state = BOARD_FAILED;
6794 brd->dpastatus = BD_NOFEP;
6800 * Allocate channel memory that might not have been allocated
6801 * when the driver was first loaded.
6803 for (i = 0; i < brd->nasync; i++) {
6805 kzalloc(sizeof(struct channel_t), GFP_KERNEL);
6806 if (!brd->channels[i]) {
6812 ch = brd->channels[0];
6813 vaddr = brd->re_map_membase;
6815 bs = (struct bs_t __iomem *) ((ulong) vaddr + CHANBUF);
6816 cm = (struct cm_t __iomem *) ((ulong) vaddr + CMDBUF);
6820 /* Set up channel variables */
6821 for (i = 0; i < brd->nasync; i++, ch = brd->channels[i], bs++) {
6823 spin_lock_init(&ch->ch_lock);
6825 /* Store all our magic numbers */
6826 ch->magic = DGAP_CHANNEL_MAGIC;
6827 ch->ch_tun.magic = DGAP_UNIT_MAGIC;
6828 ch->ch_tun.un_type = DGAP_SERIAL;
6829 ch->ch_tun.un_ch = ch;
6830 ch->ch_tun.un_dev = i;
6832 ch->ch_pun.magic = DGAP_UNIT_MAGIC;
6833 ch->ch_pun.un_type = DGAP_PRINT;
6834 ch->ch_pun.un_ch = ch;
6835 ch->ch_pun.un_dev = i;
6837 ch->ch_vaddr = vaddr;
6842 ch->ch_digi = dgap_digi_init;
6845 * Set up digi dsr and dcd bits based on altpin flag.
6847 if (dgap_config_get_altpin(brd)) {
6850 ch->ch_digi.digi_flags |= DIGI_ALTPIN;
6853 ch->ch_dsr = DM_DSR;
6856 ch->ch_taddr = vaddr + (ioread16(&(ch->ch_bs->tx_seg)) << 4);
6857 ch->ch_raddr = vaddr + (ioread16(&(ch->ch_bs->rx_seg)) << 4);
6860 ch->ch_tsize = readw(&(ch->ch_bs->tx_max)) + 1;
6861 ch->ch_rsize = readw(&(ch->ch_bs->rx_max)) + 1;
6866 * Set queue water marks, interrupt mask,
6867 * and general tty parameters.
6869 tlw = ch->ch_tsize >= 2000 ? ((ch->ch_tsize * 5) / 8) :
6873 dgap_cmdw(ch, STLOW, tlw, 0);
6875 dgap_cmdw(ch, SRLOW, ch->ch_rsize / 2, 0);
6877 dgap_cmdw(ch, SRHIGH, 7 * ch->ch_rsize / 8, 0);
6879 ch->ch_mistat = readb(&(ch->ch_bs->m_stat));
6881 init_waitqueue_head(&ch->ch_flags_wait);
6882 init_waitqueue_head(&ch->ch_tun.un_flags_wait);
6883 init_waitqueue_head(&ch->ch_pun.un_flags_wait);
6885 /* Turn on all modem interrupts for now */
6886 modem = (DM_CD | DM_DSR | DM_CTS | DM_RI);
6887 writeb(modem, &(ch->ch_bs->m_int));
6890 * Set edelay to 0 if interrupts are turned on,
6891 * otherwise set edelay to the usual 100.
6894 writew(0, &(ch->ch_bs->edelay));
6896 writew(100, &(ch->ch_bs->edelay));
6898 writeb(1, &(ch->ch_bs->idata));
6905 kfree(brd->channels[i]);
6906 brd->channels[i] = NULL;
6914 * Free the channles which are allocated in dgap_tty_init().
6916 static void dgap_tty_free(struct board_t *brd)
6920 for (i = 0; i < brd->nasync; i++)
6921 kfree(brd->channels[i]);
6924 static int dgap_init_one(struct pci_dev *pdev, const struct pci_device_id *ent)
6927 struct board_t *brd;
6929 if (dgap_numboards >= MAXBOARDS)
6932 rc = pci_enable_device(pdev);
6936 brd = dgap_found_board(pdev, ent->driver_data, dgap_numboards);
6938 return PTR_ERR(brd);
6940 rc = dgap_firmware_load(pdev, ent->driver_data, brd);
6944 rc = dgap_alloc_flipbuf(brd);
6948 rc = dgap_tty_register(brd);
6952 rc = dgap_request_irq(brd);
6954 goto unregister_tty;
6957 * Do tty device initialization.
6959 rc = dgap_tty_init(brd);
6963 rc = dgap_tty_register_ports(brd);
6967 brd->state = BOARD_READY;
6968 brd->dpastatus = BD_RUNNING;
6970 dgap_board[dgap_numboards++] = brd;
6979 dgap_tty_unregister(brd);
6981 dgap_free_flipbuf(brd);
6983 dgap_cleanup_nodes();
6990 static void dgap_remove_one(struct pci_dev *dev)
6995 static struct pci_driver dgap_driver = {
6997 .probe = dgap_init_one,
6998 .id_table = dgap_pci_tbl,
6999 .remove = dgap_remove_one,
7005 static int dgap_start(void)
7008 unsigned long flags;
7009 struct device *device;
7013 pr_info("For the tools package please visit http://www.digi.com\n");
7016 * Register our base character device into the kernel.
7020 * Register management/dpa devices
7022 rc = register_chrdev(DIGI_DGAP_MAJOR, "dgap", &dgap_board_fops);
7026 dgap_class = class_create(THIS_MODULE, "dgap_mgmt");
7027 if (IS_ERR(dgap_class)) {
7028 rc = PTR_ERR(dgap_class);
7032 device = device_create(dgap_class, NULL,
7033 MKDEV(DIGI_DGAP_MAJOR, 0),
7035 if (IS_ERR(device)) {
7036 rc = PTR_ERR(device);
7040 /* Start the poller */
7041 spin_lock_irqsave(&dgap_poll_lock, flags);
7042 setup_timer(&dgap_poll_timer, dgap_poll_handler, 0);
7043 dgap_poll_timer.data = 0;
7044 dgap_poll_time = jiffies + dgap_jiffies_from_ms(dgap_poll_tick);
7045 dgap_poll_timer.expires = dgap_poll_time;
7046 spin_unlock_irqrestore(&dgap_poll_lock, flags);
7048 add_timer(&dgap_poll_timer);
7053 class_destroy(dgap_class);
7055 unregister_chrdev(DIGI_DGAP_MAJOR, "dgap");
7059 static void dgap_stop(void)
7061 unsigned long lock_flags;
7063 spin_lock_irqsave(&dgap_poll_lock, lock_flags);
7065 spin_unlock_irqrestore(&dgap_poll_lock, lock_flags);
7067 del_timer_sync(&dgap_poll_timer);
7069 device_destroy(dgap_class, MKDEV(DIGI_DGAP_MAJOR, 0));
7070 class_destroy(dgap_class);
7071 unregister_chrdev(DIGI_DGAP_MAJOR, "dgap");
7075 * dgap_cleanup_board()
7077 * Free all the memory associated with a board
7079 static void dgap_cleanup_board(struct board_t *brd)
7083 if (!brd || brd->magic != DGAP_BOARD_MAGIC)
7088 tasklet_kill(&brd->helper_tasklet);
7092 /* Free all allocated channels structs */
7093 for (i = 0; i < MAXPORTS ; i++)
7094 kfree(brd->channels[i]);
7096 kfree(brd->flipbuf);
7097 kfree(brd->flipflagbuf);
7099 dgap_board[brd->boardnum] = NULL;
7105 /************************************************************************
7107 * Driver load/unload functions
7109 ************************************************************************/
7114 * Module load. This is where it all starts.
7116 static int dgap_init_module(void)
7120 pr_info("%s, Digi International Part Number %s\n", DG_NAME, DG_PART);
7126 rc = pci_register_driver(&dgap_driver);
7130 rc = dgap_create_driver_sysfiles(&dgap_driver);
7132 goto err_unregister;
7134 dgap_driver_state = DRIVER_READY;
7139 pci_unregister_driver(&dgap_driver);
7147 * dgap_cleanup_module()
7149 * Module unload. This is where it all ends.
7151 static void dgap_cleanup_module(void)
7156 spin_lock_irqsave(&dgap_poll_lock, lock_flags);
7158 spin_unlock_irqrestore(&dgap_poll_lock, lock_flags);
7160 /* Turn off poller right away. */
7161 del_timer_sync(&dgap_poll_timer);
7163 dgap_remove_driver_sysfiles(&dgap_driver);
7165 device_destroy(dgap_class, MKDEV(DIGI_DGAP_MAJOR, 0));
7166 class_destroy(dgap_class);
7167 unregister_chrdev(DIGI_DGAP_MAJOR, "dgap");
7169 for (i = 0; i < dgap_numboards; ++i) {
7170 dgap_remove_ports_sysfiles(dgap_board[i]);
7171 dgap_cleanup_tty(dgap_board[i]);
7172 dgap_cleanup_board(dgap_board[i]);
7175 dgap_cleanup_nodes();
7178 pci_unregister_driver(&dgap_driver);
7181 module_init(dgap_init_module);
7182 module_exit(dgap_cleanup_module);
7184 MODULE_LICENSE("GPL");
7185 MODULE_AUTHOR("Digi International, http://www.digi.com");
7186 MODULE_DESCRIPTION("Driver for the Digi International EPCA PCI based product line");
7187 MODULE_SUPPORTED_DEVICE("dgap");