Loading...
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 746 747 748 749 750 751 752 753 754 755 756 757 758 759 760 761 762 763 764 765 766 767 768 769 770 771 772 773 774 775 776 777 778 779 780 781 782 783 784 785 786 787 788 789 790 791 792 793 794 795 796 797 798 799 800 801 802 803 804 805 806 807 808 809 810 811 812 813 814 815 816 817 818 819 820 821 822 823 824 825 826 827 828 829 830 831 832 833 834 835 836 837 838 839 840 841 842 843 844 845 846 847 848 849 850 851 852 853 854 855 856 857 858 859 860 861 862 863 864 865 866 867 868 869 870 871 872 873 874 875 876 877 878 879 880 881 882 883 884 885 886 887 888 889 890 891 892 893 894 895 896 897 898 899 900 901 902 903 904 905 906 907 908 909 910 911 912 913 914 915 916 917 918 919 920 921 922 923 924 925 926 927 928 929 930 931 932 933 934 935 936 937 938 939 940 941 942 943 944 945 946 947 948 949 950 951 952 953 954 955 956 957 958 959 960 961 962 963 964 965 966 967 968 969 970 971 972 973 974 975 976 977 978 979 980 981 982 983 984 985 986 987 988 989 990 991 992 993 994 995 996 997 998 999 1000 1001 1002 1003 1004 1005 1006 1007 1008 1009 1010 1011 1012 1013 1014 1015 1016 1017 1018 1019 1020 1021 1022 1023 1024 1025 1026 1027 1028 1029 1030 1031 1032 1033 1034 1035 1036 1037 1038 1039 1040 1041 1042 1043 1044 1045 1046 1047 1048 1049 1050 1051 1052 1053 1054 1055 1056 1057 1058 1059 1060 1061 1062 1063 1064 1065 1066 1067 1068 1069 1070 1071 1072 1073 1074 1075 1076 1077 1078 1079 1080 1081 1082 1083 1084 1085 1086 1087 1088 1089 1090 1091 1092 1093 1094 1095 1096 1097 1098 1099 1100 1101 1102 1103 1104 1105 1106 1107 1108 1109 1110 1111 1112 1113 1114 1115 1116 1117 1118 1119 1120 1121 1122 1123 1124 1125 1126 1127 1128 1129 1130 1131 1132 1133 1134 1135 1136 1137 1138 1139 1140 1141 1142 1143 1144 1145 1146 1147 1148 1149 1150 1151 1152 1153 1154 1155 1156 1157 1158 1159 1160 1161 1162 1163 1164 1165 1166 1167 1168 1169 1170 1171 1172 1173 1174 1175 1176 1177 1178 1179 1180 1181 1182 1183 1184 1185 1186 1187 1188 1189 1190 1191 1192 1193 1194 1195 1196 1197 1198 1199 1200 1201 1202 1203 1204 1205 1206 1207 1208 1209 1210 1211 1212 1213 1214 1215 1216 1217 1218 1219 1220 1221 1222 1223 1224 1225 1226 1227 1228 1229 1230 1231 1232 1233 1234 1235 1236 1237 1238 1239 1240 1241 1242 1243 1244 1245 1246 1247 1248 1249 1250 1251 1252 1253 1254 1255 1256 1257 1258 1259 1260 1261 1262 1263 1264 1265 1266 1267 1268 1269 1270 1271 1272 1273 1274 1275 1276 1277 1278 1279 1280 1281 1282 1283 1284 1285 1286 1287 1288 1289 1290 1291 1292 1293 1294 1295 1296 1297 1298 1299 1300 1301 1302 1303 1304 1305 1306 1307 1308 1309 1310 1311 1312 1313 1314 1315 1316 1317 1318 1319 1320 1321 1322 1323 1324 1325 1326 1327 1328 1329 1330 1331 1332 1333 1334 1335 1336 1337 1338 1339 1340 1341 1342 1343 1344 1345 1346 1347 1348 1349 1350 1351 1352 1353 1354 1355 1356 1357 1358 1359 1360 1361 1362 1363 1364 1365 1366 1367 1368 1369 1370 1371 1372 1373 1374 1375 1376 1377 1378 1379 1380 1381 1382 1383 1384 1385 1386 1387 1388 1389 1390 1391 1392 1393 1394 1395 1396 1397 1398 1399 1400 1401 1402 1403 1404 1405 1406 1407 1408 1409 1410 1411 1412 1413 1414 1415 1416 1417 1418 1419 1420 1421 1422 1423 1424 1425 1426 1427 1428 1429 1430 1431 1432 1433 1434 1435 1436 1437 1438 1439 1440 1441 1442 1443 1444 1445 1446 1447 1448 1449 1450 1451 1452 1453 1454 1455 1456 1457 1458 1459 1460 1461 1462 1463 1464 1465 1466 1467 1468 1469 1470 1471 1472 1473 1474 1475 1476 1477 1478 1479 1480 1481 1482 1483 1484 1485 1486 1487 1488 1489 1490 1491 1492 1493 1494 1495 1496 1497 1498 1499 1500 1501 1502 1503 1504 1505 1506 1507 1508 1509 1510 1511 1512 1513 1514 1515 1516 1517 1518 1519 1520 1521 1522 1523 1524 1525 1526 1527 1528 1529 1530 1531 1532 1533 1534 1535 1536 1537 1538 1539 1540 1541 1542 1543 1544 1545 1546 1547 1548 1549 1550 1551 1552 1553 1554 1555 1556 1557 1558 1559 1560 1561 1562 1563 1564 1565 1566 1567 1568 1569 1570 1571 1572 1573 1574 1575 1576 1577 1578 1579 1580 1581 1582 1583 1584 1585 1586 1587 1588 1589 1590 1591 1592 1593 1594 1595 1596 1597 1598 1599 1600 1601 1602 1603 1604 1605 1606 1607 1608 1609 1610 1611 1612 1613 1614 1615 1616 1617 1618 1619 1620 1621 1622 1623 1624 1625 1626 1627 1628 1629 1630 1631 1632 1633 1634 1635 1636 1637 1638 1639 1640 1641 1642 1643 1644 1645 1646 1647 1648 1649 1650 1651 1652 1653 1654 1655 1656 1657 1658 1659 1660 1661 1662 1663 1664 1665 1666 1667 1668 1669 1670 1671 1672 1673 1674 1675 1676 1677 1678 1679 1680 1681 1682 1683 1684 1685 1686 1687 1688 1689 1690 1691 1692 1693 1694 1695 1696 1697 1698 1699 1700 1701 1702 1703 1704 1705 1706 1707 1708 1709 1710 1711 1712 1713 1714 1715 1716 1717 1718 1719 1720 1721 1722 1723 1724 1725 1726 1727 1728 1729 1730 1731 1732 1733 1734 1735 1736 1737 1738 1739 1740 1741 1742 1743 1744 1745 1746 1747 1748 1749 1750 1751 1752 1753 1754 1755 1756 1757 1758 1759 1760 1761 1762 1763 1764 1765 1766 1767 1768 1769 1770 1771 1772 1773 1774 1775 1776 1777 1778 1779 1780 1781 1782 1783 1784 1785 1786 1787 1788 1789 1790 1791 1792 1793 1794 1795 1796 1797 1798 1799 1800 1801 1802 1803 1804 1805 1806 1807 1808 1809 1810 1811 1812 1813 1814 1815 1816 1817 1818 1819 1820 1821 1822 1823 1824 1825 1826 1827 1828 1829 1830 1831 1832 1833 1834 1835 1836 1837 1838 1839 1840 1841 1842 1843 1844 1845 1846 1847 1848 1849 1850 1851 1852 1853 1854 1855 1856 1857 1858 1859 1860 1861 1862 1863 1864 1865 1866 1867 1868 1869 1870 1871 1872 1873 1874 1875 1876 1877 1878 1879 1880 1881 1882 1883 1884 1885 1886 1887 1888 1889 1890 1891 1892 1893 1894 1895 1896 1897 1898 1899 1900 1901 1902 1903 1904 1905 1906 1907 1908 1909 1910 1911 1912 1913 1914 1915 1916 1917 1918 1919 1920 1921 1922 1923 1924 1925 1926 1927 1928 1929 1930 1931 1932 1933 1934 1935 1936 1937 1938 1939 1940 1941 1942 1943 1944 1945 1946 1947 1948 1949 1950 1951 1952 1953 1954 1955 1956 1957 1958 1959 1960 1961 1962 1963 1964 1965 1966 1967 1968 1969 1970 1971 1972 1973 1974 1975 1976 1977 1978 1979 1980 1981 1982 1983 1984 1985 1986 1987 1988 1989 1990 1991 1992 1993 1994 1995 1996 1997 1998 1999 2000 2001 2002 2003 2004 2005 2006 2007 2008 2009 2010 2011 2012 2013 2014 2015 2016 2017 2018 2019 2020 2021 2022 2023 2024 2025 2026 2027 2028 2029 2030 2031 2032 2033 2034 2035 2036 2037 2038 2039 2040 2041 2042 2043 2044 2045 2046 2047 2048 2049 2050 2051 2052 2053 2054 2055 2056 2057 2058 2059 2060 2061 2062 2063 2064 2065 2066 2067 2068 2069 2070 2071 2072 2073 2074 2075 2076 2077 2078 2079 2080 2081 2082 2083 2084 2085 2086 2087 2088 2089 2090 2091 2092 2093 2094 2095 2096 2097 2098 2099 2100 2101 2102 2103 2104 2105 2106 2107 2108 2109 2110 2111 2112 2113 2114 2115 2116 2117 2118 2119 2120 2121 2122 2123 2124 2125 2126 2127 2128 2129 2130 2131 2132 2133 2134 2135 2136 2137 2138 2139 2140 2141 2142 2143 2144 2145 2146 2147 2148 2149 2150 2151 2152 2153 2154 2155 2156 2157 2158 2159 2160 2161 2162 2163 2164 2165 2166 2167 2168 2169 2170 2171 2172 2173 2174 2175 2176 2177 2178 2179 2180 2181 2182 2183 2184 2185 2186 2187 2188 2189 2190 2191 2192 2193 2194 2195 2196 2197 2198 2199 2200 2201 2202 2203 2204 2205 2206 2207 2208 2209 2210 2211 2212 2213 2214 2215 2216 2217 2218 2219 2220 2221 2222 2223 2224 2225 2226 2227 2228 2229 2230 2231 2232 2233 2234 2235 2236 2237 2238 2239 2240 2241 2242 2243 2244 2245 2246 2247 2248 2249 2250 2251 2252 2253 2254 2255 2256 2257 2258 2259 2260 2261 2262 2263 2264 2265 2266 2267 2268 2269 2270 2271 2272 2273 2274 2275 2276 2277 2278 2279 2280 2281 2282 2283 2284 2285 2286 2287 2288 2289 2290 2291 2292 2293 2294 2295 2296 2297 2298 2299 2300 2301 2302 2303 2304 2305 2306 2307 2308 2309 2310 2311 2312 2313 2314 2315 2316 2317 2318 2319 2320 2321 2322 2323 2324 2325 2326 2327 2328 2329 2330 2331 2332 2333 2334 2335 2336 2337 2338 2339 2340 2341 2342 2343 2344 2345 2346 2347 2348 2349 2350 2351 2352 2353 2354 2355 2356 2357 2358 2359 2360 2361 2362 2363 2364 2365 2366 2367 2368 2369 2370 2371 2372 2373 2374 2375 2376 2377 2378 2379 2380 2381 2382 2383 2384 2385 2386 2387 2388 2389 2390 2391 2392 2393 2394 2395 2396 2397 2398 2399 2400 2401 2402 2403 2404 2405 2406 2407 2408 2409 2410 2411 2412 2413 2414 2415 2416 2417 2418 2419 2420 2421 2422 2423 2424 2425 2426 2427 2428 2429 2430 2431 2432 2433 2434 2435 2436 2437 2438 2439 2440 2441 2442 2443 2444 2445 2446 2447 2448 2449 2450 2451 2452 2453 2454 2455 2456 2457 2458 2459 2460 2461 2462 2463 2464 2465 2466 2467 2468 2469 2470 2471 2472 2473 2474 2475 2476 2477 2478 2479 2480 2481 2482 2483 2484 2485 2486 2487 2488 2489 2490 | /* * linux/drivers/char/pcxe.c * * Written by Troy De Jongh, November, 1994 * * Copyright (C) 1994,1995 Troy De Jongh * This software may be used and distributed according to the terms * of the GNU Public License. * * This driver is for the DigiBoard PC/Xe and PC/Xi line of products. * * This driver does NOT support DigiBoard's fastcook FEP option and * does not support the transparent print (i.e. digiprint) option. * * This Driver is currently maintained by Christoph Lameter (clameter@fuller.edu) * Please contact the mailing list for problems first. * * Sources of Information: * 1. The Linux Digiboard Page at http://private.fuller.edu/clameter/digi.html * 2. The Linux Digiboard Mailing list at digiboard@list.fuller.edu * (Simply write a message to introduce yourself to subscribe) * * 1.5.2 Fall 1995 Bug fixes by David Nugent * 1.5.3 March 9, 1996 Christoph Lameter: Fixed 115.2K Support. Memory * allocation harmonized with 1.3.X Series. * 1.5.4 March 30, 1996 Christoph Lameter: Fixup for 1.3.81. Use init_bh * instead of direct assignment to kernel arrays. * 1.5.5 April 5, 1996 Major device numbers corrected. * Mike McLagan<mike.mclagan@linux.org>: Add setup * variable handling, instead of using the old pcxxconfig.h * 1.5.6 April 16, 1996 Christoph Lameter: Pointer cleanup, macro cleanup. * Call out devices changed to /dev/cudxx. * 1.5.7 July 22, 1996 Martin Mares: CLOCAL fix, pcxe_table clearing. * David Nugent: Bug in pcxe_open. * Brian J. Murrell: Modem Control fixes, Majors correctly assigned * 1.6.1 April 6, 1997 Bernhard Kaindl: fixed virtual memory access for 2.1 * i386-kernels and use on other archtitectures, Allowing use * as module, added module parameters, added switch to enable * verbose messages to assist user during card configuration. * Currently only tested on a PC/Xi card, but should work on Xe * and Xeve also. * */ #undef SPEED_HACK /* If you define SPEED_HACK then you get the following Baudrate translation 19200 = 57600 38400 = 115K The driver supports the native 57.6K and 115K Baudrates under Linux, but some distributions like Slackware 3.0 don't like these high baudrates. */ #include <linux/module.h> #include <linux/mm.h> #include <linux/ioport.h> #include <linux/errno.h> #include <linux/signal.h> #include <linux/sched.h> #include <linux/timer.h> #include <linux/interrupt.h> #include <linux/tty.h> #include <linux/tty_flip.h> #include <linux/major.h> #include <linux/string.h> #include <linux/fcntl.h> #include <linux/ptrace.h> #include <linux/delay.h> #include <linux/serial.h> #include <linux/tty_driver.h> #include <linux/malloc.h> #include <linux/string.h> #include <linux/init.h> #ifndef MODULE #include <linux/ctype.h> /* We only need it for parsing the "digi="-line */ #endif #include <asm/system.h> #include <asm/io.h> #include <asm/uaccess.h> #include <asm/bitops.h> #define VERSION "1.6.1" #include "digi.h" #include "fep.h" #include "pcxx.h" #include "digi_fep.h" #include "digi_bios.h" /* * Define one default setting if no digi= config line is used. * Default is altpin = disabled, 16 ports, I/O 200h, Memory 0D0000h */ static struct board_info boards[MAX_DIGI_BOARDS] = { { /* Board is enabled */ ENABLED, /* Type is auto-detected */ 0, /* altping is disabled */ DISABLED, /* number of ports = 16 */ 16, /* io address is 0x200 */ 0x200, /* card memory at 0xd0000 */ 0xd0000, /* first minor device no. */ 0 } }; static int verbose = 0; static int debug = 0; #ifdef MODULE /* Variables for insmod */ static int io[] = {0, 0, 0, 0}; static int membase[] = {0, 0, 0, 0}; static int memsize[] = {0, 0, 0, 0}; static int altpin[] = {0, 0, 0, 0}; static int numports[] = {0, 0, 0, 0}; # if (LINUX_VERSION_CODE > 0x020111) MODULE_AUTHOR("Bernhard Kaindl"); MODULE_DESCRIPTION("Digiboard PC/X{i,e,eve} driver"); MODULE_PARM(verbose, "i"); MODULE_PARM(debug, "i"); MODULE_PARM(io, "1-4i"); MODULE_PARM(membase, "1-4i"); MODULE_PARM(memsize, "1-4i"); MODULE_PARM(altpin, "1-4i"); MODULE_PARM(numports, "1-4i"); # endif #endif MODULE static int numcards = 1; static int nbdevs = 0; static struct channel *digi_channels; static struct tty_struct **pcxe_table; static struct termios **pcxe_termios; static struct termios **pcxe_termios_locked; int pcxx_ncook=sizeof(pcxx_cook); int pcxx_nbios=sizeof(pcxx_bios); #define MIN(a,b) ((a) < (b) ? (a) : (b)) #define pcxxassert(x, msg) if(!(x)) pcxx_error(__LINE__, msg) #define FEPTIMEOUT 200000 #define SERIAL_TYPE_NORMAL 1 #define SERIAL_TYPE_CALLOUT 2 #define PCXE_EVENT_HANGUP 1 struct tty_driver pcxe_driver; struct tty_driver pcxe_callout; static int pcxe_refcount; DECLARE_TASK_QUEUE(tq_pcxx); static void pcxxpoll(void); static void pcxxdelay(int); static void fepcmd(struct channel *, int, int, int, int, int); static void pcxe_put_char(struct tty_struct *, unsigned char); static void pcxe_flush_chars(struct tty_struct *); static void pcxx_error(int, char *); static void pcxe_close(struct tty_struct *, struct file *); static int pcxe_ioctl(struct tty_struct *, struct file *, unsigned int, unsigned long); static void pcxe_set_termios(struct tty_struct *, struct termios *); static int pcxe_write(struct tty_struct *, int, const unsigned char *, int); static int pcxe_write_room(struct tty_struct *); static int pcxe_chars_in_buffer(struct tty_struct *); static void pcxe_flush_buffer(struct tty_struct *); static void doevent(int); static void receive_data(struct channel *); static void pcxxparam(struct tty_struct *, struct channel *ch); static void do_softint(void *); static inline void pcxe_sched_event(struct channel *, int); static void do_pcxe_bh(void); static void pcxe_start(struct tty_struct *); static void pcxe_stop(struct tty_struct *); static void pcxe_throttle(struct tty_struct *); static void pcxe_unthrottle(struct tty_struct *); static void digi_send_break(struct channel *ch, int msec); static void shutdown(struct channel *); static void setup_empty_event(struct tty_struct *tty, struct channel *ch); static inline void memwinon(struct board_info *b, unsigned int win); static inline void memwinoff(struct board_info *b, unsigned int win); static inline void globalwinon(struct channel *ch); static inline void rxwinon(struct channel *ch); static inline void txwinon(struct channel *ch); static inline void memoff(struct channel *ch); static inline void assertgwinon(struct channel *ch); static inline void assertmemoff(struct channel *ch); #define TZ_BUFSZ 4096 /* function definitions */ #ifdef MODULE /* * pcxe_init() is our init_module(): */ #define pcxe_init init_module void cleanup_module(void); /*****************************************************************************/ void cleanup_module() { unsigned long flags; int crd, i; int e1, e2; struct board_info *bd; struct channel *ch; printk(KERN_NOTICE "Unloading PC/Xx version %s\n", VERSION); save_flags(flags); cli(); timer_active &= ~(1 << DIGI_TIMER); timer_table[DIGI_TIMER].fn = NULL; timer_table[DIGI_TIMER].expires = 0; remove_bh(DIGI_BH); if ((e1 = tty_unregister_driver(&pcxe_driver))) printk("SERIAL: failed to unregister serial driver (%d)\n", e1); if ((e2 = tty_unregister_driver(&pcxe_callout))) printk("SERIAL: failed to unregister callout driver (%d)\n",e2); for(crd=0; crd < numcards; crd++) { bd = &boards[crd]; ch = digi_channels+bd->first_minor; for(i=0; i < bd->numports; i++, ch++) { kfree(ch->tmp_buf); } release_region(bd->port, 4); } kfree(digi_channels); kfree(pcxe_termios_locked); kfree(pcxe_termios); kfree(pcxe_table); restore_flags(flags); } #endif static inline struct channel *chan(register struct tty_struct *tty) { if (tty) { register struct channel *ch=(struct channel *)tty->driver_data; if (ch >= digi_channels && ch < digi_channels+nbdevs) { if (ch->magic==PCXX_MAGIC) return ch; } } return NULL; } /* These inline routines are to turn board memory on and off */ static inline void memwinon(struct board_info *b, unsigned int win) { if(b->type == PCXEVE) outb_p(FEPWIN|win, b->port+1); else outb_p(inb(b->port)|FEPMEM, b->port); } static inline void memwinoff(struct board_info *b, unsigned int win) { outb_p(inb(b->port)&~FEPMEM, b->port); if(b->type == PCXEVE) outb_p(0, b->port + 1); } static inline void globalwinon(struct channel *ch) { if(ch->board->type == PCXEVE) outb_p(FEPWIN, ch->board->port+1); else outb_p(FEPMEM, ch->board->port); } static inline void rxwinon(struct channel *ch) { if(ch->rxwin == 0) outb_p(FEPMEM, ch->board->port); else outb_p(ch->rxwin, ch->board->port+1); } static inline void txwinon(struct channel *ch) { if(ch->txwin == 0) outb_p(FEPMEM, ch->board->port); else outb_p(ch->txwin, ch->board->port+1); } static inline void memoff(struct channel *ch) { outb_p(0, ch->board->port); if(ch->board->type == PCXEVE) outb_p(0, ch->board->port+1); } static inline void assertgwinon(struct channel *ch) { if(ch->board->type != PCXEVE) pcxxassert(inb(ch->board->port) & FEPMEM, "Global memory off"); } static inline void assertmemoff(struct channel *ch) { if(ch->board->type != PCXEVE) pcxxassert(!(inb(ch->board->port) & FEPMEM), "Memory on"); } static inline void pcxe_sched_event(struct channel *info, int event) { info->event |= 1 << event; queue_task(&info->tqueue, &tq_pcxx); mark_bh(DIGI_BH); } static void pcxx_error(int line, char *msg) { printk("pcxx_error (DigiBoard): line=%d %s\n", line, msg); } static int pcxx_waitcarrier(struct tty_struct *tty,struct file *filp,struct channel *info) { struct wait_queue wait = { current, NULL }; int retval = 0; int do_clocal = 0; if (info->asyncflags & ASYNC_CALLOUT_ACTIVE) { if (info->normal_termios.c_cflag & CLOCAL) do_clocal = 1; } else { if (tty->termios->c_cflag & CLOCAL) do_clocal = 1; } /* * Block waiting for the carrier detect and the line to become free */ retval = 0; add_wait_queue(&info->open_wait, &wait); info->count--; info->blocked_open++; for (;;) { cli(); if ((info->asyncflags & ASYNC_CALLOUT_ACTIVE) == 0) { globalwinon(info); info->omodem |= DTR|RTS; fepcmd(info, SETMODEM, DTR|RTS, 0, 10, 1); memoff(info); } sti(); current->state = TASK_INTERRUPTIBLE; if(tty_hung_up_p(filp) || (info->asyncflags & ASYNC_INITIALIZED) == 0) { if(info->asyncflags & ASYNC_HUP_NOTIFY) retval = -EAGAIN; else retval = -ERESTARTSYS; break; } if ((info->asyncflags & ASYNC_CALLOUT_ACTIVE) == 0 && (info->asyncflags & ASYNC_CLOSING) == 0 && (do_clocal || (info->imodem & info->dcd))) break; if(signal_pending(current)) { retval = -ERESTARTSYS; break; } schedule(); } current->state = TASK_RUNNING; remove_wait_queue(&info->open_wait, &wait); if(!tty_hung_up_p(filp)) info->count++; info->blocked_open--; return retval; } int pcxe_open(struct tty_struct *tty, struct file * filp) { volatile struct board_chan *bc; struct channel *ch; unsigned long flags; int line; int boardnum; int retval; line = MINOR(tty->device) - tty->driver.minor_start; if(line < 0 || line >= nbdevs) { printk("line out of range in pcxe_open\n"); tty->driver_data = NULL; return(-ENODEV); } for(boardnum=0;boardnum<numcards;boardnum++) if ((line >= boards[boardnum].first_minor) && (line < boards[boardnum].first_minor + boards[boardnum].numports)) break; if(boardnum >= numcards || boards[boardnum].status == DISABLED || (line - boards[boardnum].first_minor) >= boards[boardnum].numports) { tty->driver_data = NULL; /* Mark this device as 'down' */ return(-ENODEV); } ch = digi_channels+line; if(ch->brdchan == 0) { tty->driver_data = NULL; return(-ENODEV); } /* flag the kernel that there is somebody using this guy */ MOD_INC_USE_COUNT; /* * If the device is in the middle of being closed, then block * until it's done, and then try again. */ if(ch->asyncflags & ASYNC_CLOSING) { interruptible_sleep_on(&ch->close_wait); if(ch->asyncflags & ASYNC_HUP_NOTIFY) return -EAGAIN; else return -ERESTARTSYS; } save_flags(flags); cli(); ch->count++; tty->driver_data = ch; ch->tty = tty; if ((ch->asyncflags & ASYNC_INITIALIZED) == 0) { unsigned int head; globalwinon(ch); ch->statusflags = 0; bc=ch->brdchan; ch->imodem = bc->mstat; head = bc->rin; bc->rout = head; ch->tty = tty; pcxxparam(tty,ch); ch->imodem = bc->mstat; bc->idata = 1; ch->omodem = DTR|RTS; fepcmd(ch, SETMODEM, DTR|RTS, 0, 10, 1); memoff(ch); ch->asyncflags |= ASYNC_INITIALIZED; } restore_flags(flags); if(ch->asyncflags & ASYNC_CLOSING) { interruptible_sleep_on(&ch->close_wait); if(ch->asyncflags & ASYNC_HUP_NOTIFY) return -EAGAIN; else return -ERESTARTSYS; } /* * If this is a callout device, then just make sure the normal * device isn't being used. */ if (tty->driver.subtype == SERIAL_TYPE_CALLOUT) { if (ch->asyncflags & ASYNC_NORMAL_ACTIVE) return -EBUSY; if (ch->asyncflags & ASYNC_CALLOUT_ACTIVE) { if ((ch->asyncflags & ASYNC_SESSION_LOCKOUT) && (ch->session != current->session)) return -EBUSY; if((ch->asyncflags & ASYNC_PGRP_LOCKOUT) && (ch->pgrp != current->pgrp)) return -EBUSY; } ch->asyncflags |= ASYNC_CALLOUT_ACTIVE; } else { if (filp->f_flags & O_NONBLOCK) { if(ch->asyncflags & ASYNC_CALLOUT_ACTIVE) return -EBUSY; } else { /* this has to be set in order for the "block until * CD" code to work correctly. i'm not sure under * what circumstances asyncflags should be set to * ASYNC_NORMAL_ACTIVE though * brian@ilinx.com */ ch->asyncflags |= ASYNC_NORMAL_ACTIVE; if ((retval = pcxx_waitcarrier(tty, filp, ch)) != 0) return retval; } ch->asyncflags |= ASYNC_NORMAL_ACTIVE; } save_flags(flags); cli(); if((ch->count == 1) && (ch->asyncflags & ASYNC_SPLIT_TERMIOS)) { if(tty->driver.subtype == SERIAL_TYPE_NORMAL) *tty->termios = ch->normal_termios; else *tty->termios = ch->callout_termios; globalwinon(ch); pcxxparam(tty,ch); memoff(ch); } ch->session = current->session; ch->pgrp = current->pgrp; restore_flags(flags); return 0; } static void shutdown(struct channel *info) { unsigned long flags; volatile struct board_chan *bc; struct tty_struct *tty; if (!(info->asyncflags & ASYNC_INITIALIZED)) return; save_flags(flags); cli(); globalwinon(info); bc = info->brdchan; if(bc) bc->idata = 0; tty = info->tty; /* * If we're a modem control device and HUPCL is on, drop RTS & DTR. */ if(tty->termios->c_cflag & HUPCL) { info->omodem &= ~(RTS|DTR); fepcmd(info, SETMODEM, 0, DTR|RTS, 10, 1); } memoff(info); info->asyncflags &= ~ASYNC_INITIALIZED; restore_flags(flags); } static void pcxe_close(struct tty_struct * tty, struct file * filp) { struct channel *info; if ((info=chan(tty))!=NULL) { unsigned long flags; save_flags(flags); cli(); if(tty_hung_up_p(filp)) { /* flag that somebody is done with this module */ MOD_DEC_USE_COUNT; restore_flags(flags); return; } /* this check is in serial.c, it won't hurt to do it here too */ if ((tty->count == 1) && (info->count != 1)) { /* * Uh, oh. tty->count is 1, which means that the tty * structure will be freed. Info->count should always * be one in these conditions. If it's greater than * one, we've got real problems, since it means the * serial port won't be shutdown. */ printk("pcxe_close: bad serial port count; tty->count is 1, info->count is %d\n", info->count); info->count = 1; } if (info->count-- > 1) { restore_flags(flags); MOD_DEC_USE_COUNT; return; } if (info->count < 0) { info->count = 0; } info->asyncflags |= ASYNC_CLOSING; /* * Save the termios structure, since this port may have * separate termios for callout and dialin. */ if(info->asyncflags & ASYNC_NORMAL_ACTIVE) info->normal_termios = *tty->termios; if(info->asyncflags & ASYNC_CALLOUT_ACTIVE) info->callout_termios = *tty->termios; tty->closing = 1; if(info->asyncflags & ASYNC_INITIALIZED) { setup_empty_event(tty,info); tty_wait_until_sent(tty, 3000); /* 30 seconds timeout */ } if(tty->driver.flush_buffer) tty->driver.flush_buffer(tty); if(tty->ldisc.flush_buffer) tty->ldisc.flush_buffer(tty); shutdown(info); tty->closing = 0; info->event = 0; info->tty = NULL; #ifndef MODULE /* ldiscs[] is not available in a MODULE ** worth noting that while I'm not sure what this hunk of code is supposed ** to do, it is not present in the serial.c driver. Hmmm. If you know, ** please send me a note. brian@ilinx.com ** Dont know either what this is supposed to do clameter@waterf.org. */ if(tty->ldisc.num != ldiscs[N_TTY].num) { if(tty->ldisc.close) (tty->ldisc.close)(tty); tty->ldisc = ldiscs[N_TTY]; tty->termios->c_line = N_TTY; if(tty->ldisc.open) (tty->ldisc.open)(tty); } #endif if(info->blocked_open) { if(info->close_delay) { current->state = TASK_INTERRUPTIBLE; current->timeout = jiffies + info->close_delay; schedule(); } wake_up_interruptible(&info->open_wait); } info->asyncflags &= ~(ASYNC_NORMAL_ACTIVE| ASYNC_CALLOUT_ACTIVE|ASYNC_CLOSING); wake_up_interruptible(&info->close_wait); MOD_DEC_USE_COUNT; restore_flags(flags); } } void pcxe_hangup(struct tty_struct *tty) { struct channel *ch; if ((ch=chan(tty))!=NULL) { unsigned long flags; save_flags(flags); cli(); shutdown(ch); ch->event = 0; ch->count = 0; ch->tty = NULL; ch->asyncflags &= ~(ASYNC_NORMAL_ACTIVE|ASYNC_CALLOUT_ACTIVE); wake_up_interruptible(&ch->open_wait); restore_flags(flags); } } static int pcxe_write(struct tty_struct * tty, int from_user, const unsigned char *buf, int count) { struct channel *ch; volatile struct board_chan *bc; int total, remain, size, stlen; unsigned int head, tail; unsigned long flags; /* printk("Entering pcxe_write()\n"); */ if ((ch=chan(tty))==NULL) return 0; bc = ch->brdchan; size = ch->txbufsize; if (from_user) { save_flags(flags); cli(); globalwinon(ch); head = bc->tin & (size - 1); /* It seems to be necessary to make sure that the value is stable here somehow This is a rather odd pice of code here. */ do { tail = bc->tout; } while (tail != bc->tout); tail &= (size - 1); stlen = (head >= tail) ? (size - (head - tail) - 1) : (tail - head - 1); count = MIN(stlen, count); if (count) { if (verify_area(VERIFY_READ, (char*)buf, count)) count=0; else copy_from_user(ch->tmp_buf, buf, count); } buf = ch->tmp_buf; memoff(ch); restore_flags(flags); } /* * All data is now local */ total = 0; save_flags(flags); cli(); globalwinon(ch); head = bc->tin & (size - 1); tail = bc->tout; if (tail != bc->tout) tail = bc->tout; tail &= (size - 1); if (head >= tail) { remain = size - (head - tail) - 1; stlen = size - head; } else { remain = tail - head - 1; stlen = remain; } count = MIN(remain, count); txwinon(ch); while (count > 0) { stlen = MIN(count, stlen); memcpy(ch->txptr + head, buf, stlen); buf += stlen; count -= stlen; total += stlen; head += stlen; if (head >= size) { head = 0; stlen = tail; } } ch->statusflags |= TXBUSY; globalwinon(ch); bc->tin = head; if ((ch->statusflags & LOWWAIT) == 0) { ch->statusflags |= LOWWAIT; bc->ilow = 1; } memoff(ch); restore_flags(flags); return(total); } static void pcxe_put_char(struct tty_struct *tty, unsigned char c) { pcxe_write(tty, 0, &c, 1); return; } static int pcxe_write_room(struct tty_struct *tty) { struct channel *ch; int remain; remain = 0; if ((ch=chan(tty))!=NULL) { volatile struct board_chan *bc; unsigned int head, tail; unsigned long flags; save_flags(flags); cli(); globalwinon(ch); bc = ch->brdchan; head = bc->tin & (ch->txbufsize - 1); tail = bc->tout; if (tail != bc->tout) tail = bc->tout; tail &= (ch->txbufsize - 1); if((remain = tail - head - 1) < 0 ) remain += ch->txbufsize; if (remain && (ch->statusflags & LOWWAIT) == 0) { ch->statusflags |= LOWWAIT; bc->ilow = 1; } memoff(ch); restore_flags(flags); } return remain; } static int pcxe_chars_in_buffer(struct tty_struct *tty) { int chars; unsigned int ctail, head, tail; int remain; unsigned long flags; struct channel *ch; volatile struct board_chan *bc; if ((ch=chan(tty))==NULL) return(0); save_flags(flags); cli(); globalwinon(ch); bc = ch->brdchan; tail = bc->tout; head = bc->tin; ctail = ch->mailbox->cout; if(tail == head && ch->mailbox->cin == ctail && bc->tbusy == 0) chars = 0; else { head = bc->tin & (ch->txbufsize - 1); tail &= (ch->txbufsize - 1); if((remain = tail - head - 1) < 0 ) remain += ch->txbufsize; chars = (int)(ch->txbufsize - remain); /* * Make it possible to wakeup anything waiting for output * in tty_ioctl.c, etc. */ if(!(ch->statusflags & EMPTYWAIT)) setup_empty_event(tty,ch); } memoff(ch); restore_flags(flags); return(chars); } static void pcxe_flush_buffer(struct tty_struct *tty) { unsigned int tail; volatile struct board_chan *bc; struct channel *ch; unsigned long flags; if ((ch=chan(tty))==NULL) return; save_flags(flags); cli(); globalwinon(ch); bc = ch->brdchan; tail = bc->tout; fepcmd(ch, STOUT, (unsigned) tail, 0, 0, 0); memoff(ch); restore_flags(flags); wake_up_interruptible(&tty->write_wait); if((tty->flags & (1 << TTY_DO_WRITE_WAKEUP)) && tty->ldisc.write_wakeup) (tty->ldisc.write_wakeup)(tty); } static void pcxe_flush_chars(struct tty_struct *tty) { struct channel * ch; if ((ch=chan(tty))!=NULL) { unsigned long flags; save_flags(flags); cli(); if ((ch->statusflags & TXBUSY) && !(ch->statusflags & EMPTYWAIT)) setup_empty_event(tty,ch); restore_flags(flags); } } #ifndef MODULE /* * Driver setup function when linked into the kernel to optionally parse multible * "digi="-lines and initialize the driver at boot time. No probing. */ __initfunc(void pcxx_setup(char *str, int *ints)) { struct board_info board; int i, j, last; char *temp, *t2; unsigned len; numcards=0; memset(&board, 0, sizeof(board)); for(last=0,i=1;i<=ints[0];i++) switch(i) { case 1: board.status = ints[i]; last = i; break; case 2: board.type = ints[i]; last = i; break; case 3: board.altpin = ints[i]; last = i; break; case 4: board.numports = ints[i]; last = i; break; case 5: board.port = ints[i]; last = i; break; case 6: board.membase = ints[i]; last = i; break; default: printk("PC/Xx: Too many integer parms\n"); return; } while (str && *str) { /* find the next comma or terminator */ temp = str; while (*temp && (*temp != ',')) temp++; if (!*temp) temp = NULL; else *temp++ = 0; i = last + 1; switch(i) { case 1: len = strlen(str); if (strncmp("Disable", str, len) == 0) board.status = 0; else if (strncmp("Enable", str, len) == 0) board.status = 1; else { printk("PC/Xx: Invalid status %s\n", str); return; } last = i; break; case 2: for(j=0;j<PCXX_NUM_TYPES;j++) if (strcmp(board_desc[j], str) == 0) break; if (i<PCXX_NUM_TYPES) board.type = j; else { printk("PC/Xx: Invalid board name: %s\n", str); return; } last = i; break; case 3: len = strlen(str); if (strncmp("Disable", str, len) == 0) board.altpin = 0; else if (strncmp("Enable", str, len) == 0) board.altpin = 1; else { printk("PC/Xx: Invalid altpin %s\n", str); return; } last = i; break; case 4: t2 = str; while (isdigit(*t2)) t2++; if (*t2) { printk("PC/Xx: Invalid port count %s\n", str); return; } board.numports = simple_strtoul(str, NULL, 0); last = i; break; case 5: t2 = str; while (isxdigit(*t2)) t2++; if (*t2) { printk("PC/Xx: Invalid io port address %s\n", str); return; } board.port = simple_strtoul(str, NULL, 16); last = i; break; case 6: t2 = str; while (isxdigit(*t2)) t2++; if (*t2) { printk("PC/Xx: Invalid memory base %s\n", str); return; } board.membase = simple_strtoul(str, NULL, 16); last = i; break; default: printk("PC/Xx: Too many string parms\n"); return; } str = temp; } if (last < 6) { printk("PC/Xx: Insufficient parms specified\n"); return; } /* I should REALLY validate the stuff here */ memcpy(&boards[numcards],&board, sizeof(board)); printk("PC/Xx: Added board %i, %s %s %i ports at 0x%4.4X base 0x%6.6X\n", numcards, board_desc[board.type], board_mem[board.type], board.numports, board.port, (unsigned int) board.membase); /* keep track of my initial minor number */ if (numcards) boards[numcards].first_minor = boards[numcards-1].first_minor + boards[numcards-1].numports; else boards[numcards].first_minor = 0; /* yeha! string parameter was successful! */ numcards++; } #endif /* * function to initialize the driver with the given parameters, which are either * the default values from this file or the parameters given at boot. */ __initfunc(int pcxe_init(void)) { ulong memory_seg=0, memory_size=0; int lowwater, enabled_cards=0, i, crd, shrinkmem=0, topwin = 0xff00L, botwin=0x100L; unchar *fepos, *memaddr, *bios, v; volatile struct global_data *gd; volatile struct board_chan *bc; struct board_info *bd; struct channel *ch; printk(KERN_NOTICE "Digiboard PC/X{i,e,eve} driver v%s\n", VERSION); #ifdef MODULE for (i = 0; i < 4; i++) { if (io[i]) { numcards = 0; break; } } if (numcards == 0) { int first_minor = 0; for (i = 0; i < 4; i++) { if (io[i] == 0) { boards[i].port = 0; boards[i].status = DISABLED; } else { boards[i].port = (ushort)io[i]; boards[i].status = ENABLED; boards[i].first_minor = first_minor; numcards=i+1; } if (membase[i]) boards[i].membase = (ulong)membase[i]; else boards[i].membase = 0xD0000; if (memsize[i]) boards[i].memsize = (ulong)(memsize[i] * 1024); else boards[i].memsize = 0; if (altpin[i]) boards[i].altpin = ON; else boards[i].altpin = OFF; if (numports[i]) boards[i].numports = (ushort)numports[i]; else boards[i].numports = 16; first_minor += boards[i].numports; } } #endif if (numcards <= 0) { printk("PC/Xx: No cards configured, driver not active.\n"); return -EIO; } #if 1 if (debug) for (i = 0; i < numcards; i++) { printk("Card %d:status=%d, port=0x%x, membase=0x%lx, memsize=0x%lx, altpin=%d, numports=%d, first_minor=%d\n", i+1, boards[i].status, boards[i].port, boards[i].membase, boards[i].memsize, boards[i].altpin, boards[i].numports, boards[i].first_minor); } #endif for (i=0;i<numcards;i++) nbdevs += boards[i].numports; if (nbdevs <= 0) { printk("PC/Xx: No devices activated, driver not active.\n"); return -EIO; } /* * this turns out to be more memory efficient, as there are no * unused spaces. */ digi_channels = kmalloc(sizeof(struct channel) * nbdevs, GFP_KERNEL); if (!digi_channels) panic("Unable to allocate digi_channel struct"); memset(digi_channels, 0, sizeof(struct channel) * nbdevs); pcxe_table = kmalloc(sizeof(struct tty_struct *) * nbdevs, GFP_KERNEL); if (!pcxe_table) panic("Unable to allocate pcxe_table struct"); memset(pcxe_table, 0, sizeof(struct tty_struct *) * nbdevs); pcxe_termios = kmalloc(sizeof(struct termios *) * nbdevs, GFP_KERNEL); if (!pcxe_termios) panic("Unable to allocate pcxe_termios struct"); memset(pcxe_termios,0,sizeof(struct termios *)*nbdevs); pcxe_termios_locked = kmalloc(sizeof(struct termios *) * nbdevs, GFP_KERNEL); if (!pcxe_termios_locked) panic("Unable to allocate pcxe_termios_locked struct"); memset(pcxe_termios_locked,0,sizeof(struct termios *)*nbdevs); init_bh(DIGI_BH,do_pcxe_bh); enable_bh(DIGI_BH); timer_table[DIGI_TIMER].fn = pcxxpoll; timer_table[DIGI_TIMER].expires = 0; memset(&pcxe_driver, 0, sizeof(struct tty_driver)); pcxe_driver.magic = TTY_DRIVER_MAGIC; pcxe_driver.name = "ttyD"; pcxe_driver.major = DIGI_MAJOR; pcxe_driver.minor_start = 0; pcxe_driver.num = nbdevs; pcxe_driver.type = TTY_DRIVER_TYPE_SERIAL; pcxe_driver.subtype = SERIAL_TYPE_NORMAL; pcxe_driver.init_termios = tty_std_termios; pcxe_driver.init_termios.c_cflag = B9600 | CS8 | CREAD | HUPCL; pcxe_driver.flags = TTY_DRIVER_REAL_RAW; pcxe_driver.refcount = &pcxe_refcount; pcxe_driver.table = pcxe_table; pcxe_driver.termios = pcxe_termios; pcxe_driver.termios_locked = pcxe_termios_locked; pcxe_driver.open = pcxe_open; pcxe_driver.close = pcxe_close; pcxe_driver.write = pcxe_write; pcxe_driver.put_char = pcxe_put_char; pcxe_driver.flush_chars = pcxe_flush_chars; pcxe_driver.write_room = pcxe_write_room; pcxe_driver.chars_in_buffer = pcxe_chars_in_buffer; pcxe_driver.flush_buffer = pcxe_flush_buffer; pcxe_driver.ioctl = pcxe_ioctl; pcxe_driver.throttle = pcxe_throttle; pcxe_driver.unthrottle = pcxe_unthrottle; pcxe_driver.set_termios = pcxe_set_termios; pcxe_driver.stop = pcxe_stop; pcxe_driver.start = pcxe_start; pcxe_driver.hangup = pcxe_hangup; pcxe_callout = pcxe_driver; pcxe_callout.name = "cud"; pcxe_callout.major = DIGICU_MAJOR; pcxe_callout.subtype = SERIAL_TYPE_CALLOUT; pcxe_callout.init_termios.c_cflag = B9600 | CS8 | CREAD | HUPCL | CLOCAL; for(crd=0; crd < numcards; crd++) { bd = &boards[crd]; outb(FEPRST, bd->port); pcxxdelay(1); for(i=0; (inb(bd->port) & FEPMASK) != FEPRST; i++) { if(i > 100) { printk("PC/Xx: Board not found at port 0x%x! Check switch settings.\n", bd->port); bd->status = DISABLED; break; } #ifdef MODULE schedule(); #endif pcxxdelay(10); } if(bd->status == DISABLED) continue; v = inb(bd->port); if((v & 0x1) == 0x1) { if((v & 0x30) == 0) { /* PC/Xi 64K card */ memory_seg = 0xf000; memory_size = 0x10000; } if((v & 0x30) == 0x10) { /* PC/Xi 128K card */ memory_seg = 0xe000; memory_size = 0x20000; } if((v & 0x30) == 0x20) { /* PC/Xi 256K card */ memory_seg = 0xc000; memory_size = 0x40000; } if((v & 0x30) == 0x30) { /* PC/Xi 512K card */ memory_seg = 0x8000; memory_size = 0x80000; } bd->type = PCXI; } else { if((v & 0x1) == 0x1) { bd->status = DISABLED; /* PC/Xm unsupported card */ printk("PC/Xx: PC/Xm at 0x%x not supported!!\n", bd->port); continue; } else { if(v & 0xC0) { topwin = 0x1f00L; outb((((ulong)bd->membase>>8) & 0xe0) | 0x10, bd->port+2); outb(((ulong)bd->membase>>16) & 0xff, bd->port+3); bd->type = PCXEVE; /* PC/Xe 8K card */ } else { bd->type = PCXE; /* PC/Xe 64K card */ } memory_seg = 0xf000; memory_size = 0x10000; } } if (verbose) printk("Configuring card %d as a %s %ldK card. io=0x%x, mem=%lx-%lx\n", crd+1, board_desc[bd->type], memory_size/1024, bd->port,bd->membase,bd->membase+memory_size-1); if (boards[crd].memsize == 0) boards[crd].memsize = memory_size; else if (boards[crd].memsize != memory_size) { printk("PC/Xx: memory size mismatch:supplied=%lx(%ldK) probed=%ld(%ldK)\n", boards[crd].memsize, boards[crd].memsize / 1024, memory_size, memory_size / 1024); continue; } memaddr = (unchar *)phys_to_virt(bd->membase); if (verbose) printk("Resetting board and testing memory access:"); outb(FEPRST|FEPMEM, bd->port); for(i=0; (inb(bd->port) & FEPMASK) != (FEPRST|FEPMEM); i++) { if(i > 1000) { printk("\nPC/Xx: %s not resetting at port 0x%x! Check switch settings.\n", board_desc[bd->type], bd->port); bd->status = DISABLED; break; } #ifdef MODULE schedule(); #endif pcxxdelay(1); } if(bd->status == DISABLED) continue; memwinon(bd,0); *(ulong *)(memaddr + botwin) = 0xa55a3cc3; *(ulong *)(memaddr + topwin) = 0x5aa5c33c; if(*(ulong *)(memaddr + botwin) != 0xa55a3cc3 || *(ulong *)(memaddr + topwin) != 0x5aa5c33c) { printk("PC/Xx: Failed memory test at %lx for %s at port %x, check switch settings.\n", bd->membase, board_desc[bd->type], bd->port); bd->status = DISABLED; continue; } if (verbose) printk(" done.\n"); for(i=0; i < 16; i++) { memaddr[MISCGLOBAL+i] = 0; } if(bd->type == PCXI || bd->type == PCXE) { bios = memaddr + BIOSCODE + ((0xf000 - memory_seg) << 4); if (verbose) printk("Downloading BIOS to 0x%lx:", virt_to_phys(bios)); memcpy(bios, pcxx_bios, pcxx_nbios); if (verbose) printk(" done.\n"); outb(FEPMEM, bd->port); if (verbose) printk("Waiting for BIOS to become ready"); for(i=1; i <= 30; i++) { if(*(ushort *)((ulong)memaddr + MISCGLOBAL) == *(ushort *)"GD" ) { goto load_fep; } if (verbose) { printk("."); if (i % 50 == 0) printk("\n"); } #ifdef MODULE schedule(); #endif pcxxdelay(50); } printk("\nPC/Xx: BIOS download failed for board at 0x%x(addr=%lx-%lx)!\n", bd->port, bd->membase, bd->membase+bd->memsize); bd->status = DISABLED; continue; } if(bd->type == PCXEVE) { bios = memaddr + (BIOSCODE & 0x1fff); memwinon(bd,0xff); memcpy(bios, pcxx_bios, pcxx_nbios); outb(FEPCLR, bd->port); memwinon(bd,0); for(i=0; i <= 1000; i++) { if(*(ushort *)((ulong)memaddr + MISCGLOBAL) == *(ushort *)"GD" ) { goto load_fep; } if (verbose) { printk("."); if (i % 50 == 0) printk("\n"); } #ifdef MODULE schedule(); #endif pcxxdelay(10); } printk("\nPC/Xx: BIOS download failed on the %s at 0x%x!\n", board_desc[bd->type], bd->port); bd->status = DISABLED; continue; } load_fep: fepos = memaddr + FEPCODE; if(bd->type == PCXEVE) fepos = memaddr + (FEPCODE & 0x1fff); if (verbose) printk(" ok.\nDownloading FEP/OS to 0x%lx:", virt_to_phys(fepos)); memwinon(bd, (FEPCODE >> 13)); memcpy(fepos, pcxx_cook, pcxx_ncook); memwinon(bd, 0); if (verbose) printk(" done.\n"); *(ushort *)((ulong)memaddr + MBOX + 0) = 2; *(ushort *)((ulong)memaddr + MBOX + 2) = memory_seg + FEPCODESEG; *(ushort *)((ulong)memaddr + MBOX + 4) = 0; *(ushort *)((ulong)memaddr + MBOX + 6) = FEPCODESEG; *(ushort *)((ulong)memaddr + MBOX + 8) = 0; *(ushort *)((ulong)memaddr + MBOX + 10) = pcxx_ncook; outb(FEPMEM|FEPINT, bd->port); outb(FEPMEM, bd->port); for(i=0; *(ushort *)((ulong)memaddr + MBOX); i++) { if(i > 2000) { printk("PC/Xx: Command failed for the %s at 0x%x!\n", board_desc[bd->type], bd->port); bd->status = DISABLED; break; } #ifdef MODULE schedule(); #endif pcxxdelay(1); } if(bd->status == DISABLED) continue; if (verbose) printk("Waiting for FEP/OS to become ready"); *(ushort *)(memaddr + FEPSTAT) = 0; *(ushort *)(memaddr + MBOX + 0) = 1; *(ushort *)(memaddr + MBOX + 2) = FEPCODESEG; *(ushort *)(memaddr + MBOX + 4) = 0x4L; outb(FEPINT, bd->port); outb(FEPCLR, bd->port); memwinon(bd, 0); for(i=1; *(ushort *)((ulong)memaddr + FEPSTAT) != *(ushort *)"OS"; i++) { if(i > 1000) { printk("\nPC/Xx: FEP/OS download failed on the %s at 0x%x!\n", board_desc[bd->type], bd->port); bd->status = DISABLED; break; } if (verbose) { printk("."); if (i % 50 == 0) printk("\n%5d",i/50); } #ifdef MODULE schedule(); #endif pcxxdelay(1); } if(bd->status == DISABLED) continue; if (verbose) printk(" ok.\n"); ch = digi_channels+bd->first_minor; pcxxassert(ch < digi_channels+nbdevs, "ch out of range"); bc = (volatile struct board_chan *)((ulong)memaddr + CHANSTRUCT); gd = (volatile struct global_data *)((ulong)memaddr + GLOBAL); if((bd->type == PCXEVE) && (*(ushort *)((ulong)memaddr+NPORT) < 3)) shrinkmem = 1; request_region(bd->port, 4, "PC/Xx"); for(i=0; i < bd->numports; i++, ch++, bc++) { if(((ushort *)((ulong)memaddr + PORTBASE))[i] == 0) { ch->brdchan = 0; continue; } ch->brdchan = bc; ch->mailbox = gd; ch->tqueue.routine = do_softint; ch->tqueue.data = ch; ch->board = &boards[crd]; #ifdef DEFAULT_HW_FLOW ch->digiext.digi_flags = RTSPACE|CTSPACE; #endif if(boards[crd].altpin) { ch->dsr = CD; ch->dcd = DSR; ch->digiext.digi_flags |= DIGI_ALTPIN; } else { ch->dcd = CD; ch->dsr = DSR; } ch->magic = PCXX_MAGIC; ch->boardnum = crd; ch->channelnum = i; ch->dev = bd->first_minor + i; ch->tty = 0; if(shrinkmem) { fepcmd(ch, SETBUFFER, 32, 0, 0, 0); shrinkmem = 0; } if(bd->type != PCXEVE) { ch->txptr = memaddr+((bc->tseg-memory_seg) << 4); ch->rxptr = memaddr+((bc->rseg-memory_seg) << 4); ch->txwin = ch->rxwin = 0; } else { ch->txptr = memaddr+(((bc->tseg-memory_seg) << 4) & 0x1fff); ch->txwin = FEPWIN | ((bc->tseg-memory_seg) >> 9); ch->rxptr = memaddr+(((bc->rseg-memory_seg) << 4) & 0x1fff); ch->rxwin = FEPWIN | ((bc->rseg-memory_seg) >>9 ); } ch->txbufsize = bc->tmax + 1; ch->rxbufsize = bc->rmax + 1; ch->tmp_buf = kmalloc(ch->txbufsize,GFP_KERNEL); lowwater = ch->txbufsize >= 2000 ? 1024 : ch->txbufsize/2; fepcmd(ch, STXLWATER, lowwater, 0, 10, 0); fepcmd(ch, SRXLWATER, ch->rxbufsize/4, 0, 10, 0); fepcmd(ch, SRXHWATER, 3 * ch->rxbufsize/4, 0, 10, 0); bc->edelay = 100; bc->idata = 1; ch->startc = bc->startc; ch->stopc = bc->stopc; ch->startca = bc->startca; ch->stopca = bc->stopca; ch->fepcflag = 0; ch->fepiflag = 0; ch->fepoflag = 0; ch->fepstartc = 0; ch->fepstopc = 0; ch->fepstartca = 0; ch->fepstopca = 0; ch->close_delay = 50; ch->count = 0; ch->blocked_open = 0; ch->callout_termios = pcxe_callout.init_termios; ch->normal_termios = pcxe_driver.init_termios; ch->open_wait = 0; ch->close_wait = 0; ch->asyncflags = 0; } if (verbose) printk("Card No. %d ready: %s (%s) I/O=0x%x Mem=0x%lx Ports=%d\n", crd+1, board_desc[bd->type], board_mem[bd->type], bd->port, bd->membase, bd->numports); else printk("PC/Xx: %s (%s) I/O=0x%x Mem=0x%lx Ports=%d\n", board_desc[bd->type], board_mem[bd->type], bd->port, bd->membase, bd->numports); memwinoff(bd, 0); enabled_cards++; } if (enabled_cards <= 0) { printk(KERN_NOTICE "PC/Xx: No cards enabled, no driver.\n"); return -EIO; } if(tty_register_driver(&pcxe_driver)) panic("Couldn't register PC/Xe driver"); if(tty_register_driver(&pcxe_callout)) panic("Couldn't register PC/Xe callout"); /* * Start up the poller to check for events on all enabled boards */ timer_active |= 1 << DIGI_TIMER; if (verbose) printk(KERN_NOTICE "PC/Xx: Driver with %d card(s) ready.\n", enabled_cards); return 0; } static void pcxxpoll(void) { unsigned long flags; int crd; volatile unsigned int head, tail; struct channel *ch; struct board_info *bd; save_flags(flags); cli(); for(crd=0; crd < numcards; crd++) { bd = &boards[crd]; ch = digi_channels+bd->first_minor; if(bd->status == DISABLED) continue; assertmemoff(ch); globalwinon(ch); head = ch->mailbox->ein; tail = ch->mailbox->eout; if(head != tail) doevent(crd); memoff(ch); } timer_table[DIGI_TIMER].fn = pcxxpoll; timer_table[DIGI_TIMER].expires = jiffies + HZ/25; timer_active |= 1 << DIGI_TIMER; restore_flags(flags); } static void doevent(int crd) { volatile struct board_info *bd; static struct tty_struct *tty; volatile struct board_chan *bc; volatile unchar *eventbuf; volatile unsigned int head; volatile unsigned int tail; struct channel *ch; struct channel *chan0; int channel, event, mstat, lstat; bd = &boards[crd]; chan0 = digi_channels+bd->first_minor; pcxxassert(chan0 < digi_channels+nbdevs, "ch out of range"); assertgwinon(chan0); while ((tail = chan0->mailbox->eout) != (head = chan0->mailbox->ein)) { assertgwinon(chan0); eventbuf = (volatile unchar *)phys_to_virt(bd->membase + tail + ISTART); channel = eventbuf[0]; event = eventbuf[1]; mstat = eventbuf[2]; lstat = eventbuf[3]; ch=chan0+channel; if ((unsigned)channel >= bd->numports || !ch) { printk("physmem=%lx, tail=%x, head=%x\n", bd->membase, tail, head); printk("doevent(%x) channel %x, event %x, mstat %x, lstat %x\n", crd, (unsigned)channel, event, (unsigned)mstat, lstat); if(channel >= bd->numports) ch = chan0; bc = ch->brdchan; goto next; } if ((bc = ch->brdchan) == NULL) goto next; if (event & DATA_IND) { receive_data(ch); assertgwinon(ch); } if (event & MODEMCHG_IND) { ch->imodem = mstat; if (ch->asyncflags & (ASYNC_NORMAL_ACTIVE|ASYNC_CALLOUT_ACTIVE)) { if (ch->asyncflags & ASYNC_CHECK_CD) { if (mstat & ch->dcd) { wake_up_interruptible(&ch->open_wait); } else { pcxe_sched_event(ch, PCXE_EVENT_HANGUP); } } } } tty = ch->tty; if (tty) { if (event & BREAK_IND) { tty->flip.count++; *tty->flip.flag_buf_ptr++ = TTY_BREAK; *tty->flip.char_buf_ptr++ = 0; #if 0 if (ch->asyncflags & ASYNC_SAK) do_SAK(tty); #endif tty_schedule_flip(tty); } if (event & LOWTX_IND) { if (ch->statusflags & LOWWAIT) { ch->statusflags &= ~LOWWAIT; if ((tty->flags & (1 << TTY_DO_WRITE_WAKEUP)) && tty->ldisc.write_wakeup) (tty->ldisc.write_wakeup)(tty); wake_up_interruptible(&tty->write_wait); } } if (event & EMPTYTX_IND) { ch->statusflags &= ~TXBUSY; if (ch->statusflags & EMPTYWAIT) { ch->statusflags &= ~EMPTYWAIT; if ((tty->flags & (1 << TTY_DO_WRITE_WAKEUP)) && tty->ldisc.write_wakeup) (tty->ldisc.write_wakeup)(tty); wake_up_interruptible(&tty->write_wait); } } } next: globalwinon(ch); if(!bc) printk("bc == NULL in doevent!\n"); else bc->idata = 1; chan0->mailbox->eout = (tail+4) & (IMAX-ISTART-4); globalwinon(chan0); } } /* * pcxxdelay - delays a specified number of milliseconds */ static void pcxxdelay(int msec) { while(msec-- > 0) __delay(loops_per_sec/1000); } static void fepcmd(struct channel *ch, int cmd, int word_or_byte, int byte2, int ncmds, int bytecmd) { unchar *memaddr; unsigned int head, tail; long count; int n; if(ch->board->status == DISABLED) return; assertgwinon(ch); memaddr = (unchar *)phys_to_virt(ch->board->membase); head = ch->mailbox->cin; if(head >= (CMAX-CSTART) || (head & 03)) { printk("line %d: Out of range, cmd=%x, head=%x\n", __LINE__, cmd, head); return; } if(bytecmd) { *(unchar *)(memaddr+head+CSTART+0) = cmd; *(unchar *)(memaddr+head+CSTART+1) = ch->dev - ch->board->first_minor; *(unchar *)(memaddr+head+CSTART+2) = word_or_byte; *(unchar *)(memaddr+head+CSTART+3) = byte2; } else { *(unchar *)(memaddr+head+CSTART+0) = cmd; *(unchar *)(memaddr+head+CSTART+1) = ch->dev - ch->board->first_minor; *(ushort*)(memaddr+head+CSTART+2) = word_or_byte; } head = (head+4) & (CMAX-CSTART-4); ch->mailbox->cin = head; count = FEPTIMEOUT; while(1) { count--; if(count == 0) { printk("Fep not responding in fepcmd()\n"); return; } head = ch->mailbox->cin; tail = ch->mailbox->cout; n = (head-tail) & (CMAX-CSTART-4); if(n <= ncmds * (sizeof(short)*4)) break; /* Seems not to be good here: schedule(); */ } } static unsigned termios2digi_c(struct channel *ch, unsigned cflag) { unsigned res = 0; #ifdef SPEED_HACK /* CL: HACK to force 115200 at 38400 and 57600 at 19200 Baud */ if ((cflag & CBAUD)== B38400) cflag=cflag - B38400 + B115200; if ((cflag & CBAUD)== B19200) cflag=cflag - B19200 + B57600; #endif if (cflag & CBAUDEX) { ch->digiext.digi_flags |= DIGI_FAST; res |= FEP_HUPCL; /* This gets strange but if we don't do this we will get 78600 * instead of 115200. 57600 is mapped to 50 baud yielding 57600 in * FAST mode. 115200 is mapped to 75. We need to map it to 110 to * do 115K */ if (cflag & B115200) res|=1; } else ch->digiext.digi_flags &= ~DIGI_FAST; res |= cflag & (CBAUD | PARODD | PARENB | CSTOPB | CSIZE | CLOCAL); return res; } static unsigned termios2digi_i(struct channel *ch, unsigned iflag) { unsigned res = iflag & (IGNBRK|BRKINT|IGNPAR|PARMRK|INPCK|ISTRIP|IXON|IXANY|IXOFF); if(ch->digiext.digi_flags & DIGI_AIXON) res |= IAIXON; return res; } static unsigned termios2digi_h(struct channel *ch, unsigned cflag) { unsigned res = 0; if(cflag & CRTSCTS) { ch->digiext.digi_flags |= (RTSPACE|CTSPACE); res |= (CTS | RTS); } if(ch->digiext.digi_flags & RTSPACE) res |= RTS; if(ch->digiext.digi_flags & DTRPACE) res |= DTR; if(ch->digiext.digi_flags & CTSPACE) res |= CTS; if(ch->digiext.digi_flags & DSRPACE) res |= ch->dsr; if(ch->digiext.digi_flags & DCDPACE) res |= ch->dcd; if (res & RTS) ch->digiext.digi_flags |= RTSPACE; if (res & CTS) ch->digiext.digi_flags |= CTSPACE; return res; } static void pcxxparam(struct tty_struct *tty, struct channel *ch) { volatile struct board_chan *bc; unsigned int head; unsigned mval, hflow, cflag, iflag; struct termios *ts; bc = ch->brdchan; assertgwinon(ch); ts = tty->termios; if((ts->c_cflag & CBAUD) == 0) { head = bc->rin; bc->rout = head; head = bc->tin; fepcmd(ch, STOUT, (unsigned) head, 0, 0, 0); mval = 0; } else { cflag = termios2digi_c(ch, ts->c_cflag); if(cflag != ch->fepcflag) { ch->fepcflag = cflag; fepcmd(ch, SETCTRLFLAGS, (unsigned) cflag, 0, 0, 0); } if(cflag & CLOCAL) ch->asyncflags &= ~ASYNC_CHECK_CD; else { ch->asyncflags |= ASYNC_CHECK_CD; } mval = DTR | RTS; } iflag = termios2digi_i(ch, ts->c_iflag); if(iflag != ch->fepiflag) { ch->fepiflag = iflag; fepcmd(ch, SETIFLAGS, (unsigned int) ch->fepiflag, 0, 0, 0); } bc->mint = ch->dcd; if((ts->c_cflag & CLOCAL) || (ch->digiext.digi_flags & DIGI_FORCEDCD)) if(ch->digiext.digi_flags & DIGI_FORCEDCD) bc->mint = 0; ch->imodem = bc->mstat; hflow = termios2digi_h(ch, ts->c_cflag); if(hflow != ch->hflow) { ch->hflow = hflow; fepcmd(ch, SETHFLOW, hflow, 0xff, 0, 1); } /* mval ^= ch->modemfake & (mval ^ ch->modem); */ if(ch->omodem != mval) { ch->omodem = mval; fepcmd(ch, SETMODEM, mval, RTS|DTR, 0, 1); } if(ch->startc != ch->fepstartc || ch->stopc != ch->fepstopc) { ch->fepstartc = ch->startc; ch->fepstopc = ch->stopc; fepcmd(ch, SONOFFC, ch->fepstartc, ch->fepstopc, 0, 1); } if(ch->startca != ch->fepstartca || ch->stopca != ch->fepstopca) { ch->fepstartca = ch->startca; ch->fepstopca = ch->stopca; fepcmd(ch, SAUXONOFFC, ch->fepstartca, ch->fepstopca, 0, 1); } } static void receive_data(struct channel *ch) { volatile struct board_chan *bc; struct tty_struct *tty; unsigned int tail, head, wrapmask; int n; int piece; struct termios *ts=0; unchar *rptr; int rc; int wrapgap; globalwinon(ch); if (ch->statusflags & RXSTOPPED) return; tty = ch->tty; if(tty) ts = tty->termios; bc = ch->brdchan; if(!bc) { printk("bc is NULL in receive_data!\n"); return; } wrapmask = ch->rxbufsize - 1; head = bc->rin; head &= wrapmask; tail = bc->rout & wrapmask; n = (head-tail) & wrapmask; if(n == 0) return; /* * If CREAD bit is off or device not open, set TX tail to head */ if(!tty || !ts || !(ts->c_cflag & CREAD)) { bc->rout = head; return; } if(tty->flip.count == TTY_FLIPBUF_SIZE) { /* printk("tty->flip.count = TTY_FLIPBUF_SIZE\n"); */ return; } if(bc->orun) { bc->orun = 0; printk("overrun! DigiBoard device minor=%d\n",MINOR(tty->device)); } rxwinon(ch); rptr = tty->flip.char_buf_ptr; rc = tty->flip.count; while(n > 0) { wrapgap = (head >= tail) ? head - tail : ch->rxbufsize - tail; piece = (wrapgap < n) ? wrapgap : n; /* * Make sure we don't overflow the buffer */ if ((rc + piece) > TTY_FLIPBUF_SIZE) piece = TTY_FLIPBUF_SIZE - rc; if (piece == 0) break; memcpy(rptr, ch->rxptr + tail, piece); rptr += piece; rc += piece; tail = (tail + piece) & wrapmask; n -= piece; } tty->flip.count = rc; tty->flip.char_buf_ptr = rptr; globalwinon(ch); bc->rout = tail; /* Must be called with global data */ tty_schedule_flip(ch->tty); return; } static int pcxe_ioctl(struct tty_struct *tty, struct file * file, unsigned int cmd, unsigned long arg) { int error; struct channel *ch = (struct channel *) tty->driver_data; volatile struct board_chan *bc; int retval; unsigned int mflag, mstat; unsigned char startc, stopc; unsigned long flags; digiflow_t dflow; if(ch) bc = ch->brdchan; else { printk("ch is NULL in pcxe_ioctl!\n"); return(-EINVAL); } save_flags(flags); switch(cmd) { case TCSBRK: /* SVID version: non-zero arg --> no break */ retval = tty_check_change(tty); if(retval) return retval; setup_empty_event(tty,ch); tty_wait_until_sent(tty, 0); if(!arg) digi_send_break(ch, HZ/4); /* 1/4 second */ return 0; case TCSBRKP: /* support for POSIX tcsendbreak() */ retval = tty_check_change(tty); if(retval) return retval; setup_empty_event(tty,ch); tty_wait_until_sent(tty, 0); digi_send_break(ch, arg ? arg*(HZ/10) : HZ/4); return 0; case TIOCGSOFTCAR: return put_user(C_CLOCAL(tty) ? 1 : 0, (unsigned int *) arg); case TIOCSSOFTCAR: { unsigned int value; error = get_user( value, (unsigned int *) arg); if (error) return error; tty->termios->c_cflag = ((tty->termios->c_cflag & ~CLOCAL) | (value ? CLOCAL : 0)); } return 0; case TIOCMODG: case TIOCMGET: mflag = 0; cli(); globalwinon(ch); mstat = bc->mstat; memoff(ch); restore_flags(flags); if(mstat & DTR) mflag |= TIOCM_DTR; if(mstat & RTS) mflag |= TIOCM_RTS; if(mstat & CTS) mflag |= TIOCM_CTS; if(mstat & ch->dsr) mflag |= TIOCM_DSR; if(mstat & RI) mflag |= TIOCM_RI; if(mstat & ch->dcd) mflag |= TIOCM_CD; error = put_user(mflag, (unsigned int *) arg); if(error) return error; break; case TIOCMBIS: case TIOCMBIC: case TIOCMODS: case TIOCMSET: error = get_user(mstat, (unsigned int *) arg); if(error) return error; mflag = 0; if(mstat & TIOCM_DTR) mflag |= DTR; if(mstat & TIOCM_RTS) mflag |= RTS; switch(cmd) { case TIOCMODS: case TIOCMSET: ch->modemfake = DTR|RTS; ch->modem = mflag; break; case TIOCMBIS: ch->modemfake |= mflag; ch->modem |= mflag; break; case TIOCMBIC: ch->modemfake &= ~mflag; ch->modem &= ~mflag; break; } cli(); globalwinon(ch); pcxxparam(tty,ch); memoff(ch); restore_flags(flags); break; case TIOCSDTR: cli(); ch->omodem |= DTR; globalwinon(ch); fepcmd(ch, SETMODEM, DTR, 0, 10, 1); memoff(ch); restore_flags(flags); break; case TIOCCDTR: ch->omodem &= ~DTR; cli(); globalwinon(ch); fepcmd(ch, SETMODEM, 0, DTR, 10, 1); memoff(ch); restore_flags(flags); break; case DIGI_GETA: if((error=verify_area(VERIFY_WRITE, (char*)arg, sizeof(digi_t)))) return(error); copy_to_user((char*)arg, &ch->digiext, sizeof(digi_t)); break; case DIGI_SETAW: case DIGI_SETAF: if(cmd == DIGI_SETAW) { setup_empty_event(tty,ch); tty_wait_until_sent(tty, 0); } else { if(tty->ldisc.flush_buffer) tty->ldisc.flush_buffer(tty); } /* Fall Thru */ case DIGI_SETA: if((error=verify_area(VERIFY_READ, (char*)arg,sizeof(digi_t)))) return(error); copy_from_user(&ch->digiext, (char*)arg, sizeof(digi_t)); #ifdef DEBUG_IOCTL printk("ioctl(DIGI_SETA): flags = %x\n", ch->digiext.digi_flags); #endif if(ch->digiext.digi_flags & DIGI_ALTPIN) { ch->dcd = DSR; ch->dsr = CD; } else { ch->dcd = CD; ch->dsr = DSR; } cli(); globalwinon(ch); pcxxparam(tty,ch); memoff(ch); restore_flags(flags); break; case DIGI_GETFLOW: case DIGI_GETAFLOW: cli(); globalwinon(ch); if(cmd == DIGI_GETFLOW) { dflow.startc = bc->startc; dflow.stopc = bc->stopc; } else { dflow.startc = bc->startca; dflow.stopc = bc->stopca; } memoff(ch); restore_flags(flags); if((error=verify_area(VERIFY_WRITE, (char*)arg,sizeof(dflow)))) return(error); copy_to_user((char*)arg, &dflow, sizeof(dflow)); break; case DIGI_SETAFLOW: case DIGI_SETFLOW: if(cmd == DIGI_SETFLOW) { startc = ch->startc; stopc = ch->stopc; } else { startc = ch->startca; stopc = ch->stopca; } if((error=verify_area(VERIFY_READ, (char*)arg,sizeof(dflow)))) return(error); copy_from_user(&dflow, (char*)arg, sizeof(dflow)); if(dflow.startc != startc || dflow.stopc != stopc) { cli(); globalwinon(ch); if(cmd == DIGI_SETFLOW) { ch->fepstartc = ch->startc = dflow.startc; ch->fepstopc = ch->stopc = dflow.stopc; fepcmd(ch,SONOFFC,ch->fepstartc,ch->fepstopc,0, 1); } else { ch->fepstartca = ch->startca = dflow.startc; ch->fepstopca = ch->stopca = dflow.stopc; fepcmd(ch, SAUXONOFFC, ch->fepstartca, ch->fepstopca, 0, 1); } if(ch->statusflags & TXSTOPPED) pcxe_start(tty); memoff(ch); restore_flags(flags); } break; default: return -ENOIOCTLCMD; } return 0; } static void pcxe_set_termios(struct tty_struct *tty, struct termios *old_termios) { struct channel *info; if ((info=chan(tty))!=NULL) { unsigned long flags; save_flags(flags); cli(); globalwinon(info); pcxxparam(tty,info); memoff(info); if ((old_termios->c_cflag & CRTSCTS) && ((tty->termios->c_cflag & CRTSCTS) == 0)) tty->hw_stopped = 0; if(!(old_termios->c_cflag & CLOCAL) && (tty->termios->c_cflag & CLOCAL)) wake_up_interruptible(&info->open_wait); restore_flags(flags); } } static void do_pcxe_bh(void) { run_task_queue(&tq_pcxx); } static void do_softint(void *private_) { struct channel *info = (struct channel *) private_; if(info && info->magic == PCXX_MAGIC) { struct tty_struct *tty = info->tty; if (tty && tty->driver_data) { if(test_and_clear_bit(PCXE_EVENT_HANGUP, &info->event)) { tty_hangup(tty); wake_up_interruptible(&info->open_wait); info->asyncflags &= ~(ASYNC_NORMAL_ACTIVE|ASYNC_CALLOUT_ACTIVE); } } } } static void pcxe_stop(struct tty_struct *tty) { struct channel *info; if ((info=chan(tty))!=NULL) { unsigned long flags; save_flags(flags); cli(); if ((info->statusflags & TXSTOPPED) == 0) { globalwinon(info); fepcmd(info, PAUSETX, 0, 0, 0, 0); info->statusflags |= TXSTOPPED; memoff(info); } restore_flags(flags); } } static void pcxe_throttle(struct tty_struct * tty) { struct channel *info; if ((info=chan(tty))!=NULL) { unsigned long flags; save_flags(flags); cli(); if ((info->statusflags & RXSTOPPED) == 0) { globalwinon(info); fepcmd(info, PAUSERX, 0, 0, 0, 0); info->statusflags |= RXSTOPPED; memoff(info); } restore_flags(flags); } } static void pcxe_unthrottle(struct tty_struct *tty) { struct channel *info; if ((info=chan(tty)) != NULL) { unsigned long flags; /* Just in case output was resumed because of a change in Digi-flow */ save_flags(flags); cli(); if(info->statusflags & RXSTOPPED) { volatile struct board_chan *bc; globalwinon(info); bc = info->brdchan; fepcmd(info, RESUMERX, 0, 0, 0, 0); info->statusflags &= ~RXSTOPPED; memoff(info); } restore_flags(flags); } } static void pcxe_start(struct tty_struct *tty) { struct channel *info; if ((info=chan(tty))!=NULL) { unsigned long flags; save_flags(flags); cli(); /* Just in case output was resumed because of a change in Digi-flow */ if(info->statusflags & TXSTOPPED) { volatile struct board_chan *bc; globalwinon(info); bc = info->brdchan; if(info->statusflags & LOWWAIT) bc->ilow = 1; fepcmd(info, RESUMETX, 0, 0, 0, 0); info->statusflags &= ~TXSTOPPED; memoff(info); } restore_flags(flags); } } void digi_send_break(struct channel *ch, int msec) { unsigned long flags; save_flags(flags); cli(); globalwinon(ch); /* * Maybe I should send an infinite break here, schedule() for * msec amount of time, and then stop the break. This way, * the user can't screw up the FEP by causing digi_send_break() * to be called (i.e. via an ioctl()) more than once in msec amount * of time. Try this for now... */ fepcmd(ch, SENDBREAK, msec, 0, 10, 0); memoff(ch); restore_flags(flags); } static void setup_empty_event(struct tty_struct *tty, struct channel *ch) { volatile struct board_chan *bc; unsigned long flags; save_flags(flags); cli(); globalwinon(ch); ch->statusflags |= EMPTYWAIT; bc = ch->brdchan; bc->iempty = 1; memoff(ch); restore_flags(flags); } |