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/device.h>
43 #include <linux/wait.h>
44 #include <linux/eisa.h>
47 #include <asm/uaccess.h>
49 #include <linux/pci.h>
51 /*****************************************************************************/
54 * Define different board types. Not all of the following board types
55 * are supported by this driver. But I will use the standard "assigned"
56 * board numbers. Currently supported boards are abbreviated as:
57 * ECP = EasyConnection 8/64, ONB = ONboard, BBY = Brumby and
61 #define BRD_STALLION 1
63 #define BRD_ONBOARD2 3
66 #define BRD_BRUMBY16 6
67 #define BRD_ONBOARDE 7
68 #define BRD_ONBOARD32 9
69 #define BRD_ONBOARD2_32 10
70 #define BRD_ONBOARDRS 11
78 #define BRD_ECH64PCI 27
79 #define BRD_EASYIOPCI 28
82 #define BRD_BRUMBY BRD_BRUMBY4
85 * Define a configuration structure to hold the board configuration.
86 * Need to set this up in the code (for now) with the boards that are
87 * to be configured into the system. This is what needs to be modified
88 * when adding/removing/modifying boards. Each line entry in the
89 * stli_brdconf[] array is a board. Each line contains io/irq/memory
90 * ranges for that board (as well as what type of board it is).
92 * { BRD_ECP, 0x2a0, 0, 0xcc000, 0, 0 },
93 * This line will configure an EasyConnection 8/64 at io address 2a0,
94 * and shared memory address of cc000. Multiple EasyConnection 8/64
95 * boards can share the same shared memory address space. No interrupt
96 * is required for this board type.
98 * { BRD_ECPE, 0x5000, 0, 0x80000000, 0, 0 },
99 * This line will configure an EasyConnection 8/64 EISA in slot 5 and
100 * shared memory address of 0x80000000 (2 GByte). Multiple
101 * EasyConnection 8/64 EISA boards can share the same shared memory
102 * address space. No interrupt is required for this board type.
104 * { BRD_ONBOARD, 0x240, 0, 0xd0000, 0, 0 },
105 * This line will configure an ONboard (ISA type) at io address 240,
106 * and shared memory address of d0000. Multiple ONboards can share
107 * the same shared memory address space. No interrupt required.
109 * { BRD_BRUMBY4, 0x360, 0, 0xc8000, 0, 0 },
110 * This line will configure a Brumby board (any number of ports!) at
111 * io address 360 and shared memory address of c8000. All Brumby boards
112 * configured into a system must have their own separate io and memory
113 * addresses. No interrupt is required.
115 * { BRD_STALLION, 0x330, 0, 0xd0000, 0, 0 },
116 * This line will configure an original Stallion board at io address 330
117 * and shared memory address d0000 (this would only be valid for a "V4.0"
118 * or Rev.O Stallion board). All Stallion boards configured into the
119 * system must have their own separate io and memory addresses. No
120 * interrupt is required.
127 unsigned long memaddr;
132 static stlconf_t stli_brdconf[] = {
133 /*{ BRD_ECP, 0x2a0, 0, 0xcc000, 0, 0 },*/
136 static int stli_nrbrds = ARRAY_SIZE(stli_brdconf);
138 /* stli_lock must NOT be taken holding brd_lock */
139 static spinlock_t stli_lock; /* TTY logic lock */
140 static spinlock_t brd_lock; /* Board logic lock */
143 * There is some experimental EISA board detection code in this driver.
144 * By default it is disabled, but for those that want to try it out,
145 * then set the define below to be 1.
147 #define STLI_EISAPROBE 0
149 /*****************************************************************************/
152 * Define some important driver characteristics. Device major numbers
153 * allocated as per Linux Device Registry.
155 #ifndef STL_SIOMEMMAJOR
156 #define STL_SIOMEMMAJOR 28
158 #ifndef STL_SERIALMAJOR
159 #define STL_SERIALMAJOR 24
161 #ifndef STL_CALLOUTMAJOR
162 #define STL_CALLOUTMAJOR 25
165 /*****************************************************************************/
168 * Define our local driver identity first. Set up stuff to deal with
169 * all the local structures required by a serial tty driver.
171 static char *stli_drvtitle = "Stallion Intelligent Multiport Serial Driver";
172 static char *stli_drvname = "istallion";
173 static char *stli_drvversion = "5.6.0";
174 static char *stli_serialname = "ttyE";
176 static struct tty_driver *stli_serial;
179 #define STLI_TXBUFSIZE 4096
182 * Use a fast local buffer for cooked characters. Typically a whole
183 * bunch of cooked characters come in for a port, 1 at a time. So we
184 * save those up into a local buffer, then write out the whole lot
185 * with a large memcpy. Just use 1 buffer for all ports, since its
186 * use it is only need for short periods of time by each port.
188 static char *stli_txcookbuf;
189 static int stli_txcooksize;
190 static int stli_txcookrealsize;
191 static struct tty_struct *stli_txcooktty;
194 * Define a local default termios struct. All ports will be created
195 * with this termios initially. Basically all it defines is a raw port
196 * at 9600 baud, 8 data bits, no parity, 1 stop bit.
198 static struct termios stli_deftermios = {
199 .c_cflag = (B9600 | CS8 | CREAD | HUPCL | CLOCAL),
204 * Define global stats structures. Not used often, and can be
205 * re-used for each stats call.
207 static comstats_t stli_comstats;
208 static combrd_t stli_brdstats;
209 static asystats_t stli_cdkstats;
210 static stlibrd_t stli_dummybrd;
211 static stliport_t stli_dummyport;
213 /*****************************************************************************/
215 static stlibrd_t *stli_brds[STL_MAXBRDS];
217 static int stli_shared;
220 * Per board state flags. Used with the state field of the board struct.
221 * Not really much here... All we need to do is keep track of whether
222 * the board has been detected, and whether it is actually running a slave
225 #define BST_FOUND 0x1
226 #define BST_STARTED 0x2
229 * Define the set of port state flags. These are marked for internal
230 * state purposes only, usually to do with the state of communications
231 * with the slave. Most of them need to be updated atomically, so always
232 * use the bit setting operations (unless protected by cli/sti).
234 #define ST_INITIALIZING 1
240 #define ST_DOFLUSHRX 7
241 #define ST_DOFLUSHTX 8
244 #define ST_GETSIGS 11
247 * Define an array of board names as printable strings. Handy for
248 * referencing boards when printing trace and stuff.
250 static char *stli_brdnames[] = {
283 /*****************************************************************************/
286 * Define some string labels for arguments passed from the module
287 * load line. These allow for easy board definitions, and easy
288 * modification of the io, memory and irq resoucres.
291 static char *board0[8];
292 static char *board1[8];
293 static char *board2[8];
294 static char *board3[8];
296 static char **stli_brdsp[] = {
304 * Define a set of common board names, and types. This is used to
305 * parse any module arguments.
308 typedef struct stlibrdtype {
313 static stlibrdtype_t stli_brdstr[] = {
314 { "stallion", BRD_STALLION },
315 { "1", BRD_STALLION },
316 { "brumby", BRD_BRUMBY },
317 { "brumby4", BRD_BRUMBY },
318 { "brumby/4", BRD_BRUMBY },
319 { "brumby-4", BRD_BRUMBY },
320 { "brumby8", BRD_BRUMBY },
321 { "brumby/8", BRD_BRUMBY },
322 { "brumby-8", BRD_BRUMBY },
323 { "brumby16", BRD_BRUMBY },
324 { "brumby/16", BRD_BRUMBY },
325 { "brumby-16", BRD_BRUMBY },
327 { "onboard2", BRD_ONBOARD2 },
328 { "onboard-2", BRD_ONBOARD2 },
329 { "onboard/2", BRD_ONBOARD2 },
330 { "onboard-mc", BRD_ONBOARD2 },
331 { "onboard/mc", BRD_ONBOARD2 },
332 { "onboard-mca", BRD_ONBOARD2 },
333 { "onboard/mca", BRD_ONBOARD2 },
334 { "3", BRD_ONBOARD2 },
335 { "onboard", BRD_ONBOARD },
336 { "onboardat", BRD_ONBOARD },
337 { "4", BRD_ONBOARD },
338 { "onboarde", BRD_ONBOARDE },
339 { "onboard-e", BRD_ONBOARDE },
340 { "onboard/e", BRD_ONBOARDE },
341 { "onboard-ei", BRD_ONBOARDE },
342 { "onboard/ei", BRD_ONBOARDE },
343 { "7", BRD_ONBOARDE },
345 { "ecpat", BRD_ECP },
346 { "ec8/64", BRD_ECP },
347 { "ec8/64-at", BRD_ECP },
348 { "ec8/64-isa", BRD_ECP },
350 { "ecpe", BRD_ECPE },
351 { "ecpei", BRD_ECPE },
352 { "ec8/64-e", BRD_ECPE },
353 { "ec8/64-ei", BRD_ECPE },
355 { "ecpmc", BRD_ECPMC },
356 { "ec8/64-mc", BRD_ECPMC },
357 { "ec8/64-mca", BRD_ECPMC },
359 { "ecppci", BRD_ECPPCI },
360 { "ec/ra", BRD_ECPPCI },
361 { "ec/ra-pc", BRD_ECPPCI },
362 { "ec/ra-pci", BRD_ECPPCI },
363 { "29", BRD_ECPPCI },
367 * Define the module agruments.
369 MODULE_AUTHOR("Greg Ungerer");
370 MODULE_DESCRIPTION("Stallion Intelligent Multiport Serial Driver");
371 MODULE_LICENSE("GPL");
374 module_param_array(board0, charp, NULL, 0);
375 MODULE_PARM_DESC(board0, "Board 0 config -> name[,ioaddr[,memaddr]");
376 module_param_array(board1, charp, NULL, 0);
377 MODULE_PARM_DESC(board1, "Board 1 config -> name[,ioaddr[,memaddr]");
378 module_param_array(board2, charp, NULL, 0);
379 MODULE_PARM_DESC(board2, "Board 2 config -> name[,ioaddr[,memaddr]");
380 module_param_array(board3, charp, NULL, 0);
381 MODULE_PARM_DESC(board3, "Board 3 config -> name[,ioaddr[,memaddr]");
384 * Set up a default memory address table for EISA board probing.
385 * The default addresses are all bellow 1Mbyte, which has to be the
386 * case anyway. They should be safe, since we only read values from
387 * them, and interrupts are disabled while we do it. If the higher
388 * memory support is compiled in then we also try probing around
389 * the 1Gb, 2Gb and 3Gb areas as well...
391 static unsigned long stli_eisamemprobeaddrs[] = {
392 0xc0000, 0xd0000, 0xe0000, 0xf0000,
393 0x80000000, 0x80010000, 0x80020000, 0x80030000,
394 0x40000000, 0x40010000, 0x40020000, 0x40030000,
395 0xc0000000, 0xc0010000, 0xc0020000, 0xc0030000,
396 0xff000000, 0xff010000, 0xff020000, 0xff030000,
399 static int stli_eisamempsize = ARRAY_SIZE(stli_eisamemprobeaddrs);
402 * Define the Stallion PCI vendor and device IDs.
405 #ifndef PCI_VENDOR_ID_STALLION
406 #define PCI_VENDOR_ID_STALLION 0x124d
408 #ifndef PCI_DEVICE_ID_ECRA
409 #define PCI_DEVICE_ID_ECRA 0x0004
412 static struct pci_device_id istallion_pci_tbl[] = {
413 { PCI_DEVICE(PCI_VENDOR_ID_STALLION, PCI_DEVICE_ID_ECRA), },
416 MODULE_DEVICE_TABLE(pci, istallion_pci_tbl);
418 #endif /* CONFIG_PCI */
420 /*****************************************************************************/
423 * Hardware configuration info for ECP boards. These defines apply
424 * to the directly accessible io ports of the ECP. There is a set of
425 * defines for each ECP board type, ISA, EISA, MCA and PCI.
429 #define ECP_MEMSIZE (128 * 1024)
430 #define ECP_PCIMEMSIZE (256 * 1024)
432 #define ECP_ATPAGESIZE (4 * 1024)
433 #define ECP_MCPAGESIZE (4 * 1024)
434 #define ECP_EIPAGESIZE (64 * 1024)
435 #define ECP_PCIPAGESIZE (64 * 1024)
437 #define STL_EISAID 0x8c4e
440 * Important defines for the ISA class of ECP board.
443 #define ECP_ATCONFR 1
444 #define ECP_ATMEMAR 2
445 #define ECP_ATMEMPR 3
446 #define ECP_ATSTOP 0x1
447 #define ECP_ATINTENAB 0x10
448 #define ECP_ATENABLE 0x20
449 #define ECP_ATDISABLE 0x00
450 #define ECP_ATADDRMASK 0x3f000
451 #define ECP_ATADDRSHFT 12
454 * Important defines for the EISA class of ECP board.
457 #define ECP_EIMEMARL 1
458 #define ECP_EICONFR 2
459 #define ECP_EIMEMARH 3
460 #define ECP_EIENABLE 0x1
461 #define ECP_EIDISABLE 0x0
462 #define ECP_EISTOP 0x4
463 #define ECP_EIEDGE 0x00
464 #define ECP_EILEVEL 0x80
465 #define ECP_EIADDRMASKL 0x00ff0000
466 #define ECP_EIADDRSHFTL 16
467 #define ECP_EIADDRMASKH 0xff000000
468 #define ECP_EIADDRSHFTH 24
469 #define ECP_EIBRDENAB 0xc84
471 #define ECP_EISAID 0x4
474 * Important defines for the Micro-channel class of ECP board.
475 * (It has a lot in common with the ISA boards.)
478 #define ECP_MCCONFR 1
479 #define ECP_MCSTOP 0x20
480 #define ECP_MCENABLE 0x80
481 #define ECP_MCDISABLE 0x00
484 * Important defines for the PCI class of ECP board.
485 * (It has a lot in common with the other ECP boards.)
487 #define ECP_PCIIREG 0
488 #define ECP_PCICONFR 1
489 #define ECP_PCISTOP 0x01
492 * Hardware configuration info for ONboard and Brumby boards. These
493 * defines apply to the directly accessible io ports of these boards.
495 #define ONB_IOSIZE 16
496 #define ONB_MEMSIZE (64 * 1024)
497 #define ONB_ATPAGESIZE (64 * 1024)
498 #define ONB_MCPAGESIZE (64 * 1024)
499 #define ONB_EIMEMSIZE (128 * 1024)
500 #define ONB_EIPAGESIZE (64 * 1024)
503 * Important defines for the ISA class of ONboard board.
506 #define ONB_ATMEMAR 1
507 #define ONB_ATCONFR 2
508 #define ONB_ATSTOP 0x4
509 #define ONB_ATENABLE 0x01
510 #define ONB_ATDISABLE 0x00
511 #define ONB_ATADDRMASK 0xff0000
512 #define ONB_ATADDRSHFT 16
514 #define ONB_MEMENABLO 0
515 #define ONB_MEMENABHI 0x02
518 * Important defines for the EISA class of ONboard board.
521 #define ONB_EIMEMARL 1
522 #define ONB_EICONFR 2
523 #define ONB_EIMEMARH 3
524 #define ONB_EIENABLE 0x1
525 #define ONB_EIDISABLE 0x0
526 #define ONB_EISTOP 0x4
527 #define ONB_EIEDGE 0x00
528 #define ONB_EILEVEL 0x80
529 #define ONB_EIADDRMASKL 0x00ff0000
530 #define ONB_EIADDRSHFTL 16
531 #define ONB_EIADDRMASKH 0xff000000
532 #define ONB_EIADDRSHFTH 24
533 #define ONB_EIBRDENAB 0xc84
535 #define ONB_EISAID 0x1
538 * Important defines for the Brumby boards. They are pretty simple,
539 * there is not much that is programmably configurable.
541 #define BBY_IOSIZE 16
542 #define BBY_MEMSIZE (64 * 1024)
543 #define BBY_PAGESIZE (16 * 1024)
546 #define BBY_ATCONFR 1
547 #define BBY_ATSTOP 0x4
550 * Important defines for the Stallion boards. They are pretty simple,
551 * there is not much that is programmably configurable.
553 #define STAL_IOSIZE 16
554 #define STAL_MEMSIZE (64 * 1024)
555 #define STAL_PAGESIZE (64 * 1024)
558 * Define the set of status register values for EasyConnection panels.
559 * The signature will return with the status value for each panel. From
560 * this we can determine what is attached to the board - before we have
561 * actually down loaded any code to it.
563 #define ECH_PNLSTATUS 2
564 #define ECH_PNL16PORT 0x20
565 #define ECH_PNLIDMASK 0x07
566 #define ECH_PNLXPID 0x40
567 #define ECH_PNLINTRPEND 0x80
570 * Define some macros to do things to the board. Even those these boards
571 * are somewhat related there is often significantly different ways of
572 * doing some operation on it (like enable, paging, reset, etc). So each
573 * board class has a set of functions which do the commonly required
574 * operations. The macros below basically just call these functions,
575 * generally checking for a NULL function - which means that the board
576 * needs nothing done to it to achieve this operation!
578 #define EBRDINIT(brdp) \
579 if (brdp->init != NULL) \
582 #define EBRDENABLE(brdp) \
583 if (brdp->enable != NULL) \
584 (* brdp->enable)(brdp);
586 #define EBRDDISABLE(brdp) \
587 if (brdp->disable != NULL) \
588 (* brdp->disable)(brdp);
590 #define EBRDINTR(brdp) \
591 if (brdp->intr != NULL) \
592 (* brdp->intr)(brdp);
594 #define EBRDRESET(brdp) \
595 if (brdp->reset != NULL) \
596 (* brdp->reset)(brdp);
598 #define EBRDGETMEMPTR(brdp,offset) \
599 (* brdp->getmemptr)(brdp, offset, __LINE__)
602 * Define the maximal baud rate, and the default baud base for ports.
604 #define STL_MAXBAUD 460800
605 #define STL_BAUDBASE 115200
606 #define STL_CLOSEDELAY (5 * HZ / 10)
608 /*****************************************************************************/
611 * Define macros to extract a brd or port number from a minor number.
613 #define MINOR2BRD(min) (((min) & 0xc0) >> 6)
614 #define MINOR2PORT(min) ((min) & 0x3f)
617 * Define a baud rate table that converts termios baud rate selector
618 * into the actual baud rate value. All baud rate calculations are based
619 * on the actual baud rate required.
621 static unsigned int stli_baudrates[] = {
622 0, 50, 75, 110, 134, 150, 200, 300, 600, 1200, 1800, 2400, 4800,
623 9600, 19200, 38400, 57600, 115200, 230400, 460800, 921600
626 /*****************************************************************************/
629 * Define some handy local macros...
632 #define MIN(a,b) (((a) <= (b)) ? (a) : (b))
635 #define TOLOWER(x) ((((x) >= 'A') && ((x) <= 'Z')) ? ((x) + 0x20) : (x))
637 /*****************************************************************************/
640 * Prototype all functions in this driver!
643 static int stli_parsebrd(stlconf_t *confp, char **argp);
644 static int stli_init(void);
645 static int stli_open(struct tty_struct *tty, struct file *filp);
646 static void stli_close(struct tty_struct *tty, struct file *filp);
647 static int stli_write(struct tty_struct *tty, const unsigned char *buf, int count);
648 static void stli_putchar(struct tty_struct *tty, unsigned char ch);
649 static void stli_flushchars(struct tty_struct *tty);
650 static int stli_writeroom(struct tty_struct *tty);
651 static int stli_charsinbuffer(struct tty_struct *tty);
652 static int stli_ioctl(struct tty_struct *tty, struct file *file, unsigned int cmd, unsigned long arg);
653 static void stli_settermios(struct tty_struct *tty, struct termios *old);
654 static void stli_throttle(struct tty_struct *tty);
655 static void stli_unthrottle(struct tty_struct *tty);
656 static void stli_stop(struct tty_struct *tty);
657 static void stli_start(struct tty_struct *tty);
658 static void stli_flushbuffer(struct tty_struct *tty);
659 static void stli_breakctl(struct tty_struct *tty, int state);
660 static void stli_waituntilsent(struct tty_struct *tty, int timeout);
661 static void stli_sendxchar(struct tty_struct *tty, char ch);
662 static void stli_hangup(struct tty_struct *tty);
663 static int stli_portinfo(stlibrd_t *brdp, stliport_t *portp, int portnr, char *pos);
665 static int stli_brdinit(stlibrd_t *brdp);
666 static int stli_startbrd(stlibrd_t *brdp);
667 static ssize_t stli_memread(struct file *fp, char __user *buf, size_t count, loff_t *offp);
668 static ssize_t stli_memwrite(struct file *fp, const char __user *buf, size_t count, loff_t *offp);
669 static int stli_memioctl(struct inode *ip, struct file *fp, unsigned int cmd, unsigned long arg);
670 static void stli_brdpoll(stlibrd_t *brdp, cdkhdr_t __iomem *hdrp);
671 static void stli_poll(unsigned long arg);
672 static int stli_hostcmd(stlibrd_t *brdp, stliport_t *portp);
673 static int stli_initopen(stlibrd_t *brdp, stliport_t *portp);
674 static int stli_rawopen(stlibrd_t *brdp, stliport_t *portp, unsigned long arg, int wait);
675 static int stli_rawclose(stlibrd_t *brdp, stliport_t *portp, unsigned long arg, int wait);
676 static int stli_waitcarrier(stlibrd_t *brdp, stliport_t *portp, struct file *filp);
677 static void stli_dohangup(void *arg);
678 static int stli_setport(stliport_t *portp);
679 static int stli_cmdwait(stlibrd_t *brdp, stliport_t *portp, unsigned long cmd, void *arg, int size, int copyback);
680 static void stli_sendcmd(stlibrd_t *brdp, stliport_t *portp, unsigned long cmd, void *arg, int size, int copyback);
681 static void __stli_sendcmd(stlibrd_t *brdp, stliport_t *portp, unsigned long cmd, void *arg, int size, int copyback);
682 static void stli_dodelaycmd(stliport_t *portp, cdkctrl_t __iomem *cp);
683 static void stli_mkasyport(stliport_t *portp, asyport_t *pp, struct termios *tiosp);
684 static void stli_mkasysigs(asysigs_t *sp, int dtr, int rts);
685 static long stli_mktiocm(unsigned long sigvalue);
686 static void stli_read(stlibrd_t *brdp, stliport_t *portp);
687 static int stli_getserial(stliport_t *portp, struct serial_struct __user *sp);
688 static int stli_setserial(stliport_t *portp, struct serial_struct __user *sp);
689 static int stli_getbrdstats(combrd_t __user *bp);
690 static int stli_getportstats(stliport_t *portp, comstats_t __user *cp);
691 static int stli_portcmdstats(stliport_t *portp);
692 static int stli_clrportstats(stliport_t *portp, comstats_t __user *cp);
693 static int stli_getportstruct(stliport_t __user *arg);
694 static int stli_getbrdstruct(stlibrd_t __user *arg);
695 static stlibrd_t *stli_allocbrd(void);
697 static void stli_ecpinit(stlibrd_t *brdp);
698 static void stli_ecpenable(stlibrd_t *brdp);
699 static void stli_ecpdisable(stlibrd_t *brdp);
700 static char *stli_ecpgetmemptr(stlibrd_t *brdp, unsigned long offset, int line);
701 static void stli_ecpreset(stlibrd_t *brdp);
702 static void stli_ecpintr(stlibrd_t *brdp);
703 static void stli_ecpeiinit(stlibrd_t *brdp);
704 static void stli_ecpeienable(stlibrd_t *brdp);
705 static void stli_ecpeidisable(stlibrd_t *brdp);
706 static char *stli_ecpeigetmemptr(stlibrd_t *brdp, unsigned long offset, int line);
707 static void stli_ecpeireset(stlibrd_t *brdp);
708 static void stli_ecpmcenable(stlibrd_t *brdp);
709 static void stli_ecpmcdisable(stlibrd_t *brdp);
710 static char *stli_ecpmcgetmemptr(stlibrd_t *brdp, unsigned long offset, int line);
711 static void stli_ecpmcreset(stlibrd_t *brdp);
712 static void stli_ecppciinit(stlibrd_t *brdp);
713 static char *stli_ecppcigetmemptr(stlibrd_t *brdp, unsigned long offset, int line);
714 static void stli_ecppcireset(stlibrd_t *brdp);
716 static void stli_onbinit(stlibrd_t *brdp);
717 static void stli_onbenable(stlibrd_t *brdp);
718 static void stli_onbdisable(stlibrd_t *brdp);
719 static char *stli_onbgetmemptr(stlibrd_t *brdp, unsigned long offset, int line);
720 static void stli_onbreset(stlibrd_t *brdp);
721 static void stli_onbeinit(stlibrd_t *brdp);
722 static void stli_onbeenable(stlibrd_t *brdp);
723 static void stli_onbedisable(stlibrd_t *brdp);
724 static char *stli_onbegetmemptr(stlibrd_t *brdp, unsigned long offset, int line);
725 static void stli_onbereset(stlibrd_t *brdp);
726 static void stli_bbyinit(stlibrd_t *brdp);
727 static char *stli_bbygetmemptr(stlibrd_t *brdp, unsigned long offset, int line);
728 static void stli_bbyreset(stlibrd_t *brdp);
729 static void stli_stalinit(stlibrd_t *brdp);
730 static char *stli_stalgetmemptr(stlibrd_t *brdp, unsigned long offset, int line);
731 static void stli_stalreset(stlibrd_t *brdp);
733 static stliport_t *stli_getport(int brdnr, int panelnr, int portnr);
735 static int stli_initecp(stlibrd_t *brdp);
736 static int stli_initonb(stlibrd_t *brdp);
737 static int stli_eisamemprobe(stlibrd_t *brdp);
738 static int stli_initports(stlibrd_t *brdp);
741 static int stli_initpcibrd(int brdtype, struct pci_dev *devp);
744 /*****************************************************************************/
747 * Define the driver info for a user level shared memory device. This
748 * device will work sort of like the /dev/kmem device - except that it
749 * will give access to the shared memory on the Stallion intelligent
750 * board. This is also a very useful debugging tool.
752 static struct file_operations stli_fsiomem = {
753 .owner = THIS_MODULE,
754 .read = stli_memread,
755 .write = stli_memwrite,
756 .ioctl = stli_memioctl,
759 /*****************************************************************************/
762 * Define a timer_list entry for our poll routine. The slave board
763 * is polled every so often to see if anything needs doing. This is
764 * much cheaper on host cpu than using interrupts. It turns out to
765 * not increase character latency by much either...
767 static DEFINE_TIMER(stli_timerlist, stli_poll, 0, 0);
769 static int stli_timeron;
772 * Define the calculation for the timeout routine.
774 #define STLI_TIMEOUT (jiffies + 1)
776 /*****************************************************************************/
778 static struct class *istallion_class;
781 * Loadable module initialization stuff.
784 static int __init istallion_module_init(void)
790 /*****************************************************************************/
792 static void __exit istallion_module_exit(void)
798 printk(KERN_INFO "Unloading %s: version %s\n", stli_drvtitle,
802 * Free up all allocated resources used by the ports. This includes
803 * memory and interrupts.
807 del_timer_sync(&stli_timerlist);
810 i = tty_unregister_driver(stli_serial);
812 printk("STALLION: failed to un-register tty driver, "
816 put_tty_driver(stli_serial);
817 for (i = 0; i < 4; i++)
818 class_device_destroy(istallion_class, MKDEV(STL_SIOMEMMAJOR, i));
819 class_destroy(istallion_class);
820 if ((i = unregister_chrdev(STL_SIOMEMMAJOR, "staliomem")))
821 printk("STALLION: failed to un-register serial memory device, "
824 kfree(stli_txcookbuf);
826 for (i = 0; (i < stli_nrbrds); i++) {
827 if ((brdp = stli_brds[i]) == NULL)
829 for (j = 0; (j < STL_MAXPORTS); j++) {
830 portp = brdp->ports[j];
832 if (portp->tty != NULL)
833 tty_hangup(portp->tty);
838 iounmap(brdp->membase);
839 if (brdp->iosize > 0)
840 release_region(brdp->iobase, brdp->iosize);
846 module_init(istallion_module_init);
847 module_exit(istallion_module_exit);
849 /*****************************************************************************/
852 * Check for any arguments passed in on the module load command line.
855 static void stli_argbrds(void)
861 for (i = stli_nrbrds; i < ARRAY_SIZE(stli_brdsp); i++) {
862 memset(&conf, 0, sizeof(conf));
863 if (stli_parsebrd(&conf, stli_brdsp[i]) == 0)
865 if ((brdp = stli_allocbrd()) == NULL)
869 brdp->brdtype = conf.brdtype;
870 brdp->iobase = conf.ioaddr1;
871 brdp->memaddr = conf.memaddr;
876 /*****************************************************************************/
879 * Convert an ascii string number into an unsigned long.
882 static unsigned long stli_atol(char *str)
890 if ((*sp == '0') && (*(sp+1) == 'x')) {
893 } else if (*sp == '0') {
900 for (; (*sp != 0); sp++) {
901 c = (*sp > '9') ? (TOLOWER(*sp) - 'a' + 10) : (*sp - '0');
902 if ((c < 0) || (c >= base)) {
903 printk("STALLION: invalid argument %s\n", str);
907 val = (val * base) + c;
912 /*****************************************************************************/
915 * Parse the supplied argument string, into the board conf struct.
918 static int stli_parsebrd(stlconf_t *confp, char **argp)
923 if (argp[0] == NULL || *argp[0] == 0)
926 for (sp = argp[0], i = 0; ((*sp != 0) && (i < 25)); sp++, i++)
929 for (i = 0; i < ARRAY_SIZE(stli_brdstr); i++) {
930 if (strcmp(stli_brdstr[i].name, argp[0]) == 0)
933 if (i == ARRAY_SIZE(stli_brdstr)) {
934 printk("STALLION: unknown board name, %s?\n", argp[0]);
938 confp->brdtype = stli_brdstr[i].type;
939 if (argp[1] != NULL && *argp[1] != 0)
940 confp->ioaddr1 = stli_atol(argp[1]);
941 if (argp[2] != NULL && *argp[2] != 0)
942 confp->memaddr = stli_atol(argp[2]);
946 /*****************************************************************************/
948 static int stli_open(struct tty_struct *tty, struct file *filp)
952 unsigned int minordev;
953 int brdnr, portnr, rc;
955 minordev = tty->index;
956 brdnr = MINOR2BRD(minordev);
957 if (brdnr >= stli_nrbrds)
959 brdp = stli_brds[brdnr];
962 if ((brdp->state & BST_STARTED) == 0)
964 portnr = MINOR2PORT(minordev);
965 if ((portnr < 0) || (portnr > brdp->nrports))
968 portp = brdp->ports[portnr];
971 if (portp->devnr < 1)
976 * Check if this port is in the middle of closing. If so then wait
977 * until it is closed then return error status based on flag settings.
978 * The sleep here does not need interrupt protection since the wakeup
979 * for it is done with the same context.
981 if (portp->flags & ASYNC_CLOSING) {
982 interruptible_sleep_on(&portp->close_wait);
983 if (portp->flags & ASYNC_HUP_NOTIFY)
989 * On the first open of the device setup the port hardware, and
990 * initialize the per port data structure. Since initializing the port
991 * requires several commands to the board we will need to wait for any
992 * other open that is already initializing the port.
995 tty->driver_data = portp;
998 wait_event_interruptible(portp->raw_wait,
999 !test_bit(ST_INITIALIZING, &portp->state));
1000 if (signal_pending(current))
1001 return -ERESTARTSYS;
1003 if ((portp->flags & ASYNC_INITIALIZED) == 0) {
1004 set_bit(ST_INITIALIZING, &portp->state);
1005 if ((rc = stli_initopen(brdp, portp)) >= 0) {
1006 portp->flags |= ASYNC_INITIALIZED;
1007 clear_bit(TTY_IO_ERROR, &tty->flags);
1009 clear_bit(ST_INITIALIZING, &portp->state);
1010 wake_up_interruptible(&portp->raw_wait);
1016 * Check if this port is in the middle of closing. If so then wait
1017 * until it is closed then return error status, based on flag settings.
1018 * The sleep here does not need interrupt protection since the wakeup
1019 * for it is done with the same context.
1021 if (portp->flags & ASYNC_CLOSING) {
1022 interruptible_sleep_on(&portp->close_wait);
1023 if (portp->flags & ASYNC_HUP_NOTIFY)
1025 return -ERESTARTSYS;
1029 * Based on type of open being done check if it can overlap with any
1030 * previous opens still in effect. If we are a normal serial device
1031 * then also we might have to wait for carrier.
1033 if (!(filp->f_flags & O_NONBLOCK)) {
1034 if ((rc = stli_waitcarrier(brdp, portp, filp)) != 0)
1037 portp->flags |= ASYNC_NORMAL_ACTIVE;
1041 /*****************************************************************************/
1043 static void stli_close(struct tty_struct *tty, struct file *filp)
1047 unsigned long flags;
1049 portp = tty->driver_data;
1053 spin_lock_irqsave(&stli_lock, flags);
1054 if (tty_hung_up_p(filp)) {
1055 spin_unlock_irqrestore(&stli_lock, flags);
1058 if ((tty->count == 1) && (portp->refcount != 1))
1059 portp->refcount = 1;
1060 if (portp->refcount-- > 1) {
1061 spin_unlock_irqrestore(&stli_lock, flags);
1065 portp->flags |= ASYNC_CLOSING;
1068 * May want to wait for data to drain before closing. The BUSY flag
1069 * keeps track of whether we are still transmitting or not. It is
1070 * updated by messages from the slave - indicating when all chars
1071 * really have drained.
1073 if (tty == stli_txcooktty)
1074 stli_flushchars(tty);
1076 spin_unlock_irqrestore(&stli_lock, flags);
1078 if (portp->closing_wait != ASYNC_CLOSING_WAIT_NONE)
1079 tty_wait_until_sent(tty, portp->closing_wait);
1081 portp->flags &= ~ASYNC_INITIALIZED;
1082 brdp = stli_brds[portp->brdnr];
1083 stli_rawclose(brdp, portp, 0, 0);
1084 if (tty->termios->c_cflag & HUPCL) {
1085 stli_mkasysigs(&portp->asig, 0, 0);
1086 if (test_bit(ST_CMDING, &portp->state))
1087 set_bit(ST_DOSIGS, &portp->state);
1089 stli_sendcmd(brdp, portp, A_SETSIGNALS, &portp->asig,
1090 sizeof(asysigs_t), 0);
1092 clear_bit(ST_TXBUSY, &portp->state);
1093 clear_bit(ST_RXSTOP, &portp->state);
1094 set_bit(TTY_IO_ERROR, &tty->flags);
1095 if (tty->ldisc.flush_buffer)
1096 (tty->ldisc.flush_buffer)(tty);
1097 set_bit(ST_DOFLUSHRX, &portp->state);
1098 stli_flushbuffer(tty);
1103 if (portp->openwaitcnt) {
1104 if (portp->close_delay)
1105 msleep_interruptible(jiffies_to_msecs(portp->close_delay));
1106 wake_up_interruptible(&portp->open_wait);
1109 portp->flags &= ~(ASYNC_NORMAL_ACTIVE|ASYNC_CLOSING);
1110 wake_up_interruptible(&portp->close_wait);
1113 /*****************************************************************************/
1116 * Carry out first open operations on a port. This involves a number of
1117 * commands to be sent to the slave. We need to open the port, set the
1118 * notification events, set the initial port settings, get and set the
1119 * initial signal values. We sleep and wait in between each one. But
1120 * this still all happens pretty quickly.
1123 static int stli_initopen(stlibrd_t *brdp, stliport_t *portp)
1125 struct tty_struct *tty;
1130 if ((rc = stli_rawopen(brdp, portp, 0, 1)) < 0)
1133 memset(&nt, 0, sizeof(asynotify_t));
1134 nt.data = (DT_TXLOW | DT_TXEMPTY | DT_RXBUSY | DT_RXBREAK);
1136 if ((rc = stli_cmdwait(brdp, portp, A_SETNOTIFY, &nt,
1137 sizeof(asynotify_t), 0)) < 0)
1143 stli_mkasyport(portp, &aport, tty->termios);
1144 if ((rc = stli_cmdwait(brdp, portp, A_SETPORT, &aport,
1145 sizeof(asyport_t), 0)) < 0)
1148 set_bit(ST_GETSIGS, &portp->state);
1149 if ((rc = stli_cmdwait(brdp, portp, A_GETSIGNALS, &portp->asig,
1150 sizeof(asysigs_t), 1)) < 0)
1152 if (test_and_clear_bit(ST_GETSIGS, &portp->state))
1153 portp->sigs = stli_mktiocm(portp->asig.sigvalue);
1154 stli_mkasysigs(&portp->asig, 1, 1);
1155 if ((rc = stli_cmdwait(brdp, portp, A_SETSIGNALS, &portp->asig,
1156 sizeof(asysigs_t), 0)) < 0)
1162 /*****************************************************************************/
1165 * Send an open message to the slave. This will sleep waiting for the
1166 * acknowledgement, so must have user context. We need to co-ordinate
1167 * with close events here, since we don't want open and close events
1171 static int stli_rawopen(stlibrd_t *brdp, stliport_t *portp, unsigned long arg, int wait)
1173 cdkhdr_t __iomem *hdrp;
1174 cdkctrl_t __iomem *cp;
1175 unsigned char __iomem *bits;
1176 unsigned long flags;
1180 * Send a message to the slave to open this port.
1184 * Slave is already closing this port. This can happen if a hangup
1185 * occurs on this port. So we must wait until it is complete. The
1186 * order of opens and closes may not be preserved across shared
1187 * memory, so we must wait until it is complete.
1189 wait_event_interruptible(portp->raw_wait,
1190 !test_bit(ST_CLOSING, &portp->state));
1191 if (signal_pending(current)) {
1192 return -ERESTARTSYS;
1196 * Everything is ready now, so write the open message into shared
1197 * memory. Once the message is in set the service bits to say that
1198 * this port wants service.
1200 spin_lock_irqsave(&brd_lock, flags);
1202 cp = &((cdkasy_t __iomem *) EBRDGETMEMPTR(brdp, portp->addr))->ctrl;
1203 writel(arg, &cp->openarg);
1204 writeb(1, &cp->open);
1205 hdrp = (cdkhdr_t __iomem *) EBRDGETMEMPTR(brdp, CDK_CDKADDR);
1206 bits = ((unsigned char __iomem *) hdrp) + brdp->slaveoffset +
1208 writeb(readb(bits) | portp->portbit, bits);
1212 spin_unlock_irqrestore(&brd_lock, flags);
1217 * Slave is in action, so now we must wait for the open acknowledgment
1221 set_bit(ST_OPENING, &portp->state);
1222 spin_unlock_irqrestore(&brd_lock, flags);
1224 wait_event_interruptible(portp->raw_wait,
1225 !test_bit(ST_OPENING, &portp->state));
1226 if (signal_pending(current))
1229 if ((rc == 0) && (portp->rc != 0))
1234 /*****************************************************************************/
1237 * Send a close message to the slave. Normally this will sleep waiting
1238 * for the acknowledgement, but if wait parameter is 0 it will not. If
1239 * wait is true then must have user context (to sleep).
1242 static int stli_rawclose(stlibrd_t *brdp, stliport_t *portp, unsigned long arg, int wait)
1244 cdkhdr_t __iomem *hdrp;
1245 cdkctrl_t __iomem *cp;
1246 unsigned char __iomem *bits;
1247 unsigned long flags;
1251 * Slave is already closing this port. This can happen if a hangup
1252 * occurs on this port.
1255 wait_event_interruptible(portp->raw_wait,
1256 !test_bit(ST_CLOSING, &portp->state));
1257 if (signal_pending(current)) {
1258 return -ERESTARTSYS;
1263 * Write the close command into shared memory.
1265 spin_lock_irqsave(&brd_lock, flags);
1267 cp = &((cdkasy_t __iomem *) EBRDGETMEMPTR(brdp, portp->addr))->ctrl;
1268 writel(arg, &cp->closearg);
1269 writeb(1, &cp->close);
1270 hdrp = (cdkhdr_t __iomem *) EBRDGETMEMPTR(brdp, CDK_CDKADDR);
1271 bits = ((unsigned char __iomem *) hdrp) + brdp->slaveoffset +
1273 writeb(readb(bits) |portp->portbit, bits);
1276 set_bit(ST_CLOSING, &portp->state);
1277 spin_unlock_irqrestore(&brd_lock, flags);
1283 * Slave is in action, so now we must wait for the open acknowledgment
1287 wait_event_interruptible(portp->raw_wait,
1288 !test_bit(ST_CLOSING, &portp->state));
1289 if (signal_pending(current))
1292 if ((rc == 0) && (portp->rc != 0))
1297 /*****************************************************************************/
1300 * Send a command to the slave and wait for the response. This must
1301 * have user context (it sleeps). This routine is generic in that it
1302 * can send any type of command. Its purpose is to wait for that command
1303 * to complete (as opposed to initiating the command then returning).
1306 static int stli_cmdwait(stlibrd_t *brdp, stliport_t *portp, unsigned long cmd, void *arg, int size, int copyback)
1308 wait_event_interruptible(portp->raw_wait,
1309 !test_bit(ST_CMDING, &portp->state));
1310 if (signal_pending(current))
1311 return -ERESTARTSYS;
1313 stli_sendcmd(brdp, portp, cmd, arg, size, copyback);
1315 wait_event_interruptible(portp->raw_wait,
1316 !test_bit(ST_CMDING, &portp->state));
1317 if (signal_pending(current))
1318 return -ERESTARTSYS;
1325 /*****************************************************************************/
1328 * Send the termios settings for this port to the slave. This sleeps
1329 * waiting for the command to complete - so must have user context.
1332 static int stli_setport(stliport_t *portp)
1339 if (portp->tty == NULL)
1341 if (portp->brdnr < 0 && portp->brdnr >= stli_nrbrds)
1343 brdp = stli_brds[portp->brdnr];
1347 stli_mkasyport(portp, &aport, portp->tty->termios);
1348 return(stli_cmdwait(brdp, portp, A_SETPORT, &aport, sizeof(asyport_t), 0));
1351 /*****************************************************************************/
1354 * Possibly need to wait for carrier (DCD signal) to come high. Say
1355 * maybe because if we are clocal then we don't need to wait...
1358 static int stli_waitcarrier(stlibrd_t *brdp, stliport_t *portp, struct file *filp)
1360 unsigned long flags;
1366 if (portp->tty->termios->c_cflag & CLOCAL)
1369 spin_lock_irqsave(&stli_lock, flags);
1370 portp->openwaitcnt++;
1371 if (! tty_hung_up_p(filp))
1373 spin_unlock_irqrestore(&stli_lock, flags);
1376 stli_mkasysigs(&portp->asig, 1, 1);
1377 if ((rc = stli_cmdwait(brdp, portp, A_SETSIGNALS,
1378 &portp->asig, sizeof(asysigs_t), 0)) < 0)
1380 if (tty_hung_up_p(filp) ||
1381 ((portp->flags & ASYNC_INITIALIZED) == 0)) {
1382 if (portp->flags & ASYNC_HUP_NOTIFY)
1388 if (((portp->flags & ASYNC_CLOSING) == 0) &&
1389 (doclocal || (portp->sigs & TIOCM_CD))) {
1392 if (signal_pending(current)) {
1396 interruptible_sleep_on(&portp->open_wait);
1399 spin_lock_irqsave(&stli_lock, flags);
1400 if (! tty_hung_up_p(filp))
1402 portp->openwaitcnt--;
1403 spin_unlock_irqrestore(&stli_lock, flags);
1408 /*****************************************************************************/
1411 * Write routine. Take the data and put it in the shared memory ring
1412 * queue. If port is not already sending chars then need to mark the
1413 * service bits for this port.
1416 static int stli_write(struct tty_struct *tty, const unsigned char *buf, int count)
1418 cdkasy_t __iomem *ap;
1419 cdkhdr_t __iomem *hdrp;
1420 unsigned char __iomem *bits;
1421 unsigned char __iomem *shbuf;
1422 unsigned char *chbuf;
1425 unsigned int len, stlen, head, tail, size;
1426 unsigned long flags;
1428 if (tty == stli_txcooktty)
1429 stli_flushchars(tty);
1430 portp = tty->driver_data;
1433 if ((portp->brdnr < 0) || (portp->brdnr >= stli_nrbrds))
1435 brdp = stli_brds[portp->brdnr];
1438 chbuf = (unsigned char *) buf;
1441 * All data is now local, shove as much as possible into shared memory.
1443 spin_lock_irqsave(&brd_lock, flags);
1445 ap = (cdkasy_t __iomem *) EBRDGETMEMPTR(brdp, portp->addr);
1446 head = (unsigned int) readw(&ap->txq.head);
1447 tail = (unsigned int) readw(&ap->txq.tail);
1448 if (tail != ((unsigned int) readw(&ap->txq.tail)))
1449 tail = (unsigned int) readw(&ap->txq.tail);
1450 size = portp->txsize;
1452 len = size - (head - tail) - 1;
1453 stlen = size - head;
1455 len = tail - head - 1;
1459 len = MIN(len, count);
1461 shbuf = (char __iomem *) EBRDGETMEMPTR(brdp, portp->txoffset);
1464 stlen = MIN(len, stlen);
1465 memcpy_toio(shbuf + head, chbuf, stlen);
1476 ap = (cdkasy_t __iomem *) EBRDGETMEMPTR(brdp, portp->addr);
1477 writew(head, &ap->txq.head);
1478 if (test_bit(ST_TXBUSY, &portp->state)) {
1479 if (readl(&ap->changed.data) & DT_TXEMPTY)
1480 writel(readl(&ap->changed.data) & ~DT_TXEMPTY, &ap->changed.data);
1482 hdrp = (cdkhdr_t __iomem *) EBRDGETMEMPTR(brdp, CDK_CDKADDR);
1483 bits = ((unsigned char __iomem *) hdrp) + brdp->slaveoffset +
1485 writeb(readb(bits) | portp->portbit, bits);
1486 set_bit(ST_TXBUSY, &portp->state);
1488 spin_unlock_irqrestore(&brd_lock, flags);
1493 /*****************************************************************************/
1496 * Output a single character. We put it into a temporary local buffer
1497 * (for speed) then write out that buffer when the flushchars routine
1498 * is called. There is a safety catch here so that if some other port
1499 * writes chars before the current buffer has been, then we write them
1500 * first them do the new ports.
1503 static void stli_putchar(struct tty_struct *tty, unsigned char ch)
1505 if (tty != stli_txcooktty) {
1506 if (stli_txcooktty != NULL)
1507 stli_flushchars(stli_txcooktty);
1508 stli_txcooktty = tty;
1511 stli_txcookbuf[stli_txcooksize++] = ch;
1514 /*****************************************************************************/
1517 * Transfer characters from the local TX cooking buffer to the board.
1518 * We sort of ignore the tty that gets passed in here. We rely on the
1519 * info stored with the TX cook buffer to tell us which port to flush
1520 * the data on. In any case we clean out the TX cook buffer, for re-use
1524 static void stli_flushchars(struct tty_struct *tty)
1526 cdkhdr_t __iomem *hdrp;
1527 unsigned char __iomem *bits;
1528 cdkasy_t __iomem *ap;
1529 struct tty_struct *cooktty;
1532 unsigned int len, stlen, head, tail, size, count, cooksize;
1534 unsigned char __iomem *shbuf;
1535 unsigned long flags;
1537 cooksize = stli_txcooksize;
1538 cooktty = stli_txcooktty;
1539 stli_txcooksize = 0;
1540 stli_txcookrealsize = 0;
1541 stli_txcooktty = NULL;
1545 if (cooktty == NULL)
1552 portp = tty->driver_data;
1555 if ((portp->brdnr < 0) || (portp->brdnr >= stli_nrbrds))
1557 brdp = stli_brds[portp->brdnr];
1561 spin_lock_irqsave(&brd_lock, flags);
1564 ap = (cdkasy_t __iomem *) EBRDGETMEMPTR(brdp, portp->addr);
1565 head = (unsigned int) readw(&ap->txq.head);
1566 tail = (unsigned int) readw(&ap->txq.tail);
1567 if (tail != ((unsigned int) readw(&ap->txq.tail)))
1568 tail = (unsigned int) readw(&ap->txq.tail);
1569 size = portp->txsize;
1571 len = size - (head - tail) - 1;
1572 stlen = size - head;
1574 len = tail - head - 1;
1578 len = MIN(len, cooksize);
1580 shbuf = (char *) EBRDGETMEMPTR(brdp, portp->txoffset);
1581 buf = stli_txcookbuf;
1584 stlen = MIN(len, stlen);
1585 memcpy_toio(shbuf + head, buf, stlen);
1596 ap = (cdkasy_t __iomem *) EBRDGETMEMPTR(brdp, portp->addr);
1597 writew(head, &ap->txq.head);
1599 if (test_bit(ST_TXBUSY, &portp->state)) {
1600 if (readl(&ap->changed.data) & DT_TXEMPTY)
1601 writel(readl(&ap->changed.data) & ~DT_TXEMPTY, &ap->changed.data);
1603 hdrp = (cdkhdr_t __iomem *) EBRDGETMEMPTR(brdp, CDK_CDKADDR);
1604 bits = ((unsigned char __iomem *) hdrp) + brdp->slaveoffset +
1606 writeb(readb(bits) | portp->portbit, bits);
1607 set_bit(ST_TXBUSY, &portp->state);
1610 spin_unlock_irqrestore(&brd_lock, flags);
1613 /*****************************************************************************/
1615 static int stli_writeroom(struct tty_struct *tty)
1617 cdkasyrq_t __iomem *rp;
1620 unsigned int head, tail, len;
1621 unsigned long flags;
1623 if (tty == stli_txcooktty) {
1624 if (stli_txcookrealsize != 0) {
1625 len = stli_txcookrealsize - stli_txcooksize;
1630 portp = tty->driver_data;
1633 if ((portp->brdnr < 0) || (portp->brdnr >= stli_nrbrds))
1635 brdp = stli_brds[portp->brdnr];
1639 spin_lock_irqsave(&brd_lock, flags);
1641 rp = &((cdkasy_t __iomem *) EBRDGETMEMPTR(brdp, portp->addr))->txq;
1642 head = (unsigned int) readw(&rp->head);
1643 tail = (unsigned int) readw(&rp->tail);
1644 if (tail != ((unsigned int) readw(&rp->tail)))
1645 tail = (unsigned int) readw(&rp->tail);
1646 len = (head >= tail) ? (portp->txsize - (head - tail)) : (tail - head);
1649 spin_unlock_irqrestore(&brd_lock, flags);
1651 if (tty == stli_txcooktty) {
1652 stli_txcookrealsize = len;
1653 len -= stli_txcooksize;
1658 /*****************************************************************************/
1661 * Return the number of characters in the transmit buffer. Normally we
1662 * will return the number of chars in the shared memory ring queue.
1663 * We need to kludge around the case where the shared memory buffer is
1664 * empty but not all characters have drained yet, for this case just
1665 * return that there is 1 character in the buffer!
1668 static int stli_charsinbuffer(struct tty_struct *tty)
1670 cdkasyrq_t __iomem *rp;
1673 unsigned int head, tail, len;
1674 unsigned long flags;
1676 if (tty == stli_txcooktty)
1677 stli_flushchars(tty);
1678 portp = tty->driver_data;
1681 if ((portp->brdnr < 0) || (portp->brdnr >= stli_nrbrds))
1683 brdp = stli_brds[portp->brdnr];
1687 spin_lock_irqsave(&brd_lock, flags);
1689 rp = &((cdkasy_t __iomem *) EBRDGETMEMPTR(brdp, portp->addr))->txq;
1690 head = (unsigned int) readw(&rp->head);
1691 tail = (unsigned int) readw(&rp->tail);
1692 if (tail != ((unsigned int) readw(&rp->tail)))
1693 tail = (unsigned int) readw(&rp->tail);
1694 len = (head >= tail) ? (head - tail) : (portp->txsize - (tail - head));
1695 if ((len == 0) && test_bit(ST_TXBUSY, &portp->state))
1698 spin_unlock_irqrestore(&brd_lock, flags);
1703 /*****************************************************************************/
1706 * Generate the serial struct info.
1709 static int stli_getserial(stliport_t *portp, struct serial_struct __user *sp)
1711 struct serial_struct sio;
1714 memset(&sio, 0, sizeof(struct serial_struct));
1715 sio.type = PORT_UNKNOWN;
1716 sio.line = portp->portnr;
1718 sio.flags = portp->flags;
1719 sio.baud_base = portp->baud_base;
1720 sio.close_delay = portp->close_delay;
1721 sio.closing_wait = portp->closing_wait;
1722 sio.custom_divisor = portp->custom_divisor;
1723 sio.xmit_fifo_size = 0;
1726 brdp = stli_brds[portp->brdnr];
1728 sio.port = brdp->iobase;
1730 return copy_to_user(sp, &sio, sizeof(struct serial_struct)) ?
1734 /*****************************************************************************/
1737 * Set port according to the serial struct info.
1738 * At this point we do not do any auto-configure stuff, so we will
1739 * just quietly ignore any requests to change irq, etc.
1742 static int stli_setserial(stliport_t *portp, struct serial_struct __user *sp)
1744 struct serial_struct sio;
1747 if (copy_from_user(&sio, sp, sizeof(struct serial_struct)))
1749 if (!capable(CAP_SYS_ADMIN)) {
1750 if ((sio.baud_base != portp->baud_base) ||
1751 (sio.close_delay != portp->close_delay) ||
1752 ((sio.flags & ~ASYNC_USR_MASK) !=
1753 (portp->flags & ~ASYNC_USR_MASK)))
1757 portp->flags = (portp->flags & ~ASYNC_USR_MASK) |
1758 (sio.flags & ASYNC_USR_MASK);
1759 portp->baud_base = sio.baud_base;
1760 portp->close_delay = sio.close_delay;
1761 portp->closing_wait = sio.closing_wait;
1762 portp->custom_divisor = sio.custom_divisor;
1764 if ((rc = stli_setport(portp)) < 0)
1769 /*****************************************************************************/
1771 static int stli_tiocmget(struct tty_struct *tty, struct file *file)
1773 stliport_t *portp = tty->driver_data;
1779 if (portp->brdnr < 0 || portp->brdnr >= stli_nrbrds)
1781 brdp = stli_brds[portp->brdnr];
1784 if (tty->flags & (1 << TTY_IO_ERROR))
1787 if ((rc = stli_cmdwait(brdp, portp, A_GETSIGNALS,
1788 &portp->asig, sizeof(asysigs_t), 1)) < 0)
1791 return stli_mktiocm(portp->asig.sigvalue);
1794 static int stli_tiocmset(struct tty_struct *tty, struct file *file,
1795 unsigned int set, unsigned int clear)
1797 stliport_t *portp = tty->driver_data;
1799 int rts = -1, dtr = -1;
1803 if (portp->brdnr < 0 || portp->brdnr >= stli_nrbrds)
1805 brdp = stli_brds[portp->brdnr];
1808 if (tty->flags & (1 << TTY_IO_ERROR))
1811 if (set & TIOCM_RTS)
1813 if (set & TIOCM_DTR)
1815 if (clear & TIOCM_RTS)
1817 if (clear & TIOCM_DTR)
1820 stli_mkasysigs(&portp->asig, dtr, rts);
1822 return stli_cmdwait(brdp, portp, A_SETSIGNALS, &portp->asig,
1823 sizeof(asysigs_t), 0);
1826 static int stli_ioctl(struct tty_struct *tty, struct file *file, unsigned int cmd, unsigned long arg)
1832 void __user *argp = (void __user *)arg;
1834 portp = tty->driver_data;
1837 if (portp->brdnr < 0 || portp->brdnr >= stli_nrbrds)
1839 brdp = stli_brds[portp->brdnr];
1843 if ((cmd != TIOCGSERIAL) && (cmd != TIOCSSERIAL) &&
1844 (cmd != COM_GETPORTSTATS) && (cmd != COM_CLRPORTSTATS)) {
1845 if (tty->flags & (1 << TTY_IO_ERROR))
1853 rc = put_user(((tty->termios->c_cflag & CLOCAL) ? 1 : 0),
1854 (unsigned __user *) arg);
1857 if ((rc = get_user(ival, (unsigned __user *) arg)) == 0)
1858 tty->termios->c_cflag =
1859 (tty->termios->c_cflag & ~CLOCAL) |
1860 (ival ? CLOCAL : 0);
1863 rc = stli_getserial(portp, argp);
1866 rc = stli_setserial(portp, argp);
1869 rc = put_user(portp->pflag, (unsigned __user *)argp);
1872 if ((rc = get_user(portp->pflag, (unsigned __user *)argp)) == 0)
1873 stli_setport(portp);
1875 case COM_GETPORTSTATS:
1876 rc = stli_getportstats(portp, argp);
1878 case COM_CLRPORTSTATS:
1879 rc = stli_clrportstats(portp, argp);
1885 case TIOCSERGSTRUCT:
1886 case TIOCSERGETMULTI:
1887 case TIOCSERSETMULTI:
1896 /*****************************************************************************/
1899 * This routine assumes that we have user context and can sleep.
1900 * Looks like it is true for the current ttys implementation..!!
1903 static void stli_settermios(struct tty_struct *tty, struct termios *old)
1907 struct termios *tiosp;
1912 portp = tty->driver_data;
1915 if (portp->brdnr < 0 || portp->brdnr >= stli_nrbrds)
1917 brdp = stli_brds[portp->brdnr];
1921 tiosp = tty->termios;
1922 if ((tiosp->c_cflag == old->c_cflag) &&
1923 (tiosp->c_iflag == old->c_iflag))
1926 stli_mkasyport(portp, &aport, tiosp);
1927 stli_cmdwait(brdp, portp, A_SETPORT, &aport, sizeof(asyport_t), 0);
1928 stli_mkasysigs(&portp->asig, ((tiosp->c_cflag & CBAUD) ? 1 : 0), -1);
1929 stli_cmdwait(brdp, portp, A_SETSIGNALS, &portp->asig,
1930 sizeof(asysigs_t), 0);
1931 if ((old->c_cflag & CRTSCTS) && ((tiosp->c_cflag & CRTSCTS) == 0))
1932 tty->hw_stopped = 0;
1933 if (((old->c_cflag & CLOCAL) == 0) && (tiosp->c_cflag & CLOCAL))
1934 wake_up_interruptible(&portp->open_wait);
1937 /*****************************************************************************/
1940 * Attempt to flow control who ever is sending us data. We won't really
1941 * do any flow control action here. We can't directly, and even if we
1942 * wanted to we would have to send a command to the slave. The slave
1943 * knows how to flow control, and will do so when its buffers reach its
1944 * internal high water marks. So what we will do is set a local state
1945 * bit that will stop us sending any RX data up from the poll routine
1946 * (which is the place where RX data from the slave is handled).
1949 static void stli_throttle(struct tty_struct *tty)
1951 stliport_t *portp = tty->driver_data;
1954 set_bit(ST_RXSTOP, &portp->state);
1957 /*****************************************************************************/
1960 * Unflow control the device sending us data... That means that all
1961 * we have to do is clear the RXSTOP state bit. The next poll call
1962 * will then be able to pass the RX data back up.
1965 static void stli_unthrottle(struct tty_struct *tty)
1967 stliport_t *portp = tty->driver_data;
1970 clear_bit(ST_RXSTOP, &portp->state);
1973 /*****************************************************************************/
1976 * Stop the transmitter.
1979 static void stli_stop(struct tty_struct *tty)
1983 /*****************************************************************************/
1986 * Start the transmitter again.
1989 static void stli_start(struct tty_struct *tty)
1993 /*****************************************************************************/
1996 * Scheduler called hang up routine. This is called from the scheduler,
1997 * not direct from the driver "poll" routine. We can't call it there
1998 * since the real local hangup code will enable/disable the board and
1999 * other things that we can't do while handling the poll. Much easier
2000 * to deal with it some time later (don't really care when, hangups
2001 * aren't that time critical).
2004 static void stli_dohangup(void *arg)
2006 stliport_t *portp = (stliport_t *) arg;
2007 if (portp->tty != NULL) {
2008 tty_hangup(portp->tty);
2012 /*****************************************************************************/
2015 * Hangup this port. This is pretty much like closing the port, only
2016 * a little more brutal. No waiting for data to drain. Shutdown the
2017 * port and maybe drop signals. This is rather tricky really. We want
2018 * to close the port as well.
2021 static void stli_hangup(struct tty_struct *tty)
2025 unsigned long flags;
2027 portp = tty->driver_data;
2030 if (portp->brdnr < 0 || portp->brdnr >= stli_nrbrds)
2032 brdp = stli_brds[portp->brdnr];
2036 portp->flags &= ~ASYNC_INITIALIZED;
2038 if (!test_bit(ST_CLOSING, &portp->state))
2039 stli_rawclose(brdp, portp, 0, 0);
2041 spin_lock_irqsave(&stli_lock, flags);
2042 if (tty->termios->c_cflag & HUPCL) {
2043 stli_mkasysigs(&portp->asig, 0, 0);
2044 if (test_bit(ST_CMDING, &portp->state)) {
2045 set_bit(ST_DOSIGS, &portp->state);
2046 set_bit(ST_DOFLUSHTX, &portp->state);
2047 set_bit(ST_DOFLUSHRX, &portp->state);
2049 stli_sendcmd(brdp, portp, A_SETSIGNALSF,
2050 &portp->asig, sizeof(asysigs_t), 0);
2054 clear_bit(ST_TXBUSY, &portp->state);
2055 clear_bit(ST_RXSTOP, &portp->state);
2056 set_bit(TTY_IO_ERROR, &tty->flags);
2058 portp->flags &= ~ASYNC_NORMAL_ACTIVE;
2059 portp->refcount = 0;
2060 spin_unlock_irqrestore(&stli_lock, flags);
2062 wake_up_interruptible(&portp->open_wait);
2065 /*****************************************************************************/
2068 * Flush characters from the lower buffer. We may not have user context
2069 * so we cannot sleep waiting for it to complete. Also we need to check
2070 * if there is chars for this port in the TX cook buffer, and flush them
2074 static void stli_flushbuffer(struct tty_struct *tty)
2078 unsigned long ftype, flags;
2080 portp = tty->driver_data;
2083 if (portp->brdnr < 0 || portp->brdnr >= stli_nrbrds)
2085 brdp = stli_brds[portp->brdnr];
2089 spin_lock_irqsave(&brd_lock, flags);
2090 if (tty == stli_txcooktty) {
2091 stli_txcooktty = NULL;
2092 stli_txcooksize = 0;
2093 stli_txcookrealsize = 0;
2095 if (test_bit(ST_CMDING, &portp->state)) {
2096 set_bit(ST_DOFLUSHTX, &portp->state);
2099 if (test_bit(ST_DOFLUSHRX, &portp->state)) {
2101 clear_bit(ST_DOFLUSHRX, &portp->state);
2103 __stli_sendcmd(brdp, portp, A_FLUSH, &ftype, sizeof(u32), 0);
2105 spin_unlock_irqrestore(&brd_lock, flags);
2109 /*****************************************************************************/
2111 static void stli_breakctl(struct tty_struct *tty, int state)
2117 portp = tty->driver_data;
2120 if (portp->brdnr < 0 || portp->brdnr >= stli_nrbrds)
2122 brdp = stli_brds[portp->brdnr];
2126 arg = (state == -1) ? BREAKON : BREAKOFF;
2127 stli_cmdwait(brdp, portp, A_BREAK, &arg, sizeof(long), 0);
2130 /*****************************************************************************/
2132 static void stli_waituntilsent(struct tty_struct *tty, int timeout)
2139 portp = tty->driver_data;
2145 tend = jiffies + timeout;
2147 while (test_bit(ST_TXBUSY, &portp->state)) {
2148 if (signal_pending(current))
2150 msleep_interruptible(20);
2151 if (time_after_eq(jiffies, tend))
2156 /*****************************************************************************/
2158 static void stli_sendxchar(struct tty_struct *tty, char ch)
2164 portp = tty->driver_data;
2167 if (portp->brdnr < 0 || portp->brdnr >= stli_nrbrds)
2169 brdp = stli_brds[portp->brdnr];
2173 memset(&actrl, 0, sizeof(asyctrl_t));
2174 if (ch == STOP_CHAR(tty)) {
2175 actrl.rxctrl = CT_STOPFLOW;
2176 } else if (ch == START_CHAR(tty)) {
2177 actrl.rxctrl = CT_STARTFLOW;
2179 actrl.txctrl = CT_SENDCHR;
2182 stli_cmdwait(brdp, portp, A_PORTCTRL, &actrl, sizeof(asyctrl_t), 0);
2185 /*****************************************************************************/
2190 * Format info for a specified port. The line is deliberately limited
2191 * to 80 characters. (If it is too long it will be truncated, if too
2192 * short then padded with spaces).
2195 static int stli_portinfo(stlibrd_t *brdp, stliport_t *portp, int portnr, char *pos)
2200 rc = stli_portcmdstats(portp);
2203 if (brdp->state & BST_STARTED) {
2204 switch (stli_comstats.hwid) {
2205 case 0: uart = "2681"; break;
2206 case 1: uart = "SC26198"; break;
2207 default:uart = "CD1400"; break;
2212 sp += sprintf(sp, "%d: uart:%s ", portnr, uart);
2214 if ((brdp->state & BST_STARTED) && (rc >= 0)) {
2215 sp += sprintf(sp, "tx:%d rx:%d", (int) stli_comstats.txtotal,
2216 (int) stli_comstats.rxtotal);
2218 if (stli_comstats.rxframing)
2219 sp += sprintf(sp, " fe:%d",
2220 (int) stli_comstats.rxframing);
2221 if (stli_comstats.rxparity)
2222 sp += sprintf(sp, " pe:%d",
2223 (int) stli_comstats.rxparity);
2224 if (stli_comstats.rxbreaks)
2225 sp += sprintf(sp, " brk:%d",
2226 (int) stli_comstats.rxbreaks);
2227 if (stli_comstats.rxoverrun)
2228 sp += sprintf(sp, " oe:%d",
2229 (int) stli_comstats.rxoverrun);
2231 cnt = sprintf(sp, "%s%s%s%s%s ",
2232 (stli_comstats.signals & TIOCM_RTS) ? "|RTS" : "",
2233 (stli_comstats.signals & TIOCM_CTS) ? "|CTS" : "",
2234 (stli_comstats.signals & TIOCM_DTR) ? "|DTR" : "",
2235 (stli_comstats.signals & TIOCM_CD) ? "|DCD" : "",
2236 (stli_comstats.signals & TIOCM_DSR) ? "|DSR" : "");
2241 for (cnt = (sp - pos); (cnt < (MAXLINE - 1)); cnt++)
2244 pos[(MAXLINE - 2)] = '+';
2245 pos[(MAXLINE - 1)] = '\n';
2250 /*****************************************************************************/
2253 * Port info, read from the /proc file system.
2256 static int stli_readproc(char *page, char **start, off_t off, int count, int *eof, void *data)
2260 int brdnr, portnr, totalport;
2269 pos += sprintf(pos, "%s: version %s", stli_drvtitle,
2271 while (pos < (page + MAXLINE - 1))
2278 * We scan through for each board, panel and port. The offset is
2279 * calculated on the fly, and irrelevant ports are skipped.
2281 for (brdnr = 0; (brdnr < stli_nrbrds); brdnr++) {
2282 brdp = stli_brds[brdnr];
2285 if (brdp->state == 0)
2288 maxoff = curoff + (brdp->nrports * MAXLINE);
2289 if (off >= maxoff) {
2294 totalport = brdnr * STL_MAXPORTS;
2295 for (portnr = 0; (portnr < brdp->nrports); portnr++,
2297 portp = brdp->ports[portnr];
2300 if (off >= (curoff += MAXLINE))
2302 if ((pos - page + MAXLINE) > count)
2304 pos += stli_portinfo(brdp, portp, totalport, pos);
2315 /*****************************************************************************/
2318 * Generic send command routine. This will send a message to the slave,
2319 * of the specified type with the specified argument. Must be very
2320 * careful of data that will be copied out from shared memory -
2321 * containing command results. The command completion is all done from
2322 * a poll routine that does not have user context. Therefore you cannot
2323 * copy back directly into user space, or to the kernel stack of a
2324 * process. This routine does not sleep, so can be called from anywhere.
2326 * The caller must hold the brd_lock (see also stli_sendcmd the usual
2330 static void __stli_sendcmd(stlibrd_t *brdp, stliport_t *portp, unsigned long cmd, void *arg, int size, int copyback)
2332 cdkhdr_t __iomem *hdrp;
2333 cdkctrl_t __iomem *cp;
2334 unsigned char __iomem *bits;
2335 unsigned long flags;
2337 spin_lock_irqsave(&brd_lock, flags);
2339 if (test_bit(ST_CMDING, &portp->state)) {
2340 printk(KERN_ERR "STALLION: command already busy, cmd=%x!\n",
2342 spin_unlock_irqrestore(&brd_lock, flags);
2347 cp = &((cdkasy_t __iomem *) EBRDGETMEMPTR(brdp, portp->addr))->ctrl;
2349 memcpy_toio((void __iomem *) &(cp->args[0]), arg, size);
2352 portp->argsize = size;
2355 writel(0, &cp->status);
2356 writel(cmd, &cp->cmd);
2357 hdrp = (cdkhdr_t __iomem *) EBRDGETMEMPTR(brdp, CDK_CDKADDR);
2358 bits = ((unsigned char __iomem *) hdrp) + brdp->slaveoffset +
2360 writeb(readb(bits) | portp->portbit, bits);
2361 set_bit(ST_CMDING, &portp->state);
2363 spin_unlock_irqrestore(&brd_lock, flags);
2366 static void stli_sendcmd(stlibrd_t *brdp, stliport_t *portp, unsigned long cmd, void *arg, int size, int copyback)
2368 unsigned long flags;
2370 spin_lock_irqsave(&brd_lock, flags);
2371 __stli_sendcmd(brdp, portp, cmd, arg, size, copyback);
2372 spin_unlock_irqrestore(&brd_lock, flags);
2375 /*****************************************************************************/
2378 * Read data from shared memory. This assumes that the shared memory
2379 * is enabled and that interrupts are off. Basically we just empty out
2380 * the shared memory buffer into the tty buffer. Must be careful to
2381 * handle the case where we fill up the tty buffer, but still have
2382 * more chars to unload.
2385 static void stli_read(stlibrd_t *brdp, stliport_t *portp)
2387 cdkasyrq_t __iomem *rp;
2388 char __iomem *shbuf;
2389 struct tty_struct *tty;
2390 unsigned int head, tail, size;
2391 unsigned int len, stlen;
2393 if (test_bit(ST_RXSTOP, &portp->state))
2399 rp = &((cdkasy_t __iomem *) EBRDGETMEMPTR(brdp, portp->addr))->rxq;
2400 head = (unsigned int) readw(&rp->head);
2401 if (head != ((unsigned int) readw(&rp->head)))
2402 head = (unsigned int) readw(&rp->head);
2403 tail = (unsigned int) readw(&rp->tail);
2404 size = portp->rxsize;
2409 len = size - (tail - head);
2410 stlen = size - tail;
2413 len = tty_buffer_request_room(tty, len);
2415 shbuf = (char __iomem *) EBRDGETMEMPTR(brdp, portp->rxoffset);
2418 unsigned char *cptr;
2420 stlen = MIN(len, stlen);
2421 tty_prepare_flip_string(tty, &cptr, stlen);
2422 memcpy_fromio(cptr, shbuf + tail, stlen);
2430 rp = &((cdkasy_t __iomem *) EBRDGETMEMPTR(brdp, portp->addr))->rxq;
2431 writew(tail, &rp->tail);
2434 set_bit(ST_RXING, &portp->state);
2436 tty_schedule_flip(tty);
2439 /*****************************************************************************/
2442 * Set up and carry out any delayed commands. There is only a small set
2443 * of slave commands that can be done "off-level". So it is not too
2444 * difficult to deal with them here.
2447 static void stli_dodelaycmd(stliport_t *portp, cdkctrl_t __iomem *cp)
2451 if (test_bit(ST_DOSIGS, &portp->state)) {
2452 if (test_bit(ST_DOFLUSHTX, &portp->state) &&
2453 test_bit(ST_DOFLUSHRX, &portp->state))
2454 cmd = A_SETSIGNALSF;
2455 else if (test_bit(ST_DOFLUSHTX, &portp->state))
2456 cmd = A_SETSIGNALSFTX;
2457 else if (test_bit(ST_DOFLUSHRX, &portp->state))
2458 cmd = A_SETSIGNALSFRX;
2461 clear_bit(ST_DOFLUSHTX, &portp->state);
2462 clear_bit(ST_DOFLUSHRX, &portp->state);
2463 clear_bit(ST_DOSIGS, &portp->state);
2464 memcpy_toio((void __iomem *) &(cp->args[0]), (void *) &portp->asig,
2466 writel(0, &cp->status);
2467 writel(cmd, &cp->cmd);
2468 set_bit(ST_CMDING, &portp->state);
2469 } else if (test_bit(ST_DOFLUSHTX, &portp->state) ||
2470 test_bit(ST_DOFLUSHRX, &portp->state)) {
2471 cmd = ((test_bit(ST_DOFLUSHTX, &portp->state)) ? FLUSHTX : 0);
2472 cmd |= ((test_bit(ST_DOFLUSHRX, &portp->state)) ? FLUSHRX : 0);
2473 clear_bit(ST_DOFLUSHTX, &portp->state);
2474 clear_bit(ST_DOFLUSHRX, &portp->state);
2475 memcpy_toio((void __iomem *) &(cp->args[0]), (void *) &cmd, sizeof(int));
2476 writel(0, &cp->status);
2477 writel(A_FLUSH, &cp->cmd);
2478 set_bit(ST_CMDING, &portp->state);
2482 /*****************************************************************************/
2485 * Host command service checking. This handles commands or messages
2486 * coming from the slave to the host. Must have board shared memory
2487 * enabled and interrupts off when called. Notice that by servicing the
2488 * read data last we don't need to change the shared memory pointer
2489 * during processing (which is a slow IO operation).
2490 * Return value indicates if this port is still awaiting actions from
2491 * the slave (like open, command, or even TX data being sent). If 0
2492 * then port is still busy, otherwise no longer busy.
2495 static int stli_hostcmd(stlibrd_t *brdp, stliport_t *portp)
2497 cdkasy_t __iomem *ap;
2498 cdkctrl_t __iomem *cp;
2499 struct tty_struct *tty;
2501 unsigned long oldsigs;
2504 ap = (cdkasy_t __iomem *) EBRDGETMEMPTR(brdp, portp->addr);
2508 * Check if we are waiting for an open completion message.
2510 if (test_bit(ST_OPENING, &portp->state)) {
2511 rc = readl(&cp->openarg);
2512 if (readb(&cp->open) == 0 && rc != 0) {
2515 writel(0, &cp->openarg);
2517 clear_bit(ST_OPENING, &portp->state);
2518 wake_up_interruptible(&portp->raw_wait);
2523 * Check if we are waiting for a close completion message.
2525 if (test_bit(ST_CLOSING, &portp->state)) {
2526 rc = (int) readl(&cp->closearg);
2527 if (readb(&cp->close) == 0 && rc != 0) {
2530 writel(0, &cp->closearg);
2532 clear_bit(ST_CLOSING, &portp->state);
2533 wake_up_interruptible(&portp->raw_wait);
2538 * Check if we are waiting for a command completion message. We may
2539 * need to copy out the command results associated with this command.
2541 if (test_bit(ST_CMDING, &portp->state)) {
2542 rc = readl(&cp->status);
2543 if (readl(&cp->cmd) == 0 && rc != 0) {
2546 if (portp->argp != NULL) {
2547 memcpy_fromio(portp->argp, (void __iomem *) &(cp->args[0]),
2551 writel(0, &cp->status);
2553 clear_bit(ST_CMDING, &portp->state);
2554 stli_dodelaycmd(portp, cp);
2555 wake_up_interruptible(&portp->raw_wait);
2560 * Check for any notification messages ready. This includes lots of
2561 * different types of events - RX chars ready, RX break received,
2562 * TX data low or empty in the slave, modem signals changed state.
2571 if (nt.signal & SG_DCD) {
2572 oldsigs = portp->sigs;
2573 portp->sigs = stli_mktiocm(nt.sigvalue);
2574 clear_bit(ST_GETSIGS, &portp->state);
2575 if ((portp->sigs & TIOCM_CD) &&
2576 ((oldsigs & TIOCM_CD) == 0))
2577 wake_up_interruptible(&portp->open_wait);
2578 if ((oldsigs & TIOCM_CD) &&
2579 ((portp->sigs & TIOCM_CD) == 0)) {
2580 if (portp->flags & ASYNC_CHECK_CD) {
2582 schedule_work(&portp->tqhangup);
2587 if (nt.data & DT_TXEMPTY)
2588 clear_bit(ST_TXBUSY, &portp->state);
2589 if (nt.data & (DT_TXEMPTY | DT_TXLOW)) {
2593 wake_up_interruptible(&tty->write_wait);
2597 if ((nt.data & DT_RXBREAK) && (portp->rxmarkmsk & BRKINT)) {
2599 tty_insert_flip_char(tty, 0, TTY_BREAK);
2600 if (portp->flags & ASYNC_SAK) {
2604 tty_schedule_flip(tty);
2608 if (nt.data & DT_RXBUSY) {
2610 stli_read(brdp, portp);
2615 * It might seem odd that we are checking for more RX chars here.
2616 * But, we need to handle the case where the tty buffer was previously
2617 * filled, but we had more characters to pass up. The slave will not
2618 * send any more RX notify messages until the RX buffer has been emptied.
2619 * But it will leave the service bits on (since the buffer is not empty).
2620 * So from here we can try to process more RX chars.
2622 if ((!donerx) && test_bit(ST_RXING, &portp->state)) {
2623 clear_bit(ST_RXING, &portp->state);
2624 stli_read(brdp, portp);
2627 return((test_bit(ST_OPENING, &portp->state) ||
2628 test_bit(ST_CLOSING, &portp->state) ||
2629 test_bit(ST_CMDING, &portp->state) ||
2630 test_bit(ST_TXBUSY, &portp->state) ||
2631 test_bit(ST_RXING, &portp->state)) ? 0 : 1);
2634 /*****************************************************************************/
2637 * Service all ports on a particular board. Assumes that the boards
2638 * shared memory is enabled, and that the page pointer is pointed
2639 * at the cdk header structure.
2642 static void stli_brdpoll(stlibrd_t *brdp, cdkhdr_t __iomem *hdrp)
2645 unsigned char hostbits[(STL_MAXCHANS / 8) + 1];
2646 unsigned char slavebits[(STL_MAXCHANS / 8) + 1];
2647 unsigned char __iomem *slavep;
2648 int bitpos, bitat, bitsize;
2649 int channr, nrdevs, slavebitchange;
2651 bitsize = brdp->bitsize;
2652 nrdevs = brdp->nrdevs;
2655 * Check if slave wants any service. Basically we try to do as
2656 * little work as possible here. There are 2 levels of service
2657 * bits. So if there is nothing to do we bail early. We check
2658 * 8 service bits at a time in the inner loop, so we can bypass
2659 * the lot if none of them want service.
2661 memcpy_fromio(&hostbits[0], (((unsigned char __iomem *) hdrp) + brdp->hostoffset),
2664 memset(&slavebits[0], 0, bitsize);
2667 for (bitpos = 0; (bitpos < bitsize); bitpos++) {
2668 if (hostbits[bitpos] == 0)
2670 channr = bitpos * 8;
2671 for (bitat = 0x1; (channr < nrdevs); channr++, bitat <<= 1) {
2672 if (hostbits[bitpos] & bitat) {
2673 portp = brdp->ports[(channr - 1)];
2674 if (stli_hostcmd(brdp, portp)) {
2676 slavebits[bitpos] |= bitat;
2683 * If any of the ports are no longer busy then update them in the
2684 * slave request bits. We need to do this after, since a host port
2685 * service may initiate more slave requests.
2687 if (slavebitchange) {
2688 hdrp = (cdkhdr_t __iomem *) EBRDGETMEMPTR(brdp, CDK_CDKADDR);
2689 slavep = ((unsigned char __iomem *) hdrp) + brdp->slaveoffset;
2690 for (bitpos = 0; (bitpos < bitsize); bitpos++) {
2691 if (readb(slavebits + bitpos))
2692 writeb(readb(slavep + bitpos) & ~slavebits[bitpos], slavebits + bitpos);
2697 /*****************************************************************************/
2700 * Driver poll routine. This routine polls the boards in use and passes
2701 * messages back up to host when necessary. This is actually very
2702 * CPU efficient, since we will always have the kernel poll clock, it
2703 * adds only a few cycles when idle (since board service can be
2704 * determined very easily), but when loaded generates no interrupts
2705 * (with their expensive associated context change).
2708 static void stli_poll(unsigned long arg)
2710 cdkhdr_t __iomem *hdrp;
2714 stli_timerlist.expires = STLI_TIMEOUT;
2715 add_timer(&stli_timerlist);
2718 * Check each board and do any servicing required.
2720 for (brdnr = 0; (brdnr < stli_nrbrds); brdnr++) {
2721 brdp = stli_brds[brdnr];
2724 if ((brdp->state & BST_STARTED) == 0)
2727 spin_lock(&brd_lock);
2729 hdrp = (cdkhdr_t __iomem *) EBRDGETMEMPTR(brdp, CDK_CDKADDR);
2730 if (readb(&hdrp->hostreq))
2731 stli_brdpoll(brdp, hdrp);
2733 spin_unlock(&brd_lock);
2737 /*****************************************************************************/
2740 * Translate the termios settings into the port setting structure of
2744 static void stli_mkasyport(stliport_t *portp, asyport_t *pp, struct termios *tiosp)
2746 memset(pp, 0, sizeof(asyport_t));
2749 * Start of by setting the baud, char size, parity and stop bit info.
2751 pp->baudout = tiosp->c_cflag & CBAUD;
2752 if (pp->baudout & CBAUDEX) {
2753 pp->baudout &= ~CBAUDEX;
2754 if ((pp->baudout < 1) || (pp->baudout > 4))
2755 tiosp->c_cflag &= ~CBAUDEX;
2759 pp->baudout = stli_baudrates[pp->baudout];
2760 if ((tiosp->c_cflag & CBAUD) == B38400) {
2761 if ((portp->flags & ASYNC_SPD_MASK) == ASYNC_SPD_HI)
2762 pp->baudout = 57600;
2763 else if ((portp->flags & ASYNC_SPD_MASK) == ASYNC_SPD_VHI)
2764 pp->baudout = 115200;
2765 else if ((portp->flags & ASYNC_SPD_MASK) == ASYNC_SPD_SHI)
2766 pp->baudout = 230400;
2767 else if ((portp->flags & ASYNC_SPD_MASK) == ASYNC_SPD_WARP)
2768 pp->baudout = 460800;
2769 else if ((portp->flags & ASYNC_SPD_MASK) == ASYNC_SPD_CUST)
2770 pp->baudout = (portp->baud_base / portp->custom_divisor);
2772 if (pp->baudout > STL_MAXBAUD)
2773 pp->baudout = STL_MAXBAUD;
2774 pp->baudin = pp->baudout;
2776 switch (tiosp->c_cflag & CSIZE) {
2791 if (tiosp->c_cflag & CSTOPB)
2792 pp->stopbs = PT_STOP2;
2794 pp->stopbs = PT_STOP1;
2796 if (tiosp->c_cflag & PARENB) {
2797 if (tiosp->c_cflag & PARODD)
2798 pp->parity = PT_ODDPARITY;
2800 pp->parity = PT_EVENPARITY;
2802 pp->parity = PT_NOPARITY;
2806 * Set up any flow control options enabled.
2808 if (tiosp->c_iflag & IXON) {
2810 if (tiosp->c_iflag & IXANY)
2811 pp->flow |= F_IXANY;
2813 if (tiosp->c_cflag & CRTSCTS)
2814 pp->flow |= (F_RTSFLOW | F_CTSFLOW);
2816 pp->startin = tiosp->c_cc[VSTART];
2817 pp->stopin = tiosp->c_cc[VSTOP];
2818 pp->startout = tiosp->c_cc[VSTART];
2819 pp->stopout = tiosp->c_cc[VSTOP];
2822 * Set up the RX char marking mask with those RX error types we must
2823 * catch. We can get the slave to help us out a little here, it will
2824 * ignore parity errors and breaks for us, and mark parity errors in
2827 if (tiosp->c_iflag & IGNPAR)
2828 pp->iflag |= FI_IGNRXERRS;
2829 if (tiosp->c_iflag & IGNBRK)
2830 pp->iflag |= FI_IGNBREAK;
2832 portp->rxmarkmsk = 0;
2833 if (tiosp->c_iflag & (INPCK | PARMRK))
2834 pp->iflag |= FI_1MARKRXERRS;
2835 if (tiosp->c_iflag & BRKINT)
2836 portp->rxmarkmsk |= BRKINT;
2839 * Set up clocal processing as required.
2841 if (tiosp->c_cflag & CLOCAL)
2842 portp->flags &= ~ASYNC_CHECK_CD;
2844 portp->flags |= ASYNC_CHECK_CD;
2847 * Transfer any persistent flags into the asyport structure.
2849 pp->pflag = (portp->pflag & 0xffff);
2850 pp->vmin = (portp->pflag & P_RXIMIN) ? 1 : 0;
2851 pp->vtime = (portp->pflag & P_RXITIME) ? 1 : 0;
2852 pp->cc[1] = (portp->pflag & P_RXTHOLD) ? 1 : 0;
2855 /*****************************************************************************/
2858 * Construct a slave signals structure for setting the DTR and RTS
2859 * signals as specified.
2862 static void stli_mkasysigs(asysigs_t *sp, int dtr, int rts)
2864 memset(sp, 0, sizeof(asysigs_t));
2866 sp->signal |= SG_DTR;
2867 sp->sigvalue |= ((dtr > 0) ? SG_DTR : 0);
2870 sp->signal |= SG_RTS;
2871 sp->sigvalue |= ((rts > 0) ? SG_RTS : 0);
2875 /*****************************************************************************/
2878 * Convert the signals returned from the slave into a local TIOCM type
2879 * signals value. We keep them locally in TIOCM format.
2882 static long stli_mktiocm(unsigned long sigvalue)
2885 tiocm |= ((sigvalue & SG_DCD) ? TIOCM_CD : 0);
2886 tiocm |= ((sigvalue & SG_CTS) ? TIOCM_CTS : 0);
2887 tiocm |= ((sigvalue & SG_RI) ? TIOCM_RI : 0);
2888 tiocm |= ((sigvalue & SG_DSR) ? TIOCM_DSR : 0);
2889 tiocm |= ((sigvalue & SG_DTR) ? TIOCM_DTR : 0);
2890 tiocm |= ((sigvalue & SG_RTS) ? TIOCM_RTS : 0);
2894 /*****************************************************************************/
2897 * All panels and ports actually attached have been worked out. All
2898 * we need to do here is set up the appropriate per port data structures.
2901 static int stli_initports(stlibrd_t *brdp)
2904 int i, panelnr, panelport;
2906 for (i = 0, panelnr = 0, panelport = 0; (i < brdp->nrports); i++) {
2907 portp = kzalloc(sizeof(stliport_t), GFP_KERNEL);
2909 printk("STALLION: failed to allocate port structure\n");
2913 portp->magic = STLI_PORTMAGIC;
2915 portp->brdnr = brdp->brdnr;
2916 portp->panelnr = panelnr;
2917 portp->baud_base = STL_BAUDBASE;
2918 portp->close_delay = STL_CLOSEDELAY;
2919 portp->closing_wait = 30 * HZ;
2920 INIT_WORK(&portp->tqhangup, stli_dohangup, portp);
2921 init_waitqueue_head(&portp->open_wait);
2922 init_waitqueue_head(&portp->close_wait);
2923 init_waitqueue_head(&portp->raw_wait);
2925 if (panelport >= brdp->panels[panelnr]) {
2929 brdp->ports[i] = portp;
2935 /*****************************************************************************/
2938 * All the following routines are board specific hardware operations.
2941 static void stli_ecpinit(stlibrd_t *brdp)
2943 unsigned long memconf;
2945 outb(ECP_ATSTOP, (brdp->iobase + ECP_ATCONFR));
2947 outb(ECP_ATDISABLE, (brdp->iobase + ECP_ATCONFR));
2950 memconf = (brdp->memaddr & ECP_ATADDRMASK) >> ECP_ATADDRSHFT;
2951 outb(memconf, (brdp->iobase + ECP_ATMEMAR));
2954 /*****************************************************************************/
2956 static void stli_ecpenable(stlibrd_t *brdp)
2958 outb(ECP_ATENABLE, (brdp->iobase + ECP_ATCONFR));
2961 /*****************************************************************************/
2963 static void stli_ecpdisable(stlibrd_t *brdp)
2965 outb(ECP_ATDISABLE, (brdp->iobase + ECP_ATCONFR));
2968 /*****************************************************************************/
2970 static char *stli_ecpgetmemptr(stlibrd_t *brdp, unsigned long offset, int line)
2975 if (offset > brdp->memsize) {
2976 printk(KERN_ERR "STALLION: shared memory pointer=%x out of "
2977 "range at line=%d(%d), brd=%d\n",
2978 (int) offset, line, __LINE__, brdp->brdnr);
2982 ptr = brdp->membase + (offset % ECP_ATPAGESIZE);
2983 val = (unsigned char) (offset / ECP_ATPAGESIZE);
2985 outb(val, (brdp->iobase + ECP_ATMEMPR));
2989 /*****************************************************************************/
2991 static void stli_ecpreset(stlibrd_t *brdp)
2993 outb(ECP_ATSTOP, (brdp->iobase + ECP_ATCONFR));
2995 outb(ECP_ATDISABLE, (brdp->iobase + ECP_ATCONFR));
2999 /*****************************************************************************/
3001 static void stli_ecpintr(stlibrd_t *brdp)
3003 outb(0x1, brdp->iobase);
3006 /*****************************************************************************/
3009 * The following set of functions act on ECP EISA boards.
3012 static void stli_ecpeiinit(stlibrd_t *brdp)
3014 unsigned long memconf;
3016 outb(0x1, (brdp->iobase + ECP_EIBRDENAB));
3017 outb(ECP_EISTOP, (brdp->iobase + ECP_EICONFR));
3019 outb(ECP_EIDISABLE, (brdp->iobase + ECP_EICONFR));
3022 memconf = (brdp->memaddr & ECP_EIADDRMASKL) >> ECP_EIADDRSHFTL;
3023 outb(memconf, (brdp->iobase + ECP_EIMEMARL));
3024 memconf = (brdp->memaddr & ECP_EIADDRMASKH) >> ECP_EIADDRSHFTH;
3025 outb(memconf, (brdp->iobase + ECP_EIMEMARH));
3028 /*****************************************************************************/
3030 static void stli_ecpeienable(stlibrd_t *brdp)
3032 outb(ECP_EIENABLE, (brdp->iobase + ECP_EICONFR));
3035 /*****************************************************************************/
3037 static void stli_ecpeidisable(stlibrd_t *brdp)
3039 outb(ECP_EIDISABLE, (brdp->iobase + ECP_EICONFR));
3042 /*****************************************************************************/
3044 static char *stli_ecpeigetmemptr(stlibrd_t *brdp, unsigned long offset, int line)
3049 if (offset > brdp->memsize) {
3050 printk(KERN_ERR "STALLION: shared memory pointer=%x out of "
3051 "range at line=%d(%d), brd=%d\n",
3052 (int) offset, line, __LINE__, brdp->brdnr);
3056 ptr = brdp->membase + (offset % ECP_EIPAGESIZE);
3057 if (offset < ECP_EIPAGESIZE)
3060 val = ECP_EIENABLE | 0x40;
3062 outb(val, (brdp->iobase + ECP_EICONFR));
3066 /*****************************************************************************/
3068 static void stli_ecpeireset(stlibrd_t *brdp)
3070 outb(ECP_EISTOP, (brdp->iobase + ECP_EICONFR));
3072 outb(ECP_EIDISABLE, (brdp->iobase + ECP_EICONFR));
3076 /*****************************************************************************/
3079 * The following set of functions act on ECP MCA boards.
3082 static void stli_ecpmcenable(stlibrd_t *brdp)
3084 outb(ECP_MCENABLE, (brdp->iobase + ECP_MCCONFR));
3087 /*****************************************************************************/
3089 static void stli_ecpmcdisable(stlibrd_t *brdp)
3091 outb(ECP_MCDISABLE, (brdp->iobase + ECP_MCCONFR));
3094 /*****************************************************************************/
3096 static char *stli_ecpmcgetmemptr(stlibrd_t *brdp, unsigned long offset, int line)
3101 if (offset > brdp->memsize) {
3102 printk(KERN_ERR "STALLION: shared memory pointer=%x out of "
3103 "range at line=%d(%d), brd=%d\n",
3104 (int) offset, line, __LINE__, brdp->brdnr);
3108 ptr = brdp->membase + (offset % ECP_MCPAGESIZE);
3109 val = ((unsigned char) (offset / ECP_MCPAGESIZE)) | ECP_MCENABLE;
3111 outb(val, (brdp->iobase + ECP_MCCONFR));
3115 /*****************************************************************************/
3117 static void stli_ecpmcreset(stlibrd_t *brdp)
3119 outb(ECP_MCSTOP, (brdp->iobase + ECP_MCCONFR));
3121 outb(ECP_MCDISABLE, (brdp->iobase + ECP_MCCONFR));
3125 /*****************************************************************************/
3128 * The following set of functions act on ECP PCI boards.
3131 static void stli_ecppciinit(stlibrd_t *brdp)
3133 outb(ECP_PCISTOP, (brdp->iobase + ECP_PCICONFR));
3135 outb(0, (brdp->iobase + ECP_PCICONFR));
3139 /*****************************************************************************/
3141 static char *stli_ecppcigetmemptr(stlibrd_t *brdp, unsigned long offset, int line)
3146 if (offset > brdp->memsize) {
3147 printk(KERN_ERR "STALLION: shared memory pointer=%x out of "
3148 "range at line=%d(%d), board=%d\n",
3149 (int) offset, line, __LINE__, brdp->brdnr);
3153 ptr = brdp->membase + (offset % ECP_PCIPAGESIZE);
3154 val = (offset / ECP_PCIPAGESIZE) << 1;
3156 outb(val, (brdp->iobase + ECP_PCICONFR));
3160 /*****************************************************************************/
3162 static void stli_ecppcireset(stlibrd_t *brdp)
3164 outb(ECP_PCISTOP, (brdp->iobase + ECP_PCICONFR));
3166 outb(0, (brdp->iobase + ECP_PCICONFR));
3170 /*****************************************************************************/
3173 * The following routines act on ONboards.
3176 static void stli_onbinit(stlibrd_t *brdp)
3178 unsigned long memconf;
3180 outb(ONB_ATSTOP, (brdp->iobase + ONB_ATCONFR));
3182 outb(ONB_ATDISABLE, (brdp->iobase + ONB_ATCONFR));
3185 memconf = (brdp->memaddr & ONB_ATADDRMASK) >> ONB_ATADDRSHFT;
3186 outb(memconf, (brdp->iobase + ONB_ATMEMAR));
3187 outb(0x1, brdp->iobase);
3191 /*****************************************************************************/
3193 static void stli_onbenable(stlibrd_t *brdp)
3195 outb((brdp->enabval | ONB_ATENABLE), (brdp->iobase + ONB_ATCONFR));
3198 /*****************************************************************************/
3200 static void stli_onbdisable(stlibrd_t *brdp)
3202 outb((brdp->enabval | ONB_ATDISABLE), (brdp->iobase + ONB_ATCONFR));
3205 /*****************************************************************************/
3207 static char *stli_onbgetmemptr(stlibrd_t *brdp, unsigned long offset, int line)
3211 if (offset > brdp->memsize) {
3212 printk(KERN_ERR "STALLION: shared memory pointer=%x out of "
3213 "range at line=%d(%d), brd=%d\n",
3214 (int) offset, line, __LINE__, brdp->brdnr);
3217 ptr = brdp->membase + (offset % ONB_ATPAGESIZE);
3222 /*****************************************************************************/
3224 static void stli_onbreset(stlibrd_t *brdp)
3226 outb(ONB_ATSTOP, (brdp->iobase + ONB_ATCONFR));
3228 outb(ONB_ATDISABLE, (brdp->iobase + ONB_ATCONFR));
3232 /*****************************************************************************/
3235 * The following routines act on ONboard EISA.
3238 static void stli_onbeinit(stlibrd_t *brdp)
3240 unsigned long memconf;
3242 outb(0x1, (brdp->iobase + ONB_EIBRDENAB));
3243 outb(ONB_EISTOP, (brdp->iobase + ONB_EICONFR));
3245 outb(ONB_EIDISABLE, (brdp->iobase + ONB_EICONFR));
3248 memconf = (brdp->memaddr & ONB_EIADDRMASKL) >> ONB_EIADDRSHFTL;
3249 outb(memconf, (brdp->iobase + ONB_EIMEMARL));
3250 memconf = (brdp->memaddr & ONB_EIADDRMASKH) >> ONB_EIADDRSHFTH;
3251 outb(memconf, (brdp->iobase + ONB_EIMEMARH));
3252 outb(0x1, brdp->iobase);
3256 /*****************************************************************************/
3258 static void stli_onbeenable(stlibrd_t *brdp)
3260 outb(ONB_EIENABLE, (brdp->iobase + ONB_EICONFR));
3263 /*****************************************************************************/
3265 static void stli_onbedisable(stlibrd_t *brdp)
3267 outb(ONB_EIDISABLE, (brdp->iobase + ONB_EICONFR));
3270 /*****************************************************************************/
3272 static char *stli_onbegetmemptr(stlibrd_t *brdp, unsigned long offset, int line)
3277 if (offset > brdp->memsize) {
3278 printk(KERN_ERR "STALLION: shared memory pointer=%x out of "
3279 "range at line=%d(%d), brd=%d\n",
3280 (int) offset, line, __LINE__, brdp->brdnr);
3284 ptr = brdp->membase + (offset % ONB_EIPAGESIZE);
3285 if (offset < ONB_EIPAGESIZE)
3288 val = ONB_EIENABLE | 0x40;
3290 outb(val, (brdp->iobase + ONB_EICONFR));
3294 /*****************************************************************************/
3296 static void stli_onbereset(stlibrd_t *brdp)
3298 outb(ONB_EISTOP, (brdp->iobase + ONB_EICONFR));
3300 outb(ONB_EIDISABLE, (brdp->iobase + ONB_EICONFR));
3304 /*****************************************************************************/
3307 * The following routines act on Brumby boards.
3310 static void stli_bbyinit(stlibrd_t *brdp)
3312 outb(BBY_ATSTOP, (brdp->iobase + BBY_ATCONFR));
3314 outb(0, (brdp->iobase + BBY_ATCONFR));
3316 outb(0x1, brdp->iobase);
3320 /*****************************************************************************/
3322 static char *stli_bbygetmemptr(stlibrd_t *brdp, unsigned long offset, int line)
3327 BUG_ON(offset > brdp->memsize);
3329 ptr = brdp->membase + (offset % BBY_PAGESIZE);
3330 val = (unsigned char) (offset / BBY_PAGESIZE);
3331 outb(val, (brdp->iobase + BBY_ATCONFR));
3335 /*****************************************************************************/
3337 static void stli_bbyreset(stlibrd_t *brdp)
3339 outb(BBY_ATSTOP, (brdp->iobase + BBY_ATCONFR));
3341 outb(0, (brdp->iobase + BBY_ATCONFR));
3345 /*****************************************************************************/
3348 * The following routines act on original old Stallion boards.
3351 static void stli_stalinit(stlibrd_t *brdp)
3353 outb(0x1, brdp->iobase);
3357 /*****************************************************************************/
3359 static char *stli_stalgetmemptr(stlibrd_t *brdp, unsigned long offset, int line)
3361 BUG_ON(offset > brdp->memsize);
3362 return brdp->membase + (offset % STAL_PAGESIZE);
3365 /*****************************************************************************/
3367 static void stli_stalreset(stlibrd_t *brdp)
3371 vecp = (u32 __iomem *) (brdp->membase + 0x30);
3372 writel(0xffff0000, vecp);
3373 outb(0, brdp->iobase);
3377 /*****************************************************************************/
3380 * Try to find an ECP board and initialize it. This handles only ECP
3384 static int stli_initecp(stlibrd_t *brdp)
3387 cdkecpsig_t __iomem *sigsp;
3388 unsigned int status, nxtid;
3390 int panelnr, nrports;
3392 if (!request_region(brdp->iobase, brdp->iosize, "istallion"))
3395 if ((brdp->iobase == 0) || (brdp->memaddr == 0))
3397 release_region(brdp->iobase, brdp->iosize);
3401 brdp->iosize = ECP_IOSIZE;
3404 * Based on the specific board type setup the common vars to access
3405 * and enable shared memory. Set all board specific information now
3408 switch (brdp->brdtype) {
3410 brdp->membase = (void *) brdp->memaddr;
3411 brdp->memsize = ECP_MEMSIZE;
3412 brdp->pagesize = ECP_ATPAGESIZE;
3413 brdp->init = stli_ecpinit;
3414 brdp->enable = stli_ecpenable;
3415 brdp->reenable = stli_ecpenable;
3416 brdp->disable = stli_ecpdisable;
3417 brdp->getmemptr = stli_ecpgetmemptr;
3418 brdp->intr = stli_ecpintr;
3419 brdp->reset = stli_ecpreset;
3420 name = "serial(EC8/64)";
3424 brdp->membase = (void *) brdp->memaddr;
3425 brdp->memsize = ECP_MEMSIZE;
3426 brdp->pagesize = ECP_EIPAGESIZE;
3427 brdp->init = stli_ecpeiinit;
3428 brdp->enable = stli_ecpeienable;
3429 brdp->reenable = stli_ecpeienable;
3430 brdp->disable = stli_ecpeidisable;
3431 brdp->getmemptr = stli_ecpeigetmemptr;
3432 brdp->intr = stli_ecpintr;
3433 brdp->reset = stli_ecpeireset;
3434 name = "serial(EC8/64-EI)";
3438 brdp->membase = (void *) brdp->memaddr;
3439 brdp->memsize = ECP_MEMSIZE;
3440 brdp->pagesize = ECP_MCPAGESIZE;
3442 brdp->enable = stli_ecpmcenable;
3443 brdp->reenable = stli_ecpmcenable;
3444 brdp->disable = stli_ecpmcdisable;
3445 brdp->getmemptr = stli_ecpmcgetmemptr;
3446 brdp->intr = stli_ecpintr;
3447 brdp->reset = stli_ecpmcreset;
3448 name = "serial(EC8/64-MCA)";
3452 brdp->membase = (void *) brdp->memaddr;
3453 brdp->memsize = ECP_PCIMEMSIZE;
3454 brdp->pagesize = ECP_PCIPAGESIZE;
3455 brdp->init = stli_ecppciinit;
3456 brdp->enable = NULL;
3457 brdp->reenable = NULL;
3458 brdp->disable = NULL;
3459 brdp->getmemptr = stli_ecppcigetmemptr;
3460 brdp->intr = stli_ecpintr;
3461 brdp->reset = stli_ecppcireset;
3462 name = "serial(EC/RA-PCI)";
3466 release_region(brdp->iobase, brdp->iosize);
3471 * The per-board operations structure is all set up, so now let's go
3472 * and get the board operational. Firstly initialize board configuration
3473 * registers. Set the memory mapping info so we can get at the boards
3478 brdp->membase = ioremap(brdp->memaddr, brdp->memsize);
3479 if (brdp->membase == NULL)
3481 release_region(brdp->iobase, brdp->iosize);
3486 * Now that all specific code is set up, enable the shared memory and
3487 * look for the a signature area that will tell us exactly what board
3488 * this is, and what it is connected to it.
3491 sigsp = (cdkecpsig_t __iomem *) EBRDGETMEMPTR(brdp, CDK_SIGADDR);
3492 memcpy(&sig, sigsp, sizeof(cdkecpsig_t));
3495 if (sig.magic != cpu_to_le32(ECP_MAGIC))
3497 release_region(brdp->iobase, brdp->iosize);
3502 * Scan through the signature looking at the panels connected to the
3503 * board. Calculate the total number of ports as we go.
3505 for (panelnr = 0, nxtid = 0; (panelnr < STL_MAXPANELS); panelnr++) {
3506 status = sig.panelid[nxtid];
3507 if ((status & ECH_PNLIDMASK) != nxtid)
3510 brdp->panelids[panelnr] = status;
3511 nrports = (status & ECH_PNL16PORT) ? 16 : 8;
3512 if ((nrports == 16) && ((status & ECH_PNLXPID) == 0))
3514 brdp->panels[panelnr] = nrports;
3515 brdp->nrports += nrports;
3521 brdp->state |= BST_FOUND;
3525 /*****************************************************************************/
3528 * Try to find an ONboard, Brumby or Stallion board and initialize it.
3529 * This handles only these board types.
3532 static int stli_initonb(stlibrd_t *brdp)
3535 cdkonbsig_t __iomem *sigsp;
3540 * Do a basic sanity check on the IO and memory addresses.
3542 if (brdp->iobase == 0 || brdp->memaddr == 0)
3545 brdp->iosize = ONB_IOSIZE;
3547 if (!request_region(brdp->iobase, brdp->iosize, "istallion"))
3551 * Based on the specific board type setup the common vars to access
3552 * and enable shared memory. Set all board specific information now
3555 switch (brdp->brdtype) {
3559 case BRD_ONBOARD2_32:
3561 brdp->memsize = ONB_MEMSIZE;
3562 brdp->pagesize = ONB_ATPAGESIZE;
3563 brdp->init = stli_onbinit;
3564 brdp->enable = stli_onbenable;
3565 brdp->reenable = stli_onbenable;
3566 brdp->disable = stli_onbdisable;
3567 brdp->getmemptr = stli_onbgetmemptr;
3568 brdp->intr = stli_ecpintr;
3569 brdp->reset = stli_onbreset;
3570 if (brdp->memaddr > 0x100000)
3571 brdp->enabval = ONB_MEMENABHI;
3573 brdp->enabval = ONB_MEMENABLO;
3574 name = "serial(ONBoard)";
3578 brdp->memsize = ONB_EIMEMSIZE;
3579 brdp->pagesize = ONB_EIPAGESIZE;
3580 brdp->init = stli_onbeinit;
3581 brdp->enable = stli_onbeenable;
3582 brdp->reenable = stli_onbeenable;
3583 brdp->disable = stli_onbedisable;
3584 brdp->getmemptr = stli_onbegetmemptr;
3585 brdp->intr = stli_ecpintr;
3586 brdp->reset = stli_onbereset;
3587 name = "serial(ONBoard/E)";
3593 brdp->memsize = BBY_MEMSIZE;
3594 brdp->pagesize = BBY_PAGESIZE;
3595 brdp->init = stli_bbyinit;
3596 brdp->enable = NULL;
3597 brdp->reenable = NULL;
3598 brdp->disable = NULL;
3599 brdp->getmemptr = stli_bbygetmemptr;
3600 brdp->intr = stli_ecpintr;
3601 brdp->reset = stli_bbyreset;
3602 name = "serial(Brumby)";
3606 brdp->memsize = STAL_MEMSIZE;
3607 brdp->pagesize = STAL_PAGESIZE;
3608 brdp->init = stli_stalinit;
3609 brdp->enable = NULL;
3610 brdp->reenable = NULL;
3611 brdp->disable = NULL;
3612 brdp->getmemptr = stli_stalgetmemptr;
3613 brdp->intr = stli_ecpintr;
3614 brdp->reset = stli_stalreset;
3615 name = "serial(Stallion)";
3619 release_region(brdp->iobase, brdp->iosize);
3624 * The per-board operations structure is all set up, so now let's go
3625 * and get the board operational. Firstly initialize board configuration
3626 * registers. Set the memory mapping info so we can get at the boards
3631 brdp->membase = ioremap(brdp->memaddr, brdp->memsize);
3632 if (brdp->membase == NULL)
3634 release_region(brdp->iobase, brdp->iosize);
3639 * Now that all specific code is set up, enable the shared memory and
3640 * look for the a signature area that will tell us exactly what board
3641 * this is, and how many ports.
3644 sigsp = (cdkonbsig_t __iomem *) EBRDGETMEMPTR(brdp, CDK_SIGADDR);
3645 memcpy_fromio(&sig, sigsp, sizeof(cdkonbsig_t));
3648 if (sig.magic0 != cpu_to_le16(ONB_MAGIC0) ||
3649 sig.magic1 != cpu_to_le16(ONB_MAGIC1) ||
3650 sig.magic2 != cpu_to_le16(ONB_MAGIC2) ||
3651 sig.magic3 != cpu_to_le16(ONB_MAGIC3))
3653 release_region(brdp->iobase, brdp->iosize);
3658 * Scan through the signature alive mask and calculate how many ports
3659 * there are on this board.
3665 for (i = 0; (i < 16); i++) {
3666 if (((sig.amask0 << i) & 0x8000) == 0)
3671 brdp->panels[0] = brdp->nrports;
3674 brdp->state |= BST_FOUND;
3678 /*****************************************************************************/
3681 * Start up a running board. This routine is only called after the
3682 * code has been down loaded to the board and is operational. It will
3683 * read in the memory map, and get the show on the road...
3686 static int stli_startbrd(stlibrd_t *brdp)
3688 cdkhdr_t __iomem *hdrp;
3689 cdkmem_t __iomem *memp;
3690 cdkasy_t __iomem *ap;
3691 unsigned long flags;
3693 int portnr, nrdevs, i, rc = 0;
3696 spin_lock_irqsave(&brd_lock, flags);
3698 hdrp = (cdkhdr_t __iomem *) EBRDGETMEMPTR(brdp, CDK_CDKADDR);
3699 nrdevs = hdrp->nrdevs;
3702 printk("%s(%d): CDK version %d.%d.%d --> "
3703 "nrdevs=%d memp=%x hostp=%x slavep=%x\n",
3704 __FILE__, __LINE__, readb(&hdrp->ver_release), readb(&hdrp->ver_modification),
3705 readb(&hdrp->ver_fix), nrdevs, (int) readl(&hdrp->memp), readl(&hdrp->hostp),
3706 readl(&hdrp->slavep));
3709 if (nrdevs < (brdp->nrports + 1)) {
3710 printk(KERN_ERR "STALLION: slave failed to allocate memory for "
3711 "all devices, devices=%d\n", nrdevs);
3712 brdp->nrports = nrdevs - 1;
3714 brdp->nrdevs = nrdevs;
3715 brdp->hostoffset = hdrp->hostp - CDK_CDKADDR;
3716 brdp->slaveoffset = hdrp->slavep - CDK_CDKADDR;
3717 brdp->bitsize = (nrdevs + 7) / 8;
3718 memoff = readl(&hdrp->memp);
3719 if (memoff > brdp->memsize) {
3720 printk(KERN_ERR "STALLION: corrupted shared memory region?\n");
3722 goto stli_donestartup;
3724 memp = (cdkmem_t __iomem *) EBRDGETMEMPTR(brdp, memoff);
3725 if (readw(&memp->dtype) != TYP_ASYNCTRL) {
3726 printk(KERN_ERR "STALLION: no slave control device found\n");
3727 goto stli_donestartup;
3732 * Cycle through memory allocation of each port. We are guaranteed to
3733 * have all ports inside the first page of slave window, so no need to
3734 * change pages while reading memory map.
3736 for (i = 1, portnr = 0; (i < nrdevs); i++, portnr++, memp++) {
3737 if (readw(&memp->dtype) != TYP_ASYNC)
3739 portp = brdp->ports[portnr];
3743 portp->addr = readl(&memp->offset);
3744 portp->reqbit = (unsigned char) (0x1 << (i * 8 / nrdevs));
3745 portp->portidx = (unsigned char) (i / 8);
3746 portp->portbit = (unsigned char) (0x1 << (i % 8));
3749 writeb(0xff, &hdrp->slavereq);
3752 * For each port setup a local copy of the RX and TX buffer offsets
3753 * and sizes. We do this separate from the above, because we need to
3754 * move the shared memory page...
3756 for (i = 1, portnr = 0; (i < nrdevs); i++, portnr++) {
3757 portp = brdp->ports[portnr];
3760 if (portp->addr == 0)
3762 ap = (cdkasy_t __iomem *) EBRDGETMEMPTR(brdp, portp->addr);
3764 portp->rxsize = readw(&ap->rxq.size);
3765 portp->txsize = readw(&ap->txq.size);
3766 portp->rxoffset = readl(&ap->rxq.offset);
3767 portp->txoffset = readl(&ap->txq.offset);
3773 spin_unlock_irqrestore(&brd_lock, flags);
3776 brdp->state |= BST_STARTED;
3778 if (! stli_timeron) {
3780 stli_timerlist.expires = STLI_TIMEOUT;
3781 add_timer(&stli_timerlist);
3787 /*****************************************************************************/
3790 * Probe and initialize the specified board.
3793 static int __init stli_brdinit(stlibrd_t *brdp)
3795 stli_brds[brdp->brdnr] = brdp;
3797 switch (brdp->brdtype) {
3808 case BRD_ONBOARD2_32:
3820 printk(KERN_ERR "STALLION: %s board type not supported in "
3821 "this driver\n", stli_brdnames[brdp->brdtype]);
3824 printk(KERN_ERR "STALLION: board=%d is unknown board "
3825 "type=%d\n", brdp->brdnr, brdp->brdtype);
3829 if ((brdp->state & BST_FOUND) == 0) {
3830 printk(KERN_ERR "STALLION: %s board not found, board=%d "
3832 stli_brdnames[brdp->brdtype], brdp->brdnr,
3833 brdp->iobase, (int) brdp->memaddr);
3837 stli_initports(brdp);
3838 printk(KERN_INFO "STALLION: %s found, board=%d io=%x mem=%x "
3839 "nrpanels=%d nrports=%d\n", stli_brdnames[brdp->brdtype],
3840 brdp->brdnr, brdp->iobase, (int) brdp->memaddr,
3841 brdp->nrpanels, brdp->nrports);
3845 /*****************************************************************************/
3848 * Probe around trying to find where the EISA boards shared memory
3849 * might be. This is a bit if hack, but it is the best we can do.
3852 static int stli_eisamemprobe(stlibrd_t *brdp)
3854 cdkecpsig_t ecpsig, __iomem *ecpsigp;
3855 cdkonbsig_t onbsig, __iomem *onbsigp;
3859 * First up we reset the board, to get it into a known state. There
3860 * is only 2 board types here we need to worry about. Don;t use the
3861 * standard board init routine here, it programs up the shared
3862 * memory address, and we don't know it yet...
3864 if (brdp->brdtype == BRD_ECPE) {
3865 outb(0x1, (brdp->iobase + ECP_EIBRDENAB));
3866 outb(ECP_EISTOP, (brdp->iobase + ECP_EICONFR));
3868 outb(ECP_EIDISABLE, (brdp->iobase + ECP_EICONFR));
3870 stli_ecpeienable(brdp);
3871 } else if (brdp->brdtype == BRD_ONBOARDE) {
3872 outb(0x1, (brdp->iobase + ONB_EIBRDENAB));
3873 outb(ONB_EISTOP, (brdp->iobase + ONB_EICONFR));
3875 outb(ONB_EIDISABLE, (brdp->iobase + ONB_EICONFR));
3877 outb(0x1, brdp->iobase);
3879 stli_onbeenable(brdp);
3885 brdp->memsize = ECP_MEMSIZE;
3888 * Board shared memory is enabled, so now we have a poke around and
3889 * see if we can find it.
3891 for (i = 0; (i < stli_eisamempsize); i++) {
3892 brdp->memaddr = stli_eisamemprobeaddrs[i];
3893 brdp->membase = ioremap(brdp->memaddr, brdp->memsize);
3894 if (brdp->membase == NULL)
3897 if (brdp->brdtype == BRD_ECPE) {
3898 ecpsigp = (cdkecpsig_t __iomem *) stli_ecpeigetmemptr(brdp,
3899 CDK_SIGADDR, __LINE__);
3900 memcpy_fromio(&ecpsig, ecpsigp, sizeof(cdkecpsig_t));
3901 if (ecpsig.magic == cpu_to_le32(ECP_MAGIC))
3904 onbsigp = (cdkonbsig_t __iomem *) stli_onbegetmemptr(brdp,
3905 CDK_SIGADDR, __LINE__);
3906 memcpy_fromio(&onbsig, onbsigp, sizeof(cdkonbsig_t));
3907 if ((onbsig.magic0 == cpu_to_le16(ONB_MAGIC0)) &&
3908 (onbsig.magic1 == cpu_to_le16(ONB_MAGIC1)) &&
3909 (onbsig.magic2 == cpu_to_le16(ONB_MAGIC2)) &&
3910 (onbsig.magic3 == cpu_to_le16(ONB_MAGIC3)))
3914 iounmap(brdp->membase);
3920 * Regardless of whether we found the shared memory or not we must
3921 * disable the region. After that return success or failure.
3923 if (brdp->brdtype == BRD_ECPE)
3924 stli_ecpeidisable(brdp);
3926 stli_onbedisable(brdp);
3930 brdp->membase = NULL;
3931 printk(KERN_ERR "STALLION: failed to probe shared memory "
3932 "region for %s in EISA slot=%d\n",
3933 stli_brdnames[brdp->brdtype], (brdp->iobase >> 12));
3939 static int stli_getbrdnr(void)
3943 for (i = 0; i < STL_MAXBRDS; i++) {
3944 if (!stli_brds[i]) {
3945 if (i >= stli_nrbrds)
3946 stli_nrbrds = i + 1;
3953 /*****************************************************************************/
3956 * Probe around and try to find any EISA boards in system. The biggest
3957 * problem here is finding out what memory address is associated with
3958 * an EISA board after it is found. The registers of the ECPE and
3959 * ONboardE are not readable - so we can't read them from there. We
3960 * don't have access to the EISA CMOS (or EISA BIOS) so we don't
3961 * actually have any way to find out the real value. The best we can
3962 * do is go probing around in the usual places hoping we can find it.
3965 static int stli_findeisabrds(void)
3968 unsigned int iobase, eid;
3972 * Firstly check if this is an EISA system. If this is not an EISA system then
3973 * don't bother going any further!
3979 * Looks like an EISA system, so go searching for EISA boards.
3981 for (iobase = 0x1000; (iobase <= 0xc000); iobase += 0x1000) {
3982 outb(0xff, (iobase + 0xc80));
3983 eid = inb(iobase + 0xc80);
3984 eid |= inb(iobase + 0xc81) << 8;
3985 if (eid != STL_EISAID)
3989 * We have found a board. Need to check if this board was
3990 * statically configured already (just in case!).
3992 for (i = 0; (i < STL_MAXBRDS); i++) {
3993 brdp = stli_brds[i];
3996 if (brdp->iobase == iobase)
3999 if (i < STL_MAXBRDS)
4003 * We have found a Stallion board and it is not configured already.
4004 * Allocate a board structure and initialize it.
4006 if ((brdp = stli_allocbrd()) == NULL)
4008 if ((brdp->brdnr = stli_getbrdnr()) < 0)
4010 eid = inb(iobase + 0xc82);
4011 if (eid == ECP_EISAID)
4012 brdp->brdtype = BRD_ECPE;
4013 else if (eid == ONB_EISAID)
4014 brdp->brdtype = BRD_ONBOARDE;
4016 brdp->brdtype = BRD_UNKNOWN;
4017 brdp->iobase = iobase;
4018 outb(0x1, (iobase + 0xc84));
4019 if (stli_eisamemprobe(brdp))
4020 outb(0, (iobase + 0xc84));
4027 /*****************************************************************************/
4030 * Find the next available board number that is free.
4033 /*****************************************************************************/
4038 * We have a Stallion board. Allocate a board structure and
4039 * initialize it. Read its IO and MEMORY resources from PCI
4040 * configuration space.
4043 static int stli_initpcibrd(int brdtype, struct pci_dev *devp)
4047 if (pci_enable_device(devp))
4049 if ((brdp = stli_allocbrd()) == NULL)
4051 if ((brdp->brdnr = stli_getbrdnr()) < 0) {
4052 printk(KERN_INFO "STALLION: too many boards found, "
4053 "maximum supported %d\n", STL_MAXBRDS);
4056 brdp->brdtype = brdtype;
4058 * We have all resources from the board, so lets setup the actual
4059 * board structure now.
4061 brdp->iobase = pci_resource_start(devp, 3);
4062 brdp->memaddr = pci_resource_start(devp, 2);
4068 /*****************************************************************************/
4071 * Find all Stallion PCI boards that might be installed. Initialize each
4072 * one as it is found.
4075 static int stli_findpcibrds(void)
4077 struct pci_dev *dev = NULL;
4079 while ((dev = pci_get_device(PCI_VENDOR_ID_STALLION, PCI_DEVICE_ID_ECRA, dev))) {
4080 stli_initpcibrd(BRD_ECPPCI, dev);
4087 /*****************************************************************************/
4090 * Allocate a new board structure. Fill out the basic info in it.
4093 static stlibrd_t *stli_allocbrd(void)
4097 brdp = kzalloc(sizeof(stlibrd_t), GFP_KERNEL);
4099 printk(KERN_ERR "STALLION: failed to allocate memory "
4100 "(size=%Zd)\n", sizeof(stlibrd_t));
4103 brdp->magic = STLI_BOARDMAGIC;
4107 /*****************************************************************************/
4110 * Scan through all the boards in the configuration and see what we
4114 static int stli_initbrds(void)
4116 stlibrd_t *brdp, *nxtbrdp;
4120 if (stli_nrbrds > STL_MAXBRDS) {
4121 printk(KERN_INFO "STALLION: too many boards in configuration "
4122 "table, truncating to %d\n", STL_MAXBRDS);
4123 stli_nrbrds = STL_MAXBRDS;
4127 * Firstly scan the list of static boards configured. Allocate
4128 * resources and initialize the boards as found. If this is a
4129 * module then let the module args override static configuration.
4131 for (i = 0; (i < stli_nrbrds); i++) {
4132 confp = &stli_brdconf[i];
4133 stli_parsebrd(confp, stli_brdsp[i]);
4134 if ((brdp = stli_allocbrd()) == NULL)
4137 brdp->brdtype = confp->brdtype;
4138 brdp->iobase = confp->ioaddr1;
4139 brdp->memaddr = confp->memaddr;
4144 * Static configuration table done, so now use dynamic methods to
4145 * see if any more boards should be configured.
4149 stli_findeisabrds();
4155 * All found boards are initialized. Now for a little optimization, if
4156 * no boards are sharing the "shared memory" regions then we can just
4157 * leave them all enabled. This is in fact the usual case.
4160 if (stli_nrbrds > 1) {
4161 for (i = 0; (i < stli_nrbrds); i++) {
4162 brdp = stli_brds[i];
4165 for (j = i + 1; (j < stli_nrbrds); j++) {
4166 nxtbrdp = stli_brds[j];
4167 if (nxtbrdp == NULL)
4169 if ((brdp->membase >= nxtbrdp->membase) &&
4170 (brdp->membase <= (nxtbrdp->membase +
4171 nxtbrdp->memsize - 1))) {
4179 if (stli_shared == 0) {
4180 for (i = 0; (i < stli_nrbrds); i++) {
4181 brdp = stli_brds[i];
4184 if (brdp->state & BST_FOUND) {
4186 brdp->enable = NULL;
4187 brdp->disable = NULL;
4195 /*****************************************************************************/
4198 * Code to handle an "staliomem" read operation. This device is the
4199 * contents of the board shared memory. It is used for down loading
4200 * the slave image (and debugging :-)
4203 static ssize_t stli_memread(struct file *fp, char __user *buf, size_t count, loff_t *offp)
4205 unsigned long flags;
4212 brdnr = iminor(fp->f_dentry->d_inode);
4213 if (brdnr >= stli_nrbrds)
4215 brdp = stli_brds[brdnr];
4218 if (brdp->state == 0)
4220 if (off >= brdp->memsize || off + count < off)
4223 size = MIN(count, (brdp->memsize - off));
4226 * Copy the data a page at a time
4229 p = (void *)__get_free_page(GFP_KERNEL);
4234 spin_lock_irqsave(&brd_lock, flags);
4236 memptr = (void *) EBRDGETMEMPTR(brdp, off);
4237 n = MIN(size, (brdp->pagesize - (((unsigned long) off) % brdp->pagesize)));
4238 n = MIN(n, PAGE_SIZE);
4239 memcpy_fromio(p, memptr, n);
4241 spin_unlock_irqrestore(&brd_lock, flags);
4242 if (copy_to_user(buf, p, n)) {
4252 free_page((unsigned long)p);
4256 /*****************************************************************************/
4259 * Code to handle an "staliomem" write operation. This device is the
4260 * contents of the board shared memory. It is used for down loading
4261 * the slave image (and debugging :-)
4263 * FIXME: copy under lock
4266 static ssize_t stli_memwrite(struct file *fp, const char __user *buf, size_t count, loff_t *offp)
4268 unsigned long flags;
4276 brdnr = iminor(fp->f_dentry->d_inode);
4278 if (brdnr >= stli_nrbrds)
4280 brdp = stli_brds[brdnr];
4283 if (brdp->state == 0)
4285 if (off >= brdp->memsize || off + count < off)
4288 chbuf = (char __user *) buf;
4289 size = MIN(count, (brdp->memsize - off));
4292 * Copy the data a page at a time
4295 p = (void *)__get_free_page(GFP_KERNEL);
4300 n = MIN(size, (brdp->pagesize - (((unsigned long) off) % brdp->pagesize)));
4301 n = MIN(n, PAGE_SIZE);
4302 if (copy_from_user(p, chbuf, n)) {
4307 spin_lock_irqsave(&brd_lock, flags);
4309 memptr = (void *) EBRDGETMEMPTR(brdp, off);
4310 memcpy_toio(memptr, p, n);
4312 spin_unlock_irqrestore(&brd_lock, flags);
4318 free_page((unsigned long) p);
4323 /*****************************************************************************/
4326 * Return the board stats structure to user app.
4329 static int stli_getbrdstats(combrd_t __user *bp)
4334 if (copy_from_user(&stli_brdstats, bp, sizeof(combrd_t)))
4336 if (stli_brdstats.brd >= STL_MAXBRDS)
4338 brdp = stli_brds[stli_brdstats.brd];
4342 memset(&stli_brdstats, 0, sizeof(combrd_t));
4343 stli_brdstats.brd = brdp->brdnr;
4344 stli_brdstats.type = brdp->brdtype;
4345 stli_brdstats.hwid = 0;
4346 stli_brdstats.state = brdp->state;
4347 stli_brdstats.ioaddr = brdp->iobase;
4348 stli_brdstats.memaddr = brdp->memaddr;
4349 stli_brdstats.nrpanels = brdp->nrpanels;
4350 stli_brdstats.nrports = brdp->nrports;
4351 for (i = 0; (i < brdp->nrpanels); i++) {
4352 stli_brdstats.panels[i].panel = i;
4353 stli_brdstats.panels[i].hwid = brdp->panelids[i];
4354 stli_brdstats.panels[i].nrports = brdp->panels[i];
4357 if (copy_to_user(bp, &stli_brdstats, sizeof(combrd_t)))
4362 /*****************************************************************************/
4365 * Resolve the referenced port number into a port struct pointer.
4368 static stliport_t *stli_getport(int brdnr, int panelnr, int portnr)
4373 if (brdnr < 0 || brdnr >= STL_MAXBRDS)
4375 brdp = stli_brds[brdnr];
4378 for (i = 0; (i < panelnr); i++)
4379 portnr += brdp->panels[i];
4380 if ((portnr < 0) || (portnr >= brdp->nrports))
4382 return brdp->ports[portnr];
4385 /*****************************************************************************/
4388 * Return the port stats structure to user app. A NULL port struct
4389 * pointer passed in means that we need to find out from the app
4390 * what port to get stats for (used through board control device).
4393 static int stli_portcmdstats(stliport_t *portp)
4395 unsigned long flags;
4399 memset(&stli_comstats, 0, sizeof(comstats_t));
4403 brdp = stli_brds[portp->brdnr];
4407 if (brdp->state & BST_STARTED) {
4408 if ((rc = stli_cmdwait(brdp, portp, A_GETSTATS,
4409 &stli_cdkstats, sizeof(asystats_t), 1)) < 0)
4412 memset(&stli_cdkstats, 0, sizeof(asystats_t));
4415 stli_comstats.brd = portp->brdnr;
4416 stli_comstats.panel = portp->panelnr;
4417 stli_comstats.port = portp->portnr;
4418 stli_comstats.state = portp->state;
4419 stli_comstats.flags = portp->flags;
4421 spin_lock_irqsave(&brd_lock, flags);
4422 if (portp->tty != NULL) {
4423 if (portp->tty->driver_data == portp) {
4424 stli_comstats.ttystate = portp->tty->flags;
4425 stli_comstats.rxbuffered = -1;
4426 if (portp->tty->termios != NULL) {
4427 stli_comstats.cflags = portp->tty->termios->c_cflag;
4428 stli_comstats.iflags = portp->tty->termios->c_iflag;
4429 stli_comstats.oflags = portp->tty->termios->c_oflag;
4430 stli_comstats.lflags = portp->tty->termios->c_lflag;
4434 spin_unlock_irqrestore(&brd_lock, flags);
4436 stli_comstats.txtotal = stli_cdkstats.txchars;
4437 stli_comstats.rxtotal = stli_cdkstats.rxchars + stli_cdkstats.ringover;
4438 stli_comstats.txbuffered = stli_cdkstats.txringq;
4439 stli_comstats.rxbuffered += stli_cdkstats.rxringq;
4440 stli_comstats.rxoverrun = stli_cdkstats.overruns;
4441 stli_comstats.rxparity = stli_cdkstats.parity;
4442 stli_comstats.rxframing = stli_cdkstats.framing;
4443 stli_comstats.rxlost = stli_cdkstats.ringover;
4444 stli_comstats.rxbreaks = stli_cdkstats.rxbreaks;
4445 stli_comstats.txbreaks = stli_cdkstats.txbreaks;
4446 stli_comstats.txxon = stli_cdkstats.txstart;
4447 stli_comstats.txxoff = stli_cdkstats.txstop;
4448 stli_comstats.rxxon = stli_cdkstats.rxstart;
4449 stli_comstats.rxxoff = stli_cdkstats.rxstop;
4450 stli_comstats.rxrtsoff = stli_cdkstats.rtscnt / 2;
4451 stli_comstats.rxrtson = stli_cdkstats.rtscnt - stli_comstats.rxrtsoff;
4452 stli_comstats.modem = stli_cdkstats.dcdcnt;
4453 stli_comstats.hwid = stli_cdkstats.hwid;
4454 stli_comstats.signals = stli_mktiocm(stli_cdkstats.signals);
4459 /*****************************************************************************/
4462 * Return the port stats structure to user app. A NULL port struct
4463 * pointer passed in means that we need to find out from the app
4464 * what port to get stats for (used through board control device).
4467 static int stli_getportstats(stliport_t *portp, comstats_t __user *cp)
4473 if (copy_from_user(&stli_comstats, cp, sizeof(comstats_t)))
4475 portp = stli_getport(stli_comstats.brd, stli_comstats.panel,
4476 stli_comstats.port);
4481 brdp = stli_brds[portp->brdnr];
4485 if ((rc = stli_portcmdstats(portp)) < 0)
4488 return copy_to_user(cp, &stli_comstats, sizeof(comstats_t)) ?
4492 /*****************************************************************************/
4495 * Clear the port stats structure. We also return it zeroed out...
4498 static int stli_clrportstats(stliport_t *portp, comstats_t __user *cp)
4504 if (copy_from_user(&stli_comstats, cp, sizeof(comstats_t)))
4506 portp = stli_getport(stli_comstats.brd, stli_comstats.panel,
4507 stli_comstats.port);
4512 brdp = stli_brds[portp->brdnr];
4516 if (brdp->state & BST_STARTED) {
4517 if ((rc = stli_cmdwait(brdp, portp, A_CLEARSTATS, NULL, 0, 0)) < 0)
4521 memset(&stli_comstats, 0, sizeof(comstats_t));
4522 stli_comstats.brd = portp->brdnr;
4523 stli_comstats.panel = portp->panelnr;
4524 stli_comstats.port = portp->portnr;
4526 if (copy_to_user(cp, &stli_comstats, sizeof(comstats_t)))
4531 /*****************************************************************************/
4534 * Return the entire driver ports structure to a user app.
4537 static int stli_getportstruct(stliport_t __user *arg)
4541 if (copy_from_user(&stli_dummyport, arg, sizeof(stliport_t)))
4543 portp = stli_getport(stli_dummyport.brdnr, stli_dummyport.panelnr,
4544 stli_dummyport.portnr);
4547 if (copy_to_user(arg, portp, sizeof(stliport_t)))
4552 /*****************************************************************************/
4555 * Return the entire driver board structure to a user app.
4558 static int stli_getbrdstruct(stlibrd_t __user *arg)
4562 if (copy_from_user(&stli_dummybrd, arg, sizeof(stlibrd_t)))
4564 if ((stli_dummybrd.brdnr < 0) || (stli_dummybrd.brdnr >= STL_MAXBRDS))
4566 brdp = stli_brds[stli_dummybrd.brdnr];
4569 if (copy_to_user(arg, brdp, sizeof(stlibrd_t)))
4574 /*****************************************************************************/
4577 * The "staliomem" device is also required to do some special operations on
4578 * the board. We need to be able to send an interrupt to the board,
4579 * reset it, and start/stop it.
4582 static int stli_memioctl(struct inode *ip, struct file *fp, unsigned int cmd, unsigned long arg)
4585 int brdnr, rc, done;
4586 void __user *argp = (void __user *)arg;
4589 * First up handle the board independent ioctls.
4595 case COM_GETPORTSTATS:
4596 rc = stli_getportstats(NULL, argp);
4599 case COM_CLRPORTSTATS:
4600 rc = stli_clrportstats(NULL, argp);
4603 case COM_GETBRDSTATS:
4604 rc = stli_getbrdstats(argp);
4608 rc = stli_getportstruct(argp);
4612 rc = stli_getbrdstruct(argp);
4621 * Now handle the board specific ioctls. These all depend on the
4622 * minor number of the device they were called from.
4625 if (brdnr >= STL_MAXBRDS)
4627 brdp = stli_brds[brdnr];
4630 if (brdp->state == 0)
4638 rc = stli_startbrd(brdp);
4641 brdp->state &= ~BST_STARTED;
4644 brdp->state &= ~BST_STARTED;
4646 if (stli_shared == 0) {
4647 if (brdp->reenable != NULL)
4648 (* brdp->reenable)(brdp);
4658 static struct tty_operations stli_ops = {
4660 .close = stli_close,
4661 .write = stli_write,
4662 .put_char = stli_putchar,
4663 .flush_chars = stli_flushchars,
4664 .write_room = stli_writeroom,
4665 .chars_in_buffer = stli_charsinbuffer,
4666 .ioctl = stli_ioctl,
4667 .set_termios = stli_settermios,
4668 .throttle = stli_throttle,
4669 .unthrottle = stli_unthrottle,
4671 .start = stli_start,
4672 .hangup = stli_hangup,
4673 .flush_buffer = stli_flushbuffer,
4674 .break_ctl = stli_breakctl,
4675 .wait_until_sent = stli_waituntilsent,
4676 .send_xchar = stli_sendxchar,
4677 .read_proc = stli_readproc,
4678 .tiocmget = stli_tiocmget,
4679 .tiocmset = stli_tiocmset,
4682 /*****************************************************************************/
4684 static int __init stli_init(void)
4687 printk(KERN_INFO "%s: version %s\n", stli_drvtitle, stli_drvversion);
4689 spin_lock_init(&stli_lock);
4690 spin_lock_init(&brd_lock);
4694 stli_serial = alloc_tty_driver(STL_MAXBRDS * STL_MAXPORTS);
4699 * Allocate a temporary write buffer.
4701 stli_txcookbuf = kmalloc(STLI_TXBUFSIZE, GFP_KERNEL);
4702 if (!stli_txcookbuf)
4703 printk(KERN_ERR "STALLION: failed to allocate memory "
4704 "(size=%d)\n", STLI_TXBUFSIZE);
4707 * Set up a character driver for the shared memory region. We need this
4708 * to down load the slave code image. Also it is a useful debugging tool.
4710 if (register_chrdev(STL_SIOMEMMAJOR, "staliomem", &stli_fsiomem))
4711 printk(KERN_ERR "STALLION: failed to register serial memory "
4714 istallion_class = class_create(THIS_MODULE, "staliomem");
4715 for (i = 0; i < 4; i++)
4716 class_device_create(istallion_class, NULL,
4717 MKDEV(STL_SIOMEMMAJOR, i),
4718 NULL, "staliomem%d", i);
4721 * Set up the tty driver structure and register us as a driver.
4723 stli_serial->owner = THIS_MODULE;
4724 stli_serial->driver_name = stli_drvname;
4725 stli_serial->name = stli_serialname;
4726 stli_serial->major = STL_SERIALMAJOR;
4727 stli_serial->minor_start = 0;
4728 stli_serial->type = TTY_DRIVER_TYPE_SERIAL;
4729 stli_serial->subtype = SERIAL_TYPE_NORMAL;
4730 stli_serial->init_termios = stli_deftermios;
4731 stli_serial->flags = TTY_DRIVER_REAL_RAW;
4732 tty_set_operations(stli_serial, &stli_ops);
4734 if (tty_register_driver(stli_serial)) {
4735 put_tty_driver(stli_serial);
4736 printk(KERN_ERR "STALLION: failed to register serial driver\n");
4742 /*****************************************************************************/