1 /*****************************************************************************/
2
3 /*
4 * istallion.c -- stallion intelligent multiport serial driver.
5 *
6 * Copyright (C) 1996-1999 Stallion Technologies (support@stallion.oz.au).
7 * Copyright (C) 1994-1996 Greg Ungerer.
8 *
9 * This code is loosely based on the Linux serial driver, written by
10 * Linus Torvalds, Theodore T'so and others.
11 *
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.
16 *
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.
21 *
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.
25 */
26
27 /*****************************************************************************/
28
29 #include <linux/config.h>
30 #include <linux/module.h>
31 #include <linux/malloc.h>
32 #include <linux/interrupt.h>
33 #include <linux/tty_flip.h>
34 #include <linux/serial.h>
35 #include <linux/cdk.h>
36 #include <linux/comstats.h>
37 #include <linux/version.h>
38 #include <linux/istallion.h>
39 #include <linux/ioport.h>
40 #include <linux/delay.h>
41 #include <linux/init.h>
42 #include <linux/devfs_fs_kernel.h>
43
44 #include <asm/io.h>
45 #include <asm/uaccess.h>
46
47 #ifdef CONFIG_PCI
48 #include <linux/pci.h>
49 #endif
50
51 /*****************************************************************************/
52
53 /*
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.
59 */
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
81
82 #define BRD_BRUMBY BRD_BRUMBY4
83
84 /*
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.
121 */
122
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;
131
132 static stlconf_t stli_brdconf[] = {
133 /*{ BRD_ECP, 0x2a0, 0, 0xcc000, 0, 0 },*/
134 };
135
136 static int stli_nrbrds = sizeof(stli_brdconf) / sizeof(stlconf_t);
137
138 /*
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.
142 */
143 #define STLI_EISAPROBE 0
144
145 static devfs_handle_t devfs_handle;
146
147 /*****************************************************************************/
148
149 /*
150 * Define some important driver characteristics. Device major numbers
151 * allocated as per Linux Device Registry.
152 */
153 #ifndef STL_SIOMEMMAJOR
154 #define STL_SIOMEMMAJOR 28
155 #endif
156 #ifndef STL_SERIALMAJOR
157 #define STL_SERIALMAJOR 24
158 #endif
159 #ifndef STL_CALLOUTMAJOR
160 #define STL_CALLOUTMAJOR 25
161 #endif
162
163 #define STL_DRVTYPSERIAL 1
164 #define STL_DRVTYPCALLOUT 2
165
166 /*****************************************************************************/
167
168 /*
169 * Define our local driver identity first. Set up stuff to deal with
170 * all the local structures required by a serial tty driver.
171 */
172 static char *stli_drvtitle = "Stallion Intelligent Multiport Serial Driver";
173 static char *stli_drvname = "istallion";
174 static char *stli_drvversion = "5.6.0";
175 static char *stli_serialname = "ttyE";
176 static char *stli_calloutname = "cue";
177
178 static struct tty_driver stli_serial;
179 static struct tty_driver stli_callout;
180 static struct tty_struct *stli_ttys[STL_MAXDEVS];
181 static struct termios *stli_termios[STL_MAXDEVS];
182 static struct termios *stli_termioslocked[STL_MAXDEVS];
183 static int stli_refcount;
184
185 /*
186 * We will need to allocate a temporary write buffer for chars that
187 * come direct from user space. The problem is that a copy from user
188 * space might cause a page fault (typically on a system that is
189 * swapping!). All ports will share one buffer - since if the system
190 * is already swapping a shared buffer won't make things any worse.
191 */
192 static char *stli_tmpwritebuf;
193 static DECLARE_MUTEX(stli_tmpwritesem);
194
195 #define STLI_TXBUFSIZE 4096
196
197 /*
198 * Use a fast local buffer for cooked characters. Typically a whole
199 * bunch of cooked characters come in for a port, 1 at a time. So we
200 * save those up into a local buffer, then write out the whole lot
201 * with a large memcpy. Just use 1 buffer for all ports, since its
202 * use it is only need for short periods of time by each port.
203 */
204 static char *stli_txcookbuf;
205 static int stli_txcooksize;
206 static int stli_txcookrealsize;
207 static struct tty_struct *stli_txcooktty;
208
209 /*
210 * Define a local default termios struct. All ports will be created
211 * with this termios initially. Basically all it defines is a raw port
212 * at 9600 baud, 8 data bits, no parity, 1 stop bit.
213 */
214 static struct termios stli_deftermios = {
215 0,
216 0,
217 (B9600 | CS8 | CREAD | HUPCL | CLOCAL),
218 0,
219 0,
220 INIT_C_CC
221 };
222
223 /*
224 * Define global stats structures. Not used often, and can be
225 * re-used for each stats call.
226 */
227 static comstats_t stli_comstats;
228 static combrd_t stli_brdstats;
229 static asystats_t stli_cdkstats;
230 static stlibrd_t stli_dummybrd;
231 static stliport_t stli_dummyport;
232
233 /*****************************************************************************/
234
235 static stlibrd_t *stli_brds[STL_MAXBRDS];
236
237 static int stli_shared;
238
239 /*
240 * Per board state flags. Used with the state field of the board struct.
241 * Not really much here... All we need to do is keep track of whether
242 * the board has been detected, and whether it is actually running a slave
243 * or not.
244 */
245 #define BST_FOUND 0x1
246 #define BST_STARTED 0x2
247
248 /*
249 * Define the set of port state flags. These are marked for internal
250 * state purposes only, usually to do with the state of communications
251 * with the slave. Most of them need to be updated atomically, so always
252 * use the bit setting operations (unless protected by cli/sti).
253 */
254 #define ST_INITIALIZING 1
255 #define ST_OPENING 2
256 #define ST_CLOSING 3
257 #define ST_CMDING 4
258 #define ST_TXBUSY 5
259 #define ST_RXING 6
260 #define ST_DOFLUSHRX 7
261 #define ST_DOFLUSHTX 8
262 #define ST_DOSIGS 9
263 #define ST_RXSTOP 10
264 #define ST_GETSIGS 11
265
266 /*
267 * Define an array of board names as printable strings. Handy for
268 * referencing boards when printing trace and stuff.
269 */
270 static char *stli_brdnames[] = {
271 "Unknown",
272 "Stallion",
273 "Brumby",
274 "ONboard-MC",
275 "ONboard",
276 "Brumby",
277 "Brumby",
278 "ONboard-EI",
279 (char *) NULL,
280 "ONboard",
281 "ONboard-MC",
282 "ONboard-MC",
283 (char *) NULL,
284 (char *) NULL,
285 (char *) NULL,
286 (char *) NULL,
287 (char *) NULL,
288 (char *) NULL,
289 (char *) NULL,
290 (char *) NULL,
291 "EasyIO",
292 "EC8/32-AT",
293 "EC8/32-MC",
294 "EC8/64-AT",
295 "EC8/64-EI",
296 "EC8/64-MC",
297 "EC8/32-PCI",
298 "EC8/64-PCI",
299 "EasyIO-PCI",
300 "EC/RA-PCI",
301 };
302
303 /*****************************************************************************/
304
305 #ifdef MODULE
306 /*
307 * Define some string labels for arguments passed from the module
308 * load line. These allow for easy board definitions, and easy
309 * modification of the io, memory and irq resoucres.
310 */
311
312 static char *board0[8];
313 static char *board1[8];
314 static char *board2[8];
315 static char *board3[8];
316
317 static char **stli_brdsp[] = {
318 (char **) &board0,
319 (char **) &board1,
320 (char **) &board2,
321 (char **) &board3
322 };
323
324 /*
325 * Define a set of common board names, and types. This is used to
326 * parse any module arguments.
327 */
328
329 typedef struct stlibrdtype {
330 char *name;
331 int type;
332 } stlibrdtype_t;
333
334 static stlibrdtype_t stli_brdstr[] = {
335 { "stallion", BRD_STALLION },
336 { "1", BRD_STALLION },
337 { "brumby", BRD_BRUMBY },
338 { "brumby4", BRD_BRUMBY },
339 { "brumby/4", BRD_BRUMBY },
340 { "brumby-4", BRD_BRUMBY },
341 { "brumby8", BRD_BRUMBY },
342 { "brumby/8", BRD_BRUMBY },
343 { "brumby-8", BRD_BRUMBY },
344 { "brumby16", BRD_BRUMBY },
345 { "brumby/16", BRD_BRUMBY },
346 { "brumby-16", BRD_BRUMBY },
347 { "2", BRD_BRUMBY },
348 { "onboard2", BRD_ONBOARD2 },
349 { "onboard-2", BRD_ONBOARD2 },
350 { "onboard/2", BRD_ONBOARD2 },
351 { "onboard-mc", BRD_ONBOARD2 },
352 { "onboard/mc", BRD_ONBOARD2 },
353 { "onboard-mca", BRD_ONBOARD2 },
354 { "onboard/mca", BRD_ONBOARD2 },
355 { "3", BRD_ONBOARD2 },
356 { "onboard", BRD_ONBOARD },
357 { "onboardat", BRD_ONBOARD },
358 { "4", BRD_ONBOARD },
359 { "onboarde", BRD_ONBOARDE },
360 { "onboard-e", BRD_ONBOARDE },
361 { "onboard/e", BRD_ONBOARDE },
362 { "onboard-ei", BRD_ONBOARDE },
363 { "onboard/ei", BRD_ONBOARDE },
364 { "7", BRD_ONBOARDE },
365 { "ecp", BRD_ECP },
366 { "ecpat", BRD_ECP },
367 { "ec8/64", BRD_ECP },
368 { "ec8/64-at", BRD_ECP },
369 { "ec8/64-isa", BRD_ECP },
370 { "23", BRD_ECP },
371 { "ecpe", BRD_ECPE },
372 { "ecpei", BRD_ECPE },
373 { "ec8/64-e", BRD_ECPE },
374 { "ec8/64-ei", BRD_ECPE },
375 { "24", BRD_ECPE },
376 { "ecpmc", BRD_ECPMC },
377 { "ec8/64-mc", BRD_ECPMC },
378 { "ec8/64-mca", BRD_ECPMC },
379 { "25", BRD_ECPMC },
380 { "ecppci", BRD_ECPPCI },
381 { "ec/ra", BRD_ECPPCI },
382 { "ec/ra-pc", BRD_ECPPCI },
383 { "ec/ra-pci", BRD_ECPPCI },
384 { "29", BRD_ECPPCI },
385 };
386
387 /*
388 * Define the module agruments.
389 */
390 MODULE_AUTHOR("Greg Ungerer");
391 MODULE_DESCRIPTION("Stallion Intelligent Multiport Serial Driver");
392
393 MODULE_PARM(board0, "1-3s");
394 MODULE_PARM_DESC(board0, "Board 0 config -> name[,ioaddr[,memaddr]");
395 MODULE_PARM(board1, "1-3s");
396 MODULE_PARM_DESC(board1, "Board 1 config -> name[,ioaddr[,memaddr]");
397 MODULE_PARM(board2, "1-3s");
398 MODULE_PARM_DESC(board2, "Board 2 config -> name[,ioaddr[,memaddr]");
399 MODULE_PARM(board3, "1-3s");
400 MODULE_PARM_DESC(board3, "Board 3 config -> name[,ioaddr[,memaddr]");
401
402 #endif
403
404 /*
405 * Set up a default memory address table for EISA board probing.
406 * The default addresses are all bellow 1Mbyte, which has to be the
407 * case anyway. They should be safe, since we only read values from
408 * them, and interrupts are disabled while we do it. If the higher
409 * memory support is compiled in then we also try probing around
410 * the 1Gb, 2Gb and 3Gb areas as well...
411 */
412 static unsigned long stli_eisamemprobeaddrs[] = {
413 0xc0000, 0xd0000, 0xe0000, 0xf0000,
414 0x80000000, 0x80010000, 0x80020000, 0x80030000,
415 0x40000000, 0x40010000, 0x40020000, 0x40030000,
416 0xc0000000, 0xc0010000, 0xc0020000, 0xc0030000,
417 0xff000000, 0xff010000, 0xff020000, 0xff030000,
418 };
419
420 static int stli_eisamempsize = sizeof(stli_eisamemprobeaddrs) / sizeof(unsigned long);
421 int stli_eisaprobe = STLI_EISAPROBE;
422
423 /*
424 * Define the Stallion PCI vendor and device IDs.
425 */
426 #ifdef CONFIG_PCI
427 #ifndef PCI_VENDOR_ID_STALLION
428 #define PCI_VENDOR_ID_STALLION 0x124d
429 #endif
430 #ifndef PCI_DEVICE_ID_ECRA
431 #define PCI_DEVICE_ID_ECRA 0x0004
432 #endif
433 #endif
434
435 /*****************************************************************************/
436
437 /*
438 * Hardware configuration info for ECP boards. These defines apply
439 * to the directly accessible io ports of the ECP. There is a set of
440 * defines for each ECP board type, ISA, EISA, MCA and PCI.
441 */
442 #define ECP_IOSIZE 4
443
444 #define ECP_MEMSIZE (128 * 1024)
445 #define ECP_PCIMEMSIZE (256 * 1024)
446
447 #define ECP_ATPAGESIZE (4 * 1024)
448 #define ECP_MCPAGESIZE (4 * 1024)
449 #define ECP_EIPAGESIZE (64 * 1024)
450 #define ECP_PCIPAGESIZE (64 * 1024)
451
452 #define STL_EISAID 0x8c4e
453
454 /*
455 * Important defines for the ISA class of ECP board.
456 */
457 #define ECP_ATIREG 0
458 #define ECP_ATCONFR 1
459 #define ECP_ATMEMAR 2
460 #define ECP_ATMEMPR 3
461 #define ECP_ATSTOP 0x1
462 #define ECP_ATINTENAB 0x10
463 #define ECP_ATENABLE 0x20
464 #define ECP_ATDISABLE 0x00
465 #define ECP_ATADDRMASK 0x3f000
466 #define ECP_ATADDRSHFT 12
467
468 /*
469 * Important defines for the EISA class of ECP board.
470 */
471 #define ECP_EIIREG 0
472 #define ECP_EIMEMARL 1
473 #define ECP_EICONFR 2
474 #define ECP_EIMEMARH 3
475 #define ECP_EIENABLE 0x1
476 #define ECP_EIDISABLE 0x0
477 #define ECP_EISTOP 0x4
478 #define ECP_EIEDGE 0x00
479 #define ECP_EILEVEL 0x80
480 #define ECP_EIADDRMASKL 0x00ff0000
481 #define ECP_EIADDRSHFTL 16
482 #define ECP_EIADDRMASKH 0xff000000
483 #define ECP_EIADDRSHFTH 24
484 #define ECP_EIBRDENAB 0xc84
485
486 #define ECP_EISAID 0x4
487
488 /*
489 * Important defines for the Micro-channel class of ECP board.
490 * (It has a lot in common with the ISA boards.)
491 */
492 #define ECP_MCIREG 0
493 #define ECP_MCCONFR 1
494 #define ECP_MCSTOP 0x20
495 #define ECP_MCENABLE 0x80
496 #define ECP_MCDISABLE 0x00
497
498 /*
499 * Important defines for the PCI class of ECP board.
500 * (It has a lot in common with the other ECP boards.)
501 */
502 #define ECP_PCIIREG 0
503 #define ECP_PCICONFR 1
504 #define ECP_PCISTOP 0x01
505
506 /*
507 * Hardware configuration info for ONboard and Brumby boards. These
508 * defines apply to the directly accessible io ports of these boards.
509 */
510 #define ONB_IOSIZE 16
511 #define ONB_MEMSIZE (64 * 1024)
512 #define ONB_ATPAGESIZE (64 * 1024)
513 #define ONB_MCPAGESIZE (64 * 1024)
514 #define ONB_EIMEMSIZE (128 * 1024)
515 #define ONB_EIPAGESIZE (64 * 1024)
516
517 /*
518 * Important defines for the ISA class of ONboard board.
519 */
520 #define ONB_ATIREG 0
521 #define ONB_ATMEMAR 1
522 #define ONB_ATCONFR 2
523 #define ONB_ATSTOP 0x4
524 #define ONB_ATENABLE 0x01
525 #define ONB_ATDISABLE 0x00
526 #define ONB_ATADDRMASK 0xff0000
527 #define ONB_ATADDRSHFT 16
528
529 #define ONB_MEMENABLO 0
530 #define ONB_MEMENABHI 0x02
531
532 /*
533 * Important defines for the EISA class of ONboard board.
534 */
535 #define ONB_EIIREG 0
536 #define ONB_EIMEMARL 1
537 #define ONB_EICONFR 2
538 #define ONB_EIMEMARH 3
539 #define ONB_EIENABLE 0x1
540 #define ONB_EIDISABLE 0x0
541 #define ONB_EISTOP 0x4
542 #define ONB_EIEDGE 0x00
543 #define ONB_EILEVEL 0x80
544 #define ONB_EIADDRMASKL 0x00ff0000
545 #define ONB_EIADDRSHFTL 16
546 #define ONB_EIADDRMASKH 0xff000000
547 #define ONB_EIADDRSHFTH 24
548 #define ONB_EIBRDENAB 0xc84
549
550 #define ONB_EISAID 0x1
551
552 /*
553 * Important defines for the Brumby boards. They are pretty simple,
554 * there is not much that is programmably configurable.
555 */
556 #define BBY_IOSIZE 16
557 #define BBY_MEMSIZE (64 * 1024)
558 #define BBY_PAGESIZE (16 * 1024)
559
560 #define BBY_ATIREG 0
561 #define BBY_ATCONFR 1
562 #define BBY_ATSTOP 0x4
563
564 /*
565 * Important defines for the Stallion boards. They are pretty simple,
566 * there is not much that is programmably configurable.
567 */
568 #define STAL_IOSIZE 16
569 #define STAL_MEMSIZE (64 * 1024)
570 #define STAL_PAGESIZE (64 * 1024)
571
572 /*
573 * Define the set of status register values for EasyConnection panels.
574 * The signature will return with the status value for each panel. From
575 * this we can determine what is attached to the board - before we have
576 * actually down loaded any code to it.
577 */
578 #define ECH_PNLSTATUS 2
579 #define ECH_PNL16PORT 0x20
580 #define ECH_PNLIDMASK 0x07
581 #define ECH_PNLXPID 0x40
582 #define ECH_PNLINTRPEND 0x80
583
584 /*
585 * Define some macros to do things to the board. Even those these boards
586 * are somewhat related there is often significantly different ways of
587 * doing some operation on it (like enable, paging, reset, etc). So each
588 * board class has a set of functions which do the commonly required
589 * operations. The macros below basically just call these functions,
590 * generally checking for a NULL function - which means that the board
591 * needs nothing done to it to achieve this operation!
592 */
593 #define EBRDINIT(brdp) \
594 if (brdp->init != NULL) \
595 (* brdp->init)(brdp)
596
597 #define EBRDENABLE(brdp) \
598 if (brdp->enable != NULL) \
599 (* brdp->enable)(brdp);
600
601 #define EBRDDISABLE(brdp) \
602 if (brdp->disable != NULL) \
603 (* brdp->disable)(brdp);
604
605 #define EBRDINTR(brdp) \
606 if (brdp->intr != NULL) \
607 (* brdp->intr)(brdp);
608
609 #define EBRDRESET(brdp) \
610 if (brdp->reset != NULL) \
611 (* brdp->reset)(brdp);
612
613 #define EBRDGETMEMPTR(brdp,offset) \
614 (* brdp->getmemptr)(brdp, offset, __LINE__)
615
616 /*
617 * Define the maximal baud rate, and the default baud base for ports.
618 */
619 #define STL_MAXBAUD 460800
620 #define STL_BAUDBASE 115200
621 #define STL_CLOSEDELAY (5 * HZ / 10)
622
623 /*****************************************************************************/
624
625 /*
626 * Define macros to extract a brd or port number from a minor number.
627 */
628 #define MINOR2BRD(min) (((min) & 0xc0) >> 6)
629 #define MINOR2PORT(min) ((min) & 0x3f)
630
631 /*
632 * Define a baud rate table that converts termios baud rate selector
633 * into the actual baud rate value. All baud rate calculations are based
634 * on the actual baud rate required.
635 */
636 static unsigned int stli_baudrates[] = {
637 0, 50, 75, 110, 134, 150, 200, 300, 600, 1200, 1800, 2400, 4800,
638 9600, 19200, 38400, 57600, 115200, 230400, 460800, 921600
639 };
640
641 /*****************************************************************************/
642
643 /*
644 * Define some handy local macros...
645 */
646 #undef MIN
647 #define MIN(a,b) (((a) <= (b)) ? (a) : (b))
648
649 #undef TOLOWER
650 #define TOLOWER(x) ((((x) >= 'A') && ((x) <= 'Z')) ? ((x) + 0x20) : (x))
651
652 /*****************************************************************************/
653
654 /*
655 * Prototype all functions in this driver!
656 */
657
658 #ifdef MODULE
659 int init_module(void);
660 void cleanup_module(void);
661 static void stli_argbrds(void);
662 static int stli_parsebrd(stlconf_t *confp, char **argp);
663
664 static unsigned long stli_atol(char *str);
665 #endif
666
667 int stli_init(void);
668 static int stli_open(struct tty_struct *tty, struct file *filp);
669 static void stli_close(struct tty_struct *tty, struct file *filp);
670 static int stli_write(struct tty_struct *tty, int from_user, const unsigned char *buf, int count);
671 static void stli_putchar(struct tty_struct *tty, unsigned char ch);
672 static void stli_flushchars(struct tty_struct *tty);
673 static int stli_writeroom(struct tty_struct *tty);
674 static int stli_charsinbuffer(struct tty_struct *tty);
675 static int stli_ioctl(struct tty_struct *tty, struct file *file, unsigned int cmd, unsigned long arg);
676 static void stli_settermios(struct tty_struct *tty, struct termios *old);
677 static void stli_throttle(struct tty_struct *tty);
678 static void stli_unthrottle(struct tty_struct *tty);
679 static void stli_stop(struct tty_struct *tty);
680 static void stli_start(struct tty_struct *tty);
681 static void stli_flushbuffer(struct tty_struct *tty);
682 static void stli_breakctl(struct tty_struct *tty, int state);
683 static void stli_waituntilsent(struct tty_struct *tty, int timeout);
684 static void stli_sendxchar(struct tty_struct *tty, char ch);
685 static void stli_hangup(struct tty_struct *tty);
686 static int stli_portinfo(stlibrd_t *brdp, stliport_t *portp, int portnr, char *pos);
687
688 static int stli_brdinit(stlibrd_t *brdp);
689 static int stli_startbrd(stlibrd_t *brdp);
690 static ssize_t stli_memread(struct file *fp, char *buf, size_t count, loff_t *offp);
691 static ssize_t stli_memwrite(struct file *fp, const char *buf, size_t count, loff_t *offp);
692 static int stli_memioctl(struct inode *ip, struct file *fp, unsigned int cmd, unsigned long arg);
693 static void stli_brdpoll(stlibrd_t *brdp, volatile cdkhdr_t *hdrp);
694 static void stli_poll(unsigned long arg);
695 static int stli_hostcmd(stlibrd_t *brdp, stliport_t *portp);
696 static int stli_initopen(stlibrd_t *brdp, stliport_t *portp);
697 static int stli_rawopen(stlibrd_t *brdp, stliport_t *portp, unsigned long arg, int wait);
698 static int stli_rawclose(stlibrd_t *brdp, stliport_t *portp, unsigned long arg, int wait);
699 static int stli_waitcarrier(stlibrd_t *brdp, stliport_t *portp, struct file *filp);
700 static void stli_dohangup(void *arg);
701 static void stli_delay(int len);
702 static int stli_setport(stliport_t *portp);
703 static int stli_cmdwait(stlibrd_t *brdp, stliport_t *portp, unsigned long cmd, void *arg, int size, int copyback);
704 static void stli_sendcmd(stlibrd_t *brdp, stliport_t *portp, unsigned long cmd, void *arg, int size, int copyback);
705 static void stli_dodelaycmd(stliport_t *portp, volatile cdkctrl_t *cp);
706 static void stli_mkasyport(stliport_t *portp, asyport_t *pp, struct termios *tiosp);
707 static void stli_mkasysigs(asysigs_t *sp, int dtr, int rts);
708 static long stli_mktiocm(unsigned long sigvalue);
709 static void stli_read(stlibrd_t *brdp, stliport_t *portp);
710 static void stli_getserial(stliport_t *portp, struct serial_struct *sp);
711 static int stli_setserial(stliport_t *portp, struct serial_struct *sp);
712 static int stli_getbrdstats(combrd_t *bp);
713 static int stli_getportstats(stliport_t *portp, comstats_t *cp);
714 static int stli_portcmdstats(stliport_t *portp);
715 static int stli_clrportstats(stliport_t *portp, comstats_t *cp);
716 static int stli_getportstruct(unsigned long arg);
717 static int stli_getbrdstruct(unsigned long arg);
718 static void *stli_memalloc(int len);
719 static stlibrd_t *stli_allocbrd(void);
720
721 static void stli_ecpinit(stlibrd_t *brdp);
722 static void stli_ecpenable(stlibrd_t *brdp);
723 static void stli_ecpdisable(stlibrd_t *brdp);
724 static char *stli_ecpgetmemptr(stlibrd_t *brdp, unsigned long offset, int line);
725 static void stli_ecpreset(stlibrd_t *brdp);
726 static void stli_ecpintr(stlibrd_t *brdp);
727 static void stli_ecpeiinit(stlibrd_t *brdp);
728 static void stli_ecpeienable(stlibrd_t *brdp);
729 static void stli_ecpeidisable(stlibrd_t *brdp);
730 static char *stli_ecpeigetmemptr(stlibrd_t *brdp, unsigned long offset, int line);
731 static void stli_ecpeireset(stlibrd_t *brdp);
732 static void stli_ecpmcenable(stlibrd_t *brdp);
733 static void stli_ecpmcdisable(stlibrd_t *brdp);
734 static char *stli_ecpmcgetmemptr(stlibrd_t *brdp, unsigned long offset, int line);
735 static void stli_ecpmcreset(stlibrd_t *brdp);
736 static void stli_ecppciinit(stlibrd_t *brdp);
737 static char *stli_ecppcigetmemptr(stlibrd_t *brdp, unsigned long offset, int line);
738 static void stli_ecppcireset(stlibrd_t *brdp);
739
740 static void stli_onbinit(stlibrd_t *brdp);
741 static void stli_onbenable(stlibrd_t *brdp);
742 static void stli_onbdisable(stlibrd_t *brdp);
743 static char *stli_onbgetmemptr(stlibrd_t *brdp, unsigned long offset, int line);
744 static void stli_onbreset(stlibrd_t *brdp);
745 static void stli_onbeinit(stlibrd_t *brdp);
746 static void stli_onbeenable(stlibrd_t *brdp);
747 static void stli_onbedisable(stlibrd_t *brdp);
748 static char *stli_onbegetmemptr(stlibrd_t *brdp, unsigned long offset, int line);
749 static void stli_onbereset(stlibrd_t *brdp);
750 static void stli_bbyinit(stlibrd_t *brdp);
751 static char *stli_bbygetmemptr(stlibrd_t *brdp, unsigned long offset, int line);
752 static void stli_bbyreset(stlibrd_t *brdp);
753 static void stli_stalinit(stlibrd_t *brdp);
754 static char *stli_stalgetmemptr(stlibrd_t *brdp, unsigned long offset, int line);
755 static void stli_stalreset(stlibrd_t *brdp);
756
757 static stliport_t *stli_getport(int brdnr, int panelnr, int portnr);
758
759 static inline int stli_initbrds(void);
760 static inline int stli_initecp(stlibrd_t *brdp);
761 static inline int stli_initonb(stlibrd_t *brdp);
762 static inline int stli_findeisabrds(void);
763 static inline int stli_eisamemprobe(stlibrd_t *brdp);
764 static inline int stli_initports(stlibrd_t *brdp);
765 static inline int stli_getbrdnr(void);
766
767 #ifdef CONFIG_PCI
768 static inline int stli_findpcibrds(void);
769 static inline int stli_initpcibrd(int brdtype, struct pci_dev *devp);
770 #endif
771
772 /*****************************************************************************/
773
774 /*
775 * Define the driver info for a user level shared memory device. This
776 * device will work sort of like the /dev/kmem device - except that it
777 * will give access to the shared memory on the Stallion intelligent
778 * board. This is also a very useful debugging tool.
779 */
780 static struct file_operations stli_fsiomem = {
781 owner: THIS_MODULE,
782 read: stli_memread,
783 write: stli_memwrite,
784 ioctl: stli_memioctl,
785 };
786
787 /*****************************************************************************/
788
789 /*
790 * Define a timer_list entry for our poll routine. The slave board
791 * is polled every so often to see if anything needs doing. This is
792 * much cheaper on host cpu than using interrupts. It turns out to
793 * not increase character latency by much either...
794 */
795 static struct timer_list stli_timerlist = {
796 function: stli_poll
797 };
798
799 static int stli_timeron;
800
801 /*
802 * Define the calculation for the timeout routine.
803 */
804 #define STLI_TIMEOUT (jiffies + 1)
805
806 /*****************************************************************************/
807
808 #ifdef MODULE
809
810 /*
811 * Loadable module initialization stuff.
812 */
813
814 int init_module()
815 {
816 unsigned long flags;
817
818 #if DEBUG
819 printk("init_module()\n");
820 #endif
821
822 save_flags(flags);
823 cli();
824 stli_init();
825 restore_flags(flags);
826
827 return(0);
828 }
829
830 /*****************************************************************************/
831
832 void cleanup_module()
833 {
834 stlibrd_t *brdp;
835 stliport_t *portp;
836 unsigned long flags;
837 int i, j;
838
839 #if DEBUG
840 printk("cleanup_module()\n");
841 #endif
842
843 printk(KERN_INFO "Unloading %s: version %s\n", stli_drvtitle,
844 stli_drvversion);
845
846 save_flags(flags);
847 cli();
848
849 /*
850 * Free up all allocated resources used by the ports. This includes
851 * memory and interrupts.
852 */
853 if (stli_timeron) {
854 stli_timeron = 0;
855 del_timer(&stli_timerlist);
856 }
857
858 i = tty_unregister_driver(&stli_serial);
859 j = tty_unregister_driver(&stli_callout);
860 if (i || j) {
861 printk("STALLION: failed to un-register tty driver, "
862 "errno=%d,%d\n", -i, -j);
863 restore_flags(flags);
864 return;
865 }
866 devfs_unregister (devfs_handle);
867 if ((i = devfs_unregister_chrdev(STL_SIOMEMMAJOR, "staliomem")))
868 printk("STALLION: failed to un-register serial memory device, "
869 "errno=%d\n", -i);
870 if (stli_tmpwritebuf != (char *) NULL)
871 kfree(stli_tmpwritebuf);
872 if (stli_txcookbuf != (char *) NULL)
873 kfree(stli_txcookbuf);
874
875 for (i = 0; (i < stli_nrbrds); i++) {
876 if ((brdp = stli_brds[i]) == (stlibrd_t *) NULL)
877 continue;
878 for (j = 0; (j < STL_MAXPORTS); j++) {
879 portp = brdp->ports[j];
880 if (portp != (stliport_t *) NULL) {
881 if (portp->tty != (struct tty_struct *) NULL)
882 tty_hangup(portp->tty);
883 kfree(portp);
884 }
885 }
886
887 iounmap(brdp->membase);
888 if (brdp->iosize > 0)
889 release_region(brdp->iobase, brdp->iosize);
890 kfree(brdp);
891 stli_brds[i] = (stlibrd_t *) NULL;
892 }
893
894 restore_flags(flags);
895 }
896
897 /*****************************************************************************/
898
899 /*
900 * Check for any arguments passed in on the module load command line.
901 */
902
903 static void stli_argbrds()
904 {
905 stlconf_t conf;
906 stlibrd_t *brdp;
907 int nrargs, i;
908
909 #if DEBUG
910 printk("stli_argbrds()\n");
911 #endif
912
913 nrargs = sizeof(stli_brdsp) / sizeof(char **);
914
915 for (i = stli_nrbrds; (i < nrargs); i++) {
916 memset(&conf, 0, sizeof(conf));
917 if (stli_parsebrd(&conf, stli_brdsp[i]) == 0)
918 continue;
919 if ((brdp = stli_allocbrd()) == (stlibrd_t *) NULL)
920 continue;
921 stli_nrbrds = i + 1;
922 brdp->brdnr = i;
923 brdp->brdtype = conf.brdtype;
924 brdp->iobase = conf.ioaddr1;
925 brdp->memaddr = conf.memaddr;
926 stli_brdinit(brdp);
927 }
928 }
929
930 /*****************************************************************************/
931
932 /*
933 * Convert an ascii string number into an unsigned long.
934 */
935
936 static unsigned long stli_atol(char *str)
937 {
938 unsigned long val;
939 int base, c;
940 char *sp;
941
942 val = 0;
943 sp = str;
944 if ((*sp == '') && (*(sp+1) == 'x')) {
945 base = 16;
946 sp += 2;
947 } else if (*sp == '') {
948 base = 8;
949 sp++;
950 } else {
951 base = 10;
952 }
953
954 for (; (*sp != 0); sp++) {
955 c = (*sp > '9') ? (TOLOWER(*sp) - 'a' + 10) : (*sp - '');
956 if ((c < 0) || (c >= base)) {
957 printk("STALLION: invalid argument %s\n", str);
958 val = 0;
959 break;
960 }
961 val = (val * base) + c;
962 }
963 return(val);
964 }
965
966 /*****************************************************************************/
967
968 /*
969 * Parse the supplied argument string, into the board conf struct.
970 */
971
972 static int stli_parsebrd(stlconf_t *confp, char **argp)
973 {
974 char *sp;
975 int nrbrdnames, i;
976
977 #if DEBUG
978 printk("stli_parsebrd(confp=%x,argp=%x)\n", (int) confp, (int) argp);
979 #endif
980
981 if ((argp[0] == (char *) NULL) || (*argp[0] == 0))
982 return(0);
983
984 for (sp = argp[0], i = 0; ((*sp != 0) && (i < 25)); sp++, i++)
985 *sp = TOLOWER(*sp);
986
987 nrbrdnames = sizeof(stli_brdstr) / sizeof(stlibrdtype_t);
988 for (i = 0; (i < nrbrdnames); i++) {
989 if (strcmp(stli_brdstr[i].name, argp[0]) == 0)
990 break;
991 }
992 if (i >= nrbrdnames) {
993 printk("STALLION: unknown board name, %s?\n", argp[0]);
994 return(0);
995 }
996
997 confp->brdtype = stli_brdstr[i].type;
998 if ((argp[1] != (char *) NULL) && (*argp[1] != 0))
999 confp->ioaddr1 = stli_atol(argp[1]);
1000 if ((argp[2] != (char *) NULL) && (*argp[2] != 0))
1001 confp->memaddr = stli_atol(argp[2]);
1002 return(1);
1003 }
1004
1005 #endif
1006
1007 /*****************************************************************************/
1008
1009 /*
1010 * Local driver kernel malloc routine.
1011 */
1012
1013 static void *stli_memalloc(int len)
1014 {
1015 return((void *) kmalloc(len, GFP_KERNEL));
1016 }
1017
1018 /*****************************************************************************/
1019
1020 static int stli_open(struct tty_struct *tty, struct file *filp)
1021 {
1022 stlibrd_t *brdp;
1023 stliport_t *portp;
1024 unsigned int minordev;
1025 int brdnr, portnr, rc;
1026
1027 #if DEBUG
1028 printk("stli_open(tty=%x,filp=%x): device=%x\n", (int) tty,
1029 (int) filp, tty->device);
1030 #endif
1031
1032 minordev = MINOR(tty->device);
1033 brdnr = MINOR2BRD(minordev);
1034 if (brdnr >= stli_nrbrds)
1035 return(-ENODEV);
1036 brdp = stli_brds[brdnr];
1037 if (brdp == (stlibrd_t *) NULL)
1038 return(-ENODEV);
1039 if ((brdp->state & BST_STARTED) == 0)
1040 return(-ENODEV);
1041 portnr = MINOR2PORT(minordev);
1042 if ((portnr < 0) || (portnr > brdp->nrports))
1043 return(-ENODEV);
1044
1045 portp = brdp->ports[portnr];
1046 if (portp == (stliport_t *) NULL)
1047 return(-ENODEV);
1048 if (portp->devnr < 1)
1049 return(-ENODEV);
1050
1051 MOD_INC_USE_COUNT;
1052
1053 /*
1054 * Check if this port is in the middle of closing. If so then wait
1055 * until it is closed then return error status based on flag settings.
1056 * The sleep here does not need interrupt protection since the wakeup
1057 * for it is done with the same context.
1058 */
1059 if (portp->flags & ASYNC_CLOSING) {
1060 interruptible_sleep_on(&portp->close_wait);
1061 if (portp->flags & ASYNC_HUP_NOTIFY)
1062 return(-EAGAIN);
1063 return(-ERESTARTSYS);
1064 }
1065
1066 /*
1067 * On the first open of the device setup the port hardware, and
1068 * initialize the per port data structure. Since initializing the port
1069 * requires several commands to the board we will need to wait for any
1070 * other open that is already initializing the port.
1071 */
1072 portp->tty = tty;
1073 tty->driver_data = portp;
1074 portp->refcount++;
1075
1076 while (test_bit(ST_INITIALIZING, &portp->state)) {
1077 if (signal_pending(current))
1078 return(-ERESTARTSYS);
1079 interruptible_sleep_on(&portp->raw_wait);
1080 }
1081
1082 if ((portp->flags & ASYNC_INITIALIZED) == 0) {
1083 set_bit(ST_INITIALIZING, &portp->state);
1084 if ((rc = stli_initopen(brdp, portp)) >= 0) {
1085 portp->flags |= ASYNC_INITIALIZED;
1086 clear_bit(TTY_IO_ERROR, &tty->flags);
1087 }
1088 clear_bit(ST_INITIALIZING, &portp->state);
1089 wake_up_interruptible(&portp->raw_wait);
1090 if (rc < 0)
1091 return(rc);
1092 }
1093
1094 /*
1095 * Check if this port is in the middle of closing. If so then wait
1096 * until it is closed then return error status, based on flag settings.
1097 * The sleep here does not need interrupt protection since the wakeup
1098 * for it is done with the same context.
1099 */
1100 if (portp->flags & ASYNC_CLOSING) {
1101 interruptible_sleep_on(&portp->close_wait);
1102 if (portp->flags & ASYNC_HUP_NOTIFY)
1103 return(-EAGAIN);
1104 return(-ERESTARTSYS);
1105 }
1106
1107 /*
1108 * Based on type of open being done check if it can overlap with any
1109 * previous opens still in effect. If we are a normal serial device
1110 * then also we might have to wait for carrier.
1111 */
1112 if (tty->driver.subtype == STL_DRVTYPCALLOUT) {
1113 if (portp->flags & ASYNC_NORMAL_ACTIVE)
1114 return(-EBUSY);
1115 if (portp->flags & ASYNC_CALLOUT_ACTIVE) {
1116 if ((portp->flags & ASYNC_SESSION_LOCKOUT) &&
1117 (portp->session != current->session))
1118 return(-EBUSY);
1119 if ((portp->flags & ASYNC_PGRP_LOCKOUT) &&
1120 (portp->pgrp != current->pgrp))
1121 return(-EBUSY);
1122 }
1123 portp->flags |= ASYNC_CALLOUT_ACTIVE;
1124 } else {
1125 if (filp->f_flags & O_NONBLOCK) {
1126 if (portp->flags & ASYNC_CALLOUT_ACTIVE)
1127 return(-EBUSY);
1128 } else {
1129 if ((rc = stli_waitcarrier(brdp, portp, filp)) != 0)
1130 return(rc);
1131 }
1132 portp->flags |= ASYNC_NORMAL_ACTIVE;
1133 }
1134
1135 if ((portp->refcount == 1) && (portp->flags & ASYNC_SPLIT_TERMIOS)) {
1136 if (tty->driver.subtype == STL_DRVTYPSERIAL)
1137 *tty->termios = portp->normaltermios;
1138 else
1139 *tty->termios = portp->callouttermios;
1140 stli_setport(portp);
1141 }
1142
1143 portp->session = current->session;
1144 portp->pgrp = current->pgrp;
1145 return(0);
1146 }
1147
1148 /*****************************************************************************/
1149
1150 static void stli_close(struct tty_struct *tty, struct file *filp)
1151 {
1152 stlibrd_t *brdp;
1153 stliport_t *portp;
1154 unsigned long flags;
1155
1156 #if DEBUG
1157 printk("stli_close(tty=%x,filp=%x)\n", (int) tty, (int) filp);
1158 #endif
1159
1160 portp = tty->driver_data;
1161 if (portp == (stliport_t *) NULL)
1162 return;
1163
1164 save_flags(flags);
1165 cli();
1166 if (tty_hung_up_p(filp)) {
1167 MOD_DEC_USE_COUNT;
1168 restore_flags(flags);
1169 return;
1170 }
1171 if ((tty->count == 1) && (portp->refcount != 1))
1172 portp->refcount = 1;
1173 if (portp->refcount-- > 1) {
1174 MOD_DEC_USE_COUNT;
1175 restore_flags(flags);
1176 return;
1177 }
1178
1179 portp->flags |= ASYNC_CLOSING;
1180
1181 if (portp->flags & ASYNC_NORMAL_ACTIVE)
1182 portp->normaltermios = *tty->termios;
1183 if (portp->flags & ASYNC_CALLOUT_ACTIVE)
1184 portp->callouttermios = *tty->termios;
1185
1186 /*
1187 * May want to wait for data to drain before closing. The BUSY flag
1188 * keeps track of whether we are still transmitting or not. It is
1189 * updated by messages from the slave - indicating when all chars
1190 * really have drained.
1191 */
1192 if (tty == stli_txcooktty)
1193 stli_flushchars(tty);
1194 tty->closing = 1;
1195 if (portp->closing_wait != ASYNC_CLOSING_WAIT_NONE)
1196 tty_wait_until_sent(tty, portp->closing_wait);
1197
1198 portp->flags &= ~ASYNC_INITIALIZED;
1199 brdp = stli_brds[portp->brdnr];
1200 stli_rawclose(brdp, portp, 0, 0);
1201 if (tty->termios->c_cflag & HUPCL) {
1202 stli_mkasysigs(&portp->asig, 0, 0);
1203 if (test_bit(ST_CMDING, &portp->state))
1204 set_bit(ST_DOSIGS, &portp->state);
1205 else
1206 stli_sendcmd(brdp, portp, A_SETSIGNALS, &portp->asig,
1207 sizeof(asysigs_t), 0);
1208 }
1209 clear_bit(ST_TXBUSY, &portp->state);
1210 clear_bit(ST_RXSTOP, &portp->state);
1211 set_bit(TTY_IO_ERROR, &tty->flags);
1212 if (tty->ldisc.flush_buffer)
1213 (tty->ldisc.flush_buffer)(tty);
1214 set_bit(ST_DOFLUSHRX, &portp->state);
1215 stli_flushbuffer(tty);
1216
1217 tty->closing = 0;
1218 portp->tty = (struct tty_struct *) NULL;
1219
1220 if (portp->openwaitcnt) {
1221 if (portp->close_delay)
1222 stli_delay(portp->close_delay);
1223 wake_up_interruptible(&portp->open_wait);
1224 }
1225
1226 portp->flags &= ~(ASYNC_CALLOUT_ACTIVE | ASYNC_NORMAL_ACTIVE |
1227 ASYNC_CLOSING);
1228 wake_up_interruptible(&portp->close_wait);
1229 MOD_DEC_USE_COUNT;
1230 restore_flags(flags);
1231 }
1232
1233 /*****************************************************************************/
1234
1235 /*
1236 * Carry out first open operations on a port. This involves a number of
1237 * commands to be sent to the slave. We need to open the port, set the
1238 * notification events, set the initial port settings, get and set the
1239 * initial signal values. We sleep and wait in between each one. But
1240 * this still all happens pretty quickly.
1241 */
1242
1243 static int stli_initopen(stlibrd_t *brdp, stliport_t *portp)
1244 {
1245 struct tty_struct *tty;
1246 asynotify_t nt;
1247 asyport_t aport;
1248 int rc;
1249
1250 #if DEBUG
1251 printk("stli_initopen(brdp=%x,portp=%x)\n", (int) brdp, (int) portp);
1252 #endif
1253
1254 if ((rc = stli_rawopen(brdp, portp, 0, 1)) < 0)
1255 return(rc);
1256
1257 memset(&nt, 0, sizeof(asynotify_t));
1258 nt.data = (DT_TXLOW | DT_TXEMPTY | DT_RXBUSY | DT_RXBREAK);
1259 nt.signal = SG_DCD;
1260 if ((rc = stli_cmdwait(brdp, portp, A_SETNOTIFY, &nt,
1261 sizeof(asynotify_t), 0)) < 0)
1262 return(rc);
1263
1264 tty = portp->tty;
1265 if (tty == (struct tty_struct *) NULL)
1266 return(-ENODEV);
1267 stli_mkasyport(portp, &aport, tty->termios);
1268 if ((rc = stli_cmdwait(brdp, portp, A_SETPORT, &aport,
1269 sizeof(asyport_t), 0)) < 0)
1270 return(rc);
1271
1272 set_bit(ST_GETSIGS, &portp->state);
1273 if ((rc = stli_cmdwait(brdp, portp, A_GETSIGNALS, &portp->asig,
1274 sizeof(asysigs_t), 1)) < 0)
1275 return(rc);
1276 if (test_and_clear_bit(ST_GETSIGS, &portp->state))
1277 portp->sigs = stli_mktiocm(portp->asig.sigvalue);
1278 stli_mkasysigs(&portp->asig, 1, 1);
1279 if ((rc = stli_cmdwait(brdp, portp, A_SETSIGNALS, &portp->asig,
1280 sizeof(asysigs_t), 0)) < 0)
1281 return(rc);
1282
1283 return(0);
1284 }
1285
1286 /*****************************************************************************/
1287
1288 /*
1289 * Send an open message to the slave. This will sleep waiting for the
1290 * acknowledgement, so must have user context. We need to co-ordinate
1291 * with close events here, since we don't want open and close events
1292 * to overlap.
1293 */
1294
1295 static int stli_rawopen(stlibrd_t *brdp, stliport_t *portp, unsigned long arg, int wait)
1296 {
1297 volatile cdkhdr_t *hdrp;
1298 volatile cdkctrl_t *cp;
1299 volatile unsigned char *bits;
1300 unsigned long flags;
1301 int rc;
1302
1303 #if DEBUG
1304 printk("stli_rawopen(brdp=%x,portp=%x,arg=%x,wait=%d)\n",
1305 (int) brdp, (int) portp, (int) arg, wait);
1306 #endif
1307
1308 /*
1309 * Send a message to the slave to open this port.
1310 */
1311 save_flags(flags);
1312 cli();
1313
1314 /*
1315 * Slave is already closing this port. This can happen if a hangup
1316 * occurs on this port. So we must wait until it is complete. The
1317 * order of opens and closes may not be preserved across shared
1318 * memory, so we must wait until it is complete.
1319 */
1320 while (test_bit(ST_CLOSING, &portp->state)) {
1321 if (signal_pending(current)) {
1322 restore_flags(flags);
1323 return(-ERESTARTSYS);
1324 }
1325 interruptible_sleep_on(&portp->raw_wait);
1326 }
1327
1328 /*
1329 * Everything is ready now, so write the open message into shared
1330 * memory. Once the message is in set the service bits to say that
1331 * this port wants service.
1332 */
1333 EBRDENABLE(brdp);
1334 cp = &((volatile cdkasy_t *) EBRDGETMEMPTR(brdp, portp->addr))->ctrl;
1335 cp->openarg = arg;
1336 cp->open = 1;
1337 hdrp = (volatile cdkhdr_t *) EBRDGETMEMPTR(brdp, CDK_CDKADDR);
1338 bits = ((volatile unsigned char *) hdrp) + brdp->slaveoffset +
1339 portp->portidx;
1340 *bits |= portp->portbit;
1341 EBRDDISABLE(brdp);
1342
1343 if (wait == 0) {
1344 restore_flags(flags);
1345 return(0);
1346 }
1347
1348 /*
1349 * Slave is in action, so now we must wait for the open acknowledgment
1350 * to come back.
1351 */
1352 rc = 0;
1353 set_bit(ST_OPENING, &portp->state);
1354 while (test_bit(ST_OPENING, &portp->state)) {
1355 if (signal_pending(current)) {
1356 rc = -ERESTARTSYS;
1357 break;
1358 }
1359 interruptible_sleep_on(&portp->raw_wait);
1360 }
1361 restore_flags(flags);
1362
1363 if ((rc == 0) && (portp->rc != 0))
1364 rc = -EIO;
1365 return(rc);
1366 }
1367
1368 /*****************************************************************************/
1369
1370 /*
1371 * Send a close message to the slave. Normally this will sleep waiting
1372 * for the acknowledgement, but if wait parameter is 0 it will not. If
1373 * wait is true then must have user context (to sleep).
1374 */
1375
1376 static int stli_rawclose(stlibrd_t *brdp, stliport_t *portp, unsigned long arg, int wait)
1377 {
1378 volatile cdkhdr_t *hdrp;
1379 volatile cdkctrl_t *cp;
1380 volatile unsigned char *bits;
1381 unsigned long flags;
1382 int rc;
1383
1384 #if DEBUG
1385 printk("stli_rawclose(brdp=%x,portp=%x,arg=%x,wait=%d)\n",
1386 (int) brdp, (int) portp, (int) arg, wait);
1387 #endif
1388
1389 save_flags(flags);
1390 cli();
1391
1392 /*
1393 * Slave is already closing this port. This can happen if a hangup
1394 * occurs on this port.
1395 */
1396 if (wait) {
1397 while (test_bit(ST_CLOSING, &portp->state)) {
1398 if (signal_pending(current)) {
1399 restore_flags(flags);
1400 return(-ERESTARTSYS);
1401 }
1402 interruptible_sleep_on(&portp->raw_wait);
1403 }
1404 }
1405
1406 /*
1407 * Write the close command into shared memory.
1408 */
1409 EBRDENABLE(brdp);
1410 cp = &((volatile cdkasy_t *) EBRDGETMEMPTR(brdp, portp->addr))->ctrl;
1411 cp->closearg = arg;
1412 cp->close = 1;
1413 hdrp = (volatile cdkhdr_t *) EBRDGETMEMPTR(brdp, CDK_CDKADDR);
1414 bits = ((volatile unsigned char *) hdrp) + brdp->slaveoffset +
1415 portp->portidx;
1416 *bits |= portp->portbit;
1417 EBRDDISABLE(brdp);
1418
1419 set_bit(ST_CLOSING, &portp->state);
1420 if (wait == 0) {
1421 restore_flags(flags);
1422 return(0);
1423 }
1424
1425 /*
1426 * Slave is in action, so now we must wait for the open acknowledgment
1427 * to come back.
1428 */
1429 rc = 0;
1430 while (test_bit(ST_CLOSING, &portp->state)) {
1431 if (signal_pending(current)) {
1432 rc = -ERESTARTSYS;
1433 break;
1434 }
1435 interruptible_sleep_on(&portp->raw_wait);
1436 }
1437 restore_flags(flags);
1438
1439 if ((rc == 0) && (portp->rc != 0))
1440 rc = -EIO;
1441 return(rc);
1442 }
1443
1444 /*****************************************************************************/
1445
1446 /*
1447 * Send a command to the slave and wait for the response. This must
1448 * have user context (it sleeps). This routine is generic in that it
1449 * can send any type of command. Its purpose is to wait for that command
1450 * to complete (as opposed to initiating the command then returning).
1451 */
1452
1453 static int stli_cmdwait(stlibrd_t *brdp, stliport_t *portp, unsigned long cmd, void *arg, int size, int copyback)
1454 {
1455 unsigned long flags;
1456
1457 #if DEBUG
1458 printk("stli_cmdwait(brdp=%x,portp=%x,cmd=%x,arg=%x,size=%d,"
1459 "copyback=%d)\n", (int) brdp, (int) portp, (int) cmd,
1460 (int) arg, size, copyback);
1461 #endif
1462
1463 save_flags(flags);
1464 cli();
1465 while (test_bit(ST_CMDING, &portp->state)) {
1466 if (signal_pending(current)) {
1467 restore_flags(flags);
1468 return(-ERESTARTSYS);
1469 }
1470 interruptible_sleep_on(&portp->raw_wait);
1471 }
1472
1473 stli_sendcmd(brdp, portp, cmd, arg, size, copyback);
1474
1475 while (test_bit(ST_CMDING, &portp->state)) {
1476 if (signal_pending(current)) {
1477 restore_flags(flags);
1478 return(-ERESTARTSYS);
1479 }
1480 interruptible_sleep_on(&portp->raw_wait);
1481 }
1482 restore_flags(flags);
1483
1484 if (portp->rc != 0)
1485 return(-EIO);
1486 return(0);
1487 }
1488
1489 /*****************************************************************************/
1490
1491 /*
1492 * Send the termios settings for this port to the slave. This sleeps
1493 * waiting for the command to complete - so must have user context.
1494 */
1495
1496 static int stli_setport(stliport_t *portp)
1497 {
1498 stlibrd_t *brdp;
1499 asyport_t aport;
1500
1501 #if DEBUG
1502 printk("stli_setport(portp=%x)\n", (int) portp);
1503 #endif
1504
1505 if (portp == (stliport_t *) NULL)
1506 return(-ENODEV);
1507 if (portp->tty == (struct tty_struct *) NULL)
1508 return(-ENODEV);
1509 if ((portp->brdnr < 0) && (portp->brdnr >= stli_nrbrds))
1510 return(-ENODEV);
1511 brdp = stli_brds[portp->brdnr];
1512 if (brdp == (stlibrd_t *) NULL)
1513 return(-ENODEV);
1514
1515 stli_mkasyport(portp, &aport, portp->tty->termios);
1516 return(stli_cmdwait(brdp, portp, A_SETPORT, &aport, sizeof(asyport_t), 0));
1517 }
1518
1519 /*****************************************************************************/
1520
1521 /*
1522 * Wait for a specified delay period, this is not a busy-loop. It will
1523 * give up the processor while waiting. Unfortunately this has some
1524 * rather intimate knowledge of the process management stuff.
1525 */
1526
1527 static void stli_delay(int len)
1528 {
1529 #if DEBUG
1530 printk("stli_delay(len=%d)\n", len);
1531 #endif
1532 if (len > 0) {
1533 current->state = TASK_INTERRUPTIBLE;
1534 schedule_timeout(len);
1535 current->state = TASK_RUNNING;
1536 }
1537 }
1538
1539 /*****************************************************************************/
1540
1541 /*
1542 * Possibly need to wait for carrier (DCD signal) to come high. Say
1543 * maybe because if we are clocal then we don't need to wait...
1544 */
1545
1546 static int stli_waitcarrier(stlibrd_t *brdp, stliport_t *portp, struct file *filp)
1547 {
1548 unsigned long flags;
1549 int rc, doclocal;
1550
1551 #if DEBUG
1552 printk("stli_waitcarrier(brdp=%x,portp=%x,filp=%x)\n",
1553 (int) brdp, (int) portp, (int) filp);
1554 #endif
1555
1556 rc = 0;
1557 doclocal = 0;
1558
1559 if (portp->flags & ASYNC_CALLOUT_ACTIVE) {
1560 if (portp->normaltermios.c_cflag & CLOCAL)
1561 doclocal++;
1562 } else {
1563 if (portp->tty->termios->c_cflag & CLOCAL)
1564 doclocal++;
1565 }
1566
1567 save_flags(flags);
1568 cli();
1569 portp->openwaitcnt++;
1570 if (! tty_hung_up_p(filp))
1571 portp->refcount--;
1572
1573 for (;;) {
1574 if ((portp->flags & ASYNC_CALLOUT_ACTIVE) == 0) {
1575 stli_mkasysigs(&portp->asig, 1, 1);
1576 if ((rc = stli_cmdwait(brdp, portp, A_SETSIGNALS,
1577 &portp->asig, sizeof(asysigs_t), 0)) < 0)
1578 break;
1579 }
1580 if (tty_hung_up_p(filp) ||
1581 ((portp->flags & ASYNC_INITIALIZED) == 0)) {
1582 if (portp->flags & ASYNC_HUP_NOTIFY)
1583 rc = -EBUSY;
1584 else
1585 rc = -ERESTARTSYS;
1586 break;
1587 }
1588 if (((portp->flags & ASYNC_CALLOUT_ACTIVE) == 0) &&
1589 ((portp->flags & ASYNC_CLOSING) == 0) &&
1590 (doclocal || (portp->sigs & TIOCM_CD))) {
1591 break;
1592 }
1593 if (signal_pending(current)) {
1594 rc = -ERESTARTSYS;
1595 break;
1596 }
1597 interruptible_sleep_on(&portp->open_wait);
1598 }
1599
1600 if (! tty_hung_up_p(filp))
1601 portp->refcount++;
1602 portp->openwaitcnt--;
1603 restore_flags(flags);
1604
1605 return(rc);
1606 }
1607
1608 /*****************************************************************************/
1609
1610 /*
1611 * Write routine. Take the data and put it in the shared memory ring
1612 * queue. If port is not already sending chars then need to mark the
1613 * service bits for this port.
1614 */
1615
1616 static int stli_write(struct tty_struct *tty, int from_user, const unsigned char *buf, int count)
1617 {
1618 volatile cdkasy_t *ap;
1619 volatile cdkhdr_t *hdrp;
1620 volatile unsigned char *bits;
1621 unsigned char *shbuf, *chbuf;
1622 stliport_t *portp;
1623 stlibrd_t *brdp;
1624 unsigned int len, stlen, head, tail, size;
1625 unsigned long flags;
1626
1627 #if DEBUG
1628 printk("stli_write(tty=%x,from_user=%d,buf=%x,count=%d)\n",
1629 (int) tty, from_user, (int) buf, count);
1630 #endif
1631
1632 if ((tty == (struct tty_struct *) NULL) ||
1633 (stli_tmpwritebuf == (char *) NULL))
1634 return(0);
1635 if (tty == stli_txcooktty)
1636 stli_flushchars(tty);
1637 portp = tty->driver_data;
1638 if (portp == (stliport_t *) NULL)
1639 return(0);
1640 if ((portp->brdnr < 0) || (portp->brdnr >= stli_nrbrds))
1641 return(0);
1642 brdp = stli_brds[portp->brdnr];
1643 if (brdp == (stlibrd_t *) NULL)
1644 return(0);
1645 chbuf = (unsigned char *) buf;
1646
1647 /*
1648 * If copying direct from user space we need to be able to handle page
1649 * faults while we are copying. To do this copy as much as we can now
1650 * into a kernel buffer. From there we copy it into shared memory. The
1651 * big problem is that we do not want shared memory enabled when we are
1652 * sleeping (other boards may be serviced while asleep). Something else
1653 * to note here is the reading of the tail twice. Since the boards
1654 * shared memory can be on an 8-bit bus then we need to be very careful
1655 * reading 16 bit quantities - since both the board (slave) and host
1656 * could be writing and reading at the same time.
1657 */
1658 if (from_user) {
1659 save_flags(flags);
1660 cli();
1661 EBRDENABLE(brdp);
1662 ap = (volatile cdkasy_t *) EBRDGETMEMPTR(brdp, portp->addr);
1663 head = (unsigned int) ap->txq.head;
1664 tail = (unsigned int) ap->txq.tail;
1665 if (tail != ((unsigned int) ap->txq.tail))
1666 tail = (unsigned int) ap->txq.tail;
1667 len = (head >= tail) ? (portp->txsize - (head - tail) - 1) :
1668 (tail - head - 1);
1669 count = MIN(len, count);
1670 EBRDDISABLE(brdp);
1671 restore_flags(flags);
1672
1673 down(&stli_tmpwritesem);
1674 copy_from_user(stli_tmpwritebuf, chbuf, count);
1675 chbuf = &stli_tmpwritebuf[0];
1676 }
1677
1678 /*
1679 * All data is now local, shove as much as possible into shared memory.
1680 */
1681 save_flags(flags);
1682 cli();
1683 EBRDENABLE(brdp);
1684 ap = (volatile cdkasy_t *) EBRDGETMEMPTR(brdp, portp->addr);
1685 head = (unsigned int) ap->txq.head;
1686 tail = (unsigned int) ap->txq.tail;
1687 if (tail != ((unsigned int) ap->txq.tail))
1688 tail = (unsigned int) ap->txq.tail;
1689 size = portp->txsize;
1690 if (head >= tail) {
1691 len = size - (head - tail) - 1;
1692 stlen = size - head;
1693 } else {
1694 len = tail - head - 1;
1695 stlen = len;
1696 }
1697
1698 len = MIN(len, count);
1699 count = 0;
1700 shbuf = (char *) EBRDGETMEMPTR(brdp, portp->txoffset);
1701
1702 while (len > 0) {
1703 stlen = MIN(len, stlen);
1704 memcpy((shbuf + head), chbuf, stlen);
1705 chbuf += stlen;
1706 len -= stlen;
1707 count += stlen;
1708 head += stlen;
1709 if (head >= size) {
1710 head = 0;
1711 stlen = tail;
1712 }
1713 }
1714
1715 ap = (volatile cdkasy_t *) EBRDGETMEMPTR(brdp, portp->addr);
1716 ap->txq.head = head;
1717 if (test_bit(ST_TXBUSY, &portp->state)) {
1718 if (ap->changed.data & DT_TXEMPTY)
1719 ap->changed.data &= ~DT_TXEMPTY;
1720 }
1721 hdrp = (volatile cdkhdr_t *) EBRDGETMEMPTR(brdp, CDK_CDKADDR);
1722 bits = ((volatile unsigned char *) hdrp) + brdp->slaveoffset +
1723 portp->portidx;
1724 *bits |= portp->portbit;
1725 set_bit(ST_TXBUSY, &portp->state);
1726 EBRDDISABLE(brdp);
1727
1728 if (from_user)
1729 up(&stli_tmpwritesem);
1730 restore_flags(flags);
1731
1732 return(count);
1733 }
1734
1735 /*****************************************************************************/
1736
1737 /*
1738 * Output a single character. We put it into a temporary local buffer
1739 * (for speed) then write out that buffer when the flushchars routine
1740 * is called. There is a safety catch here so that if some other port
1741 * writes chars before the current buffer has been, then we write them
1742 * first them do the new ports.
1743 */
1744
1745 static void stli_putchar(struct tty_struct *tty, unsigned char ch)
1746 {
1747 #if DEBUG
1748 printk("stli_putchar(tty=%x,ch=%x)\n", (int) tty, (int) ch);
1749 #endif
1750
1751 if (tty == (struct tty_struct *) NULL)
1752 return;
1753 if (tty != stli_txcooktty) {
1754 if (stli_txcooktty != (struct tty_struct *) NULL)
1755 stli_flushchars(stli_txcooktty);
1756 stli_txcooktty = tty;
1757 }
1758
1759 stli_txcookbuf[stli_txcooksize++] = ch;
1760 }
1761
1762 /*****************************************************************************/
1763
1764 /*
1765 * Transfer characters from the local TX cooking buffer to the board.
1766 * We sort of ignore the tty that gets passed in here. We rely on the
1767 * info stored with the TX cook buffer to tell us which port to flush
1768 * the data on. In any case we clean out the TX cook buffer, for re-use
1769 * by someone else.
1770 */
1771
1772 static void stli_flushchars(struct tty_struct *tty)
1773 {
1774 volatile cdkhdr_t *hdrp;
1775 volatile unsigned char *bits;
1776 volatile cdkasy_t *ap;
1777 struct tty_struct *cooktty;
1778 stliport_t *portp;
1779 stlibrd_t *brdp;
1780 unsigned int len, stlen, head, tail, size, count, cooksize;
1781 unsigned char *buf, *shbuf;
1782 unsigned long flags;
1783
1784 #if DEBUG
1785 printk("stli_flushchars(tty=%x)\n", (int) tty);
1786 #endif
1787
1788 cooksize = stli_txcooksize;
1789 cooktty = stli_txcooktty;
1790 stli_txcooksize = 0;
1791 stli_txcookrealsize = 0;
1792 stli_txcooktty = (struct tty_struct *) NULL;
1793
1794 if (tty == (struct tty_struct *) NULL)
1795 return;
1796 if (cooktty == (struct tty_struct *) NULL)
1797 return;
1798 if (tty != cooktty)
1799 tty = cooktty;
1800 if (cooksize == 0)
1801 return;
1802
1803 portp = tty->driver_data;
1804 if (portp == (stliport_t *) NULL)
1805 return;
1806 if ((portp->brdnr < 0) || (portp->brdnr >= stli_nrbrds))
1807 return;
1808 brdp = stli_brds[portp->brdnr];
1809 if (brdp == (stlibrd_t *) NULL)
1810 return;
1811
1812 save_flags(flags);
1813 cli();
1814 EBRDENABLE(brdp);
1815
1816 ap = (volatile cdkasy_t *) EBRDGETMEMPTR(brdp, portp->addr);
1817 head = (unsigned int) ap->txq.head;
1818 tail = (unsigned int) ap->txq.tail;
1819 if (tail != ((unsigned int) ap->txq.tail))
1820 tail = (unsigned int) ap->txq.tail;
1821 size = portp->txsize;
1822 if (head >= tail) {
1823 len = size - (head - tail) - 1;
1824 stlen = size - head;
1825 } else {
1826 len = tail - head - 1;
1827 stlen = len;
1828 }
1829
1830 len = MIN(len, cooksize);
1831 count = 0;
1832 shbuf = (char *) EBRDGETMEMPTR(brdp, portp->txoffset);
1833 buf = stli_txcookbuf;
1834
1835 while (len > 0) {
1836 stlen = MIN(len, stlen);
1837 memcpy((shbuf + head), buf, stlen);
1838 buf += stlen;
1839 len -= stlen;
1840 count += stlen;
1841 head += stlen;
1842 if (head >= size) {
1843 head = 0;
1844 stlen = tail;
1845 }
1846 }
1847
1848 ap = (volatile cdkasy_t *) EBRDGETMEMPTR(brdp, portp->addr);
1849 ap->txq.head = head;
1850
1851 if (test_bit(ST_TXBUSY, &portp->state)) {
1852 if (ap->changed.data & DT_TXEMPTY)
1853 ap->changed.data &= ~DT_TXEMPTY;
1854 }
1855 hdrp = (volatile cdkhdr_t *) EBRDGETMEMPTR(brdp, CDK_CDKADDR);
1856 bits = ((volatile unsigned char *) hdrp) + brdp->slaveoffset +
1857 portp->portidx;
1858 *bits |= portp->portbit;
1859 set_bit(ST_TXBUSY, &portp->state);
1860
1861 EBRDDISABLE(brdp);
1862 restore_flags(flags);
1863 }
1864
1865 /*****************************************************************************/
1866
1867 static int stli_writeroom(struct tty_struct *tty)
1868 {
1869 volatile cdkasyrq_t *rp;
1870 stliport_t *portp;
1871 stlibrd_t *brdp;
1872 unsigned int head, tail, len;
1873 unsigned long flags;
1874
1875 #if DEBUG
1876 printk("stli_writeroom(tty=%x)\n", (int) tty);
1877 #endif
1878
1879 if (tty == (struct tty_struct *) NULL)
1880 return(0);
1881 if (tty == stli_txcooktty) {
1882 if (stli_txcookrealsize != 0) {
1883 len = stli_txcookrealsize - stli_txcooksize;
1884 return(len);
1885 }
1886 }
1887
1888 portp = tty->driver_data;
1889 if (portp == (stliport_t *) NULL)
1890 return(0);
1891 if ((portp->brdnr < 0) || (portp->brdnr >= stli_nrbrds))
1892 return(0);
1893 brdp = stli_brds[portp->brdnr];
1894 if (brdp == (stlibrd_t *) NULL)
1895 return(0);
1896
1897 save_flags(flags);
1898 cli();
1899 EBRDENABLE(brdp);
1900 rp = &((volatile cdkasy_t *) EBRDGETMEMPTR(brdp, portp->addr))->txq;
1901 head = (unsigned int) rp->head;
1902 tail = (unsigned int) rp->tail;
1903 if (tail != ((unsigned int) rp->tail))
1904 tail = (unsigned int) rp->tail;
1905 len = (head >= tail) ? (portp->txsize - (head - tail)) : (tail - head);
1906 len--;
1907 EBRDDISABLE(brdp);
1908 restore_flags(flags);
1909
1910 if (tty == stli_txcooktty) {
1911 stli_txcookrealsize = len;
1912 len -= stli_txcooksize;
1913 }
1914 return(len);
1915 }
1916
1917 /*****************************************************************************/
1918
1919 /*
1920 * Return the number of characters in the transmit buffer. Normally we
1921 * will return the number of chars in the shared memory ring queue.
1922 * We need to kludge around the case where the shared memory buffer is
1923 * empty but not all characters have drained yet, for this case just
1924 * return that there is 1 character in the buffer!
1925 */
1926
1927 static int stli_charsinbuffer(struct tty_struct *tty)
1928 {
1929 volatile cdkasyrq_t *rp;
1930 stliport_t *portp;
1931 stlibrd_t *brdp;
1932 unsigned int head, tail, len;
1933 unsigned long flags;
1934
1935 #if DEBUG
1936 printk("stli_charsinbuffer(tty=%x)\n", (int) tty);
1937 #endif
1938
1939 if (tty == (struct tty_struct *) NULL)
1940 return(0);
1941 if (tty == stli_txcooktty)
1942 stli_flushchars(tty);
1943 portp = tty->driver_data;
1944 if (portp == (stliport_t *) NULL)
1945 return(0);
1946 if ((portp->brdnr < 0) || (portp->brdnr >= stli_nrbrds))
1947 return(0);
1948 brdp = stli_brds[portp->brdnr];
1949 if (brdp == (stlibrd_t *) NULL)
1950 return(0);
1951
1952 save_flags(flags);
1953 cli();
1954 EBRDENABLE(brdp);
1955 rp = &((volatile cdkasy_t *) EBRDGETMEMPTR(brdp, portp->addr))->txq;
1956 head = (unsigned int) rp->head;
1957 tail = (unsigned int) rp->tail;
1958 if (tail != ((unsigned int) rp->tail))
1959 tail = (unsigned int) rp->tail;
1960 len = (head >= tail) ? (head - tail) : (portp->txsize - (tail - head));
1961 if ((len == 0) && test_bit(ST_TXBUSY, &portp->state))
1962 len = 1;
1963 EBRDDISABLE(brdp);
1964 restore_flags(flags);
1965
1966 return(len);
1967 }
1968
1969 /*****************************************************************************/
1970
1971 /*
1972 * Generate the serial struct info.
1973 */
1974
1975 static void stli_getserial(stliport_t *portp, struct serial_struct *sp)
1976 {
1977 struct serial_struct sio;
1978 stlibrd_t *brdp;
1979
1980 #if DEBUG
1981 printk("stli_getserial(portp=%x,sp=%x)\n", (int) portp, (int) sp);
1982 #endif
1983
1984 memset(&sio, 0, sizeof(struct serial_struct));
1985 sio.type = PORT_UNKNOWN;
1986 sio.line = portp->portnr;
1987 sio.irq = 0;
1988 sio.flags = portp->flags;
1989 sio.baud_base = portp->baud_base;
1990 sio.close_delay = portp->close_delay;
1991 sio.closing_wait = portp->closing_wait;
1992 sio.custom_divisor = portp->custom_divisor;
1993 sio.xmit_fifo_size = 0;
1994 sio.hub6 = 0;
1995
1996 brdp = stli_brds[portp->brdnr];
1997 if (brdp != (stlibrd_t *) NULL)
1998 sio.port = brdp->iobase;
1999
2000 copy_to_user(sp, &sio, sizeof(struct serial_struct));
2001 }
2002
2003 /*****************************************************************************/
2004
2005 /*
2006 * Set port according to the serial struct info.
2007 * At this point we do not do any auto-configure stuff, so we will
2008 * just quietly ignore any requests to change irq, etc.
2009 */
2010
2011 static int stli_setserial(stliport_t *portp, struct serial_struct *sp)
2012 {
2013 struct serial_struct sio;
2014 int rc;
2015
2016 #if DEBUG
2017 printk("stli_setserial(portp=%x,sp=%x)\n", (int) portp, (int) sp);
2018 #endif
2019
2020 copy_from_user(&sio, sp, sizeof(struct serial_struct));
2021 if (!capable(CAP_SYS_ADMIN)) {
2022 if ((sio.baud_base != portp->baud_base) ||
2023 (sio.close_delay != portp->close_delay) ||
2024 ((sio.flags & ~ASYNC_USR_MASK) !=
2025 (portp->flags & ~ASYNC_USR_MASK)))
2026 return(-EPERM);
2027 }
2028
2029 portp->flags = (portp->flags & ~ASYNC_USR_MASK) |
2030 (sio.flags & ASYNC_USR_MASK);
2031 portp->baud_base = sio.baud_base;
2032 portp->close_delay = sio.close_delay;
2033 portp->closing_wait = sio.closing_wait;
2034 portp->custom_divisor = sio.custom_divisor;
2035
2036 if ((rc = stli_setport(portp)) < 0)
2037 return(rc);
2038 return(0);
2039 }
2040
2041 /*****************************************************************************/
2042
2043 static int stli_ioctl(struct tty_struct *tty, struct file *file, unsigned int cmd, unsigned long arg)
2044 {
2045 stliport_t *portp;
2046 stlibrd_t *brdp;
2047 unsigned long lval;
2048 unsigned int ival;
2049 int rc;
2050
2051 #if DEBUG
2052 printk("stli_ioctl(tty=%x,file=%x,cmd=%x,arg=%x)\n",
2053 (int) tty, (int) file, cmd, (int) arg);
2054 #endif
2055
2056 if (tty == (struct tty_struct *) NULL)
2057 return(-ENODEV);
2058 portp = tty->driver_data;
2059 if (portp == (stliport_t *) NULL)
2060 return(-ENODEV);
2061 if ((portp->brdnr < 0) || (portp->brdnr >= stli_nrbrds))
2062 return(0);
2063 brdp = stli_brds[portp->brdnr];
2064 if (brdp == (stlibrd_t *) NULL)
2065 return(0);
2066
2067 if ((cmd != TIOCGSERIAL) && (cmd != TIOCSSERIAL) &&
2068 (cmd != COM_GETPORTSTATS) && (cmd != COM_CLRPORTSTATS)) {
2069 if (tty->flags & (1 << TTY_IO_ERROR))
2070 return(-EIO);
2071 }
2072
2073 rc = 0;
2074
2075 switch (cmd) {
2076 case TIOCGSOFTCAR:
2077 rc = put_user(((tty->termios->c_cflag & CLOCAL) ? 1 : 0),
2078 (unsigned int *) arg);
2079 break;
2080 case TIOCSSOFTCAR:
2081 if ((rc = verify_area(VERIFY_READ, (void *) arg,
2082 sizeof(unsigned int))) == 0) {
2083 get_user(ival, (unsigned int *) arg);
2084 tty->termios->c_cflag =
2085 (tty->termios->c_cflag & ~CLOCAL) |
2086 (ival ? CLOCAL : 0);
2087 }
2088 break;
2089 case TIOCMGET:
2090 if ((rc = verify_area(VERIFY_WRITE, (void *) arg,
2091 sizeof(unsigned int))) == 0) {
2092 if ((rc = stli_cmdwait(brdp, portp, A_GETSIGNALS,
2093 &portp->asig, sizeof(asysigs_t), 1)) < 0)
2094 return(rc);
2095 lval = stli_mktiocm(portp->asig.sigvalue);
2096 put_user(lval, (unsigned int *) arg);
2097 }
2098 break;
2099 case TIOCMBIS:
2100 if ((rc = verify_area(VERIFY_READ, (void *) arg,
2101 sizeof(unsigned int))) == 0) {
2102 get_user(ival, (unsigned int *) arg);
2103 stli_mkasysigs(&portp->asig,
2104 ((ival & TIOCM_DTR) ? 1 : -1),
2105 ((ival & TIOCM_RTS) ? 1 : -1));
2106 rc = stli_cmdwait(brdp, portp, A_SETSIGNALS,
2107 &portp->asig, sizeof(asysigs_t), 0);
2108 }
2109 break;
2110 case TIOCMBIC:
2111 if ((rc = verify_area(VERIFY_READ, (void *) arg,
2112 sizeof(unsigned int))) == 0) {
2113 get_user(ival, (unsigned int *) arg);
2114 stli_mkasysigs(&portp->asig,
2115 ((ival & TIOCM_DTR) ? 0 : -1),
2116 ((ival & TIOCM_RTS) ? 0 : -1));
2117 rc = stli_cmdwait(brdp, portp, A_SETSIGNALS,
2118 &portp->asig, sizeof(asysigs_t), 0);
2119 }
2120 break;
2121 case TIOCMSET:
2122 if ((rc = verify_area(VERIFY_READ, (void *) arg,
2123 sizeof(unsigned int))) == 0) {
2124 get_user(ival, (unsigned int *) arg);
2125 stli_mkasysigs(&portp->asig,
2126 ((ival & TIOCM_DTR) ? 1 : 0),
2127 ((ival & TIOCM_RTS) ? 1 : 0));
2128 rc = stli_cmdwait(brdp, portp, A_SETSIGNALS,
2129 &portp->asig, sizeof(asysigs_t), 0);
2130 }
2131 break;
2132 case TIOCGSERIAL:
2133 if ((rc = verify_area(VERIFY_WRITE, (void *) arg,
2134 sizeof(struct serial_struct))) == 0)
2135 stli_getserial(portp, (struct serial_struct *) arg);
2136 break;
2137 case TIOCSSERIAL:
2138 if ((rc = verify_area(VERIFY_READ, (void *) arg,
2139 sizeof(struct serial_struct))) == 0)
2140 rc = stli_setserial(portp, (struct serial_struct *)arg);
2141 break;
2142 case STL_GETPFLAG:
2143 if ((rc = verify_area(VERIFY_WRITE, (void *) arg,
2144 sizeof(unsigned long))) == 0)
2145 put_user(portp->pflag, (unsigned int *) arg);
2146 break;
2147 case STL_SETPFLAG:
2148 if ((rc = verify_area(VERIFY_READ, (void *) arg,
2149 sizeof(unsigned long))) == 0) {
2150 get_user(portp->pflag, (unsigned int *) arg);
2151 stli_setport(portp);
2152 }
2153 break;
2154 case COM_GETPORTSTATS:
2155 if ((rc = verify_area(VERIFY_WRITE, (void *) arg,
2156 sizeof(comstats_t))) == 0)
2157 rc = stli_getportstats(portp, (comstats_t *) arg);
2158 break;
2159 case COM_CLRPORTSTATS:
2160 if ((rc = verify_area(VERIFY_WRITE, (void *) arg,
2161 sizeof(comstats_t))) == 0)
2162 rc = stli_clrportstats(portp, (comstats_t *) arg);
2163 break;
2164 case TIOCSERCONFIG:
2165 case TIOCSERGWILD:
2166 case TIOCSERSWILD:
2167 case TIOCSERGETLSR:
2168 case TIOCSERGSTRUCT:
2169 case TIOCSERGETMULTI:
2170 case TIOCSERSETMULTI:
2171 default:
2172 rc = -ENOIOCTLCMD;
2173 break;
2174 }
2175
2176 return(rc);
2177 }
2178
2179 /*****************************************************************************/
2180
2181 /*
2182 * This routine assumes that we have user context and can sleep.
2183 * Looks like it is true for the current ttys implementation..!!
2184 */
2185
2186 static void stli_settermios(struct tty_struct *tty, struct termios *old)
2187 {
2188 stliport_t *portp;
2189 stlibrd_t *brdp;
2190 struct termios *tiosp;
2191 asyport_t aport;
2192
2193 #if DEBUG
2194 printk("stli_settermios(tty=%x,old=%x)\n", (int) tty, (int) old);
2195 #endif
2196
2197 if (tty == (struct tty_struct *) NULL)
2198 return;
2199 portp = tty->driver_data;
2200 if (portp == (stliport_t *) NULL)
2201 return;
2202 if ((portp->brdnr < 0) || (portp->brdnr >= stli_nrbrds))
2203 return;
2204 brdp = stli_brds[portp->brdnr];
2205 if (brdp == (stlibrd_t *) NULL)
2206 return;
2207
2208 tiosp = tty->termios;
2209 if ((tiosp->c_cflag == old->c_cflag) &&
2210 (tiosp->c_iflag == old->c_iflag))
2211 return;
2212
2213 stli_mkasyport(portp, &aport, tiosp);
2214 stli_cmdwait(brdp, portp, A_SETPORT, &aport, sizeof(asyport_t), 0);
2215 stli_mkasysigs(&portp->asig, ((tiosp->c_cflag & CBAUD) ? 1 : 0), -1);
2216 stli_cmdwait(brdp, portp, A_SETSIGNALS, &portp->asig,
2217 sizeof(asysigs_t), 0);
2218 if ((old->c_cflag & CRTSCTS) && ((tiosp->c_cflag & CRTSCTS) == 0))
2219 tty->hw_stopped = 0;
2220 if (((old->c_cflag & CLOCAL) == 0) && (tiosp->c_cflag & CLOCAL))
2221 wake_up_interruptible(&portp->open_wait);
2222 }
2223
2224 /*****************************************************************************/
2225
2226 /*
2227 * Attempt to flow control who ever is sending us data. We won't really
2228 * do any flow control action here. We can't directly, and even if we
2229 * wanted to we would have to send a command to the slave. The slave
2230 * knows how to flow control, and will do so when its buffers reach its
2231 * internal high water marks. So what we will do is set a local state
2232 * bit that will stop us sending any RX data up from the poll routine
2233 * (which is the place where RX data from the slave is handled).
2234 */
2235
2236 static void stli_throttle(struct tty_struct *tty)
2237 {
2238 stliport_t *portp;
2239
2240 #if DEBUG
2241 printk("stli_throttle(tty=%x)\n", (int) tty);
2242 #endif
2243
2244 if (tty == (struct tty_struct *) NULL)
2245 return;
2246 portp = tty->driver_data;
2247 if (portp == (stliport_t *) NULL)
2248 return;
2249
2250 set_bit(ST_RXSTOP, &portp->state);
2251 }
2252
2253 /*****************************************************************************/
2254
2255 /*
2256 * Unflow control the device sending us data... That means that all
2257 * we have to do is clear the RXSTOP state bit. The next poll call
2258 * will then be able to pass the RX data back up.
2259 */
2260
2261 static void stli_unthrottle(struct tty_struct *tty)
2262 {
2263 stliport_t *portp;
2264
2265 #if DEBUG
2266 printk("stli_unthrottle(tty=%x)\n", (int) tty);
2267 #endif
2268
2269 if (tty == (struct tty_struct *) NULL)
2270 return;
2271 portp = tty->driver_data;
2272 if (portp == (stliport_t *) NULL)
2273 return;
2274
2275 clear_bit(ST_RXSTOP, &portp->state);
2276 }
2277
2278 /*****************************************************************************/
2279
2280 /*
2281 * Stop the transmitter. Basically to do this we will just turn TX
2282 * interrupts off.
2283 */
2284
2285 static void stli_stop(struct tty_struct *tty)
2286 {
2287 stlibrd_t *brdp;
2288 stliport_t *portp;
2289 asyctrl_t actrl;
2290
2291 #if DEBUG
2292 printk("stli_stop(tty=%x)\n", (int) tty);
2293 #endif
2294
2295 if (tty == (struct tty_struct *) NULL)
2296 return;
2297 portp = tty->driver_data;
2298 if (portp == (stliport_t *) NULL)
2299 return;
2300 if ((portp->brdnr < 0) || (portp->brdnr >= stli_nrbrds))
2301 return;
2302 brdp = stli_brds[portp->brdnr];
2303 if (brdp == (stlibrd_t *) NULL)
2304 return;
2305
2306 memset(&actrl, 0, sizeof(asyctrl_t));
2307 actrl.txctrl = CT_STOPFLOW;
2308 #if 0
2309 stli_cmdwait(brdp, portp, A_PORTCTRL, &actrl, sizeof(asyctrl_t), 0);
2310 #endif
2311 }
2312
2313 /*****************************************************************************/
2314
2315 /*
2316 * Start the transmitter again. Just turn TX interrupts back on.
2317 */
2318
2319 static void stli_start(struct tty_struct *tty)
2320 {
2321 stliport_t *portp;
2322 stlibrd_t *brdp;
2323 asyctrl_t actrl;
2324
2325 #if DEBUG
2326 printk("stli_start(tty=%x)\n", (int) tty);
2327 #endif
2328
2329 if (tty == (struct tty_struct *) NULL)
2330 return;
2331 portp = tty->driver_data;
2332 if (portp == (stliport_t *) NULL)
2333 return;
2334 if ((portp->brdnr < 0) || (portp->brdnr >= stli_nrbrds))
2335 return;
2336 brdp = stli_brds[portp->brdnr];
2337 if (brdp == (stlibrd_t *) NULL)
2338 return;
2339
2340 memset(&actrl, 0, sizeof(asyctrl_t));
2341 actrl.txctrl = CT_STARTFLOW;
2342 #if 0
2343 stli_cmdwait(brdp, portp, A_PORTCTRL, &actrl, sizeof(asyctrl_t), 0);
2344 #endif
2345 }
2346
2347 /*****************************************************************************/
2348
2349 /*
2350 * Scheduler called hang up routine. This is called from the scheduler,
2351 * not direct from the driver "poll" routine. We can't call it there
2352 * since the real local hangup code will enable/disable the board and
2353 * other things that we can't do while handling the poll. Much easier
2354 * to deal with it some time later (don't really care when, hangups
2355 * aren't that time critical).
2356 */
2357
2358 static void stli_dohangup(void *arg)
2359 {
2360 stliport_t *portp;
2361
2362 #if DEBUG
2363 printk("stli_dohangup(portp=%x)\n", (int) arg);
2364 #endif
2365
2366 /*
2367 * FIXME: There's a module removal race here: tty_hangup
2368 * calls schedule_task which will call into this
2369 * driver later.
2370 */
2371 portp = (stliport_t *) arg;
2372 if (portp != (stliport_t *) NULL) {
2373 if (portp->tty != (struct tty_struct *) NULL) {
2374 tty_hangup(portp->tty);
2375 }
2376 }
2377 MOD_DEC_USE_COUNT;
2378 }
2379
2380 /*****************************************************************************/
2381
2382 /*
2383 * Hangup this port. This is pretty much like closing the port, only
2384 * a little more brutal. No waiting for data to drain. Shutdown the
2385 * port and maybe drop signals. This is rather tricky really. We want
2386 * to close the port as well.
2387 */
2388
2389 static void stli_hangup(struct tty_struct *tty)
2390 {
2391 stliport_t *portp;
2392 stlibrd_t *brdp;
2393 unsigned long flags;
2394
2395 #if DEBUG
2396 printk("stli_hangup(tty=%x)\n", (int) tty);
2397 #endif
2398
2399 if (tty == (struct tty_struct *) NULL)
2400 return;
2401 portp = tty->driver_data;
2402 if (portp == (stliport_t *) NULL)
2403 return;
2404 if ((portp->brdnr < 0) || (portp->brdnr >= stli_nrbrds))
2405 return;
2406 brdp = stli_brds[portp->brdnr];
2407 if (brdp == (stlibrd_t *) NULL)
2408 return;
2409
2410 portp->flags &= ~ASYNC_INITIALIZED;
2411
2412 save_flags(flags);
2413 cli();
2414 if (! test_bit(ST_CLOSING, &portp->state))
2415 stli_rawclose(brdp, portp, 0, 0);
2416 if (tty->termios->c_cflag & HUPCL) {
2417 stli_mkasysigs(&portp->asig, 0, 0);
2418 if (test_bit(ST_CMDING, &portp->state)) {
2419 set_bit(ST_DOSIGS, &portp->state);
2420 set_bit(ST_DOFLUSHTX, &portp->state);
2421 set_bit(ST_DOFLUSHRX, &portp->state);
2422 } else {
2423 stli_sendcmd(brdp, portp, A_SETSIGNALSF,
2424 &portp->asig, sizeof(asysigs_t), 0);
2425 }
2426 }
2427 restore_flags(flags);
2428
2429 clear_bit(ST_TXBUSY, &portp->state);
2430 clear_bit(ST_RXSTOP, &portp->state);
2431 set_bit(TTY_IO_ERROR, &tty->flags);
2432 portp->tty = (struct tty_struct *) NULL;
2433 portp->flags &= ~(ASYNC_NORMAL_ACTIVE | ASYNC_CALLOUT_ACTIVE);
2434 portp->refcount = 0;
2435 wake_up_interruptible(&portp->open_wait);
2436 }
2437
2438 /*****************************************************************************/
2439
2440 /*
2441 * Flush characters from the lower buffer. We may not have user context
2442 * so we cannot sleep waiting for it to complete. Also we need to check
2443 * if there is chars for this port in the TX cook buffer, and flush them
2444 * as well.
2445 */
2446
2447 static void stli_flushbuffer(struct tty_struct *tty)
2448 {
2449 stliport_t *portp;
2450 stlibrd_t *brdp;
2451 unsigned long ftype, flags;
2452
2453 #if DEBUG
2454 printk("stli_flushbuffer(tty=%x)\n", (int) tty);
2455 #endif
2456
2457 if (tty == (struct tty_struct *) NULL)
2458 return;
2459 portp = tty->driver_data;
2460 if (portp == (stliport_t *) NULL)
2461 return;
2462 if ((portp->brdnr < 0) || (portp->brdnr >= stli_nrbrds))
2463 return;
2464 brdp = stli_brds[portp->brdnr];
2465 if (brdp == (stlibrd_t *) NULL)
2466 return;
2467
2468 save_flags(flags);
2469 cli();
2470 if (tty == stli_txcooktty) {
2471 stli_txcooktty = (struct tty_struct *) NULL;
2472 stli_txcooksize = 0;
2473 stli_txcookrealsize = 0;
2474 }
2475 if (test_bit(ST_CMDING, &portp->state)) {
2476 set_bit(ST_DOFLUSHTX, &portp->state);
2477 } else {
2478 ftype = FLUSHTX;
2479 if (test_bit(ST_DOFLUSHRX, &portp->state)) {
2480 ftype |= FLUSHRX;
2481 clear_bit(ST_DOFLUSHRX, &portp->state);
2482 }
2483 stli_sendcmd(brdp, portp, A_FLUSH, &ftype,
2484 sizeof(unsigned long), 0);
2485 }
2486 restore_flags(flags);
2487
2488 wake_up_interruptible(&tty->write_wait);
2489 if ((tty->flags & (1 << TTY_DO_WRITE_WAKEUP)) &&
2490 tty->ldisc.write_wakeup)
2491 (tty->ldisc.write_wakeup)(tty);
2492 }
2493
2494 /*****************************************************************************/
2495
2496 static void stli_breakctl(struct tty_struct *tty, int state)
2497 {
2498 stlibrd_t *brdp;
2499 stliport_t *portp;
2500 long arg;
2501 /* long savestate, savetime; */
2502
2503 #if DEBUG
2504 printk("stli_breakctl(tty=%x,state=%d)\n", (int) tty, state);
2505 #endif
2506
2507 if (tty == (struct tty_struct *) NULL)
2508 return;
2509 portp = tty->driver_data;
2510 if (portp == (stliport_t *) NULL)
2511 return;
2512 if ((portp->brdnr < 0) || (portp->brdnr >= stli_nrbrds))
2513 return;
2514 brdp = stli_brds[portp->brdnr];
2515 if (brdp == (stlibrd_t *) NULL)
2516 return;
2517
2518 /*
2519 * Due to a bug in the tty send_break() code we need to preserve
2520 * the current process state and timeout...
2521 savetime = current->timeout;
2522 savestate = current->state;
2523 */
2524
2525 arg = (state == -1) ? BREAKON : BREAKOFF;
2526 stli_cmdwait(brdp, portp, A_BREAK, &arg, sizeof(long), 0);
2527
2528 /*
2529 *
2530 current->timeout = savetime;
2531 current->state = savestate;
2532 */
2533 }
2534
2535 /*****************************************************************************/
2536
2537 static void stli_waituntilsent(struct tty_struct *tty, int timeout)
2538 {
2539 stliport_t *portp;
2540 unsigned long tend;
2541
2542 #if DEBUG
2543 printk("stli_waituntilsent(tty=%x,timeout=%x)\n", (int) tty, timeout);
2544 #endif
2545
2546 if (tty == (struct tty_struct *) NULL)
2547 return;
2548 portp = tty->driver_data;
2549 if (portp == (stliport_t *) NULL)
2550 return;
2551
2552 if (timeout == 0)
2553 timeout = HZ;
2554 tend = jiffies + timeout;
2555
2556 while (test_bit(ST_TXBUSY, &portp->state)) {
2557 if (signal_pending(current))
2558 break;
2559 stli_delay(2);
2560 if (time_after_eq(jiffies, tend))
2561 break;
2562 }
2563 }
2564
2565 /*****************************************************************************/
2566
2567 static void stli_sendxchar(struct tty_struct *tty, char ch)
2568 {
2569 stlibrd_t *brdp;
2570 stliport_t *portp;
2571 asyctrl_t actrl;
2572
2573 #if DEBUG
2574 printk("stli_sendxchar(tty=%x,ch=%x)\n", (int) tty, ch);
2575 #endif
2576
2577 if (tty == (struct tty_struct *) NULL)
2578 return;
2579 portp = tty->driver_data;
2580 if (portp == (stliport_t *) NULL)
2581 return;
2582 if ((portp->brdnr < 0) || (portp->brdnr >= stli_nrbrds))
2583 return;
2584 brdp = stli_brds[portp->brdnr];
2585 if (brdp == (stlibrd_t *) NULL)
2586 return;
2587
2588 memset(&actrl, 0, sizeof(asyctrl_t));
2589 if (ch == STOP_CHAR(tty)) {
2590 actrl.rxctrl = CT_STOPFLOW;
2591 } else if (ch == START_CHAR(tty)) {
2592 actrl.rxctrl = CT_STARTFLOW;
2593 } else {
2594 actrl.txctrl = CT_SENDCHR;
2595 actrl.tximdch = ch;
2596 }
2597
2598 stli_cmdwait(brdp, portp, A_PORTCTRL, &actrl, sizeof(asyctrl_t), 0);
2599 }
2600
2601 /*****************************************************************************/
2602
2603 #define MAXLINE 80
2604
2605 /*
2606 * Format info for a specified port. The line is deliberately limited
2607 * to 80 characters. (If it is too long it will be truncated, if too
2608 * short then padded with spaces).
2609 */
2610
2611 static int stli_portinfo(stlibrd_t *brdp, stliport_t *portp, int portnr, char *pos)
2612 {
2613 char *sp, *uart;
2614 int rc, cnt;
2615
2616 rc = stli_portcmdstats(portp);
2617
2618 uart = "UNKNOWN";
2619 if (brdp->state & BST_STARTED) {
2620 switch (stli_comstats.hwid) {
2621 case 0: uart = "2681"; break;
2622 case 1: uart = "SC26198"; break;
2623 default: uart = "CD1400"; break;
2624 }
2625 }
2626
2627 sp = pos;
2628 sp += sprintf(sp, "%d: uart:%s ", portnr, uart);
2629
2630 if ((brdp->state & BST_STARTED) && (rc >= 0)) {
2631 sp += sprintf(sp, "tx:%d rx:%d", (int) stli_comstats.txtotal,
2632 (int) stli_comstats.rxtotal);
2633
2634 if (stli_comstats.rxframing)
2635 sp += sprintf(sp, " fe:%d",
2636 (int) stli_comstats.rxframing);
2637 if (stli_comstats.rxparity)
2638 sp += sprintf(sp, " pe:%d",
2639 (int) stli_comstats.rxparity);
2640 if (stli_comstats.rxbreaks)
2641 sp += sprintf(sp, " brk:%d",
2642 (int) stli_comstats.rxbreaks);
2643 if (stli_comstats.rxoverrun)
2644 sp += sprintf(sp, " oe:%d",
2645 (int) stli_comstats.rxoverrun);
2646
2647 cnt = sprintf(sp, "%s%s%s%s%s ",
2648 (stli_comstats.signals & TIOCM_RTS) ? "|RTS" : "",
2649 (stli_comstats.signals & TIOCM_CTS) ? "|CTS" : "",
2650 (stli_comstats.signals & TIOCM_DTR) ? "|DTR" : "",
2651 (stli_comstats.signals & TIOCM_CD) ? "|DCD" : "",
2652 (stli_comstats.signals & TIOCM_DSR) ? "|DSR" : "");
2653 *sp = ' ';
2654 sp += cnt;
2655 }
2656
2657 for (cnt = (sp - pos); (cnt < (MAXLINE - 1)); cnt++)
2658 *sp++ = ' ';
2659 if (cnt >= MAXLINE)
2660 pos[(MAXLINE - 2)] = '+';
2661 pos[(MAXLINE - 1)] = '\n';
2662
2663 return(MAXLINE);
2664 }
2665
2666 /*****************************************************************************/
2667
2668 /*
2669 * Port info, read from the /proc file system.
2670 */
2671
2672 static int stli_readproc(char *page, char **start, off_t off, int count, int *eof, void *data)
2673 {
2674 stlibrd_t *brdp;
2675 stliport_t *portp;
2676 int brdnr, portnr, totalport;
2677 int curoff, maxoff;
2678 char *pos;
2679
2680 #if DEBUG
2681 printk("stli_readproc(page=%x,start=%x,off=%x,count=%d,eof=%x,"
2682 "data=%x\n", (int) page, (int) start, (int) off, count,
2683 (int) eof, (int) data);
2684 #endif
2685
2686 pos = page;
2687 totalport = 0;
2688 curoff = 0;
2689
2690 if (off == 0) {
2691 pos += sprintf(pos, "%s: version %s", stli_drvtitle,
2692 stli_drvversion);
2693 while (pos < (page + MAXLINE - 1))
2694 *pos++ = ' ';
2695 *pos++ = '\n';
2696 }
2697 curoff = MAXLINE;
2698
2699 /*
2700 * We scan through for each board, panel and port. The offset is
2701 * calculated on the fly, and irrelevant ports are skipped.
2702 */
2703 for (brdnr = 0; (brdnr < stli_nrbrds); brdnr++) {
2704 brdp = stli_brds[brdnr];
2705 if (brdp == (stlibrd_t *) NULL)
2706 continue;
2707 if (brdp->state == 0)
2708 continue;
2709
2710 maxoff = curoff + (brdp->nrports * MAXLINE);
2711 if (off >= maxoff) {
2712 curoff = maxoff;
2713 continue;
2714 }
2715
2716 totalport = brdnr * STL_MAXPORTS;
2717 for (portnr = 0; (portnr < brdp->nrports); portnr++,
2718 totalport++) {
2719 portp = brdp->ports[portnr];
2720 if (portp == (stliport_t *) NULL)
2721 continue;
2722 if (off >= (curoff += MAXLINE))
2723 continue;
2724 if ((pos - page + MAXLINE) > count)
2725 goto stli_readdone;
2726 pos += stli_portinfo(brdp, portp, totalport, pos);
2727 }
2728 }
2729
2730 *eof = 1;
2731
2732 stli_readdone:
2733 *start = page;
2734 return(pos - page);
2735 }
2736
2737 /*****************************************************************************/
2738
2739 /*
2740 * Generic send command routine. This will send a message to the slave,
2741 * of the specified type with the specified argument. Must be very
2742 * careful of data that will be copied out from shared memory -
2743 * containing command results. The command completion is all done from
2744 * a poll routine that does not have user context. Therefore you cannot
2745 * copy back directly into user space, or to the kernel stack of a
2746 * process. This routine does not sleep, so can be called from anywhere.
2747 */
2748
2749 static void stli_sendcmd(stlibrd_t *brdp, stliport_t *portp, unsigned long cmd, void *arg, int size, int copyback)
2750 {
2751 volatile cdkhdr_t *hdrp;
2752 volatile cdkctrl_t *cp;
2753 volatile unsigned char *bits;
2754 unsigned long flags;
2755
2756 #if DEBUG
2757 printk("stli_sendcmd(brdp=%x,portp=%x,cmd=%x,arg=%x,size=%d,"
2758 "copyback=%d)\n", (int) brdp, (int) portp, (int) cmd,
2759 (int) arg, size, copyback);
2760 #endif
2761
2762 save_flags(flags);
2763 cli();
2764
2765 if (test_bit(ST_CMDING, &portp->state)) {
2766 printk("STALLION: command already busy, cmd=%x!\n", (int) cmd);
2767 restore_flags(flags);
2768 return;
2769 }
2770
2771 EBRDENABLE(brdp);
2772 cp = &((volatile cdkasy_t *) EBRDGETMEMPTR(brdp, portp->addr))->ctrl;
2773 if (size > 0) {
2774 memcpy((void *) &(cp->args[0]), arg, size);
2775 if (copyback) {
2776 portp->argp = arg;
2777 portp->argsize = size;
2778 }
2779 }
2780 cp->status = 0;
2781 cp->cmd = cmd;
2782 hdrp = (volatile cdkhdr_t *) EBRDGETMEMPTR(brdp, CDK_CDKADDR);
2783 bits = ((volatile unsigned char *) hdrp) + brdp->slaveoffset +
2784 portp->portidx;
2785 *bits |= portp->portbit;
2786 set_bit(ST_CMDING, &portp->state);
2787 EBRDDISABLE(brdp);
2788 restore_flags(flags);
2789 }
2790
2791 /*****************************************************************************/
2792
2793 /*
2794 * Read data from shared memory. This assumes that the shared memory
2795 * is enabled and that interrupts are off. Basically we just empty out
2796 * the shared memory buffer into the tty buffer. Must be careful to
2797 * handle the case where we fill up the tty buffer, but still have
2798 * more chars to unload.
2799 */
2800
2801 static inline void stli_read(stlibrd_t *brdp, stliport_t *portp)
2802 {
2803 volatile cdkasyrq_t *rp;
2804 volatile char *shbuf;
2805 struct tty_struct *tty;
2806 unsigned int head, tail, size;
2807 unsigned int len, stlen;
2808
2809 #if DEBUG
2810 printk("stli_read(brdp=%x,portp=%d)\n", (int) brdp, (int) portp);
2811 #endif
2812
2813 if (test_bit(ST_RXSTOP, &portp->state))
2814 return;
2815 tty = portp->tty;
2816 if (tty == (struct tty_struct *) NULL)
2817 return;
2818
2819 rp = &((volatile cdkasy_t *) EBRDGETMEMPTR(brdp, portp->addr))->rxq;
2820 head = (unsigned int) rp->head;
2821 if (head != ((unsigned int) rp->head))
2822 head = (unsigned int) rp->head;
2823 tail = (unsigned int) rp->tail;
2824 size = portp->rxsize;
2825 if (head >= tail) {
2826 len = head - tail;
2827 stlen = len;
2828 } else {
2829 len = size - (tail - head);
2830 stlen = size - tail;
2831 }
2832
2833 len = MIN(len, (TTY_FLIPBUF_SIZE - tty->flip.count));
2834 shbuf = (volatile char *) EBRDGETMEMPTR(brdp, portp->rxoffset);
2835
2836 while (len > 0) {
2837 stlen = MIN(len, stlen);
2838 memcpy(tty->flip.char_buf_ptr, (char *) (shbuf + tail), stlen);
2839 memset(tty->flip.flag_buf_ptr, 0, stlen);
2840 tty->flip.char_buf_ptr += stlen;
2841 tty->flip.flag_buf_ptr += stlen;
2842 tty->flip.count += stlen;
2843
2844 len -= stlen;
2845 tail += stlen;
2846 if (tail >= size) {
2847 tail = 0;
2848 stlen = head;
2849 }
2850 }
2851 rp = &((volatile cdkasy_t *) EBRDGETMEMPTR(brdp, portp->addr))->rxq;
2852 rp->tail = tail;
2853
2854 if (head != tail)
2855 set_bit(ST_RXING, &portp->state);
2856
2857 tty_schedule_flip(tty);
2858 }
2859
2860 /*****************************************************************************/
2861
2862 /*
2863 * Set up and carry out any delayed commands. There is only a small set
2864 * of slave commands that can be done "off-level". So it is not too
2865 * difficult to deal with them here.
2866 */
2867
2868 static inline void stli_dodelaycmd(stliport_t *portp, volatile cdkctrl_t *cp)
2869 {
2870 int cmd;
2871
2872 if (test_bit(ST_DOSIGS, &portp->state)) {
2873 if (test_bit(ST_DOFLUSHTX, &portp->state) &&
2874 test_bit(ST_DOFLUSHRX, &portp->state))
2875 cmd = A_SETSIGNALSF;
2876 else if (test_bit(ST_DOFLUSHTX, &portp->state))
2877 cmd = A_SETSIGNALSFTX;
2878 else if (test_bit(ST_DOFLUSHRX, &portp->state))
2879 cmd = A_SETSIGNALSFRX;
2880 else
2881 cmd = A_SETSIGNALS;
2882 clear_bit(ST_DOFLUSHTX, &portp->state);
2883 clear_bit(ST_DOFLUSHRX, &portp->state);
2884 clear_bit(ST_DOSIGS, &portp->state);
2885 memcpy((void *) &(cp->args[0]), (void *) &portp->asig,
2886 sizeof(asysigs_t));
2887 cp->status = 0;
2888 cp->cmd = cmd;
2889 set_bit(ST_CMDING, &portp->state);
2890 } else if (test_bit(ST_DOFLUSHTX, &portp->state) ||
2891 test_bit(ST_DOFLUSHRX, &portp->state)) {
2892 cmd = ((test_bit(ST_DOFLUSHTX, &portp->state)) ? FLUSHTX : 0);
2893 cmd |= ((test_bit(ST_DOFLUSHRX, &portp->state)) ? FLUSHRX : 0);
2894 clear_bit(ST_DOFLUSHTX, &portp->state);
2895 clear_bit(ST_DOFLUSHRX, &portp->state);
2896 memcpy((void *) &(cp->args[0]), (void *) &cmd, sizeof(int));
2897 cp->status = 0;
2898 cp->cmd = A_FLUSH;
2899 set_bit(ST_CMDING, &portp->state);
2900 }
2901 }
2902
2903 /*****************************************************************************/
2904
2905 /*
2906 * Host command service checking. This handles commands or messages
2907 * coming from the slave to the host. Must have board shared memory
2908 * enabled and interrupts off when called. Notice that by servicing the
2909 * read data last we don't need to change the shared memory pointer
2910 * during processing (which is a slow IO operation).
2911 * Return value indicates if this port is still awaiting actions from
2912 * the slave (like open, command, or even TX data being sent). If 0
2913 * then port is still busy, otherwise no longer busy.
2914 */
2915
2916 static inline int stli_hostcmd(stlibrd_t *brdp, stliport_t *portp)
2917 {
2918 volatile cdkasy_t *ap;
2919 volatile cdkctrl_t *cp;
2920 struct tty_struct *tty;
2921 asynotify_t nt;
2922 unsigned long oldsigs;
2923 int rc, donerx;
2924
2925 #if DEBUG
2926 printk("stli_hostcmd(brdp=%x,channr=%d)\n", (int) brdp, channr);
2927 #endif
2928
2929 ap = (volatile cdkasy_t *) EBRDGETMEMPTR(brdp, portp->addr);
2930 cp = &ap->ctrl;
2931
2932 /*
2933 * Check if we are waiting for an open completion message.
2934 */
2935 if (test_bit(ST_OPENING, &portp->state)) {
2936 rc = (int) cp->openarg;
2937 if ((cp->open == 0) && (rc != 0)) {
2938 if (rc > 0)
2939 rc--;
2940 cp->openarg = 0;
2941 portp->rc = rc;
2942 clear_bit(ST_OPENING, &portp->state);
2943 wake_up_interruptible(&portp->raw_wait);
2944 }
2945 }
2946
2947 /*
2948 * Check if we are waiting for a close completion message.
2949 */
2950 if (test_bit(ST_CLOSING, &portp->state)) {
2951 rc = (int) cp->closearg;
2952 if ((cp->close == 0) && (rc != 0)) {
2953 if (rc > 0)
2954 rc--;
2955 cp->closearg = 0;
2956 portp->rc = rc;
2957 clear_bit(ST_CLOSING, &portp->state);
2958 wake_up_interruptible(&portp->raw_wait);
2959 }
2960 }
2961
2962 /*
2963 * Check if we are waiting for a command completion message. We may
2964 * need to copy out the command results associated with this command.
2965 */
2966 if (test_bit(ST_CMDING, &portp->state)) {
2967 rc = cp->status;
2968 if ((cp->cmd == 0) && (rc != 0)) {
2969 if (rc > 0)
2970 rc--;
2971 if (portp->argp != (void *) NULL) {
2972 memcpy(portp->argp, (void *) &(cp->args[0]),
2973 portp->argsize);
2974 portp->argp = (void *) NULL;
2975 }
2976 cp->status = 0;
2977 portp->rc = rc;
2978 clear_bit(ST_CMDING, &portp->state);
2979 stli_dodelaycmd(portp, cp);
2980 wake_up_interruptible(&portp->raw_wait);
2981 }
2982 }
2983
2984 /*
2985 * Check for any notification messages ready. This includes lots of
2986 * different types of events - RX chars ready, RX break received,
2987 * TX data low or empty in the slave, modem signals changed state.
2988 */
2989 donerx = 0;
2990
2991 if (ap->notify) {
2992 nt = ap->changed;
2993 ap->notify = 0;
2994 tty = portp->tty;
2995
2996 if (nt.signal & SG_DCD) {
2997 oldsigs = portp->sigs;
2998 portp->sigs = stli_mktiocm(nt.sigvalue);
2999 clear_bit(ST_GETSIGS, &portp->state);
3000 if ((portp->sigs & TIOCM_CD) &&
3001 ((oldsigs & TIOCM_CD) == 0))
3002 wake_up_interruptible(&portp->open_wait);
3003 if ((oldsigs & TIOCM_CD) &&
3004 ((portp->sigs & TIOCM_CD) == 0)) {
3005 if (portp->flags & ASYNC_CHECK_CD) {
3006 if (! ((portp->flags & ASYNC_CALLOUT_ACTIVE) &&
3007 (portp->flags & ASYNC_CALLOUT_NOHUP))) {
3008 if (tty != (struct tty_struct *) NULL) {
3009 MOD_INC_USE_COUNT;
3010 if (schedule_task(&portp->tqhangup) == 0)
3011 MOD_DEC_USE_COUNT;
3012 }
3013 }
3014 }
3015 }
3016 }
3017
3018 if (nt.data & DT_TXEMPTY)
3019 clear_bit(ST_TXBUSY, &portp->state);
3020 if (nt.data & (DT_TXEMPTY | DT_TXLOW)) {
3021 if (tty != (struct tty_struct *) NULL) {
3022 if ((tty->flags & (1 << TTY_DO_WRITE_WAKEUP)) &&
3023 tty->ldisc.write_wakeup) {
3024 (tty->ldisc.write_wakeup)(tty);
3025 EBRDENABLE(brdp);
3026 }
3027 wake_up_interruptible(&tty->write_wait);
3028 }
3029 }
3030
3031 if ((nt.data & DT_RXBREAK) && (portp->rxmarkmsk & BRKINT)) {
3032 if (tty != (struct tty_struct *) NULL) {
3033 if (tty->flip.count < TTY_FLIPBUF_SIZE) {
3034 tty->flip.count++;
3035 *tty->flip.flag_buf_ptr++ = TTY_BREAK;
3036 *tty->flip.char_buf_ptr++ = 0;
3037 if (portp->flags & ASYNC_SAK) {
3038 do_SAK(tty);
3039 EBRDENABLE(brdp);
3040 }
3041 tty_schedule_flip(tty);
3042 }
3043 }
3044 }
3045
3046 if (nt.data & DT_RXBUSY) {
3047 donerx++;
3048 stli_read(brdp, portp);
3049 }
3050 }
3051
3052 /*
3053 * It might seem odd that we are checking for more RX chars here.
3054 * But, we need to handle the case where the tty buffer was previously
3055 * filled, but we had more characters to pass up. The slave will not
3056 * send any more RX notify messages until the RX buffer has been emptied.
3057 * But it will leave the service bits on (since the buffer is not empty).
3058 * So from here we can try to process more RX chars.
3059 */
3060 if ((!donerx) && test_bit(ST_RXING, &portp->state)) {
3061 clear_bit(ST_RXING, &portp->state);
3062 stli_read(brdp, portp);
3063 }
3064
3065 return((test_bit(ST_OPENING, &portp->state) ||
3066 test_bit(ST_CLOSING, &portp->state) ||
3067 test_bit(ST_CMDING, &portp->state) ||
3068 test_bit(ST_TXBUSY, &portp->state) ||
3069 test_bit(ST_RXING, &portp->state)) ? 0 : 1);
3070 }
3071
3072 /*****************************************************************************/
3073
3074 /*
3075 * Service all ports on a particular board. Assumes that the boards
3076 * shared memory is enabled, and that the page pointer is pointed
3077 * at the cdk header structure.
3078 */
3079
3080 static inline void stli_brdpoll(stlibrd_t *brdp, volatile cdkhdr_t *hdrp)
3081 {
3082 stliport_t *portp;
3083 unsigned char hostbits[(STL_MAXCHANS / 8) + 1];
3084 unsigned char slavebits[(STL_MAXCHANS / 8) + 1];
3085 unsigned char *slavep;
3086 int bitpos, bitat, bitsize;
3087 int channr, nrdevs, slavebitchange;
3088
3089 bitsize = brdp->bitsize;
3090 nrdevs = brdp->nrdevs;
3091
3092 /*
3093 * Check if slave wants any service. Basically we try to do as
3094 * little work as possible here. There are 2 levels of service
3095 * bits. So if there is nothing to do we bail early. We check
3096 * 8 service bits at a time in the inner loop, so we can bypass
3097 * the lot if none of them want service.
3098 */
3099 memcpy(&hostbits[0], (((unsigned char *) hdrp) + brdp->hostoffset),
3100 bitsize);
3101
3102 memset(&slavebits[0], 0, bitsize);
3103 slavebitchange = 0;
3104
3105 for (bitpos = 0; (bitpos < bitsize); bitpos++) {
3106 if (hostbits[bitpos] == 0)
3107 continue;
3108 channr = bitpos * 8;
3109 for (bitat = 0x1; (channr < nrdevs); channr++, bitat <<= 1) {
3110 if (hostbits[bitpos] & bitat) {
3111 portp = brdp->ports[(channr - 1)];
3112 if (stli_hostcmd(brdp, portp)) {
3113 slavebitchange++;
3114 slavebits[bitpos] |= bitat;
3115 }
3116 }
3117 }
3118 }
3119
3120 /*
3121 * If any of the ports are no longer busy then update them in the
3122 * slave request bits. We need to do this after, since a host port
3123 * service may initiate more slave requests.
3124 */
3125 if (slavebitchange) {
3126 hdrp = (volatile cdkhdr_t *) EBRDGETMEMPTR(brdp, CDK_CDKADDR);
3127 slavep = ((unsigned char *) hdrp) + brdp->slaveoffset;
3128 for (bitpos = 0; (bitpos < bitsize); bitpos++) {
3129 if (slavebits[bitpos])
3130 slavep[bitpos] &= ~slavebits[bitpos];
3131 }
3132 }
3133 }
3134
3135 /*****************************************************************************/
3136
3137 /*
3138 * Driver poll routine. This routine polls the boards in use and passes
3139 * messages back up to host when necessary. This is actually very
3140 * CPU efficient, since we will always have the kernel poll clock, it
3141 * adds only a few cycles when idle (since board service can be
3142 * determined very easily), but when loaded generates no interrupts
3143 * (with their expensive associated context change).
3144 */
3145
3146 static void stli_poll(unsigned long arg)
3147 {
3148 volatile cdkhdr_t *hdrp;
3149 stlibrd_t *brdp;
3150 int brdnr;
3151
3152 stli_timerlist.expires = STLI_TIMEOUT;
3153 add_timer(&stli_timerlist);
3154
3155 /*
3156 * Check each board and do any servicing required.
3157 */
3158 for (brdnr = 0; (brdnr < stli_nrbrds); brdnr++) {
3159 brdp = stli_brds[brdnr];
3160 if (brdp == (stlibrd_t *) NULL)
3161 continue;
3162 if ((brdp->state & BST_STARTED) == 0)
3163 continue;
3164
3165 EBRDENABLE(brdp);
3166 hdrp = (volatile cdkhdr_t *) EBRDGETMEMPTR(brdp, CDK_CDKADDR);
3167 if (hdrp->hostreq)
3168 stli_brdpoll(brdp, hdrp);
3169 EBRDDISABLE(brdp);
3170 }
3171 }
3172
3173 /*****************************************************************************/
3174
3175 /*
3176 * Translate the termios settings into the port setting structure of
3177 * the slave.
3178 */
3179
3180 static void stli_mkasyport(stliport_t *portp, asyport_t *pp, struct termios *tiosp)
3181 {
3182 #if DEBUG
3183 printk("stli_mkasyport(portp=%x,pp=%x,tiosp=%d)\n",
3184 (int) portp, (int) pp, (int) tiosp);
3185 #endif
3186
3187 memset(pp, 0, sizeof(asyport_t));
3188
3189 /*
3190 * Start of by setting the baud, char size, parity and stop bit info.
3191 */
3192 pp->baudout = tiosp->c_cflag & CBAUD;
3193 if (pp->baudout & CBAUDEX) {
3194 pp->baudout &= ~CBAUDEX;
3195 if ((pp->baudout < 1) || (pp->baudout > 4))
3196 tiosp->c_cflag &= ~CBAUDEX;
3197 else
3198 pp->baudout += 15;
3199 }
3200 pp->baudout = stli_baudrates[pp->baudout];
3201 if ((tiosp->c_cflag & CBAUD) == B38400) {
3202 if ((portp->flags & ASYNC_SPD_MASK) == ASYNC_SPD_HI)
3203 pp->baudout = 57600;
3204 else if ((portp->flags & ASYNC_SPD_MASK) == ASYNC_SPD_VHI)
3205 pp->baudout = 115200;
3206 else if ((portp->flags & ASYNC_SPD_MASK) == ASYNC_SPD_SHI)
3207 pp->baudout = 230400;
3208 else if ((portp->flags & ASYNC_SPD_MASK) == ASYNC_SPD_WARP)
3209 pp->baudout = 460800;
3210 else if ((portp->flags & ASYNC_SPD_MASK) == ASYNC_SPD_CUST)
3211 pp->baudout = (portp->baud_base / portp->custom_divisor);
3212 }
3213 if (pp->baudout > STL_MAXBAUD)
3214 pp->baudout = STL_MAXBAUD;
3215 pp->baudin = pp->baudout;
3216
3217 switch (tiosp->c_cflag & CSIZE) {
3218 case CS5:
3219 pp->csize = 5;
3220 break;
3221 case CS6:
3222 pp->csize = 6;
3223 break;
3224 case CS7:
3225 pp->csize = 7;
3226 break;
3227 default:
3228 pp->csize = 8;
3229 break;
3230 }
3231
3232 if (tiosp->c_cflag & CSTOPB)
3233 pp->stopbs = PT_STOP2;
3234 else
3235 pp->stopbs = PT_STOP1;
3236
3237 if (tiosp->c_cflag & PARENB) {
3238 if (tiosp->c_cflag & PARODD)
3239 pp->parity = PT_ODDPARITY;
3240 else
3241 pp->parity = PT_EVENPARITY;
3242 } else {
3243 pp->parity = PT_NOPARITY;
3244 }
3245
3246 /*
3247 * Set up any flow control options enabled.
3248 */
3249 if (tiosp->c_iflag & IXON) {
3250 pp->flow |= F_IXON;
3251 if (tiosp->c_iflag & IXANY)
3252 pp->flow |= F_IXANY;
3253 }
3254 if (tiosp->c_cflag & CRTSCTS)
3255 pp->flow |= (F_RTSFLOW | F_CTSFLOW);
3256
3257 pp->startin = tiosp->c_cc[VSTART];
3258 pp->stopin = tiosp->c_cc[VSTOP];
3259 pp->startout = tiosp->c_cc[VSTART];
3260 pp->stopout = tiosp->c_cc[VSTOP];
3261
3262 /*
3263 * Set up the RX char marking mask with those RX error types we must
3264 * catch. We can get the slave to help us out a little here, it will
3265 * ignore parity errors and breaks for us, and mark parity errors in
3266 * the data stream.
3267 */
3268 if (tiosp->c_iflag & IGNPAR)
3269 pp->iflag |= FI_IGNRXERRS;
3270 if (tiosp->c_iflag & IGNBRK)
3271 pp->iflag |= FI_IGNBREAK;
3272
3273 portp->rxmarkmsk = 0;
3274 if (tiosp->c_iflag & (INPCK | PARMRK))
3275 pp->iflag |= FI_1MARKRXERRS;
3276 if (tiosp->c_iflag & BRKINT)
3277 portp->rxmarkmsk |= BRKINT;
3278
3279 /*
3280 * Set up clocal processing as required.
3281 */
3282 if (tiosp->c_cflag & CLOCAL)
3283 portp->flags &= ~ASYNC_CHECK_CD;
3284 else
3285 portp->flags |= ASYNC_CHECK_CD;
3286
3287 /*
3288 * Transfer any persistent flags into the asyport structure.
3289 */
3290 pp->pflag = (portp->pflag & 0xffff);
3291 pp->vmin = (portp->pflag & P_RXIMIN) ? 1 : 0;
3292 pp->vtime = (portp->pflag & P_RXITIME) ? 1 : 0;
3293 pp->cc[1] = (portp->pflag & P_RXTHOLD) ? 1 : 0;
3294 }
3295
3296 /*****************************************************************************/
3297
3298 /*
3299 * Construct a slave signals structure for setting the DTR and RTS
3300 * signals as specified.
3301 */
3302
3303 static void stli_mkasysigs(asysigs_t *sp, int dtr, int rts)
3304 {
3305 #if DEBUG
3306 printk("stli_mkasysigs(sp=%x,dtr=%d,rts=%d)\n", (int) sp, dtr, rts);
3307 #endif
3308
3309 memset(sp, 0, sizeof(asysigs_t));
3310 if (dtr >= 0) {
3311 sp->signal |= SG_DTR;
3312 sp->sigvalue |= ((dtr > 0) ? SG_DTR : 0);
3313 }
3314 if (rts >= 0) {
3315 sp->signal |= SG_RTS;
3316 sp->sigvalue |= ((rts > 0) ? SG_RTS : 0);
3317 }
3318 }
3319
3320 /*****************************************************************************/
3321
3322 /*
3323 * Convert the signals returned from the slave into a local TIOCM type
3324 * signals value. We keep them locally in TIOCM format.
3325 */
3326
3327 static long stli_mktiocm(unsigned long sigvalue)
3328 {
3329 long tiocm;
3330
3331 #if DEBUG
3332 printk("stli_mktiocm(sigvalue=%x)\n", (int) sigvalue);
3333 #endif
3334
3335 tiocm = 0;
3336 tiocm |= ((sigvalue & SG_DCD) ? TIOCM_CD : 0);
3337 tiocm |= ((sigvalue & SG_CTS) ? TIOCM_CTS : 0);
3338 tiocm |= ((sigvalue & SG_RI) ? TIOCM_RI : 0);
3339 tiocm |= ((sigvalue & SG_DSR) ? TIOCM_DSR : 0);
3340 tiocm |= ((sigvalue & SG_DTR) ? TIOCM_DTR : 0);
3341 tiocm |= ((sigvalue & SG_RTS) ? TIOCM_RTS : 0);
3342 return(tiocm);
3343 }
3344
3345 /*****************************************************************************/
3346
3347 /*
3348 * All panels and ports actually attached have been worked out. All
3349 * we need to do here is set up the appropriate per port data structures.
3350 */
3351
3352 static inline int stli_initports(stlibrd_t *brdp)
3353 {
3354 stliport_t *portp;
3355 int i, panelnr, panelport;
3356
3357 #if DEBUG
3358 printk("stli_initports(brdp=%x)\n", (int) brdp);
3359 #endif
3360
3361 for (i = 0, panelnr = 0, panelport = 0; (i < brdp->nrports); i++) {
3362 portp = (stliport_t *) stli_memalloc(sizeof(stliport_t));
3363 if (portp == (stliport_t *) NULL) {
3364 printk("STALLION: failed to allocate port structure\n");
3365 continue;
3366 }
3367
3368 memset(portp, 0, sizeof(stliport_t));
3369 portp->magic = STLI_PORTMAGIC;
3370 portp->portnr = i;
3371 portp->brdnr = brdp->brdnr;
3372 portp->panelnr = panelnr;
3373 portp->baud_base = STL_BAUDBASE;
3374 portp->close_delay = STL_CLOSEDELAY;
3375 portp->closing_wait = 30 * HZ;
3376 portp->tqhangup.routine = stli_dohangup;
3377 portp->tqhangup.data = portp;
3378 init_waitqueue_head(&portp->open_wait);
3379 init_waitqueue_head(&portp->close_wait);
3380 init_waitqueue_head(&portp->raw_wait);
3381 portp->normaltermios = stli_deftermios;
3382 portp->callouttermios = stli_deftermios;
3383 panelport++;
3384 if (panelport >= brdp->panels[panelnr]) {
3385 panelport = 0;
3386 panelnr++;
3387 }
3388 brdp->ports[i] = portp;
3389 }
3390
3391 return(0);
3392 }
3393
3394 /*****************************************************************************/
3395
3396 /*
3397 * All the following routines are board specific hardware operations.
3398 */
3399
3400 static void stli_ecpinit(stlibrd_t *brdp)
3401 {
3402 unsigned long memconf;
3403
3404 #if DEBUG
3405 printk("stli_ecpinit(brdp=%d)\n", (int) brdp);
3406 #endif
3407
3408 outb(ECP_ATSTOP, (brdp->iobase + ECP_ATCONFR));
3409 udelay(10);
3410 outb(ECP_ATDISABLE, (brdp->iobase + ECP_ATCONFR));
3411 udelay(100);
3412
3413 memconf = (brdp->memaddr & ECP_ATADDRMASK) >> ECP_ATADDRSHFT;
3414 outb(memconf, (brdp->iobase + ECP_ATMEMAR));
3415 }
3416
3417 /*****************************************************************************/
3418
3419 static void stli_ecpenable(stlibrd_t *brdp)
3420 {
3421 #if DEBUG
3422 printk("stli_ecpenable(brdp=%x)\n", (int) brdp);
3423 #endif
3424 outb(ECP_ATENABLE, (brdp->iobase + ECP_ATCONFR));
3425 }
3426
3427 /*****************************************************************************/
3428
3429 static void stli_ecpdisable(stlibrd_t *brdp)
3430 {
3431 #if DEBUG
3432 printk("stli_ecpdisable(brdp=%x)\n", (int) brdp);
3433 #endif
3434 outb(ECP_ATDISABLE, (brdp->iobase + ECP_ATCONFR));
3435 }
3436
3437 /*****************************************************************************/
3438
3439 static char *stli_ecpgetmemptr(stlibrd_t *brdp, unsigned long offset, int line)
3440 {
3441 void *ptr;
3442 unsigned char val;
3443
3444 #if DEBUG
3445 printk("stli_ecpgetmemptr(brdp=%x,offset=%x)\n", (int) brdp,
3446 (int) offset);
3447 #endif
3448
3449 if (offset > brdp->memsize) {
3450 printk("STALLION: shared memory pointer=%x out of range at "
3451 "line=%d(%d), brd=%d\n", (int) offset, line,
3452 __LINE__, brdp->brdnr);
3453 ptr = 0;
3454 val = 0;
3455 } else {
3456 ptr = brdp->membase + (offset % ECP_ATPAGESIZE);
3457 val = (unsigned char) (offset / ECP_ATPAGESIZE);
3458 }
3459 outb(val, (brdp->iobase + ECP_ATMEMPR));
3460 return(ptr);
3461 }
3462
3463 /*****************************************************************************/
3464
3465 static void stli_ecpreset(stlibrd_t *brdp)
3466 {
3467 #if DEBUG
3468 printk("stli_ecpreset(brdp=%x)\n", (int) brdp);
3469 #endif
3470
3471 outb(ECP_ATSTOP, (brdp->iobase + ECP_ATCONFR));
3472 udelay(10);
3473 outb(ECP_ATDISABLE, (brdp->iobase + ECP_ATCONFR));
3474 udelay(500);
3475 }
3476
3477 /*****************************************************************************/
3478
3479 static void stli_ecpintr(stlibrd_t *brdp)
3480 {
3481 #if DEBUG
3482 printk("stli_ecpintr(brdp=%x)\n", (int) brdp);
3483 #endif
3484 outb(0x1, brdp->iobase);
3485 }
3486
3487 /*****************************************************************************/
3488
3489 /*
3490 * The following set of functions act on ECP EISA boards.
3491 */
3492
3493 static void stli_ecpeiinit(stlibrd_t *brdp)
3494 {
3495 unsigned long memconf;
3496
3497 #if DEBUG
3498 printk("stli_ecpeiinit(brdp=%x)\n", (int) brdp);
3499 #endif
3500
3501 outb(0x1, (brdp->iobase + ECP_EIBRDENAB));
3502 outb(ECP_EISTOP, (brdp->iobase + ECP_EICONFR));
3503 udelay(10);
3504 outb(ECP_EIDISABLE, (brdp->iobase + ECP_EICONFR));
3505 udelay(500);
3506
3507 memconf = (brdp->memaddr & ECP_EIADDRMASKL) >> ECP_EIADDRSHFTL;
3508 outb(memconf, (brdp->iobase + ECP_EIMEMARL));
3509 memconf = (brdp->memaddr & ECP_EIADDRMASKH) >> ECP_EIADDRSHFTH;
3510 outb(memconf, (brdp->iobase + ECP_EIMEMARH));
3511 }
3512
3513 /*****************************************************************************/
3514
3515 static void stli_ecpeienable(stlibrd_t *brdp)
3516 {
3517 outb(ECP_EIENABLE, (brdp->iobase + ECP_EICONFR));
3518 }
3519
3520 /*****************************************************************************/
3521
3522 static void stli_ecpeidisable(stlibrd_t *brdp)
3523 {
3524 outb(ECP_EIDISABLE, (brdp->iobase + ECP_EICONFR));
3525 }
3526
3527 /*****************************************************************************/
3528
3529 static char *stli_ecpeigetmemptr(stlibrd_t *brdp, unsigned long offset, int line)
3530 {
3531 void *ptr;
3532 unsigned char val;
3533
3534 #if DEBUG
3535 printk("stli_ecpeigetmemptr(brdp=%x,offset=%x,line=%d)\n",
3536 (int) brdp, (int) offset, line);
3537 #endif
3538
3539 if (offset > brdp->memsize) {
3540 printk("STALLION: shared memory pointer=%x out of range at "
3541 "line=%d(%d), brd=%d\n", (int) offset, line,
3542 __LINE__, brdp->brdnr);
3543 ptr = 0;
3544 val = 0;
3545 } else {
3546 ptr = brdp->membase + (offset % ECP_EIPAGESIZE);
3547 if (offset < ECP_EIPAGESIZE)
3548 val = ECP_EIENABLE;
3549 else
3550 val = ECP_EIENABLE | 0x40;
3551 }
3552 outb(val, (brdp->iobase + ECP_EICONFR));
3553 return(ptr);
3554 }
3555
3556 /*****************************************************************************/
3557
3558 static void stli_ecpeireset(stlibrd_t *brdp)
3559 {
3560 outb(ECP_EISTOP, (brdp->iobase + ECP_EICONFR));
3561 udelay(10);
3562 outb(ECP_EIDISABLE, (brdp->iobase + ECP_EICONFR));
3563 udelay(500);
3564 }
3565
3566 /*****************************************************************************/
3567
3568 /*
3569 * The following set of functions act on ECP MCA boards.
3570 */
3571
3572 static void stli_ecpmcenable(stlibrd_t *brdp)
3573 {
3574 outb(ECP_MCENABLE, (brdp->iobase + ECP_MCCONFR));
3575 }
3576
3577 /*****************************************************************************/
3578
3579 static void stli_ecpmcdisable(stlibrd_t *brdp)
3580 {
3581 outb(ECP_MCDISABLE, (brdp->iobase + ECP_MCCONFR));
3582 }
3583
3584 /*****************************************************************************/
3585
3586 static char *stli_ecpmcgetmemptr(stlibrd_t *brdp, unsigned long offset, int line)
3587 {
3588 void *ptr;
3589 unsigned char val;
3590
3591 if (offset > brdp->memsize) {
3592 printk("STALLION: shared memory pointer=%x out of range at "
3593 "line=%d(%d), brd=%d\n", (int) offset, line,
3594 __LINE__, brdp->brdnr);
3595 ptr = 0;
3596 val = 0;
3597 } else {
3598 ptr = brdp->membase + (offset % ECP_MCPAGESIZE);
3599 val = ((unsigned char) (offset / ECP_MCPAGESIZE)) | ECP_MCENABLE;
3600 }
3601 outb(val, (brdp->iobase + ECP_MCCONFR));
3602 return(ptr);
3603 }
3604
3605 /*****************************************************************************/
3606
3607 static void stli_ecpmcreset(stlibrd_t *brdp)
3608 {
3609 outb(ECP_MCSTOP, (brdp->iobase + ECP_MCCONFR));
3610 udelay(10);
3611 outb(ECP_MCDISABLE, (brdp->iobase + ECP_MCCONFR));
3612 udelay(500);
3613 }
3614
3615 /*****************************************************************************/
3616
3617 /*
3618 * The following set of functions act on ECP PCI boards.
3619 */
3620
3621 static void stli_ecppciinit(stlibrd_t *brdp)
3622 {
3623 #if DEBUG
3624 printk("stli_ecppciinit(brdp=%x)\n", (int) brdp);
3625 #endif
3626
3627 outb(ECP_PCISTOP, (brdp->iobase + ECP_PCICONFR));
3628 udelay(10);
3629 outb(0, (brdp->iobase + ECP_PCICONFR));
3630 udelay(500);
3631 }
3632
3633 /*****************************************************************************/
3634
3635 static char *stli_ecppcigetmemptr(stlibrd_t *brdp, unsigned long offset, int line)
3636 {
3637 void *ptr;
3638 unsigned char val;
3639
3640 #if DEBUG
3641 printk("stli_ecppcigetmemptr(brdp=%x,offset=%x,line=%d)\n",
3642 (int) brdp, (int) offset, line);
3643 #endif
3644
3645 if (offset > brdp->memsize) {
3646 printk("STALLION: shared memory pointer=%x out of range at "
3647 "line=%d(%d), board=%d\n", (int) offset, line,
3648 __LINE__, brdp->brdnr);
3649 ptr = 0;
3650 val = 0;
3651 } else {
3652 ptr = brdp->membase + (offset % ECP_PCIPAGESIZE);
3653 val = (offset / ECP_PCIPAGESIZE) << 1;
3654 }
3655 outb(val, (brdp->iobase + ECP_PCICONFR));
3656 return(ptr);
3657 }
3658
3659 /*****************************************************************************/
3660
3661 static void stli_ecppcireset(stlibrd_t *brdp)
3662 {
3663 outb(ECP_PCISTOP, (brdp->iobase + ECP_PCICONFR));
3664 udelay(10);
3665 outb(0, (brdp->iobase + ECP_PCICONFR));
3666 udelay(500);
3667 }
3668
3669 /*****************************************************************************/
3670
3671 /*
3672 * The following routines act on ONboards.
3673 */
3674
3675 static void stli_onbinit(stlibrd_t *brdp)
3676 {
3677 unsigned long memconf;
3678
3679 #if DEBUG
3680 printk("stli_onbinit(brdp=%d)\n", (int) brdp);
3681 #endif
3682
3683 outb(ONB_ATSTOP, (brdp->iobase + ONB_ATCONFR));
3684 udelay(10);
3685 outb(ONB_ATDISABLE, (brdp->iobase + ONB_ATCONFR));
3686 mdelay(1000);
3687
3688 memconf = (brdp->memaddr & ONB_ATADDRMASK) >> ONB_ATADDRSHFT;
3689 outb(memconf, (brdp->iobase + ONB_ATMEMAR));
3690 outb(0x1, brdp->iobase);
3691 mdelay(1);
3692 }
3693
3694 /*****************************************************************************/
3695
3696 static void stli_onbenable(stlibrd_t *brdp)
3697 {
3698 #if DEBUG
3699 printk("stli_onbenable(brdp=%x)\n", (int) brdp);
3700 #endif
3701 outb((brdp->enabval | ONB_ATENABLE), (brdp->iobase + ONB_ATCONFR));
3702 }
3703
3704 /*****************************************************************************/
3705
3706 static void stli_onbdisable(stlibrd_t *brdp)
3707 {
3708 #if DEBUG
3709 printk("stli_onbdisable(brdp=%x)\n", (int) brdp);
3710 #endif
3711 outb((brdp->enabval | ONB_ATDISABLE), (brdp->iobase + ONB_ATCONFR));
3712 }
3713
3714 /*****************************************************************************/
3715
3716 static char *stli_onbgetmemptr(stlibrd_t *brdp, unsigned long offset, int line)
3717 {
3718 void *ptr;
3719
3720 #if DEBUG
3721 printk("stli_onbgetmemptr(brdp=%x,offset=%x)\n", (int) brdp,
3722 (int) offset);
3723 #endif
3724
3725 if (offset > brdp->memsize) {
3726 printk("STALLION: shared memory pointer=%x out of range at "
3727 "line=%d(%d), brd=%d\n", (int) offset, line,
3728 __LINE__, brdp->brdnr);
3729 ptr = 0;
3730 } else {
3731 ptr = brdp->membase + (offset % ONB_ATPAGESIZE);
3732 }
3733 return(ptr);
3734 }
3735
3736 /*****************************************************************************/
3737
3738 static void stli_onbreset(stlibrd_t *brdp)
3739 {
3740
3741 #if DEBUG
3742 printk("stli_onbreset(brdp=%x)\n", (int) brdp);
3743 #endif
3744
3745 outb(ONB_ATSTOP, (brdp->iobase + ONB_ATCONFR));
3746 udelay(10);
3747 outb(ONB_ATDISABLE, (brdp->iobase + ONB_ATCONFR));
3748 mdelay(1000);
3749 }
3750
3751 /*****************************************************************************/
3752
3753 /*
3754 * The following routines act on ONboard EISA.
3755 */
3756
3757 static void stli_onbeinit(stlibrd_t *brdp)
3758 {
3759 unsigned long memconf;
3760
3761 #if DEBUG
3762 printk("stli_onbeinit(brdp=%d)\n", (int) brdp);
3763 #endif
3764
3765 outb(0x1, (brdp->iobase + ONB_EIBRDENAB));
3766 outb(ONB_EISTOP, (brdp->iobase + ONB_EICONFR));
3767 udelay(10);
3768 outb(ONB_EIDISABLE, (brdp->iobase + ONB_EICONFR));
3769 mdelay(1000);
3770
3771 memconf = (brdp->memaddr & ONB_EIADDRMASKL) >> ONB_EIADDRSHFTL;
3772 outb(memconf, (brdp->iobase + ONB_EIMEMARL));
3773 memconf = (brdp->memaddr & ONB_EIADDRMASKH) >> ONB_EIADDRSHFTH;
3774 outb(memconf, (brdp->iobase + ONB_EIMEMARH));
3775 outb(0x1, brdp->iobase);
3776 mdelay(1);
3777 }
3778
3779 /*****************************************************************************/
3780
3781 static void stli_onbeenable(stlibrd_t *brdp)
3782 {
3783 #if DEBUG
3784 printk("stli_onbeenable(brdp=%x)\n", (int) brdp);
3785 #endif
3786 outb(ONB_EIENABLE, (brdp->iobase + ONB_EICONFR));
3787 }
3788
3789 /*****************************************************************************/
3790
3791 static void stli_onbedisable(stlibrd_t *brdp)
3792 {
3793 #if DEBUG
3794 printk("stli_onbedisable(brdp=%x)\n", (int) brdp);
3795 #endif
3796 outb(ONB_EIDISABLE, (brdp->iobase + ONB_EICONFR));
3797 }
3798
3799 /*****************************************************************************/
3800
3801 static char *stli_onbegetmemptr(stlibrd_t *brdp, unsigned long offset, int line)
3802 {
3803 void *ptr;
3804 unsigned char val;
3805
3806 #if DEBUG
3807 printk("stli_onbegetmemptr(brdp=%x,offset=%x,line=%d)\n",
3808 (int) brdp, (int) offset, line);
3809 #endif
3810
3811 if (offset > brdp->memsize) {
3812 printk("STALLION: shared memory pointer=%x out of range at "
3813 "line=%d(%d), brd=%d\n", (int) offset, line,
3814 __LINE__, brdp->brdnr);
3815 ptr = 0;
3816 val = 0;
3817 } else {
3818 ptr = brdp->membase + (offset % ONB_EIPAGESIZE);
3819 if (offset < ONB_EIPAGESIZE)
3820 val = ONB_EIENABLE;
3821 else
3822 val = ONB_EIENABLE | 0x40;
3823 }
3824 outb(val, (brdp->iobase + ONB_EICONFR));
3825 return(ptr);
3826 }
3827
3828 /*****************************************************************************/
3829
3830 static void stli_onbereset(stlibrd_t *brdp)
3831 {
3832
3833 #if DEBUG
3834 printk("stli_onbereset(brdp=%x)\n", (int) brdp);
3835 #endif
3836
3837 outb(ONB_EISTOP, (brdp->iobase + ONB_EICONFR));
3838 udelay(10);
3839 outb(ONB_EIDISABLE, (brdp->iobase + ONB_EICONFR));
3840 mdelay(1000);
3841 }
3842
3843 /*****************************************************************************/
3844
3845 /*
3846 * The following routines act on Brumby boards.
3847 */
3848
3849 static void stli_bbyinit(stlibrd_t *brdp)
3850 {
3851
3852 #if DEBUG
3853 printk("stli_bbyinit(brdp=%d)\n", (int) brdp);
3854 #endif
3855
3856 outb(BBY_ATSTOP, (brdp->iobase + BBY_ATCONFR));
3857 udelay(10);
3858 outb(0, (brdp->iobase + BBY_ATCONFR));
3859 mdelay(1000);
3860 outb(0x1, brdp->iobase);
3861 mdelay(1);
3862 }
3863
3864 /*****************************************************************************/
3865
3866 static char *stli_bbygetmemptr(stlibrd_t *brdp, unsigned long offset, int line)
3867 {
3868 void *ptr;
3869 unsigned char val;
3870
3871 #if DEBUG
3872 printk("stli_bbygetmemptr(brdp=%x,offset=%x)\n", (int) brdp,
3873 (int) offset);
3874 #endif
3875
3876 if (offset > brdp->memsize) {
3877 printk("STALLION: shared memory pointer=%x out of range at "
3878 "line=%d(%d), brd=%d\n", (int) offset, line,
3879 __LINE__, brdp->brdnr);
3880 ptr = 0;
3881 val = 0;
3882 } else {
3883 ptr = brdp->membase + (offset % BBY_PAGESIZE);
3884 val = (unsigned char) (offset / BBY_PAGESIZE);
3885 }
3886 outb(val, (brdp->iobase + BBY_ATCONFR));
3887 return(ptr);
3888 }
3889
3890 /*****************************************************************************/
3891
3892 static void stli_bbyreset(stlibrd_t *brdp)
3893 {
3894
3895 #if DEBUG
3896 printk("stli_bbyreset(brdp=%x)\n", (int) brdp);
3897 #endif
3898
3899 outb(BBY_ATSTOP, (brdp->iobase + BBY_ATCONFR));
3900 udelay(10);
3901 outb(0, (brdp->iobase + BBY_ATCONFR));
3902 mdelay(1000);
3903 }
3904
3905 /*****************************************************************************/
3906
3907 /*
3908 * The following routines act on original old Stallion boards.
3909 */
3910
3911 static void stli_stalinit(stlibrd_t *brdp)
3912 {
3913
3914 #if DEBUG
3915 printk("stli_stalinit(brdp=%d)\n", (int) brdp);
3916 #endif
3917
3918 outb(0x1, brdp->iobase);
3919 mdelay(1000);
3920 }
3921
3922 /*****************************************************************************/
3923
3924 static char *stli_stalgetmemptr(stlibrd_t *brdp, unsigned long offset, int line)
3925 {
3926 void *ptr;
3927
3928 #if DEBUG
3929 printk("stli_stalgetmemptr(brdp=%x,offset=%x)\n", (int) brdp,
3930 (int) offset);
3931 #endif
3932
3933 if (offset > brdp->memsize) {
3934 printk("STALLION: shared memory pointer=%x out of range at "
3935 "line=%d(%d), brd=%d\n", (int) offset, line,
3936 __LINE__, brdp->brdnr);
3937 ptr = 0;
3938 } else {
3939 ptr = brdp->membase + (offset % STAL_PAGESIZE);
3940 }
3941 return(ptr);
3942 }
3943
3944 /*****************************************************************************/
3945
3946 static void stli_stalreset(stlibrd_t *brdp)
3947 {
3948 volatile unsigned long *vecp;
3949
3950 #if DEBUG
3951 printk("stli_stalreset(brdp=%x)\n", (int) brdp);
3952 #endif
3953
3954 vecp = (volatile unsigned long *) (brdp->membase + 0x30);
3955 *vecp = 0xffff0000;
3956 outb(0, brdp->iobase);
3957 mdelay(1000);
3958 }
3959
3960 /*****************************************************************************/
3961
3962 /*
3963 * Try to find an ECP board and initialize it. This handles only ECP
3964 * board types.
3965 */
3966
3967 static inline int stli_initecp(stlibrd_t *brdp)
3968 {
3969 cdkecpsig_t sig;
3970 cdkecpsig_t *sigsp;
3971 unsigned int status, nxtid;
3972 char *name;
3973 int panelnr, nrports;
3974
3975 #if DEBUG
3976 printk("stli_initecp(brdp=%x)\n", (int) brdp);
3977 #endif
3978
3979 /*
3980 * Do a basic sanity check on the IO and memory addresses.
3981 */
3982 if ((brdp->iobase == 0) || (brdp->memaddr == 0))
3983 return(-ENODEV);
3984
3985 brdp->iosize = ECP_IOSIZE;
3986 if (check_region(brdp->iobase, brdp->iosize))
3987 printk("STALLION: Warning, board %d I/O address %x conflicts "
3988 "with another device\n", brdp->brdnr, brdp->iobase);
3989
3990 /*
3991 * Based on the specific board type setup the common vars to access
3992 * and enable shared memory. Set all board specific information now
3993 * as well.
3994 */
3995 switch (brdp->brdtype) {
3996 case BRD_ECP:
3997 brdp->membase = (void *) brdp->memaddr;
3998 brdp->memsize = ECP_MEMSIZE;
3999 brdp->pagesize = ECP_ATPAGESIZE;
4000 brdp->init = stli_ecpinit;
4001 brdp->enable = stli_ecpenable;
4002 brdp->reenable = stli_ecpenable;
4003 brdp->disable = stli_ecpdisable;
4004 brdp->getmemptr = stli_ecpgetmemptr;
4005 brdp->intr = stli_ecpintr;
4006 brdp->reset = stli_ecpreset;
4007 name = "serial(EC8/64)";
4008 break;
4009
4010 case BRD_ECPE:
4011 brdp->membase = (void *) brdp->memaddr;
4012 brdp->memsize = ECP_MEMSIZE;
4013 brdp->pagesize = ECP_EIPAGESIZE;
4014 brdp->init = stli_ecpeiinit;
4015 brdp->enable = stli_ecpeienable;
4016 brdp->reenable = stli_ecpeienable;
4017 brdp->disable = stli_ecpeidisable;
4018 brdp->getmemptr = stli_ecpeigetmemptr;
4019 brdp->intr = stli_ecpintr;
4020 brdp->reset = stli_ecpeireset;
4021 name = "serial(EC8/64-EI)";
4022 break;
4023
4024 case BRD_ECPMC:
4025 brdp->membase = (void *) brdp->memaddr;
4026 brdp->memsize = ECP_MEMSIZE;
4027 brdp->pagesize = ECP_MCPAGESIZE;
4028 brdp->init = NULL;
4029 brdp->enable = stli_ecpmcenable;
4030 brdp->reenable = stli_ecpmcenable;
4031 brdp->disable = stli_ecpmcdisable;
4032 brdp->getmemptr = stli_ecpmcgetmemptr;
4033 brdp->intr = stli_ecpintr;
4034 brdp->reset = stli_ecpmcreset;
4035 name = "serial(EC8/64-MCA)";
4036 break;
4037
4038 case BRD_ECPPCI:
4039 brdp->membase = (void *) brdp->memaddr;
4040 brdp->memsize = ECP_PCIMEMSIZE;
4041 brdp->pagesize = ECP_PCIPAGESIZE;
4042 brdp->init = stli_ecppciinit;
4043 brdp->enable = NULL;
4044 brdp->reenable = NULL;
4045 brdp->disable = NULL;
4046 brdp->getmemptr = stli_ecppcigetmemptr;
4047 brdp->intr = stli_ecpintr;
4048 brdp->reset = stli_ecppcireset;
4049 name = "serial(EC/RA-PCI)";
4050 break;
4051
4052 default:
4053 return(-EINVAL);
4054 }
4055
4056 /*
4057 * The per-board operations structure is all set up, so now let's go
4058 * and get the board operational. Firstly initialize board configuration
4059 * registers. Set the memory mapping info so we can get at the boards
4060 * shared memory.
4061 */
4062 EBRDINIT(brdp);
4063
4064 brdp->membase = ioremap(brdp->memaddr, brdp->memsize);
4065 if (brdp->membase == (void *) NULL)
4066 return(-ENOMEM);
4067
4068 /*
4069 * Now that all specific code is set up, enable the shared memory and
4070 * look for the a signature area that will tell us exactly what board
4071 * this is, and what it is connected to it.
4072 */
4073 EBRDENABLE(brdp);
4074 sigsp = (cdkecpsig_t *) EBRDGETMEMPTR(brdp, CDK_SIGADDR);
4075 memcpy(&sig, sigsp, sizeof(cdkecpsig_t));
4076 EBRDDISABLE(brdp);
4077
4078 #if 0
4079 printk("%s(%d): sig-> magic=%x rom=%x panel=%x,%x,%x,%x,%x,%x,%x,%x\n",
4080 __FILE__, __LINE__, (int) sig.magic, sig.romver, sig.panelid[0],
4081 (int) sig.panelid[1], (int) sig.panelid[2],
4082 (int) sig.panelid[3], (int) sig.panelid[4],
4083 (int) sig.panelid[5], (int) sig.panelid[6],
4084 (int) sig.panelid[7]);
4085 #endif
4086
4087 if (sig.magic != ECP_MAGIC)
4088 return(-ENODEV);
4089
4090 /*
4091 * Scan through the signature looking at the panels connected to the
4092 * board. Calculate the total number of ports as we go.
4093 */
4094 for (panelnr = 0, nxtid = 0; (panelnr < STL_MAXPANELS); panelnr++) {
4095 status = sig.panelid[nxtid];
4096 if ((status & ECH_PNLIDMASK) != nxtid)
4097 break;
4098
4099 brdp->panelids[panelnr] = status;
4100 nrports = (status & ECH_PNL16PORT) ? 16 : 8;
4101 if ((nrports == 16) && ((status & ECH_PNLXPID) == 0))
4102 nxtid++;
4103 brdp->panels[panelnr] = nrports;
4104 brdp->nrports += nrports;
4105 nxtid++;
4106 brdp->nrpanels++;
4107 }
4108
4109 request_region(brdp->iobase, brdp->iosize, name);
4110 brdp->state |= BST_FOUND;
4111 return(0);
4112 }
4113
4114 /*****************************************************************************/
4115
4116 /*
4117 * Try to find an ONboard, Brumby or Stallion board and initialize it.
4118 * This handles only these board types.
4119 */
4120
4121 static inline int stli_initonb(stlibrd_t *brdp)
4122 {
4123 cdkonbsig_t sig;
4124 cdkonbsig_t *sigsp;
4125 char *name;
4126 int i;
4127
4128 #if DEBUG
4129 printk("stli_initonb(brdp=%x)\n", (int) brdp);
4130 #endif
4131
4132 /*
4133 * Do a basic sanity check on the IO and memory addresses.
4134 */
4135 if ((brdp->iobase == 0) || (brdp->memaddr == 0))
4136 return(-ENODEV);
4137
4138 brdp->iosize = ONB_IOSIZE;
4139 if (check_region(brdp->iobase, brdp->iosize))
4140 printk("STALLION: Warning, board %d I/O address %x conflicts "
4141 "with another device\n", brdp->brdnr, brdp->iobase);
4142
4143 /*
4144 * Based on the specific board type setup the common vars to access
4145 * and enable shared memory. Set all board specific information now
4146 * as well.
4147 */
4148 switch (brdp->brdtype) {
4149 case BRD_ONBOARD:
4150 case BRD_ONBOARD32:
4151 case BRD_ONBOARD2:
4152 case BRD_ONBOARD2_32:
4153 case BRD_ONBOARDRS:
4154 brdp->membase = (void *) brdp->memaddr;
4155 brdp->memsize = ONB_MEMSIZE;
4156 brdp->pagesize = ONB_ATPAGESIZE;
4157 brdp->init = stli_onbinit;
4158 brdp->enable = stli_onbenable;
4159 brdp->reenable = stli_onbenable;
4160 brdp->disable = stli_onbdisable;
4161 brdp->getmemptr = stli_onbgetmemptr;
4162 brdp->intr = stli_ecpintr;
4163 brdp->reset = stli_onbreset;
4164 if (brdp->memaddr > 0x100000)
4165 brdp->enabval = ONB_MEMENABHI;
4166 else
4167 brdp->enabval = ONB_MEMENABLO;
4168 name = "serial(ONBoard)";
4169 break;
4170
4171 case BRD_ONBOARDE:
4172 brdp->membase = (void *) brdp->memaddr;
4173 brdp->memsize = ONB_EIMEMSIZE;
4174 brdp->pagesize = ONB_EIPAGESIZE;
4175 brdp->init = stli_onbeinit;
4176 brdp->enable = stli_onbeenable;
4177 brdp->reenable = stli_onbeenable;
4178 brdp->disable = stli_onbedisable;
4179 brdp->getmemptr = stli_onbegetmemptr;
4180 brdp->intr = stli_ecpintr;
4181 brdp->reset = stli_onbereset;
4182 name = "serial(ONBoard/E)";
4183 break;
4184
4185 case BRD_BRUMBY4:
4186 case BRD_BRUMBY8:
4187 case BRD_BRUMBY16:
4188 brdp->membase = (void *) brdp->memaddr;
4189 brdp->memsize = BBY_MEMSIZE;
4190 brdp->pagesize = BBY_PAGESIZE;
4191 brdp->init = stli_bbyinit;
4192 brdp->enable = NULL;
4193 brdp->reenable = NULL;
4194 brdp->disable = NULL;
4195 brdp->getmemptr = stli_bbygetmemptr;
4196 brdp->intr = stli_ecpintr;
4197 brdp->reset = stli_bbyreset;
4198 name = "serial(Brumby)";
4199 break;
4200
4201 case BRD_STALLION:
4202 brdp->membase = (void *) brdp->memaddr;
4203 brdp->memsize = STAL_MEMSIZE;
4204 brdp->pagesize = STAL_PAGESIZE;
4205 brdp->init = stli_stalinit;
4206 brdp->enable = NULL;
4207 brdp->reenable = NULL;
4208 brdp->disable = NULL;
4209 brdp->getmemptr = stli_stalgetmemptr;
4210 brdp->intr = stli_ecpintr;
4211 brdp->reset = stli_stalreset;
4212 name = "serial(Stallion)";
4213 break;
4214
4215 default:
4216 return(-EINVAL);
4217 }
4218
4219 /*
4220 * The per-board operations structure is all set up, so now let's go
4221 * and get the board operational. Firstly initialize board configuration
4222 * registers. Set the memory mapping info so we can get at the boards
4223 * shared memory.
4224 */
4225 EBRDINIT(brdp);
4226
4227 brdp->membase = ioremap(brdp->memaddr, brdp->memsize);
4228 if (brdp->membase == (void *) NULL)
4229 return(-ENOMEM);
4230
4231 /*
4232 * Now that all specific code is set up, enable the shared memory and
4233 * look for the a signature area that will tell us exactly what board
4234 * this is, and how many ports.
4235 */
4236 EBRDENABLE(brdp);
4237 sigsp = (cdkonbsig_t *) EBRDGETMEMPTR(brdp, CDK_SIGADDR);
4238 memcpy(&sig, sigsp, sizeof(cdkonbsig_t));
4239 EBRDDISABLE(brdp);
4240
4241 #if 0
4242 printk("%s(%d): sig-> magic=%x:%x:%x:%x romver=%x amask=%x:%x:%x\n",
4243 __FILE__, __LINE__, sig.magic0, sig.magic1, sig.magic2,
4244 sig.magic3, sig.romver, sig.amask0, sig.amask1, sig.amask2);
4245 #endif
4246
4247 if ((sig.magic0 != ONB_MAGIC0) || (sig.magic1 != ONB_MAGIC1) ||
4248 (sig.magic2 != ONB_MAGIC2) || (sig.magic3 != ONB_MAGIC3))
4249 return(-ENODEV);
4250
4251 /*
4252 * Scan through the signature alive mask and calculate how many ports
4253 * there are on this board.
4254 */
4255 brdp->nrpanels = 1;
4256 if (sig.amask1) {
4257 brdp->nrports = 32;
4258 } else {
4259 for (i = 0; (i < 16); i++) {
4260 if (((sig.amask0 << i) & 0x8000) == 0)
4261 break;
4262 }
4263 brdp->nrports = i;
4264 }
4265 brdp->panels[0] = brdp->nrports;
4266
4267 request_region(brdp->iobase, brdp->iosize, name);
4268 brdp->state |= BST_FOUND;
4269 return(0);
4270 }
4271
4272 /*****************************************************************************/
4273
4274 /*
4275 * Start up a running board. This routine is only called after the
4276 * code has been down loaded to the board and is operational. It will
4277 * read in the memory map, and get the show on the road...
4278 */
4279
4280 static int stli_startbrd(stlibrd_t *brdp)
4281 {
4282 volatile cdkhdr_t *hdrp;
4283 volatile cdkmem_t *memp;
4284 volatile cdkasy_t *ap;
4285 unsigned long flags;
4286 stliport_t *portp;
4287 int portnr, nrdevs, i, rc;
4288
4289 #if DEBUG
4290 printk("stli_startbrd(brdp=%x)\n", (int) brdp);
4291 #endif
4292
4293 rc = 0;
4294
4295 save_flags(flags);
4296 cli();
4297 EBRDENABLE(brdp);
4298 hdrp = (volatile cdkhdr_t *) EBRDGETMEMPTR(brdp, CDK_CDKADDR);
4299 nrdevs = hdrp->nrdevs;
4300
4301 #if 0
4302 printk("%s(%d): CDK version %d.%d.%d --> "
4303 "nrdevs=%d memp=%x hostp=%x slavep=%x\n",
4304 __FILE__, __LINE__, hdrp->ver_release, hdrp->ver_modification,
4305 hdrp->ver_fix, nrdevs, (int) hdrp->memp, (int) hdrp->hostp,
4306 (int) hdrp->slavep);
4307 #endif
4308
4309 if (nrdevs < (brdp->nrports + 1)) {
4310 printk("STALLION: slave failed to allocate memory for all "
4311 "devices, devices=%d\n", nrdevs);
4312 brdp->nrports = nrdevs - 1;
4313 }
4314 brdp->nrdevs = nrdevs;
4315 brdp->hostoffset = hdrp->hostp - CDK_CDKADDR;
4316 brdp->slaveoffset = hdrp->slavep - CDK_CDKADDR;
4317 brdp->bitsize = (nrdevs + 7) / 8;
4318 memp = (volatile cdkmem_t *) hdrp->memp;
4319 if (((unsigned long) memp) > brdp->memsize) {
4320 printk("STALLION: corrupted shared memory region?\n");
4321 rc = -EIO;
4322 goto stli_donestartup;
4323 }
4324 memp = (volatile cdkmem_t *) EBRDGETMEMPTR(brdp, (unsigned long) memp);
4325 if (memp->dtype != TYP_ASYNCTRL) {
4326 printk("STALLION: no slave control device found\n");
4327 goto stli_donestartup;
4328 }
4329 memp++;
4330
4331 /*
4332 * Cycle through memory allocation of each port. We are guaranteed to
4333 * have all ports inside the first page of slave window, so no need to
4334 * change pages while reading memory map.
4335 */
4336 for (i = 1, portnr = 0; (i < nrdevs); i++, portnr++, memp++) {
4337 if (memp->dtype != TYP_ASYNC)
4338 break;
4339 portp = brdp->ports[portnr];
4340 if (portp == (stliport_t *) NULL)
4341 break;
4342 portp->devnr = i;
4343 portp->addr = memp->offset;
4344 portp->reqbit = (unsigned char) (0x1 << (i * 8 / nrdevs));
4345 portp->portidx = (unsigned char) (i / 8);
4346 portp->portbit = (unsigned char) (0x1 << (i % 8));
4347 }
4348
4349 hdrp->slavereq = 0xff;
4350
4351 /*
4352 * For each port setup a local copy of the RX and TX buffer offsets
4353 * and sizes. We do this separate from the above, because we need to
4354 * move the shared memory page...
4355 */
4356 for (i = 1, portnr = 0; (i < nrdevs); i++, portnr++) {
4357 portp = brdp->ports[portnr];
4358 if (portp == (stliport_t *) NULL)
4359 break;
4360 if (portp->addr == 0)
4361 break;
4362 ap = (volatile cdkasy_t *) EBRDGETMEMPTR(brdp, portp->addr);
4363 if (ap != (volatile cdkasy_t *) NULL) {
4364 portp->rxsize = ap->rxq.size;
4365 portp->txsize = ap->txq.size;
4366 portp->rxoffset = ap->rxq.offset;
4367 portp->txoffset = ap->txq.offset;
4368 }
4369 }
4370
4371 stli_donestartup:
4372 EBRDDISABLE(brdp);
4373 restore_flags(flags);
4374
4375 if (rc == 0)
4376 brdp->state |= BST_STARTED;
4377
4378 if (! stli_timeron) {
4379 stli_timeron++;
4380 stli_timerlist.expires = STLI_TIMEOUT;
4381 add_timer(&stli_timerlist);
4382 }
4383
4384 return(rc);
4385 }
4386
4387 /*****************************************************************************/
4388
4389 /*
4390 * Probe and initialize the specified board.
4391 */
4392
4393 static int __init stli_brdinit(stlibrd_t *brdp)
4394 {
4395 #if DEBUG
4396 printk("stli_brdinit(brdp=%x)\n", (int) brdp);
4397 #endif
4398
4399 stli_brds[brdp->brdnr] = brdp;
4400
4401 switch (brdp->brdtype) {
4402 case BRD_ECP:
4403 case BRD_ECPE:
4404 case BRD_ECPMC:
4405 case BRD_ECPPCI:
4406 stli_initecp(brdp);
4407 break;
4408 case BRD_ONBOARD:
4409 case BRD_ONBOARDE:
4410 case BRD_ONBOARD2:
4411 case BRD_ONBOARD32:
4412 case BRD_ONBOARD2_32:
4413 case BRD_ONBOARDRS:
4414 case BRD_BRUMBY4:
4415 case BRD_BRUMBY8:
4416 case BRD_BRUMBY16:
4417 case BRD_STALLION:
4418 stli_initonb(brdp);
4419 break;
4420 case BRD_EASYIO:
4421 case BRD_ECH:
4422 case BRD_ECHMC:
4423 case BRD_ECHPCI:
4424 printk("STALLION: %s board type not supported in this driver\n",
4425 stli_brdnames[brdp->brdtype]);
4426 return(ENODEV);
4427 default:
4428 printk("STALLION: board=%d is unknown board type=%d\n",
4429 brdp->brdnr, brdp->brdtype);
4430 return(ENODEV);
4431 }
4432
4433 if ((brdp->state & BST_FOUND) == 0) {
4434 printk("STALLION: %s board not found, board=%d io=%x mem=%x\n",
4435 stli_brdnames[brdp->brdtype], brdp->brdnr,
4436 brdp->iobase, (int) brdp->memaddr);
4437 return(ENODEV);
4438 }
4439
4440 stli_initports(brdp);
4441 printk("STALLION: %s found, board=%d io=%x mem=%x "
4442 "nrpanels=%d nrports=%d\n", stli_brdnames[brdp->brdtype],
4443 brdp->brdnr, brdp->iobase, (int) brdp->memaddr,
4444 brdp->nrpanels, brdp->nrports);
4445 return(0);
4446 }
4447
4448 /*****************************************************************************/
4449
4450 /*
4451 * Probe around trying to find where the EISA boards shared memory
4452 * might be. This is a bit if hack, but it is the best we can do.
4453 */
4454
4455 static inline int stli_eisamemprobe(stlibrd_t *brdp)
4456 {
4457 cdkecpsig_t ecpsig, *ecpsigp;
4458 cdkonbsig_t onbsig, *onbsigp;
4459 int i, foundit;
4460
4461 #if DEBUG
4462 printk("stli_eisamemprobe(brdp=%x)\n", (int) brdp);
4463 #endif
4464
4465 /*
4466 * First up we reset the board, to get it into a known state. There
4467 * is only 2 board types here we need to worry about. Don;t use the
4468 * standard board init routine here, it programs up the shared
4469 * memory address, and we don't know it yet...
4470 */
4471 if (brdp->brdtype == BRD_ECPE) {
4472 outb(0x1, (brdp->iobase + ECP_EIBRDENAB));
4473 outb(ECP_EISTOP, (brdp->iobase + ECP_EICONFR));
4474 udelay(10);
4475 outb(ECP_EIDISABLE, (brdp->iobase + ECP_EICONFR));
4476 udelay(500);
4477 stli_ecpeienable(brdp);
4478 } else if (brdp->brdtype == BRD_ONBOARDE) {
4479 outb(0x1, (brdp->iobase + ONB_EIBRDENAB));
4480 outb(ONB_EISTOP, (brdp->iobase + ONB_EICONFR));
4481 udelay(10);
4482 outb(ONB_EIDISABLE, (brdp->iobase + ONB_EICONFR));
4483 mdelay(100);
4484 outb(0x1, brdp->iobase);
4485 mdelay(1);
4486 stli_onbeenable(brdp);
4487 } else {
4488 return(-ENODEV);
4489 }
4490
4491 foundit = 0;
4492 brdp->memsize = ECP_MEMSIZE;
4493
4494 /*
4495 * Board shared memory is enabled, so now we have a poke around and
4496 * see if we can find it.
4497 */
4498 for (i = 0; (i < stli_eisamempsize); i++) {
4499 brdp->memaddr = stli_eisamemprobeaddrs[i];
4500 brdp->membase = (void *) brdp->memaddr;
4501 brdp->membase = ioremap(brdp->memaddr, brdp->memsize);
4502 if (brdp->membase == (void *) NULL)
4503 continue;
4504
4505 if (brdp->brdtype == BRD_ECPE) {
4506 ecpsigp = (cdkecpsig_t *) stli_ecpeigetmemptr(brdp,
4507 CDK_SIGADDR, __LINE__);
4508 memcpy(&ecpsig, ecpsigp, sizeof(cdkecpsig_t));
4509 if (ecpsig.magic == ECP_MAGIC)
4510 foundit = 1;
4511 } else {
4512 onbsigp = (cdkonbsig_t *) stli_onbegetmemptr(brdp,
4513 CDK_SIGADDR, __LINE__);
4514 memcpy(&onbsig, onbsigp, sizeof(cdkonbsig_t));
4515 if ((onbsig.magic0 == ONB_MAGIC0) &&
4516 (onbsig.magic1 == ONB_MAGIC1) &&
4517 (onbsig.magic2 == ONB_MAGIC2) &&
4518 (onbsig.magic3 == ONB_MAGIC3))
4519 foundit = 1;
4520 }
4521
4522 iounmap(brdp->membase);
4523 if (foundit)
4524 break;
4525 }
4526
4527 /*
4528 * Regardless of whether we found the shared memory or not we must
4529 * disable the region. After that return success or failure.
4530 */
4531 if (brdp->brdtype == BRD_ECPE)
4532 stli_ecpeidisable(brdp);
4533 else
4534 stli_onbedisable(brdp);
4535
4536 if (! foundit) {
4537 brdp->memaddr = 0;
4538 brdp->membase = 0;
4539 printk("STALLION: failed to probe shared memory region for "
4540 "%s in EISA slot=%d\n", stli_brdnames[brdp->brdtype],
4541 (brdp->iobase >> 12));
4542 return(-ENODEV);
4543 }
4544 return(0);
4545 }
4546
4547 /*****************************************************************************/
4548
4549 /*
4550 * Probe around and try to find any EISA boards in system. The biggest
4551 * problem here is finding out what memory address is associated with
4552 * an EISA board after it is found. The registers of the ECPE and
4553 * ONboardE are not readable - so we can't read them from there. We
4554 * don't have access to the EISA CMOS (or EISA BIOS) so we don't
4555 * actually have any way to find out the real value. The best we can
4556 * do is go probing around in the usual places hoping we can find it.
4557 */
4558
4559 static inline int stli_findeisabrds()
4560 {
4561 stlibrd_t *brdp;
4562 unsigned int iobase, eid;
4563 int i;
4564
4565 #if DEBUG
4566 printk("stli_findeisabrds()\n");
4567 #endif
4568
4569 /*
4570 * Firstly check if this is an EISA system. Do this by probing for
4571 * the system board EISA ID. If this is not an EISA system then
4572 * don't bother going any further!
4573 */
4574 outb(0xff, 0xc80);
4575 if (inb(0xc80) == 0xff)
4576 return(0);
4577
4578 /*
4579 * Looks like an EISA system, so go searching for EISA boards.
4580 */
4581 for (iobase = 0x1000; (iobase <= 0xc000); iobase += 0x1000) {
4582 outb(0xff, (iobase + 0xc80));
4583 eid = inb(iobase + 0xc80);
4584 eid |= inb(iobase + 0xc81) << 8;
4585 if (eid != STL_EISAID)
4586 continue;
4587
4588 /*
4589 * We have found a board. Need to check if this board was
4590 * statically configured already (just in case!).
4591 */
4592 for (i = 0; (i < STL_MAXBRDS); i++) {
4593 brdp = stli_brds[i];
4594 if (brdp == (stlibrd_t *) NULL)
4595 continue;
4596 if (brdp->iobase == iobase)
4597 break;
4598 }
4599 if (i < STL_MAXBRDS)
4600 continue;
4601
4602 /*
4603 * We have found a Stallion board and it is not configured already.
4604 * Allocate a board structure and initialize it.
4605 */
4606 if ((brdp = stli_allocbrd()) == (stlibrd_t *) NULL)
4607 return(-ENOMEM);
4608 if ((brdp->brdnr = stli_getbrdnr()) < 0)
4609 return(-ENOMEM);
4610 eid = inb(iobase + 0xc82);
4611 if (eid == ECP_EISAID)
4612 brdp->brdtype = BRD_ECPE;
4613 else if (eid == ONB_EISAID)
4614 brdp->brdtype = BRD_ONBOARDE;
4615 else
4616 brdp->brdtype = BRD_UNKNOWN;
4617 brdp->iobase = iobase;
4618 outb(0x1, (iobase + 0xc84));
4619 if (stli_eisamemprobe(brdp))
4620 outb(0, (iobase + 0xc84));
4621 stli_brdinit(brdp);
4622 }
4623
4624 return(0);
4625 }
4626
4627 /*****************************************************************************/
4628
4629 /*
4630 * Find the next available board number that is free.
4631 */
4632
4633 static inline int stli_getbrdnr()
4634 {
4635 int i;
4636
4637 for (i = 0; (i < STL_MAXBRDS); i++) {
4638 if (stli_brds[i] == (stlibrd_t *) NULL) {
4639 if (i >= stli_nrbrds)
4640 stli_nrbrds = i + 1;
4641 return(i);
4642 }
4643 }
4644 return(-1);
4645 }
4646
4647 /*****************************************************************************/
4648
4649 #ifdef CONFIG_PCI
4650
4651 /*
4652 * We have a Stallion board. Allocate a board structure and
4653 * initialize it. Read its IO and MEMORY resources from PCI
4654 * configuration space.
4655 */
4656
4657 static inline int stli_initpcibrd(int brdtype, struct pci_dev *devp)
4658 {
4659 stlibrd_t *brdp;
4660
4661 #if DEBUG
4662 printk("stli_initpcibrd(brdtype=%d,busnr=%x,devnr=%x)\n", brdtype,
4663 dev->bus->number, dev->devfn);
4664 #endif
4665
4666 if (pci_enable_device(devp))
4667 return(-EIO);
4668 if ((brdp = stli_allocbrd()) == (stlibrd_t *) NULL)
4669 return(-ENOMEM);
4670 if ((brdp->brdnr = stli_getbrdnr()) < 0) {
4671 printk("STALLION: too many boards found, "
4672 "maximum supported %d\n", STL_MAXBRDS);
4673 return(0);
4674 }
4675 brdp->brdtype = brdtype;
4676
4677 #if DEBUG
4678 printk("%s(%d): BAR[]=%lx,%lx,%lx,%lx\n", __FILE__, __LINE__,
4679 pci_resource_start(devp, 0),
4680 pci_resource_start(devp, 1),
4681 pci_resource_start(devp, 2),
4682 pci_resource_start(devp, 3));
4683 #endif
4684
4685 /*
4686 * We have all resources from the board, so lets setup the actual
4687 * board structure now.
4688 */
4689 brdp->iobase = pci_resource_start(devp, 3);
4690 brdp->memaddr = pci_resource_start(devp, 2);
4691 stli_brdinit(brdp);
4692
4693 return(0);
4694 }
4695
4696 /*****************************************************************************/
4697
4698 /*
4699 * Find all Stallion PCI boards that might be installed. Initialize each
4700 * one as it is found.
4701 */
4702
4703 static inline int stli_findpcibrds()
4704 {
4705 struct pci_dev *dev = NULL;
4706 int rc;
4707
4708 #if DEBUG
4709 printk("stli_findpcibrds()\n");
4710 #endif
4711
4712 if (! pci_present())
4713 return(0);
4714
4715 while ((dev = pci_find_device(PCI_VENDOR_ID_STALLION,
4716 PCI_DEVICE_ID_ECRA, dev))) {
4717 if ((rc = stli_initpcibrd(BRD_ECPPCI, dev)))
4718 return(rc);
4719 }
4720
4721 return(0);
4722 }
4723
4724 #endif
4725
4726 /*****************************************************************************/
4727
4728 /*
4729 * Allocate a new board structure. Fill out the basic info in it.
4730 */
4731
4732 static stlibrd_t *stli_allocbrd()
4733 {
4734 stlibrd_t *brdp;
4735
4736 brdp = (stlibrd_t *) stli_memalloc(sizeof(stlibrd_t));
4737 if (brdp == (stlibrd_t *) NULL) {
4738 printk("STALLION: failed to allocate memory (size=%d)\n",
4739 sizeof(stlibrd_t));
4740 return((stlibrd_t *) NULL);
4741 }
4742
4743 memset(brdp, 0, sizeof(stlibrd_t));
4744 brdp->magic = STLI_BOARDMAGIC;
4745 return(brdp);
4746 }
4747
4748 /*****************************************************************************/
4749
4750 /*
4751 * Scan through all the boards in the configuration and see what we
4752 * can find.
4753 */
4754
4755 static inline int stli_initbrds()
4756 {
4757 stlibrd_t *brdp, *nxtbrdp;
4758 stlconf_t *confp;
4759 int i, j;
4760
4761 #if DEBUG
4762 printk("stli_initbrds()\n");
4763 #endif
4764
4765 if (stli_nrbrds > STL_MAXBRDS) {
4766 printk("STALLION: too many boards in configuration table, "
4767 "truncating to %d\n", STL_MAXBRDS);
4768 stli_nrbrds = STL_MAXBRDS;
4769 }
4770
4771 /*
4772 * Firstly scan the list of static boards configured. Allocate
4773 * resources and initialize the boards as found. If this is a
4774 * module then let the module args override static configuration.
4775 */
4776 for (i = 0; (i < stli_nrbrds); i++) {
4777 confp = &stli_brdconf[i];
4778 #ifdef MODULE
4779 stli_parsebrd(confp, stli_brdsp[i]);
4780 #endif
4781 if ((brdp = stli_allocbrd()) == (stlibrd_t *) NULL)
4782 return(-ENOMEM);
4783 brdp->brdnr = i;
4784 brdp->brdtype = confp->brdtype;
4785 brdp->iobase = confp->ioaddr1;
4786 brdp->memaddr = confp->memaddr;
4787 stli_brdinit(brdp);
4788 }
4789
4790 /*
4791 * Static configuration table done, so now use dynamic methods to
4792 * see if any more boards should be configured.
4793 */
4794 #ifdef MODULE
4795 stli_argbrds();
4796 #endif
4797 if (stli_eisaprobe)
4798 stli_findeisabrds();
4799 #ifdef CONFIG_PCI
4800 stli_findpcibrds();
4801 #endif
4802
4803 /*
4804 * All found boards are initialized. Now for a little optimization, if
4805 * no boards are sharing the "shared memory" regions then we can just
4806 * leave them all enabled. This is in fact the usual case.
4807 */
4808 stli_shared = 0;
4809 if (stli_nrbrds > 1) {
4810 for (i = 0; (i < stli_nrbrds); i++) {
4811 brdp = stli_brds[i];
4812 if (brdp == (stlibrd_t *) NULL)
4813 continue;
4814 for (j = i + 1; (j < stli_nrbrds); j++) {
4815 nxtbrdp = stli_brds[j];
4816 if (nxtbrdp == (stlibrd_t *) NULL)
4817 continue;
4818 if ((brdp->membase >= nxtbrdp->membase) &&
4819 (brdp->membase <= (nxtbrdp->membase +
4820 nxtbrdp->memsize - 1))) {
4821 stli_shared++;
4822 break;
4823 }
4824 }
4825 }
4826 }
4827
4828 if (stli_shared == 0) {
4829 for (i = 0; (i < stli_nrbrds); i++) {
4830 brdp = stli_brds[i];
4831 if (brdp == (stlibrd_t *) NULL)
4832 continue;
4833 if (brdp->state & BST_FOUND) {
4834 EBRDENABLE(brdp);
4835 brdp->enable = NULL;
4836 brdp->disable = NULL;
4837 }
4838 }
4839 }
4840
4841 return(0);
4842 }
4843
4844 /*****************************************************************************/
4845
4846 /*
4847 * Code to handle an "staliomem" read operation. This device is the
4848 * contents of the board shared memory. It is used for down loading
4849 * the slave image (and debugging :-)
4850 */
4851
4852 static ssize_t stli_memread(struct file *fp, char *buf, size_t count, loff_t *offp)
4853 {
4854 unsigned long flags;
4855 void *memptr;
4856 stlibrd_t *brdp;
4857 int brdnr, size, n;
4858
4859 #if DEBUG
4860 printk("stli_memread(fp=%x,buf=%x,count=%x,offp=%x)\n", (int) fp,
4861 (int) buf, count, (int) offp);
4862 #endif
4863
4864 brdnr = MINOR(fp->f_dentry->d_inode->i_rdev);
4865 if (brdnr >= stli_nrbrds)
4866 return(-ENODEV);
4867 brdp = stli_brds[brdnr];
4868 if (brdp == (stlibrd_t *) NULL)
4869 return(-ENODEV);
4870 if (brdp->state == 0)
4871 return(-ENODEV);
4872 if (fp->f_pos >= brdp->memsize)
4873 return(0);
4874
4875 size = MIN(count, (brdp->memsize - fp->f_pos));
4876
4877 save_flags(flags);
4878 cli();
4879 EBRDENABLE(brdp);
4880 while (size > 0) {
4881 memptr = (void *) EBRDGETMEMPTR(brdp, fp->f_pos);
4882 n = MIN(size, (brdp->pagesize - (((unsigned long) fp->f_pos) % brdp->pagesize)));
4883 copy_to_user(buf, memptr, n);
4884 fp->f_pos += n;
4885 buf += n;
4886 size -= n;
4887 }
4888 EBRDDISABLE(brdp);
4889 restore_flags(flags);
4890
4891 return(count);
4892 }
4893
4894 /*****************************************************************************/
4895
4896 /*
4897 * Code to handle an "staliomem" write operation. This device is the
4898 * contents of the board shared memory. It is used for down loading
4899 * the slave image (and debugging :-)
4900 */
4901
4902 static ssize_t stli_memwrite(struct file *fp, const char *buf, size_t count, loff_t *offp)
4903 {
4904 unsigned long flags;
4905 void *memptr;
4906 stlibrd_t *brdp;
4907 char *chbuf;
4908 int brdnr, size, n;
4909
4910 #if DEBUG
4911 printk("stli_memwrite(fp=%x,buf=%x,count=%x,offp=%x)\n", (int) fp,
4912 (int) buf, count, (int) offp);
4913 #endif
4914
4915 brdnr = MINOR(fp->f_dentry->d_inode->i_rdev);
4916 if (brdnr >= stli_nrbrds)
4917 return(-ENODEV);
4918 brdp = stli_brds[brdnr];
4919 if (brdp == (stlibrd_t *) NULL)
4920 return(-ENODEV);
4921 if (brdp->state == 0)
4922 return(-ENODEV);
4923 if (fp->f_pos >= brdp->memsize)
4924 return(0);
4925
4926 chbuf = (char *) buf;
4927 size = MIN(count, (brdp->memsize - fp->f_pos));
4928
4929 save_flags(flags);
4930 cli();
4931 EBRDENABLE(brdp);
4932 while (size > 0) {
4933 memptr = (void *) EBRDGETMEMPTR(brdp, fp->f_pos);
4934 n = MIN(size, (brdp->pagesize - (((unsigned long) fp->f_pos) % brdp->pagesize)));
4935 copy_from_user(memptr, chbuf, n);
4936 fp->f_pos += n;
4937 chbuf += n;
4938 size -= n;
4939 }
4940 EBRDDISABLE(brdp);
4941 restore_flags(flags);
4942
4943 return(count);
4944 }
4945
4946 /*****************************************************************************/
4947
4948 /*
4949 * Return the board stats structure to user app.
4950 */
4951
4952 static int stli_getbrdstats(combrd_t *bp)
4953 {
4954 stlibrd_t *brdp;
4955 int i;
4956
4957 copy_from_user(&stli_brdstats, bp, sizeof(combrd_t));
4958 if (stli_brdstats.brd >= STL_MAXBRDS)
4959 return(-ENODEV);
4960 brdp = stli_brds[stli_brdstats.brd];
4961 if (brdp == (stlibrd_t *) NULL)
4962 return(-ENODEV);
4963
4964 memset(&stli_brdstats, 0, sizeof(combrd_t));
4965 stli_brdstats.brd = brdp->brdnr;
4966 stli_brdstats.type = brdp->brdtype;
4967 stli_brdstats.hwid = 0;
4968 stli_brdstats.state = brdp->state;
4969 stli_brdstats.ioaddr = brdp->iobase;
4970 stli_brdstats.memaddr = brdp->memaddr;
4971 stli_brdstats.nrpanels = brdp->nrpanels;
4972 stli_brdstats.nrports = brdp->nrports;
4973 for (i = 0; (i < brdp->nrpanels); i++) {
4974 stli_brdstats.panels[i].panel = i;
4975 stli_brdstats.panels[i].hwid = brdp->panelids[i];
4976 stli_brdstats.panels[i].nrports = brdp->panels[i];
4977 }
4978
4979 copy_to_user(bp, &stli_brdstats, sizeof(combrd_t));
4980 return(0);
4981 }
4982
4983 /*****************************************************************************/
4984
4985 /*
4986 * Resolve the referenced port number into a port struct pointer.
4987 */
4988
4989 static stliport_t *stli_getport(int brdnr, int panelnr, int portnr)
4990 {
4991 stlibrd_t *brdp;
4992 int i;
4993
4994 if ((brdnr < 0) || (brdnr >= STL_MAXBRDS))
4995 return((stliport_t *) NULL);
4996 brdp = stli_brds[brdnr];
4997 if (brdp == (stlibrd_t *) NULL)
4998 return((stliport_t *) NULL);
4999 for (i = 0; (i < panelnr); i++)
5000 portnr += brdp->panels[i];
5001 if ((portnr < 0) || (portnr >= brdp->nrports))
5002 return((stliport_t *) NULL);
5003 return(brdp->ports[portnr]);
5004 }
5005
5006 /*****************************************************************************/
5007
5008 /*
5009 * Return the port stats structure to user app. A NULL port struct
5010 * pointer passed in means that we need to find out from the app
5011 * what port to get stats for (used through board control device).
5012 */
5013
5014 static int stli_portcmdstats(stliport_t *portp)
5015 {
5016 unsigned long flags;
5017 stlibrd_t *brdp;
5018 int rc;
5019
5020 memset(&stli_comstats, 0, sizeof(comstats_t));
5021
5022 if (portp == (stliport_t *) NULL)
5023 return(-ENODEV);
5024 brdp = stli_brds[portp->brdnr];
5025 if (brdp == (stlibrd_t *) NULL)
5026 return(-ENODEV);
5027
5028 if (brdp->state & BST_STARTED) {
5029 if ((rc = stli_cmdwait(brdp, portp, A_GETSTATS,
5030 &stli_cdkstats, sizeof(asystats_t), 1)) < 0)
5031 return(rc);
5032 } else {
5033 memset(&stli_cdkstats, 0, sizeof(asystats_t));
5034 }
5035
5036 stli_comstats.brd = portp->brdnr;
5037 stli_comstats.panel = portp->panelnr;
5038 stli_comstats.port = portp->portnr;
5039 stli_comstats.state = portp->state;
5040 stli_comstats.flags = portp->flags;
5041
5042 save_flags(flags);
5043 cli();
5044 if (portp->tty != (struct tty_struct *) NULL) {
5045 if (portp->tty->driver_data == portp) {
5046 stli_comstats.ttystate = portp->tty->flags;
5047 stli_comstats.rxbuffered = portp->tty->flip.count;
5048 if (portp->tty->termios != (struct termios *) NULL) {
5049 stli_comstats.cflags = portp->tty->termios->c_cflag;
5050 stli_comstats.iflags = portp->tty->termios->c_iflag;
5051 stli_comstats.oflags = portp->tty->termios->c_oflag;
5052 stli_comstats.lflags = portp->tty->termios->c_lflag;
5053 }
5054 }
5055 }
5056 restore_flags(flags);
5057
5058 stli_comstats.txtotal = stli_cdkstats.txchars;
5059 stli_comstats.rxtotal = stli_cdkstats.rxchars + stli_cdkstats.ringover;
5060 stli_comstats.txbuffered = stli_cdkstats.txringq;
5061 stli_comstats.rxbuffered += stli_cdkstats.rxringq;
5062 stli_comstats.rxoverrun = stli_cdkstats.overruns;
5063 stli_comstats.rxparity = stli_cdkstats.parity;
5064 stli_comstats.rxframing = stli_cdkstats.framing;
5065 stli_comstats.rxlost = stli_cdkstats.ringover;
5066 stli_comstats.rxbreaks = stli_cdkstats.rxbreaks;
5067 stli_comstats.txbreaks = stli_cdkstats.txbreaks;
5068 stli_comstats.txxon = stli_cdkstats.txstart;
5069 stli_comstats.txxoff = stli_cdkstats.txstop;
5070 stli_comstats.rxxon = stli_cdkstats.rxstart;
5071 stli_comstats.rxxoff = stli_cdkstats.rxstop;
5072 stli_comstats.rxrtsoff = stli_cdkstats.rtscnt / 2;
5073 stli_comstats.rxrtson = stli_cdkstats.rtscnt - stli_comstats.rxrtsoff;
5074 stli_comstats.modem = stli_cdkstats.dcdcnt;
5075 stli_comstats.hwid = stli_cdkstats.hwid;
5076 stli_comstats.signals = stli_mktiocm(stli_cdkstats.signals);
5077
5078 return(0);
5079 }
5080
5081 /*****************************************************************************/
5082
5083 /*
5084 * Return the port stats structure to user app. A NULL port struct
5085 * pointer passed in means that we need to find out from the app
5086 * what port to get stats for (used through board control device).
5087 */
5088
5089 static int stli_getportstats(stliport_t *portp, comstats_t *cp)
5090 {
5091 stlibrd_t *brdp;
5092 int rc;
5093
5094 if (portp == (stliport_t *) NULL) {
5095 copy_from_user(&stli_comstats, cp, sizeof(comstats_t));
5096 portp = stli_getport(stli_comstats.brd, stli_comstats.panel,
5097 stli_comstats.port);
5098 if (portp == (stliport_t *) NULL)
5099 return(-ENODEV);
5100 }
5101
5102 brdp = stli_brds[portp->brdnr];
5103 if (brdp == (stlibrd_t *) NULL)
5104 return(-ENODEV);
5105
5106 if ((rc = stli_portcmdstats(portp)) < 0)
5107 return(rc);
5108
5109 copy_to_user(cp, &stli_comstats, sizeof(comstats_t));
5110 return(0);
5111 }
5112
5113 /*****************************************************************************/
5114
5115 /*
5116 * Clear the port stats structure. We also return it zeroed out...
5117 */
5118
5119 static int stli_clrportstats(stliport_t *portp, comstats_t *cp)
5120 {
5121 stlibrd_t *brdp;
5122 int rc;
5123
5124 if (portp == (stliport_t *) NULL) {
5125 copy_from_user(&stli_comstats, cp, sizeof(comstats_t));
5126 portp = stli_getport(stli_comstats.brd, stli_comstats.panel,
5127 stli_comstats.port);
5128 if (portp == (stliport_t *) NULL)
5129 return(-ENODEV);
5130 }
5131
5132 brdp = stli_brds[portp->brdnr];
5133 if (brdp == (stlibrd_t *) NULL)
5134 return(-ENODEV);
5135
5136 if (brdp->state & BST_STARTED) {
5137 if ((rc = stli_cmdwait(brdp, portp, A_CLEARSTATS, 0, 0, 0)) < 0)
5138 return(rc);
5139 }
5140
5141 memset(&stli_comstats, 0, sizeof(comstats_t));
5142 stli_comstats.brd = portp->brdnr;
5143 stli_comstats.panel = portp->panelnr;
5144 stli_comstats.port = portp->portnr;
5145
5146 copy_to_user(cp, &stli_comstats, sizeof(comstats_t));
5147 return(0);
5148 }
5149
5150 /*****************************************************************************/
5151
5152 /*
5153 * Return the entire driver ports structure to a user app.
5154 */
5155
5156 static int stli_getportstruct(unsigned long arg)
5157 {
5158 stliport_t *portp;
5159
5160 copy_from_user(&stli_dummyport, (void *) arg, sizeof(stliport_t));
5161 portp = stli_getport(stli_dummyport.brdnr, stli_dummyport.panelnr,
5162 stli_dummyport.portnr);
5163 if (portp == (stliport_t *) NULL)
5164 return(-ENODEV);
5165 copy_to_user((void *) arg, portp, sizeof(stliport_t));
5166 return(0);
5167 }
5168
5169 /*****************************************************************************/
5170
5171 /*
5172 * Return the entire driver board structure to a user app.
5173 */
5174
5175 static int stli_getbrdstruct(unsigned long arg)
5176 {
5177 stlibrd_t *brdp;
5178
5179 copy_from_user(&stli_dummybrd, (void *) arg, sizeof(stlibrd_t));
5180 if ((stli_dummybrd.brdnr < 0) || (stli_dummybrd.brdnr >= STL_MAXBRDS))
5181 return(-ENODEV);
5182 brdp = stli_brds[stli_dummybrd.brdnr];
5183 if (brdp == (stlibrd_t *) NULL)
5184 return(-ENODEV);
5185 copy_to_user((void *) arg, brdp, sizeof(stlibrd_t));
5186 return(0);
5187 }
5188
5189 /*****************************************************************************/
5190
5191 /*
5192 * The "staliomem" device is also required to do some special operations on
5193 * the board. We need to be able to send an interrupt to the board,
5194 * reset it, and start/stop it.
5195 */
5196
5197 static int stli_memioctl(struct inode *ip, struct file *fp, unsigned int cmd, unsigned long arg)
5198 {
5199 stlibrd_t *brdp;
5200 int brdnr, rc, done;
5201
5202 #if DEBUG
5203 printk("stli_memioctl(ip=%x,fp=%x,cmd=%x,arg=%x)\n", (int) ip,
5204 (int) fp, cmd, (int) arg);
5205 #endif
5206
5207 /*
5208 * First up handle the board independent ioctls.
5209 */
5210 done = 0;
5211 rc = 0;
5212
5213 switch (cmd) {
5214 case COM_GETPORTSTATS:
5215 if ((rc = verify_area(VERIFY_WRITE, (void *) arg,
5216 sizeof(comstats_t))) == 0)
5217 rc = stli_getportstats((stliport_t *) NULL,
5218 (comstats_t *) arg);
5219 done++;
5220 break;
5221 case COM_CLRPORTSTATS:
5222 if ((rc = verify_area(VERIFY_WRITE, (void *) arg,
5223 sizeof(comstats_t))) == 0)
5224 rc = stli_clrportstats((stliport_t *) NULL,
5225 (comstats_t *) arg);
5226 done++;
5227 break;
5228 case COM_GETBRDSTATS:
5229 if ((rc = verify_area(VERIFY_WRITE, (void *) arg,
5230 sizeof(combrd_t))) == 0)
5231 rc = stli_getbrdstats((combrd_t *) arg);
5232 done++;
5233 break;
5234 case COM_READPORT:
5235 if ((rc = verify_area(VERIFY_WRITE, (void *) arg,
5236 sizeof(stliport_t))) == 0)
5237 rc = stli_getportstruct(arg);
5238 done++;
5239 break;
5240 case COM_READBOARD:
5241 if ((rc = verify_area(VERIFY_WRITE, (void *) arg,
5242 sizeof(stlibrd_t))) == 0)
5243 rc = stli_getbrdstruct(arg);
5244 done++;
5245 break;
5246 default:
5247 break;
5248 }
5249
5250 if (done)
5251 return(rc);
5252
5253 /*
5254 * Now handle the board specific ioctls. These all depend on the
5255 * minor number of the device they were called from.
5256 */
5257 brdnr = MINOR(ip->i_rdev);
5258 if (brdnr >= STL_MAXBRDS)
5259 return(-ENODEV);
5260 brdp = stli_brds[brdnr];
5261 if (brdp == (stlibrd_t *) NULL)
5262 return(-ENODEV);
5263 if (brdp->state == 0)
5264 return(-ENODEV);
5265
5266 switch (cmd) {
5267 case STL_BINTR:
5268 EBRDINTR(brdp);
5269 break;
5270 case STL_BSTART:
5271 rc = stli_startbrd(brdp);
5272 break;
5273 case STL_BSTOP:
5274 brdp->state &= ~BST_STARTED;
5275 break;
5276 case STL_BRESET:
5277 brdp->state &= ~BST_STARTED;
5278 EBRDRESET(brdp);
5279 if (stli_shared == 0) {
5280 if (brdp->reenable != NULL)
5281 (* brdp->reenable)(brdp);
5282 }
5283 break;
5284 default:
5285 rc = -ENOIOCTLCMD;
5286 break;
5287 }
5288
5289 return(rc);
5290 }
5291
5292 /*****************************************************************************/
5293
5294 int __init stli_init(void)
5295 {
5296 printk(KERN_INFO "%s: version %s\n", stli_drvtitle, stli_drvversion);
5297
5298 stli_initbrds();
5299
5300 /*
5301 * Allocate a temporary write buffer.
5302 */
5303 stli_tmpwritebuf = (char *) stli_memalloc(STLI_TXBUFSIZE);
5304 if (stli_tmpwritebuf == (char *) NULL)
5305 printk("STALLION: failed to allocate memory (size=%d)\n",
5306 STLI_TXBUFSIZE);
5307 stli_txcookbuf = (char *) stli_memalloc(STLI_TXBUFSIZE);
5308 if (stli_txcookbuf == (char *) NULL)
5309 printk("STALLION: failed to allocate memory (size=%d)\n",
5310 STLI_TXBUFSIZE);
5311
5312 /*
5313 * Set up a character driver for the shared memory region. We need this
5314 * to down load the slave code image. Also it is a useful debugging tool.
5315 */
5316 if (devfs_register_chrdev(STL_SIOMEMMAJOR, "staliomem", &stli_fsiomem))
5317 printk("STALLION: failed to register serial memory device\n");
5318
5319 devfs_handle = devfs_mk_dir (NULL, "staliomem", NULL);
5320 devfs_register_series (devfs_handle, "%u", 4, DEVFS_FL_DEFAULT,
5321 STL_SIOMEMMAJOR, 0,
5322 S_IFCHR | S_IRUSR | S_IWUSR,
5323 &stli_fsiomem, NULL);
5324
5325 /*
5326 * Set up the tty driver structure and register us as a driver.
5327 * Also setup the callout tty device.
5328 */
5329 memset(&stli_serial, 0, sizeof(struct tty_driver));
5330 stli_serial.magic = TTY_DRIVER_MAGIC;
5331 stli_serial.driver_name = stli_drvname;
5332 stli_serial.name = stli_serialname;
5333 stli_serial.major = STL_SERIALMAJOR;
5334 stli_serial.minor_start = 0;
5335 stli_serial.num = STL_MAXBRDS * STL_MAXPORTS;
5336 stli_serial.type = TTY_DRIVER_TYPE_SERIAL;
5337 stli_serial.subtype = STL_DRVTYPSERIAL;
5338 stli_serial.init_termios = stli_deftermios;
5339 stli_serial.flags = TTY_DRIVER_REAL_RAW;
5340 stli_serial.refcount = &stli_refcount;
5341 stli_serial.table = stli_ttys;
5342 stli_serial.termios = stli_termios;
5343 stli_serial.termios_locked = stli_termioslocked;
5344
5345 stli_serial.open = stli_open;
5346 stli_serial.close = stli_close;
5347 stli_serial.write = stli_write;
5348 stli_serial.put_char = stli_putchar;
5349 stli_serial.flush_chars = stli_flushchars;
5350 stli_serial.write_room = stli_writeroom;
5351 stli_serial.chars_in_buffer = stli_charsinbuffer;
5352 stli_serial.ioctl = stli_ioctl;
5353 stli_serial.set_termios = stli_settermios;
5354 stli_serial.throttle = stli_throttle;
5355 stli_serial.unthrottle = stli_unthrottle;
5356 stli_serial.stop = stli_stop;
5357 stli_serial.start = stli_start;
5358 stli_serial.hangup = stli_hangup;
5359 stli_serial.flush_buffer = stli_flushbuffer;
5360 stli_serial.break_ctl = stli_breakctl;
5361 stli_serial.wait_until_sent = stli_waituntilsent;
5362 stli_serial.send_xchar = stli_sendxchar;
5363 stli_serial.read_proc = stli_readproc;
5364
5365 stli_callout = stli_serial;
5366 stli_callout.name = stli_calloutname;
5367 stli_callout.major = STL_CALLOUTMAJOR;
5368 stli_callout.subtype = STL_DRVTYPCALLOUT;
5369 stli_callout.read_proc = 0;
5370
5371 if (tty_register_driver(&stli_serial))
5372 printk("STALLION: failed to register serial driver\n");
5373 if (tty_register_driver(&stli_callout))
5374 printk("STALLION: failed to register callout driver\n");
5375
5376 return(0);
5377 }
5378
5379 /*****************************************************************************/
5380
This page was automatically generated by the
LXR engine.
Visit the LXR main site for more
information.