1 /*****************************************************************************/
4 * istallion.c -- stallion intelligent multiport serial driver.
6 * Copyright (C) 1996-1999 Stallion Technologies (support@stallion.oz.au).
7 * Copyright (C) 1994-1996 Greg Ungerer.
9 * This code is loosely based on the Linux serial driver, written by
10 * Linus Torvalds, Theodore T'so and others.
12 * This program is free software; you can redistribute it and/or modify
13 * it under the terms of the GNU General Public License as published by
14 * the Free Software Foundation; either version 2 of the License, or
15 * (at your option) any later version.
17 * This program is distributed in the hope that it will be useful,
18 * but WITHOUT ANY WARRANTY; without even the implied warranty of
19 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
20 * GNU General Public License for more details.
22 * You should have received a copy of the GNU General Public License
23 * along with this program; if not, write to the Free Software
24 * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
27 /*****************************************************************************/
29 #include <linux/config.h>
30 #include <linux/module.h>
31 #include <linux/malloc.h>
32 #include <linux/interrupt.h>
33 #include <linux/tty_flip.h>
34 #include <linux/serial.h>
35 #include <linux/cdk.h>
36 #include <linux/comstats.h>
37 #include <linux/version.h>
38 #include <linux/istallion.h>
39 #include <linux/ioport.h>
40 #include <linux/delay.h>
41 #include <linux/init.h>
42 #include <linux/devfs_fs_kernel.h>
45 #include <asm/uaccess.h>
48 #include <linux/pci.h>
51 /*****************************************************************************/
54 * Define different board types. Not all of the following board types
55 * are supported by this driver. But I will use the standard "assigned"
56 * board numbers. Currently supported boards are abbreviated as:
57 * ECP = EasyConnection 8/64, ONB = ONboard, BBY = Brumby and
61 #define BRD_STALLION 1
63 #define BRD_ONBOARD2 3
66 #define BRD_BRUMBY16 6
67 #define BRD_ONBOARDE 7
68 #define BRD_ONBOARD32 9
69 #define BRD_ONBOARD2_32 10
70 #define BRD_ONBOARDRS 11
78 #define BRD_ECH64PCI 27
79 #define BRD_EASYIOPCI 28
82 #define BRD_BRUMBY BRD_BRUMBY4
85 * Define a configuration structure to hold the board configuration.
86 * Need to set this up in the code (for now) with the boards that are
87 * to be configured into the system. This is what needs to be modified
88 * when adding/removing/modifying boards. Each line entry in the
89 * stli_brdconf[] array is a board. Each line contains io/irq/memory
90 * ranges for that board (as well as what type of board it is).
92 * { BRD_ECP, 0x2a0, 0, 0xcc000, 0, 0 },
93 * This line will configure an EasyConnection 8/64 at io address 2a0,
94 * and shared memory address of cc000. Multiple EasyConnection 8/64
95 * boards can share the same shared memory address space. No interrupt
96 * is required for this board type.
98 * { BRD_ECPE, 0x5000, 0, 0x80000000, 0, 0 },
99 * This line will configure an EasyConnection 8/64 EISA in slot 5 and
100 * shared memory address of 0x80000000 (2 GByte). Multiple
101 * EasyConnection 8/64 EISA boards can share the same shared memory
102 * address space. No interrupt is required for this board type.
104 * { BRD_ONBOARD, 0x240, 0, 0xd0000, 0, 0 },
105 * This line will configure an ONboard (ISA type) at io address 240,
106 * and shared memory address of d0000. Multiple ONboards can share
107 * the same shared memory address space. No interrupt required.
109 * { BRD_BRUMBY4, 0x360, 0, 0xc8000, 0, 0 },
110 * This line will configure a Brumby board (any number of ports!) at
111 * io address 360 and shared memory address of c8000. All Brumby boards
112 * configured into a system must have their own separate io and memory
113 * addresses. No interrupt is required.
115 * { BRD_STALLION, 0x330, 0, 0xd0000, 0, 0 },
116 * This line will configure an original Stallion board at io address 330
117 * and shared memory address d0000 (this would only be valid for a "V4.0"
118 * or Rev.O Stallion board). All Stallion boards configured into the
119 * system must have their own separate io and memory addresses. No
120 * interrupt is required.
127 unsigned long memaddr
;
132 static stlconf_t stli_brdconf
[] = {
133 /*{ BRD_ECP, 0x2a0, 0, 0xcc000, 0, 0 },*/
136 static int stli_nrbrds
= sizeof(stli_brdconf
) / sizeof(stlconf_t
);
139 * There is some experimental EISA board detection code in this driver.
140 * By default it is disabled, but for those that want to try it out,
141 * then set the define below to be 1.
143 #define STLI_EISAPROBE 0
145 static devfs_handle_t devfs_handle
;
147 /*****************************************************************************/
150 * Define some important driver characteristics. Device major numbers
151 * allocated as per Linux Device Registry.
153 #ifndef STL_SIOMEMMAJOR
154 #define STL_SIOMEMMAJOR 28
156 #ifndef STL_SERIALMAJOR
157 #define STL_SERIALMAJOR 24
159 #ifndef STL_CALLOUTMAJOR
160 #define STL_CALLOUTMAJOR 25
163 #define STL_DRVTYPSERIAL 1
164 #define STL_DRVTYPCALLOUT 2
166 /*****************************************************************************/
169 * Define our local driver identity first. Set up stuff to deal with
170 * all the local structures required by a serial tty driver.
172 static char *stli_drvtitle
= "Stallion Intelligent Multiport Serial Driver";
173 static char *stli_drvname
= "istallion";
174 static char *stli_drvversion
= "5.6.0";
175 static char *stli_serialname
= "ttyE";
176 static char *stli_calloutname
= "cue";
178 static struct tty_driver stli_serial
;
179 static struct tty_driver stli_callout
;
180 static struct tty_struct
*stli_ttys
[STL_MAXDEVS
];
181 static struct termios
*stli_termios
[STL_MAXDEVS
];
182 static struct termios
*stli_termioslocked
[STL_MAXDEVS
];
183 static int stli_refcount
;
186 * We will need to allocate a temporary write buffer for chars that
187 * come direct from user space. The problem is that a copy from user
188 * space might cause a page fault (typically on a system that is
189 * swapping!). All ports will share one buffer - since if the system
190 * is already swapping a shared buffer won't make things any worse.
192 static char *stli_tmpwritebuf
;
193 static DECLARE_MUTEX(stli_tmpwritesem
);
195 #define STLI_TXBUFSIZE 4096
198 * Use a fast local buffer for cooked characters. Typically a whole
199 * bunch of cooked characters come in for a port, 1 at a time. So we
200 * save those up into a local buffer, then write out the whole lot
201 * with a large memcpy. Just use 1 buffer for all ports, since its
202 * use it is only need for short periods of time by each port.
204 static char *stli_txcookbuf
;
205 static int stli_txcooksize
;
206 static int stli_txcookrealsize
;
207 static struct tty_struct
*stli_txcooktty
;
210 * Define a local default termios struct. All ports will be created
211 * with this termios initially. Basically all it defines is a raw port
212 * at 9600 baud, 8 data bits, no parity, 1 stop bit.
214 static struct termios stli_deftermios
= {
217 (B9600
| CS8
| CREAD
| HUPCL
| CLOCAL
),
224 * Define global stats structures. Not used often, and can be
225 * re-used for each stats call.
227 static comstats_t stli_comstats
;
228 static combrd_t stli_brdstats
;
229 static asystats_t stli_cdkstats
;
230 static stlibrd_t stli_dummybrd
;
231 static stliport_t stli_dummyport
;
233 /*****************************************************************************/
235 static stlibrd_t
*stli_brds
[STL_MAXBRDS
];
237 static int stli_shared
;
240 * Per board state flags. Used with the state field of the board struct.
241 * Not really much here... All we need to do is keep track of whether
242 * the board has been detected, and whether it is actually running a slave
245 #define BST_FOUND 0x1
246 #define BST_STARTED 0x2
249 * Define the set of port state flags. These are marked for internal
250 * state purposes only, usually to do with the state of communications
251 * with the slave. Most of them need to be updated atomically, so always
252 * use the bit setting operations (unless protected by cli/sti).
254 #define ST_INITIALIZING 1
260 #define ST_DOFLUSHRX 7
261 #define ST_DOFLUSHTX 8
264 #define ST_GETSIGS 11
267 * Define an array of board names as printable strings. Handy for
268 * referencing boards when printing trace and stuff.
270 static char *stli_brdnames
[] = {
303 /*****************************************************************************/
307 * Define some string labels for arguments passed from the module
308 * load line. These allow for easy board definitions, and easy
309 * modification of the io, memory and irq resoucres.
312 static char *board0
[8];
313 static char *board1
[8];
314 static char *board2
[8];
315 static char *board3
[8];
317 static char **stli_brdsp
[] = {
325 * Define a set of common board names, and types. This is used to
326 * parse any module arguments.
329 typedef struct stlibrdtype
{
334 static stlibrdtype_t stli_brdstr
[] = {
335 { "stallion", BRD_STALLION
},
336 { "1", BRD_STALLION
},
337 { "brumby", BRD_BRUMBY
},
338 { "brumby4", BRD_BRUMBY
},
339 { "brumby/4", BRD_BRUMBY
},
340 { "brumby-4", BRD_BRUMBY
},
341 { "brumby8", BRD_BRUMBY
},
342 { "brumby/8", BRD_BRUMBY
},
343 { "brumby-8", BRD_BRUMBY
},
344 { "brumby16", BRD_BRUMBY
},
345 { "brumby/16", BRD_BRUMBY
},
346 { "brumby-16", BRD_BRUMBY
},
348 { "onboard2", BRD_ONBOARD2
},
349 { "onboard-2", BRD_ONBOARD2
},
350 { "onboard/2", BRD_ONBOARD2
},
351 { "onboard-mc", BRD_ONBOARD2
},
352 { "onboard/mc", BRD_ONBOARD2
},
353 { "onboard-mca", BRD_ONBOARD2
},
354 { "onboard/mca", BRD_ONBOARD2
},
355 { "3", BRD_ONBOARD2
},
356 { "onboard", BRD_ONBOARD
},
357 { "onboardat", BRD_ONBOARD
},
358 { "4", BRD_ONBOARD
},
359 { "onboarde", BRD_ONBOARDE
},
360 { "onboard-e", BRD_ONBOARDE
},
361 { "onboard/e", BRD_ONBOARDE
},
362 { "onboard-ei", BRD_ONBOARDE
},
363 { "onboard/ei", BRD_ONBOARDE
},
364 { "7", BRD_ONBOARDE
},
366 { "ecpat", BRD_ECP
},
367 { "ec8/64", BRD_ECP
},
368 { "ec8/64-at", BRD_ECP
},
369 { "ec8/64-isa", BRD_ECP
},
371 { "ecpe", BRD_ECPE
},
372 { "ecpei", BRD_ECPE
},
373 { "ec8/64-e", BRD_ECPE
},
374 { "ec8/64-ei", BRD_ECPE
},
376 { "ecpmc", BRD_ECPMC
},
377 { "ec8/64-mc", BRD_ECPMC
},
378 { "ec8/64-mca", BRD_ECPMC
},
380 { "ecppci", BRD_ECPPCI
},
381 { "ec/ra", BRD_ECPPCI
},
382 { "ec/ra-pc", BRD_ECPPCI
},
383 { "ec/ra-pci", BRD_ECPPCI
},
384 { "29", BRD_ECPPCI
},
388 * Define the module agruments.
390 MODULE_AUTHOR("Greg Ungerer");
391 MODULE_DESCRIPTION("Stallion Intelligent Multiport Serial Driver");
393 MODULE_PARM(board0
, "1-3s");
394 MODULE_PARM_DESC(board0
, "Board 0 config -> name[,ioaddr[,memaddr]");
395 MODULE_PARM(board1
, "1-3s");
396 MODULE_PARM_DESC(board1
, "Board 1 config -> name[,ioaddr[,memaddr]");
397 MODULE_PARM(board2
, "1-3s");
398 MODULE_PARM_DESC(board2
, "Board 2 config -> name[,ioaddr[,memaddr]");
399 MODULE_PARM(board3
, "1-3s");
400 MODULE_PARM_DESC(board3
, "Board 3 config -> name[,ioaddr[,memaddr]");
405 * Set up a default memory address table for EISA board probing.
406 * The default addresses are all bellow 1Mbyte, which has to be the
407 * case anyway. They should be safe, since we only read values from
408 * them, and interrupts are disabled while we do it. If the higher
409 * memory support is compiled in then we also try probing around
410 * the 1Gb, 2Gb and 3Gb areas as well...
412 static unsigned long stli_eisamemprobeaddrs
[] = {
413 0xc0000, 0xd0000, 0xe0000, 0xf0000,
414 0x80000000, 0x80010000, 0x80020000, 0x80030000,
415 0x40000000, 0x40010000, 0x40020000, 0x40030000,
416 0xc0000000, 0xc0010000, 0xc0020000, 0xc0030000,
417 0xff000000, 0xff010000, 0xff020000, 0xff030000,
420 static int stli_eisamempsize
= sizeof(stli_eisamemprobeaddrs
) / sizeof(unsigned long);
421 int stli_eisaprobe
= STLI_EISAPROBE
;
424 * Define the Stallion PCI vendor and device IDs.
427 #ifndef PCI_VENDOR_ID_STALLION
428 #define PCI_VENDOR_ID_STALLION 0x124d
430 #ifndef PCI_DEVICE_ID_ECRA
431 #define PCI_DEVICE_ID_ECRA 0x0004
435 /*****************************************************************************/
438 * Hardware configuration info for ECP boards. These defines apply
439 * to the directly accessible io ports of the ECP. There is a set of
440 * defines for each ECP board type, ISA, EISA, MCA and PCI.
444 #define ECP_MEMSIZE (128 * 1024)
445 #define ECP_PCIMEMSIZE (256 * 1024)
447 #define ECP_ATPAGESIZE (4 * 1024)
448 #define ECP_MCPAGESIZE (4 * 1024)
449 #define ECP_EIPAGESIZE (64 * 1024)
450 #define ECP_PCIPAGESIZE (64 * 1024)
452 #define STL_EISAID 0x8c4e
455 * Important defines for the ISA class of ECP board.
458 #define ECP_ATCONFR 1
459 #define ECP_ATMEMAR 2
460 #define ECP_ATMEMPR 3
461 #define ECP_ATSTOP 0x1
462 #define ECP_ATINTENAB 0x10
463 #define ECP_ATENABLE 0x20
464 #define ECP_ATDISABLE 0x00
465 #define ECP_ATADDRMASK 0x3f000
466 #define ECP_ATADDRSHFT 12
469 * Important defines for the EISA class of ECP board.
472 #define ECP_EIMEMARL 1
473 #define ECP_EICONFR 2
474 #define ECP_EIMEMARH 3
475 #define ECP_EIENABLE 0x1
476 #define ECP_EIDISABLE 0x0
477 #define ECP_EISTOP 0x4
478 #define ECP_EIEDGE 0x00
479 #define ECP_EILEVEL 0x80
480 #define ECP_EIADDRMASKL 0x00ff0000
481 #define ECP_EIADDRSHFTL 16
482 #define ECP_EIADDRMASKH 0xff000000
483 #define ECP_EIADDRSHFTH 24
484 #define ECP_EIBRDENAB 0xc84
486 #define ECP_EISAID 0x4
489 * Important defines for the Micro-channel class of ECP board.
490 * (It has a lot in common with the ISA boards.)
493 #define ECP_MCCONFR 1
494 #define ECP_MCSTOP 0x20
495 #define ECP_MCENABLE 0x80
496 #define ECP_MCDISABLE 0x00
499 * Important defines for the PCI class of ECP board.
500 * (It has a lot in common with the other ECP boards.)
502 #define ECP_PCIIREG 0
503 #define ECP_PCICONFR 1
504 #define ECP_PCISTOP 0x01
507 * Hardware configuration info for ONboard and Brumby boards. These
508 * defines apply to the directly accessible io ports of these boards.
510 #define ONB_IOSIZE 16
511 #define ONB_MEMSIZE (64 * 1024)
512 #define ONB_ATPAGESIZE (64 * 1024)
513 #define ONB_MCPAGESIZE (64 * 1024)
514 #define ONB_EIMEMSIZE (128 * 1024)
515 #define ONB_EIPAGESIZE (64 * 1024)
518 * Important defines for the ISA class of ONboard board.
521 #define ONB_ATMEMAR 1
522 #define ONB_ATCONFR 2
523 #define ONB_ATSTOP 0x4
524 #define ONB_ATENABLE 0x01
525 #define ONB_ATDISABLE 0x00
526 #define ONB_ATADDRMASK 0xff0000
527 #define ONB_ATADDRSHFT 16
529 #define ONB_MEMENABLO 0
530 #define ONB_MEMENABHI 0x02
533 * Important defines for the EISA class of ONboard board.
536 #define ONB_EIMEMARL 1
537 #define ONB_EICONFR 2
538 #define ONB_EIMEMARH 3
539 #define ONB_EIENABLE 0x1
540 #define ONB_EIDISABLE 0x0
541 #define ONB_EISTOP 0x4
542 #define ONB_EIEDGE 0x00
543 #define ONB_EILEVEL 0x80
544 #define ONB_EIADDRMASKL 0x00ff0000
545 #define ONB_EIADDRSHFTL 16
546 #define ONB_EIADDRMASKH 0xff000000
547 #define ONB_EIADDRSHFTH 24
548 #define ONB_EIBRDENAB 0xc84
550 #define ONB_EISAID 0x1
553 * Important defines for the Brumby boards. They are pretty simple,
554 * there is not much that is programmably configurable.
556 #define BBY_IOSIZE 16
557 #define BBY_MEMSIZE (64 * 1024)
558 #define BBY_PAGESIZE (16 * 1024)
561 #define BBY_ATCONFR 1
562 #define BBY_ATSTOP 0x4
565 * Important defines for the Stallion boards. They are pretty simple,
566 * there is not much that is programmably configurable.
568 #define STAL_IOSIZE 16
569 #define STAL_MEMSIZE (64 * 1024)
570 #define STAL_PAGESIZE (64 * 1024)
573 * Define the set of status register values for EasyConnection panels.
574 * The signature will return with the status value for each panel. From
575 * this we can determine what is attached to the board - before we have
576 * actually down loaded any code to it.
578 #define ECH_PNLSTATUS 2
579 #define ECH_PNL16PORT 0x20
580 #define ECH_PNLIDMASK 0x07
581 #define ECH_PNLXPID 0x40
582 #define ECH_PNLINTRPEND 0x80
585 * Define some macros to do things to the board. Even those these boards
586 * are somewhat related there is often significantly different ways of
587 * doing some operation on it (like enable, paging, reset, etc). So each
588 * board class has a set of functions which do the commonly required
589 * operations. The macros below basically just call these functions,
590 * generally checking for a NULL function - which means that the board
591 * needs nothing done to it to achieve this operation!
593 #define EBRDINIT(brdp) \
594 if (brdp->init != NULL) \
597 #define EBRDENABLE(brdp) \
598 if (brdp->enable != NULL) \
599 (* brdp->enable)(brdp);
601 #define EBRDDISABLE(brdp) \
602 if (brdp->disable != NULL) \
603 (* brdp->disable)(brdp);
605 #define EBRDINTR(brdp) \
606 if (brdp->intr != NULL) \
607 (* brdp->intr)(brdp);
609 #define EBRDRESET(brdp) \
610 if (brdp->reset != NULL) \
611 (* brdp->reset)(brdp);
613 #define EBRDGETMEMPTR(brdp,offset) \
614 (* brdp->getmemptr)(brdp, offset, __LINE__)
617 * Define the maximal baud rate, and the default baud base for ports.
619 #define STL_MAXBAUD 460800
620 #define STL_BAUDBASE 115200
621 #define STL_CLOSEDELAY (5 * HZ / 10)
623 /*****************************************************************************/
626 * Define macros to extract a brd or port number from a minor number.
628 #define MINOR2BRD(min) (((min) & 0xc0) >> 6)
629 #define MINOR2PORT(min) ((min) & 0x3f)
632 * Define a baud rate table that converts termios baud rate selector
633 * into the actual baud rate value. All baud rate calculations are based
634 * on the actual baud rate required.
636 static unsigned int stli_baudrates
[] = {
637 0, 50, 75, 110, 134, 150, 200, 300, 600, 1200, 1800, 2400, 4800,
638 9600, 19200, 38400, 57600, 115200, 230400, 460800, 921600
641 /*****************************************************************************/
644 * Define some handy local macros...
647 #define MIN(a,b) (((a) <= (b)) ? (a) : (b))
650 #define TOLOWER(x) ((((x) >= 'A') && ((x) <= 'Z')) ? ((x) + 0x20) : (x))
652 /*****************************************************************************/
655 * Prototype all functions in this driver!
659 int init_module(void);
660 void cleanup_module(void);
661 static void stli_argbrds(void);
662 static int stli_parsebrd(stlconf_t
*confp
, char **argp
);
664 static unsigned long stli_atol(char *str
);
668 static int stli_open(struct tty_struct
*tty
, struct file
*filp
);
669 static void stli_close(struct tty_struct
*tty
, struct file
*filp
);
670 static int stli_write(struct tty_struct
*tty
, int from_user
, const unsigned char *buf
, int count
);
671 static void stli_putchar(struct tty_struct
*tty
, unsigned char ch
);
672 static void stli_flushchars(struct tty_struct
*tty
);
673 static int stli_writeroom(struct tty_struct
*tty
);
674 static int stli_charsinbuffer(struct tty_struct
*tty
);
675 static int stli_ioctl(struct tty_struct
*tty
, struct file
*file
, unsigned int cmd
, unsigned long arg
);
676 static void stli_settermios(struct tty_struct
*tty
, struct termios
*old
);
677 static void stli_throttle(struct tty_struct
*tty
);
678 static void stli_unthrottle(struct tty_struct
*tty
);
679 static void stli_stop(struct tty_struct
*tty
);
680 static void stli_start(struct tty_struct
*tty
);
681 static void stli_flushbuffer(struct tty_struct
*tty
);
682 static void stli_breakctl(struct tty_struct
*tty
, int state
);
683 static void stli_waituntilsent(struct tty_struct
*tty
, int timeout
);
684 static void stli_sendxchar(struct tty_struct
*tty
, char ch
);
685 static void stli_hangup(struct tty_struct
*tty
);
686 static int stli_portinfo(stlibrd_t
*brdp
, stliport_t
*portp
, int portnr
, char *pos
);
688 static int stli_brdinit(stlibrd_t
*brdp
);
689 static int stli_startbrd(stlibrd_t
*brdp
);
690 static ssize_t
stli_memread(struct file
*fp
, char *buf
, size_t count
, loff_t
*offp
);
691 static ssize_t
stli_memwrite(struct file
*fp
, const char *buf
, size_t count
, loff_t
*offp
);
692 static int stli_memioctl(struct inode
*ip
, struct file
*fp
, unsigned int cmd
, unsigned long arg
);
693 static void stli_brdpoll(stlibrd_t
*brdp
, volatile cdkhdr_t
*hdrp
);
694 static void stli_poll(unsigned long arg
);
695 static int stli_hostcmd(stlibrd_t
*brdp
, stliport_t
*portp
);
696 static int stli_initopen(stlibrd_t
*brdp
, stliport_t
*portp
);
697 static int stli_rawopen(stlibrd_t
*brdp
, stliport_t
*portp
, unsigned long arg
, int wait
);
698 static int stli_rawclose(stlibrd_t
*brdp
, stliport_t
*portp
, unsigned long arg
, int wait
);
699 static int stli_waitcarrier(stlibrd_t
*brdp
, stliport_t
*portp
, struct file
*filp
);
700 static void stli_dohangup(void *arg
);
701 static void stli_delay(int len
);
702 static int stli_setport(stliport_t
*portp
);
703 static int stli_cmdwait(stlibrd_t
*brdp
, stliport_t
*portp
, unsigned long cmd
, void *arg
, int size
, int copyback
);
704 static void stli_sendcmd(stlibrd_t
*brdp
, stliport_t
*portp
, unsigned long cmd
, void *arg
, int size
, int copyback
);
705 static void stli_dodelaycmd(stliport_t
*portp
, volatile cdkctrl_t
*cp
);
706 static void stli_mkasyport(stliport_t
*portp
, asyport_t
*pp
, struct termios
*tiosp
);
707 static void stli_mkasysigs(asysigs_t
*sp
, int dtr
, int rts
);
708 static long stli_mktiocm(unsigned long sigvalue
);
709 static void stli_read(stlibrd_t
*brdp
, stliport_t
*portp
);
710 static void stli_getserial(stliport_t
*portp
, struct serial_struct
*sp
);
711 static int stli_setserial(stliport_t
*portp
, struct serial_struct
*sp
);
712 static int stli_getbrdstats(combrd_t
*bp
);
713 static int stli_getportstats(stliport_t
*portp
, comstats_t
*cp
);
714 static int stli_portcmdstats(stliport_t
*portp
);
715 static int stli_clrportstats(stliport_t
*portp
, comstats_t
*cp
);
716 static int stli_getportstruct(unsigned long arg
);
717 static int stli_getbrdstruct(unsigned long arg
);
718 static void *stli_memalloc(int len
);
719 static stlibrd_t
*stli_allocbrd(void);
721 static void stli_ecpinit(stlibrd_t
*brdp
);
722 static void stli_ecpenable(stlibrd_t
*brdp
);
723 static void stli_ecpdisable(stlibrd_t
*brdp
);
724 static char *stli_ecpgetmemptr(stlibrd_t
*brdp
, unsigned long offset
, int line
);
725 static void stli_ecpreset(stlibrd_t
*brdp
);
726 static void stli_ecpintr(stlibrd_t
*brdp
);
727 static void stli_ecpeiinit(stlibrd_t
*brdp
);
728 static void stli_ecpeienable(stlibrd_t
*brdp
);
729 static void stli_ecpeidisable(stlibrd_t
*brdp
);
730 static char *stli_ecpeigetmemptr(stlibrd_t
*brdp
, unsigned long offset
, int line
);
731 static void stli_ecpeireset(stlibrd_t
*brdp
);
732 static void stli_ecpmcenable(stlibrd_t
*brdp
);
733 static void stli_ecpmcdisable(stlibrd_t
*brdp
);
734 static char *stli_ecpmcgetmemptr(stlibrd_t
*brdp
, unsigned long offset
, int line
);
735 static void stli_ecpmcreset(stlibrd_t
*brdp
);
736 static void stli_ecppciinit(stlibrd_t
*brdp
);
737 static char *stli_ecppcigetmemptr(stlibrd_t
*brdp
, unsigned long offset
, int line
);
738 static void stli_ecppcireset(stlibrd_t
*brdp
);
740 static void stli_onbinit(stlibrd_t
*brdp
);
741 static void stli_onbenable(stlibrd_t
*brdp
);
742 static void stli_onbdisable(stlibrd_t
*brdp
);
743 static char *stli_onbgetmemptr(stlibrd_t
*brdp
, unsigned long offset
, int line
);
744 static void stli_onbreset(stlibrd_t
*brdp
);
745 static void stli_onbeinit(stlibrd_t
*brdp
);
746 static void stli_onbeenable(stlibrd_t
*brdp
);
747 static void stli_onbedisable(stlibrd_t
*brdp
);
748 static char *stli_onbegetmemptr(stlibrd_t
*brdp
, unsigned long offset
, int line
);
749 static void stli_onbereset(stlibrd_t
*brdp
);
750 static void stli_bbyinit(stlibrd_t
*brdp
);
751 static char *stli_bbygetmemptr(stlibrd_t
*brdp
, unsigned long offset
, int line
);
752 static void stli_bbyreset(stlibrd_t
*brdp
);
753 static void stli_stalinit(stlibrd_t
*brdp
);
754 static char *stli_stalgetmemptr(stlibrd_t
*brdp
, unsigned long offset
, int line
);
755 static void stli_stalreset(stlibrd_t
*brdp
);
757 static stliport_t
*stli_getport(int brdnr
, int panelnr
, int portnr
);
759 static inline int stli_initbrds(void);
760 static inline int stli_initecp(stlibrd_t
*brdp
);
761 static inline int stli_initonb(stlibrd_t
*brdp
);
762 static inline int stli_findeisabrds(void);
763 static inline int stli_eisamemprobe(stlibrd_t
*brdp
);
764 static inline int stli_initports(stlibrd_t
*brdp
);
765 static inline int stli_getbrdnr(void);
768 static inline int stli_findpcibrds(void);
769 static inline int stli_initpcibrd(int brdtype
, struct pci_dev
*devp
);
772 /*****************************************************************************/
775 * Define the driver info for a user level shared memory device. This
776 * device will work sort of like the /dev/kmem device - except that it
777 * will give access to the shared memory on the Stallion intelligent
778 * board. This is also a very useful debugging tool.
780 static struct file_operations stli_fsiomem
= {
783 write
: stli_memwrite
,
784 ioctl
: stli_memioctl
,
787 /*****************************************************************************/
790 * Define a timer_list entry for our poll routine. The slave board
791 * is polled every so often to see if anything needs doing. This is
792 * much cheaper on host cpu than using interrupts. It turns out to
793 * not increase character latency by much either...
795 static struct timer_list stli_timerlist
= {
799 static int stli_timeron
;
802 * Define the calculation for the timeout routine.
804 #define STLI_TIMEOUT (jiffies + 1)
806 /*****************************************************************************/
811 * Loadable module initialization stuff.
819 printk("init_module()\n");
825 restore_flags(flags
);
830 /*****************************************************************************/
832 void cleanup_module()
840 printk("cleanup_module()\n");
843 printk(KERN_INFO
"Unloading %s: version %s\n", stli_drvtitle
,
850 * Free up all allocated resources used by the ports. This includes
851 * memory and interrupts.
855 del_timer(&stli_timerlist
);
858 i
= tty_unregister_driver(&stli_serial
);
859 j
= tty_unregister_driver(&stli_callout
);
861 printk("STALLION: failed to un-register tty driver, "
862 "errno=%d,%d\n", -i
, -j
);
863 restore_flags(flags
);
866 devfs_unregister (devfs_handle
);
867 if ((i
= devfs_unregister_chrdev(STL_SIOMEMMAJOR
, "staliomem")))
868 printk("STALLION: failed to un-register serial memory device, "
870 if (stli_tmpwritebuf
!= (char *) NULL
)
871 kfree(stli_tmpwritebuf
);
872 if (stli_txcookbuf
!= (char *) NULL
)
873 kfree(stli_txcookbuf
);
875 for (i
= 0; (i
< stli_nrbrds
); i
++) {
876 if ((brdp
= stli_brds
[i
]) == (stlibrd_t
*) NULL
)
878 for (j
= 0; (j
< STL_MAXPORTS
); j
++) {
879 portp
= brdp
->ports
[j
];
880 if (portp
!= (stliport_t
*) NULL
) {
881 if (portp
->tty
!= (struct tty_struct
*) NULL
)
882 tty_hangup(portp
->tty
);
887 iounmap(brdp
->membase
);
888 if (brdp
->iosize
> 0)
889 release_region(brdp
->iobase
, brdp
->iosize
);
891 stli_brds
[i
] = (stlibrd_t
*) NULL
;
894 restore_flags(flags
);
897 /*****************************************************************************/
900 * Check for any arguments passed in on the module load command line.
903 static void stli_argbrds()
910 printk("stli_argbrds()\n");
913 nrargs
= sizeof(stli_brdsp
) / sizeof(char **);
915 for (i
= stli_nrbrds
; (i
< nrargs
); i
++) {
916 memset(&conf
, 0, sizeof(conf
));
917 if (stli_parsebrd(&conf
, stli_brdsp
[i
]) == 0)
919 if ((brdp
= stli_allocbrd()) == (stlibrd_t
*) NULL
)
923 brdp
->brdtype
= conf
.brdtype
;
924 brdp
->iobase
= conf
.ioaddr1
;
925 brdp
->memaddr
= conf
.memaddr
;
930 /*****************************************************************************/
933 * Convert an ascii string number into an unsigned long.
936 static unsigned long stli_atol(char *str
)
944 if ((*sp
== '0') && (*(sp
+1) == 'x')) {
947 } else if (*sp
== '0') {
954 for (; (*sp
!= 0); sp
++) {
955 c
= (*sp
> '9') ? (TOLOWER(*sp
) - 'a' + 10) : (*sp
- '0');
956 if ((c
< 0) || (c
>= base
)) {
957 printk("STALLION: invalid argument %s\n", str
);
961 val
= (val
* base
) + c
;
966 /*****************************************************************************/
969 * Parse the supplied argument string, into the board conf struct.
972 static int stli_parsebrd(stlconf_t
*confp
, char **argp
)
978 printk("stli_parsebrd(confp=%x,argp=%x)\n", (int) confp
, (int) argp
);
981 if ((argp
[0] == (char *) NULL
) || (*argp
[0] == 0))
984 for (sp
= argp
[0], i
= 0; ((*sp
!= 0) && (i
< 25)); sp
++, i
++)
987 nrbrdnames
= sizeof(stli_brdstr
) / sizeof(stlibrdtype_t
);
988 for (i
= 0; (i
< nrbrdnames
); i
++) {
989 if (strcmp(stli_brdstr
[i
].name
, argp
[0]) == 0)
992 if (i
>= nrbrdnames
) {
993 printk("STALLION: unknown board name, %s?\n", argp
[0]);
997 confp
->brdtype
= stli_brdstr
[i
].type
;
998 if ((argp
[1] != (char *) NULL
) && (*argp
[1] != 0))
999 confp
->ioaddr1
= stli_atol(argp
[1]);
1000 if ((argp
[2] != (char *) NULL
) && (*argp
[2] != 0))
1001 confp
->memaddr
= stli_atol(argp
[2]);
1007 /*****************************************************************************/
1010 * Local driver kernel malloc routine.
1013 static void *stli_memalloc(int len
)
1015 return((void *) kmalloc(len
, GFP_KERNEL
));
1018 /*****************************************************************************/
1020 static int stli_open(struct tty_struct
*tty
, struct file
*filp
)
1024 unsigned int minordev
;
1025 int brdnr
, portnr
, rc
;
1028 printk("stli_open(tty=%x,filp=%x): device=%x\n", (int) tty
,
1029 (int) filp
, tty
->device
);
1032 minordev
= MINOR(tty
->device
);
1033 brdnr
= MINOR2BRD(minordev
);
1034 if (brdnr
>= stli_nrbrds
)
1036 brdp
= stli_brds
[brdnr
];
1037 if (brdp
== (stlibrd_t
*) NULL
)
1039 if ((brdp
->state
& BST_STARTED
) == 0)
1041 portnr
= MINOR2PORT(minordev
);
1042 if ((portnr
< 0) || (portnr
> brdp
->nrports
))
1045 portp
= brdp
->ports
[portnr
];
1046 if (portp
== (stliport_t
*) NULL
)
1048 if (portp
->devnr
< 1)
1054 * Check if this port is in the middle of closing. If so then wait
1055 * until it is closed then return error status based on flag settings.
1056 * The sleep here does not need interrupt protection since the wakeup
1057 * for it is done with the same context.
1059 if (portp
->flags
& ASYNC_CLOSING
) {
1060 interruptible_sleep_on(&portp
->close_wait
);
1061 if (portp
->flags
& ASYNC_HUP_NOTIFY
)
1063 return(-ERESTARTSYS
);
1067 * On the first open of the device setup the port hardware, and
1068 * initialize the per port data structure. Since initializing the port
1069 * requires several commands to the board we will need to wait for any
1070 * other open that is already initializing the port.
1073 tty
->driver_data
= portp
;
1076 while (test_bit(ST_INITIALIZING
, &portp
->state
)) {
1077 if (signal_pending(current
))
1078 return(-ERESTARTSYS
);
1079 interruptible_sleep_on(&portp
->raw_wait
);
1082 if ((portp
->flags
& ASYNC_INITIALIZED
) == 0) {
1083 set_bit(ST_INITIALIZING
, &portp
->state
);
1084 if ((rc
= stli_initopen(brdp
, portp
)) >= 0) {
1085 portp
->flags
|= ASYNC_INITIALIZED
;
1086 clear_bit(TTY_IO_ERROR
, &tty
->flags
);
1088 clear_bit(ST_INITIALIZING
, &portp
->state
);
1089 wake_up_interruptible(&portp
->raw_wait
);
1095 * Check if this port is in the middle of closing. If so then wait
1096 * until it is closed then return error status, based on flag settings.
1097 * The sleep here does not need interrupt protection since the wakeup
1098 * for it is done with the same context.
1100 if (portp
->flags
& ASYNC_CLOSING
) {
1101 interruptible_sleep_on(&portp
->close_wait
);
1102 if (portp
->flags
& ASYNC_HUP_NOTIFY
)
1104 return(-ERESTARTSYS
);
1108 * Based on type of open being done check if it can overlap with any
1109 * previous opens still in effect. If we are a normal serial device
1110 * then also we might have to wait for carrier.
1112 if (tty
->driver
.subtype
== STL_DRVTYPCALLOUT
) {
1113 if (portp
->flags
& ASYNC_NORMAL_ACTIVE
)
1115 if (portp
->flags
& ASYNC_CALLOUT_ACTIVE
) {
1116 if ((portp
->flags
& ASYNC_SESSION_LOCKOUT
) &&
1117 (portp
->session
!= current
->session
))
1119 if ((portp
->flags
& ASYNC_PGRP_LOCKOUT
) &&
1120 (portp
->pgrp
!= current
->pgrp
))
1123 portp
->flags
|= ASYNC_CALLOUT_ACTIVE
;
1125 if (filp
->f_flags
& O_NONBLOCK
) {
1126 if (portp
->flags
& ASYNC_CALLOUT_ACTIVE
)
1129 if ((rc
= stli_waitcarrier(brdp
, portp
, filp
)) != 0)
1132 portp
->flags
|= ASYNC_NORMAL_ACTIVE
;
1135 if ((portp
->refcount
== 1) && (portp
->flags
& ASYNC_SPLIT_TERMIOS
)) {
1136 if (tty
->driver
.subtype
== STL_DRVTYPSERIAL
)
1137 *tty
->termios
= portp
->normaltermios
;
1139 *tty
->termios
= portp
->callouttermios
;
1140 stli_setport(portp
);
1143 portp
->session
= current
->session
;
1144 portp
->pgrp
= current
->pgrp
;
1148 /*****************************************************************************/
1150 static void stli_close(struct tty_struct
*tty
, struct file
*filp
)
1154 unsigned long flags
;
1157 printk("stli_close(tty=%x,filp=%x)\n", (int) tty
, (int) filp
);
1160 portp
= tty
->driver_data
;
1161 if (portp
== (stliport_t
*) NULL
)
1166 if (tty_hung_up_p(filp
)) {
1168 restore_flags(flags
);
1171 if ((tty
->count
== 1) && (portp
->refcount
!= 1))
1172 portp
->refcount
= 1;
1173 if (portp
->refcount
-- > 1) {
1175 restore_flags(flags
);
1179 portp
->flags
|= ASYNC_CLOSING
;
1181 if (portp
->flags
& ASYNC_NORMAL_ACTIVE
)
1182 portp
->normaltermios
= *tty
->termios
;
1183 if (portp
->flags
& ASYNC_CALLOUT_ACTIVE
)
1184 portp
->callouttermios
= *tty
->termios
;
1187 * May want to wait for data to drain before closing. The BUSY flag
1188 * keeps track of whether we are still transmitting or not. It is
1189 * updated by messages from the slave - indicating when all chars
1190 * really have drained.
1192 if (tty
== stli_txcooktty
)
1193 stli_flushchars(tty
);
1195 if (portp
->closing_wait
!= ASYNC_CLOSING_WAIT_NONE
)
1196 tty_wait_until_sent(tty
, portp
->closing_wait
);
1198 portp
->flags
&= ~ASYNC_INITIALIZED
;
1199 brdp
= stli_brds
[portp
->brdnr
];
1200 stli_rawclose(brdp
, portp
, 0, 0);
1201 if (tty
->termios
->c_cflag
& HUPCL
) {
1202 stli_mkasysigs(&portp
->asig
, 0, 0);
1203 if (test_bit(ST_CMDING
, &portp
->state
))
1204 set_bit(ST_DOSIGS
, &portp
->state
);
1206 stli_sendcmd(brdp
, portp
, A_SETSIGNALS
, &portp
->asig
,
1207 sizeof(asysigs_t
), 0);
1209 clear_bit(ST_TXBUSY
, &portp
->state
);
1210 clear_bit(ST_RXSTOP
, &portp
->state
);
1211 set_bit(TTY_IO_ERROR
, &tty
->flags
);
1212 if (tty
->ldisc
.flush_buffer
)
1213 (tty
->ldisc
.flush_buffer
)(tty
);
1214 set_bit(ST_DOFLUSHRX
, &portp
->state
);
1215 stli_flushbuffer(tty
);
1218 portp
->tty
= (struct tty_struct
*) NULL
;
1220 if (portp
->openwaitcnt
) {
1221 if (portp
->close_delay
)
1222 stli_delay(portp
->close_delay
);
1223 wake_up_interruptible(&portp
->open_wait
);
1226 portp
->flags
&= ~(ASYNC_CALLOUT_ACTIVE
| ASYNC_NORMAL_ACTIVE
|
1228 wake_up_interruptible(&portp
->close_wait
);
1230 restore_flags(flags
);
1233 /*****************************************************************************/
1236 * Carry out first open operations on a port. This involves a number of
1237 * commands to be sent to the slave. We need to open the port, set the
1238 * notification events, set the initial port settings, get and set the
1239 * initial signal values. We sleep and wait in between each one. But
1240 * this still all happens pretty quickly.
1243 static int stli_initopen(stlibrd_t
*brdp
, stliport_t
*portp
)
1245 struct tty_struct
*tty
;
1251 printk("stli_initopen(brdp=%x,portp=%x)\n", (int) brdp
, (int) portp
);
1254 if ((rc
= stli_rawopen(brdp
, portp
, 0, 1)) < 0)
1257 memset(&nt
, 0, sizeof(asynotify_t
));
1258 nt
.data
= (DT_TXLOW
| DT_TXEMPTY
| DT_RXBUSY
| DT_RXBREAK
);
1260 if ((rc
= stli_cmdwait(brdp
, portp
, A_SETNOTIFY
, &nt
,
1261 sizeof(asynotify_t
), 0)) < 0)
1265 if (tty
== (struct tty_struct
*) NULL
)
1267 stli_mkasyport(portp
, &aport
, tty
->termios
);
1268 if ((rc
= stli_cmdwait(brdp
, portp
, A_SETPORT
, &aport
,
1269 sizeof(asyport_t
), 0)) < 0)
1272 set_bit(ST_GETSIGS
, &portp
->state
);
1273 if ((rc
= stli_cmdwait(brdp
, portp
, A_GETSIGNALS
, &portp
->asig
,
1274 sizeof(asysigs_t
), 1)) < 0)
1276 if (test_and_clear_bit(ST_GETSIGS
, &portp
->state
))
1277 portp
->sigs
= stli_mktiocm(portp
->asig
.sigvalue
);
1278 stli_mkasysigs(&portp
->asig
, 1, 1);
1279 if ((rc
= stli_cmdwait(brdp
, portp
, A_SETSIGNALS
, &portp
->asig
,
1280 sizeof(asysigs_t
), 0)) < 0)
1286 /*****************************************************************************/
1289 * Send an open message to the slave. This will sleep waiting for the
1290 * acknowledgement, so must have user context. We need to co-ordinate
1291 * with close events here, since we don't want open and close events
1295 static int stli_rawopen(stlibrd_t
*brdp
, stliport_t
*portp
, unsigned long arg
, int wait
)
1297 volatile cdkhdr_t
*hdrp
;
1298 volatile cdkctrl_t
*cp
;
1299 volatile unsigned char *bits
;
1300 unsigned long flags
;
1304 printk("stli_rawopen(brdp=%x,portp=%x,arg=%x,wait=%d)\n",
1305 (int) brdp
, (int) portp
, (int) arg
, wait
);
1309 * Send a message to the slave to open this port.
1315 * Slave is already closing this port. This can happen if a hangup
1316 * occurs on this port. So we must wait until it is complete. The
1317 * order of opens and closes may not be preserved across shared
1318 * memory, so we must wait until it is complete.
1320 while (test_bit(ST_CLOSING
, &portp
->state
)) {
1321 if (signal_pending(current
)) {
1322 restore_flags(flags
);
1323 return(-ERESTARTSYS
);
1325 interruptible_sleep_on(&portp
->raw_wait
);
1329 * Everything is ready now, so write the open message into shared
1330 * memory. Once the message is in set the service bits to say that
1331 * this port wants service.
1334 cp
= &((volatile cdkasy_t
*) EBRDGETMEMPTR(brdp
, portp
->addr
))->ctrl
;
1337 hdrp
= (volatile cdkhdr_t
*) EBRDGETMEMPTR(brdp
, CDK_CDKADDR
);
1338 bits
= ((volatile unsigned char *) hdrp
) + brdp
->slaveoffset
+
1340 *bits
|= portp
->portbit
;
1344 restore_flags(flags
);
1349 * Slave is in action, so now we must wait for the open acknowledgment
1353 set_bit(ST_OPENING
, &portp
->state
);
1354 while (test_bit(ST_OPENING
, &portp
->state
)) {
1355 if (signal_pending(current
)) {
1359 interruptible_sleep_on(&portp
->raw_wait
);
1361 restore_flags(flags
);
1363 if ((rc
== 0) && (portp
->rc
!= 0))
1368 /*****************************************************************************/
1371 * Send a close message to the slave. Normally this will sleep waiting
1372 * for the acknowledgement, but if wait parameter is 0 it will not. If
1373 * wait is true then must have user context (to sleep).
1376 static int stli_rawclose(stlibrd_t
*brdp
, stliport_t
*portp
, unsigned long arg
, int wait
)
1378 volatile cdkhdr_t
*hdrp
;
1379 volatile cdkctrl_t
*cp
;
1380 volatile unsigned char *bits
;
1381 unsigned long flags
;
1385 printk("stli_rawclose(brdp=%x,portp=%x,arg=%x,wait=%d)\n",
1386 (int) brdp
, (int) portp
, (int) arg
, wait
);
1393 * Slave is already closing this port. This can happen if a hangup
1394 * occurs on this port.
1397 while (test_bit(ST_CLOSING
, &portp
->state
)) {
1398 if (signal_pending(current
)) {
1399 restore_flags(flags
);
1400 return(-ERESTARTSYS
);
1402 interruptible_sleep_on(&portp
->raw_wait
);
1407 * Write the close command into shared memory.
1410 cp
= &((volatile cdkasy_t
*) EBRDGETMEMPTR(brdp
, portp
->addr
))->ctrl
;
1413 hdrp
= (volatile cdkhdr_t
*) EBRDGETMEMPTR(brdp
, CDK_CDKADDR
);
1414 bits
= ((volatile unsigned char *) hdrp
) + brdp
->slaveoffset
+
1416 *bits
|= portp
->portbit
;
1419 set_bit(ST_CLOSING
, &portp
->state
);
1421 restore_flags(flags
);
1426 * Slave is in action, so now we must wait for the open acknowledgment
1430 while (test_bit(ST_CLOSING
, &portp
->state
)) {
1431 if (signal_pending(current
)) {
1435 interruptible_sleep_on(&portp
->raw_wait
);
1437 restore_flags(flags
);
1439 if ((rc
== 0) && (portp
->rc
!= 0))
1444 /*****************************************************************************/
1447 * Send a command to the slave and wait for the response. This must
1448 * have user context (it sleeps). This routine is generic in that it
1449 * can send any type of command. Its purpose is to wait for that command
1450 * to complete (as opposed to initiating the command then returning).
1453 static int stli_cmdwait(stlibrd_t
*brdp
, stliport_t
*portp
, unsigned long cmd
, void *arg
, int size
, int copyback
)
1455 unsigned long flags
;
1458 printk("stli_cmdwait(brdp=%x,portp=%x,cmd=%x,arg=%x,size=%d,"
1459 "copyback=%d)\n", (int) brdp
, (int) portp
, (int) cmd
,
1460 (int) arg
, size
, copyback
);
1465 while (test_bit(ST_CMDING
, &portp
->state
)) {
1466 if (signal_pending(current
)) {
1467 restore_flags(flags
);
1468 return(-ERESTARTSYS
);
1470 interruptible_sleep_on(&portp
->raw_wait
);
1473 stli_sendcmd(brdp
, portp
, cmd
, arg
, size
, copyback
);
1475 while (test_bit(ST_CMDING
, &portp
->state
)) {
1476 if (signal_pending(current
)) {
1477 restore_flags(flags
);
1478 return(-ERESTARTSYS
);
1480 interruptible_sleep_on(&portp
->raw_wait
);
1482 restore_flags(flags
);
1489 /*****************************************************************************/
1492 * Send the termios settings for this port to the slave. This sleeps
1493 * waiting for the command to complete - so must have user context.
1496 static int stli_setport(stliport_t
*portp
)
1502 printk("stli_setport(portp=%x)\n", (int) portp
);
1505 if (portp
== (stliport_t
*) NULL
)
1507 if (portp
->tty
== (struct tty_struct
*) NULL
)
1509 if ((portp
->brdnr
< 0) && (portp
->brdnr
>= stli_nrbrds
))
1511 brdp
= stli_brds
[portp
->brdnr
];
1512 if (brdp
== (stlibrd_t
*) NULL
)
1515 stli_mkasyport(portp
, &aport
, portp
->tty
->termios
);
1516 return(stli_cmdwait(brdp
, portp
, A_SETPORT
, &aport
, sizeof(asyport_t
), 0));
1519 /*****************************************************************************/
1522 * Wait for a specified delay period, this is not a busy-loop. It will
1523 * give up the processor while waiting. Unfortunately this has some
1524 * rather intimate knowledge of the process management stuff.
1527 static void stli_delay(int len
)
1530 printk("stli_delay(len=%d)\n", len
);
1533 current
->state
= TASK_INTERRUPTIBLE
;
1534 schedule_timeout(len
);
1535 current
->state
= TASK_RUNNING
;
1539 /*****************************************************************************/
1542 * Possibly need to wait for carrier (DCD signal) to come high. Say
1543 * maybe because if we are clocal then we don't need to wait...
1546 static int stli_waitcarrier(stlibrd_t
*brdp
, stliport_t
*portp
, struct file
*filp
)
1548 unsigned long flags
;
1552 printk("stli_waitcarrier(brdp=%x,portp=%x,filp=%x)\n",
1553 (int) brdp
, (int) portp
, (int) filp
);
1559 if (portp
->flags
& ASYNC_CALLOUT_ACTIVE
) {
1560 if (portp
->normaltermios
.c_cflag
& CLOCAL
)
1563 if (portp
->tty
->termios
->c_cflag
& CLOCAL
)
1569 portp
->openwaitcnt
++;
1570 if (! tty_hung_up_p(filp
))
1574 if ((portp
->flags
& ASYNC_CALLOUT_ACTIVE
) == 0) {
1575 stli_mkasysigs(&portp
->asig
, 1, 1);
1576 if ((rc
= stli_cmdwait(brdp
, portp
, A_SETSIGNALS
,
1577 &portp
->asig
, sizeof(asysigs_t
), 0)) < 0)
1580 if (tty_hung_up_p(filp
) ||
1581 ((portp
->flags
& ASYNC_INITIALIZED
) == 0)) {
1582 if (portp
->flags
& ASYNC_HUP_NOTIFY
)
1588 if (((portp
->flags
& ASYNC_CALLOUT_ACTIVE
) == 0) &&
1589 ((portp
->flags
& ASYNC_CLOSING
) == 0) &&
1590 (doclocal
|| (portp
->sigs
& TIOCM_CD
))) {
1593 if (signal_pending(current
)) {
1597 interruptible_sleep_on(&portp
->open_wait
);
1600 if (! tty_hung_up_p(filp
))
1602 portp
->openwaitcnt
--;
1603 restore_flags(flags
);
1608 /*****************************************************************************/
1611 * Write routine. Take the data and put it in the shared memory ring
1612 * queue. If port is not already sending chars then need to mark the
1613 * service bits for this port.
1616 static int stli_write(struct tty_struct
*tty
, int from_user
, const unsigned char *buf
, int count
)
1618 volatile cdkasy_t
*ap
;
1619 volatile cdkhdr_t
*hdrp
;
1620 volatile unsigned char *bits
;
1621 unsigned char *shbuf
, *chbuf
;
1624 unsigned int len
, stlen
, head
, tail
, size
;
1625 unsigned long flags
;
1628 printk("stli_write(tty=%x,from_user=%d,buf=%x,count=%d)\n",
1629 (int) tty
, from_user
, (int) buf
, count
);
1632 if ((tty
== (struct tty_struct
*) NULL
) ||
1633 (stli_tmpwritebuf
== (char *) NULL
))
1635 if (tty
== stli_txcooktty
)
1636 stli_flushchars(tty
);
1637 portp
= tty
->driver_data
;
1638 if (portp
== (stliport_t
*) NULL
)
1640 if ((portp
->brdnr
< 0) || (portp
->brdnr
>= stli_nrbrds
))
1642 brdp
= stli_brds
[portp
->brdnr
];
1643 if (brdp
== (stlibrd_t
*) NULL
)
1645 chbuf
= (unsigned char *) buf
;
1648 * If copying direct from user space we need to be able to handle page
1649 * faults while we are copying. To do this copy as much as we can now
1650 * into a kernel buffer. From there we copy it into shared memory. The
1651 * big problem is that we do not want shared memory enabled when we are
1652 * sleeping (other boards may be serviced while asleep). Something else
1653 * to note here is the reading of the tail twice. Since the boards
1654 * shared memory can be on an 8-bit bus then we need to be very careful
1655 * reading 16 bit quantities - since both the board (slave) and host
1656 * could be writing and reading at the same time.
1662 ap
= (volatile cdkasy_t
*) EBRDGETMEMPTR(brdp
, portp
->addr
);
1663 head
= (unsigned int) ap
->txq
.head
;
1664 tail
= (unsigned int) ap
->txq
.tail
;
1665 if (tail
!= ((unsigned int) ap
->txq
.tail
))
1666 tail
= (unsigned int) ap
->txq
.tail
;
1667 len
= (head
>= tail
) ? (portp
->txsize
- (head
- tail
) - 1) :
1669 count
= MIN(len
, count
);
1671 restore_flags(flags
);
1673 down(&stli_tmpwritesem
);
1674 copy_from_user(stli_tmpwritebuf
, chbuf
, count
);
1675 chbuf
= &stli_tmpwritebuf
[0];
1679 * All data is now local, shove as much as possible into shared memory.
1684 ap
= (volatile cdkasy_t
*) EBRDGETMEMPTR(brdp
, portp
->addr
);
1685 head
= (unsigned int) ap
->txq
.head
;
1686 tail
= (unsigned int) ap
->txq
.tail
;
1687 if (tail
!= ((unsigned int) ap
->txq
.tail
))
1688 tail
= (unsigned int) ap
->txq
.tail
;
1689 size
= portp
->txsize
;
1691 len
= size
- (head
- tail
) - 1;
1692 stlen
= size
- head
;
1694 len
= tail
- head
- 1;
1698 len
= MIN(len
, count
);
1700 shbuf
= (char *) EBRDGETMEMPTR(brdp
, portp
->txoffset
);
1703 stlen
= MIN(len
, stlen
);
1704 memcpy((shbuf
+ head
), chbuf
, stlen
);
1715 ap
= (volatile cdkasy_t
*) EBRDGETMEMPTR(brdp
, portp
->addr
);
1716 ap
->txq
.head
= head
;
1717 if (test_bit(ST_TXBUSY
, &portp
->state
)) {
1718 if (ap
->changed
.data
& DT_TXEMPTY
)
1719 ap
->changed
.data
&= ~DT_TXEMPTY
;
1721 hdrp
= (volatile cdkhdr_t
*) EBRDGETMEMPTR(brdp
, CDK_CDKADDR
);
1722 bits
= ((volatile unsigned char *) hdrp
) + brdp
->slaveoffset
+
1724 *bits
|= portp
->portbit
;
1725 set_bit(ST_TXBUSY
, &portp
->state
);
1729 up(&stli_tmpwritesem
);
1730 restore_flags(flags
);
1735 /*****************************************************************************/
1738 * Output a single character. We put it into a temporary local buffer
1739 * (for speed) then write out that buffer when the flushchars routine
1740 * is called. There is a safety catch here so that if some other port
1741 * writes chars before the current buffer has been, then we write them
1742 * first them do the new ports.
1745 static void stli_putchar(struct tty_struct
*tty
, unsigned char ch
)
1748 printk("stli_putchar(tty=%x,ch=%x)\n", (int) tty
, (int) ch
);
1751 if (tty
== (struct tty_struct
*) NULL
)
1753 if (tty
!= stli_txcooktty
) {
1754 if (stli_txcooktty
!= (struct tty_struct
*) NULL
)
1755 stli_flushchars(stli_txcooktty
);
1756 stli_txcooktty
= tty
;
1759 stli_txcookbuf
[stli_txcooksize
++] = ch
;
1762 /*****************************************************************************/
1765 * Transfer characters from the local TX cooking buffer to the board.
1766 * We sort of ignore the tty that gets passed in here. We rely on the
1767 * info stored with the TX cook buffer to tell us which port to flush
1768 * the data on. In any case we clean out the TX cook buffer, for re-use
1772 static void stli_flushchars(struct tty_struct
*tty
)
1774 volatile cdkhdr_t
*hdrp
;
1775 volatile unsigned char *bits
;
1776 volatile cdkasy_t
*ap
;
1777 struct tty_struct
*cooktty
;
1780 unsigned int len
, stlen
, head
, tail
, size
, count
, cooksize
;
1781 unsigned char *buf
, *shbuf
;
1782 unsigned long flags
;
1785 printk("stli_flushchars(tty=%x)\n", (int) tty
);
1788 cooksize
= stli_txcooksize
;
1789 cooktty
= stli_txcooktty
;
1790 stli_txcooksize
= 0;
1791 stli_txcookrealsize
= 0;
1792 stli_txcooktty
= (struct tty_struct
*) NULL
;
1794 if (tty
== (struct tty_struct
*) NULL
)
1796 if (cooktty
== (struct tty_struct
*) NULL
)
1803 portp
= tty
->driver_data
;
1804 if (portp
== (stliport_t
*) NULL
)
1806 if ((portp
->brdnr
< 0) || (portp
->brdnr
>= stli_nrbrds
))
1808 brdp
= stli_brds
[portp
->brdnr
];
1809 if (brdp
== (stlibrd_t
*) NULL
)
1816 ap
= (volatile cdkasy_t
*) EBRDGETMEMPTR(brdp
, portp
->addr
);
1817 head
= (unsigned int) ap
->txq
.head
;
1818 tail
= (unsigned int) ap
->txq
.tail
;
1819 if (tail
!= ((unsigned int) ap
->txq
.tail
))
1820 tail
= (unsigned int) ap
->txq
.tail
;
1821 size
= portp
->txsize
;
1823 len
= size
- (head
- tail
) - 1;
1824 stlen
= size
- head
;
1826 len
= tail
- head
- 1;
1830 len
= MIN(len
, cooksize
);
1832 shbuf
= (char *) EBRDGETMEMPTR(brdp
, portp
->txoffset
);
1833 buf
= stli_txcookbuf
;
1836 stlen
= MIN(len
, stlen
);
1837 memcpy((shbuf
+ head
), buf
, stlen
);
1848 ap
= (volatile cdkasy_t
*) EBRDGETMEMPTR(brdp
, portp
->addr
);
1849 ap
->txq
.head
= head
;
1851 if (test_bit(ST_TXBUSY
, &portp
->state
)) {
1852 if (ap
->changed
.data
& DT_TXEMPTY
)
1853 ap
->changed
.data
&= ~DT_TXEMPTY
;
1855 hdrp
= (volatile cdkhdr_t
*) EBRDGETMEMPTR(brdp
, CDK_CDKADDR
);
1856 bits
= ((volatile unsigned char *) hdrp
) + brdp
->slaveoffset
+
1858 *bits
|= portp
->portbit
;
1859 set_bit(ST_TXBUSY
, &portp
->state
);
1862 restore_flags(flags
);
1865 /*****************************************************************************/
1867 static int stli_writeroom(struct tty_struct
*tty
)
1869 volatile cdkasyrq_t
*rp
;
1872 unsigned int head
, tail
, len
;
1873 unsigned long flags
;
1876 printk("stli_writeroom(tty=%x)\n", (int) tty
);
1879 if (tty
== (struct tty_struct
*) NULL
)
1881 if (tty
== stli_txcooktty
) {
1882 if (stli_txcookrealsize
!= 0) {
1883 len
= stli_txcookrealsize
- stli_txcooksize
;
1888 portp
= tty
->driver_data
;
1889 if (portp
== (stliport_t
*) NULL
)
1891 if ((portp
->brdnr
< 0) || (portp
->brdnr
>= stli_nrbrds
))
1893 brdp
= stli_brds
[portp
->brdnr
];
1894 if (brdp
== (stlibrd_t
*) NULL
)
1900 rp
= &((volatile cdkasy_t
*) EBRDGETMEMPTR(brdp
, portp
->addr
))->txq
;
1901 head
= (unsigned int) rp
->head
;
1902 tail
= (unsigned int) rp
->tail
;
1903 if (tail
!= ((unsigned int) rp
->tail
))
1904 tail
= (unsigned int) rp
->tail
;
1905 len
= (head
>= tail
) ? (portp
->txsize
- (head
- tail
)) : (tail
- head
);
1908 restore_flags(flags
);
1910 if (tty
== stli_txcooktty
) {
1911 stli_txcookrealsize
= len
;
1912 len
-= stli_txcooksize
;
1917 /*****************************************************************************/
1920 * Return the number of characters in the transmit buffer. Normally we
1921 * will return the number of chars in the shared memory ring queue.
1922 * We need to kludge around the case where the shared memory buffer is
1923 * empty but not all characters have drained yet, for this case just
1924 * return that there is 1 character in the buffer!
1927 static int stli_charsinbuffer(struct tty_struct
*tty
)
1929 volatile cdkasyrq_t
*rp
;
1932 unsigned int head
, tail
, len
;
1933 unsigned long flags
;
1936 printk("stli_charsinbuffer(tty=%x)\n", (int) tty
);
1939 if (tty
== (struct tty_struct
*) NULL
)
1941 if (tty
== stli_txcooktty
)
1942 stli_flushchars(tty
);
1943 portp
= tty
->driver_data
;
1944 if (portp
== (stliport_t
*) NULL
)
1946 if ((portp
->brdnr
< 0) || (portp
->brdnr
>= stli_nrbrds
))
1948 brdp
= stli_brds
[portp
->brdnr
];
1949 if (brdp
== (stlibrd_t
*) NULL
)
1955 rp
= &((volatile cdkasy_t
*) EBRDGETMEMPTR(brdp
, portp
->addr
))->txq
;
1956 head
= (unsigned int) rp
->head
;
1957 tail
= (unsigned int) rp
->tail
;
1958 if (tail
!= ((unsigned int) rp
->tail
))
1959 tail
= (unsigned int) rp
->tail
;
1960 len
= (head
>= tail
) ? (head
- tail
) : (portp
->txsize
- (tail
- head
));
1961 if ((len
== 0) && test_bit(ST_TXBUSY
, &portp
->state
))
1964 restore_flags(flags
);
1969 /*****************************************************************************/
1972 * Generate the serial struct info.
1975 static void stli_getserial(stliport_t
*portp
, struct serial_struct
*sp
)
1977 struct serial_struct sio
;
1981 printk("stli_getserial(portp=%x,sp=%x)\n", (int) portp
, (int) sp
);
1984 memset(&sio
, 0, sizeof(struct serial_struct
));
1985 sio
.type
= PORT_UNKNOWN
;
1986 sio
.line
= portp
->portnr
;
1988 sio
.flags
= portp
->flags
;
1989 sio
.baud_base
= portp
->baud_base
;
1990 sio
.close_delay
= portp
->close_delay
;
1991 sio
.closing_wait
= portp
->closing_wait
;
1992 sio
.custom_divisor
= portp
->custom_divisor
;
1993 sio
.xmit_fifo_size
= 0;
1996 brdp
= stli_brds
[portp
->brdnr
];
1997 if (brdp
!= (stlibrd_t
*) NULL
)
1998 sio
.port
= brdp
->iobase
;
2000 copy_to_user(sp
, &sio
, sizeof(struct serial_struct
));
2003 /*****************************************************************************/
2006 * Set port according to the serial struct info.
2007 * At this point we do not do any auto-configure stuff, so we will
2008 * just quietly ignore any requests to change irq, etc.
2011 static int stli_setserial(stliport_t
*portp
, struct serial_struct
*sp
)
2013 struct serial_struct sio
;
2017 printk("stli_setserial(portp=%x,sp=%x)\n", (int) portp
, (int) sp
);
2020 copy_from_user(&sio
, sp
, sizeof(struct serial_struct
));
2021 if (!capable(CAP_SYS_ADMIN
)) {
2022 if ((sio
.baud_base
!= portp
->baud_base
) ||
2023 (sio
.close_delay
!= portp
->close_delay
) ||
2024 ((sio
.flags
& ~ASYNC_USR_MASK
) !=
2025 (portp
->flags
& ~ASYNC_USR_MASK
)))
2029 portp
->flags
= (portp
->flags
& ~ASYNC_USR_MASK
) |
2030 (sio
.flags
& ASYNC_USR_MASK
);
2031 portp
->baud_base
= sio
.baud_base
;
2032 portp
->close_delay
= sio
.close_delay
;
2033 portp
->closing_wait
= sio
.closing_wait
;
2034 portp
->custom_divisor
= sio
.custom_divisor
;
2036 if ((rc
= stli_setport(portp
)) < 0)
2041 /*****************************************************************************/
2043 static int stli_ioctl(struct tty_struct
*tty
, struct file
*file
, unsigned int cmd
, unsigned long arg
)
2052 printk("stli_ioctl(tty=%x,file=%x,cmd=%x,arg=%x)\n",
2053 (int) tty
, (int) file
, cmd
, (int) arg
);
2056 if (tty
== (struct tty_struct
*) NULL
)
2058 portp
= tty
->driver_data
;
2059 if (portp
== (stliport_t
*) NULL
)
2061 if ((portp
->brdnr
< 0) || (portp
->brdnr
>= stli_nrbrds
))
2063 brdp
= stli_brds
[portp
->brdnr
];
2064 if (brdp
== (stlibrd_t
*) NULL
)
2067 if ((cmd
!= TIOCGSERIAL
) && (cmd
!= TIOCSSERIAL
) &&
2068 (cmd
!= COM_GETPORTSTATS
) && (cmd
!= COM_CLRPORTSTATS
)) {
2069 if (tty
->flags
& (1 << TTY_IO_ERROR
))
2077 rc
= put_user(((tty
->termios
->c_cflag
& CLOCAL
) ? 1 : 0),
2078 (unsigned int *) arg
);
2081 if ((rc
= verify_area(VERIFY_READ
, (void *) arg
,
2082 sizeof(unsigned int))) == 0) {
2083 get_user(ival
, (unsigned int *) arg
);
2084 tty
->termios
->c_cflag
=
2085 (tty
->termios
->c_cflag
& ~CLOCAL
) |
2086 (ival
? CLOCAL
: 0);
2090 if ((rc
= verify_area(VERIFY_WRITE
, (void *) arg
,
2091 sizeof(unsigned int))) == 0) {
2092 if ((rc
= stli_cmdwait(brdp
, portp
, A_GETSIGNALS
,
2093 &portp
->asig
, sizeof(asysigs_t
), 1)) < 0)
2095 lval
= stli_mktiocm(portp
->asig
.sigvalue
);
2096 put_user(lval
, (unsigned int *) arg
);
2100 if ((rc
= verify_area(VERIFY_READ
, (void *) arg
,
2101 sizeof(unsigned int))) == 0) {
2102 get_user(ival
, (unsigned int *) arg
);
2103 stli_mkasysigs(&portp
->asig
,
2104 ((ival
& TIOCM_DTR
) ? 1 : -1),
2105 ((ival
& TIOCM_RTS
) ? 1 : -1));
2106 rc
= stli_cmdwait(brdp
, portp
, A_SETSIGNALS
,
2107 &portp
->asig
, sizeof(asysigs_t
), 0);
2111 if ((rc
= verify_area(VERIFY_READ
, (void *) arg
,
2112 sizeof(unsigned int))) == 0) {
2113 get_user(ival
, (unsigned int *) arg
);
2114 stli_mkasysigs(&portp
->asig
,
2115 ((ival
& TIOCM_DTR
) ? 0 : -1),
2116 ((ival
& TIOCM_RTS
) ? 0 : -1));
2117 rc
= stli_cmdwait(brdp
, portp
, A_SETSIGNALS
,
2118 &portp
->asig
, sizeof(asysigs_t
), 0);
2122 if ((rc
= verify_area(VERIFY_READ
, (void *) arg
,
2123 sizeof(unsigned int))) == 0) {
2124 get_user(ival
, (unsigned int *) arg
);
2125 stli_mkasysigs(&portp
->asig
,
2126 ((ival
& TIOCM_DTR
) ? 1 : 0),
2127 ((ival
& TIOCM_RTS
) ? 1 : 0));
2128 rc
= stli_cmdwait(brdp
, portp
, A_SETSIGNALS
,
2129 &portp
->asig
, sizeof(asysigs_t
), 0);
2133 if ((rc
= verify_area(VERIFY_WRITE
, (void *) arg
,
2134 sizeof(struct serial_struct
))) == 0)
2135 stli_getserial(portp
, (struct serial_struct
*) arg
);
2138 if ((rc
= verify_area(VERIFY_READ
, (void *) arg
,
2139 sizeof(struct serial_struct
))) == 0)
2140 rc
= stli_setserial(portp
, (struct serial_struct
*)arg
);
2143 if ((rc
= verify_area(VERIFY_WRITE
, (void *) arg
,
2144 sizeof(unsigned long))) == 0)
2145 put_user(portp
->pflag
, (unsigned int *) arg
);
2148 if ((rc
= verify_area(VERIFY_READ
, (void *) arg
,
2149 sizeof(unsigned long))) == 0) {
2150 get_user(portp
->pflag
, (unsigned int *) arg
);
2151 stli_setport(portp
);
2154 case COM_GETPORTSTATS
:
2155 if ((rc
= verify_area(VERIFY_WRITE
, (void *) arg
,
2156 sizeof(comstats_t
))) == 0)
2157 rc
= stli_getportstats(portp
, (comstats_t
*) arg
);
2159 case COM_CLRPORTSTATS
:
2160 if ((rc
= verify_area(VERIFY_WRITE
, (void *) arg
,
2161 sizeof(comstats_t
))) == 0)
2162 rc
= stli_clrportstats(portp
, (comstats_t
*) arg
);
2168 case TIOCSERGSTRUCT
:
2169 case TIOCSERGETMULTI
:
2170 case TIOCSERSETMULTI
:
2179 /*****************************************************************************/
2182 * This routine assumes that we have user context and can sleep.
2183 * Looks like it is true for the current ttys implementation..!!
2186 static void stli_settermios(struct tty_struct
*tty
, struct termios
*old
)
2190 struct termios
*tiosp
;
2194 printk("stli_settermios(tty=%x,old=%x)\n", (int) tty
, (int) old
);
2197 if (tty
== (struct tty_struct
*) NULL
)
2199 portp
= tty
->driver_data
;
2200 if (portp
== (stliport_t
*) NULL
)
2202 if ((portp
->brdnr
< 0) || (portp
->brdnr
>= stli_nrbrds
))
2204 brdp
= stli_brds
[portp
->brdnr
];
2205 if (brdp
== (stlibrd_t
*) NULL
)
2208 tiosp
= tty
->termios
;
2209 if ((tiosp
->c_cflag
== old
->c_cflag
) &&
2210 (tiosp
->c_iflag
== old
->c_iflag
))
2213 stli_mkasyport(portp
, &aport
, tiosp
);
2214 stli_cmdwait(brdp
, portp
, A_SETPORT
, &aport
, sizeof(asyport_t
), 0);
2215 stli_mkasysigs(&portp
->asig
, ((tiosp
->c_cflag
& CBAUD
) ? 1 : 0), -1);
2216 stli_cmdwait(brdp
, portp
, A_SETSIGNALS
, &portp
->asig
,
2217 sizeof(asysigs_t
), 0);
2218 if ((old
->c_cflag
& CRTSCTS
) && ((tiosp
->c_cflag
& CRTSCTS
) == 0))
2219 tty
->hw_stopped
= 0;
2220 if (((old
->c_cflag
& CLOCAL
) == 0) && (tiosp
->c_cflag
& CLOCAL
))
2221 wake_up_interruptible(&portp
->open_wait
);
2224 /*****************************************************************************/
2227 * Attempt to flow control who ever is sending us data. We won't really
2228 * do any flow control action here. We can't directly, and even if we
2229 * wanted to we would have to send a command to the slave. The slave
2230 * knows how to flow control, and will do so when its buffers reach its
2231 * internal high water marks. So what we will do is set a local state
2232 * bit that will stop us sending any RX data up from the poll routine
2233 * (which is the place where RX data from the slave is handled).
2236 static void stli_throttle(struct tty_struct
*tty
)
2241 printk("stli_throttle(tty=%x)\n", (int) tty
);
2244 if (tty
== (struct tty_struct
*) NULL
)
2246 portp
= tty
->driver_data
;
2247 if (portp
== (stliport_t
*) NULL
)
2250 set_bit(ST_RXSTOP
, &portp
->state
);
2253 /*****************************************************************************/
2256 * Unflow control the device sending us data... That means that all
2257 * we have to do is clear the RXSTOP state bit. The next poll call
2258 * will then be able to pass the RX data back up.
2261 static void stli_unthrottle(struct tty_struct
*tty
)
2266 printk("stli_unthrottle(tty=%x)\n", (int) tty
);
2269 if (tty
== (struct tty_struct
*) NULL
)
2271 portp
= tty
->driver_data
;
2272 if (portp
== (stliport_t
*) NULL
)
2275 clear_bit(ST_RXSTOP
, &portp
->state
);
2278 /*****************************************************************************/
2281 * Stop the transmitter. Basically to do this we will just turn TX
2285 static void stli_stop(struct tty_struct
*tty
)
2292 printk("stli_stop(tty=%x)\n", (int) tty
);
2295 if (tty
== (struct tty_struct
*) NULL
)
2297 portp
= tty
->driver_data
;
2298 if (portp
== (stliport_t
*) NULL
)
2300 if ((portp
->brdnr
< 0) || (portp
->brdnr
>= stli_nrbrds
))
2302 brdp
= stli_brds
[portp
->brdnr
];
2303 if (brdp
== (stlibrd_t
*) NULL
)
2306 memset(&actrl
, 0, sizeof(asyctrl_t
));
2307 actrl
.txctrl
= CT_STOPFLOW
;
2309 stli_cmdwait(brdp
, portp
, A_PORTCTRL
, &actrl
, sizeof(asyctrl_t
), 0);
2313 /*****************************************************************************/
2316 * Start the transmitter again. Just turn TX interrupts back on.
2319 static void stli_start(struct tty_struct
*tty
)
2326 printk("stli_start(tty=%x)\n", (int) tty
);
2329 if (tty
== (struct tty_struct
*) NULL
)
2331 portp
= tty
->driver_data
;
2332 if (portp
== (stliport_t
*) NULL
)
2334 if ((portp
->brdnr
< 0) || (portp
->brdnr
>= stli_nrbrds
))
2336 brdp
= stli_brds
[portp
->brdnr
];
2337 if (brdp
== (stlibrd_t
*) NULL
)
2340 memset(&actrl
, 0, sizeof(asyctrl_t
));
2341 actrl
.txctrl
= CT_STARTFLOW
;
2343 stli_cmdwait(brdp
, portp
, A_PORTCTRL
, &actrl
, sizeof(asyctrl_t
), 0);
2347 /*****************************************************************************/
2350 * Scheduler called hang up routine. This is called from the scheduler,
2351 * not direct from the driver "poll" routine. We can't call it there
2352 * since the real local hangup code will enable/disable the board and
2353 * other things that we can't do while handling the poll. Much easier
2354 * to deal with it some time later (don't really care when, hangups
2355 * aren't that time critical).
2358 static void stli_dohangup(void *arg
)
2363 printk("stli_dohangup(portp=%x)\n", (int) arg
);
2366 portp
= (stliport_t
*) arg
;
2367 if (portp
== (stliport_t
*) NULL
)
2369 if (portp
->tty
== (struct tty_struct
*) NULL
)
2371 tty_hangup(portp
->tty
);
2374 /*****************************************************************************/
2377 * Hangup this port. This is pretty much like closing the port, only
2378 * a little more brutal. No waiting for data to drain. Shutdown the
2379 * port and maybe drop signals. This is rather tricky really. We want
2380 * to close the port as well.
2383 static void stli_hangup(struct tty_struct
*tty
)
2387 unsigned long flags
;
2390 printk("stli_hangup(tty=%x)\n", (int) tty
);
2393 if (tty
== (struct tty_struct
*) NULL
)
2395 portp
= tty
->driver_data
;
2396 if (portp
== (stliport_t
*) NULL
)
2398 if ((portp
->brdnr
< 0) || (portp
->brdnr
>= stli_nrbrds
))
2400 brdp
= stli_brds
[portp
->brdnr
];
2401 if (brdp
== (stlibrd_t
*) NULL
)
2404 portp
->flags
&= ~ASYNC_INITIALIZED
;
2408 if (! test_bit(ST_CLOSING
, &portp
->state
))
2409 stli_rawclose(brdp
, portp
, 0, 0);
2410 if (tty
->termios
->c_cflag
& HUPCL
) {
2411 stli_mkasysigs(&portp
->asig
, 0, 0);
2412 if (test_bit(ST_CMDING
, &portp
->state
)) {
2413 set_bit(ST_DOSIGS
, &portp
->state
);
2414 set_bit(ST_DOFLUSHTX
, &portp
->state
);
2415 set_bit(ST_DOFLUSHRX
, &portp
->state
);
2417 stli_sendcmd(brdp
, portp
, A_SETSIGNALSF
,
2418 &portp
->asig
, sizeof(asysigs_t
), 0);
2421 restore_flags(flags
);
2423 clear_bit(ST_TXBUSY
, &portp
->state
);
2424 clear_bit(ST_RXSTOP
, &portp
->state
);
2425 set_bit(TTY_IO_ERROR
, &tty
->flags
);
2426 portp
->tty
= (struct tty_struct
*) NULL
;
2427 portp
->flags
&= ~(ASYNC_NORMAL_ACTIVE
| ASYNC_CALLOUT_ACTIVE
);
2428 portp
->refcount
= 0;
2429 wake_up_interruptible(&portp
->open_wait
);
2432 /*****************************************************************************/
2435 * Flush characters from the lower buffer. We may not have user context
2436 * so we cannot sleep waiting for it to complete. Also we need to check
2437 * if there is chars for this port in the TX cook buffer, and flush them
2441 static void stli_flushbuffer(struct tty_struct
*tty
)
2445 unsigned long ftype
, flags
;
2448 printk("stli_flushbuffer(tty=%x)\n", (int) tty
);
2451 if (tty
== (struct tty_struct
*) NULL
)
2453 portp
= tty
->driver_data
;
2454 if (portp
== (stliport_t
*) NULL
)
2456 if ((portp
->brdnr
< 0) || (portp
->brdnr
>= stli_nrbrds
))
2458 brdp
= stli_brds
[portp
->brdnr
];
2459 if (brdp
== (stlibrd_t
*) NULL
)
2464 if (tty
== stli_txcooktty
) {
2465 stli_txcooktty
= (struct tty_struct
*) NULL
;
2466 stli_txcooksize
= 0;
2467 stli_txcookrealsize
= 0;
2469 if (test_bit(ST_CMDING
, &portp
->state
)) {
2470 set_bit(ST_DOFLUSHTX
, &portp
->state
);
2473 if (test_bit(ST_DOFLUSHRX
, &portp
->state
)) {
2475 clear_bit(ST_DOFLUSHRX
, &portp
->state
);
2477 stli_sendcmd(brdp
, portp
, A_FLUSH
, &ftype
,
2478 sizeof(unsigned long), 0);
2480 restore_flags(flags
);
2482 wake_up_interruptible(&tty
->write_wait
);
2483 if ((tty
->flags
& (1 << TTY_DO_WRITE_WAKEUP
)) &&
2484 tty
->ldisc
.write_wakeup
)
2485 (tty
->ldisc
.write_wakeup
)(tty
);
2488 /*****************************************************************************/
2490 static void stli_breakctl(struct tty_struct
*tty
, int state
)
2495 /* long savestate, savetime; */
2498 printk("stli_breakctl(tty=%x,state=%d)\n", (int) tty
, state
);
2501 if (tty
== (struct tty_struct
*) NULL
)
2503 portp
= tty
->driver_data
;
2504 if (portp
== (stliport_t
*) NULL
)
2506 if ((portp
->brdnr
< 0) || (portp
->brdnr
>= stli_nrbrds
))
2508 brdp
= stli_brds
[portp
->brdnr
];
2509 if (brdp
== (stlibrd_t
*) NULL
)
2513 * Due to a bug in the tty send_break() code we need to preserve
2514 * the current process state and timeout...
2515 savetime = current->timeout;
2516 savestate = current->state;
2519 arg
= (state
== -1) ? BREAKON
: BREAKOFF
;
2520 stli_cmdwait(brdp
, portp
, A_BREAK
, &arg
, sizeof(long), 0);
2524 current->timeout = savetime;
2525 current->state = savestate;
2529 /*****************************************************************************/
2531 static void stli_waituntilsent(struct tty_struct
*tty
, int timeout
)
2537 printk("stli_waituntilsent(tty=%x,timeout=%x)\n", (int) tty
, timeout
);
2540 if (tty
== (struct tty_struct
*) NULL
)
2542 portp
= tty
->driver_data
;
2543 if (portp
== (stliport_t
*) NULL
)
2548 tend
= jiffies
+ timeout
;
2550 while (test_bit(ST_TXBUSY
, &portp
->state
)) {
2551 if (signal_pending(current
))
2554 if (time_after_eq(jiffies
, tend
))
2559 /*****************************************************************************/
2561 static void stli_sendxchar(struct tty_struct
*tty
, char ch
)
2568 printk("stli_sendxchar(tty=%x,ch=%x)\n", (int) tty
, ch
);
2571 if (tty
== (struct tty_struct
*) NULL
)
2573 portp
= tty
->driver_data
;
2574 if (portp
== (stliport_t
*) NULL
)
2576 if ((portp
->brdnr
< 0) || (portp
->brdnr
>= stli_nrbrds
))
2578 brdp
= stli_brds
[portp
->brdnr
];
2579 if (brdp
== (stlibrd_t
*) NULL
)
2582 memset(&actrl
, 0, sizeof(asyctrl_t
));
2583 if (ch
== STOP_CHAR(tty
)) {
2584 actrl
.rxctrl
= CT_STOPFLOW
;
2585 } else if (ch
== START_CHAR(tty
)) {
2586 actrl
.rxctrl
= CT_STARTFLOW
;
2588 actrl
.txctrl
= CT_SENDCHR
;
2592 stli_cmdwait(brdp
, portp
, A_PORTCTRL
, &actrl
, sizeof(asyctrl_t
), 0);
2595 /*****************************************************************************/
2600 * Format info for a specified port. The line is deliberately limited
2601 * to 80 characters. (If it is too long it will be truncated, if too
2602 * short then padded with spaces).
2605 static int stli_portinfo(stlibrd_t
*brdp
, stliport_t
*portp
, int portnr
, char *pos
)
2610 rc
= stli_portcmdstats(portp
);
2613 if (brdp
->state
& BST_STARTED
) {
2614 switch (stli_comstats
.hwid
) {
2615 case 0: uart
= "2681"; break;
2616 case 1: uart
= "SC26198"; break;
2617 default: uart
= "CD1400"; break;
2622 sp
+= sprintf(sp
, "%d: uart:%s ", portnr
, uart
);
2624 if ((brdp
->state
& BST_STARTED
) && (rc
>= 0)) {
2625 sp
+= sprintf(sp
, "tx:%d rx:%d", (int) stli_comstats
.txtotal
,
2626 (int) stli_comstats
.rxtotal
);
2628 if (stli_comstats
.rxframing
)
2629 sp
+= sprintf(sp
, " fe:%d",
2630 (int) stli_comstats
.rxframing
);
2631 if (stli_comstats
.rxparity
)
2632 sp
+= sprintf(sp
, " pe:%d",
2633 (int) stli_comstats
.rxparity
);
2634 if (stli_comstats
.rxbreaks
)
2635 sp
+= sprintf(sp
, " brk:%d",
2636 (int) stli_comstats
.rxbreaks
);
2637 if (stli_comstats
.rxoverrun
)
2638 sp
+= sprintf(sp
, " oe:%d",
2639 (int) stli_comstats
.rxoverrun
);
2641 cnt
= sprintf(sp
, "%s%s%s%s%s ",
2642 (stli_comstats
.signals
& TIOCM_RTS
) ? "|RTS" : "",
2643 (stli_comstats
.signals
& TIOCM_CTS
) ? "|CTS" : "",
2644 (stli_comstats
.signals
& TIOCM_DTR
) ? "|DTR" : "",
2645 (stli_comstats
.signals
& TIOCM_CD
) ? "|DCD" : "",
2646 (stli_comstats
.signals
& TIOCM_DSR
) ? "|DSR" : "");
2651 for (cnt
= (sp
- pos
); (cnt
< (MAXLINE
- 1)); cnt
++)
2654 pos
[(MAXLINE
- 2)] = '+';
2655 pos
[(MAXLINE
- 1)] = '\n';
2660 /*****************************************************************************/
2663 * Port info, read from the /proc file system.
2666 static int stli_readproc(char *page
, char **start
, off_t off
, int count
, int *eof
, void *data
)
2670 int brdnr
, portnr
, totalport
;
2675 printk("stli_readproc(page=%x,start=%x,off=%x,count=%d,eof=%x,"
2676 "data=%x\n", (int) page
, (int) start
, (int) off
, count
,
2677 (int) eof
, (int) data
);
2685 pos
+= sprintf(pos
, "%s: version %s", stli_drvtitle
,
2687 while (pos
< (page
+ MAXLINE
- 1))
2694 * We scan through for each board, panel and port. The offset is
2695 * calculated on the fly, and irrelevant ports are skipped.
2697 for (brdnr
= 0; (brdnr
< stli_nrbrds
); brdnr
++) {
2698 brdp
= stli_brds
[brdnr
];
2699 if (brdp
== (stlibrd_t
*) NULL
)
2701 if (brdp
->state
== 0)
2704 maxoff
= curoff
+ (brdp
->nrports
* MAXLINE
);
2705 if (off
>= maxoff
) {
2710 totalport
= brdnr
* STL_MAXPORTS
;
2711 for (portnr
= 0; (portnr
< brdp
->nrports
); portnr
++,
2713 portp
= brdp
->ports
[portnr
];
2714 if (portp
== (stliport_t
*) NULL
)
2716 if (off
>= (curoff
+= MAXLINE
))
2718 if ((pos
- page
+ MAXLINE
) > count
)
2720 pos
+= stli_portinfo(brdp
, portp
, totalport
, pos
);
2731 /*****************************************************************************/
2734 * Generic send command routine. This will send a message to the slave,
2735 * of the specified type with the specified argument. Must be very
2736 * careful of data that will be copied out from shared memory -
2737 * containing command results. The command completion is all done from
2738 * a poll routine that does not have user context. Therefore you cannot
2739 * copy back directly into user space, or to the kernel stack of a
2740 * process. This routine does not sleep, so can be called from anywhere.
2743 static void stli_sendcmd(stlibrd_t
*brdp
, stliport_t
*portp
, unsigned long cmd
, void *arg
, int size
, int copyback
)
2745 volatile cdkhdr_t
*hdrp
;
2746 volatile cdkctrl_t
*cp
;
2747 volatile unsigned char *bits
;
2748 unsigned long flags
;
2751 printk("stli_sendcmd(brdp=%x,portp=%x,cmd=%x,arg=%x,size=%d,"
2752 "copyback=%d)\n", (int) brdp
, (int) portp
, (int) cmd
,
2753 (int) arg
, size
, copyback
);
2759 if (test_bit(ST_CMDING
, &portp
->state
)) {
2760 printk("STALLION: command already busy, cmd=%x!\n", (int) cmd
);
2761 restore_flags(flags
);
2766 cp
= &((volatile cdkasy_t
*) EBRDGETMEMPTR(brdp
, portp
->addr
))->ctrl
;
2768 memcpy((void *) &(cp
->args
[0]), arg
, size
);
2771 portp
->argsize
= size
;
2776 hdrp
= (volatile cdkhdr_t
*) EBRDGETMEMPTR(brdp
, CDK_CDKADDR
);
2777 bits
= ((volatile unsigned char *) hdrp
) + brdp
->slaveoffset
+
2779 *bits
|= portp
->portbit
;
2780 set_bit(ST_CMDING
, &portp
->state
);
2782 restore_flags(flags
);
2785 /*****************************************************************************/
2788 * Read data from shared memory. This assumes that the shared memory
2789 * is enabled and that interrupts are off. Basically we just empty out
2790 * the shared memory buffer into the tty buffer. Must be careful to
2791 * handle the case where we fill up the tty buffer, but still have
2792 * more chars to unload.
2795 static inline void stli_read(stlibrd_t
*brdp
, stliport_t
*portp
)
2797 volatile cdkasyrq_t
*rp
;
2798 volatile char *shbuf
;
2799 struct tty_struct
*tty
;
2800 unsigned int head
, tail
, size
;
2801 unsigned int len
, stlen
;
2804 printk("stli_read(brdp=%x,portp=%d)\n", (int) brdp
, (int) portp
);
2807 if (test_bit(ST_RXSTOP
, &portp
->state
))
2810 if (tty
== (struct tty_struct
*) NULL
)
2813 rp
= &((volatile cdkasy_t
*) EBRDGETMEMPTR(brdp
, portp
->addr
))->rxq
;
2814 head
= (unsigned int) rp
->head
;
2815 if (head
!= ((unsigned int) rp
->head
))
2816 head
= (unsigned int) rp
->head
;
2817 tail
= (unsigned int) rp
->tail
;
2818 size
= portp
->rxsize
;
2823 len
= size
- (tail
- head
);
2824 stlen
= size
- tail
;
2827 len
= MIN(len
, (TTY_FLIPBUF_SIZE
- tty
->flip
.count
));
2828 shbuf
= (volatile char *) EBRDGETMEMPTR(brdp
, portp
->rxoffset
);
2831 stlen
= MIN(len
, stlen
);
2832 memcpy(tty
->flip
.char_buf_ptr
, (char *) (shbuf
+ tail
), stlen
);
2833 memset(tty
->flip
.flag_buf_ptr
, 0, stlen
);
2834 tty
->flip
.char_buf_ptr
+= stlen
;
2835 tty
->flip
.flag_buf_ptr
+= stlen
;
2836 tty
->flip
.count
+= stlen
;
2845 rp
= &((volatile cdkasy_t
*) EBRDGETMEMPTR(brdp
, portp
->addr
))->rxq
;
2849 set_bit(ST_RXING
, &portp
->state
);
2851 tty_schedule_flip(tty
);
2854 /*****************************************************************************/
2857 * Set up and carry out any delayed commands. There is only a small set
2858 * of slave commands that can be done "off-level". So it is not too
2859 * difficult to deal with them here.
2862 static inline void stli_dodelaycmd(stliport_t
*portp
, volatile cdkctrl_t
*cp
)
2866 if (test_bit(ST_DOSIGS
, &portp
->state
)) {
2867 if (test_bit(ST_DOFLUSHTX
, &portp
->state
) &&
2868 test_bit(ST_DOFLUSHRX
, &portp
->state
))
2869 cmd
= A_SETSIGNALSF
;
2870 else if (test_bit(ST_DOFLUSHTX
, &portp
->state
))
2871 cmd
= A_SETSIGNALSFTX
;
2872 else if (test_bit(ST_DOFLUSHRX
, &portp
->state
))
2873 cmd
= A_SETSIGNALSFRX
;
2876 clear_bit(ST_DOFLUSHTX
, &portp
->state
);
2877 clear_bit(ST_DOFLUSHRX
, &portp
->state
);
2878 clear_bit(ST_DOSIGS
, &portp
->state
);
2879 memcpy((void *) &(cp
->args
[0]), (void *) &portp
->asig
,
2883 set_bit(ST_CMDING
, &portp
->state
);
2884 } else if (test_bit(ST_DOFLUSHTX
, &portp
->state
) ||
2885 test_bit(ST_DOFLUSHRX
, &portp
->state
)) {
2886 cmd
= ((test_bit(ST_DOFLUSHTX
, &portp
->state
)) ? FLUSHTX
: 0);
2887 cmd
|= ((test_bit(ST_DOFLUSHRX
, &portp
->state
)) ? FLUSHRX
: 0);
2888 clear_bit(ST_DOFLUSHTX
, &portp
->state
);
2889 clear_bit(ST_DOFLUSHRX
, &portp
->state
);
2890 memcpy((void *) &(cp
->args
[0]), (void *) &cmd
, sizeof(int));
2893 set_bit(ST_CMDING
, &portp
->state
);
2897 /*****************************************************************************/
2900 * Host command service checking. This handles commands or messages
2901 * coming from the slave to the host. Must have board shared memory
2902 * enabled and interrupts off when called. Notice that by servicing the
2903 * read data last we don't need to change the shared memory pointer
2904 * during processing (which is a slow IO operation).
2905 * Return value indicates if this port is still awaiting actions from
2906 * the slave (like open, command, or even TX data being sent). If 0
2907 * then port is still busy, otherwise no longer busy.
2910 static inline int stli_hostcmd(stlibrd_t
*brdp
, stliport_t
*portp
)
2912 volatile cdkasy_t
*ap
;
2913 volatile cdkctrl_t
*cp
;
2914 struct tty_struct
*tty
;
2916 unsigned long oldsigs
;
2920 printk("stli_hostcmd(brdp=%x,channr=%d)\n", (int) brdp
, channr
);
2923 ap
= (volatile cdkasy_t
*) EBRDGETMEMPTR(brdp
, portp
->addr
);
2927 * Check if we are waiting for an open completion message.
2929 if (test_bit(ST_OPENING
, &portp
->state
)) {
2930 rc
= (int) cp
->openarg
;
2931 if ((cp
->open
== 0) && (rc
!= 0)) {
2936 clear_bit(ST_OPENING
, &portp
->state
);
2937 wake_up_interruptible(&portp
->raw_wait
);
2942 * Check if we are waiting for a close completion message.
2944 if (test_bit(ST_CLOSING
, &portp
->state
)) {
2945 rc
= (int) cp
->closearg
;
2946 if ((cp
->close
== 0) && (rc
!= 0)) {
2951 clear_bit(ST_CLOSING
, &portp
->state
);
2952 wake_up_interruptible(&portp
->raw_wait
);
2957 * Check if we are waiting for a command completion message. We may
2958 * need to copy out the command results associated with this command.
2960 if (test_bit(ST_CMDING
, &portp
->state
)) {
2962 if ((cp
->cmd
== 0) && (rc
!= 0)) {
2965 if (portp
->argp
!= (void *) NULL
) {
2966 memcpy(portp
->argp
, (void *) &(cp
->args
[0]),
2968 portp
->argp
= (void *) NULL
;
2972 clear_bit(ST_CMDING
, &portp
->state
);
2973 stli_dodelaycmd(portp
, cp
);
2974 wake_up_interruptible(&portp
->raw_wait
);
2979 * Check for any notification messages ready. This includes lots of
2980 * different types of events - RX chars ready, RX break received,
2981 * TX data low or empty in the slave, modem signals changed state.
2990 if (nt
.signal
& SG_DCD
) {
2991 oldsigs
= portp
->sigs
;
2992 portp
->sigs
= stli_mktiocm(nt
.sigvalue
);
2993 clear_bit(ST_GETSIGS
, &portp
->state
);
2994 if ((portp
->sigs
& TIOCM_CD
) &&
2995 ((oldsigs
& TIOCM_CD
) == 0))
2996 wake_up_interruptible(&portp
->open_wait
);
2997 if ((oldsigs
& TIOCM_CD
) &&
2998 ((portp
->sigs
& TIOCM_CD
) == 0)) {
2999 if (portp
->flags
& ASYNC_CHECK_CD
) {
3000 if (! ((portp
->flags
& ASYNC_CALLOUT_ACTIVE
) &&
3001 (portp
->flags
& ASYNC_CALLOUT_NOHUP
))) {
3002 if (tty
!= (struct tty_struct
*) NULL
)
3003 queue_task(&portp
->tqhangup
, &tq_scheduler
);
3009 if (nt
.data
& DT_TXEMPTY
)
3010 clear_bit(ST_TXBUSY
, &portp
->state
);
3011 if (nt
.data
& (DT_TXEMPTY
| DT_TXLOW
)) {
3012 if (tty
!= (struct tty_struct
*) NULL
) {
3013 if ((tty
->flags
& (1 << TTY_DO_WRITE_WAKEUP
)) &&
3014 tty
->ldisc
.write_wakeup
) {
3015 (tty
->ldisc
.write_wakeup
)(tty
);
3018 wake_up_interruptible(&tty
->write_wait
);
3022 if ((nt
.data
& DT_RXBREAK
) && (portp
->rxmarkmsk
& BRKINT
)) {
3023 if (tty
!= (struct tty_struct
*) NULL
) {
3024 if (tty
->flip
.count
< TTY_FLIPBUF_SIZE
) {
3026 *tty
->flip
.flag_buf_ptr
++ = TTY_BREAK
;
3027 *tty
->flip
.char_buf_ptr
++ = 0;
3028 if (portp
->flags
& ASYNC_SAK
) {
3032 tty_schedule_flip(tty
);
3037 if (nt
.data
& DT_RXBUSY
) {
3039 stli_read(brdp
, portp
);
3044 * It might seem odd that we are checking for more RX chars here.
3045 * But, we need to handle the case where the tty buffer was previously
3046 * filled, but we had more characters to pass up. The slave will not
3047 * send any more RX notify messages until the RX buffer has been emptied.
3048 * But it will leave the service bits on (since the buffer is not empty).
3049 * So from here we can try to process more RX chars.
3051 if ((!donerx
) && test_bit(ST_RXING
, &portp
->state
)) {
3052 clear_bit(ST_RXING
, &portp
->state
);
3053 stli_read(brdp
, portp
);
3056 return((test_bit(ST_OPENING
, &portp
->state
) ||
3057 test_bit(ST_CLOSING
, &portp
->state
) ||
3058 test_bit(ST_CMDING
, &portp
->state
) ||
3059 test_bit(ST_TXBUSY
, &portp
->state
) ||
3060 test_bit(ST_RXING
, &portp
->state
)) ? 0 : 1);
3063 /*****************************************************************************/
3066 * Service all ports on a particular board. Assumes that the boards
3067 * shared memory is enabled, and that the page pointer is pointed
3068 * at the cdk header structure.
3071 static inline void stli_brdpoll(stlibrd_t
*brdp
, volatile cdkhdr_t
*hdrp
)
3074 unsigned char hostbits
[(STL_MAXCHANS
/ 8) + 1];
3075 unsigned char slavebits
[(STL_MAXCHANS
/ 8) + 1];
3076 unsigned char *slavep
;
3077 int bitpos
, bitat
, bitsize
;
3078 int channr
, nrdevs
, slavebitchange
;
3080 bitsize
= brdp
->bitsize
;
3081 nrdevs
= brdp
->nrdevs
;
3084 * Check if slave wants any service. Basically we try to do as
3085 * little work as possible here. There are 2 levels of service
3086 * bits. So if there is nothing to do we bail early. We check
3087 * 8 service bits at a time in the inner loop, so we can bypass
3088 * the lot if none of them want service.
3090 memcpy(&hostbits
[0], (((unsigned char *) hdrp
) + brdp
->hostoffset
),
3093 memset(&slavebits
[0], 0, bitsize
);
3096 for (bitpos
= 0; (bitpos
< bitsize
); bitpos
++) {
3097 if (hostbits
[bitpos
] == 0)
3099 channr
= bitpos
* 8;
3100 for (bitat
= 0x1; (channr
< nrdevs
); channr
++, bitat
<<= 1) {
3101 if (hostbits
[bitpos
] & bitat
) {
3102 portp
= brdp
->ports
[(channr
- 1)];
3103 if (stli_hostcmd(brdp
, portp
)) {
3105 slavebits
[bitpos
] |= bitat
;
3112 * If any of the ports are no longer busy then update them in the
3113 * slave request bits. We need to do this after, since a host port
3114 * service may initiate more slave requests.
3116 if (slavebitchange
) {
3117 hdrp
= (volatile cdkhdr_t
*) EBRDGETMEMPTR(brdp
, CDK_CDKADDR
);
3118 slavep
= ((unsigned char *) hdrp
) + brdp
->slaveoffset
;
3119 for (bitpos
= 0; (bitpos
< bitsize
); bitpos
++) {
3120 if (slavebits
[bitpos
])
3121 slavep
[bitpos
] &= ~slavebits
[bitpos
];
3126 /*****************************************************************************/
3129 * Driver poll routine. This routine polls the boards in use and passes
3130 * messages back up to host when necessary. This is actually very
3131 * CPU efficient, since we will always have the kernel poll clock, it
3132 * adds only a few cycles when idle (since board service can be
3133 * determined very easily), but when loaded generates no interrupts
3134 * (with their expensive associated context change).
3137 static void stli_poll(unsigned long arg
)
3139 volatile cdkhdr_t
*hdrp
;
3143 stli_timerlist
.expires
= STLI_TIMEOUT
;
3144 add_timer(&stli_timerlist
);
3147 * Check each board and do any servicing required.
3149 for (brdnr
= 0; (brdnr
< stli_nrbrds
); brdnr
++) {
3150 brdp
= stli_brds
[brdnr
];
3151 if (brdp
== (stlibrd_t
*) NULL
)
3153 if ((brdp
->state
& BST_STARTED
) == 0)
3157 hdrp
= (volatile cdkhdr_t
*) EBRDGETMEMPTR(brdp
, CDK_CDKADDR
);
3159 stli_brdpoll(brdp
, hdrp
);
3164 /*****************************************************************************/
3167 * Translate the termios settings into the port setting structure of
3171 static void stli_mkasyport(stliport_t
*portp
, asyport_t
*pp
, struct termios
*tiosp
)
3174 printk("stli_mkasyport(portp=%x,pp=%x,tiosp=%d)\n",
3175 (int) portp
, (int) pp
, (int) tiosp
);
3178 memset(pp
, 0, sizeof(asyport_t
));
3181 * Start of by setting the baud, char size, parity and stop bit info.
3183 pp
->baudout
= tiosp
->c_cflag
& CBAUD
;
3184 if (pp
->baudout
& CBAUDEX
) {
3185 pp
->baudout
&= ~CBAUDEX
;
3186 if ((pp
->baudout
< 1) || (pp
->baudout
> 4))
3187 tiosp
->c_cflag
&= ~CBAUDEX
;
3191 pp
->baudout
= stli_baudrates
[pp
->baudout
];
3192 if ((tiosp
->c_cflag
& CBAUD
) == B38400
) {
3193 if ((portp
->flags
& ASYNC_SPD_MASK
) == ASYNC_SPD_HI
)
3194 pp
->baudout
= 57600;
3195 else if ((portp
->flags
& ASYNC_SPD_MASK
) == ASYNC_SPD_VHI
)
3196 pp
->baudout
= 115200;
3197 else if ((portp
->flags
& ASYNC_SPD_MASK
) == ASYNC_SPD_SHI
)
3198 pp
->baudout
= 230400;
3199 else if ((portp
->flags
& ASYNC_SPD_MASK
) == ASYNC_SPD_WARP
)
3200 pp
->baudout
= 460800;
3201 else if ((portp
->flags
& ASYNC_SPD_MASK
) == ASYNC_SPD_CUST
)
3202 pp
->baudout
= (portp
->baud_base
/ portp
->custom_divisor
);
3204 if (pp
->baudout
> STL_MAXBAUD
)
3205 pp
->baudout
= STL_MAXBAUD
;
3206 pp
->baudin
= pp
->baudout
;
3208 switch (tiosp
->c_cflag
& CSIZE
) {
3223 if (tiosp
->c_cflag
& CSTOPB
)
3224 pp
->stopbs
= PT_STOP2
;
3226 pp
->stopbs
= PT_STOP1
;
3228 if (tiosp
->c_cflag
& PARENB
) {
3229 if (tiosp
->c_cflag
& PARODD
)
3230 pp
->parity
= PT_ODDPARITY
;
3232 pp
->parity
= PT_EVENPARITY
;
3234 pp
->parity
= PT_NOPARITY
;
3238 * Set up any flow control options enabled.
3240 if (tiosp
->c_iflag
& IXON
) {
3242 if (tiosp
->c_iflag
& IXANY
)
3243 pp
->flow
|= F_IXANY
;
3245 if (tiosp
->c_cflag
& CRTSCTS
)
3246 pp
->flow
|= (F_RTSFLOW
| F_CTSFLOW
);
3248 pp
->startin
= tiosp
->c_cc
[VSTART
];
3249 pp
->stopin
= tiosp
->c_cc
[VSTOP
];
3250 pp
->startout
= tiosp
->c_cc
[VSTART
];
3251 pp
->stopout
= tiosp
->c_cc
[VSTOP
];
3254 * Set up the RX char marking mask with those RX error types we must
3255 * catch. We can get the slave to help us out a little here, it will
3256 * ignore parity errors and breaks for us, and mark parity errors in
3259 if (tiosp
->c_iflag
& IGNPAR
)
3260 pp
->iflag
|= FI_IGNRXERRS
;
3261 if (tiosp
->c_iflag
& IGNBRK
)
3262 pp
->iflag
|= FI_IGNBREAK
;
3264 portp
->rxmarkmsk
= 0;
3265 if (tiosp
->c_iflag
& (INPCK
| PARMRK
))
3266 pp
->iflag
|= FI_1MARKRXERRS
;
3267 if (tiosp
->c_iflag
& BRKINT
)
3268 portp
->rxmarkmsk
|= BRKINT
;
3271 * Set up clocal processing as required.
3273 if (tiosp
->c_cflag
& CLOCAL
)
3274 portp
->flags
&= ~ASYNC_CHECK_CD
;
3276 portp
->flags
|= ASYNC_CHECK_CD
;
3279 * Transfer any persistent flags into the asyport structure.
3281 pp
->pflag
= (portp
->pflag
& 0xffff);
3282 pp
->vmin
= (portp
->pflag
& P_RXIMIN
) ? 1 : 0;
3283 pp
->vtime
= (portp
->pflag
& P_RXITIME
) ? 1 : 0;
3284 pp
->cc
[1] = (portp
->pflag
& P_RXTHOLD
) ? 1 : 0;
3287 /*****************************************************************************/
3290 * Construct a slave signals structure for setting the DTR and RTS
3291 * signals as specified.
3294 static void stli_mkasysigs(asysigs_t
*sp
, int dtr
, int rts
)
3297 printk("stli_mkasysigs(sp=%x,dtr=%d,rts=%d)\n", (int) sp
, dtr
, rts
);
3300 memset(sp
, 0, sizeof(asysigs_t
));
3302 sp
->signal
|= SG_DTR
;
3303 sp
->sigvalue
|= ((dtr
> 0) ? SG_DTR
: 0);
3306 sp
->signal
|= SG_RTS
;
3307 sp
->sigvalue
|= ((rts
> 0) ? SG_RTS
: 0);
3311 /*****************************************************************************/
3314 * Convert the signals returned from the slave into a local TIOCM type
3315 * signals value. We keep them locally in TIOCM format.
3318 static long stli_mktiocm(unsigned long sigvalue
)
3323 printk("stli_mktiocm(sigvalue=%x)\n", (int) sigvalue
);
3327 tiocm
|= ((sigvalue
& SG_DCD
) ? TIOCM_CD
: 0);
3328 tiocm
|= ((sigvalue
& SG_CTS
) ? TIOCM_CTS
: 0);
3329 tiocm
|= ((sigvalue
& SG_RI
) ? TIOCM_RI
: 0);
3330 tiocm
|= ((sigvalue
& SG_DSR
) ? TIOCM_DSR
: 0);
3331 tiocm
|= ((sigvalue
& SG_DTR
) ? TIOCM_DTR
: 0);
3332 tiocm
|= ((sigvalue
& SG_RTS
) ? TIOCM_RTS
: 0);
3336 /*****************************************************************************/
3339 * All panels and ports actually attached have been worked out. All
3340 * we need to do here is set up the appropriate per port data structures.
3343 static inline int stli_initports(stlibrd_t
*brdp
)
3346 int i
, panelnr
, panelport
;
3349 printk("stli_initports(brdp=%x)\n", (int) brdp
);
3352 for (i
= 0, panelnr
= 0, panelport
= 0; (i
< brdp
->nrports
); i
++) {
3353 portp
= (stliport_t
*) stli_memalloc(sizeof(stliport_t
));
3354 if (portp
== (stliport_t
*) NULL
) {
3355 printk("STALLION: failed to allocate port structure\n");
3359 memset(portp
, 0, sizeof(stliport_t
));
3360 portp
->magic
= STLI_PORTMAGIC
;
3362 portp
->brdnr
= brdp
->brdnr
;
3363 portp
->panelnr
= panelnr
;
3364 portp
->baud_base
= STL_BAUDBASE
;
3365 portp
->close_delay
= STL_CLOSEDELAY
;
3366 portp
->closing_wait
= 30 * HZ
;
3367 portp
->tqhangup
.routine
= stli_dohangup
;
3368 portp
->tqhangup
.data
= portp
;
3369 init_waitqueue_head(&portp
->open_wait
);
3370 init_waitqueue_head(&portp
->close_wait
);
3371 init_waitqueue_head(&portp
->raw_wait
);
3372 portp
->normaltermios
= stli_deftermios
;
3373 portp
->callouttermios
= stli_deftermios
;
3375 if (panelport
>= brdp
->panels
[panelnr
]) {
3379 brdp
->ports
[i
] = portp
;
3385 /*****************************************************************************/
3388 * All the following routines are board specific hardware operations.
3391 static void stli_ecpinit(stlibrd_t
*brdp
)
3393 unsigned long memconf
;
3396 printk("stli_ecpinit(brdp=%d)\n", (int) brdp
);
3399 outb(ECP_ATSTOP
, (brdp
->iobase
+ ECP_ATCONFR
));
3401 outb(ECP_ATDISABLE
, (brdp
->iobase
+ ECP_ATCONFR
));
3404 memconf
= (brdp
->memaddr
& ECP_ATADDRMASK
) >> ECP_ATADDRSHFT
;
3405 outb(memconf
, (brdp
->iobase
+ ECP_ATMEMAR
));
3408 /*****************************************************************************/
3410 static void stli_ecpenable(stlibrd_t
*brdp
)
3413 printk("stli_ecpenable(brdp=%x)\n", (int) brdp
);
3415 outb(ECP_ATENABLE
, (brdp
->iobase
+ ECP_ATCONFR
));
3418 /*****************************************************************************/
3420 static void stli_ecpdisable(stlibrd_t
*brdp
)
3423 printk("stli_ecpdisable(brdp=%x)\n", (int) brdp
);
3425 outb(ECP_ATDISABLE
, (brdp
->iobase
+ ECP_ATCONFR
));
3428 /*****************************************************************************/
3430 static char *stli_ecpgetmemptr(stlibrd_t
*brdp
, unsigned long offset
, int line
)
3436 printk("stli_ecpgetmemptr(brdp=%x,offset=%x)\n", (int) brdp
,
3440 if (offset
> brdp
->memsize
) {
3441 printk("STALLION: shared memory pointer=%x out of range at "
3442 "line=%d(%d), brd=%d\n", (int) offset
, line
,
3443 __LINE__
, brdp
->brdnr
);
3447 ptr
= brdp
->membase
+ (offset
% ECP_ATPAGESIZE
);
3448 val
= (unsigned char) (offset
/ ECP_ATPAGESIZE
);
3450 outb(val
, (brdp
->iobase
+ ECP_ATMEMPR
));
3454 /*****************************************************************************/
3456 static void stli_ecpreset(stlibrd_t
*brdp
)
3459 printk("stli_ecpreset(brdp=%x)\n", (int) brdp
);
3462 outb(ECP_ATSTOP
, (brdp
->iobase
+ ECP_ATCONFR
));
3464 outb(ECP_ATDISABLE
, (brdp
->iobase
+ ECP_ATCONFR
));
3468 /*****************************************************************************/
3470 static void stli_ecpintr(stlibrd_t
*brdp
)
3473 printk("stli_ecpintr(brdp=%x)\n", (int) brdp
);
3475 outb(0x1, brdp
->iobase
);
3478 /*****************************************************************************/
3481 * The following set of functions act on ECP EISA boards.
3484 static void stli_ecpeiinit(stlibrd_t
*brdp
)
3486 unsigned long memconf
;
3489 printk("stli_ecpeiinit(brdp=%x)\n", (int) brdp
);
3492 outb(0x1, (brdp
->iobase
+ ECP_EIBRDENAB
));
3493 outb(ECP_EISTOP
, (brdp
->iobase
+ ECP_EICONFR
));
3495 outb(ECP_EIDISABLE
, (brdp
->iobase
+ ECP_EICONFR
));
3498 memconf
= (brdp
->memaddr
& ECP_EIADDRMASKL
) >> ECP_EIADDRSHFTL
;
3499 outb(memconf
, (brdp
->iobase
+ ECP_EIMEMARL
));
3500 memconf
= (brdp
->memaddr
& ECP_EIADDRMASKH
) >> ECP_EIADDRSHFTH
;
3501 outb(memconf
, (brdp
->iobase
+ ECP_EIMEMARH
));
3504 /*****************************************************************************/
3506 static void stli_ecpeienable(stlibrd_t
*brdp
)
3508 outb(ECP_EIENABLE
, (brdp
->iobase
+ ECP_EICONFR
));
3511 /*****************************************************************************/
3513 static void stli_ecpeidisable(stlibrd_t
*brdp
)
3515 outb(ECP_EIDISABLE
, (brdp
->iobase
+ ECP_EICONFR
));
3518 /*****************************************************************************/
3520 static char *stli_ecpeigetmemptr(stlibrd_t
*brdp
, unsigned long offset
, int line
)
3526 printk("stli_ecpeigetmemptr(brdp=%x,offset=%x,line=%d)\n",
3527 (int) brdp
, (int) offset
, line
);
3530 if (offset
> brdp
->memsize
) {
3531 printk("STALLION: shared memory pointer=%x out of range at "
3532 "line=%d(%d), brd=%d\n", (int) offset
, line
,
3533 __LINE__
, brdp
->brdnr
);
3537 ptr
= brdp
->membase
+ (offset
% ECP_EIPAGESIZE
);
3538 if (offset
< ECP_EIPAGESIZE
)
3541 val
= ECP_EIENABLE
| 0x40;
3543 outb(val
, (brdp
->iobase
+ ECP_EICONFR
));
3547 /*****************************************************************************/
3549 static void stli_ecpeireset(stlibrd_t
*brdp
)
3551 outb(ECP_EISTOP
, (brdp
->iobase
+ ECP_EICONFR
));
3553 outb(ECP_EIDISABLE
, (brdp
->iobase
+ ECP_EICONFR
));
3557 /*****************************************************************************/
3560 * The following set of functions act on ECP MCA boards.
3563 static void stli_ecpmcenable(stlibrd_t
*brdp
)
3565 outb(ECP_MCENABLE
, (brdp
->iobase
+ ECP_MCCONFR
));
3568 /*****************************************************************************/
3570 static void stli_ecpmcdisable(stlibrd_t
*brdp
)
3572 outb(ECP_MCDISABLE
, (brdp
->iobase
+ ECP_MCCONFR
));
3575 /*****************************************************************************/
3577 static char *stli_ecpmcgetmemptr(stlibrd_t
*brdp
, unsigned long offset
, int line
)
3582 if (offset
> brdp
->memsize
) {
3583 printk("STALLION: shared memory pointer=%x out of range at "
3584 "line=%d(%d), brd=%d\n", (int) offset
, line
,
3585 __LINE__
, brdp
->brdnr
);
3589 ptr
= brdp
->membase
+ (offset
% ECP_MCPAGESIZE
);
3590 val
= ((unsigned char) (offset
/ ECP_MCPAGESIZE
)) | ECP_MCENABLE
;
3592 outb(val
, (brdp
->iobase
+ ECP_MCCONFR
));
3596 /*****************************************************************************/
3598 static void stli_ecpmcreset(stlibrd_t
*brdp
)
3600 outb(ECP_MCSTOP
, (brdp
->iobase
+ ECP_MCCONFR
));
3602 outb(ECP_MCDISABLE
, (brdp
->iobase
+ ECP_MCCONFR
));
3606 /*****************************************************************************/
3609 * The following set of functions act on ECP PCI boards.
3612 static void stli_ecppciinit(stlibrd_t
*brdp
)
3615 printk("stli_ecppciinit(brdp=%x)\n", (int) brdp
);
3618 outb(ECP_PCISTOP
, (brdp
->iobase
+ ECP_PCICONFR
));
3620 outb(0, (brdp
->iobase
+ ECP_PCICONFR
));
3624 /*****************************************************************************/
3626 static char *stli_ecppcigetmemptr(stlibrd_t
*brdp
, unsigned long offset
, int line
)
3632 printk("stli_ecppcigetmemptr(brdp=%x,offset=%x,line=%d)\n",
3633 (int) brdp
, (int) offset
, line
);
3636 if (offset
> brdp
->memsize
) {
3637 printk("STALLION: shared memory pointer=%x out of range at "
3638 "line=%d(%d), board=%d\n", (int) offset
, line
,
3639 __LINE__
, brdp
->brdnr
);
3643 ptr
= brdp
->membase
+ (offset
% ECP_PCIPAGESIZE
);
3644 val
= (offset
/ ECP_PCIPAGESIZE
) << 1;
3646 outb(val
, (brdp
->iobase
+ ECP_PCICONFR
));
3650 /*****************************************************************************/
3652 static void stli_ecppcireset(stlibrd_t
*brdp
)
3654 outb(ECP_PCISTOP
, (brdp
->iobase
+ ECP_PCICONFR
));
3656 outb(0, (brdp
->iobase
+ ECP_PCICONFR
));
3660 /*****************************************************************************/
3663 * The following routines act on ONboards.
3666 static void stli_onbinit(stlibrd_t
*brdp
)
3668 unsigned long memconf
;
3671 printk("stli_onbinit(brdp=%d)\n", (int) brdp
);
3674 outb(ONB_ATSTOP
, (brdp
->iobase
+ ONB_ATCONFR
));
3676 outb(ONB_ATDISABLE
, (brdp
->iobase
+ ONB_ATCONFR
));
3679 memconf
= (brdp
->memaddr
& ONB_ATADDRMASK
) >> ONB_ATADDRSHFT
;
3680 outb(memconf
, (brdp
->iobase
+ ONB_ATMEMAR
));
3681 outb(0x1, brdp
->iobase
);
3685 /*****************************************************************************/
3687 static void stli_onbenable(stlibrd_t
*brdp
)
3690 printk("stli_onbenable(brdp=%x)\n", (int) brdp
);
3692 outb((brdp
->enabval
| ONB_ATENABLE
), (brdp
->iobase
+ ONB_ATCONFR
));
3695 /*****************************************************************************/
3697 static void stli_onbdisable(stlibrd_t
*brdp
)
3700 printk("stli_onbdisable(brdp=%x)\n", (int) brdp
);
3702 outb((brdp
->enabval
| ONB_ATDISABLE
), (brdp
->iobase
+ ONB_ATCONFR
));
3705 /*****************************************************************************/
3707 static char *stli_onbgetmemptr(stlibrd_t
*brdp
, unsigned long offset
, int line
)
3712 printk("stli_onbgetmemptr(brdp=%x,offset=%x)\n", (int) brdp
,
3716 if (offset
> brdp
->memsize
) {
3717 printk("STALLION: shared memory pointer=%x out of range at "
3718 "line=%d(%d), brd=%d\n", (int) offset
, line
,
3719 __LINE__
, brdp
->brdnr
);
3722 ptr
= brdp
->membase
+ (offset
% ONB_ATPAGESIZE
);
3727 /*****************************************************************************/
3729 static void stli_onbreset(stlibrd_t
*brdp
)
3733 printk("stli_onbreset(brdp=%x)\n", (int) brdp
);
3736 outb(ONB_ATSTOP
, (brdp
->iobase
+ ONB_ATCONFR
));
3738 outb(ONB_ATDISABLE
, (brdp
->iobase
+ ONB_ATCONFR
));
3742 /*****************************************************************************/
3745 * The following routines act on ONboard EISA.
3748 static void stli_onbeinit(stlibrd_t
*brdp
)
3750 unsigned long memconf
;
3753 printk("stli_onbeinit(brdp=%d)\n", (int) brdp
);
3756 outb(0x1, (brdp
->iobase
+ ONB_EIBRDENAB
));
3757 outb(ONB_EISTOP
, (brdp
->iobase
+ ONB_EICONFR
));
3759 outb(ONB_EIDISABLE
, (brdp
->iobase
+ ONB_EICONFR
));
3762 memconf
= (brdp
->memaddr
& ONB_EIADDRMASKL
) >> ONB_EIADDRSHFTL
;
3763 outb(memconf
, (brdp
->iobase
+ ONB_EIMEMARL
));
3764 memconf
= (brdp
->memaddr
& ONB_EIADDRMASKH
) >> ONB_EIADDRSHFTH
;
3765 outb(memconf
, (brdp
->iobase
+ ONB_EIMEMARH
));
3766 outb(0x1, brdp
->iobase
);
3770 /*****************************************************************************/
3772 static void stli_onbeenable(stlibrd_t
*brdp
)
3775 printk("stli_onbeenable(brdp=%x)\n", (int) brdp
);
3777 outb(ONB_EIENABLE
, (brdp
->iobase
+ ONB_EICONFR
));
3780 /*****************************************************************************/
3782 static void stli_onbedisable(stlibrd_t
*brdp
)
3785 printk("stli_onbedisable(brdp=%x)\n", (int) brdp
);
3787 outb(ONB_EIDISABLE
, (brdp
->iobase
+ ONB_EICONFR
));
3790 /*****************************************************************************/
3792 static char *stli_onbegetmemptr(stlibrd_t
*brdp
, unsigned long offset
, int line
)
3798 printk("stli_onbegetmemptr(brdp=%x,offset=%x,line=%d)\n",
3799 (int) brdp
, (int) offset
, line
);
3802 if (offset
> brdp
->memsize
) {
3803 printk("STALLION: shared memory pointer=%x out of range at "
3804 "line=%d(%d), brd=%d\n", (int) offset
, line
,
3805 __LINE__
, brdp
->brdnr
);
3809 ptr
= brdp
->membase
+ (offset
% ONB_EIPAGESIZE
);
3810 if (offset
< ONB_EIPAGESIZE
)
3813 val
= ONB_EIENABLE
| 0x40;
3815 outb(val
, (brdp
->iobase
+ ONB_EICONFR
));
3819 /*****************************************************************************/
3821 static void stli_onbereset(stlibrd_t
*brdp
)
3825 printk("stli_onbereset(brdp=%x)\n", (int) brdp
);
3828 outb(ONB_EISTOP
, (brdp
->iobase
+ ONB_EICONFR
));
3830 outb(ONB_EIDISABLE
, (brdp
->iobase
+ ONB_EICONFR
));
3834 /*****************************************************************************/
3837 * The following routines act on Brumby boards.
3840 static void stli_bbyinit(stlibrd_t
*brdp
)
3844 printk("stli_bbyinit(brdp=%d)\n", (int) brdp
);
3847 outb(BBY_ATSTOP
, (brdp
->iobase
+ BBY_ATCONFR
));
3849 outb(0, (brdp
->iobase
+ BBY_ATCONFR
));
3851 outb(0x1, brdp
->iobase
);
3855 /*****************************************************************************/
3857 static char *stli_bbygetmemptr(stlibrd_t
*brdp
, unsigned long offset
, int line
)
3863 printk("stli_bbygetmemptr(brdp=%x,offset=%x)\n", (int) brdp
,
3867 if (offset
> brdp
->memsize
) {
3868 printk("STALLION: shared memory pointer=%x out of range at "
3869 "line=%d(%d), brd=%d\n", (int) offset
, line
,
3870 __LINE__
, brdp
->brdnr
);
3874 ptr
= brdp
->membase
+ (offset
% BBY_PAGESIZE
);
3875 val
= (unsigned char) (offset
/ BBY_PAGESIZE
);
3877 outb(val
, (brdp
->iobase
+ BBY_ATCONFR
));
3881 /*****************************************************************************/
3883 static void stli_bbyreset(stlibrd_t
*brdp
)
3887 printk("stli_bbyreset(brdp=%x)\n", (int) brdp
);
3890 outb(BBY_ATSTOP
, (brdp
->iobase
+ BBY_ATCONFR
));
3892 outb(0, (brdp
->iobase
+ BBY_ATCONFR
));
3896 /*****************************************************************************/
3899 * The following routines act on original old Stallion boards.
3902 static void stli_stalinit(stlibrd_t
*brdp
)
3906 printk("stli_stalinit(brdp=%d)\n", (int) brdp
);
3909 outb(0x1, brdp
->iobase
);
3913 /*****************************************************************************/
3915 static char *stli_stalgetmemptr(stlibrd_t
*brdp
, unsigned long offset
, int line
)
3920 printk("stli_stalgetmemptr(brdp=%x,offset=%x)\n", (int) brdp
,
3924 if (offset
> brdp
->memsize
) {
3925 printk("STALLION: shared memory pointer=%x out of range at "
3926 "line=%d(%d), brd=%d\n", (int) offset
, line
,
3927 __LINE__
, brdp
->brdnr
);
3930 ptr
= brdp
->membase
+ (offset
% STAL_PAGESIZE
);
3935 /*****************************************************************************/
3937 static void stli_stalreset(stlibrd_t
*brdp
)
3939 volatile unsigned long *vecp
;
3942 printk("stli_stalreset(brdp=%x)\n", (int) brdp
);
3945 vecp
= (volatile unsigned long *) (brdp
->membase
+ 0x30);
3947 outb(0, brdp
->iobase
);
3951 /*****************************************************************************/
3954 * Try to find an ECP board and initialize it. This handles only ECP
3958 static inline int stli_initecp(stlibrd_t
*brdp
)
3962 unsigned int status
, nxtid
;
3964 int panelnr
, nrports
;
3967 printk("stli_initecp(brdp=%x)\n", (int) brdp
);
3971 * Do a basic sanity check on the IO and memory addresses.
3973 if ((brdp
->iobase
== 0) || (brdp
->memaddr
== 0))
3976 brdp
->iosize
= ECP_IOSIZE
;
3977 if (check_region(brdp
->iobase
, brdp
->iosize
))
3978 printk("STALLION: Warning, board %d I/O address %x conflicts "
3979 "with another device\n", brdp
->brdnr
, brdp
->iobase
);
3982 * Based on the specific board type setup the common vars to access
3983 * and enable shared memory. Set all board specific information now
3986 switch (brdp
->brdtype
) {
3988 brdp
->membase
= (void *) brdp
->memaddr
;
3989 brdp
->memsize
= ECP_MEMSIZE
;
3990 brdp
->pagesize
= ECP_ATPAGESIZE
;
3991 brdp
->init
= stli_ecpinit
;
3992 brdp
->enable
= stli_ecpenable
;
3993 brdp
->reenable
= stli_ecpenable
;
3994 brdp
->disable
= stli_ecpdisable
;
3995 brdp
->getmemptr
= stli_ecpgetmemptr
;
3996 brdp
->intr
= stli_ecpintr
;
3997 brdp
->reset
= stli_ecpreset
;
3998 name
= "serial(EC8/64)";
4002 brdp
->membase
= (void *) brdp
->memaddr
;
4003 brdp
->memsize
= ECP_MEMSIZE
;
4004 brdp
->pagesize
= ECP_EIPAGESIZE
;
4005 brdp
->init
= stli_ecpeiinit
;
4006 brdp
->enable
= stli_ecpeienable
;
4007 brdp
->reenable
= stli_ecpeienable
;
4008 brdp
->disable
= stli_ecpeidisable
;
4009 brdp
->getmemptr
= stli_ecpeigetmemptr
;
4010 brdp
->intr
= stli_ecpintr
;
4011 brdp
->reset
= stli_ecpeireset
;
4012 name
= "serial(EC8/64-EI)";
4016 brdp
->membase
= (void *) brdp
->memaddr
;
4017 brdp
->memsize
= ECP_MEMSIZE
;
4018 brdp
->pagesize
= ECP_MCPAGESIZE
;
4020 brdp
->enable
= stli_ecpmcenable
;
4021 brdp
->reenable
= stli_ecpmcenable
;
4022 brdp
->disable
= stli_ecpmcdisable
;
4023 brdp
->getmemptr
= stli_ecpmcgetmemptr
;
4024 brdp
->intr
= stli_ecpintr
;
4025 brdp
->reset
= stli_ecpmcreset
;
4026 name
= "serial(EC8/64-MCA)";
4030 brdp
->membase
= (void *) brdp
->memaddr
;
4031 brdp
->memsize
= ECP_PCIMEMSIZE
;
4032 brdp
->pagesize
= ECP_PCIPAGESIZE
;
4033 brdp
->init
= stli_ecppciinit
;
4034 brdp
->enable
= NULL
;
4035 brdp
->reenable
= NULL
;
4036 brdp
->disable
= NULL
;
4037 brdp
->getmemptr
= stli_ecppcigetmemptr
;
4038 brdp
->intr
= stli_ecpintr
;
4039 brdp
->reset
= stli_ecppcireset
;
4040 name
= "serial(EC/RA-PCI)";
4048 * The per-board operations structure is all set up, so now let's go
4049 * and get the board operational. Firstly initialize board configuration
4050 * registers. Set the memory mapping info so we can get at the boards
4055 brdp
->membase
= ioremap(brdp
->memaddr
, brdp
->memsize
);
4056 if (brdp
->membase
== (void *) NULL
)
4060 * Now that all specific code is set up, enable the shared memory and
4061 * look for the a signature area that will tell us exactly what board
4062 * this is, and what it is connected to it.
4065 sigsp
= (cdkecpsig_t
*) EBRDGETMEMPTR(brdp
, CDK_SIGADDR
);
4066 memcpy(&sig
, sigsp
, sizeof(cdkecpsig_t
));
4070 printk("%s(%d): sig-> magic=%x rom=%x panel=%x,%x,%x,%x,%x,%x,%x,%x\n",
4071 __FILE__
, __LINE__
, (int) sig
.magic
, sig
.romver
, sig
.panelid
[0],
4072 (int) sig
.panelid
[1], (int) sig
.panelid
[2],
4073 (int) sig
.panelid
[3], (int) sig
.panelid
[4],
4074 (int) sig
.panelid
[5], (int) sig
.panelid
[6],
4075 (int) sig
.panelid
[7]);
4078 if (sig
.magic
!= ECP_MAGIC
)
4082 * Scan through the signature looking at the panels connected to the
4083 * board. Calculate the total number of ports as we go.
4085 for (panelnr
= 0, nxtid
= 0; (panelnr
< STL_MAXPANELS
); panelnr
++) {
4086 status
= sig
.panelid
[nxtid
];
4087 if ((status
& ECH_PNLIDMASK
) != nxtid
)
4090 brdp
->panelids
[panelnr
] = status
;
4091 nrports
= (status
& ECH_PNL16PORT
) ? 16 : 8;
4092 if ((nrports
== 16) && ((status
& ECH_PNLXPID
) == 0))
4094 brdp
->panels
[panelnr
] = nrports
;
4095 brdp
->nrports
+= nrports
;
4100 request_region(brdp
->iobase
, brdp
->iosize
, name
);
4101 brdp
->state
|= BST_FOUND
;
4105 /*****************************************************************************/
4108 * Try to find an ONboard, Brumby or Stallion board and initialize it.
4109 * This handles only these board types.
4112 static inline int stli_initonb(stlibrd_t
*brdp
)
4120 printk("stli_initonb(brdp=%x)\n", (int) brdp
);
4124 * Do a basic sanity check on the IO and memory addresses.
4126 if ((brdp
->iobase
== 0) || (brdp
->memaddr
== 0))
4129 brdp
->iosize
= ONB_IOSIZE
;
4130 if (check_region(brdp
->iobase
, brdp
->iosize
))
4131 printk("STALLION: Warning, board %d I/O address %x conflicts "
4132 "with another device\n", brdp
->brdnr
, brdp
->iobase
);
4135 * Based on the specific board type setup the common vars to access
4136 * and enable shared memory. Set all board specific information now
4139 switch (brdp
->brdtype
) {
4143 case BRD_ONBOARD2_32
:
4145 brdp
->membase
= (void *) brdp
->memaddr
;
4146 brdp
->memsize
= ONB_MEMSIZE
;
4147 brdp
->pagesize
= ONB_ATPAGESIZE
;
4148 brdp
->init
= stli_onbinit
;
4149 brdp
->enable
= stli_onbenable
;
4150 brdp
->reenable
= stli_onbenable
;
4151 brdp
->disable
= stli_onbdisable
;
4152 brdp
->getmemptr
= stli_onbgetmemptr
;
4153 brdp
->intr
= stli_ecpintr
;
4154 brdp
->reset
= stli_onbreset
;
4155 if (brdp
->memaddr
> 0x100000)
4156 brdp
->enabval
= ONB_MEMENABHI
;
4158 brdp
->enabval
= ONB_MEMENABLO
;
4159 name
= "serial(ONBoard)";
4163 brdp
->membase
= (void *) brdp
->memaddr
;
4164 brdp
->memsize
= ONB_EIMEMSIZE
;
4165 brdp
->pagesize
= ONB_EIPAGESIZE
;
4166 brdp
->init
= stli_onbeinit
;
4167 brdp
->enable
= stli_onbeenable
;
4168 brdp
->reenable
= stli_onbeenable
;
4169 brdp
->disable
= stli_onbedisable
;
4170 brdp
->getmemptr
= stli_onbegetmemptr
;
4171 brdp
->intr
= stli_ecpintr
;
4172 brdp
->reset
= stli_onbereset
;
4173 name
= "serial(ONBoard/E)";
4179 brdp
->membase
= (void *) brdp
->memaddr
;
4180 brdp
->memsize
= BBY_MEMSIZE
;
4181 brdp
->pagesize
= BBY_PAGESIZE
;
4182 brdp
->init
= stli_bbyinit
;
4183 brdp
->enable
= NULL
;
4184 brdp
->reenable
= NULL
;
4185 brdp
->disable
= NULL
;
4186 brdp
->getmemptr
= stli_bbygetmemptr
;
4187 brdp
->intr
= stli_ecpintr
;
4188 brdp
->reset
= stli_bbyreset
;
4189 name
= "serial(Brumby)";
4193 brdp
->membase
= (void *) brdp
->memaddr
;
4194 brdp
->memsize
= STAL_MEMSIZE
;
4195 brdp
->pagesize
= STAL_PAGESIZE
;
4196 brdp
->init
= stli_stalinit
;
4197 brdp
->enable
= NULL
;
4198 brdp
->reenable
= NULL
;
4199 brdp
->disable
= NULL
;
4200 brdp
->getmemptr
= stli_stalgetmemptr
;
4201 brdp
->intr
= stli_ecpintr
;
4202 brdp
->reset
= stli_stalreset
;
4203 name
= "serial(Stallion)";
4211 * The per-board operations structure is all set up, so now let's go
4212 * and get the board operational. Firstly initialize board configuration
4213 * registers. Set the memory mapping info so we can get at the boards
4218 brdp
->membase
= ioremap(brdp
->memaddr
, brdp
->memsize
);
4219 if (brdp
->membase
== (void *) NULL
)
4223 * Now that all specific code is set up, enable the shared memory and
4224 * look for the a signature area that will tell us exactly what board
4225 * this is, and how many ports.
4228 sigsp
= (cdkonbsig_t
*) EBRDGETMEMPTR(brdp
, CDK_SIGADDR
);
4229 memcpy(&sig
, sigsp
, sizeof(cdkonbsig_t
));
4233 printk("%s(%d): sig-> magic=%x:%x:%x:%x romver=%x amask=%x:%x:%x\n",
4234 __FILE__
, __LINE__
, sig
.magic0
, sig
.magic1
, sig
.magic2
,
4235 sig
.magic3
, sig
.romver
, sig
.amask0
, sig
.amask1
, sig
.amask2
);
4238 if ((sig
.magic0
!= ONB_MAGIC0
) || (sig
.magic1
!= ONB_MAGIC1
) ||
4239 (sig
.magic2
!= ONB_MAGIC2
) || (sig
.magic3
!= ONB_MAGIC3
))
4243 * Scan through the signature alive mask and calculate how many ports
4244 * there are on this board.
4250 for (i
= 0; (i
< 16); i
++) {
4251 if (((sig
.amask0
<< i
) & 0x8000) == 0)
4256 brdp
->panels
[0] = brdp
->nrports
;
4258 request_region(brdp
->iobase
, brdp
->iosize
, name
);
4259 brdp
->state
|= BST_FOUND
;
4263 /*****************************************************************************/
4266 * Start up a running board. This routine is only called after the
4267 * code has been down loaded to the board and is operational. It will
4268 * read in the memory map, and get the show on the road...
4271 static int stli_startbrd(stlibrd_t
*brdp
)
4273 volatile cdkhdr_t
*hdrp
;
4274 volatile cdkmem_t
*memp
;
4275 volatile cdkasy_t
*ap
;
4276 unsigned long flags
;
4278 int portnr
, nrdevs
, i
, rc
;
4281 printk("stli_startbrd(brdp=%x)\n", (int) brdp
);
4289 hdrp
= (volatile cdkhdr_t
*) EBRDGETMEMPTR(brdp
, CDK_CDKADDR
);
4290 nrdevs
= hdrp
->nrdevs
;
4293 printk("%s(%d): CDK version %d.%d.%d --> "
4294 "nrdevs=%d memp=%x hostp=%x slavep=%x\n",
4295 __FILE__
, __LINE__
, hdrp
->ver_release
, hdrp
->ver_modification
,
4296 hdrp
->ver_fix
, nrdevs
, (int) hdrp
->memp
, (int) hdrp
->hostp
,
4297 (int) hdrp
->slavep
);
4300 if (nrdevs
< (brdp
->nrports
+ 1)) {
4301 printk("STALLION: slave failed to allocate memory for all "
4302 "devices, devices=%d\n", nrdevs
);
4303 brdp
->nrports
= nrdevs
- 1;
4305 brdp
->nrdevs
= nrdevs
;
4306 brdp
->hostoffset
= hdrp
->hostp
- CDK_CDKADDR
;
4307 brdp
->slaveoffset
= hdrp
->slavep
- CDK_CDKADDR
;
4308 brdp
->bitsize
= (nrdevs
+ 7) / 8;
4309 memp
= (volatile cdkmem_t
*) hdrp
->memp
;
4310 if (((unsigned long) memp
) > brdp
->memsize
) {
4311 printk("STALLION: corrupted shared memory region?\n");
4313 goto stli_donestartup
;
4315 memp
= (volatile cdkmem_t
*) EBRDGETMEMPTR(brdp
, (unsigned long) memp
);
4316 if (memp
->dtype
!= TYP_ASYNCTRL
) {
4317 printk("STALLION: no slave control device found\n");
4318 goto stli_donestartup
;
4323 * Cycle through memory allocation of each port. We are guaranteed to
4324 * have all ports inside the first page of slave window, so no need to
4325 * change pages while reading memory map.
4327 for (i
= 1, portnr
= 0; (i
< nrdevs
); i
++, portnr
++, memp
++) {
4328 if (memp
->dtype
!= TYP_ASYNC
)
4330 portp
= brdp
->ports
[portnr
];
4331 if (portp
== (stliport_t
*) NULL
)
4334 portp
->addr
= memp
->offset
;
4335 portp
->reqbit
= (unsigned char) (0x1 << (i
* 8 / nrdevs
));
4336 portp
->portidx
= (unsigned char) (i
/ 8);
4337 portp
->portbit
= (unsigned char) (0x1 << (i
% 8));
4340 hdrp
->slavereq
= 0xff;
4343 * For each port setup a local copy of the RX and TX buffer offsets
4344 * and sizes. We do this separate from the above, because we need to
4345 * move the shared memory page...
4347 for (i
= 1, portnr
= 0; (i
< nrdevs
); i
++, portnr
++) {
4348 portp
= brdp
->ports
[portnr
];
4349 if (portp
== (stliport_t
*) NULL
)
4351 if (portp
->addr
== 0)
4353 ap
= (volatile cdkasy_t
*) EBRDGETMEMPTR(brdp
, portp
->addr
);
4354 if (ap
!= (volatile cdkasy_t
*) NULL
) {
4355 portp
->rxsize
= ap
->rxq
.size
;
4356 portp
->txsize
= ap
->txq
.size
;
4357 portp
->rxoffset
= ap
->rxq
.offset
;
4358 portp
->txoffset
= ap
->txq
.offset
;
4364 restore_flags(flags
);
4367 brdp
->state
|= BST_STARTED
;
4369 if (! stli_timeron
) {
4371 stli_timerlist
.expires
= STLI_TIMEOUT
;
4372 add_timer(&stli_timerlist
);
4378 /*****************************************************************************/
4381 * Probe and initialize the specified board.
4384 static int __init
stli_brdinit(stlibrd_t
*brdp
)
4387 printk("stli_brdinit(brdp=%x)\n", (int) brdp
);
4390 stli_brds
[brdp
->brdnr
] = brdp
;
4392 switch (brdp
->brdtype
) {
4403 case BRD_ONBOARD2_32
:
4415 printk("STALLION: %s board type not supported in this driver\n",
4416 stli_brdnames
[brdp
->brdtype
]);
4419 printk("STALLION: board=%d is unknown board type=%d\n",
4420 brdp
->brdnr
, brdp
->brdtype
);
4424 if ((brdp
->state
& BST_FOUND
) == 0) {
4425 printk("STALLION: %s board not found, board=%d io=%x mem=%x\n",
4426 stli_brdnames
[brdp
->brdtype
], brdp
->brdnr
,
4427 brdp
->iobase
, (int) brdp
->memaddr
);
4431 stli_initports(brdp
);
4432 printk("STALLION: %s found, board=%d io=%x mem=%x "
4433 "nrpanels=%d nrports=%d\n", stli_brdnames
[brdp
->brdtype
],
4434 brdp
->brdnr
, brdp
->iobase
, (int) brdp
->memaddr
,
4435 brdp
->nrpanels
, brdp
->nrports
);
4439 /*****************************************************************************/
4442 * Probe around trying to find where the EISA boards shared memory
4443 * might be. This is a bit if hack, but it is the best we can do.
4446 static inline int stli_eisamemprobe(stlibrd_t
*brdp
)
4448 cdkecpsig_t ecpsig
, *ecpsigp
;
4449 cdkonbsig_t onbsig
, *onbsigp
;
4453 printk("stli_eisamemprobe(brdp=%x)\n", (int) brdp
);
4457 * First up we reset the board, to get it into a known state. There
4458 * is only 2 board types here we need to worry about. Don;t use the
4459 * standard board init routine here, it programs up the shared
4460 * memory address, and we don't know it yet...
4462 if (brdp
->brdtype
== BRD_ECPE
) {
4463 outb(0x1, (brdp
->iobase
+ ECP_EIBRDENAB
));
4464 outb(ECP_EISTOP
, (brdp
->iobase
+ ECP_EICONFR
));
4466 outb(ECP_EIDISABLE
, (brdp
->iobase
+ ECP_EICONFR
));
4468 stli_ecpeienable(brdp
);
4469 } else if (brdp
->brdtype
== BRD_ONBOARDE
) {
4470 outb(0x1, (brdp
->iobase
+ ONB_EIBRDENAB
));
4471 outb(ONB_EISTOP
, (brdp
->iobase
+ ONB_EICONFR
));
4473 outb(ONB_EIDISABLE
, (brdp
->iobase
+ ONB_EICONFR
));
4475 outb(0x1, brdp
->iobase
);
4477 stli_onbeenable(brdp
);
4483 brdp
->memsize
= ECP_MEMSIZE
;
4486 * Board shared memory is enabled, so now we have a poke around and
4487 * see if we can find it.
4489 for (i
= 0; (i
< stli_eisamempsize
); i
++) {
4490 brdp
->memaddr
= stli_eisamemprobeaddrs
[i
];
4491 brdp
->membase
= (void *) brdp
->memaddr
;
4492 brdp
->membase
= ioremap(brdp
->memaddr
, brdp
->memsize
);
4493 if (brdp
->membase
== (void *) NULL
)
4496 if (brdp
->brdtype
== BRD_ECPE
) {
4497 ecpsigp
= (cdkecpsig_t
*) stli_ecpeigetmemptr(brdp
,
4498 CDK_SIGADDR
, __LINE__
);
4499 memcpy(&ecpsig
, ecpsigp
, sizeof(cdkecpsig_t
));
4500 if (ecpsig
.magic
== ECP_MAGIC
)
4503 onbsigp
= (cdkonbsig_t
*) stli_onbegetmemptr(brdp
,
4504 CDK_SIGADDR
, __LINE__
);
4505 memcpy(&onbsig
, onbsigp
, sizeof(cdkonbsig_t
));
4506 if ((onbsig
.magic0
== ONB_MAGIC0
) &&
4507 (onbsig
.magic1
== ONB_MAGIC1
) &&
4508 (onbsig
.magic2
== ONB_MAGIC2
) &&
4509 (onbsig
.magic3
== ONB_MAGIC3
))
4513 iounmap(brdp
->membase
);
4519 * Regardless of whether we found the shared memory or not we must
4520 * disable the region. After that return success or failure.
4522 if (brdp
->brdtype
== BRD_ECPE
)
4523 stli_ecpeidisable(brdp
);
4525 stli_onbedisable(brdp
);
4530 printk("STALLION: failed to probe shared memory region for "
4531 "%s in EISA slot=%d\n", stli_brdnames
[brdp
->brdtype
],
4532 (brdp
->iobase
>> 12));
4538 /*****************************************************************************/
4541 * Probe around and try to find any EISA boards in system. The biggest
4542 * problem here is finding out what memory address is associated with
4543 * an EISA board after it is found. The registers of the ECPE and
4544 * ONboardE are not readable - so we can't read them from there. We
4545 * don't have access to the EISA CMOS (or EISA BIOS) so we don't
4546 * actually have any way to find out the real value. The best we can
4547 * do is go probing around in the usual places hoping we can find it.
4550 static inline int stli_findeisabrds()
4553 unsigned int iobase
, eid
;
4557 printk("stli_findeisabrds()\n");
4561 * Firstly check if this is an EISA system. Do this by probing for
4562 * the system board EISA ID. If this is not an EISA system then
4563 * don't bother going any further!
4566 if (inb(0xc80) == 0xff)
4570 * Looks like an EISA system, so go searching for EISA boards.
4572 for (iobase
= 0x1000; (iobase
<= 0xc000); iobase
+= 0x1000) {
4573 outb(0xff, (iobase
+ 0xc80));
4574 eid
= inb(iobase
+ 0xc80);
4575 eid
|= inb(iobase
+ 0xc81) << 8;
4576 if (eid
!= STL_EISAID
)
4580 * We have found a board. Need to check if this board was
4581 * statically configured already (just in case!).
4583 for (i
= 0; (i
< STL_MAXBRDS
); i
++) {
4584 brdp
= stli_brds
[i
];
4585 if (brdp
== (stlibrd_t
*) NULL
)
4587 if (brdp
->iobase
== iobase
)
4590 if (i
< STL_MAXBRDS
)
4594 * We have found a Stallion board and it is not configured already.
4595 * Allocate a board structure and initialize it.
4597 if ((brdp
= stli_allocbrd()) == (stlibrd_t
*) NULL
)
4599 if ((brdp
->brdnr
= stli_getbrdnr()) < 0)
4601 eid
= inb(iobase
+ 0xc82);
4602 if (eid
== ECP_EISAID
)
4603 brdp
->brdtype
= BRD_ECPE
;
4604 else if (eid
== ONB_EISAID
)
4605 brdp
->brdtype
= BRD_ONBOARDE
;
4607 brdp
->brdtype
= BRD_UNKNOWN
;
4608 brdp
->iobase
= iobase
;
4609 outb(0x1, (iobase
+ 0xc84));
4610 if (stli_eisamemprobe(brdp
))
4611 outb(0, (iobase
+ 0xc84));
4618 /*****************************************************************************/
4621 * Find the next available board number that is free.
4624 static inline int stli_getbrdnr()
4628 for (i
= 0; (i
< STL_MAXBRDS
); i
++) {
4629 if (stli_brds
[i
] == (stlibrd_t
*) NULL
) {
4630 if (i
>= stli_nrbrds
)
4631 stli_nrbrds
= i
+ 1;
4638 /*****************************************************************************/
4643 * We have a Stallion board. Allocate a board structure and
4644 * initialize it. Read its IO and MEMORY resources from PCI
4645 * configuration space.
4648 static inline int stli_initpcibrd(int brdtype
, struct pci_dev
*devp
)
4653 printk("stli_initpcibrd(brdtype=%d,busnr=%x,devnr=%x)\n", brdtype
,
4654 dev
->bus
->number
, dev
->devfn
);
4657 if (pci_enable_device(devp
))
4659 if ((brdp
= stli_allocbrd()) == (stlibrd_t
*) NULL
)
4661 if ((brdp
->brdnr
= stli_getbrdnr()) < 0) {
4662 printk("STALLION: too many boards found, "
4663 "maximum supported %d\n", STL_MAXBRDS
);
4666 brdp
->brdtype
= brdtype
;
4669 printk("%s(%d): BAR[]=%lx,%lx,%lx,%lx\n", __FILE__
, __LINE__
,
4670 pci_resource_start(devp
, 0),
4671 pci_resource_start(devp
, 1),
4672 pci_resource_start(devp
, 2),
4673 pci_resource_start(devp
, 3));
4677 * We have all resources from the board, so lets setup the actual
4678 * board structure now.
4680 brdp
->iobase
= pci_resource_start(devp
, 3);
4681 brdp
->memaddr
= pci_resource_start(devp
, 2);
4687 /*****************************************************************************/
4690 * Find all Stallion PCI boards that might be installed. Initialize each
4691 * one as it is found.
4694 static inline int stli_findpcibrds()
4696 struct pci_dev
*dev
= NULL
;
4700 printk("stli_findpcibrds()\n");
4703 if (! pci_present())
4706 while ((dev
= pci_find_device(PCI_VENDOR_ID_STALLION
,
4707 PCI_DEVICE_ID_ECRA
, dev
))) {
4708 if ((rc
= stli_initpcibrd(BRD_ECPPCI
, dev
)))
4717 /*****************************************************************************/
4720 * Allocate a new board structure. Fill out the basic info in it.
4723 static stlibrd_t
*stli_allocbrd()
4727 brdp
= (stlibrd_t
*) stli_memalloc(sizeof(stlibrd_t
));
4728 if (brdp
== (stlibrd_t
*) NULL
) {
4729 printk("STALLION: failed to allocate memory (size=%d)\n",
4731 return((stlibrd_t
*) NULL
);
4734 memset(brdp
, 0, sizeof(stlibrd_t
));
4735 brdp
->magic
= STLI_BOARDMAGIC
;
4739 /*****************************************************************************/
4742 * Scan through all the boards in the configuration and see what we
4746 static inline int stli_initbrds()
4748 stlibrd_t
*brdp
, *nxtbrdp
;
4753 printk("stli_initbrds()\n");
4756 if (stli_nrbrds
> STL_MAXBRDS
) {
4757 printk("STALLION: too many boards in configuration table, "
4758 "truncating to %d\n", STL_MAXBRDS
);
4759 stli_nrbrds
= STL_MAXBRDS
;
4763 * Firstly scan the list of static boards configured. Allocate
4764 * resources and initialize the boards as found. If this is a
4765 * module then let the module args override static configuration.
4767 for (i
= 0; (i
< stli_nrbrds
); i
++) {
4768 confp
= &stli_brdconf
[i
];
4770 stli_parsebrd(confp
, stli_brdsp
[i
]);
4772 if ((brdp
= stli_allocbrd()) == (stlibrd_t
*) NULL
)
4775 brdp
->brdtype
= confp
->brdtype
;
4776 brdp
->iobase
= confp
->ioaddr1
;
4777 brdp
->memaddr
= confp
->memaddr
;
4782 * Static configuration table done, so now use dynamic methods to
4783 * see if any more boards should be configured.
4789 stli_findeisabrds();
4795 * All found boards are initialized. Now for a little optimization, if
4796 * no boards are sharing the "shared memory" regions then we can just
4797 * leave them all enabled. This is in fact the usual case.
4800 if (stli_nrbrds
> 1) {
4801 for (i
= 0; (i
< stli_nrbrds
); i
++) {
4802 brdp
= stli_brds
[i
];
4803 if (brdp
== (stlibrd_t
*) NULL
)
4805 for (j
= i
+ 1; (j
< stli_nrbrds
); j
++) {
4806 nxtbrdp
= stli_brds
[j
];
4807 if (nxtbrdp
== (stlibrd_t
*) NULL
)
4809 if ((brdp
->membase
>= nxtbrdp
->membase
) &&
4810 (brdp
->membase
<= (nxtbrdp
->membase
+
4811 nxtbrdp
->memsize
- 1))) {
4819 if (stli_shared
== 0) {
4820 for (i
= 0; (i
< stli_nrbrds
); i
++) {
4821 brdp
= stli_brds
[i
];
4822 if (brdp
== (stlibrd_t
*) NULL
)
4824 if (brdp
->state
& BST_FOUND
) {
4826 brdp
->enable
= NULL
;
4827 brdp
->disable
= NULL
;
4835 /*****************************************************************************/
4838 * Code to handle an "staliomem" read operation. This device is the
4839 * contents of the board shared memory. It is used for down loading
4840 * the slave image (and debugging :-)
4843 static ssize_t
stli_memread(struct file
*fp
, char *buf
, size_t count
, loff_t
*offp
)
4845 unsigned long flags
;
4851 printk("stli_memread(fp=%x,buf=%x,count=%x,offp=%x)\n", (int) fp
,
4852 (int) buf
, count
, (int) offp
);
4855 brdnr
= MINOR(fp
->f_dentry
->d_inode
->i_rdev
);
4856 if (brdnr
>= stli_nrbrds
)
4858 brdp
= stli_brds
[brdnr
];
4859 if (brdp
== (stlibrd_t
*) NULL
)
4861 if (brdp
->state
== 0)
4863 if (fp
->f_pos
>= brdp
->memsize
)
4866 size
= MIN(count
, (brdp
->memsize
- fp
->f_pos
));
4872 memptr
= (void *) EBRDGETMEMPTR(brdp
, fp
->f_pos
);
4873 n
= MIN(size
, (brdp
->pagesize
- (((unsigned long) fp
->f_pos
) % brdp
->pagesize
)));
4874 copy_to_user(buf
, memptr
, n
);
4880 restore_flags(flags
);
4885 /*****************************************************************************/
4888 * Code to handle an "staliomem" write operation. This device is the
4889 * contents of the board shared memory. It is used for down loading
4890 * the slave image (and debugging :-)
4893 static ssize_t
stli_memwrite(struct file
*fp
, const char *buf
, size_t count
, loff_t
*offp
)
4895 unsigned long flags
;
4902 printk("stli_memwrite(fp=%x,buf=%x,count=%x,offp=%x)\n", (int) fp
,
4903 (int) buf
, count
, (int) offp
);
4906 brdnr
= MINOR(fp
->f_dentry
->d_inode
->i_rdev
);
4907 if (brdnr
>= stli_nrbrds
)
4909 brdp
= stli_brds
[brdnr
];
4910 if (brdp
== (stlibrd_t
*) NULL
)
4912 if (brdp
->state
== 0)
4914 if (fp
->f_pos
>= brdp
->memsize
)
4917 chbuf
= (char *) buf
;
4918 size
= MIN(count
, (brdp
->memsize
- fp
->f_pos
));
4924 memptr
= (void *) EBRDGETMEMPTR(brdp
, fp
->f_pos
);
4925 n
= MIN(size
, (brdp
->pagesize
- (((unsigned long) fp
->f_pos
) % brdp
->pagesize
)));
4926 copy_from_user(memptr
, chbuf
, n
);
4932 restore_flags(flags
);
4937 /*****************************************************************************/
4940 * Return the board stats structure to user app.
4943 static int stli_getbrdstats(combrd_t
*bp
)
4948 copy_from_user(&stli_brdstats
, bp
, sizeof(combrd_t
));
4949 if (stli_brdstats
.brd
>= STL_MAXBRDS
)
4951 brdp
= stli_brds
[stli_brdstats
.brd
];
4952 if (brdp
== (stlibrd_t
*) NULL
)
4955 memset(&stli_brdstats
, 0, sizeof(combrd_t
));
4956 stli_brdstats
.brd
= brdp
->brdnr
;
4957 stli_brdstats
.type
= brdp
->brdtype
;
4958 stli_brdstats
.hwid
= 0;
4959 stli_brdstats
.state
= brdp
->state
;
4960 stli_brdstats
.ioaddr
= brdp
->iobase
;
4961 stli_brdstats
.memaddr
= brdp
->memaddr
;
4962 stli_brdstats
.nrpanels
= brdp
->nrpanels
;
4963 stli_brdstats
.nrports
= brdp
->nrports
;
4964 for (i
= 0; (i
< brdp
->nrpanels
); i
++) {
4965 stli_brdstats
.panels
[i
].panel
= i
;
4966 stli_brdstats
.panels
[i
].hwid
= brdp
->panelids
[i
];
4967 stli_brdstats
.panels
[i
].nrports
= brdp
->panels
[i
];
4970 copy_to_user(bp
, &stli_brdstats
, sizeof(combrd_t
));
4974 /*****************************************************************************/
4977 * Resolve the referenced port number into a port struct pointer.
4980 static stliport_t
*stli_getport(int brdnr
, int panelnr
, int portnr
)
4985 if ((brdnr
< 0) || (brdnr
>= STL_MAXBRDS
))
4986 return((stliport_t
*) NULL
);
4987 brdp
= stli_brds
[brdnr
];
4988 if (brdp
== (stlibrd_t
*) NULL
)
4989 return((stliport_t
*) NULL
);
4990 for (i
= 0; (i
< panelnr
); i
++)
4991 portnr
+= brdp
->panels
[i
];
4992 if ((portnr
< 0) || (portnr
>= brdp
->nrports
))
4993 return((stliport_t
*) NULL
);
4994 return(brdp
->ports
[portnr
]);
4997 /*****************************************************************************/
5000 * Return the port stats structure to user app. A NULL port struct
5001 * pointer passed in means that we need to find out from the app
5002 * what port to get stats for (used through board control device).
5005 static int stli_portcmdstats(stliport_t
*portp
)
5007 unsigned long flags
;
5011 memset(&stli_comstats
, 0, sizeof(comstats_t
));
5013 if (portp
== (stliport_t
*) NULL
)
5015 brdp
= stli_brds
[portp
->brdnr
];
5016 if (brdp
== (stlibrd_t
*) NULL
)
5019 if (brdp
->state
& BST_STARTED
) {
5020 if ((rc
= stli_cmdwait(brdp
, portp
, A_GETSTATS
,
5021 &stli_cdkstats
, sizeof(asystats_t
), 1)) < 0)
5024 memset(&stli_cdkstats
, 0, sizeof(asystats_t
));
5027 stli_comstats
.brd
= portp
->brdnr
;
5028 stli_comstats
.panel
= portp
->panelnr
;
5029 stli_comstats
.port
= portp
->portnr
;
5030 stli_comstats
.state
= portp
->state
;
5031 stli_comstats
.flags
= portp
->flags
;
5035 if (portp
->tty
!= (struct tty_struct
*) NULL
) {
5036 if (portp
->tty
->driver_data
== portp
) {
5037 stli_comstats
.ttystate
= portp
->tty
->flags
;
5038 stli_comstats
.rxbuffered
= portp
->tty
->flip
.count
;
5039 if (portp
->tty
->termios
!= (struct termios
*) NULL
) {
5040 stli_comstats
.cflags
= portp
->tty
->termios
->c_cflag
;
5041 stli_comstats
.iflags
= portp
->tty
->termios
->c_iflag
;
5042 stli_comstats
.oflags
= portp
->tty
->termios
->c_oflag
;
5043 stli_comstats
.lflags
= portp
->tty
->termios
->c_lflag
;
5047 restore_flags(flags
);
5049 stli_comstats
.txtotal
= stli_cdkstats
.txchars
;
5050 stli_comstats
.rxtotal
= stli_cdkstats
.rxchars
+ stli_cdkstats
.ringover
;
5051 stli_comstats
.txbuffered
= stli_cdkstats
.txringq
;
5052 stli_comstats
.rxbuffered
+= stli_cdkstats
.rxringq
;
5053 stli_comstats
.rxoverrun
= stli_cdkstats
.overruns
;
5054 stli_comstats
.rxparity
= stli_cdkstats
.parity
;
5055 stli_comstats
.rxframing
= stli_cdkstats
.framing
;
5056 stli_comstats
.rxlost
= stli_cdkstats
.ringover
;
5057 stli_comstats
.rxbreaks
= stli_cdkstats
.rxbreaks
;
5058 stli_comstats
.txbreaks
= stli_cdkstats
.txbreaks
;
5059 stli_comstats
.txxon
= stli_cdkstats
.txstart
;
5060 stli_comstats
.txxoff
= stli_cdkstats
.txstop
;
5061 stli_comstats
.rxxon
= stli_cdkstats
.rxstart
;
5062 stli_comstats
.rxxoff
= stli_cdkstats
.rxstop
;
5063 stli_comstats
.rxrtsoff
= stli_cdkstats
.rtscnt
/ 2;
5064 stli_comstats
.rxrtson
= stli_cdkstats
.rtscnt
- stli_comstats
.rxrtsoff
;
5065 stli_comstats
.modem
= stli_cdkstats
.dcdcnt
;
5066 stli_comstats
.hwid
= stli_cdkstats
.hwid
;
5067 stli_comstats
.signals
= stli_mktiocm(stli_cdkstats
.signals
);
5072 /*****************************************************************************/
5075 * Return the port stats structure to user app. A NULL port struct
5076 * pointer passed in means that we need to find out from the app
5077 * what port to get stats for (used through board control device).
5080 static int stli_getportstats(stliport_t
*portp
, comstats_t
*cp
)
5085 if (portp
== (stliport_t
*) NULL
) {
5086 copy_from_user(&stli_comstats
, cp
, sizeof(comstats_t
));
5087 portp
= stli_getport(stli_comstats
.brd
, stli_comstats
.panel
,
5088 stli_comstats
.port
);
5089 if (portp
== (stliport_t
*) NULL
)
5093 brdp
= stli_brds
[portp
->brdnr
];
5094 if (brdp
== (stlibrd_t
*) NULL
)
5097 if ((rc
= stli_portcmdstats(portp
)) < 0)
5100 copy_to_user(cp
, &stli_comstats
, sizeof(comstats_t
));
5104 /*****************************************************************************/
5107 * Clear the port stats structure. We also return it zeroed out...
5110 static int stli_clrportstats(stliport_t
*portp
, comstats_t
*cp
)
5115 if (portp
== (stliport_t
*) NULL
) {
5116 copy_from_user(&stli_comstats
, cp
, sizeof(comstats_t
));
5117 portp
= stli_getport(stli_comstats
.brd
, stli_comstats
.panel
,
5118 stli_comstats
.port
);
5119 if (portp
== (stliport_t
*) NULL
)
5123 brdp
= stli_brds
[portp
->brdnr
];
5124 if (brdp
== (stlibrd_t
*) NULL
)
5127 if (brdp
->state
& BST_STARTED
) {
5128 if ((rc
= stli_cmdwait(brdp
, portp
, A_CLEARSTATS
, 0, 0, 0)) < 0)
5132 memset(&stli_comstats
, 0, sizeof(comstats_t
));
5133 stli_comstats
.brd
= portp
->brdnr
;
5134 stli_comstats
.panel
= portp
->panelnr
;
5135 stli_comstats
.port
= portp
->portnr
;
5137 copy_to_user(cp
, &stli_comstats
, sizeof(comstats_t
));
5141 /*****************************************************************************/
5144 * Return the entire driver ports structure to a user app.
5147 static int stli_getportstruct(unsigned long arg
)
5151 copy_from_user(&stli_dummyport
, (void *) arg
, sizeof(stliport_t
));
5152 portp
= stli_getport(stli_dummyport
.brdnr
, stli_dummyport
.panelnr
,
5153 stli_dummyport
.portnr
);
5154 if (portp
== (stliport_t
*) NULL
)
5156 copy_to_user((void *) arg
, portp
, sizeof(stliport_t
));
5160 /*****************************************************************************/
5163 * Return the entire driver board structure to a user app.
5166 static int stli_getbrdstruct(unsigned long arg
)
5170 copy_from_user(&stli_dummybrd
, (void *) arg
, sizeof(stlibrd_t
));
5171 if ((stli_dummybrd
.brdnr
< 0) || (stli_dummybrd
.brdnr
>= STL_MAXBRDS
))
5173 brdp
= stli_brds
[stli_dummybrd
.brdnr
];
5174 if (brdp
== (stlibrd_t
*) NULL
)
5176 copy_to_user((void *) arg
, brdp
, sizeof(stlibrd_t
));
5180 /*****************************************************************************/
5183 * The "staliomem" device is also required to do some special operations on
5184 * the board. We need to be able to send an interrupt to the board,
5185 * reset it, and start/stop it.
5188 static int stli_memioctl(struct inode
*ip
, struct file
*fp
, unsigned int cmd
, unsigned long arg
)
5191 int brdnr
, rc
, done
;
5194 printk("stli_memioctl(ip=%x,fp=%x,cmd=%x,arg=%x)\n", (int) ip
,
5195 (int) fp
, cmd
, (int) arg
);
5199 * First up handle the board independent ioctls.
5205 case COM_GETPORTSTATS
:
5206 if ((rc
= verify_area(VERIFY_WRITE
, (void *) arg
,
5207 sizeof(comstats_t
))) == 0)
5208 rc
= stli_getportstats((stliport_t
*) NULL
,
5209 (comstats_t
*) arg
);
5212 case COM_CLRPORTSTATS
:
5213 if ((rc
= verify_area(VERIFY_WRITE
, (void *) arg
,
5214 sizeof(comstats_t
))) == 0)
5215 rc
= stli_clrportstats((stliport_t
*) NULL
,
5216 (comstats_t
*) arg
);
5219 case COM_GETBRDSTATS
:
5220 if ((rc
= verify_area(VERIFY_WRITE
, (void *) arg
,
5221 sizeof(combrd_t
))) == 0)
5222 rc
= stli_getbrdstats((combrd_t
*) arg
);
5226 if ((rc
= verify_area(VERIFY_WRITE
, (void *) arg
,
5227 sizeof(stliport_t
))) == 0)
5228 rc
= stli_getportstruct(arg
);
5232 if ((rc
= verify_area(VERIFY_WRITE
, (void *) arg
,
5233 sizeof(stlibrd_t
))) == 0)
5234 rc
= stli_getbrdstruct(arg
);
5245 * Now handle the board specific ioctls. These all depend on the
5246 * minor number of the device they were called from.
5248 brdnr
= MINOR(ip
->i_rdev
);
5249 if (brdnr
>= STL_MAXBRDS
)
5251 brdp
= stli_brds
[brdnr
];
5252 if (brdp
== (stlibrd_t
*) NULL
)
5254 if (brdp
->state
== 0)
5262 rc
= stli_startbrd(brdp
);
5265 brdp
->state
&= ~BST_STARTED
;
5268 brdp
->state
&= ~BST_STARTED
;
5270 if (stli_shared
== 0) {
5271 if (brdp
->reenable
!= NULL
)
5272 (* brdp
->reenable
)(brdp
);
5283 /*****************************************************************************/
5285 int __init
stli_init(void)
5287 printk(KERN_INFO
"%s: version %s\n", stli_drvtitle
, stli_drvversion
);
5292 * Allocate a temporary write buffer.
5294 stli_tmpwritebuf
= (char *) stli_memalloc(STLI_TXBUFSIZE
);
5295 if (stli_tmpwritebuf
== (char *) NULL
)
5296 printk("STALLION: failed to allocate memory (size=%d)\n",
5298 stli_txcookbuf
= (char *) stli_memalloc(STLI_TXBUFSIZE
);
5299 if (stli_txcookbuf
== (char *) NULL
)
5300 printk("STALLION: failed to allocate memory (size=%d)\n",
5304 * Set up a character driver for the shared memory region. We need this
5305 * to down load the slave code image. Also it is a useful debugging tool.
5307 if (devfs_register_chrdev(STL_SIOMEMMAJOR
, "staliomem", &stli_fsiomem
))
5308 printk("STALLION: failed to register serial memory device\n");
5310 devfs_handle
= devfs_mk_dir (NULL
, "staliomem", NULL
);
5311 devfs_register_series (devfs_handle
, "%u", 4, DEVFS_FL_DEFAULT
,
5313 S_IFCHR
| S_IRUSR
| S_IWUSR
,
5314 &stli_fsiomem
, NULL
);
5317 * Set up the tty driver structure and register us as a driver.
5318 * Also setup the callout tty device.
5320 memset(&stli_serial
, 0, sizeof(struct tty_driver
));
5321 stli_serial
.magic
= TTY_DRIVER_MAGIC
;
5322 stli_serial
.driver_name
= stli_drvname
;
5323 stli_serial
.name
= stli_serialname
;
5324 stli_serial
.major
= STL_SERIALMAJOR
;
5325 stli_serial
.minor_start
= 0;
5326 stli_serial
.num
= STL_MAXBRDS
* STL_MAXPORTS
;
5327 stli_serial
.type
= TTY_DRIVER_TYPE_SERIAL
;
5328 stli_serial
.subtype
= STL_DRVTYPSERIAL
;
5329 stli_serial
.init_termios
= stli_deftermios
;
5330 stli_serial
.flags
= TTY_DRIVER_REAL_RAW
;
5331 stli_serial
.refcount
= &stli_refcount
;
5332 stli_serial
.table
= stli_ttys
;
5333 stli_serial
.termios
= stli_termios
;
5334 stli_serial
.termios_locked
= stli_termioslocked
;
5336 stli_serial
.open
= stli_open
;
5337 stli_serial
.close
= stli_close
;
5338 stli_serial
.write
= stli_write
;
5339 stli_serial
.put_char
= stli_putchar
;
5340 stli_serial
.flush_chars
= stli_flushchars
;
5341 stli_serial
.write_room
= stli_writeroom
;
5342 stli_serial
.chars_in_buffer
= stli_charsinbuffer
;
5343 stli_serial
.ioctl
= stli_ioctl
;
5344 stli_serial
.set_termios
= stli_settermios
;
5345 stli_serial
.throttle
= stli_throttle
;
5346 stli_serial
.unthrottle
= stli_unthrottle
;
5347 stli_serial
.stop
= stli_stop
;
5348 stli_serial
.start
= stli_start
;
5349 stli_serial
.hangup
= stli_hangup
;
5350 stli_serial
.flush_buffer
= stli_flushbuffer
;
5351 stli_serial
.break_ctl
= stli_breakctl
;
5352 stli_serial
.wait_until_sent
= stli_waituntilsent
;
5353 stli_serial
.send_xchar
= stli_sendxchar
;
5354 stli_serial
.read_proc
= stli_readproc
;
5356 stli_callout
= stli_serial
;
5357 stli_callout
.name
= stli_calloutname
;
5358 stli_callout
.major
= STL_CALLOUTMAJOR
;
5359 stli_callout
.subtype
= STL_DRVTYPCALLOUT
;
5360 stli_callout
.read_proc
= 0;
5362 if (tty_register_driver(&stli_serial
))
5363 printk("STALLION: failed to register serial driver\n");
5364 if (tty_register_driver(&stli_callout
))
5365 printk("STALLION: failed to register callout driver\n");
5370 /*****************************************************************************/