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 /*****************************************************************************/
287 * Define some string labels for arguments passed from the module
288 * load line. These allow for easy board definitions, and easy
289 * modification of the io, memory and irq resoucres.
292 static char *board0[8];
293 static char *board1[8];
294 static char *board2[8];
295 static char *board3[8];
297 static char **stli_brdsp[] = {
305 * Define a set of common board names, and types. This is used to
306 * parse any module arguments.
309 typedef struct stlibrdtype {
314 static stlibrdtype_t stli_brdstr[] = {
315 { "stallion", BRD_STALLION },
316 { "1", BRD_STALLION },
317 { "brumby", BRD_BRUMBY },
318 { "brumby4", BRD_BRUMBY },
319 { "brumby/4", BRD_BRUMBY },
320 { "brumby-4", BRD_BRUMBY },
321 { "brumby8", BRD_BRUMBY },
322 { "brumby/8", BRD_BRUMBY },
323 { "brumby-8", BRD_BRUMBY },
324 { "brumby16", BRD_BRUMBY },
325 { "brumby/16", BRD_BRUMBY },
326 { "brumby-16", BRD_BRUMBY },
328 { "onboard2", BRD_ONBOARD2 },
329 { "onboard-2", BRD_ONBOARD2 },
330 { "onboard/2", BRD_ONBOARD2 },
331 { "onboard-mc", BRD_ONBOARD2 },
332 { "onboard/mc", BRD_ONBOARD2 },
333 { "onboard-mca", BRD_ONBOARD2 },
334 { "onboard/mca", BRD_ONBOARD2 },
335 { "3", BRD_ONBOARD2 },
336 { "onboard", BRD_ONBOARD },
337 { "onboardat", BRD_ONBOARD },
338 { "4", BRD_ONBOARD },
339 { "onboarde", BRD_ONBOARDE },
340 { "onboard-e", BRD_ONBOARDE },
341 { "onboard/e", BRD_ONBOARDE },
342 { "onboard-ei", BRD_ONBOARDE },
343 { "onboard/ei", BRD_ONBOARDE },
344 { "7", BRD_ONBOARDE },
346 { "ecpat", BRD_ECP },
347 { "ec8/64", BRD_ECP },
348 { "ec8/64-at", BRD_ECP },
349 { "ec8/64-isa", BRD_ECP },
351 { "ecpe", BRD_ECPE },
352 { "ecpei", BRD_ECPE },
353 { "ec8/64-e", BRD_ECPE },
354 { "ec8/64-ei", BRD_ECPE },
356 { "ecpmc", BRD_ECPMC },
357 { "ec8/64-mc", BRD_ECPMC },
358 { "ec8/64-mca", BRD_ECPMC },
360 { "ecppci", BRD_ECPPCI },
361 { "ec/ra", BRD_ECPPCI },
362 { "ec/ra-pc", BRD_ECPPCI },
363 { "ec/ra-pci", BRD_ECPPCI },
364 { "29", BRD_ECPPCI },
368 * Define the module agruments.
370 MODULE_AUTHOR("Greg Ungerer");
371 MODULE_DESCRIPTION("Stallion Intelligent Multiport Serial Driver");
372 MODULE_LICENSE("GPL");
375 module_param_array(board0, charp, NULL, 0);
376 MODULE_PARM_DESC(board0, "Board 0 config -> name[,ioaddr[,memaddr]");
377 module_param_array(board1, charp, NULL, 0);
378 MODULE_PARM_DESC(board1, "Board 1 config -> name[,ioaddr[,memaddr]");
379 module_param_array(board2, charp, NULL, 0);
380 MODULE_PARM_DESC(board2, "Board 2 config -> name[,ioaddr[,memaddr]");
381 module_param_array(board3, charp, NULL, 0);
382 MODULE_PARM_DESC(board3, "Board 3 config -> name[,ioaddr[,memaddr]");
387 * Set up a default memory address table for EISA board probing.
388 * The default addresses are all bellow 1Mbyte, which has to be the
389 * case anyway. They should be safe, since we only read values from
390 * them, and interrupts are disabled while we do it. If the higher
391 * memory support is compiled in then we also try probing around
392 * the 1Gb, 2Gb and 3Gb areas as well...
394 static unsigned long stli_eisamemprobeaddrs[] = {
395 0xc0000, 0xd0000, 0xe0000, 0xf0000,
396 0x80000000, 0x80010000, 0x80020000, 0x80030000,
397 0x40000000, 0x40010000, 0x40020000, 0x40030000,
398 0xc0000000, 0xc0010000, 0xc0020000, 0xc0030000,
399 0xff000000, 0xff010000, 0xff020000, 0xff030000,
402 static int stli_eisamempsize = ARRAY_SIZE(stli_eisamemprobeaddrs);
405 * Define the Stallion PCI vendor and device IDs.
408 #ifndef PCI_VENDOR_ID_STALLION
409 #define PCI_VENDOR_ID_STALLION 0x124d
411 #ifndef PCI_DEVICE_ID_ECRA
412 #define PCI_DEVICE_ID_ECRA 0x0004
415 static struct pci_device_id istallion_pci_tbl[] = {
416 { PCI_DEVICE(PCI_VENDOR_ID_STALLION, PCI_DEVICE_ID_ECRA), },
419 MODULE_DEVICE_TABLE(pci, istallion_pci_tbl);
421 #endif /* CONFIG_PCI */
423 /*****************************************************************************/
426 * Hardware configuration info for ECP boards. These defines apply
427 * to the directly accessible io ports of the ECP. There is a set of
428 * defines for each ECP board type, ISA, EISA, MCA and PCI.
432 #define ECP_MEMSIZE (128 * 1024)
433 #define ECP_PCIMEMSIZE (256 * 1024)
435 #define ECP_ATPAGESIZE (4 * 1024)
436 #define ECP_MCPAGESIZE (4 * 1024)
437 #define ECP_EIPAGESIZE (64 * 1024)
438 #define ECP_PCIPAGESIZE (64 * 1024)
440 #define STL_EISAID 0x8c4e
443 * Important defines for the ISA class of ECP board.
446 #define ECP_ATCONFR 1
447 #define ECP_ATMEMAR 2
448 #define ECP_ATMEMPR 3
449 #define ECP_ATSTOP 0x1
450 #define ECP_ATINTENAB 0x10
451 #define ECP_ATENABLE 0x20
452 #define ECP_ATDISABLE 0x00
453 #define ECP_ATADDRMASK 0x3f000
454 #define ECP_ATADDRSHFT 12
457 * Important defines for the EISA class of ECP board.
460 #define ECP_EIMEMARL 1
461 #define ECP_EICONFR 2
462 #define ECP_EIMEMARH 3
463 #define ECP_EIENABLE 0x1
464 #define ECP_EIDISABLE 0x0
465 #define ECP_EISTOP 0x4
466 #define ECP_EIEDGE 0x00
467 #define ECP_EILEVEL 0x80
468 #define ECP_EIADDRMASKL 0x00ff0000
469 #define ECP_EIADDRSHFTL 16
470 #define ECP_EIADDRMASKH 0xff000000
471 #define ECP_EIADDRSHFTH 24
472 #define ECP_EIBRDENAB 0xc84
474 #define ECP_EISAID 0x4
477 * Important defines for the Micro-channel class of ECP board.
478 * (It has a lot in common with the ISA boards.)
481 #define ECP_MCCONFR 1
482 #define ECP_MCSTOP 0x20
483 #define ECP_MCENABLE 0x80
484 #define ECP_MCDISABLE 0x00
487 * Important defines for the PCI class of ECP board.
488 * (It has a lot in common with the other ECP boards.)
490 #define ECP_PCIIREG 0
491 #define ECP_PCICONFR 1
492 #define ECP_PCISTOP 0x01
495 * Hardware configuration info for ONboard and Brumby boards. These
496 * defines apply to the directly accessible io ports of these boards.
498 #define ONB_IOSIZE 16
499 #define ONB_MEMSIZE (64 * 1024)
500 #define ONB_ATPAGESIZE (64 * 1024)
501 #define ONB_MCPAGESIZE (64 * 1024)
502 #define ONB_EIMEMSIZE (128 * 1024)
503 #define ONB_EIPAGESIZE (64 * 1024)
506 * Important defines for the ISA class of ONboard board.
509 #define ONB_ATMEMAR 1
510 #define ONB_ATCONFR 2
511 #define ONB_ATSTOP 0x4
512 #define ONB_ATENABLE 0x01
513 #define ONB_ATDISABLE 0x00
514 #define ONB_ATADDRMASK 0xff0000
515 #define ONB_ATADDRSHFT 16
517 #define ONB_MEMENABLO 0
518 #define ONB_MEMENABHI 0x02
521 * Important defines for the EISA class of ONboard board.
524 #define ONB_EIMEMARL 1
525 #define ONB_EICONFR 2
526 #define ONB_EIMEMARH 3
527 #define ONB_EIENABLE 0x1
528 #define ONB_EIDISABLE 0x0
529 #define ONB_EISTOP 0x4
530 #define ONB_EIEDGE 0x00
531 #define ONB_EILEVEL 0x80
532 #define ONB_EIADDRMASKL 0x00ff0000
533 #define ONB_EIADDRSHFTL 16
534 #define ONB_EIADDRMASKH 0xff000000
535 #define ONB_EIADDRSHFTH 24
536 #define ONB_EIBRDENAB 0xc84
538 #define ONB_EISAID 0x1
541 * Important defines for the Brumby boards. They are pretty simple,
542 * there is not much that is programmably configurable.
544 #define BBY_IOSIZE 16
545 #define BBY_MEMSIZE (64 * 1024)
546 #define BBY_PAGESIZE (16 * 1024)
549 #define BBY_ATCONFR 1
550 #define BBY_ATSTOP 0x4
553 * Important defines for the Stallion boards. They are pretty simple,
554 * there is not much that is programmably configurable.
556 #define STAL_IOSIZE 16
557 #define STAL_MEMSIZE (64 * 1024)
558 #define STAL_PAGESIZE (64 * 1024)
561 * Define the set of status register values for EasyConnection panels.
562 * The signature will return with the status value for each panel. From
563 * this we can determine what is attached to the board - before we have
564 * actually down loaded any code to it.
566 #define ECH_PNLSTATUS 2
567 #define ECH_PNL16PORT 0x20
568 #define ECH_PNLIDMASK 0x07
569 #define ECH_PNLXPID 0x40
570 #define ECH_PNLINTRPEND 0x80
573 * Define some macros to do things to the board. Even those these boards
574 * are somewhat related there is often significantly different ways of
575 * doing some operation on it (like enable, paging, reset, etc). So each
576 * board class has a set of functions which do the commonly required
577 * operations. The macros below basically just call these functions,
578 * generally checking for a NULL function - which means that the board
579 * needs nothing done to it to achieve this operation!
581 #define EBRDINIT(brdp) \
582 if (brdp->init != NULL) \
585 #define EBRDENABLE(brdp) \
586 if (brdp->enable != NULL) \
587 (* brdp->enable)(brdp);
589 #define EBRDDISABLE(brdp) \
590 if (brdp->disable != NULL) \
591 (* brdp->disable)(brdp);
593 #define EBRDINTR(brdp) \
594 if (brdp->intr != NULL) \
595 (* brdp->intr)(brdp);
597 #define EBRDRESET(brdp) \
598 if (brdp->reset != NULL) \
599 (* brdp->reset)(brdp);
601 #define EBRDGETMEMPTR(brdp,offset) \
602 (* brdp->getmemptr)(brdp, offset, __LINE__)
605 * Define the maximal baud rate, and the default baud base for ports.
607 #define STL_MAXBAUD 460800
608 #define STL_BAUDBASE 115200
609 #define STL_CLOSEDELAY (5 * HZ / 10)
611 /*****************************************************************************/
614 * Define macros to extract a brd or port number from a minor number.
616 #define MINOR2BRD(min) (((min) & 0xc0) >> 6)
617 #define MINOR2PORT(min) ((min) & 0x3f)
620 * Define a baud rate table that converts termios baud rate selector
621 * into the actual baud rate value. All baud rate calculations are based
622 * on the actual baud rate required.
624 static unsigned int stli_baudrates[] = {
625 0, 50, 75, 110, 134, 150, 200, 300, 600, 1200, 1800, 2400, 4800,
626 9600, 19200, 38400, 57600, 115200, 230400, 460800, 921600
629 /*****************************************************************************/
632 * Define some handy local macros...
635 #define MIN(a,b) (((a) <= (b)) ? (a) : (b))
638 #define TOLOWER(x) ((((x) >= 'A') && ((x) <= 'Z')) ? ((x) + 0x20) : (x))
640 /*****************************************************************************/
643 * Prototype all functions in this driver!
647 static void stli_argbrds(void);
648 static int stli_parsebrd(stlconf_t *confp, char **argp);
650 static unsigned long stli_atol(char *str);
654 static int stli_open(struct tty_struct *tty, struct file *filp);
655 static void stli_close(struct tty_struct *tty, struct file *filp);
656 static int stli_write(struct tty_struct *tty, const unsigned char *buf, int count);
657 static void stli_putchar(struct tty_struct *tty, unsigned char ch);
658 static void stli_flushchars(struct tty_struct *tty);
659 static int stli_writeroom(struct tty_struct *tty);
660 static int stli_charsinbuffer(struct tty_struct *tty);
661 static int stli_ioctl(struct tty_struct *tty, struct file *file, unsigned int cmd, unsigned long arg);
662 static void stli_settermios(struct tty_struct *tty, struct termios *old);
663 static void stli_throttle(struct tty_struct *tty);
664 static void stli_unthrottle(struct tty_struct *tty);
665 static void stli_stop(struct tty_struct *tty);
666 static void stli_start(struct tty_struct *tty);
667 static void stli_flushbuffer(struct tty_struct *tty);
668 static void stli_breakctl(struct tty_struct *tty, int state);
669 static void stli_waituntilsent(struct tty_struct *tty, int timeout);
670 static void stli_sendxchar(struct tty_struct *tty, char ch);
671 static void stli_hangup(struct tty_struct *tty);
672 static int stli_portinfo(stlibrd_t *brdp, stliport_t *portp, int portnr, char *pos);
674 static int stli_brdinit(stlibrd_t *brdp);
675 static int stli_startbrd(stlibrd_t *brdp);
676 static ssize_t stli_memread(struct file *fp, char __user *buf, size_t count, loff_t *offp);
677 static ssize_t stli_memwrite(struct file *fp, const char __user *buf, size_t count, loff_t *offp);
678 static int stli_memioctl(struct inode *ip, struct file *fp, unsigned int cmd, unsigned long arg);
679 static void stli_brdpoll(stlibrd_t *brdp, cdkhdr_t __iomem *hdrp);
680 static void stli_poll(unsigned long arg);
681 static int stli_hostcmd(stlibrd_t *brdp, stliport_t *portp);
682 static int stli_initopen(stlibrd_t *brdp, stliport_t *portp);
683 static int stli_rawopen(stlibrd_t *brdp, stliport_t *portp, unsigned long arg, int wait);
684 static int stli_rawclose(stlibrd_t *brdp, stliport_t *portp, unsigned long arg, int wait);
685 static int stli_waitcarrier(stlibrd_t *brdp, stliport_t *portp, struct file *filp);
686 static void stli_dohangup(void *arg);
687 static int stli_setport(stliport_t *portp);
688 static int stli_cmdwait(stlibrd_t *brdp, stliport_t *portp, unsigned long cmd, void *arg, int size, int copyback);
689 static void stli_sendcmd(stlibrd_t *brdp, stliport_t *portp, unsigned long cmd, void *arg, int size, int copyback);
690 static void __stli_sendcmd(stlibrd_t *brdp, stliport_t *portp, unsigned long cmd, void *arg, int size, int copyback);
691 static void stli_dodelaycmd(stliport_t *portp, cdkctrl_t __iomem *cp);
692 static void stli_mkasyport(stliport_t *portp, asyport_t *pp, struct termios *tiosp);
693 static void stli_mkasysigs(asysigs_t *sp, int dtr, int rts);
694 static long stli_mktiocm(unsigned long sigvalue);
695 static void stli_read(stlibrd_t *brdp, stliport_t *portp);
696 static int stli_getserial(stliport_t *portp, struct serial_struct __user *sp);
697 static int stli_setserial(stliport_t *portp, struct serial_struct __user *sp);
698 static int stli_getbrdstats(combrd_t __user *bp);
699 static int stli_getportstats(stliport_t *portp, comstats_t __user *cp);
700 static int stli_portcmdstats(stliport_t *portp);
701 static int stli_clrportstats(stliport_t *portp, comstats_t __user *cp);
702 static int stli_getportstruct(stliport_t __user *arg);
703 static int stli_getbrdstruct(stlibrd_t __user *arg);
704 static stlibrd_t *stli_allocbrd(void);
706 static void stli_ecpinit(stlibrd_t *brdp);
707 static void stli_ecpenable(stlibrd_t *brdp);
708 static void stli_ecpdisable(stlibrd_t *brdp);
709 static char *stli_ecpgetmemptr(stlibrd_t *brdp, unsigned long offset, int line);
710 static void stli_ecpreset(stlibrd_t *brdp);
711 static void stli_ecpintr(stlibrd_t *brdp);
712 static void stli_ecpeiinit(stlibrd_t *brdp);
713 static void stli_ecpeienable(stlibrd_t *brdp);
714 static void stli_ecpeidisable(stlibrd_t *brdp);
715 static char *stli_ecpeigetmemptr(stlibrd_t *brdp, unsigned long offset, int line);
716 static void stli_ecpeireset(stlibrd_t *brdp);
717 static void stli_ecpmcenable(stlibrd_t *brdp);
718 static void stli_ecpmcdisable(stlibrd_t *brdp);
719 static char *stli_ecpmcgetmemptr(stlibrd_t *brdp, unsigned long offset, int line);
720 static void stli_ecpmcreset(stlibrd_t *brdp);
721 static void stli_ecppciinit(stlibrd_t *brdp);
722 static char *stli_ecppcigetmemptr(stlibrd_t *brdp, unsigned long offset, int line);
723 static void stli_ecppcireset(stlibrd_t *brdp);
725 static void stli_onbinit(stlibrd_t *brdp);
726 static void stli_onbenable(stlibrd_t *brdp);
727 static void stli_onbdisable(stlibrd_t *brdp);
728 static char *stli_onbgetmemptr(stlibrd_t *brdp, unsigned long offset, int line);
729 static void stli_onbreset(stlibrd_t *brdp);
730 static void stli_onbeinit(stlibrd_t *brdp);
731 static void stli_onbeenable(stlibrd_t *brdp);
732 static void stli_onbedisable(stlibrd_t *brdp);
733 static char *stli_onbegetmemptr(stlibrd_t *brdp, unsigned long offset, int line);
734 static void stli_onbereset(stlibrd_t *brdp);
735 static void stli_bbyinit(stlibrd_t *brdp);
736 static char *stli_bbygetmemptr(stlibrd_t *brdp, unsigned long offset, int line);
737 static void stli_bbyreset(stlibrd_t *brdp);
738 static void stli_stalinit(stlibrd_t *brdp);
739 static char *stli_stalgetmemptr(stlibrd_t *brdp, unsigned long offset, int line);
740 static void stli_stalreset(stlibrd_t *brdp);
742 static stliport_t *stli_getport(int brdnr, int panelnr, int portnr);
744 static int stli_initecp(stlibrd_t *brdp);
745 static int stli_initonb(stlibrd_t *brdp);
746 static int stli_eisamemprobe(stlibrd_t *brdp);
747 static int stli_initports(stlibrd_t *brdp);
750 static int stli_initpcibrd(int brdtype, struct pci_dev *devp);
753 /*****************************************************************************/
756 * Define the driver info for a user level shared memory device. This
757 * device will work sort of like the /dev/kmem device - except that it
758 * will give access to the shared memory on the Stallion intelligent
759 * board. This is also a very useful debugging tool.
761 static struct file_operations stli_fsiomem = {
762 .owner = THIS_MODULE,
763 .read = stli_memread,
764 .write = stli_memwrite,
765 .ioctl = stli_memioctl,
768 /*****************************************************************************/
771 * Define a timer_list entry for our poll routine. The slave board
772 * is polled every so often to see if anything needs doing. This is
773 * much cheaper on host cpu than using interrupts. It turns out to
774 * not increase character latency by much either...
776 static DEFINE_TIMER(stli_timerlist, stli_poll, 0, 0);
778 static int stli_timeron;
781 * Define the calculation for the timeout routine.
783 #define STLI_TIMEOUT (jiffies + 1)
785 /*****************************************************************************/
787 static struct class *istallion_class;
792 * Loadable module initialization stuff.
795 static int __init istallion_module_init(void)
801 /*****************************************************************************/
803 static void __exit istallion_module_exit(void)
809 printk(KERN_INFO "Unloading %s: version %s\n", stli_drvtitle,
813 * Free up all allocated resources used by the ports. This includes
814 * memory and interrupts.
818 del_timer_sync(&stli_timerlist);
821 i = tty_unregister_driver(stli_serial);
823 printk("STALLION: failed to un-register tty driver, "
827 put_tty_driver(stli_serial);
828 for (i = 0; i < 4; i++)
829 class_device_destroy(istallion_class, MKDEV(STL_SIOMEMMAJOR, i));
830 class_destroy(istallion_class);
831 if ((i = unregister_chrdev(STL_SIOMEMMAJOR, "staliomem")))
832 printk("STALLION: failed to un-register serial memory device, "
835 kfree(stli_txcookbuf);
837 for (i = 0; (i < stli_nrbrds); i++) {
838 if ((brdp = stli_brds[i]) == NULL)
840 for (j = 0; (j < STL_MAXPORTS); j++) {
841 portp = brdp->ports[j];
843 if (portp->tty != NULL)
844 tty_hangup(portp->tty);
849 iounmap(brdp->membase);
850 if (brdp->iosize > 0)
851 release_region(brdp->iobase, brdp->iosize);
857 module_init(istallion_module_init);
858 module_exit(istallion_module_exit);
860 /*****************************************************************************/
863 * Check for any arguments passed in on the module load command line.
866 static void stli_argbrds(void)
872 for (i = stli_nrbrds; i < ARRAY_SIZE(stli_brdsp); i++) {
873 memset(&conf, 0, sizeof(conf));
874 if (stli_parsebrd(&conf, stli_brdsp[i]) == 0)
876 if ((brdp = stli_allocbrd()) == NULL)
880 brdp->brdtype = conf.brdtype;
881 brdp->iobase = conf.ioaddr1;
882 brdp->memaddr = conf.memaddr;
887 /*****************************************************************************/
890 * Convert an ascii string number into an unsigned long.
893 static unsigned long stli_atol(char *str)
901 if ((*sp == '0') && (*(sp+1) == 'x')) {
904 } else if (*sp == '0') {
911 for (; (*sp != 0); sp++) {
912 c = (*sp > '9') ? (TOLOWER(*sp) - 'a' + 10) : (*sp - '0');
913 if ((c < 0) || (c >= base)) {
914 printk("STALLION: invalid argument %s\n", str);
918 val = (val * base) + c;
923 /*****************************************************************************/
926 * Parse the supplied argument string, into the board conf struct.
929 static int stli_parsebrd(stlconf_t *confp, char **argp)
934 if (argp[0] == NULL || *argp[0] == 0)
937 for (sp = argp[0], i = 0; ((*sp != 0) && (i < 25)); sp++, i++)
940 for (i = 0; i < ARRAY_SIZE(stli_brdstr); i++) {
941 if (strcmp(stli_brdstr[i].name, argp[0]) == 0)
944 if (i == ARRAY_SIZE(stli_brdstr)) {
945 printk("STALLION: unknown board name, %s?\n", argp[0]);
949 confp->brdtype = stli_brdstr[i].type;
950 if (argp[1] != NULL && *argp[1] != 0)
951 confp->ioaddr1 = stli_atol(argp[1]);
952 if (argp[2] != NULL && *argp[2] != 0)
953 confp->memaddr = stli_atol(argp[2]);
959 /*****************************************************************************/
961 static int stli_open(struct tty_struct *tty, struct file *filp)
965 unsigned int minordev;
966 int brdnr, portnr, rc;
968 minordev = tty->index;
969 brdnr = MINOR2BRD(minordev);
970 if (brdnr >= stli_nrbrds)
972 brdp = stli_brds[brdnr];
975 if ((brdp->state & BST_STARTED) == 0)
977 portnr = MINOR2PORT(minordev);
978 if ((portnr < 0) || (portnr > brdp->nrports))
981 portp = brdp->ports[portnr];
984 if (portp->devnr < 1)
989 * Check if this port is in the middle of closing. If so then wait
990 * until it is closed then return error status based on flag settings.
991 * The sleep here does not need interrupt protection since the wakeup
992 * for it is done with the same context.
994 if (portp->flags & ASYNC_CLOSING) {
995 interruptible_sleep_on(&portp->close_wait);
996 if (portp->flags & ASYNC_HUP_NOTIFY)
1002 * On the first open of the device setup the port hardware, and
1003 * initialize the per port data structure. Since initializing the port
1004 * requires several commands to the board we will need to wait for any
1005 * other open that is already initializing the port.
1008 tty->driver_data = portp;
1011 wait_event_interruptible(portp->raw_wait,
1012 !test_bit(ST_INITIALIZING, &portp->state));
1013 if (signal_pending(current))
1014 return -ERESTARTSYS;
1016 if ((portp->flags & ASYNC_INITIALIZED) == 0) {
1017 set_bit(ST_INITIALIZING, &portp->state);
1018 if ((rc = stli_initopen(brdp, portp)) >= 0) {
1019 portp->flags |= ASYNC_INITIALIZED;
1020 clear_bit(TTY_IO_ERROR, &tty->flags);
1022 clear_bit(ST_INITIALIZING, &portp->state);
1023 wake_up_interruptible(&portp->raw_wait);
1029 * Check if this port is in the middle of closing. If so then wait
1030 * until it is closed then return error status, based on flag settings.
1031 * The sleep here does not need interrupt protection since the wakeup
1032 * for it is done with the same context.
1034 if (portp->flags & ASYNC_CLOSING) {
1035 interruptible_sleep_on(&portp->close_wait);
1036 if (portp->flags & ASYNC_HUP_NOTIFY)
1038 return -ERESTARTSYS;
1042 * Based on type of open being done check if it can overlap with any
1043 * previous opens still in effect. If we are a normal serial device
1044 * then also we might have to wait for carrier.
1046 if (!(filp->f_flags & O_NONBLOCK)) {
1047 if ((rc = stli_waitcarrier(brdp, portp, filp)) != 0)
1050 portp->flags |= ASYNC_NORMAL_ACTIVE;
1054 /*****************************************************************************/
1056 static void stli_close(struct tty_struct *tty, struct file *filp)
1060 unsigned long flags;
1062 portp = tty->driver_data;
1066 spin_lock_irqsave(&stli_lock, flags);
1067 if (tty_hung_up_p(filp)) {
1068 spin_unlock_irqrestore(&stli_lock, flags);
1071 if ((tty->count == 1) && (portp->refcount != 1))
1072 portp->refcount = 1;
1073 if (portp->refcount-- > 1) {
1074 spin_unlock_irqrestore(&stli_lock, flags);
1078 portp->flags |= ASYNC_CLOSING;
1081 * May want to wait for data to drain before closing. The BUSY flag
1082 * keeps track of whether we are still transmitting or not. It is
1083 * updated by messages from the slave - indicating when all chars
1084 * really have drained.
1086 if (tty == stli_txcooktty)
1087 stli_flushchars(tty);
1089 spin_unlock_irqrestore(&stli_lock, flags);
1091 if (portp->closing_wait != ASYNC_CLOSING_WAIT_NONE)
1092 tty_wait_until_sent(tty, portp->closing_wait);
1094 portp->flags &= ~ASYNC_INITIALIZED;
1095 brdp = stli_brds[portp->brdnr];
1096 stli_rawclose(brdp, portp, 0, 0);
1097 if (tty->termios->c_cflag & HUPCL) {
1098 stli_mkasysigs(&portp->asig, 0, 0);
1099 if (test_bit(ST_CMDING, &portp->state))
1100 set_bit(ST_DOSIGS, &portp->state);
1102 stli_sendcmd(brdp, portp, A_SETSIGNALS, &portp->asig,
1103 sizeof(asysigs_t), 0);
1105 clear_bit(ST_TXBUSY, &portp->state);
1106 clear_bit(ST_RXSTOP, &portp->state);
1107 set_bit(TTY_IO_ERROR, &tty->flags);
1108 if (tty->ldisc.flush_buffer)
1109 (tty->ldisc.flush_buffer)(tty);
1110 set_bit(ST_DOFLUSHRX, &portp->state);
1111 stli_flushbuffer(tty);
1116 if (portp->openwaitcnt) {
1117 if (portp->close_delay)
1118 msleep_interruptible(jiffies_to_msecs(portp->close_delay));
1119 wake_up_interruptible(&portp->open_wait);
1122 portp->flags &= ~(ASYNC_NORMAL_ACTIVE|ASYNC_CLOSING);
1123 wake_up_interruptible(&portp->close_wait);
1126 /*****************************************************************************/
1129 * Carry out first open operations on a port. This involves a number of
1130 * commands to be sent to the slave. We need to open the port, set the
1131 * notification events, set the initial port settings, get and set the
1132 * initial signal values. We sleep and wait in between each one. But
1133 * this still all happens pretty quickly.
1136 static int stli_initopen(stlibrd_t *brdp, stliport_t *portp)
1138 struct tty_struct *tty;
1143 if ((rc = stli_rawopen(brdp, portp, 0, 1)) < 0)
1146 memset(&nt, 0, sizeof(asynotify_t));
1147 nt.data = (DT_TXLOW | DT_TXEMPTY | DT_RXBUSY | DT_RXBREAK);
1149 if ((rc = stli_cmdwait(brdp, portp, A_SETNOTIFY, &nt,
1150 sizeof(asynotify_t), 0)) < 0)
1156 stli_mkasyport(portp, &aport, tty->termios);
1157 if ((rc = stli_cmdwait(brdp, portp, A_SETPORT, &aport,
1158 sizeof(asyport_t), 0)) < 0)
1161 set_bit(ST_GETSIGS, &portp->state);
1162 if ((rc = stli_cmdwait(brdp, portp, A_GETSIGNALS, &portp->asig,
1163 sizeof(asysigs_t), 1)) < 0)
1165 if (test_and_clear_bit(ST_GETSIGS, &portp->state))
1166 portp->sigs = stli_mktiocm(portp->asig.sigvalue);
1167 stli_mkasysigs(&portp->asig, 1, 1);
1168 if ((rc = stli_cmdwait(brdp, portp, A_SETSIGNALS, &portp->asig,
1169 sizeof(asysigs_t), 0)) < 0)
1175 /*****************************************************************************/
1178 * Send an open message to the slave. This will sleep waiting for the
1179 * acknowledgement, so must have user context. We need to co-ordinate
1180 * with close events here, since we don't want open and close events
1184 static int stli_rawopen(stlibrd_t *brdp, stliport_t *portp, unsigned long arg, int wait)
1186 cdkhdr_t __iomem *hdrp;
1187 cdkctrl_t __iomem *cp;
1188 unsigned char __iomem *bits;
1189 unsigned long flags;
1193 * Send a message to the slave to open this port.
1197 * Slave is already closing this port. This can happen if a hangup
1198 * occurs on this port. So we must wait until it is complete. The
1199 * order of opens and closes may not be preserved across shared
1200 * memory, so we must wait until it is complete.
1202 wait_event_interruptible(portp->raw_wait,
1203 !test_bit(ST_CLOSING, &portp->state));
1204 if (signal_pending(current)) {
1205 return -ERESTARTSYS;
1209 * Everything is ready now, so write the open message into shared
1210 * memory. Once the message is in set the service bits to say that
1211 * this port wants service.
1213 spin_lock_irqsave(&brd_lock, flags);
1215 cp = &((cdkasy_t __iomem *) EBRDGETMEMPTR(brdp, portp->addr))->ctrl;
1216 writel(arg, &cp->openarg);
1217 writeb(1, &cp->open);
1218 hdrp = (cdkhdr_t __iomem *) EBRDGETMEMPTR(brdp, CDK_CDKADDR);
1219 bits = ((unsigned char __iomem *) hdrp) + brdp->slaveoffset +
1221 writeb(readb(bits) | portp->portbit, bits);
1225 spin_unlock_irqrestore(&brd_lock, flags);
1230 * Slave is in action, so now we must wait for the open acknowledgment
1234 set_bit(ST_OPENING, &portp->state);
1235 spin_unlock_irqrestore(&brd_lock, flags);
1237 wait_event_interruptible(portp->raw_wait,
1238 !test_bit(ST_OPENING, &portp->state));
1239 if (signal_pending(current))
1242 if ((rc == 0) && (portp->rc != 0))
1247 /*****************************************************************************/
1250 * Send a close message to the slave. Normally this will sleep waiting
1251 * for the acknowledgement, but if wait parameter is 0 it will not. If
1252 * wait is true then must have user context (to sleep).
1255 static int stli_rawclose(stlibrd_t *brdp, stliport_t *portp, unsigned long arg, int wait)
1257 cdkhdr_t __iomem *hdrp;
1258 cdkctrl_t __iomem *cp;
1259 unsigned char __iomem *bits;
1260 unsigned long flags;
1264 * Slave is already closing this port. This can happen if a hangup
1265 * occurs on this port.
1268 wait_event_interruptible(portp->raw_wait,
1269 !test_bit(ST_CLOSING, &portp->state));
1270 if (signal_pending(current)) {
1271 return -ERESTARTSYS;
1276 * Write the close command into shared memory.
1278 spin_lock_irqsave(&brd_lock, flags);
1280 cp = &((cdkasy_t __iomem *) EBRDGETMEMPTR(brdp, portp->addr))->ctrl;
1281 writel(arg, &cp->closearg);
1282 writeb(1, &cp->close);
1283 hdrp = (cdkhdr_t __iomem *) EBRDGETMEMPTR(brdp, CDK_CDKADDR);
1284 bits = ((unsigned char __iomem *) hdrp) + brdp->slaveoffset +
1286 writeb(readb(bits) |portp->portbit, bits);
1289 set_bit(ST_CLOSING, &portp->state);
1290 spin_unlock_irqrestore(&brd_lock, flags);
1296 * Slave is in action, so now we must wait for the open acknowledgment
1300 wait_event_interruptible(portp->raw_wait,
1301 !test_bit(ST_CLOSING, &portp->state));
1302 if (signal_pending(current))
1305 if ((rc == 0) && (portp->rc != 0))
1310 /*****************************************************************************/
1313 * Send a command to the slave and wait for the response. This must
1314 * have user context (it sleeps). This routine is generic in that it
1315 * can send any type of command. Its purpose is to wait for that command
1316 * to complete (as opposed to initiating the command then returning).
1319 static int stli_cmdwait(stlibrd_t *brdp, stliport_t *portp, unsigned long cmd, void *arg, int size, int copyback)
1321 wait_event_interruptible(portp->raw_wait,
1322 !test_bit(ST_CMDING, &portp->state));
1323 if (signal_pending(current))
1324 return -ERESTARTSYS;
1326 stli_sendcmd(brdp, portp, cmd, arg, size, copyback);
1328 wait_event_interruptible(portp->raw_wait,
1329 !test_bit(ST_CMDING, &portp->state));
1330 if (signal_pending(current))
1331 return -ERESTARTSYS;
1338 /*****************************************************************************/
1341 * Send the termios settings for this port to the slave. This sleeps
1342 * waiting for the command to complete - so must have user context.
1345 static int stli_setport(stliport_t *portp)
1352 if (portp->tty == NULL)
1354 if (portp->brdnr < 0 && portp->brdnr >= stli_nrbrds)
1356 brdp = stli_brds[portp->brdnr];
1360 stli_mkasyport(portp, &aport, portp->tty->termios);
1361 return(stli_cmdwait(brdp, portp, A_SETPORT, &aport, sizeof(asyport_t), 0));
1364 /*****************************************************************************/
1367 * Possibly need to wait for carrier (DCD signal) to come high. Say
1368 * maybe because if we are clocal then we don't need to wait...
1371 static int stli_waitcarrier(stlibrd_t *brdp, stliport_t *portp, struct file *filp)
1373 unsigned long flags;
1379 if (portp->tty->termios->c_cflag & CLOCAL)
1382 spin_lock_irqsave(&stli_lock, flags);
1383 portp->openwaitcnt++;
1384 if (! tty_hung_up_p(filp))
1386 spin_unlock_irqrestore(&stli_lock, flags);
1389 stli_mkasysigs(&portp->asig, 1, 1);
1390 if ((rc = stli_cmdwait(brdp, portp, A_SETSIGNALS,
1391 &portp->asig, sizeof(asysigs_t), 0)) < 0)
1393 if (tty_hung_up_p(filp) ||
1394 ((portp->flags & ASYNC_INITIALIZED) == 0)) {
1395 if (portp->flags & ASYNC_HUP_NOTIFY)
1401 if (((portp->flags & ASYNC_CLOSING) == 0) &&
1402 (doclocal || (portp->sigs & TIOCM_CD))) {
1405 if (signal_pending(current)) {
1409 interruptible_sleep_on(&portp->open_wait);
1412 spin_lock_irqsave(&stli_lock, flags);
1413 if (! tty_hung_up_p(filp))
1415 portp->openwaitcnt--;
1416 spin_unlock_irqrestore(&stli_lock, flags);
1421 /*****************************************************************************/
1424 * Write routine. Take the data and put it in the shared memory ring
1425 * queue. If port is not already sending chars then need to mark the
1426 * service bits for this port.
1429 static int stli_write(struct tty_struct *tty, const unsigned char *buf, int count)
1431 cdkasy_t __iomem *ap;
1432 cdkhdr_t __iomem *hdrp;
1433 unsigned char __iomem *bits;
1434 unsigned char __iomem *shbuf;
1435 unsigned char *chbuf;
1438 unsigned int len, stlen, head, tail, size;
1439 unsigned long flags;
1441 if (tty == stli_txcooktty)
1442 stli_flushchars(tty);
1443 portp = tty->driver_data;
1446 if ((portp->brdnr < 0) || (portp->brdnr >= stli_nrbrds))
1448 brdp = stli_brds[portp->brdnr];
1451 chbuf = (unsigned char *) buf;
1454 * All data is now local, shove as much as possible into shared memory.
1456 spin_lock_irqsave(&brd_lock, flags);
1458 ap = (cdkasy_t __iomem *) EBRDGETMEMPTR(brdp, portp->addr);
1459 head = (unsigned int) readw(&ap->txq.head);
1460 tail = (unsigned int) readw(&ap->txq.tail);
1461 if (tail != ((unsigned int) readw(&ap->txq.tail)))
1462 tail = (unsigned int) readw(&ap->txq.tail);
1463 size = portp->txsize;
1465 len = size - (head - tail) - 1;
1466 stlen = size - head;
1468 len = tail - head - 1;
1472 len = MIN(len, count);
1474 shbuf = (char __iomem *) EBRDGETMEMPTR(brdp, portp->txoffset);
1477 stlen = MIN(len, stlen);
1478 memcpy_toio(shbuf + head, chbuf, stlen);
1489 ap = (cdkasy_t __iomem *) EBRDGETMEMPTR(brdp, portp->addr);
1490 writew(head, &ap->txq.head);
1491 if (test_bit(ST_TXBUSY, &portp->state)) {
1492 if (readl(&ap->changed.data) & DT_TXEMPTY)
1493 writel(readl(&ap->changed.data) & ~DT_TXEMPTY, &ap->changed.data);
1495 hdrp = (cdkhdr_t __iomem *) EBRDGETMEMPTR(brdp, CDK_CDKADDR);
1496 bits = ((unsigned char __iomem *) hdrp) + brdp->slaveoffset +
1498 writeb(readb(bits) | portp->portbit, bits);
1499 set_bit(ST_TXBUSY, &portp->state);
1501 spin_unlock_irqrestore(&brd_lock, flags);
1506 /*****************************************************************************/
1509 * Output a single character. We put it into a temporary local buffer
1510 * (for speed) then write out that buffer when the flushchars routine
1511 * is called. There is a safety catch here so that if some other port
1512 * writes chars before the current buffer has been, then we write them
1513 * first them do the new ports.
1516 static void stli_putchar(struct tty_struct *tty, unsigned char ch)
1518 if (tty != stli_txcooktty) {
1519 if (stli_txcooktty != NULL)
1520 stli_flushchars(stli_txcooktty);
1521 stli_txcooktty = tty;
1524 stli_txcookbuf[stli_txcooksize++] = ch;
1527 /*****************************************************************************/
1530 * Transfer characters from the local TX cooking buffer to the board.
1531 * We sort of ignore the tty that gets passed in here. We rely on the
1532 * info stored with the TX cook buffer to tell us which port to flush
1533 * the data on. In any case we clean out the TX cook buffer, for re-use
1537 static void stli_flushchars(struct tty_struct *tty)
1539 cdkhdr_t __iomem *hdrp;
1540 unsigned char __iomem *bits;
1541 cdkasy_t __iomem *ap;
1542 struct tty_struct *cooktty;
1545 unsigned int len, stlen, head, tail, size, count, cooksize;
1547 unsigned char __iomem *shbuf;
1548 unsigned long flags;
1550 cooksize = stli_txcooksize;
1551 cooktty = stli_txcooktty;
1552 stli_txcooksize = 0;
1553 stli_txcookrealsize = 0;
1554 stli_txcooktty = NULL;
1558 if (cooktty == NULL)
1565 portp = tty->driver_data;
1568 if ((portp->brdnr < 0) || (portp->brdnr >= stli_nrbrds))
1570 brdp = stli_brds[portp->brdnr];
1574 spin_lock_irqsave(&brd_lock, flags);
1577 ap = (cdkasy_t __iomem *) EBRDGETMEMPTR(brdp, portp->addr);
1578 head = (unsigned int) readw(&ap->txq.head);
1579 tail = (unsigned int) readw(&ap->txq.tail);
1580 if (tail != ((unsigned int) readw(&ap->txq.tail)))
1581 tail = (unsigned int) readw(&ap->txq.tail);
1582 size = portp->txsize;
1584 len = size - (head - tail) - 1;
1585 stlen = size - head;
1587 len = tail - head - 1;
1591 len = MIN(len, cooksize);
1593 shbuf = (char *) EBRDGETMEMPTR(brdp, portp->txoffset);
1594 buf = stli_txcookbuf;
1597 stlen = MIN(len, stlen);
1598 memcpy_toio(shbuf + head, buf, stlen);
1609 ap = (cdkasy_t __iomem *) EBRDGETMEMPTR(brdp, portp->addr);
1610 writew(head, &ap->txq.head);
1612 if (test_bit(ST_TXBUSY, &portp->state)) {
1613 if (readl(&ap->changed.data) & DT_TXEMPTY)
1614 writel(readl(&ap->changed.data) & ~DT_TXEMPTY, &ap->changed.data);
1616 hdrp = (cdkhdr_t __iomem *) EBRDGETMEMPTR(brdp, CDK_CDKADDR);
1617 bits = ((unsigned char __iomem *) hdrp) + brdp->slaveoffset +
1619 writeb(readb(bits) | portp->portbit, bits);
1620 set_bit(ST_TXBUSY, &portp->state);
1623 spin_unlock_irqrestore(&brd_lock, flags);
1626 /*****************************************************************************/
1628 static int stli_writeroom(struct tty_struct *tty)
1630 cdkasyrq_t __iomem *rp;
1633 unsigned int head, tail, len;
1634 unsigned long flags;
1636 if (tty == stli_txcooktty) {
1637 if (stli_txcookrealsize != 0) {
1638 len = stli_txcookrealsize - stli_txcooksize;
1643 portp = tty->driver_data;
1646 if ((portp->brdnr < 0) || (portp->brdnr >= stli_nrbrds))
1648 brdp = stli_brds[portp->brdnr];
1652 spin_lock_irqsave(&brd_lock, flags);
1654 rp = &((cdkasy_t __iomem *) EBRDGETMEMPTR(brdp, portp->addr))->txq;
1655 head = (unsigned int) readw(&rp->head);
1656 tail = (unsigned int) readw(&rp->tail);
1657 if (tail != ((unsigned int) readw(&rp->tail)))
1658 tail = (unsigned int) readw(&rp->tail);
1659 len = (head >= tail) ? (portp->txsize - (head - tail)) : (tail - head);
1662 spin_unlock_irqrestore(&brd_lock, flags);
1664 if (tty == stli_txcooktty) {
1665 stli_txcookrealsize = len;
1666 len -= stli_txcooksize;
1671 /*****************************************************************************/
1674 * Return the number of characters in the transmit buffer. Normally we
1675 * will return the number of chars in the shared memory ring queue.
1676 * We need to kludge around the case where the shared memory buffer is
1677 * empty but not all characters have drained yet, for this case just
1678 * return that there is 1 character in the buffer!
1681 static int stli_charsinbuffer(struct tty_struct *tty)
1683 cdkasyrq_t __iomem *rp;
1686 unsigned int head, tail, len;
1687 unsigned long flags;
1689 if (tty == stli_txcooktty)
1690 stli_flushchars(tty);
1691 portp = tty->driver_data;
1694 if ((portp->brdnr < 0) || (portp->brdnr >= stli_nrbrds))
1696 brdp = stli_brds[portp->brdnr];
1700 spin_lock_irqsave(&brd_lock, flags);
1702 rp = &((cdkasy_t __iomem *) EBRDGETMEMPTR(brdp, portp->addr))->txq;
1703 head = (unsigned int) readw(&rp->head);
1704 tail = (unsigned int) readw(&rp->tail);
1705 if (tail != ((unsigned int) readw(&rp->tail)))
1706 tail = (unsigned int) readw(&rp->tail);
1707 len = (head >= tail) ? (head - tail) : (portp->txsize - (tail - head));
1708 if ((len == 0) && test_bit(ST_TXBUSY, &portp->state))
1711 spin_unlock_irqrestore(&brd_lock, flags);
1716 /*****************************************************************************/
1719 * Generate the serial struct info.
1722 static int stli_getserial(stliport_t *portp, struct serial_struct __user *sp)
1724 struct serial_struct sio;
1727 memset(&sio, 0, sizeof(struct serial_struct));
1728 sio.type = PORT_UNKNOWN;
1729 sio.line = portp->portnr;
1731 sio.flags = portp->flags;
1732 sio.baud_base = portp->baud_base;
1733 sio.close_delay = portp->close_delay;
1734 sio.closing_wait = portp->closing_wait;
1735 sio.custom_divisor = portp->custom_divisor;
1736 sio.xmit_fifo_size = 0;
1739 brdp = stli_brds[portp->brdnr];
1741 sio.port = brdp->iobase;
1743 return copy_to_user(sp, &sio, sizeof(struct serial_struct)) ?
1747 /*****************************************************************************/
1750 * Set port according to the serial struct info.
1751 * At this point we do not do any auto-configure stuff, so we will
1752 * just quietly ignore any requests to change irq, etc.
1755 static int stli_setserial(stliport_t *portp, struct serial_struct __user *sp)
1757 struct serial_struct sio;
1760 if (copy_from_user(&sio, sp, sizeof(struct serial_struct)))
1762 if (!capable(CAP_SYS_ADMIN)) {
1763 if ((sio.baud_base != portp->baud_base) ||
1764 (sio.close_delay != portp->close_delay) ||
1765 ((sio.flags & ~ASYNC_USR_MASK) !=
1766 (portp->flags & ~ASYNC_USR_MASK)))
1770 portp->flags = (portp->flags & ~ASYNC_USR_MASK) |
1771 (sio.flags & ASYNC_USR_MASK);
1772 portp->baud_base = sio.baud_base;
1773 portp->close_delay = sio.close_delay;
1774 portp->closing_wait = sio.closing_wait;
1775 portp->custom_divisor = sio.custom_divisor;
1777 if ((rc = stli_setport(portp)) < 0)
1782 /*****************************************************************************/
1784 static int stli_tiocmget(struct tty_struct *tty, struct file *file)
1786 stliport_t *portp = tty->driver_data;
1792 if (portp->brdnr < 0 || portp->brdnr >= stli_nrbrds)
1794 brdp = stli_brds[portp->brdnr];
1797 if (tty->flags & (1 << TTY_IO_ERROR))
1800 if ((rc = stli_cmdwait(brdp, portp, A_GETSIGNALS,
1801 &portp->asig, sizeof(asysigs_t), 1)) < 0)
1804 return stli_mktiocm(portp->asig.sigvalue);
1807 static int stli_tiocmset(struct tty_struct *tty, struct file *file,
1808 unsigned int set, unsigned int clear)
1810 stliport_t *portp = tty->driver_data;
1812 int rts = -1, dtr = -1;
1816 if (portp->brdnr < 0 || portp->brdnr >= stli_nrbrds)
1818 brdp = stli_brds[portp->brdnr];
1821 if (tty->flags & (1 << TTY_IO_ERROR))
1824 if (set & TIOCM_RTS)
1826 if (set & TIOCM_DTR)
1828 if (clear & TIOCM_RTS)
1830 if (clear & TIOCM_DTR)
1833 stli_mkasysigs(&portp->asig, dtr, rts);
1835 return stli_cmdwait(brdp, portp, A_SETSIGNALS, &portp->asig,
1836 sizeof(asysigs_t), 0);
1839 static int stli_ioctl(struct tty_struct *tty, struct file *file, unsigned int cmd, unsigned long arg)
1845 void __user *argp = (void __user *)arg;
1847 portp = tty->driver_data;
1850 if (portp->brdnr < 0 || portp->brdnr >= stli_nrbrds)
1852 brdp = stli_brds[portp->brdnr];
1856 if ((cmd != TIOCGSERIAL) && (cmd != TIOCSSERIAL) &&
1857 (cmd != COM_GETPORTSTATS) && (cmd != COM_CLRPORTSTATS)) {
1858 if (tty->flags & (1 << TTY_IO_ERROR))
1866 rc = put_user(((tty->termios->c_cflag & CLOCAL) ? 1 : 0),
1867 (unsigned __user *) arg);
1870 if ((rc = get_user(ival, (unsigned __user *) arg)) == 0)
1871 tty->termios->c_cflag =
1872 (tty->termios->c_cflag & ~CLOCAL) |
1873 (ival ? CLOCAL : 0);
1876 rc = stli_getserial(portp, argp);
1879 rc = stli_setserial(portp, argp);
1882 rc = put_user(portp->pflag, (unsigned __user *)argp);
1885 if ((rc = get_user(portp->pflag, (unsigned __user *)argp)) == 0)
1886 stli_setport(portp);
1888 case COM_GETPORTSTATS:
1889 rc = stli_getportstats(portp, argp);
1891 case COM_CLRPORTSTATS:
1892 rc = stli_clrportstats(portp, argp);
1898 case TIOCSERGSTRUCT:
1899 case TIOCSERGETMULTI:
1900 case TIOCSERSETMULTI:
1909 /*****************************************************************************/
1912 * This routine assumes that we have user context and can sleep.
1913 * Looks like it is true for the current ttys implementation..!!
1916 static void stli_settermios(struct tty_struct *tty, struct termios *old)
1920 struct termios *tiosp;
1925 portp = tty->driver_data;
1928 if (portp->brdnr < 0 || portp->brdnr >= stli_nrbrds)
1930 brdp = stli_brds[portp->brdnr];
1934 tiosp = tty->termios;
1935 if ((tiosp->c_cflag == old->c_cflag) &&
1936 (tiosp->c_iflag == old->c_iflag))
1939 stli_mkasyport(portp, &aport, tiosp);
1940 stli_cmdwait(brdp, portp, A_SETPORT, &aport, sizeof(asyport_t), 0);
1941 stli_mkasysigs(&portp->asig, ((tiosp->c_cflag & CBAUD) ? 1 : 0), -1);
1942 stli_cmdwait(brdp, portp, A_SETSIGNALS, &portp->asig,
1943 sizeof(asysigs_t), 0);
1944 if ((old->c_cflag & CRTSCTS) && ((tiosp->c_cflag & CRTSCTS) == 0))
1945 tty->hw_stopped = 0;
1946 if (((old->c_cflag & CLOCAL) == 0) && (tiosp->c_cflag & CLOCAL))
1947 wake_up_interruptible(&portp->open_wait);
1950 /*****************************************************************************/
1953 * Attempt to flow control who ever is sending us data. We won't really
1954 * do any flow control action here. We can't directly, and even if we
1955 * wanted to we would have to send a command to the slave. The slave
1956 * knows how to flow control, and will do so when its buffers reach its
1957 * internal high water marks. So what we will do is set a local state
1958 * bit that will stop us sending any RX data up from the poll routine
1959 * (which is the place where RX data from the slave is handled).
1962 static void stli_throttle(struct tty_struct *tty)
1964 stliport_t *portp = tty->driver_data;
1967 set_bit(ST_RXSTOP, &portp->state);
1970 /*****************************************************************************/
1973 * Unflow control the device sending us data... That means that all
1974 * we have to do is clear the RXSTOP state bit. The next poll call
1975 * will then be able to pass the RX data back up.
1978 static void stli_unthrottle(struct tty_struct *tty)
1980 stliport_t *portp = tty->driver_data;
1983 clear_bit(ST_RXSTOP, &portp->state);
1986 /*****************************************************************************/
1989 * Stop the transmitter.
1992 static void stli_stop(struct tty_struct *tty)
1996 /*****************************************************************************/
1999 * Start the transmitter again.
2002 static void stli_start(struct tty_struct *tty)
2006 /*****************************************************************************/
2009 * Scheduler called hang up routine. This is called from the scheduler,
2010 * not direct from the driver "poll" routine. We can't call it there
2011 * since the real local hangup code will enable/disable the board and
2012 * other things that we can't do while handling the poll. Much easier
2013 * to deal with it some time later (don't really care when, hangups
2014 * aren't that time critical).
2017 static void stli_dohangup(void *arg)
2019 stliport_t *portp = (stliport_t *) arg;
2020 if (portp->tty != NULL) {
2021 tty_hangup(portp->tty);
2025 /*****************************************************************************/
2028 * Hangup this port. This is pretty much like closing the port, only
2029 * a little more brutal. No waiting for data to drain. Shutdown the
2030 * port and maybe drop signals. This is rather tricky really. We want
2031 * to close the port as well.
2034 static void stli_hangup(struct tty_struct *tty)
2038 unsigned long flags;
2040 portp = tty->driver_data;
2043 if (portp->brdnr < 0 || portp->brdnr >= stli_nrbrds)
2045 brdp = stli_brds[portp->brdnr];
2049 portp->flags &= ~ASYNC_INITIALIZED;
2051 if (!test_bit(ST_CLOSING, &portp->state))
2052 stli_rawclose(brdp, portp, 0, 0);
2054 spin_lock_irqsave(&stli_lock, flags);
2055 if (tty->termios->c_cflag & HUPCL) {
2056 stli_mkasysigs(&portp->asig, 0, 0);
2057 if (test_bit(ST_CMDING, &portp->state)) {
2058 set_bit(ST_DOSIGS, &portp->state);
2059 set_bit(ST_DOFLUSHTX, &portp->state);
2060 set_bit(ST_DOFLUSHRX, &portp->state);
2062 stli_sendcmd(brdp, portp, A_SETSIGNALSF,
2063 &portp->asig, sizeof(asysigs_t), 0);
2067 clear_bit(ST_TXBUSY, &portp->state);
2068 clear_bit(ST_RXSTOP, &portp->state);
2069 set_bit(TTY_IO_ERROR, &tty->flags);
2071 portp->flags &= ~ASYNC_NORMAL_ACTIVE;
2072 portp->refcount = 0;
2073 spin_unlock_irqrestore(&stli_lock, flags);
2075 wake_up_interruptible(&portp->open_wait);
2078 /*****************************************************************************/
2081 * Flush characters from the lower buffer. We may not have user context
2082 * so we cannot sleep waiting for it to complete. Also we need to check
2083 * if there is chars for this port in the TX cook buffer, and flush them
2087 static void stli_flushbuffer(struct tty_struct *tty)
2091 unsigned long ftype, flags;
2093 portp = tty->driver_data;
2096 if (portp->brdnr < 0 || portp->brdnr >= stli_nrbrds)
2098 brdp = stli_brds[portp->brdnr];
2102 spin_lock_irqsave(&brd_lock, flags);
2103 if (tty == stli_txcooktty) {
2104 stli_txcooktty = NULL;
2105 stli_txcooksize = 0;
2106 stli_txcookrealsize = 0;
2108 if (test_bit(ST_CMDING, &portp->state)) {
2109 set_bit(ST_DOFLUSHTX, &portp->state);
2112 if (test_bit(ST_DOFLUSHRX, &portp->state)) {
2114 clear_bit(ST_DOFLUSHRX, &portp->state);
2116 __stli_sendcmd(brdp, portp, A_FLUSH, &ftype, sizeof(u32), 0);
2118 spin_unlock_irqrestore(&brd_lock, flags);
2122 /*****************************************************************************/
2124 static void stli_breakctl(struct tty_struct *tty, int state)
2130 portp = tty->driver_data;
2133 if (portp->brdnr < 0 || portp->brdnr >= stli_nrbrds)
2135 brdp = stli_brds[portp->brdnr];
2139 arg = (state == -1) ? BREAKON : BREAKOFF;
2140 stli_cmdwait(brdp, portp, A_BREAK, &arg, sizeof(long), 0);
2143 /*****************************************************************************/
2145 static void stli_waituntilsent(struct tty_struct *tty, int timeout)
2152 portp = tty->driver_data;
2158 tend = jiffies + timeout;
2160 while (test_bit(ST_TXBUSY, &portp->state)) {
2161 if (signal_pending(current))
2163 msleep_interruptible(20);
2164 if (time_after_eq(jiffies, tend))
2169 /*****************************************************************************/
2171 static void stli_sendxchar(struct tty_struct *tty, char ch)
2177 portp = tty->driver_data;
2180 if (portp->brdnr < 0 || portp->brdnr >= stli_nrbrds)
2182 brdp = stli_brds[portp->brdnr];
2186 memset(&actrl, 0, sizeof(asyctrl_t));
2187 if (ch == STOP_CHAR(tty)) {
2188 actrl.rxctrl = CT_STOPFLOW;
2189 } else if (ch == START_CHAR(tty)) {
2190 actrl.rxctrl = CT_STARTFLOW;
2192 actrl.txctrl = CT_SENDCHR;
2195 stli_cmdwait(brdp, portp, A_PORTCTRL, &actrl, sizeof(asyctrl_t), 0);
2198 /*****************************************************************************/
2203 * Format info for a specified port. The line is deliberately limited
2204 * to 80 characters. (If it is too long it will be truncated, if too
2205 * short then padded with spaces).
2208 static int stli_portinfo(stlibrd_t *brdp, stliport_t *portp, int portnr, char *pos)
2213 rc = stli_portcmdstats(portp);
2216 if (brdp->state & BST_STARTED) {
2217 switch (stli_comstats.hwid) {
2218 case 0: uart = "2681"; break;
2219 case 1: uart = "SC26198"; break;
2220 default:uart = "CD1400"; break;
2225 sp += sprintf(sp, "%d: uart:%s ", portnr, uart);
2227 if ((brdp->state & BST_STARTED) && (rc >= 0)) {
2228 sp += sprintf(sp, "tx:%d rx:%d", (int) stli_comstats.txtotal,
2229 (int) stli_comstats.rxtotal);
2231 if (stli_comstats.rxframing)
2232 sp += sprintf(sp, " fe:%d",
2233 (int) stli_comstats.rxframing);
2234 if (stli_comstats.rxparity)
2235 sp += sprintf(sp, " pe:%d",
2236 (int) stli_comstats.rxparity);
2237 if (stli_comstats.rxbreaks)
2238 sp += sprintf(sp, " brk:%d",
2239 (int) stli_comstats.rxbreaks);
2240 if (stli_comstats.rxoverrun)
2241 sp += sprintf(sp, " oe:%d",
2242 (int) stli_comstats.rxoverrun);
2244 cnt = sprintf(sp, "%s%s%s%s%s ",
2245 (stli_comstats.signals & TIOCM_RTS) ? "|RTS" : "",
2246 (stli_comstats.signals & TIOCM_CTS) ? "|CTS" : "",
2247 (stli_comstats.signals & TIOCM_DTR) ? "|DTR" : "",
2248 (stli_comstats.signals & TIOCM_CD) ? "|DCD" : "",
2249 (stli_comstats.signals & TIOCM_DSR) ? "|DSR" : "");
2254 for (cnt = (sp - pos); (cnt < (MAXLINE - 1)); cnt++)
2257 pos[(MAXLINE - 2)] = '+';
2258 pos[(MAXLINE - 1)] = '\n';
2263 /*****************************************************************************/
2266 * Port info, read from the /proc file system.
2269 static int stli_readproc(char *page, char **start, off_t off, int count, int *eof, void *data)
2273 int brdnr, portnr, totalport;
2282 pos += sprintf(pos, "%s: version %s", stli_drvtitle,
2284 while (pos < (page + MAXLINE - 1))
2291 * We scan through for each board, panel and port. The offset is
2292 * calculated on the fly, and irrelevant ports are skipped.
2294 for (brdnr = 0; (brdnr < stli_nrbrds); brdnr++) {
2295 brdp = stli_brds[brdnr];
2298 if (brdp->state == 0)
2301 maxoff = curoff + (brdp->nrports * MAXLINE);
2302 if (off >= maxoff) {
2307 totalport = brdnr * STL_MAXPORTS;
2308 for (portnr = 0; (portnr < brdp->nrports); portnr++,
2310 portp = brdp->ports[portnr];
2313 if (off >= (curoff += MAXLINE))
2315 if ((pos - page + MAXLINE) > count)
2317 pos += stli_portinfo(brdp, portp, totalport, pos);
2328 /*****************************************************************************/
2331 * Generic send command routine. This will send a message to the slave,
2332 * of the specified type with the specified argument. Must be very
2333 * careful of data that will be copied out from shared memory -
2334 * containing command results. The command completion is all done from
2335 * a poll routine that does not have user context. Therefore you cannot
2336 * copy back directly into user space, or to the kernel stack of a
2337 * process. This routine does not sleep, so can be called from anywhere.
2339 * The caller must hold the brd_lock (see also stli_sendcmd the usual
2343 static void __stli_sendcmd(stlibrd_t *brdp, stliport_t *portp, unsigned long cmd, void *arg, int size, int copyback)
2345 cdkhdr_t __iomem *hdrp;
2346 cdkctrl_t __iomem *cp;
2347 unsigned char __iomem *bits;
2348 unsigned long flags;
2350 spin_lock_irqsave(&brd_lock, flags);
2352 if (test_bit(ST_CMDING, &portp->state)) {
2353 printk(KERN_ERR "STALLION: command already busy, cmd=%x!\n",
2355 spin_unlock_irqrestore(&brd_lock, flags);
2360 cp = &((cdkasy_t __iomem *) EBRDGETMEMPTR(brdp, portp->addr))->ctrl;
2362 memcpy_toio((void __iomem *) &(cp->args[0]), arg, size);
2365 portp->argsize = size;
2368 writel(0, &cp->status);
2369 writel(cmd, &cp->cmd);
2370 hdrp = (cdkhdr_t __iomem *) EBRDGETMEMPTR(brdp, CDK_CDKADDR);
2371 bits = ((unsigned char __iomem *) hdrp) + brdp->slaveoffset +
2373 writeb(readb(bits) | portp->portbit, bits);
2374 set_bit(ST_CMDING, &portp->state);
2376 spin_unlock_irqrestore(&brd_lock, flags);
2379 static void stli_sendcmd(stlibrd_t *brdp, stliport_t *portp, unsigned long cmd, void *arg, int size, int copyback)
2381 unsigned long flags;
2383 spin_lock_irqsave(&brd_lock, flags);
2384 __stli_sendcmd(brdp, portp, cmd, arg, size, copyback);
2385 spin_unlock_irqrestore(&brd_lock, flags);
2388 /*****************************************************************************/
2391 * Read data from shared memory. This assumes that the shared memory
2392 * is enabled and that interrupts are off. Basically we just empty out
2393 * the shared memory buffer into the tty buffer. Must be careful to
2394 * handle the case where we fill up the tty buffer, but still have
2395 * more chars to unload.
2398 static void stli_read(stlibrd_t *brdp, stliport_t *portp)
2400 cdkasyrq_t __iomem *rp;
2401 char __iomem *shbuf;
2402 struct tty_struct *tty;
2403 unsigned int head, tail, size;
2404 unsigned int len, stlen;
2406 if (test_bit(ST_RXSTOP, &portp->state))
2412 rp = &((cdkasy_t __iomem *) EBRDGETMEMPTR(brdp, portp->addr))->rxq;
2413 head = (unsigned int) readw(&rp->head);
2414 if (head != ((unsigned int) readw(&rp->head)))
2415 head = (unsigned int) readw(&rp->head);
2416 tail = (unsigned int) readw(&rp->tail);
2417 size = portp->rxsize;
2422 len = size - (tail - head);
2423 stlen = size - tail;
2426 len = tty_buffer_request_room(tty, len);
2428 shbuf = (char __iomem *) EBRDGETMEMPTR(brdp, portp->rxoffset);
2431 unsigned char *cptr;
2433 stlen = MIN(len, stlen);
2434 tty_prepare_flip_string(tty, &cptr, stlen);
2435 memcpy_fromio(cptr, shbuf + tail, stlen);
2443 rp = &((cdkasy_t __iomem *) EBRDGETMEMPTR(brdp, portp->addr))->rxq;
2444 writew(tail, &rp->tail);
2447 set_bit(ST_RXING, &portp->state);
2449 tty_schedule_flip(tty);
2452 /*****************************************************************************/
2455 * Set up and carry out any delayed commands. There is only a small set
2456 * of slave commands that can be done "off-level". So it is not too
2457 * difficult to deal with them here.
2460 static void stli_dodelaycmd(stliport_t *portp, cdkctrl_t __iomem *cp)
2464 if (test_bit(ST_DOSIGS, &portp->state)) {
2465 if (test_bit(ST_DOFLUSHTX, &portp->state) &&
2466 test_bit(ST_DOFLUSHRX, &portp->state))
2467 cmd = A_SETSIGNALSF;
2468 else if (test_bit(ST_DOFLUSHTX, &portp->state))
2469 cmd = A_SETSIGNALSFTX;
2470 else if (test_bit(ST_DOFLUSHRX, &portp->state))
2471 cmd = A_SETSIGNALSFRX;
2474 clear_bit(ST_DOFLUSHTX, &portp->state);
2475 clear_bit(ST_DOFLUSHRX, &portp->state);
2476 clear_bit(ST_DOSIGS, &portp->state);
2477 memcpy_toio((void __iomem *) &(cp->args[0]), (void *) &portp->asig,
2479 writel(0, &cp->status);
2480 writel(cmd, &cp->cmd);
2481 set_bit(ST_CMDING, &portp->state);
2482 } else if (test_bit(ST_DOFLUSHTX, &portp->state) ||
2483 test_bit(ST_DOFLUSHRX, &portp->state)) {
2484 cmd = ((test_bit(ST_DOFLUSHTX, &portp->state)) ? FLUSHTX : 0);
2485 cmd |= ((test_bit(ST_DOFLUSHRX, &portp->state)) ? FLUSHRX : 0);
2486 clear_bit(ST_DOFLUSHTX, &portp->state);
2487 clear_bit(ST_DOFLUSHRX, &portp->state);
2488 memcpy_toio((void __iomem *) &(cp->args[0]), (void *) &cmd, sizeof(int));
2489 writel(0, &cp->status);
2490 writel(A_FLUSH, &cp->cmd);
2491 set_bit(ST_CMDING, &portp->state);
2495 /*****************************************************************************/
2498 * Host command service checking. This handles commands or messages
2499 * coming from the slave to the host. Must have board shared memory
2500 * enabled and interrupts off when called. Notice that by servicing the
2501 * read data last we don't need to change the shared memory pointer
2502 * during processing (which is a slow IO operation).
2503 * Return value indicates if this port is still awaiting actions from
2504 * the slave (like open, command, or even TX data being sent). If 0
2505 * then port is still busy, otherwise no longer busy.
2508 static int stli_hostcmd(stlibrd_t *brdp, stliport_t *portp)
2510 cdkasy_t __iomem *ap;
2511 cdkctrl_t __iomem *cp;
2512 struct tty_struct *tty;
2514 unsigned long oldsigs;
2517 ap = (cdkasy_t __iomem *) EBRDGETMEMPTR(brdp, portp->addr);
2521 * Check if we are waiting for an open completion message.
2523 if (test_bit(ST_OPENING, &portp->state)) {
2524 rc = readl(&cp->openarg);
2525 if (readb(&cp->open) == 0 && rc != 0) {
2528 writel(0, &cp->openarg);
2530 clear_bit(ST_OPENING, &portp->state);
2531 wake_up_interruptible(&portp->raw_wait);
2536 * Check if we are waiting for a close completion message.
2538 if (test_bit(ST_CLOSING, &portp->state)) {
2539 rc = (int) readl(&cp->closearg);
2540 if (readb(&cp->close) == 0 && rc != 0) {
2543 writel(0, &cp->closearg);
2545 clear_bit(ST_CLOSING, &portp->state);
2546 wake_up_interruptible(&portp->raw_wait);
2551 * Check if we are waiting for a command completion message. We may
2552 * need to copy out the command results associated with this command.
2554 if (test_bit(ST_CMDING, &portp->state)) {
2555 rc = readl(&cp->status);
2556 if (readl(&cp->cmd) == 0 && rc != 0) {
2559 if (portp->argp != NULL) {
2560 memcpy_fromio(portp->argp, (void __iomem *) &(cp->args[0]),
2564 writel(0, &cp->status);
2566 clear_bit(ST_CMDING, &portp->state);
2567 stli_dodelaycmd(portp, cp);
2568 wake_up_interruptible(&portp->raw_wait);
2573 * Check for any notification messages ready. This includes lots of
2574 * different types of events - RX chars ready, RX break received,
2575 * TX data low or empty in the slave, modem signals changed state.
2584 if (nt.signal & SG_DCD) {
2585 oldsigs = portp->sigs;
2586 portp->sigs = stli_mktiocm(nt.sigvalue);
2587 clear_bit(ST_GETSIGS, &portp->state);
2588 if ((portp->sigs & TIOCM_CD) &&
2589 ((oldsigs & TIOCM_CD) == 0))
2590 wake_up_interruptible(&portp->open_wait);
2591 if ((oldsigs & TIOCM_CD) &&
2592 ((portp->sigs & TIOCM_CD) == 0)) {
2593 if (portp->flags & ASYNC_CHECK_CD) {
2595 schedule_work(&portp->tqhangup);
2600 if (nt.data & DT_TXEMPTY)
2601 clear_bit(ST_TXBUSY, &portp->state);
2602 if (nt.data & (DT_TXEMPTY | DT_TXLOW)) {
2606 wake_up_interruptible(&tty->write_wait);
2610 if ((nt.data & DT_RXBREAK) && (portp->rxmarkmsk & BRKINT)) {
2612 tty_insert_flip_char(tty, 0, TTY_BREAK);
2613 if (portp->flags & ASYNC_SAK) {
2617 tty_schedule_flip(tty);
2621 if (nt.data & DT_RXBUSY) {
2623 stli_read(brdp, portp);
2628 * It might seem odd that we are checking for more RX chars here.
2629 * But, we need to handle the case where the tty buffer was previously
2630 * filled, but we had more characters to pass up. The slave will not
2631 * send any more RX notify messages until the RX buffer has been emptied.
2632 * But it will leave the service bits on (since the buffer is not empty).
2633 * So from here we can try to process more RX chars.
2635 if ((!donerx) && test_bit(ST_RXING, &portp->state)) {
2636 clear_bit(ST_RXING, &portp->state);
2637 stli_read(brdp, portp);
2640 return((test_bit(ST_OPENING, &portp->state) ||
2641 test_bit(ST_CLOSING, &portp->state) ||
2642 test_bit(ST_CMDING, &portp->state) ||
2643 test_bit(ST_TXBUSY, &portp->state) ||
2644 test_bit(ST_RXING, &portp->state)) ? 0 : 1);
2647 /*****************************************************************************/
2650 * Service all ports on a particular board. Assumes that the boards
2651 * shared memory is enabled, and that the page pointer is pointed
2652 * at the cdk header structure.
2655 static void stli_brdpoll(stlibrd_t *brdp, cdkhdr_t __iomem *hdrp)
2658 unsigned char hostbits[(STL_MAXCHANS / 8) + 1];
2659 unsigned char slavebits[(STL_MAXCHANS / 8) + 1];
2660 unsigned char __iomem *slavep;
2661 int bitpos, bitat, bitsize;
2662 int channr, nrdevs, slavebitchange;
2664 bitsize = brdp->bitsize;
2665 nrdevs = brdp->nrdevs;
2668 * Check if slave wants any service. Basically we try to do as
2669 * little work as possible here. There are 2 levels of service
2670 * bits. So if there is nothing to do we bail early. We check
2671 * 8 service bits at a time in the inner loop, so we can bypass
2672 * the lot if none of them want service.
2674 memcpy_fromio(&hostbits[0], (((unsigned char __iomem *) hdrp) + brdp->hostoffset),
2677 memset(&slavebits[0], 0, bitsize);
2680 for (bitpos = 0; (bitpos < bitsize); bitpos++) {
2681 if (hostbits[bitpos] == 0)
2683 channr = bitpos * 8;
2684 for (bitat = 0x1; (channr < nrdevs); channr++, bitat <<= 1) {
2685 if (hostbits[bitpos] & bitat) {
2686 portp = brdp->ports[(channr - 1)];
2687 if (stli_hostcmd(brdp, portp)) {
2689 slavebits[bitpos] |= bitat;
2696 * If any of the ports are no longer busy then update them in the
2697 * slave request bits. We need to do this after, since a host port
2698 * service may initiate more slave requests.
2700 if (slavebitchange) {
2701 hdrp = (cdkhdr_t __iomem *) EBRDGETMEMPTR(brdp, CDK_CDKADDR);
2702 slavep = ((unsigned char __iomem *) hdrp) + brdp->slaveoffset;
2703 for (bitpos = 0; (bitpos < bitsize); bitpos++) {
2704 if (readb(slavebits + bitpos))
2705 writeb(readb(slavep + bitpos) & ~slavebits[bitpos], slavebits + bitpos);
2710 /*****************************************************************************/
2713 * Driver poll routine. This routine polls the boards in use and passes
2714 * messages back up to host when necessary. This is actually very
2715 * CPU efficient, since we will always have the kernel poll clock, it
2716 * adds only a few cycles when idle (since board service can be
2717 * determined very easily), but when loaded generates no interrupts
2718 * (with their expensive associated context change).
2721 static void stli_poll(unsigned long arg)
2723 cdkhdr_t __iomem *hdrp;
2727 stli_timerlist.expires = STLI_TIMEOUT;
2728 add_timer(&stli_timerlist);
2731 * Check each board and do any servicing required.
2733 for (brdnr = 0; (brdnr < stli_nrbrds); brdnr++) {
2734 brdp = stli_brds[brdnr];
2737 if ((brdp->state & BST_STARTED) == 0)
2740 spin_lock(&brd_lock);
2742 hdrp = (cdkhdr_t __iomem *) EBRDGETMEMPTR(brdp, CDK_CDKADDR);
2743 if (readb(&hdrp->hostreq))
2744 stli_brdpoll(brdp, hdrp);
2746 spin_unlock(&brd_lock);
2750 /*****************************************************************************/
2753 * Translate the termios settings into the port setting structure of
2757 static void stli_mkasyport(stliport_t *portp, asyport_t *pp, struct termios *tiosp)
2759 memset(pp, 0, sizeof(asyport_t));
2762 * Start of by setting the baud, char size, parity and stop bit info.
2764 pp->baudout = tiosp->c_cflag & CBAUD;
2765 if (pp->baudout & CBAUDEX) {
2766 pp->baudout &= ~CBAUDEX;
2767 if ((pp->baudout < 1) || (pp->baudout > 4))
2768 tiosp->c_cflag &= ~CBAUDEX;
2772 pp->baudout = stli_baudrates[pp->baudout];
2773 if ((tiosp->c_cflag & CBAUD) == B38400) {
2774 if ((portp->flags & ASYNC_SPD_MASK) == ASYNC_SPD_HI)
2775 pp->baudout = 57600;
2776 else if ((portp->flags & ASYNC_SPD_MASK) == ASYNC_SPD_VHI)
2777 pp->baudout = 115200;
2778 else if ((portp->flags & ASYNC_SPD_MASK) == ASYNC_SPD_SHI)
2779 pp->baudout = 230400;
2780 else if ((portp->flags & ASYNC_SPD_MASK) == ASYNC_SPD_WARP)
2781 pp->baudout = 460800;
2782 else if ((portp->flags & ASYNC_SPD_MASK) == ASYNC_SPD_CUST)
2783 pp->baudout = (portp->baud_base / portp->custom_divisor);
2785 if (pp->baudout > STL_MAXBAUD)
2786 pp->baudout = STL_MAXBAUD;
2787 pp->baudin = pp->baudout;
2789 switch (tiosp->c_cflag & CSIZE) {
2804 if (tiosp->c_cflag & CSTOPB)
2805 pp->stopbs = PT_STOP2;
2807 pp->stopbs = PT_STOP1;
2809 if (tiosp->c_cflag & PARENB) {
2810 if (tiosp->c_cflag & PARODD)
2811 pp->parity = PT_ODDPARITY;
2813 pp->parity = PT_EVENPARITY;
2815 pp->parity = PT_NOPARITY;
2819 * Set up any flow control options enabled.
2821 if (tiosp->c_iflag & IXON) {
2823 if (tiosp->c_iflag & IXANY)
2824 pp->flow |= F_IXANY;
2826 if (tiosp->c_cflag & CRTSCTS)
2827 pp->flow |= (F_RTSFLOW | F_CTSFLOW);
2829 pp->startin = tiosp->c_cc[VSTART];
2830 pp->stopin = tiosp->c_cc[VSTOP];
2831 pp->startout = tiosp->c_cc[VSTART];
2832 pp->stopout = tiosp->c_cc[VSTOP];
2835 * Set up the RX char marking mask with those RX error types we must
2836 * catch. We can get the slave to help us out a little here, it will
2837 * ignore parity errors and breaks for us, and mark parity errors in
2840 if (tiosp->c_iflag & IGNPAR)
2841 pp->iflag |= FI_IGNRXERRS;
2842 if (tiosp->c_iflag & IGNBRK)
2843 pp->iflag |= FI_IGNBREAK;
2845 portp->rxmarkmsk = 0;
2846 if (tiosp->c_iflag & (INPCK | PARMRK))
2847 pp->iflag |= FI_1MARKRXERRS;
2848 if (tiosp->c_iflag & BRKINT)
2849 portp->rxmarkmsk |= BRKINT;
2852 * Set up clocal processing as required.
2854 if (tiosp->c_cflag & CLOCAL)
2855 portp->flags &= ~ASYNC_CHECK_CD;
2857 portp->flags |= ASYNC_CHECK_CD;
2860 * Transfer any persistent flags into the asyport structure.
2862 pp->pflag = (portp->pflag & 0xffff);
2863 pp->vmin = (portp->pflag & P_RXIMIN) ? 1 : 0;
2864 pp->vtime = (portp->pflag & P_RXITIME) ? 1 : 0;
2865 pp->cc[1] = (portp->pflag & P_RXTHOLD) ? 1 : 0;
2868 /*****************************************************************************/
2871 * Construct a slave signals structure for setting the DTR and RTS
2872 * signals as specified.
2875 static void stli_mkasysigs(asysigs_t *sp, int dtr, int rts)
2877 memset(sp, 0, sizeof(asysigs_t));
2879 sp->signal |= SG_DTR;
2880 sp->sigvalue |= ((dtr > 0) ? SG_DTR : 0);
2883 sp->signal |= SG_RTS;
2884 sp->sigvalue |= ((rts > 0) ? SG_RTS : 0);
2888 /*****************************************************************************/
2891 * Convert the signals returned from the slave into a local TIOCM type
2892 * signals value. We keep them locally in TIOCM format.
2895 static long stli_mktiocm(unsigned long sigvalue)
2898 tiocm |= ((sigvalue & SG_DCD) ? TIOCM_CD : 0);
2899 tiocm |= ((sigvalue & SG_CTS) ? TIOCM_CTS : 0);
2900 tiocm |= ((sigvalue & SG_RI) ? TIOCM_RI : 0);
2901 tiocm |= ((sigvalue & SG_DSR) ? TIOCM_DSR : 0);
2902 tiocm |= ((sigvalue & SG_DTR) ? TIOCM_DTR : 0);
2903 tiocm |= ((sigvalue & SG_RTS) ? TIOCM_RTS : 0);
2907 /*****************************************************************************/
2910 * All panels and ports actually attached have been worked out. All
2911 * we need to do here is set up the appropriate per port data structures.
2914 static int stli_initports(stlibrd_t *brdp)
2917 int i, panelnr, panelport;
2919 for (i = 0, panelnr = 0, panelport = 0; (i < brdp->nrports); i++) {
2920 portp = kzalloc(sizeof(stliport_t), GFP_KERNEL);
2922 printk("STALLION: failed to allocate port structure\n");
2926 portp->magic = STLI_PORTMAGIC;
2928 portp->brdnr = brdp->brdnr;
2929 portp->panelnr = panelnr;
2930 portp->baud_base = STL_BAUDBASE;
2931 portp->close_delay = STL_CLOSEDELAY;
2932 portp->closing_wait = 30 * HZ;
2933 INIT_WORK(&portp->tqhangup, stli_dohangup, portp);
2934 init_waitqueue_head(&portp->open_wait);
2935 init_waitqueue_head(&portp->close_wait);
2936 init_waitqueue_head(&portp->raw_wait);
2938 if (panelport >= brdp->panels[panelnr]) {
2942 brdp->ports[i] = portp;
2948 /*****************************************************************************/
2951 * All the following routines are board specific hardware operations.
2954 static void stli_ecpinit(stlibrd_t *brdp)
2956 unsigned long memconf;
2958 outb(ECP_ATSTOP, (brdp->iobase + ECP_ATCONFR));
2960 outb(ECP_ATDISABLE, (brdp->iobase + ECP_ATCONFR));
2963 memconf = (brdp->memaddr & ECP_ATADDRMASK) >> ECP_ATADDRSHFT;
2964 outb(memconf, (brdp->iobase + ECP_ATMEMAR));
2967 /*****************************************************************************/
2969 static void stli_ecpenable(stlibrd_t *brdp)
2971 outb(ECP_ATENABLE, (brdp->iobase + ECP_ATCONFR));
2974 /*****************************************************************************/
2976 static void stli_ecpdisable(stlibrd_t *brdp)
2978 outb(ECP_ATDISABLE, (brdp->iobase + ECP_ATCONFR));
2981 /*****************************************************************************/
2983 static char *stli_ecpgetmemptr(stlibrd_t *brdp, unsigned long offset, int line)
2988 if (offset > brdp->memsize) {
2989 printk(KERN_ERR "STALLION: shared memory pointer=%x out of "
2990 "range at line=%d(%d), brd=%d\n",
2991 (int) offset, line, __LINE__, brdp->brdnr);
2995 ptr = brdp->membase + (offset % ECP_ATPAGESIZE);
2996 val = (unsigned char) (offset / ECP_ATPAGESIZE);
2998 outb(val, (brdp->iobase + ECP_ATMEMPR));
3002 /*****************************************************************************/
3004 static void stli_ecpreset(stlibrd_t *brdp)
3006 outb(ECP_ATSTOP, (brdp->iobase + ECP_ATCONFR));
3008 outb(ECP_ATDISABLE, (brdp->iobase + ECP_ATCONFR));
3012 /*****************************************************************************/
3014 static void stli_ecpintr(stlibrd_t *brdp)
3016 outb(0x1, brdp->iobase);
3019 /*****************************************************************************/
3022 * The following set of functions act on ECP EISA boards.
3025 static void stli_ecpeiinit(stlibrd_t *brdp)
3027 unsigned long memconf;
3029 outb(0x1, (brdp->iobase + ECP_EIBRDENAB));
3030 outb(ECP_EISTOP, (brdp->iobase + ECP_EICONFR));
3032 outb(ECP_EIDISABLE, (brdp->iobase + ECP_EICONFR));
3035 memconf = (brdp->memaddr & ECP_EIADDRMASKL) >> ECP_EIADDRSHFTL;
3036 outb(memconf, (brdp->iobase + ECP_EIMEMARL));
3037 memconf = (brdp->memaddr & ECP_EIADDRMASKH) >> ECP_EIADDRSHFTH;
3038 outb(memconf, (brdp->iobase + ECP_EIMEMARH));
3041 /*****************************************************************************/
3043 static void stli_ecpeienable(stlibrd_t *brdp)
3045 outb(ECP_EIENABLE, (brdp->iobase + ECP_EICONFR));
3048 /*****************************************************************************/
3050 static void stli_ecpeidisable(stlibrd_t *brdp)
3052 outb(ECP_EIDISABLE, (brdp->iobase + ECP_EICONFR));
3055 /*****************************************************************************/
3057 static char *stli_ecpeigetmemptr(stlibrd_t *brdp, unsigned long offset, int line)
3062 if (offset > brdp->memsize) {
3063 printk(KERN_ERR "STALLION: shared memory pointer=%x out of "
3064 "range at line=%d(%d), brd=%d\n",
3065 (int) offset, line, __LINE__, brdp->brdnr);
3069 ptr = brdp->membase + (offset % ECP_EIPAGESIZE);
3070 if (offset < ECP_EIPAGESIZE)
3073 val = ECP_EIENABLE | 0x40;
3075 outb(val, (brdp->iobase + ECP_EICONFR));
3079 /*****************************************************************************/
3081 static void stli_ecpeireset(stlibrd_t *brdp)
3083 outb(ECP_EISTOP, (brdp->iobase + ECP_EICONFR));
3085 outb(ECP_EIDISABLE, (brdp->iobase + ECP_EICONFR));
3089 /*****************************************************************************/
3092 * The following set of functions act on ECP MCA boards.
3095 static void stli_ecpmcenable(stlibrd_t *brdp)
3097 outb(ECP_MCENABLE, (brdp->iobase + ECP_MCCONFR));
3100 /*****************************************************************************/
3102 static void stli_ecpmcdisable(stlibrd_t *brdp)
3104 outb(ECP_MCDISABLE, (brdp->iobase + ECP_MCCONFR));
3107 /*****************************************************************************/
3109 static char *stli_ecpmcgetmemptr(stlibrd_t *brdp, unsigned long offset, int line)
3114 if (offset > brdp->memsize) {
3115 printk(KERN_ERR "STALLION: shared memory pointer=%x out of "
3116 "range at line=%d(%d), brd=%d\n",
3117 (int) offset, line, __LINE__, brdp->brdnr);
3121 ptr = brdp->membase + (offset % ECP_MCPAGESIZE);
3122 val = ((unsigned char) (offset / ECP_MCPAGESIZE)) | ECP_MCENABLE;
3124 outb(val, (brdp->iobase + ECP_MCCONFR));
3128 /*****************************************************************************/
3130 static void stli_ecpmcreset(stlibrd_t *brdp)
3132 outb(ECP_MCSTOP, (brdp->iobase + ECP_MCCONFR));
3134 outb(ECP_MCDISABLE, (brdp->iobase + ECP_MCCONFR));
3138 /*****************************************************************************/
3141 * The following set of functions act on ECP PCI boards.
3144 static void stli_ecppciinit(stlibrd_t *brdp)
3146 outb(ECP_PCISTOP, (brdp->iobase + ECP_PCICONFR));
3148 outb(0, (brdp->iobase + ECP_PCICONFR));
3152 /*****************************************************************************/
3154 static char *stli_ecppcigetmemptr(stlibrd_t *brdp, unsigned long offset, int line)
3159 if (offset > brdp->memsize) {
3160 printk(KERN_ERR "STALLION: shared memory pointer=%x out of "
3161 "range at line=%d(%d), board=%d\n",
3162 (int) offset, line, __LINE__, brdp->brdnr);
3166 ptr = brdp->membase + (offset % ECP_PCIPAGESIZE);
3167 val = (offset / ECP_PCIPAGESIZE) << 1;
3169 outb(val, (brdp->iobase + ECP_PCICONFR));
3173 /*****************************************************************************/
3175 static void stli_ecppcireset(stlibrd_t *brdp)
3177 outb(ECP_PCISTOP, (brdp->iobase + ECP_PCICONFR));
3179 outb(0, (brdp->iobase + ECP_PCICONFR));
3183 /*****************************************************************************/
3186 * The following routines act on ONboards.
3189 static void stli_onbinit(stlibrd_t *brdp)
3191 unsigned long memconf;
3193 outb(ONB_ATSTOP, (brdp->iobase + ONB_ATCONFR));
3195 outb(ONB_ATDISABLE, (brdp->iobase + ONB_ATCONFR));
3198 memconf = (brdp->memaddr & ONB_ATADDRMASK) >> ONB_ATADDRSHFT;
3199 outb(memconf, (brdp->iobase + ONB_ATMEMAR));
3200 outb(0x1, brdp->iobase);
3204 /*****************************************************************************/
3206 static void stli_onbenable(stlibrd_t *brdp)
3208 outb((brdp->enabval | ONB_ATENABLE), (brdp->iobase + ONB_ATCONFR));
3211 /*****************************************************************************/
3213 static void stli_onbdisable(stlibrd_t *brdp)
3215 outb((brdp->enabval | ONB_ATDISABLE), (brdp->iobase + ONB_ATCONFR));
3218 /*****************************************************************************/
3220 static char *stli_onbgetmemptr(stlibrd_t *brdp, unsigned long offset, int line)
3224 if (offset > brdp->memsize) {
3225 printk(KERN_ERR "STALLION: shared memory pointer=%x out of "
3226 "range at line=%d(%d), brd=%d\n",
3227 (int) offset, line, __LINE__, brdp->brdnr);
3230 ptr = brdp->membase + (offset % ONB_ATPAGESIZE);
3235 /*****************************************************************************/
3237 static void stli_onbreset(stlibrd_t *brdp)
3239 outb(ONB_ATSTOP, (brdp->iobase + ONB_ATCONFR));
3241 outb(ONB_ATDISABLE, (brdp->iobase + ONB_ATCONFR));
3245 /*****************************************************************************/
3248 * The following routines act on ONboard EISA.
3251 static void stli_onbeinit(stlibrd_t *brdp)
3253 unsigned long memconf;
3255 outb(0x1, (brdp->iobase + ONB_EIBRDENAB));
3256 outb(ONB_EISTOP, (brdp->iobase + ONB_EICONFR));
3258 outb(ONB_EIDISABLE, (brdp->iobase + ONB_EICONFR));
3261 memconf = (brdp->memaddr & ONB_EIADDRMASKL) >> ONB_EIADDRSHFTL;
3262 outb(memconf, (brdp->iobase + ONB_EIMEMARL));
3263 memconf = (brdp->memaddr & ONB_EIADDRMASKH) >> ONB_EIADDRSHFTH;
3264 outb(memconf, (brdp->iobase + ONB_EIMEMARH));
3265 outb(0x1, brdp->iobase);
3269 /*****************************************************************************/
3271 static void stli_onbeenable(stlibrd_t *brdp)
3273 outb(ONB_EIENABLE, (brdp->iobase + ONB_EICONFR));
3276 /*****************************************************************************/
3278 static void stli_onbedisable(stlibrd_t *brdp)
3280 outb(ONB_EIDISABLE, (brdp->iobase + ONB_EICONFR));
3283 /*****************************************************************************/
3285 static char *stli_onbegetmemptr(stlibrd_t *brdp, unsigned long offset, int line)
3290 if (offset > brdp->memsize) {
3291 printk(KERN_ERR "STALLION: shared memory pointer=%x out of "
3292 "range at line=%d(%d), brd=%d\n",
3293 (int) offset, line, __LINE__, brdp->brdnr);
3297 ptr = brdp->membase + (offset % ONB_EIPAGESIZE);
3298 if (offset < ONB_EIPAGESIZE)
3301 val = ONB_EIENABLE | 0x40;
3303 outb(val, (brdp->iobase + ONB_EICONFR));
3307 /*****************************************************************************/
3309 static void stli_onbereset(stlibrd_t *brdp)
3311 outb(ONB_EISTOP, (brdp->iobase + ONB_EICONFR));
3313 outb(ONB_EIDISABLE, (brdp->iobase + ONB_EICONFR));
3317 /*****************************************************************************/
3320 * The following routines act on Brumby boards.
3323 static void stli_bbyinit(stlibrd_t *brdp)
3325 outb(BBY_ATSTOP, (brdp->iobase + BBY_ATCONFR));
3327 outb(0, (brdp->iobase + BBY_ATCONFR));
3329 outb(0x1, brdp->iobase);
3333 /*****************************************************************************/
3335 static char *stli_bbygetmemptr(stlibrd_t *brdp, unsigned long offset, int line)
3340 BUG_ON(offset > brdp->memsize);
3342 ptr = brdp->membase + (offset % BBY_PAGESIZE);
3343 val = (unsigned char) (offset / BBY_PAGESIZE);
3344 outb(val, (brdp->iobase + BBY_ATCONFR));
3348 /*****************************************************************************/
3350 static void stli_bbyreset(stlibrd_t *brdp)
3352 outb(BBY_ATSTOP, (brdp->iobase + BBY_ATCONFR));
3354 outb(0, (brdp->iobase + BBY_ATCONFR));
3358 /*****************************************************************************/
3361 * The following routines act on original old Stallion boards.
3364 static void stli_stalinit(stlibrd_t *brdp)
3366 outb(0x1, brdp->iobase);
3370 /*****************************************************************************/
3372 static char *stli_stalgetmemptr(stlibrd_t *brdp, unsigned long offset, int line)
3374 BUG_ON(offset > brdp->memsize);
3375 return brdp->membase + (offset % STAL_PAGESIZE);
3378 /*****************************************************************************/
3380 static void stli_stalreset(stlibrd_t *brdp)
3384 vecp = (u32 __iomem *) (brdp->membase + 0x30);
3385 writel(0xffff0000, vecp);
3386 outb(0, brdp->iobase);
3390 /*****************************************************************************/
3393 * Try to find an ECP board and initialize it. This handles only ECP
3397 static int stli_initecp(stlibrd_t *brdp)
3400 cdkecpsig_t __iomem *sigsp;
3401 unsigned int status, nxtid;
3403 int panelnr, nrports;
3405 if (!request_region(brdp->iobase, brdp->iosize, "istallion"))
3408 if ((brdp->iobase == 0) || (brdp->memaddr == 0))
3410 release_region(brdp->iobase, brdp->iosize);
3414 brdp->iosize = ECP_IOSIZE;
3417 * Based on the specific board type setup the common vars to access
3418 * and enable shared memory. Set all board specific information now
3421 switch (brdp->brdtype) {
3423 brdp->membase = (void *) brdp->memaddr;
3424 brdp->memsize = ECP_MEMSIZE;
3425 brdp->pagesize = ECP_ATPAGESIZE;
3426 brdp->init = stli_ecpinit;
3427 brdp->enable = stli_ecpenable;
3428 brdp->reenable = stli_ecpenable;
3429 brdp->disable = stli_ecpdisable;
3430 brdp->getmemptr = stli_ecpgetmemptr;
3431 brdp->intr = stli_ecpintr;
3432 brdp->reset = stli_ecpreset;
3433 name = "serial(EC8/64)";
3437 brdp->membase = (void *) brdp->memaddr;
3438 brdp->memsize = ECP_MEMSIZE;
3439 brdp->pagesize = ECP_EIPAGESIZE;
3440 brdp->init = stli_ecpeiinit;
3441 brdp->enable = stli_ecpeienable;
3442 brdp->reenable = stli_ecpeienable;
3443 brdp->disable = stli_ecpeidisable;
3444 brdp->getmemptr = stli_ecpeigetmemptr;
3445 brdp->intr = stli_ecpintr;
3446 brdp->reset = stli_ecpeireset;
3447 name = "serial(EC8/64-EI)";
3451 brdp->membase = (void *) brdp->memaddr;
3452 brdp->memsize = ECP_MEMSIZE;
3453 brdp->pagesize = ECP_MCPAGESIZE;
3455 brdp->enable = stli_ecpmcenable;
3456 brdp->reenable = stli_ecpmcenable;
3457 brdp->disable = stli_ecpmcdisable;
3458 brdp->getmemptr = stli_ecpmcgetmemptr;
3459 brdp->intr = stli_ecpintr;
3460 brdp->reset = stli_ecpmcreset;
3461 name = "serial(EC8/64-MCA)";
3465 brdp->membase = (void *) brdp->memaddr;
3466 brdp->memsize = ECP_PCIMEMSIZE;
3467 brdp->pagesize = ECP_PCIPAGESIZE;
3468 brdp->init = stli_ecppciinit;
3469 brdp->enable = NULL;
3470 brdp->reenable = NULL;
3471 brdp->disable = NULL;
3472 brdp->getmemptr = stli_ecppcigetmemptr;
3473 brdp->intr = stli_ecpintr;
3474 brdp->reset = stli_ecppcireset;
3475 name = "serial(EC/RA-PCI)";
3479 release_region(brdp->iobase, brdp->iosize);
3484 * The per-board operations structure is all set up, so now let's go
3485 * and get the board operational. Firstly initialize board configuration
3486 * registers. Set the memory mapping info so we can get at the boards
3491 brdp->membase = ioremap(brdp->memaddr, brdp->memsize);
3492 if (brdp->membase == NULL)
3494 release_region(brdp->iobase, brdp->iosize);
3499 * Now that all specific code is set up, enable the shared memory and
3500 * look for the a signature area that will tell us exactly what board
3501 * this is, and what it is connected to it.
3504 sigsp = (cdkecpsig_t __iomem *) EBRDGETMEMPTR(brdp, CDK_SIGADDR);
3505 memcpy(&sig, sigsp, sizeof(cdkecpsig_t));
3508 if (sig.magic != cpu_to_le32(ECP_MAGIC))
3510 release_region(brdp->iobase, brdp->iosize);
3515 * Scan through the signature looking at the panels connected to the
3516 * board. Calculate the total number of ports as we go.
3518 for (panelnr = 0, nxtid = 0; (panelnr < STL_MAXPANELS); panelnr++) {
3519 status = sig.panelid[nxtid];
3520 if ((status & ECH_PNLIDMASK) != nxtid)
3523 brdp->panelids[panelnr] = status;
3524 nrports = (status & ECH_PNL16PORT) ? 16 : 8;
3525 if ((nrports == 16) && ((status & ECH_PNLXPID) == 0))
3527 brdp->panels[panelnr] = nrports;
3528 brdp->nrports += nrports;
3534 brdp->state |= BST_FOUND;
3538 /*****************************************************************************/
3541 * Try to find an ONboard, Brumby or Stallion board and initialize it.
3542 * This handles only these board types.
3545 static int stli_initonb(stlibrd_t *brdp)
3548 cdkonbsig_t __iomem *sigsp;
3553 * Do a basic sanity check on the IO and memory addresses.
3555 if (brdp->iobase == 0 || brdp->memaddr == 0)
3558 brdp->iosize = ONB_IOSIZE;
3560 if (!request_region(brdp->iobase, brdp->iosize, "istallion"))
3564 * Based on the specific board type setup the common vars to access
3565 * and enable shared memory. Set all board specific information now
3568 switch (brdp->brdtype) {
3572 case BRD_ONBOARD2_32:
3574 brdp->memsize = ONB_MEMSIZE;
3575 brdp->pagesize = ONB_ATPAGESIZE;
3576 brdp->init = stli_onbinit;
3577 brdp->enable = stli_onbenable;
3578 brdp->reenable = stli_onbenable;
3579 brdp->disable = stli_onbdisable;
3580 brdp->getmemptr = stli_onbgetmemptr;
3581 brdp->intr = stli_ecpintr;
3582 brdp->reset = stli_onbreset;
3583 if (brdp->memaddr > 0x100000)
3584 brdp->enabval = ONB_MEMENABHI;
3586 brdp->enabval = ONB_MEMENABLO;
3587 name = "serial(ONBoard)";
3591 brdp->memsize = ONB_EIMEMSIZE;
3592 brdp->pagesize = ONB_EIPAGESIZE;
3593 brdp->init = stli_onbeinit;
3594 brdp->enable = stli_onbeenable;
3595 brdp->reenable = stli_onbeenable;
3596 brdp->disable = stli_onbedisable;
3597 brdp->getmemptr = stli_onbegetmemptr;
3598 brdp->intr = stli_ecpintr;
3599 brdp->reset = stli_onbereset;
3600 name = "serial(ONBoard/E)";
3606 brdp->memsize = BBY_MEMSIZE;
3607 brdp->pagesize = BBY_PAGESIZE;
3608 brdp->init = stli_bbyinit;
3609 brdp->enable = NULL;
3610 brdp->reenable = NULL;
3611 brdp->disable = NULL;
3612 brdp->getmemptr = stli_bbygetmemptr;
3613 brdp->intr = stli_ecpintr;
3614 brdp->reset = stli_bbyreset;
3615 name = "serial(Brumby)";
3619 brdp->memsize = STAL_MEMSIZE;
3620 brdp->pagesize = STAL_PAGESIZE;
3621 brdp->init = stli_stalinit;
3622 brdp->enable = NULL;
3623 brdp->reenable = NULL;
3624 brdp->disable = NULL;
3625 brdp->getmemptr = stli_stalgetmemptr;
3626 brdp->intr = stli_ecpintr;
3627 brdp->reset = stli_stalreset;
3628 name = "serial(Stallion)";
3632 release_region(brdp->iobase, brdp->iosize);
3637 * The per-board operations structure is all set up, so now let's go
3638 * and get the board operational. Firstly initialize board configuration
3639 * registers. Set the memory mapping info so we can get at the boards
3644 brdp->membase = ioremap(brdp->memaddr, brdp->memsize);
3645 if (brdp->membase == NULL)
3647 release_region(brdp->iobase, brdp->iosize);
3652 * Now that all specific code is set up, enable the shared memory and
3653 * look for the a signature area that will tell us exactly what board
3654 * this is, and how many ports.
3657 sigsp = (cdkonbsig_t __iomem *) EBRDGETMEMPTR(brdp, CDK_SIGADDR);
3658 memcpy_fromio(&sig, sigsp, sizeof(cdkonbsig_t));
3661 if (sig.magic0 != cpu_to_le16(ONB_MAGIC0) ||
3662 sig.magic1 != cpu_to_le16(ONB_MAGIC1) ||
3663 sig.magic2 != cpu_to_le16(ONB_MAGIC2) ||
3664 sig.magic3 != cpu_to_le16(ONB_MAGIC3))
3666 release_region(brdp->iobase, brdp->iosize);
3671 * Scan through the signature alive mask and calculate how many ports
3672 * there are on this board.
3678 for (i = 0; (i < 16); i++) {
3679 if (((sig.amask0 << i) & 0x8000) == 0)
3684 brdp->panels[0] = brdp->nrports;
3687 brdp->state |= BST_FOUND;
3691 /*****************************************************************************/
3694 * Start up a running board. This routine is only called after the
3695 * code has been down loaded to the board and is operational. It will
3696 * read in the memory map, and get the show on the road...
3699 static int stli_startbrd(stlibrd_t *brdp)
3701 cdkhdr_t __iomem *hdrp;
3702 cdkmem_t __iomem *memp;
3703 cdkasy_t __iomem *ap;
3704 unsigned long flags;
3706 int portnr, nrdevs, i, rc = 0;
3709 spin_lock_irqsave(&brd_lock, flags);
3711 hdrp = (cdkhdr_t __iomem *) EBRDGETMEMPTR(brdp, CDK_CDKADDR);
3712 nrdevs = hdrp->nrdevs;
3715 printk("%s(%d): CDK version %d.%d.%d --> "
3716 "nrdevs=%d memp=%x hostp=%x slavep=%x\n",
3717 __FILE__, __LINE__, readb(&hdrp->ver_release), readb(&hdrp->ver_modification),
3718 readb(&hdrp->ver_fix), nrdevs, (int) readl(&hdrp->memp), readl(&hdrp->hostp),
3719 readl(&hdrp->slavep));
3722 if (nrdevs < (brdp->nrports + 1)) {
3723 printk(KERN_ERR "STALLION: slave failed to allocate memory for "
3724 "all devices, devices=%d\n", nrdevs);
3725 brdp->nrports = nrdevs - 1;
3727 brdp->nrdevs = nrdevs;
3728 brdp->hostoffset = hdrp->hostp - CDK_CDKADDR;
3729 brdp->slaveoffset = hdrp->slavep - CDK_CDKADDR;
3730 brdp->bitsize = (nrdevs + 7) / 8;
3731 memoff = readl(&hdrp->memp);
3732 if (memoff > brdp->memsize) {
3733 printk(KERN_ERR "STALLION: corrupted shared memory region?\n");
3735 goto stli_donestartup;
3737 memp = (cdkmem_t __iomem *) EBRDGETMEMPTR(brdp, memoff);
3738 if (readw(&memp->dtype) != TYP_ASYNCTRL) {
3739 printk(KERN_ERR "STALLION: no slave control device found\n");
3740 goto stli_donestartup;
3745 * Cycle through memory allocation of each port. We are guaranteed to
3746 * have all ports inside the first page of slave window, so no need to
3747 * change pages while reading memory map.
3749 for (i = 1, portnr = 0; (i < nrdevs); i++, portnr++, memp++) {
3750 if (readw(&memp->dtype) != TYP_ASYNC)
3752 portp = brdp->ports[portnr];
3756 portp->addr = readl(&memp->offset);
3757 portp->reqbit = (unsigned char) (0x1 << (i * 8 / nrdevs));
3758 portp->portidx = (unsigned char) (i / 8);
3759 portp->portbit = (unsigned char) (0x1 << (i % 8));
3762 writeb(0xff, &hdrp->slavereq);
3765 * For each port setup a local copy of the RX and TX buffer offsets
3766 * and sizes. We do this separate from the above, because we need to
3767 * move the shared memory page...
3769 for (i = 1, portnr = 0; (i < nrdevs); i++, portnr++) {
3770 portp = brdp->ports[portnr];
3773 if (portp->addr == 0)
3775 ap = (cdkasy_t __iomem *) EBRDGETMEMPTR(brdp, portp->addr);
3777 portp->rxsize = readw(&ap->rxq.size);
3778 portp->txsize = readw(&ap->txq.size);
3779 portp->rxoffset = readl(&ap->rxq.offset);
3780 portp->txoffset = readl(&ap->txq.offset);
3786 spin_unlock_irqrestore(&brd_lock, flags);
3789 brdp->state |= BST_STARTED;
3791 if (! stli_timeron) {
3793 stli_timerlist.expires = STLI_TIMEOUT;
3794 add_timer(&stli_timerlist);
3800 /*****************************************************************************/
3803 * Probe and initialize the specified board.
3806 static int __init stli_brdinit(stlibrd_t *brdp)
3808 stli_brds[brdp->brdnr] = brdp;
3810 switch (brdp->brdtype) {
3821 case BRD_ONBOARD2_32:
3833 printk(KERN_ERR "STALLION: %s board type not supported in "
3834 "this driver\n", stli_brdnames[brdp->brdtype]);
3837 printk(KERN_ERR "STALLION: board=%d is unknown board "
3838 "type=%d\n", brdp->brdnr, brdp->brdtype);
3842 if ((brdp->state & BST_FOUND) == 0) {
3843 printk(KERN_ERR "STALLION: %s board not found, board=%d "
3845 stli_brdnames[brdp->brdtype], brdp->brdnr,
3846 brdp->iobase, (int) brdp->memaddr);
3850 stli_initports(brdp);
3851 printk(KERN_INFO "STALLION: %s found, board=%d io=%x mem=%x "
3852 "nrpanels=%d nrports=%d\n", stli_brdnames[brdp->brdtype],
3853 brdp->brdnr, brdp->iobase, (int) brdp->memaddr,
3854 brdp->nrpanels, brdp->nrports);
3858 /*****************************************************************************/
3861 * Probe around trying to find where the EISA boards shared memory
3862 * might be. This is a bit if hack, but it is the best we can do.
3865 static int stli_eisamemprobe(stlibrd_t *brdp)
3867 cdkecpsig_t ecpsig, __iomem *ecpsigp;
3868 cdkonbsig_t onbsig, __iomem *onbsigp;
3872 * First up we reset the board, to get it into a known state. There
3873 * is only 2 board types here we need to worry about. Don;t use the
3874 * standard board init routine here, it programs up the shared
3875 * memory address, and we don't know it yet...
3877 if (brdp->brdtype == BRD_ECPE) {
3878 outb(0x1, (brdp->iobase + ECP_EIBRDENAB));
3879 outb(ECP_EISTOP, (brdp->iobase + ECP_EICONFR));
3881 outb(ECP_EIDISABLE, (brdp->iobase + ECP_EICONFR));
3883 stli_ecpeienable(brdp);
3884 } else if (brdp->brdtype == BRD_ONBOARDE) {
3885 outb(0x1, (brdp->iobase + ONB_EIBRDENAB));
3886 outb(ONB_EISTOP, (brdp->iobase + ONB_EICONFR));
3888 outb(ONB_EIDISABLE, (brdp->iobase + ONB_EICONFR));
3890 outb(0x1, brdp->iobase);
3892 stli_onbeenable(brdp);
3898 brdp->memsize = ECP_MEMSIZE;
3901 * Board shared memory is enabled, so now we have a poke around and
3902 * see if we can find it.
3904 for (i = 0; (i < stli_eisamempsize); i++) {
3905 brdp->memaddr = stli_eisamemprobeaddrs[i];
3906 brdp->membase = ioremap(brdp->memaddr, brdp->memsize);
3907 if (brdp->membase == NULL)
3910 if (brdp->brdtype == BRD_ECPE) {
3911 ecpsigp = (cdkecpsig_t __iomem *) stli_ecpeigetmemptr(brdp,
3912 CDK_SIGADDR, __LINE__);
3913 memcpy_fromio(&ecpsig, ecpsigp, sizeof(cdkecpsig_t));
3914 if (ecpsig.magic == cpu_to_le32(ECP_MAGIC))
3917 onbsigp = (cdkonbsig_t __iomem *) stli_onbegetmemptr(brdp,
3918 CDK_SIGADDR, __LINE__);
3919 memcpy_fromio(&onbsig, onbsigp, sizeof(cdkonbsig_t));
3920 if ((onbsig.magic0 == cpu_to_le16(ONB_MAGIC0)) &&
3921 (onbsig.magic1 == cpu_to_le16(ONB_MAGIC1)) &&
3922 (onbsig.magic2 == cpu_to_le16(ONB_MAGIC2)) &&
3923 (onbsig.magic3 == cpu_to_le16(ONB_MAGIC3)))
3927 iounmap(brdp->membase);
3933 * Regardless of whether we found the shared memory or not we must
3934 * disable the region. After that return success or failure.
3936 if (brdp->brdtype == BRD_ECPE)
3937 stli_ecpeidisable(brdp);
3939 stli_onbedisable(brdp);
3943 brdp->membase = NULL;
3944 printk(KERN_ERR "STALLION: failed to probe shared memory "
3945 "region for %s in EISA slot=%d\n",
3946 stli_brdnames[brdp->brdtype], (brdp->iobase >> 12));
3952 static int stli_getbrdnr(void)
3956 for (i = 0; i < STL_MAXBRDS; i++) {
3957 if (!stli_brds[i]) {
3958 if (i >= stli_nrbrds)
3959 stli_nrbrds = i + 1;
3966 /*****************************************************************************/
3969 * Probe around and try to find any EISA boards in system. The biggest
3970 * problem here is finding out what memory address is associated with
3971 * an EISA board after it is found. The registers of the ECPE and
3972 * ONboardE are not readable - so we can't read them from there. We
3973 * don't have access to the EISA CMOS (or EISA BIOS) so we don't
3974 * actually have any way to find out the real value. The best we can
3975 * do is go probing around in the usual places hoping we can find it.
3978 static int stli_findeisabrds(void)
3981 unsigned int iobase, eid;
3985 * Firstly check if this is an EISA system. If this is not an EISA system then
3986 * don't bother going any further!
3992 * Looks like an EISA system, so go searching for EISA boards.
3994 for (iobase = 0x1000; (iobase <= 0xc000); iobase += 0x1000) {
3995 outb(0xff, (iobase + 0xc80));
3996 eid = inb(iobase + 0xc80);
3997 eid |= inb(iobase + 0xc81) << 8;
3998 if (eid != STL_EISAID)
4002 * We have found a board. Need to check if this board was
4003 * statically configured already (just in case!).
4005 for (i = 0; (i < STL_MAXBRDS); i++) {
4006 brdp = stli_brds[i];
4009 if (brdp->iobase == iobase)
4012 if (i < STL_MAXBRDS)
4016 * We have found a Stallion board and it is not configured already.
4017 * Allocate a board structure and initialize it.
4019 if ((brdp = stli_allocbrd()) == NULL)
4021 if ((brdp->brdnr = stli_getbrdnr()) < 0)
4023 eid = inb(iobase + 0xc82);
4024 if (eid == ECP_EISAID)
4025 brdp->brdtype = BRD_ECPE;
4026 else if (eid == ONB_EISAID)
4027 brdp->brdtype = BRD_ONBOARDE;
4029 brdp->brdtype = BRD_UNKNOWN;
4030 brdp->iobase = iobase;
4031 outb(0x1, (iobase + 0xc84));
4032 if (stli_eisamemprobe(brdp))
4033 outb(0, (iobase + 0xc84));
4040 /*****************************************************************************/
4043 * Find the next available board number that is free.
4046 /*****************************************************************************/
4051 * We have a Stallion board. Allocate a board structure and
4052 * initialize it. Read its IO and MEMORY resources from PCI
4053 * configuration space.
4056 static int stli_initpcibrd(int brdtype, struct pci_dev *devp)
4060 if (pci_enable_device(devp))
4062 if ((brdp = stli_allocbrd()) == NULL)
4064 if ((brdp->brdnr = stli_getbrdnr()) < 0) {
4065 printk(KERN_INFO "STALLION: too many boards found, "
4066 "maximum supported %d\n", STL_MAXBRDS);
4069 brdp->brdtype = brdtype;
4071 * We have all resources from the board, so lets setup the actual
4072 * board structure now.
4074 brdp->iobase = pci_resource_start(devp, 3);
4075 brdp->memaddr = pci_resource_start(devp, 2);
4081 /*****************************************************************************/
4084 * Find all Stallion PCI boards that might be installed. Initialize each
4085 * one as it is found.
4088 static int stli_findpcibrds(void)
4090 struct pci_dev *dev = NULL;
4092 while ((dev = pci_get_device(PCI_VENDOR_ID_STALLION, PCI_DEVICE_ID_ECRA, dev))) {
4093 stli_initpcibrd(BRD_ECPPCI, dev);
4100 /*****************************************************************************/
4103 * Allocate a new board structure. Fill out the basic info in it.
4106 static stlibrd_t *stli_allocbrd(void)
4110 brdp = kzalloc(sizeof(stlibrd_t), GFP_KERNEL);
4112 printk(KERN_ERR "STALLION: failed to allocate memory "
4113 "(size=%Zd)\n", sizeof(stlibrd_t));
4116 brdp->magic = STLI_BOARDMAGIC;
4120 /*****************************************************************************/
4123 * Scan through all the boards in the configuration and see what we
4127 static int stli_initbrds(void)
4129 stlibrd_t *brdp, *nxtbrdp;
4133 if (stli_nrbrds > STL_MAXBRDS) {
4134 printk(KERN_INFO "STALLION: too many boards in configuration "
4135 "table, truncating to %d\n", STL_MAXBRDS);
4136 stli_nrbrds = STL_MAXBRDS;
4140 * Firstly scan the list of static boards configured. Allocate
4141 * resources and initialize the boards as found. If this is a
4142 * module then let the module args override static configuration.
4144 for (i = 0; (i < stli_nrbrds); i++) {
4145 confp = &stli_brdconf[i];
4146 stli_parsebrd(confp, stli_brdsp[i]);
4147 if ((brdp = stli_allocbrd()) == NULL)
4150 brdp->brdtype = confp->brdtype;
4151 brdp->iobase = confp->ioaddr1;
4152 brdp->memaddr = confp->memaddr;
4157 * Static configuration table done, so now use dynamic methods to
4158 * see if any more boards should be configured.
4162 stli_findeisabrds();
4168 * All found boards are initialized. Now for a little optimization, if
4169 * no boards are sharing the "shared memory" regions then we can just
4170 * leave them all enabled. This is in fact the usual case.
4173 if (stli_nrbrds > 1) {
4174 for (i = 0; (i < stli_nrbrds); i++) {
4175 brdp = stli_brds[i];
4178 for (j = i + 1; (j < stli_nrbrds); j++) {
4179 nxtbrdp = stli_brds[j];
4180 if (nxtbrdp == NULL)
4182 if ((brdp->membase >= nxtbrdp->membase) &&
4183 (brdp->membase <= (nxtbrdp->membase +
4184 nxtbrdp->memsize - 1))) {
4192 if (stli_shared == 0) {
4193 for (i = 0; (i < stli_nrbrds); i++) {
4194 brdp = stli_brds[i];
4197 if (brdp->state & BST_FOUND) {
4199 brdp->enable = NULL;
4200 brdp->disable = NULL;
4208 /*****************************************************************************/
4211 * Code to handle an "staliomem" read operation. This device is the
4212 * contents of the board shared memory. It is used for down loading
4213 * the slave image (and debugging :-)
4216 static ssize_t stli_memread(struct file *fp, char __user *buf, size_t count, loff_t *offp)
4218 unsigned long flags;
4225 brdnr = iminor(fp->f_dentry->d_inode);
4226 if (brdnr >= stli_nrbrds)
4228 brdp = stli_brds[brdnr];
4231 if (brdp->state == 0)
4233 if (off >= brdp->memsize || off + count < off)
4236 size = MIN(count, (brdp->memsize - off));
4239 * Copy the data a page at a time
4242 p = (void *)__get_free_page(GFP_KERNEL);
4247 spin_lock_irqsave(&brd_lock, flags);
4249 memptr = (void *) EBRDGETMEMPTR(brdp, off);
4250 n = MIN(size, (brdp->pagesize - (((unsigned long) off) % brdp->pagesize)));
4251 n = MIN(n, PAGE_SIZE);
4252 memcpy_fromio(p, memptr, n);
4254 spin_unlock_irqrestore(&brd_lock, flags);
4255 if (copy_to_user(buf, p, n)) {
4265 free_page((unsigned long)p);
4269 /*****************************************************************************/
4272 * Code to handle an "staliomem" write operation. This device is the
4273 * contents of the board shared memory. It is used for down loading
4274 * the slave image (and debugging :-)
4276 * FIXME: copy under lock
4279 static ssize_t stli_memwrite(struct file *fp, const char __user *buf, size_t count, loff_t *offp)
4281 unsigned long flags;
4289 brdnr = iminor(fp->f_dentry->d_inode);
4291 if (brdnr >= stli_nrbrds)
4293 brdp = stli_brds[brdnr];
4296 if (brdp->state == 0)
4298 if (off >= brdp->memsize || off + count < off)
4301 chbuf = (char __user *) buf;
4302 size = MIN(count, (brdp->memsize - off));
4305 * Copy the data a page at a time
4308 p = (void *)__get_free_page(GFP_KERNEL);
4313 n = MIN(size, (brdp->pagesize - (((unsigned long) off) % brdp->pagesize)));
4314 n = MIN(n, PAGE_SIZE);
4315 if (copy_from_user(p, chbuf, n)) {
4320 spin_lock_irqsave(&brd_lock, flags);
4322 memptr = (void *) EBRDGETMEMPTR(brdp, off);
4323 memcpy_toio(memptr, p, n);
4325 spin_unlock_irqrestore(&brd_lock, flags);
4331 free_page((unsigned long) p);
4336 /*****************************************************************************/
4339 * Return the board stats structure to user app.
4342 static int stli_getbrdstats(combrd_t __user *bp)
4347 if (copy_from_user(&stli_brdstats, bp, sizeof(combrd_t)))
4349 if (stli_brdstats.brd >= STL_MAXBRDS)
4351 brdp = stli_brds[stli_brdstats.brd];
4355 memset(&stli_brdstats, 0, sizeof(combrd_t));
4356 stli_brdstats.brd = brdp->brdnr;
4357 stli_brdstats.type = brdp->brdtype;
4358 stli_brdstats.hwid = 0;
4359 stli_brdstats.state = brdp->state;
4360 stli_brdstats.ioaddr = brdp->iobase;
4361 stli_brdstats.memaddr = brdp->memaddr;
4362 stli_brdstats.nrpanels = brdp->nrpanels;
4363 stli_brdstats.nrports = brdp->nrports;
4364 for (i = 0; (i < brdp->nrpanels); i++) {
4365 stli_brdstats.panels[i].panel = i;
4366 stli_brdstats.panels[i].hwid = brdp->panelids[i];
4367 stli_brdstats.panels[i].nrports = brdp->panels[i];
4370 if (copy_to_user(bp, &stli_brdstats, sizeof(combrd_t)))
4375 /*****************************************************************************/
4378 * Resolve the referenced port number into a port struct pointer.
4381 static stliport_t *stli_getport(int brdnr, int panelnr, int portnr)
4386 if (brdnr < 0 || brdnr >= STL_MAXBRDS)
4388 brdp = stli_brds[brdnr];
4391 for (i = 0; (i < panelnr); i++)
4392 portnr += brdp->panels[i];
4393 if ((portnr < 0) || (portnr >= brdp->nrports))
4395 return brdp->ports[portnr];
4398 /*****************************************************************************/
4401 * Return the port stats structure to user app. A NULL port struct
4402 * pointer passed in means that we need to find out from the app
4403 * what port to get stats for (used through board control device).
4406 static int stli_portcmdstats(stliport_t *portp)
4408 unsigned long flags;
4412 memset(&stli_comstats, 0, sizeof(comstats_t));
4416 brdp = stli_brds[portp->brdnr];
4420 if (brdp->state & BST_STARTED) {
4421 if ((rc = stli_cmdwait(brdp, portp, A_GETSTATS,
4422 &stli_cdkstats, sizeof(asystats_t), 1)) < 0)
4425 memset(&stli_cdkstats, 0, sizeof(asystats_t));
4428 stli_comstats.brd = portp->brdnr;
4429 stli_comstats.panel = portp->panelnr;
4430 stli_comstats.port = portp->portnr;
4431 stli_comstats.state = portp->state;
4432 stli_comstats.flags = portp->flags;
4434 spin_lock_irqsave(&brd_lock, flags);
4435 if (portp->tty != NULL) {
4436 if (portp->tty->driver_data == portp) {
4437 stli_comstats.ttystate = portp->tty->flags;
4438 stli_comstats.rxbuffered = -1;
4439 if (portp->tty->termios != NULL) {
4440 stli_comstats.cflags = portp->tty->termios->c_cflag;
4441 stli_comstats.iflags = portp->tty->termios->c_iflag;
4442 stli_comstats.oflags = portp->tty->termios->c_oflag;
4443 stli_comstats.lflags = portp->tty->termios->c_lflag;
4447 spin_unlock_irqrestore(&brd_lock, flags);
4449 stli_comstats.txtotal = stli_cdkstats.txchars;
4450 stli_comstats.rxtotal = stli_cdkstats.rxchars + stli_cdkstats.ringover;
4451 stli_comstats.txbuffered = stli_cdkstats.txringq;
4452 stli_comstats.rxbuffered += stli_cdkstats.rxringq;
4453 stli_comstats.rxoverrun = stli_cdkstats.overruns;
4454 stli_comstats.rxparity = stli_cdkstats.parity;
4455 stli_comstats.rxframing = stli_cdkstats.framing;
4456 stli_comstats.rxlost = stli_cdkstats.ringover;
4457 stli_comstats.rxbreaks = stli_cdkstats.rxbreaks;
4458 stli_comstats.txbreaks = stli_cdkstats.txbreaks;
4459 stli_comstats.txxon = stli_cdkstats.txstart;
4460 stli_comstats.txxoff = stli_cdkstats.txstop;
4461 stli_comstats.rxxon = stli_cdkstats.rxstart;
4462 stli_comstats.rxxoff = stli_cdkstats.rxstop;
4463 stli_comstats.rxrtsoff = stli_cdkstats.rtscnt / 2;
4464 stli_comstats.rxrtson = stli_cdkstats.rtscnt - stli_comstats.rxrtsoff;
4465 stli_comstats.modem = stli_cdkstats.dcdcnt;
4466 stli_comstats.hwid = stli_cdkstats.hwid;
4467 stli_comstats.signals = stli_mktiocm(stli_cdkstats.signals);
4472 /*****************************************************************************/
4475 * Return the port stats structure to user app. A NULL port struct
4476 * pointer passed in means that we need to find out from the app
4477 * what port to get stats for (used through board control device).
4480 static int stli_getportstats(stliport_t *portp, comstats_t __user *cp)
4486 if (copy_from_user(&stli_comstats, cp, sizeof(comstats_t)))
4488 portp = stli_getport(stli_comstats.brd, stli_comstats.panel,
4489 stli_comstats.port);
4494 brdp = stli_brds[portp->brdnr];
4498 if ((rc = stli_portcmdstats(portp)) < 0)
4501 return copy_to_user(cp, &stli_comstats, sizeof(comstats_t)) ?
4505 /*****************************************************************************/
4508 * Clear the port stats structure. We also return it zeroed out...
4511 static int stli_clrportstats(stliport_t *portp, comstats_t __user *cp)
4517 if (copy_from_user(&stli_comstats, cp, sizeof(comstats_t)))
4519 portp = stli_getport(stli_comstats.brd, stli_comstats.panel,
4520 stli_comstats.port);
4525 brdp = stli_brds[portp->brdnr];
4529 if (brdp->state & BST_STARTED) {
4530 if ((rc = stli_cmdwait(brdp, portp, A_CLEARSTATS, NULL, 0, 0)) < 0)
4534 memset(&stli_comstats, 0, sizeof(comstats_t));
4535 stli_comstats.brd = portp->brdnr;
4536 stli_comstats.panel = portp->panelnr;
4537 stli_comstats.port = portp->portnr;
4539 if (copy_to_user(cp, &stli_comstats, sizeof(comstats_t)))
4544 /*****************************************************************************/
4547 * Return the entire driver ports structure to a user app.
4550 static int stli_getportstruct(stliport_t __user *arg)
4554 if (copy_from_user(&stli_dummyport, arg, sizeof(stliport_t)))
4556 portp = stli_getport(stli_dummyport.brdnr, stli_dummyport.panelnr,
4557 stli_dummyport.portnr);
4560 if (copy_to_user(arg, portp, sizeof(stliport_t)))
4565 /*****************************************************************************/
4568 * Return the entire driver board structure to a user app.
4571 static int stli_getbrdstruct(stlibrd_t __user *arg)
4575 if (copy_from_user(&stli_dummybrd, arg, sizeof(stlibrd_t)))
4577 if ((stli_dummybrd.brdnr < 0) || (stli_dummybrd.brdnr >= STL_MAXBRDS))
4579 brdp = stli_brds[stli_dummybrd.brdnr];
4582 if (copy_to_user(arg, brdp, sizeof(stlibrd_t)))
4587 /*****************************************************************************/
4590 * The "staliomem" device is also required to do some special operations on
4591 * the board. We need to be able to send an interrupt to the board,
4592 * reset it, and start/stop it.
4595 static int stli_memioctl(struct inode *ip, struct file *fp, unsigned int cmd, unsigned long arg)
4598 int brdnr, rc, done;
4599 void __user *argp = (void __user *)arg;
4602 * First up handle the board independent ioctls.
4608 case COM_GETPORTSTATS:
4609 rc = stli_getportstats(NULL, argp);
4612 case COM_CLRPORTSTATS:
4613 rc = stli_clrportstats(NULL, argp);
4616 case COM_GETBRDSTATS:
4617 rc = stli_getbrdstats(argp);
4621 rc = stli_getportstruct(argp);
4625 rc = stli_getbrdstruct(argp);
4634 * Now handle the board specific ioctls. These all depend on the
4635 * minor number of the device they were called from.
4638 if (brdnr >= STL_MAXBRDS)
4640 brdp = stli_brds[brdnr];
4643 if (brdp->state == 0)
4651 rc = stli_startbrd(brdp);
4654 brdp->state &= ~BST_STARTED;
4657 brdp->state &= ~BST_STARTED;
4659 if (stli_shared == 0) {
4660 if (brdp->reenable != NULL)
4661 (* brdp->reenable)(brdp);
4671 static struct tty_operations stli_ops = {
4673 .close = stli_close,
4674 .write = stli_write,
4675 .put_char = stli_putchar,
4676 .flush_chars = stli_flushchars,
4677 .write_room = stli_writeroom,
4678 .chars_in_buffer = stli_charsinbuffer,
4679 .ioctl = stli_ioctl,
4680 .set_termios = stli_settermios,
4681 .throttle = stli_throttle,
4682 .unthrottle = stli_unthrottle,
4684 .start = stli_start,
4685 .hangup = stli_hangup,
4686 .flush_buffer = stli_flushbuffer,
4687 .break_ctl = stli_breakctl,
4688 .wait_until_sent = stli_waituntilsent,
4689 .send_xchar = stli_sendxchar,
4690 .read_proc = stli_readproc,
4691 .tiocmget = stli_tiocmget,
4692 .tiocmset = stli_tiocmset,
4695 /*****************************************************************************/
4697 int __init stli_init(void)
4700 printk(KERN_INFO "%s: version %s\n", stli_drvtitle, stli_drvversion);
4702 spin_lock_init(&stli_lock);
4703 spin_lock_init(&brd_lock);
4707 stli_serial = alloc_tty_driver(STL_MAXBRDS * STL_MAXPORTS);
4712 * Allocate a temporary write buffer.
4714 stli_txcookbuf = kmalloc(STLI_TXBUFSIZE, GFP_KERNEL);
4715 if (!stli_txcookbuf)
4716 printk(KERN_ERR "STALLION: failed to allocate memory "
4717 "(size=%d)\n", STLI_TXBUFSIZE);
4720 * Set up a character driver for the shared memory region. We need this
4721 * to down load the slave code image. Also it is a useful debugging tool.
4723 if (register_chrdev(STL_SIOMEMMAJOR, "staliomem", &stli_fsiomem))
4724 printk(KERN_ERR "STALLION: failed to register serial memory "
4727 istallion_class = class_create(THIS_MODULE, "staliomem");
4728 for (i = 0; i < 4; i++)
4729 class_device_create(istallion_class, NULL,
4730 MKDEV(STL_SIOMEMMAJOR, i),
4731 NULL, "staliomem%d", i);
4734 * Set up the tty driver structure and register us as a driver.
4736 stli_serial->owner = THIS_MODULE;
4737 stli_serial->driver_name = stli_drvname;
4738 stli_serial->name = stli_serialname;
4739 stli_serial->major = STL_SERIALMAJOR;
4740 stli_serial->minor_start = 0;
4741 stli_serial->type = TTY_DRIVER_TYPE_SERIAL;
4742 stli_serial->subtype = SERIAL_TYPE_NORMAL;
4743 stli_serial->init_termios = stli_deftermios;
4744 stli_serial->flags = TTY_DRIVER_REAL_RAW;
4745 tty_set_operations(stli_serial, &stli_ops);
4747 if (tty_register_driver(stli_serial)) {
4748 put_tty_driver(stli_serial);
4749 printk(KERN_ERR "STALLION: failed to register serial driver\n");
4755 /*****************************************************************************/