1 /*****************************************************************************/
4 * stallion.c -- stallion multiport serial driver.
6 * Copyright (c) 1995-1996 Greg Ungerer (gerg@stallion.oz.au).
9 * Redistribution and use in source and binary forms, with or without
10 * modification, are permitted provided that the following conditions
12 * 1. Redistributions of source code must retain the above copyright
13 * notice, this list of conditions and the following disclaimer.
14 * 2. Redistributions in binary form must reproduce the above copyright
15 * notice, this list of conditions and the following disclaimer in the
16 * documentation and/or other materials provided with the distribution.
17 * 3. All advertising materials mentioning features or use of this software
18 * must display the following acknowledgement:
19 * This product includes software developed by Greg Ungerer.
20 * 4. Neither the name of the author nor the names of any co-contributors
21 * may be used to endorse or promote products derived from this software
22 * without specific prior written permission.
24 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
25 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
26 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
27 * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
28 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
29 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
30 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
31 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
32 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
33 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
39 /*****************************************************************************/
43 #include "opt_compat.h"
45 #include <sys/param.h>
46 #include <sys/systm.h>
47 #include <sys/kernel.h>
48 #include <sys/malloc.h>
51 #include <sys/fcntl.h>
53 #include <i386/isa/isa_device.h>
54 #include <i386/isa/ic/scd1400.h>
55 #include <machine/comstats.h>
59 #warning "The stallion pci device is broken and not compiled with LINT"
65 #error "The stallion pci driver requires the old pci compatibility shims"
67 #include <pci/pcivar.h>
68 #include <pci/pcireg.h>
71 /*****************************************************************************/
74 * Define the version level of the kernel - so we can compile in the
75 * appropriate bits of code. By default this will compile for a 2.1
86 /*****************************************************************************/
89 * Define different board types. At the moment I have only declared
90 * those boards that this driver supports. But I will use the standard
91 * "assigned" board numbers. In the future this driver will support
92 * some of the other Stallion boards. Currently supported boards are
93 * abbreviated as EIO = EasyIO and ECH = EasyConnection 8/32.
101 * When using the BSD "config" stuff there is no easy way to specifiy
102 * a secondary IO address region. So it is hard wired here. Also the
103 * shared interrupt information is hard wired here...
105 static unsigned int stl_ioshared = 0x280;
106 static unsigned int stl_irqshared = 0;
108 /*****************************************************************************/
111 * Define important driver limitations.
113 #define STL_MAXBRDS 8
114 #define STL_MAXPANELS 4
115 #define STL_PORTSPERPANEL 16
116 #define STL_PORTSPERBRD 64
119 * Define the important minor number break down bits. These have been
120 * chosen to be "compatible" with the standard sio driver minor numbers.
121 * Extra high bits are used to distinguish between boards.
123 #define STL_CALLOUTDEV 0x80
124 #define STL_CTRLLOCK 0x40
125 #define STL_CTRLINIT 0x20
126 #define STL_CTRLDEV (STL_CTRLLOCK | STL_CTRLINIT)
128 #define STL_MEMDEV 0x07000000
130 #define STL_DEFSPEED TTYDEF_SPEED
131 #define STL_DEFCFLAG (CS8 | CREAD | HUPCL)
134 * I haven't really decided (or measured) what buffer sizes give
135 * a good balance between performance and memory usage. These seem
136 * to work pretty well...
138 #define STL_RXBUFSIZE 2048
139 #define STL_TXBUFSIZE 2048
141 #define STL_TXBUFLOW (STL_TXBUFSIZE / 4)
142 #define STL_RXBUFHIGH (3 * STL_RXBUFSIZE / 4)
144 /*****************************************************************************/
147 * Define our local driver identity first. Set up stuff to deal with
148 * all the local structures required by a serial tty driver.
150 static const char stl_drvname[] = "stl";
151 static const char stl_longdrvname[] = "Stallion Multiport Serial Driver";
152 static const char stl_drvversion[] = "1.0.0";
153 static int stl_brdprobed[STL_MAXBRDS];
155 static int stl_nrbrds = 0;
156 static int stl_doingtimeout = 0;
158 static const char __file__[] = /*__FILE__*/ "stallion.c";
161 * Define global stats structures. Not used often, and can be
162 * re-used for each stats call.
164 static combrd_t stl_brdstats;
165 static comstats_t stl_comstats;
167 /*****************************************************************************/
170 * Define a set of structures to hold all the board/panel/port info
171 * for our ports. These will be dynamically allocated as required.
175 * Define a ring queue structure for each port. This will hold the
176 * TX data waiting to be output. Characters are fed into this buffer
177 * from the line discipline (or even direct from user space!) and
178 * then fed into the UARTs during interrupts. Will use a clasic ring
179 * queue here for this. The good thing about this type of ring queue
180 * is that the head and tail pointers can be updated without interrupt
181 * protection - since "write" code only needs to change the head, and
182 * interrupt code only needs to change the tail.
192 * Port, panel and board structures to hold status info about each.
193 * The board structure contains pointers to structures for each panel
194 * connected to it, and in turn each panel structure contains pointers
195 * for each port structure for each port on that panel. Note that
196 * the port structure also contains the board and panel number that it
197 * is associated with, this makes it (fairly) easy to get back to the
198 * board/panel info for a port. Also note that the tty struct is at
199 * the top of the structure, this is important, since the code uses
200 * this fact to get the port struct pointer from the tty struct
220 unsigned int rxignoremsk;
221 unsigned int rxmarkmsk;
223 struct termios initintios;
224 struct termios initouttios;
225 struct termios lockintios;
226 struct termios lockouttios;
227 struct timeval timestamp;
241 unsigned int ackmask;
242 stlport_t *ports[STL_PORTSPERPANEL];
254 unsigned int ioaddr1;
255 unsigned int ioaddr2;
256 unsigned int iostatus;
258 unsigned int ioctrlval;
261 stlpanel_t *panels[STL_MAXPANELS];
262 stlport_t *ports[STL_PORTSPERBRD];
265 static stlbrd_t *stl_brds[STL_MAXBRDS];
268 * Per board state flags. Used with the state field of the board struct.
269 * Not really much here yet!
271 #define BRD_FOUND 0x1
274 * Define the port structure state flags. These set of flags are
275 * modified at interrupt time - so setting and reseting them needs
278 #define ASY_TXLOW 0x1
279 #define ASY_RXDATA 0x2
280 #define ASY_DCDCHANGE 0x4
281 #define ASY_DTRWAIT 0x8
282 #define ASY_RTSFLOW 0x10
283 #define ASY_RTSFLOWMODE 0x20
284 #define ASY_CTSFLOWMODE 0x40
286 #define ASY_ACTIVE (ASY_TXLOW | ASY_RXDATA | ASY_DCDCHANGE)
289 * Define an array of board names as printable strings. Handy for
290 * referencing boards when printing trace and stuff.
292 static char *stl_brdnames[] = {
322 /*****************************************************************************/
325 * Hardware ID bits for the EasyIO and ECH boards. These defines apply
326 * to the directly accessible io ports of these boards (not the cd1400
327 * uarts - they are in scd1400.h).
329 #define EIO_8PORTRS 0x04
330 #define EIO_4PORTRS 0x05
331 #define EIO_8PORTDI 0x00
332 #define EIO_8PORTM 0x06
333 #define EIO_IDBITMASK 0x07
334 #define EIO_INTRPEND 0x08
335 #define EIO_INTEDGE 0x00
336 #define EIO_INTLEVEL 0x08
339 #define ECH_IDBITMASK 0xe0
340 #define ECH_BRDENABLE 0x08
341 #define ECH_BRDDISABLE 0x00
342 #define ECH_INTENABLE 0x01
343 #define ECH_INTDISABLE 0x00
344 #define ECH_INTLEVEL 0x02
345 #define ECH_INTEDGE 0x00
346 #define ECH_INTRPEND 0x01
347 #define ECH_BRDRESET 0x01
349 #define ECHMC_INTENABLE 0x01
350 #define ECHMC_BRDRESET 0x02
352 #define ECH_PNLSTATUS 2
353 #define ECH_PNL16PORT 0x20
354 #define ECH_PNLIDMASK 0x07
355 #define ECH_PNLINTRPEND 0x80
356 #define ECH_ADDR2MASK 0x1e0
358 #define EIO_CLK 25000000
359 #define EIO_CLK8M 20000000
360 #define ECH_CLK EIO_CLK
363 * Define the offsets within the register bank for all io registers.
364 * These io address offsets are common to both the EIO and ECH.
372 #define EREG_BANKSIZE 8
375 * Define the PCI vendor and device id for ECH8/32-PCI.
377 #define STL_PCIDEVID 0xd001100b
380 * Define the vector mapping bits for the programmable interrupt board
381 * hardware. These bits encode the interrupt for the board to use - it
382 * is software selectable (except the EIO-8M).
384 static unsigned char stl_vecmap[] = {
385 0xff, 0xff, 0xff, 0x04, 0x06, 0x05, 0xff, 0x07,
386 0xff, 0xff, 0x00, 0x02, 0x01, 0xff, 0xff, 0x03
390 * Set up enable and disable macros for the ECH boards. They require
391 * the secondary io address space to be activated and deactivated.
392 * This way all ECH boards can share their secondary io region.
393 * If this is an ECH-PCI board then also need to set the page pointer
394 * to point to the correct page.
396 #define BRDENABLE(brdnr,pagenr) \
397 if (stl_brds[(brdnr)]->brdtype == BRD_ECH) \
398 outb(stl_brds[(brdnr)]->ioctrl, \
399 (stl_brds[(brdnr)]->ioctrlval | ECH_BRDENABLE));\
400 else if (stl_brds[(brdnr)]->brdtype == BRD_ECHPCI) \
401 outb(stl_brds[(brdnr)]->ioctrl, (pagenr));
403 #define BRDDISABLE(brdnr) \
404 if (stl_brds[(brdnr)]->brdtype == BRD_ECH) \
405 outb(stl_brds[(brdnr)]->ioctrl, \
406 (stl_brds[(brdnr)]->ioctrlval | ECH_BRDDISABLE));
409 * Define the cd1400 baud rate clocks. These are used when calculating
410 * what clock and divisor to use for the required baud rate. Also
411 * define the maximum baud rate allowed, and the default base baud.
413 static int stl_cd1400clkdivs[] = {
414 CD1400_CLK0, CD1400_CLK1, CD1400_CLK2, CD1400_CLK3, CD1400_CLK4
417 #define STL_MAXBAUD 230400
419 /*****************************************************************************/
422 * Define macros to extract a brd and port number from a minor number.
423 * This uses the extended minor number range in the upper 2 bytes of
424 * the device number. This gives us plenty of minor numbers to play
427 #define MKDEV2BRD(m) ((minor(m) & 0x00700000) >> 20)
428 #define MKDEV2PORT(m) ((minor(m) & 0x1f) | ((minor(m) & 0x00010000) >> 11))
431 * Define some handy local macros...
434 #define MIN(a,b) (((a) <= (b)) ? (a) : (b))
437 /*****************************************************************************/
440 * Declare all those functions in this driver! First up is the set of
441 * externally visible functions.
444 static int stlprobe(struct isa_device *idp);
445 static int stlattach(struct isa_device *idp);
447 STATIC d_open_t stlopen;
448 STATIC d_close_t stlclose;
449 STATIC d_ioctl_t stlioctl;
452 * Internal function prototypes.
454 static stlport_t *stl_dev2port(dev_t dev);
455 static int stl_findfreeunit(void);
456 static int stl_rawopen(stlport_t *portp);
457 static int stl_rawclose(stlport_t *portp);
458 static int stl_param(struct tty *tp, struct termios *tiosp);
459 static void stl_start(struct tty *tp);
460 static void stl_stop(struct tty *tp, int);
461 static void stl_ttyoptim(stlport_t *portp, struct termios *tiosp);
462 static void stl_dotimeout(void);
463 static void stl_poll(void *arg);
464 static void stl_rxprocess(stlport_t *portp);
465 static void stl_dtrwakeup(void *arg);
466 static int stl_brdinit(stlbrd_t *brdp);
467 static int stl_initeio(stlbrd_t *brdp);
468 static int stl_initech(stlbrd_t *brdp);
469 static int stl_initports(stlbrd_t *brdp, stlpanel_t *panelp);
470 static ointhand2_t stlintr;
471 static __inline void stl_txisr(stlpanel_t *panelp, int ioaddr);
472 static __inline void stl_rxisr(stlpanel_t *panelp, int ioaddr);
473 static __inline void stl_mdmisr(stlpanel_t *panelp, int ioaddr);
474 static void stl_setreg(stlport_t *portp, int regnr, int value);
475 static int stl_getreg(stlport_t *portp, int regnr);
476 static int stl_updatereg(stlport_t *portp, int regnr, int value);
477 static int stl_getsignals(stlport_t *portp);
478 static void stl_setsignals(stlport_t *portp, int dtr, int rts);
479 static void stl_flowcontrol(stlport_t *portp, int hw, int sw);
480 static void stl_ccrwait(stlport_t *portp);
481 static void stl_enablerxtx(stlport_t *portp, int rx, int tx);
482 static void stl_startrxtx(stlport_t *portp, int rx, int tx);
483 static void stl_disableintrs(stlport_t *portp);
484 static void stl_sendbreak(stlport_t *portp, long len);
485 static void stl_flush(stlport_t *portp, int flag);
486 static int stl_memioctl(dev_t dev, unsigned long cmd, caddr_t data,
487 int flag, struct proc *p);
488 static int stl_getbrdstats(caddr_t data);
489 static int stl_getportstats(stlport_t *portp, caddr_t data);
490 static int stl_clrportstats(stlport_t *portp, caddr_t data);
491 static stlport_t *stl_getport(int brdnr, int panelnr, int portnr);
494 static const char *stlpciprobe(pcici_t tag, pcidi_t type);
495 static void stlpciattach(pcici_t tag, int unit);
496 static void stlpciintr(void * arg);
499 /*****************************************************************************/
502 * Declare the driver isa structure.
504 struct isa_driver stldriver = {
510 COMPAT_ISA_DRIVER(stl, stldriver);
512 /*****************************************************************************/
517 * Declare the driver pci structure.
519 static unsigned long stl_count;
521 static struct pci_device stlpcidriver = {
529 COMPAT_PCI_DRIVER (stlpci, stlpcidriver);
533 /*****************************************************************************/
538 * FreeBSD-2.2+ kernel linkage.
541 #define CDEV_MAJOR 72
542 static struct cdevsw stl_cdevsw = {
544 /* close */ stlclose,
546 /* write */ ttywrite,
547 /* ioctl */ stlioctl,
550 /* strategy */ nostrategy,
552 /* maj */ CDEV_MAJOR,
559 static void stl_drvinit(void *unused)
562 cdevsw_add(&stl_cdevsw);
565 SYSINIT(sidev,SI_SUB_DRIVERS,SI_ORDER_MIDDLE+CDEV_MAJOR,stl_drvinit,NULL)
569 /*****************************************************************************/
572 * Probe for some type of EasyIO or EasyConnection 8/32 board at
573 * the supplied address. All we do is check if we can find the
574 * board ID for the board... (Note, PCI boards not checked here,
575 * they are done in the stlpciprobe() routine).
578 static int stlprobe(struct isa_device *idp)
583 printf("stlprobe(idp=%x): unit=%d iobase=%x\n", (int) idp,
584 idp->id_unit, idp->id_iobase);
587 if (idp->id_unit > STL_MAXBRDS)
590 status = inb(idp->id_iobase + 1);
591 if ((status & ECH_IDBITMASK) == ECH_ID) {
592 stl_brdprobed[idp->id_unit] = BRD_ECH;
596 status = inb(idp->id_iobase + 2);
597 switch (status & EIO_IDBITMASK) {
602 stl_brdprobed[idp->id_unit] = BRD_EASYIO;
611 /*****************************************************************************/
614 * Find an available internal board number (unit number). The problem
615 * is that the same unit numbers can be assigned to different boards
616 * detected during the ISA and PCI initialization phases.
619 static int stl_findfreeunit()
623 for (i = 0; (i < STL_MAXBRDS); i++)
624 if (stl_brds[i] == (stlbrd_t *) NULL)
626 return((i >= STL_MAXBRDS) ? -1 : i);
629 /*****************************************************************************/
632 * Allocate resources for and initialize the specified board.
635 static int stlattach(struct isa_device *idp)
640 printf("stlattach(idp=%p): unit=%d iobase=%x\n", (void *) idp,
641 idp->id_unit, idp->id_iobase);
644 idp->id_ointr = stlintr;
646 brdp = (stlbrd_t *) malloc(sizeof(stlbrd_t), M_TTYS, M_NOWAIT | M_ZERO);
647 if (brdp == (stlbrd_t *) NULL) {
648 printf("STALLION: failed to allocate memory (size=%d)\n",
653 if ((brdp->brdnr = stl_findfreeunit()) < 0) {
654 printf("STALLION: too many boards found, max=%d\n",
658 if (brdp->brdnr >= stl_nrbrds)
659 stl_nrbrds = brdp->brdnr + 1;
661 brdp->unitid = idp->id_unit;
662 brdp->brdtype = stl_brdprobed[idp->id_unit];
663 brdp->ioaddr1 = idp->id_iobase;
664 brdp->ioaddr2 = stl_ioshared;
665 brdp->irq = ffs(idp->id_irq) - 1;
666 brdp->irqtype = stl_irqshared;
672 /*****************************************************************************/
677 * Probe specifically for the PCI boards. We need to be a little
678 * carefull here, since it looks sort like a Nat Semi IDE chip...
681 static const char *stlpciprobe(pcici_t tag, pcidi_t type)
686 printf("stlpciprobe(tag=%x,type=%x)\n", (int) &tag, (int) type);
693 return((char *) NULL);
696 class = pci_conf_read(tag, PCI_CLASS_REG);
697 if ((class & PCI_CLASS_MASK) == PCI_CLASS_MASS_STORAGE)
698 return((char *) NULL);
700 return("Stallion EasyConnection 8/32-PCI");
703 /*****************************************************************************/
706 * Allocate resources for and initialize the specified PCI board.
709 void stlpciattach(pcici_t tag, int unit)
714 printf("stlpciattach(tag=%x,unit=%x)\n", (int) &tag, unit);
717 brdp = (stlbrd_t *) malloc(sizeof(stlbrd_t), M_TTYS, M_NOWAIT | M_ZERO);
718 if (brdp == (stlbrd_t *) NULL) {
719 printf("STALLION: failed to allocate memory (size=%d)\n",
724 if ((unit < 0) || (unit > STL_MAXBRDS)) {
725 printf("STALLION: bad PCI board unit number=%d\n", unit);
730 * Allocate us a new driver unique unit number.
732 if ((brdp->brdnr = stl_findfreeunit()) < 0) {
733 printf("STALLION: too many boards found, max=%d\n",
737 if (brdp->brdnr >= stl_nrbrds)
738 stl_nrbrds = brdp->brdnr + 1;
741 brdp->brdtype = BRD_ECHPCI;
742 brdp->ioaddr1 = ((unsigned int) pci_conf_read(tag, 0x14)) & 0xfffc;
743 brdp->ioaddr2 = ((unsigned int) pci_conf_read(tag, 0x10)) & 0xfffc;
744 brdp->irq = ((int) pci_conf_read(tag, 0x3c)) & 0xff;
746 if (pci_map_int(tag, stlpciintr, (void *) NULL, &tty_imask) == 0) {
747 printf("STALLION: failed to map interrupt irq=%d for unit=%d\n",
748 brdp->irq, brdp->brdnr);
753 printf("%s(%d): ECH-PCI iobase=%x iopage=%x irq=%d\n", __file__, __LINE__, brdp->ioaddr2, brdp->ioaddr1, brdp->irq);
760 /*****************************************************************************/
762 STATIC int stlopen(dev_t dev, int flag, int mode, struct proc *p)
766 int error, callout, x;
769 printf("stlopen(dev=%x,flag=%x,mode=%x,p=%x)\n", (int) dev, flag,
774 * Firstly check if the supplied device number is a valid device.
776 if (minor(dev) & STL_MEMDEV)
779 portp = stl_dev2port(dev);
780 if (portp == (stlport_t *) NULL)
784 callout = minor(dev) & STL_CALLOUTDEV;
791 * Wait here for the DTR drop timeout period to expire.
793 while (portp->state & ASY_DTRWAIT) {
794 error = tsleep(&portp->dtrwait, (TTIPRI | PCATCH),
801 * We have a valid device, so now we check if it is already open.
802 * If not then initialize the port hardware and set up the tty
803 * struct as required.
805 if ((tp->t_state & TS_ISOPEN) == 0) {
806 tp->t_oproc = stl_start;
807 tp->t_stop = stl_stop;
808 tp->t_param = stl_param;
810 tp->t_termios = callout ? portp->initouttios :
813 if ((portp->sigs & TIOCM_CD) || callout)
814 (*linesw[tp->t_line].l_modem)(tp, 1);
817 if (portp->callout == 0) {
822 if (portp->callout != 0) {
823 if (flag & O_NONBLOCK) {
827 error = tsleep(&portp->callout,
828 (TTIPRI | PCATCH), "stlcall", 0);
831 goto stlopen_restart;
834 if ((tp->t_state & TS_XCLUDE) &&
842 * If this port is not the callout device and we do not have carrier
843 * then we need to sleep, waiting for it to be asserted.
845 if (((tp->t_state & TS_CARR_ON) == 0) && !callout &&
846 ((tp->t_cflag & CLOCAL) == 0) &&
847 ((flag & O_NONBLOCK) == 0)) {
849 error = tsleep(TSA_CARR_ON(tp), (TTIPRI | PCATCH), "stldcd", 0);
853 goto stlopen_restart;
857 * Open the line discipline.
859 error = (*linesw[tp->t_line].l_open)(dev, tp);
860 stl_ttyoptim(portp, &tp->t_termios);
861 if ((tp->t_state & TS_ISOPEN) && callout)
865 * If for any reason we get to here and the port is not actually
866 * open then close of the physical hardware - no point leaving it
867 * active when the open failed...
871 if (((tp->t_state & TS_ISOPEN) == 0) && (portp->waitopens == 0))
877 /*****************************************************************************/
879 STATIC int stlclose(dev_t dev, int flag, int mode, struct proc *p)
886 printf("stlclose(dev=%s,flag=%x,mode=%x,p=%p)\n", devtoname(dev),
887 flag, mode, (void *) p);
890 if (minor(dev) & STL_MEMDEV)
893 portp = stl_dev2port(dev);
894 if (portp == (stlport_t *) NULL)
899 (*linesw[tp->t_line].l_close)(tp, flag);
900 stl_ttyoptim(portp, &tp->t_termios);
907 /*****************************************************************************/
911 STATIC void stl_stop(struct tty *tp, int rw)
914 printf("stl_stop(tp=%x,rw=%x)\n", (int) tp, rw);
917 stl_flush((stlport_t *) tp, rw);
922 STATIC int stlstop(struct tty *tp, int rw)
925 printf("stlstop(tp=%x,rw=%x)\n", (int) tp, rw);
928 stl_flush((stlport_t *) tp, rw);
934 /*****************************************************************************/
936 STATIC int stlioctl(dev_t dev, unsigned long cmd, caddr_t data, int flag,
939 struct termios *newtios, *localtios;
945 printf("stlioctl(dev=%s,cmd=%lx,data=%p,flag=%x,p=%p)\n",
946 devtoname(dev), cmd, (void *) data, flag, (void *) p);
949 if (minor(dev) & STL_MEMDEV)
950 return(stl_memioctl(dev, cmd, data, flag, p));
952 portp = stl_dev2port(dev);
953 if (portp == (stlport_t *) NULL)
959 * First up handle ioctls on the control devices.
961 if (minor(dev) & STL_CTRLDEV) {
962 if ((minor(dev) & STL_CTRLDEV) == STL_CTRLINIT)
963 localtios = (minor(dev) & STL_CALLOUTDEV) ?
964 &portp->initouttios : &portp->initintios;
965 else if ((minor(dev) & STL_CTRLDEV) == STL_CTRLLOCK)
966 localtios = (minor(dev) & STL_CALLOUTDEV) ?
967 &portp->lockouttios : &portp->lockintios;
973 if ((error = suser(p)) == 0)
974 *localtios = *((struct termios *) data);
977 *((struct termios *) data) = *localtios;
980 *((int *) data) = TTYDISC;
983 bzero(data, sizeof(struct winsize));
993 * Deal with 4.3 compatibility issues if we have too...
995 #if defined(COMPAT_43) || defined(COMPAT_SUNOS)
998 unsigned long oldcmd;
1000 tios = tp->t_termios;
1002 if ((error = ttsetcompat(tp, &cmd, data, &tios)))
1005 data = (caddr_t) &tios;
1010 * Carry out some pre-cmd processing work first...
1011 * Hmmm, not so sure we want this, disable for now...
1013 if ((cmd == TIOCSETA) || (cmd == TIOCSETAW) || (cmd == TIOCSETAF)) {
1014 newtios = (struct termios *) data;
1015 localtios = (minor(dev) & STL_CALLOUTDEV) ?
1016 &portp->lockouttios : &portp->lockintios;
1018 newtios->c_iflag = (tp->t_iflag & localtios->c_iflag) |
1019 (newtios->c_iflag & ~localtios->c_iflag);
1020 newtios->c_oflag = (tp->t_oflag & localtios->c_oflag) |
1021 (newtios->c_oflag & ~localtios->c_oflag);
1022 newtios->c_cflag = (tp->t_cflag & localtios->c_cflag) |
1023 (newtios->c_cflag & ~localtios->c_cflag);
1024 newtios->c_lflag = (tp->t_lflag & localtios->c_lflag) |
1025 (newtios->c_lflag & ~localtios->c_lflag);
1026 for (i = 0; (i < NCCS); i++) {
1027 if (localtios->c_cc[i] != 0)
1028 newtios->c_cc[i] = tp->t_cc[i];
1030 if (localtios->c_ispeed != 0)
1031 newtios->c_ispeed = tp->t_ispeed;
1032 if (localtios->c_ospeed != 0)
1033 newtios->c_ospeed = tp->t_ospeed;
1037 * Call the line discipline and the common command processing to
1038 * process this command (if they can).
1040 error = (*linesw[tp->t_line].l_ioctl)(tp, cmd, data, flag, p);
1041 if (error != ENOIOCTL)
1045 error = ttioctl(tp, cmd, data, flag);
1046 stl_ttyoptim(portp, &tp->t_termios);
1047 if (error != ENOIOCTL) {
1055 * Process local commands here. These are all commands that only we
1056 * can take care of (they all rely on actually doing something special
1057 * to the actual hardware).
1061 stl_sendbreak(portp, -1);
1064 stl_sendbreak(portp, -2);
1067 stl_setsignals(portp, 1, -1);
1070 stl_setsignals(portp, 0, -1);
1073 i = *((int *) data);
1074 stl_setsignals(portp, ((i & TIOCM_DTR) ? 1 : 0),
1075 ((i & TIOCM_RTS) ? 1 : 0));
1078 i = *((int *) data);
1079 stl_setsignals(portp, ((i & TIOCM_DTR) ? 1 : -1),
1080 ((i & TIOCM_RTS) ? 1 : -1));
1083 i = *((int *) data);
1084 stl_setsignals(portp, ((i & TIOCM_DTR) ? 0 : -1),
1085 ((i & TIOCM_RTS) ? 0 : -1));
1088 *((int *) data) = (stl_getsignals(portp) | TIOCM_LE);
1091 if ((error = suser(p)) == 0)
1092 portp->dtrwait = *((int *) data) * hz / 100;
1095 *((int *) data) = portp->dtrwait * 100 / hz;
1098 portp->dotimestamp = 1;
1099 *((struct timeval *) data) = portp->timestamp;
1110 /*****************************************************************************/
1113 * Convert the specified minor device number into a port struct
1114 * pointer. Return NULL if the device number is not a valid port.
1117 STATIC stlport_t *stl_dev2port(dev_t dev)
1121 brdp = stl_brds[MKDEV2BRD(dev)];
1122 if (brdp == (stlbrd_t *) NULL)
1123 return((stlport_t *) NULL);
1124 return(brdp->ports[MKDEV2PORT(dev)]);
1127 /*****************************************************************************/
1130 * Initialize the port hardware. This involves enabling the transmitter
1131 * and receiver, setting the port configuration, and setting the initial
1135 static int stl_rawopen(stlport_t *portp)
1138 printf("stl_rawopen(portp=%p): brdnr=%d panelnr=%d portnr=%d\n",
1139 (void *) portp, portp->brdnr, portp->panelnr, portp->portnr);
1141 stl_param(&portp->tty, &portp->tty.t_termios);
1142 portp->sigs = stl_getsignals(portp);
1143 stl_setsignals(portp, 1, 1);
1144 stl_enablerxtx(portp, 1, 1);
1145 stl_startrxtx(portp, 1, 0);
1149 /*****************************************************************************/
1152 * Shutdown the hardware of a port. Disable its transmitter and
1153 * receiver, and maybe drop signals if appropriate.
1156 static int stl_rawclose(stlport_t *portp)
1161 printf("stl_rawclose(portp=%p): brdnr=%d panelnr=%d portnr=%d\n",
1162 (void *) portp, portp->brdnr, portp->panelnr, portp->portnr);
1166 stl_disableintrs(portp);
1167 stl_enablerxtx(portp, 0, 0);
1168 stl_flush(portp, (FWRITE | FREAD));
1169 if (tp->t_cflag & HUPCL) {
1170 stl_setsignals(portp, 0, 0);
1171 if (portp->dtrwait != 0) {
1172 portp->state |= ASY_DTRWAIT;
1173 timeout(stl_dtrwakeup, portp, portp->dtrwait);
1178 portp->state &= ~(ASY_ACTIVE | ASY_RTSFLOW);
1179 wakeup(&portp->callout);
1180 wakeup(TSA_CARR_ON(tp));
1184 /*****************************************************************************/
1187 * Clear the DTR waiting flag, and wake up any sleepers waiting for
1188 * DTR wait period to finish.
1191 static void stl_dtrwakeup(void *arg)
1195 portp = (stlport_t *) arg;
1196 portp->state &= ~ASY_DTRWAIT;
1197 wakeup(&portp->dtrwait);
1200 /*****************************************************************************/
1203 * Start (or continue) the transfer of TX data on this port. If the
1204 * port is not currently busy then load up the interrupt ring queue
1205 * buffer and kick of the transmitter. If the port is running low on
1206 * TX data then refill the ring queue. This routine is also used to
1207 * activate input flow control!
1210 static void stl_start(struct tty *tp)
1213 unsigned int len, stlen;
1217 portp = (stlport_t *) tp;
1220 printf("stl_start(tp=%x): brdnr=%d portnr=%d\n", (int) tp,
1221 portp->brdnr, portp->portnr);
1227 * Check if the ports input has been blocked, and take appropriate action.
1228 * Not very often do we really need to do anything, so make it quick.
1230 if (tp->t_state & TS_TBLOCK) {
1231 if ((portp->state & ASY_RTSFLOW) == 0)
1232 stl_flowcontrol(portp, 0, -1);
1234 if (portp->state & ASY_RTSFLOW)
1235 stl_flowcontrol(portp, 1, -1);
1240 * Check if the output cooked clist buffers are near empty, wake up
1241 * the line discipline to fill it up.
1243 if (tp->t_outq.c_cc <= tp->t_lowat) {
1244 if (tp->t_state & TS_ASLEEP) {
1245 tp->t_state &= ~TS_ASLEEP;
1246 wakeup(&tp->t_outq);
1248 selwakeup(&tp->t_wsel);
1252 if (tp->t_state & (TS_TIMEOUT | TS_TTSTOP)) {
1258 * Copy data from the clists into the interrupt ring queue. This will
1259 * require at most 2 copys... What we do is calculate how many chars
1260 * can fit into the ring queue, and how many can fit in 1 copy. If after
1261 * the first copy there is still more room then do the second copy.
1262 * The beauty of this type of ring queue is that we do not need to
1263 * spl protect our-selves, since we only ever update the head pointer,
1264 * and the interrupt routine only ever updates the tail pointer.
1266 if (tp->t_outq.c_cc != 0) {
1267 head = portp->tx.head;
1268 tail = portp->tx.tail;
1270 len = STL_TXBUFSIZE - (head - tail) - 1;
1271 stlen = portp->tx.endbuf - head;
1273 len = tail - head - 1;
1278 stlen = MIN(len, stlen);
1279 count = q_to_b(&tp->t_outq, head, stlen);
1282 if (head >= portp->tx.endbuf) {
1283 head = portp->tx.buf;
1285 stlen = q_to_b(&tp->t_outq, head, len);
1290 portp->tx.head = head;
1292 stl_startrxtx(portp, -1, 1);
1296 * If we sent something, make sure we are called again.
1298 tp->t_state |= TS_BUSY;
1303 * Do any writer wakeups.
1311 /*****************************************************************************/
1313 static void stl_flush(stlport_t *portp, int flag)
1319 printf("stl_flush(portp=%x,flag=%x)\n", (int) portp, flag);
1322 if (portp == (stlport_t *) NULL)
1327 if (flag & FWRITE) {
1328 BRDENABLE(portp->brdnr, portp->pagenr);
1329 stl_setreg(portp, CAR, (portp->portnr & 0x03));
1331 stl_setreg(portp, CCR, CCR_TXFLUSHFIFO);
1333 portp->tx.tail = portp->tx.head;
1334 BRDDISABLE(portp->brdnr);
1338 * The only thing to watch out for when flushing the read side is
1339 * the RX status buffer. The interrupt code relys on the status
1340 * bytes as being zeroed all the time (it does not bother setting
1341 * a good char status to 0, it expects that it already will be).
1342 * We also need to un-flow the RX channel if flow control was
1346 head = portp->rx.head;
1347 tail = portp->rx.tail;
1352 len = portp->rx.endbuf - tail;
1353 bzero(portp->rxstatus.buf,
1354 (head - portp->rx.buf));
1356 bzero((tail + STL_RXBUFSIZE), len);
1357 portp->rx.tail = head;
1360 if ((portp->state & ASY_RTSFLOW) &&
1361 ((portp->tty.t_state & TS_TBLOCK) == 0))
1362 stl_flowcontrol(portp, 1, -1);
1368 /*****************************************************************************/
1371 * These functions get/set/update the registers of the cd1400 UARTs.
1372 * Access to the cd1400 registers is via an address/data io port pair.
1373 * (Maybe should make this inline...)
1376 static int stl_getreg(stlport_t *portp, int regnr)
1378 outb(portp->ioaddr, (regnr + portp->uartaddr));
1379 return(inb(portp->ioaddr + EREG_DATA));
1382 /*****************************************************************************/
1384 static void stl_setreg(stlport_t *portp, int regnr, int value)
1386 outb(portp->ioaddr, (regnr + portp->uartaddr));
1387 outb((portp->ioaddr + EREG_DATA), value);
1390 /*****************************************************************************/
1392 static int stl_updatereg(stlport_t *portp, int regnr, int value)
1394 outb(portp->ioaddr, (regnr + portp->uartaddr));
1395 if (inb(portp->ioaddr + EREG_DATA) != value) {
1396 outb((portp->ioaddr + EREG_DATA), value);
1402 /*****************************************************************************/
1405 * Wait for the command register to be ready. We will poll this, since
1406 * it won't usually take too long to be ready, and it is only really
1407 * used for non-critical actions.
1410 static void stl_ccrwait(stlport_t *portp)
1414 for (i = 0; (i < CCR_MAXWAIT); i++) {
1415 if (stl_getreg(portp, CCR) == 0) {
1420 printf("STALLION: cd1400 device not responding, brd=%d panel=%d"
1421 "port=%d\n", portp->brdnr, portp->panelnr, portp->portnr);
1424 /*****************************************************************************/
1427 * Transmit interrupt handler. This has gotta be fast! Handling TX
1428 * chars is pretty simple, stuff as many as possible from the TX buffer
1429 * into the cd1400 FIFO. Must also handle TX breaks here, since they
1430 * are embedded as commands in the data stream. Oh no, had to use a goto!
1431 * This could be optimized more, will do when I get time...
1432 * In practice it is possible that interrupts are enabled but that the
1433 * port has been hung up. Need to handle not having any TX buffer here,
1434 * this is done by using the side effect that head and tail will also
1435 * be NULL if the buffer has been freed.
1438 static __inline void stl_txisr(stlpanel_t *panelp, int ioaddr)
1443 unsigned char ioack, srer;
1446 printf("stl_txisr(panelp=%x,ioaddr=%x)\n", (int) panelp, ioaddr);
1449 ioack = inb(ioaddr + EREG_TXACK);
1450 if (((ioack & panelp->ackmask) != 0) ||
1451 ((ioack & ACK_TYPMASK) != ACK_TYPTX)) {
1452 printf("STALLION: bad TX interrupt ack value=%x\n", ioack);
1455 portp = panelp->ports[(ioack >> 3)];
1458 * Unfortunately we need to handle breaks in the data stream, since
1459 * this is the only way to generate them on the cd1400. Do it now if
1460 * a break is to be sent. Some special cases here: brklen is -1 then
1461 * start sending an un-timed break, if brklen is -2 then stop sending
1462 * an un-timed break, if brklen is -3 then we have just sent an
1463 * un-timed break and do not want any data to go out, if brklen is -4
1464 * then a break has just completed so clean up the port settings.
1466 if (portp->brklen != 0) {
1467 if (portp->brklen >= -1) {
1468 outb(ioaddr, (TDR + portp->uartaddr));
1469 outb((ioaddr + EREG_DATA), ETC_CMD);
1470 outb((ioaddr + EREG_DATA), ETC_STARTBREAK);
1471 if (portp->brklen > 0) {
1472 outb((ioaddr + EREG_DATA), ETC_CMD);
1473 outb((ioaddr + EREG_DATA), ETC_DELAY);
1474 outb((ioaddr + EREG_DATA), portp->brklen);
1475 outb((ioaddr + EREG_DATA), ETC_CMD);
1476 outb((ioaddr + EREG_DATA), ETC_STOPBREAK);
1481 } else if (portp->brklen == -2) {
1482 outb(ioaddr, (TDR + portp->uartaddr));
1483 outb((ioaddr + EREG_DATA), ETC_CMD);
1484 outb((ioaddr + EREG_DATA), ETC_STOPBREAK);
1486 } else if (portp->brklen == -3) {
1487 outb(ioaddr, (SRER + portp->uartaddr));
1488 srer = inb(ioaddr + EREG_DATA);
1489 srer &= ~(SRER_TXDATA | SRER_TXEMPTY);
1490 outb((ioaddr + EREG_DATA), srer);
1492 outb(ioaddr, (COR2 + portp->uartaddr));
1493 outb((ioaddr + EREG_DATA),
1494 (inb(ioaddr + EREG_DATA) & ~COR2_ETC));
1500 head = portp->tx.head;
1501 tail = portp->tx.tail;
1502 len = (head >= tail) ? (head - tail) : (STL_TXBUFSIZE - (tail - head));
1503 if ((len == 0) || ((len < STL_TXBUFLOW) &&
1504 ((portp->state & ASY_TXLOW) == 0))) {
1505 portp->state |= ASY_TXLOW;
1510 outb(ioaddr, (SRER + portp->uartaddr));
1511 srer = inb(ioaddr + EREG_DATA);
1512 if (srer & SRER_TXDATA) {
1513 srer = (srer & ~SRER_TXDATA) | SRER_TXEMPTY;
1515 srer &= ~(SRER_TXDATA | SRER_TXEMPTY);
1516 portp->tty.t_state &= ~TS_BUSY;
1518 outb((ioaddr + EREG_DATA), srer);
1520 len = MIN(len, CD1400_TXFIFOSIZE);
1521 portp->stats.txtotal += len;
1522 stlen = MIN(len, (portp->tx.endbuf - tail));
1523 outb(ioaddr, (TDR + portp->uartaddr));
1524 outsb((ioaddr + EREG_DATA), tail, stlen);
1527 if (tail >= portp->tx.endbuf)
1528 tail = portp->tx.buf;
1530 outsb((ioaddr + EREG_DATA), tail, len);
1533 portp->tx.tail = tail;
1537 outb(ioaddr, (EOSRR + portp->uartaddr));
1538 outb((ioaddr + EREG_DATA), 0);
1541 /*****************************************************************************/
1544 * Receive character interrupt handler. Determine if we have good chars
1545 * or bad chars and then process appropriately. Good chars are easy
1546 * just shove the lot into the RX buffer and set all status bytes to 0.
1547 * If a bad RX char then process as required. This routine needs to be
1551 static __inline void stl_rxisr(stlpanel_t *panelp, int ioaddr)
1555 unsigned int ioack, len, buflen, stlen;
1556 unsigned char status;
1559 static char unwanted[CD1400_RXFIFOSIZE];
1562 printf("stl_rxisr(panelp=%x,ioaddr=%x)\n", (int) panelp, ioaddr);
1565 ioack = inb(ioaddr + EREG_RXACK);
1566 if ((ioack & panelp->ackmask) != 0) {
1567 printf("STALLION: bad RX interrupt ack value=%x\n", ioack);
1570 portp = panelp->ports[(ioack >> 3)];
1574 * First up, caluclate how much room there is in the RX ring queue.
1575 * We also want to keep track of the longest possible copy length,
1576 * this has to allow for the wrapping of the ring queue.
1578 head = portp->rx.head;
1579 tail = portp->rx.tail;
1581 buflen = STL_RXBUFSIZE - (head - tail) - 1;
1582 stlen = portp->rx.endbuf - head;
1584 buflen = tail - head - 1;
1589 * Check if the input buffer is near full. If so then we should take
1590 * some flow control action... It is very easy to do hardware and
1591 * software flow control from here since we have the port selected on
1594 if (buflen <= (STL_RXBUFSIZE - STL_RXBUFHIGH)) {
1595 if (((portp->state & ASY_RTSFLOW) == 0) &&
1596 (portp->state & ASY_RTSFLOWMODE)) {
1597 portp->state |= ASY_RTSFLOW;
1598 stl_setreg(portp, MCOR1,
1599 (stl_getreg(portp, MCOR1) & 0xf0));
1600 stl_setreg(portp, MSVR2, 0);
1601 portp->stats.rxrtsoff++;
1606 * OK we are set, process good data... If the RX ring queue is full
1607 * just chuck the chars - don't leave them in the UART.
1609 if ((ioack & ACK_TYPMASK) == ACK_TYPRXGOOD) {
1610 outb(ioaddr, (RDCR + portp->uartaddr));
1611 len = inb(ioaddr + EREG_DATA);
1613 outb(ioaddr, (RDSR + portp->uartaddr));
1614 insb((ioaddr + EREG_DATA), &unwanted[0], len);
1615 portp->stats.rxlost += len;
1616 portp->stats.rxtotal += len;
1618 len = MIN(len, buflen);
1619 portp->stats.rxtotal += len;
1620 stlen = MIN(len, stlen);
1622 outb(ioaddr, (RDSR + portp->uartaddr));
1623 insb((ioaddr + EREG_DATA), head, stlen);
1625 if (head >= portp->rx.endbuf) {
1626 head = portp->rx.buf;
1628 insb((ioaddr + EREG_DATA), head, len);
1633 } else if ((ioack & ACK_TYPMASK) == ACK_TYPRXBAD) {
1634 outb(ioaddr, (RDSR + portp->uartaddr));
1635 status = inb(ioaddr + EREG_DATA);
1636 ch = inb(ioaddr + EREG_DATA);
1637 if (status & ST_BREAK)
1638 portp->stats.rxbreaks++;
1639 if (status & ST_FRAMING)
1640 portp->stats.rxframing++;
1641 if (status & ST_PARITY)
1642 portp->stats.rxparity++;
1643 if (status & ST_OVERRUN)
1644 portp->stats.rxoverrun++;
1645 if (status & ST_SCHARMASK) {
1646 if ((status & ST_SCHARMASK) == ST_SCHAR1)
1647 portp->stats.txxon++;
1648 if ((status & ST_SCHARMASK) == ST_SCHAR2)
1649 portp->stats.txxoff++;
1652 if ((portp->rxignoremsk & status) == 0) {
1653 if ((tp->t_state & TS_CAN_BYPASS_L_RINT) &&
1654 ((status & ST_FRAMING) ||
1655 ((status & ST_PARITY) && (tp->t_iflag & INPCK))))
1657 if ((portp->rxmarkmsk & status) == 0)
1659 *(head + STL_RXBUFSIZE) = status;
1661 if (head >= portp->rx.endbuf)
1662 head = portp->rx.buf;
1665 printf("STALLION: bad RX interrupt ack value=%x\n", ioack);
1669 portp->rx.head = head;
1670 portp->state |= ASY_RXDATA;
1674 outb(ioaddr, (EOSRR + portp->uartaddr));
1675 outb((ioaddr + EREG_DATA), 0);
1678 /*****************************************************************************/
1681 * Modem interrupt handler. The is called when the modem signal line
1682 * (DCD) has changed state. Leave most of the work to the off-level
1683 * processing routine.
1686 static __inline void stl_mdmisr(stlpanel_t *panelp, int ioaddr)
1693 printf("stl_mdmisr(panelp=%x,ioaddr=%x)\n", (int) panelp, ioaddr);
1696 ioack = inb(ioaddr + EREG_MDACK);
1697 if (((ioack & panelp->ackmask) != 0) ||
1698 ((ioack & ACK_TYPMASK) != ACK_TYPMDM)) {
1699 printf("STALLION: bad MODEM interrupt ack value=%x\n", ioack);
1702 portp = panelp->ports[(ioack >> 3)];
1704 outb(ioaddr, (MISR + portp->uartaddr));
1705 misr = inb(ioaddr + EREG_DATA);
1706 if (misr & MISR_DCD) {
1707 portp->state |= ASY_DCDCHANGE;
1708 portp->stats.modem++;
1712 outb(ioaddr, (EOSRR + portp->uartaddr));
1713 outb((ioaddr + EREG_DATA), 0);
1716 /*****************************************************************************/
1719 * Interrupt handler for EIO and ECH boards. This code ain't all that
1720 * pretty, but the idea is to make it as fast as possible. This code is
1721 * well suited to be assemblerized :-) We don't use the general purpose
1722 * register access functions here, for speed we will go strait to the
1726 static void stlintr(int unit)
1730 unsigned char svrtype;
1731 int i, panelnr, iobase;
1735 printf("stlintr(unit=%d)\n", unit);
1739 panelp = (stlpanel_t *) NULL;
1740 for (i = 0; (i < stl_nrbrds); ) {
1741 if ((brdp = stl_brds[i]) == (stlbrd_t *) NULL) {
1745 if (brdp->state == 0) {
1750 * The following section of code handles the subtle differences
1751 * between board types. It is sort of similar, but different
1752 * enough to handle each separately.
1754 if (brdp->brdtype == BRD_EASYIO) {
1755 if ((inb(brdp->iostatus) & EIO_INTRPEND) == 0) {
1759 panelp = brdp->panels[0];
1760 iobase = panelp->iobase;
1762 svrtype = inb(iobase + EREG_DATA);
1763 if (brdp->nrports > 4) {
1764 outb(iobase, (SVRR + 0x80));
1765 svrtype |= inb(iobase + EREG_DATA);
1767 } else if (brdp->brdtype == BRD_ECH) {
1768 if ((inb(brdp->iostatus) & ECH_INTRPEND) == 0) {
1772 outb(brdp->ioctrl, (brdp->ioctrlval | ECH_BRDENABLE));
1773 for (panelnr = 0; (panelnr < brdp->nrpanels); panelnr++) {
1774 panelp = brdp->panels[panelnr];
1775 iobase = panelp->iobase;
1776 if (inb(iobase + ECH_PNLSTATUS) & ECH_PNLINTRPEND)
1778 if (panelp->nrports > 8) {
1780 if (inb(iobase + ECH_PNLSTATUS) & ECH_PNLINTRPEND)
1784 if (panelnr >= brdp->nrpanels) {
1789 svrtype = inb(iobase + EREG_DATA);
1790 outb(iobase, (SVRR + 0x80));
1791 svrtype |= inb(iobase + EREG_DATA);
1792 } else if (brdp->brdtype == BRD_ECHPCI) {
1793 iobase = brdp->ioaddr2;
1794 for (panelnr = 0; (panelnr < brdp->nrpanels); panelnr++) {
1795 panelp = brdp->panels[panelnr];
1796 outb(brdp->ioctrl, panelp->pagenr);
1797 if (inb(iobase + ECH_PNLSTATUS) & ECH_PNLINTRPEND)
1799 if (panelp->nrports > 8) {
1800 outb(brdp->ioctrl, (panelp->pagenr + 1));
1801 if (inb(iobase + ECH_PNLSTATUS) & ECH_PNLINTRPEND)
1805 if (panelnr >= brdp->nrpanels) {
1810 svrtype = inb(iobase + EREG_DATA);
1811 outb(iobase, (SVRR + 0x80));
1812 svrtype |= inb(iobase + EREG_DATA);
1813 } else if (brdp->brdtype == BRD_ECHMC) {
1814 if ((inb(brdp->iostatus) & ECH_INTRPEND) == 0) {
1818 for (panelnr = 0; (panelnr < brdp->nrpanels); panelnr++) {
1819 panelp = brdp->panels[panelnr];
1820 iobase = panelp->iobase;
1821 if (inb(iobase + ECH_PNLSTATUS) & ECH_PNLINTRPEND)
1823 if (panelp->nrports > 8) {
1825 if (inb(iobase + ECH_PNLSTATUS) & ECH_PNLINTRPEND)
1829 if (panelnr >= brdp->nrpanels) {
1834 svrtype = inb(iobase + EREG_DATA);
1835 outb(iobase, (SVRR + 0x80));
1836 svrtype |= inb(iobase + EREG_DATA);
1838 printf("STALLION: unknown board type=%x\n", brdp->brdtype);
1844 * We have determined what type of service is required for a
1845 * port. From here on in the service of a port is the same no
1846 * matter what the board type...
1848 if (svrtype & SVRR_RX)
1849 stl_rxisr(panelp, iobase);
1850 if (svrtype & SVRR_TX)
1851 stl_txisr(panelp, iobase);
1852 if (svrtype & SVRR_MDM)
1853 stl_mdmisr(panelp, iobase);
1855 if (brdp->brdtype == BRD_ECH)
1856 outb(brdp->ioctrl, (brdp->ioctrlval | ECH_BRDDISABLE));
1860 /*****************************************************************************/
1864 static void stlpciintr(void *arg)
1871 /*****************************************************************************/
1874 * If we haven't scheduled a timeout then do it, some port needs high
1878 static void stl_dotimeout()
1881 printf("stl_dotimeout()\n");
1884 if (stl_doingtimeout == 0) {
1885 timeout(stl_poll, 0, 1);
1890 /*****************************************************************************/
1893 * Service "software" level processing. Too slow or painfull to be done
1894 * at real hardware interrupt time. This way we might also be able to
1895 * do some service on other waiting ports as well...
1898 static void stl_poll(void *arg)
1903 int brdnr, portnr, rearm, x;
1906 printf("stl_poll()\n");
1909 stl_doingtimeout = 0;
1913 for (brdnr = 0; (brdnr < stl_nrbrds); brdnr++) {
1914 if ((brdp = stl_brds[brdnr]) == (stlbrd_t *) NULL)
1916 for (portnr = 0; (portnr < brdp->nrports); portnr++) {
1917 if ((portp = brdp->ports[portnr]) == (stlport_t *) NULL)
1919 if ((portp->state & ASY_ACTIVE) == 0)
1923 if (portp->state & ASY_RXDATA)
1924 stl_rxprocess(portp);
1925 if (portp->state & ASY_DCDCHANGE) {
1926 portp->state &= ~ASY_DCDCHANGE;
1927 portp->sigs = stl_getsignals(portp);
1928 (*linesw[tp->t_line].l_modem)(tp,
1929 (portp->sigs & TIOCM_CD));
1931 if (portp->state & ASY_TXLOW) {
1932 portp->state &= ~ASY_TXLOW;
1933 (*linesw[tp->t_line].l_start)(tp);
1936 if (portp->state & ASY_ACTIVE)
1946 /*****************************************************************************/
1949 * Process the RX data that has been buffered up in the RX ring queue.
1952 static void stl_rxprocess(stlport_t *portp)
1955 unsigned int len, stlen, lostlen;
1961 printf("stl_rxprocess(portp=%x): brdnr=%d portnr=%d\n", (int) portp,
1962 portp->brdnr, portp->portnr);
1966 portp->state &= ~ASY_RXDATA;
1968 if ((tp->t_state & TS_ISOPEN) == 0) {
1969 stl_flush(portp, FREAD);
1974 * Calculate the amount of data in the RX ring queue. Also calculate
1975 * the largest single copy size...
1977 head = portp->rx.head;
1978 tail = portp->rx.tail;
1983 len = STL_RXBUFSIZE - (tail - head);
1984 stlen = portp->rx.endbuf - tail;
1987 if (tp->t_state & TS_CAN_BYPASS_L_RINT) {
1989 if (((tp->t_rawq.c_cc + len) >= TTYHOG) &&
1990 ((portp->state & ASY_RTSFLOWMODE) ||
1991 (tp->t_iflag & IXOFF)) &&
1992 ((tp->t_state & TS_TBLOCK) == 0)) {
1993 ch = TTYHOG - tp->t_rawq.c_cc - 1;
1994 len = (ch > 0) ? ch : 0;
1995 stlen = MIN(stlen, len);
1998 lostlen = b_to_q(tail, stlen, &tp->t_rawq);
2001 if (tail >= portp->rx.endbuf) {
2002 tail = portp->rx.buf;
2003 lostlen += b_to_q(tail, len, &tp->t_rawq);
2006 portp->stats.rxlost += lostlen;
2008 portp->rx.tail = tail;
2011 while (portp->rx.tail != head) {
2012 ch = (unsigned char) *(portp->rx.tail);
2013 status = *(portp->rx.tail + STL_RXBUFSIZE);
2015 *(portp->rx.tail + STL_RXBUFSIZE) = 0;
2016 if (status & ST_BREAK)
2018 if (status & ST_FRAMING)
2020 if (status & ST_PARITY)
2022 if (status & ST_OVERRUN)
2025 (*linesw[tp->t_line].l_rint)(ch, tp);
2026 if (portp->rx.tail == head)
2029 if (++(portp->rx.tail) >= portp->rx.endbuf)
2030 portp->rx.tail = portp->rx.buf;
2034 if (head != portp->rx.tail)
2035 portp->state |= ASY_RXDATA;
2038 * If we where flow controled then maybe the buffer is low enough that
2039 * we can re-activate it.
2041 if ((portp->state & ASY_RTSFLOW) && ((tp->t_state & TS_TBLOCK) == 0))
2042 stl_flowcontrol(portp, 1, -1);
2045 /*****************************************************************************/
2048 * Set up the cd1400 registers for a port based on the termios port
2052 static int stl_param(struct tty *tp, struct termios *tiosp)
2055 unsigned int clkdiv;
2056 unsigned char cor1, cor2, cor3;
2057 unsigned char cor4, cor5, ccr;
2058 unsigned char srer, sreron, sreroff;
2059 unsigned char mcor1, mcor2, rtpr;
2060 unsigned char clk, div;
2063 portp = (stlport_t *) tp;
2066 printf("stl_param(tp=%x,tiosp=%x): brdnr=%d portnr=%d\n", (int) tp,
2067 (int) tiosp, portp->brdnr, portp->portnr);
2085 * Set up the RX char ignore mask with those RX error types we
2086 * can ignore. We could have used some special modes of the cd1400
2087 * UART to help, but it is better this way because we can keep stats
2088 * on the number of each type of RX exception event.
2090 portp->rxignoremsk = 0;
2091 if (tiosp->c_iflag & IGNPAR)
2092 portp->rxignoremsk |= (ST_PARITY | ST_FRAMING | ST_OVERRUN);
2093 if (tiosp->c_iflag & IGNBRK)
2094 portp->rxignoremsk |= ST_BREAK;
2096 portp->rxmarkmsk = ST_OVERRUN;
2097 if (tiosp->c_iflag & (INPCK | PARMRK))
2098 portp->rxmarkmsk |= (ST_PARITY | ST_FRAMING);
2099 if (tiosp->c_iflag & BRKINT)
2100 portp->rxmarkmsk |= ST_BREAK;
2103 * Go through the char size, parity and stop bits and set all the
2104 * option registers appropriately.
2106 switch (tiosp->c_cflag & CSIZE) {
2121 if (tiosp->c_cflag & CSTOPB)
2126 if (tiosp->c_cflag & PARENB) {
2127 if (tiosp->c_cflag & PARODD)
2128 cor1 |= (COR1_PARENB | COR1_PARODD);
2130 cor1 |= (COR1_PARENB | COR1_PAREVEN);
2132 cor1 |= COR1_PARNONE;
2135 if (tiosp->c_iflag & ISTRIP)
2136 cor5 |= COR5_ISTRIP;
2139 * Set the RX FIFO threshold at 6 chars. This gives a bit of breathing
2140 * space for hardware flow control and the like. This should be set to
2141 * VMIN. Also here we will set the RX data timeout to 10ms - this should
2142 * really be based on VTIME...
2144 cor3 |= FIFO_RXTHRESHOLD;
2148 * Calculate the baud rate timers. For now we will just assume that
2149 * the input and output baud are the same. Could have used a baud
2150 * table here, but this way we can generate virtually any baud rate
2153 if (tiosp->c_ispeed == 0)
2154 tiosp->c_ispeed = tiosp->c_ospeed;
2155 if ((tiosp->c_ospeed < 0) || (tiosp->c_ospeed > STL_MAXBAUD))
2158 if (tiosp->c_ospeed > 0) {
2159 for (clk = 0; (clk < CD1400_NUMCLKS); clk++) {
2160 clkdiv = ((portp->clk / stl_cd1400clkdivs[clk]) /
2165 div = (unsigned char) clkdiv;
2169 * Check what form of modem signaling is required and set it up.
2171 if ((tiosp->c_cflag & CLOCAL) == 0) {
2174 sreron |= SRER_MODEM;
2178 * Setup cd1400 enhanced modes if we can. In particular we want to
2179 * handle as much of the flow control as possbile automatically. As
2180 * well as saving a few CPU cycles it will also greatly improve flow
2181 * control reliablilty.
2183 if (tiosp->c_iflag & IXON) {
2186 if (tiosp->c_iflag & IXANY)
2190 if (tiosp->c_cflag & CCTS_OFLOW)
2192 if (tiosp->c_cflag & CRTS_IFLOW)
2193 mcor1 |= FIFO_RTSTHRESHOLD;
2196 * All cd1400 register values calculated so go through and set them
2200 printf("SETPORT: portnr=%d panelnr=%d brdnr=%d\n", portp->portnr,
2201 portp->panelnr, portp->brdnr);
2202 printf(" cor1=%x cor2=%x cor3=%x cor4=%x cor5=%x\n", cor1, cor2,
2204 printf(" mcor1=%x mcor2=%x rtpr=%x sreron=%x sreroff=%x\n",
2205 mcor1, mcor2, rtpr, sreron, sreroff);
2206 printf(" tcor=%x tbpr=%x rcor=%x rbpr=%x\n", clk, div, clk, div);
2207 printf(" schr1=%x schr2=%x schr3=%x schr4=%x\n",
2208 tiosp->c_cc[VSTART], tiosp->c_cc[VSTOP], tiosp->c_cc[VSTART],
2209 tiosp->c_cc[VSTOP]);
2213 BRDENABLE(portp->brdnr, portp->pagenr);
2214 stl_setreg(portp, CAR, (portp->portnr & 0x3));
2215 srer = stl_getreg(portp, SRER);
2216 stl_setreg(portp, SRER, 0);
2217 ccr += stl_updatereg(portp, COR1, cor1);
2218 ccr += stl_updatereg(portp, COR2, cor2);
2219 ccr += stl_updatereg(portp, COR3, cor3);
2222 stl_setreg(portp, CCR, CCR_CORCHANGE);
2224 stl_setreg(portp, COR4, cor4);
2225 stl_setreg(portp, COR5, cor5);
2226 stl_setreg(portp, MCOR1, mcor1);
2227 stl_setreg(portp, MCOR2, mcor2);
2228 if (tiosp->c_ospeed == 0) {
2229 stl_setreg(portp, MSVR1, 0);
2231 stl_setreg(portp, MSVR1, MSVR1_DTR);
2232 stl_setreg(portp, TCOR, clk);
2233 stl_setreg(portp, TBPR, div);
2234 stl_setreg(portp, RCOR, clk);
2235 stl_setreg(portp, RBPR, div);
2237 stl_setreg(portp, SCHR1, tiosp->c_cc[VSTART]);
2238 stl_setreg(portp, SCHR2, tiosp->c_cc[VSTOP]);
2239 stl_setreg(portp, SCHR3, tiosp->c_cc[VSTART]);
2240 stl_setreg(portp, SCHR4, tiosp->c_cc[VSTOP]);
2241 stl_setreg(portp, RTPR, rtpr);
2242 mcor1 = stl_getreg(portp, MSVR1);
2243 if (mcor1 & MSVR1_DCD)
2244 portp->sigs |= TIOCM_CD;
2246 portp->sigs &= ~TIOCM_CD;
2247 stl_setreg(portp, SRER, ((srer & ~sreroff) | sreron));
2248 BRDDISABLE(portp->brdnr);
2249 portp->state &= ~(ASY_RTSFLOWMODE | ASY_CTSFLOWMODE);
2250 portp->state |= ((tiosp->c_cflag & CRTS_IFLOW) ? ASY_RTSFLOWMODE : 0);
2251 portp->state |= ((tiosp->c_cflag & CCTS_OFLOW) ? ASY_CTSFLOWMODE : 0);
2252 stl_ttyoptim(portp, tiosp);
2258 /*****************************************************************************/
2261 * Action the flow control as required. The hw and sw args inform the
2262 * routine what flow control methods it should try.
2265 static void stl_flowcontrol(stlport_t *portp, int hw, int sw)
2267 unsigned char *head, *tail;
2271 printf("stl_flowcontrol(portp=%x,hw=%d,sw=%d)\n", (int) portp, hw, sw);
2276 if (portp->state & ASY_RTSFLOWMODE) {
2278 if ((portp->state & ASY_RTSFLOW) == 0)
2280 } else if (hw > 0) {
2281 if (portp->state & ASY_RTSFLOW) {
2282 head = portp->rx.head;
2283 tail = portp->rx.tail;
2284 len = (head >= tail) ? (head - tail) :
2285 (STL_RXBUFSIZE - (tail - head));
2286 if (len < STL_RXBUFHIGH)
2293 * We have worked out what to do, if anything. So now apply it to the
2298 BRDENABLE(portp->brdnr, portp->pagenr);
2299 stl_setreg(portp, CAR, (portp->portnr & 0x03));
2301 portp->state |= ASY_RTSFLOW;
2302 stl_setreg(portp, MCOR1,
2303 (stl_getreg(portp, MCOR1) & 0xf0));
2304 stl_setreg(portp, MSVR2, 0);
2305 portp->stats.rxrtsoff++;
2306 } else if (hwflow > 0) {
2307 portp->state &= ~ASY_RTSFLOW;
2308 stl_setreg(portp, MSVR2, MSVR2_RTS);
2309 stl_setreg(portp, MCOR1,
2310 (stl_getreg(portp, MCOR1) | FIFO_RTSTHRESHOLD));
2311 portp->stats.rxrtson++;
2313 BRDDISABLE(portp->brdnr);
2319 /*****************************************************************************/
2322 * Set the state of the DTR and RTS signals.
2325 static void stl_setsignals(stlport_t *portp, int dtr, int rts)
2327 unsigned char msvr1, msvr2;
2331 printf("stl_setsignals(portp=%x,dtr=%d,rts=%d)\n", (int) portp,
2343 BRDENABLE(portp->brdnr, portp->pagenr);
2344 stl_setreg(portp, CAR, (portp->portnr & 0x03));
2346 stl_setreg(portp, MSVR2, msvr2);
2348 stl_setreg(portp, MSVR1, msvr1);
2349 BRDDISABLE(portp->brdnr);
2353 /*****************************************************************************/
2356 * Get the state of the signals.
2359 static int stl_getsignals(stlport_t *portp)
2361 unsigned char msvr1, msvr2;
2365 printf("stl_getsignals(portp=%x)\n", (int) portp);
2369 BRDENABLE(portp->brdnr, portp->pagenr);
2370 stl_setreg(portp, CAR, (portp->portnr & 0x3));
2371 msvr1 = stl_getreg(portp, MSVR1);
2372 msvr2 = stl_getreg(portp, MSVR2);
2373 BRDDISABLE(portp->brdnr);
2377 sigs |= (msvr1 & MSVR1_DCD) ? TIOCM_CD : 0;
2378 sigs |= (msvr1 & MSVR1_CTS) ? TIOCM_CTS : 0;
2379 sigs |= (msvr1 & MSVR1_RI) ? TIOCM_RI : 0;
2380 sigs |= (msvr1 & MSVR1_DSR) ? TIOCM_DSR : 0;
2381 sigs |= (msvr1 & MSVR1_DTR) ? TIOCM_DTR : 0;
2382 sigs |= (msvr2 & MSVR2_RTS) ? TIOCM_RTS : 0;
2386 /*****************************************************************************/
2389 * Enable or disable the Transmitter and/or Receiver.
2392 static void stl_enablerxtx(stlport_t *portp, int rx, int tx)
2398 printf("stl_enablerxtx(portp=%x,rx=%d,tx=%d)\n", (int) portp, rx, tx);
2403 ccr |= CCR_TXDISABLE;
2405 ccr |= CCR_TXENABLE;
2407 ccr |= CCR_RXDISABLE;
2409 ccr |= CCR_RXENABLE;
2412 BRDENABLE(portp->brdnr, portp->pagenr);
2413 stl_setreg(portp, CAR, (portp->portnr & 0x03));
2415 stl_setreg(portp, CCR, ccr);
2417 BRDDISABLE(portp->brdnr);
2421 /*****************************************************************************/
2424 * Start or stop the Transmitter and/or Receiver.
2427 static void stl_startrxtx(stlport_t *portp, int rx, int tx)
2429 unsigned char sreron, sreroff;
2433 printf("stl_startrxtx(portp=%x,rx=%d,tx=%d)\n", (int) portp, rx, tx);
2439 sreroff |= (SRER_TXDATA | SRER_TXEMPTY);
2441 sreron |= SRER_TXDATA;
2443 sreron |= SRER_TXEMPTY;
2445 sreroff |= SRER_RXDATA;
2447 sreron |= SRER_RXDATA;
2450 BRDENABLE(portp->brdnr, portp->pagenr);
2451 stl_setreg(portp, CAR, (portp->portnr & 0x3));
2452 stl_setreg(portp, SRER,
2453 ((stl_getreg(portp, SRER) & ~sreroff) | sreron));
2454 BRDDISABLE(portp->brdnr);
2456 portp->tty.t_state |= TS_BUSY;
2460 /*****************************************************************************/
2463 * Disable all interrupts from this port.
2466 static void stl_disableintrs(stlport_t *portp)
2471 printf("stl_disableintrs(portp=%x)\n", (int) portp);
2475 BRDENABLE(portp->brdnr, portp->pagenr);
2476 stl_setreg(portp, CAR, (portp->portnr & 0x3));
2477 stl_setreg(portp, SRER, 0);
2478 BRDDISABLE(portp->brdnr);
2482 /*****************************************************************************/
2484 static void stl_sendbreak(stlport_t *portp, long len)
2489 printf("stl_sendbreak(portp=%x,len=%d)\n", (int) portp, (int) len);
2493 BRDENABLE(portp->brdnr, portp->pagenr);
2494 stl_setreg(portp, CAR, (portp->portnr & 0x3));
2495 stl_setreg(portp, COR2, (stl_getreg(portp, COR2) | COR2_ETC));
2496 stl_setreg(portp, SRER,
2497 ((stl_getreg(portp, SRER) & ~SRER_TXDATA) | SRER_TXEMPTY));
2498 BRDDISABLE(portp->brdnr);
2501 portp->brklen = (len > 255) ? 255 : len;
2503 portp->brklen = len;
2506 portp->stats.txbreaks++;
2509 /*****************************************************************************/
2512 * Enable l_rint processing bypass mode if tty modes allow it.
2515 static void stl_ttyoptim(stlport_t *portp, struct termios *tiosp)
2520 if (((tiosp->c_iflag & (ICRNL | IGNCR | IMAXBEL | INLCR)) == 0) &&
2521 (((tiosp->c_iflag & BRKINT) == 0) || (tiosp->c_iflag & IGNBRK)) &&
2522 (((tiosp->c_iflag & PARMRK) == 0) ||
2523 ((tiosp->c_iflag & (IGNPAR | IGNBRK)) == (IGNPAR | IGNBRK))) &&
2524 ((tiosp->c_lflag & (ECHO | ICANON | IEXTEN | ISIG | PENDIN)) ==0) &&
2525 (linesw[tp->t_line].l_rint == ttyinput))
2526 tp->t_state |= TS_CAN_BYPASS_L_RINT;
2528 tp->t_state &= ~TS_CAN_BYPASS_L_RINT;
2529 portp->hotchar = linesw[tp->t_line].l_hotchar;
2532 /*****************************************************************************/
2535 * Try and find and initialize all the ports on a panel. We don't care
2536 * what sort of board these ports are on - since the port io registers
2537 * are almost identical when dealing with ports.
2540 static int stl_initports(stlbrd_t *brdp, stlpanel_t *panelp)
2543 unsigned int chipmask;
2545 int nrchips, uartaddr, ioaddr;
2549 printf("stl_initports(panelp=%x)\n", (int) panelp);
2552 BRDENABLE(panelp->brdnr, panelp->pagenr);
2555 * Check that each chip is present and started up OK.
2558 nrchips = panelp->nrports / CD1400_PORTS;
2559 for (i = 0; (i < nrchips); i++) {
2560 if (brdp->brdtype == BRD_ECHPCI) {
2561 outb(brdp->ioctrl, (panelp->pagenr + (i >> 1)));
2562 ioaddr = panelp->iobase;
2564 ioaddr = panelp->iobase + (EREG_BANKSIZE * (i >> 1));
2566 uartaddr = (i & 0x01) ? 0x080 : 0;
2567 outb(ioaddr, (GFRCR + uartaddr));
2568 outb((ioaddr + EREG_DATA), 0);
2569 outb(ioaddr, (CCR + uartaddr));
2570 outb((ioaddr + EREG_DATA), CCR_RESETFULL);
2571 outb((ioaddr + EREG_DATA), CCR_RESETFULL);
2572 outb(ioaddr, (GFRCR + uartaddr));
2573 for (j = 0; (j < CCR_MAXWAIT); j++) {
2574 gfrcr = inb(ioaddr + EREG_DATA);
2575 if ((gfrcr > 0x40) && (gfrcr < 0x60))
2578 if (j >= CCR_MAXWAIT) {
2579 printf("STALLION: cd1400 not responding, brd=%d "
2580 "panel=%d chip=%d\n", panelp->brdnr,
2581 panelp->panelnr, i);
2584 chipmask |= (0x1 << i);
2585 outb(ioaddr, (PPR + uartaddr));
2586 outb((ioaddr + EREG_DATA), PPR_SCALAR);
2590 * All cd1400's are initialized (if found!). Now go through and setup
2591 * each ports data structures. Also init the LIVR register of cd1400
2594 ioaddr = panelp->iobase;
2595 for (i = 0; (i < panelp->nrports); i++) {
2596 if (brdp->brdtype == BRD_ECHPCI) {
2597 outb(brdp->ioctrl, (panelp->pagenr + (i >> 3)));
2598 ioaddr = panelp->iobase;
2600 ioaddr = panelp->iobase + (EREG_BANKSIZE * (i >> 3));
2602 if ((chipmask & (0x1 << (i / 4))) == 0)
2604 portp = (stlport_t *) malloc(sizeof(stlport_t), M_TTYS,
2606 if (portp == (stlport_t *) NULL) {
2607 printf("STALLION: failed to allocate port memory "
2608 "(size=%d)\n", sizeof(stlport_t));
2613 portp->brdnr = panelp->brdnr;
2614 portp->panelnr = panelp->panelnr;
2615 portp->clk = brdp->clk;
2616 portp->ioaddr = ioaddr;
2617 portp->uartaddr = (i & 0x4) << 5;
2618 portp->pagenr = panelp->pagenr + (i >> 3);
2619 portp->hwid = stl_getreg(portp, GFRCR);
2620 stl_setreg(portp, CAR, (i & 0x3));
2621 stl_setreg(portp, LIVR, (i << 3));
2622 panelp->ports[i] = portp;
2624 j = STL_TXBUFSIZE + (2 * STL_RXBUFSIZE);
2625 portp->tx.buf = (char *) malloc(j, M_TTYS, M_NOWAIT);
2626 if (portp->tx.buf == (char *) NULL) {
2627 printf("STALLION: failed to allocate buffer memory "
2631 portp->tx.endbuf = portp->tx.buf + STL_TXBUFSIZE;
2632 portp->tx.head = portp->tx.buf;
2633 portp->tx.tail = portp->tx.buf;
2634 portp->rx.buf = portp->tx.buf + STL_TXBUFSIZE;
2635 portp->rx.endbuf = portp->rx.buf + STL_RXBUFSIZE;
2636 portp->rx.head = portp->rx.buf;
2637 portp->rx.tail = portp->rx.buf;
2638 portp->rxstatus.buf = portp->rx.buf + STL_RXBUFSIZE;
2639 portp->rxstatus.endbuf = portp->rxstatus.buf + STL_RXBUFSIZE;
2640 portp->rxstatus.head = portp->rxstatus.buf;
2641 portp->rxstatus.tail = portp->rxstatus.buf;
2642 bzero(portp->rxstatus.head, STL_RXBUFSIZE);
2644 portp->initintios.c_ispeed = STL_DEFSPEED;
2645 portp->initintios.c_ospeed = STL_DEFSPEED;
2646 portp->initintios.c_cflag = STL_DEFCFLAG;
2647 portp->initintios.c_iflag = 0;
2648 portp->initintios.c_oflag = 0;
2649 portp->initintios.c_lflag = 0;
2650 bcopy(&ttydefchars[0], &portp->initintios.c_cc[0],
2651 sizeof(portp->initintios.c_cc));
2652 portp->initouttios = portp->initintios;
2653 portp->dtrwait = 3 * hz;
2656 BRDDISABLE(panelp->brdnr);
2660 /*****************************************************************************/
2663 * Try to find and initialize an EasyIO board.
2666 static int stl_initeio(stlbrd_t *brdp)
2669 unsigned int status;
2672 printf("stl_initeio(brdp=%x)\n", (int) brdp);
2675 brdp->ioctrl = brdp->ioaddr1 + 1;
2676 brdp->iostatus = brdp->ioaddr1 + 2;
2677 brdp->clk = EIO_CLK;
2679 status = inb(brdp->iostatus);
2680 switch (status & EIO_IDBITMASK) {
2682 brdp->clk = EIO_CLK8M;
2696 * Check that the supplied IRQ is good and then use it to setup the
2697 * programmable interrupt bits on EIO board. Also set the edge/level
2698 * triggered interrupt bit.
2700 if ((brdp->irq < 0) || (brdp->irq > 15) ||
2701 (stl_vecmap[brdp->irq] == (unsigned char) 0xff)) {
2702 printf("STALLION: invalid irq=%d for brd=%d\n", brdp->irq,
2706 outb(brdp->ioctrl, (stl_vecmap[brdp->irq] |
2707 ((brdp->irqtype) ? EIO_INTLEVEL : EIO_INTEDGE)));
2709 panelp = (stlpanel_t *) malloc(sizeof(stlpanel_t), M_TTYS,
2711 if (panelp == (stlpanel_t *) NULL) {
2712 printf("STALLION: failed to allocate memory (size=%d)\n",
2713 sizeof(stlpanel_t));
2717 panelp->brdnr = brdp->brdnr;
2718 panelp->panelnr = 0;
2719 panelp->nrports = brdp->nrports;
2720 panelp->iobase = brdp->ioaddr1;
2721 panelp->hwid = status;
2722 brdp->panels[0] = panelp;
2724 brdp->hwid = status;
2725 brdp->state |= BRD_FOUND;
2729 /*****************************************************************************/
2732 * Try to find an ECH board and initialize it. This code is capable of
2733 * dealing with all types of ECH board.
2736 static int stl_initech(stlbrd_t *brdp)
2739 unsigned int status, nxtid;
2740 int panelnr, ioaddr, i;
2743 printf("stl_initech(brdp=%x)\n", (int) brdp);
2747 * Set up the initial board register contents for boards. This varys a
2748 * bit between the different board types. So we need to handle each
2749 * separately. Also do a check that the supplied IRQ is good.
2751 if (brdp->brdtype == BRD_ECH) {
2752 brdp->ioctrl = brdp->ioaddr1 + 1;
2753 brdp->iostatus = brdp->ioaddr1 + 1;
2754 status = inb(brdp->iostatus);
2755 if ((status & ECH_IDBITMASK) != ECH_ID)
2757 brdp->hwid = status;
2759 if ((brdp->irq < 0) || (brdp->irq > 15) ||
2760 (stl_vecmap[brdp->irq] == (unsigned char) 0xff)) {
2761 printf("STALLION: invalid irq=%d for brd=%d\n",
2762 brdp->irq, brdp->brdnr);
2765 status = ((brdp->ioaddr2 & ECH_ADDR2MASK) >> 1);
2766 status |= (stl_vecmap[brdp->irq] << 1);
2767 outb(brdp->ioaddr1, (status | ECH_BRDRESET));
2768 brdp->ioctrlval = ECH_INTENABLE |
2769 ((brdp->irqtype) ? ECH_INTLEVEL : ECH_INTEDGE);
2770 outb(brdp->ioctrl, (brdp->ioctrlval | ECH_BRDENABLE));
2771 outb(brdp->ioaddr1, status);
2772 } else if (brdp->brdtype == BRD_ECHMC) {
2773 brdp->ioctrl = brdp->ioaddr1 + 0x20;
2774 brdp->iostatus = brdp->ioctrl;
2775 status = inb(brdp->iostatus);
2776 if ((status & ECH_IDBITMASK) != ECH_ID)
2778 brdp->hwid = status;
2780 if ((brdp->irq < 0) || (brdp->irq > 15) ||
2781 (stl_vecmap[brdp->irq] == (unsigned char) 0xff)) {
2782 printf("STALLION: invalid irq=%d for brd=%d\n",
2783 brdp->irq, brdp->brdnr);
2786 outb(brdp->ioctrl, ECHMC_BRDRESET);
2787 outb(brdp->ioctrl, ECHMC_INTENABLE);
2788 } else if (brdp->brdtype == BRD_ECHPCI) {
2789 brdp->ioctrl = brdp->ioaddr1 + 2;
2792 brdp->clk = ECH_CLK;
2795 * Scan through the secondary io address space looking for panels.
2796 * As we find'em allocate and initialize panel structures for each.
2798 ioaddr = brdp->ioaddr2;
2802 for (i = 0; (i < STL_MAXPANELS); i++) {
2803 if (brdp->brdtype == BRD_ECHPCI) {
2804 outb(brdp->ioctrl, nxtid);
2805 ioaddr = brdp->ioaddr2;
2807 status = inb(ioaddr + ECH_PNLSTATUS);
2808 if ((status & ECH_PNLIDMASK) != nxtid)
2810 panelp = (stlpanel_t *) malloc(sizeof(stlpanel_t), M_TTYS,
2812 if (panelp == (stlpanel_t *) NULL) {
2813 printf("STALLION: failed to allocate memory"
2814 "(size=%d)\n", sizeof(stlpanel_t));
2817 panelp->brdnr = brdp->brdnr;
2818 panelp->panelnr = panelnr;
2819 panelp->iobase = ioaddr;
2820 panelp->pagenr = nxtid;
2821 panelp->hwid = status;
2822 if (status & ECH_PNL16PORT) {
2823 if ((brdp->nrports + 16) > 32)
2825 panelp->nrports = 16;
2826 panelp->ackmask = 0x80;
2827 brdp->nrports += 16;
2828 ioaddr += (EREG_BANKSIZE * 2);
2831 panelp->nrports = 8;
2832 panelp->ackmask = 0xc0;
2834 ioaddr += EREG_BANKSIZE;
2837 brdp->panels[panelnr++] = panelp;
2839 if (ioaddr >= (brdp->ioaddr2 + 0x20))
2843 if (brdp->brdtype == BRD_ECH)
2844 outb(brdp->ioctrl, (brdp->ioctrlval | ECH_BRDDISABLE));
2846 brdp->state |= BRD_FOUND;
2850 /*****************************************************************************/
2853 * Initialize and configure the specified board. This firstly probes
2854 * for the board, if it is found then the board is initialized and
2855 * then all its ports are initialized as well.
2858 static int stl_brdinit(stlbrd_t *brdp)
2864 printf("stl_brdinit(brdp=%x): unit=%d type=%d io1=%x io2=%x irq=%d\n",
2865 (int) brdp, brdp->brdnr, brdp->brdtype, brdp->ioaddr1,
2866 brdp->ioaddr2, brdp->irq);
2869 switch (brdp->brdtype) {
2879 printf("STALLION: unit=%d is unknown board type=%d\n",
2880 brdp->brdnr, brdp->brdtype);
2884 stl_brds[brdp->brdnr] = brdp;
2885 if ((brdp->state & BRD_FOUND) == 0) {
2887 printf("STALLION: %s board not found, unit=%d io=%x irq=%d\n",
2888 stl_brdnames[brdp->brdtype], brdp->brdnr,
2889 brdp->ioaddr1, brdp->irq);
2894 for (i = 0, k = 0; (i < STL_MAXPANELS); i++) {
2895 panelp = brdp->panels[i];
2896 if (panelp != (stlpanel_t *) NULL) {
2897 stl_initports(brdp, panelp);
2898 for (j = 0; (j < panelp->nrports); j++)
2899 brdp->ports[k++] = panelp->ports[j];
2903 printf("stl%d: %s (driver version %s) unit=%d nrpanels=%d nrports=%d\n",
2904 brdp->unitid, stl_brdnames[brdp->brdtype], stl_drvversion,
2905 brdp->brdnr, brdp->nrpanels, brdp->nrports);
2909 /*****************************************************************************/
2912 * Return the board stats structure to user app.
2915 static int stl_getbrdstats(caddr_t data)
2921 stl_brdstats = *((combrd_t *) data);
2922 if (stl_brdstats.brd >= STL_MAXBRDS)
2924 brdp = stl_brds[stl_brdstats.brd];
2925 if (brdp == (stlbrd_t *) NULL)
2928 bzero(&stl_brdstats, sizeof(combrd_t));
2929 stl_brdstats.brd = brdp->brdnr;
2930 stl_brdstats.type = brdp->brdtype;
2931 stl_brdstats.hwid = brdp->hwid;
2932 stl_brdstats.state = brdp->state;
2933 stl_brdstats.ioaddr = brdp->ioaddr1;
2934 stl_brdstats.ioaddr2 = brdp->ioaddr2;
2935 stl_brdstats.irq = brdp->irq;
2936 stl_brdstats.nrpanels = brdp->nrpanels;
2937 stl_brdstats.nrports = brdp->nrports;
2938 for (i = 0; (i < brdp->nrpanels); i++) {
2939 panelp = brdp->panels[i];
2940 stl_brdstats.panels[i].panel = i;
2941 stl_brdstats.panels[i].hwid = panelp->hwid;
2942 stl_brdstats.panels[i].nrports = panelp->nrports;
2945 *((combrd_t *) data) = stl_brdstats;;
2949 /*****************************************************************************/
2952 * Resolve the referenced port number into a port struct pointer.
2955 static stlport_t *stl_getport(int brdnr, int panelnr, int portnr)
2960 if ((brdnr < 0) || (brdnr >= STL_MAXBRDS))
2961 return((stlport_t *) NULL);
2962 brdp = stl_brds[brdnr];
2963 if (brdp == (stlbrd_t *) NULL)
2964 return((stlport_t *) NULL);
2965 if ((panelnr < 0) || (panelnr >= brdp->nrpanels))
2966 return((stlport_t *) NULL);
2967 panelp = brdp->panels[panelnr];
2968 if (panelp == (stlpanel_t *) NULL)
2969 return((stlport_t *) NULL);
2970 if ((portnr < 0) || (portnr >= panelp->nrports))
2971 return((stlport_t *) NULL);
2972 return(panelp->ports[portnr]);
2975 /*****************************************************************************/
2978 * Return the port stats structure to user app. A NULL port struct
2979 * pointer passed in means that we need to find out from the app
2980 * what port to get stats for (used through board control device).
2983 static int stl_getportstats(stlport_t *portp, caddr_t data)
2985 unsigned char *head, *tail;
2987 if (portp == (stlport_t *) NULL) {
2988 stl_comstats = *((comstats_t *) data);
2989 portp = stl_getport(stl_comstats.brd, stl_comstats.panel,
2991 if (portp == (stlport_t *) NULL)
2995 portp->stats.state = portp->state;
2996 /*portp->stats.flags = portp->flags;*/
2997 portp->stats.hwid = portp->hwid;
2998 portp->stats.ttystate = portp->tty.t_state;
2999 portp->stats.cflags = portp->tty.t_cflag;
3000 portp->stats.iflags = portp->tty.t_iflag;
3001 portp->stats.oflags = portp->tty.t_oflag;
3002 portp->stats.lflags = portp->tty.t_lflag;
3004 head = portp->tx.head;
3005 tail = portp->tx.tail;
3006 portp->stats.txbuffered = ((head >= tail) ? (head - tail) :
3007 (STL_TXBUFSIZE - (tail - head)));
3009 head = portp->rx.head;
3010 tail = portp->rx.tail;
3011 portp->stats.rxbuffered = (head >= tail) ? (head - tail) :
3012 (STL_RXBUFSIZE - (tail - head));
3014 portp->stats.signals = (unsigned long) stl_getsignals(portp);
3016 *((comstats_t *) data) = portp->stats;
3020 /*****************************************************************************/
3023 * Clear the port stats structure. We also return it zeroed out...
3026 static int stl_clrportstats(stlport_t *portp, caddr_t data)
3028 if (portp == (stlport_t *) NULL) {
3029 stl_comstats = *((comstats_t *) data);
3030 portp = stl_getport(stl_comstats.brd, stl_comstats.panel,
3032 if (portp == (stlport_t *) NULL)
3036 bzero(&portp->stats, sizeof(comstats_t));
3037 portp->stats.brd = portp->brdnr;
3038 portp->stats.panel = portp->panelnr;
3039 portp->stats.port = portp->portnr;
3040 *((comstats_t *) data) = stl_comstats;
3044 /*****************************************************************************/
3047 * The "staliomem" device is used for stats collection in this driver.
3050 static int stl_memioctl(dev_t dev, unsigned long cmd, caddr_t data, int flag,
3057 printf("stl_memioctl(dev=%s,cmd=%lx,data=%p,flag=%x)\n",
3058 devtoname(dev), cmd, (void *) data, flag);
3061 brdnr = minor(dev) & 0x7;
3062 brdp = stl_brds[brdnr];
3063 if (brdp == (stlbrd_t *) NULL)
3065 if (brdp->state == 0)
3071 case COM_GETPORTSTATS:
3072 rc = stl_getportstats((stlport_t *) NULL, data);
3074 case COM_CLRPORTSTATS:
3075 rc = stl_clrportstats((stlport_t *) NULL, data);
3077 case COM_GETBRDSTATS:
3078 rc = stl_getbrdstats(data);
3088 /*****************************************************************************/