51#include <sys/ioctl_compat.h> 52#endif 53#include <sys/tty.h> 54#include <sys/conf.h> 55#include <sys/fcntl.h> 56#include <sys/kernel.h> 57#include <sys/malloc.h> 58#include <sys/sysctl.h> 59#include <sys/bus.h> 60#include <machine/bus.h> 61#include <sys/rman.h> 62#include <machine/resource.h> 63 64 65#include <vm/vm.h> 66#include <vm/pmap.h> 67 68#include <machine/stdarg.h> 69 70#include <dev/si/sireg.h> 71#include <dev/si/sivar.h> 72#include <dev/si/si.h> 73 74/* 75 * This device driver is designed to interface the Specialix International 76 * SI, XIO and SX range of serial multiplexor cards to FreeBSD on an ISA, 77 * EISA or PCI bus machine. 78 * 79 * The controller is interfaced to the host via dual port RAM 80 * and an interrupt. 81 * 82 * The code for the Host 1 (very old ISA cards) has not been tested. 83 */ 84 85#define POLL /* turn on poller to scan for lost interrupts */ 86#define REALPOLL /* on each poll, scan for work regardless */ 87#define POLLHZ (hz/10) /* 10 times per second */ 88#define SI_I_HIGH_WATER (TTYHOG - 2 * SI_BUFFERSIZE) 89#define INT_COUNT 25000 /* max of 125 ints per second */ 90#define JET_INT_COUNT 100 /* max of 100 ints per second */ 91#define RXINT_COUNT 1 /* one rxint per 10 milliseconds */ 92 93enum si_mctl { GET, SET, BIS, BIC }; 94 95static void si_command(struct si_port *, int, int); 96static int si_modem(struct si_port *, enum si_mctl, int); 97static void si_write_enable(struct si_port *, int); 98static int si_Sioctl(dev_t, u_long, caddr_t, int, struct thread *); 99static void si_start(struct tty *); 100static void si_stop(struct tty *, int); 101static timeout_t si_lstart; 102static void sihardclose(struct si_port *pp); 103static void sidtrwakeup(void *chan); 104 105#ifdef SI_DEBUG 106static char *si_mctl2str(enum si_mctl cmd); 107#endif 108 109static int siparam(struct tty *, struct termios *); 110 111static void si_modem_state(struct si_port *pp, struct tty *tp, int hi_ip); 112static char * si_modulename(int host_type, int uart_type); 113 114static d_open_t siopen; 115static d_close_t siclose; 116static d_write_t siwrite; 117static d_ioctl_t siioctl; 118 119static struct cdevsw si_cdevsw = { 120 .d_version = D_VERSION, 121 .d_open = siopen, 122 .d_close = siclose, 123 .d_write = siwrite, 124 .d_ioctl = siioctl, 125 .d_name = "si", 126 .d_flags = D_TTY | D_NEEDGIANT, 127}; 128 129static int si_Nports; 130static int si_Nmodules; 131static int si_debug = 0; /* data, not bss, so it's patchable */ 132 133SYSCTL_INT(_machdep, OID_AUTO, si_debug, CTLFLAG_RW, &si_debug, 0, ""); 134TUNABLE_INT("machdep.si_debug", &si_debug); 135 136static int si_numunits; 137 138devclass_t si_devclass; 139 140#ifndef B2000 /* not standard, but the hardware knows it. */ 141# define B2000 2000 142#endif 143static struct speedtab bdrates[] = { 144 { B75, CLK75, }, /* 0x0 */ 145 { B110, CLK110, }, /* 0x1 */ 146 { B150, CLK150, }, /* 0x3 */ 147 { B300, CLK300, }, /* 0x4 */ 148 { B600, CLK600, }, /* 0x5 */ 149 { B1200, CLK1200, }, /* 0x6 */ 150 { B2000, CLK2000, }, /* 0x7 */ 151 { B2400, CLK2400, }, /* 0x8 */ 152 { B4800, CLK4800, }, /* 0x9 */ 153 { B9600, CLK9600, }, /* 0xb */ 154 { B19200, CLK19200, }, /* 0xc */ 155 { B38400, CLK38400, }, /* 0x2 (out of order!) */ 156 { B57600, CLK57600, }, /* 0xd */ 157 { B115200, CLK110, }, /* 0x1 (dupe!, 110 baud on "si") */ 158 { -1, -1 }, 159}; 160 161 162/* populated with approx character/sec rates - translated at card 163 * initialisation time to chars per tick of the clock */ 164static int done_chartimes = 0; 165static struct speedtab chartimes[] = { 166 { B75, 8, }, 167 { B110, 11, }, 168 { B150, 15, }, 169 { B300, 30, }, 170 { B600, 60, }, 171 { B1200, 120, }, 172 { B2000, 200, }, 173 { B2400, 240, }, 174 { B4800, 480, }, 175 { B9600, 960, }, 176 { B19200, 1920, }, 177 { B38400, 3840, }, 178 { B57600, 5760, }, 179 { B115200, 11520, }, 180 { -1, -1 }, 181}; 182static volatile int in_intr = 0; /* Inside interrupt handler? */ 183 184#ifdef POLL 185static int si_pollrate; /* in addition to irq */ 186static int si_realpoll = 0; /* poll HW on timer */ 187 188SYSCTL_INT(_machdep, OID_AUTO, si_pollrate, CTLFLAG_RW, &si_pollrate, 0, ""); 189SYSCTL_INT(_machdep, OID_AUTO, si_realpoll, CTLFLAG_RW, &si_realpoll, 0, ""); 190 191static int init_finished = 0; 192static void si_poll(void *); 193#endif 194 195/* 196 * Array of adapter types and the corresponding RAM size. The order of 197 * entries here MUST match the ordinal of the adapter type. 198 */ 199static char *si_type[] = { 200 "EMPTY", 201 "SIHOST", 202 "SIMCA", /* FreeBSD does not support Microchannel */ 203 "SIHOST2", 204 "SIEISA", 205 "SIPCI", 206 "SXPCI", 207 "SXISA", 208}; 209 210/* 211 * We have to make an 8 bit version of bcopy, since some cards can't 212 * deal with 32 bit I/O 213 */ 214static void __inline 215si_bcopy(const void *src, void *dst, size_t len) 216{ 217 while (len--) 218 *(((u_char *)dst)++) = *(((const u_char *)src)++); 219} 220static void __inline 221si_vbcopy(const volatile void *src, void *dst, size_t len) 222{ 223 while (len--) 224 *(((u_char *)dst)++) = *(((const volatile u_char *)src)++); 225} 226static void __inline 227si_bcopyv(const void *src, volatile void *dst, size_t len) 228{ 229 while (len--) 230 *(((volatile u_char *)dst)++) = *(((const u_char *)src)++); 231} 232 233 234/* 235 * Attach the device. Initialize the card. 236 */ 237int 238siattach(device_t dev) 239{ 240 int unit; 241 struct si_softc *sc; 242 struct si_port *pp; 243 volatile struct si_channel *ccbp; 244 volatile struct si_reg *regp; 245 volatile caddr_t maddr; 246 struct si_module *modp; 247 struct speedtab *spt; 248 int nmodule, nport, x, y; 249 int uart_type; 250 251 sc = device_get_softc(dev); 252 unit = device_get_unit(dev); 253 254 sc->sc_typename = si_type[sc->sc_type]; 255 if (si_numunits < unit + 1) 256 si_numunits = unit + 1; 257 258 DPRINT((0, DBG_AUTOBOOT, "si%d: siattach\n", unit)); 259 260#ifdef POLL 261 if (si_pollrate == 0) { 262 si_pollrate = POLLHZ; /* in addition to irq */ 263#ifdef REALPOLL 264 si_realpoll = 1; /* scan always */ 265#endif 266 } 267#endif 268 269 DPRINT((0, DBG_AUTOBOOT, "si%d: type: %s paddr: %x maddr: %x\n", unit, 270 sc->sc_typename, sc->sc_paddr, sc->sc_maddr)); 271 272 sc->sc_ports = NULL; /* mark as uninitialised */ 273 274 maddr = sc->sc_maddr; 275 276 /* Stop the CPU first so it won't stomp around while we load */ 277 278 switch (sc->sc_type) { 279 case SIEISA: 280 outb(sc->sc_iobase + 2, sc->sc_irq << 4); 281 break; 282 case SIPCI: 283 *(maddr+SIPCIRESET) = 0; 284 break; 285 case SIJETPCI: /* fall through to JET ISA */ 286 case SIJETISA: 287 *(maddr+SIJETCONFIG) = 0; 288 break; 289 case SIHOST2: 290 *(maddr+SIPLRESET) = 0; 291 break; 292 case SIHOST: 293 *(maddr+SIRESET) = 0; 294 break; 295 default: /* this should never happen */ 296 printf("si%d: unsupported configuration\n", unit); 297 return EINVAL; 298 break; 299 } 300 301 /* OK, now lets download the download code */ 302 303 if (SI_ISJET(sc->sc_type)) { 304 DPRINT((0, DBG_DOWNLOAD, "si%d: jet_download: nbytes %d\n", 305 unit, si3_t225_dsize)); 306 si_bcopy(si3_t225_download, maddr + si3_t225_downloadaddr, 307 si3_t225_dsize); 308 DPRINT((0, DBG_DOWNLOAD, 309 "si%d: jet_bootstrap: nbytes %d -> %x\n", 310 unit, si3_t225_bsize, si3_t225_bootloadaddr)); 311 si_bcopy(si3_t225_bootstrap, maddr + si3_t225_bootloadaddr, 312 si3_t225_bsize); 313 } else { 314 DPRINT((0, DBG_DOWNLOAD, "si%d: si_download: nbytes %d\n", 315 unit, si2_z280_dsize)); 316 si_bcopy(si2_z280_download, maddr + si2_z280_downloadaddr, 317 si2_z280_dsize); 318 } 319 320 /* Now start the CPU */ 321 322 switch (sc->sc_type) { 323 case SIEISA: 324 /* modify the download code to tell it that it's on an EISA */ 325 *(maddr + 0x42) = 1; 326 outb(sc->sc_iobase + 2, (sc->sc_irq << 4) | 4); 327 (void)inb(sc->sc_iobase + 3); /* reset interrupt */ 328 break; 329 case SIPCI: 330 /* modify the download code to tell it that it's on a PCI */ 331 *(maddr+0x42) = 1; 332 *(maddr+SIPCIRESET) = 1; 333 *(maddr+SIPCIINTCL) = 0; 334 break; 335 case SIJETPCI: 336 *(maddr+SIJETRESET) = 0; 337 *(maddr+SIJETCONFIG) = SIJETBUSEN|SIJETIRQEN; 338 break; 339 case SIJETISA: 340 *(maddr+SIJETRESET) = 0; 341 switch (sc->sc_irq) { 342 case 9: 343 *(maddr+SIJETCONFIG) = SIJETBUSEN|SIJETIRQEN|0x90; 344 break; 345 case 10: 346 *(maddr+SIJETCONFIG) = SIJETBUSEN|SIJETIRQEN|0xa0; 347 break; 348 case 11: 349 *(maddr+SIJETCONFIG) = SIJETBUSEN|SIJETIRQEN|0xb0; 350 break; 351 case 12: 352 *(maddr+SIJETCONFIG) = SIJETBUSEN|SIJETIRQEN|0xc0; 353 break; 354 case 15: 355 *(maddr+SIJETCONFIG) = SIJETBUSEN|SIJETIRQEN|0xf0; 356 break; 357 } 358 break; 359 case SIHOST: 360 *(maddr+SIRESET_CL) = 0; 361 *(maddr+SIINTCL_CL) = 0; 362 break; 363 case SIHOST2: 364 *(maddr+SIPLRESET) = 0x10; 365 switch (sc->sc_irq) { 366 case 11: 367 *(maddr+SIPLIRQ11) = 0x10; 368 break; 369 case 12: 370 *(maddr+SIPLIRQ12) = 0x10; 371 break; 372 case 15: 373 *(maddr+SIPLIRQ15) = 0x10; 374 break; 375 } 376 *(maddr+SIPLIRQCLR) = 0x10; 377 break; 378 default: /* this should _REALLY_ never happen */ 379 printf("si%d: Uh, it was supported a second ago...\n", unit); 380 return EINVAL; 381 } 382 383 DELAY(1000000); /* wait around for a second */ 384 385 regp = (struct si_reg *)maddr; 386 y = 0; 387 /* wait max of 5 sec for init OK */ 388 while (regp->initstat == 0 && y++ < 10) { 389 DELAY(500000); 390 } 391 switch (regp->initstat) { 392 case 0: 393 printf("si%d: startup timeout - aborting\n", unit); 394 sc->sc_type = SIEMPTY; 395 return EINVAL; 396 case 1: 397 if (SI_ISJET(sc->sc_type)) { 398 /* set throttle to 100 times per second */ 399 regp->int_count = JET_INT_COUNT; 400 /* rx_intr_count is a NOP in Jet */ 401 } else { 402 /* set throttle to 125 times per second */ 403 regp->int_count = INT_COUNT; 404 /* rx intr max of 25 times per second */ 405 regp->rx_int_count = RXINT_COUNT; 406 } 407 regp->int_pending = 0; /* no intr pending */ 408 regp->int_scounter = 0; /* reset counter */ 409 break; 410 case 0xff: 411 /* 412 * No modules found, so give up on this one. 413 */ 414 printf("si%d: %s - no ports found\n", unit, 415 si_type[sc->sc_type]); 416 return 0; 417 default: 418 printf("si%d: download code version error - initstat %x\n", 419 unit, regp->initstat); 420 return EINVAL; 421 } 422 423 /* 424 * First time around the ports just count them in order 425 * to allocate some memory. 426 */ 427 nport = 0; 428 modp = (struct si_module *)(maddr + 0x80); 429 for (;;) { 430 DPRINT((0, DBG_DOWNLOAD, "si%d: ccb addr 0x%x\n", unit, modp)); 431 switch (modp->sm_type) { 432 case TA4: 433 DPRINT((0, DBG_DOWNLOAD, 434 "si%d: Found old TA4 module, 4 ports\n", 435 unit)); 436 x = 4; 437 break; 438 case TA8: 439 DPRINT((0, DBG_DOWNLOAD, 440 "si%d: Found old TA8 module, 8 ports\n", 441 unit)); 442 x = 8; 443 break; 444 case TA4_ASIC: 445 DPRINT((0, DBG_DOWNLOAD, 446 "si%d: Found ASIC TA4 module, 4 ports\n", 447 unit)); 448 x = 4; 449 break; 450 case TA8_ASIC: 451 DPRINT((0, DBG_DOWNLOAD, 452 "si%d: Found ASIC TA8 module, 8 ports\n", 453 unit)); 454 x = 8; 455 break; 456 case MTA: 457 DPRINT((0, DBG_DOWNLOAD, 458 "si%d: Found CD1400 module, 8 ports\n", 459 unit)); 460 x = 8; 461 break; 462 case SXDC: 463 DPRINT((0, DBG_DOWNLOAD, 464 "si%d: Found SXDC module, 8 ports\n", 465 unit)); 466 x = 8; 467 break; 468 default: 469 printf("si%d: unknown module type %d\n", 470 unit, modp->sm_type); 471 goto try_next; 472 } 473 474 /* this was limited in firmware and is also a driver issue */ 475 if ((nport + x) > SI_MAXPORTPERCARD) { 476 printf("si%d: extra ports ignored\n", unit); 477 goto try_next; 478 } 479 480 nport += x; 481 si_Nports += x; 482 si_Nmodules++; 483 484try_next: 485 if (modp->sm_next == 0) 486 break; 487 modp = (struct si_module *) 488 (maddr + (unsigned)(modp->sm_next & 0x7fff)); 489 } 490 sc->sc_ports = (struct si_port *)malloc(sizeof(struct si_port) * nport, 491 M_DEVBUF, M_NOWAIT | M_ZERO); 492 if (sc->sc_ports == 0) { 493 printf("si%d: fail to malloc memory for port structs\n", 494 unit); 495 return EINVAL; 496 } 497 sc->sc_nport = nport; 498 499 /* 500 * Scan round the ports again, this time initialising. 501 */ 502 pp = sc->sc_ports; 503 nmodule = 0; 504 modp = (struct si_module *)(maddr + 0x80); 505 uart_type = 1000; /* arbitary, > uchar_max */ 506 for (;;) { 507 switch (modp->sm_type) { 508 case TA4: 509 nport = 4; 510 break; 511 case TA8: 512 nport = 8; 513 break; 514 case TA4_ASIC: 515 nport = 4; 516 break; 517 case TA8_ASIC: 518 nport = 8; 519 break; 520 case MTA: 521 nport = 8; 522 break; 523 case SXDC: 524 nport = 8; 525 break; 526 default: 527 goto try_next2; 528 } 529 nmodule++; 530 ccbp = (struct si_channel *)((char *)modp + 0x100); 531 if (uart_type == 1000) 532 uart_type = ccbp->type; 533 else if (uart_type != ccbp->type) 534 printf("si%d: Warning: module %d mismatch! (%d%s != %d%s)\n", 535 unit, nmodule, 536 ccbp->type, si_modulename(sc->sc_type, ccbp->type), 537 uart_type, si_modulename(sc->sc_type, uart_type)); 538 539 for (x = 0; x < nport; x++, pp++, ccbp++) { 540 pp->sp_ccb = ccbp; /* save the address */ 541 pp->sp_tty = ttymalloc(NULL); 542 pp->sp_pend = IDLE_CLOSE; 543 pp->sp_state = 0; /* internal flag */ 544 pp->sp_dtr_wait = 3 * hz; 545 pp->sp_iin.c_iflag = TTYDEF_IFLAG; 546 pp->sp_iin.c_oflag = TTYDEF_OFLAG; 547 pp->sp_iin.c_cflag = TTYDEF_CFLAG; 548 pp->sp_iin.c_lflag = TTYDEF_LFLAG; 549 termioschars(&pp->sp_iin); 550 pp->sp_iin.c_ispeed = pp->sp_iin.c_ospeed = 551 TTYDEF_SPEED;; 552 pp->sp_iout = pp->sp_iin; 553 } 554try_next2: 555 if (modp->sm_next == 0) { 556 printf("si%d: card: %s, ports: %d, modules: %d, type: %d%s\n", 557 unit, 558 sc->sc_typename, 559 sc->sc_nport, 560 nmodule, 561 uart_type, 562 si_modulename(sc->sc_type, uart_type)); 563 break; 564 } 565 modp = (struct si_module *) 566 (maddr + (unsigned)(modp->sm_next & 0x7fff)); 567 } 568 if (done_chartimes == 0) { 569 for (spt = chartimes ; spt->sp_speed != -1; spt++) { 570 if ((spt->sp_code /= hz) == 0) 571 spt->sp_code = 1; 572 } 573 done_chartimes = 1; 574 } 575 576/* path name devsw minor type uid gid perm*/ 577 for (x = 0; x < sc->sc_nport; x++) { 578 /* sync with the manuals that start at 1 */ 579 y = x + 1 + unit * (1 << SI_CARDSHIFT); 580 make_dev(&si_cdevsw, x, 0, 0, 0600, "ttyA%02d", y); 581 make_dev(&si_cdevsw, x + 0x00080, 0, 0, 0600, "cuaA%02d", y); 582 make_dev(&si_cdevsw, x + 0x10000, 0, 0, 0600, "ttyiA%02d", y); 583 make_dev(&si_cdevsw, x + 0x10080, 0, 0, 0600, "cuaiA%02d", y); 584 make_dev(&si_cdevsw, x + 0x20000, 0, 0, 0600, "ttylA%02d", y); 585 make_dev(&si_cdevsw, x + 0x20080, 0, 0, 0600, "cualA%02d", y); 586 } 587 make_dev(&si_cdevsw, 0x40000, 0, 0, 0600, "si_control"); 588 return (0); 589} 590 591static int 592siopen(dev_t dev, int flag, int mode, struct thread *td) 593{ 594 int oldspl, error; 595 int card, port; 596 struct si_softc *sc; 597 struct tty *tp; 598 volatile struct si_channel *ccbp; 599 struct si_port *pp; 600 int mynor = minor(dev); 601 602 /* quickly let in /dev/si_control */ 603 if (IS_CONTROLDEV(mynor)) { 604 if ((error = suser(td))) 605 return(error); 606 return(0); 607 } 608 609 card = SI_CARD(mynor); 610 sc = devclass_get_softc(si_devclass, card); 611 if (sc == NULL) 612 return (ENXIO); 613 614 if (sc->sc_type == SIEMPTY) { 615 DPRINT((0, DBG_OPEN|DBG_FAIL, "si%d: type %s??\n", 616 card, sc->sc_typename)); 617 return(ENXIO); 618 } 619 620 port = SI_PORT(mynor); 621 if (port >= sc->sc_nport) { 622 DPRINT((0, DBG_OPEN|DBG_FAIL, "si%d: nports %d\n", 623 card, sc->sc_nport)); 624 return(ENXIO); 625 } 626 627#ifdef POLL 628 /* 629 * We've now got a device, so start the poller. 630 */ 631 if (init_finished == 0) { 632 timeout(si_poll, (caddr_t)0L, si_pollrate); 633 init_finished = 1; 634 } 635#endif 636 637 /* initial/lock device */ 638 if (IS_STATE(mynor)) { 639 return(0); 640 } 641 642 pp = sc->sc_ports + port; 643 tp = pp->sp_tty; /* the "real" tty */ 644 dev->si_tty = tp; 645 ccbp = pp->sp_ccb; /* Find control block */ 646 DPRINT((pp, DBG_ENTRY|DBG_OPEN, "siopen(%s,%x,%x,%x)\n", 647 devtoname(dev), flag, mode, td)); 648 649 oldspl = spltty(); /* Keep others out */ 650 error = 0; 651 652open_top: 653 while (pp->sp_state & SS_DTR_OFF) { 654 error = tsleep(&pp->sp_dtr_wait, TTIPRI|PCATCH, "sidtr", 0); 655 if (error != 0) 656 goto out; 657 } 658 659 if (tp->t_state & TS_ISOPEN) { 660 /* 661 * The device is open, so everything has been initialised. 662 * handle conflicts. 663 */ 664 if (IS_CALLOUT(mynor)) { 665 if (!pp->sp_active_out) { 666 error = EBUSY; 667 goto out; 668 } 669 } else { 670 if (pp->sp_active_out) { 671 if (flag & O_NONBLOCK) { 672 error = EBUSY; 673 goto out; 674 } 675 error = tsleep(&pp->sp_active_out, 676 TTIPRI|PCATCH, "sibi", 0); 677 if (error != 0) 678 goto out; 679 goto open_top; 680 } 681 } 682 if (tp->t_state & TS_XCLUDE && 683 suser(td)) { 684 DPRINT((pp, DBG_OPEN|DBG_FAIL, 685 "already open and EXCLUSIVE set\n")); 686 error = EBUSY; 687 goto out; 688 } 689 } else { 690 /* 691 * The device isn't open, so there are no conflicts. 692 * Initialize it. Avoid sleep... :-) 693 */ 694 DPRINT((pp, DBG_OPEN, "first open\n")); 695 tp->t_oproc = si_start; 696 tp->t_stop = si_stop; 697 tp->t_param = siparam; 698 tp->t_dev = dev; 699 tp->t_termios = mynor & SI_CALLOUT_MASK 700 ? pp->sp_iout : pp->sp_iin; 701 702 (void) si_modem(pp, SET, TIOCM_DTR|TIOCM_RTS); 703 704 ++pp->sp_wopeners; /* in case of sleep in siparam */ 705 706 error = siparam(tp, &tp->t_termios); 707 708 --pp->sp_wopeners; 709 if (error != 0) 710 goto out; 711 /* XXX: we should goto_top if siparam slept */ 712 713 /* set initial DCD state */ 714 pp->sp_last_hi_ip = ccbp->hi_ip; 715 if ((pp->sp_last_hi_ip & IP_DCD) || IS_CALLOUT(mynor)) { 716 ttyld_modem(tp, 1); 717 } 718 } 719 720 /* whoops! we beat the close! */ 721 if (pp->sp_state & SS_CLOSING) { 722 /* try and stop it from proceeding to bash the hardware */ 723 pp->sp_state &= ~SS_CLOSING; 724 } 725 726 /* 727 * Wait for DCD if necessary 728 */ 729 if (!(tp->t_state & TS_CARR_ON) && 730 !IS_CALLOUT(mynor) && 731 !(tp->t_cflag & CLOCAL) && 732 !(flag & O_NONBLOCK)) { 733 ++pp->sp_wopeners; 734 DPRINT((pp, DBG_OPEN, "sleeping for carrier\n")); 735 error = tsleep(TSA_CARR_ON(tp), TTIPRI|PCATCH, "sidcd", 0); 736 --pp->sp_wopeners; 737 if (error != 0) 738 goto out; 739 goto open_top; 740 } 741 742 error = ttyld_open(tp, dev); 743 pp->sp_hotchar = ttyldoptim(tp); 744 if (tp->t_state & TS_ISOPEN && IS_CALLOUT(mynor)) 745 pp->sp_active_out = TRUE; 746 747 pp->sp_state |= SS_OPEN; /* made it! */ 748 749out: 750 splx(oldspl); 751 752 DPRINT((pp, DBG_OPEN, "leaving siopen\n")); 753 754 if (!(tp->t_state & TS_ISOPEN) && pp->sp_wopeners == 0) 755 sihardclose(pp); 756 757 return(error); 758} 759 760static int 761siclose(dev_t dev, int flag, int mode, struct thread *td) 762{ 763 struct si_port *pp; 764 struct tty *tp; 765 int oldspl; 766 int error = 0; 767 int mynor = minor(dev); 768 769 if (IS_SPECIAL(mynor)) 770 return(0); 771 772 oldspl = spltty(); 773 774 pp = MINOR2PP(mynor); 775 tp = pp->sp_tty; 776 777 DPRINT((pp, DBG_ENTRY|DBG_CLOSE, "siclose(%s,%x,%x,%x) sp_state:%x\n", 778 devtoname(dev), flag, mode, td, pp->sp_state)); 779 780 /* did we sleep and loose a race? */ 781 if (pp->sp_state & SS_CLOSING) { 782 /* error = ESOMETING? */ 783 goto out; 784 } 785 786 /* begin race detection.. */ 787 pp->sp_state |= SS_CLOSING; 788 789 si_write_enable(pp, 0); /* block writes for ttywait() */ 790 791 /* THIS MAY SLEEP IN TTYWAIT!!! */ 792 ttyld_close(tp, flag); 793 794 si_write_enable(pp, 1); 795 796 /* did we sleep and somebody started another open? */ 797 if (!(pp->sp_state & SS_CLOSING)) { 798 /* error = ESOMETING? */ 799 goto out; 800 } 801 /* ok. we are now still on the right track.. nuke the hardware */ 802 803 if (pp->sp_state & SS_LSTART) { 804 untimeout(si_lstart, (caddr_t)pp, pp->lstart_ch); 805 pp->sp_state &= ~SS_LSTART; 806 } 807 808 sihardclose(pp); 809 ttyclose(tp); 810 pp->sp_state &= ~SS_OPEN; 811 812out: 813 DPRINT((pp, DBG_CLOSE|DBG_EXIT, "close done, returning\n")); 814 splx(oldspl); 815 return(error); 816} 817 818static void 819sihardclose(struct si_port *pp) 820{ 821 int oldspl; 822 struct tty *tp; 823 volatile struct si_channel *ccbp; 824 825 oldspl = spltty(); 826 827 tp = pp->sp_tty; 828 ccbp = pp->sp_ccb; /* Find control block */ 829 if (tp->t_cflag & HUPCL || 830 (!pp->sp_active_out && 831 !(ccbp->hi_ip & IP_DCD) && 832 !(pp->sp_iin.c_cflag && CLOCAL)) || 833 !(tp->t_state & TS_ISOPEN)) { 834 835 (void) si_modem(pp, BIC, TIOCM_DTR|TIOCM_RTS); 836 (void) si_command(pp, FCLOSE, SI_NOWAIT); 837 838 if (pp->sp_dtr_wait != 0) { 839 timeout(sidtrwakeup, pp, pp->sp_dtr_wait); 840 pp->sp_state |= SS_DTR_OFF; 841 } 842 843 } 844 pp->sp_active_out = FALSE; 845 wakeup(&pp->sp_active_out); 846 wakeup(TSA_CARR_ON(tp)); 847 848 splx(oldspl); 849} 850 851 852/* 853 * called at splsoftclock()... 854 */ 855static void 856sidtrwakeup(void *chan) 857{ 858 struct si_port *pp; 859 int oldspl; 860 861 oldspl = spltty(); 862 863 pp = (struct si_port *)chan; 864 pp->sp_state &= ~SS_DTR_OFF; 865 wakeup(&pp->sp_dtr_wait); 866 867 splx(oldspl); 868} 869 870static int 871siwrite(dev_t dev, struct uio *uio, int flag) 872{ 873 struct si_port *pp; 874 struct tty *tp; 875 int error = 0; 876 int mynor = minor(dev); 877 int oldspl; 878 879 if (IS_SPECIAL(mynor)) { 880 DPRINT((0, DBG_ENTRY|DBG_FAIL|DBG_WRITE, "siwrite(CONTROLDEV!!)\n")); 881 return(ENODEV); 882 } 883 pp = MINOR2PP(mynor); 884 tp = pp->sp_tty; 885 DPRINT((pp, DBG_WRITE, "siwrite(%s,%x,%x)\n", devtoname(dev), uio, flag)); 886 887 oldspl = spltty(); 888 /* 889 * If writes are currently blocked, wait on the "real" tty 890 */ 891 while (pp->sp_state & SS_BLOCKWRITE) { 892 pp->sp_state |= SS_WAITWRITE; 893 DPRINT((pp, DBG_WRITE, "in siwrite, wait for SS_BLOCKWRITE to clear\n")); 894 if ((error = ttysleep(tp, (caddr_t)pp, TTOPRI|PCATCH, 895 "siwrite", tp->t_timeout))) { 896 if (error == EWOULDBLOCK) 897 error = EIO; 898 goto out; 899 } 900 } 901 902 error = ttyld_write(tp, uio, flag); 903out: 904 splx(oldspl); 905 return (error); 906} 907 908 909static int 910siioctl(dev_t dev, u_long cmd, caddr_t data, int flag, struct thread *td) 911{ 912 struct si_port *pp; 913 struct tty *tp; 914 int error; 915 int mynor = minor(dev); 916 int oldspl; 917 int blocked = 0; 918#if defined(COMPAT_43) 919 u_long oldcmd; 920 struct termios term; 921#endif 922 923 if (IS_SI_IOCTL(cmd)) 924 return(si_Sioctl(dev, cmd, data, flag, td)); 925 926 pp = MINOR2PP(mynor); 927 tp = pp->sp_tty; 928 929 DPRINT((pp, DBG_ENTRY|DBG_IOCTL, "siioctl(%s,%lx,%x,%x)\n", 930 devtoname(dev), cmd, data, flag)); 931 if (IS_STATE(mynor)) { 932 struct termios *ct; 933 934 switch (mynor & SI_STATE_MASK) { 935 case SI_INIT_STATE_MASK: 936 ct = IS_CALLOUT(mynor) ? &pp->sp_iout : &pp->sp_iin; 937 break; 938 case SI_LOCK_STATE_MASK: 939 ct = IS_CALLOUT(mynor) ? &pp->sp_lout : &pp->sp_lin; 940 break; 941 default: 942 return (ENODEV); 943 } 944 switch (cmd) { 945 case TIOCSETA: 946 error = suser(td); 947 if (error != 0) 948 return (error); 949 *ct = *(struct termios *)data; 950 return (0); 951 case TIOCGETA: 952 *(struct termios *)data = *ct; 953 return (0); 954 case TIOCGETD: 955 *(int *)data = TTYDISC; 956 return (0); 957 case TIOCGWINSZ: 958 bzero(data, sizeof(struct winsize)); 959 return (0); 960 default: 961 return (ENOTTY); 962 } 963 } 964 /* 965 * Do the old-style ioctl compat routines... 966 */ 967#if defined(COMPAT_43) 968 term = tp->t_termios; 969 oldcmd = cmd; 970 error = ttsetcompat(tp, &cmd, data, &term); 971 if (error != 0) 972 return (error); 973 if (cmd != oldcmd) 974 data = (caddr_t)&term; 975#endif 976 /* 977 * Do the initial / lock state business 978 */ 979 if (cmd == TIOCSETA || cmd == TIOCSETAW || cmd == TIOCSETAF) { 980 int cc; 981 struct termios *dt = (struct termios *)data; 982 struct termios *lt = mynor & SI_CALLOUT_MASK 983 ? &pp->sp_lout : &pp->sp_lin; 984 985 dt->c_iflag = (tp->t_iflag & lt->c_iflag) | 986 (dt->c_iflag & ~lt->c_iflag); 987 dt->c_oflag = (tp->t_oflag & lt->c_oflag) | 988 (dt->c_oflag & ~lt->c_oflag); 989 dt->c_cflag = (tp->t_cflag & lt->c_cflag) | 990 (dt->c_cflag & ~lt->c_cflag); 991 dt->c_lflag = (tp->t_lflag & lt->c_lflag) | 992 (dt->c_lflag & ~lt->c_lflag); 993 for (cc = 0; cc < NCCS; ++cc) 994 if (lt->c_cc[cc] != 0) 995 dt->c_cc[cc] = tp->t_cc[cc]; 996 if (lt->c_ispeed != 0) 997 dt->c_ispeed = tp->t_ispeed; 998 if (lt->c_ospeed != 0) 999 dt->c_ospeed = tp->t_ospeed; 1000 } 1001 1002 /* 1003 * Block user-level writes to give the ttywait() 1004 * a chance to completely drain for commands 1005 * that require the port to be in a quiescent state. 1006 */ 1007 switch (cmd) { 1008 case TIOCSETAW: 1009 case TIOCSETAF: 1010 case TIOCDRAIN: 1011#ifdef COMPAT_43 1012 case TIOCSETP: 1013#endif 1014 blocked++; /* block writes for ttywait() and siparam() */ 1015 si_write_enable(pp, 0); 1016 } 1017 1018 error = ttyioctl(dev, cmd, data, flag, td); 1019 pp->sp_hotchar = ttyldoptim(tp); 1020 if (error != ENOTTY) 1021 goto out; 1022 1023 oldspl = spltty(); 1024 1025 error = 0; 1026 switch (cmd) { 1027 case TIOCSBRK: 1028 si_command(pp, SBREAK, SI_WAIT); 1029 break; 1030 case TIOCCBRK: 1031 si_command(pp, EBREAK, SI_WAIT); 1032 break; 1033 case TIOCSDTR: 1034 (void) si_modem(pp, SET, TIOCM_DTR|TIOCM_RTS); 1035 break; 1036 case TIOCCDTR: 1037 (void) si_modem(pp, SET, 0); 1038 break; 1039 case TIOCMSET: 1040 (void) si_modem(pp, SET, *(int *)data); 1041 break; 1042 case TIOCMBIS: 1043 (void) si_modem(pp, BIS, *(int *)data); 1044 break; 1045 case TIOCMBIC: 1046 (void) si_modem(pp, BIC, *(int *)data); 1047 break; 1048 case TIOCMGET: 1049 *(int *)data = si_modem(pp, GET, 0); 1050 break; 1051 case TIOCMSDTRWAIT: 1052 /* must be root since the wait applies to following logins */ 1053 error = suser(td); 1054 if (error == 0) 1055 pp->sp_dtr_wait = *(int *)data * hz / 100; 1056 break; 1057 case TIOCMGDTRWAIT: 1058 *(int *)data = pp->sp_dtr_wait * 100 / hz; 1059 break; 1060 default: 1061 error = ENOTTY; 1062 } 1063 splx(oldspl); 1064 1065out: 1066 DPRINT((pp, DBG_IOCTL|DBG_EXIT, "siioctl ret %d\n", error)); 1067 if (blocked) 1068 si_write_enable(pp, 1); 1069 return(error); 1070} 1071 1072/* 1073 * Handle the Specialix ioctls. All MUST be called via the CONTROL device 1074 */ 1075static int 1076si_Sioctl(dev_t dev, u_long cmd, caddr_t data, int flag, struct thread *td) 1077{ 1078 struct si_softc *xsc; 1079 struct si_port *xpp; 1080 volatile struct si_reg *regp; 1081 struct si_tcsi *dp; 1082 struct si_pstat *sps; 1083 int *ip, error = 0; 1084 int oldspl; 1085 int card, port; 1086 int mynor = minor(dev); 1087 1088 DPRINT((0, DBG_ENTRY|DBG_IOCTL, "si_Sioctl(%s,%lx,%x,%x)\n", 1089 devtoname(dev), cmd, data, flag)); 1090 1091#if 1 1092 DPRINT((0, DBG_IOCTL, "TCSI_PORT=%x\n", TCSI_PORT)); 1093 DPRINT((0, DBG_IOCTL, "TCSI_CCB=%x\n", TCSI_CCB)); 1094 DPRINT((0, DBG_IOCTL, "TCSI_TTY=%x\n", TCSI_TTY)); 1095#endif 1096 1097 if (!IS_CONTROLDEV(mynor)) { 1098 DPRINT((0, DBG_IOCTL|DBG_FAIL, "not called from control device!\n")); 1099 return(ENODEV); 1100 } 1101 1102 oldspl = spltty(); /* better safe than sorry */ 1103 1104 ip = (int *)data; 1105 1106#define SUCHECK if ((error = suser(td))) goto out 1107 1108 switch (cmd) { 1109 case TCSIPORTS: 1110 *ip = si_Nports; 1111 goto out; 1112 case TCSIMODULES: 1113 *ip = si_Nmodules; 1114 goto out; 1115 case TCSISDBG_ALL: 1116 SUCHECK; 1117 si_debug = *ip; 1118 goto out; 1119 case TCSIGDBG_ALL: 1120 *ip = si_debug; 1121 goto out; 1122 default: 1123 /* 1124 * Check that a controller for this port exists 1125 */ 1126 1127 /* may also be a struct si_pstat, a superset of si_tcsi */ 1128 1129 dp = (struct si_tcsi *)data; 1130 sps = (struct si_pstat *)data; 1131 card = dp->tc_card; 1132 xsc = devclass_get_softc(si_devclass, card); /* check.. */ 1133 if (xsc == NULL || xsc->sc_type == SIEMPTY) { 1134 error = ENOENT; 1135 goto out; 1136 } 1137 /* 1138 * And check that a port exists 1139 */ 1140 port = dp->tc_port; 1141 if (port < 0 || port >= xsc->sc_nport) { 1142 error = ENOENT; 1143 goto out; 1144 } 1145 xpp = xsc->sc_ports + port; 1146 regp = (struct si_reg *)xsc->sc_maddr; 1147 } 1148 1149 switch (cmd) { 1150 case TCSIDEBUG: 1151#ifdef SI_DEBUG 1152 SUCHECK; 1153 if (xpp->sp_debug) 1154 xpp->sp_debug = 0; 1155 else { 1156 xpp->sp_debug = DBG_ALL; 1157 DPRINT((xpp, DBG_IOCTL, "debug toggled %s\n", 1158 (xpp->sp_debug&DBG_ALL)?"ON":"OFF")); 1159 } 1160 break; 1161#else 1162 error = ENODEV; 1163 goto out; 1164#endif 1165 case TCSISDBG_LEVEL: 1166 case TCSIGDBG_LEVEL: 1167#ifdef SI_DEBUG 1168 if (cmd == TCSIGDBG_LEVEL) { 1169 dp->tc_dbglvl = xpp->sp_debug; 1170 } else { 1171 SUCHECK; 1172 xpp->sp_debug = dp->tc_dbglvl; 1173 } 1174 break; 1175#else 1176 error = ENODEV; 1177 goto out; 1178#endif 1179 case TCSIGRXIT: 1180 dp->tc_int = regp->rx_int_count; 1181 break; 1182 case TCSIRXIT: 1183 SUCHECK; 1184 regp->rx_int_count = dp->tc_int; 1185 break; 1186 case TCSIGIT: 1187 dp->tc_int = regp->int_count; 1188 break; 1189 case TCSIIT: 1190 SUCHECK; 1191 regp->int_count = dp->tc_int; 1192 break; 1193 case TCSISTATE: 1194 dp->tc_int = xpp->sp_ccb->hi_ip; 1195 break; 1196 /* these next three use a different structure */ 1197 case TCSI_PORT: 1198 SUCHECK; 1199 si_bcopy(xpp, &sps->tc_siport, sizeof(sps->tc_siport)); 1200 break; 1201 case TCSI_CCB: 1202 SUCHECK; 1203 si_vbcopy(xpp->sp_ccb, &sps->tc_ccb, sizeof(sps->tc_ccb)); 1204 break; 1205 case TCSI_TTY: 1206 SUCHECK; 1207 si_bcopy(xpp->sp_tty, &sps->tc_tty, sizeof(sps->tc_tty)); 1208 break; 1209 default: 1210 error = EINVAL; 1211 goto out; 1212 } 1213out: 1214 splx(oldspl); 1215 return(error); /* success */ 1216} 1217 1218/* 1219 * siparam() : Configure line params 1220 * called at spltty(); 1221 * this may sleep, does not flush, nor wait for drain, nor block writes 1222 * caller must arrange this if it's important.. 1223 */ 1224static int 1225siparam(struct tty *tp, struct termios *t) 1226{ 1227 struct si_port *pp = TP2PP(tp); 1228 volatile struct si_channel *ccbp; 1229 int oldspl, cflag, iflag, oflag, lflag; 1230 int error = 0; /* shutup gcc */ 1231 int ispeed = 0; /* shutup gcc */ 1232 int ospeed = 0; /* shutup gcc */ 1233 BYTE val; 1234 1235 DPRINT((pp, DBG_ENTRY|DBG_PARAM, "siparam(%x,%x)\n", tp, t)); 1236 cflag = t->c_cflag; 1237 iflag = t->c_iflag; 1238 oflag = t->c_oflag; 1239 lflag = t->c_lflag; 1240 DPRINT((pp, DBG_PARAM, "OFLAG 0x%x CFLAG 0x%x IFLAG 0x%x LFLAG 0x%x\n", 1241 oflag, cflag, iflag, lflag)); 1242 1243 /* XXX - if Jet host and SXDC module, use extended baud rates */ 1244 1245 /* if not hung up.. */ 1246 if (t->c_ospeed != 0) { 1247 /* translate baud rate to firmware values */ 1248 ospeed = ttspeedtab(t->c_ospeed, bdrates); 1249 ispeed = t->c_ispeed ? 1250 ttspeedtab(t->c_ispeed, bdrates) : ospeed; 1251 1252 /* enforce legit baud rate */ 1253 if (ospeed < 0 || ispeed < 0) 1254 return (EINVAL); 1255 } 1256 1257 oldspl = spltty(); 1258 1259 ccbp = pp->sp_ccb; 1260 1261 /* ========== set hi_break ========== */ 1262 val = 0; 1263 if (iflag & IGNBRK) /* Breaks */ 1264 val |= BR_IGN; 1265 if (iflag & BRKINT) /* Interrupt on break? */ 1266 val |= BR_INT; 1267 if (iflag & PARMRK) /* Parity mark? */ 1268 val |= BR_PARMRK; 1269 if (iflag & IGNPAR) /* Ignore chars with parity errors? */ 1270 val |= BR_PARIGN; 1271 ccbp->hi_break = val; 1272 1273 /* ========== set hi_csr ========== */ 1274 /* if not hung up.. */ 1275 if (t->c_ospeed != 0) { 1276 /* Set I/O speeds */ 1277 val = (ispeed << 4) | ospeed; 1278 } 1279 ccbp->hi_csr = val; 1280 1281 /* ========== set hi_mr2 ========== */ 1282 val = 0; 1283 if (cflag & CSTOPB) /* Stop bits */ 1284 val |= MR2_2_STOP; 1285 else 1286 val |= MR2_1_STOP; 1287 /* 1288 * Enable H/W RTS/CTS handshaking. The default TA/MTA is 1289 * a DCE, hence the reverse sense of RTS and CTS 1290 */ 1291 /* Output Flow - RTS must be raised before data can be sent */ 1292 if (cflag & CCTS_OFLOW) 1293 val |= MR2_RTSCONT; 1294 1295 ccbp->hi_mr2 = val; 1296 1297 /* ========== set hi_mr1 ========== */ 1298 val = 0; 1299 if (!(cflag & PARENB)) /* Parity */ 1300 val |= MR1_NONE; 1301 else 1302 val |= MR1_WITH; 1303 if (cflag & PARODD) 1304 val |= MR1_ODD; 1305 1306 if ((cflag & CS8) == CS8) { /* 8 data bits? */ 1307 val |= MR1_8_BITS; 1308 } else if ((cflag & CS7) == CS7) { /* 7 data bits? */ 1309 val |= MR1_7_BITS; 1310 } else if ((cflag & CS6) == CS6) { /* 6 data bits? */ 1311 val |= MR1_6_BITS; 1312 } else { /* Must be 5 */ 1313 val |= MR1_5_BITS; 1314 } 1315 /* 1316 * Enable H/W RTS/CTS handshaking. The default TA/MTA is 1317 * a DCE, hence the reverse sense of RTS and CTS 1318 */ 1319 /* Input Flow - CTS is raised when port is ready to receive data */ 1320 if (cflag & CRTS_IFLOW) 1321 val |= MR1_CTSCONT; 1322 1323 ccbp->hi_mr1 = val; 1324 1325 /* ========== set hi_mask ========== */ 1326 val = 0xff; 1327 if ((cflag & CS8) == CS8) { /* 8 data bits? */ 1328 val &= 0xFF; 1329 } else if ((cflag & CS7) == CS7) { /* 7 data bits? */ 1330 val &= 0x7F; 1331 } else if ((cflag & CS6) == CS6) { /* 6 data bits? */ 1332 val &= 0x3F; 1333 } else { /* Must be 5 */ 1334 val &= 0x1F; 1335 } 1336 if (iflag & ISTRIP) 1337 val &= 0x7F; 1338 1339 ccbp->hi_mask = val; 1340 1341 /* ========== set hi_prtcl ========== */ 1342 val = SP_DCEN; /* Monitor DCD always, or TIOCMGET misses it */ 1343 if (iflag & IXANY) 1344 val |= SP_TANY; 1345 if (iflag & IXON) 1346 val |= SP_TXEN; 1347 if (iflag & IXOFF) 1348 val |= SP_RXEN; 1349 if (iflag & INPCK) 1350 val |= SP_PAEN; 1351 1352 ccbp->hi_prtcl = val; 1353 1354 1355 /* ========== set hi_{rx|tx}{on|off} ========== */ 1356 /* XXX: the card TOTALLY shields us from the flow control... */ 1357 ccbp->hi_txon = t->c_cc[VSTART]; 1358 ccbp->hi_txoff = t->c_cc[VSTOP]; 1359 1360 ccbp->hi_rxon = t->c_cc[VSTART]; 1361 ccbp->hi_rxoff = t->c_cc[VSTOP]; 1362 1363 /* ========== send settings to the card ========== */ 1364 /* potential sleep here */ 1365 if (ccbp->hi_stat == IDLE_CLOSE) /* Not yet open */ 1366 si_command(pp, LOPEN, SI_WAIT); /* open it */ 1367 else 1368 si_command(pp, CONFIG, SI_WAIT); /* change params */ 1369 1370 /* ========== set DTR etc ========== */ 1371 /* Hangup if ospeed == 0 */ 1372 if (t->c_ospeed == 0) { 1373 (void) si_modem(pp, BIC, TIOCM_DTR|TIOCM_RTS); 1374 } else { 1375 /* 1376 * If the previous speed was 0, may need to re-enable 1377 * the modem signals 1378 */ 1379 (void) si_modem(pp, SET, TIOCM_DTR|TIOCM_RTS); 1380 } 1381 1382 DPRINT((pp, DBG_PARAM, "siparam, complete: MR1 %x MR2 %x HI_MASK %x PRTCL %x HI_BREAK %x\n", 1383 ccbp->hi_mr1, ccbp->hi_mr2, ccbp->hi_mask, ccbp->hi_prtcl, ccbp->hi_break)); 1384 1385 splx(oldspl); 1386 return(error); 1387} 1388 1389/* 1390 * Enable or Disable the writes to this channel... 1391 * "state" -> enabled = 1; disabled = 0; 1392 */ 1393static void 1394si_write_enable(struct si_port *pp, int state) 1395{ 1396 int oldspl; 1397 1398 oldspl = spltty(); 1399 1400 if (state) { 1401 pp->sp_state &= ~SS_BLOCKWRITE; 1402 if (pp->sp_state & SS_WAITWRITE) { 1403 pp->sp_state &= ~SS_WAITWRITE; 1404 /* thunder away! */ 1405 wakeup(pp); 1406 } 1407 } else { 1408 pp->sp_state |= SS_BLOCKWRITE; 1409 } 1410 1411 splx(oldspl); 1412} 1413 1414/* 1415 * Set/Get state of modem control lines. 1416 * Due to DCE-like behaviour of the adapter, some signals need translation: 1417 * TIOCM_DTR DSR 1418 * TIOCM_RTS CTS 1419 */ 1420static int 1421si_modem(struct si_port *pp, enum si_mctl cmd, int bits) 1422{ 1423 volatile struct si_channel *ccbp; 1424 int x; 1425 1426 DPRINT((pp, DBG_ENTRY|DBG_MODEM, "si_modem(%x,%s,%x)\n", pp, si_mctl2str(cmd), bits)); 1427 ccbp = pp->sp_ccb; /* Find channel address */ 1428 switch (cmd) { 1429 case GET: 1430 x = ccbp->hi_ip; 1431 bits = TIOCM_LE; 1432 if (x & IP_DCD) bits |= TIOCM_CAR; 1433 if (x & IP_DTR) bits |= TIOCM_DTR; 1434 if (x & IP_RTS) bits |= TIOCM_RTS; 1435 if (x & IP_RI) bits |= TIOCM_RI; 1436 return(bits); 1437 case SET: 1438 ccbp->hi_op &= ~(OP_DSR|OP_CTS); 1439 /* fall through */ 1440 case BIS: 1441 x = 0; 1442 if (bits & TIOCM_DTR) 1443 x |= OP_DSR; 1444 if (bits & TIOCM_RTS) 1445 x |= OP_CTS; 1446 ccbp->hi_op |= x; 1447 break; 1448 case BIC: 1449 if (bits & TIOCM_DTR) 1450 ccbp->hi_op &= ~OP_DSR; 1451 if (bits & TIOCM_RTS) 1452 ccbp->hi_op &= ~OP_CTS; 1453 } 1454 return 0; 1455} 1456 1457/* 1458 * Handle change of modem state 1459 */ 1460static void 1461si_modem_state(struct si_port *pp, struct tty *tp, int hi_ip) 1462{ 1463 /* if a modem dev */ 1464 if (hi_ip & IP_DCD) { 1465 if (!(pp->sp_last_hi_ip & IP_DCD)) { 1466 DPRINT((pp, DBG_INTR, "modem carr on t_line %d\n", 1467 tp->t_line)); 1468 (void)ttyld_modem(tp, 1); 1469 } 1470 } else { 1471 if (pp->sp_last_hi_ip & IP_DCD) { 1472 DPRINT((pp, DBG_INTR, "modem carr off\n")); 1473 if (ttyld_modem(tp, 0)) 1474 (void) si_modem(pp, SET, 0); 1475 } 1476 } 1477 pp->sp_last_hi_ip = hi_ip; 1478 1479} 1480 1481/* 1482 * Poller to catch missed interrupts. 1483 * 1484 * Note that the SYSV Specialix drivers poll at 100 times per second to get 1485 * better response. We could really use a "periodic" version timeout(). :-) 1486 */ 1487#ifdef POLL 1488static void 1489si_poll(void *nothing) 1490{ 1491 struct si_softc *sc; 1492 int i; 1493 volatile struct si_reg *regp; 1494 struct si_port *pp; 1495 int lost, oldspl, port; 1496 1497 DPRINT((0, DBG_POLL, "si_poll()\n")); 1498 oldspl = spltty(); 1499 if (in_intr) 1500 goto out; 1501 lost = 0; 1502 for (i = 0; i < si_numunits; i++) { 1503 sc = devclass_get_softc(si_devclass, i); 1504 if (sc == NULL || sc->sc_type == SIEMPTY) 1505 continue; 1506 regp = (struct si_reg *)sc->sc_maddr; 1507 1508 /* 1509 * See if there has been a pending interrupt for 2 seconds 1510 * or so. The test (int_scounter >= 200) won't correspond 1511 * to 2 seconds if int_count gets changed. 1512 */ 1513 if (regp->int_pending != 0) { 1514 if (regp->int_scounter >= 200 && 1515 regp->initstat == 1) { 1516 printf("si%d: lost intr\n", i); 1517 lost++; 1518 } 1519 } else { 1520 regp->int_scounter = 0; 1521 } 1522 1523 /* 1524 * gripe about no input flow control.. 1525 */ 1526 pp = sc->sc_ports; 1527 for (port = 0; port < sc->sc_nport; pp++, port++) { 1528 if (pp->sp_delta_overflows > 0) { 1529 printf("si%d: %d tty level buffer overflows\n", 1530 i, pp->sp_delta_overflows); 1531 pp->sp_delta_overflows = 0; 1532 } 1533 } 1534 } 1535 if (lost || si_realpoll) 1536 si_intr(NULL); /* call intr with fake vector */ 1537out: 1538 splx(oldspl); 1539 1540 timeout(si_poll, (caddr_t)0L, si_pollrate); 1541} 1542#endif /* ifdef POLL */ 1543 1544/* 1545 * The interrupt handler polls ALL ports on ALL adapters each time 1546 * it is called. 1547 */ 1548 1549static BYTE si_rxbuf[SI_BUFFERSIZE]; /* input staging area */ 1550static BYTE si_txbuf[SI_BUFFERSIZE]; /* output staging area */ 1551 1552void 1553si_intr(void *arg) 1554{ 1555 struct si_softc *sc; 1556 struct si_port *pp; 1557 volatile struct si_channel *ccbp; 1558 struct tty *tp; 1559 volatile caddr_t maddr; 1560 BYTE op, ip; 1561 int x, card, port, n, i, isopen; 1562 volatile BYTE *z; 1563 BYTE c; 1564 1565 sc = arg; 1566 1567 DPRINT((0, arg == NULL ? DBG_POLL:DBG_INTR, "si_intr\n")); 1568 if (in_intr) 1569 return; 1570 in_intr = 1; 1571 1572 /* 1573 * When we get an int we poll all the channels and do ALL pending 1574 * work, not just the first one we find. This allows all cards to 1575 * share the same vector. 1576 * 1577 * XXX - But if we're sharing the vector with something that's NOT 1578 * a SI/XIO/SX card, we may be making more work for ourselves. 1579 */ 1580 for (card = 0; card < si_numunits; card++) { 1581 sc = devclass_get_softc(si_devclass, card); 1582 if (sc == NULL || sc->sc_type == SIEMPTY) 1583 continue; 1584 1585 /* 1586 * First, clear the interrupt 1587 */ 1588 switch(sc->sc_type) { 1589 case SIHOST: 1590 maddr = sc->sc_maddr; 1591 ((volatile struct si_reg *)maddr)->int_pending = 0; 1592 /* flag nothing pending */ 1593 *(maddr+SIINTCL) = 0x00; /* Set IRQ clear */ 1594 *(maddr+SIINTCL_CL) = 0x00; /* Clear IRQ clear */ 1595 break; 1596 case SIHOST2: 1597 maddr = sc->sc_maddr; 1598 ((volatile struct si_reg *)maddr)->int_pending = 0; 1599 *(maddr+SIPLIRQCLR) = 0x00; 1600 *(maddr+SIPLIRQCLR) = 0x10; 1601 break; 1602 case SIPCI: 1603 maddr = sc->sc_maddr; 1604 ((volatile struct si_reg *)maddr)->int_pending = 0; 1605 *(maddr+SIPCIINTCL) = 0x0; 1606 break; 1607 case SIJETPCI: /* fall through to JETISA case */ 1608 case SIJETISA: 1609 maddr = sc->sc_maddr; 1610 ((volatile struct si_reg *)maddr)->int_pending = 0; 1611 *(maddr+SIJETINTCL) = 0x0; 1612 break; 1613 case SIEISA: 1614 maddr = sc->sc_maddr; 1615 ((volatile struct si_reg *)maddr)->int_pending = 0; 1616 (void)inb(sc->sc_iobase + 3); 1617 break; 1618 case SIEMPTY: 1619 default: 1620 continue; 1621 } 1622 ((volatile struct si_reg *)maddr)->int_scounter = 0; 1623 1624 /* 1625 * check each port 1626 */ 1627 for (pp = sc->sc_ports, port = 0; port < sc->sc_nport; 1628 pp++, port++) { 1629 ccbp = pp->sp_ccb; 1630 tp = pp->sp_tty; 1631 1632 /* 1633 * See if a command has completed ? 1634 */ 1635 if (ccbp->hi_stat != pp->sp_pend) { 1636 DPRINT((pp, DBG_INTR, 1637 "si_intr hi_stat = 0x%x, pend = %d\n", 1638 ccbp->hi_stat, pp->sp_pend)); 1639 switch(pp->sp_pend) { 1640 case LOPEN: 1641 case MPEND: 1642 case MOPEN: 1643 case CONFIG: 1644 case SBREAK: 1645 case EBREAK: 1646 pp->sp_pend = ccbp->hi_stat; 1647 /* sleeping in si_command */ 1648 wakeup(&pp->sp_state); 1649 break; 1650 default: 1651 pp->sp_pend = ccbp->hi_stat; 1652 } 1653 } 1654 1655 /* 1656 * Continue on if it's closed 1657 */ 1658 if (ccbp->hi_stat == IDLE_CLOSE) { 1659 continue; 1660 } 1661 1662 /* 1663 * Do modem state change if not a local device 1664 */ 1665 si_modem_state(pp, tp, ccbp->hi_ip); 1666 1667 /* 1668 * Check to see if we should 'receive' characters. 1669 */ 1670 if (tp->t_state & TS_CONNECTED && 1671 tp->t_state & TS_ISOPEN) 1672 isopen = 1; 1673 else 1674 isopen = 0; 1675 1676 /* 1677 * Do input break processing 1678 */ 1679 if (ccbp->hi_state & ST_BREAK) { 1680 if (isopen) { 1681 ttyld_rint(tp, TTY_BI); 1682 } 1683 ccbp->hi_state &= ~ST_BREAK; /* A Bit iffy this */ 1684 DPRINT((pp, DBG_INTR, "si_intr break\n")); 1685 } 1686 1687 /* 1688 * Do RX stuff - if not open then dump any characters. 1689 * XXX: This is VERY messy and needs to be cleaned up. 1690 * 1691 * XXX: can we leave data in the host adapter buffer 1692 * when the clists are full? That may be dangerous 1693 * if the user cannot get an interrupt signal through. 1694 */ 1695 1696 more_rx: /* XXX Sorry. the nesting was driving me bats! :-( */ 1697 1698 if (!isopen) { 1699 ccbp->hi_rxopos = ccbp->hi_rxipos; 1700 goto end_rx; 1701 } 1702 1703 /* 1704 * If the tty input buffers are blocked, stop emptying 1705 * the incoming buffers and let the auto flow control 1706 * assert.. 1707 */ 1708 if (tp->t_state & TS_TBLOCK) { 1709 goto end_rx; 1710 } 1711 1712 /* 1713 * Process read characters if not skipped above 1714 */ 1715 op = ccbp->hi_rxopos; 1716 ip = ccbp->hi_rxipos; 1717 c = ip - op; 1718 if (c == 0) { 1719 goto end_rx; 1720 } 1721 1722 n = c & 0xff; 1723 if (n > 250) 1724 n = 250; 1725 1726 DPRINT((pp, DBG_INTR, "n = %d, op = %d, ip = %d\n", 1727 n, op, ip)); 1728 1729 /* 1730 * Suck characters out of host card buffer into the 1731 * "input staging buffer" - so that we dont leave the 1732 * host card in limbo while we're possibly echoing 1733 * characters and possibly flushing input inside the 1734 * ldisc l_rint() routine. 1735 */ 1736 if (n <= SI_BUFFERSIZE - op) { 1737 1738 DPRINT((pp, DBG_INTR, "\tsingle copy\n")); 1739 z = ccbp->hi_rxbuf + op; 1740 si_vbcopy(z, si_rxbuf, n); 1741 1742 op += n; 1743 } else { 1744 x = SI_BUFFERSIZE - op; 1745 1746 DPRINT((pp, DBG_INTR, "\tdouble part 1 %d\n", x)); 1747 z = ccbp->hi_rxbuf + op; 1748 si_vbcopy(z, si_rxbuf, x); 1749 1750 DPRINT((pp, DBG_INTR, "\tdouble part 2 %d\n", 1751 n - x)); 1752 z = ccbp->hi_rxbuf; 1753 si_vbcopy(z, si_rxbuf + x, n - x); 1754 1755 op += n; 1756 } 1757 1758 /* clear collected characters from buffer */ 1759 ccbp->hi_rxopos = op; 1760 1761 DPRINT((pp, DBG_INTR, "n = %d, op = %d, ip = %d\n", 1762 n, op, ip)); 1763 1764 /* 1765 * at this point... 1766 * n = number of chars placed in si_rxbuf 1767 */ 1768 1769 /* 1770 * Avoid the grotesquely inefficient lineswitch 1771 * routine (ttyinput) in "raw" mode. It usually 1772 * takes about 450 instructions (that's without 1773 * canonical processing or echo!). slinput is 1774 * reasonably fast (usually 40 instructions 1775 * plus call overhead). 1776 */ 1777 if (tp->t_state & TS_CAN_BYPASS_L_RINT) { 1778 1779 /* block if the driver supports it */ 1780 if (tp->t_rawq.c_cc + n >= SI_I_HIGH_WATER && 1781 (tp->t_cflag & CRTS_IFLOW || 1782 tp->t_iflag & IXOFF) && 1783 !(tp->t_state & TS_TBLOCK)) 1784 ttyblock(tp); 1785 1786 tk_nin += n; 1787 tk_rawcc += n; 1788 tp->t_rawcc += n; 1789 1790 pp->sp_delta_overflows += 1791 b_to_q((char *)si_rxbuf, n, &tp->t_rawq); 1792 1793 ttwakeup(tp); 1794 if (tp->t_state & TS_TTSTOP && 1795 (tp->t_iflag & IXANY || 1796 tp->t_cc[VSTART] == tp->t_cc[VSTOP])) { 1797 tp->t_state &= ~TS_TTSTOP; 1798 tp->t_lflag &= ~FLUSHO; 1799 si_start(tp); 1800 } 1801 } else { 1802 /* 1803 * It'd be nice to not have to go through the 1804 * function call overhead for each char here. 1805 * It'd be nice to block input it, saving a 1806 * loop here and the call/return overhead. 1807 */ 1808 for(x = 0; x < n; x++) { 1809 i = si_rxbuf[x]; 1810 if (ttyld_rint(tp, i) 1811 == -1) { 1812 pp->sp_delta_overflows++; 1813 } 1814 } 1815 } 1816 goto more_rx; /* try for more until RXbuf is empty */ 1817 1818 end_rx: /* XXX: Again, sorry about the gotos.. :-) */ 1819 1820 /* 1821 * Do TX stuff 1822 */ 1823 ttyld_start(tp); 1824 1825 } /* end of for (all ports on this controller) */ 1826 } /* end of for (all controllers) */ 1827 1828 in_intr = 0; 1829 DPRINT((0, arg == NULL ? DBG_POLL:DBG_INTR, "end si_intr\n")); 1830} 1831 1832/* 1833 * Nudge the transmitter... 1834 * 1835 * XXX: I inherited some funny code here. It implies the host card only 1836 * interrupts when the transmit buffer reaches the low-water-mark, and does 1837 * not interrupt when it's actually hits empty. In some cases, we have 1838 * processes waiting for complete drain, and we need to simulate an interrupt 1839 * about when we think the buffer is going to be empty (and retry if not). 1840 * I really am not certain about this... I *need* the hardware manuals. 1841 */ 1842static void 1843si_start(struct tty *tp) 1844{ 1845 struct si_port *pp; 1846 volatile struct si_channel *ccbp; 1847 struct clist *qp; 1848 BYTE ipos; 1849 int nchar; 1850 int oldspl, count, n, amount, buffer_full; 1851 1852 oldspl = spltty(); 1853 1854 qp = &tp->t_outq; 1855 pp = TP2PP(tp); 1856 1857 DPRINT((pp, DBG_ENTRY|DBG_START, 1858 "si_start(%x) t_state %x sp_state %x t_outq.c_cc %d\n", 1859 tp, tp->t_state, pp->sp_state, qp->c_cc)); 1860 1861 if (tp->t_state & (TS_TIMEOUT|TS_TTSTOP)) 1862 goto out; 1863 1864 buffer_full = 0; 1865 ccbp = pp->sp_ccb; 1866 1867 count = (int)ccbp->hi_txipos - (int)ccbp->hi_txopos; 1868 DPRINT((pp, DBG_START, "count %d\n", (BYTE)count)); 1869 1870 while ((nchar = qp->c_cc) > 0) { 1871 if ((BYTE)count >= 255) { 1872 buffer_full++; 1873 break; 1874 } 1875 amount = min(nchar, (255 - (BYTE)count)); 1876 ipos = (unsigned int)ccbp->hi_txipos; 1877 n = q_to_b(&tp->t_outq, si_txbuf, amount); 1878 /* will it fit in one lump? */ 1879 if ((SI_BUFFERSIZE - ipos) >= n) { 1880 si_bcopyv(si_txbuf, &ccbp->hi_txbuf[ipos], n); 1881 } else { 1882 si_bcopyv(si_txbuf, &ccbp->hi_txbuf[ipos], 1883 SI_BUFFERSIZE - ipos); 1884 si_bcopyv(si_txbuf + (SI_BUFFERSIZE - ipos), 1885 &ccbp->hi_txbuf[0], n - (SI_BUFFERSIZE - ipos)); 1886 } 1887 ccbp->hi_txipos += n; 1888 count = (int)ccbp->hi_txipos - (int)ccbp->hi_txopos; 1889 } 1890 1891 if (count != 0 && nchar == 0) { 1892 tp->t_state |= TS_BUSY; 1893 } else { 1894 tp->t_state &= ~TS_BUSY; 1895 } 1896 1897 /* wakeup time? */ 1898 ttwwakeup(tp); 1899 1900 DPRINT((pp, DBG_START, "count %d, nchar %d, tp->t_state 0x%x\n", 1901 (BYTE)count, nchar, tp->t_state)); 1902 1903 if (tp->t_state & TS_BUSY) 1904 { 1905 int time; 1906 1907 time = ttspeedtab(tp->t_ospeed, chartimes); 1908 1909 if (time > 0) { 1910 if (time < nchar) 1911 time = nchar / time; 1912 else 1913 time = 2; 1914 } else { 1915 DPRINT((pp, DBG_START, 1916 "bad char time value! %d\n", time)); 1917 time = hz/10; 1918 } 1919 1920 if ((pp->sp_state & (SS_LSTART|SS_INLSTART)) == SS_LSTART) { 1921 untimeout(si_lstart, (caddr_t)pp, pp->lstart_ch); 1922 } else { 1923 pp->sp_state |= SS_LSTART; 1924 } 1925 DPRINT((pp, DBG_START, "arming lstart, time=%d\n", time)); 1926 pp->lstart_ch = timeout(si_lstart, (caddr_t)pp, time); 1927 } 1928 1929out: 1930 splx(oldspl); 1931 DPRINT((pp, DBG_EXIT|DBG_START, "leave si_start()\n")); 1932} 1933 1934/* 1935 * Note: called at splsoftclock from the timeout code 1936 * This has to deal with two things... cause wakeups while waiting for 1937 * tty drains on last process exit, and call l_start at about the right 1938 * time for protocols like ppp. 1939 */ 1940static void 1941si_lstart(void *arg) 1942{ 1943 struct si_port *pp = arg; 1944 struct tty *tp; 1945 int oldspl; 1946 1947 DPRINT((pp, DBG_ENTRY|DBG_LSTART, "si_lstart(%x) sp_state %x\n", 1948 pp, pp->sp_state)); 1949 1950 oldspl = spltty(); 1951 1952 if ((pp->sp_state & SS_OPEN) == 0 || (pp->sp_state & SS_LSTART) == 0) { 1953 splx(oldspl); 1954 return; 1955 } 1956 pp->sp_state &= ~SS_LSTART; 1957 pp->sp_state |= SS_INLSTART; 1958 1959 tp = pp->sp_tty; 1960 1961 /* deal with the process exit case */ 1962 ttwwakeup(tp); 1963 1964 /* nudge protocols - eg: ppp */ 1965 ttyld_start(tp); 1966 1967 pp->sp_state &= ~SS_INLSTART; 1968 splx(oldspl); 1969} 1970 1971/* 1972 * Stop output on a line. called at spltty(); 1973 */ 1974static void 1975si_stop(struct tty *tp, int rw) 1976{ 1977 volatile struct si_channel *ccbp; 1978 struct si_port *pp; 1979 1980 pp = TP2PP(tp); 1981 ccbp = pp->sp_ccb; 1982 1983 DPRINT((TP2PP(tp), DBG_ENTRY|DBG_STOP, "si_stop(%x,%x)\n", tp, rw)); 1984 1985 /* XXX: must check (rw & FWRITE | FREAD) etc flushing... */ 1986 if (rw & FWRITE) { 1987 /* what level are we meant to be flushing anyway? */ 1988 if (tp->t_state & TS_BUSY) { 1989 si_command(TP2PP(tp), WFLUSH, SI_NOWAIT); 1990 tp->t_state &= ~TS_BUSY; 1991 ttwwakeup(tp); /* Bruce???? */ 1992 } 1993 } 1994#if 1 /* XXX: this doesn't work right yet.. */ 1995 /* XXX: this may have been failing because we used to call l_rint() 1996 * while we were looping based on these two counters. Now, we collect 1997 * the data and then loop stuffing it into l_rint(), making this 1998 * useless. Should we cause this to blow away the staging buffer? 1999 */ 2000 if (rw & FREAD) { 2001 ccbp->hi_rxopos = ccbp->hi_rxipos; 2002 } 2003#endif 2004} 2005 2006/* 2007 * Issue a command to the host card CPU. 2008 */ 2009 2010static void 2011si_command(struct si_port *pp, int cmd, int waitflag) 2012{ 2013 int oldspl; 2014 volatile struct si_channel *ccbp = pp->sp_ccb; 2015 int x; 2016 2017 DPRINT((pp, DBG_ENTRY|DBG_PARAM, "si_command(%x,%x,%d): hi_stat 0x%x\n", 2018 pp, cmd, waitflag, ccbp->hi_stat)); 2019 2020 oldspl = spltty(); /* Keep others out */ 2021 2022 /* wait until it's finished what it was doing.. */ 2023 /* XXX: sits in IDLE_BREAK until something disturbs it or break 2024 * is turned off. */ 2025 while((x = ccbp->hi_stat) != IDLE_OPEN && 2026 x != IDLE_CLOSE && 2027 x != IDLE_BREAK && 2028 x != cmd) { 2029 if (in_intr) { /* Prevent sleep in intr */ 2030 DPRINT((pp, DBG_PARAM, 2031 "cmd intr collision - completing %d\trequested %d\n", 2032 x, cmd)); 2033 splx(oldspl); 2034 return; 2035 } else if (ttysleep(pp->sp_tty, (caddr_t)&pp->sp_state, TTIPRI|PCATCH, 2036 "sicmd1", 1)) { 2037 splx(oldspl); 2038 return; 2039 } 2040 } 2041 /* it should now be in IDLE_{OPEN|CLOSE|BREAK}, or "cmd" */ 2042 2043 /* if there was a pending command, cause a state-change wakeup */ 2044 switch(pp->sp_pend) { 2045 case LOPEN: 2046 case MPEND: 2047 case MOPEN: 2048 case CONFIG: 2049 case SBREAK: 2050 case EBREAK: 2051 wakeup(&pp->sp_state); 2052 break; 2053 default: 2054 break; 2055 } 2056 2057 pp->sp_pend = cmd; /* New command pending */ 2058 ccbp->hi_stat = cmd; /* Post it */ 2059 2060 if (waitflag) { 2061 if (in_intr) { /* If in interrupt handler */ 2062 DPRINT((pp, DBG_PARAM, 2063 "attempt to sleep in si_intr - cmd req %d\n", 2064 cmd)); 2065 splx(oldspl); 2066 return; 2067 } else while(ccbp->hi_stat != IDLE_OPEN && 2068 ccbp->hi_stat != IDLE_BREAK) { 2069 if (ttysleep(pp->sp_tty, (caddr_t)&pp->sp_state, TTIPRI|PCATCH, 2070 "sicmd2", 0)) 2071 break; 2072 } 2073 } 2074 splx(oldspl); 2075} 2076 2077 2078#ifdef SI_DEBUG 2079 2080void 2081si_dprintf(struct si_port *pp, int flags, const char *fmt, ...) 2082{ 2083 va_list ap; 2084 2085 if ((pp == NULL && (si_debug&flags)) || 2086 (pp != NULL && ((pp->sp_debug&flags) || (si_debug&flags)))) { 2087 if (pp != NULL) 2088 printf("%ci%d(%d): ", 's', 2089 (int)SI_CARD(minor(pp->sp_tty->t_dev)), 2090 (int)SI_PORT(minor(pp->sp_tty->t_dev))); 2091 va_start(ap, fmt); 2092 vprintf(fmt, ap); 2093 va_end(ap); 2094 } 2095} 2096 2097static char * 2098si_mctl2str(enum si_mctl cmd) 2099{ 2100 switch (cmd) { 2101 case GET: 2102 return("GET"); 2103 case SET: 2104 return("SET"); 2105 case BIS: 2106 return("BIS"); 2107 case BIC: 2108 return("BIC"); 2109 } 2110 return("BAD"); 2111} 2112 2113#endif /* DEBUG */ 2114 2115static char * 2116si_modulename(int host_type, int uart_type) 2117{ 2118 switch (host_type) { 2119 /* Z280 based cards */ 2120 case SIEISA: 2121 case SIHOST2: 2122 case SIHOST: 2123 case SIPCI: 2124 switch (uart_type) { 2125 case 0: 2126 return(" (XIO)"); 2127 case 1: 2128 return(" (SI)"); 2129 } 2130 break; 2131 /* T225 based hosts */ 2132 case SIJETPCI: 2133 case SIJETISA: 2134 switch (uart_type) { 2135 case 0: 2136 return(" (SI)"); 2137 case 40: 2138 return(" (XIO)"); 2139 case 72: 2140 return(" (SXDC)"); 2141 } 2142 break; 2143 } 2144 return(""); 2145}
| 51#include <sys/ioctl_compat.h> 52#endif 53#include <sys/tty.h> 54#include <sys/conf.h> 55#include <sys/fcntl.h> 56#include <sys/kernel.h> 57#include <sys/malloc.h> 58#include <sys/sysctl.h> 59#include <sys/bus.h> 60#include <machine/bus.h> 61#include <sys/rman.h> 62#include <machine/resource.h> 63 64 65#include <vm/vm.h> 66#include <vm/pmap.h> 67 68#include <machine/stdarg.h> 69 70#include <dev/si/sireg.h> 71#include <dev/si/sivar.h> 72#include <dev/si/si.h> 73 74/* 75 * This device driver is designed to interface the Specialix International 76 * SI, XIO and SX range of serial multiplexor cards to FreeBSD on an ISA, 77 * EISA or PCI bus machine. 78 * 79 * The controller is interfaced to the host via dual port RAM 80 * and an interrupt. 81 * 82 * The code for the Host 1 (very old ISA cards) has not been tested. 83 */ 84 85#define POLL /* turn on poller to scan for lost interrupts */ 86#define REALPOLL /* on each poll, scan for work regardless */ 87#define POLLHZ (hz/10) /* 10 times per second */ 88#define SI_I_HIGH_WATER (TTYHOG - 2 * SI_BUFFERSIZE) 89#define INT_COUNT 25000 /* max of 125 ints per second */ 90#define JET_INT_COUNT 100 /* max of 100 ints per second */ 91#define RXINT_COUNT 1 /* one rxint per 10 milliseconds */ 92 93enum si_mctl { GET, SET, BIS, BIC }; 94 95static void si_command(struct si_port *, int, int); 96static int si_modem(struct si_port *, enum si_mctl, int); 97static void si_write_enable(struct si_port *, int); 98static int si_Sioctl(dev_t, u_long, caddr_t, int, struct thread *); 99static void si_start(struct tty *); 100static void si_stop(struct tty *, int); 101static timeout_t si_lstart; 102static void sihardclose(struct si_port *pp); 103static void sidtrwakeup(void *chan); 104 105#ifdef SI_DEBUG 106static char *si_mctl2str(enum si_mctl cmd); 107#endif 108 109static int siparam(struct tty *, struct termios *); 110 111static void si_modem_state(struct si_port *pp, struct tty *tp, int hi_ip); 112static char * si_modulename(int host_type, int uart_type); 113 114static d_open_t siopen; 115static d_close_t siclose; 116static d_write_t siwrite; 117static d_ioctl_t siioctl; 118 119static struct cdevsw si_cdevsw = { 120 .d_version = D_VERSION, 121 .d_open = siopen, 122 .d_close = siclose, 123 .d_write = siwrite, 124 .d_ioctl = siioctl, 125 .d_name = "si", 126 .d_flags = D_TTY | D_NEEDGIANT, 127}; 128 129static int si_Nports; 130static int si_Nmodules; 131static int si_debug = 0; /* data, not bss, so it's patchable */ 132 133SYSCTL_INT(_machdep, OID_AUTO, si_debug, CTLFLAG_RW, &si_debug, 0, ""); 134TUNABLE_INT("machdep.si_debug", &si_debug); 135 136static int si_numunits; 137 138devclass_t si_devclass; 139 140#ifndef B2000 /* not standard, but the hardware knows it. */ 141# define B2000 2000 142#endif 143static struct speedtab bdrates[] = { 144 { B75, CLK75, }, /* 0x0 */ 145 { B110, CLK110, }, /* 0x1 */ 146 { B150, CLK150, }, /* 0x3 */ 147 { B300, CLK300, }, /* 0x4 */ 148 { B600, CLK600, }, /* 0x5 */ 149 { B1200, CLK1200, }, /* 0x6 */ 150 { B2000, CLK2000, }, /* 0x7 */ 151 { B2400, CLK2400, }, /* 0x8 */ 152 { B4800, CLK4800, }, /* 0x9 */ 153 { B9600, CLK9600, }, /* 0xb */ 154 { B19200, CLK19200, }, /* 0xc */ 155 { B38400, CLK38400, }, /* 0x2 (out of order!) */ 156 { B57600, CLK57600, }, /* 0xd */ 157 { B115200, CLK110, }, /* 0x1 (dupe!, 110 baud on "si") */ 158 { -1, -1 }, 159}; 160 161 162/* populated with approx character/sec rates - translated at card 163 * initialisation time to chars per tick of the clock */ 164static int done_chartimes = 0; 165static struct speedtab chartimes[] = { 166 { B75, 8, }, 167 { B110, 11, }, 168 { B150, 15, }, 169 { B300, 30, }, 170 { B600, 60, }, 171 { B1200, 120, }, 172 { B2000, 200, }, 173 { B2400, 240, }, 174 { B4800, 480, }, 175 { B9600, 960, }, 176 { B19200, 1920, }, 177 { B38400, 3840, }, 178 { B57600, 5760, }, 179 { B115200, 11520, }, 180 { -1, -1 }, 181}; 182static volatile int in_intr = 0; /* Inside interrupt handler? */ 183 184#ifdef POLL 185static int si_pollrate; /* in addition to irq */ 186static int si_realpoll = 0; /* poll HW on timer */ 187 188SYSCTL_INT(_machdep, OID_AUTO, si_pollrate, CTLFLAG_RW, &si_pollrate, 0, ""); 189SYSCTL_INT(_machdep, OID_AUTO, si_realpoll, CTLFLAG_RW, &si_realpoll, 0, ""); 190 191static int init_finished = 0; 192static void si_poll(void *); 193#endif 194 195/* 196 * Array of adapter types and the corresponding RAM size. The order of 197 * entries here MUST match the ordinal of the adapter type. 198 */ 199static char *si_type[] = { 200 "EMPTY", 201 "SIHOST", 202 "SIMCA", /* FreeBSD does not support Microchannel */ 203 "SIHOST2", 204 "SIEISA", 205 "SIPCI", 206 "SXPCI", 207 "SXISA", 208}; 209 210/* 211 * We have to make an 8 bit version of bcopy, since some cards can't 212 * deal with 32 bit I/O 213 */ 214static void __inline 215si_bcopy(const void *src, void *dst, size_t len) 216{ 217 while (len--) 218 *(((u_char *)dst)++) = *(((const u_char *)src)++); 219} 220static void __inline 221si_vbcopy(const volatile void *src, void *dst, size_t len) 222{ 223 while (len--) 224 *(((u_char *)dst)++) = *(((const volatile u_char *)src)++); 225} 226static void __inline 227si_bcopyv(const void *src, volatile void *dst, size_t len) 228{ 229 while (len--) 230 *(((volatile u_char *)dst)++) = *(((const u_char *)src)++); 231} 232 233 234/* 235 * Attach the device. Initialize the card. 236 */ 237int 238siattach(device_t dev) 239{ 240 int unit; 241 struct si_softc *sc; 242 struct si_port *pp; 243 volatile struct si_channel *ccbp; 244 volatile struct si_reg *regp; 245 volatile caddr_t maddr; 246 struct si_module *modp; 247 struct speedtab *spt; 248 int nmodule, nport, x, y; 249 int uart_type; 250 251 sc = device_get_softc(dev); 252 unit = device_get_unit(dev); 253 254 sc->sc_typename = si_type[sc->sc_type]; 255 if (si_numunits < unit + 1) 256 si_numunits = unit + 1; 257 258 DPRINT((0, DBG_AUTOBOOT, "si%d: siattach\n", unit)); 259 260#ifdef POLL 261 if (si_pollrate == 0) { 262 si_pollrate = POLLHZ; /* in addition to irq */ 263#ifdef REALPOLL 264 si_realpoll = 1; /* scan always */ 265#endif 266 } 267#endif 268 269 DPRINT((0, DBG_AUTOBOOT, "si%d: type: %s paddr: %x maddr: %x\n", unit, 270 sc->sc_typename, sc->sc_paddr, sc->sc_maddr)); 271 272 sc->sc_ports = NULL; /* mark as uninitialised */ 273 274 maddr = sc->sc_maddr; 275 276 /* Stop the CPU first so it won't stomp around while we load */ 277 278 switch (sc->sc_type) { 279 case SIEISA: 280 outb(sc->sc_iobase + 2, sc->sc_irq << 4); 281 break; 282 case SIPCI: 283 *(maddr+SIPCIRESET) = 0; 284 break; 285 case SIJETPCI: /* fall through to JET ISA */ 286 case SIJETISA: 287 *(maddr+SIJETCONFIG) = 0; 288 break; 289 case SIHOST2: 290 *(maddr+SIPLRESET) = 0; 291 break; 292 case SIHOST: 293 *(maddr+SIRESET) = 0; 294 break; 295 default: /* this should never happen */ 296 printf("si%d: unsupported configuration\n", unit); 297 return EINVAL; 298 break; 299 } 300 301 /* OK, now lets download the download code */ 302 303 if (SI_ISJET(sc->sc_type)) { 304 DPRINT((0, DBG_DOWNLOAD, "si%d: jet_download: nbytes %d\n", 305 unit, si3_t225_dsize)); 306 si_bcopy(si3_t225_download, maddr + si3_t225_downloadaddr, 307 si3_t225_dsize); 308 DPRINT((0, DBG_DOWNLOAD, 309 "si%d: jet_bootstrap: nbytes %d -> %x\n", 310 unit, si3_t225_bsize, si3_t225_bootloadaddr)); 311 si_bcopy(si3_t225_bootstrap, maddr + si3_t225_bootloadaddr, 312 si3_t225_bsize); 313 } else { 314 DPRINT((0, DBG_DOWNLOAD, "si%d: si_download: nbytes %d\n", 315 unit, si2_z280_dsize)); 316 si_bcopy(si2_z280_download, maddr + si2_z280_downloadaddr, 317 si2_z280_dsize); 318 } 319 320 /* Now start the CPU */ 321 322 switch (sc->sc_type) { 323 case SIEISA: 324 /* modify the download code to tell it that it's on an EISA */ 325 *(maddr + 0x42) = 1; 326 outb(sc->sc_iobase + 2, (sc->sc_irq << 4) | 4); 327 (void)inb(sc->sc_iobase + 3); /* reset interrupt */ 328 break; 329 case SIPCI: 330 /* modify the download code to tell it that it's on a PCI */ 331 *(maddr+0x42) = 1; 332 *(maddr+SIPCIRESET) = 1; 333 *(maddr+SIPCIINTCL) = 0; 334 break; 335 case SIJETPCI: 336 *(maddr+SIJETRESET) = 0; 337 *(maddr+SIJETCONFIG) = SIJETBUSEN|SIJETIRQEN; 338 break; 339 case SIJETISA: 340 *(maddr+SIJETRESET) = 0; 341 switch (sc->sc_irq) { 342 case 9: 343 *(maddr+SIJETCONFIG) = SIJETBUSEN|SIJETIRQEN|0x90; 344 break; 345 case 10: 346 *(maddr+SIJETCONFIG) = SIJETBUSEN|SIJETIRQEN|0xa0; 347 break; 348 case 11: 349 *(maddr+SIJETCONFIG) = SIJETBUSEN|SIJETIRQEN|0xb0; 350 break; 351 case 12: 352 *(maddr+SIJETCONFIG) = SIJETBUSEN|SIJETIRQEN|0xc0; 353 break; 354 case 15: 355 *(maddr+SIJETCONFIG) = SIJETBUSEN|SIJETIRQEN|0xf0; 356 break; 357 } 358 break; 359 case SIHOST: 360 *(maddr+SIRESET_CL) = 0; 361 *(maddr+SIINTCL_CL) = 0; 362 break; 363 case SIHOST2: 364 *(maddr+SIPLRESET) = 0x10; 365 switch (sc->sc_irq) { 366 case 11: 367 *(maddr+SIPLIRQ11) = 0x10; 368 break; 369 case 12: 370 *(maddr+SIPLIRQ12) = 0x10; 371 break; 372 case 15: 373 *(maddr+SIPLIRQ15) = 0x10; 374 break; 375 } 376 *(maddr+SIPLIRQCLR) = 0x10; 377 break; 378 default: /* this should _REALLY_ never happen */ 379 printf("si%d: Uh, it was supported a second ago...\n", unit); 380 return EINVAL; 381 } 382 383 DELAY(1000000); /* wait around for a second */ 384 385 regp = (struct si_reg *)maddr; 386 y = 0; 387 /* wait max of 5 sec for init OK */ 388 while (regp->initstat == 0 && y++ < 10) { 389 DELAY(500000); 390 } 391 switch (regp->initstat) { 392 case 0: 393 printf("si%d: startup timeout - aborting\n", unit); 394 sc->sc_type = SIEMPTY; 395 return EINVAL; 396 case 1: 397 if (SI_ISJET(sc->sc_type)) { 398 /* set throttle to 100 times per second */ 399 regp->int_count = JET_INT_COUNT; 400 /* rx_intr_count is a NOP in Jet */ 401 } else { 402 /* set throttle to 125 times per second */ 403 regp->int_count = INT_COUNT; 404 /* rx intr max of 25 times per second */ 405 regp->rx_int_count = RXINT_COUNT; 406 } 407 regp->int_pending = 0; /* no intr pending */ 408 regp->int_scounter = 0; /* reset counter */ 409 break; 410 case 0xff: 411 /* 412 * No modules found, so give up on this one. 413 */ 414 printf("si%d: %s - no ports found\n", unit, 415 si_type[sc->sc_type]); 416 return 0; 417 default: 418 printf("si%d: download code version error - initstat %x\n", 419 unit, regp->initstat); 420 return EINVAL; 421 } 422 423 /* 424 * First time around the ports just count them in order 425 * to allocate some memory. 426 */ 427 nport = 0; 428 modp = (struct si_module *)(maddr + 0x80); 429 for (;;) { 430 DPRINT((0, DBG_DOWNLOAD, "si%d: ccb addr 0x%x\n", unit, modp)); 431 switch (modp->sm_type) { 432 case TA4: 433 DPRINT((0, DBG_DOWNLOAD, 434 "si%d: Found old TA4 module, 4 ports\n", 435 unit)); 436 x = 4; 437 break; 438 case TA8: 439 DPRINT((0, DBG_DOWNLOAD, 440 "si%d: Found old TA8 module, 8 ports\n", 441 unit)); 442 x = 8; 443 break; 444 case TA4_ASIC: 445 DPRINT((0, DBG_DOWNLOAD, 446 "si%d: Found ASIC TA4 module, 4 ports\n", 447 unit)); 448 x = 4; 449 break; 450 case TA8_ASIC: 451 DPRINT((0, DBG_DOWNLOAD, 452 "si%d: Found ASIC TA8 module, 8 ports\n", 453 unit)); 454 x = 8; 455 break; 456 case MTA: 457 DPRINT((0, DBG_DOWNLOAD, 458 "si%d: Found CD1400 module, 8 ports\n", 459 unit)); 460 x = 8; 461 break; 462 case SXDC: 463 DPRINT((0, DBG_DOWNLOAD, 464 "si%d: Found SXDC module, 8 ports\n", 465 unit)); 466 x = 8; 467 break; 468 default: 469 printf("si%d: unknown module type %d\n", 470 unit, modp->sm_type); 471 goto try_next; 472 } 473 474 /* this was limited in firmware and is also a driver issue */ 475 if ((nport + x) > SI_MAXPORTPERCARD) { 476 printf("si%d: extra ports ignored\n", unit); 477 goto try_next; 478 } 479 480 nport += x; 481 si_Nports += x; 482 si_Nmodules++; 483 484try_next: 485 if (modp->sm_next == 0) 486 break; 487 modp = (struct si_module *) 488 (maddr + (unsigned)(modp->sm_next & 0x7fff)); 489 } 490 sc->sc_ports = (struct si_port *)malloc(sizeof(struct si_port) * nport, 491 M_DEVBUF, M_NOWAIT | M_ZERO); 492 if (sc->sc_ports == 0) { 493 printf("si%d: fail to malloc memory for port structs\n", 494 unit); 495 return EINVAL; 496 } 497 sc->sc_nport = nport; 498 499 /* 500 * Scan round the ports again, this time initialising. 501 */ 502 pp = sc->sc_ports; 503 nmodule = 0; 504 modp = (struct si_module *)(maddr + 0x80); 505 uart_type = 1000; /* arbitary, > uchar_max */ 506 for (;;) { 507 switch (modp->sm_type) { 508 case TA4: 509 nport = 4; 510 break; 511 case TA8: 512 nport = 8; 513 break; 514 case TA4_ASIC: 515 nport = 4; 516 break; 517 case TA8_ASIC: 518 nport = 8; 519 break; 520 case MTA: 521 nport = 8; 522 break; 523 case SXDC: 524 nport = 8; 525 break; 526 default: 527 goto try_next2; 528 } 529 nmodule++; 530 ccbp = (struct si_channel *)((char *)modp + 0x100); 531 if (uart_type == 1000) 532 uart_type = ccbp->type; 533 else if (uart_type != ccbp->type) 534 printf("si%d: Warning: module %d mismatch! (%d%s != %d%s)\n", 535 unit, nmodule, 536 ccbp->type, si_modulename(sc->sc_type, ccbp->type), 537 uart_type, si_modulename(sc->sc_type, uart_type)); 538 539 for (x = 0; x < nport; x++, pp++, ccbp++) { 540 pp->sp_ccb = ccbp; /* save the address */ 541 pp->sp_tty = ttymalloc(NULL); 542 pp->sp_pend = IDLE_CLOSE; 543 pp->sp_state = 0; /* internal flag */ 544 pp->sp_dtr_wait = 3 * hz; 545 pp->sp_iin.c_iflag = TTYDEF_IFLAG; 546 pp->sp_iin.c_oflag = TTYDEF_OFLAG; 547 pp->sp_iin.c_cflag = TTYDEF_CFLAG; 548 pp->sp_iin.c_lflag = TTYDEF_LFLAG; 549 termioschars(&pp->sp_iin); 550 pp->sp_iin.c_ispeed = pp->sp_iin.c_ospeed = 551 TTYDEF_SPEED;; 552 pp->sp_iout = pp->sp_iin; 553 } 554try_next2: 555 if (modp->sm_next == 0) { 556 printf("si%d: card: %s, ports: %d, modules: %d, type: %d%s\n", 557 unit, 558 sc->sc_typename, 559 sc->sc_nport, 560 nmodule, 561 uart_type, 562 si_modulename(sc->sc_type, uart_type)); 563 break; 564 } 565 modp = (struct si_module *) 566 (maddr + (unsigned)(modp->sm_next & 0x7fff)); 567 } 568 if (done_chartimes == 0) { 569 for (spt = chartimes ; spt->sp_speed != -1; spt++) { 570 if ((spt->sp_code /= hz) == 0) 571 spt->sp_code = 1; 572 } 573 done_chartimes = 1; 574 } 575 576/* path name devsw minor type uid gid perm*/ 577 for (x = 0; x < sc->sc_nport; x++) { 578 /* sync with the manuals that start at 1 */ 579 y = x + 1 + unit * (1 << SI_CARDSHIFT); 580 make_dev(&si_cdevsw, x, 0, 0, 0600, "ttyA%02d", y); 581 make_dev(&si_cdevsw, x + 0x00080, 0, 0, 0600, "cuaA%02d", y); 582 make_dev(&si_cdevsw, x + 0x10000, 0, 0, 0600, "ttyiA%02d", y); 583 make_dev(&si_cdevsw, x + 0x10080, 0, 0, 0600, "cuaiA%02d", y); 584 make_dev(&si_cdevsw, x + 0x20000, 0, 0, 0600, "ttylA%02d", y); 585 make_dev(&si_cdevsw, x + 0x20080, 0, 0, 0600, "cualA%02d", y); 586 } 587 make_dev(&si_cdevsw, 0x40000, 0, 0, 0600, "si_control"); 588 return (0); 589} 590 591static int 592siopen(dev_t dev, int flag, int mode, struct thread *td) 593{ 594 int oldspl, error; 595 int card, port; 596 struct si_softc *sc; 597 struct tty *tp; 598 volatile struct si_channel *ccbp; 599 struct si_port *pp; 600 int mynor = minor(dev); 601 602 /* quickly let in /dev/si_control */ 603 if (IS_CONTROLDEV(mynor)) { 604 if ((error = suser(td))) 605 return(error); 606 return(0); 607 } 608 609 card = SI_CARD(mynor); 610 sc = devclass_get_softc(si_devclass, card); 611 if (sc == NULL) 612 return (ENXIO); 613 614 if (sc->sc_type == SIEMPTY) { 615 DPRINT((0, DBG_OPEN|DBG_FAIL, "si%d: type %s??\n", 616 card, sc->sc_typename)); 617 return(ENXIO); 618 } 619 620 port = SI_PORT(mynor); 621 if (port >= sc->sc_nport) { 622 DPRINT((0, DBG_OPEN|DBG_FAIL, "si%d: nports %d\n", 623 card, sc->sc_nport)); 624 return(ENXIO); 625 } 626 627#ifdef POLL 628 /* 629 * We've now got a device, so start the poller. 630 */ 631 if (init_finished == 0) { 632 timeout(si_poll, (caddr_t)0L, si_pollrate); 633 init_finished = 1; 634 } 635#endif 636 637 /* initial/lock device */ 638 if (IS_STATE(mynor)) { 639 return(0); 640 } 641 642 pp = sc->sc_ports + port; 643 tp = pp->sp_tty; /* the "real" tty */ 644 dev->si_tty = tp; 645 ccbp = pp->sp_ccb; /* Find control block */ 646 DPRINT((pp, DBG_ENTRY|DBG_OPEN, "siopen(%s,%x,%x,%x)\n", 647 devtoname(dev), flag, mode, td)); 648 649 oldspl = spltty(); /* Keep others out */ 650 error = 0; 651 652open_top: 653 while (pp->sp_state & SS_DTR_OFF) { 654 error = tsleep(&pp->sp_dtr_wait, TTIPRI|PCATCH, "sidtr", 0); 655 if (error != 0) 656 goto out; 657 } 658 659 if (tp->t_state & TS_ISOPEN) { 660 /* 661 * The device is open, so everything has been initialised. 662 * handle conflicts. 663 */ 664 if (IS_CALLOUT(mynor)) { 665 if (!pp->sp_active_out) { 666 error = EBUSY; 667 goto out; 668 } 669 } else { 670 if (pp->sp_active_out) { 671 if (flag & O_NONBLOCK) { 672 error = EBUSY; 673 goto out; 674 } 675 error = tsleep(&pp->sp_active_out, 676 TTIPRI|PCATCH, "sibi", 0); 677 if (error != 0) 678 goto out; 679 goto open_top; 680 } 681 } 682 if (tp->t_state & TS_XCLUDE && 683 suser(td)) { 684 DPRINT((pp, DBG_OPEN|DBG_FAIL, 685 "already open and EXCLUSIVE set\n")); 686 error = EBUSY; 687 goto out; 688 } 689 } else { 690 /* 691 * The device isn't open, so there are no conflicts. 692 * Initialize it. Avoid sleep... :-) 693 */ 694 DPRINT((pp, DBG_OPEN, "first open\n")); 695 tp->t_oproc = si_start; 696 tp->t_stop = si_stop; 697 tp->t_param = siparam; 698 tp->t_dev = dev; 699 tp->t_termios = mynor & SI_CALLOUT_MASK 700 ? pp->sp_iout : pp->sp_iin; 701 702 (void) si_modem(pp, SET, TIOCM_DTR|TIOCM_RTS); 703 704 ++pp->sp_wopeners; /* in case of sleep in siparam */ 705 706 error = siparam(tp, &tp->t_termios); 707 708 --pp->sp_wopeners; 709 if (error != 0) 710 goto out; 711 /* XXX: we should goto_top if siparam slept */ 712 713 /* set initial DCD state */ 714 pp->sp_last_hi_ip = ccbp->hi_ip; 715 if ((pp->sp_last_hi_ip & IP_DCD) || IS_CALLOUT(mynor)) { 716 ttyld_modem(tp, 1); 717 } 718 } 719 720 /* whoops! we beat the close! */ 721 if (pp->sp_state & SS_CLOSING) { 722 /* try and stop it from proceeding to bash the hardware */ 723 pp->sp_state &= ~SS_CLOSING; 724 } 725 726 /* 727 * Wait for DCD if necessary 728 */ 729 if (!(tp->t_state & TS_CARR_ON) && 730 !IS_CALLOUT(mynor) && 731 !(tp->t_cflag & CLOCAL) && 732 !(flag & O_NONBLOCK)) { 733 ++pp->sp_wopeners; 734 DPRINT((pp, DBG_OPEN, "sleeping for carrier\n")); 735 error = tsleep(TSA_CARR_ON(tp), TTIPRI|PCATCH, "sidcd", 0); 736 --pp->sp_wopeners; 737 if (error != 0) 738 goto out; 739 goto open_top; 740 } 741 742 error = ttyld_open(tp, dev); 743 pp->sp_hotchar = ttyldoptim(tp); 744 if (tp->t_state & TS_ISOPEN && IS_CALLOUT(mynor)) 745 pp->sp_active_out = TRUE; 746 747 pp->sp_state |= SS_OPEN; /* made it! */ 748 749out: 750 splx(oldspl); 751 752 DPRINT((pp, DBG_OPEN, "leaving siopen\n")); 753 754 if (!(tp->t_state & TS_ISOPEN) && pp->sp_wopeners == 0) 755 sihardclose(pp); 756 757 return(error); 758} 759 760static int 761siclose(dev_t dev, int flag, int mode, struct thread *td) 762{ 763 struct si_port *pp; 764 struct tty *tp; 765 int oldspl; 766 int error = 0; 767 int mynor = minor(dev); 768 769 if (IS_SPECIAL(mynor)) 770 return(0); 771 772 oldspl = spltty(); 773 774 pp = MINOR2PP(mynor); 775 tp = pp->sp_tty; 776 777 DPRINT((pp, DBG_ENTRY|DBG_CLOSE, "siclose(%s,%x,%x,%x) sp_state:%x\n", 778 devtoname(dev), flag, mode, td, pp->sp_state)); 779 780 /* did we sleep and loose a race? */ 781 if (pp->sp_state & SS_CLOSING) { 782 /* error = ESOMETING? */ 783 goto out; 784 } 785 786 /* begin race detection.. */ 787 pp->sp_state |= SS_CLOSING; 788 789 si_write_enable(pp, 0); /* block writes for ttywait() */ 790 791 /* THIS MAY SLEEP IN TTYWAIT!!! */ 792 ttyld_close(tp, flag); 793 794 si_write_enable(pp, 1); 795 796 /* did we sleep and somebody started another open? */ 797 if (!(pp->sp_state & SS_CLOSING)) { 798 /* error = ESOMETING? */ 799 goto out; 800 } 801 /* ok. we are now still on the right track.. nuke the hardware */ 802 803 if (pp->sp_state & SS_LSTART) { 804 untimeout(si_lstart, (caddr_t)pp, pp->lstart_ch); 805 pp->sp_state &= ~SS_LSTART; 806 } 807 808 sihardclose(pp); 809 ttyclose(tp); 810 pp->sp_state &= ~SS_OPEN; 811 812out: 813 DPRINT((pp, DBG_CLOSE|DBG_EXIT, "close done, returning\n")); 814 splx(oldspl); 815 return(error); 816} 817 818static void 819sihardclose(struct si_port *pp) 820{ 821 int oldspl; 822 struct tty *tp; 823 volatile struct si_channel *ccbp; 824 825 oldspl = spltty(); 826 827 tp = pp->sp_tty; 828 ccbp = pp->sp_ccb; /* Find control block */ 829 if (tp->t_cflag & HUPCL || 830 (!pp->sp_active_out && 831 !(ccbp->hi_ip & IP_DCD) && 832 !(pp->sp_iin.c_cflag && CLOCAL)) || 833 !(tp->t_state & TS_ISOPEN)) { 834 835 (void) si_modem(pp, BIC, TIOCM_DTR|TIOCM_RTS); 836 (void) si_command(pp, FCLOSE, SI_NOWAIT); 837 838 if (pp->sp_dtr_wait != 0) { 839 timeout(sidtrwakeup, pp, pp->sp_dtr_wait); 840 pp->sp_state |= SS_DTR_OFF; 841 } 842 843 } 844 pp->sp_active_out = FALSE; 845 wakeup(&pp->sp_active_out); 846 wakeup(TSA_CARR_ON(tp)); 847 848 splx(oldspl); 849} 850 851 852/* 853 * called at splsoftclock()... 854 */ 855static void 856sidtrwakeup(void *chan) 857{ 858 struct si_port *pp; 859 int oldspl; 860 861 oldspl = spltty(); 862 863 pp = (struct si_port *)chan; 864 pp->sp_state &= ~SS_DTR_OFF; 865 wakeup(&pp->sp_dtr_wait); 866 867 splx(oldspl); 868} 869 870static int 871siwrite(dev_t dev, struct uio *uio, int flag) 872{ 873 struct si_port *pp; 874 struct tty *tp; 875 int error = 0; 876 int mynor = minor(dev); 877 int oldspl; 878 879 if (IS_SPECIAL(mynor)) { 880 DPRINT((0, DBG_ENTRY|DBG_FAIL|DBG_WRITE, "siwrite(CONTROLDEV!!)\n")); 881 return(ENODEV); 882 } 883 pp = MINOR2PP(mynor); 884 tp = pp->sp_tty; 885 DPRINT((pp, DBG_WRITE, "siwrite(%s,%x,%x)\n", devtoname(dev), uio, flag)); 886 887 oldspl = spltty(); 888 /* 889 * If writes are currently blocked, wait on the "real" tty 890 */ 891 while (pp->sp_state & SS_BLOCKWRITE) { 892 pp->sp_state |= SS_WAITWRITE; 893 DPRINT((pp, DBG_WRITE, "in siwrite, wait for SS_BLOCKWRITE to clear\n")); 894 if ((error = ttysleep(tp, (caddr_t)pp, TTOPRI|PCATCH, 895 "siwrite", tp->t_timeout))) { 896 if (error == EWOULDBLOCK) 897 error = EIO; 898 goto out; 899 } 900 } 901 902 error = ttyld_write(tp, uio, flag); 903out: 904 splx(oldspl); 905 return (error); 906} 907 908 909static int 910siioctl(dev_t dev, u_long cmd, caddr_t data, int flag, struct thread *td) 911{ 912 struct si_port *pp; 913 struct tty *tp; 914 int error; 915 int mynor = minor(dev); 916 int oldspl; 917 int blocked = 0; 918#if defined(COMPAT_43) 919 u_long oldcmd; 920 struct termios term; 921#endif 922 923 if (IS_SI_IOCTL(cmd)) 924 return(si_Sioctl(dev, cmd, data, flag, td)); 925 926 pp = MINOR2PP(mynor); 927 tp = pp->sp_tty; 928 929 DPRINT((pp, DBG_ENTRY|DBG_IOCTL, "siioctl(%s,%lx,%x,%x)\n", 930 devtoname(dev), cmd, data, flag)); 931 if (IS_STATE(mynor)) { 932 struct termios *ct; 933 934 switch (mynor & SI_STATE_MASK) { 935 case SI_INIT_STATE_MASK: 936 ct = IS_CALLOUT(mynor) ? &pp->sp_iout : &pp->sp_iin; 937 break; 938 case SI_LOCK_STATE_MASK: 939 ct = IS_CALLOUT(mynor) ? &pp->sp_lout : &pp->sp_lin; 940 break; 941 default: 942 return (ENODEV); 943 } 944 switch (cmd) { 945 case TIOCSETA: 946 error = suser(td); 947 if (error != 0) 948 return (error); 949 *ct = *(struct termios *)data; 950 return (0); 951 case TIOCGETA: 952 *(struct termios *)data = *ct; 953 return (0); 954 case TIOCGETD: 955 *(int *)data = TTYDISC; 956 return (0); 957 case TIOCGWINSZ: 958 bzero(data, sizeof(struct winsize)); 959 return (0); 960 default: 961 return (ENOTTY); 962 } 963 } 964 /* 965 * Do the old-style ioctl compat routines... 966 */ 967#if defined(COMPAT_43) 968 term = tp->t_termios; 969 oldcmd = cmd; 970 error = ttsetcompat(tp, &cmd, data, &term); 971 if (error != 0) 972 return (error); 973 if (cmd != oldcmd) 974 data = (caddr_t)&term; 975#endif 976 /* 977 * Do the initial / lock state business 978 */ 979 if (cmd == TIOCSETA || cmd == TIOCSETAW || cmd == TIOCSETAF) { 980 int cc; 981 struct termios *dt = (struct termios *)data; 982 struct termios *lt = mynor & SI_CALLOUT_MASK 983 ? &pp->sp_lout : &pp->sp_lin; 984 985 dt->c_iflag = (tp->t_iflag & lt->c_iflag) | 986 (dt->c_iflag & ~lt->c_iflag); 987 dt->c_oflag = (tp->t_oflag & lt->c_oflag) | 988 (dt->c_oflag & ~lt->c_oflag); 989 dt->c_cflag = (tp->t_cflag & lt->c_cflag) | 990 (dt->c_cflag & ~lt->c_cflag); 991 dt->c_lflag = (tp->t_lflag & lt->c_lflag) | 992 (dt->c_lflag & ~lt->c_lflag); 993 for (cc = 0; cc < NCCS; ++cc) 994 if (lt->c_cc[cc] != 0) 995 dt->c_cc[cc] = tp->t_cc[cc]; 996 if (lt->c_ispeed != 0) 997 dt->c_ispeed = tp->t_ispeed; 998 if (lt->c_ospeed != 0) 999 dt->c_ospeed = tp->t_ospeed; 1000 } 1001 1002 /* 1003 * Block user-level writes to give the ttywait() 1004 * a chance to completely drain for commands 1005 * that require the port to be in a quiescent state. 1006 */ 1007 switch (cmd) { 1008 case TIOCSETAW: 1009 case TIOCSETAF: 1010 case TIOCDRAIN: 1011#ifdef COMPAT_43 1012 case TIOCSETP: 1013#endif 1014 blocked++; /* block writes for ttywait() and siparam() */ 1015 si_write_enable(pp, 0); 1016 } 1017 1018 error = ttyioctl(dev, cmd, data, flag, td); 1019 pp->sp_hotchar = ttyldoptim(tp); 1020 if (error != ENOTTY) 1021 goto out; 1022 1023 oldspl = spltty(); 1024 1025 error = 0; 1026 switch (cmd) { 1027 case TIOCSBRK: 1028 si_command(pp, SBREAK, SI_WAIT); 1029 break; 1030 case TIOCCBRK: 1031 si_command(pp, EBREAK, SI_WAIT); 1032 break; 1033 case TIOCSDTR: 1034 (void) si_modem(pp, SET, TIOCM_DTR|TIOCM_RTS); 1035 break; 1036 case TIOCCDTR: 1037 (void) si_modem(pp, SET, 0); 1038 break; 1039 case TIOCMSET: 1040 (void) si_modem(pp, SET, *(int *)data); 1041 break; 1042 case TIOCMBIS: 1043 (void) si_modem(pp, BIS, *(int *)data); 1044 break; 1045 case TIOCMBIC: 1046 (void) si_modem(pp, BIC, *(int *)data); 1047 break; 1048 case TIOCMGET: 1049 *(int *)data = si_modem(pp, GET, 0); 1050 break; 1051 case TIOCMSDTRWAIT: 1052 /* must be root since the wait applies to following logins */ 1053 error = suser(td); 1054 if (error == 0) 1055 pp->sp_dtr_wait = *(int *)data * hz / 100; 1056 break; 1057 case TIOCMGDTRWAIT: 1058 *(int *)data = pp->sp_dtr_wait * 100 / hz; 1059 break; 1060 default: 1061 error = ENOTTY; 1062 } 1063 splx(oldspl); 1064 1065out: 1066 DPRINT((pp, DBG_IOCTL|DBG_EXIT, "siioctl ret %d\n", error)); 1067 if (blocked) 1068 si_write_enable(pp, 1); 1069 return(error); 1070} 1071 1072/* 1073 * Handle the Specialix ioctls. All MUST be called via the CONTROL device 1074 */ 1075static int 1076si_Sioctl(dev_t dev, u_long cmd, caddr_t data, int flag, struct thread *td) 1077{ 1078 struct si_softc *xsc; 1079 struct si_port *xpp; 1080 volatile struct si_reg *regp; 1081 struct si_tcsi *dp; 1082 struct si_pstat *sps; 1083 int *ip, error = 0; 1084 int oldspl; 1085 int card, port; 1086 int mynor = minor(dev); 1087 1088 DPRINT((0, DBG_ENTRY|DBG_IOCTL, "si_Sioctl(%s,%lx,%x,%x)\n", 1089 devtoname(dev), cmd, data, flag)); 1090 1091#if 1 1092 DPRINT((0, DBG_IOCTL, "TCSI_PORT=%x\n", TCSI_PORT)); 1093 DPRINT((0, DBG_IOCTL, "TCSI_CCB=%x\n", TCSI_CCB)); 1094 DPRINT((0, DBG_IOCTL, "TCSI_TTY=%x\n", TCSI_TTY)); 1095#endif 1096 1097 if (!IS_CONTROLDEV(mynor)) { 1098 DPRINT((0, DBG_IOCTL|DBG_FAIL, "not called from control device!\n")); 1099 return(ENODEV); 1100 } 1101 1102 oldspl = spltty(); /* better safe than sorry */ 1103 1104 ip = (int *)data; 1105 1106#define SUCHECK if ((error = suser(td))) goto out 1107 1108 switch (cmd) { 1109 case TCSIPORTS: 1110 *ip = si_Nports; 1111 goto out; 1112 case TCSIMODULES: 1113 *ip = si_Nmodules; 1114 goto out; 1115 case TCSISDBG_ALL: 1116 SUCHECK; 1117 si_debug = *ip; 1118 goto out; 1119 case TCSIGDBG_ALL: 1120 *ip = si_debug; 1121 goto out; 1122 default: 1123 /* 1124 * Check that a controller for this port exists 1125 */ 1126 1127 /* may also be a struct si_pstat, a superset of si_tcsi */ 1128 1129 dp = (struct si_tcsi *)data; 1130 sps = (struct si_pstat *)data; 1131 card = dp->tc_card; 1132 xsc = devclass_get_softc(si_devclass, card); /* check.. */ 1133 if (xsc == NULL || xsc->sc_type == SIEMPTY) { 1134 error = ENOENT; 1135 goto out; 1136 } 1137 /* 1138 * And check that a port exists 1139 */ 1140 port = dp->tc_port; 1141 if (port < 0 || port >= xsc->sc_nport) { 1142 error = ENOENT; 1143 goto out; 1144 } 1145 xpp = xsc->sc_ports + port; 1146 regp = (struct si_reg *)xsc->sc_maddr; 1147 } 1148 1149 switch (cmd) { 1150 case TCSIDEBUG: 1151#ifdef SI_DEBUG 1152 SUCHECK; 1153 if (xpp->sp_debug) 1154 xpp->sp_debug = 0; 1155 else { 1156 xpp->sp_debug = DBG_ALL; 1157 DPRINT((xpp, DBG_IOCTL, "debug toggled %s\n", 1158 (xpp->sp_debug&DBG_ALL)?"ON":"OFF")); 1159 } 1160 break; 1161#else 1162 error = ENODEV; 1163 goto out; 1164#endif 1165 case TCSISDBG_LEVEL: 1166 case TCSIGDBG_LEVEL: 1167#ifdef SI_DEBUG 1168 if (cmd == TCSIGDBG_LEVEL) { 1169 dp->tc_dbglvl = xpp->sp_debug; 1170 } else { 1171 SUCHECK; 1172 xpp->sp_debug = dp->tc_dbglvl; 1173 } 1174 break; 1175#else 1176 error = ENODEV; 1177 goto out; 1178#endif 1179 case TCSIGRXIT: 1180 dp->tc_int = regp->rx_int_count; 1181 break; 1182 case TCSIRXIT: 1183 SUCHECK; 1184 regp->rx_int_count = dp->tc_int; 1185 break; 1186 case TCSIGIT: 1187 dp->tc_int = regp->int_count; 1188 break; 1189 case TCSIIT: 1190 SUCHECK; 1191 regp->int_count = dp->tc_int; 1192 break; 1193 case TCSISTATE: 1194 dp->tc_int = xpp->sp_ccb->hi_ip; 1195 break; 1196 /* these next three use a different structure */ 1197 case TCSI_PORT: 1198 SUCHECK; 1199 si_bcopy(xpp, &sps->tc_siport, sizeof(sps->tc_siport)); 1200 break; 1201 case TCSI_CCB: 1202 SUCHECK; 1203 si_vbcopy(xpp->sp_ccb, &sps->tc_ccb, sizeof(sps->tc_ccb)); 1204 break; 1205 case TCSI_TTY: 1206 SUCHECK; 1207 si_bcopy(xpp->sp_tty, &sps->tc_tty, sizeof(sps->tc_tty)); 1208 break; 1209 default: 1210 error = EINVAL; 1211 goto out; 1212 } 1213out: 1214 splx(oldspl); 1215 return(error); /* success */ 1216} 1217 1218/* 1219 * siparam() : Configure line params 1220 * called at spltty(); 1221 * this may sleep, does not flush, nor wait for drain, nor block writes 1222 * caller must arrange this if it's important.. 1223 */ 1224static int 1225siparam(struct tty *tp, struct termios *t) 1226{ 1227 struct si_port *pp = TP2PP(tp); 1228 volatile struct si_channel *ccbp; 1229 int oldspl, cflag, iflag, oflag, lflag; 1230 int error = 0; /* shutup gcc */ 1231 int ispeed = 0; /* shutup gcc */ 1232 int ospeed = 0; /* shutup gcc */ 1233 BYTE val; 1234 1235 DPRINT((pp, DBG_ENTRY|DBG_PARAM, "siparam(%x,%x)\n", tp, t)); 1236 cflag = t->c_cflag; 1237 iflag = t->c_iflag; 1238 oflag = t->c_oflag; 1239 lflag = t->c_lflag; 1240 DPRINT((pp, DBG_PARAM, "OFLAG 0x%x CFLAG 0x%x IFLAG 0x%x LFLAG 0x%x\n", 1241 oflag, cflag, iflag, lflag)); 1242 1243 /* XXX - if Jet host and SXDC module, use extended baud rates */ 1244 1245 /* if not hung up.. */ 1246 if (t->c_ospeed != 0) { 1247 /* translate baud rate to firmware values */ 1248 ospeed = ttspeedtab(t->c_ospeed, bdrates); 1249 ispeed = t->c_ispeed ? 1250 ttspeedtab(t->c_ispeed, bdrates) : ospeed; 1251 1252 /* enforce legit baud rate */ 1253 if (ospeed < 0 || ispeed < 0) 1254 return (EINVAL); 1255 } 1256 1257 oldspl = spltty(); 1258 1259 ccbp = pp->sp_ccb; 1260 1261 /* ========== set hi_break ========== */ 1262 val = 0; 1263 if (iflag & IGNBRK) /* Breaks */ 1264 val |= BR_IGN; 1265 if (iflag & BRKINT) /* Interrupt on break? */ 1266 val |= BR_INT; 1267 if (iflag & PARMRK) /* Parity mark? */ 1268 val |= BR_PARMRK; 1269 if (iflag & IGNPAR) /* Ignore chars with parity errors? */ 1270 val |= BR_PARIGN; 1271 ccbp->hi_break = val; 1272 1273 /* ========== set hi_csr ========== */ 1274 /* if not hung up.. */ 1275 if (t->c_ospeed != 0) { 1276 /* Set I/O speeds */ 1277 val = (ispeed << 4) | ospeed; 1278 } 1279 ccbp->hi_csr = val; 1280 1281 /* ========== set hi_mr2 ========== */ 1282 val = 0; 1283 if (cflag & CSTOPB) /* Stop bits */ 1284 val |= MR2_2_STOP; 1285 else 1286 val |= MR2_1_STOP; 1287 /* 1288 * Enable H/W RTS/CTS handshaking. The default TA/MTA is 1289 * a DCE, hence the reverse sense of RTS and CTS 1290 */ 1291 /* Output Flow - RTS must be raised before data can be sent */ 1292 if (cflag & CCTS_OFLOW) 1293 val |= MR2_RTSCONT; 1294 1295 ccbp->hi_mr2 = val; 1296 1297 /* ========== set hi_mr1 ========== */ 1298 val = 0; 1299 if (!(cflag & PARENB)) /* Parity */ 1300 val |= MR1_NONE; 1301 else 1302 val |= MR1_WITH; 1303 if (cflag & PARODD) 1304 val |= MR1_ODD; 1305 1306 if ((cflag & CS8) == CS8) { /* 8 data bits? */ 1307 val |= MR1_8_BITS; 1308 } else if ((cflag & CS7) == CS7) { /* 7 data bits? */ 1309 val |= MR1_7_BITS; 1310 } else if ((cflag & CS6) == CS6) { /* 6 data bits? */ 1311 val |= MR1_6_BITS; 1312 } else { /* Must be 5 */ 1313 val |= MR1_5_BITS; 1314 } 1315 /* 1316 * Enable H/W RTS/CTS handshaking. The default TA/MTA is 1317 * a DCE, hence the reverse sense of RTS and CTS 1318 */ 1319 /* Input Flow - CTS is raised when port is ready to receive data */ 1320 if (cflag & CRTS_IFLOW) 1321 val |= MR1_CTSCONT; 1322 1323 ccbp->hi_mr1 = val; 1324 1325 /* ========== set hi_mask ========== */ 1326 val = 0xff; 1327 if ((cflag & CS8) == CS8) { /* 8 data bits? */ 1328 val &= 0xFF; 1329 } else if ((cflag & CS7) == CS7) { /* 7 data bits? */ 1330 val &= 0x7F; 1331 } else if ((cflag & CS6) == CS6) { /* 6 data bits? */ 1332 val &= 0x3F; 1333 } else { /* Must be 5 */ 1334 val &= 0x1F; 1335 } 1336 if (iflag & ISTRIP) 1337 val &= 0x7F; 1338 1339 ccbp->hi_mask = val; 1340 1341 /* ========== set hi_prtcl ========== */ 1342 val = SP_DCEN; /* Monitor DCD always, or TIOCMGET misses it */ 1343 if (iflag & IXANY) 1344 val |= SP_TANY; 1345 if (iflag & IXON) 1346 val |= SP_TXEN; 1347 if (iflag & IXOFF) 1348 val |= SP_RXEN; 1349 if (iflag & INPCK) 1350 val |= SP_PAEN; 1351 1352 ccbp->hi_prtcl = val; 1353 1354 1355 /* ========== set hi_{rx|tx}{on|off} ========== */ 1356 /* XXX: the card TOTALLY shields us from the flow control... */ 1357 ccbp->hi_txon = t->c_cc[VSTART]; 1358 ccbp->hi_txoff = t->c_cc[VSTOP]; 1359 1360 ccbp->hi_rxon = t->c_cc[VSTART]; 1361 ccbp->hi_rxoff = t->c_cc[VSTOP]; 1362 1363 /* ========== send settings to the card ========== */ 1364 /* potential sleep here */ 1365 if (ccbp->hi_stat == IDLE_CLOSE) /* Not yet open */ 1366 si_command(pp, LOPEN, SI_WAIT); /* open it */ 1367 else 1368 si_command(pp, CONFIG, SI_WAIT); /* change params */ 1369 1370 /* ========== set DTR etc ========== */ 1371 /* Hangup if ospeed == 0 */ 1372 if (t->c_ospeed == 0) { 1373 (void) si_modem(pp, BIC, TIOCM_DTR|TIOCM_RTS); 1374 } else { 1375 /* 1376 * If the previous speed was 0, may need to re-enable 1377 * the modem signals 1378 */ 1379 (void) si_modem(pp, SET, TIOCM_DTR|TIOCM_RTS); 1380 } 1381 1382 DPRINT((pp, DBG_PARAM, "siparam, complete: MR1 %x MR2 %x HI_MASK %x PRTCL %x HI_BREAK %x\n", 1383 ccbp->hi_mr1, ccbp->hi_mr2, ccbp->hi_mask, ccbp->hi_prtcl, ccbp->hi_break)); 1384 1385 splx(oldspl); 1386 return(error); 1387} 1388 1389/* 1390 * Enable or Disable the writes to this channel... 1391 * "state" -> enabled = 1; disabled = 0; 1392 */ 1393static void 1394si_write_enable(struct si_port *pp, int state) 1395{ 1396 int oldspl; 1397 1398 oldspl = spltty(); 1399 1400 if (state) { 1401 pp->sp_state &= ~SS_BLOCKWRITE; 1402 if (pp->sp_state & SS_WAITWRITE) { 1403 pp->sp_state &= ~SS_WAITWRITE; 1404 /* thunder away! */ 1405 wakeup(pp); 1406 } 1407 } else { 1408 pp->sp_state |= SS_BLOCKWRITE; 1409 } 1410 1411 splx(oldspl); 1412} 1413 1414/* 1415 * Set/Get state of modem control lines. 1416 * Due to DCE-like behaviour of the adapter, some signals need translation: 1417 * TIOCM_DTR DSR 1418 * TIOCM_RTS CTS 1419 */ 1420static int 1421si_modem(struct si_port *pp, enum si_mctl cmd, int bits) 1422{ 1423 volatile struct si_channel *ccbp; 1424 int x; 1425 1426 DPRINT((pp, DBG_ENTRY|DBG_MODEM, "si_modem(%x,%s,%x)\n", pp, si_mctl2str(cmd), bits)); 1427 ccbp = pp->sp_ccb; /* Find channel address */ 1428 switch (cmd) { 1429 case GET: 1430 x = ccbp->hi_ip; 1431 bits = TIOCM_LE; 1432 if (x & IP_DCD) bits |= TIOCM_CAR; 1433 if (x & IP_DTR) bits |= TIOCM_DTR; 1434 if (x & IP_RTS) bits |= TIOCM_RTS; 1435 if (x & IP_RI) bits |= TIOCM_RI; 1436 return(bits); 1437 case SET: 1438 ccbp->hi_op &= ~(OP_DSR|OP_CTS); 1439 /* fall through */ 1440 case BIS: 1441 x = 0; 1442 if (bits & TIOCM_DTR) 1443 x |= OP_DSR; 1444 if (bits & TIOCM_RTS) 1445 x |= OP_CTS; 1446 ccbp->hi_op |= x; 1447 break; 1448 case BIC: 1449 if (bits & TIOCM_DTR) 1450 ccbp->hi_op &= ~OP_DSR; 1451 if (bits & TIOCM_RTS) 1452 ccbp->hi_op &= ~OP_CTS; 1453 } 1454 return 0; 1455} 1456 1457/* 1458 * Handle change of modem state 1459 */ 1460static void 1461si_modem_state(struct si_port *pp, struct tty *tp, int hi_ip) 1462{ 1463 /* if a modem dev */ 1464 if (hi_ip & IP_DCD) { 1465 if (!(pp->sp_last_hi_ip & IP_DCD)) { 1466 DPRINT((pp, DBG_INTR, "modem carr on t_line %d\n", 1467 tp->t_line)); 1468 (void)ttyld_modem(tp, 1); 1469 } 1470 } else { 1471 if (pp->sp_last_hi_ip & IP_DCD) { 1472 DPRINT((pp, DBG_INTR, "modem carr off\n")); 1473 if (ttyld_modem(tp, 0)) 1474 (void) si_modem(pp, SET, 0); 1475 } 1476 } 1477 pp->sp_last_hi_ip = hi_ip; 1478 1479} 1480 1481/* 1482 * Poller to catch missed interrupts. 1483 * 1484 * Note that the SYSV Specialix drivers poll at 100 times per second to get 1485 * better response. We could really use a "periodic" version timeout(). :-) 1486 */ 1487#ifdef POLL 1488static void 1489si_poll(void *nothing) 1490{ 1491 struct si_softc *sc; 1492 int i; 1493 volatile struct si_reg *regp; 1494 struct si_port *pp; 1495 int lost, oldspl, port; 1496 1497 DPRINT((0, DBG_POLL, "si_poll()\n")); 1498 oldspl = spltty(); 1499 if (in_intr) 1500 goto out; 1501 lost = 0; 1502 for (i = 0; i < si_numunits; i++) { 1503 sc = devclass_get_softc(si_devclass, i); 1504 if (sc == NULL || sc->sc_type == SIEMPTY) 1505 continue; 1506 regp = (struct si_reg *)sc->sc_maddr; 1507 1508 /* 1509 * See if there has been a pending interrupt for 2 seconds 1510 * or so. The test (int_scounter >= 200) won't correspond 1511 * to 2 seconds if int_count gets changed. 1512 */ 1513 if (regp->int_pending != 0) { 1514 if (regp->int_scounter >= 200 && 1515 regp->initstat == 1) { 1516 printf("si%d: lost intr\n", i); 1517 lost++; 1518 } 1519 } else { 1520 regp->int_scounter = 0; 1521 } 1522 1523 /* 1524 * gripe about no input flow control.. 1525 */ 1526 pp = sc->sc_ports; 1527 for (port = 0; port < sc->sc_nport; pp++, port++) { 1528 if (pp->sp_delta_overflows > 0) { 1529 printf("si%d: %d tty level buffer overflows\n", 1530 i, pp->sp_delta_overflows); 1531 pp->sp_delta_overflows = 0; 1532 } 1533 } 1534 } 1535 if (lost || si_realpoll) 1536 si_intr(NULL); /* call intr with fake vector */ 1537out: 1538 splx(oldspl); 1539 1540 timeout(si_poll, (caddr_t)0L, si_pollrate); 1541} 1542#endif /* ifdef POLL */ 1543 1544/* 1545 * The interrupt handler polls ALL ports on ALL adapters each time 1546 * it is called. 1547 */ 1548 1549static BYTE si_rxbuf[SI_BUFFERSIZE]; /* input staging area */ 1550static BYTE si_txbuf[SI_BUFFERSIZE]; /* output staging area */ 1551 1552void 1553si_intr(void *arg) 1554{ 1555 struct si_softc *sc; 1556 struct si_port *pp; 1557 volatile struct si_channel *ccbp; 1558 struct tty *tp; 1559 volatile caddr_t maddr; 1560 BYTE op, ip; 1561 int x, card, port, n, i, isopen; 1562 volatile BYTE *z; 1563 BYTE c; 1564 1565 sc = arg; 1566 1567 DPRINT((0, arg == NULL ? DBG_POLL:DBG_INTR, "si_intr\n")); 1568 if (in_intr) 1569 return; 1570 in_intr = 1; 1571 1572 /* 1573 * When we get an int we poll all the channels and do ALL pending 1574 * work, not just the first one we find. This allows all cards to 1575 * share the same vector. 1576 * 1577 * XXX - But if we're sharing the vector with something that's NOT 1578 * a SI/XIO/SX card, we may be making more work for ourselves. 1579 */ 1580 for (card = 0; card < si_numunits; card++) { 1581 sc = devclass_get_softc(si_devclass, card); 1582 if (sc == NULL || sc->sc_type == SIEMPTY) 1583 continue; 1584 1585 /* 1586 * First, clear the interrupt 1587 */ 1588 switch(sc->sc_type) { 1589 case SIHOST: 1590 maddr = sc->sc_maddr; 1591 ((volatile struct si_reg *)maddr)->int_pending = 0; 1592 /* flag nothing pending */ 1593 *(maddr+SIINTCL) = 0x00; /* Set IRQ clear */ 1594 *(maddr+SIINTCL_CL) = 0x00; /* Clear IRQ clear */ 1595 break; 1596 case SIHOST2: 1597 maddr = sc->sc_maddr; 1598 ((volatile struct si_reg *)maddr)->int_pending = 0; 1599 *(maddr+SIPLIRQCLR) = 0x00; 1600 *(maddr+SIPLIRQCLR) = 0x10; 1601 break; 1602 case SIPCI: 1603 maddr = sc->sc_maddr; 1604 ((volatile struct si_reg *)maddr)->int_pending = 0; 1605 *(maddr+SIPCIINTCL) = 0x0; 1606 break; 1607 case SIJETPCI: /* fall through to JETISA case */ 1608 case SIJETISA: 1609 maddr = sc->sc_maddr; 1610 ((volatile struct si_reg *)maddr)->int_pending = 0; 1611 *(maddr+SIJETINTCL) = 0x0; 1612 break; 1613 case SIEISA: 1614 maddr = sc->sc_maddr; 1615 ((volatile struct si_reg *)maddr)->int_pending = 0; 1616 (void)inb(sc->sc_iobase + 3); 1617 break; 1618 case SIEMPTY: 1619 default: 1620 continue; 1621 } 1622 ((volatile struct si_reg *)maddr)->int_scounter = 0; 1623 1624 /* 1625 * check each port 1626 */ 1627 for (pp = sc->sc_ports, port = 0; port < sc->sc_nport; 1628 pp++, port++) { 1629 ccbp = pp->sp_ccb; 1630 tp = pp->sp_tty; 1631 1632 /* 1633 * See if a command has completed ? 1634 */ 1635 if (ccbp->hi_stat != pp->sp_pend) { 1636 DPRINT((pp, DBG_INTR, 1637 "si_intr hi_stat = 0x%x, pend = %d\n", 1638 ccbp->hi_stat, pp->sp_pend)); 1639 switch(pp->sp_pend) { 1640 case LOPEN: 1641 case MPEND: 1642 case MOPEN: 1643 case CONFIG: 1644 case SBREAK: 1645 case EBREAK: 1646 pp->sp_pend = ccbp->hi_stat; 1647 /* sleeping in si_command */ 1648 wakeup(&pp->sp_state); 1649 break; 1650 default: 1651 pp->sp_pend = ccbp->hi_stat; 1652 } 1653 } 1654 1655 /* 1656 * Continue on if it's closed 1657 */ 1658 if (ccbp->hi_stat == IDLE_CLOSE) { 1659 continue; 1660 } 1661 1662 /* 1663 * Do modem state change if not a local device 1664 */ 1665 si_modem_state(pp, tp, ccbp->hi_ip); 1666 1667 /* 1668 * Check to see if we should 'receive' characters. 1669 */ 1670 if (tp->t_state & TS_CONNECTED && 1671 tp->t_state & TS_ISOPEN) 1672 isopen = 1; 1673 else 1674 isopen = 0; 1675 1676 /* 1677 * Do input break processing 1678 */ 1679 if (ccbp->hi_state & ST_BREAK) { 1680 if (isopen) { 1681 ttyld_rint(tp, TTY_BI); 1682 } 1683 ccbp->hi_state &= ~ST_BREAK; /* A Bit iffy this */ 1684 DPRINT((pp, DBG_INTR, "si_intr break\n")); 1685 } 1686 1687 /* 1688 * Do RX stuff - if not open then dump any characters. 1689 * XXX: This is VERY messy and needs to be cleaned up. 1690 * 1691 * XXX: can we leave data in the host adapter buffer 1692 * when the clists are full? That may be dangerous 1693 * if the user cannot get an interrupt signal through. 1694 */ 1695 1696 more_rx: /* XXX Sorry. the nesting was driving me bats! :-( */ 1697 1698 if (!isopen) { 1699 ccbp->hi_rxopos = ccbp->hi_rxipos; 1700 goto end_rx; 1701 } 1702 1703 /* 1704 * If the tty input buffers are blocked, stop emptying 1705 * the incoming buffers and let the auto flow control 1706 * assert.. 1707 */ 1708 if (tp->t_state & TS_TBLOCK) { 1709 goto end_rx; 1710 } 1711 1712 /* 1713 * Process read characters if not skipped above 1714 */ 1715 op = ccbp->hi_rxopos; 1716 ip = ccbp->hi_rxipos; 1717 c = ip - op; 1718 if (c == 0) { 1719 goto end_rx; 1720 } 1721 1722 n = c & 0xff; 1723 if (n > 250) 1724 n = 250; 1725 1726 DPRINT((pp, DBG_INTR, "n = %d, op = %d, ip = %d\n", 1727 n, op, ip)); 1728 1729 /* 1730 * Suck characters out of host card buffer into the 1731 * "input staging buffer" - so that we dont leave the 1732 * host card in limbo while we're possibly echoing 1733 * characters and possibly flushing input inside the 1734 * ldisc l_rint() routine. 1735 */ 1736 if (n <= SI_BUFFERSIZE - op) { 1737 1738 DPRINT((pp, DBG_INTR, "\tsingle copy\n")); 1739 z = ccbp->hi_rxbuf + op; 1740 si_vbcopy(z, si_rxbuf, n); 1741 1742 op += n; 1743 } else { 1744 x = SI_BUFFERSIZE - op; 1745 1746 DPRINT((pp, DBG_INTR, "\tdouble part 1 %d\n", x)); 1747 z = ccbp->hi_rxbuf + op; 1748 si_vbcopy(z, si_rxbuf, x); 1749 1750 DPRINT((pp, DBG_INTR, "\tdouble part 2 %d\n", 1751 n - x)); 1752 z = ccbp->hi_rxbuf; 1753 si_vbcopy(z, si_rxbuf + x, n - x); 1754 1755 op += n; 1756 } 1757 1758 /* clear collected characters from buffer */ 1759 ccbp->hi_rxopos = op; 1760 1761 DPRINT((pp, DBG_INTR, "n = %d, op = %d, ip = %d\n", 1762 n, op, ip)); 1763 1764 /* 1765 * at this point... 1766 * n = number of chars placed in si_rxbuf 1767 */ 1768 1769 /* 1770 * Avoid the grotesquely inefficient lineswitch 1771 * routine (ttyinput) in "raw" mode. It usually 1772 * takes about 450 instructions (that's without 1773 * canonical processing or echo!). slinput is 1774 * reasonably fast (usually 40 instructions 1775 * plus call overhead). 1776 */ 1777 if (tp->t_state & TS_CAN_BYPASS_L_RINT) { 1778 1779 /* block if the driver supports it */ 1780 if (tp->t_rawq.c_cc + n >= SI_I_HIGH_WATER && 1781 (tp->t_cflag & CRTS_IFLOW || 1782 tp->t_iflag & IXOFF) && 1783 !(tp->t_state & TS_TBLOCK)) 1784 ttyblock(tp); 1785 1786 tk_nin += n; 1787 tk_rawcc += n; 1788 tp->t_rawcc += n; 1789 1790 pp->sp_delta_overflows += 1791 b_to_q((char *)si_rxbuf, n, &tp->t_rawq); 1792 1793 ttwakeup(tp); 1794 if (tp->t_state & TS_TTSTOP && 1795 (tp->t_iflag & IXANY || 1796 tp->t_cc[VSTART] == tp->t_cc[VSTOP])) { 1797 tp->t_state &= ~TS_TTSTOP; 1798 tp->t_lflag &= ~FLUSHO; 1799 si_start(tp); 1800 } 1801 } else { 1802 /* 1803 * It'd be nice to not have to go through the 1804 * function call overhead for each char here. 1805 * It'd be nice to block input it, saving a 1806 * loop here and the call/return overhead. 1807 */ 1808 for(x = 0; x < n; x++) { 1809 i = si_rxbuf[x]; 1810 if (ttyld_rint(tp, i) 1811 == -1) { 1812 pp->sp_delta_overflows++; 1813 } 1814 } 1815 } 1816 goto more_rx; /* try for more until RXbuf is empty */ 1817 1818 end_rx: /* XXX: Again, sorry about the gotos.. :-) */ 1819 1820 /* 1821 * Do TX stuff 1822 */ 1823 ttyld_start(tp); 1824 1825 } /* end of for (all ports on this controller) */ 1826 } /* end of for (all controllers) */ 1827 1828 in_intr = 0; 1829 DPRINT((0, arg == NULL ? DBG_POLL:DBG_INTR, "end si_intr\n")); 1830} 1831 1832/* 1833 * Nudge the transmitter... 1834 * 1835 * XXX: I inherited some funny code here. It implies the host card only 1836 * interrupts when the transmit buffer reaches the low-water-mark, and does 1837 * not interrupt when it's actually hits empty. In some cases, we have 1838 * processes waiting for complete drain, and we need to simulate an interrupt 1839 * about when we think the buffer is going to be empty (and retry if not). 1840 * I really am not certain about this... I *need* the hardware manuals. 1841 */ 1842static void 1843si_start(struct tty *tp) 1844{ 1845 struct si_port *pp; 1846 volatile struct si_channel *ccbp; 1847 struct clist *qp; 1848 BYTE ipos; 1849 int nchar; 1850 int oldspl, count, n, amount, buffer_full; 1851 1852 oldspl = spltty(); 1853 1854 qp = &tp->t_outq; 1855 pp = TP2PP(tp); 1856 1857 DPRINT((pp, DBG_ENTRY|DBG_START, 1858 "si_start(%x) t_state %x sp_state %x t_outq.c_cc %d\n", 1859 tp, tp->t_state, pp->sp_state, qp->c_cc)); 1860 1861 if (tp->t_state & (TS_TIMEOUT|TS_TTSTOP)) 1862 goto out; 1863 1864 buffer_full = 0; 1865 ccbp = pp->sp_ccb; 1866 1867 count = (int)ccbp->hi_txipos - (int)ccbp->hi_txopos; 1868 DPRINT((pp, DBG_START, "count %d\n", (BYTE)count)); 1869 1870 while ((nchar = qp->c_cc) > 0) { 1871 if ((BYTE)count >= 255) { 1872 buffer_full++; 1873 break; 1874 } 1875 amount = min(nchar, (255 - (BYTE)count)); 1876 ipos = (unsigned int)ccbp->hi_txipos; 1877 n = q_to_b(&tp->t_outq, si_txbuf, amount); 1878 /* will it fit in one lump? */ 1879 if ((SI_BUFFERSIZE - ipos) >= n) { 1880 si_bcopyv(si_txbuf, &ccbp->hi_txbuf[ipos], n); 1881 } else { 1882 si_bcopyv(si_txbuf, &ccbp->hi_txbuf[ipos], 1883 SI_BUFFERSIZE - ipos); 1884 si_bcopyv(si_txbuf + (SI_BUFFERSIZE - ipos), 1885 &ccbp->hi_txbuf[0], n - (SI_BUFFERSIZE - ipos)); 1886 } 1887 ccbp->hi_txipos += n; 1888 count = (int)ccbp->hi_txipos - (int)ccbp->hi_txopos; 1889 } 1890 1891 if (count != 0 && nchar == 0) { 1892 tp->t_state |= TS_BUSY; 1893 } else { 1894 tp->t_state &= ~TS_BUSY; 1895 } 1896 1897 /* wakeup time? */ 1898 ttwwakeup(tp); 1899 1900 DPRINT((pp, DBG_START, "count %d, nchar %d, tp->t_state 0x%x\n", 1901 (BYTE)count, nchar, tp->t_state)); 1902 1903 if (tp->t_state & TS_BUSY) 1904 { 1905 int time; 1906 1907 time = ttspeedtab(tp->t_ospeed, chartimes); 1908 1909 if (time > 0) { 1910 if (time < nchar) 1911 time = nchar / time; 1912 else 1913 time = 2; 1914 } else { 1915 DPRINT((pp, DBG_START, 1916 "bad char time value! %d\n", time)); 1917 time = hz/10; 1918 } 1919 1920 if ((pp->sp_state & (SS_LSTART|SS_INLSTART)) == SS_LSTART) { 1921 untimeout(si_lstart, (caddr_t)pp, pp->lstart_ch); 1922 } else { 1923 pp->sp_state |= SS_LSTART; 1924 } 1925 DPRINT((pp, DBG_START, "arming lstart, time=%d\n", time)); 1926 pp->lstart_ch = timeout(si_lstart, (caddr_t)pp, time); 1927 } 1928 1929out: 1930 splx(oldspl); 1931 DPRINT((pp, DBG_EXIT|DBG_START, "leave si_start()\n")); 1932} 1933 1934/* 1935 * Note: called at splsoftclock from the timeout code 1936 * This has to deal with two things... cause wakeups while waiting for 1937 * tty drains on last process exit, and call l_start at about the right 1938 * time for protocols like ppp. 1939 */ 1940static void 1941si_lstart(void *arg) 1942{ 1943 struct si_port *pp = arg; 1944 struct tty *tp; 1945 int oldspl; 1946 1947 DPRINT((pp, DBG_ENTRY|DBG_LSTART, "si_lstart(%x) sp_state %x\n", 1948 pp, pp->sp_state)); 1949 1950 oldspl = spltty(); 1951 1952 if ((pp->sp_state & SS_OPEN) == 0 || (pp->sp_state & SS_LSTART) == 0) { 1953 splx(oldspl); 1954 return; 1955 } 1956 pp->sp_state &= ~SS_LSTART; 1957 pp->sp_state |= SS_INLSTART; 1958 1959 tp = pp->sp_tty; 1960 1961 /* deal with the process exit case */ 1962 ttwwakeup(tp); 1963 1964 /* nudge protocols - eg: ppp */ 1965 ttyld_start(tp); 1966 1967 pp->sp_state &= ~SS_INLSTART; 1968 splx(oldspl); 1969} 1970 1971/* 1972 * Stop output on a line. called at spltty(); 1973 */ 1974static void 1975si_stop(struct tty *tp, int rw) 1976{ 1977 volatile struct si_channel *ccbp; 1978 struct si_port *pp; 1979 1980 pp = TP2PP(tp); 1981 ccbp = pp->sp_ccb; 1982 1983 DPRINT((TP2PP(tp), DBG_ENTRY|DBG_STOP, "si_stop(%x,%x)\n", tp, rw)); 1984 1985 /* XXX: must check (rw & FWRITE | FREAD) etc flushing... */ 1986 if (rw & FWRITE) { 1987 /* what level are we meant to be flushing anyway? */ 1988 if (tp->t_state & TS_BUSY) { 1989 si_command(TP2PP(tp), WFLUSH, SI_NOWAIT); 1990 tp->t_state &= ~TS_BUSY; 1991 ttwwakeup(tp); /* Bruce???? */ 1992 } 1993 } 1994#if 1 /* XXX: this doesn't work right yet.. */ 1995 /* XXX: this may have been failing because we used to call l_rint() 1996 * while we were looping based on these two counters. Now, we collect 1997 * the data and then loop stuffing it into l_rint(), making this 1998 * useless. Should we cause this to blow away the staging buffer? 1999 */ 2000 if (rw & FREAD) { 2001 ccbp->hi_rxopos = ccbp->hi_rxipos; 2002 } 2003#endif 2004} 2005 2006/* 2007 * Issue a command to the host card CPU. 2008 */ 2009 2010static void 2011si_command(struct si_port *pp, int cmd, int waitflag) 2012{ 2013 int oldspl; 2014 volatile struct si_channel *ccbp = pp->sp_ccb; 2015 int x; 2016 2017 DPRINT((pp, DBG_ENTRY|DBG_PARAM, "si_command(%x,%x,%d): hi_stat 0x%x\n", 2018 pp, cmd, waitflag, ccbp->hi_stat)); 2019 2020 oldspl = spltty(); /* Keep others out */ 2021 2022 /* wait until it's finished what it was doing.. */ 2023 /* XXX: sits in IDLE_BREAK until something disturbs it or break 2024 * is turned off. */ 2025 while((x = ccbp->hi_stat) != IDLE_OPEN && 2026 x != IDLE_CLOSE && 2027 x != IDLE_BREAK && 2028 x != cmd) { 2029 if (in_intr) { /* Prevent sleep in intr */ 2030 DPRINT((pp, DBG_PARAM, 2031 "cmd intr collision - completing %d\trequested %d\n", 2032 x, cmd)); 2033 splx(oldspl); 2034 return; 2035 } else if (ttysleep(pp->sp_tty, (caddr_t)&pp->sp_state, TTIPRI|PCATCH, 2036 "sicmd1", 1)) { 2037 splx(oldspl); 2038 return; 2039 } 2040 } 2041 /* it should now be in IDLE_{OPEN|CLOSE|BREAK}, or "cmd" */ 2042 2043 /* if there was a pending command, cause a state-change wakeup */ 2044 switch(pp->sp_pend) { 2045 case LOPEN: 2046 case MPEND: 2047 case MOPEN: 2048 case CONFIG: 2049 case SBREAK: 2050 case EBREAK: 2051 wakeup(&pp->sp_state); 2052 break; 2053 default: 2054 break; 2055 } 2056 2057 pp->sp_pend = cmd; /* New command pending */ 2058 ccbp->hi_stat = cmd; /* Post it */ 2059 2060 if (waitflag) { 2061 if (in_intr) { /* If in interrupt handler */ 2062 DPRINT((pp, DBG_PARAM, 2063 "attempt to sleep in si_intr - cmd req %d\n", 2064 cmd)); 2065 splx(oldspl); 2066 return; 2067 } else while(ccbp->hi_stat != IDLE_OPEN && 2068 ccbp->hi_stat != IDLE_BREAK) { 2069 if (ttysleep(pp->sp_tty, (caddr_t)&pp->sp_state, TTIPRI|PCATCH, 2070 "sicmd2", 0)) 2071 break; 2072 } 2073 } 2074 splx(oldspl); 2075} 2076 2077 2078#ifdef SI_DEBUG 2079 2080void 2081si_dprintf(struct si_port *pp, int flags, const char *fmt, ...) 2082{ 2083 va_list ap; 2084 2085 if ((pp == NULL && (si_debug&flags)) || 2086 (pp != NULL && ((pp->sp_debug&flags) || (si_debug&flags)))) { 2087 if (pp != NULL) 2088 printf("%ci%d(%d): ", 's', 2089 (int)SI_CARD(minor(pp->sp_tty->t_dev)), 2090 (int)SI_PORT(minor(pp->sp_tty->t_dev))); 2091 va_start(ap, fmt); 2092 vprintf(fmt, ap); 2093 va_end(ap); 2094 } 2095} 2096 2097static char * 2098si_mctl2str(enum si_mctl cmd) 2099{ 2100 switch (cmd) { 2101 case GET: 2102 return("GET"); 2103 case SET: 2104 return("SET"); 2105 case BIS: 2106 return("BIS"); 2107 case BIC: 2108 return("BIC"); 2109 } 2110 return("BAD"); 2111} 2112 2113#endif /* DEBUG */ 2114 2115static char * 2116si_modulename(int host_type, int uart_type) 2117{ 2118 switch (host_type) { 2119 /* Z280 based cards */ 2120 case SIEISA: 2121 case SIHOST2: 2122 case SIHOST: 2123 case SIPCI: 2124 switch (uart_type) { 2125 case 0: 2126 return(" (XIO)"); 2127 case 1: 2128 return(" (SI)"); 2129 } 2130 break; 2131 /* T225 based hosts */ 2132 case SIJETPCI: 2133 case SIJETISA: 2134 switch (uart_type) { 2135 case 0: 2136 return(" (SI)"); 2137 case 40: 2138 return(" (XIO)"); 2139 case 72: 2140 return(" (SXDC)"); 2141 } 2142 break; 2143 } 2144 return(""); 2145}
|