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