Linux 2.4.0-test10pre4
[davej-history.git] / drivers / char / istallion.c
blob0bcc63a436af241851a9ae6844f834c64459a40a
1 /*****************************************************************************/
3 /*
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>
44 #include <asm/io.h>
45 #include <asm/uaccess.h>
47 #ifdef CONFIG_PCI
48 #include <linux/pci.h>
49 #endif
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
58 * STAL = Stallion.
60 #define BRD_UNKNOWN 0
61 #define BRD_STALLION 1
62 #define BRD_BRUMBY4 2
63 #define BRD_ONBOARD2 3
64 #define BRD_ONBOARD 4
65 #define BRD_BRUMBY8 5
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
71 #define BRD_EASYIO 20
72 #define BRD_ECH 21
73 #define BRD_ECHMC 22
74 #define BRD_ECP 23
75 #define BRD_ECPE 24
76 #define BRD_ECPMC 25
77 #define BRD_ECHPCI 26
78 #define BRD_ECH64PCI 27
79 #define BRD_EASYIOPCI 28
80 #define BRD_ECPPCI 29
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).
91 * Some examples:
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.
97 * Another example:
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.
103 * Another example:
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.
108 * Another example:
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.
114 * Another example:
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.
123 typedef struct {
124 int brdtype;
125 int ioaddr1;
126 int ioaddr2;
127 unsigned long memaddr;
128 int irq;
129 int irqtype;
130 } stlconf_t;
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
155 #endif
156 #ifndef STL_SERIALMAJOR
157 #define STL_SERIALMAJOR 24
158 #endif
159 #ifndef STL_CALLOUTMAJOR
160 #define STL_CALLOUTMAJOR 25
161 #endif
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),
220 INIT_C_CC
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
243 * or not.
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
255 #define ST_OPENING 2
256 #define ST_CLOSING 3
257 #define ST_CMDING 4
258 #define ST_TXBUSY 5
259 #define ST_RXING 6
260 #define ST_DOFLUSHRX 7
261 #define ST_DOFLUSHTX 8
262 #define ST_DOSIGS 9
263 #define ST_RXSTOP 10
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[] = {
271 "Unknown",
272 "Stallion",
273 "Brumby",
274 "ONboard-MC",
275 "ONboard",
276 "Brumby",
277 "Brumby",
278 "ONboard-EI",
279 (char *) NULL,
280 "ONboard",
281 "ONboard-MC",
282 "ONboard-MC",
283 (char *) NULL,
284 (char *) NULL,
285 (char *) NULL,
286 (char *) NULL,
287 (char *) NULL,
288 (char *) NULL,
289 (char *) NULL,
290 (char *) NULL,
291 "EasyIO",
292 "EC8/32-AT",
293 "EC8/32-MC",
294 "EC8/64-AT",
295 "EC8/64-EI",
296 "EC8/64-MC",
297 "EC8/32-PCI",
298 "EC8/64-PCI",
299 "EasyIO-PCI",
300 "EC/RA-PCI",
303 /*****************************************************************************/
305 #ifdef MODULE
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[] = {
318 (char **) &board0,
319 (char **) &board1,
320 (char **) &board2,
321 (char **) &board3
325 * Define a set of common board names, and types. This is used to
326 * parse any module arguments.
329 typedef struct stlibrdtype {
330 char *name;
331 int type;
332 } stlibrdtype_t;
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 },
347 { "2", 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 },
365 { "ecp", BRD_ECP },
366 { "ecpat", BRD_ECP },
367 { "ec8/64", BRD_ECP },
368 { "ec8/64-at", BRD_ECP },
369 { "ec8/64-isa", BRD_ECP },
370 { "23", BRD_ECP },
371 { "ecpe", BRD_ECPE },
372 { "ecpei", BRD_ECPE },
373 { "ec8/64-e", BRD_ECPE },
374 { "ec8/64-ei", BRD_ECPE },
375 { "24", BRD_ECPE },
376 { "ecpmc", BRD_ECPMC },
377 { "ec8/64-mc", BRD_ECPMC },
378 { "ec8/64-mca", BRD_ECPMC },
379 { "25", 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]");
402 #endif
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.
426 #ifdef CONFIG_PCI
427 #ifndef PCI_VENDOR_ID_STALLION
428 #define PCI_VENDOR_ID_STALLION 0x124d
429 #endif
430 #ifndef PCI_DEVICE_ID_ECRA
431 #define PCI_DEVICE_ID_ECRA 0x0004
432 #endif
433 #endif
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.
442 #define ECP_IOSIZE 4
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.
457 #define ECP_ATIREG 0
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.
471 #define ECP_EIIREG 0
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.)
492 #define ECP_MCIREG 0
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.
520 #define ONB_ATIREG 0
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.
535 #define ONB_EIIREG 0
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)
560 #define BBY_ATIREG 0
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) \
595 (* brdp->init)(brdp)
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...
646 #undef MIN
647 #define MIN(a,b) (((a) <= (b)) ? (a) : (b))
649 #undef TOLOWER
650 #define TOLOWER(x) ((((x) >= 'A') && ((x) <= 'Z')) ? ((x) + 0x20) : (x))
652 /*****************************************************************************/
655 * Prototype all functions in this driver!
658 #ifdef MODULE
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);
665 #endif
667 int stli_init(void);
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);
767 #ifdef CONFIG_PCI
768 static inline int stli_findpcibrds(void);
769 static inline int stli_initpcibrd(int brdtype, struct pci_dev *devp);
770 #endif
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 = {
781 owner: THIS_MODULE,
782 read: stli_memread,
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 = {
796 function: stli_poll
799 static int stli_timeron;
802 * Define the calculation for the timeout routine.
804 #define STLI_TIMEOUT (jiffies + 1)
806 /*****************************************************************************/
808 #ifdef MODULE
811 * Loadable module initialization stuff.
814 int init_module()
816 unsigned long flags;
818 #if DEBUG
819 printk("init_module()\n");
820 #endif
822 save_flags(flags);
823 cli();
824 stli_init();
825 restore_flags(flags);
827 return(0);
830 /*****************************************************************************/
832 void cleanup_module()
834 stlibrd_t *brdp;
835 stliport_t *portp;
836 unsigned long flags;
837 int i, j;
839 #if DEBUG
840 printk("cleanup_module()\n");
841 #endif
843 printk(KERN_INFO "Unloading %s: version %s\n", stli_drvtitle,
844 stli_drvversion);
846 save_flags(flags);
847 cli();
850 * Free up all allocated resources used by the ports. This includes
851 * memory and interrupts.
853 if (stli_timeron) {
854 stli_timeron = 0;
855 del_timer(&stli_timerlist);
858 i = tty_unregister_driver(&stli_serial);
859 j = tty_unregister_driver(&stli_callout);
860 if (i || j) {
861 printk("STALLION: failed to un-register tty driver, "
862 "errno=%d,%d\n", -i, -j);
863 restore_flags(flags);
864 return;
866 devfs_unregister (devfs_handle);
867 if ((i = devfs_unregister_chrdev(STL_SIOMEMMAJOR, "staliomem")))
868 printk("STALLION: failed to un-register serial memory device, "
869 "errno=%d\n", -i);
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)
877 continue;
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);
883 kfree(portp);
887 iounmap(brdp->membase);
888 if (brdp->iosize > 0)
889 release_region(brdp->iobase, brdp->iosize);
890 kfree(brdp);
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()
905 stlconf_t conf;
906 stlibrd_t *brdp;
907 int nrargs, i;
909 #if DEBUG
910 printk("stli_argbrds()\n");
911 #endif
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)
918 continue;
919 if ((brdp = stli_allocbrd()) == (stlibrd_t *) NULL)
920 continue;
921 stli_nrbrds = i + 1;
922 brdp->brdnr = i;
923 brdp->brdtype = conf.brdtype;
924 brdp->iobase = conf.ioaddr1;
925 brdp->memaddr = conf.memaddr;
926 stli_brdinit(brdp);
930 /*****************************************************************************/
933 * Convert an ascii string number into an unsigned long.
936 static unsigned long stli_atol(char *str)
938 unsigned long val;
939 int base, c;
940 char *sp;
942 val = 0;
943 sp = str;
944 if ((*sp == '0') && (*(sp+1) == 'x')) {
945 base = 16;
946 sp += 2;
947 } else if (*sp == '0') {
948 base = 8;
949 sp++;
950 } else {
951 base = 10;
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);
958 val = 0;
959 break;
961 val = (val * base) + c;
963 return(val);
966 /*****************************************************************************/
969 * Parse the supplied argument string, into the board conf struct.
972 static int stli_parsebrd(stlconf_t *confp, char **argp)
974 char *sp;
975 int nrbrdnames, i;
977 #if DEBUG
978 printk("stli_parsebrd(confp=%x,argp=%x)\n", (int) confp, (int) argp);
979 #endif
981 if ((argp[0] == (char *) NULL) || (*argp[0] == 0))
982 return(0);
984 for (sp = argp[0], i = 0; ((*sp != 0) && (i < 25)); sp++, i++)
985 *sp = TOLOWER(*sp);
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)
990 break;
992 if (i >= nrbrdnames) {
993 printk("STALLION: unknown board name, %s?\n", argp[0]);
994 return(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]);
1002 return(1);
1005 #endif
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)
1022 stlibrd_t *brdp;
1023 stliport_t *portp;
1024 unsigned int minordev;
1025 int brdnr, portnr, rc;
1027 #if DEBUG
1028 printk("stli_open(tty=%x,filp=%x): device=%x\n", (int) tty,
1029 (int) filp, tty->device);
1030 #endif
1032 minordev = MINOR(tty->device);
1033 brdnr = MINOR2BRD(minordev);
1034 if (brdnr >= stli_nrbrds)
1035 return(-ENODEV);
1036 brdp = stli_brds[brdnr];
1037 if (brdp == (stlibrd_t *) NULL)
1038 return(-ENODEV);
1039 if ((brdp->state & BST_STARTED) == 0)
1040 return(-ENODEV);
1041 portnr = MINOR2PORT(minordev);
1042 if ((portnr < 0) || (portnr > brdp->nrports))
1043 return(-ENODEV);
1045 portp = brdp->ports[portnr];
1046 if (portp == (stliport_t *) NULL)
1047 return(-ENODEV);
1048 if (portp->devnr < 1)
1049 return(-ENODEV);
1051 MOD_INC_USE_COUNT;
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)
1062 return(-EAGAIN);
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.
1072 portp->tty = tty;
1073 tty->driver_data = portp;
1074 portp->refcount++;
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);
1090 if (rc < 0)
1091 return(rc);
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)
1103 return(-EAGAIN);
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)
1114 return(-EBUSY);
1115 if (portp->flags & ASYNC_CALLOUT_ACTIVE) {
1116 if ((portp->flags & ASYNC_SESSION_LOCKOUT) &&
1117 (portp->session != current->session))
1118 return(-EBUSY);
1119 if ((portp->flags & ASYNC_PGRP_LOCKOUT) &&
1120 (portp->pgrp != current->pgrp))
1121 return(-EBUSY);
1123 portp->flags |= ASYNC_CALLOUT_ACTIVE;
1124 } else {
1125 if (filp->f_flags & O_NONBLOCK) {
1126 if (portp->flags & ASYNC_CALLOUT_ACTIVE)
1127 return(-EBUSY);
1128 } else {
1129 if ((rc = stli_waitcarrier(brdp, portp, filp)) != 0)
1130 return(rc);
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;
1138 else
1139 *tty->termios = portp->callouttermios;
1140 stli_setport(portp);
1143 portp->session = current->session;
1144 portp->pgrp = current->pgrp;
1145 return(0);
1148 /*****************************************************************************/
1150 static void stli_close(struct tty_struct *tty, struct file *filp)
1152 stlibrd_t *brdp;
1153 stliport_t *portp;
1154 unsigned long flags;
1156 #if DEBUG
1157 printk("stli_close(tty=%x,filp=%x)\n", (int) tty, (int) filp);
1158 #endif
1160 portp = tty->driver_data;
1161 if (portp == (stliport_t *) NULL)
1162 return;
1164 save_flags(flags);
1165 cli();
1166 if (tty_hung_up_p(filp)) {
1167 MOD_DEC_USE_COUNT;
1168 restore_flags(flags);
1169 return;
1171 if ((tty->count == 1) && (portp->refcount != 1))
1172 portp->refcount = 1;
1173 if (portp->refcount-- > 1) {
1174 MOD_DEC_USE_COUNT;
1175 restore_flags(flags);
1176 return;
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);
1194 tty->closing = 1;
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);
1205 else
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);
1217 tty->closing = 0;
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 |
1227 ASYNC_CLOSING);
1228 wake_up_interruptible(&portp->close_wait);
1229 MOD_DEC_USE_COUNT;
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;
1246 asynotify_t nt;
1247 asyport_t aport;
1248 int rc;
1250 #if DEBUG
1251 printk("stli_initopen(brdp=%x,portp=%x)\n", (int) brdp, (int) portp);
1252 #endif
1254 if ((rc = stli_rawopen(brdp, portp, 0, 1)) < 0)
1255 return(rc);
1257 memset(&nt, 0, sizeof(asynotify_t));
1258 nt.data = (DT_TXLOW | DT_TXEMPTY | DT_RXBUSY | DT_RXBREAK);
1259 nt.signal = SG_DCD;
1260 if ((rc = stli_cmdwait(brdp, portp, A_SETNOTIFY, &nt,
1261 sizeof(asynotify_t), 0)) < 0)
1262 return(rc);
1264 tty = portp->tty;
1265 if (tty == (struct tty_struct *) NULL)
1266 return(-ENODEV);
1267 stli_mkasyport(portp, &aport, tty->termios);
1268 if ((rc = stli_cmdwait(brdp, portp, A_SETPORT, &aport,
1269 sizeof(asyport_t), 0)) < 0)
1270 return(rc);
1272 set_bit(ST_GETSIGS, &portp->state);
1273 if ((rc = stli_cmdwait(brdp, portp, A_GETSIGNALS, &portp->asig,
1274 sizeof(asysigs_t), 1)) < 0)
1275 return(rc);
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)
1281 return(rc);
1283 return(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
1292 * to overlap.
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;
1301 int rc;
1303 #if DEBUG
1304 printk("stli_rawopen(brdp=%x,portp=%x,arg=%x,wait=%d)\n",
1305 (int) brdp, (int) portp, (int) arg, wait);
1306 #endif
1309 * Send a message to the slave to open this port.
1311 save_flags(flags);
1312 cli();
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.
1333 EBRDENABLE(brdp);
1334 cp = &((volatile cdkasy_t *) EBRDGETMEMPTR(brdp, portp->addr))->ctrl;
1335 cp->openarg = arg;
1336 cp->open = 1;
1337 hdrp = (volatile cdkhdr_t *) EBRDGETMEMPTR(brdp, CDK_CDKADDR);
1338 bits = ((volatile unsigned char *) hdrp) + brdp->slaveoffset +
1339 portp->portidx;
1340 *bits |= portp->portbit;
1341 EBRDDISABLE(brdp);
1343 if (wait == 0) {
1344 restore_flags(flags);
1345 return(0);
1349 * Slave is in action, so now we must wait for the open acknowledgment
1350 * to come back.
1352 rc = 0;
1353 set_bit(ST_OPENING, &portp->state);
1354 while (test_bit(ST_OPENING, &portp->state)) {
1355 if (signal_pending(current)) {
1356 rc = -ERESTARTSYS;
1357 break;
1359 interruptible_sleep_on(&portp->raw_wait);
1361 restore_flags(flags);
1363 if ((rc == 0) && (portp->rc != 0))
1364 rc = -EIO;
1365 return(rc);
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;
1382 int rc;
1384 #if DEBUG
1385 printk("stli_rawclose(brdp=%x,portp=%x,arg=%x,wait=%d)\n",
1386 (int) brdp, (int) portp, (int) arg, wait);
1387 #endif
1389 save_flags(flags);
1390 cli();
1393 * Slave is already closing this port. This can happen if a hangup
1394 * occurs on this port.
1396 if (wait) {
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.
1409 EBRDENABLE(brdp);
1410 cp = &((volatile cdkasy_t *) EBRDGETMEMPTR(brdp, portp->addr))->ctrl;
1411 cp->closearg = arg;
1412 cp->close = 1;
1413 hdrp = (volatile cdkhdr_t *) EBRDGETMEMPTR(brdp, CDK_CDKADDR);
1414 bits = ((volatile unsigned char *) hdrp) + brdp->slaveoffset +
1415 portp->portidx;
1416 *bits |= portp->portbit;
1417 EBRDDISABLE(brdp);
1419 set_bit(ST_CLOSING, &portp->state);
1420 if (wait == 0) {
1421 restore_flags(flags);
1422 return(0);
1426 * Slave is in action, so now we must wait for the open acknowledgment
1427 * to come back.
1429 rc = 0;
1430 while (test_bit(ST_CLOSING, &portp->state)) {
1431 if (signal_pending(current)) {
1432 rc = -ERESTARTSYS;
1433 break;
1435 interruptible_sleep_on(&portp->raw_wait);
1437 restore_flags(flags);
1439 if ((rc == 0) && (portp->rc != 0))
1440 rc = -EIO;
1441 return(rc);
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;
1457 #if DEBUG
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);
1461 #endif
1463 save_flags(flags);
1464 cli();
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);
1484 if (portp->rc != 0)
1485 return(-EIO);
1486 return(0);
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)
1498 stlibrd_t *brdp;
1499 asyport_t aport;
1501 #if DEBUG
1502 printk("stli_setport(portp=%x)\n", (int) portp);
1503 #endif
1505 if (portp == (stliport_t *) NULL)
1506 return(-ENODEV);
1507 if (portp->tty == (struct tty_struct *) NULL)
1508 return(-ENODEV);
1509 if ((portp->brdnr < 0) && (portp->brdnr >= stli_nrbrds))
1510 return(-ENODEV);
1511 brdp = stli_brds[portp->brdnr];
1512 if (brdp == (stlibrd_t *) NULL)
1513 return(-ENODEV);
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)
1529 #if DEBUG
1530 printk("stli_delay(len=%d)\n", len);
1531 #endif
1532 if (len > 0) {
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;
1549 int rc, doclocal;
1551 #if DEBUG
1552 printk("stli_waitcarrier(brdp=%x,portp=%x,filp=%x)\n",
1553 (int) brdp, (int) portp, (int) filp);
1554 #endif
1556 rc = 0;
1557 doclocal = 0;
1559 if (portp->flags & ASYNC_CALLOUT_ACTIVE) {
1560 if (portp->normaltermios.c_cflag & CLOCAL)
1561 doclocal++;
1562 } else {
1563 if (portp->tty->termios->c_cflag & CLOCAL)
1564 doclocal++;
1567 save_flags(flags);
1568 cli();
1569 portp->openwaitcnt++;
1570 if (! tty_hung_up_p(filp))
1571 portp->refcount--;
1573 for (;;) {
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)
1578 break;
1580 if (tty_hung_up_p(filp) ||
1581 ((portp->flags & ASYNC_INITIALIZED) == 0)) {
1582 if (portp->flags & ASYNC_HUP_NOTIFY)
1583 rc = -EBUSY;
1584 else
1585 rc = -ERESTARTSYS;
1586 break;
1588 if (((portp->flags & ASYNC_CALLOUT_ACTIVE) == 0) &&
1589 ((portp->flags & ASYNC_CLOSING) == 0) &&
1590 (doclocal || (portp->sigs & TIOCM_CD))) {
1591 break;
1593 if (signal_pending(current)) {
1594 rc = -ERESTARTSYS;
1595 break;
1597 interruptible_sleep_on(&portp->open_wait);
1600 if (! tty_hung_up_p(filp))
1601 portp->refcount++;
1602 portp->openwaitcnt--;
1603 restore_flags(flags);
1605 return(rc);
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;
1622 stliport_t *portp;
1623 stlibrd_t *brdp;
1624 unsigned int len, stlen, head, tail, size;
1625 unsigned long flags;
1627 #if DEBUG
1628 printk("stli_write(tty=%x,from_user=%d,buf=%x,count=%d)\n",
1629 (int) tty, from_user, (int) buf, count);
1630 #endif
1632 if ((tty == (struct tty_struct *) NULL) ||
1633 (stli_tmpwritebuf == (char *) NULL))
1634 return(0);
1635 if (tty == stli_txcooktty)
1636 stli_flushchars(tty);
1637 portp = tty->driver_data;
1638 if (portp == (stliport_t *) NULL)
1639 return(0);
1640 if ((portp->brdnr < 0) || (portp->brdnr >= stli_nrbrds))
1641 return(0);
1642 brdp = stli_brds[portp->brdnr];
1643 if (brdp == (stlibrd_t *) NULL)
1644 return(0);
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.
1658 if (from_user) {
1659 save_flags(flags);
1660 cli();
1661 EBRDENABLE(brdp);
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) :
1668 (tail - head - 1);
1669 count = MIN(len, count);
1670 EBRDDISABLE(brdp);
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.
1681 save_flags(flags);
1682 cli();
1683 EBRDENABLE(brdp);
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;
1690 if (head >= tail) {
1691 len = size - (head - tail) - 1;
1692 stlen = size - head;
1693 } else {
1694 len = tail - head - 1;
1695 stlen = len;
1698 len = MIN(len, count);
1699 count = 0;
1700 shbuf = (char *) EBRDGETMEMPTR(brdp, portp->txoffset);
1702 while (len > 0) {
1703 stlen = MIN(len, stlen);
1704 memcpy((shbuf + head), chbuf, stlen);
1705 chbuf += stlen;
1706 len -= stlen;
1707 count += stlen;
1708 head += stlen;
1709 if (head >= size) {
1710 head = 0;
1711 stlen = tail;
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 +
1723 portp->portidx;
1724 *bits |= portp->portbit;
1725 set_bit(ST_TXBUSY, &portp->state);
1726 EBRDDISABLE(brdp);
1728 if (from_user)
1729 up(&stli_tmpwritesem);
1730 restore_flags(flags);
1732 return(count);
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)
1747 #if DEBUG
1748 printk("stli_putchar(tty=%x,ch=%x)\n", (int) tty, (int) ch);
1749 #endif
1751 if (tty == (struct tty_struct *) NULL)
1752 return;
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
1769 * by someone else.
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;
1778 stliport_t *portp;
1779 stlibrd_t *brdp;
1780 unsigned int len, stlen, head, tail, size, count, cooksize;
1781 unsigned char *buf, *shbuf;
1782 unsigned long flags;
1784 #if DEBUG
1785 printk("stli_flushchars(tty=%x)\n", (int) tty);
1786 #endif
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)
1795 return;
1796 if (cooktty == (struct tty_struct *) NULL)
1797 return;
1798 if (tty != cooktty)
1799 tty = cooktty;
1800 if (cooksize == 0)
1801 return;
1803 portp = tty->driver_data;
1804 if (portp == (stliport_t *) NULL)
1805 return;
1806 if ((portp->brdnr < 0) || (portp->brdnr >= stli_nrbrds))
1807 return;
1808 brdp = stli_brds[portp->brdnr];
1809 if (brdp == (stlibrd_t *) NULL)
1810 return;
1812 save_flags(flags);
1813 cli();
1814 EBRDENABLE(brdp);
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;
1822 if (head >= tail) {
1823 len = size - (head - tail) - 1;
1824 stlen = size - head;
1825 } else {
1826 len = tail - head - 1;
1827 stlen = len;
1830 len = MIN(len, cooksize);
1831 count = 0;
1832 shbuf = (char *) EBRDGETMEMPTR(brdp, portp->txoffset);
1833 buf = stli_txcookbuf;
1835 while (len > 0) {
1836 stlen = MIN(len, stlen);
1837 memcpy((shbuf + head), buf, stlen);
1838 buf += stlen;
1839 len -= stlen;
1840 count += stlen;
1841 head += stlen;
1842 if (head >= size) {
1843 head = 0;
1844 stlen = tail;
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 +
1857 portp->portidx;
1858 *bits |= portp->portbit;
1859 set_bit(ST_TXBUSY, &portp->state);
1861 EBRDDISABLE(brdp);
1862 restore_flags(flags);
1865 /*****************************************************************************/
1867 static int stli_writeroom(struct tty_struct *tty)
1869 volatile cdkasyrq_t *rp;
1870 stliport_t *portp;
1871 stlibrd_t *brdp;
1872 unsigned int head, tail, len;
1873 unsigned long flags;
1875 #if DEBUG
1876 printk("stli_writeroom(tty=%x)\n", (int) tty);
1877 #endif
1879 if (tty == (struct tty_struct *) NULL)
1880 return(0);
1881 if (tty == stli_txcooktty) {
1882 if (stli_txcookrealsize != 0) {
1883 len = stli_txcookrealsize - stli_txcooksize;
1884 return(len);
1888 portp = tty->driver_data;
1889 if (portp == (stliport_t *) NULL)
1890 return(0);
1891 if ((portp->brdnr < 0) || (portp->brdnr >= stli_nrbrds))
1892 return(0);
1893 brdp = stli_brds[portp->brdnr];
1894 if (brdp == (stlibrd_t *) NULL)
1895 return(0);
1897 save_flags(flags);
1898 cli();
1899 EBRDENABLE(brdp);
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);
1906 len--;
1907 EBRDDISABLE(brdp);
1908 restore_flags(flags);
1910 if (tty == stli_txcooktty) {
1911 stli_txcookrealsize = len;
1912 len -= stli_txcooksize;
1914 return(len);
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;
1930 stliport_t *portp;
1931 stlibrd_t *brdp;
1932 unsigned int head, tail, len;
1933 unsigned long flags;
1935 #if DEBUG
1936 printk("stli_charsinbuffer(tty=%x)\n", (int) tty);
1937 #endif
1939 if (tty == (struct tty_struct *) NULL)
1940 return(0);
1941 if (tty == stli_txcooktty)
1942 stli_flushchars(tty);
1943 portp = tty->driver_data;
1944 if (portp == (stliport_t *) NULL)
1945 return(0);
1946 if ((portp->brdnr < 0) || (portp->brdnr >= stli_nrbrds))
1947 return(0);
1948 brdp = stli_brds[portp->brdnr];
1949 if (brdp == (stlibrd_t *) NULL)
1950 return(0);
1952 save_flags(flags);
1953 cli();
1954 EBRDENABLE(brdp);
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))
1962 len = 1;
1963 EBRDDISABLE(brdp);
1964 restore_flags(flags);
1966 return(len);
1969 /*****************************************************************************/
1972 * Generate the serial struct info.
1975 static void stli_getserial(stliport_t *portp, struct serial_struct *sp)
1977 struct serial_struct sio;
1978 stlibrd_t *brdp;
1980 #if DEBUG
1981 printk("stli_getserial(portp=%x,sp=%x)\n", (int) portp, (int) sp);
1982 #endif
1984 memset(&sio, 0, sizeof(struct serial_struct));
1985 sio.type = PORT_UNKNOWN;
1986 sio.line = portp->portnr;
1987 sio.irq = 0;
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;
1994 sio.hub6 = 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;
2014 int rc;
2016 #if DEBUG
2017 printk("stli_setserial(portp=%x,sp=%x)\n", (int) portp, (int) sp);
2018 #endif
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)))
2026 return(-EPERM);
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)
2037 return(rc);
2038 return(0);
2041 /*****************************************************************************/
2043 static int stli_ioctl(struct tty_struct *tty, struct file *file, unsigned int cmd, unsigned long arg)
2045 stliport_t *portp;
2046 stlibrd_t *brdp;
2047 unsigned long lval;
2048 unsigned int ival;
2049 int rc;
2051 #if DEBUG
2052 printk("stli_ioctl(tty=%x,file=%x,cmd=%x,arg=%x)\n",
2053 (int) tty, (int) file, cmd, (int) arg);
2054 #endif
2056 if (tty == (struct tty_struct *) NULL)
2057 return(-ENODEV);
2058 portp = tty->driver_data;
2059 if (portp == (stliport_t *) NULL)
2060 return(-ENODEV);
2061 if ((portp->brdnr < 0) || (portp->brdnr >= stli_nrbrds))
2062 return(0);
2063 brdp = stli_brds[portp->brdnr];
2064 if (brdp == (stlibrd_t *) NULL)
2065 return(0);
2067 if ((cmd != TIOCGSERIAL) && (cmd != TIOCSSERIAL) &&
2068 (cmd != COM_GETPORTSTATS) && (cmd != COM_CLRPORTSTATS)) {
2069 if (tty->flags & (1 << TTY_IO_ERROR))
2070 return(-EIO);
2073 rc = 0;
2075 switch (cmd) {
2076 case TIOCGSOFTCAR:
2077 rc = put_user(((tty->termios->c_cflag & CLOCAL) ? 1 : 0),
2078 (unsigned int *) arg);
2079 break;
2080 case TIOCSSOFTCAR:
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);
2088 break;
2089 case TIOCMGET:
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)
2094 return(rc);
2095 lval = stli_mktiocm(portp->asig.sigvalue);
2096 put_user(lval, (unsigned int *) arg);
2098 break;
2099 case TIOCMBIS:
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);
2109 break;
2110 case TIOCMBIC:
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);
2120 break;
2121 case TIOCMSET:
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);
2131 break;
2132 case TIOCGSERIAL:
2133 if ((rc = verify_area(VERIFY_WRITE, (void *) arg,
2134 sizeof(struct serial_struct))) == 0)
2135 stli_getserial(portp, (struct serial_struct *) arg);
2136 break;
2137 case TIOCSSERIAL:
2138 if ((rc = verify_area(VERIFY_READ, (void *) arg,
2139 sizeof(struct serial_struct))) == 0)
2140 rc = stli_setserial(portp, (struct serial_struct *)arg);
2141 break;
2142 case STL_GETPFLAG:
2143 if ((rc = verify_area(VERIFY_WRITE, (void *) arg,
2144 sizeof(unsigned long))) == 0)
2145 put_user(portp->pflag, (unsigned int *) arg);
2146 break;
2147 case STL_SETPFLAG:
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);
2153 break;
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);
2158 break;
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);
2163 break;
2164 case TIOCSERCONFIG:
2165 case TIOCSERGWILD:
2166 case TIOCSERSWILD:
2167 case TIOCSERGETLSR:
2168 case TIOCSERGSTRUCT:
2169 case TIOCSERGETMULTI:
2170 case TIOCSERSETMULTI:
2171 default:
2172 rc = -ENOIOCTLCMD;
2173 break;
2176 return(rc);
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)
2188 stliport_t *portp;
2189 stlibrd_t *brdp;
2190 struct termios *tiosp;
2191 asyport_t aport;
2193 #if DEBUG
2194 printk("stli_settermios(tty=%x,old=%x)\n", (int) tty, (int) old);
2195 #endif
2197 if (tty == (struct tty_struct *) NULL)
2198 return;
2199 portp = tty->driver_data;
2200 if (portp == (stliport_t *) NULL)
2201 return;
2202 if ((portp->brdnr < 0) || (portp->brdnr >= stli_nrbrds))
2203 return;
2204 brdp = stli_brds[portp->brdnr];
2205 if (brdp == (stlibrd_t *) NULL)
2206 return;
2208 tiosp = tty->termios;
2209 if ((tiosp->c_cflag == old->c_cflag) &&
2210 (tiosp->c_iflag == old->c_iflag))
2211 return;
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)
2238 stliport_t *portp;
2240 #if DEBUG
2241 printk("stli_throttle(tty=%x)\n", (int) tty);
2242 #endif
2244 if (tty == (struct tty_struct *) NULL)
2245 return;
2246 portp = tty->driver_data;
2247 if (portp == (stliport_t *) NULL)
2248 return;
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)
2263 stliport_t *portp;
2265 #if DEBUG
2266 printk("stli_unthrottle(tty=%x)\n", (int) tty);
2267 #endif
2269 if (tty == (struct tty_struct *) NULL)
2270 return;
2271 portp = tty->driver_data;
2272 if (portp == (stliport_t *) NULL)
2273 return;
2275 clear_bit(ST_RXSTOP, &portp->state);
2278 /*****************************************************************************/
2281 * Stop the transmitter. Basically to do this we will just turn TX
2282 * interrupts off.
2285 static void stli_stop(struct tty_struct *tty)
2287 stlibrd_t *brdp;
2288 stliport_t *portp;
2289 asyctrl_t actrl;
2291 #if DEBUG
2292 printk("stli_stop(tty=%x)\n", (int) tty);
2293 #endif
2295 if (tty == (struct tty_struct *) NULL)
2296 return;
2297 portp = tty->driver_data;
2298 if (portp == (stliport_t *) NULL)
2299 return;
2300 if ((portp->brdnr < 0) || (portp->brdnr >= stli_nrbrds))
2301 return;
2302 brdp = stli_brds[portp->brdnr];
2303 if (brdp == (stlibrd_t *) NULL)
2304 return;
2306 memset(&actrl, 0, sizeof(asyctrl_t));
2307 actrl.txctrl = CT_STOPFLOW;
2308 #if 0
2309 stli_cmdwait(brdp, portp, A_PORTCTRL, &actrl, sizeof(asyctrl_t), 0);
2310 #endif
2313 /*****************************************************************************/
2316 * Start the transmitter again. Just turn TX interrupts back on.
2319 static void stli_start(struct tty_struct *tty)
2321 stliport_t *portp;
2322 stlibrd_t *brdp;
2323 asyctrl_t actrl;
2325 #if DEBUG
2326 printk("stli_start(tty=%x)\n", (int) tty);
2327 #endif
2329 if (tty == (struct tty_struct *) NULL)
2330 return;
2331 portp = tty->driver_data;
2332 if (portp == (stliport_t *) NULL)
2333 return;
2334 if ((portp->brdnr < 0) || (portp->brdnr >= stli_nrbrds))
2335 return;
2336 brdp = stli_brds[portp->brdnr];
2337 if (brdp == (stlibrd_t *) NULL)
2338 return;
2340 memset(&actrl, 0, sizeof(asyctrl_t));
2341 actrl.txctrl = CT_STARTFLOW;
2342 #if 0
2343 stli_cmdwait(brdp, portp, A_PORTCTRL, &actrl, sizeof(asyctrl_t), 0);
2344 #endif
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)
2360 stliport_t *portp;
2362 #if DEBUG
2363 printk("stli_dohangup(portp=%x)\n", (int) arg);
2364 #endif
2366 portp = (stliport_t *) arg;
2367 if (portp == (stliport_t *) NULL)
2368 return;
2369 if (portp->tty == (struct tty_struct *) NULL)
2370 return;
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)
2385 stliport_t *portp;
2386 stlibrd_t *brdp;
2387 unsigned long flags;
2389 #if DEBUG
2390 printk("stli_hangup(tty=%x)\n", (int) tty);
2391 #endif
2393 if (tty == (struct tty_struct *) NULL)
2394 return;
2395 portp = tty->driver_data;
2396 if (portp == (stliport_t *) NULL)
2397 return;
2398 if ((portp->brdnr < 0) || (portp->brdnr >= stli_nrbrds))
2399 return;
2400 brdp = stli_brds[portp->brdnr];
2401 if (brdp == (stlibrd_t *) NULL)
2402 return;
2404 portp->flags &= ~ASYNC_INITIALIZED;
2406 save_flags(flags);
2407 cli();
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);
2416 } else {
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
2438 * as well.
2441 static void stli_flushbuffer(struct tty_struct *tty)
2443 stliport_t *portp;
2444 stlibrd_t *brdp;
2445 unsigned long ftype, flags;
2447 #if DEBUG
2448 printk("stli_flushbuffer(tty=%x)\n", (int) tty);
2449 #endif
2451 if (tty == (struct tty_struct *) NULL)
2452 return;
2453 portp = tty->driver_data;
2454 if (portp == (stliport_t *) NULL)
2455 return;
2456 if ((portp->brdnr < 0) || (portp->brdnr >= stli_nrbrds))
2457 return;
2458 brdp = stli_brds[portp->brdnr];
2459 if (brdp == (stlibrd_t *) NULL)
2460 return;
2462 save_flags(flags);
2463 cli();
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);
2471 } else {
2472 ftype = FLUSHTX;
2473 if (test_bit(ST_DOFLUSHRX, &portp->state)) {
2474 ftype |= FLUSHRX;
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)
2492 stlibrd_t *brdp;
2493 stliport_t *portp;
2494 long arg;
2495 /* long savestate, savetime; */
2497 #if DEBUG
2498 printk("stli_breakctl(tty=%x,state=%d)\n", (int) tty, state);
2499 #endif
2501 if (tty == (struct tty_struct *) NULL)
2502 return;
2503 portp = tty->driver_data;
2504 if (portp == (stliport_t *) NULL)
2505 return;
2506 if ((portp->brdnr < 0) || (portp->brdnr >= stli_nrbrds))
2507 return;
2508 brdp = stli_brds[portp->brdnr];
2509 if (brdp == (stlibrd_t *) NULL)
2510 return;
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)
2533 stliport_t *portp;
2534 unsigned long tend;
2536 #if DEBUG
2537 printk("stli_waituntilsent(tty=%x,timeout=%x)\n", (int) tty, timeout);
2538 #endif
2540 if (tty == (struct tty_struct *) NULL)
2541 return;
2542 portp = tty->driver_data;
2543 if (portp == (stliport_t *) NULL)
2544 return;
2546 if (timeout == 0)
2547 timeout = HZ;
2548 tend = jiffies + timeout;
2550 while (test_bit(ST_TXBUSY, &portp->state)) {
2551 if (signal_pending(current))
2552 break;
2553 stli_delay(2);
2554 if (time_after_eq(jiffies, tend))
2555 break;
2559 /*****************************************************************************/
2561 static void stli_sendxchar(struct tty_struct *tty, char ch)
2563 stlibrd_t *brdp;
2564 stliport_t *portp;
2565 asyctrl_t actrl;
2567 #if DEBUG
2568 printk("stli_sendxchar(tty=%x,ch=%x)\n", (int) tty, ch);
2569 #endif
2571 if (tty == (struct tty_struct *) NULL)
2572 return;
2573 portp = tty->driver_data;
2574 if (portp == (stliport_t *) NULL)
2575 return;
2576 if ((portp->brdnr < 0) || (portp->brdnr >= stli_nrbrds))
2577 return;
2578 brdp = stli_brds[portp->brdnr];
2579 if (brdp == (stlibrd_t *) NULL)
2580 return;
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;
2587 } else {
2588 actrl.txctrl = CT_SENDCHR;
2589 actrl.tximdch = ch;
2592 stli_cmdwait(brdp, portp, A_PORTCTRL, &actrl, sizeof(asyctrl_t), 0);
2595 /*****************************************************************************/
2597 #define MAXLINE 80
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)
2607 char *sp, *uart;
2608 int rc, cnt;
2610 rc = stli_portcmdstats(portp);
2612 uart = "UNKNOWN";
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;
2621 sp = pos;
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" : "");
2647 *sp = ' ';
2648 sp += cnt;
2651 for (cnt = (sp - pos); (cnt < (MAXLINE - 1)); cnt++)
2652 *sp++ = ' ';
2653 if (cnt >= MAXLINE)
2654 pos[(MAXLINE - 2)] = '+';
2655 pos[(MAXLINE - 1)] = '\n';
2657 return(MAXLINE);
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)
2668 stlibrd_t *brdp;
2669 stliport_t *portp;
2670 int brdnr, portnr, totalport;
2671 int curoff, maxoff;
2672 char *pos;
2674 #if DEBUG
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);
2678 #endif
2680 pos = page;
2681 totalport = 0;
2682 curoff = 0;
2684 if (off == 0) {
2685 pos += sprintf(pos, "%s: version %s", stli_drvtitle,
2686 stli_drvversion);
2687 while (pos < (page + MAXLINE - 1))
2688 *pos++ = ' ';
2689 *pos++ = '\n';
2691 curoff = MAXLINE;
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)
2700 continue;
2701 if (brdp->state == 0)
2702 continue;
2704 maxoff = curoff + (brdp->nrports * MAXLINE);
2705 if (off >= maxoff) {
2706 curoff = maxoff;
2707 continue;
2710 totalport = brdnr * STL_MAXPORTS;
2711 for (portnr = 0; (portnr < brdp->nrports); portnr++,
2712 totalport++) {
2713 portp = brdp->ports[portnr];
2714 if (portp == (stliport_t *) NULL)
2715 continue;
2716 if (off >= (curoff += MAXLINE))
2717 continue;
2718 if ((pos - page + MAXLINE) > count)
2719 goto stli_readdone;
2720 pos += stli_portinfo(brdp, portp, totalport, pos);
2724 *eof = 1;
2726 stli_readdone:
2727 *start = page;
2728 return(pos - page);
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;
2750 #if DEBUG
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);
2754 #endif
2756 save_flags(flags);
2757 cli();
2759 if (test_bit(ST_CMDING, &portp->state)) {
2760 printk("STALLION: command already busy, cmd=%x!\n", (int) cmd);
2761 restore_flags(flags);
2762 return;
2765 EBRDENABLE(brdp);
2766 cp = &((volatile cdkasy_t *) EBRDGETMEMPTR(brdp, portp->addr))->ctrl;
2767 if (size > 0) {
2768 memcpy((void *) &(cp->args[0]), arg, size);
2769 if (copyback) {
2770 portp->argp = arg;
2771 portp->argsize = size;
2774 cp->status = 0;
2775 cp->cmd = cmd;
2776 hdrp = (volatile cdkhdr_t *) EBRDGETMEMPTR(brdp, CDK_CDKADDR);
2777 bits = ((volatile unsigned char *) hdrp) + brdp->slaveoffset +
2778 portp->portidx;
2779 *bits |= portp->portbit;
2780 set_bit(ST_CMDING, &portp->state);
2781 EBRDDISABLE(brdp);
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;
2803 #if DEBUG
2804 printk("stli_read(brdp=%x,portp=%d)\n", (int) brdp, (int) portp);
2805 #endif
2807 if (test_bit(ST_RXSTOP, &portp->state))
2808 return;
2809 tty = portp->tty;
2810 if (tty == (struct tty_struct *) NULL)
2811 return;
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;
2819 if (head >= tail) {
2820 len = head - tail;
2821 stlen = len;
2822 } else {
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);
2830 while (len > 0) {
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;
2838 len -= stlen;
2839 tail += stlen;
2840 if (tail >= size) {
2841 tail = 0;
2842 stlen = head;
2845 rp = &((volatile cdkasy_t *) EBRDGETMEMPTR(brdp, portp->addr))->rxq;
2846 rp->tail = tail;
2848 if (head != tail)
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)
2864 int cmd;
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;
2874 else
2875 cmd = A_SETSIGNALS;
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,
2880 sizeof(asysigs_t));
2881 cp->status = 0;
2882 cp->cmd = cmd;
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));
2891 cp->status = 0;
2892 cp->cmd = A_FLUSH;
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;
2915 asynotify_t nt;
2916 unsigned long oldsigs;
2917 int rc, donerx;
2919 #if DEBUG
2920 printk("stli_hostcmd(brdp=%x,channr=%d)\n", (int) brdp, channr);
2921 #endif
2923 ap = (volatile cdkasy_t *) EBRDGETMEMPTR(brdp, portp->addr);
2924 cp = &ap->ctrl;
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)) {
2932 if (rc > 0)
2933 rc--;
2934 cp->openarg = 0;
2935 portp->rc = rc;
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)) {
2947 if (rc > 0)
2948 rc--;
2949 cp->closearg = 0;
2950 portp->rc = rc;
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)) {
2961 rc = cp->status;
2962 if ((cp->cmd == 0) && (rc != 0)) {
2963 if (rc > 0)
2964 rc--;
2965 if (portp->argp != (void *) NULL) {
2966 memcpy(portp->argp, (void *) &(cp->args[0]),
2967 portp->argsize);
2968 portp->argp = (void *) NULL;
2970 cp->status = 0;
2971 portp->rc = rc;
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.
2983 donerx = 0;
2985 if (ap->notify) {
2986 nt = ap->changed;
2987 ap->notify = 0;
2988 tty = portp->tty;
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);
3016 EBRDENABLE(brdp);
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) {
3025 tty->flip.count++;
3026 *tty->flip.flag_buf_ptr++ = TTY_BREAK;
3027 *tty->flip.char_buf_ptr++ = 0;
3028 if (portp->flags & ASYNC_SAK) {
3029 do_SAK(tty);
3030 EBRDENABLE(brdp);
3032 tty_schedule_flip(tty);
3037 if (nt.data & DT_RXBUSY) {
3038 donerx++;
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)
3073 stliport_t *portp;
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),
3091 bitsize);
3093 memset(&slavebits[0], 0, bitsize);
3094 slavebitchange = 0;
3096 for (bitpos = 0; (bitpos < bitsize); bitpos++) {
3097 if (hostbits[bitpos] == 0)
3098 continue;
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)) {
3104 slavebitchange++;
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;
3140 stlibrd_t *brdp;
3141 int brdnr;
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)
3152 continue;
3153 if ((brdp->state & BST_STARTED) == 0)
3154 continue;
3156 EBRDENABLE(brdp);
3157 hdrp = (volatile cdkhdr_t *) EBRDGETMEMPTR(brdp, CDK_CDKADDR);
3158 if (hdrp->hostreq)
3159 stli_brdpoll(brdp, hdrp);
3160 EBRDDISABLE(brdp);
3164 /*****************************************************************************/
3167 * Translate the termios settings into the port setting structure of
3168 * the slave.
3171 static void stli_mkasyport(stliport_t *portp, asyport_t *pp, struct termios *tiosp)
3173 #if DEBUG
3174 printk("stli_mkasyport(portp=%x,pp=%x,tiosp=%d)\n",
3175 (int) portp, (int) pp, (int) tiosp);
3176 #endif
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;
3188 else
3189 pp->baudout += 15;
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) {
3209 case CS5:
3210 pp->csize = 5;
3211 break;
3212 case CS6:
3213 pp->csize = 6;
3214 break;
3215 case CS7:
3216 pp->csize = 7;
3217 break;
3218 default:
3219 pp->csize = 8;
3220 break;
3223 if (tiosp->c_cflag & CSTOPB)
3224 pp->stopbs = PT_STOP2;
3225 else
3226 pp->stopbs = PT_STOP1;
3228 if (tiosp->c_cflag & PARENB) {
3229 if (tiosp->c_cflag & PARODD)
3230 pp->parity = PT_ODDPARITY;
3231 else
3232 pp->parity = PT_EVENPARITY;
3233 } else {
3234 pp->parity = PT_NOPARITY;
3238 * Set up any flow control options enabled.
3240 if (tiosp->c_iflag & IXON) {
3241 pp->flow |= F_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
3257 * the data stream.
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;
3275 else
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)
3296 #if DEBUG
3297 printk("stli_mkasysigs(sp=%x,dtr=%d,rts=%d)\n", (int) sp, dtr, rts);
3298 #endif
3300 memset(sp, 0, sizeof(asysigs_t));
3301 if (dtr >= 0) {
3302 sp->signal |= SG_DTR;
3303 sp->sigvalue |= ((dtr > 0) ? SG_DTR : 0);
3305 if (rts >= 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)
3320 long tiocm;
3322 #if DEBUG
3323 printk("stli_mktiocm(sigvalue=%x)\n", (int) sigvalue);
3324 #endif
3326 tiocm = 0;
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);
3333 return(tiocm);
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)
3345 stliport_t *portp;
3346 int i, panelnr, panelport;
3348 #if DEBUG
3349 printk("stli_initports(brdp=%x)\n", (int) brdp);
3350 #endif
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");
3356 continue;
3359 memset(portp, 0, sizeof(stliport_t));
3360 portp->magic = STLI_PORTMAGIC;
3361 portp->portnr = i;
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;
3374 panelport++;
3375 if (panelport >= brdp->panels[panelnr]) {
3376 panelport = 0;
3377 panelnr++;
3379 brdp->ports[i] = portp;
3382 return(0);
3385 /*****************************************************************************/
3388 * All the following routines are board specific hardware operations.
3391 static void stli_ecpinit(stlibrd_t *brdp)
3393 unsigned long memconf;
3395 #if DEBUG
3396 printk("stli_ecpinit(brdp=%d)\n", (int) brdp);
3397 #endif
3399 outb(ECP_ATSTOP, (brdp->iobase + ECP_ATCONFR));
3400 udelay(10);
3401 outb(ECP_ATDISABLE, (brdp->iobase + ECP_ATCONFR));
3402 udelay(100);
3404 memconf = (brdp->memaddr & ECP_ATADDRMASK) >> ECP_ATADDRSHFT;
3405 outb(memconf, (brdp->iobase + ECP_ATMEMAR));
3408 /*****************************************************************************/
3410 static void stli_ecpenable(stlibrd_t *brdp)
3412 #if DEBUG
3413 printk("stli_ecpenable(brdp=%x)\n", (int) brdp);
3414 #endif
3415 outb(ECP_ATENABLE, (brdp->iobase + ECP_ATCONFR));
3418 /*****************************************************************************/
3420 static void stli_ecpdisable(stlibrd_t *brdp)
3422 #if DEBUG
3423 printk("stli_ecpdisable(brdp=%x)\n", (int) brdp);
3424 #endif
3425 outb(ECP_ATDISABLE, (brdp->iobase + ECP_ATCONFR));
3428 /*****************************************************************************/
3430 static char *stli_ecpgetmemptr(stlibrd_t *brdp, unsigned long offset, int line)
3432 void *ptr;
3433 unsigned char val;
3435 #if DEBUG
3436 printk("stli_ecpgetmemptr(brdp=%x,offset=%x)\n", (int) brdp,
3437 (int) offset);
3438 #endif
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);
3444 ptr = 0;
3445 val = 0;
3446 } else {
3447 ptr = brdp->membase + (offset % ECP_ATPAGESIZE);
3448 val = (unsigned char) (offset / ECP_ATPAGESIZE);
3450 outb(val, (brdp->iobase + ECP_ATMEMPR));
3451 return(ptr);
3454 /*****************************************************************************/
3456 static void stli_ecpreset(stlibrd_t *brdp)
3458 #if DEBUG
3459 printk("stli_ecpreset(brdp=%x)\n", (int) brdp);
3460 #endif
3462 outb(ECP_ATSTOP, (brdp->iobase + ECP_ATCONFR));
3463 udelay(10);
3464 outb(ECP_ATDISABLE, (brdp->iobase + ECP_ATCONFR));
3465 udelay(500);
3468 /*****************************************************************************/
3470 static void stli_ecpintr(stlibrd_t *brdp)
3472 #if DEBUG
3473 printk("stli_ecpintr(brdp=%x)\n", (int) brdp);
3474 #endif
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;
3488 #if DEBUG
3489 printk("stli_ecpeiinit(brdp=%x)\n", (int) brdp);
3490 #endif
3492 outb(0x1, (brdp->iobase + ECP_EIBRDENAB));
3493 outb(ECP_EISTOP, (brdp->iobase + ECP_EICONFR));
3494 udelay(10);
3495 outb(ECP_EIDISABLE, (brdp->iobase + ECP_EICONFR));
3496 udelay(500);
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)
3522 void *ptr;
3523 unsigned char val;
3525 #if DEBUG
3526 printk("stli_ecpeigetmemptr(brdp=%x,offset=%x,line=%d)\n",
3527 (int) brdp, (int) offset, line);
3528 #endif
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);
3534 ptr = 0;
3535 val = 0;
3536 } else {
3537 ptr = brdp->membase + (offset % ECP_EIPAGESIZE);
3538 if (offset < ECP_EIPAGESIZE)
3539 val = ECP_EIENABLE;
3540 else
3541 val = ECP_EIENABLE | 0x40;
3543 outb(val, (brdp->iobase + ECP_EICONFR));
3544 return(ptr);
3547 /*****************************************************************************/
3549 static void stli_ecpeireset(stlibrd_t *brdp)
3551 outb(ECP_EISTOP, (brdp->iobase + ECP_EICONFR));
3552 udelay(10);
3553 outb(ECP_EIDISABLE, (brdp->iobase + ECP_EICONFR));
3554 udelay(500);
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)
3579 void *ptr;
3580 unsigned char val;
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);
3586 ptr = 0;
3587 val = 0;
3588 } else {
3589 ptr = brdp->membase + (offset % ECP_MCPAGESIZE);
3590 val = ((unsigned char) (offset / ECP_MCPAGESIZE)) | ECP_MCENABLE;
3592 outb(val, (brdp->iobase + ECP_MCCONFR));
3593 return(ptr);
3596 /*****************************************************************************/
3598 static void stli_ecpmcreset(stlibrd_t *brdp)
3600 outb(ECP_MCSTOP, (brdp->iobase + ECP_MCCONFR));
3601 udelay(10);
3602 outb(ECP_MCDISABLE, (brdp->iobase + ECP_MCCONFR));
3603 udelay(500);
3606 /*****************************************************************************/
3609 * The following set of functions act on ECP PCI boards.
3612 static void stli_ecppciinit(stlibrd_t *brdp)
3614 #if DEBUG
3615 printk("stli_ecppciinit(brdp=%x)\n", (int) brdp);
3616 #endif
3618 outb(ECP_PCISTOP, (brdp->iobase + ECP_PCICONFR));
3619 udelay(10);
3620 outb(0, (brdp->iobase + ECP_PCICONFR));
3621 udelay(500);
3624 /*****************************************************************************/
3626 static char *stli_ecppcigetmemptr(stlibrd_t *brdp, unsigned long offset, int line)
3628 void *ptr;
3629 unsigned char val;
3631 #if DEBUG
3632 printk("stli_ecppcigetmemptr(brdp=%x,offset=%x,line=%d)\n",
3633 (int) brdp, (int) offset, line);
3634 #endif
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);
3640 ptr = 0;
3641 val = 0;
3642 } else {
3643 ptr = brdp->membase + (offset % ECP_PCIPAGESIZE);
3644 val = (offset / ECP_PCIPAGESIZE) << 1;
3646 outb(val, (brdp->iobase + ECP_PCICONFR));
3647 return(ptr);
3650 /*****************************************************************************/
3652 static void stli_ecppcireset(stlibrd_t *brdp)
3654 outb(ECP_PCISTOP, (brdp->iobase + ECP_PCICONFR));
3655 udelay(10);
3656 outb(0, (brdp->iobase + ECP_PCICONFR));
3657 udelay(500);
3660 /*****************************************************************************/
3663 * The following routines act on ONboards.
3666 static void stli_onbinit(stlibrd_t *brdp)
3668 unsigned long memconf;
3670 #if DEBUG
3671 printk("stli_onbinit(brdp=%d)\n", (int) brdp);
3672 #endif
3674 outb(ONB_ATSTOP, (brdp->iobase + ONB_ATCONFR));
3675 udelay(10);
3676 outb(ONB_ATDISABLE, (brdp->iobase + ONB_ATCONFR));
3677 mdelay(1000);
3679 memconf = (brdp->memaddr & ONB_ATADDRMASK) >> ONB_ATADDRSHFT;
3680 outb(memconf, (brdp->iobase + ONB_ATMEMAR));
3681 outb(0x1, brdp->iobase);
3682 mdelay(1);
3685 /*****************************************************************************/
3687 static void stli_onbenable(stlibrd_t *brdp)
3689 #if DEBUG
3690 printk("stli_onbenable(brdp=%x)\n", (int) brdp);
3691 #endif
3692 outb((brdp->enabval | ONB_ATENABLE), (brdp->iobase + ONB_ATCONFR));
3695 /*****************************************************************************/
3697 static void stli_onbdisable(stlibrd_t *brdp)
3699 #if DEBUG
3700 printk("stli_onbdisable(brdp=%x)\n", (int) brdp);
3701 #endif
3702 outb((brdp->enabval | ONB_ATDISABLE), (brdp->iobase + ONB_ATCONFR));
3705 /*****************************************************************************/
3707 static char *stli_onbgetmemptr(stlibrd_t *brdp, unsigned long offset, int line)
3709 void *ptr;
3711 #if DEBUG
3712 printk("stli_onbgetmemptr(brdp=%x,offset=%x)\n", (int) brdp,
3713 (int) offset);
3714 #endif
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);
3720 ptr = 0;
3721 } else {
3722 ptr = brdp->membase + (offset % ONB_ATPAGESIZE);
3724 return(ptr);
3727 /*****************************************************************************/
3729 static void stli_onbreset(stlibrd_t *brdp)
3732 #if DEBUG
3733 printk("stli_onbreset(brdp=%x)\n", (int) brdp);
3734 #endif
3736 outb(ONB_ATSTOP, (brdp->iobase + ONB_ATCONFR));
3737 udelay(10);
3738 outb(ONB_ATDISABLE, (brdp->iobase + ONB_ATCONFR));
3739 mdelay(1000);
3742 /*****************************************************************************/
3745 * The following routines act on ONboard EISA.
3748 static void stli_onbeinit(stlibrd_t *brdp)
3750 unsigned long memconf;
3752 #if DEBUG
3753 printk("stli_onbeinit(brdp=%d)\n", (int) brdp);
3754 #endif
3756 outb(0x1, (brdp->iobase + ONB_EIBRDENAB));
3757 outb(ONB_EISTOP, (brdp->iobase + ONB_EICONFR));
3758 udelay(10);
3759 outb(ONB_EIDISABLE, (brdp->iobase + ONB_EICONFR));
3760 mdelay(1000);
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);
3767 mdelay(1);
3770 /*****************************************************************************/
3772 static void stli_onbeenable(stlibrd_t *brdp)
3774 #if DEBUG
3775 printk("stli_onbeenable(brdp=%x)\n", (int) brdp);
3776 #endif
3777 outb(ONB_EIENABLE, (brdp->iobase + ONB_EICONFR));
3780 /*****************************************************************************/
3782 static void stli_onbedisable(stlibrd_t *brdp)
3784 #if DEBUG
3785 printk("stli_onbedisable(brdp=%x)\n", (int) brdp);
3786 #endif
3787 outb(ONB_EIDISABLE, (brdp->iobase + ONB_EICONFR));
3790 /*****************************************************************************/
3792 static char *stli_onbegetmemptr(stlibrd_t *brdp, unsigned long offset, int line)
3794 void *ptr;
3795 unsigned char val;
3797 #if DEBUG
3798 printk("stli_onbegetmemptr(brdp=%x,offset=%x,line=%d)\n",
3799 (int) brdp, (int) offset, line);
3800 #endif
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);
3806 ptr = 0;
3807 val = 0;
3808 } else {
3809 ptr = brdp->membase + (offset % ONB_EIPAGESIZE);
3810 if (offset < ONB_EIPAGESIZE)
3811 val = ONB_EIENABLE;
3812 else
3813 val = ONB_EIENABLE | 0x40;
3815 outb(val, (brdp->iobase + ONB_EICONFR));
3816 return(ptr);
3819 /*****************************************************************************/
3821 static void stli_onbereset(stlibrd_t *brdp)
3824 #if DEBUG
3825 printk("stli_onbereset(brdp=%x)\n", (int) brdp);
3826 #endif
3828 outb(ONB_EISTOP, (brdp->iobase + ONB_EICONFR));
3829 udelay(10);
3830 outb(ONB_EIDISABLE, (brdp->iobase + ONB_EICONFR));
3831 mdelay(1000);
3834 /*****************************************************************************/
3837 * The following routines act on Brumby boards.
3840 static void stli_bbyinit(stlibrd_t *brdp)
3843 #if DEBUG
3844 printk("stli_bbyinit(brdp=%d)\n", (int) brdp);
3845 #endif
3847 outb(BBY_ATSTOP, (brdp->iobase + BBY_ATCONFR));
3848 udelay(10);
3849 outb(0, (brdp->iobase + BBY_ATCONFR));
3850 mdelay(1000);
3851 outb(0x1, brdp->iobase);
3852 mdelay(1);
3855 /*****************************************************************************/
3857 static char *stli_bbygetmemptr(stlibrd_t *brdp, unsigned long offset, int line)
3859 void *ptr;
3860 unsigned char val;
3862 #if DEBUG
3863 printk("stli_bbygetmemptr(brdp=%x,offset=%x)\n", (int) brdp,
3864 (int) offset);
3865 #endif
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);
3871 ptr = 0;
3872 val = 0;
3873 } else {
3874 ptr = brdp->membase + (offset % BBY_PAGESIZE);
3875 val = (unsigned char) (offset / BBY_PAGESIZE);
3877 outb(val, (brdp->iobase + BBY_ATCONFR));
3878 return(ptr);
3881 /*****************************************************************************/
3883 static void stli_bbyreset(stlibrd_t *brdp)
3886 #if DEBUG
3887 printk("stli_bbyreset(brdp=%x)\n", (int) brdp);
3888 #endif
3890 outb(BBY_ATSTOP, (brdp->iobase + BBY_ATCONFR));
3891 udelay(10);
3892 outb(0, (brdp->iobase + BBY_ATCONFR));
3893 mdelay(1000);
3896 /*****************************************************************************/
3899 * The following routines act on original old Stallion boards.
3902 static void stli_stalinit(stlibrd_t *brdp)
3905 #if DEBUG
3906 printk("stli_stalinit(brdp=%d)\n", (int) brdp);
3907 #endif
3909 outb(0x1, brdp->iobase);
3910 mdelay(1000);
3913 /*****************************************************************************/
3915 static char *stli_stalgetmemptr(stlibrd_t *brdp, unsigned long offset, int line)
3917 void *ptr;
3919 #if DEBUG
3920 printk("stli_stalgetmemptr(brdp=%x,offset=%x)\n", (int) brdp,
3921 (int) offset);
3922 #endif
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);
3928 ptr = 0;
3929 } else {
3930 ptr = brdp->membase + (offset % STAL_PAGESIZE);
3932 return(ptr);
3935 /*****************************************************************************/
3937 static void stli_stalreset(stlibrd_t *brdp)
3939 volatile unsigned long *vecp;
3941 #if DEBUG
3942 printk("stli_stalreset(brdp=%x)\n", (int) brdp);
3943 #endif
3945 vecp = (volatile unsigned long *) (brdp->membase + 0x30);
3946 *vecp = 0xffff0000;
3947 outb(0, brdp->iobase);
3948 mdelay(1000);
3951 /*****************************************************************************/
3954 * Try to find an ECP board and initialize it. This handles only ECP
3955 * board types.
3958 static inline int stli_initecp(stlibrd_t *brdp)
3960 cdkecpsig_t sig;
3961 cdkecpsig_t *sigsp;
3962 unsigned int status, nxtid;
3963 char *name;
3964 int panelnr, nrports;
3966 #if DEBUG
3967 printk("stli_initecp(brdp=%x)\n", (int) brdp);
3968 #endif
3971 * Do a basic sanity check on the IO and memory addresses.
3973 if ((brdp->iobase == 0) || (brdp->memaddr == 0))
3974 return(-ENODEV);
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
3984 * as well.
3986 switch (brdp->brdtype) {
3987 case BRD_ECP:
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)";
3999 break;
4001 case BRD_ECPE:
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)";
4013 break;
4015 case BRD_ECPMC:
4016 brdp->membase = (void *) brdp->memaddr;
4017 brdp->memsize = ECP_MEMSIZE;
4018 brdp->pagesize = ECP_MCPAGESIZE;
4019 brdp->init = NULL;
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)";
4027 break;
4029 case BRD_ECPPCI:
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)";
4041 break;
4043 default:
4044 return(-EINVAL);
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
4051 * shared memory.
4053 EBRDINIT(brdp);
4055 brdp->membase = ioremap(brdp->memaddr, brdp->memsize);
4056 if (brdp->membase == (void *) NULL)
4057 return(-ENOMEM);
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.
4064 EBRDENABLE(brdp);
4065 sigsp = (cdkecpsig_t *) EBRDGETMEMPTR(brdp, CDK_SIGADDR);
4066 memcpy(&sig, sigsp, sizeof(cdkecpsig_t));
4067 EBRDDISABLE(brdp);
4069 #if 0
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]);
4076 #endif
4078 if (sig.magic != ECP_MAGIC)
4079 return(-ENODEV);
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)
4088 break;
4090 brdp->panelids[panelnr] = status;
4091 nrports = (status & ECH_PNL16PORT) ? 16 : 8;
4092 if ((nrports == 16) && ((status & ECH_PNLXPID) == 0))
4093 nxtid++;
4094 brdp->panels[panelnr] = nrports;
4095 brdp->nrports += nrports;
4096 nxtid++;
4097 brdp->nrpanels++;
4100 request_region(brdp->iobase, brdp->iosize, name);
4101 brdp->state |= BST_FOUND;
4102 return(0);
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)
4114 cdkonbsig_t sig;
4115 cdkonbsig_t *sigsp;
4116 char *name;
4117 int i;
4119 #if DEBUG
4120 printk("stli_initonb(brdp=%x)\n", (int) brdp);
4121 #endif
4124 * Do a basic sanity check on the IO and memory addresses.
4126 if ((brdp->iobase == 0) || (brdp->memaddr == 0))
4127 return(-ENODEV);
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
4137 * as well.
4139 switch (brdp->brdtype) {
4140 case BRD_ONBOARD:
4141 case BRD_ONBOARD32:
4142 case BRD_ONBOARD2:
4143 case BRD_ONBOARD2_32:
4144 case BRD_ONBOARDRS:
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;
4157 else
4158 brdp->enabval = ONB_MEMENABLO;
4159 name = "serial(ONBoard)";
4160 break;
4162 case BRD_ONBOARDE:
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)";
4174 break;
4176 case BRD_BRUMBY4:
4177 case BRD_BRUMBY8:
4178 case BRD_BRUMBY16:
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)";
4190 break;
4192 case BRD_STALLION:
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)";
4204 break;
4206 default:
4207 return(-EINVAL);
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
4214 * shared memory.
4216 EBRDINIT(brdp);
4218 brdp->membase = ioremap(brdp->memaddr, brdp->memsize);
4219 if (brdp->membase == (void *) NULL)
4220 return(-ENOMEM);
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.
4227 EBRDENABLE(brdp);
4228 sigsp = (cdkonbsig_t *) EBRDGETMEMPTR(brdp, CDK_SIGADDR);
4229 memcpy(&sig, sigsp, sizeof(cdkonbsig_t));
4230 EBRDDISABLE(brdp);
4232 #if 0
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);
4236 #endif
4238 if ((sig.magic0 != ONB_MAGIC0) || (sig.magic1 != ONB_MAGIC1) ||
4239 (sig.magic2 != ONB_MAGIC2) || (sig.magic3 != ONB_MAGIC3))
4240 return(-ENODEV);
4243 * Scan through the signature alive mask and calculate how many ports
4244 * there are on this board.
4246 brdp->nrpanels = 1;
4247 if (sig.amask1) {
4248 brdp->nrports = 32;
4249 } else {
4250 for (i = 0; (i < 16); i++) {
4251 if (((sig.amask0 << i) & 0x8000) == 0)
4252 break;
4254 brdp->nrports = i;
4256 brdp->panels[0] = brdp->nrports;
4258 request_region(brdp->iobase, brdp->iosize, name);
4259 brdp->state |= BST_FOUND;
4260 return(0);
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;
4277 stliport_t *portp;
4278 int portnr, nrdevs, i, rc;
4280 #if DEBUG
4281 printk("stli_startbrd(brdp=%x)\n", (int) brdp);
4282 #endif
4284 rc = 0;
4286 save_flags(flags);
4287 cli();
4288 EBRDENABLE(brdp);
4289 hdrp = (volatile cdkhdr_t *) EBRDGETMEMPTR(brdp, CDK_CDKADDR);
4290 nrdevs = hdrp->nrdevs;
4292 #if 0
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);
4298 #endif
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");
4312 rc = -EIO;
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;
4320 memp++;
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)
4329 break;
4330 portp = brdp->ports[portnr];
4331 if (portp == (stliport_t *) NULL)
4332 break;
4333 portp->devnr = i;
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)
4350 break;
4351 if (portp->addr == 0)
4352 break;
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;
4362 stli_donestartup:
4363 EBRDDISABLE(brdp);
4364 restore_flags(flags);
4366 if (rc == 0)
4367 brdp->state |= BST_STARTED;
4369 if (! stli_timeron) {
4370 stli_timeron++;
4371 stli_timerlist.expires = STLI_TIMEOUT;
4372 add_timer(&stli_timerlist);
4375 return(rc);
4378 /*****************************************************************************/
4381 * Probe and initialize the specified board.
4384 static int __init stli_brdinit(stlibrd_t *brdp)
4386 #if DEBUG
4387 printk("stli_brdinit(brdp=%x)\n", (int) brdp);
4388 #endif
4390 stli_brds[brdp->brdnr] = brdp;
4392 switch (brdp->brdtype) {
4393 case BRD_ECP:
4394 case BRD_ECPE:
4395 case BRD_ECPMC:
4396 case BRD_ECPPCI:
4397 stli_initecp(brdp);
4398 break;
4399 case BRD_ONBOARD:
4400 case BRD_ONBOARDE:
4401 case BRD_ONBOARD2:
4402 case BRD_ONBOARD32:
4403 case BRD_ONBOARD2_32:
4404 case BRD_ONBOARDRS:
4405 case BRD_BRUMBY4:
4406 case BRD_BRUMBY8:
4407 case BRD_BRUMBY16:
4408 case BRD_STALLION:
4409 stli_initonb(brdp);
4410 break;
4411 case BRD_EASYIO:
4412 case BRD_ECH:
4413 case BRD_ECHMC:
4414 case BRD_ECHPCI:
4415 printk("STALLION: %s board type not supported in this driver\n",
4416 stli_brdnames[brdp->brdtype]);
4417 return(ENODEV);
4418 default:
4419 printk("STALLION: board=%d is unknown board type=%d\n",
4420 brdp->brdnr, brdp->brdtype);
4421 return(ENODEV);
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);
4428 return(ENODEV);
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);
4436 return(0);
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;
4450 int i, foundit;
4452 #if DEBUG
4453 printk("stli_eisamemprobe(brdp=%x)\n", (int) brdp);
4454 #endif
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));
4465 udelay(10);
4466 outb(ECP_EIDISABLE, (brdp->iobase + ECP_EICONFR));
4467 udelay(500);
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));
4472 udelay(10);
4473 outb(ONB_EIDISABLE, (brdp->iobase + ONB_EICONFR));
4474 mdelay(100);
4475 outb(0x1, brdp->iobase);
4476 mdelay(1);
4477 stli_onbeenable(brdp);
4478 } else {
4479 return(-ENODEV);
4482 foundit = 0;
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)
4494 continue;
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)
4501 foundit = 1;
4502 } else {
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))
4510 foundit = 1;
4513 iounmap(brdp->membase);
4514 if (foundit)
4515 break;
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);
4524 else
4525 stli_onbedisable(brdp);
4527 if (! foundit) {
4528 brdp->memaddr = 0;
4529 brdp->membase = 0;
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));
4533 return(-ENODEV);
4535 return(0);
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()
4552 stlibrd_t *brdp;
4553 unsigned int iobase, eid;
4554 int i;
4556 #if DEBUG
4557 printk("stli_findeisabrds()\n");
4558 #endif
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!
4565 outb(0xff, 0xc80);
4566 if (inb(0xc80) == 0xff)
4567 return(0);
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)
4577 continue;
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)
4586 continue;
4587 if (brdp->iobase == iobase)
4588 break;
4590 if (i < STL_MAXBRDS)
4591 continue;
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)
4598 return(-ENOMEM);
4599 if ((brdp->brdnr = stli_getbrdnr()) < 0)
4600 return(-ENOMEM);
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;
4606 else
4607 brdp->brdtype = BRD_UNKNOWN;
4608 brdp->iobase = iobase;
4609 outb(0x1, (iobase + 0xc84));
4610 if (stli_eisamemprobe(brdp))
4611 outb(0, (iobase + 0xc84));
4612 stli_brdinit(brdp);
4615 return(0);
4618 /*****************************************************************************/
4621 * Find the next available board number that is free.
4624 static inline int stli_getbrdnr()
4626 int i;
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;
4632 return(i);
4635 return(-1);
4638 /*****************************************************************************/
4640 #ifdef CONFIG_PCI
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)
4650 stlibrd_t *brdp;
4652 #if DEBUG
4653 printk("stli_initpcibrd(brdtype=%d,busnr=%x,devnr=%x)\n", brdtype,
4654 dev->bus->number, dev->devfn);
4655 #endif
4657 if (pci_enable_device(devp))
4658 return(-EIO);
4659 if ((brdp = stli_allocbrd()) == (stlibrd_t *) NULL)
4660 return(-ENOMEM);
4661 if ((brdp->brdnr = stli_getbrdnr()) < 0) {
4662 printk("STALLION: too many boards found, "
4663 "maximum supported %d\n", STL_MAXBRDS);
4664 return(0);
4666 brdp->brdtype = brdtype;
4668 #if DEBUG
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));
4674 #endif
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);
4682 stli_brdinit(brdp);
4684 return(0);
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;
4697 int rc;
4699 #if DEBUG
4700 printk("stli_findpcibrds()\n");
4701 #endif
4703 if (! pci_present())
4704 return(0);
4706 while ((dev = pci_find_device(PCI_VENDOR_ID_STALLION,
4707 PCI_DEVICE_ID_ECRA, dev))) {
4708 if ((rc = stli_initpcibrd(BRD_ECPPCI, dev)))
4709 return(rc);
4712 return(0);
4715 #endif
4717 /*****************************************************************************/
4720 * Allocate a new board structure. Fill out the basic info in it.
4723 static stlibrd_t *stli_allocbrd()
4725 stlibrd_t *brdp;
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",
4730 sizeof(stlibrd_t));
4731 return((stlibrd_t *) NULL);
4734 memset(brdp, 0, sizeof(stlibrd_t));
4735 brdp->magic = STLI_BOARDMAGIC;
4736 return(brdp);
4739 /*****************************************************************************/
4742 * Scan through all the boards in the configuration and see what we
4743 * can find.
4746 static inline int stli_initbrds()
4748 stlibrd_t *brdp, *nxtbrdp;
4749 stlconf_t *confp;
4750 int i, j;
4752 #if DEBUG
4753 printk("stli_initbrds()\n");
4754 #endif
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];
4769 #ifdef MODULE
4770 stli_parsebrd(confp, stli_brdsp[i]);
4771 #endif
4772 if ((brdp = stli_allocbrd()) == (stlibrd_t *) NULL)
4773 return(-ENOMEM);
4774 brdp->brdnr = i;
4775 brdp->brdtype = confp->brdtype;
4776 brdp->iobase = confp->ioaddr1;
4777 brdp->memaddr = confp->memaddr;
4778 stli_brdinit(brdp);
4782 * Static configuration table done, so now use dynamic methods to
4783 * see if any more boards should be configured.
4785 #ifdef MODULE
4786 stli_argbrds();
4787 #endif
4788 if (stli_eisaprobe)
4789 stli_findeisabrds();
4790 #ifdef CONFIG_PCI
4791 stli_findpcibrds();
4792 #endif
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.
4799 stli_shared = 0;
4800 if (stli_nrbrds > 1) {
4801 for (i = 0; (i < stli_nrbrds); i++) {
4802 brdp = stli_brds[i];
4803 if (brdp == (stlibrd_t *) NULL)
4804 continue;
4805 for (j = i + 1; (j < stli_nrbrds); j++) {
4806 nxtbrdp = stli_brds[j];
4807 if (nxtbrdp == (stlibrd_t *) NULL)
4808 continue;
4809 if ((brdp->membase >= nxtbrdp->membase) &&
4810 (brdp->membase <= (nxtbrdp->membase +
4811 nxtbrdp->memsize - 1))) {
4812 stli_shared++;
4813 break;
4819 if (stli_shared == 0) {
4820 for (i = 0; (i < stli_nrbrds); i++) {
4821 brdp = stli_brds[i];
4822 if (brdp == (stlibrd_t *) NULL)
4823 continue;
4824 if (brdp->state & BST_FOUND) {
4825 EBRDENABLE(brdp);
4826 brdp->enable = NULL;
4827 brdp->disable = NULL;
4832 return(0);
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;
4846 void *memptr;
4847 stlibrd_t *brdp;
4848 int brdnr, size, n;
4850 #if DEBUG
4851 printk("stli_memread(fp=%x,buf=%x,count=%x,offp=%x)\n", (int) fp,
4852 (int) buf, count, (int) offp);
4853 #endif
4855 brdnr = MINOR(fp->f_dentry->d_inode->i_rdev);
4856 if (brdnr >= stli_nrbrds)
4857 return(-ENODEV);
4858 brdp = stli_brds[brdnr];
4859 if (brdp == (stlibrd_t *) NULL)
4860 return(-ENODEV);
4861 if (brdp->state == 0)
4862 return(-ENODEV);
4863 if (fp->f_pos >= brdp->memsize)
4864 return(0);
4866 size = MIN(count, (brdp->memsize - fp->f_pos));
4868 save_flags(flags);
4869 cli();
4870 EBRDENABLE(brdp);
4871 while (size > 0) {
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);
4875 fp->f_pos += n;
4876 buf += n;
4877 size -= n;
4879 EBRDDISABLE(brdp);
4880 restore_flags(flags);
4882 return(count);
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;
4896 void *memptr;
4897 stlibrd_t *brdp;
4898 char *chbuf;
4899 int brdnr, size, n;
4901 #if DEBUG
4902 printk("stli_memwrite(fp=%x,buf=%x,count=%x,offp=%x)\n", (int) fp,
4903 (int) buf, count, (int) offp);
4904 #endif
4906 brdnr = MINOR(fp->f_dentry->d_inode->i_rdev);
4907 if (brdnr >= stli_nrbrds)
4908 return(-ENODEV);
4909 brdp = stli_brds[brdnr];
4910 if (brdp == (stlibrd_t *) NULL)
4911 return(-ENODEV);
4912 if (brdp->state == 0)
4913 return(-ENODEV);
4914 if (fp->f_pos >= brdp->memsize)
4915 return(0);
4917 chbuf = (char *) buf;
4918 size = MIN(count, (brdp->memsize - fp->f_pos));
4920 save_flags(flags);
4921 cli();
4922 EBRDENABLE(brdp);
4923 while (size > 0) {
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);
4927 fp->f_pos += n;
4928 chbuf += n;
4929 size -= n;
4931 EBRDDISABLE(brdp);
4932 restore_flags(flags);
4934 return(count);
4937 /*****************************************************************************/
4940 * Return the board stats structure to user app.
4943 static int stli_getbrdstats(combrd_t *bp)
4945 stlibrd_t *brdp;
4946 int i;
4948 copy_from_user(&stli_brdstats, bp, sizeof(combrd_t));
4949 if (stli_brdstats.brd >= STL_MAXBRDS)
4950 return(-ENODEV);
4951 brdp = stli_brds[stli_brdstats.brd];
4952 if (brdp == (stlibrd_t *) NULL)
4953 return(-ENODEV);
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));
4971 return(0);
4974 /*****************************************************************************/
4977 * Resolve the referenced port number into a port struct pointer.
4980 static stliport_t *stli_getport(int brdnr, int panelnr, int portnr)
4982 stlibrd_t *brdp;
4983 int i;
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;
5008 stlibrd_t *brdp;
5009 int rc;
5011 memset(&stli_comstats, 0, sizeof(comstats_t));
5013 if (portp == (stliport_t *) NULL)
5014 return(-ENODEV);
5015 brdp = stli_brds[portp->brdnr];
5016 if (brdp == (stlibrd_t *) NULL)
5017 return(-ENODEV);
5019 if (brdp->state & BST_STARTED) {
5020 if ((rc = stli_cmdwait(brdp, portp, A_GETSTATS,
5021 &stli_cdkstats, sizeof(asystats_t), 1)) < 0)
5022 return(rc);
5023 } else {
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;
5033 save_flags(flags);
5034 cli();
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);
5069 return(0);
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)
5082 stlibrd_t *brdp;
5083 int rc;
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)
5090 return(-ENODEV);
5093 brdp = stli_brds[portp->brdnr];
5094 if (brdp == (stlibrd_t *) NULL)
5095 return(-ENODEV);
5097 if ((rc = stli_portcmdstats(portp)) < 0)
5098 return(rc);
5100 copy_to_user(cp, &stli_comstats, sizeof(comstats_t));
5101 return(0);
5104 /*****************************************************************************/
5107 * Clear the port stats structure. We also return it zeroed out...
5110 static int stli_clrportstats(stliport_t *portp, comstats_t *cp)
5112 stlibrd_t *brdp;
5113 int rc;
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)
5120 return(-ENODEV);
5123 brdp = stli_brds[portp->brdnr];
5124 if (brdp == (stlibrd_t *) NULL)
5125 return(-ENODEV);
5127 if (brdp->state & BST_STARTED) {
5128 if ((rc = stli_cmdwait(brdp, portp, A_CLEARSTATS, 0, 0, 0)) < 0)
5129 return(rc);
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));
5138 return(0);
5141 /*****************************************************************************/
5144 * Return the entire driver ports structure to a user app.
5147 static int stli_getportstruct(unsigned long arg)
5149 stliport_t *portp;
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)
5155 return(-ENODEV);
5156 copy_to_user((void *) arg, portp, sizeof(stliport_t));
5157 return(0);
5160 /*****************************************************************************/
5163 * Return the entire driver board structure to a user app.
5166 static int stli_getbrdstruct(unsigned long arg)
5168 stlibrd_t *brdp;
5170 copy_from_user(&stli_dummybrd, (void *) arg, sizeof(stlibrd_t));
5171 if ((stli_dummybrd.brdnr < 0) || (stli_dummybrd.brdnr >= STL_MAXBRDS))
5172 return(-ENODEV);
5173 brdp = stli_brds[stli_dummybrd.brdnr];
5174 if (brdp == (stlibrd_t *) NULL)
5175 return(-ENODEV);
5176 copy_to_user((void *) arg, brdp, sizeof(stlibrd_t));
5177 return(0);
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)
5190 stlibrd_t *brdp;
5191 int brdnr, rc, done;
5193 #if DEBUG
5194 printk("stli_memioctl(ip=%x,fp=%x,cmd=%x,arg=%x)\n", (int) ip,
5195 (int) fp, cmd, (int) arg);
5196 #endif
5199 * First up handle the board independent ioctls.
5201 done = 0;
5202 rc = 0;
5204 switch (cmd) {
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);
5210 done++;
5211 break;
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);
5217 done++;
5218 break;
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);
5223 done++;
5224 break;
5225 case COM_READPORT:
5226 if ((rc = verify_area(VERIFY_WRITE, (void *) arg,
5227 sizeof(stliport_t))) == 0)
5228 rc = stli_getportstruct(arg);
5229 done++;
5230 break;
5231 case COM_READBOARD:
5232 if ((rc = verify_area(VERIFY_WRITE, (void *) arg,
5233 sizeof(stlibrd_t))) == 0)
5234 rc = stli_getbrdstruct(arg);
5235 done++;
5236 break;
5237 default:
5238 break;
5241 if (done)
5242 return(rc);
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)
5250 return(-ENODEV);
5251 brdp = stli_brds[brdnr];
5252 if (brdp == (stlibrd_t *) NULL)
5253 return(-ENODEV);
5254 if (brdp->state == 0)
5255 return(-ENODEV);
5257 switch (cmd) {
5258 case STL_BINTR:
5259 EBRDINTR(brdp);
5260 break;
5261 case STL_BSTART:
5262 rc = stli_startbrd(brdp);
5263 break;
5264 case STL_BSTOP:
5265 brdp->state &= ~BST_STARTED;
5266 break;
5267 case STL_BRESET:
5268 brdp->state &= ~BST_STARTED;
5269 EBRDRESET(brdp);
5270 if (stli_shared == 0) {
5271 if (brdp->reenable != NULL)
5272 (* brdp->reenable)(brdp);
5274 break;
5275 default:
5276 rc = -ENOIOCTLCMD;
5277 break;
5280 return(rc);
5283 /*****************************************************************************/
5285 int __init stli_init(void)
5287 printk(KERN_INFO "%s: version %s\n", stli_drvtitle, stli_drvversion);
5289 stli_initbrds();
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",
5297 STLI_TXBUFSIZE);
5298 stli_txcookbuf = (char *) stli_memalloc(STLI_TXBUFSIZE);
5299 if (stli_txcookbuf == (char *) NULL)
5300 printk("STALLION: failed to allocate memory (size=%d)\n",
5301 STLI_TXBUFSIZE);
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,
5312 STL_SIOMEMMAJOR, 0,
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");
5367 return(0);
5370 /*****************************************************************************/