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)
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)
1926 kprintf("stl_initports(panelp=%x)\n", (int) panelp);
1930 * All UART's are initialized if found. Now go through and setup
1931 * each ports data structures. Also initialize each individual
1934 for (i = 0; (i < panelp->nrports); i++) {
1935 portp = kmalloc(sizeof(stlport_t), M_TTYS, M_WAITOK | M_ZERO);
1938 portp->brdnr = panelp->brdnr;
1939 portp->panelnr = panelp->panelnr;
1940 portp->uartp = panelp->uartp;
1941 portp->clk = brdp->clk;
1942 panelp->ports[i] = portp;
1944 j = STL_TXBUFSIZE + (2 * STL_RXBUFSIZE);
1945 portp->tx.buf = kmalloc(j, M_TTYS, M_WAITOK);
1946 portp->tx.endbuf = portp->tx.buf + STL_TXBUFSIZE;
1947 portp->tx.head = portp->tx.buf;
1948 portp->tx.tail = portp->tx.buf;
1949 portp->rx.buf = portp->tx.buf + STL_TXBUFSIZE;
1950 portp->rx.endbuf = portp->rx.buf + STL_RXBUFSIZE;
1951 portp->rx.head = portp->rx.buf;
1952 portp->rx.tail = portp->rx.buf;
1953 portp->rxstatus.buf = portp->rx.buf + STL_RXBUFSIZE;
1954 portp->rxstatus.endbuf = portp->rxstatus.buf + STL_RXBUFSIZE;
1955 portp->rxstatus.head = portp->rxstatus.buf;
1956 portp->rxstatus.tail = portp->rxstatus.buf;
1957 bzero(portp->rxstatus.head, STL_RXBUFSIZE);
1959 portp->initintios.c_ispeed = STL_DEFSPEED;
1960 portp->initintios.c_ospeed = STL_DEFSPEED;
1961 portp->initintios.c_cflag = STL_DEFCFLAG;
1962 portp->initintios.c_iflag = 0;
1963 portp->initintios.c_oflag = 0;
1964 portp->initintios.c_lflag = 0;
1965 bcopy(&ttydefchars[0], &portp->initintios.c_cc[0],
1966 sizeof(portp->initintios.c_cc));
1967 portp->initouttios = portp->initintios;
1968 portp->dtrwait = 3 * hz;
1969 callout_init(&portp->dtr_ch);
1971 stl_portinit(brdp, panelp, portp);
1977 /*****************************************************************************/
1980 * Try to find and initialize an EasyIO board.
1983 static int stl_initeio(stlbrd_t *brdp)
1986 unsigned int status;
1989 kprintf("stl_initeio(brdp=%x)\n", (int) brdp);
1992 brdp->ioctrl = brdp->ioaddr1 + 1;
1993 brdp->iostatus = brdp->ioaddr1 + 2;
1994 brdp->clk = EIO_CLK;
1995 brdp->isr = stl_eiointr;
1997 status = inb(brdp->iostatus);
1998 switch (status & EIO_IDBITMASK) {
2000 brdp->clk = EIO_CLK8M;
2010 switch (status & EIO_BRDMASK) {
2029 if (brdp->brdtype == BRD_EASYIOPCI) {
2030 outb((brdp->ioaddr2 + 0x4c), 0x41);
2033 * Check that the supplied IRQ is good and then use it to setup the
2034 * programmable interrupt bits on EIO board. Also set the edge/level
2035 * triggered interrupt bit.
2037 if ((brdp->irq < 0) || (brdp->irq > 15) ||
2038 (stl_vecmap[brdp->irq] == (unsigned char) 0xff)) {
2039 kprintf("STALLION: invalid irq=%d for brd=%d\n",
2040 brdp->irq, brdp->brdnr);
2043 outb(brdp->ioctrl, (stl_vecmap[brdp->irq] |
2044 ((brdp->irqtype) ? EIO_INTLEVEL : EIO_INTEDGE)));
2047 panelp = kmalloc(sizeof(stlpanel_t), M_TTYS, M_WAITOK | M_ZERO);
2048 panelp->brdnr = brdp->brdnr;
2049 panelp->panelnr = 0;
2050 panelp->nrports = brdp->nrports;
2051 panelp->iobase = brdp->ioaddr1;
2052 panelp->hwid = status;
2053 if ((status & EIO_IDBITMASK) == EIO_MK3) {
2054 panelp->uartp = (void *) &stl_sc26198uart;
2055 panelp->isr = stl_sc26198intr;
2057 panelp->uartp = (void *) &stl_cd1400uart;
2058 panelp->isr = stl_cd1400eiointr;
2060 brdp->panels[0] = panelp;
2062 brdp->hwid = status;
2063 brdp->state |= BRD_FOUND;
2067 /*****************************************************************************/
2070 * Try to find an ECH board and initialize it. This code is capable of
2071 * dealing with all types of ECH board.
2074 static int stl_initech(stlbrd_t *brdp)
2077 unsigned int status, nxtid;
2078 int panelnr, ioaddr, banknr, i;
2081 kprintf("stl_initech(brdp=%x)\n", (int) brdp);
2085 * Set up the initial board register contents for boards. This varys a
2086 * bit between the different board types. So we need to handle each
2087 * separately. Also do a check that the supplied IRQ is good.
2089 switch (brdp->brdtype) {
2092 brdp->isr = stl_echatintr;
2093 brdp->ioctrl = brdp->ioaddr1 + 1;
2094 brdp->iostatus = brdp->ioaddr1 + 1;
2095 status = inb(brdp->iostatus);
2096 if ((status & ECH_IDBITMASK) != ECH_ID)
2098 brdp->hwid = status;
2100 if ((brdp->irq < 0) || (brdp->irq > 15) ||
2101 (stl_vecmap[brdp->irq] == (unsigned char) 0xff)) {
2102 kprintf("STALLION: invalid irq=%d for brd=%d\n",
2103 brdp->irq, brdp->brdnr);
2106 status = ((brdp->ioaddr2 & ECH_ADDR2MASK) >> 1);
2107 status |= (stl_vecmap[brdp->irq] << 1);
2108 outb(brdp->ioaddr1, (status | ECH_BRDRESET));
2109 brdp->ioctrlval = ECH_INTENABLE |
2110 ((brdp->irqtype) ? ECH_INTLEVEL : ECH_INTEDGE);
2111 outb(brdp->ioctrl, (brdp->ioctrlval | ECH_BRDENABLE));
2112 outb(brdp->ioaddr1, status);
2116 brdp->isr = stl_echmcaintr;
2117 brdp->ioctrl = brdp->ioaddr1 + 0x20;
2118 brdp->iostatus = brdp->ioctrl;
2119 status = inb(brdp->iostatus);
2120 if ((status & ECH_IDBITMASK) != ECH_ID)
2122 brdp->hwid = status;
2124 if ((brdp->irq < 0) || (brdp->irq > 15) ||
2125 (stl_vecmap[brdp->irq] == (unsigned char) 0xff)) {
2126 kprintf("STALLION: invalid irq=%d for brd=%d\n",
2127 brdp->irq, brdp->brdnr);
2130 outb(brdp->ioctrl, ECHMC_BRDRESET);
2131 outb(brdp->ioctrl, ECHMC_INTENABLE);
2135 brdp->isr = stl_echpciintr;
2136 brdp->ioctrl = brdp->ioaddr1 + 2;
2140 brdp->isr = stl_echpci64intr;
2141 brdp->ioctrl = brdp->ioaddr2 + 0x40;
2142 outb((brdp->ioaddr1 + 0x4c), 0x43);
2146 kprintf("STALLION: unknown board type=%d\n", brdp->brdtype);
2150 brdp->clk = ECH_CLK;
2153 * Scan through the secondary io address space looking for panels.
2154 * As we find'em allocate and initialize panel structures for each.
2156 ioaddr = brdp->ioaddr2;
2161 for (i = 0; (i < STL_MAXPANELS); i++) {
2162 if (brdp->brdtype == BRD_ECHPCI) {
2163 outb(brdp->ioctrl, nxtid);
2164 ioaddr = brdp->ioaddr2;
2166 status = inb(ioaddr + ECH_PNLSTATUS);
2167 if ((status & ECH_PNLIDMASK) != nxtid)
2169 panelp = kmalloc(sizeof(stlpanel_t), M_TTYS, M_WAITOK | M_ZERO);
2170 panelp->brdnr = brdp->brdnr;
2171 panelp->panelnr = panelnr;
2172 panelp->iobase = ioaddr;
2173 panelp->pagenr = nxtid;
2174 panelp->hwid = status;
2175 brdp->bnk2panel[banknr] = panelp;
2176 brdp->bnkpageaddr[banknr] = nxtid;
2177 brdp->bnkstataddr[banknr++] = ioaddr + ECH_PNLSTATUS;
2179 if (status & ECH_PNLXPID) {
2180 panelp->uartp = (void *) &stl_sc26198uart;
2181 panelp->isr = stl_sc26198intr;
2182 if (status & ECH_PNL16PORT) {
2183 panelp->nrports = 16;
2184 brdp->bnk2panel[banknr] = panelp;
2185 brdp->bnkpageaddr[banknr] = nxtid;
2186 brdp->bnkstataddr[banknr++] = ioaddr + 4 +
2189 panelp->nrports = 8;
2192 panelp->uartp = (void *) &stl_cd1400uart;
2193 panelp->isr = stl_cd1400echintr;
2194 if (status & ECH_PNL16PORT) {
2195 panelp->nrports = 16;
2196 panelp->ackmask = 0x80;
2197 if (brdp->brdtype != BRD_ECHPCI)
2198 ioaddr += EREG_BANKSIZE;
2199 brdp->bnk2panel[banknr] = panelp;
2200 brdp->bnkpageaddr[banknr] = ++nxtid;
2201 brdp->bnkstataddr[banknr++] = ioaddr +
2204 panelp->nrports = 8;
2205 panelp->ackmask = 0xc0;
2210 ioaddr += EREG_BANKSIZE;
2211 brdp->nrports += panelp->nrports;
2212 brdp->panels[panelnr++] = panelp;
2213 if ((brdp->brdtype == BRD_ECH) || (brdp->brdtype == BRD_ECHMC)){
2214 if (ioaddr >= (brdp->ioaddr2 + 0x20)) {
2215 kprintf("STALLION: too many ports attached "
2216 "to board %d, remove last module\n",
2223 brdp->nrpanels = panelnr;
2224 brdp->nrbnks = banknr;
2225 if (brdp->brdtype == BRD_ECH)
2226 outb(brdp->ioctrl, (brdp->ioctrlval | ECH_BRDDISABLE));
2228 brdp->state |= BRD_FOUND;
2232 /*****************************************************************************/
2235 * Initialize and configure the specified board. This firstly probes
2236 * for the board, if it is found then the board is initialized and
2237 * then all its ports are initialized as well.
2240 static int stl_brdinit(stlbrd_t *brdp)
2246 kprintf("stl_brdinit(brdp=%x): unit=%d type=%d io1=%x io2=%x irq=%d\n",
2247 (int) brdp, brdp->brdnr, brdp->brdtype, brdp->ioaddr1,
2248 brdp->ioaddr2, brdp->irq);
2251 switch (brdp->brdtype) {
2263 kprintf("STALLION: unit=%d is unknown board type=%d\n",
2264 brdp->brdnr, brdp->brdtype);
2268 stl_brds[brdp->brdnr] = brdp;
2269 if ((brdp->state & BRD_FOUND) == 0) {
2271 kprintf("STALLION: %s board not found, unit=%d io=%x irq=%d\n",
2272 stl_brdnames[brdp->brdtype], brdp->brdnr,
2273 brdp->ioaddr1, brdp->irq);
2278 for (i = 0, k = 0; (i < STL_MAXPANELS); i++) {
2279 panelp = brdp->panels[i];
2280 if (panelp != NULL) {
2281 stl_initports(brdp, panelp);
2282 for (j = 0; (j < panelp->nrports); j++)
2283 brdp->ports[k++] = panelp->ports[j];
2287 kprintf("stl%d: %s (driver version %s) unit=%d nrpanels=%d nrports=%d\n",
2288 brdp->unitid, stl_brdnames[brdp->brdtype], stl_drvversion,
2289 brdp->brdnr, brdp->nrpanels, brdp->nrports);
2293 /*****************************************************************************/
2296 * Return the board stats structure to user app.
2299 static int stl_getbrdstats(caddr_t data)
2305 stl_brdstats = *((combrd_t *) data);
2306 if (stl_brdstats.brd >= STL_MAXBRDS)
2308 brdp = stl_brds[stl_brdstats.brd];
2312 bzero(&stl_brdstats, sizeof(combrd_t));
2313 stl_brdstats.brd = brdp->brdnr;
2314 stl_brdstats.type = brdp->brdtype;
2315 stl_brdstats.hwid = brdp->hwid;
2316 stl_brdstats.state = brdp->state;
2317 stl_brdstats.ioaddr = brdp->ioaddr1;
2318 stl_brdstats.ioaddr2 = brdp->ioaddr2;
2319 stl_brdstats.irq = brdp->irq;
2320 stl_brdstats.nrpanels = brdp->nrpanels;
2321 stl_brdstats.nrports = brdp->nrports;
2322 for (i = 0; (i < brdp->nrpanels); i++) {
2323 panelp = brdp->panels[i];
2324 stl_brdstats.panels[i].panel = i;
2325 stl_brdstats.panels[i].hwid = panelp->hwid;
2326 stl_brdstats.panels[i].nrports = panelp->nrports;
2329 *((combrd_t *) data) = stl_brdstats;
2333 /*****************************************************************************/
2336 * Resolve the referenced port number into a port struct pointer.
2339 static stlport_t *stl_getport(int brdnr, int panelnr, int portnr)
2344 if ((brdnr < 0) || (brdnr >= STL_MAXBRDS))
2346 brdp = stl_brds[brdnr];
2349 if ((panelnr < 0) || (panelnr >= brdp->nrpanels))
2351 panelp = brdp->panels[panelnr];
2354 if ((portnr < 0) || (portnr >= panelp->nrports))
2356 return(panelp->ports[portnr]);
2359 /*****************************************************************************/
2362 * Return the port stats structure to user app. A NULL port struct
2363 * pointer passed in means that we need to find out from the app
2364 * what port to get stats for (used through board control device).
2367 static int stl_getportstats(stlport_t *portp, caddr_t data)
2369 unsigned char *head, *tail;
2371 if (portp == NULL) {
2372 stl_comstats = *((comstats_t *) data);
2373 portp = stl_getport(stl_comstats.brd, stl_comstats.panel,
2379 portp->stats.state = portp->state;
2380 /*portp->stats.flags = portp->flags;*/
2381 portp->stats.hwid = portp->hwid;
2382 portp->stats.ttystate = portp->tty.t_state;
2383 portp->stats.cflags = portp->tty.t_cflag;
2384 portp->stats.iflags = portp->tty.t_iflag;
2385 portp->stats.oflags = portp->tty.t_oflag;
2386 portp->stats.lflags = portp->tty.t_lflag;
2388 head = portp->tx.head;
2389 tail = portp->tx.tail;
2390 portp->stats.txbuffered = ((head >= tail) ? (head - tail) :
2391 (STL_TXBUFSIZE - (tail - head)));
2393 head = portp->rx.head;
2394 tail = portp->rx.tail;
2395 portp->stats.rxbuffered = (head >= tail) ? (head - tail) :
2396 (STL_RXBUFSIZE - (tail - head));
2398 portp->stats.signals = (unsigned long) stl_getsignals(portp);
2400 *((comstats_t *) data) = portp->stats;
2404 /*****************************************************************************/
2407 * Clear the port stats structure. We also return it zeroed out...
2410 static int stl_clrportstats(stlport_t *portp, caddr_t data)
2412 if (portp == NULL) {
2413 stl_comstats = *((comstats_t *) data);
2414 portp = stl_getport(stl_comstats.brd, stl_comstats.panel,
2420 bzero(&portp->stats, sizeof(comstats_t));
2421 portp->stats.brd = portp->brdnr;
2422 portp->stats.panel = portp->panelnr;
2423 portp->stats.port = portp->portnr;
2424 *((comstats_t *) data) = stl_comstats;
2428 /*****************************************************************************/
2431 * The "staliomem" device is used for stats collection in this driver.
2434 static int stl_memioctl(cdev_t dev, unsigned long cmd, caddr_t data, int flag)
2439 kprintf("stl_memioctl(dev=%s,cmd=%lx,data=%p,flag=%x)\n",
2440 devtoname(dev), cmd, (void *) data, flag);
2446 case COM_GETPORTSTATS:
2447 rc = stl_getportstats(NULL, data);
2449 case COM_CLRPORTSTATS:
2450 rc = stl_clrportstats(NULL, data);
2452 case COM_GETBRDSTATS:
2453 rc = stl_getbrdstats(data);
2463 /*****************************************************************************/
2465 /*****************************************************************************/
2466 /* CD1400 UART CODE */
2467 /*****************************************************************************/
2470 * These functions get/set/update the registers of the cd1400 UARTs.
2471 * Access to the cd1400 registers is via an address/data io port pair.
2474 static int stl_cd1400getreg(stlport_t *portp, int regnr)
2476 outb(portp->ioaddr, (regnr + portp->uartaddr));
2477 return(inb(portp->ioaddr + EREG_DATA));
2480 /*****************************************************************************/
2482 static void stl_cd1400setreg(stlport_t *portp, int regnr, int value)
2484 outb(portp->ioaddr, (regnr + portp->uartaddr));
2485 outb((portp->ioaddr + EREG_DATA), value);
2488 /*****************************************************************************/
2490 static int stl_cd1400updatereg(stlport_t *portp, int regnr, int value)
2492 outb(portp->ioaddr, (regnr + portp->uartaddr));
2493 if (inb(portp->ioaddr + EREG_DATA) != value) {
2494 outb((portp->ioaddr + EREG_DATA), value);
2500 /*****************************************************************************/
2502 static void stl_cd1400flush(stlport_t *portp, int flag)
2506 kprintf("stl_cd1400flush(portp=%x,flag=%x)\n", (int) portp, flag);
2514 if (flag & FWRITE) {
2515 BRDENABLE(portp->brdnr, portp->pagenr);
2516 stl_cd1400setreg(portp, CAR, (portp->portnr & 0x03));
2517 stl_cd1400ccrwait(portp);
2518 stl_cd1400setreg(portp, CCR, CCR_TXFLUSHFIFO);
2519 stl_cd1400ccrwait(portp);
2520 BRDDISABLE(portp->brdnr);
2530 /*****************************************************************************/
2532 static void stl_cd1400ccrwait(stlport_t *portp)
2536 for (i = 0; (i < CCR_MAXWAIT); i++) {
2537 if (stl_cd1400getreg(portp, CCR) == 0)
2541 kprintf("stl%d: cd1400 device not responding, panel=%d port=%d\n",
2542 portp->brdnr, portp->panelnr, portp->portnr);
2545 /*****************************************************************************/
2548 * Transmit interrupt handler. This has gotta be fast! Handling TX
2549 * chars is pretty simple, stuff as many as possible from the TX buffer
2550 * into the cd1400 FIFO. Must also handle TX breaks here, since they
2551 * are embedded as commands in the data stream. Oh no, had to use a goto!
2554 static __inline void stl_cd1400txisr(stlpanel_t *panelp, int ioaddr)
2557 unsigned char ioack, srer;
2562 kprintf("stl_cd1400txisr(panelp=%x,ioaddr=%x)\n", (int) panelp, ioaddr);
2565 ioack = inb(ioaddr + EREG_TXACK);
2566 if (((ioack & panelp->ackmask) != 0) ||
2567 ((ioack & ACK_TYPMASK) != ACK_TYPTX)) {
2568 kprintf("STALLION: bad TX interrupt ack value=%x\n",
2572 portp = panelp->ports[(ioack >> 3)];
2575 * Unfortunately we need to handle breaks in the data stream, since
2576 * this is the only way to generate them on the cd1400. Do it now if
2577 * a break is to be sent. Some special cases here: brklen is -1 then
2578 * start sending an un-timed break, if brklen is -2 then stop sending
2579 * an un-timed break, if brklen is -3 then we have just sent an
2580 * un-timed break and do not want any data to go out, if brklen is -4
2581 * then a break has just completed so clean up the port settings.
2583 if (portp->brklen != 0) {
2584 if (portp->brklen >= -1) {
2585 outb(ioaddr, (TDR + portp->uartaddr));
2586 outb((ioaddr + EREG_DATA), ETC_CMD);
2587 outb((ioaddr + EREG_DATA), ETC_STARTBREAK);
2588 if (portp->brklen > 0) {
2589 outb((ioaddr + EREG_DATA), ETC_CMD);
2590 outb((ioaddr + EREG_DATA), ETC_DELAY);
2591 outb((ioaddr + EREG_DATA), portp->brklen);
2592 outb((ioaddr + EREG_DATA), ETC_CMD);
2593 outb((ioaddr + EREG_DATA), ETC_STOPBREAK);
2598 } else if (portp->brklen == -2) {
2599 outb(ioaddr, (TDR + portp->uartaddr));
2600 outb((ioaddr + EREG_DATA), ETC_CMD);
2601 outb((ioaddr + EREG_DATA), ETC_STOPBREAK);
2603 } else if (portp->brklen == -3) {
2604 outb(ioaddr, (SRER + portp->uartaddr));
2605 srer = inb(ioaddr + EREG_DATA);
2606 srer &= ~(SRER_TXDATA | SRER_TXEMPTY);
2607 outb((ioaddr + EREG_DATA), srer);
2609 outb(ioaddr, (COR2 + portp->uartaddr));
2610 outb((ioaddr + EREG_DATA),
2611 (inb(ioaddr + EREG_DATA) & ~COR2_ETC));
2617 head = portp->tx.head;
2618 tail = portp->tx.tail;
2619 len = (head >= tail) ? (head - tail) : (STL_TXBUFSIZE - (tail - head));
2620 if ((len == 0) || ((len < STL_TXBUFLOW) &&
2621 ((portp->state & ASY_TXLOW) == 0))) {
2622 portp->state |= ASY_TXLOW;
2627 outb(ioaddr, (SRER + portp->uartaddr));
2628 srer = inb(ioaddr + EREG_DATA);
2629 if (srer & SRER_TXDATA) {
2630 srer = (srer & ~SRER_TXDATA) | SRER_TXEMPTY;
2632 srer &= ~(SRER_TXDATA | SRER_TXEMPTY);
2633 portp->state |= ASY_TXEMPTY;
2634 portp->state &= ~ASY_TXBUSY;
2636 outb((ioaddr + EREG_DATA), srer);
2638 len = MIN(len, CD1400_TXFIFOSIZE);
2639 portp->stats.txtotal += len;
2640 stlen = MIN(len, (portp->tx.endbuf - tail));
2641 outb(ioaddr, (TDR + portp->uartaddr));
2642 outsb((ioaddr + EREG_DATA), tail, stlen);
2645 if (tail >= portp->tx.endbuf)
2646 tail = portp->tx.buf;
2648 outsb((ioaddr + EREG_DATA), tail, len);
2651 portp->tx.tail = tail;
2655 outb(ioaddr, (EOSRR + portp->uartaddr));
2656 outb((ioaddr + EREG_DATA), 0);
2659 /*****************************************************************************/
2662 * Receive character interrupt handler. Determine if we have good chars
2663 * or bad chars and then process appropriately.
2666 static __inline void stl_cd1400rxisr(stlpanel_t *panelp, int ioaddr)
2670 unsigned int ioack, len, buflen, stlen;
2671 unsigned char status;
2676 kprintf("stl_cd1400rxisr(panelp=%x,ioaddr=%x)\n", (int) panelp, ioaddr);
2679 ioack = inb(ioaddr + EREG_RXACK);
2680 if ((ioack & panelp->ackmask) != 0) {
2681 kprintf("STALLION: bad RX interrupt ack value=%x\n", ioack);
2684 portp = panelp->ports[(ioack >> 3)];
2688 * First up, calculate how much room there is in the RX ring queue.
2689 * We also want to keep track of the longest possible copy length,
2690 * this has to allow for the wrapping of the ring queue.
2692 head = portp->rx.head;
2693 tail = portp->rx.tail;
2695 buflen = STL_RXBUFSIZE - (head - tail) - 1;
2696 stlen = portp->rx.endbuf - head;
2698 buflen = tail - head - 1;
2703 * Check if the input buffer is near full. If so then we should take
2704 * some flow control action... It is very easy to do hardware and
2705 * software flow control from here since we have the port selected on
2708 if (buflen <= (STL_RXBUFSIZE - STL_RXBUFHIGH)) {
2709 if (((portp->state & ASY_RTSFLOW) == 0) &&
2710 (portp->state & ASY_RTSFLOWMODE)) {
2711 portp->state |= ASY_RTSFLOW;
2712 stl_cd1400setreg(portp, MCOR1,
2713 (stl_cd1400getreg(portp, MCOR1) & 0xf0));
2714 stl_cd1400setreg(portp, MSVR2, 0);
2715 portp->stats.rxrtsoff++;
2720 * OK we are set, process good data... If the RX ring queue is full
2721 * just chuck the chars - don't leave them in the UART.
2723 if ((ioack & ACK_TYPMASK) == ACK_TYPRXGOOD) {
2724 outb(ioaddr, (RDCR + portp->uartaddr));
2725 len = inb(ioaddr + EREG_DATA);
2727 outb(ioaddr, (RDSR + portp->uartaddr));
2728 insb((ioaddr + EREG_DATA), &stl_unwanted[0], len);
2729 portp->stats.rxlost += len;
2730 portp->stats.rxtotal += len;
2732 len = MIN(len, buflen);
2733 portp->stats.rxtotal += len;
2734 stlen = MIN(len, stlen);
2736 outb(ioaddr, (RDSR + portp->uartaddr));
2737 insb((ioaddr + EREG_DATA), head, stlen);
2739 if (head >= portp->rx.endbuf) {
2740 head = portp->rx.buf;
2742 insb((ioaddr + EREG_DATA), head, len);
2747 } else if ((ioack & ACK_TYPMASK) == ACK_TYPRXBAD) {
2748 outb(ioaddr, (RDSR + portp->uartaddr));
2749 status = inb(ioaddr + EREG_DATA);
2750 ch = inb(ioaddr + EREG_DATA);
2751 if (status & ST_BREAK)
2752 portp->stats.rxbreaks++;
2753 if (status & ST_FRAMING)
2754 portp->stats.rxframing++;
2755 if (status & ST_PARITY)
2756 portp->stats.rxparity++;
2757 if (status & ST_OVERRUN)
2758 portp->stats.rxoverrun++;
2759 if (status & ST_SCHARMASK) {
2760 if ((status & ST_SCHARMASK) == ST_SCHAR1)
2761 portp->stats.txxon++;
2762 if ((status & ST_SCHARMASK) == ST_SCHAR2)
2763 portp->stats.txxoff++;
2766 if ((portp->rxignoremsk & status) == 0) {
2767 if ((tp->t_state & TS_CAN_BYPASS_L_RINT) &&
2768 ((status & ST_FRAMING) ||
2769 ((status & ST_PARITY) && (tp->t_iflag & INPCK))))
2771 if ((portp->rxmarkmsk & status) == 0)
2773 *(head + STL_RXBUFSIZE) = status;
2775 if (head >= portp->rx.endbuf)
2776 head = portp->rx.buf;
2779 kprintf("STALLION: bad RX interrupt ack value=%x\n", ioack);
2783 portp->rx.head = head;
2784 portp->state |= ASY_RXDATA;
2788 outb(ioaddr, (EOSRR + portp->uartaddr));
2789 outb((ioaddr + EREG_DATA), 0);
2792 /*****************************************************************************/
2795 * Modem interrupt handler. The is called when the modem signal line
2796 * (DCD) has changed state.
2799 static __inline void stl_cd1400mdmisr(stlpanel_t *panelp, int ioaddr)
2806 kprintf("stl_cd1400mdmisr(panelp=%x,ioaddr=%x)\n", (int) panelp, ioaddr);
2809 ioack = inb(ioaddr + EREG_MDACK);
2810 if (((ioack & panelp->ackmask) != 0) ||
2811 ((ioack & ACK_TYPMASK) != ACK_TYPMDM)) {
2812 kprintf("STALLION: bad MODEM interrupt ack value=%x\n", ioack);
2815 portp = panelp->ports[(ioack >> 3)];
2817 outb(ioaddr, (MISR + portp->uartaddr));
2818 misr = inb(ioaddr + EREG_DATA);
2819 if (misr & MISR_DCD) {
2820 portp->state |= ASY_DCDCHANGE;
2821 portp->stats.modem++;
2825 outb(ioaddr, (EOSRR + portp->uartaddr));
2826 outb((ioaddr + EREG_DATA), 0);
2829 /*****************************************************************************/
2832 * Interrupt service routine for cd1400 EasyIO boards.
2835 static void stl_cd1400eiointr(stlpanel_t *panelp, unsigned int iobase)
2837 unsigned char svrtype;
2840 kprintf("stl_cd1400eiointr(panelp=%x,iobase=%x)\n", (int) panelp,
2845 svrtype = inb(iobase + EREG_DATA);
2846 if (panelp->nrports > 4) {
2847 outb(iobase, (SVRR + 0x80));
2848 svrtype |= inb(iobase + EREG_DATA);
2851 kprintf("stl_cd1400eiointr(panelp=%x,iobase=%x): svrr=%x\n", (int) panelp, iobase, svrtype);
2854 if (svrtype & SVRR_RX)
2855 stl_cd1400rxisr(panelp, iobase);
2856 else if (svrtype & SVRR_TX)
2857 stl_cd1400txisr(panelp, iobase);
2858 else if (svrtype & SVRR_MDM)
2859 stl_cd1400mdmisr(panelp, iobase);
2862 /*****************************************************************************/
2865 * Interrupt service routine for cd1400 panels.
2868 static void stl_cd1400echintr(stlpanel_t *panelp, unsigned int iobase)
2870 unsigned char svrtype;
2873 kprintf("stl_cd1400echintr(panelp=%x,iobase=%x)\n", (int) panelp,
2878 svrtype = inb(iobase + EREG_DATA);
2879 outb(iobase, (SVRR + 0x80));
2880 svrtype |= inb(iobase + EREG_DATA);
2881 if (svrtype & SVRR_RX)
2882 stl_cd1400rxisr(panelp, iobase);
2883 else if (svrtype & SVRR_TX)
2884 stl_cd1400txisr(panelp, iobase);
2885 else if (svrtype & SVRR_MDM)
2886 stl_cd1400mdmisr(panelp, iobase);
2889 /*****************************************************************************/
2892 * Set up the cd1400 registers for a port based on the termios port
2896 static int stl_cd1400setport(stlport_t *portp, struct termios *tiosp)
2898 unsigned int clkdiv;
2899 unsigned char cor1, cor2, cor3;
2900 unsigned char cor4, cor5, ccr;
2901 unsigned char srer, sreron, sreroff;
2902 unsigned char mcor1, mcor2, rtpr;
2903 unsigned char clk, div;
2906 kprintf("stl_cd1400setport(portp=%x,tiosp=%x): brdnr=%d portnr=%d\n",
2907 (int) portp, (int) tiosp, portp->brdnr, portp->portnr);
2925 * Set up the RX char ignore mask with those RX error types we
2926 * can ignore. We could have used some special modes of the cd1400
2927 * UART to help, but it is better this way because we can keep stats
2928 * on the number of each type of RX exception event.
2930 portp->rxignoremsk = 0;
2931 if (tiosp->c_iflag & IGNPAR)
2932 portp->rxignoremsk |= (ST_PARITY | ST_FRAMING | ST_OVERRUN);
2933 if (tiosp->c_iflag & IGNBRK)
2934 portp->rxignoremsk |= ST_BREAK;
2936 portp->rxmarkmsk = ST_OVERRUN;
2937 if (tiosp->c_iflag & (INPCK | PARMRK))
2938 portp->rxmarkmsk |= (ST_PARITY | ST_FRAMING);
2939 if (tiosp->c_iflag & BRKINT)
2940 portp->rxmarkmsk |= ST_BREAK;
2943 * Go through the char size, parity and stop bits and set all the
2944 * option registers appropriately.
2946 switch (tiosp->c_cflag & CSIZE) {
2961 if (tiosp->c_cflag & CSTOPB)
2966 if (tiosp->c_cflag & PARENB) {
2967 if (tiosp->c_cflag & PARODD)
2968 cor1 |= (COR1_PARENB | COR1_PARODD);
2970 cor1 |= (COR1_PARENB | COR1_PAREVEN);
2972 cor1 |= COR1_PARNONE;
2976 * Set the RX FIFO threshold at 6 chars. This gives a bit of breathing
2977 * space for hardware flow control and the like. This should be set to
2978 * VMIN. Also here we will set the RX data timeout to 10ms - this should
2979 * really be based on VTIME...
2981 cor3 |= FIFO_RXTHRESHOLD;
2985 * Calculate the baud rate timers. For now we will just assume that
2986 * the input and output baud are the same. Could have used a baud
2987 * table here, but this way we can generate virtually any baud rate
2990 if (tiosp->c_ispeed == 0)
2991 tiosp->c_ispeed = tiosp->c_ospeed;
2992 if ((tiosp->c_ospeed < 0) || (tiosp->c_ospeed > CD1400_MAXBAUD))
2995 if (tiosp->c_ospeed > 0) {
2996 for (clk = 0; (clk < CD1400_NUMCLKS); clk++) {
2997 clkdiv = ((portp->clk / stl_cd1400clkdivs[clk]) /
3002 div = (unsigned char) clkdiv;
3006 * Check what form of modem signaling is required and set it up.
3008 if ((tiosp->c_cflag & CLOCAL) == 0) {
3011 sreron |= SRER_MODEM;
3015 * Setup cd1400 enhanced modes if we can. In particular we want to
3016 * handle as much of the flow control as possbile automatically. As
3017 * well as saving a few CPU cycles it will also greatly improve flow
3018 * control reliablilty.
3020 if (tiosp->c_iflag & IXON) {
3023 if (tiosp->c_iflag & IXANY)
3027 if (tiosp->c_cflag & CCTS_OFLOW)
3029 if (tiosp->c_cflag & CRTS_IFLOW)
3030 mcor1 |= FIFO_RTSTHRESHOLD;
3033 * All cd1400 register values calculated so go through and set them
3037 kprintf("SETPORT: portnr=%d panelnr=%d brdnr=%d\n", portp->portnr,
3038 portp->panelnr, portp->brdnr);
3039 kprintf(" cor1=%x cor2=%x cor3=%x cor4=%x cor5=%x\n", cor1, cor2,
3041 kprintf(" mcor1=%x mcor2=%x rtpr=%x sreron=%x sreroff=%x\n",
3042 mcor1, mcor2, rtpr, sreron, sreroff);
3043 kprintf(" tcor=%x tbpr=%x rcor=%x rbpr=%x\n", clk, div, clk, div);
3044 kprintf(" schr1=%x schr2=%x schr3=%x schr4=%x\n",
3045 tiosp->c_cc[VSTART], tiosp->c_cc[VSTOP], tiosp->c_cc[VSTART],
3046 tiosp->c_cc[VSTOP]);
3050 BRDENABLE(portp->brdnr, portp->pagenr);
3051 stl_cd1400setreg(portp, CAR, (portp->portnr & 0x3));
3052 srer = stl_cd1400getreg(portp, SRER);
3053 stl_cd1400setreg(portp, SRER, 0);
3054 ccr += stl_cd1400updatereg(portp, COR1, cor1);
3055 ccr += stl_cd1400updatereg(portp, COR2, cor2);
3056 ccr += stl_cd1400updatereg(portp, COR3, cor3);
3058 stl_cd1400ccrwait(portp);
3059 stl_cd1400setreg(portp, CCR, CCR_CORCHANGE);
3061 stl_cd1400setreg(portp, COR4, cor4);
3062 stl_cd1400setreg(portp, COR5, cor5);
3063 stl_cd1400setreg(portp, MCOR1, mcor1);
3064 stl_cd1400setreg(portp, MCOR2, mcor2);
3065 if (tiosp->c_ospeed == 0) {
3066 stl_cd1400setreg(portp, MSVR1, 0);
3068 stl_cd1400setreg(portp, MSVR1, MSVR1_DTR);
3069 stl_cd1400setreg(portp, TCOR, clk);
3070 stl_cd1400setreg(portp, TBPR, div);
3071 stl_cd1400setreg(portp, RCOR, clk);
3072 stl_cd1400setreg(portp, RBPR, div);
3074 stl_cd1400setreg(portp, SCHR1, tiosp->c_cc[VSTART]);
3075 stl_cd1400setreg(portp, SCHR2, tiosp->c_cc[VSTOP]);
3076 stl_cd1400setreg(portp, SCHR3, tiosp->c_cc[VSTART]);
3077 stl_cd1400setreg(portp, SCHR4, tiosp->c_cc[VSTOP]);
3078 stl_cd1400setreg(portp, RTPR, rtpr);
3079 mcor1 = stl_cd1400getreg(portp, MSVR1);
3080 if (mcor1 & MSVR1_DCD)
3081 portp->sigs |= TIOCM_CD;
3083 portp->sigs &= ~TIOCM_CD;
3084 stl_cd1400setreg(portp, SRER, ((srer & ~sreroff) | sreron));
3085 BRDDISABLE(portp->brdnr);
3086 portp->state &= ~(ASY_RTSFLOWMODE | ASY_CTSFLOWMODE);
3087 portp->state |= ((tiosp->c_cflag & CRTS_IFLOW) ? ASY_RTSFLOWMODE : 0);
3088 portp->state |= ((tiosp->c_cflag & CCTS_OFLOW) ? ASY_CTSFLOWMODE : 0);
3089 stl_ttyoptim(portp, tiosp);
3095 /*****************************************************************************/
3098 * Action the flow control as required. The hw and sw args inform the
3099 * routine what flow control methods it should try.
3102 static void stl_cd1400sendflow(stlport_t *portp, int hw, int sw)
3106 kprintf("stl_cd1400sendflow(portp=%x,hw=%d,sw=%d)\n",
3107 (int) portp, hw, sw);
3111 BRDENABLE(portp->brdnr, portp->pagenr);
3112 stl_cd1400setreg(portp, CAR, (portp->portnr & 0x03));
3115 stl_cd1400ccrwait(portp);
3117 stl_cd1400setreg(portp, CCR, CCR_SENDSCHR2);
3118 portp->stats.rxxoff++;
3120 stl_cd1400setreg(portp, CCR, CCR_SENDSCHR1);
3121 portp->stats.rxxon++;
3123 stl_cd1400ccrwait(portp);
3127 portp->state |= ASY_RTSFLOW;
3128 stl_cd1400setreg(portp, MCOR1,
3129 (stl_cd1400getreg(portp, MCOR1) & 0xf0));
3130 stl_cd1400setreg(portp, MSVR2, 0);
3131 portp->stats.rxrtsoff++;
3132 } else if (hw > 0) {
3133 portp->state &= ~ASY_RTSFLOW;
3134 stl_cd1400setreg(portp, MSVR2, MSVR2_RTS);
3135 stl_cd1400setreg(portp, MCOR1,
3136 (stl_cd1400getreg(portp, MCOR1) | FIFO_RTSTHRESHOLD));
3137 portp->stats.rxrtson++;
3140 BRDDISABLE(portp->brdnr);
3144 /*****************************************************************************/
3147 * Return the current state of data flow on this port. This is only
3148 * really interresting when determining if data has fully completed
3149 * transmission or not... This is easy for the cd1400, it accurately
3150 * maintains the busy port flag.
3153 static int stl_cd1400datastate(stlport_t *portp)
3156 kprintf("stl_cd1400datastate(portp=%x)\n", (int) portp);
3162 return((portp->state & ASY_TXBUSY) ? 1 : 0);
3165 /*****************************************************************************/
3168 * Set the state of the DTR and RTS signals. Got to do some extra
3169 * work here to deal hardware flow control.
3172 static void stl_cd1400setsignals(stlport_t *portp, int dtr, int rts)
3174 unsigned char msvr1, msvr2;
3177 kprintf("stl_cd1400setsignals(portp=%x,dtr=%d,rts=%d)\n", (int) portp,
3189 BRDENABLE(portp->brdnr, portp->pagenr);
3190 stl_cd1400setreg(portp, CAR, (portp->portnr & 0x03));
3192 if (portp->tty.t_cflag & CRTS_IFLOW) {
3194 stl_cd1400setreg(portp, MCOR1,
3195 (stl_cd1400getreg(portp, MCOR1) & 0xf0));
3196 portp->stats.rxrtsoff++;
3198 stl_cd1400setreg(portp, MCOR1,
3199 (stl_cd1400getreg(portp, MCOR1) |
3200 FIFO_RTSTHRESHOLD));
3201 portp->stats.rxrtson++;
3204 stl_cd1400setreg(portp, MSVR2, msvr2);
3207 stl_cd1400setreg(portp, MSVR1, msvr1);
3208 BRDDISABLE(portp->brdnr);
3212 /*****************************************************************************/
3215 * Get the state of the signals.
3218 static int stl_cd1400getsignals(stlport_t *portp)
3220 unsigned char msvr1, msvr2;
3224 kprintf("stl_cd1400getsignals(portp=%x)\n", (int) portp);
3228 BRDENABLE(portp->brdnr, portp->pagenr);
3229 stl_cd1400setreg(portp, CAR, (portp->portnr & 0x3));
3230 msvr1 = stl_cd1400getreg(portp, MSVR1);
3231 msvr2 = stl_cd1400getreg(portp, MSVR2);
3232 BRDDISABLE(portp->brdnr);
3236 sigs |= (msvr1 & MSVR1_DCD) ? TIOCM_CD : 0;
3237 sigs |= (msvr1 & MSVR1_CTS) ? TIOCM_CTS : 0;
3238 sigs |= (msvr1 & MSVR1_DTR) ? TIOCM_DTR : 0;
3239 sigs |= (msvr2 & MSVR2_RTS) ? TIOCM_RTS : 0;
3241 sigs |= (msvr1 & MSVR1_RI) ? TIOCM_RI : 0;
3242 sigs |= (msvr1 & MSVR1_DSR) ? TIOCM_DSR : 0;
3249 /*****************************************************************************/
3252 * Enable or disable the Transmitter and/or Receiver.
3255 static void stl_cd1400enablerxtx(stlport_t *portp, int rx, int tx)
3260 kprintf("stl_cd1400enablerxtx(portp=%x,rx=%d,tx=%d)\n",
3261 (int) portp, rx, tx);
3266 ccr |= CCR_TXDISABLE;
3268 ccr |= CCR_TXENABLE;
3270 ccr |= CCR_RXDISABLE;
3272 ccr |= CCR_RXENABLE;
3275 BRDENABLE(portp->brdnr, portp->pagenr);
3276 stl_cd1400setreg(portp, CAR, (portp->portnr & 0x03));
3277 stl_cd1400ccrwait(portp);
3278 stl_cd1400setreg(portp, CCR, ccr);
3279 stl_cd1400ccrwait(portp);
3280 BRDDISABLE(portp->brdnr);
3284 /*****************************************************************************/
3287 * Start or stop the Transmitter and/or Receiver.
3290 static void stl_cd1400startrxtx(stlport_t *portp, int rx, int tx)
3292 unsigned char sreron, sreroff;
3295 kprintf("stl_cd1400startrxtx(portp=%x,rx=%d,tx=%d)\n",
3296 (int) portp, rx, tx);
3302 sreroff |= (SRER_TXDATA | SRER_TXEMPTY);
3304 sreron |= SRER_TXDATA;
3306 sreron |= SRER_TXEMPTY;
3308 sreroff |= SRER_RXDATA;
3310 sreron |= SRER_RXDATA;
3313 BRDENABLE(portp->brdnr, portp->pagenr);
3314 stl_cd1400setreg(portp, CAR, (portp->portnr & 0x3));
3315 stl_cd1400setreg(portp, SRER,
3316 ((stl_cd1400getreg(portp, SRER) & ~sreroff) | sreron));
3317 BRDDISABLE(portp->brdnr);
3319 portp->state |= ASY_TXBUSY;
3320 portp->tty.t_state |= TS_BUSY;
3325 /*****************************************************************************/
3328 * Disable all interrupts from this port.
3331 static void stl_cd1400disableintrs(stlport_t *portp)
3335 kprintf("stl_cd1400disableintrs(portp=%x)\n", (int) portp);
3339 BRDENABLE(portp->brdnr, portp->pagenr);
3340 stl_cd1400setreg(portp, CAR, (portp->portnr & 0x3));
3341 stl_cd1400setreg(portp, SRER, 0);
3342 BRDDISABLE(portp->brdnr);
3346 /*****************************************************************************/
3348 static void stl_cd1400sendbreak(stlport_t *portp, long len)
3352 kprintf("stl_cd1400sendbreak(portp=%x,len=%d)\n", (int) portp,
3357 BRDENABLE(portp->brdnr, portp->pagenr);
3358 stl_cd1400setreg(portp, CAR, (portp->portnr & 0x3));
3359 stl_cd1400setreg(portp, COR2,
3360 (stl_cd1400getreg(portp, COR2) | COR2_ETC));
3361 stl_cd1400setreg(portp, SRER,
3362 ((stl_cd1400getreg(portp, SRER) & ~SRER_TXDATA) |
3364 BRDDISABLE(portp->brdnr);
3367 portp->brklen = (len > 255) ? 255 : len;
3369 portp->brklen = len;
3372 portp->stats.txbreaks++;
3375 /*****************************************************************************/
3378 * Try and find and initialize all the ports on a panel. We don't care
3379 * what sort of board these ports are on - since the port io registers
3380 * are almost identical when dealing with ports.
3383 static void stl_cd1400portinit(stlbrd_t *brdp, stlpanel_t *panelp, stlport_t *portp)
3386 kprintf("stl_cd1400portinit(brdp=%x,panelp=%x,portp=%x)\n",
3387 (int) brdp, (int) panelp, (int) portp);
3390 if ((brdp == NULL) || (panelp == NULL) ||
3394 portp->ioaddr = panelp->iobase + (((brdp->brdtype == BRD_ECHPCI) ||
3395 (portp->portnr < 8)) ? 0 : EREG_BANKSIZE);
3396 portp->uartaddr = (portp->portnr & 0x04) << 5;
3397 portp->pagenr = panelp->pagenr + (portp->portnr >> 3);
3399 BRDENABLE(portp->brdnr, portp->pagenr);
3400 stl_cd1400setreg(portp, CAR, (portp->portnr & 0x3));
3401 stl_cd1400setreg(portp, LIVR, (portp->portnr << 3));
3402 portp->hwid = stl_cd1400getreg(portp, GFRCR);
3403 BRDDISABLE(portp->brdnr);
3406 /*****************************************************************************/
3409 * Inbitialize the UARTs in a panel. We don't care what sort of board
3410 * these ports are on - since the port io registers are almost
3411 * identical when dealing with ports.
3414 static int stl_cd1400panelinit(stlbrd_t *brdp, stlpanel_t *panelp)
3418 int nrchips, uartaddr, ioaddr;
3421 kprintf("stl_cd1400panelinit(brdp=%x,panelp=%x)\n", (int) brdp,
3425 BRDENABLE(panelp->brdnr, panelp->pagenr);
3428 * Check that each chip is present and started up OK.
3431 nrchips = panelp->nrports / CD1400_PORTS;
3432 for (i = 0; (i < nrchips); i++) {
3433 if (brdp->brdtype == BRD_ECHPCI) {
3434 outb((panelp->pagenr + (i >> 1)), brdp->ioctrl);
3435 ioaddr = panelp->iobase;
3437 ioaddr = panelp->iobase + (EREG_BANKSIZE * (i >> 1));
3439 uartaddr = (i & 0x01) ? 0x080 : 0;
3440 outb(ioaddr, (GFRCR + uartaddr));
3441 outb((ioaddr + EREG_DATA), 0);
3442 outb(ioaddr, (CCR + uartaddr));
3443 outb((ioaddr + EREG_DATA), CCR_RESETFULL);
3444 outb((ioaddr + EREG_DATA), CCR_RESETFULL);
3445 outb(ioaddr, (GFRCR + uartaddr));
3446 for (j = 0; (j < CCR_MAXWAIT); j++) {
3447 if ((gfrcr = inb(ioaddr + EREG_DATA)) != 0)
3450 if ((j >= CCR_MAXWAIT) || (gfrcr < 0x40) || (gfrcr > 0x60)) {
3451 kprintf("STALLION: cd1400 not responding, "
3452 "board=%d panel=%d chip=%d\n", panelp->brdnr,
3453 panelp->panelnr, i);
3456 chipmask |= (0x1 << i);
3457 outb(ioaddr, (PPR + uartaddr));
3458 outb((ioaddr + EREG_DATA), PPR_SCALAR);
3462 BRDDISABLE(panelp->brdnr);
3466 /*****************************************************************************/
3467 /* SC26198 HARDWARE FUNCTIONS */
3468 /*****************************************************************************/
3471 * These functions get/set/update the registers of the sc26198 UARTs.
3472 * Access to the sc26198 registers is via an address/data io port pair.
3473 * (Maybe should make this inline...)
3476 static int stl_sc26198getreg(stlport_t *portp, int regnr)
3478 outb((portp->ioaddr + XP_ADDR), (regnr | portp->uartaddr));
3479 return(inb(portp->ioaddr + XP_DATA));
3482 static void stl_sc26198setreg(stlport_t *portp, int regnr, int value)
3484 outb((portp->ioaddr + XP_ADDR), (regnr | portp->uartaddr));
3485 outb((portp->ioaddr + XP_DATA), value);
3488 static int stl_sc26198updatereg(stlport_t *portp, int regnr, int value)
3490 outb((portp->ioaddr + XP_ADDR), (regnr | portp->uartaddr));
3491 if (inb(portp->ioaddr + XP_DATA) != value) {
3492 outb((portp->ioaddr + XP_DATA), value);
3498 /*****************************************************************************/
3501 * Functions to get and set the sc26198 global registers.
3504 static int stl_sc26198getglobreg(stlport_t *portp, int regnr)
3506 outb((portp->ioaddr + XP_ADDR), regnr);
3507 return(inb(portp->ioaddr + XP_DATA));
3511 static void stl_sc26198setglobreg(stlport_t *portp, int regnr, int value)
3513 outb((portp->ioaddr + XP_ADDR), regnr);
3514 outb((portp->ioaddr + XP_DATA), value);
3518 /*****************************************************************************/
3521 * Inbitialize the UARTs in a panel. We don't care what sort of board
3522 * these ports are on - since the port io registers are almost
3523 * identical when dealing with ports.
3526 static int stl_sc26198panelinit(stlbrd_t *brdp, stlpanel_t *panelp)
3529 int nrchips, ioaddr;
3532 kprintf("stl_sc26198panelinit(brdp=%x,panelp=%x)\n", (int) brdp,
3536 BRDENABLE(panelp->brdnr, panelp->pagenr);
3539 * Check that each chip is present and started up OK.
3542 nrchips = (panelp->nrports + 4) / SC26198_PORTS;
3543 if (brdp->brdtype == BRD_ECHPCI)
3544 outb(brdp->ioctrl, panelp->pagenr);
3546 for (i = 0; (i < nrchips); i++) {
3547 ioaddr = panelp->iobase + (i * 4);
3548 outb((ioaddr + XP_ADDR), SCCR);
3549 outb((ioaddr + XP_DATA), CR_RESETALL);
3550 outb((ioaddr + XP_ADDR), TSTR);
3551 if (inb(ioaddr + XP_DATA) != 0) {
3552 kprintf("STALLION: sc26198 not responding, "
3553 "board=%d panel=%d chip=%d\n", panelp->brdnr,
3554 panelp->panelnr, i);
3557 chipmask |= (0x1 << i);
3558 outb((ioaddr + XP_ADDR), GCCR);
3559 outb((ioaddr + XP_DATA), GCCR_IVRTYPCHANACK);
3560 outb((ioaddr + XP_ADDR), WDTRCR);
3561 outb((ioaddr + XP_DATA), 0xff);
3564 BRDDISABLE(panelp->brdnr);
3568 /*****************************************************************************/
3571 * Initialize hardware specific port registers.
3574 static void stl_sc26198portinit(stlbrd_t *brdp, stlpanel_t *panelp, stlport_t *portp)
3577 kprintf("stl_sc26198portinit(brdp=%x,panelp=%x,portp=%x)\n",
3578 (int) brdp, (int) panelp, (int) portp);
3581 if ((brdp == NULL) || (panelp == NULL) ||
3585 portp->ioaddr = panelp->iobase + ((portp->portnr < 8) ? 0 : 4);
3586 portp->uartaddr = (portp->portnr & 0x07) << 4;
3587 portp->pagenr = panelp->pagenr;
3590 BRDENABLE(portp->brdnr, portp->pagenr);
3591 stl_sc26198setreg(portp, IOPCR, IOPCR_SETSIGS);
3592 BRDDISABLE(portp->brdnr);
3595 /*****************************************************************************/
3598 * Set up the sc26198 registers for a port based on the termios port
3602 static int stl_sc26198setport(stlport_t *portp, struct termios *tiosp)
3604 unsigned char mr0, mr1, mr2, clk;
3605 unsigned char imron, imroff, iopr, ipr;
3608 kprintf("stl_sc26198setport(portp=%x,tiosp=%x): brdnr=%d portnr=%d\n",
3609 (int) portp, (int) tiosp, portp->brdnr, portp->portnr);
3621 * Set up the RX char ignore mask with those RX error types we
3624 portp->rxignoremsk = 0;
3625 if (tiosp->c_iflag & IGNPAR)
3626 portp->rxignoremsk |= (SR_RXPARITY | SR_RXFRAMING |
3628 if (tiosp->c_iflag & IGNBRK)
3629 portp->rxignoremsk |= SR_RXBREAK;
3631 portp->rxmarkmsk = SR_RXOVERRUN;
3632 if (tiosp->c_iflag & (INPCK | PARMRK))
3633 portp->rxmarkmsk |= (SR_RXPARITY | SR_RXFRAMING);
3634 if (tiosp->c_iflag & BRKINT)
3635 portp->rxmarkmsk |= SR_RXBREAK;
3638 * Go through the char size, parity and stop bits and set all the
3639 * option registers appropriately.
3641 switch (tiosp->c_cflag & CSIZE) {
3656 if (tiosp->c_cflag & CSTOPB)
3661 if (tiosp->c_cflag & PARENB) {
3662 if (tiosp->c_cflag & PARODD)
3663 mr1 |= (MR1_PARENB | MR1_PARODD);
3665 mr1 |= (MR1_PARENB | MR1_PAREVEN);
3670 mr1 |= MR1_ERRBLOCK;
3673 * Set the RX FIFO threshold at 8 chars. This gives a bit of breathing
3674 * space for hardware flow control and the like. This should be set to
3677 mr2 |= MR2_RXFIFOHALF;
3680 * Calculate the baud rate timers. For now we will just assume that
3681 * the input and output baud are the same. The sc26198 has a fixed
3682 * baud rate table, so only discrete baud rates possible.
3684 if (tiosp->c_ispeed == 0)
3685 tiosp->c_ispeed = tiosp->c_ospeed;
3686 if ((tiosp->c_ospeed < 0) || (tiosp->c_ospeed > SC26198_MAXBAUD))
3689 if (tiosp->c_ospeed > 0) {
3690 for (clk = 0; (clk < SC26198_NRBAUDS); clk++) {
3691 if (tiosp->c_ospeed <= sc26198_baudtable[clk])
3697 * Check what form of modem signaling is required and set it up.
3699 if ((tiosp->c_cflag & CLOCAL) == 0) {
3700 iopr |= IOPR_DCDCOS;
3705 * Setup sc26198 enhanced modes if we can. In particular we want to
3706 * handle as much of the flow control as possible automatically. As
3707 * well as saving a few CPU cycles it will also greatly improve flow
3708 * control reliability.
3710 if (tiosp->c_iflag & IXON) {
3711 mr0 |= MR0_SWFTX | MR0_SWFT;
3712 imron |= IR_XONXOFF;
3714 imroff |= IR_XONXOFF;
3717 if (tiosp->c_iflag & IXOFF)
3721 if (tiosp->c_cflag & CCTS_OFLOW)
3723 if (tiosp->c_cflag & CRTS_IFLOW)
3727 * All sc26198 register values calculated so go through and set
3732 kprintf("SETPORT: portnr=%d panelnr=%d brdnr=%d\n", portp->portnr,
3733 portp->panelnr, portp->brdnr);
3734 kprintf(" mr0=%x mr1=%x mr2=%x clk=%x\n", mr0, mr1, mr2, clk);
3735 kprintf(" iopr=%x imron=%x imroff=%x\n", iopr, imron, imroff);
3736 kprintf(" schr1=%x schr2=%x schr3=%x schr4=%x\n",
3737 tiosp->c_cc[VSTART], tiosp->c_cc[VSTOP],
3738 tiosp->c_cc[VSTART], tiosp->c_cc[VSTOP]);
3742 BRDENABLE(portp->brdnr, portp->pagenr);
3743 stl_sc26198setreg(portp, IMR, 0);
3744 stl_sc26198updatereg(portp, MR0, mr0);
3745 stl_sc26198updatereg(portp, MR1, mr1);
3746 stl_sc26198setreg(portp, SCCR, CR_RXERRBLOCK);
3747 stl_sc26198updatereg(portp, MR2, mr2);
3748 iopr = (stl_sc26198getreg(portp, IOPIOR) & ~IPR_CHANGEMASK) | iopr;
3749 if (tiosp->c_ospeed == 0) {
3753 stl_sc26198setreg(portp, TXCSR, clk);
3754 stl_sc26198setreg(portp, RXCSR, clk);
3756 stl_sc26198updatereg(portp, IOPIOR, iopr);
3757 stl_sc26198setreg(portp, XONCR, tiosp->c_cc[VSTART]);
3758 stl_sc26198setreg(portp, XOFFCR, tiosp->c_cc[VSTOP]);
3759 ipr = stl_sc26198getreg(portp, IPR);
3761 portp->sigs &= ~TIOCM_CD;
3763 portp->sigs |= TIOCM_CD;
3764 portp->imr = (portp->imr & ~imroff) | imron;
3765 stl_sc26198setreg(portp, IMR, portp->imr);
3766 BRDDISABLE(portp->brdnr);
3767 portp->state &= ~(ASY_RTSFLOWMODE | ASY_CTSFLOWMODE);
3768 portp->state |= ((tiosp->c_cflag & CRTS_IFLOW) ? ASY_RTSFLOWMODE : 0);
3769 portp->state |= ((tiosp->c_cflag & CCTS_OFLOW) ? ASY_CTSFLOWMODE : 0);
3770 stl_ttyoptim(portp, tiosp);
3776 /*****************************************************************************/
3779 * Set the state of the DTR and RTS signals.
3782 static void stl_sc26198setsignals(stlport_t *portp, int dtr, int rts)
3784 unsigned char iopioron, iopioroff;
3787 kprintf("stl_sc26198setsignals(portp=%x,dtr=%d,rts=%d)\n",
3788 (int) portp, dtr, rts);
3794 iopioroff |= IPR_DTR;
3796 iopioron |= IPR_DTR;
3798 iopioroff |= IPR_RTS;
3800 iopioron |= IPR_RTS;
3803 BRDENABLE(portp->brdnr, portp->pagenr);
3804 if ((rts >= 0) && (portp->tty.t_cflag & CRTS_IFLOW)) {
3806 stl_sc26198setreg(portp, MR1,
3807 (stl_sc26198getreg(portp, MR1) & ~MR1_AUTORTS));
3808 portp->stats.rxrtsoff++;
3810 stl_sc26198setreg(portp, MR1,
3811 (stl_sc26198getreg(portp, MR1) | MR1_AUTORTS));
3812 portp->stats.rxrtson++;
3815 stl_sc26198setreg(portp, IOPIOR,
3816 ((stl_sc26198getreg(portp, IOPIOR) & ~iopioroff) | iopioron));
3817 BRDDISABLE(portp->brdnr);
3821 /*****************************************************************************/
3824 * Return the state of the signals.
3827 static int stl_sc26198getsignals(stlport_t *portp)
3833 kprintf("stl_sc26198getsignals(portp=%x)\n", (int) portp);
3837 BRDENABLE(portp->brdnr, portp->pagenr);
3838 ipr = stl_sc26198getreg(portp, IPR);
3839 BRDDISABLE(portp->brdnr);
3843 sigs |= (ipr & IPR_DCD) ? 0 : TIOCM_CD;
3844 sigs |= (ipr & IPR_CTS) ? 0 : TIOCM_CTS;
3845 sigs |= (ipr & IPR_DTR) ? 0: TIOCM_DTR;
3846 sigs |= (ipr & IPR_RTS) ? 0: TIOCM_RTS;
3850 /*****************************************************************************/
3853 * Enable/Disable the Transmitter and/or Receiver.
3856 static void stl_sc26198enablerxtx(stlport_t *portp, int rx, int tx)
3861 kprintf("stl_sc26198enablerxtx(portp=%x,rx=%d,tx=%d)\n",
3862 (int) portp, rx, tx);
3865 ccr = portp->crenable;
3867 ccr &= ~CR_TXENABLE;
3871 ccr &= ~CR_RXENABLE;
3876 BRDENABLE(portp->brdnr, portp->pagenr);
3877 stl_sc26198setreg(portp, SCCR, ccr);
3878 BRDDISABLE(portp->brdnr);
3879 portp->crenable = ccr;
3883 /*****************************************************************************/
3886 * Start/stop the Transmitter and/or Receiver.
3889 static void stl_sc26198startrxtx(stlport_t *portp, int rx, int tx)
3894 kprintf("stl_sc26198startrxtx(portp=%x,rx=%d,tx=%d)\n",
3895 (int) portp, rx, tx);
3904 imr &= ~(IR_RXRDY | IR_RXBREAK | IR_RXWATCHDOG);
3906 imr |= IR_RXRDY | IR_RXBREAK | IR_RXWATCHDOG;
3909 BRDENABLE(portp->brdnr, portp->pagenr);
3910 stl_sc26198setreg(portp, IMR, imr);
3911 BRDDISABLE(portp->brdnr);
3914 portp->state |= ASY_TXBUSY;
3915 portp->tty.t_state |= TS_BUSY;
3920 /*****************************************************************************/
3923 * Disable all interrupts from this port.
3926 static void stl_sc26198disableintrs(stlport_t *portp)
3930 kprintf("stl_sc26198disableintrs(portp=%x)\n", (int) portp);
3934 BRDENABLE(portp->brdnr, portp->pagenr);
3936 stl_sc26198setreg(portp, IMR, 0);
3937 BRDDISABLE(portp->brdnr);
3941 /*****************************************************************************/
3943 static void stl_sc26198sendbreak(stlport_t *portp, long len)
3947 kprintf("stl_sc26198sendbreak(portp=%x,len=%d)\n",
3948 (int) portp, (int) len);
3952 BRDENABLE(portp->brdnr, portp->pagenr);
3954 stl_sc26198setreg(portp, SCCR, CR_TXSTARTBREAK);
3955 portp->stats.txbreaks++;
3957 stl_sc26198setreg(portp, SCCR, CR_TXSTOPBREAK);
3959 BRDDISABLE(portp->brdnr);
3963 /*****************************************************************************/
3966 * Take flow control actions...
3969 static void stl_sc26198sendflow(stlport_t *portp, int hw, int sw)
3974 kprintf("stl_sc26198sendflow(portp=%x,hw=%d,sw=%d)\n",
3975 (int) portp, hw, sw);
3982 BRDENABLE(portp->brdnr, portp->pagenr);
3985 mr0 = stl_sc26198getreg(portp, MR0);
3986 stl_sc26198setreg(portp, MR0, (mr0 & ~MR0_SWFRXTX));
3988 stl_sc26198setreg(portp, SCCR, CR_TXSENDXOFF);
3990 portp->stats.rxxoff++;
3992 stl_sc26198setreg(portp, SCCR, CR_TXSENDXON);
3994 portp->stats.rxxon++;
3996 stl_sc26198wait(portp);
3997 stl_sc26198setreg(portp, MR0, mr0);
4001 portp->state |= ASY_RTSFLOW;
4002 stl_sc26198setreg(portp, MR1,
4003 (stl_sc26198getreg(portp, MR1) & ~MR1_AUTORTS));
4004 stl_sc26198setreg(portp, IOPIOR,
4005 (stl_sc26198getreg(portp, IOPIOR) & ~IOPR_RTS));
4006 portp->stats.rxrtsoff++;
4007 } else if (hw > 0) {
4008 portp->state &= ~ASY_RTSFLOW;
4009 stl_sc26198setreg(portp, MR1,
4010 (stl_sc26198getreg(portp, MR1) | MR1_AUTORTS));
4011 stl_sc26198setreg(portp, IOPIOR,
4012 (stl_sc26198getreg(portp, IOPIOR) | IOPR_RTS));
4013 portp->stats.rxrtson++;
4016 BRDDISABLE(portp->brdnr);
4020 /*****************************************************************************/
4023 * Return the current state of data flow on this port. This is only
4024 * really interresting when determining if data has fully completed
4025 * transmission or not... The sc26198 interrupt scheme cannot
4026 * determine when all data has actually drained, so we need to
4027 * check the port statusy register to be sure.
4030 static int stl_sc26198datastate(stlport_t *portp)
4035 kprintf("stl_sc26198datastate(portp=%x)\n", (int) portp);
4040 if (portp->state & ASY_TXBUSY)
4044 BRDENABLE(portp->brdnr, portp->pagenr);
4045 sr = stl_sc26198getreg(portp, SR);
4046 BRDDISABLE(portp->brdnr);
4049 return((sr & SR_TXEMPTY) ? 0 : 1);
4052 /*****************************************************************************/
4054 static void stl_sc26198flush(stlport_t *portp, int flag)
4058 kprintf("stl_sc26198flush(portp=%x,flag=%x)\n", (int) portp, flag);
4065 BRDENABLE(portp->brdnr, portp->pagenr);
4066 if (flag & FWRITE) {
4067 stl_sc26198setreg(portp, SCCR, CR_TXRESET);
4068 stl_sc26198setreg(portp, SCCR, portp->crenable);
4071 while (stl_sc26198getreg(portp, SR) & SR_RXRDY)
4072 stl_sc26198getreg(portp, RXFIFO);
4074 BRDDISABLE(portp->brdnr);
4078 /*****************************************************************************/
4081 * If we are TX flow controlled and in IXANY mode then we may
4082 * need to unflow control here. We gotta do this because of the
4083 * automatic flow control modes of the sc26198 - which downs't
4084 * support any concept of an IXANY mode.
4087 static void stl_sc26198txunflow(stlport_t *portp)
4091 mr0 = stl_sc26198getreg(portp, MR0);
4092 stl_sc26198setreg(portp, MR0, (mr0 & ~MR0_SWFRXTX));
4093 stl_sc26198setreg(portp, SCCR, CR_HOSTXON);
4094 stl_sc26198setreg(portp, MR0, mr0);
4095 portp->state &= ~ASY_TXFLOWED;
4098 /*****************************************************************************/
4101 * Delay for a small amount of time, to give the sc26198 a chance
4102 * to process a command...
4105 static void stl_sc26198wait(stlport_t *portp)
4110 kprintf("stl_sc26198wait(portp=%x)\n", (int) portp);
4116 for (i = 0; (i < 20); i++)
4117 stl_sc26198getglobreg(portp, TSTR);
4120 /*****************************************************************************/
4123 * Transmit interrupt handler. This has gotta be fast! Handling TX
4124 * chars is pretty simple, stuff as many as possible from the TX buffer
4125 * into the sc26198 FIFO.
4128 static __inline void stl_sc26198txisr(stlport_t *portp)
4130 unsigned int ioaddr;
4136 kprintf("stl_sc26198txisr(portp=%x)\n", (int) portp);
4139 ioaddr = portp->ioaddr;
4141 head = portp->tx.head;
4142 tail = portp->tx.tail;
4143 len = (head >= tail) ? (head - tail) : (STL_TXBUFSIZE - (tail - head));
4144 if ((len == 0) || ((len < STL_TXBUFLOW) &&
4145 ((portp->state & ASY_TXLOW) == 0))) {
4146 portp->state |= ASY_TXLOW;
4151 outb((ioaddr + XP_ADDR), (MR0 | portp->uartaddr));
4152 mr0 = inb(ioaddr + XP_DATA);
4153 if ((mr0 & MR0_TXMASK) == MR0_TXEMPTY) {
4154 portp->imr &= ~IR_TXRDY;
4155 outb((ioaddr + XP_ADDR), (IMR | portp->uartaddr));
4156 outb((ioaddr + XP_DATA), portp->imr);
4157 portp->state |= ASY_TXEMPTY;
4158 portp->state &= ~ASY_TXBUSY;
4160 mr0 |= ((mr0 & ~MR0_TXMASK) | MR0_TXEMPTY);
4161 outb((ioaddr + XP_DATA), mr0);
4164 len = MIN(len, SC26198_TXFIFOSIZE);
4165 portp->stats.txtotal += len;
4166 stlen = MIN(len, (portp->tx.endbuf - tail));
4167 outb((ioaddr + XP_ADDR), GTXFIFO);
4168 outsb((ioaddr + XP_DATA), tail, stlen);
4171 if (tail >= portp->tx.endbuf)
4172 tail = portp->tx.buf;
4174 outsb((ioaddr + XP_DATA), tail, len);
4177 portp->tx.tail = tail;
4181 /*****************************************************************************/
4184 * Receive character interrupt handler. Determine if we have good chars
4185 * or bad chars and then process appropriately. Good chars are easy
4186 * just shove the lot into the RX buffer and set all status byte to 0.
4187 * If a bad RX char then process as required. This routine needs to be
4191 static __inline void stl_sc26198rxisr(stlport_t *portp, unsigned int iack)
4194 kprintf("stl_sc26198rxisr(portp=%x,iack=%x)\n", (int) portp, iack);
4197 if ((iack & IVR_TYPEMASK) == IVR_RXDATA)
4198 stl_sc26198rxgoodchars(portp);
4200 stl_sc26198rxbadchars(portp);
4203 * If we are TX flow controlled and in IXANY mode then we may need
4204 * to unflow control here. We gotta do this because of the automatic
4205 * flow control modes of the sc26198.
4207 if ((portp->state & ASY_TXFLOWED) && (portp->tty.t_iflag & IXANY))
4208 stl_sc26198txunflow(portp);
4211 /*****************************************************************************/
4214 * Process the good received characters from RX FIFO.
4217 static void stl_sc26198rxgoodchars(stlport_t *portp)
4219 unsigned int ioaddr, len, buflen, stlen;
4223 kprintf("stl_sc26198rxgoodchars(port=%x)\n", (int) portp);
4226 ioaddr = portp->ioaddr;
4229 * First up, calculate how much room there is in the RX ring queue.
4230 * We also want to keep track of the longest possible copy length,
4231 * this has to allow for the wrapping of the ring queue.
4233 head = portp->rx.head;
4234 tail = portp->rx.tail;
4236 buflen = STL_RXBUFSIZE - (head - tail) - 1;
4237 stlen = portp->rx.endbuf - head;
4239 buflen = tail - head - 1;
4244 * Check if the input buffer is near full. If so then we should take
4245 * some flow control action... It is very easy to do hardware and
4246 * software flow control from here since we have the port selected on
4249 if (buflen <= (STL_RXBUFSIZE - STL_RXBUFHIGH)) {
4250 if (((portp->state & ASY_RTSFLOW) == 0) &&
4251 (portp->state & ASY_RTSFLOWMODE)) {
4252 portp->state |= ASY_RTSFLOW;
4253 stl_sc26198setreg(portp, MR1,
4254 (stl_sc26198getreg(portp, MR1) & ~MR1_AUTORTS));
4255 stl_sc26198setreg(portp, IOPIOR,
4256 (stl_sc26198getreg(portp, IOPIOR) & ~IOPR_RTS));
4257 portp->stats.rxrtsoff++;
4262 * OK we are set, process good data... If the RX ring queue is full
4263 * just chuck the chars - don't leave them in the UART.
4265 outb((ioaddr + XP_ADDR), GIBCR);
4266 len = inb(ioaddr + XP_DATA) + 1;
4268 outb((ioaddr + XP_ADDR), GRXFIFO);
4269 insb((ioaddr + XP_DATA), &stl_unwanted[0], len);
4270 portp->stats.rxlost += len;
4271 portp->stats.rxtotal += len;
4273 len = MIN(len, buflen);
4274 portp->stats.rxtotal += len;
4275 stlen = MIN(len, stlen);
4277 outb((ioaddr + XP_ADDR), GRXFIFO);
4278 insb((ioaddr + XP_DATA), head, stlen);
4280 if (head >= portp->rx.endbuf) {
4281 head = portp->rx.buf;
4283 insb((ioaddr + XP_DATA), head, len);
4289 portp->rx.head = head;
4290 portp->state |= ASY_RXDATA;
4294 /*****************************************************************************/
4297 * Process all characters in the RX FIFO of the UART. Check all char
4298 * status bytes as well, and process as required. We need to check
4299 * all bytes in the FIFO, in case some more enter the FIFO while we
4300 * are here. To get the exact character error type we need to switch
4301 * into CHAR error mode (that is why we need to make sure we empty
4305 static void stl_sc26198rxbadchars(stlport_t *portp)
4308 unsigned int status;
4314 * First up, calculate how much room there is in the RX ring queue.
4315 * We also want to keep track of the longest possible copy length,
4316 * this has to allow for the wrapping of the ring queue.
4318 head = portp->rx.head;
4319 tail = portp->rx.tail;
4320 len = (head >= tail) ? (STL_RXBUFSIZE - (head - tail) - 1) :
4324 * To get the precise error type for each character we must switch
4325 * back into CHAR error mode.
4327 mr1 = stl_sc26198getreg(portp, MR1);
4328 stl_sc26198setreg(portp, MR1, (mr1 & ~MR1_ERRBLOCK));
4330 while ((status = stl_sc26198getreg(portp, SR)) & SR_RXRDY) {
4331 stl_sc26198setreg(portp, SCCR, CR_CLEARRXERR);
4332 ch = stl_sc26198getreg(portp, RXFIFO);
4334 if (status & SR_RXBREAK)
4335 portp->stats.rxbreaks++;
4336 if (status & SR_RXFRAMING)
4337 portp->stats.rxframing++;
4338 if (status & SR_RXPARITY)
4339 portp->stats.rxparity++;
4340 if (status & SR_RXOVERRUN)
4341 portp->stats.rxoverrun++;
4342 if ((portp->rxignoremsk & status) == 0) {
4343 if ((portp->tty.t_state & TS_CAN_BYPASS_L_RINT) &&
4344 ((status & SR_RXFRAMING) ||
4345 ((status & SR_RXPARITY) &&
4346 (portp->tty.t_iflag & INPCK))))
4348 if ((portp->rxmarkmsk & status) == 0)
4351 *(head + STL_RXBUFSIZE) = status;
4353 if (head >= portp->rx.endbuf)
4354 head = portp->rx.buf;
4361 * To get correct interrupt class we must switch back into BLOCK
4364 stl_sc26198setreg(portp, MR1, mr1);
4366 portp->rx.head = head;
4367 portp->state |= ASY_RXDATA;
4371 /*****************************************************************************/
4374 * Other interrupt handler. This includes modem signals, flow
4375 * control actions, etc.
4378 static void stl_sc26198otherisr(stlport_t *portp, unsigned int iack)
4380 unsigned char cir, ipr, xisr;
4383 kprintf("stl_sc26198otherisr(portp=%x,iack=%x)\n", (int) portp, iack);
4386 cir = stl_sc26198getglobreg(portp, CIR);
4388 switch (cir & CIR_SUBTYPEMASK) {
4390 ipr = stl_sc26198getreg(portp, IPR);
4391 if (ipr & IPR_DCDCHANGE) {
4392 portp->state |= ASY_DCDCHANGE;
4393 portp->stats.modem++;
4397 case CIR_SUBXONXOFF:
4398 xisr = stl_sc26198getreg(portp, XISR);
4399 if (xisr & XISR_RXXONGOT) {
4400 portp->state |= ASY_TXFLOWED;
4401 portp->stats.txxoff++;
4403 if (xisr & XISR_RXXOFFGOT) {
4404 portp->state &= ~ASY_TXFLOWED;
4405 portp->stats.txxon++;
4409 stl_sc26198setreg(portp, SCCR, CR_BREAKRESET);
4410 stl_sc26198rxbadchars(portp);
4417 /*****************************************************************************/
4420 * Interrupt service routine for sc26198 panels.
4423 static void stl_sc26198intr(stlpanel_t *panelp, unsigned int iobase)
4429 * Work around bug in sc26198 chip... Cannot have A6 address
4430 * line of UART high, else iack will be returned as 0.
4432 outb((iobase + 1), 0);
4434 iack = inb(iobase + XP_IACK);
4436 kprintf("stl_sc26198intr(panelp=%p,iobase=%x): iack=%x\n", panelp, iobase, iack);
4438 portp = panelp->ports[(iack & IVR_CHANMASK) + ((iobase & 0x4) << 1)];
4440 if (iack & IVR_RXDATA)
4441 stl_sc26198rxisr(portp, iack);
4442 else if (iack & IVR_TXDATA)
4443 stl_sc26198txisr(portp);
4445 stl_sc26198otherisr(portp, iack);
4448 /*****************************************************************************/