1 /*****************************************************************************/
4 * istallion.c -- stallion intelligent multiport serial driver.
6 * Copyright (c) 1994-1998 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/istallion.c,v 1.36.2.2 2001/08/30 12:29:57 murray Exp $
39 /*****************************************************************************/
41 #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>
55 #include <sys/thread2.h>
56 #include <machine/clock.h>
59 #include <bus/isa/isa_device.h>
60 #include <machine/cdk.h>
61 #include <machine/comstats.h>
65 /*****************************************************************************/
68 * Define the version level of the kernel - so we can compile in the
69 * appropriate bits of code. By default this will compile for a 2.1
80 /*****************************************************************************/
83 * Define different board types. Not all of the following board types
84 * are supported by this driver. But I will use the standard "assigned"
85 * board numbers. Currently supported boards are abbreviated as:
86 * ECP = EasyConnection 8/64, ONB = ONboard, BBY = Brumby and
90 #define BRD_STALLION 1
92 #define BRD_ONBOARD2 3
95 #define BRD_BRUMBY16 6
96 #define BRD_ONBOARDE 7
97 #define BRD_ONBOARD32 9
98 #define BRD_ONBOARD2_32 10
99 #define BRD_ONBOARDRS 11
100 #define BRD_EASYIO 20
105 #define BRD_ECHPCI 26
106 #define BRD_ECH64PCI 27
107 #define BRD_EASYIOPCI 28
109 #define BRD_BRUMBY BRD_BRUMBY4
111 /*****************************************************************************/
114 * Define important driver limitations.
116 #define STL_MAXBRDS 8
117 #define STL_MAXPANELS 4
118 #define STL_PORTSPERPANEL 16
119 #define STL_PORTSPERBRD 64
121 #define STL_MAXCHANS STL_PORTSPERBRD
125 * Define the important minor number break down bits. These have been
126 * chosen to be "compatible" with the standard sio driver minor numbers.
127 * Extra high bits are used to distinguish between boards and also for
128 * really high port numbers (> 32).
130 #define STL_CALLOUTDEV 0x80
131 #define STL_CTRLLOCK 0x40
132 #define STL_CTRLINIT 0x20
133 #define STL_CTRLDEV (STL_CTRLLOCK | STL_CTRLINIT)
135 #define STL_MEMDEV 0x07000000
137 #define STL_DEFSPEED TTYDEF_SPEED
138 #define STL_DEFCFLAG (CS8 | CREAD | HUPCL)
140 /*****************************************************************************/
143 * Define our local driver identity first. Set up stuff to deal with
144 * all the local structures required by a serial tty driver.
146 static char stli_drvname[] = "stli";
147 static char const stli_drvtitle[] = "Stallion Multiport Serial Driver";
148 static char const stli_drvversion[] = "2.0.0";
150 static int stli_nrbrds = 0;
151 static int stli_doingtimeout = 0;
152 static struct callout stli_poll_ch;
155 * Define some macros to use to class define boards.
161 static unsigned char stli_stliprobed[STL_MAXBRDS];
163 /*****************************************************************************/
166 * Define a set of structures to hold all the board/panel/port info
167 * for our ports. These will be dynamically allocated as required at
168 * driver initialization time.
172 * Port and board structures to hold status info about each object.
173 * The board structure contains pointers to structures for each port
174 * connected to it. Panels are not distinguished here, since
175 * communication with the slave board will always be on a per port
195 struct termios initintios;
196 struct termios initouttios;
197 struct termios lockintios;
198 struct termios lockouttios;
199 struct timeval timestamp;
202 unsigned long rxlost;
203 unsigned long rxoffset;
204 unsigned long txoffset;
208 unsigned char reqidx;
209 unsigned char reqbit;
210 unsigned char portidx;
211 unsigned char portbit;
212 struct callout dtr_ch;
216 * Use a structure of function pointers to do board level operations.
217 * These include, enable/disable, paging shared memory, interrupting, etc.
219 typedef struct stlibrd {
236 void (*init)(struct stlibrd *brdp);
237 void (*enable)(struct stlibrd *brdp);
238 void (*reenable)(struct stlibrd *brdp);
239 void (*disable)(struct stlibrd *brdp);
240 void (*intr)(struct stlibrd *brdp);
241 void (*reset)(struct stlibrd *brdp);
242 char *(*getmemptr)(struct stlibrd *brdp,
243 unsigned long offset, int line);
244 int panels[STL_MAXPANELS];
245 int panelids[STL_MAXPANELS];
246 stliport_t *ports[STL_PORTSPERBRD];
249 static stlibrd_t *stli_brds[STL_MAXBRDS];
251 static int stli_shared = 0;
254 * Keep a local char buffer for processing chars into the LD. We
255 * do this to avoid copying from the boards shared memory one char
258 static int stli_rxtmplen;
259 static stliport_t *stli_rxtmpport;
260 static char stli_rxtmpbuf[TTYHOG];
263 * Define global stats structures. Not used often, and can be re-used
264 * for each stats call.
266 static comstats_t stli_comstats;
267 static combrd_t stli_brdstats;
268 static asystats_t stli_cdkstats;
271 * Per board state flags. Used with the state field of the board struct.
272 * Not really much here... All we need to do is keep track of whether
273 * the board has been detected, and whether it is actully running a slave
276 #define BST_FOUND 0x1
277 #define BST_STARTED 0x2
280 * Define the set of port state flags. These are marked for internal
281 * state purposes only, usually to do with the state of communications
282 * with the slave. They need to be updated atomically.
284 #define ST_INITIALIZING 0x1
285 #define ST_INITIALIZED 0x2
286 #define ST_OPENING 0x4
287 #define ST_CLOSING 0x8
288 #define ST_CMDING 0x10
289 #define ST_RXING 0x20
290 #define ST_TXBUSY 0x40
291 #define ST_DOFLUSHRX 0x80
292 #define ST_DOFLUSHTX 0x100
293 #define ST_DOSIGS 0x200
294 #define ST_GETSIGS 0x400
295 #define ST_DTRWAIT 0x800
298 * Define an array of board names as printable strings. Handy for
299 * referencing boards when printing trace and stuff.
301 static char *stli_brdnames[] = {
331 /*****************************************************************************/
334 * Hardware configuration info for ECP boards. These defines apply
335 * to the directly accessable io ports of the ECP.
338 #define ECP_MEMSIZE (128 * 1024)
339 #define ECP_ATPAGESIZE (4 * 1024)
340 #define ECP_EIPAGESIZE (64 * 1024)
343 * Important defines for the ISA class of ECP board.
346 #define ECP_ATCONFR 1
347 #define ECP_ATMEMAR 2
348 #define ECP_ATMEMPR 3
349 #define ECP_ATSTOP 0x1
350 #define ECP_ATINTENAB 0x10
351 #define ECP_ATENABLE 0x20
352 #define ECP_ATDISABLE 0x00
353 #define ECP_ATADDRMASK 0x3f000
354 #define ECP_ATADDRSHFT 12
357 * Important defines for the Micro-channel class of ECP board.
358 * (It has a lot in common with the ISA boards.)
361 #define ECP_MCCONFR 1
362 #define ECP_MCSTOP 0x20
363 #define ECP_MCENABLE 0x80
364 #define ECP_MCDISABLE 0x00
367 * Hardware configuration info for ONboard and Brumby boards. These
368 * defines apply to the directly accessable io ports of these boards.
370 #define ONB_IOSIZE 16
371 #define ONB_MEMSIZE (64 * 1024)
372 #define ONB_ATPAGESIZE (64 * 1024)
373 #define ONB_MCPAGESIZE (64 * 1024)
374 #define ONB_EIMEMSIZE (128 * 1024)
375 #define ONB_EIPAGESIZE (64 * 1024)
378 * Important defines for the ISA class of ONboard board.
381 #define ONB_ATMEMAR 1
382 #define ONB_ATCONFR 2
383 #define ONB_ATSTOP 0x4
384 #define ONB_ATENABLE 0x01
385 #define ONB_ATDISABLE 0x00
386 #define ONB_ATADDRMASK 0xff0000
387 #define ONB_ATADDRSHFT 16
389 #define ONB_HIMEMENAB 0x02
392 * Important defines for the Brumby boards. They are pretty simple,
393 * there is not much that is programmably configurable.
395 #define BBY_IOSIZE 16
396 #define BBY_MEMSIZE (64 * 1024)
397 #define BBY_PAGESIZE (16 * 1024)
400 #define BBY_ATCONFR 1
401 #define BBY_ATSTOP 0x4
404 * Important defines for the Stallion boards. They are pretty simple,
405 * there is not much that is programmably configurable.
407 #define STAL_IOSIZE 16
408 #define STAL_MEMSIZE (64 * 1024)
409 #define STAL_PAGESIZE (64 * 1024)
412 * Define the set of status register values for EasyConnection panels.
413 * The signature will return with the status value for each panel. From
414 * this we can determine what is attached to the board - before we have
415 * actually down loaded any code to it.
417 #define ECH_PNLSTATUS 2
418 #define ECH_PNL16PORT 0x20
419 #define ECH_PNLIDMASK 0x07
420 #define ECH_PNLXPID 0x40
421 #define ECH_PNLINTRPEND 0x80
424 * Define some macros to do things to the board. Even those these boards
425 * are somewhat related there is often significantly different ways of
426 * doing some operation on it (like enable, paging, reset, etc). So each
427 * board class has a set of functions which do the commonly required
428 * operations. The macros below basically just call these functions,
429 * generally checking for a NULL function - which means that the board
430 * needs nothing done to it to achieve this operation!
432 #define EBRDINIT(brdp) \
433 if (brdp->init != NULL) \
436 #define EBRDENABLE(brdp) \
437 if (brdp->enable != NULL) \
438 (* brdp->enable)(brdp);
440 #define EBRDDISABLE(brdp) \
441 if (brdp->disable != NULL) \
442 (* brdp->disable)(brdp);
444 #define EBRDINTR(brdp) \
445 if (brdp->intr != NULL) \
446 (* brdp->intr)(brdp);
448 #define EBRDRESET(brdp) \
449 if (brdp->reset != NULL) \
450 (* brdp->reset)(brdp);
452 #define EBRDGETMEMPTR(brdp,offset) \
453 (* brdp->getmemptr)(brdp, offset, __LINE__)
456 * Define the maximal baud rate.
458 #define STL_MAXBAUD 230400
460 /*****************************************************************************/
463 * Define macros to extract a brd and port number from a minor number.
464 * This uses the extended minor number range in the upper 2 bytes of
465 * the device number. This gives us plenty of minor numbers to play
468 #define MKDEV2BRD(m) ((minor(m) & 0x00700000) >> 20)
469 #define MKDEV2PORT(m) ((minor(m) & 0x1f) | ((minor(m) & 0x00010000) >> 11))
472 * Define some handy local macros...
475 #define MIN(a,b) (((a) <= (b)) ? (a) : (b))
478 /*****************************************************************************/
481 * Declare all those functions in this driver! First up is the set of
482 * externally visible functions.
484 static int stliprobe(struct isa_device *idp);
485 static int stliattach(struct isa_device *idp);
487 STATIC d_open_t stliopen;
488 STATIC d_close_t stliclose;
489 STATIC d_read_t stliread;
490 STATIC d_write_t stliwrite;
491 STATIC d_ioctl_t stliioctl;
494 * Internal function prototypes.
496 static stliport_t *stli_dev2port(cdev_t dev);
497 static int stli_isaprobe(struct isa_device *idp);
498 static int stli_brdinit(stlibrd_t *brdp);
499 static int stli_brdattach(stlibrd_t *brdp);
500 static int stli_initecp(stlibrd_t *brdp);
501 static int stli_initonb(stlibrd_t *brdp);
502 static int stli_initports(stlibrd_t *brdp);
503 static int stli_startbrd(stlibrd_t *brdp);
504 static void stli_poll(void *arg);
505 static __inline void stli_brdpoll(stlibrd_t *brdp, volatile cdkhdr_t *hdrp);
506 static __inline int stli_hostcmd(stlibrd_t *brdp, stliport_t *portp);
507 static __inline void stli_dodelaycmd(stliport_t *portp,
508 volatile cdkctrl_t *cp);
509 static void stli_mkasysigs(asysigs_t *sp, int dtr, int rts);
510 static long stli_mktiocm(unsigned long sigvalue);
511 static void stli_rxprocess(stlibrd_t *brdp, stliport_t *portp);
512 static void stli_flush(stliport_t *portp, int flag);
513 static void stli_start(struct tty *tp);
514 static void stli_stop(struct tty *tp, int rw);
515 static int stli_param(struct tty *tp, struct termios *tiosp);
516 static void stli_ttyoptim(stliport_t *portp, struct termios *tiosp);
517 static void stli_dtrwakeup(void *arg);
518 static int stli_initopen(stliport_t *portp);
519 static int stli_shutdownclose(stliport_t *portp);
520 static int stli_rawopen(stlibrd_t *brdp, stliport_t *portp,
521 unsigned long arg, int wait);
522 static int stli_rawclose(stlibrd_t *brdp, stliport_t *portp,
523 unsigned long arg, int wait);
524 static int stli_cmdwait(stlibrd_t *brdp, stliport_t *portp,
525 unsigned long cmd, void *arg, int size, int copyback);
526 static void stli_sendcmd(stlibrd_t *brdp, stliport_t *portp,
527 unsigned long cmd, void *arg, int size, int copyback);
528 static void stli_mkasyport(stliport_t *portp, asyport_t *pp,
529 struct termios *tiosp);
530 static int stli_memrw(cdev_t dev, struct uio *uiop, int flag);
531 static int stli_memioctl(cdev_t dev, unsigned long cmd, caddr_t data,
533 static int stli_getbrdstats(caddr_t data);
534 static int stli_getportstats(stliport_t *portp, caddr_t data);
535 static int stli_clrportstats(stliport_t *portp, caddr_t data);
536 static stliport_t *stli_getport(int brdnr, int panelnr, int portnr);
538 static void stli_ecpinit(stlibrd_t *brdp);
539 static void stli_ecpenable(stlibrd_t *brdp);
540 static void stli_ecpdisable(stlibrd_t *brdp);
541 static void stli_ecpreset(stlibrd_t *brdp);
542 static char *stli_ecpgetmemptr(stlibrd_t *brdp, unsigned long offset,
544 static void stli_ecpintr(stlibrd_t *brdp);
545 static void stli_onbinit(stlibrd_t *brdp);
546 static void stli_onbenable(stlibrd_t *brdp);
547 static void stli_onbdisable(stlibrd_t *brdp);
548 static void stli_onbreset(stlibrd_t *brdp);
549 static char *stli_onbgetmemptr(stlibrd_t *brdp, unsigned long offset,
551 static void stli_bbyinit(stlibrd_t *brdp);
552 static void stli_bbyreset(stlibrd_t *brdp);
553 static char *stli_bbygetmemptr(stlibrd_t *brdp, unsigned long offset,
555 static void stli_stalinit(stlibrd_t *brdp);
556 static void stli_stalreset(stlibrd_t *brdp);
557 static char *stli_stalgetmemptr(stlibrd_t *brdp, unsigned long offset,
560 /*****************************************************************************/
563 * Declare the driver isa structure.
565 struct isa_driver stlidriver = {
566 stliprobe, stliattach, stli_drvname
569 /*****************************************************************************/
574 * FreeBSD-2.2+ kernel linkage.
577 static struct dev_ops stli_ops = {
578 { stli_drvname, 0, D_TTY },
580 .d_close = stliclose,
582 .d_write = stliwrite,
583 .d_ioctl = stliioctl,
584 .d_kqfilter = ttykqfilter,
585 .d_revoke = ttyrevoke
590 /*****************************************************************************/
592 static stlibrd_t *stli_brdalloc(void)
596 brdp = kmalloc(sizeof(stlibrd_t), M_TTYS, M_WAITOK | M_ZERO);
600 /*****************************************************************************/
603 * Find an available internal board number (unit number). The problem
604 * is that the same unit numbers can be assigned to different class
605 * boards - but we only want to maintain one setup board structures.
608 static int stli_findfreeunit(void)
612 for (i = 0; (i < STL_MAXBRDS); i++)
613 if (stli_brds[i] == NULL)
615 return((i >= STL_MAXBRDS) ? -1 : i);
618 /*****************************************************************************/
621 * Try and determine the ISA board type. Hopefully the board
622 * configuration entry will help us out, using the flags field.
623 * If not, we may ne be able to determine the board type...
626 static int stli_isaprobe(struct isa_device *idp)
631 kprintf("stli_isaprobe(idp=%x): unit=%d iobase=%x flags=%x\n",
632 (int) idp, idp->id_unit, idp->id_iobase, idp->id_flags);
635 switch (idp->id_flags) {
643 btype = idp->id_flags;
652 /*****************************************************************************/
655 * Probe for a board. This is involved, since we need to enable the
656 * shared memory region to see if the board is really there or not...
659 static int stliprobe(struct isa_device *idp)
665 kprintf("stliprobe(idp=%x): unit=%d iobase=%x flags=%x\n", (int) idp,
666 idp->id_unit, idp->id_iobase, idp->id_flags);
669 if (idp->id_unit > STL_MAXBRDS)
673 * First up determine what bus type of board we might be dealing
677 if ((idp->id_iobase > 0) && (idp->id_iobase < 0x400))
680 if ((bclass == 0) || (idp->id_iobase == 0))
684 * Based on the board bus type, try and figure out what it might be...
687 if (bclass & BRD_ISA)
688 btype = stli_isaprobe(idp);
693 * Go ahead and try probing for the shared memory region now.
694 * This way we will really know if the board is here...
696 if ((brdp = stli_brdalloc()) == NULL)
699 brdp->brdnr = stli_findfreeunit();
700 brdp->brdtype = btype;
701 brdp->unitid = idp->id_unit;
702 brdp->iobase = idp->id_iobase;
703 brdp->vaddr = idp->id_maddr;
704 brdp->paddr = vtophys(idp->id_maddr);
707 kprintf("%s(%d): btype=%x unit=%d brd=%d io=%x mem=%lx(%p)\n",
708 __file__, __LINE__, btype, brdp->unitid, brdp->brdnr,
709 brdp->iobase, brdp->paddr, brdp->vaddr);
712 stli_stliprobed[idp->id_unit] = brdp->brdnr;
714 if ((brdp->state & BST_FOUND) == 0) {
715 stli_brds[brdp->brdnr] = NULL;
722 /*****************************************************************************/
725 * Allocate resources for and initialize a board.
728 static int stliattach(struct isa_device *idp)
734 kprintf("stliattach(idp=%p): unit=%d iobase=%x\n", (void *) idp,
735 idp->id_unit, idp->id_iobase);
738 brdnr = stli_stliprobed[idp->id_unit];
739 brdp = stli_brds[brdnr];
742 if (brdp->state & BST_FOUND)
743 stli_brdattach(brdp);
748 /*****************************************************************************/
750 STATIC int stliopen(struct dev_open_args *ap)
752 cdev_t dev = ap->a_head.a_dev;
758 kprintf("stliopen(dev=%x,flag=%x,mode=%x,p=%x)\n", (int) dev, flag,
763 * Firstly check if the supplied device number is a valid device.
765 if (minor(dev) & STL_MEMDEV)
768 portp = stli_dev2port(dev);
771 if (minor(dev) & STL_CTRLDEV)
775 callout = minor(dev) & STL_CALLOUTDEV;
782 * Wait here for the DTR drop timeout period to expire.
784 while (portp->state & ST_DTRWAIT) {
785 error = tsleep(&portp->dtrwait, PCATCH, "stlidtr", 0);
791 * If the port is in its raw hardware initialization phase, then
792 * hold up here 'till it is done.
794 while (portp->state & (ST_INITIALIZING | ST_CLOSING)) {
795 error = tsleep(&portp->state, PCATCH, "stliraw", 0);
801 * We have a valid device, so now we check if it is already open.
802 * If not then initialize the port hardware and set up the tty
803 * struct as required.
805 if ((tp->t_state & TS_ISOPEN) == 0) {
806 tp->t_oproc = stli_start;
807 tp->t_param = stli_param;
808 tp->t_stop = stli_stop;
810 tp->t_termios = callout ? portp->initouttios :
812 stli_initopen(portp);
813 wakeup(&portp->state);
815 if ((portp->sigs & TIOCM_CD) || callout)
816 (*linesw[tp->t_line].l_modem)(tp, 1);
819 if (portp->callout == 0) {
824 if (portp->callout != 0) {
825 if (ap->a_oflags & O_NONBLOCK) {
829 error = tsleep(&portp->callout,
830 PCATCH, "stlicall", 0);
833 goto stliopen_restart;
836 if ((tp->t_state & TS_XCLUDE) &&
837 priv_check_cred(ap->a_cred, PRIV_ROOT, 0)) {
844 * If this port is not the callout device and we do not have carrier
845 * then we need to sleep, waiting for it to be asserted.
847 if (((tp->t_state & TS_CARR_ON) == 0) && !callout &&
848 ((tp->t_cflag & CLOCAL) == 0) &&
849 ((ap->a_oflags & O_NONBLOCK) == 0)) {
851 error = tsleep(TSA_CARR_ON(tp), PCATCH, "stlidcd",0);
855 goto stliopen_restart;
859 * Open the line discipline.
861 error = (*linesw[tp->t_line].l_open)(dev, tp);
862 stli_ttyoptim(portp, &tp->t_termios);
863 if ((tp->t_state & TS_ISOPEN) && callout)
867 * If for any reason we get to here and the port is not actually
868 * open then close of the physical hardware - no point leaving it
869 * active when the open failed...
873 if (((tp->t_state & TS_ISOPEN) == 0) && (portp->waitopens == 0))
874 stli_shutdownclose(portp);
879 /*****************************************************************************/
881 STATIC int stliclose(struct dev_close_args *ap)
883 cdev_t dev = ap->a_head.a_dev;
888 kprintf("stliclose(dev=%s,flag=%x,mode=%x,p=%p)\n",
889 devtoname(dev), flag, mode, (void *) p);
892 if (minor(dev) & STL_MEMDEV)
894 if (minor(dev) & STL_CTRLDEV)
897 portp = stli_dev2port(dev);
903 (*linesw[tp->t_line].l_close)(tp, ap->a_fflag);
904 stli_ttyoptim(portp, &tp->t_termios);
905 stli_shutdownclose(portp);
912 STATIC int stliread(struct dev_read_args *ap)
914 cdev_t dev = ap->a_head.a_dev;
918 kprintf("stliread(dev=%s,uiop=%p,flag=%x)\n", devtoname(dev),
922 if (minor(dev) & STL_MEMDEV)
923 return(stli_memrw(dev, ap->a_uio, ap->a_ioflag));
924 if (minor(dev) & STL_CTRLDEV)
927 portp = stli_dev2port(dev);
933 /*****************************************************************************/
937 STATIC void stli_stop(struct tty *tp, int rw)
940 kprintf("stli_stop(tp=%x,rw=%x)\n", (int) tp, rw);
943 stli_flush((stliport_t *) tp, rw);
948 STATIC int stlistop(struct tty *tp, int rw)
951 kprintf("stlistop(tp=%x,rw=%x)\n", (int) tp, rw);
954 stli_flush((stliport_t *) tp, rw);
960 /*****************************************************************************/
962 STATIC int stliwrite(struct dev_write_args *ap)
964 cdev_t dev = ap->a_head.a_dev;
968 kprintf("stliwrite(dev=%s,uiop=%p,flag=%x)\n", devtoname(dev),
972 if (minor(dev) & STL_MEMDEV)
973 return(stli_memrw(dev, ap->a_uio, ap->a_ioflag));
974 if (minor(dev) & STL_CTRLDEV)
976 portp = stli_dev2port(dev);
982 /*****************************************************************************/
984 STATIC int stliioctl(struct dev_ioctl_args *ap)
986 cdev_t dev = ap->a_head.a_dev;
987 u_long cmd = ap->a_cmd;
988 caddr_t data = ap->a_data;
989 struct termios *newtios, *localtios;
997 kprintf("stliioctl(dev=%s,cmd=%lx,data=%p,flag=%x,p=%p)\n",
998 devtoname(dev), cmd, (void *) data, ap->a_fflag, (void *) p);
1001 if (minor(dev) & STL_MEMDEV)
1002 return(stli_memioctl(dev, cmd, data, ap->a_fflag));
1004 portp = stli_dev2port(dev);
1007 if ((brdp = stli_brds[portp->brdnr]) == NULL)
1013 * First up handle ioctls on the control devices.
1015 if (minor(dev) & STL_CTRLDEV) {
1016 if ((minor(dev) & STL_CTRLDEV) == STL_CTRLINIT)
1017 localtios = (minor(dev) & STL_CALLOUTDEV) ?
1018 &portp->initouttios : &portp->initintios;
1019 else if ((minor(dev) & STL_CTRLDEV) == STL_CTRLLOCK)
1020 localtios = (minor(dev) & STL_CALLOUTDEV) ?
1021 &portp->lockouttios : &portp->lockintios;
1027 if ((error = priv_check_cred(ap->a_cred, PRIV_ROOT, 0)) == 0)
1028 *localtios = *((struct termios *) data);
1031 *((struct termios *) data) = *localtios;
1034 *((int *) data) = TTYDISC;
1037 bzero(data, sizeof(struct winsize));
1047 * Deal with 4.3 compatibility issues if we have too...
1049 #if defined(COMPAT_43) || defined(COMPAT_SUNOS)
1051 struct termios tios;
1052 unsigned long oldcmd;
1054 tios = tp->t_termios;
1056 if ((error = ttsetcompat(tp, &cmd, data, &tios)))
1059 data = (caddr_t) &tios;
1064 * Carry out some pre-cmd processing work first...
1065 * Hmmm, not so sure we want this, disable for now...
1067 if ((cmd == TIOCSETA) || (cmd == TIOCSETAW) || (cmd == TIOCSETAF)) {
1068 newtios = (struct termios *) data;
1069 localtios = (minor(dev) & STL_CALLOUTDEV) ? &portp->lockouttios :
1072 newtios->c_iflag = (tp->t_iflag & localtios->c_iflag) |
1073 (newtios->c_iflag & ~localtios->c_iflag);
1074 newtios->c_oflag = (tp->t_oflag & localtios->c_oflag) |
1075 (newtios->c_oflag & ~localtios->c_oflag);
1076 newtios->c_cflag = (tp->t_cflag & localtios->c_cflag) |
1077 (newtios->c_cflag & ~localtios->c_cflag);
1078 newtios->c_lflag = (tp->t_lflag & localtios->c_lflag) |
1079 (newtios->c_lflag & ~localtios->c_lflag);
1080 for (i = 0; (i < NCCS); i++) {
1081 if (localtios->c_cc[i] != 0)
1082 newtios->c_cc[i] = tp->t_cc[i];
1084 if (localtios->c_ispeed != 0)
1085 newtios->c_ispeed = tp->t_ispeed;
1086 if (localtios->c_ospeed != 0)
1087 newtios->c_ospeed = tp->t_ospeed;
1091 * Call the line discipline and the common command processing to
1092 * process this command (if they can).
1094 error = (*linesw[tp->t_line].l_ioctl)(tp, cmd, data,
1095 ap->a_fflag, ap->a_cred);
1096 if (error != ENOIOCTL)
1100 error = ttioctl(tp, cmd, data, ap->a_fflag);
1101 stli_ttyoptim(portp, &tp->t_termios);
1102 if (error != ENOIOCTL) {
1110 * Process local commands here. These are all commands that only we
1111 * can take care of (they all rely on actually doing something special
1112 * to the actual hardware).
1117 error = stli_cmdwait(brdp, portp, A_BREAK, &arg,
1118 sizeof(unsigned long), 0);
1122 error = stli_cmdwait(brdp, portp, A_BREAK, &arg,
1123 sizeof(unsigned long), 0);
1126 stli_mkasysigs(&portp->asig, 1, -1);
1127 error = stli_cmdwait(brdp, portp, A_SETSIGNALS, &portp->asig,
1128 sizeof(asysigs_t), 0);
1131 stli_mkasysigs(&portp->asig, 0, -1);
1132 error = stli_cmdwait(brdp, portp, A_SETSIGNALS, &portp->asig,
1133 sizeof(asysigs_t), 0);
1136 i = *((int *) data);
1137 stli_mkasysigs(&portp->asig, ((i & TIOCM_DTR) ? 1 : 0),
1138 ((i & TIOCM_RTS) ? 1 : 0));
1139 error = stli_cmdwait(brdp, portp, A_SETSIGNALS, &portp->asig,
1140 sizeof(asysigs_t), 0);
1143 i = *((int *) data);
1144 stli_mkasysigs(&portp->asig, ((i & TIOCM_DTR) ? 1 : -1),
1145 ((i & TIOCM_RTS) ? 1 : -1));
1146 error = stli_cmdwait(brdp, portp, A_SETSIGNALS, &portp->asig,
1147 sizeof(asysigs_t), 0);
1150 i = *((int *) data);
1151 stli_mkasysigs(&portp->asig, ((i & TIOCM_DTR) ? 0 : -1),
1152 ((i & TIOCM_RTS) ? 0 : -1));
1153 error = stli_cmdwait(brdp, portp, A_SETSIGNALS, &portp->asig,
1154 sizeof(asysigs_t), 0);
1157 if ((error = stli_cmdwait(brdp, portp, A_GETSIGNALS,
1158 &portp->asig, sizeof(asysigs_t), 1)) < 0)
1160 portp->sigs = stli_mktiocm(portp->asig.sigvalue);
1161 *((int *) data) = (portp->sigs | TIOCM_LE);
1164 if ((error = priv_check_cred(ap->a_cred, PRIV_ROOT, 0)) == 0)
1165 portp->dtrwait = *((int *) data) * hz / 100;
1168 *((int *) data) = portp->dtrwait * 100 / hz;
1171 portp->dotimestamp = 1;
1172 *((struct timeval *) data) = portp->timestamp;
1175 *((unsigned long *) data) = portp->pflag;
1178 portp->pflag = *((unsigned long *) data);
1179 stli_param(&portp->tty, &portp->tty.t_termios);
1190 /*****************************************************************************/
1193 * Convert the specified minor device number into a port struct
1194 * pointer. Return NULL if the device number is not a valid port.
1197 STATIC stliport_t *stli_dev2port(cdev_t dev)
1201 brdp = stli_brds[MKDEV2BRD(dev)];
1204 if ((brdp->state & BST_STARTED) == 0)
1206 return(brdp->ports[MKDEV2PORT(dev)]);
1209 /*****************************************************************************/
1212 * Carry out first open operations on a port. This involves a number of
1213 * commands to be sent to the slave. We need to open the port, set the
1214 * notification events, set the initial port settings, get and set the
1215 * initial signal values. We sleep and wait in between each one. But
1216 * this still all happens pretty quickly.
1219 static int stli_initopen(stliport_t *portp)
1227 kprintf("stli_initopen(portp=%x)\n", (int) portp);
1230 if ((brdp = stli_brds[portp->brdnr]) == NULL)
1232 if (portp->state & ST_INITIALIZED)
1234 portp->state |= ST_INITIALIZED;
1236 if ((rc = stli_rawopen(brdp, portp, 0, 1)) < 0)
1239 bzero(&nt, sizeof(asynotify_t));
1240 nt.data = (DT_TXLOW | DT_TXEMPTY | DT_RXBUSY | DT_RXBREAK);
1242 if ((rc = stli_cmdwait(brdp, portp, A_SETNOTIFY, &nt,
1243 sizeof(asynotify_t), 0)) < 0)
1246 stli_mkasyport(portp, &aport, &portp->tty.t_termios);
1247 if ((rc = stli_cmdwait(brdp, portp, A_SETPORT, &aport,
1248 sizeof(asyport_t), 0)) < 0)
1251 portp->state |= ST_GETSIGS;
1252 if ((rc = stli_cmdwait(brdp, portp, A_GETSIGNALS, &portp->asig,
1253 sizeof(asysigs_t), 1)) < 0)
1255 if (portp->state & ST_GETSIGS) {
1256 portp->sigs = stli_mktiocm(portp->asig.sigvalue);
1257 portp->state &= ~ST_GETSIGS;
1260 stli_mkasysigs(&portp->asig, 1, 1);
1261 if ((rc = stli_cmdwait(brdp, portp, A_SETSIGNALS, &portp->asig,
1262 sizeof(asysigs_t), 0)) < 0)
1268 /*****************************************************************************/
1271 * Shutdown the hardware of a port.
1274 static int stli_shutdownclose(stliport_t *portp)
1280 kprintf("stli_shutdownclose(portp=%p): brdnr=%d panelnr=%d portnr=%d\n",
1281 (void *) portp, portp->brdnr, portp->panelnr, portp->portnr);
1284 if ((brdp = stli_brds[portp->brdnr]) == NULL)
1288 stli_rawclose(brdp, portp, 0, 0);
1289 stli_flush(portp, (FWRITE | FREAD));
1290 if (tp->t_cflag & HUPCL) {
1292 stli_mkasysigs(&portp->asig, 0, 0);
1293 if (portp->state & ST_CMDING) {
1294 portp->state |= ST_DOSIGS;
1296 stli_sendcmd(brdp, portp, A_SETSIGNALS,
1297 &portp->asig, sizeof(asysigs_t), 0);
1300 if (portp->dtrwait != 0) {
1301 portp->state |= ST_DTRWAIT;
1302 callout_reset(&portp->dtr_ch, portp->dtrwait,
1303 stli_dtrwakeup, portp);
1307 portp->state &= ~ST_INITIALIZED;
1308 wakeup(&portp->callout);
1309 wakeup(TSA_CARR_ON(tp));
1313 /*****************************************************************************/
1316 * Clear the DTR waiting flag, and wake up any sleepers waiting for
1317 * DTR wait period to finish.
1320 static void stli_dtrwakeup(void *arg)
1324 portp = (stliport_t *) arg;
1325 portp->state &= ~ST_DTRWAIT;
1326 wakeup(&portp->dtrwait);
1329 /*****************************************************************************/
1332 * Send an open message to the slave. This will sleep waiting for the
1333 * acknowledgement, so must have user context. We need to co-ordinate
1334 * with close events here, since we don't want open and close events
1338 static int stli_rawopen(stlibrd_t *brdp, stliport_t *portp, unsigned long arg, int wait)
1340 volatile cdkhdr_t *hdrp;
1341 volatile cdkctrl_t *cp;
1342 volatile unsigned char *bits;
1346 kprintf("stli_rawopen(brdp=%x,portp=%x,arg=%x,wait=%d)\n", (int) brdp,
1347 (int) portp, (int) arg, wait);
1353 * Slave is already closing this port. This can happen if a hangup
1354 * occurs on this port. So we must wait until it is complete. The
1355 * order of opens and closes may not be preserved across shared
1356 * memory, so we must wait until it is complete.
1358 while (portp->state & ST_CLOSING) {
1359 rc = tsleep(&portp->state, PCATCH, "stliraw", 0);
1367 * Everything is ready now, so write the open message into shared
1368 * memory. Once the message is in set the service bits to say that
1369 * this port wants service.
1372 cp = &((volatile cdkasy_t *) EBRDGETMEMPTR(brdp, portp->addr))->ctrl;
1375 hdrp = (volatile cdkhdr_t *) EBRDGETMEMPTR(brdp, CDK_CDKADDR);
1376 bits = ((volatile unsigned char *) hdrp) + brdp->slaveoffset +
1378 *bits |= portp->portbit;
1387 * Slave is in action, so now we must wait for the open acknowledgment
1391 portp->state |= ST_OPENING;
1392 while (portp->state & ST_OPENING) {
1393 rc = tsleep(&portp->state, PCATCH, "stliraw", 0);
1401 if ((rc == 0) && (portp->rc != 0))
1406 /*****************************************************************************/
1409 * Send a close message to the slave. Normally this will sleep waiting
1410 * for the acknowledgement, but if wait parameter is 0 it will not. If
1411 * wait is true then must have user context (to sleep).
1414 static int stli_rawclose(stlibrd_t *brdp, stliport_t *portp, unsigned long arg, int wait)
1416 volatile cdkhdr_t *hdrp;
1417 volatile cdkctrl_t *cp;
1418 volatile unsigned char *bits;
1422 kprintf("stli_rawclose(brdp=%x,portp=%x,arg=%x,wait=%d)\n", (int) brdp,
1423 (int) portp, (int) arg, wait);
1429 * Slave is already closing this port. This can happen if a hangup
1430 * occurs on this port.
1433 while (portp->state & ST_CLOSING) {
1434 rc = tsleep(&portp->state, PCATCH, "stliraw", 0);
1443 * Write the close command into shared memory.
1446 cp = &((volatile cdkasy_t *) EBRDGETMEMPTR(brdp, portp->addr))->ctrl;
1449 hdrp = (volatile cdkhdr_t *) EBRDGETMEMPTR(brdp, CDK_CDKADDR);
1450 bits = ((volatile unsigned char *) hdrp) + brdp->slaveoffset +
1452 *bits |= portp->portbit;
1455 portp->state |= ST_CLOSING;
1462 * Slave is in action, so now we must wait for the open acknowledgment
1466 while (portp->state & ST_CLOSING) {
1467 rc = tsleep(&portp->state, PCATCH, "stliraw", 0);
1475 if ((rc == 0) && (portp->rc != 0))
1480 /*****************************************************************************/
1483 * Send a command to the slave and wait for the response. This must
1484 * have user context (it sleeps). This routine is generic in that it
1485 * can send any type of command. Its purpose is to wait for that command
1486 * to complete (as opposed to initiating the command then returning).
1489 static int stli_cmdwait(stlibrd_t *brdp, stliport_t *portp, unsigned long cmd, void *arg, int size, int copyback)
1494 kprintf("stli_cmdwait(brdp=%x,portp=%x,cmd=%x,arg=%x,size=%d,"
1495 "copyback=%d)\n", (int) brdp, (int) portp, (int) cmd,
1496 (int) arg, size, copyback);
1500 while (portp->state & ST_CMDING) {
1501 rc = tsleep(&portp->state, PCATCH, "stliraw", 0);
1508 stli_sendcmd(brdp, portp, cmd, arg, size, copyback);
1510 while (portp->state & ST_CMDING) {
1511 rc = tsleep(&portp->state, PCATCH, "stliraw", 0);
1524 /*****************************************************************************/
1527 * Start (or continue) the transfer of TX data on this port. If the
1528 * port is not currently busy then load up the interrupt ring queue
1529 * buffer and kick of the transmitter. If the port is running low on
1530 * TX data then refill the ring queue. This routine is also used to
1531 * activate input flow control!
1534 static void stli_start(struct tty *tp)
1536 volatile cdkasy_t *ap;
1537 volatile cdkhdr_t *hdrp;
1538 volatile unsigned char *bits;
1539 unsigned char *shbuf;
1542 unsigned int len, stlen, head, tail, size;
1545 portp = (stliport_t *) tp;
1548 kprintf("stli_start(tp=%x): brdnr=%d portnr=%d\n", (int) tp,
1549 portp->brdnr, portp->portnr);
1556 * Check if the output cooked clist buffers are near empty, wake up
1557 * the line discipline to fill it up.
1559 if (tp->t_outq.c_cc <= tp->t_lowat) {
1560 if (tp->t_state & TS_ASLEEP) {
1561 tp->t_state &= ~TS_ASLEEP;
1562 wakeup(&tp->t_outq);
1564 KNOTE(&tp->t_wsel.si_note, 0);
1568 if (tp->t_state & (TS_TIMEOUT | TS_TTSTOP)) {
1574 * Copy data from the clists into the interrupt ring queue. This will
1575 * require at most 2 copys... What we do is calculate how many chars
1576 * can fit into the ring queue, and how many can fit in 1 copy. If after
1577 * the first copy there is still more room then do the second copy.
1579 if (tp->t_outq.c_cc != 0) {
1580 brdp = stli_brds[portp->brdnr];
1587 ap = (volatile cdkasy_t *) EBRDGETMEMPTR(brdp, portp->addr);
1588 head = (unsigned int) ap->txq.head;
1589 tail = (unsigned int) ap->txq.tail;
1590 if (tail != ((unsigned int) ap->txq.tail))
1591 tail = (unsigned int) ap->txq.tail;
1592 size = portp->txsize;
1594 len = size - (head - tail) - 1;
1595 stlen = size - head;
1597 len = tail - head - 1;
1602 shbuf = (char *) EBRDGETMEMPTR(brdp, portp->txoffset);
1605 stlen = MIN(len, stlen);
1606 count = q_to_b(&tp->t_outq, (shbuf + head), stlen);
1612 stlen = q_to_b(&tp->t_outq, shbuf, len);
1619 ap = (volatile cdkasy_t *) EBRDGETMEMPTR(brdp, portp->addr);
1620 ap->txq.head = head;
1621 hdrp = (volatile cdkhdr_t *) EBRDGETMEMPTR(brdp, CDK_CDKADDR);
1622 bits = ((volatile unsigned char *) hdrp) + brdp->slaveoffset +
1624 *bits |= portp->portbit;
1625 portp->state |= ST_TXBUSY;
1626 tp->t_state |= TS_BUSY;
1633 * Do any writer wakeups.
1641 /*****************************************************************************/
1644 * Send a new port configuration to the slave.
1647 static int stli_param(struct tty *tp, struct termios *tiosp)
1654 portp = (stliport_t *) tp;
1655 if ((brdp = stli_brds[portp->brdnr]) == NULL)
1659 stli_mkasyport(portp, &aport, tiosp);
1660 /* can we sleep here? */
1661 rc = stli_cmdwait(brdp, portp, A_SETPORT, &aport, sizeof(asyport_t), 0);
1662 stli_ttyoptim(portp, tiosp);
1667 /*****************************************************************************/
1670 * Flush characters from the lower buffer. We may not have user context
1671 * so we cannot sleep waiting for it to complete. Also we need to check
1672 * if there is chars for this port in the TX cook buffer, and flush them
1676 static void stli_flush(stliport_t *portp, int flag)
1679 unsigned long ftype;
1682 kprintf("stli_flush(portp=%x,flag=%x)\n", (int) portp, flag);
1687 if ((portp->brdnr < 0) || (portp->brdnr >= stli_nrbrds))
1689 brdp = stli_brds[portp->brdnr];
1694 if (portp->state & ST_CMDING) {
1695 portp->state |= (flag & FWRITE) ? ST_DOFLUSHTX : 0;
1696 portp->state |= (flag & FREAD) ? ST_DOFLUSHRX : 0;
1698 ftype = (flag & FWRITE) ? FLUSHTX : 0;
1699 ftype |= (flag & FREAD) ? FLUSHRX : 0;
1700 portp->state &= ~(ST_DOFLUSHTX | ST_DOFLUSHRX);
1701 stli_sendcmd(brdp, portp, A_FLUSH, &ftype,
1702 sizeof(unsigned long), 0);
1704 if ((flag & FREAD) && (stli_rxtmpport == portp))
1709 /*****************************************************************************/
1712 * Generic send command routine. This will send a message to the slave,
1713 * of the specified type with the specified argument. Must be very
1714 * carefull of data that will be copied out from shared memory -
1715 * containing command results. The command completion is all done from
1716 * a poll routine that does not have user coontext. Therefore you cannot
1717 * copy back directly into user space, or to the kernel stack of a
1718 * process. This routine does not sleep, so can be called from anywhere,
1719 * and must be called with interrupt locks set.
1722 static void stli_sendcmd(stlibrd_t *brdp, stliport_t *portp, unsigned long cmd, void *arg, int size, int copyback)
1724 volatile cdkhdr_t *hdrp;
1725 volatile cdkctrl_t *cp;
1726 volatile unsigned char *bits;
1729 kprintf("stli_sendcmd(brdp=%x,portp=%x,cmd=%x,arg=%x,size=%d,"
1730 "copyback=%d)\n", (int) brdp, (int) portp, (int) cmd,
1731 (int) arg, size, copyback);
1734 if (portp->state & ST_CMDING) {
1735 kprintf("STALLION: command already busy, cmd=%x!\n", (int) cmd);
1740 cp = &((volatile cdkasy_t *) EBRDGETMEMPTR(brdp, portp->addr))->ctrl;
1742 bcopy(arg, &(cp->args[0]), size);
1745 portp->argsize = size;
1750 hdrp = (volatile cdkhdr_t *) EBRDGETMEMPTR(brdp, CDK_CDKADDR);
1751 bits = ((volatile unsigned char *) hdrp) + brdp->slaveoffset +
1753 *bits |= portp->portbit;
1754 portp->state |= ST_CMDING;
1758 /*****************************************************************************/
1761 * Read data from shared memory. This assumes that the shared memory
1762 * is enabled and that interrupts are off. Basically we just empty out
1763 * the shared memory buffer into the tty buffer. Must be carefull to
1764 * handle the case where we fill up the tty buffer, but still have
1765 * more chars to unload.
1768 static void stli_rxprocess(stlibrd_t *brdp, stliport_t *portp)
1770 volatile cdkasyrq_t *rp;
1771 volatile char *shbuf;
1773 unsigned int head, tail, size;
1774 unsigned int len, stlen, i;
1778 kprintf("stli_rxprocess(brdp=%x,portp=%d)\n", (int) brdp, (int) portp);
1782 if ((tp->t_state & TS_ISOPEN) == 0) {
1783 stli_flush(portp, FREAD);
1786 if (tp->t_state & TS_TBLOCK)
1789 rp = &((volatile cdkasy_t *) EBRDGETMEMPTR(brdp, portp->addr))->rxq;
1790 head = (unsigned int) rp->head;
1791 if (head != ((unsigned int) rp->head))
1792 head = (unsigned int) rp->head;
1793 tail = (unsigned int) rp->tail;
1794 size = portp->rxsize;
1799 len = size - (tail - head);
1800 stlen = size - tail;
1806 shbuf = (volatile char *) EBRDGETMEMPTR(brdp, portp->rxoffset);
1809 * If we can bypass normal LD processing then just copy direct
1810 * from board shared memory into the tty buffers.
1812 if (tp->t_state & TS_CAN_BYPASS_L_RINT) {
1813 if (((tp->t_rawq.c_cc + len) >= TTYHOG) &&
1814 ((tp->t_cflag & CRTS_IFLOW) || (tp->t_iflag & IXOFF)) &&
1815 ((tp->t_state & TS_TBLOCK) == 0)) {
1816 ch = TTYHOG - tp->t_rawq.c_cc - 1;
1817 len = (ch > 0) ? ch : 0;
1818 stlen = MIN(stlen, len);
1819 tp->t_state |= TS_TBLOCK;
1821 i = b_to_q(__DEVOLATILE(char *, shbuf + tail), stlen,
1827 i += b_to_q(__DEVOLATILE(char *, shbuf), len,
1833 rp = &((volatile cdkasy_t *)
1834 EBRDGETMEMPTR(brdp, portp->addr))->rxq;
1839 * Copy the data from board shared memory into a local
1840 * memory buffer. Then feed them from here into the LD.
1841 * We don't want to go into board shared memory one char
1842 * at a time, it is too slow...
1846 stlen = min(len, stlen);
1848 stli_rxtmpport = portp;
1849 stli_rxtmplen = len;
1850 bcopy(__DEVOLATILE(char *, shbuf + tail), &stli_rxtmpbuf[0],
1854 bcopy(shbuf, &stli_rxtmpbuf[stlen], len);
1856 for (i = 0; (i < stli_rxtmplen); i++) {
1857 ch = (unsigned char) stli_rxtmpbuf[i];
1858 (*linesw[tp->t_line].l_rint)(ch, tp);
1861 rp = &((volatile cdkasy_t *)
1862 EBRDGETMEMPTR(brdp, portp->addr))->rxq;
1863 if (stli_rxtmplen == 0) {
1864 head = (unsigned int) rp->head;
1865 if (head != ((unsigned int) rp->head))
1866 head = (unsigned int) rp->head;
1874 stli_rxtmpport = NULL;
1878 portp->state |= ST_RXING;
1881 /*****************************************************************************/
1884 * Set up and carry out any delayed commands. There is only a small set
1885 * of slave commands that can be done "off-level". So it is not too
1886 * difficult to deal with them as a special case here.
1889 static __inline void stli_dodelaycmd(stliport_t *portp, volatile cdkctrl_t *cp)
1893 if (portp->state & ST_DOSIGS) {
1894 if ((portp->state & ST_DOFLUSHTX) &&
1895 (portp->state & ST_DOFLUSHRX))
1896 cmd = A_SETSIGNALSF;
1897 else if (portp->state & ST_DOFLUSHTX)
1898 cmd = A_SETSIGNALSFTX;
1899 else if (portp->state & ST_DOFLUSHRX)
1900 cmd = A_SETSIGNALSFRX;
1903 portp->state &= ~(ST_DOFLUSHTX | ST_DOFLUSHRX | ST_DOSIGS);
1904 bcopy(&portp->asig, &(cp->args[0]), sizeof(asysigs_t));
1907 portp->state |= ST_CMDING;
1908 } else if ((portp->state & ST_DOFLUSHTX) ||
1909 (portp->state & ST_DOFLUSHRX)) {
1910 cmd = ((portp->state & ST_DOFLUSHTX) ? FLUSHTX : 0);
1911 cmd |= ((portp->state & ST_DOFLUSHRX) ? FLUSHRX : 0);
1912 portp->state &= ~(ST_DOFLUSHTX | ST_DOFLUSHRX);
1913 bcopy(&cmd, &(cp->args[0]), sizeof(int));
1916 portp->state |= ST_CMDING;
1920 /*****************************************************************************/
1923 * Host command service checking. This handles commands or messages
1924 * coming from the slave to the host. Must have board shared memory
1925 * enabled and interrupts off when called. Notice that by servicing the
1926 * read data last we don't need to change the shared memory pointer
1927 * during processing (which is a slow IO operation).
1928 * Return value indicates if this port is still awaiting actions from
1929 * the slave (like open, command, or even TX data being sent). If 0
1930 * then port is still busy, otherwise the port request bit flag is
1934 static __inline int stli_hostcmd(stlibrd_t *brdp, stliport_t *portp)
1936 volatile cdkasy_t *ap;
1937 volatile cdkctrl_t *cp;
1939 unsigned long oldsigs;
1940 unsigned int head, tail;
1944 kprintf("stli_hostcmd(brdp=%x,portp=%x)\n", (int) brdp, (int) portp);
1947 ap = (volatile cdkasy_t *) EBRDGETMEMPTR(brdp, portp->addr);
1951 * Check if we are waiting for an open completion message.
1953 if (portp->state & ST_OPENING) {
1954 rc = (int) cp->openarg;
1955 if ((cp->open == 0) && (rc != 0)) {
1960 portp->state &= ~ST_OPENING;
1961 wakeup(&portp->state);
1966 * Check if we are waiting for a close completion message.
1968 if (portp->state & ST_CLOSING) {
1969 rc = (int) cp->closearg;
1970 if ((cp->close == 0) && (rc != 0)) {
1975 portp->state &= ~ST_CLOSING;
1976 wakeup(&portp->state);
1981 * Check if we are waiting for a command completion message. We may
1982 * need to copy out the command results associated with this command.
1984 if (portp->state & ST_CMDING) {
1986 if ((cp->cmd == 0) && (rc != 0)) {
1989 if (portp->argp != NULL) {
1990 bcopy(&(cp->args[0]), portp->argp,
1996 portp->state &= ~ST_CMDING;
1997 stli_dodelaycmd(portp, cp);
1998 wakeup(&portp->state);
2003 * Check for any notification messages ready. This includes lots of
2004 * different types of events - RX chars ready, RX break received,
2005 * TX data low or empty in the slave, modem signals changed state.
2006 * Must be extremely carefull if we call to the LD, it may call
2007 * other routines of ours that will disable the memory...
2008 * Something else we need to be carefull of is race conditions on
2009 * marking the TX as empty...
2020 if (nt.signal & SG_DCD) {
2021 oldsigs = portp->sigs;
2022 portp->sigs = stli_mktiocm(nt.sigvalue);
2023 portp->state &= ~ST_GETSIGS;
2024 (*linesw[tp->t_line].l_modem)(tp,
2025 (portp->sigs & TIOCM_CD));
2028 if (nt.data & DT_RXBUSY) {
2030 stli_rxprocess(brdp, portp);
2032 if (nt.data & DT_RXBREAK) {
2033 (*linesw[tp->t_line].l_rint)(TTY_BI, tp);
2036 if (nt.data & DT_TXEMPTY) {
2037 ap = (volatile cdkasy_t *)
2038 EBRDGETMEMPTR(brdp, portp->addr);
2039 head = (unsigned int) ap->txq.head;
2040 tail = (unsigned int) ap->txq.tail;
2041 if (tail != ((unsigned int) ap->txq.tail))
2042 tail = (unsigned int) ap->txq.tail;
2043 head = (head >= tail) ? (head - tail) :
2044 portp->txsize - (tail - head);
2046 portp->state &= ~ST_TXBUSY;
2047 tp->t_state &= ~TS_BUSY;
2050 if (nt.data & (DT_TXEMPTY | DT_TXLOW)) {
2051 (*linesw[tp->t_line].l_start)(tp);
2057 * It might seem odd that we are checking for more RX chars here.
2058 * But, we need to handle the case where the tty buffer was previously
2059 * filled, but we had more characters to pass up. The slave will not
2060 * send any more RX notify messages until the RX buffer has been emptied.
2061 * But it will leave the service bits on (since the buffer is not empty).
2062 * So from here we can try to process more RX chars.
2064 if ((!donerx) && (portp->state & ST_RXING)) {
2065 portp->state &= ~ST_RXING;
2066 stli_rxprocess(brdp, portp);
2069 return((portp->state & (ST_OPENING | ST_CLOSING | ST_CMDING |
2070 ST_TXBUSY | ST_RXING)) ? 0 : 1);
2073 /*****************************************************************************/
2076 * Service all ports on a particular board. Assumes that the boards
2077 * shared memory is enabled, and that the page pointer is pointed
2078 * at the cdk header structure.
2081 static __inline void stli_brdpoll(stlibrd_t *brdp, volatile cdkhdr_t *hdrp)
2084 unsigned char hostbits[(STL_MAXCHANS / 8) + 1];
2085 unsigned char slavebits[(STL_MAXCHANS / 8) + 1];
2086 unsigned char *slavep;
2087 int bitpos, bitat, bitsize;
2088 int channr, nrdevs, slavebitchange;
2090 bitsize = brdp->bitsize;
2091 nrdevs = brdp->nrdevs;
2094 * Check if slave wants any service. Basically we try to do as
2095 * little work as possible here. There are 2 levels of service
2096 * bits. So if there is nothing to do we bail early. We check
2097 * 8 service bits at a time in the inner loop, so we can bypass
2098 * the lot if none of them want service.
2100 bcopy(__DEVOLATILE(unsigned char *, hdrp) + brdp->hostoffset,
2101 &hostbits[0], bitsize);
2103 bzero(&slavebits[0], bitsize);
2106 for (bitpos = 0; (bitpos < bitsize); bitpos++) {
2107 if (hostbits[bitpos] == 0)
2109 channr = bitpos * 8;
2111 for (; (channr < nrdevs); channr++, bitat <<=1) {
2112 if (hostbits[bitpos] & bitat) {
2113 portp = brdp->ports[(channr - 1)];
2114 if (stli_hostcmd(brdp, portp)) {
2116 slavebits[bitpos] |= bitat;
2123 * If any of the ports are no longer busy then update them in the
2124 * slave request bits. We need to do this after, since a host port
2125 * service may initiate more slave requests...
2127 if (slavebitchange) {
2128 hdrp = (volatile cdkhdr_t *)
2129 EBRDGETMEMPTR(brdp, CDK_CDKADDR);
2130 slavep = __DEVOLATILE(unsigned char *, hdrp) + brdp->slaveoffset;
2131 for (bitpos = 0; (bitpos < bitsize); bitpos++) {
2132 if (slavebits[bitpos])
2133 slavep[bitpos] &= ~slavebits[bitpos];
2138 /*****************************************************************************/
2141 * Driver poll routine. This routine polls the boards in use and passes
2142 * messages back up to host when neccesary. This is actually very
2143 * CPU efficient, since we will always have the kernel poll clock, it
2144 * adds only a few cycles when idle (since board service can be
2145 * determined very easily), but when loaded generates no interrupts
2146 * (with their expensive associated context change).
2149 static void stli_poll(void *arg)
2151 volatile cdkhdr_t *hdrp;
2158 * Check each board and do any servicing required.
2160 for (brdnr = 0; (brdnr < stli_nrbrds); brdnr++) {
2161 brdp = stli_brds[brdnr];
2164 if ((brdp->state & BST_STARTED) == 0)
2168 hdrp = (volatile cdkhdr_t *) EBRDGETMEMPTR(brdp, CDK_CDKADDR);
2170 stli_brdpoll(brdp, hdrp);
2175 callout_reset(&stli_poll_ch, 1, stli_poll, NULL);
2178 /*****************************************************************************/
2181 * Translate the termios settings into the port setting structure of
2185 static void stli_mkasyport(stliport_t *portp, asyport_t *pp, struct termios *tiosp)
2188 kprintf("stli_mkasyport(portp=%x,pp=%x,tiosp=%d)\n", (int) portp,
2189 (int) pp, (int) tiosp);
2192 bzero(pp, sizeof(asyport_t));
2195 * Start of by setting the baud, char size, parity and stop bit info.
2197 if (tiosp->c_ispeed == 0)
2198 tiosp->c_ispeed = tiosp->c_ospeed;
2199 if ((tiosp->c_ospeed < 0) || (tiosp->c_ospeed > STL_MAXBAUD))
2200 tiosp->c_ospeed = STL_MAXBAUD;
2201 pp->baudout = tiosp->c_ospeed;
2202 pp->baudin = pp->baudout;
2204 switch (tiosp->c_cflag & CSIZE) {
2219 if (tiosp->c_cflag & CSTOPB)
2220 pp->stopbs = PT_STOP2;
2222 pp->stopbs = PT_STOP1;
2224 if (tiosp->c_cflag & PARENB) {
2225 if (tiosp->c_cflag & PARODD)
2226 pp->parity = PT_ODDPARITY;
2228 pp->parity = PT_EVENPARITY;
2230 pp->parity = PT_NOPARITY;
2233 if (tiosp->c_iflag & ISTRIP)
2234 pp->iflag |= FI_ISTRIP;
2237 * Set up any flow control options enabled.
2239 if (tiosp->c_iflag & IXON) {
2241 if (tiosp->c_iflag & IXANY)
2242 pp->flow |= F_IXANY;
2244 if (tiosp->c_iflag & IXOFF)
2245 pp->flow |= F_IXOFF;
2246 if (tiosp->c_cflag & CCTS_OFLOW)
2247 pp->flow |= F_CTSFLOW;
2248 if (tiosp->c_cflag & CRTS_IFLOW)
2249 pp->flow |= F_RTSFLOW;
2251 pp->startin = tiosp->c_cc[VSTART];
2252 pp->stopin = tiosp->c_cc[VSTOP];
2253 pp->startout = tiosp->c_cc[VSTART];
2254 pp->stopout = tiosp->c_cc[VSTOP];
2257 * Set up the RX char marking mask with those RX error types we must
2258 * catch. We can get the slave to help us out a little here, it will
2259 * ignore parity errors and breaks for us, and mark parity errors in
2262 if (tiosp->c_iflag & IGNPAR)
2263 pp->iflag |= FI_IGNRXERRS;
2264 if (tiosp->c_iflag & IGNBRK)
2265 pp->iflag |= FI_IGNBREAK;
2266 if (tiosp->c_iflag & (INPCK | PARMRK))
2267 pp->iflag |= FI_1MARKRXERRS;
2270 * Transfer any persistent flags into the asyport structure.
2272 pp->pflag = (portp->pflag & 0xffff);
2273 pp->vmin = (portp->pflag & P_RXIMIN) ? 1 : 0;
2274 pp->vtime = (portp->pflag & P_RXITIME) ? 1 : 0;
2275 pp->cc[1] = (portp->pflag & P_RXTHOLD) ? 1 : 0;
2278 /*****************************************************************************/
2281 * Construct a slave signals structure for setting the DTR and RTS
2282 * signals as specified.
2285 static void stli_mkasysigs(asysigs_t *sp, int dtr, int rts)
2288 kprintf("stli_mkasysigs(sp=%x,dtr=%d,rts=%d)\n", (int) sp, dtr, rts);
2291 bzero(sp, sizeof(asysigs_t));
2293 sp->signal |= SG_DTR;
2294 sp->sigvalue |= ((dtr > 0) ? SG_DTR : 0);
2297 sp->signal |= SG_RTS;
2298 sp->sigvalue |= ((rts > 0) ? SG_RTS : 0);
2302 /*****************************************************************************/
2305 * Convert the signals returned from the slave into a local TIOCM type
2306 * signals value. We keep them localy in TIOCM format.
2309 static long stli_mktiocm(unsigned long sigvalue)
2314 kprintf("stli_mktiocm(sigvalue=%x)\n", (int) sigvalue);
2318 tiocm |= ((sigvalue & SG_DCD) ? TIOCM_CD : 0);
2319 tiocm |= ((sigvalue & SG_CTS) ? TIOCM_CTS : 0);
2320 tiocm |= ((sigvalue & SG_RI) ? TIOCM_RI : 0);
2321 tiocm |= ((sigvalue & SG_DSR) ? TIOCM_DSR : 0);
2322 tiocm |= ((sigvalue & SG_DTR) ? TIOCM_DTR : 0);
2323 tiocm |= ((sigvalue & SG_RTS) ? TIOCM_RTS : 0);
2327 /*****************************************************************************/
2330 * Enable l_rint processing bypass mode if tty modes allow it.
2333 static void stli_ttyoptim(stliport_t *portp, struct termios *tiosp)
2338 if (((tiosp->c_iflag & (ICRNL | IGNCR | IMAXBEL | INLCR)) == 0) &&
2339 (((tiosp->c_iflag & BRKINT) == 0) || (tiosp->c_iflag & IGNBRK)) &&
2340 (((tiosp->c_iflag & PARMRK) == 0) ||
2341 ((tiosp->c_iflag & (IGNPAR | IGNBRK)) == (IGNPAR | IGNBRK))) &&
2342 ((tiosp->c_lflag & (ECHO | ICANON | IEXTEN | ISIG | PENDIN)) ==0) &&
2343 (linesw[tp->t_line].l_rint == ttyinput))
2344 tp->t_state |= TS_CAN_BYPASS_L_RINT;
2346 tp->t_state &= ~TS_CAN_BYPASS_L_RINT;
2347 portp->hotchar = linesw[tp->t_line].l_hotchar;
2350 /*****************************************************************************/
2353 * All panels and ports actually attached have been worked out. All
2354 * we need to do here is set up the appropriate per port data structures.
2357 static int stli_initports(stlibrd_t *brdp)
2360 int i, panelnr, panelport;
2363 kprintf("stli_initports(brdp=%x)\n", (int) brdp);
2366 for (i = 0, panelnr = 0, panelport = 0; (i < brdp->nrports); i++) {
2367 portp = kmalloc(sizeof(stliport_t), M_TTYS, M_WAITOK | M_ZERO);
2368 callout_init(&portp->dtr_ch);
2370 portp->brdnr = brdp->brdnr;
2371 portp->panelnr = panelnr;
2372 portp->initintios.c_ispeed = STL_DEFSPEED;
2373 portp->initintios.c_ospeed = STL_DEFSPEED;
2374 portp->initintios.c_cflag = STL_DEFCFLAG;
2375 portp->initintios.c_iflag = 0;
2376 portp->initintios.c_oflag = 0;
2377 portp->initintios.c_lflag = 0;
2378 bcopy(&ttydefchars[0], &portp->initintios.c_cc[0],
2379 sizeof(portp->initintios.c_cc));
2380 portp->initouttios = portp->initintios;
2381 portp->dtrwait = 3 * hz;
2384 if (panelport >= brdp->panels[panelnr]) {
2388 brdp->ports[i] = portp;
2395 /*****************************************************************************/
2398 * All the following routines are board specific hardware operations.
2401 static void stli_ecpinit(stlibrd_t *brdp)
2403 unsigned long memconf;
2406 kprintf("stli_ecpinit(brdp=%d)\n", (int) brdp);
2409 outb((brdp->iobase + ECP_ATCONFR), ECP_ATSTOP);
2411 outb((brdp->iobase + ECP_ATCONFR), ECP_ATDISABLE);
2414 memconf = (brdp->paddr & ECP_ATADDRMASK) >> ECP_ATADDRSHFT;
2415 outb((brdp->iobase + ECP_ATMEMAR), memconf);
2418 /*****************************************************************************/
2420 static void stli_ecpenable(stlibrd_t *brdp)
2423 kprintf("stli_ecpenable(brdp=%x)\n", (int) brdp);
2425 outb((brdp->iobase + ECP_ATCONFR), ECP_ATENABLE);
2428 /*****************************************************************************/
2430 static void stli_ecpdisable(stlibrd_t *brdp)
2433 kprintf("stli_ecpdisable(brdp=%x)\n", (int) brdp);
2435 outb((brdp->iobase + ECP_ATCONFR), ECP_ATDISABLE);
2438 /*****************************************************************************/
2440 static char *stli_ecpgetmemptr(stlibrd_t *brdp, unsigned long offset, int line)
2446 kprintf("stli_ecpgetmemptr(brdp=%x,offset=%x)\n", (int) brdp,
2450 if (offset > brdp->memsize) {
2451 kprintf("STALLION: shared memory pointer=%x out of range at "
2452 "line=%d(%d), brd=%d\n", (int) offset, line,
2453 __LINE__, brdp->brdnr);
2457 ptr = (char *) brdp->vaddr + (offset % ECP_ATPAGESIZE);
2458 val = (unsigned char) (offset / ECP_ATPAGESIZE);
2460 outb((brdp->iobase + ECP_ATMEMPR), val);
2464 /*****************************************************************************/
2466 static void stli_ecpreset(stlibrd_t *brdp)
2469 kprintf("stli_ecpreset(brdp=%x)\n", (int) brdp);
2472 outb((brdp->iobase + ECP_ATCONFR), ECP_ATSTOP);
2474 outb((brdp->iobase + ECP_ATCONFR), ECP_ATDISABLE);
2478 /*****************************************************************************/
2480 static void stli_ecpintr(stlibrd_t *brdp)
2483 kprintf("stli_ecpintr(brdp=%x)\n", (int) brdp);
2485 outb(brdp->iobase, 0x1);
2488 /*****************************************************************************/
2491 * The following routines act on ONboards.
2494 static void stli_onbinit(stlibrd_t *brdp)
2496 unsigned long memconf;
2500 kprintf("stli_onbinit(brdp=%d)\n", (int) brdp);
2503 outb((brdp->iobase + ONB_ATCONFR), ONB_ATSTOP);
2505 outb((brdp->iobase + ONB_ATCONFR), ONB_ATDISABLE);
2506 for (i = 0; (i < 1000); i++)
2509 memconf = (brdp->paddr & ONB_ATADDRMASK) >> ONB_ATADDRSHFT;
2510 outb((brdp->iobase + ONB_ATMEMAR), memconf);
2511 outb(brdp->iobase, 0x1);
2515 /*****************************************************************************/
2517 static void stli_onbenable(stlibrd_t *brdp)
2520 kprintf("stli_onbenable(brdp=%x)\n", (int) brdp);
2522 outb((brdp->iobase + ONB_ATCONFR), (ONB_ATENABLE | brdp->confbits));
2525 /*****************************************************************************/
2527 static void stli_onbdisable(stlibrd_t *brdp)
2530 kprintf("stli_onbdisable(brdp=%x)\n", (int) brdp);
2532 outb((brdp->iobase + ONB_ATCONFR), (ONB_ATDISABLE | brdp->confbits));
2535 /*****************************************************************************/
2537 static char *stli_onbgetmemptr(stlibrd_t *brdp, unsigned long offset, int line)
2542 kprintf("stli_onbgetmemptr(brdp=%x,offset=%x)\n", (int) brdp,
2546 if (offset > brdp->memsize) {
2547 kprintf("STALLION: shared memory pointer=%x out of range at "
2548 "line=%d(%d), brd=%d\n", (int) offset, line,
2549 __LINE__, brdp->brdnr);
2552 ptr = (char *) brdp->vaddr + (offset % ONB_ATPAGESIZE);
2557 /*****************************************************************************/
2559 static void stli_onbreset(stlibrd_t *brdp)
2564 kprintf("stli_onbreset(brdp=%x)\n", (int) brdp);
2567 outb((brdp->iobase + ONB_ATCONFR), ONB_ATSTOP);
2569 outb((brdp->iobase + ONB_ATCONFR), ONB_ATDISABLE);
2570 for (i = 0; (i < 1000); i++)
2574 /*****************************************************************************/
2577 * The following routines act on Brumby boards.
2580 static void stli_bbyinit(stlibrd_t *brdp)
2585 kprintf("stli_bbyinit(brdp=%d)\n", (int) brdp);
2588 outb((brdp->iobase + BBY_ATCONFR), BBY_ATSTOP);
2590 outb((brdp->iobase + BBY_ATCONFR), 0);
2591 for (i = 0; (i < 1000); i++)
2593 outb(brdp->iobase, 0x1);
2597 /*****************************************************************************/
2599 static char *stli_bbygetmemptr(stlibrd_t *brdp, unsigned long offset, int line)
2605 kprintf("stli_bbygetmemptr(brdp=%x,offset=%x)\n", (int) brdp,
2609 if (offset > brdp->memsize) {
2610 kprintf("STALLION: shared memory pointer=%x out of range at "
2611 "line=%d(%d), brd=%d\n", (int) offset, line,
2612 __LINE__, brdp->brdnr);
2616 ptr = (char *) brdp->vaddr + (offset % BBY_PAGESIZE);
2617 val = (unsigned char) (offset / BBY_PAGESIZE);
2619 outb((brdp->iobase + BBY_ATCONFR), val);
2623 /*****************************************************************************/
2625 static void stli_bbyreset(stlibrd_t *brdp)
2630 kprintf("stli_bbyreset(brdp=%x)\n", (int) brdp);
2633 outb((brdp->iobase + BBY_ATCONFR), BBY_ATSTOP);
2635 outb((brdp->iobase + BBY_ATCONFR), 0);
2636 for (i = 0; (i < 1000); i++)
2640 /*****************************************************************************/
2643 * The following routines act on original old Stallion boards.
2646 static void stli_stalinit(stlibrd_t *brdp)
2651 kprintf("stli_stalinit(brdp=%d)\n", (int) brdp);
2654 outb(brdp->iobase, 0x1);
2655 for (i = 0; (i < 1000); i++)
2659 /*****************************************************************************/
2661 static char *stli_stalgetmemptr(stlibrd_t *brdp, unsigned long offset, int line)
2666 kprintf("stli_stalgetmemptr(brdp=%x,offset=%x)\n", (int) brdp,
2670 if (offset > brdp->memsize) {
2671 kprintf("STALLION: shared memory pointer=%x out of range at "
2672 "line=%d(%d), brd=%d\n", (int) offset, line,
2673 __LINE__, brdp->brdnr);
2676 ptr = (char *) brdp->vaddr + (offset % STAL_PAGESIZE);
2681 /*****************************************************************************/
2683 static void stli_stalreset(stlibrd_t *brdp)
2685 volatile unsigned long *vecp;
2689 kprintf("stli_stalreset(brdp=%x)\n", (int) brdp);
2692 vecp = (volatile unsigned long *) ((char *) brdp->vaddr + 0x30);
2694 outb(brdp->iobase, 0);
2695 for (i = 0; (i < 1000); i++)
2699 /*****************************************************************************/
2702 * Try to find an ECP board and initialize it. This handles only ECP
2706 static int stli_initecp(stlibrd_t *brdp)
2710 unsigned int status, nxtid;
2714 kprintf("stli_initecp(brdp=%x)\n", (int) brdp);
2718 * Do a basic sanity check on the IO and memory addresses.
2720 if ((brdp->iobase == 0) || (brdp->paddr == 0))
2724 * Based on the specific board type setup the common vars to access
2725 * and enable shared memory. Set all board specific information now
2728 switch (brdp->brdtype) {
2730 brdp->memsize = ECP_MEMSIZE;
2731 brdp->pagesize = ECP_ATPAGESIZE;
2732 brdp->init = stli_ecpinit;
2733 brdp->enable = stli_ecpenable;
2734 brdp->reenable = stli_ecpenable;
2735 brdp->disable = stli_ecpdisable;
2736 brdp->getmemptr = stli_ecpgetmemptr;
2737 brdp->intr = stli_ecpintr;
2738 brdp->reset = stli_ecpreset;
2746 * The per-board operations structure is all setup, so now lets go
2747 * and get the board operational. Firstly initialize board configuration
2753 * Now that all specific code is set up, enable the shared memory and
2754 * look for the a signature area that will tell us exactly what board
2755 * this is, and what it is connected to it.
2758 sigsp = (cdkecpsig_t *) EBRDGETMEMPTR(brdp, CDK_SIGADDR);
2759 bcopy(sigsp, &sig, sizeof(cdkecpsig_t));
2763 kprintf("%s(%d): sig-> magic=%x rom=%x panel=%x,%x,%x,%x,%x,%x,%x,%x\n",
2764 __file__, __LINE__, (int) sig.magic, sig.romver,
2765 sig.panelid[0], (int) sig.panelid[1], (int) sig.panelid[2],
2766 (int) sig.panelid[3], (int) sig.panelid[4],
2767 (int) sig.panelid[5], (int) sig.panelid[6],
2768 (int) sig.panelid[7]);
2771 if (sig.magic != ECP_MAGIC)
2775 * Scan through the signature looking at the panels connected to the
2776 * board. Calculate the total number of ports as we go.
2778 for (panelnr = 0, nxtid = 0; (panelnr < STL_MAXPANELS); panelnr++) {
2779 status = sig.panelid[nxtid];
2780 if ((status & ECH_PNLIDMASK) != nxtid)
2782 brdp->panelids[panelnr] = status;
2783 if (status & ECH_PNL16PORT) {
2784 brdp->panels[panelnr] = 16;
2785 brdp->nrports += 16;
2788 brdp->panels[panelnr] = 8;
2795 brdp->state |= BST_FOUND;
2799 /*****************************************************************************/
2802 * Try to find an ONboard, Brumby or Stallion board and initialize it.
2803 * This handles only these board types.
2806 static int stli_initonb(stlibrd_t *brdp)
2813 kprintf("stli_initonb(brdp=%x)\n", (int) brdp);
2817 * Do a basic sanity check on the IO and memory addresses.
2819 if ((brdp->iobase == 0) || (brdp->paddr == 0))
2823 * Based on the specific board type setup the common vars to access
2824 * and enable shared memory. Set all board specific information now
2827 switch (brdp->brdtype) {
2831 case BRD_ONBOARD2_32:
2833 brdp->memsize = ONB_MEMSIZE;
2834 brdp->pagesize = ONB_ATPAGESIZE;
2835 brdp->init = stli_onbinit;
2836 brdp->enable = stli_onbenable;
2837 brdp->reenable = stli_onbenable;
2838 brdp->disable = stli_onbdisable;
2839 brdp->getmemptr = stli_onbgetmemptr;
2840 brdp->intr = stli_ecpintr;
2841 brdp->reset = stli_onbreset;
2842 brdp->confbits = (brdp->paddr > 0x100000) ? ONB_HIMEMENAB : 0;
2848 brdp->memsize = BBY_MEMSIZE;
2849 brdp->pagesize = BBY_PAGESIZE;
2850 brdp->init = stli_bbyinit;
2851 brdp->enable = NULL;
2852 brdp->reenable = NULL;
2853 brdp->disable = NULL;
2854 brdp->getmemptr = stli_bbygetmemptr;
2855 brdp->intr = stli_ecpintr;
2856 brdp->reset = stli_bbyreset;
2860 brdp->memsize = STAL_MEMSIZE;
2861 brdp->pagesize = STAL_PAGESIZE;
2862 brdp->init = stli_stalinit;
2863 brdp->enable = NULL;
2864 brdp->reenable = NULL;
2865 brdp->disable = NULL;
2866 brdp->getmemptr = stli_stalgetmemptr;
2867 brdp->intr = stli_ecpintr;
2868 brdp->reset = stli_stalreset;
2876 * The per-board operations structure is all setup, so now lets go
2877 * and get the board operational. Firstly initialize board configuration
2883 * Now that all specific code is set up, enable the shared memory and
2884 * look for the a signature area that will tell us exactly what board
2885 * this is, and how many ports.
2888 sigsp = (cdkonbsig_t *) EBRDGETMEMPTR(brdp, CDK_SIGADDR);
2889 bcopy(sigsp, &sig, sizeof(cdkonbsig_t));
2893 kprintf("%s(%d): sig-> magic=%x:%x:%x:%x romver=%x amask=%x:%x:%x\n",
2894 __file__, __LINE__, sig.magic0, sig.magic1, sig.magic2,
2895 sig.magic3, sig.romver, sig.amask0, sig.amask1, sig.amask2);
2898 if ((sig.magic0 != ONB_MAGIC0) || (sig.magic1 != ONB_MAGIC1) ||
2899 (sig.magic2 != ONB_MAGIC2) || (sig.magic3 != ONB_MAGIC3))
2903 * Scan through the signature alive mask and calculate how many ports
2904 * there are on this board.
2910 for (i = 0; (i < 16); i++) {
2911 if (((sig.amask0 << i) & 0x8000) == 0)
2916 brdp->panels[0] = brdp->nrports;
2918 brdp->state |= BST_FOUND;
2922 /*****************************************************************************/
2925 * Start up a running board. This routine is only called after the
2926 * code has been down loaded to the board and is operational. It will
2927 * read in the memory map, and get the show on the road...
2930 static int stli_startbrd(stlibrd_t *brdp)
2932 volatile cdkhdr_t *hdrp;
2933 volatile cdkmem_t *memp;
2934 volatile cdkasy_t *ap;
2936 int portnr, nrdevs, i, rc;
2939 kprintf("stli_startbrd(brdp=%x)\n", (int) brdp);
2946 hdrp = (volatile cdkhdr_t *) EBRDGETMEMPTR(brdp, CDK_CDKADDR);
2947 nrdevs = hdrp->nrdevs;
2950 kprintf("%s(%d): CDK version %d.%d.%d --> nrdevs=%d memp=%x hostp=%x "
2951 "slavep=%x\n", __file__, __LINE__, hdrp->ver_release,
2952 hdrp->ver_modification, hdrp->ver_fix, nrdevs,
2953 (int) hdrp->memp, (int) hdrp->hostp, (int) hdrp->slavep);
2956 if (nrdevs < (brdp->nrports + 1)) {
2957 kprintf("STALLION: slave failed to allocate memory for all "
2958 "devices, devices=%d\n", nrdevs);
2959 brdp->nrports = nrdevs - 1;
2961 brdp->nrdevs = nrdevs;
2962 brdp->hostoffset = hdrp->hostp - CDK_CDKADDR;
2963 brdp->slaveoffset = hdrp->slavep - CDK_CDKADDR;
2964 brdp->bitsize = (nrdevs + 7) / 8;
2965 memp = (volatile cdkmem_t *) (void *) (uintptr_t) hdrp->memp;
2966 if ((uintptr_t)(volatile void *)memp > brdp->memsize) {
2967 kprintf("STALLION: corrupted shared memory region?\n");
2969 goto stli_donestartup;
2971 memp = (volatile cdkmem_t *) EBRDGETMEMPTR(brdp,
2972 (uintptr_t)(volatile void *)memp);
2973 if (memp->dtype != TYP_ASYNCTRL) {
2974 kprintf("STALLION: no slave control device found\n");
2976 goto stli_donestartup;
2981 * Cycle through memory allocation of each port. We are guaranteed to
2982 * have all ports inside the first page of slave window, so no need to
2983 * change pages while reading memory map.
2985 for (i = 1, portnr = 0; (i < nrdevs); i++, portnr++, memp++) {
2986 if (memp->dtype != TYP_ASYNC)
2988 portp = brdp->ports[portnr];
2992 portp->addr = memp->offset;
2993 portp->reqidx = (unsigned char) (i * 8 / nrdevs);
2994 portp->reqbit = (unsigned char) (0x1 << portp->reqidx);
2995 portp->portidx = (unsigned char) (i / 8);
2996 portp->portbit = (unsigned char) (0x1 << (i % 8));
2999 hdrp->slavereq = 0xff;
3002 * For each port setup a local copy of the RX and TX buffer offsets
3003 * and sizes. We do this separate from the above, because we need to
3004 * move the shared memory page...
3006 for (i = 1, portnr = 0; (i < nrdevs); i++, portnr++) {
3007 portp = brdp->ports[portnr];
3010 if (portp->addr == 0)
3012 ap = (volatile cdkasy_t *) EBRDGETMEMPTR(brdp, portp->addr);
3014 portp->rxsize = ap->rxq.size;
3015 portp->txsize = ap->txq.size;
3016 portp->rxoffset = ap->rxq.offset;
3017 portp->txoffset = ap->txq.offset;
3026 brdp->state |= BST_STARTED;
3028 if (stli_doingtimeout == 0) {
3029 stli_doingtimeout++;
3030 callout_init(&stli_poll_ch);
3031 callout_reset(&stli_poll_ch, 1, stli_poll, NULL);
3037 /*****************************************************************************/
3040 * Probe and initialize the specified board.
3043 static int stli_brdinit(stlibrd_t *brdp)
3046 kprintf("stli_brdinit(brdp=%x)\n", (int) brdp);
3049 stli_brds[brdp->brdnr] = brdp;
3051 switch (brdp->brdtype) {
3060 case BRD_ONBOARD2_32:
3072 kprintf("STALLION: %s board type not supported in this driver\n",
3073 stli_brdnames[brdp->brdtype]);
3076 kprintf("STALLION: unit=%d is unknown board type=%d\n",
3077 brdp->brdnr, brdp->brdtype);
3084 /*****************************************************************************/
3087 * Finish off the remaining initialization for a board.
3090 static int stli_brdattach(stlibrd_t *brdp)
3093 kprintf("stli_brdattach(brdp=%x)\n", (int) brdp);
3097 if ((brdp->state & BST_FOUND) == 0) {
3098 kprintf("STALLION: %s board not found, unit=%d io=%x mem=%x\n",
3099 stli_brdnames[brdp->brdtype], brdp->brdnr,
3100 brdp->iobase, (int) brdp->paddr);
3105 stli_initports(brdp);
3106 kprintf("stli%d: %s (driver version %s), unit=%d nrpanels=%d "
3107 "nrports=%d\n", brdp->unitid, stli_brdnames[brdp->brdtype],
3108 stli_drvversion, brdp->brdnr, brdp->nrpanels, brdp->nrports);
3112 /*****************************************************************************/
3114 /*****************************************************************************/
3117 * Return the board stats structure to user app.
3120 static int stli_getbrdstats(caddr_t data)
3126 kprintf("stli_getbrdstats(data=%p)\n", (void *) data);
3129 stli_brdstats = *((combrd_t *) data);
3130 if (stli_brdstats.brd >= STL_MAXBRDS)
3132 brdp = stli_brds[stli_brdstats.brd];
3136 bzero(&stli_brdstats, sizeof(combrd_t));
3137 stli_brdstats.brd = brdp->brdnr;
3138 stli_brdstats.type = brdp->brdtype;
3139 stli_brdstats.hwid = 0;
3140 stli_brdstats.state = brdp->state;
3141 stli_brdstats.ioaddr = brdp->iobase;
3142 stli_brdstats.memaddr = brdp->paddr;
3143 stli_brdstats.nrpanels = brdp->nrpanels;
3144 stli_brdstats.nrports = brdp->nrports;
3145 for (i = 0; (i < brdp->nrpanels); i++) {
3146 stli_brdstats.panels[i].panel = i;
3147 stli_brdstats.panels[i].hwid = brdp->panelids[i];
3148 stli_brdstats.panels[i].nrports = brdp->panels[i];
3151 *((combrd_t *) data) = stli_brdstats;
3155 /*****************************************************************************/
3158 * Resolve the referenced port number into a port struct pointer.
3161 static stliport_t *stli_getport(int brdnr, int panelnr, int portnr)
3166 if ((brdnr < 0) || (brdnr >= STL_MAXBRDS))
3168 brdp = stli_brds[brdnr];
3171 for (i = 0; (i < panelnr); i++)
3172 portnr += brdp->panels[i];
3173 if ((portnr < 0) || (portnr >= brdp->nrports))
3175 return(brdp->ports[portnr]);
3178 /*****************************************************************************/
3181 * Return the port stats structure to user app. A NULL port struct
3182 * pointer passed in means that we need to find out from the app
3183 * what port to get stats for (used through board control device).
3186 static int stli_getportstats(stliport_t *portp, caddr_t data)
3191 if (portp == NULL) {
3192 stli_comstats = *((comstats_t *) data);
3193 portp = stli_getport(stli_comstats.brd, stli_comstats.panel,
3194 stli_comstats.port);
3199 brdp = stli_brds[portp->brdnr];
3203 if (brdp->state & BST_STARTED) {
3204 if ((rc = stli_cmdwait(brdp, portp, A_GETSTATS, &stli_cdkstats,
3205 sizeof(asystats_t), 1)) < 0)
3208 bzero(&stli_cdkstats, sizeof(asystats_t));
3211 stli_comstats.brd = portp->brdnr;
3212 stli_comstats.panel = portp->panelnr;
3213 stli_comstats.port = portp->portnr;
3214 stli_comstats.state = portp->state;
3215 /*stli_comstats.flags = portp->flags;*/
3216 stli_comstats.ttystate = portp->tty.t_state;
3217 stli_comstats.cflags = portp->tty.t_cflag;
3218 stli_comstats.iflags = portp->tty.t_iflag;
3219 stli_comstats.oflags = portp->tty.t_oflag;
3220 stli_comstats.lflags = portp->tty.t_lflag;
3222 stli_comstats.txtotal = stli_cdkstats.txchars;
3223 stli_comstats.rxtotal = stli_cdkstats.rxchars + stli_cdkstats.ringover;
3224 stli_comstats.txbuffered = stli_cdkstats.txringq;
3225 stli_comstats.rxbuffered = stli_cdkstats.rxringq;
3226 stli_comstats.rxoverrun = stli_cdkstats.overruns;
3227 stli_comstats.rxparity = stli_cdkstats.parity;
3228 stli_comstats.rxframing = stli_cdkstats.framing;
3229 stli_comstats.rxlost = stli_cdkstats.ringover + portp->rxlost;
3230 stli_comstats.rxbreaks = stli_cdkstats.rxbreaks;
3231 stli_comstats.txbreaks = stli_cdkstats.txbreaks;
3232 stli_comstats.txxon = stli_cdkstats.txstart;
3233 stli_comstats.txxoff = stli_cdkstats.txstop;
3234 stli_comstats.rxxon = stli_cdkstats.rxstart;
3235 stli_comstats.rxxoff = stli_cdkstats.rxstop;
3236 stli_comstats.rxrtsoff = stli_cdkstats.rtscnt / 2;
3237 stli_comstats.rxrtson = stli_cdkstats.rtscnt - stli_comstats.rxrtsoff;
3238 stli_comstats.modem = stli_cdkstats.dcdcnt;
3239 stli_comstats.hwid = stli_cdkstats.hwid;
3240 stli_comstats.signals = stli_mktiocm(stli_cdkstats.signals);
3242 *((comstats_t *) data) = stli_comstats;
3246 /*****************************************************************************/
3249 * Clear the port stats structure. We also return it zeroed out...
3252 static int stli_clrportstats(stliport_t *portp, caddr_t data)
3257 if (portp == NULL) {
3258 stli_comstats = *((comstats_t *) data);
3259 portp = stli_getport(stli_comstats.brd, stli_comstats.panel,
3260 stli_comstats.port);
3265 brdp = stli_brds[portp->brdnr];
3269 if ((rc = stli_cmdwait(brdp, portp, A_CLEARSTATS, 0, 0, 0)) < 0)
3273 bzero(&stli_comstats, sizeof(comstats_t));
3274 stli_comstats.brd = portp->brdnr;
3275 stli_comstats.panel = portp->panelnr;
3276 stli_comstats.port = portp->portnr;
3278 *((comstats_t *) data) = stli_comstats;
3282 /*****************************************************************************/
3285 * Code to handle an "staliomem" read and write operations. This device
3286 * is the contents of the board shared memory. It is used for down
3287 * loading the slave image (and debugging :-)
3290 STATIC int stli_memrw(cdev_t dev, struct uio *uiop, int flag)
3294 int brdnr, size, n, error;
3297 kprintf("stli_memrw(dev=%x,uiop=%x,flag=%x)\n", (int) dev,
3301 brdnr = minor(dev) & 0x7;
3302 brdp = stli_brds[brdnr];
3305 if (brdp->state == 0)
3308 if (uiop->uio_offset >= brdp->memsize)
3312 size = brdp->memsize - uiop->uio_offset;
3317 memptr = (void *) EBRDGETMEMPTR(brdp, uiop->uio_offset);
3318 n = MIN(size, (brdp->pagesize -
3319 (((unsigned long) uiop->uio_offset) % brdp->pagesize)));
3320 error = uiomove(memptr, n, uiop);
3321 if ((uiop->uio_resid == 0) || error)
3330 /*****************************************************************************/
3333 * The "staliomem" device is also required to do some special operations
3334 * on the board. We need to be able to send an interrupt to the board,
3335 * reset it, and start/stop it.
3338 static int stli_memioctl(cdev_t dev, unsigned long cmd, caddr_t data, int flag)
3344 kprintf("stli_memioctl(dev=%s,cmd=%lx,data=%p,flag=%x)\n",
3345 devtoname(dev), cmd, (void *) data, flag);
3349 * Handle board independant ioctls first.
3352 case COM_GETPORTSTATS:
3353 return(stli_getportstats(NULL, data));
3355 case COM_CLRPORTSTATS:
3356 return(stli_clrportstats(NULL, data));
3358 case COM_GETBRDSTATS:
3359 return(stli_getbrdstats(data));
3366 * Handle board dependant ioctls now.
3368 brdnr = minor(dev) & 0x7;
3369 brdp = stli_brds[brdnr];
3372 if (brdp->state == 0)
3382 rc = stli_startbrd(brdp);
3385 brdp->state &= ~BST_STARTED;
3388 brdp->state &= ~BST_STARTED;
3390 if (stli_shared == 0) {
3391 if (brdp->reenable != NULL)
3392 (* brdp->reenable)(brdp);
3395 case COM_GETPORTSTATS:
3396 rc = stli_getportstats(NULL, data);
3398 case COM_CLRPORTSTATS:
3399 rc = stli_clrportstats(NULL, data);
3401 case COM_GETBRDSTATS:
3402 rc = stli_getbrdstats(data);
3412 /*****************************************************************************/