[PATCH] Fix up 'linux-dvb' maintainers entry
[linux-2.6/history.git] / drivers / char / istallion.c
blob9bfce6ec3dee656596609d96660f30c885107187
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/slab.h>
32 #include <linux/interrupt.h>
33 #include <linux/tty.h>
34 #include <linux/tty_flip.h>
35 #include <linux/serial.h>
36 #include <linux/cdk.h>
37 #include <linux/comstats.h>
38 #include <linux/istallion.h>
39 #include <linux/ioport.h>
40 #include <linux/delay.h>
41 #include <linux/init.h>
42 #include <linux/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 /*****************************************************************************/
148 * Define some important driver characteristics. Device major numbers
149 * allocated as per Linux Device Registry.
151 #ifndef STL_SIOMEMMAJOR
152 #define STL_SIOMEMMAJOR 28
153 #endif
154 #ifndef STL_SERIALMAJOR
155 #define STL_SERIALMAJOR 24
156 #endif
157 #ifndef STL_CALLOUTMAJOR
158 #define STL_CALLOUTMAJOR 25
159 #endif
161 /*****************************************************************************/
164 * Define our local driver identity first. Set up stuff to deal with
165 * all the local structures required by a serial tty driver.
167 static char *stli_drvtitle = "Stallion Intelligent Multiport Serial Driver";
168 static char *stli_drvname = "istallion";
169 static char *stli_drvversion = "5.6.0";
170 static char *stli_serialname = "ttyE";
172 static struct tty_driver *stli_serial;
175 * We will need to allocate a temporary write buffer for chars that
176 * come direct from user space. The problem is that a copy from user
177 * space might cause a page fault (typically on a system that is
178 * swapping!). All ports will share one buffer - since if the system
179 * is already swapping a shared buffer won't make things any worse.
181 static char *stli_tmpwritebuf;
182 static DECLARE_MUTEX(stli_tmpwritesem);
184 #define STLI_TXBUFSIZE 4096
187 * Use a fast local buffer for cooked characters. Typically a whole
188 * bunch of cooked characters come in for a port, 1 at a time. So we
189 * save those up into a local buffer, then write out the whole lot
190 * with a large memcpy. Just use 1 buffer for all ports, since its
191 * use it is only need for short periods of time by each port.
193 static char *stli_txcookbuf;
194 static int stli_txcooksize;
195 static int stli_txcookrealsize;
196 static struct tty_struct *stli_txcooktty;
199 * Define a local default termios struct. All ports will be created
200 * with this termios initially. Basically all it defines is a raw port
201 * at 9600 baud, 8 data bits, no parity, 1 stop bit.
203 static struct termios stli_deftermios = {
204 .c_cflag = (B9600 | CS8 | CREAD | HUPCL | CLOCAL),
205 .c_cc = INIT_C_CC,
209 * Define global stats structures. Not used often, and can be
210 * re-used for each stats call.
212 static comstats_t stli_comstats;
213 static combrd_t stli_brdstats;
214 static asystats_t stli_cdkstats;
215 static stlibrd_t stli_dummybrd;
216 static stliport_t stli_dummyport;
218 /*****************************************************************************/
220 static stlibrd_t *stli_brds[STL_MAXBRDS];
222 static int stli_shared;
225 * Per board state flags. Used with the state field of the board struct.
226 * Not really much here... All we need to do is keep track of whether
227 * the board has been detected, and whether it is actually running a slave
228 * or not.
230 #define BST_FOUND 0x1
231 #define BST_STARTED 0x2
234 * Define the set of port state flags. These are marked for internal
235 * state purposes only, usually to do with the state of communications
236 * with the slave. Most of them need to be updated atomically, so always
237 * use the bit setting operations (unless protected by cli/sti).
239 #define ST_INITIALIZING 1
240 #define ST_OPENING 2
241 #define ST_CLOSING 3
242 #define ST_CMDING 4
243 #define ST_TXBUSY 5
244 #define ST_RXING 6
245 #define ST_DOFLUSHRX 7
246 #define ST_DOFLUSHTX 8
247 #define ST_DOSIGS 9
248 #define ST_RXSTOP 10
249 #define ST_GETSIGS 11
252 * Define an array of board names as printable strings. Handy for
253 * referencing boards when printing trace and stuff.
255 static char *stli_brdnames[] = {
256 "Unknown",
257 "Stallion",
258 "Brumby",
259 "ONboard-MC",
260 "ONboard",
261 "Brumby",
262 "Brumby",
263 "ONboard-EI",
264 (char *) NULL,
265 "ONboard",
266 "ONboard-MC",
267 "ONboard-MC",
268 (char *) NULL,
269 (char *) NULL,
270 (char *) NULL,
271 (char *) NULL,
272 (char *) NULL,
273 (char *) NULL,
274 (char *) NULL,
275 (char *) NULL,
276 "EasyIO",
277 "EC8/32-AT",
278 "EC8/32-MC",
279 "EC8/64-AT",
280 "EC8/64-EI",
281 "EC8/64-MC",
282 "EC8/32-PCI",
283 "EC8/64-PCI",
284 "EasyIO-PCI",
285 "EC/RA-PCI",
288 /*****************************************************************************/
290 #ifdef MODULE
292 * Define some string labels for arguments passed from the module
293 * load line. These allow for easy board definitions, and easy
294 * modification of the io, memory and irq resoucres.
297 static char *board0[8];
298 static char *board1[8];
299 static char *board2[8];
300 static char *board3[8];
302 static char **stli_brdsp[] = {
303 (char **) &board0,
304 (char **) &board1,
305 (char **) &board2,
306 (char **) &board3
310 * Define a set of common board names, and types. This is used to
311 * parse any module arguments.
314 typedef struct stlibrdtype {
315 char *name;
316 int type;
317 } stlibrdtype_t;
319 static stlibrdtype_t stli_brdstr[] = {
320 { "stallion", BRD_STALLION },
321 { "1", BRD_STALLION },
322 { "brumby", BRD_BRUMBY },
323 { "brumby4", BRD_BRUMBY },
324 { "brumby/4", BRD_BRUMBY },
325 { "brumby-4", BRD_BRUMBY },
326 { "brumby8", BRD_BRUMBY },
327 { "brumby/8", BRD_BRUMBY },
328 { "brumby-8", BRD_BRUMBY },
329 { "brumby16", BRD_BRUMBY },
330 { "brumby/16", BRD_BRUMBY },
331 { "brumby-16", BRD_BRUMBY },
332 { "2", BRD_BRUMBY },
333 { "onboard2", BRD_ONBOARD2 },
334 { "onboard-2", BRD_ONBOARD2 },
335 { "onboard/2", BRD_ONBOARD2 },
336 { "onboard-mc", BRD_ONBOARD2 },
337 { "onboard/mc", BRD_ONBOARD2 },
338 { "onboard-mca", BRD_ONBOARD2 },
339 { "onboard/mca", BRD_ONBOARD2 },
340 { "3", BRD_ONBOARD2 },
341 { "onboard", BRD_ONBOARD },
342 { "onboardat", BRD_ONBOARD },
343 { "4", BRD_ONBOARD },
344 { "onboarde", BRD_ONBOARDE },
345 { "onboard-e", BRD_ONBOARDE },
346 { "onboard/e", BRD_ONBOARDE },
347 { "onboard-ei", BRD_ONBOARDE },
348 { "onboard/ei", BRD_ONBOARDE },
349 { "7", BRD_ONBOARDE },
350 { "ecp", BRD_ECP },
351 { "ecpat", BRD_ECP },
352 { "ec8/64", BRD_ECP },
353 { "ec8/64-at", BRD_ECP },
354 { "ec8/64-isa", BRD_ECP },
355 { "23", BRD_ECP },
356 { "ecpe", BRD_ECPE },
357 { "ecpei", BRD_ECPE },
358 { "ec8/64-e", BRD_ECPE },
359 { "ec8/64-ei", BRD_ECPE },
360 { "24", BRD_ECPE },
361 { "ecpmc", BRD_ECPMC },
362 { "ec8/64-mc", BRD_ECPMC },
363 { "ec8/64-mca", BRD_ECPMC },
364 { "25", BRD_ECPMC },
365 { "ecppci", BRD_ECPPCI },
366 { "ec/ra", BRD_ECPPCI },
367 { "ec/ra-pc", BRD_ECPPCI },
368 { "ec/ra-pci", BRD_ECPPCI },
369 { "29", BRD_ECPPCI },
373 * Define the module agruments.
375 MODULE_AUTHOR("Greg Ungerer");
376 MODULE_DESCRIPTION("Stallion Intelligent Multiport Serial Driver");
377 MODULE_LICENSE("GPL");
380 MODULE_PARM(board0, "1-3s");
381 MODULE_PARM_DESC(board0, "Board 0 config -> name[,ioaddr[,memaddr]");
382 MODULE_PARM(board1, "1-3s");
383 MODULE_PARM_DESC(board1, "Board 1 config -> name[,ioaddr[,memaddr]");
384 MODULE_PARM(board2, "1-3s");
385 MODULE_PARM_DESC(board2, "Board 2 config -> name[,ioaddr[,memaddr]");
386 MODULE_PARM(board3, "1-3s");
387 MODULE_PARM_DESC(board3, "Board 3 config -> name[,ioaddr[,memaddr]");
389 #endif
392 * Set up a default memory address table for EISA board probing.
393 * The default addresses are all bellow 1Mbyte, which has to be the
394 * case anyway. They should be safe, since we only read values from
395 * them, and interrupts are disabled while we do it. If the higher
396 * memory support is compiled in then we also try probing around
397 * the 1Gb, 2Gb and 3Gb areas as well...
399 static unsigned long stli_eisamemprobeaddrs[] = {
400 0xc0000, 0xd0000, 0xe0000, 0xf0000,
401 0x80000000, 0x80010000, 0x80020000, 0x80030000,
402 0x40000000, 0x40010000, 0x40020000, 0x40030000,
403 0xc0000000, 0xc0010000, 0xc0020000, 0xc0030000,
404 0xff000000, 0xff010000, 0xff020000, 0xff030000,
407 static int stli_eisamempsize = sizeof(stli_eisamemprobeaddrs) / sizeof(unsigned long);
408 int stli_eisaprobe = STLI_EISAPROBE;
411 * Define the Stallion PCI vendor and device IDs.
413 #ifdef CONFIG_PCI
414 #ifndef PCI_VENDOR_ID_STALLION
415 #define PCI_VENDOR_ID_STALLION 0x124d
416 #endif
417 #ifndef PCI_DEVICE_ID_ECRA
418 #define PCI_DEVICE_ID_ECRA 0x0004
419 #endif
420 #endif
422 static struct pci_device_id istallion_pci_tbl[] = {
423 { PCI_VENDOR_ID_STALLION, PCI_DEVICE_ID_ECRA, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0 },
424 { 0 }
426 MODULE_DEVICE_TABLE(pci, istallion_pci_tbl);
428 /*****************************************************************************/
431 * Hardware configuration info for ECP boards. These defines apply
432 * to the directly accessible io ports of the ECP. There is a set of
433 * defines for each ECP board type, ISA, EISA, MCA and PCI.
435 #define ECP_IOSIZE 4
437 #define ECP_MEMSIZE (128 * 1024)
438 #define ECP_PCIMEMSIZE (256 * 1024)
440 #define ECP_ATPAGESIZE (4 * 1024)
441 #define ECP_MCPAGESIZE (4 * 1024)
442 #define ECP_EIPAGESIZE (64 * 1024)
443 #define ECP_PCIPAGESIZE (64 * 1024)
445 #define STL_EISAID 0x8c4e
448 * Important defines for the ISA class of ECP board.
450 #define ECP_ATIREG 0
451 #define ECP_ATCONFR 1
452 #define ECP_ATMEMAR 2
453 #define ECP_ATMEMPR 3
454 #define ECP_ATSTOP 0x1
455 #define ECP_ATINTENAB 0x10
456 #define ECP_ATENABLE 0x20
457 #define ECP_ATDISABLE 0x00
458 #define ECP_ATADDRMASK 0x3f000
459 #define ECP_ATADDRSHFT 12
462 * Important defines for the EISA class of ECP board.
464 #define ECP_EIIREG 0
465 #define ECP_EIMEMARL 1
466 #define ECP_EICONFR 2
467 #define ECP_EIMEMARH 3
468 #define ECP_EIENABLE 0x1
469 #define ECP_EIDISABLE 0x0
470 #define ECP_EISTOP 0x4
471 #define ECP_EIEDGE 0x00
472 #define ECP_EILEVEL 0x80
473 #define ECP_EIADDRMASKL 0x00ff0000
474 #define ECP_EIADDRSHFTL 16
475 #define ECP_EIADDRMASKH 0xff000000
476 #define ECP_EIADDRSHFTH 24
477 #define ECP_EIBRDENAB 0xc84
479 #define ECP_EISAID 0x4
482 * Important defines for the Micro-channel class of ECP board.
483 * (It has a lot in common with the ISA boards.)
485 #define ECP_MCIREG 0
486 #define ECP_MCCONFR 1
487 #define ECP_MCSTOP 0x20
488 #define ECP_MCENABLE 0x80
489 #define ECP_MCDISABLE 0x00
492 * Important defines for the PCI class of ECP board.
493 * (It has a lot in common with the other ECP boards.)
495 #define ECP_PCIIREG 0
496 #define ECP_PCICONFR 1
497 #define ECP_PCISTOP 0x01
500 * Hardware configuration info for ONboard and Brumby boards. These
501 * defines apply to the directly accessible io ports of these boards.
503 #define ONB_IOSIZE 16
504 #define ONB_MEMSIZE (64 * 1024)
505 #define ONB_ATPAGESIZE (64 * 1024)
506 #define ONB_MCPAGESIZE (64 * 1024)
507 #define ONB_EIMEMSIZE (128 * 1024)
508 #define ONB_EIPAGESIZE (64 * 1024)
511 * Important defines for the ISA class of ONboard board.
513 #define ONB_ATIREG 0
514 #define ONB_ATMEMAR 1
515 #define ONB_ATCONFR 2
516 #define ONB_ATSTOP 0x4
517 #define ONB_ATENABLE 0x01
518 #define ONB_ATDISABLE 0x00
519 #define ONB_ATADDRMASK 0xff0000
520 #define ONB_ATADDRSHFT 16
522 #define ONB_MEMENABLO 0
523 #define ONB_MEMENABHI 0x02
526 * Important defines for the EISA class of ONboard board.
528 #define ONB_EIIREG 0
529 #define ONB_EIMEMARL 1
530 #define ONB_EICONFR 2
531 #define ONB_EIMEMARH 3
532 #define ONB_EIENABLE 0x1
533 #define ONB_EIDISABLE 0x0
534 #define ONB_EISTOP 0x4
535 #define ONB_EIEDGE 0x00
536 #define ONB_EILEVEL 0x80
537 #define ONB_EIADDRMASKL 0x00ff0000
538 #define ONB_EIADDRSHFTL 16
539 #define ONB_EIADDRMASKH 0xff000000
540 #define ONB_EIADDRSHFTH 24
541 #define ONB_EIBRDENAB 0xc84
543 #define ONB_EISAID 0x1
546 * Important defines for the Brumby boards. They are pretty simple,
547 * there is not much that is programmably configurable.
549 #define BBY_IOSIZE 16
550 #define BBY_MEMSIZE (64 * 1024)
551 #define BBY_PAGESIZE (16 * 1024)
553 #define BBY_ATIREG 0
554 #define BBY_ATCONFR 1
555 #define BBY_ATSTOP 0x4
558 * Important defines for the Stallion boards. They are pretty simple,
559 * there is not much that is programmably configurable.
561 #define STAL_IOSIZE 16
562 #define STAL_MEMSIZE (64 * 1024)
563 #define STAL_PAGESIZE (64 * 1024)
566 * Define the set of status register values for EasyConnection panels.
567 * The signature will return with the status value for each panel. From
568 * this we can determine what is attached to the board - before we have
569 * actually down loaded any code to it.
571 #define ECH_PNLSTATUS 2
572 #define ECH_PNL16PORT 0x20
573 #define ECH_PNLIDMASK 0x07
574 #define ECH_PNLXPID 0x40
575 #define ECH_PNLINTRPEND 0x80
578 * Define some macros to do things to the board. Even those these boards
579 * are somewhat related there is often significantly different ways of
580 * doing some operation on it (like enable, paging, reset, etc). So each
581 * board class has a set of functions which do the commonly required
582 * operations. The macros below basically just call these functions,
583 * generally checking for a NULL function - which means that the board
584 * needs nothing done to it to achieve this operation!
586 #define EBRDINIT(brdp) \
587 if (brdp->init != NULL) \
588 (* brdp->init)(brdp)
590 #define EBRDENABLE(brdp) \
591 if (brdp->enable != NULL) \
592 (* brdp->enable)(brdp);
594 #define EBRDDISABLE(brdp) \
595 if (brdp->disable != NULL) \
596 (* brdp->disable)(brdp);
598 #define EBRDINTR(brdp) \
599 if (brdp->intr != NULL) \
600 (* brdp->intr)(brdp);
602 #define EBRDRESET(brdp) \
603 if (brdp->reset != NULL) \
604 (* brdp->reset)(brdp);
606 #define EBRDGETMEMPTR(brdp,offset) \
607 (* brdp->getmemptr)(brdp, offset, __LINE__)
610 * Define the maximal baud rate, and the default baud base for ports.
612 #define STL_MAXBAUD 460800
613 #define STL_BAUDBASE 115200
614 #define STL_CLOSEDELAY (5 * HZ / 10)
616 /*****************************************************************************/
619 * Define macros to extract a brd or port number from a minor number.
621 #define MINOR2BRD(min) (((min) & 0xc0) >> 6)
622 #define MINOR2PORT(min) ((min) & 0x3f)
625 * Define a baud rate table that converts termios baud rate selector
626 * into the actual baud rate value. All baud rate calculations are based
627 * on the actual baud rate required.
629 static unsigned int stli_baudrates[] = {
630 0, 50, 75, 110, 134, 150, 200, 300, 600, 1200, 1800, 2400, 4800,
631 9600, 19200, 38400, 57600, 115200, 230400, 460800, 921600
634 /*****************************************************************************/
637 * Define some handy local macros...
639 #undef MIN
640 #define MIN(a,b) (((a) <= (b)) ? (a) : (b))
642 #undef TOLOWER
643 #define TOLOWER(x) ((((x) >= 'A') && ((x) <= 'Z')) ? ((x) + 0x20) : (x))
645 /*****************************************************************************/
648 * Prototype all functions in this driver!
651 #ifdef MODULE
652 static void stli_argbrds(void);
653 static int stli_parsebrd(stlconf_t *confp, char **argp);
655 static unsigned long stli_atol(char *str);
656 #endif
658 int stli_init(void);
659 static int stli_open(struct tty_struct *tty, struct file *filp);
660 static void stli_close(struct tty_struct *tty, struct file *filp);
661 static int stli_write(struct tty_struct *tty, int from_user, const unsigned char *buf, int count);
662 static void stli_putchar(struct tty_struct *tty, unsigned char ch);
663 static void stli_flushchars(struct tty_struct *tty);
664 static int stli_writeroom(struct tty_struct *tty);
665 static int stli_charsinbuffer(struct tty_struct *tty);
666 static int stli_ioctl(struct tty_struct *tty, struct file *file, unsigned int cmd, unsigned long arg);
667 static void stli_settermios(struct tty_struct *tty, struct termios *old);
668 static void stli_throttle(struct tty_struct *tty);
669 static void stli_unthrottle(struct tty_struct *tty);
670 static void stli_stop(struct tty_struct *tty);
671 static void stli_start(struct tty_struct *tty);
672 static void stli_flushbuffer(struct tty_struct *tty);
673 static void stli_breakctl(struct tty_struct *tty, int state);
674 static void stli_waituntilsent(struct tty_struct *tty, int timeout);
675 static void stli_sendxchar(struct tty_struct *tty, char ch);
676 static void stli_hangup(struct tty_struct *tty);
677 static int stli_portinfo(stlibrd_t *brdp, stliport_t *portp, int portnr, char *pos);
679 static int stli_brdinit(stlibrd_t *brdp);
680 static int stli_startbrd(stlibrd_t *brdp);
681 static ssize_t stli_memread(struct file *fp, char *buf, size_t count, loff_t *offp);
682 static ssize_t stli_memwrite(struct file *fp, const char *buf, size_t count, loff_t *offp);
683 static int stli_memioctl(struct inode *ip, struct file *fp, unsigned int cmd, unsigned long arg);
684 static void stli_brdpoll(stlibrd_t *brdp, volatile cdkhdr_t *hdrp);
685 static void stli_poll(unsigned long arg);
686 static int stli_hostcmd(stlibrd_t *brdp, stliport_t *portp);
687 static int stli_initopen(stlibrd_t *brdp, stliport_t *portp);
688 static int stli_rawopen(stlibrd_t *brdp, stliport_t *portp, unsigned long arg, int wait);
689 static int stli_rawclose(stlibrd_t *brdp, stliport_t *portp, unsigned long arg, int wait);
690 static int stli_waitcarrier(stlibrd_t *brdp, stliport_t *portp, struct file *filp);
691 static void stli_dohangup(void *arg);
692 static void stli_delay(int len);
693 static int stli_setport(stliport_t *portp);
694 static int stli_cmdwait(stlibrd_t *brdp, stliport_t *portp, unsigned long cmd, void *arg, int size, int copyback);
695 static void stli_sendcmd(stlibrd_t *brdp, stliport_t *portp, unsigned long cmd, void *arg, int size, int copyback);
696 static void stli_dodelaycmd(stliport_t *portp, volatile cdkctrl_t *cp);
697 static void stli_mkasyport(stliport_t *portp, asyport_t *pp, struct termios *tiosp);
698 static void stli_mkasysigs(asysigs_t *sp, int dtr, int rts);
699 static long stli_mktiocm(unsigned long sigvalue);
700 static void stli_read(stlibrd_t *brdp, stliport_t *portp);
701 static int stli_getserial(stliport_t *portp, struct serial_struct *sp);
702 static int stli_setserial(stliport_t *portp, struct serial_struct *sp);
703 static int stli_getbrdstats(combrd_t *bp);
704 static int stli_getportstats(stliport_t *portp, comstats_t *cp);
705 static int stli_portcmdstats(stliport_t *portp);
706 static int stli_clrportstats(stliport_t *portp, comstats_t *cp);
707 static int stli_getportstruct(unsigned long arg);
708 static int stli_getbrdstruct(unsigned long arg);
709 static void *stli_memalloc(int len);
710 static stlibrd_t *stli_allocbrd(void);
712 static void stli_ecpinit(stlibrd_t *brdp);
713 static void stli_ecpenable(stlibrd_t *brdp);
714 static void stli_ecpdisable(stlibrd_t *brdp);
715 static char *stli_ecpgetmemptr(stlibrd_t *brdp, unsigned long offset, int line);
716 static void stli_ecpreset(stlibrd_t *brdp);
717 static void stli_ecpintr(stlibrd_t *brdp);
718 static void stli_ecpeiinit(stlibrd_t *brdp);
719 static void stli_ecpeienable(stlibrd_t *brdp);
720 static void stli_ecpeidisable(stlibrd_t *brdp);
721 static char *stli_ecpeigetmemptr(stlibrd_t *brdp, unsigned long offset, int line);
722 static void stli_ecpeireset(stlibrd_t *brdp);
723 static void stli_ecpmcenable(stlibrd_t *brdp);
724 static void stli_ecpmcdisable(stlibrd_t *brdp);
725 static char *stli_ecpmcgetmemptr(stlibrd_t *brdp, unsigned long offset, int line);
726 static void stli_ecpmcreset(stlibrd_t *brdp);
727 static void stli_ecppciinit(stlibrd_t *brdp);
728 static char *stli_ecppcigetmemptr(stlibrd_t *brdp, unsigned long offset, int line);
729 static void stli_ecppcireset(stlibrd_t *brdp);
731 static void stli_onbinit(stlibrd_t *brdp);
732 static void stli_onbenable(stlibrd_t *brdp);
733 static void stli_onbdisable(stlibrd_t *brdp);
734 static char *stli_onbgetmemptr(stlibrd_t *brdp, unsigned long offset, int line);
735 static void stli_onbreset(stlibrd_t *brdp);
736 static void stli_onbeinit(stlibrd_t *brdp);
737 static void stli_onbeenable(stlibrd_t *brdp);
738 static void stli_onbedisable(stlibrd_t *brdp);
739 static char *stli_onbegetmemptr(stlibrd_t *brdp, unsigned long offset, int line);
740 static void stli_onbereset(stlibrd_t *brdp);
741 static void stli_bbyinit(stlibrd_t *brdp);
742 static char *stli_bbygetmemptr(stlibrd_t *brdp, unsigned long offset, int line);
743 static void stli_bbyreset(stlibrd_t *brdp);
744 static void stli_stalinit(stlibrd_t *brdp);
745 static char *stli_stalgetmemptr(stlibrd_t *brdp, unsigned long offset, int line);
746 static void stli_stalreset(stlibrd_t *brdp);
748 static stliport_t *stli_getport(int brdnr, int panelnr, int portnr);
750 static inline int stli_initbrds(void);
751 static inline int stli_initecp(stlibrd_t *brdp);
752 static inline int stli_initonb(stlibrd_t *brdp);
753 static inline int stli_findeisabrds(void);
754 static inline int stli_eisamemprobe(stlibrd_t *brdp);
755 static inline int stli_initports(stlibrd_t *brdp);
756 static inline int stli_getbrdnr(void);
758 #ifdef CONFIG_PCI
759 static inline int stli_findpcibrds(void);
760 static inline int stli_initpcibrd(int brdtype, struct pci_dev *devp);
761 #endif
763 /*****************************************************************************/
766 * Define the driver info for a user level shared memory device. This
767 * device will work sort of like the /dev/kmem device - except that it
768 * will give access to the shared memory on the Stallion intelligent
769 * board. This is also a very useful debugging tool.
771 static struct file_operations stli_fsiomem = {
772 .owner = THIS_MODULE,
773 .read = stli_memread,
774 .write = stli_memwrite,
775 .ioctl = stli_memioctl,
778 /*****************************************************************************/
781 * Define a timer_list entry for our poll routine. The slave board
782 * is polled every so often to see if anything needs doing. This is
783 * much cheaper on host cpu than using interrupts. It turns out to
784 * not increase character latency by much either...
786 static struct timer_list stli_timerlist = TIMER_INITIALIZER(stli_poll, 0, 0);
788 static int stli_timeron;
791 * Define the calculation for the timeout routine.
793 #define STLI_TIMEOUT (jiffies + 1)
795 /*****************************************************************************/
797 #ifdef MODULE
800 * Loadable module initialization stuff.
803 static int __init istallion_module_init(void)
805 unsigned long flags;
807 #if DEBUG
808 printk("init_module()\n");
809 #endif
811 save_flags(flags);
812 cli();
813 stli_init();
814 restore_flags(flags);
816 return(0);
819 /*****************************************************************************/
821 static void __exit istallion_module_exit(void)
823 stlibrd_t *brdp;
824 stliport_t *portp;
825 unsigned long flags;
826 int i, j;
828 #if DEBUG
829 printk("cleanup_module()\n");
830 #endif
832 printk(KERN_INFO "Unloading %s: version %s\n", stli_drvtitle,
833 stli_drvversion);
835 save_flags(flags);
836 cli();
839 * Free up all allocated resources used by the ports. This includes
840 * memory and interrupts.
842 if (stli_timeron) {
843 stli_timeron = 0;
844 del_timer(&stli_timerlist);
847 i = tty_unregister_driver(stli_serial);
848 if (i) {
849 printk("STALLION: failed to un-register tty driver, "
850 "errno=%d,%d\n", -i);
851 restore_flags(flags);
852 return;
854 put_tty_driver(stli_serial);
855 for (i = 0; i < 4; i++)
856 devfs_remove("staliomem/%d", i);
857 devfs_remove("staliomem");
858 if ((i = unregister_chrdev(STL_SIOMEMMAJOR, "staliomem")))
859 printk("STALLION: failed to un-register serial memory device, "
860 "errno=%d\n", -i);
861 if (stli_tmpwritebuf != (char *) NULL)
862 kfree(stli_tmpwritebuf);
863 if (stli_txcookbuf != (char *) NULL)
864 kfree(stli_txcookbuf);
866 for (i = 0; (i < stli_nrbrds); i++) {
867 if ((brdp = stli_brds[i]) == (stlibrd_t *) NULL)
868 continue;
869 for (j = 0; (j < STL_MAXPORTS); j++) {
870 portp = brdp->ports[j];
871 if (portp != (stliport_t *) NULL) {
872 if (portp->tty != (struct tty_struct *) NULL)
873 tty_hangup(portp->tty);
874 kfree(portp);
878 iounmap(brdp->membase);
879 if (brdp->iosize > 0)
880 release_region(brdp->iobase, brdp->iosize);
881 kfree(brdp);
882 stli_brds[i] = (stlibrd_t *) NULL;
885 restore_flags(flags);
888 module_init(istallion_module_init);
889 module_exit(istallion_module_exit);
891 /*****************************************************************************/
894 * Check for any arguments passed in on the module load command line.
897 static void stli_argbrds()
899 stlconf_t conf;
900 stlibrd_t *brdp;
901 int nrargs, i;
903 #if DEBUG
904 printk("stli_argbrds()\n");
905 #endif
907 nrargs = sizeof(stli_brdsp) / sizeof(char **);
909 for (i = stli_nrbrds; (i < nrargs); i++) {
910 memset(&conf, 0, sizeof(conf));
911 if (stli_parsebrd(&conf, stli_brdsp[i]) == 0)
912 continue;
913 if ((brdp = stli_allocbrd()) == (stlibrd_t *) NULL)
914 continue;
915 stli_nrbrds = i + 1;
916 brdp->brdnr = i;
917 brdp->brdtype = conf.brdtype;
918 brdp->iobase = conf.ioaddr1;
919 brdp->memaddr = conf.memaddr;
920 stli_brdinit(brdp);
924 /*****************************************************************************/
927 * Convert an ascii string number into an unsigned long.
930 static unsigned long stli_atol(char *str)
932 unsigned long val;
933 int base, c;
934 char *sp;
936 val = 0;
937 sp = str;
938 if ((*sp == '0') && (*(sp+1) == 'x')) {
939 base = 16;
940 sp += 2;
941 } else if (*sp == '0') {
942 base = 8;
943 sp++;
944 } else {
945 base = 10;
948 for (; (*sp != 0); sp++) {
949 c = (*sp > '9') ? (TOLOWER(*sp) - 'a' + 10) : (*sp - '0');
950 if ((c < 0) || (c >= base)) {
951 printk("STALLION: invalid argument %s\n", str);
952 val = 0;
953 break;
955 val = (val * base) + c;
957 return(val);
960 /*****************************************************************************/
963 * Parse the supplied argument string, into the board conf struct.
966 static int stli_parsebrd(stlconf_t *confp, char **argp)
968 char *sp;
969 int nrbrdnames, i;
971 #if DEBUG
972 printk("stli_parsebrd(confp=%x,argp=%x)\n", (int) confp, (int) argp);
973 #endif
975 if ((argp[0] == (char *) NULL) || (*argp[0] == 0))
976 return(0);
978 for (sp = argp[0], i = 0; ((*sp != 0) && (i < 25)); sp++, i++)
979 *sp = TOLOWER(*sp);
981 nrbrdnames = sizeof(stli_brdstr) / sizeof(stlibrdtype_t);
982 for (i = 0; (i < nrbrdnames); i++) {
983 if (strcmp(stli_brdstr[i].name, argp[0]) == 0)
984 break;
986 if (i >= nrbrdnames) {
987 printk("STALLION: unknown board name, %s?\n", argp[0]);
988 return(0);
991 confp->brdtype = stli_brdstr[i].type;
992 if ((argp[1] != (char *) NULL) && (*argp[1] != 0))
993 confp->ioaddr1 = stli_atol(argp[1]);
994 if ((argp[2] != (char *) NULL) && (*argp[2] != 0))
995 confp->memaddr = stli_atol(argp[2]);
996 return(1);
999 #endif
1001 /*****************************************************************************/
1004 * Local driver kernel malloc routine.
1007 static void *stli_memalloc(int len)
1009 return((void *) kmalloc(len, GFP_KERNEL));
1012 /*****************************************************************************/
1014 static int stli_open(struct tty_struct *tty, struct file *filp)
1016 stlibrd_t *brdp;
1017 stliport_t *portp;
1018 unsigned int minordev;
1019 int brdnr, portnr, rc;
1021 #if DEBUG
1022 printk("stli_open(tty=%x,filp=%x): device=%s\n", (int) tty,
1023 (int) filp, tty->name);
1024 #endif
1026 minordev = tty->index;
1027 brdnr = MINOR2BRD(minordev);
1028 if (brdnr >= stli_nrbrds)
1029 return(-ENODEV);
1030 brdp = stli_brds[brdnr];
1031 if (brdp == (stlibrd_t *) NULL)
1032 return(-ENODEV);
1033 if ((brdp->state & BST_STARTED) == 0)
1034 return(-ENODEV);
1035 portnr = MINOR2PORT(minordev);
1036 if ((portnr < 0) || (portnr > brdp->nrports))
1037 return(-ENODEV);
1039 portp = brdp->ports[portnr];
1040 if (portp == (stliport_t *) NULL)
1041 return(-ENODEV);
1042 if (portp->devnr < 1)
1043 return(-ENODEV);
1047 * Check if this port is in the middle of closing. If so then wait
1048 * until it is closed then return error status based on flag settings.
1049 * The sleep here does not need interrupt protection since the wakeup
1050 * for it is done with the same context.
1052 if (portp->flags & ASYNC_CLOSING) {
1053 interruptible_sleep_on(&portp->close_wait);
1054 if (portp->flags & ASYNC_HUP_NOTIFY)
1055 return(-EAGAIN);
1056 return(-ERESTARTSYS);
1060 * On the first open of the device setup the port hardware, and
1061 * initialize the per port data structure. Since initializing the port
1062 * requires several commands to the board we will need to wait for any
1063 * other open that is already initializing the port.
1065 portp->tty = tty;
1066 tty->driver_data = portp;
1067 portp->refcount++;
1069 while (test_bit(ST_INITIALIZING, &portp->state)) {
1070 if (signal_pending(current))
1071 return(-ERESTARTSYS);
1072 interruptible_sleep_on(&portp->raw_wait);
1075 if ((portp->flags & ASYNC_INITIALIZED) == 0) {
1076 set_bit(ST_INITIALIZING, &portp->state);
1077 if ((rc = stli_initopen(brdp, portp)) >= 0) {
1078 portp->flags |= ASYNC_INITIALIZED;
1079 clear_bit(TTY_IO_ERROR, &tty->flags);
1081 clear_bit(ST_INITIALIZING, &portp->state);
1082 wake_up_interruptible(&portp->raw_wait);
1083 if (rc < 0)
1084 return(rc);
1088 * Check if this port is in the middle of closing. If so then wait
1089 * until it is closed then return error status, based on flag settings.
1090 * The sleep here does not need interrupt protection since the wakeup
1091 * for it is done with the same context.
1093 if (portp->flags & ASYNC_CLOSING) {
1094 interruptible_sleep_on(&portp->close_wait);
1095 if (portp->flags & ASYNC_HUP_NOTIFY)
1096 return(-EAGAIN);
1097 return(-ERESTARTSYS);
1101 * Based on type of open being done check if it can overlap with any
1102 * previous opens still in effect. If we are a normal serial device
1103 * then also we might have to wait for carrier.
1105 if (!(filp->f_flags & O_NONBLOCK)) {
1106 if ((rc = stli_waitcarrier(brdp, portp, filp)) != 0)
1107 return(rc);
1109 portp->flags |= ASYNC_NORMAL_ACTIVE;
1110 return(0);
1113 /*****************************************************************************/
1115 static void stli_close(struct tty_struct *tty, struct file *filp)
1117 stlibrd_t *brdp;
1118 stliport_t *portp;
1119 unsigned long flags;
1121 #if DEBUG
1122 printk("stli_close(tty=%x,filp=%x)\n", (int) tty, (int) filp);
1123 #endif
1125 portp = tty->driver_data;
1126 if (portp == (stliport_t *) NULL)
1127 return;
1129 save_flags(flags);
1130 cli();
1131 if (tty_hung_up_p(filp)) {
1132 restore_flags(flags);
1133 return;
1135 if ((tty->count == 1) && (portp->refcount != 1))
1136 portp->refcount = 1;
1137 if (portp->refcount-- > 1) {
1138 restore_flags(flags);
1139 return;
1142 portp->flags |= ASYNC_CLOSING;
1145 * May want to wait for data to drain before closing. The BUSY flag
1146 * keeps track of whether we are still transmitting or not. It is
1147 * updated by messages from the slave - indicating when all chars
1148 * really have drained.
1150 if (tty == stli_txcooktty)
1151 stli_flushchars(tty);
1152 tty->closing = 1;
1153 if (portp->closing_wait != ASYNC_CLOSING_WAIT_NONE)
1154 tty_wait_until_sent(tty, portp->closing_wait);
1156 portp->flags &= ~ASYNC_INITIALIZED;
1157 brdp = stli_brds[portp->brdnr];
1158 stli_rawclose(brdp, portp, 0, 0);
1159 if (tty->termios->c_cflag & HUPCL) {
1160 stli_mkasysigs(&portp->asig, 0, 0);
1161 if (test_bit(ST_CMDING, &portp->state))
1162 set_bit(ST_DOSIGS, &portp->state);
1163 else
1164 stli_sendcmd(brdp, portp, A_SETSIGNALS, &portp->asig,
1165 sizeof(asysigs_t), 0);
1167 clear_bit(ST_TXBUSY, &portp->state);
1168 clear_bit(ST_RXSTOP, &portp->state);
1169 set_bit(TTY_IO_ERROR, &tty->flags);
1170 if (tty->ldisc.flush_buffer)
1171 (tty->ldisc.flush_buffer)(tty);
1172 set_bit(ST_DOFLUSHRX, &portp->state);
1173 stli_flushbuffer(tty);
1175 tty->closing = 0;
1176 portp->tty = (struct tty_struct *) NULL;
1178 if (portp->openwaitcnt) {
1179 if (portp->close_delay)
1180 stli_delay(portp->close_delay);
1181 wake_up_interruptible(&portp->open_wait);
1184 portp->flags &= ~(ASYNC_NORMAL_ACTIVE|ASYNC_CLOSING);
1185 wake_up_interruptible(&portp->close_wait);
1186 restore_flags(flags);
1189 /*****************************************************************************/
1192 * Carry out first open operations on a port. This involves a number of
1193 * commands to be sent to the slave. We need to open the port, set the
1194 * notification events, set the initial port settings, get and set the
1195 * initial signal values. We sleep and wait in between each one. But
1196 * this still all happens pretty quickly.
1199 static int stli_initopen(stlibrd_t *brdp, stliport_t *portp)
1201 struct tty_struct *tty;
1202 asynotify_t nt;
1203 asyport_t aport;
1204 int rc;
1206 #if DEBUG
1207 printk("stli_initopen(brdp=%x,portp=%x)\n", (int) brdp, (int) portp);
1208 #endif
1210 if ((rc = stli_rawopen(brdp, portp, 0, 1)) < 0)
1211 return(rc);
1213 memset(&nt, 0, sizeof(asynotify_t));
1214 nt.data = (DT_TXLOW | DT_TXEMPTY | DT_RXBUSY | DT_RXBREAK);
1215 nt.signal = SG_DCD;
1216 if ((rc = stli_cmdwait(brdp, portp, A_SETNOTIFY, &nt,
1217 sizeof(asynotify_t), 0)) < 0)
1218 return(rc);
1220 tty = portp->tty;
1221 if (tty == (struct tty_struct *) NULL)
1222 return(-ENODEV);
1223 stli_mkasyport(portp, &aport, tty->termios);
1224 if ((rc = stli_cmdwait(brdp, portp, A_SETPORT, &aport,
1225 sizeof(asyport_t), 0)) < 0)
1226 return(rc);
1228 set_bit(ST_GETSIGS, &portp->state);
1229 if ((rc = stli_cmdwait(brdp, portp, A_GETSIGNALS, &portp->asig,
1230 sizeof(asysigs_t), 1)) < 0)
1231 return(rc);
1232 if (test_and_clear_bit(ST_GETSIGS, &portp->state))
1233 portp->sigs = stli_mktiocm(portp->asig.sigvalue);
1234 stli_mkasysigs(&portp->asig, 1, 1);
1235 if ((rc = stli_cmdwait(brdp, portp, A_SETSIGNALS, &portp->asig,
1236 sizeof(asysigs_t), 0)) < 0)
1237 return(rc);
1239 return(0);
1242 /*****************************************************************************/
1245 * Send an open message to the slave. This will sleep waiting for the
1246 * acknowledgement, so must have user context. We need to co-ordinate
1247 * with close events here, since we don't want open and close events
1248 * to overlap.
1251 static int stli_rawopen(stlibrd_t *brdp, stliport_t *portp, unsigned long arg, int wait)
1253 volatile cdkhdr_t *hdrp;
1254 volatile cdkctrl_t *cp;
1255 volatile unsigned char *bits;
1256 unsigned long flags;
1257 int rc;
1259 #if DEBUG
1260 printk("stli_rawopen(brdp=%x,portp=%x,arg=%x,wait=%d)\n",
1261 (int) brdp, (int) portp, (int) arg, wait);
1262 #endif
1265 * Send a message to the slave to open this port.
1267 save_flags(flags);
1268 cli();
1271 * Slave is already closing this port. This can happen if a hangup
1272 * occurs on this port. So we must wait until it is complete. The
1273 * order of opens and closes may not be preserved across shared
1274 * memory, so we must wait until it is complete.
1276 while (test_bit(ST_CLOSING, &portp->state)) {
1277 if (signal_pending(current)) {
1278 restore_flags(flags);
1279 return(-ERESTARTSYS);
1281 interruptible_sleep_on(&portp->raw_wait);
1285 * Everything is ready now, so write the open message into shared
1286 * memory. Once the message is in set the service bits to say that
1287 * this port wants service.
1289 EBRDENABLE(brdp);
1290 cp = &((volatile cdkasy_t *) EBRDGETMEMPTR(brdp, portp->addr))->ctrl;
1291 cp->openarg = arg;
1292 cp->open = 1;
1293 hdrp = (volatile cdkhdr_t *) EBRDGETMEMPTR(brdp, CDK_CDKADDR);
1294 bits = ((volatile unsigned char *) hdrp) + brdp->slaveoffset +
1295 portp->portidx;
1296 *bits |= portp->portbit;
1297 EBRDDISABLE(brdp);
1299 if (wait == 0) {
1300 restore_flags(flags);
1301 return(0);
1305 * Slave is in action, so now we must wait for the open acknowledgment
1306 * to come back.
1308 rc = 0;
1309 set_bit(ST_OPENING, &portp->state);
1310 while (test_bit(ST_OPENING, &portp->state)) {
1311 if (signal_pending(current)) {
1312 rc = -ERESTARTSYS;
1313 break;
1315 interruptible_sleep_on(&portp->raw_wait);
1317 restore_flags(flags);
1319 if ((rc == 0) && (portp->rc != 0))
1320 rc = -EIO;
1321 return(rc);
1324 /*****************************************************************************/
1327 * Send a close message to the slave. Normally this will sleep waiting
1328 * for the acknowledgement, but if wait parameter is 0 it will not. If
1329 * wait is true then must have user context (to sleep).
1332 static int stli_rawclose(stlibrd_t *brdp, stliport_t *portp, unsigned long arg, int wait)
1334 volatile cdkhdr_t *hdrp;
1335 volatile cdkctrl_t *cp;
1336 volatile unsigned char *bits;
1337 unsigned long flags;
1338 int rc;
1340 #if DEBUG
1341 printk("stli_rawclose(brdp=%x,portp=%x,arg=%x,wait=%d)\n",
1342 (int) brdp, (int) portp, (int) arg, wait);
1343 #endif
1345 save_flags(flags);
1346 cli();
1349 * Slave is already closing this port. This can happen if a hangup
1350 * occurs on this port.
1352 if (wait) {
1353 while (test_bit(ST_CLOSING, &portp->state)) {
1354 if (signal_pending(current)) {
1355 restore_flags(flags);
1356 return(-ERESTARTSYS);
1358 interruptible_sleep_on(&portp->raw_wait);
1363 * Write the close command into shared memory.
1365 EBRDENABLE(brdp);
1366 cp = &((volatile cdkasy_t *) EBRDGETMEMPTR(brdp, portp->addr))->ctrl;
1367 cp->closearg = arg;
1368 cp->close = 1;
1369 hdrp = (volatile cdkhdr_t *) EBRDGETMEMPTR(brdp, CDK_CDKADDR);
1370 bits = ((volatile unsigned char *) hdrp) + brdp->slaveoffset +
1371 portp->portidx;
1372 *bits |= portp->portbit;
1373 EBRDDISABLE(brdp);
1375 set_bit(ST_CLOSING, &portp->state);
1376 if (wait == 0) {
1377 restore_flags(flags);
1378 return(0);
1382 * Slave is in action, so now we must wait for the open acknowledgment
1383 * to come back.
1385 rc = 0;
1386 while (test_bit(ST_CLOSING, &portp->state)) {
1387 if (signal_pending(current)) {
1388 rc = -ERESTARTSYS;
1389 break;
1391 interruptible_sleep_on(&portp->raw_wait);
1393 restore_flags(flags);
1395 if ((rc == 0) && (portp->rc != 0))
1396 rc = -EIO;
1397 return(rc);
1400 /*****************************************************************************/
1403 * Send a command to the slave and wait for the response. This must
1404 * have user context (it sleeps). This routine is generic in that it
1405 * can send any type of command. Its purpose is to wait for that command
1406 * to complete (as opposed to initiating the command then returning).
1409 static int stli_cmdwait(stlibrd_t *brdp, stliport_t *portp, unsigned long cmd, void *arg, int size, int copyback)
1411 unsigned long flags;
1413 #if DEBUG
1414 printk("stli_cmdwait(brdp=%x,portp=%x,cmd=%x,arg=%x,size=%d,"
1415 "copyback=%d)\n", (int) brdp, (int) portp, (int) cmd,
1416 (int) arg, size, copyback);
1417 #endif
1419 save_flags(flags);
1420 cli();
1421 while (test_bit(ST_CMDING, &portp->state)) {
1422 if (signal_pending(current)) {
1423 restore_flags(flags);
1424 return(-ERESTARTSYS);
1426 interruptible_sleep_on(&portp->raw_wait);
1429 stli_sendcmd(brdp, portp, cmd, arg, size, copyback);
1431 while (test_bit(ST_CMDING, &portp->state)) {
1432 if (signal_pending(current)) {
1433 restore_flags(flags);
1434 return(-ERESTARTSYS);
1436 interruptible_sleep_on(&portp->raw_wait);
1438 restore_flags(flags);
1440 if (portp->rc != 0)
1441 return(-EIO);
1442 return(0);
1445 /*****************************************************************************/
1448 * Send the termios settings for this port to the slave. This sleeps
1449 * waiting for the command to complete - so must have user context.
1452 static int stli_setport(stliport_t *portp)
1454 stlibrd_t *brdp;
1455 asyport_t aport;
1457 #if DEBUG
1458 printk("stli_setport(portp=%x)\n", (int) portp);
1459 #endif
1461 if (portp == (stliport_t *) NULL)
1462 return(-ENODEV);
1463 if (portp->tty == (struct tty_struct *) NULL)
1464 return(-ENODEV);
1465 if ((portp->brdnr < 0) && (portp->brdnr >= stli_nrbrds))
1466 return(-ENODEV);
1467 brdp = stli_brds[portp->brdnr];
1468 if (brdp == (stlibrd_t *) NULL)
1469 return(-ENODEV);
1471 stli_mkasyport(portp, &aport, portp->tty->termios);
1472 return(stli_cmdwait(brdp, portp, A_SETPORT, &aport, sizeof(asyport_t), 0));
1475 /*****************************************************************************/
1478 * Wait for a specified delay period, this is not a busy-loop. It will
1479 * give up the processor while waiting. Unfortunately this has some
1480 * rather intimate knowledge of the process management stuff.
1483 static void stli_delay(int len)
1485 #if DEBUG
1486 printk("stli_delay(len=%d)\n", len);
1487 #endif
1488 if (len > 0) {
1489 set_current_state(TASK_INTERRUPTIBLE);
1490 schedule_timeout(len);
1494 /*****************************************************************************/
1497 * Possibly need to wait for carrier (DCD signal) to come high. Say
1498 * maybe because if we are clocal then we don't need to wait...
1501 static int stli_waitcarrier(stlibrd_t *brdp, stliport_t *portp, struct file *filp)
1503 unsigned long flags;
1504 int rc, doclocal;
1506 #if DEBUG
1507 printk("stli_waitcarrier(brdp=%x,portp=%x,filp=%x)\n",
1508 (int) brdp, (int) portp, (int) filp);
1509 #endif
1511 rc = 0;
1512 doclocal = 0;
1514 if (portp->tty->termios->c_cflag & CLOCAL)
1515 doclocal++;
1517 save_flags(flags);
1518 cli();
1519 portp->openwaitcnt++;
1520 if (! tty_hung_up_p(filp))
1521 portp->refcount--;
1523 for (;;) {
1524 stli_mkasysigs(&portp->asig, 1, 1);
1525 if ((rc = stli_cmdwait(brdp, portp, A_SETSIGNALS,
1526 &portp->asig, sizeof(asysigs_t), 0)) < 0)
1527 break;
1528 if (tty_hung_up_p(filp) ||
1529 ((portp->flags & ASYNC_INITIALIZED) == 0)) {
1530 if (portp->flags & ASYNC_HUP_NOTIFY)
1531 rc = -EBUSY;
1532 else
1533 rc = -ERESTARTSYS;
1534 break;
1536 if (((portp->flags & ASYNC_CLOSING) == 0) &&
1537 (doclocal || (portp->sigs & TIOCM_CD))) {
1538 break;
1540 if (signal_pending(current)) {
1541 rc = -ERESTARTSYS;
1542 break;
1544 interruptible_sleep_on(&portp->open_wait);
1547 if (! tty_hung_up_p(filp))
1548 portp->refcount++;
1549 portp->openwaitcnt--;
1550 restore_flags(flags);
1552 return(rc);
1555 /*****************************************************************************/
1558 * Write routine. Take the data and put it in the shared memory ring
1559 * queue. If port is not already sending chars then need to mark the
1560 * service bits for this port.
1563 static int stli_write(struct tty_struct *tty, int from_user, const unsigned char *buf, int count)
1565 volatile cdkasy_t *ap;
1566 volatile cdkhdr_t *hdrp;
1567 volatile unsigned char *bits;
1568 unsigned char *shbuf, *chbuf;
1569 stliport_t *portp;
1570 stlibrd_t *brdp;
1571 unsigned int len, stlen, head, tail, size;
1572 unsigned long flags;
1574 #if DEBUG
1575 printk("stli_write(tty=%x,from_user=%d,buf=%x,count=%d)\n",
1576 (int) tty, from_user, (int) buf, count);
1577 #endif
1579 if ((tty == (struct tty_struct *) NULL) ||
1580 (stli_tmpwritebuf == (char *) NULL))
1581 return(0);
1582 if (tty == stli_txcooktty)
1583 stli_flushchars(tty);
1584 portp = tty->driver_data;
1585 if (portp == (stliport_t *) NULL)
1586 return(0);
1587 if ((portp->brdnr < 0) || (portp->brdnr >= stli_nrbrds))
1588 return(0);
1589 brdp = stli_brds[portp->brdnr];
1590 if (brdp == (stlibrd_t *) NULL)
1591 return(0);
1592 chbuf = (unsigned char *) buf;
1595 * If copying direct from user space we need to be able to handle page
1596 * faults while we are copying. To do this copy as much as we can now
1597 * into a kernel buffer. From there we copy it into shared memory. The
1598 * big problem is that we do not want shared memory enabled when we are
1599 * sleeping (other boards may be serviced while asleep). Something else
1600 * to note here is the reading of the tail twice. Since the boards
1601 * shared memory can be on an 8-bit bus then we need to be very careful
1602 * reading 16 bit quantities - since both the board (slave) and host
1603 * could be writing and reading at the same time.
1605 if (from_user) {
1606 save_flags(flags);
1607 cli();
1608 EBRDENABLE(brdp);
1609 ap = (volatile cdkasy_t *) EBRDGETMEMPTR(brdp, portp->addr);
1610 head = (unsigned int) ap->txq.head;
1611 tail = (unsigned int) ap->txq.tail;
1612 if (tail != ((unsigned int) ap->txq.tail))
1613 tail = (unsigned int) ap->txq.tail;
1614 len = (head >= tail) ? (portp->txsize - (head - tail) - 1) :
1615 (tail - head - 1);
1616 count = MIN(len, count);
1617 EBRDDISABLE(brdp);
1618 restore_flags(flags);
1620 down(&stli_tmpwritesem);
1621 if (copy_from_user(stli_tmpwritebuf, chbuf, count))
1622 return -EFAULT;
1623 chbuf = &stli_tmpwritebuf[0];
1627 * All data is now local, shove as much as possible into shared memory.
1629 save_flags(flags);
1630 cli();
1631 EBRDENABLE(brdp);
1632 ap = (volatile cdkasy_t *) EBRDGETMEMPTR(brdp, portp->addr);
1633 head = (unsigned int) ap->txq.head;
1634 tail = (unsigned int) ap->txq.tail;
1635 if (tail != ((unsigned int) ap->txq.tail))
1636 tail = (unsigned int) ap->txq.tail;
1637 size = portp->txsize;
1638 if (head >= tail) {
1639 len = size - (head - tail) - 1;
1640 stlen = size - head;
1641 } else {
1642 len = tail - head - 1;
1643 stlen = len;
1646 len = MIN(len, count);
1647 count = 0;
1648 shbuf = (char *) EBRDGETMEMPTR(brdp, portp->txoffset);
1650 while (len > 0) {
1651 stlen = MIN(len, stlen);
1652 memcpy((shbuf + head), chbuf, stlen);
1653 chbuf += stlen;
1654 len -= stlen;
1655 count += stlen;
1656 head += stlen;
1657 if (head >= size) {
1658 head = 0;
1659 stlen = tail;
1663 ap = (volatile cdkasy_t *) EBRDGETMEMPTR(brdp, portp->addr);
1664 ap->txq.head = head;
1665 if (test_bit(ST_TXBUSY, &portp->state)) {
1666 if (ap->changed.data & DT_TXEMPTY)
1667 ap->changed.data &= ~DT_TXEMPTY;
1669 hdrp = (volatile cdkhdr_t *) EBRDGETMEMPTR(brdp, CDK_CDKADDR);
1670 bits = ((volatile unsigned char *) hdrp) + brdp->slaveoffset +
1671 portp->portidx;
1672 *bits |= portp->portbit;
1673 set_bit(ST_TXBUSY, &portp->state);
1674 EBRDDISABLE(brdp);
1676 if (from_user)
1677 up(&stli_tmpwritesem);
1678 restore_flags(flags);
1680 return(count);
1683 /*****************************************************************************/
1686 * Output a single character. We put it into a temporary local buffer
1687 * (for speed) then write out that buffer when the flushchars routine
1688 * is called. There is a safety catch here so that if some other port
1689 * writes chars before the current buffer has been, then we write them
1690 * first them do the new ports.
1693 static void stli_putchar(struct tty_struct *tty, unsigned char ch)
1695 #if DEBUG
1696 printk("stli_putchar(tty=%x,ch=%x)\n", (int) tty, (int) ch);
1697 #endif
1699 if (tty == (struct tty_struct *) NULL)
1700 return;
1701 if (tty != stli_txcooktty) {
1702 if (stli_txcooktty != (struct tty_struct *) NULL)
1703 stli_flushchars(stli_txcooktty);
1704 stli_txcooktty = tty;
1707 stli_txcookbuf[stli_txcooksize++] = ch;
1710 /*****************************************************************************/
1713 * Transfer characters from the local TX cooking buffer to the board.
1714 * We sort of ignore the tty that gets passed in here. We rely on the
1715 * info stored with the TX cook buffer to tell us which port to flush
1716 * the data on. In any case we clean out the TX cook buffer, for re-use
1717 * by someone else.
1720 static void stli_flushchars(struct tty_struct *tty)
1722 volatile cdkhdr_t *hdrp;
1723 volatile unsigned char *bits;
1724 volatile cdkasy_t *ap;
1725 struct tty_struct *cooktty;
1726 stliport_t *portp;
1727 stlibrd_t *brdp;
1728 unsigned int len, stlen, head, tail, size, count, cooksize;
1729 unsigned char *buf, *shbuf;
1730 unsigned long flags;
1732 #if DEBUG
1733 printk("stli_flushchars(tty=%x)\n", (int) tty);
1734 #endif
1736 cooksize = stli_txcooksize;
1737 cooktty = stli_txcooktty;
1738 stli_txcooksize = 0;
1739 stli_txcookrealsize = 0;
1740 stli_txcooktty = (struct tty_struct *) NULL;
1742 if (tty == (struct tty_struct *) NULL)
1743 return;
1744 if (cooktty == (struct tty_struct *) NULL)
1745 return;
1746 if (tty != cooktty)
1747 tty = cooktty;
1748 if (cooksize == 0)
1749 return;
1751 portp = tty->driver_data;
1752 if (portp == (stliport_t *) NULL)
1753 return;
1754 if ((portp->brdnr < 0) || (portp->brdnr >= stli_nrbrds))
1755 return;
1756 brdp = stli_brds[portp->brdnr];
1757 if (brdp == (stlibrd_t *) NULL)
1758 return;
1760 save_flags(flags);
1761 cli();
1762 EBRDENABLE(brdp);
1764 ap = (volatile cdkasy_t *) EBRDGETMEMPTR(brdp, portp->addr);
1765 head = (unsigned int) ap->txq.head;
1766 tail = (unsigned int) ap->txq.tail;
1767 if (tail != ((unsigned int) ap->txq.tail))
1768 tail = (unsigned int) ap->txq.tail;
1769 size = portp->txsize;
1770 if (head >= tail) {
1771 len = size - (head - tail) - 1;
1772 stlen = size - head;
1773 } else {
1774 len = tail - head - 1;
1775 stlen = len;
1778 len = MIN(len, cooksize);
1779 count = 0;
1780 shbuf = (char *) EBRDGETMEMPTR(brdp, portp->txoffset);
1781 buf = stli_txcookbuf;
1783 while (len > 0) {
1784 stlen = MIN(len, stlen);
1785 memcpy((shbuf + head), buf, stlen);
1786 buf += stlen;
1787 len -= stlen;
1788 count += stlen;
1789 head += stlen;
1790 if (head >= size) {
1791 head = 0;
1792 stlen = tail;
1796 ap = (volatile cdkasy_t *) EBRDGETMEMPTR(brdp, portp->addr);
1797 ap->txq.head = head;
1799 if (test_bit(ST_TXBUSY, &portp->state)) {
1800 if (ap->changed.data & DT_TXEMPTY)
1801 ap->changed.data &= ~DT_TXEMPTY;
1803 hdrp = (volatile cdkhdr_t *) EBRDGETMEMPTR(brdp, CDK_CDKADDR);
1804 bits = ((volatile unsigned char *) hdrp) + brdp->slaveoffset +
1805 portp->portidx;
1806 *bits |= portp->portbit;
1807 set_bit(ST_TXBUSY, &portp->state);
1809 EBRDDISABLE(brdp);
1810 restore_flags(flags);
1813 /*****************************************************************************/
1815 static int stli_writeroom(struct tty_struct *tty)
1817 volatile cdkasyrq_t *rp;
1818 stliport_t *portp;
1819 stlibrd_t *brdp;
1820 unsigned int head, tail, len;
1821 unsigned long flags;
1823 #if DEBUG
1824 printk("stli_writeroom(tty=%x)\n", (int) tty);
1825 #endif
1827 if (tty == (struct tty_struct *) NULL)
1828 return(0);
1829 if (tty == stli_txcooktty) {
1830 if (stli_txcookrealsize != 0) {
1831 len = stli_txcookrealsize - stli_txcooksize;
1832 return(len);
1836 portp = tty->driver_data;
1837 if (portp == (stliport_t *) NULL)
1838 return(0);
1839 if ((portp->brdnr < 0) || (portp->brdnr >= stli_nrbrds))
1840 return(0);
1841 brdp = stli_brds[portp->brdnr];
1842 if (brdp == (stlibrd_t *) NULL)
1843 return(0);
1845 save_flags(flags);
1846 cli();
1847 EBRDENABLE(brdp);
1848 rp = &((volatile cdkasy_t *) EBRDGETMEMPTR(brdp, portp->addr))->txq;
1849 head = (unsigned int) rp->head;
1850 tail = (unsigned int) rp->tail;
1851 if (tail != ((unsigned int) rp->tail))
1852 tail = (unsigned int) rp->tail;
1853 len = (head >= tail) ? (portp->txsize - (head - tail)) : (tail - head);
1854 len--;
1855 EBRDDISABLE(brdp);
1856 restore_flags(flags);
1858 if (tty == stli_txcooktty) {
1859 stli_txcookrealsize = len;
1860 len -= stli_txcooksize;
1862 return(len);
1865 /*****************************************************************************/
1868 * Return the number of characters in the transmit buffer. Normally we
1869 * will return the number of chars in the shared memory ring queue.
1870 * We need to kludge around the case where the shared memory buffer is
1871 * empty but not all characters have drained yet, for this case just
1872 * return that there is 1 character in the buffer!
1875 static int stli_charsinbuffer(struct tty_struct *tty)
1877 volatile cdkasyrq_t *rp;
1878 stliport_t *portp;
1879 stlibrd_t *brdp;
1880 unsigned int head, tail, len;
1881 unsigned long flags;
1883 #if DEBUG
1884 printk("stli_charsinbuffer(tty=%x)\n", (int) tty);
1885 #endif
1887 if (tty == (struct tty_struct *) NULL)
1888 return(0);
1889 if (tty == stli_txcooktty)
1890 stli_flushchars(tty);
1891 portp = tty->driver_data;
1892 if (portp == (stliport_t *) NULL)
1893 return(0);
1894 if ((portp->brdnr < 0) || (portp->brdnr >= stli_nrbrds))
1895 return(0);
1896 brdp = stli_brds[portp->brdnr];
1897 if (brdp == (stlibrd_t *) NULL)
1898 return(0);
1900 save_flags(flags);
1901 cli();
1902 EBRDENABLE(brdp);
1903 rp = &((volatile cdkasy_t *) EBRDGETMEMPTR(brdp, portp->addr))->txq;
1904 head = (unsigned int) rp->head;
1905 tail = (unsigned int) rp->tail;
1906 if (tail != ((unsigned int) rp->tail))
1907 tail = (unsigned int) rp->tail;
1908 len = (head >= tail) ? (head - tail) : (portp->txsize - (tail - head));
1909 if ((len == 0) && test_bit(ST_TXBUSY, &portp->state))
1910 len = 1;
1911 EBRDDISABLE(brdp);
1912 restore_flags(flags);
1914 return(len);
1917 /*****************************************************************************/
1920 * Generate the serial struct info.
1923 static int stli_getserial(stliport_t *portp, struct serial_struct *sp)
1925 struct serial_struct sio;
1926 stlibrd_t *brdp;
1928 #if DEBUG
1929 printk("stli_getserial(portp=%x,sp=%x)\n", (int) portp, (int) sp);
1930 #endif
1932 memset(&sio, 0, sizeof(struct serial_struct));
1933 sio.type = PORT_UNKNOWN;
1934 sio.line = portp->portnr;
1935 sio.irq = 0;
1936 sio.flags = portp->flags;
1937 sio.baud_base = portp->baud_base;
1938 sio.close_delay = portp->close_delay;
1939 sio.closing_wait = portp->closing_wait;
1940 sio.custom_divisor = portp->custom_divisor;
1941 sio.xmit_fifo_size = 0;
1942 sio.hub6 = 0;
1944 brdp = stli_brds[portp->brdnr];
1945 if (brdp != (stlibrd_t *) NULL)
1946 sio.port = brdp->iobase;
1948 return copy_to_user(sp, &sio, sizeof(struct serial_struct)) ?
1949 -EFAULT : 0;
1952 /*****************************************************************************/
1955 * Set port according to the serial struct info.
1956 * At this point we do not do any auto-configure stuff, so we will
1957 * just quietly ignore any requests to change irq, etc.
1960 static int stli_setserial(stliport_t *portp, struct serial_struct *sp)
1962 struct serial_struct sio;
1963 int rc;
1965 #if DEBUG
1966 printk("stli_setserial(portp=%x,sp=%x)\n", (int) portp, (int) sp);
1967 #endif
1969 if (copy_from_user(&sio, sp, sizeof(struct serial_struct)))
1970 return -EFAULT;
1971 if (!capable(CAP_SYS_ADMIN)) {
1972 if ((sio.baud_base != portp->baud_base) ||
1973 (sio.close_delay != portp->close_delay) ||
1974 ((sio.flags & ~ASYNC_USR_MASK) !=
1975 (portp->flags & ~ASYNC_USR_MASK)))
1976 return(-EPERM);
1979 portp->flags = (portp->flags & ~ASYNC_USR_MASK) |
1980 (sio.flags & ASYNC_USR_MASK);
1981 portp->baud_base = sio.baud_base;
1982 portp->close_delay = sio.close_delay;
1983 portp->closing_wait = sio.closing_wait;
1984 portp->custom_divisor = sio.custom_divisor;
1986 if ((rc = stli_setport(portp)) < 0)
1987 return(rc);
1988 return(0);
1991 /*****************************************************************************/
1993 static int stli_ioctl(struct tty_struct *tty, struct file *file, unsigned int cmd, unsigned long arg)
1995 stliport_t *portp;
1996 stlibrd_t *brdp;
1997 unsigned long lval;
1998 unsigned int ival;
1999 int rc;
2001 #if DEBUG
2002 printk("stli_ioctl(tty=%x,file=%x,cmd=%x,arg=%x)\n",
2003 (int) tty, (int) file, cmd, (int) arg);
2004 #endif
2006 if (tty == (struct tty_struct *) NULL)
2007 return(-ENODEV);
2008 portp = tty->driver_data;
2009 if (portp == (stliport_t *) NULL)
2010 return(-ENODEV);
2011 if ((portp->brdnr < 0) || (portp->brdnr >= stli_nrbrds))
2012 return(0);
2013 brdp = stli_brds[portp->brdnr];
2014 if (brdp == (stlibrd_t *) NULL)
2015 return(0);
2017 if ((cmd != TIOCGSERIAL) && (cmd != TIOCSSERIAL) &&
2018 (cmd != COM_GETPORTSTATS) && (cmd != COM_CLRPORTSTATS)) {
2019 if (tty->flags & (1 << TTY_IO_ERROR))
2020 return(-EIO);
2023 rc = 0;
2025 switch (cmd) {
2026 case TIOCGSOFTCAR:
2027 rc = put_user(((tty->termios->c_cflag & CLOCAL) ? 1 : 0),
2028 (unsigned int *) arg);
2029 break;
2030 case TIOCSSOFTCAR:
2031 if ((rc = get_user(ival, (unsigned int *) arg)) == 0)
2032 tty->termios->c_cflag =
2033 (tty->termios->c_cflag & ~CLOCAL) |
2034 (ival ? CLOCAL : 0);
2035 break;
2036 case TIOCMGET:
2037 if ((rc = verify_area(VERIFY_WRITE, (void *) arg,
2038 sizeof(unsigned int))) == 0) {
2039 if ((rc = stli_cmdwait(brdp, portp, A_GETSIGNALS,
2040 &portp->asig, sizeof(asysigs_t), 1)) < 0)
2041 return(rc);
2042 lval = stli_mktiocm(portp->asig.sigvalue);
2043 put_user(lval, (unsigned int *) arg);
2045 break;
2046 case TIOCMBIS:
2047 if ((rc = get_user(ival, (unsigned int *) arg)) == 0) {
2048 stli_mkasysigs(&portp->asig,
2049 ((ival & TIOCM_DTR) ? 1 : -1),
2050 ((ival & TIOCM_RTS) ? 1 : -1));
2051 rc = stli_cmdwait(brdp, portp, A_SETSIGNALS,
2052 &portp->asig, sizeof(asysigs_t), 0);
2054 break;
2055 case TIOCMBIC:
2056 if ((rc = get_user(ival, (unsigned int *) arg)) == 0) {
2057 stli_mkasysigs(&portp->asig,
2058 ((ival & TIOCM_DTR) ? 0 : -1),
2059 ((ival & TIOCM_RTS) ? 0 : -1));
2060 rc = stli_cmdwait(brdp, portp, A_SETSIGNALS,
2061 &portp->asig, sizeof(asysigs_t), 0);
2063 break;
2064 case TIOCMSET:
2065 if ((rc = get_user(ival, (unsigned int *) arg)) == 0) {
2066 stli_mkasysigs(&portp->asig,
2067 ((ival & TIOCM_DTR) ? 1 : 0),
2068 ((ival & TIOCM_RTS) ? 1 : 0));
2069 rc = stli_cmdwait(brdp, portp, A_SETSIGNALS,
2070 &portp->asig, sizeof(asysigs_t), 0);
2072 break;
2073 case TIOCGSERIAL:
2074 if ((rc = verify_area(VERIFY_WRITE, (void *) arg,
2075 sizeof(struct serial_struct))) == 0)
2076 rc = stli_getserial(portp, (struct serial_struct *) arg);
2077 break;
2078 case TIOCSSERIAL:
2079 if ((rc = verify_area(VERIFY_READ, (void *) arg,
2080 sizeof(struct serial_struct))) == 0)
2081 rc = stli_setserial(portp, (struct serial_struct *)arg);
2082 break;
2083 case STL_GETPFLAG:
2084 rc = put_user(portp->pflag, (unsigned int *) arg);
2085 break;
2086 case STL_SETPFLAG:
2087 if ((rc = get_user(portp->pflag, (unsigned int *) arg)) == 0)
2088 stli_setport(portp);
2089 break;
2090 case COM_GETPORTSTATS:
2091 if ((rc = verify_area(VERIFY_WRITE, (void *) arg,
2092 sizeof(comstats_t))) == 0)
2093 rc = stli_getportstats(portp, (comstats_t *) arg);
2094 break;
2095 case COM_CLRPORTSTATS:
2096 if ((rc = verify_area(VERIFY_WRITE, (void *) arg,
2097 sizeof(comstats_t))) == 0)
2098 rc = stli_clrportstats(portp, (comstats_t *) arg);
2099 break;
2100 case TIOCSERCONFIG:
2101 case TIOCSERGWILD:
2102 case TIOCSERSWILD:
2103 case TIOCSERGETLSR:
2104 case TIOCSERGSTRUCT:
2105 case TIOCSERGETMULTI:
2106 case TIOCSERSETMULTI:
2107 default:
2108 rc = -ENOIOCTLCMD;
2109 break;
2112 return(rc);
2115 /*****************************************************************************/
2118 * This routine assumes that we have user context and can sleep.
2119 * Looks like it is true for the current ttys implementation..!!
2122 static void stli_settermios(struct tty_struct *tty, struct termios *old)
2124 stliport_t *portp;
2125 stlibrd_t *brdp;
2126 struct termios *tiosp;
2127 asyport_t aport;
2129 #if DEBUG
2130 printk("stli_settermios(tty=%x,old=%x)\n", (int) tty, (int) old);
2131 #endif
2133 if (tty == (struct tty_struct *) NULL)
2134 return;
2135 portp = tty->driver_data;
2136 if (portp == (stliport_t *) NULL)
2137 return;
2138 if ((portp->brdnr < 0) || (portp->brdnr >= stli_nrbrds))
2139 return;
2140 brdp = stli_brds[portp->brdnr];
2141 if (brdp == (stlibrd_t *) NULL)
2142 return;
2144 tiosp = tty->termios;
2145 if ((tiosp->c_cflag == old->c_cflag) &&
2146 (tiosp->c_iflag == old->c_iflag))
2147 return;
2149 stli_mkasyport(portp, &aport, tiosp);
2150 stli_cmdwait(brdp, portp, A_SETPORT, &aport, sizeof(asyport_t), 0);
2151 stli_mkasysigs(&portp->asig, ((tiosp->c_cflag & CBAUD) ? 1 : 0), -1);
2152 stli_cmdwait(brdp, portp, A_SETSIGNALS, &portp->asig,
2153 sizeof(asysigs_t), 0);
2154 if ((old->c_cflag & CRTSCTS) && ((tiosp->c_cflag & CRTSCTS) == 0))
2155 tty->hw_stopped = 0;
2156 if (((old->c_cflag & CLOCAL) == 0) && (tiosp->c_cflag & CLOCAL))
2157 wake_up_interruptible(&portp->open_wait);
2160 /*****************************************************************************/
2163 * Attempt to flow control who ever is sending us data. We won't really
2164 * do any flow control action here. We can't directly, and even if we
2165 * wanted to we would have to send a command to the slave. The slave
2166 * knows how to flow control, and will do so when its buffers reach its
2167 * internal high water marks. So what we will do is set a local state
2168 * bit that will stop us sending any RX data up from the poll routine
2169 * (which is the place where RX data from the slave is handled).
2172 static void stli_throttle(struct tty_struct *tty)
2174 stliport_t *portp;
2176 #if DEBUG
2177 printk("stli_throttle(tty=%x)\n", (int) tty);
2178 #endif
2180 if (tty == (struct tty_struct *) NULL)
2181 return;
2182 portp = tty->driver_data;
2183 if (portp == (stliport_t *) NULL)
2184 return;
2186 set_bit(ST_RXSTOP, &portp->state);
2189 /*****************************************************************************/
2192 * Unflow control the device sending us data... That means that all
2193 * we have to do is clear the RXSTOP state bit. The next poll call
2194 * will then be able to pass the RX data back up.
2197 static void stli_unthrottle(struct tty_struct *tty)
2199 stliport_t *portp;
2201 #if DEBUG
2202 printk("stli_unthrottle(tty=%x)\n", (int) tty);
2203 #endif
2205 if (tty == (struct tty_struct *) NULL)
2206 return;
2207 portp = tty->driver_data;
2208 if (portp == (stliport_t *) NULL)
2209 return;
2211 clear_bit(ST_RXSTOP, &portp->state);
2214 /*****************************************************************************/
2217 * Stop the transmitter. Basically to do this we will just turn TX
2218 * interrupts off.
2221 static void stli_stop(struct tty_struct *tty)
2223 stlibrd_t *brdp;
2224 stliport_t *portp;
2225 asyctrl_t actrl;
2227 #if DEBUG
2228 printk("stli_stop(tty=%x)\n", (int) tty);
2229 #endif
2231 if (tty == (struct tty_struct *) NULL)
2232 return;
2233 portp = tty->driver_data;
2234 if (portp == (stliport_t *) NULL)
2235 return;
2236 if ((portp->brdnr < 0) || (portp->brdnr >= stli_nrbrds))
2237 return;
2238 brdp = stli_brds[portp->brdnr];
2239 if (brdp == (stlibrd_t *) NULL)
2240 return;
2242 memset(&actrl, 0, sizeof(asyctrl_t));
2243 actrl.txctrl = CT_STOPFLOW;
2244 #if 0
2245 stli_cmdwait(brdp, portp, A_PORTCTRL, &actrl, sizeof(asyctrl_t), 0);
2246 #endif
2249 /*****************************************************************************/
2252 * Start the transmitter again. Just turn TX interrupts back on.
2255 static void stli_start(struct tty_struct *tty)
2257 stliport_t *portp;
2258 stlibrd_t *brdp;
2259 asyctrl_t actrl;
2261 #if DEBUG
2262 printk("stli_start(tty=%x)\n", (int) tty);
2263 #endif
2265 if (tty == (struct tty_struct *) NULL)
2266 return;
2267 portp = tty->driver_data;
2268 if (portp == (stliport_t *) NULL)
2269 return;
2270 if ((portp->brdnr < 0) || (portp->brdnr >= stli_nrbrds))
2271 return;
2272 brdp = stli_brds[portp->brdnr];
2273 if (brdp == (stlibrd_t *) NULL)
2274 return;
2276 memset(&actrl, 0, sizeof(asyctrl_t));
2277 actrl.txctrl = CT_STARTFLOW;
2278 #if 0
2279 stli_cmdwait(brdp, portp, A_PORTCTRL, &actrl, sizeof(asyctrl_t), 0);
2280 #endif
2283 /*****************************************************************************/
2286 * Scheduler called hang up routine. This is called from the scheduler,
2287 * not direct from the driver "poll" routine. We can't call it there
2288 * since the real local hangup code will enable/disable the board and
2289 * other things that we can't do while handling the poll. Much easier
2290 * to deal with it some time later (don't really care when, hangups
2291 * aren't that time critical).
2294 static void stli_dohangup(void *arg)
2296 stliport_t *portp;
2298 #if DEBUG
2299 printk(KERN_DEBUG "stli_dohangup(portp=%x)\n", (int) arg);
2300 #endif
2303 * FIXME: There's a module removal race here: tty_hangup
2304 * calls schedule_work which will call into this
2305 * driver later.
2307 portp = (stliport_t *) arg;
2308 if (portp != (stliport_t *) NULL) {
2309 if (portp->tty != (struct tty_struct *) NULL) {
2310 tty_hangup(portp->tty);
2315 /*****************************************************************************/
2318 * Hangup this port. This is pretty much like closing the port, only
2319 * a little more brutal. No waiting for data to drain. Shutdown the
2320 * port and maybe drop signals. This is rather tricky really. We want
2321 * to close the port as well.
2324 static void stli_hangup(struct tty_struct *tty)
2326 stliport_t *portp;
2327 stlibrd_t *brdp;
2328 unsigned long flags;
2330 #if DEBUG
2331 printk(KERN_DEBUG "stli_hangup(tty=%x)\n", (int) tty);
2332 #endif
2334 if (tty == (struct tty_struct *) NULL)
2335 return;
2336 portp = tty->driver_data;
2337 if (portp == (stliport_t *) NULL)
2338 return;
2339 if ((portp->brdnr < 0) || (portp->brdnr >= stli_nrbrds))
2340 return;
2341 brdp = stli_brds[portp->brdnr];
2342 if (brdp == (stlibrd_t *) NULL)
2343 return;
2345 portp->flags &= ~ASYNC_INITIALIZED;
2347 save_flags(flags);
2348 cli();
2349 if (! test_bit(ST_CLOSING, &portp->state))
2350 stli_rawclose(brdp, portp, 0, 0);
2351 if (tty->termios->c_cflag & HUPCL) {
2352 stli_mkasysigs(&portp->asig, 0, 0);
2353 if (test_bit(ST_CMDING, &portp->state)) {
2354 set_bit(ST_DOSIGS, &portp->state);
2355 set_bit(ST_DOFLUSHTX, &portp->state);
2356 set_bit(ST_DOFLUSHRX, &portp->state);
2357 } else {
2358 stli_sendcmd(brdp, portp, A_SETSIGNALSF,
2359 &portp->asig, sizeof(asysigs_t), 0);
2362 restore_flags(flags);
2364 clear_bit(ST_TXBUSY, &portp->state);
2365 clear_bit(ST_RXSTOP, &portp->state);
2366 set_bit(TTY_IO_ERROR, &tty->flags);
2367 portp->tty = (struct tty_struct *) NULL;
2368 portp->flags &= ~ASYNC_NORMAL_ACTIVE;
2369 portp->refcount = 0;
2370 wake_up_interruptible(&portp->open_wait);
2373 /*****************************************************************************/
2376 * Flush characters from the lower buffer. We may not have user context
2377 * so we cannot sleep waiting for it to complete. Also we need to check
2378 * if there is chars for this port in the TX cook buffer, and flush them
2379 * as well.
2382 static void stli_flushbuffer(struct tty_struct *tty)
2384 stliport_t *portp;
2385 stlibrd_t *brdp;
2386 unsigned long ftype, flags;
2388 #if DEBUG
2389 printk(KERN_DEBUG "stli_flushbuffer(tty=%x)\n", (int) tty);
2390 #endif
2392 if (tty == (struct tty_struct *) NULL)
2393 return;
2394 portp = tty->driver_data;
2395 if (portp == (stliport_t *) NULL)
2396 return;
2397 if ((portp->brdnr < 0) || (portp->brdnr >= stli_nrbrds))
2398 return;
2399 brdp = stli_brds[portp->brdnr];
2400 if (brdp == (stlibrd_t *) NULL)
2401 return;
2403 save_flags(flags);
2404 cli();
2405 if (tty == stli_txcooktty) {
2406 stli_txcooktty = (struct tty_struct *) NULL;
2407 stli_txcooksize = 0;
2408 stli_txcookrealsize = 0;
2410 if (test_bit(ST_CMDING, &portp->state)) {
2411 set_bit(ST_DOFLUSHTX, &portp->state);
2412 } else {
2413 ftype = FLUSHTX;
2414 if (test_bit(ST_DOFLUSHRX, &portp->state)) {
2415 ftype |= FLUSHRX;
2416 clear_bit(ST_DOFLUSHRX, &portp->state);
2418 stli_sendcmd(brdp, portp, A_FLUSH, &ftype,
2419 sizeof(unsigned long), 0);
2421 restore_flags(flags);
2423 wake_up_interruptible(&tty->write_wait);
2424 if ((tty->flags & (1 << TTY_DO_WRITE_WAKEUP)) &&
2425 tty->ldisc.write_wakeup)
2426 (tty->ldisc.write_wakeup)(tty);
2429 /*****************************************************************************/
2431 static void stli_breakctl(struct tty_struct *tty, int state)
2433 stlibrd_t *brdp;
2434 stliport_t *portp;
2435 long arg;
2436 /* long savestate, savetime; */
2438 #if DEBUG
2439 printk(KERN_DEBUG "stli_breakctl(tty=%x,state=%d)\n", (int) tty, state);
2440 #endif
2442 if (tty == (struct tty_struct *) NULL)
2443 return;
2444 portp = tty->driver_data;
2445 if (portp == (stliport_t *) NULL)
2446 return;
2447 if ((portp->brdnr < 0) || (portp->brdnr >= stli_nrbrds))
2448 return;
2449 brdp = stli_brds[portp->brdnr];
2450 if (brdp == (stlibrd_t *) NULL)
2451 return;
2454 * Due to a bug in the tty send_break() code we need to preserve
2455 * the current process state and timeout...
2456 savetime = current->timeout;
2457 savestate = current->state;
2460 arg = (state == -1) ? BREAKON : BREAKOFF;
2461 stli_cmdwait(brdp, portp, A_BREAK, &arg, sizeof(long), 0);
2465 current->timeout = savetime;
2466 current->state = savestate;
2470 /*****************************************************************************/
2472 static void stli_waituntilsent(struct tty_struct *tty, int timeout)
2474 stliport_t *portp;
2475 unsigned long tend;
2477 #if DEBUG
2478 printk(KERN_DEBUG "stli_waituntilsent(tty=%x,timeout=%x)\n", (int) tty, timeout);
2479 #endif
2481 if (tty == (struct tty_struct *) NULL)
2482 return;
2483 portp = tty->driver_data;
2484 if (portp == (stliport_t *) NULL)
2485 return;
2487 if (timeout == 0)
2488 timeout = HZ;
2489 tend = jiffies + timeout;
2491 while (test_bit(ST_TXBUSY, &portp->state)) {
2492 if (signal_pending(current))
2493 break;
2494 stli_delay(2);
2495 if (time_after_eq(jiffies, tend))
2496 break;
2500 /*****************************************************************************/
2502 static void stli_sendxchar(struct tty_struct *tty, char ch)
2504 stlibrd_t *brdp;
2505 stliport_t *portp;
2506 asyctrl_t actrl;
2508 #if DEBUG
2509 printk(KERN_DEBUG "stli_sendxchar(tty=%x,ch=%x)\n", (int) tty, ch);
2510 #endif
2512 if (tty == (struct tty_struct *) NULL)
2513 return;
2514 portp = tty->driver_data;
2515 if (portp == (stliport_t *) NULL)
2516 return;
2517 if ((portp->brdnr < 0) || (portp->brdnr >= stli_nrbrds))
2518 return;
2519 brdp = stli_brds[portp->brdnr];
2520 if (brdp == (stlibrd_t *) NULL)
2521 return;
2523 memset(&actrl, 0, sizeof(asyctrl_t));
2524 if (ch == STOP_CHAR(tty)) {
2525 actrl.rxctrl = CT_STOPFLOW;
2526 } else if (ch == START_CHAR(tty)) {
2527 actrl.rxctrl = CT_STARTFLOW;
2528 } else {
2529 actrl.txctrl = CT_SENDCHR;
2530 actrl.tximdch = ch;
2533 stli_cmdwait(brdp, portp, A_PORTCTRL, &actrl, sizeof(asyctrl_t), 0);
2536 /*****************************************************************************/
2538 #define MAXLINE 80
2541 * Format info for a specified port. The line is deliberately limited
2542 * to 80 characters. (If it is too long it will be truncated, if too
2543 * short then padded with spaces).
2546 static int stli_portinfo(stlibrd_t *brdp, stliport_t *portp, int portnr, char *pos)
2548 char *sp, *uart;
2549 int rc, cnt;
2551 rc = stli_portcmdstats(portp);
2553 uart = "UNKNOWN";
2554 if (brdp->state & BST_STARTED) {
2555 switch (stli_comstats.hwid) {
2556 case 0: uart = "2681"; break;
2557 case 1: uart = "SC26198"; break;
2558 default: uart = "CD1400"; break;
2562 sp = pos;
2563 sp += sprintf(sp, "%d: uart:%s ", portnr, uart);
2565 if ((brdp->state & BST_STARTED) && (rc >= 0)) {
2566 sp += sprintf(sp, "tx:%d rx:%d", (int) stli_comstats.txtotal,
2567 (int) stli_comstats.rxtotal);
2569 if (stli_comstats.rxframing)
2570 sp += sprintf(sp, " fe:%d",
2571 (int) stli_comstats.rxframing);
2572 if (stli_comstats.rxparity)
2573 sp += sprintf(sp, " pe:%d",
2574 (int) stli_comstats.rxparity);
2575 if (stli_comstats.rxbreaks)
2576 sp += sprintf(sp, " brk:%d",
2577 (int) stli_comstats.rxbreaks);
2578 if (stli_comstats.rxoverrun)
2579 sp += sprintf(sp, " oe:%d",
2580 (int) stli_comstats.rxoverrun);
2582 cnt = sprintf(sp, "%s%s%s%s%s ",
2583 (stli_comstats.signals & TIOCM_RTS) ? "|RTS" : "",
2584 (stli_comstats.signals & TIOCM_CTS) ? "|CTS" : "",
2585 (stli_comstats.signals & TIOCM_DTR) ? "|DTR" : "",
2586 (stli_comstats.signals & TIOCM_CD) ? "|DCD" : "",
2587 (stli_comstats.signals & TIOCM_DSR) ? "|DSR" : "");
2588 *sp = ' ';
2589 sp += cnt;
2592 for (cnt = (sp - pos); (cnt < (MAXLINE - 1)); cnt++)
2593 *sp++ = ' ';
2594 if (cnt >= MAXLINE)
2595 pos[(MAXLINE - 2)] = '+';
2596 pos[(MAXLINE - 1)] = '\n';
2598 return(MAXLINE);
2601 /*****************************************************************************/
2604 * Port info, read from the /proc file system.
2607 static int stli_readproc(char *page, char **start, off_t off, int count, int *eof, void *data)
2609 stlibrd_t *brdp;
2610 stliport_t *portp;
2611 int brdnr, portnr, totalport;
2612 int curoff, maxoff;
2613 char *pos;
2615 #if DEBUG
2616 printk(KERN_DEBUG "stli_readproc(page=%x,start=%x,off=%x,count=%d,eof=%x,"
2617 "data=%x\n", (int) page, (int) start, (int) off, count,
2618 (int) eof, (int) data);
2619 #endif
2621 pos = page;
2622 totalport = 0;
2623 curoff = 0;
2625 if (off == 0) {
2626 pos += sprintf(pos, "%s: version %s", stli_drvtitle,
2627 stli_drvversion);
2628 while (pos < (page + MAXLINE - 1))
2629 *pos++ = ' ';
2630 *pos++ = '\n';
2632 curoff = MAXLINE;
2635 * We scan through for each board, panel and port. The offset is
2636 * calculated on the fly, and irrelevant ports are skipped.
2638 for (brdnr = 0; (brdnr < stli_nrbrds); brdnr++) {
2639 brdp = stli_brds[brdnr];
2640 if (brdp == (stlibrd_t *) NULL)
2641 continue;
2642 if (brdp->state == 0)
2643 continue;
2645 maxoff = curoff + (brdp->nrports * MAXLINE);
2646 if (off >= maxoff) {
2647 curoff = maxoff;
2648 continue;
2651 totalport = brdnr * STL_MAXPORTS;
2652 for (portnr = 0; (portnr < brdp->nrports); portnr++,
2653 totalport++) {
2654 portp = brdp->ports[portnr];
2655 if (portp == (stliport_t *) NULL)
2656 continue;
2657 if (off >= (curoff += MAXLINE))
2658 continue;
2659 if ((pos - page + MAXLINE) > count)
2660 goto stli_readdone;
2661 pos += stli_portinfo(brdp, portp, totalport, pos);
2665 *eof = 1;
2667 stli_readdone:
2668 *start = page;
2669 return(pos - page);
2672 /*****************************************************************************/
2675 * Generic send command routine. This will send a message to the slave,
2676 * of the specified type with the specified argument. Must be very
2677 * careful of data that will be copied out from shared memory -
2678 * containing command results. The command completion is all done from
2679 * a poll routine that does not have user context. Therefore you cannot
2680 * copy back directly into user space, or to the kernel stack of a
2681 * process. This routine does not sleep, so can be called from anywhere.
2684 static void stli_sendcmd(stlibrd_t *brdp, stliport_t *portp, unsigned long cmd, void *arg, int size, int copyback)
2686 volatile cdkhdr_t *hdrp;
2687 volatile cdkctrl_t *cp;
2688 volatile unsigned char *bits;
2689 unsigned long flags;
2691 #if DEBUG
2692 printk(KERN_DEBUG "stli_sendcmd(brdp=%x,portp=%x,cmd=%x,arg=%x,size=%d,"
2693 "copyback=%d)\n", (int) brdp, (int) portp, (int) cmd,
2694 (int) arg, size, copyback);
2695 #endif
2697 save_flags(flags);
2698 cli();
2700 if (test_bit(ST_CMDING, &portp->state)) {
2701 printk(KERN_ERR "STALLION: command already busy, cmd=%x!\n",
2702 (int) cmd);
2703 restore_flags(flags);
2704 return;
2707 EBRDENABLE(brdp);
2708 cp = &((volatile cdkasy_t *) EBRDGETMEMPTR(brdp, portp->addr))->ctrl;
2709 if (size > 0) {
2710 memcpy((void *) &(cp->args[0]), arg, size);
2711 if (copyback) {
2712 portp->argp = arg;
2713 portp->argsize = size;
2716 cp->status = 0;
2717 cp->cmd = cmd;
2718 hdrp = (volatile cdkhdr_t *) EBRDGETMEMPTR(brdp, CDK_CDKADDR);
2719 bits = ((volatile unsigned char *) hdrp) + brdp->slaveoffset +
2720 portp->portidx;
2721 *bits |= portp->portbit;
2722 set_bit(ST_CMDING, &portp->state);
2723 EBRDDISABLE(brdp);
2724 restore_flags(flags);
2727 /*****************************************************************************/
2730 * Read data from shared memory. This assumes that the shared memory
2731 * is enabled and that interrupts are off. Basically we just empty out
2732 * the shared memory buffer into the tty buffer. Must be careful to
2733 * handle the case where we fill up the tty buffer, but still have
2734 * more chars to unload.
2737 static inline void stli_read(stlibrd_t *brdp, stliport_t *portp)
2739 volatile cdkasyrq_t *rp;
2740 volatile char *shbuf;
2741 struct tty_struct *tty;
2742 unsigned int head, tail, size;
2743 unsigned int len, stlen;
2745 #if DEBUG
2746 printk(KERN_DEBUG "stli_read(brdp=%x,portp=%d)\n",
2747 (int) brdp, (int) portp);
2748 #endif
2750 if (test_bit(ST_RXSTOP, &portp->state))
2751 return;
2752 tty = portp->tty;
2753 if (tty == (struct tty_struct *) NULL)
2754 return;
2756 rp = &((volatile cdkasy_t *) EBRDGETMEMPTR(brdp, portp->addr))->rxq;
2757 head = (unsigned int) rp->head;
2758 if (head != ((unsigned int) rp->head))
2759 head = (unsigned int) rp->head;
2760 tail = (unsigned int) rp->tail;
2761 size = portp->rxsize;
2762 if (head >= tail) {
2763 len = head - tail;
2764 stlen = len;
2765 } else {
2766 len = size - (tail - head);
2767 stlen = size - tail;
2770 len = MIN(len, (TTY_FLIPBUF_SIZE - tty->flip.count));
2771 shbuf = (volatile char *) EBRDGETMEMPTR(brdp, portp->rxoffset);
2773 while (len > 0) {
2774 stlen = MIN(len, stlen);
2775 memcpy(tty->flip.char_buf_ptr, (char *) (shbuf + tail), stlen);
2776 memset(tty->flip.flag_buf_ptr, 0, stlen);
2777 tty->flip.char_buf_ptr += stlen;
2778 tty->flip.flag_buf_ptr += stlen;
2779 tty->flip.count += stlen;
2781 len -= stlen;
2782 tail += stlen;
2783 if (tail >= size) {
2784 tail = 0;
2785 stlen = head;
2788 rp = &((volatile cdkasy_t *) EBRDGETMEMPTR(brdp, portp->addr))->rxq;
2789 rp->tail = tail;
2791 if (head != tail)
2792 set_bit(ST_RXING, &portp->state);
2794 tty_schedule_flip(tty);
2797 /*****************************************************************************/
2800 * Set up and carry out any delayed commands. There is only a small set
2801 * of slave commands that can be done "off-level". So it is not too
2802 * difficult to deal with them here.
2805 static inline void stli_dodelaycmd(stliport_t *portp, volatile cdkctrl_t *cp)
2807 int cmd;
2809 if (test_bit(ST_DOSIGS, &portp->state)) {
2810 if (test_bit(ST_DOFLUSHTX, &portp->state) &&
2811 test_bit(ST_DOFLUSHRX, &portp->state))
2812 cmd = A_SETSIGNALSF;
2813 else if (test_bit(ST_DOFLUSHTX, &portp->state))
2814 cmd = A_SETSIGNALSFTX;
2815 else if (test_bit(ST_DOFLUSHRX, &portp->state))
2816 cmd = A_SETSIGNALSFRX;
2817 else
2818 cmd = A_SETSIGNALS;
2819 clear_bit(ST_DOFLUSHTX, &portp->state);
2820 clear_bit(ST_DOFLUSHRX, &portp->state);
2821 clear_bit(ST_DOSIGS, &portp->state);
2822 memcpy((void *) &(cp->args[0]), (void *) &portp->asig,
2823 sizeof(asysigs_t));
2824 cp->status = 0;
2825 cp->cmd = cmd;
2826 set_bit(ST_CMDING, &portp->state);
2827 } else if (test_bit(ST_DOFLUSHTX, &portp->state) ||
2828 test_bit(ST_DOFLUSHRX, &portp->state)) {
2829 cmd = ((test_bit(ST_DOFLUSHTX, &portp->state)) ? FLUSHTX : 0);
2830 cmd |= ((test_bit(ST_DOFLUSHRX, &portp->state)) ? FLUSHRX : 0);
2831 clear_bit(ST_DOFLUSHTX, &portp->state);
2832 clear_bit(ST_DOFLUSHRX, &portp->state);
2833 memcpy((void *) &(cp->args[0]), (void *) &cmd, sizeof(int));
2834 cp->status = 0;
2835 cp->cmd = A_FLUSH;
2836 set_bit(ST_CMDING, &portp->state);
2840 /*****************************************************************************/
2843 * Host command service checking. This handles commands or messages
2844 * coming from the slave to the host. Must have board shared memory
2845 * enabled and interrupts off when called. Notice that by servicing the
2846 * read data last we don't need to change the shared memory pointer
2847 * during processing (which is a slow IO operation).
2848 * Return value indicates if this port is still awaiting actions from
2849 * the slave (like open, command, or even TX data being sent). If 0
2850 * then port is still busy, otherwise no longer busy.
2853 static inline int stli_hostcmd(stlibrd_t *brdp, stliport_t *portp)
2855 volatile cdkasy_t *ap;
2856 volatile cdkctrl_t *cp;
2857 struct tty_struct *tty;
2858 asynotify_t nt;
2859 unsigned long oldsigs;
2860 int rc, donerx;
2862 #if DEBUG
2863 printk(KERN_DEBUG "stli_hostcmd(brdp=%x,channr=%d)\n",
2864 (int) brdp, channr);
2865 #endif
2867 ap = (volatile cdkasy_t *) EBRDGETMEMPTR(brdp, portp->addr);
2868 cp = &ap->ctrl;
2871 * Check if we are waiting for an open completion message.
2873 if (test_bit(ST_OPENING, &portp->state)) {
2874 rc = (int) cp->openarg;
2875 if ((cp->open == 0) && (rc != 0)) {
2876 if (rc > 0)
2877 rc--;
2878 cp->openarg = 0;
2879 portp->rc = rc;
2880 clear_bit(ST_OPENING, &portp->state);
2881 wake_up_interruptible(&portp->raw_wait);
2886 * Check if we are waiting for a close completion message.
2888 if (test_bit(ST_CLOSING, &portp->state)) {
2889 rc = (int) cp->closearg;
2890 if ((cp->close == 0) && (rc != 0)) {
2891 if (rc > 0)
2892 rc--;
2893 cp->closearg = 0;
2894 portp->rc = rc;
2895 clear_bit(ST_CLOSING, &portp->state);
2896 wake_up_interruptible(&portp->raw_wait);
2901 * Check if we are waiting for a command completion message. We may
2902 * need to copy out the command results associated with this command.
2904 if (test_bit(ST_CMDING, &portp->state)) {
2905 rc = cp->status;
2906 if ((cp->cmd == 0) && (rc != 0)) {
2907 if (rc > 0)
2908 rc--;
2909 if (portp->argp != (void *) NULL) {
2910 memcpy(portp->argp, (void *) &(cp->args[0]),
2911 portp->argsize);
2912 portp->argp = (void *) NULL;
2914 cp->status = 0;
2915 portp->rc = rc;
2916 clear_bit(ST_CMDING, &portp->state);
2917 stli_dodelaycmd(portp, cp);
2918 wake_up_interruptible(&portp->raw_wait);
2923 * Check for any notification messages ready. This includes lots of
2924 * different types of events - RX chars ready, RX break received,
2925 * TX data low or empty in the slave, modem signals changed state.
2927 donerx = 0;
2929 if (ap->notify) {
2930 nt = ap->changed;
2931 ap->notify = 0;
2932 tty = portp->tty;
2934 if (nt.signal & SG_DCD) {
2935 oldsigs = portp->sigs;
2936 portp->sigs = stli_mktiocm(nt.sigvalue);
2937 clear_bit(ST_GETSIGS, &portp->state);
2938 if ((portp->sigs & TIOCM_CD) &&
2939 ((oldsigs & TIOCM_CD) == 0))
2940 wake_up_interruptible(&portp->open_wait);
2941 if ((oldsigs & TIOCM_CD) &&
2942 ((portp->sigs & TIOCM_CD) == 0)) {
2943 if (portp->flags & ASYNC_CHECK_CD) {
2944 if (tty)
2945 schedule_work(&portp->tqhangup);
2950 if (nt.data & DT_TXEMPTY)
2951 clear_bit(ST_TXBUSY, &portp->state);
2952 if (nt.data & (DT_TXEMPTY | DT_TXLOW)) {
2953 if (tty != (struct tty_struct *) NULL) {
2954 if ((tty->flags & (1 << TTY_DO_WRITE_WAKEUP)) &&
2955 tty->ldisc.write_wakeup) {
2956 (tty->ldisc.write_wakeup)(tty);
2957 EBRDENABLE(brdp);
2959 wake_up_interruptible(&tty->write_wait);
2963 if ((nt.data & DT_RXBREAK) && (portp->rxmarkmsk & BRKINT)) {
2964 if (tty != (struct tty_struct *) NULL) {
2965 if (tty->flip.count < TTY_FLIPBUF_SIZE) {
2966 tty->flip.count++;
2967 *tty->flip.flag_buf_ptr++ = TTY_BREAK;
2968 *tty->flip.char_buf_ptr++ = 0;
2969 if (portp->flags & ASYNC_SAK) {
2970 do_SAK(tty);
2971 EBRDENABLE(brdp);
2973 tty_schedule_flip(tty);
2978 if (nt.data & DT_RXBUSY) {
2979 donerx++;
2980 stli_read(brdp, portp);
2985 * It might seem odd that we are checking for more RX chars here.
2986 * But, we need to handle the case where the tty buffer was previously
2987 * filled, but we had more characters to pass up. The slave will not
2988 * send any more RX notify messages until the RX buffer has been emptied.
2989 * But it will leave the service bits on (since the buffer is not empty).
2990 * So from here we can try to process more RX chars.
2992 if ((!donerx) && test_bit(ST_RXING, &portp->state)) {
2993 clear_bit(ST_RXING, &portp->state);
2994 stli_read(brdp, portp);
2997 return((test_bit(ST_OPENING, &portp->state) ||
2998 test_bit(ST_CLOSING, &portp->state) ||
2999 test_bit(ST_CMDING, &portp->state) ||
3000 test_bit(ST_TXBUSY, &portp->state) ||
3001 test_bit(ST_RXING, &portp->state)) ? 0 : 1);
3004 /*****************************************************************************/
3007 * Service all ports on a particular board. Assumes that the boards
3008 * shared memory is enabled, and that the page pointer is pointed
3009 * at the cdk header structure.
3012 static inline void stli_brdpoll(stlibrd_t *brdp, volatile cdkhdr_t *hdrp)
3014 stliport_t *portp;
3015 unsigned char hostbits[(STL_MAXCHANS / 8) + 1];
3016 unsigned char slavebits[(STL_MAXCHANS / 8) + 1];
3017 unsigned char *slavep;
3018 int bitpos, bitat, bitsize;
3019 int channr, nrdevs, slavebitchange;
3021 bitsize = brdp->bitsize;
3022 nrdevs = brdp->nrdevs;
3025 * Check if slave wants any service. Basically we try to do as
3026 * little work as possible here. There are 2 levels of service
3027 * bits. So if there is nothing to do we bail early. We check
3028 * 8 service bits at a time in the inner loop, so we can bypass
3029 * the lot if none of them want service.
3031 memcpy(&hostbits[0], (((unsigned char *) hdrp) + brdp->hostoffset),
3032 bitsize);
3034 memset(&slavebits[0], 0, bitsize);
3035 slavebitchange = 0;
3037 for (bitpos = 0; (bitpos < bitsize); bitpos++) {
3038 if (hostbits[bitpos] == 0)
3039 continue;
3040 channr = bitpos * 8;
3041 for (bitat = 0x1; (channr < nrdevs); channr++, bitat <<= 1) {
3042 if (hostbits[bitpos] & bitat) {
3043 portp = brdp->ports[(channr - 1)];
3044 if (stli_hostcmd(brdp, portp)) {
3045 slavebitchange++;
3046 slavebits[bitpos] |= bitat;
3053 * If any of the ports are no longer busy then update them in the
3054 * slave request bits. We need to do this after, since a host port
3055 * service may initiate more slave requests.
3057 if (slavebitchange) {
3058 hdrp = (volatile cdkhdr_t *) EBRDGETMEMPTR(brdp, CDK_CDKADDR);
3059 slavep = ((unsigned char *) hdrp) + brdp->slaveoffset;
3060 for (bitpos = 0; (bitpos < bitsize); bitpos++) {
3061 if (slavebits[bitpos])
3062 slavep[bitpos] &= ~slavebits[bitpos];
3067 /*****************************************************************************/
3070 * Driver poll routine. This routine polls the boards in use and passes
3071 * messages back up to host when necessary. This is actually very
3072 * CPU efficient, since we will always have the kernel poll clock, it
3073 * adds only a few cycles when idle (since board service can be
3074 * determined very easily), but when loaded generates no interrupts
3075 * (with their expensive associated context change).
3078 static void stli_poll(unsigned long arg)
3080 volatile cdkhdr_t *hdrp;
3081 stlibrd_t *brdp;
3082 int brdnr;
3084 stli_timerlist.expires = STLI_TIMEOUT;
3085 add_timer(&stli_timerlist);
3088 * Check each board and do any servicing required.
3090 for (brdnr = 0; (brdnr < stli_nrbrds); brdnr++) {
3091 brdp = stli_brds[brdnr];
3092 if (brdp == (stlibrd_t *) NULL)
3093 continue;
3094 if ((brdp->state & BST_STARTED) == 0)
3095 continue;
3097 EBRDENABLE(brdp);
3098 hdrp = (volatile cdkhdr_t *) EBRDGETMEMPTR(brdp, CDK_CDKADDR);
3099 if (hdrp->hostreq)
3100 stli_brdpoll(brdp, hdrp);
3101 EBRDDISABLE(brdp);
3105 /*****************************************************************************/
3108 * Translate the termios settings into the port setting structure of
3109 * the slave.
3112 static void stli_mkasyport(stliport_t *portp, asyport_t *pp, struct termios *tiosp)
3114 #if DEBUG
3115 printk(KERN_DEBUG "stli_mkasyport(portp=%x,pp=%x,tiosp=%d)\n",
3116 (int) portp, (int) pp, (int) tiosp);
3117 #endif
3119 memset(pp, 0, sizeof(asyport_t));
3122 * Start of by setting the baud, char size, parity and stop bit info.
3124 pp->baudout = tiosp->c_cflag & CBAUD;
3125 if (pp->baudout & CBAUDEX) {
3126 pp->baudout &= ~CBAUDEX;
3127 if ((pp->baudout < 1) || (pp->baudout > 4))
3128 tiosp->c_cflag &= ~CBAUDEX;
3129 else
3130 pp->baudout += 15;
3132 pp->baudout = stli_baudrates[pp->baudout];
3133 if ((tiosp->c_cflag & CBAUD) == B38400) {
3134 if ((portp->flags & ASYNC_SPD_MASK) == ASYNC_SPD_HI)
3135 pp->baudout = 57600;
3136 else if ((portp->flags & ASYNC_SPD_MASK) == ASYNC_SPD_VHI)
3137 pp->baudout = 115200;
3138 else if ((portp->flags & ASYNC_SPD_MASK) == ASYNC_SPD_SHI)
3139 pp->baudout = 230400;
3140 else if ((portp->flags & ASYNC_SPD_MASK) == ASYNC_SPD_WARP)
3141 pp->baudout = 460800;
3142 else if ((portp->flags & ASYNC_SPD_MASK) == ASYNC_SPD_CUST)
3143 pp->baudout = (portp->baud_base / portp->custom_divisor);
3145 if (pp->baudout > STL_MAXBAUD)
3146 pp->baudout = STL_MAXBAUD;
3147 pp->baudin = pp->baudout;
3149 switch (tiosp->c_cflag & CSIZE) {
3150 case CS5:
3151 pp->csize = 5;
3152 break;
3153 case CS6:
3154 pp->csize = 6;
3155 break;
3156 case CS7:
3157 pp->csize = 7;
3158 break;
3159 default:
3160 pp->csize = 8;
3161 break;
3164 if (tiosp->c_cflag & CSTOPB)
3165 pp->stopbs = PT_STOP2;
3166 else
3167 pp->stopbs = PT_STOP1;
3169 if (tiosp->c_cflag & PARENB) {
3170 if (tiosp->c_cflag & PARODD)
3171 pp->parity = PT_ODDPARITY;
3172 else
3173 pp->parity = PT_EVENPARITY;
3174 } else {
3175 pp->parity = PT_NOPARITY;
3179 * Set up any flow control options enabled.
3181 if (tiosp->c_iflag & IXON) {
3182 pp->flow |= F_IXON;
3183 if (tiosp->c_iflag & IXANY)
3184 pp->flow |= F_IXANY;
3186 if (tiosp->c_cflag & CRTSCTS)
3187 pp->flow |= (F_RTSFLOW | F_CTSFLOW);
3189 pp->startin = tiosp->c_cc[VSTART];
3190 pp->stopin = tiosp->c_cc[VSTOP];
3191 pp->startout = tiosp->c_cc[VSTART];
3192 pp->stopout = tiosp->c_cc[VSTOP];
3195 * Set up the RX char marking mask with those RX error types we must
3196 * catch. We can get the slave to help us out a little here, it will
3197 * ignore parity errors and breaks for us, and mark parity errors in
3198 * the data stream.
3200 if (tiosp->c_iflag & IGNPAR)
3201 pp->iflag |= FI_IGNRXERRS;
3202 if (tiosp->c_iflag & IGNBRK)
3203 pp->iflag |= FI_IGNBREAK;
3205 portp->rxmarkmsk = 0;
3206 if (tiosp->c_iflag & (INPCK | PARMRK))
3207 pp->iflag |= FI_1MARKRXERRS;
3208 if (tiosp->c_iflag & BRKINT)
3209 portp->rxmarkmsk |= BRKINT;
3212 * Set up clocal processing as required.
3214 if (tiosp->c_cflag & CLOCAL)
3215 portp->flags &= ~ASYNC_CHECK_CD;
3216 else
3217 portp->flags |= ASYNC_CHECK_CD;
3220 * Transfer any persistent flags into the asyport structure.
3222 pp->pflag = (portp->pflag & 0xffff);
3223 pp->vmin = (portp->pflag & P_RXIMIN) ? 1 : 0;
3224 pp->vtime = (portp->pflag & P_RXITIME) ? 1 : 0;
3225 pp->cc[1] = (portp->pflag & P_RXTHOLD) ? 1 : 0;
3228 /*****************************************************************************/
3231 * Construct a slave signals structure for setting the DTR and RTS
3232 * signals as specified.
3235 static void stli_mkasysigs(asysigs_t *sp, int dtr, int rts)
3237 #if DEBUG
3238 printk(KERN_DEBUG "stli_mkasysigs(sp=%x,dtr=%d,rts=%d)\n",
3239 (int) sp, dtr, rts);
3240 #endif
3242 memset(sp, 0, sizeof(asysigs_t));
3243 if (dtr >= 0) {
3244 sp->signal |= SG_DTR;
3245 sp->sigvalue |= ((dtr > 0) ? SG_DTR : 0);
3247 if (rts >= 0) {
3248 sp->signal |= SG_RTS;
3249 sp->sigvalue |= ((rts > 0) ? SG_RTS : 0);
3253 /*****************************************************************************/
3256 * Convert the signals returned from the slave into a local TIOCM type
3257 * signals value. We keep them locally in TIOCM format.
3260 static long stli_mktiocm(unsigned long sigvalue)
3262 long tiocm;
3264 #if DEBUG
3265 printk(KERN_DEBUG "stli_mktiocm(sigvalue=%x)\n", (int) sigvalue);
3266 #endif
3268 tiocm = 0;
3269 tiocm |= ((sigvalue & SG_DCD) ? TIOCM_CD : 0);
3270 tiocm |= ((sigvalue & SG_CTS) ? TIOCM_CTS : 0);
3271 tiocm |= ((sigvalue & SG_RI) ? TIOCM_RI : 0);
3272 tiocm |= ((sigvalue & SG_DSR) ? TIOCM_DSR : 0);
3273 tiocm |= ((sigvalue & SG_DTR) ? TIOCM_DTR : 0);
3274 tiocm |= ((sigvalue & SG_RTS) ? TIOCM_RTS : 0);
3275 return(tiocm);
3278 /*****************************************************************************/
3281 * All panels and ports actually attached have been worked out. All
3282 * we need to do here is set up the appropriate per port data structures.
3285 static inline int stli_initports(stlibrd_t *brdp)
3287 stliport_t *portp;
3288 int i, panelnr, panelport;
3290 #if DEBUG
3291 printk(KERN_DEBUG "stli_initports(brdp=%x)\n", (int) brdp);
3292 #endif
3294 for (i = 0, panelnr = 0, panelport = 0; (i < brdp->nrports); i++) {
3295 portp = (stliport_t *) stli_memalloc(sizeof(stliport_t));
3296 if (portp == (stliport_t *) NULL) {
3297 printk("STALLION: failed to allocate port structure\n");
3298 continue;
3301 memset(portp, 0, sizeof(stliport_t));
3302 portp->magic = STLI_PORTMAGIC;
3303 portp->portnr = i;
3304 portp->brdnr = brdp->brdnr;
3305 portp->panelnr = panelnr;
3306 portp->baud_base = STL_BAUDBASE;
3307 portp->close_delay = STL_CLOSEDELAY;
3308 portp->closing_wait = 30 * HZ;
3309 INIT_WORK(&portp->tqhangup, stli_dohangup, portp);
3310 init_waitqueue_head(&portp->open_wait);
3311 init_waitqueue_head(&portp->close_wait);
3312 init_waitqueue_head(&portp->raw_wait);
3313 panelport++;
3314 if (panelport >= brdp->panels[panelnr]) {
3315 panelport = 0;
3316 panelnr++;
3318 brdp->ports[i] = portp;
3321 return(0);
3324 /*****************************************************************************/
3327 * All the following routines are board specific hardware operations.
3330 static void stli_ecpinit(stlibrd_t *brdp)
3332 unsigned long memconf;
3334 #if DEBUG
3335 printk(KERN_DEBUG "stli_ecpinit(brdp=%d)\n", (int) brdp);
3336 #endif
3338 outb(ECP_ATSTOP, (brdp->iobase + ECP_ATCONFR));
3339 udelay(10);
3340 outb(ECP_ATDISABLE, (brdp->iobase + ECP_ATCONFR));
3341 udelay(100);
3343 memconf = (brdp->memaddr & ECP_ATADDRMASK) >> ECP_ATADDRSHFT;
3344 outb(memconf, (brdp->iobase + ECP_ATMEMAR));
3347 /*****************************************************************************/
3349 static void stli_ecpenable(stlibrd_t *brdp)
3351 #if DEBUG
3352 printk(KERN_DEBUG "stli_ecpenable(brdp=%x)\n", (int) brdp);
3353 #endif
3354 outb(ECP_ATENABLE, (brdp->iobase + ECP_ATCONFR));
3357 /*****************************************************************************/
3359 static void stli_ecpdisable(stlibrd_t *brdp)
3361 #if DEBUG
3362 printk(KERN_DEBUG "stli_ecpdisable(brdp=%x)\n", (int) brdp);
3363 #endif
3364 outb(ECP_ATDISABLE, (brdp->iobase + ECP_ATCONFR));
3367 /*****************************************************************************/
3369 static char *stli_ecpgetmemptr(stlibrd_t *brdp, unsigned long offset, int line)
3371 void *ptr;
3372 unsigned char val;
3374 #if DEBUG
3375 printk(KERN_DEBUG "stli_ecpgetmemptr(brdp=%x,offset=%x)\n", (int) brdp,
3376 (int) offset);
3377 #endif
3379 if (offset > brdp->memsize) {
3380 printk(KERN_ERR "STALLION: shared memory pointer=%x out of "
3381 "range at line=%d(%d), brd=%d\n",
3382 (int) offset, line, __LINE__, brdp->brdnr);
3383 ptr = 0;
3384 val = 0;
3385 } else {
3386 ptr = brdp->membase + (offset % ECP_ATPAGESIZE);
3387 val = (unsigned char) (offset / ECP_ATPAGESIZE);
3389 outb(val, (brdp->iobase + ECP_ATMEMPR));
3390 return(ptr);
3393 /*****************************************************************************/
3395 static void stli_ecpreset(stlibrd_t *brdp)
3397 #if DEBUG
3398 printk(KERN_DEBUG "stli_ecpreset(brdp=%x)\n", (int) brdp);
3399 #endif
3401 outb(ECP_ATSTOP, (brdp->iobase + ECP_ATCONFR));
3402 udelay(10);
3403 outb(ECP_ATDISABLE, (brdp->iobase + ECP_ATCONFR));
3404 udelay(500);
3407 /*****************************************************************************/
3409 static void stli_ecpintr(stlibrd_t *brdp)
3411 #if DEBUG
3412 printk(KERN_DEBUG "stli_ecpintr(brdp=%x)\n", (int) brdp);
3413 #endif
3414 outb(0x1, brdp->iobase);
3417 /*****************************************************************************/
3420 * The following set of functions act on ECP EISA boards.
3423 static void stli_ecpeiinit(stlibrd_t *brdp)
3425 unsigned long memconf;
3427 #if DEBUG
3428 printk(KERN_DEBUG "stli_ecpeiinit(brdp=%x)\n", (int) brdp);
3429 #endif
3431 outb(0x1, (brdp->iobase + ECP_EIBRDENAB));
3432 outb(ECP_EISTOP, (brdp->iobase + ECP_EICONFR));
3433 udelay(10);
3434 outb(ECP_EIDISABLE, (brdp->iobase + ECP_EICONFR));
3435 udelay(500);
3437 memconf = (brdp->memaddr & ECP_EIADDRMASKL) >> ECP_EIADDRSHFTL;
3438 outb(memconf, (brdp->iobase + ECP_EIMEMARL));
3439 memconf = (brdp->memaddr & ECP_EIADDRMASKH) >> ECP_EIADDRSHFTH;
3440 outb(memconf, (brdp->iobase + ECP_EIMEMARH));
3443 /*****************************************************************************/
3445 static void stli_ecpeienable(stlibrd_t *brdp)
3447 outb(ECP_EIENABLE, (brdp->iobase + ECP_EICONFR));
3450 /*****************************************************************************/
3452 static void stli_ecpeidisable(stlibrd_t *brdp)
3454 outb(ECP_EIDISABLE, (brdp->iobase + ECP_EICONFR));
3457 /*****************************************************************************/
3459 static char *stli_ecpeigetmemptr(stlibrd_t *brdp, unsigned long offset, int line)
3461 void *ptr;
3462 unsigned char val;
3464 #if DEBUG
3465 printk(KERN_DEBUG "stli_ecpeigetmemptr(brdp=%x,offset=%x,line=%d)\n",
3466 (int) brdp, (int) offset, line);
3467 #endif
3469 if (offset > brdp->memsize) {
3470 printk(KERN_ERR "STALLION: shared memory pointer=%x out of "
3471 "range at line=%d(%d), brd=%d\n",
3472 (int) offset, line, __LINE__, brdp->brdnr);
3473 ptr = 0;
3474 val = 0;
3475 } else {
3476 ptr = brdp->membase + (offset % ECP_EIPAGESIZE);
3477 if (offset < ECP_EIPAGESIZE)
3478 val = ECP_EIENABLE;
3479 else
3480 val = ECP_EIENABLE | 0x40;
3482 outb(val, (brdp->iobase + ECP_EICONFR));
3483 return(ptr);
3486 /*****************************************************************************/
3488 static void stli_ecpeireset(stlibrd_t *brdp)
3490 outb(ECP_EISTOP, (brdp->iobase + ECP_EICONFR));
3491 udelay(10);
3492 outb(ECP_EIDISABLE, (brdp->iobase + ECP_EICONFR));
3493 udelay(500);
3496 /*****************************************************************************/
3499 * The following set of functions act on ECP MCA boards.
3502 static void stli_ecpmcenable(stlibrd_t *brdp)
3504 outb(ECP_MCENABLE, (brdp->iobase + ECP_MCCONFR));
3507 /*****************************************************************************/
3509 static void stli_ecpmcdisable(stlibrd_t *brdp)
3511 outb(ECP_MCDISABLE, (brdp->iobase + ECP_MCCONFR));
3514 /*****************************************************************************/
3516 static char *stli_ecpmcgetmemptr(stlibrd_t *brdp, unsigned long offset, int line)
3518 void *ptr;
3519 unsigned char val;
3521 if (offset > brdp->memsize) {
3522 printk(KERN_ERR "STALLION: shared memory pointer=%x out of "
3523 "range at line=%d(%d), brd=%d\n",
3524 (int) offset, line, __LINE__, brdp->brdnr);
3525 ptr = 0;
3526 val = 0;
3527 } else {
3528 ptr = brdp->membase + (offset % ECP_MCPAGESIZE);
3529 val = ((unsigned char) (offset / ECP_MCPAGESIZE)) | ECP_MCENABLE;
3531 outb(val, (brdp->iobase + ECP_MCCONFR));
3532 return(ptr);
3535 /*****************************************************************************/
3537 static void stli_ecpmcreset(stlibrd_t *brdp)
3539 outb(ECP_MCSTOP, (brdp->iobase + ECP_MCCONFR));
3540 udelay(10);
3541 outb(ECP_MCDISABLE, (brdp->iobase + ECP_MCCONFR));
3542 udelay(500);
3545 /*****************************************************************************/
3548 * The following set of functions act on ECP PCI boards.
3551 static void stli_ecppciinit(stlibrd_t *brdp)
3553 #if DEBUG
3554 printk(KERN_DEBUG "stli_ecppciinit(brdp=%x)\n", (int) brdp);
3555 #endif
3557 outb(ECP_PCISTOP, (brdp->iobase + ECP_PCICONFR));
3558 udelay(10);
3559 outb(0, (brdp->iobase + ECP_PCICONFR));
3560 udelay(500);
3563 /*****************************************************************************/
3565 static char *stli_ecppcigetmemptr(stlibrd_t *brdp, unsigned long offset, int line)
3567 void *ptr;
3568 unsigned char val;
3570 #if DEBUG
3571 printk(KERN_DEBUG "stli_ecppcigetmemptr(brdp=%x,offset=%x,line=%d)\n",
3572 (int) brdp, (int) offset, line);
3573 #endif
3575 if (offset > brdp->memsize) {
3576 printk(KERN_ERR "STALLION: shared memory pointer=%x out of "
3577 "range at line=%d(%d), board=%d\n",
3578 (int) offset, line, __LINE__, brdp->brdnr);
3579 ptr = 0;
3580 val = 0;
3581 } else {
3582 ptr = brdp->membase + (offset % ECP_PCIPAGESIZE);
3583 val = (offset / ECP_PCIPAGESIZE) << 1;
3585 outb(val, (brdp->iobase + ECP_PCICONFR));
3586 return(ptr);
3589 /*****************************************************************************/
3591 static void stli_ecppcireset(stlibrd_t *brdp)
3593 outb(ECP_PCISTOP, (brdp->iobase + ECP_PCICONFR));
3594 udelay(10);
3595 outb(0, (brdp->iobase + ECP_PCICONFR));
3596 udelay(500);
3599 /*****************************************************************************/
3602 * The following routines act on ONboards.
3605 static void stli_onbinit(stlibrd_t *brdp)
3607 unsigned long memconf;
3609 #if DEBUG
3610 printk(KERN_DEBUG "stli_onbinit(brdp=%d)\n", (int) brdp);
3611 #endif
3613 outb(ONB_ATSTOP, (brdp->iobase + ONB_ATCONFR));
3614 udelay(10);
3615 outb(ONB_ATDISABLE, (brdp->iobase + ONB_ATCONFR));
3616 mdelay(1000);
3618 memconf = (brdp->memaddr & ONB_ATADDRMASK) >> ONB_ATADDRSHFT;
3619 outb(memconf, (brdp->iobase + ONB_ATMEMAR));
3620 outb(0x1, brdp->iobase);
3621 mdelay(1);
3624 /*****************************************************************************/
3626 static void stli_onbenable(stlibrd_t *brdp)
3628 #if DEBUG
3629 printk(KERN_DEBUG "stli_onbenable(brdp=%x)\n", (int) brdp);
3630 #endif
3631 outb((brdp->enabval | ONB_ATENABLE), (brdp->iobase + ONB_ATCONFR));
3634 /*****************************************************************************/
3636 static void stli_onbdisable(stlibrd_t *brdp)
3638 #if DEBUG
3639 printk(KERN_DEBUG "stli_onbdisable(brdp=%x)\n", (int) brdp);
3640 #endif
3641 outb((brdp->enabval | ONB_ATDISABLE), (brdp->iobase + ONB_ATCONFR));
3644 /*****************************************************************************/
3646 static char *stli_onbgetmemptr(stlibrd_t *brdp, unsigned long offset, int line)
3648 void *ptr;
3650 #if DEBUG
3651 printk(KERN_DEBUG "stli_onbgetmemptr(brdp=%x,offset=%x)\n", (int) brdp,
3652 (int) offset);
3653 #endif
3655 if (offset > brdp->memsize) {
3656 printk(KERN_ERR "STALLION: shared memory pointer=%x out of "
3657 "range at line=%d(%d), brd=%d\n",
3658 (int) offset, line, __LINE__, brdp->brdnr);
3659 ptr = 0;
3660 } else {
3661 ptr = brdp->membase + (offset % ONB_ATPAGESIZE);
3663 return(ptr);
3666 /*****************************************************************************/
3668 static void stli_onbreset(stlibrd_t *brdp)
3671 #if DEBUG
3672 printk(KERN_DEBUG "stli_onbreset(brdp=%x)\n", (int) brdp);
3673 #endif
3675 outb(ONB_ATSTOP, (brdp->iobase + ONB_ATCONFR));
3676 udelay(10);
3677 outb(ONB_ATDISABLE, (brdp->iobase + ONB_ATCONFR));
3678 mdelay(1000);
3681 /*****************************************************************************/
3684 * The following routines act on ONboard EISA.
3687 static void stli_onbeinit(stlibrd_t *brdp)
3689 unsigned long memconf;
3691 #if DEBUG
3692 printk(KERN_DEBUG "stli_onbeinit(brdp=%d)\n", (int) brdp);
3693 #endif
3695 outb(0x1, (brdp->iobase + ONB_EIBRDENAB));
3696 outb(ONB_EISTOP, (brdp->iobase + ONB_EICONFR));
3697 udelay(10);
3698 outb(ONB_EIDISABLE, (brdp->iobase + ONB_EICONFR));
3699 mdelay(1000);
3701 memconf = (brdp->memaddr & ONB_EIADDRMASKL) >> ONB_EIADDRSHFTL;
3702 outb(memconf, (brdp->iobase + ONB_EIMEMARL));
3703 memconf = (brdp->memaddr & ONB_EIADDRMASKH) >> ONB_EIADDRSHFTH;
3704 outb(memconf, (brdp->iobase + ONB_EIMEMARH));
3705 outb(0x1, brdp->iobase);
3706 mdelay(1);
3709 /*****************************************************************************/
3711 static void stli_onbeenable(stlibrd_t *brdp)
3713 #if DEBUG
3714 printk(KERN_DEBUG "stli_onbeenable(brdp=%x)\n", (int) brdp);
3715 #endif
3716 outb(ONB_EIENABLE, (brdp->iobase + ONB_EICONFR));
3719 /*****************************************************************************/
3721 static void stli_onbedisable(stlibrd_t *brdp)
3723 #if DEBUG
3724 printk(KERN_DEBUG "stli_onbedisable(brdp=%x)\n", (int) brdp);
3725 #endif
3726 outb(ONB_EIDISABLE, (brdp->iobase + ONB_EICONFR));
3729 /*****************************************************************************/
3731 static char *stli_onbegetmemptr(stlibrd_t *brdp, unsigned long offset, int line)
3733 void *ptr;
3734 unsigned char val;
3736 #if DEBUG
3737 printk(KERN_DEBUG "stli_onbegetmemptr(brdp=%x,offset=%x,line=%d)\n",
3738 (int) brdp, (int) offset, line);
3739 #endif
3741 if (offset > brdp->memsize) {
3742 printk(KERN_ERR "STALLION: shared memory pointer=%x out of "
3743 "range at line=%d(%d), brd=%d\n",
3744 (int) offset, line, __LINE__, brdp->brdnr);
3745 ptr = 0;
3746 val = 0;
3747 } else {
3748 ptr = brdp->membase + (offset % ONB_EIPAGESIZE);
3749 if (offset < ONB_EIPAGESIZE)
3750 val = ONB_EIENABLE;
3751 else
3752 val = ONB_EIENABLE | 0x40;
3754 outb(val, (brdp->iobase + ONB_EICONFR));
3755 return(ptr);
3758 /*****************************************************************************/
3760 static void stli_onbereset(stlibrd_t *brdp)
3763 #if DEBUG
3764 printk(KERN_ERR "stli_onbereset(brdp=%x)\n", (int) brdp);
3765 #endif
3767 outb(ONB_EISTOP, (brdp->iobase + ONB_EICONFR));
3768 udelay(10);
3769 outb(ONB_EIDISABLE, (brdp->iobase + ONB_EICONFR));
3770 mdelay(1000);
3773 /*****************************************************************************/
3776 * The following routines act on Brumby boards.
3779 static void stli_bbyinit(stlibrd_t *brdp)
3782 #if DEBUG
3783 printk(KERN_ERR "stli_bbyinit(brdp=%d)\n", (int) brdp);
3784 #endif
3786 outb(BBY_ATSTOP, (brdp->iobase + BBY_ATCONFR));
3787 udelay(10);
3788 outb(0, (brdp->iobase + BBY_ATCONFR));
3789 mdelay(1000);
3790 outb(0x1, brdp->iobase);
3791 mdelay(1);
3794 /*****************************************************************************/
3796 static char *stli_bbygetmemptr(stlibrd_t *brdp, unsigned long offset, int line)
3798 void *ptr;
3799 unsigned char val;
3801 #if DEBUG
3802 printk(KERN_ERR "stli_bbygetmemptr(brdp=%x,offset=%x)\n", (int) brdp,
3803 (int) offset);
3804 #endif
3806 if (offset > brdp->memsize) {
3807 printk(KERN_ERR "STALLION: shared memory pointer=%x out of "
3808 "range at line=%d(%d), brd=%d\n",
3809 (int) offset, line, __LINE__, brdp->brdnr);
3810 ptr = 0;
3811 val = 0;
3812 } else {
3813 ptr = brdp->membase + (offset % BBY_PAGESIZE);
3814 val = (unsigned char) (offset / BBY_PAGESIZE);
3816 outb(val, (brdp->iobase + BBY_ATCONFR));
3817 return(ptr);
3820 /*****************************************************************************/
3822 static void stli_bbyreset(stlibrd_t *brdp)
3825 #if DEBUG
3826 printk(KERN_DEBUG "stli_bbyreset(brdp=%x)\n", (int) brdp);
3827 #endif
3829 outb(BBY_ATSTOP, (brdp->iobase + BBY_ATCONFR));
3830 udelay(10);
3831 outb(0, (brdp->iobase + BBY_ATCONFR));
3832 mdelay(1000);
3835 /*****************************************************************************/
3838 * The following routines act on original old Stallion boards.
3841 static void stli_stalinit(stlibrd_t *brdp)
3844 #if DEBUG
3845 printk(KERN_DEBUG "stli_stalinit(brdp=%d)\n", (int) brdp);
3846 #endif
3848 outb(0x1, brdp->iobase);
3849 mdelay(1000);
3852 /*****************************************************************************/
3854 static char *stli_stalgetmemptr(stlibrd_t *brdp, unsigned long offset, int line)
3856 void *ptr;
3858 #if DEBUG
3859 printk(KERN_DEBUG "stli_stalgetmemptr(brdp=%x,offset=%x)\n", (int) brdp,
3860 (int) offset);
3861 #endif
3863 if (offset > brdp->memsize) {
3864 printk(KERN_ERR "STALLION: shared memory pointer=%x out of "
3865 "range at line=%d(%d), brd=%d\n",
3866 (int) offset, line, __LINE__, brdp->brdnr);
3867 ptr = 0;
3868 } else {
3869 ptr = brdp->membase + (offset % STAL_PAGESIZE);
3871 return(ptr);
3874 /*****************************************************************************/
3876 static void stli_stalreset(stlibrd_t *brdp)
3878 volatile unsigned long *vecp;
3880 #if DEBUG
3881 printk(KERN_DEBUG "stli_stalreset(brdp=%x)\n", (int) brdp);
3882 #endif
3884 vecp = (volatile unsigned long *) (brdp->membase + 0x30);
3885 *vecp = 0xffff0000;
3886 outb(0, brdp->iobase);
3887 mdelay(1000);
3890 /*****************************************************************************/
3893 * Try to find an ECP board and initialize it. This handles only ECP
3894 * board types.
3897 static inline int stli_initecp(stlibrd_t *brdp)
3899 cdkecpsig_t sig;
3900 cdkecpsig_t *sigsp;
3901 unsigned int status, nxtid;
3902 char *name;
3903 int panelnr, nrports;
3905 #if DEBUG
3906 printk(KERN_DEBUG "stli_initecp(brdp=%x)\n", (int) brdp);
3907 #endif
3909 if (!request_region(brdp->iobase, brdp->iosize, "istallion"))
3910 return -EIO;
3912 if ((brdp->iobase == 0) || (brdp->memaddr == 0))
3914 release_region(brdp->iobase, brdp->iosize);
3915 return(-ENODEV);
3918 brdp->iosize = ECP_IOSIZE;
3921 * Based on the specific board type setup the common vars to access
3922 * and enable shared memory. Set all board specific information now
3923 * as well.
3925 switch (brdp->brdtype) {
3926 case BRD_ECP:
3927 brdp->membase = (void *) brdp->memaddr;
3928 brdp->memsize = ECP_MEMSIZE;
3929 brdp->pagesize = ECP_ATPAGESIZE;
3930 brdp->init = stli_ecpinit;
3931 brdp->enable = stli_ecpenable;
3932 brdp->reenable = stli_ecpenable;
3933 brdp->disable = stli_ecpdisable;
3934 brdp->getmemptr = stli_ecpgetmemptr;
3935 brdp->intr = stli_ecpintr;
3936 brdp->reset = stli_ecpreset;
3937 name = "serial(EC8/64)";
3938 break;
3940 case BRD_ECPE:
3941 brdp->membase = (void *) brdp->memaddr;
3942 brdp->memsize = ECP_MEMSIZE;
3943 brdp->pagesize = ECP_EIPAGESIZE;
3944 brdp->init = stli_ecpeiinit;
3945 brdp->enable = stli_ecpeienable;
3946 brdp->reenable = stli_ecpeienable;
3947 brdp->disable = stli_ecpeidisable;
3948 brdp->getmemptr = stli_ecpeigetmemptr;
3949 brdp->intr = stli_ecpintr;
3950 brdp->reset = stli_ecpeireset;
3951 name = "serial(EC8/64-EI)";
3952 break;
3954 case BRD_ECPMC:
3955 brdp->membase = (void *) brdp->memaddr;
3956 brdp->memsize = ECP_MEMSIZE;
3957 brdp->pagesize = ECP_MCPAGESIZE;
3958 brdp->init = NULL;
3959 brdp->enable = stli_ecpmcenable;
3960 brdp->reenable = stli_ecpmcenable;
3961 brdp->disable = stli_ecpmcdisable;
3962 brdp->getmemptr = stli_ecpmcgetmemptr;
3963 brdp->intr = stli_ecpintr;
3964 brdp->reset = stli_ecpmcreset;
3965 name = "serial(EC8/64-MCA)";
3966 break;
3968 case BRD_ECPPCI:
3969 brdp->membase = (void *) brdp->memaddr;
3970 brdp->memsize = ECP_PCIMEMSIZE;
3971 brdp->pagesize = ECP_PCIPAGESIZE;
3972 brdp->init = stli_ecppciinit;
3973 brdp->enable = NULL;
3974 brdp->reenable = NULL;
3975 brdp->disable = NULL;
3976 brdp->getmemptr = stli_ecppcigetmemptr;
3977 brdp->intr = stli_ecpintr;
3978 brdp->reset = stli_ecppcireset;
3979 name = "serial(EC/RA-PCI)";
3980 break;
3982 default:
3983 release_region(brdp->iobase, brdp->iosize);
3984 return(-EINVAL);
3988 * The per-board operations structure is all set up, so now let's go
3989 * and get the board operational. Firstly initialize board configuration
3990 * registers. Set the memory mapping info so we can get at the boards
3991 * shared memory.
3993 EBRDINIT(brdp);
3995 brdp->membase = ioremap(brdp->memaddr, brdp->memsize);
3996 if (brdp->membase == (void *) NULL)
3998 release_region(brdp->iobase, brdp->iosize);
3999 return(-ENOMEM);
4003 * Now that all specific code is set up, enable the shared memory and
4004 * look for the a signature area that will tell us exactly what board
4005 * this is, and what it is connected to it.
4007 EBRDENABLE(brdp);
4008 sigsp = (cdkecpsig_t *) EBRDGETMEMPTR(brdp, CDK_SIGADDR);
4009 memcpy(&sig, sigsp, sizeof(cdkecpsig_t));
4010 EBRDDISABLE(brdp);
4012 #if 0
4013 printk("%s(%d): sig-> magic=%x rom=%x panel=%x,%x,%x,%x,%x,%x,%x,%x\n",
4014 __FILE__, __LINE__, (int) sig.magic, sig.romver, sig.panelid[0],
4015 (int) sig.panelid[1], (int) sig.panelid[2],
4016 (int) sig.panelid[3], (int) sig.panelid[4],
4017 (int) sig.panelid[5], (int) sig.panelid[6],
4018 (int) sig.panelid[7]);
4019 #endif
4021 if (sig.magic != ECP_MAGIC)
4023 release_region(brdp->iobase, brdp->iosize);
4024 return(-ENODEV);
4028 * Scan through the signature looking at the panels connected to the
4029 * board. Calculate the total number of ports as we go.
4031 for (panelnr = 0, nxtid = 0; (panelnr < STL_MAXPANELS); panelnr++) {
4032 status = sig.panelid[nxtid];
4033 if ((status & ECH_PNLIDMASK) != nxtid)
4034 break;
4036 brdp->panelids[panelnr] = status;
4037 nrports = (status & ECH_PNL16PORT) ? 16 : 8;
4038 if ((nrports == 16) && ((status & ECH_PNLXPID) == 0))
4039 nxtid++;
4040 brdp->panels[panelnr] = nrports;
4041 brdp->nrports += nrports;
4042 nxtid++;
4043 brdp->nrpanels++;
4047 brdp->state |= BST_FOUND;
4048 return(0);
4051 /*****************************************************************************/
4054 * Try to find an ONboard, Brumby or Stallion board and initialize it.
4055 * This handles only these board types.
4058 static inline int stli_initonb(stlibrd_t *brdp)
4060 cdkonbsig_t sig;
4061 cdkonbsig_t *sigsp;
4062 char *name;
4063 int i;
4065 #if DEBUG
4066 printk(KERN_DEBUG "stli_initonb(brdp=%x)\n", (int) brdp);
4067 #endif
4070 * Do a basic sanity check on the IO and memory addresses.
4072 if ((brdp->iobase == 0) || (brdp->memaddr == 0))
4073 return(-ENODEV);
4075 brdp->iosize = ONB_IOSIZE;
4077 if (!request_region(brdp->iobase, brdp->iosize, "istallion"))
4078 return -EIO;
4081 * Based on the specific board type setup the common vars to access
4082 * and enable shared memory. Set all board specific information now
4083 * as well.
4085 switch (brdp->brdtype) {
4086 case BRD_ONBOARD:
4087 case BRD_ONBOARD32:
4088 case BRD_ONBOARD2:
4089 case BRD_ONBOARD2_32:
4090 case BRD_ONBOARDRS:
4091 brdp->membase = (void *) brdp->memaddr;
4092 brdp->memsize = ONB_MEMSIZE;
4093 brdp->pagesize = ONB_ATPAGESIZE;
4094 brdp->init = stli_onbinit;
4095 brdp->enable = stli_onbenable;
4096 brdp->reenable = stli_onbenable;
4097 brdp->disable = stli_onbdisable;
4098 brdp->getmemptr = stli_onbgetmemptr;
4099 brdp->intr = stli_ecpintr;
4100 brdp->reset = stli_onbreset;
4101 if (brdp->memaddr > 0x100000)
4102 brdp->enabval = ONB_MEMENABHI;
4103 else
4104 brdp->enabval = ONB_MEMENABLO;
4105 name = "serial(ONBoard)";
4106 break;
4108 case BRD_ONBOARDE:
4109 brdp->membase = (void *) brdp->memaddr;
4110 brdp->memsize = ONB_EIMEMSIZE;
4111 brdp->pagesize = ONB_EIPAGESIZE;
4112 brdp->init = stli_onbeinit;
4113 brdp->enable = stli_onbeenable;
4114 brdp->reenable = stli_onbeenable;
4115 brdp->disable = stli_onbedisable;
4116 brdp->getmemptr = stli_onbegetmemptr;
4117 brdp->intr = stli_ecpintr;
4118 brdp->reset = stli_onbereset;
4119 name = "serial(ONBoard/E)";
4120 break;
4122 case BRD_BRUMBY4:
4123 case BRD_BRUMBY8:
4124 case BRD_BRUMBY16:
4125 brdp->membase = (void *) brdp->memaddr;
4126 brdp->memsize = BBY_MEMSIZE;
4127 brdp->pagesize = BBY_PAGESIZE;
4128 brdp->init = stli_bbyinit;
4129 brdp->enable = NULL;
4130 brdp->reenable = NULL;
4131 brdp->disable = NULL;
4132 brdp->getmemptr = stli_bbygetmemptr;
4133 brdp->intr = stli_ecpintr;
4134 brdp->reset = stli_bbyreset;
4135 name = "serial(Brumby)";
4136 break;
4138 case BRD_STALLION:
4139 brdp->membase = (void *) brdp->memaddr;
4140 brdp->memsize = STAL_MEMSIZE;
4141 brdp->pagesize = STAL_PAGESIZE;
4142 brdp->init = stli_stalinit;
4143 brdp->enable = NULL;
4144 brdp->reenable = NULL;
4145 brdp->disable = NULL;
4146 brdp->getmemptr = stli_stalgetmemptr;
4147 brdp->intr = stli_ecpintr;
4148 brdp->reset = stli_stalreset;
4149 name = "serial(Stallion)";
4150 break;
4152 default:
4153 release_region(brdp->iobase, brdp->iosize);
4154 return(-EINVAL);
4158 * The per-board operations structure is all set up, so now let's go
4159 * and get the board operational. Firstly initialize board configuration
4160 * registers. Set the memory mapping info so we can get at the boards
4161 * shared memory.
4163 EBRDINIT(brdp);
4165 brdp->membase = ioremap(brdp->memaddr, brdp->memsize);
4166 if (brdp->membase == (void *) NULL)
4168 release_region(brdp->iobase, brdp->iosize);
4169 return(-ENOMEM);
4173 * Now that all specific code is set up, enable the shared memory and
4174 * look for the a signature area that will tell us exactly what board
4175 * this is, and how many ports.
4177 EBRDENABLE(brdp);
4178 sigsp = (cdkonbsig_t *) EBRDGETMEMPTR(brdp, CDK_SIGADDR);
4179 memcpy(&sig, sigsp, sizeof(cdkonbsig_t));
4180 EBRDDISABLE(brdp);
4182 #if 0
4183 printk("%s(%d): sig-> magic=%x:%x:%x:%x romver=%x amask=%x:%x:%x\n",
4184 __FILE__, __LINE__, sig.magic0, sig.magic1, sig.magic2,
4185 sig.magic3, sig.romver, sig.amask0, sig.amask1, sig.amask2);
4186 #endif
4188 if ((sig.magic0 != ONB_MAGIC0) || (sig.magic1 != ONB_MAGIC1) ||
4189 (sig.magic2 != ONB_MAGIC2) || (sig.magic3 != ONB_MAGIC3))
4191 release_region(brdp->iobase, brdp->iosize);
4192 return(-ENODEV);
4196 * Scan through the signature alive mask and calculate how many ports
4197 * there are on this board.
4199 brdp->nrpanels = 1;
4200 if (sig.amask1) {
4201 brdp->nrports = 32;
4202 } else {
4203 for (i = 0; (i < 16); i++) {
4204 if (((sig.amask0 << i) & 0x8000) == 0)
4205 break;
4207 brdp->nrports = i;
4209 brdp->panels[0] = brdp->nrports;
4212 brdp->state |= BST_FOUND;
4213 return(0);
4216 /*****************************************************************************/
4219 * Start up a running board. This routine is only called after the
4220 * code has been down loaded to the board and is operational. It will
4221 * read in the memory map, and get the show on the road...
4224 static int stli_startbrd(stlibrd_t *brdp)
4226 volatile cdkhdr_t *hdrp;
4227 volatile cdkmem_t *memp;
4228 volatile cdkasy_t *ap;
4229 unsigned long flags;
4230 stliport_t *portp;
4231 int portnr, nrdevs, i, rc;
4233 #if DEBUG
4234 printk(KERN_DEBUG "stli_startbrd(brdp=%x)\n", (int) brdp);
4235 #endif
4237 rc = 0;
4239 save_flags(flags);
4240 cli();
4241 EBRDENABLE(brdp);
4242 hdrp = (volatile cdkhdr_t *) EBRDGETMEMPTR(brdp, CDK_CDKADDR);
4243 nrdevs = hdrp->nrdevs;
4245 #if 0
4246 printk("%s(%d): CDK version %d.%d.%d --> "
4247 "nrdevs=%d memp=%x hostp=%x slavep=%x\n",
4248 __FILE__, __LINE__, hdrp->ver_release, hdrp->ver_modification,
4249 hdrp->ver_fix, nrdevs, (int) hdrp->memp, (int) hdrp->hostp,
4250 (int) hdrp->slavep);
4251 #endif
4253 if (nrdevs < (brdp->nrports + 1)) {
4254 printk(KERN_ERR "STALLION: slave failed to allocate memory for "
4255 "all devices, devices=%d\n", nrdevs);
4256 brdp->nrports = nrdevs - 1;
4258 brdp->nrdevs = nrdevs;
4259 brdp->hostoffset = hdrp->hostp - CDK_CDKADDR;
4260 brdp->slaveoffset = hdrp->slavep - CDK_CDKADDR;
4261 brdp->bitsize = (nrdevs + 7) / 8;
4262 memp = (volatile cdkmem_t *) hdrp->memp;
4263 if (((unsigned long) memp) > brdp->memsize) {
4264 printk(KERN_ERR "STALLION: corrupted shared memory region?\n");
4265 rc = -EIO;
4266 goto stli_donestartup;
4268 memp = (volatile cdkmem_t *) EBRDGETMEMPTR(brdp, (unsigned long) memp);
4269 if (memp->dtype != TYP_ASYNCTRL) {
4270 printk(KERN_ERR "STALLION: no slave control device found\n");
4271 goto stli_donestartup;
4273 memp++;
4276 * Cycle through memory allocation of each port. We are guaranteed to
4277 * have all ports inside the first page of slave window, so no need to
4278 * change pages while reading memory map.
4280 for (i = 1, portnr = 0; (i < nrdevs); i++, portnr++, memp++) {
4281 if (memp->dtype != TYP_ASYNC)
4282 break;
4283 portp = brdp->ports[portnr];
4284 if (portp == (stliport_t *) NULL)
4285 break;
4286 portp->devnr = i;
4287 portp->addr = memp->offset;
4288 portp->reqbit = (unsigned char) (0x1 << (i * 8 / nrdevs));
4289 portp->portidx = (unsigned char) (i / 8);
4290 portp->portbit = (unsigned char) (0x1 << (i % 8));
4293 hdrp->slavereq = 0xff;
4296 * For each port setup a local copy of the RX and TX buffer offsets
4297 * and sizes. We do this separate from the above, because we need to
4298 * move the shared memory page...
4300 for (i = 1, portnr = 0; (i < nrdevs); i++, portnr++) {
4301 portp = brdp->ports[portnr];
4302 if (portp == (stliport_t *) NULL)
4303 break;
4304 if (portp->addr == 0)
4305 break;
4306 ap = (volatile cdkasy_t *) EBRDGETMEMPTR(brdp, portp->addr);
4307 if (ap != (volatile cdkasy_t *) NULL) {
4308 portp->rxsize = ap->rxq.size;
4309 portp->txsize = ap->txq.size;
4310 portp->rxoffset = ap->rxq.offset;
4311 portp->txoffset = ap->txq.offset;
4315 stli_donestartup:
4316 EBRDDISABLE(brdp);
4317 restore_flags(flags);
4319 if (rc == 0)
4320 brdp->state |= BST_STARTED;
4322 if (! stli_timeron) {
4323 stli_timeron++;
4324 stli_timerlist.expires = STLI_TIMEOUT;
4325 add_timer(&stli_timerlist);
4328 return(rc);
4331 /*****************************************************************************/
4334 * Probe and initialize the specified board.
4337 static int __init stli_brdinit(stlibrd_t *brdp)
4339 #if DEBUG
4340 printk(KERN_DEBUG "stli_brdinit(brdp=%x)\n", (int) brdp);
4341 #endif
4343 stli_brds[brdp->brdnr] = brdp;
4345 switch (brdp->brdtype) {
4346 case BRD_ECP:
4347 case BRD_ECPE:
4348 case BRD_ECPMC:
4349 case BRD_ECPPCI:
4350 stli_initecp(brdp);
4351 break;
4352 case BRD_ONBOARD:
4353 case BRD_ONBOARDE:
4354 case BRD_ONBOARD2:
4355 case BRD_ONBOARD32:
4356 case BRD_ONBOARD2_32:
4357 case BRD_ONBOARDRS:
4358 case BRD_BRUMBY4:
4359 case BRD_BRUMBY8:
4360 case BRD_BRUMBY16:
4361 case BRD_STALLION:
4362 stli_initonb(brdp);
4363 break;
4364 case BRD_EASYIO:
4365 case BRD_ECH:
4366 case BRD_ECHMC:
4367 case BRD_ECHPCI:
4368 printk(KERN_ERR "STALLION: %s board type not supported in "
4369 "this driver\n", stli_brdnames[brdp->brdtype]);
4370 return(ENODEV);
4371 default:
4372 printk(KERN_ERR "STALLION: board=%d is unknown board "
4373 "type=%d\n", brdp->brdnr, brdp->brdtype);
4374 return(ENODEV);
4377 if ((brdp->state & BST_FOUND) == 0) {
4378 printk(KERN_ERR "STALLION: %s board not found, board=%d "
4379 "io=%x mem=%x\n",
4380 stli_brdnames[brdp->brdtype], brdp->brdnr,
4381 brdp->iobase, (int) brdp->memaddr);
4382 return(ENODEV);
4385 stli_initports(brdp);
4386 printk(KERN_INFO "STALLION: %s found, board=%d io=%x mem=%x "
4387 "nrpanels=%d nrports=%d\n", stli_brdnames[brdp->brdtype],
4388 brdp->brdnr, brdp->iobase, (int) brdp->memaddr,
4389 brdp->nrpanels, brdp->nrports);
4390 return(0);
4393 /*****************************************************************************/
4396 * Probe around trying to find where the EISA boards shared memory
4397 * might be. This is a bit if hack, but it is the best we can do.
4400 static inline int stli_eisamemprobe(stlibrd_t *brdp)
4402 cdkecpsig_t ecpsig, *ecpsigp;
4403 cdkonbsig_t onbsig, *onbsigp;
4404 int i, foundit;
4406 #if DEBUG
4407 printk(KERN_DEBUG "stli_eisamemprobe(brdp=%x)\n", (int) brdp);
4408 #endif
4411 * First up we reset the board, to get it into a known state. There
4412 * is only 2 board types here we need to worry about. Don;t use the
4413 * standard board init routine here, it programs up the shared
4414 * memory address, and we don't know it yet...
4416 if (brdp->brdtype == BRD_ECPE) {
4417 outb(0x1, (brdp->iobase + ECP_EIBRDENAB));
4418 outb(ECP_EISTOP, (brdp->iobase + ECP_EICONFR));
4419 udelay(10);
4420 outb(ECP_EIDISABLE, (brdp->iobase + ECP_EICONFR));
4421 udelay(500);
4422 stli_ecpeienable(brdp);
4423 } else if (brdp->brdtype == BRD_ONBOARDE) {
4424 outb(0x1, (brdp->iobase + ONB_EIBRDENAB));
4425 outb(ONB_EISTOP, (brdp->iobase + ONB_EICONFR));
4426 udelay(10);
4427 outb(ONB_EIDISABLE, (brdp->iobase + ONB_EICONFR));
4428 mdelay(100);
4429 outb(0x1, brdp->iobase);
4430 mdelay(1);
4431 stli_onbeenable(brdp);
4432 } else {
4433 return(-ENODEV);
4436 foundit = 0;
4437 brdp->memsize = ECP_MEMSIZE;
4440 * Board shared memory is enabled, so now we have a poke around and
4441 * see if we can find it.
4443 for (i = 0; (i < stli_eisamempsize); i++) {
4444 brdp->memaddr = stli_eisamemprobeaddrs[i];
4445 brdp->membase = (void *) brdp->memaddr;
4446 brdp->membase = ioremap(brdp->memaddr, brdp->memsize);
4447 if (brdp->membase == (void *) NULL)
4448 continue;
4450 if (brdp->brdtype == BRD_ECPE) {
4451 ecpsigp = (cdkecpsig_t *) stli_ecpeigetmemptr(brdp,
4452 CDK_SIGADDR, __LINE__);
4453 memcpy(&ecpsig, ecpsigp, sizeof(cdkecpsig_t));
4454 if (ecpsig.magic == ECP_MAGIC)
4455 foundit = 1;
4456 } else {
4457 onbsigp = (cdkonbsig_t *) stli_onbegetmemptr(brdp,
4458 CDK_SIGADDR, __LINE__);
4459 memcpy(&onbsig, onbsigp, sizeof(cdkonbsig_t));
4460 if ((onbsig.magic0 == ONB_MAGIC0) &&
4461 (onbsig.magic1 == ONB_MAGIC1) &&
4462 (onbsig.magic2 == ONB_MAGIC2) &&
4463 (onbsig.magic3 == ONB_MAGIC3))
4464 foundit = 1;
4467 iounmap(brdp->membase);
4468 if (foundit)
4469 break;
4473 * Regardless of whether we found the shared memory or not we must
4474 * disable the region. After that return success or failure.
4476 if (brdp->brdtype == BRD_ECPE)
4477 stli_ecpeidisable(brdp);
4478 else
4479 stli_onbedisable(brdp);
4481 if (! foundit) {
4482 brdp->memaddr = 0;
4483 brdp->membase = 0;
4484 printk(KERN_ERR "STALLION: failed to probe shared memory "
4485 "region for %s in EISA slot=%d\n",
4486 stli_brdnames[brdp->brdtype], (brdp->iobase >> 12));
4487 return(-ENODEV);
4489 return(0);
4492 /*****************************************************************************/
4495 * Probe around and try to find any EISA boards in system. The biggest
4496 * problem here is finding out what memory address is associated with
4497 * an EISA board after it is found. The registers of the ECPE and
4498 * ONboardE are not readable - so we can't read them from there. We
4499 * don't have access to the EISA CMOS (or EISA BIOS) so we don't
4500 * actually have any way to find out the real value. The best we can
4501 * do is go probing around in the usual places hoping we can find it.
4504 static inline int stli_findeisabrds()
4506 stlibrd_t *brdp;
4507 unsigned int iobase, eid;
4508 int i;
4510 #if DEBUG
4511 printk(KERN_DEBUG "stli_findeisabrds()\n");
4512 #endif
4515 * Firstly check if this is an EISA system. Do this by probing for
4516 * the system board EISA ID. If this is not an EISA system then
4517 * don't bother going any further!
4519 outb(0xff, 0xc80);
4520 if (inb(0xc80) == 0xff)
4521 return(0);
4524 * Looks like an EISA system, so go searching for EISA boards.
4526 for (iobase = 0x1000; (iobase <= 0xc000); iobase += 0x1000) {
4527 outb(0xff, (iobase + 0xc80));
4528 eid = inb(iobase + 0xc80);
4529 eid |= inb(iobase + 0xc81) << 8;
4530 if (eid != STL_EISAID)
4531 continue;
4534 * We have found a board. Need to check if this board was
4535 * statically configured already (just in case!).
4537 for (i = 0; (i < STL_MAXBRDS); i++) {
4538 brdp = stli_brds[i];
4539 if (brdp == (stlibrd_t *) NULL)
4540 continue;
4541 if (brdp->iobase == iobase)
4542 break;
4544 if (i < STL_MAXBRDS)
4545 continue;
4548 * We have found a Stallion board and it is not configured already.
4549 * Allocate a board structure and initialize it.
4551 if ((brdp = stli_allocbrd()) == (stlibrd_t *) NULL)
4552 return(-ENOMEM);
4553 if ((brdp->brdnr = stli_getbrdnr()) < 0)
4554 return(-ENOMEM);
4555 eid = inb(iobase + 0xc82);
4556 if (eid == ECP_EISAID)
4557 brdp->brdtype = BRD_ECPE;
4558 else if (eid == ONB_EISAID)
4559 brdp->brdtype = BRD_ONBOARDE;
4560 else
4561 brdp->brdtype = BRD_UNKNOWN;
4562 brdp->iobase = iobase;
4563 outb(0x1, (iobase + 0xc84));
4564 if (stli_eisamemprobe(brdp))
4565 outb(0, (iobase + 0xc84));
4566 stli_brdinit(brdp);
4569 return(0);
4572 /*****************************************************************************/
4575 * Find the next available board number that is free.
4578 static inline int stli_getbrdnr()
4580 int i;
4582 for (i = 0; (i < STL_MAXBRDS); i++) {
4583 if (stli_brds[i] == (stlibrd_t *) NULL) {
4584 if (i >= stli_nrbrds)
4585 stli_nrbrds = i + 1;
4586 return(i);
4589 return(-1);
4592 /*****************************************************************************/
4594 #ifdef CONFIG_PCI
4597 * We have a Stallion board. Allocate a board structure and
4598 * initialize it. Read its IO and MEMORY resources from PCI
4599 * configuration space.
4602 static inline int stli_initpcibrd(int brdtype, struct pci_dev *devp)
4604 stlibrd_t *brdp;
4606 #if DEBUG
4607 printk(KERN_DEBUG "stli_initpcibrd(brdtype=%d,busnr=%x,devnr=%x)\n",
4608 brdtype, dev->bus->number, dev->devfn);
4609 #endif
4611 if (pci_enable_device(devp))
4612 return(-EIO);
4613 if ((brdp = stli_allocbrd()) == (stlibrd_t *) NULL)
4614 return(-ENOMEM);
4615 if ((brdp->brdnr = stli_getbrdnr()) < 0) {
4616 printk(KERN_INFO "STALLION: too many boards found, "
4617 "maximum supported %d\n", STL_MAXBRDS);
4618 return(0);
4620 brdp->brdtype = brdtype;
4622 #if DEBUG
4623 printk(KERN_DEBUG "%s(%d): BAR[]=%lx,%lx,%lx,%lx\n", __FILE__, __LINE__,
4624 pci_resource_start(devp, 0),
4625 pci_resource_start(devp, 1),
4626 pci_resource_start(devp, 2),
4627 pci_resource_start(devp, 3));
4628 #endif
4631 * We have all resources from the board, so lets setup the actual
4632 * board structure now.
4634 brdp->iobase = pci_resource_start(devp, 3);
4635 brdp->memaddr = pci_resource_start(devp, 2);
4636 stli_brdinit(brdp);
4638 return(0);
4641 /*****************************************************************************/
4644 * Find all Stallion PCI boards that might be installed. Initialize each
4645 * one as it is found.
4648 static inline int stli_findpcibrds()
4650 struct pci_dev *dev = NULL;
4651 int rc;
4653 #if DEBUG
4654 printk("stli_findpcibrds()\n");
4655 #endif
4657 while ((dev = pci_find_device(PCI_VENDOR_ID_STALLION,
4658 PCI_DEVICE_ID_ECRA, dev))) {
4659 if ((rc = stli_initpcibrd(BRD_ECPPCI, dev)))
4660 return(rc);
4663 return(0);
4666 #endif
4668 /*****************************************************************************/
4671 * Allocate a new board structure. Fill out the basic info in it.
4674 static stlibrd_t *stli_allocbrd()
4676 stlibrd_t *brdp;
4678 brdp = (stlibrd_t *) stli_memalloc(sizeof(stlibrd_t));
4679 if (brdp == (stlibrd_t *) NULL) {
4680 printk(KERN_ERR "STALLION: failed to allocate memory "
4681 "(size=%d)\n", sizeof(stlibrd_t));
4682 return((stlibrd_t *) NULL);
4685 memset(brdp, 0, sizeof(stlibrd_t));
4686 brdp->magic = STLI_BOARDMAGIC;
4687 return(brdp);
4690 /*****************************************************************************/
4693 * Scan through all the boards in the configuration and see what we
4694 * can find.
4697 static inline int stli_initbrds()
4699 stlibrd_t *brdp, *nxtbrdp;
4700 stlconf_t *confp;
4701 int i, j;
4703 #if DEBUG
4704 printk(KERN_DEBUG "stli_initbrds()\n");
4705 #endif
4707 if (stli_nrbrds > STL_MAXBRDS) {
4708 printk(KERN_INFO "STALLION: too many boards in configuration "
4709 "table, truncating to %d\n", STL_MAXBRDS);
4710 stli_nrbrds = STL_MAXBRDS;
4714 * Firstly scan the list of static boards configured. Allocate
4715 * resources and initialize the boards as found. If this is a
4716 * module then let the module args override static configuration.
4718 for (i = 0; (i < stli_nrbrds); i++) {
4719 confp = &stli_brdconf[i];
4720 #ifdef MODULE
4721 stli_parsebrd(confp, stli_brdsp[i]);
4722 #endif
4723 if ((brdp = stli_allocbrd()) == (stlibrd_t *) NULL)
4724 return(-ENOMEM);
4725 brdp->brdnr = i;
4726 brdp->brdtype = confp->brdtype;
4727 brdp->iobase = confp->ioaddr1;
4728 brdp->memaddr = confp->memaddr;
4729 stli_brdinit(brdp);
4733 * Static configuration table done, so now use dynamic methods to
4734 * see if any more boards should be configured.
4736 #ifdef MODULE
4737 stli_argbrds();
4738 #endif
4739 if (stli_eisaprobe)
4740 stli_findeisabrds();
4741 #ifdef CONFIG_PCI
4742 stli_findpcibrds();
4743 #endif
4746 * All found boards are initialized. Now for a little optimization, if
4747 * no boards are sharing the "shared memory" regions then we can just
4748 * leave them all enabled. This is in fact the usual case.
4750 stli_shared = 0;
4751 if (stli_nrbrds > 1) {
4752 for (i = 0; (i < stli_nrbrds); i++) {
4753 brdp = stli_brds[i];
4754 if (brdp == (stlibrd_t *) NULL)
4755 continue;
4756 for (j = i + 1; (j < stli_nrbrds); j++) {
4757 nxtbrdp = stli_brds[j];
4758 if (nxtbrdp == (stlibrd_t *) NULL)
4759 continue;
4760 if ((brdp->membase >= nxtbrdp->membase) &&
4761 (brdp->membase <= (nxtbrdp->membase +
4762 nxtbrdp->memsize - 1))) {
4763 stli_shared++;
4764 break;
4770 if (stli_shared == 0) {
4771 for (i = 0; (i < stli_nrbrds); i++) {
4772 brdp = stli_brds[i];
4773 if (brdp == (stlibrd_t *) NULL)
4774 continue;
4775 if (brdp->state & BST_FOUND) {
4776 EBRDENABLE(brdp);
4777 brdp->enable = NULL;
4778 brdp->disable = NULL;
4783 return(0);
4786 /*****************************************************************************/
4789 * Code to handle an "staliomem" read operation. This device is the
4790 * contents of the board shared memory. It is used for down loading
4791 * the slave image (and debugging :-)
4794 static ssize_t stli_memread(struct file *fp, char *buf, size_t count, loff_t *offp)
4796 unsigned long flags;
4797 void *memptr;
4798 stlibrd_t *brdp;
4799 int brdnr, size, n;
4801 #if DEBUG
4802 printk(KERN_DEBUG "stli_memread(fp=%x,buf=%x,count=%x,offp=%x)\n",
4803 (int) fp, (int) buf, count, (int) offp);
4804 #endif
4806 brdnr = iminor(fp->f_dentry->d_inode);
4807 if (brdnr >= stli_nrbrds)
4808 return(-ENODEV);
4809 brdp = stli_brds[brdnr];
4810 if (brdp == (stlibrd_t *) NULL)
4811 return(-ENODEV);
4812 if (brdp->state == 0)
4813 return(-ENODEV);
4814 if (fp->f_pos >= brdp->memsize)
4815 return(0);
4817 size = MIN(count, (brdp->memsize - fp->f_pos));
4819 save_flags(flags);
4820 cli();
4821 EBRDENABLE(brdp);
4822 while (size > 0) {
4823 memptr = (void *) EBRDGETMEMPTR(brdp, fp->f_pos);
4824 n = MIN(size, (brdp->pagesize - (((unsigned long) fp->f_pos) % brdp->pagesize)));
4825 if (copy_to_user(buf, memptr, n)) {
4826 count = -EFAULT;
4827 goto out;
4829 fp->f_pos += n;
4830 buf += n;
4831 size -= n;
4833 out:
4834 EBRDDISABLE(brdp);
4835 restore_flags(flags);
4837 return(count);
4840 /*****************************************************************************/
4843 * Code to handle an "staliomem" write operation. This device is the
4844 * contents of the board shared memory. It is used for down loading
4845 * the slave image (and debugging :-)
4848 static ssize_t stli_memwrite(struct file *fp, const char *buf, size_t count, loff_t *offp)
4850 unsigned long flags;
4851 void *memptr;
4852 stlibrd_t *brdp;
4853 char *chbuf;
4854 int brdnr, size, n;
4856 #if DEBUG
4857 printk(KERN_DEBUG "stli_memwrite(fp=%x,buf=%x,count=%x,offp=%x)\n",
4858 (int) fp, (int) buf, count, (int) offp);
4859 #endif
4861 brdnr = iminor(fp->f_dentry->d_inode);
4862 if (brdnr >= stli_nrbrds)
4863 return(-ENODEV);
4864 brdp = stli_brds[brdnr];
4865 if (brdp == (stlibrd_t *) NULL)
4866 return(-ENODEV);
4867 if (brdp->state == 0)
4868 return(-ENODEV);
4869 if (fp->f_pos >= brdp->memsize)
4870 return(0);
4872 chbuf = (char *) buf;
4873 size = MIN(count, (brdp->memsize - fp->f_pos));
4875 save_flags(flags);
4876 cli();
4877 EBRDENABLE(brdp);
4878 while (size > 0) {
4879 memptr = (void *) EBRDGETMEMPTR(brdp, fp->f_pos);
4880 n = MIN(size, (brdp->pagesize - (((unsigned long) fp->f_pos) % brdp->pagesize)));
4881 if (copy_from_user(memptr, chbuf, n)) {
4882 count = -EFAULT;
4883 goto out;
4885 fp->f_pos += n;
4886 chbuf += n;
4887 size -= n;
4889 out:
4890 EBRDDISABLE(brdp);
4891 restore_flags(flags);
4893 return(count);
4896 /*****************************************************************************/
4899 * Return the board stats structure to user app.
4902 static int stli_getbrdstats(combrd_t *bp)
4904 stlibrd_t *brdp;
4905 int i;
4907 if (copy_from_user(&stli_brdstats, bp, sizeof(combrd_t)))
4908 return -EFAULT;
4909 if (stli_brdstats.brd >= STL_MAXBRDS)
4910 return(-ENODEV);
4911 brdp = stli_brds[stli_brdstats.brd];
4912 if (brdp == (stlibrd_t *) NULL)
4913 return(-ENODEV);
4915 memset(&stli_brdstats, 0, sizeof(combrd_t));
4916 stli_brdstats.brd = brdp->brdnr;
4917 stli_brdstats.type = brdp->brdtype;
4918 stli_brdstats.hwid = 0;
4919 stli_brdstats.state = brdp->state;
4920 stli_brdstats.ioaddr = brdp->iobase;
4921 stli_brdstats.memaddr = brdp->memaddr;
4922 stli_brdstats.nrpanels = brdp->nrpanels;
4923 stli_brdstats.nrports = brdp->nrports;
4924 for (i = 0; (i < brdp->nrpanels); i++) {
4925 stli_brdstats.panels[i].panel = i;
4926 stli_brdstats.panels[i].hwid = brdp->panelids[i];
4927 stli_brdstats.panels[i].nrports = brdp->panels[i];
4930 if (copy_to_user(bp, &stli_brdstats, sizeof(combrd_t)))
4931 return -EFAULT;
4932 return(0);
4935 /*****************************************************************************/
4938 * Resolve the referenced port number into a port struct pointer.
4941 static stliport_t *stli_getport(int brdnr, int panelnr, int portnr)
4943 stlibrd_t *brdp;
4944 int i;
4946 if ((brdnr < 0) || (brdnr >= STL_MAXBRDS))
4947 return((stliport_t *) NULL);
4948 brdp = stli_brds[brdnr];
4949 if (brdp == (stlibrd_t *) NULL)
4950 return((stliport_t *) NULL);
4951 for (i = 0; (i < panelnr); i++)
4952 portnr += brdp->panels[i];
4953 if ((portnr < 0) || (portnr >= brdp->nrports))
4954 return((stliport_t *) NULL);
4955 return(brdp->ports[portnr]);
4958 /*****************************************************************************/
4961 * Return the port stats structure to user app. A NULL port struct
4962 * pointer passed in means that we need to find out from the app
4963 * what port to get stats for (used through board control device).
4966 static int stli_portcmdstats(stliport_t *portp)
4968 unsigned long flags;
4969 stlibrd_t *brdp;
4970 int rc;
4972 memset(&stli_comstats, 0, sizeof(comstats_t));
4974 if (portp == (stliport_t *) NULL)
4975 return(-ENODEV);
4976 brdp = stli_brds[portp->brdnr];
4977 if (brdp == (stlibrd_t *) NULL)
4978 return(-ENODEV);
4980 if (brdp->state & BST_STARTED) {
4981 if ((rc = stli_cmdwait(brdp, portp, A_GETSTATS,
4982 &stli_cdkstats, sizeof(asystats_t), 1)) < 0)
4983 return(rc);
4984 } else {
4985 memset(&stli_cdkstats, 0, sizeof(asystats_t));
4988 stli_comstats.brd = portp->brdnr;
4989 stli_comstats.panel = portp->panelnr;
4990 stli_comstats.port = portp->portnr;
4991 stli_comstats.state = portp->state;
4992 stli_comstats.flags = portp->flags;
4994 save_flags(flags);
4995 cli();
4996 if (portp->tty != (struct tty_struct *) NULL) {
4997 if (portp->tty->driver_data == portp) {
4998 stli_comstats.ttystate = portp->tty->flags;
4999 stli_comstats.rxbuffered = portp->tty->flip.count;
5000 if (portp->tty->termios != (struct termios *) NULL) {
5001 stli_comstats.cflags = portp->tty->termios->c_cflag;
5002 stli_comstats.iflags = portp->tty->termios->c_iflag;
5003 stli_comstats.oflags = portp->tty->termios->c_oflag;
5004 stli_comstats.lflags = portp->tty->termios->c_lflag;
5008 restore_flags(flags);
5010 stli_comstats.txtotal = stli_cdkstats.txchars;
5011 stli_comstats.rxtotal = stli_cdkstats.rxchars + stli_cdkstats.ringover;
5012 stli_comstats.txbuffered = stli_cdkstats.txringq;
5013 stli_comstats.rxbuffered += stli_cdkstats.rxringq;
5014 stli_comstats.rxoverrun = stli_cdkstats.overruns;
5015 stli_comstats.rxparity = stli_cdkstats.parity;
5016 stli_comstats.rxframing = stli_cdkstats.framing;
5017 stli_comstats.rxlost = stli_cdkstats.ringover;
5018 stli_comstats.rxbreaks = stli_cdkstats.rxbreaks;
5019 stli_comstats.txbreaks = stli_cdkstats.txbreaks;
5020 stli_comstats.txxon = stli_cdkstats.txstart;
5021 stli_comstats.txxoff = stli_cdkstats.txstop;
5022 stli_comstats.rxxon = stli_cdkstats.rxstart;
5023 stli_comstats.rxxoff = stli_cdkstats.rxstop;
5024 stli_comstats.rxrtsoff = stli_cdkstats.rtscnt / 2;
5025 stli_comstats.rxrtson = stli_cdkstats.rtscnt - stli_comstats.rxrtsoff;
5026 stli_comstats.modem = stli_cdkstats.dcdcnt;
5027 stli_comstats.hwid = stli_cdkstats.hwid;
5028 stli_comstats.signals = stli_mktiocm(stli_cdkstats.signals);
5030 return(0);
5033 /*****************************************************************************/
5036 * Return the port stats structure to user app. A NULL port struct
5037 * pointer passed in means that we need to find out from the app
5038 * what port to get stats for (used through board control device).
5041 static int stli_getportstats(stliport_t *portp, comstats_t *cp)
5043 stlibrd_t *brdp;
5044 int rc;
5046 if (portp == (stliport_t *) NULL) {
5047 if (copy_from_user(&stli_comstats, cp, sizeof(comstats_t)))
5048 return -EFAULT;
5049 portp = stli_getport(stli_comstats.brd, stli_comstats.panel,
5050 stli_comstats.port);
5051 if (portp == (stliport_t *) NULL)
5052 return(-ENODEV);
5055 brdp = stli_brds[portp->brdnr];
5056 if (brdp == (stlibrd_t *) NULL)
5057 return(-ENODEV);
5059 if ((rc = stli_portcmdstats(portp)) < 0)
5060 return(rc);
5062 return copy_to_user(cp, &stli_comstats, sizeof(comstats_t)) ?
5063 -EFAULT : 0;
5066 /*****************************************************************************/
5069 * Clear the port stats structure. We also return it zeroed out...
5072 static int stli_clrportstats(stliport_t *portp, comstats_t *cp)
5074 stlibrd_t *brdp;
5075 int rc;
5077 if (portp == (stliport_t *) NULL) {
5078 if (copy_from_user(&stli_comstats, cp, sizeof(comstats_t)))
5079 return -EFAULT;
5080 portp = stli_getport(stli_comstats.brd, stli_comstats.panel,
5081 stli_comstats.port);
5082 if (portp == (stliport_t *) NULL)
5083 return(-ENODEV);
5086 brdp = stli_brds[portp->brdnr];
5087 if (brdp == (stlibrd_t *) NULL)
5088 return(-ENODEV);
5090 if (brdp->state & BST_STARTED) {
5091 if ((rc = stli_cmdwait(brdp, portp, A_CLEARSTATS, 0, 0, 0)) < 0)
5092 return(rc);
5095 memset(&stli_comstats, 0, sizeof(comstats_t));
5096 stli_comstats.brd = portp->brdnr;
5097 stli_comstats.panel = portp->panelnr;
5098 stli_comstats.port = portp->portnr;
5100 if (copy_to_user(cp, &stli_comstats, sizeof(comstats_t)))
5101 return -EFAULT;
5102 return(0);
5105 /*****************************************************************************/
5108 * Return the entire driver ports structure to a user app.
5111 static int stli_getportstruct(unsigned long arg)
5113 stliport_t *portp;
5115 if (copy_from_user(&stli_dummyport, (void *)arg, sizeof(stliport_t)))
5116 return -EFAULT;
5117 portp = stli_getport(stli_dummyport.brdnr, stli_dummyport.panelnr,
5118 stli_dummyport.portnr);
5119 if (portp == (stliport_t *) NULL)
5120 return(-ENODEV);
5121 if (copy_to_user((void *) arg, portp, sizeof(stliport_t)))
5122 return -EFAULT;
5123 return(0);
5126 /*****************************************************************************/
5129 * Return the entire driver board structure to a user app.
5132 static int stli_getbrdstruct(unsigned long arg)
5134 stlibrd_t *brdp;
5136 if (copy_from_user(&stli_dummybrd, (void *)arg, sizeof(stlibrd_t)))
5137 return -EFAULT;
5138 if ((stli_dummybrd.brdnr < 0) || (stli_dummybrd.brdnr >= STL_MAXBRDS))
5139 return(-ENODEV);
5140 brdp = stli_brds[stli_dummybrd.brdnr];
5141 if (brdp == (stlibrd_t *) NULL)
5142 return(-ENODEV);
5143 if (copy_to_user((void *) arg, brdp, sizeof(stlibrd_t)))
5144 return -EFAULT;
5145 return(0);
5148 /*****************************************************************************/
5151 * The "staliomem" device is also required to do some special operations on
5152 * the board. We need to be able to send an interrupt to the board,
5153 * reset it, and start/stop it.
5156 static int stli_memioctl(struct inode *ip, struct file *fp, unsigned int cmd, unsigned long arg)
5158 stlibrd_t *brdp;
5159 int brdnr, rc, done;
5161 #if DEBUG
5162 printk(KERN_DEBUG "stli_memioctl(ip=%x,fp=%x,cmd=%x,arg=%x)\n",
5163 (int) ip, (int) fp, cmd, (int) arg);
5164 #endif
5167 * First up handle the board independent ioctls.
5169 done = 0;
5170 rc = 0;
5172 switch (cmd) {
5173 case COM_GETPORTSTATS:
5174 rc = stli_getportstats((stliport_t *)NULL, (comstats_t *)arg);
5175 done++;
5176 break;
5177 case COM_CLRPORTSTATS:
5178 rc = stli_clrportstats((stliport_t *)NULL, (comstats_t *)arg);
5179 done++;
5180 break;
5181 case COM_GETBRDSTATS:
5182 rc = stli_getbrdstats((combrd_t *) arg);
5183 done++;
5184 break;
5185 case COM_READPORT:
5186 rc = stli_getportstruct(arg);
5187 done++;
5188 break;
5189 case COM_READBOARD:
5190 rc = stli_getbrdstruct(arg);
5191 done++;
5192 break;
5195 if (done)
5196 return(rc);
5199 * Now handle the board specific ioctls. These all depend on the
5200 * minor number of the device they were called from.
5202 brdnr = iminor(ip);
5203 if (brdnr >= STL_MAXBRDS)
5204 return(-ENODEV);
5205 brdp = stli_brds[brdnr];
5206 if (brdp == (stlibrd_t *) NULL)
5207 return(-ENODEV);
5208 if (brdp->state == 0)
5209 return(-ENODEV);
5211 switch (cmd) {
5212 case STL_BINTR:
5213 EBRDINTR(brdp);
5214 break;
5215 case STL_BSTART:
5216 rc = stli_startbrd(brdp);
5217 break;
5218 case STL_BSTOP:
5219 brdp->state &= ~BST_STARTED;
5220 break;
5221 case STL_BRESET:
5222 brdp->state &= ~BST_STARTED;
5223 EBRDRESET(brdp);
5224 if (stli_shared == 0) {
5225 if (brdp->reenable != NULL)
5226 (* brdp->reenable)(brdp);
5228 break;
5229 default:
5230 rc = -ENOIOCTLCMD;
5231 break;
5234 return(rc);
5237 static struct tty_operations stli_ops = {
5238 .open = stli_open,
5239 .close = stli_close,
5240 .write = stli_write,
5241 .put_char = stli_putchar,
5242 .flush_chars = stli_flushchars,
5243 .write_room = stli_writeroom,
5244 .chars_in_buffer = stli_charsinbuffer,
5245 .ioctl = stli_ioctl,
5246 .set_termios = stli_settermios,
5247 .throttle = stli_throttle,
5248 .unthrottle = stli_unthrottle,
5249 .stop = stli_stop,
5250 .start = stli_start,
5251 .hangup = stli_hangup,
5252 .flush_buffer = stli_flushbuffer,
5253 .break_ctl = stli_breakctl,
5254 .wait_until_sent = stli_waituntilsent,
5255 .send_xchar = stli_sendxchar,
5256 .read_proc = stli_readproc,
5259 /*****************************************************************************/
5261 int __init stli_init(void)
5263 int i;
5264 printk(KERN_INFO "%s: version %s\n", stli_drvtitle, stli_drvversion);
5266 stli_initbrds();
5268 stli_serial = alloc_tty_driver(STL_MAXBRDS * STL_MAXPORTS);
5269 if (!stli_serial)
5270 return -ENOMEM;
5273 * Allocate a temporary write buffer.
5275 stli_tmpwritebuf = (char *) stli_memalloc(STLI_TXBUFSIZE);
5276 if (stli_tmpwritebuf == (char *) NULL)
5277 printk(KERN_ERR "STALLION: failed to allocate memory "
5278 "(size=%d)\n", STLI_TXBUFSIZE);
5279 stli_txcookbuf = stli_memalloc(STLI_TXBUFSIZE);
5280 if (stli_txcookbuf == (char *) NULL)
5281 printk(KERN_ERR "STALLION: failed to allocate memory "
5282 "(size=%d)\n", STLI_TXBUFSIZE);
5285 * Set up a character driver for the shared memory region. We need this
5286 * to down load the slave code image. Also it is a useful debugging tool.
5288 if (register_chrdev(STL_SIOMEMMAJOR, "staliomem", &stli_fsiomem))
5289 printk(KERN_ERR "STALLION: failed to register serial memory "
5290 "device\n");
5292 devfs_mk_dir("staliomem");
5293 for (i = 0; i < 4; i++) {
5294 devfs_mk_cdev(MKDEV(STL_SIOMEMMAJOR, i),
5295 S_IFCHR | S_IRUSR | S_IWUSR,
5296 "staliomem/%d", i);
5300 * Set up the tty driver structure and register us as a driver.
5302 stli_serial->owner = THIS_MODULE;
5303 stli_serial->driver_name = stli_drvname;
5304 stli_serial->name = stli_serialname;
5305 stli_serial->major = STL_SERIALMAJOR;
5306 stli_serial->minor_start = 0;
5307 stli_serial->type = TTY_DRIVER_TYPE_SERIAL;
5308 stli_serial->subtype = SERIAL_TYPE_NORMAL;
5309 stli_serial->init_termios = stli_deftermios;
5310 stli_serial->flags = TTY_DRIVER_REAL_RAW;
5311 tty_set_operations(stli_serial, &stli_ops);
5313 if (tty_register_driver(stli_serial)) {
5314 put_tty_driver(stli_serial);
5315 printk(KERN_ERR "STALLION: failed to register serial driver\n");
5316 return -EBUSY;
5318 return(0);
5321 /*****************************************************************************/