forked from torvalds/linux
-
Notifications
You must be signed in to change notification settings - Fork 0
/
epca.c
3112 lines (2621 loc) · 98.9 KB
/
epca.c
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
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
/*
Copyright (C) 1996 Digi International.
For technical support please email [email protected] or
call Digi tech support at (612) 912-3456
** This driver is no longer supported by Digi **
Much of this design and code came from epca.c which was
copyright (C) 1994, 1995 Troy De Jongh, and subsquently
modified by David Nugent, Christoph Lameter, Mike McLagan.
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
--------------------------------------------------------------------------- */
/* See README.epca for change history --DAT*/
#include <linux/module.h>
#include <linux/kernel.h>
#include <linux/types.h>
#include <linux/init.h>
#include <linux/serial.h>
#include <linux/delay.h>
#include <linux/ctype.h>
#include <linux/tty.h>
#include <linux/tty_flip.h>
#include <linux/slab.h>
#include <linux/ioport.h>
#include <linux/interrupt.h>
#include <asm/uaccess.h>
#include <asm/io.h>
#include <linux/spinlock.h>
#include <linux/pci.h>
#include "digiPCI.h"
#include "digi1.h"
#include "digiFep1.h"
#include "epca.h"
#include "epcaconfig.h"
/* ---------------------- Begin defines ------------------------ */
#define VERSION "1.3.0.1-LK2.6"
/* This major needs to be submitted to Linux to join the majors list */
#define DIGIINFOMAJOR 35 /* For Digi specific ioctl */
#define MAXCARDS 7
#define epcaassert(x, msg) if (!(x)) epca_error(__LINE__, msg)
#define PFX "epca: "
/* ----------------- Begin global definitions ------------------- */
static int nbdevs, num_cards, liloconfig;
static int digi_poller_inhibited = 1 ;
static int setup_error_code;
static int invalid_lilo_config;
/* The ISA boards do window flipping into the same spaces so its only sane
with a single lock. It's still pretty efficient */
static DEFINE_SPINLOCK(epca_lock);
/* -----------------------------------------------------------------------
MAXBOARDS is typically 12, but ISA and EISA cards are restricted to
7 below.
--------------------------------------------------------------------------*/
static struct board_info boards[MAXBOARDS];
/* ------------- Begin structures used for driver registeration ---------- */
static struct tty_driver *pc_driver;
static struct tty_driver *pc_info;
/* ------------------ Begin Digi specific structures -------------------- */
/* ------------------------------------------------------------------------
digi_channels represents an array of structures that keep track of
each channel of the Digi product. Information such as transmit and
receive pointers, termio data, and signal definitions (DTR, CTS, etc ...)
are stored here. This structure is NOT used to overlay the cards
physical channel structure.
-------------------------------------------------------------------------- */
static struct channel digi_channels[MAX_ALLOC];
/* ------------------------------------------------------------------------
card_ptr is an array used to hold the address of the
first channel structure of each card. This array will hold
the addresses of various channels located in digi_channels.
-------------------------------------------------------------------------- */
static struct channel *card_ptr[MAXCARDS];
static struct timer_list epca_timer;
/* ---------------------- Begin function prototypes --------------------- */
/* ----------------------------------------------------------------------
Begin generic memory functions. These functions will be alias
(point at) more specific functions dependent on the board being
configured.
----------------------------------------------------------------------- */
static void memwinon(struct board_info *b, unsigned int win);
static void memwinoff(struct board_info *b, unsigned int win);
static void globalwinon(struct channel *ch);
static void rxwinon(struct channel *ch);
static void txwinon(struct channel *ch);
static void memoff(struct channel *ch);
static void assertgwinon(struct channel *ch);
static void assertmemoff(struct channel *ch);
/* ---- Begin more 'specific' memory functions for cx_like products --- */
static void pcxem_memwinon(struct board_info *b, unsigned int win);
static void pcxem_memwinoff(struct board_info *b, unsigned int win);
static void pcxem_globalwinon(struct channel *ch);
static void pcxem_rxwinon(struct channel *ch);
static void pcxem_txwinon(struct channel *ch);
static void pcxem_memoff(struct channel *ch);
/* ------ Begin more 'specific' memory functions for the pcxe ------- */
static void pcxe_memwinon(struct board_info *b, unsigned int win);
static void pcxe_memwinoff(struct board_info *b, unsigned int win);
static void pcxe_globalwinon(struct channel *ch);
static void pcxe_rxwinon(struct channel *ch);
static void pcxe_txwinon(struct channel *ch);
static void pcxe_memoff(struct channel *ch);
/* ---- Begin more 'specific' memory functions for the pc64xe and pcxi ---- */
/* Note : pc64xe and pcxi share the same windowing routines */
static void pcxi_memwinon(struct board_info *b, unsigned int win);
static void pcxi_memwinoff(struct board_info *b, unsigned int win);
static void pcxi_globalwinon(struct channel *ch);
static void pcxi_rxwinon(struct channel *ch);
static void pcxi_txwinon(struct channel *ch);
static void pcxi_memoff(struct channel *ch);
/* - Begin 'specific' do nothing memory functions needed for some cards - */
static void dummy_memwinon(struct board_info *b, unsigned int win);
static void dummy_memwinoff(struct board_info *b, unsigned int win);
static void dummy_globalwinon(struct channel *ch);
static void dummy_rxwinon(struct channel *ch);
static void dummy_txwinon(struct channel *ch);
static void dummy_memoff(struct channel *ch);
static void dummy_assertgwinon(struct channel *ch);
static void dummy_assertmemoff(struct channel *ch);
/* ------------------- Begin declare functions ----------------------- */
static struct channel *verifyChannel(struct tty_struct *);
static void pc_sched_event(struct channel *, int);
static void epca_error(int, char *);
static void pc_close(struct tty_struct *, struct file *);
static void shutdown(struct channel *);
static void pc_hangup(struct tty_struct *);
static void pc_put_char(struct tty_struct *, unsigned char);
static int pc_write_room(struct tty_struct *);
static int pc_chars_in_buffer(struct tty_struct *);
static void pc_flush_buffer(struct tty_struct *);
static void pc_flush_chars(struct tty_struct *);
static int block_til_ready(struct tty_struct *, struct file *,
struct channel *);
static int pc_open(struct tty_struct *, struct file *);
static void post_fep_init(unsigned int crd);
static void epcapoll(unsigned long);
static void doevent(int);
static void fepcmd(struct channel *, int, int, int, int, int);
static unsigned termios2digi_h(struct channel *ch, unsigned);
static unsigned termios2digi_i(struct channel *ch, unsigned);
static unsigned termios2digi_c(struct channel *ch, unsigned);
static void epcaparam(struct tty_struct *, struct channel *);
static void receive_data(struct channel *);
static int pc_ioctl(struct tty_struct *, struct file *,
unsigned int, unsigned long);
static int info_ioctl(struct tty_struct *, struct file *,
unsigned int, unsigned long);
static void pc_set_termios(struct tty_struct *, struct termios *);
static void do_softint(void *);
static void pc_stop(struct tty_struct *);
static void pc_start(struct tty_struct *);
static void pc_throttle(struct tty_struct * tty);
static void pc_unthrottle(struct tty_struct *tty);
static void digi_send_break(struct channel *ch, int msec);
static void setup_empty_event(struct tty_struct *tty, struct channel *ch);
void epca_setup(char *, int *);
static int get_termio(struct tty_struct *, struct termio __user *);
static int pc_write(struct tty_struct *, const unsigned char *, int);
static int pc_init(void);
static int init_PCI(void);
/* ------------------------------------------------------------------
Table of functions for each board to handle memory. Mantaining
parallelism is a *very* good idea here. The idea is for the
runtime code to blindly call these functions, not knowing/caring
about the underlying hardware. This stuff should contain no
conditionals; if more functionality is needed a different entry
should be established. These calls are the interface calls and
are the only functions that should be accessed. Anyone caught
making direct calls deserves what they get.
-------------------------------------------------------------------- */
static void memwinon(struct board_info *b, unsigned int win)
{
(b->memwinon)(b, win);
}
static void memwinoff(struct board_info *b, unsigned int win)
{
(b->memwinoff)(b, win);
}
static void globalwinon(struct channel *ch)
{
(ch->board->globalwinon)(ch);
}
static void rxwinon(struct channel *ch)
{
(ch->board->rxwinon)(ch);
}
static void txwinon(struct channel *ch)
{
(ch->board->txwinon)(ch);
}
static void memoff(struct channel *ch)
{
(ch->board->memoff)(ch);
}
static void assertgwinon(struct channel *ch)
{
(ch->board->assertgwinon)(ch);
}
static void assertmemoff(struct channel *ch)
{
(ch->board->assertmemoff)(ch);
}
/* ---------------------------------------------------------
PCXEM windowing is the same as that used in the PCXR
and CX series cards.
------------------------------------------------------------ */
static void pcxem_memwinon(struct board_info *b, unsigned int win)
{
outb_p(FEPWIN|win, b->port + 1);
}
static void pcxem_memwinoff(struct board_info *b, unsigned int win)
{
outb_p(0, b->port + 1);
}
static void pcxem_globalwinon(struct channel *ch)
{
outb_p( FEPWIN, (int)ch->board->port + 1);
}
static void pcxem_rxwinon(struct channel *ch)
{
outb_p(ch->rxwin, (int)ch->board->port + 1);
}
static void pcxem_txwinon(struct channel *ch)
{
outb_p(ch->txwin, (int)ch->board->port + 1);
}
static void pcxem_memoff(struct channel *ch)
{
outb_p(0, (int)ch->board->port + 1);
}
/* ----------------- Begin pcxe memory window stuff ------------------ */
static void pcxe_memwinon(struct board_info *b, unsigned int win)
{
outb_p(FEPWIN | win, b->port + 1);
}
static void pcxe_memwinoff(struct board_info *b, unsigned int win)
{
outb_p(inb(b->port) & ~FEPMEM,
b->port + 1);
outb_p(0, b->port + 1);
}
static void pcxe_globalwinon(struct channel *ch)
{
outb_p( FEPWIN, (int)ch->board->port + 1);
}
static void pcxe_rxwinon(struct channel *ch)
{
outb_p(ch->rxwin, (int)ch->board->port + 1);
}
static void pcxe_txwinon(struct channel *ch)
{
outb_p(ch->txwin, (int)ch->board->port + 1);
}
static void pcxe_memoff(struct channel *ch)
{
outb_p(0, (int)ch->board->port);
outb_p(0, (int)ch->board->port + 1);
}
/* ------------- Begin pc64xe and pcxi memory window stuff -------------- */
static void pcxi_memwinon(struct board_info *b, unsigned int win)
{
outb_p(inb(b->port) | FEPMEM, b->port);
}
static void pcxi_memwinoff(struct board_info *b, unsigned int win)
{
outb_p(inb(b->port) & ~FEPMEM, b->port);
}
static void pcxi_globalwinon(struct channel *ch)
{
outb_p(FEPMEM, ch->board->port);
}
static void pcxi_rxwinon(struct channel *ch)
{
outb_p(FEPMEM, ch->board->port);
}
static void pcxi_txwinon(struct channel *ch)
{
outb_p(FEPMEM, ch->board->port);
}
static void pcxi_memoff(struct channel *ch)
{
outb_p(0, ch->board->port);
}
static void pcxi_assertgwinon(struct channel *ch)
{
epcaassert(inb(ch->board->port) & FEPMEM, "Global memory off");
}
static void pcxi_assertmemoff(struct channel *ch)
{
epcaassert(!(inb(ch->board->port) & FEPMEM), "Memory on");
}
/* ----------------------------------------------------------------------
Not all of the cards need specific memory windowing routines. Some
cards (Such as PCI) needs no windowing routines at all. We provide
these do nothing routines so that the same code base can be used.
The driver will ALWAYS call a windowing routine if it thinks it needs
to; regardless of the card. However, dependent on the card the routine
may or may not do anything.
---------------------------------------------------------------------------*/
static void dummy_memwinon(struct board_info *b, unsigned int win)
{
}
static void dummy_memwinoff(struct board_info *b, unsigned int win)
{
}
static void dummy_globalwinon(struct channel *ch)
{
}
static void dummy_rxwinon(struct channel *ch)
{
}
static void dummy_txwinon(struct channel *ch)
{
}
static void dummy_memoff(struct channel *ch)
{
}
static void dummy_assertgwinon(struct channel *ch)
{
}
static void dummy_assertmemoff(struct channel *ch)
{
}
/* ----------------- Begin verifyChannel function ----------------------- */
static struct channel *verifyChannel(struct tty_struct *tty)
{ /* Begin verifyChannel */
/* --------------------------------------------------------------------
This routine basically provides a sanity check. It insures that
the channel returned is within the proper range of addresses as
well as properly initialized. If some bogus info gets passed in
through tty->driver_data this should catch it.
--------------------------------------------------------------------- */
if (tty) {
struct channel *ch = (struct channel *)tty->driver_data;
if ((ch >= &digi_channels[0]) && (ch < &digi_channels[nbdevs])) {
if (ch->magic == EPCA_MAGIC)
return ch;
}
}
return NULL;
} /* End verifyChannel */
/* ------------------ Begin pc_sched_event ------------------------- */
static void pc_sched_event(struct channel *ch, int event)
{
/* ----------------------------------------------------------------------
We call this to schedule interrupt processing on some event. The
kernel sees our request and calls the related routine in OUR driver.
-------------------------------------------------------------------------*/
ch->event |= 1 << event;
schedule_work(&ch->tqueue);
} /* End pc_sched_event */
/* ------------------ Begin epca_error ------------------------- */
static void epca_error(int line, char *msg)
{
printk(KERN_ERR "epca_error (Digi): line = %d %s\n",line,msg);
}
/* ------------------ Begin pc_close ------------------------- */
static void pc_close(struct tty_struct * tty, struct file * filp)
{
struct channel *ch;
unsigned long flags;
/* ---------------------------------------------------------
verifyChannel returns the channel from the tty struct
if it is valid. This serves as a sanity check.
------------------------------------------------------------- */
if ((ch = verifyChannel(tty)) != NULL) { /* Begin if ch != NULL */
spin_lock_irqsave(&epca_lock, flags);
if (tty_hung_up_p(filp)) {
spin_unlock_irqrestore(&epca_lock, flags);
return;
}
/* Check to see if the channel is open more than once */
if (ch->count-- > 1) {
/* Begin channel is open more than once */
/* -------------------------------------------------------------
Return without doing anything. Someone might still be using
the channel.
---------------------------------------------------------------- */
spin_unlock_irqrestore(&epca_lock, flags);
return;
} /* End channel is open more than once */
/* Port open only once go ahead with shutdown & reset */
BUG_ON(ch->count < 0);
/* ---------------------------------------------------------------
Let the rest of the driver know the channel is being closed.
This becomes important if an open is attempted before close
is finished.
------------------------------------------------------------------ */
ch->asyncflags |= ASYNC_CLOSING;
tty->closing = 1;
spin_unlock_irqrestore(&epca_lock, flags);
if (ch->asyncflags & ASYNC_INITIALIZED) {
/* Setup an event to indicate when the transmit buffer empties */
setup_empty_event(tty, ch);
tty_wait_until_sent(tty, 3000); /* 30 seconds timeout */
}
if (tty->driver->flush_buffer)
tty->driver->flush_buffer(tty);
tty_ldisc_flush(tty);
shutdown(ch);
spin_lock_irqsave(&epca_lock, flags);
tty->closing = 0;
ch->event = 0;
ch->tty = NULL;
spin_unlock_irqrestore(&epca_lock, flags);
if (ch->blocked_open) { /* Begin if blocked_open */
if (ch->close_delay)
msleep_interruptible(jiffies_to_msecs(ch->close_delay));
wake_up_interruptible(&ch->open_wait);
} /* End if blocked_open */
ch->asyncflags &= ~(ASYNC_NORMAL_ACTIVE | ASYNC_INITIALIZED |
ASYNC_CLOSING);
wake_up_interruptible(&ch->close_wait);
} /* End if ch != NULL */
} /* End pc_close */
/* ------------------ Begin shutdown ------------------------- */
static void shutdown(struct channel *ch)
{ /* Begin shutdown */
unsigned long flags;
struct tty_struct *tty;
struct board_chan __iomem *bc;
if (!(ch->asyncflags & ASYNC_INITIALIZED))
return;
spin_lock_irqsave(&epca_lock, flags);
globalwinon(ch);
bc = ch->brdchan;
/* ------------------------------------------------------------------
In order for an event to be generated on the receipt of data the
idata flag must be set. Since we are shutting down, this is not
necessary clear this flag.
--------------------------------------------------------------------- */
if (bc)
writeb(0, &bc->idata);
tty = ch->tty;
/* ----------------------------------------------------------------
If we're a modem control device and HUPCL is on, drop RTS & DTR.
------------------------------------------------------------------ */
if (tty->termios->c_cflag & HUPCL) {
ch->omodem &= ~(ch->m_rts | ch->m_dtr);
fepcmd(ch, SETMODEM, 0, ch->m_dtr | ch->m_rts, 10, 1);
}
memoff(ch);
/* ------------------------------------------------------------------
The channel has officialy been closed. The next time it is opened
it will have to reinitialized. Set a flag to indicate this.
---------------------------------------------------------------------- */
/* Prevent future Digi programmed interrupts from coming active */
ch->asyncflags &= ~ASYNC_INITIALIZED;
spin_unlock_irqrestore(&epca_lock, flags);
} /* End shutdown */
/* ------------------ Begin pc_hangup ------------------------- */
static void pc_hangup(struct tty_struct *tty)
{ /* Begin pc_hangup */
struct channel *ch;
/* ---------------------------------------------------------
verifyChannel returns the channel from the tty struct
if it is valid. This serves as a sanity check.
------------------------------------------------------------- */
if ((ch = verifyChannel(tty)) != NULL) { /* Begin if ch != NULL */
unsigned long flags;
if (tty->driver->flush_buffer)
tty->driver->flush_buffer(tty);
tty_ldisc_flush(tty);
shutdown(ch);
spin_lock_irqsave(&epca_lock, flags);
ch->tty = NULL;
ch->event = 0;
ch->count = 0;
ch->asyncflags &= ~(ASYNC_NORMAL_ACTIVE | ASYNC_INITIALIZED);
spin_unlock_irqrestore(&epca_lock, flags);
wake_up_interruptible(&ch->open_wait);
} /* End if ch != NULL */
} /* End pc_hangup */
/* ------------------ Begin pc_write ------------------------- */
static int pc_write(struct tty_struct * tty,
const unsigned char *buf, int bytesAvailable)
{ /* Begin pc_write */
unsigned int head, tail;
int dataLen;
int size;
int amountCopied;
struct channel *ch;
unsigned long flags;
int remain;
struct board_chan __iomem *bc;
/* ----------------------------------------------------------------
pc_write is primarily called directly by the kernel routine
tty_write (Though it can also be called by put_char) found in
tty_io.c. pc_write is passed a line discipline buffer where
the data to be written out is stored. The line discipline
implementation itself is done at the kernel level and is not
brought into the driver.
------------------------------------------------------------------- */
/* ---------------------------------------------------------
verifyChannel returns the channel from the tty struct
if it is valid. This serves as a sanity check.
------------------------------------------------------------- */
if ((ch = verifyChannel(tty)) == NULL)
return 0;
/* Make a pointer to the channel data structure found on the board. */
bc = ch->brdchan;
size = ch->txbufsize;
amountCopied = 0;
spin_lock_irqsave(&epca_lock, flags);
globalwinon(ch);
head = readw(&bc->tin) & (size - 1);
tail = readw(&bc->tout);
if (tail != readw(&bc->tout))
tail = readw(&bc->tout);
tail &= (size - 1);
/* If head >= tail, head has not wrapped around. */
if (head >= tail) { /* Begin head has not wrapped */
/* ---------------------------------------------------------------
remain (much like dataLen above) represents the total amount of
space available on the card for data. Here dataLen represents
the space existing between the head pointer and the end of
buffer. This is important because a memcpy cannot be told to
automatically wrap around when it hits the buffer end.
------------------------------------------------------------------ */
dataLen = size - head;
remain = size - (head - tail) - 1;
} else { /* Begin head has wrapped around */
remain = tail - head - 1;
dataLen = remain;
} /* End head has wrapped around */
/* -------------------------------------------------------------------
Check the space on the card. If we have more data than
space; reduce the amount of data to fit the space.
---------------------------------------------------------------------- */
bytesAvailable = min(remain, bytesAvailable);
txwinon(ch);
while (bytesAvailable > 0)
{ /* Begin while there is data to copy onto card */
/* -----------------------------------------------------------------
If head is not wrapped, the below will make sure the first
data copy fills to the end of card buffer.
------------------------------------------------------------------- */
dataLen = min(bytesAvailable, dataLen);
memcpy_toio(ch->txptr + head, buf, dataLen);
buf += dataLen;
head += dataLen;
amountCopied += dataLen;
bytesAvailable -= dataLen;
if (head >= size) {
head = 0;
dataLen = tail;
}
} /* End while there is data to copy onto card */
ch->statusflags |= TXBUSY;
globalwinon(ch);
writew(head, &bc->tin);
if ((ch->statusflags & LOWWAIT) == 0) {
ch->statusflags |= LOWWAIT;
writeb(1, &bc->ilow);
}
memoff(ch);
spin_unlock_irqrestore(&epca_lock, flags);
return(amountCopied);
} /* End pc_write */
/* ------------------ Begin pc_put_char ------------------------- */
static void pc_put_char(struct tty_struct *tty, unsigned char c)
{ /* Begin pc_put_char */
pc_write(tty, &c, 1);
} /* End pc_put_char */
/* ------------------ Begin pc_write_room ------------------------- */
static int pc_write_room(struct tty_struct *tty)
{ /* Begin pc_write_room */
int remain;
struct channel *ch;
unsigned long flags;
unsigned int head, tail;
struct board_chan __iomem *bc;
remain = 0;
/* ---------------------------------------------------------
verifyChannel returns the channel from the tty struct
if it is valid. This serves as a sanity check.
------------------------------------------------------------- */
if ((ch = verifyChannel(tty)) != NULL) {
spin_lock_irqsave(&epca_lock, flags);
globalwinon(ch);
bc = ch->brdchan;
head = readw(&bc->tin) & (ch->txbufsize - 1);
tail = readw(&bc->tout);
if (tail != readw(&bc->tout))
tail = readw(&bc->tout);
/* Wrap tail if necessary */
tail &= (ch->txbufsize - 1);
if ((remain = tail - head - 1) < 0 )
remain += ch->txbufsize;
if (remain && (ch->statusflags & LOWWAIT) == 0) {
ch->statusflags |= LOWWAIT;
writeb(1, &bc->ilow);
}
memoff(ch);
spin_unlock_irqrestore(&epca_lock, flags);
}
/* Return how much room is left on card */
return remain;
} /* End pc_write_room */
/* ------------------ Begin pc_chars_in_buffer ---------------------- */
static int pc_chars_in_buffer(struct tty_struct *tty)
{ /* Begin pc_chars_in_buffer */
int chars;
unsigned int ctail, head, tail;
int remain;
unsigned long flags;
struct channel *ch;
struct board_chan __iomem *bc;
/* ---------------------------------------------------------
verifyChannel returns the channel from the tty struct
if it is valid. This serves as a sanity check.
------------------------------------------------------------- */
if ((ch = verifyChannel(tty)) == NULL)
return(0);
spin_lock_irqsave(&epca_lock, flags);
globalwinon(ch);
bc = ch->brdchan;
tail = readw(&bc->tout);
head = readw(&bc->tin);
ctail = readw(&ch->mailbox->cout);
if (tail == head && readw(&ch->mailbox->cin) == ctail && readb(&bc->tbusy) == 0)
chars = 0;
else { /* Begin if some space on the card has been used */
head = readw(&bc->tin) & (ch->txbufsize - 1);
tail &= (ch->txbufsize - 1);
/* --------------------------------------------------------------
The logic here is basically opposite of the above pc_write_room
here we are finding the amount of bytes in the buffer filled.
Not the amount of bytes empty.
------------------------------------------------------------------- */
if ((remain = tail - head - 1) < 0 )
remain += ch->txbufsize;
chars = (int)(ch->txbufsize - remain);
/* -------------------------------------------------------------
Make it possible to wakeup anything waiting for output
in tty_ioctl.c, etc.
If not already set. Setup an event to indicate when the
transmit buffer empties
----------------------------------------------------------------- */
if (!(ch->statusflags & EMPTYWAIT))
setup_empty_event(tty,ch);
} /* End if some space on the card has been used */
memoff(ch);
spin_unlock_irqrestore(&epca_lock, flags);
/* Return number of characters residing on card. */
return(chars);
} /* End pc_chars_in_buffer */
/* ------------------ Begin pc_flush_buffer ---------------------- */
static void pc_flush_buffer(struct tty_struct *tty)
{ /* Begin pc_flush_buffer */
unsigned int tail;
unsigned long flags;
struct channel *ch;
struct board_chan __iomem *bc;
/* ---------------------------------------------------------
verifyChannel returns the channel from the tty struct
if it is valid. This serves as a sanity check.
------------------------------------------------------------- */
if ((ch = verifyChannel(tty)) == NULL)
return;
spin_lock_irqsave(&epca_lock, flags);
globalwinon(ch);
bc = ch->brdchan;
tail = readw(&bc->tout);
/* Have FEP move tout pointer; effectively flushing transmit buffer */
fepcmd(ch, STOUT, (unsigned) tail, 0, 0, 0);
memoff(ch);
spin_unlock_irqrestore(&epca_lock, flags);
wake_up_interruptible(&tty->write_wait);
tty_wakeup(tty);
} /* End pc_flush_buffer */
/* ------------------ Begin pc_flush_chars ---------------------- */
static void pc_flush_chars(struct tty_struct *tty)
{ /* Begin pc_flush_chars */
struct channel * ch;
/* ---------------------------------------------------------
verifyChannel returns the channel from the tty struct
if it is valid. This serves as a sanity check.
------------------------------------------------------------- */
if ((ch = verifyChannel(tty)) != NULL) {
unsigned long flags;
spin_lock_irqsave(&epca_lock, flags);
/* ----------------------------------------------------------------
If not already set and the transmitter is busy setup an event
to indicate when the transmit empties.
------------------------------------------------------------------- */
if ((ch->statusflags & TXBUSY) && !(ch->statusflags & EMPTYWAIT))
setup_empty_event(tty,ch);
spin_unlock_irqrestore(&epca_lock, flags);
}
} /* End pc_flush_chars */
/* ------------------ Begin block_til_ready ---------------------- */
static int block_til_ready(struct tty_struct *tty,
struct file *filp, struct channel *ch)
{ /* Begin block_til_ready */
DECLARE_WAITQUEUE(wait,current);
int retval, do_clocal = 0;
unsigned long flags;
if (tty_hung_up_p(filp)) {
if (ch->asyncflags & ASYNC_HUP_NOTIFY)
retval = -EAGAIN;
else
retval = -ERESTARTSYS;
return(retval);
}
/* -----------------------------------------------------------------
If the device is in the middle of being closed, then block
until it's done, and then try again.
-------------------------------------------------------------------- */
if (ch->asyncflags & ASYNC_CLOSING) {
interruptible_sleep_on(&ch->close_wait);
if (ch->asyncflags & ASYNC_HUP_NOTIFY)
return -EAGAIN;
else
return -ERESTARTSYS;
}
if (filp->f_flags & O_NONBLOCK) {
/* -----------------------------------------------------------------
If non-blocking mode is set, then make the check up front
and then exit.
-------------------------------------------------------------------- */
ch->asyncflags |= ASYNC_NORMAL_ACTIVE;
return 0;
}
if (tty->termios->c_cflag & CLOCAL)
do_clocal = 1;
/* Block waiting for the carrier detect and the line to become free */
retval = 0;
add_wait_queue(&ch->open_wait, &wait);
spin_lock_irqsave(&epca_lock, flags);
/* We dec count so that pc_close will know when to free things */
if (!tty_hung_up_p(filp))
ch->count--;
ch->blocked_open++;
while(1)
{ /* Begin forever while */
set_current_state(TASK_INTERRUPTIBLE);
if (tty_hung_up_p(filp) ||
!(ch->asyncflags & ASYNC_INITIALIZED))
{
if (ch->asyncflags & ASYNC_HUP_NOTIFY)
retval = -EAGAIN;
else
retval = -ERESTARTSYS;
break;
}
if (!(ch->asyncflags & ASYNC_CLOSING) &&
(do_clocal || (ch->imodem & ch->dcd)))
break;
if (signal_pending(current)) {
retval = -ERESTARTSYS;
break;
}
spin_unlock_irqrestore(&epca_lock, flags);
/* ---------------------------------------------------------------
Allow someone else to be scheduled. We will occasionally go
through this loop until one of the above conditions change.
The below schedule call will allow other processes to enter and
prevent this loop from hogging the cpu.
------------------------------------------------------------------ */
schedule();
spin_lock_irqsave(&epca_lock, flags);
} /* End forever while */
current->state = TASK_RUNNING;
remove_wait_queue(&ch->open_wait, &wait);
if (!tty_hung_up_p(filp))
ch->count++;
ch->blocked_open--;
spin_unlock_irqrestore(&epca_lock, flags);
if (retval)
return retval;
ch->asyncflags |= ASYNC_NORMAL_ACTIVE;
return 0;
} /* End block_til_ready */
/* ------------------ Begin pc_open ---------------------- */
static int pc_open(struct tty_struct *tty, struct file * filp)
{ /* Begin pc_open */
struct channel *ch;
unsigned long flags;
int line, retval, boardnum;
struct board_chan __iomem *bc;
unsigned int head;
line = tty->index;
if (line < 0 || line >= nbdevs)
return -ENODEV;
ch = &digi_channels[line];
boardnum = ch->boardnum;
/* Check status of board configured in system. */
/* -----------------------------------------------------------------
I check to see if the epca_setup routine detected an user error.
It might be better to put this in pc_init, but for the moment it
goes here.
---------------------------------------------------------------------- */
if (invalid_lilo_config) {
if (setup_error_code & INVALID_BOARD_TYPE)
printk(KERN_ERR "epca: pc_open: Invalid board type specified in kernel options.\n");
if (setup_error_code & INVALID_NUM_PORTS)
printk(KERN_ERR "epca: pc_open: Invalid number of ports specified in kernel options.\n");
if (setup_error_code & INVALID_MEM_BASE)