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>
46 #include <sys/systm.h>
47 #include <sys/kernel.h>
48 #include <sys/malloc.h>
53 #include <sys/fcntl.h>
54 #include <sys/thread2.h>
55 #include <machine_base/isa/ic/scd1400.h>
56 #include <machine_base/isa/ic/sc26198.h>
57 #include <machine/comstats.h>
59 #include <bus/pci/pcivar.h>
60 #include <bus/pci/pcireg.h>
64 /*****************************************************************************/
67 * Define different board types. At the moment I have only declared
68 * those boards that this driver supports. But I will use the standard
69 * "assigned" board numbers. In the future this driver will support
70 * some of the other Stallion boards. Currently supported boards are
71 * abbreviated as EIO = EasyIO and ECH = EasyConnection 8/32.
77 #define BRD_ECH64PCI 27
78 #define BRD_EASYIOPCI 28
80 /*****************************************************************************/
83 * Define important driver limitations.
86 #define STL_MAXPANELS 4
87 #define STL_MAXBANKS 8
88 #define STL_PORTSPERPANEL 16
89 #define STL_PORTSPERBRD 64
92 * Define the important minor number break down bits. These have been
93 * chosen to be "compatible" with the standard sio driver minor numbers.
94 * Extra high bits are used to distinguish between boards.
96 #define STL_CALLOUTDEV 0x80
97 #define STL_CTRLLOCK 0x40
98 #define STL_CTRLINIT 0x20
99 #define STL_CTRLDEV (STL_CTRLLOCK | STL_CTRLINIT)
101 #define STL_MEMDEV 0x07000000
103 #define STL_DEFSPEED TTYDEF_SPEED
104 #define STL_DEFCFLAG (CS8 | CREAD | HUPCL)
107 * I haven't really decided (or measured) what buffer sizes give
108 * a good balance between performance and memory usage. These seem
109 * to work pretty well...
111 #define STL_RXBUFSIZE 2048
112 #define STL_TXBUFSIZE 2048
114 #define STL_TXBUFLOW (STL_TXBUFSIZE / 4)
115 #define STL_RXBUFHIGH (3 * STL_RXBUFSIZE / 4)
117 /*****************************************************************************/
120 * Define our local driver identity first. Set up stuff to deal with
121 * all the local structures required by a serial tty driver.
123 static const char stl_drvname[] = "stl";
124 static const char stl_longdrvname[] = "Stallion Multiport Serial Driver";
125 static const char stl_drvversion[] = "2.0.0";
127 static int stl_nrbrds = 0;
128 static int stl_doingtimeout = 0;
129 static struct callout stl_poll_ch;
131 static const char __file__[] = /*__FILE__*/ "stallion.c";
134 * Define global stats structures. Not used often, and can be
135 * re-used for each stats call.
137 static combrd_t stl_brdstats;
138 static comstats_t stl_comstats;
140 /*****************************************************************************/
143 * Define a set of structures to hold all the board/panel/port info
144 * for our ports. These will be dynamically allocated as required.
148 * Define a ring queue structure for each port. This will hold the
149 * TX data waiting to be output. Characters are fed into this buffer
150 * from the line discipline (or even direct from user space!) and
151 * then fed into the UARTs during interrupts. Will use a clasic ring
152 * queue here for this. The good thing about this type of ring queue
153 * is that the head and tail pointers can be updated without interrupt
154 * protection - since "write" code only needs to change the head, and
155 * interrupt code only needs to change the tail.
165 * Port, panel and board structures to hold status info about each.
166 * The board structure contains pointers to structures for each panel
167 * connected to it, and in turn each panel structure contains pointers
168 * for each port structure for each port on that panel. Note that
169 * the port structure also contains the board and panel number that it
170 * is associated with, this makes it (fairly) easy to get back to the
171 * board/panel info for a port. Also note that the tty struct is at
172 * the top of the structure, this is important, since the code uses
173 * this fact to get the port struct pointer from the tty struct
176 typedef struct stlport {
194 unsigned int rxignoremsk;
195 unsigned int rxmarkmsk;
196 unsigned int crenable;
199 struct termios initintios;
200 struct termios initouttios;
201 struct termios lockintios;
202 struct termios lockouttios;
203 struct timeval timestamp;
208 struct callout dtr_ch;
211 typedef struct stlpanel {
218 unsigned int ackmask;
219 void (*isr)(struct stlpanel *panelp, unsigned int iobase);
221 stlport_t *ports[STL_PORTSPERPANEL];
224 typedef struct stlbrd {
234 unsigned int ioaddr1;
235 unsigned int ioaddr2;
236 unsigned int iostatus;
238 unsigned int ioctrlval;
241 void (*isr)(struct stlbrd *brdp);
242 unsigned int bnkpageaddr[STL_MAXBANKS];
243 unsigned int bnkstataddr[STL_MAXBANKS];
244 stlpanel_t *bnk2panel[STL_MAXBANKS];
245 stlpanel_t *panels[STL_MAXPANELS];
246 stlport_t *ports[STL_PORTSPERBRD];
249 static stlbrd_t *stl_brds[STL_MAXBRDS];
252 * Per board state flags. Used with the state field of the board struct.
253 * Not really much here yet!
255 #define BRD_FOUND 0x1
258 * Define the port structure state flags. These set of flags are
259 * modified at interrupt time - so setting and reseting them needs
262 #define ASY_TXLOW 0x1
263 #define ASY_RXDATA 0x2
264 #define ASY_DCDCHANGE 0x4
265 #define ASY_DTRWAIT 0x8
266 #define ASY_RTSFLOW 0x10
267 #define ASY_RTSFLOWMODE 0x20
268 #define ASY_CTSFLOWMODE 0x40
269 #define ASY_TXFLOWED 0x80
270 #define ASY_TXBUSY 0x100
271 #define ASY_TXEMPTY 0x200
273 #define ASY_ACTIVE (ASY_TXLOW | ASY_RXDATA | ASY_DCDCHANGE)
276 * Define an array of board names as printable strings. Handy for
277 * referencing boards when printing trace and stuff.
279 static char *stl_brdnames[] = {
311 /*****************************************************************************/
314 * Hardware ID bits for the EasyIO and ECH boards. These defines apply
315 * to the directly accessable io ports of these boards (not the cd1400
316 * uarts - they are in scd1400.h).
318 #define EIO_8PORTRS 0x04
319 #define EIO_4PORTRS 0x05
320 #define EIO_8PORTDI 0x00
321 #define EIO_8PORTM 0x06
323 #define EIO_IDBITMASK 0x07
325 #define EIO_BRDMASK 0xf0
328 #define ID_BRD16 0x30
330 #define EIO_INTRPEND 0x08
331 #define EIO_INTEDGE 0x00
332 #define EIO_INTLEVEL 0x08
335 #define ECH_IDBITMASK 0xe0
336 #define ECH_BRDENABLE 0x08
337 #define ECH_BRDDISABLE 0x00
338 #define ECH_INTENABLE 0x01
339 #define ECH_INTDISABLE 0x00
340 #define ECH_INTLEVEL 0x02
341 #define ECH_INTEDGE 0x00
342 #define ECH_INTRPEND 0x01
343 #define ECH_BRDRESET 0x01
345 #define ECHMC_INTENABLE 0x01
346 #define ECHMC_BRDRESET 0x02
348 #define ECH_PNLSTATUS 2
349 #define ECH_PNL16PORT 0x20
350 #define ECH_PNLIDMASK 0x07
351 #define ECH_PNLXPID 0x40
352 #define ECH_PNLINTRPEND 0x80
353 #define ECH_ADDR2MASK 0x1e0
355 #define EIO_CLK 25000000
356 #define EIO_CLK8M 20000000
357 #define ECH_CLK EIO_CLK
360 * Define the PCI vendor and device ID for Stallion PCI boards.
362 #define STL_PCINSVENDID 0x100b
363 #define STL_PCINSDEVID 0xd001
365 #define STL_PCIVENDID 0x124d
366 #define STL_PCI32DEVID 0x0000
367 #define STL_PCI64DEVID 0x0002
368 #define STL_PCIEIODEVID 0x0003
370 #define STL_PCIBADCLASS 0x0101
372 typedef struct stlpcibrd {
373 unsigned short vendid;
374 unsigned short devid;
378 static stlpcibrd_t stl_pcibrds[] = {
379 { STL_PCIVENDID, STL_PCI64DEVID, BRD_ECH64PCI },
380 { STL_PCIVENDID, STL_PCIEIODEVID, BRD_EASYIOPCI },
381 { STL_PCIVENDID, STL_PCI32DEVID, BRD_ECHPCI },
382 { STL_PCINSVENDID, STL_PCINSDEVID, BRD_ECHPCI },
385 static int stl_nrpcibrds = NELEM(stl_pcibrds);
387 /*****************************************************************************/
390 * Define the vector mapping bits for the programmable interrupt board
391 * hardware. These bits encode the interrupt for the board to use - it
392 * is software selectable (except the EIO-8M).
394 static unsigned char stl_vecmap[] = {
395 0xff, 0xff, 0xff, 0x04, 0x06, 0x05, 0xff, 0x07,
396 0xff, 0xff, 0x00, 0x02, 0x01, 0xff, 0xff, 0x03
400 * Set up enable and disable macros for the ECH boards. They require
401 * the secondary io address space to be activated and deactivated.
402 * This way all ECH boards can share their secondary io region.
403 * If this is an ECH-PCI board then also need to set the page pointer
404 * to point to the correct page.
406 #define BRDENABLE(brdnr,pagenr) \
407 if (stl_brds[(brdnr)]->brdtype == BRD_ECH) \
408 outb(stl_brds[(brdnr)]->ioctrl, \
409 (stl_brds[(brdnr)]->ioctrlval | ECH_BRDENABLE));\
410 else if (stl_brds[(brdnr)]->brdtype == BRD_ECHPCI) \
411 outb(stl_brds[(brdnr)]->ioctrl, (pagenr));
413 #define BRDDISABLE(brdnr) \
414 if (stl_brds[(brdnr)]->brdtype == BRD_ECH) \
415 outb(stl_brds[(brdnr)]->ioctrl, \
416 (stl_brds[(brdnr)]->ioctrlval | ECH_BRDDISABLE));
419 * Define some spare buffer space for un-wanted received characters.
421 static char stl_unwanted[SC26198_RXFIFOSIZE];
423 /*****************************************************************************/
426 * Define macros to extract a brd and port number from a minor number.
427 * This uses the extended minor number range in the upper 2 bytes of
428 * the device number. This gives us plenty of minor numbers to play
431 #define MKDEV2BRD(m) ((minor(m) & 0x00700000) >> 20)
432 #define MKDEV2PORT(m) ((minor(m) & 0x1f) | ((minor(m) & 0x00010000) >> 11))
435 * Define some handy local macros...
438 #define MIN(a,b) (((a) <= (b)) ? (a) : (b))
441 /*****************************************************************************/
444 * Declare all those functions in this driver! First up is the set of
445 * externally visible functions.
448 static d_open_t stlopen;
449 static d_close_t stlclose;
450 static d_ioctl_t stlioctl;
453 * Internal function prototypes.
455 static stlport_t *stl_dev2port(cdev_t dev);
456 static int stl_findfreeunit(void);
457 static int stl_rawopen(stlport_t *portp);
458 static int stl_rawclose(stlport_t *portp);
459 static void stl_flush(stlport_t *portp, int flag);
460 static int stl_param(struct tty *tp, struct termios *tiosp);
461 static void stl_start(struct tty *tp);
462 static void stl_stop(struct tty *tp, int);
463 static void stl_ttyoptim(stlport_t *portp, struct termios *tiosp);
464 static void stl_dotimeout(void);
465 static void stl_poll(void *arg);
466 static void stl_rxprocess(stlport_t *portp);
467 static void stl_flowcontrol(stlport_t *portp, int hw, int sw);
468 static void stl_dtrwakeup(void *arg);
469 static int stl_brdinit(stlbrd_t *brdp);
470 static int stl_initeio(stlbrd_t *brdp);
471 static int stl_initech(stlbrd_t *brdp);
472 static int stl_initports(stlbrd_t *brdp, stlpanel_t *panelp);
473 static void stl_eiointr(stlbrd_t *brdp);
474 static void stl_echatintr(stlbrd_t *brdp);
475 static void stl_echmcaintr(stlbrd_t *brdp);
476 static void stl_echpciintr(stlbrd_t *brdp);
477 static void stl_echpci64intr(stlbrd_t *brdp);
478 static int stl_memioctl(cdev_t dev, unsigned long cmd, caddr_t data,
480 static int stl_getbrdstats(caddr_t data);
481 static int stl_getportstats(stlport_t *portp, caddr_t data);
482 static int stl_clrportstats(stlport_t *portp, caddr_t data);
483 static stlport_t *stl_getport(int brdnr, int panelnr, int portnr);
484 static void stlintr(void *);
486 static const char *stlpciprobe(pcici_t tag, pcidi_t type);
487 static void stlpciattach(pcici_t tag, int unit);
488 static void stlpciintr(void * arg);
491 * CD1400 uart specific handling functions.
493 static void stl_cd1400setreg(stlport_t *portp, int regnr, int value);
494 static int stl_cd1400getreg(stlport_t *portp, int regnr);
495 static int stl_cd1400updatereg(stlport_t *portp, int regnr, int value);
496 static int stl_cd1400panelinit(stlbrd_t *brdp, stlpanel_t *panelp);
497 static void stl_cd1400portinit(stlbrd_t *brdp, stlpanel_t *panelp, stlport_t *portp);
498 static int stl_cd1400setport(stlport_t *portp, struct termios *tiosp);
499 static int stl_cd1400getsignals(stlport_t *portp);
500 static void stl_cd1400setsignals(stlport_t *portp, int dtr, int rts);
501 static void stl_cd1400ccrwait(stlport_t *portp);
502 static void stl_cd1400enablerxtx(stlport_t *portp, int rx, int tx);
503 static void stl_cd1400startrxtx(stlport_t *portp, int rx, int tx);
504 static void stl_cd1400disableintrs(stlport_t *portp);
505 static void stl_cd1400sendbreak(stlport_t *portp, long len);
506 static void stl_cd1400sendflow(stlport_t *portp, int hw, int sw);
507 static int stl_cd1400datastate(stlport_t *portp);
508 static void stl_cd1400flush(stlport_t *portp, int flag);
509 static __inline void stl_cd1400txisr(stlpanel_t *panelp, int ioaddr);
510 static void stl_cd1400rxisr(stlpanel_t *panelp, int ioaddr);
511 static void stl_cd1400mdmisr(stlpanel_t *panelp, int ioaddr);
512 static void stl_cd1400eiointr(stlpanel_t *panelp, unsigned int iobase);
513 static void stl_cd1400echintr(stlpanel_t *panelp, unsigned int iobase);
516 * SC26198 uart specific handling functions.
518 static void stl_sc26198setreg(stlport_t *portp, int regnr, int value);
519 static int stl_sc26198getreg(stlport_t *portp, int regnr);
520 static int stl_sc26198updatereg(stlport_t *portp, int regnr, int value);
521 static int stl_sc26198getglobreg(stlport_t *portp, int regnr);
522 static int stl_sc26198panelinit(stlbrd_t *brdp, stlpanel_t *panelp);
523 static void stl_sc26198portinit(stlbrd_t *brdp, stlpanel_t *panelp, stlport_t *portp);
524 static int stl_sc26198setport(stlport_t *portp, struct termios *tiosp);
525 static int stl_sc26198getsignals(stlport_t *portp);
526 static void stl_sc26198setsignals(stlport_t *portp, int dtr, int rts);
527 static void stl_sc26198enablerxtx(stlport_t *portp, int rx, int tx);
528 static void stl_sc26198startrxtx(stlport_t *portp, int rx, int tx);
529 static void stl_sc26198disableintrs(stlport_t *portp);
530 static void stl_sc26198sendbreak(stlport_t *portp, long len);
531 static void stl_sc26198sendflow(stlport_t *portp, int hw, int sw);
532 static int stl_sc26198datastate(stlport_t *portp);
533 static void stl_sc26198flush(stlport_t *portp, int flag);
534 static void stl_sc26198txunflow(stlport_t *portp);
535 static void stl_sc26198wait(stlport_t *portp);
536 static void stl_sc26198intr(stlpanel_t *panelp, unsigned int iobase);
537 static void stl_sc26198txisr(stlport_t *port);
538 static void stl_sc26198rxisr(stlport_t *port, unsigned int iack);
539 static void stl_sc26198rxgoodchars(stlport_t *portp);
540 static void stl_sc26198rxbadchars(stlport_t *portp);
541 static void stl_sc26198otherisr(stlport_t *port, unsigned int iack);
543 /*****************************************************************************/
546 * Generic UART support structure.
548 typedef struct uart {
549 int (*panelinit)(stlbrd_t *brdp, stlpanel_t *panelp);
550 void (*portinit)(stlbrd_t *brdp, stlpanel_t *panelp, stlport_t *portp);
551 int (*setport)(stlport_t *portp, struct termios *tiosp);
552 int (*getsignals)(stlport_t *portp);
553 void (*setsignals)(stlport_t *portp, int dtr, int rts);
554 void (*enablerxtx)(stlport_t *portp, int rx, int tx);
555 void (*startrxtx)(stlport_t *portp, int rx, int tx);
556 void (*disableintrs)(stlport_t *portp);
557 void (*sendbreak)(stlport_t *portp, long len);
558 void (*sendflow)(stlport_t *portp, int hw, int sw);
559 void (*flush)(stlport_t *portp, int flag);
560 int (*datastate)(stlport_t *portp);
561 void (*intr)(stlpanel_t *panelp, unsigned int iobase);
565 * Define some macros to make calling these functions nice and clean.
567 #define stl_panelinit (* ((uart_t *) panelp->uartp)->panelinit)
568 #define stl_portinit (* ((uart_t *) portp->uartp)->portinit)
569 #define stl_setport (* ((uart_t *) portp->uartp)->setport)
570 #define stl_getsignals (* ((uart_t *) portp->uartp)->getsignals)
571 #define stl_setsignals (* ((uart_t *) portp->uartp)->setsignals)
572 #define stl_enablerxtx (* ((uart_t *) portp->uartp)->enablerxtx)
573 #define stl_startrxtx (* ((uart_t *) portp->uartp)->startrxtx)
574 #define stl_disableintrs (* ((uart_t *) portp->uartp)->disableintrs)
575 #define stl_sendbreak (* ((uart_t *) portp->uartp)->sendbreak)
576 #define stl_sendflow (* ((uart_t *) portp->uartp)->sendflow)
577 #define stl_uartflush (* ((uart_t *) portp->uartp)->flush)
578 #define stl_datastate (* ((uart_t *) portp->uartp)->datastate)
580 /*****************************************************************************/
583 * CD1400 UART specific data initialization.
585 static uart_t stl_cd1400uart = {
589 stl_cd1400getsignals,
590 stl_cd1400setsignals,
591 stl_cd1400enablerxtx,
593 stl_cd1400disableintrs,
602 * Define the offsets within the register bank of a cd1400 based panel.
603 * These io address offsets are common to the EasyIO board as well.
611 #define EREG_BANKSIZE 8
613 #define CD1400_CLK 25000000
614 #define CD1400_CLK8M 20000000
617 * Define the cd1400 baud rate clocks. These are used when calculating
618 * what clock and divisor to use for the required baud rate. Also
619 * define the maximum baud rate allowed, and the default base baud.
621 static int stl_cd1400clkdivs[] = {
622 CD1400_CLK0, CD1400_CLK1, CD1400_CLK2, CD1400_CLK3, CD1400_CLK4
626 * Define the maximum baud rate of the cd1400 devices.
628 #define CD1400_MAXBAUD 230400
630 /*****************************************************************************/
633 * SC26198 UART specific data initization.
635 static uart_t stl_sc26198uart = {
636 stl_sc26198panelinit,
639 stl_sc26198getsignals,
640 stl_sc26198setsignals,
641 stl_sc26198enablerxtx,
642 stl_sc26198startrxtx,
643 stl_sc26198disableintrs,
644 stl_sc26198sendbreak,
647 stl_sc26198datastate,
652 * Define the offsets within the register bank of a sc26198 based panel.
660 #define XP_BANKSIZE 4
663 * Define the sc26198 baud rate table. Offsets within the table
664 * represent the actual baud rate selector of sc26198 registers.
666 static unsigned int sc26198_baudtable[] = {
667 50, 75, 150, 200, 300, 450, 600, 900, 1200, 1800, 2400, 3600,
668 4800, 7200, 9600, 14400, 19200, 28800, 38400, 57600, 115200,
672 #define SC26198_NRBAUDS NELEM(sc26198_baudtable)
675 * Define the maximum baud rate of the sc26198 devices.
677 #define SC26198_MAXBAUD 460800
679 /*****************************************************************************/
682 * Declare the driver pci structure.
684 static unsigned long stl_count;
686 static struct pci_device stlpcidriver = {
694 COMPAT_PCI_DRIVER (stlpci, stlpcidriver);
696 /*****************************************************************************/
699 * FreeBSD-2.2+ kernel linkage.
702 #define CDEV_MAJOR 72
703 static struct dev_ops stl_ops = {
710 .d_kqfilter = ttykqfilter,
711 .d_revoke = ttyrevoke
714 static void stl_drvinit(void *unused)
718 SYSINIT(sidev,SI_SUB_DRIVERS,SI_ORDER_MIDDLE+CDEV_MAJOR,stl_drvinit,NULL)
720 /*****************************************************************************/
723 * Find an available internal board number (unit number). The problem
724 * is that the same unit numbers can be assigned to different boards
725 * detected during the ISA and PCI initialization phases.
728 static int stl_findfreeunit(void)
732 for (i = 0; (i < STL_MAXBRDS); i++)
733 if (stl_brds[i] == NULL)
735 return((i >= STL_MAXBRDS) ? -1 : i);
738 /*****************************************************************************/
741 * Probe specifically for the PCI boards. We need to be a little
742 * carefull here, since it looks sort like a Nat Semi IDE chip...
745 static const char *stlpciprobe(pcici_t tag, pcidi_t type)
751 kprintf("stlpciprobe(tag=%x,type=%x)\n", (int) &tag, (int) type);
755 for (i = 0; (i < stl_nrpcibrds); i++) {
756 if (((type & 0xffff) == stl_pcibrds[i].vendid) &&
757 (((type >> 16) & 0xffff) == stl_pcibrds[i].devid)) {
758 brdtype = stl_pcibrds[i].brdtype;
766 class = pci_conf_read(tag, PCI_CLASS_REG);
767 if ((class & PCI_CLASS_MASK) == PCI_CLASS_MASS_STORAGE)
770 return(stl_brdnames[brdtype]);
773 /*****************************************************************************/
776 * Allocate resources for and initialize the specified PCI board.
779 void stlpciattach(pcici_t tag, int unit)
785 int boardnr, portnr, minor_dev;
788 kprintf("stlpciattach(tag=%x,unit=%x)\n", (int) &tag, unit);
791 brdp = kmalloc(sizeof(stlbrd_t), M_TTYS, M_WAITOK | M_ZERO);
793 if ((unit < 0) || (unit > STL_MAXBRDS)) {
794 kprintf("STALLION: bad PCI board unit number=%d\n", unit);
799 * Allocate us a new driver unique unit number.
801 if ((brdp->brdnr = stl_findfreeunit()) < 0) {
802 kprintf("STALLION: too many boards found, max=%d\n",
806 if (brdp->brdnr >= stl_nrbrds)
807 stl_nrbrds = brdp->brdnr + 1;
810 * Determine what type of PCI board this is...
812 id = (unsigned int) pci_conf_read(tag, 0x0);
813 for (i = 0; (i < stl_nrpcibrds); i++) {
814 if (((id & 0xffff) == stl_pcibrds[i].vendid) &&
815 (((id >> 16) & 0xffff) == stl_pcibrds[i].devid)) {
816 brdp->brdtype = stl_pcibrds[i].brdtype;
821 if (i >= stl_nrpcibrds) {
822 kprintf("STALLION: probed PCI board unknown type=%x\n", id);
826 for (i = 0; (i < 4); i++)
827 bar[i] = (unsigned int) pci_conf_read(tag, 0x10 + (i * 4)) &
830 switch (brdp->brdtype) {
832 brdp->ioaddr1 = bar[1];
833 brdp->ioaddr2 = bar[2];
836 brdp->ioaddr1 = bar[2];
837 brdp->ioaddr2 = bar[1];
840 brdp->ioaddr1 = bar[1];
841 brdp->ioaddr2 = bar[0];
844 kprintf("STALLION: unknown PCI board type=%d\n", brdp->brdtype);
849 brdp->unitid = brdp->brdnr; /* PCI units auto-assigned */
850 brdp->irq = ((int) pci_conf_read(tag, 0x3c)) & 0xff;
852 if (pci_map_int(tag, stlpciintr, NULL) == 0) {
853 kprintf("STALLION: failed to map interrupt irq=%d for unit=%d\n",
854 brdp->irq, brdp->brdnr);
860 /* register devices for DEVFS */
861 boardnr = brdp->brdnr;
862 make_dev(&stl_ops, boardnr + 0x1000000, UID_ROOT, GID_WHEEL,
863 0600, "staliomem%d", boardnr);
865 for (portnr = 0, minor_dev = boardnr * 0x100000;
866 portnr < 32; portnr++, minor_dev++) {
868 make_dev(&stl_ops, minor_dev,
869 UID_ROOT, GID_WHEEL, 0600,
870 "ttyE%d", portnr + (boardnr * 64));
871 make_dev(&stl_ops, minor_dev + 32,
872 UID_ROOT, GID_WHEEL, 0600,
873 "ttyiE%d", portnr + (boardnr * 64));
874 make_dev(&stl_ops, minor_dev + 64,
875 UID_ROOT, GID_WHEEL, 0600,
876 "ttylE%d", portnr + (boardnr * 64));
877 make_dev(&stl_ops, minor_dev + 128,
878 UID_ROOT, GID_WHEEL, 0600,
879 "cue%d", portnr + (boardnr * 64));
880 make_dev(&stl_ops, minor_dev + 160,
881 UID_ROOT, GID_WHEEL, 0600,
882 "cuie%d", portnr + (boardnr * 64));
883 make_dev(&stl_ops, minor_dev + 192,
884 UID_ROOT, GID_WHEEL, 0600,
885 "cule%d", portnr + (boardnr * 64));
888 make_dev(&stl_ops, minor_dev + 0x10000,
889 UID_ROOT, GID_WHEEL, 0600,
890 "ttyE%d", portnr + (boardnr * 64) + 32);
891 make_dev(&stl_ops, minor_dev + 32 + 0x10000,
892 UID_ROOT, GID_WHEEL, 0600,
893 "ttyiE%d", portnr + (boardnr * 64) + 32);
894 make_dev(&stl_ops, minor_dev + 64 + 0x10000,
895 UID_ROOT, GID_WHEEL, 0600,
896 "ttylE%d", portnr + (boardnr * 64) + 32);
897 make_dev(&stl_ops, minor_dev + 128 + 0x10000,
898 UID_ROOT, GID_WHEEL, 0600,
899 "cue%d", portnr + (boardnr * 64) + 32);
900 make_dev(&stl_ops, minor_dev + 160 + 0x10000,
901 UID_ROOT, GID_WHEEL, 0600,
902 "cuie%d", portnr + (boardnr * 64) + 32);
903 make_dev(&stl_ops, minor_dev + 192 + 0x10000,
904 UID_ROOT, GID_WHEEL, 0600,
905 "cule%d", portnr + (boardnr * 64) + 32);
909 /*****************************************************************************/
911 static int stlopen(struct dev_open_args *ap)
913 cdev_t dev = ap->a_head.a_dev;
919 kprintf("stlopen(dev=%x,flag=%x,mode=%x,p=%x)\n", (int) dev, flag,
924 * Firstly check if the supplied device number is a valid device.
926 if (minor(dev) & STL_MEMDEV)
929 portp = stl_dev2port(dev);
932 if (minor(dev) & STL_CTRLDEV)
936 callout = minor(dev) & STL_CALLOUTDEV;
943 * Wait here for the DTR drop timeout period to expire.
945 while (portp->state & ASY_DTRWAIT) {
946 error = tsleep(&portp->dtrwait, PCATCH, "stldtr", 0);
952 * We have a valid device, so now we check if it is already open.
953 * If not then initialize the port hardware and set up the tty
954 * struct as required.
956 if ((tp->t_state & TS_ISOPEN) == 0) {
957 tp->t_oproc = stl_start;
958 tp->t_stop = stl_stop;
959 tp->t_param = stl_param;
961 tp->t_termios = callout ? portp->initouttios :
965 if ((portp->sigs & TIOCM_CD) || callout)
966 (*linesw[tp->t_line].l_modem)(tp, 1);
969 if (portp->callout == 0) {
974 if (portp->callout != 0) {
975 if (ap->a_oflags & O_NONBLOCK) {
979 error = tsleep(&portp->callout,
980 PCATCH, "stlcall", 0);
983 goto stlopen_restart;
986 if ((tp->t_state & TS_XCLUDE) && priv_check_cred(ap->a_cred, PRIV_ROOT, 0)) {
993 * If this port is not the callout device and we do not have carrier
994 * then we need to sleep, waiting for it to be asserted.
996 if (((tp->t_state & TS_CARR_ON) == 0) && !callout &&
997 ((tp->t_cflag & CLOCAL) == 0) &&
998 ((ap->a_oflags & O_NONBLOCK) == 0)) {
1000 error = tsleep(TSA_CARR_ON(tp), PCATCH, "stldcd", 0);
1004 goto stlopen_restart;
1008 * Open the line discipline.
1010 error = (*linesw[tp->t_line].l_open)(dev, tp);
1011 stl_ttyoptim(portp, &tp->t_termios);
1012 if ((tp->t_state & TS_ISOPEN) && callout)
1016 * If for any reason we get to here and the port is not actually
1017 * open then close of the physical hardware - no point leaving it
1018 * active when the open failed...
1022 if (((tp->t_state & TS_ISOPEN) == 0) && (portp->waitopens == 0))
1023 stl_rawclose(portp);
1028 /*****************************************************************************/
1030 static int stlclose(struct dev_close_args *ap)
1032 cdev_t dev = ap->a_head.a_dev;
1037 kprintf("stlclose(dev=%s,flag=%x,mode=%x,p=%p)\n", devtoname(dev),
1038 flag, mode, (void *) p);
1041 if (minor(dev) & STL_MEMDEV)
1043 if (minor(dev) & STL_CTRLDEV)
1046 portp = stl_dev2port(dev);
1052 (*linesw[tp->t_line].l_close)(tp, ap->a_fflag);
1053 stl_ttyoptim(portp, &tp->t_termios);
1054 stl_rawclose(portp);
1060 /*****************************************************************************/
1062 static void stl_stop(struct tty *tp, int rw)
1065 kprintf("stl_stop(tp=%x,rw=%x)\n", (int) tp, rw);
1068 stl_flush((stlport_t *) tp, rw);
1071 /*****************************************************************************/
1073 static int stlioctl(struct dev_ioctl_args *ap)
1075 cdev_t dev = ap->a_head.a_dev;
1076 u_long cmd = ap->a_cmd;
1077 caddr_t data = ap->a_data;
1078 struct termios *newtios, *localtios;
1084 kprintf("stlioctl(dev=%s,cmd=%lx,data=%p,flag=%x)\n",
1085 devtoname(dev), cmd, (void *) data, ap->a_fflag);
1088 if (minor(dev) & STL_MEMDEV)
1089 return(stl_memioctl(dev, cmd, data, ap->a_fflag));
1091 portp = stl_dev2port(dev);
1098 * First up handle ioctls on the control devices.
1100 if (minor(dev) & STL_CTRLDEV) {
1101 if ((minor(dev) & STL_CTRLDEV) == STL_CTRLINIT)
1102 localtios = (minor(dev) & STL_CALLOUTDEV) ?
1103 &portp->initouttios : &portp->initintios;
1104 else if ((minor(dev) & STL_CTRLDEV) == STL_CTRLLOCK)
1105 localtios = (minor(dev) & STL_CALLOUTDEV) ?
1106 &portp->lockouttios : &portp->lockintios;
1112 if ((error = priv_check_cred(ap->a_cred, PRIV_ROOT, 0)) == 0)
1113 *localtios = *((struct termios *) data);
1116 *((struct termios *) data) = *localtios;
1119 *((int *) data) = TTYDISC;
1122 bzero(data, sizeof(struct winsize));
1132 * Deal with 4.3 compatibility issues if we have too...
1134 #if defined(COMPAT_43) || defined(COMPAT_SUNOS)
1136 struct termios tios;
1137 unsigned long oldcmd;
1139 tios = tp->t_termios;
1141 if ((error = ttsetcompat(tp, &cmd, data, &tios)))
1144 data = (caddr_t) &tios;
1149 * Carry out some pre-cmd processing work first...
1150 * Hmmm, not so sure we want this, disable for now...
1152 if ((cmd == TIOCSETA) || (cmd == TIOCSETAW) || (cmd == TIOCSETAF)) {
1153 newtios = (struct termios *) data;
1154 localtios = (minor(dev) & STL_CALLOUTDEV) ?
1155 &portp->lockouttios : &portp->lockintios;
1157 newtios->c_iflag = (tp->t_iflag & localtios->c_iflag) |
1158 (newtios->c_iflag & ~localtios->c_iflag);
1159 newtios->c_oflag = (tp->t_oflag & localtios->c_oflag) |
1160 (newtios->c_oflag & ~localtios->c_oflag);
1161 newtios->c_cflag = (tp->t_cflag & localtios->c_cflag) |
1162 (newtios->c_cflag & ~localtios->c_cflag);
1163 newtios->c_lflag = (tp->t_lflag & localtios->c_lflag) |
1164 (newtios->c_lflag & ~localtios->c_lflag);
1165 for (i = 0; (i < NCCS); i++) {
1166 if (localtios->c_cc[i] != 0)
1167 newtios->c_cc[i] = tp->t_cc[i];
1169 if (localtios->c_ispeed != 0)
1170 newtios->c_ispeed = tp->t_ispeed;
1171 if (localtios->c_ospeed != 0)
1172 newtios->c_ospeed = tp->t_ospeed;
1176 * Call the line discipline and the common command processing to
1177 * process this command (if they can).
1179 error = (*linesw[tp->t_line].l_ioctl)(tp, cmd, data,
1180 ap->a_fflag, ap->a_cred);
1181 if (error != ENOIOCTL)
1185 error = ttioctl(tp, cmd, data, ap->a_fflag);
1186 stl_ttyoptim(portp, &tp->t_termios);
1187 if (error != ENOIOCTL) {
1195 * Process local commands here. These are all commands that only we
1196 * can take care of (they all rely on actually doing something special
1197 * to the actual hardware).
1201 stl_sendbreak(portp, -1);
1204 stl_sendbreak(portp, -2);
1207 stl_setsignals(portp, 1, -1);
1210 stl_setsignals(portp, 0, -1);
1213 i = *((int *) data);
1214 stl_setsignals(portp, ((i & TIOCM_DTR) ? 1 : 0),
1215 ((i & TIOCM_RTS) ? 1 : 0));
1218 i = *((int *) data);
1219 stl_setsignals(portp, ((i & TIOCM_DTR) ? 1 : -1),
1220 ((i & TIOCM_RTS) ? 1 : -1));
1223 i = *((int *) data);
1224 stl_setsignals(portp, ((i & TIOCM_DTR) ? 0 : -1),
1225 ((i & TIOCM_RTS) ? 0 : -1));
1228 *((int *) data) = (stl_getsignals(portp) | TIOCM_LE);
1231 if ((error = priv_check_cred(ap->a_cred, PRIV_ROOT, 0)) == 0)
1232 portp->dtrwait = *((int *) data) * hz / 100;
1235 *((int *) data) = portp->dtrwait * 100 / hz;
1238 portp->dotimestamp = 1;
1239 *((struct timeval *) data) = portp->timestamp;
1249 /*****************************************************************************/
1252 * Convert the specified minor device number into a port struct
1253 * pointer. Return NULL if the device number is not a valid port.
1256 static stlport_t *stl_dev2port(cdev_t dev)
1260 brdp = stl_brds[MKDEV2BRD(dev)];
1263 return(brdp->ports[MKDEV2PORT(dev)]);
1266 /*****************************************************************************/
1269 * Initialize the port hardware. This involves enabling the transmitter
1270 * and receiver, setting the port configuration, and setting the initial
1274 static int stl_rawopen(stlport_t *portp)
1277 kprintf("stl_rawopen(portp=%p): brdnr=%d panelnr=%d portnr=%d\n",
1278 (void *) portp, portp->brdnr, portp->panelnr, portp->portnr);
1281 stl_setport(portp, &portp->tty.t_termios);
1282 portp->sigs = stl_getsignals(portp);
1283 stl_setsignals(portp, 1, 1);
1284 stl_enablerxtx(portp, 1, 1);
1285 stl_startrxtx(portp, 1, 0);
1289 /*****************************************************************************/
1292 * Shutdown the hardware of a port. Disable its transmitter and
1293 * receiver, and maybe drop signals if appropriate.
1296 static int stl_rawclose(stlport_t *portp)
1301 kprintf("stl_rawclose(portp=%p): brdnr=%d panelnr=%d portnr=%d\n",
1302 (void *) portp, portp->brdnr, portp->panelnr, portp->portnr);
1306 stl_disableintrs(portp);
1307 stl_enablerxtx(portp, 0, 0);
1308 stl_flush(portp, (FWRITE | FREAD));
1309 if (tp->t_cflag & HUPCL) {
1310 stl_setsignals(portp, 0, 0);
1311 if (portp->dtrwait != 0) {
1312 portp->state |= ASY_DTRWAIT;
1313 callout_reset(&portp->dtr_ch, portp->dtrwait,
1314 stl_dtrwakeup, portp);
1319 portp->state &= ~(ASY_ACTIVE | ASY_RTSFLOW);
1320 wakeup(&portp->callout);
1321 wakeup(TSA_CARR_ON(tp));
1325 /*****************************************************************************/
1328 * Clear the DTR waiting flag, and wake up any sleepers waiting for
1329 * DTR wait period to finish.
1332 static void stl_dtrwakeup(void *arg)
1336 portp = (stlport_t *) arg;
1337 portp->state &= ~ASY_DTRWAIT;
1338 wakeup(&portp->dtrwait);
1341 /*****************************************************************************/
1344 * Start (or continue) the transfer of TX data on this port. If the
1345 * port is not currently busy then load up the interrupt ring queue
1346 * buffer and kick of the transmitter. If the port is running low on
1347 * TX data then refill the ring queue. This routine is also used to
1348 * activate input flow control!
1351 static void stl_start(struct tty *tp)
1354 unsigned int len, stlen;
1358 portp = (stlport_t *) tp;
1361 kprintf("stl_start(tp=%x): brdnr=%d portnr=%d\n", (int) tp,
1362 portp->brdnr, portp->portnr);
1368 * Check if the ports input has been blocked, and take appropriate action.
1369 * Not very often do we really need to do anything, so make it quick.
1371 if (tp->t_state & TS_TBLOCK) {
1372 if ((portp->state & ASY_RTSFLOWMODE) &&
1373 ((portp->state & ASY_RTSFLOW) == 0))
1374 stl_flowcontrol(portp, 0, -1);
1376 if (portp->state & ASY_RTSFLOW)
1377 stl_flowcontrol(portp, 1, -1);
1380 if (tp->t_state & (TS_TIMEOUT | TS_TTSTOP)) {
1386 * Copy data from the clists into the interrupt ring queue. This will
1387 * require at most 2 copys... What we do is calculate how many chars
1388 * can fit into the ring queue, and how many can fit in 1 copy. If after
1389 * the first copy there is still more room then do the second copy.
1390 * The beauty of this type of ring queue is that we do not need to
1391 * spl protect our-selves, since we only ever update the head pointer,
1392 * and the interrupt routine only ever updates the tail pointer.
1394 if (tp->t_outq.c_cc != 0) {
1395 head = portp->tx.head;
1396 tail = portp->tx.tail;
1398 len = STL_TXBUFSIZE - (head - tail) - 1;
1399 stlen = portp->tx.endbuf - head;
1401 len = tail - head - 1;
1406 stlen = MIN(len, stlen);
1407 count = q_to_b(&tp->t_outq, head, stlen);
1410 if (head >= portp->tx.endbuf) {
1411 head = portp->tx.buf;
1413 stlen = q_to_b(&tp->t_outq, head, len);
1418 portp->tx.head = head;
1420 stl_startrxtx(portp, -1, 1);
1424 * If we sent something, make sure we are called again.
1426 tp->t_state |= TS_BUSY;
1430 * Do any writer wakeups.
1437 /*****************************************************************************/
1439 static void stl_flush(stlport_t *portp, int flag)
1445 kprintf("stl_flush(portp=%x,flag=%x)\n", (int) portp, flag);
1453 if (flag & FWRITE) {
1454 stl_uartflush(portp, FWRITE);
1455 portp->tx.tail = portp->tx.head;
1459 * The only thing to watch out for when flushing the read side is
1460 * the RX status buffer. The interrupt code relys on the status
1461 * bytes as being zeroed all the time (it does not bother setting
1462 * a good char status to 0, it expects that it already will be).
1463 * We also need to un-flow the RX channel if flow control was
1467 head = portp->rx.head;
1468 tail = portp->rx.tail;
1473 len = portp->rx.endbuf - tail;
1474 bzero(portp->rxstatus.buf,
1475 (head - portp->rx.buf));
1477 bzero((tail + STL_RXBUFSIZE), len);
1478 portp->rx.tail = head;
1481 if ((portp->state & ASY_RTSFLOW) &&
1482 ((portp->tty.t_state & TS_TBLOCK) == 0))
1483 stl_flowcontrol(portp, 1, -1);
1489 /*****************************************************************************/
1492 * Interrupt handler for host based boards. Interrupts for all boards
1493 * are vectored through here.
1496 void stlintr(void *arg)
1502 kprintf("stlintr(unit=%d)\n", (int)arg);
1505 for (i = 0; (i < stl_nrbrds); i++) {
1506 if ((brdp = stl_brds[i]) == NULL)
1508 if (brdp->state == 0)
1510 (* brdp->isr)(brdp);
1514 /*****************************************************************************/
1516 static void stlpciintr(void *arg)
1521 /*****************************************************************************/
1524 * Interrupt service routine for EasyIO boards.
1527 static void stl_eiointr(stlbrd_t *brdp)
1533 kprintf("stl_eiointr(brdp=%p)\n", brdp);
1536 panelp = brdp->panels[0];
1537 iobase = panelp->iobase;
1538 while (inb(brdp->iostatus) & EIO_INTRPEND)
1539 (* panelp->isr)(panelp, iobase);
1543 * Interrupt service routine for ECH-AT board types.
1546 static void stl_echatintr(stlbrd_t *brdp)
1549 unsigned int ioaddr;
1552 outb(brdp->ioctrl, (brdp->ioctrlval | ECH_BRDENABLE));
1554 while (inb(brdp->iostatus) & ECH_INTRPEND) {
1555 for (bnknr = 0; (bnknr < brdp->nrbnks); bnknr++) {
1556 ioaddr = brdp->bnkstataddr[bnknr];
1557 if (inb(ioaddr) & ECH_PNLINTRPEND) {
1558 panelp = brdp->bnk2panel[bnknr];
1559 (* panelp->isr)(panelp, (ioaddr & 0xfffc));
1564 outb(brdp->ioctrl, (brdp->ioctrlval | ECH_BRDDISABLE));
1567 /*****************************************************************************/
1570 * Interrupt service routine for ECH-MCA board types.
1573 static void stl_echmcaintr(stlbrd_t *brdp)
1576 unsigned int ioaddr;
1579 while (inb(brdp->iostatus) & ECH_INTRPEND) {
1580 for (bnknr = 0; (bnknr < brdp->nrbnks); bnknr++) {
1581 ioaddr = brdp->bnkstataddr[bnknr];
1582 if (inb(ioaddr) & ECH_PNLINTRPEND) {
1583 panelp = brdp->bnk2panel[bnknr];
1584 (* panelp->isr)(panelp, (ioaddr & 0xfffc));
1590 /*****************************************************************************/
1593 * Interrupt service routine for ECH-PCI board types.
1596 static void stl_echpciintr(stlbrd_t *brdp)
1599 unsigned int ioaddr;
1603 kprintf("stl_echpciintr(brdp=%x)\n", (int) brdp);
1608 for (bnknr = 0; (bnknr < brdp->nrbnks); bnknr++) {
1609 outb(brdp->ioctrl, brdp->bnkpageaddr[bnknr]);
1610 ioaddr = brdp->bnkstataddr[bnknr];
1611 if (inb(ioaddr) & ECH_PNLINTRPEND) {
1612 panelp = brdp->bnk2panel[bnknr];
1613 (* panelp->isr)(panelp, (ioaddr & 0xfffc));
1622 /*****************************************************************************/
1625 * Interrupt service routine for EC8/64-PCI board types.
1628 static void stl_echpci64intr(stlbrd_t *brdp)
1631 unsigned int ioaddr;
1635 kprintf("stl_echpci64intr(brdp=%p)\n", brdp);
1638 while (inb(brdp->ioctrl) & 0x1) {
1639 for (bnknr = 0; (bnknr < brdp->nrbnks); bnknr++) {
1640 ioaddr = brdp->bnkstataddr[bnknr];
1642 kprintf(" --> ioaddr=%x status=%x(%x)\n", ioaddr, inb(ioaddr) & ECH_PNLINTRPEND, inb(ioaddr));
1644 if (inb(ioaddr) & ECH_PNLINTRPEND) {
1645 panelp = brdp->bnk2panel[bnknr];
1646 (* panelp->isr)(panelp, (ioaddr & 0xfffc));
1652 /*****************************************************************************/
1655 * If we haven't scheduled a timeout then do it, some port needs high
1659 static void stl_dotimeout(void)
1662 kprintf("stl_dotimeout()\n");
1664 if (stl_doingtimeout == 0) {
1665 if ((stl_poll_ch.c_flags & CALLOUT_DID_INIT) == 0)
1666 callout_init(&stl_poll_ch);
1667 callout_reset(&stl_poll_ch, 1, stl_poll, NULL);
1672 /*****************************************************************************/
1675 * Service "software" level processing. Too slow or painfull to be done
1676 * at real hardware interrupt time. This way we might also be able to
1677 * do some service on other waiting ports as well...
1680 static void stl_poll(void *arg)
1685 int brdnr, portnr, rearm;
1688 kprintf("stl_poll()\n");
1691 stl_doingtimeout = 0;
1695 for (brdnr = 0; (brdnr < stl_nrbrds); brdnr++) {
1696 if ((brdp = stl_brds[brdnr]) == NULL)
1698 for (portnr = 0; (portnr < brdp->nrports); portnr++) {
1699 if ((portp = brdp->ports[portnr]) == NULL)
1701 if ((portp->state & ASY_ACTIVE) == 0)
1705 if (portp->state & ASY_RXDATA)
1706 stl_rxprocess(portp);
1707 if (portp->state & ASY_DCDCHANGE) {
1708 portp->state &= ~ASY_DCDCHANGE;
1709 portp->sigs = stl_getsignals(portp);
1710 (*linesw[tp->t_line].l_modem)(tp,
1711 (portp->sigs & TIOCM_CD));
1713 if (portp->state & ASY_TXEMPTY) {
1714 if (stl_datastate(portp) == 0) {
1715 portp->state &= ~ASY_TXEMPTY;
1716 tp->t_state &= ~TS_BUSY;
1717 (*linesw[tp->t_line].l_start)(tp);
1720 if (portp->state & ASY_TXLOW) {
1721 portp->state &= ~ASY_TXLOW;
1722 (*linesw[tp->t_line].l_start)(tp);
1725 if (portp->state & ASY_ACTIVE)
1735 /*****************************************************************************/
1738 * Process the RX data that has been buffered up in the RX ring queue.
1741 static void stl_rxprocess(stlport_t *portp)
1744 unsigned int len, stlen, lostlen;
1750 kprintf("stl_rxprocess(portp=%x): brdnr=%d portnr=%d\n", (int) portp,
1751 portp->brdnr, portp->portnr);
1755 portp->state &= ~ASY_RXDATA;
1757 if ((tp->t_state & TS_ISOPEN) == 0) {
1758 stl_flush(portp, FREAD);
1763 * Calculate the amount of data in the RX ring queue. Also calculate
1764 * the largest single copy size...
1766 head = portp->rx.head;
1767 tail = portp->rx.tail;
1772 len = STL_RXBUFSIZE - (tail - head);
1773 stlen = portp->rx.endbuf - tail;
1776 if (tp->t_state & TS_CAN_BYPASS_L_RINT) {
1778 if (((tp->t_rawq.c_cc + len) >= TTYHOG) &&
1779 ((portp->state & ASY_RTSFLOWMODE) ||
1780 (tp->t_iflag & IXOFF)) &&
1781 ((tp->t_state & TS_TBLOCK) == 0)) {
1782 ch = TTYHOG - tp->t_rawq.c_cc - 1;
1783 len = (ch > 0) ? ch : 0;
1784 stlen = MIN(stlen, len);
1787 lostlen = b_to_q(tail, stlen, &tp->t_rawq);
1790 if (tail >= portp->rx.endbuf) {
1791 tail = portp->rx.buf;
1792 lostlen += b_to_q(tail, len, &tp->t_rawq);
1795 portp->stats.rxlost += lostlen;
1797 portp->rx.tail = tail;
1800 while (portp->rx.tail != head) {
1801 ch = (unsigned char) *(portp->rx.tail);
1802 status = *(portp->rx.tail + STL_RXBUFSIZE);
1804 *(portp->rx.tail + STL_RXBUFSIZE) = 0;
1805 if (status & ST_BREAK)
1807 if (status & ST_FRAMING)
1809 if (status & ST_PARITY)
1811 if (status & ST_OVERRUN)
1814 (*linesw[tp->t_line].l_rint)(ch, tp);
1815 if (portp->rx.tail == head)
1818 if (++(portp->rx.tail) >= portp->rx.endbuf)
1819 portp->rx.tail = portp->rx.buf;
1823 if (head != portp->rx.tail)
1824 portp->state |= ASY_RXDATA;
1827 * If we were flow controled then maybe the buffer is low enough that
1828 * we can re-activate it.
1830 if ((portp->state & ASY_RTSFLOW) && ((tp->t_state & TS_TBLOCK) == 0))
1831 stl_flowcontrol(portp, 1, -1);
1834 /*****************************************************************************/
1836 static int stl_param(struct tty *tp, struct termios *tiosp)
1840 portp = (stlport_t *) tp;
1844 return(stl_setport(portp, tiosp));
1847 /*****************************************************************************/
1850 * Action the flow control as required. The hw and sw args inform the
1851 * routine what flow control methods it should try.
1854 static void stl_flowcontrol(stlport_t *portp, int hw, int sw)
1856 unsigned char *head, *tail;
1860 kprintf("stl_flowcontrol(portp=%x,hw=%d,sw=%d)\n", (int) portp, hw, sw);
1865 if (portp->state & ASY_RTSFLOWMODE) {
1867 if ((portp->state & ASY_RTSFLOW) == 0)
1869 } else if (hw > 0) {
1870 if (portp->state & ASY_RTSFLOW) {
1871 head = portp->rx.head;
1872 tail = portp->rx.tail;
1873 len = (head >= tail) ? (head - tail) :
1874 (STL_RXBUFSIZE - (tail - head));
1875 if (len < STL_RXBUFHIGH)
1882 * We have worked out what to do, if anything. So now apply it to the
1885 stl_sendflow(portp, hwflow, sw);
1888 /*****************************************************************************/
1891 * Enable l_rint processing bypass mode if tty modes allow it.
1894 static void stl_ttyoptim(stlport_t *portp, struct termios *tiosp)
1899 if (((tiosp->c_iflag &
1900 (ICRNL | IGNCR | IMAXBEL | INLCR | ISTRIP)) == 0) &&
1901 (((tiosp->c_iflag & BRKINT) == 0) || (tiosp->c_iflag & IGNBRK)) &&
1902 (((tiosp->c_iflag & PARMRK) == 0) ||
1903 ((tiosp->c_iflag & (IGNPAR | IGNBRK)) == (IGNPAR | IGNBRK))) &&
1904 ((tiosp->c_lflag & (ECHO | ICANON | IEXTEN | ISIG | PENDIN)) ==0) &&
1905 (linesw[tp->t_line].l_rint == ttyinput))
1906 tp->t_state |= TS_CAN_BYPASS_L_RINT;
1908 tp->t_state &= ~TS_CAN_BYPASS_L_RINT;
1909 portp->hotchar = linesw[tp->t_line].l_hotchar;
1912 /*****************************************************************************/
1915 * Try and find and initialize all the ports on a panel. We don't care
1916 * what sort of board these ports are on - since the port io registers
1917 * are almost identical when dealing with ports.
1920 static int stl_initports(stlbrd_t *brdp, stlpanel_t *panelp)
1923 unsigned int chipmask;
1927 kprintf("stl_initports(panelp=%x)\n", (int) panelp);
1930 chipmask = stl_panelinit(brdp, panelp);
1933 * All UART's are initialized if found. Now go through and setup
1934 * each ports data structures. Also initialize each individual
1937 for (i = 0; (i < panelp->nrports); i++) {
1938 portp = kmalloc(sizeof(stlport_t), M_TTYS, M_WAITOK | M_ZERO);
1941 portp->brdnr = panelp->brdnr;
1942 portp->panelnr = panelp->panelnr;
1943 portp->uartp = panelp->uartp;
1944 portp->clk = brdp->clk;
1945 panelp->ports[i] = portp;
1947 j = STL_TXBUFSIZE + (2 * STL_RXBUFSIZE);
1948 portp->tx.buf = kmalloc(j, M_TTYS, M_WAITOK);
1949 portp->tx.endbuf = portp->tx.buf + STL_TXBUFSIZE;
1950 portp->tx.head = portp->tx.buf;
1951 portp->tx.tail = portp->tx.buf;
1952 portp->rx.buf = portp->tx.buf + STL_TXBUFSIZE;
1953 portp->rx.endbuf = portp->rx.buf + STL_RXBUFSIZE;
1954 portp->rx.head = portp->rx.buf;
1955 portp->rx.tail = portp->rx.buf;
1956 portp->rxstatus.buf = portp->rx.buf + STL_RXBUFSIZE;
1957 portp->rxstatus.endbuf = portp->rxstatus.buf + STL_RXBUFSIZE;
1958 portp->rxstatus.head = portp->rxstatus.buf;
1959 portp->rxstatus.tail = portp->rxstatus.buf;
1960 bzero(portp->rxstatus.head, STL_RXBUFSIZE);
1962 portp->initintios.c_ispeed = STL_DEFSPEED;
1963 portp->initintios.c_ospeed = STL_DEFSPEED;
1964 portp->initintios.c_cflag = STL_DEFCFLAG;
1965 portp->initintios.c_iflag = 0;
1966 portp->initintios.c_oflag = 0;
1967 portp->initintios.c_lflag = 0;
1968 bcopy(&ttydefchars[0], &portp->initintios.c_cc[0],
1969 sizeof(portp->initintios.c_cc));
1970 portp->initouttios = portp->initintios;
1971 portp->dtrwait = 3 * hz;
1972 callout_init(&portp->dtr_ch);
1974 stl_portinit(brdp, panelp, portp);
1980 /*****************************************************************************/
1983 * Try to find and initialize an EasyIO board.
1986 static int stl_initeio(stlbrd_t *brdp)
1989 unsigned int status;
1992 kprintf("stl_initeio(brdp=%x)\n", (int) brdp);
1995 brdp->ioctrl = brdp->ioaddr1 + 1;
1996 brdp->iostatus = brdp->ioaddr1 + 2;
1997 brdp->clk = EIO_CLK;
1998 brdp->isr = stl_eiointr;
2000 status = inb(brdp->iostatus);
2001 switch (status & EIO_IDBITMASK) {
2003 brdp->clk = EIO_CLK8M;
2013 switch (status & EIO_BRDMASK) {
2032 if (brdp->brdtype == BRD_EASYIOPCI) {
2033 outb((brdp->ioaddr2 + 0x4c), 0x41);
2036 * Check that the supplied IRQ is good and then use it to setup the
2037 * programmable interrupt bits on EIO board. Also set the edge/level
2038 * triggered interrupt bit.
2040 if ((brdp->irq < 0) || (brdp->irq > 15) ||
2041 (stl_vecmap[brdp->irq] == (unsigned char) 0xff)) {
2042 kprintf("STALLION: invalid irq=%d for brd=%d\n",
2043 brdp->irq, brdp->brdnr);
2046 outb(brdp->ioctrl, (stl_vecmap[brdp->irq] |
2047 ((brdp->irqtype) ? EIO_INTLEVEL : EIO_INTEDGE)));
2050 panelp = kmalloc(sizeof(stlpanel_t), M_TTYS, M_WAITOK | M_ZERO);
2051 panelp->brdnr = brdp->brdnr;
2052 panelp->panelnr = 0;
2053 panelp->nrports = brdp->nrports;
2054 panelp->iobase = brdp->ioaddr1;
2055 panelp->hwid = status;
2056 if ((status & EIO_IDBITMASK) == EIO_MK3) {
2057 panelp->uartp = (void *) &stl_sc26198uart;
2058 panelp->isr = stl_sc26198intr;
2060 panelp->uartp = (void *) &stl_cd1400uart;
2061 panelp->isr = stl_cd1400eiointr;
2063 brdp->panels[0] = panelp;
2065 brdp->hwid = status;
2066 brdp->state |= BRD_FOUND;
2070 /*****************************************************************************/
2073 * Try to find an ECH board and initialize it. This code is capable of
2074 * dealing with all types of ECH board.
2077 static int stl_initech(stlbrd_t *brdp)
2080 unsigned int status, nxtid;
2081 int panelnr, ioaddr, banknr, i;
2084 kprintf("stl_initech(brdp=%x)\n", (int) brdp);
2088 * Set up the initial board register contents for boards. This varys a
2089 * bit between the different board types. So we need to handle each
2090 * separately. Also do a check that the supplied IRQ is good.
2092 switch (brdp->brdtype) {
2095 brdp->isr = stl_echatintr;
2096 brdp->ioctrl = brdp->ioaddr1 + 1;
2097 brdp->iostatus = brdp->ioaddr1 + 1;
2098 status = inb(brdp->iostatus);
2099 if ((status & ECH_IDBITMASK) != ECH_ID)
2101 brdp->hwid = status;
2103 if ((brdp->irq < 0) || (brdp->irq > 15) ||
2104 (stl_vecmap[brdp->irq] == (unsigned char) 0xff)) {
2105 kprintf("STALLION: invalid irq=%d for brd=%d\n",
2106 brdp->irq, brdp->brdnr);
2109 status = ((brdp->ioaddr2 & ECH_ADDR2MASK) >> 1);
2110 status |= (stl_vecmap[brdp->irq] << 1);
2111 outb(brdp->ioaddr1, (status | ECH_BRDRESET));
2112 brdp->ioctrlval = ECH_INTENABLE |
2113 ((brdp->irqtype) ? ECH_INTLEVEL : ECH_INTEDGE);
2114 outb(brdp->ioctrl, (brdp->ioctrlval | ECH_BRDENABLE));
2115 outb(brdp->ioaddr1, status);
2119 brdp->isr = stl_echmcaintr;
2120 brdp->ioctrl = brdp->ioaddr1 + 0x20;
2121 brdp->iostatus = brdp->ioctrl;
2122 status = inb(brdp->iostatus);
2123 if ((status & ECH_IDBITMASK) != ECH_ID)
2125 brdp->hwid = status;
2127 if ((brdp->irq < 0) || (brdp->irq > 15) ||
2128 (stl_vecmap[brdp->irq] == (unsigned char) 0xff)) {
2129 kprintf("STALLION: invalid irq=%d for brd=%d\n",
2130 brdp->irq, brdp->brdnr);
2133 outb(brdp->ioctrl, ECHMC_BRDRESET);
2134 outb(brdp->ioctrl, ECHMC_INTENABLE);
2138 brdp->isr = stl_echpciintr;
2139 brdp->ioctrl = brdp->ioaddr1 + 2;
2143 brdp->isr = stl_echpci64intr;
2144 brdp->ioctrl = brdp->ioaddr2 + 0x40;
2145 outb((brdp->ioaddr1 + 0x4c), 0x43);
2149 kprintf("STALLION: unknown board type=%d\n", brdp->brdtype);
2153 brdp->clk = ECH_CLK;
2156 * Scan through the secondary io address space looking for panels.
2157 * As we find'em allocate and initialize panel structures for each.
2159 ioaddr = brdp->ioaddr2;
2164 for (i = 0; (i < STL_MAXPANELS); i++) {
2165 if (brdp->brdtype == BRD_ECHPCI) {
2166 outb(brdp->ioctrl, nxtid);
2167 ioaddr = brdp->ioaddr2;
2169 status = inb(ioaddr + ECH_PNLSTATUS);
2170 if ((status & ECH_PNLIDMASK) != nxtid)
2172 panelp = kmalloc(sizeof(stlpanel_t), M_TTYS, M_WAITOK | M_ZERO);
2173 panelp->brdnr = brdp->brdnr;
2174 panelp->panelnr = panelnr;
2175 panelp->iobase = ioaddr;
2176 panelp->pagenr = nxtid;
2177 panelp->hwid = status;
2178 brdp->bnk2panel[banknr] = panelp;
2179 brdp->bnkpageaddr[banknr] = nxtid;
2180 brdp->bnkstataddr[banknr++] = ioaddr + ECH_PNLSTATUS;
2182 if (status & ECH_PNLXPID) {
2183 panelp->uartp = (void *) &stl_sc26198uart;
2184 panelp->isr = stl_sc26198intr;
2185 if (status & ECH_PNL16PORT) {
2186 panelp->nrports = 16;
2187 brdp->bnk2panel[banknr] = panelp;
2188 brdp->bnkpageaddr[banknr] = nxtid;
2189 brdp->bnkstataddr[banknr++] = ioaddr + 4 +
2192 panelp->nrports = 8;
2195 panelp->uartp = (void *) &stl_cd1400uart;
2196 panelp->isr = stl_cd1400echintr;
2197 if (status & ECH_PNL16PORT) {
2198 panelp->nrports = 16;
2199 panelp->ackmask = 0x80;
2200 if (brdp->brdtype != BRD_ECHPCI)
2201 ioaddr += EREG_BANKSIZE;
2202 brdp->bnk2panel[banknr] = panelp;
2203 brdp->bnkpageaddr[banknr] = ++nxtid;
2204 brdp->bnkstataddr[banknr++] = ioaddr +
2207 panelp->nrports = 8;
2208 panelp->ackmask = 0xc0;
2213 ioaddr += EREG_BANKSIZE;
2214 brdp->nrports += panelp->nrports;
2215 brdp->panels[panelnr++] = panelp;
2216 if ((brdp->brdtype == BRD_ECH) || (brdp->brdtype == BRD_ECHMC)){
2217 if (ioaddr >= (brdp->ioaddr2 + 0x20)) {
2218 kprintf("STALLION: too many ports attached "
2219 "to board %d, remove last module\n",
2226 brdp->nrpanels = panelnr;
2227 brdp->nrbnks = banknr;
2228 if (brdp->brdtype == BRD_ECH)
2229 outb(brdp->ioctrl, (brdp->ioctrlval | ECH_BRDDISABLE));
2231 brdp->state |= BRD_FOUND;
2235 /*****************************************************************************/
2238 * Initialize and configure the specified board. This firstly probes
2239 * for the board, if it is found then the board is initialized and
2240 * then all its ports are initialized as well.
2243 static int stl_brdinit(stlbrd_t *brdp)
2249 kprintf("stl_brdinit(brdp=%x): unit=%d type=%d io1=%x io2=%x irq=%d\n",
2250 (int) brdp, brdp->brdnr, brdp->brdtype, brdp->ioaddr1,
2251 brdp->ioaddr2, brdp->irq);
2254 switch (brdp->brdtype) {
2266 kprintf("STALLION: unit=%d is unknown board type=%d\n",
2267 brdp->brdnr, brdp->brdtype);
2271 stl_brds[brdp->brdnr] = brdp;
2272 if ((brdp->state & BRD_FOUND) == 0) {
2274 kprintf("STALLION: %s board not found, unit=%d io=%x irq=%d\n",
2275 stl_brdnames[brdp->brdtype], brdp->brdnr,
2276 brdp->ioaddr1, brdp->irq);
2281 for (i = 0, k = 0; (i < STL_MAXPANELS); i++) {
2282 panelp = brdp->panels[i];
2283 if (panelp != NULL) {
2284 stl_initports(brdp, panelp);
2285 for (j = 0; (j < panelp->nrports); j++)
2286 brdp->ports[k++] = panelp->ports[j];
2290 kprintf("stl%d: %s (driver version %s) unit=%d nrpanels=%d nrports=%d\n",
2291 brdp->unitid, stl_brdnames[brdp->brdtype], stl_drvversion,
2292 brdp->brdnr, brdp->nrpanels, brdp->nrports);
2296 /*****************************************************************************/
2299 * Return the board stats structure to user app.
2302 static int stl_getbrdstats(caddr_t data)
2308 stl_brdstats = *((combrd_t *) data);
2309 if (stl_brdstats.brd >= STL_MAXBRDS)
2311 brdp = stl_brds[stl_brdstats.brd];
2315 bzero(&stl_brdstats, sizeof(combrd_t));
2316 stl_brdstats.brd = brdp->brdnr;
2317 stl_brdstats.type = brdp->brdtype;
2318 stl_brdstats.hwid = brdp->hwid;
2319 stl_brdstats.state = brdp->state;
2320 stl_brdstats.ioaddr = brdp->ioaddr1;
2321 stl_brdstats.ioaddr2 = brdp->ioaddr2;
2322 stl_brdstats.irq = brdp->irq;
2323 stl_brdstats.nrpanels = brdp->nrpanels;
2324 stl_brdstats.nrports = brdp->nrports;
2325 for (i = 0; (i < brdp->nrpanels); i++) {
2326 panelp = brdp->panels[i];
2327 stl_brdstats.panels[i].panel = i;
2328 stl_brdstats.panels[i].hwid = panelp->hwid;
2329 stl_brdstats.panels[i].nrports = panelp->nrports;
2332 *((combrd_t *) data) = stl_brdstats;
2336 /*****************************************************************************/
2339 * Resolve the referenced port number into a port struct pointer.
2342 static stlport_t *stl_getport(int brdnr, int panelnr, int portnr)
2347 if ((brdnr < 0) || (brdnr >= STL_MAXBRDS))
2349 brdp = stl_brds[brdnr];
2352 if ((panelnr < 0) || (panelnr >= brdp->nrpanels))
2354 panelp = brdp->panels[panelnr];
2357 if ((portnr < 0) || (portnr >= panelp->nrports))
2359 return(panelp->ports[portnr]);
2362 /*****************************************************************************/
2365 * Return the port stats structure to user app. A NULL port struct
2366 * pointer passed in means that we need to find out from the app
2367 * what port to get stats for (used through board control device).
2370 static int stl_getportstats(stlport_t *portp, caddr_t data)
2372 unsigned char *head, *tail;
2374 if (portp == NULL) {
2375 stl_comstats = *((comstats_t *) data);
2376 portp = stl_getport(stl_comstats.brd, stl_comstats.panel,
2382 portp->stats.state = portp->state;
2383 /*portp->stats.flags = portp->flags;*/
2384 portp->stats.hwid = portp->hwid;
2385 portp->stats.ttystate = portp->tty.t_state;
2386 portp->stats.cflags = portp->tty.t_cflag;
2387 portp->stats.iflags = portp->tty.t_iflag;
2388 portp->stats.oflags = portp->tty.t_oflag;
2389 portp->stats.lflags = portp->tty.t_lflag;
2391 head = portp->tx.head;
2392 tail = portp->tx.tail;
2393 portp->stats.txbuffered = ((head >= tail) ? (head - tail) :
2394 (STL_TXBUFSIZE - (tail - head)));
2396 head = portp->rx.head;
2397 tail = portp->rx.tail;
2398 portp->stats.rxbuffered = (head >= tail) ? (head - tail) :
2399 (STL_RXBUFSIZE - (tail - head));
2401 portp->stats.signals = (unsigned long) stl_getsignals(portp);
2403 *((comstats_t *) data) = portp->stats;
2407 /*****************************************************************************/
2410 * Clear the port stats structure. We also return it zeroed out...
2413 static int stl_clrportstats(stlport_t *portp, caddr_t data)
2415 if (portp == NULL) {
2416 stl_comstats = *((comstats_t *) data);
2417 portp = stl_getport(stl_comstats.brd, stl_comstats.panel,
2423 bzero(&portp->stats, sizeof(comstats_t));
2424 portp->stats.brd = portp->brdnr;
2425 portp->stats.panel = portp->panelnr;
2426 portp->stats.port = portp->portnr;
2427 *((comstats_t *) data) = stl_comstats;
2431 /*****************************************************************************/
2434 * The "staliomem" device is used for stats collection in this driver.
2437 static int stl_memioctl(cdev_t dev, unsigned long cmd, caddr_t data, int flag)
2442 kprintf("stl_memioctl(dev=%s,cmd=%lx,data=%p,flag=%x)\n",
2443 devtoname(dev), cmd, (void *) data, flag);
2449 case COM_GETPORTSTATS:
2450 rc = stl_getportstats(NULL, data);
2452 case COM_CLRPORTSTATS:
2453 rc = stl_clrportstats(NULL, data);
2455 case COM_GETBRDSTATS:
2456 rc = stl_getbrdstats(data);
2466 /*****************************************************************************/
2468 /*****************************************************************************/
2469 /* CD1400 UART CODE */
2470 /*****************************************************************************/
2473 * These functions get/set/update the registers of the cd1400 UARTs.
2474 * Access to the cd1400 registers is via an address/data io port pair.
2477 static int stl_cd1400getreg(stlport_t *portp, int regnr)
2479 outb(portp->ioaddr, (regnr + portp->uartaddr));
2480 return(inb(portp->ioaddr + EREG_DATA));
2483 /*****************************************************************************/
2485 static void stl_cd1400setreg(stlport_t *portp, int regnr, int value)
2487 outb(portp->ioaddr, (regnr + portp->uartaddr));
2488 outb((portp->ioaddr + EREG_DATA), value);
2491 /*****************************************************************************/
2493 static int stl_cd1400updatereg(stlport_t *portp, int regnr, int value)
2495 outb(portp->ioaddr, (regnr + portp->uartaddr));
2496 if (inb(portp->ioaddr + EREG_DATA) != value) {
2497 outb((portp->ioaddr + EREG_DATA), value);
2503 /*****************************************************************************/
2505 static void stl_cd1400flush(stlport_t *portp, int flag)
2509 kprintf("stl_cd1400flush(portp=%x,flag=%x)\n", (int) portp, flag);
2517 if (flag & FWRITE) {
2518 BRDENABLE(portp->brdnr, portp->pagenr);
2519 stl_cd1400setreg(portp, CAR, (portp->portnr & 0x03));
2520 stl_cd1400ccrwait(portp);
2521 stl_cd1400setreg(portp, CCR, CCR_TXFLUSHFIFO);
2522 stl_cd1400ccrwait(portp);
2523 BRDDISABLE(portp->brdnr);
2533 /*****************************************************************************/
2535 static void stl_cd1400ccrwait(stlport_t *portp)
2539 for (i = 0; (i < CCR_MAXWAIT); i++) {
2540 if (stl_cd1400getreg(portp, CCR) == 0)
2544 kprintf("stl%d: cd1400 device not responding, panel=%d port=%d\n",
2545 portp->brdnr, portp->panelnr, portp->portnr);
2548 /*****************************************************************************/
2551 * Transmit interrupt handler. This has gotta be fast! Handling TX
2552 * chars is pretty simple, stuff as many as possible from the TX buffer
2553 * into the cd1400 FIFO. Must also handle TX breaks here, since they
2554 * are embedded as commands in the data stream. Oh no, had to use a goto!
2557 static __inline void stl_cd1400txisr(stlpanel_t *panelp, int ioaddr)
2561 unsigned char ioack, srer;
2566 kprintf("stl_cd1400txisr(panelp=%x,ioaddr=%x)\n", (int) panelp, ioaddr);
2569 ioack = inb(ioaddr + EREG_TXACK);
2570 if (((ioack & panelp->ackmask) != 0) ||
2571 ((ioack & ACK_TYPMASK) != ACK_TYPTX)) {
2572 kprintf("STALLION: bad TX interrupt ack value=%x\n",
2576 portp = panelp->ports[(ioack >> 3)];
2580 * Unfortunately we need to handle breaks in the data stream, since
2581 * this is the only way to generate them on the cd1400. Do it now if
2582 * a break is to be sent. Some special cases here: brklen is -1 then
2583 * start sending an un-timed break, if brklen is -2 then stop sending
2584 * an un-timed break, if brklen is -3 then we have just sent an
2585 * un-timed break and do not want any data to go out, if brklen is -4
2586 * then a break has just completed so clean up the port settings.
2588 if (portp->brklen != 0) {
2589 if (portp->brklen >= -1) {
2590 outb(ioaddr, (TDR + portp->uartaddr));
2591 outb((ioaddr + EREG_DATA), ETC_CMD);
2592 outb((ioaddr + EREG_DATA), ETC_STARTBREAK);
2593 if (portp->brklen > 0) {
2594 outb((ioaddr + EREG_DATA), ETC_CMD);
2595 outb((ioaddr + EREG_DATA), ETC_DELAY);
2596 outb((ioaddr + EREG_DATA), portp->brklen);
2597 outb((ioaddr + EREG_DATA), ETC_CMD);
2598 outb((ioaddr + EREG_DATA), ETC_STOPBREAK);
2603 } else if (portp->brklen == -2) {
2604 outb(ioaddr, (TDR + portp->uartaddr));
2605 outb((ioaddr + EREG_DATA), ETC_CMD);
2606 outb((ioaddr + EREG_DATA), ETC_STOPBREAK);
2608 } else if (portp->brklen == -3) {
2609 outb(ioaddr, (SRER + portp->uartaddr));
2610 srer = inb(ioaddr + EREG_DATA);
2611 srer &= ~(SRER_TXDATA | SRER_TXEMPTY);
2612 outb((ioaddr + EREG_DATA), srer);
2614 outb(ioaddr, (COR2 + portp->uartaddr));
2615 outb((ioaddr + EREG_DATA),
2616 (inb(ioaddr + EREG_DATA) & ~COR2_ETC));
2622 head = portp->tx.head;
2623 tail = portp->tx.tail;
2624 len = (head >= tail) ? (head - tail) : (STL_TXBUFSIZE - (tail - head));
2625 if ((len == 0) || ((len < STL_TXBUFLOW) &&
2626 ((portp->state & ASY_TXLOW) == 0))) {
2627 portp->state |= ASY_TXLOW;
2632 outb(ioaddr, (SRER + portp->uartaddr));
2633 srer = inb(ioaddr + EREG_DATA);
2634 if (srer & SRER_TXDATA) {
2635 srer = (srer & ~SRER_TXDATA) | SRER_TXEMPTY;
2637 srer &= ~(SRER_TXDATA | SRER_TXEMPTY);
2638 portp->state |= ASY_TXEMPTY;
2639 portp->state &= ~ASY_TXBUSY;
2641 outb((ioaddr + EREG_DATA), srer);
2643 len = MIN(len, CD1400_TXFIFOSIZE);
2644 portp->stats.txtotal += len;
2645 stlen = MIN(len, (portp->tx.endbuf - tail));
2646 outb(ioaddr, (TDR + portp->uartaddr));
2647 outsb((ioaddr + EREG_DATA), tail, stlen);
2650 if (tail >= portp->tx.endbuf)
2651 tail = portp->tx.buf;
2653 outsb((ioaddr + EREG_DATA), tail, len);
2656 portp->tx.tail = tail;
2660 outb(ioaddr, (EOSRR + portp->uartaddr));
2661 outb((ioaddr + EREG_DATA), 0);
2664 /*****************************************************************************/
2667 * Receive character interrupt handler. Determine if we have good chars
2668 * or bad chars and then process appropriately.
2671 static __inline void stl_cd1400rxisr(stlpanel_t *panelp, int ioaddr)
2675 unsigned int ioack, len, buflen, stlen;
2676 unsigned char status;
2681 kprintf("stl_cd1400rxisr(panelp=%x,ioaddr=%x)\n", (int) panelp, ioaddr);
2684 ioack = inb(ioaddr + EREG_RXACK);
2685 if ((ioack & panelp->ackmask) != 0) {
2686 kprintf("STALLION: bad RX interrupt ack value=%x\n", ioack);
2689 portp = panelp->ports[(ioack >> 3)];
2693 * First up, calculate how much room there is in the RX ring queue.
2694 * We also want to keep track of the longest possible copy length,
2695 * this has to allow for the wrapping of the ring queue.
2697 head = portp->rx.head;
2698 tail = portp->rx.tail;
2700 buflen = STL_RXBUFSIZE - (head - tail) - 1;
2701 stlen = portp->rx.endbuf - head;
2703 buflen = tail - head - 1;
2708 * Check if the input buffer is near full. If so then we should take
2709 * some flow control action... It is very easy to do hardware and
2710 * software flow control from here since we have the port selected on
2713 if (buflen <= (STL_RXBUFSIZE - STL_RXBUFHIGH)) {
2714 if (((portp->state & ASY_RTSFLOW) == 0) &&
2715 (portp->state & ASY_RTSFLOWMODE)) {
2716 portp->state |= ASY_RTSFLOW;
2717 stl_cd1400setreg(portp, MCOR1,
2718 (stl_cd1400getreg(portp, MCOR1) & 0xf0));
2719 stl_cd1400setreg(portp, MSVR2, 0);
2720 portp->stats.rxrtsoff++;
2725 * OK we are set, process good data... If the RX ring queue is full
2726 * just chuck the chars - don't leave them in the UART.
2728 if ((ioack & ACK_TYPMASK) == ACK_TYPRXGOOD) {
2729 outb(ioaddr, (RDCR + portp->uartaddr));
2730 len = inb(ioaddr + EREG_DATA);
2732 outb(ioaddr, (RDSR + portp->uartaddr));
2733 insb((ioaddr + EREG_DATA), &stl_unwanted[0], len);
2734 portp->stats.rxlost += len;
2735 portp->stats.rxtotal += len;
2737 len = MIN(len, buflen);
2738 portp->stats.rxtotal += len;
2739 stlen = MIN(len, stlen);
2741 outb(ioaddr, (RDSR + portp->uartaddr));
2742 insb((ioaddr + EREG_DATA), head, stlen);
2744 if (head >= portp->rx.endbuf) {
2745 head = portp->rx.buf;
2747 insb((ioaddr + EREG_DATA), head, len);
2752 } else if ((ioack & ACK_TYPMASK) == ACK_TYPRXBAD) {
2753 outb(ioaddr, (RDSR + portp->uartaddr));
2754 status = inb(ioaddr + EREG_DATA);
2755 ch = inb(ioaddr + EREG_DATA);
2756 if (status & ST_BREAK)
2757 portp->stats.rxbreaks++;
2758 if (status & ST_FRAMING)
2759 portp->stats.rxframing++;
2760 if (status & ST_PARITY)
2761 portp->stats.rxparity++;
2762 if (status & ST_OVERRUN)
2763 portp->stats.rxoverrun++;
2764 if (status & ST_SCHARMASK) {
2765 if ((status & ST_SCHARMASK) == ST_SCHAR1)
2766 portp->stats.txxon++;
2767 if ((status & ST_SCHARMASK) == ST_SCHAR2)
2768 portp->stats.txxoff++;
2771 if ((portp->rxignoremsk & status) == 0) {
2772 if ((tp->t_state & TS_CAN_BYPASS_L_RINT) &&
2773 ((status & ST_FRAMING) ||
2774 ((status & ST_PARITY) && (tp->t_iflag & INPCK))))
2776 if ((portp->rxmarkmsk & status) == 0)
2778 *(head + STL_RXBUFSIZE) = status;
2780 if (head >= portp->rx.endbuf)
2781 head = portp->rx.buf;
2784 kprintf("STALLION: bad RX interrupt ack value=%x\n", ioack);
2788 portp->rx.head = head;
2789 portp->state |= ASY_RXDATA;
2793 outb(ioaddr, (EOSRR + portp->uartaddr));
2794 outb((ioaddr + EREG_DATA), 0);
2797 /*****************************************************************************/
2800 * Modem interrupt handler. The is called when the modem signal line
2801 * (DCD) has changed state.
2804 static __inline void stl_cd1400mdmisr(stlpanel_t *panelp, int ioaddr)
2811 kprintf("stl_cd1400mdmisr(panelp=%x,ioaddr=%x)\n", (int) panelp, ioaddr);
2814 ioack = inb(ioaddr + EREG_MDACK);
2815 if (((ioack & panelp->ackmask) != 0) ||
2816 ((ioack & ACK_TYPMASK) != ACK_TYPMDM)) {
2817 kprintf("STALLION: bad MODEM interrupt ack value=%x\n", ioack);
2820 portp = panelp->ports[(ioack >> 3)];
2822 outb(ioaddr, (MISR + portp->uartaddr));
2823 misr = inb(ioaddr + EREG_DATA);
2824 if (misr & MISR_DCD) {
2825 portp->state |= ASY_DCDCHANGE;
2826 portp->stats.modem++;
2830 outb(ioaddr, (EOSRR + portp->uartaddr));
2831 outb((ioaddr + EREG_DATA), 0);
2834 /*****************************************************************************/
2837 * Interrupt service routine for cd1400 EasyIO boards.
2840 static void stl_cd1400eiointr(stlpanel_t *panelp, unsigned int iobase)
2842 unsigned char svrtype;
2845 kprintf("stl_cd1400eiointr(panelp=%x,iobase=%x)\n", (int) panelp,
2850 svrtype = inb(iobase + EREG_DATA);
2851 if (panelp->nrports > 4) {
2852 outb(iobase, (SVRR + 0x80));
2853 svrtype |= inb(iobase + EREG_DATA);
2856 kprintf("stl_cd1400eiointr(panelp=%x,iobase=%x): svrr=%x\n", (int) panelp, iobase, svrtype);
2859 if (svrtype & SVRR_RX)
2860 stl_cd1400rxisr(panelp, iobase);
2861 else if (svrtype & SVRR_TX)
2862 stl_cd1400txisr(panelp, iobase);
2863 else if (svrtype & SVRR_MDM)
2864 stl_cd1400mdmisr(panelp, iobase);
2867 /*****************************************************************************/
2870 * Interrupt service routine for cd1400 panels.
2873 static void stl_cd1400echintr(stlpanel_t *panelp, unsigned int iobase)
2875 unsigned char svrtype;
2878 kprintf("stl_cd1400echintr(panelp=%x,iobase=%x)\n", (int) panelp,
2883 svrtype = inb(iobase + EREG_DATA);
2884 outb(iobase, (SVRR + 0x80));
2885 svrtype |= inb(iobase + EREG_DATA);
2886 if (svrtype & SVRR_RX)
2887 stl_cd1400rxisr(panelp, iobase);
2888 else if (svrtype & SVRR_TX)
2889 stl_cd1400txisr(panelp, iobase);
2890 else if (svrtype & SVRR_MDM)
2891 stl_cd1400mdmisr(panelp, iobase);
2894 /*****************************************************************************/
2897 * Set up the cd1400 registers for a port based on the termios port
2901 static int stl_cd1400setport(stlport_t *portp, struct termios *tiosp)
2903 unsigned int clkdiv;
2904 unsigned char cor1, cor2, cor3;
2905 unsigned char cor4, cor5, ccr;
2906 unsigned char srer, sreron, sreroff;
2907 unsigned char mcor1, mcor2, rtpr;
2908 unsigned char clk, div;
2911 kprintf("stl_cd1400setport(portp=%x,tiosp=%x): brdnr=%d portnr=%d\n",
2912 (int) portp, (int) tiosp, portp->brdnr, portp->portnr);
2930 * Set up the RX char ignore mask with those RX error types we
2931 * can ignore. We could have used some special modes of the cd1400
2932 * UART to help, but it is better this way because we can keep stats
2933 * on the number of each type of RX exception event.
2935 portp->rxignoremsk = 0;
2936 if (tiosp->c_iflag & IGNPAR)
2937 portp->rxignoremsk |= (ST_PARITY | ST_FRAMING | ST_OVERRUN);
2938 if (tiosp->c_iflag & IGNBRK)
2939 portp->rxignoremsk |= ST_BREAK;
2941 portp->rxmarkmsk = ST_OVERRUN;
2942 if (tiosp->c_iflag & (INPCK | PARMRK))
2943 portp->rxmarkmsk |= (ST_PARITY | ST_FRAMING);
2944 if (tiosp->c_iflag & BRKINT)
2945 portp->rxmarkmsk |= ST_BREAK;
2948 * Go through the char size, parity and stop bits and set all the
2949 * option registers appropriately.
2951 switch (tiosp->c_cflag & CSIZE) {
2966 if (tiosp->c_cflag & CSTOPB)
2971 if (tiosp->c_cflag & PARENB) {
2972 if (tiosp->c_cflag & PARODD)
2973 cor1 |= (COR1_PARENB | COR1_PARODD);
2975 cor1 |= (COR1_PARENB | COR1_PAREVEN);
2977 cor1 |= COR1_PARNONE;
2981 * Set the RX FIFO threshold at 6 chars. This gives a bit of breathing
2982 * space for hardware flow control and the like. This should be set to
2983 * VMIN. Also here we will set the RX data timeout to 10ms - this should
2984 * really be based on VTIME...
2986 cor3 |= FIFO_RXTHRESHOLD;
2990 * Calculate the baud rate timers. For now we will just assume that
2991 * the input and output baud are the same. Could have used a baud
2992 * table here, but this way we can generate virtually any baud rate
2995 if (tiosp->c_ispeed == 0)
2996 tiosp->c_ispeed = tiosp->c_ospeed;
2997 if ((tiosp->c_ospeed < 0) || (tiosp->c_ospeed > CD1400_MAXBAUD))
3000 if (tiosp->c_ospeed > 0) {
3001 for (clk = 0; (clk < CD1400_NUMCLKS); clk++) {
3002 clkdiv = ((portp->clk / stl_cd1400clkdivs[clk]) /
3007 div = (unsigned char) clkdiv;
3011 * Check what form of modem signaling is required and set it up.
3013 if ((tiosp->c_cflag & CLOCAL) == 0) {
3016 sreron |= SRER_MODEM;
3020 * Setup cd1400 enhanced modes if we can. In particular we want to
3021 * handle as much of the flow control as possbile automatically. As
3022 * well as saving a few CPU cycles it will also greatly improve flow
3023 * control reliablilty.
3025 if (tiosp->c_iflag & IXON) {
3028 if (tiosp->c_iflag & IXANY)
3032 if (tiosp->c_cflag & CCTS_OFLOW)
3034 if (tiosp->c_cflag & CRTS_IFLOW)
3035 mcor1 |= FIFO_RTSTHRESHOLD;
3038 * All cd1400 register values calculated so go through and set them
3042 kprintf("SETPORT: portnr=%d panelnr=%d brdnr=%d\n", portp->portnr,
3043 portp->panelnr, portp->brdnr);
3044 kprintf(" cor1=%x cor2=%x cor3=%x cor4=%x cor5=%x\n", cor1, cor2,
3046 kprintf(" mcor1=%x mcor2=%x rtpr=%x sreron=%x sreroff=%x\n",
3047 mcor1, mcor2, rtpr, sreron, sreroff);
3048 kprintf(" tcor=%x tbpr=%x rcor=%x rbpr=%x\n", clk, div, clk, div);
3049 kprintf(" schr1=%x schr2=%x schr3=%x schr4=%x\n",
3050 tiosp->c_cc[VSTART], tiosp->c_cc[VSTOP], tiosp->c_cc[VSTART],
3051 tiosp->c_cc[VSTOP]);
3055 BRDENABLE(portp->brdnr, portp->pagenr);
3056 stl_cd1400setreg(portp, CAR, (portp->portnr & 0x3));
3057 srer = stl_cd1400getreg(portp, SRER);
3058 stl_cd1400setreg(portp, SRER, 0);
3059 ccr += stl_cd1400updatereg(portp, COR1, cor1);
3060 ccr += stl_cd1400updatereg(portp, COR2, cor2);
3061 ccr += stl_cd1400updatereg(portp, COR3, cor3);
3063 stl_cd1400ccrwait(portp);
3064 stl_cd1400setreg(portp, CCR, CCR_CORCHANGE);
3066 stl_cd1400setreg(portp, COR4, cor4);
3067 stl_cd1400setreg(portp, COR5, cor5);
3068 stl_cd1400setreg(portp, MCOR1, mcor1);
3069 stl_cd1400setreg(portp, MCOR2, mcor2);
3070 if (tiosp->c_ospeed == 0) {
3071 stl_cd1400setreg(portp, MSVR1, 0);
3073 stl_cd1400setreg(portp, MSVR1, MSVR1_DTR);
3074 stl_cd1400setreg(portp, TCOR, clk);
3075 stl_cd1400setreg(portp, TBPR, div);
3076 stl_cd1400setreg(portp, RCOR, clk);
3077 stl_cd1400setreg(portp, RBPR, div);
3079 stl_cd1400setreg(portp, SCHR1, tiosp->c_cc[VSTART]);
3080 stl_cd1400setreg(portp, SCHR2, tiosp->c_cc[VSTOP]);
3081 stl_cd1400setreg(portp, SCHR3, tiosp->c_cc[VSTART]);
3082 stl_cd1400setreg(portp, SCHR4, tiosp->c_cc[VSTOP]);
3083 stl_cd1400setreg(portp, RTPR, rtpr);
3084 mcor1 = stl_cd1400getreg(portp, MSVR1);
3085 if (mcor1 & MSVR1_DCD)
3086 portp->sigs |= TIOCM_CD;
3088 portp->sigs &= ~TIOCM_CD;
3089 stl_cd1400setreg(portp, SRER, ((srer & ~sreroff) | sreron));
3090 BRDDISABLE(portp->brdnr);
3091 portp->state &= ~(ASY_RTSFLOWMODE | ASY_CTSFLOWMODE);
3092 portp->state |= ((tiosp->c_cflag & CRTS_IFLOW) ? ASY_RTSFLOWMODE : 0);
3093 portp->state |= ((tiosp->c_cflag & CCTS_OFLOW) ? ASY_CTSFLOWMODE : 0);
3094 stl_ttyoptim(portp, tiosp);
3100 /*****************************************************************************/
3103 * Action the flow control as required. The hw and sw args inform the
3104 * routine what flow control methods it should try.
3107 static void stl_cd1400sendflow(stlport_t *portp, int hw, int sw)
3111 kprintf("stl_cd1400sendflow(portp=%x,hw=%d,sw=%d)\n",
3112 (int) portp, hw, sw);
3116 BRDENABLE(portp->brdnr, portp->pagenr);
3117 stl_cd1400setreg(portp, CAR, (portp->portnr & 0x03));
3120 stl_cd1400ccrwait(portp);
3122 stl_cd1400setreg(portp, CCR, CCR_SENDSCHR2);
3123 portp->stats.rxxoff++;
3125 stl_cd1400setreg(portp, CCR, CCR_SENDSCHR1);
3126 portp->stats.rxxon++;
3128 stl_cd1400ccrwait(portp);
3132 portp->state |= ASY_RTSFLOW;
3133 stl_cd1400setreg(portp, MCOR1,
3134 (stl_cd1400getreg(portp, MCOR1) & 0xf0));
3135 stl_cd1400setreg(portp, MSVR2, 0);
3136 portp->stats.rxrtsoff++;
3137 } else if (hw > 0) {
3138 portp->state &= ~ASY_RTSFLOW;
3139 stl_cd1400setreg(portp, MSVR2, MSVR2_RTS);
3140 stl_cd1400setreg(portp, MCOR1,
3141 (stl_cd1400getreg(portp, MCOR1) | FIFO_RTSTHRESHOLD));
3142 portp->stats.rxrtson++;
3145 BRDDISABLE(portp->brdnr);
3149 /*****************************************************************************/
3152 * Return the current state of data flow on this port. This is only
3153 * really interresting when determining if data has fully completed
3154 * transmission or not... This is easy for the cd1400, it accurately
3155 * maintains the busy port flag.
3158 static int stl_cd1400datastate(stlport_t *portp)
3161 kprintf("stl_cd1400datastate(portp=%x)\n", (int) portp);
3167 return((portp->state & ASY_TXBUSY) ? 1 : 0);
3170 /*****************************************************************************/
3173 * Set the state of the DTR and RTS signals. Got to do some extra
3174 * work here to deal hardware flow control.
3177 static void stl_cd1400setsignals(stlport_t *portp, int dtr, int rts)
3179 unsigned char msvr1, msvr2;
3182 kprintf("stl_cd1400setsignals(portp=%x,dtr=%d,rts=%d)\n", (int) portp,
3194 BRDENABLE(portp->brdnr, portp->pagenr);
3195 stl_cd1400setreg(portp, CAR, (portp->portnr & 0x03));
3197 if (portp->tty.t_cflag & CRTS_IFLOW) {
3199 stl_cd1400setreg(portp, MCOR1,
3200 (stl_cd1400getreg(portp, MCOR1) & 0xf0));
3201 portp->stats.rxrtsoff++;
3203 stl_cd1400setreg(portp, MCOR1,
3204 (stl_cd1400getreg(portp, MCOR1) |
3205 FIFO_RTSTHRESHOLD));
3206 portp->stats.rxrtson++;
3209 stl_cd1400setreg(portp, MSVR2, msvr2);
3212 stl_cd1400setreg(portp, MSVR1, msvr1);
3213 BRDDISABLE(portp->brdnr);
3217 /*****************************************************************************/
3220 * Get the state of the signals.
3223 static int stl_cd1400getsignals(stlport_t *portp)
3225 unsigned char msvr1, msvr2;
3229 kprintf("stl_cd1400getsignals(portp=%x)\n", (int) portp);
3233 BRDENABLE(portp->brdnr, portp->pagenr);
3234 stl_cd1400setreg(portp, CAR, (portp->portnr & 0x3));
3235 msvr1 = stl_cd1400getreg(portp, MSVR1);
3236 msvr2 = stl_cd1400getreg(portp, MSVR2);
3237 BRDDISABLE(portp->brdnr);
3241 sigs |= (msvr1 & MSVR1_DCD) ? TIOCM_CD : 0;
3242 sigs |= (msvr1 & MSVR1_CTS) ? TIOCM_CTS : 0;
3243 sigs |= (msvr1 & MSVR1_DTR) ? TIOCM_DTR : 0;
3244 sigs |= (msvr2 & MSVR2_RTS) ? TIOCM_RTS : 0;
3246 sigs |= (msvr1 & MSVR1_RI) ? TIOCM_RI : 0;
3247 sigs |= (msvr1 & MSVR1_DSR) ? TIOCM_DSR : 0;
3254 /*****************************************************************************/
3257 * Enable or disable the Transmitter and/or Receiver.
3260 static void stl_cd1400enablerxtx(stlport_t *portp, int rx, int tx)
3265 kprintf("stl_cd1400enablerxtx(portp=%x,rx=%d,tx=%d)\n",
3266 (int) portp, rx, tx);
3271 ccr |= CCR_TXDISABLE;
3273 ccr |= CCR_TXENABLE;
3275 ccr |= CCR_RXDISABLE;
3277 ccr |= CCR_RXENABLE;
3280 BRDENABLE(portp->brdnr, portp->pagenr);
3281 stl_cd1400setreg(portp, CAR, (portp->portnr & 0x03));
3282 stl_cd1400ccrwait(portp);
3283 stl_cd1400setreg(portp, CCR, ccr);
3284 stl_cd1400ccrwait(portp);
3285 BRDDISABLE(portp->brdnr);
3289 /*****************************************************************************/
3292 * Start or stop the Transmitter and/or Receiver.
3295 static void stl_cd1400startrxtx(stlport_t *portp, int rx, int tx)
3297 unsigned char sreron, sreroff;
3300 kprintf("stl_cd1400startrxtx(portp=%x,rx=%d,tx=%d)\n",
3301 (int) portp, rx, tx);
3307 sreroff |= (SRER_TXDATA | SRER_TXEMPTY);
3309 sreron |= SRER_TXDATA;
3311 sreron |= SRER_TXEMPTY;
3313 sreroff |= SRER_RXDATA;
3315 sreron |= SRER_RXDATA;
3318 BRDENABLE(portp->brdnr, portp->pagenr);
3319 stl_cd1400setreg(portp, CAR, (portp->portnr & 0x3));
3320 stl_cd1400setreg(portp, SRER,
3321 ((stl_cd1400getreg(portp, SRER) & ~sreroff) | sreron));
3322 BRDDISABLE(portp->brdnr);
3324 portp->state |= ASY_TXBUSY;
3325 portp->tty.t_state |= TS_BUSY;
3330 /*****************************************************************************/
3333 * Disable all interrupts from this port.
3336 static void stl_cd1400disableintrs(stlport_t *portp)
3340 kprintf("stl_cd1400disableintrs(portp=%x)\n", (int) portp);
3344 BRDENABLE(portp->brdnr, portp->pagenr);
3345 stl_cd1400setreg(portp, CAR, (portp->portnr & 0x3));
3346 stl_cd1400setreg(portp, SRER, 0);
3347 BRDDISABLE(portp->brdnr);
3351 /*****************************************************************************/
3353 static void stl_cd1400sendbreak(stlport_t *portp, long len)
3357 kprintf("stl_cd1400sendbreak(portp=%x,len=%d)\n", (int) portp,
3362 BRDENABLE(portp->brdnr, portp->pagenr);
3363 stl_cd1400setreg(portp, CAR, (portp->portnr & 0x3));
3364 stl_cd1400setreg(portp, COR2,
3365 (stl_cd1400getreg(portp, COR2) | COR2_ETC));
3366 stl_cd1400setreg(portp, SRER,
3367 ((stl_cd1400getreg(portp, SRER) & ~SRER_TXDATA) |
3369 BRDDISABLE(portp->brdnr);
3372 portp->brklen = (len > 255) ? 255 : len;
3374 portp->brklen = len;
3377 portp->stats.txbreaks++;
3380 /*****************************************************************************/
3383 * Try and find and initialize all the ports on a panel. We don't care
3384 * what sort of board these ports are on - since the port io registers
3385 * are almost identical when dealing with ports.
3388 static void stl_cd1400portinit(stlbrd_t *brdp, stlpanel_t *panelp, stlport_t *portp)
3391 kprintf("stl_cd1400portinit(brdp=%x,panelp=%x,portp=%x)\n",
3392 (int) brdp, (int) panelp, (int) portp);
3395 if ((brdp == NULL) || (panelp == NULL) ||
3399 portp->ioaddr = panelp->iobase + (((brdp->brdtype == BRD_ECHPCI) ||
3400 (portp->portnr < 8)) ? 0 : EREG_BANKSIZE);
3401 portp->uartaddr = (portp->portnr & 0x04) << 5;
3402 portp->pagenr = panelp->pagenr + (portp->portnr >> 3);
3404 BRDENABLE(portp->brdnr, portp->pagenr);
3405 stl_cd1400setreg(portp, CAR, (portp->portnr & 0x3));
3406 stl_cd1400setreg(portp, LIVR, (portp->portnr << 3));
3407 portp->hwid = stl_cd1400getreg(portp, GFRCR);
3408 BRDDISABLE(portp->brdnr);
3411 /*****************************************************************************/
3414 * Inbitialize the UARTs in a panel. We don't care what sort of board
3415 * these ports are on - since the port io registers are almost
3416 * identical when dealing with ports.
3419 static int stl_cd1400panelinit(stlbrd_t *brdp, stlpanel_t *panelp)
3423 int nrchips, uartaddr, ioaddr;
3426 kprintf("stl_cd1400panelinit(brdp=%x,panelp=%x)\n", (int) brdp,
3430 BRDENABLE(panelp->brdnr, panelp->pagenr);
3433 * Check that each chip is present and started up OK.
3436 nrchips = panelp->nrports / CD1400_PORTS;
3437 for (i = 0; (i < nrchips); i++) {
3438 if (brdp->brdtype == BRD_ECHPCI) {
3439 outb((panelp->pagenr + (i >> 1)), brdp->ioctrl);
3440 ioaddr = panelp->iobase;
3442 ioaddr = panelp->iobase + (EREG_BANKSIZE * (i >> 1));
3444 uartaddr = (i & 0x01) ? 0x080 : 0;
3445 outb(ioaddr, (GFRCR + uartaddr));
3446 outb((ioaddr + EREG_DATA), 0);
3447 outb(ioaddr, (CCR + uartaddr));
3448 outb((ioaddr + EREG_DATA), CCR_RESETFULL);
3449 outb((ioaddr + EREG_DATA), CCR_RESETFULL);
3450 outb(ioaddr, (GFRCR + uartaddr));
3451 for (j = 0; (j < CCR_MAXWAIT); j++) {
3452 if ((gfrcr = inb(ioaddr + EREG_DATA)) != 0)
3455 if ((j >= CCR_MAXWAIT) || (gfrcr < 0x40) || (gfrcr > 0x60)) {
3456 kprintf("STALLION: cd1400 not responding, "
3457 "board=%d panel=%d chip=%d\n", panelp->brdnr,
3458 panelp->panelnr, i);
3461 chipmask |= (0x1 << i);
3462 outb(ioaddr, (PPR + uartaddr));
3463 outb((ioaddr + EREG_DATA), PPR_SCALAR);
3467 BRDDISABLE(panelp->brdnr);
3471 /*****************************************************************************/
3472 /* SC26198 HARDWARE FUNCTIONS */
3473 /*****************************************************************************/
3476 * These functions get/set/update the registers of the sc26198 UARTs.
3477 * Access to the sc26198 registers is via an address/data io port pair.
3478 * (Maybe should make this inline...)
3481 static int stl_sc26198getreg(stlport_t *portp, int regnr)
3483 outb((portp->ioaddr + XP_ADDR), (regnr | portp->uartaddr));
3484 return(inb(portp->ioaddr + XP_DATA));
3487 static void stl_sc26198setreg(stlport_t *portp, int regnr, int value)
3489 outb((portp->ioaddr + XP_ADDR), (regnr | portp->uartaddr));
3490 outb((portp->ioaddr + XP_DATA), value);
3493 static int stl_sc26198updatereg(stlport_t *portp, int regnr, int value)
3495 outb((portp->ioaddr + XP_ADDR), (regnr | portp->uartaddr));
3496 if (inb(portp->ioaddr + XP_DATA) != value) {
3497 outb((portp->ioaddr + XP_DATA), value);
3503 /*****************************************************************************/
3506 * Functions to get and set the sc26198 global registers.
3509 static int stl_sc26198getglobreg(stlport_t *portp, int regnr)
3511 outb((portp->ioaddr + XP_ADDR), regnr);
3512 return(inb(portp->ioaddr + XP_DATA));
3516 static void stl_sc26198setglobreg(stlport_t *portp, int regnr, int value)
3518 outb((portp->ioaddr + XP_ADDR), regnr);
3519 outb((portp->ioaddr + XP_DATA), value);
3523 /*****************************************************************************/
3526 * Inbitialize the UARTs in a panel. We don't care what sort of board
3527 * these ports are on - since the port io registers are almost
3528 * identical when dealing with ports.
3531 static int stl_sc26198panelinit(stlbrd_t *brdp, stlpanel_t *panelp)
3534 int nrchips, ioaddr;
3537 kprintf("stl_sc26198panelinit(brdp=%x,panelp=%x)\n", (int) brdp,
3541 BRDENABLE(panelp->brdnr, panelp->pagenr);
3544 * Check that each chip is present and started up OK.
3547 nrchips = (panelp->nrports + 4) / SC26198_PORTS;
3548 if (brdp->brdtype == BRD_ECHPCI)
3549 outb(brdp->ioctrl, panelp->pagenr);
3551 for (i = 0; (i < nrchips); i++) {
3552 ioaddr = panelp->iobase + (i * 4);
3553 outb((ioaddr + XP_ADDR), SCCR);
3554 outb((ioaddr + XP_DATA), CR_RESETALL);
3555 outb((ioaddr + XP_ADDR), TSTR);
3556 if (inb(ioaddr + XP_DATA) != 0) {
3557 kprintf("STALLION: sc26198 not responding, "
3558 "board=%d panel=%d chip=%d\n", panelp->brdnr,
3559 panelp->panelnr, i);
3562 chipmask |= (0x1 << i);
3563 outb((ioaddr + XP_ADDR), GCCR);
3564 outb((ioaddr + XP_DATA), GCCR_IVRTYPCHANACK);
3565 outb((ioaddr + XP_ADDR), WDTRCR);
3566 outb((ioaddr + XP_DATA), 0xff);
3569 BRDDISABLE(panelp->brdnr);
3573 /*****************************************************************************/
3576 * Initialize hardware specific port registers.
3579 static void stl_sc26198portinit(stlbrd_t *brdp, stlpanel_t *panelp, stlport_t *portp)
3582 kprintf("stl_sc26198portinit(brdp=%x,panelp=%x,portp=%x)\n",
3583 (int) brdp, (int) panelp, (int) portp);
3586 if ((brdp == NULL) || (panelp == NULL) ||
3590 portp->ioaddr = panelp->iobase + ((portp->portnr < 8) ? 0 : 4);
3591 portp->uartaddr = (portp->portnr & 0x07) << 4;
3592 portp->pagenr = panelp->pagenr;
3595 BRDENABLE(portp->brdnr, portp->pagenr);
3596 stl_sc26198setreg(portp, IOPCR, IOPCR_SETSIGS);
3597 BRDDISABLE(portp->brdnr);
3600 /*****************************************************************************/
3603 * Set up the sc26198 registers for a port based on the termios port
3607 static int stl_sc26198setport(stlport_t *portp, struct termios *tiosp)
3609 unsigned char mr0, mr1, mr2, clk;
3610 unsigned char imron, imroff, iopr, ipr;
3613 kprintf("stl_sc26198setport(portp=%x,tiosp=%x): brdnr=%d portnr=%d\n",
3614 (int) portp, (int) tiosp, portp->brdnr, portp->portnr);
3626 * Set up the RX char ignore mask with those RX error types we
3629 portp->rxignoremsk = 0;
3630 if (tiosp->c_iflag & IGNPAR)
3631 portp->rxignoremsk |= (SR_RXPARITY | SR_RXFRAMING |
3633 if (tiosp->c_iflag & IGNBRK)
3634 portp->rxignoremsk |= SR_RXBREAK;
3636 portp->rxmarkmsk = SR_RXOVERRUN;
3637 if (tiosp->c_iflag & (INPCK | PARMRK))
3638 portp->rxmarkmsk |= (SR_RXPARITY | SR_RXFRAMING);
3639 if (tiosp->c_iflag & BRKINT)
3640 portp->rxmarkmsk |= SR_RXBREAK;
3643 * Go through the char size, parity and stop bits and set all the
3644 * option registers appropriately.
3646 switch (tiosp->c_cflag & CSIZE) {
3661 if (tiosp->c_cflag & CSTOPB)
3666 if (tiosp->c_cflag & PARENB) {
3667 if (tiosp->c_cflag & PARODD)
3668 mr1 |= (MR1_PARENB | MR1_PARODD);
3670 mr1 |= (MR1_PARENB | MR1_PAREVEN);
3675 mr1 |= MR1_ERRBLOCK;
3678 * Set the RX FIFO threshold at 8 chars. This gives a bit of breathing
3679 * space for hardware flow control and the like. This should be set to
3682 mr2 |= MR2_RXFIFOHALF;
3685 * Calculate the baud rate timers. For now we will just assume that
3686 * the input and output baud are the same. The sc26198 has a fixed
3687 * baud rate table, so only discrete baud rates possible.
3689 if (tiosp->c_ispeed == 0)
3690 tiosp->c_ispeed = tiosp->c_ospeed;
3691 if ((tiosp->c_ospeed < 0) || (tiosp->c_ospeed > SC26198_MAXBAUD))
3694 if (tiosp->c_ospeed > 0) {
3695 for (clk = 0; (clk < SC26198_NRBAUDS); clk++) {
3696 if (tiosp->c_ospeed <= sc26198_baudtable[clk])
3702 * Check what form of modem signaling is required and set it up.
3704 if ((tiosp->c_cflag & CLOCAL) == 0) {
3705 iopr |= IOPR_DCDCOS;
3710 * Setup sc26198 enhanced modes if we can. In particular we want to
3711 * handle as much of the flow control as possible automatically. As
3712 * well as saving a few CPU cycles it will also greatly improve flow
3713 * control reliability.
3715 if (tiosp->c_iflag & IXON) {
3716 mr0 |= MR0_SWFTX | MR0_SWFT;
3717 imron |= IR_XONXOFF;
3719 imroff |= IR_XONXOFF;
3722 if (tiosp->c_iflag & IXOFF)
3726 if (tiosp->c_cflag & CCTS_OFLOW)
3728 if (tiosp->c_cflag & CRTS_IFLOW)
3732 * All sc26198 register values calculated so go through and set
3737 kprintf("SETPORT: portnr=%d panelnr=%d brdnr=%d\n", portp->portnr,
3738 portp->panelnr, portp->brdnr);
3739 kprintf(" mr0=%x mr1=%x mr2=%x clk=%x\n", mr0, mr1, mr2, clk);
3740 kprintf(" iopr=%x imron=%x imroff=%x\n", iopr, imron, imroff);
3741 kprintf(" schr1=%x schr2=%x schr3=%x schr4=%x\n",
3742 tiosp->c_cc[VSTART], tiosp->c_cc[VSTOP],
3743 tiosp->c_cc[VSTART], tiosp->c_cc[VSTOP]);
3747 BRDENABLE(portp->brdnr, portp->pagenr);
3748 stl_sc26198setreg(portp, IMR, 0);
3749 stl_sc26198updatereg(portp, MR0, mr0);
3750 stl_sc26198updatereg(portp, MR1, mr1);
3751 stl_sc26198setreg(portp, SCCR, CR_RXERRBLOCK);
3752 stl_sc26198updatereg(portp, MR2, mr2);
3753 iopr = (stl_sc26198getreg(portp, IOPIOR) & ~IPR_CHANGEMASK) | iopr;
3754 if (tiosp->c_ospeed == 0) {
3758 stl_sc26198setreg(portp, TXCSR, clk);
3759 stl_sc26198setreg(portp, RXCSR, clk);
3761 stl_sc26198updatereg(portp, IOPIOR, iopr);
3762 stl_sc26198setreg(portp, XONCR, tiosp->c_cc[VSTART]);
3763 stl_sc26198setreg(portp, XOFFCR, tiosp->c_cc[VSTOP]);
3764 ipr = stl_sc26198getreg(portp, IPR);
3766 portp->sigs &= ~TIOCM_CD;
3768 portp->sigs |= TIOCM_CD;
3769 portp->imr = (portp->imr & ~imroff) | imron;
3770 stl_sc26198setreg(portp, IMR, portp->imr);
3771 BRDDISABLE(portp->brdnr);
3772 portp->state &= ~(ASY_RTSFLOWMODE | ASY_CTSFLOWMODE);
3773 portp->state |= ((tiosp->c_cflag & CRTS_IFLOW) ? ASY_RTSFLOWMODE : 0);
3774 portp->state |= ((tiosp->c_cflag & CCTS_OFLOW) ? ASY_CTSFLOWMODE : 0);
3775 stl_ttyoptim(portp, tiosp);
3781 /*****************************************************************************/
3784 * Set the state of the DTR and RTS signals.
3787 static void stl_sc26198setsignals(stlport_t *portp, int dtr, int rts)
3789 unsigned char iopioron, iopioroff;
3792 kprintf("stl_sc26198setsignals(portp=%x,dtr=%d,rts=%d)\n",
3793 (int) portp, dtr, rts);
3799 iopioroff |= IPR_DTR;
3801 iopioron |= IPR_DTR;
3803 iopioroff |= IPR_RTS;
3805 iopioron |= IPR_RTS;
3808 BRDENABLE(portp->brdnr, portp->pagenr);
3809 if ((rts >= 0) && (portp->tty.t_cflag & CRTS_IFLOW)) {
3811 stl_sc26198setreg(portp, MR1,
3812 (stl_sc26198getreg(portp, MR1) & ~MR1_AUTORTS));
3813 portp->stats.rxrtsoff++;
3815 stl_sc26198setreg(portp, MR1,
3816 (stl_sc26198getreg(portp, MR1) | MR1_AUTORTS));
3817 portp->stats.rxrtson++;
3820 stl_sc26198setreg(portp, IOPIOR,
3821 ((stl_sc26198getreg(portp, IOPIOR) & ~iopioroff) | iopioron));
3822 BRDDISABLE(portp->brdnr);
3826 /*****************************************************************************/
3829 * Return the state of the signals.
3832 static int stl_sc26198getsignals(stlport_t *portp)
3838 kprintf("stl_sc26198getsignals(portp=%x)\n", (int) portp);
3842 BRDENABLE(portp->brdnr, portp->pagenr);
3843 ipr = stl_sc26198getreg(portp, IPR);
3844 BRDDISABLE(portp->brdnr);
3848 sigs |= (ipr & IPR_DCD) ? 0 : TIOCM_CD;
3849 sigs |= (ipr & IPR_CTS) ? 0 : TIOCM_CTS;
3850 sigs |= (ipr & IPR_DTR) ? 0: TIOCM_DTR;
3851 sigs |= (ipr & IPR_RTS) ? 0: TIOCM_RTS;
3855 /*****************************************************************************/
3858 * Enable/Disable the Transmitter and/or Receiver.
3861 static void stl_sc26198enablerxtx(stlport_t *portp, int rx, int tx)
3866 kprintf("stl_sc26198enablerxtx(portp=%x,rx=%d,tx=%d)\n",
3867 (int) portp, rx, tx);
3870 ccr = portp->crenable;
3872 ccr &= ~CR_TXENABLE;
3876 ccr &= ~CR_RXENABLE;
3881 BRDENABLE(portp->brdnr, portp->pagenr);
3882 stl_sc26198setreg(portp, SCCR, ccr);
3883 BRDDISABLE(portp->brdnr);
3884 portp->crenable = ccr;
3888 /*****************************************************************************/
3891 * Start/stop the Transmitter and/or Receiver.
3894 static void stl_sc26198startrxtx(stlport_t *portp, int rx, int tx)
3899 kprintf("stl_sc26198startrxtx(portp=%x,rx=%d,tx=%d)\n",
3900 (int) portp, rx, tx);
3909 imr &= ~(IR_RXRDY | IR_RXBREAK | IR_RXWATCHDOG);
3911 imr |= IR_RXRDY | IR_RXBREAK | IR_RXWATCHDOG;
3914 BRDENABLE(portp->brdnr, portp->pagenr);
3915 stl_sc26198setreg(portp, IMR, imr);
3916 BRDDISABLE(portp->brdnr);
3919 portp->state |= ASY_TXBUSY;
3920 portp->tty.t_state |= TS_BUSY;
3925 /*****************************************************************************/
3928 * Disable all interrupts from this port.
3931 static void stl_sc26198disableintrs(stlport_t *portp)
3935 kprintf("stl_sc26198disableintrs(portp=%x)\n", (int) portp);
3939 BRDENABLE(portp->brdnr, portp->pagenr);
3941 stl_sc26198setreg(portp, IMR, 0);
3942 BRDDISABLE(portp->brdnr);
3946 /*****************************************************************************/
3948 static void stl_sc26198sendbreak(stlport_t *portp, long len)
3952 kprintf("stl_sc26198sendbreak(portp=%x,len=%d)\n",
3953 (int) portp, (int) len);
3957 BRDENABLE(portp->brdnr, portp->pagenr);
3959 stl_sc26198setreg(portp, SCCR, CR_TXSTARTBREAK);
3960 portp->stats.txbreaks++;
3962 stl_sc26198setreg(portp, SCCR, CR_TXSTOPBREAK);
3964 BRDDISABLE(portp->brdnr);
3968 /*****************************************************************************/
3971 * Take flow control actions...
3974 static void stl_sc26198sendflow(stlport_t *portp, int hw, int sw)
3979 kprintf("stl_sc26198sendflow(portp=%x,hw=%d,sw=%d)\n",
3980 (int) portp, hw, sw);
3987 BRDENABLE(portp->brdnr, portp->pagenr);
3990 mr0 = stl_sc26198getreg(portp, MR0);
3991 stl_sc26198setreg(portp, MR0, (mr0 & ~MR0_SWFRXTX));
3993 stl_sc26198setreg(portp, SCCR, CR_TXSENDXOFF);
3995 portp->stats.rxxoff++;
3997 stl_sc26198setreg(portp, SCCR, CR_TXSENDXON);
3999 portp->stats.rxxon++;
4001 stl_sc26198wait(portp);
4002 stl_sc26198setreg(portp, MR0, mr0);
4006 portp->state |= ASY_RTSFLOW;
4007 stl_sc26198setreg(portp, MR1,
4008 (stl_sc26198getreg(portp, MR1) & ~MR1_AUTORTS));
4009 stl_sc26198setreg(portp, IOPIOR,
4010 (stl_sc26198getreg(portp, IOPIOR) & ~IOPR_RTS));
4011 portp->stats.rxrtsoff++;
4012 } else if (hw > 0) {
4013 portp->state &= ~ASY_RTSFLOW;
4014 stl_sc26198setreg(portp, MR1,
4015 (stl_sc26198getreg(portp, MR1) | MR1_AUTORTS));
4016 stl_sc26198setreg(portp, IOPIOR,
4017 (stl_sc26198getreg(portp, IOPIOR) | IOPR_RTS));
4018 portp->stats.rxrtson++;
4021 BRDDISABLE(portp->brdnr);
4025 /*****************************************************************************/
4028 * Return the current state of data flow on this port. This is only
4029 * really interresting when determining if data has fully completed
4030 * transmission or not... The sc26198 interrupt scheme cannot
4031 * determine when all data has actually drained, so we need to
4032 * check the port statusy register to be sure.
4035 static int stl_sc26198datastate(stlport_t *portp)
4040 kprintf("stl_sc26198datastate(portp=%x)\n", (int) portp);
4045 if (portp->state & ASY_TXBUSY)
4049 BRDENABLE(portp->brdnr, portp->pagenr);
4050 sr = stl_sc26198getreg(portp, SR);
4051 BRDDISABLE(portp->brdnr);
4054 return((sr & SR_TXEMPTY) ? 0 : 1);
4057 /*****************************************************************************/
4059 static void stl_sc26198flush(stlport_t *portp, int flag)
4063 kprintf("stl_sc26198flush(portp=%x,flag=%x)\n", (int) portp, flag);
4070 BRDENABLE(portp->brdnr, portp->pagenr);
4071 if (flag & FWRITE) {
4072 stl_sc26198setreg(portp, SCCR, CR_TXRESET);
4073 stl_sc26198setreg(portp, SCCR, portp->crenable);
4076 while (stl_sc26198getreg(portp, SR) & SR_RXRDY)
4077 stl_sc26198getreg(portp, RXFIFO);
4079 BRDDISABLE(portp->brdnr);
4083 /*****************************************************************************/
4086 * If we are TX flow controlled and in IXANY mode then we may
4087 * need to unflow control here. We gotta do this because of the
4088 * automatic flow control modes of the sc26198 - which downs't
4089 * support any concept of an IXANY mode.
4092 static void stl_sc26198txunflow(stlport_t *portp)
4096 mr0 = stl_sc26198getreg(portp, MR0);
4097 stl_sc26198setreg(portp, MR0, (mr0 & ~MR0_SWFRXTX));
4098 stl_sc26198setreg(portp, SCCR, CR_HOSTXON);
4099 stl_sc26198setreg(portp, MR0, mr0);
4100 portp->state &= ~ASY_TXFLOWED;
4103 /*****************************************************************************/
4106 * Delay for a small amount of time, to give the sc26198 a chance
4107 * to process a command...
4110 static void stl_sc26198wait(stlport_t *portp)
4115 kprintf("stl_sc26198wait(portp=%x)\n", (int) portp);
4121 for (i = 0; (i < 20); i++)
4122 stl_sc26198getglobreg(portp, TSTR);
4125 /*****************************************************************************/
4128 * Transmit interrupt handler. This has gotta be fast! Handling TX
4129 * chars is pretty simple, stuff as many as possible from the TX buffer
4130 * into the sc26198 FIFO.
4133 static __inline void stl_sc26198txisr(stlport_t *portp)
4135 unsigned int ioaddr;
4141 kprintf("stl_sc26198txisr(portp=%x)\n", (int) portp);
4144 ioaddr = portp->ioaddr;
4146 head = portp->tx.head;
4147 tail = portp->tx.tail;
4148 len = (head >= tail) ? (head - tail) : (STL_TXBUFSIZE - (tail - head));
4149 if ((len == 0) || ((len < STL_TXBUFLOW) &&
4150 ((portp->state & ASY_TXLOW) == 0))) {
4151 portp->state |= ASY_TXLOW;
4156 outb((ioaddr + XP_ADDR), (MR0 | portp->uartaddr));
4157 mr0 = inb(ioaddr + XP_DATA);
4158 if ((mr0 & MR0_TXMASK) == MR0_TXEMPTY) {
4159 portp->imr &= ~IR_TXRDY;
4160 outb((ioaddr + XP_ADDR), (IMR | portp->uartaddr));
4161 outb((ioaddr + XP_DATA), portp->imr);
4162 portp->state |= ASY_TXEMPTY;
4163 portp->state &= ~ASY_TXBUSY;
4165 mr0 |= ((mr0 & ~MR0_TXMASK) | MR0_TXEMPTY);
4166 outb((ioaddr + XP_DATA), mr0);
4169 len = MIN(len, SC26198_TXFIFOSIZE);
4170 portp->stats.txtotal += len;
4171 stlen = MIN(len, (portp->tx.endbuf - tail));
4172 outb((ioaddr + XP_ADDR), GTXFIFO);
4173 outsb((ioaddr + XP_DATA), tail, stlen);
4176 if (tail >= portp->tx.endbuf)
4177 tail = portp->tx.buf;
4179 outsb((ioaddr + XP_DATA), tail, len);
4182 portp->tx.tail = tail;
4186 /*****************************************************************************/
4189 * Receive character interrupt handler. Determine if we have good chars
4190 * or bad chars and then process appropriately. Good chars are easy
4191 * just shove the lot into the RX buffer and set all status byte to 0.
4192 * If a bad RX char then process as required. This routine needs to be
4196 static __inline void stl_sc26198rxisr(stlport_t *portp, unsigned int iack)
4199 kprintf("stl_sc26198rxisr(portp=%x,iack=%x)\n", (int) portp, iack);
4202 if ((iack & IVR_TYPEMASK) == IVR_RXDATA)
4203 stl_sc26198rxgoodchars(portp);
4205 stl_sc26198rxbadchars(portp);
4208 * If we are TX flow controlled and in IXANY mode then we may need
4209 * to unflow control here. We gotta do this because of the automatic
4210 * flow control modes of the sc26198.
4212 if ((portp->state & ASY_TXFLOWED) && (portp->tty.t_iflag & IXANY))
4213 stl_sc26198txunflow(portp);
4216 /*****************************************************************************/
4219 * Process the good received characters from RX FIFO.
4222 static void stl_sc26198rxgoodchars(stlport_t *portp)
4224 unsigned int ioaddr, len, buflen, stlen;
4228 kprintf("stl_sc26198rxgoodchars(port=%x)\n", (int) portp);
4231 ioaddr = portp->ioaddr;
4234 * First up, calculate how much room there is in the RX ring queue.
4235 * We also want to keep track of the longest possible copy length,
4236 * this has to allow for the wrapping of the ring queue.
4238 head = portp->rx.head;
4239 tail = portp->rx.tail;
4241 buflen = STL_RXBUFSIZE - (head - tail) - 1;
4242 stlen = portp->rx.endbuf - head;
4244 buflen = tail - head - 1;
4249 * Check if the input buffer is near full. If so then we should take
4250 * some flow control action... It is very easy to do hardware and
4251 * software flow control from here since we have the port selected on
4254 if (buflen <= (STL_RXBUFSIZE - STL_RXBUFHIGH)) {
4255 if (((portp->state & ASY_RTSFLOW) == 0) &&
4256 (portp->state & ASY_RTSFLOWMODE)) {
4257 portp->state |= ASY_RTSFLOW;
4258 stl_sc26198setreg(portp, MR1,
4259 (stl_sc26198getreg(portp, MR1) & ~MR1_AUTORTS));
4260 stl_sc26198setreg(portp, IOPIOR,
4261 (stl_sc26198getreg(portp, IOPIOR) & ~IOPR_RTS));
4262 portp->stats.rxrtsoff++;
4267 * OK we are set, process good data... If the RX ring queue is full
4268 * just chuck the chars - don't leave them in the UART.
4270 outb((ioaddr + XP_ADDR), GIBCR);
4271 len = inb(ioaddr + XP_DATA) + 1;
4273 outb((ioaddr + XP_ADDR), GRXFIFO);
4274 insb((ioaddr + XP_DATA), &stl_unwanted[0], len);
4275 portp->stats.rxlost += len;
4276 portp->stats.rxtotal += len;
4278 len = MIN(len, buflen);
4279 portp->stats.rxtotal += len;
4280 stlen = MIN(len, stlen);
4282 outb((ioaddr + XP_ADDR), GRXFIFO);
4283 insb((ioaddr + XP_DATA), head, stlen);
4285 if (head >= portp->rx.endbuf) {
4286 head = portp->rx.buf;
4288 insb((ioaddr + XP_DATA), head, len);
4294 portp->rx.head = head;
4295 portp->state |= ASY_RXDATA;
4299 /*****************************************************************************/
4302 * Process all characters in the RX FIFO of the UART. Check all char
4303 * status bytes as well, and process as required. We need to check
4304 * all bytes in the FIFO, in case some more enter the FIFO while we
4305 * are here. To get the exact character error type we need to switch
4306 * into CHAR error mode (that is why we need to make sure we empty
4310 static void stl_sc26198rxbadchars(stlport_t *portp)
4313 unsigned int status;
4319 * First up, calculate how much room there is in the RX ring queue.
4320 * We also want to keep track of the longest possible copy length,
4321 * this has to allow for the wrapping of the ring queue.
4323 head = portp->rx.head;
4324 tail = portp->rx.tail;
4325 len = (head >= tail) ? (STL_RXBUFSIZE - (head - tail) - 1) :
4329 * To get the precise error type for each character we must switch
4330 * back into CHAR error mode.
4332 mr1 = stl_sc26198getreg(portp, MR1);
4333 stl_sc26198setreg(portp, MR1, (mr1 & ~MR1_ERRBLOCK));
4335 while ((status = stl_sc26198getreg(portp, SR)) & SR_RXRDY) {
4336 stl_sc26198setreg(portp, SCCR, CR_CLEARRXERR);
4337 ch = stl_sc26198getreg(portp, RXFIFO);
4339 if (status & SR_RXBREAK)
4340 portp->stats.rxbreaks++;
4341 if (status & SR_RXFRAMING)
4342 portp->stats.rxframing++;
4343 if (status & SR_RXPARITY)
4344 portp->stats.rxparity++;
4345 if (status & SR_RXOVERRUN)
4346 portp->stats.rxoverrun++;
4347 if ((portp->rxignoremsk & status) == 0) {
4348 if ((portp->tty.t_state & TS_CAN_BYPASS_L_RINT) &&
4349 ((status & SR_RXFRAMING) ||
4350 ((status & SR_RXPARITY) &&
4351 (portp->tty.t_iflag & INPCK))))
4353 if ((portp->rxmarkmsk & status) == 0)
4356 *(head + STL_RXBUFSIZE) = status;
4358 if (head >= portp->rx.endbuf)
4359 head = portp->rx.buf;
4366 * To get correct interrupt class we must switch back into BLOCK
4369 stl_sc26198setreg(portp, MR1, mr1);
4371 portp->rx.head = head;
4372 portp->state |= ASY_RXDATA;
4376 /*****************************************************************************/
4379 * Other interrupt handler. This includes modem signals, flow
4380 * control actions, etc.
4383 static void stl_sc26198otherisr(stlport_t *portp, unsigned int iack)
4385 unsigned char cir, ipr, xisr;
4388 kprintf("stl_sc26198otherisr(portp=%x,iack=%x)\n", (int) portp, iack);
4391 cir = stl_sc26198getglobreg(portp, CIR);
4393 switch (cir & CIR_SUBTYPEMASK) {
4395 ipr = stl_sc26198getreg(portp, IPR);
4396 if (ipr & IPR_DCDCHANGE) {
4397 portp->state |= ASY_DCDCHANGE;
4398 portp->stats.modem++;
4402 case CIR_SUBXONXOFF:
4403 xisr = stl_sc26198getreg(portp, XISR);
4404 if (xisr & XISR_RXXONGOT) {
4405 portp->state |= ASY_TXFLOWED;
4406 portp->stats.txxoff++;
4408 if (xisr & XISR_RXXOFFGOT) {
4409 portp->state &= ~ASY_TXFLOWED;
4410 portp->stats.txxon++;
4414 stl_sc26198setreg(portp, SCCR, CR_BREAKRESET);
4415 stl_sc26198rxbadchars(portp);
4422 /*****************************************************************************/
4425 * Interrupt service routine for sc26198 panels.
4428 static void stl_sc26198intr(stlpanel_t *panelp, unsigned int iobase)
4434 * Work around bug in sc26198 chip... Cannot have A6 address
4435 * line of UART high, else iack will be returned as 0.
4437 outb((iobase + 1), 0);
4439 iack = inb(iobase + XP_IACK);
4441 kprintf("stl_sc26198intr(panelp=%p,iobase=%x): iack=%x\n", panelp, iobase, iack);
4443 portp = panelp->ports[(iack & IVR_CHANMASK) + ((iobase & 0x4) << 1)];
4445 if (iack & IVR_RXDATA)
4446 stl_sc26198rxisr(portp, iack);
4447 else if (iack & IVR_TXDATA)
4448 stl_sc26198txisr(portp);
4450 stl_sc26198otherisr(portp, iack);
4453 /*****************************************************************************/