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 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 asystats_t stli_cdkstats;
189 static stlibrd_t stli_dummybrd;
190 static stliport_t stli_dummyport;
192 /*****************************************************************************/
194 static stlibrd_t *stli_brds[STL_MAXBRDS];
196 static int stli_shared;
199 * Per board state flags. Used with the state field of the board struct.
200 * Not really much here... All we need to do is keep track of whether
201 * the board has been detected, and whether it is actually running a slave
204 #define BST_FOUND 0x1
205 #define BST_STARTED 0x2
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 typedef struct stlibrdtype {
292 static stlibrdtype_t stli_brdstr[] = {
293 { "stallion", BRD_STALLION },
294 { "1", BRD_STALLION },
295 { "brumby", BRD_BRUMBY },
296 { "brumby4", BRD_BRUMBY },
297 { "brumby/4", BRD_BRUMBY },
298 { "brumby-4", BRD_BRUMBY },
299 { "brumby8", BRD_BRUMBY },
300 { "brumby/8", BRD_BRUMBY },
301 { "brumby-8", BRD_BRUMBY },
302 { "brumby16", BRD_BRUMBY },
303 { "brumby/16", BRD_BRUMBY },
304 { "brumby-16", BRD_BRUMBY },
306 { "onboard2", BRD_ONBOARD2 },
307 { "onboard-2", BRD_ONBOARD2 },
308 { "onboard/2", BRD_ONBOARD2 },
309 { "onboard-mc", BRD_ONBOARD2 },
310 { "onboard/mc", BRD_ONBOARD2 },
311 { "onboard-mca", BRD_ONBOARD2 },
312 { "onboard/mca", BRD_ONBOARD2 },
313 { "3", BRD_ONBOARD2 },
314 { "onboard", BRD_ONBOARD },
315 { "onboardat", BRD_ONBOARD },
316 { "4", BRD_ONBOARD },
317 { "onboarde", BRD_ONBOARDE },
318 { "onboard-e", BRD_ONBOARDE },
319 { "onboard/e", BRD_ONBOARDE },
320 { "onboard-ei", BRD_ONBOARDE },
321 { "onboard/ei", BRD_ONBOARDE },
322 { "7", BRD_ONBOARDE },
324 { "ecpat", BRD_ECP },
325 { "ec8/64", BRD_ECP },
326 { "ec8/64-at", BRD_ECP },
327 { "ec8/64-isa", BRD_ECP },
329 { "ecpe", BRD_ECPE },
330 { "ecpei", BRD_ECPE },
331 { "ec8/64-e", BRD_ECPE },
332 { "ec8/64-ei", BRD_ECPE },
334 { "ecpmc", BRD_ECPMC },
335 { "ec8/64-mc", BRD_ECPMC },
336 { "ec8/64-mca", BRD_ECPMC },
338 { "ecppci", BRD_ECPPCI },
339 { "ec/ra", BRD_ECPPCI },
340 { "ec/ra-pc", BRD_ECPPCI },
341 { "ec/ra-pci", BRD_ECPPCI },
342 { "29", BRD_ECPPCI },
346 * Define the module agruments.
348 MODULE_AUTHOR("Greg Ungerer");
349 MODULE_DESCRIPTION("Stallion Intelligent Multiport Serial Driver");
350 MODULE_LICENSE("GPL");
353 module_param_array(board0, charp, NULL, 0);
354 MODULE_PARM_DESC(board0, "Board 0 config -> name[,ioaddr[,memaddr]");
355 module_param_array(board1, charp, NULL, 0);
356 MODULE_PARM_DESC(board1, "Board 1 config -> name[,ioaddr[,memaddr]");
357 module_param_array(board2, charp, NULL, 0);
358 MODULE_PARM_DESC(board2, "Board 2 config -> name[,ioaddr[,memaddr]");
359 module_param_array(board3, charp, NULL, 0);
360 MODULE_PARM_DESC(board3, "Board 3 config -> name[,ioaddr[,memaddr]");
363 * Set up a default memory address table for EISA board probing.
364 * The default addresses are all bellow 1Mbyte, which has to be the
365 * case anyway. They should be safe, since we only read values from
366 * them, and interrupts are disabled while we do it. If the higher
367 * memory support is compiled in then we also try probing around
368 * the 1Gb, 2Gb and 3Gb areas as well...
370 static unsigned long stli_eisamemprobeaddrs[] = {
371 0xc0000, 0xd0000, 0xe0000, 0xf0000,
372 0x80000000, 0x80010000, 0x80020000, 0x80030000,
373 0x40000000, 0x40010000, 0x40020000, 0x40030000,
374 0xc0000000, 0xc0010000, 0xc0020000, 0xc0030000,
375 0xff000000, 0xff010000, 0xff020000, 0xff030000,
378 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(stlconf_t *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(stlibrd_t *brdp, stliport_t *portp, int portnr, char *pos);
619 static int stli_brdinit(stlibrd_t *brdp);
620 static int stli_startbrd(stlibrd_t *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(stlibrd_t *brdp, cdkhdr_t __iomem *hdrp);
625 static void stli_poll(unsigned long arg);
626 static int stli_hostcmd(stlibrd_t *brdp, stliport_t *portp);
627 static int stli_initopen(stlibrd_t *brdp, stliport_t *portp);
628 static int stli_rawopen(stlibrd_t *brdp, stliport_t *portp, unsigned long arg, int wait);
629 static int stli_rawclose(stlibrd_t *brdp, stliport_t *portp, unsigned long arg, int wait);
630 static int stli_waitcarrier(stlibrd_t *brdp, stliport_t *portp, struct file *filp);
631 static void stli_dohangup(struct work_struct *);
632 static int stli_setport(stliport_t *portp);
633 static int stli_cmdwait(stlibrd_t *brdp, stliport_t *portp, unsigned long cmd, void *arg, int size, int copyback);
634 static void stli_sendcmd(stlibrd_t *brdp, stliport_t *portp, unsigned long cmd, void *arg, int size, int copyback);
635 static void __stli_sendcmd(stlibrd_t *brdp, stliport_t *portp, unsigned long cmd, void *arg, int size, int copyback);
636 static void stli_dodelaycmd(stliport_t *portp, cdkctrl_t __iomem *cp);
637 static void stli_mkasyport(stliport_t *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(stlibrd_t *brdp, stliport_t *portp);
641 static int stli_getserial(stliport_t *portp, struct serial_struct __user *sp);
642 static int stli_setserial(stliport_t *portp, struct serial_struct __user *sp);
643 static int stli_getbrdstats(combrd_t __user *bp);
644 static int stli_getportstats(stliport_t *portp, comstats_t __user *cp);
645 static int stli_portcmdstats(stliport_t *portp);
646 static int stli_clrportstats(stliport_t *portp, comstats_t __user *cp);
647 static int stli_getportstruct(stliport_t __user *arg);
648 static int stli_getbrdstruct(stlibrd_t __user *arg);
649 static stlibrd_t *stli_allocbrd(void);
651 static void stli_ecpinit(stlibrd_t *brdp);
652 static void stli_ecpenable(stlibrd_t *brdp);
653 static void stli_ecpdisable(stlibrd_t *brdp);
654 static void __iomem *stli_ecpgetmemptr(stlibrd_t *brdp, unsigned long offset, int line);
655 static void stli_ecpreset(stlibrd_t *brdp);
656 static void stli_ecpintr(stlibrd_t *brdp);
657 static void stli_ecpeiinit(stlibrd_t *brdp);
658 static void stli_ecpeienable(stlibrd_t *brdp);
659 static void stli_ecpeidisable(stlibrd_t *brdp);
660 static void __iomem *stli_ecpeigetmemptr(stlibrd_t *brdp, unsigned long offset, int line);
661 static void stli_ecpeireset(stlibrd_t *brdp);
662 static void stli_ecpmcenable(stlibrd_t *brdp);
663 static void stli_ecpmcdisable(stlibrd_t *brdp);
664 static void __iomem *stli_ecpmcgetmemptr(stlibrd_t *brdp, unsigned long offset, int line);
665 static void stli_ecpmcreset(stlibrd_t *brdp);
666 static void stli_ecppciinit(stlibrd_t *brdp);
667 static void __iomem *stli_ecppcigetmemptr(stlibrd_t *brdp, unsigned long offset, int line);
668 static void stli_ecppcireset(stlibrd_t *brdp);
670 static void stli_onbinit(stlibrd_t *brdp);
671 static void stli_onbenable(stlibrd_t *brdp);
672 static void stli_onbdisable(stlibrd_t *brdp);
673 static void __iomem *stli_onbgetmemptr(stlibrd_t *brdp, unsigned long offset, int line);
674 static void stli_onbreset(stlibrd_t *brdp);
675 static void stli_onbeinit(stlibrd_t *brdp);
676 static void stli_onbeenable(stlibrd_t *brdp);
677 static void stli_onbedisable(stlibrd_t *brdp);
678 static void __iomem *stli_onbegetmemptr(stlibrd_t *brdp, unsigned long offset, int line);
679 static void stli_onbereset(stlibrd_t *brdp);
680 static void stli_bbyinit(stlibrd_t *brdp);
681 static void __iomem *stli_bbygetmemptr(stlibrd_t *brdp, unsigned long offset, int line);
682 static void stli_bbyreset(stlibrd_t *brdp);
683 static void stli_stalinit(stlibrd_t *brdp);
684 static void __iomem *stli_stalgetmemptr(stlibrd_t *brdp, unsigned long offset, int line);
685 static void stli_stalreset(stlibrd_t *brdp);
687 static stliport_t *stli_getport(int brdnr, int panelnr, int portnr);
689 static int stli_initecp(stlibrd_t *brdp);
690 static int stli_initonb(stlibrd_t *brdp);
691 static int stli_eisamemprobe(stlibrd_t *brdp);
692 static int stli_initports(stlibrd_t *brdp);
694 /*****************************************************************************/
697 * Define the driver info for a user level shared memory device. This
698 * device will work sort of like the /dev/kmem device - except that it
699 * will give access to the shared memory on the Stallion intelligent
700 * board. This is also a very useful debugging tool.
702 static const struct file_operations stli_fsiomem = {
703 .owner = THIS_MODULE,
704 .read = stli_memread,
705 .write = stli_memwrite,
706 .ioctl = stli_memioctl,
709 /*****************************************************************************/
712 * Define a timer_list entry for our poll routine. The slave board
713 * is polled every so often to see if anything needs doing. This is
714 * much cheaper on host cpu than using interrupts. It turns out to
715 * not increase character latency by much either...
717 static DEFINE_TIMER(stli_timerlist, stli_poll, 0, 0);
719 static int stli_timeron;
722 * Define the calculation for the timeout routine.
724 #define STLI_TIMEOUT (jiffies + 1)
726 /*****************************************************************************/
728 static struct class *istallion_class;
730 static void stli_cleanup_ports(stlibrd_t *brdp)
735 for (j = 0; j < STL_MAXPORTS; j++) {
736 portp = brdp->ports[j];
738 if (portp->tty != NULL)
739 tty_hangup(portp->tty);
746 * Loadable module initialization stuff.
749 static int __init istallion_module_init(void)
755 /*****************************************************************************/
757 static void __exit istallion_module_exit(void)
762 printk(KERN_INFO "Unloading %s: version %s\n", stli_drvtitle,
765 pci_unregister_driver(&stli_pcidriver);
767 * Free up all allocated resources used by the ports. This includes
768 * memory and interrupts.
772 del_timer_sync(&stli_timerlist);
775 i = tty_unregister_driver(stli_serial);
777 printk("STALLION: failed to un-register tty driver, "
781 put_tty_driver(stli_serial);
782 for (i = 0; i < 4; i++)
783 class_device_destroy(istallion_class, MKDEV(STL_SIOMEMMAJOR, i));
784 class_destroy(istallion_class);
785 if ((i = unregister_chrdev(STL_SIOMEMMAJOR, "staliomem")))
786 printk("STALLION: failed to un-register serial memory device, "
789 kfree(stli_txcookbuf);
791 for (i = 0; (i < stli_nrbrds); i++) {
792 if ((brdp = stli_brds[i]) == NULL)
795 stli_cleanup_ports(brdp);
797 iounmap(brdp->membase);
798 if (brdp->iosize > 0)
799 release_region(brdp->iobase, brdp->iosize);
805 module_init(istallion_module_init);
806 module_exit(istallion_module_exit);
808 /*****************************************************************************/
811 * Parse the supplied argument string, into the board conf struct.
814 static int stli_parsebrd(stlconf_t *confp, char **argp)
819 if (argp[0] == NULL || *argp[0] == 0)
822 for (sp = argp[0], i = 0; ((*sp != 0) && (i < 25)); sp++, i++)
825 for (i = 0; i < ARRAY_SIZE(stli_brdstr); i++) {
826 if (strcmp(stli_brdstr[i].name, argp[0]) == 0)
829 if (i == ARRAY_SIZE(stli_brdstr)) {
830 printk("STALLION: unknown board name, %s?\n", argp[0]);
834 confp->brdtype = stli_brdstr[i].type;
835 if (argp[1] != NULL && *argp[1] != 0)
836 confp->ioaddr1 = simple_strtoul(argp[1], NULL, 0);
837 if (argp[2] != NULL && *argp[2] != 0)
838 confp->memaddr = simple_strtoul(argp[2], NULL, 0);
842 /*****************************************************************************/
844 static int stli_open(struct tty_struct *tty, struct file *filp)
848 unsigned int minordev;
849 int brdnr, portnr, rc;
851 minordev = tty->index;
852 brdnr = MINOR2BRD(minordev);
853 if (brdnr >= stli_nrbrds)
855 brdp = stli_brds[brdnr];
858 if ((brdp->state & BST_STARTED) == 0)
860 portnr = MINOR2PORT(minordev);
861 if ((portnr < 0) || (portnr > brdp->nrports))
864 portp = brdp->ports[portnr];
867 if (portp->devnr < 1)
872 * Check if this port is in the middle of closing. If so then wait
873 * until it is closed then return error status based on flag settings.
874 * The sleep here does not need interrupt protection since the wakeup
875 * for it is done with the same context.
877 if (portp->flags & ASYNC_CLOSING) {
878 interruptible_sleep_on(&portp->close_wait);
879 if (portp->flags & ASYNC_HUP_NOTIFY)
885 * On the first open of the device setup the port hardware, and
886 * initialize the per port data structure. Since initializing the port
887 * requires several commands to the board we will need to wait for any
888 * other open that is already initializing the port.
891 tty->driver_data = portp;
894 wait_event_interruptible(portp->raw_wait,
895 !test_bit(ST_INITIALIZING, &portp->state));
896 if (signal_pending(current))
899 if ((portp->flags & ASYNC_INITIALIZED) == 0) {
900 set_bit(ST_INITIALIZING, &portp->state);
901 if ((rc = stli_initopen(brdp, portp)) >= 0) {
902 portp->flags |= ASYNC_INITIALIZED;
903 clear_bit(TTY_IO_ERROR, &tty->flags);
905 clear_bit(ST_INITIALIZING, &portp->state);
906 wake_up_interruptible(&portp->raw_wait);
912 * Check if this port is in the middle of closing. If so then wait
913 * until it is closed then return error status, based on flag settings.
914 * The sleep here does not need interrupt protection since the wakeup
915 * for it is done with the same context.
917 if (portp->flags & ASYNC_CLOSING) {
918 interruptible_sleep_on(&portp->close_wait);
919 if (portp->flags & ASYNC_HUP_NOTIFY)
925 * Based on type of open being done check if it can overlap with any
926 * previous opens still in effect. If we are a normal serial device
927 * then also we might have to wait for carrier.
929 if (!(filp->f_flags & O_NONBLOCK)) {
930 if ((rc = stli_waitcarrier(brdp, portp, filp)) != 0)
933 portp->flags |= ASYNC_NORMAL_ACTIVE;
937 /*****************************************************************************/
939 static void stli_close(struct tty_struct *tty, struct file *filp)
945 portp = tty->driver_data;
949 spin_lock_irqsave(&stli_lock, flags);
950 if (tty_hung_up_p(filp)) {
951 spin_unlock_irqrestore(&stli_lock, flags);
954 if ((tty->count == 1) && (portp->refcount != 1))
956 if (portp->refcount-- > 1) {
957 spin_unlock_irqrestore(&stli_lock, flags);
961 portp->flags |= ASYNC_CLOSING;
964 * May want to wait for data to drain before closing. The BUSY flag
965 * keeps track of whether we are still transmitting or not. It is
966 * updated by messages from the slave - indicating when all chars
967 * really have drained.
969 if (tty == stli_txcooktty)
970 stli_flushchars(tty);
972 spin_unlock_irqrestore(&stli_lock, flags);
974 if (portp->closing_wait != ASYNC_CLOSING_WAIT_NONE)
975 tty_wait_until_sent(tty, portp->closing_wait);
977 portp->flags &= ~ASYNC_INITIALIZED;
978 brdp = stli_brds[portp->brdnr];
979 stli_rawclose(brdp, portp, 0, 0);
980 if (tty->termios->c_cflag & HUPCL) {
981 stli_mkasysigs(&portp->asig, 0, 0);
982 if (test_bit(ST_CMDING, &portp->state))
983 set_bit(ST_DOSIGS, &portp->state);
985 stli_sendcmd(brdp, portp, A_SETSIGNALS, &portp->asig,
986 sizeof(asysigs_t), 0);
988 clear_bit(ST_TXBUSY, &portp->state);
989 clear_bit(ST_RXSTOP, &portp->state);
990 set_bit(TTY_IO_ERROR, &tty->flags);
991 if (tty->ldisc.flush_buffer)
992 (tty->ldisc.flush_buffer)(tty);
993 set_bit(ST_DOFLUSHRX, &portp->state);
994 stli_flushbuffer(tty);
999 if (portp->openwaitcnt) {
1000 if (portp->close_delay)
1001 msleep_interruptible(jiffies_to_msecs(portp->close_delay));
1002 wake_up_interruptible(&portp->open_wait);
1005 portp->flags &= ~(ASYNC_NORMAL_ACTIVE|ASYNC_CLOSING);
1006 wake_up_interruptible(&portp->close_wait);
1009 /*****************************************************************************/
1012 * Carry out first open operations on a port. This involves a number of
1013 * commands to be sent to the slave. We need to open the port, set the
1014 * notification events, set the initial port settings, get and set the
1015 * initial signal values. We sleep and wait in between each one. But
1016 * this still all happens pretty quickly.
1019 static int stli_initopen(stlibrd_t *brdp, stliport_t *portp)
1021 struct tty_struct *tty;
1026 if ((rc = stli_rawopen(brdp, portp, 0, 1)) < 0)
1029 memset(&nt, 0, sizeof(asynotify_t));
1030 nt.data = (DT_TXLOW | DT_TXEMPTY | DT_RXBUSY | DT_RXBREAK);
1032 if ((rc = stli_cmdwait(brdp, portp, A_SETNOTIFY, &nt,
1033 sizeof(asynotify_t), 0)) < 0)
1039 stli_mkasyport(portp, &aport, tty->termios);
1040 if ((rc = stli_cmdwait(brdp, portp, A_SETPORT, &aport,
1041 sizeof(asyport_t), 0)) < 0)
1044 set_bit(ST_GETSIGS, &portp->state);
1045 if ((rc = stli_cmdwait(brdp, portp, A_GETSIGNALS, &portp->asig,
1046 sizeof(asysigs_t), 1)) < 0)
1048 if (test_and_clear_bit(ST_GETSIGS, &portp->state))
1049 portp->sigs = stli_mktiocm(portp->asig.sigvalue);
1050 stli_mkasysigs(&portp->asig, 1, 1);
1051 if ((rc = stli_cmdwait(brdp, portp, A_SETSIGNALS, &portp->asig,
1052 sizeof(asysigs_t), 0)) < 0)
1058 /*****************************************************************************/
1061 * Send an open message to the slave. This will sleep waiting for the
1062 * acknowledgement, so must have user context. We need to co-ordinate
1063 * with close events here, since we don't want open and close events
1067 static int stli_rawopen(stlibrd_t *brdp, stliport_t *portp, unsigned long arg, int wait)
1069 cdkhdr_t __iomem *hdrp;
1070 cdkctrl_t __iomem *cp;
1071 unsigned char __iomem *bits;
1072 unsigned long flags;
1076 * Send a message to the slave to open this port.
1080 * Slave is already closing this port. This can happen if a hangup
1081 * occurs on this port. So we must wait until it is complete. The
1082 * order of opens and closes may not be preserved across shared
1083 * memory, so we must wait until it is complete.
1085 wait_event_interruptible(portp->raw_wait,
1086 !test_bit(ST_CLOSING, &portp->state));
1087 if (signal_pending(current)) {
1088 return -ERESTARTSYS;
1092 * Everything is ready now, so write the open message into shared
1093 * memory. Once the message is in set the service bits to say that
1094 * this port wants service.
1096 spin_lock_irqsave(&brd_lock, flags);
1098 cp = &((cdkasy_t __iomem *) EBRDGETMEMPTR(brdp, portp->addr))->ctrl;
1099 writel(arg, &cp->openarg);
1100 writeb(1, &cp->open);
1101 hdrp = (cdkhdr_t __iomem *) EBRDGETMEMPTR(brdp, CDK_CDKADDR);
1102 bits = ((unsigned char __iomem *) hdrp) + brdp->slaveoffset +
1104 writeb(readb(bits) | portp->portbit, bits);
1108 spin_unlock_irqrestore(&brd_lock, flags);
1113 * Slave is in action, so now we must wait for the open acknowledgment
1117 set_bit(ST_OPENING, &portp->state);
1118 spin_unlock_irqrestore(&brd_lock, flags);
1120 wait_event_interruptible(portp->raw_wait,
1121 !test_bit(ST_OPENING, &portp->state));
1122 if (signal_pending(current))
1125 if ((rc == 0) && (portp->rc != 0))
1130 /*****************************************************************************/
1133 * Send a close message to the slave. Normally this will sleep waiting
1134 * for the acknowledgement, but if wait parameter is 0 it will not. If
1135 * wait is true then must have user context (to sleep).
1138 static int stli_rawclose(stlibrd_t *brdp, stliport_t *portp, unsigned long arg, int wait)
1140 cdkhdr_t __iomem *hdrp;
1141 cdkctrl_t __iomem *cp;
1142 unsigned char __iomem *bits;
1143 unsigned long flags;
1147 * Slave is already closing this port. This can happen if a hangup
1148 * occurs on this port.
1151 wait_event_interruptible(portp->raw_wait,
1152 !test_bit(ST_CLOSING, &portp->state));
1153 if (signal_pending(current)) {
1154 return -ERESTARTSYS;
1159 * Write the close command into shared memory.
1161 spin_lock_irqsave(&brd_lock, flags);
1163 cp = &((cdkasy_t __iomem *) EBRDGETMEMPTR(brdp, portp->addr))->ctrl;
1164 writel(arg, &cp->closearg);
1165 writeb(1, &cp->close);
1166 hdrp = (cdkhdr_t __iomem *) EBRDGETMEMPTR(brdp, CDK_CDKADDR);
1167 bits = ((unsigned char __iomem *) hdrp) + brdp->slaveoffset +
1169 writeb(readb(bits) |portp->portbit, bits);
1172 set_bit(ST_CLOSING, &portp->state);
1173 spin_unlock_irqrestore(&brd_lock, flags);
1179 * Slave is in action, so now we must wait for the open acknowledgment
1183 wait_event_interruptible(portp->raw_wait,
1184 !test_bit(ST_CLOSING, &portp->state));
1185 if (signal_pending(current))
1188 if ((rc == 0) && (portp->rc != 0))
1193 /*****************************************************************************/
1196 * Send a command to the slave and wait for the response. This must
1197 * have user context (it sleeps). This routine is generic in that it
1198 * can send any type of command. Its purpose is to wait for that command
1199 * to complete (as opposed to initiating the command then returning).
1202 static int stli_cmdwait(stlibrd_t *brdp, stliport_t *portp, unsigned long cmd, void *arg, int size, int copyback)
1204 wait_event_interruptible(portp->raw_wait,
1205 !test_bit(ST_CMDING, &portp->state));
1206 if (signal_pending(current))
1207 return -ERESTARTSYS;
1209 stli_sendcmd(brdp, portp, cmd, arg, size, copyback);
1211 wait_event_interruptible(portp->raw_wait,
1212 !test_bit(ST_CMDING, &portp->state));
1213 if (signal_pending(current))
1214 return -ERESTARTSYS;
1221 /*****************************************************************************/
1224 * Send the termios settings for this port to the slave. This sleeps
1225 * waiting for the command to complete - so must have user context.
1228 static int stli_setport(stliport_t *portp)
1235 if (portp->tty == NULL)
1237 if (portp->brdnr < 0 && portp->brdnr >= stli_nrbrds)
1239 brdp = stli_brds[portp->brdnr];
1243 stli_mkasyport(portp, &aport, portp->tty->termios);
1244 return(stli_cmdwait(brdp, portp, A_SETPORT, &aport, sizeof(asyport_t), 0));
1247 /*****************************************************************************/
1250 * Possibly need to wait for carrier (DCD signal) to come high. Say
1251 * maybe because if we are clocal then we don't need to wait...
1254 static int stli_waitcarrier(stlibrd_t *brdp, stliport_t *portp, struct file *filp)
1256 unsigned long flags;
1262 if (portp->tty->termios->c_cflag & CLOCAL)
1265 spin_lock_irqsave(&stli_lock, flags);
1266 portp->openwaitcnt++;
1267 if (! tty_hung_up_p(filp))
1269 spin_unlock_irqrestore(&stli_lock, flags);
1272 stli_mkasysigs(&portp->asig, 1, 1);
1273 if ((rc = stli_cmdwait(brdp, portp, A_SETSIGNALS,
1274 &portp->asig, sizeof(asysigs_t), 0)) < 0)
1276 if (tty_hung_up_p(filp) ||
1277 ((portp->flags & ASYNC_INITIALIZED) == 0)) {
1278 if (portp->flags & ASYNC_HUP_NOTIFY)
1284 if (((portp->flags & ASYNC_CLOSING) == 0) &&
1285 (doclocal || (portp->sigs & TIOCM_CD))) {
1288 if (signal_pending(current)) {
1292 interruptible_sleep_on(&portp->open_wait);
1295 spin_lock_irqsave(&stli_lock, flags);
1296 if (! tty_hung_up_p(filp))
1298 portp->openwaitcnt--;
1299 spin_unlock_irqrestore(&stli_lock, flags);
1304 /*****************************************************************************/
1307 * Write routine. Take the data and put it in the shared memory ring
1308 * queue. If port is not already sending chars then need to mark the
1309 * service bits for this port.
1312 static int stli_write(struct tty_struct *tty, const unsigned char *buf, int count)
1314 cdkasy_t __iomem *ap;
1315 cdkhdr_t __iomem *hdrp;
1316 unsigned char __iomem *bits;
1317 unsigned char __iomem *shbuf;
1318 unsigned char *chbuf;
1321 unsigned int len, stlen, head, tail, size;
1322 unsigned long flags;
1324 if (tty == stli_txcooktty)
1325 stli_flushchars(tty);
1326 portp = tty->driver_data;
1329 if ((portp->brdnr < 0) || (portp->brdnr >= stli_nrbrds))
1331 brdp = stli_brds[portp->brdnr];
1334 chbuf = (unsigned char *) buf;
1337 * All data is now local, shove as much as possible into shared memory.
1339 spin_lock_irqsave(&brd_lock, flags);
1341 ap = (cdkasy_t __iomem *) EBRDGETMEMPTR(brdp, portp->addr);
1342 head = (unsigned int) readw(&ap->txq.head);
1343 tail = (unsigned int) readw(&ap->txq.tail);
1344 if (tail != ((unsigned int) readw(&ap->txq.tail)))
1345 tail = (unsigned int) readw(&ap->txq.tail);
1346 size = portp->txsize;
1348 len = size - (head - tail) - 1;
1349 stlen = size - head;
1351 len = tail - head - 1;
1355 len = min(len, (unsigned int)count);
1357 shbuf = (char __iomem *) EBRDGETMEMPTR(brdp, portp->txoffset);
1360 stlen = min(len, stlen);
1361 memcpy_toio(shbuf + head, chbuf, stlen);
1372 ap = (cdkasy_t __iomem *) EBRDGETMEMPTR(brdp, portp->addr);
1373 writew(head, &ap->txq.head);
1374 if (test_bit(ST_TXBUSY, &portp->state)) {
1375 if (readl(&ap->changed.data) & DT_TXEMPTY)
1376 writel(readl(&ap->changed.data) & ~DT_TXEMPTY, &ap->changed.data);
1378 hdrp = (cdkhdr_t __iomem *) EBRDGETMEMPTR(brdp, CDK_CDKADDR);
1379 bits = ((unsigned char __iomem *) hdrp) + brdp->slaveoffset +
1381 writeb(readb(bits) | portp->portbit, bits);
1382 set_bit(ST_TXBUSY, &portp->state);
1384 spin_unlock_irqrestore(&brd_lock, flags);
1389 /*****************************************************************************/
1392 * Output a single character. We put it into a temporary local buffer
1393 * (for speed) then write out that buffer when the flushchars routine
1394 * is called. There is a safety catch here so that if some other port
1395 * writes chars before the current buffer has been, then we write them
1396 * first them do the new ports.
1399 static void stli_putchar(struct tty_struct *tty, unsigned char ch)
1401 if (tty != stli_txcooktty) {
1402 if (stli_txcooktty != NULL)
1403 stli_flushchars(stli_txcooktty);
1404 stli_txcooktty = tty;
1407 stli_txcookbuf[stli_txcooksize++] = ch;
1410 /*****************************************************************************/
1413 * Transfer characters from the local TX cooking buffer to the board.
1414 * We sort of ignore the tty that gets passed in here. We rely on the
1415 * info stored with the TX cook buffer to tell us which port to flush
1416 * the data on. In any case we clean out the TX cook buffer, for re-use
1420 static void stli_flushchars(struct tty_struct *tty)
1422 cdkhdr_t __iomem *hdrp;
1423 unsigned char __iomem *bits;
1424 cdkasy_t __iomem *ap;
1425 struct tty_struct *cooktty;
1428 unsigned int len, stlen, head, tail, size, count, cooksize;
1430 unsigned char __iomem *shbuf;
1431 unsigned long flags;
1433 cooksize = stli_txcooksize;
1434 cooktty = stli_txcooktty;
1435 stli_txcooksize = 0;
1436 stli_txcookrealsize = 0;
1437 stli_txcooktty = NULL;
1441 if (cooktty == NULL)
1448 portp = tty->driver_data;
1451 if ((portp->brdnr < 0) || (portp->brdnr >= stli_nrbrds))
1453 brdp = stli_brds[portp->brdnr];
1457 spin_lock_irqsave(&brd_lock, flags);
1460 ap = (cdkasy_t __iomem *) EBRDGETMEMPTR(brdp, portp->addr);
1461 head = (unsigned int) readw(&ap->txq.head);
1462 tail = (unsigned int) readw(&ap->txq.tail);
1463 if (tail != ((unsigned int) readw(&ap->txq.tail)))
1464 tail = (unsigned int) readw(&ap->txq.tail);
1465 size = portp->txsize;
1467 len = size - (head - tail) - 1;
1468 stlen = size - head;
1470 len = tail - head - 1;
1474 len = min(len, cooksize);
1476 shbuf = EBRDGETMEMPTR(brdp, portp->txoffset);
1477 buf = stli_txcookbuf;
1480 stlen = min(len, stlen);
1481 memcpy_toio(shbuf + head, buf, stlen);
1492 ap = (cdkasy_t __iomem *) EBRDGETMEMPTR(brdp, portp->addr);
1493 writew(head, &ap->txq.head);
1495 if (test_bit(ST_TXBUSY, &portp->state)) {
1496 if (readl(&ap->changed.data) & DT_TXEMPTY)
1497 writel(readl(&ap->changed.data) & ~DT_TXEMPTY, &ap->changed.data);
1499 hdrp = (cdkhdr_t __iomem *) EBRDGETMEMPTR(brdp, CDK_CDKADDR);
1500 bits = ((unsigned char __iomem *) hdrp) + brdp->slaveoffset +
1502 writeb(readb(bits) | portp->portbit, bits);
1503 set_bit(ST_TXBUSY, &portp->state);
1506 spin_unlock_irqrestore(&brd_lock, flags);
1509 /*****************************************************************************/
1511 static int stli_writeroom(struct tty_struct *tty)
1513 cdkasyrq_t __iomem *rp;
1516 unsigned int head, tail, len;
1517 unsigned long flags;
1519 if (tty == stli_txcooktty) {
1520 if (stli_txcookrealsize != 0) {
1521 len = stli_txcookrealsize - stli_txcooksize;
1526 portp = tty->driver_data;
1529 if ((portp->brdnr < 0) || (portp->brdnr >= stli_nrbrds))
1531 brdp = stli_brds[portp->brdnr];
1535 spin_lock_irqsave(&brd_lock, flags);
1537 rp = &((cdkasy_t __iomem *) EBRDGETMEMPTR(brdp, portp->addr))->txq;
1538 head = (unsigned int) readw(&rp->head);
1539 tail = (unsigned int) readw(&rp->tail);
1540 if (tail != ((unsigned int) readw(&rp->tail)))
1541 tail = (unsigned int) readw(&rp->tail);
1542 len = (head >= tail) ? (portp->txsize - (head - tail)) : (tail - head);
1545 spin_unlock_irqrestore(&brd_lock, flags);
1547 if (tty == stli_txcooktty) {
1548 stli_txcookrealsize = len;
1549 len -= stli_txcooksize;
1554 /*****************************************************************************/
1557 * Return the number of characters in the transmit buffer. Normally we
1558 * will return the number of chars in the shared memory ring queue.
1559 * We need to kludge around the case where the shared memory buffer is
1560 * empty but not all characters have drained yet, for this case just
1561 * return that there is 1 character in the buffer!
1564 static int stli_charsinbuffer(struct tty_struct *tty)
1566 cdkasyrq_t __iomem *rp;
1569 unsigned int head, tail, len;
1570 unsigned long flags;
1572 if (tty == stli_txcooktty)
1573 stli_flushchars(tty);
1574 portp = tty->driver_data;
1577 if ((portp->brdnr < 0) || (portp->brdnr >= stli_nrbrds))
1579 brdp = stli_brds[portp->brdnr];
1583 spin_lock_irqsave(&brd_lock, flags);
1585 rp = &((cdkasy_t __iomem *) EBRDGETMEMPTR(brdp, portp->addr))->txq;
1586 head = (unsigned int) readw(&rp->head);
1587 tail = (unsigned int) readw(&rp->tail);
1588 if (tail != ((unsigned int) readw(&rp->tail)))
1589 tail = (unsigned int) readw(&rp->tail);
1590 len = (head >= tail) ? (head - tail) : (portp->txsize - (tail - head));
1591 if ((len == 0) && test_bit(ST_TXBUSY, &portp->state))
1594 spin_unlock_irqrestore(&brd_lock, flags);
1599 /*****************************************************************************/
1602 * Generate the serial struct info.
1605 static int stli_getserial(stliport_t *portp, struct serial_struct __user *sp)
1607 struct serial_struct sio;
1610 memset(&sio, 0, sizeof(struct serial_struct));
1611 sio.type = PORT_UNKNOWN;
1612 sio.line = portp->portnr;
1614 sio.flags = portp->flags;
1615 sio.baud_base = portp->baud_base;
1616 sio.close_delay = portp->close_delay;
1617 sio.closing_wait = portp->closing_wait;
1618 sio.custom_divisor = portp->custom_divisor;
1619 sio.xmit_fifo_size = 0;
1622 brdp = stli_brds[portp->brdnr];
1624 sio.port = brdp->iobase;
1626 return copy_to_user(sp, &sio, sizeof(struct serial_struct)) ?
1630 /*****************************************************************************/
1633 * Set port according to the serial struct info.
1634 * At this point we do not do any auto-configure stuff, so we will
1635 * just quietly ignore any requests to change irq, etc.
1638 static int stli_setserial(stliport_t *portp, struct serial_struct __user *sp)
1640 struct serial_struct sio;
1643 if (copy_from_user(&sio, sp, sizeof(struct serial_struct)))
1645 if (!capable(CAP_SYS_ADMIN)) {
1646 if ((sio.baud_base != portp->baud_base) ||
1647 (sio.close_delay != portp->close_delay) ||
1648 ((sio.flags & ~ASYNC_USR_MASK) !=
1649 (portp->flags & ~ASYNC_USR_MASK)))
1653 portp->flags = (portp->flags & ~ASYNC_USR_MASK) |
1654 (sio.flags & ASYNC_USR_MASK);
1655 portp->baud_base = sio.baud_base;
1656 portp->close_delay = sio.close_delay;
1657 portp->closing_wait = sio.closing_wait;
1658 portp->custom_divisor = sio.custom_divisor;
1660 if ((rc = stli_setport(portp)) < 0)
1665 /*****************************************************************************/
1667 static int stli_tiocmget(struct tty_struct *tty, struct file *file)
1669 stliport_t *portp = tty->driver_data;
1675 if (portp->brdnr < 0 || portp->brdnr >= stli_nrbrds)
1677 brdp = stli_brds[portp->brdnr];
1680 if (tty->flags & (1 << TTY_IO_ERROR))
1683 if ((rc = stli_cmdwait(brdp, portp, A_GETSIGNALS,
1684 &portp->asig, sizeof(asysigs_t), 1)) < 0)
1687 return stli_mktiocm(portp->asig.sigvalue);
1690 static int stli_tiocmset(struct tty_struct *tty, struct file *file,
1691 unsigned int set, unsigned int clear)
1693 stliport_t *portp = tty->driver_data;
1695 int rts = -1, dtr = -1;
1699 if (portp->brdnr < 0 || portp->brdnr >= stli_nrbrds)
1701 brdp = stli_brds[portp->brdnr];
1704 if (tty->flags & (1 << TTY_IO_ERROR))
1707 if (set & TIOCM_RTS)
1709 if (set & TIOCM_DTR)
1711 if (clear & TIOCM_RTS)
1713 if (clear & TIOCM_DTR)
1716 stli_mkasysigs(&portp->asig, dtr, rts);
1718 return stli_cmdwait(brdp, portp, A_SETSIGNALS, &portp->asig,
1719 sizeof(asysigs_t), 0);
1722 static int stli_ioctl(struct tty_struct *tty, struct file *file, unsigned int cmd, unsigned long arg)
1728 void __user *argp = (void __user *)arg;
1730 portp = tty->driver_data;
1733 if (portp->brdnr < 0 || portp->brdnr >= stli_nrbrds)
1735 brdp = stli_brds[portp->brdnr];
1739 if ((cmd != TIOCGSERIAL) && (cmd != TIOCSSERIAL) &&
1740 (cmd != COM_GETPORTSTATS) && (cmd != COM_CLRPORTSTATS)) {
1741 if (tty->flags & (1 << TTY_IO_ERROR))
1749 rc = put_user(((tty->termios->c_cflag & CLOCAL) ? 1 : 0),
1750 (unsigned __user *) arg);
1753 if ((rc = get_user(ival, (unsigned __user *) arg)) == 0)
1754 tty->termios->c_cflag =
1755 (tty->termios->c_cflag & ~CLOCAL) |
1756 (ival ? CLOCAL : 0);
1759 rc = stli_getserial(portp, argp);
1762 rc = stli_setserial(portp, argp);
1765 rc = put_user(portp->pflag, (unsigned __user *)argp);
1768 if ((rc = get_user(portp->pflag, (unsigned __user *)argp)) == 0)
1769 stli_setport(portp);
1771 case COM_GETPORTSTATS:
1772 rc = stli_getportstats(portp, argp);
1774 case COM_CLRPORTSTATS:
1775 rc = stli_clrportstats(portp, argp);
1781 case TIOCSERGSTRUCT:
1782 case TIOCSERGETMULTI:
1783 case TIOCSERSETMULTI:
1792 /*****************************************************************************/
1795 * This routine assumes that we have user context and can sleep.
1796 * Looks like it is true for the current ttys implementation..!!
1799 static void stli_settermios(struct tty_struct *tty, struct ktermios *old)
1803 struct ktermios *tiosp;
1808 portp = tty->driver_data;
1811 if (portp->brdnr < 0 || portp->brdnr >= stli_nrbrds)
1813 brdp = stli_brds[portp->brdnr];
1817 tiosp = tty->termios;
1818 if ((tiosp->c_cflag == old->c_cflag) &&
1819 (tiosp->c_iflag == old->c_iflag))
1822 stli_mkasyport(portp, &aport, tiosp);
1823 stli_cmdwait(brdp, portp, A_SETPORT, &aport, sizeof(asyport_t), 0);
1824 stli_mkasysigs(&portp->asig, ((tiosp->c_cflag & CBAUD) ? 1 : 0), -1);
1825 stli_cmdwait(brdp, portp, A_SETSIGNALS, &portp->asig,
1826 sizeof(asysigs_t), 0);
1827 if ((old->c_cflag & CRTSCTS) && ((tiosp->c_cflag & CRTSCTS) == 0))
1828 tty->hw_stopped = 0;
1829 if (((old->c_cflag & CLOCAL) == 0) && (tiosp->c_cflag & CLOCAL))
1830 wake_up_interruptible(&portp->open_wait);
1833 /*****************************************************************************/
1836 * Attempt to flow control who ever is sending us data. We won't really
1837 * do any flow control action here. We can't directly, and even if we
1838 * wanted to we would have to send a command to the slave. The slave
1839 * knows how to flow control, and will do so when its buffers reach its
1840 * internal high water marks. So what we will do is set a local state
1841 * bit that will stop us sending any RX data up from the poll routine
1842 * (which is the place where RX data from the slave is handled).
1845 static void stli_throttle(struct tty_struct *tty)
1847 stliport_t *portp = tty->driver_data;
1850 set_bit(ST_RXSTOP, &portp->state);
1853 /*****************************************************************************/
1856 * Unflow control the device sending us data... That means that all
1857 * we have to do is clear the RXSTOP state bit. The next poll call
1858 * will then be able to pass the RX data back up.
1861 static void stli_unthrottle(struct tty_struct *tty)
1863 stliport_t *portp = tty->driver_data;
1866 clear_bit(ST_RXSTOP, &portp->state);
1869 /*****************************************************************************/
1872 * Stop the transmitter.
1875 static void stli_stop(struct tty_struct *tty)
1879 /*****************************************************************************/
1882 * Start the transmitter again.
1885 static void stli_start(struct tty_struct *tty)
1889 /*****************************************************************************/
1892 * Scheduler called hang up routine. This is called from the scheduler,
1893 * not direct from the driver "poll" routine. We can't call it there
1894 * since the real local hangup code will enable/disable the board and
1895 * other things that we can't do while handling the poll. Much easier
1896 * to deal with it some time later (don't really care when, hangups
1897 * aren't that time critical).
1900 static void stli_dohangup(struct work_struct *ugly_api)
1902 stliport_t *portp = container_of(ugly_api, stliport_t, tqhangup);
1903 if (portp->tty != NULL) {
1904 tty_hangup(portp->tty);
1908 /*****************************************************************************/
1911 * Hangup this port. This is pretty much like closing the port, only
1912 * a little more brutal. No waiting for data to drain. Shutdown the
1913 * port and maybe drop signals. This is rather tricky really. We want
1914 * to close the port as well.
1917 static void stli_hangup(struct tty_struct *tty)
1921 unsigned long flags;
1923 portp = tty->driver_data;
1926 if (portp->brdnr < 0 || portp->brdnr >= stli_nrbrds)
1928 brdp = stli_brds[portp->brdnr];
1932 portp->flags &= ~ASYNC_INITIALIZED;
1934 if (!test_bit(ST_CLOSING, &portp->state))
1935 stli_rawclose(brdp, portp, 0, 0);
1937 spin_lock_irqsave(&stli_lock, flags);
1938 if (tty->termios->c_cflag & HUPCL) {
1939 stli_mkasysigs(&portp->asig, 0, 0);
1940 if (test_bit(ST_CMDING, &portp->state)) {
1941 set_bit(ST_DOSIGS, &portp->state);
1942 set_bit(ST_DOFLUSHTX, &portp->state);
1943 set_bit(ST_DOFLUSHRX, &portp->state);
1945 stli_sendcmd(brdp, portp, A_SETSIGNALSF,
1946 &portp->asig, sizeof(asysigs_t), 0);
1950 clear_bit(ST_TXBUSY, &portp->state);
1951 clear_bit(ST_RXSTOP, &portp->state);
1952 set_bit(TTY_IO_ERROR, &tty->flags);
1954 portp->flags &= ~ASYNC_NORMAL_ACTIVE;
1955 portp->refcount = 0;
1956 spin_unlock_irqrestore(&stli_lock, flags);
1958 wake_up_interruptible(&portp->open_wait);
1961 /*****************************************************************************/
1964 * Flush characters from the lower buffer. We may not have user context
1965 * so we cannot sleep waiting for it to complete. Also we need to check
1966 * if there is chars for this port in the TX cook buffer, and flush them
1970 static void stli_flushbuffer(struct tty_struct *tty)
1974 unsigned long ftype, flags;
1976 portp = tty->driver_data;
1979 if (portp->brdnr < 0 || portp->brdnr >= stli_nrbrds)
1981 brdp = stli_brds[portp->brdnr];
1985 spin_lock_irqsave(&brd_lock, flags);
1986 if (tty == stli_txcooktty) {
1987 stli_txcooktty = NULL;
1988 stli_txcooksize = 0;
1989 stli_txcookrealsize = 0;
1991 if (test_bit(ST_CMDING, &portp->state)) {
1992 set_bit(ST_DOFLUSHTX, &portp->state);
1995 if (test_bit(ST_DOFLUSHRX, &portp->state)) {
1997 clear_bit(ST_DOFLUSHRX, &portp->state);
1999 __stli_sendcmd(brdp, portp, A_FLUSH, &ftype, sizeof(u32), 0);
2001 spin_unlock_irqrestore(&brd_lock, flags);
2005 /*****************************************************************************/
2007 static void stli_breakctl(struct tty_struct *tty, int state)
2013 portp = tty->driver_data;
2016 if (portp->brdnr < 0 || portp->brdnr >= stli_nrbrds)
2018 brdp = stli_brds[portp->brdnr];
2022 arg = (state == -1) ? BREAKON : BREAKOFF;
2023 stli_cmdwait(brdp, portp, A_BREAK, &arg, sizeof(long), 0);
2026 /*****************************************************************************/
2028 static void stli_waituntilsent(struct tty_struct *tty, int timeout)
2035 portp = tty->driver_data;
2041 tend = jiffies + timeout;
2043 while (test_bit(ST_TXBUSY, &portp->state)) {
2044 if (signal_pending(current))
2046 msleep_interruptible(20);
2047 if (time_after_eq(jiffies, tend))
2052 /*****************************************************************************/
2054 static void stli_sendxchar(struct tty_struct *tty, char ch)
2060 portp = tty->driver_data;
2063 if (portp->brdnr < 0 || portp->brdnr >= stli_nrbrds)
2065 brdp = stli_brds[portp->brdnr];
2069 memset(&actrl, 0, sizeof(asyctrl_t));
2070 if (ch == STOP_CHAR(tty)) {
2071 actrl.rxctrl = CT_STOPFLOW;
2072 } else if (ch == START_CHAR(tty)) {
2073 actrl.rxctrl = CT_STARTFLOW;
2075 actrl.txctrl = CT_SENDCHR;
2078 stli_cmdwait(brdp, portp, A_PORTCTRL, &actrl, sizeof(asyctrl_t), 0);
2081 /*****************************************************************************/
2086 * Format info for a specified port. The line is deliberately limited
2087 * to 80 characters. (If it is too long it will be truncated, if too
2088 * short then padded with spaces).
2091 static int stli_portinfo(stlibrd_t *brdp, stliport_t *portp, int portnr, char *pos)
2096 rc = stli_portcmdstats(portp);
2099 if (brdp->state & BST_STARTED) {
2100 switch (stli_comstats.hwid) {
2101 case 0: uart = "2681"; break;
2102 case 1: uart = "SC26198"; break;
2103 default:uart = "CD1400"; break;
2108 sp += sprintf(sp, "%d: uart:%s ", portnr, uart);
2110 if ((brdp->state & BST_STARTED) && (rc >= 0)) {
2111 sp += sprintf(sp, "tx:%d rx:%d", (int) stli_comstats.txtotal,
2112 (int) stli_comstats.rxtotal);
2114 if (stli_comstats.rxframing)
2115 sp += sprintf(sp, " fe:%d",
2116 (int) stli_comstats.rxframing);
2117 if (stli_comstats.rxparity)
2118 sp += sprintf(sp, " pe:%d",
2119 (int) stli_comstats.rxparity);
2120 if (stli_comstats.rxbreaks)
2121 sp += sprintf(sp, " brk:%d",
2122 (int) stli_comstats.rxbreaks);
2123 if (stli_comstats.rxoverrun)
2124 sp += sprintf(sp, " oe:%d",
2125 (int) stli_comstats.rxoverrun);
2127 cnt = sprintf(sp, "%s%s%s%s%s ",
2128 (stli_comstats.signals & TIOCM_RTS) ? "|RTS" : "",
2129 (stli_comstats.signals & TIOCM_CTS) ? "|CTS" : "",
2130 (stli_comstats.signals & TIOCM_DTR) ? "|DTR" : "",
2131 (stli_comstats.signals & TIOCM_CD) ? "|DCD" : "",
2132 (stli_comstats.signals & TIOCM_DSR) ? "|DSR" : "");
2137 for (cnt = (sp - pos); (cnt < (MAXLINE - 1)); cnt++)
2140 pos[(MAXLINE - 2)] = '+';
2141 pos[(MAXLINE - 1)] = '\n';
2146 /*****************************************************************************/
2149 * Port info, read from the /proc file system.
2152 static int stli_readproc(char *page, char **start, off_t off, int count, int *eof, void *data)
2156 int brdnr, portnr, totalport;
2165 pos += sprintf(pos, "%s: version %s", stli_drvtitle,
2167 while (pos < (page + MAXLINE - 1))
2174 * We scan through for each board, panel and port. The offset is
2175 * calculated on the fly, and irrelevant ports are skipped.
2177 for (brdnr = 0; (brdnr < stli_nrbrds); brdnr++) {
2178 brdp = stli_brds[brdnr];
2181 if (brdp->state == 0)
2184 maxoff = curoff + (brdp->nrports * MAXLINE);
2185 if (off >= maxoff) {
2190 totalport = brdnr * STL_MAXPORTS;
2191 for (portnr = 0; (portnr < brdp->nrports); portnr++,
2193 portp = brdp->ports[portnr];
2196 if (off >= (curoff += MAXLINE))
2198 if ((pos - page + MAXLINE) > count)
2200 pos += stli_portinfo(brdp, portp, totalport, pos);
2211 /*****************************************************************************/
2214 * Generic send command routine. This will send a message to the slave,
2215 * of the specified type with the specified argument. Must be very
2216 * careful of data that will be copied out from shared memory -
2217 * containing command results. The command completion is all done from
2218 * a poll routine that does not have user context. Therefore you cannot
2219 * copy back directly into user space, or to the kernel stack of a
2220 * process. This routine does not sleep, so can be called from anywhere.
2222 * The caller must hold the brd_lock (see also stli_sendcmd the usual
2226 static void __stli_sendcmd(stlibrd_t *brdp, stliport_t *portp, unsigned long cmd, void *arg, int size, int copyback)
2228 cdkhdr_t __iomem *hdrp;
2229 cdkctrl_t __iomem *cp;
2230 unsigned char __iomem *bits;
2231 unsigned long flags;
2233 spin_lock_irqsave(&brd_lock, flags);
2235 if (test_bit(ST_CMDING, &portp->state)) {
2236 printk(KERN_ERR "STALLION: command already busy, cmd=%x!\n",
2238 spin_unlock_irqrestore(&brd_lock, flags);
2243 cp = &((cdkasy_t __iomem *) EBRDGETMEMPTR(brdp, portp->addr))->ctrl;
2245 memcpy_toio((void __iomem *) &(cp->args[0]), arg, size);
2248 portp->argsize = size;
2251 writel(0, &cp->status);
2252 writel(cmd, &cp->cmd);
2253 hdrp = (cdkhdr_t __iomem *) EBRDGETMEMPTR(brdp, CDK_CDKADDR);
2254 bits = ((unsigned char __iomem *) hdrp) + brdp->slaveoffset +
2256 writeb(readb(bits) | portp->portbit, bits);
2257 set_bit(ST_CMDING, &portp->state);
2259 spin_unlock_irqrestore(&brd_lock, flags);
2262 static void stli_sendcmd(stlibrd_t *brdp, stliport_t *portp, unsigned long cmd, void *arg, int size, int copyback)
2264 unsigned long flags;
2266 spin_lock_irqsave(&brd_lock, flags);
2267 __stli_sendcmd(brdp, portp, cmd, arg, size, copyback);
2268 spin_unlock_irqrestore(&brd_lock, flags);
2271 /*****************************************************************************/
2274 * Read data from shared memory. This assumes that the shared memory
2275 * is enabled and that interrupts are off. Basically we just empty out
2276 * the shared memory buffer into the tty buffer. Must be careful to
2277 * handle the case where we fill up the tty buffer, but still have
2278 * more chars to unload.
2281 static void stli_read(stlibrd_t *brdp, stliport_t *portp)
2283 cdkasyrq_t __iomem *rp;
2284 char __iomem *shbuf;
2285 struct tty_struct *tty;
2286 unsigned int head, tail, size;
2287 unsigned int len, stlen;
2289 if (test_bit(ST_RXSTOP, &portp->state))
2295 rp = &((cdkasy_t __iomem *) EBRDGETMEMPTR(brdp, portp->addr))->rxq;
2296 head = (unsigned int) readw(&rp->head);
2297 if (head != ((unsigned int) readw(&rp->head)))
2298 head = (unsigned int) readw(&rp->head);
2299 tail = (unsigned int) readw(&rp->tail);
2300 size = portp->rxsize;
2305 len = size - (tail - head);
2306 stlen = size - tail;
2309 len = tty_buffer_request_room(tty, len);
2311 shbuf = (char __iomem *) EBRDGETMEMPTR(brdp, portp->rxoffset);
2314 unsigned char *cptr;
2316 stlen = min(len, stlen);
2317 tty_prepare_flip_string(tty, &cptr, stlen);
2318 memcpy_fromio(cptr, shbuf + tail, stlen);
2326 rp = &((cdkasy_t __iomem *) EBRDGETMEMPTR(brdp, portp->addr))->rxq;
2327 writew(tail, &rp->tail);
2330 set_bit(ST_RXING, &portp->state);
2332 tty_schedule_flip(tty);
2335 /*****************************************************************************/
2338 * Set up and carry out any delayed commands. There is only a small set
2339 * of slave commands that can be done "off-level". So it is not too
2340 * difficult to deal with them here.
2343 static void stli_dodelaycmd(stliport_t *portp, cdkctrl_t __iomem *cp)
2347 if (test_bit(ST_DOSIGS, &portp->state)) {
2348 if (test_bit(ST_DOFLUSHTX, &portp->state) &&
2349 test_bit(ST_DOFLUSHRX, &portp->state))
2350 cmd = A_SETSIGNALSF;
2351 else if (test_bit(ST_DOFLUSHTX, &portp->state))
2352 cmd = A_SETSIGNALSFTX;
2353 else if (test_bit(ST_DOFLUSHRX, &portp->state))
2354 cmd = A_SETSIGNALSFRX;
2357 clear_bit(ST_DOFLUSHTX, &portp->state);
2358 clear_bit(ST_DOFLUSHRX, &portp->state);
2359 clear_bit(ST_DOSIGS, &portp->state);
2360 memcpy_toio((void __iomem *) &(cp->args[0]), (void *) &portp->asig,
2362 writel(0, &cp->status);
2363 writel(cmd, &cp->cmd);
2364 set_bit(ST_CMDING, &portp->state);
2365 } else if (test_bit(ST_DOFLUSHTX, &portp->state) ||
2366 test_bit(ST_DOFLUSHRX, &portp->state)) {
2367 cmd = ((test_bit(ST_DOFLUSHTX, &portp->state)) ? FLUSHTX : 0);
2368 cmd |= ((test_bit(ST_DOFLUSHRX, &portp->state)) ? FLUSHRX : 0);
2369 clear_bit(ST_DOFLUSHTX, &portp->state);
2370 clear_bit(ST_DOFLUSHRX, &portp->state);
2371 memcpy_toio((void __iomem *) &(cp->args[0]), (void *) &cmd, sizeof(int));
2372 writel(0, &cp->status);
2373 writel(A_FLUSH, &cp->cmd);
2374 set_bit(ST_CMDING, &portp->state);
2378 /*****************************************************************************/
2381 * Host command service checking. This handles commands or messages
2382 * coming from the slave to the host. Must have board shared memory
2383 * enabled and interrupts off when called. Notice that by servicing the
2384 * read data last we don't need to change the shared memory pointer
2385 * during processing (which is a slow IO operation).
2386 * Return value indicates if this port is still awaiting actions from
2387 * the slave (like open, command, or even TX data being sent). If 0
2388 * then port is still busy, otherwise no longer busy.
2391 static int stli_hostcmd(stlibrd_t *brdp, stliport_t *portp)
2393 cdkasy_t __iomem *ap;
2394 cdkctrl_t __iomem *cp;
2395 struct tty_struct *tty;
2397 unsigned long oldsigs;
2400 ap = (cdkasy_t __iomem *) EBRDGETMEMPTR(brdp, portp->addr);
2404 * Check if we are waiting for an open completion message.
2406 if (test_bit(ST_OPENING, &portp->state)) {
2407 rc = readl(&cp->openarg);
2408 if (readb(&cp->open) == 0 && rc != 0) {
2411 writel(0, &cp->openarg);
2413 clear_bit(ST_OPENING, &portp->state);
2414 wake_up_interruptible(&portp->raw_wait);
2419 * Check if we are waiting for a close completion message.
2421 if (test_bit(ST_CLOSING, &portp->state)) {
2422 rc = (int) readl(&cp->closearg);
2423 if (readb(&cp->close) == 0 && rc != 0) {
2426 writel(0, &cp->closearg);
2428 clear_bit(ST_CLOSING, &portp->state);
2429 wake_up_interruptible(&portp->raw_wait);
2434 * Check if we are waiting for a command completion message. We may
2435 * need to copy out the command results associated with this command.
2437 if (test_bit(ST_CMDING, &portp->state)) {
2438 rc = readl(&cp->status);
2439 if (readl(&cp->cmd) == 0 && rc != 0) {
2442 if (portp->argp != NULL) {
2443 memcpy_fromio(portp->argp, (void __iomem *) &(cp->args[0]),
2447 writel(0, &cp->status);
2449 clear_bit(ST_CMDING, &portp->state);
2450 stli_dodelaycmd(portp, cp);
2451 wake_up_interruptible(&portp->raw_wait);
2456 * Check for any notification messages ready. This includes lots of
2457 * different types of events - RX chars ready, RX break received,
2458 * TX data low or empty in the slave, modem signals changed state.
2467 if (nt.signal & SG_DCD) {
2468 oldsigs = portp->sigs;
2469 portp->sigs = stli_mktiocm(nt.sigvalue);
2470 clear_bit(ST_GETSIGS, &portp->state);
2471 if ((portp->sigs & TIOCM_CD) &&
2472 ((oldsigs & TIOCM_CD) == 0))
2473 wake_up_interruptible(&portp->open_wait);
2474 if ((oldsigs & TIOCM_CD) &&
2475 ((portp->sigs & TIOCM_CD) == 0)) {
2476 if (portp->flags & ASYNC_CHECK_CD) {
2478 schedule_work(&portp->tqhangup);
2483 if (nt.data & DT_TXEMPTY)
2484 clear_bit(ST_TXBUSY, &portp->state);
2485 if (nt.data & (DT_TXEMPTY | DT_TXLOW)) {
2489 wake_up_interruptible(&tty->write_wait);
2493 if ((nt.data & DT_RXBREAK) && (portp->rxmarkmsk & BRKINT)) {
2495 tty_insert_flip_char(tty, 0, TTY_BREAK);
2496 if (portp->flags & ASYNC_SAK) {
2500 tty_schedule_flip(tty);
2504 if (nt.data & DT_RXBUSY) {
2506 stli_read(brdp, portp);
2511 * It might seem odd that we are checking for more RX chars here.
2512 * But, we need to handle the case where the tty buffer was previously
2513 * filled, but we had more characters to pass up. The slave will not
2514 * send any more RX notify messages until the RX buffer has been emptied.
2515 * But it will leave the service bits on (since the buffer is not empty).
2516 * So from here we can try to process more RX chars.
2518 if ((!donerx) && test_bit(ST_RXING, &portp->state)) {
2519 clear_bit(ST_RXING, &portp->state);
2520 stli_read(brdp, portp);
2523 return((test_bit(ST_OPENING, &portp->state) ||
2524 test_bit(ST_CLOSING, &portp->state) ||
2525 test_bit(ST_CMDING, &portp->state) ||
2526 test_bit(ST_TXBUSY, &portp->state) ||
2527 test_bit(ST_RXING, &portp->state)) ? 0 : 1);
2530 /*****************************************************************************/
2533 * Service all ports on a particular board. Assumes that the boards
2534 * shared memory is enabled, and that the page pointer is pointed
2535 * at the cdk header structure.
2538 static void stli_brdpoll(stlibrd_t *brdp, cdkhdr_t __iomem *hdrp)
2541 unsigned char hostbits[(STL_MAXCHANS / 8) + 1];
2542 unsigned char slavebits[(STL_MAXCHANS / 8) + 1];
2543 unsigned char __iomem *slavep;
2544 int bitpos, bitat, bitsize;
2545 int channr, nrdevs, slavebitchange;
2547 bitsize = brdp->bitsize;
2548 nrdevs = brdp->nrdevs;
2551 * Check if slave wants any service. Basically we try to do as
2552 * little work as possible here. There are 2 levels of service
2553 * bits. So if there is nothing to do we bail early. We check
2554 * 8 service bits at a time in the inner loop, so we can bypass
2555 * the lot if none of them want service.
2557 memcpy_fromio(&hostbits[0], (((unsigned char __iomem *) hdrp) + brdp->hostoffset),
2560 memset(&slavebits[0], 0, bitsize);
2563 for (bitpos = 0; (bitpos < bitsize); bitpos++) {
2564 if (hostbits[bitpos] == 0)
2566 channr = bitpos * 8;
2567 for (bitat = 0x1; (channr < nrdevs); channr++, bitat <<= 1) {
2568 if (hostbits[bitpos] & bitat) {
2569 portp = brdp->ports[(channr - 1)];
2570 if (stli_hostcmd(brdp, portp)) {
2572 slavebits[bitpos] |= bitat;
2579 * If any of the ports are no longer busy then update them in the
2580 * slave request bits. We need to do this after, since a host port
2581 * service may initiate more slave requests.
2583 if (slavebitchange) {
2584 hdrp = (cdkhdr_t __iomem *) EBRDGETMEMPTR(brdp, CDK_CDKADDR);
2585 slavep = ((unsigned char __iomem *) hdrp) + brdp->slaveoffset;
2586 for (bitpos = 0; (bitpos < bitsize); bitpos++) {
2587 if (readb(slavebits + bitpos))
2588 writeb(readb(slavep + bitpos) & ~slavebits[bitpos], slavebits + bitpos);
2593 /*****************************************************************************/
2596 * Driver poll routine. This routine polls the boards in use and passes
2597 * messages back up to host when necessary. This is actually very
2598 * CPU efficient, since we will always have the kernel poll clock, it
2599 * adds only a few cycles when idle (since board service can be
2600 * determined very easily), but when loaded generates no interrupts
2601 * (with their expensive associated context change).
2604 static void stli_poll(unsigned long arg)
2606 cdkhdr_t __iomem *hdrp;
2610 stli_timerlist.expires = STLI_TIMEOUT;
2611 add_timer(&stli_timerlist);
2614 * Check each board and do any servicing required.
2616 for (brdnr = 0; (brdnr < stli_nrbrds); brdnr++) {
2617 brdp = stli_brds[brdnr];
2620 if ((brdp->state & BST_STARTED) == 0)
2623 spin_lock(&brd_lock);
2625 hdrp = (cdkhdr_t __iomem *) EBRDGETMEMPTR(brdp, CDK_CDKADDR);
2626 if (readb(&hdrp->hostreq))
2627 stli_brdpoll(brdp, hdrp);
2629 spin_unlock(&brd_lock);
2633 /*****************************************************************************/
2636 * Translate the termios settings into the port setting structure of
2640 static void stli_mkasyport(stliport_t *portp, asyport_t *pp, struct ktermios *tiosp)
2642 memset(pp, 0, sizeof(asyport_t));
2645 * Start of by setting the baud, char size, parity and stop bit info.
2647 pp->baudout = tty_get_baud_rate(portp->tty);
2648 if ((tiosp->c_cflag & CBAUD) == B38400) {
2649 if ((portp->flags & ASYNC_SPD_MASK) == ASYNC_SPD_HI)
2650 pp->baudout = 57600;
2651 else if ((portp->flags & ASYNC_SPD_MASK) == ASYNC_SPD_VHI)
2652 pp->baudout = 115200;
2653 else if ((portp->flags & ASYNC_SPD_MASK) == ASYNC_SPD_SHI)
2654 pp->baudout = 230400;
2655 else if ((portp->flags & ASYNC_SPD_MASK) == ASYNC_SPD_WARP)
2656 pp->baudout = 460800;
2657 else if ((portp->flags & ASYNC_SPD_MASK) == ASYNC_SPD_CUST)
2658 pp->baudout = (portp->baud_base / portp->custom_divisor);
2660 if (pp->baudout > STL_MAXBAUD)
2661 pp->baudout = STL_MAXBAUD;
2662 pp->baudin = pp->baudout;
2664 switch (tiosp->c_cflag & CSIZE) {
2679 if (tiosp->c_cflag & CSTOPB)
2680 pp->stopbs = PT_STOP2;
2682 pp->stopbs = PT_STOP1;
2684 if (tiosp->c_cflag & PARENB) {
2685 if (tiosp->c_cflag & PARODD)
2686 pp->parity = PT_ODDPARITY;
2688 pp->parity = PT_EVENPARITY;
2690 pp->parity = PT_NOPARITY;
2694 * Set up any flow control options enabled.
2696 if (tiosp->c_iflag & IXON) {
2698 if (tiosp->c_iflag & IXANY)
2699 pp->flow |= F_IXANY;
2701 if (tiosp->c_cflag & CRTSCTS)
2702 pp->flow |= (F_RTSFLOW | F_CTSFLOW);
2704 pp->startin = tiosp->c_cc[VSTART];
2705 pp->stopin = tiosp->c_cc[VSTOP];
2706 pp->startout = tiosp->c_cc[VSTART];
2707 pp->stopout = tiosp->c_cc[VSTOP];
2710 * Set up the RX char marking mask with those RX error types we must
2711 * catch. We can get the slave to help us out a little here, it will
2712 * ignore parity errors and breaks for us, and mark parity errors in
2715 if (tiosp->c_iflag & IGNPAR)
2716 pp->iflag |= FI_IGNRXERRS;
2717 if (tiosp->c_iflag & IGNBRK)
2718 pp->iflag |= FI_IGNBREAK;
2720 portp->rxmarkmsk = 0;
2721 if (tiosp->c_iflag & (INPCK | PARMRK))
2722 pp->iflag |= FI_1MARKRXERRS;
2723 if (tiosp->c_iflag & BRKINT)
2724 portp->rxmarkmsk |= BRKINT;
2727 * Set up clocal processing as required.
2729 if (tiosp->c_cflag & CLOCAL)
2730 portp->flags &= ~ASYNC_CHECK_CD;
2732 portp->flags |= ASYNC_CHECK_CD;
2735 * Transfer any persistent flags into the asyport structure.
2737 pp->pflag = (portp->pflag & 0xffff);
2738 pp->vmin = (portp->pflag & P_RXIMIN) ? 1 : 0;
2739 pp->vtime = (portp->pflag & P_RXITIME) ? 1 : 0;
2740 pp->cc[1] = (portp->pflag & P_RXTHOLD) ? 1 : 0;
2743 /*****************************************************************************/
2746 * Construct a slave signals structure for setting the DTR and RTS
2747 * signals as specified.
2750 static void stli_mkasysigs(asysigs_t *sp, int dtr, int rts)
2752 memset(sp, 0, sizeof(asysigs_t));
2754 sp->signal |= SG_DTR;
2755 sp->sigvalue |= ((dtr > 0) ? SG_DTR : 0);
2758 sp->signal |= SG_RTS;
2759 sp->sigvalue |= ((rts > 0) ? SG_RTS : 0);
2763 /*****************************************************************************/
2766 * Convert the signals returned from the slave into a local TIOCM type
2767 * signals value. We keep them locally in TIOCM format.
2770 static long stli_mktiocm(unsigned long sigvalue)
2773 tiocm |= ((sigvalue & SG_DCD) ? TIOCM_CD : 0);
2774 tiocm |= ((sigvalue & SG_CTS) ? TIOCM_CTS : 0);
2775 tiocm |= ((sigvalue & SG_RI) ? TIOCM_RI : 0);
2776 tiocm |= ((sigvalue & SG_DSR) ? TIOCM_DSR : 0);
2777 tiocm |= ((sigvalue & SG_DTR) ? TIOCM_DTR : 0);
2778 tiocm |= ((sigvalue & SG_RTS) ? TIOCM_RTS : 0);
2782 /*****************************************************************************/
2785 * All panels and ports actually attached have been worked out. All
2786 * we need to do here is set up the appropriate per port data structures.
2789 static int stli_initports(stlibrd_t *brdp)
2792 int i, panelnr, panelport;
2794 for (i = 0, panelnr = 0, panelport = 0; (i < brdp->nrports); i++) {
2795 portp = kzalloc(sizeof(stliport_t), GFP_KERNEL);
2797 printk("STALLION: failed to allocate port structure\n");
2801 portp->magic = STLI_PORTMAGIC;
2803 portp->brdnr = brdp->brdnr;
2804 portp->panelnr = panelnr;
2805 portp->baud_base = STL_BAUDBASE;
2806 portp->close_delay = STL_CLOSEDELAY;
2807 portp->closing_wait = 30 * HZ;
2808 INIT_WORK(&portp->tqhangup, stli_dohangup);
2809 init_waitqueue_head(&portp->open_wait);
2810 init_waitqueue_head(&portp->close_wait);
2811 init_waitqueue_head(&portp->raw_wait);
2813 if (panelport >= brdp->panels[panelnr]) {
2817 brdp->ports[i] = portp;
2823 /*****************************************************************************/
2826 * All the following routines are board specific hardware operations.
2829 static void stli_ecpinit(stlibrd_t *brdp)
2831 unsigned long memconf;
2833 outb(ECP_ATSTOP, (brdp->iobase + ECP_ATCONFR));
2835 outb(ECP_ATDISABLE, (brdp->iobase + ECP_ATCONFR));
2838 memconf = (brdp->memaddr & ECP_ATADDRMASK) >> ECP_ATADDRSHFT;
2839 outb(memconf, (brdp->iobase + ECP_ATMEMAR));
2842 /*****************************************************************************/
2844 static void stli_ecpenable(stlibrd_t *brdp)
2846 outb(ECP_ATENABLE, (brdp->iobase + ECP_ATCONFR));
2849 /*****************************************************************************/
2851 static void stli_ecpdisable(stlibrd_t *brdp)
2853 outb(ECP_ATDISABLE, (brdp->iobase + ECP_ATCONFR));
2856 /*****************************************************************************/
2858 static void __iomem *stli_ecpgetmemptr(stlibrd_t *brdp, unsigned long offset, int line)
2863 if (offset > brdp->memsize) {
2864 printk(KERN_ERR "STALLION: shared memory pointer=%x out of "
2865 "range at line=%d(%d), brd=%d\n",
2866 (int) offset, line, __LINE__, brdp->brdnr);
2870 ptr = brdp->membase + (offset % ECP_ATPAGESIZE);
2871 val = (unsigned char) (offset / ECP_ATPAGESIZE);
2873 outb(val, (brdp->iobase + ECP_ATMEMPR));
2877 /*****************************************************************************/
2879 static void stli_ecpreset(stlibrd_t *brdp)
2881 outb(ECP_ATSTOP, (brdp->iobase + ECP_ATCONFR));
2883 outb(ECP_ATDISABLE, (brdp->iobase + ECP_ATCONFR));
2887 /*****************************************************************************/
2889 static void stli_ecpintr(stlibrd_t *brdp)
2891 outb(0x1, brdp->iobase);
2894 /*****************************************************************************/
2897 * The following set of functions act on ECP EISA boards.
2900 static void stli_ecpeiinit(stlibrd_t *brdp)
2902 unsigned long memconf;
2904 outb(0x1, (brdp->iobase + ECP_EIBRDENAB));
2905 outb(ECP_EISTOP, (brdp->iobase + ECP_EICONFR));
2907 outb(ECP_EIDISABLE, (brdp->iobase + ECP_EICONFR));
2910 memconf = (brdp->memaddr & ECP_EIADDRMASKL) >> ECP_EIADDRSHFTL;
2911 outb(memconf, (brdp->iobase + ECP_EIMEMARL));
2912 memconf = (brdp->memaddr & ECP_EIADDRMASKH) >> ECP_EIADDRSHFTH;
2913 outb(memconf, (brdp->iobase + ECP_EIMEMARH));
2916 /*****************************************************************************/
2918 static void stli_ecpeienable(stlibrd_t *brdp)
2920 outb(ECP_EIENABLE, (brdp->iobase + ECP_EICONFR));
2923 /*****************************************************************************/
2925 static void stli_ecpeidisable(stlibrd_t *brdp)
2927 outb(ECP_EIDISABLE, (brdp->iobase + ECP_EICONFR));
2930 /*****************************************************************************/
2932 static void __iomem *stli_ecpeigetmemptr(stlibrd_t *brdp, unsigned long offset, int line)
2937 if (offset > brdp->memsize) {
2938 printk(KERN_ERR "STALLION: shared memory pointer=%x out of "
2939 "range at line=%d(%d), brd=%d\n",
2940 (int) offset, line, __LINE__, brdp->brdnr);
2944 ptr = brdp->membase + (offset % ECP_EIPAGESIZE);
2945 if (offset < ECP_EIPAGESIZE)
2948 val = ECP_EIENABLE | 0x40;
2950 outb(val, (brdp->iobase + ECP_EICONFR));
2954 /*****************************************************************************/
2956 static void stli_ecpeireset(stlibrd_t *brdp)
2958 outb(ECP_EISTOP, (brdp->iobase + ECP_EICONFR));
2960 outb(ECP_EIDISABLE, (brdp->iobase + ECP_EICONFR));
2964 /*****************************************************************************/
2967 * The following set of functions act on ECP MCA boards.
2970 static void stli_ecpmcenable(stlibrd_t *brdp)
2972 outb(ECP_MCENABLE, (brdp->iobase + ECP_MCCONFR));
2975 /*****************************************************************************/
2977 static void stli_ecpmcdisable(stlibrd_t *brdp)
2979 outb(ECP_MCDISABLE, (brdp->iobase + ECP_MCCONFR));
2982 /*****************************************************************************/
2984 static void __iomem *stli_ecpmcgetmemptr(stlibrd_t *brdp, unsigned long offset, int line)
2989 if (offset > brdp->memsize) {
2990 printk(KERN_ERR "STALLION: shared memory pointer=%x out of "
2991 "range at line=%d(%d), brd=%d\n",
2992 (int) offset, line, __LINE__, brdp->brdnr);
2996 ptr = brdp->membase + (offset % ECP_MCPAGESIZE);
2997 val = ((unsigned char) (offset / ECP_MCPAGESIZE)) | ECP_MCENABLE;
2999 outb(val, (brdp->iobase + ECP_MCCONFR));
3003 /*****************************************************************************/
3005 static void stli_ecpmcreset(stlibrd_t *brdp)
3007 outb(ECP_MCSTOP, (brdp->iobase + ECP_MCCONFR));
3009 outb(ECP_MCDISABLE, (brdp->iobase + ECP_MCCONFR));
3013 /*****************************************************************************/
3016 * The following set of functions act on ECP PCI boards.
3019 static void stli_ecppciinit(stlibrd_t *brdp)
3021 outb(ECP_PCISTOP, (brdp->iobase + ECP_PCICONFR));
3023 outb(0, (brdp->iobase + ECP_PCICONFR));
3027 /*****************************************************************************/
3029 static void __iomem *stli_ecppcigetmemptr(stlibrd_t *brdp, unsigned long offset, int line)
3034 if (offset > brdp->memsize) {
3035 printk(KERN_ERR "STALLION: shared memory pointer=%x out of "
3036 "range at line=%d(%d), board=%d\n",
3037 (int) offset, line, __LINE__, brdp->brdnr);
3041 ptr = brdp->membase + (offset % ECP_PCIPAGESIZE);
3042 val = (offset / ECP_PCIPAGESIZE) << 1;
3044 outb(val, (brdp->iobase + ECP_PCICONFR));
3048 /*****************************************************************************/
3050 static void stli_ecppcireset(stlibrd_t *brdp)
3052 outb(ECP_PCISTOP, (brdp->iobase + ECP_PCICONFR));
3054 outb(0, (brdp->iobase + ECP_PCICONFR));
3058 /*****************************************************************************/
3061 * The following routines act on ONboards.
3064 static void stli_onbinit(stlibrd_t *brdp)
3066 unsigned long memconf;
3068 outb(ONB_ATSTOP, (brdp->iobase + ONB_ATCONFR));
3070 outb(ONB_ATDISABLE, (brdp->iobase + ONB_ATCONFR));
3073 memconf = (brdp->memaddr & ONB_ATADDRMASK) >> ONB_ATADDRSHFT;
3074 outb(memconf, (brdp->iobase + ONB_ATMEMAR));
3075 outb(0x1, brdp->iobase);
3079 /*****************************************************************************/
3081 static void stli_onbenable(stlibrd_t *brdp)
3083 outb((brdp->enabval | ONB_ATENABLE), (brdp->iobase + ONB_ATCONFR));
3086 /*****************************************************************************/
3088 static void stli_onbdisable(stlibrd_t *brdp)
3090 outb((brdp->enabval | ONB_ATDISABLE), (brdp->iobase + ONB_ATCONFR));
3093 /*****************************************************************************/
3095 static void __iomem *stli_onbgetmemptr(stlibrd_t *brdp, unsigned long offset, int line)
3099 if (offset > brdp->memsize) {
3100 printk(KERN_ERR "STALLION: shared memory pointer=%x out of "
3101 "range at line=%d(%d), brd=%d\n",
3102 (int) offset, line, __LINE__, brdp->brdnr);
3105 ptr = brdp->membase + (offset % ONB_ATPAGESIZE);
3110 /*****************************************************************************/
3112 static void stli_onbreset(stlibrd_t *brdp)
3114 outb(ONB_ATSTOP, (brdp->iobase + ONB_ATCONFR));
3116 outb(ONB_ATDISABLE, (brdp->iobase + ONB_ATCONFR));
3120 /*****************************************************************************/
3123 * The following routines act on ONboard EISA.
3126 static void stli_onbeinit(stlibrd_t *brdp)
3128 unsigned long memconf;
3130 outb(0x1, (brdp->iobase + ONB_EIBRDENAB));
3131 outb(ONB_EISTOP, (brdp->iobase + ONB_EICONFR));
3133 outb(ONB_EIDISABLE, (brdp->iobase + ONB_EICONFR));
3136 memconf = (brdp->memaddr & ONB_EIADDRMASKL) >> ONB_EIADDRSHFTL;
3137 outb(memconf, (brdp->iobase + ONB_EIMEMARL));
3138 memconf = (brdp->memaddr & ONB_EIADDRMASKH) >> ONB_EIADDRSHFTH;
3139 outb(memconf, (brdp->iobase + ONB_EIMEMARH));
3140 outb(0x1, brdp->iobase);
3144 /*****************************************************************************/
3146 static void stli_onbeenable(stlibrd_t *brdp)
3148 outb(ONB_EIENABLE, (brdp->iobase + ONB_EICONFR));
3151 /*****************************************************************************/
3153 static void stli_onbedisable(stlibrd_t *brdp)
3155 outb(ONB_EIDISABLE, (brdp->iobase + ONB_EICONFR));
3158 /*****************************************************************************/
3160 static void __iomem *stli_onbegetmemptr(stlibrd_t *brdp, unsigned long offset, int line)
3165 if (offset > brdp->memsize) {
3166 printk(KERN_ERR "STALLION: shared memory pointer=%x out of "
3167 "range at line=%d(%d), brd=%d\n",
3168 (int) offset, line, __LINE__, brdp->brdnr);
3172 ptr = brdp->membase + (offset % ONB_EIPAGESIZE);
3173 if (offset < ONB_EIPAGESIZE)
3176 val = ONB_EIENABLE | 0x40;
3178 outb(val, (brdp->iobase + ONB_EICONFR));
3182 /*****************************************************************************/
3184 static void stli_onbereset(stlibrd_t *brdp)
3186 outb(ONB_EISTOP, (brdp->iobase + ONB_EICONFR));
3188 outb(ONB_EIDISABLE, (brdp->iobase + ONB_EICONFR));
3192 /*****************************************************************************/
3195 * The following routines act on Brumby boards.
3198 static void stli_bbyinit(stlibrd_t *brdp)
3200 outb(BBY_ATSTOP, (brdp->iobase + BBY_ATCONFR));
3202 outb(0, (brdp->iobase + BBY_ATCONFR));
3204 outb(0x1, brdp->iobase);
3208 /*****************************************************************************/
3210 static void __iomem *stli_bbygetmemptr(stlibrd_t *brdp, unsigned long offset, int line)
3215 BUG_ON(offset > brdp->memsize);
3217 ptr = brdp->membase + (offset % BBY_PAGESIZE);
3218 val = (unsigned char) (offset / BBY_PAGESIZE);
3219 outb(val, (brdp->iobase + BBY_ATCONFR));
3223 /*****************************************************************************/
3225 static void stli_bbyreset(stlibrd_t *brdp)
3227 outb(BBY_ATSTOP, (brdp->iobase + BBY_ATCONFR));
3229 outb(0, (brdp->iobase + BBY_ATCONFR));
3233 /*****************************************************************************/
3236 * The following routines act on original old Stallion boards.
3239 static void stli_stalinit(stlibrd_t *brdp)
3241 outb(0x1, brdp->iobase);
3245 /*****************************************************************************/
3247 static void __iomem *stli_stalgetmemptr(stlibrd_t *brdp, unsigned long offset, int line)
3249 BUG_ON(offset > brdp->memsize);
3250 return brdp->membase + (offset % STAL_PAGESIZE);
3253 /*****************************************************************************/
3255 static void stli_stalreset(stlibrd_t *brdp)
3259 vecp = (u32 __iomem *) (brdp->membase + 0x30);
3260 writel(0xffff0000, vecp);
3261 outb(0, brdp->iobase);
3265 /*****************************************************************************/
3268 * Try to find an ECP board and initialize it. This handles only ECP
3272 static int stli_initecp(stlibrd_t *brdp)
3275 cdkecpsig_t __iomem *sigsp;
3276 unsigned int status, nxtid;
3278 int panelnr, nrports;
3280 if (!request_region(brdp->iobase, brdp->iosize, "istallion"))
3283 if ((brdp->iobase == 0) || (brdp->memaddr == 0))
3285 release_region(brdp->iobase, brdp->iosize);
3289 brdp->iosize = ECP_IOSIZE;
3292 * Based on the specific board type setup the common vars to access
3293 * and enable shared memory. Set all board specific information now
3296 switch (brdp->brdtype) {
3298 brdp->memsize = ECP_MEMSIZE;
3299 brdp->pagesize = ECP_ATPAGESIZE;
3300 brdp->init = stli_ecpinit;
3301 brdp->enable = stli_ecpenable;
3302 brdp->reenable = stli_ecpenable;
3303 brdp->disable = stli_ecpdisable;
3304 brdp->getmemptr = stli_ecpgetmemptr;
3305 brdp->intr = stli_ecpintr;
3306 brdp->reset = stli_ecpreset;
3307 name = "serial(EC8/64)";
3311 brdp->memsize = ECP_MEMSIZE;
3312 brdp->pagesize = ECP_EIPAGESIZE;
3313 brdp->init = stli_ecpeiinit;
3314 brdp->enable = stli_ecpeienable;
3315 brdp->reenable = stli_ecpeienable;
3316 brdp->disable = stli_ecpeidisable;
3317 brdp->getmemptr = stli_ecpeigetmemptr;
3318 brdp->intr = stli_ecpintr;
3319 brdp->reset = stli_ecpeireset;
3320 name = "serial(EC8/64-EI)";
3324 brdp->memsize = ECP_MEMSIZE;
3325 brdp->pagesize = ECP_MCPAGESIZE;
3327 brdp->enable = stli_ecpmcenable;
3328 brdp->reenable = stli_ecpmcenable;
3329 brdp->disable = stli_ecpmcdisable;
3330 brdp->getmemptr = stli_ecpmcgetmemptr;
3331 brdp->intr = stli_ecpintr;
3332 brdp->reset = stli_ecpmcreset;
3333 name = "serial(EC8/64-MCA)";
3337 brdp->memsize = ECP_PCIMEMSIZE;
3338 brdp->pagesize = ECP_PCIPAGESIZE;
3339 brdp->init = stli_ecppciinit;
3340 brdp->enable = NULL;
3341 brdp->reenable = NULL;
3342 brdp->disable = NULL;
3343 brdp->getmemptr = stli_ecppcigetmemptr;
3344 brdp->intr = stli_ecpintr;
3345 brdp->reset = stli_ecppcireset;
3346 name = "serial(EC/RA-PCI)";
3350 release_region(brdp->iobase, brdp->iosize);
3355 * The per-board operations structure is all set up, so now let's go
3356 * and get the board operational. Firstly initialize board configuration
3357 * registers. Set the memory mapping info so we can get at the boards
3362 brdp->membase = ioremap(brdp->memaddr, brdp->memsize);
3363 if (brdp->membase == NULL)
3365 release_region(brdp->iobase, brdp->iosize);
3370 * Now that all specific code is set up, enable the shared memory and
3371 * look for the a signature area that will tell us exactly what board
3372 * this is, and what it is connected to it.
3375 sigsp = (cdkecpsig_t __iomem *) EBRDGETMEMPTR(brdp, CDK_SIGADDR);
3376 memcpy_fromio(&sig, sigsp, sizeof(cdkecpsig_t));
3379 if (sig.magic != cpu_to_le32(ECP_MAGIC))
3381 release_region(brdp->iobase, brdp->iosize);
3382 iounmap(brdp->membase);
3383 brdp->membase = NULL;
3388 * Scan through the signature looking at the panels connected to the
3389 * board. Calculate the total number of ports as we go.
3391 for (panelnr = 0, nxtid = 0; (panelnr < STL_MAXPANELS); panelnr++) {
3392 status = sig.panelid[nxtid];
3393 if ((status & ECH_PNLIDMASK) != nxtid)
3396 brdp->panelids[panelnr] = status;
3397 nrports = (status & ECH_PNL16PORT) ? 16 : 8;
3398 if ((nrports == 16) && ((status & ECH_PNLXPID) == 0))
3400 brdp->panels[panelnr] = nrports;
3401 brdp->nrports += nrports;
3407 brdp->state |= BST_FOUND;
3411 /*****************************************************************************/
3414 * Try to find an ONboard, Brumby or Stallion board and initialize it.
3415 * This handles only these board types.
3418 static int stli_initonb(stlibrd_t *brdp)
3421 cdkonbsig_t __iomem *sigsp;
3426 * Do a basic sanity check on the IO and memory addresses.
3428 if (brdp->iobase == 0 || brdp->memaddr == 0)
3431 brdp->iosize = ONB_IOSIZE;
3433 if (!request_region(brdp->iobase, brdp->iosize, "istallion"))
3437 * Based on the specific board type setup the common vars to access
3438 * and enable shared memory. Set all board specific information now
3441 switch (brdp->brdtype) {
3444 brdp->memsize = ONB_MEMSIZE;
3445 brdp->pagesize = ONB_ATPAGESIZE;
3446 brdp->init = stli_onbinit;
3447 brdp->enable = stli_onbenable;
3448 brdp->reenable = stli_onbenable;
3449 brdp->disable = stli_onbdisable;
3450 brdp->getmemptr = stli_onbgetmemptr;
3451 brdp->intr = stli_ecpintr;
3452 brdp->reset = stli_onbreset;
3453 if (brdp->memaddr > 0x100000)
3454 brdp->enabval = ONB_MEMENABHI;
3456 brdp->enabval = ONB_MEMENABLO;
3457 name = "serial(ONBoard)";
3461 brdp->memsize = ONB_EIMEMSIZE;
3462 brdp->pagesize = ONB_EIPAGESIZE;
3463 brdp->init = stli_onbeinit;
3464 brdp->enable = stli_onbeenable;
3465 brdp->reenable = stli_onbeenable;
3466 brdp->disable = stli_onbedisable;
3467 brdp->getmemptr = stli_onbegetmemptr;
3468 brdp->intr = stli_ecpintr;
3469 brdp->reset = stli_onbereset;
3470 name = "serial(ONBoard/E)";
3474 brdp->memsize = BBY_MEMSIZE;
3475 brdp->pagesize = BBY_PAGESIZE;
3476 brdp->init = stli_bbyinit;
3477 brdp->enable = NULL;
3478 brdp->reenable = NULL;
3479 brdp->disable = NULL;
3480 brdp->getmemptr = stli_bbygetmemptr;
3481 brdp->intr = stli_ecpintr;
3482 brdp->reset = stli_bbyreset;
3483 name = "serial(Brumby)";
3487 brdp->memsize = STAL_MEMSIZE;
3488 brdp->pagesize = STAL_PAGESIZE;
3489 brdp->init = stli_stalinit;
3490 brdp->enable = NULL;
3491 brdp->reenable = NULL;
3492 brdp->disable = NULL;
3493 brdp->getmemptr = stli_stalgetmemptr;
3494 brdp->intr = stli_ecpintr;
3495 brdp->reset = stli_stalreset;
3496 name = "serial(Stallion)";
3500 release_region(brdp->iobase, brdp->iosize);
3505 * The per-board operations structure is all set up, so now let's go
3506 * and get the board operational. Firstly initialize board configuration
3507 * registers. Set the memory mapping info so we can get at the boards
3512 brdp->membase = ioremap(brdp->memaddr, brdp->memsize);
3513 if (brdp->membase == NULL)
3515 release_region(brdp->iobase, brdp->iosize);
3520 * Now that all specific code is set up, enable the shared memory and
3521 * look for the a signature area that will tell us exactly what board
3522 * this is, and how many ports.
3525 sigsp = (cdkonbsig_t __iomem *) EBRDGETMEMPTR(brdp, CDK_SIGADDR);
3526 memcpy_fromio(&sig, sigsp, sizeof(cdkonbsig_t));
3529 if (sig.magic0 != cpu_to_le16(ONB_MAGIC0) ||
3530 sig.magic1 != cpu_to_le16(ONB_MAGIC1) ||
3531 sig.magic2 != cpu_to_le16(ONB_MAGIC2) ||
3532 sig.magic3 != cpu_to_le16(ONB_MAGIC3))
3534 release_region(brdp->iobase, brdp->iosize);
3535 iounmap(brdp->membase);
3536 brdp->membase = NULL;
3541 * Scan through the signature alive mask and calculate how many ports
3542 * there are on this board.
3548 for (i = 0; (i < 16); i++) {
3549 if (((sig.amask0 << i) & 0x8000) == 0)
3554 brdp->panels[0] = brdp->nrports;
3557 brdp->state |= BST_FOUND;
3561 /*****************************************************************************/
3564 * Start up a running board. This routine is only called after the
3565 * code has been down loaded to the board and is operational. It will
3566 * read in the memory map, and get the show on the road...
3569 static int stli_startbrd(stlibrd_t *brdp)
3571 cdkhdr_t __iomem *hdrp;
3572 cdkmem_t __iomem *memp;
3573 cdkasy_t __iomem *ap;
3574 unsigned long flags;
3576 int portnr, nrdevs, i, rc = 0;
3579 spin_lock_irqsave(&brd_lock, flags);
3581 hdrp = (cdkhdr_t __iomem *) EBRDGETMEMPTR(brdp, CDK_CDKADDR);
3582 nrdevs = hdrp->nrdevs;
3585 printk("%s(%d): CDK version %d.%d.%d --> "
3586 "nrdevs=%d memp=%x hostp=%x slavep=%x\n",
3587 __FILE__, __LINE__, readb(&hdrp->ver_release), readb(&hdrp->ver_modification),
3588 readb(&hdrp->ver_fix), nrdevs, (int) readl(&hdrp->memp), readl(&hdrp->hostp),
3589 readl(&hdrp->slavep));
3592 if (nrdevs < (brdp->nrports + 1)) {
3593 printk(KERN_ERR "STALLION: slave failed to allocate memory for "
3594 "all devices, devices=%d\n", nrdevs);
3595 brdp->nrports = nrdevs - 1;
3597 brdp->nrdevs = nrdevs;
3598 brdp->hostoffset = hdrp->hostp - CDK_CDKADDR;
3599 brdp->slaveoffset = hdrp->slavep - CDK_CDKADDR;
3600 brdp->bitsize = (nrdevs + 7) / 8;
3601 memoff = readl(&hdrp->memp);
3602 if (memoff > brdp->memsize) {
3603 printk(KERN_ERR "STALLION: corrupted shared memory region?\n");
3605 goto stli_donestartup;
3607 memp = (cdkmem_t __iomem *) EBRDGETMEMPTR(brdp, memoff);
3608 if (readw(&memp->dtype) != TYP_ASYNCTRL) {
3609 printk(KERN_ERR "STALLION: no slave control device found\n");
3610 goto stli_donestartup;
3615 * Cycle through memory allocation of each port. We are guaranteed to
3616 * have all ports inside the first page of slave window, so no need to
3617 * change pages while reading memory map.
3619 for (i = 1, portnr = 0; (i < nrdevs); i++, portnr++, memp++) {
3620 if (readw(&memp->dtype) != TYP_ASYNC)
3622 portp = brdp->ports[portnr];
3626 portp->addr = readl(&memp->offset);
3627 portp->reqbit = (unsigned char) (0x1 << (i * 8 / nrdevs));
3628 portp->portidx = (unsigned char) (i / 8);
3629 portp->portbit = (unsigned char) (0x1 << (i % 8));
3632 writeb(0xff, &hdrp->slavereq);
3635 * For each port setup a local copy of the RX and TX buffer offsets
3636 * and sizes. We do this separate from the above, because we need to
3637 * move the shared memory page...
3639 for (i = 1, portnr = 0; (i < nrdevs); i++, portnr++) {
3640 portp = brdp->ports[portnr];
3643 if (portp->addr == 0)
3645 ap = (cdkasy_t __iomem *) EBRDGETMEMPTR(brdp, portp->addr);
3647 portp->rxsize = readw(&ap->rxq.size);
3648 portp->txsize = readw(&ap->txq.size);
3649 portp->rxoffset = readl(&ap->rxq.offset);
3650 portp->txoffset = readl(&ap->txq.offset);
3656 spin_unlock_irqrestore(&brd_lock, flags);
3659 brdp->state |= BST_STARTED;
3661 if (! stli_timeron) {
3663 stli_timerlist.expires = STLI_TIMEOUT;
3664 add_timer(&stli_timerlist);
3670 /*****************************************************************************/
3673 * Probe and initialize the specified board.
3676 static int __devinit stli_brdinit(stlibrd_t *brdp)
3678 stli_brds[brdp->brdnr] = brdp;
3680 switch (brdp->brdtype) {
3695 printk(KERN_ERR "STALLION: board=%d is unknown board "
3696 "type=%d\n", brdp->brdnr, brdp->brdtype);
3700 if ((brdp->state & BST_FOUND) == 0) {
3701 printk(KERN_ERR "STALLION: %s board not found, board=%d "
3703 stli_brdnames[brdp->brdtype], brdp->brdnr,
3704 brdp->iobase, (int) brdp->memaddr);
3708 stli_initports(brdp);
3709 printk(KERN_INFO "STALLION: %s found, board=%d io=%x mem=%x "
3710 "nrpanels=%d nrports=%d\n", stli_brdnames[brdp->brdtype],
3711 brdp->brdnr, brdp->iobase, (int) brdp->memaddr,
3712 brdp->nrpanels, brdp->nrports);
3716 /*****************************************************************************/
3719 * Probe around trying to find where the EISA boards shared memory
3720 * might be. This is a bit if hack, but it is the best we can do.
3723 static int stli_eisamemprobe(stlibrd_t *brdp)
3725 cdkecpsig_t ecpsig, __iomem *ecpsigp;
3726 cdkonbsig_t onbsig, __iomem *onbsigp;
3730 * First up we reset the board, to get it into a known state. There
3731 * is only 2 board types here we need to worry about. Don;t use the
3732 * standard board init routine here, it programs up the shared
3733 * memory address, and we don't know it yet...
3735 if (brdp->brdtype == BRD_ECPE) {
3736 outb(0x1, (brdp->iobase + ECP_EIBRDENAB));
3737 outb(ECP_EISTOP, (brdp->iobase + ECP_EICONFR));
3739 outb(ECP_EIDISABLE, (brdp->iobase + ECP_EICONFR));
3741 stli_ecpeienable(brdp);
3742 } else if (brdp->brdtype == BRD_ONBOARDE) {
3743 outb(0x1, (brdp->iobase + ONB_EIBRDENAB));
3744 outb(ONB_EISTOP, (brdp->iobase + ONB_EICONFR));
3746 outb(ONB_EIDISABLE, (brdp->iobase + ONB_EICONFR));
3748 outb(0x1, brdp->iobase);
3750 stli_onbeenable(brdp);
3756 brdp->memsize = ECP_MEMSIZE;
3759 * Board shared memory is enabled, so now we have a poke around and
3760 * see if we can find it.
3762 for (i = 0; (i < stli_eisamempsize); i++) {
3763 brdp->memaddr = stli_eisamemprobeaddrs[i];
3764 brdp->membase = ioremap(brdp->memaddr, brdp->memsize);
3765 if (brdp->membase == NULL)
3768 if (brdp->brdtype == BRD_ECPE) {
3769 ecpsigp = stli_ecpeigetmemptr(brdp,
3770 CDK_SIGADDR, __LINE__);
3771 memcpy_fromio(&ecpsig, ecpsigp, sizeof(cdkecpsig_t));
3772 if (ecpsig.magic == cpu_to_le32(ECP_MAGIC))
3775 onbsigp = (cdkonbsig_t __iomem *) stli_onbegetmemptr(brdp,
3776 CDK_SIGADDR, __LINE__);
3777 memcpy_fromio(&onbsig, onbsigp, sizeof(cdkonbsig_t));
3778 if ((onbsig.magic0 == cpu_to_le16(ONB_MAGIC0)) &&
3779 (onbsig.magic1 == cpu_to_le16(ONB_MAGIC1)) &&
3780 (onbsig.magic2 == cpu_to_le16(ONB_MAGIC2)) &&
3781 (onbsig.magic3 == cpu_to_le16(ONB_MAGIC3)))
3785 iounmap(brdp->membase);
3791 * Regardless of whether we found the shared memory or not we must
3792 * disable the region. After that return success or failure.
3794 if (brdp->brdtype == BRD_ECPE)
3795 stli_ecpeidisable(brdp);
3797 stli_onbedisable(brdp);
3801 brdp->membase = NULL;
3802 printk(KERN_ERR "STALLION: failed to probe shared memory "
3803 "region for %s in EISA slot=%d\n",
3804 stli_brdnames[brdp->brdtype], (brdp->iobase >> 12));
3810 static int stli_getbrdnr(void)
3814 for (i = 0; i < STL_MAXBRDS; i++) {
3815 if (!stli_brds[i]) {
3816 if (i >= stli_nrbrds)
3817 stli_nrbrds = i + 1;
3824 /*****************************************************************************/
3827 * Probe around and try to find any EISA boards in system. The biggest
3828 * problem here is finding out what memory address is associated with
3829 * an EISA board after it is found. The registers of the ECPE and
3830 * ONboardE are not readable - so we can't read them from there. We
3831 * don't have access to the EISA CMOS (or EISA BIOS) so we don't
3832 * actually have any way to find out the real value. The best we can
3833 * do is go probing around in the usual places hoping we can find it.
3836 static int stli_findeisabrds(void)
3839 unsigned int iobase, eid;
3843 * Firstly check if this is an EISA system. If this is not an EISA system then
3844 * don't bother going any further!
3850 * Looks like an EISA system, so go searching for EISA boards.
3852 for (iobase = 0x1000; (iobase <= 0xc000); iobase += 0x1000) {
3853 outb(0xff, (iobase + 0xc80));
3854 eid = inb(iobase + 0xc80);
3855 eid |= inb(iobase + 0xc81) << 8;
3856 if (eid != STL_EISAID)
3860 * We have found a board. Need to check if this board was
3861 * statically configured already (just in case!).
3863 for (i = 0; (i < STL_MAXBRDS); i++) {
3864 brdp = stli_brds[i];
3867 if (brdp->iobase == iobase)
3870 if (i < STL_MAXBRDS)
3874 * We have found a Stallion board and it is not configured already.
3875 * Allocate a board structure and initialize it.
3877 if ((brdp = stli_allocbrd()) == NULL)
3879 if ((brdp->brdnr = stli_getbrdnr()) < 0)
3881 eid = inb(iobase + 0xc82);
3882 if (eid == ECP_EISAID)
3883 brdp->brdtype = BRD_ECPE;
3884 else if (eid == ONB_EISAID)
3885 brdp->brdtype = BRD_ONBOARDE;
3887 brdp->brdtype = BRD_UNKNOWN;
3888 brdp->iobase = iobase;
3889 outb(0x1, (iobase + 0xc84));
3890 if (stli_eisamemprobe(brdp))
3891 outb(0, (iobase + 0xc84));
3898 /*****************************************************************************/
3901 * Find the next available board number that is free.
3904 /*****************************************************************************/
3907 * We have a Stallion board. Allocate a board structure and
3908 * initialize it. Read its IO and MEMORY resources from PCI
3909 * configuration space.
3912 static int __devinit stli_pciprobe(struct pci_dev *pdev,
3913 const struct pci_device_id *ent)
3918 retval = pci_enable_device(pdev);
3921 brdp = stli_allocbrd();
3926 if ((brdp->brdnr = stli_getbrdnr()) < 0) { /* TODO: locking */
3927 printk(KERN_INFO "STALLION: too many boards found, "
3928 "maximum supported %d\n", STL_MAXBRDS);
3932 brdp->brdtype = BRD_ECPPCI;
3934 * We have all resources from the board, so lets setup the actual
3935 * board structure now.
3937 brdp->iobase = pci_resource_start(pdev, 3);
3938 brdp->memaddr = pci_resource_start(pdev, 2);
3939 retval = stli_brdinit(brdp);
3943 pci_set_drvdata(pdev, brdp);
3952 static void stli_pciremove(struct pci_dev *pdev)
3954 stlibrd_t *brdp = pci_get_drvdata(pdev);
3956 stli_cleanup_ports(brdp);
3958 iounmap(brdp->membase);
3959 if (brdp->iosize > 0)
3960 release_region(brdp->iobase, brdp->iosize);
3962 stli_brds[brdp->brdnr] = NULL;
3966 static struct pci_driver stli_pcidriver = {
3967 .name = "istallion",
3968 .id_table = istallion_pci_tbl,
3969 .probe = stli_pciprobe,
3970 .remove = __devexit_p(stli_pciremove)
3972 /*****************************************************************************/
3975 * Allocate a new board structure. Fill out the basic info in it.
3978 static stlibrd_t *stli_allocbrd(void)
3982 brdp = kzalloc(sizeof(stlibrd_t), GFP_KERNEL);
3984 printk(KERN_ERR "STALLION: failed to allocate memory "
3985 "(size=%Zd)\n", sizeof(stlibrd_t));
3988 brdp->magic = STLI_BOARDMAGIC;
3992 /*****************************************************************************/
3995 * Scan through all the boards in the configuration and see what we
3999 static int stli_initbrds(void)
4001 stlibrd_t *brdp, *nxtbrdp;
4005 for (stli_nrbrds = 0; stli_nrbrds < ARRAY_SIZE(stli_brdsp);
4007 memset(&conf, 0, sizeof(conf));
4008 if (stli_parsebrd(&conf, stli_brdsp[stli_nrbrds]) == 0)
4010 if ((brdp = stli_allocbrd()) == NULL)
4012 brdp->brdnr = stli_nrbrds;
4013 brdp->brdtype = conf.brdtype;
4014 brdp->iobase = conf.ioaddr1;
4015 brdp->memaddr = conf.memaddr;
4020 stli_findeisabrds();
4022 retval = pci_register_driver(&stli_pcidriver);
4023 /* TODO: check retval and do something */
4026 * All found boards are initialized. Now for a little optimization, if
4027 * no boards are sharing the "shared memory" regions then we can just
4028 * leave them all enabled. This is in fact the usual case.
4031 if (stli_nrbrds > 1) {
4032 for (i = 0; (i < stli_nrbrds); i++) {
4033 brdp = stli_brds[i];
4036 for (j = i + 1; (j < stli_nrbrds); j++) {
4037 nxtbrdp = stli_brds[j];
4038 if (nxtbrdp == NULL)
4040 if ((brdp->membase >= nxtbrdp->membase) &&
4041 (brdp->membase <= (nxtbrdp->membase +
4042 nxtbrdp->memsize - 1))) {
4050 if (stli_shared == 0) {
4051 for (i = 0; (i < stli_nrbrds); i++) {
4052 brdp = stli_brds[i];
4055 if (brdp->state & BST_FOUND) {
4057 brdp->enable = NULL;
4058 brdp->disable = NULL;
4066 /*****************************************************************************/
4069 * Code to handle an "staliomem" read operation. This device is the
4070 * contents of the board shared memory. It is used for down loading
4071 * the slave image (and debugging :-)
4074 static ssize_t stli_memread(struct file *fp, char __user *buf, size_t count, loff_t *offp)
4076 unsigned long flags;
4077 void __iomem *memptr;
4083 brdnr = iminor(fp->f_path.dentry->d_inode);
4084 if (brdnr >= stli_nrbrds)
4086 brdp = stli_brds[brdnr];
4089 if (brdp->state == 0)
4091 if (off >= brdp->memsize || off + count < off)
4094 size = min(count, (size_t)(brdp->memsize - off));
4097 * Copy the data a page at a time
4100 p = (void *)__get_free_page(GFP_KERNEL);
4105 spin_lock_irqsave(&brd_lock, flags);
4107 memptr = EBRDGETMEMPTR(brdp, off);
4108 n = min(size, (int)(brdp->pagesize - (((unsigned long) off) % brdp->pagesize)));
4109 n = min(n, (int)PAGE_SIZE);
4110 memcpy_fromio(p, memptr, n);
4112 spin_unlock_irqrestore(&brd_lock, flags);
4113 if (copy_to_user(buf, p, n)) {
4123 free_page((unsigned long)p);
4127 /*****************************************************************************/
4130 * Code to handle an "staliomem" write operation. This device is the
4131 * contents of the board shared memory. It is used for down loading
4132 * the slave image (and debugging :-)
4134 * FIXME: copy under lock
4137 static ssize_t stli_memwrite(struct file *fp, const char __user *buf, size_t count, loff_t *offp)
4139 unsigned long flags;
4140 void __iomem *memptr;
4147 brdnr = iminor(fp->f_path.dentry->d_inode);
4149 if (brdnr >= stli_nrbrds)
4151 brdp = stli_brds[brdnr];
4154 if (brdp->state == 0)
4156 if (off >= brdp->memsize || off + count < off)
4159 chbuf = (char __user *) buf;
4160 size = min(count, (size_t)(brdp->memsize - off));
4163 * Copy the data a page at a time
4166 p = (void *)__get_free_page(GFP_KERNEL);
4171 n = min(size, (int)(brdp->pagesize - (((unsigned long) off) % brdp->pagesize)));
4172 n = min(n, (int)PAGE_SIZE);
4173 if (copy_from_user(p, chbuf, n)) {
4178 spin_lock_irqsave(&brd_lock, flags);
4180 memptr = EBRDGETMEMPTR(brdp, off);
4181 memcpy_toio(memptr, p, n);
4183 spin_unlock_irqrestore(&brd_lock, flags);
4189 free_page((unsigned long) p);
4194 /*****************************************************************************/
4197 * Return the board stats structure to user app.
4200 static int stli_getbrdstats(combrd_t __user *bp)
4205 if (copy_from_user(&stli_brdstats, bp, sizeof(combrd_t)))
4207 if (stli_brdstats.brd >= STL_MAXBRDS)
4209 brdp = stli_brds[stli_brdstats.brd];
4213 memset(&stli_brdstats, 0, sizeof(combrd_t));
4214 stli_brdstats.brd = brdp->brdnr;
4215 stli_brdstats.type = brdp->brdtype;
4216 stli_brdstats.hwid = 0;
4217 stli_brdstats.state = brdp->state;
4218 stli_brdstats.ioaddr = brdp->iobase;
4219 stli_brdstats.memaddr = brdp->memaddr;
4220 stli_brdstats.nrpanels = brdp->nrpanels;
4221 stli_brdstats.nrports = brdp->nrports;
4222 for (i = 0; (i < brdp->nrpanels); i++) {
4223 stli_brdstats.panels[i].panel = i;
4224 stli_brdstats.panels[i].hwid = brdp->panelids[i];
4225 stli_brdstats.panels[i].nrports = brdp->panels[i];
4228 if (copy_to_user(bp, &stli_brdstats, sizeof(combrd_t)))
4233 /*****************************************************************************/
4236 * Resolve the referenced port number into a port struct pointer.
4239 static stliport_t *stli_getport(int brdnr, int panelnr, int portnr)
4244 if (brdnr < 0 || brdnr >= STL_MAXBRDS)
4246 brdp = stli_brds[brdnr];
4249 for (i = 0; (i < panelnr); i++)
4250 portnr += brdp->panels[i];
4251 if ((portnr < 0) || (portnr >= brdp->nrports))
4253 return brdp->ports[portnr];
4256 /*****************************************************************************/
4259 * Return the port stats structure to user app. A NULL port struct
4260 * pointer passed in means that we need to find out from the app
4261 * what port to get stats for (used through board control device).
4264 static int stli_portcmdstats(stliport_t *portp)
4266 unsigned long flags;
4270 memset(&stli_comstats, 0, sizeof(comstats_t));
4274 brdp = stli_brds[portp->brdnr];
4278 if (brdp->state & BST_STARTED) {
4279 if ((rc = stli_cmdwait(brdp, portp, A_GETSTATS,
4280 &stli_cdkstats, sizeof(asystats_t), 1)) < 0)
4283 memset(&stli_cdkstats, 0, sizeof(asystats_t));
4286 stli_comstats.brd = portp->brdnr;
4287 stli_comstats.panel = portp->panelnr;
4288 stli_comstats.port = portp->portnr;
4289 stli_comstats.state = portp->state;
4290 stli_comstats.flags = portp->flags;
4292 spin_lock_irqsave(&brd_lock, flags);
4293 if (portp->tty != NULL) {
4294 if (portp->tty->driver_data == portp) {
4295 stli_comstats.ttystate = portp->tty->flags;
4296 stli_comstats.rxbuffered = -1;
4297 if (portp->tty->termios != NULL) {
4298 stli_comstats.cflags = portp->tty->termios->c_cflag;
4299 stli_comstats.iflags = portp->tty->termios->c_iflag;
4300 stli_comstats.oflags = portp->tty->termios->c_oflag;
4301 stli_comstats.lflags = portp->tty->termios->c_lflag;
4305 spin_unlock_irqrestore(&brd_lock, flags);
4307 stli_comstats.txtotal = stli_cdkstats.txchars;
4308 stli_comstats.rxtotal = stli_cdkstats.rxchars + stli_cdkstats.ringover;
4309 stli_comstats.txbuffered = stli_cdkstats.txringq;
4310 stli_comstats.rxbuffered += stli_cdkstats.rxringq;
4311 stli_comstats.rxoverrun = stli_cdkstats.overruns;
4312 stli_comstats.rxparity = stli_cdkstats.parity;
4313 stli_comstats.rxframing = stli_cdkstats.framing;
4314 stli_comstats.rxlost = stli_cdkstats.ringover;
4315 stli_comstats.rxbreaks = stli_cdkstats.rxbreaks;
4316 stli_comstats.txbreaks = stli_cdkstats.txbreaks;
4317 stli_comstats.txxon = stli_cdkstats.txstart;
4318 stli_comstats.txxoff = stli_cdkstats.txstop;
4319 stli_comstats.rxxon = stli_cdkstats.rxstart;
4320 stli_comstats.rxxoff = stli_cdkstats.rxstop;
4321 stli_comstats.rxrtsoff = stli_cdkstats.rtscnt / 2;
4322 stli_comstats.rxrtson = stli_cdkstats.rtscnt - stli_comstats.rxrtsoff;
4323 stli_comstats.modem = stli_cdkstats.dcdcnt;
4324 stli_comstats.hwid = stli_cdkstats.hwid;
4325 stli_comstats.signals = stli_mktiocm(stli_cdkstats.signals);
4330 /*****************************************************************************/
4333 * Return the port stats structure to user app. A NULL port struct
4334 * pointer passed in means that we need to find out from the app
4335 * what port to get stats for (used through board control device).
4338 static int stli_getportstats(stliport_t *portp, comstats_t __user *cp)
4344 if (copy_from_user(&stli_comstats, cp, sizeof(comstats_t)))
4346 portp = stli_getport(stli_comstats.brd, stli_comstats.panel,
4347 stli_comstats.port);
4352 brdp = stli_brds[portp->brdnr];
4356 if ((rc = stli_portcmdstats(portp)) < 0)
4359 return copy_to_user(cp, &stli_comstats, sizeof(comstats_t)) ?
4363 /*****************************************************************************/
4366 * Clear the port stats structure. We also return it zeroed out...
4369 static int stli_clrportstats(stliport_t *portp, comstats_t __user *cp)
4375 if (copy_from_user(&stli_comstats, cp, sizeof(comstats_t)))
4377 portp = stli_getport(stli_comstats.brd, stli_comstats.panel,
4378 stli_comstats.port);
4383 brdp = stli_brds[portp->brdnr];
4387 if (brdp->state & BST_STARTED) {
4388 if ((rc = stli_cmdwait(brdp, portp, A_CLEARSTATS, NULL, 0, 0)) < 0)
4392 memset(&stli_comstats, 0, sizeof(comstats_t));
4393 stli_comstats.brd = portp->brdnr;
4394 stli_comstats.panel = portp->panelnr;
4395 stli_comstats.port = portp->portnr;
4397 if (copy_to_user(cp, &stli_comstats, sizeof(comstats_t)))
4402 /*****************************************************************************/
4405 * Return the entire driver ports structure to a user app.
4408 static int stli_getportstruct(stliport_t __user *arg)
4412 if (copy_from_user(&stli_dummyport, arg, sizeof(stliport_t)))
4414 portp = stli_getport(stli_dummyport.brdnr, stli_dummyport.panelnr,
4415 stli_dummyport.portnr);
4418 if (copy_to_user(arg, portp, sizeof(stliport_t)))
4423 /*****************************************************************************/
4426 * Return the entire driver board structure to a user app.
4429 static int stli_getbrdstruct(stlibrd_t __user *arg)
4433 if (copy_from_user(&stli_dummybrd, arg, sizeof(stlibrd_t)))
4435 if ((stli_dummybrd.brdnr < 0) || (stli_dummybrd.brdnr >= STL_MAXBRDS))
4437 brdp = stli_brds[stli_dummybrd.brdnr];
4440 if (copy_to_user(arg, brdp, sizeof(stlibrd_t)))
4445 /*****************************************************************************/
4448 * The "staliomem" device is also required to do some special operations on
4449 * the board. We need to be able to send an interrupt to the board,
4450 * reset it, and start/stop it.
4453 static int stli_memioctl(struct inode *ip, struct file *fp, unsigned int cmd, unsigned long arg)
4456 int brdnr, rc, done;
4457 void __user *argp = (void __user *)arg;
4460 * First up handle the board independent ioctls.
4466 case COM_GETPORTSTATS:
4467 rc = stli_getportstats(NULL, argp);
4470 case COM_CLRPORTSTATS:
4471 rc = stli_clrportstats(NULL, argp);
4474 case COM_GETBRDSTATS:
4475 rc = stli_getbrdstats(argp);
4479 rc = stli_getportstruct(argp);
4483 rc = stli_getbrdstruct(argp);
4492 * Now handle the board specific ioctls. These all depend on the
4493 * minor number of the device they were called from.
4496 if (brdnr >= STL_MAXBRDS)
4498 brdp = stli_brds[brdnr];
4501 if (brdp->state == 0)
4509 rc = stli_startbrd(brdp);
4512 brdp->state &= ~BST_STARTED;
4515 brdp->state &= ~BST_STARTED;
4517 if (stli_shared == 0) {
4518 if (brdp->reenable != NULL)
4519 (* brdp->reenable)(brdp);
4529 static const struct tty_operations stli_ops = {
4531 .close = stli_close,
4532 .write = stli_write,
4533 .put_char = stli_putchar,
4534 .flush_chars = stli_flushchars,
4535 .write_room = stli_writeroom,
4536 .chars_in_buffer = stli_charsinbuffer,
4537 .ioctl = stli_ioctl,
4538 .set_termios = stli_settermios,
4539 .throttle = stli_throttle,
4540 .unthrottle = stli_unthrottle,
4542 .start = stli_start,
4543 .hangup = stli_hangup,
4544 .flush_buffer = stli_flushbuffer,
4545 .break_ctl = stli_breakctl,
4546 .wait_until_sent = stli_waituntilsent,
4547 .send_xchar = stli_sendxchar,
4548 .read_proc = stli_readproc,
4549 .tiocmget = stli_tiocmget,
4550 .tiocmset = stli_tiocmset,
4553 /*****************************************************************************/
4555 static int __init stli_init(void)
4558 printk(KERN_INFO "%s: version %s\n", stli_drvtitle, stli_drvversion);
4560 spin_lock_init(&stli_lock);
4561 spin_lock_init(&brd_lock);
4565 stli_serial = alloc_tty_driver(STL_MAXBRDS * STL_MAXPORTS);
4570 * Allocate a temporary write buffer.
4572 stli_txcookbuf = kmalloc(STLI_TXBUFSIZE, GFP_KERNEL);
4573 if (!stli_txcookbuf)
4574 printk(KERN_ERR "STALLION: failed to allocate memory "
4575 "(size=%d)\n", STLI_TXBUFSIZE);
4578 * Set up a character driver for the shared memory region. We need this
4579 * to down load the slave code image. Also it is a useful debugging tool.
4581 if (register_chrdev(STL_SIOMEMMAJOR, "staliomem", &stli_fsiomem))
4582 printk(KERN_ERR "STALLION: failed to register serial memory "
4585 istallion_class = class_create(THIS_MODULE, "staliomem");
4586 for (i = 0; i < 4; i++)
4587 class_device_create(istallion_class, NULL,
4588 MKDEV(STL_SIOMEMMAJOR, i),
4589 NULL, "staliomem%d", i);
4592 * Set up the tty driver structure and register us as a driver.
4594 stli_serial->owner = THIS_MODULE;
4595 stli_serial->driver_name = stli_drvname;
4596 stli_serial->name = stli_serialname;
4597 stli_serial->major = STL_SERIALMAJOR;
4598 stli_serial->minor_start = 0;
4599 stli_serial->type = TTY_DRIVER_TYPE_SERIAL;
4600 stli_serial->subtype = SERIAL_TYPE_NORMAL;
4601 stli_serial->init_termios = stli_deftermios;
4602 stli_serial->flags = TTY_DRIVER_REAL_RAW;
4603 tty_set_operations(stli_serial, &stli_ops);
4605 if (tty_register_driver(stli_serial)) {
4606 put_tty_driver(stli_serial);
4607 printk(KERN_ERR "STALLION: failed to register serial driver\n");
4613 /*****************************************************************************/