/
ip2main.c
3220 lines (2816 loc) · 101 KB
/
ip2main.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
/*
*
* (c) 1999 by Computone Corporation
*
********************************************************************************
*
* PACKAGE: Linux tty Device Driver for IntelliPort family of multiport
* serial I/O controllers.
*
* DESCRIPTION: Mainline code for the device driver
*
*******************************************************************************/
// ToDo:
//
// Fix the immediate DSS_NOW problem.
// Work over the channel stats return logic in ip2_ipl_ioctl so they
// make sense for all 256 possible channels and so the user space
// utilities will compile and work properly.
//
// Done:
//
// 1.2.14 /\/\|=mhw=|\/\/
// Added bounds checking to ip2_ipl_ioctl to avoid potential terroristic acts.
// Changed the definition of ip2trace to be more consistent with kernel style
// Thanks to Andreas Dilger <adilger@turbolabs.com> for these updates
//
// 1.2.13 /\/\|=mhw=|\/\/
// DEVFS: Renamed ttf/{n} to tts/F{n} and cuf/{n} to cua/F{n} to conform
// to agreed devfs serial device naming convention.
//
// 1.2.12 /\/\|=mhw=|\/\/
// Cleaned up some remove queue cut and paste errors
//
// 1.2.11 /\/\|=mhw=|\/\/
// Clean up potential NULL pointer dereferences
// Clean up devfs registration
// Add kernel command line parsing for io and irq
// Compile defaults for io and irq are now set in ip2.c not ip2.h!
// Reworked poll_only hack for explicit parameter setting
// You must now EXPLICITLY set poll_only = 1 or set all irqs to 0
// Merged ip2_loadmain and old_ip2_init
// Converted all instances of interruptible_sleep_on into queue calls
// Most of these had no race conditions but better to clean up now
//
// 1.2.10 /\/\|=mhw=|\/\/
// Fixed the bottom half interrupt handler and enabled USE_IQI
// to split the interrupt handler into a formal top-half / bottom-half
// Fixed timing window on high speed processors that queued messages to
// the outbound mail fifo faster than the board could handle.
//
// 1.2.9
// Four box EX was barfing on >128k kmalloc, made structure smaller by
// reducing output buffer size
//
// 1.2.8
// Device file system support (MHW)
//
// 1.2.7
// Fixed
// Reload of ip2 without unloading ip2main hangs system on cat of /proc/modules
//
// 1.2.6
//Fixes DCD problems
// DCD was not reported when CLOCAL was set on call to TIOCMGET
//
//Enhancements:
// TIOCMGET requests and waits for status return
// No DSS interrupts enabled except for DCD when needed
//
// For internal use only
//
//#define IP2DEBUG_INIT
//#define IP2DEBUG_OPEN
//#define IP2DEBUG_WRITE
//#define IP2DEBUG_READ
//#define IP2DEBUG_IOCTL
//#define IP2DEBUG_IPL
//#define IP2DEBUG_TRACE
//#define DEBUG_FIFO
/************/
/* Includes */
/************/
#include <linux/ctype.h>
#include <linux/string.h>
#include <linux/fcntl.h>
#include <linux/errno.h>
#include <linux/module.h>
#include <linux/signal.h>
#include <linux/sched.h>
#include <linux/timer.h>
#include <linux/interrupt.h>
#include <linux/pci.h>
#include <linux/mm.h>
#include <linux/slab.h>
#include <linux/major.h>
#include <linux/wait.h>
#include <linux/device.h>
#include <linux/mutex.h>
#include <linux/firmware.h>
#include <linux/platform_device.h>
#include <linux/tty.h>
#include <linux/tty_flip.h>
#include <linux/termios.h>
#include <linux/tty_driver.h>
#include <linux/serial.h>
#include <linux/ptrace.h>
#include <linux/ioport.h>
#include <linux/cdk.h>
#include <linux/comstats.h>
#include <linux/delay.h>
#include <linux/bitops.h>
#include <asm/system.h>
#include <asm/io.h>
#include <asm/irq.h>
#include <linux/vmalloc.h>
#include <linux/init.h>
#include <asm/uaccess.h>
#include "ip2types.h"
#include "ip2trace.h"
#include "ip2ioctl.h"
#include "ip2.h"
#include "i2ellis.h"
#include "i2lib.h"
/*****************
* /proc/ip2mem *
*****************/
#include <linux/proc_fs.h>
#include <linux/seq_file.h>
static DEFINE_MUTEX(ip2_mutex);
static const struct file_operations ip2mem_proc_fops;
static const struct file_operations ip2_proc_fops;
/********************/
/* Type Definitions */
/********************/
/*************/
/* Constants */
/*************/
/* String constants to identify ourselves */
static const char pcName[] = "Computone IntelliPort Plus multiport driver";
static const char pcVersion[] = "1.2.14";
/* String constants for port names */
static const char pcDriver_name[] = "ip2";
static const char pcIpl[] = "ip2ipl";
/***********************/
/* Function Prototypes */
/***********************/
/* Global module entry functions */
/* Private (static) functions */
static int ip2_open(PTTY, struct file *);
static void ip2_close(PTTY, struct file *);
static int ip2_write(PTTY, const unsigned char *, int);
static int ip2_putchar(PTTY, unsigned char);
static void ip2_flush_chars(PTTY);
static int ip2_write_room(PTTY);
static int ip2_chars_in_buf(PTTY);
static void ip2_flush_buffer(PTTY);
static int ip2_ioctl(PTTY, struct file *, UINT, ULONG);
static void ip2_set_termios(PTTY, struct ktermios *);
static void ip2_set_line_discipline(PTTY);
static void ip2_throttle(PTTY);
static void ip2_unthrottle(PTTY);
static void ip2_stop(PTTY);
static void ip2_start(PTTY);
static void ip2_hangup(PTTY);
static int ip2_tiocmget(struct tty_struct *tty, struct file *file);
static int ip2_tiocmset(struct tty_struct *tty, struct file *file,
unsigned int set, unsigned int clear);
static void set_irq(int, int);
static void ip2_interrupt_bh(struct work_struct *work);
static irqreturn_t ip2_interrupt(int irq, void *dev_id);
static void ip2_poll(unsigned long arg);
static inline void service_all_boards(void);
static void do_input(struct work_struct *);
static void do_status(struct work_struct *);
static void ip2_wait_until_sent(PTTY,int);
static void set_params (i2ChanStrPtr, struct ktermios *);
static int get_serial_info(i2ChanStrPtr, struct serial_struct __user *);
static int set_serial_info(i2ChanStrPtr, struct serial_struct __user *);
static ssize_t ip2_ipl_read(struct file *, char __user *, size_t, loff_t *);
static ssize_t ip2_ipl_write(struct file *, const char __user *, size_t, loff_t *);
static long ip2_ipl_ioctl(struct file *, UINT, ULONG);
static int ip2_ipl_open(struct inode *, struct file *);
static int DumpTraceBuffer(char __user *, int);
static int DumpFifoBuffer( char __user *, int);
static void ip2_init_board(int, const struct firmware *);
static unsigned short find_eisa_board(int);
static int ip2_setup(char *str);
/***************/
/* Static Data */
/***************/
static struct tty_driver *ip2_tty_driver;
/* Here, then is a table of board pointers which the interrupt routine should
* scan through to determine who it must service.
*/
static unsigned short i2nBoards; // Number of boards here
static i2eBordStrPtr i2BoardPtrTable[IP2_MAX_BOARDS];
static i2ChanStrPtr DevTable[IP2_MAX_PORTS];
//DevTableMem just used to save addresses for kfree
static void *DevTableMem[IP2_MAX_BOARDS];
/* This is the driver descriptor for the ip2ipl device, which is used to
* download the loadware to the boards.
*/
static const struct file_operations ip2_ipl = {
.owner = THIS_MODULE,
.read = ip2_ipl_read,
.write = ip2_ipl_write,
.unlocked_ioctl = ip2_ipl_ioctl,
.open = ip2_ipl_open,
.llseek = noop_llseek,
};
static unsigned long irq_counter;
static unsigned long bh_counter;
// Use immediate queue to service interrupts
#define USE_IQI
//#define USE_IQ // PCI&2.2 needs work
/* The timer_list entry for our poll routine. If interrupt operation is not
* selected, the board is serviced periodically to see if anything needs doing.
*/
#define POLL_TIMEOUT (jiffies + 1)
static DEFINE_TIMER(PollTimer, ip2_poll, 0, 0);
#ifdef IP2DEBUG_TRACE
/* Trace (debug) buffer data */
#define TRACEMAX 1000
static unsigned long tracebuf[TRACEMAX];
static int tracestuff;
static int tracestrip;
static int tracewrap;
#endif
/**********/
/* Macros */
/**********/
#ifdef IP2DEBUG_OPEN
#define DBG_CNT(s) printk(KERN_DEBUG "(%s): [%x] ttyc=%d, modc=%x -> %s\n", \
tty->name,(pCh->flags), \
tty->count,/*GET_USE_COUNT(module)*/0,s)
#else
#define DBG_CNT(s)
#endif
/********/
/* Code */
/********/
#include "i2ellis.c" /* Extremely low-level interface services */
#include "i2cmd.c" /* Standard loadware command definitions */
#include "i2lib.c" /* High level interface services */
/* Configuration area for modprobe */
MODULE_AUTHOR("Doug McNash");
MODULE_DESCRIPTION("Computone IntelliPort Plus Driver");
MODULE_LICENSE("GPL");
#define MAX_CMD_STR 50
static int poll_only;
static char cmd[MAX_CMD_STR];
static int Eisa_irq;
static int Eisa_slot;
static int iindx;
static char rirqs[IP2_MAX_BOARDS];
static int Valid_Irqs[] = { 3, 4, 5, 7, 10, 11, 12, 15, 0};
/* Note: Add compiled in defaults to these arrays, not to the structure
in ip2.h any longer. That structure WILL get overridden
by these values, or command line values, or insmod values!!! =mhw=
*/
static int io[IP2_MAX_BOARDS];
static int irq[IP2_MAX_BOARDS] = { -1, -1, -1, -1 };
MODULE_AUTHOR("Doug McNash");
MODULE_DESCRIPTION("Computone IntelliPort Plus Driver");
module_param_array(irq, int, NULL, 0);
MODULE_PARM_DESC(irq, "Interrupts for IntelliPort Cards");
module_param_array(io, int, NULL, 0);
MODULE_PARM_DESC(io, "I/O ports for IntelliPort Cards");
module_param(poll_only, bool, 0);
MODULE_PARM_DESC(poll_only, "Do not use card interrupts");
module_param_string(ip2, cmd, MAX_CMD_STR, 0);
MODULE_PARM_DESC(ip2, "Contains module parameter passed with 'ip2='");
/* for sysfs class support */
static struct class *ip2_class;
/* Some functions to keep track of what irqs we have */
static int __init is_valid_irq(int irq)
{
int *i = Valid_Irqs;
while (*i != 0 && *i != irq)
i++;
return *i;
}
static void __init mark_requested_irq(char irq)
{
rirqs[iindx++] = irq;
}
static int __exit clear_requested_irq(char irq)
{
int i;
for (i = 0; i < IP2_MAX_BOARDS; ++i) {
if (rirqs[i] == irq) {
rirqs[i] = 0;
return 1;
}
}
return 0;
}
static int have_requested_irq(char irq)
{
/* array init to zeros so 0 irq will not be requested as a side
* effect */
int i;
for (i = 0; i < IP2_MAX_BOARDS; ++i)
if (rirqs[i] == irq)
return 1;
return 0;
}
/******************************************************************************/
/* Function: cleanup_module() */
/* Parameters: None */
/* Returns: Nothing */
/* */
/* Description: */
/* This is a required entry point for an installable module. It has to return */
/* the device and the driver to a passive state. It should not be necessary */
/* to reset the board fully, especially as the loadware is downloaded */
/* externally rather than in the driver. We just want to disable the board */
/* and clear the loadware to a reset state. To allow this there has to be a */
/* way to detect whether the board has the loadware running at init time to */
/* handle subsequent installations of the driver. All memory allocated by the */
/* driver should be returned since it may be unloaded from memory. */
/******************************************************************************/
static void __exit ip2_cleanup_module(void)
{
int err;
int i;
del_timer_sync(&PollTimer);
/* Reset the boards we have. */
for (i = 0; i < IP2_MAX_BOARDS; i++)
if (i2BoardPtrTable[i])
iiReset(i2BoardPtrTable[i]);
/* The following is done at most once, if any boards were installed. */
for (i = 0; i < IP2_MAX_BOARDS; i++) {
if (i2BoardPtrTable[i]) {
iiResetDelay(i2BoardPtrTable[i]);
/* free io addresses and Tibet */
release_region(ip2config.addr[i], 8);
device_destroy(ip2_class, MKDEV(IP2_IPL_MAJOR, 4 * i));
device_destroy(ip2_class, MKDEV(IP2_IPL_MAJOR,
4 * i + 1));
}
/* Disable and remove interrupt handler. */
if (ip2config.irq[i] > 0 &&
have_requested_irq(ip2config.irq[i])) {
free_irq(ip2config.irq[i], (void *)&pcName);
clear_requested_irq(ip2config.irq[i]);
}
}
class_destroy(ip2_class);
err = tty_unregister_driver(ip2_tty_driver);
if (err)
printk(KERN_ERR "IP2: failed to unregister tty driver (%d)\n",
err);
put_tty_driver(ip2_tty_driver);
unregister_chrdev(IP2_IPL_MAJOR, pcIpl);
remove_proc_entry("ip2mem", NULL);
/* free memory */
for (i = 0; i < IP2_MAX_BOARDS; i++) {
void *pB;
#ifdef CONFIG_PCI
if (ip2config.type[i] == PCI && ip2config.pci_dev[i]) {
pci_disable_device(ip2config.pci_dev[i]);
pci_dev_put(ip2config.pci_dev[i]);
ip2config.pci_dev[i] = NULL;
}
#endif
pB = i2BoardPtrTable[i];
if (pB != NULL) {
kfree(pB);
i2BoardPtrTable[i] = NULL;
}
if (DevTableMem[i] != NULL) {
kfree(DevTableMem[i]);
DevTableMem[i] = NULL;
}
}
}
module_exit(ip2_cleanup_module);
static const struct tty_operations ip2_ops = {
.open = ip2_open,
.close = ip2_close,
.write = ip2_write,
.put_char = ip2_putchar,
.flush_chars = ip2_flush_chars,
.write_room = ip2_write_room,
.chars_in_buffer = ip2_chars_in_buf,
.flush_buffer = ip2_flush_buffer,
.ioctl = ip2_ioctl,
.throttle = ip2_throttle,
.unthrottle = ip2_unthrottle,
.set_termios = ip2_set_termios,
.set_ldisc = ip2_set_line_discipline,
.stop = ip2_stop,
.start = ip2_start,
.hangup = ip2_hangup,
.tiocmget = ip2_tiocmget,
.tiocmset = ip2_tiocmset,
.proc_fops = &ip2_proc_fops,
};
/******************************************************************************/
/* Function: ip2_loadmain() */
/* Parameters: irq, io from command line of insmod et. al. */
/* pointer to fip firmware and firmware size for boards */
/* Returns: Success (0) */
/* */
/* Description: */
/* This was the required entry point for all drivers (now in ip2.c) */
/* It performs all */
/* initialisation of the devices and driver structures, and registers itself */
/* with the relevant kernel modules. */
/******************************************************************************/
/* IRQF_DISABLED - if set blocks all interrupts else only this line */
/* IRQF_SHARED - for shared irq PCI or maybe EISA only */
/* SA_RANDOM - can be source for cert. random number generators */
#define IP2_SA_FLAGS 0
static const struct firmware *ip2_request_firmware(void)
{
struct platform_device *pdev;
const struct firmware *fw;
pdev = platform_device_register_simple("ip2", 0, NULL, 0);
if (IS_ERR(pdev)) {
printk(KERN_ERR "Failed to register platform device for ip2\n");
return NULL;
}
if (request_firmware(&fw, "intelliport2.bin", &pdev->dev)) {
printk(KERN_ERR "Failed to load firmware 'intelliport2.bin'\n");
fw = NULL;
}
platform_device_unregister(pdev);
return fw;
}
/******************************************************************************
* ip2_setup:
* str: kernel command line string
*
* Can't autoprobe the boards so user must specify configuration on
* kernel command line. Sane people build it modular but the others
* come here.
*
* Alternating pairs of io,irq for up to 4 boards.
* ip2=io0,irq0,io1,irq1,io2,irq2,io3,irq3
*
* io=0 => No board
* io=1 => PCI
* io=2 => EISA
* else => ISA I/O address
*
* irq=0 or invalid for ISA will revert to polling mode
*
* Any value = -1, do not overwrite compiled in value.
*
******************************************************************************/
static int __init ip2_setup(char *str)
{
int j, ints[10]; /* 4 boards, 2 parameters + 2 */
unsigned int i;
str = get_options(str, ARRAY_SIZE(ints), ints);
for (i = 0, j = 1; i < 4; i++) {
if (j > ints[0])
break;
if (ints[j] >= 0)
io[i] = ints[j];
j++;
if (j > ints[0])
break;
if (ints[j] >= 0)
irq[i] = ints[j];
j++;
}
return 1;
}
__setup("ip2=", ip2_setup);
static int __init ip2_loadmain(void)
{
int i, j, box;
int err = 0;
i2eBordStrPtr pB = NULL;
int rc = -1;
const struct firmware *fw = NULL;
char *str;
str = cmd;
if (poll_only) {
/* Hard lock the interrupts to zero */
irq[0] = irq[1] = irq[2] = irq[3] = poll_only = 0;
}
/* Check module parameter with 'ip2=' has been passed or not */
if (!poll_only && (!strncmp(str, "ip2=", 4)))
ip2_setup(str);
ip2trace(ITRC_NO_PORT, ITRC_INIT, ITRC_ENTER, 0);
/* process command line arguments to modprobe or
insmod i.e. iop & irqp */
/* irqp and iop should ALWAYS be specified now... But we check
them individually just to be sure, anyways... */
for (i = 0; i < IP2_MAX_BOARDS; ++i) {
ip2config.addr[i] = io[i];
if (irq[i] >= 0)
ip2config.irq[i] = irq[i];
else
ip2config.irq[i] = 0;
/* This is a little bit of a hack. If poll_only=1 on command
line back in ip2.c OR all IRQs on all specified boards are
explicitly set to 0, then drop to poll only mode and override
PCI or EISA interrupts. This superceeds the old hack of
triggering if all interrupts were zero (like da default).
Still a hack but less prone to random acts of terrorism.
What we really should do, now that the IRQ default is set
to -1, is to use 0 as a hard coded, do not probe.
/\/\|=mhw=|\/\/
*/
poll_only |= irq[i];
}
poll_only = !poll_only;
/* Announce our presence */
printk(KERN_INFO "%s version %s\n", pcName, pcVersion);
ip2_tty_driver = alloc_tty_driver(IP2_MAX_PORTS);
if (!ip2_tty_driver)
return -ENOMEM;
/* Initialise all the boards we can find (up to the maximum). */
for (i = 0; i < IP2_MAX_BOARDS; ++i) {
switch (ip2config.addr[i]) {
case 0: /* skip this slot even if card is present */
break;
default: /* ISA */
/* ISA address must be specified */
if (ip2config.addr[i] < 0x100 ||
ip2config.addr[i] > 0x3f8) {
printk(KERN_ERR "IP2: Bad ISA board %d "
"address %x\n", i,
ip2config.addr[i]);
ip2config.addr[i] = 0;
break;
}
ip2config.type[i] = ISA;
/* Check for valid irq argument, set for polling if
* invalid */
if (ip2config.irq[i] &&
!is_valid_irq(ip2config.irq[i])) {
printk(KERN_ERR "IP2: Bad IRQ(%d) specified\n",
ip2config.irq[i]);
/* 0 is polling and is valid in that sense */
ip2config.irq[i] = 0;
}
break;
case PCI:
#ifdef CONFIG_PCI
{
struct pci_dev *pdev = NULL;
u32 addr;
int status;
pdev = pci_get_device(PCI_VENDOR_ID_COMPUTONE,
PCI_DEVICE_ID_COMPUTONE_IP2EX, pdev);
if (pdev == NULL) {
ip2config.addr[i] = 0;
printk(KERN_ERR "IP2: PCI board %d not "
"found\n", i);
break;
}
if (pci_enable_device(pdev)) {
dev_err(&pdev->dev, "can't enable device\n");
goto out;
}
ip2config.type[i] = PCI;
ip2config.pci_dev[i] = pci_dev_get(pdev);
status = pci_read_config_dword(pdev, PCI_BASE_ADDRESS_1,
&addr);
if (addr & 1)
ip2config.addr[i] = (USHORT)(addr & 0xfffe);
else
dev_err(&pdev->dev, "I/O address error\n");
ip2config.irq[i] = pdev->irq;
out:
pci_dev_put(pdev);
}
#else
printk(KERN_ERR "IP2: PCI card specified but PCI "
"support not enabled.\n");
printk(KERN_ERR "IP2: Recompile kernel with CONFIG_PCI "
"defined!\n");
#endif /* CONFIG_PCI */
break;
case EISA:
ip2config.addr[i] = find_eisa_board(Eisa_slot + 1);
if (ip2config.addr[i] != 0) {
/* Eisa_irq set as side effect, boo */
ip2config.type[i] = EISA;
}
ip2config.irq[i] = Eisa_irq;
break;
} /* switch */
} /* for */
for (i = 0; i < IP2_MAX_BOARDS; ++i) {
if (ip2config.addr[i]) {
pB = kzalloc(sizeof(i2eBordStr), GFP_KERNEL);
if (pB) {
i2BoardPtrTable[i] = pB;
iiSetAddress(pB, ip2config.addr[i],
ii2DelayTimer);
iiReset(pB);
} else
printk(KERN_ERR "IP2: board memory allocation "
"error\n");
}
}
for (i = 0; i < IP2_MAX_BOARDS; ++i) {
pB = i2BoardPtrTable[i];
if (pB != NULL) {
iiResetDelay(pB);
break;
}
}
for (i = 0; i < IP2_MAX_BOARDS; ++i) {
/* We don't want to request the firmware unless we have at
least one board */
if (i2BoardPtrTable[i] != NULL) {
if (!fw)
fw = ip2_request_firmware();
if (!fw)
break;
ip2_init_board(i, fw);
}
}
if (fw)
release_firmware(fw);
ip2trace(ITRC_NO_PORT, ITRC_INIT, 2, 0);
ip2_tty_driver->owner = THIS_MODULE;
ip2_tty_driver->name = "ttyF";
ip2_tty_driver->driver_name = pcDriver_name;
ip2_tty_driver->major = IP2_TTY_MAJOR;
ip2_tty_driver->minor_start = 0;
ip2_tty_driver->type = TTY_DRIVER_TYPE_SERIAL;
ip2_tty_driver->subtype = SERIAL_TYPE_NORMAL;
ip2_tty_driver->init_termios = tty_std_termios;
ip2_tty_driver->init_termios.c_cflag = B9600|CS8|CREAD|HUPCL|CLOCAL;
ip2_tty_driver->flags = TTY_DRIVER_REAL_RAW |
TTY_DRIVER_DYNAMIC_DEV;
tty_set_operations(ip2_tty_driver, &ip2_ops);
ip2trace(ITRC_NO_PORT, ITRC_INIT, 3, 0);
err = tty_register_driver(ip2_tty_driver);
if (err) {
printk(KERN_ERR "IP2: failed to register tty driver\n");
put_tty_driver(ip2_tty_driver);
return err; /* leaking resources */
}
err = register_chrdev(IP2_IPL_MAJOR, pcIpl, &ip2_ipl);
if (err) {
printk(KERN_ERR "IP2: failed to register IPL device (%d)\n",
err);
} else {
/* create the sysfs class */
ip2_class = class_create(THIS_MODULE, "ip2");
if (IS_ERR(ip2_class)) {
err = PTR_ERR(ip2_class);
goto out_chrdev;
}
}
/* Register the read_procmem thing */
if (!proc_create("ip2mem",0,NULL,&ip2mem_proc_fops)) {
printk(KERN_ERR "IP2: failed to register read_procmem\n");
return -EIO; /* leaking resources */
}
ip2trace(ITRC_NO_PORT, ITRC_INIT, 4, 0);
/* Register the interrupt handler or poll handler, depending upon the
* specified interrupt.
*/
for (i = 0; i < IP2_MAX_BOARDS; ++i) {
if (ip2config.addr[i] == 0)
continue;
pB = i2BoardPtrTable[i];
if (pB != NULL) {
device_create(ip2_class, NULL,
MKDEV(IP2_IPL_MAJOR, 4 * i),
NULL, "ipl%d", i);
device_create(ip2_class, NULL,
MKDEV(IP2_IPL_MAJOR, 4 * i + 1),
NULL, "stat%d", i);
for (box = 0; box < ABS_MAX_BOXES; box++)
for (j = 0; j < ABS_BIGGEST_BOX; j++)
if (pB->i2eChannelMap[box] & (1 << j))
tty_register_device(
ip2_tty_driver,
j + ABS_BIGGEST_BOX *
(box+i*ABS_MAX_BOXES),
NULL);
}
if (poll_only) {
/* Poll only forces driver to only use polling and
to ignore the probed PCI or EISA interrupts. */
ip2config.irq[i] = CIR_POLL;
}
if (ip2config.irq[i] == CIR_POLL) {
retry:
if (!timer_pending(&PollTimer)) {
mod_timer(&PollTimer, POLL_TIMEOUT);
printk(KERN_INFO "IP2: polling\n");
}
} else {
if (have_requested_irq(ip2config.irq[i]))
continue;
rc = request_irq(ip2config.irq[i], ip2_interrupt,
IP2_SA_FLAGS |
(ip2config.type[i] == PCI ? IRQF_SHARED : 0),
pcName, i2BoardPtrTable[i]);
if (rc) {
printk(KERN_ERR "IP2: request_irq failed: "
"error %d\n", rc);
ip2config.irq[i] = CIR_POLL;
printk(KERN_INFO "IP2: Polling %ld/sec.\n",
(POLL_TIMEOUT - jiffies));
goto retry;
}
mark_requested_irq(ip2config.irq[i]);
/* Initialise the interrupt handler bottom half
* (aka slih). */
}
}
for (i = 0; i < IP2_MAX_BOARDS; ++i) {
if (i2BoardPtrTable[i]) {
/* set and enable board interrupt */
set_irq(i, ip2config.irq[i]);
}
}
ip2trace(ITRC_NO_PORT, ITRC_INIT, ITRC_RETURN, 0);
return 0;
out_chrdev:
unregister_chrdev(IP2_IPL_MAJOR, "ip2");
/* unregister and put tty here */
return err;
}
module_init(ip2_loadmain);
/******************************************************************************/
/* Function: ip2_init_board() */
/* Parameters: Index of board in configuration structure */
/* Returns: Success (0) */
/* */
/* Description: */
/* This function initializes the specified board. The loadware is copied to */
/* the board, the channel structures are initialized, and the board details */
/* are reported on the console. */
/******************************************************************************/
static void
ip2_init_board(int boardnum, const struct firmware *fw)
{
int i;
int nports = 0, nboxes = 0;
i2ChanStrPtr pCh;
i2eBordStrPtr pB = i2BoardPtrTable[boardnum];
if ( !iiInitialize ( pB ) ) {
printk ( KERN_ERR "IP2: Failed to initialize board at 0x%x, error %d\n",
pB->i2eBase, pB->i2eError );
goto err_initialize;
}
printk(KERN_INFO "IP2: Board %d: addr=0x%x irq=%d\n", boardnum + 1,
ip2config.addr[boardnum], ip2config.irq[boardnum] );
if (!request_region( ip2config.addr[boardnum], 8, pcName )) {
printk(KERN_ERR "IP2: bad addr=0x%x\n", ip2config.addr[boardnum]);
goto err_initialize;
}
if ( iiDownloadAll ( pB, (loadHdrStrPtr)fw->data, 1, fw->size )
!= II_DOWN_GOOD ) {
printk ( KERN_ERR "IP2: failed to download loadware\n" );
goto err_release_region;
} else {
printk ( KERN_INFO "IP2: fv=%d.%d.%d lv=%d.%d.%d\n",
pB->i2ePom.e.porVersion,
pB->i2ePom.e.porRevision,
pB->i2ePom.e.porSubRev, pB->i2eLVersion,
pB->i2eLRevision, pB->i2eLSub );
}
switch ( pB->i2ePom.e.porID & ~POR_ID_RESERVED ) {
default:
printk( KERN_ERR "IP2: Unknown board type, ID = %x\n",
pB->i2ePom.e.porID );
nports = 0;
goto err_release_region;
break;
case POR_ID_II_4: /* IntelliPort-II, ISA-4 (4xRJ45) */
printk ( KERN_INFO "IP2: ISA-4\n" );
nports = 4;
break;
case POR_ID_II_8: /* IntelliPort-II, 8-port using standard brick. */
printk ( KERN_INFO "IP2: ISA-8 std\n" );
nports = 8;
break;
case POR_ID_II_8R: /* IntelliPort-II, 8-port using RJ11's (no CTS) */
printk ( KERN_INFO "IP2: ISA-8 RJ11\n" );
nports = 8;
break;
case POR_ID_FIIEX: /* IntelliPort IIEX */
{
int portnum = IP2_PORTS_PER_BOARD * boardnum;
int box;
for( box = 0; box < ABS_MAX_BOXES; ++box ) {
if ( pB->i2eChannelMap[box] != 0 ) {
++nboxes;
}
for( i = 0; i < ABS_BIGGEST_BOX; ++i ) {
if ( pB->i2eChannelMap[box] & 1<< i ) {
++nports;
}
}
}
DevTableMem[boardnum] = pCh =
kmalloc( sizeof(i2ChanStr) * nports, GFP_KERNEL );
if ( !pCh ) {
printk ( KERN_ERR "IP2: (i2_init_channel:) Out of memory.\n");
goto err_release_region;
}
if ( !i2InitChannels( pB, nports, pCh ) ) {
printk(KERN_ERR "IP2: i2InitChannels failed: %d\n",pB->i2eError);
kfree ( pCh );
goto err_release_region;
}
pB->i2eChannelPtr = &DevTable[portnum];
pB->i2eChannelCnt = ABS_MOST_PORTS;
for( box = 0; box < ABS_MAX_BOXES; ++box, portnum += ABS_BIGGEST_BOX ) {
for( i = 0; i < ABS_BIGGEST_BOX; ++i ) {
if ( pB->i2eChannelMap[box] & (1 << i) ) {
DevTable[portnum + i] = pCh;
pCh->port_index = portnum + i;
pCh++;
}
}
}
printk(KERN_INFO "IP2: EX box=%d ports=%d %d bit\n",
nboxes, nports, pB->i2eDataWidth16 ? 16 : 8 );
}
goto ex_exit;
}
DevTableMem[boardnum] = pCh =
kmalloc ( sizeof (i2ChanStr) * nports, GFP_KERNEL );
if ( !pCh ) {
printk ( KERN_ERR "IP2: (i2_init_channel:) Out of memory.\n");
goto err_release_region;
}
pB->i2eChannelPtr = pCh;
pB->i2eChannelCnt = nports;
if ( !i2InitChannels( pB, nports, pCh ) ) {
printk(KERN_ERR "IP2: i2InitChannels failed: %d\n",pB->i2eError);
kfree ( pCh );
goto err_release_region;
}
pB->i2eChannelPtr = &DevTable[IP2_PORTS_PER_BOARD * boardnum];
for( i = 0; i < pB->i2eChannelCnt; ++i ) {
DevTable[IP2_PORTS_PER_BOARD * boardnum + i] = pCh;
pCh->port_index = (IP2_PORTS_PER_BOARD * boardnum) + i;
pCh++;
}
ex_exit:
INIT_WORK(&pB->tqueue_interrupt, ip2_interrupt_bh);
return;
err_release_region:
release_region(ip2config.addr[boardnum], 8);
err_initialize:
kfree ( pB );
i2BoardPtrTable[boardnum] = NULL;
return;
}
/******************************************************************************/
/* Function: find_eisa_board ( int start_slot ) */
/* Parameters: First slot to check */
/* Returns: Address of EISA IntelliPort II controller */
/* */
/* Description: */
/* This function searches for an EISA IntelliPort controller, starting */
/* from the specified slot number. If the motherboard is not identified as an */
/* EISA motherboard, or no valid board ID is selected it returns 0. Otherwise */
/* it returns the base address of the controller. */
/******************************************************************************/
static unsigned short
find_eisa_board( int start_slot )
{
int i, j;
unsigned int idm = 0;
unsigned int idp = 0;
unsigned int base = 0;
unsigned int value;
int setup_address;
int setup_irq;
int ismine = 0;
/*
* First a check for an EISA motherboard, which we do by comparing the
* EISA ID registers for the system board and the first couple of slots.
* No slot ID should match the system board ID, but on an ISA or PCI
* machine the odds are that an empty bus will return similar values for
* each slot.
*/