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