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
|
/*
* Copyright 2003 Digi International (www.digi.com)
* Scott H Kilau <Scott_Kilau at digi dot com>
*
* 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, or (at your option)
* any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY, EXPRESS OR IMPLIED; 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.
*
*
* NOTE TO LINUX KERNEL HACKERS: DO NOT REFORMAT THIS CODE!
*
* This is shared code between Digi's CVS archive and the
* Linux Kernel sources.
* Changing the source just for reformatting needlessly breaks
* our CVS diff history.
*
* Send any bug fixes/changes to: Eng.Linux at digi dot com.
* Thank you.
*
*/
#include <linux/kernel.h>
#include <linux/version.h>
#include <linux/module.h>
#include <linux/pci.h>
#include <linux/slab.h>
#if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,39)
#include <linux/sched.h>
#endif
#include "dgnc_driver.h"
#include "dgnc_pci.h"
#include "dpacompat.h"
#include "dgnc_mgmt.h"
#include "dgnc_tty.h"
#include "dgnc_trace.h"
#include "dgnc_cls.h"
#include "dgnc_neo.h"
#include "dgnc_sysfs.h"
MODULE_LICENSE("GPL");
MODULE_AUTHOR("Digi International, http://www.digi.com");
MODULE_DESCRIPTION("Driver for the Digi International Neo and Classic PCI based product line");
MODULE_SUPPORTED_DEVICE("dgnc");
/*
* insmod command line overrideable parameters
*
* NOTE: we use a set of macros to create the variables, which allows
* us to specify the variable type, name, initial value, and description.
*/
PARM_INT(debug, 0x00, 0644, "Driver debugging level");
PARM_INT(rawreadok, 1, 0644, "Bypass flip buffers on input");
PARM_INT(trcbuf_size, 0x100000, 0644, "Debugging trace buffer size.");
/**************************************************************************
*
* protos for this file
*
*/
static int dgnc_start(void);
static int dgnc_finalize_board_init(struct board_t *brd);
static void dgnc_init_globals(void);
static int dgnc_found_board(struct pci_dev *pdev, int id);
static void dgnc_cleanup_board(struct board_t *brd);
static void dgnc_poll_handler(ulong dummy);
static int dgnc_init_pci(void);
static int dgnc_init_one(struct pci_dev *pdev, const struct pci_device_id *ent);
static void dgnc_remove_one(struct pci_dev *dev);
static int dgnc_probe1(struct pci_dev *pdev, int card_type);
static void dgnc_do_remap(struct board_t *brd);
/* Driver load/unload functions */
int dgnc_init_module(void);
void dgnc_cleanup_module(void);
module_init(dgnc_init_module);
module_exit(dgnc_cleanup_module);
/*
* File operations permitted on Control/Management major.
*/
static struct file_operations dgnc_BoardFops =
{
.owner = THIS_MODULE,
.unlocked_ioctl = dgnc_mgmt_ioctl,
.open = dgnc_mgmt_open,
.release = dgnc_mgmt_close
};
/*
* Globals
*/
uint dgnc_NumBoards;
struct board_t *dgnc_Board[MAXBOARDS];
DEFINE_SPINLOCK(dgnc_global_lock);
int dgnc_driver_state = DRIVER_INITIALIZED;
ulong dgnc_poll_counter;
uint dgnc_Major;
int dgnc_poll_tick = 20; /* Poll interval - 20 ms */
/*
* Static vars.
*/
static uint dgnc_Major_Control_Registered = FALSE;
static uint dgnc_driver_start = FALSE;
static struct class *dgnc_class;
/*
* Poller stuff
*/
static DEFINE_SPINLOCK(dgnc_poll_lock); /* Poll scheduling lock */
static ulong dgnc_poll_time; /* Time of next poll */
static uint dgnc_poll_stop; /* Used to tell poller to stop */
static struct timer_list dgnc_poll_timer;
static struct pci_device_id dgnc_pci_tbl[] = {
{ DIGI_VID, PCI_DEVICE_CLASSIC_4_DID, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0 },
{ DIGI_VID, PCI_DEVICE_CLASSIC_4_422_DID, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 1 },
{ DIGI_VID, PCI_DEVICE_CLASSIC_8_DID, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 2 },
{ DIGI_VID, PCI_DEVICE_CLASSIC_8_422_DID, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 3 },
{ DIGI_VID, PCI_DEVICE_NEO_4_DID, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 4 },
{ DIGI_VID, PCI_DEVICE_NEO_8_DID, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 5 },
{ DIGI_VID, PCI_DEVICE_NEO_2DB9_DID, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 6 },
{ DIGI_VID, PCI_DEVICE_NEO_2DB9PRI_DID, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 7 },
{ DIGI_VID, PCI_DEVICE_NEO_2RJ45_DID, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 8 },
{ DIGI_VID, PCI_DEVICE_NEO_2RJ45PRI_DID, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 9 },
{ DIGI_VID, PCI_DEVICE_NEO_1_422_DID, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 10 },
{ DIGI_VID, PCI_DEVICE_NEO_1_422_485_DID, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 11 },
{ DIGI_VID, PCI_DEVICE_NEO_2_422_485_DID, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 12 },
{ DIGI_VID, PCI_DEVICE_NEO_EXPRESS_8_DID, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 13 },
{ DIGI_VID, PCI_DEVICE_NEO_EXPRESS_4_DID, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 14 },
{ DIGI_VID, PCI_DEVICE_NEO_EXPRESS_4RJ45_DID, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 15 },
{ DIGI_VID, PCI_DEVICE_NEO_EXPRESS_8RJ45_DID, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 16 },
{0,} /* 0 terminated list. */
};
MODULE_DEVICE_TABLE(pci, dgnc_pci_tbl);
struct board_id {
uchar *name;
uint maxports;
unsigned int is_pci_express;
};
static struct board_id dgnc_Ids[] =
{
{ PCI_DEVICE_CLASSIC_4_PCI_NAME, 4, 0 },
{ PCI_DEVICE_CLASSIC_4_422_PCI_NAME, 4, 0 },
{ PCI_DEVICE_CLASSIC_8_PCI_NAME, 8, 0 },
{ PCI_DEVICE_CLASSIC_8_422_PCI_NAME, 8, 0 },
{ PCI_DEVICE_NEO_4_PCI_NAME, 4, 0 },
{ PCI_DEVICE_NEO_8_PCI_NAME, 8, 0 },
{ PCI_DEVICE_NEO_2DB9_PCI_NAME, 2, 0 },
{ PCI_DEVICE_NEO_2DB9PRI_PCI_NAME, 2, 0 },
{ PCI_DEVICE_NEO_2RJ45_PCI_NAME, 2, 0 },
{ PCI_DEVICE_NEO_2RJ45PRI_PCI_NAME, 2, 0 },
{ PCI_DEVICE_NEO_1_422_PCI_NAME, 1, 0 },
{ PCI_DEVICE_NEO_1_422_485_PCI_NAME, 1, 0 },
{ PCI_DEVICE_NEO_2_422_485_PCI_NAME, 2, 0 },
{ PCI_DEVICE_NEO_EXPRESS_8_PCI_NAME, 8, 1 },
{ PCI_DEVICE_NEO_EXPRESS_4_PCI_NAME, 4, 1 },
{ PCI_DEVICE_NEO_EXPRESS_4RJ45_PCI_NAME, 4, 1 },
{ PCI_DEVICE_NEO_EXPRESS_8RJ45_PCI_NAME, 8, 1 },
{ NULL, 0, 0 }
};
static struct pci_driver dgnc_driver = {
.name = "dgnc",
.probe = dgnc_init_one,
.id_table = dgnc_pci_tbl,
.remove = dgnc_remove_one,
};
char *dgnc_state_text[] = {
"Board Failed",
"Board Found",
"Board READY",
};
char *dgnc_driver_state_text[] = {
"Driver Initialized",
"Driver Ready."
};
/************************************************************************
*
* Driver load/unload functions
*
************************************************************************/
/*
* init_module()
*
* Module load. This is where it all starts.
*/
int dgnc_init_module(void)
{
int rc = 0;
APR(("%s, Digi International Part Number %s\n", DG_NAME, DG_PART));
/*
* Initialize global stuff
*/
rc = dgnc_start();
if (rc < 0) {
return(rc);
}
/*
* Find and configure all the cards
*/
rc = dgnc_init_pci();
/*
* If something went wrong in the scan, bail out of driver.
*/
if (rc < 0) {
/* Only unregister the pci driver if it was actually registered. */
if (dgnc_NumBoards)
pci_unregister_driver(&dgnc_driver);
else
printk("WARNING: dgnc driver load failed. No Digi Neo or Classic boards found.\n");
dgnc_cleanup_module();
}
else {
dgnc_create_driver_sysfiles(&dgnc_driver);
}
DPR_INIT(("Finished init_module. Returning %d\n", rc));
return (rc);
}
/*
* Start of driver.
*/
static int dgnc_start(void)
{
int rc = 0;
unsigned long flags;
if (dgnc_driver_start == FALSE) {
dgnc_driver_start = TRUE;
/* make sure that the globals are init'd before we do anything else */
dgnc_init_globals();
dgnc_NumBoards = 0;
APR(("For the tools package or updated drivers please visit http://www.digi.com\n"));
/*
* Register our base character device into the kernel.
* This allows the download daemon to connect to the downld device
* before any of the boards are init'ed.
*/
if (!dgnc_Major_Control_Registered) {
/*
* Register management/dpa devices
*/
rc = register_chrdev(0, "dgnc", &dgnc_BoardFops);
if (rc <= 0) {
APR(("Can't register dgnc driver device (%d)\n", rc));
rc = -ENXIO;
return(rc);
}
dgnc_Major = rc;
dgnc_class = class_create(THIS_MODULE, "dgnc_mgmt");
#if LINUX_VERSION_CODE < KERNEL_VERSION(2,6,28)
device_create_drvdata(dgnc_class, NULL,
MKDEV(dgnc_Major, 0),
NULL, "dgnc_mgmt");
#else
device_create(dgnc_class, NULL,
MKDEV(dgnc_Major, 0),
NULL, "dgnc_mgmt");
#endif
dgnc_Major_Control_Registered = TRUE;
}
/*
* Init any global tty stuff.
*/
rc = dgnc_tty_preinit();
if (rc < 0) {
APR(("tty preinit - not enough memory (%d)\n", rc));
return(rc);
}
/* Start the poller */
DGNC_LOCK(dgnc_poll_lock, flags);
init_timer(&dgnc_poll_timer);
dgnc_poll_timer.function = dgnc_poll_handler;
dgnc_poll_timer.data = 0;
dgnc_poll_time = jiffies + dgnc_jiffies_from_ms(dgnc_poll_tick);
dgnc_poll_timer.expires = dgnc_poll_time;
DGNC_UNLOCK(dgnc_poll_lock, flags);
add_timer(&dgnc_poll_timer);
dgnc_driver_state = DRIVER_READY;
}
return(rc);
}
/*
* Register pci driver, and return how many boards we have.
*/
static int dgnc_init_pci(void)
{
return pci_register_driver(&dgnc_driver);
}
/* returns count (>= 0), or negative on error */
static int dgnc_init_one(struct pci_dev *pdev, const struct pci_device_id *ent)
{
int rc;
/* wake up and enable device */
rc = pci_enable_device(pdev);
if (rc < 0) {
rc = -EIO;
} else {
rc = dgnc_probe1(pdev, ent->driver_data);
if (rc == 0) {
dgnc_NumBoards++;
DPR_INIT(("Incrementing numboards to %d\n", dgnc_NumBoards));
}
}
return rc;
}
static int dgnc_probe1(struct pci_dev *pdev, int card_type)
{
return dgnc_found_board(pdev, card_type);
}
static void dgnc_remove_one(struct pci_dev *dev)
{
/* Do Nothing */
}
/*
* dgnc_cleanup_module()
*
* Module unload. This is where it all ends.
*/
void dgnc_cleanup_module(void)
{
int i;
ulong lock_flags;
DGNC_LOCK(dgnc_poll_lock, lock_flags);
dgnc_poll_stop = 1;
DGNC_UNLOCK(dgnc_poll_lock, lock_flags);
/* Turn off poller right away. */
del_timer_sync(&dgnc_poll_timer);
dgnc_remove_driver_sysfiles(&dgnc_driver);
if (dgnc_Major_Control_Registered) {
device_destroy(dgnc_class, MKDEV(dgnc_Major, 0));
class_destroy(dgnc_class);
unregister_chrdev(dgnc_Major, "dgnc");
}
for (i = 0; i < dgnc_NumBoards; ++i) {
dgnc_remove_ports_sysfiles(dgnc_Board[i]);
dgnc_tty_uninit(dgnc_Board[i]);
dgnc_cleanup_board(dgnc_Board[i]);
}
dgnc_tty_post_uninit();
#if defined(DGNC_TRACER)
/* last thing, make sure we release the tracebuffer */
dgnc_tracer_free();
#endif
if (dgnc_NumBoards)
pci_unregister_driver(&dgnc_driver);
}
/*
* dgnc_cleanup_board()
*
* Free all the memory associated with a board
*/
static void dgnc_cleanup_board(struct board_t *brd)
{
int i = 0;
if(!brd || brd->magic != DGNC_BOARD_MAGIC)
return;
switch (brd->device) {
case PCI_DEVICE_CLASSIC_4_DID:
case PCI_DEVICE_CLASSIC_8_DID:
case PCI_DEVICE_CLASSIC_4_422_DID:
case PCI_DEVICE_CLASSIC_8_422_DID:
/* Tell card not to interrupt anymore. */
outb(0, brd->iobase + 0x4c);
break;
default:
break;
}
if (brd->irq)
free_irq(brd->irq, brd);
tasklet_kill(&brd->helper_tasklet);
if (brd->re_map_membase) {
iounmap(brd->re_map_membase);
brd->re_map_membase = NULL;
}
if (brd->msgbuf_head) {
unsigned long flags;
DGNC_LOCK(dgnc_global_lock, flags);
brd->msgbuf = NULL;
printk(brd->msgbuf_head);
kfree(brd->msgbuf_head);
brd->msgbuf_head = NULL;
DGNC_UNLOCK(dgnc_global_lock, flags);
}
/* Free all allocated channels structs */
for (i = 0; i < MAXPORTS ; i++) {
if (brd->channels[i]) {
if (brd->channels[i]->ch_rqueue)
kfree(brd->channels[i]->ch_rqueue);
if (brd->channels[i]->ch_equeue)
kfree(brd->channels[i]->ch_equeue);
if (brd->channels[i]->ch_wqueue)
kfree(brd->channels[i]->ch_wqueue);
kfree(brd->channels[i]);
brd->channels[i] = NULL;
}
}
if (brd->flipbuf)
kfree(brd->flipbuf);
dgnc_Board[brd->boardnum] = NULL;
kfree(brd);
}
/*
* dgnc_found_board()
*
* A board has been found, init it.
*/
static int dgnc_found_board(struct pci_dev *pdev, int id)
{
struct board_t *brd;
unsigned int pci_irq;
int i = 0;
int rc = 0;
unsigned long flags;
/* get the board structure and prep it */
brd = dgnc_Board[dgnc_NumBoards] =
(struct board_t *) dgnc_driver_kzmalloc(sizeof(struct board_t), GFP_KERNEL);
if (!brd) {
APR(("memory allocation for board structure failed\n"));
return(-ENOMEM);
}
/* make a temporary message buffer for the boot messages */
brd->msgbuf = brd->msgbuf_head =
(char *) dgnc_driver_kzmalloc(sizeof(char) * 8192, GFP_KERNEL);
if (!brd->msgbuf) {
kfree(brd);
APR(("memory allocation for board msgbuf failed\n"));
return(-ENOMEM);
}
/* store the info for the board we've found */
brd->magic = DGNC_BOARD_MAGIC;
brd->boardnum = dgnc_NumBoards;
brd->vendor = dgnc_pci_tbl[id].vendor;
brd->device = dgnc_pci_tbl[id].device;
brd->pdev = pdev;
brd->pci_bus = pdev->bus->number;
brd->pci_slot = PCI_SLOT(pdev->devfn);
brd->name = dgnc_Ids[id].name;
brd->maxports = dgnc_Ids[id].maxports;
if (dgnc_Ids[i].is_pci_express)
brd->bd_flags |= BD_IS_PCI_EXPRESS;
brd->dpastatus = BD_NOFEP;
init_waitqueue_head(&brd->state_wait);
DGNC_SPINLOCK_INIT(brd->bd_lock);
DGNC_SPINLOCK_INIT(brd->bd_intr_lock);
brd->state = BOARD_FOUND;
for (i = 0; i < MAXPORTS; i++) {
brd->channels[i] = NULL;
}
/* store which card & revision we have */
pci_read_config_word(pdev, PCI_SUBSYSTEM_VENDOR_ID, &brd->subvendor);
pci_read_config_word(pdev, PCI_SUBSYSTEM_ID, &brd->subdevice);
pci_read_config_byte(pdev, PCI_REVISION_ID, &brd->rev);
pci_irq = pdev->irq;
brd->irq = pci_irq;
switch(brd->device) {
case PCI_DEVICE_CLASSIC_4_DID:
case PCI_DEVICE_CLASSIC_8_DID:
case PCI_DEVICE_CLASSIC_4_422_DID:
case PCI_DEVICE_CLASSIC_8_422_DID:
brd->dpatype = T_CLASSIC | T_PCIBUS;
DPR_INIT(("dgnc_found_board - Classic.\n"));
/*
* For PCI ClassicBoards
* PCI Local Address (i.e. "resource" number) space
* 0 PLX Memory Mapped Config
* 1 PLX I/O Mapped Config
* 2 I/O Mapped UARTs and Status
* 3 Memory Mapped VPD
* 4 Memory Mapped UARTs and Status
*/
/* get the PCI Base Address Registers */
brd->membase = pci_resource_start(pdev, 4);
if (!brd->membase) {
APR(("card has no PCI IO resources, failing board.\n"));
return -ENODEV;
}
brd->membase_end = pci_resource_end(pdev, 4);
if (brd->membase & 1)
brd->membase &= ~3;
else
brd->membase &= ~15;
brd->iobase = pci_resource_start(pdev, 1);
brd->iobase_end = pci_resource_end(pdev, 1);
brd->iobase = ((unsigned int) (brd->iobase)) & 0xFFFE;
/* Assign the board_ops struct */
brd->bd_ops = &dgnc_cls_ops;
brd->bd_uart_offset = 0x8;
brd->bd_dividend = 921600;
dgnc_do_remap(brd);
/* Get and store the board VPD, if it exists */
brd->bd_ops->vpd(brd);
/*
* Enable Local Interrupt 1 (0x1),
* Local Interrupt 1 Polarity Active high (0x2),
* Enable PCI interrupt (0x40)
*/
outb(0x43, brd->iobase + 0x4c);
break;
case PCI_DEVICE_NEO_4_DID:
case PCI_DEVICE_NEO_8_DID:
case PCI_DEVICE_NEO_2DB9_DID:
case PCI_DEVICE_NEO_2DB9PRI_DID:
case PCI_DEVICE_NEO_2RJ45_DID:
case PCI_DEVICE_NEO_2RJ45PRI_DID:
case PCI_DEVICE_NEO_1_422_DID:
case PCI_DEVICE_NEO_1_422_485_DID:
case PCI_DEVICE_NEO_2_422_485_DID:
case PCI_DEVICE_NEO_EXPRESS_8_DID:
case PCI_DEVICE_NEO_EXPRESS_4_DID:
case PCI_DEVICE_NEO_EXPRESS_4RJ45_DID:
case PCI_DEVICE_NEO_EXPRESS_8RJ45_DID:
/*
* This chip is set up 100% when we get to it.
* No need to enable global interrupts or anything.
*/
if (brd->bd_flags & BD_IS_PCI_EXPRESS)
brd->dpatype = T_NEO_EXPRESS | T_PCIBUS;
else
brd->dpatype = T_NEO | T_PCIBUS;
DPR_INIT(("dgnc_found_board - NEO.\n"));
/* get the PCI Base Address Registers */
brd->membase = pci_resource_start(pdev, 0);
brd->membase_end = pci_resource_end(pdev, 0);
if (brd->membase & 1)
brd->membase &= ~3;
else
brd->membase &= ~15;
/* Assign the board_ops struct */
brd->bd_ops = &dgnc_neo_ops;
brd->bd_uart_offset = 0x200;
brd->bd_dividend = 921600;
dgnc_do_remap(brd);
if (brd->re_map_membase) {
/* After remap is complete, we need to read and store the dvid */
brd->dvid = readb(brd->re_map_membase + 0x8D);
/* Get and store the board VPD, if it exists */
brd->bd_ops->vpd(brd);
}
break;
default:
APR(("Did not find any compatible Neo or Classic PCI boards in system.\n"));
return (-ENXIO);
}
/*
* Do tty device initialization.
*/
rc = dgnc_tty_register(brd);
if (rc < 0) {
dgnc_tty_uninit(brd);
APR(("Can't register tty devices (%d)\n", rc));
brd->state = BOARD_FAILED;
brd->dpastatus = BD_NOFEP;
goto failed;
}
rc = dgnc_finalize_board_init(brd);
if (rc < 0) {
APR(("Can't finalize board init (%d)\n", rc));
brd->state = BOARD_FAILED;
brd->dpastatus = BD_NOFEP;
goto failed;
}
rc = dgnc_tty_init(brd);
if (rc < 0) {
dgnc_tty_uninit(brd);
APR(("Can't init tty devices (%d)\n", rc));
brd->state = BOARD_FAILED;
brd->dpastatus = BD_NOFEP;
goto failed;
}
brd->state = BOARD_READY;
brd->dpastatus = BD_RUNNING;
dgnc_create_ports_sysfiles(brd);
/* init our poll helper tasklet */
tasklet_init(&brd->helper_tasklet, brd->bd_ops->tasklet, (unsigned long) brd);
DPR_INIT(("dgnc_scan(%d) - printing out the msgbuf\n", i));
DGNC_LOCK(dgnc_global_lock, flags);
brd->msgbuf = NULL;
printk(brd->msgbuf_head);
kfree(brd->msgbuf_head);
brd->msgbuf_head = NULL;
DGNC_UNLOCK(dgnc_global_lock, flags);
/*
* allocate flip buffer for board.
*
* Okay to malloc with GFP_KERNEL, we are not at interrupt
* context, and there are no locks held.
*/
brd->flipbuf = dgnc_driver_kzmalloc(MYFLIPLEN, GFP_KERNEL);
wake_up_interruptible(&brd->state_wait);
return(0);
failed:
return (-ENXIO);
}
static int dgnc_finalize_board_init(struct board_t *brd) {
int rc = 0;
DPR_INIT(("dgnc_finalize_board_init() - start\n"));
if (!brd || brd->magic != DGNC_BOARD_MAGIC)
return(-ENODEV);
DPR_INIT(("dgnc_finalize_board_init() - start #2\n"));
if (brd->irq) {
rc = request_irq(brd->irq, brd->bd_ops->intr, IRQF_SHARED, "DGNC", brd);
if (rc) {
printk("Failed to hook IRQ %d\n",brd->irq);
brd->state = BOARD_FAILED;
brd->dpastatus = BD_NOFEP;
rc = -ENODEV;
} else {
DPR_INIT(("Requested and received usage of IRQ %d\n", brd->irq));
}
}
return(rc);
}
/*
* Remap PCI memory.
*/
static void dgnc_do_remap(struct board_t *brd)
{
if (!brd || brd->magic != DGNC_BOARD_MAGIC)
return;
brd->re_map_membase = ioremap(brd->membase, 0x1000);
DPR_INIT(("remapped mem: 0x%p\n", brd->re_map_membase));
}
/*****************************************************************************
*
* Function:
*
* dgnc_poll_handler
*
* Author:
*
* Scott H Kilau
*
* Parameters:
*
* dummy -- ignored
*
* Return Values:
*
* none
*
* Description:
*
* As each timer expires, it determines (a) whether the "transmit"
* waiter needs to be woken up, and (b) whether the poller needs to
* be rescheduled.
*
******************************************************************************/
static void dgnc_poll_handler(ulong dummy)
{
struct board_t *brd;
unsigned long lock_flags;
int i;
unsigned long new_time;
dgnc_poll_counter++;
/*
* Do not start the board state machine until
* driver tells us its up and running, and has
* everything it needs.
*/
if (dgnc_driver_state != DRIVER_READY) {
goto schedule_poller;
}
/* Go thru each board, kicking off a tasklet for each if needed */
for (i = 0; i < dgnc_NumBoards; i++) {
brd = dgnc_Board[i];
DGNC_LOCK(brd->bd_lock, lock_flags);
/* If board is in a failed state, don't bother scheduling a tasklet */
if (brd->state == BOARD_FAILED) {
DGNC_UNLOCK(brd->bd_lock, lock_flags);
continue;
}
/* Schedule a poll helper task */
tasklet_schedule(&brd->helper_tasklet);
DGNC_UNLOCK(brd->bd_lock, lock_flags);
}
schedule_poller:
/*
* Schedule ourself back at the nominal wakeup interval.
*/
DGNC_LOCK(dgnc_poll_lock, lock_flags);
dgnc_poll_time += dgnc_jiffies_from_ms(dgnc_poll_tick);
new_time = dgnc_poll_time - jiffies;
if ((ulong) new_time >= 2 * dgnc_poll_tick) {
dgnc_poll_time = jiffies + dgnc_jiffies_from_ms(dgnc_poll_tick);
}
init_timer(&dgnc_poll_timer);
dgnc_poll_timer.function = dgnc_poll_handler;
dgnc_poll_timer.data = 0;
dgnc_poll_timer.expires = dgnc_poll_time;
DGNC_UNLOCK(dgnc_poll_lock, lock_flags);
if (!dgnc_poll_stop)
add_timer(&dgnc_poll_timer);
}
/*
* dgnc_init_globals()
*
* This is where we initialize the globals from the static insmod
* configuration variables. These are declared near the head of
* this file.
*/
static void dgnc_init_globals(void)
{
int i = 0;
dgnc_rawreadok = rawreadok;
dgnc_trcbuf_size = trcbuf_size;
dgnc_debug = debug;
for (i = 0; i < MAXBOARDS; i++) {
dgnc_Board[i] = NULL;
}
init_timer(&dgnc_poll_timer);
}
/************************************************************************
*
* Utility functions
*
************************************************************************/
/*
* dgnc_driver_kzmalloc()
*
* Malloc and clear memory,
*/
void *dgnc_driver_kzmalloc(size_t size, int priority)
{
void *p = kmalloc(size, priority);
if(p)
memset(p, 0, size);
return(p);
}
/*
* dgnc_ms_sleep()
*
* Put the driver to sleep for x ms's
*
* Returns 0 if timed out, !0 (showing signal) if interrupted by a signal.
*/
int dgnc_ms_sleep(ulong ms)
{
current->state = TASK_INTERRUPTIBLE;
schedule_timeout((ms * HZ) / 1000);
return (signal_pending(current));
}
/*
* dgnc_ioctl_name() : Returns a text version of each ioctl value.
*/
char *dgnc_ioctl_name(int cmd)
{
switch(cmd) {
case TCGETA: return("TCGETA");
case TCGETS: return("TCGETS");
case TCSETA: return("TCSETA");
case TCSETS: return("TCSETS");
case TCSETAW: return("TCSETAW");
case TCSETSW: return("TCSETSW");
case TCSETAF: return("TCSETAF");
case TCSETSF: return("TCSETSF");
case TCSBRK: return("TCSBRK");
case TCXONC: return("TCXONC");
case TCFLSH: return("TCFLSH");
case TIOCGSID: return("TIOCGSID");
case TIOCGETD: return("TIOCGETD");
case TIOCSETD: return("TIOCSETD");
case TIOCGWINSZ: return("TIOCGWINSZ");
case TIOCSWINSZ: return("TIOCSWINSZ");
case TIOCMGET: return("TIOCMGET");
case TIOCMSET: return("TIOCMSET");
case TIOCMBIS: return("TIOCMBIS");
case TIOCMBIC: return("TIOCMBIC");
/* from digi.h */
case DIGI_SETA: return("DIGI_SETA");
case DIGI_SETAW: return("DIGI_SETAW");
case DIGI_SETAF: return("DIGI_SETAF");
case DIGI_SETFLOW: return("DIGI_SETFLOW");
case DIGI_SETAFLOW: return("DIGI_SETAFLOW");
case DIGI_GETFLOW: return("DIGI_GETFLOW");
case DIGI_GETAFLOW: return("DIGI_GETAFLOW");
case DIGI_GETA: return("DIGI_GETA");
case DIGI_GEDELAY: return("DIGI_GEDELAY");
case DIGI_SEDELAY: return("DIGI_SEDELAY");
case DIGI_GETCUSTOMBAUD: return("DIGI_GETCUSTOMBAUD");
case DIGI_SETCUSTOMBAUD: return("DIGI_SETCUSTOMBAUD");
case TIOCMODG: return("TIOCMODG");
case TIOCMODS: return("TIOCMODS");
case TIOCSDTR: return("TIOCSDTR");
case TIOCCDTR: return("TIOCCDTR");
default: return("unknown");
}
}
|