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.
19 /*****************************************************************************/
21 #include <linux/module.h>
22 #include <linux/slab.h>
23 #include <linux/interrupt.h>
24 #include <linux/tty.h>
25 #include <linux/tty_flip.h>
26 #include <linux/serial.h>
27 #include <linux/cdk.h>
28 #include <linux/comstats.h>
29 #include <linux/istallion.h>
30 #include <linux/ioport.h>
31 #include <linux/delay.h>
32 #include <linux/init.h>
33 #include <linux/device.h>
34 #include <linux/wait.h>
35 #include <linux/eisa.h>
36 #include <linux/ctype.h>
39 #include <asm/uaccess.h>
41 #include <linux/pci.h>
43 /*****************************************************************************/
46 * Define different board types. Not all of the following board types
47 * are supported by this driver. But I will use the standard "assigned"
48 * board numbers. Currently supported boards are abbreviated as:
49 * ECP = EasyConnection 8/64, ONB = ONboard, BBY = Brumby and
53 #define BRD_STALLION 1
55 #define BRD_ONBOARD2 3
57 #define BRD_ONBOARDE 7
63 #define BRD_BRUMBY BRD_BRUMBY4
66 * Define a configuration structure to hold the board configuration.
67 * Need to set this up in the code (for now) with the boards that are
68 * to be configured into the system. This is what needs to be modified
69 * when adding/removing/modifying boards. Each line entry in the
70 * stli_brdconf[] array is a board. Each line contains io/irq/memory
71 * ranges for that board (as well as what type of board it is).
73 * { BRD_ECP, 0x2a0, 0, 0xcc000, 0, 0 },
74 * This line will configure an EasyConnection 8/64 at io address 2a0,
75 * and shared memory address of cc000. Multiple EasyConnection 8/64
76 * boards can share the same shared memory address space. No interrupt
77 * is required for this board type.
79 * { BRD_ECPE, 0x5000, 0, 0x80000000, 0, 0 },
80 * This line will configure an EasyConnection 8/64 EISA in slot 5 and
81 * shared memory address of 0x80000000 (2 GByte). Multiple
82 * EasyConnection 8/64 EISA boards can share the same shared memory
83 * address space. No interrupt is required for this board type.
85 * { BRD_ONBOARD, 0x240, 0, 0xd0000, 0, 0 },
86 * This line will configure an ONboard (ISA type) at io address 240,
87 * and shared memory address of d0000. Multiple ONboards can share
88 * the same shared memory address space. No interrupt required.
90 * { BRD_BRUMBY4, 0x360, 0, 0xc8000, 0, 0 },
91 * This line will configure a Brumby board (any number of ports!) at
92 * io address 360 and shared memory address of c8000. All Brumby boards
93 * configured into a system must have their own separate io and memory
94 * addresses. No interrupt is required.
96 * { BRD_STALLION, 0x330, 0, 0xd0000, 0, 0 },
97 * This line will configure an original Stallion board at io address 330
98 * and shared memory address d0000 (this would only be valid for a "V4.0"
99 * or Rev.O Stallion board). All Stallion boards configured into the
100 * system must have their own separate io and memory addresses. No
101 * interrupt is required.
108 unsigned long memaddr;
113 static unsigned int stli_nrbrds;
115 /* stli_lock must NOT be taken holding brd_lock */
116 static spinlock_t stli_lock; /* TTY logic lock */
117 static spinlock_t brd_lock; /* Board logic lock */
120 * There is some experimental EISA board detection code in this driver.
121 * By default it is disabled, but for those that want to try it out,
122 * then set the define below to be 1.
124 #define STLI_EISAPROBE 0
126 /*****************************************************************************/
129 * Define some important driver characteristics. Device major numbers
130 * allocated as per Linux Device Registry.
132 #ifndef STL_SIOMEMMAJOR
133 #define STL_SIOMEMMAJOR 28
135 #ifndef STL_SERIALMAJOR
136 #define STL_SERIALMAJOR 24
138 #ifndef STL_CALLOUTMAJOR
139 #define STL_CALLOUTMAJOR 25
142 /*****************************************************************************/
145 * Define our local driver identity first. Set up stuff to deal with
146 * all the local structures required by a serial tty driver.
148 static char *stli_drvtitle = "Stallion Intelligent Multiport Serial Driver";
149 static char *stli_drvname = "istallion";
150 static char *stli_drvversion = "5.6.0";
151 static char *stli_serialname = "ttyE";
153 static struct tty_driver *stli_serial;
156 #define STLI_TXBUFSIZE 4096
159 * Use a fast local buffer for cooked characters. Typically a whole
160 * bunch of cooked characters come in for a port, 1 at a time. So we
161 * save those up into a local buffer, then write out the whole lot
162 * with a large memcpy. Just use 1 buffer for all ports, since its
163 * use it is only need for short periods of time by each port.
165 static char *stli_txcookbuf;
166 static int stli_txcooksize;
167 static int stli_txcookrealsize;
168 static struct tty_struct *stli_txcooktty;
171 * Define a local default termios struct. All ports will be created
172 * with this termios initially. Basically all it defines is a raw port
173 * at 9600 baud, 8 data bits, no parity, 1 stop bit.
175 static struct ktermios stli_deftermios = {
176 .c_cflag = (B9600 | CS8 | CREAD | HUPCL | CLOCAL),
183 * Define global stats structures. Not used often, and can be
184 * re-used for each stats call.
186 static comstats_t stli_comstats;
187 static combrd_t stli_brdstats;
188 static struct asystats stli_cdkstats;
190 /*****************************************************************************/
192 static DEFINE_MUTEX(stli_brdslock);
193 static struct stlibrd *stli_brds[STL_MAXBRDS];
195 static int stli_shared;
198 * Per board state flags. Used with the state field of the board struct.
199 * Not really much here... All we need to do is keep track of whether
200 * the board has been detected, and whether it is actually running a slave
203 #define BST_FOUND 0x1
204 #define BST_STARTED 0x2
205 #define BST_PROBED 0x4
208 * Define the set of port state flags. These are marked for internal
209 * state purposes only, usually to do with the state of communications
210 * with the slave. Most of them need to be updated atomically, so always
211 * use the bit setting operations (unless protected by cli/sti).
213 #define ST_INITIALIZING 1
219 #define ST_DOFLUSHRX 7
220 #define ST_DOFLUSHTX 8
223 #define ST_GETSIGS 11
226 * Define an array of board names as printable strings. Handy for
227 * referencing boards when printing trace and stuff.
229 static char *stli_brdnames[] = {
262 /*****************************************************************************/
265 * Define some string labels for arguments passed from the module
266 * load line. These allow for easy board definitions, and easy
267 * modification of the io, memory and irq resoucres.
270 static char *board0[8];
271 static char *board1[8];
272 static char *board2[8];
273 static char *board3[8];
275 static char **stli_brdsp[] = {
283 * Define a set of common board names, and types. This is used to
284 * parse any module arguments.
287 static struct stlibrdtype {
291 { "stallion", BRD_STALLION },
292 { "1", BRD_STALLION },
293 { "brumby", BRD_BRUMBY },
294 { "brumby4", BRD_BRUMBY },
295 { "brumby/4", BRD_BRUMBY },
296 { "brumby-4", BRD_BRUMBY },
297 { "brumby8", BRD_BRUMBY },
298 { "brumby/8", BRD_BRUMBY },
299 { "brumby-8", BRD_BRUMBY },
300 { "brumby16", BRD_BRUMBY },
301 { "brumby/16", BRD_BRUMBY },
302 { "brumby-16", BRD_BRUMBY },
304 { "onboard2", BRD_ONBOARD2 },
305 { "onboard-2", BRD_ONBOARD2 },
306 { "onboard/2", BRD_ONBOARD2 },
307 { "onboard-mc", BRD_ONBOARD2 },
308 { "onboard/mc", BRD_ONBOARD2 },
309 { "onboard-mca", BRD_ONBOARD2 },
310 { "onboard/mca", BRD_ONBOARD2 },
311 { "3", BRD_ONBOARD2 },
312 { "onboard", BRD_ONBOARD },
313 { "onboardat", BRD_ONBOARD },
314 { "4", BRD_ONBOARD },
315 { "onboarde", BRD_ONBOARDE },
316 { "onboard-e", BRD_ONBOARDE },
317 { "onboard/e", BRD_ONBOARDE },
318 { "onboard-ei", BRD_ONBOARDE },
319 { "onboard/ei", BRD_ONBOARDE },
320 { "7", BRD_ONBOARDE },
322 { "ecpat", BRD_ECP },
323 { "ec8/64", BRD_ECP },
324 { "ec8/64-at", BRD_ECP },
325 { "ec8/64-isa", BRD_ECP },
327 { "ecpe", BRD_ECPE },
328 { "ecpei", BRD_ECPE },
329 { "ec8/64-e", BRD_ECPE },
330 { "ec8/64-ei", BRD_ECPE },
332 { "ecpmc", BRD_ECPMC },
333 { "ec8/64-mc", BRD_ECPMC },
334 { "ec8/64-mca", BRD_ECPMC },
336 { "ecppci", BRD_ECPPCI },
337 { "ec/ra", BRD_ECPPCI },
338 { "ec/ra-pc", BRD_ECPPCI },
339 { "ec/ra-pci", BRD_ECPPCI },
340 { "29", BRD_ECPPCI },
344 * Define the module agruments.
346 MODULE_AUTHOR("Greg Ungerer");
347 MODULE_DESCRIPTION("Stallion Intelligent Multiport Serial Driver");
348 MODULE_LICENSE("GPL");
351 module_param_array(board0, charp, NULL, 0);
352 MODULE_PARM_DESC(board0, "Board 0 config -> name[,ioaddr[,memaddr]");
353 module_param_array(board1, charp, NULL, 0);
354 MODULE_PARM_DESC(board1, "Board 1 config -> name[,ioaddr[,memaddr]");
355 module_param_array(board2, charp, NULL, 0);
356 MODULE_PARM_DESC(board2, "Board 2 config -> name[,ioaddr[,memaddr]");
357 module_param_array(board3, charp, NULL, 0);
358 MODULE_PARM_DESC(board3, "Board 3 config -> name[,ioaddr[,memaddr]");
360 #if STLI_EISAPROBE != 0
362 * Set up a default memory address table for EISA board probing.
363 * The default addresses are all bellow 1Mbyte, which has to be the
364 * case anyway. They should be safe, since we only read values from
365 * them, and interrupts are disabled while we do it. If the higher
366 * memory support is compiled in then we also try probing around
367 * the 1Gb, 2Gb and 3Gb areas as well...
369 static unsigned long stli_eisamemprobeaddrs[] = {
370 0xc0000, 0xd0000, 0xe0000, 0xf0000,
371 0x80000000, 0x80010000, 0x80020000, 0x80030000,
372 0x40000000, 0x40010000, 0x40020000, 0x40030000,
373 0xc0000000, 0xc0010000, 0xc0020000, 0xc0030000,
374 0xff000000, 0xff010000, 0xff020000, 0xff030000,
377 static int stli_eisamempsize = ARRAY_SIZE(stli_eisamemprobeaddrs);
381 * Define the Stallion PCI vendor and device IDs.
383 #ifndef PCI_DEVICE_ID_ECRA
384 #define PCI_DEVICE_ID_ECRA 0x0004
387 static struct pci_device_id istallion_pci_tbl[] = {
388 { PCI_DEVICE(PCI_VENDOR_ID_STALLION, PCI_DEVICE_ID_ECRA), },
391 MODULE_DEVICE_TABLE(pci, istallion_pci_tbl);
393 static struct pci_driver stli_pcidriver;
395 /*****************************************************************************/
398 * Hardware configuration info for ECP boards. These defines apply
399 * to the directly accessible io ports of the ECP. There is a set of
400 * defines for each ECP board type, ISA, EISA, MCA and PCI.
404 #define ECP_MEMSIZE (128 * 1024)
405 #define ECP_PCIMEMSIZE (256 * 1024)
407 #define ECP_ATPAGESIZE (4 * 1024)
408 #define ECP_MCPAGESIZE (4 * 1024)
409 #define ECP_EIPAGESIZE (64 * 1024)
410 #define ECP_PCIPAGESIZE (64 * 1024)
412 #define STL_EISAID 0x8c4e
415 * Important defines for the ISA class of ECP board.
418 #define ECP_ATCONFR 1
419 #define ECP_ATMEMAR 2
420 #define ECP_ATMEMPR 3
421 #define ECP_ATSTOP 0x1
422 #define ECP_ATINTENAB 0x10
423 #define ECP_ATENABLE 0x20
424 #define ECP_ATDISABLE 0x00
425 #define ECP_ATADDRMASK 0x3f000
426 #define ECP_ATADDRSHFT 12
429 * Important defines for the EISA class of ECP board.
432 #define ECP_EIMEMARL 1
433 #define ECP_EICONFR 2
434 #define ECP_EIMEMARH 3
435 #define ECP_EIENABLE 0x1
436 #define ECP_EIDISABLE 0x0
437 #define ECP_EISTOP 0x4
438 #define ECP_EIEDGE 0x00
439 #define ECP_EILEVEL 0x80
440 #define ECP_EIADDRMASKL 0x00ff0000
441 #define ECP_EIADDRSHFTL 16
442 #define ECP_EIADDRMASKH 0xff000000
443 #define ECP_EIADDRSHFTH 24
444 #define ECP_EIBRDENAB 0xc84
446 #define ECP_EISAID 0x4
449 * Important defines for the Micro-channel class of ECP board.
450 * (It has a lot in common with the ISA boards.)
453 #define ECP_MCCONFR 1
454 #define ECP_MCSTOP 0x20
455 #define ECP_MCENABLE 0x80
456 #define ECP_MCDISABLE 0x00
459 * Important defines for the PCI class of ECP board.
460 * (It has a lot in common with the other ECP boards.)
462 #define ECP_PCIIREG 0
463 #define ECP_PCICONFR 1
464 #define ECP_PCISTOP 0x01
467 * Hardware configuration info for ONboard and Brumby boards. These
468 * defines apply to the directly accessible io ports of these boards.
470 #define ONB_IOSIZE 16
471 #define ONB_MEMSIZE (64 * 1024)
472 #define ONB_ATPAGESIZE (64 * 1024)
473 #define ONB_MCPAGESIZE (64 * 1024)
474 #define ONB_EIMEMSIZE (128 * 1024)
475 #define ONB_EIPAGESIZE (64 * 1024)
478 * Important defines for the ISA class of ONboard board.
481 #define ONB_ATMEMAR 1
482 #define ONB_ATCONFR 2
483 #define ONB_ATSTOP 0x4
484 #define ONB_ATENABLE 0x01
485 #define ONB_ATDISABLE 0x00
486 #define ONB_ATADDRMASK 0xff0000
487 #define ONB_ATADDRSHFT 16
489 #define ONB_MEMENABLO 0
490 #define ONB_MEMENABHI 0x02
493 * Important defines for the EISA class of ONboard board.
496 #define ONB_EIMEMARL 1
497 #define ONB_EICONFR 2
498 #define ONB_EIMEMARH 3
499 #define ONB_EIENABLE 0x1
500 #define ONB_EIDISABLE 0x0
501 #define ONB_EISTOP 0x4
502 #define ONB_EIEDGE 0x00
503 #define ONB_EILEVEL 0x80
504 #define ONB_EIADDRMASKL 0x00ff0000
505 #define ONB_EIADDRSHFTL 16
506 #define ONB_EIADDRMASKH 0xff000000
507 #define ONB_EIADDRSHFTH 24
508 #define ONB_EIBRDENAB 0xc84
510 #define ONB_EISAID 0x1
513 * Important defines for the Brumby boards. They are pretty simple,
514 * there is not much that is programmably configurable.
516 #define BBY_IOSIZE 16
517 #define BBY_MEMSIZE (64 * 1024)
518 #define BBY_PAGESIZE (16 * 1024)
521 #define BBY_ATCONFR 1
522 #define BBY_ATSTOP 0x4
525 * Important defines for the Stallion boards. They are pretty simple,
526 * there is not much that is programmably configurable.
528 #define STAL_IOSIZE 16
529 #define STAL_MEMSIZE (64 * 1024)
530 #define STAL_PAGESIZE (64 * 1024)
533 * Define the set of status register values for EasyConnection panels.
534 * The signature will return with the status value for each panel. From
535 * this we can determine what is attached to the board - before we have
536 * actually down loaded any code to it.
538 #define ECH_PNLSTATUS 2
539 #define ECH_PNL16PORT 0x20
540 #define ECH_PNLIDMASK 0x07
541 #define ECH_PNLXPID 0x40
542 #define ECH_PNLINTRPEND 0x80
545 * Define some macros to do things to the board. Even those these boards
546 * are somewhat related there is often significantly different ways of
547 * doing some operation on it (like enable, paging, reset, etc). So each
548 * board class has a set of functions which do the commonly required
549 * operations. The macros below basically just call these functions,
550 * generally checking for a NULL function - which means that the board
551 * needs nothing done to it to achieve this operation!
553 #define EBRDINIT(brdp) \
554 if (brdp->init != NULL) \
557 #define EBRDENABLE(brdp) \
558 if (brdp->enable != NULL) \
559 (* brdp->enable)(brdp);
561 #define EBRDDISABLE(brdp) \
562 if (brdp->disable != NULL) \
563 (* brdp->disable)(brdp);
565 #define EBRDINTR(brdp) \
566 if (brdp->intr != NULL) \
567 (* brdp->intr)(brdp);
569 #define EBRDRESET(brdp) \
570 if (brdp->reset != NULL) \
571 (* brdp->reset)(brdp);
573 #define EBRDGETMEMPTR(brdp,offset) \
574 (* brdp->getmemptr)(brdp, offset, __LINE__)
577 * Define the maximal baud rate, and the default baud base for ports.
579 #define STL_MAXBAUD 460800
580 #define STL_BAUDBASE 115200
581 #define STL_CLOSEDELAY (5 * HZ / 10)
583 /*****************************************************************************/
586 * Define macros to extract a brd or port number from a minor number.
588 #define MINOR2BRD(min) (((min) & 0xc0) >> 6)
589 #define MINOR2PORT(min) ((min) & 0x3f)
591 /*****************************************************************************/
594 * Prototype all functions in this driver!
597 static int stli_parsebrd(struct stlconf *confp, char **argp);
598 static int stli_init(void);
599 static int stli_open(struct tty_struct *tty, struct file *filp);
600 static void stli_close(struct tty_struct *tty, struct file *filp);
601 static int stli_write(struct tty_struct *tty, const unsigned char *buf, int count);
602 static void stli_putchar(struct tty_struct *tty, unsigned char ch);
603 static void stli_flushchars(struct tty_struct *tty);
604 static int stli_writeroom(struct tty_struct *tty);
605 static int stli_charsinbuffer(struct tty_struct *tty);
606 static int stli_ioctl(struct tty_struct *tty, struct file *file, unsigned int cmd, unsigned long arg);
607 static void stli_settermios(struct tty_struct *tty, struct ktermios *old);
608 static void stli_throttle(struct tty_struct *tty);
609 static void stli_unthrottle(struct tty_struct *tty);
610 static void stli_stop(struct tty_struct *tty);
611 static void stli_start(struct tty_struct *tty);
612 static void stli_flushbuffer(struct tty_struct *tty);
613 static void stli_breakctl(struct tty_struct *tty, int state);
614 static void stli_waituntilsent(struct tty_struct *tty, int timeout);
615 static void stli_sendxchar(struct tty_struct *tty, char ch);
616 static void stli_hangup(struct tty_struct *tty);
617 static int stli_portinfo(struct stlibrd *brdp, struct stliport *portp, int portnr, char *pos);
619 static int stli_brdinit(struct stlibrd *brdp);
620 static int stli_startbrd(struct stlibrd *brdp);
621 static ssize_t stli_memread(struct file *fp, char __user *buf, size_t count, loff_t *offp);
622 static ssize_t stli_memwrite(struct file *fp, const char __user *buf, size_t count, loff_t *offp);
623 static int stli_memioctl(struct inode *ip, struct file *fp, unsigned int cmd, unsigned long arg);
624 static void stli_brdpoll(struct stlibrd *brdp, cdkhdr_t __iomem *hdrp);
625 static void stli_poll(unsigned long arg);
626 static int stli_hostcmd(struct stlibrd *brdp, struct stliport *portp);
627 static int stli_initopen(struct stlibrd *brdp, struct stliport *portp);
628 static int stli_rawopen(struct stlibrd *brdp, struct stliport *portp, unsigned long arg, int wait);
629 static int stli_rawclose(struct stlibrd *brdp, struct stliport *portp, unsigned long arg, int wait);
630 static int stli_waitcarrier(struct stlibrd *brdp, struct stliport *portp, struct file *filp);
631 static void stli_dohangup(struct work_struct *);
632 static int stli_setport(struct stliport *portp);
633 static int stli_cmdwait(struct stlibrd *brdp, struct stliport *portp, unsigned long cmd, void *arg, int size, int copyback);
634 static void stli_sendcmd(struct stlibrd *brdp, struct stliport *portp, unsigned long cmd, void *arg, int size, int copyback);
635 static void __stli_sendcmd(struct stlibrd *brdp, struct stliport *portp, unsigned long cmd, void *arg, int size, int copyback);
636 static void stli_dodelaycmd(struct stliport *portp, cdkctrl_t __iomem *cp);
637 static void stli_mkasyport(struct stliport *portp, asyport_t *pp, struct ktermios *tiosp);
638 static void stli_mkasysigs(asysigs_t *sp, int dtr, int rts);
639 static long stli_mktiocm(unsigned long sigvalue);
640 static void stli_read(struct stlibrd *brdp, struct stliport *portp);
641 static int stli_getserial(struct stliport *portp, struct serial_struct __user *sp);
642 static int stli_setserial(struct stliport *portp, struct serial_struct __user *sp);
643 static int stli_getbrdstats(combrd_t __user *bp);
644 static int stli_getportstats(struct stliport *portp, comstats_t __user *cp);
645 static int stli_portcmdstats(struct stliport *portp);
646 static int stli_clrportstats(struct stliport *portp, comstats_t __user *cp);
647 static int stli_getportstruct(struct stliport __user *arg);
648 static int stli_getbrdstruct(struct stlibrd __user *arg);
649 static struct stlibrd *stli_allocbrd(void);
651 static void stli_ecpinit(struct stlibrd *brdp);
652 static void stli_ecpenable(struct stlibrd *brdp);
653 static void stli_ecpdisable(struct stlibrd *brdp);
654 static void __iomem *stli_ecpgetmemptr(struct stlibrd *brdp, unsigned long offset, int line);
655 static void stli_ecpreset(struct stlibrd *brdp);
656 static void stli_ecpintr(struct stlibrd *brdp);
657 static void stli_ecpeiinit(struct stlibrd *brdp);
658 static void stli_ecpeienable(struct stlibrd *brdp);
659 static void stli_ecpeidisable(struct stlibrd *brdp);
660 static void __iomem *stli_ecpeigetmemptr(struct stlibrd *brdp, unsigned long offset, int line);
661 static void stli_ecpeireset(struct stlibrd *brdp);
662 static void stli_ecpmcenable(struct stlibrd *brdp);
663 static void stli_ecpmcdisable(struct stlibrd *brdp);
664 static void __iomem *stli_ecpmcgetmemptr(struct stlibrd *brdp, unsigned long offset, int line);
665 static void stli_ecpmcreset(struct stlibrd *brdp);
666 static void stli_ecppciinit(struct stlibrd *brdp);
667 static void __iomem *stli_ecppcigetmemptr(struct stlibrd *brdp, unsigned long offset, int line);
668 static void stli_ecppcireset(struct stlibrd *brdp);
670 static void stli_onbinit(struct stlibrd *brdp);
671 static void stli_onbenable(struct stlibrd *brdp);
672 static void stli_onbdisable(struct stlibrd *brdp);
673 static void __iomem *stli_onbgetmemptr(struct stlibrd *brdp, unsigned long offset, int line);
674 static void stli_onbreset(struct stlibrd *brdp);
675 static void stli_onbeinit(struct stlibrd *brdp);
676 static void stli_onbeenable(struct stlibrd *brdp);
677 static void stli_onbedisable(struct stlibrd *brdp);
678 static void __iomem *stli_onbegetmemptr(struct stlibrd *brdp, unsigned long offset, int line);
679 static void stli_onbereset(struct stlibrd *brdp);
680 static void stli_bbyinit(struct stlibrd *brdp);
681 static void __iomem *stli_bbygetmemptr(struct stlibrd *brdp, unsigned long offset, int line);
682 static void stli_bbyreset(struct stlibrd *brdp);
683 static void stli_stalinit(struct stlibrd *brdp);
684 static void __iomem *stli_stalgetmemptr(struct stlibrd *brdp, unsigned long offset, int line);
685 static void stli_stalreset(struct stlibrd *brdp);
687 static struct stliport *stli_getport(unsigned int brdnr, unsigned int panelnr, unsigned int portnr);
689 static int stli_initecp(struct stlibrd *brdp);
690 static int stli_initonb(struct stlibrd *brdp);
691 #if STLI_EISAPROBE != 0
692 static int stli_eisamemprobe(struct stlibrd *brdp);
694 static int stli_initports(struct stlibrd *brdp);
696 /*****************************************************************************/
699 * Define the driver info for a user level shared memory device. This
700 * device will work sort of like the /dev/kmem device - except that it
701 * will give access to the shared memory on the Stallion intelligent
702 * board. This is also a very useful debugging tool.
704 static const struct file_operations stli_fsiomem = {
705 .owner = THIS_MODULE,
706 .read = stli_memread,
707 .write = stli_memwrite,
708 .ioctl = stli_memioctl,
711 /*****************************************************************************/
714 * Define a timer_list entry for our poll routine. The slave board
715 * is polled every so often to see if anything needs doing. This is
716 * much cheaper on host cpu than using interrupts. It turns out to
717 * not increase character latency by much either...
719 static DEFINE_TIMER(stli_timerlist, stli_poll, 0, 0);
721 static int stli_timeron;
724 * Define the calculation for the timeout routine.
726 #define STLI_TIMEOUT (jiffies + 1)
728 /*****************************************************************************/
730 static struct class *istallion_class;
732 static void stli_cleanup_ports(struct stlibrd *brdp)
734 struct stliport *portp;
737 for (j = 0; j < STL_MAXPORTS; j++) {
738 portp = brdp->ports[j];
740 if (portp->tty != NULL)
741 tty_hangup(portp->tty);
748 * Loadable module initialization stuff.
751 static int __init istallion_module_init(void)
757 /*****************************************************************************/
759 static void __exit istallion_module_exit(void)
761 struct stlibrd *brdp;
765 printk(KERN_INFO "Unloading %s: version %s\n", stli_drvtitle,
768 pci_unregister_driver(&stli_pcidriver);
770 * Free up all allocated resources used by the ports. This includes
771 * memory and interrupts.
775 del_timer_sync(&stli_timerlist);
778 i = tty_unregister_driver(stli_serial);
780 printk("STALLION: failed to un-register tty driver, "
784 put_tty_driver(stli_serial);
785 for (j = 0; j < 4; j++)
786 class_device_destroy(istallion_class, MKDEV(STL_SIOMEMMAJOR, j));
787 class_destroy(istallion_class);
788 if ((i = unregister_chrdev(STL_SIOMEMMAJOR, "staliomem")))
789 printk("STALLION: failed to un-register serial memory device, "
792 kfree(stli_txcookbuf);
794 for (j = 0; (j < stli_nrbrds); j++) {
795 if ((brdp = stli_brds[j]) == NULL || (brdp->state & BST_PROBED))
798 stli_cleanup_ports(brdp);
800 iounmap(brdp->membase);
801 if (brdp->iosize > 0)
802 release_region(brdp->iobase, brdp->iosize);
808 module_init(istallion_module_init);
809 module_exit(istallion_module_exit);
811 /*****************************************************************************/
814 * Parse the supplied argument string, into the board conf struct.
817 static int stli_parsebrd(struct stlconf *confp, char **argp)
822 if (argp[0] == NULL || *argp[0] == 0)
825 for (sp = argp[0], i = 0; ((*sp != 0) && (i < 25)); sp++, i++)
828 for (i = 0; i < ARRAY_SIZE(stli_brdstr); i++) {
829 if (strcmp(stli_brdstr[i].name, argp[0]) == 0)
832 if (i == ARRAY_SIZE(stli_brdstr)) {
833 printk("STALLION: unknown board name, %s?\n", argp[0]);
837 confp->brdtype = stli_brdstr[i].type;
838 if (argp[1] != NULL && *argp[1] != 0)
839 confp->ioaddr1 = simple_strtoul(argp[1], NULL, 0);
840 if (argp[2] != NULL && *argp[2] != 0)
841 confp->memaddr = simple_strtoul(argp[2], NULL, 0);
845 /*****************************************************************************/
847 static int stli_open(struct tty_struct *tty, struct file *filp)
849 struct stlibrd *brdp;
850 struct stliport *portp;
851 unsigned int minordev, brdnr, portnr;
854 minordev = tty->index;
855 brdnr = MINOR2BRD(minordev);
856 if (brdnr >= stli_nrbrds)
858 brdp = stli_brds[brdnr];
861 if ((brdp->state & BST_STARTED) == 0)
863 portnr = MINOR2PORT(minordev);
864 if (portnr > brdp->nrports)
867 portp = brdp->ports[portnr];
870 if (portp->devnr < 1)
875 * Check if this port is in the middle of closing. If so then wait
876 * until it is closed then return error status based on flag settings.
877 * The sleep here does not need interrupt protection since the wakeup
878 * for it is done with the same context.
880 if (portp->flags & ASYNC_CLOSING) {
881 interruptible_sleep_on(&portp->close_wait);
882 if (portp->flags & ASYNC_HUP_NOTIFY)
888 * On the first open of the device setup the port hardware, and
889 * initialize the per port data structure. Since initializing the port
890 * requires several commands to the board we will need to wait for any
891 * other open that is already initializing the port.
894 tty->driver_data = portp;
897 wait_event_interruptible(portp->raw_wait,
898 !test_bit(ST_INITIALIZING, &portp->state));
899 if (signal_pending(current))
902 if ((portp->flags & ASYNC_INITIALIZED) == 0) {
903 set_bit(ST_INITIALIZING, &portp->state);
904 if ((rc = stli_initopen(brdp, portp)) >= 0) {
905 portp->flags |= ASYNC_INITIALIZED;
906 clear_bit(TTY_IO_ERROR, &tty->flags);
908 clear_bit(ST_INITIALIZING, &portp->state);
909 wake_up_interruptible(&portp->raw_wait);
915 * Check if this port is in the middle of closing. If so then wait
916 * until it is closed then return error status, based on flag settings.
917 * The sleep here does not need interrupt protection since the wakeup
918 * for it is done with the same context.
920 if (portp->flags & ASYNC_CLOSING) {
921 interruptible_sleep_on(&portp->close_wait);
922 if (portp->flags & ASYNC_HUP_NOTIFY)
928 * Based on type of open being done check if it can overlap with any
929 * previous opens still in effect. If we are a normal serial device
930 * then also we might have to wait for carrier.
932 if (!(filp->f_flags & O_NONBLOCK)) {
933 if ((rc = stli_waitcarrier(brdp, portp, filp)) != 0)
936 portp->flags |= ASYNC_NORMAL_ACTIVE;
940 /*****************************************************************************/
942 static void stli_close(struct tty_struct *tty, struct file *filp)
944 struct stlibrd *brdp;
945 struct stliport *portp;
948 portp = tty->driver_data;
952 spin_lock_irqsave(&stli_lock, flags);
953 if (tty_hung_up_p(filp)) {
954 spin_unlock_irqrestore(&stli_lock, flags);
957 if ((tty->count == 1) && (portp->refcount != 1))
959 if (portp->refcount-- > 1) {
960 spin_unlock_irqrestore(&stli_lock, flags);
964 portp->flags |= ASYNC_CLOSING;
967 * May want to wait for data to drain before closing. The BUSY flag
968 * keeps track of whether we are still transmitting or not. It is
969 * updated by messages from the slave - indicating when all chars
970 * really have drained.
972 if (tty == stli_txcooktty)
973 stli_flushchars(tty);
975 spin_unlock_irqrestore(&stli_lock, flags);
977 if (portp->closing_wait != ASYNC_CLOSING_WAIT_NONE)
978 tty_wait_until_sent(tty, portp->closing_wait);
980 portp->flags &= ~ASYNC_INITIALIZED;
981 brdp = stli_brds[portp->brdnr];
982 stli_rawclose(brdp, portp, 0, 0);
983 if (tty->termios->c_cflag & HUPCL) {
984 stli_mkasysigs(&portp->asig, 0, 0);
985 if (test_bit(ST_CMDING, &portp->state))
986 set_bit(ST_DOSIGS, &portp->state);
988 stli_sendcmd(brdp, portp, A_SETSIGNALS, &portp->asig,
989 sizeof(asysigs_t), 0);
991 clear_bit(ST_TXBUSY, &portp->state);
992 clear_bit(ST_RXSTOP, &portp->state);
993 set_bit(TTY_IO_ERROR, &tty->flags);
994 if (tty->ldisc.flush_buffer)
995 (tty->ldisc.flush_buffer)(tty);
996 set_bit(ST_DOFLUSHRX, &portp->state);
997 stli_flushbuffer(tty);
1002 if (portp->openwaitcnt) {
1003 if (portp->close_delay)
1004 msleep_interruptible(jiffies_to_msecs(portp->close_delay));
1005 wake_up_interruptible(&portp->open_wait);
1008 portp->flags &= ~(ASYNC_NORMAL_ACTIVE|ASYNC_CLOSING);
1009 wake_up_interruptible(&portp->close_wait);
1012 /*****************************************************************************/
1015 * Carry out first open operations on a port. This involves a number of
1016 * commands to be sent to the slave. We need to open the port, set the
1017 * notification events, set the initial port settings, get and set the
1018 * initial signal values. We sleep and wait in between each one. But
1019 * this still all happens pretty quickly.
1022 static int stli_initopen(struct stlibrd *brdp, struct stliport *portp)
1024 struct tty_struct *tty;
1029 if ((rc = stli_rawopen(brdp, portp, 0, 1)) < 0)
1032 memset(&nt, 0, sizeof(asynotify_t));
1033 nt.data = (DT_TXLOW | DT_TXEMPTY | DT_RXBUSY | DT_RXBREAK);
1035 if ((rc = stli_cmdwait(brdp, portp, A_SETNOTIFY, &nt,
1036 sizeof(asynotify_t), 0)) < 0)
1042 stli_mkasyport(portp, &aport, tty->termios);
1043 if ((rc = stli_cmdwait(brdp, portp, A_SETPORT, &aport,
1044 sizeof(asyport_t), 0)) < 0)
1047 set_bit(ST_GETSIGS, &portp->state);
1048 if ((rc = stli_cmdwait(brdp, portp, A_GETSIGNALS, &portp->asig,
1049 sizeof(asysigs_t), 1)) < 0)
1051 if (test_and_clear_bit(ST_GETSIGS, &portp->state))
1052 portp->sigs = stli_mktiocm(portp->asig.sigvalue);
1053 stli_mkasysigs(&portp->asig, 1, 1);
1054 if ((rc = stli_cmdwait(brdp, portp, A_SETSIGNALS, &portp->asig,
1055 sizeof(asysigs_t), 0)) < 0)
1061 /*****************************************************************************/
1064 * Send an open message to the slave. This will sleep waiting for the
1065 * acknowledgement, so must have user context. We need to co-ordinate
1066 * with close events here, since we don't want open and close events
1070 static int stli_rawopen(struct stlibrd *brdp, struct stliport *portp, unsigned long arg, int wait)
1072 cdkhdr_t __iomem *hdrp;
1073 cdkctrl_t __iomem *cp;
1074 unsigned char __iomem *bits;
1075 unsigned long flags;
1079 * Send a message to the slave to open this port.
1083 * Slave is already closing this port. This can happen if a hangup
1084 * occurs on this port. So we must wait until it is complete. The
1085 * order of opens and closes may not be preserved across shared
1086 * memory, so we must wait until it is complete.
1088 wait_event_interruptible(portp->raw_wait,
1089 !test_bit(ST_CLOSING, &portp->state));
1090 if (signal_pending(current)) {
1091 return -ERESTARTSYS;
1095 * Everything is ready now, so write the open message into shared
1096 * memory. Once the message is in set the service bits to say that
1097 * this port wants service.
1099 spin_lock_irqsave(&brd_lock, flags);
1101 cp = &((cdkasy_t __iomem *) EBRDGETMEMPTR(brdp, portp->addr))->ctrl;
1102 writel(arg, &cp->openarg);
1103 writeb(1, &cp->open);
1104 hdrp = (cdkhdr_t __iomem *) EBRDGETMEMPTR(brdp, CDK_CDKADDR);
1105 bits = ((unsigned char __iomem *) hdrp) + brdp->slaveoffset +
1107 writeb(readb(bits) | portp->portbit, bits);
1111 spin_unlock_irqrestore(&brd_lock, flags);
1116 * Slave is in action, so now we must wait for the open acknowledgment
1120 set_bit(ST_OPENING, &portp->state);
1121 spin_unlock_irqrestore(&brd_lock, flags);
1123 wait_event_interruptible(portp->raw_wait,
1124 !test_bit(ST_OPENING, &portp->state));
1125 if (signal_pending(current))
1128 if ((rc == 0) && (portp->rc != 0))
1133 /*****************************************************************************/
1136 * Send a close message to the slave. Normally this will sleep waiting
1137 * for the acknowledgement, but if wait parameter is 0 it will not. If
1138 * wait is true then must have user context (to sleep).
1141 static int stli_rawclose(struct stlibrd *brdp, struct stliport *portp, unsigned long arg, int wait)
1143 cdkhdr_t __iomem *hdrp;
1144 cdkctrl_t __iomem *cp;
1145 unsigned char __iomem *bits;
1146 unsigned long flags;
1150 * Slave is already closing this port. This can happen if a hangup
1151 * occurs on this port.
1154 wait_event_interruptible(portp->raw_wait,
1155 !test_bit(ST_CLOSING, &portp->state));
1156 if (signal_pending(current)) {
1157 return -ERESTARTSYS;
1162 * Write the close command into shared memory.
1164 spin_lock_irqsave(&brd_lock, flags);
1166 cp = &((cdkasy_t __iomem *) EBRDGETMEMPTR(brdp, portp->addr))->ctrl;
1167 writel(arg, &cp->closearg);
1168 writeb(1, &cp->close);
1169 hdrp = (cdkhdr_t __iomem *) EBRDGETMEMPTR(brdp, CDK_CDKADDR);
1170 bits = ((unsigned char __iomem *) hdrp) + brdp->slaveoffset +
1172 writeb(readb(bits) |portp->portbit, bits);
1175 set_bit(ST_CLOSING, &portp->state);
1176 spin_unlock_irqrestore(&brd_lock, flags);
1182 * Slave is in action, so now we must wait for the open acknowledgment
1186 wait_event_interruptible(portp->raw_wait,
1187 !test_bit(ST_CLOSING, &portp->state));
1188 if (signal_pending(current))
1191 if ((rc == 0) && (portp->rc != 0))
1196 /*****************************************************************************/
1199 * Send a command to the slave and wait for the response. This must
1200 * have user context (it sleeps). This routine is generic in that it
1201 * can send any type of command. Its purpose is to wait for that command
1202 * to complete (as opposed to initiating the command then returning).
1205 static int stli_cmdwait(struct stlibrd *brdp, struct stliport *portp, unsigned long cmd, void *arg, int size, int copyback)
1207 wait_event_interruptible(portp->raw_wait,
1208 !test_bit(ST_CMDING, &portp->state));
1209 if (signal_pending(current))
1210 return -ERESTARTSYS;
1212 stli_sendcmd(brdp, portp, cmd, arg, size, copyback);
1214 wait_event_interruptible(portp->raw_wait,
1215 !test_bit(ST_CMDING, &portp->state));
1216 if (signal_pending(current))
1217 return -ERESTARTSYS;
1224 /*****************************************************************************/
1227 * Send the termios settings for this port to the slave. This sleeps
1228 * waiting for the command to complete - so must have user context.
1231 static int stli_setport(struct stliport *portp)
1233 struct stlibrd *brdp;
1238 if (portp->tty == NULL)
1240 if (portp->brdnr >= stli_nrbrds)
1242 brdp = stli_brds[portp->brdnr];
1246 stli_mkasyport(portp, &aport, portp->tty->termios);
1247 return(stli_cmdwait(brdp, portp, A_SETPORT, &aport, sizeof(asyport_t), 0));
1250 /*****************************************************************************/
1253 * Possibly need to wait for carrier (DCD signal) to come high. Say
1254 * maybe because if we are clocal then we don't need to wait...
1257 static int stli_waitcarrier(struct stlibrd *brdp, struct stliport *portp, struct file *filp)
1259 unsigned long flags;
1265 if (portp->tty->termios->c_cflag & CLOCAL)
1268 spin_lock_irqsave(&stli_lock, flags);
1269 portp->openwaitcnt++;
1270 if (! tty_hung_up_p(filp))
1272 spin_unlock_irqrestore(&stli_lock, flags);
1275 stli_mkasysigs(&portp->asig, 1, 1);
1276 if ((rc = stli_cmdwait(brdp, portp, A_SETSIGNALS,
1277 &portp->asig, sizeof(asysigs_t), 0)) < 0)
1279 if (tty_hung_up_p(filp) ||
1280 ((portp->flags & ASYNC_INITIALIZED) == 0)) {
1281 if (portp->flags & ASYNC_HUP_NOTIFY)
1287 if (((portp->flags & ASYNC_CLOSING) == 0) &&
1288 (doclocal || (portp->sigs & TIOCM_CD))) {
1291 if (signal_pending(current)) {
1295 interruptible_sleep_on(&portp->open_wait);
1298 spin_lock_irqsave(&stli_lock, flags);
1299 if (! tty_hung_up_p(filp))
1301 portp->openwaitcnt--;
1302 spin_unlock_irqrestore(&stli_lock, flags);
1307 /*****************************************************************************/
1310 * Write routine. Take the data and put it in the shared memory ring
1311 * queue. If port is not already sending chars then need to mark the
1312 * service bits for this port.
1315 static int stli_write(struct tty_struct *tty, const unsigned char *buf, int count)
1317 cdkasy_t __iomem *ap;
1318 cdkhdr_t __iomem *hdrp;
1319 unsigned char __iomem *bits;
1320 unsigned char __iomem *shbuf;
1321 unsigned char *chbuf;
1322 struct stliport *portp;
1323 struct stlibrd *brdp;
1324 unsigned int len, stlen, head, tail, size;
1325 unsigned long flags;
1327 if (tty == stli_txcooktty)
1328 stli_flushchars(tty);
1329 portp = tty->driver_data;
1332 if (portp->brdnr >= stli_nrbrds)
1334 brdp = stli_brds[portp->brdnr];
1337 chbuf = (unsigned char *) buf;
1340 * All data is now local, shove as much as possible into shared memory.
1342 spin_lock_irqsave(&brd_lock, flags);
1344 ap = (cdkasy_t __iomem *) EBRDGETMEMPTR(brdp, portp->addr);
1345 head = (unsigned int) readw(&ap->txq.head);
1346 tail = (unsigned int) readw(&ap->txq.tail);
1347 if (tail != ((unsigned int) readw(&ap->txq.tail)))
1348 tail = (unsigned int) readw(&ap->txq.tail);
1349 size = portp->txsize;
1351 len = size - (head - tail) - 1;
1352 stlen = size - head;
1354 len = tail - head - 1;
1358 len = min(len, (unsigned int)count);
1360 shbuf = (char __iomem *) EBRDGETMEMPTR(brdp, portp->txoffset);
1363 stlen = min(len, stlen);
1364 memcpy_toio(shbuf + head, chbuf, stlen);
1375 ap = (cdkasy_t __iomem *) EBRDGETMEMPTR(brdp, portp->addr);
1376 writew(head, &ap->txq.head);
1377 if (test_bit(ST_TXBUSY, &portp->state)) {
1378 if (readl(&ap->changed.data) & DT_TXEMPTY)
1379 writel(readl(&ap->changed.data) & ~DT_TXEMPTY, &ap->changed.data);
1381 hdrp = (cdkhdr_t __iomem *) EBRDGETMEMPTR(brdp, CDK_CDKADDR);
1382 bits = ((unsigned char __iomem *) hdrp) + brdp->slaveoffset +
1384 writeb(readb(bits) | portp->portbit, bits);
1385 set_bit(ST_TXBUSY, &portp->state);
1387 spin_unlock_irqrestore(&brd_lock, flags);
1392 /*****************************************************************************/
1395 * Output a single character. We put it into a temporary local buffer
1396 * (for speed) then write out that buffer when the flushchars routine
1397 * is called. There is a safety catch here so that if some other port
1398 * writes chars before the current buffer has been, then we write them
1399 * first them do the new ports.
1402 static void stli_putchar(struct tty_struct *tty, unsigned char ch)
1404 if (tty != stli_txcooktty) {
1405 if (stli_txcooktty != NULL)
1406 stli_flushchars(stli_txcooktty);
1407 stli_txcooktty = tty;
1410 stli_txcookbuf[stli_txcooksize++] = ch;
1413 /*****************************************************************************/
1416 * Transfer characters from the local TX cooking buffer to the board.
1417 * We sort of ignore the tty that gets passed in here. We rely on the
1418 * info stored with the TX cook buffer to tell us which port to flush
1419 * the data on. In any case we clean out the TX cook buffer, for re-use
1423 static void stli_flushchars(struct tty_struct *tty)
1425 cdkhdr_t __iomem *hdrp;
1426 unsigned char __iomem *bits;
1427 cdkasy_t __iomem *ap;
1428 struct tty_struct *cooktty;
1429 struct stliport *portp;
1430 struct stlibrd *brdp;
1431 unsigned int len, stlen, head, tail, size, count, cooksize;
1433 unsigned char __iomem *shbuf;
1434 unsigned long flags;
1436 cooksize = stli_txcooksize;
1437 cooktty = stli_txcooktty;
1438 stli_txcooksize = 0;
1439 stli_txcookrealsize = 0;
1440 stli_txcooktty = NULL;
1444 if (cooktty == NULL)
1451 portp = tty->driver_data;
1454 if (portp->brdnr >= stli_nrbrds)
1456 brdp = stli_brds[portp->brdnr];
1460 spin_lock_irqsave(&brd_lock, flags);
1463 ap = (cdkasy_t __iomem *) EBRDGETMEMPTR(brdp, portp->addr);
1464 head = (unsigned int) readw(&ap->txq.head);
1465 tail = (unsigned int) readw(&ap->txq.tail);
1466 if (tail != ((unsigned int) readw(&ap->txq.tail)))
1467 tail = (unsigned int) readw(&ap->txq.tail);
1468 size = portp->txsize;
1470 len = size - (head - tail) - 1;
1471 stlen = size - head;
1473 len = tail - head - 1;
1477 len = min(len, cooksize);
1479 shbuf = EBRDGETMEMPTR(brdp, portp->txoffset);
1480 buf = stli_txcookbuf;
1483 stlen = min(len, stlen);
1484 memcpy_toio(shbuf + head, buf, stlen);
1495 ap = (cdkasy_t __iomem *) EBRDGETMEMPTR(brdp, portp->addr);
1496 writew(head, &ap->txq.head);
1498 if (test_bit(ST_TXBUSY, &portp->state)) {
1499 if (readl(&ap->changed.data) & DT_TXEMPTY)
1500 writel(readl(&ap->changed.data) & ~DT_TXEMPTY, &ap->changed.data);
1502 hdrp = (cdkhdr_t __iomem *) EBRDGETMEMPTR(brdp, CDK_CDKADDR);
1503 bits = ((unsigned char __iomem *) hdrp) + brdp->slaveoffset +
1505 writeb(readb(bits) | portp->portbit, bits);
1506 set_bit(ST_TXBUSY, &portp->state);
1509 spin_unlock_irqrestore(&brd_lock, flags);
1512 /*****************************************************************************/
1514 static int stli_writeroom(struct tty_struct *tty)
1516 cdkasyrq_t __iomem *rp;
1517 struct stliport *portp;
1518 struct stlibrd *brdp;
1519 unsigned int head, tail, len;
1520 unsigned long flags;
1522 if (tty == stli_txcooktty) {
1523 if (stli_txcookrealsize != 0) {
1524 len = stli_txcookrealsize - stli_txcooksize;
1529 portp = tty->driver_data;
1532 if (portp->brdnr >= stli_nrbrds)
1534 brdp = stli_brds[portp->brdnr];
1538 spin_lock_irqsave(&brd_lock, flags);
1540 rp = &((cdkasy_t __iomem *) EBRDGETMEMPTR(brdp, portp->addr))->txq;
1541 head = (unsigned int) readw(&rp->head);
1542 tail = (unsigned int) readw(&rp->tail);
1543 if (tail != ((unsigned int) readw(&rp->tail)))
1544 tail = (unsigned int) readw(&rp->tail);
1545 len = (head >= tail) ? (portp->txsize - (head - tail)) : (tail - head);
1548 spin_unlock_irqrestore(&brd_lock, flags);
1550 if (tty == stli_txcooktty) {
1551 stli_txcookrealsize = len;
1552 len -= stli_txcooksize;
1557 /*****************************************************************************/
1560 * Return the number of characters in the transmit buffer. Normally we
1561 * will return the number of chars in the shared memory ring queue.
1562 * We need to kludge around the case where the shared memory buffer is
1563 * empty but not all characters have drained yet, for this case just
1564 * return that there is 1 character in the buffer!
1567 static int stli_charsinbuffer(struct tty_struct *tty)
1569 cdkasyrq_t __iomem *rp;
1570 struct stliport *portp;
1571 struct stlibrd *brdp;
1572 unsigned int head, tail, len;
1573 unsigned long flags;
1575 if (tty == stli_txcooktty)
1576 stli_flushchars(tty);
1577 portp = tty->driver_data;
1580 if (portp->brdnr >= stli_nrbrds)
1582 brdp = stli_brds[portp->brdnr];
1586 spin_lock_irqsave(&brd_lock, flags);
1588 rp = &((cdkasy_t __iomem *) EBRDGETMEMPTR(brdp, portp->addr))->txq;
1589 head = (unsigned int) readw(&rp->head);
1590 tail = (unsigned int) readw(&rp->tail);
1591 if (tail != ((unsigned int) readw(&rp->tail)))
1592 tail = (unsigned int) readw(&rp->tail);
1593 len = (head >= tail) ? (head - tail) : (portp->txsize - (tail - head));
1594 if ((len == 0) && test_bit(ST_TXBUSY, &portp->state))
1597 spin_unlock_irqrestore(&brd_lock, flags);
1602 /*****************************************************************************/
1605 * Generate the serial struct info.
1608 static int stli_getserial(struct stliport *portp, struct serial_struct __user *sp)
1610 struct serial_struct sio;
1611 struct stlibrd *brdp;
1613 memset(&sio, 0, sizeof(struct serial_struct));
1614 sio.type = PORT_UNKNOWN;
1615 sio.line = portp->portnr;
1617 sio.flags = portp->flags;
1618 sio.baud_base = portp->baud_base;
1619 sio.close_delay = portp->close_delay;
1620 sio.closing_wait = portp->closing_wait;
1621 sio.custom_divisor = portp->custom_divisor;
1622 sio.xmit_fifo_size = 0;
1625 brdp = stli_brds[portp->brdnr];
1627 sio.port = brdp->iobase;
1629 return copy_to_user(sp, &sio, sizeof(struct serial_struct)) ?
1633 /*****************************************************************************/
1636 * Set port according to the serial struct info.
1637 * At this point we do not do any auto-configure stuff, so we will
1638 * just quietly ignore any requests to change irq, etc.
1641 static int stli_setserial(struct stliport *portp, struct serial_struct __user *sp)
1643 struct serial_struct sio;
1646 if (copy_from_user(&sio, sp, sizeof(struct serial_struct)))
1648 if (!capable(CAP_SYS_ADMIN)) {
1649 if ((sio.baud_base != portp->baud_base) ||
1650 (sio.close_delay != portp->close_delay) ||
1651 ((sio.flags & ~ASYNC_USR_MASK) !=
1652 (portp->flags & ~ASYNC_USR_MASK)))
1656 portp->flags = (portp->flags & ~ASYNC_USR_MASK) |
1657 (sio.flags & ASYNC_USR_MASK);
1658 portp->baud_base = sio.baud_base;
1659 portp->close_delay = sio.close_delay;
1660 portp->closing_wait = sio.closing_wait;
1661 portp->custom_divisor = sio.custom_divisor;
1663 if ((rc = stli_setport(portp)) < 0)
1668 /*****************************************************************************/
1670 static int stli_tiocmget(struct tty_struct *tty, struct file *file)
1672 struct stliport *portp = tty->driver_data;
1673 struct stlibrd *brdp;
1678 if (portp->brdnr >= stli_nrbrds)
1680 brdp = stli_brds[portp->brdnr];
1683 if (tty->flags & (1 << TTY_IO_ERROR))
1686 if ((rc = stli_cmdwait(brdp, portp, A_GETSIGNALS,
1687 &portp->asig, sizeof(asysigs_t), 1)) < 0)
1690 return stli_mktiocm(portp->asig.sigvalue);
1693 static int stli_tiocmset(struct tty_struct *tty, struct file *file,
1694 unsigned int set, unsigned int clear)
1696 struct stliport *portp = tty->driver_data;
1697 struct stlibrd *brdp;
1698 int rts = -1, dtr = -1;
1702 if (portp->brdnr >= stli_nrbrds)
1704 brdp = stli_brds[portp->brdnr];
1707 if (tty->flags & (1 << TTY_IO_ERROR))
1710 if (set & TIOCM_RTS)
1712 if (set & TIOCM_DTR)
1714 if (clear & TIOCM_RTS)
1716 if (clear & TIOCM_DTR)
1719 stli_mkasysigs(&portp->asig, dtr, rts);
1721 return stli_cmdwait(brdp, portp, A_SETSIGNALS, &portp->asig,
1722 sizeof(asysigs_t), 0);
1725 static int stli_ioctl(struct tty_struct *tty, struct file *file, unsigned int cmd, unsigned long arg)
1727 struct stliport *portp;
1728 struct stlibrd *brdp;
1731 void __user *argp = (void __user *)arg;
1733 portp = tty->driver_data;
1736 if (portp->brdnr >= stli_nrbrds)
1738 brdp = stli_brds[portp->brdnr];
1742 if ((cmd != TIOCGSERIAL) && (cmd != TIOCSSERIAL) &&
1743 (cmd != COM_GETPORTSTATS) && (cmd != COM_CLRPORTSTATS)) {
1744 if (tty->flags & (1 << TTY_IO_ERROR))
1752 rc = put_user(((tty->termios->c_cflag & CLOCAL) ? 1 : 0),
1753 (unsigned __user *) arg);
1756 if ((rc = get_user(ival, (unsigned __user *) arg)) == 0)
1757 tty->termios->c_cflag =
1758 (tty->termios->c_cflag & ~CLOCAL) |
1759 (ival ? CLOCAL : 0);
1762 rc = stli_getserial(portp, argp);
1765 rc = stli_setserial(portp, argp);
1768 rc = put_user(portp->pflag, (unsigned __user *)argp);
1771 if ((rc = get_user(portp->pflag, (unsigned __user *)argp)) == 0)
1772 stli_setport(portp);
1774 case COM_GETPORTSTATS:
1775 rc = stli_getportstats(portp, argp);
1777 case COM_CLRPORTSTATS:
1778 rc = stli_clrportstats(portp, argp);
1784 case TIOCSERGSTRUCT:
1785 case TIOCSERGETMULTI:
1786 case TIOCSERSETMULTI:
1795 /*****************************************************************************/
1798 * This routine assumes that we have user context and can sleep.
1799 * Looks like it is true for the current ttys implementation..!!
1802 static void stli_settermios(struct tty_struct *tty, struct ktermios *old)
1804 struct stliport *portp;
1805 struct stlibrd *brdp;
1806 struct ktermios *tiosp;
1811 portp = tty->driver_data;
1814 if (portp->brdnr >= stli_nrbrds)
1816 brdp = stli_brds[portp->brdnr];
1820 tiosp = tty->termios;
1821 if ((tiosp->c_cflag == old->c_cflag) &&
1822 (tiosp->c_iflag == old->c_iflag))
1825 stli_mkasyport(portp, &aport, tiosp);
1826 stli_cmdwait(brdp, portp, A_SETPORT, &aport, sizeof(asyport_t), 0);
1827 stli_mkasysigs(&portp->asig, ((tiosp->c_cflag & CBAUD) ? 1 : 0), -1);
1828 stli_cmdwait(brdp, portp, A_SETSIGNALS, &portp->asig,
1829 sizeof(asysigs_t), 0);
1830 if ((old->c_cflag & CRTSCTS) && ((tiosp->c_cflag & CRTSCTS) == 0))
1831 tty->hw_stopped = 0;
1832 if (((old->c_cflag & CLOCAL) == 0) && (tiosp->c_cflag & CLOCAL))
1833 wake_up_interruptible(&portp->open_wait);
1836 /*****************************************************************************/
1839 * Attempt to flow control who ever is sending us data. We won't really
1840 * do any flow control action here. We can't directly, and even if we
1841 * wanted to we would have to send a command to the slave. The slave
1842 * knows how to flow control, and will do so when its buffers reach its
1843 * internal high water marks. So what we will do is set a local state
1844 * bit that will stop us sending any RX data up from the poll routine
1845 * (which is the place where RX data from the slave is handled).
1848 static void stli_throttle(struct tty_struct *tty)
1850 struct stliport *portp = tty->driver_data;
1853 set_bit(ST_RXSTOP, &portp->state);
1856 /*****************************************************************************/
1859 * Unflow control the device sending us data... That means that all
1860 * we have to do is clear the RXSTOP state bit. The next poll call
1861 * will then be able to pass the RX data back up.
1864 static void stli_unthrottle(struct tty_struct *tty)
1866 struct stliport *portp = tty->driver_data;
1869 clear_bit(ST_RXSTOP, &portp->state);
1872 /*****************************************************************************/
1875 * Stop the transmitter.
1878 static void stli_stop(struct tty_struct *tty)
1882 /*****************************************************************************/
1885 * Start the transmitter again.
1888 static void stli_start(struct tty_struct *tty)
1892 /*****************************************************************************/
1895 * Scheduler called hang up routine. This is called from the scheduler,
1896 * not direct from the driver "poll" routine. We can't call it there
1897 * since the real local hangup code will enable/disable the board and
1898 * other things that we can't do while handling the poll. Much easier
1899 * to deal with it some time later (don't really care when, hangups
1900 * aren't that time critical).
1903 static void stli_dohangup(struct work_struct *ugly_api)
1905 struct stliport *portp = container_of(ugly_api, struct stliport, tqhangup);
1906 if (portp->tty != NULL) {
1907 tty_hangup(portp->tty);
1911 /*****************************************************************************/
1914 * Hangup this port. This is pretty much like closing the port, only
1915 * a little more brutal. No waiting for data to drain. Shutdown the
1916 * port and maybe drop signals. This is rather tricky really. We want
1917 * to close the port as well.
1920 static void stli_hangup(struct tty_struct *tty)
1922 struct stliport *portp;
1923 struct stlibrd *brdp;
1924 unsigned long flags;
1926 portp = tty->driver_data;
1929 if (portp->brdnr >= stli_nrbrds)
1931 brdp = stli_brds[portp->brdnr];
1935 portp->flags &= ~ASYNC_INITIALIZED;
1937 if (!test_bit(ST_CLOSING, &portp->state))
1938 stli_rawclose(brdp, portp, 0, 0);
1940 spin_lock_irqsave(&stli_lock, flags);
1941 if (tty->termios->c_cflag & HUPCL) {
1942 stli_mkasysigs(&portp->asig, 0, 0);
1943 if (test_bit(ST_CMDING, &portp->state)) {
1944 set_bit(ST_DOSIGS, &portp->state);
1945 set_bit(ST_DOFLUSHTX, &portp->state);
1946 set_bit(ST_DOFLUSHRX, &portp->state);
1948 stli_sendcmd(brdp, portp, A_SETSIGNALSF,
1949 &portp->asig, sizeof(asysigs_t), 0);
1953 clear_bit(ST_TXBUSY, &portp->state);
1954 clear_bit(ST_RXSTOP, &portp->state);
1955 set_bit(TTY_IO_ERROR, &tty->flags);
1957 portp->flags &= ~ASYNC_NORMAL_ACTIVE;
1958 portp->refcount = 0;
1959 spin_unlock_irqrestore(&stli_lock, flags);
1961 wake_up_interruptible(&portp->open_wait);
1964 /*****************************************************************************/
1967 * Flush characters from the lower buffer. We may not have user context
1968 * so we cannot sleep waiting for it to complete. Also we need to check
1969 * if there is chars for this port in the TX cook buffer, and flush them
1973 static void stli_flushbuffer(struct tty_struct *tty)
1975 struct stliport *portp;
1976 struct stlibrd *brdp;
1977 unsigned long ftype, flags;
1979 portp = tty->driver_data;
1982 if (portp->brdnr >= stli_nrbrds)
1984 brdp = stli_brds[portp->brdnr];
1988 spin_lock_irqsave(&brd_lock, flags);
1989 if (tty == stli_txcooktty) {
1990 stli_txcooktty = NULL;
1991 stli_txcooksize = 0;
1992 stli_txcookrealsize = 0;
1994 if (test_bit(ST_CMDING, &portp->state)) {
1995 set_bit(ST_DOFLUSHTX, &portp->state);
1998 if (test_bit(ST_DOFLUSHRX, &portp->state)) {
2000 clear_bit(ST_DOFLUSHRX, &portp->state);
2002 __stli_sendcmd(brdp, portp, A_FLUSH, &ftype, sizeof(u32), 0);
2004 spin_unlock_irqrestore(&brd_lock, flags);
2008 /*****************************************************************************/
2010 static void stli_breakctl(struct tty_struct *tty, int state)
2012 struct stlibrd *brdp;
2013 struct stliport *portp;
2016 portp = tty->driver_data;
2019 if (portp->brdnr >= stli_nrbrds)
2021 brdp = stli_brds[portp->brdnr];
2025 arg = (state == -1) ? BREAKON : BREAKOFF;
2026 stli_cmdwait(brdp, portp, A_BREAK, &arg, sizeof(long), 0);
2029 /*****************************************************************************/
2031 static void stli_waituntilsent(struct tty_struct *tty, int timeout)
2033 struct stliport *portp;
2038 portp = tty->driver_data;
2044 tend = jiffies + timeout;
2046 while (test_bit(ST_TXBUSY, &portp->state)) {
2047 if (signal_pending(current))
2049 msleep_interruptible(20);
2050 if (time_after_eq(jiffies, tend))
2055 /*****************************************************************************/
2057 static void stli_sendxchar(struct tty_struct *tty, char ch)
2059 struct stlibrd *brdp;
2060 struct stliport *portp;
2063 portp = tty->driver_data;
2066 if (portp->brdnr >= stli_nrbrds)
2068 brdp = stli_brds[portp->brdnr];
2072 memset(&actrl, 0, sizeof(asyctrl_t));
2073 if (ch == STOP_CHAR(tty)) {
2074 actrl.rxctrl = CT_STOPFLOW;
2075 } else if (ch == START_CHAR(tty)) {
2076 actrl.rxctrl = CT_STARTFLOW;
2078 actrl.txctrl = CT_SENDCHR;
2081 stli_cmdwait(brdp, portp, A_PORTCTRL, &actrl, sizeof(asyctrl_t), 0);
2084 /*****************************************************************************/
2089 * Format info for a specified port. The line is deliberately limited
2090 * to 80 characters. (If it is too long it will be truncated, if too
2091 * short then padded with spaces).
2094 static int stli_portinfo(struct stlibrd *brdp, struct stliport *portp, int portnr, char *pos)
2099 rc = stli_portcmdstats(portp);
2102 if (brdp->state & BST_STARTED) {
2103 switch (stli_comstats.hwid) {
2104 case 0: uart = "2681"; break;
2105 case 1: uart = "SC26198"; break;
2106 default:uart = "CD1400"; break;
2111 sp += sprintf(sp, "%d: uart:%s ", portnr, uart);
2113 if ((brdp->state & BST_STARTED) && (rc >= 0)) {
2114 sp += sprintf(sp, "tx:%d rx:%d", (int) stli_comstats.txtotal,
2115 (int) stli_comstats.rxtotal);
2117 if (stli_comstats.rxframing)
2118 sp += sprintf(sp, " fe:%d",
2119 (int) stli_comstats.rxframing);
2120 if (stli_comstats.rxparity)
2121 sp += sprintf(sp, " pe:%d",
2122 (int) stli_comstats.rxparity);
2123 if (stli_comstats.rxbreaks)
2124 sp += sprintf(sp, " brk:%d",
2125 (int) stli_comstats.rxbreaks);
2126 if (stli_comstats.rxoverrun)
2127 sp += sprintf(sp, " oe:%d",
2128 (int) stli_comstats.rxoverrun);
2130 cnt = sprintf(sp, "%s%s%s%s%s ",
2131 (stli_comstats.signals & TIOCM_RTS) ? "|RTS" : "",
2132 (stli_comstats.signals & TIOCM_CTS) ? "|CTS" : "",
2133 (stli_comstats.signals & TIOCM_DTR) ? "|DTR" : "",
2134 (stli_comstats.signals & TIOCM_CD) ? "|DCD" : "",
2135 (stli_comstats.signals & TIOCM_DSR) ? "|DSR" : "");
2140 for (cnt = (sp - pos); (cnt < (MAXLINE - 1)); cnt++)
2143 pos[(MAXLINE - 2)] = '+';
2144 pos[(MAXLINE - 1)] = '\n';
2149 /*****************************************************************************/
2152 * Port info, read from the /proc file system.
2155 static int stli_readproc(char *page, char **start, off_t off, int count, int *eof, void *data)
2157 struct stlibrd *brdp;
2158 struct stliport *portp;
2159 unsigned int brdnr, portnr, totalport;
2168 pos += sprintf(pos, "%s: version %s", stli_drvtitle,
2170 while (pos < (page + MAXLINE - 1))
2177 * We scan through for each board, panel and port. The offset is
2178 * calculated on the fly, and irrelevant ports are skipped.
2180 for (brdnr = 0; (brdnr < stli_nrbrds); brdnr++) {
2181 brdp = stli_brds[brdnr];
2184 if (brdp->state == 0)
2187 maxoff = curoff + (brdp->nrports * MAXLINE);
2188 if (off >= maxoff) {
2193 totalport = brdnr * STL_MAXPORTS;
2194 for (portnr = 0; (portnr < brdp->nrports); portnr++,
2196 portp = brdp->ports[portnr];
2199 if (off >= (curoff += MAXLINE))
2201 if ((pos - page + MAXLINE) > count)
2203 pos += stli_portinfo(brdp, portp, totalport, pos);
2214 /*****************************************************************************/
2217 * Generic send command routine. This will send a message to the slave,
2218 * of the specified type with the specified argument. Must be very
2219 * careful of data that will be copied out from shared memory -
2220 * containing command results. The command completion is all done from
2221 * a poll routine that does not have user context. Therefore you cannot
2222 * copy back directly into user space, or to the kernel stack of a
2223 * process. This routine does not sleep, so can be called from anywhere.
2225 * The caller must hold the brd_lock (see also stli_sendcmd the usual
2229 static void __stli_sendcmd(struct stlibrd *brdp, struct stliport *portp, unsigned long cmd, void *arg, int size, int copyback)
2231 cdkhdr_t __iomem *hdrp;
2232 cdkctrl_t __iomem *cp;
2233 unsigned char __iomem *bits;
2234 unsigned long flags;
2236 spin_lock_irqsave(&brd_lock, flags);
2238 if (test_bit(ST_CMDING, &portp->state)) {
2239 printk(KERN_ERR "STALLION: command already busy, cmd=%x!\n",
2241 spin_unlock_irqrestore(&brd_lock, flags);
2246 cp = &((cdkasy_t __iomem *) EBRDGETMEMPTR(brdp, portp->addr))->ctrl;
2248 memcpy_toio((void __iomem *) &(cp->args[0]), arg, size);
2251 portp->argsize = size;
2254 writel(0, &cp->status);
2255 writel(cmd, &cp->cmd);
2256 hdrp = (cdkhdr_t __iomem *) EBRDGETMEMPTR(brdp, CDK_CDKADDR);
2257 bits = ((unsigned char __iomem *) hdrp) + brdp->slaveoffset +
2259 writeb(readb(bits) | portp->portbit, bits);
2260 set_bit(ST_CMDING, &portp->state);
2262 spin_unlock_irqrestore(&brd_lock, flags);
2265 static void stli_sendcmd(struct stlibrd *brdp, struct stliport *portp, unsigned long cmd, void *arg, int size, int copyback)
2267 unsigned long flags;
2269 spin_lock_irqsave(&brd_lock, flags);
2270 __stli_sendcmd(brdp, portp, cmd, arg, size, copyback);
2271 spin_unlock_irqrestore(&brd_lock, flags);
2274 /*****************************************************************************/
2277 * Read data from shared memory. This assumes that the shared memory
2278 * is enabled and that interrupts are off. Basically we just empty out
2279 * the shared memory buffer into the tty buffer. Must be careful to
2280 * handle the case where we fill up the tty buffer, but still have
2281 * more chars to unload.
2284 static void stli_read(struct stlibrd *brdp, struct stliport *portp)
2286 cdkasyrq_t __iomem *rp;
2287 char __iomem *shbuf;
2288 struct tty_struct *tty;
2289 unsigned int head, tail, size;
2290 unsigned int len, stlen;
2292 if (test_bit(ST_RXSTOP, &portp->state))
2298 rp = &((cdkasy_t __iomem *) EBRDGETMEMPTR(brdp, portp->addr))->rxq;
2299 head = (unsigned int) readw(&rp->head);
2300 if (head != ((unsigned int) readw(&rp->head)))
2301 head = (unsigned int) readw(&rp->head);
2302 tail = (unsigned int) readw(&rp->tail);
2303 size = portp->rxsize;
2308 len = size - (tail - head);
2309 stlen = size - tail;
2312 len = tty_buffer_request_room(tty, len);
2314 shbuf = (char __iomem *) EBRDGETMEMPTR(brdp, portp->rxoffset);
2317 unsigned char *cptr;
2319 stlen = min(len, stlen);
2320 tty_prepare_flip_string(tty, &cptr, stlen);
2321 memcpy_fromio(cptr, shbuf + tail, stlen);
2329 rp = &((cdkasy_t __iomem *) EBRDGETMEMPTR(brdp, portp->addr))->rxq;
2330 writew(tail, &rp->tail);
2333 set_bit(ST_RXING, &portp->state);
2335 tty_schedule_flip(tty);
2338 /*****************************************************************************/
2341 * Set up and carry out any delayed commands. There is only a small set
2342 * of slave commands that can be done "off-level". So it is not too
2343 * difficult to deal with them here.
2346 static void stli_dodelaycmd(struct stliport *portp, cdkctrl_t __iomem *cp)
2350 if (test_bit(ST_DOSIGS, &portp->state)) {
2351 if (test_bit(ST_DOFLUSHTX, &portp->state) &&
2352 test_bit(ST_DOFLUSHRX, &portp->state))
2353 cmd = A_SETSIGNALSF;
2354 else if (test_bit(ST_DOFLUSHTX, &portp->state))
2355 cmd = A_SETSIGNALSFTX;
2356 else if (test_bit(ST_DOFLUSHRX, &portp->state))
2357 cmd = A_SETSIGNALSFRX;
2360 clear_bit(ST_DOFLUSHTX, &portp->state);
2361 clear_bit(ST_DOFLUSHRX, &portp->state);
2362 clear_bit(ST_DOSIGS, &portp->state);
2363 memcpy_toio((void __iomem *) &(cp->args[0]), (void *) &portp->asig,
2365 writel(0, &cp->status);
2366 writel(cmd, &cp->cmd);
2367 set_bit(ST_CMDING, &portp->state);
2368 } else if (test_bit(ST_DOFLUSHTX, &portp->state) ||
2369 test_bit(ST_DOFLUSHRX, &portp->state)) {
2370 cmd = ((test_bit(ST_DOFLUSHTX, &portp->state)) ? FLUSHTX : 0);
2371 cmd |= ((test_bit(ST_DOFLUSHRX, &portp->state)) ? FLUSHRX : 0);
2372 clear_bit(ST_DOFLUSHTX, &portp->state);
2373 clear_bit(ST_DOFLUSHRX, &portp->state);
2374 memcpy_toio((void __iomem *) &(cp->args[0]), (void *) &cmd, sizeof(int));
2375 writel(0, &cp->status);
2376 writel(A_FLUSH, &cp->cmd);
2377 set_bit(ST_CMDING, &portp->state);
2381 /*****************************************************************************/
2384 * Host command service checking. This handles commands or messages
2385 * coming from the slave to the host. Must have board shared memory
2386 * enabled and interrupts off when called. Notice that by servicing the
2387 * read data last we don't need to change the shared memory pointer
2388 * during processing (which is a slow IO operation).
2389 * Return value indicates if this port is still awaiting actions from
2390 * the slave (like open, command, or even TX data being sent). If 0
2391 * then port is still busy, otherwise no longer busy.
2394 static int stli_hostcmd(struct stlibrd *brdp, struct stliport *portp)
2396 cdkasy_t __iomem *ap;
2397 cdkctrl_t __iomem *cp;
2398 struct tty_struct *tty;
2400 unsigned long oldsigs;
2403 ap = (cdkasy_t __iomem *) EBRDGETMEMPTR(brdp, portp->addr);
2407 * Check if we are waiting for an open completion message.
2409 if (test_bit(ST_OPENING, &portp->state)) {
2410 rc = readl(&cp->openarg);
2411 if (readb(&cp->open) == 0 && rc != 0) {
2414 writel(0, &cp->openarg);
2416 clear_bit(ST_OPENING, &portp->state);
2417 wake_up_interruptible(&portp->raw_wait);
2422 * Check if we are waiting for a close completion message.
2424 if (test_bit(ST_CLOSING, &portp->state)) {
2425 rc = (int) readl(&cp->closearg);
2426 if (readb(&cp->close) == 0 && rc != 0) {
2429 writel(0, &cp->closearg);
2431 clear_bit(ST_CLOSING, &portp->state);
2432 wake_up_interruptible(&portp->raw_wait);
2437 * Check if we are waiting for a command completion message. We may
2438 * need to copy out the command results associated with this command.
2440 if (test_bit(ST_CMDING, &portp->state)) {
2441 rc = readl(&cp->status);
2442 if (readl(&cp->cmd) == 0 && rc != 0) {
2445 if (portp->argp != NULL) {
2446 memcpy_fromio(portp->argp, (void __iomem *) &(cp->args[0]),
2450 writel(0, &cp->status);
2452 clear_bit(ST_CMDING, &portp->state);
2453 stli_dodelaycmd(portp, cp);
2454 wake_up_interruptible(&portp->raw_wait);
2459 * Check for any notification messages ready. This includes lots of
2460 * different types of events - RX chars ready, RX break received,
2461 * TX data low or empty in the slave, modem signals changed state.
2470 if (nt.signal & SG_DCD) {
2471 oldsigs = portp->sigs;
2472 portp->sigs = stli_mktiocm(nt.sigvalue);
2473 clear_bit(ST_GETSIGS, &portp->state);
2474 if ((portp->sigs & TIOCM_CD) &&
2475 ((oldsigs & TIOCM_CD) == 0))
2476 wake_up_interruptible(&portp->open_wait);
2477 if ((oldsigs & TIOCM_CD) &&
2478 ((portp->sigs & TIOCM_CD) == 0)) {
2479 if (portp->flags & ASYNC_CHECK_CD) {
2481 schedule_work(&portp->tqhangup);
2486 if (nt.data & DT_TXEMPTY)
2487 clear_bit(ST_TXBUSY, &portp->state);
2488 if (nt.data & (DT_TXEMPTY | DT_TXLOW)) {
2492 wake_up_interruptible(&tty->write_wait);
2496 if ((nt.data & DT_RXBREAK) && (portp->rxmarkmsk & BRKINT)) {
2498 tty_insert_flip_char(tty, 0, TTY_BREAK);
2499 if (portp->flags & ASYNC_SAK) {
2503 tty_schedule_flip(tty);
2507 if (nt.data & DT_RXBUSY) {
2509 stli_read(brdp, portp);
2514 * It might seem odd that we are checking for more RX chars here.
2515 * But, we need to handle the case where the tty buffer was previously
2516 * filled, but we had more characters to pass up. The slave will not
2517 * send any more RX notify messages until the RX buffer has been emptied.
2518 * But it will leave the service bits on (since the buffer is not empty).
2519 * So from here we can try to process more RX chars.
2521 if ((!donerx) && test_bit(ST_RXING, &portp->state)) {
2522 clear_bit(ST_RXING, &portp->state);
2523 stli_read(brdp, portp);
2526 return((test_bit(ST_OPENING, &portp->state) ||
2527 test_bit(ST_CLOSING, &portp->state) ||
2528 test_bit(ST_CMDING, &portp->state) ||
2529 test_bit(ST_TXBUSY, &portp->state) ||
2530 test_bit(ST_RXING, &portp->state)) ? 0 : 1);
2533 /*****************************************************************************/
2536 * Service all ports on a particular board. Assumes that the boards
2537 * shared memory is enabled, and that the page pointer is pointed
2538 * at the cdk header structure.
2541 static void stli_brdpoll(struct stlibrd *brdp, cdkhdr_t __iomem *hdrp)
2543 struct stliport *portp;
2544 unsigned char hostbits[(STL_MAXCHANS / 8) + 1];
2545 unsigned char slavebits[(STL_MAXCHANS / 8) + 1];
2546 unsigned char __iomem *slavep;
2547 int bitpos, bitat, bitsize;
2548 int channr, nrdevs, slavebitchange;
2550 bitsize = brdp->bitsize;
2551 nrdevs = brdp->nrdevs;
2554 * Check if slave wants any service. Basically we try to do as
2555 * little work as possible here. There are 2 levels of service
2556 * bits. So if there is nothing to do we bail early. We check
2557 * 8 service bits at a time in the inner loop, so we can bypass
2558 * the lot if none of them want service.
2560 memcpy_fromio(&hostbits[0], (((unsigned char __iomem *) hdrp) + brdp->hostoffset),
2563 memset(&slavebits[0], 0, bitsize);
2566 for (bitpos = 0; (bitpos < bitsize); bitpos++) {
2567 if (hostbits[bitpos] == 0)
2569 channr = bitpos * 8;
2570 for (bitat = 0x1; (channr < nrdevs); channr++, bitat <<= 1) {
2571 if (hostbits[bitpos] & bitat) {
2572 portp = brdp->ports[(channr - 1)];
2573 if (stli_hostcmd(brdp, portp)) {
2575 slavebits[bitpos] |= bitat;
2582 * If any of the ports are no longer busy then update them in the
2583 * slave request bits. We need to do this after, since a host port
2584 * service may initiate more slave requests.
2586 if (slavebitchange) {
2587 hdrp = (cdkhdr_t __iomem *) EBRDGETMEMPTR(brdp, CDK_CDKADDR);
2588 slavep = ((unsigned char __iomem *) hdrp) + brdp->slaveoffset;
2589 for (bitpos = 0; (bitpos < bitsize); bitpos++) {
2590 if (readb(slavebits + bitpos))
2591 writeb(readb(slavep + bitpos) & ~slavebits[bitpos], slavebits + bitpos);
2596 /*****************************************************************************/
2599 * Driver poll routine. This routine polls the boards in use and passes
2600 * messages back up to host when necessary. This is actually very
2601 * CPU efficient, since we will always have the kernel poll clock, it
2602 * adds only a few cycles when idle (since board service can be
2603 * determined very easily), but when loaded generates no interrupts
2604 * (with their expensive associated context change).
2607 static void stli_poll(unsigned long arg)
2609 cdkhdr_t __iomem *hdrp;
2610 struct stlibrd *brdp;
2613 stli_timerlist.expires = STLI_TIMEOUT;
2614 add_timer(&stli_timerlist);
2617 * Check each board and do any servicing required.
2619 for (brdnr = 0; (brdnr < stli_nrbrds); brdnr++) {
2620 brdp = stli_brds[brdnr];
2623 if ((brdp->state & BST_STARTED) == 0)
2626 spin_lock(&brd_lock);
2628 hdrp = (cdkhdr_t __iomem *) EBRDGETMEMPTR(brdp, CDK_CDKADDR);
2629 if (readb(&hdrp->hostreq))
2630 stli_brdpoll(brdp, hdrp);
2632 spin_unlock(&brd_lock);
2636 /*****************************************************************************/
2639 * Translate the termios settings into the port setting structure of
2643 static void stli_mkasyport(struct stliport *portp, asyport_t *pp, struct ktermios *tiosp)
2645 memset(pp, 0, sizeof(asyport_t));
2648 * Start of by setting the baud, char size, parity and stop bit info.
2650 pp->baudout = tty_get_baud_rate(portp->tty);
2651 if ((tiosp->c_cflag & CBAUD) == B38400) {
2652 if ((portp->flags & ASYNC_SPD_MASK) == ASYNC_SPD_HI)
2653 pp->baudout = 57600;
2654 else if ((portp->flags & ASYNC_SPD_MASK) == ASYNC_SPD_VHI)
2655 pp->baudout = 115200;
2656 else if ((portp->flags & ASYNC_SPD_MASK) == ASYNC_SPD_SHI)
2657 pp->baudout = 230400;
2658 else if ((portp->flags & ASYNC_SPD_MASK) == ASYNC_SPD_WARP)
2659 pp->baudout = 460800;
2660 else if ((portp->flags & ASYNC_SPD_MASK) == ASYNC_SPD_CUST)
2661 pp->baudout = (portp->baud_base / portp->custom_divisor);
2663 if (pp->baudout > STL_MAXBAUD)
2664 pp->baudout = STL_MAXBAUD;
2665 pp->baudin = pp->baudout;
2667 switch (tiosp->c_cflag & CSIZE) {
2682 if (tiosp->c_cflag & CSTOPB)
2683 pp->stopbs = PT_STOP2;
2685 pp->stopbs = PT_STOP1;
2687 if (tiosp->c_cflag & PARENB) {
2688 if (tiosp->c_cflag & PARODD)
2689 pp->parity = PT_ODDPARITY;
2691 pp->parity = PT_EVENPARITY;
2693 pp->parity = PT_NOPARITY;
2697 * Set up any flow control options enabled.
2699 if (tiosp->c_iflag & IXON) {
2701 if (tiosp->c_iflag & IXANY)
2702 pp->flow |= F_IXANY;
2704 if (tiosp->c_cflag & CRTSCTS)
2705 pp->flow |= (F_RTSFLOW | F_CTSFLOW);
2707 pp->startin = tiosp->c_cc[VSTART];
2708 pp->stopin = tiosp->c_cc[VSTOP];
2709 pp->startout = tiosp->c_cc[VSTART];
2710 pp->stopout = tiosp->c_cc[VSTOP];
2713 * Set up the RX char marking mask with those RX error types we must
2714 * catch. We can get the slave to help us out a little here, it will
2715 * ignore parity errors and breaks for us, and mark parity errors in
2718 if (tiosp->c_iflag & IGNPAR)
2719 pp->iflag |= FI_IGNRXERRS;
2720 if (tiosp->c_iflag & IGNBRK)
2721 pp->iflag |= FI_IGNBREAK;
2723 portp->rxmarkmsk = 0;
2724 if (tiosp->c_iflag & (INPCK | PARMRK))
2725 pp->iflag |= FI_1MARKRXERRS;
2726 if (tiosp->c_iflag & BRKINT)
2727 portp->rxmarkmsk |= BRKINT;
2730 * Set up clocal processing as required.
2732 if (tiosp->c_cflag & CLOCAL)
2733 portp->flags &= ~ASYNC_CHECK_CD;
2735 portp->flags |= ASYNC_CHECK_CD;
2738 * Transfer any persistent flags into the asyport structure.
2740 pp->pflag = (portp->pflag & 0xffff);
2741 pp->vmin = (portp->pflag & P_RXIMIN) ? 1 : 0;
2742 pp->vtime = (portp->pflag & P_RXITIME) ? 1 : 0;
2743 pp->cc[1] = (portp->pflag & P_RXTHOLD) ? 1 : 0;
2746 /*****************************************************************************/
2749 * Construct a slave signals structure for setting the DTR and RTS
2750 * signals as specified.
2753 static void stli_mkasysigs(asysigs_t *sp, int dtr, int rts)
2755 memset(sp, 0, sizeof(asysigs_t));
2757 sp->signal |= SG_DTR;
2758 sp->sigvalue |= ((dtr > 0) ? SG_DTR : 0);
2761 sp->signal |= SG_RTS;
2762 sp->sigvalue |= ((rts > 0) ? SG_RTS : 0);
2766 /*****************************************************************************/
2769 * Convert the signals returned from the slave into a local TIOCM type
2770 * signals value. We keep them locally in TIOCM format.
2773 static long stli_mktiocm(unsigned long sigvalue)
2776 tiocm |= ((sigvalue & SG_DCD) ? TIOCM_CD : 0);
2777 tiocm |= ((sigvalue & SG_CTS) ? TIOCM_CTS : 0);
2778 tiocm |= ((sigvalue & SG_RI) ? TIOCM_RI : 0);
2779 tiocm |= ((sigvalue & SG_DSR) ? TIOCM_DSR : 0);
2780 tiocm |= ((sigvalue & SG_DTR) ? TIOCM_DTR : 0);
2781 tiocm |= ((sigvalue & SG_RTS) ? TIOCM_RTS : 0);
2785 /*****************************************************************************/
2788 * All panels and ports actually attached have been worked out. All
2789 * we need to do here is set up the appropriate per port data structures.
2792 static int stli_initports(struct stlibrd *brdp)
2794 struct stliport *portp;
2795 unsigned int i, panelnr, panelport;
2797 for (i = 0, panelnr = 0, panelport = 0; (i < brdp->nrports); i++) {
2798 portp = kzalloc(sizeof(struct stliport), GFP_KERNEL);
2800 printk("STALLION: failed to allocate port structure\n");
2804 portp->magic = STLI_PORTMAGIC;
2806 portp->brdnr = brdp->brdnr;
2807 portp->panelnr = panelnr;
2808 portp->baud_base = STL_BAUDBASE;
2809 portp->close_delay = STL_CLOSEDELAY;
2810 portp->closing_wait = 30 * HZ;
2811 INIT_WORK(&portp->tqhangup, stli_dohangup);
2812 init_waitqueue_head(&portp->open_wait);
2813 init_waitqueue_head(&portp->close_wait);
2814 init_waitqueue_head(&portp->raw_wait);
2816 if (panelport >= brdp->panels[panelnr]) {
2820 brdp->ports[i] = portp;
2826 /*****************************************************************************/
2829 * All the following routines are board specific hardware operations.
2832 static void stli_ecpinit(struct stlibrd *brdp)
2834 unsigned long memconf;
2836 outb(ECP_ATSTOP, (brdp->iobase + ECP_ATCONFR));
2838 outb(ECP_ATDISABLE, (brdp->iobase + ECP_ATCONFR));
2841 memconf = (brdp->memaddr & ECP_ATADDRMASK) >> ECP_ATADDRSHFT;
2842 outb(memconf, (brdp->iobase + ECP_ATMEMAR));
2845 /*****************************************************************************/
2847 static void stli_ecpenable(struct stlibrd *brdp)
2849 outb(ECP_ATENABLE, (brdp->iobase + ECP_ATCONFR));
2852 /*****************************************************************************/
2854 static void stli_ecpdisable(struct stlibrd *brdp)
2856 outb(ECP_ATDISABLE, (brdp->iobase + ECP_ATCONFR));
2859 /*****************************************************************************/
2861 static void __iomem *stli_ecpgetmemptr(struct stlibrd *brdp, unsigned long offset, int line)
2866 if (offset > brdp->memsize) {
2867 printk(KERN_ERR "STALLION: shared memory pointer=%x out of "
2868 "range at line=%d(%d), brd=%d\n",
2869 (int) offset, line, __LINE__, brdp->brdnr);
2873 ptr = brdp->membase + (offset % ECP_ATPAGESIZE);
2874 val = (unsigned char) (offset / ECP_ATPAGESIZE);
2876 outb(val, (brdp->iobase + ECP_ATMEMPR));
2880 /*****************************************************************************/
2882 static void stli_ecpreset(struct stlibrd *brdp)
2884 outb(ECP_ATSTOP, (brdp->iobase + ECP_ATCONFR));
2886 outb(ECP_ATDISABLE, (brdp->iobase + ECP_ATCONFR));
2890 /*****************************************************************************/
2892 static void stli_ecpintr(struct stlibrd *brdp)
2894 outb(0x1, brdp->iobase);
2897 /*****************************************************************************/
2900 * The following set of functions act on ECP EISA boards.
2903 static void stli_ecpeiinit(struct stlibrd *brdp)
2905 unsigned long memconf;
2907 outb(0x1, (brdp->iobase + ECP_EIBRDENAB));
2908 outb(ECP_EISTOP, (brdp->iobase + ECP_EICONFR));
2910 outb(ECP_EIDISABLE, (brdp->iobase + ECP_EICONFR));
2913 memconf = (brdp->memaddr & ECP_EIADDRMASKL) >> ECP_EIADDRSHFTL;
2914 outb(memconf, (brdp->iobase + ECP_EIMEMARL));
2915 memconf = (brdp->memaddr & ECP_EIADDRMASKH) >> ECP_EIADDRSHFTH;
2916 outb(memconf, (brdp->iobase + ECP_EIMEMARH));
2919 /*****************************************************************************/
2921 static void stli_ecpeienable(struct stlibrd *brdp)
2923 outb(ECP_EIENABLE, (brdp->iobase + ECP_EICONFR));
2926 /*****************************************************************************/
2928 static void stli_ecpeidisable(struct stlibrd *brdp)
2930 outb(ECP_EIDISABLE, (brdp->iobase + ECP_EICONFR));
2933 /*****************************************************************************/
2935 static void __iomem *stli_ecpeigetmemptr(struct stlibrd *brdp, unsigned long offset, int line)
2940 if (offset > brdp->memsize) {
2941 printk(KERN_ERR "STALLION: shared memory pointer=%x out of "
2942 "range at line=%d(%d), brd=%d\n",
2943 (int) offset, line, __LINE__, brdp->brdnr);
2947 ptr = brdp->membase + (offset % ECP_EIPAGESIZE);
2948 if (offset < ECP_EIPAGESIZE)
2951 val = ECP_EIENABLE | 0x40;
2953 outb(val, (brdp->iobase + ECP_EICONFR));
2957 /*****************************************************************************/
2959 static void stli_ecpeireset(struct stlibrd *brdp)
2961 outb(ECP_EISTOP, (brdp->iobase + ECP_EICONFR));
2963 outb(ECP_EIDISABLE, (brdp->iobase + ECP_EICONFR));
2967 /*****************************************************************************/
2970 * The following set of functions act on ECP MCA boards.
2973 static void stli_ecpmcenable(struct stlibrd *brdp)
2975 outb(ECP_MCENABLE, (brdp->iobase + ECP_MCCONFR));
2978 /*****************************************************************************/
2980 static void stli_ecpmcdisable(struct stlibrd *brdp)
2982 outb(ECP_MCDISABLE, (brdp->iobase + ECP_MCCONFR));
2985 /*****************************************************************************/
2987 static void __iomem *stli_ecpmcgetmemptr(struct stlibrd *brdp, unsigned long offset, int line)
2992 if (offset > brdp->memsize) {
2993 printk(KERN_ERR "STALLION: shared memory pointer=%x out of "
2994 "range at line=%d(%d), brd=%d\n",
2995 (int) offset, line, __LINE__, brdp->brdnr);
2999 ptr = brdp->membase + (offset % ECP_MCPAGESIZE);
3000 val = ((unsigned char) (offset / ECP_MCPAGESIZE)) | ECP_MCENABLE;
3002 outb(val, (brdp->iobase + ECP_MCCONFR));
3006 /*****************************************************************************/
3008 static void stli_ecpmcreset(struct stlibrd *brdp)
3010 outb(ECP_MCSTOP, (brdp->iobase + ECP_MCCONFR));
3012 outb(ECP_MCDISABLE, (brdp->iobase + ECP_MCCONFR));
3016 /*****************************************************************************/
3019 * The following set of functions act on ECP PCI boards.
3022 static void stli_ecppciinit(struct stlibrd *brdp)
3024 outb(ECP_PCISTOP, (brdp->iobase + ECP_PCICONFR));
3026 outb(0, (brdp->iobase + ECP_PCICONFR));
3030 /*****************************************************************************/
3032 static void __iomem *stli_ecppcigetmemptr(struct stlibrd *brdp, unsigned long offset, int line)
3037 if (offset > brdp->memsize) {
3038 printk(KERN_ERR "STALLION: shared memory pointer=%x out of "
3039 "range at line=%d(%d), board=%d\n",
3040 (int) offset, line, __LINE__, brdp->brdnr);
3044 ptr = brdp->membase + (offset % ECP_PCIPAGESIZE);
3045 val = (offset / ECP_PCIPAGESIZE) << 1;
3047 outb(val, (brdp->iobase + ECP_PCICONFR));
3051 /*****************************************************************************/
3053 static void stli_ecppcireset(struct stlibrd *brdp)
3055 outb(ECP_PCISTOP, (brdp->iobase + ECP_PCICONFR));
3057 outb(0, (brdp->iobase + ECP_PCICONFR));
3061 /*****************************************************************************/
3064 * The following routines act on ONboards.
3067 static void stli_onbinit(struct stlibrd *brdp)
3069 unsigned long memconf;
3071 outb(ONB_ATSTOP, (brdp->iobase + ONB_ATCONFR));
3073 outb(ONB_ATDISABLE, (brdp->iobase + ONB_ATCONFR));
3076 memconf = (brdp->memaddr & ONB_ATADDRMASK) >> ONB_ATADDRSHFT;
3077 outb(memconf, (brdp->iobase + ONB_ATMEMAR));
3078 outb(0x1, brdp->iobase);
3082 /*****************************************************************************/
3084 static void stli_onbenable(struct stlibrd *brdp)
3086 outb((brdp->enabval | ONB_ATENABLE), (brdp->iobase + ONB_ATCONFR));
3089 /*****************************************************************************/
3091 static void stli_onbdisable(struct stlibrd *brdp)
3093 outb((brdp->enabval | ONB_ATDISABLE), (brdp->iobase + ONB_ATCONFR));
3096 /*****************************************************************************/
3098 static void __iomem *stli_onbgetmemptr(struct stlibrd *brdp, unsigned long offset, int line)
3102 if (offset > brdp->memsize) {
3103 printk(KERN_ERR "STALLION: shared memory pointer=%x out of "
3104 "range at line=%d(%d), brd=%d\n",
3105 (int) offset, line, __LINE__, brdp->brdnr);
3108 ptr = brdp->membase + (offset % ONB_ATPAGESIZE);
3113 /*****************************************************************************/
3115 static void stli_onbreset(struct stlibrd *brdp)
3117 outb(ONB_ATSTOP, (brdp->iobase + ONB_ATCONFR));
3119 outb(ONB_ATDISABLE, (brdp->iobase + ONB_ATCONFR));
3123 /*****************************************************************************/
3126 * The following routines act on ONboard EISA.
3129 static void stli_onbeinit(struct stlibrd *brdp)
3131 unsigned long memconf;
3133 outb(0x1, (brdp->iobase + ONB_EIBRDENAB));
3134 outb(ONB_EISTOP, (brdp->iobase + ONB_EICONFR));
3136 outb(ONB_EIDISABLE, (brdp->iobase + ONB_EICONFR));
3139 memconf = (brdp->memaddr & ONB_EIADDRMASKL) >> ONB_EIADDRSHFTL;
3140 outb(memconf, (brdp->iobase + ONB_EIMEMARL));
3141 memconf = (brdp->memaddr & ONB_EIADDRMASKH) >> ONB_EIADDRSHFTH;
3142 outb(memconf, (brdp->iobase + ONB_EIMEMARH));
3143 outb(0x1, brdp->iobase);
3147 /*****************************************************************************/
3149 static void stli_onbeenable(struct stlibrd *brdp)
3151 outb(ONB_EIENABLE, (brdp->iobase + ONB_EICONFR));
3154 /*****************************************************************************/
3156 static void stli_onbedisable(struct stlibrd *brdp)
3158 outb(ONB_EIDISABLE, (brdp->iobase + ONB_EICONFR));
3161 /*****************************************************************************/
3163 static void __iomem *stli_onbegetmemptr(struct stlibrd *brdp, unsigned long offset, int line)
3168 if (offset > brdp->memsize) {
3169 printk(KERN_ERR "STALLION: shared memory pointer=%x out of "
3170 "range at line=%d(%d), brd=%d\n",
3171 (int) offset, line, __LINE__, brdp->brdnr);
3175 ptr = brdp->membase + (offset % ONB_EIPAGESIZE);
3176 if (offset < ONB_EIPAGESIZE)
3179 val = ONB_EIENABLE | 0x40;
3181 outb(val, (brdp->iobase + ONB_EICONFR));
3185 /*****************************************************************************/
3187 static void stli_onbereset(struct stlibrd *brdp)
3189 outb(ONB_EISTOP, (brdp->iobase + ONB_EICONFR));
3191 outb(ONB_EIDISABLE, (brdp->iobase + ONB_EICONFR));
3195 /*****************************************************************************/
3198 * The following routines act on Brumby boards.
3201 static void stli_bbyinit(struct stlibrd *brdp)
3203 outb(BBY_ATSTOP, (brdp->iobase + BBY_ATCONFR));
3205 outb(0, (brdp->iobase + BBY_ATCONFR));
3207 outb(0x1, brdp->iobase);
3211 /*****************************************************************************/
3213 static void __iomem *stli_bbygetmemptr(struct stlibrd *brdp, unsigned long offset, int line)
3218 BUG_ON(offset > brdp->memsize);
3220 ptr = brdp->membase + (offset % BBY_PAGESIZE);
3221 val = (unsigned char) (offset / BBY_PAGESIZE);
3222 outb(val, (brdp->iobase + BBY_ATCONFR));
3226 /*****************************************************************************/
3228 static void stli_bbyreset(struct stlibrd *brdp)
3230 outb(BBY_ATSTOP, (brdp->iobase + BBY_ATCONFR));
3232 outb(0, (brdp->iobase + BBY_ATCONFR));
3236 /*****************************************************************************/
3239 * The following routines act on original old Stallion boards.
3242 static void stli_stalinit(struct stlibrd *brdp)
3244 outb(0x1, brdp->iobase);
3248 /*****************************************************************************/
3250 static void __iomem *stli_stalgetmemptr(struct stlibrd *brdp, unsigned long offset, int line)
3252 BUG_ON(offset > brdp->memsize);
3253 return brdp->membase + (offset % STAL_PAGESIZE);
3256 /*****************************************************************************/
3258 static void stli_stalreset(struct stlibrd *brdp)
3262 vecp = (u32 __iomem *) (brdp->membase + 0x30);
3263 writel(0xffff0000, vecp);
3264 outb(0, brdp->iobase);
3268 /*****************************************************************************/
3271 * Try to find an ECP board and initialize it. This handles only ECP
3275 static int stli_initecp(struct stlibrd *brdp)
3278 cdkecpsig_t __iomem *sigsp;
3279 unsigned int status, nxtid;
3281 int panelnr, nrports;
3283 if (!request_region(brdp->iobase, brdp->iosize, "istallion"))
3286 if ((brdp->iobase == 0) || (brdp->memaddr == 0))
3288 release_region(brdp->iobase, brdp->iosize);
3292 brdp->iosize = ECP_IOSIZE;
3295 * Based on the specific board type setup the common vars to access
3296 * and enable shared memory. Set all board specific information now
3299 switch (brdp->brdtype) {
3301 brdp->memsize = ECP_MEMSIZE;
3302 brdp->pagesize = ECP_ATPAGESIZE;
3303 brdp->init = stli_ecpinit;
3304 brdp->enable = stli_ecpenable;
3305 brdp->reenable = stli_ecpenable;
3306 brdp->disable = stli_ecpdisable;
3307 brdp->getmemptr = stli_ecpgetmemptr;
3308 brdp->intr = stli_ecpintr;
3309 brdp->reset = stli_ecpreset;
3310 name = "serial(EC8/64)";
3314 brdp->memsize = ECP_MEMSIZE;
3315 brdp->pagesize = ECP_EIPAGESIZE;
3316 brdp->init = stli_ecpeiinit;
3317 brdp->enable = stli_ecpeienable;
3318 brdp->reenable = stli_ecpeienable;
3319 brdp->disable = stli_ecpeidisable;
3320 brdp->getmemptr = stli_ecpeigetmemptr;
3321 brdp->intr = stli_ecpintr;
3322 brdp->reset = stli_ecpeireset;
3323 name = "serial(EC8/64-EI)";
3327 brdp->memsize = ECP_MEMSIZE;
3328 brdp->pagesize = ECP_MCPAGESIZE;
3330 brdp->enable = stli_ecpmcenable;
3331 brdp->reenable = stli_ecpmcenable;
3332 brdp->disable = stli_ecpmcdisable;
3333 brdp->getmemptr = stli_ecpmcgetmemptr;
3334 brdp->intr = stli_ecpintr;
3335 brdp->reset = stli_ecpmcreset;
3336 name = "serial(EC8/64-MCA)";
3340 brdp->memsize = ECP_PCIMEMSIZE;
3341 brdp->pagesize = ECP_PCIPAGESIZE;
3342 brdp->init = stli_ecppciinit;
3343 brdp->enable = NULL;
3344 brdp->reenable = NULL;
3345 brdp->disable = NULL;
3346 brdp->getmemptr = stli_ecppcigetmemptr;
3347 brdp->intr = stli_ecpintr;
3348 brdp->reset = stli_ecppcireset;
3349 name = "serial(EC/RA-PCI)";
3353 release_region(brdp->iobase, brdp->iosize);
3358 * The per-board operations structure is all set up, so now let's go
3359 * and get the board operational. Firstly initialize board configuration
3360 * registers. Set the memory mapping info so we can get at the boards
3365 brdp->membase = ioremap(brdp->memaddr, brdp->memsize);
3366 if (brdp->membase == NULL)
3368 release_region(brdp->iobase, brdp->iosize);
3373 * Now that all specific code is set up, enable the shared memory and
3374 * look for the a signature area that will tell us exactly what board
3375 * this is, and what it is connected to it.
3378 sigsp = (cdkecpsig_t __iomem *) EBRDGETMEMPTR(brdp, CDK_SIGADDR);
3379 memcpy_fromio(&sig, sigsp, sizeof(cdkecpsig_t));
3382 if (sig.magic != cpu_to_le32(ECP_MAGIC))
3384 release_region(brdp->iobase, brdp->iosize);
3385 iounmap(brdp->membase);
3386 brdp->membase = NULL;
3391 * Scan through the signature looking at the panels connected to the
3392 * board. Calculate the total number of ports as we go.
3394 for (panelnr = 0, nxtid = 0; (panelnr < STL_MAXPANELS); panelnr++) {
3395 status = sig.panelid[nxtid];
3396 if ((status & ECH_PNLIDMASK) != nxtid)
3399 brdp->panelids[panelnr] = status;
3400 nrports = (status & ECH_PNL16PORT) ? 16 : 8;
3401 if ((nrports == 16) && ((status & ECH_PNLXPID) == 0))
3403 brdp->panels[panelnr] = nrports;
3404 brdp->nrports += nrports;
3410 brdp->state |= BST_FOUND;
3414 /*****************************************************************************/
3417 * Try to find an ONboard, Brumby or Stallion board and initialize it.
3418 * This handles only these board types.
3421 static int stli_initonb(struct stlibrd *brdp)
3424 cdkonbsig_t __iomem *sigsp;
3429 * Do a basic sanity check on the IO and memory addresses.
3431 if (brdp->iobase == 0 || brdp->memaddr == 0)
3434 brdp->iosize = ONB_IOSIZE;
3436 if (!request_region(brdp->iobase, brdp->iosize, "istallion"))
3440 * Based on the specific board type setup the common vars to access
3441 * and enable shared memory. Set all board specific information now
3444 switch (brdp->brdtype) {
3447 brdp->memsize = ONB_MEMSIZE;
3448 brdp->pagesize = ONB_ATPAGESIZE;
3449 brdp->init = stli_onbinit;
3450 brdp->enable = stli_onbenable;
3451 brdp->reenable = stli_onbenable;
3452 brdp->disable = stli_onbdisable;
3453 brdp->getmemptr = stli_onbgetmemptr;
3454 brdp->intr = stli_ecpintr;
3455 brdp->reset = stli_onbreset;
3456 if (brdp->memaddr > 0x100000)
3457 brdp->enabval = ONB_MEMENABHI;
3459 brdp->enabval = ONB_MEMENABLO;
3460 name = "serial(ONBoard)";
3464 brdp->memsize = ONB_EIMEMSIZE;
3465 brdp->pagesize = ONB_EIPAGESIZE;
3466 brdp->init = stli_onbeinit;
3467 brdp->enable = stli_onbeenable;
3468 brdp->reenable = stli_onbeenable;
3469 brdp->disable = stli_onbedisable;
3470 brdp->getmemptr = stli_onbegetmemptr;
3471 brdp->intr = stli_ecpintr;
3472 brdp->reset = stli_onbereset;
3473 name = "serial(ONBoard/E)";
3477 brdp->memsize = BBY_MEMSIZE;
3478 brdp->pagesize = BBY_PAGESIZE;
3479 brdp->init = stli_bbyinit;
3480 brdp->enable = NULL;
3481 brdp->reenable = NULL;
3482 brdp->disable = NULL;
3483 brdp->getmemptr = stli_bbygetmemptr;
3484 brdp->intr = stli_ecpintr;
3485 brdp->reset = stli_bbyreset;
3486 name = "serial(Brumby)";
3490 brdp->memsize = STAL_MEMSIZE;
3491 brdp->pagesize = STAL_PAGESIZE;
3492 brdp->init = stli_stalinit;
3493 brdp->enable = NULL;
3494 brdp->reenable = NULL;
3495 brdp->disable = NULL;
3496 brdp->getmemptr = stli_stalgetmemptr;
3497 brdp->intr = stli_ecpintr;
3498 brdp->reset = stli_stalreset;
3499 name = "serial(Stallion)";
3503 release_region(brdp->iobase, brdp->iosize);
3508 * The per-board operations structure is all set up, so now let's go
3509 * and get the board operational. Firstly initialize board configuration
3510 * registers. Set the memory mapping info so we can get at the boards
3515 brdp->membase = ioremap(brdp->memaddr, brdp->memsize);
3516 if (brdp->membase == NULL)
3518 release_region(brdp->iobase, brdp->iosize);
3523 * Now that all specific code is set up, enable the shared memory and
3524 * look for the a signature area that will tell us exactly what board
3525 * this is, and how many ports.
3528 sigsp = (cdkonbsig_t __iomem *) EBRDGETMEMPTR(brdp, CDK_SIGADDR);
3529 memcpy_fromio(&sig, sigsp, sizeof(cdkonbsig_t));
3532 if (sig.magic0 != cpu_to_le16(ONB_MAGIC0) ||
3533 sig.magic1 != cpu_to_le16(ONB_MAGIC1) ||
3534 sig.magic2 != cpu_to_le16(ONB_MAGIC2) ||
3535 sig.magic3 != cpu_to_le16(ONB_MAGIC3))
3537 release_region(brdp->iobase, brdp->iosize);
3538 iounmap(brdp->membase);
3539 brdp->membase = NULL;
3544 * Scan through the signature alive mask and calculate how many ports
3545 * there are on this board.
3551 for (i = 0; (i < 16); i++) {
3552 if (((sig.amask0 << i) & 0x8000) == 0)
3557 brdp->panels[0] = brdp->nrports;
3560 brdp->state |= BST_FOUND;
3564 /*****************************************************************************/
3567 * Start up a running board. This routine is only called after the
3568 * code has been down loaded to the board and is operational. It will
3569 * read in the memory map, and get the show on the road...
3572 static int stli_startbrd(struct stlibrd *brdp)
3574 cdkhdr_t __iomem *hdrp;
3575 cdkmem_t __iomem *memp;
3576 cdkasy_t __iomem *ap;
3577 unsigned long flags;
3578 unsigned int portnr, nrdevs, i;
3579 struct stliport *portp;
3583 spin_lock_irqsave(&brd_lock, flags);
3585 hdrp = (cdkhdr_t __iomem *) EBRDGETMEMPTR(brdp, CDK_CDKADDR);
3586 nrdevs = hdrp->nrdevs;
3589 printk("%s(%d): CDK version %d.%d.%d --> "
3590 "nrdevs=%d memp=%x hostp=%x slavep=%x\n",
3591 __FILE__, __LINE__, readb(&hdrp->ver_release), readb(&hdrp->ver_modification),
3592 readb(&hdrp->ver_fix), nrdevs, (int) readl(&hdrp->memp), readl(&hdrp->hostp),
3593 readl(&hdrp->slavep));
3596 if (nrdevs < (brdp->nrports + 1)) {
3597 printk(KERN_ERR "STALLION: slave failed to allocate memory for "
3598 "all devices, devices=%d\n", nrdevs);
3599 brdp->nrports = nrdevs - 1;
3601 brdp->nrdevs = nrdevs;
3602 brdp->hostoffset = hdrp->hostp - CDK_CDKADDR;
3603 brdp->slaveoffset = hdrp->slavep - CDK_CDKADDR;
3604 brdp->bitsize = (nrdevs + 7) / 8;
3605 memoff = readl(&hdrp->memp);
3606 if (memoff > brdp->memsize) {
3607 printk(KERN_ERR "STALLION: corrupted shared memory region?\n");
3609 goto stli_donestartup;
3611 memp = (cdkmem_t __iomem *) EBRDGETMEMPTR(brdp, memoff);
3612 if (readw(&memp->dtype) != TYP_ASYNCTRL) {
3613 printk(KERN_ERR "STALLION: no slave control device found\n");
3614 goto stli_donestartup;
3619 * Cycle through memory allocation of each port. We are guaranteed to
3620 * have all ports inside the first page of slave window, so no need to
3621 * change pages while reading memory map.
3623 for (i = 1, portnr = 0; (i < nrdevs); i++, portnr++, memp++) {
3624 if (readw(&memp->dtype) != TYP_ASYNC)
3626 portp = brdp->ports[portnr];
3630 portp->addr = readl(&memp->offset);
3631 portp->reqbit = (unsigned char) (0x1 << (i * 8 / nrdevs));
3632 portp->portidx = (unsigned char) (i / 8);
3633 portp->portbit = (unsigned char) (0x1 << (i % 8));
3636 writeb(0xff, &hdrp->slavereq);
3639 * For each port setup a local copy of the RX and TX buffer offsets
3640 * and sizes. We do this separate from the above, because we need to
3641 * move the shared memory page...
3643 for (i = 1, portnr = 0; (i < nrdevs); i++, portnr++) {
3644 portp = brdp->ports[portnr];
3647 if (portp->addr == 0)
3649 ap = (cdkasy_t __iomem *) EBRDGETMEMPTR(brdp, portp->addr);
3651 portp->rxsize = readw(&ap->rxq.size);
3652 portp->txsize = readw(&ap->txq.size);
3653 portp->rxoffset = readl(&ap->rxq.offset);
3654 portp->txoffset = readl(&ap->txq.offset);
3660 spin_unlock_irqrestore(&brd_lock, flags);
3663 brdp->state |= BST_STARTED;
3665 if (! stli_timeron) {
3667 stli_timerlist.expires = STLI_TIMEOUT;
3668 add_timer(&stli_timerlist);
3674 /*****************************************************************************/
3677 * Probe and initialize the specified board.
3680 static int __devinit stli_brdinit(struct stlibrd *brdp)
3682 switch (brdp->brdtype) {
3697 printk(KERN_ERR "STALLION: board=%d is unknown board "
3698 "type=%d\n", brdp->brdnr, brdp->brdtype);
3702 if ((brdp->state & BST_FOUND) == 0) {
3703 printk(KERN_ERR "STALLION: %s board not found, board=%d "
3705 stli_brdnames[brdp->brdtype], brdp->brdnr,
3706 brdp->iobase, (int) brdp->memaddr);
3710 stli_initports(brdp);
3711 printk(KERN_INFO "STALLION: %s found, board=%d io=%x mem=%x "
3712 "nrpanels=%d nrports=%d\n", stli_brdnames[brdp->brdtype],
3713 brdp->brdnr, brdp->iobase, (int) brdp->memaddr,
3714 brdp->nrpanels, brdp->nrports);
3718 #if STLI_EISAPROBE != 0
3719 /*****************************************************************************/
3722 * Probe around trying to find where the EISA boards shared memory
3723 * might be. This is a bit if hack, but it is the best we can do.
3726 static int stli_eisamemprobe(struct stlibrd *brdp)
3728 cdkecpsig_t ecpsig, __iomem *ecpsigp;
3729 cdkonbsig_t onbsig, __iomem *onbsigp;
3733 * First up we reset the board, to get it into a known state. There
3734 * is only 2 board types here we need to worry about. Don;t use the
3735 * standard board init routine here, it programs up the shared
3736 * memory address, and we don't know it yet...
3738 if (brdp->brdtype == BRD_ECPE) {
3739 outb(0x1, (brdp->iobase + ECP_EIBRDENAB));
3740 outb(ECP_EISTOP, (brdp->iobase + ECP_EICONFR));
3742 outb(ECP_EIDISABLE, (brdp->iobase + ECP_EICONFR));
3744 stli_ecpeienable(brdp);
3745 } else if (brdp->brdtype == BRD_ONBOARDE) {
3746 outb(0x1, (brdp->iobase + ONB_EIBRDENAB));
3747 outb(ONB_EISTOP, (brdp->iobase + ONB_EICONFR));
3749 outb(ONB_EIDISABLE, (brdp->iobase + ONB_EICONFR));
3751 outb(0x1, brdp->iobase);
3753 stli_onbeenable(brdp);
3759 brdp->memsize = ECP_MEMSIZE;
3762 * Board shared memory is enabled, so now we have a poke around and
3763 * see if we can find it.
3765 for (i = 0; (i < stli_eisamempsize); i++) {
3766 brdp->memaddr = stli_eisamemprobeaddrs[i];
3767 brdp->membase = ioremap(brdp->memaddr, brdp->memsize);
3768 if (brdp->membase == NULL)
3771 if (brdp->brdtype == BRD_ECPE) {
3772 ecpsigp = stli_ecpeigetmemptr(brdp,
3773 CDK_SIGADDR, __LINE__);
3774 memcpy_fromio(&ecpsig, ecpsigp, sizeof(cdkecpsig_t));
3775 if (ecpsig.magic == cpu_to_le32(ECP_MAGIC))
3778 onbsigp = (cdkonbsig_t __iomem *) stli_onbegetmemptr(brdp,
3779 CDK_SIGADDR, __LINE__);
3780 memcpy_fromio(&onbsig, onbsigp, sizeof(cdkonbsig_t));
3781 if ((onbsig.magic0 == cpu_to_le16(ONB_MAGIC0)) &&
3782 (onbsig.magic1 == cpu_to_le16(ONB_MAGIC1)) &&
3783 (onbsig.magic2 == cpu_to_le16(ONB_MAGIC2)) &&
3784 (onbsig.magic3 == cpu_to_le16(ONB_MAGIC3)))
3788 iounmap(brdp->membase);
3794 * Regardless of whether we found the shared memory or not we must
3795 * disable the region. After that return success or failure.
3797 if (brdp->brdtype == BRD_ECPE)
3798 stli_ecpeidisable(brdp);
3800 stli_onbedisable(brdp);
3804 brdp->membase = NULL;
3805 printk(KERN_ERR "STALLION: failed to probe shared memory "
3806 "region for %s in EISA slot=%d\n",
3807 stli_brdnames[brdp->brdtype], (brdp->iobase >> 12));
3814 static int stli_getbrdnr(void)
3818 for (i = 0; i < STL_MAXBRDS; i++) {
3819 if (!stli_brds[i]) {
3820 if (i >= stli_nrbrds)
3821 stli_nrbrds = i + 1;
3828 #if STLI_EISAPROBE != 0
3829 /*****************************************************************************/
3832 * Probe around and try to find any EISA boards in system. The biggest
3833 * problem here is finding out what memory address is associated with
3834 * an EISA board after it is found. The registers of the ECPE and
3835 * ONboardE are not readable - so we can't read them from there. We
3836 * don't have access to the EISA CMOS (or EISA BIOS) so we don't
3837 * actually have any way to find out the real value. The best we can
3838 * do is go probing around in the usual places hoping we can find it.
3841 static int stli_findeisabrds(void)
3843 struct stlibrd *brdp;
3844 unsigned int iobase, eid, i;
3848 * Firstly check if this is an EISA system. If this is not an EISA system then
3849 * don't bother going any further!
3855 * Looks like an EISA system, so go searching for EISA boards.
3857 for (iobase = 0x1000; (iobase <= 0xc000); iobase += 0x1000) {
3858 outb(0xff, (iobase + 0xc80));
3859 eid = inb(iobase + 0xc80);
3860 eid |= inb(iobase + 0xc81) << 8;
3861 if (eid != STL_EISAID)
3865 * We have found a board. Need to check if this board was
3866 * statically configured already (just in case!).
3868 for (i = 0; (i < STL_MAXBRDS); i++) {
3869 brdp = stli_brds[i];
3872 if (brdp->iobase == iobase)
3875 if (i < STL_MAXBRDS)
3879 * We have found a Stallion board and it is not configured already.
3880 * Allocate a board structure and initialize it.
3882 if ((brdp = stli_allocbrd()) == NULL)
3884 brdnr = stli_getbrdnr();
3887 brdp->brdnr = (unsigned int)brdnr;
3888 eid = inb(iobase + 0xc82);
3889 if (eid == ECP_EISAID)
3890 brdp->brdtype = BRD_ECPE;
3891 else if (eid == ONB_EISAID)
3892 brdp->brdtype = BRD_ONBOARDE;
3894 brdp->brdtype = BRD_UNKNOWN;
3895 brdp->iobase = iobase;
3896 outb(0x1, (iobase + 0xc84));
3897 if (stli_eisamemprobe(brdp))
3898 outb(0, (iobase + 0xc84));
3899 stli_brds[brdp->brdnr] = brdp;
3906 static inline int stli_findeisabrds(void) { return 0; }
3909 /*****************************************************************************/
3912 * Find the next available board number that is free.
3915 /*****************************************************************************/
3918 * We have a Stallion board. Allocate a board structure and
3919 * initialize it. Read its IO and MEMORY resources from PCI
3920 * configuration space.
3923 static int __devinit stli_pciprobe(struct pci_dev *pdev,
3924 const struct pci_device_id *ent)
3926 struct stlibrd *brdp;
3927 int brdnr, retval = -EIO;
3929 retval = pci_enable_device(pdev);
3932 brdp = stli_allocbrd();
3937 mutex_lock(&stli_brdslock);
3938 brdnr = stli_getbrdnr();
3940 printk(KERN_INFO "STALLION: too many boards found, "
3941 "maximum supported %d\n", STL_MAXBRDS);
3942 mutex_unlock(&stli_brdslock);
3946 brdp->brdnr = (unsigned int)brdnr;
3947 stli_brds[brdp->brdnr] = brdp;
3948 mutex_unlock(&stli_brdslock);
3949 brdp->brdtype = BRD_ECPPCI;
3951 * We have all resources from the board, so lets setup the actual
3952 * board structure now.
3954 brdp->iobase = pci_resource_start(pdev, 3);
3955 brdp->memaddr = pci_resource_start(pdev, 2);
3956 retval = stli_brdinit(brdp);
3960 brdp->state |= BST_PROBED;
3961 pci_set_drvdata(pdev, brdp);
3965 stli_brds[brdp->brdnr] = NULL;
3972 static void stli_pciremove(struct pci_dev *pdev)
3974 struct stlibrd *brdp = pci_get_drvdata(pdev);
3976 stli_cleanup_ports(brdp);
3978 iounmap(brdp->membase);
3979 if (brdp->iosize > 0)
3980 release_region(brdp->iobase, brdp->iosize);
3982 stli_brds[brdp->brdnr] = NULL;
3986 static struct pci_driver stli_pcidriver = {
3987 .name = "istallion",
3988 .id_table = istallion_pci_tbl,
3989 .probe = stli_pciprobe,
3990 .remove = __devexit_p(stli_pciremove)
3992 /*****************************************************************************/
3995 * Allocate a new board structure. Fill out the basic info in it.
3998 static struct stlibrd *stli_allocbrd(void)
4000 struct stlibrd *brdp;
4002 brdp = kzalloc(sizeof(struct stlibrd), GFP_KERNEL);
4004 printk(KERN_ERR "STALLION: failed to allocate memory "
4005 "(size=%Zd)\n", sizeof(struct stlibrd));
4008 brdp->magic = STLI_BOARDMAGIC;
4012 /*****************************************************************************/
4015 * Scan through all the boards in the configuration and see what we
4019 static int stli_initbrds(void)
4021 struct stlibrd *brdp, *nxtbrdp;
4022 struct stlconf conf;
4026 for (stli_nrbrds = 0; stli_nrbrds < ARRAY_SIZE(stli_brdsp);
4028 memset(&conf, 0, sizeof(conf));
4029 if (stli_parsebrd(&conf, stli_brdsp[stli_nrbrds]) == 0)
4031 if ((brdp = stli_allocbrd()) == NULL)
4033 brdp->brdnr = stli_nrbrds;
4034 brdp->brdtype = conf.brdtype;
4035 brdp->iobase = conf.ioaddr1;
4036 brdp->memaddr = conf.memaddr;
4037 stli_brds[brdp->brdnr] = brdp;
4041 stli_findeisabrds();
4043 retval = pci_register_driver(&stli_pcidriver);
4044 /* TODO: check retval and do something */
4047 * All found boards are initialized. Now for a little optimization, if
4048 * no boards are sharing the "shared memory" regions then we can just
4049 * leave them all enabled. This is in fact the usual case.
4052 if (stli_nrbrds > 1) {
4053 for (i = 0; (i < stli_nrbrds); i++) {
4054 brdp = stli_brds[i];
4057 for (j = i + 1; (j < stli_nrbrds); j++) {
4058 nxtbrdp = stli_brds[j];
4059 if (nxtbrdp == NULL)
4061 if ((brdp->membase >= nxtbrdp->membase) &&
4062 (brdp->membase <= (nxtbrdp->membase +
4063 nxtbrdp->memsize - 1))) {
4071 if (stli_shared == 0) {
4072 for (i = 0; (i < stli_nrbrds); i++) {
4073 brdp = stli_brds[i];
4076 if (brdp->state & BST_FOUND) {
4078 brdp->enable = NULL;
4079 brdp->disable = NULL;
4087 /*****************************************************************************/
4090 * Code to handle an "staliomem" read operation. This device is the
4091 * contents of the board shared memory. It is used for down loading
4092 * the slave image (and debugging :-)
4095 static ssize_t stli_memread(struct file *fp, char __user *buf, size_t count, loff_t *offp)
4097 unsigned long flags;
4098 void __iomem *memptr;
4099 struct stlibrd *brdp;
4105 brdnr = iminor(fp->f_path.dentry->d_inode);
4106 if (brdnr >= stli_nrbrds)
4108 brdp = stli_brds[brdnr];
4111 if (brdp->state == 0)
4113 if (off >= brdp->memsize || off + count < off)
4116 size = min(count, (size_t)(brdp->memsize - off));
4119 * Copy the data a page at a time
4122 p = (void *)__get_free_page(GFP_KERNEL);
4127 spin_lock_irqsave(&brd_lock, flags);
4129 memptr = EBRDGETMEMPTR(brdp, off);
4130 n = min(size, (int)(brdp->pagesize - (((unsigned long) off) % brdp->pagesize)));
4131 n = min(n, (int)PAGE_SIZE);
4132 memcpy_fromio(p, memptr, n);
4134 spin_unlock_irqrestore(&brd_lock, flags);
4135 if (copy_to_user(buf, p, n)) {
4145 free_page((unsigned long)p);
4149 /*****************************************************************************/
4152 * Code to handle an "staliomem" write operation. This device is the
4153 * contents of the board shared memory. It is used for down loading
4154 * the slave image (and debugging :-)
4156 * FIXME: copy under lock
4159 static ssize_t stli_memwrite(struct file *fp, const char __user *buf, size_t count, loff_t *offp)
4161 unsigned long flags;
4162 void __iomem *memptr;
4163 struct stlibrd *brdp;
4170 brdnr = iminor(fp->f_path.dentry->d_inode);
4172 if (brdnr >= stli_nrbrds)
4174 brdp = stli_brds[brdnr];
4177 if (brdp->state == 0)
4179 if (off >= brdp->memsize || off + count < off)
4182 chbuf = (char __user *) buf;
4183 size = min(count, (size_t)(brdp->memsize - off));
4186 * Copy the data a page at a time
4189 p = (void *)__get_free_page(GFP_KERNEL);
4194 n = min(size, (int)(brdp->pagesize - (((unsigned long) off) % brdp->pagesize)));
4195 n = min(n, (int)PAGE_SIZE);
4196 if (copy_from_user(p, chbuf, n)) {
4201 spin_lock_irqsave(&brd_lock, flags);
4203 memptr = EBRDGETMEMPTR(brdp, off);
4204 memcpy_toio(memptr, p, n);
4206 spin_unlock_irqrestore(&brd_lock, flags);
4212 free_page((unsigned long) p);
4217 /*****************************************************************************/
4220 * Return the board stats structure to user app.
4223 static int stli_getbrdstats(combrd_t __user *bp)
4225 struct stlibrd *brdp;
4228 if (copy_from_user(&stli_brdstats, bp, sizeof(combrd_t)))
4230 if (stli_brdstats.brd >= STL_MAXBRDS)
4232 brdp = stli_brds[stli_brdstats.brd];
4236 memset(&stli_brdstats, 0, sizeof(combrd_t));
4237 stli_brdstats.brd = brdp->brdnr;
4238 stli_brdstats.type = brdp->brdtype;
4239 stli_brdstats.hwid = 0;
4240 stli_brdstats.state = brdp->state;
4241 stli_brdstats.ioaddr = brdp->iobase;
4242 stli_brdstats.memaddr = brdp->memaddr;
4243 stli_brdstats.nrpanels = brdp->nrpanels;
4244 stli_brdstats.nrports = brdp->nrports;
4245 for (i = 0; (i < brdp->nrpanels); i++) {
4246 stli_brdstats.panels[i].panel = i;
4247 stli_brdstats.panels[i].hwid = brdp->panelids[i];
4248 stli_brdstats.panels[i].nrports = brdp->panels[i];
4251 if (copy_to_user(bp, &stli_brdstats, sizeof(combrd_t)))
4256 /*****************************************************************************/
4259 * Resolve the referenced port number into a port struct pointer.
4262 static struct stliport *stli_getport(unsigned int brdnr, unsigned int panelnr,
4263 unsigned int portnr)
4265 struct stlibrd *brdp;
4268 if (brdnr >= STL_MAXBRDS)
4270 brdp = stli_brds[brdnr];
4273 for (i = 0; (i < panelnr); i++)
4274 portnr += brdp->panels[i];
4275 if (portnr >= brdp->nrports)
4277 return brdp->ports[portnr];
4280 /*****************************************************************************/
4283 * Return the port stats structure to user app. A NULL port struct
4284 * pointer passed in means that we need to find out from the app
4285 * what port to get stats for (used through board control device).
4288 static int stli_portcmdstats(struct stliport *portp)
4290 unsigned long flags;
4291 struct stlibrd *brdp;
4294 memset(&stli_comstats, 0, sizeof(comstats_t));
4298 brdp = stli_brds[portp->brdnr];
4302 if (brdp->state & BST_STARTED) {
4303 if ((rc = stli_cmdwait(brdp, portp, A_GETSTATS,
4304 &stli_cdkstats, sizeof(asystats_t), 1)) < 0)
4307 memset(&stli_cdkstats, 0, sizeof(asystats_t));
4310 stli_comstats.brd = portp->brdnr;
4311 stli_comstats.panel = portp->panelnr;
4312 stli_comstats.port = portp->portnr;
4313 stli_comstats.state = portp->state;
4314 stli_comstats.flags = portp->flags;
4316 spin_lock_irqsave(&brd_lock, flags);
4317 if (portp->tty != NULL) {
4318 if (portp->tty->driver_data == portp) {
4319 stli_comstats.ttystate = portp->tty->flags;
4320 stli_comstats.rxbuffered = -1;
4321 if (portp->tty->termios != NULL) {
4322 stli_comstats.cflags = portp->tty->termios->c_cflag;
4323 stli_comstats.iflags = portp->tty->termios->c_iflag;
4324 stli_comstats.oflags = portp->tty->termios->c_oflag;
4325 stli_comstats.lflags = portp->tty->termios->c_lflag;
4329 spin_unlock_irqrestore(&brd_lock, flags);
4331 stli_comstats.txtotal = stli_cdkstats.txchars;
4332 stli_comstats.rxtotal = stli_cdkstats.rxchars + stli_cdkstats.ringover;
4333 stli_comstats.txbuffered = stli_cdkstats.txringq;
4334 stli_comstats.rxbuffered += stli_cdkstats.rxringq;
4335 stli_comstats.rxoverrun = stli_cdkstats.overruns;
4336 stli_comstats.rxparity = stli_cdkstats.parity;
4337 stli_comstats.rxframing = stli_cdkstats.framing;
4338 stli_comstats.rxlost = stli_cdkstats.ringover;
4339 stli_comstats.rxbreaks = stli_cdkstats.rxbreaks;
4340 stli_comstats.txbreaks = stli_cdkstats.txbreaks;
4341 stli_comstats.txxon = stli_cdkstats.txstart;
4342 stli_comstats.txxoff = stli_cdkstats.txstop;
4343 stli_comstats.rxxon = stli_cdkstats.rxstart;
4344 stli_comstats.rxxoff = stli_cdkstats.rxstop;
4345 stli_comstats.rxrtsoff = stli_cdkstats.rtscnt / 2;
4346 stli_comstats.rxrtson = stli_cdkstats.rtscnt - stli_comstats.rxrtsoff;
4347 stli_comstats.modem = stli_cdkstats.dcdcnt;
4348 stli_comstats.hwid = stli_cdkstats.hwid;
4349 stli_comstats.signals = stli_mktiocm(stli_cdkstats.signals);
4354 /*****************************************************************************/
4357 * Return the port stats structure to user app. A NULL port struct
4358 * pointer passed in means that we need to find out from the app
4359 * what port to get stats for (used through board control device).
4362 static int stli_getportstats(struct stliport *portp, comstats_t __user *cp)
4364 struct stlibrd *brdp;
4368 if (copy_from_user(&stli_comstats, cp, sizeof(comstats_t)))
4370 portp = stli_getport(stli_comstats.brd, stli_comstats.panel,
4371 stli_comstats.port);
4376 brdp = stli_brds[portp->brdnr];
4380 if ((rc = stli_portcmdstats(portp)) < 0)
4383 return copy_to_user(cp, &stli_comstats, sizeof(comstats_t)) ?
4387 /*****************************************************************************/
4390 * Clear the port stats structure. We also return it zeroed out...
4393 static int stli_clrportstats(struct stliport *portp, comstats_t __user *cp)
4395 struct stlibrd *brdp;
4399 if (copy_from_user(&stli_comstats, cp, sizeof(comstats_t)))
4401 portp = stli_getport(stli_comstats.brd, stli_comstats.panel,
4402 stli_comstats.port);
4407 brdp = stli_brds[portp->brdnr];
4411 if (brdp->state & BST_STARTED) {
4412 if ((rc = stli_cmdwait(brdp, portp, A_CLEARSTATS, NULL, 0, 0)) < 0)
4416 memset(&stli_comstats, 0, sizeof(comstats_t));
4417 stli_comstats.brd = portp->brdnr;
4418 stli_comstats.panel = portp->panelnr;
4419 stli_comstats.port = portp->portnr;
4421 if (copy_to_user(cp, &stli_comstats, sizeof(comstats_t)))
4426 /*****************************************************************************/
4429 * Return the entire driver ports structure to a user app.
4432 static int stli_getportstruct(struct stliport __user *arg)
4434 struct stliport stli_dummyport;
4435 struct stliport *portp;
4437 if (copy_from_user(&stli_dummyport, arg, sizeof(struct stliport)))
4439 portp = stli_getport(stli_dummyport.brdnr, stli_dummyport.panelnr,
4440 stli_dummyport.portnr);
4443 if (copy_to_user(arg, portp, sizeof(struct stliport)))
4448 /*****************************************************************************/
4451 * Return the entire driver board structure to a user app.
4454 static int stli_getbrdstruct(struct stlibrd __user *arg)
4456 struct stlibrd stli_dummybrd;
4457 struct stlibrd *brdp;
4459 if (copy_from_user(&stli_dummybrd, arg, sizeof(struct stlibrd)))
4461 if (stli_dummybrd.brdnr >= STL_MAXBRDS)
4463 brdp = stli_brds[stli_dummybrd.brdnr];
4466 if (copy_to_user(arg, brdp, sizeof(struct stlibrd)))
4471 /*****************************************************************************/
4474 * The "staliomem" device is also required to do some special operations on
4475 * the board. We need to be able to send an interrupt to the board,
4476 * reset it, and start/stop it.
4479 static int stli_memioctl(struct inode *ip, struct file *fp, unsigned int cmd, unsigned long arg)
4481 struct stlibrd *brdp;
4482 int brdnr, rc, done;
4483 void __user *argp = (void __user *)arg;
4486 * First up handle the board independent ioctls.
4492 case COM_GETPORTSTATS:
4493 rc = stli_getportstats(NULL, argp);
4496 case COM_CLRPORTSTATS:
4497 rc = stli_clrportstats(NULL, argp);
4500 case COM_GETBRDSTATS:
4501 rc = stli_getbrdstats(argp);
4505 rc = stli_getportstruct(argp);
4509 rc = stli_getbrdstruct(argp);
4518 * Now handle the board specific ioctls. These all depend on the
4519 * minor number of the device they were called from.
4522 if (brdnr >= STL_MAXBRDS)
4524 brdp = stli_brds[brdnr];
4527 if (brdp->state == 0)
4535 rc = stli_startbrd(brdp);
4538 brdp->state &= ~BST_STARTED;
4541 brdp->state &= ~BST_STARTED;
4543 if (stli_shared == 0) {
4544 if (brdp->reenable != NULL)
4545 (* brdp->reenable)(brdp);
4555 static const struct tty_operations stli_ops = {
4557 .close = stli_close,
4558 .write = stli_write,
4559 .put_char = stli_putchar,
4560 .flush_chars = stli_flushchars,
4561 .write_room = stli_writeroom,
4562 .chars_in_buffer = stli_charsinbuffer,
4563 .ioctl = stli_ioctl,
4564 .set_termios = stli_settermios,
4565 .throttle = stli_throttle,
4566 .unthrottle = stli_unthrottle,
4568 .start = stli_start,
4569 .hangup = stli_hangup,
4570 .flush_buffer = stli_flushbuffer,
4571 .break_ctl = stli_breakctl,
4572 .wait_until_sent = stli_waituntilsent,
4573 .send_xchar = stli_sendxchar,
4574 .read_proc = stli_readproc,
4575 .tiocmget = stli_tiocmget,
4576 .tiocmset = stli_tiocmset,
4579 /*****************************************************************************/
4581 static int __init stli_init(void)
4584 printk(KERN_INFO "%s: version %s\n", stli_drvtitle, stli_drvversion);
4586 spin_lock_init(&stli_lock);
4587 spin_lock_init(&brd_lock);
4591 stli_serial = alloc_tty_driver(STL_MAXBRDS * STL_MAXPORTS);
4596 * Allocate a temporary write buffer.
4598 stli_txcookbuf = kmalloc(STLI_TXBUFSIZE, GFP_KERNEL);
4599 if (!stli_txcookbuf)
4600 printk(KERN_ERR "STALLION: failed to allocate memory "
4601 "(size=%d)\n", STLI_TXBUFSIZE);
4604 * Set up a character driver for the shared memory region. We need this
4605 * to down load the slave code image. Also it is a useful debugging tool.
4607 if (register_chrdev(STL_SIOMEMMAJOR, "staliomem", &stli_fsiomem))
4608 printk(KERN_ERR "STALLION: failed to register serial memory "
4611 istallion_class = class_create(THIS_MODULE, "staliomem");
4612 for (i = 0; i < 4; i++)
4613 class_device_create(istallion_class, NULL,
4614 MKDEV(STL_SIOMEMMAJOR, i),
4615 NULL, "staliomem%d", i);
4618 * Set up the tty driver structure and register us as a driver.
4620 stli_serial->owner = THIS_MODULE;
4621 stli_serial->driver_name = stli_drvname;
4622 stli_serial->name = stli_serialname;
4623 stli_serial->major = STL_SERIALMAJOR;
4624 stli_serial->minor_start = 0;
4625 stli_serial->type = TTY_DRIVER_TYPE_SERIAL;
4626 stli_serial->subtype = SERIAL_TYPE_NORMAL;
4627 stli_serial->init_termios = stli_deftermios;
4628 stli_serial->flags = TTY_DRIVER_REAL_RAW;
4629 tty_set_operations(stli_serial, &stli_ops);
4631 if (tty_register_driver(stli_serial)) {
4632 put_tty_driver(stli_serial);
4633 printk(KERN_ERR "STALLION: failed to register serial driver\n");
4639 /*****************************************************************************/