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
36 * $FreeBSD: src/sys/i386/isa/stallion.c,v 1.39.2.2 2001/08/30 12:29:57 murray Exp $
39 /*****************************************************************************/
43 #include "opt_compat.h"
45 #include <sys/param.h>
47 #include <sys/systm.h>
48 #include <sys/kernel.h>
49 #include <sys/malloc.h>
54 #include <sys/fcntl.h>
55 #include <sys/thread2.h>
56 #include <dev/serial/stl/scd1400.h>
57 #include <dev/serial/stl/sc26198.h>
58 #include <machine/comstats.h>
60 #include <bus/pci/pcivar.h>
61 #include <bus/pci/pcireg.h>
65 /*****************************************************************************/
68 * Define different board types. At the moment I have only declared
69 * those boards that this driver supports. But I will use the standard
70 * "assigned" board numbers. In the future this driver will support
71 * some of the other Stallion boards. Currently supported boards are
72 * abbreviated as EIO = EasyIO and ECH = EasyConnection 8/32.
78 #define BRD_ECH64PCI 27
79 #define BRD_EASYIOPCI 28
81 /*****************************************************************************/
84 * Define important driver limitations.
87 #define STL_MAXPANELS 4
88 #define STL_MAXBANKS 8
89 #define STL_PORTSPERPANEL 16
90 #define STL_PORTSPERBRD 64
93 * Define the important minor number break down bits. These have been
94 * chosen to be "compatible" with the standard sio driver minor numbers.
95 * Extra high bits are used to distinguish between boards.
97 #define STL_CALLOUTDEV 0x80
98 #define STL_CTRLLOCK 0x40
99 #define STL_CTRLINIT 0x20
100 #define STL_CTRLDEV (STL_CTRLLOCK | STL_CTRLINIT)
102 #define STL_MEMDEV 0x07000000
104 #define STL_DEFSPEED TTYDEF_SPEED
105 #define STL_DEFCFLAG (CS8 | CREAD | HUPCL)
108 * I haven't really decided (or measured) what buffer sizes give
109 * a good balance between performance and memory usage. These seem
110 * to work pretty well...
112 #define STL_RXBUFSIZE 2048
113 #define STL_TXBUFSIZE 2048
115 #define STL_TXBUFLOW (STL_TXBUFSIZE / 4)
116 #define STL_RXBUFHIGH (3 * STL_RXBUFSIZE / 4)
118 /*****************************************************************************/
121 * Define our local driver identity first. Set up stuff to deal with
122 * all the local structures required by a serial tty driver.
124 static const char stl_drvname[] = "stl";
125 static const char stl_longdrvname[] = "Stallion Multiport Serial Driver";
126 static const char stl_drvversion[] = "2.0.0";
128 static int stl_nrbrds = 0;
129 static int stl_doingtimeout = 0;
130 static struct callout stl_poll_ch;
132 static const char __file__[] = /*__FILE__*/ "stallion.c";
135 * Define global stats structures. Not used often, and can be
136 * re-used for each stats call.
138 static combrd_t stl_brdstats;
139 static comstats_t stl_comstats;
141 /*****************************************************************************/
144 * Define a set of structures to hold all the board/panel/port info
145 * for our ports. These will be dynamically allocated as required.
149 * Define a ring queue structure for each port. This will hold the
150 * TX data waiting to be output. Characters are fed into this buffer
151 * from the line discipline (or even direct from user space!) and
152 * then fed into the UARTs during interrupts. Will use a clasic ring
153 * queue here for this. The good thing about this type of ring queue
154 * is that the head and tail pointers can be updated without interrupt
155 * protection - since "write" code only needs to change the head, and
156 * interrupt code only needs to change the tail.
166 * Port, panel and board structures to hold status info about each.
167 * The board structure contains pointers to structures for each panel
168 * connected to it, and in turn each panel structure contains pointers
169 * for each port structure for each port on that panel. Note that
170 * the port structure also contains the board and panel number that it
171 * is associated with, this makes it (fairly) easy to get back to the
172 * board/panel info for a port. Also note that the tty struct is at
173 * the top of the structure, this is important, since the code uses
174 * this fact to get the port struct pointer from the tty struct
177 typedef struct stlport {
195 unsigned int rxignoremsk;
196 unsigned int rxmarkmsk;
197 unsigned int crenable;
200 struct termios initintios;
201 struct termios initouttios;
202 struct termios lockintios;
203 struct termios lockouttios;
204 struct timeval timestamp;
209 struct callout dtr_ch;
212 typedef struct stlpanel {
219 unsigned int ackmask;
220 void (*isr)(struct stlpanel *panelp, unsigned int iobase);
222 stlport_t *ports[STL_PORTSPERPANEL];
225 typedef struct stlbrd {
235 unsigned int ioaddr1;
236 unsigned int ioaddr2;
237 unsigned int iostatus;
239 unsigned int ioctrlval;
242 void (*isr)(struct stlbrd *brdp);
243 unsigned int bnkpageaddr[STL_MAXBANKS];
244 unsigned int bnkstataddr[STL_MAXBANKS];
245 stlpanel_t *bnk2panel[STL_MAXBANKS];
246 stlpanel_t *panels[STL_MAXPANELS];
247 stlport_t *ports[STL_PORTSPERBRD];
250 static stlbrd_t *stl_brds[STL_MAXBRDS];
253 * Per board state flags. Used with the state field of the board struct.
254 * Not really much here yet!
256 #define BRD_FOUND 0x1
259 * Define the port structure state flags. These set of flags are
260 * modified at interrupt time - so setting and reseting them needs
263 #define ASY_TXLOW 0x1
264 #define ASY_RXDATA 0x2
265 #define ASY_DCDCHANGE 0x4
266 #define ASY_DTRWAIT 0x8
267 #define ASY_RTSFLOW 0x10
268 #define ASY_RTSFLOWMODE 0x20
269 #define ASY_CTSFLOWMODE 0x40
270 #define ASY_TXFLOWED 0x80
271 #define ASY_TXBUSY 0x100
272 #define ASY_TXEMPTY 0x200
274 #define ASY_ACTIVE (ASY_TXLOW | ASY_RXDATA | ASY_DCDCHANGE)
277 * Define an array of board names as printable strings. Handy for
278 * referencing boards when printing trace and stuff.
280 static char *stl_brdnames[] = {
312 /*****************************************************************************/
315 * Hardware ID bits for the EasyIO and ECH boards. These defines apply
316 * to the directly accessable io ports of these boards (not the cd1400
317 * uarts - they are in scd1400.h).
319 #define EIO_8PORTRS 0x04
320 #define EIO_4PORTRS 0x05
321 #define EIO_8PORTDI 0x00
322 #define EIO_8PORTM 0x06
324 #define EIO_IDBITMASK 0x07
326 #define EIO_BRDMASK 0xf0
329 #define ID_BRD16 0x30
331 #define EIO_INTRPEND 0x08
332 #define EIO_INTEDGE 0x00
333 #define EIO_INTLEVEL 0x08
336 #define ECH_IDBITMASK 0xe0
337 #define ECH_BRDENABLE 0x08
338 #define ECH_BRDDISABLE 0x00
339 #define ECH_INTENABLE 0x01
340 #define ECH_INTDISABLE 0x00
341 #define ECH_INTLEVEL 0x02
342 #define ECH_INTEDGE 0x00
343 #define ECH_INTRPEND 0x01
344 #define ECH_BRDRESET 0x01
346 #define ECHMC_INTENABLE 0x01
347 #define ECHMC_BRDRESET 0x02
349 #define ECH_PNLSTATUS 2
350 #define ECH_PNL16PORT 0x20
351 #define ECH_PNLIDMASK 0x07
352 #define ECH_PNLXPID 0x40
353 #define ECH_PNLINTRPEND 0x80
354 #define ECH_ADDR2MASK 0x1e0
356 #define EIO_CLK 25000000
357 #define EIO_CLK8M 20000000
358 #define ECH_CLK EIO_CLK
361 * Define the PCI vendor and device ID for Stallion PCI boards.
363 #define STL_PCINSVENDID 0x100b
364 #define STL_PCINSDEVID 0xd001
366 #define STL_PCIVENDID 0x124d
367 #define STL_PCI32DEVID 0x0000
368 #define STL_PCI64DEVID 0x0002
369 #define STL_PCIEIODEVID 0x0003
371 #define STL_PCIBADCLASS 0x0101
373 typedef struct stlpcibrd {
374 unsigned short vendid;
375 unsigned short devid;
379 static stlpcibrd_t stl_pcibrds[] = {
380 { STL_PCIVENDID, STL_PCI64DEVID, BRD_ECH64PCI },
381 { STL_PCIVENDID, STL_PCIEIODEVID, BRD_EASYIOPCI },
382 { STL_PCIVENDID, STL_PCI32DEVID, BRD_ECHPCI },
383 { STL_PCINSVENDID, STL_PCINSDEVID, BRD_ECHPCI },
386 static int stl_nrpcibrds = NELEM(stl_pcibrds);
388 /*****************************************************************************/
391 * Define the vector mapping bits for the programmable interrupt board
392 * hardware. These bits encode the interrupt for the board to use - it
393 * is software selectable (except the EIO-8M).
395 static unsigned char stl_vecmap[] = {
396 0xff, 0xff, 0xff, 0x04, 0x06, 0x05, 0xff, 0x07,
397 0xff, 0xff, 0x00, 0x02, 0x01, 0xff, 0xff, 0x03
401 * Set up enable and disable macros for the ECH boards. They require
402 * the secondary io address space to be activated and deactivated.
403 * This way all ECH boards can share their secondary io region.
404 * If this is an ECH-PCI board then also need to set the page pointer
405 * to point to the correct page.
407 #define BRDENABLE(brdnr,pagenr) \
408 if (stl_brds[(brdnr)]->brdtype == BRD_ECH) \
409 outb(stl_brds[(brdnr)]->ioctrl, \
410 (stl_brds[(brdnr)]->ioctrlval | ECH_BRDENABLE));\
411 else if (stl_brds[(brdnr)]->brdtype == BRD_ECHPCI) \
412 outb(stl_brds[(brdnr)]->ioctrl, (pagenr));
414 #define BRDDISABLE(brdnr) \
415 if (stl_brds[(brdnr)]->brdtype == BRD_ECH) \
416 outb(stl_brds[(brdnr)]->ioctrl, \
417 (stl_brds[(brdnr)]->ioctrlval | ECH_BRDDISABLE));
420 * Define some spare buffer space for un-wanted received characters.
422 static char stl_unwanted[SC26198_RXFIFOSIZE];
424 /*****************************************************************************/
427 * Define macros to extract a brd and port number from a minor number.
428 * This uses the extended minor number range in the upper 2 bytes of
429 * the device number. This gives us plenty of minor numbers to play
432 #define MKDEV2BRD(m) ((minor(m) & 0x00700000) >> 20)
433 #define MKDEV2PORT(m) ((minor(m) & 0x1f) | ((minor(m) & 0x00010000) >> 11))
436 * Define some handy local macros...
439 #define MIN(a,b) (((a) <= (b)) ? (a) : (b))
442 /*****************************************************************************/
445 * Declare all those functions in this driver! First up is the set of
446 * externally visible functions.
449 static d_open_t stlopen;
450 static d_close_t stlclose;
451 static d_ioctl_t stlioctl;
454 * Internal function prototypes.
456 static stlport_t *stl_dev2port(cdev_t dev);
457 static int stl_findfreeunit(void);
458 static int stl_rawopen(stlport_t *portp);
459 static int stl_rawclose(stlport_t *portp);
460 static void stl_flush(stlport_t *portp, int flag);
461 static int stl_param(struct tty *tp, struct termios *tiosp);
462 static void stl_start(struct tty *tp);
463 static void stl_stop(struct tty *tp, int);
464 static void stl_ttyoptim(stlport_t *portp, struct termios *tiosp);
465 static void stl_dotimeout(void);
466 static void stl_poll(void *arg);
467 static void stl_rxprocess(stlport_t *portp);
468 static void stl_flowcontrol(stlport_t *portp, int hw, int sw);
469 static void stl_dtrwakeup(void *arg);
470 static int stl_brdinit(stlbrd_t *brdp);
471 static int stl_initeio(stlbrd_t *brdp);
472 static int stl_initech(stlbrd_t *brdp);
473 static int stl_initports(stlbrd_t *brdp, stlpanel_t *panelp);
474 static void stl_eiointr(stlbrd_t *brdp);
475 static void stl_echatintr(stlbrd_t *brdp);
476 static void stl_echmcaintr(stlbrd_t *brdp);
477 static void stl_echpciintr(stlbrd_t *brdp);
478 static void stl_echpci64intr(stlbrd_t *brdp);
479 static int stl_memioctl(cdev_t dev, unsigned long cmd, caddr_t data,
481 static int stl_getbrdstats(caddr_t data);
482 static int stl_getportstats(stlport_t *portp, caddr_t data);
483 static int stl_clrportstats(stlport_t *portp, caddr_t data);
484 static stlport_t *stl_getport(int brdnr, int panelnr, int portnr);
485 static void stlintr(void *);
487 static const char *stlpciprobe(pcici_t tag, pcidi_t type);
488 static void stlpciattach(pcici_t tag, int unit);
489 static void stlpciintr(void * arg);
492 * CD1400 uart specific handling functions.
494 static void stl_cd1400setreg(stlport_t *portp, int regnr, int value);
495 static int stl_cd1400getreg(stlport_t *portp, int regnr);
496 static int stl_cd1400updatereg(stlport_t *portp, int regnr, int value);
497 static int stl_cd1400panelinit(stlbrd_t *brdp, stlpanel_t *panelp);
498 static void stl_cd1400portinit(stlbrd_t *brdp, stlpanel_t *panelp, stlport_t *portp);
499 static int stl_cd1400setport(stlport_t *portp, struct termios *tiosp);
500 static int stl_cd1400getsignals(stlport_t *portp);
501 static void stl_cd1400setsignals(stlport_t *portp, int dtr, int rts);
502 static void stl_cd1400ccrwait(stlport_t *portp);
503 static void stl_cd1400enablerxtx(stlport_t *portp, int rx, int tx);
504 static void stl_cd1400startrxtx(stlport_t *portp, int rx, int tx);
505 static void stl_cd1400disableintrs(stlport_t *portp);
506 static void stl_cd1400sendbreak(stlport_t *portp, long len);
507 static void stl_cd1400sendflow(stlport_t *portp, int hw, int sw);
508 static int stl_cd1400datastate(stlport_t *portp);
509 static void stl_cd1400flush(stlport_t *portp, int flag);
510 static __inline void stl_cd1400txisr(stlpanel_t *panelp, int ioaddr);
511 static void stl_cd1400rxisr(stlpanel_t *panelp, int ioaddr);
512 static void stl_cd1400mdmisr(stlpanel_t *panelp, int ioaddr);
513 static void stl_cd1400eiointr(stlpanel_t *panelp, unsigned int iobase);
514 static void stl_cd1400echintr(stlpanel_t *panelp, unsigned int iobase);
517 * SC26198 uart specific handling functions.
519 static void stl_sc26198setreg(stlport_t *portp, int regnr, int value);
520 static int stl_sc26198getreg(stlport_t *portp, int regnr);
521 static int stl_sc26198updatereg(stlport_t *portp, int regnr, int value);
522 static int stl_sc26198getglobreg(stlport_t *portp, int regnr);
523 static int stl_sc26198panelinit(stlbrd_t *brdp, stlpanel_t *panelp);
524 static void stl_sc26198portinit(stlbrd_t *brdp, stlpanel_t *panelp, stlport_t *portp);
525 static int stl_sc26198setport(stlport_t *portp, struct termios *tiosp);
526 static int stl_sc26198getsignals(stlport_t *portp);
527 static void stl_sc26198setsignals(stlport_t *portp, int dtr, int rts);
528 static void stl_sc26198enablerxtx(stlport_t *portp, int rx, int tx);
529 static void stl_sc26198startrxtx(stlport_t *portp, int rx, int tx);
530 static void stl_sc26198disableintrs(stlport_t *portp);
531 static void stl_sc26198sendbreak(stlport_t *portp, long len);
532 static void stl_sc26198sendflow(stlport_t *portp, int hw, int sw);
533 static int stl_sc26198datastate(stlport_t *portp);
534 static void stl_sc26198flush(stlport_t *portp, int flag);
535 static void stl_sc26198txunflow(stlport_t *portp);
536 static void stl_sc26198wait(stlport_t *portp);
537 static void stl_sc26198intr(stlpanel_t *panelp, unsigned int iobase);
538 static void stl_sc26198txisr(stlport_t *port);
539 static void stl_sc26198rxisr(stlport_t *port, unsigned int iack);
540 static void stl_sc26198rxgoodchars(stlport_t *portp);
541 static void stl_sc26198rxbadchars(stlport_t *portp);
542 static void stl_sc26198otherisr(stlport_t *port, unsigned int iack);
544 /*****************************************************************************/
547 * Generic UART support structure.
549 typedef struct uart {
550 int (*panelinit)(stlbrd_t *brdp, stlpanel_t *panelp);
551 void (*portinit)(stlbrd_t *brdp, stlpanel_t *panelp, stlport_t *portp);
552 int (*setport)(stlport_t *portp, struct termios *tiosp);
553 int (*getsignals)(stlport_t *portp);
554 void (*setsignals)(stlport_t *portp, int dtr, int rts);
555 void (*enablerxtx)(stlport_t *portp, int rx, int tx);
556 void (*startrxtx)(stlport_t *portp, int rx, int tx);
557 void (*disableintrs)(stlport_t *portp);
558 void (*sendbreak)(stlport_t *portp, long len);
559 void (*sendflow)(stlport_t *portp, int hw, int sw);
560 void (*flush)(stlport_t *portp, int flag);
561 int (*datastate)(stlport_t *portp);
562 void (*intr)(stlpanel_t *panelp, unsigned int iobase);
566 * Define some macros to make calling these functions nice and clean.
568 #define stl_panelinit (* ((uart_t *) panelp->uartp)->panelinit)
569 #define stl_portinit (* ((uart_t *) portp->uartp)->portinit)
570 #define stl_setport (* ((uart_t *) portp->uartp)->setport)
571 #define stl_getsignals (* ((uart_t *) portp->uartp)->getsignals)
572 #define stl_setsignals (* ((uart_t *) portp->uartp)->setsignals)
573 #define stl_enablerxtx (* ((uart_t *) portp->uartp)->enablerxtx)
574 #define stl_startrxtx (* ((uart_t *) portp->uartp)->startrxtx)
575 #define stl_disableintrs (* ((uart_t *) portp->uartp)->disableintrs)
576 #define stl_sendbreak (* ((uart_t *) portp->uartp)->sendbreak)
577 #define stl_sendflow (* ((uart_t *) portp->uartp)->sendflow)
578 #define stl_uartflush (* ((uart_t *) portp->uartp)->flush)
579 #define stl_datastate (* ((uart_t *) portp->uartp)->datastate)
581 /*****************************************************************************/
584 * CD1400 UART specific data initialization.
586 static uart_t stl_cd1400uart = {
590 stl_cd1400getsignals,
591 stl_cd1400setsignals,
592 stl_cd1400enablerxtx,
594 stl_cd1400disableintrs,
603 * Define the offsets within the register bank of a cd1400 based panel.
604 * These io address offsets are common to the EasyIO board as well.
612 #define EREG_BANKSIZE 8
614 #define CD1400_CLK 25000000
615 #define CD1400_CLK8M 20000000
618 * Define the cd1400 baud rate clocks. These are used when calculating
619 * what clock and divisor to use for the required baud rate. Also
620 * define the maximum baud rate allowed, and the default base baud.
622 static int stl_cd1400clkdivs[] = {
623 CD1400_CLK0, CD1400_CLK1, CD1400_CLK2, CD1400_CLK3, CD1400_CLK4
627 * Define the maximum baud rate of the cd1400 devices.
629 #define CD1400_MAXBAUD 230400
631 /*****************************************************************************/
634 * SC26198 UART specific data initization.
636 static uart_t stl_sc26198uart = {
637 stl_sc26198panelinit,
640 stl_sc26198getsignals,
641 stl_sc26198setsignals,
642 stl_sc26198enablerxtx,
643 stl_sc26198startrxtx,
644 stl_sc26198disableintrs,
645 stl_sc26198sendbreak,
648 stl_sc26198datastate,
653 * Define the offsets within the register bank of a sc26198 based panel.
661 #define XP_BANKSIZE 4
664 * Define the sc26198 baud rate table. Offsets within the table
665 * represent the actual baud rate selector of sc26198 registers.
667 static unsigned int sc26198_baudtable[] = {
668 50, 75, 150, 200, 300, 450, 600, 900, 1200, 1800, 2400, 3600,
669 4800, 7200, 9600, 14400, 19200, 28800, 38400, 57600, 115200,
673 #define SC26198_NRBAUDS NELEM(sc26198_baudtable)
676 * Define the maximum baud rate of the sc26198 devices.
678 #define SC26198_MAXBAUD 460800
680 /*****************************************************************************/
683 * Declare the driver pci structure.
685 static unsigned long stl_count;
687 static struct pci_device stlpcidriver = {
695 COMPAT_PCI_DRIVER (stlpci, stlpcidriver);
697 /*****************************************************************************/
700 * FreeBSD-2.2+ kernel linkage.
703 #define CDEV_MAJOR 72
704 static struct dev_ops stl_ops = {
711 .d_kqfilter = ttykqfilter,
712 .d_revoke = ttyrevoke
715 static void stl_drvinit(void *unused)
719 SYSINIT(sidev,SI_SUB_DRIVERS,SI_ORDER_MIDDLE+CDEV_MAJOR,stl_drvinit,NULL);
721 /*****************************************************************************/
724 * Find an available internal board number (unit number). The problem
725 * is that the same unit numbers can be assigned to different boards
726 * detected during the ISA and PCI initialization phases.
729 static int stl_findfreeunit(void)
733 for (i = 0; (i < STL_MAXBRDS); i++)
734 if (stl_brds[i] == NULL)
736 return((i >= STL_MAXBRDS) ? -1 : i);
739 /*****************************************************************************/
742 * Probe specifically for the PCI boards. We need to be a little
743 * carefull here, since it looks sort like a Nat Semi IDE chip...
746 static const char *stlpciprobe(pcici_t tag, pcidi_t type)
752 kprintf("stlpciprobe(tag=%x,type=%x)\n", (int) &tag, (int) type);
756 for (i = 0; (i < stl_nrpcibrds); i++) {
757 if (((type & 0xffff) == stl_pcibrds[i].vendid) &&
758 (((type >> 16) & 0xffff) == stl_pcibrds[i].devid)) {
759 brdtype = stl_pcibrds[i].brdtype;
767 class = pci_conf_read(tag, PCI_CLASS_REG);
768 if ((class & PCI_CLASS_MASK) == PCI_CLASS_MASS_STORAGE)
771 return(stl_brdnames[brdtype]);
774 /*****************************************************************************/
777 * Allocate resources for and initialize the specified PCI board.
780 void stlpciattach(pcici_t tag, int unit)
786 int boardnr, portnr, minor_dev;
789 kprintf("stlpciattach(tag=%x,unit=%x)\n", (int) &tag, unit);
792 brdp = kmalloc(sizeof(stlbrd_t), M_TTYS, M_WAITOK | M_ZERO);
794 if ((unit < 0) || (unit > STL_MAXBRDS)) {
795 kprintf("STALLION: bad PCI board unit number=%d\n", unit);
800 * Allocate us a new driver unique unit number.
802 if ((brdp->brdnr = stl_findfreeunit()) < 0) {
803 kprintf("STALLION: too many boards found, max=%d\n",
807 if (brdp->brdnr >= stl_nrbrds)
808 stl_nrbrds = brdp->brdnr + 1;
811 * Determine what type of PCI board this is...
813 id = (unsigned int) pci_conf_read(tag, 0x0);
814 for (i = 0; (i < stl_nrpcibrds); i++) {
815 if (((id & 0xffff) == stl_pcibrds[i].vendid) &&
816 (((id >> 16) & 0xffff) == stl_pcibrds[i].devid)) {
817 brdp->brdtype = stl_pcibrds[i].brdtype;
822 if (i >= stl_nrpcibrds) {
823 kprintf("STALLION: probed PCI board unknown type=%x\n", id);
827 for (i = 0; (i < 4); i++)
828 bar[i] = (unsigned int) pci_conf_read(tag, 0x10 + (i * 4)) &
831 switch (brdp->brdtype) {
833 brdp->ioaddr1 = bar[1];
834 brdp->ioaddr2 = bar[2];
837 brdp->ioaddr1 = bar[2];
838 brdp->ioaddr2 = bar[1];
841 brdp->ioaddr1 = bar[1];
842 brdp->ioaddr2 = bar[0];
845 kprintf("STALLION: unknown PCI board type=%d\n", brdp->brdtype);
850 brdp->unitid = brdp->brdnr; /* PCI units auto-assigned */
851 brdp->irq = ((int) pci_conf_read(tag, 0x3c)) & 0xff;
853 if (pci_map_int(tag, stlpciintr, NULL) == 0) {
854 kprintf("STALLION: failed to map interrupt irq=%d for unit=%d\n",
855 brdp->irq, brdp->brdnr);
861 /* register devices for DEVFS */
862 boardnr = brdp->brdnr;
863 make_dev(&stl_ops, boardnr + 0x1000000, UID_ROOT, GID_WHEEL,
864 0600, "staliomem%d", boardnr);
866 for (portnr = 0, minor_dev = boardnr * 0x100000;
867 portnr < 32; portnr++, minor_dev++) {
869 make_dev(&stl_ops, minor_dev,
870 UID_ROOT, GID_WHEEL, 0600,
871 "ttyE%d", portnr + (boardnr * 64));
872 make_dev(&stl_ops, minor_dev + 32,
873 UID_ROOT, GID_WHEEL, 0600,
874 "ttyiE%d", portnr + (boardnr * 64));
875 make_dev(&stl_ops, minor_dev + 64,
876 UID_ROOT, GID_WHEEL, 0600,
877 "ttylE%d", portnr + (boardnr * 64));
878 make_dev(&stl_ops, minor_dev + 128,
879 UID_ROOT, GID_WHEEL, 0600,
880 "cue%d", portnr + (boardnr * 64));
881 make_dev(&stl_ops, minor_dev + 160,
882 UID_ROOT, GID_WHEEL, 0600,
883 "cuie%d", portnr + (boardnr * 64));
884 make_dev(&stl_ops, minor_dev + 192,
885 UID_ROOT, GID_WHEEL, 0600,
886 "cule%d", portnr + (boardnr * 64));
889 make_dev(&stl_ops, minor_dev + 0x10000,
890 UID_ROOT, GID_WHEEL, 0600,
891 "ttyE%d", portnr + (boardnr * 64) + 32);
892 make_dev(&stl_ops, minor_dev + 32 + 0x10000,
893 UID_ROOT, GID_WHEEL, 0600,
894 "ttyiE%d", portnr + (boardnr * 64) + 32);
895 make_dev(&stl_ops, minor_dev + 64 + 0x10000,
896 UID_ROOT, GID_WHEEL, 0600,
897 "ttylE%d", portnr + (boardnr * 64) + 32);
898 make_dev(&stl_ops, minor_dev + 128 + 0x10000,
899 UID_ROOT, GID_WHEEL, 0600,
900 "cue%d", portnr + (boardnr * 64) + 32);
901 make_dev(&stl_ops, minor_dev + 160 + 0x10000,
902 UID_ROOT, GID_WHEEL, 0600,
903 "cuie%d", portnr + (boardnr * 64) + 32);
904 make_dev(&stl_ops, minor_dev + 192 + 0x10000,
905 UID_ROOT, GID_WHEEL, 0600,
906 "cule%d", portnr + (boardnr * 64) + 32);
910 /*****************************************************************************/
912 static int stlopen(struct dev_open_args *ap)
914 cdev_t dev = ap->a_head.a_dev;
920 kprintf("stlopen(dev=%x,flag=%x,mode=%x,p=%x)\n", (int) dev, flag,
925 * Firstly check if the supplied device number is a valid device.
927 if (minor(dev) & STL_MEMDEV)
930 portp = stl_dev2port(dev);
933 if (minor(dev) & STL_CTRLDEV)
937 callout = minor(dev) & STL_CALLOUTDEV;
944 * Wait here for the DTR drop timeout period to expire.
946 while (portp->state & ASY_DTRWAIT) {
947 error = tsleep(&portp->dtrwait, PCATCH, "stldtr", 0);
953 * We have a valid device, so now we check if it is already open.
954 * If not then initialize the port hardware and set up the tty
955 * struct as required.
957 if ((tp->t_state & TS_ISOPEN) == 0) {
958 tp->t_oproc = stl_start;
959 tp->t_stop = stl_stop;
960 tp->t_param = stl_param;
962 tp->t_termios = callout ? portp->initouttios :
966 if ((portp->sigs & TIOCM_CD) || callout)
967 (*linesw[tp->t_line].l_modem)(tp, 1);
970 if (portp->callout == 0) {
975 if (portp->callout != 0) {
976 if (ap->a_oflags & O_NONBLOCK) {
980 error = tsleep(&portp->callout,
981 PCATCH, "stlcall", 0);
984 goto stlopen_restart;
987 if ((tp->t_state & TS_XCLUDE) && priv_check_cred(ap->a_cred, PRIV_ROOT, 0)) {
994 * If this port is not the callout device and we do not have carrier
995 * then we need to sleep, waiting for it to be asserted.
997 if (((tp->t_state & TS_CARR_ON) == 0) && !callout &&
998 ((tp->t_cflag & CLOCAL) == 0) &&
999 ((ap->a_oflags & O_NONBLOCK) == 0)) {
1001 error = tsleep(TSA_CARR_ON(tp), PCATCH, "stldcd", 0);
1005 goto stlopen_restart;
1009 * Open the line discipline.
1011 error = (*linesw[tp->t_line].l_open)(dev, tp);
1012 stl_ttyoptim(portp, &tp->t_termios);
1013 if ((tp->t_state & TS_ISOPEN) && callout)
1017 * If for any reason we get to here and the port is not actually
1018 * open then close of the physical hardware - no point leaving it
1019 * active when the open failed...
1023 if (((tp->t_state & TS_ISOPEN) == 0) && (portp->waitopens == 0))
1024 stl_rawclose(portp);
1029 /*****************************************************************************/
1031 static int stlclose(struct dev_close_args *ap)
1033 cdev_t dev = ap->a_head.a_dev;
1038 kprintf("stlclose(dev=%s,flag=%x,mode=%x,p=%p)\n", devtoname(dev),
1039 flag, mode, (void *) p);
1042 if (minor(dev) & STL_MEMDEV)
1044 if (minor(dev) & STL_CTRLDEV)
1047 portp = stl_dev2port(dev);
1053 (*linesw[tp->t_line].l_close)(tp, ap->a_fflag);
1054 stl_ttyoptim(portp, &tp->t_termios);
1055 stl_rawclose(portp);
1061 /*****************************************************************************/
1063 static void stl_stop(struct tty *tp, int rw)
1066 kprintf("stl_stop(tp=%x,rw=%x)\n", (int) tp, rw);
1069 stl_flush((stlport_t *) tp, rw);
1072 /*****************************************************************************/
1074 static int stlioctl(struct dev_ioctl_args *ap)
1076 cdev_t dev = ap->a_head.a_dev;
1077 u_long cmd = ap->a_cmd;
1078 caddr_t data = ap->a_data;
1079 struct termios *newtios, *localtios;
1085 kprintf("stlioctl(dev=%s,cmd=%lx,data=%p,flag=%x)\n",
1086 devtoname(dev), cmd, (void *) data, ap->a_fflag);
1089 if (minor(dev) & STL_MEMDEV)
1090 return(stl_memioctl(dev, cmd, data, ap->a_fflag));
1092 portp = stl_dev2port(dev);
1099 * First up handle ioctls on the control devices.
1101 if (minor(dev) & STL_CTRLDEV) {
1102 if ((minor(dev) & STL_CTRLDEV) == STL_CTRLINIT)
1103 localtios = (minor(dev) & STL_CALLOUTDEV) ?
1104 &portp->initouttios : &portp->initintios;
1105 else if ((minor(dev) & STL_CTRLDEV) == STL_CTRLLOCK)
1106 localtios = (minor(dev) & STL_CALLOUTDEV) ?
1107 &portp->lockouttios : &portp->lockintios;
1113 if ((error = priv_check_cred(ap->a_cred, PRIV_ROOT, 0)) == 0)
1114 *localtios = *((struct termios *) data);
1117 *((struct termios *) data) = *localtios;
1120 *((int *) data) = TTYDISC;
1123 bzero(data, sizeof(struct winsize));
1133 * Deal with 4.3 compatibility issues if we have too...
1135 #if defined(COMPAT_43)
1137 struct termios tios;
1138 unsigned long oldcmd;
1140 tios = tp->t_termios;
1142 if ((error = ttsetcompat(tp, &cmd, data, &tios)))
1145 data = (caddr_t) &tios;
1150 * Carry out some pre-cmd processing work first...
1151 * Hmmm, not so sure we want this, disable for now...
1153 if ((cmd == TIOCSETA) || (cmd == TIOCSETAW) || (cmd == TIOCSETAF)) {
1154 newtios = (struct termios *) data;
1155 localtios = (minor(dev) & STL_CALLOUTDEV) ?
1156 &portp->lockouttios : &portp->lockintios;
1158 newtios->c_iflag = (tp->t_iflag & localtios->c_iflag) |
1159 (newtios->c_iflag & ~localtios->c_iflag);
1160 newtios->c_oflag = (tp->t_oflag & localtios->c_oflag) |
1161 (newtios->c_oflag & ~localtios->c_oflag);
1162 newtios->c_cflag = (tp->t_cflag & localtios->c_cflag) |
1163 (newtios->c_cflag & ~localtios->c_cflag);
1164 newtios->c_lflag = (tp->t_lflag & localtios->c_lflag) |
1165 (newtios->c_lflag & ~localtios->c_lflag);
1166 for (i = 0; (i < NCCS); i++) {
1167 if (localtios->c_cc[i] != 0)
1168 newtios->c_cc[i] = tp->t_cc[i];
1170 if (localtios->c_ispeed != 0)
1171 newtios->c_ispeed = tp->t_ispeed;
1172 if (localtios->c_ospeed != 0)
1173 newtios->c_ospeed = tp->t_ospeed;
1177 * Call the line discipline and the common command processing to
1178 * process this command (if they can).
1180 error = (*linesw[tp->t_line].l_ioctl)(tp, cmd, data,
1181 ap->a_fflag, ap->a_cred);
1182 if (error != ENOIOCTL)
1186 error = ttioctl(tp, cmd, data, ap->a_fflag);
1187 stl_ttyoptim(portp, &tp->t_termios);
1188 if (error != ENOIOCTL) {
1196 * Process local commands here. These are all commands that only we
1197 * can take care of (they all rely on actually doing something special
1198 * to the actual hardware).
1202 stl_sendbreak(portp, -1);
1205 stl_sendbreak(portp, -2);
1208 stl_setsignals(portp, 1, -1);
1211 stl_setsignals(portp, 0, -1);
1214 i = *((int *) data);
1215 stl_setsignals(portp, ((i & TIOCM_DTR) ? 1 : 0),
1216 ((i & TIOCM_RTS) ? 1 : 0));
1219 i = *((int *) data);
1220 stl_setsignals(portp, ((i & TIOCM_DTR) ? 1 : -1),
1221 ((i & TIOCM_RTS) ? 1 : -1));
1224 i = *((int *) data);
1225 stl_setsignals(portp, ((i & TIOCM_DTR) ? 0 : -1),
1226 ((i & TIOCM_RTS) ? 0 : -1));
1229 *((int *) data) = (stl_getsignals(portp) | TIOCM_LE);
1232 if ((error = priv_check_cred(ap->a_cred, PRIV_ROOT, 0)) == 0)
1233 portp->dtrwait = *((int *) data) * hz / 100;
1236 *((int *) data) = portp->dtrwait * 100 / hz;
1239 portp->dotimestamp = 1;
1240 *((struct timeval *) data) = portp->timestamp;
1250 /*****************************************************************************/
1253 * Convert the specified minor device number into a port struct
1254 * pointer. Return NULL if the device number is not a valid port.
1257 static stlport_t *stl_dev2port(cdev_t dev)
1261 brdp = stl_brds[MKDEV2BRD(dev)];
1264 return(brdp->ports[MKDEV2PORT(dev)]);
1267 /*****************************************************************************/
1270 * Initialize the port hardware. This involves enabling the transmitter
1271 * and receiver, setting the port configuration, and setting the initial
1275 static int stl_rawopen(stlport_t *portp)
1278 kprintf("stl_rawopen(portp=%p): brdnr=%d panelnr=%d portnr=%d\n",
1279 (void *) portp, portp->brdnr, portp->panelnr, portp->portnr);
1282 stl_setport(portp, &portp->tty.t_termios);
1283 portp->sigs = stl_getsignals(portp);
1284 stl_setsignals(portp, 1, 1);
1285 stl_enablerxtx(portp, 1, 1);
1286 stl_startrxtx(portp, 1, 0);
1290 /*****************************************************************************/
1293 * Shutdown the hardware of a port. Disable its transmitter and
1294 * receiver, and maybe drop signals if appropriate.
1297 static int stl_rawclose(stlport_t *portp)
1302 kprintf("stl_rawclose(portp=%p): brdnr=%d panelnr=%d portnr=%d\n",
1303 (void *) portp, portp->brdnr, portp->panelnr, portp->portnr);
1307 stl_disableintrs(portp);
1308 stl_enablerxtx(portp, 0, 0);
1309 stl_flush(portp, (FWRITE | FREAD));
1310 if (tp->t_cflag & HUPCL) {
1311 stl_setsignals(portp, 0, 0);
1312 if (portp->dtrwait != 0) {
1313 portp->state |= ASY_DTRWAIT;
1314 callout_reset(&portp->dtr_ch, portp->dtrwait,
1315 stl_dtrwakeup, portp);
1320 portp->state &= ~(ASY_ACTIVE | ASY_RTSFLOW);
1321 wakeup(&portp->callout);
1322 wakeup(TSA_CARR_ON(tp));
1326 /*****************************************************************************/
1329 * Clear the DTR waiting flag, and wake up any sleepers waiting for
1330 * DTR wait period to finish.
1333 static void stl_dtrwakeup(void *arg)
1337 portp = (stlport_t *) arg;
1338 portp->state &= ~ASY_DTRWAIT;
1339 wakeup(&portp->dtrwait);
1342 /*****************************************************************************/
1345 * Start (or continue) the transfer of TX data on this port. If the
1346 * port is not currently busy then load up the interrupt ring queue
1347 * buffer and kick of the transmitter. If the port is running low on
1348 * TX data then refill the ring queue. This routine is also used to
1349 * activate input flow control!
1352 static void stl_start(struct tty *tp)
1355 unsigned int len, stlen;
1359 portp = (stlport_t *) tp;
1362 kprintf("stl_start(tp=%x): brdnr=%d portnr=%d\n", (int) tp,
1363 portp->brdnr, portp->portnr);
1369 * Check if the ports input has been blocked, and take appropriate action.
1370 * Not very often do we really need to do anything, so make it quick.
1372 if (tp->t_state & TS_TBLOCK) {
1373 if ((portp->state & ASY_RTSFLOWMODE) &&
1374 ((portp->state & ASY_RTSFLOW) == 0))
1375 stl_flowcontrol(portp, 0, -1);
1377 if (portp->state & ASY_RTSFLOW)
1378 stl_flowcontrol(portp, 1, -1);
1381 if (tp->t_state & (TS_TIMEOUT | TS_TTSTOP)) {
1387 * Copy data from the clists into the interrupt ring queue. This will
1388 * require at most 2 copys... What we do is calculate how many chars
1389 * can fit into the ring queue, and how many can fit in 1 copy. If after
1390 * the first copy there is still more room then do the second copy.
1391 * The beauty of this type of ring queue is that we do not need to
1392 * spl protect our-selves, since we only ever update the head pointer,
1393 * and the interrupt routine only ever updates the tail pointer.
1395 if (tp->t_outq.c_cc != 0) {
1396 head = portp->tx.head;
1397 tail = portp->tx.tail;
1399 len = STL_TXBUFSIZE - (head - tail) - 1;
1400 stlen = portp->tx.endbuf - head;
1402 len = tail - head - 1;
1407 stlen = MIN(len, stlen);
1408 count = q_to_b(&tp->t_outq, head, stlen);
1411 if (head >= portp->tx.endbuf) {
1412 head = portp->tx.buf;
1414 stlen = q_to_b(&tp->t_outq, head, len);
1419 portp->tx.head = head;
1421 stl_startrxtx(portp, -1, 1);
1425 * If we sent something, make sure we are called again.
1427 tp->t_state |= TS_BUSY;
1431 * Do any writer wakeups.
1438 /*****************************************************************************/
1440 static void stl_flush(stlport_t *portp, int flag)
1446 kprintf("stl_flush(portp=%x,flag=%x)\n", (int) portp, flag);
1454 if (flag & FWRITE) {
1455 stl_uartflush(portp, FWRITE);
1456 portp->tx.tail = portp->tx.head;
1460 * The only thing to watch out for when flushing the read side is
1461 * the RX status buffer. The interrupt code relys on the status
1462 * bytes as being zeroed all the time (it does not bother setting
1463 * a good char status to 0, it expects that it already will be).
1464 * We also need to un-flow the RX channel if flow control was
1468 head = portp->rx.head;
1469 tail = portp->rx.tail;
1474 len = portp->rx.endbuf - tail;
1475 bzero(portp->rxstatus.buf,
1476 (head - portp->rx.buf));
1478 bzero((tail + STL_RXBUFSIZE), len);
1479 portp->rx.tail = head;
1482 if ((portp->state & ASY_RTSFLOW) &&
1483 ((portp->tty.t_state & TS_TBLOCK) == 0))
1484 stl_flowcontrol(portp, 1, -1);
1490 /*****************************************************************************/
1493 * Interrupt handler for host based boards. Interrupts for all boards
1494 * are vectored through here.
1497 void stlintr(void *arg)
1503 kprintf("stlintr(unit=%d)\n", (int)arg);
1506 for (i = 0; (i < stl_nrbrds); i++) {
1507 if ((brdp = stl_brds[i]) == NULL)
1509 if (brdp->state == 0)
1511 (* brdp->isr)(brdp);
1515 /*****************************************************************************/
1517 static void stlpciintr(void *arg)
1522 /*****************************************************************************/
1525 * Interrupt service routine for EasyIO boards.
1528 static void stl_eiointr(stlbrd_t *brdp)
1534 kprintf("stl_eiointr(brdp=%p)\n", brdp);
1537 panelp = brdp->panels[0];
1538 iobase = panelp->iobase;
1539 while (inb(brdp->iostatus) & EIO_INTRPEND)
1540 (* panelp->isr)(panelp, iobase);
1544 * Interrupt service routine for ECH-AT board types.
1547 static void stl_echatintr(stlbrd_t *brdp)
1550 unsigned int ioaddr;
1553 outb(brdp->ioctrl, (brdp->ioctrlval | ECH_BRDENABLE));
1555 while (inb(brdp->iostatus) & ECH_INTRPEND) {
1556 for (bnknr = 0; (bnknr < brdp->nrbnks); bnknr++) {
1557 ioaddr = brdp->bnkstataddr[bnknr];
1558 if (inb(ioaddr) & ECH_PNLINTRPEND) {
1559 panelp = brdp->bnk2panel[bnknr];
1560 (* panelp->isr)(panelp, (ioaddr & 0xfffc));
1565 outb(brdp->ioctrl, (brdp->ioctrlval | ECH_BRDDISABLE));
1568 /*****************************************************************************/
1571 * Interrupt service routine for ECH-MCA board types.
1574 static void stl_echmcaintr(stlbrd_t *brdp)
1577 unsigned int ioaddr;
1580 while (inb(brdp->iostatus) & ECH_INTRPEND) {
1581 for (bnknr = 0; (bnknr < brdp->nrbnks); bnknr++) {
1582 ioaddr = brdp->bnkstataddr[bnknr];
1583 if (inb(ioaddr) & ECH_PNLINTRPEND) {
1584 panelp = brdp->bnk2panel[bnknr];
1585 (* panelp->isr)(panelp, (ioaddr & 0xfffc));
1591 /*****************************************************************************/
1594 * Interrupt service routine for ECH-PCI board types.
1597 static void stl_echpciintr(stlbrd_t *brdp)
1600 unsigned int ioaddr;
1604 kprintf("stl_echpciintr(brdp=%x)\n", (int) brdp);
1609 for (bnknr = 0; (bnknr < brdp->nrbnks); bnknr++) {
1610 outb(brdp->ioctrl, brdp->bnkpageaddr[bnknr]);
1611 ioaddr = brdp->bnkstataddr[bnknr];
1612 if (inb(ioaddr) & ECH_PNLINTRPEND) {
1613 panelp = brdp->bnk2panel[bnknr];
1614 (* panelp->isr)(panelp, (ioaddr & 0xfffc));
1623 /*****************************************************************************/
1626 * Interrupt service routine for EC8/64-PCI board types.
1629 static void stl_echpci64intr(stlbrd_t *brdp)
1632 unsigned int ioaddr;
1636 kprintf("stl_echpci64intr(brdp=%p)\n", brdp);
1639 while (inb(brdp->ioctrl) & 0x1) {
1640 for (bnknr = 0; (bnknr < brdp->nrbnks); bnknr++) {
1641 ioaddr = brdp->bnkstataddr[bnknr];
1643 kprintf(" --> ioaddr=%x status=%x(%x)\n", ioaddr, inb(ioaddr) & ECH_PNLINTRPEND, inb(ioaddr));
1645 if (inb(ioaddr) & ECH_PNLINTRPEND) {
1646 panelp = brdp->bnk2panel[bnknr];
1647 (* panelp->isr)(panelp, (ioaddr & 0xfffc));
1653 /*****************************************************************************/
1656 * If we haven't scheduled a timeout then do it, some port needs high
1660 static void stl_dotimeout(void)
1663 kprintf("stl_dotimeout()\n");
1665 if (stl_doingtimeout == 0) {
1666 if ((stl_poll_ch.c_flags & CALLOUT_DID_INIT) == 0)
1667 callout_init(&stl_poll_ch);
1668 callout_reset(&stl_poll_ch, 1, stl_poll, NULL);
1673 /*****************************************************************************/
1676 * Service "software" level processing. Too slow or painfull to be done
1677 * at real hardware interrupt time. This way we might also be able to
1678 * do some service on other waiting ports as well...
1681 static void stl_poll(void *arg)
1686 int brdnr, portnr, rearm;
1689 kprintf("stl_poll()\n");
1692 stl_doingtimeout = 0;
1696 for (brdnr = 0; (brdnr < stl_nrbrds); brdnr++) {
1697 if ((brdp = stl_brds[brdnr]) == NULL)
1699 for (portnr = 0; (portnr < brdp->nrports); portnr++) {
1700 if ((portp = brdp->ports[portnr]) == NULL)
1702 if ((portp->state & ASY_ACTIVE) == 0)
1706 if (portp->state & ASY_RXDATA)
1707 stl_rxprocess(portp);
1708 if (portp->state & ASY_DCDCHANGE) {
1709 portp->state &= ~ASY_DCDCHANGE;
1710 portp->sigs = stl_getsignals(portp);
1711 (*linesw[tp->t_line].l_modem)(tp,
1712 (portp->sigs & TIOCM_CD));
1714 if (portp->state & ASY_TXEMPTY) {
1715 if (stl_datastate(portp) == 0) {
1716 portp->state &= ~ASY_TXEMPTY;
1717 tp->t_state &= ~TS_BUSY;
1718 (*linesw[tp->t_line].l_start)(tp);
1721 if (portp->state & ASY_TXLOW) {
1722 portp->state &= ~ASY_TXLOW;
1723 (*linesw[tp->t_line].l_start)(tp);
1726 if (portp->state & ASY_ACTIVE)
1736 /*****************************************************************************/
1739 * Process the RX data that has been buffered up in the RX ring queue.
1742 static void stl_rxprocess(stlport_t *portp)
1745 unsigned int len, stlen, lostlen;
1751 kprintf("stl_rxprocess(portp=%x): brdnr=%d portnr=%d\n", (int) portp,
1752 portp->brdnr, portp->portnr);
1756 portp->state &= ~ASY_RXDATA;
1758 if ((tp->t_state & TS_ISOPEN) == 0) {
1759 stl_flush(portp, FREAD);
1764 * Calculate the amount of data in the RX ring queue. Also calculate
1765 * the largest single copy size...
1767 head = portp->rx.head;
1768 tail = portp->rx.tail;
1773 len = STL_RXBUFSIZE - (tail - head);
1774 stlen = portp->rx.endbuf - tail;
1777 if (tp->t_state & TS_CAN_BYPASS_L_RINT) {
1779 if (((tp->t_rawq.c_cc + len) >= TTYHOG) &&
1780 ((portp->state & ASY_RTSFLOWMODE) ||
1781 (tp->t_iflag & IXOFF)) &&
1782 ((tp->t_state & TS_TBLOCK) == 0)) {
1783 ch = TTYHOG - tp->t_rawq.c_cc - 1;
1784 len = (ch > 0) ? ch : 0;
1785 stlen = MIN(stlen, len);
1788 lostlen = b_to_q(tail, stlen, &tp->t_rawq);
1791 if (tail >= portp->rx.endbuf) {
1792 tail = portp->rx.buf;
1793 lostlen += b_to_q(tail, len, &tp->t_rawq);
1796 portp->stats.rxlost += lostlen;
1798 portp->rx.tail = tail;
1801 while (portp->rx.tail != head) {
1802 ch = (unsigned char) *(portp->rx.tail);
1803 status = *(portp->rx.tail + STL_RXBUFSIZE);
1805 *(portp->rx.tail + STL_RXBUFSIZE) = 0;
1806 if (status & ST_BREAK)
1808 if (status & ST_FRAMING)
1810 if (status & ST_PARITY)
1812 if (status & ST_OVERRUN)
1815 (*linesw[tp->t_line].l_rint)(ch, tp);
1816 if (portp->rx.tail == head)
1819 if (++(portp->rx.tail) >= portp->rx.endbuf)
1820 portp->rx.tail = portp->rx.buf;
1824 if (head != portp->rx.tail)
1825 portp->state |= ASY_RXDATA;
1828 * If we were flow controled then maybe the buffer is low enough that
1829 * we can re-activate it.
1831 if ((portp->state & ASY_RTSFLOW) && ((tp->t_state & TS_TBLOCK) == 0))
1832 stl_flowcontrol(portp, 1, -1);
1835 /*****************************************************************************/
1837 static int stl_param(struct tty *tp, struct termios *tiosp)
1841 portp = (stlport_t *) tp;
1845 return(stl_setport(portp, tiosp));
1848 /*****************************************************************************/
1851 * Action the flow control as required. The hw and sw args inform the
1852 * routine what flow control methods it should try.
1855 static void stl_flowcontrol(stlport_t *portp, int hw, int sw)
1857 unsigned char *head, *tail;
1861 kprintf("stl_flowcontrol(portp=%x,hw=%d,sw=%d)\n", (int) portp, hw, sw);
1866 if (portp->state & ASY_RTSFLOWMODE) {
1868 if ((portp->state & ASY_RTSFLOW) == 0)
1870 } else if (hw > 0) {
1871 if (portp->state & ASY_RTSFLOW) {
1872 head = portp->rx.head;
1873 tail = portp->rx.tail;
1874 len = (head >= tail) ? (head - tail) :
1875 (STL_RXBUFSIZE - (tail - head));
1876 if (len < STL_RXBUFHIGH)
1883 * We have worked out what to do, if anything. So now apply it to the
1886 stl_sendflow(portp, hwflow, sw);
1889 /*****************************************************************************/
1892 * Enable l_rint processing bypass mode if tty modes allow it.
1895 static void stl_ttyoptim(stlport_t *portp, struct termios *tiosp)
1900 if (((tiosp->c_iflag &
1901 (ICRNL | IGNCR | IMAXBEL | INLCR | ISTRIP)) == 0) &&
1902 (((tiosp->c_iflag & BRKINT) == 0) || (tiosp->c_iflag & IGNBRK)) &&
1903 (((tiosp->c_iflag & PARMRK) == 0) ||
1904 ((tiosp->c_iflag & (IGNPAR | IGNBRK)) == (IGNPAR | IGNBRK))) &&
1905 ((tiosp->c_lflag & (ECHO | ICANON | IEXTEN | ISIG | PENDIN)) ==0) &&
1906 (linesw[tp->t_line].l_rint == ttyinput))
1907 tp->t_state |= TS_CAN_BYPASS_L_RINT;
1909 tp->t_state &= ~TS_CAN_BYPASS_L_RINT;
1910 portp->hotchar = linesw[tp->t_line].l_hotchar;
1913 /*****************************************************************************/
1916 * Try and find and initialize all the ports on a panel. We don't care
1917 * what sort of board these ports are on - since the port io registers
1918 * are almost identical when dealing with ports.
1921 static int stl_initports(stlbrd_t *brdp, stlpanel_t *panelp)
1927 kprintf("stl_initports(panelp=%x)\n", (int) panelp);
1931 * All UART's are initialized if found. Now go through and setup
1932 * each ports data structures. Also initialize each individual
1935 for (i = 0; (i < panelp->nrports); i++) {
1936 portp = kmalloc(sizeof(stlport_t), M_TTYS, M_WAITOK | M_ZERO);
1939 portp->brdnr = panelp->brdnr;
1940 portp->panelnr = panelp->panelnr;
1941 portp->uartp = panelp->uartp;
1942 portp->clk = brdp->clk;
1943 panelp->ports[i] = portp;
1945 j = STL_TXBUFSIZE + (2 * STL_RXBUFSIZE);
1946 portp->tx.buf = kmalloc(j, M_TTYS, M_WAITOK);
1947 portp->tx.endbuf = portp->tx.buf + STL_TXBUFSIZE;
1948 portp->tx.head = portp->tx.buf;
1949 portp->tx.tail = portp->tx.buf;
1950 portp->rx.buf = portp->tx.buf + STL_TXBUFSIZE;
1951 portp->rx.endbuf = portp->rx.buf + STL_RXBUFSIZE;
1952 portp->rx.head = portp->rx.buf;
1953 portp->rx.tail = portp->rx.buf;
1954 portp->rxstatus.buf = portp->rx.buf + STL_RXBUFSIZE;
1955 portp->rxstatus.endbuf = portp->rxstatus.buf + STL_RXBUFSIZE;
1956 portp->rxstatus.head = portp->rxstatus.buf;
1957 portp->rxstatus.tail = portp->rxstatus.buf;
1958 bzero(portp->rxstatus.head, STL_RXBUFSIZE);
1960 portp->initintios.c_ispeed = STL_DEFSPEED;
1961 portp->initintios.c_ospeed = STL_DEFSPEED;
1962 portp->initintios.c_cflag = STL_DEFCFLAG;
1963 portp->initintios.c_iflag = 0;
1964 portp->initintios.c_oflag = 0;
1965 portp->initintios.c_lflag = 0;
1966 bcopy(&ttydefchars[0], &portp->initintios.c_cc[0],
1967 sizeof(portp->initintios.c_cc));
1968 portp->initouttios = portp->initintios;
1969 portp->dtrwait = 3 * hz;
1970 callout_init(&portp->dtr_ch);
1972 stl_portinit(brdp, panelp, portp);
1978 /*****************************************************************************/
1981 * Try to find and initialize an EasyIO board.
1984 static int stl_initeio(stlbrd_t *brdp)
1987 unsigned int status;
1990 kprintf("stl_initeio(brdp=%x)\n", (int) brdp);
1993 brdp->ioctrl = brdp->ioaddr1 + 1;
1994 brdp->iostatus = brdp->ioaddr1 + 2;
1995 brdp->clk = EIO_CLK;
1996 brdp->isr = stl_eiointr;
1998 status = inb(brdp->iostatus);
1999 switch (status & EIO_IDBITMASK) {
2001 brdp->clk = EIO_CLK8M;
2011 switch (status & EIO_BRDMASK) {
2030 if (brdp->brdtype == BRD_EASYIOPCI) {
2031 outb((brdp->ioaddr2 + 0x4c), 0x41);
2034 * Check that the supplied IRQ is good and then use it to setup the
2035 * programmable interrupt bits on EIO board. Also set the edge/level
2036 * triggered interrupt bit.
2038 if ((brdp->irq < 0) || (brdp->irq > 15) ||
2039 (stl_vecmap[brdp->irq] == (unsigned char) 0xff)) {
2040 kprintf("STALLION: invalid irq=%d for brd=%d\n",
2041 brdp->irq, brdp->brdnr);
2044 outb(brdp->ioctrl, (stl_vecmap[brdp->irq] |
2045 ((brdp->irqtype) ? EIO_INTLEVEL : EIO_INTEDGE)));
2048 panelp = kmalloc(sizeof(stlpanel_t), M_TTYS, M_WAITOK | M_ZERO);
2049 panelp->brdnr = brdp->brdnr;
2050 panelp->panelnr = 0;
2051 panelp->nrports = brdp->nrports;
2052 panelp->iobase = brdp->ioaddr1;
2053 panelp->hwid = status;
2054 if ((status & EIO_IDBITMASK) == EIO_MK3) {
2055 panelp->uartp = (void *) &stl_sc26198uart;
2056 panelp->isr = stl_sc26198intr;
2058 panelp->uartp = (void *) &stl_cd1400uart;
2059 panelp->isr = stl_cd1400eiointr;
2061 brdp->panels[0] = panelp;
2063 brdp->hwid = status;
2064 brdp->state |= BRD_FOUND;
2068 /*****************************************************************************/
2071 * Try to find an ECH board and initialize it. This code is capable of
2072 * dealing with all types of ECH board.
2075 static int stl_initech(stlbrd_t *brdp)
2078 unsigned int status, nxtid;
2079 int panelnr, ioaddr, banknr, i;
2082 kprintf("stl_initech(brdp=%x)\n", (int) brdp);
2086 * Set up the initial board register contents for boards. This varys a
2087 * bit between the different board types. So we need to handle each
2088 * separately. Also do a check that the supplied IRQ is good.
2090 switch (brdp->brdtype) {
2093 brdp->isr = stl_echatintr;
2094 brdp->ioctrl = brdp->ioaddr1 + 1;
2095 brdp->iostatus = brdp->ioaddr1 + 1;
2096 status = inb(brdp->iostatus);
2097 if ((status & ECH_IDBITMASK) != ECH_ID)
2099 brdp->hwid = status;
2101 if ((brdp->irq < 0) || (brdp->irq > 15) ||
2102 (stl_vecmap[brdp->irq] == (unsigned char) 0xff)) {
2103 kprintf("STALLION: invalid irq=%d for brd=%d\n",
2104 brdp->irq, brdp->brdnr);
2107 status = ((brdp->ioaddr2 & ECH_ADDR2MASK) >> 1);
2108 status |= (stl_vecmap[brdp->irq] << 1);
2109 outb(brdp->ioaddr1, (status | ECH_BRDRESET));
2110 brdp->ioctrlval = ECH_INTENABLE |
2111 ((brdp->irqtype) ? ECH_INTLEVEL : ECH_INTEDGE);
2112 outb(brdp->ioctrl, (brdp->ioctrlval | ECH_BRDENABLE));
2113 outb(brdp->ioaddr1, status);
2117 brdp->isr = stl_echmcaintr;
2118 brdp->ioctrl = brdp->ioaddr1 + 0x20;
2119 brdp->iostatus = brdp->ioctrl;
2120 status = inb(brdp->iostatus);
2121 if ((status & ECH_IDBITMASK) != ECH_ID)
2123 brdp->hwid = status;
2125 if ((brdp->irq < 0) || (brdp->irq > 15) ||
2126 (stl_vecmap[brdp->irq] == (unsigned char) 0xff)) {
2127 kprintf("STALLION: invalid irq=%d for brd=%d\n",
2128 brdp->irq, brdp->brdnr);
2131 outb(brdp->ioctrl, ECHMC_BRDRESET);
2132 outb(brdp->ioctrl, ECHMC_INTENABLE);
2136 brdp->isr = stl_echpciintr;
2137 brdp->ioctrl = brdp->ioaddr1 + 2;
2141 brdp->isr = stl_echpci64intr;
2142 brdp->ioctrl = brdp->ioaddr2 + 0x40;
2143 outb((brdp->ioaddr1 + 0x4c), 0x43);
2147 kprintf("STALLION: unknown board type=%d\n", brdp->brdtype);
2151 brdp->clk = ECH_CLK;
2154 * Scan through the secondary io address space looking for panels.
2155 * As we find'em allocate and initialize panel structures for each.
2157 ioaddr = brdp->ioaddr2;
2162 for (i = 0; (i < STL_MAXPANELS); i++) {
2163 if (brdp->brdtype == BRD_ECHPCI) {
2164 outb(brdp->ioctrl, nxtid);
2165 ioaddr = brdp->ioaddr2;
2167 status = inb(ioaddr + ECH_PNLSTATUS);
2168 if ((status & ECH_PNLIDMASK) != nxtid)
2170 panelp = kmalloc(sizeof(stlpanel_t), M_TTYS, M_WAITOK | M_ZERO);
2171 panelp->brdnr = brdp->brdnr;
2172 panelp->panelnr = panelnr;
2173 panelp->iobase = ioaddr;
2174 panelp->pagenr = nxtid;
2175 panelp->hwid = status;
2176 brdp->bnk2panel[banknr] = panelp;
2177 brdp->bnkpageaddr[banknr] = nxtid;
2178 brdp->bnkstataddr[banknr++] = ioaddr + ECH_PNLSTATUS;
2180 if (status & ECH_PNLXPID) {
2181 panelp->uartp = (void *) &stl_sc26198uart;
2182 panelp->isr = stl_sc26198intr;
2183 if (status & ECH_PNL16PORT) {
2184 panelp->nrports = 16;
2185 brdp->bnk2panel[banknr] = panelp;
2186 brdp->bnkpageaddr[banknr] = nxtid;
2187 brdp->bnkstataddr[banknr++] = ioaddr + 4 +
2190 panelp->nrports = 8;
2193 panelp->uartp = (void *) &stl_cd1400uart;
2194 panelp->isr = stl_cd1400echintr;
2195 if (status & ECH_PNL16PORT) {
2196 panelp->nrports = 16;
2197 panelp->ackmask = 0x80;
2198 if (brdp->brdtype != BRD_ECHPCI)
2199 ioaddr += EREG_BANKSIZE;
2200 brdp->bnk2panel[banknr] = panelp;
2201 brdp->bnkpageaddr[banknr] = ++nxtid;
2202 brdp->bnkstataddr[banknr++] = ioaddr +
2205 panelp->nrports = 8;
2206 panelp->ackmask = 0xc0;
2211 ioaddr += EREG_BANKSIZE;
2212 brdp->nrports += panelp->nrports;
2213 brdp->panels[panelnr++] = panelp;
2214 if ((brdp->brdtype == BRD_ECH) || (brdp->brdtype == BRD_ECHMC)){
2215 if (ioaddr >= (brdp->ioaddr2 + 0x20)) {
2216 kprintf("STALLION: too many ports attached "
2217 "to board %d, remove last module\n",
2224 brdp->nrpanels = panelnr;
2225 brdp->nrbnks = banknr;
2226 if (brdp->brdtype == BRD_ECH)
2227 outb(brdp->ioctrl, (brdp->ioctrlval | ECH_BRDDISABLE));
2229 brdp->state |= BRD_FOUND;
2233 /*****************************************************************************/
2236 * Initialize and configure the specified board. This firstly probes
2237 * for the board, if it is found then the board is initialized and
2238 * then all its ports are initialized as well.
2241 static int stl_brdinit(stlbrd_t *brdp)
2247 kprintf("stl_brdinit(brdp=%x): unit=%d type=%d io1=%x io2=%x irq=%d\n",
2248 (int) brdp, brdp->brdnr, brdp->brdtype, brdp->ioaddr1,
2249 brdp->ioaddr2, brdp->irq);
2252 switch (brdp->brdtype) {
2264 kprintf("STALLION: unit=%d is unknown board type=%d\n",
2265 brdp->brdnr, brdp->brdtype);
2269 stl_brds[brdp->brdnr] = brdp;
2270 if ((brdp->state & BRD_FOUND) == 0) {
2272 kprintf("STALLION: %s board not found, unit=%d io=%x irq=%d\n",
2273 stl_brdnames[brdp->brdtype], brdp->brdnr,
2274 brdp->ioaddr1, brdp->irq);
2279 for (i = 0, k = 0; (i < STL_MAXPANELS); i++) {
2280 panelp = brdp->panels[i];
2281 if (panelp != NULL) {
2282 stl_initports(brdp, panelp);
2283 for (j = 0; (j < panelp->nrports); j++)
2284 brdp->ports[k++] = panelp->ports[j];
2288 kprintf("stl%d: %s (driver version %s) unit=%d nrpanels=%d nrports=%d\n",
2289 brdp->unitid, stl_brdnames[brdp->brdtype], stl_drvversion,
2290 brdp->brdnr, brdp->nrpanels, brdp->nrports);
2294 /*****************************************************************************/
2297 * Return the board stats structure to user app.
2300 static int stl_getbrdstats(caddr_t data)
2306 stl_brdstats = *((combrd_t *) data);
2307 if (stl_brdstats.brd >= STL_MAXBRDS)
2309 brdp = stl_brds[stl_brdstats.brd];
2313 bzero(&stl_brdstats, sizeof(combrd_t));
2314 stl_brdstats.brd = brdp->brdnr;
2315 stl_brdstats.type = brdp->brdtype;
2316 stl_brdstats.hwid = brdp->hwid;
2317 stl_brdstats.state = brdp->state;
2318 stl_brdstats.ioaddr = brdp->ioaddr1;
2319 stl_brdstats.ioaddr2 = brdp->ioaddr2;
2320 stl_brdstats.irq = brdp->irq;
2321 stl_brdstats.nrpanels = brdp->nrpanels;
2322 stl_brdstats.nrports = brdp->nrports;
2323 for (i = 0; (i < brdp->nrpanels); i++) {
2324 panelp = brdp->panels[i];
2325 stl_brdstats.panels[i].panel = i;
2326 stl_brdstats.panels[i].hwid = panelp->hwid;
2327 stl_brdstats.panels[i].nrports = panelp->nrports;
2330 *((combrd_t *) data) = stl_brdstats;
2334 /*****************************************************************************/
2337 * Resolve the referenced port number into a port struct pointer.
2340 static stlport_t *stl_getport(int brdnr, int panelnr, int portnr)
2345 if ((brdnr < 0) || (brdnr >= STL_MAXBRDS))
2347 brdp = stl_brds[brdnr];
2350 if ((panelnr < 0) || (panelnr >= brdp->nrpanels))
2352 panelp = brdp->panels[panelnr];
2355 if ((portnr < 0) || (portnr >= panelp->nrports))
2357 return(panelp->ports[portnr]);
2360 /*****************************************************************************/
2363 * Return the port stats structure to user app. A NULL port struct
2364 * pointer passed in means that we need to find out from the app
2365 * what port to get stats for (used through board control device).
2368 static int stl_getportstats(stlport_t *portp, caddr_t data)
2370 unsigned char *head, *tail;
2372 if (portp == NULL) {
2373 stl_comstats = *((comstats_t *) data);
2374 portp = stl_getport(stl_comstats.brd, stl_comstats.panel,
2380 portp->stats.state = portp->state;
2381 /*portp->stats.flags = portp->flags;*/
2382 portp->stats.hwid = portp->hwid;
2383 portp->stats.ttystate = portp->tty.t_state;
2384 portp->stats.cflags = portp->tty.t_cflag;
2385 portp->stats.iflags = portp->tty.t_iflag;
2386 portp->stats.oflags = portp->tty.t_oflag;
2387 portp->stats.lflags = portp->tty.t_lflag;
2389 head = portp->tx.head;
2390 tail = portp->tx.tail;
2391 portp->stats.txbuffered = ((head >= tail) ? (head - tail) :
2392 (STL_TXBUFSIZE - (tail - head)));
2394 head = portp->rx.head;
2395 tail = portp->rx.tail;
2396 portp->stats.rxbuffered = (head >= tail) ? (head - tail) :
2397 (STL_RXBUFSIZE - (tail - head));
2399 portp->stats.signals = (unsigned long) stl_getsignals(portp);
2401 *((comstats_t *) data) = portp->stats;
2405 /*****************************************************************************/
2408 * Clear the port stats structure. We also return it zeroed out...
2411 static int stl_clrportstats(stlport_t *portp, caddr_t data)
2413 if (portp == NULL) {
2414 stl_comstats = *((comstats_t *) data);
2415 portp = stl_getport(stl_comstats.brd, stl_comstats.panel,
2421 bzero(&portp->stats, sizeof(comstats_t));
2422 portp->stats.brd = portp->brdnr;
2423 portp->stats.panel = portp->panelnr;
2424 portp->stats.port = portp->portnr;
2425 *((comstats_t *) data) = stl_comstats;
2429 /*****************************************************************************/
2432 * The "staliomem" device is used for stats collection in this driver.
2435 static int stl_memioctl(cdev_t dev, unsigned long cmd, caddr_t data, int flag)
2440 kprintf("stl_memioctl(dev=%s,cmd=%lx,data=%p,flag=%x)\n",
2441 devtoname(dev), cmd, (void *) data, flag);
2447 case COM_GETPORTSTATS:
2448 rc = stl_getportstats(NULL, data);
2450 case COM_CLRPORTSTATS:
2451 rc = stl_clrportstats(NULL, data);
2453 case COM_GETBRDSTATS:
2454 rc = stl_getbrdstats(data);
2464 /*****************************************************************************/
2466 /*****************************************************************************/
2467 /* CD1400 UART CODE */
2468 /*****************************************************************************/
2471 * These functions get/set/update the registers of the cd1400 UARTs.
2472 * Access to the cd1400 registers is via an address/data io port pair.
2475 static int stl_cd1400getreg(stlport_t *portp, int regnr)
2477 outb(portp->ioaddr, (regnr + portp->uartaddr));
2478 return(inb(portp->ioaddr + EREG_DATA));
2481 /*****************************************************************************/
2483 static void stl_cd1400setreg(stlport_t *portp, int regnr, int value)
2485 outb(portp->ioaddr, (regnr + portp->uartaddr));
2486 outb((portp->ioaddr + EREG_DATA), value);
2489 /*****************************************************************************/
2491 static int stl_cd1400updatereg(stlport_t *portp, int regnr, int value)
2493 outb(portp->ioaddr, (regnr + portp->uartaddr));
2494 if (inb(portp->ioaddr + EREG_DATA) != value) {
2495 outb((portp->ioaddr + EREG_DATA), value);
2501 /*****************************************************************************/
2503 static void stl_cd1400flush(stlport_t *portp, int flag)
2507 kprintf("stl_cd1400flush(portp=%x,flag=%x)\n", (int) portp, flag);
2515 if (flag & FWRITE) {
2516 BRDENABLE(portp->brdnr, portp->pagenr);
2517 stl_cd1400setreg(portp, CAR, (portp->portnr & 0x03));
2518 stl_cd1400ccrwait(portp);
2519 stl_cd1400setreg(portp, CCR, CCR_TXFLUSHFIFO);
2520 stl_cd1400ccrwait(portp);
2521 BRDDISABLE(portp->brdnr);
2531 /*****************************************************************************/
2533 static void stl_cd1400ccrwait(stlport_t *portp)
2537 for (i = 0; (i < CCR_MAXWAIT); i++) {
2538 if (stl_cd1400getreg(portp, CCR) == 0)
2542 kprintf("stl%d: cd1400 device not responding, panel=%d port=%d\n",
2543 portp->brdnr, portp->panelnr, portp->portnr);
2546 /*****************************************************************************/
2549 * Transmit interrupt handler. This has gotta be fast! Handling TX
2550 * chars is pretty simple, stuff as many as possible from the TX buffer
2551 * into the cd1400 FIFO. Must also handle TX breaks here, since they
2552 * are embedded as commands in the data stream. Oh no, had to use a goto!
2555 static __inline void stl_cd1400txisr(stlpanel_t *panelp, int ioaddr)
2558 unsigned char ioack, srer;
2563 kprintf("stl_cd1400txisr(panelp=%x,ioaddr=%x)\n", (int) panelp, ioaddr);
2566 ioack = inb(ioaddr + EREG_TXACK);
2567 if (((ioack & panelp->ackmask) != 0) ||
2568 ((ioack & ACK_TYPMASK) != ACK_TYPTX)) {
2569 kprintf("STALLION: bad TX interrupt ack value=%x\n",
2573 portp = panelp->ports[(ioack >> 3)];
2576 * Unfortunately we need to handle breaks in the data stream, since
2577 * this is the only way to generate them on the cd1400. Do it now if
2578 * a break is to be sent. Some special cases here: brklen is -1 then
2579 * start sending an un-timed break, if brklen is -2 then stop sending
2580 * an un-timed break, if brklen is -3 then we have just sent an
2581 * un-timed break and do not want any data to go out, if brklen is -4
2582 * then a break has just completed so clean up the port settings.
2584 if (portp->brklen != 0) {
2585 if (portp->brklen >= -1) {
2586 outb(ioaddr, (TDR + portp->uartaddr));
2587 outb((ioaddr + EREG_DATA), ETC_CMD);
2588 outb((ioaddr + EREG_DATA), ETC_STARTBREAK);
2589 if (portp->brklen > 0) {
2590 outb((ioaddr + EREG_DATA), ETC_CMD);
2591 outb((ioaddr + EREG_DATA), ETC_DELAY);
2592 outb((ioaddr + EREG_DATA), portp->brklen);
2593 outb((ioaddr + EREG_DATA), ETC_CMD);
2594 outb((ioaddr + EREG_DATA), ETC_STOPBREAK);
2599 } else if (portp->brklen == -2) {
2600 outb(ioaddr, (TDR + portp->uartaddr));
2601 outb((ioaddr + EREG_DATA), ETC_CMD);
2602 outb((ioaddr + EREG_DATA), ETC_STOPBREAK);
2604 } else if (portp->brklen == -3) {
2605 outb(ioaddr, (SRER + portp->uartaddr));
2606 srer = inb(ioaddr + EREG_DATA);
2607 srer &= ~(SRER_TXDATA | SRER_TXEMPTY);
2608 outb((ioaddr + EREG_DATA), srer);
2610 outb(ioaddr, (COR2 + portp->uartaddr));
2611 outb((ioaddr + EREG_DATA),
2612 (inb(ioaddr + EREG_DATA) & ~COR2_ETC));
2618 head = portp->tx.head;
2619 tail = portp->tx.tail;
2620 len = (head >= tail) ? (head - tail) : (STL_TXBUFSIZE - (tail - head));
2621 if ((len == 0) || ((len < STL_TXBUFLOW) &&
2622 ((portp->state & ASY_TXLOW) == 0))) {
2623 portp->state |= ASY_TXLOW;
2628 outb(ioaddr, (SRER + portp->uartaddr));
2629 srer = inb(ioaddr + EREG_DATA);
2630 if (srer & SRER_TXDATA) {
2631 srer = (srer & ~SRER_TXDATA) | SRER_TXEMPTY;
2633 srer &= ~(SRER_TXDATA | SRER_TXEMPTY);
2634 portp->state |= ASY_TXEMPTY;
2635 portp->state &= ~ASY_TXBUSY;
2637 outb((ioaddr + EREG_DATA), srer);
2639 len = MIN(len, CD1400_TXFIFOSIZE);
2640 portp->stats.txtotal += len;
2641 stlen = MIN(len, (portp->tx.endbuf - tail));
2642 outb(ioaddr, (TDR + portp->uartaddr));
2643 outsb((ioaddr + EREG_DATA), tail, stlen);
2646 if (tail >= portp->tx.endbuf)
2647 tail = portp->tx.buf;
2649 outsb((ioaddr + EREG_DATA), tail, len);
2652 portp->tx.tail = tail;
2656 outb(ioaddr, (EOSRR + portp->uartaddr));
2657 outb((ioaddr + EREG_DATA), 0);
2660 /*****************************************************************************/
2663 * Receive character interrupt handler. Determine if we have good chars
2664 * or bad chars and then process appropriately.
2667 static __inline void stl_cd1400rxisr(stlpanel_t *panelp, int ioaddr)
2671 unsigned int ioack, len, buflen, stlen;
2672 unsigned char status;
2677 kprintf("stl_cd1400rxisr(panelp=%x,ioaddr=%x)\n", (int) panelp, ioaddr);
2680 ioack = inb(ioaddr + EREG_RXACK);
2681 if ((ioack & panelp->ackmask) != 0) {
2682 kprintf("STALLION: bad RX interrupt ack value=%x\n", ioack);
2685 portp = panelp->ports[(ioack >> 3)];
2689 * First up, calculate how much room there is in the RX ring queue.
2690 * We also want to keep track of the longest possible copy length,
2691 * this has to allow for the wrapping of the ring queue.
2693 head = portp->rx.head;
2694 tail = portp->rx.tail;
2696 buflen = STL_RXBUFSIZE - (head - tail) - 1;
2697 stlen = portp->rx.endbuf - head;
2699 buflen = tail - head - 1;
2704 * Check if the input buffer is near full. If so then we should take
2705 * some flow control action... It is very easy to do hardware and
2706 * software flow control from here since we have the port selected on
2709 if (buflen <= (STL_RXBUFSIZE - STL_RXBUFHIGH)) {
2710 if (((portp->state & ASY_RTSFLOW) == 0) &&
2711 (portp->state & ASY_RTSFLOWMODE)) {
2712 portp->state |= ASY_RTSFLOW;
2713 stl_cd1400setreg(portp, MCOR1,
2714 (stl_cd1400getreg(portp, MCOR1) & 0xf0));
2715 stl_cd1400setreg(portp, MSVR2, 0);
2716 portp->stats.rxrtsoff++;
2721 * OK we are set, process good data... If the RX ring queue is full
2722 * just chuck the chars - don't leave them in the UART.
2724 if ((ioack & ACK_TYPMASK) == ACK_TYPRXGOOD) {
2725 outb(ioaddr, (RDCR + portp->uartaddr));
2726 len = inb(ioaddr + EREG_DATA);
2728 outb(ioaddr, (RDSR + portp->uartaddr));
2729 insb((ioaddr + EREG_DATA), &stl_unwanted[0], len);
2730 portp->stats.rxlost += len;
2731 portp->stats.rxtotal += len;
2733 len = MIN(len, buflen);
2734 portp->stats.rxtotal += len;
2735 stlen = MIN(len, stlen);
2737 outb(ioaddr, (RDSR + portp->uartaddr));
2738 insb((ioaddr + EREG_DATA), head, stlen);
2740 if (head >= portp->rx.endbuf) {
2741 head = portp->rx.buf;
2743 insb((ioaddr + EREG_DATA), head, len);
2748 } else if ((ioack & ACK_TYPMASK) == ACK_TYPRXBAD) {
2749 outb(ioaddr, (RDSR + portp->uartaddr));
2750 status = inb(ioaddr + EREG_DATA);
2751 ch = inb(ioaddr + EREG_DATA);
2752 if (status & ST_BREAK)
2753 portp->stats.rxbreaks++;
2754 if (status & ST_FRAMING)
2755 portp->stats.rxframing++;
2756 if (status & ST_PARITY)
2757 portp->stats.rxparity++;
2758 if (status & ST_OVERRUN)
2759 portp->stats.rxoverrun++;
2760 if (status & ST_SCHARMASK) {
2761 if ((status & ST_SCHARMASK) == ST_SCHAR1)
2762 portp->stats.txxon++;
2763 if ((status & ST_SCHARMASK) == ST_SCHAR2)
2764 portp->stats.txxoff++;
2767 if ((portp->rxignoremsk & status) == 0) {
2768 if ((tp->t_state & TS_CAN_BYPASS_L_RINT) &&
2769 ((status & ST_FRAMING) ||
2770 ((status & ST_PARITY) && (tp->t_iflag & INPCK))))
2772 if ((portp->rxmarkmsk & status) == 0)
2774 *(head + STL_RXBUFSIZE) = status;
2776 if (head >= portp->rx.endbuf)
2777 head = portp->rx.buf;
2780 kprintf("STALLION: bad RX interrupt ack value=%x\n", ioack);
2784 portp->rx.head = head;
2785 portp->state |= ASY_RXDATA;
2789 outb(ioaddr, (EOSRR + portp->uartaddr));
2790 outb((ioaddr + EREG_DATA), 0);
2793 /*****************************************************************************/
2796 * Modem interrupt handler. The is called when the modem signal line
2797 * (DCD) has changed state.
2800 static __inline void stl_cd1400mdmisr(stlpanel_t *panelp, int ioaddr)
2807 kprintf("stl_cd1400mdmisr(panelp=%x,ioaddr=%x)\n", (int) panelp, ioaddr);
2810 ioack = inb(ioaddr + EREG_MDACK);
2811 if (((ioack & panelp->ackmask) != 0) ||
2812 ((ioack & ACK_TYPMASK) != ACK_TYPMDM)) {
2813 kprintf("STALLION: bad MODEM interrupt ack value=%x\n", ioack);
2816 portp = panelp->ports[(ioack >> 3)];
2818 outb(ioaddr, (MISR + portp->uartaddr));
2819 misr = inb(ioaddr + EREG_DATA);
2820 if (misr & MISR_DCD) {
2821 portp->state |= ASY_DCDCHANGE;
2822 portp->stats.modem++;
2826 outb(ioaddr, (EOSRR + portp->uartaddr));
2827 outb((ioaddr + EREG_DATA), 0);
2830 /*****************************************************************************/
2833 * Interrupt service routine for cd1400 EasyIO boards.
2836 static void stl_cd1400eiointr(stlpanel_t *panelp, unsigned int iobase)
2838 unsigned char svrtype;
2841 kprintf("stl_cd1400eiointr(panelp=%x,iobase=%x)\n", (int) panelp,
2846 svrtype = inb(iobase + EREG_DATA);
2847 if (panelp->nrports > 4) {
2848 outb(iobase, (SVRR + 0x80));
2849 svrtype |= inb(iobase + EREG_DATA);
2852 kprintf("stl_cd1400eiointr(panelp=%x,iobase=%x): svrr=%x\n", (int) panelp, iobase, svrtype);
2855 if (svrtype & SVRR_RX)
2856 stl_cd1400rxisr(panelp, iobase);
2857 else if (svrtype & SVRR_TX)
2858 stl_cd1400txisr(panelp, iobase);
2859 else if (svrtype & SVRR_MDM)
2860 stl_cd1400mdmisr(panelp, iobase);
2863 /*****************************************************************************/
2866 * Interrupt service routine for cd1400 panels.
2869 static void stl_cd1400echintr(stlpanel_t *panelp, unsigned int iobase)
2871 unsigned char svrtype;
2874 kprintf("stl_cd1400echintr(panelp=%x,iobase=%x)\n", (int) panelp,
2879 svrtype = inb(iobase + EREG_DATA);
2880 outb(iobase, (SVRR + 0x80));
2881 svrtype |= inb(iobase + EREG_DATA);
2882 if (svrtype & SVRR_RX)
2883 stl_cd1400rxisr(panelp, iobase);
2884 else if (svrtype & SVRR_TX)
2885 stl_cd1400txisr(panelp, iobase);
2886 else if (svrtype & SVRR_MDM)
2887 stl_cd1400mdmisr(panelp, iobase);
2890 /*****************************************************************************/
2893 * Set up the cd1400 registers for a port based on the termios port
2897 static int stl_cd1400setport(stlport_t *portp, struct termios *tiosp)
2899 unsigned int clkdiv;
2900 unsigned char cor1, cor2, cor3;
2901 unsigned char cor4, cor5, ccr;
2902 unsigned char srer, sreron, sreroff;
2903 unsigned char mcor1, mcor2, rtpr;
2904 unsigned char clk, div;
2907 kprintf("stl_cd1400setport(portp=%x,tiosp=%x): brdnr=%d portnr=%d\n",
2908 (int) portp, (int) tiosp, portp->brdnr, portp->portnr);
2926 * Set up the RX char ignore mask with those RX error types we
2927 * can ignore. We could have used some special modes of the cd1400
2928 * UART to help, but it is better this way because we can keep stats
2929 * on the number of each type of RX exception event.
2931 portp->rxignoremsk = 0;
2932 if (tiosp->c_iflag & IGNPAR)
2933 portp->rxignoremsk |= (ST_PARITY | ST_FRAMING | ST_OVERRUN);
2934 if (tiosp->c_iflag & IGNBRK)
2935 portp->rxignoremsk |= ST_BREAK;
2937 portp->rxmarkmsk = ST_OVERRUN;
2938 if (tiosp->c_iflag & (INPCK | PARMRK))
2939 portp->rxmarkmsk |= (ST_PARITY | ST_FRAMING);
2940 if (tiosp->c_iflag & BRKINT)
2941 portp->rxmarkmsk |= ST_BREAK;
2944 * Go through the char size, parity and stop bits and set all the
2945 * option registers appropriately.
2947 switch (tiosp->c_cflag & CSIZE) {
2962 if (tiosp->c_cflag & CSTOPB)
2967 if (tiosp->c_cflag & PARENB) {
2968 if (tiosp->c_cflag & PARODD)
2969 cor1 |= (COR1_PARENB | COR1_PARODD);
2971 cor1 |= (COR1_PARENB | COR1_PAREVEN);
2973 cor1 |= COR1_PARNONE;
2977 * Set the RX FIFO threshold at 6 chars. This gives a bit of breathing
2978 * space for hardware flow control and the like. This should be set to
2979 * VMIN. Also here we will set the RX data timeout to 10ms - this should
2980 * really be based on VTIME...
2982 cor3 |= FIFO_RXTHRESHOLD;
2986 * Calculate the baud rate timers. For now we will just assume that
2987 * the input and output baud are the same. Could have used a baud
2988 * table here, but this way we can generate virtually any baud rate
2991 if (tiosp->c_ispeed == 0)
2992 tiosp->c_ispeed = tiosp->c_ospeed;
2993 if ((tiosp->c_ospeed < 0) || (tiosp->c_ospeed > CD1400_MAXBAUD))
2996 if (tiosp->c_ospeed > 0) {
2997 for (clk = 0; (clk < CD1400_NUMCLKS); clk++) {
2998 clkdiv = ((portp->clk / stl_cd1400clkdivs[clk]) /
3003 div = (unsigned char) clkdiv;
3007 * Check what form of modem signaling is required and set it up.
3009 if ((tiosp->c_cflag & CLOCAL) == 0) {
3012 sreron |= SRER_MODEM;
3016 * Setup cd1400 enhanced modes if we can. In particular we want to
3017 * handle as much of the flow control as possbile automatically. As
3018 * well as saving a few CPU cycles it will also greatly improve flow
3019 * control reliablilty.
3021 if (tiosp->c_iflag & IXON) {
3024 if (tiosp->c_iflag & IXANY)
3028 if (tiosp->c_cflag & CCTS_OFLOW)
3030 if (tiosp->c_cflag & CRTS_IFLOW)
3031 mcor1 |= FIFO_RTSTHRESHOLD;
3034 * All cd1400 register values calculated so go through and set them
3038 kprintf("SETPORT: portnr=%d panelnr=%d brdnr=%d\n", portp->portnr,
3039 portp->panelnr, portp->brdnr);
3040 kprintf(" cor1=%x cor2=%x cor3=%x cor4=%x cor5=%x\n", cor1, cor2,
3042 kprintf(" mcor1=%x mcor2=%x rtpr=%x sreron=%x sreroff=%x\n",
3043 mcor1, mcor2, rtpr, sreron, sreroff);
3044 kprintf(" tcor=%x tbpr=%x rcor=%x rbpr=%x\n", clk, div, clk, div);
3045 kprintf(" schr1=%x schr2=%x schr3=%x schr4=%x\n",
3046 tiosp->c_cc[VSTART], tiosp->c_cc[VSTOP], tiosp->c_cc[VSTART],
3047 tiosp->c_cc[VSTOP]);
3051 BRDENABLE(portp->brdnr, portp->pagenr);
3052 stl_cd1400setreg(portp, CAR, (portp->portnr & 0x3));
3053 srer = stl_cd1400getreg(portp, SRER);
3054 stl_cd1400setreg(portp, SRER, 0);
3055 ccr += stl_cd1400updatereg(portp, COR1, cor1);
3056 ccr += stl_cd1400updatereg(portp, COR2, cor2);
3057 ccr += stl_cd1400updatereg(portp, COR3, cor3);
3059 stl_cd1400ccrwait(portp);
3060 stl_cd1400setreg(portp, CCR, CCR_CORCHANGE);
3062 stl_cd1400setreg(portp, COR4, cor4);
3063 stl_cd1400setreg(portp, COR5, cor5);
3064 stl_cd1400setreg(portp, MCOR1, mcor1);
3065 stl_cd1400setreg(portp, MCOR2, mcor2);
3066 if (tiosp->c_ospeed == 0) {
3067 stl_cd1400setreg(portp, MSVR1, 0);
3069 stl_cd1400setreg(portp, MSVR1, MSVR1_DTR);
3070 stl_cd1400setreg(portp, TCOR, clk);
3071 stl_cd1400setreg(portp, TBPR, div);
3072 stl_cd1400setreg(portp, RCOR, clk);
3073 stl_cd1400setreg(portp, RBPR, div);
3075 stl_cd1400setreg(portp, SCHR1, tiosp->c_cc[VSTART]);
3076 stl_cd1400setreg(portp, SCHR2, tiosp->c_cc[VSTOP]);
3077 stl_cd1400setreg(portp, SCHR3, tiosp->c_cc[VSTART]);
3078 stl_cd1400setreg(portp, SCHR4, tiosp->c_cc[VSTOP]);
3079 stl_cd1400setreg(portp, RTPR, rtpr);
3080 mcor1 = stl_cd1400getreg(portp, MSVR1);
3081 if (mcor1 & MSVR1_DCD)
3082 portp->sigs |= TIOCM_CD;
3084 portp->sigs &= ~TIOCM_CD;
3085 stl_cd1400setreg(portp, SRER, ((srer & ~sreroff) | sreron));
3086 BRDDISABLE(portp->brdnr);
3087 portp->state &= ~(ASY_RTSFLOWMODE | ASY_CTSFLOWMODE);
3088 portp->state |= ((tiosp->c_cflag & CRTS_IFLOW) ? ASY_RTSFLOWMODE : 0);
3089 portp->state |= ((tiosp->c_cflag & CCTS_OFLOW) ? ASY_CTSFLOWMODE : 0);
3090 stl_ttyoptim(portp, tiosp);
3096 /*****************************************************************************/
3099 * Action the flow control as required. The hw and sw args inform the
3100 * routine what flow control methods it should try.
3103 static void stl_cd1400sendflow(stlport_t *portp, int hw, int sw)
3107 kprintf("stl_cd1400sendflow(portp=%x,hw=%d,sw=%d)\n",
3108 (int) portp, hw, sw);
3112 BRDENABLE(portp->brdnr, portp->pagenr);
3113 stl_cd1400setreg(portp, CAR, (portp->portnr & 0x03));
3116 stl_cd1400ccrwait(portp);
3118 stl_cd1400setreg(portp, CCR, CCR_SENDSCHR2);
3119 portp->stats.rxxoff++;
3121 stl_cd1400setreg(portp, CCR, CCR_SENDSCHR1);
3122 portp->stats.rxxon++;
3124 stl_cd1400ccrwait(portp);
3128 portp->state |= ASY_RTSFLOW;
3129 stl_cd1400setreg(portp, MCOR1,
3130 (stl_cd1400getreg(portp, MCOR1) & 0xf0));
3131 stl_cd1400setreg(portp, MSVR2, 0);
3132 portp->stats.rxrtsoff++;
3133 } else if (hw > 0) {
3134 portp->state &= ~ASY_RTSFLOW;
3135 stl_cd1400setreg(portp, MSVR2, MSVR2_RTS);
3136 stl_cd1400setreg(portp, MCOR1,
3137 (stl_cd1400getreg(portp, MCOR1) | FIFO_RTSTHRESHOLD));
3138 portp->stats.rxrtson++;
3141 BRDDISABLE(portp->brdnr);
3145 /*****************************************************************************/
3148 * Return the current state of data flow on this port. This is only
3149 * really interresting when determining if data has fully completed
3150 * transmission or not... This is easy for the cd1400, it accurately
3151 * maintains the busy port flag.
3154 static int stl_cd1400datastate(stlport_t *portp)
3157 kprintf("stl_cd1400datastate(portp=%x)\n", (int) portp);
3163 return((portp->state & ASY_TXBUSY) ? 1 : 0);
3166 /*****************************************************************************/
3169 * Set the state of the DTR and RTS signals. Got to do some extra
3170 * work here to deal hardware flow control.
3173 static void stl_cd1400setsignals(stlport_t *portp, int dtr, int rts)
3175 unsigned char msvr1, msvr2;
3178 kprintf("stl_cd1400setsignals(portp=%x,dtr=%d,rts=%d)\n", (int) portp,
3190 BRDENABLE(portp->brdnr, portp->pagenr);
3191 stl_cd1400setreg(portp, CAR, (portp->portnr & 0x03));
3193 if (portp->tty.t_cflag & CRTS_IFLOW) {
3195 stl_cd1400setreg(portp, MCOR1,
3196 (stl_cd1400getreg(portp, MCOR1) & 0xf0));
3197 portp->stats.rxrtsoff++;
3199 stl_cd1400setreg(portp, MCOR1,
3200 (stl_cd1400getreg(portp, MCOR1) |
3201 FIFO_RTSTHRESHOLD));
3202 portp->stats.rxrtson++;
3205 stl_cd1400setreg(portp, MSVR2, msvr2);
3208 stl_cd1400setreg(portp, MSVR1, msvr1);
3209 BRDDISABLE(portp->brdnr);
3213 /*****************************************************************************/
3216 * Get the state of the signals.
3219 static int stl_cd1400getsignals(stlport_t *portp)
3221 unsigned char msvr1, msvr2;
3225 kprintf("stl_cd1400getsignals(portp=%x)\n", (int) portp);
3229 BRDENABLE(portp->brdnr, portp->pagenr);
3230 stl_cd1400setreg(portp, CAR, (portp->portnr & 0x3));
3231 msvr1 = stl_cd1400getreg(portp, MSVR1);
3232 msvr2 = stl_cd1400getreg(portp, MSVR2);
3233 BRDDISABLE(portp->brdnr);
3237 sigs |= (msvr1 & MSVR1_DCD) ? TIOCM_CD : 0;
3238 sigs |= (msvr1 & MSVR1_CTS) ? TIOCM_CTS : 0;
3239 sigs |= (msvr1 & MSVR1_DTR) ? TIOCM_DTR : 0;
3240 sigs |= (msvr2 & MSVR2_RTS) ? TIOCM_RTS : 0;
3242 sigs |= (msvr1 & MSVR1_RI) ? TIOCM_RI : 0;
3243 sigs |= (msvr1 & MSVR1_DSR) ? TIOCM_DSR : 0;
3250 /*****************************************************************************/
3253 * Enable or disable the Transmitter and/or Receiver.
3256 static void stl_cd1400enablerxtx(stlport_t *portp, int rx, int tx)
3261 kprintf("stl_cd1400enablerxtx(portp=%x,rx=%d,tx=%d)\n",
3262 (int) portp, rx, tx);
3267 ccr |= CCR_TXDISABLE;
3269 ccr |= CCR_TXENABLE;
3271 ccr |= CCR_RXDISABLE;
3273 ccr |= CCR_RXENABLE;
3276 BRDENABLE(portp->brdnr, portp->pagenr);
3277 stl_cd1400setreg(portp, CAR, (portp->portnr & 0x03));
3278 stl_cd1400ccrwait(portp);
3279 stl_cd1400setreg(portp, CCR, ccr);
3280 stl_cd1400ccrwait(portp);
3281 BRDDISABLE(portp->brdnr);
3285 /*****************************************************************************/
3288 * Start or stop the Transmitter and/or Receiver.
3291 static void stl_cd1400startrxtx(stlport_t *portp, int rx, int tx)
3293 unsigned char sreron, sreroff;
3296 kprintf("stl_cd1400startrxtx(portp=%x,rx=%d,tx=%d)\n",
3297 (int) portp, rx, tx);
3303 sreroff |= (SRER_TXDATA | SRER_TXEMPTY);
3305 sreron |= SRER_TXDATA;
3307 sreron |= SRER_TXEMPTY;
3309 sreroff |= SRER_RXDATA;
3311 sreron |= SRER_RXDATA;
3314 BRDENABLE(portp->brdnr, portp->pagenr);
3315 stl_cd1400setreg(portp, CAR, (portp->portnr & 0x3));
3316 stl_cd1400setreg(portp, SRER,
3317 ((stl_cd1400getreg(portp, SRER) & ~sreroff) | sreron));
3318 BRDDISABLE(portp->brdnr);
3320 portp->state |= ASY_TXBUSY;
3321 portp->tty.t_state |= TS_BUSY;
3326 /*****************************************************************************/
3329 * Disable all interrupts from this port.
3332 static void stl_cd1400disableintrs(stlport_t *portp)
3336 kprintf("stl_cd1400disableintrs(portp=%x)\n", (int) portp);
3340 BRDENABLE(portp->brdnr, portp->pagenr);
3341 stl_cd1400setreg(portp, CAR, (portp->portnr & 0x3));
3342 stl_cd1400setreg(portp, SRER, 0);
3343 BRDDISABLE(portp->brdnr);
3347 /*****************************************************************************/
3349 static void stl_cd1400sendbreak(stlport_t *portp, long len)
3353 kprintf("stl_cd1400sendbreak(portp=%x,len=%d)\n", (int) portp,
3358 BRDENABLE(portp->brdnr, portp->pagenr);
3359 stl_cd1400setreg(portp, CAR, (portp->portnr & 0x3));
3360 stl_cd1400setreg(portp, COR2,
3361 (stl_cd1400getreg(portp, COR2) | COR2_ETC));
3362 stl_cd1400setreg(portp, SRER,
3363 ((stl_cd1400getreg(portp, SRER) & ~SRER_TXDATA) |
3365 BRDDISABLE(portp->brdnr);
3368 portp->brklen = (len > 255) ? 255 : len;
3370 portp->brklen = len;
3373 portp->stats.txbreaks++;
3376 /*****************************************************************************/
3379 * Try and find and initialize all the ports on a panel. We don't care
3380 * what sort of board these ports are on - since the port io registers
3381 * are almost identical when dealing with ports.
3384 static void stl_cd1400portinit(stlbrd_t *brdp, stlpanel_t *panelp, stlport_t *portp)
3387 kprintf("stl_cd1400portinit(brdp=%x,panelp=%x,portp=%x)\n",
3388 (int) brdp, (int) panelp, (int) portp);
3391 if ((brdp == NULL) || (panelp == NULL) ||
3395 portp->ioaddr = panelp->iobase + (((brdp->brdtype == BRD_ECHPCI) ||
3396 (portp->portnr < 8)) ? 0 : EREG_BANKSIZE);
3397 portp->uartaddr = (portp->portnr & 0x04) << 5;
3398 portp->pagenr = panelp->pagenr + (portp->portnr >> 3);
3400 BRDENABLE(portp->brdnr, portp->pagenr);
3401 stl_cd1400setreg(portp, CAR, (portp->portnr & 0x3));
3402 stl_cd1400setreg(portp, LIVR, (portp->portnr << 3));
3403 portp->hwid = stl_cd1400getreg(portp, GFRCR);
3404 BRDDISABLE(portp->brdnr);
3407 /*****************************************************************************/
3410 * Inbitialize the UARTs in a panel. We don't care what sort of board
3411 * these ports are on - since the port io registers are almost
3412 * identical when dealing with ports.
3415 static int stl_cd1400panelinit(stlbrd_t *brdp, stlpanel_t *panelp)
3419 int nrchips, uartaddr, ioaddr;
3422 kprintf("stl_cd1400panelinit(brdp=%x,panelp=%x)\n", (int) brdp,
3426 BRDENABLE(panelp->brdnr, panelp->pagenr);
3429 * Check that each chip is present and started up OK.
3432 nrchips = panelp->nrports / CD1400_PORTS;
3433 for (i = 0; (i < nrchips); i++) {
3434 if (brdp->brdtype == BRD_ECHPCI) {
3435 outb((panelp->pagenr + (i >> 1)), brdp->ioctrl);
3436 ioaddr = panelp->iobase;
3438 ioaddr = panelp->iobase + (EREG_BANKSIZE * (i >> 1));
3440 uartaddr = (i & 0x01) ? 0x080 : 0;
3441 outb(ioaddr, (GFRCR + uartaddr));
3442 outb((ioaddr + EREG_DATA), 0);
3443 outb(ioaddr, (CCR + uartaddr));
3444 outb((ioaddr + EREG_DATA), CCR_RESETFULL);
3445 outb((ioaddr + EREG_DATA), CCR_RESETFULL);
3446 outb(ioaddr, (GFRCR + uartaddr));
3447 for (j = 0; (j < CCR_MAXWAIT); j++) {
3448 if ((gfrcr = inb(ioaddr + EREG_DATA)) != 0)
3451 if ((j >= CCR_MAXWAIT) || (gfrcr < 0x40) || (gfrcr > 0x60)) {
3452 kprintf("STALLION: cd1400 not responding, "
3453 "board=%d panel=%d chip=%d\n", panelp->brdnr,
3454 panelp->panelnr, i);
3457 chipmask |= (0x1 << i);
3458 outb(ioaddr, (PPR + uartaddr));
3459 outb((ioaddr + EREG_DATA), PPR_SCALAR);
3463 BRDDISABLE(panelp->brdnr);
3467 /*****************************************************************************/
3468 /* SC26198 HARDWARE FUNCTIONS */
3469 /*****************************************************************************/
3472 * These functions get/set/update the registers of the sc26198 UARTs.
3473 * Access to the sc26198 registers is via an address/data io port pair.
3474 * (Maybe should make this inline...)
3477 static int stl_sc26198getreg(stlport_t *portp, int regnr)
3479 outb((portp->ioaddr + XP_ADDR), (regnr | portp->uartaddr));
3480 return(inb(portp->ioaddr + XP_DATA));
3483 static void stl_sc26198setreg(stlport_t *portp, int regnr, int value)
3485 outb((portp->ioaddr + XP_ADDR), (regnr | portp->uartaddr));
3486 outb((portp->ioaddr + XP_DATA), value);
3489 static int stl_sc26198updatereg(stlport_t *portp, int regnr, int value)
3491 outb((portp->ioaddr + XP_ADDR), (regnr | portp->uartaddr));
3492 if (inb(portp->ioaddr + XP_DATA) != value) {
3493 outb((portp->ioaddr + XP_DATA), value);
3499 /*****************************************************************************/
3502 * Functions to get and set the sc26198 global registers.
3505 static int stl_sc26198getglobreg(stlport_t *portp, int regnr)
3507 outb((portp->ioaddr + XP_ADDR), regnr);
3508 return(inb(portp->ioaddr + XP_DATA));
3512 static void stl_sc26198setglobreg(stlport_t *portp, int regnr, int value)
3514 outb((portp->ioaddr + XP_ADDR), regnr);
3515 outb((portp->ioaddr + XP_DATA), value);
3519 /*****************************************************************************/
3522 * Inbitialize the UARTs in a panel. We don't care what sort of board
3523 * these ports are on - since the port io registers are almost
3524 * identical when dealing with ports.
3527 static int stl_sc26198panelinit(stlbrd_t *brdp, stlpanel_t *panelp)
3530 int nrchips, ioaddr;
3533 kprintf("stl_sc26198panelinit(brdp=%x,panelp=%x)\n", (int) brdp,
3537 BRDENABLE(panelp->brdnr, panelp->pagenr);
3540 * Check that each chip is present and started up OK.
3543 nrchips = (panelp->nrports + 4) / SC26198_PORTS;
3544 if (brdp->brdtype == BRD_ECHPCI)
3545 outb(brdp->ioctrl, panelp->pagenr);
3547 for (i = 0; (i < nrchips); i++) {
3548 ioaddr = panelp->iobase + (i * 4);
3549 outb((ioaddr + XP_ADDR), SCCR);
3550 outb((ioaddr + XP_DATA), CR_RESETALL);
3551 outb((ioaddr + XP_ADDR), TSTR);
3552 if (inb(ioaddr + XP_DATA) != 0) {
3553 kprintf("STALLION: sc26198 not responding, "
3554 "board=%d panel=%d chip=%d\n", panelp->brdnr,
3555 panelp->panelnr, i);
3558 chipmask |= (0x1 << i);
3559 outb((ioaddr + XP_ADDR), GCCR);
3560 outb((ioaddr + XP_DATA), GCCR_IVRTYPCHANACK);
3561 outb((ioaddr + XP_ADDR), WDTRCR);
3562 outb((ioaddr + XP_DATA), 0xff);
3565 BRDDISABLE(panelp->brdnr);
3569 /*****************************************************************************/
3572 * Initialize hardware specific port registers.
3575 static void stl_sc26198portinit(stlbrd_t *brdp, stlpanel_t *panelp, stlport_t *portp)
3578 kprintf("stl_sc26198portinit(brdp=%x,panelp=%x,portp=%x)\n",
3579 (int) brdp, (int) panelp, (int) portp);
3582 if ((brdp == NULL) || (panelp == NULL) ||
3586 portp->ioaddr = panelp->iobase + ((portp->portnr < 8) ? 0 : 4);
3587 portp->uartaddr = (portp->portnr & 0x07) << 4;
3588 portp->pagenr = panelp->pagenr;
3591 BRDENABLE(portp->brdnr, portp->pagenr);
3592 stl_sc26198setreg(portp, IOPCR, IOPCR_SETSIGS);
3593 BRDDISABLE(portp->brdnr);
3596 /*****************************************************************************/
3599 * Set up the sc26198 registers for a port based on the termios port
3603 static int stl_sc26198setport(stlport_t *portp, struct termios *tiosp)
3605 unsigned char mr0, mr1, mr2, clk;
3606 unsigned char imron, imroff, iopr, ipr;
3609 kprintf("stl_sc26198setport(portp=%x,tiosp=%x): brdnr=%d portnr=%d\n",
3610 (int) portp, (int) tiosp, portp->brdnr, portp->portnr);
3622 * Set up the RX char ignore mask with those RX error types we
3625 portp->rxignoremsk = 0;
3626 if (tiosp->c_iflag & IGNPAR)
3627 portp->rxignoremsk |= (SR_RXPARITY | SR_RXFRAMING |
3629 if (tiosp->c_iflag & IGNBRK)
3630 portp->rxignoremsk |= SR_RXBREAK;
3632 portp->rxmarkmsk = SR_RXOVERRUN;
3633 if (tiosp->c_iflag & (INPCK | PARMRK))
3634 portp->rxmarkmsk |= (SR_RXPARITY | SR_RXFRAMING);
3635 if (tiosp->c_iflag & BRKINT)
3636 portp->rxmarkmsk |= SR_RXBREAK;
3639 * Go through the char size, parity and stop bits and set all the
3640 * option registers appropriately.
3642 switch (tiosp->c_cflag & CSIZE) {
3657 if (tiosp->c_cflag & CSTOPB)
3662 if (tiosp->c_cflag & PARENB) {
3663 if (tiosp->c_cflag & PARODD)
3664 mr1 |= (MR1_PARENB | MR1_PARODD);
3666 mr1 |= (MR1_PARENB | MR1_PAREVEN);
3671 mr1 |= MR1_ERRBLOCK;
3674 * Set the RX FIFO threshold at 8 chars. This gives a bit of breathing
3675 * space for hardware flow control and the like. This should be set to
3678 mr2 |= MR2_RXFIFOHALF;
3681 * Calculate the baud rate timers. For now we will just assume that
3682 * the input and output baud are the same. The sc26198 has a fixed
3683 * baud rate table, so only discrete baud rates possible.
3685 if (tiosp->c_ispeed == 0)
3686 tiosp->c_ispeed = tiosp->c_ospeed;
3687 if ((tiosp->c_ospeed < 0) || (tiosp->c_ospeed > SC26198_MAXBAUD))
3690 if (tiosp->c_ospeed > 0) {
3691 for (clk = 0; (clk < SC26198_NRBAUDS); clk++) {
3692 if (tiosp->c_ospeed <= sc26198_baudtable[clk])
3698 * Check what form of modem signaling is required and set it up.
3700 if ((tiosp->c_cflag & CLOCAL) == 0) {
3701 iopr |= IOPR_DCDCOS;
3706 * Setup sc26198 enhanced modes if we can. In particular we want to
3707 * handle as much of the flow control as possible automatically. As
3708 * well as saving a few CPU cycles it will also greatly improve flow
3709 * control reliability.
3711 if (tiosp->c_iflag & IXON) {
3712 mr0 |= MR0_SWFTX | MR0_SWFT;
3713 imron |= IR_XONXOFF;
3715 imroff |= IR_XONXOFF;
3718 if (tiosp->c_iflag & IXOFF)
3722 if (tiosp->c_cflag & CCTS_OFLOW)
3724 if (tiosp->c_cflag & CRTS_IFLOW)
3728 * All sc26198 register values calculated so go through and set
3733 kprintf("SETPORT: portnr=%d panelnr=%d brdnr=%d\n", portp->portnr,
3734 portp->panelnr, portp->brdnr);
3735 kprintf(" mr0=%x mr1=%x mr2=%x clk=%x\n", mr0, mr1, mr2, clk);
3736 kprintf(" iopr=%x imron=%x imroff=%x\n", iopr, imron, imroff);
3737 kprintf(" schr1=%x schr2=%x schr3=%x schr4=%x\n",
3738 tiosp->c_cc[VSTART], tiosp->c_cc[VSTOP],
3739 tiosp->c_cc[VSTART], tiosp->c_cc[VSTOP]);
3743 BRDENABLE(portp->brdnr, portp->pagenr);
3744 stl_sc26198setreg(portp, IMR, 0);
3745 stl_sc26198updatereg(portp, MR0, mr0);
3746 stl_sc26198updatereg(portp, MR1, mr1);
3747 stl_sc26198setreg(portp, SCCR, CR_RXERRBLOCK);
3748 stl_sc26198updatereg(portp, MR2, mr2);
3749 iopr = (stl_sc26198getreg(portp, IOPIOR) & ~IPR_CHANGEMASK) | iopr;
3750 if (tiosp->c_ospeed == 0) {
3754 stl_sc26198setreg(portp, TXCSR, clk);
3755 stl_sc26198setreg(portp, RXCSR, clk);
3757 stl_sc26198updatereg(portp, IOPIOR, iopr);
3758 stl_sc26198setreg(portp, XONCR, tiosp->c_cc[VSTART]);
3759 stl_sc26198setreg(portp, XOFFCR, tiosp->c_cc[VSTOP]);
3760 ipr = stl_sc26198getreg(portp, IPR);
3762 portp->sigs &= ~TIOCM_CD;
3764 portp->sigs |= TIOCM_CD;
3765 portp->imr = (portp->imr & ~imroff) | imron;
3766 stl_sc26198setreg(portp, IMR, portp->imr);
3767 BRDDISABLE(portp->brdnr);
3768 portp->state &= ~(ASY_RTSFLOWMODE | ASY_CTSFLOWMODE);
3769 portp->state |= ((tiosp->c_cflag & CRTS_IFLOW) ? ASY_RTSFLOWMODE : 0);
3770 portp->state |= ((tiosp->c_cflag & CCTS_OFLOW) ? ASY_CTSFLOWMODE : 0);
3771 stl_ttyoptim(portp, tiosp);
3777 /*****************************************************************************/
3780 * Set the state of the DTR and RTS signals.
3783 static void stl_sc26198setsignals(stlport_t *portp, int dtr, int rts)
3785 unsigned char iopioron, iopioroff;
3788 kprintf("stl_sc26198setsignals(portp=%x,dtr=%d,rts=%d)\n",
3789 (int) portp, dtr, rts);
3795 iopioroff |= IPR_DTR;
3797 iopioron |= IPR_DTR;
3799 iopioroff |= IPR_RTS;
3801 iopioron |= IPR_RTS;
3804 BRDENABLE(portp->brdnr, portp->pagenr);
3805 if ((rts >= 0) && (portp->tty.t_cflag & CRTS_IFLOW)) {
3807 stl_sc26198setreg(portp, MR1,
3808 (stl_sc26198getreg(portp, MR1) & ~MR1_AUTORTS));
3809 portp->stats.rxrtsoff++;
3811 stl_sc26198setreg(portp, MR1,
3812 (stl_sc26198getreg(portp, MR1) | MR1_AUTORTS));
3813 portp->stats.rxrtson++;
3816 stl_sc26198setreg(portp, IOPIOR,
3817 ((stl_sc26198getreg(portp, IOPIOR) & ~iopioroff) | iopioron));
3818 BRDDISABLE(portp->brdnr);
3822 /*****************************************************************************/
3825 * Return the state of the signals.
3828 static int stl_sc26198getsignals(stlport_t *portp)
3834 kprintf("stl_sc26198getsignals(portp=%x)\n", (int) portp);
3838 BRDENABLE(portp->brdnr, portp->pagenr);
3839 ipr = stl_sc26198getreg(portp, IPR);
3840 BRDDISABLE(portp->brdnr);
3844 sigs |= (ipr & IPR_DCD) ? 0 : TIOCM_CD;
3845 sigs |= (ipr & IPR_CTS) ? 0 : TIOCM_CTS;
3846 sigs |= (ipr & IPR_DTR) ? 0: TIOCM_DTR;
3847 sigs |= (ipr & IPR_RTS) ? 0: TIOCM_RTS;
3851 /*****************************************************************************/
3854 * Enable/Disable the Transmitter and/or Receiver.
3857 static void stl_sc26198enablerxtx(stlport_t *portp, int rx, int tx)
3862 kprintf("stl_sc26198enablerxtx(portp=%x,rx=%d,tx=%d)\n",
3863 (int) portp, rx, tx);
3866 ccr = portp->crenable;
3868 ccr &= ~CR_TXENABLE;
3872 ccr &= ~CR_RXENABLE;
3877 BRDENABLE(portp->brdnr, portp->pagenr);
3878 stl_sc26198setreg(portp, SCCR, ccr);
3879 BRDDISABLE(portp->brdnr);
3880 portp->crenable = ccr;
3884 /*****************************************************************************/
3887 * Start/stop the Transmitter and/or Receiver.
3890 static void stl_sc26198startrxtx(stlport_t *portp, int rx, int tx)
3895 kprintf("stl_sc26198startrxtx(portp=%x,rx=%d,tx=%d)\n",
3896 (int) portp, rx, tx);
3905 imr &= ~(IR_RXRDY | IR_RXBREAK | IR_RXWATCHDOG);
3907 imr |= IR_RXRDY | IR_RXBREAK | IR_RXWATCHDOG;
3910 BRDENABLE(portp->brdnr, portp->pagenr);
3911 stl_sc26198setreg(portp, IMR, imr);
3912 BRDDISABLE(portp->brdnr);
3915 portp->state |= ASY_TXBUSY;
3916 portp->tty.t_state |= TS_BUSY;
3921 /*****************************************************************************/
3924 * Disable all interrupts from this port.
3927 static void stl_sc26198disableintrs(stlport_t *portp)
3931 kprintf("stl_sc26198disableintrs(portp=%x)\n", (int) portp);
3935 BRDENABLE(portp->brdnr, portp->pagenr);
3937 stl_sc26198setreg(portp, IMR, 0);
3938 BRDDISABLE(portp->brdnr);
3942 /*****************************************************************************/
3944 static void stl_sc26198sendbreak(stlport_t *portp, long len)
3948 kprintf("stl_sc26198sendbreak(portp=%x,len=%d)\n",
3949 (int) portp, (int) len);
3953 BRDENABLE(portp->brdnr, portp->pagenr);
3955 stl_sc26198setreg(portp, SCCR, CR_TXSTARTBREAK);
3956 portp->stats.txbreaks++;
3958 stl_sc26198setreg(portp, SCCR, CR_TXSTOPBREAK);
3960 BRDDISABLE(portp->brdnr);
3964 /*****************************************************************************/
3967 * Take flow control actions...
3970 static void stl_sc26198sendflow(stlport_t *portp, int hw, int sw)
3975 kprintf("stl_sc26198sendflow(portp=%x,hw=%d,sw=%d)\n",
3976 (int) portp, hw, sw);
3983 BRDENABLE(portp->brdnr, portp->pagenr);
3986 mr0 = stl_sc26198getreg(portp, MR0);
3987 stl_sc26198setreg(portp, MR0, (mr0 & ~MR0_SWFRXTX));
3989 stl_sc26198setreg(portp, SCCR, CR_TXSENDXOFF);
3991 portp->stats.rxxoff++;
3993 stl_sc26198setreg(portp, SCCR, CR_TXSENDXON);
3995 portp->stats.rxxon++;
3997 stl_sc26198wait(portp);
3998 stl_sc26198setreg(portp, MR0, mr0);
4002 portp->state |= ASY_RTSFLOW;
4003 stl_sc26198setreg(portp, MR1,
4004 (stl_sc26198getreg(portp, MR1) & ~MR1_AUTORTS));
4005 stl_sc26198setreg(portp, IOPIOR,
4006 (stl_sc26198getreg(portp, IOPIOR) & ~IOPR_RTS));
4007 portp->stats.rxrtsoff++;
4008 } else if (hw > 0) {
4009 portp->state &= ~ASY_RTSFLOW;
4010 stl_sc26198setreg(portp, MR1,
4011 (stl_sc26198getreg(portp, MR1) | MR1_AUTORTS));
4012 stl_sc26198setreg(portp, IOPIOR,
4013 (stl_sc26198getreg(portp, IOPIOR) | IOPR_RTS));
4014 portp->stats.rxrtson++;
4017 BRDDISABLE(portp->brdnr);
4021 /*****************************************************************************/
4024 * Return the current state of data flow on this port. This is only
4025 * really interresting when determining if data has fully completed
4026 * transmission or not... The sc26198 interrupt scheme cannot
4027 * determine when all data has actually drained, so we need to
4028 * check the port statusy register to be sure.
4031 static int stl_sc26198datastate(stlport_t *portp)
4036 kprintf("stl_sc26198datastate(portp=%x)\n", (int) portp);
4041 if (portp->state & ASY_TXBUSY)
4045 BRDENABLE(portp->brdnr, portp->pagenr);
4046 sr = stl_sc26198getreg(portp, SR);
4047 BRDDISABLE(portp->brdnr);
4050 return((sr & SR_TXEMPTY) ? 0 : 1);
4053 /*****************************************************************************/
4055 static void stl_sc26198flush(stlport_t *portp, int flag)
4059 kprintf("stl_sc26198flush(portp=%x,flag=%x)\n", (int) portp, flag);
4066 BRDENABLE(portp->brdnr, portp->pagenr);
4067 if (flag & FWRITE) {
4068 stl_sc26198setreg(portp, SCCR, CR_TXRESET);
4069 stl_sc26198setreg(portp, SCCR, portp->crenable);
4072 while (stl_sc26198getreg(portp, SR) & SR_RXRDY)
4073 stl_sc26198getreg(portp, RXFIFO);
4075 BRDDISABLE(portp->brdnr);
4079 /*****************************************************************************/
4082 * If we are TX flow controlled and in IXANY mode then we may
4083 * need to unflow control here. We gotta do this because of the
4084 * automatic flow control modes of the sc26198 - which downs't
4085 * support any concept of an IXANY mode.
4088 static void stl_sc26198txunflow(stlport_t *portp)
4092 mr0 = stl_sc26198getreg(portp, MR0);
4093 stl_sc26198setreg(portp, MR0, (mr0 & ~MR0_SWFRXTX));
4094 stl_sc26198setreg(portp, SCCR, CR_HOSTXON);
4095 stl_sc26198setreg(portp, MR0, mr0);
4096 portp->state &= ~ASY_TXFLOWED;
4099 /*****************************************************************************/
4102 * Delay for a small amount of time, to give the sc26198 a chance
4103 * to process a command...
4106 static void stl_sc26198wait(stlport_t *portp)
4111 kprintf("stl_sc26198wait(portp=%x)\n", (int) portp);
4117 for (i = 0; (i < 20); i++)
4118 stl_sc26198getglobreg(portp, TSTR);
4121 /*****************************************************************************/
4124 * Transmit interrupt handler. This has gotta be fast! Handling TX
4125 * chars is pretty simple, stuff as many as possible from the TX buffer
4126 * into the sc26198 FIFO.
4129 static __inline void stl_sc26198txisr(stlport_t *portp)
4131 unsigned int ioaddr;
4137 kprintf("stl_sc26198txisr(portp=%x)\n", (int) portp);
4140 ioaddr = portp->ioaddr;
4142 head = portp->tx.head;
4143 tail = portp->tx.tail;
4144 len = (head >= tail) ? (head - tail) : (STL_TXBUFSIZE - (tail - head));
4145 if ((len == 0) || ((len < STL_TXBUFLOW) &&
4146 ((portp->state & ASY_TXLOW) == 0))) {
4147 portp->state |= ASY_TXLOW;
4152 outb((ioaddr + XP_ADDR), (MR0 | portp->uartaddr));
4153 mr0 = inb(ioaddr + XP_DATA);
4154 if ((mr0 & MR0_TXMASK) == MR0_TXEMPTY) {
4155 portp->imr &= ~IR_TXRDY;
4156 outb((ioaddr + XP_ADDR), (IMR | portp->uartaddr));
4157 outb((ioaddr + XP_DATA), portp->imr);
4158 portp->state |= ASY_TXEMPTY;
4159 portp->state &= ~ASY_TXBUSY;
4161 mr0 |= ((mr0 & ~MR0_TXMASK) | MR0_TXEMPTY);
4162 outb((ioaddr + XP_DATA), mr0);
4165 len = MIN(len, SC26198_TXFIFOSIZE);
4166 portp->stats.txtotal += len;
4167 stlen = MIN(len, (portp->tx.endbuf - tail));
4168 outb((ioaddr + XP_ADDR), GTXFIFO);
4169 outsb((ioaddr + XP_DATA), tail, stlen);
4172 if (tail >= portp->tx.endbuf)
4173 tail = portp->tx.buf;
4175 outsb((ioaddr + XP_DATA), tail, len);
4178 portp->tx.tail = tail;
4182 /*****************************************************************************/
4185 * Receive character interrupt handler. Determine if we have good chars
4186 * or bad chars and then process appropriately. Good chars are easy
4187 * just shove the lot into the RX buffer and set all status byte to 0.
4188 * If a bad RX char then process as required. This routine needs to be
4192 static __inline void stl_sc26198rxisr(stlport_t *portp, unsigned int iack)
4195 kprintf("stl_sc26198rxisr(portp=%x,iack=%x)\n", (int) portp, iack);
4198 if ((iack & IVR_TYPEMASK) == IVR_RXDATA)
4199 stl_sc26198rxgoodchars(portp);
4201 stl_sc26198rxbadchars(portp);
4204 * If we are TX flow controlled and in IXANY mode then we may need
4205 * to unflow control here. We gotta do this because of the automatic
4206 * flow control modes of the sc26198.
4208 if ((portp->state & ASY_TXFLOWED) && (portp->tty.t_iflag & IXANY))
4209 stl_sc26198txunflow(portp);
4212 /*****************************************************************************/
4215 * Process the good received characters from RX FIFO.
4218 static void stl_sc26198rxgoodchars(stlport_t *portp)
4220 unsigned int ioaddr, len, buflen, stlen;
4224 kprintf("stl_sc26198rxgoodchars(port=%x)\n", (int) portp);
4227 ioaddr = portp->ioaddr;
4230 * First up, calculate how much room there is in the RX ring queue.
4231 * We also want to keep track of the longest possible copy length,
4232 * this has to allow for the wrapping of the ring queue.
4234 head = portp->rx.head;
4235 tail = portp->rx.tail;
4237 buflen = STL_RXBUFSIZE - (head - tail) - 1;
4238 stlen = portp->rx.endbuf - head;
4240 buflen = tail - head - 1;
4245 * Check if the input buffer is near full. If so then we should take
4246 * some flow control action... It is very easy to do hardware and
4247 * software flow control from here since we have the port selected on
4250 if (buflen <= (STL_RXBUFSIZE - STL_RXBUFHIGH)) {
4251 if (((portp->state & ASY_RTSFLOW) == 0) &&
4252 (portp->state & ASY_RTSFLOWMODE)) {
4253 portp->state |= ASY_RTSFLOW;
4254 stl_sc26198setreg(portp, MR1,
4255 (stl_sc26198getreg(portp, MR1) & ~MR1_AUTORTS));
4256 stl_sc26198setreg(portp, IOPIOR,
4257 (stl_sc26198getreg(portp, IOPIOR) & ~IOPR_RTS));
4258 portp->stats.rxrtsoff++;
4263 * OK we are set, process good data... If the RX ring queue is full
4264 * just chuck the chars - don't leave them in the UART.
4266 outb((ioaddr + XP_ADDR), GIBCR);
4267 len = inb(ioaddr + XP_DATA) + 1;
4269 outb((ioaddr + XP_ADDR), GRXFIFO);
4270 insb((ioaddr + XP_DATA), &stl_unwanted[0], len);
4271 portp->stats.rxlost += len;
4272 portp->stats.rxtotal += len;
4274 len = MIN(len, buflen);
4275 portp->stats.rxtotal += len;
4276 stlen = MIN(len, stlen);
4278 outb((ioaddr + XP_ADDR), GRXFIFO);
4279 insb((ioaddr + XP_DATA), head, stlen);
4281 if (head >= portp->rx.endbuf) {
4282 head = portp->rx.buf;
4284 insb((ioaddr + XP_DATA), head, len);
4290 portp->rx.head = head;
4291 portp->state |= ASY_RXDATA;
4295 /*****************************************************************************/
4298 * Process all characters in the RX FIFO of the UART. Check all char
4299 * status bytes as well, and process as required. We need to check
4300 * all bytes in the FIFO, in case some more enter the FIFO while we
4301 * are here. To get the exact character error type we need to switch
4302 * into CHAR error mode (that is why we need to make sure we empty
4306 static void stl_sc26198rxbadchars(stlport_t *portp)
4309 unsigned int status;
4315 * First up, calculate how much room there is in the RX ring queue.
4316 * We also want to keep track of the longest possible copy length,
4317 * this has to allow for the wrapping of the ring queue.
4319 head = portp->rx.head;
4320 tail = portp->rx.tail;
4321 len = (head >= tail) ? (STL_RXBUFSIZE - (head - tail) - 1) :
4325 * To get the precise error type for each character we must switch
4326 * back into CHAR error mode.
4328 mr1 = stl_sc26198getreg(portp, MR1);
4329 stl_sc26198setreg(portp, MR1, (mr1 & ~MR1_ERRBLOCK));
4331 while ((status = stl_sc26198getreg(portp, SR)) & SR_RXRDY) {
4332 stl_sc26198setreg(portp, SCCR, CR_CLEARRXERR);
4333 ch = stl_sc26198getreg(portp, RXFIFO);
4335 if (status & SR_RXBREAK)
4336 portp->stats.rxbreaks++;
4337 if (status & SR_RXFRAMING)
4338 portp->stats.rxframing++;
4339 if (status & SR_RXPARITY)
4340 portp->stats.rxparity++;
4341 if (status & SR_RXOVERRUN)
4342 portp->stats.rxoverrun++;
4343 if ((portp->rxignoremsk & status) == 0) {
4344 if ((portp->tty.t_state & TS_CAN_BYPASS_L_RINT) &&
4345 ((status & SR_RXFRAMING) ||
4346 ((status & SR_RXPARITY) &&
4347 (portp->tty.t_iflag & INPCK))))
4349 if ((portp->rxmarkmsk & status) == 0)
4352 *(head + STL_RXBUFSIZE) = status;
4354 if (head >= portp->rx.endbuf)
4355 head = portp->rx.buf;
4362 * To get correct interrupt class we must switch back into BLOCK
4365 stl_sc26198setreg(portp, MR1, mr1);
4367 portp->rx.head = head;
4368 portp->state |= ASY_RXDATA;
4372 /*****************************************************************************/
4375 * Other interrupt handler. This includes modem signals, flow
4376 * control actions, etc.
4379 static void stl_sc26198otherisr(stlport_t *portp, unsigned int iack)
4381 unsigned char cir, ipr, xisr;
4384 kprintf("stl_sc26198otherisr(portp=%x,iack=%x)\n", (int) portp, iack);
4387 cir = stl_sc26198getglobreg(portp, CIR);
4389 switch (cir & CIR_SUBTYPEMASK) {
4391 ipr = stl_sc26198getreg(portp, IPR);
4392 if (ipr & IPR_DCDCHANGE) {
4393 portp->state |= ASY_DCDCHANGE;
4394 portp->stats.modem++;
4398 case CIR_SUBXONXOFF:
4399 xisr = stl_sc26198getreg(portp, XISR);
4400 if (xisr & XISR_RXXONGOT) {
4401 portp->state |= ASY_TXFLOWED;
4402 portp->stats.txxoff++;
4404 if (xisr & XISR_RXXOFFGOT) {
4405 portp->state &= ~ASY_TXFLOWED;
4406 portp->stats.txxon++;
4410 stl_sc26198setreg(portp, SCCR, CR_BREAKRESET);
4411 stl_sc26198rxbadchars(portp);
4418 /*****************************************************************************/
4421 * Interrupt service routine for sc26198 panels.
4424 static void stl_sc26198intr(stlpanel_t *panelp, unsigned int iobase)
4430 * Work around bug in sc26198 chip... Cannot have A6 address
4431 * line of UART high, else iack will be returned as 0.
4433 outb((iobase + 1), 0);
4435 iack = inb(iobase + XP_IACK);
4437 kprintf("stl_sc26198intr(panelp=%p,iobase=%x): iack=%x\n", panelp, iobase, iack);
4439 portp = panelp->ports[(iack & IVR_CHANMASK) + ((iobase & 0x4) << 1)];
4441 if (iack & IVR_RXDATA)
4442 stl_sc26198rxisr(portp, iack);
4443 else if (iack & IVR_TXDATA)
4444 stl_sc26198txisr(portp);
4446 stl_sc26198otherisr(portp, iack);
4449 /*****************************************************************************/