1 /*****************************************************************************/
4 * istallion.c -- stallion intelligent multiport serial driver.
6 * Copyright (C) 1996-1999 Stallion Technologies
7 * Copyright (C) 1994-1996 Greg Ungerer.
9 * This code is loosely based on the Linux serial driver, written by
10 * Linus Torvalds, Theodore T'so and others.
12 * This program is free software; you can redistribute it and/or modify
13 * it under the terms of the GNU General Public License as published by
14 * the Free Software Foundation; either version 2 of the License, or
15 * (at your option) any later version.
17 * This program is distributed in the hope that it will be useful,
18 * but WITHOUT ANY WARRANTY; without even the implied warranty of
19 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
20 * GNU General Public License for more details.
22 * You should have received a copy of the GNU General Public License
23 * along with this program; if not, write to the Free Software
24 * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
27 /*****************************************************************************/
29 #include <linux/config.h>
30 #include <linux/module.h>
31 #include <linux/slab.h>
32 #include <linux/interrupt.h>
33 #include <linux/tty.h>
34 #include <linux/tty_flip.h>
35 #include <linux/serial.h>
36 #include <linux/cdk.h>
37 #include <linux/comstats.h>
38 #include <linux/istallion.h>
39 #include <linux/ioport.h>
40 #include <linux/delay.h>
41 #include <linux/init.h>
42 #include <linux/devfs_fs_kernel.h>
43 #include <linux/device.h>
44 #include <linux/wait.h>
45 #include <linux/eisa.h>
48 #include <asm/uaccess.h>
50 #include <linux/pci.h>
52 /*****************************************************************************/
55 * Define different board types. Not all of the following board types
56 * are supported by this driver. But I will use the standard "assigned"
57 * board numbers. Currently supported boards are abbreviated as:
58 * ECP = EasyConnection 8/64, ONB = ONboard, BBY = Brumby and
62 #define BRD_STALLION 1
64 #define BRD_ONBOARD2 3
67 #define BRD_BRUMBY16 6
68 #define BRD_ONBOARDE 7
69 #define BRD_ONBOARD32 9
70 #define BRD_ONBOARD2_32 10
71 #define BRD_ONBOARDRS 11
79 #define BRD_ECH64PCI 27
80 #define BRD_EASYIOPCI 28
83 #define BRD_BRUMBY BRD_BRUMBY4
86 * Define a configuration structure to hold the board configuration.
87 * Need to set this up in the code (for now) with the boards that are
88 * to be configured into the system. This is what needs to be modified
89 * when adding/removing/modifying boards. Each line entry in the
90 * stli_brdconf[] array is a board. Each line contains io/irq/memory
91 * ranges for that board (as well as what type of board it is).
93 * { BRD_ECP, 0x2a0, 0, 0xcc000, 0, 0 },
94 * This line will configure an EasyConnection 8/64 at io address 2a0,
95 * and shared memory address of cc000. Multiple EasyConnection 8/64
96 * boards can share the same shared memory address space. No interrupt
97 * is required for this board type.
99 * { BRD_ECPE, 0x5000, 0, 0x80000000, 0, 0 },
100 * This line will configure an EasyConnection 8/64 EISA in slot 5 and
101 * shared memory address of 0x80000000 (2 GByte). Multiple
102 * EasyConnection 8/64 EISA boards can share the same shared memory
103 * address space. No interrupt is required for this board type.
105 * { BRD_ONBOARD, 0x240, 0, 0xd0000, 0, 0 },
106 * This line will configure an ONboard (ISA type) at io address 240,
107 * and shared memory address of d0000. Multiple ONboards can share
108 * the same shared memory address space. No interrupt required.
110 * { BRD_BRUMBY4, 0x360, 0, 0xc8000, 0, 0 },
111 * This line will configure a Brumby board (any number of ports!) at
112 * io address 360 and shared memory address of c8000. All Brumby boards
113 * configured into a system must have their own separate io and memory
114 * addresses. No interrupt is required.
116 * { BRD_STALLION, 0x330, 0, 0xd0000, 0, 0 },
117 * This line will configure an original Stallion board at io address 330
118 * and shared memory address d0000 (this would only be valid for a "V4.0"
119 * or Rev.O Stallion board). All Stallion boards configured into the
120 * system must have their own separate io and memory addresses. No
121 * interrupt is required.
128 unsigned long memaddr;
133 static stlconf_t stli_brdconf[] = {
134 /*{ BRD_ECP, 0x2a0, 0, 0xcc000, 0, 0 },*/
137 static int stli_nrbrds = ARRAY_SIZE(stli_brdconf);
139 /* stli_lock must NOT be taken holding brd_lock */
140 static spinlock_t stli_lock; /* TTY logic lock */
141 static spinlock_t brd_lock; /* Board logic lock */
144 * There is some experimental EISA board detection code in this driver.
145 * By default it is disabled, but for those that want to try it out,
146 * then set the define below to be 1.
148 #define STLI_EISAPROBE 0
150 /*****************************************************************************/
153 * Define some important driver characteristics. Device major numbers
154 * allocated as per Linux Device Registry.
156 #ifndef STL_SIOMEMMAJOR
157 #define STL_SIOMEMMAJOR 28
159 #ifndef STL_SERIALMAJOR
160 #define STL_SERIALMAJOR 24
162 #ifndef STL_CALLOUTMAJOR
163 #define STL_CALLOUTMAJOR 25
166 /*****************************************************************************/
169 * Define our local driver identity first. Set up stuff to deal with
170 * all the local structures required by a serial tty driver.
172 static char *stli_drvtitle = "Stallion Intelligent Multiport Serial Driver";
173 static char *stli_drvname = "istallion";
174 static char *stli_drvversion = "5.6.0";
175 static char *stli_serialname = "ttyE";
177 static struct tty_driver *stli_serial;
180 #define STLI_TXBUFSIZE 4096
183 * Use a fast local buffer for cooked characters. Typically a whole
184 * bunch of cooked characters come in for a port, 1 at a time. So we
185 * save those up into a local buffer, then write out the whole lot
186 * with a large memcpy. Just use 1 buffer for all ports, since its
187 * use it is only need for short periods of time by each port.
189 static char *stli_txcookbuf;
190 static int stli_txcooksize;
191 static int stli_txcookrealsize;
192 static struct tty_struct *stli_txcooktty;
195 * Define a local default termios struct. All ports will be created
196 * with this termios initially. Basically all it defines is a raw port
197 * at 9600 baud, 8 data bits, no parity, 1 stop bit.
199 static struct termios stli_deftermios = {
200 .c_cflag = (B9600 | CS8 | CREAD | HUPCL | CLOCAL),
205 * Define global stats structures. Not used often, and can be
206 * re-used for each stats call.
208 static comstats_t stli_comstats;
209 static combrd_t stli_brdstats;
210 static asystats_t stli_cdkstats;
211 static stlibrd_t stli_dummybrd;
212 static stliport_t stli_dummyport;
214 /*****************************************************************************/
216 static stlibrd_t *stli_brds[STL_MAXBRDS];
218 static int stli_shared;
221 * Per board state flags. Used with the state field of the board struct.
222 * Not really much here... All we need to do is keep track of whether
223 * the board has been detected, and whether it is actually running a slave
226 #define BST_FOUND 0x1
227 #define BST_STARTED 0x2
230 * Define the set of port state flags. These are marked for internal
231 * state purposes only, usually to do with the state of communications
232 * with the slave. Most of them need to be updated atomically, so always
233 * use the bit setting operations (unless protected by cli/sti).
235 #define ST_INITIALIZING 1
241 #define ST_DOFLUSHRX 7
242 #define ST_DOFLUSHTX 8
245 #define ST_GETSIGS 11
248 * Define an array of board names as printable strings. Handy for
249 * referencing boards when printing trace and stuff.
251 static char *stli_brdnames[] = {
284 /*****************************************************************************/
288 * Define some string labels for arguments passed from the module
289 * load line. These allow for easy board definitions, and easy
290 * modification of the io, memory and irq resoucres.
293 static char *board0[8];
294 static char *board1[8];
295 static char *board2[8];
296 static char *board3[8];
298 static char **stli_brdsp[] = {
306 * Define a set of common board names, and types. This is used to
307 * parse any module arguments.
310 typedef struct stlibrdtype {
315 static stlibrdtype_t stli_brdstr[] = {
316 { "stallion", BRD_STALLION },
317 { "1", BRD_STALLION },
318 { "brumby", BRD_BRUMBY },
319 { "brumby4", BRD_BRUMBY },
320 { "brumby/4", BRD_BRUMBY },
321 { "brumby-4", BRD_BRUMBY },
322 { "brumby8", BRD_BRUMBY },
323 { "brumby/8", BRD_BRUMBY },
324 { "brumby-8", BRD_BRUMBY },
325 { "brumby16", BRD_BRUMBY },
326 { "brumby/16", BRD_BRUMBY },
327 { "brumby-16", BRD_BRUMBY },
329 { "onboard2", BRD_ONBOARD2 },
330 { "onboard-2", BRD_ONBOARD2 },
331 { "onboard/2", BRD_ONBOARD2 },
332 { "onboard-mc", BRD_ONBOARD2 },
333 { "onboard/mc", BRD_ONBOARD2 },
334 { "onboard-mca", BRD_ONBOARD2 },
335 { "onboard/mca", BRD_ONBOARD2 },
336 { "3", BRD_ONBOARD2 },
337 { "onboard", BRD_ONBOARD },
338 { "onboardat", BRD_ONBOARD },
339 { "4", BRD_ONBOARD },
340 { "onboarde", BRD_ONBOARDE },
341 { "onboard-e", BRD_ONBOARDE },
342 { "onboard/e", BRD_ONBOARDE },
343 { "onboard-ei", BRD_ONBOARDE },
344 { "onboard/ei", BRD_ONBOARDE },
345 { "7", BRD_ONBOARDE },
347 { "ecpat", BRD_ECP },
348 { "ec8/64", BRD_ECP },
349 { "ec8/64-at", BRD_ECP },
350 { "ec8/64-isa", BRD_ECP },
352 { "ecpe", BRD_ECPE },
353 { "ecpei", BRD_ECPE },
354 { "ec8/64-e", BRD_ECPE },
355 { "ec8/64-ei", BRD_ECPE },
357 { "ecpmc", BRD_ECPMC },
358 { "ec8/64-mc", BRD_ECPMC },
359 { "ec8/64-mca", BRD_ECPMC },
361 { "ecppci", BRD_ECPPCI },
362 { "ec/ra", BRD_ECPPCI },
363 { "ec/ra-pc", BRD_ECPPCI },
364 { "ec/ra-pci", BRD_ECPPCI },
365 { "29", BRD_ECPPCI },
369 * Define the module agruments.
371 MODULE_AUTHOR("Greg Ungerer");
372 MODULE_DESCRIPTION("Stallion Intelligent Multiport Serial Driver");
373 MODULE_LICENSE("GPL");
376 module_param_array(board0, charp, NULL, 0);
377 MODULE_PARM_DESC(board0, "Board 0 config -> name[,ioaddr[,memaddr]");
378 module_param_array(board1, charp, NULL, 0);
379 MODULE_PARM_DESC(board1, "Board 1 config -> name[,ioaddr[,memaddr]");
380 module_param_array(board2, charp, NULL, 0);
381 MODULE_PARM_DESC(board2, "Board 2 config -> name[,ioaddr[,memaddr]");
382 module_param_array(board3, charp, NULL, 0);
383 MODULE_PARM_DESC(board3, "Board 3 config -> name[,ioaddr[,memaddr]");
388 * Set up a default memory address table for EISA board probing.
389 * The default addresses are all bellow 1Mbyte, which has to be the
390 * case anyway. They should be safe, since we only read values from
391 * them, and interrupts are disabled while we do it. If the higher
392 * memory support is compiled in then we also try probing around
393 * the 1Gb, 2Gb and 3Gb areas as well...
395 static unsigned long stli_eisamemprobeaddrs[] = {
396 0xc0000, 0xd0000, 0xe0000, 0xf0000,
397 0x80000000, 0x80010000, 0x80020000, 0x80030000,
398 0x40000000, 0x40010000, 0x40020000, 0x40030000,
399 0xc0000000, 0xc0010000, 0xc0020000, 0xc0030000,
400 0xff000000, 0xff010000, 0xff020000, 0xff030000,
403 static int stli_eisamempsize = ARRAY_SIZE(stli_eisamemprobeaddrs);
406 * Define the Stallion PCI vendor and device IDs.
409 #ifndef PCI_VENDOR_ID_STALLION
410 #define PCI_VENDOR_ID_STALLION 0x124d
412 #ifndef PCI_DEVICE_ID_ECRA
413 #define PCI_DEVICE_ID_ECRA 0x0004
416 static struct pci_device_id istallion_pci_tbl[] = {
417 { PCI_DEVICE(PCI_VENDOR_ID_STALLION, PCI_DEVICE_ID_ECRA), },
420 MODULE_DEVICE_TABLE(pci, istallion_pci_tbl);
422 #endif /* CONFIG_PCI */
424 /*****************************************************************************/
427 * Hardware configuration info for ECP boards. These defines apply
428 * to the directly accessible io ports of the ECP. There is a set of
429 * defines for each ECP board type, ISA, EISA, MCA and PCI.
433 #define ECP_MEMSIZE (128 * 1024)
434 #define ECP_PCIMEMSIZE (256 * 1024)
436 #define ECP_ATPAGESIZE (4 * 1024)
437 #define ECP_MCPAGESIZE (4 * 1024)
438 #define ECP_EIPAGESIZE (64 * 1024)
439 #define ECP_PCIPAGESIZE (64 * 1024)
441 #define STL_EISAID 0x8c4e
444 * Important defines for the ISA class of ECP board.
447 #define ECP_ATCONFR 1
448 #define ECP_ATMEMAR 2
449 #define ECP_ATMEMPR 3
450 #define ECP_ATSTOP 0x1
451 #define ECP_ATINTENAB 0x10
452 #define ECP_ATENABLE 0x20
453 #define ECP_ATDISABLE 0x00
454 #define ECP_ATADDRMASK 0x3f000
455 #define ECP_ATADDRSHFT 12
458 * Important defines for the EISA class of ECP board.
461 #define ECP_EIMEMARL 1
462 #define ECP_EICONFR 2
463 #define ECP_EIMEMARH 3
464 #define ECP_EIENABLE 0x1
465 #define ECP_EIDISABLE 0x0
466 #define ECP_EISTOP 0x4
467 #define ECP_EIEDGE 0x00
468 #define ECP_EILEVEL 0x80
469 #define ECP_EIADDRMASKL 0x00ff0000
470 #define ECP_EIADDRSHFTL 16
471 #define ECP_EIADDRMASKH 0xff000000
472 #define ECP_EIADDRSHFTH 24
473 #define ECP_EIBRDENAB 0xc84
475 #define ECP_EISAID 0x4
478 * Important defines for the Micro-channel class of ECP board.
479 * (It has a lot in common with the ISA boards.)
482 #define ECP_MCCONFR 1
483 #define ECP_MCSTOP 0x20
484 #define ECP_MCENABLE 0x80
485 #define ECP_MCDISABLE 0x00
488 * Important defines for the PCI class of ECP board.
489 * (It has a lot in common with the other ECP boards.)
491 #define ECP_PCIIREG 0
492 #define ECP_PCICONFR 1
493 #define ECP_PCISTOP 0x01
496 * Hardware configuration info for ONboard and Brumby boards. These
497 * defines apply to the directly accessible io ports of these boards.
499 #define ONB_IOSIZE 16
500 #define ONB_MEMSIZE (64 * 1024)
501 #define ONB_ATPAGESIZE (64 * 1024)
502 #define ONB_MCPAGESIZE (64 * 1024)
503 #define ONB_EIMEMSIZE (128 * 1024)
504 #define ONB_EIPAGESIZE (64 * 1024)
507 * Important defines for the ISA class of ONboard board.
510 #define ONB_ATMEMAR 1
511 #define ONB_ATCONFR 2
512 #define ONB_ATSTOP 0x4
513 #define ONB_ATENABLE 0x01
514 #define ONB_ATDISABLE 0x00
515 #define ONB_ATADDRMASK 0xff0000
516 #define ONB_ATADDRSHFT 16
518 #define ONB_MEMENABLO 0
519 #define ONB_MEMENABHI 0x02
522 * Important defines for the EISA class of ONboard board.
525 #define ONB_EIMEMARL 1
526 #define ONB_EICONFR 2
527 #define ONB_EIMEMARH 3
528 #define ONB_EIENABLE 0x1
529 #define ONB_EIDISABLE 0x0
530 #define ONB_EISTOP 0x4
531 #define ONB_EIEDGE 0x00
532 #define ONB_EILEVEL 0x80
533 #define ONB_EIADDRMASKL 0x00ff0000
534 #define ONB_EIADDRSHFTL 16
535 #define ONB_EIADDRMASKH 0xff000000
536 #define ONB_EIADDRSHFTH 24
537 #define ONB_EIBRDENAB 0xc84
539 #define ONB_EISAID 0x1
542 * Important defines for the Brumby boards. They are pretty simple,
543 * there is not much that is programmably configurable.
545 #define BBY_IOSIZE 16
546 #define BBY_MEMSIZE (64 * 1024)
547 #define BBY_PAGESIZE (16 * 1024)
550 #define BBY_ATCONFR 1
551 #define BBY_ATSTOP 0x4
554 * Important defines for the Stallion boards. They are pretty simple,
555 * there is not much that is programmably configurable.
557 #define STAL_IOSIZE 16
558 #define STAL_MEMSIZE (64 * 1024)
559 #define STAL_PAGESIZE (64 * 1024)
562 * Define the set of status register values for EasyConnection panels.
563 * The signature will return with the status value for each panel. From
564 * this we can determine what is attached to the board - before we have
565 * actually down loaded any code to it.
567 #define ECH_PNLSTATUS 2
568 #define ECH_PNL16PORT 0x20
569 #define ECH_PNLIDMASK 0x07
570 #define ECH_PNLXPID 0x40
571 #define ECH_PNLINTRPEND 0x80
574 * Define some macros to do things to the board. Even those these boards
575 * are somewhat related there is often significantly different ways of
576 * doing some operation on it (like enable, paging, reset, etc). So each
577 * board class has a set of functions which do the commonly required
578 * operations. The macros below basically just call these functions,
579 * generally checking for a NULL function - which means that the board
580 * needs nothing done to it to achieve this operation!
582 #define EBRDINIT(brdp) \
583 if (brdp->init != NULL) \
586 #define EBRDENABLE(brdp) \
587 if (brdp->enable != NULL) \
588 (* brdp->enable)(brdp);
590 #define EBRDDISABLE(brdp) \
591 if (brdp->disable != NULL) \
592 (* brdp->disable)(brdp);
594 #define EBRDINTR(brdp) \
595 if (brdp->intr != NULL) \
596 (* brdp->intr)(brdp);
598 #define EBRDRESET(brdp) \
599 if (brdp->reset != NULL) \
600 (* brdp->reset)(brdp);
602 #define EBRDGETMEMPTR(brdp,offset) \
603 (* brdp->getmemptr)(brdp, offset, __LINE__)
606 * Define the maximal baud rate, and the default baud base for ports.
608 #define STL_MAXBAUD 460800
609 #define STL_BAUDBASE 115200
610 #define STL_CLOSEDELAY (5 * HZ / 10)
612 /*****************************************************************************/
615 * Define macros to extract a brd or port number from a minor number.
617 #define MINOR2BRD(min) (((min) & 0xc0) >> 6)
618 #define MINOR2PORT(min) ((min) & 0x3f)
621 * Define a baud rate table that converts termios baud rate selector
622 * into the actual baud rate value. All baud rate calculations are based
623 * on the actual baud rate required.
625 static unsigned int stli_baudrates[] = {
626 0, 50, 75, 110, 134, 150, 200, 300, 600, 1200, 1800, 2400, 4800,
627 9600, 19200, 38400, 57600, 115200, 230400, 460800, 921600
630 /*****************************************************************************/
633 * Define some handy local macros...
636 #define MIN(a,b) (((a) <= (b)) ? (a) : (b))
639 #define TOLOWER(x) ((((x) >= 'A') && ((x) <= 'Z')) ? ((x) + 0x20) : (x))
641 /*****************************************************************************/
644 * Prototype all functions in this driver!
648 static void stli_argbrds(void);
649 static int stli_parsebrd(stlconf_t *confp, char **argp);
651 static unsigned long stli_atol(char *str);
655 static int stli_open(struct tty_struct *tty, struct file *filp);
656 static void stli_close(struct tty_struct *tty, struct file *filp);
657 static int stli_write(struct tty_struct *tty, const unsigned char *buf, int count);
658 static void stli_putchar(struct tty_struct *tty, unsigned char ch);
659 static void stli_flushchars(struct tty_struct *tty);
660 static int stli_writeroom(struct tty_struct *tty);
661 static int stli_charsinbuffer(struct tty_struct *tty);
662 static int stli_ioctl(struct tty_struct *tty, struct file *file, unsigned int cmd, unsigned long arg);
663 static void stli_settermios(struct tty_struct *tty, struct termios *old);
664 static void stli_throttle(struct tty_struct *tty);
665 static void stli_unthrottle(struct tty_struct *tty);
666 static void stli_stop(struct tty_struct *tty);
667 static void stli_start(struct tty_struct *tty);
668 static void stli_flushbuffer(struct tty_struct *tty);
669 static void stli_breakctl(struct tty_struct *tty, int state);
670 static void stli_waituntilsent(struct tty_struct *tty, int timeout);
671 static void stli_sendxchar(struct tty_struct *tty, char ch);
672 static void stli_hangup(struct tty_struct *tty);
673 static int stli_portinfo(stlibrd_t *brdp, stliport_t *portp, int portnr, char *pos);
675 static int stli_brdinit(stlibrd_t *brdp);
676 static int stli_startbrd(stlibrd_t *brdp);
677 static ssize_t stli_memread(struct file *fp, char __user *buf, size_t count, loff_t *offp);
678 static ssize_t stli_memwrite(struct file *fp, const char __user *buf, size_t count, loff_t *offp);
679 static int stli_memioctl(struct inode *ip, struct file *fp, unsigned int cmd, unsigned long arg);
680 static void stli_brdpoll(stlibrd_t *brdp, cdkhdr_t __iomem *hdrp);
681 static void stli_poll(unsigned long arg);
682 static int stli_hostcmd(stlibrd_t *brdp, stliport_t *portp);
683 static int stli_initopen(stlibrd_t *brdp, stliport_t *portp);
684 static int stli_rawopen(stlibrd_t *brdp, stliport_t *portp, unsigned long arg, int wait);
685 static int stli_rawclose(stlibrd_t *brdp, stliport_t *portp, unsigned long arg, int wait);
686 static int stli_waitcarrier(stlibrd_t *brdp, stliport_t *portp, struct file *filp);
687 static void stli_dohangup(void *arg);
688 static int stli_setport(stliport_t *portp);
689 static int stli_cmdwait(stlibrd_t *brdp, stliport_t *portp, unsigned long cmd, void *arg, int size, int copyback);
690 static void stli_sendcmd(stlibrd_t *brdp, stliport_t *portp, unsigned long cmd, void *arg, int size, int copyback);
691 static void __stli_sendcmd(stlibrd_t *brdp, stliport_t *portp, unsigned long cmd, void *arg, int size, int copyback);
692 static void stli_dodelaycmd(stliport_t *portp, cdkctrl_t __iomem *cp);
693 static void stli_mkasyport(stliport_t *portp, asyport_t *pp, struct termios *tiosp);
694 static void stli_mkasysigs(asysigs_t *sp, int dtr, int rts);
695 static long stli_mktiocm(unsigned long sigvalue);
696 static void stli_read(stlibrd_t *brdp, stliport_t *portp);
697 static int stli_getserial(stliport_t *portp, struct serial_struct __user *sp);
698 static int stli_setserial(stliport_t *portp, struct serial_struct __user *sp);
699 static int stli_getbrdstats(combrd_t __user *bp);
700 static int stli_getportstats(stliport_t *portp, comstats_t __user *cp);
701 static int stli_portcmdstats(stliport_t *portp);
702 static int stli_clrportstats(stliport_t *portp, comstats_t __user *cp);
703 static int stli_getportstruct(stliport_t __user *arg);
704 static int stli_getbrdstruct(stlibrd_t __user *arg);
705 static stlibrd_t *stli_allocbrd(void);
707 static void stli_ecpinit(stlibrd_t *brdp);
708 static void stli_ecpenable(stlibrd_t *brdp);
709 static void stli_ecpdisable(stlibrd_t *brdp);
710 static char *stli_ecpgetmemptr(stlibrd_t *brdp, unsigned long offset, int line);
711 static void stli_ecpreset(stlibrd_t *brdp);
712 static void stli_ecpintr(stlibrd_t *brdp);
713 static void stli_ecpeiinit(stlibrd_t *brdp);
714 static void stli_ecpeienable(stlibrd_t *brdp);
715 static void stli_ecpeidisable(stlibrd_t *brdp);
716 static char *stli_ecpeigetmemptr(stlibrd_t *brdp, unsigned long offset, int line);
717 static void stli_ecpeireset(stlibrd_t *brdp);
718 static void stli_ecpmcenable(stlibrd_t *brdp);
719 static void stli_ecpmcdisable(stlibrd_t *brdp);
720 static char *stli_ecpmcgetmemptr(stlibrd_t *brdp, unsigned long offset, int line);
721 static void stli_ecpmcreset(stlibrd_t *brdp);
722 static void stli_ecppciinit(stlibrd_t *brdp);
723 static char *stli_ecppcigetmemptr(stlibrd_t *brdp, unsigned long offset, int line);
724 static void stli_ecppcireset(stlibrd_t *brdp);
726 static void stli_onbinit(stlibrd_t *brdp);
727 static void stli_onbenable(stlibrd_t *brdp);
728 static void stli_onbdisable(stlibrd_t *brdp);
729 static char *stli_onbgetmemptr(stlibrd_t *brdp, unsigned long offset, int line);
730 static void stli_onbreset(stlibrd_t *brdp);
731 static void stli_onbeinit(stlibrd_t *brdp);
732 static void stli_onbeenable(stlibrd_t *brdp);
733 static void stli_onbedisable(stlibrd_t *brdp);
734 static char *stli_onbegetmemptr(stlibrd_t *brdp, unsigned long offset, int line);
735 static void stli_onbereset(stlibrd_t *brdp);
736 static void stli_bbyinit(stlibrd_t *brdp);
737 static char *stli_bbygetmemptr(stlibrd_t *brdp, unsigned long offset, int line);
738 static void stli_bbyreset(stlibrd_t *brdp);
739 static void stli_stalinit(stlibrd_t *brdp);
740 static char *stli_stalgetmemptr(stlibrd_t *brdp, unsigned long offset, int line);
741 static void stli_stalreset(stlibrd_t *brdp);
743 static stliport_t *stli_getport(int brdnr, int panelnr, int portnr);
745 static int stli_initecp(stlibrd_t *brdp);
746 static int stli_initonb(stlibrd_t *brdp);
747 static int stli_eisamemprobe(stlibrd_t *brdp);
748 static int stli_initports(stlibrd_t *brdp);
751 static int stli_initpcibrd(int brdtype, struct pci_dev *devp);
754 /*****************************************************************************/
757 * Define the driver info for a user level shared memory device. This
758 * device will work sort of like the /dev/kmem device - except that it
759 * will give access to the shared memory on the Stallion intelligent
760 * board. This is also a very useful debugging tool.
762 static struct file_operations stli_fsiomem = {
763 .owner = THIS_MODULE,
764 .read = stli_memread,
765 .write = stli_memwrite,
766 .ioctl = stli_memioctl,
769 /*****************************************************************************/
772 * Define a timer_list entry for our poll routine. The slave board
773 * is polled every so often to see if anything needs doing. This is
774 * much cheaper on host cpu than using interrupts. It turns out to
775 * not increase character latency by much either...
777 static DEFINE_TIMER(stli_timerlist, stli_poll, 0, 0);
779 static int stli_timeron;
782 * Define the calculation for the timeout routine.
784 #define STLI_TIMEOUT (jiffies + 1)
786 /*****************************************************************************/
788 static struct class *istallion_class;
793 * Loadable module initialization stuff.
796 static int __init istallion_module_init(void)
802 /*****************************************************************************/
804 static void __exit istallion_module_exit(void)
810 printk(KERN_INFO "Unloading %s: version %s\n", stli_drvtitle,
814 * Free up all allocated resources used by the ports. This includes
815 * memory and interrupts.
819 del_timer_sync(&stli_timerlist);
822 i = tty_unregister_driver(stli_serial);
824 printk("STALLION: failed to un-register tty driver, "
828 put_tty_driver(stli_serial);
829 for (i = 0; i < 4; i++) {
830 devfs_remove("staliomem/%d", i);
831 class_device_destroy(istallion_class, MKDEV(STL_SIOMEMMAJOR, i));
833 devfs_remove("staliomem");
834 class_destroy(istallion_class);
835 if ((i = unregister_chrdev(STL_SIOMEMMAJOR, "staliomem")))
836 printk("STALLION: failed to un-register serial memory device, "
839 kfree(stli_txcookbuf);
841 for (i = 0; (i < stli_nrbrds); i++) {
842 if ((brdp = stli_brds[i]) == NULL)
844 for (j = 0; (j < STL_MAXPORTS); j++) {
845 portp = brdp->ports[j];
847 if (portp->tty != NULL)
848 tty_hangup(portp->tty);
853 iounmap(brdp->membase);
854 if (brdp->iosize > 0)
855 release_region(brdp->iobase, brdp->iosize);
861 module_init(istallion_module_init);
862 module_exit(istallion_module_exit);
864 /*****************************************************************************/
867 * Check for any arguments passed in on the module load command line.
870 static void stli_argbrds(void)
876 for (i = stli_nrbrds; i < ARRAY_SIZE(stli_brdsp); i++) {
877 memset(&conf, 0, sizeof(conf));
878 if (stli_parsebrd(&conf, stli_brdsp[i]) == 0)
880 if ((brdp = stli_allocbrd()) == NULL)
884 brdp->brdtype = conf.brdtype;
885 brdp->iobase = conf.ioaddr1;
886 brdp->memaddr = conf.memaddr;
891 /*****************************************************************************/
894 * Convert an ascii string number into an unsigned long.
897 static unsigned long stli_atol(char *str)
905 if ((*sp == '0') && (*(sp+1) == 'x')) {
908 } else if (*sp == '0') {
915 for (; (*sp != 0); sp++) {
916 c = (*sp > '9') ? (TOLOWER(*sp) - 'a' + 10) : (*sp - '0');
917 if ((c < 0) || (c >= base)) {
918 printk("STALLION: invalid argument %s\n", str);
922 val = (val * base) + c;
927 /*****************************************************************************/
930 * Parse the supplied argument string, into the board conf struct.
933 static int stli_parsebrd(stlconf_t *confp, char **argp)
938 if (argp[0] == NULL || *argp[0] == 0)
941 for (sp = argp[0], i = 0; ((*sp != 0) && (i < 25)); sp++, i++)
944 for (i = 0; i < ARRAY_SIZE(stli_brdstr); i++) {
945 if (strcmp(stli_brdstr[i].name, argp[0]) == 0)
948 if (i == ARRAY_SIZE(stli_brdstr)) {
949 printk("STALLION: unknown board name, %s?\n", argp[0]);
953 confp->brdtype = stli_brdstr[i].type;
954 if (argp[1] != NULL && *argp[1] != 0)
955 confp->ioaddr1 = stli_atol(argp[1]);
956 if (argp[2] != NULL && *argp[2] != 0)
957 confp->memaddr = stli_atol(argp[2]);
963 /*****************************************************************************/
965 static int stli_open(struct tty_struct *tty, struct file *filp)
969 unsigned int minordev;
970 int brdnr, portnr, rc;
972 minordev = tty->index;
973 brdnr = MINOR2BRD(minordev);
974 if (brdnr >= stli_nrbrds)
976 brdp = stli_brds[brdnr];
979 if ((brdp->state & BST_STARTED) == 0)
981 portnr = MINOR2PORT(minordev);
982 if ((portnr < 0) || (portnr > brdp->nrports))
985 portp = brdp->ports[portnr];
988 if (portp->devnr < 1)
993 * Check if this port is in the middle of closing. If so then wait
994 * until it is closed then return error status based on flag settings.
995 * The sleep here does not need interrupt protection since the wakeup
996 * for it is done with the same context.
998 if (portp->flags & ASYNC_CLOSING) {
999 interruptible_sleep_on(&portp->close_wait);
1000 if (portp->flags & ASYNC_HUP_NOTIFY)
1002 return -ERESTARTSYS;
1006 * On the first open of the device setup the port hardware, and
1007 * initialize the per port data structure. Since initializing the port
1008 * requires several commands to the board we will need to wait for any
1009 * other open that is already initializing the port.
1012 tty->driver_data = portp;
1015 wait_event_interruptible(portp->raw_wait,
1016 !test_bit(ST_INITIALIZING, &portp->state));
1017 if (signal_pending(current))
1018 return -ERESTARTSYS;
1020 if ((portp->flags & ASYNC_INITIALIZED) == 0) {
1021 set_bit(ST_INITIALIZING, &portp->state);
1022 if ((rc = stli_initopen(brdp, portp)) >= 0) {
1023 portp->flags |= ASYNC_INITIALIZED;
1024 clear_bit(TTY_IO_ERROR, &tty->flags);
1026 clear_bit(ST_INITIALIZING, &portp->state);
1027 wake_up_interruptible(&portp->raw_wait);
1033 * Check if this port is in the middle of closing. If so then wait
1034 * until it is closed then return error status, based on flag settings.
1035 * The sleep here does not need interrupt protection since the wakeup
1036 * for it is done with the same context.
1038 if (portp->flags & ASYNC_CLOSING) {
1039 interruptible_sleep_on(&portp->close_wait);
1040 if (portp->flags & ASYNC_HUP_NOTIFY)
1042 return -ERESTARTSYS;
1046 * Based on type of open being done check if it can overlap with any
1047 * previous opens still in effect. If we are a normal serial device
1048 * then also we might have to wait for carrier.
1050 if (!(filp->f_flags & O_NONBLOCK)) {
1051 if ((rc = stli_waitcarrier(brdp, portp, filp)) != 0)
1054 portp->flags |= ASYNC_NORMAL_ACTIVE;
1058 /*****************************************************************************/
1060 static void stli_close(struct tty_struct *tty, struct file *filp)
1064 unsigned long flags;
1066 portp = tty->driver_data;
1070 spin_lock_irqsave(&stli_lock, flags);
1071 if (tty_hung_up_p(filp)) {
1072 spin_unlock_irqrestore(&stli_lock, flags);
1075 if ((tty->count == 1) && (portp->refcount != 1))
1076 portp->refcount = 1;
1077 if (portp->refcount-- > 1) {
1078 spin_unlock_irqrestore(&stli_lock, flags);
1082 portp->flags |= ASYNC_CLOSING;
1085 * May want to wait for data to drain before closing. The BUSY flag
1086 * keeps track of whether we are still transmitting or not. It is
1087 * updated by messages from the slave - indicating when all chars
1088 * really have drained.
1090 if (tty == stli_txcooktty)
1091 stli_flushchars(tty);
1093 spin_unlock_irqrestore(&stli_lock, flags);
1095 if (portp->closing_wait != ASYNC_CLOSING_WAIT_NONE)
1096 tty_wait_until_sent(tty, portp->closing_wait);
1098 portp->flags &= ~ASYNC_INITIALIZED;
1099 brdp = stli_brds[portp->brdnr];
1100 stli_rawclose(brdp, portp, 0, 0);
1101 if (tty->termios->c_cflag & HUPCL) {
1102 stli_mkasysigs(&portp->asig, 0, 0);
1103 if (test_bit(ST_CMDING, &portp->state))
1104 set_bit(ST_DOSIGS, &portp->state);
1106 stli_sendcmd(brdp, portp, A_SETSIGNALS, &portp->asig,
1107 sizeof(asysigs_t), 0);
1109 clear_bit(ST_TXBUSY, &portp->state);
1110 clear_bit(ST_RXSTOP, &portp->state);
1111 set_bit(TTY_IO_ERROR, &tty->flags);
1112 if (tty->ldisc.flush_buffer)
1113 (tty->ldisc.flush_buffer)(tty);
1114 set_bit(ST_DOFLUSHRX, &portp->state);
1115 stli_flushbuffer(tty);
1120 if (portp->openwaitcnt) {
1121 if (portp->close_delay)
1122 msleep_interruptible(jiffies_to_msecs(portp->close_delay));
1123 wake_up_interruptible(&portp->open_wait);
1126 portp->flags &= ~(ASYNC_NORMAL_ACTIVE|ASYNC_CLOSING);
1127 wake_up_interruptible(&portp->close_wait);
1130 /*****************************************************************************/
1133 * Carry out first open operations on a port. This involves a number of
1134 * commands to be sent to the slave. We need to open the port, set the
1135 * notification events, set the initial port settings, get and set the
1136 * initial signal values. We sleep and wait in between each one. But
1137 * this still all happens pretty quickly.
1140 static int stli_initopen(stlibrd_t *brdp, stliport_t *portp)
1142 struct tty_struct *tty;
1147 if ((rc = stli_rawopen(brdp, portp, 0, 1)) < 0)
1150 memset(&nt, 0, sizeof(asynotify_t));
1151 nt.data = (DT_TXLOW | DT_TXEMPTY | DT_RXBUSY | DT_RXBREAK);
1153 if ((rc = stli_cmdwait(brdp, portp, A_SETNOTIFY, &nt,
1154 sizeof(asynotify_t), 0)) < 0)
1160 stli_mkasyport(portp, &aport, tty->termios);
1161 if ((rc = stli_cmdwait(brdp, portp, A_SETPORT, &aport,
1162 sizeof(asyport_t), 0)) < 0)
1165 set_bit(ST_GETSIGS, &portp->state);
1166 if ((rc = stli_cmdwait(brdp, portp, A_GETSIGNALS, &portp->asig,
1167 sizeof(asysigs_t), 1)) < 0)
1169 if (test_and_clear_bit(ST_GETSIGS, &portp->state))
1170 portp->sigs = stli_mktiocm(portp->asig.sigvalue);
1171 stli_mkasysigs(&portp->asig, 1, 1);
1172 if ((rc = stli_cmdwait(brdp, portp, A_SETSIGNALS, &portp->asig,
1173 sizeof(asysigs_t), 0)) < 0)
1179 /*****************************************************************************/
1182 * Send an open message to the slave. This will sleep waiting for the
1183 * acknowledgement, so must have user context. We need to co-ordinate
1184 * with close events here, since we don't want open and close events
1188 static int stli_rawopen(stlibrd_t *brdp, stliport_t *portp, unsigned long arg, int wait)
1190 cdkhdr_t __iomem *hdrp;
1191 cdkctrl_t __iomem *cp;
1192 unsigned char __iomem *bits;
1193 unsigned long flags;
1197 * Send a message to the slave to open this port.
1201 * Slave is already closing this port. This can happen if a hangup
1202 * occurs on this port. So we must wait until it is complete. The
1203 * order of opens and closes may not be preserved across shared
1204 * memory, so we must wait until it is complete.
1206 wait_event_interruptible(portp->raw_wait,
1207 !test_bit(ST_CLOSING, &portp->state));
1208 if (signal_pending(current)) {
1209 return -ERESTARTSYS;
1213 * Everything is ready now, so write the open message into shared
1214 * memory. Once the message is in set the service bits to say that
1215 * this port wants service.
1217 spin_lock_irqsave(&brd_lock, flags);
1219 cp = &((cdkasy_t __iomem *) EBRDGETMEMPTR(brdp, portp->addr))->ctrl;
1220 writel(arg, &cp->openarg);
1221 writeb(1, &cp->open);
1222 hdrp = (cdkhdr_t __iomem *) EBRDGETMEMPTR(brdp, CDK_CDKADDR);
1223 bits = ((unsigned char __iomem *) hdrp) + brdp->slaveoffset +
1225 writeb(readb(bits) | portp->portbit, bits);
1229 spin_unlock_irqrestore(&brd_lock, flags);
1234 * Slave is in action, so now we must wait for the open acknowledgment
1238 set_bit(ST_OPENING, &portp->state);
1239 spin_unlock_irqrestore(&brd_lock, flags);
1241 wait_event_interruptible(portp->raw_wait,
1242 !test_bit(ST_OPENING, &portp->state));
1243 if (signal_pending(current))
1246 if ((rc == 0) && (portp->rc != 0))
1251 /*****************************************************************************/
1254 * Send a close message to the slave. Normally this will sleep waiting
1255 * for the acknowledgement, but if wait parameter is 0 it will not. If
1256 * wait is true then must have user context (to sleep).
1259 static int stli_rawclose(stlibrd_t *brdp, stliport_t *portp, unsigned long arg, int wait)
1261 cdkhdr_t __iomem *hdrp;
1262 cdkctrl_t __iomem *cp;
1263 unsigned char __iomem *bits;
1264 unsigned long flags;
1268 * Slave is already closing this port. This can happen if a hangup
1269 * occurs on this port.
1272 wait_event_interruptible(portp->raw_wait,
1273 !test_bit(ST_CLOSING, &portp->state));
1274 if (signal_pending(current)) {
1275 return -ERESTARTSYS;
1280 * Write the close command into shared memory.
1282 spin_lock_irqsave(&brd_lock, flags);
1284 cp = &((cdkasy_t __iomem *) EBRDGETMEMPTR(brdp, portp->addr))->ctrl;
1285 writel(arg, &cp->closearg);
1286 writeb(1, &cp->close);
1287 hdrp = (cdkhdr_t __iomem *) EBRDGETMEMPTR(brdp, CDK_CDKADDR);
1288 bits = ((unsigned char __iomem *) hdrp) + brdp->slaveoffset +
1290 writeb(readb(bits) |portp->portbit, bits);
1293 set_bit(ST_CLOSING, &portp->state);
1294 spin_unlock_irqrestore(&brd_lock, flags);
1300 * Slave is in action, so now we must wait for the open acknowledgment
1304 wait_event_interruptible(portp->raw_wait,
1305 !test_bit(ST_CLOSING, &portp->state));
1306 if (signal_pending(current))
1309 if ((rc == 0) && (portp->rc != 0))
1314 /*****************************************************************************/
1317 * Send a command to the slave and wait for the response. This must
1318 * have user context (it sleeps). This routine is generic in that it
1319 * can send any type of command. Its purpose is to wait for that command
1320 * to complete (as opposed to initiating the command then returning).
1323 static int stli_cmdwait(stlibrd_t *brdp, stliport_t *portp, unsigned long cmd, void *arg, int size, int copyback)
1325 wait_event_interruptible(portp->raw_wait,
1326 !test_bit(ST_CMDING, &portp->state));
1327 if (signal_pending(current))
1328 return -ERESTARTSYS;
1330 stli_sendcmd(brdp, portp, cmd, arg, size, copyback);
1332 wait_event_interruptible(portp->raw_wait,
1333 !test_bit(ST_CMDING, &portp->state));
1334 if (signal_pending(current))
1335 return -ERESTARTSYS;
1342 /*****************************************************************************/
1345 * Send the termios settings for this port to the slave. This sleeps
1346 * waiting for the command to complete - so must have user context.
1349 static int stli_setport(stliport_t *portp)
1356 if (portp->tty == NULL)
1358 if (portp->brdnr < 0 && portp->brdnr >= stli_nrbrds)
1360 brdp = stli_brds[portp->brdnr];
1364 stli_mkasyport(portp, &aport, portp->tty->termios);
1365 return(stli_cmdwait(brdp, portp, A_SETPORT, &aport, sizeof(asyport_t), 0));
1368 /*****************************************************************************/
1371 * Possibly need to wait for carrier (DCD signal) to come high. Say
1372 * maybe because if we are clocal then we don't need to wait...
1375 static int stli_waitcarrier(stlibrd_t *brdp, stliport_t *portp, struct file *filp)
1377 unsigned long flags;
1383 if (portp->tty->termios->c_cflag & CLOCAL)
1386 spin_lock_irqsave(&stli_lock, flags);
1387 portp->openwaitcnt++;
1388 if (! tty_hung_up_p(filp))
1390 spin_unlock_irqrestore(&stli_lock, flags);
1393 stli_mkasysigs(&portp->asig, 1, 1);
1394 if ((rc = stli_cmdwait(brdp, portp, A_SETSIGNALS,
1395 &portp->asig, sizeof(asysigs_t), 0)) < 0)
1397 if (tty_hung_up_p(filp) ||
1398 ((portp->flags & ASYNC_INITIALIZED) == 0)) {
1399 if (portp->flags & ASYNC_HUP_NOTIFY)
1405 if (((portp->flags & ASYNC_CLOSING) == 0) &&
1406 (doclocal || (portp->sigs & TIOCM_CD))) {
1409 if (signal_pending(current)) {
1413 interruptible_sleep_on(&portp->open_wait);
1416 spin_lock_irqsave(&stli_lock, flags);
1417 if (! tty_hung_up_p(filp))
1419 portp->openwaitcnt--;
1420 spin_unlock_irqrestore(&stli_lock, flags);
1425 /*****************************************************************************/
1428 * Write routine. Take the data and put it in the shared memory ring
1429 * queue. If port is not already sending chars then need to mark the
1430 * service bits for this port.
1433 static int stli_write(struct tty_struct *tty, const unsigned char *buf, int count)
1435 cdkasy_t __iomem *ap;
1436 cdkhdr_t __iomem *hdrp;
1437 unsigned char __iomem *bits;
1438 unsigned char __iomem *shbuf;
1439 unsigned char *chbuf;
1442 unsigned int len, stlen, head, tail, size;
1443 unsigned long flags;
1445 if (tty == stli_txcooktty)
1446 stli_flushchars(tty);
1447 portp = tty->driver_data;
1450 if ((portp->brdnr < 0) || (portp->brdnr >= stli_nrbrds))
1452 brdp = stli_brds[portp->brdnr];
1455 chbuf = (unsigned char *) buf;
1458 * All data is now local, shove as much as possible into shared memory.
1460 spin_lock_irqsave(&brd_lock, flags);
1462 ap = (cdkasy_t __iomem *) EBRDGETMEMPTR(brdp, portp->addr);
1463 head = (unsigned int) readw(&ap->txq.head);
1464 tail = (unsigned int) readw(&ap->txq.tail);
1465 if (tail != ((unsigned int) readw(&ap->txq.tail)))
1466 tail = (unsigned int) readw(&ap->txq.tail);
1467 size = portp->txsize;
1469 len = size - (head - tail) - 1;
1470 stlen = size - head;
1472 len = tail - head - 1;
1476 len = MIN(len, count);
1478 shbuf = (char __iomem *) EBRDGETMEMPTR(brdp, portp->txoffset);
1481 stlen = MIN(len, stlen);
1482 memcpy_toio(shbuf + head, chbuf, stlen);
1493 ap = (cdkasy_t __iomem *) EBRDGETMEMPTR(brdp, portp->addr);
1494 writew(head, &ap->txq.head);
1495 if (test_bit(ST_TXBUSY, &portp->state)) {
1496 if (readl(&ap->changed.data) & DT_TXEMPTY)
1497 writel(readl(&ap->changed.data) & ~DT_TXEMPTY, &ap->changed.data);
1499 hdrp = (cdkhdr_t __iomem *) EBRDGETMEMPTR(brdp, CDK_CDKADDR);
1500 bits = ((unsigned char __iomem *) hdrp) + brdp->slaveoffset +
1502 writeb(readb(bits) | portp->portbit, bits);
1503 set_bit(ST_TXBUSY, &portp->state);
1505 spin_unlock_irqrestore(&brd_lock, flags);
1510 /*****************************************************************************/
1513 * Output a single character. We put it into a temporary local buffer
1514 * (for speed) then write out that buffer when the flushchars routine
1515 * is called. There is a safety catch here so that if some other port
1516 * writes chars before the current buffer has been, then we write them
1517 * first them do the new ports.
1520 static void stli_putchar(struct tty_struct *tty, unsigned char ch)
1522 if (tty != stli_txcooktty) {
1523 if (stli_txcooktty != NULL)
1524 stli_flushchars(stli_txcooktty);
1525 stli_txcooktty = tty;
1528 stli_txcookbuf[stli_txcooksize++] = ch;
1531 /*****************************************************************************/
1534 * Transfer characters from the local TX cooking buffer to the board.
1535 * We sort of ignore the tty that gets passed in here. We rely on the
1536 * info stored with the TX cook buffer to tell us which port to flush
1537 * the data on. In any case we clean out the TX cook buffer, for re-use
1541 static void stli_flushchars(struct tty_struct *tty)
1543 cdkhdr_t __iomem *hdrp;
1544 unsigned char __iomem *bits;
1545 cdkasy_t __iomem *ap;
1546 struct tty_struct *cooktty;
1549 unsigned int len, stlen, head, tail, size, count, cooksize;
1551 unsigned char __iomem *shbuf;
1552 unsigned long flags;
1554 cooksize = stli_txcooksize;
1555 cooktty = stli_txcooktty;
1556 stli_txcooksize = 0;
1557 stli_txcookrealsize = 0;
1558 stli_txcooktty = NULL;
1562 if (cooktty == NULL)
1569 portp = tty->driver_data;
1572 if ((portp->brdnr < 0) || (portp->brdnr >= stli_nrbrds))
1574 brdp = stli_brds[portp->brdnr];
1578 spin_lock_irqsave(&brd_lock, flags);
1581 ap = (cdkasy_t __iomem *) EBRDGETMEMPTR(brdp, portp->addr);
1582 head = (unsigned int) readw(&ap->txq.head);
1583 tail = (unsigned int) readw(&ap->txq.tail);
1584 if (tail != ((unsigned int) readw(&ap->txq.tail)))
1585 tail = (unsigned int) readw(&ap->txq.tail);
1586 size = portp->txsize;
1588 len = size - (head - tail) - 1;
1589 stlen = size - head;
1591 len = tail - head - 1;
1595 len = MIN(len, cooksize);
1597 shbuf = (char *) EBRDGETMEMPTR(brdp, portp->txoffset);
1598 buf = stli_txcookbuf;
1601 stlen = MIN(len, stlen);
1602 memcpy_toio(shbuf + head, buf, stlen);
1613 ap = (cdkasy_t __iomem *) EBRDGETMEMPTR(brdp, portp->addr);
1614 writew(head, &ap->txq.head);
1616 if (test_bit(ST_TXBUSY, &portp->state)) {
1617 if (readl(&ap->changed.data) & DT_TXEMPTY)
1618 writel(readl(&ap->changed.data) & ~DT_TXEMPTY, &ap->changed.data);
1620 hdrp = (cdkhdr_t __iomem *) EBRDGETMEMPTR(brdp, CDK_CDKADDR);
1621 bits = ((unsigned char __iomem *) hdrp) + brdp->slaveoffset +
1623 writeb(readb(bits) | portp->portbit, bits);
1624 set_bit(ST_TXBUSY, &portp->state);
1627 spin_unlock_irqrestore(&brd_lock, flags);
1630 /*****************************************************************************/
1632 static int stli_writeroom(struct tty_struct *tty)
1634 cdkasyrq_t __iomem *rp;
1637 unsigned int head, tail, len;
1638 unsigned long flags;
1640 if (tty == stli_txcooktty) {
1641 if (stli_txcookrealsize != 0) {
1642 len = stli_txcookrealsize - stli_txcooksize;
1647 portp = tty->driver_data;
1650 if ((portp->brdnr < 0) || (portp->brdnr >= stli_nrbrds))
1652 brdp = stli_brds[portp->brdnr];
1656 spin_lock_irqsave(&brd_lock, flags);
1658 rp = &((cdkasy_t __iomem *) EBRDGETMEMPTR(brdp, portp->addr))->txq;
1659 head = (unsigned int) readw(&rp->head);
1660 tail = (unsigned int) readw(&rp->tail);
1661 if (tail != ((unsigned int) readw(&rp->tail)))
1662 tail = (unsigned int) readw(&rp->tail);
1663 len = (head >= tail) ? (portp->txsize - (head - tail)) : (tail - head);
1666 spin_unlock_irqrestore(&brd_lock, flags);
1668 if (tty == stli_txcooktty) {
1669 stli_txcookrealsize = len;
1670 len -= stli_txcooksize;
1675 /*****************************************************************************/
1678 * Return the number of characters in the transmit buffer. Normally we
1679 * will return the number of chars in the shared memory ring queue.
1680 * We need to kludge around the case where the shared memory buffer is
1681 * empty but not all characters have drained yet, for this case just
1682 * return that there is 1 character in the buffer!
1685 static int stli_charsinbuffer(struct tty_struct *tty)
1687 cdkasyrq_t __iomem *rp;
1690 unsigned int head, tail, len;
1691 unsigned long flags;
1693 if (tty == stli_txcooktty)
1694 stli_flushchars(tty);
1695 portp = tty->driver_data;
1698 if ((portp->brdnr < 0) || (portp->brdnr >= stli_nrbrds))
1700 brdp = stli_brds[portp->brdnr];
1704 spin_lock_irqsave(&brd_lock, flags);
1706 rp = &((cdkasy_t __iomem *) EBRDGETMEMPTR(brdp, portp->addr))->txq;
1707 head = (unsigned int) readw(&rp->head);
1708 tail = (unsigned int) readw(&rp->tail);
1709 if (tail != ((unsigned int) readw(&rp->tail)))
1710 tail = (unsigned int) readw(&rp->tail);
1711 len = (head >= tail) ? (head - tail) : (portp->txsize - (tail - head));
1712 if ((len == 0) && test_bit(ST_TXBUSY, &portp->state))
1715 spin_unlock_irqrestore(&brd_lock, flags);
1720 /*****************************************************************************/
1723 * Generate the serial struct info.
1726 static int stli_getserial(stliport_t *portp, struct serial_struct __user *sp)
1728 struct serial_struct sio;
1731 memset(&sio, 0, sizeof(struct serial_struct));
1732 sio.type = PORT_UNKNOWN;
1733 sio.line = portp->portnr;
1735 sio.flags = portp->flags;
1736 sio.baud_base = portp->baud_base;
1737 sio.close_delay = portp->close_delay;
1738 sio.closing_wait = portp->closing_wait;
1739 sio.custom_divisor = portp->custom_divisor;
1740 sio.xmit_fifo_size = 0;
1743 brdp = stli_brds[portp->brdnr];
1745 sio.port = brdp->iobase;
1747 return copy_to_user(sp, &sio, sizeof(struct serial_struct)) ?
1751 /*****************************************************************************/
1754 * Set port according to the serial struct info.
1755 * At this point we do not do any auto-configure stuff, so we will
1756 * just quietly ignore any requests to change irq, etc.
1759 static int stli_setserial(stliport_t *portp, struct serial_struct __user *sp)
1761 struct serial_struct sio;
1764 if (copy_from_user(&sio, sp, sizeof(struct serial_struct)))
1766 if (!capable(CAP_SYS_ADMIN)) {
1767 if ((sio.baud_base != portp->baud_base) ||
1768 (sio.close_delay != portp->close_delay) ||
1769 ((sio.flags & ~ASYNC_USR_MASK) !=
1770 (portp->flags & ~ASYNC_USR_MASK)))
1774 portp->flags = (portp->flags & ~ASYNC_USR_MASK) |
1775 (sio.flags & ASYNC_USR_MASK);
1776 portp->baud_base = sio.baud_base;
1777 portp->close_delay = sio.close_delay;
1778 portp->closing_wait = sio.closing_wait;
1779 portp->custom_divisor = sio.custom_divisor;
1781 if ((rc = stli_setport(portp)) < 0)
1786 /*****************************************************************************/
1788 static int stli_tiocmget(struct tty_struct *tty, struct file *file)
1790 stliport_t *portp = tty->driver_data;
1796 if (portp->brdnr < 0 || portp->brdnr >= stli_nrbrds)
1798 brdp = stli_brds[portp->brdnr];
1801 if (tty->flags & (1 << TTY_IO_ERROR))
1804 if ((rc = stli_cmdwait(brdp, portp, A_GETSIGNALS,
1805 &portp->asig, sizeof(asysigs_t), 1)) < 0)
1808 return stli_mktiocm(portp->asig.sigvalue);
1811 static int stli_tiocmset(struct tty_struct *tty, struct file *file,
1812 unsigned int set, unsigned int clear)
1814 stliport_t *portp = tty->driver_data;
1816 int rts = -1, dtr = -1;
1820 if (portp->brdnr < 0 || portp->brdnr >= stli_nrbrds)
1822 brdp = stli_brds[portp->brdnr];
1825 if (tty->flags & (1 << TTY_IO_ERROR))
1828 if (set & TIOCM_RTS)
1830 if (set & TIOCM_DTR)
1832 if (clear & TIOCM_RTS)
1834 if (clear & TIOCM_DTR)
1837 stli_mkasysigs(&portp->asig, dtr, rts);
1839 return stli_cmdwait(brdp, portp, A_SETSIGNALS, &portp->asig,
1840 sizeof(asysigs_t), 0);
1843 static int stli_ioctl(struct tty_struct *tty, struct file *file, unsigned int cmd, unsigned long arg)
1849 void __user *argp = (void __user *)arg;
1851 portp = tty->driver_data;
1854 if (portp->brdnr < 0 || portp->brdnr >= stli_nrbrds)
1856 brdp = stli_brds[portp->brdnr];
1860 if ((cmd != TIOCGSERIAL) && (cmd != TIOCSSERIAL) &&
1861 (cmd != COM_GETPORTSTATS) && (cmd != COM_CLRPORTSTATS)) {
1862 if (tty->flags & (1 << TTY_IO_ERROR))
1870 rc = put_user(((tty->termios->c_cflag & CLOCAL) ? 1 : 0),
1871 (unsigned __user *) arg);
1874 if ((rc = get_user(ival, (unsigned __user *) arg)) == 0)
1875 tty->termios->c_cflag =
1876 (tty->termios->c_cflag & ~CLOCAL) |
1877 (ival ? CLOCAL : 0);
1880 rc = stli_getserial(portp, argp);
1883 rc = stli_setserial(portp, argp);
1886 rc = put_user(portp->pflag, (unsigned __user *)argp);
1889 if ((rc = get_user(portp->pflag, (unsigned __user *)argp)) == 0)
1890 stli_setport(portp);
1892 case COM_GETPORTSTATS:
1893 rc = stli_getportstats(portp, argp);
1895 case COM_CLRPORTSTATS:
1896 rc = stli_clrportstats(portp, argp);
1902 case TIOCSERGSTRUCT:
1903 case TIOCSERGETMULTI:
1904 case TIOCSERSETMULTI:
1913 /*****************************************************************************/
1916 * This routine assumes that we have user context and can sleep.
1917 * Looks like it is true for the current ttys implementation..!!
1920 static void stli_settermios(struct tty_struct *tty, struct termios *old)
1924 struct termios *tiosp;
1929 portp = tty->driver_data;
1932 if (portp->brdnr < 0 || portp->brdnr >= stli_nrbrds)
1934 brdp = stli_brds[portp->brdnr];
1938 tiosp = tty->termios;
1939 if ((tiosp->c_cflag == old->c_cflag) &&
1940 (tiosp->c_iflag == old->c_iflag))
1943 stli_mkasyport(portp, &aport, tiosp);
1944 stli_cmdwait(brdp, portp, A_SETPORT, &aport, sizeof(asyport_t), 0);
1945 stli_mkasysigs(&portp->asig, ((tiosp->c_cflag & CBAUD) ? 1 : 0), -1);
1946 stli_cmdwait(brdp, portp, A_SETSIGNALS, &portp->asig,
1947 sizeof(asysigs_t), 0);
1948 if ((old->c_cflag & CRTSCTS) && ((tiosp->c_cflag & CRTSCTS) == 0))
1949 tty->hw_stopped = 0;
1950 if (((old->c_cflag & CLOCAL) == 0) && (tiosp->c_cflag & CLOCAL))
1951 wake_up_interruptible(&portp->open_wait);
1954 /*****************************************************************************/
1957 * Attempt to flow control who ever is sending us data. We won't really
1958 * do any flow control action here. We can't directly, and even if we
1959 * wanted to we would have to send a command to the slave. The slave
1960 * knows how to flow control, and will do so when its buffers reach its
1961 * internal high water marks. So what we will do is set a local state
1962 * bit that will stop us sending any RX data up from the poll routine
1963 * (which is the place where RX data from the slave is handled).
1966 static void stli_throttle(struct tty_struct *tty)
1968 stliport_t *portp = tty->driver_data;
1971 set_bit(ST_RXSTOP, &portp->state);
1974 /*****************************************************************************/
1977 * Unflow control the device sending us data... That means that all
1978 * we have to do is clear the RXSTOP state bit. The next poll call
1979 * will then be able to pass the RX data back up.
1982 static void stli_unthrottle(struct tty_struct *tty)
1984 stliport_t *portp = tty->driver_data;
1987 clear_bit(ST_RXSTOP, &portp->state);
1990 /*****************************************************************************/
1993 * Stop the transmitter.
1996 static void stli_stop(struct tty_struct *tty)
2000 /*****************************************************************************/
2003 * Start the transmitter again.
2006 static void stli_start(struct tty_struct *tty)
2010 /*****************************************************************************/
2013 * Scheduler called hang up routine. This is called from the scheduler,
2014 * not direct from the driver "poll" routine. We can't call it there
2015 * since the real local hangup code will enable/disable the board and
2016 * other things that we can't do while handling the poll. Much easier
2017 * to deal with it some time later (don't really care when, hangups
2018 * aren't that time critical).
2021 static void stli_dohangup(void *arg)
2023 stliport_t *portp = (stliport_t *) arg;
2024 if (portp->tty != NULL) {
2025 tty_hangup(portp->tty);
2029 /*****************************************************************************/
2032 * Hangup this port. This is pretty much like closing the port, only
2033 * a little more brutal. No waiting for data to drain. Shutdown the
2034 * port and maybe drop signals. This is rather tricky really. We want
2035 * to close the port as well.
2038 static void stli_hangup(struct tty_struct *tty)
2042 unsigned long flags;
2044 portp = tty->driver_data;
2047 if (portp->brdnr < 0 || portp->brdnr >= stli_nrbrds)
2049 brdp = stli_brds[portp->brdnr];
2053 portp->flags &= ~ASYNC_INITIALIZED;
2055 if (!test_bit(ST_CLOSING, &portp->state))
2056 stli_rawclose(brdp, portp, 0, 0);
2058 spin_lock_irqsave(&stli_lock, flags);
2059 if (tty->termios->c_cflag & HUPCL) {
2060 stli_mkasysigs(&portp->asig, 0, 0);
2061 if (test_bit(ST_CMDING, &portp->state)) {
2062 set_bit(ST_DOSIGS, &portp->state);
2063 set_bit(ST_DOFLUSHTX, &portp->state);
2064 set_bit(ST_DOFLUSHRX, &portp->state);
2066 stli_sendcmd(brdp, portp, A_SETSIGNALSF,
2067 &portp->asig, sizeof(asysigs_t), 0);
2071 clear_bit(ST_TXBUSY, &portp->state);
2072 clear_bit(ST_RXSTOP, &portp->state);
2073 set_bit(TTY_IO_ERROR, &tty->flags);
2075 portp->flags &= ~ASYNC_NORMAL_ACTIVE;
2076 portp->refcount = 0;
2077 spin_unlock_irqrestore(&stli_lock, flags);
2079 wake_up_interruptible(&portp->open_wait);
2082 /*****************************************************************************/
2085 * Flush characters from the lower buffer. We may not have user context
2086 * so we cannot sleep waiting for it to complete. Also we need to check
2087 * if there is chars for this port in the TX cook buffer, and flush them
2091 static void stli_flushbuffer(struct tty_struct *tty)
2095 unsigned long ftype, flags;
2097 portp = tty->driver_data;
2100 if (portp->brdnr < 0 || portp->brdnr >= stli_nrbrds)
2102 brdp = stli_brds[portp->brdnr];
2106 spin_lock_irqsave(&brd_lock, flags);
2107 if (tty == stli_txcooktty) {
2108 stli_txcooktty = NULL;
2109 stli_txcooksize = 0;
2110 stli_txcookrealsize = 0;
2112 if (test_bit(ST_CMDING, &portp->state)) {
2113 set_bit(ST_DOFLUSHTX, &portp->state);
2116 if (test_bit(ST_DOFLUSHRX, &portp->state)) {
2118 clear_bit(ST_DOFLUSHRX, &portp->state);
2120 __stli_sendcmd(brdp, portp, A_FLUSH, &ftype, sizeof(u32), 0);
2122 spin_unlock_irqrestore(&brd_lock, flags);
2126 /*****************************************************************************/
2128 static void stli_breakctl(struct tty_struct *tty, int state)
2134 portp = tty->driver_data;
2137 if (portp->brdnr < 0 || portp->brdnr >= stli_nrbrds)
2139 brdp = stli_brds[portp->brdnr];
2143 arg = (state == -1) ? BREAKON : BREAKOFF;
2144 stli_cmdwait(brdp, portp, A_BREAK, &arg, sizeof(long), 0);
2147 /*****************************************************************************/
2149 static void stli_waituntilsent(struct tty_struct *tty, int timeout)
2156 portp = tty->driver_data;
2162 tend = jiffies + timeout;
2164 while (test_bit(ST_TXBUSY, &portp->state)) {
2165 if (signal_pending(current))
2167 msleep_interruptible(20);
2168 if (time_after_eq(jiffies, tend))
2173 /*****************************************************************************/
2175 static void stli_sendxchar(struct tty_struct *tty, char ch)
2181 portp = tty->driver_data;
2184 if (portp->brdnr < 0 || portp->brdnr >= stli_nrbrds)
2186 brdp = stli_brds[portp->brdnr];
2190 memset(&actrl, 0, sizeof(asyctrl_t));
2191 if (ch == STOP_CHAR(tty)) {
2192 actrl.rxctrl = CT_STOPFLOW;
2193 } else if (ch == START_CHAR(tty)) {
2194 actrl.rxctrl = CT_STARTFLOW;
2196 actrl.txctrl = CT_SENDCHR;
2199 stli_cmdwait(brdp, portp, A_PORTCTRL, &actrl, sizeof(asyctrl_t), 0);
2202 /*****************************************************************************/
2207 * Format info for a specified port. The line is deliberately limited
2208 * to 80 characters. (If it is too long it will be truncated, if too
2209 * short then padded with spaces).
2212 static int stli_portinfo(stlibrd_t *brdp, stliport_t *portp, int portnr, char *pos)
2217 rc = stli_portcmdstats(portp);
2220 if (brdp->state & BST_STARTED) {
2221 switch (stli_comstats.hwid) {
2222 case 0: uart = "2681"; break;
2223 case 1: uart = "SC26198"; break;
2224 default:uart = "CD1400"; break;
2229 sp += sprintf(sp, "%d: uart:%s ", portnr, uart);
2231 if ((brdp->state & BST_STARTED) && (rc >= 0)) {
2232 sp += sprintf(sp, "tx:%d rx:%d", (int) stli_comstats.txtotal,
2233 (int) stli_comstats.rxtotal);
2235 if (stli_comstats.rxframing)
2236 sp += sprintf(sp, " fe:%d",
2237 (int) stli_comstats.rxframing);
2238 if (stli_comstats.rxparity)
2239 sp += sprintf(sp, " pe:%d",
2240 (int) stli_comstats.rxparity);
2241 if (stli_comstats.rxbreaks)
2242 sp += sprintf(sp, " brk:%d",
2243 (int) stli_comstats.rxbreaks);
2244 if (stli_comstats.rxoverrun)
2245 sp += sprintf(sp, " oe:%d",
2246 (int) stli_comstats.rxoverrun);
2248 cnt = sprintf(sp, "%s%s%s%s%s ",
2249 (stli_comstats.signals & TIOCM_RTS) ? "|RTS" : "",
2250 (stli_comstats.signals & TIOCM_CTS) ? "|CTS" : "",
2251 (stli_comstats.signals & TIOCM_DTR) ? "|DTR" : "",
2252 (stli_comstats.signals & TIOCM_CD) ? "|DCD" : "",
2253 (stli_comstats.signals & TIOCM_DSR) ? "|DSR" : "");
2258 for (cnt = (sp - pos); (cnt < (MAXLINE - 1)); cnt++)
2261 pos[(MAXLINE - 2)] = '+';
2262 pos[(MAXLINE - 1)] = '\n';
2267 /*****************************************************************************/
2270 * Port info, read from the /proc file system.
2273 static int stli_readproc(char *page, char **start, off_t off, int count, int *eof, void *data)
2277 int brdnr, portnr, totalport;
2286 pos += sprintf(pos, "%s: version %s", stli_drvtitle,
2288 while (pos < (page + MAXLINE - 1))
2295 * We scan through for each board, panel and port. The offset is
2296 * calculated on the fly, and irrelevant ports are skipped.
2298 for (brdnr = 0; (brdnr < stli_nrbrds); brdnr++) {
2299 brdp = stli_brds[brdnr];
2302 if (brdp->state == 0)
2305 maxoff = curoff + (brdp->nrports * MAXLINE);
2306 if (off >= maxoff) {
2311 totalport = brdnr * STL_MAXPORTS;
2312 for (portnr = 0; (portnr < brdp->nrports); portnr++,
2314 portp = brdp->ports[portnr];
2317 if (off >= (curoff += MAXLINE))
2319 if ((pos - page + MAXLINE) > count)
2321 pos += stli_portinfo(brdp, portp, totalport, pos);
2332 /*****************************************************************************/
2335 * Generic send command routine. This will send a message to the slave,
2336 * of the specified type with the specified argument. Must be very
2337 * careful of data that will be copied out from shared memory -
2338 * containing command results. The command completion is all done from
2339 * a poll routine that does not have user context. Therefore you cannot
2340 * copy back directly into user space, or to the kernel stack of a
2341 * process. This routine does not sleep, so can be called from anywhere.
2343 * The caller must hold the brd_lock (see also stli_sendcmd the usual
2347 static void __stli_sendcmd(stlibrd_t *brdp, stliport_t *portp, unsigned long cmd, void *arg, int size, int copyback)
2349 cdkhdr_t __iomem *hdrp;
2350 cdkctrl_t __iomem *cp;
2351 unsigned char __iomem *bits;
2352 unsigned long flags;
2354 spin_lock_irqsave(&brd_lock, flags);
2356 if (test_bit(ST_CMDING, &portp->state)) {
2357 printk(KERN_ERR "STALLION: command already busy, cmd=%x!\n",
2359 spin_unlock_irqrestore(&brd_lock, flags);
2364 cp = &((cdkasy_t __iomem *) EBRDGETMEMPTR(brdp, portp->addr))->ctrl;
2366 memcpy_toio((void __iomem *) &(cp->args[0]), arg, size);
2369 portp->argsize = size;
2372 writel(0, &cp->status);
2373 writel(cmd, &cp->cmd);
2374 hdrp = (cdkhdr_t __iomem *) EBRDGETMEMPTR(brdp, CDK_CDKADDR);
2375 bits = ((unsigned char __iomem *) hdrp) + brdp->slaveoffset +
2377 writeb(readb(bits) | portp->portbit, bits);
2378 set_bit(ST_CMDING, &portp->state);
2380 spin_unlock_irqrestore(&brd_lock, flags);
2383 static void stli_sendcmd(stlibrd_t *brdp, stliport_t *portp, unsigned long cmd, void *arg, int size, int copyback)
2385 unsigned long flags;
2387 spin_lock_irqsave(&brd_lock, flags);
2388 __stli_sendcmd(brdp, portp, cmd, arg, size, copyback);
2389 spin_unlock_irqrestore(&brd_lock, flags);
2392 /*****************************************************************************/
2395 * Read data from shared memory. This assumes that the shared memory
2396 * is enabled and that interrupts are off. Basically we just empty out
2397 * the shared memory buffer into the tty buffer. Must be careful to
2398 * handle the case where we fill up the tty buffer, but still have
2399 * more chars to unload.
2402 static void stli_read(stlibrd_t *brdp, stliport_t *portp)
2404 cdkasyrq_t __iomem *rp;
2405 char __iomem *shbuf;
2406 struct tty_struct *tty;
2407 unsigned int head, tail, size;
2408 unsigned int len, stlen;
2410 if (test_bit(ST_RXSTOP, &portp->state))
2416 rp = &((cdkasy_t __iomem *) EBRDGETMEMPTR(brdp, portp->addr))->rxq;
2417 head = (unsigned int) readw(&rp->head);
2418 if (head != ((unsigned int) readw(&rp->head)))
2419 head = (unsigned int) readw(&rp->head);
2420 tail = (unsigned int) readw(&rp->tail);
2421 size = portp->rxsize;
2426 len = size - (tail - head);
2427 stlen = size - tail;
2430 len = tty_buffer_request_room(tty, len);
2432 shbuf = (char __iomem *) EBRDGETMEMPTR(brdp, portp->rxoffset);
2435 unsigned char *cptr;
2437 stlen = MIN(len, stlen);
2438 tty_prepare_flip_string(tty, &cptr, stlen);
2439 memcpy_fromio(cptr, shbuf + tail, stlen);
2447 rp = &((cdkasy_t __iomem *) EBRDGETMEMPTR(brdp, portp->addr))->rxq;
2448 writew(tail, &rp->tail);
2451 set_bit(ST_RXING, &portp->state);
2453 tty_schedule_flip(tty);
2456 /*****************************************************************************/
2459 * Set up and carry out any delayed commands. There is only a small set
2460 * of slave commands that can be done "off-level". So it is not too
2461 * difficult to deal with them here.
2464 static void stli_dodelaycmd(stliport_t *portp, cdkctrl_t __iomem *cp)
2468 if (test_bit(ST_DOSIGS, &portp->state)) {
2469 if (test_bit(ST_DOFLUSHTX, &portp->state) &&
2470 test_bit(ST_DOFLUSHRX, &portp->state))
2471 cmd = A_SETSIGNALSF;
2472 else if (test_bit(ST_DOFLUSHTX, &portp->state))
2473 cmd = A_SETSIGNALSFTX;
2474 else if (test_bit(ST_DOFLUSHRX, &portp->state))
2475 cmd = A_SETSIGNALSFRX;
2478 clear_bit(ST_DOFLUSHTX, &portp->state);
2479 clear_bit(ST_DOFLUSHRX, &portp->state);
2480 clear_bit(ST_DOSIGS, &portp->state);
2481 memcpy_toio((void __iomem *) &(cp->args[0]), (void *) &portp->asig,
2483 writel(0, &cp->status);
2484 writel(cmd, &cp->cmd);
2485 set_bit(ST_CMDING, &portp->state);
2486 } else if (test_bit(ST_DOFLUSHTX, &portp->state) ||
2487 test_bit(ST_DOFLUSHRX, &portp->state)) {
2488 cmd = ((test_bit(ST_DOFLUSHTX, &portp->state)) ? FLUSHTX : 0);
2489 cmd |= ((test_bit(ST_DOFLUSHRX, &portp->state)) ? FLUSHRX : 0);
2490 clear_bit(ST_DOFLUSHTX, &portp->state);
2491 clear_bit(ST_DOFLUSHRX, &portp->state);
2492 memcpy_toio((void __iomem *) &(cp->args[0]), (void *) &cmd, sizeof(int));
2493 writel(0, &cp->status);
2494 writel(A_FLUSH, &cp->cmd);
2495 set_bit(ST_CMDING, &portp->state);
2499 /*****************************************************************************/
2502 * Host command service checking. This handles commands or messages
2503 * coming from the slave to the host. Must have board shared memory
2504 * enabled and interrupts off when called. Notice that by servicing the
2505 * read data last we don't need to change the shared memory pointer
2506 * during processing (which is a slow IO operation).
2507 * Return value indicates if this port is still awaiting actions from
2508 * the slave (like open, command, or even TX data being sent). If 0
2509 * then port is still busy, otherwise no longer busy.
2512 static int stli_hostcmd(stlibrd_t *brdp, stliport_t *portp)
2514 cdkasy_t __iomem *ap;
2515 cdkctrl_t __iomem *cp;
2516 struct tty_struct *tty;
2518 unsigned long oldsigs;
2521 ap = (cdkasy_t __iomem *) EBRDGETMEMPTR(brdp, portp->addr);
2525 * Check if we are waiting for an open completion message.
2527 if (test_bit(ST_OPENING, &portp->state)) {
2528 rc = readl(&cp->openarg);
2529 if (readb(&cp->open) == 0 && rc != 0) {
2532 writel(0, &cp->openarg);
2534 clear_bit(ST_OPENING, &portp->state);
2535 wake_up_interruptible(&portp->raw_wait);
2540 * Check if we are waiting for a close completion message.
2542 if (test_bit(ST_CLOSING, &portp->state)) {
2543 rc = (int) readl(&cp->closearg);
2544 if (readb(&cp->close) == 0 && rc != 0) {
2547 writel(0, &cp->closearg);
2549 clear_bit(ST_CLOSING, &portp->state);
2550 wake_up_interruptible(&portp->raw_wait);
2555 * Check if we are waiting for a command completion message. We may
2556 * need to copy out the command results associated with this command.
2558 if (test_bit(ST_CMDING, &portp->state)) {
2559 rc = readl(&cp->status);
2560 if (readl(&cp->cmd) == 0 && rc != 0) {
2563 if (portp->argp != NULL) {
2564 memcpy_fromio(portp->argp, (void __iomem *) &(cp->args[0]),
2568 writel(0, &cp->status);
2570 clear_bit(ST_CMDING, &portp->state);
2571 stli_dodelaycmd(portp, cp);
2572 wake_up_interruptible(&portp->raw_wait);
2577 * Check for any notification messages ready. This includes lots of
2578 * different types of events - RX chars ready, RX break received,
2579 * TX data low or empty in the slave, modem signals changed state.
2588 if (nt.signal & SG_DCD) {
2589 oldsigs = portp->sigs;
2590 portp->sigs = stli_mktiocm(nt.sigvalue);
2591 clear_bit(ST_GETSIGS, &portp->state);
2592 if ((portp->sigs & TIOCM_CD) &&
2593 ((oldsigs & TIOCM_CD) == 0))
2594 wake_up_interruptible(&portp->open_wait);
2595 if ((oldsigs & TIOCM_CD) &&
2596 ((portp->sigs & TIOCM_CD) == 0)) {
2597 if (portp->flags & ASYNC_CHECK_CD) {
2599 schedule_work(&portp->tqhangup);
2604 if (nt.data & DT_TXEMPTY)
2605 clear_bit(ST_TXBUSY, &portp->state);
2606 if (nt.data & (DT_TXEMPTY | DT_TXLOW)) {
2610 wake_up_interruptible(&tty->write_wait);
2614 if ((nt.data & DT_RXBREAK) && (portp->rxmarkmsk & BRKINT)) {
2616 tty_insert_flip_char(tty, 0, TTY_BREAK);
2617 if (portp->flags & ASYNC_SAK) {
2621 tty_schedule_flip(tty);
2625 if (nt.data & DT_RXBUSY) {
2627 stli_read(brdp, portp);
2632 * It might seem odd that we are checking for more RX chars here.
2633 * But, we need to handle the case where the tty buffer was previously
2634 * filled, but we had more characters to pass up. The slave will not
2635 * send any more RX notify messages until the RX buffer has been emptied.
2636 * But it will leave the service bits on (since the buffer is not empty).
2637 * So from here we can try to process more RX chars.
2639 if ((!donerx) && test_bit(ST_RXING, &portp->state)) {
2640 clear_bit(ST_RXING, &portp->state);
2641 stli_read(brdp, portp);
2644 return((test_bit(ST_OPENING, &portp->state) ||
2645 test_bit(ST_CLOSING, &portp->state) ||
2646 test_bit(ST_CMDING, &portp->state) ||
2647 test_bit(ST_TXBUSY, &portp->state) ||
2648 test_bit(ST_RXING, &portp->state)) ? 0 : 1);
2651 /*****************************************************************************/
2654 * Service all ports on a particular board. Assumes that the boards
2655 * shared memory is enabled, and that the page pointer is pointed
2656 * at the cdk header structure.
2659 static void stli_brdpoll(stlibrd_t *brdp, cdkhdr_t __iomem *hdrp)
2662 unsigned char hostbits[(STL_MAXCHANS / 8) + 1];
2663 unsigned char slavebits[(STL_MAXCHANS / 8) + 1];
2664 unsigned char __iomem *slavep;
2665 int bitpos, bitat, bitsize;
2666 int channr, nrdevs, slavebitchange;
2668 bitsize = brdp->bitsize;
2669 nrdevs = brdp->nrdevs;
2672 * Check if slave wants any service. Basically we try to do as
2673 * little work as possible here. There are 2 levels of service
2674 * bits. So if there is nothing to do we bail early. We check
2675 * 8 service bits at a time in the inner loop, so we can bypass
2676 * the lot if none of them want service.
2678 memcpy_fromio(&hostbits[0], (((unsigned char __iomem *) hdrp) + brdp->hostoffset),
2681 memset(&slavebits[0], 0, bitsize);
2684 for (bitpos = 0; (bitpos < bitsize); bitpos++) {
2685 if (hostbits[bitpos] == 0)
2687 channr = bitpos * 8;
2688 for (bitat = 0x1; (channr < nrdevs); channr++, bitat <<= 1) {
2689 if (hostbits[bitpos] & bitat) {
2690 portp = brdp->ports[(channr - 1)];
2691 if (stli_hostcmd(brdp, portp)) {
2693 slavebits[bitpos] |= bitat;
2700 * If any of the ports are no longer busy then update them in the
2701 * slave request bits. We need to do this after, since a host port
2702 * service may initiate more slave requests.
2704 if (slavebitchange) {
2705 hdrp = (cdkhdr_t __iomem *) EBRDGETMEMPTR(brdp, CDK_CDKADDR);
2706 slavep = ((unsigned char __iomem *) hdrp) + brdp->slaveoffset;
2707 for (bitpos = 0; (bitpos < bitsize); bitpos++) {
2708 if (readb(slavebits + bitpos))
2709 writeb(readb(slavep + bitpos) & ~slavebits[bitpos], slavebits + bitpos);
2714 /*****************************************************************************/
2717 * Driver poll routine. This routine polls the boards in use and passes
2718 * messages back up to host when necessary. This is actually very
2719 * CPU efficient, since we will always have the kernel poll clock, it
2720 * adds only a few cycles when idle (since board service can be
2721 * determined very easily), but when loaded generates no interrupts
2722 * (with their expensive associated context change).
2725 static void stli_poll(unsigned long arg)
2727 cdkhdr_t __iomem *hdrp;
2731 stli_timerlist.expires = STLI_TIMEOUT;
2732 add_timer(&stli_timerlist);
2735 * Check each board and do any servicing required.
2737 for (brdnr = 0; (brdnr < stli_nrbrds); brdnr++) {
2738 brdp = stli_brds[brdnr];
2741 if ((brdp->state & BST_STARTED) == 0)
2744 spin_lock(&brd_lock);
2746 hdrp = (cdkhdr_t __iomem *) EBRDGETMEMPTR(brdp, CDK_CDKADDR);
2747 if (readb(&hdrp->hostreq))
2748 stli_brdpoll(brdp, hdrp);
2750 spin_unlock(&brd_lock);
2754 /*****************************************************************************/
2757 * Translate the termios settings into the port setting structure of
2761 static void stli_mkasyport(stliport_t *portp, asyport_t *pp, struct termios *tiosp)
2763 memset(pp, 0, sizeof(asyport_t));
2766 * Start of by setting the baud, char size, parity and stop bit info.
2768 pp->baudout = tiosp->c_cflag & CBAUD;
2769 if (pp->baudout & CBAUDEX) {
2770 pp->baudout &= ~CBAUDEX;
2771 if ((pp->baudout < 1) || (pp->baudout > 4))
2772 tiosp->c_cflag &= ~CBAUDEX;
2776 pp->baudout = stli_baudrates[pp->baudout];
2777 if ((tiosp->c_cflag & CBAUD) == B38400) {
2778 if ((portp->flags & ASYNC_SPD_MASK) == ASYNC_SPD_HI)
2779 pp->baudout = 57600;
2780 else if ((portp->flags & ASYNC_SPD_MASK) == ASYNC_SPD_VHI)
2781 pp->baudout = 115200;
2782 else if ((portp->flags & ASYNC_SPD_MASK) == ASYNC_SPD_SHI)
2783 pp->baudout = 230400;
2784 else if ((portp->flags & ASYNC_SPD_MASK) == ASYNC_SPD_WARP)
2785 pp->baudout = 460800;
2786 else if ((portp->flags & ASYNC_SPD_MASK) == ASYNC_SPD_CUST)
2787 pp->baudout = (portp->baud_base / portp->custom_divisor);
2789 if (pp->baudout > STL_MAXBAUD)
2790 pp->baudout = STL_MAXBAUD;
2791 pp->baudin = pp->baudout;
2793 switch (tiosp->c_cflag & CSIZE) {
2808 if (tiosp->c_cflag & CSTOPB)
2809 pp->stopbs = PT_STOP2;
2811 pp->stopbs = PT_STOP1;
2813 if (tiosp->c_cflag & PARENB) {
2814 if (tiosp->c_cflag & PARODD)
2815 pp->parity = PT_ODDPARITY;
2817 pp->parity = PT_EVENPARITY;
2819 pp->parity = PT_NOPARITY;
2823 * Set up any flow control options enabled.
2825 if (tiosp->c_iflag & IXON) {
2827 if (tiosp->c_iflag & IXANY)
2828 pp->flow |= F_IXANY;
2830 if (tiosp->c_cflag & CRTSCTS)
2831 pp->flow |= (F_RTSFLOW | F_CTSFLOW);
2833 pp->startin = tiosp->c_cc[VSTART];
2834 pp->stopin = tiosp->c_cc[VSTOP];
2835 pp->startout = tiosp->c_cc[VSTART];
2836 pp->stopout = tiosp->c_cc[VSTOP];
2839 * Set up the RX char marking mask with those RX error types we must
2840 * catch. We can get the slave to help us out a little here, it will
2841 * ignore parity errors and breaks for us, and mark parity errors in
2844 if (tiosp->c_iflag & IGNPAR)
2845 pp->iflag |= FI_IGNRXERRS;
2846 if (tiosp->c_iflag & IGNBRK)
2847 pp->iflag |= FI_IGNBREAK;
2849 portp->rxmarkmsk = 0;
2850 if (tiosp->c_iflag & (INPCK | PARMRK))
2851 pp->iflag |= FI_1MARKRXERRS;
2852 if (tiosp->c_iflag & BRKINT)
2853 portp->rxmarkmsk |= BRKINT;
2856 * Set up clocal processing as required.
2858 if (tiosp->c_cflag & CLOCAL)
2859 portp->flags &= ~ASYNC_CHECK_CD;
2861 portp->flags |= ASYNC_CHECK_CD;
2864 * Transfer any persistent flags into the asyport structure.
2866 pp->pflag = (portp->pflag & 0xffff);
2867 pp->vmin = (portp->pflag & P_RXIMIN) ? 1 : 0;
2868 pp->vtime = (portp->pflag & P_RXITIME) ? 1 : 0;
2869 pp->cc[1] = (portp->pflag & P_RXTHOLD) ? 1 : 0;
2872 /*****************************************************************************/
2875 * Construct a slave signals structure for setting the DTR and RTS
2876 * signals as specified.
2879 static void stli_mkasysigs(asysigs_t *sp, int dtr, int rts)
2881 memset(sp, 0, sizeof(asysigs_t));
2883 sp->signal |= SG_DTR;
2884 sp->sigvalue |= ((dtr > 0) ? SG_DTR : 0);
2887 sp->signal |= SG_RTS;
2888 sp->sigvalue |= ((rts > 0) ? SG_RTS : 0);
2892 /*****************************************************************************/
2895 * Convert the signals returned from the slave into a local TIOCM type
2896 * signals value. We keep them locally in TIOCM format.
2899 static long stli_mktiocm(unsigned long sigvalue)
2902 tiocm |= ((sigvalue & SG_DCD) ? TIOCM_CD : 0);
2903 tiocm |= ((sigvalue & SG_CTS) ? TIOCM_CTS : 0);
2904 tiocm |= ((sigvalue & SG_RI) ? TIOCM_RI : 0);
2905 tiocm |= ((sigvalue & SG_DSR) ? TIOCM_DSR : 0);
2906 tiocm |= ((sigvalue & SG_DTR) ? TIOCM_DTR : 0);
2907 tiocm |= ((sigvalue & SG_RTS) ? TIOCM_RTS : 0);
2911 /*****************************************************************************/
2914 * All panels and ports actually attached have been worked out. All
2915 * we need to do here is set up the appropriate per port data structures.
2918 static int stli_initports(stlibrd_t *brdp)
2921 int i, panelnr, panelport;
2923 for (i = 0, panelnr = 0, panelport = 0; (i < brdp->nrports); i++) {
2924 portp = kzalloc(sizeof(stliport_t), GFP_KERNEL);
2926 printk("STALLION: failed to allocate port structure\n");
2930 portp->magic = STLI_PORTMAGIC;
2932 portp->brdnr = brdp->brdnr;
2933 portp->panelnr = panelnr;
2934 portp->baud_base = STL_BAUDBASE;
2935 portp->close_delay = STL_CLOSEDELAY;
2936 portp->closing_wait = 30 * HZ;
2937 INIT_WORK(&portp->tqhangup, stli_dohangup, portp);
2938 init_waitqueue_head(&portp->open_wait);
2939 init_waitqueue_head(&portp->close_wait);
2940 init_waitqueue_head(&portp->raw_wait);
2942 if (panelport >= brdp->panels[panelnr]) {
2946 brdp->ports[i] = portp;
2952 /*****************************************************************************/
2955 * All the following routines are board specific hardware operations.
2958 static void stli_ecpinit(stlibrd_t *brdp)
2960 unsigned long memconf;
2962 outb(ECP_ATSTOP, (brdp->iobase + ECP_ATCONFR));
2964 outb(ECP_ATDISABLE, (brdp->iobase + ECP_ATCONFR));
2967 memconf = (brdp->memaddr & ECP_ATADDRMASK) >> ECP_ATADDRSHFT;
2968 outb(memconf, (brdp->iobase + ECP_ATMEMAR));
2971 /*****************************************************************************/
2973 static void stli_ecpenable(stlibrd_t *brdp)
2975 outb(ECP_ATENABLE, (brdp->iobase + ECP_ATCONFR));
2978 /*****************************************************************************/
2980 static void stli_ecpdisable(stlibrd_t *brdp)
2982 outb(ECP_ATDISABLE, (brdp->iobase + ECP_ATCONFR));
2985 /*****************************************************************************/
2987 static char *stli_ecpgetmemptr(stlibrd_t *brdp, unsigned long offset, int line)
2992 if (offset > brdp->memsize) {
2993 printk(KERN_ERR "STALLION: shared memory pointer=%x out of "
2994 "range at line=%d(%d), brd=%d\n",
2995 (int) offset, line, __LINE__, brdp->brdnr);
2999 ptr = brdp->membase + (offset % ECP_ATPAGESIZE);
3000 val = (unsigned char) (offset / ECP_ATPAGESIZE);
3002 outb(val, (brdp->iobase + ECP_ATMEMPR));
3006 /*****************************************************************************/
3008 static void stli_ecpreset(stlibrd_t *brdp)
3010 outb(ECP_ATSTOP, (brdp->iobase + ECP_ATCONFR));
3012 outb(ECP_ATDISABLE, (brdp->iobase + ECP_ATCONFR));
3016 /*****************************************************************************/
3018 static void stli_ecpintr(stlibrd_t *brdp)
3020 outb(0x1, brdp->iobase);
3023 /*****************************************************************************/
3026 * The following set of functions act on ECP EISA boards.
3029 static void stli_ecpeiinit(stlibrd_t *brdp)
3031 unsigned long memconf;
3033 outb(0x1, (brdp->iobase + ECP_EIBRDENAB));
3034 outb(ECP_EISTOP, (brdp->iobase + ECP_EICONFR));
3036 outb(ECP_EIDISABLE, (brdp->iobase + ECP_EICONFR));
3039 memconf = (brdp->memaddr & ECP_EIADDRMASKL) >> ECP_EIADDRSHFTL;
3040 outb(memconf, (brdp->iobase + ECP_EIMEMARL));
3041 memconf = (brdp->memaddr & ECP_EIADDRMASKH) >> ECP_EIADDRSHFTH;
3042 outb(memconf, (brdp->iobase + ECP_EIMEMARH));
3045 /*****************************************************************************/
3047 static void stli_ecpeienable(stlibrd_t *brdp)
3049 outb(ECP_EIENABLE, (brdp->iobase + ECP_EICONFR));
3052 /*****************************************************************************/
3054 static void stli_ecpeidisable(stlibrd_t *brdp)
3056 outb(ECP_EIDISABLE, (brdp->iobase + ECP_EICONFR));
3059 /*****************************************************************************/
3061 static char *stli_ecpeigetmemptr(stlibrd_t *brdp, unsigned long offset, int line)
3066 if (offset > brdp->memsize) {
3067 printk(KERN_ERR "STALLION: shared memory pointer=%x out of "
3068 "range at line=%d(%d), brd=%d\n",
3069 (int) offset, line, __LINE__, brdp->brdnr);
3073 ptr = brdp->membase + (offset % ECP_EIPAGESIZE);
3074 if (offset < ECP_EIPAGESIZE)
3077 val = ECP_EIENABLE | 0x40;
3079 outb(val, (brdp->iobase + ECP_EICONFR));
3083 /*****************************************************************************/
3085 static void stli_ecpeireset(stlibrd_t *brdp)
3087 outb(ECP_EISTOP, (brdp->iobase + ECP_EICONFR));
3089 outb(ECP_EIDISABLE, (brdp->iobase + ECP_EICONFR));
3093 /*****************************************************************************/
3096 * The following set of functions act on ECP MCA boards.
3099 static void stli_ecpmcenable(stlibrd_t *brdp)
3101 outb(ECP_MCENABLE, (brdp->iobase + ECP_MCCONFR));
3104 /*****************************************************************************/
3106 static void stli_ecpmcdisable(stlibrd_t *brdp)
3108 outb(ECP_MCDISABLE, (brdp->iobase + ECP_MCCONFR));
3111 /*****************************************************************************/
3113 static char *stli_ecpmcgetmemptr(stlibrd_t *brdp, unsigned long offset, int line)
3118 if (offset > brdp->memsize) {
3119 printk(KERN_ERR "STALLION: shared memory pointer=%x out of "
3120 "range at line=%d(%d), brd=%d\n",
3121 (int) offset, line, __LINE__, brdp->brdnr);
3125 ptr = brdp->membase + (offset % ECP_MCPAGESIZE);
3126 val = ((unsigned char) (offset / ECP_MCPAGESIZE)) | ECP_MCENABLE;
3128 outb(val, (brdp->iobase + ECP_MCCONFR));
3132 /*****************************************************************************/
3134 static void stli_ecpmcreset(stlibrd_t *brdp)
3136 outb(ECP_MCSTOP, (brdp->iobase + ECP_MCCONFR));
3138 outb(ECP_MCDISABLE, (brdp->iobase + ECP_MCCONFR));
3142 /*****************************************************************************/
3145 * The following set of functions act on ECP PCI boards.
3148 static void stli_ecppciinit(stlibrd_t *brdp)
3150 outb(ECP_PCISTOP, (brdp->iobase + ECP_PCICONFR));
3152 outb(0, (brdp->iobase + ECP_PCICONFR));
3156 /*****************************************************************************/
3158 static char *stli_ecppcigetmemptr(stlibrd_t *brdp, unsigned long offset, int line)
3163 if (offset > brdp->memsize) {
3164 printk(KERN_ERR "STALLION: shared memory pointer=%x out of "
3165 "range at line=%d(%d), board=%d\n",
3166 (int) offset, line, __LINE__, brdp->brdnr);
3170 ptr = brdp->membase + (offset % ECP_PCIPAGESIZE);
3171 val = (offset / ECP_PCIPAGESIZE) << 1;
3173 outb(val, (brdp->iobase + ECP_PCICONFR));
3177 /*****************************************************************************/
3179 static void stli_ecppcireset(stlibrd_t *brdp)
3181 outb(ECP_PCISTOP, (brdp->iobase + ECP_PCICONFR));
3183 outb(0, (brdp->iobase + ECP_PCICONFR));
3187 /*****************************************************************************/
3190 * The following routines act on ONboards.
3193 static void stli_onbinit(stlibrd_t *brdp)
3195 unsigned long memconf;
3197 outb(ONB_ATSTOP, (brdp->iobase + ONB_ATCONFR));
3199 outb(ONB_ATDISABLE, (brdp->iobase + ONB_ATCONFR));
3202 memconf = (brdp->memaddr & ONB_ATADDRMASK) >> ONB_ATADDRSHFT;
3203 outb(memconf, (brdp->iobase + ONB_ATMEMAR));
3204 outb(0x1, brdp->iobase);
3208 /*****************************************************************************/
3210 static void stli_onbenable(stlibrd_t *brdp)
3212 outb((brdp->enabval | ONB_ATENABLE), (brdp->iobase + ONB_ATCONFR));
3215 /*****************************************************************************/
3217 static void stli_onbdisable(stlibrd_t *brdp)
3219 outb((brdp->enabval | ONB_ATDISABLE), (brdp->iobase + ONB_ATCONFR));
3222 /*****************************************************************************/
3224 static char *stli_onbgetmemptr(stlibrd_t *brdp, unsigned long offset, int line)
3228 if (offset > brdp->memsize) {
3229 printk(KERN_ERR "STALLION: shared memory pointer=%x out of "
3230 "range at line=%d(%d), brd=%d\n",
3231 (int) offset, line, __LINE__, brdp->brdnr);
3234 ptr = brdp->membase + (offset % ONB_ATPAGESIZE);
3239 /*****************************************************************************/
3241 static void stli_onbreset(stlibrd_t *brdp)
3243 outb(ONB_ATSTOP, (brdp->iobase + ONB_ATCONFR));
3245 outb(ONB_ATDISABLE, (brdp->iobase + ONB_ATCONFR));
3249 /*****************************************************************************/
3252 * The following routines act on ONboard EISA.
3255 static void stli_onbeinit(stlibrd_t *brdp)
3257 unsigned long memconf;
3259 outb(0x1, (brdp->iobase + ONB_EIBRDENAB));
3260 outb(ONB_EISTOP, (brdp->iobase + ONB_EICONFR));
3262 outb(ONB_EIDISABLE, (brdp->iobase + ONB_EICONFR));
3265 memconf = (brdp->memaddr & ONB_EIADDRMASKL) >> ONB_EIADDRSHFTL;
3266 outb(memconf, (brdp->iobase + ONB_EIMEMARL));
3267 memconf = (brdp->memaddr & ONB_EIADDRMASKH) >> ONB_EIADDRSHFTH;
3268 outb(memconf, (brdp->iobase + ONB_EIMEMARH));
3269 outb(0x1, brdp->iobase);
3273 /*****************************************************************************/
3275 static void stli_onbeenable(stlibrd_t *brdp)
3277 outb(ONB_EIENABLE, (brdp->iobase + ONB_EICONFR));
3280 /*****************************************************************************/
3282 static void stli_onbedisable(stlibrd_t *brdp)
3284 outb(ONB_EIDISABLE, (brdp->iobase + ONB_EICONFR));
3287 /*****************************************************************************/
3289 static char *stli_onbegetmemptr(stlibrd_t *brdp, unsigned long offset, int line)
3294 if (offset > brdp->memsize) {
3295 printk(KERN_ERR "STALLION: shared memory pointer=%x out of "
3296 "range at line=%d(%d), brd=%d\n",
3297 (int) offset, line, __LINE__, brdp->brdnr);
3301 ptr = brdp->membase + (offset % ONB_EIPAGESIZE);
3302 if (offset < ONB_EIPAGESIZE)
3305 val = ONB_EIENABLE | 0x40;
3307 outb(val, (brdp->iobase + ONB_EICONFR));
3311 /*****************************************************************************/
3313 static void stli_onbereset(stlibrd_t *brdp)
3315 outb(ONB_EISTOP, (brdp->iobase + ONB_EICONFR));
3317 outb(ONB_EIDISABLE, (brdp->iobase + ONB_EICONFR));
3321 /*****************************************************************************/
3324 * The following routines act on Brumby boards.
3327 static void stli_bbyinit(stlibrd_t *brdp)
3329 outb(BBY_ATSTOP, (brdp->iobase + BBY_ATCONFR));
3331 outb(0, (brdp->iobase + BBY_ATCONFR));
3333 outb(0x1, brdp->iobase);
3337 /*****************************************************************************/
3339 static char *stli_bbygetmemptr(stlibrd_t *brdp, unsigned long offset, int line)
3344 BUG_ON(offset > brdp->memsize);
3346 ptr = brdp->membase + (offset % BBY_PAGESIZE);
3347 val = (unsigned char) (offset / BBY_PAGESIZE);
3348 outb(val, (brdp->iobase + BBY_ATCONFR));
3352 /*****************************************************************************/
3354 static void stli_bbyreset(stlibrd_t *brdp)
3356 outb(BBY_ATSTOP, (brdp->iobase + BBY_ATCONFR));
3358 outb(0, (brdp->iobase + BBY_ATCONFR));
3362 /*****************************************************************************/
3365 * The following routines act on original old Stallion boards.
3368 static void stli_stalinit(stlibrd_t *brdp)
3370 outb(0x1, brdp->iobase);
3374 /*****************************************************************************/
3376 static char *stli_stalgetmemptr(stlibrd_t *brdp, unsigned long offset, int line)
3378 BUG_ON(offset > brdp->memsize);
3379 return brdp->membase + (offset % STAL_PAGESIZE);
3382 /*****************************************************************************/
3384 static void stli_stalreset(stlibrd_t *brdp)
3388 vecp = (u32 __iomem *) (brdp->membase + 0x30);
3389 writel(0xffff0000, vecp);
3390 outb(0, brdp->iobase);
3394 /*****************************************************************************/
3397 * Try to find an ECP board and initialize it. This handles only ECP
3401 static int stli_initecp(stlibrd_t *brdp)
3404 cdkecpsig_t __iomem *sigsp;
3405 unsigned int status, nxtid;
3407 int panelnr, nrports;
3409 if (!request_region(brdp->iobase, brdp->iosize, "istallion"))
3412 if ((brdp->iobase == 0) || (brdp->memaddr == 0))
3414 release_region(brdp->iobase, brdp->iosize);
3418 brdp->iosize = ECP_IOSIZE;
3421 * Based on the specific board type setup the common vars to access
3422 * and enable shared memory. Set all board specific information now
3425 switch (brdp->brdtype) {
3427 brdp->membase = (void *) brdp->memaddr;
3428 brdp->memsize = ECP_MEMSIZE;
3429 brdp->pagesize = ECP_ATPAGESIZE;
3430 brdp->init = stli_ecpinit;
3431 brdp->enable = stli_ecpenable;
3432 brdp->reenable = stli_ecpenable;
3433 brdp->disable = stli_ecpdisable;
3434 brdp->getmemptr = stli_ecpgetmemptr;
3435 brdp->intr = stli_ecpintr;
3436 brdp->reset = stli_ecpreset;
3437 name = "serial(EC8/64)";
3441 brdp->membase = (void *) brdp->memaddr;
3442 brdp->memsize = ECP_MEMSIZE;
3443 brdp->pagesize = ECP_EIPAGESIZE;
3444 brdp->init = stli_ecpeiinit;
3445 brdp->enable = stli_ecpeienable;
3446 brdp->reenable = stli_ecpeienable;
3447 brdp->disable = stli_ecpeidisable;
3448 brdp->getmemptr = stli_ecpeigetmemptr;
3449 brdp->intr = stli_ecpintr;
3450 brdp->reset = stli_ecpeireset;
3451 name = "serial(EC8/64-EI)";
3455 brdp->membase = (void *) brdp->memaddr;
3456 brdp->memsize = ECP_MEMSIZE;
3457 brdp->pagesize = ECP_MCPAGESIZE;
3459 brdp->enable = stli_ecpmcenable;
3460 brdp->reenable = stli_ecpmcenable;
3461 brdp->disable = stli_ecpmcdisable;
3462 brdp->getmemptr = stli_ecpmcgetmemptr;
3463 brdp->intr = stli_ecpintr;
3464 brdp->reset = stli_ecpmcreset;
3465 name = "serial(EC8/64-MCA)";
3469 brdp->membase = (void *) brdp->memaddr;
3470 brdp->memsize = ECP_PCIMEMSIZE;
3471 brdp->pagesize = ECP_PCIPAGESIZE;
3472 brdp->init = stli_ecppciinit;
3473 brdp->enable = NULL;
3474 brdp->reenable = NULL;
3475 brdp->disable = NULL;
3476 brdp->getmemptr = stli_ecppcigetmemptr;
3477 brdp->intr = stli_ecpintr;
3478 brdp->reset = stli_ecppcireset;
3479 name = "serial(EC/RA-PCI)";
3483 release_region(brdp->iobase, brdp->iosize);
3488 * The per-board operations structure is all set up, so now let's go
3489 * and get the board operational. Firstly initialize board configuration
3490 * registers. Set the memory mapping info so we can get at the boards
3495 brdp->membase = ioremap(brdp->memaddr, brdp->memsize);
3496 if (brdp->membase == NULL)
3498 release_region(brdp->iobase, brdp->iosize);
3503 * Now that all specific code is set up, enable the shared memory and
3504 * look for the a signature area that will tell us exactly what board
3505 * this is, and what it is connected to it.
3508 sigsp = (cdkecpsig_t __iomem *) EBRDGETMEMPTR(brdp, CDK_SIGADDR);
3509 memcpy(&sig, sigsp, sizeof(cdkecpsig_t));
3512 if (sig.magic != cpu_to_le32(ECP_MAGIC))
3514 release_region(brdp->iobase, brdp->iosize);
3519 * Scan through the signature looking at the panels connected to the
3520 * board. Calculate the total number of ports as we go.
3522 for (panelnr = 0, nxtid = 0; (panelnr < STL_MAXPANELS); panelnr++) {
3523 status = sig.panelid[nxtid];
3524 if ((status & ECH_PNLIDMASK) != nxtid)
3527 brdp->panelids[panelnr] = status;
3528 nrports = (status & ECH_PNL16PORT) ? 16 : 8;
3529 if ((nrports == 16) && ((status & ECH_PNLXPID) == 0))
3531 brdp->panels[panelnr] = nrports;
3532 brdp->nrports += nrports;
3538 brdp->state |= BST_FOUND;
3542 /*****************************************************************************/
3545 * Try to find an ONboard, Brumby or Stallion board and initialize it.
3546 * This handles only these board types.
3549 static int stli_initonb(stlibrd_t *brdp)
3552 cdkonbsig_t __iomem *sigsp;
3557 * Do a basic sanity check on the IO and memory addresses.
3559 if (brdp->iobase == 0 || brdp->memaddr == 0)
3562 brdp->iosize = ONB_IOSIZE;
3564 if (!request_region(brdp->iobase, brdp->iosize, "istallion"))
3568 * Based on the specific board type setup the common vars to access
3569 * and enable shared memory. Set all board specific information now
3572 switch (brdp->brdtype) {
3576 case BRD_ONBOARD2_32:
3578 brdp->memsize = ONB_MEMSIZE;
3579 brdp->pagesize = ONB_ATPAGESIZE;
3580 brdp->init = stli_onbinit;
3581 brdp->enable = stli_onbenable;
3582 brdp->reenable = stli_onbenable;
3583 brdp->disable = stli_onbdisable;
3584 brdp->getmemptr = stli_onbgetmemptr;
3585 brdp->intr = stli_ecpintr;
3586 brdp->reset = stli_onbreset;
3587 if (brdp->memaddr > 0x100000)
3588 brdp->enabval = ONB_MEMENABHI;
3590 brdp->enabval = ONB_MEMENABLO;
3591 name = "serial(ONBoard)";
3595 brdp->memsize = ONB_EIMEMSIZE;
3596 brdp->pagesize = ONB_EIPAGESIZE;
3597 brdp->init = stli_onbeinit;
3598 brdp->enable = stli_onbeenable;
3599 brdp->reenable = stli_onbeenable;
3600 brdp->disable = stli_onbedisable;
3601 brdp->getmemptr = stli_onbegetmemptr;
3602 brdp->intr = stli_ecpintr;
3603 brdp->reset = stli_onbereset;
3604 name = "serial(ONBoard/E)";
3610 brdp->memsize = BBY_MEMSIZE;
3611 brdp->pagesize = BBY_PAGESIZE;
3612 brdp->init = stli_bbyinit;
3613 brdp->enable = NULL;
3614 brdp->reenable = NULL;
3615 brdp->disable = NULL;
3616 brdp->getmemptr = stli_bbygetmemptr;
3617 brdp->intr = stli_ecpintr;
3618 brdp->reset = stli_bbyreset;
3619 name = "serial(Brumby)";
3623 brdp->memsize = STAL_MEMSIZE;
3624 brdp->pagesize = STAL_PAGESIZE;
3625 brdp->init = stli_stalinit;
3626 brdp->enable = NULL;
3627 brdp->reenable = NULL;
3628 brdp->disable = NULL;
3629 brdp->getmemptr = stli_stalgetmemptr;
3630 brdp->intr = stli_ecpintr;
3631 brdp->reset = stli_stalreset;
3632 name = "serial(Stallion)";
3636 release_region(brdp->iobase, brdp->iosize);
3641 * The per-board operations structure is all set up, so now let's go
3642 * and get the board operational. Firstly initialize board configuration
3643 * registers. Set the memory mapping info so we can get at the boards
3648 brdp->membase = ioremap(brdp->memaddr, brdp->memsize);
3649 if (brdp->membase == NULL)
3651 release_region(brdp->iobase, brdp->iosize);
3656 * Now that all specific code is set up, enable the shared memory and
3657 * look for the a signature area that will tell us exactly what board
3658 * this is, and how many ports.
3661 sigsp = (cdkonbsig_t __iomem *) EBRDGETMEMPTR(brdp, CDK_SIGADDR);
3662 memcpy_fromio(&sig, sigsp, sizeof(cdkonbsig_t));
3665 if (sig.magic0 != cpu_to_le16(ONB_MAGIC0) ||
3666 sig.magic1 != cpu_to_le16(ONB_MAGIC1) ||
3667 sig.magic2 != cpu_to_le16(ONB_MAGIC2) ||
3668 sig.magic3 != cpu_to_le16(ONB_MAGIC3))
3670 release_region(brdp->iobase, brdp->iosize);
3675 * Scan through the signature alive mask and calculate how many ports
3676 * there are on this board.
3682 for (i = 0; (i < 16); i++) {
3683 if (((sig.amask0 << i) & 0x8000) == 0)
3688 brdp->panels[0] = brdp->nrports;
3691 brdp->state |= BST_FOUND;
3695 /*****************************************************************************/
3698 * Start up a running board. This routine is only called after the
3699 * code has been down loaded to the board and is operational. It will
3700 * read in the memory map, and get the show on the road...
3703 static int stli_startbrd(stlibrd_t *brdp)
3705 cdkhdr_t __iomem *hdrp;
3706 cdkmem_t __iomem *memp;
3707 cdkasy_t __iomem *ap;
3708 unsigned long flags;
3710 int portnr, nrdevs, i, rc = 0;
3713 spin_lock_irqsave(&brd_lock, flags);
3715 hdrp = (cdkhdr_t __iomem *) EBRDGETMEMPTR(brdp, CDK_CDKADDR);
3716 nrdevs = hdrp->nrdevs;
3719 printk("%s(%d): CDK version %d.%d.%d --> "
3720 "nrdevs=%d memp=%x hostp=%x slavep=%x\n",
3721 __FILE__, __LINE__, readb(&hdrp->ver_release), readb(&hdrp->ver_modification),
3722 readb(&hdrp->ver_fix), nrdevs, (int) readl(&hdrp->memp), readl(&hdrp->hostp),
3723 readl(&hdrp->slavep));
3726 if (nrdevs < (brdp->nrports + 1)) {
3727 printk(KERN_ERR "STALLION: slave failed to allocate memory for "
3728 "all devices, devices=%d\n", nrdevs);
3729 brdp->nrports = nrdevs - 1;
3731 brdp->nrdevs = nrdevs;
3732 brdp->hostoffset = hdrp->hostp - CDK_CDKADDR;
3733 brdp->slaveoffset = hdrp->slavep - CDK_CDKADDR;
3734 brdp->bitsize = (nrdevs + 7) / 8;
3735 memoff = readl(&hdrp->memp);
3736 if (memoff > brdp->memsize) {
3737 printk(KERN_ERR "STALLION: corrupted shared memory region?\n");
3739 goto stli_donestartup;
3741 memp = (cdkmem_t __iomem *) EBRDGETMEMPTR(brdp, memoff);
3742 if (readw(&memp->dtype) != TYP_ASYNCTRL) {
3743 printk(KERN_ERR "STALLION: no slave control device found\n");
3744 goto stli_donestartup;
3749 * Cycle through memory allocation of each port. We are guaranteed to
3750 * have all ports inside the first page of slave window, so no need to
3751 * change pages while reading memory map.
3753 for (i = 1, portnr = 0; (i < nrdevs); i++, portnr++, memp++) {
3754 if (readw(&memp->dtype) != TYP_ASYNC)
3756 portp = brdp->ports[portnr];
3760 portp->addr = readl(&memp->offset);
3761 portp->reqbit = (unsigned char) (0x1 << (i * 8 / nrdevs));
3762 portp->portidx = (unsigned char) (i / 8);
3763 portp->portbit = (unsigned char) (0x1 << (i % 8));
3766 writeb(0xff, &hdrp->slavereq);
3769 * For each port setup a local copy of the RX and TX buffer offsets
3770 * and sizes. We do this separate from the above, because we need to
3771 * move the shared memory page...
3773 for (i = 1, portnr = 0; (i < nrdevs); i++, portnr++) {
3774 portp = brdp->ports[portnr];
3777 if (portp->addr == 0)
3779 ap = (cdkasy_t __iomem *) EBRDGETMEMPTR(brdp, portp->addr);
3781 portp->rxsize = readw(&ap->rxq.size);
3782 portp->txsize = readw(&ap->txq.size);
3783 portp->rxoffset = readl(&ap->rxq.offset);
3784 portp->txoffset = readl(&ap->txq.offset);
3790 spin_unlock_irqrestore(&brd_lock, flags);
3793 brdp->state |= BST_STARTED;
3795 if (! stli_timeron) {
3797 stli_timerlist.expires = STLI_TIMEOUT;
3798 add_timer(&stli_timerlist);
3804 /*****************************************************************************/
3807 * Probe and initialize the specified board.
3810 static int __init stli_brdinit(stlibrd_t *brdp)
3812 stli_brds[brdp->brdnr] = brdp;
3814 switch (brdp->brdtype) {
3825 case BRD_ONBOARD2_32:
3837 printk(KERN_ERR "STALLION: %s board type not supported in "
3838 "this driver\n", stli_brdnames[brdp->brdtype]);
3841 printk(KERN_ERR "STALLION: board=%d is unknown board "
3842 "type=%d\n", brdp->brdnr, brdp->brdtype);
3846 if ((brdp->state & BST_FOUND) == 0) {
3847 printk(KERN_ERR "STALLION: %s board not found, board=%d "
3849 stli_brdnames[brdp->brdtype], brdp->brdnr,
3850 brdp->iobase, (int) brdp->memaddr);
3854 stli_initports(brdp);
3855 printk(KERN_INFO "STALLION: %s found, board=%d io=%x mem=%x "
3856 "nrpanels=%d nrports=%d\n", stli_brdnames[brdp->brdtype],
3857 brdp->brdnr, brdp->iobase, (int) brdp->memaddr,
3858 brdp->nrpanels, brdp->nrports);
3862 /*****************************************************************************/
3865 * Probe around trying to find where the EISA boards shared memory
3866 * might be. This is a bit if hack, but it is the best we can do.
3869 static int stli_eisamemprobe(stlibrd_t *brdp)
3871 cdkecpsig_t ecpsig, __iomem *ecpsigp;
3872 cdkonbsig_t onbsig, __iomem *onbsigp;
3876 * First up we reset the board, to get it into a known state. There
3877 * is only 2 board types here we need to worry about. Don;t use the
3878 * standard board init routine here, it programs up the shared
3879 * memory address, and we don't know it yet...
3881 if (brdp->brdtype == BRD_ECPE) {
3882 outb(0x1, (brdp->iobase + ECP_EIBRDENAB));
3883 outb(ECP_EISTOP, (brdp->iobase + ECP_EICONFR));
3885 outb(ECP_EIDISABLE, (brdp->iobase + ECP_EICONFR));
3887 stli_ecpeienable(brdp);
3888 } else if (brdp->brdtype == BRD_ONBOARDE) {
3889 outb(0x1, (brdp->iobase + ONB_EIBRDENAB));
3890 outb(ONB_EISTOP, (brdp->iobase + ONB_EICONFR));
3892 outb(ONB_EIDISABLE, (brdp->iobase + ONB_EICONFR));
3894 outb(0x1, brdp->iobase);
3896 stli_onbeenable(brdp);
3902 brdp->memsize = ECP_MEMSIZE;
3905 * Board shared memory is enabled, so now we have a poke around and
3906 * see if we can find it.
3908 for (i = 0; (i < stli_eisamempsize); i++) {
3909 brdp->memaddr = stli_eisamemprobeaddrs[i];
3910 brdp->membase = ioremap(brdp->memaddr, brdp->memsize);
3911 if (brdp->membase == NULL)
3914 if (brdp->brdtype == BRD_ECPE) {
3915 ecpsigp = (cdkecpsig_t __iomem *) stli_ecpeigetmemptr(brdp,
3916 CDK_SIGADDR, __LINE__);
3917 memcpy_fromio(&ecpsig, ecpsigp, sizeof(cdkecpsig_t));
3918 if (ecpsig.magic == cpu_to_le32(ECP_MAGIC))
3921 onbsigp = (cdkonbsig_t __iomem *) stli_onbegetmemptr(brdp,
3922 CDK_SIGADDR, __LINE__);
3923 memcpy_fromio(&onbsig, onbsigp, sizeof(cdkonbsig_t));
3924 if ((onbsig.magic0 == cpu_to_le16(ONB_MAGIC0)) &&
3925 (onbsig.magic1 == cpu_to_le16(ONB_MAGIC1)) &&
3926 (onbsig.magic2 == cpu_to_le16(ONB_MAGIC2)) &&
3927 (onbsig.magic3 == cpu_to_le16(ONB_MAGIC3)))
3931 iounmap(brdp->membase);
3937 * Regardless of whether we found the shared memory or not we must
3938 * disable the region. After that return success or failure.
3940 if (brdp->brdtype == BRD_ECPE)
3941 stli_ecpeidisable(brdp);
3943 stli_onbedisable(brdp);
3947 brdp->membase = NULL;
3948 printk(KERN_ERR "STALLION: failed to probe shared memory "
3949 "region for %s in EISA slot=%d\n",
3950 stli_brdnames[brdp->brdtype], (brdp->iobase >> 12));
3956 static int stli_getbrdnr(void)
3960 for (i = 0; i < STL_MAXBRDS; i++) {
3961 if (!stli_brds[i]) {
3962 if (i >= stli_nrbrds)
3963 stli_nrbrds = i + 1;
3970 /*****************************************************************************/
3973 * Probe around and try to find any EISA boards in system. The biggest
3974 * problem here is finding out what memory address is associated with
3975 * an EISA board after it is found. The registers of the ECPE and
3976 * ONboardE are not readable - so we can't read them from there. We
3977 * don't have access to the EISA CMOS (or EISA BIOS) so we don't
3978 * actually have any way to find out the real value. The best we can
3979 * do is go probing around in the usual places hoping we can find it.
3982 static int stli_findeisabrds(void)
3985 unsigned int iobase, eid;
3989 * Firstly check if this is an EISA system. If this is not an EISA system then
3990 * don't bother going any further!
3996 * Looks like an EISA system, so go searching for EISA boards.
3998 for (iobase = 0x1000; (iobase <= 0xc000); iobase += 0x1000) {
3999 outb(0xff, (iobase + 0xc80));
4000 eid = inb(iobase + 0xc80);
4001 eid |= inb(iobase + 0xc81) << 8;
4002 if (eid != STL_EISAID)
4006 * We have found a board. Need to check if this board was
4007 * statically configured already (just in case!).
4009 for (i = 0; (i < STL_MAXBRDS); i++) {
4010 brdp = stli_brds[i];
4013 if (brdp->iobase == iobase)
4016 if (i < STL_MAXBRDS)
4020 * We have found a Stallion board and it is not configured already.
4021 * Allocate a board structure and initialize it.
4023 if ((brdp = stli_allocbrd()) == NULL)
4025 if ((brdp->brdnr = stli_getbrdnr()) < 0)
4027 eid = inb(iobase + 0xc82);
4028 if (eid == ECP_EISAID)
4029 brdp->brdtype = BRD_ECPE;
4030 else if (eid == ONB_EISAID)
4031 brdp->brdtype = BRD_ONBOARDE;
4033 brdp->brdtype = BRD_UNKNOWN;
4034 brdp->iobase = iobase;
4035 outb(0x1, (iobase + 0xc84));
4036 if (stli_eisamemprobe(brdp))
4037 outb(0, (iobase + 0xc84));
4044 /*****************************************************************************/
4047 * Find the next available board number that is free.
4050 /*****************************************************************************/
4055 * We have a Stallion board. Allocate a board structure and
4056 * initialize it. Read its IO and MEMORY resources from PCI
4057 * configuration space.
4060 static int stli_initpcibrd(int brdtype, struct pci_dev *devp)
4064 if (pci_enable_device(devp))
4066 if ((brdp = stli_allocbrd()) == NULL)
4068 if ((brdp->brdnr = stli_getbrdnr()) < 0) {
4069 printk(KERN_INFO "STALLION: too many boards found, "
4070 "maximum supported %d\n", STL_MAXBRDS);
4073 brdp->brdtype = brdtype;
4075 * We have all resources from the board, so lets setup the actual
4076 * board structure now.
4078 brdp->iobase = pci_resource_start(devp, 3);
4079 brdp->memaddr = pci_resource_start(devp, 2);
4085 /*****************************************************************************/
4088 * Find all Stallion PCI boards that might be installed. Initialize each
4089 * one as it is found.
4092 static int stli_findpcibrds(void)
4094 struct pci_dev *dev = NULL;
4096 while ((dev = pci_get_device(PCI_VENDOR_ID_STALLION, PCI_DEVICE_ID_ECRA, dev))) {
4097 stli_initpcibrd(BRD_ECPPCI, dev);
4104 /*****************************************************************************/
4107 * Allocate a new board structure. Fill out the basic info in it.
4110 static stlibrd_t *stli_allocbrd(void)
4114 brdp = kzalloc(sizeof(stlibrd_t), GFP_KERNEL);
4116 printk(KERN_ERR "STALLION: failed to allocate memory "
4117 "(size=%Zd)\n", sizeof(stlibrd_t));
4120 brdp->magic = STLI_BOARDMAGIC;
4124 /*****************************************************************************/
4127 * Scan through all the boards in the configuration and see what we
4131 static int stli_initbrds(void)
4133 stlibrd_t *brdp, *nxtbrdp;
4137 if (stli_nrbrds > STL_MAXBRDS) {
4138 printk(KERN_INFO "STALLION: too many boards in configuration "
4139 "table, truncating to %d\n", STL_MAXBRDS);
4140 stli_nrbrds = STL_MAXBRDS;
4144 * Firstly scan the list of static boards configured. Allocate
4145 * resources and initialize the boards as found. If this is a
4146 * module then let the module args override static configuration.
4148 for (i = 0; (i < stli_nrbrds); i++) {
4149 confp = &stli_brdconf[i];
4150 stli_parsebrd(confp, stli_brdsp[i]);
4151 if ((brdp = stli_allocbrd()) == NULL)
4154 brdp->brdtype = confp->brdtype;
4155 brdp->iobase = confp->ioaddr1;
4156 brdp->memaddr = confp->memaddr;
4161 * Static configuration table done, so now use dynamic methods to
4162 * see if any more boards should be configured.
4166 stli_findeisabrds();
4172 * All found boards are initialized. Now for a little optimization, if
4173 * no boards are sharing the "shared memory" regions then we can just
4174 * leave them all enabled. This is in fact the usual case.
4177 if (stli_nrbrds > 1) {
4178 for (i = 0; (i < stli_nrbrds); i++) {
4179 brdp = stli_brds[i];
4182 for (j = i + 1; (j < stli_nrbrds); j++) {
4183 nxtbrdp = stli_brds[j];
4184 if (nxtbrdp == NULL)
4186 if ((brdp->membase >= nxtbrdp->membase) &&
4187 (brdp->membase <= (nxtbrdp->membase +
4188 nxtbrdp->memsize - 1))) {
4196 if (stli_shared == 0) {
4197 for (i = 0; (i < stli_nrbrds); i++) {
4198 brdp = stli_brds[i];
4201 if (brdp->state & BST_FOUND) {
4203 brdp->enable = NULL;
4204 brdp->disable = NULL;
4212 /*****************************************************************************/
4215 * Code to handle an "staliomem" read operation. This device is the
4216 * contents of the board shared memory. It is used for down loading
4217 * the slave image (and debugging :-)
4220 static ssize_t stli_memread(struct file *fp, char __user *buf, size_t count, loff_t *offp)
4222 unsigned long flags;
4229 brdnr = iminor(fp->f_dentry->d_inode);
4230 if (brdnr >= stli_nrbrds)
4232 brdp = stli_brds[brdnr];
4235 if (brdp->state == 0)
4237 if (off >= brdp->memsize || off + count < off)
4240 size = MIN(count, (brdp->memsize - off));
4243 * Copy the data a page at a time
4246 p = (void *)__get_free_page(GFP_KERNEL);
4251 spin_lock_irqsave(&brd_lock, flags);
4253 memptr = (void *) EBRDGETMEMPTR(brdp, off);
4254 n = MIN(size, (brdp->pagesize - (((unsigned long) off) % brdp->pagesize)));
4255 n = MIN(n, PAGE_SIZE);
4256 memcpy_fromio(p, memptr, n);
4258 spin_unlock_irqrestore(&brd_lock, flags);
4259 if (copy_to_user(buf, p, n)) {
4269 free_page((unsigned long)p);
4273 /*****************************************************************************/
4276 * Code to handle an "staliomem" write operation. This device is the
4277 * contents of the board shared memory. It is used for down loading
4278 * the slave image (and debugging :-)
4280 * FIXME: copy under lock
4283 static ssize_t stli_memwrite(struct file *fp, const char __user *buf, size_t count, loff_t *offp)
4285 unsigned long flags;
4293 brdnr = iminor(fp->f_dentry->d_inode);
4295 if (brdnr >= stli_nrbrds)
4297 brdp = stli_brds[brdnr];
4300 if (brdp->state == 0)
4302 if (off >= brdp->memsize || off + count < off)
4305 chbuf = (char __user *) buf;
4306 size = MIN(count, (brdp->memsize - off));
4309 * Copy the data a page at a time
4312 p = (void *)__get_free_page(GFP_KERNEL);
4317 n = MIN(size, (brdp->pagesize - (((unsigned long) off) % brdp->pagesize)));
4318 n = MIN(n, PAGE_SIZE);
4319 if (copy_from_user(p, chbuf, n)) {
4324 spin_lock_irqsave(&brd_lock, flags);
4326 memptr = (void *) EBRDGETMEMPTR(brdp, off);
4327 memcpy_toio(memptr, p, n);
4329 spin_unlock_irqrestore(&brd_lock, flags);
4335 free_page((unsigned long) p);
4340 /*****************************************************************************/
4343 * Return the board stats structure to user app.
4346 static int stli_getbrdstats(combrd_t __user *bp)
4351 if (copy_from_user(&stli_brdstats, bp, sizeof(combrd_t)))
4353 if (stli_brdstats.brd >= STL_MAXBRDS)
4355 brdp = stli_brds[stli_brdstats.brd];
4359 memset(&stli_brdstats, 0, sizeof(combrd_t));
4360 stli_brdstats.brd = brdp->brdnr;
4361 stli_brdstats.type = brdp->brdtype;
4362 stli_brdstats.hwid = 0;
4363 stli_brdstats.state = brdp->state;
4364 stli_brdstats.ioaddr = brdp->iobase;
4365 stli_brdstats.memaddr = brdp->memaddr;
4366 stli_brdstats.nrpanels = brdp->nrpanels;
4367 stli_brdstats.nrports = brdp->nrports;
4368 for (i = 0; (i < brdp->nrpanels); i++) {
4369 stli_brdstats.panels[i].panel = i;
4370 stli_brdstats.panels[i].hwid = brdp->panelids[i];
4371 stli_brdstats.panels[i].nrports = brdp->panels[i];
4374 if (copy_to_user(bp, &stli_brdstats, sizeof(combrd_t)))
4379 /*****************************************************************************/
4382 * Resolve the referenced port number into a port struct pointer.
4385 static stliport_t *stli_getport(int brdnr, int panelnr, int portnr)
4390 if (brdnr < 0 || brdnr >= STL_MAXBRDS)
4392 brdp = stli_brds[brdnr];
4395 for (i = 0; (i < panelnr); i++)
4396 portnr += brdp->panels[i];
4397 if ((portnr < 0) || (portnr >= brdp->nrports))
4399 return brdp->ports[portnr];
4402 /*****************************************************************************/
4405 * Return the port stats structure to user app. A NULL port struct
4406 * pointer passed in means that we need to find out from the app
4407 * what port to get stats for (used through board control device).
4410 static int stli_portcmdstats(stliport_t *portp)
4412 unsigned long flags;
4416 memset(&stli_comstats, 0, sizeof(comstats_t));
4420 brdp = stli_brds[portp->brdnr];
4424 if (brdp->state & BST_STARTED) {
4425 if ((rc = stli_cmdwait(brdp, portp, A_GETSTATS,
4426 &stli_cdkstats, sizeof(asystats_t), 1)) < 0)
4429 memset(&stli_cdkstats, 0, sizeof(asystats_t));
4432 stli_comstats.brd = portp->brdnr;
4433 stli_comstats.panel = portp->panelnr;
4434 stli_comstats.port = portp->portnr;
4435 stli_comstats.state = portp->state;
4436 stli_comstats.flags = portp->flags;
4438 spin_lock_irqsave(&brd_lock, flags);
4439 if (portp->tty != NULL) {
4440 if (portp->tty->driver_data == portp) {
4441 stli_comstats.ttystate = portp->tty->flags;
4442 stli_comstats.rxbuffered = -1;
4443 if (portp->tty->termios != NULL) {
4444 stli_comstats.cflags = portp->tty->termios->c_cflag;
4445 stli_comstats.iflags = portp->tty->termios->c_iflag;
4446 stli_comstats.oflags = portp->tty->termios->c_oflag;
4447 stli_comstats.lflags = portp->tty->termios->c_lflag;
4451 spin_unlock_irqrestore(&brd_lock, flags);
4453 stli_comstats.txtotal = stli_cdkstats.txchars;
4454 stli_comstats.rxtotal = stli_cdkstats.rxchars + stli_cdkstats.ringover;
4455 stli_comstats.txbuffered = stli_cdkstats.txringq;
4456 stli_comstats.rxbuffered += stli_cdkstats.rxringq;
4457 stli_comstats.rxoverrun = stli_cdkstats.overruns;
4458 stli_comstats.rxparity = stli_cdkstats.parity;
4459 stli_comstats.rxframing = stli_cdkstats.framing;
4460 stli_comstats.rxlost = stli_cdkstats.ringover;
4461 stli_comstats.rxbreaks = stli_cdkstats.rxbreaks;
4462 stli_comstats.txbreaks = stli_cdkstats.txbreaks;
4463 stli_comstats.txxon = stli_cdkstats.txstart;
4464 stli_comstats.txxoff = stli_cdkstats.txstop;
4465 stli_comstats.rxxon = stli_cdkstats.rxstart;
4466 stli_comstats.rxxoff = stli_cdkstats.rxstop;
4467 stli_comstats.rxrtsoff = stli_cdkstats.rtscnt / 2;
4468 stli_comstats.rxrtson = stli_cdkstats.rtscnt - stli_comstats.rxrtsoff;
4469 stli_comstats.modem = stli_cdkstats.dcdcnt;
4470 stli_comstats.hwid = stli_cdkstats.hwid;
4471 stli_comstats.signals = stli_mktiocm(stli_cdkstats.signals);
4476 /*****************************************************************************/
4479 * Return the port stats structure to user app. A NULL port struct
4480 * pointer passed in means that we need to find out from the app
4481 * what port to get stats for (used through board control device).
4484 static int stli_getportstats(stliport_t *portp, comstats_t __user *cp)
4490 if (copy_from_user(&stli_comstats, cp, sizeof(comstats_t)))
4492 portp = stli_getport(stli_comstats.brd, stli_comstats.panel,
4493 stli_comstats.port);
4498 brdp = stli_brds[portp->brdnr];
4502 if ((rc = stli_portcmdstats(portp)) < 0)
4505 return copy_to_user(cp, &stli_comstats, sizeof(comstats_t)) ?
4509 /*****************************************************************************/
4512 * Clear the port stats structure. We also return it zeroed out...
4515 static int stli_clrportstats(stliport_t *portp, comstats_t __user *cp)
4521 if (copy_from_user(&stli_comstats, cp, sizeof(comstats_t)))
4523 portp = stli_getport(stli_comstats.brd, stli_comstats.panel,
4524 stli_comstats.port);
4529 brdp = stli_brds[portp->brdnr];
4533 if (brdp->state & BST_STARTED) {
4534 if ((rc = stli_cmdwait(brdp, portp, A_CLEARSTATS, NULL, 0, 0)) < 0)
4538 memset(&stli_comstats, 0, sizeof(comstats_t));
4539 stli_comstats.brd = portp->brdnr;
4540 stli_comstats.panel = portp->panelnr;
4541 stli_comstats.port = portp->portnr;
4543 if (copy_to_user(cp, &stli_comstats, sizeof(comstats_t)))
4548 /*****************************************************************************/
4551 * Return the entire driver ports structure to a user app.
4554 static int stli_getportstruct(stliport_t __user *arg)
4558 if (copy_from_user(&stli_dummyport, arg, sizeof(stliport_t)))
4560 portp = stli_getport(stli_dummyport.brdnr, stli_dummyport.panelnr,
4561 stli_dummyport.portnr);
4564 if (copy_to_user(arg, portp, sizeof(stliport_t)))
4569 /*****************************************************************************/
4572 * Return the entire driver board structure to a user app.
4575 static int stli_getbrdstruct(stlibrd_t __user *arg)
4579 if (copy_from_user(&stli_dummybrd, arg, sizeof(stlibrd_t)))
4581 if ((stli_dummybrd.brdnr < 0) || (stli_dummybrd.brdnr >= STL_MAXBRDS))
4583 brdp = stli_brds[stli_dummybrd.brdnr];
4586 if (copy_to_user(arg, brdp, sizeof(stlibrd_t)))
4591 /*****************************************************************************/
4594 * The "staliomem" device is also required to do some special operations on
4595 * the board. We need to be able to send an interrupt to the board,
4596 * reset it, and start/stop it.
4599 static int stli_memioctl(struct inode *ip, struct file *fp, unsigned int cmd, unsigned long arg)
4602 int brdnr, rc, done;
4603 void __user *argp = (void __user *)arg;
4606 * First up handle the board independent ioctls.
4612 case COM_GETPORTSTATS:
4613 rc = stli_getportstats(NULL, argp);
4616 case COM_CLRPORTSTATS:
4617 rc = stli_clrportstats(NULL, argp);
4620 case COM_GETBRDSTATS:
4621 rc = stli_getbrdstats(argp);
4625 rc = stli_getportstruct(argp);
4629 rc = stli_getbrdstruct(argp);
4638 * Now handle the board specific ioctls. These all depend on the
4639 * minor number of the device they were called from.
4642 if (brdnr >= STL_MAXBRDS)
4644 brdp = stli_brds[brdnr];
4647 if (brdp->state == 0)
4655 rc = stli_startbrd(brdp);
4658 brdp->state &= ~BST_STARTED;
4661 brdp->state &= ~BST_STARTED;
4663 if (stli_shared == 0) {
4664 if (brdp->reenable != NULL)
4665 (* brdp->reenable)(brdp);
4675 static struct tty_operations stli_ops = {
4677 .close = stli_close,
4678 .write = stli_write,
4679 .put_char = stli_putchar,
4680 .flush_chars = stli_flushchars,
4681 .write_room = stli_writeroom,
4682 .chars_in_buffer = stli_charsinbuffer,
4683 .ioctl = stli_ioctl,
4684 .set_termios = stli_settermios,
4685 .throttle = stli_throttle,
4686 .unthrottle = stli_unthrottle,
4688 .start = stli_start,
4689 .hangup = stli_hangup,
4690 .flush_buffer = stli_flushbuffer,
4691 .break_ctl = stli_breakctl,
4692 .wait_until_sent = stli_waituntilsent,
4693 .send_xchar = stli_sendxchar,
4694 .read_proc = stli_readproc,
4695 .tiocmget = stli_tiocmget,
4696 .tiocmset = stli_tiocmset,
4699 /*****************************************************************************/
4701 int __init stli_init(void)
4704 printk(KERN_INFO "%s: version %s\n", stli_drvtitle, stli_drvversion);
4706 spin_lock_init(&stli_lock);
4707 spin_lock_init(&brd_lock);
4711 stli_serial = alloc_tty_driver(STL_MAXBRDS * STL_MAXPORTS);
4716 * Allocate a temporary write buffer.
4718 stli_txcookbuf = kmalloc(STLI_TXBUFSIZE, GFP_KERNEL);
4719 if (!stli_txcookbuf)
4720 printk(KERN_ERR "STALLION: failed to allocate memory "
4721 "(size=%d)\n", STLI_TXBUFSIZE);
4724 * Set up a character driver for the shared memory region. We need this
4725 * to down load the slave code image. Also it is a useful debugging tool.
4727 if (register_chrdev(STL_SIOMEMMAJOR, "staliomem", &stli_fsiomem))
4728 printk(KERN_ERR "STALLION: failed to register serial memory "
4731 devfs_mk_dir("staliomem");
4732 istallion_class = class_create(THIS_MODULE, "staliomem");
4733 for (i = 0; i < 4; i++) {
4734 devfs_mk_cdev(MKDEV(STL_SIOMEMMAJOR, i),
4735 S_IFCHR | S_IRUSR | S_IWUSR,
4737 class_device_create(istallion_class, NULL,
4738 MKDEV(STL_SIOMEMMAJOR, i),
4739 NULL, "staliomem%d", i);
4743 * Set up the tty driver structure and register us as a driver.
4745 stli_serial->owner = THIS_MODULE;
4746 stli_serial->driver_name = stli_drvname;
4747 stli_serial->name = stli_serialname;
4748 stli_serial->major = STL_SERIALMAJOR;
4749 stli_serial->minor_start = 0;
4750 stli_serial->type = TTY_DRIVER_TYPE_SERIAL;
4751 stli_serial->subtype = SERIAL_TYPE_NORMAL;
4752 stli_serial->init_termios = stli_deftermios;
4753 stli_serial->flags = TTY_DRIVER_REAL_RAW;
4754 tty_set_operations(stli_serial, &stli_ops);
4756 if (tty_register_driver(stli_serial)) {
4757 put_tty_driver(stli_serial);
4758 printk(KERN_ERR "STALLION: failed to register serial driver\n");
4764 /*****************************************************************************/