This source file includes following definitions.
- init_module
- cleanup_module
- stli_memalloc
- stli_open
- stli_close
- stli_initopen
- stli_rawopen
- stli_rawclose
- stli_cmdwait
- stli_setport
- stli_delay
- stli_waitcarrier
- stli_write
- stli_putchar
- stli_flushchars
- stli_writeroom
- stli_charsinbuffer
- stli_getserial
- stli_setserial
- stli_ioctl
- stli_settermios
- stli_throttle
- stli_unthrottle
- stli_stop
- stli_start
- stli_dohangup
- stli_hangup
- stli_flushbuffer
- stli_sendcmd
- stli_read
- stli_dodelaycmd
- stli_hostcmd
- stli_poll
- stli_mkasyport
- stli_mkasysigs
- stli_mktiocm
- stli_initports
- stli_ecpinit
- stli_ecpenable
- stli_ecpdisable
- stli_ecpgetmemptr
- stli_ecpreset
- stli_ecpintr
- stli_ecpeiinit
- stli_ecpeienable
- stli_ecpeidisable
- stli_ecpeigetmemptr
- stli_ecpeireset
- stli_ecpmcenable
- stli_ecpmcdisable
- stli_ecpmcgetmemptr
- stli_ecpmcreset
- stli_onbinit
- stli_onbenable
- stli_onbdisable
- stli_onbgetmemptr
- stli_onbreset
- stli_onbeinit
- stli_onbeenable
- stli_onbedisable
- stli_onbegetmemptr
- stli_onbereset
- stli_bbyinit
- stli_bbygetmemptr
- stli_bbyreset
- stli_stalinit
- stli_stalgetmemptr
- stli_stalreset
- stli_mapbrdmem
- stli_initecp
- stli_initonb
- stli_startbrd
- stli_brdinit
- stli_eisamemprobe
- stli_findeisabrds
- stli_initbrds
- stli_memread
- stli_memwrite
- stli_memioctl
- stli_init
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28 #include <linux/module.h>
29 #include <linux/errno.h>
30 #include <linux/sched.h>
31 #include <linux/timer.h>
32 #include <linux/wait.h>
33 #include <linux/interrupt.h>
34 #include <linux/termios.h>
35 #include <linux/fcntl.h>
36 #include <linux/tty_driver.h>
37 #include <linux/tty.h>
38 #include <linux/tty_flip.h>
39 #include <linux/serial.h>
40 #include <linux/cdk.h>
41 #include <linux/string.h>
42 #include <linux/malloc.h>
43 #include <linux/ioport.h>
44 #include <linux/delay.h>
45 #include <asm/io.h>
46
47
48
49
50
51
52
53
54
55
56 #define BRD_UNKNOWN 0
57 #define BRD_STALLION 1
58 #define BRD_BRUMBY4 2
59 #define BRD_ONBOARD2 3
60 #define BRD_ONBOARD 4
61 #define BRD_BRUMBY8 5
62 #define BRD_BRUMBY16 6
63 #define BRD_ONBOARDE 7
64 #define BRD_ONBOARD32 9
65 #define BRD_ONBOARD2_32 10
66 #define BRD_ONBOARDRS 11
67 #define BRD_EASYIO 20
68 #define BRD_ECH 21
69 #define BRD_ECHMC 22
70 #define BRD_ECP 23
71 #define BRD_ECPE 24
72 #define BRD_ECPMC 25
73 #define BRD_ECHPCI 26
74
75 #define BRD_BRUMBY BRD_BRUMBY4
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110 typedef struct {
111 int brdtype;
112 int ioaddr1;
113 int ioaddr2;
114 unsigned long memaddr;
115 int irq;
116 int irqtype;
117 } stlconf_t;
118
119 static stlconf_t stli_brdconf[] = {
120 { BRD_ECP, 0x2a0, 0, 0xcc000, 0, 0 },
121 };
122
123 static int stli_nrbrds = sizeof(stli_brdconf) / sizeof(stlconf_t);
124
125
126
127
128
129
130
131
132
133
134
135
136 #define STLI_HIMEMORY 0
137
138 #if STLI_HIMEMORY
139 #include <asm/page.h>
140 #include <asm/pgtable.h>
141 #endif
142
143
144
145
146
147
148 #define STLI_EISAPROBE 0
149
150
151
152
153
154
155
156 #ifndef STL_SIOMEMMAJOR
157 #define STL_SIOMEMMAJOR 28
158 #endif
159 #ifndef STL_SERIALMAJOR
160 #define STL_SERIALMAJOR 24
161 #endif
162 #ifndef STL_CALLOUTMAJOR
163 #define STL_CALLOUTMAJOR 25
164 #endif
165
166 #define STL_DRVTYPSERIAL 1
167 #define STL_DRVTYPCALLOUT 2
168
169 #define STL_MAXBRDS 4
170 #define STL_MAXPANELS 4
171 #define STL_MAXPORTS 64
172 #define STL_MAXCHANS (STL_MAXPORTS + 1)
173 #define STL_MAXDEVS (STL_MAXBRDS * STL_MAXPORTS)
174
175
176
177
178
179
180
181 static char *stli_drvname = "Stallion Intelligent Multiport Serial Driver";
182 static char *stli_drvversion = "1.0.2";
183 static char *stli_serialname = "ttyE";
184 static char *stli_calloutname = "cue";
185
186 static struct tty_driver stli_serial;
187 static struct tty_driver stli_callout;
188 static struct tty_struct *stli_ttys[STL_MAXDEVS];
189 static struct termios *stli_termios[STL_MAXDEVS];
190 static struct termios *stli_termioslocked[STL_MAXDEVS];
191 static int stli_refcount;
192
193
194
195
196
197
198
199
200 static char *stli_tmpwritebuf = (char *) NULL;
201 static struct semaphore stli_tmpwritesem = MUTEX;
202
203 #define STLI_TXBUFSIZE 4096
204
205
206
207
208
209
210
211
212 static char *stli_txcookbuf = (char *) NULL;
213 static int stli_txcooksize = 0;
214 static int stli_txcookrealsize = 0;
215 static struct tty_struct *stli_txcooktty = (struct tty_struct *) NULL;
216
217
218
219
220
221
222 static struct termios stli_deftermios = {
223 0,
224 0,
225 (B9600 | CS8 | CREAD | HUPCL | CLOCAL),
226 0,
227 0,
228 INIT_C_CC
229 };
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246 typedef struct {
247 int portnr;
248 int panelnr;
249 int brdnr;
250 unsigned long state;
251 int devnr;
252 int flags;
253 int baud_base;
254 int custom_divisor;
255 int close_delay;
256 int closing_wait;
257 int refcount;
258 int openwaitcnt;
259 int rc;
260 int argsize;
261 void *argp;
262 long session;
263 long pgrp;
264 unsigned int rxmarkmsk;
265 struct tty_struct *tty;
266 struct wait_queue *open_wait;
267 struct wait_queue *close_wait;
268 struct wait_queue *raw_wait;
269 struct tq_struct tqhangup;
270 struct termios normaltermios;
271 struct termios callouttermios;
272 asysigs_t asig;
273 unsigned long addr;
274 unsigned long rxoffset;
275 unsigned long txoffset;
276 unsigned long sigs;
277 unsigned long pflag;
278 unsigned int rxsize;
279 unsigned int txsize;
280 unsigned char reqbit;
281 unsigned char portidx;
282 unsigned char portbit;
283 } stliport_t;
284
285
286
287
288
289 typedef struct stlbrd {
290 int brdnr;
291 int brdtype;
292 int state;
293 int nrpanels;
294 int nrports;
295 int nrdevs;
296 unsigned int iobase;
297 unsigned long memaddr;
298 void *membase;
299 int memsize;
300 int pagesize;
301 int hostoffset;
302 int slaveoffset;
303 int bitsize;
304 int panels[STL_MAXPANELS];
305 void (*init)(struct stlbrd *brdp);
306 void (*enable)(struct stlbrd *brdp);
307 void (*reenable)(struct stlbrd *brdp);
308 void (*disable)(struct stlbrd *brdp);
309 char *(*getmemptr)(struct stlbrd *brdp, unsigned long offset, int line);
310 void (*intr)(struct stlbrd *brdp);
311 void (*reset)(struct stlbrd *brdp);
312 stliport_t *ports[STL_MAXPORTS];
313 } stlibrd_t;
314
315 static stlibrd_t *stli_brds[STL_MAXBRDS];
316
317 static int stli_shared = 0;
318
319
320
321
322
323
324
325 #define BST_FOUND 0x1
326 #define BST_STARTED 0x2
327
328
329
330
331
332
333
334 #define ST_INITIALIZING 1
335 #define ST_OPENING 2
336 #define ST_CLOSING 3
337 #define ST_CMDING 4
338 #define ST_TXBUSY 5
339 #define ST_RXING 6
340 #define ST_DOFLUSHRX 7
341 #define ST_DOFLUSHTX 8
342 #define ST_DOSIGS 9
343 #define ST_RXSTOP 10
344 #define ST_GETSIGS 11
345
346
347
348
349
350 static char *stli_brdnames[] = {
351 "Unknown",
352 "Stallion",
353 "Brumby",
354 "ONboard-MC",
355 "ONboard",
356 "Brumby",
357 "Brumby",
358 "ONboard-EI",
359 (char *) NULL,
360 "ONboard",
361 "ONboard-MC",
362 "ONboard-MC",
363 (char *) NULL,
364 (char *) NULL,
365 (char *) NULL,
366 (char *) NULL,
367 (char *) NULL,
368 (char *) NULL,
369 (char *) NULL,
370 (char *) NULL,
371 "EasyIO",
372 "EC8/32-AT",
373 "EC8/32-MC",
374 "EC8/64-AT",
375 "EC8/64-EI",
376 "EC8/64-MC",
377 "EC8/32-PCI",
378 };
379
380
381
382
383
384
385
386
387
388 static unsigned long stli_eisamemprobeaddrs[] = {
389 0xc0000, 0xd0000, 0xe0000, 0xf0000,
390 0x80000000, 0x80010000, 0x80020000, 0x80030000,
391 0x40000000, 0x40010000, 0x40020000, 0x40030000,
392 0xc0000000, 0xc0010000, 0xc0020000, 0xc0030000,
393 0xff000000, 0xff010000, 0xff020000, 0xff030000,
394 };
395
396 #if STLI_HIMEMORY
397 static int stli_eisamempsize = sizeof(stli_eisamemprobeaddrs) / sizeof(unsigned long);
398 #else
399 static int stli_eisamempsize = 4;
400 #endif
401
402 int stli_eisaprobe = STLI_EISAPROBE;
403
404
405
406
407
408
409
410
411 #define ECP_IOSIZE 4
412 #define ECP_MEMSIZE (128 * 1024)
413 #define ECP_ATPAGESIZE (4 * 1024)
414 #define ECP_EIPAGESIZE (64 * 1024)
415 #define ECP_MCPAGESIZE (4 * 1024)
416
417 #define STL_EISAID 0x8c4e
418
419
420
421
422 #define ECP_ATIREG 0
423 #define ECP_ATCONFR 1
424 #define ECP_ATMEMAR 2
425 #define ECP_ATMEMPR 3
426 #define ECP_ATSTOP 0x1
427 #define ECP_ATINTENAB 0x10
428 #define ECP_ATENABLE 0x20
429 #define ECP_ATDISABLE 0x00
430 #define ECP_ATADDRMASK 0x3f000
431 #define ECP_ATADDRSHFT 12
432
433
434
435
436 #define ECP_EIIREG 0
437 #define ECP_EIMEMARL 1
438 #define ECP_EICONFR 2
439 #define ECP_EIMEMARH 3
440 #define ECP_EIENABLE 0x1
441 #define ECP_EIDISABLE 0x0
442 #define ECP_EISTOP 0x4
443 #define ECP_EIEDGE 0x00
444 #define ECP_EILEVEL 0x80
445 #define ECP_EIADDRMASKL 0x00ff0000
446 #define ECP_EIADDRSHFTL 16
447 #define ECP_EIADDRMASKH 0xff000000
448 #define ECP_EIADDRSHFTH 24
449 #define ECP_EIBRDENAB 0xc84
450
451 #define ECP_EISAID 0x4
452
453
454
455
456
457 #define ECP_MCIREG 0
458 #define ECP_MCCONFR 1
459 #define ECP_MCSTOP 0x20
460 #define ECP_MCENABLE 0x80
461 #define ECP_MCDISABLE 0x00
462
463
464
465
466
467 #define ONB_IOSIZE 16
468 #define ONB_MEMSIZE (64 * 1024)
469 #define ONB_ATPAGESIZE (64 * 1024)
470 #define ONB_MCPAGESIZE (64 * 1024)
471 #define ONB_EIMEMSIZE (128 * 1024)
472 #define ONB_EIPAGESIZE (64 * 1024)
473
474
475
476
477 #define ONB_ATIREG 0
478 #define ONB_ATMEMAR 1
479 #define ONB_ATCONFR 2
480 #define ONB_ATSTOP 0x4
481 #define ONB_ATENABLE 0x01
482 #define ONB_ATDISABLE 0x00
483 #define ONB_ATADDRMASK 0xff0000
484 #define ONB_ATADDRSHFT 16
485
486 #if STLI_HIMEMORY
487 #define ONB_HIMEMENAB 0x02
488 #else
489 #define ONB_HIMEMENAB 0
490 #endif
491
492
493
494
495 #define ONB_EIIREG 0
496 #define ONB_EIMEMARL 1
497 #define ONB_EICONFR 2
498 #define ONB_EIMEMARH 3
499 #define ONB_EIENABLE 0x1
500 #define ONB_EIDISABLE 0x0
501 #define ONB_EISTOP 0x4
502 #define ONB_EIEDGE 0x00
503 #define ONB_EILEVEL 0x80
504 #define ONB_EIADDRMASKL 0x00ff0000
505 #define ONB_EIADDRSHFTL 16
506 #define ONB_EIADDRMASKH 0xff000000
507 #define ONB_EIADDRSHFTH 24
508 #define ONB_EIBRDENAB 0xc84
509
510 #define ONB_EISAID 0x1
511
512
513
514
515
516 #define BBY_IOSIZE 16
517 #define BBY_MEMSIZE (64 * 1024)
518 #define BBY_PAGESIZE (16 * 1024)
519
520 #define BBY_ATIREG 0
521 #define BBY_ATCONFR 1
522 #define BBY_ATSTOP 0x4
523
524
525
526
527
528 #define STAL_IOSIZE 16
529 #define STAL_MEMSIZE (64 * 1024)
530 #define STAL_PAGESIZE (64 * 1024)
531
532
533
534
535
536
537
538 #define ECH_PNLSTATUS 2
539 #define ECH_PNL16PORT 0x20
540 #define ECH_PNLIDMASK 0x07
541 #define ECH_PNLINTRPEND 0x80
542
543
544
545
546
547
548
549
550
551
552 #define EBRDINIT(brdp) \
553 if (brdp->init != NULL) \
554 (* brdp->init)(brdp)
555
556 #define EBRDENABLE(brdp) \
557 if (brdp->enable != NULL) \
558 (* brdp->enable)(brdp);
559
560 #define EBRDDISABLE(brdp) \
561 if (brdp->disable != NULL) \
562 (* brdp->disable)(brdp);
563
564 #define EBRDINTR(brdp) \
565 if (brdp->intr != NULL) \
566 (* brdp->intr)(brdp);
567
568 #define EBRDRESET(brdp) \
569 if (brdp->reset != NULL) \
570 (* brdp->reset)(brdp);
571
572 #define EBRDGETMEMPTR(brdp,offset) \
573 (* brdp->getmemptr)(brdp, offset, __LINE__)
574
575
576
577
578 #define STL_MAXBAUD 230400
579 #define STL_BAUDBASE 115200
580 #define STL_CLOSEDELAY 50
581
582
583
584
585
586
587 #define MKDEV2BRD(min) (((min) & 0xc0) >> 6)
588 #define MKDEV2PORT(min) ((min) & 0x3f)
589
590
591
592
593
594
595 static unsigned int stli_baudrates[] = {
596 0, 50, 75, 110, 134, 150, 200, 300, 600, 1200, 1800, 2400, 4800,
597 9600, 19200, 38400, 57600, 115200, 230400
598 };
599
600
601
602
603
604
605 #define MIN(a,b) (((a) <= (b)) ? (a) : (b))
606
607
608
609
610
611
612
613 #ifdef MODULE
614 int init_module(void);
615 void cleanup_module(void);
616 #endif
617
618 int stli_init(void);
619 static int stli_open(struct tty_struct *tty, struct file *filp);
620 static void stli_close(struct tty_struct *tty, struct file *filp);
621 static int stli_write(struct tty_struct *tty, int from_user, const unsigned char *buf, int count);
622 static void stli_putchar(struct tty_struct *tty, unsigned char ch);
623 static void stli_flushchars(struct tty_struct *tty);
624 static int stli_writeroom(struct tty_struct *tty);
625 static int stli_charsinbuffer(struct tty_struct *tty);
626 static int stli_ioctl(struct tty_struct *tty, struct file *file, unsigned int cmd, unsigned long arg);
627 static void stli_settermios(struct tty_struct *tty, struct termios *old);
628 static void stli_throttle(struct tty_struct *tty);
629 static void stli_unthrottle(struct tty_struct *tty);
630 static void stli_stop(struct tty_struct *tty);
631 static void stli_start(struct tty_struct *tty);
632 static void stli_flushbuffer(struct tty_struct *tty);
633 static void stli_hangup(struct tty_struct *tty);
634
635 static int stli_initbrds(void);
636 static int stli_brdinit(stlibrd_t *brdp);
637 static int stli_initecp(stlibrd_t *brdp);
638 static int stli_initonb(stlibrd_t *brdp);
639 static int stli_eisamemprobe(stlibrd_t *brdp);
640 static int stli_findeisabrds(void);
641 static int stli_initports(stlibrd_t *brdp);
642 static int stli_startbrd(stlibrd_t *brdp);
643 static int stli_memread(struct inode *ip, struct file *fp, char *buf, int count);
644 static int stli_memwrite(struct inode *ip, struct file *fp, const char *buf, int count);
645 static int stli_memioctl(struct inode *ip, struct file *fp, unsigned int cmd, unsigned long arg);
646 static void stli_poll(unsigned long arg);
647 static int stli_hostcmd(stlibrd_t *brdp, int channr);
648 static int stli_initopen(stlibrd_t *brdp, stliport_t *portp);
649 static int stli_rawopen(stlibrd_t *brdp, stliport_t *portp, unsigned long arg, int wait);
650 static int stli_rawclose(stlibrd_t *brdp, stliport_t *portp, unsigned long arg, int wait);
651 static int stli_waitcarrier(stlibrd_t *brdp, stliport_t *portp, struct file *filp);
652 static void stli_dohangup(void *arg);
653 static void stli_delay(int len);
654 static int stli_setport(stliport_t *portp);
655 static int stli_cmdwait(stlibrd_t *brdp, stliport_t *portp, unsigned long cmd, void *arg, int size, int copyback);
656 static void stli_sendcmd(stlibrd_t *brdp, stliport_t *portp, unsigned long cmd, void *arg, int size, int copyback);
657 static void stli_dodelaycmd(stliport_t *portp, volatile cdkctrl_t *cp);
658 static void stli_mkasyport(stliport_t *portp, asyport_t *pp, struct termios *tiosp);
659 static void stli_mkasysigs(asysigs_t *sp, int dtr, int rts);
660 static long stli_mktiocm(unsigned long sigvalue);
661 static void stli_read(stlibrd_t *brdp, stliport_t *portp);
662 static void stli_getserial(stliport_t *portp, struct serial_struct *sp);
663 static int stli_setserial(stliport_t *portp, struct serial_struct *sp);
664 static void *stli_memalloc(int len);
665
666 static void stli_ecpinit(stlibrd_t *brdp);
667 static void stli_ecpenable(stlibrd_t *brdp);
668 static void stli_ecpdisable(stlibrd_t *brdp);
669 static char *stli_ecpgetmemptr(stlibrd_t *brdp, unsigned long offset, int line);
670 static void stli_ecpreset(stlibrd_t *brdp);
671 static void stli_ecpintr(stlibrd_t *brdp);
672 static void stli_ecpeiinit(stlibrd_t *brdp);
673 static void stli_ecpeienable(stlibrd_t *brdp);
674 static void stli_ecpeidisable(stlibrd_t *brdp);
675 static char *stli_ecpeigetmemptr(stlibrd_t *brdp, unsigned long offset, int line);
676 static void stli_ecpeireset(stlibrd_t *brdp);
677 static void stli_ecpmcenable(stlibrd_t *brdp);
678 static void stli_ecpmcdisable(stlibrd_t *brdp);
679 static char *stli_ecpmcgetmemptr(stlibrd_t *brdp, unsigned long offset, int line);
680 static void stli_ecpmcreset(stlibrd_t *brdp);
681
682 static void stli_onbinit(stlibrd_t *brdp);
683 static void stli_onbenable(stlibrd_t *brdp);
684 static void stli_onbdisable(stlibrd_t *brdp);
685 static char *stli_onbgetmemptr(stlibrd_t *brdp, unsigned long offset, int line);
686 static void stli_onbreset(stlibrd_t *brdp);
687 static void stli_onbeinit(stlibrd_t *brdp);
688 static void stli_onbeenable(stlibrd_t *brdp);
689 static void stli_onbedisable(stlibrd_t *brdp);
690 static char *stli_onbegetmemptr(stlibrd_t *brdp, unsigned long offset, int line);
691 static void stli_onbereset(stlibrd_t *brdp);
692 static void stli_bbyinit(stlibrd_t *brdp);
693 static char *stli_bbygetmemptr(stlibrd_t *brdp, unsigned long offset, int line);
694 static void stli_bbyreset(stlibrd_t *brdp);
695 static void stli_stalinit(stlibrd_t *brdp);
696 static char *stli_stalgetmemptr(stlibrd_t *brdp, unsigned long offset, int line);
697 static void stli_stalreset(stlibrd_t *brdp);
698
699 #if STLI_HIMEMORY
700 static void *stli_mapbrdmem(unsigned long physaddr, unsigned int size);
701 #endif
702
703
704
705
706
707
708
709
710
711 static struct file_operations stli_fsiomem = {
712 NULL,
713 stli_memread,
714 stli_memwrite,
715 NULL,
716 NULL,
717 stli_memioctl,
718 NULL,
719 NULL,
720 NULL,
721 NULL
722 };
723
724
725
726
727
728
729
730
731
732 static struct timer_list stli_timerlist = {
733 NULL, NULL, 0, 0, stli_poll
734 };
735
736 static int stli_timeron = 0;
737
738
739
740
741 #define STLI_TIMEOUT (jiffies + 1)
742
743
744
745 #ifdef MODULE
746
747
748
749
750
751 int init_module()
752 {
753 unsigned long flags;
754
755 #if DEBUG
756 printk("init_module()\n");
757 #endif
758
759 save_flags(flags);
760 cli();
761 stli_init();
762 restore_flags(flags);
763
764 return(0);
765 }
766
767
768
769 void cleanup_module()
770 {
771 stlibrd_t *brdp;
772 stliport_t *portp;
773 unsigned long flags;
774 int i, j;
775
776 #if DEBUG
777 printk("cleanup_module()\n");
778 #endif
779
780 printk("Unloading %s: version %s\n", stli_drvname, stli_drvversion);
781
782 save_flags(flags);
783 cli();
784
785
786
787
788
789 if (stli_timeron) {
790 stli_timeron = 0;
791 del_timer(&stli_timerlist);
792 }
793
794 i = tty_unregister_driver(&stli_serial);
795 j = tty_unregister_driver(&stli_callout);
796 if (i || j) {
797 printk("STALLION: failed to un-register tty driver, errno=%d,%d\n", -i, -j);
798 restore_flags(flags);
799 return;
800 }
801 if ((i = unregister_chrdev(STL_SIOMEMMAJOR, "staliomem")))
802 printk("STALLION: failed to un-register serial memory device, errno=%d\n", -i);
803
804 if (stli_tmpwritebuf != (char *) NULL)
805 kfree_s(stli_tmpwritebuf, STLI_TXBUFSIZE);
806 if (stli_txcookbuf != (char *) NULL)
807 kfree_s(stli_txcookbuf, STLI_TXBUFSIZE);
808
809 for (i = 0; (i < stli_nrbrds); i++) {
810 brdp = stli_brds[i];
811 if (brdp == (stlibrd_t *) NULL)
812 continue;
813 for (j = 0; (j < STL_MAXPORTS); j++) {
814 portp = brdp->ports[j];
815 if (portp != (stliport_t *) NULL) {
816 if (portp->tty != (struct tty_struct *) NULL)
817 tty_hangup(portp->tty);
818 kfree_s(portp, sizeof(stliport_t));
819 }
820 }
821
822 #if STLI_HIMEMORY
823 if (((unsigned long) brdp->membase) >= 0x100000)
824 vfree(brdp->membase);
825 #endif
826 if ((brdp->brdtype == BRD_ECP) || (brdp->brdtype == BRD_ECPE) || (brdp->brdtype == BRD_ECPMC))
827 release_region(brdp->iobase, ECP_IOSIZE);
828 else
829 release_region(brdp->iobase, ONB_IOSIZE);
830 kfree_s(brdp, sizeof(stlibrd_t));
831 stli_brds[i] = (stlibrd_t *) NULL;
832 }
833
834 restore_flags(flags);
835 }
836
837 #endif
838
839
840
841
842
843
844
845 static void *stli_memalloc(int len)
846 {
847 return((void *) kmalloc(len, GFP_KERNEL));
848 }
849
850
851
852 static int stli_open(struct tty_struct *tty, struct file *filp)
853 {
854 stlibrd_t *brdp;
855 stliport_t *portp;
856 unsigned int minordev;
857 int brdnr, portnr, rc;
858
859 #if DEBUG
860 printk("stli_open(tty=%x,filp=%x): device=%x\n", (int) tty, (int) filp, tty->device);
861 #endif
862
863 minordev = MINOR(tty->device);
864 brdnr = MKDEV2BRD(minordev);
865 if (brdnr >= stli_nrbrds)
866 return(-ENODEV);
867 brdp = stli_brds[brdnr];
868 if (brdp == (stlibrd_t *) NULL)
869 return(-ENODEV);
870 if ((brdp->state & BST_STARTED) == 0)
871 return(-ENODEV);
872 portnr = MKDEV2PORT(minordev);
873 if ((portnr < 0) || (portnr > brdp->nrports))
874 return(-ENODEV);
875
876 portp = brdp->ports[portnr];
877 if (portp == (stliport_t *) NULL)
878 return(-ENODEV);
879 if (portp->devnr < 1)
880 return(-ENODEV);
881
882
883
884
885
886
887
888 if (portp->flags & ASYNC_CLOSING) {
889 interruptible_sleep_on(&portp->close_wait);
890 if (portp->flags & ASYNC_HUP_NOTIFY)
891 return(-EAGAIN);
892 return(-ERESTARTSYS);
893 }
894
895
896
897
898
899
900
901 portp->tty = tty;
902 tty->driver_data = portp;
903 portp->refcount++;
904
905 while (test_bit(ST_INITIALIZING, &portp->state)) {
906 if (current->signal & ~current->blocked)
907 return(-ERESTARTSYS);
908 interruptible_sleep_on(&portp->raw_wait);
909 }
910
911 if ((portp->flags & ASYNC_INITIALIZED) == 0) {
912 set_bit(ST_INITIALIZING, &portp->state);
913 if ((rc = stli_initopen(brdp, portp)) >= 0) {
914 portp->flags |= ASYNC_INITIALIZED;
915 clear_bit(TTY_IO_ERROR, &tty->flags);
916 }
917 clear_bit(ST_INITIALIZING, &portp->state);
918 wake_up_interruptible(&portp->raw_wait);
919 if (rc < 0)
920 return(rc);
921 }
922
923
924
925
926
927
928
929 if (portp->flags & ASYNC_CLOSING) {
930 interruptible_sleep_on(&portp->close_wait);
931 if (portp->flags & ASYNC_HUP_NOTIFY)
932 return(-EAGAIN);
933 return(-ERESTARTSYS);
934 }
935
936
937
938
939
940
941 if (tty->driver.subtype == STL_DRVTYPCALLOUT) {
942 if (portp->flags & ASYNC_NORMAL_ACTIVE)
943 return(-EBUSY);
944 if (portp->flags & ASYNC_CALLOUT_ACTIVE) {
945 if ((portp->flags & ASYNC_SESSION_LOCKOUT) &&
946 (portp->session != current->session))
947 return(-EBUSY);
948 if ((portp->flags & ASYNC_PGRP_LOCKOUT) &&
949 (portp->pgrp != current->pgrp))
950 return(-EBUSY);
951 }
952 portp->flags |= ASYNC_CALLOUT_ACTIVE;
953 } else {
954 if (filp->f_flags & O_NONBLOCK) {
955 if (portp->flags & ASYNC_CALLOUT_ACTIVE)
956 return(-EBUSY);
957 } else {
958 if ((rc = stli_waitcarrier(brdp, portp, filp)) != 0)
959 return(rc);
960 }
961 portp->flags |= ASYNC_NORMAL_ACTIVE;
962 }
963
964 if ((portp->refcount == 1) && (portp->flags & ASYNC_SPLIT_TERMIOS)) {
965 if (tty->driver.subtype == STL_DRVTYPSERIAL)
966 *tty->termios = portp->normaltermios;
967 else
968 *tty->termios = portp->callouttermios;
969 stli_setport(portp);
970 }
971
972 portp->session = current->session;
973 portp->pgrp = current->pgrp;
974 return(0);
975 }
976
977
978
979 static void stli_close(struct tty_struct *tty, struct file *filp)
980 {
981 stlibrd_t *brdp;
982 stliport_t *portp;
983 unsigned long flags;
984
985 #if DEBUG
986 printk("stli_close(tty=%x,filp=%x)\n", (int) tty, (int) filp);
987 #endif
988
989 portp = tty->driver_data;
990 if (portp == (stliport_t *) NULL)
991 return;
992
993 save_flags(flags);
994 cli();
995 if (tty_hung_up_p(filp)) {
996 restore_flags(flags);
997 return;
998 }
999 if (portp->refcount-- > 1) {
1000 restore_flags(flags);
1001 return;
1002 }
1003
1004 portp->flags |= ASYNC_CLOSING;
1005
1006 if (portp->flags & ASYNC_NORMAL_ACTIVE)
1007 portp->normaltermios = *tty->termios;
1008 if (portp->flags & ASYNC_CALLOUT_ACTIVE)
1009 portp->callouttermios = *tty->termios;
1010
1011
1012
1013
1014
1015
1016
1017 if (tty == stli_txcooktty)
1018 stli_flushchars(tty);
1019 tty->closing = 1;
1020 if (test_bit(ST_TXBUSY, &portp->state)) {
1021 if (portp->closing_wait != ASYNC_CLOSING_WAIT_NONE)
1022 tty_wait_until_sent(tty, portp->closing_wait);
1023 }
1024
1025 portp->flags &= ~ASYNC_INITIALIZED;
1026 brdp = stli_brds[portp->brdnr];
1027 stli_rawclose(brdp, portp, 0, 0);
1028 if (tty->termios->c_cflag & HUPCL) {
1029 stli_mkasysigs(&portp->asig, 0, 0);
1030 if (test_bit(ST_CMDING, &portp->state))
1031 set_bit(ST_DOSIGS, &portp->state);
1032 else
1033 stli_sendcmd(brdp, portp, A_SETSIGNALS, &portp->asig, sizeof(asysigs_t), 0);
1034 }
1035 clear_bit(ST_TXBUSY, &portp->state);
1036 clear_bit(ST_RXSTOP, &portp->state);
1037 set_bit(TTY_IO_ERROR, &tty->flags);
1038 if (tty->ldisc.flush_buffer)
1039 (tty->ldisc.flush_buffer)(tty);
1040 set_bit(ST_DOFLUSHRX, &portp->state);
1041 stli_flushbuffer(tty);
1042
1043 tty->closing = 0;
1044 tty->driver_data = (void *) NULL;
1045 portp->tty = (struct tty_struct *) NULL;
1046
1047 if (portp->openwaitcnt) {
1048 if (portp->close_delay)
1049 stli_delay(portp->close_delay);
1050 wake_up_interruptible(&portp->open_wait);
1051 }
1052
1053 portp->flags &= ~(ASYNC_CALLOUT_ACTIVE | ASYNC_NORMAL_ACTIVE | ASYNC_CLOSING);
1054 wake_up_interruptible(&portp->close_wait);
1055 restore_flags(flags);
1056 }
1057
1058
1059
1060
1061
1062
1063
1064
1065
1066
1067
1068 static int stli_initopen(stlibrd_t *brdp, stliport_t *portp)
1069 {
1070 struct tty_struct *tty;
1071 asynotify_t nt;
1072 asyport_t aport;
1073 int rc;
1074
1075 #if DEBUG
1076 printk("stli_initopen(brdp=%x,portp=%x)\n", (int) brdp, (int) portp);
1077 #endif
1078
1079 if ((rc = stli_rawopen(brdp, portp, 0, 1)) < 0)
1080 return(rc);
1081
1082 memset(&nt, 0, sizeof(asynotify_t));
1083 nt.data = (DT_TXLOW | DT_TXEMPTY | DT_RXBUSY | DT_RXBREAK);
1084 nt.signal = SG_DCD;
1085 if ((rc = stli_cmdwait(brdp, portp, A_SETNOTIFY, &nt, sizeof(asynotify_t), 0)) < 0)
1086 return(rc);
1087
1088 tty = portp->tty;
1089 if (tty == (struct tty_struct *) NULL)
1090 return(-ENODEV);
1091 stli_mkasyport(portp, &aport, tty->termios);
1092 if ((rc = stli_cmdwait(brdp, portp, A_SETPORT, &aport, sizeof(asyport_t), 0)) < 0)
1093 return(rc);
1094
1095 set_bit(ST_GETSIGS, &portp->state);
1096 if ((rc = stli_cmdwait(brdp, portp, A_GETSIGNALS, &portp->asig, sizeof(asysigs_t), 1)) < 0)
1097 return(rc);
1098 if (clear_bit(ST_GETSIGS, &portp->state))
1099 portp->sigs = stli_mktiocm(portp->asig.sigvalue);
1100 stli_mkasysigs(&portp->asig, 1, 1);
1101 if ((rc = stli_cmdwait(brdp, portp, A_SETSIGNALS, &portp->asig, sizeof(asysigs_t), 0)) < 0)
1102 return(rc);
1103
1104 return(0);
1105 }
1106
1107
1108
1109
1110
1111
1112
1113
1114
1115
1116 static int stli_rawopen(stlibrd_t *brdp, stliport_t *portp, unsigned long arg, int wait)
1117 {
1118 volatile cdkhdr_t *hdrp;
1119 volatile cdkctrl_t *cp;
1120 volatile unsigned char *bits;
1121 unsigned long flags;
1122 int rc;
1123
1124 #if DEBUG
1125 printk("stli_rawopen(brdp=%x,portp=%x,arg=%x,wait=%d)\n", (int) brdp, (int) portp, (int) arg, wait);
1126 #endif
1127
1128
1129
1130
1131 save_flags(flags);
1132 cli();
1133
1134
1135
1136
1137
1138
1139
1140 while (test_bit(ST_CLOSING, &portp->state)) {
1141 if (current->signal & ~current->blocked) {
1142 restore_flags(flags);
1143 return(-ERESTARTSYS);
1144 }
1145 interruptible_sleep_on(&portp->raw_wait);
1146 }
1147
1148
1149
1150
1151
1152
1153 EBRDENABLE(brdp);
1154 cp = &((volatile cdkasy_t *) EBRDGETMEMPTR(brdp, portp->addr))->ctrl;
1155 cp->openarg = arg;
1156 cp->open = 1;
1157 hdrp = (volatile cdkhdr_t *) EBRDGETMEMPTR(brdp, CDK_CDKADDR);
1158 hdrp->slavereq |= portp->reqbit;
1159 bits = ((volatile unsigned char *) hdrp) + brdp->slaveoffset + portp->portidx;
1160 *bits |= portp->portbit;
1161 EBRDDISABLE(brdp);
1162
1163 if (wait == 0) {
1164 restore_flags(flags);
1165 return(0);
1166 }
1167
1168
1169
1170
1171
1172 rc = 0;
1173 set_bit(ST_OPENING, &portp->state);
1174 while (test_bit(ST_OPENING, &portp->state)) {
1175 if (current->signal & ~current->blocked) {
1176 rc = -ERESTARTSYS;
1177 break;
1178 }
1179 interruptible_sleep_on(&portp->raw_wait);
1180 }
1181 restore_flags(flags);
1182
1183 if ((rc == 0) && (portp->rc != 0))
1184 rc = -EIO;
1185 return(rc);
1186 }
1187
1188
1189
1190
1191
1192
1193
1194
1195
1196 static int stli_rawclose(stlibrd_t *brdp, stliport_t *portp, unsigned long arg, int wait)
1197 {
1198 volatile cdkhdr_t *hdrp;
1199 volatile cdkctrl_t *cp;
1200 volatile unsigned char *bits;
1201 unsigned long flags;
1202 int rc;
1203
1204 #if DEBUG
1205 printk("stli_rawclose(brdp=%x,portp=%x,arg=%x,wait=%d)\n", (int) brdp, (int) portp, (int) arg, wait);
1206 #endif
1207
1208 save_flags(flags);
1209 cli();
1210
1211
1212
1213
1214
1215 if (wait) {
1216 while (test_bit(ST_CLOSING, &portp->state)) {
1217 if (current->signal & ~current->blocked) {
1218 restore_flags(flags);
1219 return(-ERESTARTSYS);
1220 }
1221 interruptible_sleep_on(&portp->raw_wait);
1222 }
1223 }
1224
1225
1226
1227
1228 EBRDENABLE(brdp);
1229 cp = &((volatile cdkasy_t *) EBRDGETMEMPTR(brdp, portp->addr))->ctrl;
1230 cp->closearg = arg;
1231 cp->close = 1;
1232 hdrp = (volatile cdkhdr_t *) EBRDGETMEMPTR(brdp, CDK_CDKADDR);
1233 hdrp->slavereq |= portp->reqbit;
1234 bits = ((volatile unsigned char *) hdrp) + brdp->slaveoffset + portp->portidx;
1235 *bits |= portp->portbit;
1236 EBRDDISABLE(brdp);
1237
1238 set_bit(ST_CLOSING, &portp->state);
1239 if (wait == 0) {
1240 restore_flags(flags);
1241 return(0);
1242 }
1243
1244
1245
1246
1247
1248 rc = 0;
1249 while (test_bit(ST_CLOSING, &portp->state)) {
1250 if (current->signal & ~current->blocked) {
1251 rc = -ERESTARTSYS;
1252 break;
1253 }
1254 interruptible_sleep_on(&portp->raw_wait);
1255 }
1256 restore_flags(flags);
1257
1258 if ((rc == 0) && (portp->rc != 0))
1259 rc = -EIO;
1260 return(rc);
1261 }
1262
1263
1264
1265
1266
1267
1268
1269
1270
1271
1272 static int stli_cmdwait(stlibrd_t *brdp, stliport_t *portp, unsigned long cmd, void *arg, int size, int copyback)
1273 {
1274 unsigned long flags;
1275
1276 #if DEBUG
1277 printk("stli_cmdwait(brdp=%x,portp=%x,cmd=%x,arg=%x,size=%d,copyback=%d)\n", (int) brdp, (int) portp, (int) cmd, (int) arg, size, copyback);
1278 #endif
1279
1280 save_flags(flags);
1281 cli();
1282 while (test_bit(ST_CMDING, &portp->state)) {
1283 if (current->signal & ~current->blocked) {
1284 restore_flags(flags);
1285 return(-ERESTARTSYS);
1286 }
1287 interruptible_sleep_on(&portp->raw_wait);
1288 }
1289
1290 stli_sendcmd(brdp, portp, cmd, arg, size, copyback);
1291
1292 while (test_bit(ST_CMDING, &portp->state)) {
1293 if (current->signal & ~current->blocked) {
1294 restore_flags(flags);
1295 return(-ERESTARTSYS);
1296 }
1297 interruptible_sleep_on(&portp->raw_wait);
1298 }
1299 restore_flags(flags);
1300
1301 if (portp->rc != 0)
1302 return(-EIO);
1303 return(0);
1304 }
1305
1306
1307
1308
1309
1310
1311
1312
1313 static int stli_setport(stliport_t *portp)
1314 {
1315 stlibrd_t *brdp;
1316 asyport_t aport;
1317
1318 #if DEBUG
1319 printk("stli_setport(portp=%x)\n", (int) portp);
1320 #endif
1321
1322 if (portp == (stliport_t *) NULL)
1323 return(-ENODEV);
1324 if (portp->tty == (struct tty_struct *) NULL)
1325 return(-ENODEV);
1326 if ((portp->brdnr < 0) && (portp->brdnr >= stli_nrbrds))
1327 return(-ENODEV);
1328 brdp = stli_brds[portp->brdnr];
1329 if (brdp == (stlibrd_t *) NULL)
1330 return(-ENODEV);
1331
1332 stli_mkasyport(portp, &aport, portp->tty->termios);
1333 return(stli_cmdwait(brdp, portp, A_SETPORT, &aport, sizeof(asyport_t), 0));
1334 }
1335
1336
1337
1338
1339
1340
1341
1342
1343
1344 static void stli_delay(int len)
1345 {
1346 #if DEBUG
1347 printk("stl_delay(len=%d)\n", len);
1348 #endif
1349 if (len > 0) {
1350 current->state = TASK_INTERRUPTIBLE;
1351 current->timeout = jiffies + len;
1352 schedule();
1353 }
1354 }
1355
1356
1357
1358
1359
1360
1361
1362
1363 static int stli_waitcarrier(stlibrd_t *brdp, stliport_t *portp, struct file *filp)
1364 {
1365 unsigned long flags;
1366 int rc;
1367
1368 #if DEBUG
1369 printk("stli_waitcarrier(brdp=%x,portp=%x,filp=%x)\n", (int) brdp, (int) portp, (int) filp);
1370 #endif
1371
1372 rc = 0;
1373
1374 save_flags(flags);
1375 cli();
1376 portp->openwaitcnt++;
1377 if (portp->refcount > 0)
1378 portp->refcount--;
1379
1380 for (;;) {
1381 if ((portp->flags & ASYNC_CALLOUT_ACTIVE) == 0) {
1382 stli_mkasysigs(&portp->asig, 1, 1);
1383 if ((rc = stli_cmdwait(brdp, portp, A_SETSIGNALS, &portp->asig, sizeof(asysigs_t), 0)) < 0)
1384 break;
1385 }
1386 if (tty_hung_up_p(filp) || ((portp->flags & ASYNC_INITIALIZED) == 0)) {
1387 if (portp->flags & ASYNC_HUP_NOTIFY)
1388 rc = -EBUSY;
1389 else
1390 rc = -ERESTARTSYS;
1391 break;
1392 }
1393 if (((portp->flags & ASYNC_CALLOUT_ACTIVE) == 0) &&
1394 ((portp->flags & ASYNC_CLOSING) == 0) &&
1395 ((portp->tty->termios->c_cflag & CLOCAL) ||
1396 (portp->sigs & TIOCM_CD))) {
1397 break;
1398 }
1399 if (current->signal & ~current->blocked) {
1400 rc = -ERESTARTSYS;
1401 break;
1402 }
1403 interruptible_sleep_on(&portp->open_wait);
1404 }
1405
1406 if (! tty_hung_up_p(filp))
1407 portp->refcount++;
1408 portp->openwaitcnt--;
1409 restore_flags(flags);
1410
1411 return(rc);
1412 }
1413
1414
1415
1416
1417
1418
1419
1420
1421
1422 static int stli_write(struct tty_struct *tty, int from_user, const unsigned char *buf, int count)
1423 {
1424 volatile cdkasy_t *ap;
1425 volatile cdkhdr_t *hdrp;
1426 volatile unsigned char *bits;
1427 unsigned char *shbuf, *chbuf;
1428 stliport_t *portp;
1429 stlibrd_t *brdp;
1430 unsigned int len, stlen, head, tail, size;
1431 unsigned long flags;
1432
1433 #if DEBUG
1434 printk("stli_write(tty=%x,from_user=%d,buf=%x,count=%d)\n", (int) tty, from_user, (int) buf, count);
1435 #endif
1436
1437 if ((tty == (struct tty_struct *) NULL) || (stli_tmpwritebuf == (char *) NULL))
1438 return(0);
1439 if (tty == stli_txcooktty)
1440 stli_flushchars(tty);
1441 portp = tty->driver_data;
1442 if (portp == (stliport_t *) NULL)
1443 return(0);
1444 if ((portp->brdnr < 0) || (portp->brdnr >= stli_nrbrds))
1445 return(0);
1446 brdp = stli_brds[portp->brdnr];
1447 if (brdp == (stlibrd_t *) NULL)
1448 return(0);
1449 chbuf = (unsigned char *) buf;
1450
1451
1452
1453
1454
1455
1456
1457
1458
1459
1460
1461
1462 if (from_user) {
1463 save_flags(flags);
1464 cli();
1465 EBRDENABLE(brdp);
1466 ap = (volatile cdkasy_t *) EBRDGETMEMPTR(brdp, portp->addr);
1467 head = (unsigned int) ap->txq.head;
1468 tail = (unsigned int) ap->txq.tail;
1469 if (tail != ((unsigned int) ap->txq.tail))
1470 tail = (unsigned int) ap->txq.tail;
1471 len = (head >= tail) ? (portp->txsize - (head - tail) - 1) : (tail - head - 1);
1472 count = MIN(len, count);
1473 EBRDDISABLE(brdp);
1474
1475 down(&stli_tmpwritesem);
1476 memcpy_fromfs(stli_tmpwritebuf, chbuf, count);
1477 up(&stli_tmpwritesem);
1478 chbuf = &stli_tmpwritebuf[0];
1479 restore_flags(flags);
1480 }
1481
1482
1483
1484
1485 save_flags(flags);
1486 cli();
1487 EBRDENABLE(brdp);
1488 ap = (volatile cdkasy_t *) EBRDGETMEMPTR(brdp, portp->addr);
1489 head = (unsigned int) ap->txq.head;
1490 tail = (unsigned int) ap->txq.tail;
1491 if (tail != ((unsigned int) ap->txq.tail))
1492 tail = (unsigned int) ap->txq.tail;
1493 size = portp->txsize;
1494 if (head >= tail) {
1495 len = size - (head - tail) - 1;
1496 stlen = size - head;
1497 } else {
1498 len = tail - head - 1;
1499 stlen = len;
1500 }
1501
1502 len = MIN(len, count);
1503 count = 0;
1504 shbuf = (char *) EBRDGETMEMPTR(brdp, portp->txoffset);
1505
1506 while (len > 0) {
1507 stlen = MIN(len, stlen);
1508 memcpy((shbuf + head), chbuf, stlen);
1509 chbuf += stlen;
1510 len -= stlen;
1511 count += stlen;
1512 head += stlen;
1513 if (head >= size) {
1514 head = 0;
1515 stlen = tail;
1516 }
1517 }
1518
1519 ap = (volatile cdkasy_t *) EBRDGETMEMPTR(brdp, portp->addr);
1520 ap->txq.head = head;
1521 if (test_bit(ST_TXBUSY, &portp->state)) {
1522 if (ap->changed.data & DT_TXEMPTY)
1523 ap->changed.data &= ~DT_TXEMPTY;
1524 }
1525 hdrp = (volatile cdkhdr_t *) EBRDGETMEMPTR(brdp, CDK_CDKADDR);
1526 hdrp->slavereq |= portp->reqbit;
1527 bits = ((volatile unsigned char *) hdrp) + brdp->slaveoffset + portp->portidx;
1528 *bits |= portp->portbit;
1529 set_bit(ST_TXBUSY, &portp->state);
1530
1531 EBRDDISABLE(brdp);
1532 restore_flags(flags);
1533
1534 return(count);
1535 }
1536
1537
1538
1539
1540
1541
1542
1543
1544
1545
1546
1547 static void stli_putchar(struct tty_struct *tty, unsigned char ch)
1548 {
1549 #if DEBUG
1550 printk("stli_putchar(tty=%x,ch=%x)\n", (int) tty, (int) ch);
1551 #endif
1552
1553 if (tty == (struct tty_struct *) NULL)
1554 return;
1555 if (tty != stli_txcooktty) {
1556 if (stli_txcooktty != (struct tty_struct *) NULL)
1557 stli_flushchars(stli_txcooktty);
1558 stli_txcooktty = tty;
1559 }
1560
1561 stli_txcookbuf[stli_txcooksize++] = ch;
1562 }
1563
1564
1565
1566
1567
1568
1569
1570
1571
1572
1573
1574 static void stli_flushchars(struct tty_struct *tty)
1575 {
1576 volatile cdkhdr_t *hdrp;
1577 volatile unsigned char *bits;
1578 volatile cdkasy_t *ap;
1579 struct tty_struct *cooktty;
1580 stliport_t *portp;
1581 stlibrd_t *brdp;
1582 unsigned int len, stlen, head, tail, size, count, cooksize;
1583 unsigned char *buf, *shbuf;
1584 unsigned long flags;
1585
1586 #if DEBUG
1587 printk("stli_flushchars(tty=%x)\n", (int) tty);
1588 #endif
1589
1590 cooksize = stli_txcooksize;
1591 cooktty = stli_txcooktty;
1592 stli_txcooksize = 0;
1593 stli_txcookrealsize = 0;
1594 stli_txcooktty = (struct tty_struct *) NULL;
1595
1596 if (tty == (struct tty_struct *) NULL)
1597 return;
1598 if (cooktty == (struct tty_struct *) NULL)
1599 return;
1600 if (tty != cooktty)
1601 tty = cooktty;
1602 if (cooksize == 0)
1603 return;
1604
1605 portp = tty->driver_data;
1606 if (portp == (stliport_t *) NULL)
1607 return;
1608 if ((portp->brdnr < 0) || (portp->brdnr >= stli_nrbrds))
1609 return;
1610 brdp = stli_brds[portp->brdnr];
1611 if (brdp == (stlibrd_t *) NULL)
1612 return;
1613
1614 save_flags(flags);
1615 cli();
1616 EBRDENABLE(brdp);
1617
1618 ap = (volatile cdkasy_t *) EBRDGETMEMPTR(brdp, portp->addr);
1619 head = (unsigned int) ap->txq.head;
1620 tail = (unsigned int) ap->txq.tail;
1621 if (tail != ((unsigned int) ap->txq.tail))
1622 tail = (unsigned int) ap->txq.tail;
1623 size = portp->txsize;
1624 if (head >= tail) {
1625 len = size - (head - tail) - 1;
1626 stlen = size - head;
1627 } else {
1628 len = tail - head - 1;
1629 stlen = len;
1630 }
1631
1632 len = MIN(len, cooksize);
1633 count = 0;
1634 shbuf = (char *) EBRDGETMEMPTR(brdp, portp->txoffset);
1635 buf = stli_txcookbuf;
1636
1637 while (len > 0) {
1638 stlen = MIN(len, stlen);
1639 memcpy((shbuf + head), buf, stlen);
1640 buf += stlen;
1641 len -= stlen;
1642 count += stlen;
1643 head += stlen;
1644 if (head >= size) {
1645 head = 0;
1646 stlen = tail;
1647 }
1648 }
1649
1650 ap = (volatile cdkasy_t *) EBRDGETMEMPTR(brdp, portp->addr);
1651 ap->txq.head = head;
1652
1653 if (test_bit(ST_TXBUSY, &portp->state)) {
1654 if (ap->changed.data & DT_TXEMPTY)
1655 ap->changed.data &= ~DT_TXEMPTY;
1656 }
1657 hdrp = (volatile cdkhdr_t *) EBRDGETMEMPTR(brdp, CDK_CDKADDR);
1658 hdrp->slavereq |= portp->reqbit;
1659 bits = ((volatile unsigned char *) hdrp) + brdp->slaveoffset + portp->portidx;
1660 *bits |= portp->portbit;
1661 set_bit(ST_TXBUSY, &portp->state);
1662
1663 EBRDDISABLE(brdp);
1664 restore_flags(flags);
1665 }
1666
1667
1668
1669 static int stli_writeroom(struct tty_struct *tty)
1670 {
1671 volatile cdkasyrq_t *rp;
1672 stliport_t *portp;
1673 stlibrd_t *brdp;
1674 unsigned int head, tail, len;
1675 unsigned long flags;
1676
1677 #if DEBUG
1678 printk("stli_writeroom(tty=%x)\n", (int) tty);
1679 #endif
1680
1681 if (tty == (struct tty_struct *) NULL)
1682 return(0);
1683 if (tty == stli_txcooktty) {
1684 if (stli_txcookrealsize != 0) {
1685 len = stli_txcookrealsize - stli_txcooksize;
1686 return(len);
1687 }
1688 }
1689
1690 portp = tty->driver_data;
1691 if (portp == (stliport_t *) NULL)
1692 return(0);
1693 if ((portp->brdnr < 0) || (portp->brdnr >= stli_nrbrds))
1694 return(0);
1695 brdp = stli_brds[portp->brdnr];
1696 if (brdp == (stlibrd_t *) NULL)
1697 return(0);
1698
1699 save_flags(flags);
1700 cli();
1701 EBRDENABLE(brdp);
1702 rp = &((volatile cdkasy_t *) EBRDGETMEMPTR(brdp, portp->addr))->txq;
1703 head = (unsigned int) rp->head;
1704 tail = (unsigned int) rp->tail;
1705 if (tail != ((unsigned int) rp->tail))
1706 tail = (unsigned int) rp->tail;
1707 len = (head >= tail) ? (portp->txsize - (head - tail)) : (tail - head);
1708 len--;
1709 EBRDDISABLE(brdp);
1710 restore_flags(flags);
1711
1712 if (tty == stli_txcooktty) {
1713 stli_txcookrealsize = len;
1714 len -= stli_txcooksize;
1715 }
1716 return(len);
1717 }
1718
1719
1720
1721
1722
1723
1724
1725
1726
1727
1728
1729 static int stli_charsinbuffer(struct tty_struct *tty)
1730 {
1731 volatile cdkasyrq_t *rp;
1732 stliport_t *portp;
1733 stlibrd_t *brdp;
1734 unsigned int head, tail, len;
1735 unsigned long flags;
1736
1737 #if DEBUG
1738 printk("stli_charsinbuffer(tty=%x)\n", (int) tty);
1739 #endif
1740
1741 if (tty == (struct tty_struct *) NULL)
1742 return(0);
1743 if (tty == stli_txcooktty)
1744 stli_flushchars(tty);
1745 portp = tty->driver_data;
1746 if (portp == (stliport_t *) NULL)
1747 return(0);
1748 if ((portp->brdnr < 0) || (portp->brdnr >= stli_nrbrds))
1749 return(0);
1750 brdp = stli_brds[portp->brdnr];
1751 if (brdp == (stlibrd_t *) NULL)
1752 return(0);
1753
1754 save_flags(flags);
1755 cli();
1756 EBRDENABLE(brdp);
1757 rp = &((volatile cdkasy_t *) EBRDGETMEMPTR(brdp, portp->addr))->txq;
1758 head = (unsigned int) rp->head;
1759 tail = (unsigned int) rp->tail;
1760 if (tail != ((unsigned int) rp->tail))
1761 tail = (unsigned int) rp->tail;
1762 len = (head >= tail) ? (head - tail) : (portp->txsize - (tail - head));
1763 if ((len == 0) && test_bit(ST_TXBUSY, &portp->state))
1764 len = 1;
1765 EBRDDISABLE(brdp);
1766 restore_flags(flags);
1767
1768 return(len);
1769 }
1770
1771
1772
1773
1774
1775
1776
1777 static void stli_getserial(stliport_t *portp, struct serial_struct *sp)
1778 {
1779 struct serial_struct sio;
1780 stlibrd_t *brdp;
1781
1782 #if DEBUG
1783 printk("stli_getserial(portp=%x,sp=%x)\n", (int) portp, (int) sp);
1784 #endif
1785
1786 memset(&sio, 0, sizeof(struct serial_struct));
1787 sio.type = PORT_UNKNOWN;
1788 sio.line = portp->portnr;
1789 sio.irq = 0;
1790 sio.flags = portp->flags;
1791 sio.baud_base = portp->baud_base;
1792 sio.close_delay = portp->close_delay;
1793 sio.closing_wait = portp->closing_wait;
1794 sio.custom_divisor = portp->custom_divisor;
1795 sio.xmit_fifo_size = 0;
1796 sio.hub6 = 0;
1797
1798 brdp = stli_brds[portp->brdnr];
1799 if (brdp != (stlibrd_t *) NULL)
1800 sio.port = brdp->iobase;
1801
1802 memcpy_tofs(sp, &sio, sizeof(struct serial_struct));
1803 }
1804
1805
1806
1807
1808
1809
1810
1811
1812
1813 static int stli_setserial(stliport_t *portp, struct serial_struct *sp)
1814 {
1815 struct serial_struct sio;
1816 int rc;
1817
1818 #if DEBUG
1819 printk("stli_setserial(portp=%x,sp=%x)\n", (int) portp, (int) sp);
1820 #endif
1821
1822 memcpy_fromfs(&sio, sp, sizeof(struct serial_struct));
1823 if (!suser()) {
1824 if ((sio.baud_base != portp->baud_base) ||
1825 (sio.close_delay != portp->close_delay) ||
1826 ((sio.flags & ~ASYNC_USR_MASK) != (portp->flags & ~ASYNC_USR_MASK)))
1827 return(-EPERM);
1828 }
1829
1830 portp->flags = (portp->flags & ~ASYNC_USR_MASK) | (sio.flags & ASYNC_USR_MASK);
1831 portp->baud_base = sio.baud_base;
1832 portp->close_delay = sio.close_delay;
1833 portp->closing_wait = sio.closing_wait;
1834 portp->custom_divisor = sio.custom_divisor;
1835
1836 if ((rc = stli_setport(portp)) < 0)
1837 return(rc);
1838 return(0);
1839 }
1840
1841
1842
1843 static int stli_ioctl(struct tty_struct *tty, struct file *file, unsigned int cmd, unsigned long arg)
1844 {
1845 stliport_t *portp;
1846 stlibrd_t *brdp;
1847 unsigned long val;
1848 int rc;
1849
1850 #if DEBUG
1851 printk("stli_ioctl(tty=%x,file=%x,cmd=%x,arg=%x)\n", (int) tty, (int) file, cmd, (int) arg);
1852 #endif
1853
1854 if (tty == (struct tty_struct *) NULL)
1855 return(-ENODEV);
1856 portp = tty->driver_data;
1857 if (portp == (stliport_t *) NULL)
1858 return(-ENODEV);
1859 if ((portp->brdnr < 0) || (portp->brdnr >= stli_nrbrds))
1860 return(0);
1861 brdp = stli_brds[portp->brdnr];
1862 if (brdp == (stlibrd_t *) NULL)
1863 return(0);
1864
1865 rc = 0;
1866
1867 switch (cmd) {
1868 case TCSBRK:
1869 if ((rc = tty_check_change(tty)) == 0) {
1870 tty_wait_until_sent(tty, 0);
1871 if (! arg) {
1872 val = 250;
1873 rc = stli_cmdwait(brdp, portp, A_BREAK, &val, sizeof(unsigned long), 0);
1874 }
1875 }
1876 break;
1877 case TCSBRKP:
1878 if ((rc = tty_check_change(tty)) == 0) {
1879 tty_wait_until_sent(tty, 0);
1880 val = (arg ? (arg * 100) : 250);
1881 rc = stli_cmdwait(brdp, portp, A_BREAK, &val, sizeof(unsigned long), 0);
1882 }
1883 break;
1884 case TIOCGSOFTCAR:
1885 if ((rc = verify_area(VERIFY_WRITE, (void *) arg, sizeof(long))) == 0)
1886 put_fs_long(((tty->termios->c_cflag & CLOCAL) ? 1 : 0), (unsigned long *) arg);
1887 break;
1888 case TIOCSSOFTCAR:
1889 if ((rc = verify_area(VERIFY_READ, (void *) arg, sizeof(long))) == 0) {
1890 arg = get_fs_long((unsigned long *) arg);
1891 tty->termios->c_cflag = (tty->termios->c_cflag & ~CLOCAL) | (arg ? CLOCAL : 0);
1892 }
1893 break;
1894 case TIOCMGET:
1895 if ((rc = verify_area(VERIFY_WRITE, (void *) arg, sizeof(unsigned int))) == 0) {
1896 if ((rc = stli_cmdwait(brdp, portp, A_GETSIGNALS, &portp->asig, sizeof(asysigs_t), 1)) < 0)
1897 return(rc);
1898 val = stli_mktiocm(portp->asig.sigvalue);
1899 put_fs_long(val, (unsigned long *) arg);
1900 }
1901 break;
1902 case TIOCMBIS:
1903 if ((rc = verify_area(VERIFY_READ, (void *) arg, sizeof(long))) == 0) {
1904 arg = get_fs_long((unsigned long *) arg);
1905 stli_mkasysigs(&portp->asig, ((arg & TIOCM_DTR) ? 1 : -1), ((arg & TIOCM_RTS) ? 1 : -1));
1906 rc = stli_cmdwait(brdp, portp, A_SETSIGNALS, &portp->asig, sizeof(asysigs_t), 0);
1907 }
1908 break;
1909 case TIOCMBIC:
1910 if ((rc = verify_area(VERIFY_READ, (void *) arg, sizeof(long))) == 0) {
1911 arg = get_fs_long((unsigned long *) arg);
1912 stli_mkasysigs(&portp->asig, ((arg & TIOCM_DTR) ? 0 : -1), ((arg & TIOCM_RTS) ? 0 : -1));
1913 rc = stli_cmdwait(brdp, portp, A_SETSIGNALS, &portp->asig, sizeof(asysigs_t), 0);
1914 }
1915 break;
1916 case TIOCMSET:
1917 if ((rc = verify_area(VERIFY_READ, (void *) arg, sizeof(long))) == 0) {
1918 arg = get_fs_long((unsigned long *) arg);
1919 stli_mkasysigs(&portp->asig, ((arg & TIOCM_DTR) ? 1 : 0), ((arg & TIOCM_RTS) ? 1 : 0));
1920 rc = stli_cmdwait(brdp, portp, A_SETSIGNALS, &portp->asig, sizeof(asysigs_t), 0);
1921 }
1922 break;
1923 case TIOCGSERIAL:
1924 if ((rc = verify_area(VERIFY_WRITE, (void *) arg, sizeof(struct serial_struct))) == 0)
1925 stli_getserial(portp, (struct serial_struct *) arg);
1926 break;
1927 case TIOCSSERIAL:
1928 if ((rc = verify_area(VERIFY_READ, (void *) arg, sizeof(struct serial_struct))) == 0)
1929 rc = stli_setserial(portp, (struct serial_struct *) arg);
1930 break;
1931 case STL_GETPFLAG:
1932 if ((rc = verify_area(VERIFY_WRITE, (void *) arg, sizeof(unsigned long))) == 0)
1933 put_fs_long(portp->pflag, (unsigned long *) arg);
1934 break;
1935 case STL_SETPFLAG:
1936 if ((rc = verify_area(VERIFY_READ, (void *) arg, sizeof(unsigned long))) == 0) {
1937 portp->pflag = get_fs_long((unsigned long *) arg);
1938 stli_setport(portp);
1939 }
1940 break;
1941 case TIOCSERCONFIG:
1942 case TIOCSERGWILD:
1943 case TIOCSERSWILD:
1944 case TIOCSERGETLSR:
1945 case TIOCSERGSTRUCT:
1946 case TIOCSERGETMULTI:
1947 case TIOCSERSETMULTI:
1948 default:
1949 rc = -ENOIOCTLCMD;
1950 break;
1951 }
1952
1953 return(rc);
1954 }
1955
1956
1957
1958
1959
1960
1961
1962
1963 static void stli_settermios(struct tty_struct *tty, struct termios *old)
1964 {
1965 stliport_t *portp;
1966 stlibrd_t *brdp;
1967 struct termios *tiosp;
1968 asyport_t aport;
1969
1970 #if DEBUG
1971 printk("stli_settermios(tty=%x,old=%x)\n", (int) tty, (int) old);
1972 #endif
1973
1974 if (tty == (struct tty_struct *) NULL)
1975 return;
1976 portp = tty->driver_data;
1977 if (portp == (stliport_t *) NULL)
1978 return;
1979 if ((portp->brdnr < 0) || (portp->brdnr >= stli_nrbrds))
1980 return;
1981 brdp = stli_brds[portp->brdnr];
1982 if (brdp == (stlibrd_t *) NULL)
1983 return;
1984
1985 tiosp = tty->termios;
1986 if ((tiosp->c_cflag == old->c_cflag) && (tiosp->c_iflag == old->c_iflag))
1987 return;
1988
1989 stli_mkasyport(portp, &aport, tiosp);
1990 stli_cmdwait(brdp, portp, A_SETPORT, &aport, sizeof(asyport_t), 0);
1991 stli_mkasysigs(&portp->asig, ((tiosp->c_cflag & CBAUD) ? 1 : 0), -1);
1992 stli_cmdwait(brdp, portp, A_SETSIGNALS, &portp->asig, sizeof(asysigs_t), 0);
1993 if ((old->c_cflag & CRTSCTS) && ((tiosp->c_cflag & CRTSCTS) == 0))
1994 tty->hw_stopped = 0;
1995 if (((old->c_cflag & CLOCAL) == 0) && (tiosp->c_cflag & CLOCAL))
1996 wake_up_interruptible(&portp->open_wait);
1997 }
1998
1999
2000
2001
2002
2003
2004
2005
2006
2007
2008
2009
2010
2011 static void stli_throttle(struct tty_struct *tty)
2012 {
2013 stliport_t *portp;
2014
2015 #if DEBUG
2016 printk("stli_throttle(tty=%x)\n", (int) tty);
2017 #endif
2018
2019 if (tty == (struct tty_struct *) NULL)
2020 return;
2021 portp = tty->driver_data;
2022 if (portp == (stliport_t *) NULL)
2023 return;
2024
2025 set_bit(ST_RXSTOP, &portp->state);
2026 }
2027
2028
2029
2030
2031
2032
2033
2034
2035
2036 static void stli_unthrottle(struct tty_struct *tty)
2037 {
2038 stliport_t *portp;
2039
2040 #if DEBUG
2041 printk("stli_unthrottle(tty=%x)\n", (int) tty);
2042 #endif
2043
2044 if (tty == (struct tty_struct *) NULL)
2045 return;
2046 portp = tty->driver_data;
2047 if (portp == (stliport_t *) NULL)
2048 return;
2049
2050 clear_bit(ST_RXSTOP, &portp->state);
2051 }
2052
2053
2054
2055
2056
2057
2058
2059
2060 static void stli_stop(struct tty_struct *tty)
2061 {
2062 stlibrd_t *brdp;
2063 stliport_t *portp;
2064 asyctrl_t actrl;
2065
2066 #if DEBUG
2067 printk("stli_stop(tty=%x)\n", (int) tty);
2068 #endif
2069
2070 if (tty == (struct tty_struct *) NULL)
2071 return;
2072 portp = tty->driver_data;
2073 if (portp == (stliport_t *) NULL)
2074 return;
2075 if ((portp->brdnr < 0) || (portp->brdnr >= stli_nrbrds))
2076 return;
2077 brdp = stli_brds[portp->brdnr];
2078 if (brdp == (stlibrd_t *) NULL)
2079 return;
2080
2081 memset(&actrl, 0, sizeof(asyctrl_t));
2082 actrl.txctrl = CT_STOPFLOW;
2083 #if 0
2084 stli_cmdwait(brdp, portp, A_PORTCTRL, &actrl, sizeof(asyctrl_t));
2085 #endif
2086 }
2087
2088
2089
2090
2091
2092
2093
2094 static void stli_start(struct tty_struct *tty)
2095 {
2096 stliport_t *portp;
2097 stlibrd_t *brdp;
2098 asyctrl_t actrl;
2099
2100 #if DEBUG
2101 printk("stli_start(tty=%x)\n", (int) tty);
2102 #endif
2103
2104 if (tty == (struct tty_struct *) NULL)
2105 return;
2106 portp = tty->driver_data;
2107 if (portp == (stliport_t *) NULL)
2108 return;
2109 if ((portp->brdnr < 0) || (portp->brdnr >= stli_nrbrds))
2110 return;
2111 brdp = stli_brds[portp->brdnr];
2112 if (brdp == (stlibrd_t *) NULL)
2113 return;
2114
2115 memset(&actrl, 0, sizeof(asyctrl_t));
2116 actrl.txctrl = CT_STARTFLOW;
2117 #if 0
2118 stli_cmdwait(brdp, portp, A_PORTCTRL, &actrl, sizeof(asyctrl_t));
2119 #endif
2120 }
2121
2122
2123
2124
2125
2126
2127
2128
2129
2130
2131
2132
2133 static void stli_dohangup(void *arg)
2134 {
2135 stliport_t *portp;
2136
2137 #if DEBUG
2138 printk("stli_dohangup(portp=%x)\n", (int) arg);
2139 #endif
2140
2141 portp = (stliport_t *) arg;
2142 if (portp == (stliport_t *) NULL)
2143 return;
2144 if (portp->tty == (struct tty_struct *) NULL)
2145 return;
2146 tty_hangup(portp->tty);
2147 }
2148
2149
2150
2151
2152
2153
2154
2155
2156
2157
2158 static void stli_hangup(struct tty_struct *tty)
2159 {
2160 stliport_t *portp;
2161 stlibrd_t *brdp;
2162 unsigned long flags;
2163
2164 #if DEBUG
2165 printk("stli_hangup(tty=%x)\n", (int) tty);
2166 #endif
2167
2168 if (tty == (struct tty_struct *) NULL)
2169 return;
2170 portp = tty->driver_data;
2171 if (portp == (stliport_t *) NULL)
2172 return;
2173 if ((portp->brdnr < 0) || (portp->brdnr >= stli_nrbrds))
2174 return;
2175 brdp = stli_brds[portp->brdnr];
2176 if (brdp == (stlibrd_t *) NULL)
2177 return;
2178
2179 portp->flags &= ~ASYNC_INITIALIZED;
2180
2181 save_flags(flags);
2182 cli();
2183 if (! test_bit(ST_CLOSING, &portp->state))
2184 stli_rawclose(brdp, portp, 0, 0);
2185 if (tty->termios->c_cflag & HUPCL) {
2186 stli_mkasysigs(&portp->asig, 0, 0);
2187 if (test_bit(ST_CMDING, &portp->state)) {
2188 set_bit(ST_DOSIGS, &portp->state);
2189 set_bit(ST_DOFLUSHTX, &portp->state);
2190 set_bit(ST_DOFLUSHRX, &portp->state);
2191 } else {
2192 stli_sendcmd(brdp, portp, A_SETSIGNALSF, &portp->asig, sizeof(asysigs_t), 0);
2193 }
2194 }
2195 restore_flags(flags);
2196
2197 clear_bit(ST_TXBUSY, &portp->state);
2198 clear_bit(ST_RXSTOP, &portp->state);
2199 set_bit(TTY_IO_ERROR, &tty->flags);
2200 tty->driver_data = (void *) NULL;
2201 portp->tty = (struct tty_struct *) NULL;
2202 portp->flags &= ~(ASYNC_NORMAL_ACTIVE | ASYNC_CALLOUT_ACTIVE);
2203 portp->refcount = 0;
2204 wake_up_interruptible(&portp->open_wait);
2205 }
2206
2207
2208
2209
2210
2211
2212
2213
2214
2215
2216 static void stli_flushbuffer(struct tty_struct *tty)
2217 {
2218 stliport_t *portp;
2219 stlibrd_t *brdp;
2220 unsigned long ftype, flags;
2221
2222 #if DEBUG
2223 printk("stli_flushbuffer(tty=%x)\n", (int) tty);
2224 #endif
2225
2226 if (tty == (struct tty_struct *) NULL)
2227 return;
2228 portp = tty->driver_data;
2229 if (portp == (stliport_t *) NULL)
2230 return;
2231 if ((portp->brdnr < 0) || (portp->brdnr >= stli_nrbrds))
2232 return;
2233 brdp = stli_brds[portp->brdnr];
2234 if (brdp == (stlibrd_t *) NULL)
2235 return;
2236
2237 save_flags(flags);
2238 cli();
2239 if (tty == stli_txcooktty) {
2240 stli_txcooktty = (struct tty_struct *) NULL;
2241 stli_txcooksize = 0;
2242 stli_txcookrealsize = 0;
2243 }
2244 if (test_bit(ST_CMDING, &portp->state)) {
2245 set_bit(ST_DOFLUSHTX, &portp->state);
2246 } else {
2247 ftype = FLUSHTX;
2248 if (test_bit(ST_DOFLUSHRX, &portp->state)) {
2249 ftype |= FLUSHRX;
2250 clear_bit(ST_DOFLUSHRX, &portp->state);
2251 }
2252 stli_sendcmd(brdp, portp, A_FLUSH, &ftype, sizeof(unsigned long), 0);
2253 }
2254 restore_flags(flags);
2255
2256 wake_up_interruptible(&tty->write_wait);
2257 if ((tty->flags & (1 << TTY_DO_WRITE_WAKEUP)) && tty->ldisc.write_wakeup)
2258 (tty->ldisc.write_wakeup)(tty);
2259 }
2260
2261
2262
2263
2264
2265
2266
2267
2268
2269
2270
2271
2272
2273 static void stli_sendcmd(stlibrd_t *brdp, stliport_t *portp, unsigned long cmd, void *arg, int size, int copyback)
2274 {
2275 volatile cdkhdr_t *hdrp;
2276 volatile cdkctrl_t *cp;
2277 volatile unsigned char *bits;
2278 unsigned long flags;
2279
2280 #if DEBUG
2281 printk("stli_sendcmd(brdp=%x,portp=%x,cmd=%x,arg=%x,size=%d,copyback=%d)\n", (int) brdp, (int) portp, (int) cmd, (int) arg, size, copyback);
2282 #endif
2283
2284 save_flags(flags);
2285 cli();
2286
2287 if (test_bit(ST_CMDING, &portp->state)) {
2288 printk("STALLION: command already busy, cmd=%x!\n", (int) cmd);
2289 restore_flags(flags);
2290 return;
2291 }
2292
2293 EBRDENABLE(brdp);
2294 cp = &((volatile cdkasy_t *) EBRDGETMEMPTR(brdp, portp->addr))->ctrl;
2295 if (size > 0) {
2296 memcpy((void *) &(cp->args[0]), arg, size);
2297 if (copyback) {
2298 portp->argp = arg;
2299 portp->argsize = size;
2300 }
2301 }
2302 cp->status = 0;
2303 cp->cmd = cmd;
2304 hdrp = (volatile cdkhdr_t *) EBRDGETMEMPTR(brdp, CDK_CDKADDR);
2305 hdrp->slavereq |= portp->reqbit;
2306 bits = ((volatile unsigned char *) hdrp) + brdp->slaveoffset + portp->portidx;
2307 *bits |= portp->portbit;
2308 set_bit(ST_CMDING, &portp->state);
2309 EBRDDISABLE(brdp);
2310 restore_flags(flags);
2311 }
2312
2313
2314
2315
2316
2317
2318
2319
2320
2321
2322
2323 static inline void stli_read(stlibrd_t *brdp, stliport_t *portp)
2324 {
2325 volatile cdkasyrq_t *rp;
2326 volatile char *shbuf;
2327 struct tty_struct *tty;
2328 unsigned int head, tail, size;
2329 unsigned int len, stlen;
2330
2331 #if DEBUG
2332 printk("stli_read(brdp=%x,portp=%d)\n", (int) brdp, (int) portp);
2333 #endif
2334
2335 if (test_bit(ST_RXSTOP, &portp->state))
2336 return;
2337 tty = portp->tty;
2338 if (tty == (struct tty_struct *) NULL)
2339 return;
2340
2341 rp = &((volatile cdkasy_t *) EBRDGETMEMPTR(brdp, portp->addr))->rxq;
2342 head = (unsigned int) rp->head;
2343 if (head != ((unsigned int) rp->head))
2344 head = (unsigned int) rp->head;
2345 tail = (unsigned int) rp->tail;
2346 size = portp->rxsize;
2347 if (head >= tail) {
2348 len = head - tail;
2349 stlen = len;
2350 } else {
2351 len = size - (tail - head);
2352 stlen = size - tail;
2353 }
2354
2355 len = MIN(len, (TTY_FLIPBUF_SIZE - tty->flip.count));
2356 shbuf = (volatile char *) EBRDGETMEMPTR(brdp, portp->rxoffset);
2357
2358 while (len > 0) {
2359 stlen = MIN(len, stlen);
2360 memcpy(tty->flip.char_buf_ptr, (char *) (shbuf + tail), stlen);
2361 memset(tty->flip.flag_buf_ptr, 0, stlen);
2362 tty->flip.char_buf_ptr += stlen;
2363 tty->flip.flag_buf_ptr += stlen;
2364 tty->flip.count += stlen;
2365
2366 len -= stlen;
2367 tail += stlen;
2368 if (tail >= size) {
2369 tail = 0;
2370 stlen = head;
2371 }
2372 }
2373 rp = &((volatile cdkasy_t *) EBRDGETMEMPTR(brdp, portp->addr))->rxq;
2374 rp->tail = tail;
2375
2376 if (head != tail)
2377 set_bit(ST_RXING, &portp->state);
2378
2379 tty_schedule_flip(tty);
2380 }
2381
2382
2383
2384
2385
2386
2387
2388
2389
2390 static inline void stli_dodelaycmd(stliport_t *portp, volatile cdkctrl_t *cp)
2391 {
2392 int cmd;
2393
2394 if (test_bit(ST_DOSIGS, &portp->state)) {
2395 if (test_bit(ST_DOFLUSHTX, &portp->state) && test_bit(ST_DOFLUSHRX, &portp->state))
2396 cmd = A_SETSIGNALSF;
2397 else if (test_bit(ST_DOFLUSHTX, &portp->state))
2398 cmd = A_SETSIGNALSFTX;
2399 else if (test_bit(ST_DOFLUSHRX, &portp->state))
2400 cmd = A_SETSIGNALSFRX;
2401 else
2402 cmd = A_SETSIGNALS;
2403 clear_bit(ST_DOFLUSHTX, &portp->state);
2404 clear_bit(ST_DOFLUSHRX, &portp->state);
2405 clear_bit(ST_DOSIGS, &portp->state);
2406 memcpy((void *) &(cp->args[0]), (void *) &portp->asig, sizeof(asysigs_t));
2407 cp->status = 0;
2408 cp->cmd = cmd;
2409 set_bit(ST_CMDING, &portp->state);
2410 } else if (test_bit(ST_DOFLUSHTX, &portp->state) || test_bit(ST_DOFLUSHRX, &portp->state)) {
2411 cmd = ((test_bit(ST_DOFLUSHTX, &portp->state)) ? FLUSHTX : 0);
2412 cmd |= ((test_bit(ST_DOFLUSHRX, &portp->state)) ? FLUSHRX : 0);
2413 clear_bit(ST_DOFLUSHTX, &portp->state);
2414 clear_bit(ST_DOFLUSHRX, &portp->state);
2415 memcpy((void *) &(cp->args[0]), (void *) &cmd, sizeof(int));
2416 cp->status = 0;
2417 cp->cmd = A_FLUSH;
2418 set_bit(ST_CMDING, &portp->state);
2419 }
2420 }
2421
2422
2423
2424
2425
2426
2427
2428
2429
2430
2431
2432 static inline int stli_hostcmd(stlibrd_t *brdp, int channr)
2433 {
2434 volatile cdkasy_t *ap;
2435 volatile cdkctrl_t *cp;
2436 struct tty_struct *tty;
2437 asynotify_t nt;
2438 stliport_t *portp;
2439 unsigned long oldsigs;
2440 int rc, donerx;
2441
2442 #if DEBUG
2443 printk("stli_hostcmd(brdp=%x,channr=%d)\n", (int) brdp, channr);
2444 #endif
2445
2446 portp = brdp->ports[(channr - 1)];
2447 ap = (volatile cdkasy_t *) EBRDGETMEMPTR(brdp, portp->addr);
2448 cp = &ap->ctrl;
2449
2450
2451
2452
2453 if (test_bit(ST_OPENING, &portp->state)) {
2454 rc = (int) cp->openarg;
2455 if ((cp->open == 0) && (rc != 0)) {
2456 if (rc > 0)
2457 rc--;
2458 cp->openarg = 0;
2459 portp->rc = rc;
2460 clear_bit(ST_OPENING, &portp->state);
2461 wake_up_interruptible(&portp->raw_wait);
2462 }
2463 }
2464
2465
2466
2467
2468 if (test_bit(ST_CLOSING, &portp->state)) {
2469 rc = (int) cp->closearg;
2470 if ((cp->close == 0) && (rc != 0)) {
2471 if (rc > 0)
2472 rc--;
2473 cp->closearg = 0;
2474 portp->rc = rc;
2475 clear_bit(ST_CLOSING, &portp->state);
2476 wake_up_interruptible(&portp->raw_wait);
2477 }
2478 }
2479
2480
2481
2482
2483
2484 if (test_bit(ST_CMDING, &portp->state)) {
2485 rc = cp->status;
2486 if ((cp->cmd == 0) && (rc != 0)) {
2487 if (rc > 0)
2488 rc--;
2489 if (portp->argp != (void *) NULL) {
2490 memcpy(portp->argp, (void *) &(cp->args[0]), portp->argsize);
2491 portp->argp = (void *) NULL;
2492 }
2493 cp->status = 0;
2494 portp->rc = rc;
2495 clear_bit(ST_CMDING, &portp->state);
2496 stli_dodelaycmd(portp, cp);
2497 wake_up_interruptible(&portp->raw_wait);
2498 }
2499 }
2500
2501
2502
2503
2504
2505
2506 donerx = 0;
2507
2508 if (ap->notify) {
2509 nt = ap->changed;
2510 ap->notify = 0;
2511 tty = portp->tty;
2512
2513 if (nt.signal & SG_DCD) {
2514 oldsigs = portp->sigs;
2515 portp->sigs = stli_mktiocm(nt.sigvalue);
2516 clear_bit(ST_GETSIGS, &portp->state);
2517 if ((portp->sigs & TIOCM_CD) && ((oldsigs & TIOCM_CD) == 0))
2518 wake_up_interruptible(&portp->open_wait);
2519 if ((oldsigs & TIOCM_CD) && ((portp->sigs & TIOCM_CD) == 0)) {
2520 if (! ((portp->flags & ASYNC_CALLOUT_ACTIVE) &&
2521 (portp->flags & ASYNC_CALLOUT_NOHUP))) {
2522 if (tty != (struct tty_struct *) NULL)
2523 queue_task_irq_off(&portp->tqhangup, &tq_scheduler);
2524 }
2525 }
2526 }
2527
2528 if (nt.data & DT_TXEMPTY)
2529 clear_bit(ST_TXBUSY, &portp->state);
2530 if (nt.data & (DT_TXEMPTY | DT_TXLOW)) {
2531 if (tty != (struct tty_struct *) NULL) {
2532 if ((tty->flags & (1 << TTY_DO_WRITE_WAKEUP)) && tty->ldisc.write_wakeup)
2533 (tty->ldisc.write_wakeup)(tty);
2534 wake_up_interruptible(&tty->write_wait);
2535 }
2536 }
2537
2538 if ((nt.data & DT_RXBREAK) && (portp->rxmarkmsk & BRKINT)) {
2539 if (tty != (struct tty_struct *) NULL) {
2540 if (tty->flip.count < TTY_FLIPBUF_SIZE) {
2541 tty->flip.count++;
2542 *tty->flip.flag_buf_ptr++ = TTY_BREAK;
2543 *tty->flip.char_buf_ptr++ = 0;
2544 #ifndef MODULE
2545 if (portp->flags & ASYNC_SAK)
2546 do_SAK(tty);
2547 #endif
2548 tty_schedule_flip(tty);
2549 }
2550 }
2551 }
2552
2553 if (nt.data & DT_RXBUSY) {
2554 donerx++;
2555 stli_read(brdp, portp);
2556 }
2557 }
2558
2559
2560
2561
2562
2563
2564
2565
2566
2567 if ((!donerx) && test_bit(ST_RXING, &portp->state)) {
2568 clear_bit(ST_RXING, &portp->state);
2569 stli_read(brdp, portp);
2570 }
2571
2572 return(0);
2573 }
2574
2575
2576
2577
2578
2579
2580
2581
2582
2583
2584
2585
2586 static void stli_poll(unsigned long arg)
2587 {
2588 volatile cdkhdr_t *hdrp;
2589 unsigned char bits[(STL_MAXCHANS / 8) + 1];
2590 unsigned char hostreq, slavereq;
2591 stliport_t *portp;
2592 stlibrd_t *brdp;
2593 int bitpos, bitat, bitsize;
2594 int brdnr, channr, nrdevs;
2595
2596 stli_timerlist.expires = STLI_TIMEOUT;
2597 add_timer(&stli_timerlist);
2598
2599
2600
2601
2602 for (brdnr = 0; (brdnr < stli_nrbrds); brdnr++) {
2603 brdp = stli_brds[brdnr];
2604 if (brdp == (stlibrd_t *) NULL)
2605 continue;
2606 if ((brdp->state & BST_STARTED) == 0)
2607 continue;
2608
2609 EBRDENABLE(brdp);
2610 hdrp = (volatile cdkhdr_t *) EBRDGETMEMPTR(brdp, CDK_CDKADDR);
2611 hostreq = hdrp->hostreq;
2612 slavereq = hdrp->slavereq;
2613 bitsize = brdp->bitsize;
2614 nrdevs = brdp->nrdevs;
2615
2616
2617
2618
2619
2620
2621
2622
2623 if (hostreq) {
2624 memcpy(&bits[0], (((unsigned char *) hdrp) + brdp->hostoffset), bitsize);
2625
2626 for (bitpos = 0; (bitpos < bitsize); bitpos++) {
2627 if (bits[bitpos] == 0)
2628 continue;
2629 channr = bitpos * 8;
2630 for (bitat = 0x1; (channr < nrdevs); channr++, bitat <<= 1) {
2631 if (bits[bitpos] & bitat) {
2632 stli_hostcmd(brdp, channr);
2633 }
2634 }
2635 }
2636 }
2637
2638
2639
2640
2641
2642
2643 if (slavereq) {
2644 slavereq = 0;
2645 hostreq = 0;
2646 memcpy(&bits[0], (((unsigned char *) hdrp) + brdp->slaveoffset), bitsize);
2647
2648 for (bitpos = 0; (bitpos < bitsize); bitpos++) {
2649 if (bits[bitpos] == 0)
2650 continue;
2651 channr = bitpos * 8;
2652 for (bitat = 0x1; (channr < nrdevs); channr++, bitat <<= 1) {
2653 if (bits[bitpos] & bitat) {
2654 portp = brdp->ports[(channr - 1)];
2655 if (test_bit(ST_OPENING, &portp->state) ||
2656 test_bit(ST_CLOSING, &portp->state) ||
2657 test_bit(ST_CMDING, &portp->state) ||
2658 test_bit(ST_TXBUSY, &portp->state)) {
2659 slavereq |= portp->reqbit;
2660 } else {
2661 bits[bitpos] &= ~bitat;
2662 hostreq++;
2663 }
2664 }
2665 }
2666 }
2667 hdrp->slavereq = slavereq;
2668 if (hostreq)
2669 memcpy((((unsigned char *) hdrp) + brdp->slaveoffset), &bits[0], bitsize);
2670 }
2671
2672 EBRDDISABLE(brdp);
2673 }
2674 }
2675
2676
2677
2678
2679
2680
2681
2682
2683 static void stli_mkasyport(stliport_t *portp, asyport_t *pp, struct termios *tiosp)
2684 {
2685 #if DEBUG
2686 printk("stli_mkasyport(portp=%x,pp=%x,tiosp=%d)\n", (int) portp, (int) pp, (int) tiosp);
2687 #endif
2688
2689 memset(pp, 0, sizeof(asyport_t));
2690
2691
2692
2693
2694 pp->baudout = tiosp->c_cflag & CBAUD;
2695 if (pp->baudout & CBAUDEX) {
2696 pp->baudout &= ~CBAUDEX;
2697 if ((pp->baudout < 1) || (pp->baudout > 2))
2698 tiosp->c_cflag &= ~CBAUDEX;
2699 else
2700 pp->baudout += 15;
2701 }
2702 pp->baudout = stli_baudrates[pp->baudout];
2703 if ((tiosp->c_cflag & CBAUD) == B38400) {
2704 if ((portp->flags & ASYNC_SPD_MASK) == ASYNC_SPD_HI)
2705 pp->baudout = 57600;
2706 else if ((portp->flags & ASYNC_SPD_MASK) == ASYNC_SPD_VHI)
2707 pp->baudout = 115200;
2708 else if ((portp->flags & ASYNC_SPD_MASK) == ASYNC_SPD_CUST)
2709 pp->baudout = (portp->baud_base / portp->custom_divisor);
2710 }
2711 if (pp->baudout > STL_MAXBAUD)
2712 pp->baudout = STL_MAXBAUD;
2713 pp->baudin = pp->baudout;
2714
2715 switch (tiosp->c_cflag & CSIZE) {
2716 case CS5:
2717 pp->csize = 5;
2718 break;
2719 case CS6:
2720 pp->csize = 6;
2721 break;
2722 case CS7:
2723 pp->csize = 7;
2724 break;
2725 default:
2726 pp->csize = 8;
2727 break;
2728 }
2729
2730 if (tiosp->c_cflag & CSTOPB)
2731 pp->stopbs = PT_STOP2;
2732 else
2733 pp->stopbs = PT_STOP1;
2734
2735 if (tiosp->c_cflag & PARENB) {
2736 if (tiosp->c_cflag & PARODD)
2737 pp->parity = PT_ODDPARITY;
2738 else
2739 pp->parity = PT_EVENPARITY;
2740 } else {
2741 pp->parity = PT_NOPARITY;
2742 }
2743
2744
2745
2746
2747 if (tiosp->c_iflag & IXON) {
2748 pp->flow |= F_IXON;
2749 if (tiosp->c_iflag & IXANY)
2750 pp->flow |= F_IXANY;
2751 }
2752 if (tiosp->c_cflag & CRTSCTS)
2753 pp->flow |= (F_RTSFLOW | F_CTSFLOW);
2754
2755 pp->startin = tiosp->c_cc[VSTART];
2756 pp->stopin = tiosp->c_cc[VSTOP];
2757 pp->startout = tiosp->c_cc[VSTART];
2758 pp->stopout = tiosp->c_cc[VSTOP];
2759
2760
2761
2762
2763
2764
2765
2766 if (tiosp->c_iflag & IGNPAR)
2767 pp->iflag |= FI_IGNRXERRS;
2768 if (tiosp->c_iflag & IGNBRK)
2769 pp->iflag |= FI_IGNBREAK;
2770
2771 portp->rxmarkmsk = 0;
2772 if (tiosp->c_iflag & (INPCK | PARMRK))
2773 pp->iflag |= FI_1MARKRXERRS;
2774 if (tiosp->c_iflag & BRKINT)
2775 portp->rxmarkmsk |= BRKINT;
2776
2777
2778
2779
2780 pp->pflag = portp->pflag;
2781 }
2782
2783
2784
2785
2786
2787
2788
2789
2790 static void stli_mkasysigs(asysigs_t *sp, int dtr, int rts)
2791 {
2792 #if DEBUG
2793 printk("stli_mkasysigs(sp=%x,dtr=%d,rts=%d)\n", (int) sp, dtr, rts);
2794 #endif
2795
2796 memset(sp, 0, sizeof(asysigs_t));
2797 if (dtr >= 0) {
2798 sp->signal |= SG_DTR;
2799 sp->sigvalue |= ((dtr > 0) ? SG_DTR : 0);
2800 }
2801 if (rts >= 0) {
2802 sp->signal |= SG_RTS;
2803 sp->sigvalue |= ((rts > 0) ? SG_RTS : 0);
2804 }
2805 }
2806
2807
2808
2809
2810
2811
2812
2813
2814 static long stli_mktiocm(unsigned long sigvalue)
2815 {
2816 long tiocm;
2817
2818 #if DEBUG
2819 printk("stli_mktiocm(sigvalue=%x)\n", (int) sigvalue);
2820 #endif
2821
2822 tiocm = 0;
2823 tiocm |= ((sigvalue & SG_DCD) ? TIOCM_CD : 0);
2824 tiocm |= ((sigvalue & SG_CTS) ? TIOCM_CTS : 0);
2825 tiocm |= ((sigvalue & SG_RI) ? TIOCM_RI : 0);
2826 tiocm |= ((sigvalue & SG_DSR) ? TIOCM_DSR : 0);
2827 tiocm |= ((sigvalue & SG_DTR) ? TIOCM_DTR : 0);
2828 tiocm |= ((sigvalue & SG_RTS) ? TIOCM_RTS : 0);
2829 return(tiocm);
2830 }
2831
2832
2833
2834
2835
2836
2837
2838
2839 static int stli_initports(stlibrd_t *brdp)
2840 {
2841 stliport_t *portp;
2842 int i, panelnr, panelport;
2843
2844 #if DEBUG
2845 printk("stli_initports(brdp=%x)\n", (int) brdp);
2846 #endif
2847
2848 for (i = 0, panelnr = 0, panelport = 0; (i < brdp->nrports); i++) {
2849 portp = (stliport_t *) stli_memalloc(sizeof(stliport_t));
2850 if (portp == (stliport_t *) NULL) {
2851 printk("STALLION: failed to allocate port structure\n");
2852 continue;
2853 }
2854
2855 memset(portp, 0, sizeof(stliport_t));
2856 portp->portnr = i;
2857 portp->brdnr = brdp->brdnr;
2858 portp->panelnr = panelnr;
2859 portp->baud_base = STL_BAUDBASE;
2860 portp->close_delay = STL_CLOSEDELAY;
2861 portp->closing_wait = 30 * HZ;
2862 portp->tqhangup.routine = stli_dohangup;
2863 portp->tqhangup.data = portp;
2864 portp->normaltermios = stli_deftermios;
2865 portp->callouttermios = stli_deftermios;
2866 panelport++;
2867 if (panelport >= brdp->panels[panelnr]) {
2868 panelport = 0;
2869 panelnr++;
2870 }
2871 brdp->ports[i] = portp;
2872 }
2873
2874 return(0);
2875 }
2876
2877
2878
2879
2880
2881
2882
2883 static void stli_ecpinit(stlibrd_t *brdp)
2884 {
2885 unsigned long memconf;
2886
2887 #if DEBUG
2888 printk("stli_ecpinit(brdp=%d)\n", (int) brdp);
2889 #endif
2890
2891 outb(ECP_ATSTOP, (brdp->iobase + ECP_ATCONFR));
2892 udelay(10);
2893 outb(ECP_ATDISABLE, (brdp->iobase + ECP_ATCONFR));
2894 udelay(100);
2895
2896 memconf = (brdp->memaddr & ECP_ATADDRMASK) >> ECP_ATADDRSHFT;
2897 outb(memconf, (brdp->iobase + ECP_ATMEMAR));
2898 }
2899
2900
2901
2902 static void stli_ecpenable(stlibrd_t *brdp)
2903 {
2904 #if DEBUG
2905 printk("stli_ecpenable(brdp=%x)\n", (int) brdp);
2906 #endif
2907 outb(ECP_ATENABLE, (brdp->iobase + ECP_ATCONFR));
2908 }
2909
2910
2911
2912 static void stli_ecpdisable(stlibrd_t *brdp)
2913 {
2914 #if DEBUG
2915 printk("stli_ecpdisable(brdp=%x)\n", (int) brdp);
2916 #endif
2917 outb(ECP_ATDISABLE, (brdp->iobase + ECP_ATCONFR));
2918 }
2919
2920
2921
2922 static char *stli_ecpgetmemptr(stlibrd_t *brdp, unsigned long offset, int line)
2923 {
2924 void *ptr;
2925 unsigned char val;
2926
2927 #if DEBUG
2928 printk("stli_ecpgetmemptr(brdp=%x,offset=%x)\n", (int) brdp, (int) offset);
2929 #endif
2930
2931 if (offset > brdp->memsize) {
2932 printk("STALLION: shared memory pointer=%x out of range at line=%d(%d), brd=%d\n", (int) offset, line, __LINE__, brdp->brdnr);
2933 ptr = 0;
2934 val = 0;
2935 } else {
2936 ptr = brdp->membase + (offset % ECP_ATPAGESIZE);
2937 val = (unsigned char) (offset / ECP_ATPAGESIZE);
2938 }
2939 outb(val, (brdp->iobase + ECP_ATMEMPR));
2940 return(ptr);
2941 }
2942
2943
2944
2945 static void stli_ecpreset(stlibrd_t *brdp)
2946 {
2947 #if DEBUG
2948 printk("stli_ecpreset(brdp=%x)\n", (int) brdp);
2949 #endif
2950
2951 outb(ECP_ATSTOP, (brdp->iobase + ECP_ATCONFR));
2952 udelay(10);
2953 outb(ECP_ATDISABLE, (brdp->iobase + ECP_ATCONFR));
2954 udelay(500);
2955 }
2956
2957
2958
2959 static void stli_ecpintr(stlibrd_t *brdp)
2960 {
2961 #if DEBUG
2962 printk("stli_ecpintr(brdp=%x)\n", (int) brdp);
2963 #endif
2964 outb(0x1, brdp->iobase);
2965 }
2966
2967
2968
2969
2970
2971
2972
2973 static void stli_ecpeiinit(stlibrd_t *brdp)
2974 {
2975 unsigned long memconf;
2976
2977 #if DEBUG
2978 printk("stli_ecpeiinit(brdp=%x)\n", (int) brdp);
2979 #endif
2980
2981 outb(0x1, (brdp->iobase + ECP_EIBRDENAB));
2982 outb(ECP_EISTOP, (brdp->iobase + ECP_EICONFR));
2983 udelay(10);
2984 outb(ECP_EIDISABLE, (brdp->iobase + ECP_EICONFR));
2985 udelay(500);
2986
2987 memconf = (brdp->memaddr & ECP_EIADDRMASKL) >> ECP_EIADDRSHFTL;
2988 outb(memconf, (brdp->iobase + ECP_EIMEMARL));
2989 memconf = (brdp->memaddr & ECP_EIADDRMASKH) >> ECP_EIADDRSHFTH;
2990 outb(memconf, (brdp->iobase + ECP_EIMEMARH));
2991 }
2992
2993
2994
2995 static void stli_ecpeienable(stlibrd_t *brdp)
2996 {
2997 outb(ECP_EIENABLE, (brdp->iobase + ECP_EICONFR));
2998 }
2999
3000
3001
3002 static void stli_ecpeidisable(stlibrd_t *brdp)
3003 {
3004 outb(ECP_EIDISABLE, (brdp->iobase + ECP_EICONFR));
3005 }
3006
3007
3008
3009 static char *stli_ecpeigetmemptr(stlibrd_t *brdp, unsigned long offset, int line)
3010 {
3011 void *ptr;
3012 unsigned char val;
3013
3014 #if DEBUG
3015 printk("stli_ecpeigetmemptr(brdp=%x,offset=%x,line=%d)\n", (int) brdp, (int) offset, line);
3016 #endif
3017
3018 if (offset > brdp->memsize) {
3019 printk("STALLION: shared memory pointer=%x out of range at line=%d(%d), brd=%d\n", (int) offset, line, __LINE__, brdp->brdnr);
3020 ptr = 0;
3021 val = 0;
3022 } else {
3023 ptr = brdp->membase + (offset % ECP_EIPAGESIZE);
3024 if (offset < ECP_EIPAGESIZE)
3025 val = ECP_EIENABLE;
3026 else
3027 val = ECP_EIENABLE | 0x40;
3028 }
3029 outb(val, (brdp->iobase + ECP_EICONFR));
3030 return(ptr);
3031 }
3032
3033
3034
3035 static void stli_ecpeireset(stlibrd_t *brdp)
3036 {
3037 outb(ECP_EISTOP, (brdp->iobase + ECP_EICONFR));
3038 udelay(10);
3039 outb(ECP_EIDISABLE, (brdp->iobase + ECP_EICONFR));
3040 udelay(500);
3041 }
3042
3043
3044
3045
3046
3047
3048
3049 static void stli_ecpmcenable(stlibrd_t *brdp)
3050 {
3051 outb(ECP_MCENABLE, (brdp->iobase + ECP_MCCONFR));
3052 }
3053
3054
3055
3056 static void stli_ecpmcdisable(stlibrd_t *brdp)
3057 {
3058 outb(ECP_MCDISABLE, (brdp->iobase + ECP_MCCONFR));
3059 }
3060
3061
3062
3063 static char *stli_ecpmcgetmemptr(stlibrd_t *brdp, unsigned long offset, int line)
3064 {
3065 void *ptr;
3066 unsigned char val;
3067
3068 if (offset > brdp->memsize) {
3069 printk("STALLION: shared memory pointer=%x out of range at line=%d(%d), brd=%d\n", (int) offset, line, __LINE__, brdp->brdnr);
3070 ptr = 0;
3071 val = 0;
3072 } else {
3073 ptr = brdp->membase + (offset % ECP_MCPAGESIZE);
3074 val = ((unsigned char) (offset / ECP_MCPAGESIZE)) | ECP_MCENABLE;
3075 }
3076 outb(val, (brdp->iobase + ECP_MCCONFR));
3077 return(ptr);
3078 }
3079
3080
3081
3082 static void stli_ecpmcreset(stlibrd_t *brdp)
3083 {
3084 outb(ECP_MCSTOP, (brdp->iobase + ECP_MCCONFR));
3085 udelay(10);
3086 outb(ECP_MCDISABLE, (brdp->iobase + ECP_MCCONFR));
3087 udelay(500);
3088 }
3089
3090
3091
3092
3093
3094
3095
3096 static void stli_onbinit(stlibrd_t *brdp)
3097 {
3098 unsigned long memconf;
3099 int i;
3100
3101 #if DEBUG
3102 printk("stli_onbinit(brdp=%d)\n", (int) brdp);
3103 #endif
3104
3105 outb(ONB_ATSTOP, (brdp->iobase + ONB_ATCONFR));
3106 udelay(10);
3107 outb(ONB_ATDISABLE, (brdp->iobase + ONB_ATCONFR));
3108 for (i = 0; (i < 1000); i++)
3109 udelay(1000);
3110
3111 memconf = (brdp->memaddr & ONB_ATADDRMASK) >> ONB_ATADDRSHFT;
3112 outb(memconf, (brdp->iobase + ONB_ATMEMAR));
3113 outb(0x1, brdp->iobase);
3114 udelay(1000);
3115 }
3116
3117
3118
3119 static void stli_onbenable(stlibrd_t *brdp)
3120 {
3121 #if DEBUG
3122 printk("stli_onbenable(brdp=%x)\n", (int) brdp);
3123 #endif
3124 outb((ONB_ATENABLE | ONB_HIMEMENAB), (brdp->iobase + ONB_ATCONFR));
3125 }
3126
3127
3128
3129 static void stli_onbdisable(stlibrd_t *brdp)
3130 {
3131 #if DEBUG
3132 printk("stli_onbdisable(brdp=%x)\n", (int) brdp);
3133 #endif
3134 outb(ONB_ATDISABLE, (brdp->iobase + ONB_ATCONFR));
3135 }
3136
3137
3138
3139 static char *stli_onbgetmemptr(stlibrd_t *brdp, unsigned long offset, int line)
3140 {
3141 void *ptr;
3142
3143 #if DEBUG
3144 printk("stli_onbgetmemptr(brdp=%x,offset=%x)\n", (int) brdp, (int) offset);
3145 #endif
3146
3147 if (offset > brdp->memsize) {
3148 printk("STALLION: shared memory pointer=%x out of range at line=%d(%d), brd=%d\n", (int) offset, line, __LINE__, brdp->brdnr);
3149 ptr = 0;
3150 } else {
3151 ptr = brdp->membase + (offset % ONB_ATPAGESIZE);
3152 }
3153 return(ptr);
3154 }
3155
3156
3157
3158 static void stli_onbreset(stlibrd_t *brdp)
3159 {
3160 int i;
3161
3162 #if DEBUG
3163 printk("stli_onbreset(brdp=%x)\n", (int) brdp);
3164 #endif
3165
3166 outb(ONB_ATSTOP, (brdp->iobase + ONB_ATCONFR));
3167 udelay(10);
3168 outb(ONB_ATDISABLE, (brdp->iobase + ONB_ATCONFR));
3169 for (i = 0; (i < 1000); i++)
3170 udelay(1000);
3171 }
3172
3173
3174
3175
3176
3177
3178
3179 static void stli_onbeinit(stlibrd_t *brdp)
3180 {
3181 unsigned long memconf;
3182 int i;
3183
3184 #if DEBUG
3185 printk("stli_onbeinit(brdp=%d)\n", (int) brdp);
3186 #endif
3187
3188 outb(0x1, (brdp->iobase + ONB_EIBRDENAB));
3189 outb(ONB_EISTOP, (brdp->iobase + ONB_EICONFR));
3190 udelay(10);
3191 outb(ONB_EIDISABLE, (brdp->iobase + ONB_EICONFR));
3192 for (i = 0; (i < 1000); i++)
3193 udelay(1000);
3194
3195 memconf = (brdp->memaddr & ONB_EIADDRMASKL) >> ONB_EIADDRSHFTL;
3196 outb(memconf, (brdp->iobase + ONB_EIMEMARL));
3197 memconf = (brdp->memaddr & ONB_EIADDRMASKH) >> ONB_EIADDRSHFTH;
3198 outb(memconf, (brdp->iobase + ONB_EIMEMARH));
3199 outb(0x1, brdp->iobase);
3200 udelay(1000);
3201 }
3202
3203
3204
3205 static void stli_onbeenable(stlibrd_t *brdp)
3206 {
3207 #if DEBUG
3208 printk("stli_onbeenable(brdp=%x)\n", (int) brdp);
3209 #endif
3210 outb(ONB_EIENABLE, (brdp->iobase + ONB_EICONFR));
3211 }
3212
3213
3214
3215 static void stli_onbedisable(stlibrd_t *brdp)
3216 {
3217 #if DEBUG
3218 printk("stli_onbedisable(brdp=%x)\n", (int) brdp);
3219 #endif
3220 outb(ONB_EIDISABLE, (brdp->iobase + ONB_EICONFR));
3221 }
3222
3223
3224
3225 static char *stli_onbegetmemptr(stlibrd_t *brdp, unsigned long offset, int line)
3226 {
3227 void *ptr;
3228 unsigned char val;
3229
3230 #if DEBUG
3231 printk("stli_onbegetmemptr(brdp=%x,offset=%x,line=%d)\n", (int) brdp, (int) offset, line);
3232 #endif
3233
3234 if (offset > brdp->memsize) {
3235 printk("STALLION: shared memory pointer=%x out of range at line=%d(%d), brd=%d\n", (int) offset, line, __LINE__, brdp->brdnr);
3236 ptr = 0;
3237 val = 0;
3238 } else {
3239 ptr = brdp->membase + (offset % ONB_EIPAGESIZE);
3240 if (offset < ONB_EIPAGESIZE)
3241 val = ONB_EIENABLE;
3242 else
3243 val = ONB_EIENABLE | 0x40;
3244 }
3245 outb(val, (brdp->iobase + ONB_EICONFR));
3246 return(ptr);
3247 }
3248
3249
3250
3251 static void stli_onbereset(stlibrd_t *brdp)
3252 {
3253 int i;
3254
3255 #if DEBUG
3256 printk("stli_onbereset(brdp=%x)\n", (int) brdp);
3257 #endif
3258
3259 outb(ONB_EISTOP, (brdp->iobase + ONB_EICONFR));
3260 udelay(10);
3261 outb(ONB_EIDISABLE, (brdp->iobase + ONB_EICONFR));
3262 for (i = 0; (i < 1000); i++)
3263 udelay(1000);
3264 }
3265
3266
3267
3268
3269
3270
3271
3272 static void stli_bbyinit(stlibrd_t *brdp)
3273 {
3274 int i;
3275
3276 #if DEBUG
3277 printk("stli_bbyinit(brdp=%d)\n", (int) brdp);
3278 #endif
3279
3280 outb(BBY_ATSTOP, (brdp->iobase + BBY_ATCONFR));
3281 udelay(10);
3282 outb(0, (brdp->iobase + BBY_ATCONFR));
3283 for (i = 0; (i < 1000); i++)
3284 udelay(1000);
3285 outb(0x1, brdp->iobase);
3286 udelay(1000);
3287 }
3288
3289
3290
3291 static char *stli_bbygetmemptr(stlibrd_t *brdp, unsigned long offset, int line)
3292 {
3293 void *ptr;
3294 unsigned char val;
3295
3296 #if DEBUG
3297 printk("stli_bbygetmemptr(brdp=%x,offset=%x)\n", (int) brdp, (int) offset);
3298 #endif
3299
3300 if (offset > brdp->memsize) {
3301 printk("STALLION: shared memory pointer=%x out of range at line=%d(%d), brd=%d\n", (int) offset, line, __LINE__, brdp->brdnr);
3302 ptr = 0;
3303 val = 0;
3304 } else {
3305 ptr = brdp->membase + (offset % BBY_PAGESIZE);
3306 val = (unsigned char) (offset / BBY_PAGESIZE);
3307 }
3308 outb(val, (brdp->iobase + BBY_ATCONFR));
3309 return(ptr);
3310 }
3311
3312
3313
3314 static void stli_bbyreset(stlibrd_t *brdp)
3315 {
3316 int i;
3317
3318 #if DEBUG
3319 printk("stli_bbyreset(brdp=%x)\n", (int) brdp);
3320 #endif
3321
3322 outb(BBY_ATSTOP, (brdp->iobase + BBY_ATCONFR));
3323 udelay(10);
3324 outb(0, (brdp->iobase + BBY_ATCONFR));
3325 for (i = 0; (i < 1000); i++)
3326 udelay(1000);
3327 }
3328
3329
3330
3331
3332
3333
3334
3335 static void stli_stalinit(stlibrd_t *brdp)
3336 {
3337 int i;
3338
3339 #if DEBUG
3340 printk("stli_stalinit(brdp=%d)\n", (int) brdp);
3341 #endif
3342
3343 outb(0x1, brdp->iobase);
3344 for (i = 0; (i < 1000); i++)
3345 udelay(1000);
3346 }
3347
3348
3349
3350 static char *stli_stalgetmemptr(stlibrd_t *brdp, unsigned long offset, int line)
3351 {
3352 void *ptr;
3353
3354 #if DEBUG
3355 printk("stli_stalgetmemptr(brdp=%x,offset=%x)\n", (int) brdp, (int) offset);
3356 #endif
3357
3358 if (offset > brdp->memsize) {
3359 printk("STALLION: shared memory pointer=%x out of range at line=%d(%d), brd=%d\n", (int) offset, line, __LINE__, brdp->brdnr);
3360 ptr = 0;
3361 } else {
3362 ptr = brdp->membase + (offset % STAL_PAGESIZE);
3363 }
3364 return(ptr);
3365 }
3366
3367
3368
3369 static void stli_stalreset(stlibrd_t *brdp)
3370 {
3371 volatile unsigned long *vecp;
3372 int i;
3373
3374 #if DEBUG
3375 printk("stli_stalreset(brdp=%x)\n", (int) brdp);
3376 #endif
3377
3378 vecp = (volatile unsigned long *) (brdp->membase + 0x30);
3379 *vecp = 0xffff0000;
3380 outb(0, brdp->iobase);
3381 for (i = 0; (i < 1000); i++)
3382 udelay(1000);
3383 }
3384
3385
3386
3387 #if STLI_HIMEMORY
3388
3389 #define PAGE_IOMEM __pgprot(_PAGE_PRESENT | _PAGE_RW | _PAGE_DIRTY | _PAGE_ACCESSED | _PAGE_PCD)
3390
3391
3392
3393
3394
3395
3396
3397 static void *stli_mapbrdmem(unsigned long physaddr, unsigned int size)
3398 {
3399 void *virtaddr;
3400 int rc;
3401
3402 #if DEBUG
3403 printk("stli_mapbrdmem(physaddr=%x,size=%x)\n", (int) physaddr, size);
3404 #endif
3405
3406 if ((virtaddr = vmalloc(size)) == (char *) NULL) {
3407 printk("STALLION: failed to allocate virtual address space, size=%x\n", size);
3408 return((void *) NULL);
3409 }
3410 if ((rc = remap_page_range((TASK_SIZE + ((unsigned long) virtaddr)), physaddr, size, PAGE_IOMEM))) {
3411 printk("STALLION: failed to map phyiscal address=%x, errno=%d\n", (int) physaddr, rc);
3412 return((void *) NULL);
3413 }
3414 return(virtaddr);
3415 }
3416
3417 #endif
3418
3419
3420
3421
3422
3423
3424
3425
3426 static int stli_initecp(stlibrd_t *brdp)
3427 {
3428 cdkecpsig_t sig;
3429 cdkecpsig_t *sigsp;
3430 unsigned int status, nxtid;
3431 int panelnr;
3432
3433 #if DEBUG
3434 printk("stli_initecp(brdp=%x)\n", (int) brdp);
3435 #endif
3436
3437
3438
3439
3440 if ((brdp->iobase == 0) || (brdp->memaddr == 0))
3441 return(-ENODEV);
3442
3443
3444
3445
3446
3447
3448 switch (brdp->brdtype) {
3449 case BRD_ECP:
3450 brdp->membase = (void *) brdp->memaddr;
3451 brdp->memsize = ECP_MEMSIZE;
3452 brdp->pagesize = ECP_ATPAGESIZE;
3453 brdp->init = stli_ecpinit;
3454 brdp->enable = stli_ecpenable;
3455 brdp->reenable = stli_ecpenable;
3456 brdp->disable = stli_ecpdisable;
3457 brdp->getmemptr = stli_ecpgetmemptr;
3458 brdp->intr = stli_ecpintr;
3459 brdp->reset = stli_ecpreset;
3460 break;
3461
3462 case BRD_ECPE:
3463 brdp->membase = (void *) brdp->memaddr;
3464 brdp->memsize = ECP_MEMSIZE;
3465 brdp->pagesize = ECP_EIPAGESIZE;
3466 brdp->init = stli_ecpeiinit;
3467 brdp->enable = stli_ecpeienable;
3468 brdp->reenable = stli_ecpeienable;
3469 brdp->disable = stli_ecpeidisable;
3470 brdp->getmemptr = stli_ecpeigetmemptr;
3471 brdp->intr = stli_ecpintr;
3472 brdp->reset = stli_ecpeireset;
3473 break;
3474
3475 case BRD_ECPMC:
3476 brdp->membase = (void *) brdp->memaddr;
3477 brdp->memsize = ECP_MEMSIZE;
3478 brdp->pagesize = ECP_MCPAGESIZE;
3479 brdp->init = NULL;
3480 brdp->enable = stli_ecpmcenable;
3481 brdp->reenable = stli_ecpmcenable;
3482 brdp->disable = stli_ecpmcdisable;
3483 brdp->getmemptr = stli_ecpmcgetmemptr;
3484 brdp->intr = stli_ecpintr;
3485 brdp->reset = stli_ecpmcreset;
3486 break;
3487
3488 default:
3489 return(-EINVAL);
3490 }
3491
3492
3493
3494
3495
3496
3497
3498 EBRDINIT(brdp);
3499
3500 #if STLI_HIMEMORY
3501 if (brdp->memaddr > 0x100000) {
3502 brdp->membase = stli_mapbrdmem(brdp->memaddr, brdp->memsize);
3503 if (brdp->membase == (void *) NULL)
3504 return(-ENOMEM);
3505 }
3506 #endif
3507
3508
3509
3510
3511
3512
3513 EBRDENABLE(brdp);
3514 sigsp = (cdkecpsig_t *) EBRDGETMEMPTR(brdp, CDK_SIGADDR);
3515 memcpy(&sig, sigsp, sizeof(cdkecpsig_t));
3516 EBRDDISABLE(brdp);
3517
3518 #if 0
3519 printk("%s(%d): sig-> magic=%x romver=%x panel=%x,%x,%x,%x,%x,%x,%x,%x\n",
3520 __FILE__, __LINE__, (int) sig.magic, sig.romver, sig.panelid[0],
3521 (int) sig.panelid[1], (int) sig.panelid[2], (int) sig.panelid[3],
3522 (int) sig.panelid[4], (int) sig.panelid[5], (int) sig.panelid[6],
3523 (int) sig.panelid[7]);
3524 #endif
3525
3526 if (sig.magic != ECP_MAGIC)
3527 return(-ENODEV);
3528
3529
3530
3531
3532
3533 for (panelnr = 0, nxtid = 0; (panelnr < STL_MAXPANELS); panelnr++) {
3534 status = sig.panelid[nxtid];
3535 if ((status & ECH_PNLIDMASK) != nxtid)
3536 break;
3537 if (status & ECH_PNL16PORT) {
3538 brdp->panels[panelnr] = 16;
3539 brdp->nrports += 16;
3540 nxtid += 2;
3541 } else {
3542 brdp->panels[panelnr] = 8;
3543 brdp->nrports += 8;
3544 nxtid++;
3545 }
3546 brdp->nrpanels++;
3547 }
3548
3549 request_region(brdp->iobase, ECP_IOSIZE, "serial(ECP)");
3550 brdp->state |= BST_FOUND;
3551 return(0);
3552 }
3553
3554
3555
3556
3557
3558
3559
3560
3561 static int stli_initonb(stlibrd_t *brdp)
3562 {
3563 cdkonbsig_t sig;
3564 cdkonbsig_t *sigsp;
3565 int i;
3566
3567 #if DEBUG
3568 printk("stli_initonb(brdp=%x)\n", (int) brdp);
3569 #endif
3570
3571
3572
3573
3574 if ((brdp->iobase == 0) || (brdp->memaddr == 0))
3575 return(-ENODEV);
3576
3577
3578
3579
3580
3581
3582 switch (brdp->brdtype) {
3583 case BRD_ONBOARD:
3584 case BRD_ONBOARD32:
3585 case BRD_ONBOARD2:
3586 case BRD_ONBOARD2_32:
3587 case BRD_ONBOARDRS:
3588 brdp->membase = (void *) brdp->memaddr;
3589 brdp->memsize = ONB_MEMSIZE;
3590 brdp->pagesize = ONB_ATPAGESIZE;
3591 brdp->init = stli_onbinit;
3592 brdp->enable = stli_onbenable;
3593 brdp->reenable = stli_onbenable;
3594 brdp->disable = stli_onbdisable;
3595 brdp->getmemptr = stli_onbgetmemptr;
3596 brdp->intr = stli_ecpintr;
3597 brdp->reset = stli_onbreset;
3598 break;
3599
3600 case BRD_ONBOARDE:
3601 brdp->membase = (void *) brdp->memaddr;
3602 brdp->memsize = ONB_EIMEMSIZE;
3603 brdp->pagesize = ONB_EIPAGESIZE;
3604 brdp->init = stli_onbeinit;
3605 brdp->enable = stli_onbeenable;
3606 brdp->reenable = stli_onbeenable;
3607 brdp->disable = stli_onbedisable;
3608 brdp->getmemptr = stli_onbegetmemptr;
3609 brdp->intr = stli_ecpintr;
3610 brdp->reset = stli_onbereset;
3611 break;
3612
3613 case BRD_BRUMBY4:
3614 case BRD_BRUMBY8:
3615 case BRD_BRUMBY16:
3616 brdp->membase = (void *) brdp->memaddr;
3617 brdp->memsize = BBY_MEMSIZE;
3618 brdp->pagesize = BBY_PAGESIZE;
3619 brdp->init = stli_bbyinit;
3620 brdp->enable = NULL;
3621 brdp->reenable = NULL;
3622 brdp->disable = NULL;
3623 brdp->getmemptr = stli_bbygetmemptr;
3624 brdp->intr = stli_ecpintr;
3625 brdp->reset = stli_bbyreset;
3626 break;
3627
3628 case BRD_STALLION:
3629 brdp->membase = (void *) brdp->memaddr;
3630 brdp->memsize = STAL_MEMSIZE;
3631 brdp->pagesize = STAL_PAGESIZE;
3632 brdp->init = stli_stalinit;
3633 brdp->enable = NULL;
3634 brdp->reenable = NULL;
3635 brdp->disable = NULL;
3636 brdp->getmemptr = stli_stalgetmemptr;
3637 brdp->intr = stli_ecpintr;
3638 brdp->reset = stli_stalreset;
3639 break;
3640
3641 default:
3642 return(-EINVAL);
3643 }
3644
3645
3646
3647
3648
3649
3650
3651 EBRDINIT(brdp);
3652
3653 #if STLI_HIMEMORY
3654 if (brdp->memaddr > 0x100000) {
3655 brdp->membase = stli_mapbrdmem(brdp->memaddr, brdp->memsize);
3656 if (brdp->membase == (void *) NULL)
3657 return(-ENOMEM);
3658 }
3659 #endif
3660
3661
3662
3663
3664
3665
3666 EBRDENABLE(brdp);
3667 sigsp = (cdkonbsig_t *) EBRDGETMEMPTR(brdp, CDK_SIGADDR);
3668 memcpy(&sig, sigsp, sizeof(cdkonbsig_t));
3669 EBRDDISABLE(brdp);
3670
3671 #if 0
3672 printk("%s(%d): sig-> magic=%x:%x:%x:%x romver=%x amask=%x:%x:%x\n",
3673 __FILE__, __LINE__, sig.magic0, sig.magic1, sig.magic2,
3674 sig.magic3, sig.romver, sig.amask0, sig.amask1, sig.amask2);
3675 #endif
3676
3677 if ((sig.magic0 != ONB_MAGIC0) || (sig.magic1 != ONB_MAGIC1) ||
3678 (sig.magic2 != ONB_MAGIC2) || (sig.magic3 != ONB_MAGIC3))
3679 return(-ENODEV);
3680
3681
3682
3683
3684
3685 brdp->nrpanels = 1;
3686 if (sig.amask1) {
3687 brdp->nrports = 32;
3688 } else {
3689 for (i = 0; (i < 16); i++) {
3690 if (((sig.amask0 << i) & 0x8000) == 0)
3691 break;
3692 }
3693 brdp->nrports = i;
3694 }
3695
3696 request_region(brdp->iobase, ONB_IOSIZE, "serial(ONB/BBY)");
3697 brdp->state |= BST_FOUND;
3698 return(0);
3699 }
3700
3701
3702
3703
3704
3705
3706
3707
3708
3709 static int stli_startbrd(stlibrd_t *brdp)
3710 {
3711 volatile cdkhdr_t *hdrp;
3712 volatile cdkmem_t *memp;
3713 volatile cdkasy_t *ap;
3714 unsigned long flags;
3715 stliport_t *portp;
3716 int portnr, nrdevs, i, rc;
3717
3718 #if DEBUG
3719 printk("stli_startbrd(brdp=%x)\n", (int) brdp);
3720 #endif
3721
3722 rc = 0;
3723
3724 save_flags(flags);
3725 cli();
3726 EBRDENABLE(brdp);
3727 hdrp = (volatile cdkhdr_t *) EBRDGETMEMPTR(brdp, CDK_CDKADDR);
3728 nrdevs = hdrp->nrdevs;
3729
3730 #if 0
3731 printk("%s(%d): CDK version %d.%d.%d --> nrdevs=%d memp=%x hostp=%x slavep=%x\n",
3732 __FILE__, __LINE__, hdrp->ver_release, hdrp->ver_modification,
3733 hdrp->ver_fix, nrdevs, (int) hdrp->memp, (int) hdrp->hostp,
3734 (int) hdrp->slavep);
3735 #endif
3736
3737 if (nrdevs < (brdp->nrports + 1)) {
3738 printk("STALLION: slave failed to allocate memory for all devices, devices=%d\n", nrdevs);
3739 brdp->nrports = nrdevs - 1;
3740 }
3741 brdp->nrdevs = nrdevs;
3742 brdp->hostoffset = hdrp->hostp - CDK_CDKADDR;
3743 brdp->slaveoffset = hdrp->slavep - CDK_CDKADDR;
3744 brdp->bitsize = (nrdevs + 7) / 8;
3745 memp = (volatile cdkmem_t *) hdrp->memp;
3746 if (((unsigned long) memp) > brdp->memsize) {
3747 printk("STALLION: corrupted shared memory region?\n");
3748 rc = -EIO;
3749 goto stli_donestartup;
3750 }
3751 memp = (volatile cdkmem_t *) EBRDGETMEMPTR(brdp, (unsigned long) memp);
3752 if (memp->dtype != TYP_ASYNCTRL) {
3753 printk("STALLION: no slave control device found\n");
3754 goto stli_donestartup;
3755 }
3756 memp++;
3757
3758
3759
3760
3761
3762
3763 for (i = 1, portnr = 0; (i < nrdevs); i++, portnr++, memp++) {
3764 if (memp->dtype != TYP_ASYNC)
3765 break;
3766 portp = brdp->ports[portnr];
3767 if (portp == (stliport_t *) NULL)
3768 break;
3769 portp->devnr = i;
3770 portp->addr = memp->offset;
3771 portp->reqbit = (unsigned char) (0x1 << (i * 8 / nrdevs));
3772 portp->portidx = (unsigned char) (i / 8);
3773 portp->portbit = (unsigned char) (0x1 << (i % 8));
3774 }
3775
3776
3777
3778
3779
3780
3781 for (i = 1, portnr = 0; (i < nrdevs); i++, portnr++) {
3782 portp = brdp->ports[portnr];
3783 if (portp == (stliport_t *) NULL)
3784 break;
3785 if (portp->addr == 0)
3786 break;
3787 ap = (volatile cdkasy_t *) EBRDGETMEMPTR(brdp, portp->addr);
3788 if (ap != (volatile cdkasy_t *) NULL) {
3789 portp->rxsize = ap->rxq.size;
3790 portp->txsize = ap->txq.size;
3791 portp->rxoffset = ap->rxq.offset;
3792 portp->txoffset = ap->txq.offset;
3793 }
3794 }
3795
3796 stli_donestartup:
3797 EBRDDISABLE(brdp);
3798 restore_flags(flags);
3799
3800 if (rc == 0)
3801 brdp->state |= BST_STARTED;
3802
3803 if (! stli_timeron) {
3804 stli_timeron++;
3805 stli_timerlist.expires = STLI_TIMEOUT;
3806 add_timer(&stli_timerlist);
3807 }
3808
3809 return(rc);
3810 }
3811
3812
3813
3814
3815
3816
3817
3818 static int stli_brdinit(stlibrd_t *brdp)
3819 {
3820 #if DEBUG
3821 printk("stli_brdinit(brdp=%x)\n", (int) brdp);
3822 #endif
3823
3824 stli_brds[brdp->brdnr] = brdp;
3825
3826 switch (brdp->brdtype) {
3827 case BRD_ECP:
3828 case BRD_ECPE:
3829 case BRD_ECPMC:
3830 stli_initecp(brdp);
3831 break;
3832 case BRD_ONBOARD:
3833 case BRD_ONBOARDE:
3834 case BRD_ONBOARD2:
3835 case BRD_ONBOARD32:
3836 case BRD_ONBOARD2_32:
3837 case BRD_ONBOARDRS:
3838 case BRD_BRUMBY4:
3839 case BRD_BRUMBY8:
3840 case BRD_BRUMBY16:
3841 case BRD_STALLION:
3842 stli_initonb(brdp);
3843 break;
3844 case BRD_EASYIO:
3845 case BRD_ECH:
3846 case BRD_ECHMC:
3847 case BRD_ECHPCI:
3848 printk("STALLION: %s board type not supported in this driver\n", stli_brdnames[brdp->brdtype]);
3849 return(ENODEV);
3850 default:
3851 printk("STALLION: unit=%d is unknown board type=%d\n", brdp->brdnr, brdp->brdtype);
3852 return(ENODEV);
3853 }
3854
3855 if ((brdp->state & BST_FOUND) == 0) {
3856 printk("STALLION: %s board not found, unit=%d io=%x mem=%x\n", stli_brdnames[brdp->brdtype], brdp->brdnr, brdp->iobase, (int) brdp->memaddr);
3857 return(ENODEV);
3858 }
3859
3860 stli_initports(brdp);
3861 printk("STALLION: %s found, unit=%d io=%x mem=%x nrpanels=%d nrports=%d\n", stli_brdnames[brdp->brdtype], brdp->brdnr, brdp->iobase, (int) brdp->memaddr, brdp->nrpanels, brdp->nrports);
3862 return(0);
3863 }
3864
3865
3866
3867
3868
3869
3870
3871
3872 static int stli_eisamemprobe(stlibrd_t *brdp)
3873 {
3874 cdkecpsig_t ecpsig, *ecpsigp;
3875 cdkonbsig_t onbsig, *onbsigp;
3876 int i, foundit;
3877
3878 #if DEBUG
3879 printk("stli_eisamemprobe(brdp=%x)\n", (int) brdp);
3880 #endif
3881
3882
3883
3884
3885
3886
3887
3888 if (brdp->brdtype == BRD_ECPE) {
3889 outb(0x1, (brdp->iobase + ECP_EIBRDENAB));
3890 outb(ECP_EISTOP, (brdp->iobase + ECP_EICONFR));
3891 udelay(10);
3892 outb(ECP_EIDISABLE, (brdp->iobase + ECP_EICONFR));
3893 udelay(500);
3894 stli_ecpeienable(brdp);
3895 } else if (brdp->brdtype == BRD_ONBOARDE) {
3896 outb(0x1, (brdp->iobase + ONB_EIBRDENAB));
3897 outb(ONB_EISTOP, (brdp->iobase + ONB_EICONFR));
3898 udelay(10);
3899 outb(ONB_EIDISABLE, (brdp->iobase + ONB_EICONFR));
3900 for (i = 0; (i < 100); i++)
3901 udelay(1000);
3902 outb(0x1, brdp->iobase);
3903 udelay(1000);
3904 stli_onbeenable(brdp);
3905 } else {
3906 return(-ENODEV);
3907 }
3908
3909 foundit = 0;
3910 brdp->memsize = ECP_MEMSIZE;
3911
3912
3913
3914
3915
3916 for (i = 0; (i < stli_eisamempsize); i++) {
3917 brdp->memaddr = stli_eisamemprobeaddrs[i];
3918 brdp->membase = (void *) brdp->memaddr;
3919 #if STLI_HIMEMORY
3920 if (brdp->memaddr > 0x100000) {
3921 brdp->membase = stli_mapbrdmem(brdp->memaddr, brdp->memsize);
3922 if (brdp->membase == (void *) NULL)
3923 continue;
3924 }
3925 #endif
3926 if (brdp->brdtype == BRD_ECPE) {
3927 ecpsigp = (cdkecpsig_t *) stli_ecpeigetmemptr(brdp, CDK_SIGADDR, __LINE__);
3928 memcpy(&ecpsig, ecpsigp, sizeof(cdkecpsig_t));
3929 if (ecpsig.magic == ECP_MAGIC)
3930 foundit = 1;
3931 } else {
3932 onbsigp = (cdkonbsig_t *) stli_onbegetmemptr(brdp, CDK_SIGADDR, __LINE__);
3933 memcpy(&onbsig, onbsigp, sizeof(cdkonbsig_t));
3934 if ((onbsig.magic0 == ONB_MAGIC0) && (onbsig.magic1 == ONB_MAGIC1) &&
3935 (onbsig.magic2 == ONB_MAGIC2) && (onbsig.magic3 == ONB_MAGIC3))
3936 foundit = 1;
3937 }
3938 #if STLI_HIMEMORY
3939 if (brdp->memaddr >= 0x100000)
3940 vfree(brdp->membase);
3941 #endif
3942 if (foundit)
3943 break;
3944 }
3945
3946
3947
3948
3949
3950 if (brdp->brdtype == BRD_ECPE)
3951 stli_ecpeidisable(brdp);
3952 else
3953 stli_onbedisable(brdp);
3954
3955 if (! foundit) {
3956 brdp->memaddr = 0;
3957 brdp->membase = 0;
3958 printk("STALLION: failed to probe shared memory region for %s in EISA slot=%d\n", stli_brdnames[brdp->brdtype], (brdp->iobase >> 12));
3959 return(-ENODEV);
3960 }
3961 return(0);
3962 }
3963
3964
3965
3966
3967
3968
3969
3970
3971
3972
3973
3974
3975
3976 static int stli_findeisabrds()
3977 {
3978 stlibrd_t *brdp;
3979 unsigned int iobase, eid;
3980 int i;
3981
3982 #if DEBUG
3983 printk("stli_findeisabrds()\n");
3984 #endif
3985
3986
3987
3988
3989
3990
3991 outb(0xff, 0xc80);
3992 if (inb(0xc80) == 0xff)
3993 return(0);
3994
3995
3996
3997
3998 for (iobase = 0x1000; (iobase <= 0xc000); iobase += 0x1000) {
3999 outb(0xff, (iobase + 0xc80));
4000 eid = inb(iobase + 0xc80);
4001 eid |= inb(iobase + 0xc81) << 8;
4002 if (eid != STL_EISAID)
4003 continue;
4004
4005
4006
4007
4008
4009 for (i = 0; (i < STL_MAXBRDS); i++) {
4010 brdp = stli_brds[i];
4011 if (brdp == (stlibrd_t *) NULL)
4012 continue;
4013 if (brdp->iobase == iobase)
4014 break;
4015 }
4016 if (i < STL_MAXBRDS)
4017 continue;
4018
4019
4020
4021
4022
4023 if (stli_nrbrds >= STL_MAXBRDS) {
4024 printk("STALLION: no room for more probed boards, maximum supported %d\n", STL_MAXBRDS);
4025 break;
4026 }
4027
4028
4029
4030
4031
4032 brdp = (stlibrd_t *) stli_memalloc(sizeof(stlibrd_t));
4033 if (brdp == (stlibrd_t *) NULL) {
4034 printk("STALLION: failed to allocate memory (size=%d)\n", sizeof(stlibrd_t));
4035 return(-ENOMEM);
4036 }
4037 memset(brdp, 0, sizeof(stlibrd_t));
4038
4039 brdp->brdnr = stli_nrbrds++;
4040 eid = inb(iobase + 0xc82);
4041 if (eid == ECP_EISAID)
4042 brdp->brdtype = BRD_ECPE;
4043 else if (eid == ONB_EISAID)
4044 brdp->brdtype = BRD_ONBOARDE;
4045 else
4046 brdp->brdtype = BRD_UNKNOWN;
4047 brdp->iobase = iobase;
4048 outb(0x1, (iobase + 0xc84));
4049 if (stli_eisamemprobe(brdp))
4050 outb(0, (iobase + 0xc84));
4051 stli_brdinit(brdp);
4052 }
4053
4054 return(0);
4055 }
4056
4057
4058
4059
4060
4061
4062
4063
4064 static int stli_initbrds()
4065 {
4066 stlibrd_t *brdp, *nxtbrdp;
4067 stlconf_t *confp;
4068 int i, j;
4069
4070 #if DEBUG
4071 printk("stli_initbrds()\n");
4072 #endif
4073
4074 if (stli_nrbrds > STL_MAXBRDS) {
4075 printk("STALLION: too many boards in configuration table, truncating to %d\n", STL_MAXBRDS);
4076 stli_nrbrds = STL_MAXBRDS;
4077 }
4078
4079
4080
4081
4082
4083 for (i = 0; (i < stli_nrbrds); i++) {
4084 confp = &stli_brdconf[i];
4085 brdp = (stlibrd_t *) stli_memalloc(sizeof(stlibrd_t));
4086 if (brdp == (stlibrd_t *) NULL) {
4087 printk("STALLION: failed to allocate memory (size=%d)\n", sizeof(stlibrd_t));
4088 return(-ENOMEM);
4089 }
4090 memset(brdp, 0, sizeof(stlibrd_t));
4091
4092 brdp->brdnr = i;
4093 brdp->brdtype = confp->brdtype;
4094 brdp->iobase = confp->ioaddr1;
4095 brdp->memaddr = confp->memaddr;
4096 stli_brdinit(brdp);
4097 }
4098
4099
4100
4101
4102 if (stli_eisaprobe)
4103 stli_findeisabrds();
4104
4105
4106
4107
4108
4109
4110 stli_shared = 0;
4111 if (stli_nrbrds > 1) {
4112 for (i = 0; (i < stli_nrbrds); i++) {
4113 brdp = stli_brds[i];
4114 if (brdp == (stlibrd_t *) NULL)
4115 continue;
4116 for (j = i + 1; (j < stli_nrbrds); j++) {
4117 nxtbrdp = stli_brds[j];
4118 if (nxtbrdp == (stlibrd_t *) NULL)
4119 continue;
4120 if ((brdp->membase >= nxtbrdp->membase) && (brdp->membase <= (nxtbrdp->membase + nxtbrdp->memsize - 1))) {
4121 stli_shared++;
4122 break;
4123 }
4124 }
4125 }
4126 }
4127
4128 if (stli_shared == 0) {
4129 for (i = 0; (i < stli_nrbrds); i++) {
4130 brdp = stli_brds[i];
4131 if (brdp == (stlibrd_t *) NULL)
4132 continue;
4133 if (brdp->state & BST_FOUND) {
4134 EBRDENABLE(brdp);
4135 brdp->enable = NULL;
4136 brdp->disable = NULL;
4137 }
4138 }
4139 }
4140
4141 return(0);
4142 }
4143
4144
4145
4146
4147
4148
4149
4150
4151
4152 static int stli_memread(struct inode *ip, struct file *fp, char *buf, int count)
4153 {
4154 unsigned long flags;
4155 void *memptr;
4156 stlibrd_t *brdp;
4157 int brdnr, size, n;
4158
4159 #if DEBUG
4160 printk("stli_memread(ip=%x,fp=%x,buf=%x,count=%d)\n", (int) ip, (int) fp, (int) buf, count);
4161 #endif
4162
4163 brdnr = MINOR(ip->i_rdev);
4164 if (brdnr >= stli_nrbrds)
4165 return(-ENODEV);
4166 brdp = stli_brds[brdnr];
4167 if (brdp == (stlibrd_t *) NULL)
4168 return(-ENODEV);
4169 if (brdp->state == 0)
4170 return(-ENODEV);
4171 if (fp->f_pos >= brdp->memsize)
4172 return(0);
4173
4174 size = MIN(count, (brdp->memsize - fp->f_pos));
4175
4176 save_flags(flags);
4177 cli();
4178 EBRDENABLE(brdp);
4179 while (size > 0) {
4180 memptr = (void *) EBRDGETMEMPTR(brdp, fp->f_pos);
4181 n = MIN(size, (brdp->pagesize - (((unsigned long) fp->f_pos) % brdp->pagesize)));
4182 memcpy_tofs(buf, memptr, n);
4183 fp->f_pos += n;
4184 buf += n;
4185 size -= n;
4186 }
4187 EBRDDISABLE(brdp);
4188 restore_flags(flags);
4189
4190 return(count);
4191 }
4192
4193
4194
4195
4196
4197
4198
4199
4200
4201 static int stli_memwrite(struct inode *ip, struct file *fp, const char *buf, int count)
4202 {
4203 unsigned long flags;
4204 void *memptr;
4205 stlibrd_t *brdp;
4206 char *chbuf;
4207 int brdnr, size, n;
4208
4209 #if DEBUG
4210 printk("stli_memwrite(ip=%x,fp=%x,buf=%x,count=%x)\n", (int) ip, (int) fp, (int) buf, count);
4211 #endif
4212
4213 brdnr = MINOR(ip->i_rdev);
4214 if (brdnr >= stli_nrbrds)
4215 return(-ENODEV);
4216 brdp = stli_brds[brdnr];
4217 if (brdp == (stlibrd_t *) NULL)
4218 return(-ENODEV);
4219 if (brdp->state == 0)
4220 return(-ENODEV);
4221 if (fp->f_pos >= brdp->memsize)
4222 return(0);
4223
4224 chbuf = (char *) buf;
4225 size = MIN(count, (brdp->memsize - fp->f_pos));
4226
4227 save_flags(flags);
4228 cli();
4229 EBRDENABLE(brdp);
4230 while (size > 0) {
4231 memptr = (void *) EBRDGETMEMPTR(brdp, fp->f_pos);
4232 n = MIN(size, (brdp->pagesize - (((unsigned long) fp->f_pos) % brdp->pagesize)));
4233 memcpy_fromfs(memptr, chbuf, n);
4234 fp->f_pos += n;
4235 chbuf += n;
4236 size -= n;
4237 }
4238 EBRDDISABLE(brdp);
4239 restore_flags(flags);
4240
4241 return(count);
4242 }
4243
4244
4245
4246
4247
4248
4249
4250
4251
4252 static int stli_memioctl(struct inode *ip, struct file *fp, unsigned int cmd, unsigned long arg)
4253 {
4254 stlibrd_t *brdp;
4255 int brdnr, rc;
4256
4257 #if DEBUG
4258 printk("stli_memioctl(ip=%x,fp=%x,cmd=%x,arg=%x)\n", (int) ip, (int) fp, cmd, (int) arg);
4259 #endif
4260
4261 brdnr = MINOR(ip->i_rdev);
4262 if (brdnr >= stli_nrbrds)
4263 return(-ENODEV);
4264 brdp = stli_brds[brdnr];
4265 if (brdp == (stlibrd_t *) NULL)
4266 return(-ENODEV);
4267 if (brdp->state == 0)
4268 return(-ENODEV);
4269
4270 rc = 0;
4271
4272 switch (cmd) {
4273 case STL_BINTR:
4274 EBRDINTR(brdp);
4275 break;
4276 case STL_BSTART:
4277 rc = stli_startbrd(brdp);
4278 break;
4279 case STL_BSTOP:
4280 brdp->state &= ~BST_STARTED;
4281 break;
4282 case STL_BRESET:
4283 brdp->state &= ~BST_STARTED;
4284 EBRDRESET(brdp);
4285 if (stli_shared == 0) {
4286 if (brdp->reenable != NULL)
4287 (* brdp->reenable)(brdp);
4288 }
4289 break;
4290 default:
4291 rc = -ENOIOCTLCMD;
4292 break;
4293 }
4294
4295 return(rc);
4296 }
4297
4298
4299
4300 int stli_init()
4301 {
4302 printk("%s: version %s\n", stli_drvname, stli_drvversion);
4303
4304 stli_initbrds();
4305
4306
4307
4308
4309 stli_tmpwritebuf = (char *) stli_memalloc(STLI_TXBUFSIZE);
4310 if (stli_tmpwritebuf == (char *) NULL)
4311 printk("STALLION: failed to allocate memory (size=%d)\n", STLI_TXBUFSIZE);
4312 stli_txcookbuf = (char *) stli_memalloc(STLI_TXBUFSIZE);
4313 if (stli_txcookbuf == (char *) NULL)
4314 printk("STALLION: failed to allocate memory (size=%d)\n", STLI_TXBUFSIZE);
4315
4316
4317
4318
4319
4320 if (register_chrdev(STL_SIOMEMMAJOR, "staliomem", &stli_fsiomem))
4321 printk("STALLION: failed to register serial memory device\n");
4322
4323
4324
4325
4326
4327 memset(&stli_serial, 0, sizeof(struct tty_driver));
4328 stli_serial.magic = TTY_DRIVER_MAGIC;
4329 stli_serial.name = stli_serialname;
4330 stli_serial.major = STL_SERIALMAJOR;
4331 stli_serial.minor_start = 0;
4332 stli_serial.num = STL_MAXBRDS * STL_MAXPORTS;
4333 stli_serial.type = TTY_DRIVER_TYPE_SERIAL;
4334 stli_serial.subtype = STL_DRVTYPSERIAL;
4335 stli_serial.init_termios = stli_deftermios;
4336 stli_serial.flags = TTY_DRIVER_REAL_RAW;
4337 stli_serial.refcount = &stli_refcount;
4338 stli_serial.table = stli_ttys;
4339 stli_serial.termios = stli_termios;
4340 stli_serial.termios_locked = stli_termioslocked;
4341
4342 stli_serial.open = stli_open;
4343 stli_serial.close = stli_close;
4344 stli_serial.write = stli_write;
4345 stli_serial.put_char = stli_putchar;
4346 stli_serial.flush_chars = stli_flushchars;
4347 stli_serial.write_room = stli_writeroom;
4348 stli_serial.chars_in_buffer = stli_charsinbuffer;
4349 stli_serial.ioctl = stli_ioctl;
4350 stli_serial.set_termios = stli_settermios;
4351 stli_serial.throttle = stli_throttle;
4352 stli_serial.unthrottle = stli_unthrottle;
4353 stli_serial.stop = stli_stop;
4354 stli_serial.start = stli_start;
4355 stli_serial.hangup = stli_hangup;
4356 stli_serial.flush_buffer = stli_flushbuffer;
4357
4358 stli_callout = stli_serial;
4359 stli_callout.name = stli_calloutname;
4360 stli_callout.major = STL_CALLOUTMAJOR;
4361 stli_callout.subtype = STL_DRVTYPCALLOUT;
4362
4363 if (tty_register_driver(&stli_serial))
4364 printk("STALLION: failed to register serial driver\n");
4365 if (tty_register_driver(&stli_callout))
4366 printk("STALLION: failed to register callout driver\n");
4367
4368 return(0);
4369 }
4370
4371